feat(ui): canvas authoring by right-click menu and + insertion points; steps edit in a slide-in panel and show what they do
This commit is contained in:
14 files changed
+716
-379
No files matched your search
@@ -0,0 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { Handle, Position } from "@vue-flow/core";
|
||||
|
||||
import AddStepMenu from "./AddStepMenu.vue";
|
||||
|
||||
defineProps<{ data: { types: string[]; editable: boolean; onInsert: (type: string) => void } }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-8 justify-center">
|
||||
<Handle type="target" :position="Position.Top" class="!opacity-0" />
|
||||
<AddStepMenu v-if="data.editable" :types="data.types" label="Add a step at the end" @pick="data.onInsert" />
|
||||
<span v-else class="size-2 rounded-full bg-border" aria-hidden="true" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import { Plus } from "@lucide/vue";
|
||||
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import StepTypeItems from "./StepTypeItems.vue";
|
||||
|
||||
defineProps<{ types: string[]; label?: string }>();
|
||||
const emit = defineEmits<{ pick: [string] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<button
|
||||
type="button"
|
||||
class="nodrag nopan flex size-6 items-center justify-center rounded-full border border-border bg-card text-muted-foreground shadow-sm transition-colors hover:border-primary hover:text-primary"
|
||||
:aria-label="label ?? 'Add a step here'"
|
||||
:title="label ?? 'Add a step here'"
|
||||
>
|
||||
<Plus class="size-3.5" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent class="w-52" align="center">
|
||||
<DropdownMenuLabel>{{ label ?? "Add a step here" }}</DropdownMenuLabel>
|
||||
<StepTypeItems :types="types" @pick="emit('pick', $event)" />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</template>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath, type EdgeProps } from "@vue-flow/core";
|
||||
|
||||
import AddStepMenu from "./AddStepMenu.vue";
|
||||
|
||||
const props = defineProps<EdgeProps<{ insertAfter?: number; types: string[]; editable: boolean; onInsert: (after: number, type: string) => void }>>();
|
||||
|
||||
const path = computed(() =>
|
||||
getSmoothStepPath({
|
||||
sourceX: props.sourceX,
|
||||
sourceY: props.sourceY,
|
||||
sourcePosition: props.sourcePosition,
|
||||
targetX: props.targetX,
|
||||
targetY: props.targetY,
|
||||
targetPosition: props.targetPosition,
|
||||
borderRadius: 8,
|
||||
}),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BaseEdge :id="id" :path="path[0]" class="workflow-flow-edge" />
|
||||
<EdgeLabelRenderer v-if="data?.editable && data.insertAfter !== undefined">
|
||||
<div
|
||||
class="workflow-insert absolute"
|
||||
:style="{ transform: `translate(-50%, -50%) translate(${path[1]}px, ${path[2]}px)`, pointerEvents: 'all' }"
|
||||
>
|
||||
<AddStepMenu :types="data.types" @pick="data.onInsert(data.insertAfter!, $event)" />
|
||||
</div>
|
||||
</EdgeLabelRenderer>
|
||||
</template>
|
||||
@@ -0,0 +1,261 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import { CircleHelp, Trash2, X } from "@lucide/vue";
|
||||
import { parse, stringify } from "yaml";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { stepIcon } from "./step-icons";
|
||||
import { earlierStepIDs, replaceStep, stepAt, type StepPath, type StepRecord } from "./workflow-edit";
|
||||
import { stepTitle } from "./workflow-graph";
|
||||
import { settingsProblem, type SettingsSchema, type StepTypeInfo } from "./workflow-yaml";
|
||||
|
||||
const props = defineProps<{ yaml: string; path: StepPath; vocabulary: StepTypeInfo[] }>();
|
||||
const emit = defineEmits<{ "update:yaml": [string]; close: []; remove: [] }>();
|
||||
|
||||
const step = computed<StepRecord>(() => stepAt(props.yaml, props.path) ?? {});
|
||||
const type = computed(() => (typeof step.value.type === "string" ? step.value.type : ""));
|
||||
const info = computed(() => props.vocabulary.find((candidate) => candidate.name === type.value));
|
||||
const settings = computed<Record<string, unknown>>(() =>
|
||||
typeof step.value.settings === "object" && step.value.settings !== null ? (step.value.settings as Record<string, unknown>) : {},
|
||||
);
|
||||
const earlier = computed(() => earlierStepIDs(props.yaml, props.path));
|
||||
const problem = computed(() =>
|
||||
info.value?.settings && step.value.settings ? settingsProblem(step.value.settings, info.value.settings, "settings") : "",
|
||||
);
|
||||
|
||||
type Kind = "select" | "text" | "line" | "boolean" | "number" | "lines" | "yaml";
|
||||
const LEAD = ["mission", "workflow", "message", "body", "plan", "then", "status", "detail", "run", "rules"];
|
||||
const longText = /mission|body|detail|plan|rules/;
|
||||
|
||||
function kindOf(key: string, schema: SettingsSchema): Kind {
|
||||
if (schema.type === "string") return schema.enum ? "select" : longText.test(key) ? "text" : "line";
|
||||
if (schema.type === "boolean") return "boolean";
|
||||
if (schema.type === "integer" || schema.type === "number") return "number";
|
||||
if (schema.type === "array" && schema.items?.type === "string") return "lines";
|
||||
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.
|
||||
const fields = computed(() => {
|
||||
const entries = Object.entries(info.value?.settings?.properties ?? {}).map(([key, schema]) => ({ key, schema, kind: kindOf(key, schema) }));
|
||||
const lead = entries.filter((field) => LEAD.includes(field.key) && field.kind !== "boolean").sort((a, b) => LEAD.indexOf(a.key) - LEAD.indexOf(b.key))[0];
|
||||
const rest = entries.filter((field) => field !== lead);
|
||||
return {
|
||||
lead,
|
||||
compact: rest.filter((field) => ["select", "line", "number", "boolean"].includes(field.kind)),
|
||||
long: rest.filter((field) => ["text", "lines", "yaml"].includes(field.kind)),
|
||||
};
|
||||
});
|
||||
|
||||
function write(next: StepRecord): void {
|
||||
// id and type lead, the way a step is read.
|
||||
const { id, type: stepType, ...rest } = next;
|
||||
emit("update:yaml", replaceStep(props.yaml, props.path, { id, type: stepType, ...rest }));
|
||||
}
|
||||
function setField(key: string, value: unknown): void {
|
||||
write({ ...step.value, [key]: value });
|
||||
}
|
||||
function setSetting(key: string, value: unknown): void {
|
||||
write({ ...step.value, settings: { ...settings.value, [key]: value } });
|
||||
}
|
||||
|
||||
// A reference goes into the text setting last focused: that is how this step
|
||||
// is connected to an earlier step's result.
|
||||
const focused = ref<string | null>(null);
|
||||
function reference(id: string, field: "summary" | "result"): void {
|
||||
const key = focused.value ?? fields.value.lead?.key;
|
||||
if (!key) return;
|
||||
const current = typeof settings.value[key] === "string" ? (settings.value[key] as string) : "";
|
||||
const token = `{{ steps.${id}.${field} }}`;
|
||||
setSetting(key, current ? `${current.trimEnd()} ${token}` : token);
|
||||
}
|
||||
|
||||
const yamlErrors = ref<Record<string, string>>({});
|
||||
function setYamlSetting(key: string, text: string): void {
|
||||
try {
|
||||
setSetting(key, text.trim() ? parse(text) : undefined);
|
||||
yamlErrors.value = { ...yamlErrors.value, [key]: "" };
|
||||
} catch (error) {
|
||||
yamlErrors.value = { ...yamlErrors.value, [key]: String((error as Error).message).split("\n")[0] };
|
||||
}
|
||||
}
|
||||
const asYaml = (value: unknown) => (value === undefined ? "" : stringify(value).trimEnd());
|
||||
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) : "");
|
||||
</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
|
||||
:value="(step.id as string) ?? ''"
|
||||
class="w-full truncate bg-transparent text-sm font-medium outline-none placeholder:text-fg-subtle focus:underline"
|
||||
:placeholder="stepTitle(type)"
|
||||
aria-label="Step id"
|
||||
@input="setField('id', ($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
<div class="truncate font-mono text-[11px] text-fg-subtle">{{ type }}</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">
|
||||
<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="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>
|
||||
<select
|
||||
v-if="fields.lead.kind === 'select'"
|
||||
class="h-9 w-full rounded-md border border-input bg-background px-2"
|
||||
:value="text(fields.lead.key)"
|
||||
@change="setSetting(fields.lead.key, ($event.target as HTMLSelectElement).value || undefined)"
|
||||
>
|
||||
<option value="">Default</option>
|
||||
<option v-for="option in fields.lead.schema.enum" :key="option" :value="option">{{ option }}</option>
|
||||
</select>
|
||||
<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" class="rounded-full border border-border px-2 py-0.5 font-mono text-[11px] hover:border-primary hover:text-primary" @click="reference(id, 'summary')">{{ id }}</button>
|
||||
<button type="button" class="rounded-full border border-border px-2 py-0.5 font-mono text-[11px] hover:border-primary hover:text-primary" @click="reference(id, 'result')">{{ id }}.result</button>
|
||||
</template>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<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">
|
||||
{{ label(field.key, field.schema) }}
|
||||
<CircleHelp v-if="field.schema.description" class="size-3 text-fg-subtle" />
|
||||
</span>
|
||||
<Switch
|
||||
v-if="field.kind === 'boolean'"
|
||||
:model-value="settings[field.key] === true"
|
||||
@update:model-value="setSetting(field.key, $event || undefined)"
|
||||
/>
|
||||
<select
|
||||
v-else-if="field.kind === 'select'"
|
||||
class="h-7 max-w-40 rounded-md border border-input bg-background px-1.5 text-[13px]"
|
||||
:value="text(field.key)"
|
||||
@change="setSetting(field.key, ($event.target as HTMLSelectElement).value || undefined)"
|
||||
>
|
||||
<option value="">Default</option>
|
||||
<option v-for="option in field.schema.enum" :key="option" :value="option">{{ option }}</option>
|
||||
</select>
|
||||
<input
|
||||
v-else-if="field.kind === 'number'"
|
||||
type="number"
|
||||
class="h-7 w-24 rounded-md border border-input bg-background px-2 text-right text-[13px]"
|
||||
:value="settings[field.key] ?? ''"
|
||||
@input="setSetting(field.key, ($event.target as HTMLInputElement).value === '' ? undefined : Number(($event.target as HTMLInputElement).value))"
|
||||
/>
|
||||
<input
|
||||
v-else
|
||||
class="h-7 w-40 rounded-md border border-input bg-background px-2 text-[13px]"
|
||||
:value="text(field.key)"
|
||||
@focus="focused = field.key"
|
||||
@input="setSetting(field.key, ($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-for="field in fields.long" :key="field.key" class="space-y-1.5">
|
||||
<div class="flex items-center gap-1 text-xs font-medium text-muted-foreground" :title="field.schema.description">
|
||||
{{ 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-else-if="field.kind === 'lines'"
|
||||
:model-value="Array.isArray(settings[field.key]) ? (settings[field.key] as string[]).join('\n') : ''"
|
||||
class="min-h-16 font-mono text-xs"
|
||||
placeholder="One per line"
|
||||
@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)"
|
||||
/>
|
||||
<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>
|
||||
<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>
|
||||
<input
|
||||
class="h-7 w-48 rounded-md border border-input bg-background px-2 font-mono text-xs"
|
||||
placeholder="always"
|
||||
:value="(step.when as string) ?? ''"
|
||||
@input="setField('when', ($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
</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>
|
||||
<select
|
||||
class="h-7 rounded-md border border-input bg-background px-1.5 text-[13px]"
|
||||
:value="(step.on_failure as string) ?? ''"
|
||||
@change="setField('on_failure', ($event.target as HTMLSelectElement).value || undefined)"
|
||||
>
|
||||
<option value="">Park the task</option>
|
||||
<option value="continue">Continue</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
||||
<span class="flex-1 text-[13px]">Attempts</span>
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
max="10"
|
||||
placeholder="1"
|
||||
class="h-7 w-20 rounded-md border border-input bg-background px-2 text-right text-[13px]"
|
||||
:value="(step.retry as { attempts?: number } | undefined)?.attempts ?? ''"
|
||||
@input="setField('retry', ($event.target as HTMLInputElement).value === '' ? undefined : { ...(step.retry as object), attempts: Number(($event.target as HTMLInputElement).value) })"
|
||||
/>
|
||||
</label>
|
||||
</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>
|
||||
@@ -3,6 +3,7 @@ import { computed } from "vue";
|
||||
import { Handle, Position } from "@vue-flow/core";
|
||||
import { Flag, GitBranch, Play, Repeat, SkipForward, Webhook, CircleDot, BookOpen, Workflow } from "@lucide/vue";
|
||||
|
||||
import { stepIcon } from "./step-icons";
|
||||
import type { StepNodeData } from "./workflow-graph";
|
||||
|
||||
const props = defineProps<{ data: StepNodeData }>();
|
||||
@@ -39,12 +40,13 @@ function duration(ms?: number): string {
|
||||
<template>
|
||||
<div
|
||||
class="w-60 rounded-lg border bg-card px-3 py-2 text-left shadow-sm"
|
||||
:class="[stateClass, data.selected && 'ring-2 ring-ring', data.kind === 'step' && 'cursor-pointer']"
|
||||
:class="[stateClass, data.selected && 'ring-2 ring-ring', data.kind === 'step' && 'cursor-pointer transition-colors hover:border-muted-foreground']"
|
||||
>
|
||||
<Handle v-if="data.kind !== 'start'" 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 class="truncate text-sm font-medium" :title="data.title">{{ data.title }}</span>
|
||||
<span v-if="data.branch" class="ml-auto flex items-center gap-0.5 text-[11px] text-fg-subtle">
|
||||
<GitBranch class="size-3" aria-hidden="true" />{{ data.branch }}
|
||||
@@ -60,6 +62,7 @@ function duration(ms?: number): string {
|
||||
</ul>
|
||||
<div v-else-if="data.kind === 'start'" class="mt-0.5 text-xs text-muted-foreground">Nothing starts it yet; run it by hand or bind an event to it.</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>
|
||||
|
||||
@@ -1,276 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { ArrowDown, ArrowUp, Link2, Plus, Trash2, X } from "@lucide/vue";
|
||||
import { parse, stringify } from "yaml";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { stepTitle } from "./workflow-graph";
|
||||
import {
|
||||
deleteStep,
|
||||
earlierStepIDs,
|
||||
insertStep,
|
||||
moveStep,
|
||||
replaceStep,
|
||||
stepAt,
|
||||
type StepPath,
|
||||
type StepRecord,
|
||||
} from "./workflow-edit";
|
||||
import { settingsProblem, type SettingsSchema, type StepTypeInfo } from "./workflow-yaml";
|
||||
|
||||
const props = defineProps<{ yaml: string; path: StepPath | null; vocabulary: StepTypeInfo[] }>();
|
||||
const emit = defineEmits<{ "update:yaml": [string]; select: [StepPath | null] }>();
|
||||
|
||||
const step = computed(() => (props.path ? stepAt(props.yaml, props.path) : undefined));
|
||||
const type = computed(() => (typeof step.value?.type === "string" ? step.value.type : ""));
|
||||
const info = computed(() => props.vocabulary.find((candidate) => candidate.name === type.value));
|
||||
const settings = computed<Record<string, unknown>>(() =>
|
||||
typeof step.value?.settings === "object" && step.value.settings !== null
|
||||
? (step.value.settings as Record<string, unknown>)
|
||||
: {},
|
||||
);
|
||||
// The schema's keys arrive sorted; the setting that says what a step does
|
||||
// comes first.
|
||||
const LEAD = ["mission", "workflow", "message", "body", "plan", "then", "status", "detail", "run", "rules"];
|
||||
const fields = computed(() =>
|
||||
Object.entries(info.value?.settings?.properties ?? {}).sort(([a], [b]) => {
|
||||
const rank = (key: string) => (LEAD.includes(key) ? LEAD.indexOf(key) : LEAD.length);
|
||||
return rank(a) - rank(b);
|
||||
}),
|
||||
);
|
||||
const earlier = computed(() => (props.path ? earlierStepIDs(props.yaml, props.path) : []));
|
||||
const inBranch = computed(() => (props.path?.length ?? 0) > 2);
|
||||
const problem = computed(() =>
|
||||
info.value?.settings && step.value?.settings ? settingsProblem(step.value.settings, info.value.settings, "settings") : "",
|
||||
);
|
||||
|
||||
// The palette is open while nothing is selected; selecting a step, including
|
||||
// the one just added, folds it away so that step's form is what shows.
|
||||
const paletteOpen = ref(true);
|
||||
watch(() => JSON.stringify(props.path), () => (paletteOpen.value = !props.path), { immediate: true });
|
||||
|
||||
const groups = computed(() => {
|
||||
const byGroup = new Map<string, StepTypeInfo[]>();
|
||||
for (const candidate of props.vocabulary) {
|
||||
const group = candidate.name.split(".")[0];
|
||||
byGroup.set(group, [...(byGroup.get(group) ?? []), candidate]);
|
||||
}
|
||||
return [...byGroup.entries()];
|
||||
});
|
||||
|
||||
function write(next: StepRecord): void {
|
||||
// id and type lead, the way a step is read.
|
||||
const { id, type: stepType, ...rest } = next;
|
||||
if (props.path) emit("update:yaml", replaceStep(props.yaml, props.path, { id, type: stepType, ...rest }));
|
||||
}
|
||||
function setField(key: string, value: unknown): void {
|
||||
write({ ...step.value, [key]: value });
|
||||
}
|
||||
function setSetting(key: string, value: unknown): void {
|
||||
write({ ...step.value, settings: { ...settings.value, [key]: value } });
|
||||
}
|
||||
|
||||
function add(stepType: string): void {
|
||||
const after = props.path && props.path.length === 2 ? Number(props.path[1]) : Number.MAX_SAFE_INTEGER;
|
||||
const inserted = insertStep(props.yaml, after, stepType);
|
||||
emit("update:yaml", inserted.source);
|
||||
emit("select", inserted.path);
|
||||
}
|
||||
function move(delta: -1 | 1): void {
|
||||
if (!props.path) return;
|
||||
const moved = moveStep(props.yaml, props.path, delta);
|
||||
emit("update:yaml", moved.source);
|
||||
emit("select", moved.path);
|
||||
}
|
||||
function remove(): void {
|
||||
if (!props.path) return;
|
||||
emit("update:yaml", deleteStep(props.yaml, props.path));
|
||||
emit("select", null);
|
||||
}
|
||||
|
||||
// A reference is inserted into the text field last focused, which is how a
|
||||
// later step is connected to an earlier step's result.
|
||||
const focused = ref<string | null>(null);
|
||||
function reference(id: string, field: "summary" | "result"): void {
|
||||
const key = focused.value ?? fields.value.find(([, schema]) => schema.type === "string")?.[0];
|
||||
if (!key) return;
|
||||
const current = typeof settings.value[key] === "string" ? (settings.value[key] as string) : "";
|
||||
const token = field === "summary" ? `{{ steps.${id}.summary }}` : `{{ steps.${id}.result }}`;
|
||||
setSetting(key, current ? `${current.trimEnd()} ${token}` : token);
|
||||
}
|
||||
|
||||
const longText = /mission|body|detail|plan|rules/;
|
||||
function kindOf(key: string, schema: SettingsSchema): "select" | "text" | "line" | "boolean" | "number" | "lines" | "yaml" {
|
||||
if (schema.type === "string") return schema.enum ? "select" : longText.test(key) ? "text" : "line";
|
||||
if (schema.type === "boolean") return "boolean";
|
||||
if (schema.type === "integer" || schema.type === "number") return "number";
|
||||
if (schema.type === "array" && schema.items?.type === "string") return "lines";
|
||||
return "yaml";
|
||||
}
|
||||
|
||||
const yamlErrors = ref<Record<string, string>>({});
|
||||
function setYamlSetting(key: string, text: string): void {
|
||||
try {
|
||||
setSetting(key, text.trim() ? parse(text) : undefined);
|
||||
yamlErrors.value = { ...yamlErrors.value, [key]: "" };
|
||||
} catch (error) {
|
||||
yamlErrors.value = { ...yamlErrors.value, [key]: String((error as Error).message).split("\n")[0] };
|
||||
}
|
||||
}
|
||||
function asYaml(value: unknown): string {
|
||||
return value === undefined ? "" : stringify(value).trimEnd();
|
||||
}
|
||||
function label(key: string, schema: SettingsSchema): string {
|
||||
return schema.title ?? key.replaceAll("_", " ").replace(/^./, (c) => c.toUpperCase());
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="flex h-[560px] flex-col gap-3 overflow-y-auto rounded-lg border border-border bg-card p-3 text-sm">
|
||||
<template v-if="step && path">
|
||||
<div class="flex items-start gap-2">
|
||||
<div class="min-w-0">
|
||||
<div class="truncate font-medium">{{ stepTitle(type) }}</div>
|
||||
<div class="font-mono text-[11px] text-fg-subtle">{{ type }}</div>
|
||||
</div>
|
||||
<Button type="button" variant="ghost" size="icon" class="ml-auto size-7" aria-label="Close" @click="emit('select', null)"><X /></Button>
|
||||
</div>
|
||||
<p v-if="problem" class="rounded bg-danger/10 px-2 py-1 text-xs text-danger" role="alert">{{ problem }}</p>
|
||||
|
||||
<label class="flex flex-col gap-1">
|
||||
<span class="text-xs text-muted-foreground">Step id</span>
|
||||
<Input
|
||||
:model-value="(step.id as string) ?? ''"
|
||||
class="h-8 font-mono"
|
||||
placeholder="name it so later steps can use its result"
|
||||
@update:model-value="setField('id', String($event))"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<template v-for="[key, schema] in fields" :key="key">
|
||||
<label v-if="kindOf(key, schema) === 'boolean'" class="flex items-start gap-2" :title="schema.description">
|
||||
<input type="checkbox" class="mt-0.5" :checked="settings[key] === true" @change="setSetting(key, ($event.target as HTMLInputElement).checked || undefined)" />
|
||||
<span>{{ label(key, schema) }}<span v-if="schema.description" class="block text-xs text-fg-subtle">{{ schema.description }}</span></span>
|
||||
</label>
|
||||
<label v-else class="flex flex-col gap-1">
|
||||
<span class="text-xs text-muted-foreground">{{ label(key, schema) }}</span>
|
||||
<select
|
||||
v-if="kindOf(key, schema) === 'select'"
|
||||
class="h-8 rounded-md border border-input bg-background px-2"
|
||||
:value="(settings[key] as string) ?? ''"
|
||||
@change="setSetting(key, ($event.target as HTMLSelectElement).value || undefined)"
|
||||
>
|
||||
<option value="">(default)</option>
|
||||
<option v-for="option in schema.enum" :key="option" :value="option">{{ option }}</option>
|
||||
</select>
|
||||
<Textarea
|
||||
v-else-if="kindOf(key, schema) === 'text'"
|
||||
:model-value="(settings[key] as string) ?? ''"
|
||||
class="min-h-28 font-mono text-xs"
|
||||
@focus="focused = key"
|
||||
@update:model-value="setSetting(key, String($event))"
|
||||
/>
|
||||
<Input
|
||||
v-else-if="kindOf(key, schema) === 'line'"
|
||||
:model-value="(settings[key] as string) ?? ''"
|
||||
class="h-8"
|
||||
@focus="focused = key"
|
||||
@update:model-value="setSetting(key, String($event))"
|
||||
/>
|
||||
<Input
|
||||
v-else-if="kindOf(key, schema) === 'number'"
|
||||
type="number"
|
||||
:model-value="(settings[key] as number) ?? ''"
|
||||
class="h-8"
|
||||
@update:model-value="setSetting(key, $event === '' ? undefined : Number($event))"
|
||||
/>
|
||||
<Textarea
|
||||
v-else-if="kindOf(key, schema) === 'lines'"
|
||||
:model-value="Array.isArray(settings[key]) ? (settings[key] as string[]).join('\n') : ''"
|
||||
class="min-h-16 font-mono text-xs"
|
||||
placeholder="one per line"
|
||||
@update:model-value="setSetting(key, String($event).split('\n').filter(Boolean))"
|
||||
/>
|
||||
<template v-else>
|
||||
<Textarea
|
||||
:model-value="asYaml(settings[key])"
|
||||
class="min-h-24 font-mono text-xs"
|
||||
placeholder="YAML"
|
||||
@change="setYamlSetting(key, ($event.target as HTMLTextAreaElement).value)"
|
||||
/>
|
||||
<span v-if="yamlErrors[key]" class="text-xs text-danger">{{ yamlErrors[key] }}</span>
|
||||
</template>
|
||||
<span v-if="schema.description" class="text-xs text-fg-subtle">{{ schema.description }}</span>
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<div v-if="earlier.length && fields.some(([, schema]) => schema.type === 'string')" class="space-y-1">
|
||||
<span class="flex items-center gap-1 text-xs text-muted-foreground"><Link2 class="size-3" aria-hidden="true" />Use an earlier step's result</span>
|
||||
<div class="flex flex-wrap gap-1">
|
||||
<template v-for="id in earlier" :key="id">
|
||||
<button type="button" class="rounded bg-secondary px-1.5 py-0.5 font-mono text-[11px] hover:bg-secondary/70" @click="reference(id, 'summary')">{{ id }}.summary</button>
|
||||
<button type="button" class="rounded bg-secondary px-1.5 py-0.5 font-mono text-[11px] hover:bg-secondary/70" @click="reference(id, 'result')">{{ id }}.result</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<details class="space-y-2">
|
||||
<summary class="cursor-pointer text-xs text-muted-foreground">When, failure and retry</summary>
|
||||
<label class="mt-2 flex flex-col gap-1">
|
||||
<span class="text-xs text-muted-foreground">Run only when</span>
|
||||
<Input :model-value="(step.when as string) ?? ''" class="h-8 font-mono" placeholder="steps.assess.result.fit" @update:model-value="setField('when', String($event))" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1">
|
||||
<span class="text-xs text-muted-foreground">If it fails</span>
|
||||
<select class="h-8 rounded-md border border-input bg-background px-2" :value="(step.on_failure as string) ?? ''" @change="setField('on_failure', ($event.target as HTMLSelectElement).value || undefined)">
|
||||
<option value="">Park the task</option>
|
||||
<option value="continue">Continue to the next step</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="flex flex-col gap-1">
|
||||
<span class="text-xs text-muted-foreground">Attempts</span>
|
||||
<Input
|
||||
type="number"
|
||||
min="1"
|
||||
max="10"
|
||||
:model-value="((step.retry as { attempts?: number } | undefined)?.attempts) ?? ''"
|
||||
class="h-8"
|
||||
@update:model-value="setField('retry', $event === '' ? undefined : { ...(step.retry as object), attempts: Number($event) })"
|
||||
/>
|
||||
</label>
|
||||
</details>
|
||||
|
||||
<div class="mt-auto flex flex-wrap gap-1.5 border-t border-border pt-3">
|
||||
<Button type="button" variant="outline" size="sm" @click="move(-1)"><ArrowUp /> Up</Button>
|
||||
<Button type="button" variant="outline" size="sm" @click="move(1)"><ArrowDown /> Down</Button>
|
||||
<Button type="button" variant="ghost" size="sm" class="ml-auto text-danger" @click="remove"><Trash2 /> Remove</Button>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else class="text-xs text-fg-subtle">Select a step to edit it.</div>
|
||||
|
||||
<details
|
||||
v-if="!inBranch"
|
||||
:open="paletteOpen"
|
||||
class="space-y-2 border-t border-border pt-3"
|
||||
@toggle="paletteOpen = ($event.target as HTMLDetailsElement).open"
|
||||
>
|
||||
<summary class="cursor-pointer text-xs font-medium">{{ step ? "Add a step after this one" : "Add a step" }}</summary>
|
||||
<div v-for="[group, members] in groups" :key="group" class="space-y-1">
|
||||
<div class="text-[11px] tracking-wide text-fg-subtle uppercase">{{ group }}</div>
|
||||
<div class="flex flex-wrap gap-1">
|
||||
<button
|
||||
v-for="candidate in members"
|
||||
:key="candidate.name"
|
||||
type="button"
|
||||
class="flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-xs hover:bg-secondary"
|
||||
:title="candidate.name"
|
||||
@click="add(candidate.name)"
|
||||
>
|
||||
<Plus class="size-3" aria-hidden="true" />{{ stepTitle(candidate.name) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</aside>
|
||||
</template>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { stepGroups } from "./step-icons";
|
||||
import { stepTitle } from "./workflow-graph";
|
||||
|
||||
const props = defineProps<{ types: string[] }>();
|
||||
const emit = defineEmits<{ pick: [string] }>();
|
||||
|
||||
const groups = computed(() => stepGroups(props.types));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-for="group in groups" :key="group.title">
|
||||
<!-- A group of one is its step: no submenu to open for a single choice. -->
|
||||
<DropdownMenuItem v-if="group.types.length === 1" @select="emit('pick', group.types[0])">
|
||||
<component :is="group.icon" />
|
||||
{{ stepTitle(group.types[0]) }}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSub v-else>
|
||||
<DropdownMenuSubTrigger>
|
||||
<component :is="group.icon" />
|
||||
{{ group.title }}
|
||||
</DropdownMenuSubTrigger>
|
||||
<DropdownMenuSubContent class="w-52">
|
||||
<DropdownMenuItem v-for="type in group.types" :key="type" @select="emit('pick', type)">
|
||||
{{ stepTitle(type) }}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuSubContent>
|
||||
</DropdownMenuSub>
|
||||
</template>
|
||||
</template>
|
||||
@@ -1,30 +1,59 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { VueFlow, type VueFlowStore } from "@vue-flow/core";
|
||||
import { VueFlow, type NodeMouseEvent, type VueFlowStore } from "@vue-flow/core";
|
||||
import { Background } from "@vue-flow/background";
|
||||
import { Controls } from "@vue-flow/controls";
|
||||
import { ArrowDown, ArrowUp, Copy, Pencil, Trash2 } from "@lucide/vue";
|
||||
import "@vue-flow/core/dist/style.css";
|
||||
import "@vue-flow/controls/dist/style.css";
|
||||
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import AddNode from "./AddNode.vue";
|
||||
import InsertEdge from "./InsertEdge.vue";
|
||||
import StepNode from "./StepNode.vue";
|
||||
import { withRuns, workflowGraph, type StageRun } from "./workflow-graph";
|
||||
import StepTypeItems from "./StepTypeItems.vue";
|
||||
import type { StepPath } from "./workflow-edit";
|
||||
import { stepTitle, withRuns, workflowGraph, type StageRun, type StepNodeData } from "./workflow-graph";
|
||||
import type { WorkflowTrigger } from "./workflow-triggers";
|
||||
|
||||
const props = defineProps<{
|
||||
yaml: string;
|
||||
stages?: StageRun[];
|
||||
selected?: (string | number)[] | null;
|
||||
selected?: StepPath | null;
|
||||
triggers?: WorkflowTrigger[];
|
||||
/** Step type names; when given, the canvas offers editing. */
|
||||
types?: string[];
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
edit: [StepPath];
|
||||
insert: [after: number, type: string];
|
||||
duplicate: [StepPath];
|
||||
move: [StepPath, -1 | 1];
|
||||
remove: [StepPath];
|
||||
}>();
|
||||
const emit = defineEmits<{ select: [(string | number)[] | null] }>();
|
||||
|
||||
const NODE_WIDTH = 240;
|
||||
const editable = computed(() => !!props.types?.length);
|
||||
const types = computed(() => props.types ?? []);
|
||||
|
||||
const container = ref<HTMLElement | null>(null);
|
||||
const graph = computed(() => withRuns(workflowGraph(props.yaml), props.stages ?? []));
|
||||
const selectedKey = computed(() => JSON.stringify(props.selected ?? null));
|
||||
const stepCount = computed(() => graph.value.nodes.filter((node) => node.data.path?.length === 2).length);
|
||||
const nodes = computed(() =>
|
||||
graph.value.nodes.map((node) => {
|
||||
if (node.type === "add")
|
||||
return { ...node, data: { types: types.value, editable: editable.value, onInsert: (type: string) => emit("insert", stepCount.value - 1, 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;
|
||||
@@ -35,14 +64,21 @@ const nodes = computed(() =>
|
||||
}),
|
||||
);
|
||||
const edges = computed(() =>
|
||||
graph.value.edges.map(({ label, offset, ...edge }) => ({
|
||||
...edge,
|
||||
type: "smoothstep",
|
||||
pathOptions: { offset: offset ?? 20, borderRadius: 8 },
|
||||
class: edge.kind === "data" ? "workflow-data-edge" : "workflow-flow-edge",
|
||||
// A data edge names the result it carries on hover, not on the canvas.
|
||||
data: { label },
|
||||
})),
|
||||
graph.value.edges.map(({ label, offset, insertAfter, ...edge }) =>
|
||||
edge.kind === "flow"
|
||||
? {
|
||||
...edge,
|
||||
type: "insert",
|
||||
data: { insertAfter, types: types.value, editable: editable.value, onInsert: (after: number, type: string) => emit("insert", after, type) },
|
||||
}
|
||||
: {
|
||||
...edge,
|
||||
type: "smoothstep",
|
||||
pathOptions: { offset: offset ?? 20, borderRadius: 8 },
|
||||
class: "workflow-data-edge",
|
||||
data: { label },
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
const ZOOM = 0.9;
|
||||
@@ -57,16 +93,36 @@ function place(store?: VueFlowStore): void {
|
||||
if (!flow) return;
|
||||
const width = container.value?.clientWidth ?? 800;
|
||||
const height = container.value?.clientHeight ?? 560;
|
||||
const reached = nodes.value.filter((node) => node.data.run).at(-1);
|
||||
const reached = graph.value.nodes.filter((node) => node.data.run).at(-1);
|
||||
const y = reached ? Math.min(24, height / 3 - reached.position.y * ZOOM) : 24;
|
||||
void flow.setViewport({ x: width / 2 - NODE_WIDTH / 2, y, zoom: ZOOM }, { duration: animate ? 300 : 0 });
|
||||
}
|
||||
|
||||
watch(() => nodes.value.filter((node) => node.data.run).length, () => place());
|
||||
watch(() => graph.value.nodes.filter((node) => node.data.run).length, () => place());
|
||||
|
||||
// The right-click menu opens at the pointer, for the step under it or for the
|
||||
// canvas itself.
|
||||
const menu = ref<{ open: boolean; x: number; y: number; step?: StepNodeData }>({ open: false, x: 0, y: 0 });
|
||||
function openMenu(event: MouseEvent, step?: StepNodeData): void {
|
||||
if (!editable.value) return;
|
||||
event.preventDefault();
|
||||
const box = container.value?.getBoundingClientRect();
|
||||
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 === "add") return;
|
||||
openMenu(event as MouseEvent, node.data as StepNodeData);
|
||||
}
|
||||
function onNodeClick({ node }: NodeMouseEvent): void {
|
||||
const path = (node.data as StepNodeData).path;
|
||||
if (editable.value && path) emit("edit", path);
|
||||
}
|
||||
const menuPath = computed(() => menu.value.step?.path);
|
||||
const topIndex = computed(() => (menuPath.value?.length === 2 ? Number(menuPath.value[1]) : undefined));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="container" class="workflow-canvas h-[560px] overflow-hidden rounded-lg border border-border bg-background">
|
||||
<div ref="container" class="workflow-canvas relative h-[620px] overflow-hidden rounded-lg border border-border bg-background">
|
||||
<VueFlow
|
||||
class="h-full"
|
||||
:nodes="nodes"
|
||||
@@ -78,15 +134,53 @@ watch(() => nodes.value.filter((node) => node.data.run).length, () => place());
|
||||
:max-zoom="1.5"
|
||||
pan-on-scroll
|
||||
@pane-ready="place"
|
||||
@node-click="({ node }) => emit('select', node.data.path ?? null)"
|
||||
@pane-click="emit('select', null)"
|
||||
@node-click="onNodeClick"
|
||||
@node-context-menu="onNodeMenu"
|
||||
@pane-context-menu="openMenu($event as MouseEvent)"
|
||||
>
|
||||
<template #node-step="nodeProps">
|
||||
<StepNode v-bind="nodeProps" />
|
||||
</template>
|
||||
<template #node-add="nodeProps">
|
||||
<AddNode v-bind="nodeProps" />
|
||||
</template>
|
||||
<template #edge-insert="edgeProps">
|
||||
<InsertEdge v-bind="edgeProps" />
|
||||
</template>
|
||||
<Background :gap="20" />
|
||||
<Controls :show-interactive="false" />
|
||||
</VueFlow>
|
||||
|
||||
<DropdownMenu v-model:open="menu.open">
|
||||
<DropdownMenuTrigger as-child>
|
||||
<span class="pointer-events-none absolute size-0" :style="{ left: `${menu.x}px`, top: `${menu.y}px` }" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent class="w-56" align="start">
|
||||
<template v-if="menu.step?.kind === 'step' && menuPath">
|
||||
<DropdownMenuLabel class="truncate">{{ menu.step.title || stepTitle(menu.step.type) }}</DropdownMenuLabel>
|
||||
<DropdownMenuItem @select="emit('edit', menuPath)"><Pencil /> Edit</DropdownMenuItem>
|
||||
<template v-if="topIndex !== undefined">
|
||||
<DropdownMenuSub>
|
||||
<DropdownMenuSubTrigger>Insert before</DropdownMenuSubTrigger>
|
||||
<DropdownMenuSubContent class="w-52"><StepTypeItems :types="types" @pick="emit('insert', topIndex - 1, $event)" /></DropdownMenuSubContent>
|
||||
</DropdownMenuSub>
|
||||
<DropdownMenuSub>
|
||||
<DropdownMenuSubTrigger>Insert after</DropdownMenuSubTrigger>
|
||||
<DropdownMenuSubContent class="w-52"><StepTypeItems :types="types" @pick="emit('insert', topIndex, $event)" /></DropdownMenuSubContent>
|
||||
</DropdownMenuSub>
|
||||
</template>
|
||||
<DropdownMenuItem @select="emit('duplicate', menuPath)"><Copy /> Duplicate</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="emit('move', menuPath, -1)"><ArrowUp /> Move up</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="emit('move', menuPath, 1)"><ArrowDown /> Move down</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem variant="destructive" @select="emit('remove', menuPath)"><Trash2 /> Delete</DropdownMenuItem>
|
||||
</template>
|
||||
<template v-else>
|
||||
<DropdownMenuLabel>{{ menu.step?.kind === "start" ? "Add the first step" : "Add a step at the end" }}</DropdownMenuLabel>
|
||||
<StepTypeItems :types="types" @pick="emit('insert', menu.step?.kind === 'start' ? -1 : stepCount - 1, $event)" />
|
||||
</template>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import { Label } from "@/components/ui/label";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import StepPanel from "./StepPanel.vue";
|
||||
import StepEditor from "./StepEditor.vue";
|
||||
import WorkflowCanvas from "./WorkflowCanvas.vue";
|
||||
import type { StepPath } from "./workflow-edit";
|
||||
import { deleteStep, duplicateStep, insertStep, moveStep, type StepPath } from "./workflow-edit";
|
||||
import { useWorkflowRuns } from "./workflow-runs";
|
||||
import { useWorkflowTriggers } from "./workflow-triggers";
|
||||
import {
|
||||
@@ -47,6 +47,28 @@ const localError = ref("");
|
||||
const { runs, watched, stages, pick } = useWorkflowRuns(selected);
|
||||
const triggers = useWorkflowTriggers(selected);
|
||||
|
||||
// Canvas edits are edits to the YAML; a newly placed step opens for editing.
|
||||
const stepTypeNames = computed(() => vocabulary.value.map((info) => info.name));
|
||||
function insertAt(after: number, type: string): void {
|
||||
const inserted = insertStep(yaml.value, after, type);
|
||||
yaml.value = inserted.source;
|
||||
selectedStep.value = inserted.path;
|
||||
}
|
||||
function duplicateAt(path: StepPath): void {
|
||||
const copied = duplicateStep(yaml.value, path);
|
||||
yaml.value = copied.source;
|
||||
selectedStep.value = 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;
|
||||
}
|
||||
function removeAt(path: StepPath): void {
|
||||
yaml.value = deleteStep(yaml.value, path);
|
||||
selectedStep.value = null;
|
||||
}
|
||||
|
||||
const shippedEntry = computed(() =>
|
||||
shipped.value.definitions.find((entry) => entry.id === id.value),
|
||||
);
|
||||
@@ -163,9 +185,36 @@ function syncScroll(event: Event): void {
|
||||
</select>
|
||||
<span v-if="!runs.length" class="text-xs text-fg-subtle">This workflow has not run yet.</span>
|
||||
</label>
|
||||
<div class="grid gap-3 lg:grid-cols-[1fr_20rem]">
|
||||
<WorkflowCanvas :yaml="yaml" :stages="stages" :selected="selectedStep" :triggers="triggers" @select="selectedStep = $event" />
|
||||
<StepPanel v-model:yaml="yaml" :path="selectedStep" :vocabulary="vocabulary" @select="selectedStep = $event" />
|
||||
<div class="relative">
|
||||
<WorkflowCanvas
|
||||
:yaml="yaml"
|
||||
:stages="stages"
|
||||
:selected="selectedStep"
|
||||
:triggers="triggers"
|
||||
:types="stepTypeNames"
|
||||
@edit="selectedStep = $event"
|
||||
@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"
|
||||
>
|
||||
<div v-if="selectedStep" class="absolute inset-y-0 right-0 overflow-hidden rounded-r-lg">
|
||||
<StepEditor
|
||||
:key="JSON.stringify(selectedStep)"
|
||||
v-model:yaml="yaml"
|
||||
:path="selectedStep"
|
||||
:vocabulary="vocabulary"
|
||||
@close="selectedStep = null"
|
||||
@remove="removeAt(selectedStep)"
|
||||
/>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</TabsContent>
|
||||
<TabsContent value="yaml">
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Bot, FileSearch, GitBranch, MessageSquare, ShieldCheck, Terminal, UserCheck, Workflow } from "@lucide/vue";
|
||||
import type { Component } from "vue";
|
||||
|
||||
const GROUP_ICONS: Record<string, Component> = {
|
||||
agent: Bot,
|
||||
command: Terminal,
|
||||
repo: GitBranch,
|
||||
gate: ShieldCheck,
|
||||
forge: MessageSquare,
|
||||
human: UserCheck,
|
||||
review: FileSearch,
|
||||
workflow: Workflow,
|
||||
};
|
||||
|
||||
const GROUP_TITLES: Record<string, string> = {
|
||||
agent: "Agents",
|
||||
command: "Commands",
|
||||
repo: "Repository",
|
||||
gate: "Checks",
|
||||
forge: "Issues and PRs",
|
||||
human: "People",
|
||||
review: "Review",
|
||||
workflow: "Flow",
|
||||
};
|
||||
|
||||
/** The icon for a step type, by the area its name starts with. */
|
||||
export function stepIcon(type: string): Component {
|
||||
return GROUP_ICONS[type.split(".")[0]] ?? Workflow;
|
||||
}
|
||||
|
||||
/** Step type names grouped by area, in a fixed reading order. */
|
||||
export function stepGroups(types: string[]): { title: string; icon: Component; types: string[] }[] {
|
||||
return Object.keys(GROUP_TITLES)
|
||||
.map((group) => ({
|
||||
title: GROUP_TITLES[group],
|
||||
icon: GROUP_ICONS[group],
|
||||
types: types.filter((type) => type.split(".")[0] === group),
|
||||
}))
|
||||
.filter((group) => group.types.length);
|
||||
}
|
||||
@@ -43,6 +43,19 @@ export function insertStep(source: string, after: number, type: string): { sourc
|
||||
return { source: document.toString(), path: ["steps", index] };
|
||||
}
|
||||
|
||||
/** Copies a step to just after itself. The copy drops the id, which must stay
|
||||
* unique. Returns the new source and the copy's path. */
|
||||
export function duplicateStep(source: string, path: StepPath): { source: string; path: StepPath } {
|
||||
const document = parseDocument(source);
|
||||
const list = document.getIn(path.slice(0, -1), true);
|
||||
const index = path.at(-1);
|
||||
if (!isSeq(list) || typeof index !== "number") return { source, path };
|
||||
const copy = document.createNode(document.getIn(path));
|
||||
if (isMap(copy)) copy.delete("id");
|
||||
list.items.splice(index + 1, 0, copy);
|
||||
return { source: document.toString(), path: [...path.slice(0, -1), index + 1] };
|
||||
}
|
||||
|
||||
/** Removes a step. A branch left empty is removed with it. */
|
||||
export function deleteStep(source: string, path: StepPath): string {
|
||||
const document = parseDocument(source);
|
||||
|
||||
@@ -15,6 +15,8 @@ export interface StepNodeData {
|
||||
title: string;
|
||||
type: string;
|
||||
detail: string;
|
||||
/** The first line of what the step is told to do, if it says. */
|
||||
summary?: string;
|
||||
when?: string;
|
||||
retry?: number;
|
||||
continues?: boolean;
|
||||
@@ -54,7 +56,7 @@ export function withRuns(graph: WorkflowGraph, stages: StageRun[]): WorkflowGrap
|
||||
|
||||
export interface GraphNode {
|
||||
id: string;
|
||||
type: "step";
|
||||
type: "step" | "add";
|
||||
position: { x: number; y: number };
|
||||
data: StepNodeData;
|
||||
}
|
||||
@@ -69,6 +71,9 @@ export interface GraphEdge {
|
||||
sourceHandle?: string;
|
||||
targetHandle?: string;
|
||||
offset?: number;
|
||||
/** A step inserted on this edge goes after the top-level step at this
|
||||
* index (-1: first). Absent inside parallel branches. */
|
||||
insertAfter?: number;
|
||||
}
|
||||
|
||||
export interface WorkflowGraph {
|
||||
@@ -76,7 +81,7 @@ export interface WorkflowGraph {
|
||||
edges: GraphEdge[];
|
||||
}
|
||||
|
||||
const ROW = 120;
|
||||
const ROW = 140;
|
||||
const COLUMN = 280;
|
||||
|
||||
const TYPE_TITLES: Record<string, string> = {
|
||||
@@ -136,6 +141,20 @@ function stepDetail(type: string, settings: Mapping): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
/** The first line of a step's main text setting, references shown by name. */
|
||||
function stepSummary(settings: Mapping): string | undefined {
|
||||
for (const key of ["mission", "message", "body", "plan", "detail"]) {
|
||||
const value = settings[key];
|
||||
if (typeof value !== "string" || !value.trim()) continue;
|
||||
return value
|
||||
.replace(/\{\{\s*([^}]+?)\s*\}\}/g, "‹$1›")
|
||||
.split("\n")
|
||||
.find((line) => line.trim())
|
||||
?.trim();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Every step id a step's settings reference. */
|
||||
function referencedSteps(settings: unknown, when: unknown): string[] {
|
||||
const text = JSON.stringify(settings ?? {}) + " " + (typeof when === "string" ? `{{ ${when.replace(/^!/, "")} }}` : "");
|
||||
@@ -190,6 +209,7 @@ export function workflowGraph(source: string): WorkflowGraph {
|
||||
title: stepID || stepTitle(type),
|
||||
type,
|
||||
detail: stepDetail(type, settings),
|
||||
summary: stepSummary(settings),
|
||||
when: typeof record.when === "string" ? record.when : undefined,
|
||||
retry: isMapping(record.retry) && typeof record.retry.attempts === "number" ? record.retry.attempts : undefined,
|
||||
continues: record.on_failure === "continue",
|
||||
@@ -202,8 +222,17 @@ export function workflowGraph(source: string): WorkflowGraph {
|
||||
for (const ref of referencedSteps(record.settings, record.when)) pendingData.push({ from: ref, to: id });
|
||||
return id;
|
||||
};
|
||||
const link = (from: string[], to: string) => {
|
||||
for (const source of from) edges.push({ id: `flow-${source}-${to}`, source, target: to, kind: "flow" });
|
||||
const link = (from: string[], to: string, insertAfter?: number) => {
|
||||
// Several edges joining into one step share one insertion point.
|
||||
from.forEach((source, n) =>
|
||||
edges.push({
|
||||
id: `flow-${source}-${to}`,
|
||||
source,
|
||||
target: to,
|
||||
kind: "flow",
|
||||
insertAfter: n === from.length - 1 ? insertAfter : undefined,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
for (const [i, step] of steps.entries()) {
|
||||
@@ -217,9 +246,10 @@ export function workflowGraph(source: string): WorkflowGraph {
|
||||
branches.forEach(([name, branchSteps], column) => {
|
||||
const x = (column - (branches.length - 1) / 2) * COLUMN;
|
||||
let tail = previous;
|
||||
const entry = previous;
|
||||
(Array.isArray(branchSteps) ? branchSteps : []).forEach((branchStep, j) => {
|
||||
const id = addStep(branchStep, `${i + 1}-${name}-${j + 1}`, x, (row + j) * ROW, name, recorded, ["steps", i, "parallel", name, j]);
|
||||
link(tail, id);
|
||||
link(tail, id, tail === entry && column === branches.length - 1 ? i - 1 : undefined);
|
||||
tail = [id];
|
||||
depth = Math.max(depth, j + 1);
|
||||
});
|
||||
@@ -230,11 +260,20 @@ export function workflowGraph(source: string): WorkflowGraph {
|
||||
continue;
|
||||
}
|
||||
const id = addStep(step, String(i + 1), 0, row * ROW, undefined, undefined, ["steps", i]);
|
||||
link(previous, id);
|
||||
link(previous, id, i - 1);
|
||||
previous = [id];
|
||||
row++;
|
||||
}
|
||||
|
||||
// The end of the run, where a new last step is added.
|
||||
nodes.push({
|
||||
id: "add-end",
|
||||
type: "add",
|
||||
position: { x: 104, y: row * ROW - 24 },
|
||||
data: { kind: "step", key: "add", title: "", type: "", detail: "" },
|
||||
});
|
||||
link(previous, "add-end");
|
||||
|
||||
for (const { from, to } of pendingData) {
|
||||
const source = byStepID.get(from);
|
||||
if (!source) continue;
|
||||
|
||||
Reference in new issue
Block a user