Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkShawn2020 committed Sep 30, 2024
0 parents commit 07324e1
Show file tree
Hide file tree
Showing 320 changed files with 15,098 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Since the ".env" file is gitignored, you can use the ".env.example" file to
# build a new ".env" file when you clone the repo. Keep this file up-to-date
# when you add new variables to `.env`.

# This file will be committed to version control, so make sure not to have any
# secrets in it. If you are cloning this repo, create a copy of this file named
# ".env" and populate it with your secrets.

# When adding additional environment variables, the schema in "/src/env.js"
# should be updated accordingly.

# Prisma
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
DATABASE_URL="postgresql://postgres:password@localhost:5432/v2agi"

# Next Auth
# You can generate a new secret on the command line with:
# openssl rand -base64 32
# https://next-auth.js.org/configuration/options#secret
# NEXTAUTH_SECRET=""
NEXTAUTH_URL="http://localhost:3000"

# Next Auth Discord Provider
DISCORD_CLIENT_ID=""
DISCORD_CLIENT_SECRET=""
46 changes: 46 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** @type {import("eslint").Linter.Config} */
const config = {
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
plugins: ["@typescript-eslint"],
extends: [
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
],
rules: {

// These opinionated rules are enabled in stylistic-type-checked above.
// Feel free to reconfigure them to your own preference.
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",

"@typescript-eslint/consistent-type-imports": [
"warn",
{
prefer: "type-imports",
fixStyle: "inline-type-imports",
},
],
"@typescript-eslint/no-unused-vars": ["warn", {argsIgnorePattern: "^_"}],
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-misused-promises": [
"warn",
{
checksVoidReturn: {attributes: false},
},
],
'@typescript-eslint/no-unsafe-call': "warn",
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-empty-interface': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/no-floating-promises': 'warn'
},
};

module.exports = config;
26 changes: 26 additions & 0 deletions .github/workflows/deploy-on-my-machine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This is a basic workflow that is manually triggered

name: Deploy On My Machine

# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
push:
branches:
- main

env:
DOMAIN: 'https://eval.cs-magic.cn'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "greet"
deploy-on-my-machine:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Runs a single command using the runners shell
- name: trigger update via curl
run: curl "${{ env.DOMAIN }}/api/system?update=true&useSSE=true"
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.env.cs-magic.cn
# zod
prisma/generated

deprecated
.next-tmp

.idea

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# database
/prisma/db.sqlite
/prisma/db.sqlite-journal

# next.js
/.next/
/out/
next-env.d.ts

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
# do not commit any .env files to git, except for the .env.example file. https://create.t3.gg/en/usage/env-variables#using-environment-variables
.env
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"semi": false
}
120 changes: 120 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Eval AI !

## Todo

- [ ] fix eval-ai running prisma
- [ ] 研究怎么把 trpc 静态编译那玩意给 generic 了

## Architecture

### 要点

- 后台静默流是可以不做的(或者高级版?),因为需要维护一个进程池,没有必要,用户打断我们即中止
- 消息的回溯是可以不做的(或者高级版?),因为要考虑数据库同步问题,以及组装上下文到底是在客户端还是服务端
- 【乐观刷新】前期为了保证开发速度与质量,可以暂时先不用
- 【状态管理】jotai vs zustand vs vs valtio
- 【trpc状态同步】在列表页上,我们还是用了invalidate机制,避免了手写各种convs的更新与对齐,然后本地的convs始终对齐trcp的列表数据即可
- 【llm-manager同步】(2024-03-09)在经历了痛苦的同步控制,最后不得不用上redis并陷入序列化的困境后,我最终决定放弃一切幻想all in pusher


### Conversation

- queryConv --> queryRequest --> queryResponse
- queryRequest = queryContext + n * queryConfig
- queryConfig -- queryResponse

### api ref

- openai: https://github.com/openai/openai-python/issues/952#issuecomment-1857207339

## Tech

### [Init] install

```shell
# ref: https://github.com/yarnpkg/berry/issues/3521#issuecomment-1907517793
# 阿里的库会有证书过期问题
yarn config set "strict-ssl" false -g
```

### [zod-prisma-types]

- zod 的版本有要求(不能太高):`yarn add zod@3.21.1`,参考:https://github.com/chrishoermann/zod-prisma-types/issues/222
- 之前在开发 lit-agent 项目的时候有 build bug,现在重新试了一下,又没了。。
- 且用且看吧

### [NextJS] server action 在 dev 里可以放在 route 里,但 build 时会失败

### [DevOps] 控制台颜色

首先,我们读了 trpc 的 loggerLink 源码,它是用 ansi/css 两种写法分别决定 node/browser 颜色的

