@jangts/agent-core 0.1.0 → 0.2.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 +18 -0
- package/README.md +59 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -0
- package/development/docs/assets/agent-core-icon.png +0 -0
- package/development/docs/assets/agent-core-logo.png +0 -0
- package/development/docs/assets/character-agent-core.png +0 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +11 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +32 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +102 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.js +11 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +38 -0
- package/dist/esm/structs/kits/search.d.ts +22 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +30 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +52 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +49 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +145 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +32 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +10 -0
- package/dist/esm/support/model/completion/default.js +29 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +11 -0
- package/dist/esm/support/model/completion/session.js +99 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +20 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +15 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +24 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +23 -3
|
@@ -15,6 +15,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.AgentCoreEngine = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Bounded execution: the generic agent run loop and workflow driver.
|
|
20
|
+
*
|
|
21
|
+
* Two execution shapes share the round budget, cancellation and one diagnostic scope. A
|
|
22
|
+
* `CoreStep` loop owns its own round counter and returns an explicit continue/complete
|
|
23
|
+
* outcome; a bound workflow is traversed node by node, with routes selected after each
|
|
24
|
+
* commit. Business rules, tools and models are injected by the host — this module only
|
|
25
|
+
* enforces ordering, cancellation, budgets and reporting.
|
|
26
|
+
*
|
|
27
|
+
* Exports: `AgentCoreEngine` and the engine option/identity types.
|
|
28
|
+
*/
|
|
18
29
|
const call_budget_js_1 = require("../model/call-budget.js");
|
|
19
30
|
const runner_js_1 = require("../model/runner.js");
|
|
20
31
|
const binding_js_1 = require("../model/binding.js");
|
|
@@ -30,10 +41,20 @@ const rules_js_1 = require("../utils/rules.js");
|
|
|
30
41
|
const reporting_js_1 = require("./reporting.js");
|
|
31
42
|
const branch_js_1 = require("./branch.js");
|
|
32
43
|
__exportStar(require("./workflow.js"), exports);
|
|
33
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Bounded execution shared by applications; business rules are registered by each host.
|
|
46
|
+
*
|
|
47
|
+
* Configuration is bound before a run and may be bound only once per model, tool runtime
|
|
48
|
+
* and workflow. A run resolves its signal from the engine, the request runtime and the
|
|
49
|
+
* caller, then executes either the bound workflow or a supplied step function until the
|
|
50
|
+
* round budget, cancellation or a completion stops it.
|
|
51
|
+
*/
|
|
34
52
|
class AgentCoreEngine {
|
|
53
|
+
/** Workflow catalog constructor, exposed so hosts do not import two modules. */
|
|
35
54
|
static Workflow = workflow_js_1.AgentWorkflow;
|
|
55
|
+
/** Attempt budget, exposed for hosts that gate their own sub-steps. */
|
|
36
56
|
static AttemptBudget = workflow_js_1.AttemptBudget;
|
|
57
|
+
/** Factory for a validated workflow definition. */
|
|
37
58
|
static createWorkflow = workflow_js_1.defineWorkflow;
|
|
38
59
|
maxRounds;
|
|
39
60
|
exhausted;
|
|
@@ -44,26 +65,70 @@ class AgentCoreEngine {
|
|
|
44
65
|
models;
|
|
45
66
|
selectedModelId;
|
|
46
67
|
maxModelCalls;
|
|
68
|
+
/**
|
|
69
|
+
* Compile model options and reject engine-owned settings.
|
|
70
|
+
*
|
|
71
|
+
* @param options - Model binding supplied to the engine.
|
|
72
|
+
* @returns The compiled binding.
|
|
73
|
+
* @throws TypeError When the binding carries its own execution scope.
|
|
74
|
+
*/
|
|
47
75
|
snapshotModel(options) {
|
|
48
76
|
if (options.execution || options.signal)
|
|
49
77
|
throw new TypeError('Configure model execution on the Engine');
|
|
50
78
|
return (0, binding_js_1.snapshotModelBinding)(options);
|
|
51
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Bind the single model this engine will use.
|
|
82
|
+
*
|
|
83
|
+
* @param options - App model settings.
|
|
84
|
+
* @returns This engine, for chaining.
|
|
85
|
+
* @throws TypeError When a model is already bound or the settings are invalid.
|
|
86
|
+
*/
|
|
52
87
|
bindModel(options) {
|
|
53
88
|
if (this.modelOptions || this.models || this.modelRuntime)
|
|
54
89
|
throw new TypeError('Engine already has a bound model');
|
|
55
90
|
return this.setModel(options);
|
|
56
91
|
}
|
|
57
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Bind an existing request lifetime once, for App services sharing this Runner's budget.
|
|
94
|
+
*
|
|
95
|
+
* Callbacks are bound to the source runtime and the counters stay live getters, so the
|
|
96
|
+
* engine and the App observe exactly the same budget and signal.
|
|
97
|
+
*
|
|
98
|
+
* @param source - Request model runtime owned by the App.
|
|
99
|
+
* @returns This engine, for chaining.
|
|
100
|
+
* @throws Error When another model is already bound or the runtime lacks a usable signal.
|
|
101
|
+
*/
|
|
58
102
|
bindModelRuntime(source) {
|
|
59
103
|
(0, rules_js_1.breakWhile)(!!this.modelOptions || !!this.models || !!this.modelRuntime, 'Engine already has a bound model');
|
|
60
104
|
const execution = source.execution, invoke = source.invoke, prepare = source.prepare;
|
|
61
|
-
(0, rules_js_1.breakWhile)(typeof invoke !== 'function' ||
|
|
62
|
-
|
|
105
|
+
(0, rules_js_1.breakWhile)(typeof invoke !== 'function' ||
|
|
106
|
+
typeof prepare !== 'function' ||
|
|
107
|
+
typeof execution?.signal?.throwIfAborted !== 'function', 'Invalid request model runtime');
|
|
108
|
+
this.modelRuntime = Object.freeze({
|
|
109
|
+
invoke: invoke.bind(source),
|
|
110
|
+
prepare: prepare.bind(source),
|
|
63
111
|
execution: Object.freeze({ signal: execution.signal, diagnostics: execution.diagnostics }),
|
|
64
|
-
get remainingCalls() {
|
|
112
|
+
get remainingCalls() {
|
|
113
|
+
return source.remainingCalls;
|
|
114
|
+
},
|
|
115
|
+
get callCount() {
|
|
116
|
+
return source.callCount;
|
|
117
|
+
},
|
|
118
|
+
get totalCallCount() {
|
|
119
|
+
return source.totalCallCount;
|
|
120
|
+
},
|
|
121
|
+
});
|
|
65
122
|
return this;
|
|
66
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Select a configured model, or replace the single bound model's configuration.
|
|
126
|
+
*
|
|
127
|
+
* @param options - A configured model id, or new settings for the single bound model.
|
|
128
|
+
* @returns This engine, for chaining.
|
|
129
|
+
* @throws WorkflowContractError When the id is not configured.
|
|
130
|
+
* @throws TypeError When no single model is bound to switch.
|
|
131
|
+
*/
|
|
67
132
|
switchModel(options) {
|
|
68
133
|
if (typeof options === 'string') {
|
|
69
134
|
this.requireModel(options, this.models);
|
|
@@ -74,17 +139,38 @@ class AgentCoreEngine {
|
|
|
74
139
|
throw new TypeError('Bind a single model before switching its configuration');
|
|
75
140
|
return this.setModel(options);
|
|
76
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Look up a configured model by id.
|
|
144
|
+
*
|
|
145
|
+
* @param id - Configured model id.
|
|
146
|
+
* @param models - Configured model map, when the engine uses a catalog.
|
|
147
|
+
* @returns The compiled binding.
|
|
148
|
+
* @throws WorkflowContractError When the id is not configured.
|
|
149
|
+
*/
|
|
77
150
|
requireModel(id, models) {
|
|
78
151
|
const options = models?.get(id);
|
|
79
152
|
if (!options)
|
|
80
153
|
throw new errors_js_2.WorkflowContractError(`Unknown configured model: ${id}`);
|
|
81
154
|
return options;
|
|
82
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Compile and store the single bound model.
|
|
158
|
+
*
|
|
159
|
+
* @param options - App model settings.
|
|
160
|
+
* @returns This engine, for chaining.
|
|
161
|
+
*/
|
|
83
162
|
setModel(options) {
|
|
84
163
|
this.modelOptions = this.snapshotModel(options);
|
|
85
164
|
return this;
|
|
86
165
|
}
|
|
87
166
|
invokeTool;
|
|
167
|
+
/**
|
|
168
|
+
* Bind the tool runtime used by workflow context.
|
|
169
|
+
*
|
|
170
|
+
* @param tools - Registry exposing `invokeAsync`, or an object exposing `invoke`.
|
|
171
|
+
* @returns This engine, for chaining.
|
|
172
|
+
* @throws TypeError When tools are already bound or expose no invoke method.
|
|
173
|
+
*/
|
|
88
174
|
bindToolRuntime(tools) {
|
|
89
175
|
if (this.invokeTool)
|
|
90
176
|
throw new TypeError('Engine already has a bound tool runtime');
|
|
@@ -102,41 +188,109 @@ class AgentCoreEngine {
|
|
|
102
188
|
engine.bind(workflow, app);
|
|
103
189
|
return engine;
|
|
104
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Store the workflow and its dependencies.
|
|
193
|
+
*
|
|
194
|
+
* @param workflow - Workflow to execute.
|
|
195
|
+
* @param app - App dependencies handed to every node and route.
|
|
196
|
+
* @throws TypeError When a workflow is already bound.
|
|
197
|
+
*/
|
|
105
198
|
bind(workflow, app) {
|
|
106
199
|
if (this.boundWorkflow)
|
|
107
200
|
throw new TypeError('Engine already has a bound workflow');
|
|
108
201
|
this.boundWorkflow = { workflow, app };
|
|
109
202
|
}
|
|
203
|
+
/** The bound workflow. */
|
|
110
204
|
get workflow() {
|
|
111
205
|
if (!this.boundWorkflow)
|
|
112
206
|
throw new TypeError('Engine has no bound workflow');
|
|
113
207
|
return this.boundWorkflow.workflow;
|
|
114
208
|
}
|
|
209
|
+
// A default identity is generated eagerly so checkpoints taken before a run still carry
|
|
210
|
+
// a stable branch, and a forked engine can point at the parent's ids.
|
|
115
211
|
branchIdentity = Object.freeze({
|
|
116
|
-
agentId: (0, invocation_js_1.invocationId)(),
|
|
212
|
+
agentId: (0, invocation_js_1.invocationId)(),
|
|
213
|
+
branchId: (0, invocation_js_1.invocationId)(),
|
|
214
|
+
agentVersionId: (0, invocation_js_1.invocationId)(),
|
|
117
215
|
});
|
|
216
|
+
// Membership test for checkpoints: a checkpoint object from another engine (or a
|
|
217
|
+
// hand-built lookalike) must not be accepted as if it proved branch ownership.
|
|
118
218
|
checkpoints = new WeakSet();
|
|
119
|
-
|
|
219
|
+
/** Identity of this engine's branch. */
|
|
220
|
+
get branch() {
|
|
221
|
+
return this.branchIdentity;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Take an in-memory checkpoint of host-owned data.
|
|
225
|
+
*
|
|
226
|
+
* The data is cloned on write and on every read, so neither side can mutate the other.
|
|
227
|
+
*
|
|
228
|
+
* @param data - Serializable data to capture.
|
|
229
|
+
* @returns A checkpoint bound to this branch.
|
|
230
|
+
*/
|
|
120
231
|
checkpoint(data) {
|
|
121
232
|
const snapshot = structuredClone(data);
|
|
122
|
-
const checkpoint = Object.freeze({
|
|
233
|
+
const checkpoint = Object.freeze({
|
|
234
|
+
id: (0, invocation_js_1.invocationId)(),
|
|
235
|
+
source: this.branch,
|
|
236
|
+
read: () => structuredClone(snapshot),
|
|
237
|
+
});
|
|
123
238
|
this.checkpoints.add(checkpoint);
|
|
124
239
|
return checkpoint;
|
|
125
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Export a checkpoint for host-owned persistence.
|
|
243
|
+
*
|
|
244
|
+
* @param checkpoint - Checkpoint taken by this engine.
|
|
245
|
+
* @returns A serializable record with a validated branch identity.
|
|
246
|
+
* @throws Error When the checkpoint belongs to another engine.
|
|
247
|
+
*/
|
|
126
248
|
exportCheckpoint(checkpoint) {
|
|
127
249
|
(0, rules_js_1.breakWhile)(!this.checkpoints.has(checkpoint), 'Checkpoint belongs to another branch');
|
|
128
|
-
return {
|
|
250
|
+
return {
|
|
251
|
+
id: checkpoint.id,
|
|
252
|
+
source: (0, branch_js_1.snapshotBranch)(checkpoint.source),
|
|
253
|
+
data: checkpoint.read(),
|
|
254
|
+
};
|
|
129
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Recreate a checkpoint from a persisted record.
|
|
258
|
+
*
|
|
259
|
+
* The record's branch must match this engine's branch exactly; otherwise persisted data
|
|
260
|
+
* from another branch would be adopted silently.
|
|
261
|
+
*
|
|
262
|
+
* @param record - Record produced by `exportCheckpoint`.
|
|
263
|
+
* @returns A checkpoint bound to this engine.
|
|
264
|
+
* @throws Error When the id is invalid or the branch identity differs.
|
|
265
|
+
*/
|
|
130
266
|
restoreCheckpoint(record) {
|
|
131
267
|
const source = (0, branch_js_1.snapshotBranch)(record.source);
|
|
132
|
-
(0, rules_js_1.breakWhile)(typeof record.id !== 'string' ||
|
|
133
|
-
|
|
268
|
+
(0, rules_js_1.breakWhile)(typeof record.id !== 'string' ||
|
|
269
|
+
!record.id.trim() ||
|
|
270
|
+
record.id.length > 200 ||
|
|
271
|
+
JSON.stringify(source) !== JSON.stringify((0, branch_js_1.snapshotBranch)(this.branch)), 'Checkpoint identity does not match the restored branch');
|
|
134
272
|
const data = structuredClone(record.data);
|
|
135
273
|
const checkpoint = Object.freeze({ id: record.id, source, read: () => structuredClone(data) });
|
|
136
274
|
this.checkpoints.add(checkpoint);
|
|
137
275
|
return checkpoint;
|
|
138
276
|
}
|
|
139
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Create an engine on a new branch forked at a checkpoint.
|
|
279
|
+
*
|
|
280
|
+
* The forked engine keeps the round budget, observation and configuration, receives an
|
|
281
|
+
* optional workflow extension, and gets a new branch identity whose parent ids point at
|
|
282
|
+
* this engine. Live handles are not copied: an App dependency, request runtime or tool
|
|
283
|
+
* runtime must be restored by the `resume` callback, because they cannot be serialized.
|
|
284
|
+
*
|
|
285
|
+
* @param request.at - Checkpoint taken by this engine to fork from.
|
|
286
|
+
* @param request.workflow - Optional extension or replacement workflow.
|
|
287
|
+
* @param request.routes - Route overrides; only valid with a workflow instance.
|
|
288
|
+
* @param request.resume - Receives the checkpoint data and returns restored dependencies.
|
|
289
|
+
* @returns A new engine on the forked branch.
|
|
290
|
+
* @throws TypeError When the checkpoint is foreign or the App dependency is missing.
|
|
291
|
+
* @throws Error When a bound request runtime or tool runtime was not restored.
|
|
292
|
+
*/
|
|
293
|
+
fork({ at, workflow, routes, resume, }) {
|
|
140
294
|
if (!this.boundWorkflow)
|
|
141
295
|
throw new TypeError('Engine has no bound workflow');
|
|
142
296
|
if (!this.checkpoints.has(at))
|
|
@@ -151,8 +305,12 @@ class AgentCoreEngine {
|
|
|
151
305
|
(0, rules_js_1.breakWhile)(!!this.modelRuntime && !dependencies?.model, 'Fork requires a restored request model runtime');
|
|
152
306
|
(0, rules_js_1.breakWhile)(!!this.invokeTool && !dependencies?.tools, 'Fork requires a restored tool runtime');
|
|
153
307
|
const engine = new AgentCoreEngine({
|
|
154
|
-
maxRounds: this.maxRounds,
|
|
155
|
-
|
|
308
|
+
maxRounds: this.maxRounds,
|
|
309
|
+
errors: { exhausted: this.exhausted },
|
|
310
|
+
execution: {
|
|
311
|
+
diagnostics: this.options.execution?.diagnostics,
|
|
312
|
+
observe: this.options.execution?.observe,
|
|
313
|
+
},
|
|
156
314
|
});
|
|
157
315
|
engine.bind(definition, dependencies?.app);
|
|
158
316
|
if (dependencies?.tools)
|
|
@@ -166,13 +324,30 @@ class AgentCoreEngine {
|
|
|
166
324
|
engine.maxModelCalls = this.maxModelCalls;
|
|
167
325
|
}
|
|
168
326
|
engine.branchIdentity = Object.freeze({
|
|
169
|
-
agentId: this.branch.agentId,
|
|
170
|
-
|
|
327
|
+
agentId: this.branch.agentId,
|
|
328
|
+
branchId: engine.branch.branchId,
|
|
329
|
+
agentVersionId: engine.branch.agentVersionId,
|
|
330
|
+
parentBranchId: this.branch.branchId,
|
|
331
|
+
parentAgentVersionId: this.branch.agentVersionId,
|
|
332
|
+
forkPointId: at.id,
|
|
171
333
|
});
|
|
172
334
|
return engine;
|
|
173
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Build an engine and validate its wiring.
|
|
338
|
+
*
|
|
339
|
+
* Legacy top-level names (`maxSteps`, `exhausted`, `signal`, `diagnostics`,
|
|
340
|
+
* `onWorkflowEvent`, `observe`) are rejected rather than ignored, because silently
|
|
341
|
+
* dropping them would change budgets or observation.
|
|
342
|
+
*
|
|
343
|
+
* @param settings - Round budget, errors, execution scope, model, tools, workflow and branch.
|
|
344
|
+
* @throws TypeError When settings are invalid, removed names are used, or model wiring is
|
|
345
|
+
* inconsistent.
|
|
346
|
+
*/
|
|
174
347
|
constructor(settings = {}) {
|
|
175
|
-
if (!settings ||
|
|
348
|
+
if (!settings ||
|
|
349
|
+
typeof settings !== 'object' ||
|
|
350
|
+
['maxSteps', 'exhausted', 'signal', 'diagnostics', 'onWorkflowEvent', 'observe'].some((key) => key in settings)) {
|
|
176
351
|
throw new TypeError('Use maxRounds, execution (including observe) and errors');
|
|
177
352
|
}
|
|
178
353
|
const execution = settings.execution;
|
|
@@ -180,10 +355,18 @@ class AgentCoreEngine {
|
|
|
180
355
|
this.branchIdentity = (0, branch_js_1.snapshotBranch)(settings.branch);
|
|
181
356
|
const observer = execution?.observe;
|
|
182
357
|
this.maxRounds = settings.maxRounds ?? 8;
|
|
183
|
-
this.exhausted =
|
|
358
|
+
this.exhausted =
|
|
359
|
+
settings.errors?.exhausted?.bind(settings.errors) ??
|
|
360
|
+
(() => new errors_js_2.BudgetError('Agent round budget exhausted'));
|
|
184
361
|
this.options = {
|
|
185
|
-
execution: {
|
|
186
|
-
|
|
362
|
+
execution: {
|
|
363
|
+
signal: execution?.signal,
|
|
364
|
+
diagnostics: execution?.diagnostics,
|
|
365
|
+
observe: observer && {
|
|
366
|
+
accepts: observer.accepts?.bind(observer),
|
|
367
|
+
event: observer.event.bind(observer),
|
|
368
|
+
},
|
|
369
|
+
},
|
|
187
370
|
};
|
|
188
371
|
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(this.maxRounds) || this.maxRounds < 1, () => new TypeError('maxRounds must be a positive safe integer'));
|
|
189
372
|
if (settings.workflow)
|
|
@@ -233,12 +416,45 @@ class AgentCoreEngine {
|
|
|
233
416
|
this.runtimeActive = false;
|
|
234
417
|
}
|
|
235
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* Resolve the lifetime of one run.
|
|
421
|
+
*
|
|
422
|
+
* All three sources are lifetime bounds only, so the strictest wins and no source can
|
|
423
|
+
* extend another.
|
|
424
|
+
*
|
|
425
|
+
* @param requestSignal - Caller-supplied signal for this run.
|
|
426
|
+
* @returns The combined signal.
|
|
427
|
+
*/
|
|
236
428
|
executionSignal(requestSignal) {
|
|
237
429
|
return (0, cancellation_js_1.combineSignals)(this.options.execution?.signal, this.modelRuntime?.execution.signal, requestSignal);
|
|
238
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* Resolve the observation scope for one run.
|
|
433
|
+
*
|
|
434
|
+
* A bound request runtime contributes its scope only when the engine has none, so one
|
|
435
|
+
* fact source serves both the App and the engine.
|
|
436
|
+
*
|
|
437
|
+
* @returns Execution options with the effective diagnostic scope.
|
|
438
|
+
*/
|
|
239
439
|
executionOptions() {
|
|
240
|
-
return {
|
|
440
|
+
return {
|
|
441
|
+
...this.options.execution,
|
|
442
|
+
diagnostics: this.options.execution?.diagnostics ?? this.modelRuntime?.execution.diagnostics,
|
|
443
|
+
};
|
|
241
444
|
}
|
|
445
|
+
/**
|
|
446
|
+
* Drive a caller-supplied step function until it completes or the budget ends.
|
|
447
|
+
*
|
|
448
|
+
* Each iteration is a round: the step must return an explicit continue/complete outcome,
|
|
449
|
+
* the continue path owns the round limit, and a report scope always closes before the
|
|
450
|
+
* next round starts. Failures leave the loop and are rethrown after the scope closes.
|
|
451
|
+
*
|
|
452
|
+
* @param step - Step implementation receiving the round index and context.
|
|
453
|
+
* @param requestSignal - Caller signal for this run.
|
|
454
|
+
* @returns The value of the completing step.
|
|
455
|
+
* @throws WorkflowContractError When the step returns something other than continue/complete.
|
|
456
|
+
* @throws The configured exhausted error, the step's failure, or the signal reason.
|
|
457
|
+
*/
|
|
242
458
|
async runLoop(step, requestSignal) {
|
|
243
459
|
const signal = this.executionSignal(requestSignal);
|
|
244
460
|
const events = (0, events_js_1.executionEvents)(this.executionOptions());
|
|
@@ -246,7 +462,14 @@ class AgentCoreEngine {
|
|
|
246
462
|
// failures leave the loop and propagate after the report scope closes.
|
|
247
463
|
let failure;
|
|
248
464
|
for (let index = 0;; index++) {
|
|
249
|
-
const diagnostics = events?.child((0, invocation_js_1.invocationId)(), {
|
|
465
|
+
const diagnostics = events?.child((0, invocation_js_1.invocationId)(), {
|
|
466
|
+
nodeRole: 'loop-step',
|
|
467
|
+
definitionKind: 'loop',
|
|
468
|
+
definitionId: 'loop',
|
|
469
|
+
nodeId: 'step',
|
|
470
|
+
nodeName: 'step',
|
|
471
|
+
nodeKind: 'loop-step',
|
|
472
|
+
});
|
|
250
473
|
const reports = new reporting_js_1.NodeReports(diagnostics, signal, 'loop.event');
|
|
251
474
|
let phase = 'boundary';
|
|
252
475
|
try {
|
|
@@ -254,10 +477,17 @@ class AgentCoreEngine {
|
|
|
254
477
|
this.emitLoop({ type: 'enter', roundIndex: index }, diagnostics);
|
|
255
478
|
phase = 'run';
|
|
256
479
|
signal.throwIfAborted();
|
|
257
|
-
const result = await (0, cancellation_js_1.awaitWithSignal)(step(index, {
|
|
480
|
+
const result = await (0, cancellation_js_1.awaitWithSignal)(step(index, {
|
|
481
|
+
signal,
|
|
482
|
+
diagnostics,
|
|
483
|
+
report: reports.report.bind(reports),
|
|
484
|
+
createSubFlowLogger: reports.createSubFlowLogger.bind(reports),
|
|
485
|
+
}), signal);
|
|
258
486
|
signal.throwIfAborted();
|
|
259
|
-
if (!result ||
|
|
260
|
-
|
|
487
|
+
if (!result ||
|
|
488
|
+
(typeof result !== 'object' && typeof result !== 'function') ||
|
|
489
|
+
(result.type !== 'continue' && result.type !== 'complete') ||
|
|
490
|
+
(result.type === 'complete' && !('value' in result)))
|
|
261
491
|
throw new errors_js_2.WorkflowContractError('Loop steps must return explicit continue/complete outcomes');
|
|
262
492
|
if (result.type === 'complete') {
|
|
263
493
|
const value = result.value;
|
|
@@ -282,13 +512,36 @@ class AgentCoreEngine {
|
|
|
282
512
|
}
|
|
283
513
|
throw failure;
|
|
284
514
|
}
|
|
515
|
+
/**
|
|
516
|
+
* Traverse a workflow node by node.
|
|
517
|
+
*
|
|
518
|
+
* Per visit the order is fixed: cancellation and round-budget checks, `requires`
|
|
519
|
+
* validation, the node handler, commit of `provides`, route selection, then either
|
|
520
|
+
* completion or transition. Failures are reported before any recovery decision, and only
|
|
521
|
+
* non-aborted, non-contract failures may follow `onErrorNodeId`; anything else propagates.
|
|
522
|
+
*
|
|
523
|
+
* @param workflow - Validated workflow catalog.
|
|
524
|
+
* @param state - Initial state; mutated in place by commits.
|
|
525
|
+
* @param app - Host dependencies exposed as `context.app`.
|
|
526
|
+
* @param requestSignal - Caller signal for this run.
|
|
527
|
+
* @param requestModelId - Per-run configured model override.
|
|
528
|
+
* @returns The workflow result.
|
|
529
|
+
* @throws WorkflowContractError for contract violations, or the node failure otherwise.
|
|
530
|
+
*/
|
|
285
531
|
async executeWorkflow(workflow, state, app, requestSignal, requestModelId) {
|
|
286
532
|
const signal = this.executionSignal(requestSignal);
|
|
287
533
|
const invokeTool = this.invokeTool;
|
|
288
534
|
const workflowInvocationId = (0, invocation_js_1.invocationId)();
|
|
289
535
|
// The execution scope also correlates content delivery when no observer or log is installed.
|
|
290
|
-
const workflowDiagnostics = ((0, events_js_1.executionEvents)(this.executionOptions()) ?? (0, events_js_1.createEventScope)()).child(workflowInvocationId, {
|
|
291
|
-
|
|
536
|
+
const workflowDiagnostics = ((0, events_js_1.executionEvents)(this.executionOptions()) ?? (0, events_js_1.createEventScope)()).child(workflowInvocationId, {
|
|
537
|
+
...this.branch,
|
|
538
|
+
invocationId: workflowInvocationId,
|
|
539
|
+
workflowInvocationId,
|
|
540
|
+
nodeRole: 'invocation',
|
|
541
|
+
definitionKind: 'workflow',
|
|
542
|
+
definitionId: workflow.id,
|
|
543
|
+
definitionRevision: workflow.revision,
|
|
544
|
+
});
|
|
292
545
|
const modelOptions = this.modelOptions;
|
|
293
546
|
const models = this.models;
|
|
294
547
|
const selectedModelId = requestModelId ?? this.selectedModelId;
|
|
@@ -308,8 +561,13 @@ class AgentCoreEngine {
|
|
|
308
561
|
throw new errors_js_2.WorkflowContractError('Select a configured modelId');
|
|
309
562
|
let runner = runners.get(modelId);
|
|
310
563
|
if (!runner) {
|
|
311
|
-
const setup = {
|
|
312
|
-
|
|
564
|
+
const setup = {
|
|
565
|
+
provider: options.provider,
|
|
566
|
+
[binding_js_1.compiledModelBinding]: options,
|
|
567
|
+
[binding_js_1.modelBindingId]: modelId,
|
|
568
|
+
[call_budget_js_1.parentModelBudget]: budget,
|
|
569
|
+
execution: { signal, diagnostics: workflowDiagnostics },
|
|
570
|
+
};
|
|
313
571
|
runner = new runner_js_1.ModelRunner(setup);
|
|
314
572
|
runners.set(modelId, runner);
|
|
315
573
|
}
|
|
@@ -328,41 +586,114 @@ class AgentCoreEngine {
|
|
|
328
586
|
throw this.exhausted();
|
|
329
587
|
}
|
|
330
588
|
catch (error) {
|
|
331
|
-
const diagnostics = workflowDiagnostics?.child(nextVisitId, {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
589
|
+
const diagnostics = workflowDiagnostics?.child(nextVisitId, {
|
|
590
|
+
nodeRole: 'workflow-boundary',
|
|
591
|
+
definitionKind: 'workflow',
|
|
592
|
+
definitionId: workflow.id,
|
|
593
|
+
definitionRevision: workflow.revision,
|
|
594
|
+
nodeId: node.id,
|
|
595
|
+
workflowNodeId: node.id,
|
|
596
|
+
nodeName: node.name ?? node.id,
|
|
597
|
+
nodeKind: 'workflow-node',
|
|
598
|
+
nodeDescription: node.description.slice(0, 1024),
|
|
599
|
+
});
|
|
600
|
+
this.emit({
|
|
601
|
+
...this.branch,
|
|
602
|
+
workflowId: workflow.id,
|
|
603
|
+
workflowInvocationId,
|
|
604
|
+
nodeId: node.id,
|
|
605
|
+
roundIndex: round,
|
|
606
|
+
...diagnostics?.identity,
|
|
607
|
+
type: 'error',
|
|
608
|
+
phase: 'boundary',
|
|
609
|
+
errorCode: this.errorCode(error, signal),
|
|
610
|
+
}, diagnostics);
|
|
335
611
|
throw error;
|
|
336
612
|
}
|
|
337
613
|
if (node.startsRound)
|
|
338
614
|
round = rounds++;
|
|
339
615
|
const started = Date.now();
|
|
340
|
-
const nodeDiagnostics = workflowDiagnostics?.child(nextVisitId, {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
616
|
+
const nodeDiagnostics = workflowDiagnostics?.child(nextVisitId, {
|
|
617
|
+
nodeRole: 'workflow-node',
|
|
618
|
+
definitionKind: 'workflow',
|
|
619
|
+
definitionId: workflow.id,
|
|
620
|
+
definitionRevision: workflow.revision,
|
|
621
|
+
nodeId: node.id,
|
|
622
|
+
workflowNodeId: node.id,
|
|
623
|
+
nodeName: node.name ?? node.id,
|
|
624
|
+
nodeKind: 'workflow-node',
|
|
625
|
+
nodeDescription: node.description.slice(0, 1024),
|
|
626
|
+
invocationId: undefined,
|
|
627
|
+
stageId: undefined,
|
|
628
|
+
});
|
|
629
|
+
const event = {
|
|
630
|
+
...this.branch,
|
|
631
|
+
workflowId: workflow.id,
|
|
632
|
+
workflowInvocationId,
|
|
633
|
+
errorEventId: failure?.errorEventId,
|
|
634
|
+
nodeId: node.id,
|
|
635
|
+
roundIndex: round,
|
|
636
|
+
...(nodeDiagnostics?.identity
|
|
637
|
+
? {
|
|
638
|
+
runId: nodeDiagnostics.identity.runId,
|
|
639
|
+
spanId: nodeDiagnostics.identity.spanId,
|
|
640
|
+
parentSpanId: nodeDiagnostics.identity.parentSpanId,
|
|
641
|
+
}
|
|
642
|
+
: {}),
|
|
643
|
+
};
|
|
344
644
|
function invokeModel(request) {
|
|
345
645
|
signal.throwIfAborted();
|
|
346
646
|
const owner = request.prepared && preparedOwners.get(request.prepared);
|
|
347
|
-
if (request.prepared &&
|
|
647
|
+
if (request.prepared &&
|
|
648
|
+
(!owner || (request.modelId !== undefined && request.modelId !== owner.modelId)))
|
|
348
649
|
throw new errors_js_2.WorkflowContractError('Prepared model call belongs to another execution or model');
|
|
349
650
|
const runner = owner?.runner ?? runnerFor(request.modelId);
|
|
350
|
-
return runner.invoke({
|
|
351
|
-
|
|
352
|
-
|
|
651
|
+
return runner.invoke({
|
|
652
|
+
stageId: request.stageId,
|
|
653
|
+
maxOutputTokens: request.maxOutputTokens,
|
|
654
|
+
transport: request.transport,
|
|
655
|
+
prepared: request.prepared,
|
|
656
|
+
signal: (0, cancellation_js_1.combineSignals)(signal, request.signal),
|
|
657
|
+
diagnostics: nodeDiagnostics,
|
|
658
|
+
...(typeof request.input === 'string'
|
|
659
|
+
? { input: request.input, instructions: request.instructions }
|
|
660
|
+
: { input: request.input }),
|
|
661
|
+
});
|
|
353
662
|
}
|
|
354
663
|
const prepareModel = ((request = {}) => {
|
|
355
664
|
signal.throwIfAborted();
|
|
356
665
|
const runner = runnerFor(request.modelId);
|
|
357
|
-
const snapshot = runner.prepare({
|
|
666
|
+
const snapshot = runner.prepare({
|
|
667
|
+
stageId: request.stageId,
|
|
668
|
+
maxOutputTokens: request.maxOutputTokens,
|
|
669
|
+
transport: request.transport,
|
|
670
|
+
});
|
|
358
671
|
preparedOwners.set(snapshot, { runner, modelId: request.modelId ?? selectedModelId });
|
|
359
672
|
return snapshot;
|
|
360
673
|
});
|
|
361
674
|
const reports = new reporting_js_1.NodeReports(nodeDiagnostics, signal);
|
|
362
|
-
const context = {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
675
|
+
const context = {
|
|
676
|
+
report: reports.report.bind(reports),
|
|
677
|
+
createSubFlowLogger: reports.createSubFlowLogger.bind(reports),
|
|
678
|
+
roundIndex: round,
|
|
679
|
+
app: app,
|
|
680
|
+
signal,
|
|
681
|
+
diagnostics: nodeDiagnostics,
|
|
682
|
+
model: {
|
|
683
|
+
invoke: invokeModel,
|
|
684
|
+
prepare: prepareModel,
|
|
685
|
+
get remainingCalls() {
|
|
686
|
+
return runnerFor().remainingCalls;
|
|
687
|
+
},
|
|
688
|
+
get callCount() {
|
|
689
|
+
return runnerFor().callCount;
|
|
690
|
+
},
|
|
691
|
+
get totalCallCount() {
|
|
692
|
+
return runnerFor().totalCallCount;
|
|
693
|
+
},
|
|
694
|
+
},
|
|
695
|
+
tools: {
|
|
696
|
+
async invoke(request) {
|
|
366
697
|
const toolSignal = (0, cancellation_js_1.combineSignals)(signal, request.signal);
|
|
367
698
|
toolSignal.throwIfAborted();
|
|
368
699
|
if (!invokeTool)
|
|
@@ -370,7 +701,10 @@ class AgentCoreEngine {
|
|
|
370
701
|
const result = await (0, cancellation_js_1.awaitWithSignal)(invokeTool({ ...request, signal: toolSignal, diagnostics: nodeDiagnostics }), toolSignal);
|
|
371
702
|
toolSignal.throwIfAborted();
|
|
372
703
|
return result;
|
|
373
|
-
}
|
|
704
|
+
},
|
|
705
|
+
},
|
|
706
|
+
...(failure ?? {}),
|
|
707
|
+
};
|
|
374
708
|
this.emit({ ...event, type: 'enter' }, nodeDiagnostics);
|
|
375
709
|
let phase = 'requires';
|
|
376
710
|
let selectedRoute;
|
|
@@ -386,7 +720,7 @@ class AgentCoreEngine {
|
|
|
386
720
|
phase = 'provides';
|
|
387
721
|
this.commit(state, update, node.provides ?? [], signal);
|
|
388
722
|
phase = 'route';
|
|
389
|
-
const routeIndex = node.routes.findIndex(route => {
|
|
723
|
+
const routeIndex = node.routes.findIndex((route) => {
|
|
390
724
|
selectedRoute = route;
|
|
391
725
|
if (!route.when)
|
|
392
726
|
return true;
|
|
@@ -427,11 +761,29 @@ class AgentCoreEngine {
|
|
|
427
761
|
if (valid !== true)
|
|
428
762
|
throw new errors_js_2.WorkflowContractError(`Invalid workflow result: ${workflow.id}`);
|
|
429
763
|
signal.throwIfAborted();
|
|
430
|
-
this.emit({
|
|
764
|
+
this.emit({
|
|
765
|
+
...event,
|
|
766
|
+
type: 'complete',
|
|
767
|
+
route: routeIndex,
|
|
768
|
+
routeId: route.id,
|
|
769
|
+
conditionId: route.conditionId,
|
|
770
|
+
durationMs: Date.now() - started,
|
|
771
|
+
}, nodeDiagnostics, node.report ? () => node.report(structuredClone(update), context) : undefined, reports);
|
|
431
772
|
return result;
|
|
432
773
|
}
|
|
433
774
|
nextVisitId = (0, invocation_js_1.invocationId)();
|
|
434
|
-
this.emit({
|
|
775
|
+
this.emit({
|
|
776
|
+
...event,
|
|
777
|
+
targetSpanId: workflowDiagnostics?.identity
|
|
778
|
+
? `${workflowDiagnostics.identity.spanId}/${nextVisitId}`
|
|
779
|
+
: undefined,
|
|
780
|
+
type: 'transition',
|
|
781
|
+
targetNodeId: route.targetNodeId,
|
|
782
|
+
route: routeIndex,
|
|
783
|
+
routeId: route.id,
|
|
784
|
+
conditionId: route.conditionId,
|
|
785
|
+
durationMs: Date.now() - started,
|
|
786
|
+
}, nodeDiagnostics, node.report ? () => node.report(structuredClone(update), context) : undefined, reports);
|
|
435
787
|
target = route.targetNodeId;
|
|
436
788
|
failure = undefined;
|
|
437
789
|
}
|
|
@@ -439,10 +791,22 @@ class AgentCoreEngine {
|
|
|
439
791
|
const recoverable = !signal.aborted && !(error instanceof errors_js_2.WorkflowContractError);
|
|
440
792
|
if (recoverable && node.onErrorNodeId !== undefined)
|
|
441
793
|
nextVisitId = (0, invocation_js_1.invocationId)();
|
|
442
|
-
const errorEvent = this.emit({
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
794
|
+
const errorEvent = this.emit({
|
|
795
|
+
...event,
|
|
796
|
+
targetSpanId: recoverable && node.onErrorNodeId !== undefined && workflowDiagnostics?.identity
|
|
797
|
+
? `${workflowDiagnostics.identity.spanId}/${nextVisitId}`
|
|
798
|
+
: undefined,
|
|
799
|
+
type: 'error',
|
|
800
|
+
targetNodeId: recoverable ? node.onErrorNodeId : undefined,
|
|
801
|
+
routeId: recoverable ? node.onErrorRouteId : undefined,
|
|
802
|
+
phase,
|
|
803
|
+
failedRouteId: ['route', 'complete', 'result'].includes(phase)
|
|
804
|
+
? selectedRoute?.id
|
|
805
|
+
: undefined,
|
|
806
|
+
conditionId: phase === 'route' ? selectedRoute?.conditionId : undefined,
|
|
807
|
+
durationMs: Date.now() - started,
|
|
808
|
+
errorCode: this.errorCode(error, signal),
|
|
809
|
+
}, nodeDiagnostics, undefined, reports);
|
|
446
810
|
signal.throwIfAborted();
|
|
447
811
|
if (node.onErrorNodeId === undefined || error instanceof errors_js_2.WorkflowContractError)
|
|
448
812
|
throw error;
|
|
@@ -454,6 +818,20 @@ class AgentCoreEngine {
|
|
|
454
818
|
}
|
|
455
819
|
}
|
|
456
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* Merge a node's state update and assert its declared outputs.
|
|
823
|
+
*
|
|
824
|
+
* The update is read once, checked against `provides` on the merged view, and only then
|
|
825
|
+
* written into the state, so a missing output never leaves a half-applied update.
|
|
826
|
+
* Cancellation is checked between the check and the write.
|
|
827
|
+
*
|
|
828
|
+
* @param state - State mutated in place.
|
|
829
|
+
* @param update - Object returned by the node handler, or undefined for no change.
|
|
830
|
+
* @param provides - Fields the node promises to leave defined.
|
|
831
|
+
* @param signal - Signal checked immediately before writing.
|
|
832
|
+
* @throws WorkflowContractError When the update is not an object or a provided field is
|
|
833
|
+
* undefined.
|
|
834
|
+
*/
|
|
457
835
|
commit(state, update, provides, signal) {
|
|
458
836
|
if (update !== undefined && (!update || typeof update !== 'object' || Array.isArray(update))) {
|
|
459
837
|
throw new errors_js_2.WorkflowContractError('Workflow handlers must return a state update object or undefined');
|
|
@@ -473,26 +851,62 @@ class AgentCoreEngine {
|
|
|
473
851
|
state[key] = fields[key];
|
|
474
852
|
}
|
|
475
853
|
}
|
|
854
|
+
/**
|
|
855
|
+
* Publish one loop event.
|
|
856
|
+
*
|
|
857
|
+
* The report scope is closed before emission for every event type, including `enter`,
|
|
858
|
+
* so a step cannot report progress against a round that has already ended.
|
|
859
|
+
*
|
|
860
|
+
* @param event - Loop event without its id.
|
|
861
|
+
* @param diagnostics - Scope of the current round.
|
|
862
|
+
* @param reports - Report scope for the current round.
|
|
863
|
+
*/
|
|
476
864
|
emitLoop(event, diagnostics, reports) {
|
|
477
865
|
const record = Object.freeze({ ...event, eventId: (0, invocation_js_1.invocationId)() });
|
|
478
866
|
reports?.close();
|
|
479
867
|
diagnostics?.emit('loop.event', () => record, reports?.debug());
|
|
480
868
|
}
|
|
869
|
+
/**
|
|
870
|
+
* Publish one workflow event and attach the node's report when content is enabled.
|
|
871
|
+
*
|
|
872
|
+
* The event is always emitted, even if the report throws or is malformed; a report is
|
|
873
|
+
* optional evidence, while the event is the authoritative transition record.
|
|
874
|
+
*
|
|
875
|
+
* @param input - Event fields without its id.
|
|
876
|
+
* @param diagnostics - Scope of the current node visit.
|
|
877
|
+
* @param report - Optional report builder evaluated only when content is enabled.
|
|
878
|
+
* @param reports - Report scope closed after emission.
|
|
879
|
+
* @returns The frozen event, so callers can reference its id.
|
|
880
|
+
*/
|
|
481
881
|
emit(input, diagnostics, report, reports) {
|
|
482
882
|
const event = Object.freeze({ ...input, eventId: (0, invocation_js_1.invocationId)() });
|
|
483
883
|
let detail;
|
|
484
|
-
if (report &&
|
|
884
|
+
if (report &&
|
|
885
|
+
diagnostics?.enabled('workflow.event') &&
|
|
886
|
+
diagnostics.enabled('workflow.event', 'content')) {
|
|
485
887
|
try {
|
|
486
888
|
const result = (0, synchronous_js_1.synchronous)(report(), 'Workflow reports must be synchronous');
|
|
487
889
|
reports?.receive(result);
|
|
488
890
|
detail = { payload: structuredClone(result.payload), subs: result.subs };
|
|
489
891
|
}
|
|
490
|
-
catch {
|
|
892
|
+
catch {
|
|
893
|
+
/* A report cannot suppress the workflow event. */
|
|
894
|
+
}
|
|
491
895
|
}
|
|
492
896
|
reports?.close();
|
|
493
897
|
diagnostics?.emit('workflow.event', () => ({ event, ...(detail?.payload === undefined ? {} : { payload: detail.payload }) }), reports?.debug(detail));
|
|
494
898
|
return event;
|
|
495
899
|
}
|
|
900
|
+
/**
|
|
901
|
+
* Classify a failure for reporting.
|
|
902
|
+
*
|
|
903
|
+
* Cancellation takes precedence over the error itself: once the signal is aborted, the
|
|
904
|
+
* reason matters more than whatever the interrupted code threw.
|
|
905
|
+
*
|
|
906
|
+
* @param error - Failure to classify.
|
|
907
|
+
* @param signal - Execution signal at the time of failure.
|
|
908
|
+
* @returns `TIMEOUT`, `CANCELLED`, or the error's own code.
|
|
909
|
+
*/
|
|
496
910
|
errorCode(error, signal) {
|
|
497
911
|
if (signal?.aborted)
|
|
498
912
|
return (0, cancellation_js_1.isTimeoutReason)(signal.reason) ? 'TIMEOUT' : 'CANCELLED';
|