@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
@@ -1,5 +1,18 @@
1
+ /**
2
+ * Conditional registration contract.
3
+ *
4
+ * Place in the package: Support-side composition for App install steps. Steps are validated once,
5
+ * then installed in order per invocation; a predicate may only observe what earlier steps already
6
+ * installed, so declaration order is part of the contract. No new scheduling protocol is defined.
7
+ *
8
+ * Exports: `RegistrationDefinition`.
9
+ */
10
+ /** One install step. */
1
11
  export interface RegistrationDefinition<Context> {
12
+ /** Unique step id; also the catalog key. */
2
13
  readonly id: string;
14
+ /** Installs the step when true; must be synchronous and is re-evaluated per install. */
3
15
  readonly when?: (context: Context) => boolean;
16
+ /** Performs the installation; must return void synchronously. */
4
17
  readonly register: (context: Context) => void;
5
18
  }
@@ -1,9 +1,23 @@
1
+ /**
2
+ * Schema adapter contract.
3
+ *
4
+ * Place in the package: Support-side adapters that turn an App's JSON Schema compiler or parsing
5
+ * library into the Core `SchemaAdapter` shape. The compiler, package and error messages stay
6
+ * application choices; schema snapshots are frozen before they reach the compiler.
7
+ *
8
+ * Exports: `JsonSchemaValidator`, `JsonSchemaOptions`.
9
+ */
1
10
  /** App-owned JSON Schema compilers provide synchronous validation. */
2
11
  export interface JsonSchemaValidator<Output = unknown> {
12
+ /** Returns whether the value is valid; must be synchronous. */
3
13
  (value: unknown): value is Output;
14
+ /** Compiler-reported details for the last failed validation, when the library exposes them. */
4
15
  readonly errors?: unknown;
5
16
  }
17
+ /** Options for building an adapter from a JSON Schema compiler. */
6
18
  export interface JsonSchemaOptions<Output> {
19
+ /** Compiles a frozen schema copy into a validator; must return synchronously. */
7
20
  compile(schema: Record<string, unknown>): JsonSchemaValidator<Output>;
21
+ /** Builds the thrown error for an invalid value; defaults to a `TypeError`. */
8
22
  error?(value: unknown, errors: unknown): Error;
9
23
  }
@@ -1,28 +1,47 @@
1
+ /**
2
+ * Tool catalog contract used by Support's tool assembly.
3
+ *
4
+ * Place in the package: an App-side projection of typed tool definitions into model capabilities.
5
+ * The model may only propose `{ toolId, input }`; authorization, invocation, budgets and
6
+ * cancellation still happen in Core's tool registry.
7
+ *
8
+ * Exports: `ToolDefinition` (type re-export), `ToolProposal`, `ToolCapabilities`, `SelectedTools`,
9
+ * `ToolOutput`, `CompiledTool`, `ToolRuntime`, `ToolCatalogEntry`, `ToolCatalog`.
10
+ */
1
11
  import type { ToolResult } from '../invocation.js';
2
12
  import type { SchemaAdapter, ExecutionOptions, ReadonlyCatalog } from '../common.js';
3
13
  import type { RegisteredModelCapability, ModelSelection } from '../capabilities/model.js';
4
14
  import type { ModelCapabilityRegistry } from '../../capabilities/model.js';
5
15
  import type { ToolDefinition, ToolExecutionEvent, ToolRegistryPorts, ToolInvocationRequest } from '../capabilities/tools.js';
6
16
  export type { ToolDefinition } from '../capabilities/tools.js';
17
+ /** A model's proposal to call one tool; nothing has been authorized or executed yet. */
7
18
  export interface ToolProposal {
19
+ /** Registered tool the model selected. */
8
20
  readonly toolId: string;
21
+ /** Raw arguments; schema parsing and authorization happen in Core. */
9
22
  readonly input: unknown;
10
23
  }
24
+ /** Model capability view of a tool catalog. */
11
25
  export interface ToolCapabilities extends ModelCapabilityRegistry {
12
26
  values(): IterableIterator<RegisteredModelCapability<ToolProposal>>;
27
+ /** Resolves a model selection into a proposal; throws for unknown or invalid selections. */
13
28
  resolve(selection: ModelSelection, context: Readonly<{
14
29
  stageId: string;
15
30
  }>): ToolProposal;
31
+ /** Narrows the capability set to `ids`; throws for unregistered ids. */
16
32
  select(ids: readonly string[]): ToolCapabilities;
17
33
  }
18
34
  type ResultDefinition = {
19
35
  readonly id: string;
20
36
  parseOutput(value: unknown): unknown;
21
37
  };
