@jangts/agent-core 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (558) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +55 -0
  3. package/NOTICE +6 -0
  4. package/README.md +8 -0
  5. package/development/docs/README.en.md +70 -0
  6. package/development/docs/README.md +1 -1
  7. package/development/docs/acceptance.en.md +34 -0
  8. package/development/docs/agent-development.en.md +42 -0
  9. package/development/docs/api/README.en.md +62 -0
  10. package/development/docs/api/advanced-agents.en.md +135 -0
  11. package/development/docs/api/context-processing.en.md +110 -0
  12. package/development/docs/api/core.en.md +274 -0
  13. package/development/docs/api/examples.en.md +118 -0
  14. package/development/docs/api/kits.en.md +183 -0
  15. package/development/docs/api/knowledge-answering.en.md +166 -0
  16. package/development/docs/api/mock.en.md +186 -0
  17. package/development/docs/api/observability.en.md +166 -0
  18. package/development/docs/api/reference.en.md +2235 -0
  19. package/development/docs/api/reference.md +1907 -1874
  20. package/development/docs/api/support.en.md +252 -0
  21. package/development/docs/api/support.md +27 -0
  22. package/development/docs/api/types.en.md +181 -0
  23. package/development/docs/api/workflow.en.md +188 -0
  24. package/development/docs/basic-usage.en.md +78 -0
  25. package/development/docs/create-app.en.md +76 -0
  26. package/development/docs/examples/offline-agent.en.md +273 -0
  27. package/development/docs/examples.en.md +36 -0
  28. package/development/docs/flows/knowledge-maintenance.en.md +38 -0
  29. package/development/docs/getting-started.en.md +71 -0
  30. package/development/docs/knowledge.en.md +89 -0
  31. package/development/docs/maintenance.en.md +62 -0
  32. package/development/docs/materials.en.md +38 -0
  33. package/development/docs/mechanisms.en.md +227 -0
  34. package/development/docs/memory-and-learning.en.md +42 -0
  35. package/development/docs/operations.en.md +51 -0
  36. package/development/docs/records.en.md +63 -0
  37. package/development/docs/registration.en.md +63 -0
  38. package/development/skills/agent-core-app/scripts/create-app.mjs +286 -70
  39. package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +77 -16
  40. package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
  41. package/development/skills/agent-core-app/scripts/plan.mjs +46 -12
  42. package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
  43. package/development/skills/agent-core-app/scripts/resources.mjs +62 -17
  44. package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
  45. package/development/skills/agent-core-app/templates/catalog.json +36 -22
  46. package/dist/cjs/capabilities/index.js +13 -0
  47. package/dist/cjs/capabilities/invocation.js +80 -10
  48. package/dist/cjs/capabilities/model.js +126 -13
  49. package/dist/cjs/capabilities/tool-runtime.js +64 -12
  50. package/dist/cjs/capabilities/tools.js +266 -31
  51. package/dist/cjs/context/assembly.js +46 -5
  52. package/dist/cjs/context/audit.js +31 -6
  53. package/dist/cjs/context/fragments.js +54 -11
  54. package/dist/cjs/context/index.js +12 -0
  55. package/dist/cjs/context/journal.js +84 -7
  56. package/dist/cjs/context/plan.js +30 -2
  57. package/dist/cjs/diagnostics/catalog.js +17 -3
  58. package/dist/cjs/diagnostics/index.js +149 -29
  59. package/dist/cjs/diagnostics/sub-flow.js +240 -40
  60. package/dist/cjs/errors.js +99 -17
  61. package/dist/cjs/execution/branch.js +20 -4
  62. package/dist/cjs/execution/engine.js +470 -56
  63. package/dist/cjs/execution/events.js +136 -18
  64. package/dist/cjs/execution/index.js +7 -0
  65. package/dist/cjs/execution/reporting.js +75 -6
  66. package/dist/cjs/execution/state.js +161 -22
  67. package/dist/cjs/execution/workflow.js +224 -32
  68. package/dist/cjs/index.js +18 -0
  69. package/dist/cjs/kits/aggregation.js +45 -3
  70. package/dist/cjs/kits/answering/batch.js +23 -4
  71. package/dist/cjs/kits/answering/check-result.js +31 -8
  72. package/dist/cjs/kits/answering/checks.js +24 -3
  73. package/dist/cjs/kits/answering/flow.js +192 -36
  74. package/dist/cjs/kits/answering/index.js +19 -1
  75. package/dist/cjs/kits/answering/tasks.js +88 -13
  76. package/dist/cjs/kits/artifacts.js +36 -4
  77. package/dist/cjs/kits/candidates.js +47 -5
  78. package/dist/cjs/kits/delivery.js +40 -5
  79. package/dist/cjs/kits/durable.js +155 -31
  80. package/dist/cjs/kits/evidence.js +66 -15
  81. package/dist/cjs/kits/family.js +152 -22
  82. package/dist/cjs/kits/index.js +12 -1
  83. package/dist/cjs/kits/inference.js +104 -16
  84. package/dist/cjs/kits/intents/catalog.js +67 -16
  85. package/dist/cjs/kits/intents/index.js +11 -0
  86. package/dist/cjs/kits/intents/registry.js +188 -43
  87. package/dist/cjs/kits/intents/scopes.js +215 -46
  88. package/dist/cjs/kits/interaction/command.js +140 -36
  89. package/dist/cjs/kits/interaction/commands.js +86 -11
  90. package/dist/cjs/kits/interaction/handlers.js +27 -10
  91. package/dist/cjs/kits/interaction/index.js +10 -0
  92. package/dist/cjs/kits/interaction/transfer.js +80 -14
  93. package/dist/cjs/kits/knowledge/catalog.js +62 -11
  94. package/dist/cjs/kits/knowledge/index.js +16 -1
  95. package/dist/cjs/kits/knowledge/publication.js +99 -23
  96. package/dist/cjs/kits/knowledge/sections.js +33 -4
  97. package/dist/cjs/kits/normalization.js +51 -7
  98. package/dist/cjs/kits/policies.js +79 -15
  99. package/dist/cjs/kits/presentation/events.js +54 -10
  100. package/dist/cjs/kits/presentation/index.js +24 -1
  101. package/dist/cjs/kits/presentation/outputs.js +176 -38
  102. package/dist/cjs/kits/presentation/templates.js +33 -5
  103. package/dist/cjs/kits/presentation/variants.js +31 -2
  104. package/dist/cjs/kits/projection.js +63 -8
  105. package/dist/cjs/kits/rank-fusion.js +27 -4
  106. package/dist/cjs/kits/reflection-log-source.js +89 -16
  107. package/dist/cjs/kits/reflection.js +234 -60
  108. package/dist/cjs/kits/retrieval.js +98 -18
  109. package/dist/cjs/kits/search.js +180 -27
  110. package/dist/cjs/kits/text-skills.js +104 -19
  111. package/dist/cjs/kits/tools.js +415 -74
  112. package/dist/cjs/kits/vector-search.js +50 -16
  113. package/dist/cjs/mock/node.js +7 -1
  114. package/dist/cjs/mock/web.js +7 -1
  115. package/dist/cjs/mock.js +7 -1
  116. package/dist/cjs/model/binding.js +68 -17
  117. package/dist/cjs/model/call-budget.js +45 -4
  118. package/dist/cjs/model/decision-retry.js +19 -1
  119. package/dist/cjs/model/defaults.js +27 -4
  120. package/dist/cjs/model/index.js +7 -0
  121. package/dist/cjs/model/interactions/arguments.js +36 -1
  122. package/dist/cjs/model/interactions/json-object.js +48 -12
  123. package/dist/cjs/model/interactions/native-functions.js +52 -10
  124. package/dist/cjs/model/message-diagnostics.js +17 -4
  125. package/dist/cjs/model/options.js +9 -1
  126. package/dist/cjs/model/preparation.js +86 -12
  127. package/dist/cjs/model/runner.js +413 -79
  128. package/dist/cjs/model/selection-transport.js +48 -8
  129. package/dist/cjs/model/settings.js +67 -13
  130. package/dist/cjs/model/token-budget.js +69 -11
  131. package/dist/cjs/model/transports.js +59 -6
  132. package/dist/cjs/structs/common.js +11 -0
  133. package/dist/cjs/structs/debug.js +34 -5
  134. package/dist/cjs/structs/errors.js +26 -1
  135. package/dist/cjs/structs/index.js +11 -1
  136. package/dist/cjs/structs/kits/durable.js +7 -0
  137. package/dist/cjs/structs/kits/family.js +1 -0
  138. package/dist/cjs/structs/kits/interaction.js +8 -1
  139. package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
  140. package/dist/cjs/structs/kits/reflection.js +18 -3
  141. package/dist/cjs/structs/model/chat-provider.js +6 -0
  142. package/dist/cjs/structs/support/model/completion.js +2 -0
  143. package/dist/cjs/structs/support/model/messages.js +2 -0
  144. package/dist/cjs/support/capabilities.js +43 -6
  145. package/dist/cjs/support/context/assembly.js +88 -16
  146. package/dist/cjs/support/context/compression.js +48 -6
  147. package/dist/cjs/support/context/fragments.js +6 -0
  148. package/dist/cjs/support/context/history.js +36 -1
  149. package/dist/cjs/support/context/index.js +11 -0
  150. package/dist/cjs/support/context/nodes.js +164 -35
  151. package/dist/cjs/support/context/processing.js +319 -61
  152. package/dist/cjs/support/context/selection-policy.js +98 -21
  153. package/dist/cjs/support/context/selection.js +61 -10
  154. package/dist/cjs/support/context/snapshot.js +29 -7
  155. package/dist/cjs/support/context/strategies.js +120 -28
  156. package/dist/cjs/support/index.js +9 -1
  157. package/dist/cjs/support/model/capabilities.js +20 -1
  158. package/dist/cjs/support/model/chat-completions.js +92 -20
  159. package/dist/cjs/support/model/children.js +34 -6
  160. package/dist/cjs/support/model/compatible-provider.js +189 -59
  161. package/dist/cjs/support/model/completion/calls.js +61 -0
  162. package/dist/cjs/support/model/completion/default.js +33 -0
  163. package/dist/cjs/support/model/completion/index.js +28 -0
  164. package/dist/cjs/support/model/completion/session.js +107 -0
  165. package/dist/cjs/support/model/index.js +12 -0
  166. package/dist/cjs/support/model/interactions/index.js +12 -1
  167. package/dist/cjs/support/model/interactions/json-object.js +6 -0
  168. package/dist/cjs/support/model/interactions/native-functions.js +6 -0
  169. package/dist/cjs/support/model/observer.js +32 -6
  170. package/dist/cjs/support/model/preview-rules.js +66 -16
  171. package/dist/cjs/support/model/reply-preview.js +77 -17
  172. package/dist/cjs/support/model/stage-transport.js +33 -7
  173. package/dist/cjs/support/model/strategies.js +75 -14
  174. package/dist/cjs/support/model/transports.js +53 -11
  175. package/dist/cjs/support/registration.js +49 -7
  176. package/dist/cjs/support/schema.js +46 -4
  177. package/dist/cjs/support/stream-events.js +60 -8
  178. package/dist/cjs/support/tool-runtime.js +6 -0
  179. package/dist/cjs/support/tools.js +79 -10
  180. package/dist/cjs/support/transport/index.js +7 -0
  181. package/dist/cjs/support/transport/json.js +28 -4
  182. package/dist/cjs/support/transport/sse.js +25 -2
  183. package/dist/cjs/utils/break-observer.js +20 -2
  184. package/dist/cjs/utils/cancellation.js +77 -9
  185. package/dist/cjs/utils/catalog.js +19 -4
  186. package/dist/cjs/utils/debug.js +14 -2
  187. package/dist/cjs/utils/index.js +8 -0
  188. package/dist/cjs/utils/interaction-definition.js +26 -6
  189. package/dist/cjs/utils/invocation.js +42 -4
  190. package/dist/cjs/utils/model-protocol.js +20 -1
  191. package/dist/cjs/utils/object.js +16 -0
  192. package/dist/cjs/utils/observer.js +22 -2
  193. package/dist/cjs/utils/protocol-registry.js +47 -4
  194. package/dist/cjs/utils/query-key.js +21 -2
  195. package/dist/cjs/utils/registration.js +18 -2
  196. package/dist/cjs/utils/rules.js +39 -11
  197. package/dist/cjs/utils/schema-adapter.js +25 -2
  198. package/dist/cjs/utils/synchronous.js +64 -7
  199. package/dist/cjs/utils/text.js +15 -1
  200. package/dist/esm/capabilities/index.d.ts +13 -0
  201. package/dist/esm/capabilities/index.js +13 -0
  202. package/dist/esm/capabilities/invocation.d.ts +16 -2
  203. package/dist/esm/capabilities/invocation.js +80 -10
  204. package/dist/esm/capabilities/model.d.ts +68 -1
  205. package/dist/esm/capabilities/model.js +126 -13
  206. package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
  207. package/dist/esm/capabilities/tool-runtime.js +64 -12
  208. package/dist/esm/capabilities/tools.d.ts +96 -3
  209. package/dist/esm/capabilities/tools.js +267 -32
  210. package/dist/esm/context/assembly.d.ts +13 -2
  211. package/dist/esm/context/assembly.js +46 -5
  212. package/dist/esm/context/audit.d.ts +23 -1
  213. package/dist/esm/context/audit.js +31 -6
  214. package/dist/esm/context/fragments.d.ts +37 -3
  215. package/dist/esm/context/fragments.js +54 -11
  216. package/dist/esm/context/index.d.ts +12 -0
  217. package/dist/esm/context/index.js +12 -0
  218. package/dist/esm/context/journal.d.ts +32 -1
  219. package/dist/esm/context/journal.js +84 -7
  220. package/dist/esm/context/plan.d.ts +11 -1
  221. package/dist/esm/context/plan.js +30 -2
  222. package/dist/esm/diagnostics/catalog.d.ts +6 -0
  223. package/dist/esm/diagnostics/catalog.js +17 -3
  224. package/dist/esm/diagnostics/index.d.ts +30 -2
  225. package/dist/esm/diagnostics/index.js +149 -29
  226. package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
  227. package/dist/esm/diagnostics/sub-flow.js +240 -40
  228. package/dist/esm/errors.d.ts +22 -2
  229. package/dist/esm/errors.js +99 -17
  230. package/dist/esm/execution/branch.d.ts +19 -1
  231. package/dist/esm/execution/branch.js +20 -4
  232. package/dist/esm/execution/engine.d.ts +291 -5
  233. package/dist/esm/execution/engine.js +471 -57
  234. package/dist/esm/execution/events.d.ts +16 -2
  235. package/dist/esm/execution/events.js +136 -18
  236. package/dist/esm/execution/index.d.ts +7 -0
  237. package/dist/esm/execution/index.js +7 -0
  238. package/dist/esm/execution/reporting.d.ts +49 -1
  239. package/dist/esm/execution/reporting.js +75 -6
  240. package/dist/esm/execution/state.d.ts +126 -10
  241. package/dist/esm/execution/state.js +161 -22
  242. package/dist/esm/execution/workflow.d.ts +121 -3
  243. package/dist/esm/execution/workflow.js +224 -32
  244. package/dist/esm/index.d.ts +17 -1
  245. package/dist/esm/index.js +18 -0
  246. package/dist/esm/kits/aggregation.d.ts +34 -2
  247. package/dist/esm/kits/aggregation.js +45 -3
  248. package/dist/esm/kits/answering/batch.d.ts +17 -0
  249. package/dist/esm/kits/answering/batch.js +23 -4
  250. package/dist/esm/kits/answering/check-result.d.ts +18 -1
  251. package/dist/esm/kits/answering/check-result.js +31 -8
  252. package/dist/esm/kits/answering/checks.d.ts +11 -0
  253. package/dist/esm/kits/answering/checks.js +24 -3
  254. package/dist/esm/kits/answering/flow.d.ts +25 -2
  255. package/dist/esm/kits/answering/flow.js +192 -36
  256. package/dist/esm/kits/answering/index.d.ts +12 -0
  257. package/dist/esm/kits/answering/index.js +19 -1
  258. package/dist/esm/kits/answering/tasks.d.ts +32 -1
  259. package/dist/esm/kits/answering/tasks.js +88 -13
  260. package/dist/esm/kits/artifacts.d.ts +11 -0
  261. package/dist/esm/kits/artifacts.js +36 -4
  262. package/dist/esm/kits/candidates.d.ts +23 -1
  263. package/dist/esm/kits/candidates.js +47 -5
  264. package/dist/esm/kits/delivery.d.ts +34 -0
  265. package/dist/esm/kits/delivery.js +40 -5
  266. package/dist/esm/kits/durable.d.ts +19 -0
  267. package/dist/esm/kits/durable.js +155 -31
  268. package/dist/esm/kits/evidence.d.ts +28 -5
  269. package/dist/esm/kits/evidence.js +66 -15
  270. package/dist/esm/kits/family.d.ts +17 -1
  271. package/dist/esm/kits/family.js +152 -22
  272. package/dist/esm/kits/index.d.ts +12 -1
  273. package/dist/esm/kits/index.js +12 -1
  274. package/dist/esm/kits/inference.d.ts +64 -0
  275. package/dist/esm/kits/inference.js +104 -16
  276. package/dist/esm/kits/intents/catalog.d.ts +13 -1
  277. package/dist/esm/kits/intents/catalog.js +67 -16
  278. package/dist/esm/kits/intents/index.d.ts +11 -0
  279. package/dist/esm/kits/intents/index.js +11 -0
  280. package/dist/esm/kits/intents/registry.d.ts +61 -3
  281. package/dist/esm/kits/intents/registry.js +188 -43
  282. package/dist/esm/kits/intents/scopes.d.ts +73 -3
  283. package/dist/esm/kits/intents/scopes.js +215 -46
  284. package/dist/esm/kits/interaction/command.d.ts +38 -4
  285. package/dist/esm/kits/interaction/command.js +140 -36
  286. package/dist/esm/kits/interaction/commands.d.ts +66 -2
  287. package/dist/esm/kits/interaction/commands.js +86 -11
  288. package/dist/esm/kits/interaction/handlers.d.ts +19 -2
  289. package/dist/esm/kits/interaction/handlers.js +27 -10
  290. package/dist/esm/kits/interaction/index.d.ts +10 -0
  291. package/dist/esm/kits/interaction/index.js +10 -0
  292. package/dist/esm/kits/interaction/transfer.d.ts +39 -2
  293. package/dist/esm/kits/interaction/transfer.js +80 -14
  294. package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
  295. package/dist/esm/kits/knowledge/catalog.js +62 -11
  296. package/dist/esm/kits/knowledge/index.d.ts +11 -0
  297. package/dist/esm/kits/knowledge/index.js +16 -1
  298. package/dist/esm/kits/knowledge/publication.d.ts +15 -1
  299. package/dist/esm/kits/knowledge/publication.js +99 -23
  300. package/dist/esm/kits/knowledge/sections.d.ts +31 -1
  301. package/dist/esm/kits/knowledge/sections.js +33 -4
  302. package/dist/esm/kits/normalization.d.ts +25 -2
  303. package/dist/esm/kits/normalization.js +51 -7
  304. package/dist/esm/kits/policies.d.ts +26 -3
  305. package/dist/esm/kits/policies.js +79 -15
  306. package/dist/esm/kits/presentation/events.d.ts +51 -4
  307. package/dist/esm/kits/presentation/events.js +54 -10
  308. package/dist/esm/kits/presentation/index.d.ts +12 -0
  309. package/dist/esm/kits/presentation/index.js +25 -2
  310. package/dist/esm/kits/presentation/outputs.d.ts +30 -1
  311. package/dist/esm/kits/presentation/outputs.js +176 -38
  312. package/dist/esm/kits/presentation/templates.d.ts +32 -3
  313. package/dist/esm/kits/presentation/templates.js +33 -5
  314. package/dist/esm/kits/presentation/variants.d.ts +29 -0
  315. package/dist/esm/kits/presentation/variants.js +31 -2
  316. package/dist/esm/kits/projection.d.ts +42 -5
  317. package/dist/esm/kits/projection.js +63 -8
  318. package/dist/esm/kits/rank-fusion.d.ts +21 -1
  319. package/dist/esm/kits/rank-fusion.js +28 -5
  320. package/dist/esm/kits/reflection-log-source.d.ts +28 -1
  321. package/dist/esm/kits/reflection-log-source.js +89 -16
  322. package/dist/esm/kits/reflection.d.ts +17 -1
  323. package/dist/esm/kits/reflection.js +235 -61
  324. package/dist/esm/kits/retrieval.d.ts +18 -2
  325. package/dist/esm/kits/retrieval.js +98 -18
  326. package/dist/esm/kits/search.d.ts +56 -3
  327. package/dist/esm/kits/search.js +180 -27
  328. package/dist/esm/kits/text-skills.d.ts +16 -2
  329. package/dist/esm/kits/text-skills.js +104 -19
  330. package/dist/esm/kits/tools.d.ts +122 -2
  331. package/dist/esm/kits/tools.js +416 -74
  332. package/dist/esm/kits/vector-search.d.ts +47 -1
  333. package/dist/esm/kits/vector-search.js +51 -17
  334. package/dist/esm/mock/node.d.ts +7 -0
  335. package/dist/esm/mock/node.js +7 -1
  336. package/dist/esm/mock/web.d.ts +7 -0
  337. package/dist/esm/mock/web.js +7 -1
  338. package/dist/esm/mock.d.ts +7 -0
  339. package/dist/esm/mock.js +7 -1
  340. package/dist/esm/model/binding.d.ts +32 -3
  341. package/dist/esm/model/binding.js +68 -17
  342. package/dist/esm/model/call-budget.d.ts +30 -2
  343. package/dist/esm/model/call-budget.js +45 -4
  344. package/dist/esm/model/decision-retry.d.ts +10 -1
  345. package/dist/esm/model/decision-retry.js +19 -1
  346. package/dist/esm/model/defaults.d.ts +13 -2
  347. package/dist/esm/model/defaults.js +27 -4
  348. package/dist/esm/model/index.d.ts +7 -0
  349. package/dist/esm/model/index.js +7 -0
  350. package/dist/esm/model/interactions/arguments.d.ts +27 -0
  351. package/dist/esm/model/interactions/arguments.js +36 -1
  352. package/dist/esm/model/interactions/json-object.d.ts +7 -1
  353. package/dist/esm/model/interactions/json-object.js +48 -12
  354. package/dist/esm/model/interactions/native-functions.d.ts +6 -0
  355. package/dist/esm/model/interactions/native-functions.js +52 -10
  356. package/dist/esm/model/message-diagnostics.d.ts +17 -1
  357. package/dist/esm/model/message-diagnostics.js +17 -4
  358. package/dist/esm/model/options.d.ts +18 -1
  359. package/dist/esm/model/options.js +9 -1
  360. package/dist/esm/model/preparation.d.ts +30 -2
  361. package/dist/esm/model/preparation.js +86 -12
  362. package/dist/esm/model/runner.d.ts +129 -5
  363. package/dist/esm/model/runner.js +414 -80
  364. package/dist/esm/model/selection-transport.d.ts +14 -1
  365. package/dist/esm/model/selection-transport.js +48 -8
  366. package/dist/esm/model/settings.d.ts +11 -0
  367. package/dist/esm/model/settings.js +67 -13
  368. package/dist/esm/model/token-budget.d.ts +59 -1
  369. package/dist/esm/model/token-budget.js +69 -11
  370. package/dist/esm/model/transports.d.ts +20 -2
  371. package/dist/esm/model/transports.js +59 -6
  372. package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
  373. package/dist/esm/structs/capabilities/model.d.ts +27 -0
  374. package/dist/esm/structs/capabilities/tools.d.ts +38 -0
  375. package/dist/esm/structs/common.d.ts +62 -2
  376. package/dist/esm/structs/common.js +11 -0
  377. package/dist/esm/structs/context/fragments.d.ts +28 -0
  378. package/dist/esm/structs/context/journal.d.ts +28 -3
  379. package/dist/esm/structs/context/processing.d.ts +11 -0
  380. package/dist/esm/structs/debug.d.ts +58 -1
  381. package/dist/esm/structs/debug.js +34 -5
  382. package/dist/esm/structs/diagnostics.d.ts +119 -1
  383. package/dist/esm/structs/errors.d.ts +42 -1
  384. package/dist/esm/structs/errors.js +26 -1
  385. package/dist/esm/structs/execution/engine.d.ts +24 -1
  386. package/dist/esm/structs/execution/events.d.ts +12 -0
  387. package/dist/esm/structs/execution/workflow.d.ts +71 -0
  388. package/dist/esm/structs/index.d.ts +11 -1
  389. package/dist/esm/structs/index.js +11 -1
  390. package/dist/esm/structs/invocation.d.ts +30 -0
  391. package/dist/esm/structs/kits/aggregation.d.ts +12 -0
  392. package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
  393. package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
  394. package/dist/esm/structs/kits/answering/state.d.ts +21 -0
  395. package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
  396. package/dist/esm/structs/kits/artifacts.d.ts +14 -0
  397. package/dist/esm/structs/kits/candidates.d.ts +19 -0
  398. package/dist/esm/structs/kits/delivery.d.ts +22 -0
  399. package/dist/esm/structs/kits/durable.d.ts +56 -3
  400. package/dist/esm/structs/kits/durable.js +7 -0
  401. package/dist/esm/structs/kits/evidence.d.ts +23 -0
  402. package/dist/esm/structs/kits/family.d.ts +49 -1
  403. package/dist/esm/structs/kits/family.js +1 -0
  404. package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
  405. package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
  406. package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
  407. package/dist/esm/structs/kits/interaction.d.ts +64 -0
  408. package/dist/esm/structs/kits/interaction.js +8 -1
  409. package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
  410. package/dist/esm/structs/kits/knowledge-publication.js +1 -0
  411. package/dist/esm/structs/kits/knowledge.d.ts +39 -2
  412. package/dist/esm/structs/kits/normalization.d.ts +15 -0
  413. package/dist/esm/structs/kits/policies.d.ts +25 -1
  414. package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
  415. package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
  416. package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
  417. package/dist/esm/structs/kits/projection.d.ts +21 -0
  418. package/dist/esm/structs/kits/reflection.d.ts +61 -2
  419. package/dist/esm/structs/kits/reflection.js +18 -3
  420. package/dist/esm/structs/kits/retrieval.d.ts +39 -0
  421. package/dist/esm/structs/kits/search.d.ts +24 -0
  422. package/dist/esm/structs/kits/text-skills.d.ts +36 -0
  423. package/dist/esm/structs/kits/tools.d.ts +87 -0
  424. package/dist/esm/structs/model/chat-provider.d.ts +24 -1
  425. package/dist/esm/structs/model/chat-provider.js +6 -0
  426. package/dist/esm/structs/model/interactions.d.ts +38 -0
  427. package/dist/esm/structs/model/messages.d.ts +34 -0
  428. package/dist/esm/structs/model/runtime.d.ts +104 -6
  429. package/dist/esm/structs/support/capabilities.d.ts +19 -2
  430. package/dist/esm/structs/support/context-processing.d.ts +88 -9
  431. package/dist/esm/structs/support/context.d.ts +29 -1
  432. package/dist/esm/structs/support/model/completion.d.ts +50 -0
  433. package/dist/esm/structs/support/model/completion.js +1 -0
  434. package/dist/esm/structs/support/model/interactions.d.ts +13 -1
  435. package/dist/esm/structs/support/model/messages.d.ts +54 -0
  436. package/dist/esm/structs/support/model/messages.js +1 -0
  437. package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
  438. package/dist/esm/structs/support/model/provider.d.ts +71 -6
  439. package/dist/esm/structs/support/registration.d.ts +13 -0
  440. package/dist/esm/structs/support/schema.d.ts +14 -0
  441. package/dist/esm/structs/support/tools.d.ts +28 -0
  442. package/dist/esm/structs/support/transport/json.d.ts +16 -0
  443. package/dist/esm/structs/support/transport/sse.d.ts +15 -0
  444. package/dist/esm/structs/utils/rules.d.ts +19 -0
  445. package/dist/esm/support/capabilities.d.ts +25 -2
  446. package/dist/esm/support/capabilities.js +43 -6
  447. package/dist/esm/support/context/assembly.d.ts +35 -4
  448. package/dist/esm/support/context/assembly.js +88 -16
  449. package/dist/esm/support/context/compression.d.ts +17 -1
  450. package/dist/esm/support/context/compression.js +48 -6
  451. package/dist/esm/support/context/fragments.d.ts +6 -0
  452. package/dist/esm/support/context/fragments.js +6 -0
  453. package/dist/esm/support/context/history.d.ts +43 -0
  454. package/dist/esm/support/context/history.js +36 -1
  455. package/dist/esm/support/context/index.d.ts +13 -2
  456. package/dist/esm/support/context/index.js +12 -1
  457. package/dist/esm/support/context/nodes.d.ts +65 -3
  458. package/dist/esm/support/context/nodes.js +165 -36
  459. package/dist/esm/support/context/processing.d.ts +152 -1
  460. package/dist/esm/support/context/processing.js +320 -62
  461. package/dist/esm/support/context/selection-policy.d.ts +42 -2
  462. package/dist/esm/support/context/selection-policy.js +98 -21
  463. package/dist/esm/support/context/selection.d.ts +14 -1
  464. package/dist/esm/support/context/selection.js +61 -10
  465. package/dist/esm/support/context/snapshot.d.ts +23 -1
  466. package/dist/esm/support/context/snapshot.js +29 -7
  467. package/dist/esm/support/context/strategies.d.ts +35 -2
  468. package/dist/esm/support/context/strategies.js +120 -28
  469. package/dist/esm/support/index.d.ts +9 -1
  470. package/dist/esm/support/index.js +9 -1
  471. package/dist/esm/support/model/capabilities.d.ts +10 -0
  472. package/dist/esm/support/model/capabilities.js +20 -1
  473. package/dist/esm/support/model/chat-completions.d.ts +44 -15
  474. package/dist/esm/support/model/chat-completions.js +92 -20
  475. package/dist/esm/support/model/children.d.ts +34 -2
  476. package/dist/esm/support/model/children.js +34 -6
  477. package/dist/esm/support/model/compatible-provider.d.ts +29 -3
  478. package/dist/esm/support/model/compatible-provider.js +190 -60
  479. package/dist/esm/support/model/completion/calls.d.ts +40 -0
  480. package/dist/esm/support/model/completion/calls.js +58 -0
  481. package/dist/esm/support/model/completion/default.d.ts +11 -0
  482. package/dist/esm/support/model/completion/default.js +30 -0
  483. package/dist/esm/support/model/completion/index.d.ts +10 -0
  484. package/dist/esm/support/model/completion/index.js +22 -0
  485. package/dist/esm/support/model/completion/session.d.ts +16 -0
  486. package/dist/esm/support/model/completion/session.js +104 -0
  487. package/dist/esm/support/model/index.d.ts +14 -0
  488. package/dist/esm/support/model/index.js +12 -0
  489. package/dist/esm/support/model/interactions/index.d.ts +1 -1
  490. package/dist/esm/support/model/interactions/index.js +12 -1
  491. package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
  492. package/dist/esm/support/model/interactions/json-object.js +6 -0
  493. package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
  494. package/dist/esm/support/model/interactions/native-functions.js +6 -0
  495. package/dist/esm/support/model/observer.d.ts +25 -2
  496. package/dist/esm/support/model/observer.js +32 -6
  497. package/dist/esm/support/model/preview-rules.d.ts +26 -2
  498. package/dist/esm/support/model/preview-rules.js +66 -16
  499. package/dist/esm/support/model/reply-preview.d.ts +22 -1
  500. package/dist/esm/support/model/reply-preview.js +77 -17
  501. package/dist/esm/support/model/stage-transport.d.ts +9 -1
  502. package/dist/esm/support/model/stage-transport.js +33 -7
  503. package/dist/esm/support/model/strategies.d.ts +28 -2
  504. package/dist/esm/support/model/strategies.js +75 -14
  505. package/dist/esm/support/model/transports.d.ts +17 -1
  506. package/dist/esm/support/model/transports.js +53 -11
  507. package/dist/esm/support/registration.d.ts +20 -1
  508. package/dist/esm/support/registration.js +49 -7
  509. package/dist/esm/support/schema.d.ts +31 -1
  510. package/dist/esm/support/schema.js +46 -4
  511. package/dist/esm/support/stream-events.d.ts +22 -1
  512. package/dist/esm/support/stream-events.js +60 -8
  513. package/dist/esm/support/tool-runtime.d.ts +6 -0
  514. package/dist/esm/support/tool-runtime.js +6 -0
  515. package/dist/esm/support/tools.d.ts +22 -0
  516. package/dist/esm/support/tools.js +79 -10
  517. package/dist/esm/support/transport/index.d.ts +7 -0
  518. package/dist/esm/support/transport/index.js +7 -0
  519. package/dist/esm/support/transport/json.d.ts +29 -2
  520. package/dist/esm/support/transport/json.js +28 -4
  521. package/dist/esm/support/transport/sse.d.ts +31 -1
  522. package/dist/esm/support/transport/sse.js +25 -2
  523. package/dist/esm/types.d.ts +9 -1
  524. package/dist/esm/utils/break-observer.d.ts +27 -2
  525. package/dist/esm/utils/break-observer.js +20 -2
  526. package/dist/esm/utils/cancellation.d.ts +56 -5
  527. package/dist/esm/utils/cancellation.js +77 -9
  528. package/dist/esm/utils/catalog.d.ts +20 -1
  529. package/dist/esm/utils/catalog.js +19 -4
  530. package/dist/esm/utils/debug.d.ts +20 -1
  531. package/dist/esm/utils/debug.js +14 -2
  532. package/dist/esm/utils/index.d.ts +8 -0
  533. package/dist/esm/utils/index.js +8 -0
  534. package/dist/esm/utils/interaction-definition.d.ts +18 -1
  535. package/dist/esm/utils/interaction-definition.js +26 -6
  536. package/dist/esm/utils/invocation.d.ts +36 -1
  537. package/dist/esm/utils/invocation.js +42 -4
  538. package/dist/esm/utils/model-protocol.d.ts +8 -0
  539. package/dist/esm/utils/model-protocol.js +20 -1
  540. package/dist/esm/utils/object.d.ts +16 -0
  541. package/dist/esm/utils/object.js +16 -0
  542. package/dist/esm/utils/observer.d.ts +19 -1
  543. package/dist/esm/utils/observer.js +22 -2
  544. package/dist/esm/utils/protocol-registry.d.ts +38 -1
  545. package/dist/esm/utils/protocol-registry.js +47 -4
  546. package/dist/esm/utils/query-key.d.ts +11 -1
  547. package/dist/esm/utils/query-key.js +21 -2
  548. package/dist/esm/utils/registration.d.ts +34 -2
  549. package/dist/esm/utils/registration.js +18 -2
  550. package/dist/esm/utils/rules.d.ts +81 -4
  551. package/dist/esm/utils/rules.js +39 -11
  552. package/dist/esm/utils/schema-adapter.d.ts +12 -1
  553. package/dist/esm/utils/schema-adapter.js +25 -2
  554. package/dist/esm/utils/synchronous.d.ts +60 -4
  555. package/dist/esm/utils/synchronous.js +64 -7
  556. package/dist/esm/utils/text.d.ts +15 -1
  557. package/dist/esm/utils/text.js +15 -1
  558. package/package.json +7 -3
