@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
@@ -10,6 +10,7 @@ exports.retryMultipleModelCalls = retryMultipleModelCalls;
10
10
  *
11
11
  * Exports: `retryMultipleModelCalls`.
12
12
  */
13
+ const native_sub_flow_js_1 = require("../diagnostics/native-sub-flow.js");
13
14
  const errors_js_1 = require("../errors.js");
14
15
  /**
15
16
  * Retry once when the failure is a rejected multi-call proposal.
@@ -28,6 +29,6 @@ async function retryMultipleModelCalls(request) {
28
29
  catch (error) {
29
30
  if (!(0, errors_js_1.getErrorInfo)(error).codes.includes('MODEL_MULTIPLE_CALLS'))
30
31
  throw error;
31
- return request.retry(error);
32
+ return (0, native_sub_flow_js_1.nativeSubFlowAsync)(request, 'retry', 'MODEL_MULTIPLE_CALLS', () => request.retry(error));
32
33
  }
33
34
  }
@@ -18,14 +18,10 @@ exports.modelRunnerDefaults = void 0;
18
18
  /**
19
19
  * Public surface of the model protocol layer.
20
20
  *
21
- * Re-exports the runner, the provider and transport contracts, the interaction
22
- * adapters and the defaults. Everything that interprets model output passes through
23
- * this module, so consumers should not import the individual files.
21
+ * Re-exports the runner and the provider/transport contracts. Support implementations are
22
+ * exported from the package root or `/support`; this Core barrel stays free of Support code.
24
23
  */
25
24
  __exportStar(require("./runner.js"), exports);
26
25
  __exportStar(require("../structs/model/chat-provider.js"), exports);
27
- __exportStar(require("../support/model/compatible-provider.js"), exports);
28
- __exportStar(require("../support/model/transports.js"), exports);
29
- __exportStar(require("../support/model/interactions/index.js"), exports);
30
26
  var defaults_js_1 = require("./defaults.js");
