@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,23 +1,42 @@
1
+ /**
2
+ * Agent catalog contract for the Intents Kit.
3
+ *
4
+ * Place in the package: an optional App-side projection that describes which intents, scopes and
5
+ * tools are available to one request. The ports read the App's real registries, so no parallel
6
+ * capability list exists; this module only declares what the catalog needs from them.
7
+ *
8
+ * Exports: `CatalogIntent`, `CatalogScope`, `CatalogTask`, `CatalogTool`, `DescribedTool`,
9
+ * `AgentCatalogPorts`.
10
+ */
11
+ /** Intent as the catalog sees it: an id plus its declared steps. */
1
12
  export interface CatalogIntent<Id extends string = string> {
2
13
  readonly id: Id;
3
14
  readonly steps: readonly string[];
4
15
  }
16
+ /** Scope as the catalog sees it: an id plus the tools it may use. */
5
17
  export interface CatalogScope {
6
18
  readonly id: string;
7
19
  readonly toolIds: readonly string[];
8
20
  }
21
+ /** The task currently accepted for the request, used to narrow the catalog. */
9
22
  export interface CatalogTask<Id extends string = string> {
10
23
  readonly intentId: Id;
24
+ /** Selected scope; `null` or `undefined` means a scope has not been chosen yet. */
11
25
  readonly scopeId?: string | null;
12
26
  }
27
+ /** Tool facts the catalog needs, independent of lifecycle details. */
13
28
  export interface CatalogTool<App> {
14
29
  readonly id: string;
30
+ /** Intent ids the tool serves, or `'all'` when it is always available. */
15
31
  readonly intentIds: 'all' | readonly string[];
32
+ /** Returns whether the tool may run for this App state; absent means always available. */
16
33
  available?(app: App): boolean;
34
+ /** Invocation step, when the tool participates in the step-based lifecycle. */
17
35
  readonly invocation?: {
18
36
  readonly step: string;
19
37
  };
20
38
  }