@@ -1,37 +1,81 @@
1
+ /**
2
+ * Interaction Kit: compile a single command protocol from field declarations.
3
+ *
4
+ * Place in the package: part of the `interaction` Kit. Parsing is synchronous and never
5
+ * executes a registered tool; it only validates the shape and applies an optional formatter.
6
+ *
7
+ * Exports: `defineCommand`, `compileCommands`, `commandSchema`, and the protocol types.
8
+ */
1
9
  import { pinCommandDefinition } from '../../utils/interaction-definition.js';
2
10
  import { assertion, booleanResult, synchronous } from '../../utils/synchronous.js';
3
11
  import { freezeSchema } from '../../utils/object.js';
4
12
  import { breakWhile } from '../../utils/rules.js';
5
13
  import { INTERACTION_CATEGORIES } from '../../structs/kits/interaction.js';
6
14
  function reason(error, value, args) {
7
- return () => typeof error === 'function' ? error(value, ...args) : error ?? new TypeError('Invalid protocol value');
15
+ return () => typeof error === 'function'
16
+ ? error(value, ...args)
17
+ : (error ?? new TypeError('Invalid protocol value'));
8
18
  }
9
- /** Compile declarations once. Parsing is synchronous and never executes a registered tool. */
19
+ /**
20
+ * Compile declarations once. Parsing is synchronous and never executes a registered tool.
21
+ *
22
+ * Two schemas are produced from one declaration: `modelJsonSchema` marks only fields the model
23
+ * must fill, while `inputJsonSchema` marks every required field. A discriminator, when present,
24
+ * is prepended as a required constant field.
25
+ *
26
+ * @param definition - Fields, discriminator, checks, tags, error wording and optional
27
+ * formatter; predicates and formatters are bound to this object.
28
+ * @returns A frozen command with `keys`, `assert`, `parse` and the three schemas.
29
+ * @throws TypeError For an unknown category, a duplicate field or discriminator field, a check
30
+ * that still uses the retired `condition`/`conditions` names, or a non-synchronous predicate.
31
+ */
10
32
  export function defineCommand(definition) {
11
33
  breakWhile(definition.category !== undefined && !INTERACTION_CATEGORIES.includes(definition.category), 'Invalid interaction category');
12
- const fields = Object.fromEntries(Object.entries(fieldDefinitions(definition.fields)).map(([name, field]) => [name, {
34
+ const fields = Object.fromEntries(Object.entries(fieldDefinitions(definition.fields)).map(([name, field]) => [
35
+ name,
36
+ {
13
37
  jsonSchema: field.jsonSchema === undefined ? undefined : structuredClone(field.jsonSchema),
14
- required: field.required, modelRequired: field.modelRequired, owned: field.owned,
15
- }]));
38
+ required: field.required,
39
+ modelRequired: field.modelRequired,
40
+ owned: field.owned,
41
+ },
42
+ ]));
16
43
  for (const name of definition.ownedFields ?? []) {
17
44
  if (!Object.hasOwn(fields, name))
18
45
  Object.defineProperty(fields, name, { value: {}, enumerable: true });
19
46
  }
20
- const discriminator = definition.discriminator && { field: definition.discriminator.field, value: definition.discriminator.value };
47
+ const discriminator = definition.discriminator && {
48
+ field: definition.discriminator.field,
49
+ value: definition.discriminator.value,
50
+ };
21
51
  breakWhile(discriminator && Object.hasOwn(fields, discriminator.field), 'Duplicate protocol discriminator field');
22
52
  const entries = [
23
- ...(discriminator ? [[discriminator.field, { required: true, jsonSchema: { type: 'string', enum: [discriminator.value] } }]] : []),
53
+ ...(discriminator
54
+ ? [
55
+ [
56
+ discriminator.field,
57
+ { required: true, jsonSchema: { type: 'string', enum: [discriminator.value] } },
58
+ ],
59
+ ]
60
+ : []),
24
61
  ...Object.entries(fields),
25
62
  ];
26
- const checks = (definition.checks ?? []).map(check => {
63
+ const checks = (definition.checks ?? []).map((check) => {
27
64
  if (!check || check.occur === undefined || 'condition' in check || 'conditions' in check)
28
65
  throw new TypeError('Protocol checks require occur');
29
66
  const bind = (predicate) => predicate?.bind(check);
30
- if (typeof check.occur !== 'function' && (!Array.isArray(check.occur) || check.occur.some(predicate => typeof predicate !== 'function')))
67
+ if (typeof check.occur !== 'function' &&
68
+ (!Array.isArray(check.occur) ||
69
+ check.occur.some((predicate) => typeof predicate !== 'function')))
31
70
  throw new TypeError('Protocol occur requires a predicate or predicate array');
32
- return Object.freeze({ occur: typeof check.occur === 'function' ? check.occur.bind(check) : Object.freeze(check.occur.map(predicate => predicate.bind(check))),
33
- when: bind(check.when), error: typeof check.error === 'function' ? check.error.bind(check) : check.error,
34
- tags: Object.freeze([...(check.tags ?? [])]) });
71
+ return Object.freeze({
72
+ occur: typeof check.occur === 'function'
73
+ ? check.occur.bind(check)
74
+ : Object.freeze(check.occur.map((predicate) => predicate.bind(check))),
75
+ when: bind(check.when),
76
+ error: typeof check.error === 'function' ? check.error.bind(check) : check.error,
77
+ tags: Object.freeze([...(check.tags ?? [])]),
78
+ });
35
79
  });
36
80
  const tags = [...(definition.tags ?? [])];
37
81
  const additionalProperties = definition.additionalProperties ?? false;
@@ -40,35 +84,57 @@ export function defineCommand(definition) {
40
84
  const refine = definition.refine?.bind(definition), format = definition.format?.bind(definition);
41
85
  const parameters = Object.fromEntries(Object.entries(fields).map(([name, field]) => [name, field.jsonSchema ?? {}]));
42
86
  const schema = {
43
- type: 'object', properties: Object.fromEntries(entries.map(([name, field]) => [name, field.jsonSchema ?? {}])),
44
- required: entries.filter(([, field]) => field.required && field.modelRequired !== false).map(([name]) => name),
87
+ type: 'object',
88
+ properties: Object.fromEntries(entries.map(([name, field]) => [name, field.jsonSchema ?? {}])),
89
+ required: entries
90
+ .filter(([, field]) => field.required && field.modelRequired !== false)
91
+ .map(([name]) => name),
45
92
  additionalProperties,
46
93
  };
47
- const inputJsonSchema = { ...schema, required: entries.filter(([, field]) => field.required).map(([name]) => name) };
94
+ const inputJsonSchema = {
95
+ ...schema,
96
+ required: entries.filter(([, field]) => field.required).map(([name]) => name),
97
+ };
48
98
  freezeSchema(inputJsonSchema);
49
99
  freezeSchema(fields);
50
100
  freezeSchema(parameters);
51
101
  freezeSchema(schema);
52
- const keys = (value) => entries.filter(([name, field]) => field.required || (optionalPresence === 'defined' ? value[name] !== undefined : Object.hasOwn(value, name))).map(([name]) => name);
102
+ const keys = (value) => entries
103
+ .filter(([name, field]) => field.required ||
104
+ (optionalPresence === 'defined' ? value[name] !== undefined : Object.hasOwn(value, name)))
105
+ .map(([name]) => name);
53
106
  const validate = (value, ...args) => {
54
107
  const fail = reason(error, value, args);
55
108
  breakWhile(!value || typeof value !== 'object' || Array.isArray(value), fail, tags);
56
109
  const record = value;
57
110
  const expected = keys(record);
58
111
  breakWhile([
59
- { occur: () => expected.some(name => !Object.hasOwn(record, name)), error: fail, tags: ['required-fields'] },
60
112
  {
61
- occur: () => !additionalProperties && Object.keys(record).some(name => !expected.includes(name)),
62
- error: fail, tags: ['unknown-fields'],
113
+ occur: () => expected.some((name) => !Object.hasOwn(record, name)),
114
+ error: fail,
115
+ tags: ['required-fields'],
116
+ },
117
+ {
118
+ occur: () => !additionalProperties && Object.keys(record).some((name) => !expected.includes(name)),
119
+ error: fail,
120
+ tags: ['unknown-fields'],
121
+ },
122
+ {
123
+ occur: () => discriminator && record[discriminator.field] !== discriminator.value,
124
+ error: fail,
125
+ tags: ['discriminator'],
63
126
  },
64
- { occur: () => discriminator && record[discriminator.field] !== discriminator.value, error: fail, tags: ['discriminator'] },
65
- ...checks.map(check => ({
127
+ ...checks.map((check) => ({
66
128
  occur: () => {
67
- if (check.when && !booleanResult(check.when(value, ...args), 'Protocol when predicates must return boolean synchronously'))
129
+ if (check.when &&
130
+ !booleanResult(check.when(value, ...args), 'Protocol when predicates must return boolean synchronously'))
68
131
  return false;
69
- return typeof check.occur === 'function' ? synchronous(check.occur(value, ...args), 'Protocol occur predicates must be synchronous') : check.occur.some(occur => synchronous(occur(value, ...args), 'Protocol occur predicates must be synchronous'));
132
+ return typeof check.occur === 'function'
133
+ ? synchronous(check.occur(value, ...args), 'Protocol occur predicates must be synchronous')
134
+ : check.occur.some((occur) => synchronous(occur(value, ...args), 'Protocol occur predicates must be synchronous'));
70
135
  },
71
- error: reason(check.error ?? error, value, args), tags: check.tags,
136
+ error: reason(check.error ?? error, value, args),
137
+ tags: check.tags,
72
138
  })),
73
139
  ], tags);
74
140
  assertion(refine?.(value, ...args), 'Protocol refinements must return void synchronously');
@@ -78,14 +144,25 @@ export function defineCommand(definition) {
78
144
  ...(definition.version !== undefined ? { version: definition.version } : {}),
79
145
  ...(definition.description !== undefined ? { description: definition.description } : {}),
80
146
  ...(definition.terminal !== undefined ? { terminal: definition.terminal } : {}),
81
- fieldSchemas: parameters, modelJsonSchema: schema, inputJsonSchema, keys, assert: validate,
147
+ fieldSchemas: parameters,
148
+ modelJsonSchema: schema,
149
+ inputJsonSchema,
150
+ keys,
151
+ assert: validate,
82
152
  modes: definition.modes && Object.freeze([...definition.modes]),
83
- ownedFields: Object.freeze([...new Set([
84
- ...(definition.ownedFields ?? []), ...Object.entries(fields).filter(([, field]) => field.owned).map(([name]) => name),
85
- ])]),
153
+ ownedFields: Object.freeze([
154
+ ...new Set([
155
+ ...(definition.ownedFields ?? []),
156
+ ...Object.entries(fields)
157
+ .filter(([, field]) => field.owned)
158
+ .map(([name]) => name),
159
+ ]),
160
+ ]),
86
161
  parse(value, ...args) {
87
162
  validate(value, ...args);
88
- return format ? synchronous(format(value, ...args), 'Protocol formatters must be synchronous') : value;
163
+ return format
164
+ ? synchronous(format(value, ...args), 'Protocol formatters must be synchronous')
165
+ : value;
89
166
  },
90
167
  });
91
168
  }
@@ -93,9 +170,20 @@ function fieldDefinitions(fields) {
93
170
  if (!Array.isArray(fields))
94
171
  return fields;
95
172
  breakWhile(new Set(fields).size !== fields.length, 'Duplicate protocol field');
96
- return Object.fromEntries(fields.map(name => [name, {}]));
173
+ return Object.fromEntries(fields.map((name) => [name, {}]));
97
174
  }
98
- /** Install an entire catalog with shared envelope fields; applications declare data and handlers only. */
175
+ /**
176
+ * Compile a whole catalog with shared envelope fields.
177
+ *
178
+ * Applications declare only their own data and handlers. Defaults are merged in this order:
179
+ * unrelated default keys, then the command's own keys, with `fields`, `checks` and `tags`
180
+ * concatenated so shared envelope checks always run before per-command checks.
181
+ *
182
+ * @param definitions - Commands keyed by their wire id.
183
+ * @param defaults - Shared envelope definition; its discriminator field is removed per command.
184
+ * @returns A frozen record from id to compiled command.
185
+ * @throws TypeError From `defineCommand` for the first invalid declaration.
186
+ */
99
187
  export function compileCommands(definitions, defaults = {}) {
100
188
  defaults = pinCommandDefinition(defaults);
101
189
  return Object.freeze(Object.fromEntries(Object.entries(definitions).map(([id, value]) => {
@@ -103,20 +191,36 @@ export function compileCommands(definitions, defaults = {}) {
103
191
  const envelopeFields = { ...fieldDefinitions(defaults.fields ?? {}) };
104
192
  if (definition.discriminator)
105
193
  delete envelopeFields[definition.discriminator.field];
106
- return [id, defineCommand({
107
- ...defaults, ...definition,
194
+ return [
195
+ id,
196
+ defineCommand({
197
+ ...defaults,
198
+ ...definition,
108
199
  fields: { ...envelopeFields, ...fieldDefinitions(definition.fields) },
109
200
  checks: [...(defaults.checks ?? []), ...(definition.checks ?? [])],
110
201
  tags: [...(defaults.tags ?? []), ...(definition.tags ?? [])],
111
- })];
202
+ }),
203
+ ];
112
204
  })));
113
205
  }
114
- /** Prefer compiled schemas; retain the existing open-schema contract for dynamic host protocols. */
206
+ /**
207
+ * Build a JSON schema for one command id.
208
+ *
209
+ * Prefer compiled schemas; retain the existing open-schema contract for dynamic host protocols.
210
+ * A protocol without `fieldSchemas` falls back to an open object that only pins the
211
+ * discriminator, which keeps legacy hosts working without weakening compiled ones.
212
+ *
213
+ * @param id - Command id used as the discriminator value.
214
+ * @param protocol - Compiled command, or a shape carrying only `fieldSchemas`/`keys`.
215
+ * @param discriminator - Field name carrying the command id; defaults to `type`.
216
+ * @returns The compiled model schema, or a generated open schema.
217
+ */
115
218
  export function commandSchema(id, protocol, discriminator = 'type') {
116
219
  if (protocol.modelJsonSchema)
117
220
  return protocol.modelJsonSchema;
118
221
  return {
119
- type: 'object', properties: { [discriminator]: { type: 'string', enum: [id] }, ...protocol.fieldSchemas },
222
+ type: 'object',
223
+ properties: { [discriminator]: { type: 'string', enum: [id] }, ...protocol.fieldSchemas },
120
224
  required: protocol.fieldSchemas ? protocol.keys({ [discriminator]: id }) : [discriminator],
121
225
  additionalProperties: !protocol.fieldSchemas,
122
226
  };
@@ -1,26 +1,90 @@
1
+ /**
2
+ * Interaction Kit: the sealed command catalog shared by every receiving host.
3
+ *
4
+ * Place in the package: part of the `interaction` Kit. It owns mode checks and cross-protocol
5
+ * field-ownership checks that every host must apply identically; the commands themselves are
6
+ * compiled elsewhere.
7
+ *
8
+ * Exports: `CommandCatalog`, `defineCommandCatalog`, and `CommandCatalogOptions`.
9
+ */
1
10
  import type { Command, CommandDefinition, CommandCatalogOptions, InteractionCategory, InteractionDescriptor } from '../../structs/kits/interaction.js';
2
11
  import { ProtocolRegistry } from '../../utils/protocol-registry.js';
3
12
  import { compileCommands } from './command.js';
4
- /** Mode and cross-protocol field ownership checks are shared by all receiving hosts. */
13
+ /**
14
+ * Mode and cross-protocol field ownership checks are shared by all receiving hosts.
15
+ *
16
+ * The catalog seals itself as soon as construction finishes, so a run cannot register a new
17
+ * command later; `set` remains available only for the superclass installation pass.
18
+ */
5
19
  export declare class CommandCatalog<Value extends object = Record<string, unknown>, Result = Value, Args extends unknown[] = [], Id extends string = string> extends ProtocolRegistry<Command<Value, Result, Args> & {
6
20
  readonly id: Id;
7
21
  }> {
22
+ /** Compile and construct a catalog from definitions in one call. */
8
23
  static readonly define: typeof defineCommandCatalog;
24
+ /** Compile a set of definitions with shared envelope fields. */
9
25
  static readonly compile: typeof compileCommands;
10
26
  private sealed;
11
27
  private readonly options;
28
+ /**
29
+ * @param definitions - Compiled `[id, command]` pairs, installed in iteration order.
30
+ * @param options - Mode field, error wording and diagnostic tags used by `parse`.
31
+ */
12
32
  constructor(definitions: Iterable<readonly [Id, Command<Value, Result, Args>]>, options?: CommandCatalogOptions);
33
+ /**
34
+ * Install one compiled command during construction.
35
+ *
36
+ * @throws Error When the id already exists or construction has finished.
37
+ */
13
38
  set(id: string, command: Command<Value, Result, Args>): this;
39
+ /**
40
+ * Removal is not supported.
41
+ *
42
+ * @throws Error Always, because the catalog is sealed.
43
+ */
14
44
  delete(_id: string): boolean;
45
+ /**
46
+ * Clearing is not supported.
47
+ *
48
+ * @throws Error Always, because the catalog is sealed.
49
+ */
15
50
  clear(): void;
51
+ /** Compiled commands in registration order. */
16
52
  get definitions(): readonly Readonly<Command<Value, Result, Args> & {
17
53
  id: Id;
18
54
  }>[];
19
55
  /** Explicit dictionary projection; definitions always remains an ordered array. */
20
56
  toRecord(): Readonly<Record<Id, Command<Value, Result, Args>>>;
21
- /** The same declarations drive purpose-specific menus, documentation and handler binding. */
57
+ /**
58
+ * The same declarations drive purpose-specific menus, documentation and handler binding.
59
+ *
60
+ * @param category - Restrict to one interaction category; omit for every command.
61
+ * @returns Plain descriptors in registration order, without schemas or handlers.
62
+ */
22
63
  manifest(category?: InteractionCategory): readonly InteractionDescriptor[];
64
+ /**
65
+ * Validate and parse one payload as the named command.
66
+ *
67
+ * Checks run before the command's own parser: the id must exist, the mode (when configured)
68
+ * must be allowed, and no other command may claim a field that this payload sets. The last
69
+ * rule prevents one command from silently consuming another command's data.
70
+ *
71
+ * @param id - Command id selected by the caller.
72
+ * @param value - Raw payload.
73
+ * @param args - Extra arguments forwarded to the command parser.
74
+ * @returns The parsed result for that command.
75
+ * @throws A configured error for an unknown command, a disallowed mode or a field owned by
76
+ * another command; the command's own error for a shape violation.
77
+ */
23
78
  parse(id: string, value: Value, ...args: Args): Result;
24
79
  }
80
+ /**
81
+ * Compile definitions and wrap them in a sealed catalog.
82
+ *
83
+ * @param definitions - Command definitions keyed by wire id.
84
+ * @param defaults - Shared envelope definition merged into every command.
85
+ * @param options - Mode field, error wording and diagnostic tags.
86
+ * @returns A sealed catalog ready for `manifest`, `parse` and handler binding.
87
+ * @throws TypeError From compilation for the first invalid definition.
88
+ */
25
89
  export declare function defineCommandCatalog<Value extends object, Result = Value, Args extends unknown[] = [], Id extends string = string>(definitions: Readonly<Record<Id, CommandDefinition<Value, Result, Args>>>, defaults?: Partial<CommandDefinition<Value, Result, Args>>, options?: CommandCatalogOptions): CommandCatalog<Value, Result, Args, Id>;
26
90
  export type { CommandCatalogOptions } from '../../structs/kits/interaction.js';
@@ -1,30 +1,73 @@
1
1
  import { breakWhile } from '../../utils/rules.js';
2
2
  import { ProtocolRegistry } from '../../utils/protocol-registry.js';
3
3
  import { compileCommands } from './command.js';
4
- /** Mode and cross-protocol field ownership checks are shared by all receiving hosts. */
4
+ /**
5
+ * Mode and cross-protocol field ownership checks are shared by all receiving hosts.
6
+ *
7
+ * The catalog seals itself as soon as construction finishes, so a run cannot register a new
8
+ * command later; `set` remains available only for the superclass installation pass.
9
+ */
5
10
  export class CommandCatalog extends ProtocolRegistry {
11
+ /** Compile and construct a catalog from definitions in one call. */
6
12
  static define = defineCommandCatalog;
13
+ /** Compile a set of definitions with shared envelope fields. */
7
14
  static compile = compileCommands;
8
15
  sealed = false;
9
16
  options;
17
+ /**
18
+ * @param definitions - Compiled `[id, command]` pairs, installed in iteration order.
19
+ * @param options - Mode field, error wording and diagnostic tags used by `parse`.
20
+ */
10
21
  constructor(definitions, options = {}) {
11
22
  // Map installation calls this class's set, which normalizes each registered identity.
12
23
  super(definitions);
13
24
  this.options = Object.freeze({ ...options, tags: Object.freeze([...(options.tags ?? [])]) });
14
25
  this.sealed = true;
15
26
  }
27
+ /**
28
+ * Install one compiled command during construction.
29
+ *
30
+ * @throws Error When the id already exists or construction has finished.
31
+ */
16
32
  set(id, command) {
17
33
  if (this.has(id))
18
34
  throw new Error(`Duplicate protocol: ${id}`);
19
35
  if (this.sealed)
20
36
  throw new Error('Command catalog is sealed');
21
- return super.set(id, Object.freeze({ ...command, id: id, fieldSchemas: command.fieldSchemas, modelJsonSchema: command.modelJsonSchema, inputJsonSchema: command.inputJsonSchema,
22
- category: command.category, version: command.version, description: command.description, terminal: command.terminal,
23
- modes: command.modes && Object.freeze([...command.modes]), ownedFields: Object.freeze([...command.ownedFields]),
24
- keys: command.keys.bind(command), assert: command.assert.bind(command), parse: command.parse.bind(command) }));
37
+ return super.set(id, Object.freeze({
38
+ ...command,
39
+ id: id,
40
+ fieldSchemas: command.fieldSchemas,
41
+ modelJsonSchema: command.modelJsonSchema,
42
+ inputJsonSchema: command.inputJsonSchema,
43
+ category: command.category,
44
+ version: command.version,
45
+ description: command.description,
46
+ terminal: command.terminal,
47
+ modes: command.modes && Object.freeze([...command.modes]),
48
+ ownedFields: Object.freeze([...command.ownedFields]),
49
+ keys: command.keys.bind(command),
50
+ assert: command.assert.bind(command),
51
+ parse: command.parse.bind(command),
52
+ }));
25
53
  }
26
- delete(_id) { throw new Error('Command catalog is sealed'); }
27
- clear() { throw new Error('Command catalog is sealed'); }
54
+ /**
55
+ * Removal is not supported.
56
+ *
57
+ * @throws Error Always, because the catalog is sealed.
58
+ */
59
+ delete(_id) {
60
+ throw new Error('Command catalog is sealed');
61
+ }
62
+ /**
63
+ * Clearing is not supported.
64
+ *
65
+ * @throws Error Always, because the catalog is sealed.
66
+ */
67
+ clear() {
68
+ throw new Error('Command catalog is sealed');
69
+ }
70
+ /** Compiled commands in registration order. */
28
71
  get definitions() {
29
72
  return Object.freeze([...this.values()]);
30
73
  }
@@ -32,24 +75,56 @@ export class CommandCatalog extends ProtocolRegistry {
32
75
  toRecord() {
33
76
  return Object.freeze(Object.fromEntries(this));
34
77
  }
35
- /** The same declarations drive purpose-specific menus, documentation and handler binding. */
78
+ /**
79
+ * The same declarations drive purpose-specific menus, documentation and handler binding.
80
+ *
81
+ * @param category - Restrict to one interaction category; omit for every command.
82
+ * @returns Plain descriptors in registration order, without schemas or handlers.
83
+ */
36
84
  manifest(category) {
37
- return Object.freeze([...this].filter(([, command]) => category === undefined || command.category === category)
85
+ return Object.freeze([...this]
86
+ .filter(([, command]) => category === undefined || command.category === category)
38
87
  .map(([id, { category, description, terminal, modes }]) => Object.freeze({ id, category, description, terminal, modes })));
39
88
  }
89
+ /**
90
+ * Validate and parse one payload as the named command.
91
+ *
92
+ * Checks run before the command's own parser: the id must exist, the mode (when configured)
93
+ * must be allowed, and no other command may claim a field that this payload sets. The last
94
+ * rule prevents one command from silently consuming another command's data.
95
+ *
96
+ * @param id - Command id selected by the caller.
97
+ * @param value - Raw payload.
98
+ * @param args - Extra arguments forwarded to the command parser.
99
+ * @returns The parsed result for that command.
100
+ * @throws A configured error for an unknown command, a disallowed mode or a field owned by
101
+ * another command; the command's own error for a shape violation.
102
+ */
40
103
  parse(id, value, ...args) {
41
104
  const protocol = this.get(id);
42
- breakWhile(!protocol, this.options.unknownError ?? 'Unknown command', [...this.options.tags, 'command-selection']);
105
+ breakWhile(!protocol, this.options.unknownError ?? 'Unknown command', [
106
+ ...this.options.tags,
107
+ 'command-selection',
108
+ ]);
43
109
  const record = value;
44
110
  const modeField = this.options.modeField;
45
111
  breakWhile(modeField && !protocol.modes?.includes(record?.[modeField]), this.options.modeError ?? 'Unsupported command mode', [...this.options.tags, 'command-mode']);
46
112
  const ownershipTags = [...this.options.tags, 'field-ownership'];
47
113
  for (const [owner, other] of this) {
48
- breakWhile(owner !== id && other.ownedFields.some(field => record?.[field] !== undefined), this.options.ownershipError ?? 'Field belongs to another command', ownershipTags);
114
+ breakWhile(owner !== id && other.ownedFields.some((field) => record?.[field] !== undefined), this.options.ownershipError ?? 'Field belongs to another command', ownershipTags);
49
115
  }
50
116
  return protocol.parse(value, ...args);
51
117
  }
52
118
  }
119
+ /**
120
+ * Compile definitions and wrap them in a sealed catalog.
121
+ *
122
+ * @param definitions - Command definitions keyed by wire id.
123
+ * @param defaults - Shared envelope definition merged into every command.
124
+ * @param options - Mode field, error wording and diagnostic tags.
125
+ * @returns A sealed catalog ready for `manifest`, `parse` and handler binding.
126
+ * @throws TypeError From compilation for the first invalid definition.
127
+ */
53
128
  export function defineCommandCatalog(definitions, defaults = {}, options = {}) {
54
129
  const compiled = compileCommands(definitions, defaults);
55
130
  return new CommandCatalog(Object.entries(compiled), options);
@@ -1,6 +1,23 @@
1
+ /**
2
+ * Interaction Kit: bind every registered command to a local handler.
3
+ *
4
+ * Place in the package: part of the `interaction` Kit. The handler table is App code; this
5
+ * module checks it is exhaustive, rejects unknown keys and dispatches on the validated wire
6
+ * value rather than on any formatter output.
7
+ *
8
+ * Exports: `bindInteraction`, and the interaction category/descriptor/handler types.
9
+ */
1
10
  import type { InteractionHandlers } from '../../structs/kits/interaction.js';
2
11
  import type { InteractionProtocol } from './transfer.js';
3
- /** Bind every registered transfer command to a local handler. Models cannot add handlers. */
12
+ /**
13
+ * Bind every registered transfer command to a local handler. Models cannot add handlers.
14
+ *
15
+ * @param protocol - Object exposing the command manifest and a `receive` entry point.
16
+ * @param handlers - One handler per command id, bound to this handlers object.
17
+ * @returns A frozen `{ catalog, dispatch }`; `dispatch` selects by the validated command id.
18
+ * @throws A configured error when a handler is missing (including prototype members such as
19
+ * `constructor` that were never assigned) or when the table contains an unregistered id.
20
+ */
4
21
  export declare function bindInteraction<Value extends object, Parsed, Args extends unknown[], Id extends string, Context, Output>(protocol: {
5
22
  readonly commands: Pick<InteractionProtocol<Value, Parsed, Args, Id>['commands'], 'manifest'>;
6
23
  receive(value: Value, ...args: Args): {
@@ -17,5 +34,5 @@ export declare function bindInteraction<Value extends object, Parsed, Args exten
17
34
  }>[];
18
35
  dispatch(value: Value, context: Context, ...args: Args): Output;
19
36
  }>;
20
- export type { InteractionCategory, InteractionDescriptor, InteractionHandlers } from '../../structs/kits/interaction.js';
37
+ export type { InteractionCategory, InteractionDescriptor, InteractionHandlers, } from '../../structs/kits/interaction.js';
21
38
  export { INTERACTION_CATEGORIES } from '../../structs/kits/interaction.js';
@@ -1,22 +1,39 @@
1
1
  import { breakWhile } from '../../utils/rules.js';
2
- /** Bind every registered transfer command to a local handler. Models cannot add handlers. */
2
+ /**
3
+ * Bind every registered transfer command to a local handler. Models cannot add handlers.
4
+ *
5
+ * @param protocol - Object exposing the command manifest and a `receive` entry point.
6
+ * @param handlers - One handler per command id, bound to this handlers object.
7
+ * @returns A frozen `{ catalog, dispatch }`; `dispatch` selects by the validated command id.
8
+ * @throws A configured error when a handler is missing (including prototype members such as
9
+ * `constructor` that were never assigned) or when the table contains an unregistered id.
10
+ */
3
11
  export function bindInteraction(protocol, handlers) {
4
- const catalog = Object.freeze(protocol.commands.manifest().map(command => Object.freeze({
5
- id: command.id, category: command.category, description: command.description, terminal: command.terminal,
12
+ const catalog = Object.freeze(protocol.commands.manifest().map((command) => Object.freeze({
13
+ id: command.id,
14
+ category: command.category,
15
+ description: command.description,
16
+ terminal: command.terminal,
6
17
  modes: command.modes && Object.freeze([...command.modes]),
7
18
  })));
8
19
  const receive = protocol.receive.bind(protocol);
9
- const ids = new Set(catalog.map(command => command.id));
20
+ const ids = new Set(catalog.map((command) => command.id));
10
21
  breakWhile([
11
22
  {
12
- occur: () => catalog.some(command => typeof handlers[command.id] !== 'function' || (!Object.hasOwn(handlers, command.id) && (command.id === 'constructor' || handlers[command.id] === Reflect.get(Object.prototype, command.id)))),
13
- error: 'Missing interaction handler', tags: ['missing-handler'],
23
+ occur: () => catalog.some((command) => typeof handlers[command.id] !== 'function' ||
24
+ (!Object.hasOwn(handlers, command.id) &&
25
+ (command.id === 'constructor' ||
26
+ handlers[command.id] === Reflect.get(Object.prototype, command.id)))),
27
+ error: 'Missing interaction handler',
28
+ tags: ['missing-handler'],
29
+ },
30
+ {
31
+ occur: () => Object.keys(handlers).some((id) => !ids.has(id)),
32
+ error: 'Unregistered interaction handler',
33
+ tags: ['unknown-handler'],
14
34
  },
15
- { occur: () => Object.keys(handlers).some(id => !ids.has(id)), error: 'Unregistered interaction handler', tags: ['unknown-handler'] },
16
35
  ], ['agent-core', 'interaction-registration']);
17
- const registered = Object.freeze(Object.fromEntries(catalog.map(({ id }) => [id,
18
- handlers[id].bind(handlers),
19
- ])));
36
+ const registered = Object.freeze(Object.fromEntries(catalog.map(({ id }) => [id, handlers[id].bind(handlers)])));
20
37
  return Object.freeze({
21
38
  catalog,
22
39
  dispatch(value, context, ...args) {
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Interaction Kit entry: command protocols, their catalog and local handler binding.
3
+ *
4
+ * Place in the package: an optional App-side library for the payload family exchanged between
5
+ * a web or AI client and the App. Framing, transport and the actual command execution stay
6
+ * outside; this directory validates shapes, routes on a discriminator and binds handlers.
7
+ *
8
+ * Exports: everything from `./command.js`, `./commands.js`, `./transfer.js` and
9
+ * `./handlers.js`, plus `InteractionProtocol` re-exported as `Interaction`.
10
+ */
1
11
  export * from './command.js';
2
12
  export * from './commands.js';
3
13
  export * from './transfer.js';
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Interaction Kit entry: command protocols, their catalog and local handler binding.
3
+ *
4
+ * Place in the package: an optional App-side library for the payload family exchanged between
5
+ * a web or AI client and the App. Framing, transport and the actual command execution stay
6
+ * outside; this directory validates shapes, routes on a discriminator and binds handlers.
7
+ *
8
+ * Exports: everything from `./command.js`, `./commands.js`, `./transfer.js` and
9
+ * `./handlers.js`, plus `InteractionProtocol` re-exported as `Interaction`.
10
+ */
1
11
  export * from './command.js';
2
12
  export * from './commands.js';
3
13
  export * from './transfer.js';