Stream brokered OpenCode chat replies over /connect
Add the server-side half of the brokered chat path (route B): the
opencode.Chat adapter forwards chat_prompt to POST
/api/session/{id}/prompt through the owned Connection.Call translation
and derives chat_event frames from the authenticated /api/event SSE
firehose (text and reasoning deltas, tool parts with their status
transitions, step and usage). Every pushed frame carries a stable
session and message id, with a last-message-id fallback so step/tool
events that omit the assistant message id stay attributable.
The /connect handler keeps per-session retained state (chatHub) capped at
1 MiB with least-recently-updated eviction at 128 turns, so a
reconnecting client re-syncs through chat_messages instead of replaying
deltas the OpenCode per-session log never resends. Prompt dispatch
subscribes before posting and buffers pre-ack frames to preserve order,
and cancels the stream on disconnect so no goroutine leaks. chat_sessions
and chat_create are declared but not yet brokered: they answer with an
explicit protocol error rather than the generic Pong.
Reuse the existing transport, validation and normalization; no second
OpenCode transport or credential path is introduced.
Tests: protocol golden round-trip, adapter normalization + v1/v2 Call
translation, and handler ack/stream/validation/resume/disconnect, plus a
real-adapter no-tool evidence harness.
This commit is contained in:
@@ -175,6 +175,21 @@ traversal, absolute paths, symlink escapes and unknown runs/steps.
|
||||
- Do not invent artifact files or claim a stage produced one without the recorded
|
||||
evidence; the server observes the directory after the stage.
|
||||
|
||||
## Brokered OpenCode chat (unshipped)
|
||||
|
||||
The protocol declares the brokered `chat_*` surface (`chat_sessions`,
|
||||
`chat_create`, `chat_prompt`, `chat_messages`, `chat_interrupt`, `chat_reply`). The
|
||||
server dispatches `chat_prompt`, `chat_messages`, `chat_interrupt` and `chat_reply`,
|
||||
answers the declared `chat_sessions`/`chat_create` with an explicit protocol error
|
||||
because they are not yet brokered, and pushes `chat_event` frames derived from
|
||||
OpenCode's global `/api/event` firehose, with retained per-session/per-message state
|
||||
so a reconnecting client re-syncs instead of replaying deltas. This is an internal, unshipped capability: no client consumes it,
|
||||
and chat is enabled only when the OpenCode connection exposes a URL-bearing SSE
|
||||
endpoint (the owned v1 serve process). On a V2 CLI (`opencode api`, no owned serve)
|
||||
that endpoint is absent, so every dispatched `chat_*` request returns a protocol error
|
||||
naming the missing configuration. Do not describe brokered chat as a finished or
|
||||
user-facing feature.
|
||||
|
||||
## Debug and retry
|
||||
|
||||
Debug opens a new conversation with retained failure context, exact definition and
|
||||
|
||||
Reference in New Issue
Block a user