@agentick/core 0.0.1

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 (626) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +875 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/.tsbuildinfo.build +1 -0
  5. package/dist/agent.d.ts +32 -0
  6. package/dist/agent.d.ts.map +1 -0
  7. package/dist/agent.js +26 -0
  8. package/dist/agent.js.map +1 -0
  9. package/dist/agentick-instance.d.ts +285 -0
  10. package/dist/agentick-instance.d.ts.map +1 -0
  11. package/dist/agentick-instance.js +700 -0
  12. package/dist/agentick-instance.js.map +1 -0
  13. package/dist/aidk-instance.d.ts +294 -0
  14. package/dist/aidk-instance.d.ts.map +1 -0
  15. package/dist/aidk-instance.js +340 -0
  16. package/dist/aidk-instance.js.map +1 -0
  17. package/dist/app/session-store.d.ts +57 -0
  18. package/dist/app/session-store.d.ts.map +1 -0
  19. package/dist/app/session-store.js +87 -0
  20. package/dist/app/session-store.js.map +1 -0
  21. package/dist/app/session.d.ts +209 -0
  22. package/dist/app/session.d.ts.map +1 -0
  23. package/dist/app/session.js +2131 -0
  24. package/dist/app/session.js.map +1 -0
  25. package/dist/app/sqlite-session-store.d.ts +60 -0
  26. package/dist/app/sqlite-session-store.d.ts.map +1 -0
  27. package/dist/app/sqlite-session-store.js +234 -0
  28. package/dist/app/sqlite-session-store.js.map +1 -0
  29. package/dist/app/types.d.ts +1461 -0
  30. package/dist/app/types.d.ts.map +1 -0
  31. package/dist/app/types.js +14 -0
  32. package/dist/app/types.js.map +1 -0
  33. package/dist/app.d.ts +79 -0
  34. package/dist/app.d.ts.map +1 -0
  35. package/dist/app.js +83 -0
  36. package/dist/app.js.map +1 -0
  37. package/dist/channels/adapters/index.d.ts +2 -0
  38. package/dist/channels/adapters/index.d.ts.map +1 -0
  39. package/dist/channels/adapters/index.js +2 -0
  40. package/dist/channels/adapters/index.js.map +1 -0
  41. package/dist/channels/adapters/redis.d.ts +77 -0
  42. package/dist/channels/adapters/redis.d.ts.map +1 -0
  43. package/dist/channels/adapters/redis.js +259 -0
  44. package/dist/channels/adapters/redis.js.map +1 -0
  45. package/dist/channels/index.d.ts +38 -0
  46. package/dist/channels/index.d.ts.map +1 -0
  47. package/dist/channels/index.js +38 -0
  48. package/dist/channels/index.js.map +1 -0
  49. package/dist/channels/service.d.ts +684 -0
  50. package/dist/channels/service.d.ts.map +1 -0
  51. package/dist/channels/service.js +870 -0
  52. package/dist/channels/service.js.map +1 -0
  53. package/dist/channels/transports/index.d.ts +4 -0
  54. package/dist/channels/transports/index.d.ts.map +1 -0
  55. package/dist/channels/transports/index.js +4 -0
  56. package/dist/channels/transports/index.js.map +1 -0
  57. package/dist/channels/transports/socketio.d.ts +98 -0
  58. package/dist/channels/transports/socketio.d.ts.map +1 -0
  59. package/dist/channels/transports/socketio.js +246 -0
  60. package/dist/channels/transports/socketio.js.map +1 -0
  61. package/dist/channels/transports/streamable-http.d.ts +107 -0
  62. package/dist/channels/transports/streamable-http.d.ts.map +1 -0
  63. package/dist/channels/transports/streamable-http.js +353 -0
  64. package/dist/channels/transports/streamable-http.js.map +1 -0
  65. package/dist/channels/transports/websocket.d.ts +117 -0
  66. package/dist/channels/transports/websocket.d.ts.map +1 -0
  67. package/dist/channels/transports/websocket.js +416 -0
  68. package/dist/channels/transports/websocket.js.map +1 -0
  69. package/dist/com/index.d.ts +29 -0
  70. package/dist/com/index.d.ts.map +1 -0
  71. package/dist/com/index.js +29 -0
  72. package/dist/com/index.js.map +1 -0
  73. package/dist/com/object-model.d.ts +634 -0
  74. package/dist/com/object-model.d.ts.map +1 -0
  75. package/dist/com/object-model.js +963 -0
  76. package/dist/com/object-model.js.map +1 -0
  77. package/dist/com/types.d.ts +192 -0
  78. package/dist/com/types.d.ts.map +1 -0
  79. package/dist/com/types.js +1 -0
  80. package/dist/com/types.js.map +1 -0
  81. package/dist/compiler/collector.d.ts +16 -0
  82. package/dist/compiler/collector.d.ts.map +1 -0
  83. package/dist/compiler/collector.js +388 -0
  84. package/dist/compiler/collector.js.map +1 -0
  85. package/dist/compiler/content-block-registry.d.ts +11 -0
  86. package/dist/compiler/content-block-registry.d.ts.map +1 -0
  87. package/dist/compiler/content-block-registry.js +312 -0
  88. package/dist/compiler/content-block-registry.js.map +1 -0
  89. package/dist/compiler/extractors.d.ts +68 -0
  90. package/dist/compiler/extractors.d.ts.map +1 -0
  91. package/dist/compiler/extractors.js +547 -0
  92. package/dist/compiler/extractors.js.map +1 -0
  93. package/dist/compiler/fiber-compiler.d.ts +203 -0
  94. package/dist/compiler/fiber-compiler.d.ts.map +1 -0
  95. package/dist/compiler/fiber-compiler.js +498 -0
  96. package/dist/compiler/fiber-compiler.js.map +1 -0
  97. package/dist/compiler/fiber.d.ts +61 -0
  98. package/dist/compiler/fiber.d.ts.map +1 -0
  99. package/dist/compiler/fiber.js +244 -0
  100. package/dist/compiler/fiber.js.map +1 -0
  101. package/dist/compiler/index.d.ts +18 -0
  102. package/dist/compiler/index.d.ts.map +1 -0
  103. package/dist/compiler/index.js +38 -0
  104. package/dist/compiler/index.js.map +1 -0
  105. package/dist/compiler/scheduler.d.ts +95 -0
  106. package/dist/compiler/scheduler.d.ts.map +1 -0
  107. package/dist/compiler/scheduler.js +138 -0
  108. package/dist/compiler/scheduler.js.map +1 -0
  109. package/dist/compiler/structure-renderer.d.ts +42 -0
  110. package/dist/compiler/structure-renderer.d.ts.map +1 -0
  111. package/dist/compiler/structure-renderer.js +189 -0
  112. package/dist/compiler/structure-renderer.js.map +1 -0
  113. package/dist/compiler/types.d.ts +96 -0
  114. package/dist/compiler/types.d.ts.map +1 -0
  115. package/dist/compiler/types.js +19 -0
  116. package/dist/compiler/types.js.map +1 -0
  117. package/dist/component/component-hooks.d.ts +68 -0
  118. package/dist/component/component-hooks.d.ts.map +1 -0
  119. package/dist/component/component-hooks.js +112 -0
  120. package/dist/component/component-hooks.js.map +1 -0
  121. package/dist/component/component.d.ts +314 -0
  122. package/dist/component/component.d.ts.map +1 -0
  123. package/dist/component/component.js +64 -0
  124. package/dist/component/component.js.map +1 -0
  125. package/dist/component/index.d.ts +47 -0
  126. package/dist/component/index.d.ts.map +1 -0
  127. package/dist/component/index.js +47 -0
  128. package/dist/component/index.js.map +1 -0
  129. package/dist/component/tentickle-component.d.ts +185 -0
  130. package/dist/component/tentickle-component.d.ts.map +1 -0
  131. package/dist/component/tentickle-component.js +182 -0
  132. package/dist/component/tentickle-component.js.map +1 -0
  133. package/dist/content/index.d.ts +12 -0
  134. package/dist/content/index.d.ts.map +1 -0
  135. package/dist/content/index.js +17 -0
  136. package/dist/content/index.js.map +1 -0
  137. package/dist/context/index.d.ts +51 -0
  138. package/dist/context/index.d.ts.map +1 -0
  139. package/dist/context/index.js +69 -0
  140. package/dist/context/index.js.map +1 -0
  141. package/dist/core/channel-helpers.d.ts +31 -0
  142. package/dist/core/channel-helpers.d.ts.map +1 -0
  143. package/dist/core/channel-helpers.js +62 -0
  144. package/dist/core/channel-helpers.js.map +1 -0
  145. package/dist/core/channel.d.ts +164 -0
  146. package/dist/core/channel.d.ts.map +1 -0
  147. package/dist/core/channel.js +199 -0
  148. package/dist/core/channel.js.map +1 -0
  149. package/dist/core/context.d.ts +412 -0
  150. package/dist/core/context.d.ts.map +1 -0
  151. package/dist/core/context.js +290 -0
  152. package/dist/core/context.js.map +1 -0
  153. package/dist/core/event-buffer.d.ts +212 -0
  154. package/dist/core/event-buffer.d.ts.map +1 -0
  155. package/dist/core/event-buffer.js +346 -0
  156. package/dist/core/event-buffer.js.map +1 -0
  157. package/dist/core/execution-helpers.d.ts +179 -0
  158. package/dist/core/execution-helpers.d.ts.map +1 -0
  159. package/dist/core/execution-helpers.js +212 -0
  160. package/dist/core/execution-helpers.js.map +1 -0
  161. package/dist/core/execution-tracker.d.ts +53 -0
  162. package/dist/core/execution-tracker.d.ts.map +1 -0
  163. package/dist/core/execution-tracker.js +309 -0
  164. package/dist/core/execution-tracker.js.map +1 -0
  165. package/dist/core/index.d.ts +58 -0
  166. package/dist/core/index.d.ts.map +1 -0
  167. package/dist/core/index.js +58 -0
  168. package/dist/core/index.js.map +1 -0
  169. package/dist/core/logger.d.ts +341 -0
  170. package/dist/core/logger.d.ts.map +1 -0
  171. package/dist/core/logger.js +346 -0
  172. package/dist/core/logger.js.map +1 -0
  173. package/dist/core/metrics-helpers.d.ts +40 -0
  174. package/dist/core/metrics-helpers.d.ts.map +1 -0
  175. package/dist/core/metrics-helpers.js +72 -0
  176. package/dist/core/metrics-helpers.js.map +1 -0
  177. package/dist/core/otel-provider.d.ts +54 -0
  178. package/dist/core/otel-provider.d.ts.map +1 -0
  179. package/dist/core/otel-provider.js +107 -0
  180. package/dist/core/otel-provider.js.map +1 -0
  181. package/dist/core/procedure-graph.d.ts +136 -0
  182. package/dist/core/procedure-graph.d.ts.map +1 -0
  183. package/dist/core/procedure-graph.js +272 -0
  184. package/dist/core/procedure-graph.js.map +1 -0
  185. package/dist/core/procedure.d.ts +755 -0
  186. package/dist/core/procedure.d.ts.map +1 -0
  187. package/dist/core/procedure.js +899 -0
  188. package/dist/core/procedure.js.map +1 -0
  189. package/dist/core/stream.d.ts +106 -0
  190. package/dist/core/stream.d.ts.map +1 -0
  191. package/dist/core/stream.js +186 -0
  192. package/dist/core/stream.js.map +1 -0
  193. package/dist/core/telemetry.d.ts +182 -0
  194. package/dist/core/telemetry.d.ts.map +1 -0
  195. package/dist/core/telemetry.js +124 -0
  196. package/dist/core/telemetry.js.map +1 -0
  197. package/dist/engine/client-tool-coordinator.d.ts +50 -0
  198. package/dist/engine/client-tool-coordinator.d.ts.map +1 -0
  199. package/dist/engine/client-tool-coordinator.js +121 -0
  200. package/dist/engine/client-tool-coordinator.js.map +1 -0
  201. package/dist/engine/engine-events.d.ts +117 -0
  202. package/dist/engine/engine-events.d.ts.map +1 -0
  203. package/dist/engine/engine-events.js +178 -0
  204. package/dist/engine/engine-events.js.map +1 -0
  205. package/dist/engine/engine-response.d.ts +48 -0
  206. package/dist/engine/engine-response.d.ts.map +1 -0
  207. package/dist/engine/engine-response.js +2 -0
  208. package/dist/engine/engine-response.js.map +1 -0
  209. package/dist/engine/execution-graph.d.ts +104 -0
  210. package/dist/engine/execution-graph.d.ts.map +1 -0
  211. package/dist/engine/execution-graph.js +257 -0
  212. package/dist/engine/execution-graph.js.map +1 -0
  213. package/dist/engine/execution-handle.d.ts +212 -0
  214. package/dist/engine/execution-handle.d.ts.map +1 -0
  215. package/dist/engine/execution-handle.js +602 -0
  216. package/dist/engine/execution-handle.js.map +1 -0
  217. package/dist/engine/execution-types.d.ts +248 -0
  218. package/dist/engine/execution-types.d.ts.map +1 -0
  219. package/dist/engine/execution-types.js +23 -0
  220. package/dist/engine/execution-types.js.map +1 -0
  221. package/dist/engine/index.d.ts +21 -0
  222. package/dist/engine/index.d.ts.map +1 -0
  223. package/dist/engine/index.js +23 -0
  224. package/dist/engine/index.js.map +1 -0
  225. package/dist/engine/tool-confirmation-coordinator.d.ts +74 -0
  226. package/dist/engine/tool-confirmation-coordinator.d.ts.map +1 -0
  227. package/dist/engine/tool-confirmation-coordinator.js +137 -0
  228. package/dist/engine/tool-confirmation-coordinator.js.map +1 -0
  229. package/dist/engine/tool-executor.d.ts +127 -0
  230. package/dist/engine/tool-executor.d.ts.map +1 -0
  231. package/dist/engine/tool-executor.js +363 -0
  232. package/dist/engine/tool-executor.js.map +1 -0
  233. package/dist/hibernation/index.d.ts +126 -0
  234. package/dist/hibernation/index.d.ts.map +1 -0
  235. package/dist/hibernation/index.js +127 -0
  236. package/dist/hibernation/index.js.map +1 -0
  237. package/dist/hooks/base-hook-registry.d.ts +41 -0
  238. package/dist/hooks/base-hook-registry.d.ts.map +1 -0
  239. package/dist/hooks/base-hook-registry.js +76 -0
  240. package/dist/hooks/base-hook-registry.js.map +1 -0
  241. package/dist/hooks/com-state.d.ts +40 -0
  242. package/dist/hooks/com-state.d.ts.map +1 -0
  243. package/dist/hooks/com-state.js +90 -0
  244. package/dist/hooks/com-state.js.map +1 -0
  245. package/dist/hooks/context-info.d.ts +139 -0
  246. package/dist/hooks/context-info.d.ts.map +1 -0
  247. package/dist/hooks/context-info.js +115 -0
  248. package/dist/hooks/context-info.js.map +1 -0
  249. package/dist/hooks/context-internal.d.ts +21 -0
  250. package/dist/hooks/context-internal.d.ts.map +1 -0
  251. package/dist/hooks/context-internal.js +20 -0
  252. package/dist/hooks/context-internal.js.map +1 -0
  253. package/dist/hooks/context.d.ts +64 -0
  254. package/dist/hooks/context.d.ts.map +1 -0
  255. package/dist/hooks/context.js +83 -0
  256. package/dist/hooks/context.js.map +1 -0
  257. package/dist/hooks/data.d.ts +33 -0
  258. package/dist/hooks/data.d.ts.map +1 -0
  259. package/dist/hooks/data.js +84 -0
  260. package/dist/hooks/data.js.map +1 -0
  261. package/dist/hooks/formatter-context.d.ts +34 -0
  262. package/dist/hooks/formatter-context.d.ts.map +1 -0
  263. package/dist/hooks/formatter-context.js +34 -0
  264. package/dist/hooks/formatter-context.js.map +1 -0
  265. package/dist/hooks/hook-registry.d.ts +45 -0
  266. package/dist/hooks/hook-registry.d.ts.map +1 -0
  267. package/dist/hooks/hook-registry.js +109 -0
  268. package/dist/hooks/hook-registry.js.map +1 -0
  269. package/dist/hooks/index.d.ts +20 -0
  270. package/dist/hooks/index.d.ts.map +1 -0
  271. package/dist/hooks/index.js +47 -0
  272. package/dist/hooks/index.js.map +1 -0
  273. package/dist/hooks/knob.d.ts +87 -0
  274. package/dist/hooks/knob.d.ts.map +1 -0
  275. package/dist/hooks/knob.js +129 -0
  276. package/dist/hooks/knob.js.map +1 -0
  277. package/dist/hooks/knobs-component.d.ts +70 -0
  278. package/dist/hooks/knobs-component.d.ts.map +1 -0
  279. package/dist/hooks/knobs-component.js +300 -0
  280. package/dist/hooks/knobs-component.js.map +1 -0
  281. package/dist/hooks/lifecycle.d.ts +158 -0
  282. package/dist/hooks/lifecycle.d.ts.map +1 -0
  283. package/dist/hooks/lifecycle.js +217 -0
  284. package/dist/hooks/lifecycle.js.map +1 -0
  285. package/dist/hooks/message-context.d.ts +101 -0
  286. package/dist/hooks/message-context.d.ts.map +1 -0
  287. package/dist/hooks/message-context.js +145 -0
  288. package/dist/hooks/message-context.js.map +1 -0
  289. package/dist/hooks/policy-context.d.ts.map +1 -0
  290. package/dist/hooks/runtime-context.d.ts +122 -0
  291. package/dist/hooks/runtime-context.d.ts.map +1 -0
  292. package/dist/hooks/runtime-context.js +149 -0
  293. package/dist/hooks/runtime-context.js.map +1 -0
  294. package/dist/hooks/signal.d.ts +267 -0
  295. package/dist/hooks/signal.d.ts.map +1 -0
  296. package/dist/hooks/signal.js +825 -0
  297. package/dist/hooks/signal.js.map +1 -0
  298. package/dist/hooks/types.d.ts +179 -0
  299. package/dist/hooks/types.d.ts.map +1 -0
  300. package/dist/hooks/types.js +5 -0
  301. package/dist/hooks/types.js.map +1 -0
  302. package/dist/index.d.ts +20 -0
  303. package/dist/index.d.ts.map +1 -0
  304. package/dist/index.js +50 -0
  305. package/dist/index.js.map +1 -0
  306. package/dist/jsx/components/agent.d.ts +64 -0
  307. package/dist/jsx/components/agent.d.ts.map +1 -0
  308. package/dist/jsx/components/agent.js +80 -0
  309. package/dist/jsx/components/agent.js.map +1 -0
  310. package/dist/jsx/components/complete.d.ts +65 -0
  311. package/dist/jsx/components/complete.d.ts.map +1 -0
  312. package/dist/jsx/components/complete.js +64 -0
  313. package/dist/jsx/components/complete.js.map +1 -0
  314. package/dist/jsx/components/content.d.ts +98 -0
  315. package/dist/jsx/components/content.d.ts.map +1 -0
  316. package/dist/jsx/components/content.js +51 -0
  317. package/dist/jsx/components/content.js.map +1 -0
  318. package/dist/jsx/components/harness.d.ts +118 -0
  319. package/dist/jsx/components/harness.d.ts.map +1 -0
  320. package/dist/jsx/components/harness.js +117 -0
  321. package/dist/jsx/components/harness.js.map +1 -0
  322. package/dist/jsx/components/index.d.ts +11 -0
  323. package/dist/jsx/components/index.d.ts.map +1 -0
  324. package/dist/jsx/components/index.js +11 -0
  325. package/dist/jsx/components/index.js.map +1 -0
  326. package/dist/jsx/components/markdown.d.ts +31 -0
  327. package/dist/jsx/components/markdown.d.ts.map +1 -0
  328. package/dist/jsx/components/markdown.js +17 -0
  329. package/dist/jsx/components/markdown.js.map +1 -0
  330. package/dist/jsx/components/messages.d.ts +283 -0
  331. package/dist/jsx/components/messages.d.ts.map +1 -0
  332. package/dist/jsx/components/messages.js +257 -0
  333. package/dist/jsx/components/messages.js.map +1 -0
  334. package/dist/jsx/components/model.d.ts +94 -0
  335. package/dist/jsx/components/model.d.ts.map +1 -0
  336. package/dist/jsx/components/model.js +96 -0
  337. package/dist/jsx/components/model.js.map +1 -0
  338. package/dist/jsx/components/primitives.d.ts +117 -0
  339. package/dist/jsx/components/primitives.d.ts.map +1 -0
  340. package/dist/jsx/components/primitives.js +83 -0
  341. package/dist/jsx/components/primitives.js.map +1 -0
  342. package/dist/jsx/components/renderer.d.ts +24 -0
  343. package/dist/jsx/components/renderer.d.ts.map +1 -0
  344. package/dist/jsx/components/renderer.js +11 -0
  345. package/dist/jsx/components/renderer.js.map +1 -0
  346. package/dist/jsx/components/semantic.d.ts +155 -0
  347. package/dist/jsx/components/semantic.d.ts.map +1 -0
  348. package/dist/jsx/components/semantic.js +39 -0
  349. package/dist/jsx/components/semantic.js.map +1 -0
  350. package/dist/jsx/components/timeline.d.ts +157 -0
  351. package/dist/jsx/components/timeline.d.ts.map +1 -0
  352. package/dist/jsx/components/timeline.js +357 -0
  353. package/dist/jsx/components/timeline.js.map +1 -0
  354. package/dist/jsx/components/token-budget.d.ts +70 -0
  355. package/dist/jsx/components/token-budget.d.ts.map +1 -0
  356. package/dist/jsx/components/token-budget.js +135 -0
  357. package/dist/jsx/components/token-budget.js.map +1 -0
  358. package/dist/jsx/components/xml.d.ts +27 -0
  359. package/dist/jsx/components/xml.d.ts.map +1 -0
  360. package/dist/jsx/components/xml.js +17 -0
  361. package/dist/jsx/components/xml.js.map +1 -0
  362. package/dist/jsx/index.d.ts +58 -0
  363. package/dist/jsx/index.d.ts.map +1 -0
  364. package/dist/jsx/index.js +59 -0
  365. package/dist/jsx/index.js.map +1 -0
  366. package/dist/jsx/jsx-runtime.d.ts +370 -0
  367. package/dist/jsx/jsx-runtime.d.ts.map +1 -0
  368. package/dist/jsx/jsx-runtime.js +79 -0
  369. package/dist/jsx/jsx-runtime.js.map +1 -0
  370. package/dist/jsx/jsx-types.d.ts +23 -0
  371. package/dist/jsx/jsx-types.d.ts.map +1 -0
  372. package/dist/jsx/jsx-types.js +1 -0
  373. package/dist/jsx/jsx-types.js.map +1 -0
  374. package/dist/mcp/client.d.ts +46 -0
  375. package/dist/mcp/client.d.ts.map +1 -0
  376. package/dist/mcp/client.js +138 -0
  377. package/dist/mcp/client.js.map +1 -0
  378. package/dist/mcp/component.d.ts +95 -0
  379. package/dist/mcp/component.d.ts.map +1 -0
  380. package/dist/mcp/component.js +185 -0
  381. package/dist/mcp/component.js.map +1 -0
  382. package/dist/mcp/create-mcp-tool.d.ts +191 -0
  383. package/dist/mcp/create-mcp-tool.d.ts.map +1 -0
  384. package/dist/mcp/create-mcp-tool.js +228 -0
  385. package/dist/mcp/create-mcp-tool.js.map +1 -0
  386. package/dist/mcp/index.d.ts +49 -0
  387. package/dist/mcp/index.d.ts.map +1 -0
  388. package/dist/mcp/index.js +48 -0
  389. package/dist/mcp/index.js.map +1 -0
  390. package/dist/mcp/service.d.ts +39 -0
  391. package/dist/mcp/service.d.ts.map +1 -0
  392. package/dist/mcp/service.js +77 -0
  393. package/dist/mcp/service.js.map +1 -0
  394. package/dist/mcp/tool.d.ts +55 -0
  395. package/dist/mcp/tool.d.ts.map +1 -0
  396. package/dist/mcp/tool.js +119 -0
  397. package/dist/mcp/tool.js.map +1 -0
  398. package/dist/mcp/types.d.ts +72 -0
  399. package/dist/mcp/types.d.ts.map +1 -0
  400. package/dist/mcp/types.js +6 -0
  401. package/dist/mcp/types.js.map +1 -0
  402. package/dist/middleware/defaults.d.ts +9 -0
  403. package/dist/middleware/defaults.d.ts.map +1 -0
  404. package/dist/middleware/defaults.js +47 -0
  405. package/dist/middleware/defaults.js.map +1 -0
  406. package/dist/model/adapter-helpers.d.ts +161 -0
  407. package/dist/model/adapter-helpers.d.ts.map +1 -0
  408. package/dist/model/adapter-helpers.js +351 -0
  409. package/dist/model/adapter-helpers.js.map +1 -0
  410. package/dist/model/adapter.d.ts +399 -0
  411. package/dist/model/adapter.d.ts.map +1 -0
  412. package/dist/model/adapter.js +497 -0
  413. package/dist/model/adapter.js.map +1 -0
  414. package/dist/model/index.d.ts +54 -0
  415. package/dist/model/index.d.ts.map +1 -0
  416. package/dist/model/index.js +55 -0
  417. package/dist/model/index.js.map +1 -0
  418. package/dist/model/model-hooks.d.ts +45 -0
  419. package/dist/model/model-hooks.d.ts.map +1 -0
  420. package/dist/model/model-hooks.js +24 -0
  421. package/dist/model/model-hooks.js.map +1 -0
  422. package/dist/model/model.d.ts +302 -0
  423. package/dist/model/model.d.ts.map +1 -0
  424. package/dist/model/model.js +20 -0
  425. package/dist/model/model.js.map +1 -0
  426. package/dist/model/simple-adapter.d.ts +176 -0
  427. package/dist/model/simple-adapter.d.ts.map +1 -0
  428. package/dist/model/simple-adapter.js +264 -0
  429. package/dist/model/simple-adapter.js.map +1 -0
  430. package/dist/model/stream-accumulator.d.ts +284 -0
  431. package/dist/model/stream-accumulator.d.ts.map +1 -0
  432. package/dist/model/stream-accumulator.js +532 -0
  433. package/dist/model/stream-accumulator.js.map +1 -0
  434. package/dist/model/utils/index.d.ts +2 -0
  435. package/dist/model/utils/index.d.ts.map +1 -0
  436. package/dist/model/utils/index.js +2 -0
  437. package/dist/model/utils/index.js.map +1 -0
  438. package/dist/model/utils/language-model.d.ts +26 -0
  439. package/dist/model/utils/language-model.d.ts.map +1 -0
  440. package/dist/model/utils/language-model.js +706 -0
  441. package/dist/model/utils/language-model.js.map +1 -0
  442. package/dist/procedure/index.d.ts +20 -0
  443. package/dist/procedure/index.d.ts.map +1 -0
  444. package/dist/procedure/index.js +19 -0
  445. package/dist/procedure/index.js.map +1 -0
  446. package/dist/reconciler/devtools-bridge.d.ts +40 -0
  447. package/dist/reconciler/devtools-bridge.d.ts.map +1 -0
  448. package/dist/reconciler/devtools-bridge.js +79 -0
  449. package/dist/reconciler/devtools-bridge.js.map +1 -0
  450. package/dist/reconciler/host-config.d.ts +39 -0
  451. package/dist/reconciler/host-config.d.ts.map +1 -0
  452. package/dist/reconciler/host-config.js +195 -0
  453. package/dist/reconciler/host-config.js.map +1 -0
  454. package/dist/reconciler/index.d.ts +7 -0
  455. package/dist/reconciler/index.d.ts.map +1 -0
  456. package/dist/reconciler/index.js +7 -0
  457. package/dist/reconciler/index.js.map +1 -0
  458. package/dist/reconciler/reconciler.d.ts +47 -0
  459. package/dist/reconciler/reconciler.d.ts.map +1 -0
  460. package/dist/reconciler/reconciler.js +89 -0
  461. package/dist/reconciler/reconciler.js.map +1 -0
  462. package/dist/reconciler/types.d.ts +86 -0
  463. package/dist/reconciler/types.d.ts.map +1 -0
  464. package/dist/reconciler/types.js +37 -0
  465. package/dist/reconciler/types.js.map +1 -0
  466. package/dist/renderers/base.d.ts +98 -0
  467. package/dist/renderers/base.d.ts.map +1 -0
  468. package/dist/renderers/base.js +82 -0
  469. package/dist/renderers/base.js.map +1 -0
  470. package/dist/renderers/index.d.ts +31 -0
  471. package/dist/renderers/index.d.ts.map +1 -0
  472. package/dist/renderers/index.js +31 -0
  473. package/dist/renderers/index.js.map +1 -0
  474. package/dist/renderers/markdown.d.ts +48 -0
  475. package/dist/renderers/markdown.d.ts.map +1 -0
  476. package/dist/renderers/markdown.js +432 -0
  477. package/dist/renderers/markdown.js.map +1 -0
  478. package/dist/renderers/types.d.ts +7 -0
  479. package/dist/renderers/types.d.ts.map +1 -0
  480. package/dist/renderers/types.js +7 -0
  481. package/dist/renderers/types.js.map +1 -0
  482. package/dist/renderers/xml.d.ts +49 -0
  483. package/dist/renderers/xml.d.ts.map +1 -0
  484. package/dist/renderers/xml.js +444 -0
  485. package/dist/renderers/xml.js.map +1 -0
  486. package/dist/state/boundary.d.ts +347 -0
  487. package/dist/state/boundary.d.ts.map +1 -0
  488. package/dist/state/boundary.js +341 -0
  489. package/dist/state/boundary.js.map +1 -0
  490. package/dist/state/context.d.ts +138 -0
  491. package/dist/state/context.d.ts.map +1 -0
  492. package/dist/state/context.js +139 -0
  493. package/dist/state/context.js.map +1 -0
  494. package/dist/state/hooks.d.ts +798 -0
  495. package/dist/state/hooks.d.ts.map +1 -0
  496. package/dist/state/hooks.js +1437 -0
  497. package/dist/state/hooks.js.map +1 -0
  498. package/dist/state/index.d.ts +72 -0
  499. package/dist/state/index.d.ts.map +1 -0
  500. package/dist/state/index.js +73 -0
  501. package/dist/state/index.js.map +1 -0
  502. package/dist/state/signal.d.ts +223 -0
  503. package/dist/state/signal.d.ts.map +1 -0
  504. package/dist/state/signal.js +699 -0
  505. package/dist/state/signal.js.map +1 -0
  506. package/dist/state/use-state.d.ts +210 -0
  507. package/dist/state/use-state.d.ts.map +1 -0
  508. package/dist/state/use-state.js +327 -0
  509. package/dist/state/use-state.js.map +1 -0
  510. package/dist/tentickle-instance.d.ts +285 -0
  511. package/dist/tentickle-instance.d.ts.map +1 -0
  512. package/dist/tentickle-instance.js +700 -0
  513. package/dist/tentickle-instance.js.map +1 -0
  514. package/dist/testing/act.d.ts +59 -0
  515. package/dist/testing/act.d.ts.map +1 -0
  516. package/dist/testing/act.js +92 -0
  517. package/dist/testing/act.js.map +1 -0
  518. package/dist/testing/async-helpers.d.ts +99 -0
  519. package/dist/testing/async-helpers.d.ts.map +1 -0
  520. package/dist/testing/async-helpers.js +193 -0
  521. package/dist/testing/async-helpers.js.map +1 -0
  522. package/dist/testing/compile-agent.d.ts +101 -0
  523. package/dist/testing/compile-agent.d.ts.map +1 -0
  524. package/dist/testing/compile-agent.js +136 -0
  525. package/dist/testing/compile-agent.js.map +1 -0
  526. package/dist/testing/index.d.ts +57 -0
  527. package/dist/testing/index.d.ts.map +1 -0
  528. package/dist/testing/index.js +59 -0
  529. package/dist/testing/index.js.map +1 -0
  530. package/dist/testing/mock-app.d.ts +163 -0
  531. package/dist/testing/mock-app.d.ts.map +1 -0
  532. package/dist/testing/mock-app.js +393 -0
  533. package/dist/testing/mock-app.js.map +1 -0
  534. package/dist/testing/mocks.d.ts +142 -0
  535. package/dist/testing/mocks.d.ts.map +1 -0
  536. package/dist/testing/mocks.js +191 -0
  537. package/dist/testing/mocks.js.map +1 -0
  538. package/dist/testing/render-agent.d.ts +146 -0
  539. package/dist/testing/render-agent.d.ts.map +1 -0
  540. package/dist/testing/render-agent.js +200 -0
  541. package/dist/testing/render-agent.js.map +1 -0
  542. package/dist/testing/test-adapter.d.ts +157 -0
  543. package/dist/testing/test-adapter.d.ts.map +1 -0
  544. package/dist/testing/test-adapter.js +297 -0
  545. package/dist/testing/test-adapter.js.map +1 -0
  546. package/dist/testing/test-model.d.ts +132 -0
  547. package/dist/testing/test-model.d.ts.map +1 -0
  548. package/dist/testing/test-model.js +260 -0
  549. package/dist/testing/test-model.js.map +1 -0
  550. package/dist/tool/index.d.ts +61 -0
  551. package/dist/tool/index.d.ts.map +1 -0
  552. package/dist/tool/index.js +63 -0
  553. package/dist/tool/index.js.map +1 -0
  554. package/dist/tool/tool-hooks.d.ts +45 -0
  555. package/dist/tool/tool-hooks.d.ts.map +1 -0
  556. package/dist/tool/tool-hooks.js +35 -0
  557. package/dist/tool/tool-hooks.js.map +1 -0
  558. package/dist/tool/tool.d.ts +403 -0
  559. package/dist/tool/tool.d.ts.map +1 -0
  560. package/dist/tool/tool.js +176 -0
  561. package/dist/tool/tool.js.map +1 -0
  562. package/dist/types.d.ts +442 -0
  563. package/dist/types.d.ts.map +1 -0
  564. package/dist/types.js +97 -0
  565. package/dist/types.js.map +1 -0
  566. package/dist/utils/abort-utils.d.ts +5 -0
  567. package/dist/utils/abort-utils.d.ts.map +1 -0
  568. package/dist/utils/abort-utils.js +50 -0
  569. package/dist/utils/abort-utils.js.map +1 -0
  570. package/dist/utils/classify-error.d.ts +19 -0
  571. package/dist/utils/classify-error.d.ts.map +1 -0
  572. package/dist/utils/classify-error.js +77 -0
  573. package/dist/utils/classify-error.js.map +1 -0
  574. package/dist/utils/index.d.ts +21 -0
  575. package/dist/utils/index.d.ts.map +1 -0
  576. package/dist/utils/index.js +21 -0
  577. package/dist/utils/index.js.map +1 -0
  578. package/dist/utils/normalization.d.ts +6 -0
  579. package/dist/utils/normalization.d.ts.map +1 -0
  580. package/dist/utils/normalization.js +103 -0
  581. package/dist/utils/normalization.js.map +1 -0
  582. package/dist/utils/registry.d.ts +15 -0
  583. package/dist/utils/registry.d.ts.map +1 -0
  584. package/dist/utils/registry.js +28 -0
  585. package/dist/utils/registry.js.map +1 -0
  586. package/dist/utils/schema.d.ts +7 -0
  587. package/dist/utils/schema.d.ts.map +1 -0
  588. package/dist/utils/schema.js +13 -0
  589. package/dist/utils/schema.js.map +1 -0
  590. package/dist/utils/token-estimate.d.ts +87 -0
  591. package/dist/utils/token-estimate.d.ts.map +1 -0
  592. package/dist/utils/token-estimate.js +199 -0
  593. package/dist/utils/token-estimate.js.map +1 -0
  594. package/dist/v2/reconciler/host-config.d.ts +31 -0
  595. package/dist/v2/reconciler/host-config.d.ts.map +1 -0
  596. package/dist/v2/reconciler/host-config.js +197 -0
  597. package/dist/v2/reconciler/host-config.js.map +1 -0
  598. package/dist/v2/reconciler/index.d.ts +7 -0
  599. package/dist/v2/reconciler/index.d.ts.map +1 -0
  600. package/dist/v2/reconciler/index.js +7 -0
  601. package/dist/v2/reconciler/index.js.map +1 -0
  602. package/dist/v2/reconciler/reconciler.d.ts +39 -0
  603. package/dist/v2/reconciler/reconciler.d.ts.map +1 -0
  604. package/dist/v2/reconciler/reconciler.js +54 -0
  605. package/dist/v2/reconciler/reconciler.js.map +1 -0
  606. package/dist/v2/reconciler/types.d.ts +64 -0
  607. package/dist/v2/reconciler/types.d.ts.map +1 -0
  608. package/dist/v2/reconciler/types.js +20 -0
  609. package/dist/v2/reconciler/types.js.map +1 -0
  610. package/dist/v2/renderers/index.d.ts +7 -0
  611. package/dist/v2/renderers/index.d.ts.map +1 -0
  612. package/dist/v2/renderers/index.js +7 -0
  613. package/dist/v2/renderers/index.js.map +1 -0
  614. package/dist/v2/renderers/markdown.d.ts +16 -0
  615. package/dist/v2/renderers/markdown.d.ts.map +1 -0
  616. package/dist/v2/renderers/markdown.js +65 -0
  617. package/dist/v2/renderers/markdown.js.map +1 -0
  618. package/dist/v2/renderers/types.d.ts +26 -0
  619. package/dist/v2/renderers/types.d.ts.map +1 -0
  620. package/dist/v2/renderers/types.js +6 -0
  621. package/dist/v2/renderers/types.js.map +1 -0
  622. package/dist/v2/renderers/xml.d.ts +17 -0
  623. package/dist/v2/renderers/xml.d.ts.map +1 -0
  624. package/dist/v2/renderers/xml.js +73 -0
  625. package/dist/v2/renderers/xml.js.map +1 -0
  626. package/package.json +49 -0
