agents 0.8.7 → 0.10.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.
Files changed (50) hide show
  1. package/dist/chat/index.d.ts +603 -0
  2. package/dist/chat/index.js +1285 -0
  3. package/dist/chat/index.js.map +1 -0
  4. package/dist/{client-BwgM3cRz.js → client-QBjFV5de.js} +161 -49
  5. package/dist/client-QBjFV5de.js.map +1 -0
  6. package/dist/client.d.ts +2 -2
  7. package/dist/{compaction-helpers-BFTBIzpK.js → compaction-helpers-BPE1_ziA.js} +1 -1
  8. package/dist/{compaction-helpers-BFTBIzpK.js.map → compaction-helpers-BPE1_ziA.js.map} +1 -1
  9. package/dist/{compaction-helpers-DkJreaDR.d.ts → compaction-helpers-CHNQeyRm.d.ts} +1 -1
  10. package/dist/{do-oauth-client-provider-C2jurFjW.d.ts → do-oauth-client-provider-31gqR33H.d.ts} +1 -1
  11. package/dist/{email-DwPlM0bQ.d.ts → email-Cql45SKP.d.ts} +1 -1
  12. package/dist/email.d.ts +2 -2
  13. package/dist/experimental/memory/session/index.d.ts +298 -73
  14. package/dist/experimental/memory/session/index.js +754 -66
  15. package/dist/experimental/memory/session/index.js.map +1 -1
  16. package/dist/experimental/memory/utils/index.d.ts +1 -1
  17. package/dist/experimental/memory/utils/index.js +1 -1
  18. package/dist/{index-C-6EMK-E.d.ts → index-BPkkIqMn.d.ts} +209 -76
  19. package/dist/{index-Ua2Nfvbm.d.ts → index-DDSX-g7W.d.ts} +11 -1
  20. package/dist/index.d.ts +30 -26
  21. package/dist/index.js +2 -3049
  22. package/dist/{internal_context-DT8RxmAN.d.ts → internal_context-DuQZFvWI.d.ts} +1 -1
  23. package/dist/internal_context.d.ts +1 -1
  24. package/dist/mcp/client.d.ts +2 -2
  25. package/dist/mcp/client.js +1 -1
  26. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  27. package/dist/mcp/index.d.ts +1 -1
  28. package/dist/mcp/index.js +2 -2
  29. package/dist/observability/index.d.ts +1 -1
  30. package/dist/react.d.ts +3 -1
  31. package/dist/react.js +3 -0
  32. package/dist/react.js.map +1 -1
  33. package/dist/{retries-DXMQGhG3.d.ts → retries-B_CN5KM9.d.ts} +1 -1
  34. package/dist/retries.d.ts +1 -1
  35. package/dist/{serializable-8Jt1B04R.d.ts → serializable-DGdO8CDh.d.ts} +1 -1
  36. package/dist/serializable.d.ts +1 -1
  37. package/dist/src-B8NZxxsO.js +3217 -0
  38. package/dist/src-B8NZxxsO.js.map +1 -0
  39. package/dist/{types-C-m0II8i.d.ts → types-B9A8AU7B.d.ts} +1 -1
  40. package/dist/types.d.ts +1 -1
  41. package/dist/{workflow-types-CZNXKj_D.d.ts → workflow-types-XmOkuI7A.d.ts} +1 -1
  42. package/dist/workflow-types.d.ts +1 -1
  43. package/dist/workflows.d.ts +2 -2
  44. package/dist/workflows.js +1 -1
  45. package/package.json +20 -18
  46. package/dist/client-BwgM3cRz.js.map +0 -1
  47. package/dist/experimental/forever.d.ts +0 -64
  48. package/dist/experimental/forever.js +0 -338
  49. package/dist/experimental/forever.js.map +0 -1
  50. package/dist/index.js.map +0 -1
@@ -1,66 +1,6 @@
1
- import { r as CompactResult } from "../../../compaction-helpers-DkJreaDR.js";
1
+ import { r as CompactResult } from "../../../compaction-helpers-CHNQeyRm.js";
2
2
  import { ToolSet, UIMessage } from "ai";
3
3
 
