feat(ui): Build with Archie runs on the chat system, floats over the canvas and keeps its conversation

Each workflow has its own persisted conversation, rendered like the chat panel.
The canvas and YAML go read-only while Archie works instead of inert. The code
block highlighter loads Go and TOML and drops jsx, tsx and vue.
This commit is contained in:
sam committed 2026-10-19 02:43:54 +11:00
1 parent ab2b50045f
commit 808551aeb0
21 files changed
+264 -252

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, watch } from "vue";
import { ChevronDown, ChevronUp, MessageCirclePlus, Sparkles } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { channelID, workflowChannel } from "@/chat/channel";
import ChatComposer from "@/chat/ChatComposer.vue";
import ChatSessionList from "@/chat/ChatSessionList.vue";
import ChatTranscript from "@/chat/ChatTranscript.vue";
import { bindChannel, isSending, messages, newChat, setTurnHooks, streamingTurn } from "@/chat/state";
/**
* Archie edits the workflow with the operator, on the same conversation system
* as the chat panel. Each workflow has its own conversation, so it opens on that
* workflow's history rather than on whatever the operator last asked the panel.
* Archie writes the draft; the operator keeps or reverts each change in the
* draft review and publishes.
*/
const props = defineProps<{ workflow: string; beforeSend: () => Promise<void> }>();
const emit = defineEmits<{ proposed: []; working: [boolean] }>();
const expanded = ref(false);
const hasConversation = computed(() => messages.value.length > 0 || !!streamingTurn.value);
watch(
() => props.workflow,
(workflow) => bindChannel(workflowChannel(workflow)),
{ immediate: true },
);
// Archie works from the saved draft, so pending edits are written first; it may
// have written the draft even on a turn that failed later, so it is read after
// every turn.
setTurnHooks({ before: () => props.beforeSend(), after: () => emit("proposed") });
watch(isSending, (value) => {
emit("working", value);
if (value) expanded.value = true;
});
onBeforeUnmount(() => {
setTurnHooks({});
bindChannel(channelID());
});
</script>
<template>
<div class="pointer-events-auto flex w-full max-w-xl flex-col overflow-hidden rounded-lg border border-border bg-popover shadow-[var(--shadow-md)]">
<div v-if="hasConversation" class="flex items-center gap-1 border-b px-3 py-2">
<Sparkles class="size-4 shrink-0 text-primary" aria-hidden="true" />
<ChatSessionList />
<Button variant="ghost" size="icon-sm" class="flex-none" title="New chat" aria-label="New chat" @click="newChat">
<MessageCirclePlus />
</Button>
<Button
variant="ghost"
size="icon-sm"
class="flex-none"
:aria-label="expanded ? 'Hide conversation' : 'Show conversation'"
:title="expanded ? 'Hide conversation' : 'Show conversation'"
:aria-expanded="expanded"
@click="expanded = !expanded"
>
<ChevronDown v-if="expanded" />
<ChevronUp v-else />
</Button>
</div>
<div v-if="hasConversation && expanded" class="flex h-[min(20rem,40vh)] min-h-0 flex-col">
<ChatTranscript />
</div>
<ChatComposer :open="false" placeholder="Build with Archie" :class="!hasConversation && 'border-t-0!'" />
</div>
</template>
-115
View File
@@ -1,115 +0,0 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { ArrowUp, Sparkles, Square } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Spinner } from "@/components/ui/spinner";
import { api } from "@/lib/api";
import { randomUUID } from "@/lib/uuid";
import { channelID } from "@/chat/channel";
/**
* Archie edits the workflow with the operator. Each request is a chat turn in
* a conversation of its own per workflow, so "not that one, try again" has the
* earlier turns as context. Archie writes the draft; the operator keeps or
* reverts each change in the draft review and publishes.
*/
const props = defineProps<{ workflow: string; beforeSend: () => Promise<void> }>();
const emit = defineEmits<{ proposed: []; working: [boolean] }>();
const text = ref("");
const reply = ref("");
const activity = ref("");
const failed = ref(false);
const busy = ref(false);
let controller: AbortController | undefined;
watch(busy, (value) => emit("working", value));
interface Frame { type?: string; text?: string; tool?: string }
async function send(): Promise<void> {
const request = text.value.trim();
if (!request || busy.value) return;
busy.value = true;
failed.value = false;
reply.value = "";
activity.value = "";
text.value = "";
controller = new AbortController();
try {
await props.beforeSend();
const response = await api.chatStream(
{
channel_id: `${channelID()}:workflow:${props.workflow}`,
source_id: randomUUID(),
text: `[Editing workflow "${props.workflow}"; write changes with workflow_draft] ${request}`,
page: location.pathname + location.search,
},
{ signal: controller.signal },
);
if (!response.body) throw new Error("no response body");
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
let finished = false;
// Read to the end: a turn that stops without a done frame failed.
for (;;) {
const { value, done } = await reader.read();
buffer += decoder.decode(value || new Uint8Array(), { stream: !done });
const frames = buffer.split("\n\n");
buffer = frames.pop() || "";
for (const frame of frames) {
const line = frame.split("\n").find((part) => part.startsWith("data: "));
if (!line) continue;
const event = JSON.parse(line.slice(6)) as Frame;
if (event.type === "delta") reply.value += event.text ?? "";
if (event.type === "tool" && event.tool) activity.value = event.tool.replaceAll("_", " ");
if (event.type === "done") {
finished = true;
if (!reply.value) reply.value = event.text ?? "";
}
if (event.type === "error") throw new Error(event.text);
}
if (done) break;
}
if (!finished) throw new Error("the turn ended early");
} catch (error) {
if ((error as Error).name !== "AbortError") {
failed.value = true;
reply.value = String((error as Error).message || error);
}
} finally {
busy.value = false;
activity.value = "";
controller = undefined;
// Archie may have written the draft even on a turn that failed later.
emit("proposed");
}
}
</script>
<template>
<div class="pointer-events-auto w-full max-w-xl rounded-lg border border-border bg-popover shadow-[var(--shadow-md)]">
<p
v-if="reply"
class="max-h-40 overflow-y-auto whitespace-pre-wrap border-b border-border px-3 py-2 text-sm"
:class="failed && 'text-danger'"
:role="failed ? 'alert' : 'status'"
>{{ reply }}</p>
<form class="flex items-center gap-2 px-3 py-2" @submit.prevent="send">
<Sparkles class="size-4 shrink-0 text-primary" aria-hidden="true" />
<input
v-model="text"
class="min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-fg-subtle"
placeholder="Build with Archie"
aria-label="Build with Archie"
:disabled="busy"
/>
<span v-if="busy" class="flex shrink-0 items-center gap-1.5 text-xs text-fg-subtle">
<Spinner />{{ activity }}
</span>
<Button v-if="busy" type="button" variant="ghost" size="icon-sm" aria-label="Stop" @click="controller?.abort()"><Square /></Button>
<Button v-else type="submit" size="icon-sm" aria-label="Send" :disabled="!text.trim()"><ArrowUp /></Button>
</form>
</div>
</template>
+8 -11
View File
@@ -39,7 +39,7 @@ import { useWorkflowHistory } from "./workflow-history";
import { revisionOfRun, type WorkflowRevision } from "./workflow-revisions";
import { deleteStep, duplicateStep, insertStep, moveStep, normalizeStepIDs, replaceStep, revertWorkflowChange, stepAt, workflowChanges, workflowField, type StepPath } from "./workflow-edit";
import ChangeList from "@/components/ChangeList.vue";
import CoBuilder from "./CoBuilder.vue";
import ArchieBuilder from "./ArchieBuilder.vue";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { useWorkflowRuns } from "./workflow-runs";
import { useWorkflowTriggers } from "./workflow-triggers";
@@ -225,7 +225,7 @@ async function dropDraft(target: string): Promise<void> {
await workflows.putDraft(target, undefined);
}
// Edits made while Archie works would be overwritten by its draft, so the
// editor is locked until the turn ends.
// canvas and YAML go read-only until the turn ends; viewing stays open.
const archieWorking = ref(false);
// Archie works from the saved draft, so pending edits are written first.
async function flushDraft(): Promise<void> {
@@ -444,13 +444,12 @@ function syncScroll(event: Event): void {
<p v-if="restartError" role="alert" class="absolute bottom-16 left-14 z-10 max-w-xl rounded-md border border-danger/40 bg-card px-3 py-2 text-sm text-danger shadow-lg">{{ restartError }}</p>
<WorkflowCanvas
class="h-auto min-h-0 flex-1"
:inert="archieWorking"
:yaml="canvasYaml"
:stages="drawnStages"
:open="open"
:triggers="triggers"
:types="stepTypeNames"
:readonly="!!pinnedYaml"
:readonly="!!pinnedYaml || archieWorking"
:restartable="restartable"
:problems="pinnedYaml ? undefined : nodeProblems"
:title="parsed.ok ? parsed.id : id"
@@ -474,7 +473,7 @@ function syncScroll(event: Event): void {
<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>
<fieldset v-else :disabled="!!pinnedYaml" class="min-w-0">
<fieldset v-else :disabled="!!pinnedYaml || archieWorking" class="min-w-0">
<StepEditor
:key="open ?? ''"
:yaml="canvasYaml"
@@ -488,12 +487,9 @@ function syncScroll(event: Event): void {
</template>
</template>
</WorkflowCanvas>
<!-- Below the canvas rather than over it: nodes run to the bottom edge,
so a floating bar hid the last step. -->
<div class="flex shrink-0 justify-center px-3 pt-2">
<CoBuilder
<div class="pointer-events-none absolute inset-x-0 bottom-14 z-10 flex justify-center px-3">
<ArchieBuilder
v-if="selected"
:key="selected"
:workflow="selected"
:before-send="flushDraft"
@proposed="takeProposal"
@@ -507,7 +503,7 @@ function syncScroll(event: Event): void {
</TabsContent>
<TabsContent value="performance" class="grid gap-4 max-md:min-h-0 max-md:overflow-y-auto"><slot name="performance" /></TabsContent>
<TabsContent value="runs" class="max-md:min-h-0 max-md:overflow-y-auto"><slot name="runs" /></TabsContent>
<TabsContent value="yaml" :inert="archieWorking" class="max-md:min-h-0 max-md:overflow-y-auto">
<TabsContent value="yaml" class="max-md:min-h-0 max-md:overflow-y-auto">
<!--
A gutter and a highlighted layer behind the live textarea, so the YAML
is numbered and coloured where it is edited rather than in a second,
@@ -554,6 +550,7 @@ function syncScroll(event: Event): void {
v-model="yaml"
name="workflow-yaml"
required
:readonly="archieWorking"
class="relative min-h-96 resize-y max-md:h-full max-md:min-h-0 max-md:resize-none rounded-none border-0 bg-transparent py-3 pr-3 pl-14 text-[13px] leading-6 text-transparent caret-foreground shadow-none md:text-[13px] focus-visible:ring-0"
spellcheck="false"
wrap="off"