Poll OpenCode permission requests and forward chat_reply
This commit is contained in:
@@ -178,17 +178,39 @@ traversal, absolute paths, symlink escapes and unknown runs/steps.
|
||||
## 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.
|
||||
`chat_create`, `chat_prompt`, `chat_messages`, `chat_interrupt`, `chat_permission`,
|
||||
`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.
|
||||
|
||||
While a `chat_prompt` subscription is open the server also polls
|
||||
`GET /api/permission/request` on a fixed small interval (first poll immediately) and
|
||||
pushes one `chat_permission` frame per newly pending approval request, deduped by
|
||||
request id so a repeated poll never re-pushes the same request. The app answers with
|
||||
`chat_reply`, which the server forwards as
|
||||
`POST /api/session/{id}/permission/{requestID}/reply` with
|
||||
`{"decision":"once"|"always"|"reject"}`. A missing session/request id or an invalid
|
||||
decision is rejected before any OpenCode call, and the poller stops when the stream
|
||||
ends or the client disconnects.
|
||||
|
||||
The permission list and reply are implemented against the V2 HTTP API only: their
|
||||
field names match the service's `Permission.Request`/`Permission.Reply` schemas
|
||||
(verified against the installed service's `/openapi.json`), and the native v1 serve
|
||||
translation rejects them explicitly instead of guessing an endpoint. Because this
|
||||
build enables brokered chat only when the OpenCode connection exposes a URL-bearing
|
||||
SSE endpoint (the owned v1 serve process), the approval flow is not reachable on the
|
||||
backend that currently enables chat; on that backend the permission poller stops
|
||||
quietly rather than reporting the documented limitation as a per-prompt error. This is
|
||||
an internal, unshipped capability: no client consumes it, and 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. The live
|
||||
end-to-end approval flow has NOT been tested against a real OpenCode service; the wire
|
||||
shapes and the exact reply path/body are covered by unit tests over an httptest
|
||||
fixture, not against a live pending request. Do not describe brokered chat as a
|
||||
finished or user-facing feature.
|
||||
|
||||
## Debug and retry
|
||||
|
||||
|
||||
Reference in New Issue
Block a user