@jangts/agent-core 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (527) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +59 -0
  3. package/development/docs/api/reference.md +1907 -1874
  4. package/development/docs/api/support.md +27 -0
  5. package/development/docs/assets/agent-core-icon.png +0 -0
  6. package/development/docs/assets/agent-core-logo.png +0 -0
  7. package/development/docs/assets/character-agent-core.png +0 -0
  8. package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
  9. package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
  10. package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
  11. package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
  12. package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
  13. package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
  14. package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
  15. package/development/skills/agent-core-app/templates/catalog.json +36 -22
  16. package/dist/cjs/capabilities/index.js +13 -0
  17. package/dist/cjs/capabilities/invocation.js +80 -10
  18. package/dist/cjs/capabilities/model.js +126 -13
  19. package/dist/cjs/capabilities/tool-runtime.js +64 -12
  20. package/dist/cjs/capabilities/tools.js +266 -31
  21. package/dist/cjs/context/assembly.js +46 -5
  22. package/dist/cjs/context/audit.js +31 -6
  23. package/dist/cjs/context/fragments.js +54 -11
  24. package/dist/cjs/context/index.js +12 -0
  25. package/dist/cjs/context/journal.js +84 -7
  26. package/dist/cjs/context/plan.js +30 -2
  27. package/dist/cjs/diagnostics/catalog.js +11 -3
  28. package/dist/cjs/diagnostics/index.js +149 -29
  29. package/dist/cjs/diagnostics/sub-flow.js +240 -40
  30. package/dist/cjs/errors.js +99 -17
  31. package/dist/cjs/execution/branch.js +20 -4
  32. package/dist/cjs/execution/engine.js +470 -56
  33. package/dist/cjs/execution/events.js +136 -18
  34. package/dist/cjs/execution/index.js +7 -0
  35. package/dist/cjs/execution/reporting.js +75 -6
  36. package/dist/cjs/execution/state.js +161 -22
  37. package/dist/cjs/execution/workflow.js +224 -32
  38. package/dist/cjs/index.js +18 -0
  39. package/dist/cjs/kits/aggregation.js +45 -3
  40. package/dist/cjs/kits/answering/batch.js +23 -4
  41. package/dist/cjs/kits/answering/check-result.js +31 -8
  42. package/dist/cjs/kits/answering/checks.js +24 -3
  43. package/dist/cjs/kits/answering/flow.js +192 -36
  44. package/dist/cjs/kits/answering/index.js +19 -1
  45. package/dist/cjs/kits/answering/tasks.js +88 -13
  46. package/dist/cjs/kits/artifacts.js +36 -4
  47. package/dist/cjs/kits/candidates.js +47 -5
  48. package/dist/cjs/kits/delivery.js +40 -5
  49. package/dist/cjs/kits/durable.js +155 -31
  50. package/dist/cjs/kits/evidence.js +66 -15
  51. package/dist/cjs/kits/family.js +152 -22
  52. package/dist/cjs/kits/index.js +12 -1
  53. package/dist/cjs/kits/inference.js +104 -16
  54. package/dist/cjs/kits/intents/catalog.js +67 -16
  55. package/dist/cjs/kits/intents/index.js +11 -0
  56. package/dist/cjs/kits/intents/registry.js +188 -43
  57. package/dist/cjs/kits/intents/scopes.js +215 -46
  58. package/dist/cjs/kits/interaction/command.js +140 -36
  59. package/dist/cjs/kits/interaction/commands.js +86 -11
  60. package/dist/cjs/kits/interaction/handlers.js +27 -10
  61. package/dist/cjs/kits/interaction/index.js +10 -0
  62. package/dist/cjs/kits/interaction/transfer.js +80 -14
  63. package/dist/cjs/kits/knowledge/catalog.js +62 -11
  64. package/dist/cjs/kits/knowledge/index.js +16 -1
  65. package/dist/cjs/kits/knowledge/publication.js +99 -23
  66. package/dist/cjs/kits/knowledge/sections.js +33 -4
  67. package/dist/cjs/kits/normalization.js +51 -7
  68. package/dist/cjs/kits/policies.js +79 -15
  69. package/dist/cjs/kits/presentation/events.js +54 -10
  70. package/dist/cjs/kits/presentation/index.js +24 -1
  71. package/dist/cjs/kits/presentation/outputs.js +176 -38
  72. package/dist/cjs/kits/presentation/templates.js +33 -5
  73. package/dist/cjs/kits/presentation/variants.js +31 -2
  74. package/dist/cjs/kits/projection.js +63 -8
  75. package/dist/cjs/kits/rank-fusion.js +27 -4
  76. package/dist/cjs/kits/reflection-log-source.js +89 -16
  77. package/dist/cjs/kits/reflection.js +234 -60
  78. package/dist/cjs/kits/retrieval.js +98 -18
  79. package/dist/cjs/kits/search.js +180 -27
  80. package/dist/cjs/kits/text-skills.js +104 -19
  81. package/dist/cjs/kits/tools.js +415 -74
  82. package/dist/cjs/kits/vector-search.js +50 -16
  83. package/dist/cjs/mock/node.js +7 -1
  84. package/dist/cjs/mock/web.js +7 -1
  85. package/dist/cjs/mock.js +7 -1
  86. package/dist/cjs/model/binding.js +68 -17
  87. package/dist/cjs/model/call-budget.js +45 -4
  88. package/dist/cjs/model/decision-retry.js +19 -1
  89. package/dist/cjs/model/defaults.js +27 -4
  90. package/dist/cjs/model/index.js +7 -0
  91. package/dist/cjs/model/interactions/arguments.js +36 -1
  92. package/dist/cjs/model/interactions/json-object.js +48 -12
  93. package/dist/cjs/model/interactions/native-functions.js +52 -10
  94. package/dist/cjs/model/message-diagnostics.js +17 -4
  95. package/dist/cjs/model/options.js +9 -1
  96. package/dist/cjs/model/preparation.js +86 -12
  97. package/dist/cjs/model/runner.js +413 -79
  98. package/dist/cjs/model/selection-transport.js +48 -8
  99. package/dist/cjs/model/settings.js +67 -13
  100. package/dist/cjs/model/token-budget.js +69 -11
  101. package/dist/cjs/model/transports.js +59 -6
  102. package/dist/cjs/structs/common.js +11 -0
  103. package/dist/cjs/structs/debug.js +34 -5
  104. package/dist/cjs/structs/errors.js +26 -1
  105. package/dist/cjs/structs/index.js +11 -1
  106. package/dist/cjs/structs/kits/durable.js +7 -0
  107. package/dist/cjs/structs/kits/family.js +1 -0
  108. package/dist/cjs/structs/kits/interaction.js +8 -1
  109. package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
  110. package/dist/cjs/structs/kits/reflection.js +18 -3
  111. package/dist/cjs/structs/model/chat-provider.js +6 -0
  112. package/dist/cjs/structs/support/model/completion.js +2 -0
  113. package/dist/cjs/structs/support/model/messages.js +2 -0
  114. package/dist/cjs/support/capabilities.js +43 -6
  115. package/dist/cjs/support/context/assembly.js +88 -16
  116. package/dist/cjs/support/context/compression.js +48 -6
  117. package/dist/cjs/support/context/fragments.js +6 -0
  118. package/dist/cjs/support/context/history.js +36 -1
  119. package/dist/cjs/support/context/index.js +11 -0
  120. package/dist/cjs/support/context/nodes.js +164 -35
  121. package/dist/cjs/support/context/processing.js +319 -61
  122. package/dist/cjs/support/context/selection-policy.js +98 -21
  123. package/dist/cjs/support/context/selection.js +61 -10
  124. package/dist/cjs/support/context/snapshot.js +29 -7
  125. package/dist/cjs/support/context/strategies.js +120 -28
  126. package/dist/cjs/support/index.js +9 -1
  127. package/dist/cjs/support/model/capabilities.js +20 -1
  128. package/dist/cjs/support/model/chat-completions.js +92 -20
  129. package/dist/cjs/support/model/children.js +34 -6
  130. package/dist/cjs/support/model/compatible-provider.js +189 -59
  131. package/dist/cjs/support/model/completion/calls.js +61 -0
  132. package/dist/cjs/support/model/completion/default.js +32 -0
  133. package/dist/cjs/support/model/completion/index.js +28 -0
  134. package/dist/cjs/support/model/completion/session.js +102 -0
  135. package/dist/cjs/support/model/index.js +12 -0
  136. package/dist/cjs/support/model/interactions/index.js +12 -1
  137. package/dist/cjs/support/model/interactions/json-object.js +6 -0
  138. package/dist/cjs/support/model/interactions/native-functions.js +6 -0
  139. package/dist/cjs/support/model/observer.js +32 -6
  140. package/dist/cjs/support/model/preview-rules.js +66 -16
  141. package/dist/cjs/support/model/reply-preview.js +77 -17
  142. package/dist/cjs/support/model/stage-transport.js +33 -7
  143. package/dist/cjs/support/model/strategies.js +75 -14
  144. package/dist/cjs/support/model/transports.js +53 -11
  145. package/dist/cjs/support/registration.js +49 -7
  146. package/dist/cjs/support/schema.js +46 -4
  147. package/dist/cjs/support/stream-events.js +60 -8
  148. package/dist/cjs/support/tool-runtime.js +6 -0
  149. package/dist/cjs/support/tools.js +79 -10
  150. package/dist/cjs/support/transport/index.js +7 -0
  151. package/dist/cjs/support/transport/json.js +28 -4
  152. package/dist/cjs/support/transport/sse.js +25 -2
  153. package/dist/cjs/utils/break-observer.js +20 -2
  154. package/dist/cjs/utils/cancellation.js +77 -9
  155. package/dist/cjs/utils/catalog.js +19 -4
  156. package/dist/cjs/utils/debug.js +14 -2
  157. package/dist/cjs/utils/index.js +8 -0
  158. package/dist/cjs/utils/interaction-definition.js +26 -6
  159. package/dist/cjs/utils/invocation.js +42 -4
  160. package/dist/cjs/utils/model-protocol.js +20 -1
  161. package/dist/cjs/utils/object.js +16 -0
  162. package/dist/cjs/utils/observer.js +22 -2
  163. package/dist/cjs/utils/protocol-registry.js +47 -4
  164. package/dist/cjs/utils/query-key.js +21 -2
  165. package/dist/cjs/utils/registration.js +18 -2
  166. package/dist/cjs/utils/rules.js +39 -11
  167. package/dist/cjs/utils/schema-adapter.js +25 -2
  168. package/dist/cjs/utils/synchronous.js +64 -7
  169. package/dist/cjs/utils/text.js +15 -1
  170. package/dist/esm/capabilities/index.d.ts +13 -0
  171. package/dist/esm/capabilities/index.js +13 -0
  172. package/dist/esm/capabilities/invocation.d.ts +16 -2
  173. package/dist/esm/capabilities/invocation.js +80 -10
  174. package/dist/esm/capabilities/model.d.ts +68 -1
  175. package/dist/esm/capabilities/model.js +126 -13
  176. package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
  177. package/dist/esm/capabilities/tool-runtime.js +64 -12
  178. package/dist/esm/capabilities/tools.d.ts +96 -3
  179. package/dist/esm/capabilities/tools.js +267 -32
  180. package/dist/esm/context/assembly.d.ts +13 -2
  181. package/dist/esm/context/assembly.js +46 -5
  182. package/dist/esm/context/audit.d.ts +23 -1
  183. package/dist/esm/context/audit.js +31 -6
  184. package/dist/esm/context/fragments.d.ts +37 -3
  185. package/dist/esm/context/fragments.js +54 -11
  186. package/dist/esm/context/index.d.ts +12 -0
  187. package/dist/esm/context/index.js +12 -0
  188. package/dist/esm/context/journal.d.ts +32 -1
  189. package/dist/esm/context/journal.js +84 -7
  190. package/dist/esm/context/plan.d.ts +11 -1
  191. package/dist/esm/context/plan.js +30 -2
  192. package/dist/esm/diagnostics/catalog.js +11 -3
  193. package/dist/esm/diagnostics/index.d.ts +30 -2
  194. package/dist/esm/diagnostics/index.js +149 -29
  195. package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
  196. package/dist/esm/diagnostics/sub-flow.js +240 -40
  197. package/dist/esm/errors.d.ts +22 -2
  198. package/dist/esm/errors.js +99 -17
  199. package/dist/esm/execution/branch.d.ts +19 -1
  200. package/dist/esm/execution/branch.js +20 -4
  201. package/dist/esm/execution/engine.d.ts +291 -5
  202. package/dist/esm/execution/engine.js +471 -57
  203. package/dist/esm/execution/events.d.ts +16 -2
  204. package/dist/esm/execution/events.js +136 -18
  205. package/dist/esm/execution/index.d.ts +7 -0
  206. package/dist/esm/execution/index.js +7 -0
  207. package/dist/esm/execution/reporting.d.ts +49 -1
  208. package/dist/esm/execution/reporting.js +75 -6
  209. package/dist/esm/execution/state.d.ts +126 -10
  210. package/dist/esm/execution/state.js +161 -22
  211. package/dist/esm/execution/workflow.d.ts +121 -3
  212. package/dist/esm/execution/workflow.js +224 -32
  213. package/dist/esm/index.d.ts +17 -1
  214. package/dist/esm/index.js +18 -0
  215. package/dist/esm/kits/aggregation.d.ts +34 -2
  216. package/dist/esm/kits/aggregation.js +45 -3
  217. package/dist/esm/kits/answering/batch.d.ts +17 -0
  218. package/dist/esm/kits/answering/batch.js +23 -4
  219. package/dist/esm/kits/answering/check-result.d.ts +18 -1
  220. package/dist/esm/kits/answering/check-result.js +31 -8
  221. package/dist/esm/kits/answering/checks.d.ts +11 -0
  222. package/dist/esm/kits/answering/checks.js +24 -3
  223. package/dist/esm/kits/answering/flow.d.ts +25 -2
  224. package/dist/esm/kits/answering/flow.js +192 -36
  225. package/dist/esm/kits/answering/index.d.ts +12 -0
  226. package/dist/esm/kits/answering/index.js +19 -1
  227. package/dist/esm/kits/answering/tasks.d.ts +32 -1
  228. package/dist/esm/kits/answering/tasks.js +88 -13
  229. package/dist/esm/kits/artifacts.d.ts +11 -0
  230. package/dist/esm/kits/artifacts.js +36 -4
  231. package/dist/esm/kits/candidates.d.ts +23 -1
  232. package/dist/esm/kits/candidates.js +47 -5
  233. package/dist/esm/kits/delivery.d.ts +34 -0
  234. package/dist/esm/kits/delivery.js +40 -5
  235. package/dist/esm/kits/durable.d.ts +19 -0
  236. package/dist/esm/kits/durable.js +155 -31
  237. package/dist/esm/kits/evidence.d.ts +28 -5
  238. package/dist/esm/kits/evidence.js +66 -15
  239. package/dist/esm/kits/family.d.ts +17 -1
  240. package/dist/esm/kits/family.js +152 -22
  241. package/dist/esm/kits/index.d.ts +12 -1
  242. package/dist/esm/kits/index.js +12 -1
  243. package/dist/esm/kits/inference.d.ts +64 -0
  244. package/dist/esm/kits/inference.js +104 -16
  245. package/dist/esm/kits/intents/catalog.d.ts +13 -1
  246. package/dist/esm/kits/intents/catalog.js +67 -16
  247. package/dist/esm/kits/intents/index.d.ts +11 -0
  248. package/dist/esm/kits/intents/index.js +11 -0
  249. package/dist/esm/kits/intents/registry.d.ts +61 -3
  250. package/dist/esm/kits/intents/registry.js +188 -43
  251. package/dist/esm/kits/intents/scopes.d.ts +73 -3
  252. package/dist/esm/kits/intents/scopes.js +215 -46
  253. package/dist/esm/kits/interaction/command.d.ts +38 -4
  254. package/dist/esm/kits/interaction/command.js +140 -36
  255. package/dist/esm/kits/interaction/commands.d.ts +66 -2
  256. package/dist/esm/kits/interaction/commands.js +86 -11
  257. package/dist/esm/kits/interaction/handlers.d.ts +19 -2
  258. package/dist/esm/kits/interaction/handlers.js +27 -10
  259. package/dist/esm/kits/interaction/index.d.ts +10 -0
  260. package/dist/esm/kits/interaction/index.js +10 -0
  261. package/dist/esm/kits/interaction/transfer.d.ts +39 -2
  262. package/dist/esm/kits/interaction/transfer.js +80 -14
  263. package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
  264. package/dist/esm/kits/knowledge/catalog.js +62 -11
  265. package/dist/esm/kits/knowledge/index.d.ts +11 -0
  266. package/dist/esm/kits/knowledge/index.js +16 -1
  267. package/dist/esm/kits/knowledge/publication.d.ts +15 -1
  268. package/dist/esm/kits/knowledge/publication.js +99 -23
  269. package/dist/esm/kits/knowledge/sections.d.ts +31 -1
  270. package/dist/esm/kits/knowledge/sections.js +33 -4
  271. package/dist/esm/kits/normalization.d.ts +25 -2
  272. package/dist/esm/kits/normalization.js +51 -7
  273. package/dist/esm/kits/policies.d.ts +26 -3
  274. package/dist/esm/kits/policies.js +79 -15
  275. package/dist/esm/kits/presentation/events.d.ts +51 -4
  276. package/dist/esm/kits/presentation/events.js +54 -10
  277. package/dist/esm/kits/presentation/index.d.ts +12 -0
  278. package/dist/esm/kits/presentation/index.js +25 -2
  279. package/dist/esm/kits/presentation/outputs.d.ts +30 -1
  280. package/dist/esm/kits/presentation/outputs.js +176 -38
  281. package/dist/esm/kits/presentation/templates.d.ts +32 -3
  282. package/dist/esm/kits/presentation/templates.js +33 -5
  283. package/dist/esm/kits/presentation/variants.d.ts +29 -0
  284. package/dist/esm/kits/presentation/variants.js +31 -2
  285. package/dist/esm/kits/projection.d.ts +42 -5
  286. package/dist/esm/kits/projection.js +63 -8
  287. package/dist/esm/kits/rank-fusion.d.ts +21 -1
  288. package/dist/esm/kits/rank-fusion.js +28 -5
  289. package/dist/esm/kits/reflection-log-source.d.ts +28 -1
  290. package/dist/esm/kits/reflection-log-source.js +89 -16
  291. package/dist/esm/kits/reflection.d.ts +17 -1
  292. package/dist/esm/kits/reflection.js +235 -61
  293. package/dist/esm/kits/retrieval.d.ts +18 -2
  294. package/dist/esm/kits/retrieval.js +98 -18
  295. package/dist/esm/kits/search.d.ts +56 -3
  296. package/dist/esm/kits/search.js +180 -27
  297. package/dist/esm/kits/text-skills.d.ts +16 -2
  298. package/dist/esm/kits/text-skills.js +104 -19
  299. package/dist/esm/kits/tools.d.ts +122 -2
  300. package/dist/esm/kits/tools.js +416 -74
  301. package/dist/esm/kits/vector-search.d.ts +47 -1
  302. package/dist/esm/kits/vector-search.js +51 -17
  303. package/dist/esm/mock/node.d.ts +7 -0
  304. package/dist/esm/mock/node.js +7 -1
  305. package/dist/esm/mock/web.d.ts +7 -0
  306. package/dist/esm/mock/web.js +7 -1
  307. package/dist/esm/mock.d.ts +7 -0
  308. package/dist/esm/mock.js +7 -1
  309. package/dist/esm/model/binding.d.ts +32 -3
  310. package/dist/esm/model/binding.js +68 -17
  311. package/dist/esm/model/call-budget.d.ts +30 -2
  312. package/dist/esm/model/call-budget.js +45 -4
  313. package/dist/esm/model/decision-retry.d.ts +10 -1
  314. package/dist/esm/model/decision-retry.js +19 -1
  315. package/dist/esm/model/defaults.d.ts +13 -2
  316. package/dist/esm/model/defaults.js +27 -4
  317. package/dist/esm/model/index.d.ts +7 -0
  318. package/dist/esm/model/index.js +7 -0
  319. package/dist/esm/model/interactions/arguments.d.ts +27 -0
  320. package/dist/esm/model/interactions/arguments.js +36 -1
  321. package/dist/esm/model/interactions/json-object.d.ts +7 -1
  322. package/dist/esm/model/interactions/json-object.js +48 -12
  323. package/dist/esm/model/interactions/native-functions.d.ts +6 -0
  324. package/dist/esm/model/interactions/native-functions.js +52 -10
  325. package/dist/esm/model/message-diagnostics.d.ts +17 -1
  326. package/dist/esm/model/message-diagnostics.js +17 -4
  327. package/dist/esm/model/options.d.ts +18 -1
  328. package/dist/esm/model/options.js +9 -1
  329. package/dist/esm/model/preparation.d.ts +30 -2
  330. package/dist/esm/model/preparation.js +86 -12
  331. package/dist/esm/model/runner.d.ts +129 -5
  332. package/dist/esm/model/runner.js +414 -80
  333. package/dist/esm/model/selection-transport.d.ts +14 -1
  334. package/dist/esm/model/selection-transport.js +48 -8
  335. package/dist/esm/model/settings.d.ts +11 -0
  336. package/dist/esm/model/settings.js +67 -13
  337. package/dist/esm/model/token-budget.d.ts +59 -1
  338. package/dist/esm/model/token-budget.js +69 -11
  339. package/dist/esm/model/transports.d.ts +20 -2
  340. package/dist/esm/model/transports.js +59 -6
  341. package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
  342. package/dist/esm/structs/capabilities/model.d.ts +27 -0
  343. package/dist/esm/structs/capabilities/tools.d.ts +38 -0
  344. package/dist/esm/structs/common.d.ts +62 -2
  345. package/dist/esm/structs/common.js +11 -0
  346. package/dist/esm/structs/context/fragments.d.ts +28 -0
  347. package/dist/esm/structs/context/journal.d.ts +28 -3
  348. package/dist/esm/structs/context/processing.d.ts +11 -0
  349. package/dist/esm/structs/debug.d.ts +58 -1
  350. package/dist/esm/structs/debug.js +34 -5
  351. package/dist/esm/structs/diagnostics.d.ts +119 -1
  352. package/dist/esm/structs/errors.d.ts +42 -1
  353. package/dist/esm/structs/errors.js +26 -1
  354. package/dist/esm/structs/execution/engine.d.ts +24 -1
  355. package/dist/esm/structs/execution/events.d.ts +12 -0
  356. package/dist/esm/structs/execution/workflow.d.ts +71 -0
  357. package/dist/esm/structs/index.d.ts +11 -1
  358. package/dist/esm/structs/index.js +11 -1
  359. package/dist/esm/structs/invocation.d.ts +30 -0
  360. package/dist/esm/structs/kits/aggregation.d.ts +12 -0
  361. package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
  362. package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
  363. package/dist/esm/structs/kits/answering/state.d.ts +21 -0
  364. package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
  365. package/dist/esm/structs/kits/artifacts.d.ts +14 -0
  366. package/dist/esm/structs/kits/candidates.d.ts +19 -0
  367. package/dist/esm/structs/kits/delivery.d.ts +22 -0
  368. package/dist/esm/structs/kits/durable.d.ts +56 -3
  369. package/dist/esm/structs/kits/durable.js +7 -0
  370. package/dist/esm/structs/kits/evidence.d.ts +23 -0
  371. package/dist/esm/structs/kits/family.d.ts +49 -1
  372. package/dist/esm/structs/kits/family.js +1 -0
  373. package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
  374. package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
  375. package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
  376. package/dist/esm/structs/kits/interaction.d.ts +64 -0
  377. package/dist/esm/structs/kits/interaction.js +8 -1
  378. package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
  379. package/dist/esm/structs/kits/knowledge-publication.js +1 -0
  380. package/dist/esm/structs/kits/knowledge.d.ts +39 -2
  381. package/dist/esm/structs/kits/normalization.d.ts +15 -0
  382. package/dist/esm/structs/kits/policies.d.ts +25 -1
  383. package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
  384. package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
  385. package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
  386. package/dist/esm/structs/kits/projection.d.ts +21 -0
  387. package/dist/esm/structs/kits/reflection.d.ts +61 -2
  388. package/dist/esm/structs/kits/reflection.js +18 -3
  389. package/dist/esm/structs/kits/retrieval.d.ts +38 -0
  390. package/dist/esm/structs/kits/search.d.ts +22 -0
  391. package/dist/esm/structs/kits/text-skills.d.ts +36 -0
  392. package/dist/esm/structs/kits/tools.d.ts +87 -0
  393. package/dist/esm/structs/model/chat-provider.d.ts +24 -1
  394. package/dist/esm/structs/model/chat-provider.js +6 -0
  395. package/dist/esm/structs/model/interactions.d.ts +38 -0
  396. package/dist/esm/structs/model/messages.d.ts +30 -0
  397. package/dist/esm/structs/model/runtime.d.ts +104 -6
  398. package/dist/esm/structs/support/capabilities.d.ts +19 -2
  399. package/dist/esm/structs/support/context-processing.d.ts +88 -9
  400. package/dist/esm/structs/support/context.d.ts +29 -1
  401. package/dist/esm/structs/support/model/completion.d.ts +50 -0
  402. package/dist/esm/structs/support/model/completion.js +1 -0
  403. package/dist/esm/structs/support/model/interactions.d.ts +13 -1
  404. package/dist/esm/structs/support/model/messages.d.ts +52 -0
  405. package/dist/esm/structs/support/model/messages.js +1 -0
  406. package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
  407. package/dist/esm/structs/support/model/provider.d.ts +71 -6
  408. package/dist/esm/structs/support/registration.d.ts +13 -0
  409. package/dist/esm/structs/support/schema.d.ts +14 -0
  410. package/dist/esm/structs/support/tools.d.ts +28 -0
  411. package/dist/esm/structs/support/transport/json.d.ts +16 -0
  412. package/dist/esm/structs/support/transport/sse.d.ts +15 -0
  413. package/dist/esm/structs/utils/rules.d.ts +19 -0
  414. package/dist/esm/support/capabilities.d.ts +25 -2
  415. package/dist/esm/support/capabilities.js +43 -6
  416. package/dist/esm/support/context/assembly.d.ts +35 -4
  417. package/dist/esm/support/context/assembly.js +88 -16
  418. package/dist/esm/support/context/compression.d.ts +17 -1
  419. package/dist/esm/support/context/compression.js +48 -6
  420. package/dist/esm/support/context/fragments.d.ts +6 -0
  421. package/dist/esm/support/context/fragments.js +6 -0
  422. package/dist/esm/support/context/history.d.ts +43 -0
  423. package/dist/esm/support/context/history.js +36 -1
  424. package/dist/esm/support/context/index.d.ts +13 -2
  425. package/dist/esm/support/context/index.js +12 -1
  426. package/dist/esm/support/context/nodes.d.ts +49 -3
  427. package/dist/esm/support/context/nodes.js +165 -36
  428. package/dist/esm/support/context/processing.d.ts +145 -1
  429. package/dist/esm/support/context/processing.js +320 -62
  430. package/dist/esm/support/context/selection-policy.d.ts +42 -2
  431. package/dist/esm/support/context/selection-policy.js +98 -21
  432. package/dist/esm/support/context/selection.d.ts +14 -1
  433. package/dist/esm/support/context/selection.js +61 -10
  434. package/dist/esm/support/context/snapshot.d.ts +23 -1
  435. package/dist/esm/support/context/snapshot.js +29 -7
  436. package/dist/esm/support/context/strategies.d.ts +35 -2
  437. package/dist/esm/support/context/strategies.js +120 -28
  438. package/dist/esm/support/index.d.ts +9 -1
  439. package/dist/esm/support/index.js +9 -1
  440. package/dist/esm/support/model/capabilities.d.ts +10 -0
  441. package/dist/esm/support/model/capabilities.js +20 -1
  442. package/dist/esm/support/model/chat-completions.d.ts +44 -15
  443. package/dist/esm/support/model/chat-completions.js +92 -20
  444. package/dist/esm/support/model/children.d.ts +32 -2
  445. package/dist/esm/support/model/children.js +34 -6
  446. package/dist/esm/support/model/compatible-provider.d.ts +29 -3
  447. package/dist/esm/support/model/compatible-provider.js +190 -60
  448. package/dist/esm/support/model/completion/calls.d.ts +40 -0
  449. package/dist/esm/support/model/completion/calls.js +58 -0
  450. package/dist/esm/support/model/completion/default.d.ts +10 -0
  451. package/dist/esm/support/model/completion/default.js +29 -0
  452. package/dist/esm/support/model/completion/index.d.ts +10 -0
  453. package/dist/esm/support/model/completion/index.js +22 -0
  454. package/dist/esm/support/model/completion/session.d.ts +11 -0
  455. package/dist/esm/support/model/completion/session.js +99 -0
  456. package/dist/esm/support/model/index.d.ts +14 -0
  457. package/dist/esm/support/model/index.js +12 -0
  458. package/dist/esm/support/model/interactions/index.d.ts +1 -1
  459. package/dist/esm/support/model/interactions/index.js +12 -1
  460. package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
  461. package/dist/esm/support/model/interactions/json-object.js +6 -0
  462. package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
  463. package/dist/esm/support/model/interactions/native-functions.js +6 -0
  464. package/dist/esm/support/model/observer.d.ts +25 -2
  465. package/dist/esm/support/model/observer.js +32 -6
  466. package/dist/esm/support/model/preview-rules.d.ts +20 -2
  467. package/dist/esm/support/model/preview-rules.js +66 -16
  468. package/dist/esm/support/model/reply-preview.d.ts +15 -1
  469. package/dist/esm/support/model/reply-preview.js +77 -17
  470. package/dist/esm/support/model/stage-transport.d.ts +9 -1
  471. package/dist/esm/support/model/stage-transport.js +33 -7
  472. package/dist/esm/support/model/strategies.d.ts +24 -2
  473. package/dist/esm/support/model/strategies.js +75 -14
  474. package/dist/esm/support/model/transports.d.ts +17 -1
  475. package/dist/esm/support/model/transports.js +53 -11
  476. package/dist/esm/support/registration.d.ts +20 -1
  477. package/dist/esm/support/registration.js +49 -7
  478. package/dist/esm/support/schema.d.ts +31 -1
  479. package/dist/esm/support/schema.js +46 -4
  480. package/dist/esm/support/stream-events.d.ts +22 -1
  481. package/dist/esm/support/stream-events.js +60 -8
  482. package/dist/esm/support/tool-runtime.d.ts +6 -0
  483. package/dist/esm/support/tool-runtime.js +6 -0
  484. package/dist/esm/support/tools.d.ts +22 -0
  485. package/dist/esm/support/tools.js +79 -10
  486. package/dist/esm/support/transport/index.d.ts +7 -0
  487. package/dist/esm/support/transport/index.js +7 -0
  488. package/dist/esm/support/transport/json.d.ts +29 -2
  489. package/dist/esm/support/transport/json.js +28 -4
  490. package/dist/esm/support/transport/sse.d.ts +31 -1
  491. package/dist/esm/support/transport/sse.js +25 -2
  492. package/dist/esm/types.d.ts +9 -1
  493. package/dist/esm/utils/break-observer.d.ts +27 -2
  494. package/dist/esm/utils/break-observer.js +20 -2
  495. package/dist/esm/utils/cancellation.d.ts +56 -5
  496. package/dist/esm/utils/cancellation.js +77 -9
  497. package/dist/esm/utils/catalog.d.ts +20 -1
  498. package/dist/esm/utils/catalog.js +19 -4
  499. package/dist/esm/utils/debug.d.ts +20 -1
  500. package/dist/esm/utils/debug.js +14 -2
  501. package/dist/esm/utils/index.d.ts +8 -0
  502. package/dist/esm/utils/index.js +8 -0
  503. package/dist/esm/utils/interaction-definition.d.ts +18 -1
  504. package/dist/esm/utils/interaction-definition.js +26 -6
  505. package/dist/esm/utils/invocation.d.ts +36 -1
  506. package/dist/esm/utils/invocation.js +42 -4
  507. package/dist/esm/utils/model-protocol.d.ts +8 -0
  508. package/dist/esm/utils/model-protocol.js +20 -1
  509. package/dist/esm/utils/object.d.ts +16 -0
  510. package/dist/esm/utils/object.js +16 -0
  511. package/dist/esm/utils/observer.d.ts +19 -1
  512. package/dist/esm/utils/observer.js +22 -2
  513. package/dist/esm/utils/protocol-registry.d.ts +38 -1
  514. package/dist/esm/utils/protocol-registry.js +47 -4
  515. package/dist/esm/utils/query-key.d.ts +11 -1
  516. package/dist/esm/utils/query-key.js +21 -2
  517. package/dist/esm/utils/registration.d.ts +34 -2
  518. package/dist/esm/utils/registration.js +18 -2
  519. package/dist/esm/utils/rules.d.ts +81 -4
  520. package/dist/esm/utils/rules.js +39 -11
  521. package/dist/esm/utils/schema-adapter.d.ts +12 -1
  522. package/dist/esm/utils/schema-adapter.js +25 -2
  523. package/dist/esm/utils/synchronous.d.ts +60 -4
  524. package/dist/esm/utils/synchronous.js +64 -7
  525. package/dist/esm/utils/text.d.ts +15 -1
  526. package/dist/esm/utils/text.js +15 -1
  527. package/package.json +23 -3
