@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
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/** Read-side projection of captured workflow facts; never dispatches or reconstructs topology. */
|
|
2
|
+
import { normalizeDiagnosticEvent } from '../diagnostics/index.js';
|
|
3
|
+
import { freezeView } from './workflow-graph.js';
|
|
4
|
+
const lifecycleTypes = new Set(['enter', 'transition', 'complete', 'error']);
|
|
5
|
+
/** Aggregate main visits by span and keep raw subflow records in their own append order. */
|
|
6
|
+
export function projectWorkflowChain(workflowId, runId, input) {
|
|
7
|
+
const coverage = structuredClone(input.coverage);
|
|
8
|
+
const issues = [...coverage.issues];
|
|
9
|
+
const issue = (code, spanId, eventId) => issues.push({ code, spanId, eventId });
|
|
10
|
+
const events = input.events
|
|
11
|
+
.map(normalizeDiagnosticEvent)
|
|
12
|
+
.filter((e) => e.runId === runId)
|
|
13
|
+
.sort((a, b) => a.producerSequence - b.producerSequence);
|
|
14
|
+
const visits = new Map();
|
|
15
|
+
const ledgers = new Map();
|
|
16
|
+
const transitions = [];
|
|
17
|
+
const seen = new Map();
|
|
18
|
+
for (const raw of events) {
|
|
19
|
+
const payload = raw.payload && typeof raw.payload === 'object'
|
|
20
|
+
? raw.payload
|
|
21
|
+
: {};
|
|
22
|
+
const candidate = payload.event;
|
|
23
|
+
const fact = raw.type === 'workflow.event' && candidate && typeof candidate === 'object'
|
|
24
|
+
? candidate
|
|
25
|
+
: undefined;
|
|
26
|
+
const belongs = fact?.workflowId === workflowId ||
|
|
27
|
+
(raw.nodeRole === 'workflow-node' && raw.definitionId === workflowId);
|
|
28
|
+
if (!belongs || (raw.nodeRole !== undefined && raw.nodeRole !== 'workflow-node'))
|
|
29
|
+
continue;
|
|
30
|
+
if (raw.type === 'workflow.event' && !fact) {
|
|
31
|
+
issue('invalid-workflow-event', raw.spanId, raw.eventId);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const identity = JSON.stringify(raw);
|
|
35
|
+
if (seen.has(raw.eventId)) {
|
|
36
|
+
if (seen.get(raw.eventId) !== identity)
|
|
37
|
+
issue('conflicting-event', raw.spanId, raw.eventId);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
seen.set(raw.eventId, identity);
|
|
41
|
+
if (fact &&
|
|
42
|
+
(!lifecycleTypes.has(fact.type) ||
|
|
43
|
+
fact.eventId !== raw.eventId ||
|
|
44
|
+
fact.workflowId !== workflowId ||
|
|
45
|
+
(raw.workflowInvocationId !== undefined &&
|
|
46
|
+
fact.workflowInvocationId !== raw.workflowInvocationId) ||
|
|
47
|
+
[
|
|
48
|
+
'targetSpanId',
|
|
49
|
+
'targetNodeId',
|
|
50
|
+
'routeId',
|
|
51
|
+
'conditionId',
|
|
52
|
+
'errorCode',
|
|
53
|
+
'errorEventId',
|
|
54
|
+
].some((key) => {
|
|
55
|
+
const value = fact[key];
|
|
56
|
+
return value !== undefined && typeof value !== 'string';
|
|
57
|
+
}) ||
|
|
58
|
+
(fact.route !== undefined && (!Number.isSafeInteger(fact.route) || fact.route < 0)) ||
|
|
59
|
+
(fact.durationMs !== undefined &&
|
|
60
|
+
(!Number.isFinite(fact.durationMs) || fact.durationMs < 0)) ||
|
|
61
|
+
!Number.isSafeInteger(fact.roundIndex) ||
|
|
62
|
+
typeof fact.workflowInvocationId !== 'string' ||
|
|
63
|
+
fact.nodeId !== raw.nodeId ||
|
|
64
|
+
(fact.spanId !== undefined && fact.spanId !== raw.spanId) ||
|
|
65
|
+
(fact.runId !== undefined && fact.runId !== runId))) {
|
|
66
|
+
issue('invalid-workflow-event', raw.spanId, raw.eventId);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!raw.nodeId) {
|
|
70
|
+
issue('missing-node-id', raw.spanId, raw.eventId);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
let visit = visits.get(raw.spanId);
|
|
74
|
+
if (!visit) {
|
|
75
|
+
visit = {
|
|
76
|
+
spanId: raw.spanId,
|
|
77
|
+
nodeId: raw.nodeId,
|
|
78
|
+
workflowInvocationId: raw.workflowInvocationId ?? fact?.workflowInvocationId,
|
|
79
|
+
definitionRevision: raw.definitionRevision,
|
|
80
|
+
name: raw.nodeName,
|
|
81
|
+
description: raw.nodeDescription,
|
|
82
|
+
kind: raw.nodeKind,
|
|
83
|
+
roundIndex: fact?.roundIndex,
|
|
84
|
+
firstEventSequence: raw.producerSequence,
|
|
85
|
+
lastEventSequence: raw.producerSequence,
|
|
86
|
+
status: 'unknown',
|
|
87
|
+
events: [],
|
|
88
|
+
subflow: [],
|
|
89
|
+
};
|
|
90
|
+
visits.set(raw.spanId, visit);
|
|
91
|
+
ledgers.set(raw.spanId, new Map());
|
|
92
|
+
}
|
|
93
|
+
if (visit.nodeId !== raw.nodeId ||
|
|
94
|
+
visit.workflowInvocationId !== (raw.workflowInvocationId ?? fact?.workflowInvocationId)) {
|
|
95
|
+
issue('conflicting-span', raw.spanId, raw.eventId);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
visit.lastEventSequence = raw.producerSequence;
|
|
99
|
+
if (raw.usedModel !== undefined)
|
|
100
|
+
visit.usedModel = raw.usedModel;
|
|
101
|
+
if (raw.subStepsDropped || raw.subStepsTruncated)
|
|
102
|
+
issue('subflow-truncated', raw.spanId, raw.eventId);
|
|
103
|
+
const ledger = ledgers.get(raw.spanId);
|
|
104
|
+
for (const step of raw.subSteps ?? []) {
|
|
105
|
+
const previous = ledger.get(step.stepId);
|
|
106
|
+
if (!previous)
|
|
107
|
+
ledger.set(step.stepId, structuredClone(step));
|
|
108
|
+
else if (JSON.stringify({ ...previous, sourceEventId: undefined, producerSequence: undefined }) !==
|
|
109
|
+
JSON.stringify(step))
|
|
110
|
+
issue('conflicting-subflow', raw.spanId, raw.eventId);
|
|
111
|
+
}
|
|
112
|
+
const progress = payload.subStep;
|
|
113
|
+
if (raw.type === 'node.progress' && progress) {
|
|
114
|
+
const record = progress.stepId ? ledger.get(progress.stepId) : undefined;
|
|
115
|
+
if (record) {
|
|
116
|
+
ledger.set(record.stepId, {
|
|
117
|
+
...record,
|
|
118
|
+
sourceEventId: raw.eventId,
|
|
119
|
+
producerSequence: raw.producerSequence,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else if (typeof progress.stepId === 'string' && Number.isSafeInteger(progress.sequence)) {
|
|
123
|
+
ledger.set(progress.stepId, {
|
|
124
|
+
...structuredClone(progress),
|
|
125
|
+
origin: 'reported',
|
|
126
|
+
sourceEventId: raw.eventId,
|
|
127
|
+
producerSequence: raw.producerSequence,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else
|
|
131
|
+
issue('invalid-subflow-progress', raw.spanId, raw.eventId);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (fact || raw.type === 'node.progress') {
|
|
135
|
+
visit.events.push({
|
|
136
|
+
eventId: raw.eventId,
|
|
137
|
+
producerSequence: raw.producerSequence,
|
|
138
|
+
occurredAtMs: raw.occurredAtMs,
|
|
139
|
+
type: fact?.type ?? 'progress',
|
|
140
|
+
phase: fact?.phase,
|
|
141
|
+
routeId: fact?.routeId,
|
|
142
|
+
conditionId: fact?.conditionId,
|
|
143
|
+
errorCode: fact?.errorCode,
|
|
144
|
+
errorEventId: fact?.errorEventId,
|
|
145
|
+
payload: payload.payload,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (!fact)
|
|
149
|
+
continue;
|
|
150
|
+
visit.roundIndex ??= fact.roundIndex;
|
|
151
|
+
if (fact.type === 'enter') {
|
|
152
|
+
visit.enteredAtMs = raw.occurredAtMs;
|
|
153
|
+
visit.status = 'running';
|
|
154
|
+
}
|
|
155
|
+
if (fact.type === 'error')
|
|
156
|
+
visit.status =
|
|
157
|
+
fact.errorCode === 'CANCELLED' || fact.errorCode === 'TIMEOUT' ? 'cancelled' : 'error';
|
|
158
|
+
if (fact.type !== 'enter') {
|
|
159
|
+
visit.endedAtMs = raw.occurredAtMs;
|
|
160
|
+
visit.durationMs = fact.durationMs;
|
|
161
|
+
if (fact.type !== 'error' && visit.status !== 'error' && visit.status !== 'cancelled')
|
|
162
|
+
visit.status = 'success';
|
|
163
|
+
}
|
|
164
|
+
if (fact.type === 'transition' ||
|
|
165
|
+
fact.type === 'complete' ||
|
|
166
|
+
(fact.type === 'error' && fact.targetNodeId !== undefined))
|
|
167
|
+
transitions.push({
|
|
168
|
+
eventId: raw.eventId,
|
|
169
|
+
producerSequence: raw.producerSequence,
|
|
170
|
+
occurredAtMs: raw.occurredAtMs,
|
|
171
|
+
type: fact.type === 'complete' ? 'complete' : 'transition',
|
|
172
|
+
sourceSpanId: raw.spanId,
|
|
173
|
+
targetSpanId: fact.targetSpanId,
|
|
174
|
+
targetNodeId: fact.targetNodeId,
|
|
175
|
+
routeOrder: fact.route,
|
|
176
|
+
routeId: fact.routeId,
|
|
177
|
+
conditionId: fact.conditionId,
|
|
178
|
+
errorEventId: fact.type === 'error' ? raw.eventId : fact.errorEventId,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (!visits.size)
|
|
182
|
+
throw new RangeError(`No captured workflow visits: ${workflowId} / ${runId}`);
|
|
183
|
+
for (const visit of visits.values()) {
|
|
184
|
+
visit.subflow = [...ledgers.get(visit.spanId).values()].sort((a, b) => a.sequence - b.sequence);
|
|
185
|
+
if (visit.enteredAtMs === undefined)
|
|
186
|
+
issue('missing-enter', visit.spanId);
|
|
187
|
+
if (visit.endedAtMs === undefined && coverage.complete === true) {
|
|
188
|
+
visit.status = 'unknown';
|
|
189
|
+
issue('missing-exit', visit.spanId);
|
|
190
|
+
}
|
|
191
|
+
for (const step of visit.subflow)
|
|
192
|
+
if (step.operation === undefined ||
|
|
193
|
+
step.revision === undefined ||
|
|
194
|
+
step.createdAtMs === undefined)
|
|
195
|
+
issue('historical-subflow-fields', visit.spanId);
|
|
196
|
+
}
|
|
197
|
+
for (const edge of transitions)
|
|
198
|
+
if (edge.targetSpanId && !visits.has(edge.targetSpanId))
|
|
199
|
+
issue('missing-target-enter', edge.targetSpanId, edge.eventId);
|
|
200
|
+
return freezeView({
|
|
201
|
+
schemaVersion: 1,
|
|
202
|
+
workflowId,
|
|
203
|
+
runId,
|
|
204
|
+
nodes: [...visits.values()],
|
|
205
|
+
transitions,
|
|
206
|
+
coverage: { ...coverage, complete: issues.length ? false : coverage.complete, issues },
|
|
207
|
+
});
|
|
208
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Project the validated catalog to pure topology without evaluating route conditions. */
|
|
2
|
+
import type { WorkflowNode } from '../structs/execution/workflow.js';
|
|
3
|
+
import type { WorkflowGraph } from '../structs/execution/workflow-views.js';
|
|
4
|
+
/** Edge identity depends on topology, never on a route label or callback. */
|
|
5
|
+
export declare function projectWorkflowGraph<S, R, C>(workflowId: string, entryNodeId: string, revision: string | undefined, definitions: readonly WorkflowNode<S, R, C>[]): WorkflowGraph;
|
|
6
|
+
/** Freeze detached JSON data recursively so callers cannot alter another consumer's view. */
|
|
7
|
+
export declare function freezeView<T>(value: T): T;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Edge identity depends on topology, never on a route label or callback. */
|
|
2
|
+
export function projectWorkflowGraph(workflowId, entryNodeId, revision, definitions) {
|
|
3
|
+
const edges = new Map();
|
|
4
|
+
const nodes = definitions.map((node, order) => {
|
|
5
|
+
const edgeFor = (kind, targetNodeId) => {
|
|
6
|
+
const id = JSON.stringify([node.id, kind, targetNodeId ?? null]);
|
|
7
|
+
if (!edges.has(id))
|
|
8
|
+
edges.set(id, {
|
|
9
|
+
id,
|
|
10
|
+
kind,
|
|
11
|
+
sourceNodeId: node.id,
|
|
12
|
+
targetNodeId,
|
|
13
|
+
routeOrders: [],
|
|
14
|
+
...(kind === 'error' ? { errorRouteId: node.onErrorRouteId } : {}),
|
|
15
|
+
});
|
|
16
|
+
return edges.get(id);
|
|
17
|
+
};
|
|
18
|
+
const routes = node.routes.map((route, order) => {
|
|
19
|
+
const edge = edgeFor(route.complete ? 'complete' : 'transition', route.targetNodeId);
|
|
20
|
+
edge.routeOrders.push(order);
|
|
21
|
+
return {
|
|
22
|
+
order,
|
|
23
|
+
routeId: route.id,
|
|
24
|
+
description: route.description,
|
|
25
|
+
conditional: !!route.when,
|
|
26
|
+
conditionId: route.conditionId,
|
|
27
|
+
edgeId: edge.id,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
if (node.onErrorNodeId)
|
|
31
|
+
edgeFor('error', node.onErrorNodeId);
|
|
32
|
+
return {
|
|
33
|
+
id: node.id,
|
|
34
|
+
name: node.name ?? node.id,
|
|
35
|
+
description: node.description,
|
|
36
|
+
order,
|
|
37
|
+
startsRound: !!node.startsRound,
|
|
38
|
+
requires: [...(node.requires ?? [])],
|
|
39
|
+
provides: [...(node.provides ?? [])],
|
|
40
|
+
routes,
|
|
41
|
+
incomingEdgeIds: [],
|
|
42
|
+
outgoingEdgeIds: [],
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
46
|
+
for (const edge of edges.values()) {
|
|
47
|
+
byId.get(edge.sourceNodeId).outgoingEdgeIds.push(edge.id);
|
|
48
|
+
if (edge.targetNodeId)
|
|
49
|
+
byId.get(edge.targetNodeId).incomingEdgeIds.push(edge.id);
|
|
50
|
+
}
|
|
51
|
+
return freezeView({
|
|
52
|
+
schemaVersion: 1,
|
|
53
|
+
workflowId,
|
|
54
|
+
revision,
|
|
55
|
+
entryNodeId,
|
|
56
|
+
nodes,
|
|
57
|
+
edges: [...edges.values()],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** Freeze detached JSON data recursively so callers cannot alter another consumer's view. */
|
|
61
|
+
export function freezeView(value) {
|
|
62
|
+
if (value && typeof value === 'object') {
|
|
63
|
+
for (const child of Object.values(value))
|
|
64
|
+
freezeView(child);
|
|
65
|
+
Object.freeze(value);
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WorkflowGraph, WorkflowChain, WorkflowChainSource } from '../structs/execution/workflow-views.js';
|
|
1
2
|
import type { AgentWorkflowDefinition, WorkflowExtension, WorkflowNode } from '../structs/execution/workflow.js';
|
|
2
3
|
/**
|
|
3
4
|
* Executable catalog: validate references and bounded cycles before any handler runs.
|
|
@@ -14,6 +15,7 @@ export declare class AgentWorkflow<State, Result, Runtime = undefined> {
|
|
|
14
15
|
readonly revision?: string;
|
|
15
16
|
/** Optional result guard; when present it must return exactly true. */
|
|
16
17
|
readonly isResult?: (result: Result) => boolean;
|
|
18
|
+
private readonly chainSource?;
|
|
17
19
|
private readonly nodes;
|
|
18
20
|
/**
|
|
19
21
|
* Build and validate a workflow.
|
|
@@ -38,6 +40,10 @@ export declare class AgentWorkflow<State, Result, Runtime = undefined> {
|
|
|
38
40
|
* @throws TypeError When an override names an unknown node or a node is invalid.
|
|
39
41
|
*/
|
|
40
42
|
add(extension: WorkflowExtension<State, Result, Runtime> | AgentWorkflow<State, Result, Runtime>, routes?: WorkflowExtension<State, Result, Runtime>['routes']): AgentWorkflow<State, Result, Runtime>;
|
|
43
|
+
/** Export topology from the registered snapshot without executing callbacks. */
|
|
44
|
+
toGraph(): WorkflowGraph;
|
|
45
|
+
/** Read an authorized run through the bound App source, or an explicit per-call source. */
|
|
46
|
+
toChain(runId: string, source?: WorkflowChainSource | undefined): Promise<WorkflowChain>;
|
|
41
47
|
/**
|
|
42
48
|
* Look up a node that must exist.
|
|
43
49
|
*
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validated workflow catalog and round accounting.
|
|
3
|
+
*
|
|
4
|
+
* A workflow is declared as data (nodes plus routes) and validated before any handler
|
|
5
|
+
* runs: references must resolve, every node must be reachable from the entry, and every
|
|
6
|
+
* cycle must cross a round boundary so the engine's budget stays authoritative. This
|
|
7
|
+
* module owns the catalog; `engine.ts` owns traversal and execution.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `AgentWorkflow`, `defineWorkflow`, `AttemptBudget`, the re-exported
|
|
10
|
+
* `requireWorkflowValue` and `route`, and the workflow contract types.
|
|
11
|
+
*/
|
|
12
|
+
import { projectWorkflowGraph } from './workflow-graph.js';
|
|
13
|
+
import { projectWorkflowChain } from './workflow-chain.js';
|
|
1
14
|
/**
|
|
2
15
|
* Derive unique route ids for one node.
|
|
3
16
|
*
|
|
@@ -51,6 +64,7 @@ export class AgentWorkflow {
|
|
|
51
64
|
revision;
|
|
52
65
|
/** Optional result guard; when present it must return exactly true. */
|
|
53
66
|
isResult;
|
|
67
|
+
chainSource;
|
|
54
68
|
nodes = new Map();
|
|
55
69
|
/**
|
|
56
70
|
* Build and validate a workflow.
|
|
@@ -68,6 +82,7 @@ export class AgentWorkflow {
|
|
|
68
82
|
if (!definition.id?.trim() || !entry?.trim() || !definition.nodes.length) {
|
|
69
83
|
throw new TypeError('Invalid workflow');
|
|
70
84
|
}
|
|
85
|
+
this.chainSource = definition.chainSource?.bind(definition);
|
|
71
86
|
this.id = definition.id;
|
|
72
87
|
this.entryNodeId = entry;
|
|
73
88
|
this.revision = definition.revision;
|
|
@@ -104,6 +119,7 @@ export class AgentWorkflow {
|
|
|
104
119
|
return new AgentWorkflow({
|
|
105
120
|
id: this.id,
|
|
106
121
|
revision: patch.revision,
|
|
122
|
+
chainSource: this.chainSource,
|
|
107
123
|
entryNodeId: this.entryNodeId,
|
|
108
124
|
isResult: this.isResult,
|
|
109
125
|
nodes: nodes.map((node) => ({
|
|
@@ -121,6 +137,18 @@ export class AgentWorkflow {
|
|
|
121
137
|
})),
|
|
122
138
|
});
|
|
123
139
|
}
|
|
140
|
+
/** Export topology from the registered snapshot without executing callbacks. */
|
|
141
|
+
toGraph() {
|
|
142
|
+
return projectWorkflowGraph(this.id, this.entryNodeId, this.revision, this.definitions);
|
|
143
|
+
}
|
|
144
|
+
/** Read an authorized run through the bound App source, or an explicit per-call source. */
|
|
145
|
+
async toChain(runId, source = this.chainSource) {
|
|
146
|
+
if (!runId.trim())
|
|
147
|
+
throw new TypeError('A runId is required');
|
|
148
|
+
if (!source)
|
|
149
|
+
throw new TypeError('Workflow chainSource is not configured');
|
|
150
|
+
return projectWorkflowChain(this.id, runId, await source(runId));
|
|
151
|
+
}
|
|
124
152
|
/**
|
|
125
153
|
* Look up a node that must exist.
|
|
126
154
|
*
|
|
@@ -203,25 +231,26 @@ export class AgentWorkflow {
|
|
|
203
231
|
* @throws TypeError When the node, a route or a state contract is invalid.
|
|
204
232
|
*/
|
|
205
233
|
register(node) {
|
|
234
|
+
const declaredRoutes = node.routes;
|
|
206
235
|
if (!node.id?.trim() ||
|
|
207
236
|
!node.description?.trim() ||
|
|
208
237
|
this.nodes.has(node.id) ||
|
|
209
|
-
!
|
|
238
|
+
!declaredRoutes.length ||
|
|
210
239
|
(node.run !== undefined && typeof node.run !== 'function')) {
|
|
211
240
|
throw new TypeError('Invalid or duplicate workflow node');
|
|
212
241
|
}
|
|
213
242
|
validateNodeFields(node);
|
|
214
243
|
if (node.onErrorRouteId !== undefined && (!node.onErrorRouteId.trim() || !node.onErrorNodeId))
|
|
215
244
|
throw new TypeError(`Invalid workflow error route identity: ${node.id}`);
|
|
216
|
-
const ids = assignRouteIds(
|
|
217
|
-
for (const [index, route] of
|
|
245
|
+
const ids = assignRouteIds(declaredRoutes);
|
|
246
|
+
for (const [index, route] of declaredRoutes.entries()) {
|
|
218
247
|
if ('to' in route ||
|
|
219
248
|
(route.id !== undefined && !route.id.trim()) ||
|
|
220
249
|
(route.conditionId !== undefined && (!route.conditionId.trim() || !route.when)))
|
|
221
250
|
throw new TypeError(`Invalid workflow route identity: ${node.id}`);
|
|
222
251
|
const hasTarget = typeof route.targetNodeId === 'string';
|
|
223
252
|
const hasCompletion = typeof route.complete === 'function';
|
|
224
|
-
const shadowsFollowingRoutes = !route.when && index !==
|
|
253
|
+
const shadowsFollowingRoutes = !route.when && index !== declaredRoutes.length - 1;
|
|
225
254
|
if (hasTarget === hasCompletion ||
|
|
226
255
|
shadowsFollowingRoutes ||
|
|
227
256
|
(route.when !== undefined && typeof route.when !== 'function')) {
|
|
@@ -235,7 +264,7 @@ export class AgentWorkflow {
|
|
|
235
264
|
throw new TypeError(`Invalid workflow state contract: ${node.id}`);
|
|
236
265
|
}
|
|
237
266
|
}
|
|
238
|
-
const routes = Object.freeze(
|
|
267
|
+
const routes = Object.freeze(declaredRoutes.map((route, index) => {
|
|
239
268
|
const id = ids[index];
|
|
240
269
|
const conditionId = route.conditionId?.replace(/\{(nid|rid)\}/g, (_, key) => {
|
|
241
270
|
if (key === 'nid')
|
|
@@ -258,7 +287,6 @@ export class AgentWorkflow {
|
|
|
258
287
|
// only when it declares it explicitly.
|
|
259
288
|
const startsRound = node.startsRound ?? (node.id === this.entryNodeId ? true : undefined);
|
|
260
289
|
this.nodes.set(node.id, Object.freeze({
|
|
261
|
-
...node,
|
|
262
290
|
id: node.id,
|
|
263
291
|
description: node.description,
|
|
264
292
|
name: node.name,
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Aggregate public entry of `@jangts/agent-core`: Core runtime contracts, one `Support`
|
|
3
|
-
* namespace
|
|
3
|
+
* namespace, and the optional Kit declaration helpers.
|
|
4
4
|
*
|
|
5
|
-
* Layering. Core owns the runtime contracts Apps call (engine, model runner,
|
|
6
|
-
* context, diagnostics) and the handler contracts Core calls back into
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* and standalone modules, not additional Core guarantees. Shared utilities are re-exported
|
|
11
|
-
* because they are needed alongside these contracts, and they carry no Agent semantics.
|
|
5
|
+
* Layering. Core owns the runtime contracts Apps call (engine, model runner, tools,
|
|
6
|
+
* context, diagnostics) and the handler contracts Core calls back into. Support supplies
|
|
7
|
+
* recommended implementations of those contracts. Kits are optional App-side libraries;
|
|
8
|
+
* they are available from this root convenience surface and from `/kits` / `/kits/*`
|
|
9
|
+
* subpaths. Importing a Kit is a choice, never a requirement.
|
|
12
10
|
*
|
|
13
11
|
* Exports are grouped by responsibility, not by dependency order. Deep subpath entries
|
|
14
12
|
* (`/engine`, `/model`, `/tools`, `/context`, `/journal`, `/diagnostics`, `/kits/...`)
|
|
15
|
-
* resolve to the same implementations
|
|
13
|
+
* resolve to the same implementations.
|
|
16
14
|
*/
|
|
17
15
|
export * from './execution/engine.js';
|
|
18
16
|
export { getErrorInfo } from './errors.js';
|
|
@@ -23,13 +21,21 @@ export * from './model/index.js';
|
|
|
23
21
|
export * from './capabilities/index.js';
|
|
24
22
|
export * from './context/fragments.js';
|
|
25
23
|
export * from './context/journal.js';
|
|
26
|
-
export
|
|
24
|
+
export * from './context/assembly.js';
|
|
27
25
|
export * from './support/context/assembly.js';
|
|
28
26
|
export { defineEvidenceChecklist, defineEvidenceProjection } from './kits/evidence.js';
|
|
29
27
|
export type { EvidenceRequirement, EvidenceProvider, EvidenceProjectionDefinition, EvidenceProjectionProvider, } from './structs/kits/evidence.js';
|
|
28
|
+
export { defineCommand, commandSchema } from './kits/interaction/command.js';
|
|
29
|
+
export type { Command, CommandDefinition, ProtocolCheck, ProtocolField, ProtocolReason, ProtocolPredicate, ProtocolShape, RegisteredProtocol, } from './structs/kits/interaction.js';
|
|
30
|
+
export * from './kits/interaction/commands.js';
|
|
31
|
+
export * from './kits/interaction/transfer.js';
|
|
32
|
+
export * from './kits/interaction/handlers.js';
|
|
30
33
|
export * from './kits/presentation/events.js';
|
|
31
34
|
export * from './support/transport/index.js';
|
|
32
35
|
export * from './support/model/chat-completions.js';
|
|
36
|
+
export * from './support/model/compatible-provider.js';
|
|
37
|
+
export * from './support/model/transports.js';
|
|
38
|
+
export * from './support/model/interactions/index.js';
|
|
33
39
|
export * from './utils/index.js';
|
|
34
40
|
export * from './kits/presentation/templates.js';
|
|
35
41
|
export { defineRetrieval } from './kits/retrieval.js';
|
|
@@ -37,11 +43,11 @@ export type * from './structs/kits/retrieval.js';
|
|
|
37
43
|
export { defineTextSkillLoader } from './kits/text-skills.js';
|
|
38
44
|
export type * from './structs/kits/text-skills.js';
|
|
39
45
|
export * from './diagnostics/index.js';
|
|
40
|
-
export * from './kits/
|
|
41
|
-
export * from './kits/
|
|
46
|
+
export * from './kits/domains/registry.js';
|
|
47
|
+
export * from './kits/domains/scopes.js';
|
|
42
48
|
export { ToolLifecycleRegistry } from './kits/tools.js';
|
|
43
49
|
export type * from './structs/kits/tools.js';
|
|
44
|
-
export * from './kits/
|
|
50
|
+
export * from './kits/domains/catalog.js';
|
|
45
51
|
export * from './support/registration.js';
|
|
46
52
|
export { defineCandidateSelection } from './kits/candidates.js';
|
|
47
53
|
export type * from './structs/kits/candidates.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Aggregate public entry of `@jangts/agent-core`: Core runtime contracts, one `Support`
|
|
3
|
-
* namespace
|
|
3
|
+
* namespace, and the optional Kit declaration helpers.
|
|
4
4
|
*
|
|
5
|
-
* Layering. Core owns the runtime contracts Apps call (engine, model runner,
|
|
6
|
-
* context, diagnostics) and the handler contracts Core calls back into
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* and standalone modules, not additional Core guarantees. Shared utilities are re-exported
|
|
11
|
-
* because they are needed alongside these contracts, and they carry no Agent semantics.
|
|
5
|
+
* Layering. Core owns the runtime contracts Apps call (engine, model runner, tools,
|
|
6
|
+
* context, diagnostics) and the handler contracts Core calls back into. Support supplies
|
|
7
|
+
* recommended implementations of those contracts. Kits are optional App-side libraries;
|
|
8
|
+
* they are available from this root convenience surface and from `/kits` / `/kits/*`
|
|
9
|
+
* subpaths. Importing a Kit is a choice, never a requirement.
|
|
12
10
|
*
|
|
13
11
|
* Exports are grouped by responsibility, not by dependency order. Deep subpath entries
|
|
14
12
|
* (`/engine`, `/model`, `/tools`, `/context`, `/journal`, `/diagnostics`, `/kits/...`)
|
|
15
|
-
* resolve to the same implementations
|
|
13
|
+
* resolve to the same implementations.
|
|
16
14
|
*/
|
|
17
15
|
export * from './execution/engine.js';
|
|
18
16
|
export { getErrorInfo } from './errors.js';
|
|
@@ -22,23 +20,28 @@ export * from './model/index.js';
|
|
|
22
20
|
export * from './capabilities/index.js';
|
|
23
21
|
export * from './context/fragments.js';
|
|
24
22
|
export * from './context/journal.js';
|
|
25
|
-
|
|
26
|
-
// root surface publishes separately below.
|
|
27
|
-
export { assembleFragments } from './context/assembly.js';
|
|
23
|
+
export * from './context/assembly.js';
|
|
28
24
|
export * from './support/context/assembly.js';
|
|
29
25
|
export { defineEvidenceChecklist, defineEvidenceProjection } from './kits/evidence.js';
|
|
26
|
+
export { defineCommand, commandSchema } from './kits/interaction/command.js';
|
|
27
|
+
export * from './kits/interaction/commands.js';
|
|
28
|
+
export * from './kits/interaction/transfer.js';
|
|
29
|
+
export * from './kits/interaction/handlers.js';
|
|
30
30
|
export * from './kits/presentation/events.js';
|
|
31
31
|
export * from './support/transport/index.js';
|
|
32
32
|
export * from './support/model/chat-completions.js';
|
|
33
|
+
export * from './support/model/compatible-provider.js';
|
|
34
|
+
export * from './support/model/transports.js';
|
|
35
|
+
export * from './support/model/interactions/index.js';
|
|
33
36
|
export * from './utils/index.js';
|
|
34
37
|
export * from './kits/presentation/templates.js';
|
|
35
38
|
export { defineRetrieval } from './kits/retrieval.js';
|
|
36
39
|
export { defineTextSkillLoader } from './kits/text-skills.js';
|
|
37
40
|
export * from './diagnostics/index.js';
|
|
38
|
-
export * from './kits/
|
|
39
|
-
export * from './kits/
|
|
41
|
+
export * from './kits/domains/registry.js';
|
|
42
|
+
export * from './kits/domains/scopes.js';
|
|
40
43
|
export { ToolLifecycleRegistry } from './kits/tools.js';
|
|
41
|
-
export * from './kits/
|
|
44
|
+
export * from './kits/domains/catalog.js';
|
|
42
45
|
export * from './support/registration.js';
|
|
43
46
|
export { defineCandidateSelection } from './kits/candidates.js';
|
|
44
47
|
/** App-facing helpers and their types are consumed through the root Support namespace. */
|
|
@@ -34,7 +34,7 @@ export declare function defineQueryAggregation<Input, Item, Context>(options: Qu
|
|
|
34
34
|
* @param context - Host context forwarded unchanged to `execute`, `key` and `merge`.
|
|
35
35
|
* @returns The merged items and their count.
|
|
36
36
|
*/
|
|
37
|
-
collect(inputs: readonly Input[], context: Context): {
|
|
37
|
+
collect(inputs: readonly Input[], context: Context, execution?: Partial<import("../structs/common.js").ExecutionContext>): {
|
|
38
38
|
total: number;
|
|
39
39
|
items: Item[];
|
|
40
40
|
};
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Exports: `mergeByKey`, `defineQueryAggregation`, `Aggregation`.
|
|
8
8
|
*/
|
|
9
|
+
import { nativeSubFlowSync } from '../diagnostics/native-sub-flow.js';
|
|
9
10
|
import { synchronous } from '../utils/synchronous.js';
|
|
10
11
|
/**
|
|
11
12
|
* Merge duplicates without moving their first position; selection policy remains host-owned.
|
|
@@ -51,21 +52,23 @@ export function defineQueryAggregation(options) {
|
|
|
51
52
|
* @param context - Host context forwarded unchanged to `execute`, `key` and `merge`.
|
|
52
53
|
* @returns The merged items and their count.
|
|
53
54
|
*/
|
|
54
|
-
collect(inputs, context) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
for (const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
collect(inputs, context, execution = {}) {
|
|
56
|
+
return nativeSubFlowSync(execution, 'aggregation', 'query-aggregation', () => {
|
|
57
|
+
const rows = [], merged = new Map();
|
|
58
|
+
for (const input of inputs)
|
|
59
|
+
for (const item of synchronous(execute(input, context), 'Query aggregation must be synchronous')) {
|
|
60
|
+
if (!keyFor) {
|
|
61
|
+
rows.push(item);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const key = synchronous(keyFor(item, input, context), 'Aggregation keys must be synchronous');
|
|
65
|
+
merged.set(key, merge
|
|
66
|
+
? synchronous(merge(item, merged.get(key), input, context), 'Aggregation merge must be synchronous')
|
|
67
|
+
: item);
|
|
61
68
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
: item);
|
|
66
|
-
}
|
|
67
|
-
const items = keyFor ? [...merged.values()] : rows;
|
|
68
|
-
return { total: items.length, items };
|
|
69
|
+
const items = keyFor ? [...merged.values()] : rows;
|
|
70
|
+
return { total: items.length, items };
|
|
71
|
+
});
|
|
69
72
|
},
|
|
70
73
|
});
|
|
71
74
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Exports: `defineAnswerCheckCatalog`, and the answer checker types.
|
|
8
8
|
*/
|
|
9
|
+
import { nativeSubFlowSync } from '../../diagnostics/native-sub-flow.js';
|
|
9
10
|
import { snapshotAnswerCheck } from './check-result.js';
|
|
10
11
|
import { readonlyCatalog } from '../../utils/catalog.js';
|
|
11
12
|
import { synchronous } from '../../utils/synchronous.js';
|
|
@@ -37,7 +38,7 @@ export function defineAnswerCheckCatalog(definitions) {
|
|
|
37
38
|
throw new TypeError('Duplicate selected check id');
|
|
38
39
|
for (const id of request.checkIds) {
|
|
39
40
|
context.signal.throwIfAborted();
|
|
40
|
-
const result = snapshotAnswerCheck(synchronous(checks.require(id).check(value, context), 'Answer checkers must be synchronous'), id);
|
|
41
|
+
const result = nativeSubFlowSync(context, 'check', id, () => snapshotAnswerCheck(synchronous(checks.require(id).check(value, context), 'Answer checkers must be synchronous'), id));
|
|
41
42
|
context.signal.throwIfAborted();
|
|
42
43
|
if (Object.hasOwn(result, 'value'))
|
|
43
44
|
value = result.value;
|