@animalabs/agent-framework 0.26.1 → 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 (276) hide show
  1. package/README.md +57 -7
  2. package/dist/src/agent.d.ts +263 -22
  3. package/dist/src/agent.d.ts.map +1 -1
  4. package/dist/src/agent.js +531 -54
  5. package/dist/src/agent.js.map +1 -1
  6. package/dist/src/api/server.d.ts.map +1 -1
  7. package/dist/src/api/server.js +1 -2
  8. package/dist/src/api/server.js.map +1 -1
  9. package/dist/src/auto-continue.d.ts +33 -0
  10. package/dist/src/auto-continue.d.ts.map +1 -0
  11. package/dist/src/auto-continue.js +35 -0
  12. package/dist/src/auto-continue.js.map +1 -0
  13. package/dist/src/code-execution/isolate/scripts.d.ts +11 -0
  14. package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -1
  15. package/dist/src/code-execution/isolate/scripts.js +5 -1
  16. package/dist/src/code-execution/isolate/scripts.js.map +1 -1
  17. package/dist/src/framework.d.ts +829 -156
  18. package/dist/src/framework.d.ts.map +1 -1
  19. package/dist/src/framework.js +3906 -1008
  20. package/dist/src/framework.js.map +1 -1
  21. package/dist/src/gate/event-gate.d.ts +309 -46
  22. package/dist/src/gate/event-gate.d.ts.map +1 -1
  23. package/dist/src/gate/event-gate.js +2117 -395
  24. package/dist/src/gate/event-gate.js.map +1 -1
  25. package/dist/src/gate/index.d.ts +2 -2
  26. package/dist/src/gate/index.d.ts.map +1 -1
  27. package/dist/src/gate/index.js +1 -1
  28. package/dist/src/gate/index.js.map +1 -1
  29. package/dist/src/gate/recipe-reconcile.d.ts +103 -0
  30. package/dist/src/gate/recipe-reconcile.d.ts.map +1 -0
  31. package/dist/src/gate/recipe-reconcile.js +325 -0
  32. package/dist/src/gate/recipe-reconcile.js.map +1 -0
  33. package/dist/src/gate/types.d.ts +68 -8
  34. package/dist/src/gate/types.d.ts.map +1 -1
  35. package/dist/src/index.d.ts +6 -4
  36. package/dist/src/index.d.ts.map +1 -1
  37. package/dist/src/index.js +5 -2
  38. package/dist/src/index.js.map +1 -1
  39. package/dist/src/mcpl/channel-registry.d.ts +433 -113
  40. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  41. package/dist/src/mcpl/channel-registry.js +1152 -434
  42. package/dist/src/mcpl/channel-registry.js.map +1 -1
  43. package/dist/src/mcpl/conversation-router.d.ts +16 -8
  44. package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
  45. package/dist/src/mcpl/conversation-router.js +29 -15
  46. package/dist/src/mcpl/conversation-router.js.map +1 -1
  47. package/dist/src/mcpl/convert-block.d.ts.map +1 -1
  48. package/dist/src/mcpl/convert-block.js +14 -2
  49. package/dist/src/mcpl/convert-block.js.map +1 -1
  50. package/dist/src/mcpl/hook-orchestrator.d.ts +7 -1
  51. package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
  52. package/dist/src/mcpl/hook-orchestrator.js +32 -7
  53. package/dist/src/mcpl/hook-orchestrator.js.map +1 -1
  54. package/dist/src/mcpl/index.d.ts +5 -1
  55. package/dist/src/mcpl/index.d.ts.map +1 -1
  56. package/dist/src/mcpl/index.js +4 -0
  57. package/dist/src/mcpl/index.js.map +1 -1
  58. package/dist/src/mcpl/inference-router.d.ts +14 -2
  59. package/dist/src/mcpl/inference-router.d.ts.map +1 -1
  60. package/dist/src/mcpl/inference-router.js +73 -28
  61. package/dist/src/mcpl/inference-router.js.map +1 -1
  62. package/dist/src/mcpl/prose-grammar.d.ts +4 -0
  63. package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
  64. package/dist/src/mcpl/prose-grammar.js +6 -0
  65. package/dist/src/mcpl/prose-grammar.js.map +1 -1
  66. package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
  67. package/dist/src/mcpl/protocol-family.js +3 -0
  68. package/dist/src/mcpl/protocol-family.js.map +1 -1
  69. package/dist/src/mcpl/push-coalescer.d.ts +20 -2
  70. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  71. package/dist/src/mcpl/push-coalescer.js +33 -11
  72. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  73. package/dist/src/mcpl/reference-fetcher.d.ts +63 -42
  74. package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
  75. package/dist/src/mcpl/reference-fetcher.js +177 -145
  76. package/dist/src/mcpl/reference-fetcher.js.map +1 -1
  77. package/dist/src/mcpl/references.d.ts +380 -46
  78. package/dist/src/mcpl/references.d.ts.map +1 -1
  79. package/dist/src/mcpl/references.js +737 -78
  80. package/dist/src/mcpl/references.js.map +1 -1
  81. package/dist/src/mcpl/server-connection.d.ts +82 -3
  82. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  83. package/dist/src/mcpl/server-connection.js +132 -7
  84. package/dist/src/mcpl/server-connection.js.map +1 -1
  85. package/dist/src/mcpl/tool-lifecycle.d.ts +11 -0
  86. package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -1
  87. package/dist/src/mcpl/tool-lifecycle.js +21 -0
  88. package/dist/src/mcpl/tool-lifecycle.js.map +1 -1
  89. package/dist/src/mcpl/tool-presence.d.ts +259 -0
  90. package/dist/src/mcpl/tool-presence.d.ts.map +1 -0
  91. package/dist/src/mcpl/tool-presence.js +628 -0
  92. package/dist/src/mcpl/tool-presence.js.map +1 -0
  93. package/dist/src/mcpl/tool-result-normalize.d.ts +9 -3
  94. package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -1
  95. package/dist/src/mcpl/tool-result-normalize.js +14 -6
  96. package/dist/src/mcpl/tool-result-normalize.js.map +1 -1
  97. package/dist/src/mcpl/tool-signature.d.ts +39 -0
  98. package/dist/src/mcpl/tool-signature.d.ts.map +1 -0
  99. package/dist/src/mcpl/tool-signature.js +292 -0
  100. package/dist/src/mcpl/tool-signature.js.map +1 -0
  101. package/dist/src/mcpl/toolset-host.d.ts +200 -0
  102. package/dist/src/mcpl/toolset-host.d.ts.map +1 -0
  103. package/dist/src/mcpl/toolset-host.js +621 -0
  104. package/dist/src/mcpl/toolset-host.js.map +1 -0
  105. package/dist/src/mcpl/toolsets-module.d.ts +80 -0
  106. package/dist/src/mcpl/toolsets-module.d.ts.map +1 -0
  107. package/dist/src/mcpl/toolsets-module.js +431 -0
  108. package/dist/src/mcpl/toolsets-module.js.map +1 -0
  109. package/dist/src/mcpl/transport.d.ts +2 -2
  110. package/dist/src/mcpl/transport.d.ts.map +1 -1
  111. package/dist/src/mcpl/transport.js +3 -2
  112. package/dist/src/mcpl/transport.js.map +1 -1
  113. package/dist/src/mcpl/types.d.ts +21 -1
  114. package/dist/src/mcpl/types.d.ts.map +1 -1
  115. package/dist/src/mcpl/types.js.map +1 -1
  116. package/dist/src/mcpl/visible-content.d.ts +7 -9
  117. package/dist/src/mcpl/visible-content.d.ts.map +1 -1
  118. package/dist/src/mcpl/visible-content.js +21 -9
  119. package/dist/src/mcpl/visible-content.js.map +1 -1
  120. package/dist/src/module-registry.d.ts +23 -8
  121. package/dist/src/module-registry.d.ts.map +1 -1
  122. package/dist/src/module-registry.js +68 -15
  123. package/dist/src/module-registry.js.map +1 -1
  124. package/dist/src/modules/discord/index.js +1 -1
  125. package/dist/src/modules/discord/index.js.map +1 -1
  126. package/dist/src/modules/history/index.d.ts +2 -1
  127. package/dist/src/modules/history/index.d.ts.map +1 -1
  128. package/dist/src/modules/history/index.js +51 -17
  129. package/dist/src/modules/history/index.js.map +1 -1
  130. package/dist/src/modules/history/semantic.d.ts +108 -6
  131. package/dist/src/modules/history/semantic.d.ts.map +1 -1
  132. package/dist/src/modules/history/semantic.js +273 -57
  133. package/dist/src/modules/history/semantic.js.map +1 -1
  134. package/dist/src/modules/workspace/direct-write.d.ts +181 -0
  135. package/dist/src/modules/workspace/direct-write.d.ts.map +1 -0
  136. package/dist/src/modules/workspace/direct-write.js +384 -0
  137. package/dist/src/modules/workspace/direct-write.js.map +1 -0
  138. package/dist/src/modules/workspace/edit-text.d.ts +26 -12
  139. package/dist/src/modules/workspace/edit-text.d.ts.map +1 -1
  140. package/dist/src/modules/workspace/edit-text.js +58 -28
  141. package/dist/src/modules/workspace/edit-text.js.map +1 -1
  142. package/dist/src/modules/workspace/effects.d.ts +10 -0
  143. package/dist/src/modules/workspace/effects.d.ts.map +1 -1
  144. package/dist/src/modules/workspace/effects.js +1 -1
  145. package/dist/src/modules/workspace/effects.js.map +1 -1
  146. package/dist/src/modules/workspace/index.d.ts +246 -27
  147. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  148. package/dist/src/modules/workspace/index.js +1216 -236
  149. package/dist/src/modules/workspace/index.js.map +1 -1
  150. package/dist/src/modules/workspace/read-page.d.ts +41 -0
  151. package/dist/src/modules/workspace/read-page.d.ts.map +1 -0
  152. package/dist/src/modules/workspace/read-page.js +213 -0
  153. package/dist/src/modules/workspace/read-page.js.map +1 -0
  154. package/dist/src/modules/workspace/result-text.d.ts +67 -0
  155. package/dist/src/modules/workspace/result-text.d.ts.map +1 -0
  156. package/dist/src/modules/workspace/result-text.js +94 -0
  157. package/dist/src/modules/workspace/result-text.js.map +1 -0
  158. package/dist/src/modules/workspace/text.d.ts +29 -12
  159. package/dist/src/modules/workspace/text.d.ts.map +1 -1
  160. package/dist/src/modules/workspace/text.js +35 -33
  161. package/dist/src/modules/workspace/text.js.map +1 -1
  162. package/dist/src/modules/workspace/types.d.ts +41 -17
  163. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  164. package/dist/src/modules/workspace/types.js.map +1 -1
  165. package/dist/src/sent-rows.d.ts +59 -0
  166. package/dist/src/sent-rows.d.ts.map +1 -0
  167. package/dist/src/sent-rows.js +145 -0
  168. package/dist/src/sent-rows.js.map +1 -0
  169. package/dist/src/silent-heartbeat.d.ts +17 -10
  170. package/dist/src/silent-heartbeat.d.ts.map +1 -1
  171. package/dist/src/silent-heartbeat.js.map +1 -1
  172. package/dist/src/stable-hash.d.ts +3 -0
  173. package/dist/src/stable-hash.d.ts.map +1 -0
  174. package/dist/src/stable-hash.js +15 -0
  175. package/dist/src/stable-hash.js.map +1 -0
  176. package/dist/src/stored-injections.d.ts +99 -0
  177. package/dist/src/stored-injections.d.ts.map +1 -0
  178. package/dist/src/stored-injections.js +106 -0
  179. package/dist/src/stored-injections.js.map +1 -0
  180. package/dist/src/text-as-stored.d.ts +4 -3
  181. package/dist/src/text-as-stored.d.ts.map +1 -1
  182. package/dist/src/text-as-stored.js +4 -3
  183. package/dist/src/text-as-stored.js.map +1 -1
  184. package/dist/src/thinking-drops.d.ts +81 -0
  185. package/dist/src/thinking-drops.d.ts.map +1 -0
  186. package/dist/src/thinking-drops.js +103 -0
  187. package/dist/src/thinking-drops.js.map +1 -0
  188. package/dist/src/tool-image-ledger.d.ts +9 -8
  189. package/dist/src/tool-image-ledger.d.ts.map +1 -1
  190. package/dist/src/tool-image-ledger.js +9 -8
  191. package/dist/src/tool-image-ledger.js.map +1 -1
  192. package/dist/src/tool-presentation.d.ts.map +1 -1
  193. package/dist/src/tool-presentation.js +3 -1
  194. package/dist/src/tool-presentation.js.map +1 -1
  195. package/dist/src/tool-result-guard.d.ts +4 -2
  196. package/dist/src/tool-result-guard.d.ts.map +1 -1
  197. package/dist/src/tool-result-guard.js +21 -6
  198. package/dist/src/tool-result-guard.js.map +1 -1
  199. package/dist/src/tool-result-history.d.ts +186 -21
  200. package/dist/src/tool-result-history.d.ts.map +1 -1
  201. package/dist/src/tool-result-history.js +428 -89
  202. package/dist/src/tool-result-history.js.map +1 -1
  203. package/dist/src/tune-out/coordinator.d.ts +17 -9
  204. package/dist/src/tune-out/coordinator.d.ts.map +1 -1
  205. package/dist/src/tune-out/coordinator.js +84 -37
  206. package/dist/src/tune-out/coordinator.js.map +1 -1
  207. package/dist/src/types/agent.d.ts +186 -7
  208. package/dist/src/types/agent.d.ts.map +1 -1
  209. package/dist/src/types/events.d.ts +19 -2
  210. package/dist/src/types/events.d.ts.map +1 -1
  211. package/dist/src/types/framework.d.ts +24 -3
  212. package/dist/src/types/framework.d.ts.map +1 -1
  213. package/dist/src/types/module.d.ts +90 -7
  214. package/dist/src/types/module.d.ts.map +1 -1
  215. package/dist/src/types/trace.d.ts +57 -2
  216. package/dist/src/types/trace.d.ts.map +1 -1
  217. package/package.json +4 -3
  218. package/src/agent.ts +593 -60
  219. package/src/api/server.ts +1 -2
  220. package/src/auto-continue.ts +42 -0
  221. package/src/code-execution/isolate/scripts.ts +11 -3
  222. package/src/framework.ts +4004 -1026
  223. package/src/gate/event-gate.ts +2315 -389
  224. package/src/gate/index.ts +2 -1
  225. package/src/gate/recipe-reconcile.ts +355 -0
  226. package/src/gate/types.ts +70 -8
  227. package/src/index.ts +7 -4
  228. package/src/mcpl/channel-registry.ts +1220 -467
  229. package/src/mcpl/conversation-router.ts +34 -16
  230. package/src/mcpl/convert-block.ts +14 -1
  231. package/src/mcpl/hook-orchestrator.ts +33 -6
  232. package/src/mcpl/index.ts +6 -1
  233. package/src/mcpl/inference-router.ts +79 -34
  234. package/src/mcpl/prose-grammar.ts +7 -0
  235. package/src/mcpl/protocol-family.ts +2 -0
  236. package/src/mcpl/push-coalescer.ts +51 -13
  237. package/src/mcpl/reference-fetcher.ts +201 -162
  238. package/src/mcpl/references.ts +852 -78
  239. package/src/mcpl/server-connection.ts +145 -7
  240. package/src/mcpl/tool-lifecycle.ts +21 -0
  241. package/src/mcpl/tool-presence.ts +650 -0
  242. package/src/mcpl/tool-result-normalize.ts +18 -6
  243. package/src/mcpl/tool-signature.ts +285 -0
  244. package/src/mcpl/toolset-host.ts +637 -0
  245. package/src/mcpl/toolsets-module.ts +451 -0
  246. package/src/mcpl/transport.ts +3 -2
  247. package/src/mcpl/types.ts +22 -1
  248. package/src/mcpl/visible-content.ts +22 -9
  249. package/src/module-registry.ts +77 -24
  250. package/src/modules/discord/index.ts +1 -1
  251. package/src/modules/history/index.ts +48 -18
  252. package/src/modules/history/semantic.ts +308 -54
  253. package/src/modules/workspace/direct-write.ts +425 -0
  254. package/src/modules/workspace/edit-text.ts +82 -35
  255. package/src/modules/workspace/effects.ts +1 -1
  256. package/src/modules/workspace/index.ts +1274 -241
  257. package/src/modules/workspace/read-page.ts +222 -0
  258. package/src/modules/workspace/result-text.ts +119 -0
  259. package/src/modules/workspace/text.ts +58 -32
  260. package/src/modules/workspace/types.ts +41 -17
  261. package/src/sent-rows.ts +162 -0
  262. package/src/silent-heartbeat.ts +17 -10
  263. package/src/stable-hash.ts +14 -0
  264. package/src/stored-injections.ts +131 -0
  265. package/src/text-as-stored.ts +4 -3
  266. package/src/thinking-drops.ts +141 -0
  267. package/src/tool-image-ledger.ts +9 -8
  268. package/src/tool-presentation.ts +3 -1
  269. package/src/tool-result-guard.ts +19 -6
  270. package/src/tool-result-history.ts +488 -88
  271. package/src/tune-out/coordinator.ts +80 -37
  272. package/src/types/agent.ts +189 -7
  273. package/src/types/events.ts +19 -2
  274. package/src/types/framework.ts +21 -3
  275. package/src/types/module.ts +86 -7
  276. package/src/types/trace.ts +58 -2
