@methodts/runtime 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/dist/__fixtures__/executor-fixtures.d.ts +10 -0
- package/dist/__fixtures__/executor-fixtures.d.ts.map +1 -0
- package/dist/__fixtures__/executor-fixtures.js +36 -0
- package/dist/__fixtures__/executor-fixtures.js.map +1 -0
- package/dist/architecture.test.d.ts +2 -0
- package/dist/architecture.test.d.ts.map +1 -0
- package/dist/architecture.test.js +143 -0
- package/dist/architecture.test.js.map +1 -0
- package/dist/config/cost-governor-config.d.ts +40 -0
- package/dist/config/cost-governor-config.d.ts.map +1 -0
- package/dist/config/cost-governor-config.js +48 -0
- package/dist/config/cost-governor-config.js.map +1 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +6 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/sessions-config.d.ts +29 -0
- package/dist/config/sessions-config.d.ts.map +1 -0
- package/dist/config/sessions-config.js +37 -0
- package/dist/config/sessions-config.js.map +1 -0
- package/dist/config/strategies-config.d.ts +38 -0
- package/dist/config/strategies-config.d.ts.map +1 -0
- package/dist/config/strategies-config.js +41 -0
- package/dist/config/strategies-config.js.map +1 -0
- package/dist/cost-governor/backpressure-queue.d.ts +20 -0
- package/dist/cost-governor/backpressure-queue.d.ts.map +1 -0
- package/dist/cost-governor/backpressure-queue.js +78 -0
- package/dist/cost-governor/backpressure-queue.js.map +1 -0
- package/dist/cost-governor/backpressure-queue.test.d.ts +2 -0
- package/dist/cost-governor/backpressure-queue.test.d.ts.map +1 -0
- package/dist/cost-governor/backpressure-queue.test.js +48 -0
- package/dist/cost-governor/backpressure-queue.test.js.map +1 -0
- package/dist/cost-governor/cost-events.d.ts +65 -0
- package/dist/cost-governor/cost-events.d.ts.map +1 -0
- package/dist/cost-governor/cost-events.js +48 -0
- package/dist/cost-governor/cost-events.js.map +1 -0
- package/dist/cost-governor/cost-governor-app-id.test.d.ts +19 -0
- package/dist/cost-governor/cost-governor-app-id.test.d.ts.map +1 -0
- package/dist/cost-governor/cost-governor-app-id.test.js +201 -0
- package/dist/cost-governor/cost-governor-app-id.test.js.map +1 -0
- package/dist/cost-governor/cost-oracle-impl.d.ts +19 -0
- package/dist/cost-governor/cost-oracle-impl.d.ts.map +1 -0
- package/dist/cost-governor/cost-oracle-impl.js +52 -0
- package/dist/cost-governor/cost-oracle-impl.js.map +1 -0
- package/dist/cost-governor/estimator.d.ts +22 -0
- package/dist/cost-governor/estimator.d.ts.map +1 -0
- package/dist/cost-governor/estimator.js +119 -0
- package/dist/cost-governor/estimator.js.map +1 -0
- package/dist/cost-governor/estimator.test.d.ts +2 -0
- package/dist/cost-governor/estimator.test.d.ts.map +1 -0
- package/dist/cost-governor/estimator.test.js +141 -0
- package/dist/cost-governor/estimator.test.js.map +1 -0
- package/dist/cost-governor/index.d.ts +75 -0
- package/dist/cost-governor/index.d.ts.map +1 -0
- package/dist/cost-governor/index.js +120 -0
- package/dist/cost-governor/index.js.map +1 -0
- package/dist/cost-governor/observations-store.d.ts +49 -0
- package/dist/cost-governor/observations-store.d.ts.map +1 -0
- package/dist/cost-governor/observations-store.js +179 -0
- package/dist/cost-governor/observations-store.js.map +1 -0
- package/dist/cost-governor/observations-store.test.d.ts +2 -0
- package/dist/cost-governor/observations-store.test.d.ts.map +1 -0
- package/dist/cost-governor/observations-store.test.js +191 -0
- package/dist/cost-governor/observations-store.test.js.map +1 -0
- package/dist/cost-governor/percentile.d.ts +17 -0
- package/dist/cost-governor/percentile.d.ts.map +1 -0
- package/dist/cost-governor/percentile.js +33 -0
- package/dist/cost-governor/percentile.js.map +1 -0
- package/dist/cost-governor/percentile.test.d.ts +2 -0
- package/dist/cost-governor/percentile.test.d.ts.map +1 -0
- package/dist/cost-governor/percentile.test.js +46 -0
- package/dist/cost-governor/percentile.test.js.map +1 -0
- package/dist/cost-governor/rate-governor-impl.d.ts +73 -0
- package/dist/cost-governor/rate-governor-impl.d.ts.map +1 -0
- package/dist/cost-governor/rate-governor-impl.js +148 -0
- package/dist/cost-governor/rate-governor-impl.js.map +1 -0
- package/dist/cost-governor/signature-builder.d.ts +22 -0
- package/dist/cost-governor/signature-builder.d.ts.map +1 -0
- package/dist/cost-governor/signature-builder.js +43 -0
- package/dist/cost-governor/signature-builder.js.map +1 -0
- package/dist/cost-governor/signature-builder.test.d.ts +2 -0
- package/dist/cost-governor/signature-builder.test.d.ts.map +1 -0
- package/dist/cost-governor/signature-builder.test.js +58 -0
- package/dist/cost-governor/signature-builder.test.js.map +1 -0
- package/dist/cost-governor/token-bucket.d.ts +57 -0
- package/dist/cost-governor/token-bucket.d.ts.map +1 -0
- package/dist/cost-governor/token-bucket.js +109 -0
- package/dist/cost-governor/token-bucket.js.map +1 -0
- package/dist/cost-governor/token-bucket.test.d.ts +2 -0
- package/dist/cost-governor/token-bucket.test.d.ts.map +1 -0
- package/dist/cost-governor/token-bucket.test.js +67 -0
- package/dist/cost-governor/token-bucket.test.js.map +1 -0
- package/dist/dlq/cortex-dlq-observer.d.ts +22 -0
- package/dist/dlq/cortex-dlq-observer.d.ts.map +1 -0
- package/dist/dlq/cortex-dlq-observer.js +29 -0
- package/dist/dlq/cortex-dlq-observer.js.map +1 -0
- package/dist/dlq/dlq-observer.test.d.ts +8 -0
- package/dist/dlq/dlq-observer.test.d.ts.map +1 -0
- package/dist/dlq/dlq-observer.test.js +103 -0
- package/dist/dlq/dlq-observer.test.js.map +1 -0
- package/dist/dlq/index.d.ts +6 -0
- package/dist/dlq/index.d.ts.map +1 -0
- package/dist/dlq/index.js +6 -0
- package/dist/dlq/index.js.map +1 -0
- package/dist/event-bus/adapters.d.ts +50 -0
- package/dist/event-bus/adapters.d.ts.map +1 -0
- package/dist/event-bus/adapters.js +51 -0
- package/dist/event-bus/adapters.js.map +1 -0
- package/dist/event-bus/adapters.test.d.ts +5 -0
- package/dist/event-bus/adapters.test.d.ts.map +1 -0
- package/dist/event-bus/adapters.test.js +73 -0
- package/dist/event-bus/adapters.test.js.map +1 -0
- package/dist/event-bus/agent-event-adapter.d.ts +22 -0
- package/dist/event-bus/agent-event-adapter.d.ts.map +1 -0
- package/dist/event-bus/agent-event-adapter.js +49 -0
- package/dist/event-bus/agent-event-adapter.js.map +1 -0
- package/dist/event-bus/agent-event-adapter.test.d.ts +5 -0
- package/dist/event-bus/agent-event-adapter.test.d.ts.map +1 -0
- package/dist/event-bus/agent-event-adapter.test.js +170 -0
- package/dist/event-bus/agent-event-adapter.test.js.map +1 -0
- package/dist/event-bus/channel-sink.d.ts +71 -0
- package/dist/event-bus/channel-sink.d.ts.map +1 -0
- package/dist/event-bus/channel-sink.js +159 -0
- package/dist/event-bus/channel-sink.js.map +1 -0
- package/dist/event-bus/channel-sink.test.d.ts +5 -0
- package/dist/event-bus/channel-sink.test.d.ts.map +1 -0
- package/dist/event-bus/channel-sink.test.js +234 -0
- package/dist/event-bus/channel-sink.test.js.map +1 -0
- package/dist/event-bus/event-types.snapshot.test.d.ts +27 -0
- package/dist/event-bus/event-types.snapshot.test.d.ts.map +1 -0
- package/dist/event-bus/event-types.snapshot.test.js +165 -0
- package/dist/event-bus/event-types.snapshot.test.js.map +1 -0
- package/dist/event-bus/genesis-sink.d.ts +55 -0
- package/dist/event-bus/genesis-sink.d.ts.map +1 -0
- package/dist/event-bus/genesis-sink.js +141 -0
- package/dist/event-bus/genesis-sink.js.map +1 -0
- package/dist/event-bus/genesis-sink.test.d.ts +5 -0
- package/dist/event-bus/genesis-sink.test.d.ts.map +1 -0
- package/dist/event-bus/genesis-sink.test.js +160 -0
- package/dist/event-bus/genesis-sink.test.js.map +1 -0
- package/dist/event-bus/in-memory-event-bus.d.ts +60 -0
- package/dist/event-bus/in-memory-event-bus.d.ts.map +1 -0
- package/dist/event-bus/in-memory-event-bus.js +274 -0
- package/dist/event-bus/in-memory-event-bus.js.map +1 -0
- package/dist/event-bus/in-memory-event-bus.test.d.ts +5 -0
- package/dist/event-bus/in-memory-event-bus.test.d.ts.map +1 -0
- package/dist/event-bus/in-memory-event-bus.test.js +457 -0
- package/dist/event-bus/in-memory-event-bus.test.js.map +1 -0
- package/dist/event-bus/index.d.ts +22 -0
- package/dist/event-bus/index.d.ts.map +1 -0
- package/dist/event-bus/index.js +17 -0
- package/dist/event-bus/index.js.map +1 -0
- package/dist/event-bus/persistence-sink.d.ts +74 -0
- package/dist/event-bus/persistence-sink.d.ts.map +1 -0
- package/dist/event-bus/persistence-sink.js +193 -0
- package/dist/event-bus/persistence-sink.js.map +1 -0
- package/dist/event-bus/persistence-sink.test.d.ts +6 -0
- package/dist/event-bus/persistence-sink.test.d.ts.map +1 -0
- package/dist/event-bus/persistence-sink.test.js +319 -0
- package/dist/event-bus/persistence-sink.test.js.map +1 -0
- package/dist/event-bus/session-checkpoint-sink.d.ts +91 -0
- package/dist/event-bus/session-checkpoint-sink.d.ts.map +1 -0
- package/dist/event-bus/session-checkpoint-sink.js +107 -0
- package/dist/event-bus/session-checkpoint-sink.js.map +1 -0
- package/dist/event-bus/session-checkpoint-sink.test.d.ts +5 -0
- package/dist/event-bus/session-checkpoint-sink.test.d.ts.map +1 -0
- package/dist/event-bus/session-checkpoint-sink.test.js +215 -0
- package/dist/event-bus/session-checkpoint-sink.test.js.map +1 -0
- package/dist/event-bus/webhook-connector.d.ts +59 -0
- package/dist/event-bus/webhook-connector.d.ts.map +1 -0
- package/dist/event-bus/webhook-connector.js +191 -0
- package/dist/event-bus/webhook-connector.js.map +1 -0
- package/dist/event-bus/webhook-connector.test.d.ts +5 -0
- package/dist/event-bus/webhook-connector.test.d.ts.map +1 -0
- package/dist/event-bus/webhook-connector.test.js +214 -0
- package/dist/event-bus/webhook-connector.test.js.map +1 -0
- package/dist/executors/cortex-job-backed-executor.d.ts +137 -0
- package/dist/executors/cortex-job-backed-executor.d.ts.map +1 -0
- package/dist/executors/cortex-job-backed-executor.js +441 -0
- package/dist/executors/cortex-job-backed-executor.js.map +1 -0
- package/dist/executors/cortex-job-backed-executor.test.d.ts +13 -0
- package/dist/executors/cortex-job-backed-executor.test.d.ts.map +1 -0
- package/dist/executors/cortex-job-backed-executor.test.js +303 -0
- package/dist/executors/cortex-job-backed-executor.test.js.map +1 -0
- package/dist/executors/index.d.ts +9 -0
- package/dist/executors/index.d.ts.map +1 -0
- package/dist/executors/index.js +9 -0
- package/dist/executors/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/ports/checkpoint-sink.d.ts +69 -0
- package/dist/ports/checkpoint-sink.d.ts.map +1 -0
- package/dist/ports/checkpoint-sink.js +16 -0
- package/dist/ports/checkpoint-sink.js.map +1 -0
- package/dist/ports/checkpoint.d.ts +68 -0
- package/dist/ports/checkpoint.d.ts.map +1 -0
- package/dist/ports/checkpoint.js +14 -0
- package/dist/ports/checkpoint.js.map +1 -0
- package/dist/ports/continuation-envelope-cross-app.test.d.ts +10 -0
- package/dist/ports/continuation-envelope-cross-app.test.d.ts.map +1 -0
- package/dist/ports/continuation-envelope-cross-app.test.js +95 -0
- package/dist/ports/continuation-envelope-cross-app.test.js.map +1 -0
- package/dist/ports/continuation-envelope.d.ts +199 -0
- package/dist/ports/continuation-envelope.d.ts.map +1 -0
- package/dist/ports/continuation-envelope.js +69 -0
- package/dist/ports/continuation-envelope.js.map +1 -0
- package/dist/ports/conversation.d.ts +64 -0
- package/dist/ports/conversation.d.ts.map +1 -0
- package/dist/ports/conversation.js +19 -0
- package/dist/ports/conversation.js.map +1 -0
- package/dist/ports/cost-oracle.d.ts +26 -0
- package/dist/ports/cost-oracle.d.ts.map +1 -0
- package/dist/ports/cost-oracle.js +9 -0
- package/dist/ports/cost-oracle.js.map +1 -0
- package/dist/ports/cross-app-invoker.d.ts +198 -0
- package/dist/ports/cross-app-invoker.d.ts.map +1 -0
- package/dist/ports/cross-app-invoker.js +157 -0
- package/dist/ports/cross-app-invoker.js.map +1 -0
- package/dist/ports/dlq-observer.d.ts +40 -0
- package/dist/ports/dlq-observer.d.ts.map +1 -0
- package/dist/ports/dlq-observer.js +20 -0
- package/dist/ports/dlq-observer.js.map +1 -0
- package/dist/ports/event-bus.d.ts +169 -0
- package/dist/ports/event-bus.d.ts.map +1 -0
- package/dist/ports/event-bus.js +20 -0
- package/dist/ports/event-bus.js.map +1 -0
- package/dist/ports/event-reader.d.ts +21 -0
- package/dist/ports/event-reader.d.ts.map +1 -0
- package/dist/ports/event-reader.js +12 -0
- package/dist/ports/event-reader.js.map +1 -0
- package/dist/ports/event-rotator.d.ts +39 -0
- package/dist/ports/event-rotator.d.ts.map +1 -0
- package/dist/ports/event-rotator.js +15 -0
- package/dist/ports/event-rotator.js.map +1 -0
- package/dist/ports/file-system.d.ts +48 -0
- package/dist/ports/file-system.d.ts.map +1 -0
- package/dist/ports/file-system.js +10 -0
- package/dist/ports/file-system.js.map +1 -0
- package/dist/ports/historical-observations.d.ts +39 -0
- package/dist/ports/historical-observations.d.ts.map +1 -0
- package/dist/ports/historical-observations.js +12 -0
- package/dist/ports/historical-observations.js.map +1 -0
- package/dist/ports/in-memory-source.d.ts +46 -0
- package/dist/ports/in-memory-source.d.ts.map +1 -0
- package/dist/ports/in-memory-source.js +69 -0
- package/dist/ports/in-memory-source.js.map +1 -0
- package/dist/ports/index.d.ts +32 -0
- package/dist/ports/index.d.ts.map +1 -0
- package/dist/ports/index.js +10 -0
- package/dist/ports/index.js.map +1 -0
- package/dist/ports/job-backed-executor.d.ts +139 -0
- package/dist/ports/job-backed-executor.d.ts.map +1 -0
- package/dist/ports/job-backed-executor.js +56 -0
- package/dist/ports/job-backed-executor.js.map +1 -0
- package/dist/ports/methodology-source.d.ts +95 -0
- package/dist/ports/methodology-source.d.ts.map +1 -0
- package/dist/ports/methodology-source.js +26 -0
- package/dist/ports/methodology-source.js.map +1 -0
- package/dist/ports/native-session-discovery.d.ts +20 -0
- package/dist/ports/native-session-discovery.d.ts.map +1 -0
- package/dist/ports/native-session-discovery.js +13 -0
- package/dist/ports/native-session-discovery.js.map +1 -0
- package/dist/ports/projection-store.d.ts +48 -0
- package/dist/ports/projection-store.d.ts.map +1 -0
- package/dist/ports/projection-store.js +17 -0
- package/dist/ports/projection-store.js.map +1 -0
- package/dist/ports/projection.d.ts +29 -0
- package/dist/ports/projection.d.ts.map +1 -0
- package/dist/ports/projection.js +13 -0
- package/dist/ports/projection.js.map +1 -0
- package/dist/ports/rate-governor.d.ts +17 -0
- package/dist/ports/rate-governor.d.ts.map +1 -0
- package/dist/ports/rate-governor.js +11 -0
- package/dist/ports/rate-governor.js.map +1 -0
- package/dist/ports/schedule-client.d.ts +29 -0
- package/dist/ports/schedule-client.d.ts.map +1 -0
- package/dist/ports/schedule-client.js +2 -0
- package/dist/ports/schedule-client.js.map +1 -0
- package/dist/ports/session-pool.d.ts +162 -0
- package/dist/ports/session-pool.d.ts.map +1 -0
- package/dist/ports/session-pool.js +21 -0
- package/dist/ports/session-pool.js.map +1 -0
- package/dist/ports/session-store-errors.d.ts +22 -0
- package/dist/ports/session-store-errors.d.ts.map +1 -0
- package/dist/ports/session-store-errors.js +29 -0
- package/dist/ports/session-store-errors.js.map +1 -0
- package/dist/ports/session-store-types.d.ts +132 -0
- package/dist/ports/session-store-types.d.ts.map +1 -0
- package/dist/ports/session-store-types.js +14 -0
- package/dist/ports/session-store-types.js.map +1 -0
- package/dist/ports/session-store.d.ts +69 -0
- package/dist/ports/session-store.d.ts.map +1 -0
- package/dist/ports/session-store.js +23 -0
- package/dist/ports/session-store.js.map +1 -0
- package/dist/ports/yaml-loader.d.ts +15 -0
- package/dist/ports/yaml-loader.d.ts.map +1 -0
- package/dist/ports/yaml-loader.js +13 -0
- package/dist/ports/yaml-loader.js.map +1 -0
- package/dist/scheduling/index.d.ts +6 -0
- package/dist/scheduling/index.d.ts.map +1 -0
- package/dist/scheduling/index.js +6 -0
- package/dist/scheduling/index.js.map +1 -0
- package/dist/scheduling/scheduled-pact.d.ts +97 -0
- package/dist/scheduling/scheduled-pact.d.ts.map +1 -0
- package/dist/scheduling/scheduled-pact.js +89 -0
- package/dist/scheduling/scheduled-pact.js.map +1 -0
- package/dist/sessions/__tests__/cognitive-modules.test.d.ts +10 -0
- package/dist/sessions/__tests__/cognitive-modules.test.d.ts.map +1 -0
- package/dist/sessions/__tests__/cognitive-modules.test.js +535 -0
- package/dist/sessions/__tests__/cognitive-modules.test.js.map +1 -0
- package/dist/sessions/__tests__/cognitive-provider.test.d.ts +13 -0
- package/dist/sessions/__tests__/cognitive-provider.test.d.ts.map +1 -0
- package/dist/sessions/__tests__/cognitive-provider.test.js +331 -0
- package/dist/sessions/__tests__/cognitive-provider.test.js.map +1 -0
- package/dist/sessions/__tests__/cognitive-sink.test.d.ts +19 -0
- package/dist/sessions/__tests__/cognitive-sink.test.d.ts.map +1 -0
- package/dist/sessions/__tests__/cognitive-sink.test.js +334 -0
- package/dist/sessions/__tests__/cognitive-sink.test.js.map +1 -0
- package/dist/sessions/__tests__/runtime-tools.test.d.ts +2 -0
- package/dist/sessions/__tests__/runtime-tools.test.d.ts.map +1 -0
- package/dist/sessions/__tests__/runtime-tools.test.js +83 -0
- package/dist/sessions/__tests__/runtime-tools.test.js.map +1 -0
- package/dist/sessions/auto-retro.d.ts +29 -0
- package/dist/sessions/auto-retro.d.ts.map +1 -0
- package/dist/sessions/auto-retro.js +181 -0
- package/dist/sessions/auto-retro.js.map +1 -0
- package/dist/sessions/auto-retro.test.d.ts +2 -0
- package/dist/sessions/auto-retro.test.d.ts.map +1 -0
- package/dist/sessions/auto-retro.test.js +361 -0
- package/dist/sessions/auto-retro.test.js.map +1 -0
- package/dist/sessions/channels.d.ts +55 -0
- package/dist/sessions/channels.d.ts.map +1 -0
- package/dist/sessions/channels.js +118 -0
- package/dist/sessions/channels.js.map +1 -0
- package/dist/sessions/channels.test.d.ts +2 -0
- package/dist/sessions/channels.test.d.ts.map +1 -0
- package/dist/sessions/channels.test.js +285 -0
- package/dist/sessions/channels.test.js.map +1 -0
- package/dist/sessions/cognitive-modules.d.ts +100 -0
- package/dist/sessions/cognitive-modules.d.ts.map +1 -0
- package/dist/sessions/cognitive-modules.js +458 -0
- package/dist/sessions/cognitive-modules.js.map +1 -0
- package/dist/sessions/cognitive-provider.d.ts +42 -0
- package/dist/sessions/cognitive-provider.d.ts.map +1 -0
- package/dist/sessions/cognitive-provider.js +208 -0
- package/dist/sessions/cognitive-provider.js.map +1 -0
- package/dist/sessions/cognitive-sink.d.ts +73 -0
- package/dist/sessions/cognitive-sink.d.ts.map +1 -0
- package/dist/sessions/cognitive-sink.js +154 -0
- package/dist/sessions/cognitive-sink.js.map +1 -0
- package/dist/sessions/diagnostics.d.ts +70 -0
- package/dist/sessions/diagnostics.d.ts.map +1 -0
- package/dist/sessions/diagnostics.js +129 -0
- package/dist/sessions/diagnostics.js.map +1 -0
- package/dist/sessions/diagnostics.test.d.ts +2 -0
- package/dist/sessions/diagnostics.test.d.ts.map +1 -0
- package/dist/sessions/diagnostics.test.js +135 -0
- package/dist/sessions/diagnostics.test.js.map +1 -0
- package/dist/sessions/index.d.ts +32 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/sessions/index.js +33 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/pool.d.ts +218 -0
- package/dist/sessions/pool.d.ts.map +1 -0
- package/dist/sessions/pool.js +991 -0
- package/dist/sessions/pool.js.map +1 -0
- package/dist/sessions/pool.test.d.ts +2 -0
- package/dist/sessions/pool.test.d.ts.map +1 -0
- package/dist/sessions/pool.test.js +633 -0
- package/dist/sessions/pool.test.js.map +1 -0
- package/dist/sessions/print-session.d.ts +142 -0
- package/dist/sessions/print-session.d.ts.map +1 -0
- package/dist/sessions/print-session.js +325 -0
- package/dist/sessions/print-session.js.map +1 -0
- package/dist/sessions/print-session.test.d.ts +2 -0
- package/dist/sessions/print-session.test.d.ts.map +1 -0
- package/dist/sessions/print-session.test.js +418 -0
- package/dist/sessions/print-session.test.js.map +1 -0
- package/dist/sessions/runtime-tools.d.ts +22 -0
- package/dist/sessions/runtime-tools.d.ts.map +1 -0
- package/dist/sessions/runtime-tools.js +162 -0
- package/dist/sessions/runtime-tools.js.map +1 -0
- package/dist/sessions/scope-hook.d.ts +77 -0
- package/dist/sessions/scope-hook.d.ts.map +1 -0
- package/dist/sessions/scope-hook.js +323 -0
- package/dist/sessions/scope-hook.js.map +1 -0
- package/dist/sessions/scope-hook.test.d.ts +2 -0
- package/dist/sessions/scope-hook.test.d.ts.map +1 -0
- package/dist/sessions/scope-hook.test.js +249 -0
- package/dist/sessions/scope-hook.test.js.map +1 -0
- package/dist/sessions/session-store/checkpoint-sink-impl.d.ts +16 -0
- package/dist/sessions/session-store/checkpoint-sink-impl.d.ts.map +1 -0
- package/dist/sessions/session-store/checkpoint-sink-impl.js +191 -0
- package/dist/sessions/session-store/checkpoint-sink-impl.js.map +1 -0
- package/dist/sessions/session-store/checkpoint-sink-impl.test.d.ts +5 -0
- package/dist/sessions/session-store/checkpoint-sink-impl.test.d.ts.map +1 -0
- package/dist/sessions/session-store/checkpoint-sink-impl.test.js +137 -0
- package/dist/sessions/session-store/checkpoint-sink-impl.test.js.map +1 -0
- package/dist/sessions/session-store/conformance.d.ts +59 -0
- package/dist/sessions/session-store/conformance.d.ts.map +1 -0
- package/dist/sessions/session-store/conformance.js +172 -0
- package/dist/sessions/session-store/conformance.js.map +1 -0
- package/dist/sessions/session-store/conformance.test.d.ts +7 -0
- package/dist/sessions/session-store/conformance.test.d.ts.map +1 -0
- package/dist/sessions/session-store/conformance.test.js +22 -0
- package/dist/sessions/session-store/conformance.test.js.map +1 -0
- package/dist/sessions/session-store/in-memory-session-store.d.ts +23 -0
- package/dist/sessions/session-store/in-memory-session-store.d.ts.map +1 -0
- package/dist/sessions/session-store/in-memory-session-store.js +197 -0
- package/dist/sessions/session-store/in-memory-session-store.js.map +1 -0
- package/dist/sessions/session-store/in-memory-session-store.test.d.ts +6 -0
- package/dist/sessions/session-store/in-memory-session-store.test.d.ts.map +1 -0
- package/dist/sessions/session-store/in-memory-session-store.test.js +183 -0
- package/dist/sessions/session-store/in-memory-session-store.test.js.map +1 -0
- package/dist/sessions/session-store/index.d.ts +20 -0
- package/dist/sessions/session-store/index.d.ts.map +1 -0
- package/dist/sessions/session-store/index.js +15 -0
- package/dist/sessions/session-store/index.js.map +1 -0
- package/dist/sessions/session-store/resume.d.ts +88 -0
- package/dist/sessions/session-store/resume.d.ts.map +1 -0
- package/dist/sessions/session-store/resume.js +96 -0
- package/dist/sessions/session-store/resume.js.map +1 -0
- package/dist/sessions/session-store/resume.test.d.ts +5 -0
- package/dist/sessions/session-store/resume.test.d.ts.map +1 -0
- package/dist/sessions/session-store/resume.test.js +119 -0
- package/dist/sessions/session-store/resume.test.js.map +1 -0
- package/dist/sessions/spawn-queue.d.ts +28 -0
- package/dist/sessions/spawn-queue.d.ts.map +1 -0
- package/dist/sessions/spawn-queue.js +63 -0
- package/dist/sessions/spawn-queue.js.map +1 -0
- package/dist/sessions/spawn-queue.test.d.ts +2 -0
- package/dist/sessions/spawn-queue.test.d.ts.map +1 -0
- package/dist/sessions/spawn-queue.test.js +65 -0
- package/dist/sessions/spawn-queue.test.js.map +1 -0
- package/dist/sessions/types.d.ts +16 -0
- package/dist/sessions/types.d.ts.map +1 -0
- package/dist/sessions/types.js +11 -0
- package/dist/sessions/types.js.map +1 -0
- package/dist/sessions/worktree-stale.test.d.ts +2 -0
- package/dist/sessions/worktree-stale.test.d.ts.map +1 -0
- package/dist/sessions/worktree-stale.test.js +468 -0
- package/dist/sessions/worktree-stale.test.js.map +1 -0
- package/dist/strategy/artifact-store.d.ts +12 -0
- package/dist/strategy/artifact-store.d.ts.map +1 -0
- package/dist/strategy/artifact-store.js +12 -0
- package/dist/strategy/artifact-store.js.map +1 -0
- package/dist/strategy/artifact-store.test.d.ts +2 -0
- package/dist/strategy/artifact-store.test.d.ts.map +1 -0
- package/dist/strategy/artifact-store.test.js +170 -0
- package/dist/strategy/artifact-store.test.js.map +1 -0
- package/dist/strategy/context-load-executor.d.ts +23 -0
- package/dist/strategy/context-load-executor.d.ts.map +1 -0
- package/dist/strategy/context-load-executor.js +87 -0
- package/dist/strategy/context-load-executor.js.map +1 -0
- package/dist/strategy/context-load-executor.test.d.ts +16 -0
- package/dist/strategy/context-load-executor.test.d.ts.map +1 -0
- package/dist/strategy/context-load-executor.test.js +158 -0
- package/dist/strategy/context-load-executor.test.js.map +1 -0
- package/dist/strategy/cortex-cross-app-invoker.stub.d.ts +65 -0
- package/dist/strategy/cortex-cross-app-invoker.stub.d.ts.map +1 -0
- package/dist/strategy/cortex-cross-app-invoker.stub.js +68 -0
- package/dist/strategy/cortex-cross-app-invoker.stub.js.map +1 -0
- package/dist/strategy/cross-app-node-executor.d.ts +54 -0
- package/dist/strategy/cross-app-node-executor.d.ts.map +1 -0
- package/dist/strategy/cross-app-node-executor.js +98 -0
- package/dist/strategy/cross-app-node-executor.js.map +1 -0
- package/dist/strategy/cross-app-node-executor.test.d.ts +13 -0
- package/dist/strategy/cross-app-node-executor.test.d.ts.map +1 -0
- package/dist/strategy/cross-app-node-executor.test.js +160 -0
- package/dist/strategy/cross-app-node-executor.test.js.map +1 -0
- package/dist/strategy/gates.d.ts +13 -0
- package/dist/strategy/gates.d.ts.map +1 -0
- package/dist/strategy/gates.js +13 -0
- package/dist/strategy/gates.js.map +1 -0
- package/dist/strategy/gates.test.d.ts +2 -0
- package/dist/strategy/gates.test.d.ts.map +1 -0
- package/dist/strategy/gates.test.js +299 -0
- package/dist/strategy/gates.test.js.map +1 -0
- package/dist/strategy/human-approval-resolver.d.ts +23 -0
- package/dist/strategy/human-approval-resolver.d.ts.map +1 -0
- package/dist/strategy/human-approval-resolver.js +94 -0
- package/dist/strategy/human-approval-resolver.js.map +1 -0
- package/dist/strategy/human-approval-resolver.test.d.ts +16 -0
- package/dist/strategy/human-approval-resolver.test.d.ts.map +1 -0
- package/dist/strategy/human-approval-resolver.test.js +200 -0
- package/dist/strategy/human-approval-resolver.test.js.map +1 -0
- package/dist/strategy/in-process-cross-app-invoker.d.ts +105 -0
- package/dist/strategy/in-process-cross-app-invoker.d.ts.map +1 -0
- package/dist/strategy/in-process-cross-app-invoker.js +206 -0
- package/dist/strategy/in-process-cross-app-invoker.js.map +1 -0
- package/dist/strategy/in-process-cross-app-invoker.test.d.ts +15 -0
- package/dist/strategy/in-process-cross-app-invoker.test.d.ts.map +1 -0
- package/dist/strategy/in-process-cross-app-invoker.test.js +190 -0
- package/dist/strategy/in-process-cross-app-invoker.test.js.map +1 -0
- package/dist/strategy/index.d.ts +29 -0
- package/dist/strategy/index.d.ts.map +1 -0
- package/dist/strategy/index.js +29 -0
- package/dist/strategy/index.js.map +1 -0
- package/dist/strategy/pacta-strategy.d.ts +97 -0
- package/dist/strategy/pacta-strategy.d.ts.map +1 -0
- package/dist/strategy/pacta-strategy.js +117 -0
- package/dist/strategy/pacta-strategy.js.map +1 -0
- package/dist/strategy/pacta-strategy.test.d.ts +2 -0
- package/dist/strategy/pacta-strategy.test.d.ts.map +1 -0
- package/dist/strategy/pacta-strategy.test.js +234 -0
- package/dist/strategy/pacta-strategy.test.js.map +1 -0
- package/dist/strategy/retro-generator.d.ts +18 -0
- package/dist/strategy/retro-generator.d.ts.map +1 -0
- package/dist/strategy/retro-generator.js +22 -0
- package/dist/strategy/retro-generator.js.map +1 -0
- package/dist/strategy/retro-writer.d.ts +25 -0
- package/dist/strategy/retro-writer.d.ts.map +1 -0
- package/dist/strategy/retro-writer.js +65 -0
- package/dist/strategy/retro-writer.js.map +1 -0
- package/dist/strategy/strategy-executor.d.ts +39 -0
- package/dist/strategy/strategy-executor.d.ts.map +1 -0
- package/dist/strategy/strategy-executor.js +253 -0
- package/dist/strategy/strategy-executor.js.map +1 -0
- package/dist/strategy/strategy-executor.test.d.ts +8 -0
- package/dist/strategy/strategy-executor.test.d.ts.map +1 -0
- package/dist/strategy/strategy-executor.test.js +1301 -0
- package/dist/strategy/strategy-executor.test.js.map +1 -0
- package/dist/strategy/strategy-parser.d.ts +30 -0
- package/dist/strategy/strategy-parser.d.ts.map +1 -0
- package/dist/strategy/strategy-parser.js +30 -0
- package/dist/strategy/strategy-parser.js.map +1 -0
- package/dist/strategy/sub-strategy-source.d.ts +27 -0
- package/dist/strategy/sub-strategy-source.d.ts.map +1 -0
- package/dist/strategy/sub-strategy-source.js +77 -0
- package/dist/strategy/sub-strategy-source.js.map +1 -0
- package/dist/strategy/types.d.ts +12 -0
- package/dist/strategy/types.d.ts.map +1 -0
- package/dist/strategy/types.js +9 -0
- package/dist/strategy/types.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { BackpressureQueue } from './backpressure-queue.js';
|
|
5
|
+
test('enqueue + dequeue resolves in FIFO order', async () => {
|
|
6
|
+
const queue = new BackpressureQueue();
|
|
7
|
+
const order = [];
|
|
8
|
+
const p1 = queue.enqueue(5000).then(() => order.push(1));
|
|
9
|
+
const p2 = queue.enqueue(5000).then(() => order.push(2));
|
|
10
|
+
assert.equal(queue.size, 2);
|
|
11
|
+
queue.dequeue();
|
|
12
|
+
await p1;
|
|
13
|
+
queue.dequeue();
|
|
14
|
+
await p2;
|
|
15
|
+
assert.deepEqual(order, [1, 2]);
|
|
16
|
+
});
|
|
17
|
+
test('dequeue returns false when empty', () => {
|
|
18
|
+
const queue = new BackpressureQueue();
|
|
19
|
+
assert.equal(queue.dequeue(), false);
|
|
20
|
+
});
|
|
21
|
+
test('timeout rejects after timeoutMs', async () => {
|
|
22
|
+
const queue = new BackpressureQueue();
|
|
23
|
+
await assert.rejects(queue.enqueue(10), (err) => err.message.includes('exceeded'));
|
|
24
|
+
});
|
|
25
|
+
test('abort signal rejects', async () => {
|
|
26
|
+
const queue = new BackpressureQueue();
|
|
27
|
+
const ac = new AbortController();
|
|
28
|
+
const p = queue.enqueue(5000, ac.signal);
|
|
29
|
+
ac.abort();
|
|
30
|
+
await assert.rejects(p, (err) => err.message.includes('Aborted'));
|
|
31
|
+
assert.equal(queue.size, 0);
|
|
32
|
+
});
|
|
33
|
+
test('already-aborted signal rejects synchronously', async () => {
|
|
34
|
+
const queue = new BackpressureQueue();
|
|
35
|
+
const ac = new AbortController();
|
|
36
|
+
ac.abort();
|
|
37
|
+
await assert.rejects(queue.enqueue(5000, ac.signal), (err) => err.message.includes('Aborted'));
|
|
38
|
+
});
|
|
39
|
+
test('clear rejects all entries', async () => {
|
|
40
|
+
const queue = new BackpressureQueue();
|
|
41
|
+
const p1 = queue.enqueue(5000);
|
|
42
|
+
const p2 = queue.enqueue(5000);
|
|
43
|
+
queue.clear();
|
|
44
|
+
await assert.rejects(p1);
|
|
45
|
+
await assert.rejects(p2);
|
|
46
|
+
assert.equal(queue.size, 0);
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=backpressure-queue.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backpressure-queue.test.js","sourceRoot":"","sources":["../../src/cost-governor/backpressure-queue.test.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,IAAI,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;IAC1D,MAAM,KAAK,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACtC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,C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AG,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACzE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAC9B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;IAC9D,MAAM,KAAK,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACtC,MAAM,EAAE,GAAG,IAAI,eAAe,EAAE,CAAC;IACjC,EAAE,CAAC,KAAK,EAAE,CAAC;IACX,MAAM,MAAM,CAAC,OAAO,CAClB,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,EAC9B,CAAC,GAAU,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAChD,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;IAC3C,MAAM,KAAK,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACtC,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACzB,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACzB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAC9B,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost telemetry event types + emit helpers.
|
|
3
|
+
*
|
|
4
|
+
* All cost events carry domain='cost' on the Universal Event Bus.
|
|
5
|
+
* The accountId field is included for forward-compatibility with
|
|
6
|
+
* multi-account routing — currently always 'default'.
|
|
7
|
+
*
|
|
8
|
+
* PRD-057 / S2 §8: Each emitter accepts an optional `appId` field. When
|
|
9
|
+
* present (agent-runtime / Cortex case), the emitted RuntimeEvent carries
|
|
10
|
+
* `payload.appId`. When absent (bridge case), behavior is bit-identical
|
|
11
|
+
* to pre-PRD-057.
|
|
12
|
+
*/
|
|
13
|
+
import type { EventBus } from '../ports/event-bus.js';
|
|
14
|
+
import type { InvocationSignature, AccountId, ProviderClass } from '@methodts/types';
|
|
15
|
+
import type { AppId } from './rate-governor-impl.js';
|
|
16
|
+
export type CostEventType = 'cost.observation_recorded' | 'cost.rate_limited' | 'cost.estimate_emitted' | 'cost.prediction_diverged' | 'cost.slot_leaked' | 'cost.integrity_violation' | 'cost.observations_corrupted' | 'cost.clock_discontinuity' | 'cost.account_saturated' | 'cost.observation_parse_error';
|
|
17
|
+
export declare function emitObservationRecorded(bus: EventBus, payload: {
|
|
18
|
+
signature: InvocationSignature;
|
|
19
|
+
costUsd: number;
|
|
20
|
+
durationMs: number;
|
|
21
|
+
accountId: AccountId;
|
|
22
|
+
appId?: AppId;
|
|
23
|
+
correlationId?: string;
|
|
24
|
+
}): void;
|
|
25
|
+
export declare function emitRateLimited(bus: EventBus, payload: {
|
|
26
|
+
accountId: AccountId;
|
|
27
|
+
providerClass: ProviderClass;
|
|
28
|
+
appId?: AppId;
|
|
29
|
+
retryAfterMs?: number;
|
|
30
|
+
correlationId?: string;
|
|
31
|
+
}): void;
|
|
32
|
+
export declare function emitEstimateEmitted(bus: EventBus, payload: {
|
|
33
|
+
strategyId: string;
|
|
34
|
+
totalCostP50Usd: number;
|
|
35
|
+
totalCostP90Usd: number;
|
|
36
|
+
durationMsP50: number;
|
|
37
|
+
confidence: 'low' | 'medium' | 'high';
|
|
38
|
+
appId?: AppId;
|
|
39
|
+
correlationId?: string;
|
|
40
|
+
}): void;
|
|
41
|
+
export declare function emitSlotLeaked(bus: EventBus, payload: {
|
|
42
|
+
slotId: string;
|
|
43
|
+
accountId: AccountId;
|
|
44
|
+
ageMs: number;
|
|
45
|
+
appId?: AppId;
|
|
46
|
+
}): void;
|
|
47
|
+
export declare function emitAccountSaturated(bus: EventBus, payload: {
|
|
48
|
+
accountId: AccountId;
|
|
49
|
+
providerClass: ProviderClass;
|
|
50
|
+
window: 'burst' | 'weekly';
|
|
51
|
+
usedPct: number;
|
|
52
|
+
appId?: AppId;
|
|
53
|
+
}): void;
|
|
54
|
+
export declare function emitIntegrityViolation(bus: EventBus, payload: {
|
|
55
|
+
lineNumber: number;
|
|
56
|
+
reason: string;
|
|
57
|
+
appId?: AppId;
|
|
58
|
+
}): void;
|
|
59
|
+
export declare function emitObservationsCorrupted(bus: EventBus, payload: {
|
|
60
|
+
renamedTo: string;
|
|
61
|
+
recordsLoaded: number;
|
|
62
|
+
recordsSkipped: number;
|
|
63
|
+
appId?: AppId;
|
|
64
|
+
}): void;
|
|
65
|
+
//# sourceMappingURL=cost-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-events.d.ts","sourceRoot":"","sources":["../../src/cost-governor/cost-events.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,uBAAuB,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAIrD,MAAM,MAAM,aAAa,GACrB,2BAA2B,GAC3B,mBAAmB,GACnB,uBAAuB,GACvB,0BAA0B,GAC1B,kBAAkB,GAClB,0BAA0B,GAC1B,6BAA6B,GAC7B,0BAA0B,GAC1B,wBAAwB,GACxB,8BAA8B,CAAC;AAEnC,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,QAAQ,EACb,OAAO,EAAE;IACP,SAAS,EAAE,mBAAmB,CAAC;IAC/B,OAAO,EAAE,MAAM,CA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B,CACpC,GAAG,EAAE,QAAQ,EACb,OAAO,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAC7D,IAAI,CAEN;AAED,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,QAAQ,EACb,OAAO,EAAE;IACP,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GACA,IAAI,CAEN"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Cost telemetry event types + emit helpers.
|
|
4
|
+
*
|
|
5
|
+
* All cost events carry domain='cost' on the Universal Event Bus.
|
|
6
|
+
* The accountId field is included for forward-compatibility with
|
|
7
|
+
* multi-account routing — currently always 'default'.
|
|
8
|
+
*
|
|
9
|
+
* PRD-057 / S2 §8: Each emitter accepts an optional `appId` field. When
|
|
10
|
+
* present (agent-runtime / Cortex case), the emitted RuntimeEvent carries
|
|
11
|
+
* `payload.appId`. When absent (bridge case), behavior is bit-identical
|
|
12
|
+
* to pre-PRD-057.
|
|
13
|
+
*/
|
|
14
|
+
const SOURCE = 'runtime/cost-governor';
|
|
15
|
+
export function emitObservationRecorded(bus, payload) {
|
|
16
|
+
emit(bus, 'cost.observation_recorded', 'info', payload, payload.correlationId);
|
|
17
|
+
}
|
|
18
|
+
export function emitRateLimited(bus, payload) {
|
|
19
|
+
emit(bus, 'cost.rate_limited', 'warning', payload, payload.correlationId);
|
|
20
|
+
}
|
|
21
|
+
export function emitEstimateEmitted(bus, payload) {
|
|
22
|
+
emit(bus, 'cost.estimate_emitted', 'info', payload, payload.correlationId);
|
|
23
|
+
}
|
|
24
|
+
export function emitSlotLeaked(bus, payload) {
|
|
25
|
+
emit(bus, 'cost.slot_leaked', 'error', payload);
|
|
26
|
+
}
|
|
27
|
+
export function emitAccountSaturated(bus, payload) {
|
|
28
|
+
emit(bus, 'cost.account_saturated', 'warning', payload);
|
|
29
|
+
}
|
|
30
|
+
export function emitIntegrityViolation(bus, payload) {
|
|
31
|
+
emit(bus, 'cost.integrity_violation', 'error', payload);
|
|
32
|
+
}
|
|
33
|
+
export function emitObservationsCorrupted(bus, payload) {
|
|
34
|
+
emit(bus, 'cost.observations_corrupted', 'error', payload);
|
|
35
|
+
}
|
|
36
|
+
// ── Internal emit helper ────────────────────────────────────────
|
|
37
|
+
function emit(bus, type, severity, payload, correlationId) {
|
|
38
|
+
bus.emit({
|
|
39
|
+
version: 1,
|
|
40
|
+
domain: 'cost',
|
|
41
|
+
type,
|
|
42
|
+
severity,
|
|
43
|
+
payload,
|
|
44
|
+
source: SOURCE,
|
|
45
|
+
correlationId,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=cost-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-events.js","sourceRoot":"","sources":["../../src/cost-governor/cost-events.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC;;;;;;;;;;;GAWG;AAMH,MAAM,MAAM,GAAG,uBAAuB,CAAC;AAcvC,MAAM,UAAU,uBAAuB,CACrC,GAAa,EACb,OAOC;IAED,IAAI,CAAC,GAAG,EAAE,2BAA2B,EAAE,MAAM,EAAE,OAAkC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;AAC5G,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,GAAa,EACb,OAMC;IAED,IAAI,CAAC,GAAG,EAAE,mBAAmB,EAAE,SAAS,EAAE,OAAkC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;AACvG,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,GAAa,EACb,OAQC;IAED,IAAI,CAAC,GAAG,EAAE,uBAAuB,EAAE,MAAM,EAAE,OAAkC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;AACxG,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,GAAa,EACb,OAA+E;IAE/E,IAAI,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAkC,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,GAAa,EACb,OAMC;IAED,IAAI,CAAC,GAAG,EAAE,wBAAwB,EAAE,SAAS,EAAE,OAAkC,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,GAAa,EACb,OAA8D;IAE9D,IAAI,CAAC,GAAG,EAAE,0BAA0B,EAAE,OAAO,EAAE,OAAkC,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,GAAa,EACb,OAKC;IAED,IAAI,CAAC,GAAG,EAAE,6BAA6B,EAAE,OAAO,EAAE,OAAkC,CAAC,CAAC;AACxF,CAAC;AAED,mEAAmE;AAEnE,SAAS,IAAI,CACX,GAAa,EACb,IAAmB,EACnB,QAAuC,EACvC,OAAgC,EAChC,aAAsB;IAEtB,GAAG,CAAC,IAAI,CAAC;QACP,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,MAAM;QACd,IAAI;QACJ,QAAQ;QACR,OAAO;QACP,MAAM,EAAE,MAAM;QACd,aAAa;KACd,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PRD-057 / S2 §8 / G-COSTGOV-APP-ID gate test.
|
|
3
|
+
*
|
|
4
|
+
* Verifies that:
|
|
5
|
+
*
|
|
6
|
+
* 1. `createCostGovernor` accepts an optional `appId` option.
|
|
7
|
+
* 2. Emitted `cost.*` events carry `payload.appId` when set, and
|
|
8
|
+
* omit it when not set.
|
|
9
|
+
* 3. `rateGovernor.utilization()` supports the scope-filter form
|
|
10
|
+
* `utilization(providerClass, appId)`.
|
|
11
|
+
* 4. The `appId`-absent path behaves bit-identically to before:
|
|
12
|
+
* no surprise payload keys, no slot-routing changes.
|
|
13
|
+
*
|
|
14
|
+
* These are *additive* assertions — they do NOT replace or mutate the
|
|
15
|
+
* existing observations-store.test.ts / rate-governor-impl.test.ts
|
|
16
|
+
* coverage (which is intentionally unchanged per PRD §9.4).
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=cost-governor-app-id.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-governor-app-id.test.d.ts","sourceRoot":"","sources":["../../src/cost-governor/cost-governor-app-id.test.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* PRD-057 / S2 §8 / G-COSTGOV-APP-ID gate test.
|
|
4
|
+
*
|
|
5
|
+
* Verifies that:
|
|
6
|
+
*
|
|
7
|
+
* 1. `createCostGovernor` accepts an optional `appId` option.
|
|
8
|
+
* 2. Emitted `cost.*` events carry `payload.appId` when set, and
|
|
9
|
+
* omit it when not set.
|
|
10
|
+
* 3. `rateGovernor.utilization()` supports the scope-filter form
|
|
11
|
+
* `utilization(providerClass, appId)`.
|
|
12
|
+
* 4. The `appId`-absent path behaves bit-identically to before:
|
|
13
|
+
* no surprise payload keys, no slot-routing changes.
|
|
14
|
+
*
|
|
15
|
+
* These are *additive* assertions — they do NOT replace or mutate the
|
|
16
|
+
* existing observations-store.test.ts / rate-governor-impl.test.ts
|
|
17
|
+
* coverage (which is intentionally unchanged per PRD §9.4).
|
|
18
|
+
*/
|
|
19
|
+
import { describe, it } from 'node:test';
|
|
20
|
+
import assert from 'node:assert/strict';
|
|
21
|
+
import { createCostGovernor } from './index.js';
|
|
22
|
+
// ── In-memory event bus that records emitted events ─────────────
|
|
23
|
+
function createRecordingBus() {
|
|
24
|
+
const events = [];
|
|
25
|
+
let seq = 0;
|
|
26
|
+
const sinks = [];
|
|
27
|
+
const bus = {
|
|
28
|
+
emit(input) {
|
|
29
|
+
const event = {
|
|
30
|
+
...input,
|
|
31
|
+
id: `ev-${++seq}`,
|
|
32
|
+
timestamp: new Date().toISOString(),
|
|
33
|
+
sequence: seq,
|
|
34
|
+
};
|
|
35
|
+
events.push(event);
|
|
36
|
+
for (const sink of sinks)
|
|
37
|
+
sink.onEvent(event);
|
|
38
|
+
return event;
|
|
39
|
+
},
|
|
40
|
+
importEvent(event) {
|
|
41
|
+
events.push(event);
|
|
42
|
+
},
|
|
43
|
+
subscribe() {
|
|
44
|
+
return { unsubscribe() { } };
|
|
45
|
+
},
|
|
46
|
+
query() {
|
|
47
|
+
return [...events];
|
|
48
|
+
},
|
|
49
|
+
registerSink(sink) {
|
|
50
|
+
sinks.push(sink);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
return { bus, events };
|
|
54
|
+
}
|
|
55
|
+
// ── Minimal in-memory FileSystemProvider (matches MemFs in other tests) ──
|
|
56
|
+
class MemFs {
|
|
57
|
+
files = new Map();
|
|
58
|
+
dirs = new Set();
|
|
59
|
+
readFileSync(path) {
|
|
60
|
+
const content = this.files.get(path);
|
|
61
|
+
if (content === undefined)
|
|
62
|
+
throw new Error(`ENOENT: ${path}`);
|
|
63
|
+
return content;
|
|
64
|
+
}
|
|
65
|
+
writeFileSync(path, content) {
|
|
66
|
+
this.files.set(path, content);
|
|
67
|
+
}
|
|
68
|
+
existsSync(path) {
|
|
69
|
+
return this.files.has(path) || this.dirs.has(path);
|
|
70
|
+
}
|
|
71
|
+
readdirSync(_path, options) {
|
|
72
|
+
return options?.withFileTypes ? [] : [];
|
|
73
|
+
}
|
|
74
|
+
statSync(_path) {
|
|
75
|
+
throw new Error('not implemented');
|
|
76
|
+
}
|
|
77
|
+
unlinkSync(path) {
|
|
78
|
+
this.files.delete(path);
|
|
79
|
+
}
|
|
80
|
+
mkdirSync(path) {
|
|
81
|
+
this.dirs.add(path);
|
|
82
|
+
}
|
|
83
|
+
renameSync(oldPath, newPath) {
|
|
84
|
+
const content = this.files.get(oldPath);
|
|
85
|
+
if (content !== undefined) {
|
|
86
|
+
this.files.set(newPath, content);
|
|
87
|
+
this.files.delete(oldPath);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
realpathSync(path) { return path; }
|
|
91
|
+
async readFile(path) { return this.readFileSync(path); }
|
|
92
|
+
async writeFile(path, content) { this.writeFileSync(path, content); }
|
|
93
|
+
async appendFile(path, content) {
|
|
94
|
+
const existing = this.files.get(path) ?? '';
|
|
95
|
+
this.files.set(path, existing + content);
|
|
96
|
+
}
|
|
97
|
+
async readdir(_path) { return []; }
|
|
98
|
+
async stat(_path) { throw new Error('not implemented'); }
|
|
99
|
+
async access(_path) { }
|
|
100
|
+
async mkdir(path) { this.dirs.add(path); }
|
|
101
|
+
}
|
|
102
|
+
// ── Tests ───────────────────────────────────────────────────────
|
|
103
|
+
describe('createCostGovernor — per-AppId hook (PRD-057 / S2 §8)', () => {
|
|
104
|
+
it('no appId: governor exposes appId=undefined and emits events without payload.appId', () => {
|
|
105
|
+
const { bus } = createRecordingBus();
|
|
106
|
+
const fs = new MemFs();
|
|
107
|
+
const governor = createCostGovernor({
|
|
108
|
+
eventBus: bus,
|
|
109
|
+
fileSystem: fs,
|
|
110
|
+
config: { dataDir: '/data', hmacSecret: 'test' },
|
|
111
|
+
});
|
|
112
|
+
assert.equal(governor.appId, undefined);
|
|
113
|
+
assert.equal(governor.rateGovernor.getAppId(), undefined);
|
|
114
|
+
assert.equal(governor.sweepLeakedSlots(), 0);
|
|
115
|
+
// Utilization without filter — single entry.
|
|
116
|
+
const util = governor.rateGovernor.utilization('claude-cli');
|
|
117
|
+
assert.equal(util.length, 1);
|
|
118
|
+
// Utilization with filter: any appId filter on a no-scope governor
|
|
119
|
+
// returns empty (scope miss).
|
|
120
|
+
const filtered = governor.rateGovernor.utilization('claude-cli', 'app-x');
|
|
121
|
+
assert.equal(filtered.length, 0);
|
|
122
|
+
});
|
|
123
|
+
it('with appId: governor exposes appId and scoped utilization matches', () => {
|
|
124
|
+
const { bus } = createRecordingBus();
|
|
125
|
+
const fs = new MemFs();
|
|
126
|
+
const appId = 'tenant-42';
|
|
127
|
+
const governor = createCostGovernor({
|
|
128
|
+
eventBus: bus,
|
|
129
|
+
fileSystem: fs,
|
|
130
|
+
config: { dataDir: '/data', hmacSecret: 'test' },
|
|
131
|
+
appId,
|
|
132
|
+
});
|
|
133
|
+
assert.equal(governor.appId, appId);
|
|
134
|
+
assert.equal(governor.rateGovernor.getAppId(), appId);
|
|
135
|
+
// Matching filter — returns the account row.
|
|
136
|
+
const matching = governor.rateGovernor.utilization('claude-cli', appId);
|
|
137
|
+
assert.equal(matching.length, 1);
|
|
138
|
+
// Non-matching filter — empty.
|
|
139
|
+
const nonMatching = governor.rateGovernor.utilization('claude-cli', 'other-tenant');
|
|
140
|
+
assert.equal(nonMatching.length, 0);
|
|
141
|
+
// Unfiltered — still returns the account row.
|
|
142
|
+
const unfiltered = governor.rateGovernor.utilization('claude-cli');
|
|
143
|
+
assert.equal(unfiltered.length, 1);
|
|
144
|
+
});
|
|
145
|
+
it('with appId: sweepLeakedSlots emits cost.slot_leaked with payload.appId', () => {
|
|
146
|
+
const { bus, events } = createRecordingBus();
|
|
147
|
+
const fs = new MemFs();
|
|
148
|
+
const appId = 'tenant-77';
|
|
149
|
+
const governor = createCostGovernor({
|
|
150
|
+
eventBus: bus,
|
|
151
|
+
fileSystem: fs,
|
|
152
|
+
config: { dataDir: '/data', hmacSecret: 'test' },
|
|
153
|
+
appId,
|
|
154
|
+
});
|
|
155
|
+
// Manually inject a stale slot so sweep has something to emit.
|
|
156
|
+
// We bypass the normal acquire path to avoid needing a full signature
|
|
157
|
+
// fixture — the assertion target is the emitted payload.
|
|
158
|
+
const rg = governor.rateGovernor;
|
|
159
|
+
rg.active.set('stale', {
|
|
160
|
+
slot: {
|
|
161
|
+
slotId: 'stale',
|
|
162
|
+
providerClass: 'claude-cli',
|
|
163
|
+
accountId: 'default',
|
|
164
|
+
acquiredAt: Date.now() - 120_000,
|
|
165
|
+
estimatedCostUsd: 0,
|
|
166
|
+
maxLifetimeMs: 60_000,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
const leaked = governor.sweepLeakedSlots();
|
|
170
|
+
assert.equal(leaked, 1);
|
|
171
|
+
const slotLeakedEvents = events.filter(e => e.type === 'cost.slot_leaked');
|
|
172
|
+
assert.equal(slotLeakedEvents.length, 1);
|
|
173
|
+
assert.equal(slotLeakedEvents[0].payload.appId, appId);
|
|
174
|
+
assert.equal(slotLeakedEvents[0].source, 'runtime/cost-governor');
|
|
175
|
+
});
|
|
176
|
+
it('no appId: cost.slot_leaked events omit payload.appId', () => {
|
|
177
|
+
const { bus, events } = createRecordingBus();
|
|
178
|
+
const fs = new MemFs();
|
|
179
|
+
const governor = createCostGovernor({
|
|
180
|
+
eventBus: bus,
|
|
181
|
+
fileSystem: fs,
|
|
182
|
+
config: { dataDir: '/data', hmacSecret: 'test' },
|
|
183
|
+
});
|
|
184
|
+
const rg = governor.rateGovernor;
|
|
185
|
+
rg.active.set('stale', {
|
|
186
|
+
slot: {
|
|
187
|
+
slotId: 'stale',
|
|
188
|
+
providerClass: 'claude-cli',
|
|
189
|
+
accountId: 'default',
|
|
190
|
+
acquiredAt: Date.now() - 120_000,
|
|
191
|
+
estimatedCostUsd: 0,
|
|
192
|
+
maxLifetimeMs: 60_000,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
governor.sweepLeakedSlots();
|
|
196
|
+
const slotLeakedEvents = events.filter(e => e.type === 'cost.slot_leaked');
|
|
197
|
+
assert.equal(slotLeakedEvents.length, 1);
|
|
198
|
+
assert.ok(!('appId' in slotLeakedEvents[0].payload), 'no-appId governor must not emit payload.appId');
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
//# sourceMappingURL=cost-governor-app-id.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-governor-app-id.test.js","sourceRoot":"","sources":["../../src/cost-governor/cost-governor-app-id.test.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAGxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGhD,mEAAmE;AAEnE,SAAS,kBAAkB;IACzB,MAAM,MAAM,GAAmB,EAAE,CAAC;IAClC,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,MAAM,KAAK,GAAgB,EAAE,CAAC;IAC9B,MAAM,GAAG,GAAa;QACpB,IAAI,CAAC,KAAwB;YAC3B,MAAM,KAAK,GAAiB;gBAC1B,GAAG,KAAK;gBACR,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE;gBACjB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACnC,QAAQ,EAAE,GAAG;aACd,CAAC;YACF,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC9C,OAAO,KAAK,CAAC;QACf,CAAC;QACD,WAAW,CAAC,KAAmB;YAC7B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QACD,SAAS;YACP,OAAO,EAAE,WAAW,KAAI,CAAC,EAAE,CAAC;QAC9B,CAAC;QACD,KAAK;YACH,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC;QACrB,CAAC;QACD,YAAY,CAAC,IAAe;YAC1B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;KACF,CAAC;IACF,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACzB,CAAC;AAED,4EAA4E;AA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;gBACpB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;gBAChC,gBAAgB,EAAE,CAAC;gBACnB,aAAa,EAAE,MAAM;aACtB;SACF,CAAC,CAAC;QAEH,QAAQ,CAAC,gBAAgB,EAAE,CAAC;QAE5B,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC;QAC3E,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACzC,MAAM,CAAC,EAAE,CACP,CAAC,CAAC,OAAO,IAAK,gBAAgB,CAAC,CAAC,CAAC,CAAC,OAAmC,CAAC,EACtE,+CAA+C,CAChD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CostOracle implementation backed by HistoricalObservations.
|
|
3
|
+
*
|
|
4
|
+
* Computes p50/p90 bands per-signature from observation history.
|
|
5
|
+
* Delegates DAG walking to estimator.ts.
|
|
6
|
+
*/
|
|
7
|
+
import type { InvocationSignature } from '@methodts/types';
|
|
8
|
+
import type { CostOracle, StrategyEstimate } from '../ports/cost-oracle.js';
|
|
9
|
+
import type { HistoricalObservations } from '../ports/historical-observations.js';
|
|
10
|
+
export declare class HistogramCostOracle implements CostOracle {
|
|
11
|
+
private readonly history;
|
|
12
|
+
private readonly onRecord?;
|
|
13
|
+
constructor(history: HistoricalObservations, onRecord?: ((sig: InvocationSignature, costUsd: number, durationMs: number, accountId: string) => void) | undefined);
|
|
14
|
+
estimateStrategy(nodeSignatures: ReadonlyMap<string, InvocationSignature>, dagEdges: ReadonlyMap<string, readonly string[]>): StrategyEstimate;
|
|
15
|
+
/** Internal: look up p50/p90 for a single signature. */
|
|
16
|
+
private estimateSignature;
|
|
17
|
+
record(sig: InvocationSignature, actualCostUsd: number, actualDurationMs: number, accountId: string): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=cost-oracle-impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-oracle-impl.d.ts","sourceRoot":"","sources":["../../src/cost-governor/cost-oracle-impl.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAY,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAIlF,qBAAa,mBAAoB,YAAW,UAAU;IAElD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBADT,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,CAAC,GAAE,CAC1B,GAAG,EAAE,mBAAmB,EACxB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,KACd,IAAI,aAAA;IAGX,gBAAgB,CACd,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACxD,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,GAC/C,gBAAgB;IAMnB,wDAAwD;IACxD,OAAO,CAAC,iBAAiB;IA+BzB,MAAM,CACJ,GAAG,EAAE,mBAAmB,EACxB,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,MAAM,EACxB,SAAS,EAAE,MAAM,GAChB,IAAI;CAMR"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* CostOracle implementation backed by HistoricalObservations.
|
|
4
|
+
*
|
|
5
|
+
* Computes p50/p90 bands per-signature from observation history.
|
|
6
|
+
* Delegates DAG walking to estimator.ts.
|
|
7
|
+
*/
|
|
8
|
+
import { computeBands } from './percentile.js';
|
|
9
|
+
import { estimateStrategy as walkDag } from './estimator.js';
|
|
10
|
+
export class HistogramCostOracle {
|
|
11
|
+
history;
|
|
12
|
+
onRecord;
|
|
13
|
+
constructor(history, onRecord) {
|
|
14
|
+
this.history = history;
|
|
15
|
+
this.onRecord = onRecord;
|
|
16
|
+
}
|
|
17
|
+
estimateStrategy(nodeSignatures, dagEdges) {
|
|
18
|
+
return walkDag(nodeSignatures, dagEdges, (sig) => this.estimateSignature(sig));
|
|
19
|
+
}
|
|
20
|
+
/** Internal: look up p50/p90 for a single signature. */
|
|
21
|
+
estimateSignature(sig) {
|
|
22
|
+
const obs = this.history.query(sig);
|
|
23
|
+
if (obs.length === 0)
|
|
24
|
+
return null;
|
|
25
|
+
const costs = obs.map((o) => o.costUsd);
|
|
26
|
+
const durations = obs.map((o) => o.durationMs);
|
|
27
|
+
const costBands = computeBands(costs);
|
|
28
|
+
const durationBands = computeBands(durations);
|
|
29
|
+
const confidence = obs.length >= 20 ? 'high' : obs.length >= 5 ? 'medium' : 'low';
|
|
30
|
+
return {
|
|
31
|
+
cost: {
|
|
32
|
+
p50Usd: costBands.p50,
|
|
33
|
+
p90Usd: costBands.p90,
|
|
34
|
+
sampleCount: obs.length,
|
|
35
|
+
confidence,
|
|
36
|
+
},
|
|
37
|
+
durationMs: {
|
|
38
|
+
p50Usd: durationBands.p50,
|
|
39
|
+
p90Usd: durationBands.p90,
|
|
40
|
+
sampleCount: obs.length,
|
|
41
|
+
confidence,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
record(sig, actualCostUsd, actualDurationMs, accountId) {
|
|
46
|
+
// The actual observation storage happens via HistoricalObservations.append()
|
|
47
|
+
// (called by the RateGovernor releaseSlot flow with AppendToken).
|
|
48
|
+
// This method is a side-channel hook for CostOracle consumers.
|
|
49
|
+
this.onRecord?.(sig, actualCostUsd, actualDurationMs, accountId);
|
|
50
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,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;QAEjE,OAAO;YACL,IAAI,EAAE;gBACJ,MAAM,EAAE,SAAS,CAAC,GAAG;gBACrB,MAAM,EAAE,SAAS,CAAC,GAAG;gBACrB,WAAW,EAAE,GAAG,CAAC,MAAM;gBACvB,UAAU;aACX;YACD,UAAU,EAAE;gBACV,MAAM,EAAE,aAAa,CAAC,GAAG;gBACzB,MAAM,EAAE,aAAa,CAAC,GAAG;gBACzB,WAAW,EAAE,GAAG,CAAC,MAAM;gBACvB,UAAU;aACX;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CACJ,GAAwB,EACxB,aAAqB,EACrB,gBAAwB,EACxB,SAAiB;QAEjB,6EAA6E;QAC7E,kEAAkE;QAClE,+DAA+D;QAC/D,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,aAAa,EAAE,gBAAgB,EAAE,SAAS,CAAC,CAAC;IACnE,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Critical-Path DAG Estimator — computes total cost/duration
|
|
3
|
+
* via the longest path through a DAG with parallelism discount.
|
|
4
|
+
*/
|
|
5
|
+
import type { InvocationSignature, CostBand } from '@methodts/types';
|
|
6
|
+
import type { StrategyEstimate } from '../ports/cost-oracle.js';
|
|
7
|
+
export interface SignatureEstimator {
|
|
8
|
+
(sig: InvocationSignature): {
|
|
9
|
+
cost: CostBand;
|
|
10
|
+
durationMs: CostBand;
|
|
11
|
+
} | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function heuristicEstimate(sig: InvocationSignature): CostBand;
|
|
14
|
+
/**
|
|
15
|
+
* Estimate a full strategy DAG.
|
|
16
|
+
*
|
|
17
|
+
* @param nodeSignatures - Map of nodeId -> InvocationSignature
|
|
18
|
+
* @param dagEdges - Map of nodeId -> list of dependency nodeIds
|
|
19
|
+
* @param estimateSignature - Lookup function for historical data
|
|
20
|
+
*/
|
|
21
|
+
export declare function estimateStrategy(nodeSignatures: ReadonlyMap<string, InvocationSignature>, dagEdges: ReadonlyMap<string, readonly string[]>, estimateSignature: SignatureEstimator): StrategyEstimate;
|
|
22
|
+
//# sourceMappingURL=estimator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimator.d.ts","sourceRoot":"","sources":["../../src/cost-governor/estimator.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EAAgB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE9E,MAAM,WAAW,kBAAkB;IACjC,CAAC,GAAG,EAAE,mBAAmB,GAAG;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,UAAU,EAAE,QAAQ,CAAA;KAAE,GAAG,IAAI,CAAC;CAC7E;AAWD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,mBAAmB,GAAG,QAAQ,CASpE;AAaD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACxD,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,EAChD,iBAAiB,EAAE,kBAAkB,GACpC,gBAAgB,CA0FlB"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Critical-Path DAG Estimator — computes total cost/duration
|
|
4
|
+
* via the longest path through a DAG with parallelism discount.
|
|
5
|
+
*/
|
|
6
|
+
/** Minimum cost floor — prevents zero-cost bypass. */
|
|
7
|
+
const COST_FLOOR_USD = 0.02;
|
|
8
|
+
const DURATION_FLOOR_MS = 5_000;
|
|
9
|
+
/** Empty-history heuristic: $0.05 default, scaled by size bucket. */
|
|
10
|
+
const SIZE_MULTIPLIERS = {
|
|
11
|
+
xs: 0.5, s: 1.0, m: 2.0, l: 5.0, xl: 10.0,
|
|
12
|
+
};
|
|
13
|
+
export function heuristicEstimate(sig) {
|
|
14
|
+
const mult = SIZE_MULTIPLIERS[sig.inputSizeBucket] ?? 1.0;
|
|
15
|
+
const base = 0.05 * mult;
|
|
16
|
+
return {
|
|
17
|
+
p50Usd: Math.max(base, COST_FLOOR_USD),
|
|
18
|
+
p90Usd: Math.max(base * 2, COST_FLOOR_USD),
|
|
19
|
+
sampleCount: 0,
|
|
20
|
+
confidence: 'low',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function heuristicDuration(sig) {
|
|
24
|
+
const mult = SIZE_MULTIPLIERS[sig.inputSizeBucket] ?? 1.0;
|
|
25
|
+
const base = 30_000 * mult;
|
|
26
|
+
return {
|
|
27
|
+
p50Usd: Math.max(base, DURATION_FLOOR_MS), // reusing CostBand shape for duration
|
|
28
|
+
p90Usd: Math.max(base * 2, DURATION_FLOOR_MS),
|
|
29
|
+
sampleCount: 0,
|
|
30
|
+
confidence: 'low',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Estimate a full strategy DAG.
|
|
35
|
+
*
|
|
36
|
+
* @param nodeSignatures - Map of nodeId -> InvocationSignature
|
|
37
|
+
* @param dagEdges - Map of nodeId -> list of dependency nodeIds
|
|
38
|
+
* @param estimateSignature - Lookup function for historical data
|
|
39
|
+
*/
|
|
40
|
+
export function estimateStrategy(nodeSignatures, dagEdges, estimateSignature) {
|
|
41
|
+
const nodes = [];
|
|
42
|
+
const unknownNodes = [];
|
|
43
|
+
// Estimate each node
|
|
44
|
+
const nodeEstimates = new Map();
|
|
45
|
+
for (const [nodeId, sig] of nodeSignatures) {
|
|
46
|
+
const est = estimateSignature(sig);
|
|
47
|
+
const cost = est?.cost ?? heuristicEstimate(sig);
|
|
48
|
+
const durationMs = est?.durationMs ?? heuristicDuration(sig);
|
|
49
|
+
if (!est)
|
|
50
|
+
unknownNodes.push(nodeId);
|
|
51
|
+
// Enforce floor
|
|
52
|
+
const flooredCost = {
|
|
53
|
+
...cost,
|
|
54
|
+
p50Usd: Math.max(cost.p50Usd, COST_FLOOR_USD),
|
|
55
|
+
p90Usd: Math.max(cost.p90Usd, COST_FLOOR_USD),
|
|
56
|
+
};
|
|
57
|
+
const ne = { nodeId, signature: sig, cost: flooredCost, durationMs };
|
|
58
|
+
nodes.push(ne);
|
|
59
|
+
nodeEstimates.set(nodeId, ne);
|
|
60
|
+
}
|
|
61
|
+
// Critical-path computation: longest duration path through DAG
|
|
62
|
+
// Total cost = sum of all nodes (all must execute)
|
|
63
|
+
// Total duration = critical path (longest chain accounting for parallelism)
|
|
64
|
+
const memo = new Map();
|
|
65
|
+
function longestPath(nodeId) {
|
|
66
|
+
if (memo.has(nodeId))
|
|
67
|
+
return memo.get(nodeId);
|
|
68
|
+
const est = nodeEstimates.get(nodeId);
|
|
69
|
+
const selfDuration = est ? est.durationMs.p50Usd : DURATION_FLOOR_MS;
|
|
70
|
+
const deps = dagEdges.get(nodeId) ?? [];
|
|
71
|
+
let maxDepDuration = 0;
|
|
72
|
+
for (const dep of deps) {
|
|
73
|
+
maxDepDuration = Math.max(maxDepDuration, longestPath(dep));
|
|
74
|
+
}
|
|
75
|
+
const total = selfDuration + maxDepDuration;
|
|
76
|
+
memo.set(nodeId, total);
|
|
77
|
+
return total;
|
|
78
|
+
}
|
|
79
|
+
// Find all leaf nodes (nodes that no other node depends on)
|
|
80
|
+
const allDeps = new Set();
|
|
81
|
+
for (const deps of dagEdges.values()) {
|
|
82
|
+
for (const d of deps)
|
|
83
|
+
allDeps.add(d);
|
|
84
|
+
}
|
|
85
|
+
const leafNodes = [...nodeSignatures.keys()].filter(n => !allDeps.has(n));
|
|
86
|
+
// If no leaves found (possible with empty DAG), use all nodes
|
|
87
|
+
const roots = leafNodes.length > 0 ? leafNodes : [...nodeSignatures.keys()];
|
|
88
|
+
let criticalPathMs = 0;
|
|
89
|
+
for (const root of roots) {
|
|
90
|
+
criticalPathMs = Math.max(criticalPathMs, longestPath(root));
|
|
91
|
+
}
|
|
92
|
+
// Sum total cost across all nodes
|
|
93
|
+
let totalP50 = 0;
|
|
94
|
+
let totalP90 = 0;
|
|
95
|
+
for (const ne of nodes) {
|
|
96
|
+
totalP50 += ne.cost.p50Usd;
|
|
97
|
+
totalP90 += ne.cost.p90Usd;
|
|
98
|
+
}
|
|
99
|
+
// Determine overall confidence
|
|
100
|
+
const minSamples = Math.min(...nodes.map(n => n.cost.sampleCount));
|
|
101
|
+
const confidence = minSamples >= 20 ? 'high' : minSamples >= 5 ? 'medium' : 'low';
|
|
102
|
+
return {
|
|
103
|
+
nodes,
|
|
104
|
+
totalCost: {
|
|
105
|
+
p50Usd: totalP50,
|
|
106
|
+
p90Usd: totalP90,
|
|
107
|
+
sampleCount: minSamples,
|
|
108
|
+
confidence,
|
|
109
|
+
},
|
|
110
|
+
totalDurationMs: {
|
|
111
|
+
p50Usd: criticalPathMs,
|
|
112
|
+
p90Usd: criticalPathMs * 1.5, // rough p90 estimate
|
|
113
|
+
sampleCount: minSamples,
|
|
114
|
+
confidence,
|
|
115
|
+
},
|
|
116
|
+
unknownNodes,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=estimator.js.map
|