agents 0.21.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.
Files changed (258) hide show
  1. package/README.md +21 -1
  2. package/dist/{agent-tool-types-CzGGB-20.d.ts → agent-routing-DE5zmCQ8.d.ts} +1844 -1336
  3. package/dist/agent-routing.d.ts +14 -0
  4. package/dist/agent-routing.js +187 -0
  5. package/dist/agent-routing.js.map +1 -0
  6. package/dist/agent-tool-types.d.ts +26 -26
  7. package/dist/{agent-tools-zR2d5uij.d.ts → agent-tools-DtXMTDGM.d.ts} +7 -7
  8. package/dist/agent-tools.d.ts +21 -21
  9. package/dist/agent-tools.js +2 -1
  10. package/dist/agent-tools.js.map +1 -1
  11. package/dist/browser/ai.js +6 -2
  12. package/dist/browser/ai.js.map +1 -1
  13. package/dist/browser/tanstack-ai.js.map +1 -1
  14. package/dist/callable-decorator-DP__HhBA.d.ts +72 -0
  15. package/dist/callable-decorator.d.ts +18 -0
  16. package/dist/callable-decorator.js +71 -0
  17. package/dist/callable-decorator.js.map +1 -0
  18. package/dist/capability-BjSKYpzg.js +42 -0
  19. package/dist/capability-BjSKYpzg.js.map +1 -0
  20. package/dist/capability-runner-Be_-PLR1.d.ts +459 -0
  21. package/dist/channel-Bnm4S7T2.d.ts +491 -0
  22. package/dist/channels/ai-sdk.d.ts +46 -0
  23. package/dist/channels/ai-sdk.js +120 -0
  24. package/dist/channels/ai-sdk.js.map +1 -0
  25. package/dist/channels/email.d.ts +95 -0
  26. package/dist/channels/email.js +323 -0
  27. package/dist/channels/email.js.map +1 -0
  28. package/dist/channels/index.d.ts +233 -0
  29. package/dist/channels/index.js +608 -0
  30. package/dist/channels/index.js.map +1 -0
  31. package/dist/channels/slack.d.ts +140 -0
  32. package/dist/channels/slack.js +614 -0
  33. package/dist/channels/slack.js.map +1 -0
  34. package/dist/channels/tanstack-ai.d.ts +39 -0
  35. package/dist/channels/tanstack-ai.js +17 -0
  36. package/dist/channels/tanstack-ai.js.map +1 -0
  37. package/dist/channels/telegram.d.ts +106 -0
  38. package/dist/channels/telegram.js +427 -0
  39. package/dist/channels/telegram.js.map +1 -0
  40. package/dist/channels/voice.d.ts +45 -0
  41. package/dist/channels/voice.js +122 -0
  42. package/dist/channels/voice.js.map +1 -0
  43. package/dist/chat/index.d.ts +2328 -2015
  44. package/dist/chat/index.js +891 -521
  45. package/dist/chat/index.js.map +1 -1
  46. package/dist/chat/react.d.ts +14 -1
  47. package/dist/chat/react.js +82 -52
  48. package/dist/chat/react.js.map +1 -1
  49. package/dist/chat/transport.js +1 -1
  50. package/dist/chat-sdk/index.d.ts +7 -7
  51. package/dist/chat-sdk/index.js +1 -1
  52. package/dist/{client-zqKcsyFa.js → client-jagG8a9_.js} +129 -37
  53. package/dist/client-jagG8a9_.js.map +1 -0
  54. package/dist/client.d.ts +1 -1
  55. package/dist/client.js +1 -1
  56. package/dist/{cloudflare-BduZwmYK.js → cloudflare-Dzvc7V2N.js} +10 -3
  57. package/dist/{cloudflare-BduZwmYK.js.map → cloudflare-Dzvc7V2N.js.map} +1 -1
  58. package/dist/context/index.d.ts +216 -0
  59. package/dist/context/index.js +454 -0
  60. package/dist/context/index.js.map +1 -0
  61. package/dist/current-agent-Da_C9a3b.d.ts +266 -0
  62. package/dist/current-agent-DhoDkSnH.js +51 -0
  63. package/dist/current-agent-DhoDkSnH.js.map +1 -0
  64. package/dist/diagnostics-BzvaX2UT.js +45 -0
  65. package/dist/diagnostics-BzvaX2UT.js.map +1 -0
  66. package/dist/diagnostics-C4jcz3VK.js +360 -0
  67. package/dist/diagnostics-C4jcz3VK.js.map +1 -0
  68. package/dist/{do-oauth-client-provider-VTZj2VtM.d.ts → do-oauth-client-provider-Tmf1vgKz.d.ts} +2 -2
  69. package/dist/{email-CL27preh.d.ts → email-7TatiTnl.d.ts} +38 -9
  70. package/dist/email-send.d.ts +15 -0
  71. package/dist/email-send.js +32 -0
  72. package/dist/email-send.js.map +1 -0
  73. package/dist/email.d.ts +14 -10
  74. package/dist/email.js.map +1 -1
  75. package/dist/{handler-stateless-C_bo-Ytq.d.ts → handler-stateless-DxYpJ_XF.d.ts} +3 -3
  76. package/dist/{handler-stateless-CIkKPETH.js → handler-stateless-VvrWSAVA.js} +5 -5
  77. package/dist/handler-stateless-VvrWSAVA.js.map +1 -0
  78. package/dist/index-BB0kqhIz.d.ts +101 -0
  79. package/dist/index-XDkuQ7zm.d.ts +89 -0
  80. package/dist/{index-BRnybD6X.d.ts → index-YSKgfgg9.d.ts} +21 -31
  81. package/dist/index.d.ts +113 -101
  82. package/dist/index.js +11 -7234
  83. package/dist/ingress-BfetZbMO.js +83 -0
  84. package/dist/ingress-BfetZbMO.js.map +1 -0
  85. package/dist/internal-CYlgHl1l.js +59 -0
  86. package/dist/internal-CYlgHl1l.js.map +1 -0
  87. package/dist/internal_context-BlxFEWfn.d.ts +19 -0
  88. package/dist/internal_context.d.ts +10 -4
  89. package/dist/internal_context.js +1 -10
  90. package/dist/{client-invoker-BNSZxAkv.d.ts → invoker-CG0_p_Wq.d.ts} +2 -2
  91. package/dist/{client-invoker-VNZ7X0nn.js → invoker-CHMnoxIA.js} +2 -2
  92. package/dist/invoker-CHMnoxIA.js.map +1 -0
  93. package/dist/lifecycle/index.d.ts +66 -0
  94. package/dist/lifecycle/index.js +4 -0
  95. package/dist/lifecycle-CMRGjZdw.js +1299 -0
  96. package/dist/lifecycle-CMRGjZdw.js.map +1 -0
  97. package/dist/mcp/{do-oauth-client-provider.d.ts → client/do-oauth-client-provider.d.ts} +1 -1
  98. package/dist/mcp/{do-oauth-client-provider.js → client/do-oauth-client-provider.js} +1 -1
  99. package/dist/mcp/client/do-oauth-client-provider.js.map +1 -0
  100. package/dist/mcp/client/index.d.ts +42 -0
  101. package/dist/mcp/{client.js → client/index.js} +1 -1
  102. package/dist/mcp/{x402.d.ts → client/x402.d.ts} +2 -2
  103. package/dist/mcp/{x402.js → client/x402.js} +2 -2
  104. package/dist/mcp/client/x402.js.map +1 -0
  105. package/dist/mcp/index.d.ts +36 -36
  106. package/dist/mcp/index.js +14 -16
  107. package/dist/mcp/index.js.map +1 -1
  108. package/dist/mcp/{server.d.ts → server/index.d.ts} +1 -1
  109. package/dist/mcp/{server.js → server/index.js} +1 -1
  110. package/dist/observability/ai/index.js +50 -35
  111. package/dist/observability/ai/index.js.map +1 -1
  112. package/dist/observability/index.d.ts +4 -4
  113. package/dist/observability/index.js +3 -50
  114. package/dist/observability/index.js.map +1 -1
  115. package/dist/{protocol-Dqc2MQxo.js → protocol-B0nh6KNf.js} +19 -21
  116. package/dist/protocol-B0nh6KNf.js.map +1 -0
  117. package/dist/react.d.ts +4 -4
  118. package/dist/react.js +1 -1
  119. package/dist/{retries-CAvxtG9d.d.ts → retries-D9Ds-1lz.d.ts} +17 -6
  120. package/dist/retries.d.ts +8 -6
  121. package/dist/retries.js +13 -1
  122. package/dist/retries.js.map +1 -1
  123. package/dist/routing/index.d.ts +137 -0
  124. package/dist/routing/index.js +244 -0
  125. package/dist/routing/index.js.map +1 -0
  126. package/dist/sanitize-D9TujEK8.js +79 -0
  127. package/dist/sanitize-D9TujEK8.js.map +1 -0
  128. package/dist/schedule.d.ts +25 -94
  129. package/dist/schedule.js +1 -98
  130. package/dist/schedule.js.map +1 -1
  131. package/dist/scheduler-DD9NdYbF.js +665 -0
  132. package/dist/scheduler-DD9NdYbF.js.map +1 -0
  133. package/dist/scheduler-Dwh85ZGl.d.ts +223 -0
  134. package/dist/schedules/index.d.ts +22 -0
  135. package/dist/schedules/index.js +2 -0
  136. package/dist/schedules/parser.d.ts +79 -0
  137. package/dist/schedules/parser.js +103 -0
  138. package/dist/schedules/parser.js.map +1 -0
  139. package/dist/sentence-chunker-BAidJ4DA.d.ts +68 -0
  140. package/dist/serializable.d.ts +1 -1
  141. package/dist/sessions/index.d.ts +441 -0
  142. package/dist/sessions/index.js +2063 -0
  143. package/dist/sessions/index.js.map +1 -0
  144. package/dist/skills/index.d.ts +99 -0
  145. package/dist/skills/index.js +254 -5
  146. package/dist/skills/index.js.map +1 -1
  147. package/dist/sql-error-CPY-GXyI.d.ts +12 -0
  148. package/dist/sql-error.d.ts +2 -0
  149. package/dist/sql-error.js +16 -0
  150. package/dist/sql-error.js.map +1 -0
  151. package/dist/src-DlSHshb2.js +6963 -0
  152. package/dist/src-DlSHshb2.js.map +1 -0
  153. package/dist/streams/index.d.ts +120 -0
  154. package/dist/streams/index.js +107 -0
  155. package/dist/streams/index.js.map +1 -0
  156. package/dist/streams-D6tJ0NN9.d.ts +370 -0
  157. package/dist/streams-DZKgAj9b.js +709 -0
  158. package/dist/streams-DZKgAj9b.js.map +1 -0
  159. package/dist/sub-routing.d.ts +12 -12
  160. package/dist/surface-bZZJqBka.js +17 -0
  161. package/dist/surface-bZZJqBka.js.map +1 -0
  162. package/dist/tasks/index.d.ts +64 -0
  163. package/dist/tasks/index.js +2 -0
  164. package/dist/tasks-BRJ5zgya.d.ts +517 -0
  165. package/dist/tasks-ylZgBjhj.js +1656 -0
  166. package/dist/tasks-ylZgBjhj.js.map +1 -0
  167. package/dist/text-segment-joiner-BtAFQSA_.js +57 -0
  168. package/dist/text-segment-joiner-BtAFQSA_.js.map +1 -0
  169. package/dist/text-stream-CpdiKrJB.js +272 -0
  170. package/dist/text-stream-CpdiKrJB.js.map +1 -0
  171. package/dist/tokens-nHAKcN6M.js +52 -0
  172. package/dist/tokens-nHAKcN6M.js.map +1 -0
  173. package/dist/tool-schema-CBjGPrsQ.js +31 -0
  174. package/dist/tool-schema-CBjGPrsQ.js.map +1 -0
  175. package/dist/types-B7LojTe4.d.ts +202 -0
  176. package/dist/types-_Faxb570.d.ts +439 -0
  177. package/dist/voice/client.d.ts +226 -0
  178. package/dist/voice/client.js +932 -0
  179. package/dist/voice/client.js.map +1 -0
  180. package/dist/voice/errors.d.ts +43 -0
  181. package/dist/voice/errors.js +41 -0
  182. package/dist/voice/errors.js.map +1 -0
  183. package/dist/voice/index.d.ts +271 -0
  184. package/dist/voice/index.js +1812 -0
  185. package/dist/voice/index.js.map +1 -0
  186. package/dist/voice/react.d.ts +167 -0
  187. package/dist/voice/react.js +234 -0
  188. package/dist/voice/react.js.map +1 -0
  189. package/dist/voice/sfu.d.ts +71 -0
  190. package/dist/voice/sfu.js +157 -0
  191. package/dist/voice/sfu.js.map +1 -0
  192. package/dist/voice/text.d.ts +6 -0
  193. package/dist/voice/text.js +2 -0
  194. package/dist/voice/types.d.ts +58 -0
  195. package/dist/voice/types.js +18 -0
  196. package/dist/voice/types.js.map +1 -0
  197. package/dist/voice/workers-ai.d.ts +136 -0
  198. package/dist/voice/workers-ai.js +568 -0
  199. package/dist/voice/workers-ai.js.map +1 -0
  200. package/dist/websockets/index.d.ts +192 -0
  201. package/dist/websockets/index.js +2 -0
  202. package/dist/websockets-DUfRHPRq.js +502 -0
  203. package/dist/websockets-DUfRHPRq.js.map +1 -0
  204. package/dist/workflow-types.d.ts +25 -25
  205. package/dist/workflows.d.ts +22 -22
  206. package/dist/workflows.js +2 -1
  207. package/dist/workflows.js.map +1 -1
  208. package/dist/{ws-chat-transport-CIoOBbO7.js → ws-chat-transport-rWwta645.js} +152 -15
  209. package/dist/ws-chat-transport-rWwta645.js.map +1 -0
  210. package/docs/agent-class.md +29 -87
  211. package/docs/agent-tools.md +2 -1
  212. package/docs/channels.md +323 -0
  213. package/docs/chat-agents.md +19 -25
  214. package/docs/context.md +131 -0
  215. package/docs/durable-execution.md +1 -1
  216. package/docs/http-websockets.md +1 -11
  217. package/docs/human-in-the-loop.md +1 -1
  218. package/docs/index.md +16 -12
  219. package/docs/lifecycle.md +370 -0
  220. package/docs/long-running-agents.md +4 -6
  221. package/docs/mcp-client.md +55 -0
  222. package/docs/mcp-servers.md +5 -1
  223. package/docs/observability.md +11 -11
  224. package/docs/resumable-streaming.md +2 -2
  225. package/docs/routing.md +105 -0
  226. package/docs/scheduling.md +175 -15
  227. package/docs/server-driven-messages.md +1 -1
  228. package/docs/sessions.md +237 -871
  229. package/docs/streams.md +213 -0
  230. package/docs/sub-agents.md +185 -125
  231. package/docs/tasks.md +246 -0
  232. package/docs/voice.md +745 -0
  233. package/package.json +144 -33
  234. package/dist/cli/index.js +0 -26
  235. package/dist/cli/index.js.map +0 -1
  236. package/dist/client-invoker-VNZ7X0nn.js.map +0 -1
  237. package/dist/client-zqKcsyFa.js.map +0 -1
  238. package/dist/compaction-helpers-iiKMr2TQ.js +0 -340
  239. package/dist/compaction-helpers-iiKMr2TQ.js.map +0 -1
  240. package/dist/compaction-helpers-wUz6M3us.d.ts +0 -621
  241. package/dist/experimental/memory/session/index.d.ts +0 -670
  242. package/dist/experimental/memory/session/index.js +0 -2374
  243. package/dist/experimental/memory/session/index.js.map +0 -1
  244. package/dist/experimental/memory/utils/index.d.ts +0 -96
  245. package/dist/experimental/memory/utils/index.js +0 -79
  246. package/dist/experimental/memory/utils/index.js.map +0 -1
  247. package/dist/handler-stateless-CIkKPETH.js.map +0 -1
  248. package/dist/index.js.map +0 -1
  249. package/dist/internal_context-Dg4Cgjcu.d.ts +0 -37
  250. package/dist/internal_context.js.map +0 -1
  251. package/dist/mcp/client.d.ts +0 -42
  252. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  253. package/dist/mcp/x402.js.map +0 -1
  254. package/dist/protocol-Dqc2MQxo.js.map +0 -1
  255. package/dist/tool-output-truncation-CNnnGZQ3.js +0 -98
  256. package/dist/tool-output-truncation-CNnnGZQ3.js.map +0 -1
  257. package/dist/ws-chat-transport-CIoOBbO7.js.map +0 -1
  258. /package/dist/{cli/index.d.ts → index-BVVgDSdq.d.ts} +0 -0
