agents 0.25.0 → 0.27.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 (238) hide show
  1. package/README.md +8 -9
  2. package/dist/{agent-routing-0DR0Tk2v.d.ts → agent-routing-Bhdbvf7s.d.ts} +13 -8
  3. package/dist/agent-routing.d.ts +1 -1
  4. package/dist/agent-tool-types.d.ts +1 -1
  5. package/dist/{agent-tools-YrATZJu2.d.ts → agent-tools-bJZwBMfq.d.ts} +2 -2
  6. package/dist/agent-tools.d.ts +1 -1
  7. package/dist/ai-sdk-OoGkFy3s.js +2444 -0
  8. package/dist/ai-sdk-OoGkFy3s.js.map +1 -0
  9. package/dist/apply-chunks-1FheRb9W.js +99 -0
  10. package/dist/apply-chunks-1FheRb9W.js.map +1 -0
  11. package/dist/broadcast-state-CEyI4uAK.js +69 -0
  12. package/dist/broadcast-state-CEyI4uAK.js.map +1 -0
  13. package/dist/browser/ai-sdk.d.ts +1 -1
  14. package/dist/browser/ai-sdk.js +2 -2
  15. package/dist/browser/ai-sdk.js.map +1 -1
  16. package/dist/browser/index.d.ts +1 -1
  17. package/dist/browser/tanstack-ai.d.ts +1 -1
  18. package/dist/browser/tanstack-ai.js +1 -1
  19. package/dist/{browser-DE3d-RLk.d.ts → browser-tmkcAAI3.d.ts} +2 -2
  20. package/dist/{browser-tool-DuNdlwZ9.d.ts → browser-tool-Bn-nzJQI.d.ts} +3 -3
  21. package/dist/{browser-tool-CQ10e6Kj.js → browser-tool-CBqs6hqa.js} +58 -18
  22. package/dist/browser-tool-CBqs6hqa.js.map +1 -0
  23. package/dist/capability-B4WbF81e.js.map +1 -1
  24. package/dist/{capability-runner-DBAnGr6L.d.ts → capability-runner-O5VbQzqg.d.ts} +9 -1
  25. package/dist/channel-Bak_6zDP.d.ts +333 -0
  26. package/dist/chat/index.d.ts +11 -9
  27. package/dist/chat/index.js +5 -194
  28. package/dist/chat/index.js.map +1 -1
  29. package/dist/chat/react.d.ts +2 -4
  30. package/dist/chat/react.js +3 -1
  31. package/dist/chat/react.js.map +1 -1
  32. package/dist/chat-sdk/index.d.ts +1 -1
  33. package/dist/chat-sdk/index.js +1 -1
  34. package/dist/cli.js +144 -0
  35. package/dist/{client-fyQrLGkD.js → client-1tEQ1Oqz.js} +27 -2
  36. package/dist/{client-fyQrLGkD.js.map → client-1tEQ1Oqz.js.map} +1 -1
  37. package/dist/{client-je3koD9Z.d.ts → client-DS3Dz9l0.d.ts} +2 -2
  38. package/dist/client-tools-aIBO0Fk7.d.ts +53 -0
  39. package/dist/client.d.ts +1 -1
  40. package/dist/conversations-DH0ut_8n.d.ts +192 -0
  41. package/dist/{current-agent-vAk_5JMt.d.ts → current-agent-C07C5o5Y.d.ts} +3 -3
  42. package/dist/daemon-core-Buubj-y1.js +481 -0
  43. package/dist/daemon-core-Buubj-y1.js.map +1 -0
  44. package/dist/daemon-core-CbohVPAu.d.ts +132 -0
  45. package/dist/{do-oauth-client-provider-Tmf1vgKz.d.ts → do-oauth-client-provider-DfsUcpc3.d.ts} +7 -1
  46. package/dist/{durable-object-lifecycle-HhgOMWq9.d.ts → durable-object-lifecycle-DRqp475_.d.ts} +2 -2
  47. package/dist/{channels/email.d.ts → experimental/channels/email/index.d.ts} +25 -12
  48. package/dist/{channels/email.js → experimental/channels/email/index.js} +13 -35
  49. package/dist/experimental/channels/email/index.js.map +1 -0
  50. package/dist/experimental/channels/index.d.ts +270 -0
  51. package/dist/experimental/channels/index.js +1186 -0
  52. package/dist/experimental/channels/index.js.map +1 -0
  53. package/dist/{channels/slack.d.ts → experimental/channels/slack/index.d.ts} +19 -9
  54. package/dist/experimental/channels/slack/index.js +267 -0
  55. package/dist/experimental/channels/slack/index.js.map +1 -0
  56. package/dist/{channels/telegram.d.ts → experimental/channels/telegram/index.d.ts} +19 -9
  57. package/dist/experimental/channels/telegram/index.js +198 -0
  58. package/dist/experimental/channels/telegram/index.js.map +1 -0
  59. package/dist/experimental/channels/web/ai-sdk.d.ts +55 -0
  60. package/dist/experimental/channels/web/ai-sdk.js +266 -0
  61. package/dist/experimental/channels/web/ai-sdk.js.map +1 -0
  62. package/dist/experimental/channels/web/client.d.ts +97 -0
  63. package/dist/experimental/channels/web/client.js +349 -0
  64. package/dist/experimental/channels/web/client.js.map +1 -0
  65. package/dist/experimental/channels/web/index.d.ts +189 -0
  66. package/dist/experimental/channels/web/index.js +332 -0
  67. package/dist/experimental/channels/web/index.js.map +1 -0
  68. package/dist/gateway-BDC07gYO.d.ts +100 -0
  69. package/dist/handle-zAzh0UW2.d.ts +460 -0
  70. package/dist/harness/ai-sdk/index.d.ts +175 -0
  71. package/dist/harness/ai-sdk/index.js +605 -0
  72. package/dist/harness/ai-sdk/index.js.map +1 -0
  73. package/dist/harness/container/daemon/index.d.ts +76 -0
  74. package/dist/harness/container/daemon/index.js +3 -0
  75. package/dist/harness/container/index.d.ts +740 -0
  76. package/dist/harness/container/index.js +2152 -0
  77. package/dist/harness/container/index.js.map +1 -0
  78. package/dist/harness/container/runtime/index.d.ts +144 -0
  79. package/dist/harness/container/runtime/index.js +1082 -0
  80. package/dist/harness/container/runtime/index.js.map +1 -0
  81. package/dist/harness/opencode/index.d.ts +369 -0
  82. package/dist/harness/opencode/index.js +1072 -0
  83. package/dist/harness/opencode/index.js.map +1 -0
  84. package/dist/{harnesses → harness}/pi/index.d.ts +85 -88
  85. package/dist/{harnesses → harness}/pi/index.js +196 -77
  86. package/dist/harness/pi/index.js.map +1 -0
  87. package/dist/harness/store/index.d.ts +24 -0
  88. package/dist/harness/store/index.js +2 -0
  89. package/dist/harness/think/index.d.ts +821 -0
  90. package/dist/harness/think/index.js +2529 -0
  91. package/dist/harness/think/index.js.map +1 -0
  92. package/dist/harness-B6B9S3rb.d.ts +203 -0
  93. package/dist/{images-iiTDSyRu.js → images-Ce9SCu3X.js} +2 -248
  94. package/dist/images-Ce9SCu3X.js.map +1 -0
  95. package/dist/{index-BreL0YrQ.d.ts → index-D0A5tbWu.d.ts} +2 -2
  96. package/dist/index-Ib_4dwOo.d.ts +200 -0
  97. package/dist/index.d.ts +5 -5
  98. package/dist/index.js +2 -2
  99. package/dist/ingress-EFbrS547.js +9 -0
  100. package/dist/ingress-EFbrS547.js.map +1 -0
  101. package/dist/input-schema-DNrpTu49.js +23 -0
  102. package/dist/input-schema-DNrpTu49.js.map +1 -0
  103. package/dist/internal-kmw70xwR.js +46 -0
  104. package/dist/internal-kmw70xwR.js.map +1 -0
  105. package/dist/internal_context.d.ts +1 -1
  106. package/dist/lifecycle/index.d.ts +3 -3
  107. package/dist/mcp/client/do-oauth-client-provider.d.ts +1 -1
  108. package/dist/mcp/client/do-oauth-client-provider.js +9 -0
  109. package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
  110. package/dist/mcp/client/index.d.ts +1 -1
  111. package/dist/mcp/client/index.js +1 -1
  112. package/dist/mcp/client/x402.d.ts +35 -4
  113. package/dist/mcp/client/x402.js +24 -3
  114. package/dist/mcp/client/x402.js.map +1 -1
  115. package/dist/mcp/index.d.ts +1 -1
  116. package/dist/mcp/index.js +2 -2
  117. package/dist/models/ai-sdk/index.d.ts +16 -14
  118. package/dist/models/ai-sdk/index.js +1 -2442
  119. package/dist/models/opencode/index.d.ts +65 -0
  120. package/dist/models/opencode/index.js +285 -0
  121. package/dist/models/opencode/index.js.map +1 -0
  122. package/dist/models/pi-ai/index.d.ts +23 -21
  123. package/dist/models/pi-ai/index.js +7 -6
  124. package/dist/models/pi-ai/index.js.map +1 -1
  125. package/dist/options-pwTNq9z6.d.ts +134 -0
  126. package/dist/protocol-BEgrJYC5.d.ts +331 -0
  127. package/dist/protocol-CukuI73M.d.ts +386 -0
  128. package/dist/protocol-cOklVBBD.js +227 -0
  129. package/dist/protocol-cOklVBBD.js.map +1 -0
  130. package/dist/{protocol-kHsr-f0X.js → protocol-eXeJxhgu.js} +2 -67
  131. package/dist/protocol-eXeJxhgu.js.map +1 -0
  132. package/dist/protocol-y2sSY584.js +148 -0
  133. package/dist/protocol-y2sSY584.js.map +1 -0
  134. package/dist/queue/index.d.ts +1 -1
  135. package/dist/react.d.ts +2 -2
  136. package/dist/routing/index.d.ts +2 -2
  137. package/dist/{scheduler-RdACNXDP.d.ts → scheduler-CrFCnv_J.d.ts} +2 -2
  138. package/dist/schedules/index.d.ts +1 -1
  139. package/dist/serializable.d.ts +1 -1
  140. package/dist/sessions/index.d.ts +11 -434
  141. package/dist/sessions/index.js +1 -2271
  142. package/dist/sessions-B9pNuxdT.js +2272 -0
  143. package/dist/sessions-B9pNuxdT.js.map +1 -0
  144. package/dist/settings-C45hDliX.js +253 -0
  145. package/dist/settings-C45hDliX.js.map +1 -0
  146. package/dist/{transport-PfFnt-Ld.d.ts → settings-NgGwF7Qt.d.ts} +14 -208
  147. package/dist/{src-BZeu-SCD.js → src-DgCbZtIR.js} +4 -4
  148. package/dist/{src-BZeu-SCD.js.map → src-DgCbZtIR.js.map} +1 -1
  149. package/dist/stall-watchdog-BpRF2uwG.js +195 -0
  150. package/dist/stall-watchdog-BpRF2uwG.js.map +1 -0
  151. package/dist/state/index.d.ts +1 -1
  152. package/dist/store-DLeqKuj3.d.ts +310 -0
  153. package/dist/store-vgcPYo8K.js +432 -0
  154. package/dist/store-vgcPYo8K.js.map +1 -0
  155. package/dist/streams/index.d.ts +1 -1
  156. package/dist/streams/index.js +1 -1
  157. package/dist/{streams-DW-UCOUc.js → streams-CITClVer.js} +16 -3
  158. package/dist/streams-CITClVer.js.map +1 -0
  159. package/dist/{streams-Cmkj9QfW.d.ts → streams-fbG61qM8.d.ts} +2 -2
  160. package/dist/sub-routing.d.ts +1 -1
  161. package/dist/tasks/index.d.ts +1 -1
  162. package/dist/tasks/index.js +1 -1
  163. package/dist/{tasks-68DESxf0.js → tasks-CkTZNaV1.js} +2 -1
  164. package/dist/tasks-CkTZNaV1.js.map +1 -0
  165. package/dist/{tasks-9YxYtByh.d.ts → tasks-PtlB4Uyn.d.ts} +2 -2
  166. package/dist/tool-3PA8xjB_.js +421 -0
  167. package/dist/tool-3PA8xjB_.js.map +1 -0
  168. package/dist/tool-BPJEbwaX.d.ts +278 -0
  169. package/dist/transport-k2mFrtL8.d.ts +200 -0
  170. package/dist/turns-DCV3ycDl.js +317 -0
  171. package/dist/turns-DCV3ycDl.js.map +1 -0
  172. package/dist/voice/client.js +1 -1
  173. package/dist/voice/index.d.ts +2 -2
  174. package/dist/voice/index.js +1 -1
  175. package/dist/websearch/index.d.ts +58 -0
  176. package/dist/websearch/index.js +2 -0
  177. package/dist/websearch/tools/ai-sdk.d.ts +77 -0
  178. package/dist/websearch/tools/ai-sdk.js +46 -0
  179. package/dist/websearch/tools/ai-sdk.js.map +1 -0
  180. package/dist/websearch/tools/pi.d.ts +82 -0
  181. package/dist/websearch/tools/pi.js +89 -0
  182. package/dist/websearch/tools/pi.js.map +1 -0
  183. package/dist/websearch/tools/tanstack-ai.d.ts +71 -0
  184. package/dist/websearch/tools/tanstack-ai.js +46 -0
  185. package/dist/websearch/tools/tanstack-ai.js.map +1 -0
  186. package/dist/websockets/index.d.ts +12 -296
  187. package/dist/websockets/index.js +1 -1
  188. package/dist/{websockets-Ci-LZFHH.js → websockets-CmENGb-Z.js} +18 -4
  189. package/dist/websockets-CmENGb-Z.js.map +1 -0
  190. package/dist/{wire-types-CrjKvDyi.d.ts → wire-types-Cv0iwjk5.d.ts} +3 -51
  191. package/dist/workflow-types.d.ts +1 -1
  192. package/dist/workflows.d.ts +1 -1
  193. package/dist/workflows.js +1 -1
  194. package/docs/browse-the-web.md +3 -0
  195. package/docs/harnesses/pi.md +114 -32
  196. package/docs/harnesses/think.md +215 -0
  197. package/docs/index.md +4 -3
  198. package/docs/lifecycle.md +40 -0
  199. package/docs/models-pi-ai.md +5 -5
  200. package/docs/search-the-web.md +133 -0
  201. package/package.json +126 -47
  202. package/dist/browser-tool-CQ10e6Kj.js.map +0 -1
  203. package/dist/channel-Bnm4S7T2.d.ts +0 -491
  204. package/dist/channels/ai-sdk.d.ts +0 -46
  205. package/dist/channels/ai-sdk.js +0 -120
  206. package/dist/channels/ai-sdk.js.map +0 -1
  207. package/dist/channels/email.js.map +0 -1
  208. package/dist/channels/index.d.ts +0 -233
  209. package/dist/channels/index.js +0 -608
  210. package/dist/channels/index.js.map +0 -1
  211. package/dist/channels/slack.js +0 -614
  212. package/dist/channels/slack.js.map +0 -1
  213. package/dist/channels/tanstack-ai.d.ts +0 -39
  214. package/dist/channels/tanstack-ai.js +0 -17
  215. package/dist/channels/tanstack-ai.js.map +0 -1
  216. package/dist/channels/telegram.js +0 -427
  217. package/dist/channels/telegram.js.map +0 -1
  218. package/dist/channels/voice.d.ts +0 -45
  219. package/dist/channels/voice.js +0 -122
  220. package/dist/channels/voice.js.map +0 -1
  221. package/dist/harnesses/pi/index.js.map +0 -1
  222. package/dist/images-iiTDSyRu.js.map +0 -1
  223. package/dist/index-BB0kqhIz.d.ts +0 -101
  224. package/dist/ingress-BfetZbMO.js +0 -83
  225. package/dist/ingress-BfetZbMO.js.map +0 -1
  226. package/dist/internal-CYlgHl1l.js +0 -59
  227. package/dist/internal-CYlgHl1l.js.map +0 -1
  228. package/dist/models/ai-sdk/index.js.map +0 -1
  229. package/dist/protocol-kHsr-f0X.js.map +0 -1
  230. package/dist/sessions/index.js.map +0 -1
  231. package/dist/streams-DW-UCOUc.js.map +0 -1
  232. package/dist/surface-bZZJqBka.js +0 -17
  233. package/dist/surface-bZZJqBka.js.map +0 -1
  234. package/dist/tasks-68DESxf0.js.map +0 -1
  235. package/dist/tool-schema-CBjGPrsQ.js +0 -31
  236. package/dist/tool-schema-CBjGPrsQ.js.map +0 -1
  237. package/dist/websockets-Ci-LZFHH.js.map +0 -1
  238. package/docs/channels.md +0 -323
