@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,23 +1,24 @@
1
1
  /**
2
- * Intent registry contract for the Intents Kit.
2
+ * Domain Tool registry contract for the Domain Tools Kit.
3
3
  *
4
- * Place in the package: an optional App-side catalog of model intents. An intent names its ordered
5
- * steps and optional App-declared policies; the registry checks identity, allowed vocabulary,
4
+ * Place in the package: an optional App-side catalog of domain Tools. An intent names its allowed
5
+ * delegates and optional App-declared policies; the registry checks identity, allowed vocabulary,
6
6
  * duplicate ids and sealing, while the meaning of each vocabulary value stays with the App.
7
7
  *
8
- * Exports: `IntentDefinition`, `IntentRegistryPolicy`, `IntentDescription`, `IntentId`,
8
+ * Exports: `IntentTool`, `IntentPolicy`, `IntentDescription`, `IntentId`,
9
9
  * `RegisteredIntent`.
10
10
  */
11
11
  import type { BreakReason } from '../../utils/rules.js';
12
12
  import type { RegistrationProjection } from '../../../utils/registration.js';
13
- /** One declarable intent. */
14
- export interface IntentDefinition {
15
- /** Unique intent id, matched against the policy's `idPattern` when configured. */
13
+ import type { ModelTool } from '../../capabilities/model.js';
14
+ /** One domain Tool. */
15
+ export interface IntentTool extends ModelTool<any, any> {
16
+ /** Unique Tool id, matched against the policy's `idPattern` when configured. */
16
17
  id: string;
17
18
  /** Non-blank model-facing description. */
18
19
  description: string;
19
- /** Ordered step ids; non-empty, unique and, when `policy.steps` is set, drawn from it. */
20
- steps: readonly string[];
20
+ /** Allowed delegate ids, retained in declaration order without imposing execution order; non-empty and unique. */
21
+ delegates?: readonly string[];
21
22
  /** App-declared scope-mode name; validated against `policy.scopeModes` when that is set. */
22
23
  scopePolicy?: string;
23
24
  /** App-declared target-mode name; validated against `policy.targetModes` when that is set. */
@@ -31,9 +32,11 @@ export interface IntentDefinition {
31
32
  /** App-declared handoff marker; validated against `policy.handoffValues` when that is set. */
32
33
  preparedHandoff?: unknown;
33
34
  }
35
+ /** Configuration form; object arguments and a Tool proposal are the registration defaults. */
36
+ export type IntentToolRegistration = Omit<IntentTool, 'inputSchema' | 'resolve'> & Partial<Pick<IntentTool, 'inputSchema' | 'resolve'>>;
34
37
  /** Registration rules for one intent registry. */
35
- export interface IntentRegistryPolicy<Definition extends IntentDefinition> {
36
- /** Pattern every intent id must match. */
38
+ export interface IntentPolicy<Definition extends IntentToolRegistration> {
39
+ /** Pattern every Tool id must match. */
37
40
  readonly idPattern?: RegExp;
38
41
  /** Allowed `scopePolicy` values; `undefined` accepts any value. */
39
42
  readonly scopeModes?: readonly string[];
@@ -43,8 +46,8 @@ export interface IntentRegistryPolicy<Definition extends IntentDefinition> {
43
46
  readonly contextTiers?: readonly string[];
44
47
  /** Allowed `planIntent` values; `undefined` accepts any value. */
45
48
  readonly actions?: readonly string[];
46
- /** Allowed step ids; `undefined` accepts any non-empty step. */
47
- readonly steps?: readonly string[];
49
+ /** Allowed delegate ids; `undefined` accepts any non-empty delegate. */
50
+ readonly delegates?: readonly string[];
48
51
  /** Allowed `preparedHandoff` values; `undefined` accepts any value. */
49
52
  readonly handoffValues?: readonly unknown[];
50
53
  /** Extra App assertion, called after the built-in checks; must return void synchronously. */
@@ -54,24 +57,24 @@ export interface IntentRegistryPolicy<Definition extends IntentDefinition> {
54
57
  readonly errors?: {
55
58
  readonly sealed?: BreakReason;
56
59
  readonly invalid?: BreakReason;
57
- /** Builds the duplicate-id rejection; receives the intent id. */
60
+ /** Builds the duplicate-id rejection; receives the Tool id. */
58
61
  readonly duplicate?: (goal: string) => Error | string;
59
62
  };
60
63
  }
61
- /** Registered intent with its steps widened to the definition's step literals. */
62
- export type IntentDescription<Definition extends IntentDefinition> = Omit<RegisteredIntent<Definition>, 'steps'> & {
63
- steps: Definition['steps'][number][];
64
+ /** Registered domain Tool with its delegates widened to the definition's delegate literals. */
65
+ export type IntentDescription<Definition extends IntentToolRegistration> = Omit<RegisteredIntent<Definition>, 'delegates'> & {
66
+ delegates: NonNullable<Definition['delegates']>[number][];
64
67
  };
65
68
  /** Union of the ids of a definition set, or `string` when it cannot be narrowed. */
66
69
  export type IntentId<Definition> = Definition extends {
67
70
  id: infer Id extends string;
68
71
  } ? Id : string;
69
- type RegisteredIntentLists<Definition extends IntentDefinition> = {
70
- readonly [Key in keyof Pick<Definition, Extract<keyof Definition, 'steps' | 'auxiliaryActions'>>]: Readonly<Definition[Key]>;
72
+ type RegisteredIntentLists<Definition extends IntentToolRegistration> = {
73
+ readonly [Key in keyof Pick<Definition, Extract<keyof Definition, 'delegates' | 'auxiliaryActions'>>]: Readonly<Definition[Key]>;
71
74
  };
72
75
  /** Frozen registration view: list fields are frozen copies, helper methods are dropped. */
73
- export type RegisteredIntent<Definition extends IntentDefinition> = Readonly<Omit<RegistrationProjection<Definition, IntentDefinition>, 'steps' | 'auxiliaryActions'> & RegisteredIntentLists<Definition> & {
76
+ export type RegisteredIntent<Definition extends IntentToolRegistration> = Readonly<Omit<RegistrationProjection<Definition, IntentTool>, 'delegates' | 'auxiliaryActions' | 'inputSchema' | 'resolve'> & ModelTool<any, any> & RegisteredIntentLists<Definition> & {
74
77
  id: Definition['id'];
75
- steps: Readonly<Definition['steps']>;
78
+ delegates: Readonly<NonNullable<Definition['delegates']>>;
76
79
  }>;
77
80
  export {};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Scope registry contract for the Intents Kit.
2
+ * Scope registry contract for the Domain Tools Kit.
3
3
  *
4
4
  * Place in the package: an optional App-side catalog of scope definitions. A scope binds an intent
5
5
  * to the sources and tools it may use; the registry validates identity, aliases, required bindings
@@ -19,8 +19,8 @@ export interface ScopeDefinition {
19
19
  description: string;
20
20
  /** Scope category; validated against `policy.categories` when that is set. */
21
21
  category: string;
22
- /** Intents this scope serves; required when the policy sets `requireIntents`. */
23
- intentIds?: readonly string[];
22
+ /** Goals this scope serves; required when the policy sets `requireGoals`. */
23
+ goalIds?: readonly string[];
24
24
  /** Referenced query scopes, resolved by the App. */
25
25
  queryScopeIds?: readonly string[];
26
26
  /** Referenced knowledge topics, resolved by the App. */
@@ -36,8 +36,8 @@ export interface ScopeDefinition {
36
36
  }
37
37
  /** Registration rules for one scope registry. */
38
38
  export interface ScopeRegistryPolicy<Definition extends ScopeDefinition> {
39
- /** Require at least one intent id per scope. */
40
- readonly requireIntents?: boolean;
39
+ /** Require at least one Tool id per scope. */
40
+ readonly requireGoals?: boolean;
41
41
  /** Require at least one query scope or knowledge topic per scope. */
42
42
  readonly requireSources?: boolean;
43
43
  /** Require at least one tool id per scope. */
@@ -49,7 +49,7 @@ export interface ScopeRegistryPolicy<Definition extends ScopeDefinition> {
49
49
  /** Extra App assertion, called after the built-in checks; must return void synchronously. */
50
50
  readonly assertDefinition?: (definition: Definition) => void;
51
51
  /** Replaces the default intent membership test; must return boolean synchronously. */
52
- readonly acceptsIntent?: (definition: Readonly<Definition>, goal: string) => boolean;
52
+ readonly acceptsTool?: (definition: Readonly<Definition>, goal: string) => boolean;
53
53
  /** Diagnostic tags attached to registration rejections. */
54
54
  readonly tags?: readonly string[];
55
55
  readonly errors?: {
@@ -59,7 +59,7 @@ export interface ScopeRegistryPolicy<Definition extends ScopeDefinition> {
59
59
  }
60
60
  /** Registered evidence entry: public data only, frozen by the registry. */
61
61
  export type RegisteredScopeEvidence<Definition extends ScopeDefinition> = Readonly<RegistrationData<NonNullable<Definition['evidence']>[number]>>;
62
- type ScopeListKey = 'intentIds' | 'queryScopeIds' | 'knowledgeTopicIds' | 'toolIds' | 'aliases';
62
+ type ScopeListKey = 'goalIds' | 'queryScopeIds' | 'knowledgeTopicIds' | 'toolIds' | 'aliases';
63
63
  type RegisteredScopeLists<Definition extends ScopeDefinition> = {
64
64
  readonly [Key in ScopeListKey]: [NonNullable<Definition[Key]>] extends [never] ? readonly [] : NonNullable<Definition[Key]> extends readonly string[] ? Readonly<NonNullable<Definition[Key]>> : readonly string[];
65
65
  };
@@ -74,8 +74,8 @@ export type RegisteredScope<Definition extends ScopeDefinition> = Readonly<Omit<
74
74
  evidence: ScopeEvidenceList<Definition>;
75
75
  }>;
76
76
  /** Plain description with mutable arrays, for documentation and model-facing catalogs. */
77
- export type ScopeDescription<Definition extends ScopeDefinition> = Omit<RegisteredScope<Definition>, 'intentIds' | 'queryScopeIds' | 'knowledgeTopicIds' | 'toolIds' | 'aliases' | 'evidence'> & {
78
- intentIds: string[];
77
+ export type ScopeDescription<Definition extends ScopeDefinition> = Omit<RegisteredScope<Definition>, 'goalIds' | 'queryScopeIds' | 'knowledgeTopicIds' | 'toolIds' | 'aliases' | 'evidence'> & {
78
+ goalIds: string[];
79
79
  queryScopeIds: string[];
80
80
  knowledgeTopicIds: string[];
81
81
  toolIds: string[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Reply-format contract for the Presentation Kit.
3
+ *
4
+ * A format exists only where the App provides a template for the final reply. Replies without a
5
+ * resolved format have no output-format requirement, so callers skip these checks instead of
6
+ * re-asking the model.
7
+ *
8
+ * Exports: `ReplyFormatCheck`, `ReplyFormatDefinition`, `CompiledReplyFormat`, `ReplyFormatOptions`.
9
+ */
10
+ /** One check a template declares, evaluated against the rendered bubbles. */
11
+ export interface ReplyFormatCheck {
12
+ /** Stable check id referenced by formats. */
13
+ readonly id: string;
14
+ /** Human-readable statement of the template requirement. */
15
+ readonly description: string;
16
+ /** Returns whether the reply satisfies this requirement. */
17
+ readonly accepts: (bubbles: readonly string[]) => boolean;
18
+ }
19
+ /** A template-bound reply format, matched against per-turn facts. */
20
+ export interface ReplyFormatDefinition<Context = unknown> {
21
+ /** Stable format id. */
22
+ readonly id: string;
23
+ /** Human-readable statement of the template. */
24
+ readonly description: string;
25
+ /** Check ids this template requires. */
26
+ readonly checks: readonly string[];
27
+ /** Whether the current turn uses this template. */
28
+ readonly when: (context: Context) => boolean;
29
+ }
30
+ /** A resolved format with its checks bound; callers only inspect replies using it. */
31
+ export interface CompiledReplyFormat {
32
+ readonly id: string;
33
+ readonly description: string;
34
+ readonly checks: readonly string[];
35
+ /** Checks the reply fails; empty means the template format is satisfied. */
36
+ readonly inspect: (bubbles: readonly string[]) => readonly ReplyFormatCheck[];
37
+ }
38
+ /** Declaration input for `defineReplyFormats`. */
39
+ export interface ReplyFormatOptions<Context = unknown> {
40
+ readonly formats: readonly ReplyFormatDefinition<Context>[];
41
+ readonly checks: readonly ReplyFormatCheck[];
42
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Text block contract for the Text Blocks Kit.
3
+ *
4
+ * Place in the package: an optional App-side helper for splitting long plain text into
5
+ * structure-aware blocks before paging or retrieval. File reading, paging, search, storage
6
+ * and prompt wording stay with the App.
7
+ *
8
+ * Exports: `TextBlock`, `TextBlockOptions`.
9
+ */
10
+ /** One structure-aware block of a long text. */
11
+ export interface TextBlock {
12
+ /** One-based position in source order; stable for a given text and target size. */
13
+ readonly number: number;
14
+ /** Exact source substring, including its own line endings. */
15
+ readonly text: string;
16
+ /** Start offset in UTF-16 code units. */
17
+ readonly start: number;
18
+ /** End offset (exclusive) in UTF-16 code units; `end - start === text.length`. */
19
+ readonly end: number;
20
+ }
21
+ /** Splitting options. */
22
+ export interface TextBlockOptions {
23
+ /** Target block size in characters; only a single over-long line may exceed it. */
24
+ readonly targetChars: number;
25
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Text block contract for the Text Blocks Kit.
3
+ *
4
+ * Place in the package: an optional App-side helper for splitting long plain text into
5
+ * structure-aware blocks before paging or retrieval. File reading, paging, search, storage
6
+ * and prompt wording stay with the App.
7
+ *
8
+ * Exports: `TextBlock`, `TextBlockOptions`.
9
+ */
10
+ export {};
@@ -1,24 +1,29 @@
1
1
  /**
2
- * Tool lifecycle contract for the Tools Kit.
2
+ * Tool contract for the Tools Kit.
3
3
  *
4
4
  * Place in the package: an optional App-side library for tools that need more than a plain
5
- * definition — availability, per-step protocols, output ownership, model-context fields, task rules
6
- * and delivery hooks. Actual invocation is delegated to Core (`ToolRegistry`, `executeInvocation`);
7
- * domain predicates, phase names and vocabulary stay App configuration.
5
+ * definition — availability, one lifecycle hook set, output ownership, model-context fields,
6
+ * task rules and delivery hooks. Actual invocation is delegated to Core (`ToolRegistry`,
7
+ * `executeInvocation`); domain predicates, phase names and vocabulary stay App configuration.
8
8
  *
9
- * Exports: `ToolRuntimeTypes`, `ToolModelField`, `LifecycleProtocol`, `ToolInvocation`,
10
- * `ToolContribution`, `LifecycleTool`, `RegisteredLifecycleTool`, `Policy`, `ToolProtocol`,
11
- * `ToolNormalizer`, `ToolFinalizer`, `ToolLifecycleOptions`, `ToolJournal` (type re-export).
9
+ * A tool declares at most one `lifecycle` block. Hooks under "selected" run only for the tool a
10
+ * decision picks; the rest run for every registered tool; `delegate` claims one delegate id so
11
+ * the registry can route a decision to its handler.
12
+ *
13
+ * Exports: `ToolRuntimeTypes`, `ToolModelField`, `LifecycleProtocol`, `LifecycleHooks`, `Tool`,
14
+ * `ToolRegistration`, `RegisteredToolDefinition`, `Policy`, `ToolProtocol`, `ToolNormalizer`,
15
+ * `ToolFinalizer`, `ToolsOptions`, `ToolJournal` (type re-export).
12
16
  */
13
17
  import type { ContextFragment, ContextLifetime } from '../context/fragments.js';
14
18
  import type { BreakReason } from '../utils/rules.js';
15
- import type { ExecutableTool, ToolRegistryPorts } from '../capabilities/tools.js';
19
+ import type { ErasedTool, ToolExecutionContext, ToolRegistryPorts } from '../capabilities/tools.js';
16
20
  import type { ProtocolShape } from './interaction.js';
21
+ import type { ModelTool } from '../capabilities/model.js';
17
22
  import type { ToolInvocationPorts } from '../capabilities/invocation.js';
18
23
  import type { RegistrationProjection } from '../../utils/registration.js';
19
24
  /** One schema binds lifecycle handler types without introducing platform fields into core. */
20
25
  export interface ToolRuntimeTypes {
21
- /** App decision object carried through invocation steps. */
26
+ /** App decision object carried through lifecycle invocations. */
22
27
  decision: unknown;
23
28
  /** App handler context for one request. */
24
29
  context: unknown;
@@ -50,52 +55,37 @@ export interface ToolModelField<Placement extends string = string> {
50
55
  /** Field value, rendered by the registry's fragment factory. */
51
56
  value: unknown;
52
57
  }
53
- /** Output protocol carried by a lifecycle step. */
58
+ /** Output protocol carried by a tool lifecycle. */
54
59
  export interface LifecycleProtocol extends ProtocolShape {
55
60
  /** Protocol version; compared with the configured `protocolVersion` when present. */
56
61
  readonly version?: number;
57
62
  /** Marks an output that ends the interaction. */
58
63
  readonly terminal?: boolean;
59
64
  }
60
- /** One lifecycle step of a tool. */
61
- export interface ToolInvocation<Types extends ToolRuntimeTypes, Protocol extends LifecycleProtocol = LifecycleProtocol> {
62
- /** Step id this invocation handles; must be unique across registered tools. */
63
- step: string;
64
- /** Output protocol of the step. */
65
- protocol: Protocol;
66
- /** Executes the step. Must be synchronous and return nothing. */
67
- call(value: unknown, context: Types['context'], execution: import('../capabilities/tools.js').ToolExecutionContext): void;
68
- /** Inspects a decision before any step runs. */
69
- inspect?(decision: Types['decision'], context: Types['context']): void;
65
+ /**
66
+ * Everything one tool declares for a request.
67
+ *
68
+ * Declaring `id` turns the tool into an invocation owner, so `protocol` and `call` become
69
+ * required in practice; the registry rejects a partial declaration. Every other hook is
70
+ * optional and returning nothing expresses "no opinion".
71
+ */
72
+ export interface LifecycleHooks<Types extends ToolRuntimeTypes, Protocol extends LifecycleProtocol = LifecycleProtocol> {
73
+ /** Invocation id this tool owns; must be unique across registered tools. */
74
+ id?: string;
75
+ /** Output protocol of the invocation. */
76
+ protocol?: Protocol;
77
+ /** Executes the invocation. Must be synchronous and return nothing. */
78
+ call?(value: unknown, context: Types['context'], execution: ToolExecutionContext): void;
70
79
  /** Permission check for the decision; runs before execution. */
71
80
  authorize?(decision: Types['decision'], context: Types['context']): void;
72
- /** Returns true when this step is a valid continuation of the decision. */
81
+ /** Returns true when this invocation is a valid continuation of the decision. */
73
82
  resume?(decision: Types['decision'], context: Types['context']): boolean;
74
- /** Normalizes the decision after the step; returning undefined keeps it unchanged. */
83
+ /** Normalizes the decision after the invocation; returning undefined keeps it unchanged. */
75
84
  complete?(decision: Types['decision'], context: Types['context']): Types['decision'] | undefined;
76
- }
77
- /**
78
- * Non-execution hooks a tool may contribute to a request.
79
- *
80
- * Every hook is optional; one returns nothing to express "no opinion".
81
- */
82
- export interface ToolContribution<Types extends ToolRuntimeTypes> {
83
- /** Builds the tool's composition value for the current context. */
84
- composition?(context: Types['context']): Types['composition'] | undefined;
85
- /** Observes the decision during the inspect phase. */
85
+ /** Observes the decision before any invocation runs. */
86
86
  inspect?(decision: Types['decision'], context: Types['context']): void;
87
- /** Extra context used when recovering a previous attempt. */
88
- recoveryContext?(context: Types['context']): unknown;
89
- /** Projects the stored context before it is shown or persisted. */
90
- projectContext?(context: unknown): unknown;
91
- /** Rewrites visible text produced by this tool. */
92
- visibleText?(text: string, context: Types['context']): string;
93
- /** Reviews a draft before delivery. */
94
- reviewDraft?(draft: unknown, context: Types['context']): unknown;
95
87
  /** Runs finalization for one phase. */
96
88
  finalize?(decision: Types['decision'], context: Types['context'], phase: Types['phase']): void;
97
- /** Returns true when an absent interaction is acceptable in this phase. */
98
- missingInteractionAllowed?(decision: Types['decision'], context: Types['context']): boolean;
99
89
  /** Extra rules contributed to the model context, ordered by `order`. */
100
90
  rules?(context: Types['context']): {
101
91
  order: number;
@@ -103,33 +93,42 @@ export interface ToolContribution<Types extends ToolRuntimeTypes> {
103
93
  }[];
104
94
  /** Model-context fields for one placement, ordered by `order`. */
105
95
  modelFields?(context: Types['context'], placement: Types['placement']): ToolModelField<Types['placement']>[];
106
- /** Vetoes an intent by returning false; silence (undefined) means support. */
107
- supportsIntent?(intentId: string, context: Types['context']): boolean | undefined;
96
+ /** Rewrites visible text produced by this tool. */
97
+ visibleText?(text: string, context: Types['context']): string;
98
+ /** Reviews a draft before delivery. */
99
+ reviewDraft?(draft: unknown, context: Types['context']): unknown;
100
+ /** Builds the tool's composition value for the current context. */
101
+ composition?(context: Types['context']): Types['composition'] | undefined;
102
+ /** Extra context used when recovering a previous attempt. */
103
+ recoveryContext?(context: Types['context']): unknown;
104
+ /** Projects the stored context before it is shown or persisted. */
105
+ projectContext?(context: unknown): unknown;
106
+ /** Returns true when an absent interaction is acceptable in this phase. */
107
+ missingInteractionAllowed?(decision: Types['decision'], context: Types['context']): boolean;
108
+ /** Vetoes a goal by returning false; silence (undefined) means support. */
109
+ supportsGoal?(goalId: string, context: Types['context']): boolean | undefined;
108
110
  }
109
- /** A tool with lifecycle steps and delivery contributions. */
110
- export interface LifecycleTool<Types extends ToolRuntimeTypes> extends ExecutableTool {
111
- /** Intent ids this tool serves, or `'all'` when it is always available. */
112
- readonly intentIds: 'all' | readonly string[];
111
+ /** A registered tool: model metadata plus one optional lifecycle block. */
112
+ export interface Tool<Types extends ToolRuntimeTypes> extends ErasedTool, ModelTool<unknown, unknown, Types['context']> {
113
+ /** Goal ids this tool serves, or `'all'` when it is always available. */
114
+ readonly goalIds: 'all' | readonly string[];
113
115
  readonly description: string;
114
116
  /** Audience this tool is described to; validated against the registry policy. */
115
117
  readonly audience: string;
116
118
  /** Declared effect class, for example read-only or mutating. */
117
119
  readonly effect: string;
118
- /** Per-step invocation contract. */
119
- readonly invocation?: ToolInvocation<Types>;
120
- /** Non-execution hooks. */
121
- readonly contribution?: ToolContribution<Types>;
122
- /** Returns whether the tool may run for this context; absent means always available. */
123
- available?(context: Types['context']): boolean;
120
+ /** Delegate id this tool answers, when a node delegates execution by name. */
121
+ readonly delegate?: string;
122
+ /** Lifecycle hooks this tool declares for a request. */
123
+ readonly lifecycle?: LifecycleHooks<Types>;
124
124
  }
125
- type RegisteredInvocation<Types extends ToolRuntimeTypes, Value> = Value extends ToolInvocation<Types> ? RegistrationProjection<Value, ToolInvocation<Types>> : Value;
126
- type RegisteredContribution<Types extends ToolRuntimeTypes, Value> = Value extends ToolContribution<Types> ? RegistrationProjection<Value, ToolContribution<Types>> : Value;
127
- type RegisteredLifecycleHooks<Types extends ToolRuntimeTypes, Tool extends LifecycleTool<Types>> = {
128
- [Key in keyof Pick<Tool, Extract<keyof Tool, 'invocation' | 'contribution'>>]: Key extends 'invocation' ? RegisteredInvocation<Types, Tool[Key]> : RegisteredContribution<Types, Tool[Key]>;
129
- };
130
- /** Registered snapshot with frozen intent ids and projected hooks. */
131
- export type RegisteredLifecycleTool<Types extends ToolRuntimeTypes, Tool extends LifecycleTool<Types> = LifecycleTool<Types>> = Readonly<Omit<RegistrationProjection<Tool, LifecycleTool<Types>>, 'invocation' | 'contribution' | 'intentIds'> & RegisteredLifecycleHooks<Types, Tool> & {
132
- intentIds: Readonly<Tool['intentIds']>;
125
+ /** Declaration form; the registry derives the ModelTool projection from existing handlers. */
126
+ export type ToolRegistration<Types extends ToolRuntimeTypes> = Omit<Tool<Types>, 'inputSchema' | 'resolve'> & Partial<Pick<Tool<Types>, 'inputSchema' | 'resolve'>>;
127
+ type RegisteredLifecycle<Types extends ToolRuntimeTypes, Value> = Value extends LifecycleHooks<Types> ? RegistrationProjection<Value, LifecycleHooks<Types>> : Value;
128
+ /** Registered snapshot with frozen goal ids and projected hooks. */
129
+ export type RegisteredToolDefinition<Types extends ToolRuntimeTypes, Declaration extends ToolRegistration<Types> = ToolRegistration<Types>> = Readonly<Omit<RegistrationProjection<Declaration, Tool<Types>>, 'lifecycle' | 'goalIds'> & {
130
+ lifecycle?: RegisteredLifecycle<Types, Declaration['lifecycle']>;
131
+ goalIds: Readonly<Declaration['goalIds']>;
133
132
  }>;
134
133
  /** Registration policy shared by every tool in the registry. */
135
134
  export interface Policy<Tool> {
@@ -141,29 +140,29 @@ export interface Policy<Tool> {
141
140
  readonly audiences: readonly string[];
142
141
  /** Accepted `effect` values. */
143
142
  readonly effects: readonly string[];
144
- /** Reports whether an intent id exists, for validating `intentIds` references. */
145
- readonly intentExists: (goal: string) => boolean;
146
- /** When set, every step protocol must declare this version. */
143
+ /** Reports whether a goal id exists, for validating `goalIds` references. */
144
+ readonly goalExists: (goal: string) => boolean;
145
+ /** When set, every lifecycle protocol must declare this version. */
147
146
  readonly protocolVersion?: number;
148
147
  /** Diagnostic tags attached to registration rejections. */
149
148
  readonly tags?: readonly string[];
150
149
  /** Rejection wording for an invalid tool definition. */
151
150
  readonly invalidTool?: BreakReason;
152
- /** Rejection wording for an invalid or duplicate invocation step. */
151
+ /** Rejection wording for an invalid or duplicate invocation id. */
153
152
  readonly invalidInvocation?: BreakReason;
154
153
  }
155
- /** Protocol type of a tool's invocation step. */
154
+ /** Protocol type of a tool's lifecycle invocation. */
156
155
  export type ToolProtocol<Tool extends {
157
- invocation?: {
158
- protocol: LifecycleProtocol;
156
+ lifecycle?: {
157
+ protocol?: LifecycleProtocol;
159
158
  };
160
- }> = NonNullable<Tool['invocation']>['protocol'];
159
+ }> = NonNullable<NonNullable<Tool['lifecycle']>['protocol']>;
161
160
  /** Converts untrusted input into a decision; must be synchronous. */
162
161
  export type ToolNormalizer<Types extends ToolRuntimeTypes> = (value: unknown, ...args: Types['normalizerArgs']) => unknown;
163
162
  /** Converts an executed decision into the tool result; must be synchronous. */
164
163
  export type ToolFinalizer<Types extends ToolRuntimeTypes> = (receiver: Types['receiver'], decision: Types['decision'], context: Types['context']) => Types['result'];
165
- /** Construction options for a lifecycle tool registry. */
166
- export interface ToolLifecycleOptions<Types extends ToolRuntimeTypes, Tool extends LifecycleTool<Types>> extends ToolInvocationPorts<Types['context']> {
164
+ /** Construction options for a tool registry. */
165
+ export interface ToolsOptions<Types extends ToolRuntimeTypes, Declaration extends ToolRegistration<Types>> extends ToolInvocationPorts<Types['context']> {
167
166
  /** Supplies the receiver handed to the finalizer. */
168
167
  readonly receiver?: () => Types['receiver'];
169
168
  /** Execution defaults (signal and diagnostics) applied to invocations. */
@@ -171,20 +170,20 @@ export interface ToolLifecycleOptions<Types extends ToolRuntimeTypes, Tool exten
171
170
  /** Error factories shared by the registry. */
172
171
  readonly errors?: Pick<ToolRegistryPorts, 'unavailable' | 'errorCode'>;
173
172
  /** Registration policy for every tool. */
174
- readonly registration: Policy<Tool>;
175
- /** Maps a decision to its lifecycle step id. */
176
- readonly step: (decision: Types['decision']) => string;
177
- /** Output protocols by id, used to validate step outputs. */
178
- readonly outputs: () => Iterable<readonly [string, ToolProtocol<Tool>]>;
173
+ readonly registration: Policy<Declaration>;
174
+ /** Maps a decision to the invocation id that should handle it. */
175
+ readonly invocationId: (decision: Types['decision']) => string;
176
+ /** Output protocols by id, used to validate invocation outputs. */
177
+ readonly outputs: () => Iterable<readonly [string, ToolProtocol<Declaration>]>;
179
178
  /** Optional context-dependent output protocols, exposed alongside `outputs`. */
180
- readonly modelOutputs?: (context: Types['context']) => Iterable<readonly [string, ToolProtocol<Tool>]>;
181
- /** Builds the error for a step with no registered tool. */
182
- readonly unavailableStep?: (step: string) => Error;
179
+ readonly modelOutputs?: (context: Types['context']) => Iterable<readonly [string, ToolProtocol<Declaration>]>;
180
+ /** Builds the error for an invocation id with no registered tool. */
181
+ readonly unavailableInvocation?: (invocationId: string) => Error;
183
182
  /** Builds the error for a tool that is currently unavailable. */
184
183
  readonly forbidden?: () => Error;
185
184
  /** Renders a model field into a context fragment. */
186
- readonly contextFragment: (tool: Tool, field: ToolModelField<Types['placement']>) => ContextFragment;
187
- /** Current intent ids, used to validate `intentIds: 'all'` availability. */
188
- readonly intentIds: () => readonly string[];
185
+ readonly contextFragment: (tool: Declaration, field: ToolModelField<Types['placement']>) => ContextFragment;
186
+ /** Current goal ids, used to validate `goalIds: 'all'` availability. */
187
+ readonly goalIds: () => readonly string[];
189
188
  }
190
189
  export type { ToolJournal } from '../capabilities/invocation.js';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Model interaction contracts: how model output is turned into a business selection.
3
3
  *
4
- * An adapter compiles registered capabilities into provider options plus an instruction, and
4
+ * An adapter compiles registered tools into provider options plus an instruction, and
5
5
  * decodes the streamed response into a `ModelSelection`. A transport registration binds one adapter
6
6
  * to a capability source, so the same business registry can be served by different wire formats.
7
7
  *
@@ -9,11 +9,18 @@
9
9
  * `ModelInteractionAdapter`, `ModelTransportRegistration`, `NativeFunctionCall`.
10
10
  */
11
11
  import type { ModelOptions, ModelPart } from './messages.js';
12
- import type { ModelSelection, ModelCapabilitySource, RegisteredModelCapability } from '../capabilities/model.js';
12
+ import type { ModelSelection, ModelToolSource, RegisteredModelTool } from '../capabilities/model.js';
13
13
  /** Accumulates streamed parts for one call and resolves them into the transport's result. */
14
14
  export interface ModelResponseCollector<Result = ModelSelection> {
15
15
  /** Native function call that carried the selection, when the response used one. */
16
16
  readonly call?: ModelSelection['call'];
17
+ /** All native calls carried by a session response; omitted by single-selection collectors. */
18
+ readonly calls?: readonly {
19
+ id: string;
20
+ name: string;
21
+ argumentChars: number;
22
+ toolId?: string;
23
+ }[];
17
24
  /** Output characters accumulated so far, for output-budget accounting. */
18
25
  readonly outputChars: number;
19
26
  /** Appends one streamed part; parts arrive in provider order. */
@@ -23,8 +30,8 @@ export interface ModelResponseCollector<Result = ModelSelection> {
23
30
  }
24
31
  /** Adapter output for one stage, before the caller binds capability resolution. */
25
32
  export interface PreparedModelInteraction<Result = unknown> {
26
- /** Provider options produced from the stage's capabilities. */
27
- readonly options: Pick<ModelOptions, 'functions' | 'json'>;
33
+ /** Provider options produced from the stage's tools. */
34
+ readonly options: Pick<ModelOptions, 'functions' | 'json' | 'toolChoice' | 'parallelToolCalls'>;
28
35
  /** Characters the compiled schemas add to the input, counted against the schema budget. */
29
36
  readonly schemaChars: number;
30
37
  /** Instruction text that teaches the model how to answer; absent when the format is native. */
@@ -36,7 +43,7 @@ export interface PreparedModelInteraction<Result = unknown> {
36
43
  }
37
44
  /** Prepared transport handed to the runner, including sampling defaults. */
38
45
  export interface PreparedModelTransport<Result = unknown> {
39
- readonly options: Pick<ModelOptions, 'functions' | 'json' | 'temperature'>;
46
+ readonly options: Pick<ModelOptions, 'functions' | 'json' | 'temperature' | 'toolChoice' | 'parallelToolCalls'>;
40
47
  readonly schemaChars: number;
41
48
  readonly instruction?: string;
42
49
  createResponse(): ModelResponseCollector<Result>;
@@ -49,19 +56,19 @@ export interface ModelInteractionAdapter {
49
56
  readonly strictArguments: boolean;
50
57
  };
51
58
  /**
52
- * Compiles one stage's capabilities.
59
+ * Compiles one stage's tools.
53
60
  *
54
- * @param capabilities - Capabilities available in this stage; must be non-empty.
61
+ * @param tools - Capabilities available in this stage; must be non-empty.
55
62
  * @returns Options, instruction and collector factory; the transport adds `resolve`.
56
63
  */
57
- prepare(capabilities: readonly RegisteredModelCapability[]): Omit<PreparedModelInteraction, 'resolve'>;
64
+ prepare(tools: readonly RegisteredModelTool[]): Omit<PreparedModelInteraction, 'resolve'>;
58
65
  }
59
- /** Binds an adapter to the capabilities one transport serves. */
66
+ /** Binds an adapter to the tools one transport serves. */
60
67
  export interface ModelTransportRegistration<Result = unknown> {
61
68
  /** Transport id used by call requests and reported in diagnostic events. */
62
69
  id: string;
63
- /** Static capability source, or a factory that selects capabilities per stage. */
64
- capabilities: ModelCapabilitySource<Result> | ((stage: string) => ModelCapabilitySource<Result>);
70
+ /** Static capability source, or a factory that selects tools per stage. */
71
+ tools: ModelToolSource<Result> | ((stage: string) => ModelToolSource<Result>);
65
72
  /** Wire-format adapter; defaults to native function calling. */
66
73
  adapter?: ModelInteractionAdapter;
67
74
  /** Sampling defaults this transport contributes to every call. */
@@ -4,7 +4,8 @@
4
4
  * These shapes are deliberately provider-neutral: they describe text, optional images, streamed
5
5
  * parts and the options a call may carry. Provider-specific wire formats stay in `support/model`.
6
6
  *
7
- * Exports: `ModelImage`, `ModelMessage`, `ModelUsage`, `ModelFunction`, `FunctionCallDelta`,
7
+ * Exports: `ModelImage`, `ModelMessage`, `ModelToolCall`, `ModelAssistantToolMessage`,
8
+ * `ModelToolResultMessage`, `ModelUsage`, `ModelFunction`, `FunctionCallDelta`,
8
9
  * `ModelPart`, `ModelOptions`.
9
10
  */
10
11
  export interface ModelImage {
@@ -13,14 +14,41 @@ export interface ModelImage {
13
14
  /** Provider resolution hint; `original` asks for no downscaling where supported. */
14
15
  detail?: 'auto' | 'low' | 'high' | 'original';
15
16
  }
17
+ /** One tool call the assistant declared, in provider order. */
18
+ export interface ModelToolCall {
19
+ /** Provider call id, echoed by the matching tool result. */
20
+ readonly id: string;
21
+ /** Declared function name. */
22
+ readonly name: string;
23
+ /** Raw JSON arguments exactly as the provider produced them. */
24
+ readonly arguments: string;
25
+ }
16
26
  /** One provider-neutral turn; `images` are user visual input and are not part of the text budget. */
17
27
  export interface ModelMessage {
18
- role: 'system' | 'user' | 'assistant';
28
+ role: 'system' | 'user' | 'assistant' | 'tool';
19
29
  /** Rendered text content sent to the model. */
20
30
  content: string;
21
31
  /** User-supplied visual input. Binary payload is separate from the text character budget. */
22
32
  images?: readonly ModelImage[];
33
+ /** Tool declarations made by an assistant turn; rejected on every other role at runtime. */
34
+ toolCalls?: readonly ModelToolCall[];
35
+ /** Call id answered by a tool result; rejected on every other role at runtime. */
36
+ toolCallId?: string;
23
37
  }
38
+ /** Assistant turn that may declare tool calls and may carry an empty text body. */
39
+ export type ModelAssistantToolMessage = ModelMessage & {
40
+ readonly role: 'assistant';
41
+ readonly toolCalls?: readonly ModelToolCall[];
42
+ readonly toolCallId?: never;
43
+ readonly images?: never;
44
+ };
45
+ /** Tool result turn; `toolCallId` is required and images/tool declarations are rejected. */
46
+ export type ModelToolResultMessage = ModelMessage & {
47
+ readonly role: 'tool';
48
+ readonly toolCallId: string;
49
+ readonly toolCalls?: never;
50
+ readonly images?: never;
51
+ };
24
52
  /** Provider-reported token counts for one call; used for accounting, never for admission. */
25
53
  export interface ModelUsage {
26
54
  /** Input tokens billed for the call. */
@@ -69,4 +97,8 @@ export interface ModelOptions {
69
97
  onUsage?: (usage: ModelUsage) => void;
70
98
  /** Functions offered to the model for this call. */
71
99
  functions?: readonly ModelFunction[];
100
+ /** Tool-selection strategy; omitted keeps the provider's default. */
101
+ toolChoice?: 'auto' | 'required' | 'none';
102
+ /** Request parallel tool calls; `'omit'` leaves the wire field out entirely. */
103
+ parallelToolCalls?: boolean | 'omit';
72
104
  }