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
@@ -1,4 +1,4 @@
1
- import { s as LifecycleCapability } from "../capability-runner-DBAnGr6L.js";
1
+ import { s as LifecycleCapability } from "../capability-runner-O5VbQzqg.js";
2
2
  import {
3
3
  a as RecentHistoryResult,
4
4
  c as SessionChangeListener,
@@ -15,440 +15,17 @@ import {
15
15
  t as AppendOptions,
16
16
  u as SessionMessagePart
17
17
  } from "../types-B7LojTe4.js";
18
+ import {
19
+ a as CompactOptions,
20
+ c as isCompactionMessage,
21
+ i as COMPACTION_PREFIX,
22
+ n as Session,
23
+ o as CompactResult,
24
+ r as SessionMirrorOptions,
25
+ s as createCompactFunction,
26
+ t as CompactionFunction
27
+ } from "../handle-zAzh0UW2.js";
18
28
 
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 content, through the digest the last write stamped, so neither the
196
- * payload nor a continuation row is read. A row without a digest compares
197
- * the reassembled content once and is stamped.
198
- */
199
- update(
200
- sessionId: string,
201
- message: SessionMessage,
202
- tokenEstimate: number
203
- ): UpdateOutcome;
204
- /**
205
- * Delete rows, SPLICING children to their grandparent so a mid-chain
206
- * delete never decapitates older history. Only surviving boundary children
207
- * are rewired: a prefix delete writes one boundary child, not one child
208
- * per deleted message.
209
- */
210
- deleteMessages(sessionId: string, messageIds: string[]): void;
211
- clearMessages(sessionId: string): void;
212
- addCompaction(
213
- sessionId: string,
214
- summary: string,
215
- fromMessageId: string,
216
- toMessageId: string
217
- ): StoredCompaction;
218
- getCompactions(sessionId: string): StoredCompaction[];
219
- search(sessionId: string, query: string, limit: number): SearchResult[];
220
- /**
221
- * Import one historical message verbatim (migrations, cross-DO moves):
222
- * explicit parent and timestamp, stamped estimate, no change-feed events.
223
- */
224
- /** Returns `false` when the id already exists and nothing was written. */
225
- importMessage(
226
- sessionId: string,
227
- message: SessionMessage,
228
- options: {
229
- parentId: string | null;
230
- createdAt: number;
231
- }
232
- ): boolean;
233
- }
234
- //#endregion
235
- //#region src/sessions/mirror.d.ts
236
- /**
237
- * How a host keeps an in-memory transcript in step with one session's change
238
- * feed. The mirror applies the reduction every such cache needs; the hooks
239
- * carry the decisions only the host can make.
240
- */
241
- interface SessionMirrorOptions<
242
- M extends {
243
- id: string;
244
- }
245
- > {
246
- /**
247
- * The cached transcript. Read on every event, so a host that reassigns its
248
- * array (a public `messages` field, say) is followed rather than
249
- * shadowed.
250
- */
251
- get(): M[];
252
- /** Install a new array: after a delete, or emptied by a clear. */
253
- set(messages: M[]): void;
254
- /** The cached form of a stored message. Defaults to the stored message. */
255
- transform?(message: SessionMessage): M;
256
- /**
257
- * Handle an event instead of the default reduction, returning `true` when
258
- * it did. A host whose cache cannot express a change in place — a branch
259
- * append, a compaction — re-reads storage here.
260
- */
261
- intercept?(event: SessionChangeEvent): boolean | Promise<boolean>;
262
- /**
263
- * After the default reduction wrote `message` for an append or update.
264
- * `previous` is the cached entry it replaced, if there was one.
265
- */
266
- onApplied?(
267
- event: Extract<
268
- SessionChangeEvent,
269
- {
270
- type: "append" | "update";
271
- }
272
- >,
273
- message: M,
274
- previous: M | undefined
275
- ): void;
276
- }
277
- //#endregion
278
- //#region src/sessions/handle.d.ts
279
- /** Summarizes a branch into an overlay. */
280
- type CompactionFunction = (
281
- messages: SessionMessage[]
282
- ) => Promise<CompactResult | null>;
283
- declare class Session {
284
- #private;
285
- readonly sessionId: string;
286
- /** @internal Constructed by the Sessions capability only. */
287
- constructor(
288
- sessionId: string,
289
- core: SessionsCore,
290
- ready: () => Promise<void>
291
- );
292
- /** Register the function `compact()` calls to summarize a branch. */
293
- onCompaction(fn: CompactionFunction): this;
294
- /**
295
- * Auto-compact after an append once the estimated token count crosses the
296
- * threshold. Requires `onCompaction()`. The estimate is derived from the
297
- * stamped per-row estimates, never from the transcript.
298
- */
299
- compactAfter(tokenThreshold: number): this;
300
- /**
301
- * Keep an in-memory transcript in step with this session's change feed,
302
- * so write sites never hand-patch it. Returns the unsubscribe function.
303
- */
304
- mirror<
305
- M extends {
306
- id: string;
307
- }
308
- >(options: SessionMirrorOptions<M>): () => void;
309
- /**
310
- * Stream the active branch path root → leaf (leaf → root with
311
- * `newestFirst`) with compaction overlays applied. Peak memory is one
312
- * bounded content window, never the whole transcript, and a consumer that
313
- * breaks out early leaves the rows it never reached unread.
314
- */
315
- history(
316
- options?: HistoryReadOptions
317
- ): AsyncGenerator<SessionMessage, void, undefined>;
318
- /**
319
- * Stream history in bounded non-empty batches. Both message count and
320
- * serialized bytes bound each batch; a single large message is yielded by
321
- * itself.
322
- */
323
- historyBatches(
324
- options?: HistoryBatchReadOptions
325
- ): AsyncGenerator<SessionMessage[], void, undefined>;
326
- /**
327
- * Materialize the whole selected path. Prefer `history()` or
328
- * `getRecentHistory()` inside a Durable Object: this holds every message
329
- * of the branch in memory at once.
330
- */
331
- getHistory(options?: HistoryReadOptions): Promise<SessionMessage[]>;
332
- /**
333
- * Byte-budgeted read of the most recent messages on the active branch path
334
- * (always at least the leaf). The budget counts each row, its continuation
335
- * rows, and the payloads it points at, so it bounds hydrated memory (#1710).
336
- */
337
- getRecentHistory(
338
- maxContentBytes: number,
339
- options?: Pick<HistoryReadOptions, "leafId">
340
- ): Promise<RecentHistoryResult>;
341
- /**
342
- * Per-row stored sizes (row plus continuation rows and attachments) and
343
- * stamped token estimates for the active branch path (root → leaf)
344
- * WITHOUT loading message content.
345
- */
346
- getHistoryRowStats(leafId?: string | null): Promise<SessionRowStat[]>;
347
- getMessage(id: string): Promise<SessionMessage | null>;
348
- getLatestLeaf(): Promise<SessionMessage | null>;
349
- getBranches(messageId: string): Promise<SessionMessage[]>;
350
- /**
351
- * Full-text search over this session's text parts. The index is built on
352
- * the first call and maintained from then on.
353
- */
354
- search(
355
- query: string,
356
- options?: {
357
- limit?: number;
358
- }
359
- ): Promise<SearchResult[]>;
360
- /**
361
- * Append one message. Idempotent on id: a repeated append returns the row
362
- * already stored and dispatches an `append` event with `inserted: false`.
363
- *
364
- * A compaction overlay (a `compaction_` id) is derived on read and is never
365
- * stored. Clients post their transcript back after every compaction, so
366
- * this and every other write drops one silently: nothing is written and no
367
- * event is dispatched.
368
- */
369
- appendMessage(
370
- message: SessionMessage,
371
- options?: AppendOptions
372
- ): Promise<AppendResult>;
373
- /**
374
- * Update one stored row. Returns the stored form, or `null` when the id is
375
- * not in this session. An unchanged message writes nothing and dispatches
376
- * no event. A compaction overlay is never a stored row, so it reports
377
- * `null`.
378
- */
379
- updateMessage(
380
- message: SessionMessage,
381
- options?: WriteOptions
382
- ): Promise<SessionMessage | null>;
383
- /**
384
- * @internal Synchronous write aperture for same-isolate first-party
385
- * machinery that must commit a message inside a caller-owned SQLite
386
- * transaction — the stream cutover, where the finished message and the
387
- * discard of its stream rows land together. Bypasses readiness (the
388
- * caller owns startup ordering) and defers everything that follows a
389
- * write — the change-feed dispatch and auto-compaction: call the returned
390
- * `after()` once the transaction commits, or subscribers (the host's
391
- * message mirror) never hear about the write. If the transaction rolls
392
- * back after an `upsert` ran inside it, call `abandon()`: the write is
393
- * gone but the in-memory tail and token-total caches already moved.
394
- * Will break without notice; never use from application code.
395
- */
396
- __DO_NOT_USE_WILL_BREAK__sync(): {
397
- upsert(
398
- message: SessionMessage,
399
- options?: AppendOptions
400
- ): {
401
- result: AppendResult;
402
- after: () => Promise<void>;
403
- };
404
- abandon(): void;
405
- };
406
- upsertMessage(
407
- message: SessionMessage,
408
- options?: AppendOptions
409
- ): Promise<AppendResult>;
410
- /**
411
- * Import one historical message verbatim (migrations, cross-object moves):
412
- * explicit parent and timestamp. A row actually written dispatches an
413
- * `import` change event so a host cache can mark itself stale; it is not
414
- * an `append`, so a cache does not patch itself per imported row, and an
415
- * id that already exists writes nothing and dispatches nothing.
416
- *
417
- * Unlike the other writes, a `compaction_` id is imported as given: a
418
- * summary copied from another session's `history()` is the only record of
419
- * the context it replaced, and later rows may be parented to it. History
420
- * reads hide such a row only when it duplicates one of this session's own
421
- * compaction overlays.
422
- */
423
- importMessage(
424
- message: SessionMessage,
425
- options: {
426
- parentId: string | null;
427
- createdAt: number;
428
- }
429
- ): Promise<void>;
430
- deleteMessages(messageIds: string[]): Promise<void>;
431
- clearMessages(): Promise<void>;
432
- /**
433
- * Store an overlay directly. Dispatches a `compaction` change event: the
434
- * rows are untouched, but what a path read returns has changed.
435
- */
436
- addCompaction(
437
- summary: string,
438
- fromMessageId: string,
439
- toMessageId: string
440
- ): Promise<StoredCompaction>;
441
- getCompactions(): Promise<StoredCompaction[]>;
442
- /**
443
- * Run the registered compaction function and store the result as an
444
- * overlay. When `leafId` is given, compact that root-to-leaf branch instead
445
- * of the active branch. Requires `onCompaction()`. A compaction function
446
- * that throws is reported through the `session:error` capability event and
447
- * the call returns `null`.
448
- */
449
- compact(leafId?: string | null): Promise<CompactResult | null>;
450
- }
451
- //#endregion
452
29
  //#region src/sessions/sessions.d.ts
453
30
  /**
454
31
  * Durable conversation history for a Lifecycle Object.