@jangts/agent-core 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (523) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/development/docs/api/reference.md +1907 -1874
  3. package/development/docs/api/support.md +27 -0
  4. package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
  5. package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
  6. package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
  7. package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
  8. package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
  9. package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
  10. package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
  11. package/development/skills/agent-core-app/templates/catalog.json +36 -22
  12. package/dist/cjs/capabilities/index.js +13 -0
  13. package/dist/cjs/capabilities/invocation.js +80 -10
  14. package/dist/cjs/capabilities/model.js +126 -13
  15. package/dist/cjs/capabilities/tool-runtime.js +64 -12
  16. package/dist/cjs/capabilities/tools.js +266 -31
  17. package/dist/cjs/context/assembly.js +46 -5
  18. package/dist/cjs/context/audit.js +31 -6
  19. package/dist/cjs/context/fragments.js +54 -11
  20. package/dist/cjs/context/index.js +12 -0
  21. package/dist/cjs/context/journal.js +84 -7
  22. package/dist/cjs/context/plan.js +30 -2
  23. package/dist/cjs/diagnostics/catalog.js +11 -3
  24. package/dist/cjs/diagnostics/index.js +149 -29
  25. package/dist/cjs/diagnostics/sub-flow.js +240 -40
  26. package/dist/cjs/errors.js +99 -17
  27. package/dist/cjs/execution/branch.js +20 -4
  28. package/dist/cjs/execution/engine.js +470 -56
  29. package/dist/cjs/execution/events.js +136 -18
  30. package/dist/cjs/execution/index.js +7 -0
  31. package/dist/cjs/execution/reporting.js +75 -6
  32. package/dist/cjs/execution/state.js +161 -22
  33. package/dist/cjs/execution/workflow.js +224 -32
  34. package/dist/cjs/index.js +18 -0
  35. package/dist/cjs/kits/aggregation.js +45 -3
  36. package/dist/cjs/kits/answering/batch.js +23 -4
  37. package/dist/cjs/kits/answering/check-result.js +31 -8
  38. package/dist/cjs/kits/answering/checks.js +24 -3
  39. package/dist/cjs/kits/answering/flow.js +192 -36
  40. package/dist/cjs/kits/answering/index.js +19 -1
  41. package/dist/cjs/kits/answering/tasks.js +88 -13
  42. package/dist/cjs/kits/artifacts.js +36 -4
  43. package/dist/cjs/kits/candidates.js +47 -5
  44. package/dist/cjs/kits/delivery.js +40 -5
  45. package/dist/cjs/kits/durable.js +155 -31
  46. package/dist/cjs/kits/evidence.js +66 -15
  47. package/dist/cjs/kits/family.js +152 -22
  48. package/dist/cjs/kits/index.js +12 -1
  49. package/dist/cjs/kits/inference.js +104 -16
  50. package/dist/cjs/kits/intents/catalog.js +67 -16
  51. package/dist/cjs/kits/intents/index.js +11 -0
  52. package/dist/cjs/kits/intents/registry.js +188 -43
  53. package/dist/cjs/kits/intents/scopes.js +215 -46
  54. package/dist/cjs/kits/interaction/command.js +140 -36
  55. package/dist/cjs/kits/interaction/commands.js +86 -11
  56. package/dist/cjs/kits/interaction/handlers.js +27 -10
  57. package/dist/cjs/kits/interaction/index.js +10 -0
  58. package/dist/cjs/kits/interaction/transfer.js +80 -14
  59. package/dist/cjs/kits/knowledge/catalog.js +62 -11
  60. package/dist/cjs/kits/knowledge/index.js +16 -1
  61. package/dist/cjs/kits/knowledge/publication.js +99 -23
  62. package/dist/cjs/kits/knowledge/sections.js +33 -4
  63. package/dist/cjs/kits/normalization.js +51 -7
  64. package/dist/cjs/kits/policies.js +79 -15
  65. package/dist/cjs/kits/presentation/events.js +54 -10
  66. package/dist/cjs/kits/presentation/index.js +24 -1
  67. package/dist/cjs/kits/presentation/outputs.js +176 -38
  68. package/dist/cjs/kits/presentation/templates.js +33 -5
  69. package/dist/cjs/kits/presentation/variants.js +31 -2
  70. package/dist/cjs/kits/projection.js +63 -8
  71. package/dist/cjs/kits/rank-fusion.js +27 -4
  72. package/dist/cjs/kits/reflection-log-source.js +89 -16
  73. package/dist/cjs/kits/reflection.js +234 -60
  74. package/dist/cjs/kits/retrieval.js +98 -18
  75. package/dist/cjs/kits/search.js +180 -27
  76. package/dist/cjs/kits/text-skills.js +104 -19
  77. package/dist/cjs/kits/tools.js +415 -74
  78. package/dist/cjs/kits/vector-search.js +50 -16
  79. package/dist/cjs/mock/node.js +7 -1
  80. package/dist/cjs/mock/web.js +7 -1
  81. package/dist/cjs/mock.js +7 -1
  82. package/dist/cjs/model/binding.js +68 -17
  83. package/dist/cjs/model/call-budget.js +45 -4
  84. package/dist/cjs/model/decision-retry.js +19 -1
  85. package/dist/cjs/model/defaults.js +27 -4
  86. package/dist/cjs/model/index.js +7 -0
  87. package/dist/cjs/model/interactions/arguments.js +36 -1
  88. package/dist/cjs/model/interactions/json-object.js +48 -12
  89. package/dist/cjs/model/interactions/native-functions.js +52 -10
  90. package/dist/cjs/model/message-diagnostics.js +17 -4
  91. package/dist/cjs/model/options.js +9 -1
  92. package/dist/cjs/model/preparation.js +86 -12
  93. package/dist/cjs/model/runner.js +413 -79
  94. package/dist/cjs/model/selection-transport.js +48 -8
  95. package/dist/cjs/model/settings.js +67 -13
  96. package/dist/cjs/model/token-budget.js +69 -11
  97. package/dist/cjs/model/transports.js +59 -6
  98. package/dist/cjs/structs/common.js +11 -0
  99. package/dist/cjs/structs/debug.js +34 -5
  100. package/dist/cjs/structs/errors.js +26 -1
  101. package/dist/cjs/structs/index.js +11 -1
  102. package/dist/cjs/structs/kits/durable.js +7 -0
  103. package/dist/cjs/structs/kits/family.js +1 -0
  104. package/dist/cjs/structs/kits/interaction.js +8 -1
  105. package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
  106. package/dist/cjs/structs/kits/reflection.js +18 -3
  107. package/dist/cjs/structs/model/chat-provider.js +6 -0
  108. package/dist/cjs/structs/support/model/completion.js +2 -0
  109. package/dist/cjs/structs/support/model/messages.js +2 -0
  110. package/dist/cjs/support/capabilities.js +43 -6
  111. package/dist/cjs/support/context/assembly.js +88 -16
  112. package/dist/cjs/support/context/compression.js +48 -6
  113. package/dist/cjs/support/context/fragments.js +6 -0
  114. package/dist/cjs/support/context/history.js +36 -1
  115. package/dist/cjs/support/context/index.js +11 -0
  116. package/dist/cjs/support/context/nodes.js +164 -35
  117. package/dist/cjs/support/context/processing.js +319 -61
  118. package/dist/cjs/support/context/selection-policy.js +98 -21
  119. package/dist/cjs/support/context/selection.js +61 -10
  120. package/dist/cjs/support/context/snapshot.js +29 -7
  121. package/dist/cjs/support/context/strategies.js +120 -28
  122. package/dist/cjs/support/index.js +9 -1
  123. package/dist/cjs/support/model/capabilities.js +20 -1
  124. package/dist/cjs/support/model/chat-completions.js +92 -20
  125. package/dist/cjs/support/model/children.js +34 -6
  126. package/dist/cjs/support/model/compatible-provider.js +189 -59
  127. package/dist/cjs/support/model/completion/calls.js +61 -0
  128. package/dist/cjs/support/model/completion/default.js +32 -0
  129. package/dist/cjs/support/model/completion/index.js +28 -0
  130. package/dist/cjs/support/model/completion/session.js +102 -0
  131. package/dist/cjs/support/model/index.js +12 -0
  132. package/dist/cjs/support/model/interactions/index.js +12 -1
  133. package/dist/cjs/support/model/interactions/json-object.js +6 -0
  134. package/dist/cjs/support/model/interactions/native-functions.js +6 -0
  135. package/dist/cjs/support/model/observer.js +32 -6
  136. package/dist/cjs/support/model/preview-rules.js +66 -16
  137. package/dist/cjs/support/model/reply-preview.js +77 -17
  138. package/dist/cjs/support/model/stage-transport.js +33 -7
  139. package/dist/cjs/support/model/strategies.js +75 -14
  140. package/dist/cjs/support/model/transports.js +53 -11
  141. package/dist/cjs/support/registration.js +49 -7
  142. package/dist/cjs/support/schema.js +46 -4
  143. package/dist/cjs/support/stream-events.js +60 -8
  144. package/dist/cjs/support/tool-runtime.js +6 -0
  145. package/dist/cjs/support/tools.js +79 -10
  146. package/dist/cjs/support/transport/index.js +7 -0
  147. package/dist/cjs/support/transport/json.js +28 -4
  148. package/dist/cjs/support/transport/sse.js +25 -2
  149. package/dist/cjs/utils/break-observer.js +20 -2
  150. package/dist/cjs/utils/cancellation.js +77 -9
  151. package/dist/cjs/utils/catalog.js +19 -4
  152. package/dist/cjs/utils/debug.js +14 -2
  153. package/dist/cjs/utils/index.js +8 -0
  154. package/dist/cjs/utils/interaction-definition.js +26 -6
  155. package/dist/cjs/utils/invocation.js +42 -4
  156. package/dist/cjs/utils/model-protocol.js +20 -1
  157. package/dist/cjs/utils/object.js +16 -0
  158. package/dist/cjs/utils/observer.js +22 -2
  159. package/dist/cjs/utils/protocol-registry.js +47 -4
  160. package/dist/cjs/utils/query-key.js +21 -2
  161. package/dist/cjs/utils/registration.js +18 -2
  162. package/dist/cjs/utils/rules.js +39 -11
  163. package/dist/cjs/utils/schema-adapter.js +25 -2
  164. package/dist/cjs/utils/synchronous.js +64 -7
  165. package/dist/cjs/utils/text.js +15 -1
  166. package/dist/esm/capabilities/index.d.ts +13 -0
  167. package/dist/esm/capabilities/index.js +13 -0
  168. package/dist/esm/capabilities/invocation.d.ts +16 -2
  169. package/dist/esm/capabilities/invocation.js +80 -10
  170. package/dist/esm/capabilities/model.d.ts +68 -1
  171. package/dist/esm/capabilities/model.js +126 -13
  172. package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
  173. package/dist/esm/capabilities/tool-runtime.js +64 -12
  174. package/dist/esm/capabilities/tools.d.ts +96 -3
  175. package/dist/esm/capabilities/tools.js +267 -32
  176. package/dist/esm/context/assembly.d.ts +13 -2
  177. package/dist/esm/context/assembly.js +46 -5
  178. package/dist/esm/context/audit.d.ts +23 -1
  179. package/dist/esm/context/audit.js +31 -6
  180. package/dist/esm/context/fragments.d.ts +37 -3
  181. package/dist/esm/context/fragments.js +54 -11
  182. package/dist/esm/context/index.d.ts +12 -0
  183. package/dist/esm/context/index.js +12 -0
  184. package/dist/esm/context/journal.d.ts +32 -1
  185. package/dist/esm/context/journal.js +84 -7
  186. package/dist/esm/context/plan.d.ts +11 -1
  187. package/dist/esm/context/plan.js +30 -2
  188. package/dist/esm/diagnostics/catalog.js +11 -3
  189. package/dist/esm/diagnostics/index.d.ts +30 -2
  190. package/dist/esm/diagnostics/index.js +149 -29
  191. package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
  192. package/dist/esm/diagnostics/sub-flow.js +240 -40
  193. package/dist/esm/errors.d.ts +22 -2
  194. package/dist/esm/errors.js +99 -17
  195. package/dist/esm/execution/branch.d.ts +19 -1
  196. package/dist/esm/execution/branch.js +20 -4
  197. package/dist/esm/execution/engine.d.ts +291 -5
  198. package/dist/esm/execution/engine.js +471 -57
  199. package/dist/esm/execution/events.d.ts +16 -2
  200. package/dist/esm/execution/events.js +136 -18
  201. package/dist/esm/execution/index.d.ts +7 -0
  202. package/dist/esm/execution/index.js +7 -0
  203. package/dist/esm/execution/reporting.d.ts +49 -1
  204. package/dist/esm/execution/reporting.js +75 -6
  205. package/dist/esm/execution/state.d.ts +126 -10
  206. package/dist/esm/execution/state.js +161 -22
  207. package/dist/esm/execution/workflow.d.ts +121 -3
  208. package/dist/esm/execution/workflow.js +224 -32
  209. package/dist/esm/index.d.ts +17 -1
  210. package/dist/esm/index.js +18 -0
  211. package/dist/esm/kits/aggregation.d.ts +34 -2
  212. package/dist/esm/kits/aggregation.js +45 -3
  213. package/dist/esm/kits/answering/batch.d.ts +17 -0
  214. package/dist/esm/kits/answering/batch.js +23 -4
  215. package/dist/esm/kits/answering/check-result.d.ts +18 -1
  216. package/dist/esm/kits/answering/check-result.js +31 -8
  217. package/dist/esm/kits/answering/checks.d.ts +11 -0
  218. package/dist/esm/kits/answering/checks.js +24 -3
  219. package/dist/esm/kits/answering/flow.d.ts +25 -2
  220. package/dist/esm/kits/answering/flow.js +192 -36
  221. package/dist/esm/kits/answering/index.d.ts +12 -0
  222. package/dist/esm/kits/answering/index.js +19 -1
  223. package/dist/esm/kits/answering/tasks.d.ts +32 -1
  224. package/dist/esm/kits/answering/tasks.js +88 -13
  225. package/dist/esm/kits/artifacts.d.ts +11 -0
  226. package/dist/esm/kits/artifacts.js +36 -4
  227. package/dist/esm/kits/candidates.d.ts +23 -1
  228. package/dist/esm/kits/candidates.js +47 -5
  229. package/dist/esm/kits/delivery.d.ts +34 -0
  230. package/dist/esm/kits/delivery.js +40 -5
  231. package/dist/esm/kits/durable.d.ts +19 -0
  232. package/dist/esm/kits/durable.js +155 -31
  233. package/dist/esm/kits/evidence.d.ts +28 -5
  234. package/dist/esm/kits/evidence.js +66 -15
  235. package/dist/esm/kits/family.d.ts +17 -1
  236. package/dist/esm/kits/family.js +152 -22
  237. package/dist/esm/kits/index.d.ts +12 -1
  238. package/dist/esm/kits/index.js +12 -1
  239. package/dist/esm/kits/inference.d.ts +64 -0
  240. package/dist/esm/kits/inference.js +104 -16
  241. package/dist/esm/kits/intents/catalog.d.ts +13 -1
  242. package/dist/esm/kits/intents/catalog.js +67 -16
  243. package/dist/esm/kits/intents/index.d.ts +11 -0
  244. package/dist/esm/kits/intents/index.js +11 -0
  245. package/dist/esm/kits/intents/registry.d.ts +61 -3
  246. package/dist/esm/kits/intents/registry.js +188 -43
  247. package/dist/esm/kits/intents/scopes.d.ts +73 -3
  248. package/dist/esm/kits/intents/scopes.js +215 -46
  249. package/dist/esm/kits/interaction/command.d.ts +38 -4
  250. package/dist/esm/kits/interaction/command.js +140 -36
  251. package/dist/esm/kits/interaction/commands.d.ts +66 -2
  252. package/dist/esm/kits/interaction/commands.js +86 -11
  253. package/dist/esm/kits/interaction/handlers.d.ts +19 -2
  254. package/dist/esm/kits/interaction/handlers.js +27 -10
  255. package/dist/esm/kits/interaction/index.d.ts +10 -0
  256. package/dist/esm/kits/interaction/index.js +10 -0
  257. package/dist/esm/kits/interaction/transfer.d.ts +39 -2
  258. package/dist/esm/kits/interaction/transfer.js +80 -14
  259. package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
  260. package/dist/esm/kits/knowledge/catalog.js +62 -11
  261. package/dist/esm/kits/knowledge/index.d.ts +11 -0
  262. package/dist/esm/kits/knowledge/index.js +16 -1
  263. package/dist/esm/kits/knowledge/publication.d.ts +15 -1
  264. package/dist/esm/kits/knowledge/publication.js +99 -23
  265. package/dist/esm/kits/knowledge/sections.d.ts +31 -1
  266. package/dist/esm/kits/knowledge/sections.js +33 -4
  267. package/dist/esm/kits/normalization.d.ts +25 -2
  268. package/dist/esm/kits/normalization.js +51 -7
  269. package/dist/esm/kits/policies.d.ts +26 -3
  270. package/dist/esm/kits/policies.js +79 -15
  271. package/dist/esm/kits/presentation/events.d.ts +51 -4
  272. package/dist/esm/kits/presentation/events.js +54 -10
  273. package/dist/esm/kits/presentation/index.d.ts +12 -0
  274. package/dist/esm/kits/presentation/index.js +25 -2
  275. package/dist/esm/kits/presentation/outputs.d.ts +30 -1
  276. package/dist/esm/kits/presentation/outputs.js +176 -38
  277. package/dist/esm/kits/presentation/templates.d.ts +32 -3
  278. package/dist/esm/kits/presentation/templates.js +33 -5
  279. package/dist/esm/kits/presentation/variants.d.ts +29 -0
  280. package/dist/esm/kits/presentation/variants.js +31 -2
  281. package/dist/esm/kits/projection.d.ts +42 -5
  282. package/dist/esm/kits/projection.js +63 -8
  283. package/dist/esm/kits/rank-fusion.d.ts +21 -1
  284. package/dist/esm/kits/rank-fusion.js +28 -5
  285. package/dist/esm/kits/reflection-log-source.d.ts +28 -1
  286. package/dist/esm/kits/reflection-log-source.js +89 -16
  287. package/dist/esm/kits/reflection.d.ts +17 -1
  288. package/dist/esm/kits/reflection.js +235 -61
  289. package/dist/esm/kits/retrieval.d.ts +18 -2
  290. package/dist/esm/kits/retrieval.js +98 -18
  291. package/dist/esm/kits/search.d.ts +56 -3
  292. package/dist/esm/kits/search.js +180 -27
  293. package/dist/esm/kits/text-skills.d.ts +16 -2
  294. package/dist/esm/kits/text-skills.js +104 -19
  295. package/dist/esm/kits/tools.d.ts +122 -2
  296. package/dist/esm/kits/tools.js +416 -74
  297. package/dist/esm/kits/vector-search.d.ts +47 -1
  298. package/dist/esm/kits/vector-search.js +51 -17
  299. package/dist/esm/mock/node.d.ts +7 -0
  300. package/dist/esm/mock/node.js +7 -1
  301. package/dist/esm/mock/web.d.ts +7 -0
  302. package/dist/esm/mock/web.js +7 -1
  303. package/dist/esm/mock.d.ts +7 -0
  304. package/dist/esm/mock.js +7 -1
  305. package/dist/esm/model/binding.d.ts +32 -3
  306. package/dist/esm/model/binding.js +68 -17
  307. package/dist/esm/model/call-budget.d.ts +30 -2
  308. package/dist/esm/model/call-budget.js +45 -4
  309. package/dist/esm/model/decision-retry.d.ts +10 -1
  310. package/dist/esm/model/decision-retry.js +19 -1
  311. package/dist/esm/model/defaults.d.ts +13 -2
  312. package/dist/esm/model/defaults.js +27 -4
  313. package/dist/esm/model/index.d.ts +7 -0
  314. package/dist/esm/model/index.js +7 -0
  315. package/dist/esm/model/interactions/arguments.d.ts +27 -0
  316. package/dist/esm/model/interactions/arguments.js +36 -1
  317. package/dist/esm/model/interactions/json-object.d.ts +7 -1
  318. package/dist/esm/model/interactions/json-object.js +48 -12
  319. package/dist/esm/model/interactions/native-functions.d.ts +6 -0
  320. package/dist/esm/model/interactions/native-functions.js +52 -10
  321. package/dist/esm/model/message-diagnostics.d.ts +17 -1
  322. package/dist/esm/model/message-diagnostics.js +17 -4
  323. package/dist/esm/model/options.d.ts +18 -1
  324. package/dist/esm/model/options.js +9 -1
  325. package/dist/esm/model/preparation.d.ts +30 -2
  326. package/dist/esm/model/preparation.js +86 -12
  327. package/dist/esm/model/runner.d.ts +129 -5
  328. package/dist/esm/model/runner.js +414 -80
  329. package/dist/esm/model/selection-transport.d.ts +14 -1
  330. package/dist/esm/model/selection-transport.js +48 -8
  331. package/dist/esm/model/settings.d.ts +11 -0
  332. package/dist/esm/model/settings.js +67 -13
  333. package/dist/esm/model/token-budget.d.ts +59 -1
  334. package/dist/esm/model/token-budget.js +69 -11
  335. package/dist/esm/model/transports.d.ts +20 -2
  336. package/dist/esm/model/transports.js +59 -6
  337. package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
  338. package/dist/esm/structs/capabilities/model.d.ts +27 -0
  339. package/dist/esm/structs/capabilities/tools.d.ts +38 -0
  340. package/dist/esm/structs/common.d.ts +62 -2
  341. package/dist/esm/structs/common.js +11 -0
  342. package/dist/esm/structs/context/fragments.d.ts +28 -0
  343. package/dist/esm/structs/context/journal.d.ts +28 -3
  344. package/dist/esm/structs/context/processing.d.ts +11 -0
  345. package/dist/esm/structs/debug.d.ts +58 -1
  346. package/dist/esm/structs/debug.js +34 -5
  347. package/dist/esm/structs/diagnostics.d.ts +119 -1
  348. package/dist/esm/structs/errors.d.ts +42 -1
  349. package/dist/esm/structs/errors.js +26 -1
  350. package/dist/esm/structs/execution/engine.d.ts +24 -1
  351. package/dist/esm/structs/execution/events.d.ts +12 -0
  352. package/dist/esm/structs/execution/workflow.d.ts +71 -0
  353. package/dist/esm/structs/index.d.ts +11 -1
  354. package/dist/esm/structs/index.js +11 -1
  355. package/dist/esm/structs/invocation.d.ts +30 -0
  356. package/dist/esm/structs/kits/aggregation.d.ts +12 -0
  357. package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
  358. package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
  359. package/dist/esm/structs/kits/answering/state.d.ts +21 -0
  360. package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
  361. package/dist/esm/structs/kits/artifacts.d.ts +14 -0
  362. package/dist/esm/structs/kits/candidates.d.ts +19 -0
  363. package/dist/esm/structs/kits/delivery.d.ts +22 -0
  364. package/dist/esm/structs/kits/durable.d.ts +56 -3
  365. package/dist/esm/structs/kits/durable.js +7 -0
  366. package/dist/esm/structs/kits/evidence.d.ts +23 -0
  367. package/dist/esm/structs/kits/family.d.ts +49 -1
  368. package/dist/esm/structs/kits/family.js +1 -0
  369. package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
  370. package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
  371. package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
  372. package/dist/esm/structs/kits/interaction.d.ts +64 -0
  373. package/dist/esm/structs/kits/interaction.js +8 -1
  374. package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
  375. package/dist/esm/structs/kits/knowledge-publication.js +1 -0
  376. package/dist/esm/structs/kits/knowledge.d.ts +39 -2
  377. package/dist/esm/structs/kits/normalization.d.ts +15 -0
  378. package/dist/esm/structs/kits/policies.d.ts +25 -1
  379. package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
  380. package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
  381. package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
  382. package/dist/esm/structs/kits/projection.d.ts +21 -0
  383. package/dist/esm/structs/kits/reflection.d.ts +61 -2
  384. package/dist/esm/structs/kits/reflection.js +18 -3
  385. package/dist/esm/structs/kits/retrieval.d.ts +38 -0
  386. package/dist/esm/structs/kits/search.d.ts +22 -0
  387. package/dist/esm/structs/kits/text-skills.d.ts +36 -0
  388. package/dist/esm/structs/kits/tools.d.ts +87 -0
  389. package/dist/esm/structs/model/chat-provider.d.ts +24 -1
  390. package/dist/esm/structs/model/chat-provider.js +6 -0
  391. package/dist/esm/structs/model/interactions.d.ts +38 -0
  392. package/dist/esm/structs/model/messages.d.ts +30 -0
  393. package/dist/esm/structs/model/runtime.d.ts +104 -6
  394. package/dist/esm/structs/support/capabilities.d.ts +19 -2
  395. package/dist/esm/structs/support/context-processing.d.ts +88 -9
  396. package/dist/esm/structs/support/context.d.ts +29 -1
  397. package/dist/esm/structs/support/model/completion.d.ts +50 -0
  398. package/dist/esm/structs/support/model/completion.js +1 -0
  399. package/dist/esm/structs/support/model/interactions.d.ts +13 -1
  400. package/dist/esm/structs/support/model/messages.d.ts +52 -0
  401. package/dist/esm/structs/support/model/messages.js +1 -0
  402. package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
  403. package/dist/esm/structs/support/model/provider.d.ts +71 -6
  404. package/dist/esm/structs/support/registration.d.ts +13 -0
  405. package/dist/esm/structs/support/schema.d.ts +14 -0
  406. package/dist/esm/structs/support/tools.d.ts +28 -0
  407. package/dist/esm/structs/support/transport/json.d.ts +16 -0
  408. package/dist/esm/structs/support/transport/sse.d.ts +15 -0
  409. package/dist/esm/structs/utils/rules.d.ts +19 -0
  410. package/dist/esm/support/capabilities.d.ts +25 -2
  411. package/dist/esm/support/capabilities.js +43 -6
  412. package/dist/esm/support/context/assembly.d.ts +35 -4
  413. package/dist/esm/support/context/assembly.js +88 -16
  414. package/dist/esm/support/context/compression.d.ts +17 -1
  415. package/dist/esm/support/context/compression.js +48 -6
  416. package/dist/esm/support/context/fragments.d.ts +6 -0
  417. package/dist/esm/support/context/fragments.js +6 -0
  418. package/dist/esm/support/context/history.d.ts +43 -0
  419. package/dist/esm/support/context/history.js +36 -1
  420. package/dist/esm/support/context/index.d.ts +13 -2
  421. package/dist/esm/support/context/index.js +12 -1
  422. package/dist/esm/support/context/nodes.d.ts +49 -3
  423. package/dist/esm/support/context/nodes.js +165 -36
  424. package/dist/esm/support/context/processing.d.ts +145 -1
  425. package/dist/esm/support/context/processing.js +320 -62
  426. package/dist/esm/support/context/selection-policy.d.ts +42 -2
  427. package/dist/esm/support/context/selection-policy.js +98 -21
  428. package/dist/esm/support/context/selection.d.ts +14 -1
  429. package/dist/esm/support/context/selection.js +61 -10
  430. package/dist/esm/support/context/snapshot.d.ts +23 -1
  431. package/dist/esm/support/context/snapshot.js +29 -7
  432. package/dist/esm/support/context/strategies.d.ts +35 -2
  433. package/dist/esm/support/context/strategies.js +120 -28
  434. package/dist/esm/support/index.d.ts +9 -1
  435. package/dist/esm/support/index.js +9 -1
  436. package/dist/esm/support/model/capabilities.d.ts +10 -0
  437. package/dist/esm/support/model/capabilities.js +20 -1
  438. package/dist/esm/support/model/chat-completions.d.ts +44 -15
  439. package/dist/esm/support/model/chat-completions.js +92 -20
  440. package/dist/esm/support/model/children.d.ts +32 -2
  441. package/dist/esm/support/model/children.js +34 -6
  442. package/dist/esm/support/model/compatible-provider.d.ts +29 -3
  443. package/dist/esm/support/model/compatible-provider.js +190 -60
  444. package/dist/esm/support/model/completion/calls.d.ts +40 -0
  445. package/dist/esm/support/model/completion/calls.js +58 -0
  446. package/dist/esm/support/model/completion/default.d.ts +10 -0
  447. package/dist/esm/support/model/completion/default.js +29 -0
  448. package/dist/esm/support/model/completion/index.d.ts +10 -0
  449. package/dist/esm/support/model/completion/index.js +22 -0
  450. package/dist/esm/support/model/completion/session.d.ts +11 -0
  451. package/dist/esm/support/model/completion/session.js +99 -0
  452. package/dist/esm/support/model/index.d.ts +14 -0
  453. package/dist/esm/support/model/index.js +12 -0
  454. package/dist/esm/support/model/interactions/index.d.ts +1 -1
  455. package/dist/esm/support/model/interactions/index.js +12 -1
  456. package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
  457. package/dist/esm/support/model/interactions/json-object.js +6 -0
  458. package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
  459. package/dist/esm/support/model/interactions/native-functions.js +6 -0
  460. package/dist/esm/support/model/observer.d.ts +25 -2
  461. package/dist/esm/support/model/observer.js +32 -6
  462. package/dist/esm/support/model/preview-rules.d.ts +20 -2
  463. package/dist/esm/support/model/preview-rules.js +66 -16
  464. package/dist/esm/support/model/reply-preview.d.ts +15 -1
  465. package/dist/esm/support/model/reply-preview.js +77 -17
  466. package/dist/esm/support/model/stage-transport.d.ts +9 -1
  467. package/dist/esm/support/model/stage-transport.js +33 -7
  468. package/dist/esm/support/model/strategies.d.ts +24 -2
  469. package/dist/esm/support/model/strategies.js +75 -14
  470. package/dist/esm/support/model/transports.d.ts +17 -1
  471. package/dist/esm/support/model/transports.js +53 -11
  472. package/dist/esm/support/registration.d.ts +20 -1
  473. package/dist/esm/support/registration.js +49 -7
  474. package/dist/esm/support/schema.d.ts +31 -1
  475. package/dist/esm/support/schema.js +46 -4
  476. package/dist/esm/support/stream-events.d.ts +22 -1
  477. package/dist/esm/support/stream-events.js +60 -8
  478. package/dist/esm/support/tool-runtime.d.ts +6 -0
  479. package/dist/esm/support/tool-runtime.js +6 -0
  480. package/dist/esm/support/tools.d.ts +22 -0
  481. package/dist/esm/support/tools.js +79 -10
  482. package/dist/esm/support/transport/index.d.ts +7 -0
  483. package/dist/esm/support/transport/index.js +7 -0
  484. package/dist/esm/support/transport/json.d.ts +29 -2
  485. package/dist/esm/support/transport/json.js +28 -4
  486. package/dist/esm/support/transport/sse.d.ts +31 -1
  487. package/dist/esm/support/transport/sse.js +25 -2
  488. package/dist/esm/types.d.ts +9 -1
  489. package/dist/esm/utils/break-observer.d.ts +27 -2
  490. package/dist/esm/utils/break-observer.js +20 -2
  491. package/dist/esm/utils/cancellation.d.ts +56 -5
  492. package/dist/esm/utils/cancellation.js +77 -9
  493. package/dist/esm/utils/catalog.d.ts +20 -1
  494. package/dist/esm/utils/catalog.js +19 -4
  495. package/dist/esm/utils/debug.d.ts +20 -1
  496. package/dist/esm/utils/debug.js +14 -2
  497. package/dist/esm/utils/index.d.ts +8 -0
  498. package/dist/esm/utils/index.js +8 -0
  499. package/dist/esm/utils/interaction-definition.d.ts +18 -1
  500. package/dist/esm/utils/interaction-definition.js +26 -6
  501. package/dist/esm/utils/invocation.d.ts +36 -1
  502. package/dist/esm/utils/invocation.js +42 -4
  503. package/dist/esm/utils/model-protocol.d.ts +8 -0
  504. package/dist/esm/utils/model-protocol.js +20 -1
  505. package/dist/esm/utils/object.d.ts +16 -0
  506. package/dist/esm/utils/object.js +16 -0
  507. package/dist/esm/utils/observer.d.ts +19 -1
  508. package/dist/esm/utils/observer.js +22 -2
  509. package/dist/esm/utils/protocol-registry.d.ts +38 -1
  510. package/dist/esm/utils/protocol-registry.js +47 -4
  511. package/dist/esm/utils/query-key.d.ts +11 -1
  512. package/dist/esm/utils/query-key.js +21 -2
  513. package/dist/esm/utils/registration.d.ts +34 -2
  514. package/dist/esm/utils/registration.js +18 -2
  515. package/dist/esm/utils/rules.d.ts +81 -4
  516. package/dist/esm/utils/rules.js +39 -11
  517. package/dist/esm/utils/schema-adapter.d.ts +12 -1
  518. package/dist/esm/utils/schema-adapter.js +25 -2
  519. package/dist/esm/utils/synchronous.d.ts +60 -4
  520. package/dist/esm/utils/synchronous.js +64 -7
  521. package/dist/esm/utils/text.d.ts +15 -1
  522. package/dist/esm/utils/text.js +15 -1
  523. package/package.json +3 -2
