Merge branch 'main' into web-chat-live

This commit is contained in:
2026-10-19 07:01:39 +01:00
9 changed files with 583 additions and 3 deletions
+213
View File
@@ -78,6 +78,15 @@ import {
runFiltersActiveCount,
} from "./runs.js";
import {
CREATE_ACTION_LABEL,
CREATE_NAME_LABEL,
CREATE_NOTE,
createConfirmLabel,
createDismissLabel,
createFormTitle,
createFormValid,
createSuccessMessage,
createdPipelineName,
effectiveStageType,
templateCard,
templateDetailName,
@@ -334,6 +343,16 @@ const state = {
templateGraphs: new Map(),
selectedTemplateKey: null,
templateTab: "summary",
// The create-from-template dialog (P5): whether it is open, the name being
// typed, whether a validate+submit is in flight, the server's refusal text and
// the created pipeline's name (null until a success, which is also what makes
// Cancel read Close and the field lock). The dialog validates the template's
// source first, then submits it create-only; nothing runs.
templateCreateOpen: false,
templateCreateName: "",
templateCreateSending: false,
templateCreateError: "",
templateCreateCreated: null,
loading: false,
error: "",
runFilters: defaultRunFilters(),
@@ -1318,6 +1337,7 @@ function renderTemplateDetail() {
return pane;
}
const graph = templateGraphFor(entry.key);
pane.append(renderTemplateDetailActions());
pane.append(
h(
"div",
@@ -1330,9 +1350,190 @@ function renderTemplateDetail() {
if (state.templateTab === "graph") pane.append(renderTemplateGraphTab(graph));
else if (state.templateTab === "source") pane.append(renderTemplateSourceTab(entry, graph));
else pane.append(renderTemplateSummaryTab(entry, graph));
if (state.templateCreateOpen) pane.append(renderTemplateCreateDialog(entry));
return pane;
}
/**
* The template detail's action row: the one "Create pipeline from this
* template" action (P5), matching the app's top-bar add action. It opens the
* dialog; it never submits on its own.
*/
function renderTemplateDetailActions() {
return h(
"div",
{ class: "detail-actions" },
h("button", {
class: "ghost template-create-open",
type: "button",
text: CREATE_ACTION_LABEL,
onclick: () => openTemplateCreateDialog(),
}),
);
}
/** Open the create dialog with a fresh, empty name; nothing is sent until Create. */
function openTemplateCreateDialog() {
state.templateCreateOpen = true;
state.templateCreateName = "";
state.templateCreateSending = false;
state.templateCreateError = "";
state.templateCreateCreated = null;
renderContent();
document.querySelector(".template-create-name")?.focus();
}
/** Dismiss the create dialog (never while a validate+submit is in flight). */
function closeTemplateCreateDialog() {
if (state.templateCreateSending) return;
state.templateCreateOpen = false;
state.templateCreateName = "";
state.templateCreateError = "";
state.templateCreateCreated = null;
renderContent();
}
/**
* The create dialog (P5): the title, the one required name field, the note, the
* server's refusal text or the success line, and Create/Cancel (Cancel reads
* Close after a success). Create is disabled while the name is blank or while
* sending; the field locks while sending and after a success. Every server
* string is set with textContent.
*/
function renderTemplateCreateDialog(entry) {
const title = createFormTitle(entry);
const overlay = h("div", {
class: "template-create-dialog",
role: "dialog",
"aria-modal": "true",
"aria-label": title,
});
overlay.addEventListener("click", (event) => {
if (event.target === overlay) closeTemplateCreateDialog();
});
const panel = h("div", { class: "template-create-panel" });
panel.append(h("h2", { class: "template-create-title", text: title }));
const field = h("label", { class: "template-create-field" });
field.append(h("span", { class: "template-create-label", text: CREATE_NAME_LABEL }));
field.append(
h("input", {
class: "template-create-name",
type: "text",
value: state.templateCreateName,
spellcheck: "false",
autocomplete: "off",
disabled: state.templateCreateSending || state.templateCreateCreated != null,
oninput: (event) => {
// Update in place (no re-render) so the field keeps focus and its caret;
// only the confirm button's enabled state depends on the name.
state.templateCreateName = event.target.value;
const confirm = overlay.querySelector(".template-create-confirm");
if (confirm) {
confirm.disabled = !createFormValid(state.templateCreateName, {
sending: state.templateCreateSending,
created: state.templateCreateCreated,
});
}
},
}),
);
panel.append(field);
panel.append(h("p", { class: "template-create-note muted", text: CREATE_NOTE }));
if (state.templateCreateError) {
panel.append(h("div", { class: "template-create-error bad", text: state.templateCreateError }));
}
if (state.templateCreateCreated != null) {
panel.append(
h("div", {
class: "template-create-success",
text: createSuccessMessage(state.templateCreateCreated),
}),
);
}
const actions = h("div", { class: "template-create-actions" });
actions.append(
h("button", {
class: "ghost template-create-cancel",
type: "button",
text: createDismissLabel(state.templateCreateCreated),
disabled: state.templateCreateSending,
onclick: closeTemplateCreateDialog,
}),
);
actions.append(
h("button", {
class: "template-create-confirm",
type: "button",
text: createConfirmLabel(state.templateCreateSending),
disabled: !createFormValid(state.templateCreateName, {
sending: state.templateCreateSending,
created: state.templateCreateCreated,
}),
onclick: () => createFromTemplate(entry),
}),
);
panel.append(actions);
overlay.append(panel);
return overlay;
}
/**
* The P5 submit flow, exactly the app's: validate the template's source first
* and, when the server refuses to parse it, show its own error in the dialog and
* send nothing; otherwise submit the source create-only with the chosen name. On
* success remember the created name, refresh the pipeline list so the new row is
* visible and leave the dialog open (Cancel now reads Close); on failure show
* the server's error without closing.
*/
async function createFromTemplate(entry) {
if (
!createFormValid(state.templateCreateName, {
sending: state.templateCreateSending,
created: state.templateCreateCreated,
})
) {
return;
}
const name = state.templateCreateName;
state.templateCreateSending = true;
state.templateCreateError = "";
renderContent();
try {
await repo.validate(entry.source);
} catch (error) {
state.templateCreateSending = false;
state.templateCreateError = describeError(error);
renderContent();
return;
}
try {
const detail = await repo.submit(name, entry.source);
state.templateCreateSending = false;
state.templateCreateCreated = createdPipelineName(detail, name);
await refreshPipelines();
} catch (error) {
state.templateCreateSending = false;
state.templateCreateError = describeError(error);
}
renderContent();
}
/**
* Refresh just the pipeline summaries after a create so the new row appears when
* the operator returns to the Pipelines list. A failed refresh keeps the created
* name and is surfaced through the banner rather than discarded.
*/
async function refreshPipelines() {
try {
state.pipelines = await repo.listPipelines();
state.pipelinesLoaded = true;
} catch (error) {
state.error = describeError(error);
}
}
function templateTabButton(tab, label) {
return h("button", {
class: `minitab${state.templateTab === tab ? " active" : ""}`,
@@ -4932,6 +5133,13 @@ async function validateTemplate(entry) {
function selectTemplate(key) {
state.selectedTemplateKey = key;
state.templateTab = "summary";
// A different template reseeds the create dialog, so a name typed for one
// template can never be submitted against another.
state.templateCreateOpen = false;
state.templateCreateName = "";
state.templateCreateSending = false;
state.templateCreateError = "";
state.templateCreateCreated = null;
renderContent();
}
@@ -5155,6 +5363,11 @@ document.addEventListener("keydown", (event) => {
return;
}
if (document.querySelector(".artifact-viewer") || document.querySelector(".change-viewer")) return;
if (state.templateCreateOpen) {
event.preventDefault();
closeTemplateCreateDialog();
return;
}
if (state.actionError) {
event.preventDefault();
dismissActionError();
+6
View File
@@ -16,6 +16,12 @@ export const Protocol = Object.freeze({
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",
+23
View File
@@ -60,6 +60,29 @@ export class PipelinesRepository {
return response.graph;
}
/**
* Creates a new pipeline from a definition `source` (the `submit` command),
* create-only, mirroring `PipelinesRepository.createPipeline`: the name must
* not already exist, so this can only ever add a draft and never overwrite a
* retained pipeline. A blank name is refused before anything is sent, exactly
* like the Android client; the sent name is trimmed. No run is started.
*/
async submit(name, source) {
if (!String(name ?? "").trim()) {
throw new ProtocolError("Enter a pipeline name.");
}
const response = await this.#client.call({
type: Protocol.SUBMIT,
name: String(name).trim(),
source,
create_only: true,
});
if (!response.detail) {
throw new ProtocolError("The server returned no pipeline detail.");
}
return response.detail;
}
async listRuns() {
const response = await this.#client.call({ type: Protocol.LIST_RUNS });
return { runs: response.runs ?? [], usage: response.usage ?? null };
+65
View File
@@ -91,3 +91,68 @@ export function templateStageSummary(graph) {
export function templateGraphNote(graph) {
return graph == null ? TEMPLATE_UNPARSED_GRAPH_NOTE : TEMPLATE_GRAPH_NOTE;
}
// --- Create a pipeline from this template (P5) -----------------------------
// The wording, verbatim from android/.../TemplateDetailScreen.kt's
// CreateFromTemplateDialog. The dialog validates the template's source first,
// then submits it create-only; nothing runs and an existing name is never
// overwritten.
/** The template-detail action that opens the create dialog. */
export const CREATE_ACTION_LABEL = "Create pipeline from this template";
/** The dialog's single required field label. */
export const CREATE_NAME_LABEL = "New pipeline name (required)";
/** The dialog's explanatory note (verbatim; states that nothing runs). */
export const CREATE_NOTE =
"Creates a new draft pipeline on the server from this template's source; it is not run.";
/** The confirm button's idle label. */
export const CREATE_CONFIRM = "Create";
/** The confirm button's in-flight label. */
export const CREATE_SENDING = "Creating…";
/** The dismiss button's label before a success. */
export const CREATE_CANCEL = "Cancel";
/** The dismiss button's label after a success. */
export const CREATE_CLOSE = "Close";
/** The dialog's title: `Create from {name}`, a blank name falling back to the key. */
export function createFormTitle(entry) {
return `Create from ${templateDetailName(entry)}`;
}
/**
* Whether the dialog can submit: not while sending, not once a pipeline has
* been created, and never with a blank (or whitespace-only) name.
*/
export function createFormValid(name, { sending = false, created = null } = {}) {
return !sending && created == null && String(name ?? "").trim() !== "";
}
/** The confirm button's label: "Creating…" while in flight, else "Create". */
export function createConfirmLabel(sending) {
return sending ? CREATE_SENDING : CREATE_CONFIRM;
}
/** The dismiss button's label: "Close" once a pipeline was created, else "Cancel". */
export function createDismissLabel(created) {
return created != null ? CREATE_CLOSE : CREATE_CANCEL;
}
/** The dialog's success line: `Created "{name}". It is in the Pipelines list.` */
export function createSuccessMessage(created) {
return `Created "${created}". It is in the Pipelines list.`;
}
/**
* The name to report after a successful submit: the created pipeline's own name
* when the server returned one, else the name the operator submitted (trimmed),
* mirroring `created = it.name.ifBlank { name.trim() }`.
*/
export function createdPipelineName(detail, submittedName) {
return String(detail?.name ?? "").trim() || String(submittedName ?? "").trim();
}