POST /api/chat/generate → 202 { runId } (async workflow run) — chat#1813

Merged
SW
5mo ago
+173-140

PR 1 (docs, the contract) of the async chat-generation migration tracked in recoupable/chat#1813 — docs → api → tasks order.

What

POST /api/chat/generate is being re-pointed from a synchronous legacy ToolLoopAgent onto the durable runAgentWorkflow. It now starts a workflow run and returns { runId } with HTTP 202 instead of the full completion body.

  • Replace the 200 ChatGenerateResponse with 202 ChatGenerateAcceptedResponse { runId }.
  • Drop the now-unused ChatGenerateResponse / ChatGenerateResponseMeta / ChatGenerateUsage / ContentPart schemas (each was referenced only by the old 200 — verified, no dangling $refs).
  • 400 unchanged.

Why the contract can change

The only caller (tasks/src/recoup/generateChat.ts) used the response only for logging; message persistence + email happen server-side. The api PR makes the caller fire-and-forget.

Merge order

This docs PR lands first (contract), then api re-points to fulfill it, then tasks goes fire-and-forget.

🤖 Generated with Claude Code


Summary by cubic

Expose chat-generation as async runs. POST /api/chat/runs starts a durable workflow and returns 202 with runId, chatId, sessionId, and a Location header; poll GET /api/chat/runs/{runId} or watch live via GET /api/chat/{chatId}/stream (chat#1813).

  • Migration
    • Replace POST /api/chat/generate with POST /api/chat/runs; add GET /api/chat/runs/{runId} for status.
    • Request schema: removed excludeTools, roomId, topic; now matches POST /api/chat (prompt | messages, artistId, model).
    • Removed ChatGenerateResponse, ChatGenerateResponseMeta, ChatGenerateUsage, ContentPart; 400 unchanged.
    • Docs: removed generate.mdx; added runs.mdx and runs-status.mdx; updated nav/index, reordered Streaming section, fixed {param} link rendering, added bidirectional cross-links, simplified run descriptions, and standardized endpoint-link formatting (backticked method links) in the touched descriptions including the Session schema.

Summary by CodeRabbit

  • New Features
    • Added an asynchronous chat run flow: POST /api/chat/runs now returns immediately with HTTP 202, along with runId, chatId, and sessionId.
    • Added GET /api/chat/runs/{runId} to retrieve the run’s current status.
  • Bug Fixes
    • Updated the chat API contract from the prior synchronous generate response to an async accepted response.
  • Documentation
    • Updated API reference pages and navigation to replace the former “Generate Chat” documentation with “Start Chat Run” and “Get Chat Run Status.”