@@ -1,29 +1,75 @@
1
+ /**
2
+ * Vector Search Kit: exact cosine search over a small, App-owned embedded corpus.
3
+ *
4
+ * Place in the package: an optional App-side library. The Kit stores vectors and computes
5
+ * scores; embeddings, document identity, metadata and persistence stay with the App. The
6
+ * corpus is held in memory and scanned exhaustively, so it suits bounded sets only.
7
+ *
8
+ * Exports: `VectorSearch`, `VectorSearchSpace`, `VectorSearchQuery`, `VectorSearchHit`.
9
+ */
1
10
  import type { SearchHit } from '../structs/common.js';
11
+ /** Embedding space identity and width; vectors from another space must never be mixed in. */
2
12
  export interface VectorSearchSpace {
13
+ /** Non-blank space name, for example `model@revision`; reported back by `VectorSearch`. */
3
14
  readonly identity: string;
15
+ /** Expected vector length, 1..16384. */
4
16
  readonly dimensions: number;
5
17
  }
18
+ /** One search hit; the document is a cloned snapshot, not the indexed instance. */
6
19
  export interface VectorSearchHit<Document> extends SearchHit<Document> {
7
20
  }
21
+ /** Search options excluding the query vector, which `search` takes alongside them. */
8
22
  export interface VectorSearchQuery<Document> {
23
+ /** Maximum hits returned, 1..1000. */
9
24
  readonly limit: number;
25
+ /** Synchronous predicate over a document snapshot; false excludes the candidate. */
10
26
  readonly filter: (document: Readonly<Document>) => boolean;
27
+ /** Minimum cosine score in [-1, 1]; defaults to -1, which keeps every candidate. */
11
28
  readonly minScore?: number;
29
+ /** Optional group key; only the best hit per group is kept, defaulting to the document id. */
12
30
  readonly groupBy?: (document: Readonly<Document>) => string;
13
31
  }
