agents 0.25.0 → 0.26.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.
@@ -6,22 +6,18 @@ import {
6
6
  } from "../../capability-runner-DBAnGr6L.js";
7
7
  import { T as SkillSource } from "../../index-kbSUIer3.js";
8
8
  import {
9
+ AgentChange,
9
10
  AgentEventStream,
10
11
  Conversation,
11
- ConversationId,
12
- ConversationRetryPolicy,
13
12
  EntryRecord,
13
+ Extension,
14
14
  Harness,
15
- ModelRef,
16
- Registry,
17
- ToolRegistration,
18
- Tx,
19
15
  UserInput
20
16
  } from "@earendil-works/pi-durable";
21
17
  import { SqliteStorage } from "@earendil-works/pi-durable/storage/sqlite";
22
- import { ModelThinkingLevel } from "@earendil-works/pi-ai";
18
+ import { Api, Model, ModelThinkingLevel } from "@earendil-works/pi-ai";
23
19
 
24
- //#region src/harnesses/pi/context.d.ts
20
+ //#region src/harness/pi/context.d.ts
25
21
  /**
26
22
  * pi's invocation context, as `@earendil-works/chord` defines it.
27
23
  *
@@ -34,44 +30,16 @@ import { ModelThinkingLevel } from "@earendil-works/pi-ai";
34
30
  *
35
31
  * One limit: chord's own derived contexts read the abort signal through a
36
32
  * private key rather than `abortSignal`, so a chord `withContextValue`
37
- * wrapped around one of these would not see its signal. pi 0.99.2 never
38
- * wraps a caller's context that way; `withAbortSignal` and `withCancel`
39
- * read `abortSignal` and work.
33
+ * wrapped around one of these would not see its signal. pi-durable does not
34
+ * use `withContextValue` to wrap a caller's context that way; `withAbortSignal`
35
+ * and `withCancel` read `abortSignal` and work.
40
36
  *
41
37
  * If pi-durable starts re-exporting chord's context helpers, replace this
42
38
  * file with those.
43
39
  */
44
40
  type Context$1 = Parameters<Harness["close"]>[0];
45
41
  //#endregion
46
- //#region src/harnesses/pi/session-store.d.ts
47
- /**
48
- * pi's session store on a Durable Object's SQLite database.
49
- *
50
- * pi owns its sessions: conversations, entries, tasks, submissions, and
51
- * documents live in pi's own schema, created and migrated by pi's portable
52
- * `SqliteStorage`. This file only supplies the synchronous database facade
53
- * pi asks for, over `ctx.storage.sql`, and moves pi's tables under a prefix
54
- * so they cannot collide with the SDK's or the host's tables in the same
55
- * object.
56
- *
57
- * It is the Durable Object counterpart of `agents/sessions` for a harness
58
- * that brings its own session model, and has nothing pi-harness specific in
59
- * it: any harness built on pi-durable can open its storage with it.
60
- */
61
- type PiSessionStoreOptions = {
62
- /**
63
- * Prefix for every table and index pi creates. Must not start with `_cf_`,
64
- * which Durable Objects reserve. Default `pi_`.
65
- */
66
- readonly prefix?: string;
67
- };
68
- /** Open pi-durable's storage over this object's SQLite database. */
69
- declare function openPiSessionStore(
70
- storage: DurableObjectStorage,
71
- options?: PiSessionStoreOptions
72
- ): Promise<SqliteStorage>;
73
- //#endregion
74
- //#region src/harnesses/pi/types.d.ts
42
+ //#region src/harness/pi/types.d.ts
75
43
  /**
76
44
  * `PiHarness`'s own types: how the harness addresses sessions and reports
77
45
  * operations. Anything pi already publishes (input, transcript entries,
@@ -125,56 +93,59 @@ type PiSessionInfo = {
125
93
  readonly busy: boolean;
126
94
  };
127
95
  //#endregion
128
- //#region src/harnesses/pi/harness.d.ts
96
+ //#region src/harness/pi/harness.d.ts
129
97
  /** The root session's id. */
130
98
  declare const ROOT_SESSION: PiSessionId;
131
99
  /**
132
- * What the harness factory is handed. The store is already open and pi's
133
- * migrations have run, so a factory only has to decide how to call
134
- * `Harness.open` — or call something else that satisfies the same contract.
100
+ * What the factory is handed: the two things only the harness can build.
101
+ * Everything else `Harness.open` takes (models, registry, settings, env,
102
+ * onReport) the factory builds itself.
135
103
  */
136
104
  type PiHarnessContext = {
137
- /** pi's storage over this object's SQLite, tables under the store prefix. */ readonly storage: SqliteStorage /** Background context, for the open itself. */;
105
+ /** pi's storage over this object's SQLite, its migrations already run. */ readonly storage: SqliteStorage /** Background context, for the open itself. */;
138
106
  readonly context: Context$1;
139
107
  };
