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

+2 -2
View File
@@ -36,7 +36,7 @@ import {
* and stops at `max-h-40`, so a long draft scrolls rather than eating the
* transcript above it.
*/
const props = defineProps<{ open: boolean }>();
const props = withDefaults(defineProps<{ open: boolean; placeholder?: string }>(), { placeholder: "Message Archie" });
// Voice: recorded in the browser, transcribed by the server like a Telegram
// voice note. The mic shows only while the composer is empty.
@@ -168,7 +168,7 @@ function onKeydown(event: KeyboardEvent): void {
ref="field"
:model-value="composerText"
rows="1"
placeholder="Message Archie"
:placeholder="placeholder"
aria-label="Message Archie"
class="max-h-40 min-h-11 flex-1 resize-none border-0 bg-transparent! px-0 py-1 text-sm focus-visible:ring-0"
@input="onInput"
+17
View File
@@ -1,3 +1,5 @@
import { ref } from "vue";
import { randomUUID } from "@/lib/uuid";
const CHANNEL_KEY = "archie.web.chat.channel";
@@ -15,3 +17,18 @@ export function channelID(): string {
}
return id;
}
const WORKFLOW_MARK = ":workflow:";
/** The channel a workflow editor's conversations live on: one per workflow. */
export function workflowChannel(workflow: string): string {
return `${channelID()}${WORKFLOW_MARK}${workflow}`;
}
/** Whether a conversation belongs to some workflow editor rather than the chat panel. */
export function isWorkflowChannel(channel: string | undefined): boolean {
return !!channel?.includes(WORKFLOW_MARK);
}
/** The channel the chat state is talking on: the browser's own, or a workflow editor's. */
export const activeChannel = ref(channelID());
+52 -7
View File
@@ -1,7 +1,7 @@
import { computed, onMounted, onUnmounted, ref, watch, type Ref } from "vue";
import { api } from "@/lib/api";
import { channelID } from "./channel";
import { activeChannel, isWorkflowChannel } from "./channel";
import { matchesFor } from "./commands";
import {
resolveTurn,
@@ -24,6 +24,7 @@ export interface ChatSession {
session_id: string;
title?: string;
branch_name?: string;
source?: { channel_id?: string };
}
/** One slash command the server will accept. */
@@ -224,10 +225,18 @@ function abortActiveTurn(): void {
}
export async function refreshSessions(): Promise<void> {
const channel = activeChannel.value;
const data = await api.chatSessions<
ChatSelectorData & { sessions?: ChatSession[] }
>();
const sessionList = data.sessions || [];
if (channel !== activeChannel.value) return;
// A workflow editor's conversations stay on its own channel: the panel does
// not list them, and the editor lists only its own.
const sessionList = (data.sessions || []).filter((session) =>
isWorkflowChannel(channel)
? session.source?.channel_id === channel
: !isWorkflowChannel(session.source?.channel_id),
);
sessions.value = sessionList;
selectorData.value = data;
@@ -250,6 +259,7 @@ export async function refreshSessions(): Promise<void> {
export async function selectSession(id: string): Promise<void> {
if (!id) return;
const channel = activeChannel.value;
currentSession.value = id;
messages.value = [];
streamingTurn.value = null;
@@ -258,11 +268,12 @@ export async function selectSession(id: string): Promise<void> {
try {
// Resuming is the server's own command, so the transcript read below is of
// a conversation the server considers current rather than a stale one.
await api.chatMessage(channelID(), `/resume ${id}`);
await api.chatMessage(activeChannel.value, `/resume ${id}`);
const [msgs, turns] = await Promise.all([
api.chatMessages<ChatMessage[]>(id),
api.chatTurns<ChatTurnView[]>(id),
]);
if (channel !== activeChannel.value) return;
const byAssistantMessage = new Map<string, ChatTurnView>();
for (const turn of turns || []) {
const assistantID = turn.assistant_message_id || turn.AssistantMessageID;
@@ -298,7 +309,7 @@ export async function runSessionCommand(command: string): Promise<void> {
const result = await api.chatMessage<{
session_id?: string;
reply?: string;
}>(channelID(), command);
}>(activeChannel.value, command);
if (result.session_id) currentSession.value = result.session_id;
statusText.value = result.reply || "Session updated";
await refreshSessions();
@@ -323,7 +334,7 @@ export async function setProvider(provider: string): Promise<void> {
if (!provider) return;
try {
const result = await api.chatMessage<{ reply?: string }>(
channelID(),
activeChannel.value,
`/model --provider ${provider}`,
);
statusText.value = result.reply || "Provider updated";
@@ -338,7 +349,7 @@ export async function setModel(model: string): Promise<void> {
if (!model) return;
try {
const result = await api.chatMessage<{ reply?: string }>(
channelID(),
activeChannel.value,
`/model ${model}`,
);
statusText.value = result.reply || "Model updated";
@@ -348,6 +359,32 @@ export async function setModel(model: string): Promise<void> {
}
}
/**
* Points the panel's state at another channel: a workflow editor's, or back to
* the browser's own. The conversation shown is that channel's, so the editor
* starts from its own conversation rather than the one the panel last used.
*/
export function bindChannel(id: string): void {
if (activeChannel.value === id) return;
abortActiveTurn();
activeChannel.value = id;
sessions.value = [];
currentSession.value = "";
messages.value = [];
streamingTurn.value = null;
composerText.value = "";
statusText.value = "Ready";
refreshSessions().catch((err: Error) => {
statusText.value = err.message || "Chat unavailable";
});
}
/** What a workflow editor runs around a turn: save its draft first, load Archie's after. */
let turnHooks: { before?: () => Promise<void>; after?: () => void } = {};
export function setTurnHooks(hooks: typeof turnHooks): void {
turnHooks = hooks;
}
export function newChat(): void {
composerText.value = "/new";
void sendMessage({ textOverride: "/new" });
@@ -388,6 +425,10 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
const { text, turn, isRetry } = resolveTurn(retryOpts, rawValue);
if (!text || isSending.value) return;
const channel = activeChannel.value;
// The channel can be rebound under a turn in flight; what it answers then
// belongs to a conversation that is no longer on screen.
const stale = () => channel !== activeChannel.value;
closeCommandMenu();
isSending.value = true;
statusText.value = isRetry ? "Retrying…" : "Thinking…";
@@ -445,10 +486,11 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
arm();
// The clock stops while a question waits on the operator.
rearmTimeout = arm;
await turnHooks.before?.();
const response = await api.chatStream(
{
channel_id: channelID(),
channel_id: channel,
source_id: turn.sourceID,
text: turn.text,
page: currentPage(),
@@ -510,6 +552,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
}
if (!finished) throw new Error("chat stream ended before completion");
if (stale()) return;
messages.value = [
...messages.value,
@@ -519,6 +562,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
statusText.value = "Ready";
await refreshSessions();
} catch (err) {
if (stale()) return;
const failed = err as Error;
if (failed.name === "AbortError" && !timedOut) {
streamingTurn.value = {
@@ -544,6 +588,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
rearmTimeout = null;
activeController = null;
isSending.value = false;
turnHooks.after?.();
}
}
@@ -12,16 +12,15 @@ const languages = {
bash: () => import('shiki/langs/shellscript.mjs'),
css: () => import('shiki/langs/css.mjs'),
diff: () => import('shiki/langs/diff.mjs'),
go: () => import('shiki/langs/go.mjs'),
html: () => import('shiki/langs/html.mjs'),
javascript: () => import('shiki/langs/javascript.mjs'),
json: () => import('shiki/langs/json.mjs'),
jsx: () => import('shiki/langs/jsx.mjs'),
markdown: () => import('shiki/langs/markdown.mjs'),
python: () => import('shiki/langs/python.mjs'),
sql: () => import('shiki/langs/sql.mjs'),
tsx: () => import('shiki/langs/tsx.mjs'),
toml: () => import('shiki/langs/toml.mjs'),
typescript: () => import('shiki/langs/typescript.mjs'),
vue: () => import('shiki/langs/vue.mjs'),
yaml: () => import('shiki/langs/yaml.mjs'),
}
+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"