@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.
- package/CHANGELOG.md +41 -0
- package/README.md +33 -31
- package/development/docs/README.en.md +2 -2
- package/development/docs/acceptance.en.md +2 -2
- package/development/docs/agent-development.en.md +1 -1
- package/development/docs/api/README.en.md +6 -2
- package/development/docs/api/README.md +4 -0
- package/development/docs/api/configuration-in-workflow.en.md +403 -0
- package/development/docs/api/configuration-in-workflow.md +403 -0
- package/development/docs/api/core.en.md +7 -7
- package/development/docs/api/core.md +6 -6
- package/development/docs/api/decorators.en.md +20 -0
- package/development/docs/api/decorators.md +20 -0
- package/development/docs/api/examples.en.md +1 -1
- package/development/docs/api/examples.md +1 -1
- package/development/docs/api/kits.en.md +22 -4
- package/development/docs/api/kits.md +22 -4
- package/development/docs/api/knowledge-answering.en.md +4 -1
- package/development/docs/api/knowledge-answering.md +4 -1
- package/development/docs/api/mock.en.md +2 -0
- package/development/docs/api/mock.md +2 -0
- package/development/docs/api/observability.en.md +37 -11
- package/development/docs/api/observability.md +64 -11
- package/development/docs/api/reference.en.md +876 -657
- package/development/docs/api/reference.md +662 -508
- package/development/docs/api/support.en.md +55 -9
- package/development/docs/api/support.md +53 -7
- package/development/docs/api/types.en.md +36 -1
- package/development/docs/api/types.md +44 -0
- package/development/docs/api/workflow-views.en.md +64 -0
- package/development/docs/api/workflow-views.md +78 -0
- package/development/docs/api/workflow.en.md +6 -2
- package/development/docs/api/workflow.md +6 -2
- package/development/docs/basic-usage.en.md +1 -1
- package/development/docs/basic-usage.md +1 -1
- package/development/docs/create-app.en.md +1 -1
- package/development/docs/examples/registration/associated.mjs +8 -0
- package/development/docs/examples/registration/independent.mjs +20 -0
- package/development/docs/examples/registration/protocol.mjs +48 -0
- package/development/docs/examples/registration/run.mjs +47 -0
- package/development/docs/examples/registration/tools.mjs +75 -0
- package/development/docs/examples/registration/workflow.mjs +109 -0
- package/development/docs/flows/knowledge-maintenance.en.md +1 -1
- package/development/docs/materials.en.md +1 -1
- package/development/docs/mechanisms.en.md +2 -2
- package/development/docs/mechanisms.md +1 -1
- package/development/docs/operations.en.md +1 -1
- package/development/docs/records.en.md +1 -1
- package/development/docs/registration.en.md +4 -4
- package/development/docs/registration.md +2 -2
- package/development/skills/agent-core-app/SKILL.md +16 -4
- package/development/skills/agent-core-app/templates/node-ts/README.md.tpl +1 -1
- package/development/skills/agent-core-app/templates/node-ts/src/catalog.ts.tpl +2 -2
- package/development/skills/agent-core-app/templates/node-ts/test/app.test.mjs.tpl +1 -1
- package/dist/cjs/capabilities/index.js +5 -12
- package/dist/cjs/capabilities/invocation.js +21 -1
- package/dist/cjs/capabilities/model.js +56 -12
- package/dist/cjs/capabilities/tool-conditions.js +65 -0
- package/dist/cjs/capabilities/tool-runtime.js +18 -4
- package/dist/cjs/capabilities/tools.js +12 -17
- package/dist/cjs/context/audit.js +5 -8
- package/dist/cjs/context/index.js +3 -4
- package/dist/cjs/diagnostics/index.js +51 -3
- package/dist/cjs/diagnostics/native-sub-flow.js +106 -0
- package/dist/cjs/diagnostics/sub-flow.js +278 -32
- package/dist/cjs/execution/engine.js +3 -2
- package/dist/cjs/execution/events.js +5 -5
- package/dist/cjs/execution/reporting.js +18 -28
- package/dist/cjs/execution/workflow-chain.js +211 -0
- package/dist/cjs/execution/workflow-graph.js +72 -0
- package/dist/cjs/execution/workflow.js +34 -6
- package/dist/cjs/index.js +21 -17
- package/dist/cjs/kits/aggregation.js +17 -14
- package/dist/cjs/kits/answering/checks.js +2 -1
- package/dist/cjs/kits/answering/flow.js +24 -21
- package/dist/cjs/kits/answering/tasks.js +30 -25
- package/dist/cjs/kits/delivery.js +36 -24
- package/dist/cjs/kits/domains/catalog.js +113 -0
- package/dist/cjs/kits/domains/index.js +20 -0
- package/dist/cjs/kits/{intents → domains}/registry.js +77 -31
- package/dist/cjs/kits/{intents → domains}/scopes.js +21 -21
- package/dist/cjs/kits/index.js +14 -13
- package/dist/cjs/kits/knowledge/catalog.js +33 -30
- package/dist/cjs/kits/policies.js +3 -2
- package/dist/cjs/kits/presentation/formats.js +110 -0
- package/dist/cjs/kits/presentation/index.js +10 -5
- package/dist/cjs/kits/presentation/outputs.js +2 -1
- package/dist/cjs/kits/reflection.js +2 -2
- package/dist/cjs/kits/retrieval.js +7 -1
- package/dist/cjs/kits/text-blocks.js +101 -0
- package/dist/cjs/kits/tools.js +247 -158
- package/dist/cjs/model/decision-retry.js +2 -1
- package/dist/cjs/model/index.js +2 -6
- package/dist/cjs/model/interactions/calls.js +61 -0
- package/dist/cjs/model/interactions/json-object.js +11 -11
- package/dist/cjs/model/interactions/native-functions.js +17 -23
- package/dist/cjs/model/message-diagnostics.js +13 -3
- package/dist/cjs/model/options.js +2 -0
- package/dist/cjs/model/preparation.js +39 -6
- package/dist/cjs/model/runner.js +34 -5
- package/dist/cjs/model/selection-transport.js +4 -4
- package/dist/cjs/model/token-budget.js +3 -0
- package/dist/cjs/model/transports.js +3 -2
- package/dist/cjs/structs/index.js +7 -6
- package/dist/cjs/structs/kits/domains/scopes.js +2 -0
- package/dist/cjs/structs/kits/presentation/formats.js +2 -0
- package/dist/cjs/structs/kits/text-blocks.js +11 -0
- package/dist/cjs/structs/model/session.js +11 -0
- package/dist/cjs/structs/support/associations.js +2 -0
- package/dist/cjs/support/associations.js +79 -0
- package/dist/cjs/support/context/nodes.js +48 -45
- package/dist/cjs/support/context/processing.js +6 -3
- package/dist/cjs/support/context/snapshot.js +11 -1
- package/dist/cjs/support/decorators/index.js +45 -3
- package/dist/cjs/support/index.js +1 -0
- package/dist/cjs/support/model/capabilities.js +35 -5
- package/dist/cjs/support/model/chat-completions.js +11 -2
- package/dist/cjs/support/model/completion/calls.js +10 -56
- package/dist/cjs/support/model/preview-rules.js +11 -11
- package/dist/cjs/support/model/reply-preview.js +3 -3
- package/dist/cjs/support/model/session.js +152 -0
- package/dist/cjs/support/model/stage-transport.js +8 -8
- package/dist/cjs/support/model/transports.js +5 -2
- package/dist/cjs/support/tools.js +42 -17
- package/dist/cjs/utils/invocation.js +1 -0
- package/dist/esm/capabilities/index.d.ts +5 -10
- package/dist/esm/capabilities/index.js +5 -9
- package/dist/esm/capabilities/invocation.js +21 -1
- package/dist/esm/capabilities/model.d.ts +17 -13
- package/dist/esm/capabilities/model.js +54 -10
- package/dist/esm/capabilities/tool-conditions.d.ts +9 -0
- package/dist/esm/capabilities/tool-conditions.js +59 -0
- package/dist/esm/capabilities/tool-runtime.js +18 -4
- package/dist/esm/capabilities/tools.d.ts +3 -3
- package/dist/esm/capabilities/tools.js +12 -17
- package/dist/esm/context/audit.js +5 -8
- package/dist/esm/context/index.d.ts +3 -4
- package/dist/esm/context/index.js +3 -4
- package/dist/esm/diagnostics/index.d.ts +1 -0
- package/dist/esm/diagnostics/index.js +48 -2
- package/dist/esm/diagnostics/native-sub-flow.d.ts +94 -0
- package/dist/esm/diagnostics/native-sub-flow.js +101 -0
- package/dist/esm/diagnostics/sub-flow.d.ts +56 -4
- package/dist/esm/diagnostics/sub-flow.js +271 -32
- package/dist/esm/execution/engine.d.ts +1 -0
- package/dist/esm/execution/engine.js +3 -2
- package/dist/esm/execution/events.js +5 -5
- package/dist/esm/execution/reporting.d.ts +6 -12
- package/dist/esm/execution/reporting.js +19 -29
- package/dist/esm/execution/workflow-chain.d.ts +3 -0
- package/dist/esm/execution/workflow-chain.js +208 -0
- package/dist/esm/execution/workflow-graph.d.ts +7 -0
- package/dist/esm/execution/workflow-graph.js +68 -0
- package/dist/esm/execution/workflow.d.ts +6 -0
- package/dist/esm/execution/workflow.js +34 -6
- package/dist/esm/index.d.ts +19 -13
- package/dist/esm/index.js +18 -15
- package/dist/esm/kits/aggregation.d.ts +1 -1
- package/dist/esm/kits/aggregation.js +17 -14
- package/dist/esm/kits/answering/checks.js +2 -1
- package/dist/esm/kits/answering/flow.js +24 -21
- package/dist/esm/kits/answering/tasks.d.ts +6 -6
- package/dist/esm/kits/answering/tasks.js +30 -25
- package/dist/esm/kits/delivery.d.ts +0 -9
- package/dist/esm/kits/delivery.js +36 -24
- package/dist/esm/kits/domains/catalog.d.ts +42 -0
- package/dist/esm/kits/domains/catalog.js +110 -0
- package/dist/esm/kits/domains/index.d.ts +4 -0
- package/dist/esm/kits/domains/index.js +4 -0
- package/dist/esm/kits/domains/registry.d.ts +100 -0
- package/dist/esm/kits/{intents → domains}/registry.js +77 -31
- package/dist/esm/kits/{intents → domains}/scopes.d.ts +18 -18
- package/dist/esm/kits/{intents → domains}/scopes.js +21 -21
- package/dist/esm/kits/index.d.ts +6 -5
- package/dist/esm/kits/index.js +6 -5
- package/dist/esm/kits/knowledge/catalog.js +33 -30
- package/dist/esm/kits/policies.d.ts +1 -1
- package/dist/esm/kits/policies.js +3 -2
- package/dist/esm/kits/presentation/formats.d.ts +42 -0
- package/dist/esm/kits/presentation/formats.js +105 -0
- package/dist/esm/kits/presentation/index.d.ts +14 -5
- package/dist/esm/kits/presentation/index.js +10 -5
- package/dist/esm/kits/presentation/outputs.js +2 -1
- package/dist/esm/kits/reflection.js +3 -3
- package/dist/esm/kits/retrieval.js +7 -1
- package/dist/esm/kits/text-blocks.d.ts +24 -0
- package/dist/esm/kits/text-blocks.js +97 -0
- package/dist/esm/kits/tools.d.ts +69 -52
- package/dist/esm/kits/tools.js +247 -158
- package/dist/esm/model/decision-retry.d.ts +2 -0
- package/dist/esm/model/decision-retry.js +2 -1
- package/dist/esm/model/index.d.ts +2 -6
- package/dist/esm/model/index.js +2 -6
- package/dist/esm/model/interactions/calls.d.ts +40 -0
- package/dist/esm/model/interactions/calls.js +58 -0
- package/dist/esm/model/interactions/json-object.js +11 -11
- package/dist/esm/model/interactions/native-functions.js +17 -23
- package/dist/esm/model/message-diagnostics.d.ts +6 -5
- package/dist/esm/model/message-diagnostics.js +13 -3
- package/dist/esm/model/options.js +2 -0
- package/dist/esm/model/preparation.js +39 -6
- package/dist/esm/model/runner.d.ts +2 -0
- package/dist/esm/model/runner.js +34 -5
- package/dist/esm/model/selection-transport.js +4 -4
- package/dist/esm/model/token-budget.js +3 -0
- package/dist/esm/model/transports.d.ts +2 -1
- package/dist/esm/model/transports.js +3 -2
- package/dist/esm/structs/capabilities/invocation.d.ts +3 -1
- package/dist/esm/structs/capabilities/model.d.ts +42 -11
- package/dist/esm/structs/capabilities/tools.d.ts +16 -7
- package/dist/esm/structs/common.d.ts +3 -1
- package/dist/esm/structs/debug.d.ts +36 -20
- package/dist/esm/structs/execution/workflow-views.d.ts +123 -0
- package/dist/esm/structs/execution/workflow.d.ts +4 -3
- package/dist/esm/structs/index.d.ts +8 -6
- package/dist/esm/structs/index.js +7 -6
- package/dist/esm/structs/kits/answering/tasks.d.ts +2 -2
- package/dist/esm/structs/kits/{intents → domains}/catalog.d.ts +20 -20
- package/dist/esm/structs/kits/{intents → domains}/registry.d.ts +24 -21
- package/dist/esm/structs/kits/{intents → domains}/scopes.d.ts +9 -9
- package/dist/esm/structs/kits/domains/scopes.js +1 -0
- package/dist/esm/structs/kits/presentation/formats.d.ts +42 -0
- package/dist/esm/structs/kits/presentation/formats.js +1 -0
- package/dist/esm/structs/kits/text-blocks.d.ts +25 -0
- package/dist/esm/structs/kits/text-blocks.js +10 -0
- package/dist/esm/structs/kits/tools.d.ts +82 -83
- package/dist/esm/structs/model/interactions.d.ts +18 -11
- package/dist/esm/structs/model/messages.d.ts +34 -2
- package/dist/esm/structs/model/runtime.d.ts +9 -0
- package/dist/esm/structs/model/session.d.ts +29 -0
- package/dist/esm/structs/model/session.js +10 -0
- package/dist/esm/structs/support/associations.d.ts +22 -0
- package/dist/esm/structs/support/associations.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +2 -2
- package/dist/esm/structs/support/model/messages.d.ts +6 -13
- package/dist/esm/structs/support/tools.d.ts +23 -23
- package/dist/esm/support/associations.d.ts +26 -0
- package/dist/esm/support/associations.js +76 -0
- package/dist/esm/support/context/nodes.js +48 -45
- package/dist/esm/support/context/processing.js +6 -3
- package/dist/esm/support/context/snapshot.js +11 -1
- package/dist/esm/support/decorators/index.d.ts +13 -2
- package/dist/esm/support/decorators/index.js +40 -3
- package/dist/esm/support/decorators/pool.d.ts +6 -5
- package/dist/esm/support/decorators/types.d.ts +3 -1
- package/dist/esm/support/index.d.ts +1 -0
- package/dist/esm/support/index.js +1 -0
- package/dist/esm/support/model/capabilities.d.ts +8 -3
- package/dist/esm/support/model/capabilities.js +35 -5
- package/dist/esm/support/model/chat-completions.js +11 -2
- package/dist/esm/support/model/completion/calls.d.ts +6 -34
- package/dist/esm/support/model/completion/calls.js +8 -55
- package/dist/esm/support/model/index.d.ts +1 -1
- package/dist/esm/support/model/preview-rules.d.ts +13 -8
- package/dist/esm/support/model/preview-rules.js +11 -11
- package/dist/esm/support/model/reply-preview.d.ts +2 -2
- package/dist/esm/support/model/reply-preview.js +3 -3
- package/dist/esm/support/model/session.d.ts +61 -0
- package/dist/esm/support/model/session.js +148 -0
- package/dist/esm/support/model/stage-transport.d.ts +1 -1
- package/dist/esm/support/model/stage-transport.js +9 -9
- package/dist/esm/support/model/transports.d.ts +2 -0
- package/dist/esm/support/model/transports.js +2 -1
- package/dist/esm/support/tools.d.ts +11 -3
- package/dist/esm/support/tools.js +43 -18
- package/dist/esm/utils/catalog.d.ts +1 -1
- package/dist/esm/utils/invocation.d.ts +1 -0
- package/dist/esm/utils/invocation.js +1 -0
- package/package.json +20 -6
- package/dist/cjs/execution/index.js +0 -30
- package/dist/cjs/kits/intents/catalog.js +0 -82
- package/dist/cjs/kits/intents/index.js +0 -35
- package/dist/cjs/utils/debug.js +0 -30
- package/dist/esm/execution/index.d.ts +0 -11
- package/dist/esm/execution/index.js +0 -11
- package/dist/esm/kits/intents/catalog.d.ts +0 -39
- package/dist/esm/kits/intents/catalog.js +0 -79
- package/dist/esm/kits/intents/index.d.ts +0 -22
- package/dist/esm/kits/intents/index.js +0 -18
- package/dist/esm/kits/intents/registry.d.ts +0 -88
- package/dist/esm/utils/debug.d.ts +0 -27
- package/dist/esm/utils/debug.js +0 -27
- /package/dist/cjs/structs/{kits/intents/catalog.js → execution/workflow-views.js} +0 -0
- /package/dist/cjs/structs/kits/{intents/registry.js → domains/catalog.js} +0 -0
- /package/dist/cjs/structs/kits/{intents/scopes.js → domains/registry.js} +0 -0
- /package/dist/esm/structs/{kits/intents/catalog.js → execution/workflow-views.js} +0 -0
- /package/dist/esm/structs/kits/{intents/registry.js → domains/catalog.js} +0 -0
- /package/dist/esm/structs/kits/{intents/scopes.js → domains/registry.js} +0 -0
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Domain Tool registry contract for the Domain Tools Kit.
|
|
3
3
|
*
|
|
4
|
-
* Place in the package: an optional App-side catalog of
|
|
5
|
-
*
|
|
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: `
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
/**
|
|
20
|
-
|
|
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
|
|
36
|
-
/** Pattern every
|
|
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
|
|
47
|
-
readonly
|
|
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
|
|
60
|
+
/** Builds the duplicate-id rejection; receives the Tool id. */
|
|
58
61
|
readonly duplicate?: (goal: string) => Error | string;
|
|
59
62
|
};
|
|
60
63
|
}
|
|
61
|
-
/** Registered
|
|
62
|
-
export type IntentDescription<Definition extends
|
|
63
|
-
|
|
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
|
|
70
|
-
readonly [Key in keyof Pick<Definition, Extract<keyof Definition, '
|
|
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
|
|
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
|
-
|
|
78
|
+
delegates: Readonly<NonNullable<Definition['delegates']>>;
|
|
76
79
|
}>;
|
|
77
80
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Scope registry contract for the
|
|
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
|
-
/**
|
|
23
|
-
|
|
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
|
|
40
|
-
readonly
|
|
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
|
|
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 = '
|
|
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>, '
|
|
78
|
-
|
|
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
|
|
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,
|
|
6
|
-
* and delivery hooks. Actual invocation is delegated to Core (`ToolRegistry`,
|
|
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
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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 {
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
107
|
-
|
|
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
|
|
110
|
-
export interface
|
|
111
|
-
/**
|
|
112
|
-
readonly
|
|
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
|
-
/**
|
|
119
|
-
readonly
|
|
120
|
-
/**
|
|
121
|
-
readonly
|
|
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
|
-
|
|
126
|
-
type
|
|
127
|
-
type
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
|
145
|
-
readonly
|
|
146
|
-
/** When set, every
|
|
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
|
|
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
|
|
154
|
+
/** Protocol type of a tool's lifecycle invocation. */
|
|
156
155
|
export type ToolProtocol<Tool extends {
|
|
157
|
-
|
|
158
|
-
protocol
|
|
156
|
+
lifecycle?: {
|
|
157
|
+
protocol?: LifecycleProtocol;
|
|
159
158
|
};
|
|
160
|
-
}> = NonNullable<Tool['
|
|
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
|
|
166
|
-
export interface
|
|
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<
|
|
175
|
-
/** Maps a decision to
|
|
176
|
-
readonly
|
|
177
|
-
/** Output protocols by id, used to validate
|
|
178
|
-
readonly outputs: () => Iterable<readonly [string, ToolProtocol<
|
|
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<
|
|
181
|
-
/** Builds the error for
|
|
182
|
-
readonly
|
|
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:
|
|
187
|
-
/** Current
|
|
188
|
-
readonly
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
59
|
+
* Compiles one stage's tools.
|
|
53
60
|
*
|
|
54
|
-
* @param
|
|
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(
|
|
64
|
+
prepare(tools: readonly RegisteredModelTool[]): Omit<PreparedModelInteraction, 'resolve'>;
|
|
58
65
|
}
|
|
59
|
-
/** Binds an adapter to the
|
|
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
|
|
64
|
-
|
|
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`, `
|
|
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
|
}
|