Skip to content

Commit

Permalink
perf: vercel 版 添加 NextChatAgent 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Nov 14, 2024
1 parent f373dde commit da4a0c8
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
"lint": "eslint --fix *.js *.ts packages plugins scripts",
"version": "tsx scripts/gen-version.ts",
"build": "pnpm -r run build",
"build:plugins": "pnpm --filter @chatgpt-telegram-workers/plugins... build",
"build:core": "pnpm --filter @chatgpt-telegram-workers/core... build",
"build:next": "pnpm --filter @chatgpt-telegram-workers/next... build",
"build:local": "pnpm --filter @chatgpt-telegram-workers/local... build",
"build:vercel": "pnpm --filter @chatgpt-telegram-workers/vercel... build",
"build:workers": "pnpm --filter @chatgpt-telegram-workers/workers... build",
"build:workersnext": "pnpm --filter @chatgpt-telegram-workers/workers-next... build",
"build:interpolate": "pnpm --filter @chatgpt-telegram-workers/interpolate... build",
"build:plugins": "pnpm run --filter @chatgpt-telegram-workers/plugins... build",
"build:core": "pnpm run --filter @chatgpt-telegram-workers/core... build",
"build:next": "pnpm run --filter @chatgpt-telegram-workers/next... build",
"build:local": "pnpm run --filter @chatgpt-telegram-workers/local... build",
"build:vercel": "pnpm run --filter @chatgpt-telegram-workers/vercel... build",
"build:workers": "pnpm run --filter @chatgpt-telegram-workers/workers... build",
"build:workersnext": "pnpm run --filter @chatgpt-telegram-workers/workers-next... build",
"build:interpolate": "pnpm run --filter @chatgpt-telegram-workers/interpolate... build",
"build:docker": "docker build -t chatgpt-telegram-workers:latest .",
"build:dockerx": "docker buildx build --platform linux/amd64,linux/arm64 -t chatgpt-telegram-workers:latest .",
"build:dist": "pnpm run version && pnpm run build:workers && cp -r packages/apps/workers/dist/index.js dist/",
"deploy:dist": "pnpm run build:dist && wrangler deploy",
"deploy:workers": "pnpm run build:workers && TOML_PATH=$INIT_CWD/wrangler.toml pnpm --filter @chatgpt-telegram-workers/workers deploy",
"deploy:workersnext": "pnpm run build:workersnext && TOML_PATH=$INIT_CWD/wrangler.toml pnpm --filter @chatgpt-telegram-workers/workers-next deploy",
"deploy:workers": "pnpm run build:workers && && TOML_PATH=$INIT_CWD/wrangler.toml pnpm run --filter @chatgpt-telegram-workers/workers deploy",
"deploy:workersnext": "pnpm run build:workersnext && TOML_PATH=$INIT_CWD/wrangler.toml pnpm run --filter @chatgpt-telegram-workers/workers-next deploy",
"deploy:vercel": "pnpm run build:vercel && vercel --prod",
"start:local": "pnpm run build:local && CONFIG_PATH=$INIT_CWD/config.json TOML_PATH=$INIT_CWD/wrangler.toml pnpm --filter @chatgpt-telegram-workers/local start",
"start:local": "pnpm run build:local && CONFIG_PATH=$INIT_CWD/config.json TOML_PATH=$INIT_CWD/wrangler.toml pnpm run --filter @chatgpt-telegram-workers/local start",
"vercel:syncenv": "tsx scripts/vercel-sync-env.ts && vercel --prod",
"clean": "pnpm -r run clean",
"wrangler": "wrangler"
Expand Down
5 changes: 4 additions & 1 deletion packages/apps/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
},
"dependencies": {
"@chatgpt-telegram-workers/core": "workspace:*",
"@chatgpt-telegram-workers/next": "workspace:*",
"cloudflare-worker-adapter": "^1.3.3"
},
"devDependencies": {
"@types/react": "^18.3.12",
"@vercel/node": "^3.2.24"
"@vercel/node": "^3.2.24",
"openai": "^4.72.0",
"react-dom": "^18.3.1"
}
}
4 changes: 3 additions & 1 deletion packages/apps/vercel/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { VercelRequest, VercelResponse } from '@vercel/node';
import * as process from 'node:process';
import { createRouter, ENV } from '@chatgpt-telegram-workers/core';
import { CHAT_AGENTS, createRouter, ENV } from '@chatgpt-telegram-workers/core';
import { injectNextChatAgent } from '@chatgpt-telegram-workers/next';
import { UpStashRedis } from 'cloudflare-worker-adapter';

export default async function (request: VercelRequest, response: VercelResponse) {
Expand All @@ -24,6 +25,7 @@ export default async function (request: VercelRequest, response: VercelResponse)
...process.env,
DATABASE: cache,
});
injectNextChatAgent(CHAT_AGENTS); // remove this line if you don't use vercel ai sdk
const router = createRouter();
let body: any | null = null;
if (request.body) {
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/vercel/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./dist",
"types": ["node", "react"]
},
"references": [
{ "path": "../../lib/core" }
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/workers-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "pnpm vite build",
"clean": "rm -rf dist",
"deploy": "wrangler deploy --config=${TOML_PATH}"
"deploy": "wrangler deploy --config ${TOML_PATH}"
},
"dependencies": {
"@chatgpt-telegram-workers/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "pnpm vite build",
"clean": "rm -rf dist",
"deploy": "wrangler deploy --config=${TOML_PATH}"
"deploy": "wrangler deploy --config ${TOML_PATH}"
},
"dependencies": {
"@chatgpt-telegram-workers/core": "workspace:*"
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions wrangler-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ name = 'chatgpt-telegram-workers'
compatibility_date = '2023-10-07'
main = './dist/index.js' # 先使用vite编译 然后再使用编译产物部署

# 修改 main = './dist/index.js' 为对应模块index.ts
# 然后在对应目录下执行 pnpm run deploy:workers 或者 pnpm run deploy:workersnext
# 即可直接使用wrangler编译部署,不使用vite编译
# 修改 main = './dist/index.js' 为对应模块dist/index.js 或 src/index.ts,
# pnpm run deploy:workers
#main = './packages/apps/workers/dist/index.js'
#main = './packages/apps/workers/src/index.ts'
# pnpm run deploy:workersnext
#main = './packages/apps/workers-next/dist/index.js'
#main = './packages/apps/workers-next/src/index.ts'

workers_dev = true
Expand Down

0 comments on commit da4a0c8

Please sign in to comment.