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

Aperta
#574 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Saifjafri212213 ci sta già lavorando.

Dal 2/11/2026.

  • #580 di @Saifjafri212213 — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.

Lingua principale
TypeScript
Stelle
13
Fork
7
Merge medio
3h 15m
PR unite (30g)
330

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di codercops/chatcops

Tutte le issue di codercops/chatcops

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.