@@ -25,6 +25,29 @@ export interface MessageQuery {
25
25
  metadata?: Record<string, unknown>;
26
26
  }
27
27
 
28
+ /**
29
+ * A context injection a module gathers (Module.gatherContext).
30
+ *
31
+ * An `afterUser` one is stored in the agent's window, as the message
32
+ * `compile()` would have placed after the last user message, where it then
33
+ * stays: so the replies after it keep their thinking, and the cache keeps the
34
+ * turns before it. The same source's unchanged content isn't stored again
35
+ * while the copy the agent will read as current has it whole: the one its
36
+ * last request held, or a newer one a start stored whose compile then
37
+ * didn't record. Once a fold has summarized it or a strategy's window has
38
+ * scrolled past it, it's stored again, as one more row. (See
39
+ * stored-injections.ts.)
40
+ *
41
+ * `placedEachCompile: true` opts out: `compile()` places the injection after
42
+ * the last user message at each start, near the end, as before it was
43
+ * stored. That's for context meant to stay near the end, such as
44
+ * instructions moved off `system`. Its cost: it moves, and on a model that
45
+ * binds a reply's thinking to everything before it, every reply after its old
46
+ * place loses its thinking. It has no effect on a `system` or `beforeUser`
47
+ * injection, which `compile()` always places.
48
+ */
49
+ export type ModuleContextInjection = ContextInjection & { placedEachCompile?: true };
50
+
28
51
  /**
29
52
  * A message as a module context's reads answer it: a stored row, or a row
30
53
  * for a write the framework holds (`held`). Either is marked
@@ -159,9 +182,16 @@ export interface Module {
159
182
  * Called before each inference to collect data (e.g., HUD overlays, game state)
160
183
  * that should be injected into the compiled context.
161
184
  * Complementary to MCPL push-based hooks — modules pull via gatherContext.
185
+ * An `afterUser` injection is appended to the agent's window, where it
186
+ * then stays, unless the copy the agent will read as current has the same
187
+ * content, every part of it (the one its last request held, or a newer
188
+ * one a start stored whose compile then didn't record), or it opts out
189
+ * (ModuleContextInjection.placedEachCompile). At a
190
+ * turn's start or a restart after tool results, that's where `compile()`
191
+ * would have placed it.
162
192
  * Adapted from Anarchid/agent-framework@mcpl-module-proto.
163
193
  */
