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:
1 parent
ab2b50045f
commit
808551aeb0
21 files changed
+264
-252
No files matched your search
@@ -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"
|
||||
|
||||
@@ -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
@@ -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?.();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user