Poll OpenCode permission requests and forward chat_reply

This commit is contained in:
2026-10-16 08:06:39 +01:00
parent 9d1676df0a
commit 3ff5cd8838
10 changed files with 889 additions and 40 deletions
+34 -2
View File
@@ -22,9 +22,12 @@ const (
ChatMessages = "chat_messages"
ChatInterrupt = "chat_interrupt"
ChatReply = "chat_reply"
// ChatEvent is the server-pushed frame; it is the only type the server
// sends without a matching request.
// ChatEvent and ChatPermission are the server-pushed frames; they are the
// only types the server sends without a matching request.
ChatEvent = "chat_event"
// ChatPermission carries one pending OpenCode approval request the phone
// answers with chat_reply.
ChatPermission = "chat_permission"
)
// Content part types carried by ChatPart.Type and ChatEvent.Kind.
@@ -200,6 +203,35 @@ type ChatUsage struct {
Cost float64 `json:"cost,omitempty"`
}
// ChatPermissionFrame is the server-pushed chat_permission payload: one pending
// OpenCode permission request the phone must approve or reject. It is a distinct
// Message field (like ChatEvent) rather than a ChatEvent.Kind, so it does not
// overload the turn-progress kinds. Its field names match the service's
// Permission.Request schema, verified against the installed service's
// /openapi.json (id, sessionID, action and resources required; save, metadata,
// source and message optional), with id -> RequestID and sessionID -> SessionID.
// The wire shape is spec-verified; a live pending request has not been observed.
// Every optional field is omitempty so older peers ignore it.
type ChatPermissionFrame struct {
SessionID string `json:"session_id"`
RequestID string `json:"request_id"`
Action string `json:"action,omitempty"`
Resources []string `json:"resources,omitempty"`
Save []string `json:"save,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Source *ChatPermissionSource `json:"source,omitempty"`
Message string `json:"message,omitempty"`
}
// ChatPermissionSource identifies what raised a permission request, matching the
// Permission.Source union (currently only a tool call: type "tool" plus the
// message and call id) verified against the service's /openapi.json.
type ChatPermissionSource struct {
Type string `json:"type,omitempty"`
MessageID string `json:"message_id,omitempty"`
ID string `json:"id,omitempty"`
}
// ChatReplyRequest is the chat_reply request body: the phone's decision on a
// pending permission request, mirroring
// POST /api/session/{id}/permission/{requestID}/reply.