164
- gatherContext?(agentName: string): Promise<ContextInjection[]>;
194
+ gatherContext?(agentName: string): Promise<ModuleContextInjection[]>;
165
195
 
166
196
  /**
167
197
  * Called once an agent's tool batch has completed — when the round's last
@@ -304,11 +334,43 @@ export interface ModuleContext {
304
334
  * (ModuleMessage.held). The writes a process held, and keeps across a
305
335
  * restart, show to the next process's modules once create() has restored
306
336
  * them, which is after every module's start().
337
+ *
338
+ * With `opts.forAgent`, it's added to the named agent's window instead: a
339
+ * conversation fork's or a running sub-agent's own store, or, for an
340
+ * ordinary resident, the residents' shared slot. It's held while that
341
+ * agent's turn is alive, as a write for the primary is while the
342
+ * primary's is. A name that isn't a registered agent when the write is
343
+ * made, or the empty name, throws, naming the registered ones, so a write
344
+ * for a launcher that has gone is heard. For an ephemeral run (a
345
+ * sub-agent's run) or a conversation fork, whose window nothing reads
346
+ * after it's released, a write it never read goes to the primary at its
347
+ * release, as the write itself, through the primary's own delivery. It's
348
+ * read as the framework reads a notice: once it's below the target's
349
+ * consumed watermark, which a compile built to send moves when it
350
+ * commits (a row that compile's strategy left out counts as read too),
351
+ * and a tool round moves when it injects messages into a stream that
352
+ * declares it carries them. So one that waited for its target's end (a
353
+ * run's end, or a fork's last turn), one stored while it was idle and
354
+ * never sent, one stored at a tool round that ended the turn, and one
355
+ * injected into a stream that didn't declare it carries injections go to
356
+ * the primary. The framework's own
357
+ * writes for a run or a fork are unchanged: they stay in its store,
358
+ * unless they're notices the primary already takes in their place (a
359
+ * failed reply, or a channel notice its reader could act on). getMessage,
360
+ * editMessage and removeMessage read the delivery agent's window (the
361
+ * primary's, or the first agent's when none is primary): they don't take
362
+ * an id or handle for a row in a fork's or a sub-agent's window, and don't
363
+ * find it (read it with queryMessages and the same forAgent). The
364
+ * residents' shared slot is the primary's window too, for a primary
365
+ * that's an ordinary resident, so there they do.
366
+ * `metadata.external` with a target throws: its id map is read in the
367
+ * primary's window.
307
368
  */
