agents 0.12.3 → 0.13.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 +7 -7
- package/dist/{agent-tool-types-DSteYkkS.d.ts → agent-tool-types-BVgYyKO9.d.ts} +153 -102
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/agent-tools-BAdX1vdI.js.map +1 -1
- package/dist/{agent-tools-eGTCdVZX.d.ts → agent-tools-C-Ch8Thl.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/agent-tools.js.map +1 -1
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration.js.map +1 -1
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.js.map +1 -1
- package/dist/browser/ai.d.ts +2 -2
- package/dist/browser/ai.js +1 -1
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +41 -10
- package/dist/browser/index.js +1 -1
- package/dist/browser/tanstack-ai.d.ts +2 -2
- package/dist/browser/tanstack-ai.js +1 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/chat/index.d.ts +297 -148
- package/dist/chat/index.js +43 -14
- package/dist/chat/index.js.map +1 -1
- package/dist/{classPrivateFieldGet2-Bqby-AHD.js → classPrivateFieldGet2-Evpt0SEr.js} +5 -5
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/client-D1kFXo80.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js.map +1 -1
- package/dist/codemode/ai.d.ts +1 -1
- package/dist/codemode/ai.js.map +1 -1
- package/dist/{compaction-helpers-CzCq1-fF.d.ts → compaction-helpers-DAe-xiVY.d.ts} +42 -17
- package/dist/{compaction-helpers-CSaqCmdE.js → compaction-helpers-DvcZnvQ1.js} +1 -1
- package/dist/{compaction-helpers-CSaqCmdE.js.map → compaction-helpers-DvcZnvQ1.js.map} +1 -1
- package/dist/{do-oauth-client-provider-C38aWbFV.d.ts → do-oauth-client-provider-4OKQU9rT.d.ts} +1 -1
- package/dist/{email-X72-zjuq.d.ts → email-J0GGS3sa.d.ts} +1 -1
- package/dist/email.d.ts +3 -3
- package/dist/email.js.map +1 -1
- package/dist/experimental/memory/session/index.d.ts +369 -56
- package/dist/experimental/memory/session/index.js +553 -138
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/experimental/memory/utils/index.d.ts +41 -5
- package/dist/experimental/memory/utils/index.js +15 -5
- package/dist/experimental/memory/utils/index.js.map +1 -1
- package/dist/experimental/webmcp.d.ts +9 -3
- package/dist/experimental/webmcp.js.map +1 -1
- package/dist/{index-Biv6K70p.d.ts → index-DKey3P4s.d.ts} +26 -2
- package/dist/index.d.ts +71 -67
- package/dist/index.js +211 -108
- package/dist/index.js.map +1 -1
- package/dist/{internal_context-BvuGZieY.d.ts → internal_context-BZrMS0B5.d.ts} +1 -1
- package/dist/internal_context.d.ts +1 -1
- package/dist/internal_context.js.map +1 -1
- package/dist/mcp/client.d.ts +26 -2
- package/dist/mcp/do-oauth-client-provider.d.ts +10 -2
- package/dist/mcp/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/index.d.ts +54 -2
- package/dist/mcp/index.js +2 -2
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/x402.d.ts +74 -17
- package/dist/mcp/x402.js.map +1 -1
- package/dist/observability/index.d.ts +16 -2
- package/dist/observability/index.js +1 -1
- package/dist/observability/index.js.map +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/react.js.map +1 -1
- package/dist/{retries-fLD8cGNf.d.ts → retries-BVdRl5ZE.d.ts} +1 -1
- package/dist/retries.d.ts +1 -1
- package/dist/retries.js.map +1 -1
- package/dist/schedule.js.map +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/{shared-C6l4ZKRN.js → shared-CiKaIK4h.js} +4 -5
- package/dist/{shared-C6l4ZKRN.js.map → shared-CiKaIK4h.js.map} +1 -1
- package/dist/{shared-Ch9slKdI.d.ts → shared-Cvj92byG.d.ts} +1 -1
- package/dist/sub-routing.d.ts +6 -6
- package/dist/sub-routing.js.map +1 -1
- package/dist/tool-output-truncation-CH-khbZ3.js +98 -0
- package/dist/tool-output-truncation-CH-khbZ3.js.map +1 -0
- package/dist/{types-DAHCZC_W.d.ts → types-_JjKmv-l.d.ts} +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.js.map +1 -1
- package/dist/vite.js.map +1 -1
- package/dist/{workflow-types-DHs0L0KP.d.ts → workflow-types-Dkzg4hAx.d.ts} +1 -1
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflow-types.js.map +1 -1
- package/dist/workflows.d.ts +2 -2
- package/dist/workflows.js.map +1 -1
- package/package.json +11 -11
|
@@ -1,26 +1,74 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
A as SessionOptions,
|
|
3
|
+
C as AgentSessionProvider,
|
|
4
|
+
D as StoredCompaction,
|
|
5
|
+
E as SessionProvider,
|
|
6
|
+
O as SessionMessage,
|
|
7
|
+
S as isSearchProvider,
|
|
8
|
+
T as SearchResult,
|
|
9
|
+
_ as R2SkillProvider,
|
|
10
|
+
b as AgentSearchProvider,
|
|
11
|
+
f as ContextBlock,
|
|
12
|
+
g as isWritableProvider,
|
|
13
|
+
h as WritableContextProvider,
|
|
14
|
+
k as SessionMessagePart,
|
|
15
|
+
m as ContextProvider,
|
|
16
|
+
p as ContextConfig,
|
|
17
|
+
r as CompactResult,
|
|
18
|
+
v as SkillProvider,
|
|
19
|
+
w as SqlProvider,
|
|
20
|
+
x as SearchProvider,
|
|
21
|
+
y as isSkillProvider
|
|
22
|
+
} from "../../../compaction-helpers-DAe-xiVY.js";
|
|
2
23
|
import { ToolSet } from "ai";
|
|
3
24
|
|
|
4
25
|
//#region src/experimental/memory/session/session.d.ts
|
|
5
26
|
type SessionContextOptions = Omit<ContextConfig, "label">;
|
|
27
|
+
type InternalMessageChangeEvent =
|
|
28
|
+
| {
|
|
29
|
+
type: "append";
|
|
30
|
+
message: SessionMessage;
|
|
31
|
+
parentId?: string | null;
|
|
32
|
+
inserted: boolean;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
type: "update";
|
|
36
|
+
message: SessionMessage;
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
type: "delete";
|
|
40
|
+
messageIds: string[];
|
|
41
|
+
}
|
|
42
|
+
| {
|
|
43
|
+
type: "clear";
|
|
44
|
+
}
|
|
45
|
+
| {
|
|
46
|
+
type: "compact";
|
|
47
|
+
};
|
|
6
48
|
declare class Session {
|
|
7
49
|
private storage;
|
|
8
50
|
private context;
|
|
9
51
|
private _agent?;
|
|
10
52
|
private _broadcaster?;
|
|
53
|
+
private _storageProvider?;
|
|
11
54
|
private _sessionId?;
|
|
12
55
|
private _pending?;
|
|
13
56
|
private _cachedPrompt?;
|
|
14
57
|
private _compactionFn?;
|
|
15
58
|
private _tokenThreshold?;
|
|
16
59
|
private _ready;
|
|
60
|
+
private _restorePromise?;
|
|
61
|
+
private _messageChangeListener?;
|
|
17
62
|
constructor(storage: SessionProvider, options?: SessionOptions);
|
|
18
63
|
/**
|
|
19
|
-
* Chainable session creation with auto-wired
|
|
20
|
-
*
|
|
64
|
+
* Chainable session creation with auto-wired providers.
|
|
65
|
+
*
|
|
66
|
+
* Pass a `SqlProvider` (Agent with `sql` method) for auto-wired SQLite,
|
|
67
|
+
* or a `SessionProvider` directly for custom storage (Postgres, etc.).
|
|
21
68
|
*
|
|
22
69
|
* @example
|
|
23
70
|
* ```ts
|
|
71
|
+
* // Auto-wired SQLite (DO Agent)
|
|
24
72
|
* const session = Session.create(this)
|
|
25
73
|
* .withContext("soul", { provider: { get: async () => "You are helpful." } })
|
|
26
74
|
* .withContext("memory", { description: "Learned facts", maxTokens: 1100 })
|
|
@@ -32,9 +80,17 @@ declare class Session {
|
|
|
32
80
|
* provider: new R2SkillProvider(env.SKILLS_BUCKET, { prefix: "skills/" })
|
|
33
81
|
* })
|
|
34
82
|
* .withCachedPrompt();
|
|
83
|
+
*
|
|
84
|
+
* // Custom storage provider (Postgres, etc.)
|
|
85
|
+
* const session = Session.create(postgresProvider)
|
|
86
|
+
* .withContext("memory", {
|
|
87
|
+
* maxTokens: 1100,
|
|
88
|
+
* provider: new PostgresContextProvider(conn, "memory")
|
|
89
|
+
* })
|
|
90
|
+
* .withCachedPrompt(new PostgresContextProvider(conn, "_prompt"));
|
|
35
91
|
* ```
|
|
36
92
|
*/
|
|
37
|
-
static create(
|
|
93
|
+
static create(provider: SqlProvider | SessionProvider): Session;
|
|
38
94
|
forSession(sessionId: string): this;
|
|
39
95
|
withContext(label: string, options?: SessionContextOptions): this;
|
|
40
96
|
withCachedPrompt(provider?: WritableContextProvider): this;
|
|
@@ -42,38 +98,77 @@ declare class Session {
|
|
|
42
98
|
* Register a compaction function. Called by `compact()` to compress
|
|
43
99
|
* message history into a summary overlay.
|
|
44
100
|
*/
|
|
45
|
-
onCompaction(
|
|
101
|
+
onCompaction(
|
|
102
|
+
fn: (messages: SessionMessage[]) => Promise<CompactResult | null>
|
|
103
|
+
): this;
|
|
46
104
|
/**
|
|
47
105
|
* Auto-compact when estimated token count exceeds the threshold.
|
|
48
106
|
* Checked after each `appendMessage`. Requires `onCompaction()`.
|
|
49
107
|
*/
|
|
50
108
|
compactAfter(tokenThreshold: number): this;
|
|
109
|
+
/**
|
|
110
|
+
* @internal
|
|
111
|
+
* Framework hook for cache-owning callers that need to mirror message
|
|
112
|
+
* storage changes. Application code should use the normal Session methods.
|
|
113
|
+
*/
|
|
114
|
+
internal_onMessagesChanged(
|
|
115
|
+
listener:
|
|
116
|
+
| ((event: InternalMessageChangeEvent) => void | Promise<void>)
|
|
117
|
+
| null
|
|
118
|
+
): this;
|
|
51
119
|
private _ensureReady;
|
|
120
|
+
/**
|
|
121
|
+
* Await the background skill-restore kicked off by `_ensureReady()`.
|
|
122
|
+
* Idempotent and cheap — every async public method calls this so that
|
|
123
|
+
* `_loadedSkills` reflects conversation history before any read or write.
|
|
124
|
+
*/
|
|
125
|
+
private _ensureRestored;
|
|
126
|
+
private _notifyMessagesChanged;
|
|
52
127
|
/**
|
|
53
128
|
* Reconstruct which skills are loaded by scanning conversation history
|
|
54
129
|
* for load_context tool results that haven't been unloaded.
|
|
55
|
-
*
|
|
130
|
+
* Runs once per init to survive hibernation / eviction, including for
|
|
131
|
+
* async SessionProviders (e.g. Postgres) where we must `await` history.
|
|
56
132
|
*/
|
|
57
133
|
private _restoreLoadedSkills;
|
|
58
134
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
135
|
+
* Reclaim context-window tokens consumed by a previously loaded skill.
|
|
136
|
+
*
|
|
137
|
+
* When a skill is loaded via the `load_context` tool, its full body is
|
|
138
|
+
* embedded as that tool call's `output-available` result inside the
|
|
139
|
+
* assistant message — which means every subsequent turn replays the
|
|
140
|
+
* entire skill as part of the conversation history and pays for it in
|
|
141
|
+
* input tokens.
|
|
142
|
+
*
|
|
143
|
+
* This method walks back through history, finds the matching
|
|
144
|
+
* `load_context` tool result for `(label, key)`, and replaces its bulky
|
|
145
|
+
* `output` with a short marker `[skill unloaded: <key>]`. The skill
|
|
146
|
+
* content is dropped from future turns and the tokens are reclaimed.
|
|
147
|
+
* The skill itself stays available to reload via `load_context`.
|
|
61
148
|
*/
|
|
62
149
|
private _reclaimLoadedSkill;
|
|
63
|
-
getHistory(leafId?: string | null): SessionMessage[]
|
|
64
|
-
getMessage(id: string): SessionMessage | null
|
|
65
|
-
getLatestLeaf(): SessionMessage | null
|
|
66
|
-
getBranches(messageId: string): SessionMessage[]
|
|
67
|
-
getPathLength(leafId?: string | null): number
|
|
150
|
+
getHistory(leafId?: string | null): Promise<SessionMessage[]>;
|
|
151
|
+
getMessage(id: string): Promise<SessionMessage | null>;
|
|
152
|
+
getLatestLeaf(): Promise<SessionMessage | null>;
|
|
153
|
+
getBranches(messageId: string): Promise<SessionMessage[]>;
|
|
154
|
+
getPathLength(leafId?: string | null): Promise<number>;
|
|
68
155
|
private _broadcast;
|
|
69
156
|
private _emitStatus;
|
|
70
157
|
private _emitError;
|
|
71
|
-
appendMessage(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
158
|
+
appendMessage(
|
|
159
|
+
message: SessionMessage,
|
|
160
|
+
parentId?: string | null
|
|
161
|
+
): Promise<void>;
|
|
162
|
+
private _appendMessage;
|
|
163
|
+
updateMessage(message: SessionMessage): Promise<void>;
|
|
164
|
+
deleteMessages(messageIds: string[]): Promise<void>;
|
|
165
|
+
clearMessages(): Promise<void>;
|
|
166
|
+
addCompaction(
|
|
167
|
+
summary: string,
|
|
168
|
+
fromMessageId: string,
|
|
169
|
+
toMessageId: string
|
|
170
|
+
): Promise<StoredCompaction>;
|
|
171
|
+
getCompactions(): Promise<StoredCompaction[]>;
|
|
77
172
|
/**
|
|
78
173
|
* Run the registered compaction function and store the result as an overlay.
|
|
79
174
|
* Requires `onCompaction()` to be called first.
|
|
@@ -85,7 +180,12 @@ declare class Session {
|
|
|
85
180
|
appendContextBlock(label: string, content: string): Promise<ContextBlock>;
|
|
86
181
|
/**
|
|
87
182
|
* Dynamically register a new context block after session initialization.
|
|
88
|
-
*
|
|
183
|
+
*
|
|
184
|
+
* This is a **builder / runtime API**, not an LLM tool. The LLM writes
|
|
185
|
+
* into existing context blocks via the `set_context` tool (see
|
|
186
|
+
* `ContextBlocks.tools()`); it cannot declare new blocks itself. This
|
|
187
|
+
* method is how extension / host code contributes blocks at runtime
|
|
188
|
+
* (e.g. an extension's `onLoad` handler registering its own memory block).
|
|
89
189
|
*
|
|
90
190
|
* The block's provider is initialized and loaded immediately.
|
|
91
191
|
* Call `refreshSystemPrompt()` afterward to include the new block
|
|
@@ -95,7 +195,10 @@ declare class Session {
|
|
|
95
195
|
* AgentContextProvider. Requires the session to have been created
|
|
96
196
|
* via `Session.create(agent)` (not the direct constructor).
|
|
97
197
|
*/
|
|
98
|
-
addContext(
|
|
198
|
+
addContext(
|
|
199
|
+
label: string,
|
|
200
|
+
options?: SessionContextOptions
|
|
201
|
+
): Promise<ContextBlock>;
|
|
99
202
|
/**
|
|
100
203
|
* Remove a dynamically registered context block.
|
|
101
204
|
* Used during extension unload cleanup.
|
|
@@ -108,22 +211,33 @@ declare class Session {
|
|
|
108
211
|
/**
|
|
109
212
|
* Unload a previously loaded skill, reclaiming context space.
|
|
110
213
|
* The tool result in conversation history is replaced with a short marker.
|
|
214
|
+
*
|
|
215
|
+
* Async so that the session's background skill-state restore (which
|
|
216
|
+
* reads conversation history) is awaited first — otherwise a freshly
|
|
217
|
+
* rehydrated DO could report "not loaded" for a skill that's actually
|
|
218
|
+
* present in history.
|
|
111
219
|
*/
|
|
112
|
-
unloadSkill(label: string, key: string): boolean
|
|
220
|
+
unloadSkill(label: string, key: string): Promise<boolean>;
|
|
113
221
|
/**
|
|
114
222
|
* Get currently loaded skill keys (as "label:key" strings).
|
|
223
|
+
* Async for the same reason as `unloadSkill` — must wait for restore.
|
|
115
224
|
*/
|
|
116
|
-
getLoadedSkillKeys(): Set<string
|
|
225
|
+
getLoadedSkillKeys(): Promise<Set<string>>;
|
|
117
226
|
freezeSystemPrompt(): Promise<string>;
|
|
118
227
|
refreshSystemPrompt(): Promise<string>;
|
|
119
|
-
search(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
228
|
+
search(
|
|
229
|
+
query: string,
|
|
230
|
+
options?: {
|
|
231
|
+
limit?: number;
|
|
232
|
+
}
|
|
233
|
+
): Promise<
|
|
234
|
+
Array<{
|
|
235
|
+
id: string;
|
|
236
|
+
role: string;
|
|
237
|
+
content: string;
|
|
238
|
+
createdAt?: string;
|
|
239
|
+
}>
|
|
240
|
+
>;
|
|
127
241
|
/** Returns set_context and load_context tools. */
|
|
128
242
|
tools(): Promise<ToolSet>;
|
|
129
243
|
}
|
|
@@ -178,7 +292,9 @@ declare class SessionManager {
|
|
|
178
292
|
* Register a compaction function propagated to all sessions.
|
|
179
293
|
* Called by `Session.compact()` to compress message history.
|
|
180
294
|
*/
|
|
181
|
-
onCompaction(
|
|
295
|
+
onCompaction(
|
|
296
|
+
fn: (messages: SessionMessage[]) => Promise<CompactResult | null>
|
|
297
|
+
): this;
|
|
182
298
|
/**
|
|
183
299
|
* Auto-compact when estimated token count exceeds the threshold.
|
|
184
300
|
* Propagated to all sessions. Requires `onCompaction()`.
|
|
@@ -205,35 +321,71 @@ declare class SessionManager {
|
|
|
205
321
|
private _createHistoryProvider;
|
|
206
322
|
/** Get or create the Session instance for a session ID. */
|
|
207
323
|
getSession(sessionId: string): Session;
|
|
208
|
-
create(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
324
|
+
create(
|
|
325
|
+
name: string,
|
|
326
|
+
opts?: {
|
|
327
|
+
parentSessionId?: string;
|
|
328
|
+
model?: string;
|
|
329
|
+
source?: string;
|
|
330
|
+
}
|
|
331
|
+
): SessionInfo;
|
|
213
332
|
get(sessionId: string): SessionInfo | null;
|
|
214
333
|
list(): SessionInfo[];
|
|
215
|
-
delete(sessionId: string): void
|
|
334
|
+
delete(sessionId: string): Promise<void>;
|
|
216
335
|
rename(sessionId: string, name: string): void;
|
|
217
|
-
append(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
336
|
+
append(
|
|
337
|
+
sessionId: string,
|
|
338
|
+
message: SessionMessage,
|
|
339
|
+
parentId?: string
|
|
340
|
+
): Promise<string>;
|
|
341
|
+
upsert(
|
|
342
|
+
sessionId: string,
|
|
343
|
+
message: SessionMessage,
|
|
344
|
+
parentId?: string
|
|
345
|
+
): Promise<string>;
|
|
346
|
+
appendAll(
|
|
347
|
+
sessionId: string,
|
|
348
|
+
messages: SessionMessage[],
|
|
349
|
+
parentId?: string
|
|
350
|
+
): Promise<string | null>;
|
|
351
|
+
getHistory(sessionId: string, leafId?: string): Promise<SessionMessage[]>;
|
|
352
|
+
getMessageCount(sessionId: string): Promise<number>;
|
|
353
|
+
clearMessages(sessionId: string): Promise<void>;
|
|
354
|
+
deleteMessages(sessionId: string, messageIds: string[]): Promise<void>;
|
|
355
|
+
getBranches(sessionId: string, messageId: string): Promise<SessionMessage[]>;
|
|
225
356
|
/**
|
|
226
357
|
* Fork a session at a specific message, creating a new session
|
|
227
358
|
* with the history up to that point copied over.
|
|
228
359
|
*/
|
|
229
|
-
fork(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
360
|
+
fork(
|
|
361
|
+
sessionId: string,
|
|
362
|
+
atMessageId: string,
|
|
363
|
+
newName: string
|
|
364
|
+
): Promise<SessionInfo>;
|
|
365
|
+
addCompaction(
|
|
366
|
+
sessionId: string,
|
|
367
|
+
summary: string,
|
|
368
|
+
fromId: string,
|
|
369
|
+
toId: string
|
|
370
|
+
): Promise<StoredCompaction>;
|
|
371
|
+
getCompactions(sessionId: string): Promise<StoredCompaction[]>;
|
|
372
|
+
compactAndSplit(
|
|
373
|
+
sessionId: string,
|
|
374
|
+
summary: string,
|
|
375
|
+
newName?: string
|
|
376
|
+
): Promise<SessionInfo>;
|
|
377
|
+
addUsage(
|
|
378
|
+
sessionId: string,
|
|
379
|
+
inputTokens: number,
|
|
380
|
+
outputTokens: number,
|
|
381
|
+
cost: number
|
|
382
|
+
): void;
|
|
383
|
+
search(
|
|
384
|
+
query: string,
|
|
385
|
+
options?: {
|
|
386
|
+
limit?: number;
|
|
387
|
+
}
|
|
388
|
+
): {
|
|
237
389
|
id: string;
|
|
238
390
|
role: string;
|
|
239
391
|
content: string;
|
|
@@ -255,5 +407,166 @@ declare class AgentContextProvider implements WritableContextProvider {
|
|
|
255
407
|
set(content: string): Promise<void>;
|
|
256
408
|
}
|
|
257
409
|
//#endregion
|
|
258
|
-
|
|
259
|
-
|
|
410
|
+
//#region src/experimental/memory/session/providers/postgres-adapter.d.ts
|
|
411
|
+
/**
|
|
412
|
+
* Postgres connection adapter.
|
|
413
|
+
*
|
|
414
|
+
* Lets the Postgres-backed providers accept either:
|
|
415
|
+
* - a raw `pg.Client` (or any client with a compatible `query` method), or
|
|
416
|
+
* - the internal `PostgresConnection` interface used by tests and custom drivers.
|
|
417
|
+
*
|
|
418
|
+
* When a `pg`-style client is passed, `?` placeholders are rewritten to
|
|
419
|
+
* `$1, $2, ...` on the way through, so the providers can keep using the
|
|
420
|
+
* portable `?` syntax internally without users having to write a wrapper.
|
|
421
|
+
*/
|
|
422
|
+
/**
|
|
423
|
+
* Minimal connection interface used internally by the Postgres providers.
|
|
424
|
+
* Tests and custom drivers can implement this directly.
|
|
425
|
+
*/
|
|
426
|
+
interface PostgresConnection {
|
|
427
|
+
execute(
|
|
428
|
+
query: string,
|
|
429
|
+
args?: (string | number | boolean | null)[]
|
|
430
|
+
): Promise<{
|
|
431
|
+
rows: Record<string, unknown>[];
|
|
432
|
+
}>;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Structural type matching `pg.Client` (and most `pg`-compatible pools).
|
|
436
|
+
* Accepts the subset of the real client that the providers need, so users
|
|
437
|
+
* can pass `new pg.Client({ connectionString: env.HYPERDRIVE.connectionString })`
|
|
438
|
+
* directly without a wrapper.
|
|
439
|
+
*/
|
|
440
|
+
interface PgClientLike {
|
|
441
|
+
query(
|
|
442
|
+
queryText: string,
|
|
443
|
+
values?: readonly unknown[]
|
|
444
|
+
): Promise<{
|
|
445
|
+
rows: Record<string, unknown>[];
|
|
446
|
+
}>;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Accepted client type across the Postgres providers.
|
|
450
|
+
*
|
|
451
|
+
* Use `pg.Client` (the recommended path for Hyperdrive):
|
|
452
|
+
* ```ts
|
|
453
|
+
* const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
|
|
454
|
+
* await client.connect();
|
|
455
|
+
* new PostgresSessionProvider(client, sessionId);
|
|
456
|
+
* ```
|
|
457
|
+
*
|
|
458
|
+
* Or implement `PostgresConnection` for tests / bespoke drivers.
|
|
459
|
+
*/
|
|
460
|
+
type PostgresClient = PostgresConnection | PgClientLike;
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/experimental/memory/session/providers/postgres.d.ts
|
|
463
|
+
declare class PostgresSessionProvider implements SessionProvider {
|
|
464
|
+
private conn;
|
|
465
|
+
private sessionId;
|
|
466
|
+
/**
|
|
467
|
+
* @param client A raw `pg.Client` (recommended) or any `PostgresConnection`.
|
|
468
|
+
* Must already be connected — this provider never opens or closes the
|
|
469
|
+
* underlying client.
|
|
470
|
+
* @param sessionId Session identifier. Different ids are fully isolated
|
|
471
|
+
* rows within the shared tables. Defaults to `""`.
|
|
472
|
+
*/
|
|
473
|
+
constructor(client: PostgresClient, sessionId?: string);
|
|
474
|
+
getMessage(id: string): Promise<SessionMessage | null>;
|
|
475
|
+
getHistory(leafId?: string | null): Promise<SessionMessage[]>;
|
|
476
|
+
getLatestLeaf(): Promise<SessionMessage | null>;
|
|
477
|
+
getBranches(messageId: string): Promise<SessionMessage[]>;
|
|
478
|
+
getPathLength(leafId?: string | null): Promise<number>;
|
|
479
|
+
appendMessage(
|
|
480
|
+
message: SessionMessage,
|
|
481
|
+
parentId?: string | null
|
|
482
|
+
): Promise<void>;
|
|
483
|
+
updateMessage(message: SessionMessage): Promise<void>;
|
|
484
|
+
deleteMessages(messageIds: string[]): Promise<void>;
|
|
485
|
+
clearMessages(): Promise<void>;
|
|
486
|
+
addCompaction(
|
|
487
|
+
summary: string,
|
|
488
|
+
fromMessageId: string,
|
|
489
|
+
toMessageId: string
|
|
490
|
+
): Promise<StoredCompaction>;
|
|
491
|
+
getCompactions(): Promise<StoredCompaction[]>;
|
|
492
|
+
searchMessages(query: string, limit?: number): Promise<SearchResult[]>;
|
|
493
|
+
private latestLeafRow;
|
|
494
|
+
private applyCompactions;
|
|
495
|
+
private parse;
|
|
496
|
+
private parseRows;
|
|
497
|
+
/**
|
|
498
|
+
* Extract just the human-readable text from a message's JSON blob
|
|
499
|
+
* and store it in `text_content`, which feeds the generated `content_tsv`
|
|
500
|
+
* column used for FTS. The full structured message (parts, tool calls,
|
|
501
|
+
* metadata) is still stored verbatim in `content` — this is the source
|
|
502
|
+
* of truth. Indexing the raw JSON would return FTS hits on keys like
|
|
503
|
+
* `"role"`, `"parts"`, `"dynamic-tool"`, etc.
|
|
504
|
+
*/
|
|
505
|
+
private extractSearchableText;
|
|
506
|
+
}
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/experimental/memory/session/providers/postgres-context.d.ts
|
|
509
|
+
declare class PostgresContextProvider implements WritableContextProvider {
|
|
510
|
+
private conn;
|
|
511
|
+
private label;
|
|
512
|
+
/**
|
|
513
|
+
* @param client A raw `pg.Client` (recommended) or any `PostgresConnection`.
|
|
514
|
+
* Must already be connected.
|
|
515
|
+
* @param label Block label used as the primary key row in
|
|
516
|
+
* `cf_agents_context_blocks`. Pass a session-scoped label (e.g.
|
|
517
|
+
* `` `memory_${sessionId}` ``) for per-session state.
|
|
518
|
+
*/
|
|
519
|
+
constructor(client: PostgresClient, label: string);
|
|
520
|
+
get(): Promise<string | null>;
|
|
521
|
+
set(content: string): Promise<void>;
|
|
522
|
+
}
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/experimental/memory/session/providers/postgres-search.d.ts
|
|
525
|
+
declare class PostgresSearchProvider implements SearchProvider {
|
|
526
|
+
private conn;
|
|
527
|
+
private label;
|
|
528
|
+
/**
|
|
529
|
+
* @param client A raw `pg.Client` (recommended) or any `PostgresConnection`.
|
|
530
|
+
* Must already be connected.
|
|
531
|
+
*/
|
|
532
|
+
constructor(client: PostgresClient);
|
|
533
|
+
init(label: string): void;
|
|
534
|
+
get(): Promise<string | null>;
|
|
535
|
+
search(query: string): Promise<string | null>;
|
|
536
|
+
set(key: string, content: string): Promise<void>;
|
|
537
|
+
}
|
|
538
|
+
//#endregion
|
|
539
|
+
export {
|
|
540
|
+
AgentContextProvider,
|
|
541
|
+
AgentSearchProvider,
|
|
542
|
+
AgentSessionProvider,
|
|
543
|
+
type ContextBlock,
|
|
544
|
+
type ContextConfig,
|
|
545
|
+
type ContextProvider,
|
|
546
|
+
type PgClientLike,
|
|
547
|
+
type PostgresClient,
|
|
548
|
+
type PostgresConnection,
|
|
549
|
+
PostgresContextProvider,
|
|
550
|
+
PostgresSearchProvider,
|
|
551
|
+
PostgresSessionProvider,
|
|
552
|
+
R2SkillProvider,
|
|
553
|
+
type SearchProvider,
|
|
554
|
+
type SearchResult,
|
|
555
|
+
Session,
|
|
556
|
+
type SessionContextOptions,
|
|
557
|
+
type SessionInfo,
|
|
558
|
+
SessionManager,
|
|
559
|
+
type SessionManagerOptions,
|
|
560
|
+
type SessionMessage,
|
|
561
|
+
type SessionMessagePart,
|
|
562
|
+
type SessionOptions,
|
|
563
|
+
type SessionProvider,
|
|
564
|
+
type SkillProvider,
|
|
565
|
+
type SqlProvider,
|
|
566
|
+
type StoredCompaction,
|
|
567
|
+
type WritableContextProvider,
|
|
568
|
+
isSearchProvider,
|
|
569
|
+
isSkillProvider,
|
|
570
|
+
isWritableProvider
|
|
571
|
+
};
|
|
572
|
+
//# sourceMappingURL=index.d.ts.map
|