@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
|
@@ -11,6 +11,7 @@ exports.defineAnswerTaskCatalog = defineAnswerTaskCatalog;
|
|
|
11
11
|
*
|
|
12
12
|
* Exports: `defineAnswerReaderCatalog`, `defineAnswerTaskCatalog`, and the task/reader types.
|
|
13
13
|
*/
|
|
14
|
+
const native_sub_flow_js_1 = require("../../diagnostics/native-sub-flow.js");
|
|
14
15
|
const catalog_js_1 = require("../../utils/catalog.js");
|
|
15
16
|
const synchronous_js_1 = require("../../utils/synchronous.js");
|
|
16
17
|
const object_js_1 = require("../../utils/object.js");
|
|
@@ -54,10 +55,10 @@ function defineAnswerTaskCatalog(definitions, ports) {
|
|
|
54
55
|
!definition.description?.trim() ||
|
|
55
56
|
!readers.has(definition.readerId) ||
|
|
56
57
|
!outputs.has(definition.outputId) ||
|
|
57
|
-
!Array.isArray(definition.
|
|
58
|
-
!definition.
|
|
59
|
-
definition.
|
|
60
|
-
new Set(definition.
|
|
58
|
+
!Array.isArray(definition.goalIds) ||
|
|
59
|
+
!definition.goalIds.length ||
|
|
60
|
+
definition.goalIds.some((id) => typeof id !== 'string' || !id.trim()) ||
|
|
61
|
+
new Set(definition.goalIds).size !== definition.goalIds.length ||
|
|
61
62
|
!Array.isArray(definition.checkIds) ||
|
|
62
63
|
new Set(definition.checkIds).size !== definition.checkIds.length ||
|
|
63
64
|
definition.checkIds.some((id) => !checkIds.includes(id)))
|
|
@@ -71,7 +72,7 @@ function defineAnswerTaskCatalog(definitions, ports) {
|
|
|
71
72
|
readerId: definition.readerId,
|
|
72
73
|
outputId: definition.outputId,
|
|
73
74
|
scopeId: definition.scopeId,
|
|
74
|
-
|
|
75
|
+
goalIds: Object.freeze([...definition.goalIds]),
|
|
75
76
|
checkIds: Object.freeze([...definition.checkIds]),
|
|
76
77
|
inputSchema: (0, schema_adapter_js_1.snapshotSchemaAdapter)(definition.inputSchema),
|
|
77
78
|
metadata,
|
|
@@ -100,16 +101,18 @@ function defineAnswerTaskCatalog(definitions, ports) {
|
|
|
100
101
|
* @throws TypeError For an unknown task, a parse failure, or a reader returning a Promise.
|
|
101
102
|
*/
|
|
102
103
|
read(request, context) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
return (0, native_sub_flow_js_1.nativeSubFlowSync)(context, 'task', request.taskId, () => {
|
|
105
|
+
const { input, task, reader } = prepare(request, context);
|
|
106
|
+
const value = (0, synchronous_js_1.synchronous)(reader.read(input, {
|
|
107
|
+
...context,
|
|
108
|
+
app: context.app,
|
|
109
|
+
signal: context.signal,
|
|
110
|
+
diagnostics: context.diagnostics,
|
|
111
|
+
task,
|
|
112
|
+
}), 'Synchronous answer readers must not return a Promise');
|
|
113
|
+
context.signal.throwIfAborted();
|
|
114
|
+
return value;
|
|
115
|
+
});
|
|
113
116
|
},
|
|
114
117
|
/**
|
|
115
118
|
* Read evidence through a task's registered reader, awaiting an async reader.
|
|
@@ -117,16 +120,18 @@ function defineAnswerTaskCatalog(definitions, ports) {
|
|
|
117
120
|
* @throws TypeError For an unknown task or a parse failure; aborts with the caller's signal.
|
|
118
121
|
*/
|
|
119
122
|
async readAsync(request, context) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
return (0, native_sub_flow_js_1.nativeSubFlowAsync)(context, 'task', request.taskId, async () => {
|
|
124
|
+
const { input, task, reader } = prepare(request, context);
|
|
125
|
+
const value = await (0, cancellation_js_1.awaitWithSignal)(reader.read(input, {
|
|
126
|
+
...context,
|
|
127
|
+
app: context.app,
|
|
128
|
+
signal: context.signal,
|
|
129
|
+
diagnostics: context.diagnostics,
|
|
130
|
+
task,
|
|
131
|
+
}), context.signal);
|
|
132
|
+
context.signal.throwIfAborted();
|
|
133
|
+
return value;
|
|
134
|
+
});
|
|
130
135
|
},
|
|
131
136
|
});
|
|
132
137
|
}
|
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Delivery = void 0;
|
|
4
4
|
exports.defineDelivery = defineDelivery;
|
|
5
|
+
/**
|
|
6
|
+
* Delivery Kit: run an ordered, synchronous stage pipeline that ends with one result.
|
|
7
|
+
*
|
|
8
|
+
* Place in the package: an optional App-side delivery pipeline (for example formatting and
|
|
9
|
+
* sending one reply). The Kit owns ordering, cancellation checks and outcome validation; the
|
|
10
|
+
* stages, their state and the actual side effects belong to the App.
|
|
11
|
+
*
|
|
12
|
+
* Exports: `defineDelivery`, `Delivery`, and the delivery option/outcome types.
|
|
13
|
+
*/
|
|
14
|
+
const native_sub_flow_js_1 = require("../diagnostics/native-sub-flow.js");
|
|
5
15
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
6
16
|
/**
|
|
7
17
|
* Compile a delivery pipeline from its declared stages.
|
|
@@ -42,33 +52,35 @@ function defineDelivery(options) {
|
|
|
42
52
|
* handler results.
|
|
43
53
|
*/
|
|
44
54
|
deliver(input, execution) {
|
|
45
|
-
|
|
46
|
-
const state = (0, synchronous_js_1.synchronous)(createState(input, execution), 'Delivery state creation must be synchronous');
|
|
47
|
-
const context = {
|
|
48
|
-
...execution,
|
|
49
|
-
signal: execution.signal,
|
|
50
|
-
diagnostics: execution.diagnostics,
|
|
51
|
-
app: input,
|
|
52
|
-
};
|
|
53
|
-
for (const stage of stages) {
|
|
55
|
+
return (0, native_sub_flow_js_1.nativeSubFlowSync)(execution, 'delivery', 'delivery', () => {
|
|
54
56
|
execution.signal.throwIfAborted();
|
|
55
|
-
(0, synchronous_js_1.synchronous)(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
const state = (0, synchronous_js_1.synchronous)(createState(input, execution), 'Delivery state creation must be synchronous');
|
|
58
|
+
const context = {
|
|
59
|
+
...execution,
|
|
60
|
+
signal: execution.signal,
|
|
61
|
+
diagnostics: execution.diagnostics,
|
|
62
|
+
app: input,
|
|
63
|
+
};
|
|
64
|
+
for (const stage of stages) {
|
|
65
|
+
execution.signal.throwIfAborted();
|
|
66
|
+
(0, synchronous_js_1.synchronous)(beforeStage?.({ stageId: stage.id, state }, context), 'Delivery hooks must be synchronous');
|
|
67
|
+
execution.signal.throwIfAborted();
|
|
68
|
+
if (!stage.handle)
|
|
69
|
+
continue;
|
|
70
|
+
const outcome = (0, synchronous_js_1.synchronous)(stage.handle(state, context), 'Delivery handlers must be synchronous');
|
|
67
71
|
execution.signal.throwIfAborted();
|
|
68
|
-
|
|
72
|
+
if (!outcome ||
|
|
73
|
+
!['continue', 'complete'].includes(outcome.type) ||
|
|
74
|
+
(outcome.type === 'complete' && !('value' in outcome)))
|
|
75
|
+
throw new TypeError('Delivery handlers require explicit continue/complete');
|
|
76
|
+
if (outcome.type === 'complete') {
|
|
77
|
+
const value = outcome.value;
|
|
78
|
+
execution.signal.throwIfAborted();
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
69
81
|
}
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
throw (0, synchronous_js_1.synchronous)(missingResult(), 'Delivery errors must be synchronous');
|
|
83
|
+
});
|
|
72
84
|
},
|
|
73
85
|
});
|
|
74
86
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineAgentCatalog = defineAgentCatalog;
|
|
4
|
+
/**
|
|
5
|
+
* Domain Tools Kit: project registered goals, scopes and tools into one task-facing catalog.
|
|
6
|
+
*
|
|
7
|
+
* Place in the package: part of the domain Tool Kit. It reads the actual registries supplied by
|
|
8
|
+
* the App instead of maintaining a parallel capability list, so an intent is only advertised
|
|
9
|
+
* when its tools, scopes and availability agree.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `defineAgentCatalog`, and the catalog intent/scope/port types.
|
|
12
|
+
*/
|
|
13
|
+
const synchronous_js_1 = require("../../utils/synchronous.js");
|
|
14
|
+
const tool_conditions_js_1 = require("../../capabilities/tool-conditions.js");
|
|
15
|
+
/**
|
|
16
|
+
* Compile a catalog projection over the App's live registries.
|
|
17
|
+
*
|
|
18
|
+
* The actual registries determine availability and relationships. No parallel capability list
|
|
19
|
+
* exists: `goalIds` filters by tool support, `modelCatalog` narrows to the currently accepted
|
|
20
|
+
* task when `restrictToTask` is enabled, and scope tool ids are filtered to tools that exist.
|
|
21
|
+
*
|
|
22
|
+
* @param ports - Sources for Tool ids, goals, scopes, the current task, the tool registry
|
|
23
|
+
* and the `restrictToTask` switch.
|
|
24
|
+
* @returns A frozen projection with `goalIds`, `goalDelegates`, `goalCatalog`,
|
|
25
|
+
* `scopeCatalog` and `modelCatalog`.
|
|
26
|
+
* @throws TypeError When a supplied predicate does not return a boolean synchronously.
|
|
27
|
+
*/
|
|
28
|
+
function defineAgentCatalog(ports) {
|
|
29
|
+
const ids = ports.goalIds.bind(ports), goals = ports.goals.bind(ports), scopes = ports.scopes.bind(ports), task = ports.currentTask.bind(ports);
|
|
30
|
+
const tools = {
|
|
31
|
+
values: ports.tools.values.bind(ports.tools),
|
|
32
|
+
has: ports.tools.has.bind(ports.tools),
|
|
33
|
+
supports: ports.tools.supportsGoal.bind(ports.tools),
|
|
34
|
+
describe: ports.tools.describe.bind(ports.tools),
|
|
35
|
+
};
|
|
36
|
+
const restrict = ports.restrictToTask !== false;
|
|
37
|
+
const boolean = (value) => (0, synchronous_js_1.booleanResult)(value, 'Catalog predicates must be synchronous', 'Catalog predicates must return boolean');
|
|
38
|
+
/** Whether one goal is active and its demand metadata currently participates. */
|
|
39
|
+
const goalAvailable = (goal, app) => {
|
|
40
|
+
const tool = goal;
|
|
41
|
+
if (!(0, tool_conditions_js_1.toolActive)(tool.active, app))
|
|
42
|
+
return false;
|
|
43
|
+
const metadata = tool.asIntent;
|
|
44
|
+
if (metadata === undefined || metadata === true || typeof metadata === 'string')
|
|
45
|
+
return true;
|
|
46
|
+
if (typeof metadata === 'function')
|
|
47
|
+
return (0, tool_conditions_js_1.toolActive)(metadata, app);
|
|
48
|
+
return (0, tool_conditions_js_1.toolActive)(metadata.when, app);
|
|
49
|
+
};
|
|
50
|
+
const goalIds = (app) => ids(app).filter((id) => boolean(tools.supports(id, app)));
|
|
51
|
+
const goalDelegates = (app) => new Map(goals().map((goal) => {
|
|
52
|
+
const metadata = goal.asIntent;
|
|
53
|
+
const explicit = typeof metadata === 'object' ? metadata.delegates : undefined;
|
|
54
|
+
return [
|
|
55
|
+
goal.id,
|
|
56
|
+
explicit
|
|
57
|
+
? [...explicit]
|
|
58
|
+
: [
|
|
59
|
+
...new Set([
|
|
60
|
+
...goal.delegates,
|
|
61
|
+
...[...tools.values()]
|
|
62
|
+
.filter((tool) => tool.lifecycle?.id &&
|
|
63
|
+
(app === undefined || (0, tool_conditions_js_1.toolActive)(tool.active, app)) &&
|
|
64
|
+
(tool.goalIds === 'all' || tool.goalIds.includes(goal.id)))
|
|
65
|
+
.map((tool) => tool.lifecycle.id),
|
|
66
|
+
]),
|
|
67
|
+
],
|
|
68
|
+
];
|
|
69
|
+
}));
|
|
70
|
+
const goalCatalog = (app) => {
|
|
71
|
+
const selected = goalIds(app), described = tools.describe('model', app), delegates = goalDelegates(app);
|
|
72
|
+
return goals(selected)
|
|
73
|
+
.filter((goal) => goalAvailable(goal, app))
|
|
74
|
+
.map((goal) => {
|
|
75
|
+
const { inputSchema: _schema, resolve: _resolve, active: _active, asIntent: _asIntent, ...metadata } = goal;
|
|
76
|
+
const demandDescription = typeof _asIntent === 'string'
|
|
77
|
+
? _asIntent
|
|
78
|
+
: typeof _asIntent === 'object' && _asIntent !== null
|
|
79
|
+
? _asIntent.description
|
|
80
|
+
: undefined;
|
|
81
|
+
return {
|
|
82
|
+
...metadata,
|
|
83
|
+
...(demandDescription ? { description: demandDescription } : {}),
|
|
84
|
+
delegates: delegates.get(goal.id) ?? [...goal.delegates],
|
|
85
|
+
scopeIds: scopes([goal.id]).map((scope) => scope.id),
|
|
86
|
+
toolIds: described
|
|
87
|
+
.filter((tool) => tool.goalIds.includes(goal.id))
|
|
88
|
+
.map((tool) => tool.id),
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const scopeCatalog = (app) => scopes(goalCatalog(app).map((goal) => goal.id)).map((scope) => ({
|
|
93
|
+
...scope,
|
|
94
|
+
toolIds: scope.toolIds.filter(tools.has),
|
|
95
|
+
}));
|
|
96
|
+
return Object.freeze({
|
|
97
|
+
goalIds,
|
|
98
|
+
goalDelegates,
|
|
99
|
+
goalCatalog,
|
|
100
|
+
scopeCatalog,
|
|
101
|
+
modelCatalog(app) {
|
|
102
|
+
const accepted = restrict ? task(app) : undefined, selected = goalIds(app).filter((id) => !accepted || id === accepted.goalId), available = goalCatalog(app).filter((intent) => selected.includes(intent.id));
|
|
103
|
+
return {
|
|
104
|
+
availableGoalIds: available.map((intent) => intent.id),
|
|
105
|
+
availableGoals: available.map((intent) => accepted ? { ...intent, scopeIds: accepted.scopeId ? [accepted.scopeId] : [] } : intent),
|
|
106
|
+
availableScopes: scopeCatalog(app).filter((scope) => !accepted || scope.id === accepted.scopeId),
|
|
107
|
+
availableTools: tools
|
|
108
|
+
.describe('model', app)
|
|
109
|
+
.filter((tool) => !accepted || tool.goalIds.includes(accepted.goalId)),
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/** Optional domain Tool constraints, scope registries and task-facing projections. */
|
|
18
|
+
__exportStar(require("./registry.js"), exports);
|
|
19
|
+
__exportStar(require("./scopes.js"), exports);
|
|
20
|
+
__exportStar(require("./catalog.js"), exports);
|
|
@@ -5,8 +5,9 @@ exports.createIntentRegistry = createIntentRegistry;
|
|
|
5
5
|
const synchronous_js_1 = require("../../utils/synchronous.js");
|
|
6
6
|
const rules_js_1 = require("../../utils/rules.js");
|
|
7
7
|
const registration_js_1 = require("../../utils/registration.js");
|
|
8
|
+
const model_js_1 = require("../../capabilities/model.js");
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
+
* Goal semantics and allowed values are configuration; the registry owns their common lifecycle.
|
|
10
11
|
*
|
|
11
12
|
* Registration order is preserved by `ids`, `definitions`, `values` and `entries`; once
|
|
12
13
|
* `seal()` is called the set is final and further registration is rejected.
|
|
@@ -16,6 +17,7 @@ class IntentRegistry {
|
|
|
16
17
|
static create = createIntentRegistry;
|
|
17
18
|
byId = new Map();
|
|
18
19
|
sealed = false;
|
|
20
|
+
modelView;
|
|
19
21
|
policy;
|
|
20
22
|
/**
|
|
21
23
|
* @param policy - Optional id pattern, vocabulary lists, error wording and assertion hook.
|
|
@@ -29,7 +31,7 @@ class IntentRegistry {
|
|
|
29
31
|
'targetModes',
|
|
30
32
|
'contextTiers',
|
|
31
33
|
'actions',
|
|
32
|
-
'
|
|
34
|
+
'delegates',
|
|
33
35
|
'handoffValues',
|
|
34
36
|
'tags',
|
|
35
37
|
];
|
|
@@ -51,16 +53,16 @@ class IntentRegistry {
|
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
54
|
-
* Validate, freeze and add one
|
|
56
|
+
* Validate, freeze and add one domain Tool.
|
|
55
57
|
*
|
|
56
58
|
* Checks run in a fixed order — sealed, identity, context contract, auxiliary actions,
|
|
57
|
-
* handoff, plan,
|
|
59
|
+
* handoff, plan, delegates — so the reported violation is stable when several rules fail.
|
|
58
60
|
*
|
|
59
|
-
* @param input -
|
|
61
|
+
* @param input - Goal declaration; the App's own assertion receives this original object,
|
|
60
62
|
* not the compiled copy, so helpers and prototype methods keep working.
|
|
61
63
|
* @returns This registry, for chaining.
|
|
62
64
|
* @throws A configured error for a sealed registry, invalid identity or vocabulary values,
|
|
63
|
-
* empty/duplicate
|
|
65
|
+
* empty/duplicate delegates, or a duplicate Tool id.
|
|
64
66
|
*/
|
|
65
67
|
register(input) {
|
|
66
68
|
const id = input.id;
|
|
@@ -68,7 +70,7 @@ class IntentRegistry {
|
|
|
68
70
|
...(0, registration_js_1.registrationData)(input, [
|
|
69
71
|
'id',
|
|
70
72
|
'description',
|
|
71
|
-
'
|
|
73
|
+
'delegates',
|
|
72
74
|
'scopePolicy',
|
|
73
75
|
'targetPolicy',
|
|
74
76
|
'contextTier',
|
|
@@ -78,7 +80,11 @@ class IntentRegistry {
|
|
|
78
80
|
]),
|
|
79
81
|
id,
|
|
80
82
|
description: input.description,
|
|
81
|
-
|
|
83
|
+
delegates: (typeof input.asIntent === 'object' && input.asIntent !== null
|
|
84
|
+
? input.asIntent.delegates
|
|
85
|
+
: undefined) ??
|
|
86
|
+
input.delegates ??
|
|
87
|
+
[],
|
|
82
88
|
scopePolicy: input.scopePolicy,
|
|
83
89
|
targetPolicy: input.targetPolicy,
|
|
84
90
|
contextTier: input.contextTier,
|
|
@@ -87,7 +93,7 @@ class IntentRegistry {
|
|
|
87
93
|
preparedHandoff: input.preparedHandoff,
|
|
88
94
|
};
|
|
89
95
|
const policy = this.policy;
|
|
90
|
-
const invalid = policy.errors?.invalid ?? 'Invalid intent definition';
|
|
96
|
+
const invalid = policy.errors?.invalid ?? 'Invalid intent Tool definition';
|
|
91
97
|
const tags = policy.tags ?? [];
|
|
92
98
|
const validName = (name) => {
|
|
93
99
|
if (typeof name !== 'string' || !name.trim())
|
|
@@ -145,75 +151,112 @@ class IntentRegistry {
|
|
|
145
151
|
},
|
|
146
152
|
{
|
|
147
153
|
occur: [
|
|
148
|
-
() =>
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
() => (input.delegates !== undefined ||
|
|
155
|
+
(typeof input.asIntent === 'object' &&
|
|
156
|
+
input.asIntent !== null &&
|
|
157
|
+
input.asIntent.delegates !== undefined)) &&
|
|
158
|
+
!definition.delegates.length,
|
|
159
|
+
() => definition.delegates.some((delegate) => policy.delegates !== undefined && !policy.delegates.includes(delegate)),
|
|
160
|
+
() => new Set(definition.delegates).size !== definition.delegates.length,
|
|
151
161
|
],
|
|
152
162
|
error: invalid,
|
|
153
|
-
tags: ['
|
|
163
|
+
tags: ['delegates'],
|
|
154
164
|
},
|
|
155
165
|
], tags);
|
|
156
166
|
// App assertions may use implementation helpers; never pass a compiled view as the source
|
|
157
167
|
// instance.
|
|
158
168
|
(0, synchronous_js_1.assertion)(policy.assertDefinition?.(input), 'Registry definition assertions must return void synchronously');
|
|
159
|
-
(0, rules_js_1.breakWhile)(this.byId.has(definition.id), () => policy.errors?.duplicate?.(definition.id) ??
|
|
160
|
-
new Error(`Duplicate intent: ${definition.id}`), [...tags, 'duplicate']);
|
|
169
|
+
(0, rules_js_1.breakWhile)(this.byId.has(definition.id), () => policy.errors?.duplicate?.(definition.id) ?? new Error(`Duplicate tool: ${definition.id}`), [...tags, 'duplicate']);
|
|
161
170
|
this.byId.set(definition.id, Object.freeze({
|
|
162
171
|
...definition,
|
|
163
|
-
|
|
172
|
+
...new model_js_1.ModelToolRegistry([
|
|
173
|
+
{
|
|
174
|
+
id: input.id,
|
|
175
|
+
description: input.description,
|
|
176
|
+
active: typeof input.active === 'function' ? input.active.bind(input) : input.active,
|
|
177
|
+
asIntent: typeof input.asIntent === 'function' ? input.asIntent.bind(input) : input.asIntent,
|
|
178
|
+
inputSchema: input.inputSchema ?? {
|
|
179
|
+
jsonSchema: { type: 'object' },
|
|
180
|
+
parse(value) {
|
|
181
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
182
|
+
throw new TypeError('Tool input must be an object');
|
|
183
|
+
return value;
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
resolve: input.resolve?.bind(input) ?? ((value) => ({ toolId: id, input: value })),
|
|
187
|
+
},
|
|
188
|
+
]).require(input.id),
|
|
189
|
+
delegates: Object.freeze([...definition.delegates]),
|
|
164
190
|
...(definition.auxiliaryActions
|
|
165
191
|
? { auxiliaryActions: Object.freeze([...definition.auxiliaryActions]) }
|
|
166
192
|
: {}),
|
|
167
193
|
}));
|
|
194
|
+
this.modelView = undefined;
|
|
168
195
|
return this;
|
|
169
196
|
}
|
|
170
|
-
/** Register every
|
|
197
|
+
/** Register every domain Tool in iteration order. */
|
|
171
198
|
registerAll(definitions) {
|
|
172
199
|
for (const definition of definitions)
|
|
173
200
|
this.register(definition);
|
|
174
201
|
return this;
|
|
175
202
|
}
|
|
176
|
-
/** Registered
|
|
203
|
+
/** Registered domain Tool for `id`, or `undefined` when it is absent. */
|
|
177
204
|
get(goal) {
|
|
178
205
|
return this.byId.get(goal);
|
|
179
206
|
}
|
|
180
|
-
/** Whether
|
|
207
|
+
/** Whether a Tool id is registered. */
|
|
181
208
|
has(goal) {
|
|
182
209
|
return this.byId.has(goal);
|
|
183
210
|
}
|
|
184
|
-
/** Registered
|
|
211
|
+
/** Registered Tool ids in registration order. */
|
|
185
212
|
ids() {
|
|
186
213
|
return Object.freeze([...this.byId.keys()]);
|
|
187
214
|
}
|
|
188
|
-
/** Registered
|
|
215
|
+
/** Registered goals in registration order. */
|
|
189
216
|
get definitions() {
|
|
190
217
|
return Object.freeze([...this.byId.values()]);
|
|
191
218
|
}
|
|
192
|
-
/** Iterate the registered
|
|
219
|
+
/** Iterate the registered goals. */
|
|
193
220
|
values() {
|
|
194
221
|
return this.byId.values();
|
|
195
222
|
}
|
|
196
|
-
/**
|
|
223
|
+
/** Demand discovery uses tool metadata; domain fields remain attached to these same IDs. */
|
|
224
|
+
withIntent(context) {
|
|
225
|
+
return this.models().withIntent(context);
|
|
226
|
+
}
|
|
227
|
+
/** Resolve a grouped transport's selected Tool through that Tool's own parser and resolver. */
|
|
228
|
+
resolve(selection, context) {
|
|
229
|
+
return this.models().resolve(selection, context);
|
|
230
|
+
}
|
|
231
|
+
/** Explicit node selection uses the same immutable model projection. */
|
|
232
|
+
select(ids, ...context) {
|
|
233
|
+
return context.length ? this.models().select(ids, context[0]) : this.models().select(ids);
|
|
234
|
+
}
|
|
235
|
+
/** Cache only immutable declarations; request activation is evaluated by each projection. */
|
|
236
|
+
models() {
|
|
237
|
+
return (this.modelView ??= new model_js_1.ModelToolRegistry(this.byId.values()).seal());
|
|
238
|
+
}
|
|
239
|
+
/** Iterate `[id, tool]` pairs. */
|
|
197
240
|
entries() {
|
|
198
241
|
return this.byId.entries();
|
|
199
242
|
}
|
|
200
243
|
/**
|
|
201
|
-
* Registered
|
|
244
|
+
* Registered domain Tool for `id`.
|
|
202
245
|
*
|
|
203
246
|
* @throws TypeError When the id is not registered.
|
|
204
247
|
*/
|
|
205
248
|
require(id) {
|
|
206
249
|
const value = this.byId.get(id);
|
|
207
250
|
if (!value)
|
|
208
|
-
throw new TypeError(`Unknown
|
|
251
|
+
throw new TypeError(`Unknown tool: ${id}`);
|
|
209
252
|
return value;
|
|
210
253
|
}
|
|
211
|
-
/** Whether the
|
|
212
|
-
allows(goal,
|
|
213
|
-
return this.byId.get(goal)?.
|
|
254
|
+
/** Whether the Tool declares this delegate; unknown goals allow nothing. */
|
|
255
|
+
allows(goal, delegate) {
|
|
256
|
+
return this.byId.get(goal)?.delegates.includes(delegate) ?? false;
|
|
214
257
|
}
|
|
215
258
|
/**
|
|
216
|
-
* Copy the selected
|
|
259
|
+
* Copy the selected goals out of the registry.
|
|
217
260
|
*
|
|
218
261
|
* @param goals - Ids to include; the default is every registered id, in registry order.
|
|
219
262
|
* @returns Descriptions whose arrays are copied so callers cannot mutate registry state.
|
|
@@ -222,7 +265,10 @@ class IntentRegistry {
|
|
|
222
265
|
const selected = new Set(goals);
|
|
223
266
|
return [...this.byId.values()]
|
|
224
267
|
.filter((item) => selected.has(item.id))
|
|
225
|
-
.map((item) => ({
|
|
268
|
+
.map((item) => ({
|
|
269
|
+
...item,
|
|
270
|
+
delegates: [...item.delegates],
|
|
271
|
+
}));
|
|
226
272
|
}
|
|
227
273
|
/** Finalize the registry; no registration is accepted afterwards. */
|
|
228
274
|
seal() {
|
|
@@ -234,7 +280,7 @@ exports.IntentRegistry = IntentRegistry;
|
|
|
234
280
|
/**
|
|
235
281
|
* Create and seal a complete catalog; use the constructor for incremental installation.
|
|
236
282
|
*
|
|
237
|
-
* @param definitions -
|
|
283
|
+
* @param definitions - Goal declarations registered in iteration order.
|
|
238
284
|
* @param policy - Optional registry policy forwarded to the constructor.
|
|
239
285
|
* @returns A sealed registry.
|
|
240
286
|
* @throws A configured error for the first invalid or duplicate declaration.
|