308
369
  addMessage(
309
370
  participant: string,
310
371
  content: ContentBlock[],
311
- metadata?: MessageMetadata & { external?: ExternalIdRef }
372
+ metadata?: MessageMetadata & { external?: ExternalIdRef },
373
+ opts?: { forAgent?: string },
312
374
  ): MessageId;
313
375
 
314
376
  /**
@@ -354,8 +416,17 @@ export interface ModuleContext {
354
416
  * restored them, after every module's start() (addMessage). A message a
355
417
  * tune-out holds from the residents is among the rows, marked
356
418
  * `heldFromResidents` (ModuleMessage).
419
+ *
420
+ * It reads the primary's window (the first registered agent's when none
421
+ * is primary), or with `opts.forAgent`, the named agent's: a conversation
422
+ * fork's or a running sub-agent's own store, or, for an ordinary resident,
423
+ * the residents' shared slot. For the subconscious, it's the
424
+ * subconscious's own store, not the residents' slot its compile merges
425
+ * in. A name that isn't a registered agent, or the empty name, throws,
426
+ * naming the registered ones, so a typo is heard rather than read as an
427
+ * empty window.
357
428
  */
358
- queryMessages(filter: MessageQuery): MessageQueryResult;
429
+ queryMessages(filter: MessageQuery, opts?: { forAgent?: string }): MessageQueryResult;
359
430
 
