@jangts/agent-core 0.3.6 → 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 (214) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +5 -5
  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 +4 -2
  7. package/development/docs/api/README.md +2 -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/reference.en.md +508 -410
  23. package/development/docs/api/reference.md +508 -410
  24. package/development/docs/api/support.en.md +55 -9
  25. package/development/docs/api/support.md +53 -7
  26. package/development/docs/api/types.en.md +35 -1
  27. package/development/docs/api/types.md +43 -0
  28. package/development/docs/basic-usage.en.md +1 -1
  29. package/development/docs/basic-usage.md +1 -1
  30. package/development/docs/create-app.en.md +1 -1
  31. package/development/docs/examples/registration/associated.mjs +8 -0
  32. package/development/docs/examples/registration/independent.mjs +20 -0
  33. package/development/docs/examples/registration/protocol.mjs +48 -0
  34. package/development/docs/examples/registration/run.mjs +47 -0
  35. package/development/docs/examples/registration/tools.mjs +75 -0
  36. package/development/docs/examples/registration/workflow.mjs +109 -0
  37. package/development/docs/flows/knowledge-maintenance.en.md +1 -1
  38. package/development/docs/materials.en.md +1 -1
  39. package/development/docs/mechanisms.en.md +2 -2
  40. package/development/docs/mechanisms.md +1 -1
  41. package/development/docs/operations.en.md +1 -1
  42. package/development/docs/records.en.md +1 -1
  43. package/development/docs/registration.en.md +4 -4
  44. package/development/docs/registration.md +2 -2
  45. package/development/skills/agent-core-app/SKILL.md +4 -4
  46. package/development/skills/agent-core-app/templates/node-ts/README.md.tpl +1 -1
  47. package/development/skills/agent-core-app/templates/node-ts/src/catalog.ts.tpl +2 -2
  48. package/development/skills/agent-core-app/templates/node-ts/test/app.test.mjs.tpl +1 -1
  49. package/dist/cjs/capabilities/index.js +5 -12
  50. package/dist/cjs/capabilities/model.js +56 -12
  51. package/dist/cjs/capabilities/tool-conditions.js +65 -0
  52. package/dist/cjs/capabilities/tool-runtime.js +10 -3
  53. package/dist/cjs/context/audit.js +5 -8
  54. package/dist/cjs/context/index.js +3 -4
  55. package/dist/cjs/index.js +21 -17
  56. package/dist/cjs/kits/answering/tasks.js +5 -5
  57. package/dist/cjs/kits/domains/catalog.js +113 -0
  58. package/dist/cjs/kits/domains/index.js +20 -0
  59. package/dist/cjs/kits/{intents → domains}/registry.js +77 -31
  60. package/dist/cjs/kits/{intents → domains}/scopes.js +21 -21
  61. package/dist/cjs/kits/index.js +14 -13
  62. package/dist/cjs/kits/presentation/formats.js +110 -0
  63. package/dist/cjs/kits/presentation/index.js +10 -5
  64. package/dist/cjs/kits/reflection.js +2 -2
  65. package/dist/cjs/kits/text-blocks.js +101 -0
  66. package/dist/cjs/kits/tools.js +246 -158
  67. package/dist/cjs/model/index.js +2 -6
  68. package/dist/cjs/model/interactions/calls.js +61 -0
  69. package/dist/cjs/model/interactions/json-object.js +11 -11
  70. package/dist/cjs/model/interactions/native-functions.js +17 -23
  71. package/dist/cjs/model/message-diagnostics.js +13 -3
  72. package/dist/cjs/model/options.js +2 -0
  73. package/dist/cjs/model/preparation.js +39 -6
  74. package/dist/cjs/model/runner.js +14 -0
  75. package/dist/cjs/model/selection-transport.js +4 -4
  76. package/dist/cjs/model/token-budget.js +3 -0
  77. package/dist/cjs/model/transports.js +3 -2
  78. package/dist/cjs/structs/index.js +7 -6
  79. package/dist/cjs/structs/kits/presentation/formats.js +2 -0
  80. package/dist/cjs/structs/kits/text-blocks.js +11 -0
  81. package/dist/cjs/structs/model/session.js +11 -0
  82. package/dist/cjs/structs/support/associations.js +2 -0
  83. package/dist/cjs/support/associations.js +79 -0
  84. package/dist/cjs/support/context/snapshot.js +11 -1
  85. package/dist/cjs/support/decorators/index.js +45 -3
  86. package/dist/cjs/support/index.js +1 -0
  87. package/dist/cjs/support/model/capabilities.js +35 -5
  88. package/dist/cjs/support/model/chat-completions.js +11 -2
  89. package/dist/cjs/support/model/completion/calls.js +10 -56
  90. package/dist/cjs/support/model/preview-rules.js +11 -11
  91. package/dist/cjs/support/model/reply-preview.js +3 -3
  92. package/dist/cjs/support/model/session.js +152 -0
  93. package/dist/cjs/support/model/stage-transport.js +8 -8
  94. package/dist/cjs/support/model/transports.js +5 -2
  95. package/dist/cjs/support/tools.js +42 -17
  96. package/dist/esm/capabilities/index.d.ts +5 -10
  97. package/dist/esm/capabilities/index.js +5 -9
  98. package/dist/esm/capabilities/model.d.ts +17 -13
  99. package/dist/esm/capabilities/model.js +54 -10
  100. package/dist/esm/capabilities/tool-conditions.d.ts +9 -0
  101. package/dist/esm/capabilities/tool-conditions.js +59 -0
  102. package/dist/esm/capabilities/tool-runtime.js +10 -3
  103. package/dist/esm/capabilities/tools.d.ts +3 -3
  104. package/dist/esm/context/audit.js +5 -8
  105. package/dist/esm/context/index.d.ts +3 -4
  106. package/dist/esm/context/index.js +3 -4
  107. package/dist/esm/index.d.ts +19 -13
  108. package/dist/esm/index.js +18 -15
  109. package/dist/esm/kits/answering/tasks.d.ts +6 -6
  110. package/dist/esm/kits/answering/tasks.js +5 -5
  111. package/dist/esm/kits/domains/catalog.d.ts +42 -0
  112. package/dist/esm/kits/domains/catalog.js +110 -0
  113. package/dist/esm/kits/domains/index.d.ts +4 -0
  114. package/dist/esm/kits/domains/index.js +4 -0
  115. package/dist/esm/kits/domains/registry.d.ts +100 -0
  116. package/dist/esm/kits/{intents → domains}/registry.js +77 -31
  117. package/dist/esm/kits/{intents → domains}/scopes.d.ts +18 -18
  118. package/dist/esm/kits/{intents → domains}/scopes.js +21 -21
  119. package/dist/esm/kits/index.d.ts +6 -5
  120. package/dist/esm/kits/index.js +6 -5
  121. package/dist/esm/kits/presentation/formats.d.ts +42 -0
  122. package/dist/esm/kits/presentation/formats.js +105 -0
  123. package/dist/esm/kits/presentation/index.d.ts +14 -5
  124. package/dist/esm/kits/presentation/index.js +10 -5
  125. package/dist/esm/kits/reflection.js +3 -3
  126. package/dist/esm/kits/text-blocks.d.ts +24 -0
  127. package/dist/esm/kits/text-blocks.js +97 -0
  128. package/dist/esm/kits/tools.d.ts +69 -52
  129. package/dist/esm/kits/tools.js +246 -158
  130. package/dist/esm/model/index.d.ts +2 -6
  131. package/dist/esm/model/index.js +2 -6
  132. package/dist/esm/model/interactions/calls.d.ts +40 -0
  133. package/dist/esm/model/interactions/calls.js +58 -0
  134. package/dist/esm/model/interactions/json-object.js +11 -11
  135. package/dist/esm/model/interactions/native-functions.js +17 -23
  136. package/dist/esm/model/message-diagnostics.d.ts +6 -5
  137. package/dist/esm/model/message-diagnostics.js +13 -3
  138. package/dist/esm/model/options.js +2 -0
  139. package/dist/esm/model/preparation.js +39 -6
  140. package/dist/esm/model/runner.js +14 -0
  141. package/dist/esm/model/selection-transport.js +4 -4
  142. package/dist/esm/model/token-budget.js +3 -0
  143. package/dist/esm/model/transports.d.ts +2 -1
  144. package/dist/esm/model/transports.js +3 -2
  145. package/dist/esm/structs/capabilities/invocation.d.ts +1 -1
  146. package/dist/esm/structs/capabilities/model.d.ts +42 -11
  147. package/dist/esm/structs/capabilities/tools.d.ts +9 -4
  148. package/dist/esm/structs/common.d.ts +1 -1
  149. package/dist/esm/structs/index.d.ts +7 -6
  150. package/dist/esm/structs/index.js +7 -6
  151. package/dist/esm/structs/kits/answering/tasks.d.ts +2 -2
  152. package/dist/esm/structs/kits/{intents → domains}/catalog.d.ts +20 -20
  153. package/dist/esm/structs/kits/{intents → domains}/registry.d.ts +24 -21
  154. package/dist/esm/structs/kits/{intents → domains}/scopes.d.ts +9 -9
  155. package/dist/esm/structs/kits/presentation/formats.d.ts +42 -0
  156. package/dist/esm/structs/kits/presentation/formats.js +1 -0
  157. package/dist/esm/structs/kits/text-blocks.d.ts +25 -0
  158. package/dist/esm/structs/kits/text-blocks.js +10 -0
  159. package/dist/esm/structs/kits/tools.d.ts +82 -83
  160. package/dist/esm/structs/model/interactions.d.ts +18 -11
  161. package/dist/esm/structs/model/messages.d.ts +34 -2
  162. package/dist/esm/structs/model/runtime.d.ts +7 -0
  163. package/dist/esm/structs/model/session.d.ts +29 -0
  164. package/dist/esm/structs/model/session.js +10 -0
  165. package/dist/esm/structs/support/associations.d.ts +22 -0
  166. package/dist/esm/structs/support/associations.js +1 -0
  167. package/dist/esm/structs/support/model/interactions.d.ts +2 -2
  168. package/dist/esm/structs/support/model/messages.d.ts +6 -13
  169. package/dist/esm/structs/support/tools.d.ts +23 -23
  170. package/dist/esm/support/associations.d.ts +26 -0
  171. package/dist/esm/support/associations.js +76 -0
  172. package/dist/esm/support/context/snapshot.js +11 -1
  173. package/dist/esm/support/decorators/index.d.ts +13 -2
  174. package/dist/esm/support/decorators/index.js +40 -3
  175. package/dist/esm/support/decorators/pool.d.ts +6 -5
  176. package/dist/esm/support/decorators/types.d.ts +3 -1
  177. package/dist/esm/support/index.d.ts +1 -0
  178. package/dist/esm/support/index.js +1 -0
  179. package/dist/esm/support/model/capabilities.d.ts +8 -3
  180. package/dist/esm/support/model/capabilities.js +35 -5
  181. package/dist/esm/support/model/chat-completions.js +11 -2
  182. package/dist/esm/support/model/completion/calls.d.ts +6 -34
  183. package/dist/esm/support/model/completion/calls.js +8 -55
  184. package/dist/esm/support/model/index.d.ts +1 -1
  185. package/dist/esm/support/model/preview-rules.d.ts +13 -8
  186. package/dist/esm/support/model/preview-rules.js +11 -11
  187. package/dist/esm/support/model/reply-preview.d.ts +2 -2
  188. package/dist/esm/support/model/reply-preview.js +3 -3
  189. package/dist/esm/support/model/session.d.ts +61 -0
  190. package/dist/esm/support/model/session.js +148 -0
  191. package/dist/esm/support/model/stage-transport.d.ts +1 -1
  192. package/dist/esm/support/model/stage-transport.js +9 -9
  193. package/dist/esm/support/model/transports.d.ts +2 -0
  194. package/dist/esm/support/model/transports.js +2 -1
  195. package/dist/esm/support/tools.d.ts +11 -3
  196. package/dist/esm/support/tools.js +43 -18
  197. package/dist/esm/utils/catalog.d.ts +1 -1
  198. package/package.json +20 -6
  199. package/dist/cjs/execution/index.js +0 -30
  200. package/dist/cjs/kits/intents/catalog.js +0 -82
  201. package/dist/cjs/kits/intents/index.js +0 -35
  202. package/dist/esm/execution/index.d.ts +0 -11
  203. package/dist/esm/execution/index.js +0 -11
  204. package/dist/esm/kits/intents/catalog.d.ts +0 -39
  205. package/dist/esm/kits/intents/catalog.js +0 -79
  206. package/dist/esm/kits/intents/index.d.ts +0 -22
  207. package/dist/esm/kits/intents/index.js +0 -18
  208. package/dist/esm/kits/intents/registry.d.ts +0 -88
  209. /package/dist/cjs/structs/kits/{intents → domains}/catalog.js +0 -0
  210. /package/dist/cjs/structs/kits/{intents → domains}/registry.js +0 -0
  211. /package/dist/cjs/structs/kits/{intents → domains}/scopes.js +0 -0
  212. /package/dist/esm/structs/kits/{intents → domains}/catalog.js +0 -0
  213. /package/dist/esm/structs/kits/{intents → domains}/registry.js +0 -0
  214. /package/dist/esm/structs/kits/{intents → domains}/scopes.js +0 -0
