@alvin0/ai-agent-sdk-core 0.1.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/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/agent/accounting/common.js +2 -0
- package/dist/agent/accounting/common.js.map +1 -0
- package/dist/agent/accounting/config.js +2 -0
- package/dist/agent/accounting/config.js.map +1 -0
- package/dist/agent/accounting/contracts.d.ts +36 -0
- package/dist/agent/accounting/contracts.d.ts.map +1 -0
- package/dist/agent/accounting/delivery/accounting-data.js +2 -0
- package/dist/agent/accounting/delivery/accounting-data.js.map +1 -0
- package/dist/agent/accounting/delivery/config.js +2 -0
- package/dist/agent/accounting/delivery/config.js.map +1 -0
- package/dist/agent/accounting/delivery/data.js +2 -0
- package/dist/agent/accounting/delivery/data.js.map +1 -0
- package/dist/agent/accounting/delivery/support-errors.js +2 -0
- package/dist/agent/accounting/delivery/support-errors.js.map +1 -0
- package/dist/agent/accounting/delivery/terminal.js +2 -0
- package/dist/agent/accounting/delivery/terminal.js.map +1 -0
- package/dist/agent/accounting/delivery-types.d.ts +43 -0
- package/dist/agent/accounting/delivery-types.d.ts.map +1 -0
- package/dist/agent/accounting/error.d.ts +18 -0
- package/dist/agent/accounting/error.d.ts.map +1 -0
- package/dist/agent/accounting/error.js +2 -0
- package/dist/agent/accounting/error.js.map +1 -0
- package/dist/agent/accounting/estimate.js +2 -0
- package/dist/agent/accounting/estimate.js.map +1 -0
- package/dist/agent/accounting/event-buffer.js +2 -0
- package/dist/agent/accounting/event-buffer.js.map +1 -0
- package/dist/agent/accounting/ledger.js +2 -0
- package/dist/agent/accounting/ledger.js.map +1 -0
- package/dist/agent/accounting/report.d.ts +70 -0
- package/dist/agent/accounting/report.d.ts.map +1 -0
- package/dist/agent/accounting/usage.d.ts +13 -0
- package/dist/agent/accounting/usage.d.ts.map +1 -0
- package/dist/agent/accounting/usage.js +2 -0
- package/dist/agent/accounting/usage.js.map +1 -0
- package/dist/agent/context/section.d.ts +15 -0
- package/dist/agent/context/section.d.ts.map +1 -0
- package/dist/agent/context/section.js +2 -0
- package/dist/agent/context/section.js.map +1 -0
- package/dist/agent/context/types.d.ts +98 -0
- package/dist/agent/context/types.d.ts.map +1 -0
- package/dist/agent/define/definition.d.ts +110 -0
- package/dist/agent/define/definition.d.ts.map +1 -0
- package/dist/agent/define/definition.js +2 -0
- package/dist/agent/define/definition.js.map +1 -0
- package/dist/agent/define/instructions.js +2 -0
- package/dist/agent/define/instructions.js.map +1 -0
- package/dist/agent/define/output-format.js +2 -0
- package/dist/agent/define/output-format.js.map +1 -0
- package/dist/agent/define/session/accounting.js +2 -0
- package/dist/agent/define/session/accounting.js.map +1 -0
- package/dist/agent/define/session/common.js +2 -0
- package/dist/agent/define/session/common.js.map +1 -0
- package/dist/agent/define/session/config.js +2 -0
- package/dist/agent/define/session/config.js.map +1 -0
- package/dist/agent/define/session/model-config.js +2 -0
- package/dist/agent/define/session/model-config.js.map +1 -0
- package/dist/agent/define/session/observer.js +2 -0
- package/dist/agent/define/session/observer.js.map +1 -0
- package/dist/agent/define/session/run-seal.js +2 -0
- package/dist/agent/define/session/run-seal.js.map +1 -0
- package/dist/agent/define/session/runtime-binding.js +2 -0
- package/dist/agent/define/session/runtime-binding.js.map +1 -0
- package/dist/agent/define/session/runtime-compaction.js +2 -0
- package/dist/agent/define/session/runtime-compaction.js.map +1 -0
- package/dist/agent/define/session/runtime-memory.js +2 -0
- package/dist/agent/define/session/runtime-memory.js.map +1 -0
- package/dist/agent/define/session/skills.js +2 -0
- package/dist/agent/define/session/skills.js.map +1 -0
- package/dist/agent/define/session/trace-accounting.js +2 -0
- package/dist/agent/define/session/trace-accounting.js.map +1 -0
- package/dist/agent/define/session/types.d.ts +217 -0
- package/dist/agent/define/session/types.d.ts.map +1 -0
- package/dist/agent/define/session/validation.js +2 -0
- package/dist/agent/define/session/validation.js.map +1 -0
- package/dist/agent/define/session.d.ts +77 -0
- package/dist/agent/define/session.d.ts.map +1 -0
- package/dist/agent/define/session.js +2 -0
- package/dist/agent/define/session.js.map +1 -0
- package/dist/agent/history/config.js +2 -0
- package/dist/agent/history/config.js.map +1 -0
- package/dist/agent/history/history.d.ts +33 -0
- package/dist/agent/history/history.d.ts.map +1 -0
- package/dist/agent/history/history.js +2 -0
- package/dist/agent/history/history.js.map +1 -0
- package/dist/agent/history/normalize.d.ts +7 -0
- package/dist/agent/history/normalize.d.ts.map +1 -0
- package/dist/agent/history/normalize.js +2 -0
- package/dist/agent/history/normalize.js.map +1 -0
- package/dist/agent/history/project.d.ts +14 -0
- package/dist/agent/history/project.d.ts.map +1 -0
- package/dist/agent/history/project.js +2 -0
- package/dist/agent/history/project.js.map +1 -0
- package/dist/agent/history/types.d.ts +85 -0
- package/dist/agent/history/types.d.ts.map +1 -0
- package/dist/agent/history/validation.js +2 -0
- package/dist/agent/history/validation.js.map +1 -0
- package/dist/agent/loop/events.d.ts +213 -0
- package/dist/agent/loop/events.d.ts.map +1 -0
- package/dist/agent/loop/queue.js +2 -0
- package/dist/agent/loop/queue.js.map +1 -0
- package/dist/agent/loop/run-turn.d.ts +8 -0
- package/dist/agent/loop/run-turn.d.ts.map +1 -0
- package/dist/agent/loop/run-turn.js +2 -0
- package/dist/agent/loop/run-turn.js.map +1 -0
- package/dist/agent/loop/schedule.d.ts +62 -0
- package/dist/agent/loop/schedule.d.ts.map +1 -0
- package/dist/agent/loop/schedule.js +3 -0
- package/dist/agent/loop/schedule.js.map +1 -0
- package/dist/agent/loop/turn/cancellation.js +2 -0
- package/dist/agent/loop/turn/cancellation.js.map +1 -0
- package/dist/agent/loop/turn/common.js +2 -0
- package/dist/agent/loop/turn/common.js.map +1 -0
- package/dist/agent/loop/turn/config.js +2 -0
- package/dist/agent/loop/turn/config.js.map +1 -0
- package/dist/agent/loop/turn/content.js +4 -0
- package/dist/agent/loop/turn/content.js.map +1 -0
- package/dist/agent/loop/turn/hooks.js +2 -0
- package/dist/agent/loop/turn/hooks.js.map +1 -0
- package/dist/agent/loop/turn/model-round.js +2 -0
- package/dist/agent/loop/turn/model-round.js.map +1 -0
- package/dist/agent/loop/turn/repetition.js +2 -0
- package/dist/agent/loop/turn/repetition.js.map +1 -0
- package/dist/agent/loop/turn/types.d.ts +82 -0
- package/dist/agent/loop/turn/types.d.ts.map +1 -0
- package/dist/agent/loop/turn/usage-stop.js +2 -0
- package/dist/agent/loop/turn/usage-stop.js.map +1 -0
- package/dist/agent/loop/turn/validation.js +2 -0
- package/dist/agent/loop/turn/validation.js.map +1 -0
- package/dist/agent/loop/types.d.ts +82 -0
- package/dist/agent/loop/types.d.ts.map +1 -0
- package/dist/agent/memory/accounting-binding.js +2 -0
- package/dist/agent/memory/accounting-binding.js.map +1 -0
- package/dist/agent/memory/compaction-config.d.ts +63 -0
- package/dist/agent/memory/compaction-config.d.ts.map +1 -0
- package/dist/agent/memory/compaction-config.js +2 -0
- package/dist/agent/memory/compaction-config.js.map +1 -0
- package/dist/agent/memory/compaction.d.ts +62 -0
- package/dist/agent/memory/compaction.d.ts.map +1 -0
- package/dist/agent/memory/compaction.js +6 -0
- package/dist/agent/memory/compaction.js.map +1 -0
- package/dist/agent/memory/memory.d.ts +61 -0
- package/dist/agent/memory/memory.d.ts.map +1 -0
- package/dist/agent/memory/memory.js +5 -0
- package/dist/agent/memory/memory.js.map +1 -0
- package/dist/agent/memory/persistence-types.d.ts +44 -0
- package/dist/agent/memory/persistence-types.d.ts.map +1 -0
- package/dist/agent/memory/surface-compaction.d.ts +6 -0
- package/dist/agent/memory/surface-compaction.d.ts.map +1 -0
- package/dist/agent/memory/surface-compaction.js +4 -0
- package/dist/agent/memory/surface-compaction.js.map +1 -0
- package/dist/agent/memory/token-estimator.d.ts +12 -0
- package/dist/agent/memory/token-estimator.d.ts.map +1 -0
- package/dist/agent/memory/token-estimator.js +2 -0
- package/dist/agent/memory/token-estimator.js.map +1 -0
- package/dist/agent/mode/run-agent.d.ts +79 -0
- package/dist/agent/mode/run-agent.d.ts.map +1 -0
- package/dist/agent/mode/run-agent.js +4 -0
- package/dist/agent/mode/run-agent.js.map +1 -0
- package/dist/agent/mode/user-input.d.ts +61 -0
- package/dist/agent/mode/user-input.d.ts.map +1 -0
- package/dist/agent/mode/user-input.js +2 -0
- package/dist/agent/mode/user-input.js.map +1 -0
- package/dist/agent/skill/catalog.d.ts +53 -0
- package/dist/agent/skill/catalog.d.ts.map +1 -0
- package/dist/agent/skill/catalog.js +2 -0
- package/dist/agent/skill/catalog.js.map +1 -0
- package/dist/agent/skill/definition.d.ts +106 -0
- package/dist/agent/skill/definition.d.ts.map +1 -0
- package/dist/agent/skill/definition.js +2 -0
- package/dist/agent/skill/definition.js.map +1 -0
- package/dist/agent/skill/provider/config.d.ts +11 -0
- package/dist/agent/skill/provider/config.d.ts.map +1 -0
- package/dist/agent/skill/provider/config.js +2 -0
- package/dist/agent/skill/provider/config.js.map +1 -0
- package/dist/agent/skill/provider/context.js +2 -0
- package/dist/agent/skill/provider/context.js.map +1 -0
- package/dist/agent/skill/provider/definition.d.ts +6 -0
- package/dist/agent/skill/provider/definition.d.ts.map +1 -0
- package/dist/agent/skill/provider/definition.js +2 -0
- package/dist/agent/skill/provider/definition.js.map +1 -0
- package/dist/agent/skill/provider/snapshot.js +2 -0
- package/dist/agent/skill/provider/snapshot.js.map +1 -0
- package/dist/agent/skill/provider/types.d.ts +49 -0
- package/dist/agent/skill/provider/types.d.ts.map +1 -0
- package/dist/agent/skill/tools.d.ts +45 -0
- package/dist/agent/skill/tools.d.ts.map +1 -0
- package/dist/agent/skill/tools.js +14 -0
- package/dist/agent/skill/tools.js.map +1 -0
- package/dist/agent/team/common.d.ts +26 -0
- package/dist/agent/team/common.d.ts.map +1 -0
- package/dist/agent/team/common.js +2 -0
- package/dist/agent/team/common.js.map +1 -0
- package/dist/agent/team/composed.d.ts +45 -0
- package/dist/agent/team/composed.d.ts.map +1 -0
- package/dist/agent/team/composed.js +2 -0
- package/dist/agent/team/composed.js.map +1 -0
- package/dist/agent/team/contracts.d.ts +54 -0
- package/dist/agent/team/contracts.d.ts.map +1 -0
- package/dist/agent/team/managed.d.ts +527 -0
- package/dist/agent/team/managed.d.ts.map +1 -0
- package/dist/agent/team/managed.js +4 -0
- package/dist/agent/team/managed.js.map +1 -0
- package/dist/agent/team/team.d.ts +142 -0
- package/dist/agent/team/team.d.ts.map +1 -0
- package/dist/agent/team/team.js +2 -0
- package/dist/agent/team/team.js.map +1 -0
- package/dist/agent/team/types.d.ts +170 -0
- package/dist/agent/team/types.d.ts.map +1 -0
- package/dist/agent/tool/approval.d.ts +106 -0
- package/dist/agent/tool/approval.d.ts.map +1 -0
- package/dist/agent/tool/approval.js +2 -0
- package/dist/agent/tool/approval.js.map +1 -0
- package/dist/agent/tool/capture.js +2 -0
- package/dist/agent/tool/capture.js.map +1 -0
- package/dist/agent/tool/config.js +2 -0
- package/dist/agent/tool/config.js.map +1 -0
- package/dist/agent/tool/definition.d.ts +227 -0
- package/dist/agent/tool/definition.d.ts.map +1 -0
- package/dist/agent/tool/definition.js +2 -0
- package/dist/agent/tool/definition.js.map +1 -0
- package/dist/agent/tool/errors.d.ts +82 -0
- package/dist/agent/tool/errors.d.ts.map +1 -0
- package/dist/agent/tool/errors.js +2 -0
- package/dist/agent/tool/errors.js.map +1 -0
- package/dist/agent/tool/execution.d.ts +60 -0
- package/dist/agent/tool/execution.d.ts.map +1 -0
- package/dist/agent/tool/execution.js +2 -0
- package/dist/agent/tool/execution.js.map +1 -0
- package/dist/agent/tool/output-budget.d.ts +159 -0
- package/dist/agent/tool/output-budget.d.ts.map +1 -0
- package/dist/agent/tool/output-budget.js +3 -0
- package/dist/agent/tool/output-budget.js.map +1 -0
- package/dist/agent/tool/pipeline.d.ts +98 -0
- package/dist/agent/tool/pipeline.d.ts.map +1 -0
- package/dist/agent/tool/pipeline.js +4 -0
- package/dist/agent/tool/pipeline.js.map +1 -0
- package/dist/agent/tool/registry.d.ts +70 -0
- package/dist/agent/tool/registry.d.ts.map +1 -0
- package/dist/agent/tool/registry.js +2 -0
- package/dist/agent/tool/registry.js.map +1 -0
- package/dist/agent/tool/schema.d.ts +12 -0
- package/dist/agent/tool/schema.d.ts.map +1 -0
- package/dist/agent/tool/schema.js +2 -0
- package/dist/agent/tool/schema.js.map +1 -0
- package/dist/agent/tool/source-types.d.ts +25 -0
- package/dist/agent/tool/source-types.d.ts.map +1 -0
- package/dist/agent/trace/trace.d.ts +63 -0
- package/dist/agent/trace/trace.d.ts.map +1 -0
- package/dist/agent/trace/trace.js +2 -0
- package/dist/agent/trace/trace.js.map +1 -0
- package/dist/agent.d.ts +52 -0
- package/dist/agent.js +1 -0
- package/dist/async/settlement.d.ts +6 -0
- package/dist/async/settlement.d.ts.map +1 -0
- package/dist/async/settlement.js +2 -0
- package/dist/async/settlement.js.map +1 -0
- package/dist/capability/common/config.js +2 -0
- package/dist/capability/common/config.js.map +1 -0
- package/dist/capability/common/data.js +2 -0
- package/dist/capability/common/data.js.map +1 -0
- package/dist/composition/agent/author.d.ts +12 -0
- package/dist/composition/agent/author.d.ts.map +1 -0
- package/dist/composition/agent/author.js +2 -0
- package/dist/composition/agent/author.js.map +1 -0
- package/dist/composition/agent/definition.js +2 -0
- package/dist/composition/agent/definition.js.map +1 -0
- package/dist/composition/agent/native-event.js +2 -0
- package/dist/composition/agent/native-event.js.map +1 -0
- package/dist/composition/agent/native-tools.js +2 -0
- package/dist/composition/agent/native-tools.js.map +1 -0
- package/dist/composition/agent/options.js +2 -0
- package/dist/composition/agent/options.js.map +1 -0
- package/dist/composition/agent/policy.js +2 -0
- package/dist/composition/agent/policy.js.map +1 -0
- package/dist/composition/agent/public-message.js +2 -0
- package/dist/composition/agent/public-message.js.map +1 -0
- package/dist/composition/agent/session.js +2 -0
- package/dist/composition/agent/session.js.map +1 -0
- package/dist/composition/agent/types.d.ts +218 -0
- package/dist/composition/agent/types.d.ts.map +1 -0
- package/dist/composition/common/counter.js +2 -0
- package/dist/composition/common/counter.js.map +1 -0
- package/dist/composition/common/errors.d.ts +15 -0
- package/dist/composition/common/errors.d.ts.map +1 -0
- package/dist/composition/common/errors.js +2 -0
- package/dist/composition/common/errors.js.map +1 -0
- package/dist/composition/common/json-data.js +2 -0
- package/dist/composition/common/json-data.js.map +1 -0
- package/dist/composition/credential/config.d.ts +5 -0
- package/dist/composition/credential/config.d.ts.map +1 -0
- package/dist/composition/credential/config.js +2 -0
- package/dist/composition/credential/config.js.map +1 -0
- package/dist/composition/credential/definition.d.ts +9 -0
- package/dist/composition/credential/definition.d.ts.map +1 -0
- package/dist/composition/credential/definition.js +2 -0
- package/dist/composition/credential/definition.js.map +1 -0
- package/dist/composition/credential/types.d.ts +38 -0
- package/dist/composition/credential/types.d.ts.map +1 -0
- package/dist/composition/delivery/ack.js +2 -0
- package/dist/composition/delivery/ack.js.map +1 -0
- package/dist/composition/delivery/attempt.js +2 -0
- package/dist/composition/delivery/attempt.js.map +1 -0
- package/dist/composition/delivery/batch.js +2 -0
- package/dist/composition/delivery/batch.js.map +1 -0
- package/dist/composition/delivery/checkpoint.js +2 -0
- package/dist/composition/delivery/checkpoint.js.map +1 -0
- package/dist/composition/delivery/event.js +2 -0
- package/dist/composition/delivery/event.js.map +1 -0
- package/dist/composition/delivery/resource.d.ts +11 -0
- package/dist/composition/delivery/resource.d.ts.map +1 -0
- package/dist/composition/delivery/resource.js +2 -0
- package/dist/composition/delivery/resource.js.map +1 -0
- package/dist/composition/delivery/staging.js +2 -0
- package/dist/composition/delivery/staging.js.map +1 -0
- package/dist/composition/diagnostics/config.js +2 -0
- package/dist/composition/diagnostics/config.js.map +1 -0
- package/dist/composition/diagnostics/ring.d.ts +12 -0
- package/dist/composition/diagnostics/ring.d.ts.map +1 -0
- package/dist/composition/diagnostics/ring.js +2 -0
- package/dist/composition/diagnostics/ring.js.map +1 -0
- package/dist/composition/exporter/definition.d.ts +7 -0
- package/dist/composition/exporter/definition.d.ts.map +1 -0
- package/dist/composition/exporter/definition.js +2 -0
- package/dist/composition/exporter/definition.js.map +1 -0
- package/dist/composition/exporter/lifecycle.js +2 -0
- package/dist/composition/exporter/lifecycle.js.map +1 -0
- package/dist/composition/exporter/preflight.js +2 -0
- package/dist/composition/exporter/preflight.js.map +1 -0
- package/dist/composition/exporter/types.d.ts +25 -0
- package/dist/composition/exporter/types.d.ts.map +1 -0
- package/dist/composition/exporter/types.js +2 -0
- package/dist/composition/exporter/types.js.map +1 -0
- package/dist/composition/identity/agent.js +2 -0
- package/dist/composition/identity/agent.js.map +1 -0
- package/dist/composition/lifecycle/bounded.js +2 -0
- package/dist/composition/lifecycle/bounded.js.map +1 -0
- package/dist/composition/lifecycle/operations.js +2 -0
- package/dist/composition/lifecycle/operations.js.map +1 -0
- package/dist/composition/lifecycle/types.d.ts +13 -0
- package/dist/composition/lifecycle/types.d.ts.map +1 -0
- package/dist/composition/lifecycle/types.js +2 -0
- package/dist/composition/lifecycle/types.js.map +1 -0
- package/dist/composition/logging/config.js +2 -0
- package/dist/composition/logging/config.js.map +1 -0
- package/dist/composition/logging/integration.js +2 -0
- package/dist/composition/logging/integration.js.map +1 -0
- package/dist/composition/logging/logger.d.ts +9 -0
- package/dist/composition/logging/logger.d.ts.map +1 -0
- package/dist/composition/logging/logger.js +2 -0
- package/dist/composition/logging/logger.js.map +1 -0
- package/dist/composition/memory/config.d.ts +10 -0
- package/dist/composition/memory/config.d.ts.map +1 -0
- package/dist/composition/memory/config.js +2 -0
- package/dist/composition/memory/config.js.map +1 -0
- package/dist/composition/memory/definition.d.ts +7 -0
- package/dist/composition/memory/definition.d.ts.map +1 -0
- package/dist/composition/memory/definition.js +2 -0
- package/dist/composition/memory/definition.js.map +1 -0
- package/dist/composition/memory/key.js +2 -0
- package/dist/composition/memory/key.js.map +1 -0
- package/dist/composition/memory/resume.js +2 -0
- package/dist/composition/memory/resume.js.map +1 -0
- package/dist/composition/memory/run.js +2 -0
- package/dist/composition/memory/run.js.map +1 -0
- package/dist/composition/model-catalog/config.js +2 -0
- package/dist/composition/model-catalog/config.js.map +1 -0
- package/dist/composition/model-catalog/manager.js +2 -0
- package/dist/composition/model-catalog/manager.js.map +1 -0
- package/dist/composition/model-catalog/options.js +2 -0
- package/dist/composition/model-catalog/options.js.map +1 -0
- package/dist/composition/model-catalog/types.d.ts +9 -0
- package/dist/composition/model-catalog/types.d.ts.map +1 -0
- package/dist/composition/observation/config.js +2 -0
- package/dist/composition/observation/config.js.map +1 -0
- package/dist/composition/observation/extensions.js +2 -0
- package/dist/composition/observation/extensions.js.map +1 -0
- package/dist/composition/observation/final-report.d.ts +6 -0
- package/dist/composition/observation/final-report.d.ts.map +1 -0
- package/dist/composition/observation/final-report.js +2 -0
- package/dist/composition/observation/final-report.js.map +1 -0
- package/dist/composition/observation/health.d.ts +13 -0
- package/dist/composition/observation/health.d.ts.map +1 -0
- package/dist/composition/observation/port.d.ts +11 -0
- package/dist/composition/observation/port.d.ts.map +1 -0
- package/dist/composition/observation/port.js +2 -0
- package/dist/composition/observation/port.js.map +1 -0
- package/dist/composition/preflight.js +2 -0
- package/dist/composition/preflight.js.map +1 -0
- package/dist/composition/provider/activation.js +2 -0
- package/dist/composition/provider/activation.js.map +1 -0
- package/dist/composition/provider/definition.d.ts +7 -0
- package/dist/composition/provider/definition.d.ts.map +1 -0
- package/dist/composition/provider/definition.js +2 -0
- package/dist/composition/provider/definition.js.map +1 -0
- package/dist/composition/provider/model-selection.js +2 -0
- package/dist/composition/provider/model-selection.js.map +1 -0
- package/dist/composition/provider/preflight.js +2 -0
- package/dist/composition/provider/preflight.js.map +1 -0
- package/dist/composition/provider/types.d.ts +38 -0
- package/dist/composition/provider/types.d.ts.map +1 -0
- package/dist/composition/provider/types.js +2 -0
- package/dist/composition/provider/types.js.map +1 -0
- package/dist/composition/queue/config.js +2 -0
- package/dist/composition/queue/config.js.map +1 -0
- package/dist/composition/queue/scheduler.js +2 -0
- package/dist/composition/queue/scheduler.js.map +1 -0
- package/dist/composition/queue/store.js +2 -0
- package/dist/composition/queue/store.js.map +1 -0
- package/dist/composition/runtime/config.js +2 -0
- package/dist/composition/runtime/config.js.map +1 -0
- package/dist/composition/runtime/owner.js +2 -0
- package/dist/composition/runtime/owner.js.map +1 -0
- package/dist/composition/runtime/public.d.ts +7 -0
- package/dist/composition/runtime/public.d.ts.map +1 -0
- package/dist/composition/runtime/public.js +2 -0
- package/dist/composition/runtime/public.js.map +1 -0
- package/dist/composition/runtime/types.d.ts +76 -0
- package/dist/composition/runtime/types.d.ts.map +1 -0
- package/dist/composition/startup.js +2 -0
- package/dist/composition/startup.js.map +1 -0
- package/dist/composition/team/config.js +2 -0
- package/dist/composition/team/config.js.map +1 -0
- package/dist/composition/team/options.js +2 -0
- package/dist/composition/team/options.js.map +1 -0
- package/dist/composition/team/runtime.js +2 -0
- package/dist/composition/team/runtime.js.map +1 -0
- package/dist/composition/team/types.d.ts +63 -0
- package/dist/composition/team/types.d.ts.map +1 -0
- package/dist/composition/tool-source/config.d.ts +5 -0
- package/dist/composition/tool-source/config.d.ts.map +1 -0
- package/dist/composition/tool-source/config.js +2 -0
- package/dist/composition/tool-source/config.js.map +1 -0
- package/dist/composition/tool-source/definition.d.ts +7 -0
- package/dist/composition/tool-source/definition.d.ts.map +1 -0
- package/dist/composition/tool-source/definition.js +2 -0
- package/dist/composition/tool-source/definition.js.map +1 -0
- package/dist/composition/tool-source/snapshot.js +2 -0
- package/dist/composition/tool-source/snapshot.js.map +1 -0
- package/dist/contract/adapter.d.ts +91 -0
- package/dist/contract/adapter.d.ts.map +1 -0
- package/dist/contract/adapter.js +2 -0
- package/dist/contract/adapter.js.map +1 -0
- package/dist/contract/call-config.d.ts +36 -0
- package/dist/contract/call-config.d.ts.map +1 -0
- package/dist/contract/call-config.js +2 -0
- package/dist/contract/call-config.js.map +1 -0
- package/dist/contract/generate-options.d.ts +41 -0
- package/dist/contract/generate-options.d.ts.map +1 -0
- package/dist/contract/model-info.d.ts +99 -0
- package/dist/contract/model-info.d.ts.map +1 -0
- package/dist/contract/output-format.d.ts +18 -0
- package/dist/contract/output-format.d.ts.map +1 -0
- package/dist/contract/retry-policy.d.ts +104 -0
- package/dist/contract/retry-policy.d.ts.map +1 -0
- package/dist/contract/retry-policy.js +2 -0
- package/dist/contract/retry-policy.js.map +1 -0
- package/dist/contract/tool.d.ts +65 -0
- package/dist/contract/tool.d.ts.map +1 -0
- package/dist/contract/tool.js +2 -0
- package/dist/contract/tool.js.map +1 -0
- package/dist/errors/agent-sdk-error.d.ts +88 -0
- package/dist/errors/agent-sdk-error.d.ts.map +1 -0
- package/dist/errors/agent-sdk-error.js +2 -0
- package/dist/errors/agent-sdk-error.js.map +1 -0
- package/dist/errors/capability-identity.d.ts +10 -0
- package/dist/errors/capability-identity.d.ts.map +1 -0
- package/dist/errors/capability-identity.js +2 -0
- package/dist/errors/capability-identity.js.map +1 -0
- package/dist/errors/failure.d.ts +33 -0
- package/dist/errors/failure.d.ts.map +1 -0
- package/dist/errors/failure.js +2 -0
- package/dist/errors/failure.js.map +1 -0
- package/dist/errors/model-error.d.ts +83 -0
- package/dist/errors/model-error.d.ts.map +1 -0
- package/dist/errors/model-error.js +2 -0
- package/dist/errors/model-error.js.map +1 -0
- package/dist/http/api-key.d.ts +47 -0
- package/dist/http/api-key.d.ts.map +1 -0
- package/dist/http/api-key.js +2 -0
- package/dist/http/api-key.js.map +1 -0
- package/dist/http/attribution.d.ts +51 -0
- package/dist/http/attribution.d.ts.map +1 -0
- package/dist/http/attribution.js +2 -0
- package/dist/http/attribution.js.map +1 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +1 -0
- package/dist/logging/types.d.ts +53 -0
- package/dist/logging/types.d.ts.map +1 -0
- package/dist/logging/types.js +2 -0
- package/dist/logging/types.js.map +1 -0
- package/dist/memory.d.ts +10 -0
- package/dist/memory.js +1 -0
- package/dist/message/content.d.ts +125 -0
- package/dist/message/content.d.ts.map +1 -0
- package/dist/message/message.d.ts +154 -0
- package/dist/message/message.d.ts.map +1 -0
- package/dist/message/message.js +2 -0
- package/dist/message/message.js.map +1 -0
- package/dist/message/projection.d.ts +34 -0
- package/dist/message/projection.d.ts.map +1 -0
- package/dist/message/projection.js +2 -0
- package/dist/message/projection.js.map +1 -0
- package/dist/observability/bus.d.ts +7 -0
- package/dist/observability/bus.d.ts.map +1 -0
- package/dist/observability/bus.js +2 -0
- package/dist/observability/bus.js.map +1 -0
- package/dist/observability/exporters.d.ts +39 -0
- package/dist/observability/exporters.d.ts.map +1 -0
- package/dist/observability/exporters.js +2 -0
- package/dist/observability/exporters.js.map +1 -0
- package/dist/observability/logger.js +2 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/projections.d.ts +12 -0
- package/dist/observability/projections.d.ts.map +1 -0
- package/dist/observability/projections.js +2 -0
- package/dist/observability/projections.js.map +1 -0
- package/dist/observability/types.d.ts +103 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability.d.ts +20 -0
- package/dist/observability.js +1 -0
- package/dist/observation/boundaries.js +2 -0
- package/dist/observation/boundaries.js.map +1 -0
- package/dist/observation/context.d.ts +39 -0
- package/dist/observation/context.d.ts.map +1 -0
- package/dist/observation/context.js +2 -0
- package/dist/observation/context.js.map +1 -0
- package/dist/observation/event.d.ts +50 -0
- package/dist/observation/event.d.ts.map +1 -0
- package/dist/observation/event.js +2 -0
- package/dist/observation/event.js.map +1 -0
- package/dist/observation/port.d.ts +56 -0
- package/dist/observation/port.d.ts.map +1 -0
- package/dist/observation/port.js +2 -0
- package/dist/observation/port.js.map +1 -0
- package/dist/observation/privacy.js +2 -0
- package/dist/observation/privacy.js.map +1 -0
- package/dist/observation/report.d.ts +117 -0
- package/dist/observation/report.d.ts.map +1 -0
- package/dist/observation/report.js +2 -0
- package/dist/observation/report.js.map +1 -0
- package/dist/observation/telemetry-types.d.ts +29 -0
- package/dist/observation/telemetry-types.d.ts.map +1 -0
- package/dist/observation/usage.d.ts +52 -0
- package/dist/observation/usage.d.ts.map +1 -0
- package/dist/observation/usage.js +2 -0
- package/dist/observation/usage.js.map +1 -0
- package/dist/platform/adapter.js +2 -0
- package/dist/platform/adapter.js.map +1 -0
- package/dist/platform/capability-operation.js +2 -0
- package/dist/platform/capability-operation.js.map +1 -0
- package/dist/platform/config.js +2 -0
- package/dist/platform/config.js.map +1 -0
- package/dist/platform/logger-platform.js +2 -0
- package/dist/platform/logger-platform.js.map +1 -0
- package/dist/platform/resources.js +2 -0
- package/dist/platform/resources.js.map +1 -0
- package/dist/plugin/provider-plugin.d.ts +37 -0
- package/dist/plugin/provider-plugin.d.ts.map +1 -0
- package/dist/plugin/provider-plugin.js +2 -0
- package/dist/plugin/provider-plugin.js.map +1 -0
- package/dist/primitives/brand.d.ts +61 -0
- package/dist/primitives/brand.d.ts.map +1 -0
- package/dist/primitives/brand.js +2 -0
- package/dist/primitives/brand.js.map +1 -0
- package/dist/primitives/freeze.d.ts +20 -0
- package/dist/primitives/freeze.d.ts.map +1 -0
- package/dist/primitives/freeze.js +2 -0
- package/dist/primitives/freeze.js.map +1 -0
- package/dist/primitives/json-snapshot.js +2 -0
- package/dist/primitives/json-snapshot.js.map +1 -0
- package/dist/primitives/json.d.ts +32 -0
- package/dist/primitives/json.d.ts.map +1 -0
- package/dist/primitives/json.js +2 -0
- package/dist/primitives/json.js.map +1 -0
- package/dist/primitives/never.d.ts +22 -0
- package/dist/primitives/never.d.ts.map +1 -0
- package/dist/primitives/never.js +2 -0
- package/dist/primitives/never.js.map +1 -0
- package/dist/primitives/snapshot.d.ts +10 -0
- package/dist/primitives/snapshot.d.ts.map +1 -0
- package/dist/primitives/snapshot.js +2 -0
- package/dist/primitives/snapshot.js.map +1 -0
- package/dist/primitives/version.d.ts +6 -0
- package/dist/primitives/version.d.ts.map +1 -0
- package/dist/primitives/version.js +2 -0
- package/dist/primitives/version.js.map +1 -0
- package/dist/provider.d.ts +19 -0
- package/dist/provider.js +1 -0
- package/dist/runtime/model-call-handle.js +2 -0
- package/dist/runtime/model-call-handle.js.map +1 -0
- package/dist/runtime/model-metadata.js +2 -0
- package/dist/runtime/model-metadata.js.map +1 -0
- package/dist/runtime/model-stream.js +2 -0
- package/dist/runtime/model-stream.js.map +1 -0
- package/dist/runtime/registry.d.ts +171 -0
- package/dist/runtime/registry.d.ts.map +1 -0
- package/dist/runtime/registry.js +2 -0
- package/dist/runtime/registry.js.map +1 -0
- package/dist/runtime/with-retry.d.ts +45 -0
- package/dist/runtime/with-retry.d.ts.map +1 -0
- package/dist/runtime/with-retry.js +2 -0
- package/dist/runtime/with-retry.js.map +1 -0
- package/dist/skills.d.ts +8 -0
- package/dist/skills.js +1 -0
- package/dist/stream/assembler.d.ts +86 -0
- package/dist/stream/assembler.d.ts.map +1 -0
- package/dist/stream/assembler.js +2 -0
- package/dist/stream/assembler.js.map +1 -0
- package/dist/stream/chunk.d.ts +135 -0
- package/dist/stream/chunk.d.ts.map +1 -0
- package/dist/stream/idle-timeout.d.ts +30 -0
- package/dist/stream/idle-timeout.d.ts.map +1 -0
- package/dist/stream/idle-timeout.js +2 -0
- package/dist/stream/idle-timeout.js.map +1 -0
- package/dist/support-safe/error.d.ts +29 -0
- package/dist/support-safe/error.d.ts.map +1 -0
- package/dist/support-safe/error.js +2 -0
- package/dist/support-safe/error.js.map +1 -0
- package/dist/tools.d.ts +15 -0
- package/dist/tools.js +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","names":[],"sources":["../../../src/composition/agent/policy.ts"],"sourcesContent":["import type { UsageEstimationInput, UsageEstimator, UsagePolicy } from '../../agent/accounting/report.ts'\nimport type { TurnHooks } from '../../agent/loop/events.ts'\nimport type { UserInputBroker, UserInputDecision, UserInputRequest } from '../../agent/mode/user-input.ts'\nimport type { ApprovalBroker, ApprovalDecision, ApprovalRequest } from '../../agent/tool/approval.ts'\nimport type { ToolExecutionResult } from '../../agent/tool/definition.ts'\nimport type { PostToolDecision, PreToolDecision, ToolCallContext, ToolInterceptor } from '../../agent/tool/pipeline.ts'\nimport type { SpillRecord, SpillSlice, SpillStore } from '../../agent/tool/output-budget.ts'\nimport type {\n ContextSection, ContextSectionResolveInput, ContextSectionState,\n} from '../../agent/context/types.ts'\nimport { captureContextSections } from '../../agent/context/section.ts'\nimport type { UsageCounters } from '../../observation/usage.ts'\nimport { arrayData, boundedText, objectValue, ownData } from '../common/data.ts'\n\nconst POLICY_LIMITS = Object.freeze({ interceptors: 128, contextSections: 64, identityBytes: 256 })\n\n/** Detach every section reference before an agent method can swap one. */\nexport function captureRuntimeContextSections(value: unknown): readonly ContextSection[] | undefined {\n if (value === undefined) return undefined\n return captureContextSections(arrayData(value, POLICY_LIMITS.contextSections).map((entry) => {\n const source = objectValue(entry)\n const id = boundedText(ownData(source, 'id'), POLICY_LIMITS.identityBytes)\n const resolve = captureMethod<\n [ContextSectionResolveInput],\n Promise<ContextSectionState | undefined> | ContextSectionState | undefined\n >(source, 'resolve', true)!\n const retraction = ownData(source, 'retractionText', false)\n return {\n id,\n resolve,\n ...retraction === undefined\n ? {}\n : { retractionText: boundedText(retraction, POLICY_LIMITS.identityBytes * 16) },\n }\n }))\n}\n\nexport function captureApprovalBroker(value: unknown): ApprovalBroker | undefined {\n if (value === undefined) return undefined\n const source = objectValue(value)\n const request = captureMethod<[ApprovalRequest, AbortSignal?], Promise<ApprovalDecision>>(source, 'request', true)!\n return Object.freeze({ request })\n}\n\nexport function captureUserInputBroker(value: unknown): UserInputBroker | undefined {\n if (value === undefined) return undefined\n const source = objectValue(value)\n const request = captureMethod<[UserInputRequest, AbortSignal?], Promise<UserInputDecision>>(source, 'request', true)!\n return Object.freeze({ request })\n}\n\nexport function captureSpillStore(value: unknown): SpillStore | undefined {\n if (value === undefined) return undefined\n const source = objectValue(value)\n const save = captureMethod<\n [string, { toolName: string; callId: string }], Promise<SpillRecord> | SpillRecord\n >(source, 'save', true)!\n const read = captureMethod<\n [string, { offset: number; limit: number }], Promise<SpillSlice | undefined> | SpillSlice | undefined\n >(source, 'read', true)!\n const search = captureMethod<\n [string, string, number], Promise<readonly string[] | undefined> | readonly string[] | undefined\n >(source, 'search', true)!\n return Object.freeze({ save, read, search })\n}\n\nexport function captureInterceptors(value: unknown): readonly ToolInterceptor[] | undefined {\n if (value === undefined) return undefined\n return Object.freeze(arrayData(value, POLICY_LIMITS.interceptors).map((entry) => {\n const source = objectValue(entry)\n const name = boundedText(ownData(source, 'name'), POLICY_LIMITS.identityBytes)\n const before = captureMethod<[ToolCallContext, () => Promise<PreToolDecision>], Promise<PreToolDecision>>(source, 'before', false)\n const around = captureMethod<[ToolCallContext, () => Promise<ToolExecutionResult>], Promise<ToolExecutionResult>>(source, 'around', false)\n const after = captureMethod<[\n ToolCallContext, ToolExecutionResult, () => Promise<PostToolDecision>,\n ], Promise<PostToolDecision>>(source, 'after', false)\n return Object.freeze({ name, ...(before === undefined ? {} : { before }),\n ...(around === undefined ? {} : { around }), ...(after === undefined ? {} : { after }) })\n }))\n}\n\nexport function captureTurnHooks(value: unknown): TurnHooks | undefined {\n if (value === undefined) return undefined\n const source = objectValue(value)\n const beforeStep = captureMethod<Parameters<NonNullable<TurnHooks['beforeStep']>>, ReturnType<NonNullable<TurnHooks['beforeStep']>>>(source, 'beforeStep', false)\n const onRequestError = captureMethod<Parameters<NonNullable<TurnHooks['onRequestError']>>, ReturnType<NonNullable<TurnHooks['onRequestError']>>>(source, 'onRequestError', false)\n const checkpoint = captureMethod<Parameters<NonNullable<TurnHooks['checkpoint']>>, ReturnType<NonNullable<TurnHooks['checkpoint']>>>(source, 'checkpoint', false)\n const onTurnEnd = captureMethod<Parameters<NonNullable<TurnHooks['onTurnEnd']>>, ReturnType<NonNullable<TurnHooks['onTurnEnd']>>>(source, 'onTurnEnd', false)\n return Object.freeze({ ...(beforeStep === undefined ? {} : { beforeStep }),\n ...(onRequestError === undefined ? {} : { onRequestError }),\n ...(checkpoint === undefined ? {} : { checkpoint }),\n ...(onTurnEnd === undefined ? {} : { onTurnEnd }) })\n}\n\nexport function captureUsagePolicy(value: unknown): UsagePolicy | undefined {\n if (value === undefined) return undefined\n const source = objectValue(value)\n const onMissing = ownData(source, 'onMissing', false)\n if (onMissing !== undefined && onMissing !== 'warn' && onMissing !== 'estimate' && onMissing !== 'fail') {\n throw new TypeError('Runtime usage policy is invalid')\n }\n const estimatorValue = ownData(source, 'estimator', false)\n const estimateTimeoutMs = ownData(source, 'estimateTimeoutMs', false)\n if (estimateTimeoutMs !== undefined && (typeof estimateTimeoutMs !== 'number'\n || !Number.isSafeInteger(estimateTimeoutMs) || estimateTimeoutMs < 1 || estimateTimeoutMs > 2_147_483_647)) {\n throw new TypeError('Runtime usage estimateTimeoutMs is invalid')\n }\n let estimator: UsageEstimator | undefined\n if (estimatorValue !== undefined) {\n const estimatorSource = objectValue(estimatorValue)\n const id = boundedText(ownData(estimatorSource, 'id'), POLICY_LIMITS.identityBytes)\n const estimate = captureMethod<[UsageEstimationInput], UsageCounters | Promise<UsageCounters>>(\n estimatorSource, 'estimate', true,\n )!\n estimator = Object.freeze({ id, estimate })\n }\n return Object.freeze({ ...(onMissing === undefined ? {} : { onMissing }),\n ...(estimateTimeoutMs === undefined ? {} : { estimateTimeoutMs }),\n ...(estimator === undefined ? {} : { estimator }) }) as UsagePolicy\n}\n\nfunction captureMethod<Args extends readonly unknown[], Result>(\n receiver: object,\n key: string,\n required: boolean,\n): ((...args: Args) => Result) | undefined {\n let method: unknown\n try { method = Reflect.get(receiver, key) }\n catch { throw new TypeError(`Runtime policy method '${key}' could not be captured`) }\n if (method === undefined && !required) return undefined\n if (typeof method !== 'function') throw new TypeError(`Runtime policy method '${key}' is invalid`)\n return (...args: Args): Result => Reflect.apply(method, receiver, args) as Result\n}\n"],"mappings":"mLAcA,MAAM,EAAgB,OAAO,OAAO,CAAE,aAAc,IAAK,gBAAiB,GAAI,cAAe,GAAI,CAAC,EAGlG,SAAgB,EAA8B,EAAuD,CAC/F,OAAU,IAAA,GACd,OAAO,EAAuB,EAAU,EAAO,EAAc,eAAe,CAAC,CAAC,IAAK,GAAU,CAC3F,IAAM,EA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AAK,EAAY,EAAQ,EAAiB,IAAI,EAAG,EAAc,aAAa,EAC5E,EAAW,EACf,EAAiB,WAAY,EAC/B,EACA,EAAY,OAAO,OAAO,CAAE,KAAI,UAAS,CAAC,CAC5C,CACA,OAAO,OAAO,OAAO,CAAE,GAAI,IAAc,IAAA,GAAY,CAAC,EAAI,CAAE,WAAU,EACpE,GAAI,IAAsB,IAAA,GAAY,CAAC,EAAI,CAAE,mBAAkB,EAC/D,GAAI,IAAc,IAAA,GAAY,CAAC,EAAI,CAAE,WAAU,CAAG,CAAC,CACvD,CAEA,SAAS,EACP,EACA,EACA,EACyC,CACzC,IAAI,EACJ,GAAI,CAAE,EAAS,QAAQ,IAAI,EAAU,CAAG,CAAE,MACpC,CAAE,MAAU,UAAU,0BAA0B,EAAI,wBAAwB,CAAE,CAChF,SAAW,IAAA,IAAa,CAAC,GAC7B,IAAI,OAAO,GAAW,WAAY,MAAU,UAAU,0BAA0B,EAAI,aAAa,EACjG,OAAQ,GAAG,IAAuB,QAAQ,MAAM,EAAQ,EAAU,CAAI,CAD2B,CAEnG"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{freezeMessage as e}from"../../message/message.js";function t(t){let r=t.source.kind===`model`?{kind:`model`,provider:t.source.provider,model:t.source.model}:t.source;return e({...t,source:r,content:n(t.content)})}function n(e){return e.map(e=>{let{providerState:t,...r}=e;return r.type===`text`&&r.annotations!==void 0?{...r,annotations:r.annotations.map(({providerState:e,...t})=>t)}:r.type===`native-tool-call`||r.type===`tool-result`?{...r,content:n(r.content)}:r})}export{n as publicContent,t as publicMessage};
|
|
2
|
+
//# sourceMappingURL=public-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-message.js","names":[],"sources":["../../../src/composition/agent/public-message.ts"],"sourcesContent":["import { freezeMessage } from '../../message/index.ts'\n\nexport function publicMessage(message: import('../../message/index.ts').Message): import('../../message/index.ts').Message {\n const source = message.source.kind === 'model'\n ? { kind: 'model' as const, provider: message.source.provider, model: message.source.model }\n : message.source\n return freezeMessage({ ...message, source, content: publicContent(message.content) })\n}\n\nexport function publicContent(blocks: readonly import('../../message/index.ts').ContentBlock[]): import('../../message/index.ts').ContentBlock[] {\n return blocks.map(block => {\n const { providerState: _state, ...content } = block as typeof block & { providerState?: unknown }\n if (content.type === 'text' && content.annotations !== undefined) return { ...content,\n annotations: content.annotations.map(({ providerState: _state, ...annotation }) => annotation) }\n if (content.type === 'native-tool-call' || content.type === 'tool-result') return { ...content, content: publicContent(content.content) }\n return content\n })\n}\n"],"mappings":"yDAEA,SAAgB,EAAc,EAA6F,CACzH,IAAM,EAAS,EAAQ,OAAO,OAAS,QACnC,CAAE,KAAM,QAAkB,SAAU,EAAQ,OAAO,SAAU,MAAO,EAAQ,OAAO,KAAM,EACzF,EAAQ,OACZ,OAAO,EAAc,CAAE,GAAG,EAAS,SAAQ,QAAS,EAAc,EAAQ,OAAO,CAAE,CAAC,CACtF,CAEA,SAAgB,EAAc,EAAmH,CAC/I,OAAO,EAAO,IAAI,GAAS,CACzB,GAAM,CAAE,cAAe,EAAQ,GAAG,GAAY,EAI9C,OAHI,EAAQ,OAAS,QAAU,EAAQ,cAAgB,IAAA,GAAkB,CAAE,GAAG,EAC5E,YAAa,EAAQ,YAAY,KAAK,CAAE,cAAe,EAAQ,GAAG,KAAiB,CAAU,CAAE,EAC7F,EAAQ,OAAS,oBAAsB,EAAQ,OAAS,cAAsB,CAAE,GAAG,EAAS,QAAS,EAAc,EAAQ,OAAO,CAAE,EACjI,CACT,CAAC,CACH"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{isJsonValue as e}from"../../primitives/json.js";import{detachedFrozen as t}from"../../primitives/snapshot.js";import{AgentSdkError as n}from"../../errors/agent-sdk-error.js";import{freezeMessage as r}from"../../message/message.js";import{capabilityIdentityError as i,inheritCapabilityIdentityConflict as a}from"../../errors/capability-identity.js";import{createRunTerminalRecord as o}from"../../agent/accounting/delivery/terminal.js";import{atDeadline as s}from"../lifecycle/bounded.js";import{AgentRunError as c}from"../../agent/accounting/error.js";import{TOOL_ERROR_CODES as l}from"../../agent/tool/errors.js";import{compactRuntimeSession as u,configureRuntimeSessionModel as d,streamPendingRuntimeSession as f,streamRuntimeSession as p}from"../../agent/define/session/runtime-binding.js";import{assertAgentIdentitySnapshot as m}from"../identity/agent.js";import{publicMessage as h}from"./public-message.js";import{finalizeRuntimeRunReport as g}from"../observation/final-report.js";import{snapshotToolSources as _}from"../tool-source/snapshot.js";import{createRuntimeMemoryPersistence as v}from"../memory/run.js";import{validateMemoryResumeBinding as y}from"../memory/resume.js";import{captureInvocationOptions as b,captureRuntimeSessionOptions as x}from"./options.js";import{projectNativeToolEvent as S}from"./native-event.js";const C=new WeakMap;function w(e,t){let n=Object.freeze({model:t.model,generate(n,r){return O(e,t).run(n,r)},stream(n,r){return O(e,t).stream(n,r)},createSession(n){return O(e,t,n)},resumeSession(n,r){return O(e,t,r,n)}});return C.set(n,Object.freeze({host:e,definition:t})),n}function T(e,t,r,i,a){let o=C.get(t);if(o?.host!==e)throw new n(`Runtime team members must be agents from the same runtime`,`TEAM_AGENT_OWNERSHIP_INVALID`);let s=O(e,o.definition,r,void 0,i,a);return Object.freeze({view:s,port:s.teamPort})}function E(e,t,r,i){let a=C.get(t);if(a?.host!==e)throw new n(`Runtime team members must be agents from the same runtime`,`TEAM_AGENT_OWNERSHIP_INVALID`);m({tools:[...a.definition.legacy.tools,...r.tools??[]],nativeTools:a.definition.legacy.nativeTools,skills:[...a.definition.legacy.skills,...r.skills??[]],...a.definition.legacy.skillIds===void 0?{}:{allowedSkillIds:a.definition.legacy.skillIds},additionalToolNames:i})}var D=class{host;session;nativeProvider;ownerSignal;active;observerTimeoutMs;teamPort;constructor(e,t,n,r,i=3e4,a){this.host=e,this.session=t,this.nativeProvider=n,this.ownerSignal=a,this.observerTimeoutMs=i;let o=this;this.teamPort=Object.freeze({definition:Object.freeze({id:r}),get conversationId(){return o.conversationId},get isRunning(){return o.isRunning},inject(e){return o.injectForTeam(e)},whenIdle(e){return o.whenIdle(e)},runPending(e={}){return o.runPendingForTeam(e)}})}get conversationId(){return this.session.conversationId}get isRunning(){return this.active!==void 0}stream(e,t){if(typeof e!=`string`){if(typeof e!=`object`||!e||e.role!==`user`)throw TypeError(`Runtime input must be text or a user message`);e=r(e)}let n=b(t),i=this.start(e,n);return A(i.legacy,i.report,i.result,this.nativeProvider)}start(n,r){let i=this.beginOperation(),a;try{let e=this.ownerSignal===void 0?r.signal:r.signal===void 0?this.ownerSignal:AbortSignal.any([r.signal,this.ownerSignal]);a=this.host.operations.acquire(`agent-run`,{...e===void 0?{}:{signal:e}})}catch(e){throw this.finishOperation(i),e}let o,s=r.structuredOutput,c;try{c=n===void 0?f(this.session,{signal:a.signal}):p(this.session,n,{signal:a.signal,...s===void 0?{}:{outputFormat:{type:`json_schema`,name:s.name,schema:s.schema.jsonSchema},validateOutput:n=>{let r=s.schema.parse(n);if(!e(r))throw TypeError(`structured output parser must return lossless JSON synchronously`);o=t(r)}},...r.imagePolicy===void 0?{}:{imagePolicy:r.imagePolicy}},r.additionalInstructions)}catch(e){throw a.settle(),this.finishOperation(i),e}let l=()=>c.abort();a.signal.addEventListener(`abort`,l,{once:!0}),a.signal.aborted&&l(),a.whenSealed.then(()=>c.seal()).catch(()=>void 0);let u=this.runtimeReport(c.report,c.toolSourceSnapshots,a.signal),d=this.runtimeResult(c.result,u,()=>o),m=Promise.race([c.eventsSettled,a.whenSealed]),h=Promise.allSettled([m,d,u]).then(()=>{a.signal.removeEventListener(`abort`,l),a.settle(),this.finishOperation(i)}).then(()=>d);return h.catch(()=>void 0),u.catch(()=>void 0),Object.freeze({legacy:c,report:u,result:h})}async run(e,t){let n=b(t),r=this.stream(e,n);try{for await(let e of r)if(n.onEvent!==void 0)try{await this.observe(n.onEvent,e,r)}catch(e){throw r.abort(),I(e,await r.report,`RUN_EVENT_OBSERVER_FAILED`)}}catch(e){if(F(e)===`RUN_EVENT_OBSERVER_FAILED`)throw e;return await r.result}return await r.result}inject(e){if(this.host.operations.assertActive(),this.assertOwnerActive(),this.active!==void 0)throw Error(`Cannot inject while a runtime session is active`);return this.session.inject(e)}injectForTeam(e){return this.host.operations.assertActive(),this.assertOwnerActive(),this.session.inject(e)}snapshot(){return this.session.snapshot()}compact(e){let t=b(e),n=this.beginOperation(),r;try{r=this.host.operations.execute(`manual-compaction`,{...this.ownerSignal===void 0?t.signal===void 0?{}:{signal:t.signal}:{signal:t.signal===void 0?this.ownerSignal:AbortSignal.any([t.signal,this.ownerSignal])}},async e=>{let t=await u(this.session,{signal:e.signal}),n=o(t.report),r=await this.host.observation.checkpointTerminal(n,e.signal),i=g(n,t.report.delivery,r,this.host.observation.mode,this.host.observation.requiredBoundary);if(t.failure!==void 0)throw I(t.failure,i,i.errors.at(-1)?.code??F(t.failure));return t.result===null?null:Object.freeze({...t.result,status:`completed`,report:i})})}catch(e){throw this.finishOperation(n),e}return r.finally(()=>this.finishOperation(n))}reset(){if(this.host.operations.assertActive(),this.assertOwnerActive(),this.active!==void 0)throw Error(`Cannot reset while a runtime session is active`);this.session.reset()}whenIdle(e){let t=this.active?.done;return t===void 0?Promise.resolve():e?.aborted?Promise.reject(new n(`Runtime idle wait was aborted`,`RUNTIME_OPERATION_ABORTED`)):new Promise((r,i)=>{let a=()=>void 0,o=e=>{a(),e===void 0?r():i(e)};e!==void 0&&(a=this.host.resources.onAbort(e,()=>o(new n(`Runtime idle wait was aborted`,`RUNTIME_OPERATION_ABORTED`)))),t.then(()=>o())})}async runPendingForTeam(e){let t=this.start(void 0,{...e.signal===void 0?{}:{signal:e.signal}});try{for await(let n of t.legacy)await e.onEvent?.(n)}catch(e){throw t.legacy.abort(),await t.result.catch(()=>void 0),e}return await t.result}beginOperation(){if(this.assertOwnerActive(),this.active!==void 0)throw Error(`Cannot start while a runtime session is active`);let e,t={done:new Promise(t=>{e=t}),resolve:e};return this.active=t,t}finishOperation(e){this.active===e&&(this.active=void 0,e.resolve())}assertOwnerActive(){if(this.ownerSignal?.aborted===!0)throw new n(`Runtime team session is closed`,`TEAM_CLOSED`)}async runtimeReport(e,t,n){let[r,i]=await Promise.all([e,t]),a=o(r,i),s=await this.host.observation.checkpointTerminal(a,n);return g(a,r.delivery,s,this.host.observation.mode,this.host.observation.requiredBoundary)}async runtimeResult(e,t,n){try{let r=await e,i=await t;if(i.status!==`success`)throw I(void 0,i,i.errors.at(-1)?.code??`AGENT_RUN_FAILED`);let a=n();return Object.freeze({runId:i.runId,traceId:i.traceId,completed:r.outcome.completed,stopReason:r.outcome.reason.kind,text:r.text,...a===void 0?{}:{output:a},...r.message===void 0?{}:{message:h(r.message)},usage:i.usage,report:i})}catch(e){throw I(e,await t,F(e))}}async observe(e,t,r){let i=this.host.resources.platform.monotonicNow()+this.observerTimeoutMs;try{await s(this.host.resources,i,()=>e(t),void 0)}catch{throw r.abort(),new n(`Runtime event observer did not complete`,`RUN_EVENT_OBSERVER_FAILED`)}}};function O(e,t,n={},r,i,a){e.operations.assertActive(),n=x(n),m({tools:[...t.legacy.tools,...n.tools??[]],nativeTools:t.legacy.nativeTools,skills:[...t.legacy.skills,...n.skills??[]],...t.legacy.skillIds===void 0?{}:{allowedSkillIds:t.legacy.skillIds}});let o=n.memory===!1?void 0:n.memory??t.memory;r!==void 0&&y(r,o);let s=k(t.toolSources,n.toolSources??[]),c=n.runtimeLimits,{maxSteps:l,maxToolCalls:u,...f}=c??{},p=c?.maxSteps===void 0&&c?.maxToolCalls===void 0?t.legacy:t.legacy.with({...c.maxSteps===void 0?{}:{maxTurns:c.maxSteps},...c.maxToolCalls===void 0?{}:{maxToolCalls:c.maxToolCalls}}),h={registry:e.registry,observation:e.observation,observationResource:e.resource,...n.tools===void 0?{}:{tools:n.tools},...n.skills===void 0?{}:{skills:n.skills},...n.skillCwd===void 0?{}:{skillCwd:n.skillCwd},...n.userInput===void 0?{}:{userInput:n.userInput},...n.approvals===void 0?{}:{approvals:n.approvals},...n.spillStore===void 0?{}:{spillStore:n.spillStore},...n.interceptors===void 0?{}:{interceptors:n.interceptors},...n.contextSections===void 0?{}:{contextSections:n.contextSections},...n.hooks===void 0?{}:{hooks:n.hooks},...n.usagePolicy===void 0?{}:{usagePolicy:n.usagePolicy},...n.historyLimits===void 0?{}:{historyLimits:n.historyLimits},...n.ledgerLimits===void 0?{}:{ledgerLimits:n.ledgerLimits},...n.eventBufferLimits===void 0?{}:{eventBufferLimits:n.eventBufferLimits},...n.compaction===void 0?{}:{compaction:n.compaction},...i===void 0?{}:{team:i},...Object.keys(f).length===0?{}:{runtimeLimits:f}},g=r===void 0?p.createSession({...h,...n.conversationId===void 0?{}:{conversationId:n.conversationId}}):p.resumeSession({...h,snapshot:r});return d(g,{provider:t.model.provider,model:t.model.id,...t.effort===void 0?{}:{reasoningEffort:t.effort},...t.maxTokens===void 0?{}:{maxTokens:t.maxTokens},logger:t=>e.observation.correlatedLogger(t,{scope:`sdk.agent.run`}),...s.length===0?{}:{prepareTools:(e,t,n)=>_(s,e,t,n)},...o===void 0?{}:{memory:v(o,t.legacy.id,f.memoryOperationTimeoutMs)}}),new D(e,g,t.model.provider,t.legacy.id,c?.observerTimeoutMs,a)}function k(e,t){let n=[...e,...t],r=new Map;for(let[e,t]of n.entries()){let n=r.get(t.id);if(n!==void 0)throw i(`TOOL_SOURCE_ID_CONFLICT`,`tool-source-id`,n,e);r.set(t.id,e)}return Object.freeze(n)}function A(e,t,n,r){let i=!1;return Object.freeze({runId:e.runId,report:t,result:n,abort:()=>e.abort(),[Symbol.asyncIterator](){return i?(async function*(){throw Error(`A runtime run handle can only be iterated once`)})():(i=!0,j(e,t,r))}})}async function*j(e,t,n){let r=0,i=!1,a=()=>({runId:e.runId,traceId:e.traceId,sequence:++r,schemaVersion:1});try{for await(let t of e){let e=M(t,n);e!==void 0&&(yield Object.freeze({...a(),...e}))}let r=await t;if(r.status===`success`)yield Object.freeze({...a(),type:`usage`,usage:r.usage,report:r});else{let e=r.errors.at(-1)??L(r);yield Object.freeze({...a(),type:`error`,error:e,report:r})}i=!0}catch{let e=await t,n=e.errors.at(-1)??L(e);yield Object.freeze({...a(),type:`error`,error:n,report:e}),i=!0}finally{i||e.abort()}}function M(e,t){if(e.type===`text-delta`)return{type:e.phase===`commentary`?`commentary-delta`:`assistant-delta`,text:e.text,index:e.index,phase:e.phase,blockId:`${e.trace.spanId}:${e.index}`};if(e.type===`assistant-message`)return{type:`assistant-message`,message:h(e.message)};if(e.type===`text-end`||e.type===`reasoning-delta`){let{trace:t,...n}=e;return{...n,blockId:`${t.spanId}:${e.index}`}}if(e.type===`image-delta`){let{trace:t,...n}=e;return{...n,blockId:`${t.spanId}:${e.itemId}`}}if(e.type===`compaction-start`||e.type===`compaction-end`||e.type===`turn-start`||e.type===`step-start`||e.type===`step-end`||e.type===`assistant-text`||e.type===`assistant-reasoning`){let{trace:t,...n}=e;return n}if(e.type===`tool-call`)return{type:`tool-call`,callId:e.call.callId,name:e.call.toolName,input:P(e.call.rawArguments)};if(e.type===`tool-result`)return{type:`tool-result`,callId:e.call.callId,name:e.call.toolName,status:N(e.result),output:e.result};if(e.type===`assistant-native-tool`)return S(e.call,t);if(e.type===`approval-request`)return{type:`approval-request`,request:e.request};if(e.type===`user-input-request`)return{type:`user-input-request`,request:e.request};if(e.type===`user-input-response`)return{type:`user-input-response`,requestId:e.request.requestId,response:e.response}}function N(e){return e.isError?e.error.code===l.ABORTED||e.error.code===l.ABORTED_BEFORE_DISPATCH?`aborted`:e.error.code===l.UNKNOWN_TOOL||e.error.code===l.INVALID_ARGUMENTS||e.error.code===l.MALFORMED_ARGUMENTS||e.error.code===l.DENIED||e.error.code===l.BUDGET_EXHAUSTED||e.error.code===l.CHECKPOINT_FAILED?`rejected`:`failed`:e.meta?.declined===!0?`declined`:`completed`}function P(e){try{return JSON.parse(e)}catch{return e}}function F(e){return e instanceof n?e.code:`AGENT_RUN_FAILED`}function I(e,t,n){return a(new c(`Agent run did not complete`,n,t),e)}function L(e){return Object.freeze({code:`AGENT_RUN_FAILED`,stage:`agent-run`,message:`Agent operation failed`,usageCoverage:e.usage.coverage,possiblyBilledAttemptsWithoutUsage:e.usage.coverage.possiblyBilledAttemptsWithoutUsage})}export{w as createRuntimeAgent,T as createRuntimeTeamMemberSession,E as preflightRuntimeTeamMember};
|
|
2
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","names":[],"sources":["../../../src/composition/agent/session.ts"],"sourcesContent":["import { publicMessage } from './public-message.ts'\nimport type { AgentInput } from '../../agent/define/session/types.ts'\nimport { isJsonValue, detachedFrozen, type JsonValue } from '../../primitives/index.ts'\nimport { freezeMessage } from '../../message/index.ts'\nimport { AgentRunError } from '../../agent/accounting/error.ts'\nimport type { RunReport } from '../exporter/delivery-types.ts'\nimport { configureRuntimeSessionModel, streamRuntimeSession, type AgentSession } from '../../agent/define/session.ts'\nimport {\n compactRuntimeSession, streamPendingRuntimeSession, type RuntimeSessionRunHandle,\n} from '../../agent/define/session/runtime-binding.ts'\nimport type { AgentRunHandle as LegacyRunHandle } from '../../agent/define/session/types.ts'\nimport type { AgentRunEvent } from '../../agent/mode/run-agent.ts'\nimport type { ToolExecutionResult } from '../../agent/tool/definition.ts'\nimport { TOOL_ERROR_CODES } from '../../agent/tool/errors.ts'\nimport { AgentSdkError } from '../../errors/agent-sdk-error.ts'\nimport type { ModelRegistry } from '../../runtime/registry.ts'\nimport { atDeadline } from '../lifecycle/bounded.ts'\nimport type { RuntimeOperations } from '../lifecycle/operations.ts'\nimport type { RuntimeObservationPort } from '../observation/port.ts'\nimport { createRunTerminalRecord } from '../delivery/terminal.ts'\nimport { finalizeRuntimeRunReport, type RuntimeRunReport } from '../observation/final-report.ts'\nimport type { RuntimeObservationResource } from '../delivery/resource.ts'\nimport type { RuntimeResources } from '../../platform/resources.ts'\nimport { snapshotToolSources } from '../tool-source/snapshot.ts'\nimport { capabilityIdentityError, inheritCapabilityIdentityConflict } from '../identity/error.ts'\nimport type { CapturedToolSource } from '../tool-source/types.ts'\nimport type { ToolSourceRunReference } from '../tool-source/types.ts'\nimport { createRuntimeMemoryPersistence } from '../memory/run.ts'\nimport { validateMemoryResumeBinding } from '../memory/resume.ts'\nimport type { BoundRuntimeAgentDefinition } from './definition.ts'\nimport { captureInvocationOptions, captureRuntimeSessionOptions } from './options.ts'\nimport { projectNativeToolEvent } from './native-event.ts'\nimport type {\n RuntimeAgent, RuntimeAgentInvocationOptions, RuntimeAgentResponse, RuntimeAgentRunEvent,\n RuntimeAgentRunHandle, RuntimeAgentSession, RuntimeAgentSessionOptions, RuntimeAgentSessionSnapshot,\n} from './types.ts'\nimport type { CompactionResult } from '../../agent/memory/compaction.ts'\nimport type { AgentTeamMemberOptions } from '../../agent/define/session/types.ts'\nimport type { TeamSessionPort } from '../../agent/team/contracts.ts'\nimport { assertAgentIdentitySnapshot } from '../identity/agent.ts'\n\nexport interface RuntimeAgentHost {\n readonly registry: ModelRegistry\n readonly operations: RuntimeOperations\n readonly observation: RuntimeObservationPort\n readonly resource: RuntimeObservationResource\n readonly resources: RuntimeResources\n}\n\ninterface RuntimeAgentBinding {\n readonly host: RuntimeAgentHost\n readonly definition: BoundRuntimeAgentDefinition\n}\n\nconst runtimeAgentBindings = new WeakMap<RuntimeAgent, RuntimeAgentBinding>()\n\nexport function createRuntimeAgent(host: RuntimeAgentHost, definition: BoundRuntimeAgentDefinition): RuntimeAgent {\n const agent = Object.freeze({\n model: definition.model,\n generate(input: AgentInput, options?: RuntimeAgentInvocationOptions) { return createRuntimeSession(host, definition).run(input, options) },\n stream(input: AgentInput, options?: RuntimeAgentInvocationOptions) { return createRuntimeSession(host, definition).stream(input, options) },\n createSession(options?: RuntimeAgentSessionOptions) { return createRuntimeSession(host, definition, options) },\n resumeSession(snapshot: RuntimeAgentSessionSnapshot, options?: RuntimeAgentSessionOptions) {\n return createRuntimeSession(host, definition, options, snapshot)\n },\n })\n runtimeAgentBindings.set(agent, Object.freeze({ host, definition }))\n return agent\n}\n\nexport function createRuntimeTeamMemberSession(\n host: RuntimeAgentHost,\n agent: RuntimeAgent,\n options: RuntimeAgentSessionOptions,\n team: AgentTeamMemberOptions,\n ownerSignal: AbortSignal,\n): { readonly view: RuntimeAgentSession; readonly port: TeamSessionPort } {\n const binding = runtimeAgentBindings.get(agent)\n if (binding?.host !== host) throw new AgentSdkError(\n 'Runtime team members must be agents from the same runtime', 'TEAM_AGENT_OWNERSHIP_INVALID',\n )\n const view = createRuntimeSession(host, binding.definition, options, undefined, team, ownerSignal)\n return Object.freeze({ view, port: view.teamPort })\n}\n\nexport function preflightRuntimeTeamMember(\n host: RuntimeAgentHost,\n agent: RuntimeAgent,\n options: RuntimeAgentSessionOptions,\n additionalToolNames: readonly string[],\n): void {\n const binding = runtimeAgentBindings.get(agent)\n if (binding?.host !== host) throw new AgentSdkError(\n 'Runtime team members must be agents from the same runtime', 'TEAM_AGENT_OWNERSHIP_INVALID',\n )\n assertAgentIdentitySnapshot({\n tools: [...binding.definition.legacy.tools, ...options.tools ?? []],\n nativeTools: binding.definition.legacy.nativeTools,\n skills: [...binding.definition.legacy.skills, ...options.skills ?? []] as never,\n ...(binding.definition.legacy.skillIds === undefined ? {} : {\n allowedSkillIds: binding.definition.legacy.skillIds,\n }),\n additionalToolNames,\n })\n}\n\nexport function runtimeOwnsAgent(host: RuntimeAgentHost, agent: unknown): agent is RuntimeAgent {\n return typeof agent === 'object' && agent !== null && runtimeAgentBindings.get(agent as RuntimeAgent)?.host === host\n}\n\nclass RuntimeAgentSessionValue implements RuntimeAgentSession {\n private active: SessionOperation | undefined\n private readonly observerTimeoutMs: number\n readonly teamPort: TeamSessionPort\n\n constructor(\n private readonly host: RuntimeAgentHost,\n private readonly session: AgentSession,\n private readonly nativeProvider: string,\n definitionId: string,\n observerTimeoutMs = 30_000,\n private readonly ownerSignal?: AbortSignal,\n ) {\n this.observerTimeoutMs = observerTimeoutMs\n const owner = this\n this.teamPort = Object.freeze({\n definition: Object.freeze({ id: definitionId }),\n get conversationId() { return owner.conversationId },\n get isRunning() { return owner.isRunning },\n inject(input: Parameters<TeamSessionPort['inject']>[0]) { return owner.injectForTeam(input) },\n whenIdle(signal?: AbortSignal) { return owner.whenIdle(signal) },\n runPending(invocation = {}) { return owner.runPendingForTeam(invocation) },\n })\n }\n\n get conversationId(): string { return this.session.conversationId }\n get isRunning(): boolean { return this.active !== undefined }\n\n stream(input: AgentInput, rawOptions?: RuntimeAgentInvocationOptions): RuntimeAgentRunHandle {\n if (typeof input !== 'string') {\n if (input === null || typeof input !== 'object' || input.role !== 'user') throw new TypeError('Runtime input must be text or a user message')\n input = freezeMessage(input)\n }\n const options = captureInvocationOptions(rawOptions)\n const started = this.start(input, options)\n return runtimeHandle(started.legacy, started.report, started.result, this.nativeProvider)\n }\n\n private start(input: AgentInput | undefined, options: RuntimeAgentInvocationOptions): StartedRuntimeRun {\n const operation = this.beginOperation()\n let lease: ReturnType<RuntimeOperations['acquire']>\n try {\n const signal = this.ownerSignal === undefined\n ? options.signal\n : options.signal === undefined ? this.ownerSignal : AbortSignal.any([options.signal, this.ownerSignal])\n lease = this.host.operations.acquire('agent-run', {\n ...(signal === undefined ? {} : { signal }),\n })\n } catch (error) { this.finishOperation(operation); throw error }\n let output: JsonValue | undefined\n const structured = options.structuredOutput\n let legacy: RuntimeSessionRunHandle\n try {\n legacy = input === undefined\n ? streamPendingRuntimeSession(this.session, { signal: lease.signal })\n : streamRuntimeSession(this.session, input, { signal: lease.signal, ...(structured === undefined ? {} : {\n outputFormat: { type: 'json_schema' as const, name: structured.name, schema: structured.schema.jsonSchema },\n validateOutput: (value: unknown) => {\n const parsed = structured.schema.parse(value)\n if (!isJsonValue(parsed)) throw new TypeError('structured output parser must return lossless JSON synchronously')\n output = detachedFrozen(parsed)\n },\n }), ...(options.imagePolicy === undefined ? {} : { imagePolicy: options.imagePolicy }) }, options.additionalInstructions)\n } catch (error) { lease.settle(); this.finishOperation(operation); throw error }\n const abort = (): void => legacy.abort()\n lease.signal.addEventListener('abort', abort, { once: true })\n if (lease.signal.aborted) abort()\n void lease.whenSealed.then(() => legacy.seal()).catch(() => undefined)\n const report = this.runtimeReport(legacy.report, legacy.toolSourceSnapshots, lease.signal)\n const internalResult = this.runtimeResult(legacy.result, report, () => output)\n const eventsSettled = Promise.race([legacy.eventsSettled, lease.whenSealed])\n const released = Promise.allSettled([eventsSettled, internalResult, report]).then(() => {\n lease.signal.removeEventListener('abort', abort)\n lease.settle()\n this.finishOperation(operation)\n })\n const result = released.then(() => internalResult)\n void result.catch(() => undefined)\n void report.catch(() => undefined)\n return Object.freeze({ legacy, report, result })\n }\n\n async run(input: AgentInput, rawOptions?: RuntimeAgentInvocationOptions): Promise<RuntimeAgentResponse> {\n const options = captureInvocationOptions(rawOptions)\n const handle = this.stream(input, options)\n try {\n for await (const event of handle) {\n if (options.onEvent !== undefined) {\n try { await this.observe(options.onEvent, event, handle) }\n catch (error) {\n handle.abort()\n const report = await handle.report\n throw runtimeFailure(error, report, 'RUN_EVENT_OBSERVER_FAILED')\n }\n }\n }\n } catch (error) { if (codeOf(error) === 'RUN_EVENT_OBSERVER_FAILED') throw error; return await handle.result }\n return await handle.result\n }\n\n inject(input: AgentInput): number {\n this.host.operations.assertActive()\n this.assertOwnerActive()\n if (this.active !== undefined) throw new Error('Cannot inject while a runtime session is active')\n return this.session.inject(input)\n }\n\n private injectForTeam(input: Parameters<TeamSessionPort['inject']>[0]): number {\n this.host.operations.assertActive()\n this.assertOwnerActive()\n return this.session.inject(input)\n }\n\n snapshot(): RuntimeAgentSessionSnapshot { return this.session.snapshot() }\n\n compact(rawOptions?: RuntimeAgentInvocationOptions): Promise<CompactionResult | null> {\n const options = captureInvocationOptions(rawOptions)\n const operation = this.beginOperation()\n let pending: Promise<CompactionResult | null>\n try {\n pending = this.host.operations.execute('manual-compaction', {\n ...(this.ownerSignal === undefined\n ? options.signal === undefined ? {} : { signal: options.signal }\n : { signal: options.signal === undefined ? this.ownerSignal : AbortSignal.any([options.signal, this.ownerSignal]) }),\n }, async lease => {\n const outcome = await compactRuntimeSession(this.session, { signal: lease.signal })\n const record = createRunTerminalRecord(outcome.report)\n const terminal = await this.host.observation.checkpointTerminal(record, lease.signal)\n const report = finalizeRuntimeRunReport(record, outcome.report.delivery, terminal,\n this.host.observation.mode, this.host.observation.requiredBoundary)\n if (outcome.failure !== undefined) throw runtimeFailure(\n outcome.failure,\n report,\n report.errors.at(-1)?.code ?? codeOf(outcome.failure),\n )\n return outcome.result === null ? null : Object.freeze({ ...outcome.result, status: 'completed' as const, report })\n })\n } catch (error) { this.finishOperation(operation); throw error }\n return pending.finally(() => this.finishOperation(operation))\n }\n\n reset(): void {\n this.host.operations.assertActive()\n this.assertOwnerActive()\n if (this.active !== undefined) throw new Error('Cannot reset while a runtime session is active')\n this.session.reset()\n }\n\n whenIdle(signal?: AbortSignal): Promise<void> {\n const pending = this.active?.done\n if (pending === undefined) return Promise.resolve()\n if (signal?.aborted) return Promise.reject(new AgentSdkError('Runtime idle wait was aborted', 'RUNTIME_OPERATION_ABORTED'))\n return new Promise((resolve, reject) => {\n let release = (): void => undefined\n const finish = (error?: Error): void => { release(); error === undefined ? resolve() : reject(error) }\n if (signal !== undefined) release = this.host.resources.onAbort(signal,\n () => finish(new AgentSdkError('Runtime idle wait was aborted', 'RUNTIME_OPERATION_ABORTED')))\n void pending.then(() => finish())\n })\n }\n\n private async runPendingForTeam(invocation: {\n readonly signal?: AbortSignal\n readonly onEvent?: (event: AgentRunEvent) => void | Promise<void>\n }): Promise<unknown> {\n const started = this.start(undefined, {\n ...(invocation.signal === undefined ? {} : { signal: invocation.signal }),\n })\n try {\n for await (const event of started.legacy) await invocation.onEvent?.(event)\n } catch (error) {\n started.legacy.abort()\n await started.result.catch(() => undefined)\n throw error\n }\n return await started.result\n }\n\n private beginOperation(): SessionOperation {\n this.assertOwnerActive()\n if (this.active !== undefined) throw new Error('Cannot start while a runtime session is active')\n let resolve!: () => void\n const operation: SessionOperation = { done: new Promise(done => { resolve = done }), resolve }\n this.active = operation\n return operation\n }\n\n private finishOperation(operation: SessionOperation): void {\n if (this.active !== operation) return\n this.active = undefined\n operation.resolve()\n }\n\n private assertOwnerActive(): void {\n if (this.ownerSignal?.aborted === true) {\n throw new AgentSdkError('Runtime team session is closed', 'TEAM_CLOSED')\n }\n }\n\n private async runtimeReport(\n legacy: Promise<RunReport>,\n sourceSnapshots: Promise<readonly ToolSourceRunReference[]>,\n signal: AbortSignal,\n ): Promise<RuntimeRunReport> {\n const [previous, sources] = await Promise.all([legacy, sourceSnapshots])\n const record = createRunTerminalRecord(previous, sources)\n const terminal = await this.host.observation.checkpointTerminal(record, signal)\n return finalizeRuntimeRunReport(record, previous.delivery, terminal,\n this.host.observation.mode, this.host.observation.requiredBoundary)\n }\n\n private async runtimeResult(\n legacy: Promise<Awaited<LegacyRunHandle['result']>>,\n report: Promise<RuntimeRunReport>,\n output: () => JsonValue | undefined,\n ): Promise<RuntimeAgentResponse> {\n try {\n const response = await legacy\n const final = await report\n if (final.status !== 'success') {\n throw runtimeFailure(undefined, final, final.errors.at(-1)?.code ?? 'AGENT_RUN_FAILED')\n }\n const parsedOutput = output()\n return Object.freeze({ runId: final.runId, traceId: final.traceId,\n completed: response.outcome.completed, stopReason: response.outcome.reason.kind,\n text: response.text, ...(parsedOutput === undefined ? {} : { output: parsedOutput }),\n ...(response.message === undefined ? {} : { message: publicMessage(response.message) }),\n usage: final.usage, report: final })\n } catch (error) {\n const final = await report\n throw runtimeFailure(error, final, codeOf(error))\n }\n }\n\n private async observe(\n observer: NonNullable<RuntimeAgentInvocationOptions['onEvent']>,\n event: RuntimeAgentRunEvent,\n handle: RuntimeAgentRunHandle,\n ): Promise<void> {\n const deadlineAt = this.host.resources.platform.monotonicNow() + this.observerTimeoutMs\n try { await atDeadline(this.host.resources, deadlineAt, () => observer(event), undefined) }\n catch { handle.abort(); throw new AgentSdkError('Runtime event observer did not complete', 'RUN_EVENT_OBSERVER_FAILED') }\n }\n}\n\nfunction createRuntimeSession(\n host: RuntimeAgentHost,\n definition: BoundRuntimeAgentDefinition,\n options: RuntimeAgentSessionOptions = {},\n snapshot?: RuntimeAgentSessionSnapshot,\n team?: AgentTeamMemberOptions,\n ownerSignal?: AbortSignal,\n): RuntimeAgentSessionValue {\n host.operations.assertActive()\n options = captureRuntimeSessionOptions(options)\n assertAgentIdentitySnapshot({\n tools: [...definition.legacy.tools, ...options.tools ?? []],\n nativeTools: definition.legacy.nativeTools,\n skills: [...definition.legacy.skills, ...options.skills ?? []] as never,\n ...(definition.legacy.skillIds === undefined ? {} : { allowedSkillIds: definition.legacy.skillIds }),\n })\n const memory = options.memory === false ? undefined : options.memory ?? definition.memory\n if (snapshot !== undefined) validateMemoryResumeBinding(snapshot, memory)\n const toolSources = combineToolSources(definition.toolSources, options.toolSources ?? [])\n const limits = options.runtimeLimits\n const { maxSteps: _maxSteps, maxToolCalls: _maxToolCalls, ...agentRuntimeLimits } = limits ?? {}\n const selected = limits?.maxSteps === undefined && limits?.maxToolCalls === undefined\n ? definition.legacy : definition.legacy.with({\n ...(limits.maxSteps === undefined ? {} : { maxTurns: limits.maxSteps }),\n ...(limits.maxToolCalls === undefined ? {} : { maxToolCalls: limits.maxToolCalls }),\n })\n const shared = { registry: host.registry, observation: host.observation, observationResource: host.resource,\n ...(options.tools === undefined ? {} : { tools: options.tools }),\n ...(options.skills === undefined ? {} : { skills: options.skills as never }),\n ...(options.skillCwd === undefined ? {} : { skillCwd: options.skillCwd }),\n ...(options.userInput === undefined ? {} : { userInput: options.userInput }),\n ...(options.approvals === undefined ? {} : { approvals: options.approvals }),\n ...(options.spillStore === undefined ? {} : { spillStore: options.spillStore }),\n ...(options.interceptors === undefined ? {} : { interceptors: options.interceptors }),\n ...(options.contextSections === undefined ? {} : { contextSections: options.contextSections }),\n ...(options.hooks === undefined ? {} : { hooks: options.hooks }),\n ...(options.usagePolicy === undefined ? {} : { usagePolicy: options.usagePolicy }),\n ...(options.historyLimits === undefined ? {} : { historyLimits: options.historyLimits }),\n ...(options.ledgerLimits === undefined ? {} : { ledgerLimits: options.ledgerLimits }),\n ...(options.eventBufferLimits === undefined ? {} : { eventBufferLimits: options.eventBufferLimits }),\n ...(options.compaction === undefined ? {} : { compaction: options.compaction }),\n ...(team === undefined ? {} : { team }),\n ...(Object.keys(agentRuntimeLimits).length === 0 ? {} : { runtimeLimits: agentRuntimeLimits }),\n }\n const session = snapshot === undefined\n ? selected.createSession({ ...shared, ...(options.conversationId === undefined ? {} : { conversationId: options.conversationId }) })\n : selected.resumeSession({ ...shared, snapshot })\n configureRuntimeSessionModel(session, { provider: definition.model.provider, model: definition.model.id,\n ...(definition.effort === undefined ? {} : { reasoningEffort: definition.effort }),\n ...(definition.maxTokens === undefined ? {} : { maxTokens: definition.maxTokens }),\n logger: correlation => host.observation.correlatedLogger(correlation, { scope: 'sdk.agent.run' }),\n ...(toolSources.length === 0 ? {} : {\n prepareTools: (signal, logger, occupiedNames) => snapshotToolSources(\n toolSources, signal, logger, occupiedNames,\n ),\n }),\n ...(memory === undefined ? {} : {\n memory: createRuntimeMemoryPersistence(\n memory,\n definition.legacy.id,\n agentRuntimeLimits.memoryOperationTimeoutMs,\n ),\n }),\n })\n return new RuntimeAgentSessionValue(\n host, session, definition.model.provider, definition.legacy.id, limits?.observerTimeoutMs, ownerSignal,\n )\n}\n\ninterface SessionOperation {\n readonly done: Promise<void>\n readonly resolve: () => void\n}\n\ninterface StartedRuntimeRun {\n readonly legacy: RuntimeSessionRunHandle\n readonly report: Promise<RuntimeRunReport>\n readonly result: Promise<RuntimeAgentResponse>\n}\n\nfunction combineToolSources(\n defined: readonly CapturedToolSource[],\n additional: readonly CapturedToolSource[],\n): readonly CapturedToolSource[] {\n const all = [...defined, ...additional]\n const seen = new Map<string, number>()\n for (const [index, source] of all.entries()) {\n const first = seen.get(source.id)\n if (first !== undefined) throw capabilityIdentityError(\n 'TOOL_SOURCE_ID_CONFLICT', 'tool-source-id', first, index,\n )\n seen.set(source.id, index)\n }\n return Object.freeze(all)\n}\n\nfunction runtimeHandle(\n source: LegacyRunHandle & { readonly traceId: string; abort(reason?: unknown): void },\n report: Promise<RuntimeRunReport>, result: Promise<RuntimeAgentResponse>, nativeProvider: string,\n): RuntimeAgentRunHandle {\n let iterated = false\n return Object.freeze({ runId: source.runId, report, result, abort: () => source.abort(),\n [Symbol.asyncIterator](): AsyncIterator<RuntimeAgentRunEvent> {\n if (iterated) return (async function* () { throw new Error('A runtime run handle can only be iterated once') })()\n iterated = true\n return projectEvents(source, report, nativeProvider)\n } })\n}\n\nasync function* projectEvents(\n source: LegacyRunHandle & { readonly traceId: string; abort(reason?: unknown): void },\n report: Promise<RuntimeRunReport>,\n nativeProvider: string,\n): AsyncGenerator<RuntimeAgentRunEvent> {\n let sequence = 0, completed = false\n const context = () => ({ runId: source.runId, traceId: source.traceId, sequence: ++sequence, schemaVersion: 1 as const })\n try {\n for await (const event of source) {\n const projected = projectEvent(event, nativeProvider)\n if (projected !== undefined) yield Object.freeze({ ...context(), ...projected }) as RuntimeAgentRunEvent\n }\n const terminal = await report\n if (terminal.status === 'success') {\n yield Object.freeze({ ...context(), type: 'usage', usage: terminal.usage, report: terminal })\n } else {\n const error = terminal.errors.at(-1) ?? fallbackError(terminal)\n yield Object.freeze({ ...context(), type: 'error', error, report: terminal })\n }\n completed = true\n } catch {\n const terminal = await report\n const error = terminal.errors.at(-1) ?? fallbackError(terminal)\n yield Object.freeze({ ...context(), type: 'error', error, report: terminal })\n completed = true\n } finally { if (!completed) source.abort() }\n}\n\ntype WithoutEventContext<T> = T extends unknown ? Omit<T, 'runId' | 'traceId' | 'sequence' | 'schemaVersion'> : never\ntype ProjectedEvent = WithoutEventContext<RuntimeAgentRunEvent>\n\nfunction projectEvent(event: AgentRunEvent, nativeProvider: string): ProjectedEvent | undefined {\n if (event.type === 'text-delta') return {\n type: event.phase === 'commentary' ? 'commentary-delta' : 'assistant-delta',\n text: event.text, index: event.index, phase: event.phase, blockId: `${event.trace.spanId}:${event.index}`,\n }\n if (event.type === 'assistant-message') return { type: 'assistant-message', message: publicMessage(event.message) }\n if (event.type === 'text-end' || event.type === 'reasoning-delta') {\n const { trace, ...content } = event\n return { ...content, blockId: `${trace.spanId}:${event.index}` }\n }\n if (event.type === 'image-delta') {\n const { trace, ...content } = event\n return { ...content, blockId: `${trace.spanId}:${event.itemId}` }\n }\n if (event.type === 'compaction-start' || event.type === 'compaction-end'\n || event.type === 'turn-start' || event.type === 'step-start' || event.type === 'step-end'\n || event.type === 'assistant-text' || event.type === 'assistant-reasoning') {\n const { trace: _trace, ...content } = event\n return content\n }\n if (event.type === 'tool-call') return { type: 'tool-call', callId: event.call.callId,\n name: event.call.toolName, input: parseInput(event.call.rawArguments) }\n if (event.type === 'tool-result') return { type: 'tool-result', callId: event.call.callId,\n name: event.call.toolName, status: toolResultStatus(event.result), output: event.result }\n if (event.type === 'assistant-native-tool') return projectNativeToolEvent(event.call, nativeProvider)\n if (event.type === 'approval-request') return { type: 'approval-request', request: event.request }\n if (event.type === 'user-input-request') return { type: 'user-input-request', request: event.request }\n if (event.type === 'user-input-response') return { type: 'user-input-response', requestId: event.request.requestId,\n response: event.response }\n return undefined\n}\n\nfunction toolResultStatus(\n result: ToolExecutionResult,\n): 'completed' | 'failed' | 'aborted' | 'rejected' | 'declined' {\n // A call the loop refused to run is neither success nor failure: nothing\n // broke, and nothing was done. Reporting it as either misleads a UI — and a\n // red row for a budget decision is what makes a finished run look crashed.\n if (!result.isError) return result.meta?.['declined'] === true ? 'declined' : 'completed'\n if (result.error.code === TOOL_ERROR_CODES.ABORTED\n || result.error.code === TOOL_ERROR_CODES.ABORTED_BEFORE_DISPATCH) return 'aborted'\n if (result.error.code === TOOL_ERROR_CODES.UNKNOWN_TOOL\n || result.error.code === TOOL_ERROR_CODES.INVALID_ARGUMENTS\n || result.error.code === TOOL_ERROR_CODES.MALFORMED_ARGUMENTS\n || result.error.code === TOOL_ERROR_CODES.DENIED\n || result.error.code === TOOL_ERROR_CODES.BUDGET_EXHAUSTED\n || result.error.code === TOOL_ERROR_CODES.CHECKPOINT_FAILED) return 'rejected'\n return 'failed'\n}\n\nfunction parseInput(value: string): unknown { try { return JSON.parse(value) as unknown } catch { return value } }\nfunction codeOf(value: unknown): string {\n return value instanceof AgentSdkError ? value.code : 'AGENT_RUN_FAILED'\n}\nfunction runtimeFailure(value: unknown, report: RuntimeRunReport, code: string): AgentRunError {\n return inheritCapabilityIdentityConflict(\n new AgentRunError('Agent run did not complete', code, report as never), value,\n )\n}\nfunction fallbackError(report: RuntimeRunReport): RuntimeRunReport['errors'][number] {\n return Object.freeze({ code: 'AGENT_RUN_FAILED', stage: 'agent-run', message: 'Agent operation failed',\n usageCoverage: report.usage.coverage,\n possiblyBilledAttemptsWithoutUsage: report.usage.coverage.possiblyBilledAttemptsWithoutUsage })\n}\n"],"mappings":"0zCAsDA,MAAM,EAAuB,IAAI,QAEjC,SAAgB,EAAmB,EAAwB,EAAuD,CAChH,IAAM,EAAQ,OAAO,OAAO,CAC1B,MAAO,EAAW,MAClB,SAAS,EAAmB,EAAyC,CAAE,OAAO,EAAqB,EAAM,CAAU,CAAC,CAAC,IAAI,EAAO,CAAO,CAAE,EACzI,OAAO,EAAmB,EAAyC,CAAE,OAAO,EAAqB,EAAM,CAAU,CAAC,CAAC,OAAO,EAAO,CAAO,CAAE,EAC1I,cAAc,EAAsC,CAAE,OAAO,EAAqB,EAAM,EAAY,CAAO,CAAE,EAC7G,cAAc,EAAuC,EAAsC,CACzF,OAAO,EAAqB,EAAM,EAAY,EAAS,CAAQ,CACjE,CACF,CAAC,EAED,OADA,EAAqB,IAAI,EAAO,OAAO,OAAO,CAAE,OAAM,YAAW,CAAC,CAAC,EAC5D,CACT,CAEA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACwE,CACxE,IAAM,EAAU,EAAqB,IAAI,CAAK,EAC9C,GAAI,GAAS,OAAS,EAAM,MAAM,IAAI,EACpC,4DAA6D,8BAC/D,EACA,IAAM,EAA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,OAAQ,EACjG,GAAI,EAAM,OAAS,qBAAsB,MAAO,CAAE,KAAM,qBAAsB,QAAS,EAAM,OAAQ,EACrG,GAAI,EAAM,OAAS,sBAAuB,MAAO,CAAE,KAAM,sBAAuB,UAAW,EAAM,QAAQ,UACvG,SAAU,EAAM,QAAS,CAE7B,CAEA,SAAS,EACP,EAC8D,CAa9D,OATK,EAAO,QACR,EAAO,MAAM,OAAS,EAAiB,SACtC,EAAO,MAAM,OAAS,EAAiB,wBAAgC,UACxE,EAAO,MAAM,OAAS,EAAiB,cACtC,EAAO,MAAM,OAAS,EAAiB,mBACvC,EAAO,MAAM,OAAS,EAAiB,qBACvC,EAAO,MAAM,OAAS,EAAiB,QACvC,EAAO,MAAM,OAAS,EAAiB,kBACvC,EAAO,MAAM,OAAS,EAAiB,kBAA0B,WAC/D,SATqB,EAAO,MAAO,WAAgB,GAAO,WAAa,WAUhF,CAEA,SAAS,EAAW,EAAwB,CAAE,GAAI,CAAE,OAAO,KAAK,MAAM,CAAK,CAAa,MAAQ,CAAE,OAAO,CAAM,CAAE,CACjH,SAAS,EAAO,EAAwB,CACtC,OAAO,aAAiB,EAAgB,EAAM,KAAO,kBACvD,CACA,SAAS,EAAe,EAAgB,EAA0B,EAA6B,CAC7F,OAAO,EACL,IAAI,EAAc,6BAA8B,EAAM,CAAe,EAAG,CAC1E,CACF,CACA,SAAS,EAAc,EAA8D,CACnF,OAAO,OAAO,OAAO,CAAE,KAAM,mBAAoB,MAAO,YAAa,QAAS,yBAC5E,cAAe,EAAO,MAAM,SAC5B,mCAAoC,EAAO,MAAM,SAAS,kCAAmC,CAAC,CAClG"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { JsonValue } from "../../primitives/json.js";
|
|
2
|
+
import { Message } from "../../message/message.js";
|
|
3
|
+
import { NativeToolSchema, ToolChoice } from "../../contract/tool.js";
|
|
4
|
+
import { ModelOutputFormat } from "../../contract/output-format.js";
|
|
5
|
+
import { ToolDefinition } from "../../agent/tool/definition.js";
|
|
6
|
+
import { SpillStore } from "../../agent/tool/output-budget.js";
|
|
7
|
+
import { HistoryLimits } from "../../agent/history/types.js";
|
|
8
|
+
import { ApprovalBroker, ApprovalRequest } from "../../agent/tool/approval.js";
|
|
9
|
+
import { ToolInterceptor } from "../../agent/tool/pipeline.js";
|
|
10
|
+
import { RunLedgerLimits, UsagePolicy } from "../../agent/accounting/report.js";
|
|
11
|
+
import { StreamedAssistantTextPhase, TurnEndReason, TurnHooks } from "../../agent/loop/events.js";
|
|
12
|
+
import { ContextSection } from "../../agent/context/types.js";
|
|
13
|
+
import { UserInputBroker, UserInputDecision, UserInputRequest } from "../../agent/mode/user-input.js";
|
|
14
|
+
import { AgentRunEvent } from "../../agent/mode/run-agent.js";
|
|
15
|
+
import { AgentCompactionOptions } from "../../agent/memory/compaction-config.js";
|
|
16
|
+
import { CompactionResult } from "../../agent/memory/compaction.js";
|
|
17
|
+
import { RuntimeSkillSource } from "../../agent/skill/provider/types.js";
|
|
18
|
+
import { AgentInput, AgentRunEventBufferLimits, AgentRuntimeLimits, AgentSessionSnapshot } from "../../agent/define/session/types.js";
|
|
19
|
+
import { MemoryBinding } from "../../agent/memory/persistence-types.js";
|
|
20
|
+
import { ToolSource } from "../../agent/tool/source-types.js";
|
|
21
|
+
import { RuntimeSchema } from "../../agent/tool/schema.js";
|
|
22
|
+
import { ModelTarget } from "../provider/types.js";
|
|
23
|
+
import { RuntimeRunReport } from "../observation/final-report.js";
|
|
24
|
+
//#region src/composition/agent/types.d.ts
|
|
25
|
+
interface RuntimeAgentDefinitionInput {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly name?: string;
|
|
28
|
+
readonly description?: string;
|
|
29
|
+
readonly model: ModelTarget;
|
|
30
|
+
readonly instructions: string;
|
|
31
|
+
readonly effort?: string;
|
|
32
|
+
readonly maxTokens?: number;
|
|
33
|
+
readonly mode?: 'basic' | 'deep' | 'deep-human-in-loop';
|
|
34
|
+
readonly tools?: readonly ToolDefinition[];
|
|
35
|
+
readonly nativeTools?: readonly NativeToolSchema[];
|
|
36
|
+
readonly toolChoice?: ToolChoice;
|
|
37
|
+
readonly outputFormat?: ModelOutputFormat;
|
|
38
|
+
readonly toolSources?: readonly ToolSource[];
|
|
39
|
+
readonly skills?: readonly RuntimeSkillSource[];
|
|
40
|
+
readonly allowedSkillIds?: readonly string[];
|
|
41
|
+
readonly memory?: MemoryBinding;
|
|
42
|
+
/**
|
|
43
|
+
* Model-visible context this agent always recomputes before a model round.
|
|
44
|
+
*
|
|
45
|
+
* Definition-level sections belong to the agent wherever it runs; mount an
|
|
46
|
+
* environment-dependent one (project instruction files, working-tree state)
|
|
47
|
+
* on the session instead.
|
|
48
|
+
*/
|
|
49
|
+
readonly contextSections?: readonly ContextSection[];
|
|
50
|
+
readonly compaction?: AgentCompactionOptions | false;
|
|
51
|
+
/** Model steps per prompt; 'auto' removes the step ceiling, not resource limits. */
|
|
52
|
+
readonly maxTurns?: number | 'auto';
|
|
53
|
+
readonly maxToolCalls?: number;
|
|
54
|
+
readonly commentary?: 'auto' | 'concise' | 'off';
|
|
55
|
+
}
|
|
56
|
+
interface RuntimeAgentDefinition extends RuntimeAgentDefinitionInput {}
|
|
57
|
+
interface RuntimeAgentBindingInput extends Omit<RuntimeAgentDefinitionInput, 'model'> {
|
|
58
|
+
readonly model?: {
|
|
59
|
+
readonly provider: string;
|
|
60
|
+
readonly id?: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
interface RuntimeAgentLimits extends AgentRuntimeLimits {
|
|
64
|
+
readonly maxSteps?: number | 'auto';
|
|
65
|
+
readonly maxToolCalls?: number;
|
|
66
|
+
}
|
|
67
|
+
interface RuntimeAgentSessionOptions {
|
|
68
|
+
readonly conversationId?: string;
|
|
69
|
+
readonly tools?: readonly ToolDefinition[];
|
|
70
|
+
readonly toolSources?: readonly ToolSource[];
|
|
71
|
+
readonly skills?: readonly RuntimeSkillSource[];
|
|
72
|
+
readonly memory?: MemoryBinding | false;
|
|
73
|
+
readonly skillCwd?: string;
|
|
74
|
+
readonly userInput?: UserInputBroker;
|
|
75
|
+
readonly approvals?: ApprovalBroker;
|
|
76
|
+
/**
|
|
77
|
+
* Where oversized tool output is saved instead of being cut.
|
|
78
|
+
*
|
|
79
|
+
* Mounting one makes the default `auto` overflow policy spill rather than
|
|
80
|
+
* truncate, and gives the model `read_tool_output` to read the rest back.
|
|
81
|
+
*/
|
|
82
|
+
readonly spillStore?: SpillStore;
|
|
83
|
+
readonly interceptors?: readonly ToolInterceptor[];
|
|
84
|
+
/**
|
|
85
|
+
* Model-visible context recomputed before every model round.
|
|
86
|
+
*
|
|
87
|
+
* Mount a platform package's section (project instruction files, working-tree
|
|
88
|
+
* state) here; the core never reads a file to build one.
|
|
89
|
+
*/
|
|
90
|
+
readonly contextSections?: readonly ContextSection[];
|
|
91
|
+
readonly hooks?: TurnHooks;
|
|
92
|
+
readonly usagePolicy?: UsagePolicy;
|
|
93
|
+
/** In-memory append-only conversation history limits. */
|
|
94
|
+
readonly historyLimits?: HistoryLimits;
|
|
95
|
+
/** Canonical per-run accounting ledger limits. */
|
|
96
|
+
readonly ledgerLimits?: RunLedgerLimits;
|
|
97
|
+
/** Public run-event queue limits for slow or paused consumers. */
|
|
98
|
+
readonly eventBufferLimits?: AgentRunEventBufferLimits;
|
|
99
|
+
readonly runtimeLimits?: RuntimeAgentLimits;
|
|
100
|
+
readonly compaction?: AgentCompactionOptions | false;
|
|
101
|
+
}
|
|
102
|
+
interface RuntimeAgentInvocationOptions {
|
|
103
|
+
/** One schema adapter supplies the provider schema and a synchronous runtime validator. */
|
|
104
|
+
readonly structuredOutput?: {
|
|
105
|
+
readonly name: string;
|
|
106
|
+
readonly schema: RuntimeSchema<JsonValue>;
|
|
107
|
+
};
|
|
108
|
+
/** strict rejects known text-only models when request history contains images; project permits lossy conversion. */
|
|
109
|
+
readonly imagePolicy?: 'strict' | 'project';
|
|
110
|
+
readonly signal?: AbortSignal;
|
|
111
|
+
readonly additionalInstructions?: string;
|
|
112
|
+
readonly onEvent?: (event: RuntimeAgentRunEvent) => void | Promise<void>;
|
|
113
|
+
}
|
|
114
|
+
interface RuntimeAgentRunEventContext {
|
|
115
|
+
readonly schemaVersion: 1;
|
|
116
|
+
readonly runId: string;
|
|
117
|
+
readonly traceId: string;
|
|
118
|
+
readonly sequence: number;
|
|
119
|
+
}
|
|
120
|
+
type PublicContentEvent = AgentRunEvent extends (infer E) ? E extends {
|
|
121
|
+
type: 'text-end' | 'image-delta' | 'assistant-message' | 'compaction-start' | 'compaction-end' | 'turn-start' | 'step-start' | 'step-end' | 'assistant-text' | 'assistant-reasoning' | 'reasoning-delta';
|
|
122
|
+
} ? Omit<E, 'trace'> & {
|
|
123
|
+
readonly blockId?: string;
|
|
124
|
+
} : never : never;
|
|
125
|
+
type RuntimeAgentRunEvent = RuntimeAgentRunEventContext & (PublicContentEvent | {
|
|
126
|
+
readonly type: 'commentary-delta';
|
|
127
|
+
readonly text: string;
|
|
128
|
+
readonly index: number;
|
|
129
|
+
readonly blockId: string;
|
|
130
|
+
readonly phase: StreamedAssistantTextPhase;
|
|
131
|
+
} | {
|
|
132
|
+
readonly type: 'assistant-delta';
|
|
133
|
+
readonly text: string;
|
|
134
|
+
readonly index: number;
|
|
135
|
+
readonly blockId: string;
|
|
136
|
+
readonly phase: StreamedAssistantTextPhase;
|
|
137
|
+
} | {
|
|
138
|
+
readonly type: 'tool-call';
|
|
139
|
+
readonly callId: string;
|
|
140
|
+
readonly name: string;
|
|
141
|
+
readonly input: unknown;
|
|
142
|
+
} | {
|
|
143
|
+
readonly type: 'tool-result';
|
|
144
|
+
readonly callId: string;
|
|
145
|
+
readonly name: string;
|
|
146
|
+
readonly status: 'completed' | 'failed' | 'aborted' | 'rejected' | 'declined';
|
|
147
|
+
readonly output: unknown;
|
|
148
|
+
} | {
|
|
149
|
+
readonly type: 'assistant-native-tool';
|
|
150
|
+
readonly callId: string;
|
|
151
|
+
readonly provider: string;
|
|
152
|
+
readonly name: string;
|
|
153
|
+
readonly status: 'started' | 'completed' | 'failed' | 'unknown';
|
|
154
|
+
readonly input?: JsonValue;
|
|
155
|
+
readonly output?: JsonValue;
|
|
156
|
+
} | {
|
|
157
|
+
readonly type: 'approval-request';
|
|
158
|
+
readonly request: ApprovalRequest;
|
|
159
|
+
} | {
|
|
160
|
+
readonly type: 'user-input-request';
|
|
161
|
+
readonly request: UserInputRequest;
|
|
162
|
+
} | {
|
|
163
|
+
readonly type: 'user-input-response';
|
|
164
|
+
readonly requestId: string;
|
|
165
|
+
readonly response: UserInputDecision;
|
|
166
|
+
} | {
|
|
167
|
+
readonly type: 'usage';
|
|
168
|
+
readonly usage: RuntimeRunReport['usage'];
|
|
169
|
+
readonly report: RuntimeRunReport;
|
|
170
|
+
} | {
|
|
171
|
+
readonly type: 'error';
|
|
172
|
+
readonly error: RuntimeRunReport['errors'][number];
|
|
173
|
+
readonly report: RuntimeRunReport;
|
|
174
|
+
});
|
|
175
|
+
interface RuntimeAgentResponse {
|
|
176
|
+
/** Objective completion, independent of report.status (execution status). */
|
|
177
|
+
readonly completed: boolean;
|
|
178
|
+
/** Terminal control-flow reason; deep mode can stop without an accepted submission. */
|
|
179
|
+
readonly stopReason: TurnEndReason['kind'];
|
|
180
|
+
readonly runId: string;
|
|
181
|
+
readonly traceId: string;
|
|
182
|
+
readonly text: string;
|
|
183
|
+
readonly output?: JsonValue;
|
|
184
|
+
readonly message?: Message;
|
|
185
|
+
readonly usage: RuntimeRunReport['usage'];
|
|
186
|
+
readonly report: RuntimeRunReport;
|
|
187
|
+
}
|
|
188
|
+
interface RuntimeAgentRunHandle extends AsyncIterable<RuntimeAgentRunEvent> {
|
|
189
|
+
readonly runId: string;
|
|
190
|
+
/** Settles after run cleanup; the session can be reused unless it or its runtime is closed. */
|
|
191
|
+
readonly result: Promise<RuntimeAgentResponse>;
|
|
192
|
+
readonly report: Promise<RuntimeRunReport>;
|
|
193
|
+
abort(reason?: unknown): void;
|
|
194
|
+
}
|
|
195
|
+
interface RuntimeAgentSessionSnapshot extends AgentSessionSnapshot {
|
|
196
|
+
readonly memoryBindingId?: string;
|
|
197
|
+
}
|
|
198
|
+
interface RuntimeAgentSession {
|
|
199
|
+
readonly conversationId: string;
|
|
200
|
+
readonly isRunning: boolean;
|
|
201
|
+
run(input: AgentInput, options?: RuntimeAgentInvocationOptions): Promise<RuntimeAgentResponse>;
|
|
202
|
+
stream(input: AgentInput, options?: RuntimeAgentInvocationOptions): RuntimeAgentRunHandle;
|
|
203
|
+
inject(input: AgentInput): number;
|
|
204
|
+
snapshot(): RuntimeAgentSessionSnapshot;
|
|
205
|
+
compact(options?: RuntimeAgentInvocationOptions): Promise<CompactionResult | null>;
|
|
206
|
+
reset(): void;
|
|
207
|
+
whenIdle(signal?: AbortSignal): Promise<void>;
|
|
208
|
+
}
|
|
209
|
+
interface RuntimeAgent {
|
|
210
|
+
readonly model: ModelTarget;
|
|
211
|
+
generate(input: AgentInput, options?: RuntimeAgentInvocationOptions): Promise<RuntimeAgentResponse>;
|
|
212
|
+
stream(input: AgentInput, options?: RuntimeAgentInvocationOptions): RuntimeAgentRunHandle;
|
|
213
|
+
createSession(options?: RuntimeAgentSessionOptions): RuntimeAgentSession;
|
|
214
|
+
resumeSession(snapshot: RuntimeAgentSessionSnapshot, options?: RuntimeAgentSessionOptions): RuntimeAgentSession;
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
export { RuntimeAgent, RuntimeAgentBindingInput, RuntimeAgentDefinition, RuntimeAgentDefinitionInput, RuntimeAgentInvocationOptions, RuntimeAgentLimits, RuntimeAgentResponse, RuntimeAgentRunEvent, RuntimeAgentRunEventContext, RuntimeAgentRunHandle, RuntimeAgentSession, RuntimeAgentSessionOptions, RuntimeAgentSessionSnapshot };
|
|
218
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/composition/agent/types.ts"],"m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WAEA,QAAQ,QAAQ;WAChB,QAAQ,QAAQ;EACzB,MAAM;;UAGS,oCAAoC;WAC1C;;UAGM;WACN;WACA;EACT,IAAI,OAAO,YAAY,UAAU,gCAAgC,QAAQ;EACzE,OAAO,OAAO,YAAY,UAAU,gCAAgC;EACpE,OAAO,OAAO;EACd,YAAY;EACZ,QAAQ,UAAU,gCAAgC,QAAQ;EAC1D;EACA,SAAS,SAAS,cAAc;;UAGjB;WACN,OAAO;EAChB,SAAS,OAAO,YAAY,UAAU,gCAAgC,QAAQ;EAC9E,OAAO,OAAO,YAAY,UAAU,gCAAgC;EACpE,cAAc,UAAU,6BAA6B;EACrD,cAAc,UAAU,6BAA6B,UAAU,6BAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counter.js","names":[],"sources":["../../../src/composition/common/counter.ts"],"sourcesContent":["/** Add monotonic health/accounting counters without wrapping past safe integer precision. */\nexport function saturatingCounterAdd(left: number, right: number): number {\n const total = left + right\n return Number.isSafeInteger(total) && total >= 0 ? total : Number.MAX_SAFE_INTEGER\n}\n"],"mappings":"AACA,SAAgB,EAAqB,EAAc,EAAuB,CACxE,IAAM,EAAQ,EAAO,EACrB,OAAO,OAAO,cAAc,CAAK,GAAK,GAAS,EAAI,SACrD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CapabilityIdentityConflict } from "../../errors/capability-identity.js";
|
|
2
|
+
//#region src/composition/common/errors.d.ts
|
|
3
|
+
interface RuntimeComponentCloseReport {
|
|
4
|
+
readonly kind: 'provider-registration' | 'observation-exporter' | 'agent-team';
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly status: 'closed' | 'failed' | 'timed-out';
|
|
7
|
+
readonly error?: {
|
|
8
|
+
readonly code: string;
|
|
9
|
+
readonly stage: string;
|
|
10
|
+
readonly message: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { type CapabilityIdentityConflict, RuntimeComponentCloseReport };
|
|
15
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../../../src/composition/common/errors.ts"],"mappings":";;UAoBiB;WACN;WACA;WACA;WACA;aAAmB;aAAuB;aAAwB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class extends Error{code=`RUNTIME_CONSTRUCTION_FAILED`;failureCode;stage;reason;component;conflict;cleanup;constructor(e){super(`Agent runtime construction did not complete`),this.name=`AgentRuntimeConstructionError`,this.failureCode=e.failureCode,this.stage=e.stage,this.reason=e.reason,e.component!==void 0&&(this.component=Object.freeze({...e.component})),e.conflict!==void 0&&(this.conflict=Object.freeze({...e.conflict})),this.cleanup=Object.freeze((e.cleanup??[]).map(e=>Object.freeze({...e,...e.error===void 0?{}:{error:Object.freeze({...e.error})}})))}};function t(t=`CAPABILITY_STARTUP_FAILED`,n){return new e({failureCode:t,stage:`preflight`,reason:`invalid`,...n===void 0?{}:{conflict:n}})}function n(t){if(t?.aborted)throw new e({failureCode:`CAPABILITY_STARTUP_ABORTED`,stage:`preflight`,reason:`aborted`})}export{e as AgentRuntimeConstructionError,n as checkPreflightAbort,t as invalidPreflight};
|
|
2
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../../../src/composition/common/errors.ts"],"sourcesContent":["export type RuntimeConstructionFailureReason = 'invalid' | 'failed' | 'timed-out' | 'aborted'\n\nexport type RuntimeConstructionFailureCode =\n | 'CAPABILITY_KIND_MISMATCH'\n | 'CAPABILITY_API_UNSUPPORTED'\n | 'CAPABILITY_ID_CONFLICT'\n | 'PROVIDER_ROUTE_CONFLICT'\n | 'PROVIDER_SETUP_ASYNC_UNSUPPORTED'\n | 'OBSERVATION_BOUNDARY_UNSUPPORTED'\n | 'CAPABILITY_STARTUP_FAILED'\n | 'CAPABILITY_STARTUP_TIMEOUT'\n | 'CAPABILITY_STARTUP_ABORTED'\n\nimport type { CapabilityIdentityConflict } from '../../errors/capability-identity.ts'\nexport type { CapabilityIdentityConflict } from '../../errors/capability-identity.ts'\n\nexport type RuntimeConstructionComponent =\n | { readonly kind: 'provider-plugin'; readonly id: string }\n | { readonly kind: 'observation-exporter'; readonly id: string }\n\nexport interface RuntimeComponentCloseReport {\n readonly kind: 'provider-registration' | 'observation-exporter' | 'agent-team'\n readonly id: string\n readonly status: 'closed' | 'failed' | 'timed-out'\n readonly error?: { readonly code: string; readonly stage: string; readonly message: string }\n}\n\nexport interface ConstructionFailure {\n readonly failureCode: RuntimeConstructionFailureCode\n readonly stage: 'preflight' | 'provider-setup' | 'exporter-ready' | 'activation'\n readonly reason: RuntimeConstructionFailureReason\n readonly component?: RuntimeConstructionComponent\n readonly conflict?: CapabilityIdentityConflict\n readonly cleanup?: readonly RuntimeComponentCloseReport[]\n}\n\n/** Support-safe envelope: deliberately carries no raw input, exception or cause. */\nexport class AgentRuntimeConstructionError extends Error {\n readonly code = 'RUNTIME_CONSTRUCTION_FAILED' as const\n readonly failureCode: RuntimeConstructionFailureCode\n readonly stage: ConstructionFailure['stage']\n readonly reason: RuntimeConstructionFailureReason\n readonly component?: RuntimeConstructionComponent\n readonly conflict?: CapabilityIdentityConflict\n readonly cleanup: readonly RuntimeComponentCloseReport[]\n\n constructor(failure: ConstructionFailure) {\n super('Agent runtime construction did not complete')\n this.name = 'AgentRuntimeConstructionError'\n this.failureCode = failure.failureCode\n this.stage = failure.stage\n this.reason = failure.reason\n if (failure.component !== undefined) this.component = Object.freeze({ ...failure.component })\n if (failure.conflict !== undefined) this.conflict = Object.freeze({ ...failure.conflict })\n this.cleanup = Object.freeze((failure.cleanup ?? []).map(row => Object.freeze({\n ...row,\n ...(row.error === undefined ? {} : { error: Object.freeze({ ...row.error }) }),\n })))\n }\n}\n\nexport function invalidPreflight(\n failureCode: RuntimeConstructionFailureCode = 'CAPABILITY_STARTUP_FAILED',\n conflict?: CapabilityIdentityConflict,\n): AgentRuntimeConstructionError {\n return new AgentRuntimeConstructionError({\n failureCode, stage: 'preflight', reason: 'invalid',\n ...(conflict === undefined ? {} : { conflict }),\n })\n}\n\nexport function checkPreflightAbort(signal?: AbortSignal): void {\n if (signal?.aborted) throw new AgentRuntimeConstructionError({\n failureCode: 'CAPABILITY_STARTUP_ABORTED', stage: 'preflight', reason: 'aborted',\n })\n}\n"],"mappings":"AAqCA,IAAa,EAAb,cAAmD,KAAM,CACvD,KAAgB,8BAChB,YACA,MACA,OACA,UACA,SACA,QAEA,YAAY,EAA8B,CACxC,MAAM,6CAA6C,EACnD,KAAK,KAAO,gCACZ,KAAK,YAAc,EAAQ,YAC3B,KAAK,MAAQ,EAAQ,MACrB,KAAK,OAAS,EAAQ,OAClB,EAAQ,YAAc,IAAA,KAAW,KAAK,UAAY,OAAO,OAAO,CAAE,GAAG,EAAQ,SAAU,CAAC,GACxF,EAAQ,WAAa,IAAA,KAAW,KAAK,SAAW,OAAO,OAAO,CAAE,GAAG,EAAQ,QAAS,CAAC,GACzF,KAAK,QAAU,OAAO,QAAQ,EAAQ,SAAW,CAAC,EAAA,CAAG,IAAI,GAAO,OAAO,OAAO,CAC5E,GAAG,EACH,GAAI,EAAI,QAAU,IAAA,GAAY,CAAC,EAAI,CAAE,MAAO,OAAO,OAAO,CAAE,GAAG,EAAI,KAAM,CAAC,CAAE,CAC9E,CAAC,CAAC,CAAC,CACL,CACF,EAEA,SAAgB,EACd,EAA8C,4BAC9C,EAC+B,CAC/B,OAAO,IAAI,EAA8B,CACvC,cAAa,MAAO,YAAa,OAAQ,UACzC,GAAI,IAAa,IAAA,GAAY,CAAC,EAAI,CAAE,UAAS,CAC/C,CAAC,CACH,CAEA,SAAgB,EAAoB,EAA4B,CAC9D,GAAI,GAAQ,QAAS,MAAM,IAAI,EAA8B,CAC3D,YAAa,6BAA8B,MAAO,YAAa,OAAQ,SACzE,CAAC,CACH"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{snapshotJsonObject as e,snapshotJsonValue as t}from"../../primitives/json-snapshot.js";const n=Object.freeze({fields:64,array:100,depth:8,nodes:4096,keyBytes:128,bytes:65536});function r(t){return e(t,a())}function i(e){return t(e,a())}function a(){return{maxObjectFields:n.fields,maxArrayItems:n.array,maxDepth:n.depth,maxNodes:n.nodes,maxKeyBytes:n.keyBytes,maxBytes:n.bytes}}export{r as cloneJsonObject,i as cloneJsonValue};
|
|
2
|
+
//# sourceMappingURL=json-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-data.js","names":[],"sources":["../../../src/composition/common/json-data.ts"],"sourcesContent":["import type { JsonObject, JsonValue } from '../../primitives/index.ts'\nimport { snapshotJsonObject, snapshotJsonValue } from '../../primitives/json-snapshot.ts'\n\nconst JSON_DATA_LIMITS = Object.freeze({ fields: 64, array: 100, depth: 8, nodes: 4_096, keyBytes: 128, bytes: 64 * 1024 })\n\n/** Strict lossless-JSON clone. Accessors, sparse arrays, classes, cycles and non-finite numbers are rejected. */\nexport function cloneJsonObject(value: unknown): Readonly<JsonObject> {\n return snapshotJsonObject(value, limits())\n}\n\n/** Strict bounded clone for a JSON value crossing a public composition boundary. */\nexport function cloneJsonValue(value: unknown): JsonValue {\n return snapshotJsonValue(value, limits())\n}\n\nfunction limits() {\n return {\n maxObjectFields: JSON_DATA_LIMITS.fields,\n maxArrayItems: JSON_DATA_LIMITS.array,\n maxDepth: JSON_DATA_LIMITS.depth,\n maxNodes: JSON_DATA_LIMITS.nodes,\n maxKeyBytes: JSON_DATA_LIMITS.keyBytes,\n maxBytes: JSON_DATA_LIMITS.bytes,\n }\n}\n"],"mappings":"8FAGA,MAAM,EAAmB,OAAO,OAAO,CAAE,OAAQ,GAAI,MAAO,IAAK,MAAO,EAAG,MAAO,KAAO,SAAU,IAAK,MAAO,KAAU,CAAC,EAG1H,SAAgB,EAAgB,EAAsC,CACpE,OAAO,EAAmB,EAAO,EAAO,CAAC,CAC3C,CAGA,SAAgB,EAAe,EAA2B,CACxD,OAAO,EAAkB,EAAO,EAAO,CAAC,CAC1C,CAEA,SAAS,GAAS,CAChB,MAAO,CACL,gBAAiB,EAAiB,OAClC,cAAe,EAAiB,MAChC,SAAU,EAAiB,MAC3B,SAAU,EAAiB,MAC3B,YAAa,EAAiB,SAC9B,SAAU,EAAiB,KAC7B,CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","names":[],"sources":["../../../src/composition/credential/config.ts"],"mappings":";cAAa"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","names":[],"sources":["../../../src/composition/credential/config.ts"],"sourcesContent":["export const CREDENTIAL_CAPABILITY_API_VERSION = 1 as const\n\nexport const CREDENTIAL_CAPABILITY_ERROR_CODES = Object.freeze({\n SOURCE_INVALID: 'CREDENTIAL_SOURCE_INVALID',\n STORE_INVALID: 'CREDENTIAL_STORE_INVALID',\n} as const)\n"],"mappings":"AAAA,MAAa,EAAoC,EAEpC,EAAoC,OAAO,OAAO,CAC7D,eAAgB,4BAChB,cAAe,0BACjB,CAAU"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CredentialSource, CredentialSourceDefinition, CredentialStore, CredentialStoreDefinition } from "./types.js";
|
|
2
|
+
//#region src/composition/credential/definition.d.ts
|
|
3
|
+
/** Side-effect-free author helper; executable references retain the caller receiver. */
|
|
4
|
+
declare function defineCredentialSource(definition: CredentialSourceDefinition): CredentialSource;
|
|
5
|
+
/** Side-effect-free author helper; it neither reads credentials nor mutates the caller store. */
|
|
6
|
+
declare function defineCredentialStore<Value>(definition: CredentialStoreDefinition<Value>): CredentialStore<Value>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { defineCredentialSource, defineCredentialStore };
|
|
9
|
+
//# sourceMappingURL=definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.d.ts","names":[],"sources":["../../../src/composition/credential/definition.ts"],"mappings":";;;iBAYgB,uBAAuB,YAAY,6BAA6B;;iBAehE,sBAAsB,OAAO,YAAY,0BAA0B,SAAS,gBAAgB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{AgentSdkError as e}from"../../errors/agent-sdk-error.js";import{boundedText as t,capturedMethod as n,objectValue as r,ownData as i}from"../../capability/common/data.js";import{runCoreCapabilityAsync as a,runCoreCapabilityMaybeAsync as o}from"../../platform/capability-operation.js";import{COMPOSITION_LIMITS as s}from"../../capability/common/config.js";import{CREDENTIAL_CAPABILITY_ERROR_CODES as c}from"./config.js";function l(a){try{let e=r(a),c=t(i(e,`id`),s.identityBytes),l=n(e,`resolve`);return Object.freeze({kind:`credential-source`,apiVersion:1,id:c,resolve:e=>o(e.logger,`core-credential`,`resolve`,e.signal,()=>l(e))})}catch{throw new e(`Credential source definition is invalid`,c.SOURCE_INVALID)}}function u(o){try{let e=r(o),c=t(i(e,`id`),s.identityBytes),l=t(i(e,`label`),s.displayNameBytes),u=n(e,`read`),d=n(e,`commit`);return Object.freeze({kind:`credential-store`,apiVersion:1,id:c,label:l,read:e=>a(e.logger,`core-credential`,`read`,e.signal,()=>u(e)),commit:(e,t)=>a(t.logger,`core-credential`,`commit`,t.signal,()=>d(e,t))})}catch{throw new e(`Credential store definition is invalid`,c.STORE_INVALID)}}export{l as defineCredentialSource,u as defineCredentialStore};
|
|
2
|
+
//# sourceMappingURL=definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.js","names":[],"sources":["../../../src/composition/credential/definition.ts"],"sourcesContent":["import { COMPOSITION_LIMITS } from '../common/config.ts'\nimport { boundedText, capturedMethod, objectValue, ownData } from '../common/data.ts'\nimport { AgentSdkError } from '../../errors/agent-sdk-error.ts'\nimport { CREDENTIAL_CAPABILITY_API_VERSION, CREDENTIAL_CAPABILITY_ERROR_CODES } from './config.ts'\nimport { runCoreCapabilityAsync, runCoreCapabilityMaybeAsync } from '../logging/capability.ts'\nimport type {\n CredentialCommitInput, CredentialCommitResult, CredentialOperationOptions,\n CredentialRecord, CredentialSource, CredentialSourceDefinition, CredentialStore,\n CredentialStoreDefinition,\n} from './types.ts'\n\n/** Side-effect-free author helper; executable references retain the caller receiver. */\nexport function defineCredentialSource(definition: CredentialSourceDefinition): CredentialSource {\n try {\n const source = objectValue(definition)\n const id = boundedText(ownData(source, 'id'), COMPOSITION_LIMITS.identityBytes)\n const capturedResolve = capturedMethod<[CredentialOperationOptions], string | Promise<string>>(source, 'resolve')\n const resolve = (options: CredentialOperationOptions): string | Promise<string> =>\n runCoreCapabilityMaybeAsync(options.logger, 'core-credential', 'resolve', options.signal,\n () => capturedResolve(options))\n return Object.freeze({ kind: 'credential-source', apiVersion: CREDENTIAL_CAPABILITY_API_VERSION, id, resolve })\n } catch {\n throw new AgentSdkError('Credential source definition is invalid', CREDENTIAL_CAPABILITY_ERROR_CODES.SOURCE_INVALID)\n }\n}\n\n/** Side-effect-free author helper; it neither reads credentials nor mutates the caller store. */\nexport function defineCredentialStore<Value>(definition: CredentialStoreDefinition<Value>): CredentialStore<Value> {\n try {\n const source = objectValue(definition)\n const id = boundedText(ownData(source, 'id'), COMPOSITION_LIMITS.identityBytes)\n const label = boundedText(ownData(source, 'label'), COMPOSITION_LIMITS.displayNameBytes)\n const capturedRead = capturedMethod<[CredentialOperationOptions], Promise<CredentialRecord<Value> | undefined>>(source, 'read')\n const capturedCommit = capturedMethod<\n [CredentialCommitInput<Value>, CredentialOperationOptions], Promise<CredentialCommitResult>\n >(source, 'commit')\n const read = (options: CredentialOperationOptions) =>\n runCoreCapabilityAsync(options.logger, 'core-credential', 'read', options.signal,\n () => capturedRead(options))\n const commit = (input: CredentialCommitInput<Value>, options: CredentialOperationOptions) =>\n runCoreCapabilityAsync(options.logger, 'core-credential', 'commit', options.signal,\n () => capturedCommit(input, options))\n return Object.freeze({ kind: 'credential-store', apiVersion: CREDENTIAL_CAPABILITY_API_VERSION,\n id, label, read, commit })\n } catch {\n throw new AgentSdkError('Credential store definition is invalid', CREDENTIAL_CAPABILITY_ERROR_CODES.STORE_INVALID)\n }\n}\n"],"mappings":"waAYA,SAAgB,EAAuB,EAA0D,CAC/F,GAAI,CACF,IAAM,EAAS,EAAY,CAAU,EAC/B,EAAK,EAAY,EAAQ,EAAQ,IAAI,EAAG,EAAmB,aAAa,EACxE,EAAkB,EAAuE,EAAQ,SAAS,EAIhH,OAAO,OAAO,OAAO,CAAE,KAAM,oBAAqB,WAAA,EAA+C,KAAI,QAHpF,GACf,EAA4B,EAAQ,OAAQ,kBAAmB,UAAW,EAAQ,WAC1E,EAAgB,CAAO,CAAC,CAC2E,CAAC,CAChH,MAAQ,CACN,MAAM,IAAI,EAAc,0CAA2C,EAAkC,cAAc,CACrH,CACF,CAGA,SAAgB,EAA6B,EAAsE,CACjH,GAAI,CACF,IAAM,EAAS,EAAY,CAAU,EAC/B,EAAK,EAAY,EAAQ,EAAQ,IAAI,EAAG,EAAmB,aAAa,EACxE,EAAQ,EAAY,EAAQ,EAAQ,OAAO,EAAG,EAAmB,gBAAgB,EACjF,EAAe,EAA2F,EAAQ,MAAM,EACxH,EAAiB,EAErB,EAAQ,QAAQ,EAOlB,OAAO,OAAO,OAAO,CAAE,KAAM,mBAAoB,WAAA,EAC/C,KAAI,QAAO,KAPC,GACZ,EAAuB,EAAQ,OAAQ,kBAAmB,OAAQ,EAAQ,WAClE,EAAa,CAAO,CAAC,EAKZ,QAJH,EAAqC,IACnD,EAAuB,EAAQ,OAAQ,kBAAmB,SAAU,EAAQ,WACpE,EAAe,EAAO,CAAO,CAAC,CAEd,CAAC,CAC7B,MAAQ,CACN,MAAM,IAAI,EAAc,yCAA0C,EAAkC,aAAa,CACnH,CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SdkLogger } from "../../logging/types.js";
|
|
2
|
+
import { CREDENTIAL_CAPABILITY_API_VERSION } from "./config.js";
|
|
3
|
+
//#region src/composition/credential/types.d.ts
|
|
4
|
+
interface CredentialOperationOptions {
|
|
5
|
+
readonly signal: AbortSignal;
|
|
6
|
+
readonly logger: SdkLogger;
|
|
7
|
+
}
|
|
8
|
+
interface CredentialSource {
|
|
9
|
+
readonly kind: 'credential-source';
|
|
10
|
+
readonly apiVersion: typeof CREDENTIAL_CAPABILITY_API_VERSION;
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly resolve: (options: CredentialOperationOptions) => string | Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
type CredentialInput = string | CredentialSource;
|
|
15
|
+
interface CredentialRecord<Value> {
|
|
16
|
+
readonly value: Value;
|
|
17
|
+
readonly revision: string;
|
|
18
|
+
}
|
|
19
|
+
interface CredentialCommitInput<Value> {
|
|
20
|
+
readonly value: Value;
|
|
21
|
+
readonly expectedRevision: string | null;
|
|
22
|
+
}
|
|
23
|
+
interface CredentialCommitResult {
|
|
24
|
+
readonly revision: string;
|
|
25
|
+
}
|
|
26
|
+
interface CredentialStore<Value> {
|
|
27
|
+
readonly kind: 'credential-store';
|
|
28
|
+
readonly apiVersion: typeof CREDENTIAL_CAPABILITY_API_VERSION;
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly label: string;
|
|
31
|
+
readonly read: (options: CredentialOperationOptions) => Promise<CredentialRecord<Value> | undefined>;
|
|
32
|
+
readonly commit: (input: CredentialCommitInput<Value>, options: CredentialOperationOptions) => Promise<CredentialCommitResult>;
|
|
33
|
+
}
|
|
34
|
+
type CredentialStoreDefinition<Value> = Omit<CredentialStore<Value>, 'kind' | 'apiVersion'>;
|
|
35
|
+
type CredentialSourceDefinition = Omit<CredentialSource, 'kind' | 'apiVersion'>;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { CredentialCommitInput, CredentialCommitResult, CredentialInput, CredentialOperationOptions, CredentialRecord, CredentialSource, CredentialSourceDefinition, CredentialStore, CredentialStoreDefinition };
|
|
38
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/composition/credential/types.ts"],"mappings":";;;UAGiB;WACN,QAAQ;WACR,QAAQ;;UAGF;WACN;WACA,mBAAmB;WACnB;WACA,UAAU,SAAS,wCAAwC;;KAG1D,2BAA2B;UAEtB,iBAAiB;WACvB,OAAO;WACP;;UAGM,sBAAsB;WAC5B,OAAO;WACP;;UAGM;WAAkC;;UAElC,gBAAgB;WACtB;WACA,mBAAmB;WACnB;WACA;WACA,OAAO,SAAS,+BAA+B,QAAQ,iBAAiB;WACxE,SACP,OAAO,sBAAsB,QAC7B,SAAS,+BACN,QAAQ;;KAGH,0BAA0B,SAAS,KAAK,gBAAgB;KACxD,6BAA6B,KAAK"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{arrayData as e,objectValue as t,ownData as n}from"../../capability/common/data.js";import{DELIVERY_ERROR_CODES as r}from"../../agent/accounting/delivery/config.js";var i=class extends Error{code=r.ACK_INVALID;constructor(){super(`Observation acknowledgment is invalid`),this.name=`DeliveryAckError`}};function a(r,a){try{let o=t(r);if(n(o,`batchId`)!==a.id)throw new i;let s=(t,r)=>{let a=e(n(o,t),r.length),s=new Set,c=a.map(e=>{if(typeof e!=`string`||!r.includes(e)||s.has(e))throw new i;return s.add(e),e});return Object.freeze(c)};return Object.freeze({batchId:a.id,acceptedEventIds:s(`acceptedEventIds`,a.events.map(e=>e.eventId)),acceptedRunIds:s(`acceptedRunIds`,a.runRecords.map(e=>e.runId))})}catch{throw new i}}export{i as DeliveryAckError,a as validateDeliveryAck};
|
|
2
|
+
//# sourceMappingURL=ack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ack.js","names":[],"sources":["../../../src/composition/delivery/ack.ts"],"sourcesContent":["import { arrayData, objectValue, ownData } from '../common/data.ts'\nimport type { ObservationDeliveryAck, ObservationDeliveryBatch } from '../exporter/delivery-types.ts'\nimport { DELIVERY_ERROR_CODES } from './config.ts'\n\nexport class DeliveryAckError extends Error {\n readonly code = DELIVERY_ERROR_CODES.ACK_INVALID\n constructor() { super('Observation acknowledgment is invalid'); this.name = 'DeliveryAckError' }\n}\n\n/** Validate both namespaces atomically; never apply the valid half of a malformed acknowledgment. */\nexport function validateDeliveryAck(value: unknown, batch: ObservationDeliveryBatch): ObservationDeliveryAck {\n try {\n const source = objectValue(value)\n if (ownData(source, 'batchId') !== batch.id) throw new DeliveryAckError()\n const list = (key: string, allowed: readonly string[]): readonly string[] => {\n const input = arrayData(ownData(source, key), allowed.length)\n const ids = new Set<string>()\n const accepted = input.map(value => {\n if (typeof value !== 'string' || !allowed.includes(value) || ids.has(value)) throw new DeliveryAckError()\n ids.add(value)\n return value\n })\n return Object.freeze(accepted)\n }\n return Object.freeze({ batchId: batch.id,\n acceptedEventIds: list('acceptedEventIds', batch.events.map(event => event.eventId)),\n acceptedRunIds: list('acceptedRunIds', batch.runRecords.map(record => record.runId)) })\n } catch { throw new DeliveryAckError() }\n}\n"],"mappings":"2KAIA,IAAa,EAAb,cAAsC,KAAM,CAC1C,KAAgB,EAAqB,YACrC,aAAc,CAAE,MAAM,uCAAuC,EAAG,KAAK,KAAO,kBAAmB,CACjG,EAGA,SAAgB,EAAoB,EAAgB,EAAyD,CAC3G,GAAI,CACF,IAAM,EAAS,EAAY,CAAK,EAChC,GAAI,EAAQ,EAAQ,SAAS,IAAM,EAAM,GAAI,MAAM,IAAI,EACvD,IAAM,GAAQ,EAAa,IAAkD,CAC3E,IAAM,EAAQ,EAAU,EAAQ,EAAQ,CAAG,EAAG,EAAQ,MAAM,EACtD,EAAM,IAAI,IACV,EAAW,EAAM,IAAI,GAAS,CAClC,GAAI,OAAO,GAAU,UAAY,CAAC,EAAQ,SAAS,CAAK,GAAK,EAAI,IAAI,CAAK,EAAG,MAAM,IAAI,EAEvF,OADA,EAAI,IAAI,CAAK,EACN,CACT,CAAC,EACD,OAAO,OAAO,OAAO,CAAQ,CAC/B,EACA,OAAO,OAAO,OAAO,CAAE,QAAS,EAAM,GACpC,iBAAkB,EAAK,mBAAoB,EAAM,OAAO,IAAI,GAAS,EAAM,OAAO,CAAC,EACnF,eAAgB,EAAK,iBAAkB,EAAM,WAAW,IAAI,GAAU,EAAO,KAAK,CAAC,CAAE,CAAC,CAC1F,MAAQ,CAAE,MAAM,IAAI,CAAmB,CACzC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{capturedMethod as e}from"../../capability/common/data.js";import{DELIVERY_ERROR_CODES as t}from"../../agent/accounting/delivery/config.js";import{DeliveryDataError as n}from"../../agent/accounting/delivery/data.js";import{isPreparedBatch as r}from"./batch.js";import{BoundaryFailure as i,atDeadline as a}from"../lifecycle/bounded.js";import{validateDeliveryAck as o}from"./ack.js";var s=class{batch;resources;events=new Set;runs=new Set;abort;sendBatch;boundary;inFlight;sealed=!1;constructor(t,i,a){if(this.batch=t,this.resources=a,!r(t)||!i.exporter.supportedBoundaries.includes(i.boundary))throw new n;this.boundary=i.boundary,this.sendBatch=e(i.exporter,`export`),this.abort=a.platform.controller()}complete(){return this.events.size===this.batch.events.length&&this.runs.size===this.batch.runRecords.length}send(e,n){return this.inFlight===void 0?this.sealed||this.resources.isClosed?Promise.resolve(this.report(`closed`,t.CLOSED)):this.complete()?Promise.resolve(this.report(`complete`)):(this.inFlight=this.exportOnce(e,n).finally(()=>{this.inFlight=void 0}),this.inFlight):this.inFlight}seal(){this.sealed||(this.sealed=!0,this.abort.abort(Error(`Observation delivery is closed`)))}async exportOnce(e,n){let r,s=`export`;try{r=this.resources.cancellation([this.abort.signal,...n===void 0?[]:[n]]);let i=await a(this.resources,e,e=>this.sendBatch(this.batch,e),r.signal);if(this.sealed||this.resources.isClosed)return this.report(`closed`,t.CLOSED);s=`ack`;let c=o(i,this.batch);if(this.resources.platform.monotonicNow()>=e)return r.cancel(),this.report(`timed-out`,t.TIMEOUT,`ack`);if(this.sealed||this.resources.isClosed)return this.report(`closed`,t.CLOSED);if(r.signal.aborted)return this.report(`aborted`,t.ABORTED);for(let e of c.acceptedEventIds)this.events.add(e);for(let e of c.acceptedRunIds)this.runs.add(e);return this.report(this.complete()?`complete`:`partial`)}catch(e){let n=e instanceof i?e.reason:`failed`;return this.sealed||this.resources.isClosed?this.report(`closed`,t.CLOSED):n===`timed-out`?this.report(`timed-out`,t.TIMEOUT):n===`aborted`?this.report(`aborted`,t.ABORTED):this.report(`failed`,s===`ack`?t.ACK_INVALID:t.EXPORT_FAILED,s)}finally{r?.dispose()}}report(e,t,n=`export`){return Object.freeze({status:e,complete:this.complete(),boundary:this.complete()?this.boundary:`none`,acceptedEventIds:Object.freeze(this.batch.events.filter(e=>this.events.has(e.eventId)).map(e=>e.eventId)),acceptedRunIds:Object.freeze(this.batch.runRecords.filter(e=>this.runs.has(e.runId)).map(e=>e.runId)),...t===void 0?{}:{error:Object.freeze({code:t,stage:n,message:`Observation delivery did not complete`})}})}};export{s as DeliveryAttempt};
|
|
2
|
+
//# sourceMappingURL=attempt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt.js","names":[],"sources":["../../../src/composition/delivery/attempt.ts"],"sourcesContent":["import type { ObservationBoundary } from '../../observation/index.ts'\nimport { RuntimeResources, type CancellationScope } from '../../platform/resources.ts'\nimport { capturedMethod } from '../common/data.ts'\nimport type { ObservationDeliveryAck, ObservationDeliveryBatch } from '../exporter/delivery-types.ts'\nimport type { RuntimeObservationExporterRegistration } from '../exporter/types.ts'\nimport { atDeadline, BoundaryFailure } from '../lifecycle/bounded.ts'\nimport { validateDeliveryAck } from './ack.ts'\nimport { isPreparedBatch } from './batch.ts'\nimport { DELIVERY_ERROR_CODES } from './config.ts'\nimport { DeliveryDataError } from './data.ts'\n\nexport interface DeliveryAttemptReport {\n readonly status: 'complete' | 'partial' | 'failed' | 'timed-out' | 'aborted' | 'closed'\n readonly complete: boolean\n readonly boundary: ObservationBoundary\n readonly acceptedEventIds: readonly string[]\n readonly acceptedRunIds: readonly string[]\n readonly error?: { readonly code: string; readonly stage: 'export' | 'ack'; readonly message: string }\n}\n\n/** One exporter/batch checkpoint. Retry keeps the exact frozen batch and canonical run-record identities. */\nexport class DeliveryAttempt {\n private readonly events = new Set<string>()\n private readonly runs = new Set<string>()\n private readonly abort: AbortController\n private readonly sendBatch: (batch: ObservationDeliveryBatch, signal: AbortSignal) => Promise<ObservationDeliveryAck>\n private readonly boundary: ObservationBoundary\n private inFlight: Promise<DeliveryAttemptReport> | undefined\n private sealed = false\n\n constructor(\n private readonly batch: ObservationDeliveryBatch,\n registration: RuntimeObservationExporterRegistration,\n private readonly resources: RuntimeResources,\n ) {\n if (!isPreparedBatch(batch) || !registration.exporter.supportedBoundaries.includes(registration.boundary)) throw new DeliveryDataError()\n this.boundary = registration.boundary\n this.sendBatch = capturedMethod(registration.exporter, 'export')\n this.abort = resources.platform.controller()\n }\n\n private complete(): boolean { return this.events.size === this.batch.events.length && this.runs.size === this.batch.runRecords.length }\n\n send(deadlineAt: number, caller?: AbortSignal): Promise<DeliveryAttemptReport> {\n if (this.inFlight !== undefined) return this.inFlight\n if (this.sealed || this.resources.isClosed) return Promise.resolve(this.report('closed', DELIVERY_ERROR_CODES.CLOSED))\n if (this.complete()) return Promise.resolve(this.report('complete'))\n this.inFlight = this.exportOnce(deadlineAt, caller).finally(() => { this.inFlight = undefined })\n return this.inFlight\n }\n\n seal(): void {\n if (this.sealed) return\n this.sealed = true\n this.abort.abort(new Error('Observation delivery is closed'))\n }\n\n private async exportOnce(deadlineAt: number, caller?: AbortSignal): Promise<DeliveryAttemptReport> {\n let scope: CancellationScope | undefined\n let stage: 'export' | 'ack' = 'export'\n try {\n scope = this.resources.cancellation([this.abort.signal, ...caller === undefined ? [] : [caller]])\n const value = await atDeadline(this.resources, deadlineAt, signal => this.sendBatch(this.batch, signal), scope.signal)\n if (this.sealed || this.resources.isClosed) return this.report('closed', DELIVERY_ERROR_CODES.CLOSED)\n stage = 'ack'\n const ack = validateDeliveryAck(value, this.batch)\n if (this.resources.platform.monotonicNow() >= deadlineAt) {\n scope.cancel()\n return this.report('timed-out', DELIVERY_ERROR_CODES.TIMEOUT, 'ack')\n }\n // An accessor/Proxy may abort while it is inspected. Recheck before committing any acceptance.\n if (this.sealed || this.resources.isClosed) return this.report('closed', DELIVERY_ERROR_CODES.CLOSED)\n if (scope.signal.aborted) return this.report('aborted', DELIVERY_ERROR_CODES.ABORTED)\n for (const id of ack.acceptedEventIds) this.events.add(id)\n for (const id of ack.acceptedRunIds) this.runs.add(id)\n return this.report(this.complete() ? 'complete' : 'partial')\n } catch (error) {\n const reason = error instanceof BoundaryFailure ? error.reason : 'failed'\n if (this.sealed || this.resources.isClosed) return this.report('closed', DELIVERY_ERROR_CODES.CLOSED)\n if (reason === 'timed-out') return this.report('timed-out', DELIVERY_ERROR_CODES.TIMEOUT)\n if (reason === 'aborted') return this.report('aborted', DELIVERY_ERROR_CODES.ABORTED)\n return this.report('failed', stage === 'ack' ? DELIVERY_ERROR_CODES.ACK_INVALID : DELIVERY_ERROR_CODES.EXPORT_FAILED, stage)\n } finally { scope?.dispose() }\n }\n\n private report(status: DeliveryAttemptReport['status'], code?: string, stage: 'export' | 'ack' = 'export'): DeliveryAttemptReport {\n return Object.freeze({ status, complete: this.complete(), boundary: this.complete() ? this.boundary : 'none',\n acceptedEventIds: Object.freeze(this.batch.events.filter(event => this.events.has(event.eventId)).map(event => event.eventId)),\n acceptedRunIds: Object.freeze(this.batch.runRecords.filter(record => this.runs.has(record.runId)).map(record => record.runId)),\n ...(code === undefined ? {} : { error: Object.freeze({ code, stage, message: 'Observation delivery did not complete' }) }) })\n }\n}\n"],"mappings":"oYAqBA,IAAa,EAAb,KAA6B,CAUR,MAEA,UAXnB,OAA0B,IAAI,IAC9B,KAAwB,IAAI,IAC5B,MACA,UACA,SACA,SACA,OAAiB,GAEjB,YACE,EACA,EACA,EACA,CACA,GAJiB,KAAA,MAAA,EAEA,KAAA,UAAA,EAEb,CAAC,EAAgB,CAAK,GAAK,CAAC,EAAa,S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
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{arrayData as e}from"../../capability/common/data.js";import{DELIVERY_LIMITS as t}from"../../agent/accounting/delivery/config.js";import{DeliveryDataError as n,bytes as r,count as i}from"../../agent/accounting/delivery/data.js";import{isRuntimeResource as a}from"./resource.js";import{isPreparedEvent as o,prepareDeliveryEvent as s}from"./event.js";import{isPreparedTerminal as c}from"../../agent/accounting/delivery/terminal.js";const l=new WeakSet;function u(e){return l.has(e)}function d(e,t){if(!a(e))throw new n;let i=c(t)?void 0:t;if(i!==void 0&&(!o(i)||i.resource!==e))throw new n;return r({id:`0`.repeat(32),resource:e,events:i===void 0?[]:[i],runRecords:i===void 0?[t]:[]})}function f(e,t,i){if(!a(e)||t.some(t=>!o(t)||t.resource!==e)||i.some(e=>!c(e)))throw new n;return r({id:`0`.repeat(32),resource:e,events:t,runRecords:i})}function p(o,u,d,f,p={}){try{if(!a(o))throw new n;let m=i(p.maxItems??t.batchItems),h=i(p.maxBytes??t.batchBytes),g=p.content??`none`;if(m===0||m>t.maxBatchItems||h===0||h>t.maxBatchBytes||g!==`none`&&g!==`metadata`)throw new n;let _=e(u,m),v=e(d,m);if(_.length+v.length===0||_.length+v.length>m)throw new n;let y=r(o),b=e=>{if(y+=r(e),y>h)throw new n},x=_.map(e=>{let t=s(e,o,g);return b(t),t}),S=v.map(e=>{if(!c(e))throw new n;return b(e),e});if(new Set(x.map(e=>e.eventId)).size!==x.length||new Set(S.map(e=>e.runId)).size!==S.length)throw new n;let C=Object.freeze({id:f.randomHex(16),resource:o,events:Object.freeze(x),runRecords:Object.freeze(S)});if(r(C)>h)throw new n;return l.add(C),C}catch{throw new n}}export{p as createDeliveryBatch,d as deliveryBatchItemBytes,f as deliveryBatchItemsBytes,u as isPreparedBatch};
|
|
2
|
+
//# sourceMappingURL=batch.js.map
|