我尝试了 colors, chalk([基于gpt](https://chat.openai.com/c/756f58ea-4d30-4b74-9c52-e4847dd2fdbf)),都只能 node 用

最后在[ chalk 的一个 issue](https://github.com/chalk/chalk/issues/535#issuecomment-1072761585) 里顺着别人的路用了 `ansi-colors`

### [Core] Websocket Integration

- vercel 不推荐,参考:
- Do Vercel Serverless Functions support WebSocket connections?, https://vercel.com/guides/do-vercel-serverless-functions-support-websocket-connections#enabling-realtime-communication
- (1) Websockets with nextjs 13 : nextjs, https://www.reddit.com/r/nextjs/comments/13360t3/websockets_with_nextjs_13/

- 使用 soketi
- pm2 的时候要注意,`soketi-pm2` 不支持 config,不如直接 `pm2 start soketi -- start --config=xx`
- [bug] PM2 doesn't pass through command line arguments on Windows · Issue #320 · soketi/soketi, https://github.com/soketi/soketi/issues/320

### [Polyfill] tsx 导入 Credentials

```ts
import CredentialsModule from "next-auth/providers/credentials"

// sb tsx 需要用 default
const Credentials = (
"default" in CredentialsModule ? CredentialsModule.default : CredentialsModule
) as typeof CredentialsModule
```


### [UI] text with gradient color

- How to do gradient text with Tailwind CSS, https://design2tailwind.com/blog/tailwindcss-gradient-text/

### [Backend] nginx

- redirect problem from `http` to `https`, see: https://serverfault.com/a/680592
- solution: 把 `$servername` 改成 `$host` 就可以了

### [Core] wechat-auth

虽然微信登录起步是访问一个 open-wechat 的网址,但不能直接点击跳转,而是在 provider 的 authorizationUrl 里配置好后,在程序里使用 `signIn` 去操作,否则会报 `State cookie was missing`

### [Core] zustand

- zustand doesn't recommend `create without curried workaround`, see: https://github.com/pmndrs/zustand/blob/main/docs/guides/typescript.md#create-without-curried-workaround

## BUGFIX

### sonner 版本要求

这个不行: `"sonner": "^1.4.0",`,参考:https://github.com/emilkowalski/sonner/issues/353

### jotai 不可以 在 set 里 set writable variable, 那是用于 useAtom 的,见:

![img.png](docs/jotai-writeable.png)

ref:
- https://jotai.org/docs/core/atom
- https://chat.openai.com/c/52cf8ab1-de90-4249-8239-322d2f860d33

### - [x] `import sum from "lodash/sum"`

问题: 这个会导致 `yarn update``spawn` 里编译时失败。

解决:将 `@types/lodash` 加入 prod 依赖即可。

原因分析:还没有完全明白,就是在全新的shell里编译好像会导致node_modules不符合预期,这个可以做一个新的todo。


## How do I deploy this?

Follow our deployment guides for [Vercel](https://create.t3.gg/en/deployment/vercel), [Netlify](https://create.t3.gg/en/deployment/netlify) and [Docker](https://create.t3.gg/en/deployment/docker) for more information.
17 changes: 17 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "src/styles/globals.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "packages/common-ui/shadcn/components",
"utils": "packages/common-ui/shadcn/utils"
}
}
Binary file added docs/jotai-writeable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import dotenv from "dotenv"
import path from "path"
import { fileURLToPath } from "url"
dotenv.config(path.join(fileURLToPath(import.meta.url), "../../.env"))
dotenv.config(path.join(fileURLToPath(import.meta.url), "../../.env.local"))

/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
await import("./src/env.js")

/** @type {import("next").NextConfig} */
const config = {
reactStrictMode: false,

distDir: process.env.DIST ?? ".next",

webpack(config, { dev, isServer }) {
// Grab the existing rule that handles SVG imports
const fileLoaderRule = config.module.rules.find((rule) =>
rule.test?.test?.(".svg"),
)

config.module.rules.push(
// Reapply the existing rule, but only for svg imports ending in ?url
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/, // *.svg?url
},
// Convert all other *.svg imports to React components
{
test: /\.svg$/i,
issuer: fileLoaderRule.issuer,
resourceQuery: { not: [...fileLoaderRule.resourceQuery.not, /url/] }, // exclude if *.svg?url
use: ["@svgr/webpack"],
},
)

// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i

return config
},

// ref: https://nextjs.org/docs/api-reference/next/image#remote-patterns
images: {
remotePatterns: [
// ref:https://stackoverflow.com/a/73951135/9422455
{ protocol: "http", hostname: "**" },
{ protocol: "https", hostname: "**" },
],
},

// ref: https://jotai.org/docs/tools/devtools#next-js-setup
transpilePackages: ["jotai-devtools"],
experimental: {
swcPlugins: [
["@swc-jotai/debug-label", {}],

// WARNING: 这个不能加!加了之后 atomWithStorage 会完蛋!(调了两天!)
// ["@swc-jotai/react-refresh", {}],
],
},

// ref: https://nextjs.org/docs/app/building-your-application/routing/redirecting#redirects-in-nextconfigjs
async redirects() {
return [
{
source: "/",
destination: "/tt",
permanent: false,
},
]
},
}

export default config
Loading

0 comments on commit 07324e1

Please sign in to comment.