@makaio/framework 1.0.0-dev-1779046984397

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 (410) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +363 -0
  3. package/dist/account-identity-Ce1Bwrqi.mjs +1 -0
  4. package/dist/adapter-CbyjCE2d.mjs +1 -0
  5. package/dist/adapters/acp-client/index.d.mts +209 -0
  6. package/dist/adapters/acp-client/index.mjs +1 -0
  7. package/dist/adapters/config/index.d.mts +429 -0
  8. package/dist/adapters/config/index.mjs +1 -0
  9. package/dist/adapters/index.d.mts +4175 -0
  10. package/dist/adapters/index.mjs +11 -0
  11. package/dist/adapters/node.d.mts +263 -0
  12. package/dist/adapters/node.mjs +4 -0
  13. package/dist/adapters/stream-session/index.d.mts +1384 -0
  14. package/dist/adapters/stream-session/index.mjs +1 -0
  15. package/dist/adapters/stream-session/testing/index.d.mts +29 -0
  16. package/dist/adapters/stream-session/testing/index.mjs +1 -0
  17. package/dist/base-orchestrator-9z8TuA5a.d.mts +772 -0
  18. package/dist/bus/index.d.mts +3331 -0
  19. package/dist/bus/index.mjs +1 -0
  20. package/dist/bus-B1seC4M_.mjs +2 -0
  21. package/dist/capability-service-tnpR_TaB.mjs +1 -0
  22. package/dist/chunk-Dc06z0qk.mjs +1 -0
  23. package/dist/chunk-cpUYaJdV.mjs +1 -0
  24. package/dist/cleanEnvForAdapter-DvcIGXTG.mjs +1 -0
  25. package/dist/client-Dh4x4GQN.mjs +1 -0
  26. package/dist/clients/index.d.mts +2786 -0
  27. package/dist/clients/index.mjs +1 -0
  28. package/dist/clients-namespace-B0xAPZ6J.d.mts +332 -0
  29. package/dist/config-namespace-DLSs83zr.d.mts +638 -0
  30. package/dist/config-namespace-MJT8P0Ud.mjs +1 -0
  31. package/dist/contracts/adapter/index.d.mts +3 -0
  32. package/dist/contracts/adapter/index.mjs +1 -0
  33. package/dist/contracts/adapter/schemas/session-lineage.d.mts +2 -0
  34. package/dist/contracts/adapter/schemas/session-lineage.mjs +1 -0
  35. package/dist/contracts/client/index.d.mts +3 -0
  36. package/dist/contracts/client/index.mjs +1 -0
  37. package/dist/contracts/common/index.d.mts +2 -0
  38. package/dist/contracts/common/index.mjs +1 -0
  39. package/dist/contracts/config/index.d.mts +455 -0
  40. package/dist/contracts/config/index.mjs +1 -0
  41. package/dist/contracts/extension/index.d.mts +3 -0
  42. package/dist/contracts/extension/index.mjs +1 -0
  43. package/dist/contracts/harness/index.d.mts +2 -0
  44. package/dist/contracts/harness/index.mjs +1 -0
  45. package/dist/contracts/host/index.d.mts +2 -0
  46. package/dist/contracts/host/index.mjs +1 -0
  47. package/dist/contracts/index.d.mts +12665 -0
  48. package/dist/contracts/index.mjs +1 -0
  49. package/dist/contracts/model-registry/index.d.mts +2 -0
  50. package/dist/contracts/model-registry/index.mjs +1 -0
  51. package/dist/contracts/native-session-supervisor/index.d.mts +2 -0
  52. package/dist/contracts/native-session-supervisor/index.mjs +1 -0
  53. package/dist/contracts/platform/index.d.mts +2 -0
  54. package/dist/contracts/platform/index.mjs +1 -0
  55. package/dist/contracts/provider/index.d.mts +3 -0
  56. package/dist/contracts/provider/index.mjs +1 -0
  57. package/dist/contracts/session/index.d.mts +3 -0
  58. package/dist/contracts/session/index.mjs +1 -0
  59. package/dist/contracts/shared/index.d.mts +2 -0
  60. package/dist/contracts/shared/index.mjs +1 -0
  61. package/dist/contracts/skill/index.d.mts +2 -0
  62. package/dist/contracts/skill/index.mjs +1 -0
  63. package/dist/contracts/toast/index.d.mts +198 -0
  64. package/dist/contracts/toast/index.mjs +1 -0
  65. package/dist/contracts/variant/index.d.mts +2 -0
  66. package/dist/contracts/variant/index.mjs +1 -0
  67. package/dist/core/index.d.mts +1001 -0
  68. package/dist/core/index.mjs +1 -0
  69. package/dist/credential-ref-DLCsoKVZ.mjs +1 -0
  70. package/dist/cursor-storage-DOQdvo9j.mjs +1 -0
  71. package/dist/definition-DkYy1PZz.mjs +1 -0
  72. package/dist/definition-DtUNiGom.d.mts +158 -0
  73. package/dist/definition-DxvZ9e22.d.mts +376 -0
  74. package/dist/drizzle-CWVVw7Er.mjs +1 -0
  75. package/dist/execution-target-BW_uiBVe.mjs +1 -0
  76. package/dist/extension-COqwS-2Q.mjs +1 -0
  77. package/dist/extension-Cbrl4YGX.mjs +1 -0
  78. package/dist/extension-namespace-zaGKi6Qj.mjs +1 -0
  79. package/dist/handlers-iGKUJ380.mjs +41 -0
  80. package/dist/harness-CEq1Zkf9.mjs +1 -0
  81. package/dist/hooks/index.d.mts +423 -0
  82. package/dist/hooks/index.mjs +1 -0
  83. package/dist/host-CXAUGGN0.mjs +1 -0
  84. package/dist/identity-B_A0mE63.mjs +1 -0
  85. package/dist/index-6lyShOoU.d.mts +225 -0
  86. package/dist/index-7sXlairn2.d.mts +43 -0
  87. package/dist/index-BAKM2GMH2.d.mts +535 -0
  88. package/dist/index-BB419vv-.d.mts +3897 -0
  89. package/dist/index-BJOfdtbw.d.mts +729 -0
  90. package/dist/index-BXP9GK5q.d.mts +1075 -0
  91. package/dist/index-BdPwu6c0.d.mts +1730 -0
  92. package/dist/index-BePI0ckL.d.mts +40 -0
  93. package/dist/index-Bigx81Kr.d.mts +37 -0
  94. package/dist/index-BnNqbx2I.d.mts +134 -0
  95. package/dist/index-Bv15sNLn.d.mts +389 -0
  96. package/dist/index-C-myW_aK.d.mts +412 -0
  97. package/dist/index-C9F3Fc1A.d.mts +2938 -0
  98. package/dist/index-CNxS4Tlu.d.mts +1 -0
  99. package/dist/index-CVA0m1g9.d.mts +995 -0
  100. package/dist/index-C_kS2aqV2.d.mts +438 -0
  101. package/dist/index-Ch3ph52M2.d.mts +40 -0
  102. package/dist/index-CnZOKNjU.d.mts +89 -0
  103. package/dist/index-D1T-PPqF.d.mts +67 -0
  104. package/dist/index-D7T8XCku.d.mts +341 -0
  105. package/dist/index-DBQtpFLE.d.mts +4843 -0
  106. package/dist/index-DEw90pa2.d.mts +183 -0
  107. package/dist/index-DQRsGXb5.d.mts +109 -0
  108. package/dist/index-Dd5s4MSm.d.mts +72 -0
  109. package/dist/index-DubqLGH8.d.mts +1002 -0
  110. package/dist/index-ESSDWIB7.d.mts +11 -0
  111. package/dist/index-N5K1NOYs.d.mts +184 -0
  112. package/dist/index-PdUSmPT2.d.mts +180 -0
  113. package/dist/index-SzSiyG61.d.mts +117 -0
  114. package/dist/index-T0471kWA.d.mts +6760 -0
  115. package/dist/index-WKjrpcA_.d.mts +218 -0
  116. package/dist/index-hapw9_En.d.mts +13592 -0
  117. package/dist/index-iID2R9G1.d.mts +1490 -0
  118. package/dist/kernel/cli/index.d.mts +141 -0
  119. package/dist/kernel/cli/index.mjs +1 -0
  120. package/dist/kernel/cli/schemas.d.mts +63 -0
  121. package/dist/kernel/cli/schemas.mjs +1 -0
  122. package/dist/kernel/extension/index.d.mts +2 -0
  123. package/dist/kernel/extension/index.mjs +1 -0
  124. package/dist/kernel/index.d.mts +296 -0
  125. package/dist/kernel/index.mjs +1 -0
  126. package/dist/kernel/namespace/index.d.mts +2 -0
  127. package/dist/kernel/namespace/index.mjs +1 -0
  128. package/dist/kernel/observability/index.d.mts +2 -0
  129. package/dist/kernel/observability/index.mjs +1 -0
  130. package/dist/kernel/providers/index.d.mts +2 -0
  131. package/dist/kernel/providers/index.mjs +1 -0
  132. package/dist/kernel/window/index.d.mts +2 -0
  133. package/dist/kernel/window/index.mjs +1 -0
  134. package/dist/model-registry-BNzpR6TU.mjs +1 -0
  135. package/dist/model-registry-CIscwC52.mjs +1 -0
  136. package/dist/namespace-0yuzAKlr.mjs +1 -0
  137. package/dist/namespace-8cNguvIp.mjs +1 -0
  138. package/dist/namespace-BK2erxpV.d.mts +921 -0
  139. package/dist/namespace-Bmc7AW4J2.mjs +1 -0
  140. package/dist/namespace-C2ufjgaQ.d.mts +767 -0
  141. package/dist/namespace-C54Oj025.d.mts +159 -0
  142. package/dist/namespace-CCDEOwmW.d.mts +1313 -0
  143. package/dist/namespace-CfEWMXBx.mjs +1 -0
  144. package/dist/namespace-CkLUtc0g.d.mts +580 -0
  145. package/dist/namespace-D5Wrt7YU.mjs +1 -0
  146. package/dist/namespace-DZcuLwEA.d.mts +51 -0
  147. package/dist/namespace-Db-p67Rg.mjs +1 -0
  148. package/dist/namespace-FWx6HxaW.d.mts +611 -0
  149. package/dist/namespace-GLGGcWPH.d.mts +43 -0
  150. package/dist/namespace-N0dfwSg6.mjs +1 -0
  151. package/dist/namespace-O5SNY-LV.d.mts +2226 -0
  152. package/dist/namespace-ZbthBQVt.d.mts +142 -0
  153. package/dist/namespace-bq4Prtzn.d.mts +2046 -0
  154. package/dist/namespace-pNcSglBS.mjs +1 -0
  155. package/dist/namespace-ptv-pw_g.d.mts +3019 -0
  156. package/dist/namespace-xkvVw3hf2.d.mts +189 -0
  157. package/dist/native-session-supervisor-L-UIaEfd.mjs +1 -0
  158. package/dist/node/bus-server/index.d.mts +178 -0
  159. package/dist/node/bus-server/index.mjs +1 -0
  160. package/dist/node/bus-server/server-lifecycle.d.mts +2 -0
  161. package/dist/node/bus-server/server-lifecycle.mjs +1 -0
  162. package/dist/node/machine-identity/index.d.mts +85 -0
  163. package/dist/node/machine-identity/index.mjs +3 -0
  164. package/dist/node/transports/index.d.mts +1752 -0
  165. package/dist/node/transports/index.mjs +2 -0
  166. package/dist/orchestrator-shared-DrjtTXYh.d.mts +249 -0
  167. package/dist/orchestrator-shared-Wv1GI2mW.mjs +1 -0
  168. package/dist/platform-BbSLVg5b.mjs +1 -0
  169. package/dist/profile-4StaDQW0.mjs +1 -0
  170. package/dist/provider-context-CNRQ4d5m.mjs +1 -0
  171. package/dist/providers/index.d.mts +135 -0
  172. package/dist/providers/index.mjs +1 -0
  173. package/dist/providers-Cr4Za8a1.mjs +1 -0
  174. package/dist/providers-namespace-CDwxY_DV.d.mts +583 -0
  175. package/dist/schema-BwzXEtT2.d.mts +837 -0
  176. package/dist/schema-CAw_BqaG.mjs +1 -0
  177. package/dist/schema-introspection-D61TT_7b.mjs +1 -0
  178. package/dist/schema-uSGW-6oM.mjs +1 -0
  179. package/dist/schemas-BXstpWVp.mjs +1 -0
  180. package/dist/schemas-BdMU-gew.d.mts +160 -0
  181. package/dist/schemas-C40ZAJ33.mjs +1 -0
  182. package/dist/schemas-C5xtVqdb.d.mts +46 -0
  183. package/dist/schemas-CGZy_rU6.d.mts +13 -0
  184. package/dist/schemas-CLxtoKFy.mjs +1 -0
  185. package/dist/schemas-Co_sVhzz.mjs +1 -0
  186. package/dist/schemas-D9108Iv1.d.mts +182 -0
  187. package/dist/schemas-DENVYyds.d.mts +463 -0
  188. package/dist/schemas-DbWs_hj8.d.mts +174 -0
  189. package/dist/schemas-Di0XnnMX.d.mts +73 -0
  190. package/dist/schemas-KMA1efQg.d.mts +944 -0
  191. package/dist/schemas-qmn5SWPU.d.mts +312 -0
  192. package/dist/schemas-sshQEF3l.d.mts +237 -0
  193. package/dist/server-lifecycle-Cf_SZ27k.d.mts +160 -0
  194. package/dist/server-lifecycle-DbFwlrTW.mjs +1 -0
  195. package/dist/service-base/index.d.mts +98 -0
  196. package/dist/service-base/index.mjs +1 -0
  197. package/dist/services/adapter-runtime/index.d.mts +4 -0
  198. package/dist/services/adapter-runtime/index.mjs +1 -0
  199. package/dist/services/adapter-runtime/namespace.d.mts +2 -0
  200. package/dist/services/adapter-runtime/namespace.mjs +1 -0
  201. package/dist/services/adapter-runtime/schemas.d.mts +2 -0
  202. package/dist/services/adapter-runtime/schemas.mjs +1 -0
  203. package/dist/services/adapter-subsystem/index.d.mts +3 -0
  204. package/dist/services/adapter-subsystem/index.mjs +1 -0
  205. package/dist/services/adapter-subsystem/namespace.d.mts +2 -0
  206. package/dist/services/adapter-subsystem/namespace.mjs +1 -0
  207. package/dist/services/agent-runtime/index.d.mts +3 -0
  208. package/dist/services/agent-runtime/index.mjs +1 -0
  209. package/dist/services/agent-runtime/namespace.d.mts +2 -0
  210. package/dist/services/agent-runtime/namespace.mjs +1 -0
  211. package/dist/services/agent-runtime/schemas.d.mts +2 -0
  212. package/dist/services/agent-runtime/schemas.mjs +1 -0
  213. package/dist/services/capability/index.d.mts +2 -0
  214. package/dist/services/capability/index.mjs +1 -0
  215. package/dist/services/cli-detection/namespace.d.mts +56 -0
  216. package/dist/services/cli-detection/namespace.mjs +1 -0
  217. package/dist/services/codebase/index.d.mts +3 -0
  218. package/dist/services/codebase/index.mjs +1 -0
  219. package/dist/services/codebase/namespace.d.mts +2 -0
  220. package/dist/services/codebase/namespace.mjs +1 -0
  221. package/dist/services/codebase/schemas.d.mts +2 -0
  222. package/dist/services/codebase/schemas.mjs +1 -0
  223. package/dist/services/compression/index.d.mts +3 -0
  224. package/dist/services/compression/index.mjs +1 -0
  225. package/dist/services/compression/namespace.d.mts +2 -0
  226. package/dist/services/compression/namespace.mjs +1 -0
  227. package/dist/services/compression/schemas.d.mts +2 -0
  228. package/dist/services/compression/schemas.mjs +1 -0
  229. package/dist/services/context-rules/index.d.mts +412 -0
  230. package/dist/services/context-rules/index.mjs +1 -0
  231. package/dist/services/credential-change/index.d.mts +17 -0
  232. package/dist/services/credential-change/index.mjs +1 -0
  233. package/dist/services/definition/index.d.mts +2 -0
  234. package/dist/services/definition/index.mjs +1 -0
  235. package/dist/services/definition/namespace.d.mts +71 -0
  236. package/dist/services/definition/namespace.mjs +1 -0
  237. package/dist/services/definition/schemas.d.mts +38 -0
  238. package/dist/services/definition/schemas.mjs +1 -0
  239. package/dist/services/dialog/namespace.d.mts +105 -0
  240. package/dist/services/dialog/namespace.mjs +1 -0
  241. package/dist/services/dialog/schemas.d.mts +109 -0
  242. package/dist/services/dialog/schemas.mjs +1 -0
  243. package/dist/services/execution-target/index.d.mts +4 -0
  244. package/dist/services/execution-target/index.mjs +1 -0
  245. package/dist/services/execution-target/namespace.d.mts +2 -0
  246. package/dist/services/execution-target/namespace.mjs +1 -0
  247. package/dist/services/execution-target/schemas.d.mts +2 -0
  248. package/dist/services/execution-target/schemas.mjs +1 -0
  249. package/dist/services/filesystem/namespace.d.mts +432 -0
  250. package/dist/services/filesystem/namespace.mjs +1 -0
  251. package/dist/services/filesystem/schemas.d.mts +240 -0
  252. package/dist/services/filesystem/schemas.mjs +1 -0
  253. package/dist/services/harness/index.d.mts +861 -0
  254. package/dist/services/harness/index.mjs +1 -0
  255. package/dist/services/harness/storage/schema.d.mts +424 -0
  256. package/dist/services/harness/storage/schema.mjs +1 -0
  257. package/dist/services/index.d.mts +5703 -0
  258. package/dist/services/index.mjs +1 -0
  259. package/dist/services/local-notification/index.d.mts +25 -0
  260. package/dist/services/local-notification/index.mjs +1 -0
  261. package/dist/services/local-notification/namespace.d.mts +73 -0
  262. package/dist/services/local-notification/namespace.mjs +1 -0
  263. package/dist/services/local-notification/schemas.d.mts +88 -0
  264. package/dist/services/local-notification/schemas.mjs +1 -0
  265. package/dist/services/log-import/browser.d.mts +3 -0
  266. package/dist/services/log-import/browser.mjs +1 -0
  267. package/dist/services/log-import/index.d.mts +275 -0
  268. package/dist/services/log-import/index.mjs +2 -0
  269. package/dist/services/log-import/log-import.d.mts +3 -0
  270. package/dist/services/log-import/log-import.mjs +1 -0
  271. package/dist/services/log-import/namespace.d.mts +327 -0
  272. package/dist/services/log-import/namespace.mjs +1 -0
  273. package/dist/services/log-import/schemas.d.mts +217 -0
  274. package/dist/services/log-import/schemas.mjs +1 -0
  275. package/dist/services/model-registry/index.d.mts +2 -0
  276. package/dist/services/model-registry/index.mjs +1 -0
  277. package/dist/services/preferences/index.d.mts +3 -0
  278. package/dist/services/preferences/index.mjs +1 -0
  279. package/dist/services/preferences/schemas.d.mts +2 -0
  280. package/dist/services/preferences/schemas.mjs +1 -0
  281. package/dist/services/preferences/storage-namespace.d.mts +3 -0
  282. package/dist/services/preferences/storage-namespace.mjs +1 -0
  283. package/dist/services/provider-context/index.d.mts +2 -0
  284. package/dist/services/provider-context/index.mjs +1 -0
  285. package/dist/services/provider-runtime/index.d.mts +136 -0
  286. package/dist/services/provider-runtime/index.mjs +1 -0
  287. package/dist/services/session/handlers/index.d.mts +2 -0
  288. package/dist/services/session/handlers/index.mjs +1 -0
  289. package/dist/services/session/index.d.mts +10 -0
  290. package/dist/services/session/index.mjs +1 -0
  291. package/dist/services/session/messages/namespace.d.mts +2 -0
  292. package/dist/services/session/messages/namespace.mjs +1 -0
  293. package/dist/services/session/orchestrator-testing/index.d.mts +2 -0
  294. package/dist/services/session/orchestrator-testing/index.mjs +1 -0
  295. package/dist/services/session/session-events/namespace.d.mts +2 -0
  296. package/dist/services/session/session-events/namespace.mjs +1 -0
  297. package/dist/services/session/storage/namespace.d.mts +2 -0
  298. package/dist/services/session/storage/namespace.mjs +1 -0
  299. package/dist/services/session/storage/schema.d.mts +2 -0
  300. package/dist/services/session/storage/schema.mjs +1 -0
  301. package/dist/services/session/testing/index.d.mts +35 -0
  302. package/dist/services/session/testing/index.mjs +52 -0
  303. package/dist/services/session/testing/orchestrator-shared.d.mts +2 -0
  304. package/dist/services/session/testing/orchestrator-shared.mjs +1 -0
  305. package/dist/services/session/turns/namespace.d.mts +2 -0
  306. package/dist/services/session/turns/namespace.mjs +1 -0
  307. package/dist/services/session-editor/index.d.mts +119 -0
  308. package/dist/services/session-editor/index.mjs +1 -0
  309. package/dist/services/settings/index.d.mts +47 -0
  310. package/dist/services/settings/index.mjs +1 -0
  311. package/dist/services/settings/namespace.d.mts +662 -0
  312. package/dist/services/settings/namespace.mjs +1 -0
  313. package/dist/services/settings/storage/clients-namespace.d.mts +2 -0
  314. package/dist/services/settings/storage/clients-namespace.mjs +1 -0
  315. package/dist/services/settings/storage/extension-configs/namespace.d.mts +184 -0
  316. package/dist/services/settings/storage/extension-configs/namespace.mjs +1 -0
  317. package/dist/services/settings/storage/index.d.mts +4 -0
  318. package/dist/services/settings/storage/index.mjs +1 -0
  319. package/dist/services/settings/storage/providers-namespace.d.mts +2 -0
  320. package/dist/services/settings/storage/providers-namespace.mjs +1 -0
  321. package/dist/services/tool-approval/index.d.mts +2 -0
  322. package/dist/services/tool-approval/index.mjs +1 -0
  323. package/dist/services/tools/index.d.mts +2 -0
  324. package/dist/services/tools/index.mjs +1 -0
  325. package/dist/services/tray-menu/index.d.mts +4 -0
  326. package/dist/services/tray-menu/index.mjs +1 -0
  327. package/dist/services/tray-menu/namespace.d.mts +2 -0
  328. package/dist/services/tray-menu/namespace.mjs +1 -0
  329. package/dist/services/tray-menu/schemas.d.mts +2 -0
  330. package/dist/services/tray-menu/schemas.mjs +1 -0
  331. package/dist/services/turn/index.d.mts +2 -0
  332. package/dist/services/turn/index.mjs +1 -0
  333. package/dist/services/turn/namespace.d.mts +2 -0
  334. package/dist/services/turn/namespace.mjs +1 -0
  335. package/dist/services/turn/schemas.d.mts +335 -0
  336. package/dist/services/turn/schemas.mjs +1 -0
  337. package/dist/services/worker/index.d.mts +3 -0
  338. package/dist/services/worker/index.mjs +1 -0
  339. package/dist/services/worker/namespace.d.mts +2 -0
  340. package/dist/services/worker/namespace.mjs +1 -0
  341. package/dist/services/worker/schemas.d.mts +2 -0
  342. package/dist/services/worker/schemas.mjs +1 -0
  343. package/dist/session-Do6lDZM4.mjs +123 -0
  344. package/dist/session-lineage-Eev4uo4I.d.mts +65 -0
  345. package/dist/session-piI1R5rP.mjs +1 -0
  346. package/dist/shared-DxHLl9UP.mjs +1 -0
  347. package/dist/shared-schemas-BgQv_tnu.mjs +1 -0
  348. package/dist/skill-CB5h-ZFQ.mjs +1 -0
  349. package/dist/storage/drizzle/client.d.mts +78 -0
  350. package/dist/storage/drizzle/client.mjs +1 -0
  351. package/dist/storage/drizzle/index.d.mts +98 -0
  352. package/dist/storage/drizzle/index.mjs +1 -0
  353. package/dist/storage/handlers/drizzle/index.d.mts +2 -0
  354. package/dist/storage/handlers/drizzle/index.mjs +1 -0
  355. package/dist/storage/handlers/index.d.mts +33 -0
  356. package/dist/storage/handlers/index.mjs +1 -0
  357. package/dist/storage/index.d.mts +192 -0
  358. package/dist/storage/index.mjs +1 -0
  359. package/dist/storage-namespace-ADwyijoe.mjs +1 -0
  360. package/dist/storage-namespace-DAm8iWEj.d.mts +221 -0
  361. package/dist/storage-namespace-definition-CHu2k14q.mjs +1 -0
  362. package/dist/storage-namespace-definition-CJgqyXH1.d.mts +17 -0
  363. package/dist/style.css +3782 -0
  364. package/dist/testing/drizzle-harness.d.mts +130 -0
  365. package/dist/testing/drizzle-harness.mjs +1 -0
  366. package/dist/testing/index.d.mts +106 -0
  367. package/dist/testing/index.mjs +1 -0
  368. package/dist/tool-approval-service-BcBSUZCO.mjs +1 -0
  369. package/dist/tools/index.d.mts +825 -0
  370. package/dist/tools/index.mjs +1 -0
  371. package/dist/tools/testing/index.d.mts +53 -0
  372. package/dist/tools/testing/index.mjs +1 -0
  373. package/dist/tools-CDSgj0ee.mjs +1 -0
  374. package/dist/tray-menu-service-CTXC1Elg.mjs +1 -0
  375. package/dist/types-6WxLfoM3.d.mts +31 -0
  376. package/dist/types-BjToUrHp.d.mts +6619 -0
  377. package/dist/types-CD1LJwPc.d.mts +1009 -0
  378. package/dist/types-Cvrj2ogm.d.mts +305 -0
  379. package/dist/types-DYF5LxZY.d.mts +233 -0
  380. package/dist/types-t295YC6T.d.mts +262 -0
  381. package/dist/types-vNpkAe4Y.d.mts +128 -0
  382. package/dist/ui-components/index.d.mts +2342 -0
  383. package/dist/ui-components/index.mjs +8 -0
  384. package/dist/ui-config-CXmbsqZV.mjs +1 -0
  385. package/dist/ui-hooks/index.d.mts +1805 -0
  386. package/dist/ui-hooks/index.mjs +1 -0
  387. package/dist/ui-kernel/index.d.mts +2793 -0
  388. package/dist/ui-kernel/index.mjs +1 -0
  389. package/dist/ui-kernel/pages/namespace.d.mts +88 -0
  390. package/dist/ui-kernel/pages/namespace.mjs +1 -0
  391. package/dist/ui-kernel/pages/schemas.d.mts +2 -0
  392. package/dist/ui-kernel/pages/schemas.mjs +1 -0
  393. package/dist/ui-views/index.d.mts +487 -0
  394. package/dist/ui-views/index.mjs +30 -0
  395. package/dist/utils/health-probe.d.mts +26 -0
  396. package/dist/utils/health-probe.mjs +1 -0
  397. package/dist/utils/index.d.mts +227 -0
  398. package/dist/utils/index.mjs +2 -0
  399. package/dist/utils/keychain.d.mts +31 -0
  400. package/dist/utils/keychain.mjs +1 -0
  401. package/dist/utils/resolve-package-root.d.mts +12 -0
  402. package/dist/utils/resolve-package-root.mjs +1 -0
  403. package/dist/utils/workspace-root.d.mts +27 -0
  404. package/dist/utils/workspace-root.mjs +2 -0
  405. package/dist/variant-D5kSrL3m.mjs +1 -0
  406. package/dist/version-CjS20oXi.mjs +1 -0
  407. package/dist/visibility-CZu8ooOA.mjs +1 -0
  408. package/dist/window-registry-CUftmDr3.mjs +1 -0
  409. package/dist/window-registry-C_IJmY8_.d.mts +130 -0
  410. package/package.json +346 -0
