mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
Session workers now host a durable Harness over a per-session sqlite storage. The server keeps each session in <sessionDir>/<id>/ with meta.json and session.sqlite and never opens the storage itself. Workers hold retirement while the Harness task graph has live tasks and resume interrupted work on open. Transcript serves the root conversation's durable view directly, Models follows the conversation's agent document, and AgentController maps prompt, steer, follow-up, queue cancellation, abort, and compaction onto the root conversation, plus waitForPrompt. navigate, nextRun, and resume are dropped (see experimental/services/README.md TODO). The durable TUI and the worker share harness-setup.ts. pi-server exports its own SessionMetadata and no longer depends on pi-agent-core. Chord accepts readonly JSON types in service contracts without walking them, which recursive JSON types like pi-ai's made too deep.
34 lines
1.5 KiB
TypeScript
34 lines
1.5 KiB
TypeScript
import { createFacetHost, defineFacet } from "@earendil-works/chord";
|
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
import { fauxAssistantMessage } from "@earendil-works/pi-ai";
|
|
import type { ConversationView } from "@earendil-works/pi-durable";
|
|
import { describe, expect, test } from "vitest";
|
|
import { Transcript } from "../src/experimental/services/transcript.ts";
|
|
import { createTranscriptServiceFacet } from "../src/experimental/services/transcript-provider.ts";
|
|
import { openFauxConversation } from "./experimental-durable-support.ts";
|
|
|
|
describe("Transcript service", () => {
|
|
test("replicates the conversation view as it changes", async () => {
|
|
const { conversation, close } = await openFauxConversation([fauxAssistantMessage("answer")]);
|
|
const views: ConversationView[] = [];
|
|
const consumer = defineFacet({
|
|
id: "test-transcript-consumer",
|
|
setup(env) {
|
|
const transcript = env.use(Transcript);
|
|
env.onActivate(() => env.own(transcript.state.subscribe((value) => void views.push(value))));
|
|
},
|
|
});
|
|
const host = await createFacetHost({
|
|
facets: [await createTranscriptServiceFacet(conversation, BACKGROUND_CONTEXT), consumer],
|
|
});
|
|
try {
|
|
expect(views[0]?.entries).toEqual([]);
|
|
const submission = await conversation.submit({ type: "input", content: "question" }, BACKGROUND_CONTEXT);
|
|
await submission.wait(BACKGROUND_CONTEXT);
|
|
await expect.poll(() => views.at(-1)?.entries.map((entry) => entry.kind)).toEqual(["pi.user", "pi.assistant"]);
|
|
} finally {
|
|
await host.dispose();
|
|
await close();
|
|
}
|
|
});
|
|
});
|