agents 0.10.0 → 0.10.1

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.
@@ -1,250 +1,6 @@
1
- import { r as CompactResult } from "../../../compaction-helpers-CHNQeyRm.js";
2
- import { ToolSet, UIMessage } from "ai";
1
+ import { A as SessionOptions, C as AgentSessionProvider, D as StoredCompaction, E as SessionProvider, O as SessionMessage, S as isSearchProvider, T as SearchResult, _ as R2SkillProvider, b as AgentSearchProvider, f as ContextBlock, g as isWritableProvider, h as WritableContextProvider, k as SessionMessagePart, m as ContextProvider, p as ContextConfig, r as CompactResult, v as SkillProvider, w as SqlProvider, x as SearchProvider, y as isSkillProvider } from "../../../compaction-helpers-BdQbZiML.js";
2
+ import { ToolSet } from "ai";
3
3
 
4
- //#region src/experimental/memory/session/provider.d.ts
5
- interface SearchResult {
6
- id: string;
7
- role: string;
8
- content: string;
9
- createdAt?: string;
10
- sessionId?: string;
11
- }
12
- interface StoredCompaction {
13
- id: string;
14
- summary: string;
15
- fromMessageId: string;
16
- toMessageId: string;
17
- createdAt: string;
18
- }
19
- /**
20
- * Session storage provider.
21
- * Messages are tree-structured via parentId for branching.
22
- */
23
- interface SessionProvider {
24
- getMessage(id: string): UIMessage | null;
25
- /**
26
- * Get conversation as a path from root to leaf.
27
- * Applies compaction overlays. If leafId is null, uses the latest leaf.
28
- */
29
- getHistory(leafId?: string | null): UIMessage[];
30
- getLatestLeaf(): UIMessage | null;
31
- getBranches(messageId: string): UIMessage[];
32
- getPathLength(leafId?: string | null): number;
33
- /**
34
- * Append a message. Parented to the latest leaf unless parentId is provided.
35
- * Idempotent — same message.id twice is a no-op.
36
- */
37
- appendMessage(message: UIMessage, parentId?: string | null): void;
38
- updateMessage(message: UIMessage): void;
39
- deleteMessages(messageIds: string[]): void;
40
- clearMessages(): void;
41
- addCompaction(summary: string, fromMessageId: string, toMessageId: string): StoredCompaction;
42
- getCompactions(): StoredCompaction[];
43
- searchMessages?(query: string, limit?: number): SearchResult[];
44
- }
45
- //#endregion
46
- //#region src/experimental/memory/session/providers/agent.d.ts
47
- interface SqlProvider {
48
- sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
49
- }
50
- declare class AgentSessionProvider implements SessionProvider {
51
- private agent;
52
- private initialized;
53
- private sessionId;
54
- /**
55
- * @param agent - Agent or any object with a `sql` tagged template method
56
- * @param sessionId - Optional session ID to isolate multiple sessions in the same DO.
57
- * Messages are filtered by session_id within shared tables.
58
- */
59
- constructor(agent: SqlProvider, sessionId?: string);
60
- private ensureTable;
61
- getMessage(id: string): UIMessage | null;
62
- getHistory(leafId?: string | null): UIMessage[];
63
- getLatestLeaf(): UIMessage | null;
64
- getBranches(messageId: string): UIMessage[];
65
- getPathLength(leafId?: string | null): number;
66
- appendMessage(message: UIMessage, parentId?: string | null): void;
67
- updateMessage(message: UIMessage): void;
68
- deleteMessages(messageIds: string[]): void;
69
- clearMessages(): void;
70
- addCompaction(summary: string, fromMessageId: string, toMessageId: string): StoredCompaction;
71
- getCompactions(): StoredCompaction[];
72
- searchMessages(query: string, limit?: number): SearchResult[];
73
- private latestLeafRow;
74
- private indexFTS;
75
- private deleteFTS;
76
- private applyCompactions;
77
- private parse;
78
- private parseRows;
79
- }
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
248
4
  //#region src/experimental/memory/session/session.d.ts
249
5
  type SessionContextOptions = Omit<ContextConfig, "label">;
