@jangts/agent-core 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (527) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +59 -0
  3. package/development/docs/api/reference.md +1907 -1874
  4. package/development/docs/api/support.md +27 -0
  5. package/development/docs/assets/agent-core-icon.png +0 -0
  6. package/development/docs/assets/agent-core-logo.png +0 -0
  7. package/development/docs/assets/character-agent-core.png +0 -0
  8. package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
  9. package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
  10. package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
  11. package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
  12. package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
  13. package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
  14. package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
  15. package/development/skills/agent-core-app/templates/catalog.json +36 -22
  16. package/dist/cjs/capabilities/index.js +13 -0
  17. package/dist/cjs/capabilities/invocation.js +80 -10
  18. package/dist/cjs/capabilities/model.js +126 -13
  19. package/dist/cjs/capabilities/tool-runtime.js +64 -12
  20. package/dist/cjs/capabilities/tools.js +266 -31
  21. package/dist/cjs/context/assembly.js +46 -5
  22. package/dist/cjs/context/audit.js +31 -6
  23. package/dist/cjs/context/fragments.js +54 -11
  24. package/dist/cjs/context/index.js +12 -0
  25. package/dist/cjs/context/journal.js +84 -7
  26. package/dist/cjs/context/plan.js +30 -2
  27. package/dist/cjs/diagnostics/catalog.js +11 -3
  28. package/dist/cjs/diagnostics/index.js +149 -29
  29. package/dist/cjs/diagnostics/sub-flow.js +240 -40
  30. package/dist/cjs/errors.js +99 -17
  31. package/dist/cjs/execution/branch.js +20 -4
  32. package/dist/cjs/execution/engine.js +470 -56
  33. package/dist/cjs/execution/events.js +136 -18
  34. package/dist/cjs/execution/index.js +7 -0
  35. package/dist/cjs/execution/reporting.js +75 -6
  36. package/dist/cjs/execution/state.js +161 -22
  37. package/dist/cjs/execution/workflow.js +224 -32
  38. package/dist/cjs/index.js +18 -0
  39. package/dist/cjs/kits/aggregation.js +45 -3
  40. package/dist/cjs/kits/answering/batch.js +23 -4
  41. package/dist/cjs/kits/answering/check-result.js +31 -8
  42. package/dist/cjs/kits/answering/checks.js +24 -3
  43. package/dist/cjs/kits/answering/flow.js +192 -36
  44. package/dist/cjs/kits/answering/index.js +19 -1
  45. package/dist/cjs/kits/answering/tasks.js +88 -13
  46. package/dist/cjs/kits/artifacts.js +36 -4
  47. package/dist/cjs/kits/candidates.js +47 -5
  48. package/dist/cjs/kits/delivery.js +40 -5
  49. package/dist/cjs/kits/durable.js +155 -31
  50. package/dist/cjs/kits/evidence.js +66 -15
  51. package/dist/cjs/kits/family.js +152 -22
  52. package/dist/cjs/kits/index.js +12 -1
  53. package/dist/cjs/kits/inference.js +104 -16
  54. package/dist/cjs/kits/intents/catalog.js +67 -16
  55. package/dist/cjs/kits/intents/index.js +11 -0
  56. package/dist/cjs/kits/intents/registry.js +188 -43
  57. package/dist/cjs/kits/intents/scopes.js +215 -46
  58. package/dist/cjs/kits/interaction/command.js +140 -36
  59. package/dist/cjs/kits/interaction/commands.js +86 -11
  60. package/dist/cjs/kits/interaction/handlers.js +27 -10
  61. package/dist/cjs/kits/interaction/index.js +10 -0
  62. package/dist/cjs/kits/interaction/transfer.js +80 -14
  63. package/dist/cjs/kits/knowledge/catalog.js +62 -11
  64. package/dist/cjs/kits/knowledge/index.js +16 -1
  65. package/dist/cjs/kits/knowledge/publication.js +99 -23
  66. package/dist/cjs/kits/knowledge/sections.js +33 -4
  67. package/dist/cjs/kits/normalization.js +51 -7
  68. package/dist/cjs/kits/policies.js +79 -15
  69. package/dist/cjs/kits/presentation/events.js +54 -10
  70. package/dist/cjs/kits/presentation/index.js +24 -1
  71. package/dist/cjs/kits/presentation/outputs.js +176 -38
  72. package/dist/cjs/kits/presentation/templates.js +33 -5
  73. package/dist/cjs/kits/presentation/variants.js +31 -2
  74. package/dist/cjs/kits/projection.js +63 -8
  75. package/dist/cjs/kits/rank-fusion.js +27 -4
  76. package/dist/cjs/kits/reflection-log-source.js +89 -16
  77. package/dist/cjs/kits/reflection.js +234 -60
  78. package/dist/cjs/kits/retrieval.js +98 -18
  79. package/dist/cjs/kits/search.js +180 -27
  80. package/dist/cjs/kits/text-skills.js +104 -19
  81. package/dist/cjs/kits/tools.js +415 -74
  82. package/dist/cjs/kits/vector-search.js +50 -16
  83. package/dist/cjs/mock/node.js +7 -1
  84. package/dist/cjs/mock/web.js +7 -1
  85. package/dist/cjs/mock.js +7 -1
  86. package/dist/cjs/model/binding.js +68 -17
  87. package/dist/cjs/model/call-budget.js +45 -4
  88. package/dist/cjs/model/decision-retry.js +19 -1
  89. package/dist/cjs/model/defaults.js +27 -4
  90. package/dist/cjs/model/index.js +7 -0
  91. package/dist/cjs/model/interactions/arguments.js +36 -1
  92. package/dist/cjs/model/interactions/json-object.js +48 -12
  93. package/dist/cjs/model/interactions/native-functions.js +52 -10
  94. package/dist/cjs/model/message-diagnostics.js +17 -4
  95. package/dist/cjs/model/options.js +9 -1
  96. package/dist/cjs/model/preparation.js +86 -12
  97. package/dist/cjs/model/runner.js +413 -79
  98. package/dist/cjs/model/selection-transport.js +48 -8
  99. package/dist/cjs/model/settings.js +67 -13
  100. package/dist/cjs/model/token-budget.js +69 -11
  101. package/dist/cjs/model/transports.js +59 -6
  102. package/dist/cjs/structs/common.js +11 -0
  103. package/dist/cjs/structs/debug.js +34 -5
  104. package/dist/cjs/structs/errors.js +26 -1
  105. package/dist/cjs/structs/index.js +11 -1
  106. package/dist/cjs/structs/kits/durable.js +7 -0
  107. package/dist/cjs/structs/kits/family.js +1 -0
  108. package/dist/cjs/structs/kits/interaction.js +8 -1
  109. package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
  110. package/dist/cjs/structs/kits/reflection.js +18 -3
  111. package/dist/cjs/structs/model/chat-provider.js +6 -0
  112. package/dist/cjs/structs/support/model/completion.js +2 -0
  113. package/dist/cjs/structs/support/model/messages.js +2 -0
  114. package/dist/cjs/support/capabilities.js +43 -6
  115. package/dist/cjs/support/context/assembly.js +88 -16
  116. package/dist/cjs/support/context/compression.js +48 -6
  117. package/dist/cjs/support/context/fragments.js +6 -0
  118. package/dist/cjs/support/context/history.js +36 -1
  119. package/dist/cjs/support/context/index.js +11 -0
  120. package/dist/cjs/support/context/nodes.js +164 -35
  121. package/dist/cjs/support/context/processing.js +319 -61
  122. package/dist/cjs/support/context/selection-policy.js +98 -21
  123. package/dist/cjs/support/context/selection.js +61 -10
  124. package/dist/cjs/support/context/snapshot.js +29 -7
  125. package/dist/cjs/support/context/strategies.js +120 -28
  126. package/dist/cjs/support/index.js +9 -1
  127. package/dist/cjs/support/model/capabilities.js +20 -1
  128. package/dist/cjs/support/model/chat-completions.js +92 -20
  129. package/dist/cjs/support/model/children.js +34 -6
  130. package/dist/cjs/support/model/compatible-provider.js +189 -59
  131. package/dist/cjs/support/model/completion/calls.js +61 -0
  132. package/dist/cjs/support/model/completion/default.js +32 -0
  133. package/dist/cjs/support/model/completion/index.js +28 -0
  134. package/dist/cjs/support/model/completion/session.js +102 -0
  135. package/dist/cjs/support/model/index.js +12 -0
  136. package/dist/cjs/support/model/interactions/index.js +12 -1
  137. package/dist/cjs/support/model/interactions/json-object.js +6 -0
  138. package/dist/cjs/support/model/interactions/native-functions.js +6 -0
  139. package/dist/cjs/support/model/observer.js +32 -6
  140. package/dist/cjs/support/model/preview-rules.js +66 -16
  141. package/dist/cjs/support/model/reply-preview.js +77 -17
  142. package/dist/cjs/support/model/stage-transport.js +33 -7
  143. package/dist/cjs/support/model/strategies.js +75 -14
  144. package/dist/cjs/support/model/transports.js +53 -11
  145. package/dist/cjs/support/registration.js +49 -7
  146. package/dist/cjs/support/schema.js +46 -4
  147. package/dist/cjs/support/stream-events.js +60 -8
  148. package/dist/cjs/support/tool-runtime.js +6 -0
  149. package/dist/cjs/support/tools.js +79 -10
  150. package/dist/cjs/support/transport/index.js +7 -0
  151. package/dist/cjs/support/transport/json.js +28 -4
  152. package/dist/cjs/support/transport/sse.js +25 -2
  153. package/dist/cjs/utils/break-observer.js +20 -2
  154. package/dist/cjs/utils/cancellation.js +77 -9
  155. package/dist/cjs/utils/catalog.js +19 -4
  156. package/dist/cjs/utils/debug.js +14 -2
  157. package/dist/cjs/utils/index.js +8 -0
  158. package/dist/cjs/utils/interaction-definition.js +26 -6
  159. package/dist/cjs/utils/invocation.js +42 -4
  160. package/dist/cjs/utils/model-protocol.js +20 -1
  161. package/dist/cjs/utils/object.js +16 -0
  162. package/dist/cjs/utils/observer.js +22 -2
  163. package/dist/cjs/utils/protocol-registry.js +47 -4
  164. package/dist/cjs/utils/query-key.js +21 -2
  165. package/dist/cjs/utils/registration.js +18 -2
  166. package/dist/cjs/utils/rules.js +39 -11
  167. package/dist/cjs/utils/schema-adapter.js +25 -2
  168. package/dist/cjs/utils/synchronous.js +64 -7
  169. package/dist/cjs/utils/text.js +15 -1
  170. package/dist/esm/capabilities/index.d.ts +13 -0
  171. package/dist/esm/capabilities/index.js +13 -0
  172. package/dist/esm/capabilities/invocation.d.ts +16 -2
  173. package/dist/esm/capabilities/invocation.js +80 -10
  174. package/dist/esm/capabilities/model.d.ts +68 -1
  175. package/dist/esm/capabilities/model.js +126 -13
  176. package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
  177. package/dist/esm/capabilities/tool-runtime.js +64 -12
  178. package/dist/esm/capabilities/tools.d.ts +96 -3
  179. package/dist/esm/capabilities/tools.js +267 -32
  180. package/dist/esm/context/assembly.d.ts +13 -2
  181. package/dist/esm/context/assembly.js +46 -5
  182. package/dist/esm/context/audit.d.ts +23 -1
  183. package/dist/esm/context/audit.js +31 -6
  184. package/dist/esm/context/fragments.d.ts +37 -3
  185. package/dist/esm/context/fragments.js +54 -11
  186. package/dist/esm/context/index.d.ts +12 -0
  187. package/dist/esm/context/index.js +12 -0
  188. package/dist/esm/context/journal.d.ts +32 -1
  189. package/dist/esm/context/journal.js +84 -7
  190. package/dist/esm/context/plan.d.ts +11 -1
  191. package/dist/esm/context/plan.js +30 -2
  192. package/dist/esm/diagnostics/catalog.js +11 -3
  193. package/dist/esm/diagnostics/index.d.ts +30 -2
  194. package/dist/esm/diagnostics/index.js +149 -29
  195. package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
  196. package/dist/esm/diagnostics/sub-flow.js +240 -40
  197. package/dist/esm/errors.d.ts +22 -2
  198. package/dist/esm/errors.js +99 -17
  199. package/dist/esm/execution/branch.d.ts +19 -1
  200. package/dist/esm/execution/branch.js +20 -4
  201. package/dist/esm/execution/engine.d.ts +291 -5
  202. package/dist/esm/execution/engine.js +471 -57
  203. package/dist/esm/execution/events.d.ts +16 -2
  204. package/dist/esm/execution/events.js +136 -18
  205. package/dist/esm/execution/index.d.ts +7 -0
  206. package/dist/esm/execution/index.js +7 -0
  207. package/dist/esm/execution/reporting.d.ts +49 -1
  208. package/dist/esm/execution/reporting.js +75 -6
  209. package/dist/esm/execution/state.d.ts +126 -10
  210. package/dist/esm/execution/state.js +161 -22
  211. package/dist/esm/execution/workflow.d.ts +121 -3
  212. package/dist/esm/execution/workflow.js +224 -32
  213. package/dist/esm/index.d.ts +17 -1
  214. package/dist/esm/index.js +18 -0
  215. package/dist/esm/kits/aggregation.d.ts +34 -2
  216. package/dist/esm/kits/aggregation.js +45 -3
  217. package/dist/esm/kits/answering/batch.d.ts +17 -0
  218. package/dist/esm/kits/answering/batch.js +23 -4
  219. package/dist/esm/kits/answering/check-result.d.ts +18 -1
  220. package/dist/esm/kits/answering/check-result.js +31 -8
  221. package/dist/esm/kits/answering/checks.d.ts +11 -0
  222. package/dist/esm/kits/answering/checks.js +24 -3
  223. package/dist/esm/kits/answering/flow.d.ts +25 -2
  224. package/dist/esm/kits/answering/flow.js +192 -36
  225. package/dist/esm/kits/answering/index.d.ts +12 -0
  226. package/dist/esm/kits/answering/index.js +19 -1
  227. package/dist/esm/kits/answering/tasks.d.ts +32 -1
  228. package/dist/esm/kits/answering/tasks.js +88 -13
  229. package/dist/esm/kits/artifacts.d.ts +11 -0
  230. package/dist/esm/kits/artifacts.js +36 -4
  231. package/dist/esm/kits/candidates.d.ts +23 -1
  232. package/dist/esm/kits/candidates.js +47 -5
  233. package/dist/esm/kits/delivery.d.ts +34 -0
  234. package/dist/esm/kits/delivery.js +40 -5
  235. package/dist/esm/kits/durable.d.ts +19 -0
  236. package/dist/esm/kits/durable.js +155 -31
  237. package/dist/esm/kits/evidence.d.ts +28 -5
  238. package/dist/esm/kits/evidence.js +66 -15
  239. package/dist/esm/kits/family.d.ts +17 -1
  240. package/dist/esm/kits/family.js +152 -22
  241. package/dist/esm/kits/index.d.ts +12 -1
  242. package/dist/esm/kits/index.js +12 -1
  243. package/dist/esm/kits/inference.d.ts +64 -0
  244. package/dist/esm/kits/inference.js +104 -16
  245. package/dist/esm/kits/intents/catalog.d.ts +13 -1
  246. package/dist/esm/kits/intents/catalog.js +67 -16
  247. package/dist/esm/kits/intents/index.d.ts +11 -0
  248. package/dist/esm/kits/intents/index.js +11 -0
  249. package/dist/esm/kits/intents/registry.d.ts +61 -3
  250. package/dist/esm/kits/intents/registry.js +188 -43
  251. package/dist/esm/kits/intents/scopes.d.ts +73 -3
  252. package/dist/esm/kits/intents/scopes.js +215 -46
  253. package/dist/esm/kits/interaction/command.d.ts +38 -4
  254. package/dist/esm/kits/interaction/command.js +140 -36
  255. package/dist/esm/kits/interaction/commands.d.ts +66 -2
  256. package/dist/esm/kits/interaction/commands.js +86 -11
  257. package/dist/esm/kits/interaction/handlers.d.ts +19 -2
  258. package/dist/esm/kits/interaction/handlers.js +27 -10
  259. package/dist/esm/kits/interaction/index.d.ts +10 -0
  260. package/dist/esm/kits/interaction/index.js +10 -0
  261. package/dist/esm/kits/interaction/transfer.d.ts +39 -2
  262. package/dist/esm/kits/interaction/transfer.js +80 -14
  263. package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
  264. package/dist/esm/kits/knowledge/catalog.js +62 -11
  265. package/dist/esm/kits/knowledge/index.d.ts +11 -0
  266. package/dist/esm/kits/knowledge/index.js +16 -1
  267. package/dist/esm/kits/knowledge/publication.d.ts +15 -1
  268. package/dist/esm/kits/knowledge/publication.js +99 -23
  269. package/dist/esm/kits/knowledge/sections.d.ts +31 -1
  270. package/dist/esm/kits/knowledge/sections.js +33 -4
  271. package/dist/esm/kits/normalization.d.ts +25 -2
  272. package/dist/esm/kits/normalization.js +51 -7
  273. package/dist/esm/kits/policies.d.ts +26 -3
  274. package/dist/esm/kits/policies.js +79 -15
  275. package/dist/esm/kits/presentation/events.d.ts +51 -4
  276. package/dist/esm/kits/presentation/events.js +54 -10
  277. package/dist/esm/kits/presentation/index.d.ts +12 -0
  278. package/dist/esm/kits/presentation/index.js +25 -2
  279. package/dist/esm/kits/presentation/outputs.d.ts +30 -1
  280. package/dist/esm/kits/presentation/outputs.js +176 -38
  281. package/dist/esm/kits/presentation/templates.d.ts +32 -3
  282. package/dist/esm/kits/presentation/templates.js +33 -5
  283. package/dist/esm/kits/presentation/variants.d.ts +29 -0
  284. package/dist/esm/kits/presentation/variants.js +31 -2
  285. package/dist/esm/kits/projection.d.ts +42 -5
  286. package/dist/esm/kits/projection.js +63 -8
  287. package/dist/esm/kits/rank-fusion.d.ts +21 -1
  288. package/dist/esm/kits/rank-fusion.js +28 -5
  289. package/dist/esm/kits/reflection-log-source.d.ts +28 -1
  290. package/dist/esm/kits/reflection-log-source.js +89 -16
  291. package/dist/esm/kits/reflection.d.ts +17 -1
  292. package/dist/esm/kits/reflection.js +235 -61
  293. package/dist/esm/kits/retrieval.d.ts +18 -2
  294. package/dist/esm/kits/retrieval.js +98 -18
  295. package/dist/esm/kits/search.d.ts +56 -3
  296. package/dist/esm/kits/search.js +180 -27
  297. package/dist/esm/kits/text-skills.d.ts +16 -2
  298. package/dist/esm/kits/text-skills.js +104 -19
  299. package/dist/esm/kits/tools.d.ts +122 -2
  300. package/dist/esm/kits/tools.js +416 -74
  301. package/dist/esm/kits/vector-search.d.ts +47 -1
  302. package/dist/esm/kits/vector-search.js +51 -17
  303. package/dist/esm/mock/node.d.ts +7 -0
  304. package/dist/esm/mock/node.js +7 -1
  305. package/dist/esm/mock/web.d.ts +7 -0
  306. package/dist/esm/mock/web.js +7 -1
  307. package/dist/esm/mock.d.ts +7 -0
  308. package/dist/esm/mock.js +7 -1
  309. package/dist/esm/model/binding.d.ts +32 -3
  310. package/dist/esm/model/binding.js +68 -17
  311. package/dist/esm/model/call-budget.d.ts +30 -2
  312. package/dist/esm/model/call-budget.js +45 -4
  313. package/dist/esm/model/decision-retry.d.ts +10 -1
  314. package/dist/esm/model/decision-retry.js +19 -1
  315. package/dist/esm/model/defaults.d.ts +13 -2
  316. package/dist/esm/model/defaults.js +27 -4
  317. package/dist/esm/model/index.d.ts +7 -0
  318. package/dist/esm/model/index.js +7 -0
  319. package/dist/esm/model/interactions/arguments.d.ts +27 -0
  320. package/dist/esm/model/interactions/arguments.js +36 -1
  321. package/dist/esm/model/interactions/json-object.d.ts +7 -1
  322. package/dist/esm/model/interactions/json-object.js +48 -12
  323. package/dist/esm/model/interactions/native-functions.d.ts +6 -0
  324. package/dist/esm/model/interactions/native-functions.js +52 -10
  325. package/dist/esm/model/message-diagnostics.d.ts +17 -1
  326. package/dist/esm/model/message-diagnostics.js +17 -4
  327. package/dist/esm/model/options.d.ts +18 -1
  328. package/dist/esm/model/options.js +9 -1
  329. package/dist/esm/model/preparation.d.ts +30 -2
  330. package/dist/esm/model/preparation.js +86 -12
  331. package/dist/esm/model/runner.d.ts +129 -5
  332. package/dist/esm/model/runner.js +414 -80
  333. package/dist/esm/model/selection-transport.d.ts +14 -1
  334. package/dist/esm/model/selection-transport.js +48 -8
  335. package/dist/esm/model/settings.d.ts +11 -0
  336. package/dist/esm/model/settings.js +67 -13
  337. package/dist/esm/model/token-budget.d.ts +59 -1
  338. package/dist/esm/model/token-budget.js +69 -11
  339. package/dist/esm/model/transports.d.ts +20 -2
  340. package/dist/esm/model/transports.js +59 -6
  341. package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
  342. package/dist/esm/structs/capabilities/model.d.ts +27 -0
  343. package/dist/esm/structs/capabilities/tools.d.ts +38 -0
  344. package/dist/esm/structs/common.d.ts +62 -2
  345. package/dist/esm/structs/common.js +11 -0
  346. package/dist/esm/structs/context/fragments.d.ts +28 -0
  347. package/dist/esm/structs/context/journal.d.ts +28 -3
  348. package/dist/esm/structs/context/processing.d.ts +11 -0
  349. package/dist/esm/structs/debug.d.ts +58 -1
  350. package/dist/esm/structs/debug.js +34 -5
  351. package/dist/esm/structs/diagnostics.d.ts +119 -1
  352. package/dist/esm/structs/errors.d.ts +42 -1
  353. package/dist/esm/structs/errors.js +26 -1
  354. package/dist/esm/structs/execution/engine.d.ts +24 -1
  355. package/dist/esm/structs/execution/events.d.ts +12 -0
  356. package/dist/esm/structs/execution/workflow.d.ts +71 -0
  357. package/dist/esm/structs/index.d.ts +11 -1
  358. package/dist/esm/structs/index.js +11 -1
  359. package/dist/esm/structs/invocation.d.ts +30 -0
  360. package/dist/esm/structs/kits/aggregation.d.ts +12 -0
  361. package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
  362. package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
  363. package/dist/esm/structs/kits/answering/state.d.ts +21 -0
  364. package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
  365. package/dist/esm/structs/kits/artifacts.d.ts +14 -0
  366. package/dist/esm/structs/kits/candidates.d.ts +19 -0
  367. package/dist/esm/structs/kits/delivery.d.ts +22 -0
  368. package/dist/esm/structs/kits/durable.d.ts +56 -3
  369. package/dist/esm/structs/kits/durable.js +7 -0
  370. package/dist/esm/structs/kits/evidence.d.ts +23 -0
  371. package/dist/esm/structs/kits/family.d.ts +49 -1
  372. package/dist/esm/structs/kits/family.js +1 -0
  373. package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
  374. package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
  375. package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
  376. package/dist/esm/structs/kits/interaction.d.ts +64 -0
  377. package/dist/esm/structs/kits/interaction.js +8 -1
  378. package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
  379. package/dist/esm/structs/kits/knowledge-publication.js +1 -0
  380. package/dist/esm/structs/kits/knowledge.d.ts +39 -2
  381. package/dist/esm/structs/kits/normalization.d.ts +15 -0
  382. package/dist/esm/structs/kits/policies.d.ts +25 -1
  383. package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
  384. package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
  385. package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
  386. package/dist/esm/structs/kits/projection.d.ts +21 -0
  387. package/dist/esm/structs/kits/reflection.d.ts +61 -2
  388. package/dist/esm/structs/kits/reflection.js +18 -3
  389. package/dist/esm/structs/kits/retrieval.d.ts +38 -0
  390. package/dist/esm/structs/kits/search.d.ts +22 -0
  391. package/dist/esm/structs/kits/text-skills.d.ts +36 -0
  392. package/dist/esm/structs/kits/tools.d.ts +87 -0
  393. package/dist/esm/structs/model/chat-provider.d.ts +24 -1
  394. package/dist/esm/structs/model/chat-provider.js +6 -0
  395. package/dist/esm/structs/model/interactions.d.ts +38 -0
  396. package/dist/esm/structs/model/messages.d.ts +30 -0
  397. package/dist/esm/structs/model/runtime.d.ts +104 -6
  398. package/dist/esm/structs/support/capabilities.d.ts +19 -2
  399. package/dist/esm/structs/support/context-processing.d.ts +88 -9
  400. package/dist/esm/structs/support/context.d.ts +29 -1
  401. package/dist/esm/structs/support/model/completion.d.ts +50 -0
  402. package/dist/esm/structs/support/model/completion.js +1 -0
  403. package/dist/esm/structs/support/model/interactions.d.ts +13 -1
  404. package/dist/esm/structs/support/model/messages.d.ts +52 -0
  405. package/dist/esm/structs/support/model/messages.js +1 -0
  406. package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
  407. package/dist/esm/structs/support/model/provider.d.ts +71 -6
  408. package/dist/esm/structs/support/registration.d.ts +13 -0
  409. package/dist/esm/structs/support/schema.d.ts +14 -0
  410. package/dist/esm/structs/support/tools.d.ts +28 -0
  411. package/dist/esm/structs/support/transport/json.d.ts +16 -0
  412. package/dist/esm/structs/support/transport/sse.d.ts +15 -0
  413. package/dist/esm/structs/utils/rules.d.ts +19 -0
  414. package/dist/esm/support/capabilities.d.ts +25 -2
  415. package/dist/esm/support/capabilities.js +43 -6
  416. package/dist/esm/support/context/assembly.d.ts +35 -4
  417. package/dist/esm/support/context/assembly.js +88 -16
  418. package/dist/esm/support/context/compression.d.ts +17 -1
  419. package/dist/esm/support/context/compression.js +48 -6
  420. package/dist/esm/support/context/fragments.d.ts +6 -0
  421. package/dist/esm/support/context/fragments.js +6 -0
  422. package/dist/esm/support/context/history.d.ts +43 -0
  423. package/dist/esm/support/context/history.js +36 -1
  424. package/dist/esm/support/context/index.d.ts +13 -2
  425. package/dist/esm/support/context/index.js +12 -1
  426. package/dist/esm/support/context/nodes.d.ts +49 -3
  427. package/dist/esm/support/context/nodes.js +165 -36
  428. package/dist/esm/support/context/processing.d.ts +145 -1
  429. package/dist/esm/support/context/processing.js +320 -62
  430. package/dist/esm/support/context/selection-policy.d.ts +42 -2
  431. package/dist/esm/support/context/selection-policy.js +98 -21
  432. package/dist/esm/support/context/selection.d.ts +14 -1
  433. package/dist/esm/support/context/selection.js +61 -10
  434. package/dist/esm/support/context/snapshot.d.ts +23 -1
  435. package/dist/esm/support/context/snapshot.js +29 -7
  436. package/dist/esm/support/context/strategies.d.ts +35 -2
  437. package/dist/esm/support/context/strategies.js +120 -28
  438. package/dist/esm/support/index.d.ts +9 -1
  439. package/dist/esm/support/index.js +9 -1
  440. package/dist/esm/support/model/capabilities.d.ts +10 -0
  441. package/dist/esm/support/model/capabilities.js +20 -1
  442. package/dist/esm/support/model/chat-completions.d.ts +44 -15
  443. package/dist/esm/support/model/chat-completions.js +92 -20
  444. package/dist/esm/support/model/children.d.ts +32 -2
  445. package/dist/esm/support/model/children.js +34 -6
  446. package/dist/esm/support/model/compatible-provider.d.ts +29 -3
  447. package/dist/esm/support/model/compatible-provider.js +190 -60
  448. package/dist/esm/support/model/completion/calls.d.ts +40 -0
  449. package/dist/esm/support/model/completion/calls.js +58 -0
  450. package/dist/esm/support/model/completion/default.d.ts +10 -0
  451. package/dist/esm/support/model/completion/default.js +29 -0
  452. package/dist/esm/support/model/completion/index.d.ts +10 -0
  453. package/dist/esm/support/model/completion/index.js +22 -0
  454. package/dist/esm/support/model/completion/session.d.ts +11 -0
  455. package/dist/esm/support/model/completion/session.js +99 -0
  456. package/dist/esm/support/model/index.d.ts +14 -0
  457. package/dist/esm/support/model/index.js +12 -0
  458. package/dist/esm/support/model/interactions/index.d.ts +1 -1
  459. package/dist/esm/support/model/interactions/index.js +12 -1
  460. package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
  461. package/dist/esm/support/model/interactions/json-object.js +6 -0
  462. package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
  463. package/dist/esm/support/model/interactions/native-functions.js +6 -0
  464. package/dist/esm/support/model/observer.d.ts +25 -2
  465. package/dist/esm/support/model/observer.js +32 -6
  466. package/dist/esm/support/model/preview-rules.d.ts +20 -2
  467. package/dist/esm/support/model/preview-rules.js +66 -16
  468. package/dist/esm/support/model/reply-preview.d.ts +15 -1
  469. package/dist/esm/support/model/reply-preview.js +77 -17
  470. package/dist/esm/support/model/stage-transport.d.ts +9 -1
  471. package/dist/esm/support/model/stage-transport.js +33 -7
  472. package/dist/esm/support/model/strategies.d.ts +24 -2
  473. package/dist/esm/support/model/strategies.js +75 -14
  474. package/dist/esm/support/model/transports.d.ts +17 -1
  475. package/dist/esm/support/model/transports.js +53 -11
  476. package/dist/esm/support/registration.d.ts +20 -1
  477. package/dist/esm/support/registration.js +49 -7
  478. package/dist/esm/support/schema.d.ts +31 -1
  479. package/dist/esm/support/schema.js +46 -4
  480. package/dist/esm/support/stream-events.d.ts +22 -1
  481. package/dist/esm/support/stream-events.js +60 -8
  482. package/dist/esm/support/tool-runtime.d.ts +6 -0
  483. package/dist/esm/support/tool-runtime.js +6 -0
  484. package/dist/esm/support/tools.d.ts +22 -0
  485. package/dist/esm/support/tools.js +79 -10
  486. package/dist/esm/support/transport/index.d.ts +7 -0
  487. package/dist/esm/support/transport/index.js +7 -0
  488. package/dist/esm/support/transport/json.d.ts +29 -2
  489. package/dist/esm/support/transport/json.js +28 -4
  490. package/dist/esm/support/transport/sse.d.ts +31 -1
  491. package/dist/esm/support/transport/sse.js +25 -2
  492. package/dist/esm/types.d.ts +9 -1
  493. package/dist/esm/utils/break-observer.d.ts +27 -2
  494. package/dist/esm/utils/break-observer.js +20 -2
  495. package/dist/esm/utils/cancellation.d.ts +56 -5
  496. package/dist/esm/utils/cancellation.js +77 -9
  497. package/dist/esm/utils/catalog.d.ts +20 -1
  498. package/dist/esm/utils/catalog.js +19 -4
  499. package/dist/esm/utils/debug.d.ts +20 -1
  500. package/dist/esm/utils/debug.js +14 -2
  501. package/dist/esm/utils/index.d.ts +8 -0
  502. package/dist/esm/utils/index.js +8 -0
  503. package/dist/esm/utils/interaction-definition.d.ts +18 -1
  504. package/dist/esm/utils/interaction-definition.js +26 -6
  505. package/dist/esm/utils/invocation.d.ts +36 -1
  506. package/dist/esm/utils/invocation.js +42 -4
  507. package/dist/esm/utils/model-protocol.d.ts +8 -0
  508. package/dist/esm/utils/model-protocol.js +20 -1
  509. package/dist/esm/utils/object.d.ts +16 -0
  510. package/dist/esm/utils/object.js +16 -0
  511. package/dist/esm/utils/observer.d.ts +19 -1
  512. package/dist/esm/utils/observer.js +22 -2
  513. package/dist/esm/utils/protocol-registry.d.ts +38 -1
  514. package/dist/esm/utils/protocol-registry.js +47 -4
  515. package/dist/esm/utils/query-key.d.ts +11 -1
  516. package/dist/esm/utils/query-key.js +21 -2
  517. package/dist/esm/utils/registration.d.ts +34 -2
  518. package/dist/esm/utils/registration.js +18 -2
  519. package/dist/esm/utils/rules.d.ts +81 -4
  520. package/dist/esm/utils/rules.js +39 -11
  521. package/dist/esm/utils/schema-adapter.d.ts +12 -1
  522. package/dist/esm/utils/schema-adapter.js +25 -2
  523. package/dist/esm/utils/synchronous.d.ts +60 -4
  524. package/dist/esm/utils/synchronous.js +64 -7
  525. package/dist/esm/utils/text.d.ts +15 -1
  526. package/dist/esm/utils/text.js +15 -1
  527. package/package.json +23 -3
