@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
@@ -1,5 +1,6 @@
1
1
  import type { WorkflowNode, AgentWorkflowDefinition } from '../../structs/execution/workflow.js';
2
2
  import type { ToolDefinition } from '../../structs/capabilities/tools.js';
3
+ import type { ModelTool } from '../../structs/capabilities/model.js';
3
4
  import type { ContextFragmentConfig } from '../../structs/support/context.js';
4
5
  /** Registration identity; ids are unique within one kind and namespace. */
5
6
  export interface IdentifiedDefinition {
@@ -19,7 +20,7 @@ export declare function registerDefinition(kind: DefinitionKind, definition: Ide
19
20
  /** Decorated nodes; ids are unique within each namespace. */
20
21
  export declare const nodePool: DefinitionReader<WorkflowNode<any, any, any>>;
21
22
  /** Decorated tools; namespaces isolate otherwise identical ids. */
22
- export declare const toolPool: DefinitionReader<ToolDefinition<any, any, any, string>>;
23
+ export declare const toolPool: DefinitionReader<ModelTool<any, any, any> | ToolDefinition<any, any, any>>;
23
24
  /** Decorated fragment configurations; use the original builder to assemble them. */
24
25
  export declare const fragmentPool: DefinitionReader<ContextFragmentConfig<any>>;
25
26
  /** Decorated workflow definitions; execution still belongs to the original Engine. */
@@ -29,7 +30,7 @@ export declare const agentPool: DefinitionReader<(Omit<import("../../index.js").
29
30
  readonly branch?: import("../../index.js").AgentBranch;
30
31
  readonly tools?: {
31
32
  invoke: (request: import("../../index.js").ToolInvocationRequest) => Promise<import("../../index.js").ToolResult<unknown>>;
32
- } | Pick<import("../../index.js").ToolRegistry<import("../../index.js").ExecutableTool>, "invokeAsync">;
33
+ } | Pick<import("../../index.js").ToolRegistry<import("../../index.js").ErasedTool>, "invokeAsync">;
33
34
  } & {
34
35
  model?: import("../../index.js").AgentModelBinding;
35
36
  models?: never;
@@ -42,7 +43,7 @@ export declare const agentPool: DefinitionReader<(Omit<import("../../index.js").
42
43
  readonly branch?: import("../../index.js").AgentBranch;
43
44
  readonly tools?: {
44
45
  invoke: (request: import("../../index.js").ToolInvocationRequest) => Promise<import("../../index.js").ToolResult<unknown>>;
45
- } | Pick<import("../../index.js").ToolRegistry<import("../../index.js").ExecutableTool>, "invokeAsync">;
46
+ } | Pick<import("../../index.js").ToolRegistry<import("../../index.js").ErasedTool>, "invokeAsync">;
46
47
  } & {
47
48
  model?: string;
48
49
  models: Readonly<Record<string, import("../../index.js").AgentModelBinding>>;
@@ -56,7 +57,7 @@ export declare const agentPool: DefinitionReader<(Omit<import("../../index.js").
56
57
  readonly branch?: import("../../index.js").AgentBranch;
57
58
  readonly tools?: {
58
59
  invoke: (request: import("../../index.js").ToolInvocationRequest) => Promise<import("../../index.js").ToolResult<unknown>>;
59
- } | Pick<import("../../index.js").ToolRegistry<import("../../index.js").ExecutableTool>, "invokeAsync">;
60
+ } | Pick<import("../../index.js").ToolRegistry<import("../../index.js").ErasedTool>, "invokeAsync">;
60
61
  } & {
61
62
  model?: import("../../index.js").AgentModelBinding;
62
63
  models?: never;
@@ -70,7 +71,7 @@ export declare const agentPool: DefinitionReader<(Omit<import("../../index.js").
70
71
  readonly branch?: import("../../index.js").AgentBranch;
71
72
  readonly tools?: {
72
73
  invoke: (request: import("../../index.js").ToolInvocationRequest) => Promise<import("../../index.js").ToolResult<unknown>>;
73
- } | Pick<import("../../index.js").ToolRegistry<import("../../index.js").ExecutableTool>, "invokeAsync">;
74
+ } | Pick<import("../../index.js").ToolRegistry<import("../../index.js").ErasedTool>, "invokeAsync">;
74
75
  } & {
75
76
  model?: string;
76
77
  models: Readonly<Record<string, import("../../index.js").AgentModelBinding>>;
@@ -11,7 +11,9 @@ import type { DefinitionBody } from './definition.js';
11
11
  /** A node implementation; its public id is supplied by @node. */
12
12
  export type Node<State, Result, App = undefined> = DefinitionBody<WorkflowNode<State, Result, App>>;
13
13
  /** A tool implementation with the original schema, authorization and execution contracts. */
14
- export type Tool<Input = unknown, Output = unknown, App = unknown> = DefinitionBody<ToolDefinition<Input, Output, App>>;
14
+ export type Tool<Input = unknown, Output = unknown, App = unknown> = DefinitionBody<Omit<ToolDefinition<Input, Output, App>, 'asIntent'>> & {
15
+ readonly asIntent?: never;
16
+ };
15
17
  /** A formatter and its original provenance, trust and budget configuration. */
16
18
  export type Fragment<Input = unknown> = DefinitionBody<ContextFragmentConfig<Input>>;
17
19
  /** A complete graph definition whose workflow id is supplied by @workflow. */
@@ -21,3 +21,4 @@ export type { ReplyPreviewRule, ReplyPreviewOptions } from './model/reply-previe
21
21
  export * from './capabilities.js';
22
22
  export { retryMultipleModelCalls } from '../model/decision-retry.js';
23
23
  export type { RegistrationDefinition } from '../structs/support/registration.js';
24
+ export * from './associations.js';
@@ -18,3 +18,4 @@ export { streamEvents } from './stream-events.js';
18
18
  export { createReplyPreview } from './model/reply-preview.js';
19
19
  export * from './capabilities.js';
20
20
  export { retryMultipleModelCalls } from '../model/decision-retry.js';
21
+ export * from './associations.js';
@@ -1,8 +1,13 @@
1
- import type { ModelCapabilityRegistration, ModelCapabilityCatalog } from '../../structs/capabilities/model.js';
1
+ import type { ModelToolRegistration, ModelToolCatalog } from '../../structs/capabilities/model.js';
2
+ import type { ToolProposal } from '../../structs/capabilities/model.js';
2
3
  /** A sealed typed snapshot. Mutating the original list cannot widen its result contract. */
3
4
  type CapabilityOutput<Definition> = Definition extends {
5
+ execute(...args: any[]): unknown;
6
+ } ? ToolProposal : Definition extends {
4
7
  resolve(...args: any[]): infer Output;
5
- } ? Output : never;
8
+ } ? Output : Definition extends {
9
+ inputSchema: import('../../structs/common.js').SchemaAdapter<infer Input>;
10
+ } ? Input : never;
6
11
  /**
7
12
  * Build a sealed capability catalog from typed declarations.
8
13
  *
@@ -13,5 +18,5 @@ type CapabilityOutput<Definition> = Definition extends {
13
18
  * unknown ID.
14
19
  * @throws {Error} When a resolver is asynchronous.
15
20
  */
16
- export declare function defineModelCapabilities<const Definitions extends readonly ModelCapabilityRegistration[]>(definitions: Definitions): ModelCapabilityCatalog<CapabilityOutput<Definitions[number]>>;
21
+ export declare function defineModelTools<const Definitions extends readonly ModelToolRegistration[]>(definitions: Definitions): ModelToolCatalog<CapabilityOutput<Definitions[number]>>;
17
22
  export {};
@@ -2,13 +2,13 @@
2
2
  * Model capability catalog: seal a typed declaration list into a reusable catalog.
3
3
  *
4
4
  * The catalog is a frozen snapshot, so mutating the original declaration list cannot widen the
5
- * result type or add capabilities at runtime. Resolution stays inside Core's registry; Support only
5
+ * result type or add tools at runtime. Resolution stays inside Core's registry; Support only
6
6
  * projects the declarations and their output type.
7
7
  *
8
- * Main export: `defineModelCapabilities`.
8
+ * Main export: `defineModelTools`.
9
9
  */
10
10
  import { readonlyCatalog } from '../../utils/catalog.js';
11
- import { ModelCapabilityRegistry } from '../../capabilities/model.js';
11
+ import { ModelToolRegistry } from '../../capabilities/model.js';
12
12
  /**
13
13
  * Build a sealed capability catalog from typed declarations.
14
14
  *
@@ -19,10 +19,40 @@ import { ModelCapabilityRegistry } from '../../capabilities/model.js';
19
19
  * unknown ID.
20
20
  * @throws {Error} When a resolver is asynchronous.
21
21
  */
22
- export function defineModelCapabilities(definitions) {
23
- const registry = new ModelCapabilityRegistry(definitions).seal();
22
+ export function defineModelTools(definitions) {
23
+ const registry = new ModelToolRegistry(definitions.map(modelDefinition)).seal();
24
+ return project(registry);
25
+ }
26
+ /** Executable tools propose raw arguments; business parsing occurs once at execution. */
27
+ function modelDefinition(definition) {
28
+ const executable = definition;
29
+ if (typeof executable.execute !== 'function')
30
+ return definition;
31
+ if (typeof executable.authorize !== 'function' || typeof executable.parseOutput !== 'function')
32
+ throw new TypeError('Missing executable tool handler');
33
+ const id = definition.id;
34
+ return {
35
+ id,
36
+ description: definition.description,
37
+ active: typeof definition.active === 'function'
38
+ ? definition.active.bind(definition)
39
+ : definition.active,
40
+ asIntent: typeof definition.asIntent === 'function'
41
+ ? definition.asIntent.bind(definition)
42
+ : definition.asIntent,
43
+ inputSchema: {
44
+ jsonSchema: definition.inputSchema.jsonSchema,
45
+ parse: (input) => input,
46
+ },
47
+ resolve: (input) => ({ toolId: id, input }),
48
+ };
49
+ }
50
+ /** Project existing immutable entries without re-registering schemas or rebinding handlers. */
51
+ function project(registry) {
24
52
  return Object.freeze({
25
53
  ...readonlyCatalog(registry.definitions, (id) => new TypeError(`Unknown model capability: ${id}`)),
26
54
  resolve: (selection, stage) => registry.resolve(selection, stage),
55
+ select: (ids, ...context) => project(context.length ? registry.select(ids, context[0]) : registry.select(ids)),
56
+ withIntent: (context) => project(registry.withIntent(context)),
27
57
  });
28
58
  }
@@ -14,10 +14,19 @@ export function chatCompletionFunctionOptions(options) {
14
14
  return {};
15
15
  if (!options.functions.length)
16
16
  throw new TypeError('Empty model function catalog');
17
+ if (options.toolChoice !== undefined &&
18
+ !['auto', 'required', 'none'].includes(options.toolChoice))
19
+ throw new TypeError('Invalid toolChoice');
20
+ if (options.parallelToolCalls !== undefined &&
21
+ options.parallelToolCalls !== 'omit' &&
22
+ typeof options.parallelToolCalls !== 'boolean')
23
+ throw new TypeError('Invalid parallelToolCalls');
17
24
  return {
18
25
  tools: options.functions.map((fn) => ({ type: 'function', function: fn })),
19
- tool_choice: 'required',
20
- parallel_tool_calls: false,
26
+ tool_choice: options.toolChoice ?? 'required',
27
+ ...(options.parallelToolCalls === 'omit'
28
+ ? {}
29
+ : { parallel_tool_calls: options.parallelToolCalls ?? false }),
21
30
  };
22
31
  }
23
32
  /**
@@ -1,40 +1,12 @@
1
1
  /**
2
- * Tool-call delta aggregation.
2
+ * Tool-call delta aggregation, re-exported from Core.
3
3
  *
4
- * One algorithm is shared by completion policies and direct callers: fragments are keyed by their
5
- * provider index, IDs may not conflict, and a complete call requires both an ID and a name. A
6
- * complete call never hides another started but incomplete one.
4
+ * The algorithm lives in `model/interactions/calls.ts` so session transports and
5
+ * completion policies share one implementation. This module keeps the existing
6
+ * Support import path stable.
7
7
  *
8
8
  * Exports: `AggregatedToolCall`, `ToolCallCollector`, `ToolCallFailure` and
9
9
  * `createToolCallCollector`.
10
10
  */
11
- import type { ModelPart } from '../../../structs/model/messages.js';
12
- /** One completed native tool call in provider index order. */
13
- export interface AggregatedToolCall {
14
- readonly index: number;
15
- readonly id: string;
16
- readonly name: string;
17
- readonly arguments: string;
18
- }
19
- /** Report a protocol violation and stop; callers decide how the failure is classified. */
20
- export type ToolCallFailure = (message: string) => never;
21
- /** Aggregation entry point for streamed function-call deltas. */
22
- export interface ToolCallCollector {
23
- /** Feed one part; text parts are ignored and cannot satisfy or break a call. */
24
- push(part: ModelPart): void;
25
- /** Calls started so far, including incomplete ones, in index order. */
26
- readonly calls: readonly AggregatedToolCall[];
27
- /**
28
- * Finalize the calls.
29
- *
30
- * @throws When any started call is still missing its ID or name.
31
- */
32
- complete(): readonly AggregatedToolCall[];
33
- }
34
- /**
35
- * Create a collector for one response.
36
- *
37
- * @param fail - Protocol failure factory; defaults to the Core model protocol error.
38
- * @returns A collector that keeps its own state and never shares it with another response.
39
- */
40
- export declare function createToolCallCollector(fail?: ToolCallFailure): ToolCallCollector;
11
+ export { createToolCallCollector } from '../../../model/interactions/calls.js';
12
+ export type { AggregatedToolCall, ToolCallCollector, ToolCallFailure, } from '../../../model/interactions/calls.js';
@@ -1,58 +1,11 @@
1
- import { modelProtocolError } from '../../../utils/model-protocol.js';
2
1
  /**
3
- * Create a collector for one response.
2
+ * Tool-call delta aggregation, re-exported from Core.
4
3
  *
5
- * @param fail - Protocol failure factory; defaults to the Core model protocol error.
6
- * @returns A collector that keeps its own state and never shares it with another response.
4
+ * The algorithm lives in `model/interactions/calls.ts` so session transports and
5
+ * completion policies share one implementation. This module keeps the existing
6
+ * Support import path stable.
7
+ *
8
+ * Exports: `AggregatedToolCall`, `ToolCallCollector`, `ToolCallFailure` and
9
+ * `createToolCallCollector`.
7
10
  */
8
- export function createToolCallCollector(fail = modelProtocolError) {
9
- const pending = new Map();
10
- const ids = new Set();
11
- const calls = () => [...pending.entries()]
12
- .sort(([left], [right]) => left - right)
13
- .map(([index, call]) => ({ index, ...call }));
14
- return {
15
- push(part) {
16
- if (typeof part === 'string')
17
- return;
18
- if (!part || typeof part !== 'object' || Array.isArray(part))
19
- fail('Expected a native model call');
20
- const { type, index, id, name, arguments: args } = part;
21
- if (type !== 'function-call-delta')
22
- fail('Expected a native model call');
23
- if (!Number.isInteger(index) || index < 0)
24
- fail('Invalid model call index');
25
- if ((id !== undefined && (typeof id !== 'string' || !id)) ||
26
- (name !== undefined && typeof name !== 'string') ||
27
- (args !== undefined && typeof args !== 'string'))
28
- fail('Invalid model call fields');
29
- let call = pending.get(index);
30
- if (!call) {
31
- call = { id: '', name: '', arguments: '' };
32
- pending.set(index, call);
33
- }
34
- if (id !== undefined) {
35
- if (call.id && call.id !== id)
36
- fail('Conflicting model call IDs');
37
- if (!call.id) {
38
- if (ids.has(id))
39
- fail('Duplicate model call ID');
40
- ids.add(id);
41
- call.id = id;
42
- }
43
- }
44
- call.name += name ?? '';
45
- call.arguments += args ?? '';
46
- },
47
- get calls() {
48
- return calls();
49
- },
50
- complete() {
51
- const completed = calls();
52
- for (const call of completed)
53
- if (!call.id || !call.name)
54
- fail('Incomplete model call');
55
- return completed;
56
- },
57
- };
58
- }
11
+ export { createToolCallCollector } from '../../../model/interactions/calls.js';
@@ -22,7 +22,7 @@ export * from './capabilities.js';
22
22
  export { createStageModelTransport } from './stage-transport.js';
23
23
  export { createProviderObservationScope } from './observer.js';
24
24
  export { createReplyPreviewRules } from './preview-rules.js';
25
- export type { ReplyPreviewCapability, ReplyPreviewStage } from './preview-rules.js';
25
+ export type { PreviewTool, ReplyPreviewTool, ReplyPreviewStage } from './preview-rules.js';
26
26
  export { runChildren } from './children.js';
27
27
  export type { ModelChildTask, ModelChildrenOptions } from './children.js';
28
28
  export { createModelStrategy, modelBudgetStrategies } from './strategies.js';
@@ -1,11 +1,16 @@
1
1
  import type { JsonSchema } from '../../structs/common.js';
2
2
  import type { ReplyPreviewRule } from './reply-preview.js';
3
+ import type { ModelTool } from '../../structs/capabilities/model.js';
4
+ /** A model tool with an explicit, presentation-only streaming preview contract. */
5
+ export interface PreviewTool<Input = unknown, Selection = Input, Context = any> extends ModelTool<Input, Selection, Context> {
6
+ readonly preview?: true | Omit<ReplyPreviewRule, 'stageId' | 'toolId'>;
7
+ }
3
8
  /**
4
9
  * Capability declaration used to derive preview rules.
5
10
  *
6
11
  * Omitted `preview` means the capability never previews, so previewing is an explicit opt-in.
7
12
  */
8
- export interface ReplyPreviewCapability {
13
+ export interface ReplyPreviewTool {
9
14
  /** Capability ID, which must equal the native function wire name used for transport. */
10
15
  readonly id: string;
11
16
  /** Input schema used to prove that preview and eligibility paths really exist. */
@@ -14,16 +19,16 @@ export interface ReplyPreviewCapability {
14
19
  * Explicit preview opt-in: `true` uses the default text/bubble paths, an object narrows the
15
20
  * paths and eligibility, and omission means the capability never previews.
16
21
  */
17
- readonly preview?: true | Omit<ReplyPreviewRule, 'stageId' | 'capabilityId'>;
22
+ readonly preview?: true | Omit<ReplyPreviewRule, 'stageId' | 'toolId'>;
18
23
  }
19
- /** Stage declaration: which capabilities it exposes and whether it previews text or arguments. */
24
+ /** Stage declaration: which tools it exposes and whether it previews text or arguments. */
20
25
  export interface ReplyPreviewStage {
21
26
  /** Stage ID used by the workflow and transport projection. */
22
27
  readonly id: string;
23
28
  /** Capabilities exposed at this stage; must be unique and registered. */
24
- readonly capabilityIds?: readonly string[];
25
- /** `text` previews plain model text; `capabilities` previews opted-in capability arguments. */
26
- readonly preview?: 'text' | 'capabilities';
29
+ readonly toolIds?: readonly string[];
30
+ /** `text` previews plain model text; `tools` previews opted-in capability arguments. */
31
+ readonly preview?: 'text' | 'tools';
27
32
  }
28
33
  /**
29
34
  * Generate frozen preview rules from capability and stage declarations.
@@ -31,12 +36,12 @@ export interface ReplyPreviewStage {
31
36
  * Capabilities without preview metadata are skipped even when their stage opts in. Default paths
32
37
  * are `text` and `bubbles[*]`, each kept only when the capability schema declares it.
33
38
  *
34
- * @param options Stage declarations and the capabilities they may reference.
39
+ * @param options Stage declarations and the tools they may reference.
35
40
  * @returns Frozen rules in stage order, each with deep-frozen paths and eligibility.
36
41
  * @throws {Error} When a capability or stage ID repeats, a stage references an unknown capability,
37
42
  * a preview mode is unknown, or a preview path or eligibility field is absent from the schema.
38
43
  */
39
44
  export declare function createReplyPreviewRules(options: {
40
45
  readonly stages: readonly ReplyPreviewStage[];
41
- readonly capabilities: readonly ReplyPreviewCapability[];
46
+ readonly tools: readonly ReplyPreviewTool[];
42
47
  }): readonly ReplyPreviewRule[];
@@ -80,29 +80,29 @@ function previewSnapshot(preview) {
80
80
  * Capabilities without preview metadata are skipped even when their stage opts in. Default paths
81
81
  * are `text` and `bubbles[*]`, each kept only when the capability schema declares it.
82
82
  *
83
- * @param options Stage declarations and the capabilities they may reference.
83
+ * @param options Stage declarations and the tools they may reference.
84
84
  * @returns Frozen rules in stage order, each with deep-frozen paths and eligibility.
85
85
  * @throws {Error} When a capability or stage ID repeats, a stage references an unknown capability,
86
86
  * a preview mode is unknown, or a preview path or eligibility field is absent from the schema.
87
87
  */
88
88
  export function createReplyPreviewRules(options) {
89
- const capabilities = new Map();
90
- for (const capability of options.capabilities) {
89
+ const tools = new Map();
90
+ for (const capability of options.tools) {
91
91
  const id = capability.id;
92
- breakWhile(!id || capabilities.has(id), 'Duplicate preview capability declaration');
92
+ breakWhile(!id || tools.has(id), 'Duplicate preview capability declaration');
93
93
  const preview = previewSnapshot(capability.preview);
94
94
  // Validate and emit the same canonical snapshot, never reread App getters.
95
95
  const jsonSchema = preview ? structuredClone(capability.jsonSchema) : {};
96
- capabilities.set(id, { id, preview, jsonSchema });
96
+ tools.set(id, { id, preview, jsonSchema });
97
97
  }
98
98
  const stages = new Set(), rules = [];
99
99
  for (const stage of options.stages) {
100
- const { id: stageId, preview, capabilityIds } = stage;
100
+ const { id: stageId, preview, toolIds } = stage;
101
101
  breakWhile(!stageId || stages.has(stageId), 'Duplicate preview stage declaration');
102
102
  stages.add(stageId);
103
- const ids = capabilityIds === undefined ? [] : stringList(capabilityIds, 'capability IDs');
104
- breakWhile(new Set(ids).size !== ids.length || ids.some((id) => !capabilities.has(id)), 'Preview stage references an unknown capability');
105
- breakWhile(preview !== undefined && !['text', 'capabilities'].includes(preview), 'Unknown preview stage mode');
103
+ const ids = toolIds === undefined ? [] : stringList(toolIds, 'capability IDs');
104
+ breakWhile(new Set(ids).size !== ids.length || ids.some((id) => !tools.has(id)), 'Preview stage references an unknown capability');
105
+ breakWhile(preview !== undefined && !['text', 'tools'].includes(preview), 'Unknown preview stage mode');
106
106
  if (!preview)
107
107
  continue;
108
108
  if (preview === 'text') {
@@ -111,7 +111,7 @@ export function createReplyPreviewRules(options) {
111
111
  continue;
112
112
  }
113
113
  for (const id of ids) {
114
- const capability = capabilities.get(id);
114
+ const capability = tools.get(id);
115
115
  if (!capability.preview)
116
116
  continue;
117
117
  const source = capability.preview === true ? {} : capability.preview;
@@ -127,7 +127,7 @@ export function createReplyPreviewRules(options) {
127
127
  Object.freeze({ path: Object.freeze(when.path), values: Object.freeze(when.values) });
128
128
  rules.push(Object.freeze({
129
129
  stageId,
130
- capabilityId: wireName(id),
130
+ toolId: wireName(id),
131
131
  paths: emittedPaths,
132
132
  ...(emittedWhen ? { when: emittedWhen } : {}),
133
133
  }));
@@ -2,11 +2,11 @@ import type { ModelOutputEvent } from '../../structs/model/runtime.js';
2
2
  /**
3
3
  * One projection rule: which stage/capability it matches and which prose fields may be shown.
4
4
  *
5
- * A rule without `capabilityId` may only match a registered plain-text stage.
5
+ * A rule without `toolId` may only match a registered plain-text stage.
6
6
  */
7
7
  export interface ReplyPreviewRule {
8
8
  /** Native function wire name. Omit only for a registered plain-text stage. */
9
- capabilityId?: string;
9
+ toolId?: string;
10
10
  /** Restrict the rule to one stage; omitted matches any stage producing this capability. */
11
11
  stageId?: string;
12
12
  /** JSON paths to project, where `*` matches any array index; defaults to text/bubble paths. */
@@ -196,7 +196,7 @@ export function createReplyPreview(options) {
196
196
  if (!Number.isSafeInteger(maxChars) || maxChars < 1)
197
197
  throw new TypeError('Invalid reply preview budget');
198
198
  const rules = options.rules.map((rule) => Object.freeze({
199
- capabilityId: rule.capabilityId,
199
+ toolId: rule.toolId,
200
200
  stageId: rule.stageId,
201
201
  paths: rule.paths === undefined ? undefined : structuredClone(rule.paths),
202
202
  when: rule.when === undefined ? undefined : structuredClone(rule.when),
@@ -258,7 +258,7 @@ export function createReplyPreview(options) {
258
258
  return;
259
259
  }
260
260
  if (typeof part === 'string') {
261
- const rule = rules.find((rule) => !rule.capabilityId && rule.stageId === event.payload.stageId);
261
+ const rule = rules.find((rule) => !rule.toolId && rule.stageId === event.payload.stageId);
262
262
  if (!rule) {
263
263
  if (part.trim()) {
264
264
  disabled = true;
@@ -276,7 +276,7 @@ export function createReplyPreview(options) {
276
276
  return;
277
277
  }
278
278
  name += part.name ?? '';
279
- const rule = rules.find((rule) => rule.capabilityId === name && (!rule.stageId || rule.stageId === event.payload.stageId));
279
+ const rule = rules.find((rule) => rule.toolId === name && (!rule.stageId || rule.stageId === event.payload.stageId));
280
280
  if (!rule) {
281
281
  if (selected) {
282
282
  disabled = true;
@@ -0,0 +1,61 @@
1
+ import type { ModelToolSource, RegisteredModelTool } from '../../structs/capabilities/model.js';
2
+ import type { ModelResponseCollector } from '../../structs/model/interactions.js';
3
+ import type { ModelOptions } from '../../structs/model/messages.js';
4
+ import type { ModelTransportDefinition } from '../../structs/model/runtime.js';
5
+ import type { ModelSessionCall, ModelSessionResult } from '../../structs/model/session.js';
6
+ /** One completed call with host-facing resolution; unknown tools and bad JSON stay non-fatal. */
7
+ export interface ResolvedSessionCall extends ModelSessionCall {
8
+ /** Registered tool id, absent when the name is unknown to this stage. */
9
+ readonly toolId?: string;
10
+ /** Parsed arguments, absent when parsing failed or the tool is unknown. */
11
+ readonly input?: Record<string, unknown>;
12
+ /** Non-fatal problem the workflow should turn into a tool error message. */
13
+ readonly problem?: 'unknown-tool' | 'invalid-arguments';
14
+ }
15
+ /** Complete result of one session response after host-facing resolution. */
16
+ export interface ResolvedSessionResult extends Omit<ModelSessionResult, 'calls'> {
17
+ readonly calls: readonly ResolvedSessionCall[];
18
+ }
19
+ /** Prepared session transport handed to the runner. */
20
+ export interface PreparedSessionTransport {
21
+ readonly options: Pick<ModelOptions, 'functions' | 'json' | 'temperature' | 'toolChoice' | 'parallelToolCalls'>;
22
+ readonly schemaChars: number;
23
+ readonly instruction: string;
24
+ createResponse(): ModelResponseCollector<ResolvedSessionResult>;
25
+ }
26
+ /** Options a session transport may pass through to provider options. */
27
+ export interface SessionFunctionOptions {
28
+ readonly temperature?: number;
29
+ readonly toolChoice?: 'auto' | 'required' | 'none';
30
+ readonly parallelToolCalls?: boolean | 'omit';
31
+ }
32
+ /** Registration for one session transport. */
33
+ export interface SessionModelTransportRegistration {
34
+ /** Transport id used by call requests and diagnostics. */
35
+ readonly id: string;
36
+ /** Tools advertised to the model for this stage. */
37
+ readonly tools: ModelToolSource;
38
+ /** Sampling and tool-selection settings. */
39
+ readonly options?: SessionFunctionOptions;
40
+ }
41
+ /**
42
+ * Build the session policy for one stage.
43
+ *
44
+ * @param tools - Registered tools available in this stage; must be non-empty.
45
+ * @param options - Sampling and tool-selection settings.
46
+ * @returns A prepared transport whose collector returns text and every completed call.
47
+ * @throws TypeError When the tool list is empty or two ids collide on the wire name.
48
+ */
49
+ export declare function prepareSessionFunctions(tools: readonly RegisteredModelTool[], options?: SessionFunctionOptions): PreparedSessionTransport;
50
+ /**
51
+ * Create a session transport.
52
+ *
53
+ * @param registration - Transport id, tool source and optional settings.
54
+ * @returns A frozen transport definition whose result contains text and every completed call.
55
+ * @throws TypeError When the id is blank.
56
+ */
57
+ export declare function createSessionModelTransport<const Id extends string>(registration: SessionModelTransportRegistration & {
58
+ readonly id: Id;
59
+ }): ModelTransportDefinition<ResolvedSessionResult> & {
60
+ readonly id: Id;
61
+ };