mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
docs(durable): renumber examples
This commit is contained in:
parent
92ab536024
commit
b9fb2b854b
29 changed files with 55 additions and 55 deletions
|
|
@ -13,7 +13,7 @@ const session = createSession(new MemoryStorage());
|
|||
// all of them exist or none do.
|
||||
|
||||
// A task definition needs a name, a version, the task's starting state, a
|
||||
// handler for every phase, and an abort handler (12-tasks.ts runs a task).
|
||||
// handler for every phase, and an abort handler (11-tasks.ts runs a task).
|
||||
// This example only creates the task record; a plain Session never runs it.
|
||||
const Supervisor = defineTask<null, { phase: "ready" }, null>({
|
||||
name: "example.supervisor",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Serialize asynchronous document work with a watch.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/05-watches.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/04-watches.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { createSession, defineDoc, MemoryStorage } from "../../src/index.ts";
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Open a Harness with a registry of extensions.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/06-harness.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/05-harness.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { Type } from "@earendil-works/pi-ai";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Per-conversation agent choices and Harness-wide settings.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/07-configuration.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/06-configuration.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { Type } from "@earendil-works/pi-ai";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Conversation handles, typed entries, created conversations, and forks.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/08-harness-conversations.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/07-harness-conversations.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
import { createRegistry, defineEntry, Harness, MemoryStorage } from "../../src/index.ts";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Transcript history and model context.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/09-context.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/08-context.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import type { AssistantMessage, Message, StopReason, ToolResultMessage } from "@earendil-works/pi-ai";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Reload extension code through the registry.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/10-registry-reload.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/09-registry-reload.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { Type } from "@earendil-works/pi-ai";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// An extension that keeps its own per-conversation document.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/11-extension-state.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/10-extension-state.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { Type } from "@earendil-works/pi-ai";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Run a durable task.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/12-tasks.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/11-tasks.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
import { createRegistry, defineExtension, defineTask, Harness, MemoryStorage } from "../../src/index.ts";
|
||||
|
|
@ -52,7 +52,7 @@ registry.install(defineExtension({ name: "payments", tasks: [Payment] }));
|
|||
const harness = await Harness.open(new MemoryStorage(), { models: createModels(), registry }, context);
|
||||
const root = await harness.root(context);
|
||||
// Every task names its owner. This one belongs to the conversation; a task can
|
||||
// also own child tasks and wait for them (24-child-tasks.ts).
|
||||
// also own child tasks and wait for them (23-child-tasks.ts).
|
||||
const paymentId = await root.commit(
|
||||
(tx) => tx.createTask(Payment, { amount: 5 }, { ownership: { kind: "conversation" } }),
|
||||
context,
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Close, reopen, and continue where a task stopped.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/13-recovery.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/12-recovery.ts
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// A chat turn.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/14-chat.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/13-chat.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
import { fauxAssistantMessage, fauxProvider } from "@earendil-works/pi-ai/providers/faux";
|
||||
|
|
@ -8,7 +8,7 @@ import { AssistantEntry, createRegistry, defineExtension, Harness, MemoryStorage
|
|||
|
||||
const context = BACKGROUND_CONTEXT;
|
||||
|
||||
// The faux provider stands in for a real model (see 16-real-model.ts).
|
||||
// The faux provider stands in for a real model (see 15-real-model.ts).
|
||||
const faux = fauxProvider();
|
||||
const models = createModels();
|
||||
models.setProvider(faux.provider);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// System prompt sections and per-conversation instructions.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/15-system-prompt.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/14-system-prompt.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
import { fauxAssistantMessage, fauxProvider } from "@earendil-works/pi-ai/providers/faux";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// A real model: stream an answer from OpenAI.
|
||||
// Run from packages/durable (needs OPENAI_API_KEY):
|
||||
// node --conditions=source --experimental-strip-types test/examples/16-real-model.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/15-real-model.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
import { openaiProvider } from "@earendil-works/pi-ai/providers/openai";
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// `cat` of /tmp/1gb.txt (create it first to measure; without it that call ends in an error result). The storage
|
||||
// directory is left behind for inspection.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/17-coding-tools.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/16-coding-tools.ts
|
||||
import { mkdtemp, readFile, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Print mode: submit one prompt and print its answer, like `pi -p`. The host awaits its own Submission, not global
|
||||
// idle. Uses OpenAI when OPENAI_API_KEY is set, and a scripted faux model otherwise.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/18-print.ts "What is in this directory?"
|
||||
// node --conditions=source --experimental-strip-types test/examples/17-print.ts "What is in this directory?"
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
// neither is deleted, and the path is printed to stderr at the end.
|
||||
// Uses OpenAI when OPENAI_API_KEY is set, and a scripted faux model otherwise.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/19-json.ts --events "What is in this directory?"
|
||||
// node --conditions=source --experimental-strip-types test/examples/18-json.ts --events "What is in this directory?"
|
||||
import { mkdtemp } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// The inbox: what happens to submissions while a conversation is busy.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/20-inbox.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/19-inbox.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import type { FauxResponseStep } from "@earendil-works/pi-ai";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Late join: a client attaches while a run is already underway. It gets the current state first, the conversation
|
||||
// view or the snapshot event, and then only what changes after that.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/21-late-join.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/20-late-join.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { Type } from "@earendil-works/pi-ai";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
// details and shows its events under the call.
|
||||
// Uses OpenAI when OPENAI_API_KEY is set, and a scripted faux model otherwise.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/22-subagent-foreground.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/21-subagent-foreground.ts
|
||||
import type { Context } from "@earendil-works/chord";
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { type AssistantMessage, type FauxResponseStep, Type } from "@earendil-works/pi-ai";
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
// survives a restart: the example closes the Harness while a subagent works and reopens it.
|
||||
// Uses OpenAI when OPENAI_API_KEY is set, and a scripted faux model otherwise.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/23-subagent-background.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/22-subagent-background.ts
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// A task that owns child tasks: a checkout charges four payments at once and waits for them.
|
||||
// The task graph view prints the checkout's tree while its payments run.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/24-child-tasks.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/23-child-tasks.ts
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Compaction: a long trip-planning chat whose older messages are summarized so the model context stays small.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/25-compaction.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/24-compaction.ts
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import type { AssistantMessage, Message, TranscriptContext } from "@earendil-works/pi-ai";
|
||||
import { createModels } from "@earendil-works/pi-ai/models";
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// A small coding agent: the built-in coding tools, a prompt that knows the working directory, settings backed by the
|
||||
// app's settings file, and an environment that follows the conversation's directory.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/26-coding-agent.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/25-coding-agent.ts
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Plan mode: the user switches a conversation into a read-only planning mode, the agent writes a plan into the
|
||||
// extension's own document, and switching back restores the full tool set.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/27-plan-mode.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/26-plan-mode.ts
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// A reviewer agent next to the main one: a cheaper model, a review role and loop, read-only tools, and its own
|
||||
// checkout of the project.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/28-reviewer.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/27-reviewer.ts
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// environment function looks it up for every tool call. Here a sandbox is a directory; a hosted product would return
|
||||
// an ExecutionEnv that runs inside the conversation's container.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/29-sandbox-per-conversation.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/28-sandbox-per-conversation.ts
|
||||
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Replace a tool for some conversations, and decorate whichever tool wins: a bash that runs inside a Python
|
||||
// virtualenv, and a wrapper that times every bash call.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/30-tool-override.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/29-tool-override.ts
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// Reload an extension while a call runs, then restart the process. Running work finishes on the code it started
|
||||
// with; stored choices are names, so they survive a restart and bind to whatever code the new process installs.
|
||||
// Run from packages/durable:
|
||||
// node --conditions=source --experimental-strip-types test/examples/31-reload-and-restart.ts
|
||||
// node --conditions=source --experimental-strip-types test/examples/30-reload-and-restart.ts
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
Loading…
Add table
Add a link
Reference in a new issue