140
108
  /**
141
- * Builds pi's `Harness`. Return value is adopted as-is: the caller owns the
142
- * registry (tools, system prompt, hooks, skills), `models`, `env`,
143
- * `onReport` and anything else `HarnessOptions` grows.
109
+ * Opens pi's `Harness`. The harness adopts what it returns.
144
110
  *
145
111
  * ```ts
146
- * harness: ({ storage, context }) =>
147
- * Harness.open(storage, { models, registry }, context)
112
+ * harness: async ({ storage, context }) => {
113
+ * const registry = createRegistry();
114
+ * registry.install(await skills(sources));
115
+ * return Harness.open(storage, { models, registry }, context);
116
+ * }
148
117
  * ```
149
118
  */
150
119
  type PiHarnessFactory = (
151
120
  context: PiHarnessContext
152
121
  ) => Harness | Promise<Harness>;
122
+ /**
123
+ * A model, as pi-ai describes one: `createAI`'s `ai("@cf/…")` returns one.
124
+ *
125
+ * Only its `provider` and `id` are used. pi stores that reference with
126
+ * the session and resolves it, at each request, against the `Models` the
127
+ * factory opened pi with. So the model must be one those `Models` list,
128
+ * and options passed to `ai(id, options)` here, such as `fallback`, are not
129
+ * applied.
130
+ */
131
+ type PiModel = Pick<Model<Api>, "provider" | "id">;
153
132
  /**
154
133
  * Applied to a session the first time it is created. Without a model, a
155
134
  * session's generation fails as unanswered until `session.setModel` sets one.
156
135
  */
157
136
  type PiSessionDefaults = {
158
- /** Model for new sessions. Change one session's with `session.setModel`. */ readonly model?: ModelRef;
159
- readonly thinkingLevel?: ModelThinkingLevel /** pi's generation retries for new sessions. */;
160
- readonly retry?: ConversationRetryPolicy;
161
- };
162
- /**
163
- * How long the wake waits and when it hands a wait to the alarm. Defaults
164
- * suit a real deployment; a test shortens them so a suite does not sit on
165
- * the real heartbeat.
166
- */
167
- type PiWakeTiming = {
168
- /** A pi wait further away than this goes to the alarm. Default 60_000. */ readonly sleepThresholdMs?: number /** Longest one wake waits inside an alarm. Default 600_000. */;
169
- readonly waitBudgetMs?: number /** Heartbeat while waiting, and the re-check for background work. Default 30_000. */;
170
- readonly heartbeatMs?: number;
137
+ /**
138
+ * Model for new sessions, by its `provider` and `id`; it must be on the
139
+ * `Models` the factory opens pi with (see `PiModel`). Change one
140
+ * session's with `session.setModel`.
141
+ */
142
+ readonly model?: PiModel;
143
+ readonly thinkingLevel?: ModelThinkingLevel;
171
144
  };
172
145
  /** `PiHarness`'s options. Only `harness`, which opens pi, is required. */
173
146
  type PiHarnessOptions = {
174
- /** Opens pi's `Harness` over the store this object prepared. */ readonly harness: PiHarnessFactory /** Applied to new sessions. */;
147
+ /** Opens pi's `Harness` over the storage this object prepared. */ readonly harness: PiHarnessFactory /** What a new session starts with. */;
175
148
  readonly defaults?: PiSessionDefaults;
176
- readonly store?: PiSessionStoreOptions;
177
- readonly timing?: PiWakeTiming;
178
149
  };
179
150
  /**
180
151
  * pi-durable hosted in a Durable Object, behind a small harness interface:
@@ -195,7 +166,7 @@ type PiHarnessOptions = {
195
166
  * restarts the object, pi reopens and resumes its own tasks, and the job
196
167
  * waits again.
197
168
  *
198
- * @experimental The API may change between releases.
169
+ * @beta The API may change between releases.
199
170
  */
