// Protocol command/type constants. Mirrors the subset of // android/app/src/main/java/net/awan/pipelines/data/protocol/Message.kt and // internal/protocol/*.go used by this spike, so renames cannot drift silently. export const Protocol = Object.freeze({ PING: "ping", PONG: "pong", ERROR: "error", LIST: "list_pipelines", PIPELINE_LIST: "pipelines", GET_PIPELINE: "get_pipeline", PIPELINE: "pipeline", LIST_TEMPLATES: "list_templates", TEMPLATES: "templates", VALIDATE: "validate", VALIDATED: "validated", // Publishing a new create-only draft from a source (internal/protocol/message.go // Submit/Submitted; mirrors PipelinesRepository.createPipeline). The reply // carries the new pipeline `detail`. SUBMIT: "submit", SUBMITTED: "submitted", LIST_RUNS: "list_runs", RUNS: "runs", GET_RUN: "get_run", RUN: "run", // Omni-search (internal/protocol/search.go): the command and its reply type. // The per-kind payloads and the kind/limit vocabulary live in src/search.js. SEARCH: "search", SEARCH_RESULTS: "search_results", // The run-level operator actions (R11–R14). Each replies with a `run` (or // `run_started` for retry) envelope carrying the updated run detail; mirrors // internal/protocol/runs.go and Message.kt. CANCEL_RUN: "cancel_run", RETRY_RUN: "retry_run", DECIDE_RUN: "decide_run", SET_RUN_TITLE: "set_run_title", // Brokered OpenCode chat (C1/C3/C4), mirroring internal/protocol/chat.go and // Message.kt. The session-scoped commands carry their body in `chat_query`; // the list replies in `chat_sessions`, history in `chat_history` (an opaque // `next_cursor` + `has_more`) and a close/reopen echoes the updated session in // `chat_session` (with the `chat_close` outcome alongside). CHAT_SESSIONS: "chat_sessions", CHAT_MESSAGES: "chat_messages", CHAT_CLOSE: "chat_close", CHAT_REOPEN: "chat_reopen", // The shared live stream (C5). `chat_subscribe` attaches this connection to one // session's stream (body: the session id); the server then pushes `chat_event` // frames without a matching request id, so every client watching a session sees // the same turn. There is no `chat_unsubscribe` on the wire — the server // detaches a subscription when the connection closes. CHAT_SUBSCRIBE: "chat_subscribe", CHAT_EVENT: "chat_event", // The composer's own commands (C8/C9). `chat_prompt` carries its body in // `chat_prompt` (`{session_id,text,files?,operation_id}`) and its reply echoes // `chat_queued` when the prompt waits behind an in-flight turn; `chat_interrupt` // carries the same `chat_query` body as the other session-scoped commands; and // `chat_create` carries `chat_create` and replies with `chat_session`. CHAT_PROMPT: "chat_prompt", CHAT_INTERRUPT: "chat_interrupt", CHAT_CREATE: "chat_create", // The approval card (C10): the server pushes `chat_permission` frames (one // pending request, later re-pushed with the resolution) and the phone answers // with `chat_reply` (internal/protocol/chat.go ChatPermission/ChatReply). CHAT_PERMISSION: "chat_permission", CHAT_REPLY: "chat_reply", SUCCESS_END: "#success", FAILURE_END: "#failure", }); /** * The envelope field names the chat commands read and write * (internal/protocol/message.go). Kept beside the command constants so a rename * in the Go envelope cannot drift silently. */ export const ChatKeys = Object.freeze({ SESSIONS: "chat_sessions", SESSION: "chat_session", QUERY: "chat_query", HISTORY: "chat_history", MESSAGES: "chat_messages", CLOSE: "chat_close", // `chat_subscribe` (the request body naming the session) and `chat_event` (the // unsolicited pushed frame on the shared stream). SUBSCRIBE: "chat_subscribe", EVENT: "chat_event", // The composer's payloads (C8/C9). `chat_interrupt` deliberately has no key of // its own: its body is the same `chat_query` the other session-scoped commands // carry (internal/protocol/chat.go ChatQuery, Chat.kt interruptRequest), so a // separate field name here would put it on the wrong part of the envelope. PROMPT: "chat_prompt", CREATE: "chat_create", QUEUED: "chat_queued", // C10: the pushed approval frame (`chat_permission`) and the answer body // (`chat_reply`), both distinct Message fields in internal/protocol/message.go. PERMISSION: "chat_permission", REPLY: "chat_reply", }); /** * The integer wire protocol this page speaks. Mirrors `ProtocolVersion` in * internal/protocol/identity.go and the value the Android client compares in * `data/protocol/Message.kt` (the `protocol` field of the `pong` reply). It is * compared as a number, never a string; a differing server value is surfaced as * a warning rather than silently misread. */ export const PROTOCOL_VERSION = 1; export function isTerminal(target) { return target === Protocol.SUCCESS_END || target === Protocol.FAILURE_END; } /** Mirrors protocol.ResolveTarget: preserve the # shorthand as an explicit terminal. */ export function resolveTarget(outcome, target) { if (target !== "#") return target; return outcome === "error" ? Protocol.FAILURE_END : Protocol.SUCCESS_END; }