14
- /** Exact cosine search for a bounded embedded corpus. Identity and metadata are App-owned. */
32
+ /**
33
+ * Exact cosine search for a bounded embedded corpus. Identity and metadata are App-owned.
34
+ *
35
+ * Vectors arrive as plain arrays and are stored normalized in `Float32Array` form, so query
36
+ * time only needs a dot product per candidate.
37
+ */
15
38
  export declare class VectorSearch<Document extends {
16
39
  id: string;
17
40
  }> {
18
41
  private readonly entries;
42
+ /** The declared space; compare it before mixing vectors from another source. */
19
43
  readonly space: VectorSearchSpace;
44
+ /**
45
+ * @param space - Non-blank identity and dimensions (1..16384) of the corpus.
46
+ * @throws TypeError When the space declaration is invalid.
47
+ */
20
48
  constructor(space: VectorSearchSpace);
49
+ /**
50
+ * Insert or replace one document and its embedding.
51
+ *
52
+ * @param document - Document with a non-blank string `id`; it is cloned before being stored.
53
+ * @param vector - Raw vector for this space.
54
+ * @throws TypeError For a blank/missing id, a vector of the wrong width, a non-finite
55
+ * component, or an all-zero vector (cosine is undefined for it).
56
+ */
21
57
  upsert({ document, vector }: {
22
58
  document: Document;
23
59
  vector: readonly number[];
24
60
  }): void;
61
+ /** Remove one document; returns whether it was present. */
25
62
  remove(id: string): boolean;
63
+ /** Drop the whole corpus while keeping the declared space. */
26
64
  clear(): void;
65
+ /**
66
+ * Score every candidate and return the best hits.
67
+ *
68
+ * @param options - Query vector plus limit, filter, minimum score and optional grouping.
69
+ * @returns At most `limit` hits, best score first, ties broken by id.
70
+ * @throws TypeError For an invalid limit, a missing filter, an out-of-range `minScore`, a
71
+ * vector the space rejects, a non-synchronous filter or grouper, or a non-string group.
72
+ */
27
73
  search(options: VectorSearchQuery<Document> & {
28
74
  vector: readonly number[];
29
75
  }): VectorSearchHit<Document>[];
@@ -1,51 +1,87 @@
1
1
  import { synchronous, booleanResult } from '../utils/synchronous.js';
2
- import { breakWhile } from "../utils/rules.js";
2
+ import { breakWhile } from '../utils/rules.js';
3
+ /**
4
+ * Validate a vector and normalize it to unit length.
5
+ *
6
+ * Scaling by the largest component first keeps the squared sum inside the float range for
7
+ * long vectors, so normalization cannot overflow to Infinity.
8
+ */
3
9
  function normalize(vector, dimensions) {
4
10
  breakWhile(!Array.isArray(vector) ||
5
11
  vector.length !== dimensions ||
6
- Array.from(vector).some((n) => typeof n !== "number" || !Number.isFinite(n)), "Invalid vector dimensions or values");
12
+ Array.from(vector).some((n) => typeof n !== 'number' || !Number.isFinite(n)), 'Invalid vector dimensions or values');
7
13
  const scale = Math.max(...vector.map(Math.abs));
8
- breakWhile(scale === 0, "Zero vector cannot be searched");
14
+ breakWhile(scale === 0, 'Zero vector cannot be searched');
9
15
  const norm = Math.sqrt(vector.reduce((sum, n) => sum + (n / scale) ** 2, 0));
10
16
  return Float32Array.from(vector, (n) => n / scale / norm);
11
17
  }
