@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
|
@@ -2,24 +2,47 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createEventScope = createEventScope;
|
|
4
4
|
exports.executionEvents = executionEvents;
|
|
5
|
+
/**
|
|
6
|
+
* Diagnostic event fact source for the execution loop.
|
|
7
|
+
*
|
|
8
|
+
* One `DiagnosticContext` tree serves both live observers and the optional persistent log.
|
|
9
|
+
* Facts are built once, then each consumer receives its own copy — full content only when
|
|
10
|
+
* that consumer asked for content, otherwise a metadata projection. No consumer means no
|
|
11
|
+
* payload work and no sub-step capture.
|
|
12
|
+
*
|
|
13
|
+
* Exports: `createEventScope` and `executionEvents`.
|
|
14
|
+
*/
|
|
5
15
|
const debug_js_1 = require("../utils/debug.js");
|
|
6
16
|
const invocation_js_1 = require("../utils/invocation.js");
|
|
7
17
|
const errors_js_1 = require("../errors.js");
|
|
8
18
|
const catalog_js_1 = require("../diagnostics/catalog.js");
|
|
9
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Create the root diagnostic scope.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Sink, observer, run id and initial span id.
|
|
23
|
+
* @returns The root scope; child scopes inherit its consumers.
|
|
24
|
+
*/
|
|
10
25
|
function createEventScope(options = {}) {
|
|
11
26
|
const { output } = options;
|
|
12
27
|
const write = output?.write.bind(output);
|
|
13
28
|
const accepts = output?.accepts?.bind(output);
|
|
14
29
|
const runId = options.runId || (0, invocation_js_1.invocationId)();
|
|
15
30
|
const spanId = options.spanId ?? 'run';
|
|
31
|
+
// Shared by every child scope so `producerSequence` orders facts across the whole run.
|
|
16
32
|
let sequence = 0;
|
|
17
33
|
const observer = (source) => ({
|
|
18
|
-
accepts: source.accepts?.bind(source),
|
|
34
|
+
accepts: source.accepts?.bind(source),
|
|
35
|
+
event: source.event.bind(source),
|
|
19
36
|
});
|
|
20
37
|
const initial = options.observe ? [observer(options.observe)] : [];
|
|
21
38
|
const context = (span, parent, fields = {}, listeners = initial) => {
|
|
22
|
-
const identity = Object.freeze({
|
|
39
|
+
const identity = Object.freeze({
|
|
40
|
+
...fields,
|
|
41
|
+
runId,
|
|
42
|
+
spanId: span,
|
|
43
|
+
...(parent ? { parentSpanId: parent } : {}),
|
|
44
|
+
});
|
|
45
|
+
// A missing accepts hook means the sink takes everything except an explicit refusal.
|
|
23
46
|
const logEnabled = (event, content) => {
|
|
24
47
|
if (!write)
|
|
25
48
|
return false;
|
|
@@ -30,9 +53,12 @@ function createEventScope(options = {}) {
|
|
|
30
53
|
return false;
|
|
31
54
|
}
|
|
32
55
|
};
|
|
56
|
+
// Listeners default to metadata-only; content requires an explicit opt-in.
|
|
33
57
|
const listenerEnabled = (listener, event, content) => {
|
|
34
58
|
try {
|
|
35
|
-
return listener.accepts
|
|
59
|
+
return listener.accepts
|
|
60
|
+
? listener.accepts({ ...identity, event, content }) === true
|
|
61
|
+
: content === 'metadata';
|
|
36
62
|
}
|
|
37
63
|
catch {
|
|
38
64
|
return false;
|
|
@@ -40,8 +66,24 @@ function createEventScope(options = {}) {
|
|
|
40
66
|
};
|
|
41
67
|
const fact = (event, payload, debug) => {
|
|
42
68
|
const value = payload();
|
|
43
|
-
const reported = scope.enabled(event, 'content')
|
|
44
|
-
|
|
69
|
+
const reported = scope.enabled(event, 'content')
|
|
70
|
+
? (0, debug_js_1.captureSubSteps)(debug?.subSteps, identity)
|
|
71
|
+
: (0, debug_js_1.captureSubSteps)(undefined);
|
|
72
|
+
return {
|
|
73
|
+
...identity,
|
|
74
|
+
...reported,
|
|
75
|
+
...(typeof debug?.usedModel === 'boolean' ? { usedModel: debug.usedModel } : {}),
|
|
76
|
+
version: 2,
|
|
77
|
+
eventId: event === 'workflow.event'
|
|
78
|
+
? value.event.eventId
|
|
79
|
+
: event === 'loop.event'
|
|
80
|
+
? value.eventId
|
|
81
|
+
: (0, invocation_js_1.invocationId)(),
|
|
82
|
+
type: event,
|
|
83
|
+
producerSequence: ++sequence,
|
|
84
|
+
occurredAtMs: Date.now(),
|
|
85
|
+
payload: value,
|
|
86
|
+
};
|
|
45
87
|
};
|
|
46
88
|
const publish = (record) => {
|
|
47
89
|
const event = record.type, kind = catalog_js_1.coreEventCatalog[event];
|
|
@@ -69,50 +111,117 @@ function createEventScope(options = {}) {
|
|
|
69
111
|
};
|
|
70
112
|
const scope = {
|
|
71
113
|
identity,
|
|
114
|
+
/** Whether any consumer would accept this event, optionally requiring content. */
|
|
72
115
|
enabled(event, content) {
|
|
73
116
|
if (!Object.hasOwn(catalog_js_1.coreEventCatalog, event))
|
|
74
117
|
return false;
|
|
75
118
|
const kind = content === 'content' ? 'content' : catalog_js_1.coreEventCatalog[event];
|
|
76
|
-
return logEnabled(event, kind) ||
|
|
119
|
+
return (logEnabled(event, kind) ||
|
|
120
|
+
listeners.some((listener) => listenerEnabled(listener, event, kind)));
|
|
77
121
|
},
|
|
122
|
+
/**
|
|
123
|
+
* Build and publish a fact without waiting for anyone.
|
|
124
|
+
*
|
|
125
|
+
* Observation failures are swallowed so reporting cannot change execution.
|
|
126
|
+
*/
|
|
78
127
|
emit(event, payload, debug) {
|
|
79
128
|
if (!this.enabled(event))
|
|
80
129
|
return;
|
|
81
130
|
try {
|
|
82
131
|
publish(fact(event, payload, debug));
|
|
83
132
|
}
|
|
84
|
-
catch {
|
|
133
|
+
catch {
|
|
134
|
+
/* Observation must not change execution. */
|
|
135
|
+
}
|
|
85
136
|
},
|
|
137
|
+
/**
|
|
138
|
+
* Publish a fact and then hand a copy of it to a delivery sink.
|
|
139
|
+
*
|
|
140
|
+
* Publication comes first so observers retain causal order even if the sink stalls.
|
|
141
|
+
*/
|
|
86
142
|
async deliver(event, payload, sink) {
|
|
87
143
|
const record = fact(event, payload);
|
|
88
144
|
publish(record);
|
|
89
145
|
await sink(eventSnapshot(record));
|
|
90
146
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Derive a child span.
|
|
149
|
+
*
|
|
150
|
+
* A child that starts its own invocation records the parent invocation, which keeps
|
|
151
|
+
* a request-scoped trace navigable without modelling the whole call tree.
|
|
152
|
+
*/
|
|
153
|
+
child: (id, childFields = {}) => context(`${span}/${id}`, span, {
|
|
154
|
+
...fields,
|
|
155
|
+
...(childFields.invocationId &&
|
|
156
|
+
childFields.invocationId !== fields.invocationId &&
|
|
157
|
+
fields.invocationId
|
|
158
|
+
? { parentInvocationId: fields.invocationId }
|
|
159
|
+
: {}),
|
|
160
|
+
...childFields,
|
|
161
|
+
}, listeners),
|
|
162
|
+
/** Add an observer to an existing scope while keeping its identity and sequence. */
|
|
163
|
+
withObserver: (source) => context(span, parent, fields, [...listeners, observer(source)]),
|
|
94
164
|
};
|
|
95
165
|
return scope;
|
|
96
166
|
};
|
|
97
167
|
return context(spanId);
|
|
98
168
|
}
|
|
99
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* Metadata projections shared by live observers and log consumers.
|
|
171
|
+
*
|
|
172
|
+
* Only events listed here are reduced; an unlisted event passes its full payload to a
|
|
173
|
+
* metadata-only consumer, so any event added to the catalog must also be added here when
|
|
174
|
+
* its payload contains content.
|
|
175
|
+
*/
|
|
100
176
|
const metadataProjections = {
|
|
101
|
-
'node.progress': ({ subStep, reportError }) => ({
|
|
177
|
+
'node.progress': ({ subStep, reportError }) => ({
|
|
178
|
+
...(subStep ? { subStep } : {}),
|
|
179
|
+
...(reportError ? { reportError } : {}),
|
|
180
|
+
}),
|
|
102
181
|
'workflow.event': ({ event }) => ({ event }),
|
|
103
182
|
'tool.call': ({ toolId, invocationId }) => ({ toolId, invocationId }),
|
|
104
|
-
'tool.result': ({ toolId, invocationId, status, durationMs, errorCode }) => ({
|
|
183
|
+
'tool.result': ({ toolId, invocationId, status, durationMs, errorCode }) => ({
|
|
184
|
+
toolId,
|
|
185
|
+
invocationId,
|
|
186
|
+
status,
|
|
187
|
+
durationMs,
|
|
188
|
+
errorCode,
|
|
189
|
+
}),
|
|
105
190
|
'model.parsed': ({ stageId, callSequence }) => ({ stageId, callSequence }),
|
|
106
191
|
'model.end': ({ stageId, state, receivedParts }) => ({ stageId, state, receivedParts }),
|
|
107
|
-
'runtime.rejected': ({ stageId, error }) => ({
|
|
192
|
+
'runtime.rejected': ({ stageId, error }) => ({
|
|
193
|
+
stageId,
|
|
194
|
+
error: { code: (0, errors_js_1.getErrorInfo)(error).code },
|
|
195
|
+
}),
|
|
108
196
|
'rule.result': ({ tags, error }) => ({ tags, error: { code: (0, errors_js_1.getErrorInfo)(error).code } }),
|
|
109
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* Reduce a payload to its metadata projection.
|
|
200
|
+
*
|
|
201
|
+
* @param type - Event type.
|
|
202
|
+
* @param payload - Full payload built for the fact.
|
|
203
|
+
* @returns The projected payload, or the original when no projection is declared.
|
|
204
|
+
*/
|
|
110
205
|
function metadataPayload(type, payload) {
|
|
111
206
|
return metadataProjections[type]?.(payload) ?? payload;
|
|
112
207
|
}
|
|
113
|
-
/**
|
|
208
|
+
/**
|
|
209
|
+
* Copy one record for a single consumer.
|
|
210
|
+
*
|
|
211
|
+
* Every consumer gets its own copy so one listener cannot observe another's mutations.
|
|
212
|
+
* A content-free copy is used when requested, and if the full record cannot be cloned the
|
|
213
|
+
* metadata-only record is used instead, since observation must never fail the caller.
|
|
214
|
+
*
|
|
215
|
+
* @param record - Fact to copy.
|
|
216
|
+
* @param content - Whether to keep payload content.
|
|
217
|
+
* @returns A structured clone of either the full record or its metadata projection.
|
|
218
|
+
*/
|
|
114
219
|
function eventSnapshot(record, content = true) {
|
|
115
|
-
const metadata = () => ({
|
|
220
|
+
const metadata = () => ({
|
|
221
|
+
...record,
|
|
222
|
+
...(0, debug_js_1.captureSubSteps)(undefined),
|
|
223
|
+
payload: metadataPayload(record.type, record.payload),
|
|
224
|
+
});
|
|
116
225
|
try {
|
|
117
226
|
return structuredClone(content ? record : metadata());
|
|
118
227
|
}
|
|
@@ -120,7 +229,16 @@ function eventSnapshot(record, content = true) {
|
|
|
120
229
|
return structuredClone(metadata());
|
|
121
230
|
}
|
|
122
231
|
}
|
|
123
|
-
/**
|
|
232
|
+
/**
|
|
233
|
+
* Resolve the diagnostic scope for one execution.
|
|
234
|
+
*
|
|
235
|
+
* An observer forces a scope to exist even when the host installed none; the observer is
|
|
236
|
+
* attached to the existing scope instead of replacing it, so log and live observation
|
|
237
|
+
* share one fact identity and one sequence.
|
|
238
|
+
*
|
|
239
|
+
* @param options - Execution options carrying a scope and/or an observer.
|
|
240
|
+
* @returns The scope to use, or undefined when the host observes nothing.
|
|
241
|
+
*/
|
|
124
242
|
function executionEvents(options) {
|
|
125
243
|
const { diagnostics, observe } = options ?? {};
|
|
126
244
|
return observe ? (diagnostics ?? createEventScope()).withObserver(observe) : diagnostics;
|
|
@@ -15,6 +15,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.ValidationError = exports.BudgetError = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Public surface of the execution layer.
|
|
20
|
+
*
|
|
21
|
+
* Re-exports the engine, the workflow catalog and its route helpers, the shared budget
|
|
22
|
+
* and validation errors, and the policy kit. Applications should import the loop and
|
|
23
|
+
* workflow contracts from here rather than from individual files.
|
|
24
|
+
*/
|
|
18
25
|
__exportStar(require("./engine.js"), exports);
|
|
19
26
|
__exportStar(require("./workflow.js"), exports);
|
|
20
27
|
var errors_js_1 = require("../structs/errors.js");
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NodeReports = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Per-visit reporting scope for workflow nodes and loop steps.
|
|
6
|
+
*
|
|
7
|
+
* A node may report progress and write sub-steps while it runs. This scope guarantees
|
|
8
|
+
* that reports stop at the end of the visit (`close`), stop on cancellation, and never
|
|
9
|
+
* fail the execution: invalid reports degrade to an error marker.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `NodeReports`.
|
|
12
|
+
*/
|
|
4
13
|
const rules_js_1 = require("../utils/rules.js");
|
|
5
14
|
const sub_flow_js_1 = require("../diagnostics/sub-flow.js");
|
|
6
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The existing node report and diagnostic outlet, scoped to one execution visit.
|
|
17
|
+
*
|
|
18
|
+
* One instance exists per node visit. `close` is called in the engine's `finally`, so
|
|
19
|
+
* reports emitted after the visit ends are dropped rather than attributed to a later
|
|
20
|
+
* node.
|
|
21
|
+
*/
|
|
7
22
|
class NodeReports {
|
|
8
23
|
diagnostics;
|
|
9
24
|
signal;
|
|
@@ -11,29 +26,70 @@ class NodeReports {
|
|
|
11
26
|
active = true;
|
|
12
27
|
logger;
|
|
13
28
|
usedModel;
|
|
29
|
+
/**
|
|
30
|
+
* @param diagnostics - Diagnostic scope of the visit; omitted when observation is off.
|
|
31
|
+
* @param signal - Execution signal; an aborted signal suppresses all further reports.
|
|
32
|
+
* @param terminalEvent - Event whose content switch also enables sub-step capture.
|
|
33
|
+
*/
|
|
14
34
|
constructor(diagnostics, signal, terminalEvent = 'workflow.event') {
|
|
15
35
|
this.diagnostics = diagnostics;
|
|
16
36
|
this.signal = signal;
|
|
17
37
|
this.terminalEvent = terminalEvent;
|
|
18
38
|
}
|
|
19
|
-
|
|
39
|
+
/** End the visit; later reports and logger creation are ignored or rejected. */
|
|
40
|
+
close() {
|
|
41
|
+
this.active = false;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Validate a report and retain its model-use flag.
|
|
45
|
+
*
|
|
46
|
+
* `usedModel` is monotonic: once a visit reports model use, a later report cannot take
|
|
47
|
+
* it back, because the observation already claimed a model-assisted step.
|
|
48
|
+
*
|
|
49
|
+
* @param update - Report supplied by the node.
|
|
50
|
+
* @throws TypeError When the report is not an object or its model-use flag conflicts.
|
|
51
|
+
*/
|
|
20
52
|
receive(update) {
|
|
21
53
|
(0, rules_js_1.breakWhile)(!update || typeof update !== 'object', () => new TypeError('Invalid node report'));
|
|
22
54
|
const usedModel = update.usedModel;
|
|
23
|
-
(0, rules_js_1.breakWhile)(usedModel !== undefined &&
|
|
55
|
+
(0, rules_js_1.breakWhile)(usedModel !== undefined &&
|
|
56
|
+
(typeof usedModel !== 'boolean' || (this.usedModel === true && !usedModel)), () => new TypeError('Invalid reported model use'));
|
|
24
57
|
if (usedModel !== undefined)
|
|
25
58
|
this.usedModel = usedModel;
|
|
26
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Build the debug view of this visit.
|
|
62
|
+
*
|
|
63
|
+
* Getters keep the values live while the fact is being built; `subSteps` prefers the
|
|
64
|
+
* logger supplied in the report and falls back to the visit's own logger.
|
|
65
|
+
*
|
|
66
|
+
* @param update - Optional report whose logger replaces the visit logger.
|
|
67
|
+
* @returns A debug output object consumed by the diagnostic pipeline.
|
|
68
|
+
*/
|
|
27
69
|
debug(update) {
|
|
28
70
|
const self = this;
|
|
29
|
-
return {
|
|
71
|
+
return {
|
|
72
|
+
get usedModel() {
|
|
73
|
+
return self.usedModel;
|
|
74
|
+
},
|
|
75
|
+
subSteps: () => {
|
|
30
76
|
const supplied = update?.subs;
|
|
31
77
|
const logger = supplied === undefined ? this.logger : supplied;
|
|
32
78
|
if (logger !== undefined)
|
|
33
79
|
(0, sub_flow_js_1.readSubFlowLogger)(logger, this);
|
|
34
80
|
return logger;
|
|
35
|
-
}
|
|
81
|
+
},
|
|
82
|
+
};
|
|
36
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Publish one progress report.
|
|
86
|
+
*
|
|
87
|
+
* Payload content is only included when content logging is enabled; failures become a
|
|
88
|
+
* fixed `INVALID_NODE_REPORT` marker so a malformed report is visible without breaking
|
|
89
|
+
* the node.
|
|
90
|
+
*
|
|
91
|
+
* @param update - Report supplied by the node.
|
|
92
|
+
*/
|
|
37
93
|
report(update) {
|
|
38
94
|
if (!this.active || this.signal?.aborted)
|
|
39
95
|
return;
|
|
@@ -45,9 +101,22 @@ class NodeReports {
|
|
|
45
101
|
this.diagnostics?.emit('node.progress', () => ({ reportError: 'INVALID_NODE_REPORT' }));
|
|
46
102
|
}
|
|
47
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Create (once) the logger that records sub-steps for this visit.
|
|
106
|
+
*
|
|
107
|
+
* Sub-steps are only collected when progress or the terminal event carries content, so
|
|
108
|
+
* a metadata-only observer pays no logging cost.
|
|
109
|
+
*
|
|
110
|
+
* @returns The visit's logger, identical on repeated calls.
|
|
111
|
+
* @throws TypeError When the visit is already closed or the execution was aborted.
|
|
112
|
+
*/
|
|
48
113
|
createSubFlowLogger() {
|
|
49
114
|
(0, rules_js_1.breakWhile)(!this.active || this.signal?.aborted, () => new TypeError('Cannot create a logger for a closed execution'));
|
|
50
|
-
return this.logger ??= (0, sub_flow_js_1.createSubFlowLogger)(this, () => this.active && !this.signal?.aborted, () => this.diagnostics?.enabled('node.progress', 'content') === true ||
|
|
115
|
+
return (this.logger ??= (0, sub_flow_js_1.createSubFlowLogger)(this, () => this.active && !this.signal?.aborted, () => this.diagnostics?.enabled('node.progress', 'content') === true ||
|
|
116
|
+
this.diagnostics?.enabled(this.terminalEvent, 'content') === true, (logger, progress) => this.diagnostics?.emit('node.progress', () => ({ subStep: progress }), {
|
|
117
|
+
usedModel: this.usedModel,
|
|
118
|
+
subSteps: () => logger,
|
|
119
|
+
}), this.diagnostics?.identity));
|
|
51
120
|
}
|
|
52
121
|
}
|
|
53
122
|
exports.NodeReports = NodeReports;
|
|
@@ -3,27 +3,67 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.route = void 0;
|
|
4
4
|
exports.requireWorkflowValue = requireWorkflowValue;
|
|
5
5
|
const errors_js_1 = require("../structs/errors.js");
|
|
6
|
+
/**
|
|
7
|
+
* Read a state field that must already be present.
|
|
8
|
+
*
|
|
9
|
+
* Used by `requires` declarations and terminal deliveries, so a node cannot observe a
|
|
10
|
+
* field as undefined and silently produce a wrong result.
|
|
11
|
+
*
|
|
12
|
+
* @param state - Current workflow state.
|
|
13
|
+
* @param key - Field to read.
|
|
14
|
+
* @returns The field value, narrowed to exclude undefined.
|
|
15
|
+
* @throws WorkflowContractError When the field is undefined.
|
|
16
|
+
*/
|
|
6
17
|
function requireWorkflowValue(state, key) {
|
|
7
18
|
const value = state[key];
|
|
8
19
|
if (value === undefined)
|
|
9
20
|
throw new errors_js_1.WorkflowContractError(`Missing workflow state: ${String(key)}`);
|
|
10
21
|
return value;
|
|
11
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Build a reader for one state path.
|
|
25
|
+
*
|
|
26
|
+
* Dotted string paths traverse nested objects and stop safely at undefined; any other key
|
|
27
|
+
* is read directly from the state. Both forms share the returned reader so route
|
|
28
|
+
* conditions stay uniform.
|
|
29
|
+
*
|
|
30
|
+
* @param path - Dotted path or direct key.
|
|
31
|
+
* @returns A function reading the value from a state object.
|
|
32
|
+
*/
|
|
12
33
|
function readPath(path) {
|
|
13
34
|
const keys = typeof path === 'string' ? path.split('.') : [path];
|
|
14
35
|
return (state) => keys.reduce((value, key) => value?.[key], state);
|
|
15
36
|
}
|
|
16
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Unconditional jump with a stable, target-derived route ID.
|
|
39
|
+
*
|
|
40
|
+
* @param target - Destination node id.
|
|
41
|
+
* @param id - Optional explicit route id.
|
|
42
|
+
* @returns A terminal-free route that always matches.
|
|
43
|
+
*/
|
|
17
44
|
const routeTo = function route(target, id) {
|
|
18
45
|
return { id: id ?? `to-${target}`, targetNodeId: target };
|
|
19
46
|
};
|
|
20
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* One conditional jump, using the same strict equality as a handwritten route.
|
|
49
|
+
*
|
|
50
|
+
* A derived route id is only produced for symbol-free paths and primitive values,
|
|
51
|
+
* because those are the cases where `String(value)` is stable and unique enough to name
|
|
52
|
+
* the condition.
|
|
53
|
+
*
|
|
54
|
+
* @param target - Destination node id.
|
|
55
|
+
* @param path - State path to compare.
|
|
56
|
+
* @param value - Expected value, compared with `===`.
|
|
57
|
+
* @param options - Optional id, condition id and description.
|
|
58
|
+
* @returns A route that matches when the path equals `value`.
|
|
59
|
+
*/
|
|
21
60
|
function toIfEqual(target, path, value, options) {
|
|
22
61
|
const stableValue = value === null || ['undefined', 'string', 'boolean', 'number', 'bigint'].includes(typeof value);
|
|
23
62
|
const condition = typeof path !== 'symbol' && stableValue
|
|
24
63
|
? JSON.stringify([String(path), typeof value, String(value)])
|
|
25
64
|
: undefined;
|
|
26
|
-
const id = options?.id ??
|
|
65
|
+
const id = options?.id ??
|
|
66
|
+
(condition === undefined ? undefined : `route:${JSON.stringify([condition, target])}`);
|
|
27
67
|
const conditionId = options?.conditionId ?? (id === undefined ? undefined : '{nid}.{rid}');
|
|
28
68
|
const read = readPath(path);
|
|
29
69
|
return {
|
|
@@ -34,52 +74,138 @@ function toIfEqual(target, path, value, options) {
|
|
|
34
74
|
targetNodeId: target,
|
|
35
75
|
};
|
|
36
76
|
}
|
|
37
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Jump when two state paths resolve to strictly equal values.
|
|
79
|
+
*
|
|
80
|
+
* No derived route id is produced for symbol paths, because a symbol cannot be embedded
|
|
81
|
+
* in a stable name.
|
|
82
|
+
*
|
|
83
|
+
* @param target - Destination node id.
|
|
84
|
+
* @param leftPath - First state path.
|
|
85
|
+
* @param rightPath - Second state path.
|
|
86
|
+
* @param options - Optional id, condition id and description.
|
|
87
|
+
* @returns A route that matches when both paths are strictly equal.
|
|
88
|
+
*/
|
|
38
89
|
function toIfEqualWith(target, leftPath, rightPath, options) {
|
|
39
90
|
const left = readPath(leftPath);
|
|
40
91
|
const right = readPath(rightPath);
|
|
41
|
-
const id = options?.id ??
|
|
42
|
-
|
|
92
|
+
const id = options?.id ??
|
|
93
|
+
(typeof leftPath === 'symbol' || typeof rightPath === 'symbol'
|
|
94
|
+
? undefined
|
|
95
|
+
: `route:with:${JSON.stringify([String(leftPath), String(rightPath), target])}`);
|
|
43
96
|
return {
|
|
44
|
-
...options,
|
|
97
|
+
...options,
|
|
98
|
+
id,
|
|
45
99
|
conditionId: options?.conditionId ?? (id === undefined ? undefined : '{nid}.{rid}'),
|
|
46
100
|
when: (state) => left(state) === right(state),
|
|
47
101
|
targetNodeId: target,
|
|
48
102
|
};
|
|
49
103
|
}
|
|
50
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* Jump when a state array contains at least one entry.
|
|
106
|
+
*
|
|
107
|
+
* A non-array value never matches, so a mistyped field cannot be treated as populated.
|
|
108
|
+
*
|
|
109
|
+
* @param target - Destination node id.
|
|
110
|
+
* @param key - State path expected to hold an array.
|
|
111
|
+
* @param options - Optional id, condition id and description.
|
|
112
|
+
* @returns A route that matches for a non-empty array.
|
|
113
|
+
*/
|
|
51
114
|
function toIfNotEmpty(target, key, options) {
|
|
52
115
|
const read = readPath(key);
|
|
53
|
-
return {
|
|
116
|
+
return {
|
|
117
|
+
...options,
|
|
118
|
+
...routeTo(target, options?.id),
|
|
119
|
+
conditionId: options?.conditionId ?? '{nid}.{rid}',
|
|
120
|
+
when: (state) => {
|
|
54
121
|
const value = read(state);
|
|
55
122
|
return Array.isArray(value) && value.length > 0;
|
|
56
|
-
}
|
|
123
|
+
},
|
|
124
|
+
};
|
|
57
125
|
}
|
|
58
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* Jump once a state field has a value.
|
|
128
|
+
*
|
|
129
|
+
* `null` counts as present: only `undefined` means the field is still unset.
|
|
130
|
+
*
|
|
131
|
+
* @param target - Destination node id.
|
|
132
|
+
* @param field - State path to inspect.
|
|
133
|
+
* @param options - Optional id, condition id and description.
|
|
134
|
+
* @returns A route that matches when the field is not undefined.
|
|
135
|
+
*/
|
|
59
136
|
function toIfDefined(target, field, options) {
|
|
60
137
|
const read = readPath(field);
|
|
61
|
-
return {
|
|
138
|
+
return {
|
|
139
|
+
...options,
|
|
140
|
+
...routeTo(target, options?.id),
|
|
141
|
+
conditionId: options?.conditionId ?? '{nid}.{rid}',
|
|
142
|
+
when: (state) => read(state) !== undefined,
|
|
143
|
+
};
|
|
62
144
|
}
|
|
63
|
-
/**
|
|
145
|
+
/**
|
|
146
|
+
* Jump to the node named by a truthy state field.
|
|
147
|
+
*
|
|
148
|
+
* The same field is used as the condition and as the destination, which is the usual
|
|
149
|
+
* shape of a dispatcher that stored its own next node.
|
|
150
|
+
*
|
|
151
|
+
* @param target - Field holding the destination node id.
|
|
152
|
+
* @param options - Optional id, condition id and description.
|
|
153
|
+
* @returns A route that matches when the field is truthy.
|
|
154
|
+
*/
|
|
64
155
|
function toIf(target, options) {
|
|
65
|
-
return {
|
|
156
|
+
return {
|
|
157
|
+
...toIfDefined(target, target, options),
|
|
158
|
+
when: (state) => Boolean(state[target]),
|
|
159
|
+
};
|
|
66
160
|
}
|
|
67
161
|
function toIfError(target, { errorKey = 'error', ...options } = {}) {
|
|
68
162
|
return toIfDefined(target, errorKey, options);
|
|
69
163
|
}
|
|
70
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* At a terminal node, the result must already exist.
|
|
166
|
+
*
|
|
167
|
+
* Completing reads the field with `requireWorkflowValue`, so a node that forgot to
|
|
168
|
+
* produce its result fails instead of returning undefined.
|
|
169
|
+
*
|
|
170
|
+
* @param field - State field holding the final result.
|
|
171
|
+
* @param options - Optional id and description; a condition id is meaningless here.
|
|
172
|
+
* @returns A completion route with the default id `complete`.
|
|
173
|
+
*/
|
|
71
174
|
function deliver(field, options) {
|
|
72
175
|
const id = options?.id ?? 'complete';
|
|
73
176
|
return {
|
|
74
|
-
...options,
|
|
177
|
+
...options,
|
|
178
|
+
id,
|
|
75
179
|
complete: (state) => requireWorkflowValue(state, field),
|
|
76
180
|
};
|
|
77
181
|
}
|
|
78
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Deliver an available result, or let the next route decide.
|
|
184
|
+
*
|
|
185
|
+
* Unlike `deliver`, this route carries a condition so a following route still has a
|
|
186
|
+
* chance to match when the field is still unset.
|
|
187
|
+
*
|
|
188
|
+
* @param field - State field holding the result.
|
|
189
|
+
* @param options - Optional route metadata.
|
|
190
|
+
* @returns A conditional completion route.
|
|
191
|
+
*/
|
|
79
192
|
function deliverIfReady(field, options) {
|
|
80
|
-
return {
|
|
193
|
+
return {
|
|
194
|
+
...deliver(field, options),
|
|
195
|
+
conditionId: options?.conditionId ?? '{nid}.{rid}',
|
|
196
|
+
when: (state) => state[field] !== undefined,
|
|
197
|
+
};
|
|
81
198
|
}
|
|
82
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* Apply the shared continue/complete outcome contract.
|
|
201
|
+
*
|
|
202
|
+
* The field holds a `StepOutcome`; only the `complete` variant ends the workflow, and the
|
|
203
|
+
* completion asserts the variant instead of trusting the condition.
|
|
204
|
+
*
|
|
205
|
+
* @param field - State field holding the outcome.
|
|
206
|
+
* @param options - Optional route metadata.
|
|
207
|
+
* @returns A conditional completion route that unwraps the outcome value.
|
|
208
|
+
*/
|
|
83
209
|
function deliverWhenComplete(field, options) {
|
|
84
210
|
return {
|
|
85
211
|
...options,
|
|
@@ -94,8 +220,21 @@ function deliverWhenComplete(field, options) {
|
|
|
94
220
|
},
|
|
95
221
|
};
|
|
96
222
|
}
|
|
97
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* Callable route catalog; aliases share the same function without namespace initialization.
|
|
225
|
+
*
|
|
226
|
+
* `route(...)` and `route.to(...)` are the same function, so both call styles stay
|
|
227
|
+
* interchangeable and no module-level setup is required to use either.
|
|
228
|
+
*/
|
|
98
229
|
exports.route = Object.assign(routeTo, {
|
|
99
|
-
to: routeTo,
|
|
100
|
-
|
|
230
|
+
to: routeTo,
|
|
231
|
+
toIfEqual,
|
|
232
|
+
toIfEqualWith,
|
|
233
|
+
toIfNotEmpty,
|
|
234
|
+
toIfDefined,
|
|
235
|
+
toIf,
|
|
236
|
+
toIfError,
|
|
237
|
+
deliver,
|
|
238
|
+
deliverIfReady,
|
|
239
|
+
deliverWhenComplete,
|
|
101
240
|
});
|