@jangts/agent-core 0.1.1 → 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/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -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 +3 -2
|
@@ -1,8 +1,46 @@
|
|
|
1
1
|
import type { RecordedSubStep, SubFlowLogger, SubStepProgress, SubFlowValue } from '../structs/debug.js';
|
|
2
2
|
import type { DiagnosticIdentity } from '../structs/diagnostics.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Validate and deep-copy a reported payload.
|
|
5
|
+
*
|
|
6
|
+
* Accessors, class instances, cycles and non-JSON values are rejected without evaluating
|
|
7
|
+
* application getters, so a payload can neither run code nor alias live state. Accepted data is
|
|
8
|
+
* frozen.
|
|
9
|
+
*
|
|
10
|
+
* @param input Object to snapshot. It must be a plain object, not an array.
|
|
11
|
+
* @returns A deeply frozen JSON-shaped copy.
|
|
12
|
+
* @throws TypeError when the value is not plain JSON data, contains a getter, or is cyclic.
|
|
13
|
+
* @throws RangeError when node count, nesting depth, string length or array length exceeds the
|
|
14
|
+
* limits below.
|
|
15
|
+
*/
|
|
4
16
|
export declare function payloadSnapshot(input: unknown): Readonly<Record<string, SubFlowValue>>;
|
|
5
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Create a logger bound to one active execution visit.
|
|
19
|
+
*
|
|
20
|
+
* Only execution contexts inside this package should call it: the resulting object is the sole
|
|
21
|
+
* way to append reported steps to the current record.
|
|
22
|
+
*
|
|
23
|
+
* @param owner Object that owns the visit. `readSubFlowLogger` compares this identity before
|
|
24
|
+
* returning any step.
|
|
25
|
+
* @param active Reports whether the visit is still open; a closed logger rejects writes.
|
|
26
|
+
* @param content Reports whether content-level detail is enabled. When false, summaries and
|
|
27
|
+
* payloads are dropped before anything is stored.
|
|
28
|
+
* @param changed Called after each accepted write or fix with the progress delta to publish.
|
|
29
|
+
* @param identity Diagnostic run and span the logger belongs to; used to reject cross-scope reads.
|
|
30
|
+
* @returns A frozen logger instance.
|
|
31
|
+
*/
|
|
6
32
|
export declare function createSubFlowLogger(owner: object, active: () => boolean, content: () => boolean, changed: (logger: SubFlowLogger, progress: SubStepProgress) => void, identity?: Readonly<DiagnosticIdentity>): SubFlowLogger;
|
|
7
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Read the steps recorded by a logger issued by this module.
|
|
35
|
+
*
|
|
36
|
+
* The instance is resolved through the private registry, so a lookalike's `readAll` method is
|
|
37
|
+
* never called and a logger cannot be borrowed across executions.
|
|
38
|
+
*
|
|
39
|
+
* @param input Candidate logger; must be an instance created by `createSubFlowLogger`.
|
|
40
|
+
* @param owner Expected owning execution visit. Omit to accept any owner.
|
|
41
|
+
* @param identity Expected run and span. Omit to accept any diagnostic scope.
|
|
42
|
+
* @returns The recorded steps in write order, as an immutable list shared with the logger.
|
|
43
|
+
* @throws TypeError when the value is not a registered logger, belongs to another owner, or
|
|
44
|
+
* belongs to another diagnostic scope.
|
|
45
|
+
*/
|
|
8
46
|
export declare function readSubFlowLogger(input: unknown, owner?: object, identity?: Readonly<DiagnosticIdentity>): readonly Readonly<RecordedSubStep>[];
|
|
@@ -1,16 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded, self-reported sub-flow logging.
|
|
3
|
+
*
|
|
4
|
+
* A node or tool may report the steps it believes it performed. Such reports are optional
|
|
5
|
+
* evidence, never proof of Core scheduling: they are marked `origin: 'reported'`, validated
|
|
6
|
+
* against a fixed field whitelist, and capped in count, text length and nested payload depth.
|
|
7
|
+
*
|
|
8
|
+
* Issued loggers are tracked in a module-private registry, so only the execution that created
|
|
9
|
+
* one can read it. A lookalike object with a `readAll` method is never accepted.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `payloadSnapshot`, `createSubFlowLogger`, `readSubFlowLogger`.
|
|
12
|
+
*/
|
|
1
13
|
import { breakWhile } from '../utils/rules.js';
|
|
2
14
|
import { invocationId } from '../utils/invocation.js';
|
|
3
15
|
import { reportedStepStatusCatalog } from '../structs/debug.js';
|
|
16
|
+
/**
|
|
17
|
+
* Registry of issued loggers: owner, diagnostic identity and reader for each instance. Kept
|
|
18
|
+
* private so a structurally identical object cannot impersonate a real logger.
|
|
19
|
+
*/
|
|
4
20
|
const instances = new WeakMap();
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
21
|
+
/** Fields accepted by `write`; anything else is rejected so a declaration cannot smuggle state. */
|
|
22
|
+
const writeFields = [
|
|
23
|
+
'name',
|
|
24
|
+
'kind',
|
|
25
|
+
'parentStepId',
|
|
26
|
+
'relatedDefinitionId',
|
|
27
|
+
'status',
|
|
28
|
+
'usedModel',
|
|
29
|
+
'startedAtMs',
|
|
30
|
+
'endedAtMs',
|
|
31
|
+
'nextStepIds',
|
|
32
|
+
'caseId',
|
|
33
|
+
'summary',
|
|
34
|
+
'payload',
|
|
35
|
+
];
|
|
36
|
+
/** Fields accepted by `fix`: identity and creation data are intentionally not patchable. */
|
|
37
|
+
const fixFields = [
|
|
38
|
+
'status',
|
|
39
|
+
'usedModel',
|
|
40
|
+
'startedAtMs',
|
|
41
|
+
'endedAtMs',
|
|
42
|
+
'summary',
|
|
43
|
+
'payload',
|
|
44
|
+
'nextStepIds',
|
|
45
|
+
];
|
|
46
|
+
/** Per-field character caps, bounding what one reported step can add to a persisted record. */
|
|
47
|
+
const textLimits = {
|
|
48
|
+
name: 256,
|
|
49
|
+
kind: 128,
|
|
50
|
+
parentStepId: 256,
|
|
51
|
+
relatedDefinitionId: 256,
|
|
52
|
+
caseId: 256,
|
|
53
|
+
summary: 1024,
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Validate a step input: plain prototype, whitelisted keys, own data properties only.
|
|
57
|
+
*
|
|
58
|
+
* Property descriptors are inspected instead of values being read, so an accessor on the input
|
|
59
|
+
* cannot execute application code during validation.
|
|
60
|
+
*/
|
|
8
61
|
function fields(input, allowed) {
|
|
9
62
|
breakWhile(!input || Object.getPrototypeOf(input) !== Object.prototype, () => new TypeError('Sub-flow input must be a plain parameter object'));
|
|
10
|
-
breakWhile(Reflect.ownKeys(input).some(key => typeof key !== 'string' || !allowed.includes(key)), () => new TypeError('Unknown sub-flow field'));
|
|
63
|
+
breakWhile(Reflect.ownKeys(input).some((key) => typeof key !== 'string' || !allowed.includes(key)), () => new TypeError('Unknown sub-flow field'));
|
|
11
64
|
for (const key of Reflect.ownKeys(input))
|
|
12
|
-
breakWhile(!['payload', 'summary'].includes(String(key)) &&
|
|
65
|
+
breakWhile(!['payload', 'summary'].includes(String(key)) &&
|
|
66
|
+
!('value' in Object.getOwnPropertyDescriptor(input, key)), () => new TypeError('Sub-flow metadata must be plain data'));
|
|
13
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Check a fully built step: text caps, status vocabulary, time ordering, and the rules tying
|
|
70
|
+
* timestamps to planned and terminal statuses.
|
|
71
|
+
*/
|
|
14
72
|
function validate(step) {
|
|
15
73
|
for (const [key, limit] of Object.entries(textLimits)) {
|
|
16
74
|
const value = step[key];
|
|
@@ -20,15 +78,33 @@ function validate(step) {
|
|
|
20
78
|
breakWhile(step.usedModel !== undefined && typeof step.usedModel !== 'boolean', () => new TypeError('Invalid sub-flow usedModel'));
|
|
21
79
|
for (const time of [step.startedAtMs, step.endedAtMs])
|
|
22
80
|
breakWhile(time !== undefined && (!Number.isFinite(time) || time < 0), () => new TypeError('Invalid sub-flow time'));
|
|
23
|
-
breakWhile(step.startedAtMs !== undefined &&
|
|
81
|
+
breakWhile(step.startedAtMs !== undefined &&
|
|
82
|
+
step.endedAtMs !== undefined &&
|
|
83
|
+
step.endedAtMs < step.startedAtMs, () => new TypeError('Invalid sub-flow time order'));
|
|
24
84
|
breakWhile(step.endedAtMs !== undefined && !reportedStepStatusCatalog[step.status].terminal, () => new TypeError('Only terminal sub-flow steps have an end time'));
|
|
25
85
|
breakWhile(['planned', 'skipped'].includes(step.status) && step.startedAtMs !== undefined, () => new TypeError('A planned or skipped sub-flow step has not started'));
|
|
26
|
-
breakWhile(step.nextStepIds !== undefined &&
|
|
27
|
-
|
|
86
|
+
breakWhile(step.nextStepIds !== undefined &&
|
|
87
|
+
(!Array.isArray(step.nextStepIds) ||
|
|
88
|
+
step.nextStepIds.length > 64 ||
|
|
89
|
+
new Set(step.nextStepIds).size !== step.nextStepIds.length ||
|
|
90
|
+
step.nextStepIds.some((id) => typeof id !== 'string' || !id.trim() || id.length > 256)), () => new TypeError('Invalid sub-flow successors'));
|
|
28
91
|
}
|
|
29
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Validate and deep-copy a reported payload.
|
|
94
|
+
*
|
|
95
|
+
* Accessors, class instances, cycles and non-JSON values are rejected without evaluating
|
|
96
|
+
* application getters, so a payload can neither run code nor alias live state. Accepted data is
|
|
97
|
+
* frozen.
|
|
98
|
+
*
|
|
99
|
+
* @param input Object to snapshot. It must be a plain object, not an array.
|
|
100
|
+
* @returns A deeply frozen JSON-shaped copy.
|
|
101
|
+
* @throws TypeError when the value is not plain JSON data, contains a getter, or is cyclic.
|
|
102
|
+
* @throws RangeError when node count, nesting depth, string length or array length exceeds the
|
|
103
|
+
* limits below.
|
|
104
|
+
*/
|
|
30
105
|
export function payloadSnapshot(input) {
|
|
31
106
|
let nodes = 0;
|
|
107
|
+
// Ancestors rather than all visited nodes: a shared subtree is fine, a cycle is not.
|
|
32
108
|
const ancestors = new Set();
|
|
33
109
|
const copy = (value, depth) => {
|
|
34
110
|
breakWhile(++nodes > 4096 || depth > 16, () => new RangeError('Sub-flow payload is too complex'));
|
|
@@ -37,7 +113,11 @@ export function payloadSnapshot(input) {
|
|
|
37
113
|
return value;
|
|
38
114
|
if (typeof value === 'number' && Number.isFinite(value))
|
|
39
115
|
return value;
|
|
40
|
-
breakWhile(!value ||
|
|
116
|
+
breakWhile(!value ||
|
|
117
|
+
typeof value !== 'object' ||
|
|
118
|
+
(typeof value === 'object' && value !== null && ancestors.has(value)) ||
|
|
119
|
+
// Only plain objects survive: a class instance may hide lazy state behind getters.
|
|
120
|
+
(!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype), () => new TypeError('Sub-flow payload must contain JSON data'));
|
|
41
121
|
breakWhile(Array.isArray(value) && value.length > 4096, () => new RangeError('Sub-flow payload array is too large'));
|
|
42
122
|
const data = value;
|
|
43
123
|
ancestors.add(data);
|
|
@@ -46,21 +126,43 @@ export function payloadSnapshot(input) {
|
|
|
46
126
|
if (Array.isArray(value) && key === 'length')
|
|
47
127
|
continue;
|
|
48
128
|
const field = Object.getOwnPropertyDescriptor(value, key);
|
|
49
|
-
breakWhile(typeof key !== 'string' ||
|
|
129
|
+
breakWhile(typeof key !== 'string' ||
|
|
130
|
+
!('value' in field) ||
|
|
131
|
+
!field.enumerable ||
|
|
132
|
+
// Array keys must be canonical indices; extra or sparse keys cannot survive JSON.
|
|
133
|
+
(Array.isArray(value) && !/^(0|[1-9]\d*)$/.test(key)), () => new TypeError('Sub-flow payload must contain plain data fields'));
|
|
50
134
|
Object.defineProperty(result, key, { value: copy(field.value, depth + 1), enumerable: true });
|
|
51
135
|
}
|
|
52
136
|
ancestors.delete(data);
|
|
53
|
-
return Array.isArray(value)
|
|
137
|
+
return Array.isArray(value)
|
|
138
|
+
? Object.freeze(Array.from({ length: value.length }, (_, i) => result[i] ?? null))
|
|
139
|
+
: Object.freeze(result);
|
|
54
140
|
};
|
|
55
141
|
breakWhile(!input || Array.isArray(input) || Object.getPrototypeOf(input) !== Object.prototype, () => new TypeError('Sub-flow payload must be an object'));
|
|
56
142
|
return copy(input, 0);
|
|
57
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Merge a payload patch into a recorded payload without replacing recorded facts.
|
|
146
|
+
*
|
|
147
|
+
* Nested objects merge recursively; an existing leaf must keep its value. A mismatch is
|
|
148
|
+
* rejected rather than overwritten, because a fix may add results but not rewrite history.
|
|
149
|
+
*/
|
|
58
150
|
function fill(previous, patch) {
|
|
59
151
|
const result = { ...previous };
|
|
60
152
|
for (const [key, value] of Object.entries(patch)) {
|
|
61
153
|
if (!Object.hasOwn(previous, key))
|
|
62
|
-
Object.defineProperty(result, key, {
|
|
63
|
-
|
|
154
|
+
Object.defineProperty(result, key, {
|
|
155
|
+
value,
|
|
156
|
+
enumerable: true,
|
|
157
|
+
configurable: true,
|
|
158
|
+
writable: true,
|
|
159
|
+
});
|
|
160
|
+
else if (value &&
|
|
161
|
+
previous[key] &&
|
|
162
|
+
typeof value === 'object' &&
|
|
163
|
+
typeof previous[key] === 'object' &&
|
|
164
|
+
!Array.isArray(value) &&
|
|
165
|
+
!Array.isArray(previous[key])) {
|
|
64
166
|
result[key] = fill(previous[key], value);
|
|
65
167
|
}
|
|
66
168
|
else
|
|
@@ -68,87 +170,185 @@ function fill(previous, patch) {
|
|
|
68
170
|
}
|
|
69
171
|
return Object.freeze(result);
|
|
70
172
|
}
|
|
71
|
-
/**
|
|
173
|
+
/**
|
|
174
|
+
* Create a logger bound to one active execution visit.
|
|
175
|
+
*
|
|
176
|
+
* Only execution contexts inside this package should call it: the resulting object is the sole
|
|
177
|
+
* way to append reported steps to the current record.
|
|
178
|
+
*
|
|
179
|
+
* @param owner Object that owns the visit. `readSubFlowLogger` compares this identity before
|
|
180
|
+
* returning any step.
|
|
181
|
+
* @param active Reports whether the visit is still open; a closed logger rejects writes.
|
|
182
|
+
* @param content Reports whether content-level detail is enabled. When false, summaries and
|
|
183
|
+
* payloads are dropped before anything is stored.
|
|
184
|
+
* @param changed Called after each accepted write or fix with the progress delta to publish.
|
|
185
|
+
* @param identity Diagnostic run and span the logger belongs to; used to reject cross-scope reads.
|
|
186
|
+
* @returns A frozen logger instance.
|
|
187
|
+
*/
|
|
72
188
|
export function createSubFlowLogger(owner, active, content, changed, identity) {
|
|
73
189
|
class Logger {
|
|
74
190
|
#steps = Object.freeze([]);
|
|
75
191
|
#changes = 0;
|
|
76
|
-
constructor() {
|
|
77
|
-
|
|
192
|
+
constructor() {
|
|
193
|
+
instances.set(this, { owner, identity, read: () => this.#steps });
|
|
194
|
+
Object.freeze(this);
|
|
195
|
+
}
|
|
196
|
+
#assertActive() {
|
|
197
|
+
// A logger that outlived its execution would append evidence to a finished request.
|
|
198
|
+
breakWhile(!active(), () => new TypeError('Sub-flow logger belongs to a closed execution'));
|
|
199
|
+
}
|
|
78
200
|
#save(step, operation) {
|
|
79
201
|
this.#assertActive();
|
|
80
|
-
|
|
81
|
-
|
|
202
|
+
// A fix replaces the step with the same id in place; a write always appends.
|
|
203
|
+
const next = operation === 'write'
|
|
204
|
+
? [...this.#steps, step]
|
|
205
|
+
: this.#steps.map((item) => (item.stepId === step.stepId ? step : item));
|
|
206
|
+
// Successors must resolve inside this logger, otherwise the recorded graph would have
|
|
207
|
+
// dangling edges.
|
|
208
|
+
breakWhile(step.nextStepIds?.some((id) => !next.some((item) => item.stepId === id)), () => new TypeError('Sub-flow successors must belong to this logger'));
|
|
209
|
+
// The step and size caps equal the persisted-record limits; the change cap bounds
|
|
210
|
+
// write/fix churn even when the final step count stays small.
|
|
82
211
|
breakWhile(next.length > 256 || this.#changes >= 1024 || JSON.stringify(next).length > 65536, () => new RangeError('Sub-flow log limit exceeded'));
|
|
83
212
|
this.#steps = Object.freeze(next);
|
|
84
213
|
this.#changes++;
|
|
85
|
-
changed(this, {
|
|
214
|
+
changed(this, {
|
|
215
|
+
operation,
|
|
216
|
+
stepId: step.stepId,
|
|
217
|
+
sequence: step.sequence,
|
|
218
|
+
revision: step.revision,
|
|
219
|
+
createdAtMs: step.createdAtMs,
|
|
220
|
+
status: step.status,
|
|
221
|
+
...(step.usedModel === undefined ? {} : { usedModel: step.usedModel }),
|
|
222
|
+
});
|
|
86
223
|
}
|
|
87
224
|
write(input) {
|
|
88
225
|
this.#assertActive();
|
|
89
226
|
fields(input, writeFields);
|
|
90
227
|
breakWhile(input.nextStepIds !== undefined && !Array.isArray(input.nextStepIds), () => new TypeError('Invalid sub-flow successors'));
|
|
91
228
|
const now = Date.now(), status = input.status === undefined ? 'planned' : input.status;
|
|
92
|
-
|
|
93
|
-
|
|
229
|
+
// Timestamps are derived from the status: a running or terminal step gets a start time,
|
|
230
|
+
// a terminal step also an end time, using the caller's value when one is supplied.
|
|
231
|
+
const step = {
|
|
232
|
+
origin: 'reported',
|
|
233
|
+
stepId: invocationId(),
|
|
234
|
+
sequence: this.#steps.length + 1,
|
|
235
|
+
revision: 1,
|
|
236
|
+
createdAtMs: now,
|
|
237
|
+
name: input.name,
|
|
238
|
+
kind: input.kind,
|
|
239
|
+
status,
|
|
94
240
|
...(input.parentStepId === undefined ? {} : { parentStepId: input.parentStepId }),
|
|
95
|
-
...(input.relatedDefinitionId === undefined
|
|
241
|
+
...(input.relatedDefinitionId === undefined
|
|
242
|
+
? {}
|
|
243
|
+
: { relatedDefinitionId: input.relatedDefinitionId }),
|
|
96
244
|
...(input.caseId === undefined ? {} : { caseId: input.caseId }),
|
|
97
245
|
...(input.usedModel === undefined ? {} : { usedModel: input.usedModel }),
|
|
98
|
-
...(input.startedAtMs === undefined && status !== 'running'
|
|
99
|
-
|
|
100
|
-
|
|
246
|
+
...(input.startedAtMs === undefined && status !== 'running'
|
|
247
|
+
? {}
|
|
248
|
+
: { startedAtMs: input.startedAtMs ?? now }),
|
|
249
|
+
...(input.endedAtMs === undefined && !reportedStepStatusCatalog[status]?.terminal
|
|
250
|
+
? {}
|
|
251
|
+
: { endedAtMs: input.endedAtMs ?? now }),
|
|
252
|
+
...(input.nextStepIds === undefined
|
|
253
|
+
? {}
|
|
254
|
+
: { nextStepIds: Object.freeze([...input.nextStepIds]) }),
|
|
101
255
|
};
|
|
102
256
|
if (content()) {
|
|
257
|
+
// Summaries and payloads are omitted entirely when content logging is off, so a
|
|
258
|
+
// metadata-only consumer never receives them.
|
|
103
259
|
if (input.summary !== undefined)
|
|
104
260
|
Object.assign(step, { summary: input.summary });
|
|
105
261
|
if (input.payload !== undefined)
|
|
106
262
|
Object.assign(step, { payload: payloadSnapshot(input.payload) });
|
|
107
263
|
}
|
|
108
264
|
validate(step);
|
|
109
|
-
breakWhile(step.parentStepId && !this.#steps.some(item => item.stepId === step.parentStepId), () => new TypeError('Sub-flow parent must belong to this logger'));
|
|
265
|
+
breakWhile(step.parentStepId && !this.#steps.some((item) => item.stepId === step.parentStepId), () => new TypeError('Sub-flow parent must belong to this logger'));
|
|
110
266
|
this.#save(Object.freeze(step), 'write');
|
|
111
267
|
return step.stepId;
|
|
112
268
|
}
|
|
113
269
|
fix(stepId, patch) {
|
|
114
270
|
this.#assertActive();
|
|
115
271
|
fields(patch, fixFields);
|
|
116
|
-
const previous = this.#steps.find(step => step.stepId === stepId);
|
|
272
|
+
const previous = this.#steps.find((step) => step.stepId === stepId);
|
|
273
|
+
// The assertion above only satisfies the type checker; this check rejects an unknown id.
|
|
117
274
|
breakWhile(!previous, () => new TypeError('Unknown sub-flow step'));
|
|
118
275
|
const terminal = reportedStepStatusCatalog[previous.status].terminal;
|
|
276
|
+
// A terminal step is sealed: its outcome, model use and timestamps cannot be rewritten.
|
|
119
277
|
breakWhile(terminal && patch.status !== undefined && patch.status !== previous.status, () => new TypeError('Terminal sub-flow status is sealed'));
|
|
120
|
-
breakWhile(terminal &&
|
|
278
|
+
breakWhile(terminal &&
|
|
279
|
+
previous.usedModel !== undefined &&
|
|
280
|
+
patch.usedModel !== undefined &&
|
|
281
|
+
previous.usedModel !== patch.usedModel, () => new TypeError('Terminal sub-flow model use is sealed'));
|
|
121
282
|
breakWhile(previous.usedModel === true && patch.usedModel === false, () => new TypeError('Cannot undo reported model use'));
|
|
122
|
-
breakWhile(patch.status !== undefined &&
|
|
283
|
+
breakWhile(patch.status !== undefined &&
|
|
284
|
+
patch.status !== previous.status &&
|
|
285
|
+
// Transitions are catalog-driven; a terminal status has no successors at all.
|
|
286
|
+
!reportedStepStatusCatalog[previous.status].next.includes(patch.status), () => new TypeError('Invalid sub-flow status transition'));
|
|
123
287
|
for (const key of ['startedAtMs', 'endedAtMs'])
|
|
124
288
|
breakWhile(previous[key] !== undefined && patch[key] !== undefined && patch[key] !== previous[key], () => new TypeError('Cannot overwrite a sub-flow time'));
|
|
125
289
|
const status = patch.status ?? previous.status;
|
|
126
|
-
breakWhile(patch.nextStepIds !== undefined &&
|
|
127
|
-
|
|
128
|
-
|
|
290
|
+
breakWhile(patch.nextStepIds !== undefined &&
|
|
291
|
+
(!Array.isArray(patch.nextStepIds) ||
|
|
292
|
+
(previous.nextStepIds !== undefined &&
|
|
293
|
+
JSON.stringify(previous.nextStepIds) !== JSON.stringify(patch.nextStepIds))), () => new TypeError('Cannot overwrite sub-flow successors'));
|
|
294
|
+
// A start time is auto-stamped only when the step becomes running and had none; an end
|
|
295
|
+
// time is added once the status becomes terminal.
|
|
296
|
+
const step = {
|
|
297
|
+
...previous,
|
|
298
|
+
revision: previous.revision + 1,
|
|
299
|
+
status,
|
|
300
|
+
...(patch.nextStepIds === undefined
|
|
301
|
+
? {}
|
|
302
|
+
: { nextStepIds: Object.freeze([...patch.nextStepIds]) }),
|
|
129
303
|
...(patch.usedModel === undefined ? {} : { usedModel: patch.usedModel }),
|
|
130
|
-
...(patch.startedAtMs === undefined &&
|
|
131
|
-
|
|
304
|
+
...(patch.startedAtMs === undefined &&
|
|
305
|
+
!(status === 'running' && previous.startedAtMs === undefined)
|
|
306
|
+
? {}
|
|
307
|
+
: { startedAtMs: patch.startedAtMs ?? Date.now() }),
|
|
308
|
+
...(patch.endedAtMs === undefined &&
|
|
309
|
+
(!reportedStepStatusCatalog[status]?.terminal || previous.endedAtMs !== undefined)
|
|
310
|
+
? {}
|
|
311
|
+
: { endedAtMs: patch.endedAtMs ?? Date.now() }),
|
|
132
312
|
};
|
|
133
313
|
if (content()) {
|
|
314
|
+
// A fix may add a summary once and fill missing payload fields, but it cannot replace
|
|
315
|
+
// a summary or a recorded payload value.
|
|
134
316
|
if (patch.summary !== undefined) {
|
|
135
317
|
breakWhile(previous.summary !== undefined && previous.summary !== patch.summary, () => new TypeError('Cannot overwrite a sub-flow summary'));
|
|
136
318
|
Object.assign(step, { summary: patch.summary });
|
|
137
319
|
}
|
|
138
320
|
if (patch.payload !== undefined)
|
|
139
|
-
Object.assign(step, {
|
|
321
|
+
Object.assign(step, {
|
|
322
|
+
payload: fill(previous.payload ?? {}, payloadSnapshot(patch.payload)),
|
|
323
|
+
});
|
|
140
324
|
}
|
|
141
325
|
validate(step);
|
|
142
326
|
this.#save(Object.freeze(step), 'fix');
|
|
143
327
|
}
|
|
144
|
-
readAll() {
|
|
328
|
+
readAll() {
|
|
329
|
+
return this.#steps;
|
|
330
|
+
}
|
|
145
331
|
}
|
|
146
332
|
return new Logger();
|
|
147
333
|
}
|
|
148
|
-
/**
|
|
334
|
+
/**
|
|
335
|
+
* Read the steps recorded by a logger issued by this module.
|
|
336
|
+
*
|
|
337
|
+
* The instance is resolved through the private registry, so a lookalike's `readAll` method is
|
|
338
|
+
* never called and a logger cannot be borrowed across executions.
|
|
339
|
+
*
|
|
340
|
+
* @param input Candidate logger; must be an instance created by `createSubFlowLogger`.
|
|
341
|
+
* @param owner Expected owning execution visit. Omit to accept any owner.
|
|
342
|
+
* @param identity Expected run and span. Omit to accept any diagnostic scope.
|
|
343
|
+
* @returns The recorded steps in write order, as an immutable list shared with the logger.
|
|
344
|
+
* @throws TypeError when the value is not a registered logger, belongs to another owner, or
|
|
345
|
+
* belongs to another diagnostic scope.
|
|
346
|
+
*/
|
|
149
347
|
export function readSubFlowLogger(input, owner, identity) {
|
|
150
348
|
const instance = input && typeof input === 'object' ? instances.get(input) : undefined;
|
|
151
|
-
breakWhile(!instance || (owner !== undefined && owner !== instance.owner), () => new TypeError(
|
|
152
|
-
breakWhile(identity &&
|
|
349
|
+
breakWhile(!instance || (owner !== undefined && owner !== instance.owner), () => new TypeError("Expected this execution's SubFlowLogger instance"));
|
|
350
|
+
breakWhile(identity &&
|
|
351
|
+
(instance.identity?.runId !== identity.runId ||
|
|
352
|
+
instance.identity?.spanId !== identity.spanId), () => new TypeError('Sub-flow logger belongs to another diagnostic scope'));
|
|
153
353
|
return instance.read();
|
|
154
354
|
}
|
package/dist/esm/errors.d.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import type { AgentErrorInfo, ErrorContext } from './structs/errors.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Attach boundary metadata to a thrown value without changing that value.
|
|
4
|
+
*
|
|
5
|
+
* The earliest recorded stage stays authoritative on re-throw, so a failure is attributed
|
|
6
|
+
* to the stage that first caught it rather than to the boundary that merely relays it.
|
|
7
|
+
* Codes and retryability may still be filled in by an outer boundary that knows more.
|
|
8
|
+
*
|
|
9
|
+
* @param error Value being propagated. Non-object values are ignored: identity is tracked
|
|
10
|
+
* by reference, so primitives cannot carry annotations.
|
|
11
|
+
* @param context Boundary annotations to merge into the existing entry, if any.
|
|
12
|
+
* @returns The same reference, allowing `throw recordErrorContext(error, ctx)`.
|
|
13
|
+
*/
|
|
3
14
|
export declare function recordErrorContext(error: unknown, context: ErrorContext): unknown;
|
|
4
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Produce a frozen diagnostic view of any thrown value.
|
|
17
|
+
*
|
|
18
|
+
* Inspection is guarded: an exotic error (revoked proxy, throwing getter, null prototype)
|
|
19
|
+
* degrades to `UNKNOWN_ERROR` instead of raising a second failure while handling the first.
|
|
20
|
+
*
|
|
21
|
+
* @param error Any thrown value, including non-Error values such as strings.
|
|
22
|
+
* @returns Frozen info. `codes` lists every known code with the primary one first; optional
|
|
23
|
+
* fields are omitted rather than emitted as `undefined`. `cause` is the original value.
|
|
24
|
+
*/
|
|
5
25
|
export declare function getErrorInfo(error: unknown): AgentErrorInfo;
|
package/dist/esm/errors.js
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error metadata boundary: records which execution stage produced a failure and exposes a
|
|
3
|
+
* stable, read-only view of it for diagnostics.
|
|
4
|
+
*
|
|
5
|
+
* The original thrown value is never wrapped or replaced, so App code keeps its own error
|
|
6
|
+
* identity and stack. Annotations live in a side table keyed by reference, which works for
|
|
7
|
+
* frozen Errors and DOMException instances whose properties cannot be added.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `recordErrorContext` (annotate at a boundary) and `getErrorInfo` (inspect).
|
|
10
|
+
*/
|
|
1
11
|
import { BudgetError, ValidationError } from './structs/errors.js';
|
|
2
12
|
// Side metadata preserves App error identity, including frozen Errors and DOMException.
|
|
3
13
|
const contexts = new WeakMap();
|
|
4
14
|
const reference = (value) => value !== null && (typeof value === 'object' || typeof value === 'function');
|
|
5
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Attach boundary metadata to a thrown value without changing that value.
|
|
17
|
+
*
|
|
18
|
+
* The earliest recorded stage stays authoritative on re-throw, so a failure is attributed
|
|
19
|
+
* to the stage that first caught it rather than to the boundary that merely relays it.
|
|
20
|
+
* Codes and retryability may still be filled in by an outer boundary that knows more.
|
|
21
|
+
*
|
|
22
|
+
* @param error Value being propagated. Non-object values are ignored: identity is tracked
|
|
23
|
+
* by reference, so primitives cannot carry annotations.
|
|
24
|
+
* @param context Boundary annotations to merge into the existing entry, if any.
|
|
25
|
+
* @returns The same reference, allowing `throw recordErrorContext(error, ctx)`.
|
|
26
|
+
*/
|
|
6
27
|
export function recordErrorContext(error, context) {
|
|
7
28
|
if (reference(error)) {
|
|
8
29
|
const previous = contexts.get(error);
|
|
@@ -11,34 +32,86 @@ export function recordErrorContext(error, context) {
|
|
|
11
32
|
}
|
|
12
33
|
return error;
|
|
13
34
|
}
|
|
14
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Read classification metadata from an arbitrary thrown value.
|
|
37
|
+
*
|
|
38
|
+
* Returns normalized issues plus a primary code. `isRetryable` is left undefined when the
|
|
39
|
+
* error neither states it nor makes a final classification, so callers do not mistake
|
|
40
|
+
* "unknown" for "retryable".
|
|
41
|
+
*/
|
|
15
42
|
function inspectError(error) {
|
|
16
|
-
const source = reference(error)
|
|
43
|
+
const source = reference(error)
|
|
44
|
+
? error
|
|
45
|
+
: {};
|
|
17
46
|
const reportedIssues = source.issues;
|
|
47
|
+
// Structured issues win over the older `errors` array, so an error carrying both is not
|
|
48
|
+
// reported twice. Only the array shape is accepted; any other value falls through.
|
|
18
49
|
const reportedErrors = Array.isArray(reportedIssues) ? undefined : source.errors;
|
|
19
|
-
const raw = Array.isArray(reportedIssues)
|
|
20
|
-
|
|
50
|
+
const raw = Array.isArray(reportedIssues)
|
|
51
|
+
? reportedIssues
|
|
52
|
+
: Array.isArray(reportedErrors)
|
|
53
|
+
? reportedErrors
|
|
54
|
+
: [];
|
|
55
|
+
const issues = raw.flatMap((value) => {
|
|
21
56
|
if (!value || typeof value !== 'object')
|
|
22
57
|
return [];
|
|
23
58
|
const { code, message, path: reportedPath, checkId } = value;
|
|
24
59
|
if (typeof code !== 'string')
|
|
25
60
|
return [];
|
|
26
|
-
const pathItems = typeof reportedPath === 'string'
|
|
27
|
-
|
|
28
|
-
|
|
61
|
+
const pathItems = typeof reportedPath === 'string'
|
|
62
|
+
? [reportedPath]
|
|
63
|
+
: Array.isArray(reportedPath)
|
|
64
|
+
? Array.from(reportedPath)
|
|
65
|
+
: undefined;
|
|
66
|
+
const path = pathItems?.every((part) => typeof part === 'string' || typeof part === 'number')
|
|
67
|
+
? pathItems
|
|
68
|
+
: undefined;
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
code,
|
|
72
|
+
message: typeof message === 'string' ? message : code,
|
|
29
73
|
...(path === undefined ? {} : { path: Object.freeze(path) }),
|
|
30
|
-
...(typeof checkId === 'string' ? { checkId } : {})
|
|
74
|
+
...(typeof checkId === 'string' ? { checkId } : {}),
|
|
75
|
+
},
|
|
76
|
+
];
|
|
31
77
|
});
|
|
32
78
|
const code = source.code;
|
|
79
|
+
// A string `code` or a structured issue is already a usable classification, so the error
|
|
80
|
+
// `name` is only consulted as a last resort.
|
|
33
81
|
const name = typeof code === 'string' || issues.length ? undefined : source.name;
|
|
34
|
-
|
|
35
|
-
|
|
82
|
+
// DOMException exposes cancellation through `name` rather than `code`; the mapping keeps
|
|
83
|
+
// cancellation and timeout distinguishable from genuine failures.
|
|
84
|
+
const fallback = typeof code === 'string'
|
|
85
|
+
? code
|
|
86
|
+
: (issues[0]?.code ??
|
|
87
|
+
(name === 'AbortError'
|
|
88
|
+
? 'CANCELLED'
|
|
89
|
+
: name === 'TimeoutError'
|
|
90
|
+
? 'TIMEOUT'
|
|
91
|
+
: 'UNKNOWN_ERROR'));
|
|
36
92
|
const retryable = source.isRetryable;
|
|
37
|
-
|
|
38
|
-
|
|
93
|
+
// Retryability stays unknown unless the error reports it or it is provably final:
|
|
94
|
+
// budget, validation, issue-bearing and cancellation failures must not be retried.
|
|
95
|
+
const isRetryable = typeof retryable === 'boolean'
|
|
96
|
+
? retryable
|
|
97
|
+
: error instanceof BudgetError ||
|
|
98
|
+
error instanceof ValidationError ||
|
|
99
|
+
issues.length ||
|
|
100
|
+
['CANCELLED', 'TIMEOUT', 'BUDGET'].includes(fallback)
|
|
101
|
+
? false
|
|
102
|
+
: undefined;
|
|
39
103
|
return { code: fallback, issues, isRetryable };
|
|
40
104
|
}
|
|
41
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* Produce a frozen diagnostic view of any thrown value.
|
|
107
|
+
*
|
|
108
|
+
* Inspection is guarded: an exotic error (revoked proxy, throwing getter, null prototype)
|
|
109
|
+
* degrades to `UNKNOWN_ERROR` instead of raising a second failure while handling the first.
|
|
110
|
+
*
|
|
111
|
+
* @param error Any thrown value, including non-Error values such as strings.
|
|
112
|
+
* @returns Frozen info. `codes` lists every known code with the primary one first; optional
|
|
113
|
+
* fields are omitted rather than emitted as `undefined`. `cause` is the original value.
|
|
114
|
+
*/
|
|
42
115
|
export function getErrorInfo(error) {
|
|
43
116
|
const context = reference(error) ? contexts.get(error) : undefined;
|
|
44
117
|
let view;
|
|
@@ -49,9 +122,18 @@ export function getErrorInfo(error) {
|
|
|
49
122
|
view = { code: 'UNKNOWN_ERROR', issues: [] };
|
|
50
123
|
}
|
|
51
124
|
const { code: fallback, issues } = view;
|
|
52
|
-
|
|
125
|
+
// Recorded codes describe the boundary where the error was first captured and outrank
|
|
126
|
+
// codes inferred from the current shape, which may already have been flattened.
|
|
127
|
+
const codes = Object.freeze([
|
|
128
|
+
...(context?.codes ?? (issues.length ? issues.map((issue) => issue.code) : [fallback])),
|
|
129
|
+
]);
|
|
53
130
|
const isRetryable = context?.isRetryable ?? view.isRetryable;
|
|
54
|
-
return Object.freeze({
|
|
131
|
+
return Object.freeze({
|
|
132
|
+
code: codes[0] ?? fallback,
|
|
133
|
+
codes,
|
|
134
|
+
issues: Object.freeze(issues.map((issue) => Object.freeze(issue))),
|
|
55
135
|
...(context?.stageId === undefined ? {} : { stageId: context.stageId }),
|
|
56
|
-
...(isRetryable === undefined ? {} : { isRetryable }),
|
|
136
|
+
...(isRetryable === undefined ? {} : { isRetryable }),
|
|
137
|
+
cause: error,
|
|
138
|
+
});
|
|
57
139
|
}
|