@jangts/agent-core 0.3.5 → 0.5.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 (288) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +33 -31
  3. package/development/docs/README.en.md +2 -2
  4. package/development/docs/acceptance.en.md +2 -2
  5. package/development/docs/agent-development.en.md +1 -1
  6. package/development/docs/api/README.en.md +6 -2
  7. package/development/docs/api/README.md +4 -0
  8. package/development/docs/api/configuration-in-workflow.en.md +403 -0
  9. package/development/docs/api/configuration-in-workflow.md +403 -0
  10. package/development/docs/api/core.en.md +7 -7
  11. package/development/docs/api/core.md +6 -6
  12. package/development/docs/api/decorators.en.md +20 -0
  13. package/development/docs/api/decorators.md +20 -0
  14. package/development/docs/api/examples.en.md +1 -1
  15. package/development/docs/api/examples.md +1 -1
  16. package/development/docs/api/kits.en.md +22 -4
  17. package/development/docs/api/kits.md +22 -4
  18. package/development/docs/api/knowledge-answering.en.md +4 -1
  19. package/development/docs/api/knowledge-answering.md +4 -1
  20. package/development/docs/api/mock.en.md +2 -0
  21. package/development/docs/api/mock.md +2 -0
  22. package/development/docs/api/observability.en.md +37 -11
  23. package/development/docs/api/observability.md +64 -11
  24. package/development/docs/api/reference.en.md +876 -657
  25. package/development/docs/api/reference.md +662 -508
  26. package/development/docs/api/support.en.md +55 -9
  27. package/development/docs/api/support.md +53 -7
  28. package/development/docs/api/types.en.md +36 -1
  29. package/development/docs/api/types.md +44 -0
  30. package/development/docs/api/workflow-views.en.md +64 -0
  31. package/development/docs/api/workflow-views.md +78 -0
  32. package/development/docs/api/workflow.en.md +6 -2
  33. package/development/docs/api/workflow.md +6 -2
  34. package/development/docs/basic-usage.en.md +1 -1
  35. package/development/docs/basic-usage.md +1 -1
  36. package/development/docs/create-app.en.md +1 -1
  37. package/development/docs/examples/registration/associated.mjs +8 -0
  38. package/development/docs/examples/registration/independent.mjs +20 -0
  39. package/development/docs/examples/registration/protocol.mjs +48 -0
  40. package/development/docs/examples/registration/run.mjs +47 -0
  41. package/development/docs/examples/registration/tools.mjs +75 -0
  42. package/development/docs/examples/registration/workflow.mjs +109 -0
  43. package/development/docs/flows/knowledge-maintenance.en.md +1 -1
  44. package/development/docs/materials.en.md +1 -1
  45. package/development/docs/mechanisms.en.md +2 -2
  46. package/development/docs/mechanisms.md +1 -1
  47. package/development/docs/operations.en.md +1 -1
  48. package/development/docs/records.en.md +1 -1
  49. package/development/docs/registration.en.md +4 -4
  50. package/development/docs/registration.md +2 -2
  51. package/development/skills/agent-core-app/SKILL.md +16 -4
  52. package/development/skills/agent-core-app/templates/node-ts/README.md.tpl +1 -1
  53. package/development/skills/agent-core-app/templates/node-ts/src/catalog.ts.tpl +2 -2
  54. package/development/skills/agent-core-app/templates/node-ts/test/app.test.mjs.tpl +1 -1
  55. package/dist/cjs/capabilities/index.js +5 -12
  56. package/dist/cjs/capabilities/invocation.js +21 -1
  57. package/dist/cjs/capabilities/model.js +56 -12
  58. package/dist/cjs/capabilities/tool-conditions.js +65 -0
  59. package/dist/cjs/capabilities/tool-runtime.js +18 -4
  60. package/dist/cjs/capabilities/tools.js +12 -17
  61. package/dist/cjs/context/audit.js +5 -8
  62. package/dist/cjs/context/index.js +3 -4
  63. package/dist/cjs/diagnostics/index.js +51 -3
  64. package/dist/cjs/diagnostics/native-sub-flow.js +106 -0
  65. package/dist/cjs/diagnostics/sub-flow.js +278 -32
  66. package/dist/cjs/execution/engine.js +3 -2
  67. package/dist/cjs/execution/events.js +5 -5
  68. package/dist/cjs/execution/reporting.js +18 -28
  69. package/dist/cjs/execution/workflow-chain.js +211 -0
  70. package/dist/cjs/execution/workflow-graph.js +72 -0
  71. package/dist/cjs/execution/workflow.js +34 -6
  72. package/dist/cjs/index.js +21 -17
  73. package/dist/cjs/kits/aggregation.js +17 -14
  74. package/dist/cjs/kits/answering/checks.js +2 -1
  75. package/dist/cjs/kits/answering/flow.js +24 -21
  76. package/dist/cjs/kits/answering/tasks.js +30 -25
  77. package/dist/cjs/kits/delivery.js +36 -24
  78. package/dist/cjs/kits/domains/catalog.js +113 -0
  79. package/dist/cjs/kits/domains/index.js +20 -0
  80. package/dist/cjs/kits/{intents → domains}/registry.js +77 -31
  81. package/dist/cjs/kits/{intents → domains}/scopes.js +21 -21
  82. package/dist/cjs/kits/index.js +14 -13
  83. package/dist/cjs/kits/knowledge/catalog.js +33 -30
  84. package/dist/cjs/kits/policies.js +3 -2
  85. package/dist/cjs/kits/presentation/formats.js +110 -0
  86. package/dist/cjs/kits/presentation/index.js +10 -5
  87. package/dist/cjs/kits/presentation/outputs.js +2 -1
  88. package/dist/cjs/kits/reflection.js +2 -2
  89. package/dist/cjs/kits/retrieval.js +7 -1
  90. package/dist/cjs/kits/text-blocks.js +101 -0
  91. package/dist/cjs/kits/tools.js +247 -158
  92. package/dist/cjs/model/decision-retry.js +2 -1
  93. package/dist/cjs/model/index.js +2 -6
  94. package/dist/cjs/model/interactions/calls.js +61 -0
  95. package/dist/cjs/model/interactions/json-object.js +11 -11
  96. package/dist/cjs/model/interactions/native-functions.js +17 -23
  97. package/dist/cjs/model/message-diagnostics.js +13 -3
  98. package/dist/cjs/model/options.js +2 -0
  99. package/dist/cjs/model/preparation.js +39 -6
  100. package/dist/cjs/model/runner.js +34 -5
  101. package/dist/cjs/model/selection-transport.js +4 -4
  102. package/dist/cjs/model/token-budget.js +3 -0
  103. package/dist/cjs/model/transports.js +3 -2
  104. package/dist/cjs/structs/index.js +7 -6
  105. package/dist/cjs/structs/kits/domains/scopes.js +2 -0
  106. package/dist/cjs/structs/kits/presentation/formats.js +2 -0
  107. package/dist/cjs/structs/kits/text-blocks.js +11 -0
  108. package/dist/cjs/structs/model/session.js +11 -0
  109. package/dist/cjs/structs/support/associations.js +2 -0
  110. package/dist/cjs/support/associations.js +79 -0
  111. package/dist/cjs/support/context/nodes.js +48 -45
  112. package/dist/cjs/support/context/processing.js +6 -3
  113. package/dist/cjs/support/context/snapshot.js +11 -1
  114. package/dist/cjs/support/decorators/index.js +45 -3
  115. package/dist/cjs/support/index.js +1 -0
  116. package/dist/cjs/support/model/capabilities.js +35 -5
  117. package/dist/cjs/support/model/chat-completions.js +11 -2
  118. package/dist/cjs/support/model/completion/calls.js +10 -56
  119. package/dist/cjs/support/model/preview-rules.js +11 -11
  120. package/dist/cjs/support/model/reply-preview.js +3 -3
  121. package/dist/cjs/support/model/session.js +152 -0
  122. package/dist/cjs/support/model/stage-transport.js +8 -8
  123. package/dist/cjs/support/model/transports.js +5 -2
  124. package/dist/cjs/support/tools.js +42 -17
  125. package/dist/cjs/utils/invocation.js +1 -0
  126. package/dist/esm/capabilities/index.d.ts +5 -10
  127. package/dist/esm/capabilities/index.js +5 -9
  128. package/dist/esm/capabilities/invocation.js +21 -1
  129. package/dist/esm/capabilities/model.d.ts +17 -13
  130. package/dist/esm/capabilities/model.js +54 -10
  131. package/dist/esm/capabilities/tool-conditions.d.ts +9 -0
  132. package/dist/esm/capabilities/tool-conditions.js +59 -0
  133. package/dist/esm/capabilities/tool-runtime.js +18 -4
  134. package/dist/esm/capabilities/tools.d.ts +3 -3
  135. package/dist/esm/capabilities/tools.js +12 -17
  136. package/dist/esm/context/audit.js +5 -8
  137. package/dist/esm/context/index.d.ts +3 -4
  138. package/dist/esm/context/index.js +3 -4
  139. package/dist/esm/diagnostics/index.d.ts +1 -0
  140. package/dist/esm/diagnostics/index.js +48 -2
  141. package/dist/esm/diagnostics/native-sub-flow.d.ts +94 -0
  142. package/dist/esm/diagnostics/native-sub-flow.js +101 -0
  143. package/dist/esm/diagnostics/sub-flow.d.ts +56 -4
  144. package/dist/esm/diagnostics/sub-flow.js +271 -32
  145. package/dist/esm/execution/engine.d.ts +1 -0
  146. package/dist/esm/execution/engine.js +3 -2
  147. package/dist/esm/execution/events.js +5 -5
  148. package/dist/esm/execution/reporting.d.ts +6 -12
  149. package/dist/esm/execution/reporting.js +19 -29
  150. package/dist/esm/execution/workflow-chain.d.ts +3 -0
  151. package/dist/esm/execution/workflow-chain.js +208 -0
  152. package/dist/esm/execution/workflow-graph.d.ts +7 -0
  153. package/dist/esm/execution/workflow-graph.js +68 -0
  154. package/dist/esm/execution/workflow.d.ts +6 -0
  155. package/dist/esm/execution/workflow.js +34 -6
  156. package/dist/esm/index.d.ts +19 -13
  157. package/dist/esm/index.js +18 -15
  158. package/dist/esm/kits/aggregation.d.ts +1 -1
  159. package/dist/esm/kits/aggregation.js +17 -14
  160. package/dist/esm/kits/answering/checks.js +2 -1
  161. package/dist/esm/kits/answering/flow.js +24 -21
  162. package/dist/esm/kits/answering/tasks.d.ts +6 -6
  163. package/dist/esm/kits/answering/tasks.js +30 -25
  164. package/dist/esm/kits/delivery.d.ts +0 -9
  165. package/dist/esm/kits/delivery.js +36 -24
  166. package/dist/esm/kits/domains/catalog.d.ts +42 -0
  167. package/dist/esm/kits/domains/catalog.js +110 -0
  168. package/dist/esm/kits/domains/index.d.ts +4 -0
  169. package/dist/esm/kits/domains/index.js +4 -0
  170. package/dist/esm/kits/domains/registry.d.ts +100 -0
  171. package/dist/esm/kits/{intents → domains}/registry.js +77 -31
  172. package/dist/esm/kits/{intents → domains}/scopes.d.ts +18 -18
  173. package/dist/esm/kits/{intents → domains}/scopes.js +21 -21
  174. package/dist/esm/kits/index.d.ts +6 -5
  175. package/dist/esm/kits/index.js +6 -5
  176. package/dist/esm/kits/knowledge/catalog.js +33 -30
  177. package/dist/esm/kits/policies.d.ts +1 -1
  178. package/dist/esm/kits/policies.js +3 -2
  179. package/dist/esm/kits/presentation/formats.d.ts +42 -0
  180. package/dist/esm/kits/presentation/formats.js +105 -0
  181. package/dist/esm/kits/presentation/index.d.ts +14 -5
  182. package/dist/esm/kits/presentation/index.js +10 -5
  183. package/dist/esm/kits/presentation/outputs.js +2 -1
  184. package/dist/esm/kits/reflection.js +3 -3
  185. package/dist/esm/kits/retrieval.js +7 -1
  186. package/dist/esm/kits/text-blocks.d.ts +24 -0
  187. package/dist/esm/kits/text-blocks.js +97 -0
  188. package/dist/esm/kits/tools.d.ts +69 -52
  189. package/dist/esm/kits/tools.js +247 -158
  190. package/dist/esm/model/decision-retry.d.ts +2 -0
  191. package/dist/esm/model/decision-retry.js +2 -1
  192. package/dist/esm/model/index.d.ts +2 -6
  193. package/dist/esm/model/index.js +2 -6
  194. package/dist/esm/model/interactions/calls.d.ts +40 -0
  195. package/dist/esm/model/interactions/calls.js +58 -0
  196. package/dist/esm/model/interactions/json-object.js +11 -11
  197. package/dist/esm/model/interactions/native-functions.js +17 -23
  198. package/dist/esm/model/message-diagnostics.d.ts +6 -5
  199. package/dist/esm/model/message-diagnostics.js +13 -3
  200. package/dist/esm/model/options.js +2 -0
  201. package/dist/esm/model/preparation.js +39 -6
  202. package/dist/esm/model/runner.d.ts +2 -0
  203. package/dist/esm/model/runner.js +34 -5
  204. package/dist/esm/model/selection-transport.js +4 -4
  205. package/dist/esm/model/token-budget.js +3 -0
  206. package/dist/esm/model/transports.d.ts +2 -1
  207. package/dist/esm/model/transports.js +3 -2
  208. package/dist/esm/structs/capabilities/invocation.d.ts +3 -1
  209. package/dist/esm/structs/capabilities/model.d.ts +42 -11
  210. package/dist/esm/structs/capabilities/tools.d.ts +16 -7
  211. package/dist/esm/structs/common.d.ts +3 -1
  212. package/dist/esm/structs/debug.d.ts +36 -20
  213. package/dist/esm/structs/execution/workflow-views.d.ts +123 -0
  214. package/dist/esm/structs/execution/workflow.d.ts +4 -3
  215. package/dist/esm/structs/index.d.ts +8 -6
  216. package/dist/esm/structs/index.js +7 -6
  217. package/dist/esm/structs/kits/answering/tasks.d.ts +2 -2
  218. package/dist/esm/structs/kits/{intents → domains}/catalog.d.ts +20 -20
  219. package/dist/esm/structs/kits/{intents → domains}/registry.d.ts +24 -21
  220. package/dist/esm/structs/kits/{intents → domains}/scopes.d.ts +9 -9
  221. package/dist/esm/structs/kits/domains/scopes.js +1 -0
  222. package/dist/esm/structs/kits/presentation/formats.d.ts +42 -0
  223. package/dist/esm/structs/kits/presentation/formats.js +1 -0
  224. package/dist/esm/structs/kits/text-blocks.d.ts +25 -0
  225. package/dist/esm/structs/kits/text-blocks.js +10 -0
  226. package/dist/esm/structs/kits/tools.d.ts +82 -83
  227. package/dist/esm/structs/model/interactions.d.ts +18 -11
  228. package/dist/esm/structs/model/messages.d.ts +34 -2
  229. package/dist/esm/structs/model/runtime.d.ts +9 -0
  230. package/dist/esm/structs/model/session.d.ts +29 -0
  231. package/dist/esm/structs/model/session.js +10 -0
  232. package/dist/esm/structs/support/associations.d.ts +22 -0
  233. package/dist/esm/structs/support/associations.js +1 -0
  234. package/dist/esm/structs/support/model/interactions.d.ts +2 -2
  235. package/dist/esm/structs/support/model/messages.d.ts +6 -13
  236. package/dist/esm/structs/support/tools.d.ts +23 -23
  237. package/dist/esm/support/associations.d.ts +26 -0
  238. package/dist/esm/support/associations.js +76 -0
  239. package/dist/esm/support/context/nodes.js +48 -45
  240. package/dist/esm/support/context/processing.js +6 -3
  241. package/dist/esm/support/context/snapshot.js +11 -1
  242. package/dist/esm/support/decorators/index.d.ts +13 -2
  243. package/dist/esm/support/decorators/index.js +40 -3
  244. package/dist/esm/support/decorators/pool.d.ts +6 -5
  245. package/dist/esm/support/decorators/types.d.ts +3 -1
  246. package/dist/esm/support/index.d.ts +1 -0
  247. package/dist/esm/support/index.js +1 -0
  248. package/dist/esm/support/model/capabilities.d.ts +8 -3
  249. package/dist/esm/support/model/capabilities.js +35 -5
  250. package/dist/esm/support/model/chat-completions.js +11 -2
  251. package/dist/esm/support/model/completion/calls.d.ts +6 -34
  252. package/dist/esm/support/model/completion/calls.js +8 -55
  253. package/dist/esm/support/model/index.d.ts +1 -1
  254. package/dist/esm/support/model/preview-rules.d.ts +13 -8
  255. package/dist/esm/support/model/preview-rules.js +11 -11
  256. package/dist/esm/support/model/reply-preview.d.ts +2 -2
  257. package/dist/esm/support/model/reply-preview.js +3 -3
  258. package/dist/esm/support/model/session.d.ts +61 -0
  259. package/dist/esm/support/model/session.js +148 -0
  260. package/dist/esm/support/model/stage-transport.d.ts +1 -1
  261. package/dist/esm/support/model/stage-transport.js +9 -9
  262. package/dist/esm/support/model/transports.d.ts +2 -0
  263. package/dist/esm/support/model/transports.js +2 -1
  264. package/dist/esm/support/tools.d.ts +11 -3
  265. package/dist/esm/support/tools.js +43 -18
  266. package/dist/esm/utils/catalog.d.ts +1 -1
  267. package/dist/esm/utils/invocation.d.ts +1 -0
  268. package/dist/esm/utils/invocation.js +1 -0
  269. package/package.json +20 -6
  270. package/dist/cjs/execution/index.js +0 -30
  271. package/dist/cjs/kits/intents/catalog.js +0 -82
  272. package/dist/cjs/kits/intents/index.js +0 -35
  273. package/dist/cjs/utils/debug.js +0 -30
  274. package/dist/esm/execution/index.d.ts +0 -11
  275. package/dist/esm/execution/index.js +0 -11
  276. package/dist/esm/kits/intents/catalog.d.ts +0 -39
  277. package/dist/esm/kits/intents/catalog.js +0 -79
  278. package/dist/esm/kits/intents/index.d.ts +0 -22
  279. package/dist/esm/kits/intents/index.js +0 -18
  280. package/dist/esm/kits/intents/registry.d.ts +0 -88
  281. package/dist/esm/utils/debug.d.ts +0 -27
  282. package/dist/esm/utils/debug.js +0 -27
  283. /package/dist/cjs/structs/{kits/intents/catalog.js → execution/workflow-views.js} +0 -0
  284. /package/dist/cjs/structs/kits/{intents/registry.js → domains/catalog.js} +0 -0
  285. /package/dist/cjs/structs/kits/{intents/scopes.js → domains/registry.js} +0 -0
  286. /package/dist/esm/structs/{kits/intents/catalog.js → execution/workflow-views.js} +0 -0
  287. /package/dist/esm/structs/kits/{intents/registry.js → domains/catalog.js} +0 -0
  288. /package/dist/esm/structs/kits/{intents/scopes.js → domains/registry.js} +0 -0