12
- /** Exact cosine search for a bounded embedded corpus. Identity and metadata are App-owned. */
18
+ /**
19
+ * Exact cosine search for a bounded embedded corpus. Identity and metadata are App-owned.
20
+ *
21
+ * Vectors arrive as plain arrays and are stored normalized in `Float32Array` form, so query
22
+ * time only needs a dot product per candidate.
23
+ */
13
24
  export class VectorSearch {
14
25
  entries = new Map();
26
+ /** The declared space; compare it before mixing vectors from another source. */
15
27
  space;
28
+ /**
29
+ * @param space - Non-blank identity and dimensions (1..16384) of the corpus.
30
+ * @throws TypeError When the space declaration is invalid.
31
+ */
16
32
  constructor(space) {
17
33
  breakWhile(!space.identity?.trim() ||
18
34
  !Number.isSafeInteger(space.dimensions) ||
19
35
  space.dimensions < 1 ||
20
- space.dimensions > 16384, "Invalid vector space");
36
+ space.dimensions > 16384, 'Invalid vector space');
21
37
  this.space = Object.freeze({ identity: space.identity, dimensions: space.dimensions });
22
38
  }
39
+ /**
40
+ * Insert or replace one document and its embedding.
41
+ *
42
+ * @param document - Document with a non-blank string `id`; it is cloned before being stored.
43
+ * @param vector - Raw vector for this space.
44
+ * @throws TypeError For a blank/missing id, a vector of the wrong width, a non-finite
45
+ * component, or an all-zero vector (cosine is undefined for it).
46
+ */
23
47
  upsert({ document, vector }) {
24
- breakWhile(!document?.id?.trim(), "Invalid vector document id");
48
+ breakWhile(!document?.id?.trim(), 'Invalid vector document id');
25
49
  this.entries.set(document.id, {
26
50
  document: structuredClone(document),
27
51
  vector: normalize(vector, this.space.dimensions),
28
52
  });
29
53
  }