@@ -0,0 +1,460 @@
1
+ import {
2
+ a as RecentHistoryResult,
3
+ c as SessionChangeListener,
4
+ d as SessionRowStat,
5
+ f as SessionsOptions,
6
+ i as HistoryReadOptions,
7
+ l as SessionMessage,
8
+ m as WriteOptions,
9
+ n as AppendResult,
10
+ o as SearchResult,
11
+ p as StoredCompaction,
12
+ r as HistoryBatchReadOptions,
13
+ s as SessionChangeEvent,
14
+ t as AppendOptions
15
+ } from "./types-B7LojTe4.js";
16
+
17
+ //#region src/sessions/compaction-helpers.d.ts
18
+ /** Prefix for all compaction messages (overlays and summaries) */
19
+ declare const COMPACTION_PREFIX = "compaction_";
20
+ /** Check if a message is a compaction message */
21
+ declare function isCompactionMessage(msg: SessionMessage): boolean;
22
+ /**
23
+ * Result of a compaction function — describes the overlay to store.
24
+ */
25
+ interface CompactResult {
26
+ /** First message ID in the compacted range */
27
+ fromMessageId: string;
28
+ /** Last message ID in the compacted range */
29
+ toMessageId: string;
30
+ /** Summary text to store as the overlay */
31
+ summary: string;
32
+ }
33
+ interface CompactOptions {
34
+ /** Calls the model to summarize; receives a prompt, returns its text. */
35
+ summarize: (prompt: string) => Promise<string>;
36
+ /**
37
+ * Token budget for the recent tail kept verbatim. Older messages above the
38
+ * protected head are summarized into one overlay. Default 20,000.
39
+ */
40
+ keepRecentTokens?: number;
41
+ }
42
+ /**
43
+ * Reference compaction implementation.
44
+ *
45
+ * Implements the full hermes-style compaction algorithm:
46
+ * 1. Protect head messages (first N)
47
+ * 2. Protect tail by token budget (walk backward)
48
+ * 3. Align boundaries to tool call groups
49
+ * 4. Summarize middle section with LLM (structured format)
50
+ * 5. Iterative summary updates on subsequent compactions
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * import { createCompactFunction } from "agents/sessions";
55
+ *
56
+ * sessions
57
+ * .session()
58
+ * .onCompaction(
59
+ * createCompactFunction({
60
+ * summarize: (prompt) => generateText({ model, prompt }).then((r) => r.text)
61
+ * })
62
+ * )
63
+ * .compactAfter(100_000);
64
+ * ```
65
+ */
66
+ declare function createCompactFunction(
67
+ opts: CompactOptions
68
+ ): (messages: SessionMessage[]) => Promise<CompactResult | null>;
69
+ //#endregion
70
+ //#region src/sessions/io.d.ts
71
+ /** @internal SQLite and telemetry supplied by the Sessions capability. */
72
+ type SqlParam = ArrayBuffer | string | number | null;
73
+ interface SessionsIo {
74
+ /** Run a read and return every row. */
75
+ sql<T>(query: string, params: SqlParam[]): T[];
76
+ /** Run a write (or DDL) and return the rows it wrote. */
77
+ sqlWrite(query: string, params: SqlParam[]): number;
78
+ /** One synchronous SQLite transaction. */
79
+ transaction<T>(fn: () => T): T;
80
+ /** Capability telemetry event. */
81
+ emit(type: string, payload: Record<string, unknown>): void;
82
+ }
83
+ //#endregion
84
+ //#region src/sessions/core.d.ts
85
+ type UpdateOutcome = "missing" | "unchanged" | "updated";
86
+ declare class SessionsCore {
87
+ #private;
88
+ readonly io: SessionsIo;
89
+ constructor(options: SessionsOptions, io: SessionsIo);
90
+ ensureTables(): void;
91
+ /**
92
+ * Lift the legacy `assistant_*` message and compaction tables.
93
+ *
94
+ * The copy is pure SQL, so SQLite streams it rather than materializing rows
95
+ * in the isolate. Each source is then verified row by row against its
96
+ * destination and DROPPED: keeping tombstones would leave every upgraded
97
+ * object holding its history twice inside the same 10 GB. A table whose
98
+ * verification fails is left in place with a `session:migration:incomplete`
99
+ * event, and the method returns false so the caller leaves the schema
100
+ * version unstamped and retries on a later start. `assistant_config`
101
+ * belongs to Think, which lifts and drops it itself.
102
+ */
103
+ migrateLegacy(): boolean;
104
+ subscribe(listener: SessionChangeListener): () => void;
105
+ /**
106
+ * Dispatch after a durable write. A listener that throws must not turn a
107
+ * committed write into a rejected call, so failures are reported through
108
+ * telemetry and dispatch continues.
109
+ */
110
+ notify(event: SessionChangeEvent): Promise<void>;
111
+ exists(sessionId: string, id: string): boolean;
112
+ getMessage(sessionId: string, id: string): SessionMessage | null;
113
+ /**
114
+ * Drop the in-memory tail and token-total caches for a session. For a
115
+ * caller whose enclosing transaction rolled back after an append or update
116
+ * ran inside it: the rows are gone but the caches already moved. The next
117
+ * read re-derives both from storage.
118
+ */
119
+ forgetCaches(sessionId: string): void;
120
+ latestLeafId(sessionId: string): string | null;
121
+ getLatestLeaf(sessionId: string): SessionMessage | null;
122
+ getBranches(sessionId: string, messageId: string): SessionMessage[];
123
+ /**
124
+ * The active branch path as content-free rows, root → leaf. Recurses over
125
+ * (id, parent_id) only — carrying content through the recursive queue
126
+ * materializes the transcript several times inside SQLite (#1710).
127
+ * `bytes` counts the message row, its continuation rows, AND the payloads
128
+ * it points at, charged at the size they take once inlined, so a byte
129
+ * budget over these rows bounds real hydrated memory.
130
+ */
131
+ pathRowStats(sessionId: string, leafId?: string | null): SessionRowStat[];
132
+ /**
133
+ * Stream the path ending at `leafId` (default: active leaf), root → leaf
134
+ * (or leaf → root with `newestFirst`), compaction overlays collapsed. Peak
135
+ * memory is one bounded content window — never the whole transcript.
136
+ */
137
+ streamHistory(
138
+ sessionId: string,
139
+ options: HistoryReadOptions
140
+ ): AsyncGenerator<SessionMessage, void, undefined>;
141
+ getHistory(
142
+ sessionId: string,
143
+ options: HistoryReadOptions
144
+ ): Promise<SessionMessage[]>;
145
+ /**
146
+ * Byte-budgeted read of the most recent messages on the active branch
147
+ * path — the longest suffix whose stored size fits `maxContentBytes`.
148
+ *
149
+ * There is no message-count floor: one used to exist, and it admitted
150
+ * rows regardless of size, so a window of media-heavy messages could
151
+ * hydrate far past the limit meant to bound it. The newest message is
152
+ * always returned even if it alone exceeds the budget, since returning
153
+ * nothing is worse. Overlays whose anchors fall outside the window are
154
+ * skipped, showing the raw recent messages.
155
+ */
156
+ getRecentHistory(
157
+ sessionId: string,
158
+ maxContentBytes: number,
159
+ leafId?: string | null
160
+ ): Promise<RecentHistoryResult>;
161
+ /**
162
+ * Heuristic token estimate for the active path with compaction overlays
163
+ * applied: stamped per-row estimates, minus compacted spans, plus their
164
+ * summaries. Derived from content-free rows on each call; it gates cheap
165
+ * triggers only, and model-reported usage stays authoritative.
166
+ */
167
+ tokenEstimate(sessionId: string): number;
168
+ stripReservedMetadata(message: SessionMessage): SessionMessage;
169
+ /**
170
+ * Stamped row estimate: the part heuristic over the message as written,
171
+ * plus a weight per inline file payload so media never counts as zero.
172
+ */
173
+ estimateRowTokens(message: SessionMessage): number;
174
+ /**
175
+ * Durable append. The caller has already sanitized the message. Message,
176
+ * continuation, attachment, and FTS rows commit in one synchronous SQLite
177
+ * transaction. Returns the stored message: the input itself when it was
178
+ * inserted (extraction is lossless, so the two are identical), or the row
179
+ * already holding the id when it was not.
180
+ */
181
+ append(
182
+ sessionId: string,
183
+ message: SessionMessage,
184
+ parentId: string | null | undefined,
185
+ tokenEstimate: number
186
+ ): {
187
+ inserted: boolean;
188
+ message: SessionMessage;
189
+ };
190
+ /**
191
+ * Durable update of an existing row. An identical row writes nothing: no
192
+ * row, no continuation, no FTS, no event. The no-op guard compares the
193
+ * FULL content, through the digest the last write stamped, so neither the
194
+ * payload nor a continuation row is read. A row without a digest compares
195
+ * the reassembled content once and is stamped.
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/mirror.d.ts
234
+ /**
235
+ * How a host keeps an in-memory transcript in step with one session's change
236
+ * feed. The mirror applies the reduction every such cache needs; the hooks
237
+ * carry the decisions only the host can make.
238
+ */
239
+ interface SessionMirrorOptions<
240
+ M extends {
241
+ id: string;
242
+ }
243
+ > {
244
+ /**
245
+ * The cached transcript. Read on every event, so a host that reassigns its
246
+ * array (a public `messages` field, say) is followed rather than
247
+ * shadowed.
248
+ */
249
+ get(): M[];
250
+ /** Install a new array: after a delete, or emptied by a clear. */
251
+ set(messages: M[]): void;
252
+ /** The cached form of a stored message. Defaults to the stored message. */
253
+ transform?(message: SessionMessage): M;
254
+ /**
255
+ * Handle an event instead of the default reduction, returning `true` when
256
+ * it did. A host whose cache cannot express a change in place — a branch
257
+ * append, a compaction — re-reads storage here.
258
+ */
259
+ intercept?(event: SessionChangeEvent): boolean | Promise<boolean>;
260
+ /**
261
+ * After the default reduction wrote `message` for an append or update.
262
+ * `previous` is the cached entry it replaced, if there was one.
263
+ */
264
+ onApplied?(
265
+ event: Extract<
266
+ SessionChangeEvent,
267
+ {
268
+ type: "append" | "update";
269
+ }
270
+ >,
271
+ message: M,
272
+ previous: M | undefined
273
+ ): void;
274
+ }
275
+ //#endregion
276
+ //#region src/sessions/handle.d.ts
277
+ /** Summarizes a branch into an overlay. */
278
+ type CompactionFunction = (
279
+ messages: SessionMessage[]
280
+ ) => Promise<CompactResult | null>;
281
+ declare class Session {
282
+ #private;
283
+ readonly sessionId: string;
284
+ /** @internal Constructed by the Sessions capability only. */
285
+ constructor(
286
+ sessionId: string,
287
+ core: SessionsCore,
288
+ ready: () => Promise<void>
289
+ );
290
+ /** Register the function `compact()` calls to summarize a branch. */
291
+ onCompaction(fn: CompactionFunction): this;
292
+ /**
293
+ * Auto-compact after an append once the estimated token count crosses the
294
+ * threshold. Requires `onCompaction()`. The estimate is derived from the
295
+ * stamped per-row estimates, never from the transcript.
296
+ */
297
+ compactAfter(tokenThreshold: number): this;
298
+ /**
299
+ * Keep an in-memory transcript in step with this session's change feed,
300
+ * so write sites never hand-patch it. Returns the unsubscribe function.
301
+ */
302
+ mirror<
303
+ M extends {
304
+ id: string;
305
+ }
306
+ >(options: SessionMirrorOptions<M>): () => void;
307
+ /**
308
+ * Stream the active branch path root → leaf (leaf → root with
309
+ * `newestFirst`) with compaction overlays applied. Peak memory is one
310
+ * bounded content window, never the whole transcript, and a consumer that
311
+ * breaks out early leaves the rows it never reached unread.
312
+ */
313
+ history(
314
+ options?: HistoryReadOptions
315
+ ): AsyncGenerator<SessionMessage, void, undefined>;
316
+ /**
317
+ * Stream history in bounded non-empty batches. Both message count and
318
+ * serialized bytes bound each batch; a single large message is yielded by
319
+ * itself.
320
+ */
321
+ historyBatches(
322
+ options?: HistoryBatchReadOptions
323
+ ): AsyncGenerator<SessionMessage[], void, undefined>;
324
+ /**
325
+ * Materialize the whole selected path. Prefer `history()` or
326
+ * `getRecentHistory()` inside a Durable Object: this holds every message
327
+ * of the branch in memory at once.
328
+ */
329
+ getHistory(options?: HistoryReadOptions): Promise<SessionMessage[]>;
330
+ /**
331
+ * Byte-budgeted read of the most recent messages on the active branch path
332
+ * (always at least the leaf). The budget counts each row, its continuation
333
+ * rows, and the payloads it points at, so it bounds hydrated memory (#1710).
334
+ */
335
+ getRecentHistory(
336
+ maxContentBytes: number,
337
+ options?: Pick<HistoryReadOptions, "leafId">
338
+ ): Promise<RecentHistoryResult>;
339
+ /**
340
+ * Per-row stored sizes (row plus continuation rows and attachments) and
341
+ * stamped token estimates for the active branch path (root → leaf)
342
+ * WITHOUT loading message content.
343
+ */
344
+ getHistoryRowStats(leafId?: string | null): Promise<SessionRowStat[]>;
345
+ getMessage(id: string): Promise<SessionMessage | null>;
346
+ getLatestLeaf(): Promise<SessionMessage | null>;
347
+ getBranches(messageId: string): Promise<SessionMessage[]>;
348
+ /**
349
+ * Full-text search over this session's text parts. The index is built on
350
+ * the first call and maintained from then on.
351
+ */
352
+ search(
353
+ query: string,
354
+ options?: {
355
+ limit?: number;
356
+ }
357
+ ): Promise<SearchResult[]>;
358
+ /**
359
+ * Append one message. Idempotent on id: a repeated append returns the row
360
+ * already stored and dispatches an `append` event with `inserted: false`.
361
+ *
362
+ * A compaction overlay (a `compaction_` id) is derived on read and is never
363
+ * stored. Clients post their transcript back after every compaction, so
364
+ * this and every other write drops one silently: nothing is written and no
365
+ * event is dispatched.
366
+ */
367
+ appendMessage(
368
+ message: SessionMessage,
369
+ options?: AppendOptions
370
+ ): Promise<AppendResult>;
371
+ /**
372
+ * Update one stored row. Returns the stored form, or `null` when the id is
373
+ * not in this session. An unchanged message writes nothing and dispatches
374
+ * no event. A compaction overlay is never a stored row, so it reports
375
+ * `null`.
376
+ */
377
+ updateMessage(
378
+ message: SessionMessage,
379
+ options?: WriteOptions
380
+ ): Promise<SessionMessage | null>;
381
+ /**
382
+ * @internal Synchronous write aperture for same-isolate first-party
383
+ * machinery that must commit a message inside a caller-owned SQLite
384
+ * transaction — the stream cutover, where the finished message and the
385
+ * discard of its stream rows land together. Bypasses readiness (the
386
+ * caller owns startup ordering) and defers everything that follows a
387
+ * write — the change-feed dispatch and auto-compaction: call the returned
388
+ * `after()` once the transaction commits, or subscribers (the host's
389
+ * message mirror) never hear about the write. If the transaction rolls
390
+ * back after an `upsert` ran inside it, call `abandon()`: the write is
391
+ * gone but the in-memory tail and token-total caches already moved.
392
+ * Will break without notice; never use from application code.
393
+ */
394
+ __DO_NOT_USE_WILL_BREAK__sync(): {
395
+ upsert(
396
+ message: SessionMessage,
397
+ options?: AppendOptions
398
+ ): {
399
+ result: AppendResult;
400
+ after: () => Promise<void>;
401
+ };
402
+ abandon(): void;
403
+ };
404
+ upsertMessage(
405
+ message: SessionMessage,
406
+ options?: AppendOptions
407
+ ): Promise<AppendResult>;
408
+ /**
409
+ * Import one historical message verbatim (migrations, cross-object moves):
410
+ * explicit parent and timestamp. A row actually written dispatches an
411
+ * `import` change event so a host cache can mark itself stale; it is not
412
+ * an `append`, so a cache does not patch itself per imported row, and an
413
+ * id that already exists writes nothing and dispatches nothing.
414
+ *
415
+ * Unlike the other writes, a `compaction_` id is imported as given: a
416
+ * summary copied from another session's `history()` is the only record of
417
+ * the context it replaced, and later rows may be parented to it. History
418
+ * reads hide such a row only when it duplicates one of this session's own
419
+ * compaction overlays.
420
+ */
421
+ importMessage(
422
+ message: SessionMessage,
423
+ options: {
424
+ parentId: string | null;
425
+ createdAt: number;
426
+ }
427
+ ): Promise<void>;
428
+ deleteMessages(messageIds: string[]): Promise<void>;
429
+ clearMessages(): Promise<void>;
430
+ /**
431
+ * Store an overlay directly. Dispatches a `compaction` change event: the
432
+ * rows are untouched, but what a path read returns has changed.
433
+ */
434
+ addCompaction(
435
+ summary: string,
436
+ fromMessageId: string,
437
+ toMessageId: string
438
+ ): Promise<StoredCompaction>;
439
+ getCompactions(): Promise<StoredCompaction[]>;
440
+ /**
441
+ * Run the registered compaction function and store the result as an
442
+ * overlay. When `leafId` is given, compact that root-to-leaf branch instead
443
+ * of the active branch. Requires `onCompaction()`. A compaction function
444
+ * that throws is reported through the `session:error` capability event and
445
+ * the call returns `null`.
446
+ */
447
+ compact(leafId?: string | null): Promise<CompactResult | null>;
448
+ }
449
+ //#endregion
450
+ export {
451
+ CompactOptions as a,
452
+ isCompactionMessage as c,
453
+ COMPACTION_PREFIX as i,
454
+ Session as n,
455
+ CompactResult as o,
456
+ SessionMirrorOptions as r,
457
+ createCompactFunction as s,
458
+ CompactionFunction as t
459
+ };
460
+ //# sourceMappingURL=handle-zAzh0UW2.d.ts.map
@@ -0,0 +1,175 @@
1
+ import {
2
+ _ as LifecycleJobContext,
3
+ s as LifecycleCapability,
4
+ v as LifecycleJobOutcome
5
+ } from "../../capability-runner-O5VbQzqg.js";
6
+ import {
7
+ o as ChannelMessage,
8
+ p as DeliveryResult
9
+ } from "../../channel-Bak_6zDP.js";
10
+ import {
11
+ _ as TranscriptMessage,
12
+ b as ChannelMessageSurface,
13
+ c as InboundEvent,
14
+ m as ResponseChunk
15
+ } from "../../protocol-CukuI73M.js";
16
+ import {
17
+ a as HarnessSessions,
18
+ d as SessionId,
19
+ i as HarnessSession,
20
+ t as AgentHarness
21
+ } from "../../harness-B6B9S3rb.js";
22
+ import { t as ChannelGateway } from "../../gateway-BDC07gYO.js";
23
+ import {
24
+ LanguageModel,
25
+ StopCondition,
26
+ Tool,
27
+ ToolSet,
28
+ UIMessage,
29
+ UIMessageChunk
30
+ } from "ai";
31
+
32
+ //#region src/harness/ai-sdk/harness.d.ts
33
+ type AiSdkHarnessOptions<TOOLS extends ToolSet> = {
34
+ model: LanguageModel;
35
+ /**
36
+ * Tools without `execute` run on the client of the participant whose
37
+ * message started the turn; tools with `needsApproval` wait for an
38
+ * approval from anyone.
39
+ */
40
+ tools?: TOOLS;
41
+ system?: string /** Default: `stepCountIs(5)`. */;
42
+ stopWhen?: StopCondition<
43
+ NoInfer<TOOLS>
44
+ > /** How often a running session's wake job checks in. Default: 30 s. */;
45
+ heartbeatMs?: number;
46
+ };
47
+ /**
48
+ * An agent harness around the AI SDK's `streamText`, hosted in a Durable
49
+ * Object: sessions, their transcripts, and a queue of operations, all in the
50
+ * object's storage. One operation runs at a time per session; a run is one
51
+ * `streamText` call over the session's transcript.
52
+ *
53
+ * The AI SDK keeps no state of its own, so a run that an eviction cuts short
54
+ * starts again from the saved transcript, and its unsaved output is lost.
55
+ * Steering is not supported: `whenBusy: "steer"` queues like a follow-up.
56
+ *
57
+ * @experimental The API may change between releases.
58
+ */
59
+ declare class AiSdkHarness<TOOLS extends ToolSet = ToolSet>
60
+ extends LifecycleCapability
61
+ implements AgentHarness
62
+ {
63
+ #private;
64
+ readonly sessions: HarnessSessions;
65
+ constructor(options: AiSdkHarnessOptions<TOOLS>);
66
+ onStart(): Promise<void>;
67
+ onJob(context: LifecycleJobContext): Promise<LifecycleJobOutcome | void>;
68
+ session(id?: SessionId): HarnessSession;
69
+ }
70
+ //#endregion
71
+ //#region src/harness/ai-sdk/send-message-tool.d.ts
72
+ type SendMessageTool = Tool<ChannelMessage, DeliveryResult>;
73
+ /** Model-facing options controlled by the caller creating the tool. */
74
+ type CreateSendMessageToolOptions = Pick<
75
+ SendMessageTool,
76
+ | "description"
77
+ | "inputExamples"
78
+ | "metadata"
79
+ | "needsApproval"
80
+ | "providerOptions"
81
+ | "strict"
82
+ >;
83
+ /**
84
+ * Adapt one Host-resolved surface to an AI SDK tool.
85
+ *
86
+ * The caller chooses the key used in its ToolSet and owns model-facing policy
87
+ * such as the description, examples, metadata, and approval requirement.
88
+ */
89
+ declare function createSendMessageTool(
90
+ gateway: ChannelGateway,
91
+ surface: ChannelMessageSurface,
92
+ options?: CreateSendMessageToolOptions
93
+ ): Tool<ChannelMessage, DeliveryResult>;
94
+ //#endregion
95
+ //#region src/harness/ai-sdk/turns.d.ts
96
+ type AiSdkConversionOptions = {
97
+ /** The agent's tools. Those without `execute` run on a client. */ tools?: ToolSet /** Id of the participant whose client runs this message's client tools. */;
98
+ owner?: string;
99
+ };
100
+ /**
101
+ * Convert an AI SDK UI message stream into response chunks.
102
+ *
103
+ * An `error` or `abort` chunk makes the iteration throw once the stream
104
+ * ends, so a failed or aborted generation never reads as a finished one, while the stream still
105
+ * runs to its end and its `onEnd` sees the partial message.
106
+ */
107
+ declare function toResponseChunks(
108
+ stream: AsyncIterable<UIMessageChunk>,
109
+ options?: AiSdkConversionOptions
110
+ ): AsyncGenerator<ResponseChunk>;
111
+ /** Convert one AI SDK UI message chunk into a response chunk, if it has one. */
112
+ declare function toResponseChunk(
113
+ chunk: UIMessageChunk,
114
+ options: AiSdkConversionOptions
115
+ ): ResponseChunk | undefined;
116
+ /**
117
+ * Convert a response chunk into an AI SDK UI message chunk. Fields that only
118
+ * Channels has, such as a tool call's `owner`, are dropped.
119
+ */
120
+ declare function toUIMessageChunk(chunk: ResponseChunk): UIMessageChunk;
121
+ /** Convert a saved AI SDK UI message into a transcript message. */
122
+ declare function toTranscriptMessage(
123
+ message: UIMessage,
124
+ options?: AiSdkConversionOptions
125
+ ): TranscriptMessage;
126
+ /** Convert a transcript message into an AI SDK UI message. */
127
+ declare function toUIMessage(message: TranscriptMessage): UIMessage;
128
+ /** Whether the message has a tool call waiting for a result or an approval. */
129
+ declare function awaitsInput(message: UIMessage): boolean;
130
+ /** A tool result or approval response, as an inbound event carries it. */
131
+ type ToolCallAnswer =
132
+ | Pick<
133
+ Extract<
134
+ InboundEvent,
135
+ {
136
+ type: "tool-result";
137
+ }
138
+ >,
139
+ "type" | "toolCallId" | "result"
140
+ >
141
+ | Pick<
142
+ Extract<
143
+ InboundEvent,
144
+ {
145
+ type: "approval-response";
146
+ }
147
+ >,
148
+ "type" | "approvalId" | "approved" | "reason"
149
+ >;
150
+ /**
151
+ * Record a tool result or approval response on the tool call it answers.
152
+ * Returns the updated message, or undefined when no call is waiting for it,
153
+ * so the first answer wins.
154
+ */
155
+ declare function answerToolCall(
156
+ messages: readonly UIMessage[],
157
+ event: ToolCallAnswer
158
+ ): UIMessage | undefined;
159
+ //#endregion
160
+ export {
161
+ AiSdkConversionOptions,
162
+ AiSdkHarness,
163
+ type AiSdkHarnessOptions,
164
+ type CreateSendMessageToolOptions,
165
+ ToolCallAnswer,
166
+ answerToolCall,
167
+ awaitsInput,
168
+ createSendMessageTool,
169
+ toResponseChunk,
170
+ toResponseChunks,
171
+ toTranscriptMessage,
172
+ toUIMessage,
173
+ toUIMessageChunk
174
+ };
175
+ //# sourceMappingURL=index.d.ts.map