250
6
  declare class Session {
@@ -286,23 +42,34 @@ declare class Session {
286
42
  * Register a compaction function. Called by `compact()` to compress
287
43
  * message history into a summary overlay.
288
44
  */
289
- onCompaction(fn: (messages: UIMessage[]) => Promise<CompactResult | null>): this;
45
+ onCompaction(fn: (messages: SessionMessage[]) => Promise<CompactResult | null>): this;
290
46
  /**
291
47
  * Auto-compact when estimated token count exceeds the threshold.
292
48
  * Checked after each `appendMessage`. Requires `onCompaction()`.
293
49
  */
294
50
  compactAfter(tokenThreshold: number): this;
295
51
  private _ensureReady;
296
- getHistory(leafId?: string | null): UIMessage[];
297
- getMessage(id: string): UIMessage | null;
298
- getLatestLeaf(): UIMessage | null;
299
- getBranches(messageId: string): UIMessage[];
52
+ /**
53
+ * Reconstruct which skills are loaded by scanning conversation history
54
+ * for load_context tool results that haven't been unloaded.
55
+ * Called during init to survive hibernation/eviction.
56
+ */
57
+ private _restoreLoadedSkills;
58
+ /**
59
+ * Replace a load_context tool result in conversation history
60
+ * with a short marker to reclaim context space.
61
+ */
62
+ private _reclaimLoadedSkill;
63
+ getHistory(leafId?: string | null): SessionMessage[];
64
+ getMessage(id: string): SessionMessage | null;
65
+ getLatestLeaf(): SessionMessage | null;
66
+ getBranches(messageId: string): SessionMessage[];
300
67
  getPathLength(leafId?: string | null): number;
301
68
  private _broadcast;
302
69
  private _emitStatus;
303
70
  private _emitError;
304
- appendMessage(message: UIMessage, parentId?: string | null): Promise<void>;
305
- updateMessage(message: UIMessage): void;
71
+ appendMessage(message: SessionMessage, parentId?: string | null): Promise<void>;
72
+ updateMessage(message: SessionMessage): void;
306
73
  deleteMessages(messageIds: string[]): void;
307
74
  clearMessages(): void;
308
75
  addCompaction(summary: string, fromMessageId: string, toMessageId: string): StoredCompaction;
@@ -316,6 +83,37 @@ declare class Session {
316
83
  getContextBlocks(): ContextBlock[];
317
84
  replaceContextBlock(label: string, content: string): Promise<ContextBlock>;
318
85
  appendContextBlock(label: string, content: string): Promise<ContextBlock>;
86
+ /**
87
+ * Dynamically register a new context block after session initialization.
88
+ * Used by extensions to contribute context blocks at runtime.
89
+ *
90
+ * The block's provider is initialized and loaded immediately.
91
+ * Call `refreshSystemPrompt()` afterward to include the new block
92
+ * in the system prompt.
93
+ *
94
+ * Note: When called without a provider, auto-wires to SQLite via
95
+ * AgentContextProvider. Requires the session to have been created
96
+ * via `Session.create(agent)` (not the direct constructor).
97
+ */
98
+ addContext(label: string, options?: SessionContextOptions): Promise<ContextBlock>;
99
+ /**
100
+ * Remove a dynamically registered context block.
101
+ * Used during extension unload cleanup.
102
+ *
103
+ * Returns true if the block existed and was removed.
104
+ * Call `refreshSystemPrompt()` afterward to rebuild the prompt
105
+ * without the removed block.
106
+ */
107
+ removeContext(label: string): boolean;
108
+ /**
109
+ * Unload a previously loaded skill, reclaiming context space.
110
+ * The tool result in conversation history is replaced with a short marker.
111
+ */
112
+ unloadSkill(label: string, key: string): boolean;
113
+ /**
114
+ * Get currently loaded skill keys (as "label:key" strings).
115
+ */
116
+ getLoadedSkillKeys(): Set<string>;
319
117
  freezeSystemPrompt(): Promise<string>;
320
118
  refreshSystemPrompt(): Promise<string>;
321
119
  search(query: string, options?: {
@@ -344,12 +142,9 @@ interface SessionInfo {
344
142
  created_at: string;
345
143
  updated_at: string;
346
144
  }
347
- interface SessionManagerOptions {
348
- maxContextMessages?: number;
349
- }
145
+ interface SessionManagerOptions {}
350
146
  declare class SessionManager {
351
147
  private agent;
352
- private _maxContextMessages;
353
148
  private _pending;
354
149
  private _cachedPrompt?;
355
150
  private _compactionFn?;
@@ -358,7 +153,7 @@ declare class SessionManager {
358
153
  private _historyLabel?;
359
154
  private _tableReady;
360
155
  private _ready;
361
- constructor(agent: SqlProvider, options?: SessionManagerOptions);
156
+ constructor(agent: SqlProvider, _options?: SessionManagerOptions);
362
157
  /**
363
158
  * Chainable SessionManager creation with auto-wired context for all sessions.
364
159
  *
@@ -368,7 +163,7 @@ declare class SessionManager {
368
163
  * .withContext("soul", { provider: { get: async () => "You are helpful." } })
369
164
  * .withContext("memory", { description: "Learned facts", maxTokens: 1100 })
370
165
  * .withCachedPrompt()
371
- * .maxContextMessages(50);
166
+ * .compactAfter(100_000);
372
167
  *
373
168
  * // Each getSession(id) auto-creates namespaced providers:
374
169
  * // memory key: "memory_<sessionId>"
@@ -379,12 +174,11 @@ declare class SessionManager {
379
174
  static create(agent: SqlProvider): SessionManager;
380
175
  withContext(label: string, options?: SessionContextOptions): this;
381
176
  withCachedPrompt(provider?: WritableContextProvider): this;
382
- maxContextMessages(count: number): this;
383
177
  /**
384
178
  * Register a compaction function propagated to all sessions.
385
179
  * Called by `Session.compact()` to compress message history.
386
180
  */
387
- onCompaction(fn: (messages: UIMessage[]) => Promise<CompactResult | null>): this;
181
+ onCompaction(fn: (messages: SessionMessage[]) => Promise<CompactResult | null>): this;
388
182
  /**
389
183
  * Auto-compact when estimated token count exceeds the threshold.
390
184
  * Propagated to all sessions. Requires `onCompaction()`.
@@ -420,20 +214,19 @@ declare class SessionManager {
420
214
  list(): SessionInfo[];
421
215
  delete(sessionId: string): void;
422
216
  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[];
217
+ append(sessionId: string, message: SessionMessage, parentId?: string): Promise<string>;
218
+ upsert(sessionId: string, message: SessionMessage, parentId?: string): Promise<string>;
219
+ appendAll(sessionId: string, messages: SessionMessage[], parentId?: string): Promise<string | null>;
220
+ getHistory(sessionId: string, leafId?: string): SessionMessage[];
427
221
  getMessageCount(sessionId: string): number;
428
222
  clearMessages(sessionId: string): void;
429
223
  deleteMessages(sessionId: string, messageIds: string[]): void;
430
- getBranches(sessionId: string, messageId: string): UIMessage[];
224
+ getBranches(sessionId: string, messageId: string): SessionMessage[];
431
225
  /**
432
226
  * Fork a session at a specific message, creating a new session
433
227
  * with the history up to that point copied over.
434
228
  */
435
229
  fork(sessionId: string, atMessageId: string, newName: string): Promise<SessionInfo>;
436
- needsCompaction(sessionId: string): boolean;
437
230
  addCompaction(sessionId: string, summary: string, fromId: string, toId: string): StoredCompaction;
438
231
  getCompactions(sessionId: string): StoredCompaction[];
439
232
  compactAndSplit(sessionId: string, summary: string, newName?: string): Promise<SessionInfo>;
@@ -462,5 +255,5 @@ declare class AgentContextProvider implements WritableContextProvider {
462
255
  set(content: string): Promise<void>;
463
256
  }
464
257
  //#endregion
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 };
258
+ export { AgentContextProvider, AgentSearchProvider, AgentSessionProvider, type ContextBlock, type ContextConfig, type ContextProvider, R2SkillProvider, type SearchProvider, type SearchResult, Session, type SessionContextOptions, type SessionInfo, SessionManager, type SessionManagerOptions, type SessionMessage, type SessionMessagePart, type SessionOptions, type SessionProvider, type SkillProvider, type SqlProvider, type StoredCompaction, type WritableContextProvider, isSearchProvider, isSkillProvider, isWritableProvider };
466
259
  //# sourceMappingURL=index.d.ts.map