@@ -1,10 +1,28 @@
1
1
  let onBreak;
2
+ // Re-entrancy guard: an observer that itself calls breakWhile would otherwise recurse
3
+ // until the stack overflows.
2
4
  let notifying = false;
3
- /** Hosts may install a diagnostic observer; no logging or persistence is enabled by default. */
5
+ /**
6
+ * Install the host-owned break observer.
7
+ *
8
+ * No logging or persistence is enabled by default; passing no argument (or an empty
9
+ * config) removes any previously installed observer.
10
+ *
11
+ * @param config - Observation configuration; `onBreak` receives one frozen event per rejection.
12
+ */
4
13
  export function configureBreakWhile(config = {}) {
5
14
  onBreak = config.onBreak;
6
15
  }
7
- /** Diagnostic failures must never replace the original interruption. */
16
+ /**
17
+ * Notify the installed observer about a rejection.
18
+ *
19
+ * The original interruption is authoritative: observer failures, and rejections of the
20
+ * promise an observer returns, are swallowed.
21
+ *
22
+ * @param error - The value that is about to be thrown by `breakWhile`.
23
+ * @param tags - Call-site tags supplied by the caller of `breakWhile`.
24
+ * @param rule - The failing check, whose own tags are merged into the reported set.
25
+ */
8
26
  export function observeBreak(error, tags, rule) {
9
27
  if (!onBreak || notifying)
10
28
  return;
@@ -1,12 +1,63 @@
1
- /** Cancellation reasons are arbitrary thrown values, including hostile objects. */
1
+ /**
2
+ * Detect a deadline expiry as opposed to any other cancellation.
3
+ *
4
+ * The reason of an aborted signal is an arbitrary thrown value, including hostile
5
+ * objects whose `name` getter throws, so the lookup is guarded.
6
+ *
7
+ * @param reason - Value delivered as `signal.reason`.
8
+ * @returns True when the reason is named `TimeoutError`.
9
+ */
2
10
  export declare function isTimeoutReason(reason: unknown): boolean;
3
- /** Optional request signals only shorten the lifetime; deduplicate without replacing a parent. */
11
+ /**
12
+ * Merge optional signals into one lifetime bound.
13
+ *
14
+ * Duplicates are removed first so a signal appearing both as an execution parent and
15
+ * as a request signal does not allocate a redundant composite. When nothing is
16
+ * supplied a fresh, never-aborting signal is returned, which keeps callers free of
17
+ * undefined checks.
18
+ *
19
+ * @param sources - Candidate signals in precedence-free order; `undefined` entries are ignored.
20
+ * @returns A signal that aborts as soon as any supplied signal aborts.
21
+ */
4
22
  export declare function combineSignals(...sources: readonly (AbortSignal | undefined)[]): AbortSignal;
5
- /** Abandon waiting, but keep observing late rejection and remove the abort listener. */
23
+ /**
24
+ * Race a pending value against an abort signal.
25
+ *
26
+ * Abandoning the wait does not cancel the underlying work: a late rejection is still
27
+ * consumed to avoid an unhandled rejection, and the abort listener is always removed.
28
+ *
29
+ * @param value - Value or promise to await; `undefined` keeps the same await semantics.
30
+ * @param signal - Optional lifetime bound; without it the value is awaited unchanged.
31
+ * @returns The resolved value.
32
+ * @throws The signal reason when aborted, or the rejection of `value`.
33
+ */
6
34
  export declare function awaitWithSignal<Value>(value: Value | PromiseLike<Value>, signal?: AbortSignal): Promise<Value>;
7
- /** Authorization and validation hooks may await, but only void means success. */
35
+ /**
36
+ * Run an assertion that may be asynchronous, bounded by a signal.
37
+ *
38
+ * Only a `void` result counts as success, so a hook that discards its decision as a
39
+ * boolean is rejected rather than silently treated as passing. The signal is checked
40
+ * before and after the hook so a decision produced after cancellation is discarded.
41
+ *
42
+ * @param check - Hook invoked once; may return a promise.
43
+ * @param signal - Lifetime bound for the hook and its result.
44
+ * @param message - Message for the TypeError raised when the hook does not return void.
45
+ * @returns A promise resolved once the assertion passed.
46
+ * @throws The signal reason when aborted, the hook's rejection, or the assertion TypeError.
47
+ */
8
48
  export declare function awaitAssertion(check: () => unknown, signal: AbortSignal, message: string): Promise<void>;
9
- /** Chunk timers exceeding the platform limit without shortening the persisted deadline. */
49
+ /**
50
+ * Abort at an absolute wall-clock deadline, combined with a parent signal.
51
+ *
52
+ * Timers above the platform maximum are chunked instead of being clamped, so the
53
+ * persisted deadline is never shortened. The deadline is recomputed from the clock on
54
+ * each chunk, which keeps the effective expiry correct across timer drift.
55
+ *
56
+ * @param deadline - Absolute deadline in epoch milliseconds.
57
+ * @param parent - Additional lifetime bound, typically the execution signal.
58
+ * @param now - Clock source; injectable for tests.
59
+ * @returns The combined `signal` and a `dispose` function that cancels the pending timer.
60
+ */
10
61
  export declare function createDeadlineSignal(deadline: number, parent: AbortSignal, now?: () => number): {
11
62
  signal: AbortSignal;
12
63
  dispose(): void;
@@ -1,5 +1,21 @@
1
+ /**
2
+ * Cancellation and deadline plumbing shared by the model runner and the engine.
3
+ *
4
+ * Every helper here treats an abort signal as a pure lifetime bound: it may only
5
+ * shorten waiting, never extend it, and it never replaces a caller-supplied parent
6
+ * signal. Exports: `isTimeoutReason`, `combineSignals`, `awaitWithSignal`,
7
+ * `awaitAssertion` and `createDeadlineSignal`.
8
+ */
1
9
  import { assertion } from './synchronous.js';
2
- /** Cancellation reasons are arbitrary thrown values, including hostile objects. */
10
+ /**
11
+ * Detect a deadline expiry as opposed to any other cancellation.
12
+ *
13
+ * The reason of an aborted signal is an arbitrary thrown value, including hostile
14
+ * objects whose `name` getter throws, so the lookup is guarded.
15
+ *
16
+ * @param reason - Value delivered as `signal.reason`.
17
+ * @returns True when the reason is named `TimeoutError`.
18
+ */
3
19
  export function isTimeoutReason(reason) {
4
20
  try {
5
21
  return reason?.name === 'TimeoutError';
@@ -8,12 +24,36 @@ export function isTimeoutReason(reason) {
8
24
  return false;
9
25
  }
10
26
  }
11
- /** Optional request signals only shorten the lifetime; deduplicate without replacing a parent. */
27
+ /**
28
+ * Merge optional signals into one lifetime bound.
29
+ *
30
+ * Duplicates are removed first so a signal appearing both as an execution parent and
31
+ * as a request signal does not allocate a redundant composite. When nothing is
32
+ * supplied a fresh, never-aborting signal is returned, which keeps callers free of
33
+ * undefined checks.
34
+ *
35
+ * @param sources - Candidate signals in precedence-free order; `undefined` entries are ignored.
36
+ * @returns A signal that aborts as soon as any supplied signal aborts.
37
+ */
12
38
  export function combineSignals(...sources) {
13
- const signals = [...new Set(sources.filter((signal) => signal !== undefined))];
14
- return signals.length > 1 ? AbortSignal.any(signals) : signals[0] ?? new AbortController().signal;
39
+ const signals = [
40
+ ...new Set(sources.filter((signal) => signal !== undefined)),
41
+ ];
42
+ return signals.length > 1
43
+ ? AbortSignal.any(signals)
44
+ : (signals[0] ?? new AbortController().signal);
15
45
  }
16
- /** Abandon waiting, but keep observing late rejection and remove the abort listener. */
46
+ /**
47
+ * Race a pending value against an abort signal.
48
+ *
49
+ * Abandoning the wait does not cancel the underlying work: a late rejection is still
50
+ * consumed to avoid an unhandled rejection, and the abort listener is always removed.
51
+ *
52
+ * @param value - Value or promise to await; `undefined` keeps the same await semantics.
53
+ * @param signal - Optional lifetime bound; without it the value is awaited unchanged.
54
+ * @returns The resolved value.
55
+ * @throws The signal reason when aborted, or the rejection of `value`.
56
+ */
17
57
  export async function awaitWithSignal(value, signal) {
18
58
  if (!signal)
19
59
  return value;
@@ -31,14 +71,37 @@ export async function awaitWithSignal(value, signal) {
31
71
  signal.removeEventListener('abort', abort);
32
72
  }
33
73
  }
34
- /** Authorization and validation hooks may await, but only void means success. */
74
+ /**
75
+ * Run an assertion that may be asynchronous, bounded by a signal.
76
+ *
77
+ * Only a `void` result counts as success, so a hook that discards its decision as a
78
+ * boolean is rejected rather than silently treated as passing. The signal is checked
79
+ * before and after the hook so a decision produced after cancellation is discarded.
80
+ *
81
+ * @param check - Hook invoked once; may return a promise.
82
+ * @param signal - Lifetime bound for the hook and its result.
83
+ * @param message - Message for the TypeError raised when the hook does not return void.
84
+ * @returns A promise resolved once the assertion passed.
85
+ * @throws The signal reason when aborted, the hook's rejection, or the assertion TypeError.
86
+ */
35
87
  export async function awaitAssertion(check, signal, message) {
36
88
  signal.throwIfAborted();
37
89
  const result = await awaitWithSignal(check(), signal);
38
90
  signal.throwIfAborted();
39
91
  assertion(result, message);
40
92
  }
41
- /** Chunk timers exceeding the platform limit without shortening the persisted deadline. */
93
+ /**
94
+ * Abort at an absolute wall-clock deadline, combined with a parent signal.
95
+ *
96
+ * Timers above the platform maximum are chunked instead of being clamped, so the
97
+ * persisted deadline is never shortened. The deadline is recomputed from the clock on
98
+ * each chunk, which keeps the effective expiry correct across timer drift.
99
+ *
100
+ * @param deadline - Absolute deadline in epoch milliseconds.
101
+ * @param parent - Additional lifetime bound, typically the execution signal.
102
+ * @param now - Clock source; injectable for tests.
103
+ * @returns The combined `signal` and a `dispose` function that cancels the pending timer.
104
+ */
42
105
  export function createDeadlineSignal(deadline, parent, now = Date.now) {
43
106
  const controller = new AbortController();
44
107
  let timer;
@@ -50,6 +113,11 @@ export function createDeadlineSignal(deadline, parent, now = Date.now) {
50
113
  timer = setTimeout(schedule, Math.min(remaining, 2147483647));
51
114
  };
52
115
  schedule();
53
- return { signal: combineSignals(parent, controller.signal), dispose() { if (timer !== undefined)
54
- clearTimeout(timer); } };
116
+ return {
117
+ signal: combineSignals(parent, controller.signal),
118
+ dispose() {
119
+ if (timer !== undefined)
120
+ clearTimeout(timer);
121
+ },
122
+ };
55
123
  }
@@ -1,5 +1,24 @@
1
+ /**
2
+ * Immutable id-keyed catalog snapshot.
3
+ *
4
+ * Modules that own registrable definitions (tools, capabilities, prompts) publish the
5
+ * snapshot produced here instead of exposing their mutable `Map`, so later mutations
6
+ * by the owner cannot be observed and no consumer can mutate the registry.
7
+ *
8
+ * Exports: `readonlyCatalog`.
9
+ */
1
10
  import type { ReadonlyCatalog } from '../structs/common.js';
2
- /** Entries are compiled/snapshotted by the owning module; this exposes no mutable Map. */
11
+ /**
12
+ * Build a frozen catalog from an iterable of definitions.
13
+ *
14
+ * Ids must be non-empty after trimming and unique; both violations surface as a
15
+ * TypeError during construction rather than on first lookup.
16
+ *
17
+ * @param definitions - Definitions to snapshot; iteration order is preserved in `definitions`.
18
+ * @param missing - Factory for the error thrown by `require` when an id is absent.
19
+ * @returns A frozen catalog; `get` is unguarded while `require` throws via `missing`.
20
+ * @throws TypeError When an id is blank or duplicated.
21
+ */
3
22
  export declare function readonlyCatalog<Definition extends {
4
23
  readonly id: string;
5
24
  }>(definitions: Iterable<Readonly<Definition>>, missing: (id: string) => Error): ReadonlyCatalog<Definition>;
@@ -1,4 +1,14 @@
1
- /** Entries are compiled/snapshotted by the owning module; this exposes no mutable Map. */
1
+ /**
2
+ * Build a frozen catalog from an iterable of definitions.
3
+ *
4
+ * Ids must be non-empty after trimming and unique; both violations surface as a
5
+ * TypeError during construction rather than on first lookup.
6
+ *
7
+ * @param definitions - Definitions to snapshot; iteration order is preserved in `definitions`.
8
+ * @param missing - Factory for the error thrown by `require` when an id is absent.
9
+ * @returns A frozen catalog; `get` is unguarded while `require` throws via `missing`.
10
+ * @throws TypeError When an id is blank or duplicated.
11
+ */
2
12
  export function readonlyCatalog(definitions, missing) {
3
13
  const byId = new Map();
4
14
  for (const definition of definitions) {
@@ -7,9 +17,14 @@ export function readonlyCatalog(definitions, missing) {
7
17
  byId.set(definition.id, definition);
8
18
  }
9
19
  const snapshot = Object.freeze([...byId.values()]);
10
- return Object.freeze({ definitions: snapshot, ids: () => Object.freeze([...byId.keys()]),
11
- values: () => byId.values(), entries: () => byId.entries(), has: (id) => byId.has(id),
12
- get: (id) => byId.get(id), require(id) {
20
+ return Object.freeze({
21
+ definitions: snapshot,
22
+ ids: () => Object.freeze([...byId.keys()]),
23
+ values: () => byId.values(),
24
+ entries: () => byId.entries(),
25
+ has: (id) => byId.has(id),
26
+ get: (id) => byId.get(id),
27
+ require(id) {
13
28
  const value = byId.get(id);
14
29
  if (value === undefined)
15
30
  throw missing(id);
@@ -1,6 +1,25 @@
1
+ /**
2
+ * Adapter between App-supplied debug loggers and the diagnostics pipeline.
3
+ *
4
+ * Sub-flow loggers are mutable, execution-owned objects. This module reads one at the
5
+ * moment a diagnostic fact is built and converts it into a frozen array of steps, so
6
+ * persisted observations never retain a live logger.
7
+ *
8
+ * Exports: `captureSubSteps`.
9
+ */
1
10
  import type { SubFlowLogger } from '../structs/debug.js';
2
11
  import type { DiagnosticIdentity } from '../structs/diagnostics.js';
3
- /** Only execution-owned logger instances can produce new child log arrays. */
12
+ /**
13
+ * Read the current sub-step log of one execution visit.
14
+ *
15
+ * A missing reader or a logger that yields nothing produces the empty shape, which
16
+ * lets callers spread the result unconditionally. Failures are reported as one
17
+ * dropped step instead of propagating, because diagnostics must not break execution.
18
+ *
19
+ * @param read - Getter for the current logger; omitted when the caller has no logger.
20
+ * @param identity - Diagnostic identity copied onto each captured step.
21
+ * @returns Frozen `subSteps`, the number of dropped steps and whether the log was truncated.
22
+ */
4
23
  export declare function captureSubSteps(read: (() => SubFlowLogger | undefined) | undefined, identity?: Readonly<DiagnosticIdentity>): {
5
24
  subSteps: readonly Readonly<import("../index.js").RecordedSubStep>[];
6
25
  subStepsDropped: number;
@@ -1,13 +1,25 @@
1
1
  import { readSubFlowLogger } from '../diagnostics/sub-flow.js';
2
2
  import { synchronous } from './synchronous.js';
3
- /** Only execution-owned logger instances can produce new child log arrays. */
3
+ /**
4
+ * Read the current sub-step log of one execution visit.
5
+ *
6
+ * A missing reader or a logger that yields nothing produces the empty shape, which
7
+ * lets callers spread the result unconditionally. Failures are reported as one
8
+ * dropped step instead of propagating, because diagnostics must not break execution.
9
+ *
10
+ * @param read - Getter for the current logger; omitted when the caller has no logger.
11
+ * @param identity - Diagnostic identity copied onto each captured step.
12
+ * @returns Frozen `subSteps`, the number of dropped steps and whether the log was truncated.
13
+ */
4
14
  export function captureSubSteps(read, identity) {
5
15
  const empty = { subSteps: Object.freeze([]), subStepsDropped: 0, subStepsTruncated: false };
6
16
  if (!read)
7
17
  return empty;
8
18
  try {
9
19
  const logger = synchronous(read(), 'Debug steps must be synchronous');
10
- return logger === undefined ? empty : { ...empty, subSteps: readSubFlowLogger(logger, undefined, identity) };
20
+ return logger === undefined
21
+ ? empty
22
+ : { ...empty, subSteps: readSubFlowLogger(logger, undefined, identity) };
11
23
  }
12
24
  catch {
13
25
  return { ...empty, subStepsDropped: 1 };
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Generic helpers shared by every other module of `@jangts/agent-core`.
3
+ *
4
+ * Nothing here knows about business prompts, stages or transports: this barrel only
5
+ * re-exports rule traversal, text comparison, model protocol errors and retrieval
6
+ * query keys. Consumers inside the package import the concrete module directly;
7
+ * this entry exists so cross-module reuse has one stable surface.
8
+ */
1
9
  export * from './rules.js';
2
10
  export { commonPrefixLength } from './text.js';
3
11
  export { modelProtocolError } from './model-protocol.js';
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Generic helpers shared by every other module of `@jangts/agent-core`.
3
+ *
4
+ * Nothing here knows about business prompts, stages or transports: this barrel only
5
+ * re-exports rule traversal, text comparison, model protocol errors and retrieval
6
+ * query keys. Consumers inside the package import the concrete module directly;
7
+ * this entry exists so cross-module reuse has one stable surface.
8
+ */
1
9
  export * from './rules.js';
2
10
  export { commonPrefixLength } from './text.js';
3
11
  export { modelProtocolError } from './model-protocol.js';
@@ -1,3 +1,20 @@
1
+ /**
2
+ * Snapshot one interaction command definition before it is registered.
3
+ *
4
+ * Definitions are often plain objects composed with prototype methods or getters.
5
+ * Copying the known contract fields explicitly keeps those inherited members while
6
+ * dropping any other implementation helper, which is not part of the runtime contract.
7
+ *
8
+ * Exports: `pinCommandDefinition`.
9
+ */
1
10
  import type { CommandDefinition } from '../structs/kits/interaction.js';
2
- /** Read contract properties explicitly so prototype methods/getters survive composition. */
11
+ /**
12
+ * Produce a detached copy of the contract fields of a command definition.
13
+ *
14
+ * Callbacks are rebound to the original definition so `this` keeps pointing at the
15
+ * source object; `undefined` entries are dropped so optional fields stay absent.
16
+ *
17
+ * @param definition - Source definition, possibly carrying inherited members.
18
+ * @returns A new partial definition containing only the declared contract fields.
19
+ */
3
20
  export declare function pinCommandDefinition<Value extends object, Result, Args extends unknown[]>(definition: Partial<CommandDefinition<Value, Result, Args>>): Partial<CommandDefinition<Value, Result, Args>>;
@@ -1,10 +1,30 @@
1
- /** Read contract properties explicitly so prototype methods/getters survive composition. */
1
+ /**
2
+ * Produce a detached copy of the contract fields of a command definition.
3
+ *
4
+ * Callbacks are rebound to the original definition so `this` keeps pointing at the
5
+ * source object; `undefined` entries are dropped so optional fields stay absent.
6
+ *
7
+ * @param definition - Source definition, possibly carrying inherited members.
8
+ * @returns A new partial definition containing only the declared contract fields.
9
+ */
2
10
  export function pinCommandDefinition(definition) {
3
- const snapshot = { ...definition, fields: definition.fields, category: definition.category, version: definition.version,
4
- description: definition.description, terminal: definition.terminal, discriminator: definition.discriminator,
5
- ownedFields: definition.ownedFields, additionalProperties: definition.additionalProperties, optionalPresence: definition.optionalPresence,
6
- modes: definition.modes, tags: definition.tags, checks: definition.checks,
11
+ const snapshot = {
12
+ ...definition,
13
+ fields: definition.fields,
14
+ category: definition.category,
15
+ version: definition.version,
16
+ description: definition.description,
17
+ terminal: definition.terminal,
18
+ discriminator: definition.discriminator,
19
+ ownedFields: definition.ownedFields,
20
+ additionalProperties: definition.additionalProperties,
21
+ optionalPresence: definition.optionalPresence,
22
+ modes: definition.modes,
23
+ tags: definition.tags,
24
+ checks: definition.checks,
7
25
  error: typeof definition.error === 'function' ? definition.error.bind(definition) : definition.error,
8
- refine: definition.refine?.bind(definition), format: definition.format?.bind(definition) };
26
+ refine: definition.refine?.bind(definition),
27
+ format: definition.format?.bind(definition),
28
+ };
9
29
  return Object.fromEntries(Object.entries(snapshot).filter(([, value]) => value !== undefined));
10
30
  }
@@ -1,7 +1,42 @@
1
+ /**
2
+ * Invocation identity and result envelopes.
3
+ *
4
+ * Invocation ids are platform-neutral: they identify one call inside a run and are
5
+ * deliberately independent of App or request identities, so callers can correlate
6
+ * diagnostics without importing a domain concept.
7
+ *
8
+ * Exports: `invocationId`, `invocationResult` and `toolInvocation`.
9
+ */
1
10
  import type { InvocationMetadata, InvocationResult } from '../structs/invocation.js';
2
- /** Call IDs are platform-neutral and independent of App/request identities. */
11
+ /**
12
+ * Generate an invocation id.
13
+ *
14
+ * @returns A random UUID from the platform crypto implementation.
15
+ */
3
16
  export declare function invocationId(): string;
17
+ /**
18
+ * Wrap a value and its metadata in a frozen result envelope.
19
+ *
20
+ * Both layers are frozen so downstream consumers cannot mutate an already reported
21
+ * invocation.
22
+ *
23
+ * @param value - The produced value.
24
+ * @param metadata - Invocation metadata describing the call.
25
+ * @returns A frozen `InvocationResult`.
26
+ */
4
27
  export declare function invocationResult<Value, Metadata extends InvocationMetadata>(value: Value, metadata: Metadata): InvocationResult<Value, Metadata>;
28
+ /**
29
+ * Normalize the positional tool-invocation shorthand used by App handlers.
30
+ *
31
+ * The shorthand only accepts exactly one request so a handler cannot silently drop
32
+ * additional tools; the request must carry a non-blank `toolId` and an explicit
33
+ * `input` property, which distinguishes "no input" from "input omitted".
34
+ *
35
+ * @param request - Candidate request supplied as a single argument.
36
+ * @param arity - Number of arguments the caller actually passed; must be 1.
37
+ * @returns A plain object with the four supported request fields.
38
+ * @throws TypeError When the arity or the request shape is invalid.
39
+ */
5
40
  export declare function toolInvocation(request: import('../structs/capabilities/tools.js').ToolInvocationRequest, arity: number): {
6
41
  toolId: string;
7
42
  input: unknown;
@@ -1,11 +1,49 @@
1
- /** Call IDs are platform-neutral and independent of App/request identities. */
2
- export function invocationId() { return globalThis.crypto.randomUUID(); }
1
+ /**
2
+ * Generate an invocation id.
3
+ *
4
+ * @returns A random UUID from the platform crypto implementation.
5
+ */
6
+ export function invocationId() {
7
+ return globalThis.crypto.randomUUID();
8
+ }
9
+ /**
10
+ * Wrap a value and its metadata in a frozen result envelope.
11
+ *
12
+ * Both layers are frozen so downstream consumers cannot mutate an already reported
13
+ * invocation.
14
+ *
15
+ * @param value - The produced value.
16
+ * @param metadata - Invocation metadata describing the call.
17
+ * @returns A frozen `InvocationResult`.
18
+ */
3
19
  export function invocationResult(value, metadata) {
4
20
  return Object.freeze({ value, invocation: Object.freeze(metadata) });
5
21
  }
22
+ /**
23
+ * Normalize the positional tool-invocation shorthand used by App handlers.
24
+ *
25
+ * The shorthand only accepts exactly one request so a handler cannot silently drop
26
+ * additional tools; the request must carry a non-blank `toolId` and an explicit
27
+ * `input` property, which distinguishes "no input" from "input omitted".
28
+ *
29
+ * @param request - Candidate request supplied as a single argument.
30
+ * @param arity - Number of arguments the caller actually passed; must be 1.
31
+ * @returns A plain object with the four supported request fields.
32
+ * @throws TypeError When the arity or the request shape is invalid.
33
+ */
6
34
  export function toolInvocation(request, arity) {
7
- if (arity !== 1 || !request || typeof request !== 'object' || typeof request.toolId !== 'string' || !request.toolId.trim() || !('input' in request)) {
35
+ if (arity !== 1 ||
36
+ !request ||
37
+ typeof request !== 'object' ||
38
+ typeof request.toolId !== 'string' ||
39
+ !request.toolId.trim() ||
40
+ !('input' in request)) {
8
41
  throw new TypeError('Use one tool request with toolId and input');
9
42
  }
10
- return { toolId: request.toolId, input: request.input, diagnostics: request.diagnostics, signal: request.signal };
43
+ return {
44
+ toolId: request.toolId,
45
+ input: request.input,
46
+ diagnostics: request.diagnostics,
47
+ signal: request.signal,
48
+ };
11
49
  }
@@ -1 +1,9 @@
1
+ /**
2
+ * Throw a model protocol validation error.
3
+ *
4
+ * @param message - Primary issue message, always reported with code `MODEL_PROTOCOL`.
5
+ * @param reason - Optional secondary code for the same message, used to distinguish variants.
6
+ * @returns Never returns; the declared `never` return lets callers use it in expressions.
7
+ * @throws ValidationError carrying one or two issues.
8
+ */
1
9
  export declare function modelProtocolError(message: string, reason?: string): never;
@@ -1,4 +1,23 @@
1
+ /**
2
+ * Fail a model-facing protocol contract.
3
+ *
4
+ * Model output is untrusted input: violations are reported as `ValidationError`
5
+ * issues so callers can inspect every problem instead of catching a bare Error.
6
+ *
7
+ * Exports: `modelProtocolError`.
8
+ */
1
9
  import { ValidationError } from '../structs/errors.js';
10
+ /**
11
+ * Throw a model protocol validation error.
12
+ *
13
+ * @param message - Primary issue message, always reported with code `MODEL_PROTOCOL`.
14
+ * @param reason - Optional secondary code for the same message, used to distinguish variants.
15
+ * @returns Never returns; the declared `never` return lets callers use it in expressions.
16
+ * @throws ValidationError carrying one or two issues.
17
+ */
2
18
  export function modelProtocolError(message, reason) {
3
- throw new ValidationError([{ code: 'MODEL_PROTOCOL', message }, ...(reason ? [{ code: reason, message }] : [])]);
19
+ throw new ValidationError([
20
+ { code: 'MODEL_PROTOCOL', message },
21
+ ...(reason ? [{ code: reason, message }] : []),
22
+ ]);
4
23
  }
@@ -1 +1,17 @@
1
+ /**
2
+ * Structural object freezing for schema snapshots.
3
+ *
4
+ * JSON schemas are shared by definition, so a consumer that mutates a nested keyword
5
+ * would corrupt every other consumer. This deep freeze makes that attempt fail loudly.
6
+ *
7
+ * Exports: `freezeSchema`.
8
+ */
9
+ /**
10
+ * Recursively freeze an object graph.
11
+ *
12
+ * Arrays are objects, so they are covered as well. Already frozen nodes are skipped,
13
+ * which makes the walk safe on cyclic or shared sub-graphs and idempotent.
14
+ *
15
+ * @param value - Candidate node; primitives and non-objects are ignored.
16
+ */
1
17
  export declare function freezeSchema(value: unknown): void;
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Structural object freezing for schema snapshots.
3
+ *
4
+ * JSON schemas are shared by definition, so a consumer that mutates a nested keyword
5
+ * would corrupt every other consumer. This deep freeze makes that attempt fail loudly.
6
+ *
7
+ * Exports: `freezeSchema`.
8
+ */
9
+ /**
10
+ * Recursively freeze an object graph.
11
+ *
12
+ * Arrays are objects, so they are covered as well. Already frozen nodes are skipped,
13
+ * which makes the walk safe on cyclic or shared sub-graphs and idempotent.
14
+ *
15
+ * @param value - Candidate node; primitives and non-objects are ignored.
16
+ */
1
17
  export function freezeSchema(value) {
2
18
  if (!value || typeof value !== 'object' || Object.isFrozen(value))
3
19
  return;
@@ -1,2 +1,20 @@
1
- /** Observers receive detached data; uncloneable observations are skipped, never exposed by reference. */
1
+ /**
2
+ * Defensive delivery of observed values to App-supplied observers.
3
+ *
4
+ * Observation is optional and must never influence the observed operation, so the
5
+ * value is cloned, failures are swallowed and returned promises are consumed.
6
+ *
7
+ * Exports: `observeSafely`.
8
+ */
9
+ /**
10
+ * Deliver a detached copy of a value to an observer.
11
+ *
12
+ * The clone prevents an observer from mutating execution state through a shared
13
+ * reference. A value that cannot be structured-cloned is skipped entirely rather
14
+ * than handed over by reference.
15
+ *
16
+ * @param observe - Observer callback, if one is installed.
17
+ * @param value - Value to clone and deliver.
18
+ * @returns Nothing; the observer may run asynchronously after this returns.
19
+ */
2
20
  export declare function observeSafely<Value>(observe: ((value: Value) => void | Promise<void>) | undefined, value: Value): void;
@@ -1,4 +1,22 @@
1
- /** Observers receive detached data; uncloneable observations are skipped, never exposed by reference. */
1
+ /**
2
+ * Defensive delivery of observed values to App-supplied observers.
3
+ *
4
+ * Observation is optional and must never influence the observed operation, so the
5
+ * value is cloned, failures are swallowed and returned promises are consumed.
6
+ *
7
+ * Exports: `observeSafely`.
8
+ */
9
+ /**
10
+ * Deliver a detached copy of a value to an observer.
11
+ *
12
+ * The clone prevents an observer from mutating execution state through a shared
13
+ * reference. A value that cannot be structured-cloned is skipped entirely rather
14
+ * than handed over by reference.
15
+ *
16
+ * @param observe - Observer callback, if one is installed.
17
+ * @param value - Value to clone and deliver.
18
+ * @returns Nothing; the observer may run asynchronously after this returns.
19
+ */
2
20
  export function observeSafely(observe, value) {
3
21
  if (!observe)
4
22
  return;
@@ -7,5 +25,7 @@ export function observeSafely(observe, value) {
7
25
  if (pending)
8
26
  void Promise.resolve(pending).catch(() => { });
9
27
  }
10
- catch { /* Observation is independent of the operation. */ }
28
+ catch {
29
+ /* Observation is independent of the operation. */
30
+ }
11
31
  }