merge: name a workflow's declared inputs on the work-request form (06nq)

# Conflicts:
#	ui/dist/assets/index.js
This commit is contained in:
sam committed 2026-09-30 07:23:07 +10:00
commit 173c0dacba
7 files changed
+333 -22

No files matched your search

+37 -1
View File
@@ -20,6 +20,11 @@ import { api } from "@/lib/api";
import { delivered } from "@/lib/delivered";
import { useIdentitiesStore } from "@/stores/identities";
import type { WorkflowDefinition, WorkflowStats } from "@/workflows/workflow-rows";
import {
declaredInputs,
inputValues,
missingRequiredInputs,
} from "@/workflows/work-request";
/** Starting work enters Archie's normal admitted task queue, not a side door. */
const emit = defineEmits<{ started: [taskId: number]; cancel: [] }>();
@@ -52,18 +57,27 @@ const workflow = ref("");
const title = ref("");
const instructions = ref("");
const identity = ref("");
// One text field per declared input, by input name: the chosen workflow's
// declaration decides what is rendered and what the request carries.
const inputText = ref<Record<string, string>>({});
watchEffect(() => {
if (!workflow.value && definitions.value[0]) workflow.value = definitions.value[0].id;
if (!identity.value && actors.value[0]) identity.value = actors.value[0].id;
});
const selected = computed(() => definitions.value.find((d) => d.id === workflow.value));
const declared = computed(() => declaredInputs(selected.value));
const missing = computed(() => missingRequiredInputs(declared.value, inputText.value));
const statFor = (id: string) => stats.value.find((s) => s.workflow === id);
const identityName = computed(() => actors.value.find((a) => a.id === identity.value)?.display_name ?? "nobody");
const submitting = ref(false);
const error = ref("");
const ready = computed(
() => !!(repository.value.trim() && workflow.value && title.value.trim() && instructions.value.trim() && identity.value),
() =>
!!(repository.value.trim() && workflow.value && title.value.trim() && instructions.value.trim() && identity.value) &&
missing.value.length === 0,
);
async function submit() {
if (!ready.value || submitting.value) return;
@@ -76,6 +90,7 @@ async function submit() {
workflow: workflow.value,
title: title.value.trim(),
instructions: instructions.value,
inputs: inputValues(declared.value, inputText.value),
});
emit("started", result.task_id);
} catch (err) {
@@ -128,6 +143,27 @@ async function submit() {
<p v-if="!definitions.length && !loadError" class="text-xs text-fg-subtle">No enabled workflows.</p>
</div>
<!-- One field per input the chosen workflow declares: pr-review cannot run
without its pr_number, and the server refuses a request that does not
set what the workflow declares. The declared type is the hint, so the
value is typed the way the workflow reads it. -->
<div v-if="declared.length" class="grid gap-3">
<div v-for="field in declared" :key="field.name" class="grid gap-1.5">
<label :for="`${uid}-input-${field.name}`" class="text-[13px] font-medium">
<span class="font-mono">{{ field.name }}</span>
<span v-if="field.required" class="text-fg-subtle"> · required</span>
</label>
<Input
:id="`${uid}-input-${field.name}`"
v-model="inputText[field.name]"
:type="field.type === 'number' ? 'number' : 'text'"
class="font-mono"
:required="field.required"
/>
<p class="text-xs text-fg-subtle">{{ field.type }}</p>
</div>
</div>
<div class="grid gap-1.5">
<label :for="`${uid}-title`" class="text-[13px] font-medium">Title</label>
<Input :id="`${uid}-title`" v-model="title" required />
+95
View File
@@ -0,0 +1,95 @@
/**
* The work-request form's input vocabulary: what the chosen workflow declares,
* and how one field's text becomes the typed value the daemon checks.
*
* A workflow is startable only by naming what it declares. pr-review requires
* pr_number, so a request that does not set it is refused by the handler
* (archie-core-06nq) rather than admitted and then parked at dispatch. The
* declaration comes from the definitions endpoint, so a workflow that starts
* declaring inputs needs no change here.
*/
import type { WorkflowDefinition } from "./workflow-rows";
/** One input a workflow declares, as the form renders it. */
export interface DeclaredInput {
name: string;
/** The declared type: string, number, bool, object, array or any. */
type: string;
required: boolean;
}
/**
* declaredInputs lists the inputs a workflow declares, by name. Sorted, so the
* fields keep their places while the operator types and across re-renders.
*/
export function declaredInputs(
definition?: WorkflowDefinition,
): DeclaredInput[] {
return Object.entries(definition?.inputs ?? {})
.map(([name, spec]) => ({
name,
type: spec.type,
required: spec.required === true,
}))
.sort((a, b) => a.name.localeCompare(b.name));
}
/**
* missingRequiredInputs names the declared inputs that are required and still
* empty, so the form disables Start instead of earning the server's refusal.
*/
export function missingRequiredInputs(
declared: DeclaredInput[],
text: Record<string, string>,
): string[] {
return declared
.filter((input) => input.required && !(text[input.name] ?? "").trim())
.map((input) => input.name);
}
/**
* inputValue is the typed value one field's text stands for. Text that does not
* read as the declared type travels as it was typed, so the server's check
* names the mismatch rather than this guessing at a value nobody typed.
*/
export function inputValue(text: string, type: string): unknown {
switch (type) {
case "number": {
const trimmed = text.trim();
return trimmed !== "" && !Number.isNaN(Number(trimmed))
? Number(trimmed)
: text;
}
case "bool":
return text === "true" ? true : text === "false" ? false : text;
case "string":
return text;
default:
// object, array and any: the field's text is JSON.
try {
return JSON.parse(text);
} catch {
return text;
}
}
}
/**
* inputValues builds the `inputs` object the request carries: the declared
* inputs the operator filled in. An input left empty is absent rather than an
* empty string, so an optional input is simply unset and a required one is
* caught by missingRequiredInputs before the request is sent.
*/
export function inputValues(
declared: DeclaredInput[],
text: Record<string, string>,
): Record<string, unknown> {
const inputs: Record<string, unknown> = {};
for (const input of declared) {
const value = text[input.name];
if (value === undefined || value === "") continue;
inputs[input.name] = inputValue(value, input.type);
}
return inputs;
}
+5
View File
@@ -26,6 +26,11 @@ export interface WorkflowDefinition {
name?: string;
origin?: string;
enabled?: boolean;
/** The inputs the workflow declares, by name. A workflow that declares none
* is started without any, which is every workflow but pr-review today. */
inputs?: Record<string, { type: string; required?: boolean }>;
/** none, optional or required; a workflow that declares none needs a repository. */
repository?: string;
}
/** One table row: a definition, its statistics, or both. */