@@ -14,6 +14,7 @@ exports.createContextReductionNode = createContextReductionNode;
14
14
  * Main exports: `createContextProcessingNode`, `createContextSelectionNode`,
15
15
  * `createContextReductionNode` and their result/definition types.
16
16
  */
17
+ const native_sub_flow_js_1 = require("../../diagnostics/native-sub-flow.js");
17
18
  const processing_js_1 = require("./processing.js");
18
19
  const defaults_js_1 = require("../../model/defaults.js");
19
20
  const synchronous_js_1 = require("../../utils/synchronous.js");
@@ -129,53 +130,55 @@ function contextNode(definition, execute) {
129
130
  onErrorRouteId: definition.onErrorRouteId,
130
131
  routes: definition.routes,
131
132
  async run(state, context) {
132
- // The node timeout is an additional bound; parent cancellation still wins.
133
- const signal = (0, cancellation_js_1.combineSignals)(context.signal, AbortSignal.timeout(timeoutMs));
134
- const prepared = selectPrepared
135
- ? selectPrepared(state, context)
136
- : context.model.prepare(typeof request === 'function' ? request(state, context) : request);
137
- const input = (0, synchronous_js_1.synchronous)(plan(state, context), 'Context plans must be synchronous');
138
- // An empty measurement reports the allowance left after transport, instruction and schema
139
- // overhead, so processing must fit inside whichever limit is tighter.
140
- const overhead = prepared.measure([]);
141
- const fullLimit = Math.min(input.maxInputChars, overhead.maxInputChars);
142
- const bodyLimit = fullLimit;
143
- (0, rules_js_1.breakWhile)(bodyLimit < 1, 'No input capacity for context');
144
- const work = (0, processing_js_1.beginContextProcessing)({
145
- fragments: input.fragments,
146
- additionalMessages: input.additionalMessages,
147
- originalFragments: input.originalFragments,
148
- mutableFragmentIds: input.mutableFragmentIds,
149
- maxInputChars: bodyLimit,
150
- }, policy, {
151
- stageId: prepared.stageId,
152
- signal,
153
- diagnostics: context.diagnostics,
154
- compressors,
155
- selectors,
156
- // Read lazily so handlers see the live budget rather than the value at preparation.
157
- remainingCalls: () => prepared.remainingCalls,
158
- callModel: (options) => context.model.invoke({
159
- ...options,
160
- modelId: options.modelId ?? prepared.modelId,
133
+ return (0, native_sub_flow_js_1.nativeSubFlowAsync)(context, 'context', definition.id, async () => {
134
+ // The node timeout is an additional bound; parent cancellation still wins.
135
+ const signal = (0, cancellation_js_1.combineSignals)(context.signal, AbortSignal.timeout(timeoutMs));
136
+ const prepared = selectPrepared
137
+ ? selectPrepared(state, context)
138
+ : context.model.prepare(typeof request === 'function' ? request(state, context) : request);
139
+ const input = (0, synchronous_js_1.synchronous)(plan(state, context), 'Context plans must be synchronous');
140
+ // An empty measurement reports the allowance left after transport, instruction and schema
141
+ // overhead, so processing must fit inside whichever limit is tighter.
142
+ const overhead = prepared.measure([]);
143
+ const fullLimit = Math.min(input.maxInputChars, overhead.maxInputChars);
144
+ const bodyLimit = fullLimit;
145
+ (0, rules_js_1.breakWhile)(bodyLimit < 1, 'No input capacity for context');
146
+ const work = (0, processing_js_1.beginContextProcessing)({
147
+ fragments: input.fragments,
148
+ additionalMessages: input.additionalMessages,
149
+ originalFragments: input.originalFragments,
150
+ mutableFragmentIds: input.mutableFragmentIds,
151
+ maxInputChars: bodyLimit,
152
+ }, policy, {
153
+ stageId: prepared.stageId,
161
154
  signal,
162
- }),
163
- ...(overhead.counterId
164
- ? {
165
- tokenBudget: {
166
- counterId: overhead.counterId,
167
- inputLimit: overhead.inputTokenLimit,
168
- measure: (messages) => prepared.measure(messages).inputTokens,
169
- },
170
- }
171
- : {}),
155
+ diagnostics: context.diagnostics,
156
+ compressors,
157
+ selectors,
158
+ // Read lazily so handlers see the live budget rather than the value at preparation.
159
+ remainingCalls: () => prepared.remainingCalls,
160
+ callModel: (options) => context.model.invoke({
161
+ ...options,
162
+ modelId: options.modelId ?? prepared.modelId,
163
+ signal,
164
+ }),
165
+ ...(overhead.counterId
166
+ ? {
167
+ tokenBudget: {
168
+ counterId: overhead.counterId,
169
+ inputLimit: overhead.inputTokenLimit,
170
+ measure: (messages) => prepared.measure(messages).inputTokens,
171
+ },
172
+ }
173
+ : {}),
174
+ });
175
+ context.report({ payload: { phase: 'processing', fragmentCount: input.fragments.length } });
176
+ const result = await execute(work, prepared, fullLimit, state, context);
177
+ // Never report or commit a result produced after cancellation.
178
+ signal.throwIfAborted();
179
+ context.report({ payload: { phase: 'processed', report: work.report } });
180
+ return (0, synchronous_js_1.synchronous)(update(result, state), 'Context node updates must be synchronous');
172
181
  });
173
- context.report({ payload: { phase: 'processing', fragmentCount: input.fragments.length } });
174
- const result = await execute(work, prepared, fullLimit, state, context);
175
- // Never report or commit a result produced after cancellation.
176
- signal.throwIfAborted();
177
- context.report({ payload: { phase: 'processed', report: work.report } });
178
- return (0, synchronous_js_1.synchronous)(update(result, state), 'Context node updates must be synchronous');
179
182
  },
180
183
  };
181
184
  }
@@ -26,6 +26,7 @@ exports.processContext = processContext;
26
26
  * `finishContextProcessing` (staged runs), the policy/reduction catalogs and the individual
27
27
  * validation, measurement and reduction helpers used by workflow nodes.
28
28
  */
29
+ const native_sub_flow_js_1 = require("../../diagnostics/native-sub-flow.js");
29
30
  const snapshot_js_1 = require("./snapshot.js");
30
31
  const audit_js_1 = require("../../context/audit.js");
31
32
  const history_js_1 = require("./history.js");
@@ -610,7 +611,9 @@ function finishContextProcessing(state) {
610
611
  * @throws {BudgetError} When a handler exhausts its call allowance.
611
612
  */
612
613
  async function processContext(plan, policy, ports) {
613
- const state = beginContextProcessing(plan, policy, ports);
614
- await exports.contextPolicyCatalog[policy.mode].run(state);
615
- return finishContextProcessing(state);
614
+ return (0, native_sub_flow_js_1.nativeSubFlowAsync)(ports, 'context', policy.mode, async () => {
615
+ const state = beginContextProcessing(plan, policy, ports);
616
+ await exports.contextPolicyCatalog[policy.mode].run(state);
617
+ return finishContextProcessing(state);
618
+ });
616
619
  }
@@ -21,7 +21,7 @@ function snapshotFragment(fragment) {
21
21
  * unsupported `detail` value.
22
22
  */
23
23
  function snapshotMessage(message) {
24
- const { role, content, images } = message;
24
+ const { role, content, images, toolCalls, toolCallId } = message;
25
25
  if (images !== undefined && !Array.isArray(images))
26
26
  throw new TypeError('Context images must be an array');
27
27
  return {
@@ -38,5 +38,15 @@ function snapshotMessage(message) {
38
38
  return { url, ...(detail === undefined ? {} : { detail }) };
39
39
  }),
40
40
  }),
41
+ ...(toolCalls === undefined
42
+ ? {}
43
+ : {
44
+ toolCalls: toolCalls.map((call) => ({
45
+ id: call.id,
46
+ name: call.name,
47
+ arguments: call.arguments,
48
+ })),
49
+ }),
50
+ ...(toolCallId === undefined ? {} : { toolCallId }),
41
51
  };
42
52
  }
