@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,8 +1,9 @@
|
|
|
1
1
|
import { assertion } from '../../utils/synchronous.js';
|
|
2
2
|
import { breakWhile } from '../../utils/rules.js';
|
|
3
3
|
import { registrationData } from '../../utils/registration.js';
|
|
4
|
+
import { ModelToolRegistry } from '../../capabilities/model.js';
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* Goal semantics and allowed values are configuration; the registry owns their common lifecycle.
|
|
6
7
|
*
|
|
7
8
|
* Registration order is preserved by `ids`, `definitions`, `values` and `entries`; once
|
|
8
9
|
* `seal()` is called the set is final and further registration is rejected.
|
|
@@ -12,6 +13,7 @@ export class IntentRegistry {
|
|
|
12
13
|
static create = createIntentRegistry;
|
|
13
14
|
byId = new Map();
|
|
14
15
|
sealed = false;
|
|
16
|
+
modelView;
|
|
15
17
|
policy;
|
|
16
18
|
/**
|
|
17
19
|
* @param policy - Optional id pattern, vocabulary lists, error wording and assertion hook.
|
|
@@ -25,7 +27,7 @@ export class IntentRegistry {
|
|
|
25
27
|
'targetModes',
|
|
26
28
|
'contextTiers',
|
|
27
29
|
'actions',
|
|
28
|
-
'
|
|
30
|
+
'delegates',
|
|
29
31
|
'handoffValues',
|
|
30
32
|
'tags',
|
|
31
33
|
];
|
|
@@ -47,16 +49,16 @@ export class IntentRegistry {
|
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
/**
|
|
50
|
-
* Validate, freeze and add one
|
|
52
|
+
* Validate, freeze and add one domain Tool.
|
|
51
53
|
*
|
|
52
54
|
* Checks run in a fixed order — sealed, identity, context contract, auxiliary actions,
|
|
53
|
-
* handoff, plan,
|
|
55
|
+
* handoff, plan, delegates — so the reported violation is stable when several rules fail.
|
|
54
56
|
*
|
|
55
|
-
* @param input -
|
|
57
|
+
* @param input - Goal declaration; the App's own assertion receives this original object,
|
|
56
58
|
* not the compiled copy, so helpers and prototype methods keep working.
|
|
57
59
|
* @returns This registry, for chaining.
|
|
58
60
|
* @throws A configured error for a sealed registry, invalid identity or vocabulary values,
|
|
59
|
-
* empty/duplicate
|
|
61
|
+
* empty/duplicate delegates, or a duplicate Tool id.
|
|
60
62
|
*/
|
|
61
63
|
register(input) {
|
|
62
64
|
const id = input.id;
|
|
@@ -64,7 +66,7 @@ export class IntentRegistry {
|
|
|
64
66
|
...registrationData(input, [
|
|
65
67
|
'id',
|
|
66
68
|
'description',
|
|
67
|
-
'
|
|
69
|
+
'delegates',
|
|
68
70
|
'scopePolicy',
|
|
69
71
|
'targetPolicy',
|
|
70
72
|
'contextTier',
|
|
@@ -74,7 +76,11 @@ export class IntentRegistry {
|
|
|
74
76
|
]),
|
|
75
77
|
id,
|
|
76
78
|
description: input.description,
|
|
77
|
-
|
|
79
|
+
delegates: (typeof input.asIntent === 'object' && input.asIntent !== null
|
|
80
|
+
? input.asIntent.delegates
|
|
81
|
+
: undefined) ??
|
|
82
|
+
input.delegates ??
|
|
83
|
+
[],
|
|
78
84
|
scopePolicy: input.scopePolicy,
|
|
79
85
|
targetPolicy: input.targetPolicy,
|
|
80
86
|
contextTier: input.contextTier,
|
|
@@ -83,7 +89,7 @@ export class IntentRegistry {
|
|
|
83
89
|
preparedHandoff: input.preparedHandoff,
|
|
84
90
|
};
|
|
85
91
|
const policy = this.policy;
|
|
86
|
-
const invalid = policy.errors?.invalid ?? 'Invalid intent definition';
|
|
92
|
+
const invalid = policy.errors?.invalid ?? 'Invalid intent Tool definition';
|
|
87
93
|
const tags = policy.tags ?? [];
|
|
88
94
|
const validName = (name) => {
|
|
89
95
|
if (typeof name !== 'string' || !name.trim())
|
|
@@ -141,75 +147,112 @@ export class IntentRegistry {
|
|
|
141
147
|
},
|
|
142
148
|
{
|
|
143
149
|
occur: [
|
|
144
|
-
() =>
|
|
145
|
-
|
|
146
|
-
|
|
150
|
+
() => (input.delegates !== undefined ||
|
|
151
|
+
(typeof input.asIntent === 'object' &&
|
|
152
|
+
input.asIntent !== null &&
|
|
153
|
+
input.asIntent.delegates !== undefined)) &&
|
|
154
|
+
!definition.delegates.length,
|
|
155
|
+
() => definition.delegates.some((delegate) => policy.delegates !== undefined && !policy.delegates.includes(delegate)),
|
|
156
|
+
() => new Set(definition.delegates).size !== definition.delegates.length,
|
|
147
157
|
],
|
|
148
158
|
error: invalid,
|
|
149
|
-
tags: ['
|
|
159
|
+
tags: ['delegates'],
|
|
150
160
|
},
|
|
151
161
|
], tags);
|
|
152
162
|
// App assertions may use implementation helpers; never pass a compiled view as the source
|
|
153
163
|
// instance.
|
|
154
164
|
assertion(policy.assertDefinition?.(input), 'Registry definition assertions must return void synchronously');
|
|
155
|
-
breakWhile(this.byId.has(definition.id), () => policy.errors?.duplicate?.(definition.id) ??
|
|
156
|
-
new Error(`Duplicate intent: ${definition.id}`), [...tags, 'duplicate']);
|
|
165
|
+
breakWhile(this.byId.has(definition.id), () => policy.errors?.duplicate?.(definition.id) ?? new Error(`Duplicate tool: ${definition.id}`), [...tags, 'duplicate']);
|
|
157
166
|
this.byId.set(definition.id, Object.freeze({
|
|
158
167
|
...definition,
|
|
159
|
-
|
|
168
|
+
...new ModelToolRegistry([
|
|
169
|
+
{
|
|
170
|
+
id: input.id,
|
|
171
|
+
description: input.description,
|
|
172
|
+
active: typeof input.active === 'function' ? input.active.bind(input) : input.active,
|
|
173
|
+
asIntent: typeof input.asIntent === 'function' ? input.asIntent.bind(input) : input.asIntent,
|
|
174
|
+
inputSchema: input.inputSchema ?? {
|
|
175
|
+
jsonSchema: { type: 'object' },
|
|
176
|
+
parse(value) {
|
|
177
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
178
|
+
throw new TypeError('Tool input must be an object');
|
|
179
|
+
return value;
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
resolve: input.resolve?.bind(input) ?? ((value) => ({ toolId: id, input: value })),
|
|
183
|
+
},
|
|
184
|
+
]).require(input.id),
|
|
185
|
+
delegates: Object.freeze([...definition.delegates]),
|
|
160
186
|
...(definition.auxiliaryActions
|
|
161
187
|
? { auxiliaryActions: Object.freeze([...definition.auxiliaryActions]) }
|
|
162
188
|
: {}),
|
|
163
189
|
}));
|
|
190
|
+
this.modelView = undefined;
|
|
164
191
|
return this;
|
|
165
192
|
}
|
|
166
|
-
/** Register every
|
|
193
|
+
/** Register every domain Tool in iteration order. */
|
|
167
194
|
registerAll(definitions) {
|
|
168
195
|
for (const definition of definitions)
|
|
169
196
|
this.register(definition);
|
|
170
197
|
return this;
|
|
171
198
|
}
|
|
172
|
-
/** Registered
|
|
199
|
+
/** Registered domain Tool for `id`, or `undefined` when it is absent. */
|
|
173
200
|
get(goal) {
|
|
174
201
|
return this.byId.get(goal);
|
|
175
202
|
}
|
|
176
|
-
/** Whether
|
|
203
|
+
/** Whether a Tool id is registered. */
|
|
177
204
|
has(goal) {
|
|
178
205
|
return this.byId.has(goal);
|
|
179
206
|
}
|
|
180
|
-
/** Registered
|
|
207
|
+
/** Registered Tool ids in registration order. */
|
|
181
208
|
ids() {
|
|
182
209
|
return Object.freeze([...this.byId.keys()]);
|
|
183
210
|
}
|
|
184
|
-
/** Registered
|
|
211
|
+
/** Registered goals in registration order. */
|
|
185
212
|
get definitions() {
|
|
186
213
|
return Object.freeze([...this.byId.values()]);
|
|
187
214
|
}
|
|
188
|
-
/** Iterate the registered
|
|
215
|
+
/** Iterate the registered goals. */
|
|
189
216
|
values() {
|
|
190
217
|
return this.byId.values();
|
|
191
218
|
}
|
|
192
|
-
/**
|
|
219
|
+
/** Demand discovery uses tool metadata; domain fields remain attached to these same IDs. */
|
|
220
|
+
withIntent(context) {
|
|
221
|
+
return this.models().withIntent(context);
|
|
222
|
+
}
|
|
223
|
+
/** Resolve a grouped transport's selected Tool through that Tool's own parser and resolver. */
|
|
224
|
+
resolve(selection, context) {
|
|
225
|
+
return this.models().resolve(selection, context);
|
|
226
|
+
}
|
|
227
|
+
/** Explicit node selection uses the same immutable model projection. */
|
|
228
|
+
select(ids, ...context) {
|
|
229
|
+
return context.length ? this.models().select(ids, context[0]) : this.models().select(ids);
|
|
230
|
+
}
|
|
231
|
+
/** Cache only immutable declarations; request activation is evaluated by each projection. */
|
|
232
|
+
models() {
|
|
233
|
+
return (this.modelView ??= new ModelToolRegistry(this.byId.values()).seal());
|
|
234
|
+
}
|
|
235
|
+
/** Iterate `[id, tool]` pairs. */
|
|
193
236
|
entries() {
|
|
194
237
|
return this.byId.entries();
|
|
195
238
|
}
|
|
196
239
|
/**
|
|
197
|
-
* Registered
|
|
240
|
+
* Registered domain Tool for `id`.
|
|
198
241
|
*
|
|
199
242
|
* @throws TypeError When the id is not registered.
|
|
200
243
|
*/
|
|
201
244
|
require(id) {
|
|
202
245
|
const value = this.byId.get(id);
|
|
203
246
|
if (!value)
|
|
204
|
-
throw new TypeError(`Unknown
|
|
247
|
+
throw new TypeError(`Unknown tool: ${id}`);
|
|
205
248
|
return value;
|
|
206
249
|
}
|
|
207
|
-
/** Whether the
|
|
208
|
-
allows(goal,
|
|
209
|
-
return this.byId.get(goal)?.
|
|
250
|
+
/** Whether the Tool declares this delegate; unknown goals allow nothing. */
|
|
251
|
+
allows(goal, delegate) {
|
|
252
|
+
return this.byId.get(goal)?.delegates.includes(delegate) ?? false;
|
|
210
253
|
}
|
|
211
254
|
/**
|
|
212
|
-
* Copy the selected
|
|
255
|
+
* Copy the selected goals out of the registry.
|
|
213
256
|
*
|
|
214
257
|
* @param goals - Ids to include; the default is every registered id, in registry order.
|
|
215
258
|
* @returns Descriptions whose arrays are copied so callers cannot mutate registry state.
|
|
@@ -218,7 +261,10 @@ export class IntentRegistry {
|
|
|
218
261
|
const selected = new Set(goals);
|
|
219
262
|
return [...this.byId.values()]
|
|
220
263
|
.filter((item) => selected.has(item.id))
|
|
221
|
-
.map((item) => ({
|
|
264
|
+
.map((item) => ({
|
|
265
|
+
...item,
|
|
266
|
+
delegates: [...item.delegates],
|
|
267
|
+
}));
|
|
222
268
|
}
|
|
223
269
|
/** Finalize the registry; no registration is accepted afterwards. */
|
|
224
270
|
seal() {
|
|
@@ -229,7 +275,7 @@ export class IntentRegistry {
|
|
|
229
275
|
/**
|
|
230
276
|
* Create and seal a complete catalog; use the constructor for incremental installation.
|
|
231
277
|
*
|
|
232
|
-
* @param definitions -
|
|
278
|
+
* @param definitions - Goal declarations registered in iteration order.
|
|
233
279
|
* @param policy - Optional registry policy forwarded to the constructor.
|
|
234
280
|
* @returns A sealed registry.
|
|
235
281
|
* @throws A configured error for the first invalid or duplicate declaration.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Domain Tools Kit: an ordered, sealable registry of scope declarations and their aliases.
|
|
3
3
|
*
|
|
4
|
-
* Place in the package: part of the
|
|
4
|
+
* Place in the package: part of the domain Tool Kit. Categories, extra fields and intent
|
|
5
5
|
* acceptance policy are App configuration; this class owns validation, alias normalization,
|
|
6
6
|
* relationship lookups and sealing.
|
|
7
7
|
*
|
|
8
8
|
* Exports: `ScopeRegistry`, `createScopeRegistry`, and the scope registry types.
|
|
9
9
|
*/
|
|
10
|
-
import type { ScopeDefinition, ScopeDescription, ScopeRegistryPolicy, RegisteredScope, RegisteredScopeEvidence } from '../../structs/kits/
|
|
10
|
+
import type { ScopeDefinition, ScopeDescription, ScopeRegistryPolicy, RegisteredScope, RegisteredScopeEvidence } from '../../structs/kits/domains/scopes.js';
|
|
11
11
|
/**
|
|
12
12
|
* Generic scope relationships; categories, intent policy and extra fields belong to the host.
|
|
13
13
|
*
|
|
@@ -33,11 +33,11 @@ export declare class ScopeRegistry<Definition extends ScopeDefinition = ScopeDef
|
|
|
33
33
|
* Every name is checked for conflicts before any of them is stored, so a rejected scope
|
|
34
34
|
* leaves no partial alias entry behind.
|
|
35
35
|
*
|
|
36
|
-
* @param input - Scope declaration; the raw object is retained for `
|
|
36
|
+
* @param input - Scope declaration; the raw object is retained for `acceptsTool` overrides
|
|
37
37
|
* while the compiled copy serves lookups.
|
|
38
38
|
* @returns This registry, for chaining.
|
|
39
39
|
* @throws A configured error for a sealed registry, an invalid name/description/category,
|
|
40
|
-
* a missing required binding, duplicate
|
|
40
|
+
* a missing required binding, duplicate Tool ids or an already-claimed name.
|
|
41
41
|
*/
|
|
42
42
|
register(input: Definition): this;
|
|
43
43
|
/** Register every scope in iteration order. */
|
|
@@ -45,9 +45,9 @@ export declare class ScopeRegistry<Definition extends ScopeDefinition = ScopeDef
|
|
|
45
45
|
/** Finalize the registry; no registration is accepted afterwards. */
|
|
46
46
|
seal(): this;
|
|
47
47
|
/** Registered scopes in registration order. */
|
|
48
|
-
get definitions(): readonly Readonly<Omit<Readonly<ScopeDefinition & import("../../utils/registration.js").RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ("toolIds" | "
|
|
48
|
+
get definitions(): readonly Readonly<Omit<Readonly<ScopeDefinition & import("../../utils/registration.js").RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ("toolIds" | "goalIds" | "queryScopeIds" | "knowledgeTopicIds" | "aliases")> & {
|
|
49
49
|
readonly toolIds: [NonNullable<Definition["toolIds"]>] extends [never] ? readonly [] : NonNullable<Definition["toolIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["toolIds"]> : readonly string[];
|
|
50
|
-
readonly
|
|
50
|
+
readonly goalIds: [NonNullable<Definition["goalIds"]>] extends [never] ? readonly [] : NonNullable<Definition["goalIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["goalIds"]> : readonly string[];
|
|
51
51
|
readonly queryScopeIds: [NonNullable<Definition["queryScopeIds"]>] extends [never] ? readonly [] : NonNullable<Definition["queryScopeIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["queryScopeIds"]> : readonly string[];
|
|
52
52
|
readonly knowledgeTopicIds: [NonNullable<Definition["knowledgeTopicIds"]>] extends [never] ? readonly [] : NonNullable<Definition["knowledgeTopicIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["knowledgeTopicIds"]> : readonly string[];
|
|
53
53
|
readonly aliases: [NonNullable<Definition["aliases"]>] extends [never] ? readonly [] : NonNullable<Definition["aliases"]> extends readonly string[] ? Readonly<readonly string[] & Definition["aliases"]> : readonly string[];
|
|
@@ -57,9 +57,9 @@ export declare class ScopeRegistry<Definition extends ScopeDefinition = ScopeDef
|
|
|
57
57
|
/** Registered scope ids in registration order; aliases are not included. */
|
|
58
58
|
ids(): readonly string[];
|
|
59
59
|
/** Iterate the registered scopes. */
|
|
60
|
-
values(): MapIterator<Readonly<Omit<Readonly<ScopeDefinition & import("../../utils/registration.js").RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ("toolIds" | "
|
|
60
|
+
values(): MapIterator<Readonly<Omit<Readonly<ScopeDefinition & import("../../utils/registration.js").RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ("toolIds" | "goalIds" | "queryScopeIds" | "knowledgeTopicIds" | "aliases")> & {
|
|
61
61
|
readonly toolIds: [NonNullable<Definition["toolIds"]>] extends [never] ? readonly [] : NonNullable<Definition["toolIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["toolIds"]> : readonly string[];
|
|
62
|
-
readonly
|
|
62
|
+
readonly goalIds: [NonNullable<Definition["goalIds"]>] extends [never] ? readonly [] : NonNullable<Definition["goalIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["goalIds"]> : readonly string[];
|
|
63
63
|
readonly queryScopeIds: [NonNullable<Definition["queryScopeIds"]>] extends [never] ? readonly [] : NonNullable<Definition["queryScopeIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["queryScopeIds"]> : readonly string[];
|
|
64
64
|
readonly knowledgeTopicIds: [NonNullable<Definition["knowledgeTopicIds"]>] extends [never] ? readonly [] : NonNullable<Definition["knowledgeTopicIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["knowledgeTopicIds"]> : readonly string[];
|
|
65
65
|
readonly aliases: [NonNullable<Definition["aliases"]>] extends [never] ? readonly [] : NonNullable<Definition["aliases"]> extends readonly string[] ? Readonly<readonly string[] & Definition["aliases"]> : readonly string[];
|
|
@@ -67,9 +67,9 @@ export declare class ScopeRegistry<Definition extends ScopeDefinition = ScopeDef
|
|
|
67
67
|
evidence: [NonNullable<Definition["evidence"]>] extends [never] ? readonly [] : NonNullable<Definition["evidence"]> extends readonly import("../evidence.js").EvidenceRequirement[] ? readonly import("../evidence.js").EvidenceRequirement[] & Definition["evidence"] extends infer T extends readonly import("../evidence.js").EvidenceRequirement[] ? { readonly [Index in keyof T]: Readonly<import("../../utils/registration.js").RegistrationData<T[Index]>>; } : never : readonly Readonly<import("../../utils/registration.js").RegistrationData<NonNullable<Definition["evidence"]>[number]>>[];
|
|
68
68
|
}>>;
|
|
69
69
|
/** Iterate `[id, scope]` pairs. */
|
|
70
|
-
entries(): MapIterator<[string, Readonly<Omit<Readonly<ScopeDefinition & import("../../utils/registration.js").RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ("toolIds" | "
|
|
70
|
+
entries(): MapIterator<[string, Readonly<Omit<Readonly<ScopeDefinition & import("../../utils/registration.js").RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ("toolIds" | "goalIds" | "queryScopeIds" | "knowledgeTopicIds" | "aliases")> & {
|
|
71
71
|
readonly toolIds: [NonNullable<Definition["toolIds"]>] extends [never] ? readonly [] : NonNullable<Definition["toolIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["toolIds"]> : readonly string[];
|
|
72
|
-
readonly
|
|
72
|
+
readonly goalIds: [NonNullable<Definition["goalIds"]>] extends [never] ? readonly [] : NonNullable<Definition["goalIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["goalIds"]> : readonly string[];
|
|
73
73
|
readonly queryScopeIds: [NonNullable<Definition["queryScopeIds"]>] extends [never] ? readonly [] : NonNullable<Definition["queryScopeIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["queryScopeIds"]> : readonly string[];
|
|
74
74
|
readonly knowledgeTopicIds: [NonNullable<Definition["knowledgeTopicIds"]>] extends [never] ? readonly [] : NonNullable<Definition["knowledgeTopicIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["knowledgeTopicIds"]> : readonly string[];
|
|
75
75
|
readonly aliases: [NonNullable<Definition["aliases"]>] extends [never] ? readonly [] : NonNullable<Definition["aliases"]> extends readonly string[] ? Readonly<readonly string[] & Definition["aliases"]> : readonly string[];
|
|
@@ -81,9 +81,9 @@ export declare class ScopeRegistry<Definition extends ScopeDefinition = ScopeDef
|
|
|
81
81
|
*
|
|
82
82
|
* @throws TypeError When the name resolves to nothing.
|
|
83
83
|
*/
|
|
84
|
-
require(id: string): Readonly<Omit<Readonly<ScopeDefinition & import("../../utils/registration.js").RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ("toolIds" | "
|
|
84
|
+
require(id: string): Readonly<Omit<Readonly<ScopeDefinition & import("../../utils/registration.js").RegistrationData<Definition> & Pick<Definition, Extract<keyof Definition, keyof ScopeDefinition>>>, "evidence" | ("toolIds" | "goalIds" | "queryScopeIds" | "knowledgeTopicIds" | "aliases")> & {
|
|
85
85
|
readonly toolIds: [NonNullable<Definition["toolIds"]>] extends [never] ? readonly [] : NonNullable<Definition["toolIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["toolIds"]> : readonly string[];
|
|
86
|
-
readonly
|
|
86
|
+
readonly goalIds: [NonNullable<Definition["goalIds"]>] extends [never] ? readonly [] : NonNullable<Definition["goalIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["goalIds"]> : readonly string[];
|
|
87
87
|
readonly queryScopeIds: [NonNullable<Definition["queryScopeIds"]>] extends [never] ? readonly [] : NonNullable<Definition["queryScopeIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["queryScopeIds"]> : readonly string[];
|
|
88
88
|
readonly knowledgeTopicIds: [NonNullable<Definition["knowledgeTopicIds"]>] extends [never] ? readonly [] : NonNullable<Definition["knowledgeTopicIds"]> extends readonly string[] ? Readonly<readonly string[] & Definition["knowledgeTopicIds"]> : readonly string[];
|
|
89
89
|
readonly aliases: [NonNullable<Definition["aliases"]>] extends [never] ? readonly [] : NonNullable<Definition["aliases"]> extends readonly string[] ? Readonly<readonly string[] & Definition["aliases"]> : readonly string[];
|
|
@@ -99,10 +99,10 @@ export declare class ScopeRegistry<Definition extends ScopeDefinition = ScopeDef
|
|
|
99
99
|
/**
|
|
100
100
|
* Whether a scope accepts an intent.
|
|
101
101
|
*
|
|
102
|
-
* The App may override the declared `
|
|
102
|
+
* The App may override the declared `goalIds` through `acceptsTool`; without an
|
|
103
103
|
* override the membership check applies.
|
|
104
104
|
*/
|
|
105
|
-
|
|
105
|
+
acceptsTool(scope: string, goal: string): boolean;
|
|
106
106
|
/** Whether the scope declares this query scope; a null scope accepts nothing. */
|
|
107
107
|
acceptsQuery(scope: string | null, queryScope: string): boolean;
|
|
108
108
|
/** Whether the scope belongs to the given App category. */
|
|
@@ -116,9 +116,9 @@ export declare class ScopeRegistry<Definition extends ScopeDefinition = ScopeDef
|
|
|
116
116
|
/** Declared context tier of one scope, if any. */
|
|
117
117
|
contextTier(scope?: string | null): Definition['contextTier'] | undefined;
|
|
118
118
|
/**
|
|
119
|
-
* Copy the scopes that accept at least one of the given
|
|
119
|
+
* Copy the scopes that accept at least one of the given goals.
|
|
120
120
|
*
|
|
121
|
-
* @param goals -
|
|
121
|
+
* @param goals - Goal ids to filter by; omit to include every registered scope.
|
|
122
122
|
* @returns Descriptions whose arrays are copied so callers cannot mutate registry state.
|
|
123
123
|
*/
|
|
124
124
|
describe(goals?: readonly string[]): ScopeDescription<Definition>[];
|
|
@@ -132,4 +132,4 @@ export declare class ScopeRegistry<Definition extends ScopeDefinition = ScopeDef
|
|
|
132
132
|
* @throws A configured error for the first invalid or duplicate declaration.
|
|
133
133
|
*/
|
|
134
134
|
export declare function createScopeRegistry<Definition extends ScopeDefinition>(definitions: Iterable<Definition>, policy?: ScopeRegistryPolicy<Definition>): ScopeRegistry<Definition>;
|
|
135
|
-
export type { ScopeDefinition, ScopeDescription, ScopeRegistryPolicy, RegisteredScope, RegisteredScopeEvidence, } from '../../structs/kits/
|
|
135
|
+
export type { ScopeDefinition, ScopeDescription, ScopeRegistryPolicy, RegisteredScope, RegisteredScopeEvidence, } from '../../structs/kits/domains/scopes.js';
|
|
@@ -31,7 +31,7 @@ export class ScopeRegistry {
|
|
|
31
31
|
...registrationData(policy, [
|
|
32
32
|
'idPattern',
|
|
33
33
|
'assertDefinition',
|
|
34
|
-
'
|
|
34
|
+
'acceptsTool',
|
|
35
35
|
'errors',
|
|
36
36
|
...listFields,
|
|
37
37
|
]),
|
|
@@ -43,7 +43,7 @@ export class ScopeRegistry {
|
|
|
43
43
|
invalid: typeof invalid === 'function' ? invalid.bind(errorPorts) : invalid,
|
|
44
44
|
}),
|
|
45
45
|
assertDefinition: policy.assertDefinition?.bind(policy),
|
|
46
|
-
|
|
46
|
+
acceptsTool: policy.acceptsTool?.bind(policy),
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
@@ -52,11 +52,11 @@ export class ScopeRegistry {
|
|
|
52
52
|
* Every name is checked for conflicts before any of them is stored, so a rejected scope
|
|
53
53
|
* leaves no partial alias entry behind.
|
|
54
54
|
*
|
|
55
|
-
* @param input - Scope declaration; the raw object is retained for `
|
|
55
|
+
* @param input - Scope declaration; the raw object is retained for `acceptsTool` overrides
|
|
56
56
|
* while the compiled copy serves lookups.
|
|
57
57
|
* @returns This registry, for chaining.
|
|
58
58
|
* @throws A configured error for a sealed registry, an invalid name/description/category,
|
|
59
|
-
* a missing required binding, duplicate
|
|
59
|
+
* a missing required binding, duplicate Tool ids or an already-claimed name.
|
|
60
60
|
*/
|
|
61
61
|
register(input) {
|
|
62
62
|
const definition = {
|
|
@@ -64,7 +64,7 @@ export class ScopeRegistry {
|
|
|
64
64
|
'id',
|
|
65
65
|
'description',
|
|
66
66
|
'category',
|
|
67
|
-
'
|
|
67
|
+
'goalIds',
|
|
68
68
|
'queryScopeIds',
|
|
69
69
|
'knowledgeTopicIds',
|
|
70
70
|
'toolIds',
|
|
@@ -75,7 +75,7 @@ export class ScopeRegistry {
|
|
|
75
75
|
id: input.id,
|
|
76
76
|
description: input.description,
|
|
77
77
|
category: input.category,
|
|
78
|
-
|
|
78
|
+
goalIds: input.goalIds ?? [],
|
|
79
79
|
queryScopeIds: input.queryScopeIds ?? [],
|
|
80
80
|
knowledgeTopicIds: input.knowledgeTopicIds ?? [],
|
|
81
81
|
toolIds: input.toolIds ?? [],
|
|
@@ -110,9 +110,9 @@ export class ScopeRegistry {
|
|
|
110
110
|
tags: ['identity'],
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
|
-
occur: () => policy.
|
|
113
|
+
occur: () => policy.requireGoals === true && !definition.goalIds.length,
|
|
114
114
|
error: invalid,
|
|
115
|
-
tags: ['
|
|
115
|
+
tags: ['goals', 'required'],
|
|
116
116
|
},
|
|
117
117
|
{
|
|
118
118
|
occur: [
|
|
@@ -126,18 +126,18 @@ export class ScopeRegistry {
|
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
128
|
occur: [
|
|
129
|
-
() => definition.
|
|
130
|
-
() => new Set(definition.
|
|
129
|
+
() => definition.goalIds.some((intent) => typeof intent !== 'string'),
|
|
130
|
+
() => new Set(definition.goalIds).size !== definition.goalIds.length,
|
|
131
131
|
],
|
|
132
132
|
error: invalid,
|
|
133
|
-
tags: ['
|
|
133
|
+
tags: ['goals', 'values'],
|
|
134
134
|
},
|
|
135
135
|
], tags);
|
|
136
136
|
assertion(policy.assertDefinition?.(input), 'Registry definition assertions must return void synchronously');
|
|
137
137
|
breakWhile(names.some((name) => this.byId.has(name) || this.aliases.has(name)), invalid, [...tags, 'duplicate']);
|
|
138
138
|
const frozen = Object.freeze({
|
|
139
139
|
...definition,
|
|
140
|
-
|
|
140
|
+
goalIds: Object.freeze([...definition.goalIds]),
|
|
141
141
|
toolIds: Object.freeze([...definition.toolIds]),
|
|
142
142
|
queryScopeIds: Object.freeze([...definition.queryScopeIds]),
|
|
143
143
|
knowledgeTopicIds: Object.freeze([...definition.knowledgeTopicIds]),
|
|
@@ -203,16 +203,16 @@ export class ScopeRegistry {
|
|
|
203
203
|
/**
|
|
204
204
|
* Whether a scope accepts an intent.
|
|
205
205
|
*
|
|
206
|
-
* The App may override the declared `
|
|
206
|
+
* The App may override the declared `goalIds` through `acceptsTool`; without an
|
|
207
207
|
* override the membership check applies.
|
|
208
208
|
*/
|
|
209
|
-
|
|
209
|
+
acceptsTool(scope, goal) {
|
|
210
210
|
const definition = this.get(scope);
|
|
211
211
|
if (!definition)
|
|
212
212
|
return false;
|
|
213
|
-
const ids = definition.
|
|
214
|
-
return this.policy.
|
|
215
|
-
? booleanResult(this.policy.
|
|
213
|
+
const ids = definition.goalIds;
|
|
214
|
+
return this.policy.acceptsTool
|
|
215
|
+
? booleanResult(this.policy.acceptsTool(this.sources.get(this.normalize(scope)), goal), 'Scope intent predicates must return boolean synchronously')
|
|
216
216
|
: ids.includes(goal);
|
|
217
217
|
}
|
|
218
218
|
/** Whether the scope declares this query scope; a null scope accepts nothing. */
|
|
@@ -241,18 +241,18 @@ export class ScopeRegistry {
|
|
|
241
241
|
return this.get(scope)?.contextTier;
|
|
242
242
|
}
|
|
243
243
|
/**
|
|
244
|
-
* Copy the scopes that accept at least one of the given
|
|
244
|
+
* Copy the scopes that accept at least one of the given goals.
|
|
245
245
|
*
|
|
246
|
-
* @param goals -
|
|
246
|
+
* @param goals - Goal ids to filter by; omit to include every registered scope.
|
|
247
247
|
* @returns Descriptions whose arrays are copied so callers cannot mutate registry state.
|
|
248
248
|
*/
|
|
249
249
|
describe(goals) {
|
|
250
250
|
const selected = goals ? new Set(goals) : undefined;
|
|
251
251
|
return [...this.byId.values()]
|
|
252
|
-
.filter((item) => !selected || item.
|
|
252
|
+
.filter((item) => !selected || item.goalIds.some((goal) => selected.has(goal)))
|
|
253
253
|
.map((item) => ({
|
|
254
254
|
...item,
|
|
255
|
-
|
|
255
|
+
goalIds: [...item.goalIds],
|
|
256
256
|
queryScopeIds: [...item.queryScopeIds],
|
|
257
257
|
knowledgeTopicIds: [...item.knowledgeTopicIds],
|
|
258
258
|
toolIds: [...item.toolIds],
|
package/dist/esm/kits/index.d.ts
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* path; this file only exists for callers that prefer one import for the whole set. Core
|
|
6
6
|
* never imports from this directory, so nothing here becomes a runtime requirement.
|
|
7
7
|
*
|
|
8
|
-
* Exports: the Kit namespaces (`Interaction`, `
|
|
8
|
+
* Exports: the Kit namespaces (`Interaction`, `Tools`, `Knowledge`, `Answering`,
|
|
9
9
|
* `Presentation`, `Normalization`, `Delivery`, `Projection`, `Aggregation`, `Retrieval`,
|
|
10
|
-
* `Evidence`, `Policies`, `Candidates`, `TextSkills`, `TextSearch`, `
|
|
11
|
-
* `VectorSearch`) plus every Kit type. Individual Kit paths stay the default.
|
|
10
|
+
* `Evidence`, `Policies`, `Candidates`, `TextSkills`, `TextSearch`, `TextBlocks`,
|
|
11
|
+
* `ModelCalls`, `VectorSearch`) plus every Kit type. Individual Kit paths stay the default.
|
|
12
12
|
*/
|
|
13
13
|
export { Interaction } from './interaction/index.js';
|
|
14
|
-
export
|
|
14
|
+
export * from './domains/index.js';
|
|
15
15
|
export { Tools } from './tools.js';
|
|
16
16
|
export { Knowledge } from './knowledge/index.js';
|
|
17
17
|
export { Answering } from './answering/index.js';
|
|
@@ -27,8 +27,9 @@ export { Candidates } from './candidates.js';
|
|
|
27
27
|
export { TextSkills } from './text-skills.js';
|
|
28
28
|
export { TextSearch } from './search.js';
|
|
29
29
|
export * from './search.js';
|
|
30
|
+
export { TextBlocks } from './text-blocks.js';
|
|
31
|
+
export * from './text-blocks.js';
|
|
30
32
|
export * from './interaction/index.js';
|
|
31
|
-
export * from './intents/index.js';
|
|
32
33
|
export * from './tools.js';
|
|
33
34
|
export * from './knowledge/index.js';
|
|
34
35
|
export * from './answering/index.js';
|
package/dist/esm/kits/index.js
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* path; this file only exists for callers that prefer one import for the whole set. Core
|
|
6
6
|
* never imports from this directory, so nothing here becomes a runtime requirement.
|
|
7
7
|
*
|
|
8
|
-
* Exports: the Kit namespaces (`Interaction`, `
|
|
8
|
+
* Exports: the Kit namespaces (`Interaction`, `Tools`, `Knowledge`, `Answering`,
|
|
9
9
|
* `Presentation`, `Normalization`, `Delivery`, `Projection`, `Aggregation`, `Retrieval`,
|
|
10
|
-
* `Evidence`, `Policies`, `Candidates`, `TextSkills`, `TextSearch`, `
|
|
11
|
-
* `VectorSearch`) plus every Kit type. Individual Kit paths stay the default.
|
|
10
|
+
* `Evidence`, `Policies`, `Candidates`, `TextSkills`, `TextSearch`, `TextBlocks`,
|
|
11
|
+
* `ModelCalls`, `VectorSearch`) plus every Kit type. Individual Kit paths stay the default.
|
|
12
12
|
*/
|
|
13
13
|
export { Interaction } from './interaction/index.js';
|
|
14
|
-
export
|
|
14
|
+
export * from './domains/index.js';
|
|
15
15
|
export { Tools } from './tools.js';
|
|
16
16
|
export { Knowledge } from './knowledge/index.js';
|
|
17
17
|
export { Answering } from './answering/index.js';
|
|
@@ -27,9 +27,10 @@ export { Candidates } from './candidates.js';
|
|
|
27
27
|
export { TextSkills } from './text-skills.js';
|
|
28
28
|
export { TextSearch } from './search.js';
|
|
29
29
|
export * from './search.js';
|
|
30
|
+
export { TextBlocks } from './text-blocks.js';
|
|
31
|
+
export * from './text-blocks.js';
|
|
30
32
|
// Types remain available with either individual or explicit bulk imports.
|
|
31
33
|
export * from './interaction/index.js';
|
|
32
|
-
export * from './intents/index.js';
|
|
33
34
|
export * from './tools.js';
|
|
34
35
|
export * from './knowledge/index.js';
|
|
35
36
|
export * from './answering/index.js';
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Exports: `defineKnowledgeCatalog`, and the knowledge document/read/snapshot types.
|
|
9
9
|
*/
|
|
10
|
+
import { nativeSubFlowSync } from '../../diagnostics/native-sub-flow.js';
|
|
10
11
|
import { readonlyCatalog } from '../../utils/catalog.js';
|
|
11
12
|
import { compileKnowledgeDocument, knowledgeText } from './sections.js';
|
|
12
13
|
import { observeSafely } from '../../utils/observer.js';
|
|
@@ -65,37 +66,39 @@ export function defineKnowledgeCatalog(documents, options = {}) {
|
|
|
65
66
|
...readonlyCatalog([...catalog.values()].map((entry) => entry.document), (id) => new TypeError(`Unknown knowledge document: ${id}`)),
|
|
66
67
|
sectionIds,
|
|
67
68
|
assertSelection,
|
|
68
|
-
read(input) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
69
|
+
read(input, context = {}) {
|
|
70
|
+
return nativeSubFlowSync(context, 'knowledge', input.documentId, () => {
|
|
71
|
+
const { read, entry } = resolve(input), raw = read.selection;
|
|
72
|
+
const selection = raw.mode === 'document'
|
|
73
|
+
? Object.freeze({ mode: 'document' })
|
|
74
|
+
: Object.freeze({ mode: raw.mode, sectionIds: Object.freeze([...raw.sectionIds]) });
|
|
75
|
+
const content = (selection.mode === 'document'
|
|
76
|
+
? knowledgeText(entry.document.parts)
|
|
77
|
+
: selection.sectionIds
|
|
78
|
+
.map((id) => knowledgeText(entry.sections.get(id).parts, selection.mode === 'subtree'))
|
|
79
|
+
.join('\n\n')).trim();
|
|
80
|
+
if (maxChars !== undefined && content.length > maxChars)
|
|
81
|
+
throw new RangeError('Knowledge selection exceeds its budget');
|
|
82
|
+
// Preserve the existing opaque snapshot identity format.
|
|
83
|
+
const identitySelection = selection.mode === 'document'
|
|
84
|
+
? selection
|
|
85
|
+
: { mode: selection.mode, sections: selection.sectionIds };
|
|
86
|
+
const snapshot = Object.freeze({
|
|
87
|
+
documentId: read.documentId,
|
|
88
|
+
selection,
|
|
89
|
+
revision: entry.document.revision,
|
|
90
|
+
locale: entry.document.locale,
|
|
91
|
+
content,
|
|
92
|
+
id: JSON.stringify([
|
|
93
|
+
read.documentId,
|
|
94
|
+
entry.document.revision,
|
|
95
|
+
entry.document.locale,
|
|
96
|
+
identitySelection,
|
|
97
|
+
]),
|
|
98
|
+
});
|
|
99
|
+
observeSafely(observe, snapshot);
|
|
100
|
+
return snapshot;
|
|
96
101
|
});
|
|
97
|
-
observeSafely(observe, snapshot);
|
|
98
|
-
return snapshot;
|
|
99
102
|
},
|
|
100
103
|
});
|
|
101
104
|
}
|
|
@@ -38,7 +38,7 @@ export declare function definePolicySet<Input, Kind extends string>(definitions:
|
|
|
38
38
|
* boolean `handled` or omits `value` while claiming to have handled the input.
|
|
39
39
|
*/
|
|
40
40
|
export declare function defineRecoveryChain<Input, Result>(definitions: readonly RecoveryDefinition<Input, Result>[]): Readonly<{
|
|
41
|
-
tryRecover: (input: Input) => RecoveryResult<Result>;
|
|
41
|
+
tryRecover: (input: Input, execution?: Partial<import("../structs/common.js").ExecutionContext>) => RecoveryResult<Result>;
|
|
42
42
|
definitions: readonly Readonly<{
|
|
43
43
|
id: string;
|
|
44
44
|
description: string;
|