@@ -0,0 +1,1384 @@
1
+ import { z } from "zod";
2
+ import { EventMessagePayload, ScopedSubjectDefinition } from "@makaio/framework/core";
3
+ import { ScopedBus } from "@makaio/framework/bus";
4
+ import { AgentToolApproveRequest, AgentToolApproveResponse, McpSessionContext, SessionMessageBlock, ToolExecuteResult, ToolExecutionContextOverrides, ToolListItem } from "@makaio/framework/contracts";
5
+ import { AIAgent, AIAgentConnector, AIReasoningLevel as AIReasoningLevel$1, AgentCompleteEvent, AgentCompleteEventSchema, AgentStartedEvent, AgentStartedEvent as AgentStartedEvent$1, AgentStartedEventSchema, BaseAgentConnectorConfig, BaseConnectorSession, ConnectorSendMessageOptions, ErrorEvent, ErrorEvent as ErrorEvent$1, ErrorEventSchema, LedgerSessionContext, MessageHandle, MessageResult, NormalizedCallUsage, NormalizedMessageInput, ProceduralAgentConnector, ProceduralConnectorSession, ProceduralConnectorTurn, ToolApprovalContext, ToolCompletedEvent, ToolCompletedEvent as ToolCompletedEvent$1, ToolCompletedEventSchema, ToolStartedEvent, ToolStartedEvent as ToolStartedEvent$1, ToolStartedEventSchema, UserMessageQueue, WireSessionConfig, WireSessionSubjects } from "@makaio/framework/adapters";
6
+
7
+ //#region adapters/shared/stream-session/src/tool-handling/tool-result.d.ts
8
+ /**
9
+ * Shared tool result types and content bounding utility.
10
+ *
11
+ * These types and functions are identical across all stream-based adapter
12
+ * implementations and are extracted here to avoid duplication.
13
+ */
14
+ /**
15
+ * Tool-specific fields extracted from a normalized tool call.
16
+ *
17
+ * Identity context (agentId, adapterId, etc.) is intentionally excluded —
18
+ * the connector injects those when forwarding to the global bus.
19
+ */
20
+ interface ToolCallPayload {
21
+ /** Name of the tool to call */
22
+ toolName: string;
23
+ /** Parsed arguments for the tool */
24
+ args: Record<string, unknown>;
25
+ /** Unique identifier for this tool call */
26
+ toolCallId: string;
27
+ }
28
+ declare const MAX_TOOL_RESULT_CONTENT_CHARS = 8000;
29
+ /**
30
+ * Bound tool result content before injecting it back into model context.
31
+ *
32
+ * Tool outputs (filesystem, grep, etc.) can be very large and cause
33
+ * context-window overflows in recursive tool-call turns. Keep full payload
34
+ * on emitted events, but cap what is sent back to the model.
35
+ * @param content - Serialized tool result payload
36
+ * @returns Content truncated to context-safe size
37
+ */
38
+ declare function boundToolResultContent(content: string): string;
39
+ //#endregion
40
+ //#region adapters/shared/stream-session/src/namespaces/schemas/tool-calls.d.ts
41
+ /**
42
+ * Public contract for a single tool-call function payload.
43
+ *
44
+ * Matches both the Anthropic ToolUseBlock.input structure and the
45
+ * OpenAI ChatCompletionMessageToolCall.Function structure.
46
+ */
47
+ interface ToolCallFunction {
48
+ /** Name of the function to call. */
49
+ name: string;
50
+ /** JSON-encoded arguments for the function. */
51
+ arguments: string;
52
+ }
53
+ /**
54
+ * Public contract for a single tool call.
55
+ *
56
+ * Contains only the fields common to both Anthropic and OpenAI adapters.
57
+ * The Anthropic adapter extends this with `blockIndex`.
58
+ */
59
+ interface ToolCall {
60
+ /** Unique identifier for this tool call. */
61
+ id: string;
62
+ /** Type of tool (always 'function' for now). */
63
+ type: 'function';
64
+ /** Function call details. */
65
+ function: ToolCallFunction;
66
+ }
67
+ /**
68
+ * Public contract for a tool-calls event.
69
+ *
70
+ * Emitted when the model requests tool / function execution.
71
+ */
72
+ interface ToolCallsEvent {
73
+ /** Discriminator for tool call events. */
74
+ eventType: 'tool_calls';
75
+ /** Array of requested tool calls. */
76
+ toolCalls: ToolCall[];
77
+ }
78
+ /**
79
+ * Schema for a single tool call function.
80
+ *
81
+ * Matches both the Anthropic ToolUseBlock.input structure and the
82
+ * OpenAI ChatCompletionMessageToolCall.Function structure.
83
+ */
84
+ declare const ToolCallFunctionSchema: z.ZodObject<{
85
+ name: z.ZodString;
86
+ arguments: z.ZodString;
87
+ }, z.core.$strip>;
88
+ /**
89
+ * Schema for a single tool call.
90
+ *
91
+ * Contains only the fields common to both Anthropic and OpenAI adapters.
92
+ * The Anthropic adapter extends this with `blockIndex` via `.extend()`.
93
+ *
94
+ * Adapter-specific schemas may extend this via `.extend()`.
95
+ */
96
+ declare const ToolCallSchema: z.ZodObject<{
97
+ id: z.ZodString;
98
+ type: z.ZodLiteral<"function">;
99
+ function: z.ZodObject<{
100
+ name: z.ZodString;
101
+ arguments: z.ZodString;
102
+ }, z.core.$strip>;
103
+ }, z.core.$strip>;
104
+ /**
105
+ * Schema for a tool calls event.
106
+ *
107
+ * Emitted when the model requests tool / function execution.
108
+ * Both adapters emit this event with the same structure, except the
109
+ * Anthropic adapter's individual `ToolCall` entries also carry `blockIndex`.
110
+ */
111
+ declare const ToolCallsEventSchema: z.ZodObject<{
112
+ eventType: z.ZodLiteral<"tool_calls">;
113
+ toolCalls: z.ZodArray<z.ZodObject<{
114
+ id: z.ZodString;
115
+ type: z.ZodLiteral<"function">;
116
+ function: z.ZodObject<{
117
+ name: z.ZodString;
118
+ arguments: z.ZodString;
119
+ }, z.core.$strip>;
120
+ }, z.core.$strip>>;
121
+ }, z.core.$strip>;
122
+ //#endregion
123
+ //#region adapters/shared/stream-session/src/tool-handling/tool-approval.d.ts
124
+ /**
125
+ * Extract tool-specific fields from a normalized tool call.
126
+ *
127
+ * The `function.arguments` field is a JSON string assembled from streaming
128
+ * delta fragments. This function parses it to recover the structured args.
129
+ * @param toolCall - Normalized tool call from the stream-bridge tool_calls event
130
+ * @param adapterLabel - Short label used in error logs (e.g. 'AnthropicSdkAgent'). Defaults to 'Adapter'.
131
+ * @returns Tool-specific payload without identity context
132
+ */
133
+ declare function extractToolCallPayload(toolCall: ToolCall, adapterLabel?: string): ToolCallPayload;
134
+ /**
135
+ * Transform a normalized tool call into an AgentToolApproveRequest.
136
+ *
137
+ * Combines the extracted tool payload with full adapter identity context.
138
+ * @param toolCall - Normalized tool call from the stream-bridge tool_calls event
139
+ * @param context - Adapter context providing identity fields
140
+ * @param adapterLabel - Short label used in error logs (e.g. 'AnthropicSdkAgent'). Defaults to 'Adapter'.
141
+ * @returns Global tool approval request ready for AgentSubjects.toolApprove
142
+ */
143
+ declare function toGlobalToolApproval(toolCall: ToolCall, context: ToolApprovalContext, adapterLabel?: string): AgentToolApproveRequest;
144
+ /**
145
+ * Apply approved argument overrides directly to the tool call payload.
146
+ *
147
+ * Approval handlers can transform tool input via `updatedInput`. When present,
148
+ * the modified args must replace the original JSON string before execution.
149
+ * @param toolCall - Tool call object to update in place
150
+ * @param approval - Allow-branch approval response from AgentSubjects.toolApprove
151
+ */
152
+ declare function applyApprovedArgs(toolCall: ToolCall, approval: Extract<AgentToolApproveResponse, {
153
+ action: 'allow';
154
+ }>): void;
155
+ //#endregion
156
+ //#region adapters/shared/stream-session/src/tool-handling/tool-registry.d.ts
157
+ /**
158
+ * Load tools from ToolRegistry via MakaioBus.
159
+ *
160
+ * Fetches available tools from the central ToolRegistry.
161
+ * Returns raw ToolListItem[] for maximum flexibility so each adapter can
162
+ * convert to its own SDK-specific format.
163
+ *
164
+ * Does not throw on failure — an agent can still operate without tools,
165
+ * so errors are logged and an empty array is returned.
166
+ * @param adapterId - Adapter instance ID for logging/routing
167
+ * @param adapterName - Adapter type name
168
+ * @returns List of available tools, or empty array if fetch fails
169
+ */
170
+ declare function loadToolsFromRegistry(adapterId: string, adapterName: string): Promise<ToolListItem[]>;
171
+ /**
172
+ * Filter tools to only those with an inputSchema defined.
173
+ *
174
+ * Most LLM SDKs require a JSON Schema for function calling parameters.
175
+ * Tools without inputSchema cannot be used with native function calling.
176
+ * @param tools - Tools from the registry
177
+ * @returns Tools that have a defined inputSchema
178
+ */
179
+ declare function filterToolsWithSchema(tools: ToolListItem[]): (ToolListItem & {
180
+ inputSchema: Record<string, unknown>;
181
+ })[];
182
+ //#endregion
183
+ //#region adapters/shared/stream-session/src/tool-handling/tool-execution.d.ts
184
+ /**
185
+ * Minimal SDK event emitter interface for tool lifecycle events.
186
+ *
187
+ * Both adapter SdkEventMessage discriminated unions include ToolStartedEvent
188
+ * and ToolCompletedEvent. Using a structural union here avoids the shared
189
+ * package depending on adapter-specific namespaces.
190
+ */
191
+ type ToolLifecycleEmitter = (event: ToolStartedEvent$1 | ToolCompletedEvent$1) => Promise<void>;
192
+ /**
193
+ * Execute a tool via Bus RPC.
194
+ *
195
+ * Routes tool execution through the ToolRegistry via MakaioBus.
196
+ * Emits tool_started before execution and tool_completed after (on both
197
+ * success and failure paths). On bus error the error is re-thrown after
198
+ * the tool_completed failure event is emitted.
199
+ * @param toolCall - The normalized tool call to execute
200
+ * @param emitSdkEvent - Callback to emit SDK lifecycle events
201
+ * @param contextOverrides - Execution context (cwd, env, sessionId, agentId, turnId)
202
+ * @returns Tool execution result
203
+ */
204
+ declare function executeTool(toolCall: ToolCall, emitSdkEvent: ToolLifecycleEmitter, contextOverrides: ToolExecutionContextOverrides): Promise<ToolExecuteResult>;
205
+ //#endregion
206
+ //#region adapters/shared/stream-session/src/tool-handling/handle-tool-calls.d.ts
207
+ /**
208
+ * Callbacks needed by {@link handleToolCalls}. Adapter-agnostic.
209
+ */
210
+ type HandleToolCallsCallbacks = {
211
+ /** Emit SDK lifecycle events (tool_started, tool_completed). */emitSdkEvent: ToolLifecycleEmitter;
212
+ /**
213
+ * Request tool approval via the scoped bus routed to the global bus.
214
+ * @param payload - Tool call payload enriched with optional reasoning
215
+ * @returns Global approval response
216
+ */
217
+ requestToolApproval: (payload: ToolCallPayload & {
218
+ reasoning?: string;
219
+ }) => Promise<AgentToolApproveResponse>;
220
+ /**
221
+ * Record an mcp_call invocation in the session tool ledger.
222
+ *
223
+ * Optional. When present, called after each successful mcp_call execution
224
+ * with the resolved target tool name. The connector binds this callback to
225
+ * its ledger and captures the current turn number in the closure, so it
226
+ * always reflects the turn in progress when the call is recorded.
227
+ * @param toolFullName - Namespaced target tool name extracted from mcp_call args
228
+ */
229
+ recordMcpCall?: (toolFullName: string) => void;
230
+ };
231
+ /**
232
+ * Adapter-specific result formatter for tool call outcomes.
233
+ * @param toolCallId - The tool call ID for correlation
234
+ * @param content - Serialized result content (already bounded)
235
+ * @param isError - Whether the result represents an error
236
+ * @returns SDK-specific result value
237
+ */
238
+ type ToolResultBuilder<TResult> = (toolCallId: string, content: string, isError: boolean) => TResult;
239
+ /**
240
+ * Process tool calls from a model response: approve, execute, and format results.
241
+ *
242
+ * Shared orchestration across all stream-based adapters. Each adapter provides
243
+ * a `buildResult` factory to format results in its SDK-specific type.
244
+ *
245
+ * **Mutation:** When approval modifies tool arguments, entries in `toolCalls`
246
+ * are mutated in place via {@link applyApprovedArgs}.
247
+ * @param toolCalls - Tool calls from the model (entries may be mutated when approval modifies args)
248
+ * @param callbacks - Approval and lifecycle event callbacks
249
+ * @param contextOverrides - Execution context (session, agent, turn)
250
+ * @param buildResult - Adapter-specific result formatter
251
+ * @param adapterLabel - Adapter name for logging
252
+ * @returns Formatted tool results for injection back into the conversation
253
+ */
254
+ declare function handleToolCalls<TResult>(toolCalls: ToolCall[], callbacks: HandleToolCallsCallbacks, contextOverrides: ToolExecutionContextOverrides, buildResult: ToolResultBuilder<TResult>, adapterLabel: string): Promise<TResult[]>;
255
+ //#endregion
256
+ //#region adapters/shared/stream-session/src/namespaces/schemas/turn-state.d.ts
257
+ /**
258
+ * Public turn-state contract for stream-session adapters.
259
+ *
260
+ * Both Anthropic SDK and OpenAI Node adapters share these states.
261
+ * Neither uses a 'paused' state — they abort and restart instead.
262
+ */
263
+ type StreamSessionTurnState = 'idle' | 'turn_started' | 'step_started' | 'step_finished' | 'turn_finished';
264
+ /**
265
+ * Public payload contract for turn-state transitions.
266
+ */
267
+ interface TurnStateChanged {
268
+ /** The adapter instance identifier. */
269
+ adapterId: string;
270
+ /** The agent this turn belongs to. */
271
+ agentId: string;
272
+ /** The state being left. */
273
+ oldState: StreamSessionTurnState;
274
+ /** The state being entered. */
275
+ newState: StreamSessionTurnState;
276
+ /** Unix timestamp (ms) when the transition occurred. */
277
+ timestamp: number;
278
+ }
279
+ /**
280
+ * Shared turn state schema for stream-session adapters.
281
+ */
282
+ declare const StreamSessionTurnStateSchema: z.ZodEnum<{
283
+ idle: "idle";
284
+ turn_started: "turn_started";
285
+ step_started: "step_started";
286
+ step_finished: "step_finished";
287
+ turn_finished: "turn_finished";
288
+ }>;
289
+ /**
290
+ * Schema for a turn state change event.
291
+ * Emitted by adapters whenever the turn state machine transitions.
292
+ * @param adapterId - The adapter instance identifier.
293
+ * @param agentId - The agent this turn belongs to.
294
+ * @param oldState - The state being left.
295
+ * @param newState - The state being entered.
296
+ * @param timestamp - Unix timestamp (ms) when the transition occurred.
297
+ */
298
+ declare const TurnStateChangedSchema: z.ZodObject<{
299
+ adapterId: z.ZodString;
300
+ agentId: z.ZodString;
301
+ oldState: z.ZodEnum<{
302
+ idle: "idle";
303
+ turn_started: "turn_started";
304
+ step_started: "step_started";
305
+ step_finished: "step_finished";
306
+ turn_finished: "turn_finished";
307
+ }>;
308
+ newState: z.ZodEnum<{
309
+ idle: "idle";
310
+ turn_started: "turn_started";
311
+ step_started: "step_started";
312
+ step_finished: "step_finished";
313
+ turn_finished: "turn_finished";
314
+ }>;
315
+ timestamp: z.ZodNumber;
316
+ }, z.core.$strip>;
317
+ //#endregion
318
+ //#region adapters/shared/stream-session/src/namespaces/schemas/reasoning.d.ts
319
+ /**
320
+ * Base schema for a reasoning delta event.
321
+ *
322
+ * Emitted during streaming when the model outputs incremental reasoning /
323
+ * thinking content. Both Anthropic (extended thinking) and OpenAI-compatible
324
+ * reasoning models emit this event.
325
+ *
326
+ * Adapter-specific schemas may extend this via `.extend()`.
327
+ */
328
+ declare const ReasoningDeltaEventSchema: z.ZodObject<{
329
+ eventType: z.ZodLiteral<"reasoning_delta">;
330
+ content: z.ZodString;
331
+ }, z.core.$strip>;
332
+ /** Inferred reasoning delta event type. */
333
+ type ReasoningDeltaEvent = z.infer<typeof ReasoningDeltaEventSchema>;
334
+ /**
335
+ * Base schema for a reasoning complete event.
336
+ *
337
+ * Emitted when the full reasoning / thinking content has been assembled from
338
+ * all streaming deltas. Does NOT include the Anthropic-specific `signature`
339
+ * field — the Anthropic adapter extends this schema with `.extend()`.
340
+ *
341
+ * Adapter-specific schemas may extend this via `.extend()`.
342
+ */
343
+ declare const ReasoningCompleteEventSchema: z.ZodObject<{
344
+ eventType: z.ZodLiteral<"reasoning_complete">;
345
+ content: z.ZodString;
346
+ }, z.core.$strip>;
347
+ /** Inferred reasoning complete event type. */
348
+ type ReasoningCompleteEvent = z.infer<typeof ReasoningCompleteEventSchema>;
349
+ //#endregion
350
+ //#region adapters/shared/stream-session/src/namespaces/schemas/message.d.ts
351
+ /**
352
+ * Base schema for a tool call embedded in a message complete event.
353
+ *
354
+ * Contains only the fields common to both Anthropic and OpenAI adapters.
355
+ * The Anthropic adapter's version additionally carries `blockIndex`.
356
+ */
357
+ declare const MessageToolCallSchema: z.ZodObject<{
358
+ id: z.ZodString;
359
+ type: z.ZodLiteral<"function">;
360
+ function: z.ZodObject<{
361
+ name: z.ZodString;
362
+ arguments: z.ZodString;
363
+ }, z.core.$strip>;
364
+ }, z.core.$strip>;
365
+ /** Inferred base message tool call type. */
366
+ type MessageToolCall = z.infer<typeof MessageToolCallSchema>;
367
+ /**
368
+ * Base schema for a message complete event.
369
+ *
370
+ * Emitted when a full assistant message has been assembled from streaming
371
+ * chunks. The `finish_reason` and `tool_calls` fields are left open for
372
+ * each adapter to specialise via `.extend()`, since the allowed values
373
+ * differ between providers.
374
+ *
375
+ * Adapter-specific schemas MUST extend this schema and narrow:
376
+ * - `finish_reason` to their provider-specific enum
377
+ * - `tool_calls` to their adapter-specific tool-call schema (if needed)
378
+ */
379
+ declare const MessageCompleteEventSchema: z.ZodObject<{
380
+ eventType: z.ZodLiteral<"message_complete">;
381
+ content: z.ZodNullable<z.ZodString>;
382
+ reasoning: z.ZodOptional<z.ZodString>;
383
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
384
+ id: z.ZodString;
385
+ type: z.ZodLiteral<"function">;
386
+ function: z.ZodObject<{
387
+ name: z.ZodString;
388
+ arguments: z.ZodString;
389
+ }, z.core.$strip>;
390
+ }, z.core.$strip>>>;
391
+ finish_reason: z.ZodNullable<z.ZodString>;
392
+ }, z.core.$strip>;
393
+ /** Inferred base message complete event type. */
394
+ type MessageCompleteEvent = z.infer<typeof MessageCompleteEventSchema>;
395
+ //#endregion
396
+ //#region adapters/shared/stream-session/src/session/types.d.ts
397
+ /**
398
+ * Union of SDK event types emitted directly by the base stream session.
399
+ *
400
+ * Adapter configs use a broader union (`SdkEventMessage`) that includes all
401
+ * adapter-specific events. Since `AgentStartedEvent` and `ErrorEvent` are
402
+ * members of every adapter's `SdkEventMessage` union, a function accepting
403
+ * the broader union satisfies this narrower parameter type via contravariance.
404
+ */
405
+ type BaseSessionEmitEvent = AgentStartedEvent$1 | ErrorEvent$1;
406
+ /**
407
+ * Minimal typed envelope for the `message_complete` SDK event returned
408
+ * from `bus.once()` inside the base stream session.
409
+ *
410
+ * Both adapter namespaces wrap their SDK events in an envelope with the same
411
+ * shape (event, agentId?, adapterId?, ...). The base session only
412
+ * needs `event.eventType` for dispatch and passes the full payload to
413
+ * `applyMessageComplete` which is implemented by each adapter subclass.
414
+ */
415
+ interface StreamSdkEventEnvelope {
416
+ /** Inner SDK event discriminated by `eventType`. */
417
+ event: {
418
+ eventType: string;
419
+ } & Record<string, unknown>;
420
+ /** Agent ID from the envelope for bus filter matching. */
421
+ agentId?: string;
422
+ /** Adapter ID from the envelope for bus filter matching. */
423
+ adapterId?: string;
424
+ /** Adapter name from the envelope. */
425
+ adapterName?: string;
426
+ /** Session ID from the envelope. */
427
+ sessionId?: string;
428
+ /** Adapter-local session ID from the envelope for turn correlation. */
429
+ adapterSessionId?: string;
430
+ }
431
+ /**
432
+ * Shared configuration interface for stream-based connector sessions.
433
+ *
434
+ * Contains all fields common to the Anthropic SDK and OpenAI Node session
435
+ * configurations. SDK-specific fields (`client`, tool-list types) remain
436
+ * in each adapter's own config type which extends this interface.
437
+ * @typeParam TBus - Scoped bus type for the adapter namespace
438
+ */
439
+ interface StreamSessionConfig<TBus extends ScopedBus<string> = ScopedBus<string>> {
440
+ /** Scoped bus for the adapter namespace. */
441
+ bus: TBus;
442
+ /** Stable adapter instance identifier. */
443
+ adapterId: string;
444
+ /** Human-readable adapter name used in log messages and bus events. */
445
+ adapterName: string;
446
+ /** Agent ID for tool execution attribution and bus subject filtering. */
447
+ agentId: string;
448
+ /** Makaio session ID for tool execution context. Stable across turns. */
449
+ sessionId?: string;
450
+ /** Working directory for tool execution context. */
451
+ cwd: string;
452
+ /** Initial model identifier; mutable per turn via `updateModel()`. */
453
+ model: string;
454
+ /** Reasoning effort level for reasoning-capable models. */
455
+ reasoningEffort?: AIReasoningLevel$1;
456
+ /**
457
+ * Timeout in milliseconds before the streaming API call is considered
458
+ * failed. A single retry is attempted before the error propagates.
459
+ */
460
+ streamStartTimeoutMs?: number;
461
+ /** Environment variables forwarded to tool execution. */
462
+ env: Record<string, string>;
463
+ /** Resolved system prompt string prepended to the message array. */
464
+ systemPrompt?: string;
465
+ /**
466
+ * Emit a typed SDK lifecycle event to the connector bus.
467
+ * Adapter configs narrow this to their full `SdkEventMessage` union.
468
+ * The base session only emits `agent_started` and `error` events,
469
+ * both of which are members of every adapter's `SdkEventMessage` union.
470
+ */
471
+ emitSdkEvent: (event: BaseSessionEmitEvent) => Promise<void>;
472
+ /** Handle a connector-level error. */
473
+ handleError: (error: Error, rethrow: boolean) => void;
474
+ /** Called synchronously when a new turn is about to start. */
475
+ onTurnStart?: (handle: MessageHandle) => void;
476
+ /** Called when a turn reaches a terminal state (completed or error). */
477
+ onTurnComplete?: (handle: MessageHandle, result: MessageResult) => void;
478
+ /** Optional low-level event logger for adapter observability. */
479
+ logLowLevelEvent?: (event: unknown) => void;
480
+ /**
481
+ * Directory restrictions for file-system tool execution.
482
+ * Forwarded as `constraints.allowedDirectories` in every tool call.
483
+ * - `undefined`: no directory restriction
484
+ * - `[]`: deny all filesystem paths
485
+ * - non-empty array: allow-list to these directories
486
+ */
487
+ allowedDirectories?: string[];
488
+ /**
489
+ * Record one mcp_call invocation in the session tool ledger.
490
+ *
491
+ * When present, the session forwards this to `HandleToolCallsCallbacks` so
492
+ * the shared `handleToolCalls` function can record mcp_call invocations.
493
+ * The connector binds it as a closure over its ledger and current turn number,
494
+ * so no turn-number threading is needed at the session level.
495
+ * @param toolFullName - The namespaced target tool name from the mcp_call args
496
+ */
497
+ recordMcpCall?: (toolFullName: string) => void;
498
+ }
499
+ //#endregion
500
+ //#region adapters/shared/stream-session/src/session/base-stream-session.d.ts
501
+ /**
502
+ * Turn contract required by `BaseStreamSession`.
503
+ *
504
+ * Stream sessions depend on the core procedural turn lifecycle plus an abort
505
+ * signal accessor used by `runTurnIteration`.
506
+ */
507
+ interface StreamSessionTurn extends ProceduralConnectorTurn {
508
+ /**
509
+ * Get the current abort signal for this turn.
510
+ * @returns AbortSignal for stream cancellation
511
+ */
512
+ getAbortSignal(): AbortSignal;
513
+ }
514
+ /**
515
+ * Abstract base class for stream-based AI connector sessions.
516
+ *
517
+ * Captures the shared session lifecycle logic between the Anthropic SDK and
518
+ * OpenAI Node adapters. Both adapters use an identical queue-based turn model:
519
+ *
520
+ * 1. `processQueue` — dequeues messages and dispatches to `startNewTurn`
521
+ * 2. `startNewTurn` — initialises a new turn, wires the finally-cleanup, and
522
+ * fires the async `queueMicrotask` loop
523
+ * 3. `runTurn` → `runTurnIteration` — the agentic loop; executes streaming
524
+ * API calls and recurses when tool calls are returned
525
+ * 4. `executeStreamingStep` — the stream-start-timeout wrapper; delegates the
526
+ * actual API call to the abstract `executeApiCall` hook
527
+ * 5. `applyMessageComplete` — abstract; each adapter appends the assistant
528
+ * response in its own wire format and handles tool recursion
529
+ *
530
+ * ## Generic type parameters
531
+ * @typeParam TConfig - Adapter session config extending `StreamSessionConfig`
532
+ * @typeParam TTurn - Adapter turn type extending `ProceduralConnectorTurn`
533
+ * @typeParam TMessageCompleteEvent - Adapter-specific `MessageCompleteEvent`
534
+ * extension; defaults to the shared base schema type
535
+ */
536
+ declare abstract class BaseStreamSession<TConfig extends StreamSessionConfig<ScopedBus<string>>, TTurn extends StreamSessionTurn, TMessageCompleteEvent extends MessageCompleteEvent = MessageCompleteEvent> extends BaseConnectorSession<TConfig> {
537
+ /**
538
+ * Maximum number of tool-call recursion steps per turn.
539
+ * Subclasses reference this in `applyMessageComplete`.
540
+ */
541
+ protected static readonly MAX_TOOL_CALL_ITERATIONS = 8;
542
+ /** Active turn reference; overwritten on each new turn. */
543
+ protected currentTurn: TTurn | undefined;
544
+ /** Assembled last assistant message content; reset on each new turn. */
545
+ protected lastAssistantMessage: string | undefined;
546
+ /** Runtime model used for subsequent API calls; set from config.model. */
547
+ protected currentModel: string;
548
+ /** Runtime working directory for tool execution; set from config.cwd. */
549
+ protected currentCwd: string;
550
+ /**
551
+ * Initialize a stream session with connector runtime config.
552
+ * @param config - Session configuration (bus identity, model/cwd defaults, and adapter hooks).
553
+ */
554
+ constructor(config: TConfig);
555
+ /**
556
+ * Create the adapter-specific turn instance for `handle`.
557
+ * @param handle - The message handle this turn will process
558
+ * @returns A new turn instance
559
+ */
560
+ protected abstract createTurn(handle: MessageHandle): TTurn;
561
+ /**
562
+ * Build (or rebuild) the adapter-specific messages array from the message
563
+ * handle's history and optional merged content from superseded messages.
564
+ * @param handle - The message handle containing history and current message
565
+ * @param mergedContent - Text content from superseded/merged messages
566
+ */
567
+ protected abstract buildMessages(handle: MessageHandle, mergedContent?: string[]): void;
568
+ /**
569
+ * Execute the adapter-specific streaming API call.
570
+ *
571
+ * Called inside `executeStreamingStep` after the stream-start timeout is
572
+ * armed. Implementors must operate on the provided turn instance rather than
573
+ * reading `this.currentTurn` directly so superseded turns cannot mutate the
574
+ * active turn state.
575
+ * @param turn - Captured turn instance for this run loop
576
+ * @param abortSignal - Combined abort signal (turn abort + stream timeout)
577
+ * @param adapterSessionId - Turn-scoped adapter session ID for event correlation
578
+ */
579
+ protected abstract executeApiCall(turn: TTurn, abortSignal: AbortSignal, adapterSessionId: string): Promise<void>;
580
+ /**
581
+ * Return the bus subject to `once()` on for the `message_complete` event.
582
+ *
583
+ * Each adapter listens on its own namespace subject (e.g.
584
+ * `AnthropicSdkConnectorSubjects.sdk.event`).
585
+ * @returns The bus subject for the adapter's SDK event stream
586
+ */
587
+ protected abstract getSdkEventSubject(): ScopedSubjectDefinition<string>;
588
+ /**
589
+ * Apply a `message_complete` event to the messages array and recurse for
590
+ * tool calls.
591
+ *
592
+ * Called in `runTurnIteration` after `message_complete` is received from
593
+ * the bus. Implementations append the assistant message in the adapter's
594
+ * wire format, check the tool-call finish reason, and call
595
+ * `runTurnIteration` again when tools need executing.
596
+ * @param result - The parsed `message_complete` event payload
597
+ * @param currentHandle - The active message handle
598
+ * @param toolCallIteration - Current recursion depth (for iteration guard)
599
+ * @param turn - Captured turn instance for this run loop
600
+ */
601
+ protected abstract applyMessageComplete(result: TMessageCompleteEvent, currentHandle: MessageHandle, toolCallIteration: number, turn: TTurn): Promise<void>;
602
+ /**
603
+ * Classify an SDK-level error into the appropriate error type.
604
+ *
605
+ * The base class re-throws whatever this returns; adapters map SDK-specific
606
+ * error shapes (e.g. Anthropic's `APIError`, OpenAI's `APIError`) to
607
+ * normalised error instances.
608
+ * @param error - The raw error caught from the API call or stream
609
+ * @returns A normalised `Error` instance
610
+ */
611
+ protected abstract classifyError(error: unknown): Error;
612
+ /**
613
+ * Process messages from the queue.
614
+ *
615
+ * Creates a new turn or handles immediate injection via abort+restart.
616
+ * @param queue - The user message queue to drain
617
+ */
618
+ processQueue(queue: UserMessageQueue): Promise<void>;
619
+ /**
620
+ * Start a new turn for the given message handle.
621
+ *
622
+ * Orchestrates the full turn setup: session ID rotation, message building,
623
+ * turn creation, acknowledgment, and the async `queueMicrotask` loop.
624
+ * Turn finalisation is always in the `finally` block so the connector state
625
+ * machine always reaches a terminal state.
626
+ * @param handle - The message handle to process
627
+ * @param mergedContent - Optional content from superseded/merged messages
628
+ */
629
+ protected startNewTurn(handle: MessageHandle, mergedContent?: string[]): Promise<void>;
630
+ /**
631
+ * Handle a turn-level error from the `queueMicrotask` body.
632
+ *
633
+ * Branches on whether the turn was paused (immediate-mode abort or
634
+ * shutdown) and either returns silently, completes the handle with an
635
+ * error result, or delegates to the connector error handler.
636
+ * @param error - The caught error
637
+ * @param turn - The captured turn reference for pause-state checks
638
+ * @param handle - The message handle to finalise on non-abort errors
639
+ */
640
+ private handleTurnError;
641
+ /**
642
+ * Run a turn — the agentic loop entry point.
643
+ * @param turn - Captured turn instance for this run loop
644
+ * @param currentHandle - The handle to track supersedence
645
+ */
646
+ protected runTurn(turn: TTurn, currentHandle: MessageHandle): Promise<void>;
647
+ /**
648
+ * Wait for the SDK `message_complete` event emitted by stream processing.
649
+ *
650
+ * Uses `bus.once` with AbortSignal support to avoid dangling listeners on
651
+ * abort. Namespace-scoped buses are shared across connector instances, so
652
+ * the filter includes both the event type and adapter identity to prevent
653
+ * concurrent agents from satisfying each other's waiter.
654
+ * @param abortSignal - Abort signal for the current turn
655
+ * @param adapterSessionId - Adapter-local session ID bound to the turn
656
+ * @returns Promise resolving to the SDK event envelope
657
+ */
658
+ protected createMessageCompletePromise(abortSignal: AbortSignal, adapterSessionId: string): Promise<{
659
+ payload: StreamSdkEventEnvelope;
660
+ }>;
661
+ /**
662
+ * Execute one streaming API step with stream-start-timeout protection.
663
+ *
664
+ * Arms a timeout that aborts the stream connection attempt if no bytes
665
+ * arrive within `streamStartTimeoutMs` (default: 30 s). On timeout a
666
+ * single retry is attempted by `runTurnIteration`. Delegates the actual
667
+ * API call to the abstract `executeApiCall` hook.
668
+ * @param turn - Captured turn instance for this run loop
669
+ * @param abortSignal - Turn-level abort signal
670
+ * @param adapterSessionId - Turn-scoped adapter session ID for event correlation
671
+ */
672
+ protected executeStreamingStep(turn: TTurn, abortSignal: AbortSignal, adapterSessionId: string): Promise<void>;
673
+ /**
674
+ * Run one iteration of the agentic loop.
675
+ *
676
+ * Fires the streaming step, waits for the `message_complete` event, then
677
+ * delegates to `applyMessageComplete`. Handles abort signals, stream-start
678
+ * timeouts (with a single retry), and SDK-level errors uniformly.
679
+ * @param turn - Captured turn instance for this run loop
680
+ * @param currentHandle - The handle to track supersedence
681
+ * @param toolCallIteration - Current tool recursion depth (default: 0)
682
+ */
683
+ protected runTurnIteration(turn: TTurn, currentHandle: MessageHandle, toolCallIteration?: number): Promise<void>;
684
+ /**
685
+ * Build the tool execution constraints object from session config.
686
+ *
687
+ * Returns `{ allowedDirectories }` when `config.allowedDirectories` is set,
688
+ * or `undefined` when no directory restrictions are configured. Both
689
+ * concrete adapter sessions call this in `applyMessageComplete` to avoid
690
+ * duplicating the conditional spread.
691
+ * @returns Typed constraints for `ToolExecutionContextOverrides`, or `undefined`
692
+ */
693
+ protected buildToolConstraints(): {
694
+ allowedDirectories: string[];
695
+ } | undefined;
696
+ /**
697
+ * Update the model used for subsequent API calls.
698
+ *
699
+ * Called by the connector's `changeModelInPlace()` to sync the session
700
+ * with the connector-level model without requiring a full session swap.
701
+ * @param model - New model identifier
702
+ */
703
+ updateModel(model: string): void;
704
+ /**
705
+ * Update the working directory used for subsequent tool executions.
706
+ *
707
+ * Called by the connector's `changeCwdInPlace()` to sync the session
708
+ * with the connector-level cwd without requiring a full session swap.
709
+ * @param cwd - New working directory path
710
+ */
711
+ updateCwd(cwd: string): void;
712
+ /**
713
+ * Get the current turn for state inspection.
714
+ * @returns The current turn or `undefined` if no turn is active
715
+ */
716
+ getCurrentTurn(): TTurn | undefined;
717
+ /**
718
+ * Returns true when a newer turn has replaced the captured turn.
719
+ * @param turn - Captured turn reference
720
+ * @returns Whether this turn has been superseded
721
+ */
722
+ protected isTurnSuperseded(turn: TTurn): boolean;
723
+ /**
724
+ * Unified early-exit guard for stale turns and superseded handles.
725
+ * @param turn - Captured turn reference
726
+ * @param currentHandle - Active message handle
727
+ * @returns True when iteration must stop
728
+ */
729
+ protected shouldAbortTurnProcessing(turn: TTurn, currentHandle: MessageHandle): boolean;
730
+ }
731
+ //#endregion
732
+ //#region adapters/shared/stream-session/src/connector/base-stream-connector.d.ts
733
+ /**
734
+ * Minimal session contract required by BaseStreamConnector.
735
+ *
736
+ * Extends `ProceduralConnectorSession` with the lifecycle methods that the
737
+ * connector delegates to: `abort` (used by interrupt/close), `updateModel` and
738
+ * `updateCwd` for in-place mutation without a full session swap.
739
+ */
740
+ interface StreamConnectorSession extends ProceduralConnectorSession {
741
+ /** Abort the active turn, cancelling any in-flight API call. */
742
+ abort(): Promise<void>;
743
+ /**
744
+ * Update the model used for subsequent API calls.
745
+ * @param model - New model identifier
746
+ */
747
+ updateModel(model: string): void;
748
+ /**
749
+ * Update the working directory used for subsequent tool executions.
750
+ * @param cwd - New working directory path
751
+ */
752
+ updateCwd(cwd: string): void;
753
+ /**
754
+ * Update the session's tool set for the next API call.
755
+ * Optional — not all adapters support mid-session tool updates.
756
+ * @param tools - New tool list in generic `ToolListItem` format; session converts internally
757
+ */
758
+ updateTools?(tools: ToolListItem[]): void;
759
+ /**
760
+ * Update the reasoning effort level used for subsequent API calls.
761
+ * Optional — only adapters that pass reasoning per-request implement this seam.
762
+ * @param level - New reasoning effort level
763
+ */
764
+ updateReasoning?(level: AIReasoningLevel$1): void;
765
+ }
766
+ /**
767
+ * Config shape required by `BaseStreamConnector`.
768
+ *
769
+ * Extends `BaseAgentConnectorConfig` and widens `mcpSessionContext` to include
770
+ * the full {@link McpSessionContext} shape so the stream connector can
771
+ * re-resolve the session via the bus (which requires `sessionId`, `profileId`,
772
+ * and `projectId`). The orchestrator always supplies a full `McpSessionContext`;
773
+ * `LedgerSessionContext` is retained in the union for standalone/test connectors
774
+ * that do not need bus re-resolve.
775
+ * @typeParam TBus - Scoped bus type for the adapter namespace
776
+ * @typeParam TProviderConfig - Provider-specific config object
777
+ */
778
+ type BaseStreamConnectorConfig<TBus extends ScopedBus<string> = ScopedBus<string>, TProviderConfig extends object = object> = Omit<BaseAgentConnectorConfig<TBus, TProviderConfig>, 'mcpSessionContext'> & {
779
+ /**
780
+ * MCP session context resolved by the orchestrator.
781
+ * May be the full {@link McpSessionContext} (with `sessionId`/`servers` for
782
+ * bus re-resolve) or a bare `LedgerSessionContext` for standalone connectors.
783
+ * The connector discriminates at runtime via `'sessionId' in ctx`.
784
+ */
785
+ mcpSessionContext?: McpSessionContext | LedgerSessionContext;
786
+ };
787
+ /**
788
+ * Abstract base class for stream-based AI adapter connectors.
789
+ *
790
+ * Captures the shared connector lifecycle logic between the Anthropic SDK and
791
+ * OpenAI Node adapters. Both connectors follow an identical pattern:
792
+ *
793
+ * - Lazy single-session initialisation via `ensureSession` / `initializeSession`
794
+ * - Tool fetching on first turn (delegated to the abstract `fetchTools` hook)
795
+ * - `sendMessage` → `processUserMessages` delegation to `ProceduralAgentConnector`
796
+ * - In-place model and cwd mutation via `changeModelInPlace` / `changeCwdInPlace`
797
+ *
798
+ * Concrete subclasses must implement the following abstract hooks:
799
+ * - `fetchTools()` — fetch adapter-specific tools and cache them internally
800
+ * - `createSession()` — construct the concrete session instance
801
+ * - `getTurnSubjects()` — return adapter-specific turn lifecycle subjects
802
+ *
803
+ * Subclasses may override `afterSessionCreated()` for extra post-creation wiring
804
+ * (e.g. Anthropic sets tools on the session after construction).
805
+ * @typeParam TBus - Scoped bus type for the adapter namespace
806
+ * @typeParam TSession - Concrete session type; must satisfy `StreamConnectorSession`
807
+ * @typeParam TConfig - Connector config type extending `BaseStreamConnectorConfig<TBus>`
808
+ */
809
+ declare abstract class BaseStreamConnector<TBus extends ScopedBus<string>, TSession extends StreamConnectorSession, TConfig extends BaseStreamConnectorConfig<TBus>> extends ProceduralAgentConnector<TBus, TConfig> {
810
+ /** Session manages Turn lifecycle. Initialised lazily on first message. */
811
+ private session?;
812
+ /** Message queue for serialising async send operations. */
813
+ private readonly userMessageQueue;
814
+ /** MCP tools resolved for direct injection into the session. */
815
+ protected mcpDirectTools: ToolListItem[];
816
+ /**
817
+ * Fresh MCP session context fetched via bus during `refreshTools()`.
818
+ *
819
+ * When set, `prepareMcpDirectTools()` reads from this cache instead of the
820
+ * startup snapshot in `config.mcpSessionContext`, ensuring that mid-session
821
+ * tool refreshes reflect the current registry state rather than the state
822
+ * at connector construction time.
823
+ */
824
+ private mcpSessionContextCache?;
825
+ /**
826
+ * Flag set via `markToolRefreshPending()` by the AIAgent layer on MCP bus events.
827
+ * Checked at turn boundaries to trigger `refreshTools()`.
828
+ *
829
+ * Refreshing mid-turn would mutate the tool set while the LLM is actively
830
+ * generating tool calls against the current set, risking inconsistent state.
831
+ * Instead, the refresh is deferred to the next turn boundary:
832
+ *
833
+ * - Consumed in `onTurnStarted` (primary) so the next turn uses updated tools
834
+ * immediately, before the API call is made.
835
+ * - Consumed in `onTurnFinished` (safety net) for updates that arrive
836
+ * mid-turn, ensuring the turn after that also picks up the updated tools.
837
+ */
838
+ protected hasPendingToolRefresh: boolean;
839
+ /**
840
+ * Set to `true` by `refreshTools()` when MCP direct-inject tools have been
841
+ * re-prepared but the canonical turn number for the next turn is not yet known.
842
+ *
843
+ * Flushed to the tool ledger in `onTurnStarted`, after `consumeTurnNumber()`
844
+ * has committed the real canonical value, ensuring `recordInjection` is always
845
+ * called with the correct turn number rather than a speculative `currentTurnNumber + 1`.
846
+ */
847
+ private hasPendingLedgerInjection;
848
+ /**
849
+ * Marks that MCP tools have changed and should be refreshed at the next turn boundary.
850
+ *
851
+ * Called by the AIAgent layer when receiving MCP bus events (`mcp.tools.updated`,
852
+ * `mcp.tools.enabled`). The connector will call `refreshTools()` before processing
853
+ * the next queued message.
854
+ */
855
+ markToolRefreshPending(): void;
856
+ /**
857
+ * Fetch adapter-specific tools from the bus and cache them internally.
858
+ *
859
+ * Called once before the first session is created. Implementations store
860
+ * the result in their own typed field (e.g. `this.anthropicTools`) which is
861
+ * then passed to `createSession()`.
862
+ */
863
+ protected abstract fetchTools(): Promise<void>;
864
+ /**
865
+ * Construct and return the concrete session instance.
866
+ *
867
+ * Called by `initializeSession` after tools have been fetched. The session
868
+ * config should be fully populated from `this.config`, `this.cwd`,
869
+ * `this.model`, and the previously fetched tools.
870
+ * @returns The initialised adapter-specific session
871
+ */
872
+ protected abstract createSession(): TSession;
873
+ /**
874
+ * Perform any adapter-specific post-creation wiring on the session.
875
+ *
876
+ * Called immediately after `createSession()` and before `wireSessionEvents()`.
877
+ * The default implementation is a no-op — override only when the adapter
878
+ * needs extra wiring beyond what `createSession()` already handles.
879
+ * @param _session - The freshly created session instance
880
+ */
881
+ protected afterSessionCreated(_session: TSession): void;
882
+ /**
883
+ * Return the adapter's namespace-specific turn subjects for `wireSessionEvents`.
884
+ *
885
+ * Forwarded to `ProceduralAgentConnector.wireSessionEvents` which subscribes
886
+ * to turn lifecycle events and updates connector processing state.
887
+ * @returns Turn subject definitions for this adapter's namespace
888
+ */
889
+ protected abstract getTurnSubjects(): WireSessionSubjects<TBus['namespace']>;
890
+ /**
891
+ * Get the active session instance.
892
+ * @returns The session or `undefined` if not yet initialised
893
+ */
894
+ protected getSession(): TSession | undefined;
895
+ /**
896
+ * Ensure the session is initialised and return it.
897
+ *
898
+ * No-op if the session already exists (idempotent). Creates and wires the
899
+ * session on first call by delegating to `initializeSession`.
900
+ * @returns The initialised session as `ProceduralConnectorSession`
901
+ */
902
+ protected ensureSession(): Promise<ProceduralConnectorSession>;
903
+ /**
904
+ * Get the user message queue for this connector.
905
+ * @returns The `UserMessageQueue` instance shared across all turns
906
+ */
907
+ protected getSessionQueue(): UserMessageQueue;
908
+ /**
909
+ * Initialise the session for SDK lifecycle management.
910
+ *
911
+ * Fetches tools (once via `fetchToolsViaBus`), prepares MCP direct-inject
912
+ * tools, constructs the concrete session via `createSession`, runs optional
913
+ * adapter-specific post-creation wiring via `afterSessionCreated`, wires turn
914
+ * events to the connector state machine via `wireSessionEvents`, pushes any
915
+ * MCP direct-inject tools into the session via `updateTools`, then records
916
+ * the initial injection set in the tool ledger at the correct turn number
917
+ * (1 for fresh sessions; the staged canonical turn for connector swaps).
918
+ */
919
+ private initializeSession;
920
+ /**
921
+ * Convert MCP direct-inject tools from the session context to the generic
922
+ * `ToolListItem` format and cache in `this.mcpDirectTools`.
923
+ *
924
+ * Called during `initializeSession()` after `fetchToolsViaBus()`, and again
925
+ * by `refreshTools()` when the tool set may have changed. Reads from
926
+ * `mcpSessionContextCache` when available (populated by a bus re-resolve),
927
+ * falling back to the startup snapshot in `config.mcpSessionContext`.
928
+ * No-op when neither source is present.
929
+ */
930
+ protected prepareMcpDirectTools(): void;
931
+ /**
932
+ * Fetch tools from the bus if not already loaded.
933
+ *
934
+ * Guards with a `this.session` check so tools are only fetched once per
935
+ * connector lifetime. Delegates to the abstract `fetchTools` hook which each
936
+ * adapter implements to populate its own typed tools field.
937
+ */
938
+ protected fetchToolsViaBus(): Promise<void>;
939
+ /**
940
+ * Re-prepare MCP direct-inject tools for the next turn.
941
+ *
942
+ * Called at turn boundary when `hasPendingToolRefresh` is true (set via
943
+ * `markToolRefreshPending()`). When a full `McpSessionContext` (with
944
+ * `sessionId`) is available, issues a `McpSubjects['session.resolve']` bus
945
+ * call to fetch the latest tool state from the registry, updating
946
+ * `mcpSessionContextCache` so `prepareMcpDirectTools()` reads fresh data.
947
+ * If the bus call fails, logs a warning and falls back to the previous cache
948
+ * (or the startup snapshot) so the connector remains operational.
949
+ *
950
+ * Subclasses that manage native adapter-format tools (e.g. Anthropic, OpenAI)
951
+ * override this to: (1) re-fetch their native tools, (2) call
952
+ * `super.refreshTools()` to re-prepare `mcpDirectTools` and arm the ledger
953
+ * flag, then (3) push the updated tool list to the active session via
954
+ * `this.getSession()?.updateTools?.(this.mcpDirectTools)`.
955
+ *
956
+ * Unlike `fetchTools()` which runs once before session creation,
957
+ * `refreshTools()` operates on a live session and may be called multiple
958
+ * times during a connector's lifetime.
959
+ */
960
+ protected refreshTools(): Promise<void>;
961
+ /**
962
+ * Re-resolve the MCP session context from the bus and update the cache.
963
+ *
964
+ * Only fires when the startup config holds a full `McpSessionContext` (i.e.
965
+ * it has a `sessionId`). Standalone connectors created without a session skip
966
+ * this and continue to use the existing cache or startup snapshot.
967
+ * On bus failure the warning is logged and the cache is left unchanged so
968
+ * the connector can continue with the last known good tool set.
969
+ */
970
+ private resolveAndCacheMcpContext;
971
+ /**
972
+ * Wire turn-boundary hooks into the session lifecycle.
973
+ *
974
+ * - `onTurnStarted`: commit the canonical turn number via `consumeTurnNumber`,
975
+ * refresh tools if a pending update arrived while idle or during the previous
976
+ * turn (primary refresh path), then flush any pending ledger injection so
977
+ * `recordInjection` is always called with the real turn number. The order
978
+ * matters: consumeTurnNumber → refreshTools → recordInjection, because
979
+ * `refreshTools` sets `hasPendingLedgerInjection`.
980
+ * - `onTurnFinished`: safety-net refresh for updates that arrive mid-turn,
981
+ * before draining the queue so the following turn uses the updated tool set.
982
+ * @returns Wire session configuration with the turn hooks
983
+ */
984
+ protected getWireSessionConfig(): WireSessionConfig;
985
+ /**
986
+ * Resolve the runtime system prompt to a plain string for the SDK API.
987
+ *
988
+ * - `string` mode: use as-is
989
+ * - Append mode: use `content` directly (stream-based adapters have no base
990
+ * prompt to append to)
991
+ * @returns Resolved prompt string, or `undefined` if no prompt is set
992
+ */
993
+ protected resolveSystemPrompt(): string | undefined;
994
+ /**
995
+ * Send a message to the agent.
996
+ * @param message - The normalised message to send
997
+ * @param options - Optional send message options
998
+ * @returns A handle for tracking the message
999
+ */
1000
+ sendMessage(message: NormalizedMessageInput, options?: ConnectorSendMessageOptions): Promise<MessageHandle>;
1001
+ /**
1002
+ * Abort the agent and clean up resources.
1003
+ *
1004
+ * Note: Session-closed event emission is handled by the adapter's AIAgent
1005
+ * layer, not by the connector.
1006
+ */
1007
+ abort(): void;
1008
+ /**
1009
+ * Gracefully close the session.
1010
+ */
1011
+ close(): Promise<void>;
1012
+ /**
1013
+ * Perform an in-place model update without swapping the connector.
1014
+ *
1015
+ * Stream-based adapters are stateless — the session caches `config.model` at
1016
+ * construction but must be synced here so the next turn uses the new model.
1017
+ *
1018
+ * **Mutation contract:** Implementations MUST NOT mutate `this.model`.
1019
+ * The caller owns the connector-level `model` field update after this returns.
1020
+ * @param newModel - The model identifier to switch to
1021
+ * @returns Always `true` — stateless APIs never require a full connector swap
1022
+ */
1023
+ changeModelInPlace(newModel: string): Promise<boolean>;
1024
+ /**
1025
+ * Perform an in-place working-directory update without swapping the connector.
1026
+ *
1027
+ * Stream-based adapters are stateless — cwd is only used for tool execution
1028
+ * context, not for persistent session state.
1029
+ *
1030
+ * **Mutation contract:** Implementations MUST NOT mutate `this.cwd`.
1031
+ * The caller owns the connector-level `cwd` field update after this returns.
1032
+ * @param newCwd - The working directory path to switch to
1033
+ * @returns Always `true` — stateless APIs never require a full connector swap
1034
+ */
1035
+ changeCwdInPlace(newCwd: string): Promise<boolean>;
1036
+ /**
1037
+ * Perform an in-place reasoning effort update without swapping the connector.
1038
+ *
1039
+ * Stream-based adapters pass `reasoning_effort` (or equivalent) per-request.
1040
+ * The session's `currentReasoningEffort` field is updated so the next API
1041
+ * call uses the new level without requiring a full connector swap.
1042
+ *
1043
+ * **Mutation contract:** Implementations MUST NOT mutate `this.currentReasoningEffort`.
1044
+ * The caller owns the connector-level field update after this returns `true`.
1045
+ * @param newLevel - The new reasoning effort level to apply
1046
+ * @returns Always `true` — stateless APIs never require a full connector swap
1047
+ */
1048
+ changeReasoningInPlace(newLevel: AIReasoningLevel$1): Promise<boolean>;
1049
+ /**
1050
+ * Interrupt the current turn by aborting the active API request.
1051
+ */
1052
+ interrupt(): Promise<void>;
1053
+ /**
1054
+ * Get the adapter session ID.
1055
+ *
1056
+ * Stream-based adapters use a locally-generated UUID (stateless APIs provide
1057
+ * no server-side session identity).
1058
+ * @returns The local session UUID
1059
+ */
1060
+ getAdapterSessionId(): Promise<string>;
1061
+ /**
1062
+ * Initialise `adapterSessionId` from config or generate a fresh UUID.
1063
+ *
1064
+ * Call this at the end of each concrete constructor after `super()`. The
1065
+ * nullish-assignment guard ensures the swap case (where the base constructor
1066
+ * already populated `adapterSessionId` from config) is preserved.
1067
+ */
1068
+ protected initAdapterSessionId(): void;
1069
+ }
1070
+ //#endregion
1071
+ //#region adapters/shared/stream-session/src/agent/base-stream-agent.d.ts
1072
+ /**
1073
+ * Extract the bus namespace from a connector via the same conditional type used by
1074
+ * `AIAgent.subscribeConnector` and `AIAgent.createConnectorEventMapping`.
1075
+ *
1076
+ * Using the identical conditional type expression ensures TypeScript resolves the
1077
+ * constraint at call sites without a namespace mismatch error.
1078
+ * @typeParam TConnector - Connector type extending `AIAgentConnector<ScopedBus<string>>`
1079
+ */
1080
+ type ConnectorNamespace<TConnector extends AIAgentConnector<ScopedBus<string>>> = TConnector extends AIAgentConnector<infer TBus> ? TBus['namespace'] : never;
1081
+ type ToolCallArgs = Record<string, unknown>;
1082
+ /**
1083
+ * A manually typed subject definition for event (non-request) subjects.
1084
+ *
1085
+ * Uses a structural interface rather than `SubjectDefinition<SubjectRecord, ...>` to
1086
+ * avoid the incompatibility that arises when the full namespace `SubjectRecord` contains
1087
+ * a mix of event and request subjects (e.g., `tool_approval` is a request). By defining
1088
+ * only the `$meta` fields we care about, concrete subjects that extend `ScopedSubjectDefinition`
1089
+ * are still assignable here as long as they carry event payloads.
1090
+ *
1091
+ * `HandlerForSubjectDefinition<EventSubjectDef<N>>` resolves to
1092
+ * `EventHandler<Record<string, unknown>>` — a concrete, non-`never` handler type —
1093
+ * enabling the base class wire methods to use typed handler parameters.
1094
+ * @typeParam TNamespace - The adapter bus namespace string
1095
+ */
1096
+ type EventSubjectDef<TNamespace extends string> = {
1097
+ readonly $meta: {
1098
+ readonly payload: EventMessagePayload<Record<string, unknown>>;
1099
+ readonly namespace: TNamespace;
1100
+ readonly isRequest: false;
1101
+ readonly local: boolean;
1102
+ readonly channel: boolean;
1103
+ };
1104
+ readonly subject: string;
1105
+ };
1106
+ /**
1107
+ * Adapter-specific subjects for stream-based agent wiring.
1108
+ *
1109
+ * Groups all connector scoped subjects used during event wiring into a single spec
1110
+ * type parameter. Subjects whose payloads differ between adapters (chunk, usage,
1111
+ * toolCalls, reasoningComplete) carry a generic `EventSubjectDef`. Concrete adapters
1112
+ * supply fully typed subjects when implementing `getConnectorSubjects()` — the typed
1113
+ * subjects extend `EventSubjectDef` so TypeScript can resolve handler signatures.
1114
+ * @typeParam TNamespace - The adapter bus namespace string literal
1115
+ */
1116
+ interface StreamAdapterSubjectSpec<TNamespace extends string> {
1117
+ /**
1118
+ * Streaming chunk subject. Payload differs per adapter:
1119
+ * - Anthropic: `{ eventType, index, delta }` (delta.text for text_delta)
1120
+ * - OpenAI: `{ eventType, id, choices }` (choices[0].delta.content)
1121
+ */
1122
+ readonly chunk: EventSubjectDef<TNamespace>;
1123
+ /**
1124
+ * Token usage subject. Payload differs per adapter:
1125
+ * - Anthropic: has `cache_read_input_tokens` / `cache_creation_input_tokens`
1126
+ * - OpenAI: has `prompt_tokens_details` / `completion_tokens_details`
1127
+ */
1128
+ readonly usage: EventSubjectDef<TNamespace>;
1129
+ /**
1130
+ * Tool calls subject. Payload differs per adapter:
1131
+ * - Anthropic: each tool call entry carries a provider `blockIndex`
1132
+ * - OpenAI: base ToolCall without blockIndex
1133
+ */
1134
+ readonly toolCalls: EventSubjectDef<TNamespace>;
1135
+ /**
1136
+ * Reasoning complete subject. Payload differs per adapter:
1137
+ * - Anthropic: base + `signature` field (for native history round-trip)
1138
+ * - OpenAI: base only
1139
+ */
1140
+ readonly reasoningComplete: EventSubjectDef<TNamespace>;
1141
+ /** Assembled message complete event — `content` field is shared across adapters. */
1142
+ readonly messageComplete: EventSubjectDef<TNamespace>;
1143
+ /** Incremental reasoning content delta — payload is shared across adapters. */
1144
+ readonly reasoningDelta: EventSubjectDef<TNamespace>;
1145
+ /** Tool execution started lifecycle event — payload is shared across adapters. */
1146
+ readonly toolStarted: EventSubjectDef<TNamespace>;
1147
+ /** Tool execution completed lifecycle event — payload is shared across adapters. */
1148
+ readonly toolCompleted: EventSubjectDef<TNamespace>;
1149
+ /** Agent turn started lifecycle event — payload is shared across adapters. */
1150
+ readonly agentStarted: EventSubjectDef<TNamespace>;
1151
+ /** Agent turn completed lifecycle event — payload is shared across adapters. */
1152
+ readonly agentComplete: EventSubjectDef<TNamespace>;
1153
+ /** Connector-level error event — payload is shared across adapters. */
1154
+ readonly error: EventSubjectDef<TNamespace>;
1155
+ }
1156
+ /**
1157
+ * Abstract base class for stream-based AI adapter agents.
1158
+ *
1159
+ * Captures the shared event-wiring logic between the Anthropic SDK and
1160
+ * OpenAI Node agent implementations. Both agents follow an identical two-tier
1161
+ * fan-out pattern:
1162
+ *
1163
+ * 1. `wireSdkEvents()` routes the sdk.event catch-all to typed semantic subjects
1164
+ * (adapter-specific — kept abstract to avoid complex generics with `createConnectorEventMapping`).
1165
+ * 2. `wireSemanticEvents()` wires semantic subjects to global `agent.*` subjects
1166
+ * (shared — implemented here; delegates adapter-specific parts to abstract hooks).
1167
+ *
1168
+ * Abstract hooks that subclasses must implement:
1169
+ * - `wireSdkEvents()` — routes sdk.event to semantic subjects (adapter-specific).
1170
+ * - `getConnectorSubjects()` — returns the semantic subject spec for this adapter.
1171
+ * - `extractChunkText(payload)` — extracts text from adapter-specific chunk events.
1172
+ * - `extractUsagePayload(payload)` — maps adapter-specific usage to `NormalizedCallUsage`.
1173
+ * - `emitUsageContextWindowUpdate(payload)` — emits context window status after usage tracking.
1174
+ * - `reserveToolCallBlockIndex(tc)` — assigns block index for a tool call.
1175
+ * - `afterToolCallStepEmitted(blockIndex)` — post-emission book-keeping for tool_calls.
1176
+ * - `getFallbackToolCompletedBlockIndex()` — fallback index when map lookup misses.
1177
+ * - `afterToolCompletedStepEmitted(resolvedBlockIndex)` — post-emission book-keeping for tool_completed.
1178
+ * - `buildReasoningBlock(payload)` — constructs the reasoning `SessionMessageBlock`.
1179
+ * - `wireToolApprovalRpc(connector)` — wires the adapter's tool_approval RPC to the global bus.
1180
+ * @typeParam TBus - Scoped bus for the adapter namespace
1181
+ * @typeParam TConnector - Concrete connector type extending `AIAgentConnector<TBus>`
1182
+ * @typeParam TSpec - Subject spec whose namespace matches `ConnectorNamespace<TConnector>`
1183
+ */
1184
+ declare abstract class BaseStreamAgent<TBus extends ScopedBus<string>, TConnector extends AIAgentConnector<TBus>, TSpec extends StreamAdapterSubjectSpec<ConnectorNamespace<TConnector>>> extends AIAgent<TBus, TConnector> {
1185
+ /**
1186
+ * Track toolCallId → blockIndex for correlation between step.started and step.finished.
1187
+ *
1188
+ * Both adapters emit parallel tool calls (all at once in the tool_calls event),
1189
+ * but results arrive asynchronously in separate tool_completed events, potentially
1190
+ * out of order. This map ensures each tool's step.finished uses the same blockIndex
1191
+ * as its step.started, maintaining correlation regardless of arrival order.
1192
+ *
1193
+ * Pattern:
1194
+ * 1. tool_calls event: reserve blockIndex per toolCallId, store in map
1195
+ * 2. tool_completed event: lookup stored blockIndex, emit step.finished, delete from map
1196
+ */
1197
+ protected toolBlockIndexMap: Map<string, number>;
1198
+ /**
1199
+ * Track tool call IDs whose completion already arrived.
1200
+ *
1201
+ * Some providers can deliver `tool_completed` before `tool_calls` under
1202
+ * race conditions. Mark completed IDs so late `tool_calls` can be ignored
1203
+ * instead of emitting out-of-order step.started/tool.use events.
1204
+ */
1205
+ protected completedToolIds: Set<string>;
1206
+ /**
1207
+ * Stash tool call args keyed by toolCallId.
1208
+ *
1209
+ * Args are available when `tool_calls` fires (parsed from function arguments)
1210
+ * but must be forwarded to `tool_completed` which arrives separately.
1211
+ * Entries are removed after emission to prevent unbounded growth.
1212
+ */
1213
+ protected toolCallArgsMap: Map<string, ToolCallArgs>;
1214
+ private resetPerTurnToolTracking;
1215
+ /**
1216
+ * Tier 1: Route sdk.event catch-all to typed semantic subjects.
1217
+ *
1218
+ * Implement by calling `this.createConnectorEventMapping(connectorSubjects.sdk.event, 'eventType', { ... }, 'event')`
1219
+ * using the adapter's own typed connector subjects. This is kept adapter-specific to avoid
1220
+ * complex generic type constraints when calling `createConnectorEventMapping` from a generic context.
1221
+ */
1222
+ protected abstract wireSdkEvents(): void;
1223
+ /**
1224
+ * Return the semantic subject spec for this adapter's connector namespace.
1225
+ *
1226
+ * Called once during `wireEvents()`. The returned subjects are used to subscribe
1227
+ * to connector events and emit to global `agent.*` subjects.
1228
+ * @returns Subject spec for this adapter's connector namespace
1229
+ */
1230
+ protected abstract getConnectorSubjects(): TSpec;
1231
+ /**
1232
+ * Extract plain text from an adapter-specific chunk event payload.
1233
+ *
1234
+ * - Anthropic: checks `delta.type === 'text_delta'` and returns `delta.text`
1235
+ * - OpenAI: returns `choices[0]?.delta?.content ?? ''`
1236
+ * @param payload - Raw chunk event payload (cast from the connector's chunk event type)
1237
+ * @returns Plain text string, or empty string when the chunk carries no text content
1238
+ */
1239
+ protected abstract extractChunkText(payload: Record<string, unknown>): string;
1240
+ /**
1241
+ * Map an adapter-specific usage event payload to the shared `NormalizedCallUsage` format.
1242
+ *
1243
+ * - Anthropic: reads `cache_read_input_tokens`, `cache_creation_input_tokens`
1244
+ * - OpenAI: reads `prompt_tokens_details.cached_tokens`, `completion_tokens_details.reasoning_tokens`
1245
+ * @param payload - Raw usage event payload (cast from the connector's usage event type)
1246
+ * @returns Normalized usage metrics ready for `trackUsage()`
1247
+ */
1248
+ protected abstract extractUsagePayload(payload: Record<string, unknown>): NormalizedCallUsage;
1249
+ /**
1250
+ * Emit the context window update after processing a usage event.
1251
+ *
1252
+ * Adapters differ in which fields provide the cached token count and the default
1253
+ * max context window size. Called from `wireUsageEvents` after `trackUsage()`.
1254
+ * @param payload - Raw usage event payload (same object passed to `extractUsagePayload`)
1255
+ */
1256
+ protected abstract emitUsageContextWindowUpdate(payload: Record<string, unknown>): Promise<void>;
1257
+ /**
1258
+ * Reserve a block index for a tool call from the tool_calls event.
1259
+ *
1260
+ * - Anthropic: returns `(tc as AnthropicToolCall).blockIndex` (provider-native; no counter mutation).
1261
+ * - OpenAI: returns `this.getBlockIndex()` and increments the internal counter.
1262
+ *
1263
+ * Called once per tool call in `wireToolEvents` before emitting step.started.
1264
+ * @param tc - The tool call entry from the tool_calls event payload
1265
+ * @returns The block index to use for this tool call's step.started / step.finished pair
1266
+ */
1267
+ protected abstract reserveToolCallBlockIndex(tc: ToolCall): number;
1268
+ /**
1269
+ * Perform adapter-specific book-keeping after a tool call's step.started has been emitted.
1270
+ *
1271
+ * - Anthropic: calls `reconcileInternalBlockIndex(blockIndex)` to keep the internal
1272
+ * block index counter in sync with provider-native indices.
1273
+ * - OpenAI: no-op (the counter was already incremented inside `reserveToolCallBlockIndex`).
1274
+ * @param blockIndex - The block index that was just emitted for this tool call
1275
+ */
1276
+ protected abstract afterToolCallStepEmitted(blockIndex: number): void;
1277
+ /**
1278
+ * Return the fallback block index when `toolBlockIndexMap` has no entry for a toolCallId.
1279
+ *
1280
+ * Used only when a tool_completed event arrives without a matching tool_calls entry
1281
+ * (out-of-order delivery or state mismatch).
1282
+ *
1283
+ * - Anthropic: `this.getBlockIndex()` (also increments the internal counter for monotonicity)
1284
+ * - OpenAI: `-1` (sentinel indicating unknown index)
1285
+ * @returns Fallback block index for unresolvable toolCallId map lookups
1286
+ */
1287
+ protected abstract getFallbackToolCompletedBlockIndex(): number;
1288
+ /**
1289
+ * Perform adapter-specific book-keeping after a tool_completed step.finished has been emitted.
1290
+ *
1291
+ * - Anthropic: calls `reconcileInternalBlockIndex(resolvedBlockIndex)`.
1292
+ * - OpenAI: no-op.
1293
+ * @param resolvedBlockIndex - The block index used for this tool's step.finished
1294
+ */
1295
+ protected abstract afterToolCompletedStepEmitted(resolvedBlockIndex: number): void;
1296
+ /**
1297
+ * Build the `SessionMessageBlock` for a reasoning step from the reasoning_complete payload.
1298
+ *
1299
+ * - Anthropic: `{ type: 'reasoning', content, metadata: { signature } }` when `signature` is set
1300
+ * - OpenAI: `{ type: 'reasoning', content }` (no metadata)
1301
+ * @param payload - Raw reasoning complete event payload (cast from the connector's event type)
1302
+ * @returns A reasoning block suitable for `emitStepFinished`
1303
+ */
1304
+ protected abstract buildReasoningBlock(payload: Record<string, unknown>): SessionMessageBlock;
1305
+ /**
1306
+ * Register the tool approval RPC handler for this adapter's connector.
1307
+ *
1308
+ * Wires the adapter-scoped `tool_approval` subject to the global
1309
+ * `AgentSubjects.toolApprove` via the adapter-specific `registerToolApprovalHandler`
1310
+ * factory (generated by `createToolApprovalHandler`). Called during `wireEvents()`.
1311
+ * @param connector - The adapter connector to register the tool approval handler on
1312
+ */
1313
+ protected abstract wireToolApprovalRpc(connector: TConnector): void;
1314
+ /**
1315
+ * Wire connector events to global agent.* subjects.
1316
+ *
1317
+ * Entry point called by `AIAgent.init()` after connector creation.
1318
+ * Follows a two-tier fan-out pattern:
1319
+ * 1. `wireSdkEvents()` — abstract, routes sdk.event to typed semantic subjects.
1320
+ * 2. `wireSemanticEvents()` — shared, wires semantic subjects to global agent.* subjects.
1321
+ * @param connector - The adapter connector to wire events from
1322
+ */
1323
+ protected wireEvents(connector: TConnector): void;
1324
+ /**
1325
+ * Wire semantic subjects to global agent.* subjects.
1326
+ *
1327
+ * Delegates to individual wire methods grouped by event category.
1328
+ * @param connector - The adapter connector to subscribe on
1329
+ * @param subjects - The adapter's connector subjects from `getConnectorSubjects()`
1330
+ */
1331
+ private wireSemanticEvents;
1332
+ /**
1333
+ * Wire message streaming and completion events.
1334
+ *
1335
+ * - `chunk` → `agent.message_delta` (adapter-specific text via `extractChunkText`)
1336
+ * - `message_complete` → `agent.message` + step.started/step.finished for text content
1337
+ * @param connector - The adapter connector to subscribe on
1338
+ * @param subjects - The adapter's connector subjects
1339
+ */
1340
+ private wireMessageEvents;
1341
+ /**
1342
+ * Wire token usage tracking events.
1343
+ *
1344
+ * Delegates payload parsing to `extractUsagePayload` and context window emission
1345
+ * to `emitUsageContextWindowUpdate` (both adapter-specific).
1346
+ * @param connector - The adapter connector to subscribe on
1347
+ * @param subjects - The adapter's connector subjects
1348
+ */
1349
+ private wireUsageEvents;
1350
+ /**
1351
+ * Wire tool lifecycle events (tool_calls, tool_started, tool_completed).
1352
+ *
1353
+ * - `tool_calls` → per-tool `agent.step.started` + `agent.tool.use`
1354
+ * - `tool_started` → `agent.tool.started`
1355
+ * - `tool_completed` → `agent.step.finished` + `agent.tool.completed`
1356
+ * @param connector - The adapter connector to subscribe on
1357
+ * @param subjects - The adapter's connector subjects
1358
+ */
1359
+ private wireToolEvents;
1360
+ /**
1361
+ * Wire reasoning streaming and completion events.
1362
+ *
1363
+ * - `reasoning_delta` → `agent.reasoning_delta`
1364
+ * - `reasoning_complete` → `agent.reasoning` + step.started/step.finished
1365
+ * @param connector - The adapter connector to subscribe on
1366
+ * @param subjects - The adapter's connector subjects
1367
+ */
1368
+ private wireReasoningEvents;
1369
+ /**
1370
+ * Wire agent lifecycle events (agent_started, agent_complete, error).
1371
+ *
1372
+ * - `agent_started` → clears per-turn tool tracking and calls `emitStart()`
1373
+ * - `agent_complete` → clears per-turn tool tracking
1374
+ * - `error` → calls `emitError()` to stash error metadata for next `emitCompletion`
1375
+ *
1376
+ * Note: `agent_complete` emission is handled by `AIAgent` via `onMessageHandle()`
1377
+ * when the connector calls `markCompleted()`. We subscribe only for state reset.
1378
+ * @param connector - The adapter connector to subscribe on
1379
+ * @param subjects - The adapter's connector subjects
1380
+ */
1381
+ private wireLifecycleEvents;
1382
+ }
1383
+ //#endregion
1384
+ export { type AgentCompleteEvent, AgentCompleteEventSchema, type AgentStartedEvent, AgentStartedEventSchema, type BaseSessionEmitEvent, BaseStreamAgent, BaseStreamConnector, type BaseStreamConnectorConfig, BaseStreamSession, type ErrorEvent, ErrorEventSchema, type HandleToolCallsCallbacks, MAX_TOOL_RESULT_CONTENT_CHARS, type MessageCompleteEvent, MessageCompleteEventSchema, type MessageToolCall, MessageToolCallSchema, type ReasoningCompleteEvent, ReasoningCompleteEventSchema, type ReasoningDeltaEvent, ReasoningDeltaEventSchema, type StreamAdapterSubjectSpec, type StreamConnectorSession, type StreamSdkEventEnvelope, type StreamSessionConfig, type StreamSessionTurnState, StreamSessionTurnStateSchema, type ToolCall, type ToolCallFunction, ToolCallFunctionSchema, type ToolCallPayload, ToolCallSchema, type ToolCallsEvent, ToolCallsEventSchema, type ToolCompletedEvent, ToolCompletedEventSchema, type ToolExecutionContextOverrides, type ToolLifecycleEmitter, type ToolResultBuilder, type ToolStartedEvent, ToolStartedEventSchema, type TurnStateChanged, TurnStateChangedSchema, applyApprovedArgs, boundToolResultContent, executeTool, extractToolCallPayload, filterToolsWithSchema, handleToolCalls, loadToolsFromRegistry, toGlobalToolApproval };