54
+ /** Remove one document; returns whether it was present. */
30
55
  remove(id) {
31
56
  return this.entries.delete(id);
32
57
  }
58
+ /** Drop the whole corpus while keeping the declared space. */
33
59
  clear() {
34
60
  this.entries.clear();
35
61
  }
62
+ /**
63
+ * Score every candidate and return the best hits.
64
+ *
65
+ * @param options - Query vector plus limit, filter, minimum score and optional grouping.
66
+ * @returns At most `limit` hits, best score first, ties broken by id.
67
+ * @throws TypeError For an invalid limit, a missing filter, an out-of-range `minScore`, a
68
+ * vector the space rejects, a non-synchronous filter or grouper, or a non-string group.
69
+ */
36
70
  search(options) {
37
71
  const { vector } = options;
38
72
  breakWhile(!Number.isSafeInteger(options.limit) ||
39
73
  options.limit < 1 ||
40
74
  options.limit > 1000 ||
41
- typeof options.filter !== "function" ||
75
+ typeof options.filter !== 'function' ||
42
76
  (options.minScore !== undefined &&
43
- (!Number.isFinite(options.minScore) ||
44
- options.minScore < -1 ||
45
- options.minScore > 1)), "Invalid vector query");
77
+ (!Number.isFinite(options.minScore) || options.minScore < -1 || options.minScore > 1)), 'Invalid vector query');
46
78
  const query = normalize(vector, this.space.dimensions), groups = new Map();
