@jangts/agent-core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +59 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -0
- package/development/docs/assets/agent-core-icon.png +0 -0
- package/development/docs/assets/agent-core-logo.png +0 -0
- package/development/docs/assets/character-agent-core.png +0 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +11 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +32 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +102 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.js +11 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +38 -0
- package/dist/esm/structs/kits/search.d.ts +22 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +30 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +52 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +49 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +145 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +32 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +10 -0
- package/dist/esm/support/model/completion/default.js +29 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +11 -0
- package/dist/esm/support/model/completion/session.js +99 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +20 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +15 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +24 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +23 -3
|
@@ -13,6 +13,19 @@ exports.validateReductionTargets = validateReductionTargets;
|
|
|
13
13
|
exports.beginContextProcessing = beginContextProcessing;
|
|
14
14
|
exports.finishContextProcessing = finishContextProcessing;
|
|
15
15
|
exports.processContext = processContext;
|
|
16
|
+
/**
|
|
17
|
+
* Context processing engine: validate, select, apply and audit context reductions.
|
|
18
|
+
*
|
|
19
|
+
* A processing state snapshots the plan once, then reductions mutate working fragments until the
|
|
20
|
+
* target size is met. Core guarantees (fragment trust, character/token budgets, structural audit
|
|
21
|
+
* and cancellation) are enforced here; application code supplies policies, handlers and selection
|
|
22
|
+
* strategies. Each mode and reduction kind is a registered entry, so validation and execution
|
|
23
|
+
* cannot diverge.
|
|
24
|
+
*
|
|
25
|
+
* Main exports: `processContext` (complete run), `beginContextProcessing` /
|
|
26
|
+
* `finishContextProcessing` (staged runs), the policy/reduction catalogs and the individual
|
|
27
|
+
* validation, measurement and reduction helpers used by workflow nodes.
|
|
28
|
+
*/
|
|
16
29
|
const snapshot_js_1 = require("./snapshot.js");
|
|
17
30
|
const audit_js_1 = require("../../context/audit.js");
|
|
18
31
|
const history_js_1 = require("./history.js");
|
|
@@ -23,17 +36,37 @@ const errors_js_1 = require("../../structs/errors.js");
|
|
|
23
36
|
const rules_js_1 = require("../../utils/rules.js");
|
|
24
37
|
const cancellation_js_1 = require("../../utils/cancellation.js");
|
|
25
38
|
const fail = (message) => new errors_js_1.ValidationError([{ code: 'CONTEXT_POLICY', message }]);
|
|
26
|
-
|
|
39
|
+
// Structured values are measured by their serialized length, matching the character budget that
|
|
40
|
+
// assembly later enforces.
|
|
41
|
+
const size = (fragment) => typeof fragment.value === 'string'
|
|
42
|
+
? fragment.value.length
|
|
43
|
+
: JSON.stringify(fragment.value).length;
|
|
27
44
|
const positive = (value) => Number.isSafeInteger(value) && value > 0;
|
|
28
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Validate a complete context policy and every handler it can reference.
|
|
47
|
+
*
|
|
48
|
+
* Handler IDs must be unique and each handler must declare a non-negative integer call ceiling.
|
|
49
|
+
* Reduction targets and selection modes are checked by their own catalog entries.
|
|
50
|
+
*
|
|
51
|
+
* @param policy Policy to validate; the mode must be one of the registered modes.
|
|
52
|
+
* @param compressors Compressors available to compression steps.
|
|
53
|
+
* @param selectors Selectors available to model-driven selection.
|
|
54
|
+
* @throws {ValidationError} When a handler, mode, reduction step or selection declaration is
|
|
55
|
+
* invalid or references something unregistered.
|
|
56
|
+
*/
|
|
29
57
|
function validateContextPolicy(policy, compressors, selectors = []) {
|
|
30
58
|
const handlers = new Set();
|
|
31
59
|
for (const handler of compressors) {
|
|
32
|
-
(0, rules_js_1.breakWhile)(!handler.id ||
|
|
33
|
-
|
|
60
|
+
(0, rules_js_1.breakWhile)(!handler.id ||
|
|
61
|
+
handlers.has(handler.id) ||
|
|
62
|
+
typeof handler.compress !== 'function' ||
|
|
63
|
+
!Number.isSafeInteger((0, selection_policy_js_1.contextHandlerCalls)(handler)) ||
|
|
64
|
+
(0, selection_policy_js_1.contextHandlerCalls)(handler) < 0, fail('Invalid context compressor'));
|
|
34
65
|
handlers.add(handler.id);
|
|
35
66
|
}
|
|
36
|
-
const mode = Object.hasOwn(exports.contextPolicyCatalog, policy.mode)
|
|
67
|
+
const mode = Object.hasOwn(exports.contextPolicyCatalog, policy.mode)
|
|
68
|
+
? exports.contextPolicyCatalog[policy.mode]
|
|
69
|
+
: undefined;
|
|
37
70
|
(0, rules_js_1.breakWhile)(!mode, fail('Unknown context processing mode'));
|
|
38
71
|
mode.validate(policy, handlers);
|
|
39
72
|
if (policy.mode === 'reduce')
|
|
@@ -45,13 +78,19 @@ function validateCorePolicy(policy, handlers) {
|
|
|
45
78
|
(0, rules_js_1.breakWhile)(policy.triggerChars !== undefined && !positive(policy.triggerChars), fail('Invalid context trigger'));
|
|
46
79
|
for (const value of [policy.targetInputChars, policy.triggerTokens, policy.targetInputTokens])
|
|
47
80
|
(0, rules_js_1.breakWhile)(value !== undefined && !positive(value), fail('Invalid context watermark'));
|
|
48
|
-
(0, rules_js_1.breakWhile)(policy.targetInputChars !== undefined &&
|
|
49
|
-
|
|
81
|
+
(0, rules_js_1.breakWhile)(policy.targetInputChars !== undefined &&
|
|
82
|
+
policy.triggerChars !== undefined &&
|
|
83
|
+
policy.targetInputChars > policy.triggerChars, fail('Context target must not exceed trigger'));
|
|
84
|
+
(0, rules_js_1.breakWhile)(policy.targetInputTokens !== undefined &&
|
|
85
|
+
policy.triggerTokens !== undefined &&
|
|
86
|
+
policy.targetInputTokens > policy.triggerTokens, fail('Token target must not exceed trigger'));
|
|
50
87
|
const ids = new Set();
|
|
51
88
|
for (const step of policy.steps) {
|
|
52
89
|
(0, rules_js_1.breakWhile)(!step.id || ids.has(step.id) || !step.fragmentId || !positive(step.targetChars), fail('Invalid context reduction'));
|
|
53
90
|
ids.add(step.id);
|
|
54
|
-
const operation = Object.hasOwn(exports.contextReductionCatalog, step.kind)
|
|
91
|
+
const operation = Object.hasOwn(exports.contextReductionCatalog, step.kind)
|
|
92
|
+
? exports.contextReductionCatalog[step.kind]
|
|
93
|
+
: undefined;
|
|
55
94
|
(0, rules_js_1.breakWhile)(!operation, fail('Unknown context reduction'));
|
|
56
95
|
operation.validate(step, handlers);
|
|
57
96
|
}
|
|
@@ -79,65 +118,107 @@ function compressionInput(step, fragment) {
|
|
|
79
118
|
const older = groups.slice(0, groups.length - kept).flat();
|
|
80
119
|
const record = fragment.value;
|
|
81
120
|
const value = { ...record, [step.preserve.field]: older };
|
|
82
|
-
const recentChars = size({ ...fragment, value: { ...record, [step.preserve.field]: recent } })
|
|
83
|
-
|
|
84
|
-
return {
|
|
121
|
+
const recentChars = size({ ...fragment, value: { ...record, [step.preserve.field]: recent } }) -
|
|
122
|
+
size({ ...fragment, value: { ...record, [step.preserve.field]: [] } });
|
|
123
|
+
return {
|
|
124
|
+
fragment: { ...fragment, value },
|
|
125
|
+
recent,
|
|
126
|
+
older,
|
|
127
|
+
// Recent groups are appended back after compression, so their characters are subtracted from
|
|
128
|
+
// the budget the handler may use; the target stays positive.
|
|
129
|
+
targetChars: Math.max(1, step.targetChars - recentChars),
|
|
130
|
+
};
|
|
85
131
|
}
|
|
86
132
|
async function compress(call) {
|
|
87
133
|
if (call.step.kind !== 'compress')
|
|
88
134
|
throw fail('Invalid compression step');
|
|
89
135
|
const step = call.step;
|
|
90
|
-
const handler = call.compressors.find(item => item.id === step.handlerId);
|
|
136
|
+
const handler = call.compressors.find((item) => item.id === step.handlerId);
|
|
91
137
|
const input = compressionInput(step, call.fragment);
|
|
92
138
|
if (input.older?.length === 0)
|
|
93
139
|
return call.fragment.value;
|
|
94
|
-
const value = await handler.compress({
|
|
95
|
-
|
|
140
|
+
const value = await handler.compress({
|
|
141
|
+
stageId: call.stageId,
|
|
142
|
+
fragment: structuredClone(input.fragment),
|
|
143
|
+
targetChars: input.targetChars,
|
|
144
|
+
callModel: call.callModel,
|
|
145
|
+
}, { signal: call.signal, diagnostics: call.diagnostics });
|
|
96
146
|
if (!step.preserve)
|
|
97
147
|
return value;
|
|
98
148
|
const field = step.preserve.field;
|
|
99
149
|
(0, rules_js_1.breakWhile)(!value || typeof value !== 'object' || !Array.isArray(value[field]), fail('Protected-history compression must return an array'));
|
|
100
150
|
const summary = value;
|
|
101
151
|
const record = call.fragment.value;
|
|
102
|
-
(0, rules_js_1.breakWhile)(Object.keys(summary).length !== Object.keys(record).length ||
|
|
152
|
+
(0, rules_js_1.breakWhile)(Object.keys(summary).length !== Object.keys(record).length ||
|
|
153
|
+
Object.keys(record).some((key) => !Object.hasOwn(summary, key) ||
|
|
154
|
+
(key !== field && JSON.stringify(summary[key]) !== JSON.stringify(record[key]))), fail('Compression must preserve unrelated history fields'));
|
|
103
155
|
const merged = { ...record, [field]: [...summary[field], ...input.recent] };
|
|
104
156
|
(0, history_js_1.historyGroups)(merged, step.preserve);
|
|
105
157
|
return merged;
|
|
106
158
|
}
|
|
107
159
|
/** This catalog drives validation and dispatch. Every step executes at most once. */
|
|
108
160
|
exports.contextReductionCatalog = {
|
|
109
|
-
trim: {
|
|
161
|
+
trim: {
|
|
162
|
+
validate(step) {
|
|
110
163
|
if (step.kind !== 'trim')
|
|
111
164
|
throw fail('Invalid trim step');
|
|
112
165
|
(0, history_js_1.validateRecentHistory)(step);
|
|
113
|
-
},
|
|
114
|
-
|
|
166
|
+
},
|
|
167
|
+
run: trim,
|
|
168
|
+
},
|
|
169
|
+
compress: {
|
|
170
|
+
validate(step, handlers) {
|
|
115
171
|
if (step.kind !== 'compress')
|
|
116
172
|
throw fail('Invalid compression step');
|
|
117
173
|
(0, rules_js_1.breakWhile)(!handlers.has(step.handlerId), fail('Unregistered context compressor'));
|
|
118
174
|
if (step.preserve)
|
|
119
175
|
(0, history_js_1.validateRecentHistory)(step.preserve);
|
|
120
|
-
},
|
|
176
|
+
},
|
|
177
|
+
run: compress,
|
|
178
|
+
},
|
|
121
179
|
};
|
|
122
180
|
/** A handler ignoring cancellation cannot block delivery or publish a late result. */
|
|
123
181
|
async function runOperation(run, signal) {
|
|
124
182
|
signal.throwIfAborted();
|
|
125
|
-
return await (0, cancellation_js_1.awaitWithSignal)(Promise.resolve().then(() => {
|
|
183
|
+
return await (0, cancellation_js_1.awaitWithSignal)(Promise.resolve().then(() => {
|
|
184
|
+
signal.throwIfAborted();
|
|
185
|
+
return run();
|
|
186
|
+
}), signal);
|
|
126
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Validate fragment structure and ID uniqueness without re-checking per-fragment budgets.
|
|
190
|
+
*
|
|
191
|
+
* Per-fragment size is rechecked during reduction, where the fragment's own allowance applies.
|
|
192
|
+
*
|
|
193
|
+
* @param fragments Fragments to validate as one set.
|
|
194
|
+
* @throws {ValidationError} When an ID is malformed or repeated, or required metadata is invalid.
|
|
195
|
+
*/
|
|
127
196
|
function validateStructure(fragments) {
|
|
128
197
|
const ids = new Set();
|
|
129
198
|
for (const fragment of fragments)
|
|
130
199
|
(0, fragments_js_1.validateContextFragment)(fragment, ids, false);
|
|
131
200
|
}
|
|
132
|
-
const measure = (fragments) => (0, assembly_js_1.assembleFragments)(fragments.map(fragment => ({ ...fragment, maxChars: Number.MAX_SAFE_INTEGER })), Number.MAX_SAFE_INTEGER).inputChars;
|
|
201
|
+
const measure = (fragments) => (0, assembly_js_1.assembleFragments)(fragments.map((fragment) => ({ ...fragment, maxChars: Number.MAX_SAFE_INTEGER })), Number.MAX_SAFE_INTEGER).inputChars;
|
|
133
202
|
function measuredTokens(fragments, additional, budget) {
|
|
134
203
|
if (!budget)
|
|
135
204
|
return undefined;
|
|
136
|
-
const context = (0, assembly_js_1.assembleFragments)(fragments.map(fragment => ({ ...fragment, maxChars: Number.MAX_SAFE_INTEGER })), Number.MAX_SAFE_INTEGER);
|
|
205
|
+
const context = (0, assembly_js_1.assembleFragments)(fragments.map((fragment) => ({ ...fragment, maxChars: Number.MAX_SAFE_INTEGER })), Number.MAX_SAFE_INTEGER);
|
|
137
206
|
const tokens = budget.measure([...context.messages, ...additional]);
|
|
138
207
|
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(tokens) || tokens < 0, fail('Invalid measured context tokens'));
|
|
139
208
|
return tokens;
|
|
140
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Resolve the effective trigger and target watermarks for a reduction policy.
|
|
212
|
+
*
|
|
213
|
+
* Configured values are clamped to the plan's character budget and the runner's token limit, so a
|
|
214
|
+
* policy can never reduce below what the request actually allows. A missing target equals the
|
|
215
|
+
* trigger, which means "reduce until back under the trigger".
|
|
216
|
+
*
|
|
217
|
+
* @param state Processing state carrying the plan and ports.
|
|
218
|
+
* @returns Trigger and target sizes in characters and, when measurable, tokens.
|
|
219
|
+
* @throws {ValidationError} When token thresholds are configured without a token measurement port,
|
|
220
|
+
* or the effective target exceeds the effective trigger.
|
|
221
|
+
*/
|
|
141
222
|
function watermarks(state) {
|
|
142
223
|
const policy = state.policy;
|
|
143
224
|
if (policy.mode !== 'reduce')
|
|
@@ -146,30 +227,76 @@ function watermarks(state) {
|
|
|
146
227
|
const targetChars = policy.targetInputChars ?? triggerChars;
|
|
147
228
|
const budget = state.ports.tokenBudget;
|
|
148
229
|
(0, rules_js_1.breakWhile)((policy.triggerTokens !== undefined || policy.targetInputTokens !== undefined) && !budget, fail('Token thresholds require a token measurement port'));
|
|
149
|
-
const triggerTokens = budget
|
|
230
|
+
const triggerTokens = budget
|
|
231
|
+
? Math.min(policy.triggerTokens ?? budget.inputLimit, budget.inputLimit)
|
|
232
|
+
: undefined;
|
|
150
233
|
const targetTokens = policy.targetInputTokens ?? triggerTokens;
|
|
151
234
|
(0, rules_js_1.breakWhile)(targetChars > triggerChars || (targetTokens !== undefined && targetTokens > triggerTokens), fail('Target exceeds effective context trigger'));
|
|
152
|
-
return {
|
|
235
|
+
return {
|
|
236
|
+
trigger: { chars: triggerChars, tokens: triggerTokens },
|
|
237
|
+
target: { chars: targetChars, tokens: targetTokens },
|
|
238
|
+
};
|
|
153
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Decide whether the current fragments still need reduction.
|
|
242
|
+
*
|
|
243
|
+
* A fragment exceeding its own `maxChars` also counts as needing reduction, even when the total
|
|
244
|
+
* fits, because per-fragment allowances are part of the plan contract.
|
|
245
|
+
*
|
|
246
|
+
* @param state Processing state to measure.
|
|
247
|
+
* @param threshold Trigger size; `tokens` is checked only when present.
|
|
248
|
+
* @returns `true` when characters, a per-fragment allowance or tokens exceed the threshold.
|
|
249
|
+
*/
|
|
154
250
|
function needsReduction(state, threshold) {
|
|
155
|
-
return measure(state.fragments) + state.additionalChars > threshold.chars
|
|
156
|
-
|
|
157
|
-
|
|
251
|
+
return (measure(state.fragments) + state.additionalChars > threshold.chars ||
|
|
252
|
+
state.fragments.some((fragment) => size(fragment) > fragment.maxChars) ||
|
|
253
|
+
(threshold.tokens !== undefined &&
|
|
254
|
+
measuredTokens(state.fragments, state.additionalMessages, state.ports.tokenBudget) >
|
|
255
|
+
threshold.tokens));
|
|
158
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Validate and record application-made changes for an `audit` policy.
|
|
259
|
+
*
|
|
260
|
+
* Only fragments listed as mutable may have changed; the audit helper enforces the rest. Changes
|
|
261
|
+
* that survive are recorded in the report as `app` entries.
|
|
262
|
+
*
|
|
263
|
+
* @param state Processing state; the policy must be `audit` and carry original fragments.
|
|
264
|
+
* @throws {ValidationError} When the policy is not `audit`, original fragments are missing, a
|
|
265
|
+
* mutable ID does not exist, or a protected fragment changed.
|
|
266
|
+
*/
|
|
159
267
|
function auditApp({ plan, policy, before, fragments, report }) {
|
|
160
268
|
if (policy.mode !== 'audit')
|
|
161
269
|
throw fail('Invalid App audit policy');
|
|
162
270
|
(0, rules_js_1.breakWhile)(!plan.originalFragments, fail('App audit requires original fragments'));
|
|
163
271
|
const mutable = new Set(policy.mutableFragmentIds);
|
|
164
|
-
(0, rules_js_1.breakWhile)([...mutable].some(id => !before.some(fragment => fragment.id === id)), fail('Unknown mutable fragment'));
|
|
272
|
+
(0, rules_js_1.breakWhile)([...mutable].some((id) => !before.some((fragment) => fragment.id === id)), fail('Unknown mutable fragment'));
|
|
165
273
|
(0, audit_js_1.auditContextChange)(before, fragments, mutable);
|
|
166
274
|
for (const [index, fragment] of fragments.entries())
|
|
167
275
|
if (JSON.stringify(fragment.value) !== JSON.stringify(before[index].value))
|
|
168
|
-
report.changes.push({
|
|
276
|
+
report.changes.push({
|
|
277
|
+
id: 'app',
|
|
278
|
+
kind: 'app',
|
|
279
|
+
fragmentId: fragment.id,
|
|
280
|
+
beforeChars: size(before[index]),
|
|
281
|
+
afterChars: size(fragment),
|
|
282
|
+
});
|
|
169
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Wrap the model call port with a handler-local call ceiling and a reply reserve.
|
|
286
|
+
*
|
|
287
|
+
* `reserve` is subtracted from the runner's remaining budget, so handlers can never consume the
|
|
288
|
+
* calls the final reply still needs.
|
|
289
|
+
*
|
|
290
|
+
* @param ports Execution ports providing cancellation and the underlying model call.
|
|
291
|
+
* @param maxCalls Maximum calls this handler may make.
|
|
292
|
+
* @param reserve Calls that must remain available for the reply.
|
|
293
|
+
* @returns A call function that throws instead of overspending.
|
|
294
|
+
* @throws {BudgetError} On each call that would exceed either limit.
|
|
295
|
+
* @throws The signal's abort reason when the request is already cancelled.
|
|
296
|
+
*/
|
|
170
297
|
function limitedCall(ports, maxCalls, reserve) {
|
|
171
298
|
let calls = 0;
|
|
172
|
-
return request => {
|
|
299
|
+
return (request) => {
|
|
173
300
|
ports.signal.throwIfAborted();
|
|
174
301
|
if (calls >= maxCalls || (ports.remainingCalls?.() ?? Infinity) <= reserve)
|
|
175
302
|
throw new errors_js_1.BudgetError('Context handler call allowance exhausted');
|
|
@@ -180,23 +307,30 @@ function limitedCall(ports, maxCalls, reserve) {
|
|
|
180
307
|
async function selectionCandidates(state, steps, selection) {
|
|
181
308
|
const candidates = [];
|
|
182
309
|
for (const step of steps) {
|
|
183
|
-
const fragment = state.fragments.find(item => item.id === step.fragmentId);
|
|
310
|
+
const fragment = state.fragments.find((item) => item.id === step.fragmentId);
|
|
184
311
|
if (size(fragment) <= step.targetChars)
|
|
185
312
|
continue;
|
|
186
|
-
const candidate = {
|
|
187
|
-
|
|
313
|
+
const candidate = {
|
|
314
|
+
id: step.id,
|
|
315
|
+
kind: step.kind,
|
|
316
|
+
fragmentId: step.fragmentId,
|
|
317
|
+
chars: size(fragment),
|
|
318
|
+
targetChars: step.targetChars,
|
|
319
|
+
requiredCalls: 0,
|
|
320
|
+
};
|
|
188
321
|
if (step.kind === 'compress') {
|
|
189
322
|
if (compressionInput(step, fragment).older?.length === 0)
|
|
190
323
|
continue;
|
|
191
|
-
candidate.requiredCalls = (0, selection_policy_js_1.contextHandlerCalls)(state.ports.compressors.find(handler => handler.id === step.handlerId));
|
|
324
|
+
candidate.requiredCalls = (0, selection_policy_js_1.contextHandlerCalls)(state.ports.compressors.find((handler) => handler.id === step.handlerId));
|
|
192
325
|
}
|
|
193
326
|
if (step.kind === 'trim' && (selection.mode === 'auto' || selection.mode === 'model')) {
|
|
194
327
|
try {
|
|
195
328
|
const value = await trim({ ...state.ports, step, fragment });
|
|
196
329
|
candidate.projectedChars = size({ ...fragment, value });
|
|
197
|
-
const retained = state.report.changes
|
|
198
|
-
.
|
|
199
|
-
|
|
330
|
+
const retained = state.report.changes
|
|
331
|
+
.filter((change) => change.fragmentId === step.fragmentId && change.kind === 'trim')
|
|
332
|
+
.reduce((ratio, change) => (ratio * change.afterChars) / change.beforeChars, 1);
|
|
333
|
+
candidate.trimLossRatio = Math.max(0, 1 - (retained * candidate.projectedChars) / candidate.chars);
|
|
200
334
|
if (candidate.projectedChars >= candidate.chars)
|
|
201
335
|
continue;
|
|
202
336
|
}
|
|
@@ -210,21 +344,43 @@ async function selectionCandidates(state, steps, selection) {
|
|
|
210
344
|
}
|
|
211
345
|
return candidates;
|
|
212
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Choose which reduction steps to run next, under the current selection mode.
|
|
349
|
+
*
|
|
350
|
+
* Candidates that cannot make progress are filtered out: a step whose fragment already fits, a
|
|
351
|
+
* compression with no older history, or a step that needs more calls than the remaining budget.
|
|
352
|
+
*
|
|
353
|
+
* @param state Processing state providing ports, fragments and the report.
|
|
354
|
+
* @param steps Reduction steps still pending.
|
|
355
|
+
* @param selection Selection strategy to apply.
|
|
356
|
+
* @returns Registered step IDs in execution order; records the decision in the report.
|
|
357
|
+
* @throws {BudgetError} When model-driven selection has no calls or no feasible candidate left.
|
|
358
|
+
* @throws {ValidationError} When the selector returns unknown, duplicate or over-budget IDs.
|
|
359
|
+
*/
|
|
213
360
|
async function chooseSteps(state, steps, selection) {
|
|
214
361
|
const { ports, report } = state;
|
|
215
362
|
const candidates = await selectionCandidates(state, steps, selection);
|
|
216
363
|
if (!candidates.length)
|
|
217
364
|
return [];
|
|
218
|
-
const handler = selection.mode === 'model'
|
|
365
|
+
const handler = selection.mode === 'model'
|
|
366
|
+
? ports.selectors?.find((item) => item.id === selection.handlerId)
|
|
367
|
+
: undefined;
|
|
219
368
|
const currentChars = measure(state.fragments) + state.additionalChars;
|
|
220
369
|
const target = watermarks(state).target;
|
|
221
370
|
const currentTokens = measuredTokens(state.fragments, state.additionalMessages, ports.tokenBudget);
|
|
222
371
|
const fragmentOverflow = state.fragments.reduce((sum, fragment) => sum + Math.max(0, size(fragment) - fragment.maxChars), 0);
|
|
223
372
|
const result = await runOperation(() => (0, selection_policy_js_1.selectContextSteps)({
|
|
224
|
-
stageId: ports.stageId,
|
|
225
|
-
|
|
226
|
-
|
|
373
|
+
stageId: ports.stageId,
|
|
374
|
+
signal: ports.signal,
|
|
375
|
+
diagnostics: ports.diagnostics,
|
|
376
|
+
selection,
|
|
377
|
+
selectors: ports.selectors ?? [],
|
|
378
|
+
candidates,
|
|
379
|
+
fragments: structuredClone(state.fragments.filter((fragment) => candidates.some((candidate) => candidate.fragmentId === fragment.id))),
|
|
380
|
+
currentChars,
|
|
381
|
+
currentTokens,
|
|
227
382
|
requiredReductionTokens: currentTokens === undefined ? undefined : Math.max(0, currentTokens - target.tokens),
|
|
383
|
+
// Per-fragment overflow also has to be removed even when the total already fits.
|
|
228
384
|
requiredReductionChars: Math.max(currentChars - target.chars, fragmentOverflow),
|
|
229
385
|
remainingCalls: ports.remainingCalls?.() ?? Infinity,
|
|
230
386
|
callModel: limitedCall(ports, handler ? (0, selection_policy_js_1.contextHandlerCalls)(handler) : 0, (0, selection_policy_js_1.reservedContextCalls)(selection)),
|
|
@@ -232,14 +388,33 @@ async function chooseSteps(state, steps, selection) {
|
|
|
232
388
|
report.decisions.push({ mode: selection.mode, stepIds: result.stepIds, reason: result.reason });
|
|
233
389
|
return result.stepIds;
|
|
234
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Apply one reduction step to its target fragment in the working state.
|
|
393
|
+
*
|
|
394
|
+
* The fragment is cloned before the handler runs, then validated, audited and size-checked before
|
|
395
|
+
* it replaces the original. A reduction that grows the fragment is rejected.
|
|
396
|
+
*
|
|
397
|
+
* @param state Processing state whose fragments are updated in place.
|
|
398
|
+
* @param step Reduction step to execute.
|
|
399
|
+
* @param selection Selection strategy used to size the handler call budget.
|
|
400
|
+
* @throws {ValidationError} When the result is structurally invalid, changes protected fields, or
|
|
401
|
+
* exceeds the original size.
|
|
402
|
+
* @throws {BudgetError} When the step's handler exceeds its call allowance.
|
|
403
|
+
*/
|
|
235
404
|
async function applyReduction(state, step, selection) {
|
|
236
405
|
const { fragments, ports, report } = state;
|
|
237
|
-
const index = fragments.findIndex(fragment => fragment.id === step.fragmentId);
|
|
406
|
+
const index = fragments.findIndex((fragment) => fragment.id === step.fragmentId);
|
|
238
407
|
const fragment = fragments[index];
|
|
239
408
|
if (size(fragment) <= step.targetChars)
|
|
240
409
|
return;
|
|
241
|
-
const handler = step.kind === 'compress'
|
|
242
|
-
|
|
410
|
+
const handler = step.kind === 'compress'
|
|
411
|
+
? ports.compressors.find((item) => item.id === step.handlerId)
|
|
412
|
+
: undefined;
|
|
413
|
+
const value = await runOperation(() => exports.contextReductionCatalog[step.kind].run({
|
|
414
|
+
...ports,
|
|
415
|
+
step,
|
|
416
|
+
// Clone first: the handler must not observe or mutate state that audit still needs.
|
|
417
|
+
fragment: structuredClone(fragment),
|
|
243
418
|
callModel: limitedCall(ports, handler ? (0, selection_policy_js_1.contextHandlerCalls)(handler) : 0, (0, selection_policy_js_1.reservedContextCalls)(selection)),
|
|
244
419
|
}), ports.signal);
|
|
245
420
|
ports.signal.throwIfAborted();
|
|
@@ -248,14 +423,29 @@ async function applyReduction(state, step, selection) {
|
|
|
248
423
|
(0, audit_js_1.auditContextChange)([fragment], [next], new Set([fragment.id]));
|
|
249
424
|
(0, rules_js_1.breakWhile)(size(next) > size(fragment), fail('Context reduction increased size'));
|
|
250
425
|
fragments[index] = next;
|
|
251
|
-
report.changes.push({
|
|
426
|
+
report.changes.push({
|
|
427
|
+
id: step.id,
|
|
428
|
+
kind: step.kind,
|
|
429
|
+
fragmentId: fragment.id,
|
|
430
|
+
beforeChars: size(fragment),
|
|
431
|
+
afterChars: size(next),
|
|
432
|
+
});
|
|
252
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Check that every reduction step targets an existing, reducible fragment.
|
|
436
|
+
*
|
|
437
|
+
* System-role and instruction-trust fragments are never reducible, regardless of policy.
|
|
438
|
+
*
|
|
439
|
+
* @param state Processing state whose policy and fragments are checked.
|
|
440
|
+
* @throws {ValidationError} When the policy is not a reduction policy or a target is missing,
|
|
441
|
+
* system-owned or instruction-trusted.
|
|
442
|
+
*/
|
|
253
443
|
function validateReductionTargets(state) {
|
|
254
444
|
const { policy, fragments } = state;
|
|
255
445
|
if (policy.mode !== 'reduce')
|
|
256
446
|
throw fail('Invalid reduction policy');
|
|
257
447
|
for (const step of policy.steps) {
|
|
258
|
-
const fragment = fragments.find(item => item.id === step.fragmentId);
|
|
448
|
+
const fragment = fragments.find((item) => item.id === step.fragmentId);
|
|
259
449
|
(0, rules_js_1.breakWhile)(!fragment || fragment.role === 'system' || fragment.trust === 'instruction', fail(`Invalid reduction target: ${step.fragmentId}`));
|
|
260
450
|
}
|
|
261
451
|
}
|
|
@@ -271,7 +461,7 @@ async function reduceCore(state) {
|
|
|
271
461
|
const thresholds = watermarks(state);
|
|
272
462
|
if (!needsReduction(state, thresholds.trigger))
|
|
273
463
|
return;
|
|
274
|
-
const pending = new Map(policy.steps.map(step => [step.id, step]));
|
|
464
|
+
const pending = new Map(policy.steps.map((step) => [step.id, step]));
|
|
275
465
|
let queue;
|
|
276
466
|
while (pending.size && needsReduction(state, thresholds.target)) {
|
|
277
467
|
queue ??= await chooseSteps(state, [...pending.values()], selection);
|
|
@@ -281,6 +471,7 @@ async function reduceCore(state) {
|
|
|
281
471
|
const step = pending.get(id);
|
|
282
472
|
pending.delete(id);
|
|
283
473
|
await applyReduction(state, step, selection);
|
|
474
|
+
// Automatic selection scores candidates against current sizes, so recompute after each step.
|
|
284
475
|
if (selection.mode === 'auto')
|
|
285
476
|
queue = undefined;
|
|
286
477
|
}
|
|
@@ -288,17 +479,34 @@ async function reduceCore(state) {
|
|
|
288
479
|
function validateAppPolicy(policy) {
|
|
289
480
|
if (policy.mode !== 'audit')
|
|
290
481
|
throw fail('Invalid App audit policy');
|
|
291
|
-
(0, rules_js_1.breakWhile)(!Array.isArray(policy.mutableFragmentIds) ||
|
|
292
|
-
|
|
482
|
+
(0, rules_js_1.breakWhile)(!Array.isArray(policy.mutableFragmentIds) ||
|
|
483
|
+
policy.mutableFragmentIds.some((id) => typeof id !== 'string' || !id) ||
|
|
484
|
+
new Set(policy.mutableFragmentIds).size !== policy.mutableFragmentIds.length, fail('Invalid mutable fragment list'));
|
|
293
485
|
}
|
|
294
486
|
/** The modes and their implementations are registered together, consumed by validation and execution. */
|
|
295
487
|
exports.contextPolicyCatalog = {
|
|
296
488
|
validate: { validate() { }, run() { } },
|
|
297
489
|
reduce: { validate: validateCorePolicy, run: reduceCore },
|
|
298
|
-
|
|
490
|
+
audit: { validate: validateAppPolicy, run: auditApp },
|
|
299
491
|
};
|
|
492
|
+
/**
|
|
493
|
+
* Snapshot and validate a plan before any reduction runs.
|
|
494
|
+
*
|
|
495
|
+
* Messages and fragments are cloned and their getters read inside cancellation checks, so a late
|
|
496
|
+
* abort cannot leave partially copied state. Additional messages must be plain user text.
|
|
497
|
+
*
|
|
498
|
+
* @param source Plan supplied by the request or a context builder.
|
|
499
|
+
* @param policy Validated policy to execute.
|
|
500
|
+
* @param ports Execution ports for cancellation, diagnostics and model calls.
|
|
501
|
+
* @returns A processing state ready for the policy runner.
|
|
502
|
+
* @throws {ValidationError} When the budget, fragments, additional messages or token budget are
|
|
503
|
+
* invalid, or a protected fragment already changed.
|
|
504
|
+
* @throws {TypeError} When the plan budget is not a valid integer or infinity.
|
|
505
|
+
*/
|
|
300
506
|
function beginContextProcessing(source, policy, ports) {
|
|
301
507
|
const signal = ports.signal;
|
|
508
|
+
// Caller-provided getters may do work; checking before and after prevents a cancelled request
|
|
509
|
+
// from contributing a value to the snapshot.
|
|
302
510
|
const read = (get) => {
|
|
303
511
|
signal.throwIfAborted();
|
|
304
512
|
try {
|
|
@@ -318,24 +526,57 @@ function beginContextProcessing(source, policy, ports) {
|
|
|
318
526
|
const rawFragments = read(() => source.fragments);
|
|
319
527
|
const originals = read(() => source.originalFragments);
|
|
320
528
|
const mutable = read(() => source.mutableFragmentIds);
|
|
321
|
-
const additionalMessages = [...(rawMessages ?? [])].map(message => read(() => (0, snapshot_js_1.snapshotMessage)(message)));
|
|
322
|
-
(0, rules_js_1.breakWhile)(additionalMessages.some(message => message.role !== 'user' || typeof message.content !== 'string'), fail('Additional context must be user messages'));
|
|
529
|
+
const additionalMessages = [...(rawMessages ?? [])].map((message) => read(() => (0, snapshot_js_1.snapshotMessage)(message)));
|
|
530
|
+
(0, rules_js_1.breakWhile)(additionalMessages.some((message) => message.role !== 'user' || typeof message.content !== 'string'), fail('Additional context must be user messages'));
|
|
323
531
|
const additionalChars = additionalMessages.reduce((sum, message) => sum + message.content.length, 0);
|
|
324
532
|
(0, rules_js_1.breakWhile)(!Array.isArray(rawFragments), fail('Context plan requires fragments'));
|
|
325
|
-
const fragments = [...rawFragments].map(fragment => read(() => (0, snapshot_js_1.snapshotFragment)(fragment)));
|
|
533
|
+
const fragments = [...rawFragments].map((fragment) => read(() => (0, snapshot_js_1.snapshotFragment)(fragment)));
|
|
326
534
|
validateStructure(fragments);
|
|
327
|
-
const before = [...(originals ?? fragments)].map(fragment => read(() => (0, snapshot_js_1.snapshotFragment)(fragment)));
|
|
535
|
+
const before = [...(originals ?? fragments)].map((fragment) => read(() => (0, snapshot_js_1.snapshotFragment)(fragment)));
|
|
328
536
|
validateStructure(before);
|
|
329
537
|
const mutableFragmentIds = mutable === undefined ? undefined : [...mutable];
|
|
538
|
+
// Only a plan that declares originals can attribute pre-processing changes; otherwise there is
|
|
539
|
+
// no baseline to compare against.
|
|
330
540
|
if (originals)
|
|
331
|
-
(0, audit_js_1.auditContextChange)(before, fragments, new Set(policy.mode === 'audit' ? policy.mutableFragmentIds : mutableFragmentIds ?? []));
|
|
332
|
-
const plan = {
|
|
333
|
-
|
|
334
|
-
|
|
541
|
+
(0, audit_js_1.auditContextChange)(before, fragments, new Set(policy.mode === 'audit' ? policy.mutableFragmentIds : (mutableFragmentIds ?? [])));
|
|
542
|
+
const plan = {
|
|
543
|
+
maxInputChars,
|
|
544
|
+
fragments,
|
|
545
|
+
additionalMessages: additionalMessages,
|
|
546
|
+
originalFragments: originals === undefined ? undefined : before,
|
|
547
|
+
mutableFragmentIds,
|
|
548
|
+
};
|
|
549
|
+
const report = {
|
|
550
|
+
mode: policy.mode,
|
|
551
|
+
beforeChars: read(() => measure(before)) + additionalChars,
|
|
552
|
+
afterChars: 0,
|
|
553
|
+
changes: [],
|
|
554
|
+
};
|
|
335
555
|
const beforeTokens = read(() => measuredTokens(before, additionalMessages, ports.tokenBudget));
|
|
336
|
-
return {
|
|
556
|
+
return {
|
|
557
|
+
plan,
|
|
558
|
+
policy,
|
|
559
|
+
ports,
|
|
560
|
+
fragments,
|
|
561
|
+
before,
|
|
562
|
+
report,
|
|
563
|
+
additionalChars,
|
|
564
|
+
additionalMessages,
|
|
565
|
+
beforeTokens,
|
|
566
|
+
};
|
|
337
567
|
});
|
|
338
568
|
}
|
|
569
|
+
/**
|
|
570
|
+
* Assemble the final context and finalize the processing report.
|
|
571
|
+
*
|
|
572
|
+
* Additional messages are appended after fragments, and the combined size is checked against the
|
|
573
|
+
* same budget. Token measurements are reported only when a measurement port exists.
|
|
574
|
+
*
|
|
575
|
+
* @param state Processing state after the policy has run.
|
|
576
|
+
* @returns The built context and the completed report.
|
|
577
|
+
* @throws {ValidationError} When the final input exceeds the character budget or, with a token
|
|
578
|
+
* counter, the token budget (code `MODEL_TOKEN_BUDGET`).
|
|
579
|
+
*/
|
|
339
580
|
function finishContextProcessing(state) {
|
|
340
581
|
const { plan, ports, fragments, report, additionalChars, additionalMessages, beforeTokens } = state;
|
|
341
582
|
ports.signal.throwIfAborted();
|
|
@@ -345,12 +586,29 @@ function finishContextProcessing(state) {
|
|
|
345
586
|
(0, fragments_js_1.validateContextBudget)(context.inputChars, plan.maxInputChars);
|
|
346
587
|
const afterTokens = measuredTokens(fragments, additionalMessages, ports.tokenBudget);
|
|
347
588
|
if (afterTokens !== undefined) {
|
|
348
|
-
(0, rules_js_1.breakWhile)(afterTokens > ports.tokenBudget.inputLimit, new errors_js_1.ValidationError([
|
|
349
|
-
|
|
589
|
+
(0, rules_js_1.breakWhile)(afterTokens > ports.tokenBudget.inputLimit, new errors_js_1.ValidationError([
|
|
590
|
+
{ code: 'MODEL_TOKEN_BUDGET', message: 'Processed context exceeds token budget' },
|
|
591
|
+
]));
|
|
592
|
+
report.tokens = {
|
|
593
|
+
counterId: ports.tokenBudget.counterId,
|
|
594
|
+
before: beforeTokens,
|
|
595
|
+
after: afterTokens,
|
|
596
|
+
inputLimit: ports.tokenBudget.inputLimit,
|
|
597
|
+
};
|
|
350
598
|
}
|
|
351
599
|
report.afterChars = context.inputChars;
|
|
352
600
|
return { context, report };
|
|
353
601
|
}
|
|
602
|
+
/**
|
|
603
|
+
* Run a complete context policy in one call: snapshot, execute and finalize.
|
|
604
|
+
*
|
|
605
|
+
* @param plan Plan to process.
|
|
606
|
+
* @param policy Policy whose mode selects the registered runner.
|
|
607
|
+
* @param ports Execution ports for cancellation, diagnostics and model calls.
|
|
608
|
+
* @returns The processed context and its report.
|
|
609
|
+
* @throws {ValidationError} When validation or the final budget check fails.
|
|
610
|
+
* @throws {BudgetError} When a handler exhausts its call allowance.
|
|
611
|
+
*/
|
|
354
612
|
async function processContext(plan, policy, ports) {
|
|
355
613
|
const state = beginContextProcessing(plan, policy, ports);
|
|
356
614
|
await exports.contextPolicyCatalog[policy.mode].run(state);
|