@@ -1,670 +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
- * Requires `onCompaction()` to be called first.
261
- */
262
- compact(): Promise<CompactResult | null>;
263
- getContextBlock(label: string): ContextBlock | null;
264
- getContextBlocks(): ContextBlock[];
265
- replaceContextBlock(label: string, content: string): Promise<ContextBlock>;
266
- appendContextBlock(label: string, content: string): Promise<ContextBlock>;
267
- /**
268
- * Dynamically register a new context block after session initialization.
269
- *
270
- * This is a **builder / runtime API**, not an LLM tool. The LLM writes
271
- * into existing context blocks via the `set_context` tool (see
272
- * `ContextBlocks.tools()`); it cannot declare new blocks itself. This
273
- * method is how extension / host code contributes blocks at runtime
274
- * (e.g. an extension's `onLoad` handler registering its own memory block).
275
- *
276
- * The block's provider is initialized and loaded immediately.
277
- * Call `refreshSystemPrompt()` afterward to include the new block
278
- * in the system prompt.
279
- *
280
- * Note: When called without a provider, auto-wires to SQLite via
281
- * AgentContextProvider. Requires the session to have been created
282
- * via `Session.create(agent)` (not the direct constructor).
283
- */
284
- addContext(
285
- label: string,
286
- options?: SessionContextOptions
287
- ): Promise<ContextBlock>;
288
- /**
289
- * Remove a dynamically registered context block.
290
- * Used during extension unload cleanup.
291
- *
292
- * Returns true if the block existed and was removed.
293
- * Call `refreshSystemPrompt()` afterward to rebuild the prompt
294
- * without the removed block.
295
- */
296
- removeContext(label: string): boolean;
297
- /**
298
- * Unload a previously loaded skill, reclaiming context space.
299
- * The tool result in conversation history is replaced with a short marker.
300
- *
301
- * Async so that the session's background skill-state restore (which
302
- * reads conversation history) is awaited first — otherwise a freshly
303
- * rehydrated DO could report "not loaded" for a skill that's actually
304
- * present in history.
305
- */
306
- unloadSkill(label: string, key: string): Promise<boolean>;
307
- /**
308
- * Get currently loaded skill keys (as "label:key" strings).
309
- * Async for the same reason as `unloadSkill` — must wait for restore.
310
- */
311
- getLoadedSkillKeys(): Promise<Set<string>>;
312
- freezeSystemPrompt(): Promise<string>;
313
- refreshSystemPrompt(): Promise<string>;
314
- search(
315
- query: string,
316
- options?: {
317
- limit?: number;
318
- }
319
- ): Promise<
320
- Array<{
321
- id: string;
322
- role: string;
323
- content: string;
324
- createdAt?: string;
325
- }>
326
- >;
327
- /** Returns set_context and load_context tools. */
328
- tools(): Promise<ToolSet>;
329
- }
330
- //#endregion
331
- //#region src/experimental/memory/session/manager.d.ts
332
- interface SessionInfo {
333
- id: string;
334
- name: string;
335
- parent_session_id: string | null;
336
- model: string | null;
337
- source: string | null;
338
- input_tokens: number;
339
- output_tokens: number;
340
- estimated_cost: number;
341
- end_reason: string | null;
342
- created_at: string;
343
- updated_at: string;
344
- }
345
- interface SessionManagerOptions {}
346
- declare class SessionManager {
347
- private agent;
348
- private _pending;
349
- private _cachedPrompt?;
350
- private _compactionFn?;
351
- private _tokenThreshold?;
352
- private _tokenCounter?;
353
- private _compactionErrorHandler?;
354
- private _sessions;
355
- private _historyLabel?;
356
- private _tableReady;
357
- private _ready;
358
- constructor(agent: SqlProvider, _options?: SessionManagerOptions);
359
- /**
360
- * Chainable SessionManager creation with auto-wired context for all sessions.
361
- *
362
- * @example
363
- * ```ts
364
- * const manager = SessionManager.create(this)
365
- * .withContext("soul", { provider: { get: async () => "You are helpful." } })
366
- * .withContext("memory", { description: "Learned facts", maxTokens: 1100 })
367
- * .withCachedPrompt()
368
- * .compactAfter(100_000);
369
- *
370
- * // Each getSession(id) auto-creates namespaced providers:
371
- * // memory key: "memory_<sessionId>"
372
- * // prompt key: "_system_prompt_<sessionId>"
373
- * const session = manager.getSession("chat-123");
374
- * ```
375
- */
376
- static create(agent: SqlProvider): SessionManager;
377
- withContext(label: string, options?: SessionContextOptions): this;
378
- withCachedPrompt(provider?: WritableContextProvider): this;
379
- /**
380
- * Register a compaction function propagated to all sessions.
381
- * Called by `Session.compact()` to compress message history.
382
- */
383
- onCompaction(
384
- fn: (messages: SessionMessage[]) => Promise<CompactResult | null>
385
- ): this;
386
- /**
387
- * Auto-compact when estimated token count exceeds the threshold.
388
- * Propagated to all sessions. Requires `onCompaction()`.
389
- */
390
- compactAfter(tokenThreshold: number, options?: CompactAfterOptions): this;
391
- /**
392
- * Handle failures from automatic compaction in managed sessions.
393
- */
394
- onCompactionError(handler: CompactionErrorHandler): this;
395
- /**
396
- * Add a searchable context block that searches conversation history
397
- * across all sessions managed by this manager.
398
- *
399
- * The model can use `search_context` to find relevant messages from
400
- * any session. The block is readonly (no `set`).
401
- *
402
- * @example
403
- * ```ts
404
- * SessionManager.create(this)
405
- * .withContext("memory", { maxTokens: 1100 })
406
- * .withSearchableHistory("history")
407
- * .withCachedPrompt();
408
- * ```
409
- */
410
- withSearchableHistory(label: string): this;
411
- private _ensureReady;
412
- private _ensureTable;
413
- private _createHistoryProvider;
414
- /** Get or create the Session instance for a session ID. */
415
- getSession(sessionId: string): Session;
416
- create(
417
- name: string,
418
- opts?: {
419
- parentSessionId?: string;
420
- model?: string;
421
- source?: string;
422
- }
423
- ): SessionInfo;
424
- get(sessionId: string): SessionInfo | null;
425
- list(): SessionInfo[];
426
- delete(sessionId: string): Promise<void>;
427
- rename(sessionId: string, name: string): void;
428
- append(
429
- sessionId: string,
430
- message: SessionMessage,
431
- parentId?: string
432
- ): Promise<string>;
433
- upsert(
434
- sessionId: string,
435
- message: SessionMessage,
436
- parentId?: string
437
- ): Promise<string>;
438
- appendAll(
439
- sessionId: string,
440
- messages: SessionMessage[],
441
- parentId?: string
442
- ): Promise<string | null>;
443
- getHistory(sessionId: string, leafId?: string): Promise<SessionMessage[]>;
444
- getMessageCount(sessionId: string): Promise<number>;
445
- clearMessages(sessionId: string): Promise<void>;
446
- deleteMessages(sessionId: string, messageIds: string[]): Promise<void>;
447
- getBranches(sessionId: string, messageId: string): Promise<SessionMessage[]>;
448
- /**
449
- * Fork a session at a specific message, creating a new session
450
- * with the history up to that point copied over.
451
- */
452
- fork(
453
- sessionId: string,
454
- atMessageId: string,
455
- newName: string
456
- ): Promise<SessionInfo>;
457
- addCompaction(
458
- sessionId: string,
459
- summary: string,
460
- fromId: string,
461
- toId: string
462
- ): Promise<StoredCompaction>;
463
- getCompactions(sessionId: string): Promise<StoredCompaction[]>;
464
- compactAndSplit(
465
- sessionId: string,
466
- summary: string,
467
- newName?: string
468
- ): Promise<SessionInfo>;
469
- addUsage(
470
- sessionId: string,
471
- inputTokens: number,
472
- outputTokens: number,
473
- cost: number
474
- ): void;
475
- search(
476
- query: string,
477
- options?: {
478
- limit?: number;
479
- }
480
- ): {
481
- id: string;
482
- role: string;
483
- content: string;
484
- createdAt: string;
485
- }[];
486
- tools(): ToolSet;
487
- private _touch;
488
- }
489
- //#endregion
490
- //#region src/experimental/memory/session/providers/agent-context.d.ts
491
- declare class AgentContextProvider implements WritableContextProvider {
492
- private agent;
493
- private label;
494
- private initialized;
495
- constructor(agent: SqlProvider, label?: string);
496
- init(label: string): void;
497
- private ensureTable;
498
- get(): Promise<string | null>;
499
- set(content: string): Promise<void>;
500
- }
501
- //#endregion
502
- //#region src/experimental/memory/session/providers/postgres-adapter.d.ts
503
- /**
504
- * Postgres connection adapter.
505
- *
506
- * Lets the Postgres-backed providers accept either:
507
- * - a raw `pg.Client` (or any client with a compatible `query` method), or
508
- * - the internal `PostgresConnection` interface used by tests and custom drivers.
509
- *
510
- * When a `pg`-style client is passed, `?` placeholders are rewritten to
511
- * `$1, $2, ...` on the way through, so the providers can keep using the
512
- * portable `?` syntax internally without users having to write a wrapper.
513
- */
514
- /**
515
- * Minimal connection interface used internally by the Postgres providers.
516
- * Tests and custom drivers can implement this directly.
517
- */
518
- interface PostgresConnection {
519
- execute(
520
- query: string,
521
- args?: (string | number | boolean | null)[]
522
- ): Promise<{
523
- rows: Record<string, unknown>[];
524
- }>;
525
- }
526
- /**
527
- * Structural type matching `pg.Client` (and most `pg`-compatible pools).
528
- * Accepts the subset of the real client that the providers need, so users
529
- * can pass `new pg.Client({ connectionString: env.HYPERDRIVE.connectionString })`
530
- * directly without a wrapper.
531
- */
532
- interface PgClientLike {
533
- query(
534
- queryText: string,
535
- values?: readonly unknown[]
536
- ): Promise<{
537
- rows: Record<string, unknown>[];
538
- }>;
539
- }
540
- /**
541
- * Accepted client type across the Postgres providers.
542
- *
543
- * Use `pg.Client` (the recommended path for Hyperdrive):
544
- * ```ts
545
- * const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
546
- * await client.connect();
547
- * new PostgresSessionProvider(client, sessionId);
548
- * ```
549
- *
550
- * Or implement `PostgresConnection` for tests / bespoke drivers.
551
- */
552
- type PostgresClient = PostgresConnection | PgClientLike;
553
- //#endregion
554
- //#region src/experimental/memory/session/providers/postgres.d.ts
555
- declare class PostgresSessionProvider implements SessionProvider {
556
- private conn;
557
- private sessionId;
558
- /**
559
- * @param client A raw `pg.Client` (recommended) or any `PostgresConnection`.
560
- * Must already be connected — this provider never opens or closes the
561
- * underlying client.
562
- * @param sessionId Session identifier. Different ids are fully isolated
563
- * rows within the shared tables. Defaults to `""`.
564
- */
565
- constructor(client: PostgresClient, sessionId?: string);
566
- getMessage(id: string): Promise<SessionMessage | null>;
567
- getHistory(leafId?: string | null): Promise<SessionMessage[]>;
568
- getLatestLeaf(): Promise<SessionMessage | null>;
569
- getBranches(messageId: string): Promise<SessionMessage[]>;
570
- getPathLength(leafId?: string | null): Promise<number>;
571
- appendMessage(
572
- message: SessionMessage,
573
- parentId?: string | null
574
- ): Promise<void>;
575
- updateMessage(message: SessionMessage): Promise<void>;
576
- deleteMessages(messageIds: string[]): Promise<void>;
577
- clearMessages(): Promise<void>;
578
- addCompaction(
579
- summary: string,
580
- fromMessageId: string,
581
- toMessageId: string
582
- ): Promise<StoredCompaction>;
583
- getCompactions(): Promise<StoredCompaction[]>;
584
- searchMessages(query: string, limit?: number): Promise<SearchResult[]>;
585
- private latestLeafRow;
586
- private applyCompactions;
587
- private parse;
588
- private parseRows;
589
- /**
590
- * Extract just the human-readable text from a message's JSON blob
591
- * and store it in `text_content`, which feeds the generated `content_tsv`
592
- * column used for FTS. The full structured message (parts, tool calls,
593
- * metadata) is still stored verbatim in `content` — this is the source
594
- * of truth. Indexing the raw JSON would return FTS hits on keys like
595
- * `"role"`, `"parts"`, `"dynamic-tool"`, etc.
596
- */
597
- private extractSearchableText;
598
- }
599
- //#endregion
600
- //#region src/experimental/memory/session/providers/postgres-context.d.ts
601
- declare class PostgresContextProvider implements WritableContextProvider {
602
- private conn;
603
- private label;
604
- /**
605
- * @param client A raw `pg.Client` (recommended) or any `PostgresConnection`.
606
- * Must already be connected.
607
- * @param label Block label used as the primary key row in
608
- * `cf_agents_context_blocks`. Pass a session-scoped label (e.g.
609
- * `` `memory_${sessionId}` ``) for per-session state.
610
- */
611
- constructor(client: PostgresClient, label: string);
612
- get(): Promise<string | null>;
613
- set(content: string): Promise<void>;
614
- }
615
- //#endregion
616
- //#region src/experimental/memory/session/providers/postgres-search.d.ts
617
- declare class PostgresSearchProvider implements SearchProvider {
618
- private conn;
619
- private label;
620
- /**
621
- * @param client A raw `pg.Client` (recommended) or any `PostgresConnection`.
622
- * Must already be connected.
623
- */
624
- constructor(client: PostgresClient);
625
- init(label: string): void;
626
- get(): Promise<string | null>;
627
- search(query: string): Promise<string | null>;
628
- set(key: string, content: string): Promise<void>;
629
- }
630
- //#endregion
631
- export {
632
- AgentContextProvider,
633
- AgentSearchProvider,
634
- AgentSessionProvider,
635
- type CompactAfterOptions,
636
- type CompactionErrorHandler,
637
- type ContextBlock,
638
- type ContextConfig,
639
- type ContextProvider,
640
- type HistoryRowStat,
641
- type PgClientLike,
642
- type PostgresClient,
643
- type PostgresConnection,
644
- PostgresContextProvider,
645
- PostgresSearchProvider,
646
- PostgresSessionProvider,
647
- R2SkillProvider,
648
- type RecentHistoryResult,
649
- type SearchProvider,
650
- type SearchResult,
651
- Session,
652
- type SessionContextOptions,
653
- type SessionInfo,
654
- SessionManager,
655
- type SessionManagerOptions,
656
- type SessionMessage,
657
- type SessionMessagePart,
658
- type SessionOptions,
659
- type SessionProvider,
660
- type SessionTokenCounter,
661
- type SessionTokenCounterInput,
662
- type SkillProvider,
663
- type SqlProvider,
664
- type StoredCompaction,
665
- type WritableContextProvider,
666
- isSearchProvider,
667
- isSkillProvider,
668
- isWritableProvider
669
- };
670
- //# sourceMappingURL=index.d.ts.map