@@ -0,0 +1,963 @@
1
+ import { EventEmitter } from "node:events";
2
+ import { toJSONSchema } from "../utils/schema";
3
+ /** Default token estimator: ~4 chars per token + overhead */
4
+ function defaultEstimateTokens(text) {
5
+ return Math.ceil(text.length / 4) + 4;
6
+ }
7
+ // Note: Use Harness component for child agent execution.
8
+ /**
9
+ * The Context Object Model (COM).
10
+ *
11
+ * Represents the mutable state of the context for an execution.
12
+ * Components interact with this model to compose the final context
13
+ * that will be sent to the model (rendered as COMInput).
14
+ *
15
+ * This is analogous to the DOM in a browser, where components
16
+ * manipulate the structure before it is "painted" (sent to the model).
17
+ *
18
+ * COM extends EventEmitter to emit events when mutations occur,
19
+ * allowing components to reactively respond to changes.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Listen for new messages
24
+ * ctx.on('message:added', (message, options) => {
25
+ * console.log('New message:', message);
26
+ * });
27
+ *
28
+ * // Listen for tool registration
29
+ * ctx.on('tool:registered', (tool) => {
30
+ * console.log('Tool registered:', tool.metadata.name);
31
+ * });
32
+ *
33
+ * // Listen for state changes
34
+ * ctx.on('state:changed', (key, value, previousValue) => {
35
+ * console.log(`State changed: ${key} = ${value}`);
36
+ * });
37
+ * ```
38
+ */
39
+ export class ContextObjectModel extends EventEmitter {
40
+ timeline = [];
41
+ sections = new Map();
42
+ tools = new Map(); // Store ExecutableTool instances for execution
43
+ toolDefinitions = new Map(); // Store ToolDefinition for provider compatibility
44
+ metadata = {};
45
+ state = {}; // COM-level state shared across components
46
+ modelOptions; // Model options from EngineInput
47
+ // Ephemeral entries - transient content rebuilt each tick, NOT persisted
48
+ ephemeral = [];
49
+ // System messages - consolidated from sections each tick, NOT persisted in previous
50
+ // Rebuilt fresh each tick to maintain declarative principle
51
+ // Uses COMTimelineEntry envelope for consistency
52
+ systemMessages = [];
53
+ // Component references (separate from state)
54
+ refs = new Map();
55
+ // Tick control requests
56
+ controlRequests = [];
57
+ // Recompile tracking for compilation stabilization loop
58
+ _recompileRequested = false;
59
+ _recompileReasons = [];
60
+ // Callback for when recompile is requested (wired to scheduler by Session)
61
+ _onRecompileRequest;
62
+ // Message queue for execution messages
63
+ // Messages are delivered immediately to onMessage hooks, then queued here
64
+ // for availability in TickState.queuedMessages during the next tick
65
+ _queuedMessages = [];
66
+ // Abort control - allows components to request execution abort via onMessage
67
+ _shouldAbort = false;
68
+ _abortReason;
69
+ // Spawn callback - delegates to session for child session creation
70
+ _spawnCallback = null;
71
+ // Injected history - entries added via injectHistory() during current tick
72
+ // Separate from timeline to avoid duplication with compiled entries
73
+ _injectedHistory = [];
74
+ // Token estimation
75
+ _tokenEstimator = defaultEstimateTokens;
76
+ /**
77
+ * The current model adapter for this execution.
78
+ * Can be set dynamically via Model components.
79
+ */
80
+ model;
81
+ /**
82
+ * The original user input for this execution (static, doesn't change).
83
+ * Components can access this via ctx.getUserInput().
84
+ */
85
+ userInput;
86
+ /**
87
+ * Channel service for bidirectional communication (optional).
88
+ * Components and tools can publish/subscribe to channels.
89
+ */
90
+ channelService;
91
+ constructor(initial, userInput, channelService) {
92
+ super(); // Initialize EventEmitter
93
+ if (initial) {
94
+ // We don't copy timeline, sections, or tools from initial input because
95
+ // Components are responsible for building them declaratively each tick.
96
+ // Components have access to previous and current
97
+ // to make decisions about what to render.
98
+ // Initial metadata is fine.
99
+ if (initial.metadata)
100
+ Object.assign(this.metadata, initial.metadata);
101
+ if (initial.modelOptions)
102
+ this.modelOptions = initial.modelOptions;
103
+ }
104
+ // Also get modelOptions from userInput if not already set
105
+ if (userInput?.modelOptions && !this.modelOptions) {
106
+ this.modelOptions = userInput.modelOptions;
107
+ }
108
+ this.userInput = userInput;
109
+ this.channelService = channelService;
110
+ }
111
+ /**
112
+ * Type-safe event listener registration
113
+ */
114
+ on(event, listener) {
115
+ return super.on(event, listener);
116
+ }
117
+ /**
118
+ * Type-safe one-time event listener registration
119
+ */
120
+ once(event, listener) {
121
+ return super.once(event, listener);
122
+ }
123
+ /**
124
+ * Type-safe event emission
125
+ */
126
+ emit(event, ...args) {
127
+ return super.emit(event, ...args);
128
+ }
129
+ /**
130
+ * Get the original user input for this execution.
131
+ */
132
+ getUserInput() {
133
+ return this.userInput;
134
+ }
135
+ /**
136
+ * Get the channel service (if available).
137
+ */
138
+ getChannelService() {
139
+ return this.channelService;
140
+ }
141
+ /**
142
+ * Convenience property accessor for channel service.
143
+ * Allows `ctx.channels` instead of `ctx.getChannelService()`.
144
+ */
145
+ get channels() {
146
+ return this.channelService;
147
+ }
148
+ /**
149
+ * Set the model adapter for this execution.
150
+ * Can be called by Model components to dynamically set the model.
151
+ * This only updates the COM's internal model state - Engine.setModel handles the actual model switching.
152
+ */
153
+ setModel(model) {
154
+ this.model = model;
155
+ // Emit event synchronously
156
+ this.emit("model:changed", model);
157
+ }
158
+ /**
159
+ * Get the current model adapter (or model identifier).
160
+ * Returns undefined if no model is set.
161
+ */
162
+ getModel() {
163
+ return this.model;
164
+ }
165
+ /**
166
+ * Clear the current model.
167
+ * Called when Model component unmounts.
168
+ */
169
+ unsetModel() {
170
+ this.model = undefined;
171
+ // Emit event synchronously
172
+ this.emit("model:unset");
173
+ }
174
+ /**
175
+ * Set or merge model options (messageTransformation, temperature, etc.).
176
+ * These are passed through to fromEngineState for content transformation.
177
+ */
178
+ setModelOptions(options) {
179
+ this.modelOptions = {
180
+ ...this.modelOptions,
181
+ ...options,
182
+ };
183
+ }
184
+ resetModelOptions() {
185
+ this.modelOptions = undefined;
186
+ }
187
+ /**
188
+ * Get the current model options.
189
+ */
190
+ getModelOptions() {
191
+ return this.modelOptions;
192
+ }
193
+ /**
194
+ * Clears all state to prepare for a new render pass.
195
+ * Components are responsible for managing what persists across ticks
196
+ * by accessing previousInput in their render methods.
197
+ *
198
+ * Note: This does NOT remove event listeners. Components are responsible
199
+ * for cleaning up their own listeners in onUnmount().
200
+ *
201
+ * Note: This does NOT clear refs - refs persist across ticks until components unmount.
202
+ * Note: This does NOT clear control requests - they are consumed per tick.
203
+ */
204
+ clear() {
205
+ this.timeline = [];
206
+ this.sections.clear();
207
+ this.tools.clear();
208
+ this.toolDefinitions.clear();
209
+ this.metadata = {};
210
+ this.ephemeral = []; // Always cleared - rebuilt fresh each tick
211
+ this.systemMessages = []; // Always cleared - rebuilt fresh each tick from sections
212
+ this.controlRequests = [];
213
+ // Note: _queuedMessages is NOT cleared here - it has separate lifecycle
214
+ // managed by session's clearQueuedMessages() calls
215
+ // Emit state cleared event
216
+ this.emit("state:cleared");
217
+ }
218
+ /**
219
+ * Adds a message to the timeline (or system array for system messages).
220
+ * Convenience method that maintains model semantics (role, content).
221
+ * This is the intuitive API for developers thinking in terms of "user messages", "assistant messages", etc.
222
+ *
223
+ * System messages go to a separate array (not timeline) because:
224
+ * - They are declarative (rebuilt each tick from sections)
225
+ * - They should not be persisted in previous
226
+ * - This prevents duplicate system messages across ticks
227
+ */
228
+ addMessage(message, options = {}) {
229
+ if (message.role === "system") {
230
+ // System messages go to separate array, not timeline
231
+ // They are rebuilt fresh each tick from sections
232
+ this.addSystemMessage(message);
233
+ this.emit("message:added", message, options);
234
+ }
235
+ else {
236
+ // Non-system messages go to timeline (conversation history)
237
+ this.addTimelineEntry({
238
+ kind: "message",
239
+ message,
240
+ tags: options.tags,
241
+ visibility: options.visibility,
242
+ metadata: options.metadata,
243
+ });
244
+ this.emit("message:added", message, options);
245
+ }
246
+ }
247
+ /**
248
+ * Adds a system message to the system messages array.
249
+ * System messages are kept separate from timeline to maintain declarative principle.
250
+ * They are rebuilt fresh each tick from sections.
251
+ */
252
+ addSystemMessage(message) {
253
+ if (message.role !== "system") {
254
+ console.warn("addSystemMessage called with non-system message, adding anyway");
255
+ }
256
+ // Wrap in COMTimelineEntry envelope for consistency
257
+ this.systemMessages.push({
258
+ kind: "message",
259
+ message,
260
+ });
261
+ }
262
+ /**
263
+ * Get all system messages as timeline entries.
264
+ * These are rebuilt fresh each tick from sections.
265
+ */
266
+ getSystemMessages() {
267
+ return [...this.systemMessages];
268
+ }
269
+ /**
270
+ * Adds a generic timeline entry.
271
+ * Use this for events or other non-message timeline entries.
272
+ * For messages, prefer `addMessage()` for better semantics.
273
+ *
274
+ * NOTE: With the declarative architecture, timeline entries from JSX
275
+ * go through the compiler's timelineEntries, not through COM accumulation.
276
+ * This method is still used for injecting history and for non-JSX additions.
277
+ */
278
+ addTimelineEntry(entry) {
279
+ this.timeline.push(entry);
280
+ // Emit event synchronously
281
+ this.emit("timeline:modified", entry, "add");
282
+ }
283
+ /**
284
+ * Get all timeline entries.
285
+ */
286
+ getTimeline() {
287
+ return [...this.timeline];
288
+ }
289
+ /**
290
+ * Inject historical timeline entries at the beginning.
291
+ *
292
+ * Use this to load an existing conversation history when the component mounts.
293
+ * Injected entries are prepended to the timeline, appearing before any new entries.
294
+ *
295
+ * Best called in `useInit()` or `onMount()` on tick 1. After tick 1, the timeline
296
+ * naturally includes all previous entries via `TickState.previous.timeline`.
297
+ *
298
+ * @param entries - Timeline entries to inject (prepended to existing timeline)
299
+ *
300
+ * @example
301
+ * ```tsx
302
+ * const ChatAgent = () => {
303
+ * const ctx = useCom();
304
+ *
305
+ * await useInit(async () => {
306
+ * const conversation = await loadConversation(id);
307
+ * ctx.injectHistory(conversation.entries);
308
+ * });
309
+ *
310
+ * return <Timeline />; // Shows injected + new entries
311
+ * };
312
+ * ```
313
+ */
314
+ injectHistory(entries) {
315
+ if (entries.length === 0)
316
+ return;
317
+ // Add entries to injected history (separate from compiled timeline)
318
+ // This avoids duplication when useConversationHistory reads from both
319
+ this._injectedHistory = [...entries, ...this._injectedHistory];
320
+ // Also prepend to timeline for output (so complete() includes them)
321
+ this.timeline = [...entries, ...this.timeline];
322
+ // Emit events for each injected entry
323
+ for (const entry of entries) {
324
+ this.emit("timeline:modified", entry, "add");
325
+ }
326
+ }
327
+ /**
328
+ * Get entries that were injected via injectHistory() during this tick.
329
+ *
330
+ * Used by useConversationHistory() to include injected entries.
331
+ * Separate from getTimeline() to avoid duplication with compiled entries.
332
+ */
333
+ getInjectedHistory() {
334
+ return [...this._injectedHistory];
335
+ }
336
+ /**
337
+ * Adds or updates a section in the context.
338
+ * Combines content from sections with the same ID.
339
+ * Last section's metadata wins.
340
+ */
341
+ addSection(section) {
342
+ const existing = this.sections.get(section.id);
343
+ if (!existing) {
344
+ this.sections.set(section.id, section);
345
+ // Emit event for new section
346
+ this.emit("section:updated", section, "add");
347
+ return;
348
+ }
349
+ // Combine content based on type
350
+ let combinedContent;
351
+ if (typeof existing.content === "string" && typeof section.content === "string") {
352
+ // Both strings: combine with newline
353
+ combinedContent = `${existing.content}\n${section.content}`;
354
+ }
355
+ else if (Array.isArray(existing.content) && Array.isArray(section.content)) {
356
+ // Both arrays: concatenate
357
+ combinedContent = [...existing.content, ...section.content];
358
+ }
359
+ else if (typeof existing.content === "object" &&
360
+ typeof section.content === "object" &&
361
+ existing.content !== null &&
362
+ section.content !== null &&
363
+ !Array.isArray(existing.content) &&
364
+ !Array.isArray(section.content)) {
365
+ // Both objects: merge
366
+ combinedContent = { ...existing.content, ...section.content };
367
+ }
368
+ else {
369
+ // Mixed types or other: convert to array
370
+ combinedContent = [existing.content, section.content];
371
+ }
372
+ // Last section's metadata wins (including formatted content)
373
+ const mergedSection = {
374
+ id: section.id,
375
+ content: combinedContent,
376
+ // Last section wins for metadata and formatted content
377
+ title: section.title || existing.title,
378
+ tags: section.tags || existing.tags,
379
+ visibility: section.visibility || existing.visibility,
380
+ audience: section.audience || existing.audience,
381
+ metadata: section.metadata || existing.metadata,
382
+ formattedContent: section.formattedContent || existing.formattedContent,
383
+ formattedWith: section.formattedWith || existing.formattedWith,
384
+ };
385
+ this.sections.set(section.id, mergedSection);
386
+ // Emit event for updated section
387
+ this.emit("section:updated", mergedSection, "update");
388
+ }
389
+ /**
390
+ * Get a section by ID.
391
+ */
392
+ getSection(id) {
393
+ return this.sections.get(id);
394
+ }
395
+ /**
396
+ * Get all sections.
397
+ */
398
+ getSections() {
399
+ return Object.fromEntries(this.sections);
400
+ }
401
+ /**
402
+ * Adds a tool definition to the context.
403
+ * Uses tool name as key to prevent duplicates.
404
+ * Converts Zod schema to JSON Schema for provider compatibility.
405
+ */
406
+ async addTool(tool) {
407
+ const name = tool.metadata.name;
408
+ if (name) {
409
+ // Store ExecutableTool for execution
410
+ this.tools.set(name, tool);
411
+ // Convert to ToolDefinition (provider-compatible format with JSON Schema)
412
+ const inputJsonSchema = await this.convertInputToJSONSchema(tool.metadata.input);
413
+ const outputJsonSchema = tool.metadata.output
414
+ ? await this.convertInputToJSONSchema(tool.metadata.output)
415
+ : undefined;
416
+ this.toolDefinitions.set(name, {
417
+ name: tool.metadata.name,
418
+ description: tool.metadata.description,
419
+ input: inputJsonSchema,
420
+ output: outputJsonSchema,
421
+ type: tool.metadata.type, // Preserve execution type
422
+ providerOptions: tool.metadata.providerOptions, // Preserve provider-specific options
423
+ mcpConfig: tool.metadata.mcpConfig, // Preserve MCP configuration
424
+ });
425
+ // Emit event synchronously
426
+ this.emit("tool:registered", tool);
427
+ }
428
+ }
429
+ /**
430
+ * Converts any supported schema to JSON Schema format.
431
+ * Supports Zod 3, Zod 4, Standard Schema, and pass-through JSON Schema.
432
+ */
433
+ async convertInputToJSONSchema(input) {
434
+ const result = await toJSONSchema(input, { stripMeta: true });
435
+ // Debug logging
436
+ if (Object.keys(result).length === 0 && input != null) {
437
+ console.warn("[COM] Schema conversion returned empty object for input:", {
438
+ hasStandard: input && typeof input === "object" && "~standard" in input,
439
+ hasDef: input && typeof input === "object" && "_def" in input,
440
+ typeName: input && typeof input === "object" ? input._def?.typeName : undefined,
441
+ });
442
+ }
443
+ return result;
444
+ }
445
+ /**
446
+ * Remove a tool from the context.
447
+ */
448
+ removeTool(name) {
449
+ const hadTool = this.tools.has(name);
450
+ this.tools.delete(name);
451
+ this.toolDefinitions.delete(name);
452
+ // Emit event if tool was actually removed
453
+ if (hadTool) {
454
+ this.emit("tool:removed", name);
455
+ }
456
+ }
457
+ /**
458
+ * Gets a registered tool instance by name.
459
+ */
460
+ getTool(name) {
461
+ return this.tools.get(name);
462
+ }
463
+ /**
464
+ * Get all registered tools.
465
+ */
466
+ getTools() {
467
+ return Array.from(this.tools.values());
468
+ }
469
+ /**
470
+ * Gets a tool definition by name.
471
+ * Returns the provider-compatible definition (JSON Schema parameters).
472
+ */
473
+ getToolDefinition(name) {
474
+ return this.toolDefinitions.get(name);
475
+ }
476
+ /**
477
+ * Adds a tool definition without an executable implementation.
478
+ * Used for client tools that are executed on the client side.
479
+ *
480
+ * @param definition - Tool definition with JSON Schema parameters
481
+ */
482
+ addToolDefinition(definition) {
483
+ const name = definition.name;
484
+ if (name) {
485
+ this.toolDefinitions.set(name, definition);
486
+ this.emit("tool:added", name);
487
+ }
488
+ }
489
+ /**
490
+ * Adds metadata to the context.
491
+ */
492
+ addMetadata(key, value) {
493
+ const previousValue = this.metadata[key];
494
+ this.metadata[key] = value;
495
+ // Emit event synchronously
496
+ this.emit("metadata:changed", key, value, previousValue);
497
+ }
498
+ // ============================================================================
499
+ // Ephemeral Content API
500
+ // ============================================================================
501
+ /**
502
+ * Adds ephemeral content to be included in the model input.
503
+ *
504
+ * Ephemeral content is NOT persisted - it's rebuilt fresh each tick.
505
+ * It provides current state/context to the model but is not part of
506
+ * the conversation history.
507
+ *
508
+ * @param content - Content blocks to include
509
+ * @param position - Where to position in the message stream
510
+ * @param order - Secondary sort order (lower = earlier, default 0)
511
+ * @param metadata - Optional metadata
512
+ * @param id - Optional identifier for debugging
513
+ * @param tags - Optional tags for categorization
514
+ * @param type - Optional type for semantic categorization (used by model config)
515
+ *
516
+ * @example
517
+ * ```typescript
518
+ * // Add current account balance at the start
519
+ * ctx.addEphemeral(
520
+ * [{ type: 'text', text: `Current balance: $${balance}` }],
521
+ * 'start'
522
+ * );
523
+ *
524
+ * // Add inventory context before user message with type
525
+ * ctx.addEphemeral(
526
+ * [{ type: 'text', text: `Available items: ${items.join(', ')}` }],
527
+ * 'before-user',
528
+ * 10, // order
529
+ * undefined, // metadata
530
+ * undefined, // id
531
+ * undefined, // tags
532
+ * 'inventory' // type
533
+ * );
534
+ * ```
535
+ */
536
+ addEphemeral(content, position = "end", order = 0, metadata, id, tags, type) {
537
+ this.ephemeral.push({
538
+ type,
539
+ content,
540
+ position,
541
+ order,
542
+ metadata,
543
+ id,
544
+ tags,
545
+ });
546
+ }
547
+ /**
548
+ * Get all ephemeral entries.
549
+ * These are cleared on each tick via clear().
550
+ */
551
+ getEphemeral() {
552
+ return [...this.ephemeral];
553
+ }
554
+ /**
555
+ * Gets COM-level state value.
556
+ * COM state is shared across all components and persists across ticks.
557
+ */
558
+ getState(key) {
559
+ return this.state[key];
560
+ }
561
+ /**
562
+ * Sets COM-level state value.
563
+ * COM state is shared across all components and persists across ticks.
564
+ * Use this for shared state that multiple components need to access.
565
+ */
566
+ setState(key, value) {
567
+ const previousValue = this.state[key];
568
+ this.state[key] = value;
569
+ // Emit event synchronously
570
+ this.emit("state:changed", key, value, previousValue);
571
+ }
572
+ /**
573
+ * Updates COM-level state with a partial object.
574
+ * Merges the provided state into the existing state.
575
+ * Emits a 'state:changed' event for each key that changed.
576
+ */
577
+ setStatePartial(partial) {
578
+ for (const [key, value] of Object.entries(partial)) {
579
+ const previousValue = this.state[key];
580
+ this.state[key] = value;
581
+ // Emit event for each changed key
582
+ this.emit("state:changed", key, value, previousValue);
583
+ }
584
+ }
585
+ /**
586
+ * Gets all COM-level state.
587
+ */
588
+ getStateAll() {
589
+ return { ...this.state };
590
+ }
591
+ /**
592
+ * Get a component reference by name
593
+ *
594
+ * Components can expose themselves via the `ref` prop.
595
+ * Use this to access component instances from other components.
596
+ *
597
+ * @param refName Reference name (from component's `ref` prop)
598
+ * @returns Component instance or undefined
599
+ *
600
+ * @example
601
+ * ```typescript
602
+ * const harness = ctx.getRef<HarnessComponent>('myHarness');
603
+ * ```
604
+ */
605
+ getRef(refName) {
606
+ return this.refs.get(refName);
607
+ }
608
+ /**
609
+ * Set a component reference
610
+ * Called by compiler when components mount with a ref prop.
611
+ * @internal
612
+ */
613
+ _setRef(refName, instance) {
614
+ this.refs.set(refName, instance);
615
+ }
616
+ /**
617
+ * Remove a component reference
618
+ * Called by components when they unmount.
619
+ * @internal
620
+ */
621
+ _removeRef(refName) {
622
+ this.refs.delete(refName);
623
+ }
624
+ /**
625
+ * Get all component references
626
+ *
627
+ * @returns Map of all component references
628
+ */
629
+ getRefs() {
630
+ return Object.fromEntries(this.refs);
631
+ }
632
+ /**
633
+ * Renders the Object Model into the final COMInput structure.
634
+ */
635
+ toInput() {
636
+ return {
637
+ timeline: [...this.timeline],
638
+ sections: Object.fromEntries(this.sections),
639
+ ephemeral: [...this.ephemeral],
640
+ system: [...this.systemMessages],
641
+ // Return ToolDefinition[] (provider-compatible format with JSON Schema)
642
+ tools: Array.from(this.toolDefinitions.values()),
643
+ metadata: { ...this.metadata },
644
+ modelOptions: this.modelOptions,
645
+ };
646
+ }
647
+ // ============================================================================
648
+ // Token Estimation API
649
+ // ============================================================================
650
+ /**
651
+ * Set the token estimator function.
652
+ * Called by Model component when the adapter provides a tokenEstimator.
653
+ */
654
+ setTokenEstimator(estimator) {
655
+ this._tokenEstimator = estimator;
656
+ }
657
+ /**
658
+ * Estimate token count for text content.
659
+ * Uses the model-provided estimator or falls back to char/4 default.
660
+ */
661
+ estimateTokens(text) {
662
+ return this._tokenEstimator(text);
663
+ }
664
+ /**
665
+ * Get the current token estimator function.
666
+ * Used by the collector to annotate compiled structures.
667
+ */
668
+ getTokenEstimator() {
669
+ return this._tokenEstimator;
670
+ }
671
+ // ============================================================================
672
+ // Tick Control API
673
+ // ============================================================================
674
+ /**
675
+ * Request that execution stop after this tick.
676
+ * Components can call this to signal that execution should terminate.
677
+ *
678
+ * @param details Stop request details
679
+ *
680
+ * @example
681
+ * ```typescript
682
+ * class ResponseVerifier extends Component {
683
+ * render(ctx: ContextObjectModel, state: TickState) {
684
+ * const response = state.current?.timeline.find(e => e.message.role === 'assistant');
685
+ * if (response && this.isComplete(response)) {
686
+ * ctx.requestStop({ reason: 'response-complete', status: 'completed' });
687
+ * }
688
+ * }
689
+ * }
690
+ * ```
691
+ */
692
+ requestStop(details = {}) {
693
+ this.controlRequests.push({
694
+ kind: "stop",
695
+ ownerId: details.ownerId,
696
+ priority: details.priority ?? 0,
697
+ reason: details.reason,
698
+ status: details.status ?? "aborted",
699
+ metadata: details.metadata,
700
+ });
701
+ }
702
+ /**
703
+ * Request that execution continue to the next tick.
704
+ * Useful when a component wants to override a default stop condition.
705
+ *
706
+ * @param details Continue request details
707
+ *
708
+ * @example
709
+ * ```typescript
710
+ * class RetryHandler extends Component {
711
+ * render(ctx: ContextObjectModel, state: TickState) {
712
+ * if (state.stopReason?.reason === 'error' && this.shouldRetry(state.error)) {
713
+ * ctx.requestContinue({ reason: 'retrying-after-error' });
714
+ * }
715
+ * }
716
+ * }
717
+ * ```
718
+ */
719
+ requestContinue(details = {}) {
720
+ this.controlRequests.push({
721
+ kind: "continue",
722
+ ownerId: details.ownerId,
723
+ priority: details.priority ?? 0,
724
+ reason: details.reason,
725
+ status: "continue",
726
+ metadata: details.metadata,
727
+ });
728
+ }
729
+ /**
730
+ * Resolve tick control decision from pending requests.
731
+ * Called by Engine at the end of each tick to determine if execution should continue.
732
+ *
733
+ * Priority: stop requests > continue requests > default status
734
+ *
735
+ * @param defaultStatus Default status if no requests
736
+ * @param defaultReason Default reason if no requests
737
+ * @param tickNumber Current tick number (for telemetry)
738
+ * @returns Decision with status and reason
739
+ * @internal
740
+ */
741
+ _resolveTickControl(defaultStatus, defaultReason, _tickNumber) {
742
+ // Sort by priority (higher priority first)
743
+ const sortedRequests = [...this.controlRequests].sort((a, b) => b.priority - a.priority);
744
+ // Find highest priority stop request
745
+ const stopRequest = sortedRequests.find((r) => r.kind === "stop");
746
+ // Find highest priority continue request
747
+ const continueRequest = sortedRequests.find((r) => r.kind === "continue");
748
+ // Clear requests (consumed)
749
+ this.controlRequests = [];
750
+ // Stop requests take precedence
751
+ if (stopRequest) {
752
+ return {
753
+ status: stopRequest.status ?? "aborted",
754
+ reason: stopRequest.reason ?? defaultReason,
755
+ decidedBy: stopRequest,
756
+ };
757
+ }
758
+ // Continue requests override default stop (but not explicit stops)
759
+ if (defaultStatus !== "continue" && continueRequest) {
760
+ return {
761
+ status: "continue",
762
+ reason: continueRequest.reason ?? defaultReason,
763
+ decidedBy: continueRequest,
764
+ };
765
+ }
766
+ // Default decision
767
+ return {
768
+ status: defaultStatus,
769
+ reason: defaultReason,
770
+ };
771
+ }
772
+ // ============================================================================
773
+ // Compilation Stabilization API
774
+ // ============================================================================
775
+ /**
776
+ * Request a re-compilation of the component tree.
777
+ *
778
+ * Call this in `onAfterCompile` when you've modified COM state and need
779
+ * the compilation to reflect those changes. The compiler will re-run
780
+ * the compile loop until no component requests recompilation (or max
781
+ * iterations is reached).
782
+ *
783
+ * @param reason Optional reason for the recompile (for debugging/logging)
784
+ *
785
+ * @example
786
+ * ```typescript
787
+ * class ContextManager extends Component {
788
+ * onAfterCompile(ctx: ContextObjectModel, compiled: CompiledStructure, state: TickState) {
789
+ * const tokens = this.estimateTokens(compiled);
790
+ * if (tokens > MAX_TOKENS) {
791
+ * ctx.setTimeline(this.summarize(ctx.getTimeline()));
792
+ * ctx.requestRecompile('context-too-large');
793
+ * }
794
+ * }
795
+ * }
796
+ * ```
797
+ */
798
+ requestRecompile(reason) {
799
+ this._recompileRequested = true;
800
+ if (reason) {
801
+ this._recompileReasons.push(reason);
802
+ }
803
+ // Notify callback if set (triggers scheduler when idle)
804
+ if (this._onRecompileRequest) {
805
+ this._onRecompileRequest(reason);
806
+ }
807
+ }
808
+ /**
809
+ * Set the callback for when recompile is requested.
810
+ * This is wired to the scheduler by Session to enable reactive updates.
811
+ * @internal
812
+ */
813
+ setRecompileCallback(callback) {
814
+ this._onRecompileRequest = callback;
815
+ }
816
+ /**
817
+ * Check if recompile was requested.
818
+ * Called by the compiler after onAfterCompile hooks.
819
+ * @internal
820
+ */
821
+ _wasRecompileRequested() {
822
+ return this._recompileRequested;
823
+ }
824
+ /**
825
+ * Get the reasons for recompile requests.
826
+ * @internal
827
+ */
828
+ _getRecompileReasons() {
829
+ return [...this._recompileReasons];
830
+ }
831
+ /**
832
+ * Reset recompile tracking for the next iteration.
833
+ * Called by the compiler before each compile iteration.
834
+ * @internal
835
+ */
836
+ _resetRecompileRequest() {
837
+ this._recompileRequested = false;
838
+ this._recompileReasons = [];
839
+ }
840
+ // ============================================================================
841
+ // Spawn API
842
+ // ============================================================================
843
+ /**
844
+ * Set the callback for spawning child sessions.
845
+ * This is wired by Session to enable ctx.spawn() from tool handlers.
846
+ * @internal
847
+ */
848
+ setSpawnCallback(callback) {
849
+ this._spawnCallback = callback;
850
+ }
851
+ /**
852
+ * Spawn a child session with a different agent/component.
853
+ *
854
+ * Delegates to the session's spawn Procedure. Available in tool handlers
855
+ * via `ctx.spawn(agentOrConfig, input)`.
856
+ *
857
+ * @param agentOrConfig - AgentConfig, ComponentFunction, or JSX element
858
+ * @param input - Optional SendInput for the child session
859
+ * @returns SessionExecutionHandle (same as session.send())
860
+ */
861
+ spawn(agentOrConfig, input) {
862
+ if (!this._spawnCallback) {
863
+ throw new Error("spawn() is not available in this context. It requires a session.");
864
+ }
865
+ return this._spawnCallback(agentOrConfig, input);
866
+ }
867
+ // ============================================================================
868
+ // Message Queue API
869
+ // ============================================================================
870
+ /**
871
+ * Queue a message for availability in the next tick's TickState.queuedMessages.
872
+ *
873
+ * This is called by RuntimeSession.sendMessage() after notifying onMessage hooks.
874
+ * Messages are queued here and made available to components during render.
875
+ *
876
+ * @param message The message to queue
877
+ * @internal Called by RuntimeSession
878
+ */
879
+ queueMessage(message) {
880
+ this._queuedMessages.push(message);
881
+ this.emit("execution:message", message);
882
+ }
883
+ /**
884
+ * Get all queued messages (snapshot).
885
+ *
886
+ * Returns a copy of the queued messages array.
887
+ * Used by prepareTickState() to populate TickState.queuedMessages.
888
+ *
889
+ * @returns Copy of queued messages
890
+ * @internal Called by RuntimeSession
891
+ */
892
+ getQueuedMessages() {
893
+ return [...this._queuedMessages];
894
+ }
895
+ /**
896
+ * Clear all queued messages.
897
+ *
898
+ * Called after tick completes to reset the queue for the next tick.
899
+ *
900
+ * @internal Called by RuntimeSession
901
+ */
902
+ clearQueuedMessages() {
903
+ this._queuedMessages = [];
904
+ }
905
+ // ============================================================================
906
+ // Abort Control API
907
+ // ============================================================================
908
+ /**
909
+ * Request immediate abort of execution.
910
+ *
911
+ * Called from onMessage hooks when a component needs to interrupt execution.
912
+ * The abort will be processed at the next checkpoint in the tick loop
913
+ * (between chunks during streaming, before/after operations, etc.).
914
+ *
915
+ * @param reason Optional reason for the abort
916
+ *
917
+ * @example
918
+ * ```typescript
919
+ * class InteractiveAgent extends Component {
920
+ * onMessage(ctx, message, state) {
921
+ * if (message.type === 'stop') {
922
+ * ctx.abort('User requested stop');
923
+ * }
924
+ * }
925
+ * }
926
+ * ```
927
+ */
928
+ abort(reason) {
929
+ this._shouldAbort = true;
930
+ this._abortReason = reason;
931
+ }
932
+ /**
933
+ * Check if abort was requested.
934
+ *
935
+ * Used by the engine tick loop to check if a component requested abort.
936
+ *
937
+ * @returns true if abort was requested
938
+ */
939
+ get shouldAbort() {
940
+ return this._shouldAbort;
941
+ }
942
+ /**
943
+ * Get the reason for the abort request.
944
+ *
945
+ * @returns The abort reason, or undefined if not set
946
+ */
947
+ get abortReason() {
948
+ return this._abortReason;
949
+ }
950
+ /**
951
+ * Reset abort state.
952
+ *
953
+ * Called at the start of each tick to reset abort tracking.
954
+ *
955
+ * @internal Called by RuntimeSession/Engine
956
+ */
957
+ _resetAbortState() {
958
+ this._shouldAbort = false;
959
+ this._abortReason = undefined;
960
+ }
961
+ }
962
+ export { ContextObjectModel as COM };
963
+ //# sourceMappingURL=object-model.js.map