@animalabs/agent-framework 0.31.0 → 0.33.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 (298) hide show
  1. package/README.md +204 -14
  2. package/dist/src/admission/admit.d.ts +18 -0
  3. package/dist/src/admission/admit.d.ts.map +1 -1
  4. package/dist/src/admission/admit.js +16 -3
  5. package/dist/src/admission/admit.js.map +1 -1
  6. package/dist/src/agent.d.ts +185 -78
  7. package/dist/src/agent.d.ts.map +1 -1
  8. package/dist/src/agent.js +279 -102
  9. package/dist/src/agent.js.map +1 -1
  10. package/dist/src/api/mcp-server-core.d.ts.map +1 -1
  11. package/dist/src/api/mcp-server-core.js +50 -12
  12. package/dist/src/api/mcp-server-core.js.map +1 -1
  13. package/dist/src/api/server.d.ts.map +1 -1
  14. package/dist/src/api/server.js +4 -20
  15. package/dist/src/api/server.js.map +1 -1
  16. package/dist/src/code-execution/isolate/scripts.d.ts +12 -8
  17. package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -1
  18. package/dist/src/code-execution/isolate/scripts.js +24 -0
  19. package/dist/src/code-execution/isolate/scripts.js.map +1 -1
  20. package/dist/src/config-checks.d.ts +7 -0
  21. package/dist/src/config-checks.d.ts.map +1 -1
  22. package/dist/src/config-checks.js +14 -0
  23. package/dist/src/config-checks.js.map +1 -1
  24. package/dist/src/context-manager-errors.d.ts +25 -0
  25. package/dist/src/context-manager-errors.d.ts.map +1 -0
  26. package/dist/src/context-manager-errors.js +31 -0
  27. package/dist/src/context-manager-errors.js.map +1 -0
  28. package/dist/src/context-options.d.ts +67 -0
  29. package/dist/src/context-options.d.ts.map +1 -0
  30. package/dist/src/context-options.js +85 -0
  31. package/dist/src/context-options.js.map +1 -0
  32. package/dist/src/deferred-import.d.ts +93 -0
  33. package/dist/src/deferred-import.d.ts.map +1 -0
  34. package/dist/src/deferred-import.js +177 -0
  35. package/dist/src/deferred-import.js.map +1 -0
  36. package/dist/src/dendrite/audience.d.ts +223 -0
  37. package/dist/src/dendrite/audience.d.ts.map +1 -0
  38. package/dist/src/dendrite/audience.js +202 -0
  39. package/dist/src/dendrite/audience.js.map +1 -0
  40. package/dist/src/dendrite/index.d.ts +5 -3
  41. package/dist/src/dendrite/index.d.ts.map +1 -1
  42. package/dist/src/dendrite/index.js +2 -1
  43. package/dist/src/dendrite/index.js.map +1 -1
  44. package/dist/src/dendrite/presets.d.ts +10 -5
  45. package/dist/src/dendrite/presets.d.ts.map +1 -1
  46. package/dist/src/dendrite/presets.js +17 -5
  47. package/dist/src/dendrite/presets.js.map +1 -1
  48. package/dist/src/dendrite/registry.d.ts +62 -7
  49. package/dist/src/dendrite/registry.d.ts.map +1 -1
  50. package/dist/src/dendrite/registry.js +179 -10
  51. package/dist/src/dendrite/registry.js.map +1 -1
  52. package/dist/src/dendrite/types.d.ts +91 -8
  53. package/dist/src/dendrite/types.d.ts.map +1 -1
  54. package/dist/src/foreign-rounds.d.ts +69 -0
  55. package/dist/src/foreign-rounds.d.ts.map +1 -0
  56. package/dist/src/foreign-rounds.js +152 -0
  57. package/dist/src/foreign-rounds.js.map +1 -0
  58. package/dist/src/framework.d.ts +1977 -820
  59. package/dist/src/framework.d.ts.map +1 -1
  60. package/dist/src/framework.js +7571 -3457
  61. package/dist/src/framework.js.map +1 -1
  62. package/dist/src/gate/event-gate.d.ts +85 -15
  63. package/dist/src/gate/event-gate.d.ts.map +1 -1
  64. package/dist/src/gate/event-gate.js +421 -47
  65. package/dist/src/gate/event-gate.js.map +1 -1
  66. package/dist/src/gate/index.d.ts +1 -1
  67. package/dist/src/gate/index.d.ts.map +1 -1
  68. package/dist/src/gate/index.js.map +1 -1
  69. package/dist/src/gate/rule-scope.d.ts +30 -0
  70. package/dist/src/gate/rule-scope.d.ts.map +1 -0
  71. package/dist/src/gate/rule-scope.js +41 -0
  72. package/dist/src/gate/rule-scope.js.map +1 -0
  73. package/dist/src/gate/suppress-script-worker.d.ts +2 -0
  74. package/dist/src/gate/suppress-script-worker.d.ts.map +1 -0
  75. package/dist/src/gate/suppress-script-worker.js +103 -0
  76. package/dist/src/gate/suppress-script-worker.js.map +1 -0
  77. package/dist/src/gate/suppress-scripts.d.ts +105 -0
  78. package/dist/src/gate/suppress-scripts.d.ts.map +1 -0
  79. package/dist/src/gate/suppress-scripts.js +403 -0
  80. package/dist/src/gate/suppress-scripts.js.map +1 -0
  81. package/dist/src/gate/suppression-review.d.ts +143 -0
  82. package/dist/src/gate/suppression-review.d.ts.map +1 -0
  83. package/dist/src/gate/suppression-review.js +463 -0
  84. package/dist/src/gate/suppression-review.js.map +1 -0
  85. package/dist/src/gate/suppression-stats.d.ts +125 -0
  86. package/dist/src/gate/suppression-stats.d.ts.map +1 -0
  87. package/dist/src/gate/suppression-stats.js +214 -0
  88. package/dist/src/gate/suppression-stats.js.map +1 -0
  89. package/dist/src/gate/types.d.ts +135 -7
  90. package/dist/src/gate/types.d.ts.map +1 -1
  91. package/dist/src/gate/wake-onboarding.d.ts +119 -0
  92. package/dist/src/gate/wake-onboarding.d.ts.map +1 -0
  93. package/dist/src/gate/wake-onboarding.js +277 -0
  94. package/dist/src/gate/wake-onboarding.js.map +1 -0
  95. package/dist/src/held-writes.d.ts +31 -23
  96. package/dist/src/held-writes.d.ts.map +1 -1
  97. package/dist/src/held-writes.js +44 -59
  98. package/dist/src/held-writes.js.map +1 -1
  99. package/dist/src/index.d.ts +5 -2
  100. package/dist/src/index.d.ts.map +1 -1
  101. package/dist/src/index.js +3 -0
  102. package/dist/src/index.js.map +1 -1
  103. package/dist/src/jsonrpc-envelope.d.ts +69 -0
  104. package/dist/src/jsonrpc-envelope.d.ts.map +1 -0
  105. package/dist/src/jsonrpc-envelope.js +66 -0
  106. package/dist/src/jsonrpc-envelope.js.map +1 -0
  107. package/dist/src/mcpl/channel-registry.d.ts +131 -15
  108. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  109. package/dist/src/mcpl/channel-registry.js +290 -46
  110. package/dist/src/mcpl/channel-registry.js.map +1 -1
  111. package/dist/src/mcpl/checkpoint-manager.d.ts +2 -4
  112. package/dist/src/mcpl/checkpoint-manager.d.ts.map +1 -1
  113. package/dist/src/mcpl/checkpoint-manager.js.map +1 -1
  114. package/dist/src/mcpl/feature-set-manager.d.ts +2 -4
  115. package/dist/src/mcpl/feature-set-manager.d.ts.map +1 -1
  116. package/dist/src/mcpl/feature-set-manager.js.map +1 -1
  117. package/dist/src/mcpl/inbound-source.d.ts +2 -1
  118. package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
  119. package/dist/src/mcpl/inbound-source.js +2 -1
  120. package/dist/src/mcpl/inbound-source.js.map +1 -1
  121. package/dist/src/mcpl/inference-router.d.ts +6 -6
  122. package/dist/src/mcpl/inference-router.d.ts.map +1 -1
  123. package/dist/src/mcpl/inference-router.js.map +1 -1
  124. package/dist/src/mcpl/push-coalescer.d.ts +132 -22
  125. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  126. package/dist/src/mcpl/push-coalescer.js +105 -15
  127. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  128. package/dist/src/mcpl/push-handler.d.ts +9 -7
  129. package/dist/src/mcpl/push-handler.d.ts.map +1 -1
  130. package/dist/src/mcpl/push-handler.js.map +1 -1
  131. package/dist/src/mcpl/server-connection.d.ts +13 -10
  132. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  133. package/dist/src/mcpl/server-connection.js +134 -56
  134. package/dist/src/mcpl/server-connection.js.map +1 -1
  135. package/dist/src/mcpl/tool-classes.d.ts.map +1 -1
  136. package/dist/src/mcpl/tool-classes.js +3 -0
  137. package/dist/src/mcpl/tool-classes.js.map +1 -1
  138. package/dist/src/mcpl/types.d.ts +8 -2
  139. package/dist/src/mcpl/types.d.ts.map +1 -1
  140. package/dist/src/mcpl/types.js.map +1 -1
  141. package/dist/src/module-registry.d.ts +24 -1
  142. package/dist/src/module-registry.d.ts.map +1 -1
  143. package/dist/src/module-registry.js +68 -18
  144. package/dist/src/module-registry.js.map +1 -1
  145. package/dist/src/modules/discord/index.d.ts +45 -8
  146. package/dist/src/modules/discord/index.d.ts.map +1 -1
  147. package/dist/src/modules/discord/index.js +237 -86
  148. package/dist/src/modules/discord/index.js.map +1 -1
  149. package/dist/src/modules/history/index.d.ts +59 -0
  150. package/dist/src/modules/history/index.d.ts.map +1 -1
  151. package/dist/src/modules/history/index.js +432 -67
  152. package/dist/src/modules/history/index.js.map +1 -1
  153. package/dist/src/modules/history/semantic.d.ts +6 -5
  154. package/dist/src/modules/history/semantic.d.ts.map +1 -1
  155. package/dist/src/modules/history/semantic.js +15 -22
  156. package/dist/src/modules/history/semantic.js.map +1 -1
  157. package/dist/src/modules/workspace/disk-agreement.d.ts +1 -1
  158. package/dist/src/modules/workspace/disk-agreement.js +1 -1
  159. package/dist/src/modules/workspace/index.d.ts +28 -7
  160. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  161. package/dist/src/modules/workspace/index.js +76 -22
  162. package/dist/src/modules/workspace/index.js.map +1 -1
  163. package/dist/src/notice-tags.d.ts +10 -1
  164. package/dist/src/notice-tags.d.ts.map +1 -1
  165. package/dist/src/notice-tags.js +10 -1
  166. package/dist/src/notice-tags.js.map +1 -1
  167. package/dist/src/operator-log.d.ts +36 -3
  168. package/dist/src/operator-log.d.ts.map +1 -1
  169. package/dist/src/operator-log.js +2 -2
  170. package/dist/src/operator-log.js.map +1 -1
  171. package/dist/src/presentation.d.ts +746 -0
  172. package/dist/src/presentation.d.ts.map +1 -0
  173. package/dist/src/presentation.js +1435 -0
  174. package/dist/src/presentation.js.map +1 -0
  175. package/dist/src/prose-drafts.d.ts +15 -11
  176. package/dist/src/prose-drafts.d.ts.map +1 -1
  177. package/dist/src/prose-drafts.js +16 -12
  178. package/dist/src/prose-drafts.js.map +1 -1
  179. package/dist/src/read-marks.d.ts +192 -0
  180. package/dist/src/read-marks.d.ts.map +1 -0
  181. package/dist/src/read-marks.js +242 -0
  182. package/dist/src/read-marks.js.map +1 -0
  183. package/dist/src/recovery/offline-branch.d.ts +91 -6
  184. package/dist/src/recovery/offline-branch.d.ts.map +1 -1
  185. package/dist/src/recovery/offline-branch.js +273 -29
  186. package/dist/src/recovery/offline-branch.js.map +1 -1
  187. package/dist/src/recovery/recover-cli.js +22 -3
  188. package/dist/src/recovery/recover-cli.js.map +1 -1
  189. package/dist/src/send-tools.d.ts +5 -9
  190. package/dist/src/send-tools.d.ts.map +1 -1
  191. package/dist/src/send-tools.js +40 -7
  192. package/dist/src/send-tools.js.map +1 -1
  193. package/dist/src/stored-injections.d.ts +2 -2
  194. package/dist/src/stored-injections.js +2 -2
  195. package/dist/src/stored-removal.d.ts +17 -4
  196. package/dist/src/stored-removal.d.ts.map +1 -1
  197. package/dist/src/stored-removal.js +29 -5
  198. package/dist/src/stored-removal.js.map +1 -1
  199. package/dist/src/tool-result-guard.d.ts +12 -1
  200. package/dist/src/tool-result-guard.d.ts.map +1 -1
  201. package/dist/src/tool-result-guard.js +42 -8
  202. package/dist/src/tool-result-guard.js.map +1 -1
  203. package/dist/src/tune-out/coordinator.d.ts +1159 -79
  204. package/dist/src/tune-out/coordinator.d.ts.map +1 -1
  205. package/dist/src/tune-out/coordinator.js +3709 -363
  206. package/dist/src/tune-out/coordinator.js.map +1 -1
  207. package/dist/src/tune-out/tools.d.ts +114 -17
  208. package/dist/src/tune-out/tools.d.ts.map +1 -1
  209. package/dist/src/tune-out/tools.js +87 -27
  210. package/dist/src/tune-out/tools.js.map +1 -1
  211. package/dist/src/tune-out/window-anchor.d.ts +143 -0
  212. package/dist/src/tune-out/window-anchor.d.ts.map +1 -0
  213. package/dist/src/tune-out/window-anchor.js +202 -0
  214. package/dist/src/tune-out/window-anchor.js.map +1 -0
  215. package/dist/src/types/agent.d.ts +86 -31
  216. package/dist/src/types/agent.d.ts.map +1 -1
  217. package/dist/src/types/events.d.ts +2 -0
  218. package/dist/src/types/events.d.ts.map +1 -1
  219. package/dist/src/types/framework.d.ts +43 -21
  220. package/dist/src/types/framework.d.ts.map +1 -1
  221. package/dist/src/types/module.d.ts +180 -69
  222. package/dist/src/types/module.d.ts.map +1 -1
  223. package/dist/src/types/trace.d.ts +510 -36
  224. package/dist/src/types/trace.d.ts.map +1 -1
  225. package/package.json +3 -3
  226. package/src/admission/admit.ts +32 -3
  227. package/src/agent.ts +323 -120
  228. package/src/api/mcp-server-core.ts +54 -17
  229. package/src/api/server.ts +4 -23
  230. package/src/code-execution/isolate/scripts.ts +28 -3
  231. package/src/config-checks.ts +14 -0
  232. package/src/context-manager-errors.ts +37 -0
  233. package/src/context-options.ts +96 -0
  234. package/src/deferred-import.ts +239 -0
  235. package/src/dendrite/audience.ts +315 -0
  236. package/src/dendrite/index.ts +14 -2
  237. package/src/dendrite/presets.ts +18 -6
  238. package/src/dendrite/registry.ts +209 -12
  239. package/src/dendrite/types.ts +92 -8
  240. package/src/foreign-rounds.ts +199 -0
  241. package/src/framework.ts +7814 -3585
  242. package/src/gate/event-gate.ts +428 -65
  243. package/src/gate/index.ts +3 -0
  244. package/src/gate/rule-scope.ts +45 -0
  245. package/src/gate/suppress-script-worker.ts +89 -0
  246. package/src/gate/suppress-scripts.ts +414 -0
  247. package/src/gate/suppression-review.ts +517 -0
  248. package/src/gate/suppression-stats.ts +314 -0
  249. package/src/gate/types.ts +141 -7
  250. package/src/gate/wake-onboarding.ts +309 -0
  251. package/src/held-writes.ts +49 -60
  252. package/src/index.ts +9 -2
  253. package/src/jsonrpc-envelope.ts +81 -0
  254. package/src/mcpl/channel-registry.ts +353 -85
  255. package/src/mcpl/checkpoint-manager.ts +3 -2
  256. package/src/mcpl/feature-set-manager.ts +2 -1
  257. package/src/mcpl/inbound-source.ts +2 -1
  258. package/src/mcpl/inference-router.ts +7 -4
  259. package/src/mcpl/push-coalescer.ts +193 -34
  260. package/src/mcpl/push-handler.ts +10 -5
  261. package/src/mcpl/server-connection.ts +141 -60
  262. package/src/mcpl/tool-classes.ts +3 -0
  263. package/src/mcpl/types.ts +8 -2
  264. package/src/module-registry.ts +73 -17
  265. package/src/modules/discord/index.ts +229 -81
  266. package/src/modules/history/index.ts +439 -70
  267. package/src/modules/history/semantic.ts +15 -21
  268. package/src/modules/workspace/disk-agreement.ts +1 -1
  269. package/src/modules/workspace/index.ts +85 -23
  270. package/src/notice-tags.ts +10 -1
  271. package/src/operator-log.ts +36 -3
  272. package/src/presentation.ts +1676 -0
  273. package/src/prose-drafts.ts +16 -12
  274. package/src/read-marks.ts +328 -0
  275. package/src/recovery/offline-branch.ts +346 -32
  276. package/src/recovery/recover-cli.ts +21 -3
  277. package/src/send-tools.ts +40 -7
  278. package/src/stored-injections.ts +2 -2
  279. package/src/stored-removal.ts +31 -7
  280. package/src/tool-result-guard.ts +41 -7
  281. package/src/tune-out/coordinator.ts +4089 -457
  282. package/src/tune-out/tools.ts +160 -43
  283. package/src/tune-out/window-anchor.ts +277 -0
  284. package/src/types/agent.ts +90 -31
  285. package/src/types/events.ts +2 -0
  286. package/src/types/framework.ts +43 -21
  287. package/src/types/module.ts +181 -68
  288. package/src/types/trace.ts +542 -40
  289. package/dist/src/reasoning-loss-notice.d.ts +0 -23
  290. package/dist/src/reasoning-loss-notice.d.ts.map +0 -1
  291. package/dist/src/reasoning-loss-notice.js +0 -52
  292. package/dist/src/reasoning-loss-notice.js.map +0 -1
  293. package/dist/src/reasoning-loss.d.ts +0 -24
  294. package/dist/src/reasoning-loss.d.ts.map +0 -1
  295. package/dist/src/reasoning-loss.js +0 -102
  296. package/dist/src/reasoning-loss.js.map +0 -1
  297. package/src/reasoning-loss-notice.ts +0 -64
  298. package/src/reasoning-loss.ts +0 -120
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Another agent's rounds as an agent that watches its slot is sent them
3
+ * (#291, answer 13).
4
+ *
5
+ * An agent reads another agent's rounds through an observe edge (decision
6
+ * 1), as the persistent subconscious watches the residents' slot, and an
7
+ * agent derived or forked from such a watcher inherits them, sent in its
8
+ * mode. A co-resident's rows stored before audience stamps, which a window
9
+ * written down from the record keeps, reach an agent that observes no one
10
+ * too: they go out as stored there, as earlier releases sent them. An agent
11
+ * sent others' rounds as a transcript is sent those as one, read by their
12
+ * participant.
13
+ * Those rounds are stored as the other agent's: its signed thinking, its
14
+ * tool calls and their results. None of that is valid as the watcher's own.
15
+ * A provider takes tool blocks only in their own pairing, in the turns of
16
+ * the agent that made the call, and a thinking block's signature binds it
17
+ * to the prefix the other agent was sent. Sent raw in a user turn, the
18
+ * blocks are refused, or moved into the watcher's assistant turns, where
19
+ * they read as calls the watcher made.
20
+ *
21
+ * So by default the watcher is sent them as a transcript, a line per block:
22
+ * a call as the tool's name and its input in brief, a result as the tool's
23
+ * name and its outcome in brief, and no thinking at all. Text, images and
24
+ * the rest go as stored. The signature forbids sending a thinking block as
25
+ * part of another prefix, not its text: leaving the text out is this
26
+ * transcript's choice. A host can have the rounds sent as stored instead
27
+ * (PersistentReaderConfig.foreignRounds `'raw'`, as 0.30.0 sent them). The rule is one function of the stored row, applied the same
28
+ * way to a compile's messages and to a row a tool boundary injects, so what
29
+ * the watcher's window holds and what its requests carried stay one thing.
30
+ *
31
+ * The watcher's own rows go as stored: its rounds (its own participant's
32
+ * messages), and the results of its own calls, which are stored under
33
+ * another participant (`user`) and are told by the call they answer: the
34
+ * nearest call before the result with its id, since a provider (or a mock)
35
+ * that numbers calls per response gives two agents' calls the same id.
36
+ */
37
+ import type { ContentBlock, NormalizedMessage } from '@animalabs/membrane';
38
+ /**
39
+ * One stored row of another agent's as the watcher is sent it: thinking
40
+ * dropped, each call and each result a line of text, a text block's
41
+ * provider-native item (`rawItem`) dropped with it, everything else as it is.
42
+ * `ownCalls` are the watcher's own calls, whose results it is sent as they
43
+ * are; `callNames` names the calls the row's results answer, where the
44
+ * result doesn't name its tool itself. A row left with nothing says so in
45
+ * a line, rather than going empty.
46
+ */
47
+ export declare function foreignRowAsSent(content: readonly ContentBlock[], context?: {
48
+ ownCalls?: {
49
+ has(id: string): boolean;
50
+ };
51
+ callNames?: {
52
+ get(id: string): string | undefined;
53
+ };
54
+ }): ContentBlock[];
55
+ /**
56
+ * A request's messages as an agent that watches another's slot is sent them:
57
+ * each message whose participant isn't the agent's own (`isOwn`) through
58
+ * foreignRowAsSent, with the results of the agent's own calls kept, and
59
+ * each result named by the call it answers. A result answers the nearest
60
+ * call before it with its id, read in one pass in order, so another
61
+ * agent's result whose id an own call of the watcher's also has, before or
62
+ * after it, is still transcribed. A call answers one result: a result after
63
+ * the one that answered it, in the same message or a later one, names no
64
+ * call (another agent's, whose call the request doesn't carry), and is
65
+ * transcribed. A message nothing changes is the same object, and so is the
66
+ * array when none changes.
67
+ */
68
+ export declare function transcribeForeignRounds(messages: readonly NormalizedMessage[], isOwn: (participant: string) => boolean): NormalizedMessage[];
69
+ //# sourceMappingURL=foreign-rounds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"foreign-rounds.d.ts","sourceRoot":"","sources":["../../src/foreign-rounds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAkE3E;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,YAAY,EAAE,EAChC,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAAC,SAAS,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;CAAO,GAC7G,YAAY,EAAE,CAwChB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,KAAK,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,GACtC,iBAAiB,EAAE,CA0BrB"}
@@ -0,0 +1,152 @@
1
+ import { NOTICE_TAG } from './notice-tags.js';
2
+ import { cutToFit, markedTexts, oneLine } from './supplied-text.js';
3
+ /** How long one transcript line's call or outcome runs before it is cut. */
4
+ const BRIEF_CHARS = 160;
5
+ /** `text` on one line: each line break the framework counts as one
6
+ * (oneLine), and each other run of whitespace, as one space. */
7
+ function flat(text) {
8
+ return oneLine(text).replace(/\s+/g, ' ').trim();
9
+ }
10
+ /** A tool result's content as pieces: its text, and its other blocks named
11
+ * by kind, in placeholders that are the framework's own. */
12
+ function resultPieces(content) {
13
+ if (typeof content === 'string')
14
+ return [{ text: content, supplied: true }];
15
+ return content.map((b) => (b.type === 'text'
16
+ ? { text: b.text, supplied: true }
17
+ : { text: `[${b.type}]`, supplied: false }));
18
+ }
19
+ /** A call's input as a piece: its JSON, or what the model sent when that
20
+ * wasn't an object. */
21
+ function callPiece(block) {
22
+ if (block.unparseableInput !== undefined)
23
+ return { text: block.unparseableInput, supplied: true };
24
+ try {
25
+ return { text: JSON.stringify(block.input ?? {}) ?? '', supplied: true };
26
+ }
27
+ catch {
28
+ return { text: '', supplied: true };
29
+ }
30
+ }
31
+ /**
32
+ * A transcript line: the framework's bracket around the tool's name, which
33
+ * the other agent's call supplied, the framework's words for what happened
34
+ * (`words[0]` before a call or outcome, `words[1]` when there is none), and
35
+ * the call or outcome in brief. What the line holds is supplied text
36
+ * (#852): set inside the framework's bracket here, where a tool block's own
37
+ * content isn't, an opening of one of the framework's notices is marked
38
+ * wherever it forms, read across the whole line (markedTexts): inside a
39
+ * piece, across a result's blocks, or where the name meets the bracket or
40
+ * the framework's words. Those words and the placeholders aren't marked.
41
+ * Each piece goes on one line first (flat), and the call or outcome is cut
42
+ * to BRIEF_CHARS with an ellipsis, at a whole character, never parting a
43
+ * mark from its bracket (cutToFit).
44
+ */
45
+ function transcriptLine(name, words, body) {
46
+ const pieces = body.map((p) => ({ ...p, text: flat(p.text) })).filter((p) => p.text.length > 0);
47
+ const word = pieces.length > 0 ? words[0] : words[1];
48
+ const marked = markedTexts(['[', oneLine(name), word, ...pieces.map((p) => p.text)], [true, true, false, ...pieces.map((p) => p.supplied)]);
49
+ const said = marked.slice(3).join(' ');
50
+ return `${marked.slice(0, 3).join('')}${said.length > BRIEF_CHARS ? `${cutToFit(said, BRIEF_CHARS - 1)}…` : said}]`;
51
+ }
52
+ /** Where a row with nothing left to send stands, so the transcript keeps a row for each stored one. */
53
+ const NOTHING_SAID = `[${NOTICE_TAG.noText}]`;
54
+ /**
55
+ * One stored row of another agent's as the watcher is sent it: thinking
56
+ * dropped, each call and each result a line of text, a text block's
57
+ * provider-native item (`rawItem`) dropped with it, everything else as it is.
58
+ * `ownCalls` are the watcher's own calls, whose results it is sent as they
59
+ * are; `callNames` names the calls the row's results answer, where the
60
+ * result doesn't name its tool itself. A row left with nothing says so in
61
+ * a line, rather than going empty.
62
+ */
63
+ export function foreignRowAsSent(content, context = {}) {
64
+ let changed = false;
65
+ const out = [];
66
+ for (const block of content) {
67
+ switch (block.type) {
68
+ case 'thinking':
69
+ case 'redacted_thinking':
70
+ changed = true;
71
+ break;
72
+ case 'tool_use': {
73
+ changed = true;
74
+ out.push({ type: 'text', text: transcriptLine(block.name, [' called: ', ' called: '], [callPiece(block)]) });
75
+ break;
76
+ }
77
+ case 'tool_result': {
78
+ if (context.ownCalls?.has(block.toolUseId)) {
79
+ out.push(block);
80
+ break;
81
+ }
82
+ changed = true;
83
+ const name = block.toolName ?? context.callNames?.get(block.toolUseId) ?? 'a tool';
84
+ const word = block.isError ? ' failed' : ' returned';
85
+ out.push({ type: 'text', text: transcriptLine(name, [`${word}: `, word], resultPieces(block.content)) });
86
+ break;
87
+ }
88
+ case 'text': {
89
+ if (block.rawItem === undefined) {
90
+ out.push(block);
91
+ break;
92
+ }
93
+ changed = true;
94
+ if (block.text.length > 0)
95
+ out.push({ type: 'text', text: block.text });
96
+ break;
97
+ }
98
+ default:
99
+ out.push(block);
100
+ }
101
+ }
102
+ if (!changed)
103
+ return content;
104
+ return out.length > 0 ? out : [{ type: 'text', text: NOTHING_SAID }];
105
+ }
106
+ /**
107
+ * A request's messages as an agent that watches another's slot is sent them:
108
+ * each message whose participant isn't the agent's own (`isOwn`) through
109
+ * foreignRowAsSent, with the results of the agent's own calls kept, and
110
+ * each result named by the call it answers. A result answers the nearest
111
+ * call before it with its id, read in one pass in order, so another
112
+ * agent's result whose id an own call of the watcher's also has, before or
113
+ * after it, is still transcribed. A call answers one result: a result after
114
+ * the one that answered it, in the same message or a later one, names no
115
+ * call (another agent's, whose call the request doesn't carry), and is
116
+ * transcribed. A message nothing changes is the same object, and so is the
117
+ * array when none changes.
118
+ */
119
+ export function transcribeForeignRounds(messages, isOwn) {
120
+ const latest = new Map();
121
+ // The watcher's own call is answered by the first result read for it,
122
+ // block by block: that result takes its entry, so a second result for it
123
+ // in the same message names no call.
124
+ const ownCalls = {
125
+ has: (id) => {
126
+ if (latest.get(id)?.own !== true)
127
+ return false;
128
+ latest.delete(id);
129
+ return true;
130
+ },
131
+ };
132
+ const callNames = { get: (id) => latest.get(id)?.name };
133
+ let changed = false;
134
+ const out = messages.map((m) => {
135
+ const own = isOwn(m.participant);
136
+ for (const b of m.content)
137
+ if (b.type === 'tool_use')
138
+ latest.set(b.id, { own, name: b.name });
139
+ const content = own ? m.content : foreignRowAsSent(m.content, { ownCalls, callNames });
140
+ // A call answers one result: a later result with its id (another
141
+ // agent's, whose call the request doesn't carry) answers no call here.
142
+ for (const b of m.content)
143
+ if (b.type === 'tool_result')
144
+ latest.delete(b.toolUseId);
145
+ if (content === m.content)
146
+ return m;
147
+ changed = true;
148
+ return { ...m, content };
149
+ });
150
+ return changed ? out : messages;
151
+ }
152
+ //# sourceMappingURL=foreign-rounds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"foreign-rounds.js","sourceRoot":"","sources":["../../src/foreign-rounds.ts"],"names":[],"mappings":"AAqCA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,WAAW,E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