@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
package/dist/esm/kits/durable.js
CHANGED
|
@@ -1,39 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable Kit: replay-safe sequential task execution on top of an App-owned checkpoint store.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: an optional App-side library for work that must survive a restart.
|
|
5
|
+
* The Kit owns step ordering, attempt and model-call accounting, deadline checks, checkpoint
|
|
6
|
+
* validation and the exclusive-store protocol; the store, its atomicity and the real side
|
|
7
|
+
* effects stay with the App. Core itself never imports this module.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `defineDurableTask`, `Durable`, the checkpoint/step/store types, and the
|
|
10
|
+
* `durableStatuses` / `durableReplayPolicies` enumerations.
|
|
11
|
+
*/
|
|
1
12
|
import { booleanResult } from '../utils/synchronous.js';
|
|
2
13
|
import { awaitWithSignal, awaitAssertion, createDeadlineSignal } from '../utils/cancellation.js';
|
|
3
14
|
import { durableStatuses, durableReplayPolicies } from '../structs/kits/durable.js';
|
|
4
15
|
import { AgentCoreEngine } from '../execution/engine.js';
|
|
16
|
+
/**
|
|
17
|
+
* Compile a durable task definition into a resumable runner.
|
|
18
|
+
*
|
|
19
|
+
* Each `run` call locks the task id in the store, loads the checkpoint and resumes at
|
|
20
|
+
* `nextStepIndex`. A checkpoint from another definition id or revision, or one that fails the
|
|
21
|
+
* predicates below, is rejected instead of being repaired, because silently accepting it would
|
|
22
|
+
* replay App side effects under a different contract.
|
|
23
|
+
*
|
|
24
|
+
* @param definition - Task identity, state predicate, ordered steps and optional authorization.
|
|
25
|
+
* @param options - Fallback store plus optional clock; both are bound to their owners.
|
|
26
|
+
* @returns A frozen task with `run({ taskId, store? }, context)`.
|
|
27
|
+
* @throws TypeError At construction for an invalid identity, step list, replay policy or
|
|
28
|
+
* duplicate step id; from `run` for a malformed request/context/store, an invalid
|
|
29
|
+
* checkpoint, or a step whose returned state fails the predicate. Also throws when the
|
|
30
|
+
* deadline passed, the attempt budget is exhausted, or the model-call budget cannot fund
|
|
31
|
+
* one more attempt.
|
|
32
|
+
*/
|
|
5
33
|
export function defineDurableTask(definition, options = {}) {
|
|
6
34
|
if (!definition || typeof definition !== 'object')
|
|
7
35
|
throw new TypeError('Use isState and replayPolicy');
|
|
8
36
|
const { id: definitionId, revision, steps: definitions, isState } = definition;
|
|
9
37
|
const clock = options.now;
|
|
10
|
-
if (typeof definitionId !== 'string' ||
|
|
11
|
-
|
|
12
|
-
|
|
38
|
+
if (typeof definitionId !== 'string' ||
|
|
39
|
+
!definitionId.trim() ||
|
|
40
|
+
typeof revision !== 'string' ||
|
|
41
|
+
!revision.trim() ||
|
|
42
|
+
typeof isState !== 'function' ||
|
|
43
|
+
!Array.isArray(definitions) ||
|
|
44
|
+
!definitions.length ||
|
|
45
|
+
(clock !== undefined && typeof clock !== 'function'))
|
|
13
46
|
throw new TypeError('Invalid durable task');
|
|
14
47
|
const now = clock?.bind(options) ?? Date.now, validate = isState.bind(definition);
|
|
15
48
|
const authorize = definition.authorize?.bind(definition);
|
|
16
|
-
const boundStore = options.store && {
|
|
49
|
+
const boundStore = options.store && {
|
|
50
|
+
exclusive: options.store.exclusive.bind(options.store),
|
|
51
|
+
load: options.store.load.bind(options.store),
|
|
52
|
+
save: options.store.save.bind(options.store),
|
|
53
|
+
};
|
|
17
54
|
const steps = Object.freeze(definitions.map((step) => {
|
|
18
55
|
if (!step || typeof step !== 'object')
|
|
19
56
|
throw new TypeError('Use replayPolicy and OperationContext');
|
|
20
57
|
const { id, replayPolicy, run, reconcile } = step;
|
|
21
|
-
if (typeof id !== 'string' ||
|
|
22
|
-
|
|
58
|
+
if (typeof id !== 'string' ||
|
|
59
|
+
!id.trim() ||
|
|
60
|
+
!durableReplayPolicies.includes(replayPolicy) ||
|
|
61
|
+
typeof run !== 'function' ||
|
|
62
|
+
(reconcile !== undefined && typeof reconcile !== 'function'))
|
|
23
63
|
throw new TypeError('Invalid durable step');
|
|
24
|
-
return Object.freeze({
|
|
64
|
+
return Object.freeze({
|
|
65
|
+
id,
|
|
66
|
+
replayPolicy,
|
|
67
|
+
run: run.bind(step),
|
|
68
|
+
reconcile: reconcile?.bind(step),
|
|
69
|
+
});
|
|
25
70
|
}));
|
|
26
|
-
if (new Set(steps.map(step => step.id)).size !== steps.length)
|
|
71
|
+
if (new Set(steps.map((step) => step.id)).size !== steps.length)
|
|
27
72
|
throw new TypeError('Duplicate durable step id');
|
|
28
73
|
return Object.freeze({
|
|
74
|
+
/**
|
|
75
|
+
* Resume or start one durable task.
|
|
76
|
+
*
|
|
77
|
+
* @param request - Task id plus an optional per-call store that overrides the bound one.
|
|
78
|
+
* @param context - Operation context supplying app, signal and diagnostics.
|
|
79
|
+
* @returns The final state, cloned so the caller cannot mutate the stored checkpoint.
|
|
80
|
+
* @throws As described for `defineDurableTask`; an already-completed task returns its state
|
|
81
|
+
* without running any step.
|
|
82
|
+
*/
|
|
29
83
|
async run(request, context) {
|
|
30
|
-
if (!request ||
|
|
84
|
+
if (!request ||
|
|
85
|
+
typeof request !== 'object' ||
|
|
86
|
+
typeof request.taskId !== 'string' ||
|
|
87
|
+
!request.taskId.trim())
|
|
31
88
|
throw new TypeError('Use a named durable task request');
|
|
32
89
|
if (!context?.signal)
|
|
33
90
|
throw new TypeError('Durable tasks require OperationContext');
|
|
34
91
|
const { taskId } = request, store = request.store ?? boundStore, { app, signal, diagnostics } = context;
|
|
35
92
|
signal.throwIfAborted();
|
|
36
|
-
if (!store ||
|
|
93
|
+
if (!store ||
|
|
94
|
+
typeof store.exclusive !== 'function' ||
|
|
95
|
+
typeof store.load !== 'function' ||
|
|
96
|
+
typeof store.save !== 'function')
|
|
37
97
|
throw new TypeError('Invalid durable store');
|
|
38
98
|
const exclusive = store.exclusive.bind(store), load = store.load.bind(store), save = store.save.bind(store);
|
|
39
99
|
signal.throwIfAborted();
|
|
@@ -44,24 +104,42 @@ export function defineDurableTask(definition, options = {}) {
|
|
|
44
104
|
if (!loaded)
|
|
45
105
|
throw new TypeError('Invalid durable checkpoint');
|
|
46
106
|
let record = snapshotCheckpoint(loaded);
|
|
47
|
-
if (record.definitionId !== definitionId ||
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
107
|
+
if (record.definitionId !== definitionId ||
|
|
108
|
+
record.revision !== revision ||
|
|
109
|
+
!booleanResult(validate(record.state), 'Durable state predicates must return boolean synchronously') ||
|
|
110
|
+
!Number.isSafeInteger(record.nextStepIndex) ||
|
|
111
|
+
record.nextStepIndex < 0 ||
|
|
112
|
+
record.nextStepIndex > steps.length ||
|
|
113
|
+
!Number.isSafeInteger(record.attemptCount) ||
|
|
114
|
+
record.attemptCount < 0 ||
|
|
115
|
+
!Number.isSafeInteger(record.maxAttempts) ||
|
|
116
|
+
record.maxAttempts < 1 ||
|
|
117
|
+
record.attemptCount > record.maxAttempts ||
|
|
118
|
+
record.attemptCount < record.nextStepIndex ||
|
|
119
|
+
!Number.isFinite(record.deadlineAtMs) ||
|
|
120
|
+
!durableStatuses.includes(record.status) ||
|
|
121
|
+
(record.status === 'completed') !== (record.nextStepIndex === steps.length))
|
|
53
122
|
throw new TypeError('Invalid durable checkpoint');
|
|
54
123
|
const deadline = record.deadlineAtMs;
|
|
55
124
|
assertActive(signal, deadline, now);
|
|
56
125
|
if (record.modelBudget) {
|
|
57
126
|
const { maxCalls, reservedCalls, maxCallsPerAttempt } = record.modelBudget;
|
|
58
|
-
if (!Number.isSafeInteger(maxCalls) ||
|
|
59
|
-
|
|
127
|
+
if (!Number.isSafeInteger(maxCalls) ||
|
|
128
|
+
maxCalls < 1 ||
|
|
129
|
+
!Number.isSafeInteger(reservedCalls) ||
|
|
130
|
+
reservedCalls < 0 ||
|
|
131
|
+
reservedCalls > maxCalls ||
|
|
132
|
+
!Number.isSafeInteger(maxCallsPerAttempt) ||
|
|
133
|
+
maxCallsPerAttempt < 1 ||
|
|
134
|
+
maxCallsPerAttempt > maxCalls)
|
|
60
135
|
throw new TypeError('Invalid durable model budget');
|
|
61
136
|
}
|
|
62
137
|
const lifetime = createDeadlineSignal(deadline, signal, now), activeSignal = lifetime.signal;
|
|
63
138
|
let saving;
|
|
64
|
-
const persist = async () => {
|
|
139
|
+
const persist = async () => {
|
|
140
|
+
saving = save(taskId, record);
|
|
141
|
+
await saving;
|
|
142
|
+
};
|
|
65
143
|
try {
|
|
66
144
|
if (authorize)
|
|
67
145
|
await awaitAssertion(() => authorize(snapshotCheckpoint(record), { app, signal: activeSignal, diagnostics }), activeSignal, 'Durable authorization must return void');
|
|
@@ -73,7 +151,10 @@ export function defineDurableTask(definition, options = {}) {
|
|
|
73
151
|
}
|
|
74
152
|
if (record.status === 'cancelled')
|
|
75
153
|
throw new Error('Durable task cancelled');
|
|
76
|
-
const engine = new AgentCoreEngine({
|
|
154
|
+
const engine = new AgentCoreEngine({
|
|
155
|
+
maxRounds: Math.max(1, record.maxAttempts - record.attemptCount),
|
|
156
|
+
execution: { signal: activeSignal, diagnostics },
|
|
157
|
+
});
|
|
77
158
|
return await engine.run(async (_index, execution) => {
|
|
78
159
|
assertActive(activeSignal, deadline, now);
|
|
79
160
|
if (record.attemptCount >= record.maxAttempts)
|
|
@@ -82,25 +163,46 @@ export function defineDurableTask(definition, options = {}) {
|
|
|
82
163
|
if (interrupted && step.replayPolicy === 'reconcile' && !step.reconcile)
|
|
83
164
|
throw new Error('Durable task reconciliation required');
|
|
84
165
|
const modelBudget = record.modelBudget;
|
|
85
|
-
if (modelBudget &&
|
|
166
|
+
if (modelBudget &&
|
|
167
|
+
modelBudget.maxCalls - modelBudget.reservedCalls < modelBudget.maxCallsPerAttempt)
|
|
86
168
|
throw new Error('Durable model budget exhausted');
|
|
87
|
-
record = {
|
|
88
|
-
...
|
|
169
|
+
record = {
|
|
170
|
+
...record,
|
|
171
|
+
attemptCount: record.attemptCount + 1,
|
|
172
|
+
status: 'running',
|
|
173
|
+
...(modelBudget
|
|
174
|
+
? {
|
|
175
|
+
modelBudget: {
|
|
176
|
+
...modelBudget,
|
|
177
|
+
reservedCalls: modelBudget.reservedCalls + modelBudget.maxCallsPerAttempt,
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
: {}),
|
|
181
|
+
};
|
|
89
182
|
// Await every save under the lock; cancellation cannot undo an in-flight commit.
|
|
90
183
|
await persist();
|
|
91
184
|
assertActive(activeSignal, deadline, now);
|
|
92
185
|
const local = structuredClone(record.state);
|
|
93
186
|
assertActive(activeSignal, deadline, now);
|
|
94
187
|
const handle = interrupted && step.replayPolicy === 'reconcile' ? step.reconcile : step.run;
|
|
95
|
-
const nextState = await awaitWithSignal(handle(local, {
|
|
96
|
-
|
|
188
|
+
const nextState = await awaitWithSignal(handle(local, {
|
|
189
|
+
app,
|
|
190
|
+
signal: execution.signal,
|
|
191
|
+
diagnostics: execution.diagnostics,
|
|
192
|
+
attemptCount: record.attemptCount,
|
|
193
|
+
maxModelCalls: record.modelBudget?.maxCallsPerAttempt,
|
|
194
|
+
}), activeSignal);
|
|
97
195
|
assertActive(activeSignal, deadline, now);
|
|
98
196
|
if (!booleanResult(validate(nextState), 'Durable state predicates must return boolean synchronously'))
|
|
99
197
|
throw new TypeError('Invalid durable step state');
|
|
100
198
|
const state = structuredClone(nextState);
|
|
101
199
|
assertActive(activeSignal, deadline, now);
|
|
102
|
-
record = {
|
|
103
|
-
|
|
200
|
+
record = {
|
|
201
|
+
...record,
|
|
202
|
+
state,
|
|
203
|
+
nextStepIndex: record.nextStepIndex + 1,
|
|
204
|
+
status: record.nextStepIndex + 1 === steps.length ? 'completed' : 'ready',
|
|
205
|
+
};
|
|
104
206
|
await persist();
|
|
105
207
|
assertActive(activeSignal, deadline, now);
|
|
106
208
|
if (record.status === 'completed') {
|
|
@@ -131,15 +233,37 @@ function assertActive(signal, deadlineAtMs, now) {
|
|
|
131
233
|
throw new Error('Durable task expired');
|
|
132
234
|
signal.throwIfAborted();
|
|
133
235
|
}
|
|
236
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
134
237
|
export const Durable = Object.freeze({ defineDurableTask });
|
|
238
|
+
/** Allowed checkpoint lifecycle states; re-exported so hosts can validate their own stores. */
|
|
135
239
|
export { durableStatuses, durableReplayPolicies } from '../structs/kits/durable.js';
|
|
136
240
|
function snapshotCheckpoint(record) {
|
|
137
241
|
const { version } = record;
|
|
242
|
+
// Only checkpoint layout 2 is readable; older layouts are not upgraded in place.
|
|
138
243
|
if (version !== 2)
|
|
139
244
|
throw new TypeError('Unsupported durable checkpoint version');
|
|
140
|
-
const { definitionId, revision, nextStepIndex, attemptCount, maxAttempts, deadlineAtMs, status, state, modelBudget } = record;
|
|
141
|
-
if (modelBudget !== undefined &&
|
|
245
|
+
const { definitionId, revision, nextStepIndex, attemptCount, maxAttempts, deadlineAtMs, status, state, modelBudget, } = record;
|
|
246
|
+
if (modelBudget !== undefined &&
|
|
247
|
+
(!modelBudget || typeof modelBudget !== 'object' || Array.isArray(modelBudget)))
|
|
142
248
|
throw new TypeError('Invalid durable model budget');
|
|
143
|
-
return {
|
|
144
|
-
|
|
249
|
+
return {
|
|
250
|
+
version,
|
|
251
|
+
definitionId,
|
|
252
|
+
revision,
|
|
253
|
+
nextStepIndex,
|
|
254
|
+
attemptCount,
|
|
255
|
+
maxAttempts,
|
|
256
|
+
deadlineAtMs,
|
|
257
|
+
status,
|
|
258
|
+
state: structuredClone(state),
|
|
259
|
+
...(modelBudget !== undefined
|
|
260
|
+
? {
|
|
261
|
+
modelBudget: {
|
|
262
|
+
maxCalls: modelBudget.maxCalls,
|
|
263
|
+
reservedCalls: modelBudget.reservedCalls,
|
|
264
|
+
maxCallsPerAttempt: modelBudget.maxCallsPerAttempt,
|
|
265
|
+
},
|
|
266
|
+
}
|
|
267
|
+
: {}),
|
|
268
|
+
};
|
|
145
269
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { EvidenceProvider, EvidenceRequirement, EvidenceProjectionDefinition } from '../structs/kits/evidence.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Compile a reusable completion checklist over actual observations.
|
|
4
|
+
*
|
|
5
|
+
* A requirement is satisfied when at least one observation satisfies the provider registered
|
|
6
|
+
* for its `kind`; `isComplete` requires every requirement to be satisfied, and `missing`
|
|
7
|
+
* returns those that are not. Hosts define evidence semantics.
|
|
8
|
+
*
|
|
9
|
+
* @param definitions - One provider per evidence kind, each with an `isSatisfied` predicate.
|
|
10
|
+
* @returns A frozen checklist exposing `isSatisfied`, `isComplete` and `missing`.
|
|
11
|
+
* @throws TypeError For duplicate kinds, missing predicates, or an unknown requirement kind;
|
|
12
|
+
* predicates must return a boolean synchronously.
|
|
13
|
+
*/
|
|
3
14
|
export declare function defineEvidenceChecklist<Observation, Requirement extends EvidenceRequirement>(definitions: readonly EvidenceProvider<Observation, Requirement>[]): Readonly<{
|
|
4
15
|
isSatisfied: (request: {
|
|
5
16
|
observations: readonly Observation[];
|
|
@@ -9,19 +20,31 @@ export declare function defineEvidenceChecklist<Observation, Requirement extends
|
|
|
9
20
|
observations: readonly Observation[];
|
|
10
21
|
requirements: readonly Requirement[];
|
|
11
22
|
}) => boolean;
|
|
12
|
-
missing({ observations, requirements }: {
|
|
23
|
+
missing({ observations, requirements, }: {
|
|
13
24
|
observations: readonly Observation[];
|
|
14
25
|
requirements: readonly Requirement[];
|
|
15
26
|
}): Requirement[];
|
|
16
27
|
}>;
|
|
17
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Compile a projection that keeps only the sources a caller asked to see.
|
|
30
|
+
*
|
|
31
|
+
* No selection retains the complete evidence; a selection narrows registered source-bearing
|
|
32
|
+
* results. Observations whose tool has no provider pass through untouched, so the projection
|
|
33
|
+
* can only ever remove sources it knows how to name.
|
|
34
|
+
*
|
|
35
|
+
* @param definition - Source id selector, optional tool id selector, and per-tool providers.
|
|
36
|
+
* @returns A frozen object whose `project({ observations, sourceIds })` returns new values.
|
|
37
|
+
* @throws TypeError For a provider without both handlers; selectors and handlers must be
|
|
38
|
+
* synchronous.
|
|
39
|
+
*/
|
|
18
40
|
export declare function defineEvidenceProjection<Observation, Source>(definition: EvidenceProjectionDefinition<Observation, Source>): Readonly<{
|
|
19
|
-
project({ observations, sourceIds }: {
|
|
41
|
+
project({ observations, sourceIds, }: {
|
|
20
42
|
observations: Observation[];
|
|
21
43
|
sourceIds?: readonly string[];
|
|
22
44
|
}): Observation[];
|
|
23
45
|
}>;
|
|
24
|
-
export type { EvidenceRequirement, EvidenceProvider, EvidenceProjectionDefinition, EvidenceProjectionProvider } from '../structs/kits/evidence.js';
|
|
46
|
+
export type { EvidenceRequirement, EvidenceProvider, EvidenceProjectionDefinition, EvidenceProjectionProvider, } from '../structs/kits/evidence.js';
|
|
47
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
25
48
|
export declare const Evidence: Readonly<{
|
|
26
49
|
defineEvidenceChecklist: typeof defineEvidenceChecklist;
|
|
27
50
|
defineEvidenceProjection: typeof defineEvidenceProjection;
|
|
@@ -1,51 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evidence Kit: check completion requirements against observations and narrow observations.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: an optional App-side library for "did we actually observe enough"
|
|
5
|
+
* logic. This module only compares observations with registered providers; what counts as
|
|
6
|
+
* evidence, where observations come from and how they are stored remain App-owned.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `defineEvidenceChecklist`, `defineEvidenceProjection`, `Evidence`, and the
|
|
9
|
+
* evidence requirement/provider/projection types.
|
|
10
|
+
*/
|
|
1
11
|
import { synchronous, booleanResult } from '../utils/synchronous.js';
|
|
2
12
|
import { breakWhile } from '../utils/rules.js';
|
|
3
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Compile a reusable completion checklist over actual observations.
|
|
15
|
+
*
|
|
16
|
+
* A requirement is satisfied when at least one observation satisfies the provider registered
|
|
17
|
+
* for its `kind`; `isComplete` requires every requirement to be satisfied, and `missing`
|
|
18
|
+
* returns those that are not. Hosts define evidence semantics.
|
|
19
|
+
*
|
|
20
|
+
* @param definitions - One provider per evidence kind, each with an `isSatisfied` predicate.
|
|
21
|
+
* @returns A frozen checklist exposing `isSatisfied`, `isComplete` and `missing`.
|
|
22
|
+
* @throws TypeError For duplicate kinds, missing predicates, or an unknown requirement kind;
|
|
23
|
+
* predicates must return a boolean synchronously.
|
|
24
|
+
*/
|
|
4
25
|
export function defineEvidenceChecklist(definitions) {
|
|
5
26
|
const providers = new Map();
|
|
6
27
|
for (const definition of definitions) {
|
|
7
28
|
const predicate = definition.isSatisfied;
|
|
8
29
|
breakWhile([
|
|
9
|
-
{
|
|
10
|
-
|
|
30
|
+
{
|
|
31
|
+
occur: () => providers.has(definition.kind),
|
|
32
|
+
error: () => `Duplicate evidence kind: ${definition.kind}`,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
occur: () => typeof predicate !== 'function',
|
|
36
|
+
error: () => `Missing evidence provider: ${definition.kind}`,
|
|
37
|
+
},
|
|
11
38
|
]);
|
|
12
|
-
providers.set(definition.kind, Object.freeze({
|
|
39
|
+
providers.set(definition.kind, Object.freeze({
|
|
40
|
+
kind: definition.kind,
|
|
41
|
+
description: definition.description,
|
|
42
|
+
isSatisfied: predicate.bind(definition),
|
|
43
|
+
}));
|
|
13
44
|
}
|
|
14
45
|
const satisfied = (observations, requirement) => {
|
|
15
46
|
const provider = providers.get(requirement.kind);
|
|
16
47
|
breakWhile(!provider, () => `Unknown evidence kind: ${requirement.kind}`);
|
|
17
|
-
return observations.some(observation => booleanResult(provider.isSatisfied(observation, requirement), 'Evidence predicates must be synchronous', 'Evidence predicates must return boolean'));
|
|
48
|
+
return observations.some((observation) => booleanResult(provider.isSatisfied(observation, requirement), 'Evidence predicates must be synchronous', 'Evidence predicates must return boolean'));
|
|
18
49
|
};
|
|
19
50
|
return Object.freeze({
|
|
20
51
|
isSatisfied: (request) => satisfied(request.observations, request.requirement),
|
|
21
|
-
isComplete: (request) => request.requirements.every(requirement => satisfied(request.observations, requirement)),
|
|
22
|
-
missing({ observations, requirements }) {
|
|
23
|
-
return requirements.filter(requirement => !satisfied(observations, requirement));
|
|
52
|
+
isComplete: (request) => request.requirements.every((requirement) => satisfied(request.observations, requirement)),
|
|
53
|
+
missing({ observations, requirements, }) {
|
|
54
|
+
return requirements.filter((requirement) => !satisfied(observations, requirement));
|
|
24
55
|
},
|
|
25
56
|
});
|
|
26
57
|
}
|
|
27
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Compile a projection that keeps only the sources a caller asked to see.
|
|
60
|
+
*
|
|
61
|
+
* No selection retains the complete evidence; a selection narrows registered source-bearing
|
|
62
|
+
* results. Observations whose tool has no provider pass through untouched, so the projection
|
|
63
|
+
* can only ever remove sources it knows how to name.
|
|
64
|
+
*
|
|
65
|
+
* @param definition - Source id selector, optional tool id selector, and per-tool providers.
|
|
66
|
+
* @returns A frozen object whose `project({ observations, sourceIds })` returns new values.
|
|
67
|
+
* @throws TypeError For a provider without both handlers; selectors and handlers must be
|
|
68
|
+
* synchronous.
|
|
69
|
+
*/
|
|
28
70
|
export function defineEvidenceProjection(definition) {
|
|
29
71
|
const sourceId = definition.sourceId.bind(definition);
|
|
30
|
-
const toolId = definition.toolId?.bind(definition) ??
|
|
72
|
+
const toolId = definition.toolId?.bind(definition) ??
|
|
73
|
+
((observation) => {
|
|
74
|
+
// Fallback tool selector: accept either the current `toolId` field or the legacy `tool`.
|
|
75
|
+
const value = observation;
|
|
76
|
+
return value.toolId ?? value.tool;
|
|
77
|
+
});
|
|
31
78
|
const providers = new Map();
|
|
32
79
|
for (const [tool, provider] of Object.entries(definition.providers)) {
|
|
33
|
-
breakWhile(![provider.sources, provider.withSources].every(handler => typeof handler === 'function'), `Invalid evidence projection: ${tool}`);
|
|
34
|
-
providers.set(tool, Object.freeze({
|
|
80
|
+
breakWhile(![provider.sources, provider.withSources].every((handler) => typeof handler === 'function'), `Invalid evidence projection: ${tool}`);
|
|
81
|
+
providers.set(tool, Object.freeze({
|
|
82
|
+
sources: provider.sources.bind(provider),
|
|
83
|
+
withSources: provider.withSources.bind(provider),
|
|
84
|
+
}));
|
|
35
85
|
}
|
|
36
86
|
return Object.freeze({
|
|
37
|
-
project({ observations, sourceIds = [] }) {
|
|
87
|
+
project({ observations, sourceIds = [], }) {
|
|
38
88
|
// Unknown/empty claims still need review against every available candidate.
|
|
39
89
|
if (!sourceIds.length)
|
|
40
90
|
return observations;
|
|
41
|
-
return observations.map(observation => {
|
|
91
|
+
return observations.map((observation) => {
|
|
42
92
|
const provider = providers.get(synchronous(toolId(observation), 'Evidence tool selectors must be synchronous'));
|
|
43
93
|
if (!provider)
|
|
44
94
|
return observation;
|
|
45
|
-
const sources = synchronous(provider.sources(observation), 'Evidence source projection must be synchronous').filter(source => sourceIds.includes(synchronous(sourceId(source), 'Evidence source selectors must be synchronous')));
|
|
95
|
+
const sources = synchronous(provider.sources(observation), 'Evidence source projection must be synchronous').filter((source) => sourceIds.includes(synchronous(sourceId(source), 'Evidence source selectors must be synchronous')));
|
|
46
96
|
return synchronous(provider.withSources(observation, sources), 'Evidence observations must be synchronous');
|
|
47
97
|
});
|
|
48
98
|
},
|
|
49
99
|
});
|
|
50
100
|
}
|
|
101
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
51
102
|
export const Evidence = Object.freeze({ defineEvidenceChecklist, defineEvidenceProjection });
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import type { AgentFamily, FamilyDefinition } from '../structs/kits/family.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Compile a versioned family backed by an App-owned compare-and-swap store.
|
|
4
|
+
*
|
|
5
|
+
* Every mutation reads the record, verifies the caller's expected revision, then commits with
|
|
6
|
+
* a compare-and-swap, so concurrent writers fail with a revision conflict rather than
|
|
7
|
+
* overwriting each other. Reads are also treated as policy checks because the App binds its
|
|
8
|
+
* read rules into the store it supplies.
|
|
9
|
+
*
|
|
10
|
+
* @param definition - Store, authorization, validation, state predicate, branch/state snapshots
|
|
11
|
+
* and optional merge handler, clock and bounds.
|
|
12
|
+
* @returns A frozen family with `read`, `create`, `fork`, `merge` and `promote`.
|
|
13
|
+
* @throws A configured error (often `TypeError`) for an invalid id, expired or unknown record,
|
|
14
|
+
* revision conflict, exhausted capacity, lineage mismatch, missing merge configuration,
|
|
15
|
+
* invalid merge result, or changed active version.
|
|
16
|
+
*/
|
|
3
17
|
export declare function defineAgentFamily<State, App>(definition: FamilyDefinition<State, App>): AgentFamily<State, App>;
|
|
18
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
4
19
|
export declare const Family: Readonly<{
|
|
5
20
|
defineAgentFamily: typeof defineAgentFamily;
|
|
6
21
|
}>;
|
|
7
22
|
export type * from '../structs/kits/family.js';
|
|
23
|
+
/** Operation names accepted by the family `authorize` hook. */
|
|
8
24
|
export { familyOperations } from '../structs/kits/family.js';
|