47
79
  for (const [id, { document, vector: value }] of this.entries) {
48
- const allowed = booleanResult(options.filter(structuredClone(document)), 'Vector filters must be synchronous', 'Vector filters must return boolean');
80
+ // One isolated snapshot per candidate serves filter, grouping and the
81
+ // returned hit; filters and groupers are typed readonly, so sharing it
82
+ // removes the redundant clones without exposing the index.
83
+ const candidate = structuredClone(document);
84
+ const allowed = booleanResult(options.filter(candidate), 'Vector filters must be synchronous', 'Vector filters must return boolean');
49
85
  if (!allowed)
50
86
  continue;
51
87
  let score = 0;
@@ -54,17 +90,15 @@ export class VectorSearch {
54
90
  score = Math.max(-1, Math.min(1, score));
55
91
  if (score < (options.minScore ?? -1))
56
92
  continue;
57
- const group = synchronous(options.groupBy?.(structuredClone(document)), 'Vector grouping must be synchronous') ?? id;
93
+ const group = synchronous(options.groupBy?.(candidate), 'Vector grouping must be synchronous') ?? id;
58
94
  if (typeof group !== 'string')
59
95
  throw new TypeError('Vector groups must be strings');
60
96
  const prior = groups.get(group);
61
- if (!prior ||
62
- score > prior.score ||
63
- (score === prior.score && id < prior.id))
64
- groups.set(group, { id, score, document });
97
+ if (!prior || score > prior.score || (score === prior.score && id < prior.id))
98
+ groups.set(group, { id, score, document: candidate });
65
99
  }
66
100
  return [...groups.values()]
67
101
  .sort((a, b) => b.score - a.score || a.id.localeCompare(b.id))
68
- .slice(0, options.limit).map(hit => ({ ...hit, document: structuredClone(hit.document) }));
102
+ .slice(0, options.limit);
69
103
  }
70
104
  }
@@ -1 +1,8 @@
1
+ /**
2
+ * Node adapter of the optional Mock Kit (`@jangts/agent-core/mock/node`).
3
+ *
4
+ * Re-exports the mock-gpt Node surface only: server and request-handler creators plus their
5
+ * option types. It starts real HTTP servers and therefore requires a Node runtime. Core
6
+ * execution does not import it.
7
+ */
1
8
  export * from '@jangts/mock-gpt/node';
@@ -1,2 +1,8 @@
1
- // Node HTTP adapter for the optional Mock Kit.
1
+ /**
2
+ * Node adapter of the optional Mock Kit (`@jangts/agent-core/mock/node`).
3
+ *
4
+ * Re-exports the mock-gpt Node surface only: server and request-handler creators plus their
5
+ * option types. It starts real HTTP servers and therefore requires a Node runtime. Core
6
+ * execution does not import it.
7
+ */
2
8
  export * from '@jangts/mock-gpt/node';
@@ -1 +1,8 @@
1
+ /**
2
+ * Web adapter of the optional Mock Kit (`@jangts/agent-core/mock/web`).
3
+ *
4
+ * Re-exports the mock-gpt web-content surface only: page sources, the public-address check and
5
+ * their option types. Fetching external pages needs a Node runtime with network access; Core
6
+ * execution does not import it.
7
+ */
1
8
  export * from '@jangts/mock-gpt/web';
@@ -1,2 +1,8 @@
1
- // Web content sources for the optional Mock Kit.
1
+ /**
2
+ * Web adapter of the optional Mock Kit (`@jangts/agent-core/mock/web`).
3
+ *
4
+ * Re-exports the mock-gpt web-content surface only: page sources, the public-address check and
5
+ * their option types. Fetching external pages needs a Node runtime with network access; Core
6
+ * execution does not import it.
7
+ */
2
8
  export * from '@jangts/mock-gpt/web';
@@ -1 +1,8 @@
1
+ /**
2
+ * Optional Mock Kit entry: a configurable mock response SDK with optional API adapters.
3
+ *
4
+ * This file is a pass-through to `@jangts/mock-gpt`; Core execution never imports it, and it
5
+ * carries no production defaults. Platform-specific adapters live in `./mock/node.js` and
6
+ * `./mock/web.js`, which are separate subpath entries (`/mock/node`, `/mock/web`).
7
+ */
1
8
  export * from '@jangts/mock-gpt';
package/dist/esm/mock.js CHANGED
@@ -1,2 +1,8 @@
1
- // Optional Mock Kit. Core execution does not import this entry.
1
+ /**
2
+ * Optional Mock Kit entry: a configurable mock response SDK with optional API adapters.
3
+ *
4
+ * This file is a pass-through to `@jangts/mock-gpt`; Core execution never imports it, and it
5
+ * carries no production defaults. Platform-specific adapters live in `./mock/node.js` and
6
+ * `./mock/web.js`, which are separate subpath entries (`/mock/node`, `/mock/web`).
7
+ */
2
8
  export * from '@jangts/mock-gpt';
@@ -1,21 +1,50 @@
1
1
  import type { ModelRunnerOptions, ModelRunnerPorts, ModelRuntimeConfig, ModelTransportDefinition, ModelTokenBudget, ModelChildPolicy } from '../structs/model/runtime.js';
2
2
  import type { ChatProvider } from '../structs/model/chat-provider.js';
3
- /** Internal compiled definition; execution scope and mutable call state belong to each runner. */
3
+ /**
4
+ * Internal compiled definition; execution scope and mutable call state belong to each runner.
5
+ */
4
6
  export interface ModelBinding {
7
+ /** Provider with its `stream` method already bound to the original receiver. */
5
8
  readonly provider: ChatProvider;
9
+ /** Frozen call limits and usage reporting switch. */
6
10
  readonly config: ModelRuntimeConfig;
11
+ /** Maximum characters of user/assistant message content per call. */
7
12
  readonly maxInputChars: number;
13
+ /** Default completion token request per call; overridable per call within limits. */
8
14
  readonly maxOutputTokens: number;
15
+ /** Output sink, diagnostics and budget-error hooks, with receivers bound. */
9
16
  readonly ports: ModelRunnerPorts;
17
+ /** Optional token accounting contract; absent when the host does not count tokens. */
10
18
  readonly tokenBudget?: ModelTokenBudget;
19
+ /** Registered transports paired with their original source definitions. */
11
20
  readonly transports: readonly {
21
+ /** Definition as supplied by the App; used as the identity key for typed lookups. */
12
22
  readonly source: ModelTransportDefinition;
23
+ /** Normalized, frozen definition actually executed. */
13
24
  readonly definition: ModelTransportDefinition;
14
25
  }[];
26
+ /** Child execution limits already merged with defaults and validated. */
15
27
  readonly children: Readonly<Required<ModelChildPolicy>>;
16
28
  }
17
- /** Only Core passes compiled definitions; not a public configuration alternative. */
29
+ /**
30
+ * Brand carrying the configured model id through copy operations.
31
+ *
32
+ * Only Core passes compiled definitions; it is not a public configuration alternative.
33
+ */
18
34
  export declare const modelBindingId: unique symbol;
35
+ /** Escape hatch that lets the engine hand an already compiled binding to a runner. */
19
36
  export declare const compiledModelBinding: unique symbol;
20
- /** Pin fixed configuration and canonical callbacks without cloning or freezing App services. */
37
+ /**
38
+ * Compile runner options into a frozen binding.
39
+ *
40
+ * Fixed configuration and callbacks are pinned without cloning or freezing App services:
41
+ * providers and sinks stay live objects, only their method receivers are bound. Optional
42
+ * child limits are filled from the defaults before validation, and transports are
43
+ * normalized and checked for duplicate ids, including the built-in text transport.
44
+ *
45
+ * @param options - Runner options as supplied by the App or by the engine.
46
+ * @returns A frozen binding shared by every runner created from these options.
47
+ * @throws TypeError When child limits, the token budget or a transport is invalid.
48
+ * @throws ValidationError When the token budget contract is incomplete.
49
+ */
21
50
  export declare function snapshotModelBinding(options: ModelRunnerOptions): ModelBinding;
@@ -1,44 +1,95 @@
1
+ /**
2
+ * Compile validated model settings into an immutable binding.
3
+ *
4
+ * The runner must not observe configuration changes after construction, so every
5
+ * option, callback and transport is snapshotted here — once per engine or runner.
6
+ * Lifecycle state (call counters, journals, budgets) stays outside the binding.
7
+ *
8
+ * Exports: the `ModelBinding` interface, the internal `modelBindingId` and
9
+ * `compiledModelBinding` symbols, and `snapshotModelBinding`.
10
+ */
1
11
  import { defaultTextTransport, modelRunnerDefaults } from './defaults.js';
