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

Offen
#574 2 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@Saifjafri212213 arbeitet bereits daran.

Seit 02.11.2026.

  • #580 von @Saifjafri212213 — offen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

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.

Vorherrschende Sprache
TypeScript
Sterne
13
Forks
7
Ø Merge
3 Std. 15 Min.
Gemergte PRs (30 T.)
330

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus codercops/chatcops

Alle Issues in codercops/chatcops

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.