agents 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{agent-routing-vVMA7m8Y.d.ts → agent-routing-BSoZzNiP.d.ts} +537 -373
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-gGXXkf1z.d.ts → agent-tools-Be-hpRpH.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/{ai-sdk-Kon40i0q.js → ai-sdk-CRMlEBX7.js} +75 -44
- package/dist/ai-sdk-CRMlEBX7.js.map +1 -0
- package/dist/browser/ai.js +1 -1
- package/dist/browser/index.d.ts +7 -3
- package/dist/browser/index.js +2 -2
- package/dist/browser/tools/ai-sdk.d.ts +68 -3
- package/dist/browser/tools/pi.d.ts +2 -2
- package/dist/browser/tools/tanstack-ai.d.ts +2 -2
- package/dist/{browser-CI97khiJ.d.ts → browser-C9T74n4c.d.ts} +84 -5
- package/dist/{browser-tool-Cxtiwfua.d.ts → browser-tool-DxAYQY9T.d.ts} +2 -2
- package/dist/capability-DBAKc6UZ.js.map +1 -1
- package/dist/{capability-runner-BiVUtjqC.d.ts → capability-runner-uFOdSANC.d.ts} +3 -2
- package/dist/chat/index.d.ts +37 -6
- package/dist/chat/index.js +39 -3
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +3 -3
- package/dist/chat-sdk/index.js +1 -1
- package/dist/cli.js +64 -63
- package/dist/client-CkT8voRY.js +3740 -0
- package/dist/client-CkT8voRY.js.map +1 -0
- package/dist/{client-eSfgYvd3.d.ts → client-DqS6oequ.d.ts} +2 -2
- package/dist/client.d.ts +1 -1
- package/dist/{connector-Dl098To-.js → connector-Bphz6wIw.js} +16 -4
- package/dist/connector-Bphz6wIw.js.map +1 -0
- package/dist/{conversations-FjHDRZyD.d.ts → conversations-CoAYNW_q.d.ts} +4 -4
- package/dist/{current-agent-CKgT5d1O.d.ts → current-agent-DShbQHDO.d.ts} +24 -3
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{do-oauth-client-provider-DtNqv7oj.d.ts → do-oauth-client-provider-BsT8-vtd.d.ts} +22 -2
- package/dist/{durable-object-lifecycle-DOI_bzCH.d.ts → durable-object-lifecycle-CRCA6O0W.d.ts} +2 -2
- package/dist/experimental/channels/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.js +1 -1
- package/dist/experimental/webmcp.js +1 -1
- package/dist/{gateway-BFO6vRDn.d.ts → gateway-Dz8zyZBJ.d.ts} +2 -2
- package/dist/harness/ai-sdk/index.d.ts +2 -2
- package/dist/harness/container/index.d.ts +2 -2
- package/dist/harness/container/index.js +1 -1
- package/dist/harness/container/index.js.map +1 -1
- package/dist/harness/opencode/index.d.ts +1 -1
- package/dist/harness/pi/index.d.ts +128 -12
- package/dist/harness/pi/index.js +128 -20
- package/dist/harness/pi/index.js.map +1 -1
- package/dist/harness/think/index.d.ts +2 -2
- package/dist/{images-CfuRCjwq.js → images-D4gtE06D.js} +119 -27
- package/dist/images-D4gtE06D.js.map +1 -0
- package/dist/{index-8k4qsX1T.d.ts → index-BXVgv6tp.d.ts} +4 -4
- package/dist/{index-BEL3ZV-s.d.ts → index-Cs7Ed9la.d.ts} +2 -2
- package/dist/{index-CBt8oRJt.d.ts → index-XiZxauMU.d.ts} +3 -3
- package/dist/index.d.ts +21 -21
- package/dist/index.js +2 -2
- package/dist/{input-schema-0uUu392-.js → input-schema-D6GilRXI.js} +2 -2
- package/dist/{input-schema-0uUu392-.js.map → input-schema-D6GilRXI.js.map} +1 -1
- package/dist/{input-schema-waggtYrH.js → input-schema-y8W5bOdM.js} +2 -2
- package/dist/{input-schema-waggtYrH.js.map → input-schema-y8W5bOdM.js.map} +1 -1
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/lifecycle/index.js +1 -1
- package/dist/{lifecycle-v1rKHV2C.js → lifecycle-CB5Dmtrt.js} +126 -38
- package/dist/lifecycle-CB5Dmtrt.js.map +1 -0
- package/dist/mcp/client/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/client/do-oauth-client-provider.js +45 -2
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/client/index.d.ts +42 -36
- package/dist/mcp/client/index.js +2 -2
- package/dist/mcp/client/x402.d.ts +8 -8
- package/dist/mcp/index.d.ts +17 -17
- package/dist/mcp/index.js +5 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/models/ai-sdk/index.d.ts +9 -5
- package/dist/models/ai-sdk/index.js +1 -1
- package/dist/models/opencode/index.d.ts +3 -3
- package/dist/models/opencode/index.js +2 -2
- package/dist/models/opencode/index.js.map +1 -1
- package/dist/models/pi-ai/index.d.ts +4 -4
- package/dist/models/pi-ai/index.js +53 -29
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/{options-CiIsJHXR.d.ts → options-CiXaymmZ.d.ts} +2 -2
- package/dist/queue/index.d.ts +1 -1
- package/dist/queue/index.js +1 -1
- package/dist/{queue-CcIjVYTE.js → queue-B_wl6K0Z.js} +24 -5
- package/dist/queue-B_wl6K0Z.js.map +1 -0
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/{scheduler-BCLESHSC.d.ts → scheduler-CTpR0Ct0.d.ts} +2 -2
- package/dist/{scheduler-FIHv2-kJ.js → scheduler-DGNEmxQR.js} +2 -1
- package/dist/scheduler-DGNEmxQR.js.map +1 -0
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/session-CRY0bGiI.js.map +1 -1
- package/dist/sessions/index.d.ts +1 -1
- package/dist/{settings-Dk2il2Hf.js → settings-D2F_qONv.js} +11 -2
- package/dist/settings-D2F_qONv.js.map +1 -0
- package/dist/{src-DoGNJ4Ud.js → src-BO1FdLK1.js} +145 -86
- package/dist/src-BO1FdLK1.js.map +1 -0
- package/dist/state/index.d.ts +1 -1
- package/dist/streams/index.d.ts +1 -1
- package/dist/{streams-vrCtbUIn.d.ts → streams-CAZxZBDg.d.ts} +2 -2
- package/dist/sub-routing.d.ts +12 -12
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +1 -1
- package/dist/{tasks-BN_5AWqI.js → tasks-Cf_UfEO4.js} +2 -1
- package/dist/{tasks-BN_5AWqI.js.map → tasks-Cf_UfEO4.js.map} +1 -1
- package/dist/{tasks-E89KdwkS.d.ts → tasks-Cs8ilctE.d.ts} +2 -2
- package/dist/{tool-DkT_DJBm.js → tool-CmAGY6Fo.js} +24 -3
- package/dist/tool-CmAGY6Fo.js.map +1 -0
- package/dist/{tool-CxKsvxjm.js → tool-Kxcj8_22.js} +24 -4
- package/dist/tool-Kxcj8_22.js.map +1 -0
- package/dist/{transport-5moD2pW5.d.ts → transport-hV8AW4Bv.d.ts} +45 -12
- package/dist/voice/index.d.ts +2 -2
- package/dist/web/fetch/index.js +1 -1
- package/dist/web/fetch/tools/ai-sdk.js +2 -2
- package/dist/web/fetch/tools/pi.d.ts +5 -0
- package/dist/web/fetch/tools/pi.js +25 -2
- package/dist/web/fetch/tools/pi.js.map +1 -1
- package/dist/web/fetch/tools/tanstack-ai.js +2 -2
- package/dist/web/search/index.js +1 -1
- package/dist/web/search/tools/ai-sdk.js +2 -2
- package/dist/web/search/tools/pi.d.ts +4 -0
- package/dist/web/search/tools/pi.js +23 -2
- package/dist/web/search/tools/pi.js.map +1 -1
- package/dist/web/search/tools/tanstack-ai.js +2 -2
- package/dist/websockets/index.d.ts +2 -2
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-C6SJtWCJ.js → websockets-W4uhRg4-.js} +68 -5
- package/dist/websockets-W4uhRg4-.js.map +1 -0
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/agent-class.md +30 -4
- package/docs/browse-the-web.md +14 -0
- package/docs/chat-agents.md +13 -10
- package/docs/client-tools-continuation.md +1 -1
- package/docs/codemode.md +1 -1
- package/docs/configuration.md +6 -3
- package/docs/cross-domain-authentication.md +1 -1
- package/docs/fetch-the-web.md +20 -0
- package/docs/harnesses/pi.md +211 -22
- package/docs/harnesses/think.md +1 -1
- package/docs/http-websockets.md +40 -32
- package/docs/human-in-the-loop.md +2 -2
- package/docs/lifecycle.md +56 -0
- package/docs/mcp-client.md +104 -7
- package/docs/models-pi-ai.md +24 -10
- package/docs/models.md +42 -17
- package/docs/resumable-streaming.md +1 -1
- package/docs/retries.md +3 -6
- package/docs/search-the-web.md +10 -0
- package/docs/voice.md +1 -1
- package/package.json +13 -12
- package/dist/ai-sdk-CpuRsjP5.d.ts +0 -72
- package/dist/ai-sdk-Kon40i0q.js.map +0 -1
- package/dist/client-DMWujQJ1.js +0 -2325
- package/dist/client-DMWujQJ1.js.map +0 -1
- package/dist/connector-Dl098To-.js.map +0 -1
- package/dist/images-CfuRCjwq.js.map +0 -1
- package/dist/lifecycle-v1rKHV2C.js.map +0 -1
- package/dist/queue-CcIjVYTE.js.map +0 -1
- package/dist/scheduler-FIHv2-kJ.js.map +0 -1
- package/dist/settings-Dk2il2Hf.js.map +0 -1
- package/dist/src-DoGNJ4Ud.js.map +0 -1
- package/dist/tool-CxKsvxjm.js.map +0 -1
- package/dist/tool-DkT_DJBm.js.map +0 -1
- package/dist/websockets-C6SJtWCJ.js.map +0 -1
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
n as CapabilityStartContext,
|
|
4
4
|
s as LifecycleCapability,
|
|
5
5
|
v as LifecycleJobOutcome
|
|
6
|
-
} from "../../capability-runner-
|
|
6
|
+
} from "../../capability-runner-uFOdSANC.js";
|
|
7
7
|
import { OpenCodeWorkerd } from "@opencode/sdk/workerd";
|
|
8
8
|
|
|
9
9
|
//#region src/harness/opencode/types.d.ts
|
|
@@ -3,11 +3,12 @@ import {
|
|
|
3
3
|
n as CapabilityStartContext,
|
|
4
4
|
s as LifecycleCapability,
|
|
5
5
|
v as LifecycleJobOutcome
|
|
6
|
-
} from "../../capability-runner-
|
|
6
|
+
} from "../../capability-runner-uFOdSANC.js";
|
|
7
7
|
import { a as SkillSource } from "../../source-9RQzlEhM.js";
|
|
8
8
|
import {
|
|
9
9
|
AgentChange,
|
|
10
10
|
Conversation,
|
|
11
|
+
ConversationInit,
|
|
11
12
|
ConversationWatch,
|
|
12
13
|
ConversationWindow,
|
|
13
14
|
Cursor,
|
|
@@ -17,6 +18,10 @@ import {
|
|
|
17
18
|
Harness,
|
|
18
19
|
InputEntry,
|
|
19
20
|
Page,
|
|
21
|
+
SignalResult,
|
|
22
|
+
SignalToken,
|
|
23
|
+
SubmissionNotify,
|
|
24
|
+
TaskId,
|
|
20
25
|
UserInput,
|
|
21
26
|
Wake
|
|
22
27
|
} from "@earendil-works/pi-durable";
|
|
@@ -52,11 +57,22 @@ type PiWhenBusy = "followUp" | "steer" | "reject";
|
|
|
52
57
|
* race the run's end.
|
|
53
58
|
*/
|
|
54
59
|
type PiWhenIdle = "reject";
|
|
60
|
+
/**
|
|
61
|
+
* What aborting the session does with a queued input:
|
|
62
|
+
*
|
|
63
|
+
* - `withdraw` (default): the input settles `unanswered` with reason
|
|
64
|
+
* `aborted`.
|
|
65
|
+
* - `keep`: the input stays queued; the next input runs it first. For input
|
|
66
|
+
* its sender cannot send again, such as another agent's message.
|
|
67
|
+
* Withdrawing the operation itself (`abort(operationId)`) still removes it.
|
|
68
|
+
*/
|
|
69
|
+
type PiOnAbort = "withdraw" | "keep";
|
|
55
70
|
type PiSubmitOptions = {
|
|
56
71
|
/** Default: the root session. */ readonly session?: PiSessionId /** Idempotency key. Submitting the same id twice returns the same receipt. */;
|
|
57
72
|
readonly operationId?: string;
|
|
58
73
|
readonly whenBusy?: PiWhenBusy;
|
|
59
74
|
readonly whenIdle?: PiWhenIdle;
|
|
75
|
+
readonly onAbort?: PiOnAbort;
|
|
60
76
|
/**
|
|
61
77
|
* The transcript entry the input is placed as, instead of pi's `pi.user`:
|
|
62
78
|
* for input the user did not type, such as a scheduled prompt, a webhook,
|
|
@@ -65,13 +81,44 @@ type PiSubmitOptions = {
|
|
|
65
81
|
* start with `pi.`.
|
|
66
82
|
*/
|
|
67
83
|
readonly entry?: InputEntry;
|
|
84
|
+
/**
|
|
85
|
+
* A pi task to signal when this input settles: pi delivers its
|
|
86
|
+
* `SubmissionSettled` signal, the settled record, to `taskId` under `key`.
|
|
87
|
+
* For a tool that parks until another session answers. If the task has
|
|
88
|
+
* ended or does not exist, the input settles as usual.
|
|
89
|
+
*/
|
|
90
|
+
readonly notify?: SubmissionNotify;
|
|
68
91
|
};
|
|
69
92
|
type PiContinueOptions = {
|
|
70
|
-
/** Idempotency key. Continuing with the same id twice returns the same receipt. */ readonly operationId?: string
|
|
93
|
+
/** Idempotency key. Continuing with the same id twice returns the same receipt. */ readonly operationId?: string /** A pi task to signal when the run settles. See `PiSubmitOptions.notify`. */;
|
|
94
|
+
readonly notify?: SubmissionNotify;
|
|
71
95
|
};
|
|
72
96
|
type PiSessionOptions = {
|
|
73
97
|
/** Default: the root session. */ readonly session?: PiSessionId;
|
|
74
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* How `harness.root()`, `sessions.create()` and `sessions.fork()` create a
|
|
101
|
+
* session: pi-durable's `ConversationCreateOptions`, without `ownership`.
|
|
102
|
+
* Both apply in the one commit that creates the session.
|
|
103
|
+
*/
|
|
104
|
+
type PiSessionCreateOptions = {
|
|
105
|
+
/**
|
|
106
|
+
* pi's agent change for the new session. For the root and `create()`, it
|
|
107
|
+
* is applied over the harness's `defaults`; a fork starts with its
|
|
108
|
+
* parent's configuration, and this is applied over that. As in pi, a
|
|
109
|
+
* field that is `undefined` leaves the value underneath in place, and
|
|
110
|
+
* `null` clears it.
|
|
111
|
+
*/
|
|
112
|
+
readonly agent?: AgentChange;
|
|
113
|
+
/**
|
|
114
|
+
* pi's `ConversationInit`: runs inside the commit that creates the
|
|
115
|
+
* session, after `agent`, for example to seed its transcript with
|
|
116
|
+
* `tx.appendEntry()`, one entry per message. Table reads throw
|
|
117
|
+
* `ReadAfterWrite` there. A throw fails the commit, so the session is not
|
|
118
|
+
* created.
|
|
119
|
+
*/
|
|
120
|
+
readonly init?: ConversationInit;
|
|
121
|
+
};
|
|
75
122
|
/** Returned once a submission is durable. It says nothing about the model yet. */
|
|
76
123
|
type PiReceipt = {
|
|
77
124
|
readonly operationId: string;
|
|
@@ -178,6 +225,16 @@ type PiHarnessOptions = {
|
|
|
178
225
|
/** Opens pi's `Harness` over the storage this object prepared. */ readonly harness: PiHarnessFactory /** What a new session starts with. */;
|
|
179
226
|
readonly defaults?: PiSessionDefaults;
|
|
180
227
|
};
|
|
228
|
+
/** What `harness.root()` returns. */
|
|
229
|
+
type PiRootResult = {
|
|
230
|
+
/** The root session. */ readonly session: PiSession;
|
|
231
|
+
/**
|
|
232
|
+
* Whether this call created the root, so its `agent` and `init` were
|
|
233
|
+
* applied. `false` when the root already existed: something used it
|
|
234
|
+
* first, and `init` did not run.
|
|
235
|
+
*/
|
|
236
|
+
readonly created: boolean;
|
|
237
|
+
};
|
|
181
238
|
/**
|
|
182
239
|
* pi-durable hosted in a Durable Object, behind a small harness interface:
|
|
183
240
|
* `harness.prompt()`, `harness.sessions`, `harness.session(id)`. How a session reaches a
|
|
@@ -190,8 +247,9 @@ type PiHarnessOptions = {
|
|
|
190
247
|
*
|
|
191
248
|
* What pi cannot do on a Durable Object is wake itself: its scheduler runs
|
|
192
249
|
* in memory, and an evicted object has no memory. The harness is that wake,
|
|
193
|
-
* with one Lifecycle job driven by `pi.wake()`.
|
|
194
|
-
* `submit()`,
|
|
250
|
+
* with one Lifecycle job driven by `pi.wake()`. Anything that can start
|
|
251
|
+
* work, such as `submit()`, `signal()`, `abort()` or `reset()`, goes to pi
|
|
252
|
+
* once, after the job is scheduled. While pi has work running, the
|
|
195
253
|
* job waits on it, rescheduling itself as a heartbeat. While pi's tasks
|
|
196
254
|
* sleep, the job is due when the first one wakes; pi tells the harness
|
|
197
255
|
* through the `onWake` the factory passes to `Harness.open`. When pi has
|
|
@@ -219,6 +277,17 @@ declare class PiHarness extends LifecycleCapability {
|
|
|
219
277
|
dispose(): Promise<void>;
|
|
220
278
|
/** A handle on one session. No I/O until you call it. */
|
|
221
279
|
session(id?: PiSessionId): PiSession;
|
|
280
|
+
/**
|
|
281
|
+
* The root session, creating it with `agent` and `init` in one commit
|
|
282
|
+
* when it does not exist yet, as pi's `Harness.root()` does. `agent` is
|
|
283
|
+
* applied over `defaults`. When the root already exists, nothing is
|
|
284
|
+
* written and `init` does not run; `created` says which happened.
|
|
285
|
+
*
|
|
286
|
+
* Without this call, the first use of the root creates it with
|
|
287
|
+
* `defaults`. So call it before anything else uses the root, for example
|
|
288
|
+
* to seed the root's transcript with an existing history.
|
|
289
|
+
*/
|
|
290
|
+
root(options?: PiSessionCreateOptions): Promise<PiRootResult>;
|
|
222
291
|
/** Submit a prompt and wait for its answer. */
|
|
223
292
|
prompt(
|
|
224
293
|
input: UserInput,
|
|
@@ -247,9 +316,25 @@ declare class PiHarness extends LifecycleCapability {
|
|
|
247
316
|
messages(options?: PiSessionOptions): Promise<EntryRecord[]>;
|
|
248
317
|
/** Submissions pi has not settled yet, oldest first. */
|
|
249
318
|
pending(options?: PiSessionOptions): Promise<PiPendingOperation[]>;
|
|
319
|
+
/**
|
|
320
|
+
* Deliver `value` to pi task `taskId` under `key`, as pi's
|
|
321
|
+
* `Harness.signal()` does: for a tool parked on that signal, such as one
|
|
322
|
+
* waiting for a person's answer or a webhook. The wake job is scheduled
|
|
323
|
+
* first, so if the object dies while the woken call runs, the job's alarm
|
|
324
|
+
* restarts it. Call this rather than `pi().signal()`, which does not.
|
|
325
|
+
*/
|
|
326
|
+
signal<T>(
|
|
327
|
+
taskId: TaskId,
|
|
328
|
+
signal: SignalToken<T>,
|
|
329
|
+
key: string,
|
|
330
|
+
value: T
|
|
331
|
+
): Promise<SignalResult>;
|
|
250
332
|
/** The opened pi Harness, for anything the interface does not cover. */
|
|
251
333
|
pi(): Promise<Harness>;
|
|
252
|
-
/**
|
|
334
|
+
/**
|
|
335
|
+
* @internal Every use of a session goes through here. The first use of
|
|
336
|
+
* the root creates it, with `defaults`.
|
|
337
|
+
*/
|
|
253
338
|
conversation(session: PiSessionId): Promise<Conversation>;
|
|
254
339
|
/** @internal */
|
|
255
340
|
storage(): Promise<SqliteStorage>;
|
|
@@ -266,12 +351,32 @@ declare class PiHarness extends LifecycleCapability {
|
|
|
266
351
|
): Promise<PiReceipt>;
|
|
267
352
|
/** @internal Withdraw a queued input, or abort the run it joined. */
|
|
268
353
|
withdraw(session: PiSessionId, operationId: string): Promise<boolean>;
|
|
354
|
+
/**
|
|
355
|
+
* @internal Abort a session's running work and withdraw its queued
|
|
356
|
+
* inputs. Stopping a parked call runs its `cancel()`, which is work, so
|
|
357
|
+
* the wake is scheduled first.
|
|
358
|
+
*/
|
|
359
|
+
abortConversation(session: PiSessionId): Promise<void>;
|
|
360
|
+
/**
|
|
361
|
+
* @internal Start a new context. Inputs kept behind a failed run or an
|
|
362
|
+
* abort run in it, so the wake is scheduled first.
|
|
363
|
+
*/
|
|
364
|
+
resetConversation(
|
|
365
|
+
session: PiSessionId,
|
|
366
|
+
handoff: string | undefined
|
|
367
|
+
): Promise<void>;
|
|
269
368
|
/** @internal Wait for pi to settle an operation, by its request id. */
|
|
270
369
|
settled(
|
|
271
370
|
session: PiSessionId,
|
|
272
371
|
operationId: string,
|
|
273
372
|
signal?: AbortSignal
|
|
274
373
|
): Promise<PiOperationResult>;
|
|
374
|
+
/**
|
|
375
|
+
* @internal `agent` applied over the defaults, by pi's rule for an
|
|
376
|
+
* `AgentChange`: a field set to a value replaces the default, `null`
|
|
377
|
+
* clears it, and `undefined` leaves it in place.
|
|
378
|
+
*/
|
|
379
|
+
agentOverDefaults(agent?: AgentChange): AgentChange;
|
|
275
380
|
/** @internal The per-conversation defaults supported by pi-durable. */
|
|
276
381
|
agentDefaults(): AgentChange;
|
|
277
382
|
}
|
|
@@ -304,8 +409,8 @@ declare class PiSession {
|
|
|
304
409
|
wait(operationId: string, signal?: AbortSignal): Promise<PiOperationResult>;
|
|
305
410
|
/**
|
|
306
411
|
* Withdraw one queued operation (or abort the run it joined), or, with no
|
|
307
|
-
* id, abort the session: pi withdraws queued inputs
|
|
308
|
-
* running work.
|
|
412
|
+
* id, abort the session: pi withdraws queued inputs, apart from those
|
|
413
|
+
* submitted with `onAbort: "keep"`, and aborts the running work.
|
|
309
414
|
*/
|
|
310
415
|
abort(operationId?: string): Promise<boolean>;
|
|
311
416
|
/** Start a new context, optionally from a handoff note. */
|
|
@@ -347,13 +452,21 @@ declare class PiSessions {
|
|
|
347
452
|
#private;
|
|
348
453
|
constructor(harness: PiHarness);
|
|
349
454
|
get(id: PiSessionId): PiSession;
|
|
350
|
-
/**
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
455
|
+
/**
|
|
456
|
+
* A new top-level session, configured with `defaults`, then `agent`; `init`
|
|
457
|
+
* runs in the commit that creates it.
|
|
458
|
+
*/
|
|
459
|
+
create(options?: PiSessionCreateOptions): Promise<PiSession>;
|
|
460
|
+
/**
|
|
461
|
+
* A new session that sees `from`'s history up to its newest entry, with
|
|
462
|
+
* `from`'s configuration, then `agent`; `init` runs in the commit that
|
|
463
|
+
* creates it.
|
|
464
|
+
*/
|
|
465
|
+
fork(from: PiSessionId, options?: PiSessionCreateOptions): Promise<PiSession>;
|
|
354
466
|
/**
|
|
355
467
|
* Every conversation, including ones subagent tools own. Read from pi's
|
|
356
|
-
* storage directly: the Harness has no conversation listing.
|
|
468
|
+
* storage directly: the Harness has no conversation listing. The root is
|
|
469
|
+
* listed once it exists: its first use, or `harness.root()`, creates it.
|
|
357
470
|
*/
|
|
358
471
|
list(): Promise<PiSessionInfo[]>;
|
|
359
472
|
}
|
|
@@ -412,11 +525,14 @@ export {
|
|
|
412
525
|
type PiHarnessFactory,
|
|
413
526
|
type PiHarnessOptions,
|
|
414
527
|
type PiModel,
|
|
528
|
+
type PiOnAbort,
|
|
415
529
|
type PiOperationResult,
|
|
416
530
|
type PiPendingOperation,
|
|
417
531
|
type PiPromptResponse,
|
|
418
532
|
type PiReceipt,
|
|
533
|
+
type PiRootResult,
|
|
419
534
|
PiSession,
|
|
535
|
+
type PiSessionCreateOptions,
|
|
420
536
|
type PiSessionDefaults,
|
|
421
537
|
type PiSessionId,
|
|
422
538
|
type PiSessionInfo,
|
package/dist/harness/pi/index.js
CHANGED
|
@@ -59,6 +59,19 @@ const WAKE_FN = "wake";
|
|
|
59
59
|
* `pi-wake:<session>`; a left-over one hands over to this one.
|
|
60
60
|
*/
|
|
61
61
|
const WAKE_JOB_ID = "pi-wake";
|
|
62
|
+
/**
|
|
63
|
+
* `change` applied over `base` as pi applies an `AgentChange`: a field that is
|
|
64
|
+
* `undefined` in `change` keeps `base`'s, any other value (`null` included)
|
|
65
|
+
* replaces it. A plain spread would copy the `undefined` over `base`'s value.
|
|
66
|
+
*/
|
|
67
|
+
function applyAgentChange(base, change) {
|
|
68
|
+
const applied = {
|
|
69
|
+
...base,
|
|
70
|
+
...change
|
|
71
|
+
};
|
|
72
|
+
for (const key in base) if (change[key] === void 0) applied[key] = base[key];
|
|
73
|
+
return applied;
|
|
74
|
+
}
|
|
62
75
|
/** pi-durable's stored reference to a pi-ai model. */
|
|
63
76
|
function modelRef(model) {
|
|
64
77
|
return {
|
|
@@ -105,8 +118,9 @@ var _onWake = /* @__PURE__ */ new WeakMap();
|
|
|
105
118
|
*
|
|
106
119
|
* What pi cannot do on a Durable Object is wake itself: its scheduler runs
|
|
107
120
|
* in memory, and an evicted object has no memory. The harness is that wake,
|
|
108
|
-
* with one Lifecycle job driven by `pi.wake()`.
|
|
109
|
-
* `submit()`,
|
|
121
|
+
* with one Lifecycle job driven by `pi.wake()`. Anything that can start
|
|
122
|
+
* work, such as `submit()`, `signal()`, `abort()` or `reset()`, goes to pi
|
|
123
|
+
* once, after the job is scheduled. While pi has work running, the
|
|
110
124
|
* job waits on it, rescheduling itself as a heartbeat. While pi's tasks
|
|
111
125
|
* sleep, the job is due when the first one wakes; pi tells the harness
|
|
112
126
|
* through the `onWake` the factory passes to `Harness.open`. When pi has
|
|
@@ -178,6 +192,31 @@ var PiHarness = class extends LifecycleCapability {
|
|
|
178
192
|
session(id = ROOT_SESSION) {
|
|
179
193
|
return new PiSession(this, id);
|
|
180
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* The root session, creating it with `agent` and `init` in one commit
|
|
197
|
+
* when it does not exist yet, as pi's `Harness.root()` does. `agent` is
|
|
198
|
+
* applied over `defaults`. When the root already exists, nothing is
|
|
199
|
+
* written and `init` does not run; `created` says which happened.
|
|
200
|
+
*
|
|
201
|
+
* Without this call, the first use of the root creates it with
|
|
202
|
+
* `defaults`. So call it before anything else uses the root, for example
|
|
203
|
+
* to seed the root's transcript with an existing history.
|
|
204
|
+
*/
|
|
205
|
+
async root(options = {}) {
|
|
206
|
+
const { pi } = await _assertClassBrand(_PiHarness_brand, this, _open).call(this);
|
|
207
|
+
let created = false;
|
|
208
|
+
await _assertClassBrand(_PiHarness_brand, this, _root).call(this, pi, {
|
|
209
|
+
...options.agent ? { agent: options.agent } : {},
|
|
210
|
+
init: async (tx, id) => {
|
|
211
|
+
created = true;
|
|
212
|
+
await options.init?.(tx, id);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return {
|
|
216
|
+
session: this.session(ROOT_SESSION),
|
|
217
|
+
created
|
|
218
|
+
};
|
|
219
|
+
}
|
|
181
220
|
/** Submit a prompt and wait for its answer. */
|
|
182
221
|
prompt(input, options = {}) {
|
|
183
222
|
return this.session(options.session).prompt(input, options);
|
|
@@ -230,14 +269,30 @@ var PiHarness = class extends LifecycleCapability {
|
|
|
230
269
|
}];
|
|
231
270
|
});
|
|
232
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Deliver `value` to pi task `taskId` under `key`, as pi's
|
|
274
|
+
* `Harness.signal()` does: for a tool parked on that signal, such as one
|
|
275
|
+
* waiting for a person's answer or a webhook. The wake job is scheduled
|
|
276
|
+
* first, so if the object dies while the woken call runs, the job's alarm
|
|
277
|
+
* restarts it. Call this rather than `pi().signal()`, which does not.
|
|
278
|
+
*/
|
|
279
|
+
async signal(taskId, signal, key, value) {
|
|
280
|
+
const { pi } = await _assertClassBrand(_PiHarness_brand, this, _open).call(this);
|
|
281
|
+
return _assertClassBrand(_PiHarness_brand, this, _admit).call(this, () => pi.signal(taskId, signal, key, value, BG));
|
|
282
|
+
}
|
|
233
283
|
/** The opened pi Harness, for anything the interface does not cover. */
|
|
234
284
|
async pi() {
|
|
235
285
|
return (await _assertClassBrand(_PiHarness_brand, this, _open).call(this)).pi;
|
|
236
286
|
}
|
|
237
|
-
/**
|
|
287
|
+
/**
|
|
288
|
+
* @internal Every use of a session goes through here. The first use of
|
|
289
|
+
* the root creates it, with `defaults`.
|
|
290
|
+
*/
|
|
238
291
|
async conversation(session) {
|
|
239
292
|
const { pi } = await _assertClassBrand(_PiHarness_brand, this, _open).call(this);
|
|
240
|
-
const
|
|
293
|
+
const id = conversationId(session);
|
|
294
|
+
if (id === ROOT_CONVERSATION_ID) return _assertClassBrand(_PiHarness_brand, this, _root).call(this, pi, {});
|
|
295
|
+
const conversation = await pi.conversation(id, BG);
|
|
241
296
|
if (!conversation) throw new Error(`Unknown pi session ${session}`);
|
|
242
297
|
return conversation;
|
|
243
298
|
}
|
|
@@ -252,12 +307,17 @@ var PiHarness = class extends LifecycleCapability {
|
|
|
252
307
|
content: input,
|
|
253
308
|
whenBusy: options.whenBusy ?? "followUp",
|
|
254
309
|
...options.whenIdle ? { whenIdle: options.whenIdle } : {},
|
|
255
|
-
...options.
|
|
310
|
+
...options.onAbort ? { onAbort: options.onAbort } : {},
|
|
311
|
+
...options.entry ? { entry: options.entry } : {},
|
|
312
|
+
...options.notify ? { notify: options.notify } : {}
|
|
256
313
|
});
|
|
257
314
|
}
|
|
258
315
|
/** @internal Start a run on the context as it is, without new input. */
|
|
259
316
|
enqueueContinue(session, options) {
|
|
260
|
-
return _assertClassBrand(_PiHarness_brand, this, _admitDraft).call(this, session, options.operationId, {
|
|
317
|
+
return _assertClassBrand(_PiHarness_brand, this, _admitDraft).call(this, session, options.operationId, {
|
|
318
|
+
type: "continue",
|
|
319
|
+
...options.notify ? { notify: options.notify } : {}
|
|
320
|
+
});
|
|
261
321
|
}
|
|
262
322
|
/** @internal Withdraw a queued input, or abort the run it joined. */
|
|
263
323
|
async withdraw(session, operationId) {
|
|
@@ -265,17 +325,34 @@ var PiHarness = class extends LifecycleCapability {
|
|
|
265
325
|
const id = conversationId(session);
|
|
266
326
|
const record = await storage.submissionByRequest(id, operationId, BG);
|
|
267
327
|
if (!record || record.status === "done" || record.status === "unanswered") return false;
|
|
268
|
-
const outcome = await pi.abortSubmission(record.id, BG, id);
|
|
328
|
+
const outcome = await _assertClassBrand(_PiHarness_brand, this, _admit).call(this, () => pi.abortSubmission(record.id, BG, id));
|
|
269
329
|
switch (outcome) {
|
|
270
330
|
case "aborted": return true;
|
|
271
331
|
case "already_placed":
|
|
272
|
-
await
|
|
332
|
+
await this.abortConversation(session);
|
|
273
333
|
return true;
|
|
274
334
|
case "settled":
|
|
275
335
|
case "not_found": return false;
|
|
276
336
|
default: return outcome;
|
|
277
337
|
}
|
|
278
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* @internal Abort a session's running work and withdraw its queued
|
|
341
|
+
* inputs. Stopping a parked call runs its `cancel()`, which is work, so
|
|
342
|
+
* the wake is scheduled first.
|
|
343
|
+
*/
|
|
344
|
+
async abortConversation(session) {
|
|
345
|
+
const conversation = await this.conversation(session);
|
|
346
|
+
await _assertClassBrand(_PiHarness_brand, this, _admit).call(this, () => conversation.abort(BG));
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* @internal Start a new context. Inputs kept behind a failed run or an
|
|
350
|
+
* abort run in it, so the wake is scheduled first.
|
|
351
|
+
*/
|
|
352
|
+
async resetConversation(session, handoff) {
|
|
353
|
+
const conversation = await this.conversation(session);
|
|
354
|
+
await _assertClassBrand(_PiHarness_brand, this, _admit).call(this, () => conversation.reset(handoff, BG));
|
|
355
|
+
}
|
|
279
356
|
/** @internal Wait for pi to settle an operation, by its request id. */
|
|
280
357
|
async settled(session, operationId, signal) {
|
|
281
358
|
const conversation = await this.conversation(session);
|
|
@@ -289,6 +366,14 @@ var PiHarness = class extends LifecycleCapability {
|
|
|
289
366
|
};
|
|
290
367
|
return _assertClassBrand(_PiHarness_brand, this, _result).call(this, session, operationId, await submission.wait(context), context);
|
|
291
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* @internal `agent` applied over the defaults, by pi's rule for an
|
|
371
|
+
* `AgentChange`: a field set to a value replaces the default, `null`
|
|
372
|
+
* clears it, and `undefined` leaves it in place.
|
|
373
|
+
*/
|
|
374
|
+
agentOverDefaults(agent = {}) {
|
|
375
|
+
return applyAgentChange(this.agentDefaults(), agent);
|
|
376
|
+
}
|
|
292
377
|
/** @internal The per-conversation defaults supported by pi-durable. */
|
|
293
378
|
agentDefaults() {
|
|
294
379
|
const defaults = _classPrivateFieldGet2(_options, this).defaults;
|
|
@@ -299,6 +384,17 @@ var PiHarness = class extends LifecycleCapability {
|
|
|
299
384
|
};
|
|
300
385
|
}
|
|
301
386
|
};
|
|
387
|
+
/**
|
|
388
|
+
* pi's root conversation, created with `options` over `defaults` when
|
|
389
|
+
* absent. pi checks for the root and creates it in one commit, so two
|
|
390
|
+
* calls never both create it.
|
|
391
|
+
*/
|
|
392
|
+
function _root(pi, options) {
|
|
393
|
+
return pi.root(BG, {
|
|
394
|
+
agent: this.agentOverDefaults(options.agent),
|
|
395
|
+
...options.init ? { init: options.init } : {}
|
|
396
|
+
});
|
|
397
|
+
}
|
|
302
398
|
async function _admitDraft(session, requested, draft) {
|
|
303
399
|
const operationId = requested ?? crypto.randomUUID();
|
|
304
400
|
const { storage } = await _assertClassBrand(_PiHarness_brand, this, _open).call(this);
|
|
@@ -455,7 +551,6 @@ async function _doOpen(onClose) {
|
|
|
455
551
|
try {
|
|
456
552
|
const closed = pi.closed;
|
|
457
553
|
pi.subscribeClose(() => onClose(pi, closed));
|
|
458
|
-
await pi.root(BG, { agent: this.agentDefaults() });
|
|
459
554
|
pi.resume();
|
|
460
555
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
461
556
|
if (!_classPrivateFieldGet2(_onWakeWired, this)) console.warn("PiHarness: the harness factory did not pass onWake to Harness.open, so pi's timers keep this Durable Object in memory while a task sleeps. Pass it: harness: ({ storage, context, onWake }) => Harness.open(storage, { ...options, onWake }, context)");
|
|
@@ -550,17 +645,17 @@ var PiSession = class {
|
|
|
550
645
|
}
|
|
551
646
|
/**
|
|
552
647
|
* Withdraw one queued operation (or abort the run it joined), or, with no
|
|
553
|
-
* id, abort the session: pi withdraws queued inputs
|
|
554
|
-
* running work.
|
|
648
|
+
* id, abort the session: pi withdraws queued inputs, apart from those
|
|
649
|
+
* submitted with `onAbort: "keep"`, and aborts the running work.
|
|
555
650
|
*/
|
|
556
651
|
async abort(operationId) {
|
|
557
652
|
if (operationId !== void 0) return _classPrivateFieldGet2(_harness, this).withdraw(this.id, operationId);
|
|
558
|
-
await
|
|
653
|
+
await _classPrivateFieldGet2(_harness, this).abortConversation(this.id);
|
|
559
654
|
return true;
|
|
560
655
|
}
|
|
561
656
|
/** Start a new context, optionally from a handoff note. */
|
|
562
657
|
async reset(handoff) {
|
|
563
|
-
await
|
|
658
|
+
await _classPrivateFieldGet2(_harness, this).resetConversation(this.id, handoff);
|
|
564
659
|
}
|
|
565
660
|
/**
|
|
566
661
|
* Change this session's model, by its `provider` and `id`; it must be on
|
|
@@ -607,25 +702,38 @@ var PiSessions = class {
|
|
|
607
702
|
get(id) {
|
|
608
703
|
return _classPrivateFieldGet2(_harness2, this).session(id);
|
|
609
704
|
}
|
|
610
|
-
/**
|
|
611
|
-
|
|
705
|
+
/**
|
|
706
|
+
* A new top-level session, configured with `defaults`, then `agent`; `init`
|
|
707
|
+
* runs in the commit that creates it.
|
|
708
|
+
*/
|
|
709
|
+
async create(options = {}) {
|
|
612
710
|
const conversation = await (await _classPrivateFieldGet2(_harness2, this).pi()).createConversation({
|
|
613
711
|
ownership: { kind: "ownerless" },
|
|
614
|
-
agent: _classPrivateFieldGet2(_harness2, this).
|
|
712
|
+
agent: _classPrivateFieldGet2(_harness2, this).agentOverDefaults(options.agent),
|
|
713
|
+
...options.init ? { init: options.init } : {}
|
|
615
714
|
}, BG);
|
|
616
715
|
return _classPrivateFieldGet2(_harness2, this).session(String(conversation.id));
|
|
617
716
|
}
|
|
618
|
-
/**
|
|
619
|
-
|
|
717
|
+
/**
|
|
718
|
+
* A new session that sees `from`'s history up to its newest entry, with
|
|
719
|
+
* `from`'s configuration, then `agent`; `init` runs in the commit that
|
|
720
|
+
* creates it.
|
|
721
|
+
*/
|
|
722
|
+
async fork(from, options = {}) {
|
|
620
723
|
const conversation = await _classPrivateFieldGet2(_harness2, this).conversation(from);
|
|
621
724
|
const at = (await conversation.entries({}, 1, void 0, BG)).items[0];
|
|
622
725
|
if (!at) throw new Error(`Session ${from} has no entries to fork from`);
|
|
623
|
-
const fork = await conversation.fork(at.id, {
|
|
726
|
+
const fork = await conversation.fork(at.id, {
|
|
727
|
+
ownership: { kind: "ownerless" },
|
|
728
|
+
...options.agent ? { agent: options.agent } : {},
|
|
729
|
+
...options.init ? { init: options.init } : {}
|
|
730
|
+
}, BG);
|
|
624
731
|
return _classPrivateFieldGet2(_harness2, this).session(String(fork.id));
|
|
625
732
|
}
|
|
626
733
|
/**
|
|
627
734
|
* Every conversation, including ones subagent tools own. Read from pi's
|
|
628
|
-
* storage directly: the Harness has no conversation listing.
|
|
735
|
+
* storage directly: the Harness has no conversation listing. The root is
|
|
736
|
+
* listed once it exists: its first use, or `harness.root()`, creates it.
|
|
629
737
|
*/
|
|
630
738
|
async list() {
|
|
631
739
|
const storage = await _classPrivateFieldGet2(_harness2, this).storage();
|