mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
Submissions with request-ID deduplication and handles, the pi.live run control and presentation document, the built-in pi.generation task (system prompt preparation, streamed durable partials, retries, deferred polling, abort), typed entry tokens, stream options and retry policy, TaskRuntime reads, Tx.settleSubmission, registry conversation setups, Storage.scanSubmissions, Harness.inspect, and byTaskId attribution. Waiting calls enable scheduling. The scratch tour is split into test/examples.
21 lines
1 KiB
TypeScript
21 lines
1 KiB
TypeScript
// A Session stores conversations, transcript entries, tasks, and documents.
|
|
// Run from packages/durable:
|
|
// node --conditions=source --experimental-strip-types test/examples/00-conversation.ts
|
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
import { createSession, MemoryStorage } from "../../src/index.ts";
|
|
|
|
// MemoryStorage keeps everything in memory; other storage backends keep it on disk.
|
|
const session = createSession(new MemoryStorage());
|
|
|
|
// Every Session call takes a context, which is used for cancellation.
|
|
// BACKGROUND_CONTEXT means "never cancel".
|
|
const context = BACKGROUND_CONTEXT;
|
|
|
|
// All writes happen inside session.commit(). The callback receives a
|
|
// transaction `tx`; everything it writes is saved together when the callback
|
|
// returns, or discarded if it throws.
|
|
// "ownerless" means no task created this conversation.
|
|
const standalone = await session.commit((tx) => tx.createConversation({ ownership: { kind: "ownerless" } }), context);
|
|
console.log("standalone conversation:", standalone);
|
|
|
|
await session.close(context);
|