4
- //#region src/experimental/memory/session/context.d.ts
5
- /**
6
- * Storage interface for a single context block.
7
- * Each block can have its own backing store (R2, SQLite, KV, in-memory, etc.)
8
- * If `set` is omitted, the block is readonly.
9
- */
10
- interface ContextProvider {
11
- get(): Promise<string | null>;
12
- set?(content: string): Promise<void>;
13
- }
14
- /**
15
- * Configuration for a context block.
16
- */
17
- interface ContextConfig {
18
- /** Block label — used as key and in tool descriptions */
19
- label: string;
20
- /** Human-readable description (shown to AI in tool) */
21
- description?: string;
22
- /** Initial content — used when provider returns null or is absent */
23
- initialContent?: string;
24
- /** Maximum tokens allowed. Enforced on set. */
25
- maxTokens?: number;
26
- /** If true, AI cannot modify this block via tools */
27
- readonly?: boolean;
28
- /** Storage provider. If omitted, auto-wired to SQLite when using builder. */
29
- provider?: ContextProvider;
30
- }
31
- /**
32
- * A loaded context block with computed token count.
33
- */
34
- interface ContextBlock {
35
- label: string;
36
- description?: string;
37
- content: string;
38
- tokens: number;
39
- maxTokens?: number;
40
- readonly?: boolean;
41
- }
42
- //#endregion
43
- //#region src/experimental/memory/session/types.d.ts
44
- /**
45
- * Options for querying messages
46
- */
47
- interface MessageQueryOptions {
48
- limit?: number;
49
- offset?: number;
50
- before?: Date;
51
- after?: Date;
52
- role?: "user" | "assistant" | "system";
53
- }
54
- /**
55
- * Options for creating a Session.
56
- */
57
- interface SessionOptions {
58
- /** Context blocks for the system prompt. */
59
- context?: ContextConfig[];
60
- /** Provider for persisting the frozen system prompt. */
61
- promptStore?: ContextProvider;
62
- }
63
- //#endregion
64
4
  //#region src/experimental/memory/session/provider.d.ts
