The dashboard talks only to the modules/chat API, which sends no slash commands, model list, voice support, attachments or any question other than an approval, so the UI built on those could never appear: - the slash command menu, Retry, Undo, Branch and Preview compression in the More menu, and the /model, /update and /new handling - the model picker, the update card and the api.update* calls - voice recording and the task tags nothing ever added - the questionnaire, picker and clarify cards, and the "Always this session" answer, so components/ui/questionnaire loses its last user - channel.ts, command-scroll.ts and turn.ts, which nothing imported - the old dock-storage migration and the second capitalised spelling of message and tool fields Tasks are gone from the binary too, so chat links and prompts speak of runs: the #N task-link step in the markdown renderer goes, since an agent already links pages through dashboard_navigate. state.ts keeps the shared state and actions; types.ts, stream.ts, transcript.ts, escape.ts and dock-window.ts hold the types, the stream reader, turn-to-message building, Escape layers and the dock's pointer and keyboard handling. ChatDock.vue drops from 560 lines to 307.
107 lines
4.5 KiB
TypeScript
107 lines
4.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { register } from "node:module";
|
|
import { pathToFileURL } from "node:url";
|
|
import { resolve as resolvePath } from "node:path";
|
|
|
|
// state.ts reads the dashboard through "@/lib/api" and "@/router", which node
|
|
// cannot resolve on its own (and which pull in the whole SPA). A resolve hook
|
|
// maps the alias into src/ for the pure modules and stubs the two browser-only
|
|
// ones, so the real frame handling in state.ts runs under node.
|
|
const srcRoot = resolvePath(import.meta.dirname, "../src");
|
|
const apiStub =
|
|
"data:text/javascript," +
|
|
encodeURIComponent(
|
|
"export const api = new Proxy({}, { get: (_, p) => globalThis.__archieChatTestApi[p] });" +
|
|
"export class ApiError extends Error { constructor(message, status) { super(message); this.status = status; } }" +
|
|
"export function describeError(err, fallback) { return err instanceof Error && err.message ? err.message : fallback; }",
|
|
);
|
|
const sessionStub =
|
|
"data:text/javascript," + encodeURIComponent("export function useSessionStore() { return { sections: null }; }");
|
|
const routerStub =
|
|
"data:text/javascript," +
|
|
encodeURIComponent(
|
|
"export const router = { currentRoute: { value: { fullPath: '/', name: 'home', meta: {}, params: {} } } };",
|
|
);
|
|
register(
|
|
"data:text/javascript," +
|
|
encodeURIComponent(`
|
|
const SRC = ${JSON.stringify(pathToFileURL(srcRoot + "/").href)};
|
|
export async function resolve(specifier, context, next) {
|
|
if (specifier === "@/lib/api") return { url: ${JSON.stringify(apiStub)}, shortCircuit: true };
|
|
if (specifier === "@/stores/session") return { url: ${JSON.stringify(sessionStub)}, shortCircuit: true };
|
|
if (specifier === "@/router") return { url: ${JSON.stringify(routerStub)}, shortCircuit: true };
|
|
if (specifier === "@/copy/errors") return { url: SRC + "copy/errors/index.ts", shortCircuit: true };
|
|
if (specifier.startsWith("@/")) return { url: SRC + specifier.slice(2) + ".ts", shortCircuit: true };
|
|
if ((specifier.startsWith("./") || specifier.startsWith("../")) && !/\\.[a-z0-9]+$/i.test(specifier)) {
|
|
return { url: new URL(specifier + ".ts", context.parentURL).href, shortCircuit: true };
|
|
}
|
|
return next(specifier, context);
|
|
}
|
|
`),
|
|
);
|
|
|
|
interface Frame {
|
|
type: string;
|
|
text?: string;
|
|
}
|
|
|
|
/** One SSE body: each frame as the server writes it, `data: {...}\n\n`. */
|
|
function sseBody(frames: Frame[]): ReadableStream<Uint8Array> {
|
|
const encoder = new TextEncoder();
|
|
const payload = frames.map((frame) => `data: ${JSON.stringify(frame)}\n\n`).join("");
|
|
return new ReadableStream({
|
|
start(controller) {
|
|
controller.enqueue(encoder.encode(payload));
|
|
controller.close();
|
|
},
|
|
});
|
|
}
|
|
|
|
// The stream stub: the turn's events answer with the given frames, sessions
|
|
// reads back an empty list so the finished turn does not trigger a reload.
|
|
function stubApi(frames: Frame[]): void {
|
|
(globalThis as Record<string, unknown>).__archieChatTestApi = {
|
|
chatCreateSession: () => ({ session_id: "s1", title: "" }),
|
|
chatSend: () => ({ id: "t1" }),
|
|
chatTurnEvents: () => ({ body: sseBody(frames) }),
|
|
chatSessions: () => ({ sessions: [] }),
|
|
};
|
|
}
|
|
|
|
const state = await import("../src/chat/state.ts");
|
|
|
|
test("reasoning frames accumulate on the live turn as its thinking", async () => {
|
|
stubApi([
|
|
{ type: "reasoning", text: "considering " },
|
|
{ type: "reasoning", text: "the request" },
|
|
{ type: "error", text: "provider exploded" },
|
|
]);
|
|
await state.sendMessage({ text: "hello" });
|
|
const turn = state.streamingTurn.value;
|
|
assert.ok(turn, "the failed turn stays on the panel");
|
|
assert.equal(turn.isError, true);
|
|
assert.equal(turn.reasoning, "considering the request");
|
|
});
|
|
|
|
test("reasoning never leaks into the reply text", async () => {
|
|
stubApi([
|
|
{ type: "reasoning", text: "secret chain of thought" },
|
|
{ type: "delta", text: "Hello" },
|
|
{ type: "done", text: "Hello" },
|
|
]);
|
|
await state.sendMessage({ text: "hi" });
|
|
assert.equal(state.streamingTurn.value, null);
|
|
const last = state.messages.value.at(-1);
|
|
assert.equal(last?.from, "assistant");
|
|
assert.equal(last?.text, "Hello");
|
|
});
|
|
|
|
test("a turn without reasoning frames completes normally", async () => {
|
|
stubApi([{ type: "delta", text: "Hi" }, { type: "done", text: "Hi" }]);
|
|
await state.sendMessage({ text: "hey" });
|
|
assert.equal(state.streamingTurn.value, null);
|
|
assert.equal(state.messages.value.at(-1)?.text, "Hi");
|
|
assert.equal(state.statusText.value, "Ready");
|
|
});
|