200
171
  declare class PiHarness extends LifecycleCapability {
201
172
  #private;
@@ -236,8 +207,6 @@ declare class PiHarness extends LifecycleCapability {
236
207
  conversation(session: PiSessionId): Promise<Conversation>;
237
208
  /** @internal */
238
209
  storage(): Promise<SqliteStorage>;
239
- /** @internal Configure a new session like the root. */
240
- initSession(tx: Tx, id: ConversationId): Promise<void>;
241
210
  /** @internal */
242
211
  enqueue(
243
212
  session: PiSessionId,
@@ -252,6 +221,8 @@ declare class PiHarness extends LifecycleCapability {
252
221
  operationId: string,
253
222
  signal?: AbortSignal
254
223
  ): Promise<PiOperationResult>;
224
+ /** @internal The per-conversation defaults supported by pi-durable. */
225
+ agentDefaults(): AgentChange;
255
226
  }
256
227
  /** One pi conversation, addressed through the harness. */
257
228
  declare class PiSession {
@@ -280,7 +251,11 @@ declare class PiSession {
280
251
  abort(operationId?: string): Promise<boolean>;
281
252
  /** Start a new context, optionally from a handoff note. */
282
253
  reset(handoff?: string): Promise<void>;
283
- setModel(model: ModelRef): Promise<void>;
254
+ /**
255
+ * Change this session's model, by its `provider` and `id`; it must be on
256
+ * the `Models` the factory opened pi with (see `PiModel`).
257
+ */
258
+ setModel(model: PiModel): Promise<void>;
284
259
  /** The active transcript, as pi's entries since the newest reset. */
285
260
  messages(): Promise<EntryRecord[]>;
286
261
  /** pi's agent events for this session: a snapshot, then one batch per commit. */
@@ -303,29 +278,52 @@ declare class PiSessions {
303
278
  list(): Promise<PiSessionInfo[]>;
304
279
  }
305
280
  //#endregion
306
- //#region src/harnesses/pi/skills.d.ts
307
- /** Skills resolved from `agents/skills` sources for one process lifetime. */
308
- type ResolvedSkills = {
309
- /** Changes when any source's fingerprint changes. */ readonly fingerprint: string /** Model-facing activation tools; empty when there are no skills. */;
310
- readonly tools: readonly ToolRegistration[] /** System-prompt catalog, or null when there are no skills. */;
311
- readonly catalog: string | null;
312
- readonly warnings: readonly string[];
281
+ //#region src/harness/pi/session-store.d.ts
282
+ /**
283
+ * pi's session store on a Durable Object's SQLite database.
284
+ *
285
+ * pi owns its sessions: conversations, entries, tasks, submissions, and
286
+ * documents live in pi's own schema, created and migrated by pi's portable
287
+ * `SqliteStorage`. This file only supplies the asynchronous database facade
288
+ * pi asks for, over `ctx.storage.sql`, and moves pi's tables under a prefix
289
+ * so they cannot collide with the SDK's or the host's tables in the same
290
+ * object.
291
+ *
292
+ * It is the Durable Object counterpart of `agents/sessions` for a harness
293
+ * that brings its own session model, and has nothing pi-harness specific in
294
+ * it: any harness built on pi-durable can open its storage with it.
295
+ */
296
+ type PiSessionStoreOptions = {
297
+ /**
298
+ * Prefix for every table and index pi creates. Must not start with `_cf_`,
299
+ * which Durable Objects reserve. Default `pi_`.
300
+ */
301
+ readonly prefix?: string;
313
302
  };
303
+ /** Open pi-durable's storage over this object's SQLite database. */
304
+ declare function openPiSessionStore(
305
+ storage: DurableObjectStorage,
306
+ options?: PiSessionStoreOptions
307
+ ): Promise<SqliteStorage>;
308
+ //#endregion
309
+ //#region src/harness/pi/skills.d.ts
314
310
  /**
315
- * Register `agents/skills` sources on a pi registry: the activation tools
316
- * and a "skills" system prompt section. Resolution reads the sources, so a
317
- * host awaits this in its `harness` factory, before `Harness.open`.
311
+ * `agents/skills` sources as a pi extension, named `agents.skills`: the
312
+ * activation tools and a `skills` system prompt section. Install it on
313
+ * pi's registry in the harness factory.
314
+ *
315
+ * ```ts
316
+ * registry.install(await skills(sources));
317
+ * ```
318
318
  */
319
- declare function addSkills(
320
- registry: Registry,
321
- sources: readonly SkillSource[]
322
- ): Promise<ResolvedSkills>;
319
+ declare function skills(sources: readonly SkillSource[]): Promise<Extension>;
323
320
  //#endregion
324
321
  export {
325
322
  PiHarness,
326
323
  type PiHarnessContext,
327
324
  type PiHarnessFactory,
328
325
  type PiHarnessOptions,
326
+ type PiModel,
329
327
  type PiOperationResult,
330
328
  type PiPendingOperation,
331
329
  type PiPromptResponse,
@@ -338,11 +336,9 @@ export {
338
336
  type PiSessionStoreOptions,
339
337
  PiSessions,
340
338
  type PiSubmitOptions,
341
- type PiWakeTiming,
342
339
  type PiWhenBusy,
343
340
  ROOT_SESSION,
344
- type ResolvedSkills,
345
- addSkills,
346
- openPiSessionStore
341
+ openPiSessionStore,
342
+ skills
347
343
  };
348
344
  //# sourceMappingURL=index.d.ts.map