@@ -1,13 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.modelPool = exports.agentPool = exports.workflowPool = exports.fragmentPool = exports.toolPool = exports.nodePool = void 0;
4
+ exports.Intent = Intent;
4
5
  exports.node = node;
6
+ exports.WorkflowNode = node;
5
7
  exports.tool = tool;
8
+ exports.WorkflowTool = tool;
9
+ exports.tool = tool;
10
+ exports.WorkflowTool = tool;
11
+ exports.node = node;
12
+ exports.WorkflowNode = node;
6
13
  exports.fragment = fragment;
7
14
  exports.workflow = workflow;
8
15
  exports.agent = agent;
9
16
  exports.model = model;
10
17
  const tools_js_1 = require("../tools.js");
18
+ const capabilities_js_1 = require("../model/capabilities.js");
19
+ const tool_conditions_js_1 = require("../../capabilities/tool-conditions.js");
11
20
  const workflow_js_1 = require("../../execution/workflow.js");
12
21
  const assembly_js_1 = require("../context/assembly.js");
13
22
  const binding_js_1 = require("../../model/binding.js");
@@ -19,15 +28,43 @@ Object.defineProperty(exports, "fragmentPool", { enumerable: true, get: function
19
28
  Object.defineProperty(exports, "workflowPool", { enumerable: true, get: function () { return pool_js_1.workflowPool; } });
20
29
  Object.defineProperty(exports, "agentPool", { enumerable: true, get: function () { return pool_js_1.agentPool; } });
21
30
  Object.defineProperty(exports, "modelPool", { enumerable: true, get: function () { return pool_js_1.modelPool; } });
31
+ /** Metadata follows the actual decorated target, independently of decorator order. */
32
+ const intentKey = Symbol.for('@jangts/agent-core/tool-intent-metadata/v1');
33
+ const realm = globalThis;
34
+ const intentMetadata = realm[intentKey] ?? new WeakMap();
35
+ if (!realm[intentKey])
36
+ Object.defineProperty(globalThis, intentKey, { value: intentMetadata });
37
+ /** Mark a WorkflowTool for demand discovery; alone this decorator registers nothing. */
38
+ function Intent(metadata = true) {
39
+ const normalized = (0, tool_conditions_js_1.snapshotIntent)(metadata);
40
+ return (value, context) => {
41
+ if (context.kind !== 'class' && context.kind !== 'method')
42
+ throw new TypeError('Intent requires a class or method');
43
+ if (intentMetadata.has(value))
44
+ throw new TypeError('Duplicate Intent decoration');
45
+ intentMetadata.set(value, normalized);
46
+ };
47
+ }
22
48
  /** Internal conversion shared by node/tool/fragment; never a public free-function adapter. */
23
49
  function decorate(kind, id, options, key, compile) {
24
50
  return (value, context) => {
51
+ const convert = (definition) => {
52
+ if (kind !== 'tool')
53
+ return compile(definition);
54
+ if ('asIntent' in definition)
55
+ throw new TypeError('Use @Intent instead of asIntent in @WorkflowTool');
56
+ const metadata = intentMetadata.get(value);
57
+ // Intent metadata is collected before class/method initializers compile definitions.
58
+ if (metadata !== undefined)
59
+ Object.defineProperty(definition, 'asIntent', { value: metadata, enumerable: true });
60
+ return compile(definition);
61
+ };
25
62
  if (context?.kind === 'class') {
26
- (0, definition_js_1.classDecoration)(kind, id, options, compile)(value, context);
63
+ (0, definition_js_1.classDecoration)(kind, id, options, convert)(value, context);
27
64
  }
28
65
  else {
29
66
  const { ns, ...metadata } = options;
30
- (0, definition_js_1.methodDecoration)(kind, id, metadata, key, { ns }, compile)(value, context);
67
+ (0, definition_js_1.methodDecoration)(kind, id, metadata, key, { ns }, convert)(value, context);
31
68
  }
32
69
  };
33
70
  }
@@ -35,7 +72,12 @@ function node(id, options = {}) {
35
72
  return decorate('node', id, options, 'run', (value) => value);
36
73
  }
37
74
  function tool(id, options = {}) {
38
- return decorate('tool', id, options, 'execute', (value) => (0, tools_js_1.defineTool)(value));
75
+ if ('asIntent' in options)
76
+ throw new TypeError('Use @Intent instead of asIntent in @WorkflowTool');
77
+ const handlerKey = 'inputSchema' in options && !('authorize' in options) ? 'resolve' : 'execute';
78
+ return decorate('tool', id, options, handlerKey, (value) => 'kind' in value || 'authorize' in value || 'execute' in value
79
+ ? (0, tools_js_1.defineTool)(value)
80
+ : (0, capabilities_js_1.defineModelTools)([value]).require(value.id));
39
81
  }
40
82
  function fragment(id, options = {}) {
41
83
  return decorate('fragment', id, options, 'format', (value) => {
@@ -42,3 +42,4 @@ Object.defineProperty(exports, "createReplyPreview", { enumerable: true, get: fu
42
42
  __exportStar(require("./capabilities.js"), exports);
43
43
  var decision_retry_js_1 = require("../model/decision-retry.js");
44
44
  Object.defineProperty(exports, "retryMultipleModelCalls", { enumerable: true, get: function () { return decision_retry_js_1.retryMultipleModelCalls; } });
45
+ __exportStar(require("./associations.js"), exports);
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineModelCapabilities = defineModelCapabilities;
3
+ exports.defineModelTools = defineModelTools;
4
4
  /**
5
5
  * Model capability catalog: seal a typed declaration list into a reusable catalog.
6
6
  *
7
7
  * The catalog is a frozen snapshot, so mutating the original declaration list cannot widen the
8
- * result type or add capabilities at runtime. Resolution stays inside Core's registry; Support only
8
+ * result type or add tools at runtime. Resolution stays inside Core's registry; Support only
9
9
  * projects the declarations and their output type.
10
10
  *
11
- * Main export: `defineModelCapabilities`.
11
+ * Main export: `defineModelTools`.
12
12
  */
13
13
  const catalog_js_1 = require("../../utils/catalog.js");
14
14
  const model_js_1 = require("../../capabilities/model.js");
@@ -22,10 +22,40 @@ const model_js_1 = require("../../capabilities/model.js");
22
22
  * unknown ID.
23
23
  * @throws {Error} When a resolver is asynchronous.
24
24
  */
25
- function defineModelCapabilities(definitions) {
26
- const registry = new model_js_1.ModelCapabilityRegistry(definitions).seal();
25
+ function defineModelTools(definitions) {
26
+ const registry = new model_js_1.ModelToolRegistry(definitions.map(modelDefinition)).seal();
27
+ return project(registry);
28
+ }
29
+ /** Executable tools propose raw arguments; business parsing occurs once at execution. */
30
+ function modelDefinition(definition) {
31
+ const executable = definition;
32
+ if (typeof executable.execute !== 'function')
33
+ return definition;
34
+ if (typeof executable.authorize !== 'function' || typeof executable.parseOutput !== 'function')
35
+ throw new TypeError('Missing executable tool handler');
36
+ const id = definition.id;
37
+ return {
38
+ id,
39
+ description: definition.description,
40
+ active: typeof definition.active === 'function'
41
+ ? definition.active.bind(definition)
42
+ : definition.active,
43
+ asIntent: typeof definition.asIntent === 'function'
44
+ ? definition.asIntent.bind(definition)
45
+ : definition.asIntent,
46
+ inputSchema: {
47
+ jsonSchema: definition.inputSchema.jsonSchema,
48
+ parse: (input) => input,
49
+ },
50
+ resolve: (input) => ({ toolId: id, input }),
51
+ };
52
+ }
53
+ /** Project existing immutable entries without re-registering schemas or rebinding handlers. */
54
+ function project(registry) {
27
55
  return Object.freeze({
28
56
  ...(0, catalog_js_1.readonlyCatalog)(registry.definitions, (id) => new TypeError(`Unknown model capability: ${id}`)),
29
57
  resolve: (selection, stage) => registry.resolve(selection, stage),
58
+ select: (ids, ...context) => project(context.length ? registry.select(ids, context[0]) : registry.select(ids)),
59
+ withIntent: (context) => project(registry.withIntent(context)),
30
60
  });
31
61
  }
@@ -19,10 +19,19 @@ function chatCompletionFunctionOptions(options) {
19
19
  return {};
20
20
  if (!options.functions.length)
21
21
  throw new TypeError('Empty model function catalog');
22
+ if (options.toolChoice !== undefined &&
23
+ !['auto', 'required', 'none'].includes(options.toolChoice))
24
+ throw new TypeError('Invalid toolChoice');
25
+ if (options.parallelToolCalls !== undefined &&
26
+ options.parallelToolCalls !== 'omit' &&
27
+ typeof options.parallelToolCalls !== 'boolean')
28
+ throw new TypeError('Invalid parallelToolCalls');
22
29
  return {
23
30
  tools: options.functions.map((fn) => ({ type: 'function', function: fn })),
24
- tool_choice: 'required',
25
- parallel_tool_calls: false,
31
+ tool_choice: options.toolChoice ?? 'required',
32
+ ...(options.parallelToolCalls === 'omit'
33
+ ? {}
34
+ : { parallel_tool_calls: options.parallelToolCalls ?? false }),
26
35
  };
27
36
  }
28
37
  /**
@@ -1,61 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createToolCallCollector = createToolCallCollector;
4
- const model_protocol_js_1 = require("../../../utils/model-protocol.js");
3
+ exports.createToolCallCollector = void 0;
5
4
  /**
6
- * Create a collector for one response.
5
+ * Tool-call delta aggregation, re-exported from Core.
7
6
  *
8
- * @param fail - Protocol failure factory; defaults to the Core model protocol error.
9
- * @returns A collector that keeps its own state and never shares it with another response.
7
+ * The algorithm lives in `model/interactions/calls.ts` so session transports and
8
+ * completion policies share one implementation. This module keeps the existing
9
+ * Support import path stable.
10
+ *
11
+ * Exports: `AggregatedToolCall`, `ToolCallCollector`, `ToolCallFailure` and
12
+ * `createToolCallCollector`.
10
13
  */
11
- function createToolCallCollector(fail = model_protocol_js_1.modelProtocolError) {
12
- const pending = new Map();
13
- const ids = new Set();
14
- const calls = () => [...pending.entries()]
15
- .sort(([left], [right]) => left - right)
16
- .map(([index, call]) => ({ index, ...call }));
17
- return {
18
- push(part) {
19
- if (typeof part === 'string')
20
- return;
21
- if (!part || typeof part !== 'object' || Array.isArray(part))
22
- fail('Expected a native model call');
23
- const { type, index, id, name, arguments: args } = part;
24
- if (type !== 'function-call-delta')
25
- fail('Expected a native model call');
26
- if (!Number.isInteger(index) || index < 0)
27
- fail('Invalid model call index');
28
- if ((id !== undefined && (typeof id !== 'string' || !id)) ||
29
- (name !== undefined && typeof name !== 'string') ||
30
- (args !== undefined && typeof args !== 'string'))
31
- fail('Invalid model call fields');
32
- let call = pending.get(index);
33
- if (!call) {
34
- call = { id: '', name: '', arguments: '' };
35
- pending.set(index, call);
36
- }
37
- if (id !== undefined) {
38
- if (call.id && call.id !== id)
39
- fail('Conflicting model call IDs');
40
- if (!call.id) {
41
- if (ids.has(id))
42
- fail('Duplicate model call ID');
43
- ids.add(id);
44
- call.id = id;
45
- }
46
- }
47
- call.name += name ?? '';
48
- call.arguments += args ?? '';
49
- },
50
- get calls() {
51
- return calls();
52
- },
53
- complete() {
54
- const completed = calls();
55
- for (const call of completed)
56
- if (!call.id || !call.name)
57
- fail('Incomplete model call');
58
- return completed;
59
- },
60
- };
61
- }
14
+ var calls_js_1 = require("../../../model/interactions/calls.js");
15
+ Object.defineProperty(exports, "createToolCallCollector", { enumerable: true, get: function () { return calls_js_1.createToolCallCollector; } });
@@ -83,29 +83,29 @@ function previewSnapshot(preview) {
83
83
  * Capabilities without preview metadata are skipped even when their stage opts in. Default paths
84
84
  * are `text` and `bubbles[*]`, each kept only when the capability schema declares it.
85
85
  *
86
- * @param options Stage declarations and the capabilities they may reference.
86
+ * @param options Stage declarations and the tools they may reference.
87
87
  * @returns Frozen rules in stage order, each with deep-frozen paths and eligibility.
88
88
  * @throws {Error} When a capability or stage ID repeats, a stage references an unknown capability,
89
89
  * a preview mode is unknown, or a preview path or eligibility field is absent from the schema.
90
90
  */
91
91
  function createReplyPreviewRules(options) {
92
- const capabilities = new Map();
93
- for (const capability of options.capabilities) {
92
+ const tools = new Map();
93
+ for (const capability of options.tools) {
94
94
  const id = capability.id;
95
- (0, rules_js_1.breakWhile)(!id || capabilities.has(id), 'Duplicate preview capability declaration');
95
+ (0, rules_js_1.breakWhile)(!id || tools.has(id), 'Duplicate preview capability declaration');
96
96
  const preview = previewSnapshot(capability.preview);
97
97
  // Validate and emit the same canonical snapshot, never reread App getters.
98
98
  const jsonSchema = preview ? structuredClone(capability.jsonSchema) : {};
99
- capabilities.set(id, { id, preview, jsonSchema });
99
+ tools.set(id, { id, preview, jsonSchema });
100
100
  }
101
101
  const stages = new Set(), rules = [];
102
102
  for (const stage of options.stages) {
103
- const { id: stageId, preview, capabilityIds } = stage;
103
+ const { id: stageId, preview, toolIds } = stage;
104
104
  (0, rules_js_1.breakWhile)(!stageId || stages.has(stageId), 'Duplicate preview stage declaration');
105
105
  stages.add(stageId);
106
- const ids = capabilityIds === undefined ? [] : stringList(capabilityIds, 'capability IDs');
107
- (0, rules_js_1.breakWhile)(new Set(ids).size !== ids.length || ids.some((id) => !capabilities.has(id)), 'Preview stage references an unknown capability');
108
- (0, rules_js_1.breakWhile)(preview !== undefined && !['text', 'capabilities'].includes(preview), 'Unknown preview stage mode');
106
+ const ids = toolIds === undefined ? [] : stringList(toolIds, 'capability IDs');
107
+ (0, rules_js_1.breakWhile)(new Set(ids).size !== ids.length || ids.some((id) => !tools.has(id)), 'Preview stage references an unknown capability');
108
+ (0, rules_js_1.breakWhile)(preview !== undefined && !['text', 'tools'].includes(preview), 'Unknown preview stage mode');
109
109
  if (!preview)
110
110
  continue;
111
111
  if (preview === 'text') {
@@ -114,7 +114,7 @@ function createReplyPreviewRules(options) {
114
114
  continue;
115
115
  }
116
116
  for (const id of ids) {
117
- const capability = capabilities.get(id);
117
+ const capability = tools.get(id);
118
118
  if (!capability.preview)
119
119
  continue;
120
120
  const source = capability.preview === true ? {} : capability.preview;
@@ -130,7 +130,7 @@ function createReplyPreviewRules(options) {
130
130
  Object.freeze({ path: Object.freeze(when.path), values: Object.freeze(when.values) });
131
131
  rules.push(Object.freeze({
132
132
  stageId,
133
- capabilityId: (0, arguments_js_1.wireName)(id),
133
+ toolId: (0, arguments_js_1.wireName)(id),
134
134
  paths: emittedPaths,
135
135
  ...(emittedWhen ? { when: emittedWhen } : {}),
136
136
  }));
@@ -199,7 +199,7 @@ function createReplyPreview(options) {
199
199
  if (!Number.isSafeInteger(maxChars) || maxChars < 1)
200
200
  throw new TypeError('Invalid reply preview budget');
201
201
  const rules = options.rules.map((rule) => Object.freeze({
202
- capabilityId: rule.capabilityId,
202
+ toolId: rule.toolId,
203
203
  stageId: rule.stageId,
204
204
  paths: rule.paths === undefined ? undefined : structuredClone(rule.paths),
205
205
  when: rule.when === undefined ? undefined : structuredClone(rule.when),
@@ -261,7 +261,7 @@ function createReplyPreview(options) {
261
261
  return;
262
262
  }
263
263
  if (typeof part === 'string') {
264
- const rule = rules.find((rule) => !rule.capabilityId && rule.stageId === event.payload.stageId);
264
+ const rule = rules.find((rule) => !rule.toolId && rule.stageId === event.payload.stageId);
265
265
  if (!rule) {
266
266
  if (part.trim()) {
267
267
  disabled = true;
@@ -279,7 +279,7 @@ function createReplyPreview(options) {
279
279
  return;
280
280
  }
281
281
  name += part.name ?? '';
282
- const rule = rules.find((rule) => rule.capabilityId === name && (!rule.stageId || rule.stageId === event.payload.stageId));
282
+ const rule = rules.find((rule) => rule.toolId === name && (!rule.stageId || rule.stageId === event.payload.stageId));
283
283
  if (!rule) {
284
284
  if (selected) {
285
285
  disabled = true;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareSessionFunctions = prepareSessionFunctions;
4
+ exports.createSessionModelTransport = createSessionModelTransport;
5
+ /**
6
+ * Session transport policy: one response may contain prose and several tool calls.
7
+ *
8
+ * Core owns the raw `ModelSessionResult`; this Support module adds the host-facing
9
+ * resolution fields (`toolId`, parsed `input`, non-fatal `problem`) and the transport
10
+ * that advertises the stage's tools. Keeping the resolution policy here prevents Core
11
+ * from depending on tool catalogs or business error categories.
12
+ *
13
+ * Exports: `ResolvedSessionCall`, `ResolvedSessionResult`, `PreparedSessionTransport`,
14
+ * `SessionFunctionOptions`, `SessionModelTransportRegistration`, `prepareSessionFunctions`
15
+ * and `createSessionModelTransport`.
16
+ */
17
+ const arguments_js_1 = require("../../model/interactions/arguments.js");
18
+ const calls_js_1 = require("../../model/interactions/calls.js");
19
+ const options_js_1 = require("../../model/options.js");
20
+ const model_protocol_js_1 = require("../../utils/model-protocol.js");
21
+ /**
22
+ * Parse one call's raw arguments without failing the whole response.
23
+ *
24
+ * @param raw - Raw JSON text; an empty string means an empty argument object.
25
+ * @returns The parsed object, or undefined when the text is not a JSON object.
26
+ */
27
+ function parseArguments(raw) {
28
+ try {
29
+ const value = JSON.parse(raw === '' ? '{}' : raw);
30
+ return value && typeof value === 'object' && !Array.isArray(value)
31
+ ? value
32
+ : undefined;
33
+ }
34
+ catch {
35
+ return undefined;
36
+ }
37
+ }
38
+ /**
39
+ * Build the session policy for one stage.
40
+ *
41
+ * @param tools - Registered tools available in this stage; must be non-empty.
42
+ * @param options - Sampling and tool-selection settings.
43
+ * @returns A prepared transport whose collector returns text and every completed call.
44
+ * @throws TypeError When the tool list is empty or two ids collide on the wire name.
45
+ */
46
+ function prepareSessionFunctions(tools, options = {}) {
47
+ if (!tools.length)
48
+ throw new TypeError('Session transport requires registered tools');
49
+ const names = new Map(tools.map((tool) => [(0, arguments_js_1.wireName)(tool.id), tool.id]));
50
+ if (names.size !== tools.length)
51
+ throw new TypeError('Model wire name collision');
52
+ const functions = tools.map((tool) => ({
53
+ name: (0, arguments_js_1.wireName)(tool.id),
54
+ description: tool.description,
55
+ parameters: tool.inputSchema.jsonSchema,
56
+ strict: false,
57
+ }));
58
+ const instruction = 'You may answer directly or call one or more registered tools. Prose and calls may appear together. A call is a proposal, not proof of execution.';
59
+ return {
60
+ options: {
61
+ json: false,
62
+ functions,
63
+ toolChoice: options.toolChoice ?? 'auto',
64
+ ...(options.parallelToolCalls === undefined
65
+ ? {}
66
+ : { parallelToolCalls: options.parallelToolCalls }),
67
+ ...(options.temperature === undefined ? {} : { temperature: options.temperature }),
68
+ },
69
+ schemaChars: JSON.stringify(functions).length + instruction.length,
70
+ instruction,
71
+ createResponse() {
72
+ const collector = (0, calls_js_1.createToolCallCollector)();
73
+ let text = '';
74
+ return {
75
+ get outputChars() {
76
+ return (text.length +
77
+ collector.calls.reduce((sum, call) => sum + call.id.length + call.name.length + call.arguments.length, 0));
78
+ },
79
+ get calls() {
80
+ try {
81
+ return collector.complete().map((call) => ({
82
+ id: call.id,
83
+ name: call.name,
84
+ argumentChars: call.arguments.length,
85
+ toolId: names.get(call.name),
86
+ }));
87
+ }
88
+ catch {
89
+ return undefined;
90
+ }
91
+ },
92
+ push(part) {
93
+ if (typeof part === 'string') {
94
+ text += part;
95
+ return;
96
+ }
97
+ collector.push(part);
98
+ },
99
+ finish() {
100
+ const completed = collector.complete();
101
+ if (text.trim() === '' && completed.length === 0)
102
+ (0, model_protocol_js_1.modelProtocolError)('Model response is empty', 'MODEL_INCOMPLETE');
103
+ const calls = completed.map((call) => {
104
+ const toolId = names.get(call.name);
105
+ const input = parseArguments(call.arguments);
106
+ return {
107
+ index: call.index,
108
+ id: call.id,
109
+ name: call.name,
110
+ arguments: call.arguments,
111
+ argumentChars: call.arguments.length,
112
+ ...(toolId === undefined ? {} : { toolId }),
113
+ ...(input === undefined ? {} : { input }),
114
+ ...(toolId === undefined
115
+ ? { problem: 'unknown-tool' }
116
+ : input === undefined
117
+ ? { problem: 'invalid-arguments' }
118
+ : {}),
119
+ };
120
+ });
121
+ return { text, calls };
122
+ },
123
+ };
124
+ },
125
+ };
126
+ }
127
+ /**
128
+ * Create a session transport.
129
+ *
130
+ * @param registration - Transport id, tool source and optional settings.
131
+ * @returns A frozen transport definition whose result contains text and every completed call.
132
+ * @throws TypeError When the id is blank.
133
+ */
134
+ function createSessionModelTransport(registration) {
135
+ const id = registration.id;
136
+ if (typeof id !== 'string' || !id.trim())
137
+ throw new TypeError('Session transport requires an ID');
138
+ const source = registration.tools;
139
+ const options = (0, options_js_1.snapshotModelOptions)(registration.options ?? {});
140
+ return Object.freeze({
141
+ id,
142
+ prepare() {
143
+ return prepareSessionFunctions([...source.values()], {
144
+ ...(options.temperature === undefined ? {} : { temperature: options.temperature }),
145
+ ...(options.toolChoice === undefined ? {} : { toolChoice: options.toolChoice }),
146
+ ...(options.parallelToolCalls === undefined
147
+ ? {}
148
+ : { parallelToolCalls: options.parallelToolCalls }),
149
+ });
150
+ },
151
+ });
152
+ }