chore(vendor): import pi 1.3.0
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
1 parent
719370c8f7
commit
6081e3e325
1743 files changed
+205459
-131704
No files matched your search
@@ -0,0 +1,21 @@
|
||||
// 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);
|
||||
Reference in new issue
Block a user