feat(ui): workflow canvas cards expand in place instead of side panels

This commit is contained in:
sam committed 2026-10-18 01:59:09 +11:00
1 parent e3add11a1d
commit 7fc4f4f9d7
21 files changed
+691 -610

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
<script setup lang="ts">
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
// A Select whose options may include the empty value, which reka-ui reserves
// for clearing: it travels as a sentinel and comes back as "".
const EMPTY = "\u0000";
defineOptions({ inheritAttrs: false });
type Option = { value: string; label: string; disabled?: boolean };
defineProps<{ modelValue: string; options: Option[]; placeholder?: string; disabled?: boolean; size?: "sm" | "default"; class?: string }>();
const emit = defineEmits<{ "update:modelValue": [string] }>();
</script>
<template>
<Select :model-value="modelValue === '' && options.some((o) => o.value === '') ? EMPTY : modelValue || undefined" :disabled="disabled" @update:model-value="emit('update:modelValue', $event === EMPTY ? '' : String($event))">
<SelectTrigger :size="size ?? 'sm'" :class="$props.class" v-bind="$attrs"><SelectValue :placeholder="placeholder" /></SelectTrigger>
<SelectContent>
<SelectItem v-for="option in options" :key="option.value" :value="option.value === '' ? EMPTY : option.value" :disabled="option.disabled">{{ option.label }}</SelectItem>
</SelectContent>
</Select>
</template>
+48
View File
@@ -0,0 +1,48 @@
<script setup lang="ts">
import { computed } from "vue";
import { Plus, Trash2 } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Switch } from "@/components/ui/switch";
import OptionSelect from "./OptionSelect.vue";
import { setWorkflowField, workflowField } from "./workflow-edit";
// A workflow's declared inputs or outputs: name, type and whether required.
const props = defineProps<{ yaml: string; field: "inputs" | "outputs" }>();
const emit = defineEmits<{ "update:yaml": [string] }>();
type Spec = { type?: string; required?: boolean };
const TYPES = ["string", "number", "bool", "object", "array", "any"].map((value) => ({ value, label: value }));
const list = computed(() => Object.entries((workflowField(props.yaml, props.field) as Record<string, Spec> | undefined) ?? {}));
function write(entries: [string, Spec][]): void {
emit("update:yaml", setWorkflowField(props.yaml, props.field, Object.fromEntries(entries.filter(([name]) => name))));
}
function edit(index: number, name: string, spec: Spec): void {
write(list.value.map((entry, i) => (i === index ? [name, spec] : entry)));
}
function add(): void {
const stem = props.field.slice(0, -1);
let n = list.value.length + 1;
while (list.value.some(([name]) => name === `${stem}_${n}`)) n++;
write([...list.value, [`${stem}_${n}`, { type: "string" }]]);
}
</script>
<template>
<section class="space-y-1.5">
<div class="flex items-center text-xs font-medium text-muted-foreground">
{{ field === "inputs" ? "Inputs" : "Outputs" }}
<Button type="button" variant="ghost" size="xs" class="ml-auto" @click="add"><Plus data-icon="inline-start" />Add</Button>
</div>
<div v-if="list.length" class="divide-y divide-border rounded-md border border-border">
<div v-for="([name, spec], i) in list" :key="i" class="flex items-center gap-2 px-2 py-1.5">
<Input :model-value="name" class="h-7 min-w-0 flex-1 font-mono text-xs" :aria-label="`${field} name`" @change="edit(i, ($event.target as HTMLInputElement).value.trim(), spec)" />
<OptionSelect :model-value="spec.type ?? 'string'" :options="TYPES" class="w-24" :aria-label="`${name} type`" @update:model-value="edit(i, name, { ...spec, type: $event })" />
<Switch :model-value="spec.required === true" :title="spec.required ? 'Required' : 'Optional'" :aria-label="`${name} required`" @update:model-value="edit(i, name, { ...spec, required: $event || undefined })" />
<Button type="button" variant="ghost" size="icon-xs" :aria-label="`Remove ${name}`" @click="write(list.filter((_, j) => j !== i))"><Trash2 /></Button>
</div>
</div>
</section>
</template>
+82 -148
View File
@@ -1,7 +1,6 @@
<script setup lang="ts">
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
import { computed, ref, useId } from "vue";
import { CircleHelp, Plus, Trash2, X } from "@lucide/vue";
import { ChevronDown, CircleHelp, Plus, Trash2 } from "@lucide/vue";
import { parse, stringify } from "yaml";
import { Button } from "@/components/ui/button";
@@ -9,18 +8,17 @@ import { DurationInput } from "@/components/ui/duration-input";
import { Input } from "@/components/ui/input";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { stepIcon } from "./step-icons";
import { addBranch, branchingOf, deleteBranch, renameBranch, earlierStepIDs, replaceStep, stepAt, workflowField, type StepPath, type StepRecord } from "./workflow-edit";
import type { WorkflowDefinitionEntry } from "@/stores/workflows";
import type { InputSpec } from "./bind-event";
import { inputValue } from "./work-request";
import OptionSelect from "./OptionSelect.vue";
import WorkflowPicker from "./WorkflowPicker.vue";
import { stepTitle } from "./workflow-graph";
import { stepControlsProblem, settingsProblem, type SettingsSchema, type StepTypeInfo } from "./workflow-yaml";
const uid = useId();
const props = defineProps<{ yaml: string; path: StepPath; vocabulary: StepTypeInfo[]; workflows: WorkflowDefinitionEntry[]; modelAliases: string[] }>();
const emit = defineEmits<{ "update:yaml": [string]; close: []; remove: [] }>();
const emit = defineEmits<{ "update:yaml": [string] }>();
const step = computed<StepRecord>(() => stepAt(props.yaml, props.path) ?? {});
const branching = computed(() => branchingOf(step.value));
@@ -66,8 +64,8 @@ function kindOf(key: string, schema: SettingsSchema): Kind {
return "yaml";
}
// The setting that says what the step does leads, on its own; choices and
// switches follow in a compact block; structured settings come last.
// The setting that says what the step does leads, on its own; everything else
// waits behind More.
const fields = computed(() => {
const entries = Object.entries(info.value?.settings?.properties ?? {})
.filter(([key]) => type.value !== "workflow.call" || !["inputs", "outputs"].includes(key))
@@ -80,6 +78,8 @@ const fields = computed(() => {
long: rest.filter((field) => ["text", "lines", "yaml"].includes(field.kind)),
};
});
const more = ref(!fields.value.lead && !branching.value);
const choices = (options: string[]) => [{ value: "", label: "Default" }, ...options.map((option) => ({ value: option, label: option }))];
function write(next: StepRecord): void {
// id and type lead, the way a step is read.
@@ -117,10 +117,13 @@ const callerOutputs = computed(() => Object.entries((workflowField(props.yaml, "
const inputMap = computed(() => (settings.value.inputs ?? {}) as Record<string, unknown>);
const outputMap = computed(() => (settings.value.outputs ?? {}) as Record<string, string>);
const isReference = (value: unknown) => typeof value === "string" && value.startsWith("inputs.");
const structured = (spec: InputSpec) => ["object", "array"].includes(spec.type ?? "");
const inputText = (name: string) => inputMap.value[name] === undefined ? "" : String(inputMap.value[name]);
function setCallInput(name: string, value: string, inputType?: string): void {
setSetting("inputs", { ...inputMap.value, [name]: value === "" ? undefined : isReference(value) ? value : inputValue(value, inputType ?? "string") });
}
const matching = (list: [string, InputSpec][], spec: InputSpec, prefix: string) =>
list.filter(([, other]) => other.type === spec.type || other.type === "any" || spec.type === "any").map(([key]) => ({ value: `${prefix}.${key}`, label: key }));
// A reference goes into the text setting last focused: that is how this step
// is connected to an earlier step's result.
@@ -146,87 +149,65 @@ const asYaml = (value: unknown) => (value === undefined ? "" : stringify(value).
const label = (key: string, schema: SettingsSchema) =>
schema.title ?? key.replaceAll("_", " ").replace(/^./, (c) => c.toUpperCase());
const text = (key: string) => (typeof settings.value[key] === "string" ? (settings.value[key] as string) : "");
const ON_FAILURE = [{ value: "", label: "Park the task" }, { value: "continue", label: "Continue" }];
</script>
<template>
<aside class="flex h-full w-[24rem] flex-col border-l border-border bg-card shadow-xl">
<header class="flex items-center gap-2.5 border-b border-border px-4 py-3">
<span class="flex size-8 shrink-0 items-center justify-center rounded-md bg-secondary text-primary">
<component :is="stepIcon(type)" class="size-4" />
</span>
<div class="min-w-0 flex-1">
<Input
:model-value="(step.id as string) ?? ''"
class="h-7 truncate border-transparent px-1 font-medium shadow-none hover:border-input dark:bg-transparent"
:placeholder="stepTitle(type)"
aria-label="Step id"
@update:model-value="(value) => setField('id', String(value))"
/>
<div class="truncate font-mono text-[11px] text-fg-subtle">{{ type }}</div>
<div class="space-y-4 px-3 py-3">
<p v-if="problem" class="rounded-md bg-danger/10 px-2.5 py-1.5 text-xs text-danger" role="alert">{{ problem }}</p>
<section v-if="branching" class="space-y-3">
<label v-if="type === 'switch'" class="block space-y-1.5">
<span class="text-xs font-medium text-muted-foreground" title="The value whose case runs; a case named default runs when none matches">Switch on</span>
<Input :model-value="branching.on" class="font-mono" placeholder="steps.assess.result.fit" :list="`${uid}-switch-on`" @change="setOn(($event.target as HTMLInputElement).value.trim())" />
<datalist :id="`${uid}-switch-on`"><option v-for="id in earlier" :key="id" :value="`steps.${id}.result.`" /></datalist>
</label>
<div class="text-xs font-medium text-muted-foreground">{{ type === "switch" ? "Cases" : "Branches" }}</div>
<div v-for="name in branches" :key="name" class="flex items-center gap-2">
<Input :model-value="name" :class="type === 'switch' && 'font-mono'" :aria-label="`${type === 'switch' ? 'Case' : 'Branch'} ${name}`" @change="changeBranch('rename', name, ($event.target as HTMLInputElement).value.trim())" />
<Button type="button" variant="ghost" size="icon-sm" :aria-label="`Remove ${name}`" :disabled="branches.length <= minBranches" @click="changeBranch('delete', name)"><Trash2 /></Button>
</div>
<Button type="button" variant="ghost" size="icon-sm" aria-label="Close" @click="emit('close')"><X /></Button>
</header>
<div class="flex items-center gap-2">
<Input v-model="newBranch" :aria-label="type === 'switch' ? 'New case value' : 'New branch name'" :placeholder="type === 'switch' ? 'Value, or default' : 'Branch name'" @keydown.enter.prevent="changeBranch('add', newBranch.trim())" />
<Button type="button" size="icon-sm" variant="outline" :aria-label="type === 'switch' ? 'Add case' : 'Add branch'" :disabled="!newBranch.trim()" @click="changeBranch('add', newBranch.trim())"><Plus /></Button>
</div>
<p v-if="branchError" role="alert" class="text-xs text-danger">{{ branchError }}</p>
</section>
<div class="flex-1 space-y-5 overflow-y-auto px-4 py-4">
<p v-if="problem" class="rounded-md bg-danger/10 px-2.5 py-1.5 text-xs text-danger" role="alert">{{ problem }}</p>
<section v-if="branching" class="space-y-3">
<template v-if="type === 'switch'">
<label class="block space-y-1.5">
<span class="text-xs font-medium text-muted-foreground" title="The value whose case runs; a case named default runs when none matches">Switch on</span>
<Input :model-value="branching.on" class="font-mono" placeholder="steps.assess.result.fit" list="switch-on" @change="setOn(($event.target as HTMLInputElement).value.trim())" />
<datalist id="switch-on"><option v-for="id in earlier" :key="id" :value="`steps.${id}.result.`" /></datalist>
</label>
<section v-if="fields.lead" class="space-y-1.5">
<div class="flex items-center gap-1 text-xs font-medium text-muted-foreground" :title="fields.lead.schema.description">
{{ label(fields.lead.key, fields.lead.schema) }}
<CircleHelp v-if="fields.lead.schema.description" class="size-3 text-fg-subtle" />
</div>
<WorkflowPicker v-if="fields.lead.kind === 'workflow'" :value="text(fields.lead.key)" :workflows="workflows" :label="label(fields.lead.key, fields.lead.schema)" @pick="setTarget(fields.lead.key, $event)" />
<OptionSelect v-else-if="fields.lead.kind === 'select'" class="w-full" :model-value="text(fields.lead.key)" :options="choices(fields.lead.options)" :aria-label="label(fields.lead.key, fields.lead.schema)" @update:model-value="setSetting(fields.lead.key, $event || undefined)" />
<Textarea
v-else-if="fields.lead.kind === 'text'"
:model-value="text(fields.lead.key)"
class="min-h-32 text-[13px] leading-relaxed"
@focus="focused = fields.lead.key"
@update:model-value="setSetting(fields.lead.key, String($event))"
/>
<Input
v-else
:model-value="text(fields.lead.key)"
@focus="focused = fields.lead.key"
@update:model-value="setSetting(fields.lead.key, String($event))"
/>
<div v-if="earlier.length && fields.lead.kind !== 'select'" class="flex flex-wrap items-center gap-1 pt-0.5">
<span class="text-[11px] text-fg-subtle">Insert</span>
<template v-for="id in earlier" :key="id">
<Button type="button" variant="outline" size="xs" class="font-mono" @click="reference(id, 'summary')">{{ id }}</Button>
<Button type="button" variant="outline" size="xs" class="font-mono" @click="reference(id, 'result')">{{ id }}.result</Button>
</template>
<div class="text-xs font-medium text-muted-foreground">{{ type === "switch" ? "Cases" : "Branches" }}</div>
<div v-for="name in branches" :key="name" class="flex items-center gap-2">
<Input :model-value="name" :class="type === 'switch' && 'font-mono'" :aria-label="`${type === 'switch' ? 'Case' : 'Branch'} ${name}`" @change="changeBranch('rename', name, ($event.target as HTMLInputElement).value.trim())" />
<Button type="button" variant="ghost" size="icon-sm" :aria-label="`Remove ${name}`" :disabled="branches.length <= minBranches" @click="changeBranch('delete', name)"><Trash2 /></Button>
</div>
<div class="flex items-center gap-2">
<Input v-model="newBranch" :aria-label="type === 'switch' ? 'New case value' : 'New branch name'" :placeholder="type === 'switch' ? 'Value, or default' : 'Branch name'" @keydown.enter.prevent="changeBranch('add', newBranch.trim())" />
<Button type="button" size="icon-sm" variant="outline" :aria-label="type === 'switch' ? 'Add case' : 'Add branch'" :disabled="!newBranch.trim()" @click="changeBranch('add', newBranch.trim())"><Plus /></Button>
</div>
<p v-if="branchError" role="alert" class="text-xs text-danger">{{ branchError }}</p>
</section>
</div>
</section>
<section v-if="fields.lead" class="space-y-1.5">
<div class="flex items-center gap-1 text-xs font-medium text-muted-foreground" :title="fields.lead.schema.description">
{{ label(fields.lead.key, fields.lead.schema) }}
<CircleHelp v-if="fields.lead.schema.description" class="size-3 text-fg-subtle" />
</div>
<WorkflowPicker v-if="fields.lead.kind === 'workflow'" :value="text(fields.lead.key)" :workflows="workflows" :label="label(fields.lead.key, fields.lead.schema)" @pick="setTarget(fields.lead.key, $event)" />
<NativeSelect
size="sm"
v-else-if="fields.lead.kind === 'select'" class="w-full"
:model-value="text(fields.lead.key)"
@update:model-value="(value) => setSetting(fields.lead.key, String(value) || undefined)"
>
<NativeSelectOption value="">Default</NativeSelectOption>
<NativeSelectOption v-for="option in fields.lead.options" :key="option" :value="option">{{ option }}</NativeSelectOption>
</NativeSelect>
<Textarea
v-else-if="fields.lead.kind === 'text'"
:model-value="text(fields.lead.key)"
class="min-h-40 text-[13px] leading-relaxed"
@focus="focused = fields.lead.key"
@update:model-value="setSetting(fields.lead.key, String($event))"
/>
<Input
v-else
:model-value="text(fields.lead.key)"
@focus="focused = fields.lead.key"
@update:model-value="setSetting(fields.lead.key, String($event))"
/>
<div v-if="earlier.length && fields.lead.kind !== 'select'" class="flex flex-wrap items-center gap-1 pt-0.5">
<span class="text-[11px] text-fg-subtle">Insert</span>
<template v-for="id in earlier" :key="id">
<Button type="button" variant="outline" size="xs" class="font-mono" @click="reference(id, 'summary')">{{ id }}</Button>
<Button type="button" variant="outline" size="xs" class="font-mono" @click="reference(id, 'result')">{{ id }}.result</Button>
</template>
</div>
</section>
<Button type="button" variant="ghost" size="xs" class="-ml-2 text-muted-foreground" :aria-expanded="more" @click="more = !more">
<ChevronDown data-icon="inline-start" class="transition-transform" :class="!more && '-rotate-90'" />More
</Button>
<template v-if="more">
<section v-if="fields.compact.length" class="divide-y divide-border rounded-md border border-border">
<div v-for="field in fields.compact" :key="field.key" class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex flex-1 items-center gap-1 text-[13px]" :title="field.schema.description">
@@ -234,20 +215,8 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
<CircleHelp v-if="field.schema.description" class="size-3 text-fg-subtle" />
</span>
<WorkflowPicker v-if="field.kind === 'workflow'" class="max-w-48" :value="text(field.key)" :workflows="workflows" :label="label(field.key, field.schema)" @pick="setTarget(field.key, $event)" />
<Switch
v-else-if="field.kind === 'boolean'"
:model-value="settings[field.key] === true"
@update:model-value="setSetting(field.key, $event || undefined)"
/>
<NativeSelect
size="sm"
v-else-if="field.kind === 'select'" class="max-w-40"
:model-value="text(field.key)"
@update:model-value="(value) => setSetting(field.key, String(value) || undefined)"
>
<NativeSelectOption value="">Default</NativeSelectOption>
<NativeSelectOption v-for="option in field.options" :key="option" :value="option">{{ option }}</NativeSelectOption>
</NativeSelect>
<Switch v-else-if="field.kind === 'boolean'" :model-value="settings[field.key] === true" @update:model-value="setSetting(field.key, $event || undefined)" />
<OptionSelect v-else-if="field.kind === 'select'" class="w-40" :model-value="text(field.key)" :options="choices(field.options)" :aria-label="label(field.key, field.schema)" @update:model-value="setSetting(field.key, $event || undefined)" />
<Input
v-else-if="field.kind === 'number'"
type="number"
@@ -255,13 +224,7 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
:model-value="(settings[field.key] as number | undefined) ?? ''"
@update:model-value="(value) => setSetting(field.key, String(value) === '' ? undefined : Number(String(value)))"
/>
<Input
v-else
class="h-7 w-40 text-[13px]"
:model-value="text(field.key)"
@focus="focused = field.key"
@update:model-value="(value) => setSetting(field.key, String(value))"
/>
<Input v-else class="h-7 w-40 text-[13px]" :model-value="text(field.key)" @focus="focused = field.key" @update:model-value="(value) => setSetting(field.key, String(value))" />
</div>
</section>
@@ -270,17 +233,16 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
<div class="text-xs font-medium text-muted-foreground">Inputs</div>
<div v-for="[name, spec] in callInputs" :key="name" class="space-y-1.5">
<div class="text-[13px]">{{ name }}<span v-if="spec.required" class="text-danger"> *</span><span class="ml-2 text-xs text-fg-subtle">{{ spec.type }}</span></div>
<NativeSelect size="sm" :aria-label="`${name} source`" class="w-full" :model-value="isReference(inputMap[name]) || ['object', 'array'].includes(spec.type ?? '') ? 'input' : 'value'" @update:model-value="(value) => setCallInput(name, String(value) === 'input' ? 'inputs.' : '')">
<NativeSelectOption v-if="!['object', 'array'].includes(spec.type ?? '')" value="value">Value</NativeSelectOption>
<NativeSelectOption value="input">Caller input</NativeSelectOption>
</NativeSelect>
<NativeSelect size="sm" v-if="isReference(inputMap[name]) || ['object', 'array'].includes(spec.type ?? '')" :aria-label="name" class="w-full" :model-value="inputText(name)" @update:model-value="(value) => setCallInput(name, String(value))">
<NativeSelectOption value="">Choose input</NativeSelectOption>
<NativeSelectOption v-for="[key] in callerInputs.filter(([, input]) => input.type === spec.type || input.type === 'any' || spec.type === 'any')" :key="key" :value="`inputs.${key}`">{{ key }}</NativeSelectOption>
</NativeSelect>
<NativeSelect size="sm" v-else-if="spec.type === 'bool'" :aria-label="name" class="w-full" :model-value="inputText(name)" @update:model-value="(value) => setCallInput(name, String(value), spec.type)">
<NativeSelectOption value="">Unset</NativeSelectOption><NativeSelectOption value="true">True</NativeSelectOption><NativeSelectOption value="false">False</NativeSelectOption>
</NativeSelect>
<OptionSelect
v-if="!structured(spec)"
class="w-full"
:aria-label="`${name} source`"
:model-value="isReference(inputMap[name]) ? 'input' : 'value'"
:options="[{ value: 'value', label: 'Value' }, { value: 'input', label: 'Caller input' }]"
@update:model-value="setCallInput(name, $event === 'input' ? 'inputs.' : '')"
/>
<OptionSelect v-if="isReference(inputMap[name]) || structured(spec)" class="w-full" :aria-label="name" placeholder="Choose input" :model-value="inputText(name) === 'inputs.' ? '' : inputText(name)" :options="matching(callerInputs, spec, 'inputs')" @update:model-value="setCallInput(name, $event)" />
<OptionSelect v-else-if="spec.type === 'bool'" class="w-full" :aria-label="name" :model-value="inputText(name)" :options="[{ value: '', label: 'Unset' }, { value: 'true', label: 'True' }, { value: 'false', label: 'False' }]" @update:model-value="setCallInput(name, $event, spec.type)" />
<Input v-else :aria-label="name" :type="spec.type === 'number' ? 'number' : 'text'" step="any" :model-value="inputText(name)" @update:model-value="setCallInput(name, String($event), spec.type)" />
</div>
</section>
@@ -288,10 +250,7 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
<div class="text-xs font-medium text-muted-foreground">Outputs</div>
<div v-for="[name, spec] in callOutputs" :key="name" class="space-y-1.5">
<div class="text-[13px]">{{ name }}<span class="ml-2 text-xs text-fg-subtle">{{ spec.type }}</span></div>
<NativeSelect size="sm" :aria-label="`${name} output`" :disabled="settings.wait !== true" class="w-full" :model-value="outputMap[name] ?? ''" @update:model-value="(value) => setSetting('outputs', { ...outputMap, [name]: String(value) || undefined })">
<NativeSelectOption value="">Do not publish</NativeSelectOption>
<NativeSelectOption v-for="[key] in callerOutputs.filter(([, output]) => output.type === spec.type || spec.type === 'any' || output.type === 'any')" :key="key" :value="`outputs.${key}`">{{ key }}</NativeSelectOption>
</NativeSelect>
<OptionSelect class="w-full" :aria-label="`${name} output`" :disabled="settings.wait !== true" :model-value="outputMap[name] ?? ''" :options="[{ value: '', label: 'Do not publish' }, ...matching(callerOutputs, spec, 'outputs')]" @update:model-value="setSetting('outputs', { ...outputMap, [name]: $event || undefined })" />
</div>
</section>
</template>
@@ -301,13 +260,7 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
{{ label(field.key, field.schema) }}
<CircleHelp v-if="field.schema.description" class="size-3 text-fg-subtle" />
</div>
<Textarea
v-if="field.kind === 'text'"
:model-value="text(field.key)"
class="min-h-20 text-[13px]"
@focus="focused = field.key"
@update:model-value="setSetting(field.key, String($event))"
/>
<Textarea v-if="field.kind === 'text'" :model-value="text(field.key)" class="min-h-20 text-[13px]" @focus="focused = field.key" @update:model-value="setSetting(field.key, String($event))" />
<Textarea
v-else-if="field.kind === 'lines'"
:model-value="Array.isArray(settings[field.key]) ? (settings[field.key] as string[]).join('\n') : ''"
@@ -316,23 +269,16 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
@update:model-value="setSetting(field.key, String($event).split('\n').filter(Boolean))"
/>
<template v-else>
<Textarea
:model-value="asYaml(settings[field.key])"
class="min-h-24 font-mono text-xs"
placeholder="YAML"
@change="setYamlSetting(field.key, ($event.target as HTMLTextAreaElement).value)"
/>
<Textarea :model-value="asYaml(settings[field.key])" class="min-h-24 font-mono text-xs" placeholder="YAML" @change="setYamlSetting(field.key, ($event.target as HTMLTextAreaElement).value)" />
<span v-if="yamlErrors[field.key]" class="text-xs text-danger">{{ yamlErrors[field.key] }}</span>
</template>
</section>
<section class="space-y-2">
<div class="text-xs font-medium text-muted-foreground">Flow</div>
<p class="text-xs text-fg-muted">Leave the condition empty to always run. Use a field such as inputs.enabled, !inputs.skip, or steps.plan.result.ready == true.</p>
<section class="space-y-1.5">
<p v-if="flowProblem" role="alert" class="text-xs text-danger">{{ flowProblem }}</p>
<div class="divide-y divide-border rounded-md border border-border">
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Run only when</span>
<span class="flex-1 text-[13px]" title="Empty always runs. A field such as inputs.enabled, !inputs.skip, or steps.plan.result.ready == true">Run only when</span>
<Input
class="h-7 w-48 font-mono text-xs"
placeholder="inputs.enabled"
@@ -343,14 +289,7 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
</label>
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">If it fails</span>
<NativeSelect
size="sm"
:model-value="(step.on_failure as string) ?? ''"
@update:model-value="(value) => setField('on_failure', String(value) || undefined)"
>
<NativeSelectOption value="">Park the task</NativeSelectOption>
<NativeSelectOption value="continue">Continue</NativeSelectOption>
</NativeSelect>
<OptionSelect class="w-36" aria-label="If it fails" :model-value="(step.on_failure as string) ?? ''" :options="ON_FAILURE" @update:model-value="setField('on_failure', $event || undefined)" />
</label>
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Attempts</span>
@@ -375,11 +314,6 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
</div>
</div>
</section>
</div>
<footer class="flex items-center border-t border-border px-4 py-2.5">
<Button type="button" variant="ghost" size="sm" class="text-danger" @click="emit('remove')"><Trash2 />Delete step</Button>
<Button type="button" size="sm" class="ml-auto" @click="emit('close')">Done</Button>
</footer>
</aside>
</template>
</div>
</template>
+124 -59
View File
@@ -1,12 +1,27 @@
<script setup lang="ts">
import { computed } from "vue";
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from "vue";
import { Handle, Position } from "@vue-flow/core";
import { Flag, Play, Repeat, SkipForward, Webhook, CircleDot, BookOpen, Workflow } from "@lucide/vue";
import { CircleAlert, CircleCheck, CircleMinus, CircleX, Copy, EllipsisVertical, Flag, LoaderCircle, Pencil, Play, Repeat, Settings2, SkipForward, Trash2 } from "@lucide/vue";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input";
import { stepIcon } from "./step-icons";
import { stepTitle, type StepNodeData } from "./workflow-graph";
const props = defineProps<{ data: StepNodeData }>();
export interface StepCardData extends StepNodeData {
expanded?: boolean;
editable?: boolean;
problem?: string;
onToggle?: () => void;
onResize?: (height: number) => void;
onRename?: (name: string) => void;
onDuplicate?: () => void;
onRemove?: () => void;
}
const props = defineProps<{ data: StepCardData }>();
const STATE_CLASSES: Record<string, string> = {
ok: "border-ok/70",
@@ -23,26 +38,31 @@ const MARK_CLASSES: Record<string, string> = {
};
const stateClass = computed(() => {
if (props.data.kind === "start") return "border-primary/60";
if (props.data.mark) return MARK_CLASSES[props.data.mark];
return STATE_CLASSES[props.data.run?.status ?? ""] ?? "border-border";
});
const ROLE_CLASSES: Record<string, string> = {
decision: "border-l-4 border-l-warn",
waiting: "border-l-4 border-l-info",
exit: "border-l-4 border-l-primary",
};
const STATUS = {
ok: { icon: CircleCheck, class: "text-ok", label: "Done" },
failed: { icon: CircleX, class: "text-danger", label: "Failed" },
interrupted: { icon: CircleAlert, class: "text-warn", label: "Interrupted" },
running: { icon: LoaderCircle, class: "text-info animate-spin", label: "Running" },
skipped: { icon: CircleMinus, class: "text-fg-subtle", label: "Skipped" },
} as const;
const status = computed(() => {
const run = props.data.run?.status;
if (run) return STATUS[run as keyof typeof STATUS] ?? null;
if (props.data.problem) return { icon: CircleAlert, class: "text-warn", label: props.data.problem };
if (props.data.editable && props.data.kind === "step") return { icon: CircleCheck, class: "text-ok/70", label: "Ready" };
return null;
});
const TRIGGER_ICONS = { issue: CircleDot, event: Webhook, playbook: BookOpen, workflow: Workflow };
const STATE_LABELS: Record<string, string> = {
ok: "Done",
failed: "Failed",
interrupted: "Interrupted",
running: "Running",
skipped: "Skipped",
};
const badge = computed(() => {
if (props.data.kind === "start") return { icon: Play, label: "Trigger" };
if (props.data.kind === "workflow") return { icon: Settings2, label: "Workflow" };
return { icon: stepIcon(props.data.type), label: stepTitle(props.data.type) };
});
const number = computed(() => (props.data.step ? `${Number(props.data.step)}.` : ""));
function duration(ms?: number): string {
if (ms === undefined) return "";
@@ -50,54 +70,99 @@ function duration(ms?: number): string {
const seconds = Math.round(ms / 1000);
return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
}
const card = ref<HTMLElement | null>(null);
let observer: ResizeObserver | undefined;
onMounted(() => {
observer = new ResizeObserver(() => props.data.onResize?.(card.value?.offsetHeight ?? 0));
if (card.value) observer.observe(card.value);
});
onBeforeUnmount(() => observer?.disconnect());
const renaming = ref(false);
const nameInput = ref<InstanceType<typeof Input> | null>(null);
async function rename(): Promise<void> {
renaming.value = true;
await nextTick();
((nameInput.value?.$el as HTMLInputElement | undefined) ?? null)?.select();
}
function commitRename(event: Event): void {
if (!renaming.value) return;
renaming.value = false;
const name = (event.target as HTMLInputElement).value.trim();
if (name !== (props.data.name ?? "")) props.data.onRename?.(name);
}
</script>
<template>
<div
class="w-60 rounded-lg border bg-card px-3 py-2 text-left shadow-sm"
:class="[stateClass, ROLE_CLASSES[data.role ?? ''], data.selected && 'ring-2 ring-ring', 'cursor-pointer transition-colors hover:border-muted-foreground']"
ref="card"
class="rounded-lg border bg-card text-left shadow-sm transition-[width,box-shadow] duration-200"
:class="[stateClass, data.expanded ? 'w-[26rem] shadow-lg ring-2 ring-ring/60' : 'w-60 hover:border-muted-foreground', data.onToggle && 'cursor-pointer']"
>
<Handle v-if="data.kind !== 'start'" type="target" :position="Position.Top" />
<Handle v-if="data.kind !== 'workflow'" type="target" :position="Position.Top" />
<Handle id="data-in" type="target" :position="Position.Right" class="!opacity-0" />
<div class="flex items-center gap-1.5">
<Play v-if="data.kind === 'start'" class="size-3.5 text-primary" aria-hidden="true" />
<component :is="stepIcon(data.type)" v-else class="size-3.5 shrink-0 text-muted-foreground" aria-hidden="true" />
<span v-if="data.step" class="font-mono text-[11px] text-fg-subtle">{{ data.step }}</span>
<span class="truncate text-sm font-medium" :title="data.title">{{ data.title }}</span>
</div>
<div v-if="data.mark" class="text-[11px] font-medium" :class="{ 'text-ok': data.mark === 'added', 'text-danger': data.mark === 'removed', 'text-warn': data.mark === 'changed' }">{{ data.mark === "added" ? "Added" : data.mark === "removed" ? "Removed" : "Changed" }}</div>
<div v-if="data.type && data.title !== stepTitle(data.type)" class="truncate font-mono text-[11px] text-fg-subtle">{{ data.type }}</div>
<ul v-if="data.kind === 'start' && data.triggers?.length" class="mt-1 space-y-0.5">
<li v-for="trigger in data.triggers" :key="trigger.kind + trigger.label" class="flex items-center gap-1.5 text-xs" :title="trigger.detail">
<component :is="TRIGGER_ICONS[trigger.kind]" class="size-3 shrink-0 text-primary" aria-hidden="true" />
<span class="truncate">{{ trigger.label }}</span>
<span v-if="trigger.detail" class="truncate text-fg-subtle">{{ trigger.detail }}</span>
</li>
</ul>
<div v-else-if="data.kind === 'start'" class="mt-0.5 text-xs text-muted-foreground">Nothing starts it yet.</div>
<div v-else-if="data.detail" class="mt-0.5 truncate text-xs text-muted-foreground" :title="data.detail">{{ data.detail }}</div>
<p v-if="data.summary" class="mt-1 line-clamp-2 text-xs leading-snug text-foreground/80" :title="data.summary">{{ data.summary }}</p>
<div v-if="data.when || data.retry || data.continues" class="mt-1 flex flex-wrap gap-1 text-[11px]">
<span v-if="data.when" class="flex max-w-full min-w-0 items-center gap-0.5 rounded bg-secondary px-1 font-mono" :title="`Runs only when ${data.when}`">
<Flag class="size-3 shrink-0" aria-hidden="true" /><span class="truncate">{{ data.when }}</span>
</span>
<span v-if="data.retry" class="flex items-center gap-0.5 rounded bg-secondary px-1" :title="`Up to ${data.retry} attempts`">
<Repeat class="size-3" aria-hidden="true" />×{{ data.retry }}
</span>
<span v-if="data.continues" class="flex items-center gap-0.5 rounded bg-secondary px-1" title="A failure does not stop the run">
<SkipForward class="size-3" aria-hidden="true" />continues</span>
</div>
<div
v-if="data.run"
class="mt-1 flex items-center gap-1.5 text-[11px]"
:class="{ 'text-ok': data.run.status === 'ok', 'text-danger': data.run.status === 'failed', 'text-info': data.run.status === 'running', 'text-warn': data.run.status === 'interrupted', 'text-fg-subtle': data.run.status === 'skipped' }"
:title="data.run.error || undefined"
>
<span class="size-1.5 rounded-full bg-current" aria-hidden="true" />
{{ STATE_LABELS[data.run.status] ?? data.run.status }}
<span v-if="data.run.duration_ms !== undefined" class="text-fg-subtle">{{ duration(data.run.duration_ms) }}</span>
<span v-if="data.run.error" class="truncate text-danger">{{ data.run.error }}</span>
<div class="px-3 py-2.5" @click="data.onToggle?.()">
<div class="flex items-center gap-1.5">
<Badge variant="outline" class="max-w-40 gap-1 bg-background">
<component :is="badge.icon" class="text-primary" aria-hidden="true" /><span class="truncate">{{ badge.label }}</span>
</Badge>
<span v-if="data.run?.duration_ms !== undefined" class="ml-auto font-mono text-[11px] text-fg-subtle">{{ duration(data.run.duration_ms) }}</span>
<component :is="status.icon" v-if="status" class="size-4 shrink-0" :class="[status.class, data.run?.duration_ms === undefined && 'ml-auto']" :aria-label="status.label" :title="data.run?.error || status.label" />
<span v-else class="ml-auto" />
<DropdownMenu v-if="data.editable && data.kind === 'step'">
<DropdownMenuTrigger as-child>
<Button variant="ghost" size="icon-xs" class="nodrag nopan -mr-1.5" aria-label="Step actions" @click.stop><EllipsisVertical /></Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" class="w-40">
<DropdownMenuItem @select="rename"><Pencil />Rename</DropdownMenuItem>
<DropdownMenuItem v-if="!['parallel', 'switch'].includes(data.type)" @select="data.onDuplicate?.()"><Copy />Duplicate</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive" @select="data.onRemove?.()"><Trash2 />Delete</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
<div class="mt-1.5 flex min-w-0 items-baseline gap-1 text-sm font-medium">
<span v-if="number" class="shrink-0">{{ number }}</span>
<Input
v-if="renaming"
ref="nameInput"
:model-value="data.name ?? ''"
class="nodrag nopan h-6 px-1 text-sm"
aria-label="Step id"
:placeholder="stepTitle(data.type)"
@click.stop
@keydown.enter.prevent="commitRename"
@keydown.esc="renaming = false"
@blur="commitRename"
/>
<span v-else class="truncate" :title="data.title">{{ data.title }}</span>
</div>
<div v-if="data.mark" class="text-[11px] font-medium" :class="{ 'text-ok': data.mark === 'added', 'text-danger': data.mark === 'removed', 'text-warn': data.mark === 'changed' }">{{ data.mark === "added" ? "Added" : data.mark === "removed" ? "Removed" : "Changed" }}</div>
<template v-if="!data.expanded">
<ul v-if="data.kind === 'start' && data.triggers?.length" class="mt-1 space-y-0.5">
<li v-for="trigger in data.triggers" :key="trigger.kind + trigger.label" class="truncate text-xs text-muted-foreground" :title="trigger.detail">{{ trigger.label }}</li>
</ul>
<div v-else-if="data.kind === 'start'" class="mt-0.5 text-xs text-muted-foreground">Manual runs only</div>
<div v-else-if="data.summary || data.detail" class="mt-0.5 truncate text-xs text-muted-foreground" :title="[data.detail, data.summary].filter(Boolean).join('\n')">{{ data.summary || data.detail }}</div>
<div v-if="data.when || data.retry || data.continues" class="mt-1 flex flex-wrap gap-1 text-[11px]">
<span v-if="data.when" class="flex max-w-full min-w-0 items-center gap-0.5 rounded bg-secondary px-1 font-mono" :title="`Runs only when ${data.when}`">
<Flag class="size-3 shrink-0" aria-hidden="true" /><span class="truncate">{{ data.when }}</span>
</span>
<span v-if="data.retry" class="flex items-center gap-0.5 rounded bg-secondary px-1" :title="`Up to ${data.retry} attempts`">
<Repeat class="size-3" aria-hidden="true" />×{{ data.retry }}
</span>
<span v-if="data.continues" class="flex items-center gap-0.5 rounded bg-secondary px-1" title="A failure does not stop the run">
<SkipForward class="size-3" aria-hidden="true" />continues</span>
</div>
<p v-if="data.run?.error" class="mt-1 line-clamp-2 text-[11px] text-danger" :title="data.run.error">{{ data.run.error }}</p>
</template>
</div>
<Transition enter-from-class="opacity-0 -translate-y-1" enter-active-class="transition duration-200" leave-to-class="opacity-0" leave-active-class="transition duration-100">
<div v-if="data.expanded" class="nodrag nopan nowheel cursor-auto border-t border-border" @click.stop>
<slot />
</div>
</Transition>
<Handle type="source" :position="Position.Bottom" />
<Handle id="data-out" type="source" :position="Position.Right" class="!opacity-0" />
<Handle v-if="data.type === 'switch'" id="otherwise" type="source" :position="Position.Right" class="!opacity-0" />
+51
View File
@@ -0,0 +1,51 @@
<script setup lang="ts">
import { ref } from "vue";
import { Plus } from "@lucide/vue";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { statusKind, statusLabel, type Binding } from "@/bindings/binding-draft";
import BindEvent from "./BindEvent.vue";
import SpecList from "./SpecList.vue";
import type { WorkflowTrigger } from "./workflow-triggers";
defineProps<{ yaml: string; triggers: WorkflowTrigger[] }>();
const emit = defineEmits<{ "update:yaml": [string]; bound: [] }>();
// The bind flow takes over the card; a null binding is a new one.
const binding = ref<Binding | null | undefined>();
function bound(): void {
binding.value = undefined;
emit("bound");
}
</script>
<template>
<BindEvent v-if="binding !== undefined" :yaml="yaml" :binding="binding" @back="binding = undefined" @saved="bound" />
<div v-else class="space-y-4 px-3 py-3">
<section class="space-y-1.5">
<div class="flex justify-end">
<Button type="button" variant="ghost" size="xs" @click="binding = null"><Plus data-icon="inline-start" />Bind an event</Button>
</div>
<ul v-if="triggers.length" class="divide-y divide-border rounded-md border border-border">
<li v-for="trigger in triggers" :key="trigger.kind + trigger.label" class="text-[13px]">
<button v-if="trigger.binding" type="button" class="flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-secondary" @click="binding = trigger.binding">
<span class="truncate">{{ trigger.label }}</span>
<Badge v-if="trigger.binding.status !== 'armed'" :variant="statusKind(trigger.binding.status)">{{ statusLabel(trigger.binding.status) }}</Badge>
<span v-if="trigger.detail" class="ml-auto truncate text-xs text-fg-subtle">{{ trigger.detail }}</span>
</button>
<RouterLink v-else-if="trigger.kind === 'workflow' || trigger.kind === 'playbook'" :to="trigger.kind === 'workflow' ? { path: '/workflows', query: { workflow: trigger.label } } : { path: '/org/playbooks' }" class="flex items-center gap-2 px-3 py-2 hover:bg-secondary">
<span class="truncate">{{ trigger.label }}</span><span class="ml-auto truncate text-xs text-fg-subtle">{{ trigger.detail }}</span>
</RouterLink>
<div v-else class="flex items-center gap-2 px-3 py-2" title="Built-in issue routing. Disable this workflow to stop it running automatically.">
<span class="truncate">{{ trigger.label }}</span>
<Badge v-if="trigger.kind === 'issue'" variant="outline" class="ml-auto">Built-in</Badge>
<span v-if="trigger.detail" class="ml-auto truncate text-xs text-fg-subtle">{{ trigger.detail }}</span>
</div>
</li>
</ul>
<p v-else class="text-xs text-fg-subtle">Manual runs only.</p>
</section>
<SpecList :yaml="yaml" field="inputs" @update:yaml="emit('update:yaml', $event)" />
</div>
</template>
+111 -36
View File
@@ -1,8 +1,9 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { computed, nextTick, ref, watch } from "vue";
import { VueFlow, type NodeMouseEvent, type VueFlowStore } from "@vue-flow/core";
import { Background } from "@vue-flow/background";
import { Controls } from "@vue-flow/controls";
import { usePreferredReducedMotion, useTransition } from "@vueuse/core";
import { ArrowDown, ArrowUp, Copy, Pencil, RotateCcw, Trash2 } from "@lucide/vue";
import "@vue-flow/core/dist/style.css";
import "@vue-flow/controls/dist/style.css";
@@ -20,17 +21,18 @@ import {
} from "@/components/ui/dropdown-menu";
import AddNode from "./AddNode.vue";
import InsertEdge from "./InsertEdge.vue";
import StepNode from "./StepNode.vue";
import StepNode, { type StepCardData } from "./StepNode.vue";
import StepTypeItems from "./StepTypeItems.vue";
import { inParallel, type StepPath } from "./workflow-edit";
import LaneNode from "./LaneNode.vue";
import { restartAt, stepTitle, withRuns, workflowGraph, type StageRun, type StepNodeData } from "./workflow-graph";
import { restartAt, stepTitle, withRuns, workflowGraph, type GraphNode, type StageRun, type StepNodeData } from "./workflow-graph";
import type { WorkflowTrigger } from "./workflow-triggers";
const props = defineProps<{
yaml: string;
stages?: StageRun[];
selected?: StepPath | null;
/** The card open in place: "workflow", "start", or a step's path as JSON. */
open?: string | null;
triggers?: WorkflowTrigger[];
/** Step type names; when given, the canvas offers editing. */
types?: string[];
@@ -38,51 +40,120 @@ const props = defineProps<{
restartable?: boolean;
/** Steps that differ from the definition being compared, by node id. */
marks?: Record<string, "added" | "removed" | "changed">;
/** What is wrong with each step, by its path as JSON. */
problems?: Record<string, string>;
/** The workflow card's title and one-line summary. */
title?: string;
summary?: string;
}>();
const emit = defineEmits<{
edit: [StepPath];
settings: [];
toggle: [key: string];
insert: [after: StepPath, type: string];
duplicate: [StepPath];
move: [StepPath, -1 | 1];
remove: [StepPath];
rename: [StepPath, string];
restart: [from: string];
}>();
const NODE_WIDTH = 240;
const OPEN_WIDTH = 416;
const TOP = -140;
const editable = computed(() => !!props.types?.length);
const types = computed(() => [...(props.types ?? []), "parallel", "switch"]);
const branchTypes = computed(() => types.value.filter((type) => ["agent.run", "workflow.call"].includes(type)));
const typesAt = (path?: StepPath) => (path && inParallel(path) ? branchTypes.value : types.value);
const keyOf = (data: StepNodeData) => (data.kind === "step" ? JSON.stringify(data.path ?? null) : data.kind);
const container = ref<HTMLElement | null>(null);
const graph = computed(() => withRuns(workflowGraph(props.yaml), props.stages ?? []));
const selectedKey = computed(() => JSON.stringify(props.selected ?? null));
const graph = computed(() => {
const laid = withRuns(workflowGraph(props.yaml), props.stages ?? []);
if (!editable.value) return laid;
// Workflow-wide settings sit on a card above the trigger.
const workflow: GraphNode = { id: "workflow", type: "step", position: { x: 0, y: TOP }, data: { kind: "workflow", key: "workflow", title: props.title || "Workflow", type: "", detail: props.summary ?? "" } };
return { nodes: [workflow, ...laid.nodes], edges: [{ id: "flow-workflow-start", source: "workflow", target: "start", kind: "flow" as const }, ...laid.edges] };
});
const stepCount = computed(() => graph.value.nodes.filter((node) => node.data.path?.length === 2).length);
const nodes = computed(() =>
graph.value.nodes.map((node) => {
// Rows are laid out for cards BASE tall. A taller card pushes everything below
// it down by the difference, measured rather than guessed, and an open card
// grows where it sits while the cards below slide down with it.
const BASE = 72;
const heights = ref<Record<string, number>>({});
const closedHeights = ref<Record<string, number>>({});
const anchor = computed(() => graph.value.nodes.find((node) => node.type === "step" && keyOf(node.data) === props.open));
function resized(id: string, height: number): void {
heights.value = { ...heights.value, [id]: height };
if (anchor.value?.id !== id) closedHeights.value = { ...closedHeights.value, [id]: height };
}
const growth = computed(() => {
const id = anchor.value?.id;
return id && heights.value[id] ? Math.max(0, heights.value[id] - (closedHeights.value[id] ?? heights.value[id])) : 0;
});
const motion = usePreferredReducedMotion();
const shift = useTransition(growth, { duration: computed(() => (motion.value === "reduce" ? 0 : 200)) });
const rows = computed(() => {
const excess = new Map<number, number>();
for (const node of graph.value.nodes) {
if (node.type !== "step") continue;
const height = (node.id === anchor.value?.id ? closedHeights.value[node.id] : undefined) ?? heights.value[node.id];
if (height !== undefined) excess.set(node.position.y, Math.max(excess.get(node.position.y) ?? -BASE, height - BASE));
}
return [...excess];
});
const pushed = (y: number) => rows.value.reduce((sum, [row, excess]) => (row < y ? sum + excess : sum), 0);
function card(node: GraphNode): GraphNode {
const data = node.data;
const key = keyOf(data);
const path = data.path;
const extra: Partial<StepCardData> = {
triggers: data.kind === "start" ? (props.triggers ?? []) : data.triggers,
expanded: key === props.open,
editable: editable.value,
problem: path ? props.problems?.[key] : undefined,
onResize: (height: number) => resized(node.id, height),
};
if (editable.value) {
extra.onToggle = () => emit("toggle", key);
if (path) {
extra.onRename = (name: string) => emit("rename", path, name);
extra.onDuplicate = () => emit("duplicate", path);
extra.onRemove = () => emit("remove", path);
}
}
return { ...node, data: { ...data, ...extra } };
}
const nodes = computed(() => {
const open = anchor.value;
return graph.value.nodes.map((node) => {
const original = node;
if (node.type === "add")
return { ...node, data: { ...node.data, types: typesAt(node.data.insertAfter), editable: editable.value, onInsert: (type: string) => emit("insert", node.data.insertAfter!, type) } };
if (node.data.kind === "start") return { ...node, data: { ...node.data, triggers: props.triggers ?? [] } };
// Each trigger past the second makes the start node a line taller.
const drop = Math.max(0, (props.triggers?.length ?? 0) - 2) * 18;
if (drop) node = { ...node, position: { ...node.position, y: node.position.y + drop } };
if (node.type === "lane") return node;
node = { ...node, data: { ...node.data, types: typesAt(node.data.insertAfter), editable: editable.value, onInsert: (type: string) => emit("insert", node.data.insertAfter!, type) } as StepNodeData };
else if (node.type === "step") node = card(node);
const mark = props.marks?.[node.id];
if (mark) node = { ...node, data: { ...node.data, mark } };
return JSON.stringify(node.data.path ?? null) === selectedKey.value && props.selected
? { ...node, data: { ...node.data, selected: true } }
: node;
}),
);
const { x } = node.position;
const opened = (at: number) => (open && at > open.position.y ? shift.value : 0);
const y = node.position.y + pushed(node.position.y) + opened(node.position.y);
if (original === open) return { ...node, position: { x: x - (OPEN_WIDTH - NODE_WIDTH) / 2, y }, zIndex: 10 };
// A lane grows with the cards inside it.
if (node.type === "lane" && node.style) {
const top = node.position.y;
const bottom = top + parseFloat(node.style.height);
const height = bottom + pushed(bottom) + opened(bottom) - y;
return { ...node, position: { x, y }, style: { ...node.style, height: `${height}px` } };
}
return { ...node, position: { x, y } };
});
});
// The run's trace: an edge lights once the run has reached its target, in the
// colour of how that step went, and moves while the step is running.
const runs = computed(() => new Map(graph.value.nodes.map((node) => [node.id, node.data.run?.status])));
// Data edges bundle into noise, so only the hovered or selected step's show.
// Data edges bundle into noise, so only the hovered or open step's show.
const hovered = ref<string | null>(null);
const focusId = computed(
() => hovered.value ?? graph.value.nodes.find((node) => props.selected && JSON.stringify(node.data.path ?? null) === selectedKey.value)?.id,
);
const focusId = computed(() => hovered.value ?? anchor.value?.id);
const edges = computed(() =>
graph.value.edges
.filter((edge) => edge.kind === "flow" || edge.source === focusId.value || edge.target === focusId.value)
@@ -106,6 +177,7 @@ const edges = computed(() =>
const ZOOM = 0.9;
let flow: VueFlowStore | undefined;
const top = computed(() => (editable.value ? TOP : 0));
// Start at a readable size rather than shrinking a long workflow until
// nothing on it can be read, scrolled to the furthest step the watched run has
@@ -118,13 +190,22 @@ function place(store?: VueFlowStore): void {
const height = container.value?.clientHeight ?? 560;
// Scroll only when the furthest step reached would be out of view.
const reached = graph.value.nodes.find((node) => props.marks?.[node.id]) ?? graph.value.nodes.filter((node) => node.data.run).at(-1);
const below = reached && 24 + (reached.position.y + 180) * ZOOM > height;
const y = below ? height / 3 - reached.position.y * ZOOM : 24;
const below = reached && 24 + (reached.position.y - top.value + 180) * ZOOM > height;
const y = below ? height / 3 - reached.position.y * ZOOM : 24 - top.value * ZOOM;
void flow.setViewport({ x: width / 2 - NODE_WIDTH * ZOOM / 2, y, zoom: ZOOM }, { duration: animate ? 300 : 0 });
}
watch(() => graph.value.nodes.filter((node) => node.data.run).length, () => place());
watch(() => props.marks, () => place());
// A card opened low on the canvas scrolls up so its form is in view.
watch(anchor, async (node) => {
await nextTick();
if (!node || !flow) return;
const { x, y, zoom } = flow.getViewport();
const screenTop = (node.position.y + pushed(node.position.y)) * zoom + y;
const height = container.value?.clientHeight ?? 560;
if (screenTop < 8 || screenTop > height / 2) void flow.setViewport({ x, y: y - screenTop + 24, zoom }, { duration: 250 });
});
// The right-click menu opens at the pointer, for the step under it or for the
// canvas itself.
@@ -136,14 +217,9 @@ function openMenu(event: MouseEvent, step?: StepNodeData): void {
menu.value = { open: true, x: event.clientX - (box?.left ?? 0), y: event.clientY - (box?.top ?? 0), step };
}
function onNodeMenu({ event, node }: NodeMouseEvent): void {
if (node.type !== "step") return;
if (node.type !== "step" || (node.data as StepNodeData).kind === "workflow") return;
openMenu(event as MouseEvent, node.data as StepNodeData);
}
function onNodeClick({ node }: NodeMouseEvent): void {
if ((node.data as StepNodeData).kind === "start" && editable.value) return emit("settings");
const path = (node.data as StepNodeData).path;
if (editable.value && path) emit("edit", path);
}
const menuPath = computed(() => menu.value.step?.path);
const restart = computed(() => (props.restartable && menuPath.value ? restartAt(graph.value, menuPath.value) : null));
const menuIndex = computed(() => Number(menuPath.value?.at(-1)));
@@ -163,14 +239,13 @@ const beforePath = computed(() => menuPath.value ? [...menuPath.value.slice(0, -
:max-zoom="1.5"
pan-on-scroll
@pane-ready="place"
@node-click="onNodeClick"
@node-mouse-enter="hovered = $event.node.id"
@node-mouse-leave="hovered = null"
@node-context-menu="onNodeMenu"
@pane-context-menu="openMenu($event as MouseEvent)"
>
<template #node-step="nodeProps">
<StepNode v-bind="nodeProps" />
<StepNode v-bind="nodeProps"><slot name="body" :data="nodeProps.data" /></StepNode>
</template>
<template #node-lane="nodeProps">
<LaneNode v-bind="nodeProps" />
@@ -196,7 +271,7 @@ const beforePath = computed(() => menuPath.value ? [...menuPath.value.slice(0, -
<DropdownMenuItem :disabled="restart.blocked" @select="emit('restart', restart.from)"><RotateCcw />{{ restart.label }}</DropdownMenuItem>
<DropdownMenuSeparator />
</template>
<DropdownMenuItem @select="emit('edit', menuPath)"><Pencil />Edit</DropdownMenuItem>
<DropdownMenuItem @select="emit('toggle', JSON.stringify(menuPath))"><Pencil />Edit</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger>Insert before</DropdownMenuSubTrigger>
<DropdownMenuSubContent class="w-52"><StepTypeItems :types="typesAt(menuPath)" @pick="emit('insert', beforePath, $event)" /></DropdownMenuSubContent>
+81 -75
View File
@@ -8,9 +8,8 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
import { computed, ref, watch } from "vue";
import { Ellipsis, RotateCcw, Trash2, X } from "@lucide/vue";
import { Ellipsis, RotateCcw, Trash2 } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import {
@@ -28,13 +27,15 @@ import { restartAt, withRuns, workflowGraph } from "./workflow-graph";
import { api } from "@/lib/api";
import StepEditor from "./StepEditor.vue";
import WorkflowSettings from "./WorkflowSettings.vue";
import TriggerSettings from "./TriggerSettings.vue";
import OptionSelect from "./OptionSelect.vue";
import RunWorkflowButton from "./RunWorkflowButton.vue";
import TaskRowActions from "@/tasks/TaskRowActions.vue";
import WorkflowCanvas from "./WorkflowCanvas.vue";
import WorkflowHistory from "./WorkflowHistory.vue";
import { useWorkflowHistory } from "./workflow-history";
import { revisionOfRun, type WorkflowRevision } from "./workflow-revisions";
import { deleteStep, duplicateStep, insertStep, moveStep, type StepPath } from "./workflow-edit";
import { deleteStep, duplicateStep, insertStep, moveStep, replaceStep, stepAt, workflowField, type StepPath } from "./workflow-edit";
import { useWorkflowRuns } from "./workflow-runs";
import { useWorkflowTriggers } from "./workflow-triggers";
import { cloneControlPlaneValue, useSettingsStore } from "@/stores/settings";
@@ -46,6 +47,8 @@ import {
} from "@/stores/workflows";
import {
parseWorkflowYaml,
settingsProblem,
stepControlsProblem,
validationLabel,
yamlLines,
yamlTokenClass,
@@ -68,27 +71,28 @@ defineProps<{ runsCount?: number }>();
const id = ref("");
const yaml = ref("");
const loadedYaml = ref("");
const selectedStep = ref<StepPath | null>(null);
// The slide-in panel shows one thing: a step's editor, or the workflow's settings.
const settingsOpen = ref(false);
watch(selectedStep, (path) => {
if (path) settingsOpen.value = false;
});
// The one card open in place: "workflow", "start", or a step's path as JSON.
const open = ref<string | null>(null);
const openPath = computed<StepPath | null>(() => (open.value?.startsWith("[") ? (JSON.parse(open.value) as StepPath) : null));
function openStepAt(path: StepPath | null): void {
open.value = path ? JSON.stringify(path) : null;
}
const localError = ref("");
const { runs, error: runsError, loading: runsLoading, watched, watchedRun, stages, attempt, pick, follow, refresh } = useWorkflowRuns(selected);
const stepTab = ref("definition");
const selectedNode = computed(() => withRuns(workflowGraph(yaml.value), stages.value).nodes.find((node) => JSON.stringify(node.data.path) === JSON.stringify(selectedStep.value))?.data);
function openStep(path: StepPath): void {
selectedStep.value = path;
stepTab.value = selectedNode.value?.run && watchedRun.value ? "run" : "definition";
const graph = computed(() => withRuns(workflowGraph(yaml.value), stages.value));
function toggle(key: string): void {
open.value = open.value === key ? null : key;
const run = graph.value.nodes.find((node) => JSON.stringify(node.data.path ?? null) === open.value)?.data.run;
stepTab.value = run && watchedRun.value ? "run" : "definition";
}
watch(watched, () => { selectedStep.value = null; restartError.value = ""; });
watch(watched, () => { open.value = null; restartError.value = ""; });
// A parked run restarts at a step through the retry action, keeping the
// results of the steps before it.
const restartable = computed(() => watchedRun.value?.status === "parked");
const selectedRestart = computed(() => restartable.value && selectedStep.value ? restartAt(withRuns(workflowGraph(yaml.value), stages.value), selectedStep.value) : null);
const openRestart = computed(() => restartable.value && openPath.value ? restartAt(graph.value, openPath.value) : null);
const restarting = ref(false);
const restartError = ref("");
async function restartFrom(from: string): Promise<void> {
@@ -120,7 +124,7 @@ function openRevision(version: number): void {
// A restored version is an unsaved edit: nothing is written until Save.
function restoreRevision(restored: string): void {
yaml.value = restored;
selectedStep.value = null;
open.value = null;
view.value = "canvas";
}
@@ -130,22 +134,26 @@ function insertAt(after: StepPath, type: string): void {
stepTab.value = "definition";
const inserted = insertStep(yaml.value, after, type);
yaml.value = inserted.source;
selectedStep.value = inserted.path;
openStepAt(inserted.path);
}
function duplicateAt(path: StepPath): void {
stepTab.value = "definition";
const copied = duplicateStep(yaml.value, path);
yaml.value = copied.source;
selectedStep.value = copied.path;
openStepAt(copied.path);
}
function moveAt(path: StepPath, delta: -1 | 1): void {
const moved = moveStep(yaml.value, path, delta);
yaml.value = moved.source;
if (selectedStep.value) selectedStep.value = moved.path;
if (openPath.value) openStepAt(moved.path);
}
function removeAt(path: StepPath): void {
yaml.value = deleteStep(yaml.value, path);
selectedStep.value = null;
open.value = null;
}
function renameAt(path: StepPath, name: string): void {
const { id: _id, type, ...rest } = stepAt(yaml.value, path) ?? {};
yaml.value = replaceStep(yaml.value, path, { id: name || undefined, type, ...rest });
}
const shippedEntry = computed(() =>
@@ -159,7 +167,7 @@ function load(value: string): void {
id.value = entry?.id ?? value;
yaml.value = entry?.yaml ?? `id: ${value}\nsteps: []\n`;
loadedYaml.value = yaml.value;
selectedStep.value = null;
open.value = null;
localError.value = "";
}
@@ -233,6 +241,31 @@ const parsed = computed(() => parseWorkflowYaml(yaml.value, vocabulary.value));
const stored = computed(() => collection.value.definitions.find((entry) => entry.id === selected.value)?.yaml);
const dirty = computed(() => yaml.value !== (stored.value ?? ""));
const view = ref("canvas");
// What each step lacks, read the way its editor reads it.
const problems = computed(() =>
Object.fromEntries(
graph.value.nodes.flatMap((node) => {
const path = node.data.path;
const step = path && stepAt(yaml.value, path);
if (!step) return [];
const schema = vocabulary.value.find((info) => info.name === step.type)?.settings;
const problem = stepControlsProblem(step) || (schema && step.settings ? settingsProblem(step.settings, schema, "settings") : "");
return problem ? [[JSON.stringify(path), problem]] : [];
}),
),
);
const WORKS_ON: Record<string, string> = { optional: "Repository if given", none: "No repository" };
const REQUIRED = "Works on a repository";
const workflowSummary = computed(() =>
[WORKS_ON[String(workflowField(yaml.value, "repository") ?? "")] ?? REQUIRED, workflowField(yaml.value, "profile")].filter(Boolean).join(" · "),
);
const runOptions = computed(() => [
{ value: "", label: "Definition only" },
...runs.value.map((run) => ({
value: String(run.id),
label: [`${run.source === "test" ? "Test" : "Run"} #${run.id}`, run.title, run.status, runRevision(run) ? `v${runRevision(run)!.version}` : ""].filter(Boolean).join(" · "),
})),
]);
const lines = computed(() => yamlLines(yaml.value));
// The highlight layer sits behind the textarea and never scrolls by itself, so
@@ -256,18 +289,7 @@ function syncScroll(event: Event): void {
<TabsTrigger v-if="$slots.runs" value="runs">Runs <span class="ml-1 font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
</TabsList>
<div v-if="runs.length && view === 'canvas'" class="flex min-w-0 items-center gap-1">
<NativeSelect
size="sm"
:model-value="watched"
aria-label="Run shown on the canvas"
class="min-w-0 max-w-64"
@update:model-value="(value) => pick(String(value))"
>
<NativeSelectOption value="">Definition only</NativeSelectOption>
<NativeSelectOption v-for="run in runs" :key="run.id" :value="String(run.id)">{{
[`${run.source === "test" ? "Test" : "Run"} #${run.id}`, run.title, run.status, runRevision(run) ? `v${runRevision(run)!.version}` : ""].filter(Boolean).join(" · ")
}}</NativeSelectOption>
</NativeSelect>
<OptionSelect :model-value="watched" :options="runOptions" aria-label="Run shown on the canvas" class="min-w-0 max-w-64" @update:model-value="pick" />
<template v-if="watchedRun">
<RouterLink :to="`/tasks/${watchedRun.id}`" class="shrink-0 px-1 text-xs text-muted-foreground hover:text-foreground hover:underline">Open</RouterLink>
<button v-if="watchedRevision" type="button" class="shrink-0 px-1 font-mono text-xs text-muted-foreground hover:text-foreground hover:underline" title="Open the version this run used" @click="openRevision(watchedRevision.version)">v{{ watchedRevision.version }}</button>
@@ -297,7 +319,7 @@ function syncScroll(event: Event): void {
<Spinner v-if="state.saving" data-icon="inline-start" />Save</Button>
</template>
</div>
<p v-if="runsLoading" class="text-xs text-fg-muted" role="status">Loading recent runs…</p>
<p v-if="runsLoading && !runs.length" class="text-xs text-fg-muted" role="status">Loading recent runs…</p>
<div v-else-if="runsError" class="text-sm text-danger" role="alert">
<p>Could not load recent runs: {{ runsError }}</p>
<Button type="button" variant="outline" size="sm" @click="refresh">Retry runs</Button>
@@ -311,60 +333,44 @@ function syncScroll(event: Event): void {
<WorkflowCanvas
:yaml="yaml"
:stages="stages"
:selected="selectedStep"
:open="open"
:triggers="triggers"
:types="stepTypeNames"
:restartable="restartable"
@edit="openStep"
:problems="problems"
:title="parsed.ok ? parsed.id : id"
:summary="workflowSummary"
@toggle="toggle"
@restart="restartFrom"
@settings="selectedStep = null; settingsOpen = true"
@insert="insertAt"
@duplicate="duplicateAt"
@move="moveAt"
@remove="removeAt"
/>
<Transition
enter-from-class="translate-x-full opacity-0"
leave-to-class="translate-x-full opacity-0"
enter-active-class="transition duration-200"
leave-active-class="transition duration-150"
@rename="renameAt"
>
<div v-if="settingsOpen" class="absolute inset-y-0 right-0 max-w-full overflow-hidden rounded-r-lg">
<WorkflowSettings v-model:yaml="yaml" :triggers="triggers" @close="settingsOpen = false" @bound="reloadTriggers" />
</div>
</Transition>
<Transition
enter-from-class="translate-x-full opacity-0"
leave-to-class="translate-x-full opacity-0"
enter-active-class="transition duration-200"
leave-active-class="transition duration-150"
>
<div v-if="selectedStep" class="absolute inset-y-0 right-0 flex max-w-full flex-col overflow-hidden rounded-r-lg border-l border-border bg-card shadow-xl">
<template v-if="selectedNode?.run && watchedRun">
<div class="flex items-center gap-2 border-b border-border px-3 py-2">
<template #body="{ data }">
<WorkflowSettings v-if="data.kind === 'workflow'" v-model:yaml="yaml" />
<TriggerSettings v-else-if="data.kind === 'start'" v-model:yaml="yaml" :triggers="triggers" @bound="reloadTriggers" />
<template v-else-if="data.path">
<div v-if="data.run && watchedRun" class="flex items-center gap-2 border-b border-border px-3 py-2">
<Tabs v-model="stepTab"><TabsList><TabsTrigger value="run">Run</TabsTrigger><TabsTrigger value="definition">Definition</TabsTrigger></TabsList></Tabs>
<span class="min-w-0 flex-1 truncate text-xs" :title="selectedNode.run.name">{{ selectedNode.run.name }}</span>
<Button v-if="selectedRestart" type="button" size="sm" variant="outline" :disabled="restarting || selectedRestart.blocked" @click="restartFrom(selectedRestart.from)"><RotateCcw />{{ selectedRestart.label }}</Button>
<Button type="button" variant="ghost" size="icon-sm" aria-label="Close step details" @click="selectedStep = null"><X /></Button>
<Button v-if="openRestart" type="button" size="sm" variant="outline" class="ml-auto" :disabled="restarting || openRestart.blocked" @click="restartFrom(openRestart.from)"><RotateCcw />{{ openRestart.label }}</Button>
</div>
<div v-if="stepTab === 'run'" class="min-h-0 w-[32rem] max-w-[calc(100vw-3rem)] flex-1 overflow-y-auto">
<StepRun :task="watchedRun" :attempt="attempt" :stage="selectedNode.run" :stages="stages" />
<div v-if="data.run && watchedRun && stepTab === 'run'" class="max-h-[32rem] overflow-y-auto">
<StepRun :task="watchedRun" :attempt="attempt" :stage="data.run" :stages="stages" />
</div>
<StepEditor
v-else
:key="open ?? ''"
v-model:yaml="yaml"
:workflows="collection.definitions"
:path="data.path"
:vocabulary="vocabulary"
:model-aliases="modelAliases"
/>
</template>
<StepEditor
:workflows="collection.definitions"
class="min-h-0 flex-1"
v-if="stepTab === 'definition' || !selectedNode?.run || !watchedRun"
:key="JSON.stringify(selectedStep)"
v-model:yaml="yaml"
:path="selectedStep"
:vocabulary="vocabulary"
:model-aliases="modelAliases"
@close="selectedStep = null"
@remove="removeAt(selectedStep)"
/>
</div>
</Transition>
</template>
</WorkflowCanvas>
</div>
</TabsContent>
<TabsContent value="history">
+70 -182
View File
@@ -2,63 +2,28 @@
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
import { computed, ref, onMounted } from "vue";
import { Plus, Trash2, X } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Switch } from "@/components/ui/switch";
import { statusKind, statusLabel, type Binding } from "@/bindings/binding-draft";
import { api } from "@/lib/api";
import type { Identity } from "@/stores/org";
import { useOrgStore } from "@/stores/org";
import BindEvent from "./BindEvent.vue";
import { useSettingsStore } from "@/stores/settings";
import OptionSelect from "./OptionSelect.vue";
import SpecList from "./SpecList.vue";
import { setWorkflowField, workflowField } from "./workflow-edit";
import type { WorkflowTrigger } from "./workflow-triggers";
const props = defineProps<{ yaml: string; triggers: WorkflowTrigger[] }>();
const emit = defineEmits<{ "update:yaml": [string]; close: []; bound: [] }>();
// The bind flow replaces the settings in this panel; null binding is a new one.
const binding = ref<Binding | null | undefined>();
function bound(): void {
binding.value = undefined;
emit("bound");
}
type Spec = { type?: string; required?: boolean };
const TYPES = ["string", "number", "bool", "object", "array", "any"];
// Kept out of the template: a literal reference there would close the
// template's own interpolation.
const EMPTY = {
inputs: "Takes none. Steps read declared inputs as {{ inputs.name }}.",
outputs: "Writes none. A calling workflow can read declared outputs.",
};
const props = defineProps<{ yaml: string }>();
const emit = defineEmits<{ "update:yaml": [string] }>();
const text = (key: string) => {
const value = workflowField(props.yaml, key);
return typeof value === "string" ? value : "";
};
const specs = (key: "inputs" | "outputs") =>
computed(() => Object.entries((workflowField(props.yaml, key) as Record<string, Spec> | undefined) ?? {}));
const inputs = specs("inputs");
const outputs = specs("outputs");
function set(key: string, value: unknown): void {
emit("update:yaml", setWorkflowField(props.yaml, key, value));
}
function setSpec(key: "inputs" | "outputs", entries: [string, Spec][]): void {
set(key, Object.fromEntries(entries.filter(([name]) => name)));
}
function editSpec(key: "inputs" | "outputs", list: [string, Spec][], index: number, name: string, spec: Spec): void {
setSpec(key, list.map((entry, i) => (i === index ? [name, spec] : entry)));
}
function addSpec(key: "inputs" | "outputs", list: [string, Spec][]): void {
let n = list.length + 1;
while (list.some(([name]) => name === `${key.slice(0, -1)}_${n}`)) n++;
setSpec(key, [...list, [`${key.slice(0, -1)}_${n}`, { type: "string" }]]);
}
// The identity a run acts as must be an agent, never a person; a workflow
// naming none is refused when it runs, so it defaults to the agent identity
@@ -82,6 +47,19 @@ async function loadAgents(): Promise<void> {
} finally { identitiesLoading.value = false; }
}
onMounted(loadAgents);
const identityOptions = computed(() => {
const current = text("identity");
const options = agents.value.map((agent) => ({ value: agent.id, label: agent.display_name }));
return current && !agents.value.some((agent) => agent.id === current) ? [{ value: current, label: `${current} (unknown)`, disabled: true }, ...options] : options;
});
const settings = useSettingsStore();
const profileOptions = computed(() => {
const names = Object.keys((settings.stateFor("agent-profiles").resource?.value ?? {}) as Record<string, unknown>).sort();
const current = text("profile");
if (current && !names.includes(current)) names.unshift(current);
return [{ value: "", label: "Default" }, ...names.map((name) => ({ value: name, label: name }))];
});
const MODES = [
{ value: "required", label: "Repository", hint: "Clones the task's repository" },
@@ -97,160 +75,70 @@ const needs = computed<{ captures?: boolean; gate_retries?: number }>(() => {
const value = workflowField(props.yaml, "needs");
return value && typeof value === "object" ? (value as { captures?: boolean; gate_retries?: number }) : {};
});
function setNeeds(next: { captures?: boolean; gate_retries?: number }): void {
set("needs", next);
}
</script>
<template>
<aside class="flex h-full w-[24rem] max-w-full flex-col border-l border-border bg-card shadow-xl">
<BindEvent v-if="binding !== undefined" :yaml="yaml" :binding="binding" @back="binding = undefined" @saved="bound" />
<template v-else>
<header class="flex items-center gap-2 border-b border-border px-4 py-3">
<div class="min-w-0 flex-1">
<div class="text-sm font-medium">Workflow settings</div>
</div>
<Button type="button" variant="ghost" size="icon-sm" aria-label="Close" @click="emit('close')"><X /></Button>
</header>
<div class="flex-1 space-y-5 overflow-y-auto px-4 py-4">
<section class="space-y-1.5">
<div class="text-xs font-medium text-muted-foreground">Works on</div>
<div class="space-y-4 px-3 py-3">
<div class="divide-y divide-border rounded-md border border-border">
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Runs as</span>
<OptionSelect
:model-value="text('identity')"
:options="identityOptions"
aria-label="Execution identity"
:placeholder="identitiesLoading ? 'Loading agents…' : 'Choose an agent'"
:disabled="identitiesLoading || !!identitiesError"
class="w-44"
@update:model-value="set('identity', $event)"
/>
</label>
<p v-if="identitiesError" role="alert" class="px-3 py-2 text-xs text-danger">{{ identitiesError }} <Button variant="link" size="xs" @click="loadAgents">Retry</Button></p>
<p v-else-if="!identitiesLoading && !agents.length" class="px-3 py-2 text-xs text-fg-subtle">No active agents in your organisation.</p>
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Container profile</span>
<OptionSelect :model-value="text('profile')" :options="profileOptions" aria-label="Container profile" class="w-44" @update:model-value="set('profile', $event || undefined)" />
</label>
<div class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Works on</span>
<ToggleGroup
type="single"
variant="outline"
size="sm"
class="w-full"
:model-value="repository"
aria-label="Works on"
@update:model-value="(value) => { if (value) set('repository', value === 'required' ? undefined : String(value)); }"
>
<ToggleGroupItem v-for="mode in MODES" :key="mode.value" :value="mode.value" :title="mode.hint" class="flex-1">{{ mode.label }}</ToggleGroupItem>
<ToggleGroupItem v-for="mode in MODES" :key="mode.value" :value="mode.value" :title="mode.hint">{{ mode.label }}</ToggleGroupItem>
</ToggleGroup>
</section>
<section v-for="[key, list] in [['inputs', inputs], ['outputs', outputs]] as const" :key="key" class="space-y-1.5">
<div class="flex items-center text-xs font-medium text-muted-foreground">
{{ key === "inputs" ? "Inputs" : "Outputs" }}
<Button type="button" variant="ghost" size="xs" class="ml-auto" @click="addSpec(key, list)"><Plus data-icon="inline-start" />Add</Button>
</div>
<div v-if="list.length" class="divide-y divide-border rounded-md border border-border">
<div v-for="([name, spec], i) in list" :key="i" class="flex items-center gap-2 px-2 py-1.5">
<Input
:model-value="name"
class="h-7 min-w-0 flex-1 font-mono text-xs"
:aria-label="`${key} name`"
@change="editSpec(key, list, i, ($event.target as HTMLInputElement).value.trim(), spec)"
/>
<NativeSelect
size="sm"
:model-value="spec.type ?? 'string'"
@update:model-value="(value) => editSpec(key, list, i, name, { ...spec, type: String(value) })"
>
<NativeSelectOption v-for="type in TYPES" :key="type" :value="type">{{ type }}</NativeSelectOption>
</NativeSelect>
<Switch
:model-value="spec.required === true"
:title="spec.required ? 'Required' : 'Optional'"
@update:model-value="editSpec(key, list, i, name, { ...spec, required: $event || undefined })"
/>
<Button type="button" variant="ghost" size="icon-xs" :aria-label="`Remove ${name}`" @click="setSpec(key, list.filter((_: unknown, j: number) => j !== i))">
<Trash2 />
</Button>
</div>
</div>
<p v-else class="text-xs text-fg-subtle">
{{ EMPTY[key] }}
</p>
</section>
<section class="space-y-1.5">
<label for="workflow-instructions" class="text-xs font-medium text-muted-foreground">Instructions</label>
<Textarea
id="workflow-instructions"
:model-value="text('instructions')"
:rows="5"
class="font-mono text-[13px]"
@change="set('instructions', ($event.target as HTMLTextAreaElement).value)"
</div>
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]" title="Stages return structured output through capture tools">Captures</span>
<Switch :model-value="needs.captures === true" @update:model-value="set('needs', { ...needs, captures: $event || undefined })" />
</label>
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Gate retries</span>
<Input
type="number"
min="0"
placeholder="0"
class="h-7 w-20 text-right text-[13px]"
:model-value="needs.gate_retries ?? ''"
@update:model-value="(value) => set('needs', { ...needs, gate_retries: String(value) === '' ? undefined : Number(String(value)) })"
/>
</section>
<section class="space-y-1.5">
<div class="text-xs font-medium text-muted-foreground">Runs as</div>
<div class="divide-y divide-border rounded-md border border-border">
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Identity</span>
<NativeSelect
:model-value="text('identity')"
aria-label="Execution identity"
:disabled="identitiesLoading || !!identitiesError"
class="w-44 text-[13px]"
@update:model-value="(value) => set('identity', String(value))"
>
<NativeSelectOption v-if="!text('identity')" value="" disabled>{{ identitiesLoading ? 'Loading agents…' : 'Choose an agent' }}</NativeSelectOption>
<NativeSelectOption v-if="text('identity') && !agents.some((agent) => agent.id === text('identity'))" :value="text('identity')" disabled>{{ text('identity') }} (unknown)</NativeSelectOption>
<NativeSelectOption v-for="agent in agents" :key="agent.id" :value="agent.id">{{ agent.display_name }}</NativeSelectOption>
</NativeSelect>
</label>
<p v-if="identitiesError" role="alert" class="px-3 py-2 text-xs text-danger">{{ identitiesError }} <Button variant="link" size="xs" @click="loadAgents">Retry</Button></p>
<p v-else-if="!identitiesLoading && !agents.length" class="px-3 py-2 text-xs text-fg-subtle">No active agents are assigned to your organisation.</p>
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Container profile</span>
<Input
:model-value="text('profile')"
placeholder="default"
class="h-7 w-44 text-[13px]"
@change="set('profile', ($event.target as HTMLInputElement).value.trim())"
/>
</label>
</div>
</section>
<section class="space-y-1.5">
<div class="text-xs font-medium text-muted-foreground">Run needs</div>
<div class="divide-y divide-border rounded-md border border-border">
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Captures</span>
<Switch :model-value="needs.captures === true" @update:model-value="setNeeds({ ...needs, captures: $event || undefined })" />
</label>
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Gate retries</span>
<Input
type="number"
min="0"
placeholder="0"
class="h-7 w-20 text-right text-[13px]"
:model-value="needs.gate_retries ?? ''"
@update:model-value="(value) => setNeeds({ ...needs, gate_retries: String(value) === '' ? undefined : Number(String(value)) })"
/>
</label>
</div>
</section>
<section class="space-y-1.5">
<div class="flex items-center text-xs font-medium text-muted-foreground">Starts when
<Button type="button" variant="ghost" size="xs" class="ml-auto" @click="binding = null"><Plus data-icon="inline-start" />Bind an event</Button>
</div>
<ul v-if="triggers.length" class="divide-y divide-border rounded-md border border-border">
<li v-for="trigger in triggers" :key="trigger.kind + trigger.label" class="text-[13px]">
<button v-if="trigger.binding" type="button" class="flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-secondary" @click="binding = trigger.binding">
<span class="truncate">{{ trigger.label }}</span>
<Badge v-if="trigger.binding.status !== 'armed'" :variant="statusKind(trigger.binding.status)">{{ statusLabel(trigger.binding.status) }}</Badge>
<span v-if="trigger.detail" class="ml-auto truncate text-xs text-fg-subtle">{{ trigger.detail }}</span>
</button>
<RouterLink v-else-if="trigger.kind==='workflow' || trigger.kind==='playbook'" :to="trigger.kind==='workflow'?{path:'/workflows',query:{workflow:trigger.label}}:{path:'/org/playbooks'}" class="flex items-center gap-2 px-3 py-2 hover:bg-secondary">
<span class="truncate">{{trigger.label}}</span><span class="ml-auto truncate text-xs text-fg-subtle">{{trigger.detail}}</span>
</RouterLink>
<div v-else class="flex items-center gap-2 px-3 py-2" title="Built-in issue routing. Disable this workflow to stop it running automatically.">
<span class="truncate">{{ trigger.label }}</span>
<Badge v-if="trigger.kind==='issue'" variant="outline" class="ml-auto">Built-in</Badge>
<span v-if="trigger.detail" class="ml-auto truncate text-xs text-fg-subtle">{{ trigger.detail }}</span>
</div>
</li>
</ul>
<p v-else class="text-xs text-fg-subtle">Nothing starts it automatically.</p>
</section>
</label>
</div>
</template>
</aside>
<section class="space-y-1.5">
<label for="workflow-instructions" class="text-xs font-medium text-muted-foreground">Instructions</label>
<Textarea
id="workflow-instructions"
:model-value="text('instructions')"
:rows="4"
class="font-mono text-[13px]"
@change="set('instructions', ($event.target as HTMLTextAreaElement).value)"
/>
</section>
<SpecList :yaml="yaml" field="outputs" @update:yaml="emit('update:yaml', $event)" />
</div>
</template>
+4 -14
View File
@@ -10,14 +10,13 @@ import type { WorkflowTrigger } from "./workflow-triggers";
*/
export interface StepNodeData {
kind: "start" | "step";
/** What the step means to the run: work, a gate that decides, a pause for a
* person, or an exit that ends or hands off the run. */
role?: StepRole;
kind: "start" | "step" | "workflow";
/** The top-level step's position in run order, as shown on the node. */
step?: string;
/** The step's id, or its 1-based position when it has none. */
key: string;
/** The id the step declares, if any. */
name?: string;
title: string;
type: string;
detail: string;
@@ -42,19 +41,10 @@ export interface StepNodeData {
mark?: "added" | "removed" | "changed";
/** Where the step lives in the YAML document, for editing it. */
path?: (string | number)[];
selected?: boolean;
triggers?: WorkflowTrigger[];
insertAfter?: (string | number)[];
}
export type StepRole = "work" | "decision" | "waiting" | "exit";
function stepRole(type: string): StepRole {
if (type.startsWith("gate.") || type === "switch") return "decision";
if (type === "human.approve") return "waiting";
if (type === "workflow.finish" || type === "workflow.handoff") return "exit";
return "work";
}
/** One recorded run of a step, from the task's attempts view. */
export interface AgentRun {
@@ -286,9 +276,9 @@ export function workflowGraph(source: string): WorkflowGraph {
data: {
kind: "step",
key: stepID || key,
name: stepID || undefined,
title: stepID || stepTitle(type),
type,
role: stepRole(type),
step: path?.length === 2 ? String(Number(path[1]) + 1).padStart(2, "0") : undefined,
detail: branching?.on ? `on ${branching.on.replace(/^steps\./, "")}` : stepDetail(type, settings),
summary: stepSummary(settings),
+5 -2
View File
@@ -51,7 +51,7 @@ export function useWorkflowRuns(workflow: Ref<string>) {
async function loadStages(): Promise<void> {
if (!watched.value) {
stages.value = [];
if (stages.value.length) stages.value = [];
attempt.value = 0;
return;
}
@@ -59,7 +59,10 @@ export function useWorkflowRuns(workflow: Ref<string>) {
const view = await api.taskAttempts<AttemptsView>(requested).catch(() => null);
if (watched.value !== requested) return;
const latest = [...(view?.attempts ?? [])].sort((a, b) => b.attempt - a.attempt)[0];
stages.value = latest?.stages ?? [];
// A live refresh that changed nothing must not redraw the canvas, which
// would close any menu open on it.
const next = latest?.stages ?? [];
if (JSON.stringify(next) !== JSON.stringify(stages.value)) stages.value = next;
attempt.value = latest?.attempt ?? 0;
}