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
@@ -0,0 +1,441 @@
1
+ import { s as LifecycleCapability } from "../capability-runner-Be_-PLR1.js";
2
+ import {
3
+ a as RecentHistoryResult,
4
+ c as SessionChangeListener,
5
+ d as SessionRowStat,
6
+ f as SessionsOptions,
7
+ i as HistoryReadOptions,
8
+ l as SessionMessage,
9
+ m as WriteOptions,
10
+ n as AppendResult,
11
+ o as SearchResult,
12
+ p as StoredCompaction,
13
+ r as HistoryBatchReadOptions,
14
+ s as SessionChangeEvent,
15
+ t as AppendOptions,
16
+ u as SessionMessagePart
17
+ } from "../types-B7LojTe4.js";
18
+
19
+ //#region src/sessions/compaction-helpers.d.ts
20
+ /** Prefix for all compaction messages (overlays and summaries) */
21
+ declare const COMPACTION_PREFIX = "compaction_";
22
+ /** Check if a message is a compaction message */
23
+ declare function isCompactionMessage(msg: SessionMessage): boolean;
24
+ /**
25
+ * Result of a compaction function — describes the overlay to store.
26
+ */
27
+ interface CompactResult {
28
+ /** First message ID in the compacted range */
29
+ fromMessageId: string;
30
+ /** Last message ID in the compacted range */
31
+ toMessageId: string;
32
+ /** Summary text to store as the overlay */
33
+ summary: string;
34
+ }
35
+ interface CompactOptions {
36
+ /** Calls the model to summarize; receives a prompt, returns its text. */
37
+ summarize: (prompt: string) => Promise<string>;
38
+ /**
39
+ * Token budget for the recent tail kept verbatim. Older messages above the
40
+ * protected head are summarized into one overlay. Default 20,000.
41
+ */
42
+ keepRecentTokens?: number;
43
+ }
44
+ /**
45
+ * Reference compaction implementation.
46
+ *
47
+ * Implements the full hermes-style compaction algorithm:
48
+ * 1. Protect head messages (first N)
49
+ * 2. Protect tail by token budget (walk backward)
50
+ * 3. Align boundaries to tool call groups
51
+ * 4. Summarize middle section with LLM (structured format)
52
+ * 5. Iterative summary updates on subsequent compactions
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { createCompactFunction } from "agents/sessions";
57
+ *
58
+ * sessions
59
+ * .session()
60
+ * .onCompaction(
61
+ * createCompactFunction({
62
+ * summarize: (prompt) => generateText({ model, prompt }).then((r) => r.text)
63
+ * })
64
+ * )
65
+ * .compactAfter(100_000);
66
+ * ```
67
+ */
68
+ declare function createCompactFunction(
69
+ opts: CompactOptions
70
+ ): (messages: SessionMessage[]) => Promise<CompactResult | null>;
71
+ //#endregion
72
+ //#region src/sessions/io.d.ts
73
+ /** @internal SQLite and telemetry supplied by the Sessions capability. */
74
+ type SqlParam = ArrayBuffer | string | number | null;
75
+ interface SessionsIo {
76
+ /** Run a read and return every row. */
77
+ sql<T>(query: string, params: SqlParam[]): T[];
78
+ /** Run a write (or DDL) and return the rows it wrote. */
79
+ sqlWrite(query: string, params: SqlParam[]): number;
80
+ /** One synchronous SQLite transaction. */
81
+ transaction<T>(fn: () => T): T;
82
+ /** Capability telemetry event. */
83
+ emit(type: string, payload: Record<string, unknown>): void;
84
+ }
85
+ //#endregion
86
+ //#region src/sessions/core.d.ts
87
+ type UpdateOutcome = "missing" | "unchanged" | "updated";
88
+ declare class SessionsCore {
89
+ #private;
90
+ readonly io: SessionsIo;
91
+ constructor(options: SessionsOptions, io: SessionsIo);
92
+ ensureTables(): void;
93
+ /**
94
+ * Lift the legacy `assistant_*` message and compaction tables.
95
+ *
96
+ * The copy is pure SQL, so SQLite streams it rather than materializing rows
97
+ * in the isolate. Each source is then verified row by row against its
98
+ * destination and DROPPED: keeping tombstones would leave every upgraded
99
+ * object holding its history twice inside the same 10 GB. A table whose
100
+ * verification fails is left in place with a `session:migration:incomplete`
101
+ * event, and the method returns false so the caller leaves the schema
102
+ * version unstamped and retries on a later start. `assistant_config`
103
+ * belongs to Think, which lifts and drops it itself.
104
+ */
105
+ migrateLegacy(): boolean;
106
+ subscribe(listener: SessionChangeListener): () => void;
107
+ /**
108
+ * Dispatch after a durable write. A listener that throws must not turn a
109
+ * committed write into a rejected call, so failures are reported through
110
+ * telemetry and dispatch continues.
111
+ */
112
+ notify(event: SessionChangeEvent): Promise<void>;
113
+ exists(sessionId: string, id: string): boolean;
114
+ getMessage(sessionId: string, id: string): SessionMessage | null;
115
+ /**
116
+ * Drop the in-memory tail and token-total caches for a session. For a
117
+ * caller whose enclosing transaction rolled back after an append or update
118
+ * ran inside it: the rows are gone but the caches already moved. The next
119
+ * read re-derives both from storage.
120
+ */
121
+ forgetCaches(sessionId: string): void;
122
+ latestLeafId(sessionId: string): string | null;
123
+ getLatestLeaf(sessionId: string): SessionMessage | null;
124
+ getBranches(sessionId: string, messageId: string): SessionMessage[];
125
+ /**
126
+ * The active branch path as content-free rows, root → leaf. Recurses over
127
+ * (id, parent_id) only — carrying content through the recursive queue
128
+ * materializes the transcript several times inside SQLite (#1710).
129
+ * `bytes` counts the message row, its continuation rows, AND the payloads
130
+ * it points at, charged at the size they take once inlined, so a byte
131
+ * budget over these rows bounds real hydrated memory.
132
+ */
133
+ pathRowStats(sessionId: string, leafId?: string | null): SessionRowStat[];
134
+ /**
135
+ * Stream the path ending at `leafId` (default: active leaf), root → leaf
136
+ * (or leaf → root with `newestFirst`), compaction overlays collapsed. Peak
137
+ * memory is one bounded content window — never the whole transcript.
138
+ */
139
+ streamHistory(
140
+ sessionId: string,
141
+ options: HistoryReadOptions
142
+ ): AsyncGenerator<SessionMessage, void, undefined>;
143
+ getHistory(
144
+ sessionId: string,
145
+ options: HistoryReadOptions
146
+ ): Promise<SessionMessage[]>;
147
+ /**
148
+ * Byte-budgeted read of the most recent messages on the active branch
149
+ * path — the longest suffix whose stored size fits `maxContentBytes`.
150
+ *
151
+ * There is no message-count floor: one used to exist, and it admitted
152
+ * rows regardless of size, so a window of media-heavy messages could
153
+ * hydrate far past the limit meant to bound it. The newest message is
154
+ * always returned even if it alone exceeds the budget, since returning
155
+ * nothing is worse. Overlays whose anchors fall outside the window are
156
+ * skipped, showing the raw recent messages.
157
+ */
158
+ getRecentHistory(
159
+ sessionId: string,
160
+ maxContentBytes: number,
161
+ leafId?: string | null
162
+ ): Promise<RecentHistoryResult>;
163
+ /**
164
+ * Heuristic token estimate for the active path with compaction overlays
165
+ * applied: stamped per-row estimates, minus compacted spans, plus their
166
+ * summaries. Derived from content-free rows on each call; it gates cheap
167
+ * triggers only, and model-reported usage stays authoritative.
168
+ */
169
+ tokenEstimate(sessionId: string): number;
170
+ stripReservedMetadata(message: SessionMessage): SessionMessage;
171
+ /**
172
+ * Stamped row estimate: the part heuristic over the message as written,
173
+ * plus a weight per inline file payload so media never counts as zero.
174
+ */
175
+ estimateRowTokens(message: SessionMessage): number;
176
+ /**
177
+ * Durable append. The caller has already sanitized the message. Message,
178
+ * continuation, attachment, and FTS rows commit in one synchronous SQLite
179
+ * transaction. Returns the stored message: the input itself when it was
180
+ * inserted (extraction is lossless, so the two are identical), or the row
181
+ * already holding the id when it was not.
182
+ */
183
+ append(
184
+ sessionId: string,
185
+ message: SessionMessage,
186
+ parentId: string | null | undefined,
187
+ tokenEstimate: number
188
+ ): {
189
+ inserted: boolean;
190
+ message: SessionMessage;
191
+ };
192
+ /**
193
+ * Durable update of an existing row. An identical row writes nothing: no
194
+ * row, no continuation, no FTS, no event. The no-op guard compares the
195
+ * FULL reassembled content, not just the slice the message row holds.
196
+ */
197
+ update(
198
+ sessionId: string,
199
+ message: SessionMessage,
200
+ tokenEstimate: number
201
+ ): UpdateOutcome;
202
+ /**
203
+ * Delete rows, SPLICING children to their grandparent so a mid-chain
204
+ * delete never decapitates older history. Only surviving boundary children
205
+ * are rewired: a prefix delete writes one boundary child, not one child
206
+ * per deleted message.
207
+ */
208
+ deleteMessages(sessionId: string, messageIds: string[]): void;
209
+ clearMessages(sessionId: string): void;
210
+ addCompaction(
211
+ sessionId: string,
212
+ summary: string,
213
+ fromMessageId: string,
214
+ toMessageId: string
215
+ ): StoredCompaction;
216
+ getCompactions(sessionId: string): StoredCompaction[];
217
+ search(sessionId: string, query: string, limit: number): SearchResult[];
218
+ /**
219
+ * Import one historical message verbatim (migrations, cross-DO moves):
220
+ * explicit parent and timestamp, stamped estimate, no change-feed events.
221
+ */
222
+ /** Returns `false` when the id already exists and nothing was written. */
223
+ importMessage(
224
+ sessionId: string,
225
+ message: SessionMessage,
226
+ options: {
227
+ parentId: string | null;
228
+ createdAt: number;
229
+ }
230
+ ): boolean;
231
+ }
232
+ //#endregion
233
+ //#region src/sessions/handle.d.ts
234
+ /** Summarizes a branch into an overlay. */
235
+ type CompactionFunction = (
236
+ messages: SessionMessage[]
237
+ ) => Promise<CompactResult | null>;
238
+ declare class Session {
239
+ #private;
240
+ readonly sessionId: string;
241
+ /** @internal Constructed by the Sessions capability only. */
242
+ constructor(
243
+ sessionId: string,
244
+ core: SessionsCore,
245
+ ready: () => Promise<void>
246
+ );
247
+ /** Register the function `compact()` calls to summarize a branch. */
248
+ onCompaction(fn: CompactionFunction): this;
249
+ /**
250
+ * Auto-compact after an append once the estimated token count crosses the
251
+ * threshold. Requires `onCompaction()`. The estimate is derived from the
252
+ * stamped per-row estimates, never from the transcript.
253
+ */
254
+ compactAfter(tokenThreshold: number): this;
255
+ /**
256
+ * Stream the active branch path root → leaf (leaf → root with
257
+ * `newestFirst`) with compaction overlays applied. Peak memory is one
258
+ * bounded content window, never the whole transcript, and a consumer that
259
+ * breaks out early leaves the rows it never reached unread.
260
+ */
261
+ history(
262
+ options?: HistoryReadOptions
263
+ ): AsyncGenerator<SessionMessage, void, undefined>;
264
+ /**
265
+ * Stream history in bounded non-empty batches. Both message count and
266
+ * serialized bytes bound each batch; a single large message is yielded by
267
+ * itself.
268
+ */
269
+ historyBatches(
270
+ options?: HistoryBatchReadOptions
271
+ ): AsyncGenerator<SessionMessage[], void, undefined>;
272
+ /**
273
+ * Materialize the whole selected path. Prefer `history()` or
274
+ * `getRecentHistory()` inside a Durable Object: this holds every message
275
+ * of the branch in memory at once.
276
+ */
277
+ getHistory(options?: HistoryReadOptions): Promise<SessionMessage[]>;
278
+ /**
279
+ * Byte-budgeted read of the most recent messages on the active branch path
280
+ * (always at least the leaf). The budget counts each row, its continuation
281
+ * rows, and the payloads it points at, so it bounds hydrated memory (#1710).
282
+ */
283
+ getRecentHistory(
284
+ maxContentBytes: number,
285
+ options?: Pick<HistoryReadOptions, "leafId">
286
+ ): Promise<RecentHistoryResult>;
287
+ /**
288
+ * Per-row stored sizes (row plus continuation rows and attachments) and
289
+ * stamped token estimates for the active branch path (root → leaf)
290
+ * WITHOUT loading message content.
291
+ */
292
+ getHistoryRowStats(leafId?: string | null): Promise<SessionRowStat[]>;
293
+ getMessage(id: string): Promise<SessionMessage | null>;
294
+ getLatestLeaf(): Promise<SessionMessage | null>;
295
+ getBranches(messageId: string): Promise<SessionMessage[]>;
296
+ /**
297
+ * Full-text search over this session's text parts. The index is built on
298
+ * the first call and maintained from then on.
299
+ */
300
+ search(
301
+ query: string,
302
+ options?: {
303
+ limit?: number;
304
+ }
305
+ ): Promise<SearchResult[]>;
306
+ /**
307
+ * Append one message. Idempotent on id: a repeated append returns the row
308
+ * already stored and dispatches an `append` event with `inserted: false`.
309
+ */
310
+ appendMessage(
311
+ message: SessionMessage,
312
+ options?: AppendOptions
313
+ ): Promise<AppendResult>;
314
+ /**
315
+ * Update one stored row. Returns the stored form, or `null` when the id is
316
+ * not in this session. An unchanged message writes nothing and dispatches
317
+ * no event.
318
+ */
319
+ updateMessage(
320
+ message: SessionMessage,
321
+ options?: WriteOptions
322
+ ): Promise<SessionMessage | null>;
323
+ /**
324
+ * @internal Synchronous write aperture for same-isolate first-party
325
+ * machinery that must commit a message inside a caller-owned SQLite
326
+ * transaction — the stream cutover, where the finished message and the
327
+ * discard of its stream rows land together. Bypasses readiness (the
328
+ * caller owns startup ordering) and defers everything that follows a
329
+ * write — the change-feed dispatch and auto-compaction: call the returned
330
+ * `after()` once the transaction commits, or subscribers (the host's
331
+ * message mirror) never hear about the write. If the transaction rolls
332
+ * back after an `upsert` ran inside it, call `abandon()`: the write is
333
+ * gone but the in-memory tail and token-total caches already moved.
334
+ * Will break without notice; never use from application code.
335
+ */
336
+ __DO_NOT_USE_WILL_BREAK__sync(): {
337
+ upsert(
338
+ message: SessionMessage,
339
+ options?: AppendOptions
340
+ ): {
341
+ result: AppendResult;
342
+ after: () => Promise<void>;
343
+ };
344
+ abandon(): void;
345
+ };
346
+ upsertMessage(
347
+ message: SessionMessage,
348
+ options?: AppendOptions
349
+ ): Promise<AppendResult>;
350
+ /**
351
+ * Import one historical message verbatim (migrations, cross-object moves):
352
+ * explicit parent and timestamp. A row actually written dispatches an
353
+ * `import` change event so a host cache can mark itself stale; it is not
354
+ * an `append`, so a cache does not patch itself per imported row, and an
355
+ * id that already exists writes nothing and dispatches nothing.
356
+ */
357
+ importMessage(
358
+ message: SessionMessage,
359
+ options: {
360
+ parentId: string | null;
361
+ createdAt: number;
362
+ }
363
+ ): Promise<void>;
364
+ deleteMessages(messageIds: string[]): Promise<void>;
365
+ clearMessages(): Promise<void>;
366
+ /**
367
+ * Store an overlay directly. Dispatches a `compaction` change event: the
368
+ * rows are untouched, but what a path read returns has changed.
369
+ */
370
+ addCompaction(
371
+ summary: string,
372
+ fromMessageId: string,
373
+ toMessageId: string
374
+ ): Promise<StoredCompaction>;
375
+ getCompactions(): Promise<StoredCompaction[]>;
376
+ /**
377
+ * Run the registered compaction function and store the result as an
378
+ * overlay. When `leafId` is given, compact that root-to-leaf branch instead
379
+ * of the active branch. Requires `onCompaction()`. A compaction function
380
+ * that throws is reported through the `session:error` capability event and
381
+ * the call returns `null`.
382
+ */
383
+ compact(leafId?: string | null): Promise<CompactResult | null>;
384
+ }
385
+ //#endregion
386
+ //#region src/sessions/sessions.d.ts
387
+ /**
388
+ * Durable conversation history for a Lifecycle Object.
389
+ *
390
+ * `session()` returns a per-session handle for reads (streamed, byte
391
+ * budgeted), writes (sanitized, media offloaded), branch navigation, and
392
+ * compaction overlays. `subscribe()` is the change feed a cache-owning host
393
+ * mirrors.
394
+ *
395
+ * @experimental The API surface may change before stabilizing.
396
+ */
397
+ declare class Sessions extends LifecycleCapability {
398
+ #private;
399
+ constructor(options?: SessionsOptions);
400
+ /** Migrate session storage during Lifecycle startup. */
401
+ onStart(): Promise<void>;
402
+ /**
403
+ * The handle for one session. The default (empty) id is the primary path:
404
+ * in the one-object-per-conversation model a Durable Object holds exactly
405
+ * one session. Handles are cached, so per-session configuration (the
406
+ * compaction trigger) survives repeated calls.
407
+ */
408
+ session(sessionId?: string): Session;
409
+ /**
410
+ * Subscribe to the change feed: ordered dispatch after every durable
411
+ * write, with the stored message. The host cache mirror lives here;
412
+ * telemetry additionally flows through capability events.
413
+ */
414
+ subscribe(listener: SessionChangeListener): () => void;
415
+ }
416
+ //#endregion
417
+ export {
418
+ type AppendOptions,
419
+ type AppendResult,
420
+ COMPACTION_PREFIX,
421
+ type CompactOptions,
422
+ type CompactResult,
423
+ type CompactionFunction,
424
+ type HistoryBatchReadOptions,
425
+ type HistoryReadOptions,
426
+ type RecentHistoryResult,
427
+ type SearchResult,
428
+ Session,
429
+ type SessionChangeEvent,
430
+ type SessionChangeListener,
431
+ type SessionMessage,
432
+ type SessionMessagePart,
433
+ type SessionRowStat,
434
+ Sessions,
435
+ type SessionsOptions,
436
+ type StoredCompaction,
437
+ type WriteOptions,
438
+ createCompactFunction,
439
+ isCompactionMessage
440
+ };
441
+ //# sourceMappingURL=index.d.ts.map