@vauban-org/agent-sdk 0.16.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/CONTRACT.md +6968 -0
- package/README.md +205 -0
- package/dist/adapters/hitl/memory-state-store.d.ts +23 -0
- package/dist/adapters/hitl/memory-state-store.d.ts.map +1 -0
- package/dist/adapters/hitl/memory-state-store.js +72 -0
- package/dist/adapters/hitl/memory-state-store.js.map +1 -0
- package/dist/adapters/hitl/postgres-state-store.d.ts +29 -0
- package/dist/adapters/hitl/postgres-state-store.d.ts.map +1 -0
- package/dist/adapters/hitl/postgres-state-store.js +103 -0
- package/dist/adapters/hitl/postgres-state-store.js.map +1 -0
- package/dist/adapters/llm/anthropic-direct.d.ts +28 -0
- package/dist/adapters/llm/anthropic-direct.d.ts.map +1 -0
- package/dist/adapters/llm/anthropic-direct.js +163 -0
- package/dist/adapters/llm/anthropic-direct.js.map +1 -0
- package/dist/adapters/llm/cascade.d.ts +27 -0
- package/dist/adapters/llm/cascade.d.ts.map +1 -0
- package/dist/adapters/llm/cascade.js +88 -0
- package/dist/adapters/llm/cascade.js.map +1 -0
- package/dist/adapters/llm/litellm.d.ts +28 -0
- package/dist/adapters/llm/litellm.d.ts.map +1 -0
- package/dist/adapters/llm/litellm.js +239 -0
- package/dist/adapters/llm/litellm.js.map +1 -0
- package/dist/adapters/messaging/console.d.ts +32 -0
- package/dist/adapters/messaging/console.d.ts.map +1 -0
- package/dist/adapters/messaging/console.js +47 -0
- package/dist/adapters/messaging/console.js.map +1 -0
- package/dist/adapters/messaging/discord.d.ts +34 -0
- package/dist/adapters/messaging/discord.d.ts.map +1 -0
- package/dist/adapters/messaging/discord.js +86 -0
- package/dist/adapters/messaging/discord.js.map +1 -0
- package/dist/adapters/messaging/mcp.d.ts +53 -0
- package/dist/adapters/messaging/mcp.d.ts.map +1 -0
- package/dist/adapters/messaging/mcp.js +43 -0
- package/dist/adapters/messaging/mcp.js.map +1 -0
- package/dist/adapters/messaging/slack.d.ts +21 -0
- package/dist/adapters/messaging/slack.d.ts.map +1 -0
- package/dist/adapters/messaging/slack.js +71 -0
- package/dist/adapters/messaging/slack.js.map +1 -0
- package/dist/adapters/messaging/telegram.d.ts +31 -0
- package/dist/adapters/messaging/telegram.d.ts.map +1 -0
- package/dist/adapters/messaging/telegram.js +85 -0
- package/dist/adapters/messaging/telegram.js.map +1 -0
- package/dist/adapters/registry/memory.d.ts +40 -0
- package/dist/adapters/registry/memory.d.ts.map +1 -0
- package/dist/adapters/registry/memory.js +71 -0
- package/dist/adapters/registry/memory.js.map +1 -0
- package/dist/adapters/registry/postgres.d.ts +39 -0
- package/dist/adapters/registry/postgres.d.ts.map +1 -0
- package/dist/adapters/registry/postgres.js +124 -0
- package/dist/adapters/registry/postgres.js.map +1 -0
- package/dist/agents/index.d.ts +2 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +3 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/trading.d.ts +99 -0
- package/dist/agents/trading.d.ts.map +1 -0
- package/dist/agents/trading.js +39 -0
- package/dist/agents/trading.js.map +1 -0
- package/dist/auth/errors.d.ts +38 -0
- package/dist/auth/errors.d.ts.map +1 -0
- package/dist/auth/errors.js +57 -0
- package/dist/auth/errors.js.map +1 -0
- package/dist/auth/nonce-store.d.ts +52 -0
- package/dist/auth/nonce-store.d.ts.map +1 -0
- package/dist/auth/nonce-store.js +55 -0
- package/dist/auth/nonce-store.js.map +1 -0
- package/dist/auth/sign-event.d.ts +28 -0
- package/dist/auth/sign-event.d.ts.map +1 -0
- package/dist/auth/sign-event.js +42 -0
- package/dist/auth/sign-event.js.map +1 -0
- package/dist/auth/verify-event.d.ts +36 -0
- package/dist/auth/verify-event.d.ts.map +1 -0
- package/dist/auth/verify-event.js +78 -0
- package/dist/auth/verify-event.js.map +1 -0
- package/dist/boot/init-sdk.d.ts +69 -0
- package/dist/boot/init-sdk.d.ts.map +1 -0
- package/dist/boot/init-sdk.js +53 -0
- package/dist/boot/init-sdk.js.map +1 -0
- package/dist/boot/load-agent-context.d.ts +82 -0
- package/dist/boot/load-agent-context.d.ts.map +1 -0
- package/dist/boot/load-agent-context.js +90 -0
- package/dist/boot/load-agent-context.js.map +1 -0
- package/dist/boot/load-recent-memory.d.ts +47 -0
- package/dist/boot/load-recent-memory.d.ts.map +1 -0
- package/dist/boot/load-recent-memory.js +56 -0
- package/dist/boot/load-recent-memory.js.map +1 -0
- package/dist/budget/budget-state.d.ts +88 -0
- package/dist/budget/budget-state.d.ts.map +1 -0
- package/dist/budget/budget-state.js +172 -0
- package/dist/budget/budget-state.js.map +1 -0
- package/dist/budget/index.d.ts +3 -0
- package/dist/budget/index.d.ts.map +1 -0
- package/dist/budget/index.js +2 -0
- package/dist/budget/index.js.map +1 -0
- package/dist/clients/agents.d.ts +40 -0
- package/dist/clients/agents.d.ts.map +1 -0
- package/dist/clients/agents.js +85 -0
- package/dist/clients/agents.js.map +1 -0
- package/dist/clients/index.d.ts +7 -0
- package/dist/clients/index.d.ts.map +1 -0
- package/dist/clients/index.js +7 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/clients/messaging-adapters.d.ts +51 -0
- package/dist/clients/messaging-adapters.d.ts.map +1 -0
- package/dist/clients/messaging-adapters.js +118 -0
- package/dist/clients/messaging-adapters.js.map +1 -0
- package/dist/clients/pipelines.d.ts +43 -0
- package/dist/clients/pipelines.d.ts.map +1 -0
- package/dist/clients/pipelines.js +96 -0
- package/dist/clients/pipelines.js.map +1 -0
- package/dist/compute/strategies/best-of-n.d.ts +46 -0
- package/dist/compute/strategies/best-of-n.d.ts.map +1 -0
- package/dist/compute/strategies/best-of-n.js +112 -0
- package/dist/compute/strategies/best-of-n.js.map +1 -0
- package/dist/compute/strategies/bon-mav.d.ts +65 -0
- package/dist/compute/strategies/bon-mav.d.ts.map +1 -0
- package/dist/compute/strategies/bon-mav.js +154 -0
- package/dist/compute/strategies/bon-mav.js.map +1 -0
- package/dist/compute/strategies/single-shot.d.ts +17 -0
- package/dist/compute/strategies/single-shot.d.ts.map +1 -0
- package/dist/compute/strategies/single-shot.js +36 -0
- package/dist/compute/strategies/single-shot.js.map +1 -0
- package/dist/compute/types.d.ts +30 -0
- package/dist/compute/types.d.ts.map +1 -0
- package/dist/compute/types.js +8 -0
- package/dist/compute/types.js.map +1 -0
- package/dist/compute/verifier.d.ts +55 -0
- package/dist/compute/verifier.d.ts.map +1 -0
- package/dist/compute/verifier.js +35 -0
- package/dist/compute/verifier.js.map +1 -0
- package/dist/compute/with-compute.d.ts +50 -0
- package/dist/compute/with-compute.d.ts.map +1 -0
- package/dist/compute/with-compute.js +69 -0
- package/dist/compute/with-compute.js.map +1 -0
- package/dist/constitution/axioms.d.ts +65 -0
- package/dist/constitution/axioms.d.ts.map +1 -0
- package/dist/constitution/axioms.js +496 -0
- package/dist/constitution/axioms.js.map +1 -0
- package/dist/constitution/gate.d.ts +47 -0
- package/dist/constitution/gate.d.ts.map +1 -0
- package/dist/constitution/gate.js +143 -0
- package/dist/constitution/gate.js.map +1 -0
- package/dist/constitution/index.d.ts +20 -0
- package/dist/constitution/index.d.ts.map +1 -0
- package/dist/constitution/index.js +15 -0
- package/dist/constitution/index.js.map +1 -0
- package/dist/constitution/scorer.d.ts +67 -0
- package/dist/constitution/scorer.d.ts.map +1 -0
- package/dist/constitution/scorer.js +111 -0
- package/dist/constitution/scorer.js.map +1 -0
- package/dist/constitution/signal.d.ts +41 -0
- package/dist/constitution/signal.d.ts.map +1 -0
- package/dist/constitution/signal.js +61 -0
- package/dist/constitution/signal.js.map +1 -0
- package/dist/constitution/types.d.ts +295 -0
- package/dist/constitution/types.d.ts.map +1 -0
- package/dist/constitution/types.js +59 -0
- package/dist/constitution/types.js.map +1 -0
- package/dist/counterfactual/index.d.ts +11 -0
- package/dist/counterfactual/index.d.ts.map +1 -0
- package/dist/counterfactual/index.js +10 -0
- package/dist/counterfactual/index.js.map +1 -0
- package/dist/counterfactual/replay-with-alt.d.ts +137 -0
- package/dist/counterfactual/replay-with-alt.d.ts.map +1 -0
- package/dist/counterfactual/replay-with-alt.js +191 -0
- package/dist/counterfactual/replay-with-alt.js.map +1 -0
- package/dist/dataops/index.d.ts +5 -0
- package/dist/dataops/index.d.ts.map +1 -0
- package/dist/dataops/index.js +3 -0
- package/dist/dataops/index.js.map +1 -0
- package/dist/dataops/starkscan.d.ts +13 -0
- package/dist/dataops/starkscan.d.ts.map +1 -0
- package/dist/dataops/starkscan.js +12 -0
- package/dist/dataops/starkscan.js.map +1 -0
- package/dist/dataops/voyager.d.ts +58 -0
- package/dist/dataops/voyager.d.ts.map +1 -0
- package/dist/dataops/voyager.js +146 -0
- package/dist/dataops/voyager.js.map +1 -0
- package/dist/deprecation.d.ts +49 -0
- package/dist/deprecation.d.ts.map +1 -0
- package/dist/deprecation.js +84 -0
- package/dist/deprecation.js.map +1 -0
- package/dist/durable/bullmq-runner.d.ts +138 -0
- package/dist/durable/bullmq-runner.d.ts.map +1 -0
- package/dist/durable/bullmq-runner.js +378 -0
- package/dist/durable/bullmq-runner.js.map +1 -0
- package/dist/durable/index.d.ts +3 -0
- package/dist/durable/index.d.ts.map +1 -0
- package/dist/durable/index.js +2 -0
- package/dist/durable/index.js.map +1 -0
- package/dist/economy/circuit-breaker.d.ts +37 -0
- package/dist/economy/circuit-breaker.d.ts.map +1 -0
- package/dist/economy/circuit-breaker.js +104 -0
- package/dist/economy/circuit-breaker.js.map +1 -0
- package/dist/economy/economy-router.d.ts +103 -0
- package/dist/economy/economy-router.d.ts.map +1 -0
- package/dist/economy/economy-router.js +176 -0
- package/dist/economy/economy-router.js.map +1 -0
- package/dist/economy/index.d.ts +16 -0
- package/dist/economy/index.d.ts.map +1 -0
- package/dist/economy/index.js +11 -0
- package/dist/economy/index.js.map +1 -0
- package/dist/economy/outcome-tracker.d.ts +90 -0
- package/dist/economy/outcome-tracker.d.ts.map +1 -0
- package/dist/economy/outcome-tracker.js +172 -0
- package/dist/economy/outcome-tracker.js.map +1 -0
- package/dist/economy/router.d.ts +97 -0
- package/dist/economy/router.d.ts.map +1 -0
- package/dist/economy/router.js +181 -0
- package/dist/economy/router.js.map +1 -0
- package/dist/economy/tier-policy.d.ts +46 -0
- package/dist/economy/tier-policy.d.ts.map +1 -0
- package/dist/economy/tier-policy.js +76 -0
- package/dist/economy/tier-policy.js.map +1 -0
- package/dist/errors.d.ts +102 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +135 -0
- package/dist/errors.js.map +1 -0
- package/dist/evals/datasets/index.d.ts +27 -0
- package/dist/evals/datasets/index.d.ts.map +1 -0
- package/dist/evals/datasets/index.js +279 -0
- package/dist/evals/datasets/index.js.map +1 -0
- package/dist/evals/harness.d.ts +52 -0
- package/dist/evals/harness.d.ts.map +1 -0
- package/dist/evals/harness.js +108 -0
- package/dist/evals/harness.js.map +1 -0
- package/dist/evals/index.d.ts +5 -0
- package/dist/evals/index.d.ts.map +1 -0
- package/dist/evals/index.js +3 -0
- package/dist/evals/index.js.map +1 -0
- package/dist/factory/agent-factory.d.ts +86 -0
- package/dist/factory/agent-factory.d.ts.map +1 -0
- package/dist/factory/agent-factory.js +119 -0
- package/dist/factory/agent-factory.js.map +1 -0
- package/dist/hitl/api.d.ts +38 -0
- package/dist/hitl/api.d.ts.map +1 -0
- package/dist/hitl/api.js +58 -0
- package/dist/hitl/api.js.map +1 -0
- package/dist/hitl/approval-channel.d.ts +84 -0
- package/dist/hitl/approval-channel.d.ts.map +1 -0
- package/dist/hitl/approval-channel.js +59 -0
- package/dist/hitl/approval-channel.js.map +1 -0
- package/dist/hitl/callback-handlers.d.ts +21 -0
- package/dist/hitl/callback-handlers.d.ts.map +1 -0
- package/dist/hitl/callback-handlers.js +30 -0
- package/dist/hitl/callback-handlers.js.map +1 -0
- package/dist/hitl/index.d.ts +3 -0
- package/dist/hitl/index.d.ts.map +1 -0
- package/dist/hitl/index.js +2 -0
- package/dist/hitl/index.js.map +1 -0
- package/dist/hitl/slack.d.ts +76 -0
- package/dist/hitl/slack.d.ts.map +1 -0
- package/dist/hitl/slack.js +243 -0
- package/dist/hitl/slack.js.map +1 -0
- package/dist/hitl/telegram.d.ts +74 -0
- package/dist/hitl/telegram.d.ts.map +1 -0
- package/dist/hitl/telegram.js +227 -0
- package/dist/hitl/telegram.js.map +1 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/parse-structured-output.d.ts +55 -0
- package/dist/llm/parse-structured-output.d.ts.map +1 -0
- package/dist/llm/parse-structured-output.js +80 -0
- package/dist/llm/parse-structured-output.js.map +1 -0
- package/dist/loop/index.d.ts +7 -0
- package/dist/loop/index.d.ts.map +1 -0
- package/dist/loop/index.js +5 -0
- package/dist/loop/index.js.map +1 -0
- package/dist/loop/minimal-loop.d.ts +81 -0
- package/dist/loop/minimal-loop.d.ts.map +1 -0
- package/dist/loop/minimal-loop.js +318 -0
- package/dist/loop/minimal-loop.js.map +1 -0
- package/dist/loop/sdk-loop.d.ts +103 -0
- package/dist/loop/sdk-loop.d.ts.map +1 -0
- package/dist/loop/sdk-loop.js +344 -0
- package/dist/loop/sdk-loop.js.map +1 -0
- package/dist/mcp/index.d.ts +38 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +113 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/metrics/create-agent-metrics.d.ts +78 -0
- package/dist/metrics/create-agent-metrics.d.ts.map +1 -0
- package/dist/metrics/create-agent-metrics.js +115 -0
- package/dist/metrics/create-agent-metrics.js.map +1 -0
- package/dist/orchestration/bulkhead.d.ts +70 -0
- package/dist/orchestration/bulkhead.d.ts.map +1 -0
- package/dist/orchestration/bulkhead.js +99 -0
- package/dist/orchestration/bulkhead.js.map +1 -0
- package/dist/orchestration/idempotency.d.ts +52 -0
- package/dist/orchestration/idempotency.d.ts.map +1 -0
- package/dist/orchestration/idempotency.js +93 -0
- package/dist/orchestration/idempotency.js.map +1 -0
- package/dist/orchestration/index.d.ts +16 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +15 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/ooda/agent-config-loader.d.ts +67 -0
- package/dist/orchestration/ooda/agent-config-loader.d.ts.map +1 -0
- package/dist/orchestration/ooda/agent-config-loader.js +65 -0
- package/dist/orchestration/ooda/agent-config-loader.js.map +1 -0
- package/dist/orchestration/ooda/agent.d.ts +54 -0
- package/dist/orchestration/ooda/agent.d.ts.map +1 -0
- package/dist/orchestration/ooda/agent.js +730 -0
- package/dist/orchestration/ooda/agent.js.map +1 -0
- package/dist/orchestration/ooda/audit-log.d.ts +26 -0
- package/dist/orchestration/ooda/audit-log.d.ts.map +1 -0
- package/dist/orchestration/ooda/audit-log.js +41 -0
- package/dist/orchestration/ooda/audit-log.js.map +1 -0
- package/dist/orchestration/ooda/brain-context.d.ts +121 -0
- package/dist/orchestration/ooda/brain-context.d.ts.map +1 -0
- package/dist/orchestration/ooda/brain-context.js +149 -0
- package/dist/orchestration/ooda/brain-context.js.map +1 -0
- package/dist/orchestration/ooda/child-agent.d.ts +55 -0
- package/dist/orchestration/ooda/child-agent.d.ts.map +1 -0
- package/dist/orchestration/ooda/child-agent.js +16 -0
- package/dist/orchestration/ooda/child-agent.js.map +1 -0
- package/dist/orchestration/ooda/cron-schedule.d.ts +26 -0
- package/dist/orchestration/ooda/cron-schedule.d.ts.map +1 -0
- package/dist/orchestration/ooda/cron-schedule.js +94 -0
- package/dist/orchestration/ooda/cron-schedule.js.map +1 -0
- package/dist/orchestration/ooda/debate.d.ts +68 -0
- package/dist/orchestration/ooda/debate.d.ts.map +1 -0
- package/dist/orchestration/ooda/debate.js +39 -0
- package/dist/orchestration/ooda/debate.js.map +1 -0
- package/dist/orchestration/ooda/economic-observer.d.ts +50 -0
- package/dist/orchestration/ooda/economic-observer.d.ts.map +1 -0
- package/dist/orchestration/ooda/economic-observer.js +36 -0
- package/dist/orchestration/ooda/economic-observer.js.map +1 -0
- package/dist/orchestration/ooda/errors.d.ts +21 -0
- package/dist/orchestration/ooda/errors.d.ts.map +1 -0
- package/dist/orchestration/ooda/errors.js +30 -0
- package/dist/orchestration/ooda/errors.js.map +1 -0
- package/dist/orchestration/ooda/execution-mode-guard.d.ts +24 -0
- package/dist/orchestration/ooda/execution-mode-guard.d.ts.map +1 -0
- package/dist/orchestration/ooda/execution-mode-guard.js +31 -0
- package/dist/orchestration/ooda/execution-mode-guard.js.map +1 -0
- package/dist/orchestration/ooda/factory.d.ts +12 -0
- package/dist/orchestration/ooda/factory.d.ts.map +1 -0
- package/dist/orchestration/ooda/factory.js +27 -0
- package/dist/orchestration/ooda/factory.js.map +1 -0
- package/dist/orchestration/ooda/guardrails.d.ts +65 -0
- package/dist/orchestration/ooda/guardrails.d.ts.map +1 -0
- package/dist/orchestration/ooda/guardrails.js +127 -0
- package/dist/orchestration/ooda/guardrails.js.map +1 -0
- package/dist/orchestration/ooda/guards/always-on.d.ts +15 -0
- package/dist/orchestration/ooda/guards/always-on.d.ts.map +1 -0
- package/dist/orchestration/ooda/guards/always-on.js +19 -0
- package/dist/orchestration/ooda/guards/always-on.js.map +1 -0
- package/dist/orchestration/ooda/guards/business-hours.d.ts +46 -0
- package/dist/orchestration/ooda/guards/business-hours.d.ts.map +1 -0
- package/dist/orchestration/ooda/guards/business-hours.js +78 -0
- package/dist/orchestration/ooda/guards/business-hours.js.map +1 -0
- package/dist/orchestration/ooda/guards/index.d.ts +14 -0
- package/dist/orchestration/ooda/guards/index.d.ts.map +1 -0
- package/dist/orchestration/ooda/guards/index.js +14 -0
- package/dist/orchestration/ooda/guards/index.js.map +1 -0
- package/dist/orchestration/ooda/guards/redis-circuit-breaker.d.ts +84 -0
- package/dist/orchestration/ooda/guards/redis-circuit-breaker.d.ts.map +1 -0
- package/dist/orchestration/ooda/guards/redis-circuit-breaker.js +96 -0
- package/dist/orchestration/ooda/guards/redis-circuit-breaker.js.map +1 -0
- package/dist/orchestration/ooda/guards/rth-session.d.ts +27 -0
- package/dist/orchestration/ooda/guards/rth-session.d.ts.map +1 -0
- package/dist/orchestration/ooda/guards/rth-session.js +95 -0
- package/dist/orchestration/ooda/guards/rth-session.js.map +1 -0
- package/dist/orchestration/ooda/handoff.d.ts +82 -0
- package/dist/orchestration/ooda/handoff.d.ts.map +1 -0
- package/dist/orchestration/ooda/handoff.js +86 -0
- package/dist/orchestration/ooda/handoff.js.map +1 -0
- package/dist/orchestration/ooda/hitl-gate.d.ts +57 -0
- package/dist/orchestration/ooda/hitl-gate.d.ts.map +1 -0
- package/dist/orchestration/ooda/hitl-gate.js +107 -0
- package/dist/orchestration/ooda/hitl-gate.js.map +1 -0
- package/dist/orchestration/ooda/index.d.ts +48 -0
- package/dist/orchestration/ooda/index.d.ts.map +1 -0
- package/dist/orchestration/ooda/index.js +33 -0
- package/dist/orchestration/ooda/index.js.map +1 -0
- package/dist/orchestration/ooda/inner-monologue.d.ts +69 -0
- package/dist/orchestration/ooda/inner-monologue.d.ts.map +1 -0
- package/dist/orchestration/ooda/inner-monologue.js +69 -0
- package/dist/orchestration/ooda/inner-monologue.js.map +1 -0
- package/dist/orchestration/ooda/learn.d.ts +60 -0
- package/dist/orchestration/ooda/learn.d.ts.map +1 -0
- package/dist/orchestration/ooda/learn.js +94 -0
- package/dist/orchestration/ooda/learn.js.map +1 -0
- package/dist/orchestration/ooda/multimodal.d.ts +91 -0
- package/dist/orchestration/ooda/multimodal.d.ts.map +1 -0
- package/dist/orchestration/ooda/multimodal.js +88 -0
- package/dist/orchestration/ooda/multimodal.js.map +1 -0
- package/dist/orchestration/ooda/phase-routing.d.ts +41 -0
- package/dist/orchestration/ooda/phase-routing.d.ts.map +1 -0
- package/dist/orchestration/ooda/phase-routing.js +43 -0
- package/dist/orchestration/ooda/phase-routing.js.map +1 -0
- package/dist/orchestration/ooda/plan-execute.d.ts +55 -0
- package/dist/orchestration/ooda/plan-execute.d.ts.map +1 -0
- package/dist/orchestration/ooda/plan-execute.js +41 -0
- package/dist/orchestration/ooda/plan-execute.js.map +1 -0
- package/dist/orchestration/ooda/react-loop.d.ts +96 -0
- package/dist/orchestration/ooda/react-loop.d.ts.map +1 -0
- package/dist/orchestration/ooda/react-loop.js +90 -0
- package/dist/orchestration/ooda/react-loop.js.map +1 -0
- package/dist/orchestration/ooda/reflexion.d.ts +56 -0
- package/dist/orchestration/ooda/reflexion.d.ts.map +1 -0
- package/dist/orchestration/ooda/reflexion.js +58 -0
- package/dist/orchestration/ooda/reflexion.js.map +1 -0
- package/dist/orchestration/ooda/resource-limits.d.ts +63 -0
- package/dist/orchestration/ooda/resource-limits.d.ts.map +1 -0
- package/dist/orchestration/ooda/resource-limits.js +107 -0
- package/dist/orchestration/ooda/resource-limits.js.map +1 -0
- package/dist/orchestration/ooda/run-step-persistence.d.ts +50 -0
- package/dist/orchestration/ooda/run-step-persistence.d.ts.map +1 -0
- package/dist/orchestration/ooda/run-step-persistence.js +89 -0
- package/dist/orchestration/ooda/run-step-persistence.js.map +1 -0
- package/dist/orchestration/ooda/skills.d.ts +58 -0
- package/dist/orchestration/ooda/skills.d.ts.map +1 -0
- package/dist/orchestration/ooda/skills.js +19 -0
- package/dist/orchestration/ooda/skills.js.map +1 -0
- package/dist/orchestration/ooda/structured-output.d.ts +46 -0
- package/dist/orchestration/ooda/structured-output.d.ts.map +1 -0
- package/dist/orchestration/ooda/structured-output.js +60 -0
- package/dist/orchestration/ooda/structured-output.js.map +1 -0
- package/dist/orchestration/ooda/types.d.ts +463 -0
- package/dist/orchestration/ooda/types.d.ts.map +1 -0
- package/dist/orchestration/ooda/types.js +38 -0
- package/dist/orchestration/ooda/types.js.map +1 -0
- package/dist/otel/attributes.d.ts +71 -0
- package/dist/otel/attributes.d.ts.map +1 -0
- package/dist/otel/attributes.js +56 -0
- package/dist/otel/attributes.js.map +1 -0
- package/dist/otel/index.d.ts +5 -0
- package/dist/otel/index.d.ts.map +1 -0
- package/dist/otel/index.js +5 -0
- package/dist/otel/index.js.map +1 -0
- package/dist/otel/ingest.d.ts +99 -0
- package/dist/otel/ingest.d.ts.map +1 -0
- package/dist/otel/ingest.js +192 -0
- package/dist/otel/ingest.js.map +1 -0
- package/dist/otel/trace-context.d.ts +48 -0
- package/dist/otel/trace-context.d.ts.map +1 -0
- package/dist/otel/trace-context.js +137 -0
- package/dist/otel/trace-context.js.map +1 -0
- package/dist/otel/types.d.ts +54 -0
- package/dist/otel/types.d.ts.map +1 -0
- package/dist/otel/types.js +12 -0
- package/dist/otel/types.js.map +1 -0
- package/dist/outcomes/client.d.ts +81 -0
- package/dist/outcomes/client.d.ts.map +1 -0
- package/dist/outcomes/client.js +98 -0
- package/dist/outcomes/client.js.map +1 -0
- package/dist/outcomes/compute-roi.d.ts +40 -0
- package/dist/outcomes/compute-roi.d.ts.map +1 -0
- package/dist/outcomes/compute-roi.js +58 -0
- package/dist/outcomes/compute-roi.js.map +1 -0
- package/dist/outcomes/index.d.ts +4 -0
- package/dist/outcomes/index.d.ts.map +1 -0
- package/dist/outcomes/index.js +4 -0
- package/dist/outcomes/index.js.map +1 -0
- package/dist/outcomes/meter.d.ts +73 -0
- package/dist/outcomes/meter.d.ts.map +1 -0
- package/dist/outcomes/meter.js +140 -0
- package/dist/outcomes/meter.js.map +1 -0
- package/dist/outcomes/trajectory.d.ts +53 -0
- package/dist/outcomes/trajectory.d.ts.map +1 -0
- package/dist/outcomes/trajectory.js +110 -0
- package/dist/outcomes/trajectory.js.map +1 -0
- package/dist/outcomes/types.d.ts +93 -0
- package/dist/outcomes/types.d.ts.map +1 -0
- package/dist/outcomes/types.js +8 -0
- package/dist/outcomes/types.js.map +1 -0
- package/dist/patterns/_shared/brain-logger.d.ts +12 -0
- package/dist/patterns/_shared/brain-logger.d.ts.map +1 -0
- package/dist/patterns/_shared/brain-logger.js +6 -0
- package/dist/patterns/_shared/brain-logger.js.map +1 -0
- package/dist/patterns/circuit-breaker/index.d.ts +3 -0
- package/dist/patterns/circuit-breaker/index.d.ts.map +1 -0
- package/dist/patterns/circuit-breaker/index.js +2 -0
- package/dist/patterns/circuit-breaker/index.js.map +1 -0
- package/dist/patterns/circuit-breaker/session-cb.d.ts +3 -0
- package/dist/patterns/circuit-breaker/session-cb.d.ts.map +1 -0
- package/dist/patterns/circuit-breaker/session-cb.js +175 -0
- package/dist/patterns/circuit-breaker/session-cb.js.map +1 -0
- package/dist/patterns/circuit-breaker/types.d.ts +68 -0
- package/dist/patterns/circuit-breaker/types.d.ts.map +1 -0
- package/dist/patterns/circuit-breaker/types.js +2 -0
- package/dist/patterns/circuit-breaker/types.js.map +1 -0
- package/dist/patterns/escalation/index.d.ts +3 -0
- package/dist/patterns/escalation/index.d.ts.map +1 -0
- package/dist/patterns/escalation/index.js +2 -0
- package/dist/patterns/escalation/index.js.map +1 -0
- package/dist/patterns/escalation/pyramid.d.ts +3 -0
- package/dist/patterns/escalation/pyramid.d.ts.map +1 -0
- package/dist/patterns/escalation/pyramid.js +86 -0
- package/dist/patterns/escalation/pyramid.js.map +1 -0
- package/dist/patterns/escalation/types.d.ts +46 -0
- package/dist/patterns/escalation/types.d.ts.map +1 -0
- package/dist/patterns/escalation/types.js +2 -0
- package/dist/patterns/escalation/types.js.map +1 -0
- package/dist/patterns/quality-gate/gate.d.ts +3 -0
- package/dist/patterns/quality-gate/gate.d.ts.map +1 -0
- package/dist/patterns/quality-gate/gate.js +73 -0
- package/dist/patterns/quality-gate/gate.js.map +1 -0
- package/dist/patterns/quality-gate/index.d.ts +3 -0
- package/dist/patterns/quality-gate/index.d.ts.map +1 -0
- package/dist/patterns/quality-gate/index.js +2 -0
- package/dist/patterns/quality-gate/index.js.map +1 -0
- package/dist/patterns/quality-gate/types.d.ts +41 -0
- package/dist/patterns/quality-gate/types.d.ts.map +1 -0
- package/dist/patterns/quality-gate/types.js +2 -0
- package/dist/patterns/quality-gate/types.js.map +1 -0
- package/dist/permissions/capability-gate.d.ts +57 -0
- package/dist/permissions/capability-gate.d.ts.map +1 -0
- package/dist/permissions/capability-gate.js +26 -0
- package/dist/permissions/capability-gate.js.map +1 -0
- package/dist/permissions/index.d.ts +3 -0
- package/dist/permissions/index.d.ts.map +1 -0
- package/dist/permissions/index.js +2 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/permissions/renewal-manager.d.ts +49 -0
- package/dist/permissions/renewal-manager.d.ts.map +1 -0
- package/dist/permissions/renewal-manager.js +60 -0
- package/dist/permissions/renewal-manager.js.map +1 -0
- package/dist/permissions/sdk-permissions.d.ts +48 -0
- package/dist/permissions/sdk-permissions.d.ts.map +1 -0
- package/dist/permissions/sdk-permissions.js +94 -0
- package/dist/permissions/sdk-permissions.js.map +1 -0
- package/dist/ports/agent-registry.d.ts +95 -0
- package/dist/ports/agent-registry.d.ts.map +1 -0
- package/dist/ports/agent-registry.js +16 -0
- package/dist/ports/agent-registry.js.map +1 -0
- package/dist/ports/brain.d.ts +147 -0
- package/dist/ports/brain.d.ts.map +1 -0
- package/dist/ports/brain.js +105 -0
- package/dist/ports/brain.js.map +1 -0
- package/dist/ports/db.d.ts +8 -0
- package/dist/ports/db.d.ts.map +1 -0
- package/dist/ports/db.js +2 -0
- package/dist/ports/db.js.map +1 -0
- package/dist/ports/event-bus.d.ts +167 -0
- package/dist/ports/event-bus.d.ts.map +1 -0
- package/dist/ports/event-bus.js +25 -0
- package/dist/ports/event-bus.js.map +1 -0
- package/dist/ports/eviction-policy.d.ts +92 -0
- package/dist/ports/eviction-policy.d.ts.map +1 -0
- package/dist/ports/eviction-policy.js +120 -0
- package/dist/ports/eviction-policy.js.map +1 -0
- package/dist/ports/hitl.contract.test.d.ts +9 -0
- package/dist/ports/hitl.contract.test.d.ts.map +1 -0
- package/dist/ports/hitl.contract.test.js +100 -0
- package/dist/ports/hitl.contract.test.js.map +1 -0
- package/dist/ports/hitl.d.ts +91 -0
- package/dist/ports/hitl.d.ts.map +1 -0
- package/dist/ports/hitl.js +76 -0
- package/dist/ports/hitl.js.map +1 -0
- package/dist/ports/index.d.ts +19 -0
- package/dist/ports/index.d.ts.map +1 -0
- package/dist/ports/index.js +4 -0
- package/dist/ports/index.js.map +1 -0
- package/dist/ports/key-provider.d.ts +113 -0
- package/dist/ports/key-provider.d.ts.map +1 -0
- package/dist/ports/key-provider.js +119 -0
- package/dist/ports/key-provider.js.map +1 -0
- package/dist/ports/llm-provider.contract.d.ts +24 -0
- package/dist/ports/llm-provider.contract.d.ts.map +1 -0
- package/dist/ports/llm-provider.contract.js +111 -0
- package/dist/ports/llm-provider.contract.js.map +1 -0
- package/dist/ports/llm-provider.d.ts +63 -0
- package/dist/ports/llm-provider.d.ts.map +1 -0
- package/dist/ports/llm-provider.js +13 -0
- package/dist/ports/llm-provider.js.map +1 -0
- package/dist/ports/logger.d.ts +18 -0
- package/dist/ports/logger.d.ts.map +1 -0
- package/dist/ports/logger.js +10 -0
- package/dist/ports/logger.js.map +1 -0
- package/dist/ports/messaging.contract.test.d.ts +22 -0
- package/dist/ports/messaging.contract.test.d.ts.map +1 -0
- package/dist/ports/messaging.contract.test.js +296 -0
- package/dist/ports/messaging.contract.test.js.map +1 -0
- package/dist/ports/messaging.d.ts +47 -0
- package/dist/ports/messaging.d.ts.map +1 -0
- package/dist/ports/messaging.js +24 -0
- package/dist/ports/messaging.js.map +1 -0
- package/dist/ports/outcome.d.ts +25 -0
- package/dist/ports/outcome.d.ts.map +1 -0
- package/dist/ports/outcome.js +9 -0
- package/dist/ports/outcome.js.map +1 -0
- package/dist/ports/timestamp.d.ts +53 -0
- package/dist/ports/timestamp.d.ts.map +1 -0
- package/dist/ports/timestamp.js +28 -0
- package/dist/ports/timestamp.js.map +1 -0
- package/dist/privacy/channel.d.ts +137 -0
- package/dist/privacy/channel.d.ts.map +1 -0
- package/dist/privacy/channel.js +196 -0
- package/dist/privacy/channel.js.map +1 -0
- package/dist/privacy/composition.d.ts +140 -0
- package/dist/privacy/composition.d.ts.map +1 -0
- package/dist/privacy/composition.js +182 -0
- package/dist/privacy/composition.js.map +1 -0
- package/dist/privacy/delegation.d.ts +87 -0
- package/dist/privacy/delegation.d.ts.map +1 -0
- package/dist/privacy/delegation.js +67 -0
- package/dist/privacy/delegation.js.map +1 -0
- package/dist/privacy/index.d.ts +25 -0
- package/dist/privacy/index.d.ts.map +1 -0
- package/dist/privacy/index.js +21 -0
- package/dist/privacy/index.js.map +1 -0
- package/dist/privacy/nullifier.d.ts +59 -0
- package/dist/privacy/nullifier.d.ts.map +1 -0
- package/dist/privacy/nullifier.js +70 -0
- package/dist/privacy/nullifier.js.map +1 -0
- package/dist/privacy/poseidon-felt252.d.ts +35 -0
- package/dist/privacy/poseidon-felt252.d.ts.map +1 -0
- package/dist/privacy/poseidon-felt252.js +93 -0
- package/dist/privacy/poseidon-felt252.js.map +1 -0
- package/dist/privacy/uar.d.ts +170 -0
- package/dist/privacy/uar.d.ts.map +1 -0
- package/dist/privacy/uar.js +150 -0
- package/dist/privacy/uar.js.map +1 -0
- package/dist/prompts/build-orient-prompt.d.ts +41 -0
- package/dist/prompts/build-orient-prompt.d.ts.map +1 -0
- package/dist/prompts/build-orient-prompt.js +40 -0
- package/dist/prompts/build-orient-prompt.js.map +1 -0
- package/dist/proof/chain.d.ts +90 -0
- package/dist/proof/chain.d.ts.map +1 -0
- package/dist/proof/chain.js +177 -0
- package/dist/proof/chain.js.map +1 -0
- package/dist/proof/fallback-adapter.d.ts +50 -0
- package/dist/proof/fallback-adapter.d.ts.map +1 -0
- package/dist/proof/fallback-adapter.js +99 -0
- package/dist/proof/fallback-adapter.js.map +1 -0
- package/dist/proof/index.d.ts +35 -0
- package/dist/proof/index.d.ts.map +1 -0
- package/dist/proof/index.js +161 -0
- package/dist/proof/index.js.map +1 -0
- package/dist/proof/load.d.ts +27 -0
- package/dist/proof/load.d.ts.map +1 -0
- package/dist/proof/load.js +44 -0
- package/dist/proof/load.js.map +1 -0
- package/dist/proof/otel.d.ts +25 -0
- package/dist/proof/otel.d.ts.map +1 -0
- package/dist/proof/otel.js +57 -0
- package/dist/proof/otel.js.map +1 -0
- package/dist/proof/receipt-queue.d.ts +97 -0
- package/dist/proof/receipt-queue.d.ts.map +1 -0
- package/dist/proof/receipt-queue.js +131 -0
- package/dist/proof/receipt-queue.js.map +1 -0
- package/dist/proof/sha256.d.ts +27 -0
- package/dist/proof/sha256.d.ts.map +1 -0
- package/dist/proof/sha256.js +65 -0
- package/dist/proof/sha256.js.map +1 -0
- package/dist/proof/types.d.ts +55 -0
- package/dist/proof/types.d.ts.map +1 -0
- package/dist/proof/types.js +10 -0
- package/dist/proof/types.js.map +1 -0
- package/dist/proof/verify.d.ts +28 -0
- package/dist/proof/verify.d.ts.map +1 -0
- package/dist/proof/verify.js +70 -0
- package/dist/proof/verify.js.map +1 -0
- package/dist/registry/agent-capability.d.ts +29 -0
- package/dist/registry/agent-capability.d.ts.map +1 -0
- package/dist/registry/agent-capability.js +21 -0
- package/dist/registry/agent-capability.js.map +1 -0
- package/dist/registry/agent-card.d.ts +86 -0
- package/dist/registry/agent-card.d.ts.map +1 -0
- package/dist/registry/agent-card.js +80 -0
- package/dist/registry/agent-card.js.map +1 -0
- package/dist/registry/agent-ids.d.ts +30 -0
- package/dist/registry/agent-ids.d.ts.map +1 -0
- package/dist/registry/agent-ids.js +46 -0
- package/dist/registry/agent-ids.js.map +1 -0
- package/dist/registry/agent-registry.d.ts +104 -0
- package/dist/registry/agent-registry.d.ts.map +1 -0
- package/dist/registry/agent-registry.js +277 -0
- package/dist/registry/agent-registry.js.map +1 -0
- package/dist/registry/index.d.ts +7 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +4 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/replay/clock.d.ts +69 -0
- package/dist/replay/clock.d.ts.map +1 -0
- package/dist/replay/clock.js +84 -0
- package/dist/replay/clock.js.map +1 -0
- package/dist/replay/cross-cycle.d.ts +143 -0
- package/dist/replay/cross-cycle.d.ts.map +1 -0
- package/dist/replay/cross-cycle.js +271 -0
- package/dist/replay/cross-cycle.js.map +1 -0
- package/dist/replay/http-vcr.d.ts +46 -0
- package/dist/replay/http-vcr.d.ts.map +1 -0
- package/dist/replay/http-vcr.js +87 -0
- package/dist/replay/http-vcr.js.map +1 -0
- package/dist/replay/index.d.ts +18 -0
- package/dist/replay/index.d.ts.map +1 -0
- package/dist/replay/index.js +18 -0
- package/dist/replay/index.js.map +1 -0
- package/dist/replay/llm-cache.d.ts +126 -0
- package/dist/replay/llm-cache.d.ts.map +1 -0
- package/dist/replay/llm-cache.js +114 -0
- package/dist/replay/llm-cache.js.map +1 -0
- package/dist/replay/random.d.ts +114 -0
- package/dist/replay/random.d.ts.map +1 -0
- package/dist/replay/random.js +183 -0
- package/dist/replay/random.js.map +1 -0
- package/dist/replay/replay.d.ts +160 -0
- package/dist/replay/replay.d.ts.map +1 -0
- package/dist/replay/replay.js +115 -0
- package/dist/replay/replay.js.map +1 -0
- package/dist/resilience/bulkhead.d.ts +37 -0
- package/dist/resilience/bulkhead.d.ts.map +1 -0
- package/dist/resilience/bulkhead.js +65 -0
- package/dist/resilience/bulkhead.js.map +1 -0
- package/dist/resilience/circuit-breaker.d.ts +56 -0
- package/dist/resilience/circuit-breaker.d.ts.map +1 -0
- package/dist/resilience/circuit-breaker.js +93 -0
- package/dist/resilience/circuit-breaker.js.map +1 -0
- package/dist/resilience/idempotent.d.ts +61 -0
- package/dist/resilience/idempotent.d.ts.map +1 -0
- package/dist/resilience/idempotent.js +103 -0
- package/dist/resilience/idempotent.js.map +1 -0
- package/dist/resilience/index.d.ts +28 -0
- package/dist/resilience/index.d.ts.map +1 -0
- package/dist/resilience/index.js +25 -0
- package/dist/resilience/index.js.map +1 -0
- package/dist/router/index.d.ts +3 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +2 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/provider-router.d.ts +61 -0
- package/dist/router/provider-router.d.ts.map +1 -0
- package/dist/router/provider-router.js +214 -0
- package/dist/router/provider-router.js.map +1 -0
- package/dist/runs/health.d.ts +24 -0
- package/dist/runs/health.d.ts.map +1 -0
- package/dist/runs/health.js +52 -0
- package/dist/runs/health.js.map +1 -0
- package/dist/runs/index.d.ts +4 -0
- package/dist/runs/index.d.ts.map +1 -0
- package/dist/runs/index.js +4 -0
- package/dist/runs/index.js.map +1 -0
- package/dist/runs/subscribe.d.ts +34 -0
- package/dist/runs/subscribe.d.ts.map +1 -0
- package/dist/runs/subscribe.js +228 -0
- package/dist/runs/subscribe.js.map +1 -0
- package/dist/runs/types.d.ts +53 -0
- package/dist/runs/types.d.ts.map +1 -0
- package/dist/runs/types.js +11 -0
- package/dist/runs/types.js.map +1 -0
- package/dist/safety/immune.d.ts +62 -0
- package/dist/safety/immune.d.ts.map +1 -0
- package/dist/safety/immune.js +109 -0
- package/dist/safety/immune.js.map +1 -0
- package/dist/safety/index.d.ts +3 -0
- package/dist/safety/index.d.ts.map +1 -0
- package/dist/safety/index.js +2 -0
- package/dist/safety/index.js.map +1 -0
- package/dist/safety/sanitize.d.ts +71 -0
- package/dist/safety/sanitize.d.ts.map +1 -0
- package/dist/safety/sanitize.js +139 -0
- package/dist/safety/sanitize.js.map +1 -0
- package/dist/sdk-permission-mapping.d.ts +41 -0
- package/dist/sdk-permission-mapping.d.ts.map +1 -0
- package/dist/sdk-permission-mapping.js +96 -0
- package/dist/sdk-permission-mapping.js.map +1 -0
- package/dist/skills/_otel.d.ts +2 -0
- package/dist/skills/_otel.d.ts.map +1 -0
- package/dist/skills/_otel.js +29 -0
- package/dist/skills/_otel.js.map +1 -0
- package/dist/skills/alpaca-quote.d.ts +30 -0
- package/dist/skills/alpaca-quote.d.ts.map +1 -0
- package/dist/skills/alpaca-quote.js +70 -0
- package/dist/skills/alpaca-quote.js.map +1 -0
- package/dist/skills/base-skills.d.ts +30 -0
- package/dist/skills/base-skills.d.ts.map +1 -0
- package/dist/skills/base-skills.js +26 -0
- package/dist/skills/base-skills.js.map +1 -0
- package/dist/skills/brain-query.d.ts +34 -0
- package/dist/skills/brain-query.d.ts.map +1 -0
- package/dist/skills/brain-query.js +46 -0
- package/dist/skills/brain-query.js.map +1 -0
- package/dist/skills/brain-store.d.ts +44 -0
- package/dist/skills/brain-store.d.ts.map +1 -0
- package/dist/skills/brain-store.js +55 -0
- package/dist/skills/brain-store.js.map +1 -0
- package/dist/skills/calendar-check.d.ts +37 -0
- package/dist/skills/calendar-check.d.ts.map +1 -0
- package/dist/skills/calendar-check.js +87 -0
- package/dist/skills/calendar-check.js.map +1 -0
- package/dist/skills/cboe-vix-spot.d.ts +24 -0
- package/dist/skills/cboe-vix-spot.d.ts.map +1 -0
- package/dist/skills/cboe-vix-spot.js +70 -0
- package/dist/skills/cboe-vix-spot.js.map +1 -0
- package/dist/skills/errors.d.ts +33 -0
- package/dist/skills/errors.d.ts.map +1 -0
- package/dist/skills/errors.js +50 -0
- package/dist/skills/errors.js.map +1 -0
- package/dist/skills/hitl-request.d.ts +39 -0
- package/dist/skills/hitl-request.d.ts.map +1 -0
- package/dist/skills/hitl-request.js +55 -0
- package/dist/skills/hitl-request.js.map +1 -0
- package/dist/skills/http-fetch.d.ts +32 -0
- package/dist/skills/http-fetch.d.ts.map +1 -0
- package/dist/skills/http-fetch.js +82 -0
- package/dist/skills/http-fetch.js.map +1 -0
- package/dist/skills/index.d.ts +46 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +32 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/record-outcome.d.ts +49 -0
- package/dist/skills/record-outcome.d.ts.map +1 -0
- package/dist/skills/record-outcome.js +104 -0
- package/dist/skills/record-outcome.js.map +1 -0
- package/dist/skills/run-sql-query.d.ts +33 -0
- package/dist/skills/run-sql-query.d.ts.map +1 -0
- package/dist/skills/run-sql-query.js +78 -0
- package/dist/skills/run-sql-query.js.map +1 -0
- package/dist/skills/send-email.d.ts +39 -0
- package/dist/skills/send-email.d.ts.map +1 -0
- package/dist/skills/send-email.js +100 -0
- package/dist/skills/send-email.js.map +1 -0
- package/dist/skills/skill-ledger.d.ts +62 -0
- package/dist/skills/skill-ledger.d.ts.map +1 -0
- package/dist/skills/skill-ledger.js +40 -0
- package/dist/skills/skill-ledger.js.map +1 -0
- package/dist/skills/skill-registry-builder.d.ts +91 -0
- package/dist/skills/skill-registry-builder.d.ts.map +1 -0
- package/dist/skills/skill-registry-builder.js +173 -0
- package/dist/skills/skill-registry-builder.js.map +1 -0
- package/dist/skills/slack-notify.d.ts +43 -0
- package/dist/skills/slack-notify.d.ts.map +1 -0
- package/dist/skills/slack-notify.js +70 -0
- package/dist/skills/slack-notify.js.map +1 -0
- package/dist/skills/starknet-balance.d.ts +34 -0
- package/dist/skills/starknet-balance.d.ts.map +1 -0
- package/dist/skills/starknet-balance.js +91 -0
- package/dist/skills/starknet-balance.js.map +1 -0
- package/dist/skills/telegram-notify.d.ts +44 -0
- package/dist/skills/telegram-notify.d.ts.map +1 -0
- package/dist/skills/telegram-notify.js +71 -0
- package/dist/skills/telegram-notify.js.map +1 -0
- package/dist/skills/web-search.d.ts +32 -0
- package/dist/skills/web-search.d.ts.map +1 -0
- package/dist/skills/web-search.js +84 -0
- package/dist/skills/web-search.js.map +1 -0
- package/dist/templates/complex-agent.d.ts +105 -0
- package/dist/templates/complex-agent.d.ts.map +1 -0
- package/dist/templates/complex-agent.js +94 -0
- package/dist/templates/complex-agent.js.map +1 -0
- package/dist/templates/index.d.ts +17 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +14 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/reasoning-agent.d.ts +160 -0
- package/dist/templates/reasoning-agent.d.ts.map +1 -0
- package/dist/templates/reasoning-agent.js +119 -0
- package/dist/templates/reasoning-agent.js.map +1 -0
- package/dist/templates/simple-agent.d.ts +108 -0
- package/dist/templates/simple-agent.d.ts.map +1 -0
- package/dist/templates/simple-agent.js +84 -0
- package/dist/templates/simple-agent.js.map +1 -0
- package/dist/testing/brain-conformance.d.ts +45 -0
- package/dist/testing/brain-conformance.d.ts.map +1 -0
- package/dist/testing/brain-conformance.js +68 -0
- package/dist/testing/brain-conformance.js.map +1 -0
- package/dist/testing/chaos.d.ts +126 -0
- package/dist/testing/chaos.d.ts.map +1 -0
- package/dist/testing/chaos.js +176 -0
- package/dist/testing/chaos.js.map +1 -0
- package/dist/testing/contracts/brain-port.contract.d.ts +23 -0
- package/dist/testing/contracts/brain-port.contract.d.ts.map +1 -0
- package/dist/testing/contracts/brain-port.contract.js +79 -0
- package/dist/testing/contracts/brain-port.contract.js.map +1 -0
- package/dist/testing/contracts/economic-observer.contract.d.ts +23 -0
- package/dist/testing/contracts/economic-observer.contract.d.ts.map +1 -0
- package/dist/testing/contracts/economic-observer.contract.js +71 -0
- package/dist/testing/contracts/economic-observer.contract.js.map +1 -0
- package/dist/testing/contracts/event-bus.contract.d.ts +30 -0
- package/dist/testing/contracts/event-bus.contract.d.ts.map +1 -0
- package/dist/testing/contracts/event-bus.contract.js +216 -0
- package/dist/testing/contracts/event-bus.contract.js.map +1 -0
- package/dist/testing/db-conformance.d.ts +22 -0
- package/dist/testing/db-conformance.d.ts.map +1 -0
- package/dist/testing/db-conformance.js +25 -0
- package/dist/testing/db-conformance.js.map +1 -0
- package/dist/testing/eval.d.ts +61 -0
- package/dist/testing/eval.d.ts.map +1 -0
- package/dist/testing/eval.js +98 -0
- package/dist/testing/eval.js.map +1 -0
- package/dist/testing/index.d.ts +32 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +38 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/integration-harness.d.ts +45 -0
- package/dist/testing/integration-harness.d.ts.map +1 -0
- package/dist/testing/integration-harness.js +57 -0
- package/dist/testing/integration-harness.js.map +1 -0
- package/dist/testing/logger-conformance.d.ts +16 -0
- package/dist/testing/logger-conformance.d.ts.map +1 -0
- package/dist/testing/logger-conformance.js +43 -0
- package/dist/testing/logger-conformance.js.map +1 -0
- package/dist/testing/outcome-conformance.d.ts +17 -0
- package/dist/testing/outcome-conformance.d.ts.map +1 -0
- package/dist/testing/outcome-conformance.js +50 -0
- package/dist/testing/outcome-conformance.js.map +1 -0
- package/dist/testing/runner.d.ts +19 -0
- package/dist/testing/runner.d.ts.map +1 -0
- package/dist/testing/runner.js +9 -0
- package/dist/testing/runner.js.map +1 -0
- package/dist/testing/test-brain-port.d.ts +25 -0
- package/dist/testing/test-brain-port.d.ts.map +1 -0
- package/dist/testing/test-brain-port.js +54 -0
- package/dist/testing/test-brain-port.js.map +1 -0
- package/dist/testing/test-child-agent.d.ts +32 -0
- package/dist/testing/test-child-agent.d.ts.map +1 -0
- package/dist/testing/test-child-agent.js +59 -0
- package/dist/testing/test-child-agent.js.map +1 -0
- package/dist/testing/test-event-bus.d.ts +57 -0
- package/dist/testing/test-event-bus.d.ts.map +1 -0
- package/dist/testing/test-event-bus.js +191 -0
- package/dist/testing/test-event-bus.js.map +1 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +20 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +102 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/types.d.ts +85 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +13 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/zod-to-json-schema.d.ts +11 -0
- package/dist/tools/zod-to-json-schema.d.ts.map +1 -0
- package/dist/tools/zod-to-json-schema.js +92 -0
- package/dist/tools/zod-to-json-schema.js.map +1 -0
- package/dist/trace/canonical.d.ts +37 -0
- package/dist/trace/canonical.d.ts.map +1 -0
- package/dist/trace/canonical.js +139 -0
- package/dist/trace/canonical.js.map +1 -0
- package/dist/trace/policy.d.ts +103 -0
- package/dist/trace/policy.d.ts.map +1 -0
- package/dist/trace/policy.js +137 -0
- package/dist/trace/policy.js.map +1 -0
- package/dist/trace/schema.d.ts +195 -0
- package/dist/trace/schema.d.ts.map +1 -0
- package/dist/trace/schema.js +18 -0
- package/dist/trace/schema.js.map +1 -0
- package/dist/trace/strict-pii-detector.d.ts +28 -0
- package/dist/trace/strict-pii-detector.d.ts.map +1 -0
- package/dist/trace/strict-pii-detector.js +144 -0
- package/dist/trace/strict-pii-detector.js.map +1 -0
- package/dist/tracing/traced-port.d.ts +50 -0
- package/dist/tracing/traced-port.d.ts.map +1 -0
- package/dist/tracing/traced-port.js +108 -0
- package/dist/tracing/traced-port.js.map +1 -0
- package/dist/tracking/agent-run-tracker.d.ts +63 -0
- package/dist/tracking/agent-run-tracker.d.ts.map +1 -0
- package/dist/tracking/agent-run-tracker.js +132 -0
- package/dist/tracking/agent-run-tracker.js.map +1 -0
- package/dist/tracking/gen-ai.d.ts +54 -0
- package/dist/tracking/gen-ai.d.ts.map +1 -0
- package/dist/tracking/gen-ai.js +101 -0
- package/dist/tracking/gen-ai.js.map +1 -0
- package/dist/tracking/index.d.ts +4 -0
- package/dist/tracking/index.d.ts.map +1 -0
- package/dist/tracking/index.js +3 -0
- package/dist/tracking/index.js.map +1 -0
- package/dist/types/agent.d.ts +84 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +13 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/agent.test.d.ts +11 -0
- package/dist/types/agent.test.d.ts.map +1 -0
- package/dist/types/agent.test.js +144 -0
- package/dist/types/agent.test.js.map +1 -0
- package/dist/types/escalation-mapping.d.ts +30 -0
- package/dist/types/escalation-mapping.d.ts.map +1 -0
- package/dist/types/escalation-mapping.js +32 -0
- package/dist/types/escalation-mapping.js.map +1 -0
- package/docs/byom.md +106 -0
- package/docs/contributing.md +139 -0
- package/docs/economy.md +159 -0
- package/docs/getting-started.md +179 -0
- package/docs/index.md +57 -0
- package/docs/migration/0.15-to-0.17.md +227 -0
- package/docs/papers/bon-mav-notes.md +36 -0
- package/docs/patterns.md +138 -0
- package/docs/platforms.md +137 -0
- package/docs/ports/agent-registry.md +100 -0
- package/docs/ports/event-bus.md +131 -0
- package/docs/ports/hitl.md +105 -0
- package/docs/ports/llm-provider.md +125 -0
- package/docs/ports/messaging.md +94 -0
- package/docs/templates.md +165 -0
- package/package.json +160 -0
- package/src/adapters/hitl/memory-state-store.ts +96 -0
- package/src/adapters/hitl/postgres-state-store.ts +147 -0
- package/src/adapters/llm/anthropic-direct.ts +212 -0
- package/src/adapters/llm/cascade.ts +109 -0
- package/src/adapters/llm/litellm.ts +300 -0
- package/src/adapters/messaging/console.ts +73 -0
- package/src/adapters/messaging/discord.ts +125 -0
- package/src/adapters/messaging/mcp.ts +84 -0
- package/src/adapters/messaging/slack.ts +109 -0
- package/src/adapters/messaging/telegram.ts +134 -0
- package/src/adapters/registry/memory.ts +84 -0
- package/src/adapters/registry/postgres.ts +166 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/trading.ts +114 -0
- package/src/auth/errors.ts +66 -0
- package/src/auth/nonce-store.ts +79 -0
- package/src/auth/sign-event.ts +51 -0
- package/src/auth/verify-event.ts +112 -0
- package/src/boot/init-sdk.ts +92 -0
- package/src/boot/load-agent-context.ts +164 -0
- package/src/boot/load-recent-memory.ts +92 -0
- package/src/budget/budget-state.ts +234 -0
- package/src/budget/index.ts +11 -0
- package/src/clients/agents.ts +140 -0
- package/src/clients/index.ts +6 -0
- package/src/clients/messaging-adapters.ts +173 -0
- package/src/clients/pipelines.ts +160 -0
- package/src/compute/strategies/best-of-n.ts +162 -0
- package/src/compute/strategies/bon-mav.ts +221 -0
- package/src/compute/strategies/single-shot.ts +45 -0
- package/src/compute/types.ts +36 -0
- package/src/compute/verifier.ts +84 -0
- package/src/compute/with-compute.ts +108 -0
- package/src/constitution/axioms.ts +548 -0
- package/src/constitution/gate.ts +180 -0
- package/src/constitution/index.ts +53 -0
- package/src/constitution/scorer.ts +170 -0
- package/src/constitution/signal.ts +114 -0
- package/src/constitution/types.ts +195 -0
- package/src/counterfactual/index.ts +20 -0
- package/src/counterfactual/replay-with-alt.ts +357 -0
- package/src/dataops/index.ts +4 -0
- package/src/dataops/starkscan.ts +13 -0
- package/src/dataops/voyager.ts +215 -0
- package/src/deprecation.ts +102 -0
- package/src/durable/bullmq-runner.ts +560 -0
- package/src/durable/index.ts +11 -0
- package/src/economy/circuit-breaker.ts +130 -0
- package/src/economy/economy-router.ts +242 -0
- package/src/economy/index.ts +28 -0
- package/src/economy/outcome-tracker.ts +228 -0
- package/src/economy/router.ts +246 -0
- package/src/economy/tier-policy.ts +116 -0
- package/src/errors.ts +159 -0
- package/src/evals/datasets/index.ts +343 -0
- package/src/evals/harness.ts +171 -0
- package/src/evals/index.ts +4 -0
- package/src/factory/agent-factory.ts +261 -0
- package/src/hitl/api.ts +78 -0
- package/src/hitl/approval-channel.ts +128 -0
- package/src/hitl/callback-handlers.ts +61 -0
- package/src/hitl/index.ts +9 -0
- package/src/hitl/slack.ts +358 -0
- package/src/hitl/telegram.ts +342 -0
- package/src/index.ts +710 -0
- package/src/llm/parse-structured-output.ts +116 -0
- package/src/loop/index.ts +26 -0
- package/src/loop/minimal-loop.ts +448 -0
- package/src/loop/sdk-loop.ts +505 -0
- package/src/mcp/index.ts +146 -0
- package/src/metrics/create-agent-metrics.ts +231 -0
- package/src/orchestration/bulkhead.ts +145 -0
- package/src/orchestration/idempotency.ts +137 -0
- package/src/orchestration/index.ts +24 -0
- package/src/orchestration/ooda/agent-config-loader.ts +118 -0
- package/src/orchestration/ooda/agent.ts +1009 -0
- package/src/orchestration/ooda/audit-log.ts +57 -0
- package/src/orchestration/ooda/brain-context.ts +269 -0
- package/src/orchestration/ooda/child-agent.ts +60 -0
- package/src/orchestration/ooda/cron-schedule.ts +115 -0
- package/src/orchestration/ooda/debate.ts +100 -0
- package/src/orchestration/ooda/economic-observer.ts +77 -0
- package/src/orchestration/ooda/errors.ts +32 -0
- package/src/orchestration/ooda/execution-mode-guard.ts +37 -0
- package/src/orchestration/ooda/factory.ts +48 -0
- package/src/orchestration/ooda/guardrails.ts +172 -0
- package/src/orchestration/ooda/guards/always-on.ts +21 -0
- package/src/orchestration/ooda/guards/business-hours.ts +134 -0
- package/src/orchestration/ooda/guards/cme-holidays-2026.json +1 -0
- package/src/orchestration/ooda/guards/index.ts +27 -0
- package/src/orchestration/ooda/guards/redis-circuit-breaker.ts +172 -0
- package/src/orchestration/ooda/guards/rth-session.ts +133 -0
- package/src/orchestration/ooda/handoff.ts +150 -0
- package/src/orchestration/ooda/hitl-gate.ts +166 -0
- package/src/orchestration/ooda/index.ts +163 -0
- package/src/orchestration/ooda/inner-monologue.ts +99 -0
- package/src/orchestration/ooda/learn.ts +146 -0
- package/src/orchestration/ooda/multimodal.ts +174 -0
- package/src/orchestration/ooda/phase-routing.ts +74 -0
- package/src/orchestration/ooda/plan-execute.ts +87 -0
- package/src/orchestration/ooda/react-loop.ts +192 -0
- package/src/orchestration/ooda/reflexion.ts +98 -0
- package/src/orchestration/ooda/resource-limits.ts +123 -0
- package/src/orchestration/ooda/run-step-persistence.ts +137 -0
- package/src/orchestration/ooda/skills.ts +60 -0
- package/src/orchestration/ooda/structured-output.ts +93 -0
- package/src/orchestration/ooda/types.ts +508 -0
- package/src/otel/attributes.ts +104 -0
- package/src/otel/index.ts +4 -0
- package/src/otel/ingest.ts +294 -0
- package/src/otel/trace-context.ts +197 -0
- package/src/otel/types.ts +49 -0
- package/src/outcomes/client.ts +194 -0
- package/src/outcomes/compute-roi.ts +89 -0
- package/src/outcomes/index.ts +3 -0
- package/src/outcomes/meter.ts +217 -0
- package/src/outcomes/trajectory.ts +170 -0
- package/src/outcomes/types.ts +88 -0
- package/src/patterns/_shared/brain-logger.ts +18 -0
- package/src/patterns/circuit-breaker/index.ts +8 -0
- package/src/patterns/circuit-breaker/session-cb.ts +198 -0
- package/src/patterns/circuit-breaker/types.ts +72 -0
- package/src/patterns/escalation/index.ts +8 -0
- package/src/patterns/escalation/pyramid.ts +125 -0
- package/src/patterns/escalation/types.ts +62 -0
- package/src/patterns/quality-gate/gate.ts +102 -0
- package/src/patterns/quality-gate/index.ts +8 -0
- package/src/patterns/quality-gate/types.ts +45 -0
- package/src/permissions/capability-gate.ts +63 -0
- package/src/permissions/index.ts +11 -0
- package/src/permissions/renewal-manager.ts +89 -0
- package/src/permissions/sdk-permissions.ts +124 -0
- package/src/ports/agent-registry.ts +104 -0
- package/src/ports/brain.ts +255 -0
- package/src/ports/db.ts +7 -0
- package/src/ports/event-bus.ts +199 -0
- package/src/ports/eviction-policy.ts +179 -0
- package/src/ports/hitl.contract.test.ts +131 -0
- package/src/ports/hitl.ts +153 -0
- package/src/ports/index.ts +48 -0
- package/src/ports/key-provider.ts +179 -0
- package/src/ports/llm-provider.contract.ts +132 -0
- package/src/ports/llm-provider.ts +68 -0
- package/src/ports/logger.ts +23 -0
- package/src/ports/messaging.contract.test.ts +422 -0
- package/src/ports/messaging.ts +53 -0
- package/src/ports/outcome.ts +26 -0
- package/src/ports/timestamp.ts +64 -0
- package/src/privacy/channel.ts +283 -0
- package/src/privacy/composition.ts +289 -0
- package/src/privacy/delegation.ts +128 -0
- package/src/privacy/index.ts +64 -0
- package/src/privacy/nullifier.ts +79 -0
- package/src/privacy/poseidon-felt252.ts +104 -0
- package/src/privacy/uar.ts +234 -0
- package/src/prompts/build-orient-prompt.ts +78 -0
- package/src/proof/chain.ts +249 -0
- package/src/proof/fallback-adapter.ts +117 -0
- package/src/proof/index.ts +207 -0
- package/src/proof/load.ts +61 -0
- package/src/proof/otel.ts +74 -0
- package/src/proof/receipt-queue.ts +235 -0
- package/src/proof/sha256.ts +80 -0
- package/src/proof/types.ts +58 -0
- package/src/proof/verify.ts +89 -0
- package/src/registry/agent-capability.ts +48 -0
- package/src/registry/agent-card.ts +162 -0
- package/src/registry/agent-ids.ts +56 -0
- package/src/registry/agent-registry.ts +378 -0
- package/src/registry/index.ts +23 -0
- package/src/replay/clock.ts +104 -0
- package/src/replay/cross-cycle.ts +406 -0
- package/src/replay/http-vcr.ts +123 -0
- package/src/replay/index.ts +62 -0
- package/src/replay/llm-cache.ts +199 -0
- package/src/replay/random.ts +249 -0
- package/src/replay/replay.ts +271 -0
- package/src/resilience/bulkhead.ts +95 -0
- package/src/resilience/circuit-breaker.ts +129 -0
- package/src/resilience/idempotent.ts +126 -0
- package/src/resilience/index.ts +51 -0
- package/src/router/index.ts +11 -0
- package/src/router/provider-router.ts +319 -0
- package/src/runs/health.ts +84 -0
- package/src/runs/index.ts +3 -0
- package/src/runs/subscribe.ts +263 -0
- package/src/runs/types.ts +63 -0
- package/src/safety/immune.ts +145 -0
- package/src/safety/index.ts +6 -0
- package/src/safety/sanitize.ts +183 -0
- package/src/sdk-permission-mapping.ts +123 -0
- package/src/skills/_otel.ts +31 -0
- package/src/skills/alpaca-quote.ts +82 -0
- package/src/skills/base-skills.ts +38 -0
- package/src/skills/brain-query.ts +62 -0
- package/src/skills/brain-store.ts +69 -0
- package/src/skills/calendar-check.ts +111 -0
- package/src/skills/cboe-vix-spot.ts +89 -0
- package/src/skills/errors.ts +59 -0
- package/src/skills/hitl-request.ts +68 -0
- package/src/skills/http-fetch.ts +92 -0
- package/src/skills/index.ts +71 -0
- package/src/skills/record-outcome.ts +125 -0
- package/src/skills/run-sql-query.ts +87 -0
- package/src/skills/send-email.ts +111 -0
- package/src/skills/skill-ledger.ts +92 -0
- package/src/skills/skill-registry-builder.ts +264 -0
- package/src/skills/slack-notify.ts +90 -0
- package/src/skills/starknet-balance.ts +106 -0
- package/src/skills/telegram-notify.ts +88 -0
- package/src/skills/web-search.ts +108 -0
- package/src/templates/complex-agent.ts +187 -0
- package/src/templates/index.ts +27 -0
- package/src/templates/reasoning-agent.ts +251 -0
- package/src/templates/simple-agent.ts +173 -0
- package/src/testing/brain-conformance.ts +105 -0
- package/src/testing/chaos.ts +266 -0
- package/src/testing/contracts/brain-port.contract.ts +91 -0
- package/src/testing/contracts/economic-observer.contract.ts +87 -0
- package/src/testing/contracts/event-bus.contract.ts +324 -0
- package/src/testing/db-conformance.ts +43 -0
- package/src/testing/eval.ts +161 -0
- package/src/testing/index.ts +59 -0
- package/src/testing/integration-harness.ts +75 -0
- package/src/testing/logger-conformance.ts +57 -0
- package/src/testing/outcome-conformance.ts +62 -0
- package/src/testing/runner.ts +19 -0
- package/src/testing/test-brain-port.ts +69 -0
- package/src/testing/test-child-agent.ts +70 -0
- package/src/testing/test-event-bus.ts +247 -0
- package/src/tools/index.ts +11 -0
- package/src/tools/registry.ts +122 -0
- package/src/tools/types.ts +114 -0
- package/src/tools/zod-to-json-schema.ts +112 -0
- package/src/trace/canonical.ts +158 -0
- package/src/trace/policy.ts +242 -0
- package/src/trace/schema.ts +245 -0
- package/src/trace/strict-pii-detector.ts +156 -0
- package/src/tracing/traced-port.ts +149 -0
- package/src/tracking/agent-run-tracker.ts +228 -0
- package/src/tracking/gen-ai.ts +153 -0
- package/src/tracking/index.ts +19 -0
- package/src/types/agent.ts +93 -0
- package/src/types/escalation-mapping.ts +48 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HITL Slack adapter — Block Kit approval messages + HMAC-verified callback handler.
|
|
3
|
+
*
|
|
4
|
+
* Plan v6 §1.7: channels are transports; state lives in HITLPort (Postgres).
|
|
5
|
+
* HMAC-SHA256 verification uses Slack signing secret (replay window: 5 min).
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
11
|
+
import type { HITLPort, HITLRequest } from "../ports/hitl.js";
|
|
12
|
+
|
|
13
|
+
// ─── Config ──────────────────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
/** Slack channel config — webhook URL only (no bot token). */
|
|
16
|
+
export interface SlackChannelConfig {
|
|
17
|
+
/** Slack Incoming Webhook URL. Never hardcoded — pass at runtime. */
|
|
18
|
+
webhookUrl: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ─── Send approval request ───────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
export interface SendHITLSlackOpts {
|
|
24
|
+
channel: SlackChannelConfig;
|
|
25
|
+
hitlPort: HITLPort;
|
|
26
|
+
request: HITLRequest;
|
|
27
|
+
/** Optional cost in USD for the Block Kit display. */
|
|
28
|
+
costDisplayUsd?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface SlackApprovalResult {
|
|
32
|
+
approvalId: string;
|
|
33
|
+
messageTs: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const MAX_PAYLOAD_PREVIEW_BYTES = 1500;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Record a new HITL approval request and post a Block Kit message to Slack.
|
|
40
|
+
* Returns the approvalId (=request.id) and the Slack message timestamp.
|
|
41
|
+
*/
|
|
42
|
+
export async function sendHITLApprovalRequestSlack(
|
|
43
|
+
opts: SendHITLSlackOpts
|
|
44
|
+
): Promise<SlackApprovalResult> {
|
|
45
|
+
const { channel, hitlPort, request, costDisplayUsd } = opts;
|
|
46
|
+
|
|
47
|
+
// Register in HITLPort state machine (pending)
|
|
48
|
+
const approvalId = await hitlPort.request(request);
|
|
49
|
+
|
|
50
|
+
const costDisplay =
|
|
51
|
+
costDisplayUsd != null ? `$${costDisplayUsd.toFixed(2)}` : "unknown";
|
|
52
|
+
const payloadSummary = summarizePayload(request.context);
|
|
53
|
+
|
|
54
|
+
const blocks = buildBlockKit({
|
|
55
|
+
agentSource: request.agentSource,
|
|
56
|
+
question: request.question,
|
|
57
|
+
approvalId,
|
|
58
|
+
costDisplay,
|
|
59
|
+
payloadSummary,
|
|
60
|
+
deadline: request.deadline,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const response = await fetch(channel.webhookUrl, {
|
|
64
|
+
method: "POST",
|
|
65
|
+
headers: { "Content-Type": "application/json" },
|
|
66
|
+
body: JSON.stringify({ blocks }),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
const body = await response.text().catch(() => "<read error>");
|
|
71
|
+
throw new Error(
|
|
72
|
+
`[hitl-slack] Slack webhook returned ${response.status}: ${body.slice(
|
|
73
|
+
0,
|
|
74
|
+
300
|
|
75
|
+
)}`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Incoming webhooks don't return a timestamp — use ISO time as placeholder
|
|
80
|
+
const messageTs = String(Date.now());
|
|
81
|
+
return { approvalId, messageTs };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ─── Block Kit builder ───────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
interface BlockKitOpts {
|
|
87
|
+
agentSource: string;
|
|
88
|
+
question: string;
|
|
89
|
+
approvalId: string;
|
|
90
|
+
costDisplay: string;
|
|
91
|
+
payloadSummary: string;
|
|
92
|
+
deadline: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Build a Slack Block Kit structure for HITL approval.
|
|
97
|
+
* Exported for snapshot testing.
|
|
98
|
+
*/
|
|
99
|
+
export function buildBlockKit(opts: BlockKitOpts): unknown[] {
|
|
100
|
+
const {
|
|
101
|
+
agentSource,
|
|
102
|
+
question,
|
|
103
|
+
approvalId,
|
|
104
|
+
costDisplay,
|
|
105
|
+
payloadSummary,
|
|
106
|
+
deadline,
|
|
107
|
+
} = opts;
|
|
108
|
+
|
|
109
|
+
return [
|
|
110
|
+
{
|
|
111
|
+
type: "header",
|
|
112
|
+
text: {
|
|
113
|
+
type: "plain_text",
|
|
114
|
+
text: `:shield: HITL Approval Required — ${agentSource}`,
|
|
115
|
+
emoji: true,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: "section",
|
|
120
|
+
fields: [
|
|
121
|
+
{ type: "mrkdwn", text: `*Agent:*\n${agentSource}` },
|
|
122
|
+
{ type: "mrkdwn", text: `*Question:*\n${question}` },
|
|
123
|
+
{ type: "mrkdwn", text: `*Cost:*\n${costDisplay}` },
|
|
124
|
+
{ type: "mrkdwn", text: `*Deadline:*\n\`${deadline}\`` },
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
type: "section",
|
|
129
|
+
text: {
|
|
130
|
+
type: "mrkdwn",
|
|
131
|
+
text: `*Context:*\n\`\`\`${payloadSummary}\`\`\``,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
type: "context",
|
|
136
|
+
elements: [
|
|
137
|
+
{
|
|
138
|
+
type: "mrkdwn",
|
|
139
|
+
text: `:clock1: ${new Date().toISOString()} · Approval ID: \`${truncate(
|
|
140
|
+
approvalId,
|
|
141
|
+
8
|
|
142
|
+
)}\``,
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
type: "actions",
|
|
148
|
+
block_id: `hitl_${approvalId.slice(0, 8)}`,
|
|
149
|
+
elements: [
|
|
150
|
+
{
|
|
151
|
+
type: "button",
|
|
152
|
+
text: {
|
|
153
|
+
type: "plain_text",
|
|
154
|
+
text: ":white_check_mark: Approve",
|
|
155
|
+
emoji: true,
|
|
156
|
+
},
|
|
157
|
+
style: "primary",
|
|
158
|
+
value: JSON.stringify({ approval_id: approvalId, action: "approve" }),
|
|
159
|
+
action_id: "hitl_approve",
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
type: "button",
|
|
163
|
+
text: { type: "plain_text", text: ":x: Reject", emoji: true },
|
|
164
|
+
style: "danger",
|
|
165
|
+
value: JSON.stringify({ approval_id: approvalId, action: "reject" }),
|
|
166
|
+
action_id: "hitl_reject",
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ─── Callback handler ────────────────────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
export interface SlackCallbackHandlerOpts {
|
|
176
|
+
hitlPort: HITLPort;
|
|
177
|
+
/** Slack signing secret. Never hardcoded — pass at runtime. */
|
|
178
|
+
signingSecret: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Raw HTTP request shape — agnostic of HTTP framework. */
|
|
182
|
+
export interface RawRequest {
|
|
183
|
+
rawBody: string;
|
|
184
|
+
headers: Record<string, string | string[] | undefined>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface HandlerResult {
|
|
188
|
+
status: number;
|
|
189
|
+
body: unknown;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Create a Slack interactive-payload callback handler.
|
|
194
|
+
*
|
|
195
|
+
* Wire to: POST /slack/interactive
|
|
196
|
+
* Verifies HMAC-SHA256 signature, parses payload, calls hitlPort.resolve().
|
|
197
|
+
* Idempotent: duplicate payloads for the same approvalId are silently ignored
|
|
198
|
+
* (HITLPort throws InvalidStateTransitionError on non-pending → we swallow it).
|
|
199
|
+
*/
|
|
200
|
+
export function createSlackCallbackHandler(
|
|
201
|
+
opts: SlackCallbackHandlerOpts
|
|
202
|
+
): (req: RawRequest) => Promise<HandlerResult> {
|
|
203
|
+
const { hitlPort, signingSecret } = opts;
|
|
204
|
+
|
|
205
|
+
return async (req: RawRequest): Promise<HandlerResult> => {
|
|
206
|
+
const timestamp = headerString(req.headers["x-slack-request-timestamp"]);
|
|
207
|
+
const signature = headerString(req.headers["x-slack-signature"]);
|
|
208
|
+
|
|
209
|
+
if (
|
|
210
|
+
!verifySlackSignature(req.rawBody, timestamp, signature, signingSecret)
|
|
211
|
+
) {
|
|
212
|
+
return { status: 401, body: { ok: false, error: "invalid signature" } };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Slack wraps the JSON payload in a form-encoded "payload" field
|
|
216
|
+
const parsed = parseFormEncoded(req.rawBody);
|
|
217
|
+
const wrapped = parsed["payload"];
|
|
218
|
+
if (!wrapped) {
|
|
219
|
+
return {
|
|
220
|
+
status: 400,
|
|
221
|
+
body: { ok: false, error: "missing payload field" },
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
let interaction: { actions?: Array<{ value?: string }> };
|
|
226
|
+
try {
|
|
227
|
+
interaction = JSON.parse(wrapped) as typeof interaction;
|
|
228
|
+
} catch {
|
|
229
|
+
return { status: 400, body: { ok: false, error: "invalid JSON" } };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const actionBlock = interaction.actions?.[0];
|
|
233
|
+
if (!actionBlock?.value) {
|
|
234
|
+
return {
|
|
235
|
+
status: 400,
|
|
236
|
+
body: { ok: false, error: "no action value" },
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const buttonVal = parseButtonValue(actionBlock.value);
|
|
241
|
+
if (!buttonVal) {
|
|
242
|
+
return {
|
|
243
|
+
status: 400,
|
|
244
|
+
body: { ok: false, error: "invalid button value" },
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const { approvalId, action } = buttonVal;
|
|
249
|
+
const decision = action === "approve" ? "approved" : "rejected";
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
await hitlPort.resolve(approvalId, decision, "slack");
|
|
253
|
+
} catch (err) {
|
|
254
|
+
// Idempotence: already resolved → silently accept
|
|
255
|
+
if (
|
|
256
|
+
err instanceof Error &&
|
|
257
|
+
(err.name === "InvalidStateTransitionError" ||
|
|
258
|
+
err.name === "HITLNotFoundError")
|
|
259
|
+
) {
|
|
260
|
+
return {
|
|
261
|
+
status: 200,
|
|
262
|
+
body: { ok: true, note: "already resolved" },
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
throw err;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
status: 200,
|
|
270
|
+
body: { text: `Action ${action}d for ${approvalId}` },
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ─── HMAC verification ───────────────────────────────────────────────────────
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Verify the X-Slack-Signature header using HMAC-SHA256.
|
|
279
|
+
* Signature format: `v0=<hex>` over `v0:{timestamp}:{rawBody}`.
|
|
280
|
+
* Rejects timestamps older than 5 minutes (replay protection).
|
|
281
|
+
*
|
|
282
|
+
* @public — exported for unit tests
|
|
283
|
+
*/
|
|
284
|
+
export function verifySlackSignature(
|
|
285
|
+
rawBody: string,
|
|
286
|
+
timestamp: string,
|
|
287
|
+
signature: string,
|
|
288
|
+
secret: string
|
|
289
|
+
): boolean {
|
|
290
|
+
if (!timestamp || !signature) return false;
|
|
291
|
+
|
|
292
|
+
const age = Math.abs(Date.now() / 1000 - Number(timestamp));
|
|
293
|
+
if (Number.isNaN(age) || age > 300) return false;
|
|
294
|
+
|
|
295
|
+
const base = `v0:${timestamp}:${rawBody}`;
|
|
296
|
+
const computed = `v0=${createHmac("sha256", secret)
|
|
297
|
+
.update(base)
|
|
298
|
+
.digest("hex")}`;
|
|
299
|
+
|
|
300
|
+
try {
|
|
301
|
+
return timingSafeEqual(
|
|
302
|
+
Buffer.from(computed, "utf-8"),
|
|
303
|
+
Buffer.from(signature, "utf-8")
|
|
304
|
+
);
|
|
305
|
+
} catch {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ─── Private helpers ─────────────────────────────────────────────────────────
|
|
311
|
+
|
|
312
|
+
function parseButtonValue(
|
|
313
|
+
value: string
|
|
314
|
+
): { approvalId: string; action: "approve" | "reject" } | null {
|
|
315
|
+
try {
|
|
316
|
+
const parsed = JSON.parse(value) as {
|
|
317
|
+
approval_id?: unknown;
|
|
318
|
+
action?: unknown;
|
|
319
|
+
};
|
|
320
|
+
if (
|
|
321
|
+
typeof parsed.approval_id === "string" &&
|
|
322
|
+
parsed.approval_id.length > 0 &&
|
|
323
|
+
(parsed.action === "approve" || parsed.action === "reject")
|
|
324
|
+
) {
|
|
325
|
+
return { approvalId: parsed.approval_id, action: parsed.action };
|
|
326
|
+
}
|
|
327
|
+
return null;
|
|
328
|
+
} catch {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function parseFormEncoded(body: string): Record<string, string> {
|
|
334
|
+
const result: Record<string, string> = {};
|
|
335
|
+
for (const pair of body.split("&")) {
|
|
336
|
+
const idx = pair.indexOf("=");
|
|
337
|
+
if (idx === -1) continue;
|
|
338
|
+
const key = decodeURIComponent(pair.slice(0, idx).replace(/\+/g, " "));
|
|
339
|
+
const val = decodeURIComponent(pair.slice(idx + 1).replace(/\+/g, " "));
|
|
340
|
+
result[key] = val;
|
|
341
|
+
}
|
|
342
|
+
return result;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function headerString(h: string | string[] | undefined): string {
|
|
346
|
+
if (!h) return "";
|
|
347
|
+
return Array.isArray(h) ? h[0] ?? "" : h;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function summarizePayload(payload: Record<string, unknown>): string {
|
|
351
|
+
const raw = JSON.stringify(payload, null, 2);
|
|
352
|
+
if (Buffer.byteLength(raw, "utf-8") <= MAX_PAYLOAD_PREVIEW_BYTES) return raw;
|
|
353
|
+
return `${raw.slice(0, MAX_PAYLOAD_PREVIEW_BYTES - 50)}\n... [truncated]`;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function truncate(s: string, maxLen: number): string {
|
|
357
|
+
return s.length <= maxLen ? s : `${s.slice(0, maxLen)}…`;
|
|
358
|
+
}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HITL Telegram adapter — inline keyboard approval messages + HMAC-verified callback handler.
|
|
3
|
+
*
|
|
4
|
+
* Plan v6 §1.7: channels are transports; state lives in HITLPort (Postgres).
|
|
5
|
+
* Callback_data uses compact keys (a/v) to stay within Telegram's 64-byte limit.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
11
|
+
import type { HITLPort, HITLRequest } from "../ports/hitl.js";
|
|
12
|
+
|
|
13
|
+
// ─── Config ──────────────────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
/** Telegram channel config. */
|
|
16
|
+
export interface TelegramChannelConfig {
|
|
17
|
+
/** Telegram Bot API token. Never hardcoded — pass at runtime. */
|
|
18
|
+
botToken: string;
|
|
19
|
+
/** Target chat ID (string or negative number for groups). */
|
|
20
|
+
chatId: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ─── Send approval request ───────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
export interface SendHITLTelegramOpts {
|
|
26
|
+
channel: TelegramChannelConfig;
|
|
27
|
+
hitlPort: HITLPort;
|
|
28
|
+
request: HITLRequest;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TelegramApprovalResult {
|
|
32
|
+
approvalId: string;
|
|
33
|
+
messageId: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const MAX_PAYLOAD_PREVIEW_BYTES = 1500;
|
|
37
|
+
const TELEGRAM_API_BASE = "https://api.telegram.org";
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Record a new HITL approval request and send an inline-keyboard message via Telegram.
|
|
41
|
+
* Returns the approvalId (=request.id) and the Telegram message_id.
|
|
42
|
+
*/
|
|
43
|
+
export async function sendHITLApprovalRequestTelegram(
|
|
44
|
+
opts: SendHITLTelegramOpts
|
|
45
|
+
): Promise<TelegramApprovalResult> {
|
|
46
|
+
const { channel, hitlPort, request } = opts;
|
|
47
|
+
|
|
48
|
+
// Register in HITLPort state machine (pending)
|
|
49
|
+
const approvalId = await hitlPort.request(request);
|
|
50
|
+
|
|
51
|
+
const payloadSummary = summarizePayload(request.context);
|
|
52
|
+
const text = buildTelegramText({
|
|
53
|
+
agentSource: request.agentSource,
|
|
54
|
+
question: request.question,
|
|
55
|
+
approvalId,
|
|
56
|
+
payloadSummary,
|
|
57
|
+
deadline: request.deadline,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Compact keys: "a" = approval_id, "v" = action (stays within 64 bytes for short UUIDs)
|
|
61
|
+
const makeButton = (label: string, action: string) => ({
|
|
62
|
+
text: label,
|
|
63
|
+
callback_data: JSON.stringify({ a: approvalId, v: action }),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const body = {
|
|
67
|
+
chat_id: channel.chatId,
|
|
68
|
+
text,
|
|
69
|
+
parse_mode: "MarkdownV2",
|
|
70
|
+
reply_markup: {
|
|
71
|
+
inline_keyboard: [
|
|
72
|
+
[
|
|
73
|
+
makeButton("✅ Approve", "approve"),
|
|
74
|
+
makeButton("❌ Reject", "reject"),
|
|
75
|
+
],
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const url = `${TELEGRAM_API_BASE}/bot${channel.botToken}/sendMessage`;
|
|
81
|
+
const response = await fetch(url, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: { "Content-Type": "application/json" },
|
|
84
|
+
body: JSON.stringify(body),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
const errBody = await response.text().catch(() => "<read error>");
|
|
89
|
+
throw new Error(
|
|
90
|
+
`[hitl-telegram] Telegram API returned ${
|
|
91
|
+
response.status
|
|
92
|
+
}: ${errBody.slice(0, 300)}`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const result = (await response.json()) as {
|
|
97
|
+
ok: boolean;
|
|
98
|
+
result?: { message_id: number };
|
|
99
|
+
description?: string;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
if (!result.ok || !result.result) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`[hitl-telegram] Telegram API error: ${result.description ?? "unknown"}`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return { approvalId, messageId: result.result.message_id };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ─── Text builder ─────────────────────────────────────────────────────────────
|
|
112
|
+
|
|
113
|
+
interface TelegramTextOpts {
|
|
114
|
+
agentSource: string;
|
|
115
|
+
question: string;
|
|
116
|
+
approvalId: string;
|
|
117
|
+
payloadSummary: string;
|
|
118
|
+
deadline: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Build the MarkdownV2 message text for a HITL approval request.
|
|
123
|
+
* Exported for snapshot testing.
|
|
124
|
+
*/
|
|
125
|
+
export function buildTelegramText(opts: TelegramTextOpts): string {
|
|
126
|
+
const { agentSource, question, approvalId, payloadSummary, deadline } = opts;
|
|
127
|
+
return [
|
|
128
|
+
`\u{1F6E1} *HITL Approval Required — ${escapeMd(agentSource)}*`,
|
|
129
|
+
"",
|
|
130
|
+
`*Agent:* ${escapeMd(agentSource)}`,
|
|
131
|
+
`*Question:* ${escapeMd(question)}`,
|
|
132
|
+
`*Deadline:* \`${escapeMd(deadline)}\``,
|
|
133
|
+
"",
|
|
134
|
+
`*Context:*`,
|
|
135
|
+
"```",
|
|
136
|
+
escapeCodeBlock(payloadSummary.slice(0, 3000)),
|
|
137
|
+
"```",
|
|
138
|
+
"",
|
|
139
|
+
`_${escapeMd(new Date().toISOString())} · ${escapeMd(
|
|
140
|
+
approvalId.slice(0, 8)
|
|
141
|
+
)}_`,
|
|
142
|
+
].join("\n");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ─── Callback handler ────────────────────────────────────────────────────────
|
|
146
|
+
|
|
147
|
+
export interface TelegramCallbackHandlerOpts {
|
|
148
|
+
hitlPort: HITLPort;
|
|
149
|
+
/** Telegram bot token — used to answer the callback query (removes loading spinner). */
|
|
150
|
+
botToken: string;
|
|
151
|
+
/** Optional HMAC secret for validating x-telegram-hmac-sha256 header. */
|
|
152
|
+
callbackSecret?: string;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface HandlerResult {
|
|
156
|
+
status: number;
|
|
157
|
+
body: unknown;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Create a Telegram webhook callback handler.
|
|
162
|
+
*
|
|
163
|
+
* Validates optional HMAC signature, extracts callback_data (compact a/v format),
|
|
164
|
+
* calls hitlPort.resolve(), then answers the Telegram callback query.
|
|
165
|
+
* Idempotent: duplicate callbacks for an already-resolved request are silently ignored.
|
|
166
|
+
*/
|
|
167
|
+
export function createTelegramCallbackHandler(
|
|
168
|
+
opts: TelegramCallbackHandlerOpts
|
|
169
|
+
): (
|
|
170
|
+
rawBody: string,
|
|
171
|
+
headers: Record<string, string>
|
|
172
|
+
) => Promise<HandlerResult> {
|
|
173
|
+
const { hitlPort, botToken, callbackSecret } = opts;
|
|
174
|
+
|
|
175
|
+
return async (
|
|
176
|
+
rawBody: string,
|
|
177
|
+
headers: Record<string, string>
|
|
178
|
+
): Promise<HandlerResult> => {
|
|
179
|
+
let payload: Record<string, unknown>;
|
|
180
|
+
try {
|
|
181
|
+
payload = JSON.parse(rawBody) as Record<string, unknown>;
|
|
182
|
+
} catch {
|
|
183
|
+
return { status: 400, body: { ok: false, error: "invalid json" } };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Optional HMAC signature check
|
|
187
|
+
if (callbackSecret) {
|
|
188
|
+
const sig = headers["x-telegram-hmac-sha256"];
|
|
189
|
+
if (!sig) {
|
|
190
|
+
return { status: 401, body: { ok: false, error: "missing signature" } };
|
|
191
|
+
}
|
|
192
|
+
if (!verifyTelegramSignature(rawBody, sig, callbackSecret)) {
|
|
193
|
+
return {
|
|
194
|
+
status: 401,
|
|
195
|
+
body: { ok: false, error: "invalid signature" },
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Only handle callback_query updates (button clicks)
|
|
201
|
+
const callbackQuery = payload["callback_query"] as
|
|
202
|
+
| Record<string, unknown>
|
|
203
|
+
| undefined;
|
|
204
|
+
if (!callbackQuery?.data) {
|
|
205
|
+
return { status: 200, body: { ok: true } };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let callbackData: {
|
|
209
|
+
a?: unknown;
|
|
210
|
+
v?: unknown;
|
|
211
|
+
approval_id?: unknown;
|
|
212
|
+
action?: unknown;
|
|
213
|
+
};
|
|
214
|
+
try {
|
|
215
|
+
callbackData = JSON.parse(
|
|
216
|
+
callbackQuery.data as string
|
|
217
|
+
) as typeof callbackData;
|
|
218
|
+
} catch {
|
|
219
|
+
return {
|
|
220
|
+
status: 400,
|
|
221
|
+
body: { ok: false, error: "invalid callback_data" },
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Support compact (a/v) and legacy (approval_id/action) formats
|
|
226
|
+
const approvalId = String(callbackData.a ?? callbackData.approval_id ?? "");
|
|
227
|
+
const actionRaw = String(callbackData.v ?? callbackData.action ?? "");
|
|
228
|
+
|
|
229
|
+
if (!approvalId || !actionRaw) {
|
|
230
|
+
return {
|
|
231
|
+
status: 400,
|
|
232
|
+
body: { ok: false, error: "missing approval_id or action" },
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const decision = actionRaw === "approve" ? "approved" : "rejected";
|
|
237
|
+
|
|
238
|
+
let resolved = true;
|
|
239
|
+
try {
|
|
240
|
+
await hitlPort.resolve(approvalId, decision, "telegram");
|
|
241
|
+
} catch (err) {
|
|
242
|
+
if (
|
|
243
|
+
err instanceof Error &&
|
|
244
|
+
(err.name === "InvalidStateTransitionError" ||
|
|
245
|
+
err.name === "HITLNotFoundError")
|
|
246
|
+
) {
|
|
247
|
+
resolved = false;
|
|
248
|
+
} else {
|
|
249
|
+
throw err;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Answer the callback query (removes Telegram's loading spinner)
|
|
254
|
+
const callbackQueryId = String(callbackQuery.id ?? "");
|
|
255
|
+
if (callbackQueryId) {
|
|
256
|
+
const answerUrl = `${TELEGRAM_API_BASE}/bot${botToken}/answerCallbackQuery`;
|
|
257
|
+
await fetch(answerUrl, {
|
|
258
|
+
method: "POST",
|
|
259
|
+
headers: { "Content-Type": "application/json" },
|
|
260
|
+
body: JSON.stringify({
|
|
261
|
+
callback_query_id: callbackQueryId,
|
|
262
|
+
text: resolved
|
|
263
|
+
? `${decision === "approved" ? "✅" : "❌"} Action ${decision}`
|
|
264
|
+
: "⚠️ Already resolved or not found",
|
|
265
|
+
show_alert: true,
|
|
266
|
+
}),
|
|
267
|
+
}).catch(() => {
|
|
268
|
+
// Best-effort — don't fail the handler if Telegram API is slow
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return { status: 200, body: { ok: true } };
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// ─── HMAC verification ───────────────────────────────────────────────────────
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Verify the x-telegram-hmac-sha256 header using HMAC-SHA256 of the raw body.
|
|
280
|
+
*
|
|
281
|
+
* @public — exported for unit tests
|
|
282
|
+
*/
|
|
283
|
+
export function verifyTelegramSignature(
|
|
284
|
+
rawBody: string,
|
|
285
|
+
signature: string,
|
|
286
|
+
secret: string
|
|
287
|
+
): boolean {
|
|
288
|
+
if (!signature || !secret) return false;
|
|
289
|
+
const computed = createHmac("sha256", secret).update(rawBody).digest("hex");
|
|
290
|
+
try {
|
|
291
|
+
return timingSafeEqual(
|
|
292
|
+
Buffer.from(computed, "hex"),
|
|
293
|
+
Buffer.from(signature, "hex")
|
|
294
|
+
);
|
|
295
|
+
} catch {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// ─── Plain message helper ─────────────────────────────────────────────────────
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Send a plain informational message to a Telegram chat (no buttons).
|
|
304
|
+
* Used for daily briefs and non-interactive notifications.
|
|
305
|
+
*/
|
|
306
|
+
export async function sendTelegramMessage(
|
|
307
|
+
text: string,
|
|
308
|
+
channel: TelegramChannelConfig
|
|
309
|
+
): Promise<void> {
|
|
310
|
+
if (!channel.botToken || !channel.chatId) return;
|
|
311
|
+
const url = `${TELEGRAM_API_BASE}/bot${channel.botToken}/sendMessage`;
|
|
312
|
+
await fetch(url, {
|
|
313
|
+
method: "POST",
|
|
314
|
+
headers: { "Content-Type": "application/json" },
|
|
315
|
+
body: JSON.stringify({
|
|
316
|
+
chat_id: channel.chatId,
|
|
317
|
+
text: text.slice(0, 4096),
|
|
318
|
+
parse_mode: "Markdown",
|
|
319
|
+
}),
|
|
320
|
+
signal: AbortSignal.timeout(10_000),
|
|
321
|
+
}).catch((err: unknown) => {
|
|
322
|
+
// Best-effort non-interactive message — swallow errors
|
|
323
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
324
|
+
process.stderr.write(`[hitl-telegram] sendMessage failed: ${msg}\n`);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// ─── Private helpers ─────────────────────────────────────────────────────────
|
|
329
|
+
|
|
330
|
+
function summarizePayload(payload: Record<string, unknown>): string {
|
|
331
|
+
const raw = JSON.stringify(payload, null, 2);
|
|
332
|
+
if (Buffer.byteLength(raw, "utf-8") <= MAX_PAYLOAD_PREVIEW_BYTES) return raw;
|
|
333
|
+
return `${raw.slice(0, MAX_PAYLOAD_PREVIEW_BYTES - 50)}\n... [truncated]`;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function escapeMd(text: string): string {
|
|
337
|
+
return text.replace(/[_*[\]()~`>#+\-=|{}.!\\]/g, "\\$&");
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function escapeCodeBlock(text: string): string {
|
|
341
|
+
return text.replace(/[`\\]/g, "\\$&");
|
|
342
|
+
}
|