web: run-level actions — human decision, cancel, retry and rename (R11–R14)
Add the run-level operator actions to the browser run detail, matching the Android client's wording and wire frames: - R11 human decision: pure model in src/actions.js (pendingDecision, lastWaitingStep, waitingPrompt/waitingOptions, humanOptions, decisionTargetLabel, DecisionDraft) plus the decision card and sheet; decide_run sends run_id, the chosen option and trimmed feedback. - R12 cancel: a Cancel run action offered only while executing; the Android confirm copy; cancel_run then a silent get_run refresh. - R13 retry: offered only for a loaded, non-executing failed run; resume is the default (no retry_mode, like Android) with a browser-only Restart from start secondary that sends retry_mode:"restart". - R14 rename: an inline set_run_title field; refreshes the run and its list row. - One shared Action failed dialog for all of the above. Add the protocol constants and typed builders, a hand-written dark-palette section for the card/sheet/dialogs, focused unit tests for the helpers and request shapes, and ui-smoke captures for the new states. Update PARITY.md: R11 stays partial (no live waiting run), R12–R14 done with the stated shown-not-executed and Android-divergence notes. Also harden openRunDetail() in the UI smoke: the tabstrip already exists from the previously opened run, so wait for the target run's identity line before asserting on its actions (review finding).
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
// Pure, DOM-free logic for the run-level operator actions the browser client
|
||||
// offers on a run detail: the pending human decision (R11), cancel (R12), retry
|
||||
// / restart (R13) and rename (R14). Ported from the Android client so the
|
||||
// browser asks for and shows exactly the same things:
|
||||
// ui/Decision.kt PendingDecision, DecisionOption,
|
||||
// pendingDecision, decisionTargetLabel,
|
||||
// DecisionDraft
|
||||
// data/protocol/HumanDecision.kt lastWaitingStep, waitingPrompt,
|
||||
// waitingOptions, humanOptions
|
||||
// ui/components/DecisionPrompt.kt the decision card and sheet wording
|
||||
// ui/screens/RunDetailScreen.kt the cancel/retry dialogs, Action failed
|
||||
//
|
||||
// Nothing here touches the DOM or imports the app: the decision model, the
|
||||
// action eligibility rules and every user-visible string are unit-tested without
|
||||
// a browser. The caller sets each string with textContent, never innerHTML.
|
||||
import { nodeLabel, resolveTarget, runLabelFor } from "./runDetail.js";
|
||||
|
||||
/** Run status while parked on a person (mirrors protocol.RunStatusWaiting). */
|
||||
export const RUN_STATUS_WAITING = "waiting";
|
||||
|
||||
/** The waiting step's status, i.e. the step a decision answers. */
|
||||
export const STEP_STATUS_WAITING = "waiting";
|
||||
|
||||
/** Run status a retry is offered for. */
|
||||
export const RUN_STATUS_FAILED = "failed";
|
||||
|
||||
/** Waiting evidence keys, the wire contract the server records. */
|
||||
export const WAITING_PROMPT_KEY = "prompt";
|
||||
export const WAITING_OPTIONS_KEY = "options";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Decision evidence (data/protocol/HumanDecision.kt)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function str(value) {
|
||||
return value == null ? "" : String(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* The most recent step a run is waiting on (the last waiting step), or null when
|
||||
* no step is waiting. Mirrors `tui.lastWaitingStep` / `HumanDecision.kt`.
|
||||
*/
|
||||
export function lastWaitingStep(steps) {
|
||||
const list = steps ?? [];
|
||||
for (let index = list.length - 1; index >= 0; index -= 1) {
|
||||
if (list[index]?.status === STEP_STATUS_WAITING) return list[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The recorded operator instructions from a waiting step's output, or "" when
|
||||
* none were recorded. Mirrors `protocol.WaitingPrompt`.
|
||||
*/
|
||||
export function waitingPrompt(output) {
|
||||
const value = output?.[WAITING_PROMPT_KEY];
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* The recorded selectable options from a waiting step's output, in recorded
|
||||
* order. Strings only, a malformed/blank entry dropped, an absent key yields an
|
||||
* empty list — exactly like `protocol.WaitingOptions` / `waitingOptions`.
|
||||
*/
|
||||
export function waitingOptions(output) {
|
||||
const value = output?.[WAITING_OPTIONS_KEY];
|
||||
if (!Array.isArray(value)) return [];
|
||||
return value.filter((entry) => typeof entry === "string" && entry.trim() !== "");
|
||||
}
|
||||
|
||||
/**
|
||||
* A stage's selectable outcomes: its non-`error` edges in sorted order. Mirrors
|
||||
* `stage.HumanOptions`, the fallback when a waiting step recorded no options.
|
||||
*/
|
||||
export function humanOptions(edges) {
|
||||
return Object.keys(edges ?? {})
|
||||
.filter((key) => key !== "error")
|
||||
.sort();
|
||||
}
|
||||
|
||||
/**
|
||||
* The resolved target label for one option: the author's target with the `#`
|
||||
* shorthand resolved and terminals named as the graph names them. Blank when the
|
||||
* option's edge is not declared, so the sheet omits the detail.
|
||||
*/
|
||||
export function decisionTargetLabel(option, target) {
|
||||
if (target == null || String(target).trim() === "") return "";
|
||||
return nodeLabel(resolveTarget(option, target));
|
||||
}
|
||||
|
||||
/**
|
||||
* The pending decision a run is waiting on, or null when it is not waiting (or
|
||||
* recorded no selectable options). The waiting step's own evidence wins over the
|
||||
* pinned graph; the graph only supplies the target labels and, for a step from
|
||||
* an older server, the option set itself. Mirrors `pendingDecision`.
|
||||
*/
|
||||
export function pendingDecision(run) {
|
||||
if (run == null || run.status !== RUN_STATUS_WAITING) return null;
|
||||
const step = lastWaitingStep(run.steps ?? []);
|
||||
const stepStage = str(step?.stage).trim() !== "" ? String(step.stage) : "";
|
||||
const runStage = str(run.current_stage).trim() !== "" ? String(run.current_stage) : "";
|
||||
const stageKey = stepStage !== "" ? stepStage : runStage;
|
||||
if (stageKey === "") return null;
|
||||
|
||||
const declared = (run.graph?.stages ?? []).find((candidate) => candidate?.key === stageKey) ?? null;
|
||||
const recorded = waitingOptions(step?.output);
|
||||
const keys = recorded.length > 0 ? recorded : humanOptions(declared?.edges);
|
||||
if (keys.length === 0) return null;
|
||||
|
||||
const edges = declared?.edges ?? {};
|
||||
const options = keys.map((key) => ({ key, target: decisionTargetLabel(key, edges[key]) }));
|
||||
const stepPrompt = waitingPrompt(step?.output);
|
||||
const instructions = stepPrompt.trim() !== "" ? stepPrompt : str(declared?.prompt);
|
||||
return {
|
||||
runId: run.id,
|
||||
runLabel: runLabelFor(run),
|
||||
stageKey,
|
||||
instructions,
|
||||
options,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The operator's in-progress answer: the chosen option and optional feedback.
|
||||
* Pure, so the deliberate-confirm rule (nothing is sent until an option is
|
||||
* chosen and Confirm is pressed) is unit-tested without a device. Mirrors
|
||||
* `DecisionDraft`.
|
||||
*/
|
||||
export class DecisionDraft {
|
||||
constructor(selected = null, feedback = "") {
|
||||
this.selected = selected;
|
||||
this.feedback = feedback;
|
||||
}
|
||||
|
||||
/** A decision is only sendable once the operator has chosen one option. */
|
||||
get canSubmit() {
|
||||
return typeof this.selected === "string" && this.selected.trim() !== "";
|
||||
}
|
||||
|
||||
/** Selecting an option is not an answer: it only enables the confirm. */
|
||||
select(option) {
|
||||
return new DecisionDraft(option, this.feedback);
|
||||
}
|
||||
|
||||
/** Feedback is optional and carried verbatim (trimmed by the sender). */
|
||||
withFeedback(text) {
|
||||
return new DecisionDraft(this.selected, String(text ?? ""));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Action eligibility (RunDetailScreen.kt)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** Cancel is offered only while the run is executing. */
|
||||
export function canCancel(run) {
|
||||
return Boolean(run?.executing);
|
||||
}
|
||||
|
||||
/** Retry is offered only for a loaded, non-executing, `failed` run. */
|
||||
export function canRetry(run) {
|
||||
return run != null && !run.executing && run.status === RUN_STATUS_FAILED;
|
||||
}
|
||||
|
||||
/** The retry modes available for a run: resume (default) and restart. */
|
||||
export function retryModes(run) {
|
||||
return canRetry(run) ? ["resume", "restart"] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* A fresh idempotency key for a retry request. The server requires one and caps
|
||||
* it at 128 characters (PipelinesRepository.MAX_REQUEST_KEY); this stays well
|
||||
* inside that bound and unique per attempt.
|
||||
*/
|
||||
export function retryRequestKey(runId, now = Date.now(), random = Math.random) {
|
||||
const suffix = Math.floor((Number(random()) || 0) * 1e9).toString(36);
|
||||
return `web-retry-${runId}-${now}-${suffix}`;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wording (DecisionPrompt.kt / RunDetailScreen.kt), verbatim
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export const DECISION_CARD_TITLE = "Waiting for your decision";
|
||||
export const DECISION_ACTION = "Decide";
|
||||
export const FEEDBACK_LABEL = "Feedback (optional)";
|
||||
export const DECISION_CANCEL = "Cancel";
|
||||
export const DECISION_CONFIRM = "Confirm decision";
|
||||
export const DECISION_SENDING = "Sending…";
|
||||
|
||||
export const CANCEL_DIALOG_MESSAGE = "This asks the server to stop the active run.";
|
||||
export const CANCEL_CONFIRM = "Cancel run";
|
||||
export const RETRY_DIALOG_MESSAGE =
|
||||
"Only failed runs can be retried. The server starts a new run from the same input.";
|
||||
export const RETRY_CONFIRM = "Retry";
|
||||
export const DISMISS_KEEP = "Keep";
|
||||
// The restart confirm is browser-only (Android exposes resume alone): it states
|
||||
// plainly that it replays the whole pipeline instead of resuming the failed
|
||||
// stage, so the more destructive choice is never ambiguous.
|
||||
export const RESTART_CONFIRM = "Restart from start";
|
||||
export const RESTART_DIALOG_MESSAGE =
|
||||
"This replays the whole pipeline from the start instead of resuming the failed stage.";
|
||||
|
||||
export const RENAME_ACTION = "Rename";
|
||||
export const RENAME_SAVE = "Save";
|
||||
export const RENAME_CANCEL = "Cancel";
|
||||
export const RENAME_FIELD_LABEL = "Run title";
|
||||
|
||||
export const ACTION_FAILED_TITLE = "Action failed";
|
||||
export const ACTION_FAILED_OK = "OK";
|
||||
|
||||
/** The decision card's meta line: `{stage} · run {id} · {runLabel}`. */
|
||||
export function decisionCardMeta(decision) {
|
||||
return `${decision.stageKey} · run ${decision.runId} · ${decision.runLabel}`;
|
||||
}
|
||||
|
||||
/** The sheet title: `Decide {stage}`. */
|
||||
export function decisionSheetTitle(stageKey) {
|
||||
return `Decide ${stageKey}`;
|
||||
}
|
||||
|
||||
/** The sheet meta line: `run {id} · {runLabel}`. */
|
||||
export function decisionSheetMeta(decision) {
|
||||
return `run ${decision.runId} · ${decision.runLabel}`;
|
||||
}
|
||||
|
||||
/** The option's target line, `→ {target}`, or "" when the target is unknown. */
|
||||
export function optionTargetText(target) {
|
||||
return String(target ?? "").trim() === "" ? "" : `→ ${target}`;
|
||||
}
|
||||
|
||||
/** The cancel dialog's title: `Cancel run {id}?`. */
|
||||
export function cancelDialogTitle(runId) {
|
||||
return `Cancel run ${runId}?`;
|
||||
}
|
||||
|
||||
/** The retry dialog's title: `Retry run {id}?`. */
|
||||
export function retryDialogTitle(runId) {
|
||||
return `Retry run ${runId}?`;
|
||||
}
|
||||
|
||||
/** The restart dialog's title: `Restart run {id}?`. */
|
||||
export function restartDialogTitle(runId) {
|
||||
return `Restart run ${runId}?`;
|
||||
}
|
||||
+497
-10
@@ -133,6 +133,39 @@ import {
|
||||
runChangesHeader,
|
||||
runChangesNote,
|
||||
} from "./changes.js";
|
||||
import {
|
||||
ACTION_FAILED_OK,
|
||||
ACTION_FAILED_TITLE,
|
||||
CANCEL_CONFIRM,
|
||||
CANCEL_DIALOG_MESSAGE,
|
||||
DECISION_ACTION,
|
||||
DECISION_CANCEL,
|
||||
DECISION_CARD_TITLE,
|
||||
DECISION_CONFIRM,
|
||||
DECISION_SENDING,
|
||||
DISMISS_KEEP,
|
||||
DecisionDraft,
|
||||
FEEDBACK_LABEL,
|
||||
RENAME_ACTION,
|
||||
RENAME_CANCEL,
|
||||
RENAME_FIELD_LABEL,
|
||||
RENAME_SAVE,
|
||||
RESTART_CONFIRM,
|
||||
RESTART_DIALOG_MESSAGE,
|
||||
RETRY_CONFIRM,
|
||||
RETRY_DIALOG_MESSAGE,
|
||||
canCancel,
|
||||
canRetry,
|
||||
cancelDialogTitle,
|
||||
decisionCardMeta,
|
||||
decisionSheetMeta,
|
||||
decisionSheetTitle,
|
||||
optionTargetText,
|
||||
pendingDecision,
|
||||
restartDialogTitle,
|
||||
retryDialogTitle,
|
||||
retryRequestKey,
|
||||
} from "./actions.js";
|
||||
|
||||
const STORAGE_KEY = "pipelines.web.serverUrl.v2";
|
||||
|
||||
@@ -209,6 +242,20 @@ const state = {
|
||||
runSections: new Set(),
|
||||
runStagePane: null,
|
||||
runStageSections: new Set(),
|
||||
// Run-level operator actions (R11–R14): the decision the open sheet renders
|
||||
// (retained across a refused send so the server's own reason can be shown even
|
||||
// after a refresh), the sheet's draft/sending/error, the action awaiting a
|
||||
// confirm dialog, the in-progress rename title (null when not editing) and the
|
||||
// one shared Action-failed dialog.
|
||||
runDecision: null,
|
||||
decisionOpen: false,
|
||||
decisionDraft: new DecisionDraft(),
|
||||
decisionSending: false,
|
||||
decisionError: "",
|
||||
confirmKind: null,
|
||||
renameValue: null,
|
||||
renameBusy: false,
|
||||
actionError: "",
|
||||
};
|
||||
|
||||
let runPoll = null;
|
||||
@@ -1184,6 +1231,12 @@ function renderRunDetail() {
|
||||
pane.append(h("div", { class: "muted pad", text: "Select a run." }));
|
||||
return pane;
|
||||
}
|
||||
// A run parked on a person surfaces its decision above the tabs, exactly where
|
||||
// the Android run detail does, so opening the run is enough — no tab hunt.
|
||||
const decision = pendingDecision(d);
|
||||
if (decision) pane.append(renderDecisionCard(decision));
|
||||
const actions = renderRunActions(d);
|
||||
if (actions) pane.append(actions);
|
||||
pane.append(
|
||||
h(
|
||||
"div",
|
||||
@@ -1212,6 +1265,10 @@ function renderRunDetail() {
|
||||
pane.append(renderRunSummaryTab(d));
|
||||
}
|
||||
if (state.runStagePane) pane.append(renderStagePane(d));
|
||||
if (state.decisionOpen && state.runDecision) pane.append(renderDecisionSheet(state.runDecision));
|
||||
const confirm = renderConfirmDialog(d);
|
||||
if (confirm) pane.append(confirm);
|
||||
if (state.actionError) pane.append(renderActionFailedDialog());
|
||||
return pane;
|
||||
}
|
||||
|
||||
@@ -1253,7 +1310,7 @@ function latestVisitIndex(d, key) {
|
||||
/** The Summary tab: identity, chip row, key/value rows, diagnostic and gallery. */
|
||||
function renderRunSummaryTab(d) {
|
||||
const wrap = h("div", { class: "run-tab-body" });
|
||||
wrap.append(h("h2", { class: "run-detail-title", text: runLabelFor(d) }));
|
||||
wrap.append(renderRunTitleRow(d));
|
||||
const status = runStateOf(d.status);
|
||||
const chips = h("div", { class: "run-chip-row" });
|
||||
chips.append(h("span", { class: `chip chip-${status}`, text: d.status || status }));
|
||||
@@ -1912,6 +1969,413 @@ function closeStagePane() {
|
||||
focusTarget?.focus();
|
||||
}
|
||||
|
||||
// --- Run-level operator actions (R11–R14) ----------------------------------
|
||||
|
||||
/** The one-line error text of a refused action (the server's own message). */
|
||||
function describeError(error) {
|
||||
return error?.message || String(error);
|
||||
}
|
||||
|
||||
/**
|
||||
* The decision card (R11): a prominent "Waiting for your decision" banner with
|
||||
* the stage/run identity and a deliberate Decide action. Only rendered when the
|
||||
* loaded run is genuinely waiting on a person.
|
||||
*/
|
||||
function renderDecisionCard(decision) {
|
||||
const card = h("div", { class: "decision-card" });
|
||||
card.append(h("span", { class: "decision-card-icon", "aria-hidden": "true", text: "\u270B" }));
|
||||
const text = h("div", { class: "decision-card-text" });
|
||||
text.append(h("div", { class: "decision-card-title", text: DECISION_CARD_TITLE }));
|
||||
text.append(h("div", { class: "decision-card-meta muted", text: decisionCardMeta(decision) }));
|
||||
card.append(text);
|
||||
card.append(
|
||||
h("button", {
|
||||
class: "decision-open",
|
||||
type: "button",
|
||||
text: DECISION_ACTION,
|
||||
onclick: () => openDecisionSheet(decision),
|
||||
}),
|
||||
);
|
||||
return card;
|
||||
}
|
||||
|
||||
/** Cancel/Retry actions, shown exactly per the app's eligibility rules. */
|
||||
function renderRunActions(d) {
|
||||
const buttons = [];
|
||||
if (canCancel(d)) {
|
||||
buttons.push(
|
||||
h("button", {
|
||||
class: "run-action cancel-run",
|
||||
type: "button",
|
||||
text: "Cancel run",
|
||||
onclick: () => openConfirm({ kind: "cancel", runId: d.id }),
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (canRetry(d)) {
|
||||
buttons.push(
|
||||
h("button", {
|
||||
class: "run-action retry-run",
|
||||
type: "button",
|
||||
text: "Retry",
|
||||
onclick: () => openConfirm({ kind: "retry", runId: d.id }),
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (!buttons.length) return null;
|
||||
return h("div", { class: "run-actions" }, ...buttons);
|
||||
}
|
||||
|
||||
/** Open the decision sheet with a fresh draft; nothing is sent until Confirm. */
|
||||
function openDecisionSheet(decision) {
|
||||
state.runDecision = decision;
|
||||
state.decisionOpen = true;
|
||||
state.decisionDraft = new DecisionDraft();
|
||||
state.decisionError = "";
|
||||
renderContent();
|
||||
document.querySelector(".decision-sheet .decision-option")?.focus();
|
||||
}
|
||||
|
||||
/** Dismiss the decision sheet (never while a decision is in flight). */
|
||||
function closeDecisionSheet() {
|
||||
if (state.decisionSending) return;
|
||||
const wasOpen = state.decisionOpen;
|
||||
state.decisionOpen = false;
|
||||
state.runDecision = null;
|
||||
state.decisionError = "";
|
||||
state.decisionDraft = new DecisionDraft();
|
||||
if (!wasOpen) return;
|
||||
renderContent();
|
||||
document.querySelector(".decision-card .decision-open")?.focus();
|
||||
}
|
||||
|
||||
/**
|
||||
* The decision sheet (R11): the waiting stage, the author's recorded
|
||||
* instructions, one selectable row per option (with its resolved target when
|
||||
* declared), the optional feedback field and the deliberate confirm. Selecting a
|
||||
* row never sends; a refusal keeps the sheet open with the server's exact reason.
|
||||
*/
|
||||
function renderDecisionSheet(decision) {
|
||||
const overlay = h("div", {
|
||||
class: "decision-sheet",
|
||||
role: "dialog",
|
||||
"aria-modal": "true",
|
||||
"aria-label": decisionSheetTitle(decision.stageKey),
|
||||
});
|
||||
overlay.addEventListener("click", (event) => {
|
||||
if (event.target === overlay) closeDecisionSheet();
|
||||
});
|
||||
const sheet = h("div", { class: "decision-sheet-panel" });
|
||||
sheet.append(h("h2", { class: "decision-sheet-title", text: decisionSheetTitle(decision.stageKey) }));
|
||||
sheet.append(h("div", { class: "decision-sheet-meta muted", text: decisionSheetMeta(decision) }));
|
||||
if (String(decision.instructions ?? "").trim() !== "") {
|
||||
sheet.append(h("p", { class: "decision-instructions", text: decision.instructions }));
|
||||
}
|
||||
|
||||
const options = h("div", { class: "decision-options", role: "radiogroup", "aria-label": "Options" });
|
||||
for (const option of decision.options) {
|
||||
const selected = state.decisionDraft.selected === option.key;
|
||||
const row = h("button", {
|
||||
class: `decision-option${selected ? " selected" : ""}`,
|
||||
type: "button",
|
||||
role: "radio",
|
||||
"aria-checked": selected ? "true" : "false",
|
||||
"data-option": option.key,
|
||||
onclick: () => {
|
||||
state.decisionDraft = state.decisionDraft.select(option.key);
|
||||
renderContent();
|
||||
},
|
||||
});
|
||||
row.append(h("span", { class: "decision-radio", "aria-hidden": "true" }));
|
||||
const body = h("span", { class: "decision-option-body" });
|
||||
body.append(h("span", { class: "decision-option-key", text: option.key }));
|
||||
const target = optionTargetText(option.target);
|
||||
if (target !== "") body.append(h("span", { class: "decision-option-target muted", text: target }));
|
||||
row.append(body);
|
||||
options.append(row);
|
||||
}
|
||||
sheet.append(options);
|
||||
|
||||
const field = h("label", { class: "decision-field" });
|
||||
field.append(h("span", { class: "decision-field-label", text: FEEDBACK_LABEL }));
|
||||
field.append(
|
||||
h("input", {
|
||||
class: "decision-feedback",
|
||||
type: "text",
|
||||
value: state.decisionDraft.feedback,
|
||||
spellcheck: "false",
|
||||
oninput: (event) => {
|
||||
state.decisionDraft = state.decisionDraft.withFeedback(event.target.value);
|
||||
},
|
||||
}),
|
||||
);
|
||||
sheet.append(field);
|
||||
if (state.decisionError) sheet.append(h("div", { class: "decision-error bad", text: state.decisionError }));
|
||||
|
||||
const actions = h("div", { class: "decision-sheet-actions" });
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "ghost decision-cancel",
|
||||
type: "button",
|
||||
text: DECISION_CANCEL,
|
||||
disabled: state.decisionSending,
|
||||
onclick: closeDecisionSheet,
|
||||
}),
|
||||
);
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "decision-confirm",
|
||||
type: "button",
|
||||
text: state.decisionSending ? DECISION_SENDING : DECISION_CONFIRM,
|
||||
disabled: !state.decisionDraft.canSubmit || state.decisionSending,
|
||||
onclick: () => confirmDecision(decision),
|
||||
}),
|
||||
);
|
||||
sheet.append(actions);
|
||||
overlay.append(sheet);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/** Send the chosen decision; on refusal show the server's reason and re-read. */
|
||||
async function confirmDecision(decision) {
|
||||
if (state.decisionSending || !state.decisionDraft.canSubmit) return;
|
||||
const option = state.decisionDraft.selected;
|
||||
state.decisionSending = true;
|
||||
state.decisionError = "";
|
||||
renderContent();
|
||||
try {
|
||||
await repo.decideRun(decision.runId, {
|
||||
stage: decision.stageKey,
|
||||
option,
|
||||
feedback: state.decisionDraft.feedback,
|
||||
});
|
||||
state.decisionSending = false;
|
||||
state.decisionOpen = false;
|
||||
state.runDecision = null;
|
||||
state.decisionDraft = new DecisionDraft();
|
||||
await selectRun(decision.runId, { silent: true });
|
||||
} catch (error) {
|
||||
state.decisionSending = false;
|
||||
state.decisionError = describeError(error);
|
||||
await selectRun(decision.runId, { silent: true });
|
||||
}
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/** Open one of the shared confirm dialogs (cancel / retry / restart). */
|
||||
function openConfirm(kind) {
|
||||
state.confirmKind = kind;
|
||||
renderContent();
|
||||
}
|
||||
|
||||
function dismissConfirm() {
|
||||
state.confirmKind = null;
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* The shared confirm dialog: the exact Android title/message for cancel and
|
||||
* retry (with Keep as the dismiss), plus the browser-only "Restart from start"
|
||||
* secondary confirm that plainly states the whole-pipeline replay. The dismiss
|
||||
* button is "Keep".
|
||||
*/
|
||||
function renderConfirmDialog(d) {
|
||||
const kind = state.confirmKind;
|
||||
if (!kind) return null;
|
||||
const runId = kind.runId ?? d.id;
|
||||
let title;
|
||||
let message;
|
||||
let confirmLabel;
|
||||
let secondary = null;
|
||||
if (kind.kind === "cancel") {
|
||||
title = cancelDialogTitle(runId);
|
||||
message = CANCEL_DIALOG_MESSAGE;
|
||||
confirmLabel = CANCEL_CONFIRM;
|
||||
} else if (kind.kind === "retry") {
|
||||
title = retryDialogTitle(runId);
|
||||
message = RETRY_DIALOG_MESSAGE;
|
||||
confirmLabel = RETRY_CONFIRM;
|
||||
secondary = { label: RESTART_CONFIRM, next: { kind: "restart", runId } };
|
||||
} else {
|
||||
title = restartDialogTitle(runId);
|
||||
message = RESTART_DIALOG_MESSAGE;
|
||||
confirmLabel = RESTART_CONFIRM;
|
||||
}
|
||||
|
||||
const overlay = h("div", {
|
||||
class: `confirm-dialog confirm-${kind.kind}`,
|
||||
role: "dialog",
|
||||
"aria-modal": "true",
|
||||
"aria-label": title,
|
||||
});
|
||||
overlay.addEventListener("click", (event) => {
|
||||
if (event.target === overlay) dismissConfirm();
|
||||
});
|
||||
const panel = h("div", { class: "confirm-panel" });
|
||||
panel.append(h("h2", { class: "confirm-title", text: title }));
|
||||
panel.append(h("p", { class: "confirm-message", text: message }));
|
||||
const actions = h("div", { class: "confirm-actions" });
|
||||
if (secondary) {
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "ghost confirm-secondary",
|
||||
type: "button",
|
||||
text: secondary.label,
|
||||
onclick: () => openConfirm(secondary.next),
|
||||
}),
|
||||
);
|
||||
}
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "ghost confirm-dismiss",
|
||||
type: "button",
|
||||
text: DISMISS_KEEP,
|
||||
onclick: dismissConfirm,
|
||||
}),
|
||||
);
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "confirm-accept",
|
||||
type: "button",
|
||||
text: confirmLabel,
|
||||
onclick: () => acceptConfirm(kind),
|
||||
}),
|
||||
);
|
||||
panel.append(actions);
|
||||
overlay.append(panel);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the confirmed action, then a silent get_run refresh — exactly as the
|
||||
* Android client does. A server refusal is reported through the one shared
|
||||
* Action-failed dialog.
|
||||
*/
|
||||
async function acceptConfirm(kind) {
|
||||
const runId = kind.runId ?? state.runDetail?.id;
|
||||
state.confirmKind = null;
|
||||
renderContent();
|
||||
try {
|
||||
if (kind.kind === "cancel") {
|
||||
await repo.cancelRun(runId);
|
||||
} else {
|
||||
const mode = kind.kind === "restart" ? "restart" : "resume";
|
||||
await repo.retryRun(runId, { mode, requestKey: retryRequestKey(runId) });
|
||||
}
|
||||
} catch (error) {
|
||||
state.actionError = describeError(error);
|
||||
}
|
||||
await selectRun(runId, { silent: true });
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/** The one shared "Action failed" dialog (title, the server's message, OK). */
|
||||
function renderActionFailedDialog() {
|
||||
const overlay = h("div", {
|
||||
class: "action-failed",
|
||||
role: "dialog",
|
||||
"aria-modal": "true",
|
||||
"aria-label": ACTION_FAILED_TITLE,
|
||||
});
|
||||
overlay.addEventListener("click", (event) => {
|
||||
if (event.target === overlay) dismissActionError();
|
||||
});
|
||||
const panel = h("div", { class: "action-failed-panel" });
|
||||
panel.append(h("h2", { class: "action-failed-title", text: ACTION_FAILED_TITLE }));
|
||||
panel.append(h("p", { class: "action-failed-message", text: state.actionError }));
|
||||
panel.append(
|
||||
h("button", { class: "action-failed-ok", type: "button", text: ACTION_FAILED_OK, onclick: dismissActionError }),
|
||||
);
|
||||
overlay.append(panel);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
function dismissActionError() {
|
||||
state.actionError = "";
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/** The Summary title row: the run's label plus the inline rename control (R14). */
|
||||
function renderRunTitleRow(d) {
|
||||
const row = h("div", { class: "run-title-row" });
|
||||
row.append(h("h2", { class: "run-detail-title", text: runLabelFor(d) }));
|
||||
if (state.renameValue == null) {
|
||||
row.append(
|
||||
h("button", {
|
||||
class: "ghost rename-open",
|
||||
type: "button",
|
||||
text: RENAME_ACTION,
|
||||
onclick: () => {
|
||||
state.renameValue = String(d.title ?? "");
|
||||
renderContent();
|
||||
},
|
||||
}),
|
||||
);
|
||||
return row;
|
||||
}
|
||||
const field = h("div", { class: "rename-field" });
|
||||
field.append(
|
||||
h("input", {
|
||||
class: "rename-input",
|
||||
type: "text",
|
||||
value: state.renameValue,
|
||||
"aria-label": RENAME_FIELD_LABEL,
|
||||
oninput: (event) => {
|
||||
state.renameValue = event.target.value;
|
||||
},
|
||||
}),
|
||||
);
|
||||
field.append(
|
||||
h("button", {
|
||||
class: "rename-save",
|
||||
type: "button",
|
||||
text: RENAME_SAVE,
|
||||
onclick: () => saveRunTitle(d.id),
|
||||
}),
|
||||
);
|
||||
field.append(
|
||||
h("button", {
|
||||
class: "ghost rename-cancel",
|
||||
type: "button",
|
||||
text: RENAME_CANCEL,
|
||||
onclick: () => {
|
||||
state.renameValue = null;
|
||||
renderContent();
|
||||
},
|
||||
}),
|
||||
);
|
||||
row.append(field);
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename the run: send `set_run_title`, then update the run detail and the runs
|
||||
* list row. A refusal (for example a blank title) keeps the field open and shows
|
||||
* the server's exact reason through the shared Action-failed dialog.
|
||||
*/
|
||||
async function saveRunTitle(id) {
|
||||
if (state.renameBusy) return;
|
||||
state.renameBusy = true;
|
||||
try {
|
||||
const detail = await repo.setRunTitle(id, String(state.renameValue ?? ""));
|
||||
state.renameValue = null;
|
||||
applyRunTitle(id, detail);
|
||||
await selectRun(id, { silent: true });
|
||||
} catch (error) {
|
||||
state.actionError = describeError(error);
|
||||
renderContent();
|
||||
} finally {
|
||||
state.renameBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Apply a renamed run to the loaded detail and the runs-list row. */
|
||||
function applyRunTitle(id, detail) {
|
||||
if (state.runDetail && state.runDetail.id === id && detail) state.runDetail = detail;
|
||||
const title = String(detail?.title ?? "");
|
||||
state.runs = state.runs.map((run) => (run.id === id ? { ...run, title } : run));
|
||||
}
|
||||
|
||||
/** Whether the configured server URL can resolve a server-relative artifact. */
|
||||
function artifactsResolvable() {
|
||||
return resolveArtifactUrl(state.url, "/artifacts/0/0/probe") != null;
|
||||
@@ -2441,6 +2905,16 @@ async function selectRun(id, { silent = false } = {}) {
|
||||
state.runSections = new Set();
|
||||
state.runStagePane = null;
|
||||
state.runStageSections = new Set();
|
||||
// A different run reseeds the run-level action state, so a decision sheet,
|
||||
// confirm dialog, rename field or failure report never leaks across runs.
|
||||
state.runDecision = null;
|
||||
state.decisionOpen = false;
|
||||
state.decisionDraft = new DecisionDraft();
|
||||
state.decisionSending = false;
|
||||
state.decisionError = "";
|
||||
state.confirmKind = null;
|
||||
state.renameValue = null;
|
||||
state.actionError = "";
|
||||
renderContent();
|
||||
}
|
||||
try {
|
||||
@@ -2541,16 +3015,29 @@ client.addEventListener("state", (event) => {
|
||||
render();
|
||||
});
|
||||
|
||||
// The stage pane is a modal dialog: Escape closes it (a stacked overlay — the
|
||||
// artifact viewer or the diff viewer, when either is above — owns Escape first).
|
||||
// Registered once; it is a no-op when no pane is open.
|
||||
// The stage pane, the decision sheet and the confirm/Action-failed dialogs are
|
||||
// modal: Escape closes the topmost one (the artifact viewer or the diff viewer,
|
||||
// when either is above, owns Escape first via its own listener). Registered
|
||||
// once; every branch is a no-op when nothing is open.
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (
|
||||
event.key === "Escape" &&
|
||||
state.runStagePane &&
|
||||
!document.querySelector(".artifact-viewer") &&
|
||||
!document.querySelector(".change-viewer")
|
||||
) {
|
||||
if (event.key !== "Escape") return;
|
||||
if (document.querySelector(".artifact-viewer") || document.querySelector(".change-viewer")) return;
|
||||
if (state.actionError) {
|
||||
event.preventDefault();
|
||||
dismissActionError();
|
||||
return;
|
||||
}
|
||||
if (state.confirmKind) {
|
||||
event.preventDefault();
|
||||
dismissConfirm();
|
||||
return;
|
||||
}
|
||||
if (state.decisionOpen) {
|
||||
event.preventDefault();
|
||||
closeDecisionSheet();
|
||||
return;
|
||||
}
|
||||
if (state.runStagePane) {
|
||||
event.preventDefault();
|
||||
closeStagePane();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,14 @@ export const Protocol = Object.freeze({
|
||||
GET_RUN: "get_run",
|
||||
RUN: "run",
|
||||
|
||||
// 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",
|
||||
|
||||
SUCCESS_END: "#success",
|
||||
FAILURE_END: "#failure",
|
||||
});
|
||||
|
||||
@@ -72,4 +72,64 @@ export class PipelinesRepository {
|
||||
}
|
||||
return response.run_detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers a run's waiting human stage with the chosen `option` and optional
|
||||
* `feedback` (mirrors PipelinesRepository.decideRun). The stage is sent only
|
||||
* when non-blank and the feedback is trimmed, exactly like the Android client;
|
||||
* a refused decision rejects with the server's own reason (a ProtocolError).
|
||||
*/
|
||||
async decideRun(id, { stage, option, feedback } = {}) {
|
||||
const request = { type: Protocol.DECIDE_RUN, run_id: id, option };
|
||||
if (stage != null && String(stage).trim() !== "") request.stage = stage;
|
||||
const trimmedFeedback = String(feedback ?? "").trim();
|
||||
if (trimmedFeedback !== "") request.feedback = trimmedFeedback;
|
||||
const response = await this.#client.call(request);
|
||||
if (!response.run_detail) {
|
||||
throw new ProtocolError("The server returned no run detail.");
|
||||
}
|
||||
return response.run_detail;
|
||||
}
|
||||
|
||||
/** Cancels a run; mirrors PipelinesRepository.cancelRun (exactly run_id). */
|
||||
async cancelRun(id) {
|
||||
const response = await this.#client.call({ type: Protocol.CANCEL_RUN, run_id: id });
|
||||
if (!response.run_detail) {
|
||||
throw new ProtocolError("The server returned no run detail.");
|
||||
}
|
||||
return response.run_detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retries a terminal failed run. `request_key` is always sent (the retry is
|
||||
* its own idempotent run); `retry_mode` is sent only for an explicit
|
||||
* `restart`, so the server's default (resume) applies exactly as the Android
|
||||
* client's mode-less call.
|
||||
*/
|
||||
async retryRun(id, { mode = null, requestKey } = {}) {
|
||||
const request = {
|
||||
type: Protocol.RETRY_RUN,
|
||||
run_id: id,
|
||||
request_key: requestKey ?? "",
|
||||
};
|
||||
if (mode === "restart") request.retry_mode = "restart";
|
||||
const response = await this.#client.call(request);
|
||||
if (!response.run_detail) {
|
||||
throw new ProtocolError("The server returned no run detail.");
|
||||
}
|
||||
return response.run_detail;
|
||||
}
|
||||
|
||||
/** Renames a run's stored title; mirrors the set_run_title wire command. */
|
||||
async setRunTitle(id, title) {
|
||||
const response = await this.#client.call({
|
||||
type: Protocol.SET_RUN_TITLE,
|
||||
run_id: id,
|
||||
title,
|
||||
});
|
||||
if (!response.run_detail) {
|
||||
throw new ProtocolError("The server returned no run detail.");
|
||||
}
|
||||
return response.run_detail;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user