Server: chatcopsNext(), one catch-all route for Next.js

未關閉
#574 2 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 1 天內回覆

@Saifjafri212213 已經在處理了。

開始於 2026年11月2日。

  • #580 來自 @Saifjafri212213 —— 未關閉

評估

這個 Issue 還沒有評估資料。

描述

enhancement server

F-12 task 5. In Next.js the chat needs two route files today: app/api/chat/route.ts and app/api/chat/session/route.ts, which re-exports the first (website/src/content/docs/server/fetch-runtimes.mdx:13-40). Forgetting the second breaks session tokens. A Next adapter can serve every sub-path from one catch-all route:

// app/api/chat/[[...path]]/route.ts
import { chatcopsNext } from '@chatcops/server/next';

export const { POST, OPTIONS } = chatcopsNext({
  provider: { type: 'claude', apiKey: process.env.ANTHROPIC_API_KEY! },
  systemPrompt: 'You are a helpful assistant.',
  sessionSecrets: [process.env.CHATCOPS_SESSION_SECRET!],
});
export const runtime = 'nodejs';

What to do

  • A new packages/server/src/adapters/next.ts with chatcopsNext(config), returning { POST, OPTIONS }, both (request: Request) => Promise<Response>. Build it like chatcopsVercelHandler (packages/server/src/adapters/vercel.ts): one createChatHandler at module scope, and fetchChatResponse with the client IP. fetchChatResponse already sends a path ending in /session to the session endpoint (isSessionPath in packages/server/src/http.ts), so the catch-all works without routing of its own. Add a GET later, with handoff (F-10).
  • Add "./next" to the exports in packages/server/package.json, next to ./vercel.
  • Docs: change the Next.js section of fetch-runtimes.mdx to the single catch-all route, and keep the two-file version as a short note for older code.

Acceptance criteria

  • Unit tests with real Request objects: a chat POST to /api/chat, a session POST to /api/chat/session, an OPTIONS preflight, and a request without a token getting 401
  • You tried it in a fresh Next.js app (npx create-next-app@latest), following the updated docs, and the widget chats with it. Say what you ran in the PR.
  • pnpm docs:check passes (it checks that the server example sets sessionSecrets)
  • A minor changeset for @chatcops/server; pnpm test:coverage, pnpm lint, pnpm publint and pnpm api (commit the snapshot) pass

Comment on this issue to be assigned.

主要語言
TypeScript
星號
13
分支
7
平均合併
3 小時 14 分鐘
30 天內合併 PR
332

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

codercops/chatcops 的其他 Issue

查看 codercops/chatcops 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。