// 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", 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", }); /** * 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; }