360
431
  /**
361
432
  * Get info about all agents.
@@ -512,7 +583,15 @@ export interface AgentInfo {
512
583
  export type AgentStatus = 'idle' | 'inferring' | 'streaming' | 'waiting_for_tools' | 'ready';
513
584
 
514
585
  /**
515
- * Response from a module's event handler.
586
+ * Response from a module's event handler. The framework applies it in this
587
+ * order: its messages added, edited and removed, then its stateUpdate, then
588
+ * its inference request. When one of these throws, such as an edit of a
589
+ * message the store doesn't hold, what came before it stays applied, the
590
+ * operation that threw may have taken effect in part or whole (a store can
591
+ * throw after it wrote), the rest of the response isn't, and a line names
592
+ * the module and where it threw; the event's other responses, a tool call's dispatch and its trace
593
+ * go on. Content the framework finds malformed refuses the whole response
594
+ * before any of it applies.
516
595
  */
517
596
  export interface EventResponse {
518
597
  /**
@@ -546,9 +625,9 @@ export interface EventResponse {
546
625
  toolsChanged?: boolean;
547
626
 
548
627
  /**
549
- * Module state update. Applied atomically with message operations.
550
- * The framework will call setState() with this value after applying
551
- * message changes, ensuring consistent state.
628
+ * Module state update. The framework calls setState() with this value
629
+ * after applying the response's message changes, and not when one of
630
+ * them threw.
552
631
  */
553
632
  stateUpdate?: unknown;
554
633
  }