@@ -1,5 +1,15 @@
1
+ /**
2
+ * Derive unique route ids for one node.
3
+ *
4
+ * Explicit ids are reserved before any suffix is generated, so a generated `~2` id can
5
+ * never collide with an id that is already declared later in the same node. The first
6
+ * occurrence keeps its id; later duplicates are renamed deterministically in order.
7
+ *
8
+ * @param routes - Routes of one node, in declaration order.
9
+ * @returns One id per route, using undefined where the route declared none.
10
+ */
1
11
  function assignRouteIds(routes) {
2
- const reserved = new Set(routes.map(route => route.id));
12
+ const reserved = new Set(routes.map((route) => route.id));
3
13
  const used = new Set();
4
14
  return routes.map(({ id }) => {
5
15
  if (id === undefined)
@@ -13,17 +23,44 @@ function assignRouteIds(routes) {
13
23
  return id;
14
24
  });
15
25
  }
26
+ /**
27
+ * Reject node fields that were renamed.
28
+ *
29
+ * Accepting `round` or `onError` silently would change budget and recovery behavior, so
30
+ * the older names are reported instead of being mapped.
31
+ *
32
+ * @param node - Node about to be registered.
33
+ * @throws TypeError When a renamed field is present.
34
+ */
16
35
  function validateNodeFields(node) {
17
36
  if ('round' in node || 'onError' in node)
18
37
  throw new TypeError(`Use startsRound and onErrorNodeId: ${node.id}`);
19
38
  }
20
- /** Executable catalog: validate references and bounded cycles before any handler runs. */
39
+ /**
40
+ * Executable catalog: validate references and bounded cycles before any handler runs.
41
+ *
42
+ * Validation happens once, at construction, so traversal can assume every target exists
43
+ * and every cycle is budget-bounded.
44
+ */
21
45
  export class AgentWorkflow {
46
+ /** Workflow id, also used in diagnostics and error messages. */
22
47
  id;
48
+ /** First node visited; always starts a round. */
23
49
  entryNodeId;
50
+ /** Optional revision passed through to diagnostics. */
24
51
  revision;
52
+ /** Optional result guard; when present it must return exactly true. */
25
53
  isResult;
26
54
  nodes = new Map();
55
+ /**
56
+ * Build and validate a workflow.
57
+ *
58
+ * The entry node must start a round, because otherwise a workflow could loop forever
59
+ * without consuming the round budget. Renamed top-level fields are rejected as well.
60
+ *
61
+ * @param definition - Nodes, entry, id, optional revision and result guard.
62
+ * @throws TypeError When the definition, a node, a route or a graph invariant is invalid.
63
+ */
27
64
  constructor(definition) {
28
65
  if ('entry' in definition || 'validateResult' in definition)
29
66
  throw new TypeError('Use entryNodeId and isResult');
@@ -43,18 +80,33 @@ export class AgentWorkflow {
43
80
  this.checkReachability();
44
81
  this.checkBoundedCycles();
45
82
  }
83
+ /**
84
+ * Derive an extended workflow without mutating this catalog.
85
+ *
86
+ * Every node is copied with its callbacks rebound, so the new catalog keeps the same
87
+ * entry and result guard and can be composed repeatedly. Route overrides are keyed by
88
+ * node id and must name a node that exists after the merge.
89
+ *
90
+ * @param extension - Extension patch, or another workflow whose definitions are merged.
91
+ * @param routes - Route overrides keyed by node id.
92
+ * @returns A new, fully re-validated workflow.
93
+ * @throws TypeError When an override names an unknown node or a node is invalid.
94
+ */
46
95
  add(extension, routes = {}) {
47
96
  const patch = extension instanceof AgentWorkflow ? { nodes: extension.definitions, routes } : extension;
48
97
  for (const node of patch.nodes)
49
98
  validateNodeFields(node);
50
99
  const nodes = [...this.definitions, ...patch.nodes];
51
100
  for (const id of Object.keys(patch.routes ?? {})) {
52
- if (!nodes.some(node => node.id === id))
101
+ if (!nodes.some((node) => node.id === id))
53
102
  throw new TypeError(`Unknown workflow route source: ${id}`);
54
103
  }
55
104
  return new AgentWorkflow({
56
- id: this.id, revision: patch.revision, entryNodeId: this.entryNodeId, isResult: this.isResult,
57
- nodes: nodes.map(node => ({
105
+ id: this.id,
106
+ revision: patch.revision,
107
+ entryNodeId: this.entryNodeId,
108
+ isResult: this.isResult,
109
+ nodes: nodes.map((node) => ({
58
110
  id: node.id,
59
111
  description: node.description,
60
112
  name: node.name,
@@ -69,49 +121,117 @@ export class AgentWorkflow {
69
121
  })),
70
122
  });
71
123
  }
124
+ /**
125
+ * Look up a node that must exist.
126
+ *
127
+ * @param id - Node id.
128
+ * @returns The registered node.
129
+ * @throws TypeError When the node is unknown.
130
+ */
72
131
  require(id) {
73
132
  const node = this.nodes.get(id);
74
133
  if (!node)
75
134
  throw new TypeError(`Unknown workflow node: ${id}`);
76
135
  return node;
77
136
  }
78
- get definitions() { return Object.freeze([...this.nodes.values()]); }
79
- ids() { return Object.freeze([...this.nodes.keys()]); }
80
- values() { return this.nodes.values(); }
81
- entries() { return this.nodes.entries(); }
82
- has(id) { return this.nodes.has(id); }
83
- get(id) { return this.nodes.get(id); }
137
+ /** Frozen snapshot of all nodes, in registration order. */
138
+ get definitions() {
139
+ return Object.freeze([...this.nodes.values()]);
140
+ }
141
+ /** @returns A frozen array of node ids in registration order. */
142
+ ids() {
143
+ return Object.freeze([...this.nodes.keys()]);
144
+ }
145
+ /** @returns An iterator over the registered nodes. */
146
+ values() {
147
+ return this.nodes.values();
148
+ }
149
+ /** @returns An iterator over id/node pairs. */
150
+ entries() {
151
+ return this.nodes.entries();
152
+ }
153
+ /**
154
+ * @param id - Node id.
155
+ * @returns Whether the node is registered.
156
+ */
157
+ has(id) {
158
+ return this.nodes.has(id);
159
+ }
160
+ /**
161
+ * @param id - Node id.
162
+ * @returns The node, or undefined when it is not registered.
163
+ */
164
+ get(id) {
165
+ return this.nodes.get(id);
166
+ }
167
+ /**
168
+ * Produce a serializable description of every node and route.
169
+ *
170
+ * Used by documentation and registration listings; it reports resolved ids and which
171
+ * routes are terminal or conditional, never the handler implementations.
172
+ *
173
+ * @returns An array of plain description objects in registration order.
174
+ */
84
175
  describe() {
85
- return [...this.nodes.values()].map(node => ({
86
- id: node.id, description: node.description, ...(node.name ? { name: node.name } : {}), startsRound: node.startsRound === true, onErrorNodeId: node.onErrorNodeId,
87
- requires: node.requires ?? [], provides: node.provides ?? [],
88
- routes: node.routes.map(route => ({ ...(route.id !== undefined ? { id: route.id } : {}), ...(route.description !== undefined ? { description: route.description } : {}), ...(route.conditionId !== undefined ? { conditionId: route.conditionId } : {}), targetNodeId: route.targetNodeId, terminal: !!route.complete, conditional: !!route.when })),
176
+ return [...this.nodes.values()].map((node) => ({
177
+ id: node.id,
178
+ description: node.description,
179
+ ...(node.name ? { name: node.name } : {}),
180
+ startsRound: node.startsRound === true,
181
+ onErrorNodeId: node.onErrorNodeId,
182
+ requires: node.requires ?? [],
183
+ provides: node.provides ?? [],
184
+ routes: node.routes.map((route) => ({
185
+ ...(route.id !== undefined ? { id: route.id } : {}),
186
+ ...(route.description !== undefined ? { description: route.description } : {}),
187
+ ...(route.conditionId !== undefined ? { conditionId: route.conditionId } : {}),
188
+ targetNodeId: route.targetNodeId,
189
+ terminal: !!route.complete,
190
+ conditional: !!route.when,
191
+ })),
89
192
  }));
90
193
  }
194
+ /**
195
+ * Validate and freeze one node, then add it to the catalog.
196
+ *
197
+ * A route must be either a jump with a target or a completion, never both; an
198
+ * unconditional route must be last, because it would shadow every later route. Route
199
+ * ids and condition ids are resolved here so the engine never interpolates templates at
200
+ * run time.
201
+ *
202
+ * @param node - Node supplied by the workflow definition.
203
+ * @throws TypeError When the node, a route or a state contract is invalid.
204
+ */
91
205
  register(node) {
92
- if (!node.id?.trim() || !node.description?.trim() || this.nodes.has(node.id) || !node.routes.length
93
- || (node.run !== undefined && typeof node.run !== 'function')) {
206
+ if (!node.id?.trim() ||
207
+ !node.description?.trim() ||
208
+ this.nodes.has(node.id) ||
209
+ !node.routes.length ||
210
+ (node.run !== undefined && typeof node.run !== 'function')) {
94
211
  throw new TypeError('Invalid or duplicate workflow node');
95
212
  }
96
213
  validateNodeFields(node);
97
- if (node.onErrorRouteId !== undefined && (!node.onErrorRouteId.trim() || !(node.onErrorNodeId)))
214
+ if (node.onErrorRouteId !== undefined && (!node.onErrorRouteId.trim() || !node.onErrorNodeId))
98
215
  throw new TypeError(`Invalid workflow error route identity: ${node.id}`);
99
216
  const ids = assignRouteIds(node.routes);
100
217
  for (const [index, route] of node.routes.entries()) {
101
- if (('to' in route)
102
- || (route.id !== undefined && !route.id.trim())
103
- || (route.conditionId !== undefined && (!route.conditionId.trim() || !route.when)))
218
+ if ('to' in route ||
219
+ (route.id !== undefined && !route.id.trim()) ||
220
+ (route.conditionId !== undefined && (!route.conditionId.trim() || !route.when)))
104
221
  throw new TypeError(`Invalid workflow route identity: ${node.id}`);
105
222
  const hasTarget = typeof route.targetNodeId === 'string';
106
223
  const hasCompletion = typeof route.complete === 'function';
107
224
  const shadowsFollowingRoutes = !route.when && index !== node.routes.length - 1;
108
- if (hasTarget === hasCompletion || shadowsFollowingRoutes
109
- || (route.when !== undefined && typeof route.when !== 'function')) {
225
+ if (hasTarget === hasCompletion ||
226
+ shadowsFollowingRoutes ||
227
+ (route.when !== undefined && typeof route.when !== 'function')) {
110
228
  throw new TypeError(`Invalid or unreachable workflow route: ${node.id}`);
111
229
  }
112
230
  }
113
231
  for (const fields of [node.requires, node.provides]) {
114
- if (fields && (fields.some(field => typeof field !== 'string' || !field.trim()) || new Set(fields).size !== fields.length)) {
232
+ if (fields &&
233
+ (fields.some((field) => typeof field !== 'string' || !field.trim()) ||
234
+ new Set(fields).size !== fields.length)) {
115
235
  throw new TypeError(`Invalid workflow state contract: ${node.id}`);
116
236
  }
117
237
  }
@@ -124,29 +244,68 @@ export class AgentWorkflow {
124
244
  throw new TypeError(`Condition ID references a missing route ID: ${node.id}`);
125
245
  return id;
126
246
  });
127
- const common = { id, description: route.description, conditionId, when: route.when?.bind(route) };
128
- return Object.freeze(route.complete ? { ...common, complete: route.complete.bind(route) }
247
+ const common = {
248
+ id,
249
+ description: route.description,
250
+ conditionId,
251
+ when: route.when?.bind(route),
252
+ };
253
+ return Object.freeze(route.complete
254
+ ? { ...common, complete: route.complete.bind(route) }
129
255
  : { ...common, targetNodeId: route.targetNodeId });
130
256
  }));
257
+ // The entry node starts a round unless it says otherwise; any other node starts one
258
+ // only when it declares it explicitly.
131
259
  const startsRound = node.startsRound ?? (node.id === this.entryNodeId ? true : undefined);
132
- this.nodes.set(node.id, Object.freeze({ ...node, id: node.id, description: node.description, name: node.name, report: node.report?.bind(node), startsRound, onErrorRouteId: node.onErrorRouteId,
133
- onErrorNodeId: node.onErrorNodeId, run: node.run?.bind(node), routes,
260
+ this.nodes.set(node.id, Object.freeze({
261
+ ...node,
262
+ id: node.id,
263
+ description: node.description,
264
+ name: node.name,
265
+ report: node.report?.bind(node),
266
+ startsRound,
267
+ onErrorRouteId: node.onErrorRouteId,
268
+ onErrorNodeId: node.onErrorNodeId,
269
+ run: node.run?.bind(node),
270
+ routes,
134
271
  requires: node.requires ? Object.freeze([...node.requires]) : undefined,
135
272
  provides: node.provides ? Object.freeze([...node.provides]) : undefined,
136
273
  }));
137
274
  }
275
+ /**
276
+ * Collect every node a visit can hand control to.
277
+ *
278
+ * Error targets are included so a recovery node is treated as reachable and is subject
279
+ * to the same cycle rule as a normal transition.
280
+ *
281
+ * @param node - Node whose outgoing edges are collected.
282
+ * @returns Target node ids, including the error node.
283
+ */
138
284
  targets(node) {
139
- const targets = node.routes.flatMap(route => route.targetNodeId !== undefined ? [route.targetNodeId] : []);
285
+ const targets = node.routes.flatMap((route) => route.targetNodeId !== undefined ? [route.targetNodeId] : []);
140
286
  if (node.onErrorNodeId !== undefined)
141
287
  targets.push(node.onErrorNodeId);
142
288
  return targets;
143
289
  }
290
+ /**
291
+ * Require every route target to name a registered node.
292
+ *
293
+ * @throws TypeError When any target is unknown.
294
+ */
144
295
  checkReferences() {
145
296
  for (const node of this.nodes.values()) {
146
297
  for (const target of this.targets(node))
147
298
  this.require(target);
148
299
  }
149
300
  }
301
+ /**
302
+ * Require every node to be reachable from the entry.
303
+ *
304
+ * An unreachable node is a declaration mistake: it would never run, yet it still
305
+ * appears in listings and documentation.
306
+ *
307
+ * @throws TypeError When any node cannot be reached.
308
+ */
150
309
  checkReachability() {
151
310
  const reachable = new Set();
152
311
  const visit = (id) => {
@@ -160,6 +319,11 @@ export class AgentWorkflow {
160
319
  if (reachable.size !== this.nodes.size)
161
320
  throw new TypeError('Unreachable workflow node');
162
321
  }
322
+ /**
323
+ * Require every cycle to cross a round boundary.
324
+ *
325
+ * @throws TypeError When a cycle can be traversed without ever starting a new round.
326
+ */
163
327
  checkBoundedCycles() {
164
328
  // Graph traversal is procedural: every possible cycle, including error routes,
165
329
  // must cross a round boundary so the engine can enforce the shared budget.
@@ -181,20 +345,47 @@ export class AgentWorkflow {
181
345
  visit(id);
182
346
  }
183
347
  }
348
+ /**
349
+ * Build a validated workflow from a definition.
350
+ *
351
+ * @param definition - Workflow definition; validated like the constructor argument.
352
+ * @returns A validated, immutable workflow catalog.
353
+ * @throws TypeError When the definition is invalid.
354
+ */
184
355
  export function defineWorkflow(definition) {
185
356
  return new AgentWorkflow(definition);
186
357
  }
187
- /** Successful acquisitions consume attempts; a refused acquisition never grants another. */
358
+ /**
359
+ * Successful acquisitions consume attempts; a refused acquisition never grants another.
360
+ *
361
+ * `available` is a snapshot of the counter, not a reservation: a caller must still call
362
+ * `take` and honor its boolean result before acting.
363
+ */
188
364
  export class AttemptBudget {
189
365
  limit;
190
366
  consumed = 0;
367
+ /**
368
+ * @param limit - Total attempts allowed; must be a nonnegative integer.
369
+ * @throws TypeError When `limit` is not a nonnegative integer.
370
+ */
191
371
  constructor(limit) {
192
372
  this.limit = limit;
193
373
  if (!Number.isInteger(limit) || limit < 0)
194
374
  throw new TypeError('Attempt limit must be a nonnegative integer');
195
375
  }
196
- get used() { return this.consumed; }
197
- get available() { return this.consumed < this.limit; }
376
+ /** Attempts consumed so far. */
377
+ get used() {
378
+ return this.consumed;
379
+ }
380
+ /** Whether at least one attempt remains unspent. */
381
+ get available() {
382
+ return this.consumed < this.limit;
383
+ }
384
+ /**
385
+ * Consume one attempt if one remains.
386
+ *
387
+ * @returns True when the attempt was granted, false when the budget is exhausted.
388
+ */
198
389
  take() {
199
390
  if (!this.available)
200
391
  return false;
@@ -202,5 +393,6 @@ export class AttemptBudget {
202
393
  return true;
203
394
  }
204
395
  }
396
+ // Re-exported so workflow authors get state helpers and route builders from one module.
205
397
  export { requireWorkflowValue, route } from './state.js';
206
398
  export { WorkflowContractError } from '../structs/errors.js';
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Aggregate public entry of `@jangts/agent-core`: Core runtime contracts, one `Support`
3
+ * namespace with a few named Support helpers, and the declaration helpers of optional Kits.
4
+ *
5
+ * Layering. Core owns the runtime contracts Apps call (engine, model runner, capabilities,
6
+ * context, diagnostics) and the handler contracts Core calls back into the App. Support only
7
+ * supplies recommended implementations of those same contracts, so it is published as a single
8
+ * namespace instead of a second dispatch layer. Kits are optional business libraries reached
9
+ * through their own subpath entries; the Kit entries re-exported here are declaration helpers
10
+ * and standalone modules, not additional Core guarantees. Shared utilities are re-exported
11
+ * because they are needed alongside these contracts, and they carry no Agent semantics.
12
+ *
13
+ * Exports are grouped by responsibility, not by dependency order. Deep subpath entries
14
+ * (`/engine`, `/model`, `/tools`, `/context`, `/journal`, `/diagnostics`, `/kits/...`)
15
+ * resolve to the same implementations, so this file is a convenience surface only.
16
+ */
1
17
  export * from './execution/engine.js';
2
18
  export { getErrorInfo } from './errors.js';
3
19
  export { BudgetError, ValidationError, type AgentErrorInfo } from './structs/errors.js';
@@ -10,7 +26,7 @@ export * from './context/journal.js';
10
26
  export { assembleFragments } from './context/assembly.js';
11
27
  export * from './support/context/assembly.js';
12
28
  export { defineEvidenceChecklist, defineEvidenceProjection } from './kits/evidence.js';
13
- export type { EvidenceRequirement, EvidenceProvider, EvidenceProjectionDefinition, EvidenceProjectionProvider } from './structs/kits/evidence.js';
29
+ export type { EvidenceRequirement, EvidenceProvider, EvidenceProjectionDefinition, EvidenceProjectionProvider, } from './structs/kits/evidence.js';
14
30
  export * from './kits/presentation/events.js';
15
31
  export * from './support/transport/index.js';
16
32
  export * from './support/model/chat-completions.js';
package/dist/esm/index.js CHANGED
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Aggregate public entry of `@jangts/agent-core`: Core runtime contracts, one `Support`
3
+ * namespace with a few named Support helpers, and the declaration helpers of optional Kits.
4
+ *
5
+ * Layering. Core owns the runtime contracts Apps call (engine, model runner, capabilities,
6
+ * context, diagnostics) and the handler contracts Core calls back into the App. Support only
7
+ * supplies recommended implementations of those same contracts, so it is published as a single
8
+ * namespace instead of a second dispatch layer. Kits are optional business libraries reached
9
+ * through their own subpath entries; the Kit entries re-exported here are declaration helpers
10
+ * and standalone modules, not additional Core guarantees. Shared utilities are re-exported
11
+ * because they are needed alongside these contracts, and they carry no Agent semantics.
12
+ *
13
+ * Exports are grouped by responsibility, not by dependency order. Deep subpath entries
14
+ * (`/engine`, `/model`, `/tools`, `/context`, `/journal`, `/diagnostics`, `/kits/...`)
15
+ * resolve to the same implementations, so this file is a convenience surface only.
16
+ */
1
17
  export * from './execution/engine.js';
2
18
  export { getErrorInfo } from './errors.js';
3
19
  export { BudgetError, ValidationError } from './structs/errors.js';
@@ -6,6 +22,8 @@ export * from './model/index.js';
6
22
  export * from './capabilities/index.js';
7
23
  export * from './context/fragments.js';
8
24
  export * from './context/journal.js';
25
+ // Named re-export: the context barrel also forwards its Kit evidence helpers, which the
26
+ // root surface publishes separately below.
9
27
  export { assembleFragments } from './context/assembly.js';
10
28
  export * from './support/context/assembly.js';
11
29
  export { defineEvidenceChecklist, defineEvidenceProjection } from './kits/evidence.js';
@@ -1,14 +1,46 @@
1
1
  import type { QueryAggregationOptions } from '../structs/kits/aggregation.js';
2
- /** Merge duplicates without moving their first position; selection policy remains host-owned. */
2
+ /**
3
+ * Merge duplicates without moving their first position; selection policy remains host-owned.
4
+ *
5
+ * The first occurrence of a key fixes the output position; `select` decides which item that
6
+ * position finally holds, so callers can prefer the newest or the most complete duplicate.
7
+ *
8
+ * @param items - Source items in the order the caller wants to display them.
9
+ * @param key - Key selector; items sharing a key collapse into one slot.
10
+ * @param select - Chooses the retained item from the incoming item and the earlier choice
11
+ * (`undefined` on the first occurrence).
12
+ * @returns One item per key, in first-occurrence order.
13
+ */
3
14
  export declare function mergeByKey<Item, Key>(items: Iterable<Item>, key: (item: Item) => Key, select: (item: Item, previous: Item | undefined) => Item): Item[];
4
- /** Ordered synchronous queries, optional stable-key merging; each real read stays host-owned. */
15
+ /**
16
+ * Compile one ordered read plan over a list of inputs.
17
+ *
18
+ * Ordered synchronous queries with optional stable-key merging; each real read stays
19
+ * host-owned. Inputs run sequentially in the given order, so a host can rely on a
20
+ * deterministic visit sequence. Without `key` every item is kept; with `key` the last write
21
+ * wins per key but the position of the first occurrence is retained.
22
+ *
23
+ * @param options - Read handler plus optional key/merge policy; handlers are bound to the
24
+ * options object so method-style implementations keep their `this`.
25
+ * @returns A frozen plan whose `collect` returns `{ total, items }`.
26
+ * @throws TypeError From `collect` when any handler returns a thenable: the whole plan is
27
+ * synchronous by contract, and an async handler cannot be awaited here.
28
+ */
5
29
  export declare function defineQueryAggregation<Input, Item, Context>(options: QueryAggregationOptions<Input, Item, Context>): Readonly<{
30
+ /**
31
+ * Run every input in order.
32
+ *
33
+ * @param inputs - Query inputs; order determines both read order and result order.
34
+ * @param context - Host context forwarded unchanged to `execute`, `key` and `merge`.
35
+ * @returns The merged items and their count.
36
+ */
6
37
  collect(inputs: readonly Input[], context: Context): {
7
38
  total: number;
8
39
  items: Item[];
9
40
  };
10
41
  }>;
11
42
  export type { QueryAggregationOptions } from '../structs/kits/aggregation.js';
43
+ /** Namespace object for callers that prefer one import over named helpers. */
12
44
  export declare const Aggregation: Readonly<{
13
45
  defineQueryAggregation: typeof defineQueryAggregation;
14
46
  mergeByKey: typeof mergeByKey;
@@ -1,5 +1,24 @@
1
+ /**
2
+ * Aggregation Kit: fold several synchronous query results into one ordered item list.
3
+ *
4
+ * Place in the package: an optional App-side helper. Reads, selection rules and result
5
+ * semantics stay with the host; this module only sequences the calls and preserves order.
6
+ *
7
+ * Exports: `mergeByKey`, `defineQueryAggregation`, `Aggregation`.
8
+ */
1
9
  import { synchronous } from '../utils/synchronous.js';
2
- /** Merge duplicates without moving their first position; selection policy remains host-owned. */
10
+ /**
11
+ * Merge duplicates without moving their first position; selection policy remains host-owned.
12
+ *
13
+ * The first occurrence of a key fixes the output position; `select` decides which item that
14
+ * position finally holds, so callers can prefer the newest or the most complete duplicate.
15
+ *
16
+ * @param items - Source items in the order the caller wants to display them.
17
+ * @param key - Key selector; items sharing a key collapse into one slot.
18
+ * @param select - Chooses the retained item from the incoming item and the earlier choice
19
+ * (`undefined` on the first occurrence).
20
+ * @returns One item per key, in first-occurrence order.
21
+ */
3
22
  export function mergeByKey(items, key, select) {
4
23
  const values = new Map();
5
24
  for (const item of items) {
@@ -8,10 +27,30 @@ export function mergeByKey(items, key, select) {
8
27
  }
9
28
  return [...values.values()];
10
29
  }
11
- /** Ordered synchronous queries, optional stable-key merging; each real read stays host-owned. */
30
+ /**
31
+ * Compile one ordered read plan over a list of inputs.
32
+ *
33
+ * Ordered synchronous queries with optional stable-key merging; each real read stays
34
+ * host-owned. Inputs run sequentially in the given order, so a host can rely on a
35
+ * deterministic visit sequence. Without `key` every item is kept; with `key` the last write
36
+ * wins per key but the position of the first occurrence is retained.
37
+ *
38
+ * @param options - Read handler plus optional key/merge policy; handlers are bound to the
39
+ * options object so method-style implementations keep their `this`.
40
+ * @returns A frozen plan whose `collect` returns `{ total, items }`.
41
+ * @throws TypeError From `collect` when any handler returns a thenable: the whole plan is
42
+ * synchronous by contract, and an async handler cannot be awaited here.
43
+ */
12
44
  export function defineQueryAggregation(options) {
13
45
  const execute = options.execute.bind(options), keyFor = options.key?.bind(options), merge = options.merge?.bind(options);
14
46
  return Object.freeze({
47
+ /**
48
+ * Run every input in order.
49
+ *
50
+ * @param inputs - Query inputs; order determines both read order and result order.
51
+ * @param context - Host context forwarded unchanged to `execute`, `key` and `merge`.
52
+ * @returns The merged items and their count.
53
+ */
15
54
  collect(inputs, context) {
16
55
  const rows = [], merged = new Map();
17
56
  for (const input of inputs)
@@ -21,11 +60,14 @@ export function defineQueryAggregation(options) {
21
60
  continue;
22
61
  }
23
62
  const key = synchronous(keyFor(item, input, context), 'Aggregation keys must be synchronous');
24
- merged.set(key, merge ? synchronous(merge(item, merged.get(key), input, context), 'Aggregation merge must be synchronous') : item);
63
+ merged.set(key, merge
64
+ ? synchronous(merge(item, merged.get(key), input, context), 'Aggregation merge must be synchronous')
65
+ : item);
25
66
  }
26
67
  const items = keyFor ? [...merged.values()] : rows;
27
68
  return { total: items.length, items };
28
69
  },
29
70
  });
30
71
  }
72
+ /** Namespace object for callers that prefer one import over named helpers. */
31
73
  export const Aggregation = Object.freeze({ defineQueryAggregation, mergeByKey });
@@ -1,2 +1,19 @@
1
+ /**
2
+ * Answering Kit: batch shape validation for one answer request.
3
+ *
4
+ * Place in the package: part of the `answering` Kit. It guards the request envelope only;
5
+ * reading, checking and repairing answers happens in the flow and task modules.
6
+ *
7
+ * Exports: `validateAnswerBatch`.
8
+ */
1
9
  import type { AnswerItem } from '../../structs/kits/answering/flow.js';
10
+ /**
11
+ * Validate that one batch is well formed and fully covered.
12
+ *
13
+ * @param inputIds - Every input id the batch must answer; non-empty, unique, non-blank.
14
+ * @param items - Answer items; each must reference known inputs and together cover all of them.
15
+ * @param maxItems - Maximum allowed item count, a positive safe integer.
16
+ * @throws TypeError For an invalid limit or input ids, an empty or oversized item list,
17
+ * duplicate item ids, an unknown source status or input id, or an uncovered input.
18
+ */
2
19
  export declare function validateAnswerBatch<Data>(inputIds: readonly string[], items: readonly AnswerItem<Data>[], maxItems: number): void;
@@ -1,11 +1,30 @@
1
+ /**
2
+ * Validate that one batch is well formed and fully covered.
3
+ *
4
+ * @param inputIds - Every input id the batch must answer; non-empty, unique, non-blank.
5
+ * @param items - Answer items; each must reference known inputs and together cover all of them.
6
+ * @param maxItems - Maximum allowed item count, a positive safe integer.
7
+ * @throws TypeError For an invalid limit or input ids, an empty or oversized item list,
8
+ * duplicate item ids, an unknown source status or input id, or an uncovered input.
9
+ */
1
10
  export function validateAnswerBatch(inputIds, items, maxItems) {
2
- if (!Number.isSafeInteger(maxItems) || maxItems < 1 || !inputIds.length || new Set(inputIds).size !== inputIds.length || inputIds.some(id => typeof id !== 'string' || !id))
11
+ if (!Number.isSafeInteger(maxItems) ||
12
+ maxItems < 1 ||
13
+ !inputIds.length ||
14
+ new Set(inputIds).size !== inputIds.length ||
15
+ inputIds.some((id) => typeof id !== 'string' || !id))
3
16
  throw new TypeError('Invalid answer input ids or limit');
4
- if (!items.length || items.length > maxItems || new Set(items.map(item => item.id)).size !== items.length)
17
+ if (!items.length ||
18
+ items.length > maxItems ||
19
+ new Set(items.map((item) => item.id)).size !== items.length)
5
20
  throw new TypeError('Invalid answer item count or ids');
6
21
  const covered = new Set();
7
22
  for (const item of items) {
8
- if (typeof item.id !== 'string' || !item.id || !['ready', 'unavailable', 'conflict'].includes(item.sourceStatus) || !item.inputIds.length || new Set(item.inputIds).size !== item.inputIds.length)
23
+ if (typeof item.id !== 'string' ||
24
+ !item.id ||
25
+ !['ready', 'unavailable', 'conflict'].includes(item.sourceStatus) ||
26
+ !item.inputIds.length ||
27
+ new Set(item.inputIds).size !== item.inputIds.length)
9
28
  throw new TypeError('Invalid answer item');
10
29
  for (const id of item.inputIds) {
11
30
  if (!inputIds.includes(id))
@@ -13,6 +32,6 @@ export function validateAnswerBatch(inputIds, items, maxItems) {
13
32
  covered.add(id);
14
33
  }
15
34
  }
16
- if (inputIds.some(id => !covered.has(id)))
35
+ if (inputIds.some((id) => !covered.has(id)))
17
36
  throw new TypeError('Answer tasks do not cover every input');
18
37
  }
@@ -1,3 +1,20 @@
1
+ /**
2
+ * Answering Kit: the frozen result contract shared by checkers and batch review.
3
+ *
4
+ * Place in the package: part of the `answering` Kit. It normalizes one check outcome and
5
+ * rejects internally inconsistent statuses so aggregation can trust what it receives.
6
+ *
7
+ * Exports: `snapshotAnswerCheck`.
8
+ */
1
9
  import type { AnswerCheck } from '../../structs/kits/answering/flow.js';
2
- /** One result contract for individual checkers and batch review. */
10
+ /**
11
+ * Freeze and validate one check result.
12
+ *
13
+ * @param check - Check outcome: status, issues and an optional replacement value.
14
+ * @param checkId - Id stamped onto issues that do not carry their own, so the failing checker
15
+ * stays identifiable after aggregation.
16
+ * @returns A frozen copy with frozen issues and paths.
17
+ * @throws TypeError When the status is unknown, an issue is malformed, a `passed` result still
18
+ * reports issues, or a `failed` result reports none.
19
+ */
3
20
  export declare function snapshotAnswerCheck<Value>(check: AnswerCheck<Value>, checkId?: string): AnswerCheck<Value>;