39
+ /** Model- or host-facing description of one tool. */
21
40
  export interface DescribedTool {
22
41
  readonly id: string;
23
42
  readonly kind: string;
@@ -26,16 +45,23 @@ export interface DescribedTool {
26
45
  readonly effect: string;
27
46
  readonly intentIds: readonly string[];
28
47
  }
48
+ /** Ports the catalog reads from the App's registries. */
29
49
  export interface AgentCatalogPorts<App, Id extends string, Intent extends CatalogIntent<Id>, Scope extends CatalogScope> {
50
+ /** All registered intent ids, before availability filtering. */
30
51
  intentIds(): readonly Id[];
52
+ /** Registered intents, optionally narrowed to `ids`. */
31
53
  intents(ids?: readonly Id[]): readonly Intent[];
54
+ /** Registered scopes for the given intent ids (all scopes when omitted). */
32
55
  scopes(ids?: readonly Id[]): readonly Scope[];
56
+ /** When not `false`, the catalog is narrowed to `currentTask`; defaults to restriction on. */
33
57
  readonly restrictToTask?: boolean;
58
+ /** Task accepted for this request, if any. */
34
59
  currentTask(app: App): CatalogTask<Id> | undefined;
35
60
  readonly tools: {
36
61
  values(): Iterable<CatalogTool<App>>;
37
62
  has(id: string): boolean;
38
63
  supportsIntent(id: Id, app: App): boolean;
64
+ /** Describes tools for an audience (for example `'model'`); must be synchronous. */
39
65
  describe(audience?: string, app?: App): readonly DescribedTool[];
40
66
  };
41
67
  }
@@ -1,41 +1,75 @@
1
+ /**
2
+ * Intent registry contract for the Intents Kit.
3
+ *
4
+ * Place in the package: an optional App-side catalog of model intents. An intent names its ordered
5
+ * steps and optional App-declared policies; the registry checks identity, allowed vocabulary,
6
+ * duplicate ids and sealing, while the meaning of each vocabulary value stays with the App.
7
+ *
8
+ * Exports: `IntentDefinition`, `IntentRegistryPolicy`, `IntentDescription`, `IntentId`,
9
+ * `RegisteredIntent`.
10
+ */
1
11
  import type { BreakReason } from '../../utils/rules.js';
2
12
  import type { RegistrationProjection } from '../../../utils/registration.js';
13
+ /** One declarable intent. */
3
14
  export interface IntentDefinition {
15
+ /** Unique intent id, matched against the policy's `idPattern` when configured. */
4
16
  id: string;
17
+ /** Non-blank model-facing description. */
5
18
  description: string;
19
+ /** Ordered step ids; non-empty, unique and, when `policy.steps` is set, drawn from it. */
6
20
  steps: readonly string[];
21
+ /** App-declared scope-mode name; validated against `policy.scopeModes` when that is set. */
7
22
  scopePolicy?: string;
23
+ /** App-declared target-mode name; validated against `policy.targetModes` when that is set. */
8
24
  targetPolicy?: string;
25
+ /** App-declared context tier; validated against `policy.contextTiers` when that is set. */
9
26
  contextTier?: string;
27
+ /** App-declared planning action; validated against `policy.actions` when that is set. */
10
28
  planIntent?: string;
29
+ /** Additional actions the intent may use; must be unique. */
11
30
  auxiliaryActions?: readonly string[];
31
+ /** App-declared handoff marker; validated against `policy.handoffValues` when that is set. */
12
32
  preparedHandoff?: unknown;
13
33
  }
34
+ /** Registration rules for one intent registry. */
14
35
  export interface IntentRegistryPolicy<Definition extends IntentDefinition> {
36
+ /** Pattern every intent id must match. */
15
37
  readonly idPattern?: RegExp;
38
+ /** Allowed `scopePolicy` values; `undefined` accepts any value. */
16
39
  readonly scopeModes?: readonly string[];
40
+ /** Allowed `targetPolicy` values; `undefined` accepts any value. */
17
41
  readonly targetModes?: readonly string[];
42
+ /** Allowed `contextTier` values; `undefined` accepts any value. */
18
43
  readonly contextTiers?: readonly string[];
44
+ /** Allowed `planIntent` values; `undefined` accepts any value. */
19
45
  readonly actions?: readonly string[];
46
+ /** Allowed step ids; `undefined` accepts any non-empty step. */
20
47
  readonly steps?: readonly string[];
48
+ /** Allowed `preparedHandoff` values; `undefined` accepts any value. */
21
49
  readonly handoffValues?: readonly unknown[];
50
+ /** Extra App assertion, called after the built-in checks; must return void synchronously. */
22
51
  readonly assertDefinition?: (definition: Definition) => void;
52
+ /** Diagnostic tags attached to registration rejections. */
23
53
  readonly tags?: readonly string[];
24
54
  readonly errors?: {
25
55
  readonly sealed?: BreakReason;
26
56
  readonly invalid?: BreakReason;
57
+ /** Builds the duplicate-id rejection; receives the intent id. */
27
58
  readonly duplicate?: (goal: string) => Error | string;
28
59
  };
29
60
  }
61
+ /** Registered intent with its steps widened to the definition's step literals. */
30
62
  export type IntentDescription<Definition extends IntentDefinition> = Omit<RegisteredIntent<Definition>, 'steps'> & {
31
63
  steps: Definition['steps'][number][];
32
64
  };
65
+ /** Union of the ids of a definition set, or `string` when it cannot be narrowed. */
33
66
  export type IntentId<Definition> = Definition extends {
34
67
  id: infer Id extends string;
35
68
  } ? Id : string;
36
69
  type RegisteredIntentLists<Definition extends IntentDefinition> = {
37
70
  readonly [Key in keyof Pick<Definition, Extract<keyof Definition, 'steps' | 'auxiliaryActions'>>]: Readonly<Definition[Key]>;
38
71
  };
72
+ /** Frozen registration view: list fields are frozen copies, helper methods are dropped. */
39
73
  export type RegisteredIntent<Definition extends IntentDefinition> = Readonly<Omit<RegistrationProjection<Definition, IntentDefinition>, 'steps' | 'auxiliaryActions'> & RegisteredIntentLists<Definition> & {
40
74
  id: Definition['id'];
41
75
  steps: Readonly<Definition['steps']>;
@@ -1,32 +1,63 @@
1
+ /**
2
+ * Scope registry contract for the Intents Kit.
3
+ *
4
+ * Place in the package: an optional App-side catalog of scope definitions. A scope binds an intent
5
+ * to the sources and tools it may use; the registry validates identity, aliases, required bindings
6
+ * and allowed categories, while resolution and business meaning stay with the App.
7
+ *
8
+ * Exports: `ScopeDefinition`, `ScopeRegistryPolicy`, `RegisteredScopeEvidence`, `RegisteredScope`,
9
+ * `ScopeDescription`.
10
+ */
1
11
  import type { EvidenceRequirement } from '../evidence.js';
2
12
  import type { BreakReason } from '../../utils/rules.js';
3
13
  import type { RegistrationData, RegistrationProjection } from '../../../utils/registration.js';
14
+ /** One declarable scope. Ids and aliases share one namespace and must be unique. */
4
15
  export interface ScopeDefinition {
16
+ /** Unique scope id, matched against the policy's `idPattern` when configured. */
5
17
  id: string;
18
+ /** Non-blank description. */
6
19
  description: string;
20
+ /** Scope category; validated against `policy.categories` when that is set. */
7
21
  category: string;
22
+ /** Intents this scope serves; required when the policy sets `requireIntents`. */
8
23
  intentIds?: readonly string[];
24
+ /** Referenced query scopes, resolved by the App. */
9
25
  queryScopeIds?: readonly string[];
26
+ /** Referenced knowledge topics, resolved by the App. */
10
27
  knowledgeTopicIds?: readonly string[];
28
+ /** Referenced tool ids; required when the policy sets `requireTools`. */
11
29
  toolIds?: readonly string[];
30
+ /** Alternate names accepted by lookup; must not collide with ids or other aliases. */
12
31
  aliases?: readonly string[];
32
+ /** App-declared context tier, passed through for the App's own policy. */
13
33
  contextTier?: string;
34
+ /** Evidence requirements that must be satisfied before this scope may answer. */
14
35
  evidence?: readonly EvidenceRequirement[];
15
36
  }
37
+ /** Registration rules for one scope registry. */
16
38
  export interface ScopeRegistryPolicy<Definition extends ScopeDefinition> {
39
+ /** Require at least one intent id per scope. */
17
40
  readonly requireIntents?: boolean;
41
+ /** Require at least one query scope or knowledge topic per scope. */
18
42
  readonly requireSources?: boolean;
43
+ /** Require at least one tool id per scope. */
19
44
  readonly requireTools?: boolean;
45
+ /** Pattern every id and alias must match. */
20
46
  readonly idPattern?: RegExp;
47
+ /** Allowed `category` values; `undefined` accepts any value. */
21
48
  readonly categories?: readonly string[];
49
+ /** Extra App assertion, called after the built-in checks; must return void synchronously. */
22
50
  readonly assertDefinition?: (definition: Definition) => void;
51
+ /** Replaces the default intent membership test; must return boolean synchronously. */
23
52
  readonly acceptsIntent?: (definition: Readonly<Definition>, goal: string) => boolean;
53
+ /** Diagnostic tags attached to registration rejections. */
24
54
  readonly tags?: readonly string[];
25
55
  readonly errors?: {
26
56
  readonly sealed?: BreakReason;
27
57
  readonly invalid?: BreakReason;
28
58
  };
29
59
  }
60
+ /** Registered evidence entry: public data only, frozen by the registry. */
30
61
  export type RegisteredScopeEvidence<Definition extends ScopeDefinition> = Readonly<RegistrationData<NonNullable<Definition['evidence']>[number]>>;
31
62
  type ScopeListKey = 'intentIds' | 'queryScopeIds' | 'knowledgeTopicIds' | 'toolIds' | 'aliases';
32
63
  type RegisteredScopeLists<Definition extends ScopeDefinition> = {
@@ -35,10 +66,14 @@ type RegisteredScopeLists<Definition extends ScopeDefinition> = {
35
66
  type RegisteredEvidenceList<Values extends readonly EvidenceRequirement[]> = {
36
67
  readonly [Index in keyof Values]: Readonly<RegistrationData<Values[Index]>>;
37
68
  };
38
- type ScopeEvidenceList<Definition extends ScopeDefinition> = [NonNullable<Definition['evidence']>] extends [never] ? readonly [] : NonNullable<Definition['evidence']> extends readonly EvidenceRequirement[] ? RegisteredEvidenceList<NonNullable<Definition['evidence']>> : readonly RegisteredScopeEvidence<Definition>[];
69
+ type ScopeEvidenceList<Definition extends ScopeDefinition> = [
70
+ NonNullable<Definition['evidence']>
71
+ ] extends [never] ? readonly [] : NonNullable<Definition['evidence']> extends readonly EvidenceRequirement[] ? RegisteredEvidenceList<NonNullable<Definition['evidence']>> : readonly RegisteredScopeEvidence<Definition>[];
72
+ /** Frozen registration view: every list is a frozen copy, evidence entries are projected. */
39
73
  export type RegisteredScope<Definition extends ScopeDefinition> = Readonly<Omit<RegistrationProjection<Definition, ScopeDefinition>, ScopeListKey | 'evidence'> & RegisteredScopeLists<Definition> & {
40
74
  evidence: ScopeEvidenceList<Definition>;
41
75
  }>;
76
+ /** Plain description with mutable arrays, for documentation and model-facing catalogs. */
42
77
  export type ScopeDescription<Definition extends ScopeDefinition> = Omit<RegisteredScope<Definition>, 'intentIds' | 'queryScopeIds' | 'knowledgeTopicIds' | 'toolIds' | 'aliases' | 'evidence'> & {
43
78
  intentIds: string[];
44
79
  queryScopeIds: string[];
@@ -1,85 +1,148 @@
1
+ /**
2
+ * Interaction protocol contract: the validated payload family exchanged with a client.
3
+ *
4
+ * Place in the package: an optional App-side library for command-shaped values. A declaration
5
+ * produces both the model-visible schema and the runtime input schema from one field list, so
6
+ * validation, routing and documentation cannot drift. HTTP/SSE framing and command execution stay
7
+ * in separate ports; nothing here executes a registered tool.
8
+ *
9
+ * Exports: `ProtocolField`, `InteractionCategory`, `INTERACTION_CATEGORIES`,
10
+ * `InteractionDescriptor`, `InteractionHandlers`, `ProtocolReason`, `ProtocolPredicate`,
11
+ * `ProtocolCheck`, `CommandDefinition`, `Command`, `CommandCatalogOptions`,
12
+ * `InteractionProtocolDefinition`, `ProtocolShape`, `RegisteredProtocol`.
13
+ */
1
14
  /** Field presence, schema and ownership are declared together; schemas describe model input. */
2
15
  export interface ProtocolField {
16
+ /** Property schema; missing means the provider accepts any value. */
3
17
  readonly jsonSchema?: Readonly<Record<string, unknown>>;
18
+ /** Required on input; such a field may be optional for the model. */
4
19
  readonly required?: boolean;
20
+ /** Required from the model; such a field may be optional on input. */
5
21
  readonly modelRequired?: boolean;
22
+ /** Written by the program, never supplied by the model. */
6
23
  readonly owned?: boolean;
7
24
  }
8
25
  /** Interaction purpose, never an authorization level or an assertion of execution success. */
9
26
  export type InteractionCategory = 'query' | 'action' | 'presentation' | 'input' | 'receipt';
27
+ /** Frozen list of accepted categories, used for validation and enumeration. */
10
28
  export declare const INTERACTION_CATEGORIES: readonly InteractionCategory[];
29
+ /** Catalog metadata for one command, independent of its field shape. */
11
30
  export interface InteractionDescriptor {
12
31
  readonly id: string;
32
+ /** Declared purpose; validated against the frozen category list. */
13
33
  readonly category?: InteractionCategory;
14
34
  readonly description?: string;
35
+ /** Marks a command that ends the interaction. */
15
36
  readonly terminal?: boolean;
37
+ /** App-declared modes in which the command is available. */
16
38
  readonly modes?: readonly string[];
17
39
  }
40
+ /** Handler map keyed by command id; each handler receives the parsed value and App context. */
18
41
  export type InteractionHandlers<Id extends string, Value, Context, Output> = Readonly<Record<Id, (value: Value, context: Context) => Output>>;
42
+ /** Lazy rejection wording: a fixed message, a pre-built error, or a factory bound to the value. */
19
43
  export type ProtocolReason<Value, Args extends unknown[]> = Error | string | ((value: Value, ...args: Args) => Error | string);
44
+ /** Predicate evaluated during validation; any truthy result counts as a failure. */
20
45
  export type ProtocolPredicate<Value, Args extends unknown[]> = (value: Value, ...args: Args) => unknown;
46
+ /** One declarative rejection rule. */
21
47
  export interface ProtocolCheck<Value, Args extends unknown[]> {
48
+ /** Runs the check only when it returns true; must be synchronous. */
22
49
  readonly when?: (value: Value, ...args: Args) => boolean;
50
+ /** Failing predicate or ordered OR-list; evaluation stops at the first failure. */
23
51
  readonly occur: ProtocolPredicate<Value, Args> | readonly ProtocolPredicate<Value, Args>[];
52
+ /** Rejection wording; omitted means a default `TypeError`. */
24
53
  readonly error?: ProtocolReason<Value, Args>;
54
+ /** Diagnostic tags attached to the rejection. */
25
55
  readonly tags?: readonly string[];
26
56
  }
57
+ /** Declarative command shape before compilation. */
27
58
  export interface CommandDefinition<Value extends object, Result = Value, Args extends unknown[] = []> {
59
+ /** Declared purpose; validated against the frozen category list. */
28
60
  readonly category?: InteractionCategory;
61
+ /** Protocol version, used to reject incompatible registrations. */
29
62
  readonly version?: number;
30
63
  readonly description?: string;
64
+ /** Marks a command that ends the interaction. */
31
65
  readonly terminal?: boolean;
66
+ /** Constant field identifying the command; its value is forced to the command id. */
32
67
  readonly discriminator?: {
33
68
  readonly field: string;
34
69
  readonly value: string;
35
70
  };
71
+ /** Field declarations by name, or an ordered list of field names. */
36
72
  readonly fields: Readonly<Record<string, ProtocolField>> | readonly string[];
73
+ /** Fields the program writes; may name fields not declared in `fields`. */
37
74
  readonly ownedFields?: readonly string[];
75
+ /** Whether fields outside the declaration are rejected; defaults to the compiler policy. */
38
76
  readonly additionalProperties?: boolean;
39
77
  /** 'defined' rejects an explicitly undefined optional property; 'own' preserves its presence. */
40
78
  readonly optionalPresence?: 'own' | 'defined';
79
+ /** App-declared modes in which the command is available. */
41
80
  readonly modes?: readonly string[];
81
+ /** Rejection wording for the command as a whole. */
42
82
  readonly error?: ProtocolReason<Value, Args>;
83
+ /** Diagnostic tags attached to rejections from this command. */
43
84
  readonly tags?: readonly string[];
85
+ /** Declarative rejection rules, evaluated in order after the structural checks. */
44
86
  readonly checks?: readonly ProtocolCheck<Value, Args>[];
45
87
  /** Domain checks/bindings only; invoked after structural and declarative checks. */
46
88
  readonly refine?: (value: Value, ...args: Args) => void;
89
+ /** Formats the validated value into the command result. */
47
90
  readonly format?: (value: Value, ...args: Args) => Result;
48
91
  }
92
+ /** Compiled command. */
49
93
  export interface Command<Value extends object, Result = Value, Args extends unknown[] = []> {
50
94
  readonly category?: InteractionCategory;
51
95
  readonly version?: number;
52
96
  readonly description?: string;
53
97
  readonly terminal?: boolean;
98
+ /** Per-field schemas, including the forced discriminator field. */
54
99
  readonly fieldSchemas: Record<string, unknown>;
100
+ /** Schema for model output; only `modelRequired` fields are required here. */
55
101
  readonly modelJsonSchema: Record<string, unknown>;
102
+ /** Schema for runtime input; every `required` field is required here. */
56
103
  readonly inputJsonSchema: Record<string, unknown>;
57
104
  readonly modes?: readonly string[];
105
+ /** Field names the program owns; the model must not supply them. */
58
106
  readonly ownedFields: readonly string[];
107
+ /** Selector values carried by `value`, used to resolve the command before parsing. */
59
108
  keys(value: Record<string, unknown>): string[];
109
+ /** Validates without formatting; throws on the first failed check. */
60
110
  assert(value: Value, ...args: Args): void;
111
+ /** Validates and returns the formatted result. */
61
112
  parse(value: Value, ...args: Args): Result;
62
113
  }
114
+ /** Envelope-level options for a command catalog. */
63
115
  export interface CommandCatalogOptions {
116
+ /** Field carrying the mode selector, when modes are used. */
64
117
  readonly modeField?: string;
118
+ /** Rejection wording for an unknown command selector. */
65
119
  readonly unknownError?: Error | string;
120
+ /** Rejection wording for a command used outside its declared modes. */
66
121
  readonly modeError?: Error | string;
122
+ /** Rejection wording for a model-supplied owned field. */
67
123
  readonly ownershipError?: Error | string;
124
+ /** Diagnostic tags attached to every rejection from this catalog. */
68
125
  readonly tags?: readonly string[];
69
126
  }
70
127
  /** Transfer envelope plus its registered command family; no change to HTTP or SSE framing. */
71
128
  export type InteractionProtocolDefinition<Value extends object, Result = Value, Args extends unknown[] = [], Id extends string = string> = Omit<Partial<CommandDefinition<Value, Result, Args>>, 'discriminator' | 'modes' | 'ownedFields'> & CommandCatalogOptions & {
129
+ /** Field carrying the command id; also the canonical key in normalized output. */
72
130
  readonly commandField: string;
73
131
  /** Accepted only on input. Schema and normalized output always use commandField. */
74
132
  readonly commandAliases?: readonly string[];
133
+ /** Rejection wording when a payload selects no command. */
75
134
  readonly selectionError?: ProtocolReason<Value, Args>;
76
135
  readonly commands: Readonly<Record<Id, CommandDefinition<Value, Result, Args>>>;
77
136
  };
78
137
  /** Custom protocols may derive dynamic keys without supplying a compiled schema. */
79
138
  export interface ProtocolShape {
139
+ /** Optional schema for model output. */
80
140
  readonly modelJsonSchema?: Record<string, unknown>;
141
+ /** Optional schema for runtime input. */
81
142
  readonly inputJsonSchema?: Record<string, unknown>;
143
+ /** Optional per-field schemas. */
82
144
  readonly fieldSchemas?: Record<string, unknown>;
145
+ /** Selector values carried by `value`. */
83
146
  keys(value: Record<string, unknown>): string[];
84
147
  }
85
148
  /** Runtime extension contract; hosts retain their own version values and validation context. */
@@ -87,5 +150,6 @@ export interface RegisteredProtocol<Args extends unknown[] = []> extends Protoco
87
150
  readonly version?: number;
88
151
  readonly description?: string;
89
152
  readonly terminal?: boolean;
153
+ /** Structural validation for an already resolved command value. */
90
154
  assert?(value: Record<string, unknown>, ...args: Args): void;
91
155
  }
@@ -1 +1,8 @@
1
- export const INTERACTION_CATEGORIES = Object.freeze(['query', 'action', 'presentation', 'input', 'receipt']);
1
+ /** Frozen list of accepted categories, used for validation and enumeration. */
2
+ export const INTERACTION_CATEGORIES = Object.freeze([
3
+ 'query',
4
+ 'action',
5
+ 'presentation',
6
+ 'input',
7
+ 'receipt',
8
+ ]);
@@ -1,51 +1,93 @@
1
+ /**
2
+ * Knowledge publication contract: staged document revisions with explicit provenance.
3
+ *
4
+ * Place in the package: an optional App-side workflow for proposing, publishing or rejecting a
5
+ * knowledge document. Candidates are validated against the same catalog compiler as published
6
+ * documents and expire unless published; the store performs one atomic revision swap.
7
+ *
8
+ * Exports: `knowledgePublicationOperations`, `KnowledgeSourceReference`, `KnowledgeCandidate`,
9
+ * `KnowledgePublicationRecord`, `KnowledgePublicationStore`, `KnowledgePublicationOptions`,
10
+ * `KnowledgePublication`.
11
+ */
1
12
  import type { KnowledgeDocument, KnowledgeRead } from './knowledge.js';
2
13
  import type { MaybePromise, OperationContext } from '../common.js';
14
+ /** Operation names accepted by the publication `authorize` hook. */
3
15
  export declare const knowledgePublicationOperations: readonly ["propose", "publish", "reject"];
16
+ /** Citation of the material a candidate was derived from. */
4
17
  export interface KnowledgeSourceReference {
18
+ /** Source identity, for example a stored document or manual id. */
5
19
  readonly id: string;
20
+ /** Revision of that source that was read. */
6
21
  readonly revision: string;
22
+ /** Optional expiry instant; a stale source invalidates the candidate. */
7
23
  readonly expiresAtMs?: number;
8
24
  }
25
+ /** A proposed document awaiting publish or reject. */
9
26
  export interface KnowledgeCandidate {
27
+ /** Candidate id, generated by the Kit. */
10
28
  readonly id: string;
29
+ /** Record revision the candidate was proposed against, used for stale-proposal detection. */
11
30
  readonly baseRevision: number;
31
+ /** Complete document that would replace the published revision with the same id. */
12
32
  readonly document: KnowledgeDocument;
33
+ /** Provenance the candidate depends on; verified by the App, never trusted from the model. */
13
34
  readonly sources: readonly KnowledgeSourceReference[];
14
35
  readonly createdAtMs: number;
36
+ /** Instant after which the candidate is discarded. */
15
37
  readonly expiresAtMs: number;
16
38
  }
39
+ /** Stored publication state: one published revision plus pending candidates. */
17
40
  export interface KnowledgePublicationRecord {
41
+ /** Monotonic record revision; every accepted mutation increments it. */
18
42
  readonly revision: number;
43
+ /** Revision number of the currently published document set. */
19
44
  readonly publishedRevision: number;
45
+ /** Published documents, in catalog order. */
20
46
  readonly documents: readonly KnowledgeDocument[];
47
+ /** Pending candidates; expired entries are removed before use. */
21
48
  readonly candidates: readonly KnowledgeCandidate[];
22
49
  }
50
+ /** Single-writer store for the publication record. */
23
51
  export interface KnowledgePublicationStore {
52
+ /** Returns the current record; it must always be readable. */
24
53
  load(): Promise<KnowledgePublicationRecord>;
54
+ /** Atomically replaces the record when the stored revision still equals `expectedRevision`. */
25
55
  compareAndSwap(expectedRevision: number, next: KnowledgePublicationRecord): Promise<boolean>;
26
56
  }
57
+ /** App-owned guards, store and limits for a publication workflow. */
27
58
  export interface KnowledgePublicationOptions<App> {
28
59
  readonly store: KnowledgePublicationStore;
60
+ /** Reads that must succeed against every compiled document set, proving sections still exist. */
29
61
  readonly requiredReads?: readonly KnowledgeRead[];
62
+ /** Per-read character budget applied by the catalog compiler. */
30
63
  readonly maxReadChars?: number;
64
+ /** Maximum pending candidates retained; defaults to 32 and must be a positive integer. */
31
65
  readonly maxCandidates?: number;
66
+ /** Candidate retention window; defaults to seven days. */
32
67
  readonly candidateRetentionMs?: number;
68
+ /** Clock override for timestamps and expiry; defaults to `Date.now`. */
33
69
  readonly now?: () => number;
34
- authorize(operation: typeof knowledgePublicationOperations[number], context: OperationContext<App>): MaybePromise<void>;
70
+ /** Guards one operation before any read or write. */
71
+ authorize(operation: (typeof knowledgePublicationOperations)[number], context: OperationContext<App>): MaybePromise<void>;
35
72
  /** Validate real provenance/revisions/visibility. A model's source list is not a grant. */
36
73
  verifySources(sources: readonly KnowledgeSourceReference[], context: OperationContext<App>): MaybePromise<void>;
37
74
  }
75
+ /** Compiled publication workflow. */
38
76
  export interface KnowledgePublication<App> {
77
+ /** Returns the current record, with expired candidates already pruned. */
39
78
  read(context: OperationContext<App>): Promise<KnowledgePublicationRecord>;
79
+ /** Adds a candidate based on `revision`; fails when the record moved on. */
40
80
  propose(request: {
41
81
  revision: number;
42
82
  document: KnowledgeDocument;
43
83
  sources: readonly KnowledgeSourceReference[];
44
84
  }, context: OperationContext<App>): Promise<KnowledgePublicationRecord>;
85
+ /** Publishes one candidate and removes it from the pending list. */
45
86
  publish(request: {
46
87
  revision: number;
47
88
  candidateId: string;
48
89
  }, context: OperationContext<App>): Promise<KnowledgePublicationRecord>;
90
+ /** Discards one candidate without touching the published documents. */
49
91
  reject(request: {
50
92
  revision: number;
51
93
  candidateId: string;
@@ -1 +1,2 @@
1
+ /** Operation names accepted by the publication `authorize` hook. */
1
2
  export const knowledgePublicationOperations = ['propose', 'publish', 'reject'];
@@ -1,37 +1,74 @@
1
+ /**
2
+ * Knowledge document contract for the Knowledge Kit.
3
+ *
4
+ * Place in the package: an optional App-side catalog of structured text. Documents are nested
5
+ * sections of strings; a read selects the whole document or explicit sections and returns an
6
+ * immutable snapshot with content, revision and identity for citation.
7
+ *
8
+ * Exports: `KnowledgeSection`, `KnowledgePart`, `KnowledgeDocument`, `SectionSelection`,
9
+ * `KnowledgeRead`, `KnowledgeSnapshot`, `KnowledgeCatalogOptions`, `KnowledgeCatalog`.
10
+ */
1
11
  import type { ReadonlyCatalog } from '../common.js';
12
+ /** A named section that may contain text and further sections. */
2
13
  export interface KnowledgeSection {
14
+ /** Section id, unique within its document; used by section selections. */
3
15
  readonly id: string;
16
+ /** Section content in order; nested sections are addressed independently. */
4
17
  readonly parts: readonly KnowledgePart[];
5
18
  }
19
+ /** Document content: a text leaf or a nested section. */
6
20
  export type KnowledgePart = string | KnowledgeSection;
21
+ /** One versioned document as supplied by the App. */
7
22
  export interface KnowledgeDocument {
23
+ /** Stable document id; duplicate ids are rejected by the catalog. */
8
24
  readonly id: string;
25
+ /** Revision label recorded in every snapshot so a citation names the exact content. */
9
26
  readonly revision: string;
27
+ /** Locale of the content, when the App maintains translations. */
10
28
  readonly locale?: string;
29
+ /** Ordered content. */
11
30
  readonly parts: readonly KnowledgePart[];
12
31
  }
13
- export type SectionSelection = {
32
+ /** Which part of a document a read returns. */
33
+ export type SectionSelection =
34
+ /** The whole document. */
35
+ {
14
36
  readonly mode: 'document';
15
- } | {
37
+ }
38
+ /** `self` returns only the named sections; `subtree` also includes their descendants. */
39
+ | {
16
40
  readonly mode: 'self' | 'subtree';
17
41
  readonly sectionIds: readonly string[];
18
42
  };
43
+ /** A request for one document selection. */
19
44
  export interface KnowledgeRead {
20
45
  readonly documentId: string;
46
+ /** Must reference existing sections; an invalid selection throws. */
21
47
  readonly selection: SectionSelection;
22
48
  }
49
+ /** Materialized read result. */
23
50
  export interface KnowledgeSnapshot extends KnowledgeRead {
51
+ /** Deterministic identity derived from document, revision and selection. */
24
52
  readonly id: string;
53
+ /** Revision of the document that produced this content. */
25
54
  readonly revision: string;
26
55
  readonly locale?: string;
56
+ /** Rendered text, trimmed; sections are separated by blank lines. */
27
57
  readonly content: string;
28
58
  }
59
+ /** Catalog construction options. */
29
60
  export interface KnowledgeCatalogOptions {
61
+ /** Maximum characters per read; exceeding it throws a `RangeError`. */
30
62
  readonly maxChars?: number;
63
+ /** Observer invoked with every produced snapshot. */
31
64
  readonly observe?: (snapshot: KnowledgeSnapshot) => void | Promise<void>;
32
65
  }
66
+ /** Compiled catalog of knowledge documents. */
33
67
  export interface KnowledgeCatalog extends ReadonlyCatalog<KnowledgeDocument> {
68
+ /** Section ids of one document, in declaration order; throws for an unknown document. */
34
69
  sectionIds(documentId: string): readonly string[];
70
+ /** Validates a read without producing content; throws when the selection is invalid. */
35
71
  assertSelection(read: KnowledgeRead): void;
72
+ /** Produces a snapshot for the read; throws for unknown documents, sections or budget excess. */
36
73
  read(read: KnowledgeRead): KnowledgeSnapshot;
37
74
  }
@@ -1,8 +1,23 @@
1
+ /**
2
+ * Normalization contract for the Normalization Kit.
3
+ *
4
+ * Place in the package: an optional App-side helper that cleans model or transport input before it
5
+ * reaches business logic. Steps are ordered, synchronous value-to-value transformations; the Kit
6
+ * never mutates the caller's arrays.
7
+ *
8
+ * Exports: `NormalizationStep`, `NormalizationOptions`.
9
+ */
10
+ /** One ordered transformation. */
1
11
  export interface NormalizationStep<Value, Context> {
12
+ /** Unique, non-blank step id used in errors. */
2
13
  readonly id: string;
14
+ /** Skips the step when it returns false; must be synchronous boolean. */
3
15
  readonly when?: (value: Value, context: Context) => boolean;
16
+ /** Returns the next value; receives the output of the previous step. Must be synchronous. */
4
17
  readonly normalize: (value: Value, context: Context) => Value;
5
18
  }
19
+ /** Pipeline options. */
6
20
  export interface NormalizationOptions<Value, Context> {
21
+ /** Stops the walk after the step that first returns true; later steps then do not run. */
7
22
  readonly isComplete?: (value: Value, context: Context) => boolean;
8
23
  }
@@ -1,22 +1,46 @@
1
+ /**
2
+ * Policy and recovery contract for the Policies Kit.
3
+ *
4
+ * Place in the package: an optional App-side library for policy and recovery tables. Predicates,
5
+ * recovery handlers, kinds and descriptions are App configuration; the Kit owns registration
6
+ * checks, evaluation order and outcome validation.
7
+ *
8
+ * Exports: `PolicyDefinition`, `PolicyAssessment`, `RecoveryResult`, `RecoveryDefinition`.
9
+ */
10
+ /** One declarative policy. */
1
11
  export interface PolicyDefinition<Input, Kind extends string = string> {
12
+ /** Unique policy id; also reported as a reason when the policy matches. */
2
13
  readonly id: string;
14
+ /** Human-readable explanation; must not be blank. */
3
15
  readonly description: string;
16
+ /** Policy family used to deduplicate reported kinds. */
4
17
  readonly kind: Kind;
18
+ /** Returns whether the policy applies; must be synchronous boolean. */
5
19
  when(input: Input): boolean;
6
20
  }
21
+ /** Result of assessing every registered policy against one input. */
7
22
  export interface PolicyAssessment<Kind extends string = string> {
23
+ /** True when at least one policy matched. */
8
24
  readonly required: boolean;
25
+ /** Ids of the matched policies, in registration order. */
9
26
  readonly reasons: readonly string[];
27
+ /** Distinct kinds of the matched policies, in first-match order. */
10
28
  readonly kinds: readonly Kind[];
11
29
  }
12
- export type RecoveryResult<Value> = {
30
+ /** Outcome of one recovery handler, or of the whole chain. */
31
+ export type RecoveryResult<Value> =
32
+ /** The handler declined; the chain continues with the next declaration. */
33
+ {
13
34
  readonly handled: false;
14
35
  } | {
15
36
  readonly handled: true;
16
37
  readonly value: Value;
17
38
  };
39
+ /** One recovery handler in an ordered chain. */
18
40
  export interface RecoveryDefinition<Input, Result> {
41
+ /** Unique handler id. */
19
42
  readonly id: string;
20
43
  readonly description: string;
44
+ /** Attempts recovery; must be synchronous and the first handled result wins. */
21
45
  tryRecover(input: Input): RecoveryResult<Result>;
22
46
  }