@@ -1,3 +1,4 @@
1
+ import type { ThinkingBindingEntry } from '@animalabs/membrane';
1
2
  import type { ProcessEvent } from './events.js';
2
3
  import type { ModuleProcessResponse } from './framework.js';
3
4
  import type { SessionUsage } from '../usage/types.js';
@@ -66,6 +67,14 @@ export type TraceEvent =
66
67
  * without re-deriving routing.
67
68
  */
68
69
  channelId?: string;
70
+ /**
71
+ * The server that registers `channelId`, given with it. Two MCPL
72
+ * servers may register one channel id, so a tap that posts back to the
73
+ * turn's channel, such as a host telling it the turn failed, passes this
74
+ * server with the id. The streaming traces, `inference:tokens` and
75
+ * `inference:content_block`, carry the id alone.
76
+ */
77
+ serverId?: string;
69
78
  /** True for a control-plane wake that must not surface typing/prose. */
70
79
  silent?: boolean;
71
80
  })
@@ -146,7 +155,9 @@ export type TraceEvent =
146
155
  * content in it or its retry after a refusal, and a tool result the
147
156
  * boundary reports carries the channel of the round it answers. In
148
157
  * hybrid mode a `>>>` envelope can send the text itself elsewhere.
149
- * Explicit mode: the channel the start's wake came from. */
158
+ * Explicit mode: the channel its typing shows, where the start's wake
159
+ * came from, or, at a start whose wake names none, such as a budget
160
+ * restart, the one the turn already shows. */
150
161
  channelId?: string;
