agents 0.22.0 → 0.23.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 +20 -1
- package/dist/{agent-routing-CnkaHb-v.d.ts → agent-routing-DE5zmCQ8.d.ts} +1038 -394
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +26 -26
- package/dist/{agent-tools-C0XJqWzB.d.ts → agent-tools-DtXMTDGM.d.ts} +7 -7
- package/dist/agent-tools.d.ts +21 -21
- package/dist/browser/ai.js +4 -1
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/callable-decorator-DP__HhBA.d.ts +72 -0
- package/dist/callable-decorator.d.ts +18 -0
- package/dist/callable-decorator.js +71 -0
- package/dist/callable-decorator.js.map +1 -0
- package/dist/capability-BjSKYpzg.js.map +1 -1
- package/dist/capability-runner-Be_-PLR1.d.ts +459 -0
- package/dist/channel-Bnm4S7T2.d.ts +491 -0
- package/dist/channels/ai-sdk.d.ts +46 -0
- package/dist/channels/ai-sdk.js +120 -0
- package/dist/channels/ai-sdk.js.map +1 -0
- package/dist/channels/email.d.ts +95 -0
- package/dist/channels/email.js +323 -0
- package/dist/channels/email.js.map +1 -0
- package/dist/channels/index.d.ts +233 -0
- package/dist/channels/index.js +608 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/slack.d.ts +140 -0
- package/dist/channels/slack.js +614 -0
- package/dist/channels/slack.js.map +1 -0
- package/dist/channels/tanstack-ai.d.ts +39 -0
- package/dist/channels/tanstack-ai.js +17 -0
- package/dist/channels/tanstack-ai.js.map +1 -0
- package/dist/channels/telegram.d.ts +106 -0
- package/dist/channels/telegram.js +427 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/channels/voice.d.ts +45 -0
- package/dist/channels/voice.js +122 -0
- package/dist/channels/voice.js.map +1 -0
- package/dist/chat/index.d.ts +2325 -2019
- package/dist/chat/index.js +888 -518
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +7 -7
- package/dist/chat-sdk/index.js +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/context/index.d.ts +216 -0
- package/dist/context/index.js +454 -0
- package/dist/context/index.js.map +1 -0
- package/dist/{current-agent-CuMErtly.d.ts → current-agent-Da_C9a3b.d.ts} +90 -107
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{diagnostics-CaBjfz4J.js → diagnostics-BzvaX2UT.js} +5 -1
- package/dist/diagnostics-BzvaX2UT.js.map +1 -0
- package/dist/diagnostics-C4jcz3VK.js +360 -0
- package/dist/diagnostics-C4jcz3VK.js.map +1 -0
- package/dist/index-BB0kqhIz.d.ts +101 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index-XDkuQ7zm.d.ts +89 -0
- package/dist/{index-DcSAZKsB.d.ts → index-YSKgfgg9.d.ts} +3 -1
- package/dist/index.d.ts +91 -82
- package/dist/index.js +3 -2
- package/dist/ingress-BfetZbMO.js +83 -0
- package/dist/ingress-BfetZbMO.js.map +1 -0
- package/dist/internal-CYlgHl1l.js +59 -0
- package/dist/internal-CYlgHl1l.js.map +1 -0
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +35 -17
- package/dist/lifecycle/index.js +1 -1
- package/dist/lifecycle-CMRGjZdw.js +1299 -0
- package/dist/lifecycle-CMRGjZdw.js.map +1 -0
- package/dist/mcp/client/index.d.ts +20 -20
- package/dist/mcp/index.d.ts +35 -35
- package/dist/mcp/index.js +1 -1
- package/dist/observability/index.d.ts +1 -1
- package/dist/observability/index.js +1 -1
- package/dist/react.d.ts +4 -4
- package/dist/{retries-CAvxtG9d.d.ts → retries-D9Ds-1lz.d.ts} +17 -6
- package/dist/retries.d.ts +8 -6
- package/dist/retries.js +13 -1
- package/dist/retries.js.map +1 -1
- package/dist/routing/index.d.ts +137 -0
- package/dist/routing/index.js +244 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/sanitize-D9TujEK8.js +79 -0
- package/dist/sanitize-D9TujEK8.js.map +1 -0
- package/dist/scheduler-DD9NdYbF.js +665 -0
- package/dist/scheduler-DD9NdYbF.js.map +1 -0
- package/dist/{scheduler-DQoTGoAW.d.ts → scheduler-Dwh85ZGl.d.ts} +21 -22
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/sentence-chunker-BAidJ4DA.d.ts +68 -0
- package/dist/serializable.d.ts +1 -1
- package/dist/sessions/index.d.ts +441 -0
- package/dist/sessions/index.js +2063 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/skills/index.d.ts +99 -0
- package/dist/skills/index.js +254 -5
- package/dist/skills/index.js.map +1 -1
- package/dist/{src-5W6JNKVb.js → src-DlSHshb2.js} +1460 -1110
- package/dist/src-DlSHshb2.js.map +1 -0
- package/dist/streams/index.d.ts +120 -0
- package/dist/streams/index.js +107 -0
- package/dist/streams/index.js.map +1 -0
- package/dist/streams-D6tJ0NN9.d.ts +370 -0
- package/dist/streams-DZKgAj9b.js +709 -0
- package/dist/streams-DZKgAj9b.js.map +1 -0
- package/dist/sub-routing.d.ts +12 -12
- package/dist/surface-bZZJqBka.js +17 -0
- package/dist/surface-bZZJqBka.js.map +1 -0
- package/dist/tasks/index.d.ts +64 -0
- package/dist/tasks/index.js +2 -0
- package/dist/tasks-BRJ5zgya.d.ts +517 -0
- package/dist/tasks-ylZgBjhj.js +1656 -0
- package/dist/tasks-ylZgBjhj.js.map +1 -0
- package/dist/text-segment-joiner-BtAFQSA_.js +57 -0
- package/dist/text-segment-joiner-BtAFQSA_.js.map +1 -0
- package/dist/text-stream-CpdiKrJB.js +272 -0
- package/dist/text-stream-CpdiKrJB.js.map +1 -0
- package/dist/tokens-nHAKcN6M.js +52 -0
- package/dist/tokens-nHAKcN6M.js.map +1 -0
- package/dist/tool-schema-CBjGPrsQ.js +31 -0
- package/dist/tool-schema-CBjGPrsQ.js.map +1 -0
- package/dist/types-B7LojTe4.d.ts +202 -0
- package/dist/types-_Faxb570.d.ts +439 -0
- package/dist/voice/client.d.ts +226 -0
- package/dist/voice/client.js +932 -0
- package/dist/voice/client.js.map +1 -0
- package/dist/voice/errors.d.ts +43 -0
- package/dist/voice/errors.js +41 -0
- package/dist/voice/errors.js.map +1 -0
- package/dist/voice/index.d.ts +271 -0
- package/dist/voice/index.js +1812 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/react.d.ts +167 -0
- package/dist/voice/react.js +234 -0
- package/dist/voice/react.js.map +1 -0
- package/dist/voice/sfu.d.ts +71 -0
- package/dist/voice/sfu.js +157 -0
- package/dist/voice/sfu.js.map +1 -0
- package/dist/voice/text.d.ts +6 -0
- package/dist/voice/text.js +2 -0
- package/dist/voice/types.d.ts +58 -0
- package/dist/voice/types.js +18 -0
- package/dist/voice/types.js.map +1 -0
- package/dist/voice/workers-ai.d.ts +136 -0
- package/dist/voice/workers-ai.js +568 -0
- package/dist/voice/workers-ai.js.map +1 -0
- package/dist/websockets/index.d.ts +192 -0
- package/dist/websockets/index.js +2 -0
- package/dist/websockets-DUfRHPRq.js +502 -0
- package/dist/websockets-DUfRHPRq.js.map +1 -0
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflows.d.ts +21 -21
- package/dist/workflows.js +1 -1
- package/docs/agent-class.md +2 -2
- package/docs/agent-tools.md +2 -1
- package/docs/channels.md +323 -0
- package/docs/chat-agents.md +6 -13
- package/docs/context.md +131 -0
- package/docs/index.md +15 -12
- package/docs/lifecycle.md +102 -55
- package/docs/long-running-agents.md +2 -2
- package/docs/mcp-servers.md +5 -1
- package/docs/resumable-streaming.md +1 -1
- package/docs/routing.md +105 -0
- package/docs/sessions.md +237 -871
- package/docs/streams.md +213 -0
- package/docs/sub-agents.md +184 -124
- package/docs/tasks.md +246 -0
- package/docs/voice.md +745 -0
- package/package.json +115 -13
- package/dist/capability-runner-CvHGZqUu.d.ts +0 -150
- package/dist/compaction-helpers-iiKMr2TQ.js +0 -340
- package/dist/compaction-helpers-iiKMr2TQ.js.map +0 -1
- package/dist/compaction-helpers-wUz6M3us.d.ts +0 -621
- package/dist/diagnostics-CaBjfz4J.js.map +0 -1
- package/dist/durable-object-lifecycle-D6nNQJJd.js +0 -862
- package/dist/durable-object-lifecycle-D6nNQJJd.js.map +0 -1
- package/dist/experimental/memory/session/index.d.ts +0 -671
- package/dist/experimental/memory/session/index.js +0 -2379
- package/dist/experimental/memory/session/index.js.map +0 -1
- package/dist/experimental/memory/utils/index.d.ts +0 -96
- package/dist/experimental/memory/utils/index.js +0 -79
- package/dist/experimental/memory/utils/index.js.map +0 -1
- package/dist/scheduler-CR9RHGos.js +0 -857
- package/dist/scheduler-CR9RHGos.js.map +0 -1
- package/dist/src-5W6JNKVb.js.map +0 -1
- package/dist/tool-output-truncation-CNnnGZQ3.js +0 -98
- package/dist/tool-output-truncation-CNnnGZQ3.js.map +0 -1
|
@@ -1,671 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
A as StoredCompaction,
|
|
3
|
-
C as isSearchProvider,
|
|
4
|
-
D as RecentHistoryResult,
|
|
5
|
-
E as HistoryRowStat,
|
|
6
|
-
F as SessionMessagePart,
|
|
7
|
-
I as SessionOptions,
|
|
8
|
-
L as SessionTokenCounter,
|
|
9
|
-
M as CompactContext,
|
|
10
|
-
N as CompactionErrorHandler,
|
|
11
|
-
O as SearchResult,
|
|
12
|
-
P as SessionMessage,
|
|
13
|
-
R as SessionTokenCounterInput,
|
|
14
|
-
S as SearchProvider,
|
|
15
|
-
T as SqlProvider,
|
|
16
|
-
_ as isWritableProvider,
|
|
17
|
-
b as isSkillProvider,
|
|
18
|
-
g as WritableContextProvider,
|
|
19
|
-
h as ContextProvider,
|
|
20
|
-
j as CompactAfterOptions,
|
|
21
|
-
k as SessionProvider,
|
|
22
|
-
m as ContextConfig,
|
|
23
|
-
p as ContextBlock,
|
|
24
|
-
r as CompactResult,
|
|
25
|
-
v as R2SkillProvider,
|
|
26
|
-
w as AgentSessionProvider,
|
|
27
|
-
x as AgentSearchProvider,
|
|
28
|
-
y as SkillProvider
|
|
29
|
-
} from "../../../compaction-helpers-wUz6M3us.js";
|
|
30
|
-
import { ToolSet } from "ai";
|
|
31
|
-
|
|
32
|
-
//#region src/experimental/memory/session/session.d.ts
|
|
33
|
-
type SessionContextOptions = Omit<ContextConfig, "label">;
|
|
34
|
-
type InternalMessageChangeEvent =
|
|
35
|
-
| {
|
|
36
|
-
type: "append";
|
|
37
|
-
message: SessionMessage;
|
|
38
|
-
parentId?: string | null;
|
|
39
|
-
inserted: boolean;
|
|
40
|
-
}
|
|
41
|
-
| {
|
|
42
|
-
type: "update";
|
|
43
|
-
message: SessionMessage;
|
|
44
|
-
}
|
|
45
|
-
| {
|
|
46
|
-
type: "delete";
|
|
47
|
-
messageIds: string[];
|
|
48
|
-
}
|
|
49
|
-
| {
|
|
50
|
-
type: "clear";
|
|
51
|
-
}
|
|
52
|
-
| {
|
|
53
|
-
type: "compact";
|
|
54
|
-
};
|
|
55
|
-
declare class Session {
|
|
56
|
-
private storage;
|
|
57
|
-
private context;
|
|
58
|
-
private _agent?;
|
|
59
|
-
private _broadcaster?;
|
|
60
|
-
private _storageProvider?;
|
|
61
|
-
private _sessionId?;
|
|
62
|
-
private _pending?;
|
|
63
|
-
private _cachedPrompt?;
|
|
64
|
-
private _compactionFn?;
|
|
65
|
-
private _warnedCompactionNoOp;
|
|
66
|
-
private _tokenThreshold?;
|
|
67
|
-
private _tokenCounter?;
|
|
68
|
-
private _compactionErrorHandler?;
|
|
69
|
-
private _ready;
|
|
70
|
-
private _restorePromise?;
|
|
71
|
-
private _messageChangeListener?;
|
|
72
|
-
constructor(storage: SessionProvider, options?: SessionOptions);
|
|
73
|
-
/**
|
|
74
|
-
* Chainable session creation with auto-wired providers.
|
|
75
|
-
*
|
|
76
|
-
* Pass a `SqlProvider` (Agent with `sql` method) for auto-wired SQLite,
|
|
77
|
-
* or a `SessionProvider` directly for custom storage (Postgres, etc.).
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* // Auto-wired SQLite (DO Agent)
|
|
82
|
-
* const session = Session.create(this)
|
|
83
|
-
* .withContext("soul", { provider: { get: async () => "You are helpful." } })
|
|
84
|
-
* .withContext("memory", { description: "Learned facts", maxTokens: 1100 })
|
|
85
|
-
* .withCachedPrompt();
|
|
86
|
-
*
|
|
87
|
-
* // Skills from R2 (on-demand loading via load_context tool)
|
|
88
|
-
* const session = Session.create(this)
|
|
89
|
-
* .withContext("skills", {
|
|
90
|
-
* provider: new R2SkillProvider(env.SKILLS_BUCKET, { prefix: "skills/" })
|
|
91
|
-
* })
|
|
92
|
-
* .withCachedPrompt();
|
|
93
|
-
*
|
|
94
|
-
* // Custom storage provider (Postgres, etc.)
|
|
95
|
-
* const session = Session.create(postgresProvider)
|
|
96
|
-
* .withContext("memory", {
|
|
97
|
-
* maxTokens: 1100,
|
|
98
|
-
* provider: new PostgresContextProvider(conn, "memory")
|
|
99
|
-
* })
|
|
100
|
-
* .withCachedPrompt(new PostgresContextProvider(conn, "_prompt"));
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
static create(provider: SqlProvider | SessionProvider): Session;
|
|
104
|
-
forSession(sessionId: string): this;
|
|
105
|
-
withContext(label: string, options?: SessionContextOptions): this;
|
|
106
|
-
withCachedPrompt(provider?: WritableContextProvider): this;
|
|
107
|
-
/**
|
|
108
|
-
* Register a compaction function. Called by `compact()` to compress
|
|
109
|
-
* message history into a summary overlay.
|
|
110
|
-
*/
|
|
111
|
-
onCompaction(
|
|
112
|
-
fn: (
|
|
113
|
-
messages: SessionMessage[],
|
|
114
|
-
context?: CompactContext
|
|
115
|
-
) => Promise<CompactResult | null>
|
|
116
|
-
): this;
|
|
117
|
-
/**
|
|
118
|
-
* Auto-compact when estimated token count exceeds the threshold.
|
|
119
|
-
* Checked after each `appendMessage`. Requires `onCompaction()`.
|
|
120
|
-
*
|
|
121
|
-
* By default this uses a Workers-safe heuristic over stored messages plus
|
|
122
|
-
* the Session-managed frozen system prompt. Provide `tokenCounter` when you
|
|
123
|
-
* have model-reported usage or a tokenizer and need a stricter budget.
|
|
124
|
-
*/
|
|
125
|
-
compactAfter(tokenThreshold: number, options?: CompactAfterOptions): this;
|
|
126
|
-
/**
|
|
127
|
-
* Handle failures from the automatic `compactAfter()` trigger.
|
|
128
|
-
*
|
|
129
|
-
* Manual `compact()` still reports errors through the existing session error
|
|
130
|
-
* broadcast path.
|
|
131
|
-
*/
|
|
132
|
-
onCompactionError(handler: CompactionErrorHandler): this;
|
|
133
|
-
/**
|
|
134
|
-
* @internal
|
|
135
|
-
* Framework hook for cache-owning callers that need to mirror message
|
|
136
|
-
* storage changes. Application code should use the normal Session methods.
|
|
137
|
-
*/
|
|
138
|
-
internal_onMessagesChanged(
|
|
139
|
-
listener:
|
|
140
|
-
| ((event: InternalMessageChangeEvent) => void | Promise<void>)
|
|
141
|
-
| null
|
|
142
|
-
): this;
|
|
143
|
-
private _ensureReady;
|
|
144
|
-
/**
|
|
145
|
-
* Await the background skill-restore kicked off by `_ensureReady()`.
|
|
146
|
-
* Idempotent and cheap — every async public method calls this so that
|
|
147
|
-
* `_loadedSkills` reflects conversation history before any read or write.
|
|
148
|
-
*/
|
|
149
|
-
private _ensureRestored;
|
|
150
|
-
private _notifyMessagesChanged;
|
|
151
|
-
/**
|
|
152
|
-
* Reconstruct which skills are loaded by scanning conversation history
|
|
153
|
-
* for load_context tool results that haven't been unloaded.
|
|
154
|
-
* Runs once per init to survive hibernation / eviction, including for
|
|
155
|
-
* async SessionProviders (e.g. Postgres) where we must `await` history.
|
|
156
|
-
*
|
|
157
|
-
* Skipped entirely when no skill-capable provider is configured —
|
|
158
|
-
* `load_context` results can only exist when a skill block was registered,
|
|
159
|
-
* and the scan would otherwise read the whole transcript on every wake,
|
|
160
|
-
* bypassing byte-budgeted hydration (#1710). A skill block added later via
|
|
161
|
-
* `addContext()` triggers the scan at that point instead.
|
|
162
|
-
*/
|
|
163
|
-
private _restoreLoadedSkills;
|
|
164
|
-
private _skillScanRan;
|
|
165
|
-
/**
|
|
166
|
-
* Scan stored history for load/unload_context tool results and restore
|
|
167
|
-
* the loaded-skill tracking set.
|
|
168
|
-
*
|
|
169
|
-
* Memory-bounded when the provider supports `getHistoryRowStats`: rows
|
|
170
|
-
* are enumerated without content, then only assistant rows are fetched
|
|
171
|
-
* and scanned ONE AT A TIME — peak memory is a single message instead of
|
|
172
|
-
* the whole transcript. Falls back to a full `getHistory()` read for
|
|
173
|
-
* providers without row stats (e.g. Postgres).
|
|
174
|
-
*
|
|
175
|
-
* Note: the bounded path scans raw path rows, so `load_context` results
|
|
176
|
-
* inside compacted ranges are still seen (the full-read path hides them
|
|
177
|
-
* behind compaction overlays). That superset is intentional — the stored
|
|
178
|
-
* tool result still exists and can be reclaimed by `unloadSkill`.
|
|
179
|
-
*/
|
|
180
|
-
private _scanHistoryForLoadedSkills;
|
|
181
|
-
/**
|
|
182
|
-
* Reclaim context-window tokens consumed by a previously loaded skill.
|
|
183
|
-
*
|
|
184
|
-
* When a skill is loaded via the `load_context` tool, its full body is
|
|
185
|
-
* embedded as that tool call's `output-available` result inside the
|
|
186
|
-
* assistant message — which means every subsequent turn replays the
|
|
187
|
-
* entire skill as part of the conversation history and pays for it in
|
|
188
|
-
* input tokens.
|
|
189
|
-
*
|
|
190
|
-
* This method walks back through history, finds the matching
|
|
191
|
-
* `load_context` tool result for `(label, key)`, and replaces its bulky
|
|
192
|
-
* `output` with a short marker `[skill unloaded: <key>]`. The skill
|
|
193
|
-
* content is dropped from future turns and the tokens are reclaimed.
|
|
194
|
-
* The skill itself stays available to reload via `load_context`.
|
|
195
|
-
*/
|
|
196
|
-
private _reclaimLoadedSkill;
|
|
197
|
-
getHistory(leafId?: string | null): Promise<SessionMessage[]>;
|
|
198
|
-
private _warnedNoRecentHistorySupport;
|
|
199
|
-
/**
|
|
200
|
-
* Byte-budgeted read of the most recent messages on the active branch
|
|
201
|
-
* path (always at least the leaf message, and at least
|
|
202
|
-
* `minRecentMessages` when the path is long enough). Lets hosts hydrate
|
|
203
|
-
* a bounded window instead of the full transcript so wake-time memory
|
|
204
|
-
* scales with the budget rather than total session history (#1710).
|
|
205
|
-
*
|
|
206
|
-
* Falls back to a full (untruncated) read when the provider doesn't
|
|
207
|
-
* implement `getRecentHistory`. The fallback reports honest metadata
|
|
208
|
-
* (`truncated: false` and the real serialized size) and warns once so a
|
|
209
|
-
* host relying on the budget knows it is not being enforced.
|
|
210
|
-
*/
|
|
211
|
-
getRecentHistory(
|
|
212
|
-
maxContentBytes: number,
|
|
213
|
-
minRecentMessages?: number
|
|
214
|
-
): Promise<RecentHistoryResult>;
|
|
215
|
-
/**
|
|
216
|
-
* Per-row stored sizes for the active branch path (root → leaf) WITHOUT
|
|
217
|
-
* loading message content, or `null` when the provider doesn't support it.
|
|
218
|
-
* Lets hosts find oversized rows (e.g. inline base64 media) and process
|
|
219
|
-
* them one at a time with bounded memory.
|
|
220
|
-
*/
|
|
221
|
-
getHistoryRowStats(): Promise<HistoryRowStat[] | null>;
|
|
222
|
-
getMessage(id: string): Promise<SessionMessage | null>;
|
|
223
|
-
getLatestLeaf(): Promise<SessionMessage | null>;
|
|
224
|
-
getBranches(messageId: string): Promise<SessionMessage[]>;
|
|
225
|
-
getPathLength(leafId?: string | null): Promise<number>;
|
|
226
|
-
private _broadcast;
|
|
227
|
-
private _shouldEstimateTokens;
|
|
228
|
-
private _estimateTokenCount;
|
|
229
|
-
private _handleAutoCompactionError;
|
|
230
|
-
private _emitStatus;
|
|
231
|
-
private _emitError;
|
|
232
|
-
appendMessage(
|
|
233
|
-
message: SessionMessage,
|
|
234
|
-
parentId?: string | null
|
|
235
|
-
): Promise<void>;
|
|
236
|
-
private _appendMessage;
|
|
237
|
-
updateMessage(message: SessionMessage): Promise<void>;
|
|
238
|
-
/**
|
|
239
|
-
* @internal
|
|
240
|
-
* Rewrite a stored message WITHOUT the public-write side effects: no
|
|
241
|
-
* token-estimate status broadcast (which reads the FULL history) and no
|
|
242
|
-
* auto-compaction check. For framework maintenance passes that rewrite
|
|
243
|
-
* many rows with bounded memory — e.g. media eviction (#1710) — where the
|
|
244
|
-
* per-row full-history estimate would reintroduce the memory pressure the
|
|
245
|
-
* pass exists to remove. The message-change listener still fires so a
|
|
246
|
-
* cache-owning host stays coherent. Application code should use
|
|
247
|
-
* `updateMessage`.
|
|
248
|
-
*/
|
|
249
|
-
internal_rewriteMessage(message: SessionMessage): Promise<void>;
|
|
250
|
-
deleteMessages(messageIds: string[]): Promise<void>;
|
|
251
|
-
clearMessages(): Promise<void>;
|
|
252
|
-
addCompaction(
|
|
253
|
-
summary: string,
|
|
254
|
-
fromMessageId: string,
|
|
255
|
-
toMessageId: string
|
|
256
|
-
): Promise<StoredCompaction>;
|
|
257
|
-
getCompactions(): Promise<StoredCompaction[]>;
|
|
258
|
-
/**
|
|
259
|
-
* Run the registered compaction function and store the result as an overlay.
|
|
260
|
-
* When `leafId` is provided, compact that root-to-leaf branch instead of the
|
|
261
|
-
* active branch. Requires `onCompaction()` to be called first.
|
|
262
|
-
*/
|
|
263
|
-
compact(leafId?: string | null): Promise<CompactResult | null>;
|
|
264
|
-
getContextBlock(label: string): ContextBlock | null;
|
|
265
|
-
getContextBlocks(): ContextBlock[];
|
|
266
|
-
replaceContextBlock(label: string, content: string): Promise<ContextBlock>;
|
|
267
|
-
appendContextBlock(label: string, content: string): Promise<ContextBlock>;
|
|
268
|
-
/**
|
|
269
|
-
* Dynamically register a new context block after session initialization.
|
|
270
|
-
*
|
|
271
|
-
* This is a **builder / runtime API**, not an LLM tool. The LLM writes
|
|
272
|
-
* into existing context blocks via the `set_context` tool (see
|
|
273
|
-
* `ContextBlocks.tools()`); it cannot declare new blocks itself. This
|
|
274
|
-
* method is how extension / host code contributes blocks at runtime
|
|
275
|
-
* (e.g. an extension's `onLoad` handler registering its own memory block).
|
|
276
|
-
*
|
|
277
|
-
* The block's provider is initialized and loaded immediately.
|
|
278
|
-
* Call `refreshSystemPrompt()` afterward to include the new block
|
|
279
|
-
* in the system prompt.
|
|
280
|
-
*
|
|
281
|
-
* Note: When called without a provider, auto-wires to SQLite via
|
|
282
|
-
* AgentContextProvider. Requires the session to have been created
|
|
283
|
-
* via `Session.create(agent)` (not the direct constructor).
|
|
284
|
-
*/
|
|
285
|
-
addContext(
|
|
286
|
-
label: string,
|
|
287
|
-
options?: SessionContextOptions
|
|
288
|
-
): Promise<ContextBlock>;
|
|
289
|
-
/**
|
|
290
|
-
* Remove a dynamically registered context block.
|
|
291
|
-
* Used during extension unload cleanup.
|
|
292
|
-
*
|
|
293
|
-
* Returns true if the block existed and was removed.
|
|
294
|
-
* Call `refreshSystemPrompt()` afterward to rebuild the prompt
|
|
295
|
-
* without the removed block.
|
|
296
|
-
*/
|
|
297
|
-
removeContext(label: string): boolean;
|
|
298
|
-
/**
|
|
299
|
-
* Unload a previously loaded skill, reclaiming context space.
|
|
300
|
-
* The tool result in conversation history is replaced with a short marker.
|
|
301
|
-
*
|
|
302
|
-
* Async so that the session's background skill-state restore (which
|
|
303
|
-
* reads conversation history) is awaited first — otherwise a freshly
|
|
304
|
-
* rehydrated DO could report "not loaded" for a skill that's actually
|
|
305
|
-
* present in history.
|
|
306
|
-
*/
|
|
307
|
-
unloadSkill(label: string, key: string): Promise<boolean>;
|
|
308
|
-
/**
|
|
309
|
-
* Get currently loaded skill keys (as "label:key" strings).
|
|
310
|
-
* Async for the same reason as `unloadSkill` — must wait for restore.
|
|
311
|
-
*/
|
|
312
|
-
getLoadedSkillKeys(): Promise<Set<string>>;
|
|
313
|
-
freezeSystemPrompt(): Promise<string>;
|
|
314
|
-
refreshSystemPrompt(): Promise<string>;
|
|
315
|
-
search(
|
|
316
|
-
query: string,
|
|
317
|
-
options?: {
|
|
318
|
-
limit?: number;
|
|
319
|
-
}
|
|
320
|
-
): Promise<
|
|
321
|
-
Array<{
|
|
322
|
-
id: string;
|
|
323
|
-
role: string;
|
|
324
|
-
content: string;
|
|
325
|
-
createdAt?: string;
|
|
326
|
-
}>
|
|
327
|
-
>;
|
|
328
|
-
/** Returns set_context and load_context tools. */
|
|
329
|
-
tools(): Promise<ToolSet>;
|
|
330
|
-
}
|
|
331
|
-
//#endregion
|
|
332
|
-
//#region src/experimental/memory/session/manager.d.ts
|
|
333
|
-
interface SessionInfo {
|
|
334
|
-
id: string;
|
|
335
|
-
name: string;
|
|
336
|
-
parent_session_id: string | null;
|
|
337
|
-
model: string | null;
|
|
338
|
-
source: string | null;
|
|
339
|
-
input_tokens: number;
|
|
340
|
-
output_tokens: number;
|
|
341
|
-
estimated_cost: number;
|
|
342
|
-
end_reason: string | null;
|
|
343
|
-
created_at: string;
|
|
344
|
-
updated_at: string;
|
|
345
|
-
}
|
|
346
|
-
interface SessionManagerOptions {}
|
|
347
|
-
declare class SessionManager {
|
|
348
|
-
private agent;
|
|
349
|
-
private _pending;
|
|
350
|
-
private _cachedPrompt?;
|
|
351
|
-
private _compactionFn?;
|
|
352
|
-
private _tokenThreshold?;
|
|
353
|
-
private _tokenCounter?;
|
|
354
|
-
private _compactionErrorHandler?;
|
|
355
|
-
private _sessions;
|
|
356
|
-
private _historyLabel?;
|
|
357
|
-
private _tableReady;
|
|
358
|
-
private _ready;
|
|
359
|
-
constructor(agent: SqlProvider, _options?: SessionManagerOptions);
|
|
360
|
-
/**
|
|
361
|
-
* Chainable SessionManager creation with auto-wired context for all sessions.
|
|
362
|
-
*
|
|
363
|
-
* @example
|
|
364
|
-
* ```ts
|
|
365
|
-
* const manager = SessionManager.create(this)
|
|
366
|
-
* .withContext("soul", { provider: { get: async () => "You are helpful." } })
|
|
367
|
-
* .withContext("memory", { description: "Learned facts", maxTokens: 1100 })
|
|
368
|
-
* .withCachedPrompt()
|
|
369
|
-
* .compactAfter(100_000);
|
|
370
|
-
*
|
|
371
|
-
* // Each getSession(id) auto-creates namespaced providers:
|
|
372
|
-
* // memory key: "memory_<sessionId>"
|
|
373
|
-
* // prompt key: "_system_prompt_<sessionId>"
|
|
374
|
-
* const session = manager.getSession("chat-123");
|
|
375
|
-
* ```
|
|
376
|
-
*/
|
|
377
|
-
static create(agent: SqlProvider): SessionManager;
|
|
378
|
-
withContext(label: string, options?: SessionContextOptions): this;
|
|
379
|
-
withCachedPrompt(provider?: WritableContextProvider): this;
|
|
380
|
-
/**
|
|
381
|
-
* Register a compaction function propagated to all sessions.
|
|
382
|
-
* Called by `Session.compact()` to compress message history.
|
|
383
|
-
*/
|
|
384
|
-
onCompaction(
|
|
385
|
-
fn: (messages: SessionMessage[]) => Promise<CompactResult | null>
|
|
386
|
-
): this;
|
|
387
|
-
/**
|
|
388
|
-
* Auto-compact when estimated token count exceeds the threshold.
|
|
389
|
-
* Propagated to all sessions. Requires `onCompaction()`.
|
|
390
|
-
*/
|
|
391
|
-
compactAfter(tokenThreshold: number, options?: CompactAfterOptions): this;
|
|
392
|
-
/**
|
|
393
|
-
* Handle failures from automatic compaction in managed sessions.
|
|
394
|
-
*/
|
|
395
|
-
onCompactionError(handler: CompactionErrorHandler): this;
|
|
396
|
-
/**
|
|
397
|
-
* Add a searchable context block that searches conversation history
|
|
398
|
-
* across all sessions managed by this manager.
|
|
399
|
-
*
|
|
400
|
-
* The model can use `search_context` to find relevant messages from
|
|
401
|
-
* any session. The block is readonly (no `set`).
|
|
402
|
-
*
|
|
403
|
-
* @example
|
|
404
|
-
* ```ts
|
|
405
|
-
* SessionManager.create(this)
|
|
406
|
-
* .withContext("memory", { maxTokens: 1100 })
|
|
407
|
-
* .withSearchableHistory("history")
|
|
408
|
-
* .withCachedPrompt();
|
|
409
|
-
* ```
|
|
410
|
-
*/
|
|
411
|
-
withSearchableHistory(label: string): this;
|
|
412
|
-
private _ensureReady;
|
|
413
|
-
private _ensureTable;
|
|
414
|
-
private _createHistoryProvider;
|
|
415
|
-
/** Get or create the Session instance for a session ID. */
|
|
416
|
-
getSession(sessionId: string): Session;
|
|
417
|
-
create(
|
|
418
|
-
name: string,
|
|
419
|
-
opts?: {
|
|
420
|
-
parentSessionId?: string;
|
|
421
|
-
model?: string;
|
|
422
|
-
source?: string;
|
|
423
|
-
}
|
|
424
|
-
): SessionInfo;
|
|
425
|
-
get(sessionId: string): SessionInfo | null;
|
|
426
|
-
list(): SessionInfo[];
|
|
427
|
-
delete(sessionId: string): Promise<void>;
|
|
428
|
-
rename(sessionId: string, name: string): void;
|
|
429
|
-
append(
|
|
430
|
-
sessionId: string,
|
|
431
|
-
message: SessionMessage,
|
|
432
|
-
parentId?: string
|
|
433
|
-
): Promise<string>;
|
|
434
|
-
upsert(
|
|
435
|
-
sessionId: string,
|
|
436
|
-
message: SessionMessage,
|
|
437
|
-
parentId?: string
|
|
438
|
-
): Promise<string>;
|
|
439
|
-
appendAll(
|
|
440
|
-
sessionId: string,
|
|
441
|
-
messages: SessionMessage[],
|
|
442
|
-
parentId?: string
|
|
443
|
-
): Promise<string | null>;
|
|
444
|
-
getHistory(sessionId: string, leafId?: string): Promise<SessionMessage[]>;
|
|
445
|
-
getMessageCount(sessionId: string): Promise<number>;
|
|
446
|
-
clearMessages(sessionId: string): Promise<void>;
|
|
447
|
-
deleteMessages(sessionId: string, messageIds: string[]): Promise<void>;
|
|
448
|
-
getBranches(sessionId: string, messageId: string): Promise<SessionMessage[]>;
|
|
449
|
-
/**
|
|
450
|
-
* Fork a session at a specific message, creating a new session
|
|
451
|
-
* with the history up to that point copied over.
|
|
452
|
-
*/
|
|
453
|
-
fork(
|
|
454
|
-
sessionId: string,
|
|
455
|
-
atMessageId: string,
|
|
456
|
-
newName: string
|
|
457
|
-
): Promise<SessionInfo>;
|
|
458
|
-
addCompaction(
|
|
459
|
-
sessionId: string,
|
|
460
|
-
summary: string,
|
|
461
|
-
fromId: string,
|
|
462
|
-
toId: string
|
|
463
|
-
): Promise<StoredCompaction>;
|
|
464
|
-
getCompactions(sessionId: string): Promise<StoredCompaction[]>;
|
|
465
|
-
compactAndSplit(
|
|
466
|
-
sessionId: string,
|
|
467
|
-
summary: string,
|
|
468
|
-
newName?: string
|
|
469
|
-
): Promise<SessionInfo>;
|
|
470
|
-
addUsage(
|
|
471
|
-
sessionId: string,
|
|
472
|
-
inputTokens: number,
|
|
473
|
-
outputTokens: number,
|
|
474
|
-
cost: number
|
|
475
|
-
): void;
|
|
476
|
-
search(
|
|
477
|
-
query: string,
|
|
478
|
-
options?: {
|
|
479
|
-
limit?: number;
|
|
480
|
-
}
|
|
481
|
-
): {
|
|
482
|
-
id: string;
|
|
483
|
-
role: string;
|
|
484
|
-
content: string;
|
|
485
|
-
createdAt: string;
|
|
486
|
-
}[];
|
|
487
|
-
tools(): ToolSet;
|
|
488
|
-
private _touch;
|
|
489
|
-
}
|
|
490
|
-
//#endregion
|
|
491
|
-
//#region src/experimental/memory/session/providers/agent-context.d.ts
|
|
492
|
-
declare class AgentContextProvider implements WritableContextProvider {
|
|
493
|
-
private agent;
|
|
494
|
-
private label;
|
|
495
|
-
private initialized;
|
|
496
|
-
constructor(agent: SqlProvider, label?: string);
|
|
497
|
-
init(label: string): void;
|
|
498
|
-
private ensureTable;
|
|
499
|
-
get(): Promise<string | null>;
|
|
500
|
-
set(content: string): Promise<void>;
|
|
501
|
-
}
|
|
502
|
-
//#endregion
|
|
503
|
-
//#region src/experimental/memory/session/providers/postgres-adapter.d.ts
|
|
504
|
-
/**
|
|
505
|
-
* Postgres connection adapter.
|
|
506
|
-
*
|
|
507
|
-
* Lets the Postgres-backed providers accept either:
|
|
508
|
-
* - a raw `pg.Client` (or any client with a compatible `query` method), or
|
|
509
|
-
* - the internal `PostgresConnection` interface used by tests and custom drivers.
|
|
510
|
-
*
|
|
511
|
-
* When a `pg`-style client is passed, `?` placeholders are rewritten to
|
|
512
|
-
* `$1, $2, ...` on the way through, so the providers can keep using the
|
|
513
|
-
* portable `?` syntax internally without users having to write a wrapper.
|
|
514
|
-
*/
|
|
515
|
-
/**
|
|
516
|
-
* Minimal connection interface used internally by the Postgres providers.
|
|
517
|
-
* Tests and custom drivers can implement this directly.
|
|
518
|
-
*/
|
|
519
|
-
interface PostgresConnection {
|
|
520
|
-
execute(
|
|
521
|
-
query: string,
|
|
522
|
-
args?: (string | number | boolean | null)[]
|
|
523
|
-
): Promise<{
|
|
524
|
-
rows: Record<string, unknown>[];
|
|
525
|
-
}>;
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Structural type matching `pg.Client` (and most `pg`-compatible pools).
|
|
529
|
-
* Accepts the subset of the real client that the providers need, so users
|
|
530
|
-
* can pass `new pg.Client({ connectionString: env.HYPERDRIVE.connectionString })`
|
|
531
|
-
* directly without a wrapper.
|
|
532
|
-
*/
|
|
533
|
-
interface PgClientLike {
|
|
534
|
-
query(
|
|
535
|
-
queryText: string,
|
|
536
|
-
values?: readonly unknown[]
|
|
537
|
-
): Promise<{
|
|
538
|
-
rows: Record<string, unknown>[];
|
|
539
|
-
}>;
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* Accepted client type across the Postgres providers.
|
|
543
|
-
*
|
|
544
|
-
* Use `pg.Client` (the recommended path for Hyperdrive):
|
|
545
|
-
* ```ts
|
|
546
|
-
* const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
|
|
547
|
-
* await client.connect();
|
|
548
|
-
* new PostgresSessionProvider(client, sessionId);
|
|
549
|
-
* ```
|
|
550
|
-
*
|
|
551
|
-
* Or implement `PostgresConnection` for tests / bespoke drivers.
|
|
552
|
-
*/
|
|
553
|
-
type PostgresClient = PostgresConnection | PgClientLike;
|
|
554
|
-
//#endregion
|
|
555
|
-
//#region src/experimental/memory/session/providers/postgres.d.ts
|
|
556
|
-
declare class PostgresSessionProvider implements SessionProvider {
|
|
557
|
-
private conn;
|
|
558
|
-
private sessionId;
|
|
559
|
-
/**
|
|
560
|
-
* @param client A raw `pg.Client` (recommended) or any `PostgresConnection`.
|
|
561
|
-
* Must already be connected — this provider never opens or closes the
|
|
562
|
-
* underlying client.
|
|
563
|
-
* @param sessionId Session identifier. Different ids are fully isolated
|
|
564
|
-
* rows within the shared tables. Defaults to `""`.
|
|
565
|
-
*/
|
|
566
|
-
constructor(client: PostgresClient, sessionId?: string);
|
|
567
|
-
getMessage(id: string): Promise<SessionMessage | null>;
|
|
568
|
-
getHistory(leafId?: string | null): Promise<SessionMessage[]>;
|
|
569
|
-
getLatestLeaf(): Promise<SessionMessage | null>;
|
|
570
|
-
getBranches(messageId: string): Promise<SessionMessage[]>;
|
|
571
|
-
getPathLength(leafId?: string | null): Promise<number>;
|
|
572
|
-
appendMessage(
|
|
573
|
-
message: SessionMessage,
|
|
574
|
-
parentId?: string | null
|
|
575
|
-
): Promise<void>;
|
|
576
|
-
updateMessage(message: SessionMessage): Promise<void>;
|
|
577
|
-
deleteMessages(messageIds: string[]): Promise<void>;
|
|
578
|
-
clearMessages(): Promise<void>;
|
|
579
|
-
addCompaction(
|
|
580
|
-
summary: string,
|
|
581
|
-
fromMessageId: string,
|
|
582
|
-
toMessageId: string
|
|
583
|
-
): Promise<StoredCompaction>;
|
|
584
|
-
getCompactions(): Promise<StoredCompaction[]>;
|
|
585
|
-
searchMessages(query: string, limit?: number): Promise<SearchResult[]>;
|
|
586
|
-
private latestLeafRow;
|
|
587
|
-
private applyCompactions;
|
|
588
|
-
private parse;
|
|
589
|
-
private parseRows;
|
|
590
|
-
/**
|
|
591
|
-
* Extract just the human-readable text from a message's JSON blob
|
|
592
|
-
* and store it in `text_content`, which feeds the generated `content_tsv`
|
|
593
|
-
* column used for FTS. The full structured message (parts, tool calls,
|
|
594
|
-
* metadata) is still stored verbatim in `content` — this is the source
|
|
595
|
-
* of truth. Indexing the raw JSON would return FTS hits on keys like
|
|
596
|
-
* `"role"`, `"parts"`, `"dynamic-tool"`, etc.
|
|
597
|
-
*/
|
|
598
|
-
private extractSearchableText;
|
|
599
|
-
}
|
|
600
|
-
//#endregion
|
|
601
|
-
//#region src/experimental/memory/session/providers/postgres-context.d.ts
|
|
602
|
-
declare class PostgresContextProvider implements WritableContextProvider {
|
|
603
|
-
private conn;
|
|
604
|
-
private label;
|
|
605
|
-
/**
|
|
606
|
-
* @param client A raw `pg.Client` (recommended) or any `PostgresConnection`.
|
|
607
|
-
* Must already be connected.
|
|
608
|
-
* @param label Block label used as the primary key row in
|
|
609
|
-
* `cf_agents_context_blocks`. Pass a session-scoped label (e.g.
|
|
610
|
-
* `` `memory_${sessionId}` ``) for per-session state.
|
|
611
|
-
*/
|
|
612
|
-
constructor(client: PostgresClient, label: string);
|
|
613
|
-
get(): Promise<string | null>;
|
|
614
|
-
set(content: string): Promise<void>;
|
|
615
|
-
}
|
|
616
|
-
//#endregion
|
|
617
|
-
//#region src/experimental/memory/session/providers/postgres-search.d.ts
|
|
618
|
-
declare class PostgresSearchProvider implements SearchProvider {
|
|
619
|
-
private conn;
|
|
620
|
-
private label;
|
|
621
|
-
/**
|
|
622
|
-
* @param client A raw `pg.Client` (recommended) or any `PostgresConnection`.
|
|
623
|
-
* Must already be connected.
|
|
624
|
-
*/
|
|
625
|
-
constructor(client: PostgresClient);
|
|
626
|
-
init(label: string): void;
|
|
627
|
-
get(): Promise<string | null>;
|
|
628
|
-
search(query: string): Promise<string | null>;
|
|
629
|
-
set(key: string, content: string): Promise<void>;
|
|
630
|
-
}
|
|
631
|
-
//#endregion
|
|
632
|
-
export {
|
|
633
|
-
AgentContextProvider,
|
|
634
|
-
AgentSearchProvider,
|
|
635
|
-
AgentSessionProvider,
|
|
636
|
-
type CompactAfterOptions,
|
|
637
|
-
type CompactionErrorHandler,
|
|
638
|
-
type ContextBlock,
|
|
639
|
-
type ContextConfig,
|
|
640
|
-
type ContextProvider,
|
|
641
|
-
type HistoryRowStat,
|
|
642
|
-
type PgClientLike,
|
|
643
|
-
type PostgresClient,
|
|
644
|
-
type PostgresConnection,
|
|
645
|
-
PostgresContextProvider,
|
|
646
|
-
PostgresSearchProvider,
|
|
647
|
-
PostgresSessionProvider,
|
|
648
|
-
R2SkillProvider,
|
|
649
|
-
type RecentHistoryResult,
|
|
650
|
-
type SearchProvider,
|
|
651
|
-
type SearchResult,
|
|
652
|
-
Session,
|
|
653
|
-
type SessionContextOptions,
|
|
654
|
-
type SessionInfo,
|
|
655
|
-
SessionManager,
|
|
656
|
-
type SessionManagerOptions,
|
|
657
|
-
type SessionMessage,
|
|
658
|
-
type SessionMessagePart,
|
|
659
|
-
type SessionOptions,
|
|
660
|
-
type SessionProvider,
|
|
661
|
-
type SessionTokenCounter,
|
|
662
|
-
type SessionTokenCounterInput,
|
|
663
|
-
type SkillProvider,
|
|
664
|
-
type SqlProvider,
|
|
665
|
-
type StoredCompaction,
|
|
666
|
-
type WritableContextProvider,
|
|
667
|
-
isSearchProvider,
|
|
668
|
-
isSkillProvider,
|
|
669
|
-
isWritableProvider
|
|
670
|
-
};
|
|
671
|
-
//# sourceMappingURL=index.d.ts.map
|