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