151
162
  })
152
163
  | (TraceEventBase & {
@@ -169,7 +180,9 @@ export type TraceEvent =
169
180
  * content in it or its retry after a refusal, and a tool result the
170
181
  * boundary reports carries the channel of the round it answers. In
171
182
  * hybrid mode a `>>>` envelope can send the text itself elsewhere.
172
- * Explicit mode: the channel the start's wake came from. */
183
+ * Explicit mode: the channel its typing shows, where the start's wake
184
+ * came from, or, at a start whose wake names none, such as a budget
185
+ * restart, the one the turn already shows. */
173
186
  channelId?: string;
174
187
  })
175
188
  | (TraceEventBase & {
@@ -181,6 +194,20 @@ export type TraceEvent =
181
194
  type: 'inference:usage';
182
195
  agentName: string;
183
196
  tokenUsage: { input: number; output: number; cacheCreation?: number; cacheRead?: number };
197
+ /**
198
+ * The provider's report on the signed thinking of the call this event
199
+ * closes (membrane's `RoundReport.thinking`): blocks it dropped before
200
+ * the model saw them, and blocks it showed the model anyway because the
201
+ * check isn't enforced. `tokenUsage` beside it is the stream's running
202
+ * total, not this call's. The provider reports them for a request that
203
+ * carried the binding control, whoever asked for it:
204
+ * `thinkingBinding.dropBlock`, or a thinking config the host sends
205
+ * itself. Present only when the report names any block.
206
+ */
207
+ thinking?: {
208
+ dropped: ThinkingBindingEntry[];
209
+ mismatchAllowed: ThinkingBindingEntry[];
210
+ };
184
211
  })