65
5
  interface SearchResult {
66
6
  id: string;
@@ -138,6 +78,173 @@ declare class AgentSessionProvider implements SessionProvider {
138
78
  private parseRows;
139
79
  }
140
80
  //#endregion
81
+ //#region src/experimental/memory/session/search.d.ts
82
+ /**
83
+ * Storage interface for searchable context.
84
+ *
85
+ * - `get()` returns a summary of indexed content (rendered into system prompt)
86
+ * - `search(query)` full-text search (via search_context tool)
87
+ * - `set(key, content)` indexes content under a key (via set_context tool)
88
+ */
89
+ interface SearchProvider extends ContextProvider {
90
+ search(query: string): Promise<string | null>;
91
+ set?(key: string, content: string): Promise<void>;
92
+ }
93
+ /**
94
+ * Check if a provider is a SearchProvider (has a `search` method).
95
+ */
96
+ declare function isSearchProvider(provider: unknown): provider is SearchProvider;
97
+ /**
98
+ * SearchProvider backed by Durable Object SQLite with FTS5.
99
+ *
100
+ * - `get()` returns a count of indexed entries
101
+ * - `search(query)` full-text search using FTS5
102
+ * - `set(key, content)` indexes or replaces content under a key
103
+ *
104
+ * Each instance uses a namespaced FTS5 table to avoid collisions
105
+ * with the session message search.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * Session.create(this)
110
+ * .withContext("knowledge", {
111
+ * provider: new AgentSearchProvider(this)
112
+ * })
113
+ * ```
114
+ */
115
+ declare class AgentSearchProvider implements SearchProvider {
116
+ private agent;
117
+ private label;
118
+ private initialized;
119
+ constructor(agent: SqlProvider);
120
+ init(label: string): void;
121
+ private ensureTable;
122
+ get(): Promise<string | null>;
123
+ search(query: string): Promise<string | null>;
124
+ set(key: string, content: string): Promise<void>;
125
+ private deleteFTS;
126
+ }
127
+ //#endregion
128
+ //#region src/experimental/memory/session/skills.d.ts
129
+ /**
130
+ * Storage interface for skill collections.
131
+ *
132
+ * - `get()` returns metadata listing (rendered into system prompt)
133
+ * - `load(key)` fetches full content (via load_context tool)
134
+ * - `set(key, content, description?)` writes an entry (via set_context tool)
135
+ */
136
+ interface SkillProvider extends ContextProvider {
137
+ load(key: string): Promise<string | null>;
138
+ set?(key: string, content: string, description?: string): Promise<void>;
139
+ }
140
+ /**
141
+ * Check if a provider is a SkillProvider (has a `load` method).
142
+ */
143
+ declare function isSkillProvider(provider: unknown): provider is SkillProvider;
144
+ /**
145
+ * SkillProvider backed by an R2 bucket.
146
+ *
147
+ * - `get()` returns a metadata listing of all skills (key + description)
148
+ * - `load(key)` fetches a skill's full content
149
+ * - `set(key, content, description?)` writes a skill
150
+ *
151
+ * Descriptions are pulled from R2 custom metadata (`description` key).
152
+ * If a prefix is provided, it is prepended on storage operations and
153
+ * stripped from keys in metadata.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * const skills = new R2SkillProvider(env.SKILLS_BUCKET, { prefix: "skills/" });
158
+ * ```
159
+ */
160
+ declare class R2SkillProvider implements SkillProvider {
161
+ private bucket;
162
+ private prefix;
163
+ constructor(bucket: R2Bucket, options?: {
164
+ prefix?: string;
165
+ });
166
+ get(): Promise<string | null>;
167
+ load(key: string): Promise<string | null>;
168
+ set(key: string, content: string, description?: string): Promise<void>;
169
+ }
170
+ //#endregion
171
+ //#region src/experimental/memory/session/context.d.ts
172
+ /**
173
+ * Base storage interface for a context block.
174
+ * A provider with only `get()` is readonly.
175
+ */
176
+ interface ContextProvider {
177
+ get(): Promise<string | null>;
178
+ /** Called by the context system to provide the block label before first use. */
179
+ init?(label: string): void;
180
+ }
181
+ /**
182
+ * Writable context provider — extends ContextProvider with `set()`.
183
+ * Blocks backed by this provider are writable via the `set_context` tool.
184
+ */
185
+ interface WritableContextProvider extends ContextProvider {
186
+ set(content: string): Promise<void>;
187
+ }
188
+ /**
189
+ * Check if a provider is writable (has a `set` method).
190
+ */
191
+ declare function isWritableProvider(provider: unknown): provider is WritableContextProvider;
192
+ /**
193
+ * Configuration for a context block.
194
+ */
195
+ interface ContextConfig {
196
+ /** Block label — used as key and in tool descriptions */
197
+ label: string;
198
+ /** Human-readable description (shown to AI in tool) */
199
+ description?: string;
200
+ /** Maximum tokens allowed. Enforced on set. */
201
+ maxTokens?: number;
202
+ /** Storage provider. Determines block behavior:
203
+ * - ContextProvider (get only) → readonly
204
+ * - WritableContextProvider (get+set) → writable via set_context
205
+ * - SkillProvider (get+load+set?) → on-demand via load_context
206
+ * - SearchProvider (get+search+set?) → searchable via search_context
207
+ * If omitted, auto-wired to writable SQLite when using builder. */
208
+ provider?: ContextProvider | WritableContextProvider | SkillProvider | SearchProvider;
209
+ }
210
+ /**
211
+ * A loaded context block with computed token count.
212
+ */
213
+ interface ContextBlock {
214
+ label: string;
215
+ description?: string;
216
+ content: string;
217
+ tokens: number;
218
+ maxTokens?: number;
219
+ /** True if provider is writable (has set) */
220
+ writable: boolean;
221
+ /** True if backed by a SkillProvider */
222
+ isSkill: boolean;
223
+ /** True if backed by a SearchProvider */
224
+ isSearchable: boolean;
225
+ }
226
+ //#endregion
227
+ //#region src/experimental/memory/session/types.d.ts
228
+ /**
229
+ * Options for querying messages
230
+ */
231
+ interface MessageQueryOptions {
232
+ limit?: number;
233
+ offset?: number;
234
+ before?: Date;
235
+ after?: Date;
236
+ role?: "user" | "assistant" | "system";
237
+ }
238
+ /**
239
+ * Options for creating a Session.
240
+ */
241
+ interface SessionOptions {
242
+ /** Context blocks for the system prompt. */
243
+ context?: ContextConfig[];
244
+ /** Provider for persisting the frozen system prompt. */
245
+ promptStore?: WritableContextProvider;
246
+ }
247
+ //#endregion
141
248
  //#region src/experimental/memory/session/session.d.ts
142
249
  type SessionContextOptions = Omit<ContextConfig, "label">;
143
250
  declare class Session {
@@ -159,17 +266,14 @@ declare class Session {
159
266
  * @example
160
267
  * ```ts
161
268
  * const session = Session.create(this)
162
- * .withContext("soul", { initialContent: "You are helpful.", readonly: true })
269
+ * .withContext("soul", { provider: { get: async () => "You are helpful." } })
163
270
  * .withContext("memory", { description: "Learned facts", maxTokens: 1100 })
164
271
  * .withCachedPrompt();
165
272
  *
166
- * // Custom storage (R2, KV, etc.)
273
+ * // Skills from R2 (on-demand loading via load_context tool)
167
274
  * const session = Session.create(this)
168
- * .withContext("workspace", {
169
- * provider: {
170
- * get: () => env.BUCKET.get("ws.md").then(o => o?.text() ?? null),
171
- * set: (c) => env.BUCKET.put("ws.md", c),
172
- * }
275
+ * .withContext("skills", {
276
+ * provider: new R2SkillProvider(env.SKILLS_BUCKET, { prefix: "skills/" })
173
277
  * })
174
278
  * .withCachedPrompt();
175
279
  * ```
@@ -177,7 +281,7 @@ declare class Session {
177
281
  static create(agent: SqlProvider): Session;
178
282
  forSession(sessionId: string): this;
179
283
  withContext(label: string, options?: SessionContextOptions): this;
180
- withCachedPrompt(provider?: ContextProvider): this;
284
+ withCachedPrompt(provider?: WritableContextProvider): this;
181
285
  /**
182
286
  * Register a compaction function. Called by `compact()` to compress
183
287
  * message history into a summary overlay.
@@ -222,20 +326,141 @@ declare class Session {
222
326
  content: string;
223
327
  createdAt?: string;
224
328
  }>;
225
- /** Returns update_context tool for writing to context blocks. */
329
+ /** Returns set_context and load_context tools. */
226
330
  tools(): Promise<ToolSet>;
227
331
  }
228
332
  //#endregion
333
+ //#region src/experimental/memory/session/manager.d.ts
334
+ interface SessionInfo {
335
+ id: string;
336
+ name: string;
337
+ parent_session_id: string | null;
338
+ model: string | null;
339
+ source: string | null;
340
+ input_tokens: number;
341
+ output_tokens: number;
342
+ estimated_cost: number;
343
+ end_reason: string | null;
344
+ created_at: string;
345
+ updated_at: string;
346
+ }
347
+ interface SessionManagerOptions {
348
+ maxContextMessages?: number;
349
+ }
350
+ declare class SessionManager {
351
+ private agent;
352
+ private _maxContextMessages;
353
+ private _pending;
354
+ private _cachedPrompt?;
355
+ private _compactionFn?;
356
+ private _tokenThreshold?;
357
+ private _sessions;
358
+ private _historyLabel?;
359
+ private _tableReady;
360
+ private _ready;
361
+ constructor(agent: SqlProvider, options?: SessionManagerOptions);
362
+ /**
363
+ * Chainable SessionManager creation with auto-wired context for all sessions.
364
+ *
365
+ * @example
366
+ * ```ts
367
+ * const manager = SessionManager.create(this)
368
+ * .withContext("soul", { provider: { get: async () => "You are helpful." } })
369
+ * .withContext("memory", { description: "Learned facts", maxTokens: 1100 })
370
+ * .withCachedPrompt()
371
+ * .maxContextMessages(50);
372
+ *
373
+ * // Each getSession(id) auto-creates namespaced providers:
374
+ * // memory key: "memory_<sessionId>"
375
+ * // prompt key: "_system_prompt_<sessionId>"
376
+ * const session = manager.getSession("chat-123");
377
+ * ```
378
+ */
379
+ static create(agent: SqlProvider): SessionManager;
380
+ withContext(label: string, options?: SessionContextOptions): this;
381
+ withCachedPrompt(provider?: WritableContextProvider): this;
382
+ maxContextMessages(count: number): this;
383
+ /**
384
+ * Register a compaction function propagated to all sessions.
385
+ * Called by `Session.compact()` to compress message history.
386
+ */
387
+ onCompaction(fn: (messages: UIMessage[]) => Promise<CompactResult | null>): this;
388
+ /**
389
+ * Auto-compact when estimated token count exceeds the threshold.
390
+ * Propagated to all sessions. Requires `onCompaction()`.
391
+ */
392
+ compactAfter(tokenThreshold: number): this;
393
+ /**
394
+ * Add a searchable context block that searches conversation history
395
+ * across all sessions managed by this manager.
396
+ *
397
+ * The model can use `search_context` to find relevant messages from
398
+ * any session. The block is readonly (no `set`).
399
+ *
400
+ * @example
401
+ * ```ts
402
+ * SessionManager.create(this)
403
+ * .withContext("memory", { maxTokens: 1100 })
404
+ * .withSearchableHistory("history")
405
+ * .withCachedPrompt();
406
+ * ```
407
+ */
408
+ withSearchableHistory(label: string): this;
409
+ private _ensureReady;
410
+ private _ensureTable;
411
+ private _createHistoryProvider;
412
+ /** Get or create the Session instance for a session ID. */
413
+ getSession(sessionId: string): Session;
414
+ create(name: string, opts?: {
415
+ parentSessionId?: string;
416
+ model?: string;
417
+ source?: string;
418
+ }): SessionInfo;
419
+ get(sessionId: string): SessionInfo | null;
420
+ list(): SessionInfo[];
421
+ delete(sessionId: string): void;
422
+ rename(sessionId: string, name: string): void;
423
+ append(sessionId: string, message: UIMessage, parentId?: string): Promise<string>;
424
+ upsert(sessionId: string, message: UIMessage, parentId?: string): Promise<string>;
425
+ appendAll(sessionId: string, messages: UIMessage[], parentId?: string): Promise<string | null>;
426
+ getHistory(sessionId: string, leafId?: string): UIMessage[];
427
+ getMessageCount(sessionId: string): number;
428
+ clearMessages(sessionId: string): void;
429
+ deleteMessages(sessionId: string, messageIds: string[]): void;
430
+ getBranches(sessionId: string, messageId: string): UIMessage[];
431
+ /**
432
+ * Fork a session at a specific message, creating a new session
433
+ * with the history up to that point copied over.
434
+ */
435
+ fork(sessionId: string, atMessageId: string, newName: string): Promise<SessionInfo>;
436
+ needsCompaction(sessionId: string): boolean;
437
+ addCompaction(sessionId: string, summary: string, fromId: string, toId: string): StoredCompaction;
438
+ getCompactions(sessionId: string): StoredCompaction[];
439
+ compactAndSplit(sessionId: string, summary: string, newName?: string): Promise<SessionInfo>;
440
+ addUsage(sessionId: string, inputTokens: number, outputTokens: number, cost: number): void;
441
+ search(query: string, options?: {
442
+ limit?: number;
443
+ }): {
444
+ id: string;
445
+ role: string;
446
+ content: string;
447
+ createdAt: string;
448
+ }[];
449
+ tools(): ToolSet;
450
+ private _touch;
451
+ }
452
+ //#endregion
229
453
  //#region src/experimental/memory/session/providers/agent-context.d.ts
230
- declare class AgentContextProvider implements ContextProvider {
454
+ declare class AgentContextProvider implements WritableContextProvider {
231
455
  private agent;
232
456
  private label;
233
457
  private initialized;
234
- constructor(agent: SqlProvider, label: string);
458
+ constructor(agent: SqlProvider, label?: string);
459
+ init(label: string): void;
235
460
  private ensureTable;
236
461
  get(): Promise<string | null>;
237
462
  set(content: string): Promise<void>;
238
463
  }
239
464
  //#endregion
240
- export { AgentContextProvider, AgentSessionProvider, type ContextBlock, type ContextConfig, type MessageQueryOptions, type SearchResult, Session, type SessionContextOptions, type SessionOptions, type SessionProvider, type SqlProvider, type StoredCompaction };
465
+ export { AgentContextProvider, AgentSearchProvider, AgentSessionProvider, type ContextBlock, type ContextConfig, type ContextProvider, type MessageQueryOptions, R2SkillProvider, type SearchProvider, type SearchResult, Session, type SessionContextOptions, type SessionInfo, SessionManager, type SessionManagerOptions, type SessionOptions, type SessionProvider, type SkillProvider, type SqlProvider, type StoredCompaction, type WritableContextProvider, isSearchProvider, isSkillProvider, isWritableProvider };
241
466
  //# sourceMappingURL=index.d.ts.map