b55de770fe
A template detail now offers "Create pipeline from this template". Its
dialog ("Create from {name}", one required field "New pipeline name
(required)", the note that it creates a draft and does not run, Create /
Cancel with Cancel reading Close after a success) validates the
template's source first and, only when it parses, submits it create-only
with the trimmed name. Create is disabled while the name is blank or
while sending; the field locks while sending and after a success. A
refusal shows the server's own error in the still-open dialog; a success
shows `Created "{name}". It is in the Pipelines list.` and refreshes
list_pipelines so the new row is visible.
Pure helpers + both request shapes are unit-tested; the flow is captured
against a scratch server with its own throwaway database. The live
server's pipeline list is never touched: the default ui-smoke run sends
no submit and create runs only under its --scratch flag. Wording matches
android/.../TemplateDetailScreen.kt and PipelinesRepository.kt.
89 lines
3.1 KiB
JavaScript
89 lines
3.1 KiB
JavaScript
// 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;
|
||
}
|