// 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_SCHEDULES: "list_schedules", SCHEDULES: "schedules", SAVE_SCHEDULE: "save_schedule", SCHEDULE: "schedule", DELETE_SCHEDULE: "delete_schedule", SCHEDULE_DELETED: "schedule_deleted", 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", REPAIR_SESSION_EXPORT: "repair_session_export", RUN: "run", // Live run state (internal/protocol/runevents.go, Message.kt; R10). `subscribe` // scopes the watch to a workspace (the blank string means "any") and may carry // explicit `run_ids`; `unsubscribe` drops the connection's watch; `run_event` is // the server-pushed compact delta, which arrives without a matching request id // and is therefore surfaced by client.js as a `frame` event. Both commands are // send-only: the server may not ack `subscribe` and the Android client never // awaits a reply. SUBSCRIBE: "subscribe", UNSUBSCRIBE: "unsubscribe", RUN_EVENT: "run_event", // 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. RUN_PIPELINE: "run_pipeline", 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", CHAT_STAR: "chat_star", CHAT_RENAME: "chat_rename", CHAT_BACKENDS: "chat_backends", // Model selection for one chat. `chat_models` uses the usual `chat_query` // session body and replies in `chat_models`; `chat_model` carries // `{session_id,provider,model}` in `chat_model` and echoes it. CHAT_MODELS: "chat_models", CHAT_MODEL: "chat_model", // 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", CHAT_ANSWER: "chat_answer", // 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 create flow's directory choices (C2): `chat_directories` has no body and // replies in the `chat_directories` field, home first then recent operator // directories (internal/protocol/chat.go ChatDirectories). CHAT_DIRECTORIES: "chat_directories", // 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", // The background shells a chat session owns (C11). `chat_shells` lists the // session's currently verified shells (body: `chat_query`); `chat_shell_output` // reads a bounded, lazy output page from one of them (body: // `chat_shell_output_query`). Mirrors internal/protocol/chat.go and Message.kt. CHAT_SHELLS: "chat_shells", CHAT_SHELL_OUTPUT: "chat_shell_output", 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", ANSWER: "chat_answer", RENAME: "chat_rename", BACKENDS: "chat_backends", MODELS: "chat_models", MODEL: "chat_model", // 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", // The `chat_directories` reply (C2), home first then recents; mirrors // internal/protocol/message.go `ChatDirectories []string`. DIRECTORIES: "chat_directories", 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 shell commands (C11, internal/protocol/message.go). `chat_shells` carries // its body in `chat_query` (like the other session-scoped commands) and replies // in `chat_shells`; `chat_shell_output` carries `chat_shell_output_query` // ({session_id,shell_id,cursor,limit}) and replies in `chat_shell_output`. SHELLS: "chat_shells", SHELL_OUTPUT: "chat_shell_output", SHELL_OUTPUT_QUERY: "chat_shell_output_query", }); /** * 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; }