2
12
  import { resolveModelSettings } from './settings.js';
3
13
  import { normalizeModelTransport } from './transports.js';
4
14
  import { validateModelTokenBudget } from './token-budget.js';
5
- /** Only Core passes compiled definitions; not a public configuration alternative. */
15
+ /**
16
+ * Brand carrying the configured model id through copy operations.
17
+ *
18
+ * Only Core passes compiled definitions; it is not a public configuration alternative.
19
+ */
6
20
  export const modelBindingId = Symbol('model-binding-id');
21
+ /** Escape hatch that lets the engine hand an already compiled binding to a runner. */
7
22
  export const compiledModelBinding = Symbol('compiled-model-binding');
8
- /** Pin fixed configuration and canonical callbacks without cloning or freezing App services. */
23
+ /**
24
+ * Compile runner options into a frozen binding.
25
+ *
26
+ * Fixed configuration and callbacks are pinned without cloning or freezing App services:
27
+ * providers and sinks stay live objects, only their method receivers are bound. Optional
28
+ * child limits are filled from the defaults before validation, and transports are
29
+ * normalized and checked for duplicate ids, including the built-in text transport.
30
+ *
31
+ * @param options - Runner options as supplied by the App or by the engine.
32
+ * @returns A frozen binding shared by every runner created from these options.
33
+ * @throws TypeError When child limits, the token budget or a transport is invalid.
34
+ * @throws ValidationError When the token budget contract is incomplete.
35
+ */
9
36
  export function snapshotModelBinding(options) {
10
37
  const resolved = resolveModelSettings(options);
11
- if (options.children !== undefined && (!options.children || typeof options.children !== 'object' || Array.isArray(options.children)))
38
+ if (options.children !== undefined &&
39
+ (!options.children || typeof options.children !== 'object' || Array.isArray(options.children)))
12
40
  throw new TypeError('Invalid child execution policy');
13
41
  const sourceChildren = options.children;
14
42
  const children = Object.freeze({
15
- maxDepth: sourceChildren?.maxDepth === undefined ? modelRunnerDefaults.children.maxDepth : sourceChildren.maxDepth,
16
- maxConcurrentCalls: sourceChildren?.maxConcurrentCalls === undefined ? modelRunnerDefaults.children.maxConcurrentCalls : sourceChildren.maxConcurrentCalls,
17
- maxChildren: sourceChildren?.maxChildren === undefined ? modelRunnerDefaults.children.maxChildren : sourceChildren.maxChildren,
43
+ maxDepth: sourceChildren?.maxDepth === undefined
44
+ ? modelRunnerDefaults.children.maxDepth
45
+ : sourceChildren.maxDepth,
46
+ maxConcurrentCalls: sourceChildren?.maxConcurrentCalls === undefined
47
+ ? modelRunnerDefaults.children.maxConcurrentCalls
48
+ : sourceChildren.maxConcurrentCalls,
49
+ maxChildren: sourceChildren?.maxChildren === undefined
50
+ ? modelRunnerDefaults.children.maxChildren
51
+ : sourceChildren.maxChildren,
18
52
  });
19
- if (!Number.isSafeInteger(children.maxDepth) || children.maxDepth < 0
20
- || !Number.isSafeInteger(children.maxConcurrentCalls) || children.maxConcurrentCalls < 1
21
- || !Number.isSafeInteger(children.maxChildren) || children.maxChildren < 1)
53
+ if (!Number.isSafeInteger(children.maxDepth) ||
54
+ children.maxDepth < 0 ||
55
+ !Number.isSafeInteger(children.maxConcurrentCalls) ||
56
+ children.maxConcurrentCalls < 1 ||
57
+ !Number.isSafeInteger(children.maxChildren) ||
58
+ children.maxChildren < 1)
22
59
  throw new TypeError('Invalid child execution policy');
23
60
  const ports = resolved.ports;
24
61
  const sourceBudget = ports.tokenBudget;
25
62
  const countTokens = sourceBudget?.countTokens;
26
- const tokenBudget = sourceBudget && Object.freeze({ counterId: sourceBudget.counterId,
27
- contextWindowTokens: sourceBudget.contextWindowTokens, safetyMarginTokens: sourceBudget.safetyMarginTokens,
28
- countTokens: typeof countTokens === 'function' ? countTokens.bind(sourceBudget) : countTokens });
63
+ const tokenBudget = sourceBudget &&
64
+ Object.freeze({
65
+ counterId: sourceBudget.counterId,
66
+ contextWindowTokens: sourceBudget.contextWindowTokens,
67
+ safetyMarginTokens: sourceBudget.safetyMarginTokens,
68
+ countTokens: typeof countTokens === 'function' ? countTokens.bind(sourceBudget) : countTokens,
69
+ });
29
70
  if (tokenBudget)
30
71
  validateModelTokenBudget(tokenBudget);
31
72
  const ids = new Set([defaultTextTransport.id]);
32
- const transports = Object.freeze((ports.transports ?? []).map(source => {
73
+ const transports = Object.freeze((ports.transports ?? []).map((source) => {
33
74
  const definition = normalizeModelTransport(source);
34
75
  if (ids.has(definition.id))
35
76
  throw new TypeError('Invalid or duplicate model transport');
36
77
  ids.add(definition.id);
37
78
  return Object.freeze({ source, definition });
38
79
  }));
39
- return Object.freeze({ provider: resolved.provider, config: resolved.config, children, maxInputChars: resolved.maxInputChars,
40
- maxOutputTokens: resolved.maxOutputTokens, tokenBudget, transports,
41
- ports: Object.freeze({ maxSchemaChars: ports.maxSchemaChars, onOutput: ports.onOutput,
42
- inputBudgetError: ports.inputBudgetError, outputBudgetError: ports.outputBudgetError }),
80
+ return Object.freeze({
81
+ provider: resolved.provider,
82
+ config: resolved.config,
83
+ children,
84
+ maxInputChars: resolved.maxInputChars,
85
+ maxOutputTokens: resolved.maxOutputTokens,
86
+ tokenBudget,
87
+ transports,
88
+ ports: Object.freeze({
89
+ maxSchemaChars: ports.maxSchemaChars,
90
+ onOutput: ports.onOutput,
91
+ inputBudgetError: ports.inputBudgetError,
92
+ outputBudgetError: ports.outputBudgetError,
93
+ }),
43
94
  });
44
95
  }
@@ -1,14 +1,42 @@
1
- /** Request-local attempt ledger. Reservations leave capacity for ancestor delivery.
2
- * No await between checking and charging: sibling consumers cannot overspend. */
1
+ /**
2
+ * Request-local attempt ledger.
3
+ *
4
+ * `reserve` is capacity kept available to the parent: a child with a reserve cannot
5
+ * consume the calls its ancestor still needs for its own turn.
6
+ */
3
7
  export declare class ModelCallBudget {
4
8
  readonly limit: number;
5
9
  private readonly parent?;
6
10
  private readonly reserve;
7
11
  private consumed;
12
+ /**
13
+ * @param limit - Calls this ledger may consume; nonnegative safe integer.
14
+ * @param parent - Ancestor ledger charged alongside every local take.
15
+ * @param reserve - Calls of the parent's remaining capacity this ledger must leave untouched.
16
+ * @throws Error When `limit` or `reserve` is not a nonnegative safe integer.
17
+ */
8
18
  constructor(limit: number, parent?: ModelCallBudget | undefined, reserve?: number);
19
+ /** Calls already charged to this ledger only. */
9
20
  get used(): number;
21
+ /** Calls still available after the local limit and the parent's reserve are applied. */
10
22
  get remaining(): number;
23
+ /**
24
+ * Derive a child ledger that also charges this one.
25
+ *
26
+ * @param limit - Calls the child may consume.
27
+ * @param reserve - Calls of this ledger's remaining capacity the child must leave free.
28
+ * @returns A new ledger linked to this instance.
29
+ */
11
30
  child(limit: number, reserve: number): ModelCallBudget;
31
+ /**
32
+ * Charge one call to this ledger and every ancestor.
33
+ *
34
+ * The parent is charged first so a failure cannot leave the child counter advanced
35
+ * while the ancestor rejected the charge.
36
+ *
37
+ * @throws BudgetError When no call is available on this ledger or an ancestor.
38
+ */
12
39
  take(): void;
13
40
  }
41
+ /** Carries an inherited budget into a child runner that was not created by `child`. */
14
42
  export declare const parentModelBudget: unique symbol;
@@ -1,27 +1,68 @@
1
+ /**
2
+ * Request-local model call accounting.
3
+ *
4
+ * A budget can have a parent, which makes sibling children compete for the same
5
+ * ancestor allowance. Charging is synchronous: there is no await between the check and
6
+ * the counter update, so two concurrent consumers cannot both spend the last call.
7
+ *
8
+ * Exports: `ModelCallBudget` and the `parentModelBudget` hand-off symbol.
9
+ */
1
10
  import { BudgetError } from '../structs/errors.js';
2
11
  import { breakWhile } from '../utils/rules.js';
3
- /** Request-local attempt ledger. Reservations leave capacity for ancestor delivery.
4
- * No await between checking and charging: sibling consumers cannot overspend. */
12
+ /**
13
+ * Request-local attempt ledger.
14
+ *
15
+ * `reserve` is capacity kept available to the parent: a child with a reserve cannot
16
+ * consume the calls its ancestor still needs for its own turn.
17
+ */
5
18
  export class ModelCallBudget {
6
19
  limit;
7
20
  parent;
8
21
  reserve;
9
22
  consumed = 0;
23
+ /**
24
+ * @param limit - Calls this ledger may consume; nonnegative safe integer.
25
+ * @param parent - Ancestor ledger charged alongside every local take.
26
+ * @param reserve - Calls of the parent's remaining capacity this ledger must leave untouched.
27
+ * @throws Error When `limit` or `reserve` is not a nonnegative safe integer.
28
+ */
10
29
  constructor(limit, parent, reserve = 0) {
11
30
  this.limit = limit;
12
31
  this.parent = parent;
13
32
  this.reserve = reserve;
14
33
  breakWhile(!Number.isSafeInteger(limit) || limit < 0 || !Number.isSafeInteger(reserve) || reserve < 0, 'Invalid model call budget');
15
34
  }
16
- get used() { return this.consumed; }
35
+ /** Calls already charged to this ledger only. */
36
+ get used() {
37
+ return this.consumed;
38
+ }
39
+ /** Calls still available after the local limit and the parent's reserve are applied. */
17
40
  get remaining() {
18
41
  return Math.max(0, Math.min(this.limit - this.consumed, this.parent ? this.parent.remaining - this.reserve : Infinity));
19
42
  }
20
- child(limit, reserve) { return new ModelCallBudget(limit, this, reserve); }
43
+ /**
44
+ * Derive a child ledger that also charges this one.
45
+ *
46
+ * @param limit - Calls the child may consume.
47
+ * @param reserve - Calls of this ledger's remaining capacity the child must leave free.
48
+ * @returns A new ledger linked to this instance.
49
+ */
50
+ child(limit, reserve) {
51
+ return new ModelCallBudget(limit, this, reserve);
52
+ }
53
+ /**
54
+ * Charge one call to this ledger and every ancestor.
55
+ *
56
+ * The parent is charged first so a failure cannot leave the child counter advanced
57
+ * while the ancestor rejected the charge.
58
+ *
59
+ * @throws BudgetError When no call is available on this ledger or an ancestor.
60
+ */
21
61
  take() {
22
62
  breakWhile(this.remaining < 1, () => new BudgetError());
23
63
  this.parent?.take();
24
64
  this.consumed++;
25
65
  }
26
66
  }
67
+ /** Carries an inherited budget into a child runner that was not created by `child`. */
27
68
  export const parentModelBudget = Symbol('parentModelBudget');
@@ -1,4 +1,13 @@
1
- /** Retry a rejected parallel proposal before any tool executes. The caller owns the fallback and its budget. */
1
+ /**
2
+ * Retry once when the failure is a rejected multi-call proposal.
3
+ *
4
+ * Only the `MODEL_MULTIPLE_CALLS` code is retried; every other failure is rethrown
5
+ * unchanged. The caller owns the fallback prompt and the budget it consumes.
6
+ *
7
+ * @param request - `invoke` performs the first attempt; `retry` performs the fallback.
8
+ * @returns The first successful value.
9
+ * @throws The original error when it is not a multi-call rejection, or the fallback error.
10
+ */
2
11
  export declare function retryMultipleModelCalls<Value>(request: {
3
12
  readonly invoke: () => Promise<Value>;
4
13
  readonly retry: (error: unknown) => Promise<Value>;
@@ -1,5 +1,23 @@
1
+ /**
2
+ * Single retry point for rejected parallel model proposals.
3
+ *
4
+ * A provider may answer with more than one tool call. The protocol rejects that answer
5
+ * before any tool runs, so retrying is safe and must happen here — after a tool had
6
+ * executed, a retry could duplicate side effects.
7
+ *
8
+ * Exports: `retryMultipleModelCalls`.
9
+ */
1
10
  import { getErrorInfo } from '../errors.js';
2
- /** Retry a rejected parallel proposal before any tool executes. The caller owns the fallback and its budget. */
11
+ /**
12
+ * Retry once when the failure is a rejected multi-call proposal.
13
+ *
14
+ * Only the `MODEL_MULTIPLE_CALLS` code is retried; every other failure is rethrown
15
+ * unchanged. The caller owns the fallback prompt and the budget it consumes.
16
+ *
17
+ * @param request - `invoke` performs the first attempt; `retry` performs the fallback.
18
+ * @returns The first successful value.
19
+ * @throws The original error when it is not a multi-call rejection, or the fallback error.
20
+ */
3
21
  export async function retryMultipleModelCalls(request) {
4
22
  try {
5
23
  return await request.invoke();
@@ -1,4 +1,10 @@
1
- /** Baseline runtime limits, not a claim about any provider's context window. */
1
+ /**
2
+ * Frozen default limits.
3
+ *
4
+ * `maxCalls` bounds one request's model calls, `callTimeoutMs` stays below the
5
+ * 32-bit timer limit, and the child limits cap fan-out per request. `stage` is the
6
+ * fallback stage id used when a call does not name one.
7
+ */
2
8
  export declare const modelRunnerDefaults: Readonly<{
3
9
  maxCalls: 8;
4
10
  callTimeoutMs: 30000;
@@ -13,7 +19,12 @@ export declare const modelRunnerDefaults: Readonly<{
13
19
  maxChildren: 32;
14
20
  }>;
15
21
  }>;
16
- /** Core owns ordinary text execution; no App-side adapter is required. */
22
+ /**
23
+ * Built-in plain-text transport.
24
+ *
25
+ * Core owns ordinary text execution, so no App-side adapter is required for the
26
+ * default single-prompt call shape.
27
+ */
17
28
  export declare const defaultTextTransport: import("./runner.js").ModelTransportDefinition<string> & {
18
29
  readonly id: "core:plain-text";
19
30
  };
@@ -1,10 +1,33 @@
1
+ /**
2
+ * Baseline model runtime limits.
3
+ *
4
+ * These are conservative runtime defaults, not a claim about any provider's context
5
+ * window; a host that knows its model must override them explicitly.
6
+ *
7
+ * Exports: `modelRunnerDefaults` and `defaultTextTransport`.
8
+ */
1
9
  import { createPlainTextTransport } from './transports.js';
2
- /** Baseline runtime limits, not a claim about any provider's context window. */
10
+ /**
11
+ * Frozen default limits.
12
+ *
13
+ * `maxCalls` bounds one request's model calls, `callTimeoutMs` stays below the
14
+ * 32-bit timer limit, and the child limits cap fan-out per request. `stage` is the
15
+ * fallback stage id used when a call does not name one.
16
+ */
3
17
  export const modelRunnerDefaults = Object.freeze({
4
- maxCalls: 8, callTimeoutMs: 30000, maxInputChars: 32000,
5
- maxOutputChars: 16000, maxSchemaChars: 16000, maxOutputTokens: 1024,
18
+ maxCalls: 8,
19
+ callTimeoutMs: 30000,
20
+ maxInputChars: 32000,
21
+ maxOutputChars: 16000,
22
+ maxSchemaChars: 16000,
23
+ maxOutputTokens: 1024,
6
24
  stage: 'model',
7
25
  children: Object.freeze({ maxDepth: 1, maxConcurrentCalls: 1, maxChildren: 32 }),
8
26
  });
9
- /** Core owns ordinary text execution; no App-side adapter is required. */
27
+ /**
28
+ * Built-in plain-text transport.
29
+ *
30
+ * Core owns ordinary text execution, so no App-side adapter is required for the
31
+ * default single-prompt call shape.
32
+ */
10
33
  export const defaultTextTransport = createPlainTextTransport('core:plain-text');