185
212
  | (TraceEventBase & {
186
213
  type: 'inference:stream_resumed';
@@ -445,6 +472,20 @@ export type TraceEvent =
445
472
  policyName: string;
446
473
  eventCount: number;
447
474
  })
475
+ | (TraceEventBase & {
476
+ /** A batched wake's turn started without its `[Gate: …]` line (the
477
+ * gate hands the line to the wake when its message is the newest at
478
+ * the fire, EventGate isNewestEntry, and the turn's start decides).
479
+ * `reason`: `newest`, on the delivery agent's start the message was
480
+ * still the newest entry in the window; `held`, the host was quiesced
481
+ * or another reader of the residents' shared slot had a turn alive,
482
+ * so no line could be written then. */
483
+ type: 'gate:wake-line-omitted';
484
+ reason: 'newest' | 'held';
485
+ policyNames: string[];
486
+ eventType: string;
487
+ channelId?: string;
488
+ })
448
489
  | (TraceEventBase & {
449
490
  type: 'gate:config-reloaded';
450
491
  configPath: string;
@@ -508,6 +549,8 @@ export type TraceEvent =
508
549
  | (TraceEventBase & {
509
550
  type: 'mcpl:conversation-spawned';
510
551
  channelId: string;
552
+ /** The channel's server: a channel id is unique only within one server. */
553
+ serverId: string;
511
554
  agentName: string;
512
555
  generation: number;
513
556
  template: string;
@@ -515,22 +558,30 @@ export type TraceEvent =
515
558
  | (TraceEventBase & {
516
559
  type: 'mcpl:conversation-spawn-failed';
517
560
  channelId: string;
561
+ /** The channel's server: a channel id is unique only within one server. */
562
+ serverId: string;
518
563
  agentName: string;
519
564
  error: string;
520
565
  })
521
566
  | (TraceEventBase & {
522
567
  type: 'mcpl:conversation-unrouted';
523
568
  channelId: string;
569
+ /** The channel's server: a channel id is unique only within one server. */
570
+ serverId: string;
524
571
  messageId: string;
525
572
  })
526
573
  | (TraceEventBase & {
527
574
  type: 'mcpl:conversation-binding-orphaned';
528
575
  channelId: string;
576
+ /** The channel's server: a channel id is unique only within one server. */
577
+ serverId: string;
529
578
  agentName: string;
530
579
  })
531
580
  | (TraceEventBase & {
532
581
  type: 'mcpl:conversation-closed';
533
582
  channelId: string;
583
+ /** The channel's server: a channel id is unique only within one server. */
584
+ serverId: string;
534
585
  agentName: string;
535
586
  reason: 'idle-ttl';
536
587
  })
@@ -538,6 +589,8 @@ export type TraceEvent =
538
589
  type: 'mcpl:conversation-disposed';
539
590
  agentName: string;
540
591
  channelId?: string;
592
+ /** The home channel's server, beside its channelId. */
593
+ serverId?: string;
541
594
  })
542
595
 
543
596
  // Host-owned speech routing (ChannelRegistry.routeSpeech). One trace per
@@ -569,6 +622,9 @@ export type TraceEvent =
569
622
  type: 'mcpl:speech-route-failed';
570
623
  /** Agent / conversation whose speech failed to route. */
571
624
  conversationId: string;
625
+ /** The channel's server, where the destination, or the caller, named
626
+ * one: a channel id is unique only within one server. */
627
+ serverId?: string;
572
628
  /** Empty string when the failure was "no locus at all". */
573
629
  channelId: string;
574
630
  reason: string;