feat(ui): one chat panel on every page; the workflow editor syncs its draft around a turn

Replaces the separate Build with Archie bar and its per-workflow channel, so
every conversation belongs to the account and is listed on every device, and
the command palette is the same everywhere.
This commit is contained in:
sam committed 2026-10-19 02:56:23 +11:00
1 parent e98f68ecba
commit 99f4eacc2b
9 files changed
+121 -270

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 = withDefaults(defineProps<{ open: boolean; placeholder?: string }>(), { placeholder: "Message Archie" });
const props = defineProps<{ open: boolean }>();
// 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="placeholder"
placeholder="Message Archie"
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"
-5
View File
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { onUnmounted, ref, watch } from "vue";
import { useRoute } from "vue-router";
import ChatFab from "./ChatFab.vue";
import ChatPanel from "./ChatPanel.vue";
@@ -22,9 +21,6 @@ import { escapeOwnedByLayer } from "./state";
* makes it a containing block for `position: fixed`, so a launcher nested
* inside it would anchor to the shell and ride off the bottom of a long page.
*/
// The workflow page has its own Archie bar under the canvas; a second entry
// point there would duplicate it and cover the canvas.
const route = useRoute();
const open = ref(false);
const fab = ref<{ $el: HTMLButtonElement } | null>(null);
@@ -63,7 +59,6 @@ onUnmounted(() => document.removeEventListener("keydown", onKeydown));
<template>
<div
v-if="route.name !== 'workflows'"
class="fixed right-6 bottom-6 z-40 max-md:right-4 max-md:bottom-4"
>
<ChatPanel :open="open" />
-17
View File
@@ -1,5 +1,3 @@
import { ref } from "vue";
import { randomUUID } from "@/lib/uuid";
const CHANNEL_KEY = "archie.web.chat.channel";
@@ -17,18 +15,3 @@ 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());
-10
View File
@@ -12,16 +12,6 @@ const ANY_TOKEN = /(?:^|\s)\/[^\s]*$/;
/** How many matches the palette will show at once. */
const MAX_MATCHES = 8;
/** The commands a workflow editor's conversation offers: those about the conversation itself. */
const WORKFLOW_COMMANDS = new Set([
"/model", "/new", "/reset", "/retry", "/undo", "/title", "/branch", "/fork",
"/compress", "/compact", "/sessions", "/resume", "/delete",
]);
export function commandsFor<T extends { command: string }>(specs: T[], workflowEditor: boolean): T[] {
return workflowEditor ? specs.filter((spec) => WORKFLOW_COMMANDS.has(spec.command)) : specs;
}
/**
* matchesFor returns the commands worth offering for the text before the
* caret, matched on the command and its description together so a word from
+13 -53
View File
@@ -1,8 +1,8 @@
import { computed, onMounted, onUnmounted, ref, watch, type Ref } from "vue";
import { api } from "@/lib/api";
import { activeChannel, isWorkflowChannel } from "./channel";
import { commandsFor, matchesFor } from "./commands";
import { channelID } from "./channel";
import { matchesFor } from "./commands";
import {
resolveTurn,
retryChatTurn,
@@ -24,7 +24,6 @@ export interface ChatSession {
session_id: string;
title?: string;
branch_name?: string;
source?: { channel_id?: string };
}
/** One slash command the server will accept. */
@@ -225,18 +224,10 @@ function abortActiveTurn(): void {
}
export async function refreshSessions(): Promise<void> {
const channel = activeChannel.value;
const data = await api.chatSessions<
ChatSelectorData & { sessions?: ChatSession[] }
>();
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),
);
const sessionList = data.sessions || [];
sessions.value = sessionList;
selectorData.value = data;
@@ -244,13 +235,10 @@ export async function refreshSessions(): Promise<void> {
selectedProvider.value = data.active_provider || providers[0] || "";
selectedModel.value = data.active_model || "";
commandSpecs.value = commandsFor(
(data.commands || []).map((item) =>
typeof item === "string"
? { command: item, usage: item, description: "" }
: item,
),
isWorkflowChannel(channel),
commandSpecs.value = (data.commands || []).map((item) =>
typeof item === "string"
? { command: item, usage: item, description: "" }
: item,
);
if (!currentSession.value && sessionList[0]) {
@@ -262,7 +250,6 @@ 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;
@@ -271,12 +258,11 @@ 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(activeChannel.value, `/resume ${id}`);
await api.chatMessage(channelID(), `/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;
@@ -312,7 +298,7 @@ export async function runSessionCommand(command: string): Promise<void> {
const result = await api.chatMessage<{
session_id?: string;
reply?: string;
}>(activeChannel.value, command);
}>(channelID(), command);
if (result.session_id) currentSession.value = result.session_id;
statusText.value = result.reply || "Session updated";
await refreshSessions();
@@ -337,7 +323,7 @@ export async function setProvider(provider: string): Promise<void> {
if (!provider) return;
try {
const result = await api.chatMessage<{ reply?: string }>(
activeChannel.value,
channelID(),
`/model --provider ${provider}`,
);
statusText.value = result.reply || "Provider updated";
@@ -352,7 +338,7 @@ export async function setModel(model: string): Promise<void> {
if (!model) return;
try {
const result = await api.chatMessage<{ reply?: string }>(
activeChannel.value,
channelID(),
`/model ${model}`,
);
statusText.value = result.reply || "Model updated";
@@ -362,27 +348,7 @@ 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. */
/** What a page that edits something Archie can change runs around a turn: save first, reload after. */
let turnHooks: { before?: () => Promise<void>; after?: () => void } = {};
export function setTurnHooks(hooks: typeof turnHooks): void {
turnHooks = hooks;
@@ -428,10 +394,6 @@ 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…";
@@ -493,7 +455,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
const response = await api.chatStream(
{
channel_id: channel,
channel_id: channelID(),
source_id: turn.sourceID,
text: turn.text,
page: currentPage(),
@@ -555,7 +517,6 @@ 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,
@@ -565,7 +526,6 @@ 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 = {
-70
View File
@@ -1,70 +0,0 @@
<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 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>
+5 -12
View File
@@ -8,8 +8,9 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { computed, onBeforeUnmount, ref, watch } from "vue";
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { CircleAlert, Ellipsis, RotateCcw, Trash2 } from "@lucide/vue";
import { isSending, setTurnHooks } from "@/chat/state";
import { Button } from "@/components/ui/button";
import {
@@ -39,7 +40,6 @@ 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 ArchieBuilder from "./ArchieBuilder.vue";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { useWorkflowRuns } from "./workflow-runs";
import { useWorkflowTriggers } from "./workflow-triggers";
@@ -215,7 +215,9 @@ watch(yaml, (value) => {
void persistDraft(edit.target, edit.value);
}, 800);
});
onMounted(() => setTurnHooks({ before: flushDraft, after: () => void takeProposal() }));
onBeforeUnmount(() => {
setTurnHooks({});
clearTimeout(pending);
void persistDraft(selected.value, yaml.value);
});
@@ -226,7 +228,7 @@ async function dropDraft(target: string): Promise<void> {
}
// Edits made while Archie works would be overwritten by its draft, so the
// canvas and YAML go read-only until the turn ends; viewing stays open.
const archieWorking = ref(false);
const archieWorking = isSending;
// Archie works from the saved draft, so pending edits are written first.
async function flushDraft(): Promise<void> {
clearTimeout(pending);
@@ -487,15 +489,6 @@ function syncScroll(event: Event): void {
</template>
</template>
</WorkflowCanvas>
<div class="pointer-events-none absolute inset-x-0 bottom-14 z-10 flex justify-center px-3">
<ArchieBuilder
v-if="selected"
:workflow="selected"
:before-send="flushDraft"
@proposed="takeProposal"
@working="(value) => (archieWorking = value)"
/>
</div>
</div>
</TabsContent>
<TabsContent value="history" class="max-md:min-h-0 max-md:overflow-y-auto">