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