@senpi-ai/runtime 1.0.97 → 1.0.99
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/README.md +113 -2
- package/dist/actions/action-runtime-module.d.ts +55 -0
- package/dist/actions/action-runtime-module.d.ts.map +1 -0
- package/dist/actions/action-runtime-module.js +491 -0
- package/dist/actions/action-runtime-module.js.map +1 -0
- package/dist/actions/close-position/close-position.action.d.ts +1 -0
- package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
- package/dist/actions/close-position/close-position.action.js +93 -25
- package/dist/actions/close-position/close-position.action.js.map +1 -1
- package/dist/actions/decision-engine.d.ts.map +1 -1
- package/dist/actions/decision-engine.js +5 -0
- package/dist/actions/decision-engine.js.map +1 -1
- package/dist/actions/decision-meta.d.ts +9 -0
- package/dist/actions/decision-meta.d.ts.map +1 -0
- package/dist/actions/decision-meta.js +18 -0
- package/dist/actions/decision-meta.js.map +1 -0
- package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
- package/dist/actions/llm-decision/openclaw-llm-decision.js +6 -0
- package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
- package/dist/actions/llm-decision/shared.d.ts +1 -1
- package/dist/actions/llm-decision/shared.d.ts.map +1 -1
- package/dist/actions/llm-decision/shared.js +1 -1
- package/dist/actions/llm-decision/shared.js.map +1 -1
- package/dist/actions/notifications/formatter.d.ts +39 -0
- package/dist/actions/notifications/formatter.d.ts.map +1 -0
- package/dist/actions/notifications/formatter.js +68 -0
- package/dist/actions/notifications/formatter.js.map +1 -0
- package/dist/actions/notifications/index.d.ts +37 -0
- package/dist/actions/notifications/index.d.ts.map +1 -0
- package/dist/actions/notifications/index.js +89 -0
- package/dist/actions/notifications/index.js.map +1 -0
- package/dist/actions/open-position/open-position.action.d.ts +1 -0
- package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +197 -34
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/actions/open-position/resolve-margin.d.ts +30 -0
- package/dist/actions/open-position/resolve-margin.d.ts.map +1 -0
- package/dist/actions/open-position/resolve-margin.js +41 -0
- package/dist/actions/open-position/resolve-margin.js.map +1 -0
- package/dist/actions/position-tracker/position-tracker.action.d.ts.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.js +4 -1
- package/dist/actions/position-tracker/position-tracker.action.js.map +1 -1
- package/dist/actions/store/action-store.d.ts +45 -0
- package/dist/actions/store/action-store.d.ts.map +1 -0
- package/dist/actions/store/action-store.js +127 -0
- package/dist/actions/store/action-store.js.map +1 -0
- package/dist/actions/store/index.d.ts +11 -0
- package/dist/actions/store/index.d.ts.map +1 -0
- package/dist/actions/store/index.js +9 -0
- package/dist/actions/store/index.js.map +1 -0
- package/dist/actions/store/paths.d.ts +15 -0
- package/dist/actions/store/paths.d.ts.map +1 -0
- package/dist/actions/store/paths.js +29 -0
- package/dist/actions/store/paths.js.map +1 -0
- package/dist/actions/store/types.d.ts +126 -0
- package/dist/actions/store/types.d.ts.map +1 -0
- package/dist/actions/store/types.js +48 -0
- package/dist/actions/store/types.js.map +1 -0
- package/dist/actions/tracking-helpers.d.ts +13 -0
- package/dist/actions/tracking-helpers.d.ts.map +1 -0
- package/dist/actions/tracking-helpers.js +47 -0
- package/dist/actions/tracking-helpers.js.map +1 -0
- package/dist/actions/types.d.ts +8 -0
- package/dist/actions/types.d.ts.map +1 -1
- package/dist/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +106 -4
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/cli/senpi-commands.d.ts.map +1 -1
- package/dist/cli/senpi-commands.js +447 -1
- package/dist/cli/senpi-commands.js.map +1 -1
- package/dist/constants/dsl/index.d.ts +12 -0
- package/dist/constants/dsl/index.d.ts.map +1 -1
- package/dist/constants/dsl/index.js +12 -0
- package/dist/constants/dsl/index.js.map +1 -1
- package/dist/constants/order-types.d.ts +7 -0
- package/dist/constants/order-types.d.ts.map +1 -0
- package/dist/constants/order-types.js +6 -0
- package/dist/constants/order-types.js.map +1 -0
- package/dist/context/interpolate.d.ts +6 -2
- package/dist/context/interpolate.d.ts.map +1 -1
- package/dist/context/interpolate.js +6 -2
- package/dist/context/interpolate.js.map +1 -1
- package/dist/context/types.d.ts +8 -1
- package/dist/context/types.d.ts.map +1 -1
- package/dist/context/types.js +8 -1
- package/dist/context/types.js.map +1 -1
- package/dist/dsl/config/exit-block.d.ts +7 -0
- package/dist/dsl/config/exit-block.d.ts.map +1 -1
- package/dist/dsl/config/parse-plugin-config.d.ts.map +1 -1
- package/dist/dsl/config/parse-plugin-config.js +27 -1
- package/dist/dsl/config/parse-plugin-config.js.map +1 -1
- package/dist/dsl/config/unknown-keys.d.ts.map +1 -1
- package/dist/dsl/config/unknown-keys.js +3 -1
- package/dist/dsl/config/unknown-keys.js.map +1 -1
- package/dist/dsl/engine-client/event-mapping.d.ts +21 -1
- package/dist/dsl/engine-client/event-mapping.d.ts.map +1 -1
- package/dist/dsl/engine-client/event-mapping.js +10 -0
- package/dist/dsl/engine-client/event-mapping.js.map +1 -1
- package/dist/dsl/engine-client/index.d.ts +1 -1
- package/dist/dsl/engine-client/index.d.ts.map +1 -1
- package/dist/dsl/events/build-closed-event.d.ts +15 -0
- package/dist/dsl/events/build-closed-event.d.ts.map +1 -0
- package/dist/dsl/events/build-closed-event.js +31 -0
- package/dist/dsl/events/build-closed-event.js.map +1 -0
- package/dist/dsl/events/handlers.d.ts +2 -1
- package/dist/dsl/events/handlers.d.ts.map +1 -1
- package/dist/dsl/events/handlers.js +15 -10
- package/dist/dsl/events/handlers.js.map +1 -1
- package/dist/dsl/events/initial-state.d.ts +2 -2
- package/dist/dsl/events/initial-state.d.ts.map +1 -1
- package/dist/dsl/events/initial-state.js +4 -1
- package/dist/dsl/events/initial-state.js.map +1 -1
- package/dist/dsl/index.js +1 -1
- package/dist/dsl/index.js.map +1 -1
- package/dist/dsl/monitor/create-monitor.d.ts +4 -0
- package/dist/dsl/monitor/create-monitor.d.ts.map +1 -1
- package/dist/dsl/monitor/create-monitor.js +8 -5
- package/dist/dsl/monitor/create-monitor.js.map +1 -1
- package/dist/dsl/monitor/process-one-position.d.ts +4 -0
- package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
- package/dist/dsl/monitor/process-one-position.js +129 -40
- package/dist/dsl/monitor/process-one-position.js.map +1 -1
- package/dist/dsl/notifications/close-resolver.d.ts +92 -0
- package/dist/dsl/notifications/close-resolver.d.ts.map +1 -0
- package/dist/dsl/notifications/close-resolver.js +309 -0
- package/dist/dsl/notifications/close-resolver.js.map +1 -0
- package/dist/dsl/notifications/format-utils.d.ts +24 -0
- package/dist/dsl/notifications/format-utils.d.ts.map +1 -0
- package/dist/dsl/notifications/format-utils.js +102 -0
- package/dist/dsl/notifications/format-utils.js.map +1 -0
- package/dist/dsl/notifications/formatter.d.ts +23 -4
- package/dist/dsl/notifications/formatter.d.ts.map +1 -1
- package/dist/dsl/notifications/formatter.js +109 -34
- package/dist/dsl/notifications/formatter.js.map +1 -1
- package/dist/dsl/notifications/index.d.ts +7 -0
- package/dist/dsl/notifications/index.d.ts.map +1 -1
- package/dist/dsl/notifications/index.js +22 -10
- package/dist/dsl/notifications/index.js.map +1 -1
- package/dist/dsl/notifications/types.d.ts +27 -0
- package/dist/dsl/notifications/types.d.ts.map +1 -0
- package/dist/dsl/notifications/types.js +5 -0
- package/dist/dsl/notifications/types.js.map +1 -0
- package/dist/dsl/plugin/index.d.ts +1 -1
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +29 -1
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/health/index.d.ts +5 -2
- package/dist/health/index.d.ts.map +1 -1
- package/dist/health/index.js +106 -6
- package/dist/health/index.js.map +1 -1
- package/dist/health/types.d.ts +102 -0
- package/dist/health/types.d.ts.map +1 -1
- package/dist/health/types.js +7 -1
- package/dist/health/types.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +459 -9
- package/dist/index.js.map +1 -1
- package/dist/risk/guardrail.types.d.ts +58 -0
- package/dist/risk/guardrail.types.d.ts.map +1 -0
- package/dist/risk/guardrail.types.js +5 -0
- package/dist/risk/guardrail.types.js.map +1 -0
- package/dist/risk/index.d.ts +2 -4
- package/dist/risk/index.d.ts.map +1 -1
- package/dist/risk/index.js +2 -6
- package/dist/risk/index.js.map +1 -1
- package/dist/risk/risk-audit-log.d.ts +25 -0
- package/dist/risk/risk-audit-log.d.ts.map +1 -0
- package/dist/risk/risk-audit-log.js +30 -0
- package/dist/risk/risk-audit-log.js.map +1 -0
- package/dist/runtime/__tests__/helpers/runtime-gateway-harness.d.ts +162 -0
- package/dist/runtime/__tests__/helpers/runtime-gateway-harness.d.ts.map +1 -0
- package/dist/runtime/__tests__/helpers/runtime-gateway-harness.js +285 -0
- package/dist/runtime/__tests__/helpers/runtime-gateway-harness.js.map +1 -0
- package/dist/runtime/audit-query.types.d.ts +113 -0
- package/dist/runtime/audit-query.types.d.ts.map +1 -0
- package/dist/runtime/audit-query.types.js +35 -0
- package/dist/runtime/audit-query.types.js.map +1 -0
- package/dist/runtime/create-actions.d.ts +6 -2
- package/dist/runtime/create-actions.d.ts.map +1 -1
- package/dist/runtime/create-actions.js +30 -8
- package/dist/runtime/create-actions.js.map +1 -1
- package/dist/runtime/create-scanner-module.d.ts +5 -0
- package/dist/runtime/create-scanner-module.d.ts.map +1 -1
- package/dist/runtime/create-scanner-module.js +12 -1
- package/dist/runtime/create-scanner-module.js.map +1 -1
- package/dist/runtime/load-runtime-config.d.ts +1 -1
- package/dist/runtime/load-runtime-config.d.ts.map +1 -1
- package/dist/runtime/load-runtime-config.js +37 -1
- package/dist/runtime/load-runtime-config.js.map +1 -1
- package/dist/runtime/map-exit-config.d.ts +2 -1
- package/dist/runtime/map-exit-config.d.ts.map +1 -1
- package/dist/runtime/map-exit-config.js +11 -1
- package/dist/runtime/map-exit-config.js.map +1 -1
- package/dist/runtime/map-strategies.d.ts +1 -1
- package/dist/runtime/map-strategies.d.ts.map +1 -1
- package/dist/runtime/map-strategies.js +38 -1
- package/dist/runtime/map-strategies.js.map +1 -1
- package/dist/runtime/notifications.d.ts.map +1 -1
- package/dist/runtime/notifications.js +53 -7
- package/dist/runtime/notifications.js.map +1 -1
- package/dist/runtime/risk-guard.d.ts +26 -2
- package/dist/runtime/risk-guard.d.ts.map +1 -1
- package/dist/runtime/risk-guard.js +539 -5
- package/dist/runtime/risk-guard.js.map +1 -1
- package/dist/runtime/run.d.ts +96 -2
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +21 -0
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime-schema.d.ts +1169 -24
- package/dist/runtime/runtime-schema.d.ts.map +1 -1
- package/dist/runtime/runtime-schema.js +105 -2
- package/dist/runtime/runtime-schema.js.map +1 -1
- package/dist/runtime/runtime.d.ts +85 -2
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +374 -10
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/scanner-composition.d.ts +10 -0
- package/dist/runtime/scanner-composition.d.ts.map +1 -1
- package/dist/runtime/scanner-composition.js +10 -0
- package/dist/runtime/scanner-composition.js.map +1 -1
- package/dist/runtime/scanner-registry.d.ts +39 -1
- package/dist/runtime/scanner-registry.d.ts.map +1 -1
- package/dist/runtime/scanner-registry.js +105 -2
- package/dist/runtime/scanner-registry.js.map +1 -1
- package/dist/runtime/state-layout.d.ts +2 -0
- package/dist/runtime/state-layout.d.ts.map +1 -1
- package/dist/runtime/state-layout.js +1 -0
- package/dist/runtime/state-layout.js.map +1 -1
- package/dist/runtime/validate-action-prompts.d.ts +30 -0
- package/dist/runtime/validate-action-prompts.d.ts.map +1 -0
- package/dist/runtime/validate-action-prompts.js +110 -0
- package/dist/runtime/validate-action-prompts.js.map +1 -0
- package/dist/runtime-api/config.d.ts +47 -0
- package/dist/runtime-api/config.d.ts.map +1 -0
- package/dist/runtime-api/config.js +74 -0
- package/dist/runtime-api/config.js.map +1 -0
- package/dist/runtime-api/handlers/audit.d.ts +78 -0
- package/dist/runtime-api/handlers/audit.d.ts.map +1 -0
- package/dist/runtime-api/handlers/audit.js +65 -0
- package/dist/runtime-api/handlers/audit.js.map +1 -0
- package/dist/runtime-api/handlers/group-by-scanner.d.ts +43 -0
- package/dist/runtime-api/handlers/group-by-scanner.d.ts.map +1 -0
- package/dist/runtime-api/handlers/group-by-scanner.js +43 -0
- package/dist/runtime-api/handlers/group-by-scanner.js.map +1 -0
- package/dist/runtime-api/handlers/ingest-signals.d.ts +54 -0
- package/dist/runtime-api/handlers/ingest-signals.d.ts.map +1 -0
- package/dist/runtime-api/handlers/ingest-signals.js +124 -0
- package/dist/runtime-api/handlers/ingest-signals.js.map +1 -0
- package/dist/runtime-api/handlers/runtime-lookup.d.ts +36 -0
- package/dist/runtime-api/handlers/runtime-lookup.d.ts.map +1 -0
- package/dist/runtime-api/handlers/runtime-lookup.js +31 -0
- package/dist/runtime-api/handlers/runtime-lookup.js.map +1 -0
- package/dist/runtime-api/handlers/types.d.ts +85 -0
- package/dist/runtime-api/handlers/types.d.ts.map +1 -0
- package/dist/runtime-api/handlers/types.js +8 -0
- package/dist/runtime-api/handlers/types.js.map +1 -0
- package/dist/runtime-api/lifecycle.d.ts +98 -0
- package/dist/runtime-api/lifecycle.d.ts.map +1 -0
- package/dist/runtime-api/lifecycle.js +137 -0
- package/dist/runtime-api/lifecycle.js.map +1 -0
- package/dist/runtime-api/readiness.d.ts +37 -0
- package/dist/runtime-api/readiness.d.ts.map +1 -0
- package/dist/runtime-api/readiness.js +35 -0
- package/dist/runtime-api/readiness.js.map +1 -0
- package/dist/runtime-api/routes/audit.d.ts +40 -0
- package/dist/runtime-api/routes/audit.d.ts.map +1 -0
- package/dist/runtime-api/routes/audit.js +90 -0
- package/dist/runtime-api/routes/audit.js.map +1 -0
- package/dist/runtime-api/routes/audit.schema.d.ts +75 -0
- package/dist/runtime-api/routes/audit.schema.d.ts.map +1 -0
- package/dist/runtime-api/routes/audit.schema.js +78 -0
- package/dist/runtime-api/routes/audit.schema.js.map +1 -0
- package/dist/runtime-api/routes/health.d.ts +53 -0
- package/dist/runtime-api/routes/health.d.ts.map +1 -0
- package/dist/runtime-api/routes/health.js +48 -0
- package/dist/runtime-api/routes/health.js.map +1 -0
- package/dist/runtime-api/routes/signals.d.ts +50 -0
- package/dist/runtime-api/routes/signals.d.ts.map +1 -0
- package/dist/runtime-api/routes/signals.js +90 -0
- package/dist/runtime-api/routes/signals.js.map +1 -0
- package/dist/runtime-api/routes/signals.schema.d.ts +94 -0
- package/dist/runtime-api/routes/signals.schema.d.ts.map +1 -0
- package/dist/runtime-api/routes/signals.schema.js +58 -0
- package/dist/runtime-api/routes/signals.schema.js.map +1 -0
- package/dist/runtime-api/routes/state.d.ts +51 -0
- package/dist/runtime-api/routes/state.d.ts.map +1 -0
- package/dist/runtime-api/routes/state.js +94 -0
- package/dist/runtime-api/routes/state.js.map +1 -0
- package/dist/runtime-api/server.d.ts +79 -0
- package/dist/runtime-api/server.d.ts.map +1 -0
- package/dist/runtime-api/server.js +114 -0
- package/dist/runtime-api/server.js.map +1 -0
- package/dist/scanners/__tests__/test-helpers.d.ts +10 -0
- package/dist/scanners/__tests__/test-helpers.d.ts.map +1 -1
- package/dist/scanners/__tests__/test-helpers.js +52 -0
- package/dist/scanners/__tests__/test-helpers.js.map +1 -1
- package/dist/scanners/engine/engine.d.ts +37 -0
- package/dist/scanners/engine/engine.d.ts.map +1 -1
- package/dist/scanners/engine/engine.js +132 -14
- package/dist/scanners/engine/engine.js.map +1 -1
- package/dist/scanners/engine/result-builder.d.ts +16 -0
- package/dist/scanners/engine/result-builder.d.ts.map +1 -1
- package/dist/scanners/engine/result-builder.js +22 -0
- package/dist/scanners/engine/result-builder.js.map +1 -1
- package/dist/scanners/engine/strategy-registry.d.ts +2 -0
- package/dist/scanners/engine/strategy-registry.d.ts.map +1 -1
- package/dist/scanners/engine/strategy-registry.js +5 -1
- package/dist/scanners/engine/strategy-registry.js.map +1 -1
- package/dist/scanners/external/liquidation-watchdog/README.md +107 -0
- package/dist/scanners/external/liquidation-watchdog/liquidation-watchdog.yaml +48 -0
- package/dist/scanners/external/liquidation-watchdog/producer.mjs +336 -0
- package/dist/scanners/external/momentum/README.md +148 -0
- package/dist/scanners/external/momentum/momentum.yaml +116 -0
- package/dist/scanners/external/momentum/producer.mjs +251 -0
- package/dist/scanners/external/shared/ingest.mjs +112 -0
- package/dist/scanners/external-scanner-receiver.d.ts +118 -0
- package/dist/scanners/external-scanner-receiver.d.ts.map +1 -0
- package/dist/scanners/external-scanner-receiver.js +266 -0
- package/dist/scanners/external-scanner-receiver.js.map +1 -0
- package/dist/scanners/implementations/external-scanner.d.ts +17 -0
- package/dist/scanners/implementations/external-scanner.d.ts.map +1 -0
- package/dist/scanners/implementations/external-scanner.js +51 -0
- package/dist/scanners/implementations/external-scanner.js.map +1 -0
- package/dist/scanners/implementations/index.d.ts +1 -0
- package/dist/scanners/implementations/index.d.ts.map +1 -1
- package/dist/scanners/implementations/index.js +1 -0
- package/dist/scanners/implementations/index.js.map +1 -1
- package/dist/scanners/implementations/position-tracker.d.ts.map +1 -1
- package/dist/scanners/implementations/position-tracker.js +3 -1
- package/dist/scanners/implementations/position-tracker.js.map +1 -1
- package/dist/scanners/index.d.ts +4 -1
- package/dist/scanners/index.d.ts.map +1 -1
- package/dist/scanners/index.js +2 -0
- package/dist/scanners/index.js.map +1 -1
- package/dist/scanners/protocol/scanner.d.ts +3 -1
- package/dist/scanners/protocol/scanner.d.ts.map +1 -1
- package/dist/scanners/providers/client.d.ts.map +1 -1
- package/dist/scanners/providers/client.js +0 -8
- package/dist/scanners/providers/client.js.map +1 -1
- package/dist/scanners/runtime-module.d.ts +10 -0
- package/dist/scanners/runtime-module.d.ts.map +1 -1
- package/dist/scanners/runtime-module.js +19 -3
- package/dist/scanners/runtime-module.js.map +1 -1
- package/dist/scanners/scanner-definition.d.ts +12 -1
- package/dist/scanners/scanner-definition.d.ts.map +1 -1
- package/dist/scanners/schema-utils.d.ts +22 -2
- package/dist/scanners/schema-utils.d.ts.map +1 -1
- package/dist/scanners/schema-utils.js +14 -2
- package/dist/scanners/schema-utils.js.map +1 -1
- package/dist/scanners/types.d.ts +3 -0
- package/dist/scanners/types.d.ts.map +1 -1
- package/dist/scanners/types.js.map +1 -1
- package/dist/scripts/run-dsl-standalone-live.js +2 -2
- package/dist/scripts/run-dsl-standalone-live.js.map +1 -1
- package/dist/scripts/run-dsl-standalone-mock.js +2 -2
- package/dist/scripts/run-dsl-standalone-mock.js.map +1 -1
- package/dist/senpi/client.d.ts +123 -4
- package/dist/senpi/client.d.ts.map +1 -1
- package/dist/senpi/client.js +304 -15
- package/dist/senpi/client.js.map +1 -1
- package/dist/senpi/index.d.ts +1 -1
- package/dist/senpi/index.d.ts.map +1 -1
- package/dist/senpi/types.d.ts +70 -0
- package/dist/senpi/types.d.ts.map +1 -1
- package/dist/state/state-manager.d.ts +3 -0
- package/dist/state/state-manager.d.ts.map +1 -1
- package/dist/state/state-manager.js +9 -0
- package/dist/state/state-manager.js.map +1 -1
- package/dist/strategy/strategy-state.d.ts +4 -1
- package/dist/strategy/strategy-state.d.ts.map +1 -1
- package/dist/strategy/strategy-state.js +7 -2
- package/dist/strategy/strategy-state.js.map +1 -1
- package/dist/tracking/constants.d.ts +24 -0
- package/dist/tracking/constants.d.ts.map +1 -0
- package/dist/tracking/constants.js +50 -0
- package/dist/tracking/constants.js.map +1 -0
- package/dist/tracking/index.d.ts +13 -0
- package/dist/tracking/index.d.ts.map +1 -0
- package/dist/tracking/index.js +9 -0
- package/dist/tracking/index.js.map +1 -0
- package/dist/tracking/plugin-event-tracker.d.ts +13 -0
- package/dist/tracking/plugin-event-tracker.d.ts.map +1 -0
- package/dist/tracking/plugin-event-tracker.js +27 -0
- package/dist/tracking/plugin-event-tracker.js.map +1 -0
- package/dist/tracking/tracker.d.ts +30 -0
- package/dist/tracking/tracker.d.ts.map +1 -0
- package/dist/tracking/tracker.js +66 -0
- package/dist/tracking/tracker.js.map +1 -0
- package/dist/tracking/tracking-handler.d.ts +12 -0
- package/dist/tracking/tracking-handler.d.ts.map +1 -0
- package/dist/tracking/tracking-handler.js +148 -0
- package/dist/tracking/tracking-handler.js.map +1 -0
- package/dist/tracking/transport.d.ts +35 -0
- package/dist/tracking/transport.d.ts.map +1 -0
- package/dist/tracking/transport.js +133 -0
- package/dist/tracking/transport.js.map +1 -0
- package/dist/tracking/types.d.ts +21 -0
- package/dist/tracking/types.d.ts.map +1 -0
- package/dist/tracking/types.js +6 -0
- package/dist/tracking/types.js.map +1 -0
- package/dist/types/action.d.ts +13 -2
- package/dist/types/action.d.ts.map +1 -1
- package/dist/types/dsl/index.d.ts +72 -3
- package/dist/types/dsl/index.d.ts.map +1 -1
- package/dist/types/strategy.d.ts +11 -3
- package/dist/types/strategy.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +6 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +35 -2
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/resolve-order-type.d.ts +5 -0
- package/dist/utils/resolve-order-type.d.ts.map +1 -0
- package/dist/utils/resolve-order-type.js +29 -0
- package/dist/utils/resolve-order-type.js.map +1 -0
- package/examples/strategies/dsl-showcase.yaml +7 -2
- package/examples/strategies/dsl.yaml +5 -1
- package/examples/strategies/fox-minimal-loosened.yaml +18 -3
- package/examples/strategies/fox-minimal.yaml +25 -3
- package/examples/strategies/minimal.yaml +4 -2
- package/examples/strategies/momentum/how-it-works.md +48 -0
- package/examples/strategies/momentum/momentum-guarded.yaml +161 -0
- package/examples/strategies/risk-showcase.yaml +93 -0
- package/examples/strategies/viper.yaml +11 -3
- package/examples/strategies/wolf.yaml +11 -3
- package/examples/yamls/sample-with-dsl-and-emerging-movers.yaml +12 -4
- package/openclaw.plugin.json +35 -1
- package/package.json +12 -7
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify route: `GET /health`.
|
|
3
|
+
*
|
|
4
|
+
* Returns a three-state readiness signal (`starting` | `ok` | `draining`)
|
|
5
|
+
* suitable for load-balancer / Kubernetes liveness and readiness probes.
|
|
6
|
+
* Also exposes per-runtime signal-queue depth for capacity planning.
|
|
7
|
+
*
|
|
8
|
+
* HTTP status:
|
|
9
|
+
* - `200` when `status === "ok"`.
|
|
10
|
+
* - `503` when `status === "starting"` or `"draining"` — load balancer
|
|
11
|
+
* should stop routing new requests but the process is still alive.
|
|
12
|
+
*/
|
|
13
|
+
import type { FastifyInstance } from "fastify";
|
|
14
|
+
import type { Readiness } from "../readiness.js";
|
|
15
|
+
import type { RuntimeHandle } from "../../runtime/run.js";
|
|
16
|
+
/**
|
|
17
|
+
* Dependencies injected into the `/health` route at registration time.
|
|
18
|
+
*/
|
|
19
|
+
export interface HealthRouteDeps {
|
|
20
|
+
/** Live runtime handles maintained by the plugin, keyed by lowercased address. */
|
|
21
|
+
runtimeHandles: Map<string, RuntimeHandle>;
|
|
22
|
+
/** Subset of `ApiConfig` needed for the response body. */
|
|
23
|
+
apiConfig: {
|
|
24
|
+
host: string;
|
|
25
|
+
port: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Three-state readiness flag.
|
|
29
|
+
* S5 (lifecycle) flips it to `"ok"` after the server binds and to
|
|
30
|
+
* `"draining"` during graceful shutdown.
|
|
31
|
+
*/
|
|
32
|
+
readiness: Readiness;
|
|
33
|
+
/**
|
|
34
|
+
* Plugin version string (read from `openclaw.plugin.json` at boot).
|
|
35
|
+
* Included in the response so callers can correlate logs with deployments.
|
|
36
|
+
*/
|
|
37
|
+
version: string;
|
|
38
|
+
/** Unix epoch ms timestamp recorded when `createApi()` was called. */
|
|
39
|
+
bootedAt: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Register `GET /health` on the given Fastify instance.
|
|
43
|
+
*
|
|
44
|
+
* Response is never cached (`Cache-Control: no-store`). The shape is stable
|
|
45
|
+
* across minor versions — callers may rely on `status`, `runtimes.count`, and
|
|
46
|
+
* `runtimes.items[].signalQueueDepth` being present whenever the server is
|
|
47
|
+
* reachable.
|
|
48
|
+
*
|
|
49
|
+
* @param fastify Fastify instance to register the route on.
|
|
50
|
+
* @param deps Route dependencies injected at plugin start.
|
|
51
|
+
*/
|
|
52
|
+
export declare function registerHealthRoute(fastify: FastifyInstance, deps: HealthRouteDeps): void;
|
|
53
|
+
//# sourceMappingURL=health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../../src/runtime-api/routes/health.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kFAAkF;IAClF,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C,0DAA0D;IAC1D,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C;;;;OAIG;IACH,SAAS,EAAE,SAAS,CAAC;IACrB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,eAAe,GACpB,IAAI,CAyBN"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify route: `GET /health`.
|
|
3
|
+
*
|
|
4
|
+
* Returns a three-state readiness signal (`starting` | `ok` | `draining`)
|
|
5
|
+
* suitable for load-balancer / Kubernetes liveness and readiness probes.
|
|
6
|
+
* Also exposes per-runtime signal-queue depth for capacity planning.
|
|
7
|
+
*
|
|
8
|
+
* HTTP status:
|
|
9
|
+
* - `200` when `status === "ok"`.
|
|
10
|
+
* - `503` when `status === "starting"` or `"draining"` — load balancer
|
|
11
|
+
* should stop routing new requests but the process is still alive.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Register `GET /health` on the given Fastify instance.
|
|
15
|
+
*
|
|
16
|
+
* Response is never cached (`Cache-Control: no-store`). The shape is stable
|
|
17
|
+
* across minor versions — callers may rely on `status`, `runtimes.count`, and
|
|
18
|
+
* `runtimes.items[].signalQueueDepth` being present whenever the server is
|
|
19
|
+
* reachable.
|
|
20
|
+
*
|
|
21
|
+
* @param fastify Fastify instance to register the route on.
|
|
22
|
+
* @param deps Route dependencies injected at plugin start.
|
|
23
|
+
*/
|
|
24
|
+
export function registerHealthRoute(fastify, deps) {
|
|
25
|
+
fastify.get("/health", async (_req, reply) => {
|
|
26
|
+
const status = deps.readiness.state();
|
|
27
|
+
const httpStatus = status === "ok" ? 200 : 503;
|
|
28
|
+
const items = Array.from(deps.runtimeHandles, ([_id, handle]) => ({
|
|
29
|
+
address: handle.wallet.toLowerCase(),
|
|
30
|
+
signalQueueDepth: handle.getSignalQueueDepth(),
|
|
31
|
+
}));
|
|
32
|
+
return reply
|
|
33
|
+
.status(httpStatus)
|
|
34
|
+
.header("Cache-Control", "no-store")
|
|
35
|
+
.send({
|
|
36
|
+
status,
|
|
37
|
+
version: deps.version,
|
|
38
|
+
uptime_ms: Date.now() - deps.bootedAt,
|
|
39
|
+
runtimes: { count: items.length, items },
|
|
40
|
+
api: { host: deps.apiConfig.host, port: deps.apiConfig.port },
|
|
41
|
+
build: {
|
|
42
|
+
commit: process.env.SENPI_GIT_COMMIT ?? null,
|
|
43
|
+
node: process.version,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../../src/runtime-api/routes/health.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA6BH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAAwB,EACxB,IAAqB;IAErB,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACtC,MAAM,UAAU,GAAG,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;QAE/C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;YAChE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE;YACpC,gBAAgB,EAAE,MAAM,CAAC,mBAAmB,EAAE;SAC/C,CAAC,CAAC,CAAC;QAEJ,OAAO,KAAK;aACT,MAAM,CAAC,UAAU,CAAC;aAClB,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC;aACnC,IAAI,CAAC;YACJ,MAAM;YACN,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ;YACrC,QAAQ,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE;YACxC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;YAC7D,KAAK,EAAE;gBACL,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,IAAI;gBAC5C,IAAI,EAAE,OAAO,CAAC,OAAO;aACtB;SACF,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify route: `POST /signals`.
|
|
3
|
+
*
|
|
4
|
+
* Accepts a batch of signal items targeting one or more runtime wallets,
|
|
5
|
+
* groups them by `(address, scanner)` to avoid the per-key ingest lock, fans
|
|
6
|
+
* out groups in parallel, processes items within each group sequentially, and
|
|
7
|
+
* returns per-item results in input order.
|
|
8
|
+
*
|
|
9
|
+
* Business logic lives entirely in:
|
|
10
|
+
* - `handlers/ingest-signals.ts` — per-item dispatch + error translation.
|
|
11
|
+
* - `handlers/group-by-scanner.ts` — lock-aware grouping helper.
|
|
12
|
+
*
|
|
13
|
+
* This file contains only Fastify wiring and the handler-level cap check.
|
|
14
|
+
*/
|
|
15
|
+
import type { FastifyInstance } from "fastify";
|
|
16
|
+
import type { RuntimeHandle } from "../../runtime/run.js";
|
|
17
|
+
import type { Logger } from "../../utils/logger.js";
|
|
18
|
+
/**
|
|
19
|
+
* Dependencies injected into the `/signals` route at registration time.
|
|
20
|
+
*/
|
|
21
|
+
export interface SignalsRouteDeps {
|
|
22
|
+
/** Live runtime handles maintained by the plugin, keyed by lowercased address. */
|
|
23
|
+
runtimeHandles: Map<string, RuntimeHandle>;
|
|
24
|
+
/** Logger instance for unexpected errors. */
|
|
25
|
+
logger: Logger;
|
|
26
|
+
/**
|
|
27
|
+
* Maximum number of items allowed in a single request.
|
|
28
|
+
* Sourced from `config.api.maxItemsPerSignalsRequest` (default 10).
|
|
29
|
+
*/
|
|
30
|
+
maxItems: number;
|
|
31
|
+
/**
|
|
32
|
+
* Transport tag forwarded to the ingest handler for telemetry.
|
|
33
|
+
* Fixed as `"http"` for this route; the gateway shim passes `"gateway"`.
|
|
34
|
+
*/
|
|
35
|
+
transport: "http" | "gateway";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Register `POST /signals` on the given Fastify instance.
|
|
39
|
+
*
|
|
40
|
+
* The route validates the body against the `SignalsBody` TypeBox schema, then:
|
|
41
|
+
* 1. Rejects oversized batches (handler-level cap, configurable).
|
|
42
|
+
* 2. Groups items by `(address, scanner)` via `groupByAddressScanner`.
|
|
43
|
+
* 3. Runs groups in parallel; items within each group run sequentially.
|
|
44
|
+
* 4. Re-flattens results back to input order before responding.
|
|
45
|
+
*
|
|
46
|
+
* @param fastify Fastify instance to register the route on.
|
|
47
|
+
* @param deps Route dependencies injected at plugin start.
|
|
48
|
+
*/
|
|
49
|
+
export declare function registerSignalsRoute(fastify: FastifyInstance, deps: SignalsRouteDeps): void;
|
|
50
|
+
//# sourceMappingURL=signals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../../../src/runtime-api/routes/signals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAM/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAwDpD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kFAAkF;IAClF,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,gBAAgB,GACrB,IAAI,CA+CN"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify route: `POST /signals`.
|
|
3
|
+
*
|
|
4
|
+
* Accepts a batch of signal items targeting one or more runtime wallets,
|
|
5
|
+
* groups them by `(address, scanner)` to avoid the per-key ingest lock, fans
|
|
6
|
+
* out groups in parallel, processes items within each group sequentially, and
|
|
7
|
+
* returns per-item results in input order.
|
|
8
|
+
*
|
|
9
|
+
* Business logic lives entirely in:
|
|
10
|
+
* - `handlers/ingest-signals.ts` — per-item dispatch + error translation.
|
|
11
|
+
* - `handlers/group-by-scanner.ts` — lock-aware grouping helper.
|
|
12
|
+
*
|
|
13
|
+
* This file contains only Fastify wiring and the handler-level cap check.
|
|
14
|
+
*/
|
|
15
|
+
import { SignalsBody } from "./signals.schema.js";
|
|
16
|
+
import { ingestSignalsHandler } from "../handlers/ingest-signals.js";
|
|
17
|
+
import { groupByAddressScanner } from "../handlers/group-by-scanner.js";
|
|
18
|
+
function toWire(r) {
|
|
19
|
+
if (r.success) {
|
|
20
|
+
return {
|
|
21
|
+
success: true,
|
|
22
|
+
address: r.address,
|
|
23
|
+
scanner: r.scanner,
|
|
24
|
+
data: {
|
|
25
|
+
timestamp: r.timestamp,
|
|
26
|
+
signalCount: r.signalCount,
|
|
27
|
+
contextUpdated: r.contextUpdated,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
address: r.address,
|
|
34
|
+
scanner: r.scanner,
|
|
35
|
+
error: {
|
|
36
|
+
code: r.code,
|
|
37
|
+
message: r.message,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Register `POST /signals` on the given Fastify instance.
|
|
43
|
+
*
|
|
44
|
+
* The route validates the body against the `SignalsBody` TypeBox schema, then:
|
|
45
|
+
* 1. Rejects oversized batches (handler-level cap, configurable).
|
|
46
|
+
* 2. Groups items by `(address, scanner)` via `groupByAddressScanner`.
|
|
47
|
+
* 3. Runs groups in parallel; items within each group run sequentially.
|
|
48
|
+
* 4. Re-flattens results back to input order before responding.
|
|
49
|
+
*
|
|
50
|
+
* @param fastify Fastify instance to register the route on.
|
|
51
|
+
* @param deps Route dependencies injected at plugin start.
|
|
52
|
+
*/
|
|
53
|
+
export function registerSignalsRoute(fastify, deps) {
|
|
54
|
+
fastify.post("/signals", { schema: { body: SignalsBody } }, async (req, reply) => {
|
|
55
|
+
const items = req.body;
|
|
56
|
+
// Handler-level cap — operator-tunable, not encoded in the TypeBox schema.
|
|
57
|
+
if (items.length > deps.maxItems) {
|
|
58
|
+
return reply.status(400).send({
|
|
59
|
+
success: false,
|
|
60
|
+
error: {
|
|
61
|
+
code: "INVALID_REQUEST",
|
|
62
|
+
message: `Exceeded api.maxItemsPerSignalsRequest=${deps.maxItems}; got ${items.length}.`,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// Group by (address, scanner) — each group is a SignalGroup (IndexedSignalItem[]).
|
|
67
|
+
const groups = groupByAddressScanner(items);
|
|
68
|
+
// Fan out across groups in parallel; process items within each group sequentially.
|
|
69
|
+
const grouped = await Promise.all(groups.map(async (group) => {
|
|
70
|
+
const out = [];
|
|
71
|
+
for (const { index, item } of group) {
|
|
72
|
+
out.push({
|
|
73
|
+
index,
|
|
74
|
+
result: await ingestSignalsHandler(item, {
|
|
75
|
+
runtimeHandles: deps.runtimeHandles,
|
|
76
|
+
logger: deps.logger,
|
|
77
|
+
transport: deps.transport,
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}));
|
|
83
|
+
// Re-flatten in input order.
|
|
84
|
+
const flat = grouped.flat();
|
|
85
|
+
flat.sort((a, b) => a.index - b.index);
|
|
86
|
+
const results = flat.map((entry) => toWire(entry.result));
|
|
87
|
+
return reply.send({ success: true, data: { results } });
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=signals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.js","sourceRoot":"","sources":["../../../src/runtime-api/routes/signals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAoCxE,SAAS,MAAM,CAAC,CAAe;IAC7B,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QACd,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,IAAI,EAAE;gBACJ,SAAS,EAAE,CAAC,CAAC,SAAS;gBACtB,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,cAAc,EAAE,CAAC,CAAC,cAAc;aACjC;SACF,CAAC;IACJ,CAAC;IACD,OAAO;QACL,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,KAAK,EAAE;YACL,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,OAAO,EAAE,CAAC,CAAC,OAAO;SACnB;KACF,CAAC;AACJ,CAAC;AAsBD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAwB,EACxB,IAAsB;IAEtB,OAAO,CAAC,IAAI,CACV,UAAU,EACV,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EACjC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QACnB,MAAM,KAAK,GAAG,GAAG,CAAC,IAAoB,CAAC;QAEvC,2EAA2E;QAC3E,IAAI,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC5B,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,iBAAiB;oBACvB,OAAO,EAAE,0CAA0C,IAAI,CAAC,QAAQ,SAAS,KAAK,CAAC,MAAM,GAAG;iBACzF;aACF,CAAC,CAAC;QACL,CAAC;QAED,mFAAmF;QACnF,MAAM,MAAM,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAE5C,mFAAmF;QACnF,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YACzB,MAAM,GAAG,GAAmD,EAAE,CAAC;YAC/D,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC;gBACpC,GAAG,CAAC,IAAI,CAAC;oBACP,KAAK;oBACL,MAAM,EAAE,MAAM,oBAAoB,CAAC,IAAI,EAAE;wBACvC,cAAc,EAAE,IAAI,CAAC,cAAc;wBACnC,MAAM,EAAE,IAAI,CAAC,MAAM;wBACnB,SAAS,EAAE,IAAI,CAAC,SAAS;qBAC1B,CAAC;iBACH,CAAC,CAAC;YACL,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,CAAC,CACH,CAAC;QAEF,6BAA6B;QAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,OAAO,GAAuB,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAE9E,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IAC1D,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeBox schema for the `POST /signals` request body.
|
|
3
|
+
*
|
|
4
|
+
* `SignalItemT` is derived from TypeBox `Static<>` and is structurally
|
|
5
|
+
* compatible with the hand-written {@link SignalItem} interface in
|
|
6
|
+
* `handlers/types.ts`. The interface in `handlers/types.ts` is kept as the
|
|
7
|
+
* canonical description (referenced by JSDoc across the codebase); this module
|
|
8
|
+
* derives the runtime-validatable form from TypeBox so both shapes stay in
|
|
9
|
+
* sync at compile-time.
|
|
10
|
+
*
|
|
11
|
+
* Note on `direction`: the TypeBox schema accepts any string so
|
|
12
|
+
* `SignalItemT["direction"]` is `string | undefined`, matching
|
|
13
|
+
* `Signal["direction"]` in `scanners/types.ts`. The tighter
|
|
14
|
+
* `"long" | "short" | null` constraint lives in the MCP layer; the runtime
|
|
15
|
+
* applies it implicitly during scanner-engine ingest.
|
|
16
|
+
*
|
|
17
|
+
* Note on `maxItems`: enforced at handler level using the configured
|
|
18
|
+
* `api.maxItemsPerSignalsRequest` value (default 10). Schema-level cap is
|
|
19
|
+
* kept open-ended so the shape works in tests without recompiling.
|
|
20
|
+
*/
|
|
21
|
+
import { type Static } from "@sinclair/typebox";
|
|
22
|
+
/** TypeBox schema for one item in the `POST /signals` body. */
|
|
23
|
+
export declare const SignalItem: import("@sinclair/typebox").TObject<{
|
|
24
|
+
/** Wallet address of the target runtime. Lowercased server-side. */
|
|
25
|
+
address: import("@sinclair/typebox").TString;
|
|
26
|
+
/** Configured scanner id. */
|
|
27
|
+
scanner: import("@sinclair/typebox").TString;
|
|
28
|
+
/** Asset for a single ingested signal. */
|
|
29
|
+
asset: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
30
|
+
/**
|
|
31
|
+
* Direction for a single ingested signal.
|
|
32
|
+
* Accepts any string — `"long"` / `"short"` are the conventional values.
|
|
33
|
+
*/
|
|
34
|
+
direction: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
35
|
+
/** Confidence score for a single ingested signal (0–1). */
|
|
36
|
+
score: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
37
|
+
/** Signal classification override for a single ingested signal. */
|
|
38
|
+
signal_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
39
|
+
/**
|
|
40
|
+
* Single ingest payload for signal-producing or context-producing scanners.
|
|
41
|
+
* Mutually exclusive with `signals[]`.
|
|
42
|
+
*/
|
|
43
|
+
data: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
|
|
44
|
+
/**
|
|
45
|
+
* Batch signal payloads for signal-producing external scanners.
|
|
46
|
+
* Mutually exclusive with `data`.
|
|
47
|
+
*/
|
|
48
|
+
signals: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
49
|
+
asset: import("@sinclair/typebox").TString;
|
|
50
|
+
direction: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
51
|
+
score: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
52
|
+
signal_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
53
|
+
data: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
|
|
54
|
+
}>>>;
|
|
55
|
+
}>;
|
|
56
|
+
/** TypeBox schema for the full `POST /signals` request body array. */
|
|
57
|
+
export declare const SignalsBody: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
58
|
+
/** Wallet address of the target runtime. Lowercased server-side. */
|
|
59
|
+
address: import("@sinclair/typebox").TString;
|
|
60
|
+
/** Configured scanner id. */
|
|
61
|
+
scanner: import("@sinclair/typebox").TString;
|
|
62
|
+
/** Asset for a single ingested signal. */
|
|
63
|
+
asset: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
64
|
+
/**
|
|
65
|
+
* Direction for a single ingested signal.
|
|
66
|
+
* Accepts any string — `"long"` / `"short"` are the conventional values.
|
|
67
|
+
*/
|
|
68
|
+
direction: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
69
|
+
/** Confidence score for a single ingested signal (0–1). */
|
|
70
|
+
score: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
71
|
+
/** Signal classification override for a single ingested signal. */
|
|
72
|
+
signal_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
73
|
+
/**
|
|
74
|
+
* Single ingest payload for signal-producing or context-producing scanners.
|
|
75
|
+
* Mutually exclusive with `signals[]`.
|
|
76
|
+
*/
|
|
77
|
+
data: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
|
|
78
|
+
/**
|
|
79
|
+
* Batch signal payloads for signal-producing external scanners.
|
|
80
|
+
* Mutually exclusive with `data`.
|
|
81
|
+
*/
|
|
82
|
+
signals: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
83
|
+
asset: import("@sinclair/typebox").TString;
|
|
84
|
+
direction: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
85
|
+
score: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
86
|
+
signal_type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
87
|
+
data: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
|
|
88
|
+
}>>>;
|
|
89
|
+
}>>;
|
|
90
|
+
/** TypeScript type for one signal item — derived from TypeBox, single source of truth. */
|
|
91
|
+
export type SignalItemT = Static<typeof SignalItem>;
|
|
92
|
+
/** TypeScript type for the `POST /signals` request body. */
|
|
93
|
+
export type SignalsBodyT = Static<typeof SignalsBody>;
|
|
94
|
+
//# sourceMappingURL=signals.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.schema.d.ts","sourceRoot":"","sources":["../../../src/runtime-api/routes/signals.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEtD,+DAA+D;AAC/D,eAAO,MAAM,UAAU;IAEnB,oEAAoE;;IAEpE,6BAA6B;;IAE7B,0CAA0C;;IAE1C;;;OAGG;;IAEH,2DAA2D;;IAE3D,mEAAmE;;IAEnE;;;OAGG;;IAEH;;;OAGG;;;;;;;;EAcN,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,WAAW;IAxCpB,oEAAoE;;IAEpE,6BAA6B;;IAE7B,0CAA0C;;IAE1C;;;OAGG;;IAEH,2DAA2D;;IAE3D,mEAAmE;;IAEnE;;;OAGG;;IAEH;;;OAGG;;;;;;;;GAiB2D,CAAC;AAEnE,0FAA0F;AAC1F,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEpD,4DAA4D;AAC5D,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeBox schema for the `POST /signals` request body.
|
|
3
|
+
*
|
|
4
|
+
* `SignalItemT` is derived from TypeBox `Static<>` and is structurally
|
|
5
|
+
* compatible with the hand-written {@link SignalItem} interface in
|
|
6
|
+
* `handlers/types.ts`. The interface in `handlers/types.ts` is kept as the
|
|
7
|
+
* canonical description (referenced by JSDoc across the codebase); this module
|
|
8
|
+
* derives the runtime-validatable form from TypeBox so both shapes stay in
|
|
9
|
+
* sync at compile-time.
|
|
10
|
+
*
|
|
11
|
+
* Note on `direction`: the TypeBox schema accepts any string so
|
|
12
|
+
* `SignalItemT["direction"]` is `string | undefined`, matching
|
|
13
|
+
* `Signal["direction"]` in `scanners/types.ts`. The tighter
|
|
14
|
+
* `"long" | "short" | null` constraint lives in the MCP layer; the runtime
|
|
15
|
+
* applies it implicitly during scanner-engine ingest.
|
|
16
|
+
*
|
|
17
|
+
* Note on `maxItems`: enforced at handler level using the configured
|
|
18
|
+
* `api.maxItemsPerSignalsRequest` value (default 10). Schema-level cap is
|
|
19
|
+
* kept open-ended so the shape works in tests without recompiling.
|
|
20
|
+
*/
|
|
21
|
+
import { Type } from "@sinclair/typebox";
|
|
22
|
+
/** TypeBox schema for one item in the `POST /signals` body. */
|
|
23
|
+
export const SignalItem = Type.Object({
|
|
24
|
+
/** Wallet address of the target runtime. Lowercased server-side. */
|
|
25
|
+
address: Type.String({ minLength: 1 }),
|
|
26
|
+
/** Configured scanner id. */
|
|
27
|
+
scanner: Type.String({ minLength: 1 }),
|
|
28
|
+
/** Asset for a single ingested signal. */
|
|
29
|
+
asset: Type.Optional(Type.String()),
|
|
30
|
+
/**
|
|
31
|
+
* Direction for a single ingested signal.
|
|
32
|
+
* Accepts any string — `"long"` / `"short"` are the conventional values.
|
|
33
|
+
*/
|
|
34
|
+
direction: Type.Optional(Type.String()),
|
|
35
|
+
/** Confidence score for a single ingested signal (0–1). */
|
|
36
|
+
score: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
37
|
+
/** Signal classification override for a single ingested signal. */
|
|
38
|
+
signal_type: Type.Optional(Type.String()),
|
|
39
|
+
/**
|
|
40
|
+
* Single ingest payload for signal-producing or context-producing scanners.
|
|
41
|
+
* Mutually exclusive with `signals[]`.
|
|
42
|
+
*/
|
|
43
|
+
data: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
|
|
44
|
+
/**
|
|
45
|
+
* Batch signal payloads for signal-producing external scanners.
|
|
46
|
+
* Mutually exclusive with `data`.
|
|
47
|
+
*/
|
|
48
|
+
signals: Type.Optional(Type.Array(Type.Object({
|
|
49
|
+
asset: Type.String(),
|
|
50
|
+
direction: Type.Optional(Type.String()),
|
|
51
|
+
score: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
52
|
+
signal_type: Type.Optional(Type.String()),
|
|
53
|
+
data: Type.Record(Type.String(), Type.Unknown()),
|
|
54
|
+
}))),
|
|
55
|
+
}, { additionalProperties: false });
|
|
56
|
+
/** TypeBox schema for the full `POST /signals` request body array. */
|
|
57
|
+
export const SignalsBody = Type.Array(SignalItem, { minItems: 1 });
|
|
58
|
+
//# sourceMappingURL=signals.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.schema.js","sourceRoot":"","sources":["../../../src/runtime-api/routes/signals.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AAEtD,+DAA+D;AAC/D,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CACnC;IACE,oEAAoE;IACpE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACtC,6BAA6B;IAC7B,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACtC,0CAA0C;IAC1C,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACnC;;;OAGG;IACH,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACvC,2DAA2D;IAC3D,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7D,mEAAmE;IACnE,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACzC;;;OAGG;IACH,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/D;;;OAGG;IACH,OAAO,EAAE,IAAI,CAAC,QAAQ,CACpB,IAAI,CAAC,KAAK,CACR,IAAI,CAAC,MAAM,CAAC;QACV,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;QACpB,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACvC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;QAC7D,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACzC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;KACjD,CAAC,CACH,CACF;CACF,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAChC,CAAC;AAEF,sEAAsE;AACtE,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify route: `GET /state`.
|
|
3
|
+
*
|
|
4
|
+
* Returns the full {@link RuntimeSystemState} for every running runtime —
|
|
5
|
+
* the same shape `senpi runtime state --json` returns over the OpenClaw
|
|
6
|
+
* gateway, exposed here over HTTP for callers (e.g. the producer wrapper's
|
|
7
|
+
* daemon liveness check) that don't want a gateway dependency.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors the existing CLI separation:
|
|
10
|
+
* - {@link registerHealthRoute `/health`} — lightweight readiness probe
|
|
11
|
+
* suitable for LB / Kubernetes probes (returns wallet + queue depth only).
|
|
12
|
+
* - `/state` (this route) — full runtime state including registered
|
|
13
|
+
* scanners, action handles, DSL state, risk gates.
|
|
14
|
+
*
|
|
15
|
+
* HTTP status:
|
|
16
|
+
* - `200` with envelope `{ success: true, data: { runtimes: [...] } }` on
|
|
17
|
+
* success. Always 200 — the response is informational; an empty
|
|
18
|
+
* `runtimes` array is a valid answer ("no runtimes registered").
|
|
19
|
+
* - `503` on internal error from a `getSystemState()` call. Surfaces
|
|
20
|
+
* the senpi-stack error envelope.
|
|
21
|
+
*
|
|
22
|
+
* Optional filter: `?address=0x...` returns only the runtime matching
|
|
23
|
+
* that wallet address (case-insensitive). Saves bytes per probe when a
|
|
24
|
+
* caller only cares about its own wallet.
|
|
25
|
+
*/
|
|
26
|
+
import type { FastifyInstance } from "fastify";
|
|
27
|
+
import type { RuntimeHandle } from "../../runtime/run.js";
|
|
28
|
+
import type { Logger } from "../../utils/logger.js";
|
|
29
|
+
/**
|
|
30
|
+
* Dependencies injected into the `/state` route at registration time.
|
|
31
|
+
*/
|
|
32
|
+
export interface StateRouteDeps {
|
|
33
|
+
/** Live runtime handles maintained by the plugin, keyed by lowercased address. */
|
|
34
|
+
runtimeHandles: Map<string, RuntimeHandle>;
|
|
35
|
+
/** Logger instance for unexpected errors. */
|
|
36
|
+
logger: Logger;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Register `GET /state` on the given Fastify instance.
|
|
40
|
+
*
|
|
41
|
+
* Iterates runtime handles, calls `getSystemState()` on each, returns the
|
|
42
|
+
* collected list under `data.runtimes[]`. A handle whose `getSystemState()`
|
|
43
|
+
* returns `null` (runtime is mid-startup or mid-shutdown) is omitted from
|
|
44
|
+
* the result rather than included as a sentinel — callers waiting for a
|
|
45
|
+
* specific wallet should re-probe rather than try to interpret a null.
|
|
46
|
+
*
|
|
47
|
+
* @param fastify Fastify instance to register the route on.
|
|
48
|
+
* @param deps Route dependencies injected at plugin start.
|
|
49
|
+
*/
|
|
50
|
+
export declare function registerStateRoute(fastify: FastifyInstance, deps: StateRouteDeps): void;
|
|
51
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/runtime-api/routes/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kFAAkF;IAClF,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;CAChB;AAeD;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,cAAc,GACnB,IAAI,CAkDN"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fastify route: `GET /state`.
|
|
3
|
+
*
|
|
4
|
+
* Returns the full {@link RuntimeSystemState} for every running runtime —
|
|
5
|
+
* the same shape `senpi runtime state --json` returns over the OpenClaw
|
|
6
|
+
* gateway, exposed here over HTTP for callers (e.g. the producer wrapper's
|
|
7
|
+
* daemon liveness check) that don't want a gateway dependency.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors the existing CLI separation:
|
|
10
|
+
* - {@link registerHealthRoute `/health`} — lightweight readiness probe
|
|
11
|
+
* suitable for LB / Kubernetes probes (returns wallet + queue depth only).
|
|
12
|
+
* - `/state` (this route) — full runtime state including registered
|
|
13
|
+
* scanners, action handles, DSL state, risk gates.
|
|
14
|
+
*
|
|
15
|
+
* HTTP status:
|
|
16
|
+
* - `200` with envelope `{ success: true, data: { runtimes: [...] } }` on
|
|
17
|
+
* success. Always 200 — the response is informational; an empty
|
|
18
|
+
* `runtimes` array is a valid answer ("no runtimes registered").
|
|
19
|
+
* - `503` on internal error from a `getSystemState()` call. Surfaces
|
|
20
|
+
* the senpi-stack error envelope.
|
|
21
|
+
*
|
|
22
|
+
* Optional filter: `?address=0x...` returns only the runtime matching
|
|
23
|
+
* that wallet address (case-insensitive). Saves bytes per probe when a
|
|
24
|
+
* caller only cares about its own wallet.
|
|
25
|
+
*/
|
|
26
|
+
import { Type } from "@sinclair/typebox";
|
|
27
|
+
/**
|
|
28
|
+
* Query schema for `/state`. All filters are optional.
|
|
29
|
+
*/
|
|
30
|
+
const StateQuery = Type.Object({
|
|
31
|
+
/** Filter to a single wallet address (case-insensitive). */
|
|
32
|
+
address: Type.Optional(Type.String({
|
|
33
|
+
pattern: "^0[xX][0-9a-fA-F]{40}$",
|
|
34
|
+
description: "Strategy wallet address (0x-prefixed, 40 hex chars).",
|
|
35
|
+
})),
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Register `GET /state` on the given Fastify instance.
|
|
39
|
+
*
|
|
40
|
+
* Iterates runtime handles, calls `getSystemState()` on each, returns the
|
|
41
|
+
* collected list under `data.runtimes[]`. A handle whose `getSystemState()`
|
|
42
|
+
* returns `null` (runtime is mid-startup or mid-shutdown) is omitted from
|
|
43
|
+
* the result rather than included as a sentinel — callers waiting for a
|
|
44
|
+
* specific wallet should re-probe rather than try to interpret a null.
|
|
45
|
+
*
|
|
46
|
+
* @param fastify Fastify instance to register the route on.
|
|
47
|
+
* @param deps Route dependencies injected at plugin start.
|
|
48
|
+
*/
|
|
49
|
+
export function registerStateRoute(fastify, deps) {
|
|
50
|
+
fastify.get("/state", { schema: { querystring: StateQuery } }, async (req, reply) => {
|
|
51
|
+
const q = req.query;
|
|
52
|
+
const filterAddress = q.address?.toLowerCase();
|
|
53
|
+
// The runtimeHandles map is keyed by runtime id (e.g.
|
|
54
|
+
// "pangolin-tracker-68ef"), NOT by wallet address — so address
|
|
55
|
+
// filtering must walk values and compare `handle.wallet`. N is
|
|
56
|
+
// small (typically 1–2 runtimes per host), so the O(N) walk is
|
|
57
|
+
// negligible compared to the per-handle getSystemState() that
|
|
58
|
+
// follows.
|
|
59
|
+
const allHandles = Array.from(deps.runtimeHandles.values());
|
|
60
|
+
const handles = filterAddress !== undefined
|
|
61
|
+
? allHandles.filter((h) => h.wallet.toLowerCase() === filterAddress)
|
|
62
|
+
: allHandles;
|
|
63
|
+
const collected = [];
|
|
64
|
+
for (const handle of handles) {
|
|
65
|
+
try {
|
|
66
|
+
const state = await handle.getSystemState();
|
|
67
|
+
if (state !== null)
|
|
68
|
+
collected.push(state);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
deps.logger.error("[senpi-core][runtime-api] /state getSystemState failed", {
|
|
72
|
+
err,
|
|
73
|
+
wallet: handle.wallet,
|
|
74
|
+
});
|
|
75
|
+
return reply.status(503).send({
|
|
76
|
+
success: false,
|
|
77
|
+
error: {
|
|
78
|
+
code: "UNAVAILABLE",
|
|
79
|
+
message: err instanceof Error
|
|
80
|
+
? `getSystemState failed: ${err.message}`
|
|
81
|
+
: "getSystemState failed",
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return reply
|
|
87
|
+
.header("Cache-Control", "no-store")
|
|
88
|
+
.send({
|
|
89
|
+
success: true,
|
|
90
|
+
data: { runtimes: collected },
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/runtime-api/routes/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAezC;;GAEG;AACH,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;IAC7B,4DAA4D;IAC5D,OAAO,EAAE,IAAI,CAAC,QAAQ,CACpB,IAAI,CAAC,MAAM,CAAC;QACV,OAAO,EAAE,wBAAwB;QACjC,WAAW,EAAE,sDAAsD;KACpE,CAAC,CACH;CACF,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAwB,EACxB,IAAoB;IAEpB,OAAO,CAAC,GAAG,CACT,QAAQ,EACR,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,EACvC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QACnB,MAAM,CAAC,GAAG,GAAG,CAAC,KAAkC,CAAC;QACjD,MAAM,aAAa,GAAG,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC;QAE/C,sDAAsD;QACtD,+DAA+D;QAC/D,+DAA+D;QAC/D,+DAA+D;QAC/D,8DAA8D;QAC9D,WAAW;QACX,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5D,MAAM,OAAO,GAAG,aAAa,KAAK,SAAS;YACzC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,aAAa,CAAC;YACpE,CAAC,CAAC,UAAU,CAAC;QAEf,MAAM,SAAS,GAAyB,EAAE,CAAC;QAC3C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,cAAc,EAAE,CAAC;gBAC5C,IAAI,KAAK,KAAK,IAAI;oBAAE,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC5C,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wDAAwD,EAAE;oBAC1E,GAAG;oBACH,MAAM,EAAE,MAAM,CAAC,MAAM;iBACtB,CAAC,CAAC;gBACH,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBAC5B,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE;wBACL,IAAI,EAAE,aAAa;wBACnB,OAAO,EACL,GAAG,YAAY,KAAK;4BAClB,CAAC,CAAC,0BAA0B,GAAG,CAAC,OAAO,EAAE;4BACzC,CAAC,CAAC,uBAAuB;qBAC9B;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,KAAK;aACT,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC;aACnC,IAAI,CAAC;YACJ,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE;SAC9B,CAAC,CAAC;IACP,CAAC,CACF,CAAC;AACJ,CAAC"}
|