31
27
  Object.defineProperty(exports, "modelRunnerDefaults", { enumerable: true, get: function () { return defaults_js_1.modelRunnerDefaults; } });
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createToolCallCollector = createToolCallCollector;
4
+ const model_protocol_js_1 = require("../../utils/model-protocol.js");
5
+ /**
6
+ * Create a collector for one response.
7
+ *
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.
10
+ */
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
+ }
@@ -25,24 +25,24 @@ exports.jsonObjectInteraction = Object.freeze({
25
25
  /**
26
26
  * Build the instruction and response collector for one stage.
27
27
  *
28
- * @param capabilities - Capabilities registered for this stage; must be non-empty.
28
+ * @param tools - Capabilities registered for this stage; must be non-empty.
29
29
  * @returns JSON mode options, the measured instruction and the collector factory.
30
30
  */
31
- prepare(capabilities) {
32
- const declarations = capabilities.map(({ id, description, inputSchema }) => ({
31
+ prepare(tools) {
32
+ const declarations = tools.map(({ id, description, inputSchema }) => ({
33
33
  id,
34
34
  description,
35
35
  input: inputSchema.jsonSchema,
36
36
  }));
37
37
  // Keep the wire shape after potentially long schemas so it cannot be mistaken
38
38
  // for a schema definition or a bare capability argument object.
39
- const instruction = 'Registered capabilities: ' +
39
+ const instruction = 'Registered tools: ' +
40
40
  JSON.stringify(declarations) +
41
- '\nReturn exactly one JSON object with exactly these two fields: {"capability":"registered id","input":{...}}. ' +
42
- 'Choose capability from ' +
43
- JSON.stringify(capabilities.map((capability) => capability.id)) +
44
- "; input is the chosen capability's actual argument object matching its input schema. " +
45
- 'Do not return the schema, response_format, an array, multiple calls, prose or fences. The outer object must contain capability and input.';
41
+ '\nReturn exactly one JSON object with exactly these two fields: {"name":"registered id","input":{...}}. ' +
42
+ 'Choose tool name from ' +
43
+ JSON.stringify(tools.map((capability) => capability.id)) +
44
+ "; input is the chosen tool's actual argument object matching its input schema. " +
45
+ 'Do not return the schema, response_format, an array, multiple calls, prose or fences. The outer object must contain name and input.';
46
46
  return {
47
47
  options: { json: true },
48
48
  schemaChars: instruction.length,
@@ -61,10 +61,10 @@ exports.jsonObjectInteraction = Object.freeze({
61
61
  finish() {
62
62
  const value = (0, arguments_js_1.parse)(raw);
63
63
  if (Object.keys(value).length !== 2 ||
64
- typeof value.capability !== 'string' ||
64
+ typeof value.name !== 'string' ||
65
65
  !Object.hasOwn(value, 'input'))
66
66
  (0, model_protocol_js_1.modelProtocolError)('Invalid model selection envelope');
67
- return { capabilityId: value.capability, input: (0, arguments_js_1.object)(value.input) };
67
+ return { toolId: value.name, input: (0, arguments_js_1.object)(value.input) };
68
68
  },
69
69
  };
70
70
  },
@@ -12,6 +12,7 @@ exports.nativeFunctionInteraction = void 0;
12
12
  */
13
13
  const model_protocol_js_1 = require("../../utils/model-protocol.js");
14
14
  const arguments_js_1 = require("./arguments.js");
15
+ const calls_js_1 = require("./calls.js");
15
16
  /**
16
17
  * Adapter that decodes a streamed native function call.
17
18
  *
@@ -27,15 +28,15 @@ exports.nativeFunctionInteraction = Object.freeze({
27
28
  * Wire names are derived from capability ids and must stay unique after mapping;
28
29
  * a collision would make it impossible to resolve the proposed name back to an id.
29
30
  *
30
- * @param capabilities - Capabilities registered for this stage; must be non-empty.
31
+ * @param tools - Capabilities registered for this stage; must be non-empty.
31
32
  * @returns Function declarations, the measured instruction and the collector factory.
32
33
  * @throws TypeError When two capability ids map to the same wire name.
33
34
  */
34
- prepare(capabilities) {
35
- const names = new Map(capabilities.map((capability) => [(0, arguments_js_1.wireName)(capability.id), capability.id]));
36
- if (names.size !== capabilities.length)
35
+ prepare(tools) {
36
+ const names = new Map(tools.map((capability) => [(0, arguments_js_1.wireName)(capability.id), capability.id]));
37
+ if (names.size !== tools.length)
37
38
  throw new TypeError('Model wire name collision');
38
- const functions = capabilities.map((capability) => ({
39
+ const functions = tools.map((capability) => ({
39
40
  name: (0, arguments_js_1.wireName)(capability.id),
40
41
  description: capability.description,
41
42
  parameters: capability.inputSchema.jsonSchema,
@@ -47,11 +48,12 @@ exports.nativeFunctionInteraction = Object.freeze({
47
48
  schemaChars: JSON.stringify(functions).length + instruction.length,
48
49
  instruction,
49
50
  createResponse() {
51
+ const collector = (0, calls_js_1.createToolCallCollector)();
50
52
  let raw = '';
51
- let call;
52
53
  return {
53
54
  get outputChars() {
54
- return (raw.length + (call ? call.id.length + call.name.length + call.arguments.length : 0));
55
+ return (raw.length +
56
+ collector.calls.reduce((sum, call) => sum + call.id.length + call.name.length + call.arguments.length, 0));
55
57
  },
56
58
  push(part) {
57
59
  if (typeof part === 'string') {
@@ -60,32 +62,24 @@ exports.nativeFunctionInteraction = Object.freeze({
60
62
  }
61
63
  if (!part || typeof part !== 'object' || Array.isArray(part))
62
64
  (0, model_protocol_js_1.modelProtocolError)('Expected a native model call');
63
- const { type, index, id, name, arguments: args } = part;
65
+ const { type, index } = part;
64
66
  if (type !== 'function-call-delta')
65
67
  (0, model_protocol_js_1.modelProtocolError)('Expected a native model call');
66
68
  if (index !== 0)
67
69
  (0, model_protocol_js_1.modelProtocolError)('Expected exactly one model call', 'MODEL_MULTIPLE_CALLS');
68
- if ((id !== undefined && (typeof id !== 'string' || !id)) ||
69
- (name !== undefined && typeof name !== 'string') ||
70
- (args !== undefined && typeof args !== 'string'))
71
- (0, model_protocol_js_1.modelProtocolError)('Invalid native model call fields');
72
- call ??= { id: '', name: '', arguments: '' };
73
- if (id !== undefined) {
74
- if (call.id && call.id !== id)
75
- (0, model_protocol_js_1.modelProtocolError)('Conflicting model call IDs');
76
- call.id = id;
77
- }
78
- call.name += name ?? '';
79
- call.arguments += args ?? '';
70
+ collector.push(part);
80
71
  },
81
72
  finish() {
82
- if (!call?.id || !call.name || raw.trim())
73
+ const calls = collector.complete();
74
+ if (calls.length !== 1)
75
+ (0, model_protocol_js_1.modelProtocolError)('Expected exactly one model call', 'MODEL_MULTIPLE_CALLS');
76
+ if (raw.trim())
83
77
  (0, model_protocol_js_1.modelProtocolError)('Expected one complete model call without prose');
84
- const completed = call;
78
+ const completed = calls[0];
85
79
  const capability = names.get(completed.name) ??
86
80
  (0, model_protocol_js_1.modelProtocolError)('Model call is not registered for this stage');
87
81
  return {
88
- capabilityId: capability,
82
+ toolId: capability,
89
83
  input: (0, arguments_js_1.parse)(completed.arguments),
90
84
  call: {
91
85
  id: completed.id,
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.modelMessageDiagnostics = modelMessageDiagnostics;
4
4
  /**
5
- * Replace every image payload with a placeholder.
5
+ * Replace every image payload and raw tool argument with a placeholder.
6
6
  *
7
7
  * Only the `url` is substituted; the `detail` hint is kept because it is small and
8
- * explains how the image was interpreted. The input array is not mutated.
8
+ * explains how the image was interpreted. Tool call ids and names remain because they
9
+ * identify the proposal; raw arguments are redacted. The input array is not mutated.
9
10
  *
10
11
  * @param messages - Messages about to be reported.
11
- * @returns New message objects whose images carry a placeholder URL.
12
+ * @returns New message objects with redacted images and tool arguments.
12
13
  */
13
14
  function modelMessageDiagnostics(messages) {
14
15
  return messages.map((message) => ({
@@ -18,5 +19,14 @@ function modelMessageDiagnostics(messages) {
18
19
  images: message.images.map((image) => ({ ...image, url: '[image omitted]' })),
19
20
  }
20
21
  : {}),
22
+ ...(message.toolCalls
23
+ ? {
24
+ toolCalls: message.toolCalls.map((call) => ({
25
+ id: call.id,
26
+ name: call.name,
27
+ arguments: '[tool arguments omitted]',
28
+ })),
29
+ }
30
+ : {}),
21
31
  }));
22
32
  }
@@ -18,6 +18,8 @@ function snapshotModelOptions(options = {}) {
18
18
  includeUsage: options.includeUsage,
19
19
  onUsage: options.onUsage?.bind(options),
20
20
  functions: options.functions,
21
+ toolChoice: options.toolChoice,
22
+ parallelToolCalls: options.parallelToolCalls,
21
23
  };
22
24
  for (const key of Object.keys(snapshot)) {
23
25
  if (!(key in options))
@@ -39,6 +39,23 @@ function snapshotImage(image) {
39
39
  (detail !== undefined && !['auto', 'low', 'high', 'original'].includes(detail)), () => new TypeError('Invalid model image'));
40
40
  return Object.freeze({ url, ...(detail === undefined ? {} : { detail }) });
41
41
  }
42
+ /**
43
+ * Validate and freeze one assistant tool declaration.
44
+ *
45
+ * @param call - Candidate tool call.
46
+ * @returns A frozen tool call with only the declared fields.
47
+ * @throws TypeError When the id, name or raw arguments are invalid.
48
+ */
49
+ function snapshotToolCall(call) {
50
+ (0, rules_js_1.breakWhile)(!call || typeof call !== 'object' || Array.isArray(call), () => new TypeError('Invalid model tool call'));
51
+ const { id, name, arguments: args } = call;
52
+ (0, rules_js_1.breakWhile)(typeof id !== 'string' ||
53
+ !id ||
54
+ typeof name !== 'string' ||
55
+ !name ||
56
+ typeof args !== 'string', () => new TypeError('Invalid model tool call'));
57
+ return Object.freeze({ id, name, arguments: args });
58
+ }
42
59
  /**
43
60
  * Snapshot a dynamic transport once, preserving its collector factory receiver.
44
61
  *
@@ -99,19 +116,35 @@ function preparedInputSize(base, prepared) {
99
116
  (0, rules_js_1.breakWhile)(!Array.isArray(base), () => new TypeError('Model messages must be an array'));
100
117
  const snapshot = Array.from(base, (message) => {
101
118
  (0, rules_js_1.breakWhile)(!message || typeof message !== 'object' || Array.isArray(message), () => new TypeError('Invalid model message'));
102
- const { role, content, images } = message;
103
- (0, rules_js_1.breakWhile)(!['system', 'user', 'assistant'].includes(role) ||
119
+ const { role, content, images, toolCalls, toolCallId } = message;
120
+ const assistant = role === 'assistant';
121
+ const tool = role === 'tool';
122
+ (0, rules_js_1.breakWhile)(!['system', 'user', 'assistant', 'tool'].includes(role) ||
104
123
  typeof content !== 'string' ||
105
- (images !== undefined && !Array.isArray(images)), () => new TypeError('Invalid model message'));
124
+ (images !== undefined && (!Array.isArray(images) || role !== 'user')) ||
125
+ (toolCalls !== undefined && (!Array.isArray(toolCalls) || !assistant)) ||
126
+ (toolCallId !== undefined &&
127
+ (!tool || typeof toolCallId !== 'string' || toolCallId.length === 0)) ||
128
+ (tool && (typeof toolCallId !== 'string' || toolCallId.length === 0)), () => new TypeError('Invalid model message'));
106
129
  return Object.freeze({
107
130
  role,
108
131
  content,
109
- ...(images === undefined ? {} : { images: Object.freeze(Array.from(images, snapshotImage)) }),
132
+ ...(images === undefined
133
+ ? {}
134
+ : { images: Object.freeze(Array.from(images, snapshotImage)) }),
135
+ ...(toolCalls === undefined
136
+ ? {}
137
+ : { toolCalls: Object.freeze(Array.from(toolCalls, snapshotToolCall)) }),
138
+ ...(toolCallId === undefined ? {} : { toolCallId }),
110
139
  });
111
140
  });
112
141
  const messages = Object.freeze((0, token_budget_js_1.modelInputMessages)(snapshot, prepared.instruction).map((message) => Object.freeze(message)));
113
- const messageChars = snapshot.reduce((sum, message) => sum + message.content.length, 0);
114
- const instructionChars = messages.reduce((sum, message) => sum + message.content.length, 0) - messageChars;
142
+ const contentChars = snapshot.reduce((sum, message) => sum + message.content.length, 0);
143
+ const messageChars = snapshot.reduce((sum, message) => sum +
144
+ message.content.length +
145
+ (message.toolCalls?.reduce((callSum, call) => callSum + call.id.length + call.name.length + call.arguments.length, 0) ?? 0) +
146
+ (message.toolCallId?.length ?? 0), 0);
147
+ const instructionChars = messages.reduce((sum, message) => sum + message.content.length, 0) - contentChars;
115
148
  const functions = prepared.options.functions;
116
149
  const schemaChars = functions
117
150
  ? (functionSizes.get(functions) ?? JSON.stringify(functions).length)
@@ -13,6 +13,8 @@ exports.ModelRunner = exports.BudgetError = void 0;
13
13
  * Exports: `ModelRunner`, the re-exported `BudgetError`, and the runtime/config type
14
14
  * re-exports at the bottom of the file.
15
15
  */
16
+ const sub_flow_js_1 = require("../diagnostics/sub-flow.js");
17
+ const native_sub_flow_js_1 = require("../diagnostics/native-sub-flow.js");
16
18
  const events_js_1 = require("../execution/events.js");
17
19
  const call_budget_js_1 = require("./call-budget.js");
18
20
  const synchronous_js_1 = require("../utils/synchronous.js");
@@ -321,6 +323,19 @@ class ModelRunner {
321
323
  return snapshot;
322
324
  }
323
325
  async invoke(request) {
326
+ const context = typeof request === 'string' ? { logger: undefined, signal: undefined } : request;
327
+ (0, sub_flow_js_1.requireSubFlowLogger)(context.logger);
328
+ const callId = (0, invocation_js_1.invocationId)();
329
+ return (0, native_sub_flow_js_1.nativeSubFlowAsync)({
330
+ logger: context.logger,
331
+ signal: (0, cancellation_js_1.combineSignals)(this.signal, context.signal),
332
+ invocationId: callId,
333
+ }, 'model', typeof request === 'string'
334
+ ? defaults_js_1.modelRunnerDefaults.stage
335
+ : (request.stageId ?? request.prepared?.stageId ?? defaults_js_1.modelRunnerDefaults.stage), () => this.invokeRequest(request, callId));
336
+ }
337
+ /** Validate and execute a single request; optional recording is owned by invoke. */
338
+ async invokeRequest(request, callId) {
324
339
  const call = typeof request === 'string' ? { input: request } : request;
325
340
  const state = call.prepared === undefined ? undefined : this.preparedCalls.get(call.prepared);
326
341
  if (call.prepared !== undefined && (!state || state.used))
@@ -384,7 +399,7 @@ class ModelRunner {
384
399
  throw invalid('Prepared model request settings cannot be replaced');
385
400
  if (state)
386
401
  state.used = true;
387
- return this.invokePrepared(stage, input, tokens, transportId, call.diagnostics, prepared, call.signal);
402
+ return this.invokePrepared(stage, input, tokens, transportId, call.diagnostics, prepared, call.signal, callId);
388
403
  }
389
404
  /**
390
405
  * Acquire the per-runner call slot and execute one call.
@@ -403,7 +418,7 @@ class ModelRunner {
403
418
  * @returns The parsed result with invocation metadata.
404
419
  * @throws Error When a call is already in flight or the request capacity is exhausted.
405
420
  */
406
- async invokePrepared(stage, input, tokens, transportId, diagnostics = this.ports.diagnostics, prepared, requestSignal) {
421
+ async invokePrepared(stage, input, tokens, transportId, diagnostics = this.ports.diagnostics, prepared, requestSignal, callId = (0, invocation_js_1.invocationId)()) {
407
422
  const configuredRun = this.ports.diagnostics?.identity?.runId, selectedRun = diagnostics?.identity?.runId;
408
423
  if (configuredRun && selectedRun && configuredRun !== selectedRun)
409
424
  throw (0, errors_js_1.recordErrorContext)(new TypeError('Model observation parent belongs to a different run'), { stageId: stage, codes: ['MODEL_CONFIG'], isRetryable: false });
@@ -413,7 +428,7 @@ class ModelRunner {
413
428
  this.requestGate.active++;
414
429
  let failure;
415
430
  try {
416
- return await this.execute(stage, input, tokens, transportId, (0, cancellation_js_1.combineSignals)(this.signal, requestSignal), diagnostics, prepared);
431
+ return await this.execute(stage, input, tokens, transportId, (0, cancellation_js_1.combineSignals)(this.signal, requestSignal), diagnostics, prepared, callId);
417
432
  }
418
433
  catch (error) {
419
434
  failure = (0, errors_js_1.recordErrorContext)(error, { stageId: stage });
@@ -444,8 +459,8 @@ class ModelRunner {
444
459
  * @returns The parsed result with invocation metadata.
445
460
  * @throws Error or ValidationError from any phase, decorated with stage context.
446
461
  */
447
- async execute(stage, input, tokens, transportId, signal, parentDiagnostics = this.ports.diagnostics, prepared) {
448
- const id = (0, invocation_js_1.invocationId)(), startedAtMs = Date.now();
462
+ async execute(stage, input, tokens, transportId, signal, parentDiagnostics = this.ports.diagnostics, prepared, callId = (0, invocation_js_1.invocationId)()) {
463
+ const id = callId, startedAtMs = Date.now();
449
464
  this.activeCall = undefined;
450
465
  const invocationDiagnostics = parentDiagnostics?.child(id, {
451
466
  invocationId: id,
@@ -617,6 +632,20 @@ class ModelRunner {
617
632
  catch {
618
633
  /* best-effort metadata */
619
634
  }
635
+ try {
636
+ const calls = response.calls;
637
+ if (calls?.length) {
638
+ step.calls = calls.map((call) => ({
639
+ id: call.id,
640
+ name: call.name,
641
+ argumentChars: call.argumentChars,
642
+ ...(call.toolId === undefined ? {} : { toolId: call.toolId }),
643
+ }));
644
+ }
645
+ }
646
+ catch {
647
+ /* best-effort metadata */
648
+ }
620
649
  };
621
650
  const accountOutput = () => {
622
651
  const outputChars = response.outputChars;
@@ -33,7 +33,7 @@ function createModelTransport(registration) {
33
33
  const adapter = registration.adapter ?? native_functions_js_1.nativeFunctionInteraction;
34
34
  if (registration.requireStrictArguments && !adapter.features.strictArguments)
35
35
  throw new TypeError(`Model interaction does not support strict arguments: ${adapter.id}`);
36
- const source = registration.capabilities, createSource = typeof source === 'function' ? source.bind(registration) : undefined;
36
+ const source = registration.tools, createSource = typeof source === 'function' ? source.bind(registration) : undefined;
37
37
  const prepare = adapter.prepare.bind(adapter), options = Object.freeze((0, options_js_1.snapshotModelOptions)(registration.options));
38
38
  return Object.freeze({
39
39
  id: registration.id,
@@ -43,8 +43,8 @@ function createModelTransport(registration) {
43
43
  : source;
44
44
  const definitions = [...catalog.values()];
45
45
  if (!definitions.length)
46
- throw new TypeError('Model stage requires registered capabilities');
47
- const capabilityIds = new Set(definitions.map((capability) => capability.id));
46
+ throw new TypeError('Model stage requires registered tools');
47
+ const toolIds = new Set(definitions.map((capability) => capability.id));
48
48
  const prepared = (0, synchronous_js_1.synchronous)(prepare(definitions), 'Model interaction preparation must be synchronous');
49
49
  const createResponse = prepared.createResponse.bind(prepared), resolve = catalog.resolve.bind(catalog);
50
50
  return {
@@ -65,7 +65,7 @@ function createModelTransport(registration) {
65
65
  finish() {
66
66
  const selection = (0, synchronous_js_1.synchronous)(buffer.finish(), 'Model selection parsers must be synchronous');
67
67
  call = selection.call;
68
- if (!capabilityIds.has(selection.capabilityId))
68
+ if (!toolIds.has(selection.toolId))
69
69
  (0, model_protocol_js_1.modelProtocolError)('Model capability is unavailable in this prepared call');
70
70
  return (0, synchronous_js_1.synchronous)(resolve(selection, { stageId }), 'Model result parsers must be synchronous');
71
71
  },
@@ -56,6 +56,9 @@ function countModelInput(budget, messages, options) {
56
56
  const snapshot = messages.map((message) => ({
57
57
  ...message,
58
58
  ...(message.images ? { images: message.images.map((image) => ({ ...image })) } : {}),
59
+ ...(message.toolCalls
60
+ ? { toolCalls: message.toolCalls.map((call) => ({ ...call })) }
61
+ : {}),
59
62
  }));
60
63
  const count = budget.countTokens({
61
64
  messages: snapshot,
@@ -49,16 +49,17 @@ function textResponse(decode) {
49
49
  *
50
50
  * @param id - Unique transport id, also used as the typed handle in `ModelRunner`.
51
51
  * @param options - Optional request options; only `temperature` is honored.
52
+ * @param trim - Trim surrounding whitespace from the final text; defaults to true.
52
53
  * @returns A frozen transport definition.
53
54
  */
54
- function createPlainTextTransport(id, options = {}) {
55
+ function createPlainTextTransport(id, options = {}, trim = true) {
55
56
  const settings = Object.freeze({ ...(0, options_js_1.snapshotModelOptions)(options), json: false });
56
57
  return Object.freeze({
57
58
  id,
58
59
  prepare: (_stageId) => ({
59
60
  options: settings,
60
61
  schemaChars: 0,
61
- createResponse: () => textResponse((raw) => raw.trim()),
62
+ createResponse: () => textResponse((raw) => (trim ? raw.trim() : raw)),
62
63
  }),
63
64
  });
64
65
  }
@@ -18,9 +18,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  * Public entry of the structs layer.
19
19
  *
20
20
  * Structs are the shape-only half of agent-core: declarations and frozen constant catalogs that the
21
- * runtime modules (`capabilities`, `context`, `execution`, `model`, `kits`, `support`) both
22
- * implement and consume. Runtime classes declared here only describe shape or initialize fields,
23
- * so importing this barrel never starts execution.
21
+ * runtime modules (`tools`, `context`, `execution`, `model`, `kits`, `support`) both implement and
22
+ * consume. Runtime classes declared here only describe shape or initialize fields, so importing this
23
+ * barrel never starts execution.
24
24
  *
25
25
  * Exports: a curated re-export of the shared vocabulary, error classes, diagnostics/event
26
26
  * envelopes, model and workflow contracts, and the optional Kit protocol definitions.
@@ -35,6 +35,7 @@ __exportStar(require("./model/interactions.js"), exports);
35
35
  __exportStar(require("./context/journal.js"), exports);
36
36
  __exportStar(require("./support/transport/json.js"), exports);
37
37
  __exportStar(require("./model/messages.js"), exports);
38
+ __exportStar(require("./model/session.js"), exports);
38
39
  __exportStar(require("./model/runtime.js"), exports);
39
40
  __exportStar(require("./support/model/provider.js"), exports);
40
41
  __exportStar(require("./kits/interaction.js"), exports);
@@ -48,10 +49,10 @@ __exportStar(require("./kits/evidence.js"), exports);
48
49
  __exportStar(require("./kits/presentation/templates.js"), exports);
49
50
  __exportStar(require("./kits/retrieval.js"), exports);
50
51
  __exportStar(require("./kits/text-skills.js"), exports);
51
- __exportStar(require("./kits/intents/registry.js"), exports);
52
- __exportStar(require("./kits/intents/scopes.js"), exports);
52
+ __exportStar(require("./kits/domains/registry.js"), exports);
53
+ __exportStar(require("./kits/domains/scopes.js"), exports);
53
54
  __exportStar(require("./kits/tools.js"), exports);
54
- __exportStar(require("./kits/intents/catalog.js"), exports);
55
+ __exportStar(require("./kits/domains/catalog.js"), exports);
55
56
  __exportStar(require("./support/registration.js"), exports);
56
57
  __exportStar(require("./diagnostics.js"), exports);
57
58
  __exportStar(require("./support/context.js"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ /**
3
+ * Text block contract for the Text Blocks Kit.
4
+ *
5
+ * Place in the package: an optional App-side helper for splitting long plain text into
6
+ * structure-aware blocks before paging or retrieval. File reading, paging, search, storage
7
+ * and prompt wording stay with the App.
8
+ *
9
+ * Exports: `TextBlock`, `TextBlockOptions`.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ /**
3
+ * Raw session response contracts: one response may carry text and several tool calls.
4
+ *
5
+ * These shapes are Core-only and deliberately contain no host tool resolution. Support's
6
+ * session transport adds `toolId`, parsed `input` and non-fatal `problem` fields in its own
7
+ * `ResolvedSessionResult` type.
8
+ *
9
+ * Exports: `ModelSessionCall`, `ModelSessionResult`.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineAssociatedCatalog = defineAssociatedCatalog;
4
+ /** Compile owner-to-tool relations without parallel intent identities or execution side effects. */
5
+ const catalog_js_1 = require("../utils/catalog.js");
6
+ const synchronous_js_1 = require("../utils/synchronous.js");
7
+ const capabilities_js_1 = require("./model/capabilities.js");
8
+ /** Compile independent and owner-derived Tool declarations, validating all references eagerly. */
9
+ function defineAssociatedCatalog(entries, options = {}) {
10
+ const owners = (0, catalog_js_1.readonlyCatalog)(entries, (id) => new TypeError(`Unknown tool owner: ${id}`));
11
+ const definitions = new Map();
12
+ const sources = new Map();
13
+ const declare = (tool, source) => {
14
+ if (definitions.has(tool.id))
15
+ throw new TypeError(`Duplicate model tool: ${tool.id}`);
16
+ definitions.set(tool.id, tool);
17
+ sources.set(tool.id, [source]);
18
+ };
19
+ const independent = new Set();
20
+ for (const tool of options.tools ?? []) {
21
+ independent.add(tool.id);
22
+ declare(tool, {
23
+ kind: 'standalone',
24
+ id: tool.id,
25
+ description: tool.description,
26
+ toolIds: [tool.id],
27
+ });
28
+ }
29
+ const bindings = owners.definitions.map((owner) => {
30
+ const fallback = options.toolDefaults
31
+ ? (0, synchronous_js_1.synchronous)(options.toolDefaults(owner), 'Tool defaults must be synchronous')
32
+ : undefined;
33
+ const declarations = owner.modelTools ?? (fallback ? [{}] : []);
34
+ const toolIds = [];
35
+ for (const declaration of declarations) {
36
+ if (typeof declaration === 'string') {
37
+ if (!independent.has(declaration))
38
+ throw new TypeError(`Tool reference must name an independent tool: ${owner.id} -> ${declaration}`);
39
+ sources.get(declaration).push({
40
+ kind: 'registration',
41
+ id: owner.id,
42
+ description: owner.description,
43
+ toolIds: [declaration],
44
+ });
45
+ toolIds.push(declaration);
46
+ }
47
+ else {
48
+ if (!declaration || typeof declaration !== 'object' || Array.isArray(declaration))
49
+ throw new TypeError('Invalid tool association');
50
+ const tool = {
51
+ ...fallback,
52
+ ...declaration,
53
+ id: declaration.id ?? fallback?.id ?? owner.id,
54
+ description: declaration.description ?? fallback?.description ?? owner.description,
55
+ resolve: declaration.resolve?.bind(declaration) ?? fallback?.resolve?.bind(fallback),
56
+ };
57
+ declare(tool, {
58
+ kind: 'registration',
59
+ id: owner.id,
60
+ description: owner.description,
61
+ toolIds: [tool.id],
62
+ });
63
+ toolIds.push(tool.id);
64
+ }
65
+ }
66
+ if (new Set(toolIds).size !== toolIds.length)
67
+ throw new TypeError(`Duplicate tool reference: ${owner.id}`);
68
+ return Object.freeze({ id: owner.id, toolIds: Object.freeze(toolIds) });
69
+ });
70
+ return Object.freeze({
71
+ ...owners,
72
+ tools: (0, capabilities_js_1.defineModelTools)([...definitions.values()]),
73
+ bindings: (0, catalog_js_1.readonlyCatalog)(bindings, (id) => new TypeError(`Unknown tool binding: ${id}`)),
74
+ sources: (0, catalog_js_1.readonlyCatalog)([...sources].map(([id, values]) => Object.freeze({
75
+ id,
76
+ sources: Object.freeze(values.map((source) => Object.freeze({ ...source, toolIds: Object.freeze([...source.toolIds]) }))),
77
+ })), (id) => new TypeError(`Unknown tool source: ${id}`)),
78
+ });
79
+ }