@@ -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
  }
@@ -97,6 +97,13 @@ export interface ModelCallTrace extends InvocationMetadata {
97
97
  name: string;
98
98
  argumentChars: number;
99
99
  };
100
+ /** All calls produced by a session response; omitted for single-selection transports. */
101
+ calls?: readonly {
102
+ id: string;
103
+ name: string;
104
+ argumentChars: number;
105
+ toolId?: string;
106
+ }[];
100
107
  /** Context accounting: per-fragment usage and characters shared with the previous call. */
101
108
  context?: {
102
109
  fragmentUsage: ContextFragmentUsage[];
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Raw session response contracts: one response may carry text and several tool calls.
3
+ *
4
+ * These shapes are Core-only and deliberately contain no host tool resolution. Support's
5
+ * session transport adds `toolId`, parsed `input` and non-fatal `problem` fields in its own
6
+ * `ResolvedSessionResult` type.
7
+ *
8
+ * Exports: `ModelSessionCall`, `ModelSessionResult`.
9
+ */
10
+ /** One completed tool call in a session response. */
11
+ export interface ModelSessionCall {
12
+ /** Provider index used to join streamed fragments. */
13
+ readonly index: number;
14
+ /** Provider call id, echoed by the matching tool result. */
15
+ readonly id: string;
16
+ /** Declared function name exactly as returned by the model. */
17
+ readonly name: string;
18
+ /** Raw JSON argument text exactly as returned by the model. */
19
+ readonly arguments: string;
20
+ /** Characters counted for the output budget. */
21
+ readonly argumentChars: number;
22
+ }
23
+ /** Complete result of one session response. */
24
+ export interface ModelSessionResult {
25
+ /** Streamed assistant prose; may be empty when the response only declares calls. */
26
+ readonly text: string;
27
+ /** Completed calls in provider index order. */
28
+ readonly calls: readonly ModelSessionCall[];
29
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Raw session response contracts: one response may carry text and several tool calls.
3
+ *
4
+ * These shapes are Core-only and deliberately contain no host tool resolution. Support's
5
+ * session transport adds `toolId`, parsed `input` and non-fatal `problem` fields in its own
6
+ * `ResolvedSessionResult` type.
7
+ *
8
+ * Exports: `ModelSessionCall`, `ModelSessionResult`.
9
+ */
10
+ export {};
@@ -0,0 +1,22 @@
1
+ /** App-side associations between registered owners and model tools; no separate intent entity. */
2
+ import type { ModelToolRegistration } from '../capabilities/model.js';
3
+ /** Explicit tool references or inline overrides of the owner's default model interface. */
4
+ export type ToolAssociation = string | Partial<ModelToolRegistration>;
5
+ /** Owners retain their business fields; Support only reads model interface associations. */
6
+ export interface AssociatedRegistration {
7
+ readonly id: string;
8
+ readonly description: string;
9
+ readonly modelTools?: readonly ToolAssociation[];
10
+ }
11
+ /** Shared independent tools and a default projection from existing contracts. */
12
+ export interface AssociationOptions<Entry extends AssociatedRegistration> {
13
+ readonly tools?: readonly ModelToolRegistration[];
14
+ readonly toolDefaults?: (entry: Readonly<Entry>) => ModelToolRegistration | undefined;
15
+ }
16
+ /** Local provenance, never an extra model input requirement. */
17
+ export interface AssociationSource {
18
+ readonly kind: 'standalone' | 'registration';
19
+ readonly id: string;
20
+ readonly description: string;
21
+ readonly toolIds: readonly string[];
22
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Stage-scoped model transport contract.
3
3
  *
4
- * Place in the package: Support-side registration for transports that expose only the capabilities
4
+ * Place in the package: Support-side registration for transports that expose only the tools
5
5
  * declared for each stage. Static sources are projected once; dynamic sources are re-projected at
6
6
  * the model boundary. Either way, an undeclared stage or capability is rejected rather than
7
7
  * silently omitted.
@@ -16,6 +16,6 @@ export interface ModelStageTransportRegistration<Result = unknown> extends Model
16
16
  /** Declared stages; each id is unique and lists non-empty, unique capability ids. */
17
17
  readonly stages: readonly {
18
18
  readonly id: string;
19
- readonly capabilityIds: readonly string[];
19
+ readonly toolIds: readonly string[];
20
20
  }[];
21
21
  }
@@ -1,23 +1,16 @@
1
1
  /**
2
2
  * Provider-level message shapes for direct compatible-provider use.
3
3
  *
4
- * Place in the package: Support-side input for hosts that keep their own tool thread. `ModelMessage`
5
- * stays the Core contract and is unchanged; these shapes add the assistant tool declaration and the
6
- * tool result, with role and field association enforced by the union and re-checked at runtime.
4
+ * Place in the package: Support-side input for hosts that keep their own tool thread. Core
5
+ * `ModelMessage` also supports the tool thread; these stricter shapes remain for hosts that want
6
+ * role and field association enforced by the union and re-checked at runtime.
7
7
  *
8
8
  * Exports: `ProviderToolCall`, `ProviderSystemMessage`, `ProviderUserMessage`,
9
9
  * `ProviderAssistantMessage`, `ProviderToolMessage`, `ProviderMessage`.
10
10
  */
11
- import type { ModelImage } from '../../model/messages.js';
12
- /** One tool call the assistant declared, in wire order. */
13
- export interface ProviderToolCall {
14
- /** Provider call ID, echoed by the matching tool result. */
15
- readonly id: string;
16
- /** Declared function name. */
17
- readonly name: string;
18
- /** Raw JSON arguments exactly as the provider produced them. */
19
- readonly arguments: string;
20
- }
11
+ import type { ModelImage, ModelToolCall } from '../../model/messages.js';
12
+ /** One tool call the assistant declared, in wire order; aliases the Core shape. */
13
+ export type ProviderToolCall = ModelToolCall;
21
14
  /** System instruction turn; text only, so the union rejects images and tool fields here. */
22
15
  export interface ProviderSystemMessage {
23
16
  readonly role: 'system';
@@ -1,35 +1,33 @@
1
1
  /**
2
2
  * Tool catalog contract used by Support's tool assembly.
3
3
  *
4
- * Place in the package: an App-side projection of typed tool definitions into model capabilities.
4
+ * Place in the package: an App-side projection of typed tool definitions into model tools.
5
5
  * The model may only propose `{ toolId, input }`; authorization, invocation, budgets and
6
6
  * cancellation still happen in Core's tool registry.
7
7
  *
8
- * Exports: `ToolDefinition` (type re-export), `ToolProposal`, `ToolCapabilities`, `SelectedTools`,
8
+ * Exports: `ToolDefinition` (type re-export), `ToolProposal`, `ToolModelView`, `SelectedTools`,
9
9
  * `ToolOutput`, `CompiledTool`, `ToolRuntime`, `ToolCatalogEntry`, `ToolCatalog`.
10
10
  */
11
11
  import type { ToolResult } from '../invocation.js';
12
12
  import type { SchemaAdapter, ExecutionOptions, ReadonlyCatalog } from '../common.js';
13
- import type { RegisteredModelCapability, ModelSelection } from '../capabilities/model.js';
14
- import type { ModelCapabilityRegistry } from '../../capabilities/model.js';
15
- import type { ToolDefinition, ToolExecutionEvent, ToolRegistryPorts, ToolInvocationRequest } from '../capabilities/tools.js';
13
+ import type { RegisteredModelTool, ModelSelection } from '../capabilities/model.js';
14
+ import type { ModelToolRegistry } from '../../capabilities/model.js';
15
+ import type { ToolDefinition, ExecutableTool, ToolExecutionEvent, ToolRegistryPorts, ToolInvocationRequest } from '../capabilities/tools.js';
16
16
  export type { ToolDefinition } from '../capabilities/tools.js';
17
17
  /** A model's proposal to call one tool; nothing has been authorized or executed yet. */
18
- export interface ToolProposal {
19
- /** Registered tool the model selected. */
20
- readonly toolId: string;
21
- /** Raw arguments; schema parsing and authorization happen in Core. */
22
- readonly input: unknown;
23
- }
24
- /** Model capability view of a tool catalog. */
25
- export interface ToolCapabilities extends ModelCapabilityRegistry {
26
- values(): IterableIterator<RegisteredModelCapability<ToolProposal>>;
18
+ export type { ToolProposal } from '../capabilities/model.js';
19
+ import type { ToolProposal } from '../capabilities/model.js';
20
+ /** Model capability view of a tool catalog, retaining the host context type. */
21
+ export interface ToolModelView<App = unknown> extends ModelToolRegistry {
22
+ values(): IterableIterator<RegisteredModelTool<ToolProposal>>;
27
23
  /** Resolves a model selection into a proposal; throws for unknown or invalid selections. */
28
24
  resolve(selection: ModelSelection, context: Readonly<{
29
25
  stageId: string;
30
26
  }>): ToolProposal;
31
27
  /** Narrows the capability set to `ids`; throws for unregistered ids. */
32
- select(ids: readonly string[]): ToolCapabilities;
28
+ select(ids: readonly string[], context?: App): ToolModelView<App>;
29
+ /** Discovery retains this projection's ToolProposal result contract. */
30
+ withIntent(context: App): ToolModelView<App>;
33
31
  }
34
32
  type ResultDefinition = {
35
33
  readonly id: string;
@@ -46,13 +44,13 @@ export type CompiledTool<App, Definition> = Definition extends {
46
44
  parseOutput(value: unknown): infer Output;
47
45
  } ? Definition extends {
48
46
  readonly id: infer Id extends string;
49
- } ? ToolDefinition<Definition extends {
47
+ } ? ExecutableTool<Definition extends {
50
48
  inputSchema: SchemaAdapter<infer Input>;
51
49
  } ? Input : unknown, Output, App, Id> : never : never;
52
50
  /** Catalog bound to one App request. */
53
- export interface ToolRuntime<Tool extends ResultDefinition = ResultDefinition> {
54
- /** The catalog's model capabilities, shared with the catalog instance. */
55
- readonly capabilities: ToolCapabilities;
51
+ export interface ToolRuntime<Tool extends ResultDefinition = ResultDefinition, App = unknown> {
52
+ /** The catalog's model tools, shared with the catalog instance. */
53
+ readonly tools: ToolModelView<App>;
56
54
  /** Execution events recorded by this runtime so far, in occurrence order. */
57
55
  readonly events: readonly ToolExecutionEvent[];
58
56
  /** Synchronous invocation; rejects tools declared as asynchronous. */
@@ -64,15 +62,17 @@ export interface ToolRuntime<Tool extends ResultDefinition = ResultDefinition> {
64
62
  }
65
63
  /** Public declaration surface of one tool, without registry internals. */
66
64
  export type ToolCatalogEntry<App, Tool extends ToolDefinition<unknown, unknown, App>> = Tool extends ToolDefinition<unknown, unknown, App> ? Pick<Tool, keyof ToolDefinition<unknown, unknown, App>> : never;
67
- /** Frozen tool catalog with model capabilities and per-request binding. */
65
+ /** Frozen tool catalog with model tools and per-request binding. */
68
66
  export interface ToolCatalog<App, Tool extends ToolDefinition<unknown, unknown, App> = ToolDefinition<unknown, unknown, App>> extends ReadonlyCatalog<ToolCatalogEntry<App, Tool>> {
69
- readonly capabilities: ToolCapabilities;
67
+ readonly tools: ToolModelView<App>;
70
68
  /** Narrows the catalog while preserving declaration order; throws for unknown ids. */
71
- select<const Ids extends readonly string[]>(ids: Ids): ToolCatalog<App, SelectedTools<Tool, Ids[number]>>;
69
+ select<const Ids extends readonly string[]>(ids: Ids, context?: App): ToolCatalog<App, SelectedTools<Tool, Ids[number]>>;
70
+ /** Active tools advertising demand-discovery use; descriptions are view-local. */
71
+ withIntent(context: App): ToolCatalog<App, Tool>;
72
72
  /** Binds the catalog to one App request and returns an invocable runtime. */
73
73
  bind(request: {
74
74
  app: App;
75
75
  execution?: ExecutionOptions;
76
76
  errors?: Pick<ToolRegistryPorts, 'unavailable' | 'errorCode'>;
77
- }): ToolRuntime<Tool>;
77
+ }): ToolRuntime<Tool, App>;
78
78
  }