38
+ /** Catalog narrowed to the given ids: each kept tool's id literal is intersected with `Id`. */
22
39
  export type SelectedTools<Tool extends ResultDefinition, Id extends string> = Tool extends ResultDefinition ? [Tool['id'] & Id] extends [never] ? never : Tool & {
23
40
  readonly id: Tool['id'] & Id;
24
41
  } : never;
42
+ /** Output type of the tool whose id matches `Id`; `never` for any other id. */
25
43
  export type ToolOutput<Tool extends ResultDefinition, Id extends string> = Tool extends ResultDefinition ? Id extends Tool['id'] ? ReturnType<Tool['parseOutput']> : never : never;
44
+ /** Tool definition type derived from a declaration literal, preserving input/output/id. */
26
45
  export type CompiledTool<App, Definition> = Definition extends {
27
46
  parseOutput(value: unknown): infer Output;
28
47
  } ? Definition extends {
@@ -30,18 +49,27 @@ export type CompiledTool<App, Definition> = Definition extends {
30
49
  } ? ToolDefinition<Definition extends {
31
50
  inputSchema: SchemaAdapter<infer Input>;
32
51
  } ? Input : unknown, Output, App, Id> : never : never;
52
+ /** Catalog bound to one App request. */
33
53
  export interface ToolRuntime<Tool extends ResultDefinition = ResultDefinition> {
54
+ /** The catalog's model capabilities, shared with the catalog instance. */
34
55
  readonly capabilities: ToolCapabilities;
56
+ /** Execution events recorded by this runtime so far, in occurrence order. */
35
57
  readonly events: readonly ToolExecutionEvent[];
58
+ /** Synchronous invocation; rejects tools declared as asynchronous. */
36
59
  invokeSync<const Id extends Tool['id']>(request: ToolInvocationRequest<Id>): ToolResult<ToolOutput<Tool, Id>>;
37
60
  invokeSync(request: ToolInvocationRequest): ToolResult<unknown>;
61
+ /** Asynchronous invocation; still bounded by the bound execution signal and errors. */
38
62
  invoke<const Id extends Tool['id']>(request: ToolInvocationRequest<Id>): Promise<ToolResult<ToolOutput<Tool, Id>>>;
39
63
  invoke(request: ToolInvocationRequest): Promise<ToolResult<unknown>>;
40
64
  }
65
+ /** Public declaration surface of one tool, without registry internals. */
41
66
  export type ToolCatalogEntry<App, Tool extends ToolDefinition<unknown, unknown, App>> = Tool extends ToolDefinition<unknown, unknown, App> ? Pick<Tool, keyof ToolDefinition<unknown, unknown, App>> : never;
67
+ /** Frozen tool catalog with model capabilities and per-request binding. */
42
68
  export interface ToolCatalog<App, Tool extends ToolDefinition<unknown, unknown, App> = ToolDefinition<unknown, unknown, App>> extends ReadonlyCatalog<ToolCatalogEntry<App, Tool>> {
43
69
  readonly capabilities: ToolCapabilities;
70
+ /** Narrows the catalog while preserving declaration order; throws for unknown ids. */
44
71
  select<const Ids extends readonly string[]>(ids: Ids): ToolCatalog<App, SelectedTools<Tool, Ids[number]>>;
72
+ /** Binds the catalog to one App request and returns an invocable runtime. */
45
73
  bind(request: {
46
74
  app: App;
47
75
  execution?: ExecutionOptions;
@@ -1,7 +1,23 @@
1
+ /**
2
+ * JSON transport framing contract.
3
+ *
4
+ * Place in the package: Support-side helpers that locate complete JSON objects inside streamed
5
+ * text. Framing is mechanical and never repairs or interprets fields; the caller decides which
6
+ * outside content and frames are acceptable. Limits prevent malformed streams from consuming
7
+ * unbounded memory.
8
+ *
9
+ * Exports: `JsonFrameLimits`, `JsonTransportPart`.
10
+ */
11
+ /** Bounds applied while scanning a streamed text. */
1
12
  export interface JsonFrameLimits {
13
+ /** Maximum number of complete frames accepted. */
2
14
  maxFrames: number;
15
+ /** Stray closing braces tolerated outside frames, covering transports that repeat a delimiter. */
3
16
  maxExtraClosings: number;
17
+ /** Optional per-frame character cap so a single frame cannot amplify into an oversized parse. */
18
+ maxFrameChars?: number;
4
19
  }
20
+ /** One scanned span: a complete object frame or a character outside any frame. */
5
21
  export type JsonTransportPart = {
6
22
  kind: 'frame' | 'outside';
7
23
  text: string;
@@ -1,9 +1,24 @@
1
+ /**
2
+ * Server-sent event transport contract.
3
+ *
4
+ * Place in the package: Support-side framing only. The host owns its HTTP response and lifecycle;
5
+ * these types let Support encode frames and wait for backpressure in a cancellable way, while
6
+ * reading is delegated to the shared streaming package.
7
+ *
8
+ * Exports: `SseEvent` and `SseReadOptions` (type re-exports), `SseWriter`, `SseOutputEvent`.
9
+ */
1
10
  export type { SseEvent, SseReadOptions } from '@jangts/streaming/sse';
11
+ /** Destination that reports backpressure instead of buffering without bound. */
2
12
  export interface SseWriter {
13
+ /** Writes one encoded frame; returns false when the consumer needs a drain wait. */
3
14
  write(frame: string): boolean;
15
+ /** Resolves once the destination can accept more data, or rejects when `signal` aborts. */
4
16
  waitForDrain(signal?: AbortSignal): Promise<unknown>;
5
17
  }
18
+ /** One outbound event before wire encoding. */
6
19
  export interface SseOutputEvent {
20
+ /** Event name; must not contain a line break. */
7
21
  event: string;
22
+ /** Payload text; each line becomes its own `data:` field. */
8
23
  data: string;
9
24
  }
@@ -1,13 +1,26 @@
1
+ /**
2
+ * Shared rule vocabulary for ordered matching, traversal and rejection checks.
3
+ *
4
+ * Place in the package: Core-level primitives used by both Core and Support. They describe rule
5
+ * lists only; the helper that executes them lives in `utils/rules.ts`, so a declaration stays
6
+ * readable without importing behaviour.
7
+ *
8
+ * Exports: `MatchRule`, `WalkRule`, `BreakReason`, `BreakPredicate`, `BreakCheck`, `BreakEvent`,
9
+ * `BreakWhileConfig`.
10
+ */
1
11
  /** Order is priority. Patterns may inspect values, types, state or regular expressions. */
2
12
  export interface MatchRule<Input, Result = void> {
13
+ /** Unique rule id used in diagnostics. */
3
14
  readonly id: string;
4
15
  readonly description: string;
5
16
  /** Omission is an unconditional match at this position, normally the final fallback. */
6
17
  readonly pattern?: (input: Readonly<Input>) => boolean;
18
+ /** Produces the rule's result; only the first matching rule runs. */
7
19
  readonly handle: (input: Input) => Result;
8
20
  }
9
21
  /** Synchronous traversal; local rules may omit catalog metadata. */
10
22
  export interface WalkRule<Input = void> extends Partial<MatchRule<Input, unknown>> {
23
+ /** Runs when the rule matches; must return synchronously. */
11
24
  readonly handle: (input: Input) => unknown;
12
25
  /** Runs before matching, including when the rule does not match. */
13
26
  readonly before?: (input: Input) => void;
@@ -20,14 +33,20 @@ export type BreakPredicate = () => unknown;
20
33
  export interface BreakCheck {
21
34
  /** A truthy failure, lazy predicate, or ordered OR-list of lazy predicates. */
22
35
  readonly occur: unknown;
36
+ /** Rejection reason; omitted means the helper creates a default `Error`. */
23
37
  readonly error?: BreakReason;
38
+ /** Tags attributed to the rejection, merged with the enclosing group's tags. */
24
39
  readonly tags?: readonly string[];
25
40
  }
26
41
  /** Diagnostic metadata only; rule inputs and request data are not included. */
27
42
  export interface BreakEvent {
43
+ /** The thrown value, kept for identity. */
28
44
  readonly error: unknown;
45
+ /** Tags of the check that rejected, plus its enclosing group tags. */
29
46
  readonly tags: readonly string[];
30
47
  }
48
+ /** Global rejection observer installed once per process. */
31
49
  export interface BreakWhileConfig {
50
+ /** Called before the reason is thrown; its errors are swallowed and promises are not awaited. */
32
51
  readonly onBreak?: (event: BreakEvent) => void | Promise<void>;
33
52
  }
@@ -1,7 +1,30 @@
1
1
  import type { CapabilityModule, CapabilityCatalogOptions, CapabilityToolReferences } from '../structs/support/capabilities.js';
2
- /** Validate against the complete registered set, including tools unavailable in this request. */
2
+ /**
3
+ * Validate tool references against the complete registered set.
4
+ *
5
+ * Checking against every registered tool (not only the ones available in the current request)
6
+ * keeps the declaration honest: a module may reference a tool that this request filters out, but
7
+ * never one that does not exist.
8
+ *
9
+ * @param names All registered tool IDs, including tools unavailable to the current request.
10
+ * @param references Tool-reference declarations to check.
11
+ * @throws {Error} When an owner ID is blank, `requiredToolIds` is not an array, or a referenced
12
+ * tool ID is not registered.
13
+ */
3
14
  export declare function validateToolReferences(names: Iterable<string>, references: readonly CapabilityToolReferences[]): void;
4
- /** App-side composition only: no new Core execution entity or domain lifecycle. */
15
+ /**
16
+ * Build a frozen capability catalog from application module declarations.
17
+ *
18
+ * Each module must carry a non-empty description, and every contributed tool ID must be unique
19
+ * across modules. Reference projections run during construction and must be synchronous.
20
+ *
21
+ * @param definitions Capability modules in declaration order; order is preserved in the catalog.
22
+ * @param options Optional projections that expose tool references for validation.
23
+ * @returns A frozen catalog with `definitions`, `require`, `tools` and `findToolOwner`.
24
+ * @throws {TypeError} When the catalog lookup receives an unknown module ID.
25
+ * @throws {Error} When a module description, tool ID, reference projection or referenced tool is
26
+ * invalid.
27
+ */
5
28
  export declare function defineCapabilityCatalog<Module extends CapabilityModule>(definitions: readonly Module[], options?: CapabilityCatalogOptions<Module>): Readonly<{
6
29
  tools: readonly Module["tools"][number][];
7
30
  findToolOwner(toolId: string): Readonly<Module> | undefined;
@@ -1,7 +1,27 @@
1
+ /**
2
+ * Capability catalog support: validate application modules and the tools they contribute.
3
+ *
4
+ * Applications declare modules (id, description, tools) plus optional tool-reference projections;
5
+ * this module checks them once at construction so the resulting catalog can be handed to Core.
6
+ * It is composition only: it creates no Core execution entity and owns no domain lifecycle.
7
+ *
8
+ * Main exports: `defineCapabilityCatalog` and `validateToolReferences`.
9
+ */
1
10
  import { synchronous } from '../utils/synchronous.js';
2
11
  import { readonlyCatalog } from '../utils/catalog.js';
3
12
  import { breakWhile } from '../utils/rules.js';
4
- /** Validate against the complete registered set, including tools unavailable in this request. */
13
+ /**
14
+ * Validate tool references against the complete registered set.
15
+ *
16
+ * Checking against every registered tool (not only the ones available in the current request)
17
+ * keeps the declaration honest: a module may reference a tool that this request filters out, but
18
+ * never one that does not exist.
19
+ *
20
+ * @param names All registered tool IDs, including tools unavailable to the current request.
21
+ * @param references Tool-reference declarations to check.
22
+ * @throws {Error} When an owner ID is blank, `requiredToolIds` is not an array, or a referenced
23
+ * tool ID is not registered.
24
+ */
5
25
  export function validateToolReferences(names, references) {
6
26
  const available = new Set(names);
7
27
  for (const reference of references) {
@@ -13,9 +33,21 @@ export function validateToolReferences(names, references) {
13
33
  }
14
34
  }
15
35
  }
16
- /** App-side composition only: no new Core execution entity or domain lifecycle. */
36
+ /**
37
+ * Build a frozen capability catalog from application module declarations.
38
+ *
39
+ * Each module must carry a non-empty description, and every contributed tool ID must be unique
40
+ * across modules. Reference projections run during construction and must be synchronous.
41
+ *
42
+ * @param definitions Capability modules in declaration order; order is preserved in the catalog.
43
+ * @param options Optional projections that expose tool references for validation.
44
+ * @returns A frozen catalog with `definitions`, `require`, `tools` and `findToolOwner`.
45
+ * @throws {TypeError} When the catalog lookup receives an unknown module ID.
46
+ * @throws {Error} When a module description, tool ID, reference projection or referenced tool is
47
+ * invalid.
48
+ */
17
49
  export function defineCapabilityCatalog(definitions, options = {}) {
18
- const catalog = readonlyCatalog(definitions, id => new TypeError(`Unknown capability module: ${id}`));
50
+ const catalog = readonlyCatalog(definitions, (id) => new TypeError(`Unknown capability module: ${id}`));
19
51
  const modules = catalog.definitions;
20
52
  const owners = new Map();
21
53
  const tools = [];
@@ -28,9 +60,14 @@ export function defineCapabilityCatalog(definitions, options = {}) {
28
60
  tools.push(tool);
29
61
  }
30
62
  }
31
- validateToolReferences(owners.keys(), modules.flatMap(module => options.toolReferences ? synchronous(options.toolReferences(module), 'Capability reference projections must be synchronous') : []));
63
+ validateToolReferences(owners.keys(), modules.flatMap((module) => options.toolReferences
64
+ ? synchronous(options.toolReferences(module), 'Capability reference projections must be synchronous')
65
+ : []));
32
66
  return Object.freeze({
33
- ...catalog, tools: Object.freeze(tools),
34
- findToolOwner(toolId) { return owners.get(toolId); },
67
+ ...catalog,
68
+ tools: Object.freeze(tools),
69
+ findToolOwner(toolId) {
70
+ return owners.get(toolId);
71
+ },
35
72
  });
36
73
  }
@@ -1,9 +1,40 @@
1
1
  import type { ContextFragment } from '../../structs/context/fragments.js';
2
2
  import type { ContextBuilder, ContextBuilderOptions, ContextFragmentConfig, ContextAssemblyOptions, ContextProjection } from '../../structs/support/context.js';
3
- /** Compile context ordering once; expansion and formatting use each request's current input. */
3
+ /**
4
+ * Compile ordered context projections into a builder.
5
+ *
6
+ * A projection is either a single fragment (with its own formatter) or a placement whose
7
+ * contribution handler expands to any number of fragments at request time.
8
+ *
9
+ * @param definitions Projections in the order they should appear in the plan.
10
+ * @param options Fragment factory, contribution handlers and an optional size budget.
11
+ * @returns A frozen builder exposing `fragments`, `plan` and `build`.
12
+ * @throws {Error} When a projection ID repeats, a formatter is missing, a placement has no
13
+ * contribution handler, or a callback is asynchronous.
14
+ */
4
15
  export declare function defineContextAssembly<Input, Id extends string = string, Placement extends string = string>(definitions: readonly ContextProjection<Input, Id, Placement>[], options: ContextAssemblyOptions<Input, Id, Placement>): ContextBuilder<Input>;
5
- /** Full-metadata catalogs use the same builder without a separate metadata reference catalog. */
16
+ /**
17
+ * Compile self-describing fragment declarations into a builder.
18
+ *
19
+ * Each definition carries its own trust, lifetime and size metadata, so no separate metadata
20
+ * catalog is needed. The budget may be a constant or a function of the request input.
21
+ *
22
+ * @param definitions Fragment configurations in plan order.
23
+ * @param options Optional transform, budget selector and related builder settings.
24
+ * @returns A frozen builder exposing `fragments`, `plan` and `build`.
25
+ * @throws {Error} When a fragment ID repeats or a formatter is missing or asynchronous.
26
+ * @throws {TypeError} When `plan`/`build` is called with no configured or overridden budget.
27
+ */
6
28
  export declare function defineContextFragments<Input>(definitions: readonly ContextFragmentConfig<Input>[], options?: ContextBuilderOptions<Input>): ContextBuilder<Input>;
7
- /** Transform all outbound text, including nested receipt values, before measuring context budgets. */
29
+ /**
30
+ * Apply a text transform to a fragment value, including strings nested inside objects.
31
+ *
32
+ * Structured values are walked through a JSON round trip, which is what the budget measurement
33
+ * serializes later; values that JSON cannot represent are therefore not preserved.
34
+ *
35
+ * @param fragment Fragment whose value should be transformed.
36
+ * @param transform Pure text mapping applied to every string in the value.
37
+ * @returns A new fragment with unchanged metadata and the transformed value.
38
+ */
8
39
  export declare function transformContextText(fragment: ContextFragment, transform: (text: string) => string): ContextFragment;
9
- export type { ContextBuilder, ContextBuilderOptions, ContextFragmentConfig, ContextAssemblyOptions, ContextProjection } from '../../structs/support/context.js';
40
+ export type { ContextBuilder, ContextBuilderOptions, ContextFragmentConfig, ContextAssemblyOptions, ContextProjection, } from '../../structs/support/context.js';
@@ -1,12 +1,34 @@
1
+ /**
2
+ * Context builders: compile application fragment declarations into a Core `ContextBuilder`.
3
+ *
4
+ * Ordering and metadata are compiled once; fragment values and formatting are produced per
5
+ * request, so a builder may be shared across invocations. The builder only assembles a plan or
6
+ * built context; reduction, selection and model execution stay with Core or explicit nodes.
7
+ *
8
+ * Main exports: `defineContextAssembly`, `defineContextFragments` and `transformContextText`.
9
+ */
1
10
  import { synchronous } from '../../utils/synchronous.js';
2
11
  import { breakWhile } from '../../utils/rules.js';
3
12
  import { assembleContextPlan } from '../../context/plan.js';
4
13
  import { validateContextBudget } from '../../context/fragments.js';
5
- /** Compile context ordering once; expansion and formatting use each request's current input. */
14
+ /**
15
+ * Compile ordered context projections into a builder.
16
+ *
17
+ * A projection is either a single fragment (with its own formatter) or a placement whose
18
+ * contribution handler expands to any number of fragments at request time.
19
+ *
20
+ * @param definitions Projections in the order they should appear in the plan.
21
+ * @param options Fragment factory, contribution handlers and an optional size budget.
22
+ * @returns A frozen builder exposing `fragments`, `plan` and `build`.
23
+ * @throws {Error} When a projection ID repeats, a formatter is missing, a placement has no
24
+ * contribution handler, or a callback is asynchronous.
25
+ */
6
26
  export function defineContextAssembly(definitions, options) {
7
27
  const fragment = options.fragment.bind(options);
8
28
  const ids = new Set();
9
- const factories = definitions.map(definition => {
29
+ const factories = definitions.map((definition) => {
30
+ // Contribution placements live in the same ID namespace, prefixed so they cannot collide with
31
+ // a real fragment ID.
10
32
  const id = definition.kind === 'fragment' ? definition.id : `contributions:${definition.placement}`;
11
33
  breakWhile(ids.has(id), `Duplicate context projection: ${id}`);
12
34
  ids.add(id);
@@ -14,7 +36,9 @@ export function defineContextAssembly(definitions, options) {
14
36
  const id = definition.id;
15
37
  breakWhile(typeof definition.format !== 'function', `Missing context formatter: ${id}`);
16
38
  const format = definition.format.bind(definition);
17
- return (input) => [synchronous(fragment(id, synchronous(format(input), 'Context formatters must be synchronous')), 'Context fragment factories must be synchronous')];
39
+ return (input) => [
40
+ synchronous(fragment(id, synchronous(format(input), 'Context formatters must be synchronous')), 'Context fragment factories must be synchronous'),
41
+ ];
18
42
  }
19
43
  const create = options.contributions?.[definition.placement];
20
44
  breakWhile(typeof create !== 'function', `Unknown context contribution: ${definition.placement}`);
@@ -23,26 +47,52 @@ export function defineContextAssembly(definitions, options) {
23
47
  });
24
48
  return contextBuilder(factories, options);
25
49
  }
26
- /** Full-metadata catalogs use the same builder without a separate metadata reference catalog. */
50
+ /**
51
+ * Compile self-describing fragment declarations into a builder.
52
+ *
53
+ * Each definition carries its own trust, lifetime and size metadata, so no separate metadata
54
+ * catalog is needed. The budget may be a constant or a function of the request input.
55
+ *
56
+ * @param definitions Fragment configurations in plan order.
57
+ * @param options Optional transform, budget selector and related builder settings.
58
+ * @returns A frozen builder exposing `fragments`, `plan` and `build`.
59
+ * @throws {Error} When a fragment ID repeats or a formatter is missing or asynchronous.
60
+ * @throws {TypeError} When `plan`/`build` is called with no configured or overridden budget.
61
+ */
27
62
  export function defineContextFragments(definitions, options = {}) {
28
63
  const ids = new Set();
29
- const factories = definitions.map(definition => {
30
- const metadata = { id: definition.id, sourceId: definition.sourceId, trust: definition.trust, lifetime: definition.lifetime, maxChars: definition.maxChars, role: definition.role };
64
+ const factories = definitions.map((definition) => {
65
+ const metadata = {
66
+ id: definition.id,
67
+ sourceId: definition.sourceId,
68
+ trust: definition.trust,
69
+ lifetime: definition.lifetime,
70
+ maxChars: definition.maxChars,
71
+ role: definition.role,
72
+ };
31
73
  breakWhile(typeof definition.format !== 'function', `Missing context formatter: ${metadata.id}`);
32
74
  const format = definition.format.bind(definition);
33
75
  breakWhile(ids.has(metadata.id), `Duplicate context fragment: ${metadata.id}`);
34
76
  ids.add(metadata.id);
35
- return (input) => [{ ...metadata, value: synchronous(format(input), 'Context formatters must be synchronous') }];
77
+ return (input) => [
78
+ { ...metadata, value: synchronous(format(input), 'Context formatters must be synchronous') },
79
+ ];
36
80
  });
37
81
  return contextBuilder(factories, options);
38
82
  }
39
83
  function contextBuilder(factories, options) {
40
84
  const transform = options.transform?.bind(options);
41
85
  const configuredLimit = typeof options.maxInputChars === 'function'
42
- ? options.maxInputChars.bind(options) : options.maxInputChars;
43
- const fragments = (input) => factories.flatMap(create => create(input).map(value => transform ? synchronous(transform(value, input), 'Context transforms must be synchronous') : value));
86
+ ? options.maxInputChars.bind(options)
87
+ : options.maxInputChars;
88
+ const fragments = (input) => factories.flatMap((create) => create(input).map((value) => transform
89
+ ? synchronous(transform(value, input), 'Context transforms must be synchronous')
90
+ : value));
44
91
  function limit(input, override) {
45
- const value = override ?? (typeof configuredLimit === 'function' ? synchronous(configuredLimit(input), 'Context budget selectors must be synchronous') : configuredLimit);
92
+ const value = override ??
93
+ (typeof configuredLimit === 'function'
94
+ ? synchronous(configuredLimit(input), 'Context budget selectors must be synchronous')
95
+ : configuredLimit);
46
96
  if (value === undefined)
47
97
  throw new TypeError('Configure a context budget or pass maxInputChars');
48
98
  validateContextBudget(0, value);
@@ -50,19 +100,41 @@ function contextBuilder(factories, options) {
50
100
  }
51
101
  return Object.freeze({
52
102
  fragments,
53
- plan({ input, maxInputChars, originalFragments, additionalMessages, mutableFragmentIds }) {
103
+ plan({ input, maxInputChars, originalFragments, additionalMessages, mutableFragmentIds, }) {
54
104
  const budget = limit(input, maxInputChars);
55
- return { fragments: fragments(input), maxInputChars: budget, originalFragments, additionalMessages, mutableFragmentIds };
105
+ return {
106
+ fragments: fragments(input),
107
+ maxInputChars: budget,
108
+ originalFragments,
109
+ additionalMessages,
110
+ mutableFragmentIds,
111
+ };
56
112
  },
57
- build({ input, maxInputChars, originalFragments, additionalMessages, mutableFragmentIds }) {
113
+ build({ input, maxInputChars, originalFragments, additionalMessages, mutableFragmentIds, }) {
58
114
  const budget = limit(input, maxInputChars);
59
- return assembleContextPlan({ fragments: fragments(input), maxInputChars: budget, originalFragments, additionalMessages, mutableFragmentIds });
115
+ return assembleContextPlan({
116
+ fragments: fragments(input),
117
+ maxInputChars: budget,
118
+ originalFragments,
119
+ additionalMessages,
120
+ mutableFragmentIds,
121
+ });
60
122
  },
61
123
  });
62
124
  }
63
- /** Transform all outbound text, including nested receipt values, before measuring context budgets. */
125
+ /**
126
+ * Apply a text transform to a fragment value, including strings nested inside objects.
127
+ *
128
+ * Structured values are walked through a JSON round trip, which is what the budget measurement
129
+ * serializes later; values that JSON cannot represent are therefore not preserved.
130
+ *
131
+ * @param fragment Fragment whose value should be transformed.
132
+ * @param transform Pure text mapping applied to every string in the value.
133
+ * @returns A new fragment with unchanged metadata and the transformed value.
134
+ */
64
135
  export function transformContextText(fragment, transform) {
65
- const value = typeof fragment.value === 'string' ? transform(fragment.value)
136
+ const value = typeof fragment.value === 'string'
137
+ ? transform(fragment.value)
66
138
  : JSON.parse(JSON.stringify(fragment.value, (_key, value) => typeof value === 'string' ? transform(value) : value));
67
139
  return { ...fragment, value };
68
140
  }
@@ -1,6 +1,22 @@
1
1
  import type { ContextCompressor } from '../../structs/support/context-processing.js';
2
2
  import type { ContextFragment } from '../../structs/context/fragments.js';
3
- /** Prompt and output contract belong to App; model execution stays on the Core call port. */
3
+ /**
4
+ * Build a compressor that asks a model to rewrite one fragment.
5
+ *
6
+ * The request pairs a system instruction with a user message carrying the fragment ID, its current
7
+ * value and the target character count. Only the model's parsed value is returned; the caller
8
+ * decides whether the result fits the reduction contract.
9
+ *
10
+ * @param options Compressor declaration.
11
+ * @param options.id Handler ID referenced by `compress` reduction steps; must be unique per policy.
12
+ * @param options.instruction System prompt describing the compression task and output format.
13
+ * @param options.modelId Optional model override; defaults to the stage's prepared model.
14
+ * @param options.transport Registered transport ID used for the compression call.
15
+ * @param options.maxOutputTokens Output reservation for the compression call.
16
+ * @param options.parse Converts the model value into the fragment value type; must be synchronous.
17
+ * @returns A frozen `ContextCompressor` whose `compress` performs the model call.
18
+ * @throws {Error} When `parse` is not a function, or when the parser returns a thenable.
19
+ */
4
20
  export declare function createContextCompressor(options: {
5
21
  id: string;
6
22
  instruction: string;
@@ -1,15 +1,57 @@
1
+ /**
2
+ * Context compressor factory: one model-backed compression handler for context reductions.
3
+ *
4
+ * The application owns the prompt and the output contract; the actual model call goes through the
5
+ * Core call port supplied with each compression request, so budgets, cancellation and diagnostics
6
+ * stay under Core control.
7
+ *
8
+ * Main export: `createContextCompressor`.
9
+ */
1
10
  import { breakWhile } from '../../utils/rules.js';
2
11
  import { synchronous } from '../../utils/synchronous.js';
3
- /** Prompt and output contract belong to App; model execution stays on the Core call port. */
12
+ /**
13
+ * Build a compressor that asks a model to rewrite one fragment.
14
+ *
15
+ * The request pairs a system instruction with a user message carrying the fragment ID, its current
16
+ * value and the target character count. Only the model's parsed value is returned; the caller
17
+ * decides whether the result fits the reduction contract.
18
+ *
19
+ * @param options Compressor declaration.
20
+ * @param options.id Handler ID referenced by `compress` reduction steps; must be unique per policy.
21
+ * @param options.instruction System prompt describing the compression task and output format.
22
+ * @param options.modelId Optional model override; defaults to the stage's prepared model.
23
+ * @param options.transport Registered transport ID used for the compression call.
24
+ * @param options.maxOutputTokens Output reservation for the compression call.
25
+ * @param options.parse Converts the model value into the fragment value type; must be synchronous.
26
+ * @returns A frozen `ContextCompressor` whose `compress` performs the model call.
27
+ * @throws {Error} When `parse` is not a function, or when the parser returns a thenable.
28
+ */
4
29
  export function createContextCompressor(options) {
5
30
  const { id, instruction, modelId, transport, maxOutputTokens } = options;
6
31
  breakWhile(typeof options.parse !== 'function', 'Context compressor requires a result parser');
7
32
  const parse = options.parse.bind(options);
8
- return Object.freeze({ id, async compress(call) {
9
- const result = await call.callModel({ stageId: `${call.stageId}:compress:${id}`, modelId, input: [
33
+ return Object.freeze({
34
+ id,
35
+ async compress(call) {
36
+ const result = await call.callModel({
37
+ // Suffix the stage ID so compressor calls are attributable in diagnostics and budgets.
38
+ stageId: `${call.stageId}:compress:${id}`,
39
+ modelId,
40
+ input: [
10
41
  { role: 'system', content: instruction },
11
- { role: 'user', content: JSON.stringify({ sourceId: call.fragment.sourceId, value: call.fragment.value, targetChars: call.targetChars }) },
12
- ], maxOutputTokens, transport });
42
+ {
43
+ role: 'user',
44
+ content: JSON.stringify({
45
+ sourceId: call.fragment.sourceId,
46
+ value: call.fragment.value,
47
+ targetChars: call.targetChars,
48
+ }),
49
+ },
50
+ ],
51
+ maxOutputTokens,
52
+ transport,
53
+ });
13
54
  return synchronous(parse(result.value), 'Context result parsers must be synchronous');
14
- } });
55
+ },
56
+ });
15
57
  }
@@ -1 +1,7 @@
1
+ /**
2
+ * Re-export barrel: Core fragment assembly helpers used by context support code.
3
+ *
4
+ * Kept as a stable Support path so applications do not import Core internals directly. No logic
5
+ * lives here.
6
+ */
1
7
  export * from '../../context/assembly.js';
@@ -1 +1,7 @@
1
+ /**
2
+ * Re-export barrel: Core fragment assembly helpers used by context support code.
3
+ *
4
+ * Kept as a stable Support path so applications do not import Core internals directly. No logic
5
+ * lives here.
6
+ */
1
7
  export * from '../../context/assembly.js';