@senpi-ai/runtime 1.0.97 → 1.0.98
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
package/dist/index.js
CHANGED
|
@@ -3,7 +3,27 @@
|
|
|
3
3
|
* actions, scanners, dsl, risk, health.
|
|
4
4
|
* Default export: OpenClaw plugin entry (register(api)).
|
|
5
5
|
* Named export run(): programmatic/standalone entry.
|
|
6
|
+
*
|
|
7
|
+
* Why this file is monolithic (vs. a thin wrapper that imports ./plugin.js):
|
|
8
|
+
* openclaw 2026.2.22's plugin loader follows relative imports from the
|
|
9
|
+
* entry through a CJS-fallback path that rejects `import.meta` syntax.
|
|
10
|
+
* The wrapper-style entry introduced in d919805 broke loadability for
|
|
11
|
+
* that reason. Keeping every export in a single file (this one) avoids
|
|
12
|
+
* the loader's relative-import path entirely.
|
|
6
13
|
*/
|
|
14
|
+
// dd-trace init MUST be the first executable statement in this file so it
|
|
15
|
+
// patches Node core modules (http, fs, etc.) before any traceable resource is
|
|
16
|
+
// constructed by the imports below. Gated on DD_TRACE_ENABLED=true so unit
|
|
17
|
+
// tests and standalone CLI invocations do not pay the init cost.
|
|
18
|
+
// `createRequire` is used because `dd-trace` is a CJS module and our
|
|
19
|
+
// tsconfig uses Node16 modules — a top-level `import "dd-trace"` would
|
|
20
|
+
// be hoisted above this gate by the bundler/loader.
|
|
21
|
+
import { createRequire } from "node:module";
|
|
22
|
+
const __require = createRequire(import.meta.url);
|
|
23
|
+
if (process.env.DD_TRACE_ENABLED === "true") {
|
|
24
|
+
__require("dd-trace").init();
|
|
25
|
+
}
|
|
26
|
+
import { readFileSync } from "node:fs";
|
|
7
27
|
import { join } from "node:path";
|
|
8
28
|
import { SenpiClient } from "./senpi/client.js";
|
|
9
29
|
import { buildRuntimeStateDir, archiveStateDir } from "./runtime/state-layout.js";
|
|
@@ -20,7 +40,14 @@ import { initDsl } from "./dsl/index.js";
|
|
|
20
40
|
import { initHealth } from "./health/index.js";
|
|
21
41
|
import { initRisk } from "./risk/index.js";
|
|
22
42
|
import { VERSION } from "./version.js";
|
|
23
|
-
import {
|
|
43
|
+
import { BUS_EVENT_MAP } from "./tracking/constants.js";
|
|
44
|
+
import { createPluginEventTracker } from "./tracking/plugin-event-tracker.js";
|
|
45
|
+
import { getLogLevel, getLogLevelSource, parseLogLevel, setErrorNotifier, setLogLevel, } from "./utils/logger.js";
|
|
46
|
+
import { ExternalScannerIngestError, } from "./scanners/external-scanner-receiver.js";
|
|
47
|
+
import { createLogger } from "./utils/logger.js";
|
|
48
|
+
import { loadApiConfig } from "./runtime-api/config.js";
|
|
49
|
+
import { startApi } from "./runtime-api/lifecycle.js";
|
|
50
|
+
import { ingestSignalsHandler } from "./runtime-api/handlers/ingest-signals.js";
|
|
24
51
|
/** Initialize all core features (DSL, risk, health) on the given event bus. */
|
|
25
52
|
export function initCore(bus) {
|
|
26
53
|
initDsl(bus);
|
|
@@ -134,6 +161,29 @@ function fireAndForgetErrorNotification(notifications, message) {
|
|
|
134
161
|
// Intentionally swallow; error notifications must never fail call sites.
|
|
135
162
|
}
|
|
136
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Read the plugin version from the sibling `openclaw.plugin.json` manifest.
|
|
166
|
+
* Performed once at module load — the manifest is shipped alongside the
|
|
167
|
+
* compiled `dist/index.js` so the relative URL resolves at runtime.
|
|
168
|
+
*
|
|
169
|
+
* Falls back to the imported `VERSION` constant (compiled into the bundle)
|
|
170
|
+
* if the manifest cannot be read; both should always agree.
|
|
171
|
+
*/
|
|
172
|
+
function readPluginManifestVersion() {
|
|
173
|
+
try {
|
|
174
|
+
const manifestUrl = new URL("../openclaw.plugin.json", import.meta.url);
|
|
175
|
+
const raw = readFileSync(manifestUrl, "utf-8");
|
|
176
|
+
const parsed = JSON.parse(raw);
|
|
177
|
+
if (typeof parsed.version === "string" && parsed.version.length > 0) {
|
|
178
|
+
return parsed.version;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
// Fall through to VERSION fallback.
|
|
183
|
+
}
|
|
184
|
+
return VERSION;
|
|
185
|
+
}
|
|
186
|
+
const PLUGIN_MANIFEST_VERSION = readPluginManifestVersion();
|
|
137
187
|
/**
|
|
138
188
|
* OpenClaw plugin entry.
|
|
139
189
|
* Boots from internal registry (installed_runtimes.json) in stateDir; does not read runtime list from config.
|
|
@@ -163,6 +213,23 @@ const senpiRuntimePlugin = {
|
|
|
163
213
|
pluginLogger.warn("[senpi-runtime] No plugin config found — skipping registration");
|
|
164
214
|
return;
|
|
165
215
|
}
|
|
216
|
+
if (typeof config.logLevel === "string" && config.logLevel.length > 0) {
|
|
217
|
+
const parsed = parseLogLevel(config.logLevel);
|
|
218
|
+
if (parsed !== null) {
|
|
219
|
+
setLogLevel(parsed, "config");
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
pluginLogger.warn(`[senpi-runtime] Ignoring invalid plugin config logLevel="${config.logLevel}" (expected debug|info|warn|error); keeping ${getLogLevel()}.`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const startupLogLevel = getLogLevel();
|
|
226
|
+
const startupLogLevelSource = getLogLevelSource();
|
|
227
|
+
const logLevelSourceLabel = startupLogLevelSource === "config"
|
|
228
|
+
? "plugin config logLevel"
|
|
229
|
+
: startupLogLevelSource === "env"
|
|
230
|
+
? "env SENPI_LOG_LEVEL"
|
|
231
|
+
: "default";
|
|
232
|
+
pluginLogger.info(`[senpi-runtime] log level: ${startupLogLevel} (source: ${logLevelSourceLabel}). Set plugin config "logLevel" or env SENPI_LOG_LEVEL to debug|info|warn|error to override.`);
|
|
166
233
|
const senpiCliStore = readSenpiCliStore();
|
|
167
234
|
const baseStateDir = resolveSenpiBaseStateDir({
|
|
168
235
|
store: senpiCliStore,
|
|
@@ -178,7 +245,13 @@ const senpiRuntimePlugin = {
|
|
|
178
245
|
pluginLogger.error("[senpi-runtime] mcpTransport or apiKey is required (provide via gateway, api, or config)");
|
|
179
246
|
return;
|
|
180
247
|
}
|
|
248
|
+
const pluginEventTracker = createPluginEventTracker(apiKey ?? process.env.SENPI_API_KEY);
|
|
181
249
|
const runtimeHandles = new Map();
|
|
250
|
+
let apiHandle;
|
|
251
|
+
// Dedicated logger for the runtime-api subtree — required because the
|
|
252
|
+
// PluginLogger surface (info/warn/error) lacks `debug`, while the
|
|
253
|
+
// Logger contract used by `runtime-api/` includes it.
|
|
254
|
+
const apiLogger = createLogger("[senpi-core][api]");
|
|
182
255
|
const lifecycleChatId = resolveTelegramChatIdFromStore(senpiCliStore);
|
|
183
256
|
const lifecycleNotifications = lifecycleChatId
|
|
184
257
|
? createNotificationService({
|
|
@@ -271,6 +344,48 @@ const senpiRuntimePlugin = {
|
|
|
271
344
|
throw err;
|
|
272
345
|
}
|
|
273
346
|
pluginLogger.info(`[senpi-runtime] Started ${started.length} runtime${started.length === 1 ? "" : "s"}`);
|
|
347
|
+
// ── HTTP API ──────────────────────────────────────────────────────
|
|
348
|
+
// Bind the HTTP server AFTER runtimes are hydrated so `/health` and
|
|
349
|
+
// `/signals` see the live `runtimeHandles` map.
|
|
350
|
+
//
|
|
351
|
+
// If the API fails to bind (e.g. EADDRINUSE) we treat the lifecycle as
|
|
352
|
+
// a single transactional unit: stop the auto-update coordinator first
|
|
353
|
+
// (otherwise it could schedule a tick mid-rollback), then stop every
|
|
354
|
+
// runtime handle that was already hydrated, then re-throw. The goal
|
|
355
|
+
// is "either everything is up or nothing is" — so openclaw never sees
|
|
356
|
+
// a half-started state where some runtimes are alive but the API
|
|
357
|
+
// they expect to be reachable on isn't.
|
|
358
|
+
//
|
|
359
|
+
// SENPI_RUNTIME_API_DISABLED=true skips API startup. Used by unit
|
|
360
|
+
// tests that exercise `plugin.register()` in parallel workers without
|
|
361
|
+
// contending for the same TCP port.
|
|
362
|
+
if (process.env.SENPI_RUNTIME_API_DISABLED !== "true") {
|
|
363
|
+
try {
|
|
364
|
+
const apiConfig = loadApiConfig(api.pluginConfig);
|
|
365
|
+
apiHandle = await startApi({
|
|
366
|
+
runtimeHandles,
|
|
367
|
+
apiConfig,
|
|
368
|
+
logger: apiLogger,
|
|
369
|
+
version: PLUGIN_MANIFEST_VERSION,
|
|
370
|
+
});
|
|
371
|
+
apiHandle.ready();
|
|
372
|
+
}
|
|
373
|
+
catch (err) {
|
|
374
|
+
pluginLogger.error("[senpi-runtime] HTTP API failed to start; rolling back lifecycle", { err });
|
|
375
|
+
// Mirror the lifecycle-stop teardown order: stop the coordinator
|
|
376
|
+
// first so it cannot schedule a tick or call stopRuntimesForUpdate
|
|
377
|
+
// mid-rollback, then stop every runtime handle that was hydrated
|
|
378
|
+
// above.
|
|
379
|
+
await autoUpdateCoordinator.stop().catch(() => { });
|
|
380
|
+
for (let i = started.length - 1; i >= 0; i--) {
|
|
381
|
+
const h = runtimeHandles.get(started[i]);
|
|
382
|
+
if (h)
|
|
383
|
+
await h.stop().catch(() => { });
|
|
384
|
+
runtimeHandles.delete(started[i]);
|
|
385
|
+
}
|
|
386
|
+
throw err;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
274
389
|
if (lifecycleNotifications) {
|
|
275
390
|
const n = started.length;
|
|
276
391
|
lifecycleNotifications
|
|
@@ -285,9 +400,16 @@ const senpiRuntimePlugin = {
|
|
|
285
400
|
if (lifecycleNotifications) {
|
|
286
401
|
lifecycleNotifications.notify("Senpi shutting down.").catch(() => { });
|
|
287
402
|
}
|
|
288
|
-
//
|
|
289
|
-
//
|
|
290
|
-
//
|
|
403
|
+
// Drain the HTTP server FIRST so in-flight POST /signals requests
|
|
404
|
+
// finish before the underlying runtime they target is torn down.
|
|
405
|
+
// `apiHandle.close()` never throws.
|
|
406
|
+
if (apiHandle) {
|
|
407
|
+
await apiHandle.close();
|
|
408
|
+
apiHandle = undefined;
|
|
409
|
+
}
|
|
410
|
+
// Stop the coordinator next so it cannot schedule a new tick or call
|
|
411
|
+
// stopRuntimesForUpdate() (auto-restart path after an update) while
|
|
412
|
+
// we are tearing down the handles below.
|
|
291
413
|
await autoUpdateCoordinator.stop();
|
|
292
414
|
const ids = Array.from(runtimeHandles.keys());
|
|
293
415
|
for (let i = ids.length - 1; i >= 0; i--) {
|
|
@@ -297,6 +419,13 @@ const senpiRuntimePlugin = {
|
|
|
297
419
|
runtimeHandles.delete(ids[i]);
|
|
298
420
|
}
|
|
299
421
|
pluginLogger.info("[senpi-runtime] All runtimes stopped");
|
|
422
|
+
// Flush plugin-scoped telemetry (lifecycle.runtime.created/deleted); otherwise
|
|
423
|
+
// BatchingTransport may still hold buffered events until the interval fires.
|
|
424
|
+
await pluginEventTracker.shutdown().catch((err) => {
|
|
425
|
+
pluginLogger.warn("[senpi-runtime] plugin telemetry shutdown failed", {
|
|
426
|
+
err: err instanceof Error ? err.message : String(err),
|
|
427
|
+
});
|
|
428
|
+
});
|
|
300
429
|
},
|
|
301
430
|
});
|
|
302
431
|
pluginLogger.info("[senpi-runtime] calling api.registerCli(..., { commands: ['senpi'] })");
|
|
@@ -443,6 +572,21 @@ const senpiRuntimePlugin = {
|
|
|
443
572
|
}
|
|
444
573
|
registry.runtimes.push(entry);
|
|
445
574
|
await writeRegistry(baseStateDir, registry);
|
|
575
|
+
const createdMapping = BUS_EVENT_MAP["tracking.runtime_created"];
|
|
576
|
+
pluginEventTracker.capture({
|
|
577
|
+
eventType: createdMapping.eventType,
|
|
578
|
+
category: createdMapping.category,
|
|
579
|
+
address: wallet,
|
|
580
|
+
data: {
|
|
581
|
+
id: resolvedId,
|
|
582
|
+
name: runtimeName,
|
|
583
|
+
wallet,
|
|
584
|
+
schemaVersion: parsedSchemaVersion,
|
|
585
|
+
source: hasPath ? "file" : "inline",
|
|
586
|
+
config: entry,
|
|
587
|
+
timestamp: new Date().toISOString(),
|
|
588
|
+
},
|
|
589
|
+
});
|
|
446
590
|
try {
|
|
447
591
|
const scannerProviders = await createScannerProvidersForRun({
|
|
448
592
|
mcpTransport,
|
|
@@ -504,29 +648,146 @@ const senpiRuntimePlugin = {
|
|
|
504
648
|
});
|
|
505
649
|
return;
|
|
506
650
|
}
|
|
651
|
+
const deletedEntry = registry.runtimes.find((e) => e.id === targetId);
|
|
507
652
|
const handle = runtimeHandles.get(targetId);
|
|
653
|
+
if (!deletedEntry && !handle) {
|
|
654
|
+
respond(false, undefined, {
|
|
655
|
+
code: "NOT_FOUND",
|
|
656
|
+
message: `No runtime found with id "${targetId}".`,
|
|
657
|
+
});
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
const targetWallet = deletedEntry?.wallet ??
|
|
661
|
+
handle?.wallet ??
|
|
662
|
+
(typeof targetAddress === "string" ? targetAddress : "");
|
|
663
|
+
let openPositionsAbandoned = 0;
|
|
664
|
+
let archivePath;
|
|
508
665
|
if (handle) {
|
|
509
|
-
await handle.teardownDslForRuntimeDeletion();
|
|
666
|
+
openPositionsAbandoned = await handle.teardownDslForRuntimeDeletion();
|
|
510
667
|
await handle.stop();
|
|
511
668
|
runtimeHandles.delete(targetId);
|
|
512
669
|
}
|
|
513
670
|
// Archive state directory before removing from registry
|
|
514
|
-
const deletedEntry = registry.runtimes.find((e) => e.id === targetId);
|
|
515
671
|
if (deletedEntry) {
|
|
516
672
|
const runtimeStateDir = buildRuntimeStateDir(baseStateDir, targetId, deletedEntry.wallet ?? "");
|
|
517
673
|
const archivesDir = join(baseStateDir, "archives");
|
|
518
674
|
try {
|
|
519
|
-
|
|
675
|
+
archivePath = await archiveStateDir(runtimeStateDir, archivesDir, targetId, deletedEntry.wallet ?? "");
|
|
520
676
|
api.logger.info(`[senpi-runtime] Archived state to ${archivePath}`);
|
|
521
677
|
}
|
|
522
678
|
catch (err) {
|
|
523
679
|
api.logger.warn("[senpi-runtime] Failed to archive state dir", { err });
|
|
524
680
|
}
|
|
525
681
|
}
|
|
526
|
-
const
|
|
527
|
-
|
|
682
|
+
const deletedMapping = BUS_EVENT_MAP["tracking.runtime_deleted"];
|
|
683
|
+
pluginEventTracker.capture({
|
|
684
|
+
eventType: deletedMapping.eventType,
|
|
685
|
+
category: deletedMapping.category,
|
|
686
|
+
address: targetWallet,
|
|
687
|
+
data: {
|
|
688
|
+
id: targetId,
|
|
689
|
+
wallet: targetWallet,
|
|
690
|
+
schemaVersion: deletedEntry?.schemaVersion,
|
|
691
|
+
reason: "user_initiated",
|
|
692
|
+
openPositionsAbandoned,
|
|
693
|
+
...(typeof archivePath === "string" ? { archivedAt: archivePath } : {}),
|
|
694
|
+
timestamp: new Date().toISOString(),
|
|
695
|
+
},
|
|
696
|
+
});
|
|
697
|
+
if (deletedEntry) {
|
|
698
|
+
const next = registry.runtimes.filter((e) => e.id !== targetId);
|
|
699
|
+
await writeRegistry(baseStateDir, { ...registry, runtimes: next });
|
|
700
|
+
}
|
|
528
701
|
respond(true, { id: targetId });
|
|
529
702
|
});
|
|
703
|
+
/**
|
|
704
|
+
* Gateway shim for `senpi.ingestExternalScannerData`.
|
|
705
|
+
*
|
|
706
|
+
* Thin wrapper over the shared {@link ingestSignalsHandler} that backs
|
|
707
|
+
* `POST /signals`. Both transports go through the same in-process logic;
|
|
708
|
+
* this shim only translates between the legacy gateway envelope and the
|
|
709
|
+
* shared handler's per-item discriminant.
|
|
710
|
+
*
|
|
711
|
+
* Response shape is preserved for backward compatibility with existing
|
|
712
|
+
* producers — slated for removal in Task 5 once the migration counter
|
|
713
|
+
* decays to zero (see `runtime-phase-2-api-plan.md` Section 8).
|
|
714
|
+
*/
|
|
715
|
+
api.registerGatewayMethod("senpi.ingestExternalScannerData", async (ctx) => {
|
|
716
|
+
const respond = ctx.respond;
|
|
717
|
+
// TODO(s11): wire actual telemetry counter for
|
|
718
|
+
// runtime.deprecated_gateway_ingest_call (event name, properties:
|
|
719
|
+
// { address, scanner }). Reuse the existing tracking transport once
|
|
720
|
+
// it is plumbed through the plugin lifecycle in S11.
|
|
721
|
+
try {
|
|
722
|
+
const { address, request } = parseGatewayExternalScannerIngestParams(ctx.params);
|
|
723
|
+
pluginLogger.info("[senpi-runtime] senpi.ingestExternalScannerData", {
|
|
724
|
+
address,
|
|
725
|
+
scanner: request.scanner,
|
|
726
|
+
});
|
|
727
|
+
const item = {
|
|
728
|
+
address,
|
|
729
|
+
scanner: request.scanner,
|
|
730
|
+
...(request.asset !== undefined && { asset: request.asset }),
|
|
731
|
+
...(request.direction !== undefined && { direction: request.direction }),
|
|
732
|
+
...(request.score !== undefined && { score: request.score }),
|
|
733
|
+
...(request.signal_type !== undefined && { signal_type: request.signal_type }),
|
|
734
|
+
...(request.data !== undefined && { data: request.data }),
|
|
735
|
+
...(request.signals !== undefined && { signals: request.signals }),
|
|
736
|
+
};
|
|
737
|
+
const result = await ingestSignalsHandler(item, {
|
|
738
|
+
runtimeHandles,
|
|
739
|
+
logger: apiLogger,
|
|
740
|
+
transport: "gateway",
|
|
741
|
+
});
|
|
742
|
+
if (result.success) {
|
|
743
|
+
respond(true, {
|
|
744
|
+
accepted: true,
|
|
745
|
+
address: result.address,
|
|
746
|
+
scanner: result.scanner,
|
|
747
|
+
timestamp: result.timestamp,
|
|
748
|
+
signalCount: result.signalCount,
|
|
749
|
+
contextUpdated: result.contextUpdated,
|
|
750
|
+
});
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
// Preserve the legacy "Failed to ingest external scanner data: ..."
|
|
754
|
+
// prefix on UNAVAILABLE so existing callers see the same error text
|
|
755
|
+
// they see today. INVALID_REQUEST and NOT_FOUND messages are already
|
|
756
|
+
// descriptive on their own and pass through unchanged.
|
|
757
|
+
if (result.code === "UNAVAILABLE") {
|
|
758
|
+
respond(false, undefined, {
|
|
759
|
+
code: "UNAVAILABLE",
|
|
760
|
+
message: `Failed to ingest external scanner data: ${result.message}`,
|
|
761
|
+
});
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
respond(false, undefined, {
|
|
765
|
+
code: result.code,
|
|
766
|
+
message: result.message,
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
catch (error) {
|
|
770
|
+
// `parseGatewayExternalScannerIngestParams` throws synchronously for
|
|
771
|
+
// malformed routing fields. The shared handler never throws — any
|
|
772
|
+
// other error here is unexpected.
|
|
773
|
+
if (error instanceof ExternalScannerIngestError) {
|
|
774
|
+
respond(false, undefined, {
|
|
775
|
+
code: error.code,
|
|
776
|
+
message: error.message,
|
|
777
|
+
});
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
pluginLogger.warn("[senpi-runtime] ingestExternalScannerData error", {
|
|
781
|
+
address: typeof ctx.params?.address === "string" ? ctx.params.address : undefined,
|
|
782
|
+
scanner: typeof ctx.params?.scanner === "string" ? ctx.params.scanner : undefined,
|
|
783
|
+
err: error,
|
|
784
|
+
});
|
|
785
|
+
respond(false, undefined, {
|
|
786
|
+
code: "UNAVAILABLE",
|
|
787
|
+
message: `Failed to ingest external scanner data: ${formatGatewayError(error)}`,
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
});
|
|
530
791
|
api.registerGatewayMethod("senpi.listDslPositions", async (ctx) => {
|
|
531
792
|
const respond = ctx.respond;
|
|
532
793
|
const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
|
|
@@ -675,6 +936,156 @@ const senpiRuntimePlugin = {
|
|
|
675
936
|
const states = await collectRuntimeSystemStates(runtimeHandles, api.logger, baseStateDir);
|
|
676
937
|
respond(true, { states, updater });
|
|
677
938
|
});
|
|
939
|
+
/**
|
|
940
|
+
* Action layer — read-only inspection.
|
|
941
|
+
*
|
|
942
|
+
* Three sibling methods (`senpi.listActions`, `senpi.getActionState`,
|
|
943
|
+
* `senpi.getActionHistory`) back the `openclaw senpi action …`
|
|
944
|
+
* subcommand family. They are intentionally read-only: they never
|
|
945
|
+
* mutate persisted state, never trigger an action, and never call the
|
|
946
|
+
* decision engine. All three resolve their `address` argument from
|
|
947
|
+
* caller params first, then fall back to the runtime handle's own
|
|
948
|
+
* `wallet`, so the CLI can omit `-a` for single-strategy runtimes.
|
|
949
|
+
*
|
|
950
|
+
* History note: these three methods were unregistered from
|
|
951
|
+
* `2026-04-16` (`15a51d7` "merge conflict resolution") through this
|
|
952
|
+
* fix — the CLI shipped wired against gateway methods that no longer
|
|
953
|
+
* existed, so the four `action` subcommands all returned
|
|
954
|
+
* `unknown method: senpi.getActionHistory`. Restoring them keeps the
|
|
955
|
+
* persisted action-store machinery (`src/actions/store/`) usable
|
|
956
|
+
* from the operator-facing CLI again.
|
|
957
|
+
*/
|
|
958
|
+
api.registerGatewayMethod("senpi.listActions", async (ctx) => {
|
|
959
|
+
const respond = ctx.respond;
|
|
960
|
+
const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
|
|
961
|
+
const address = typeof ctx.params?.address === "string" ? ctx.params.address : undefined;
|
|
962
|
+
const actionName = typeof ctx.params?.actionName === "string" ? ctx.params.actionName : undefined;
|
|
963
|
+
const filter = {};
|
|
964
|
+
if (address) {
|
|
965
|
+
filter.address = address;
|
|
966
|
+
}
|
|
967
|
+
if (actionName) {
|
|
968
|
+
filter.actionName = actionName;
|
|
969
|
+
}
|
|
970
|
+
const hasFilter = Object.keys(filter).length > 0;
|
|
971
|
+
const merged = [];
|
|
972
|
+
for (const [id, handle] of runtimeHandles) {
|
|
973
|
+
if (runtimeId && id !== runtimeId) {
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
try {
|
|
977
|
+
const items = await handle.listActionLatestStates(hasFilter ? filter : undefined);
|
|
978
|
+
for (const a of items) {
|
|
979
|
+
merged.push({ ...a, runtimeId: id });
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
catch (err) {
|
|
983
|
+
api.logger.warn("[senpi-runtime] listActions error", { runtimeId: id, err });
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
respond(true, { actions: merged });
|
|
987
|
+
});
|
|
988
|
+
api.registerGatewayMethod("senpi.getActionState", async (ctx) => {
|
|
989
|
+
const respond = ctx.respond;
|
|
990
|
+
const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
|
|
991
|
+
const actionName = typeof ctx.params?.actionName === "string" ? ctx.params.actionName : undefined;
|
|
992
|
+
if (!runtimeId || !actionName) {
|
|
993
|
+
respond(false, undefined, {
|
|
994
|
+
code: "INVALID_REQUEST",
|
|
995
|
+
message: "runtimeId and actionName are required",
|
|
996
|
+
});
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
const handle = getRuntimeHandleOrRespond(runtimeHandles, runtimeId, respond);
|
|
1000
|
+
if (!handle) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
const resolvedAddress = typeof ctx.params?.address === "string" && ctx.params.address.length > 0
|
|
1004
|
+
? ctx.params.address
|
|
1005
|
+
: handle.wallet;
|
|
1006
|
+
if (!resolvedAddress) {
|
|
1007
|
+
respond(false, undefined, {
|
|
1008
|
+
code: "INVALID_REQUEST",
|
|
1009
|
+
message: "address is required when the runtime wallet is unknown",
|
|
1010
|
+
});
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
try {
|
|
1014
|
+
const latest = await handle.getActionLatestState(resolvedAddress, actionName);
|
|
1015
|
+
respond(true, { latest });
|
|
1016
|
+
}
|
|
1017
|
+
catch (err) {
|
|
1018
|
+
api.logger.warn("[senpi-runtime] getActionState error", { runtimeId, err });
|
|
1019
|
+
respond(false, undefined, {
|
|
1020
|
+
code: "INTERNAL_ERROR",
|
|
1021
|
+
message: `Failed to read action state: ${formatGatewayError(err)}`,
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
api.registerGatewayMethod("senpi.getActionHistory", async (ctx) => {
|
|
1026
|
+
const respond = ctx.respond;
|
|
1027
|
+
const runtimeId = typeof ctx.params?.runtimeId === "string" ? ctx.params.runtimeId : undefined;
|
|
1028
|
+
const actionName = typeof ctx.params?.actionName === "string" ? ctx.params.actionName : undefined;
|
|
1029
|
+
if (!runtimeId) {
|
|
1030
|
+
respond(false, undefined, {
|
|
1031
|
+
code: "INVALID_REQUEST",
|
|
1032
|
+
message: "runtimeId is required",
|
|
1033
|
+
});
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
const handle = getRuntimeHandleOrRespond(runtimeHandles, runtimeId, respond);
|
|
1037
|
+
if (!handle) {
|
|
1038
|
+
api.logger.warn("[senpi-runtime] getActionHistory: no running runtime for the requested id", { runtimeId });
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
const resolvedAddress = typeof ctx.params?.address === "string" && ctx.params.address.length > 0
|
|
1042
|
+
? ctx.params.address
|
|
1043
|
+
: handle.wallet;
|
|
1044
|
+
if (!resolvedAddress) {
|
|
1045
|
+
respond(false, undefined, {
|
|
1046
|
+
code: "INVALID_REQUEST",
|
|
1047
|
+
message: "address is required when the runtime wallet is unknown",
|
|
1048
|
+
});
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
const limit = typeof ctx.params?.limit === "number" && ctx.params.limit > 0
|
|
1052
|
+
? ctx.params.limit
|
|
1053
|
+
: 50;
|
|
1054
|
+
// Pass through every value the underlying store and the CLI guide
|
|
1055
|
+
// already advertise (`ActionHistoryOutcomeFilter` =
|
|
1056
|
+
// "all" | "with_decision" | "executed"). "all" is the default
|
|
1057
|
+
// behaviour, so we collapse it to `undefined` and otherwise keep
|
|
1058
|
+
// "with_decision" / "executed" intact instead of silently dropping
|
|
1059
|
+
// them on the floor.
|
|
1060
|
+
const rawFilter = ctx.params?.outcomeFilter;
|
|
1061
|
+
const outcomeFilter = rawFilter === "with_decision" || rawFilter === "executed" ? rawFilter : undefined;
|
|
1062
|
+
try {
|
|
1063
|
+
if (actionName) {
|
|
1064
|
+
const history = await handle.getActionExecutionHistory(resolvedAddress, actionName, { limit, outcomeFilter });
|
|
1065
|
+
respond(true, { history });
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
// No actionName: merge histories across every action under this
|
|
1069
|
+
// wallet, then re-sort + cap to `limit`. The per-action fetch is
|
|
1070
|
+
// padded to `max(limit, 100)` so a small caller-supplied `limit`
|
|
1071
|
+
// doesn't truncate the merge before ordering globally.
|
|
1072
|
+
const latest = await handle.listActionLatestStates({ address: resolvedAddress });
|
|
1073
|
+
const records = [];
|
|
1074
|
+
for (const L of latest) {
|
|
1075
|
+
const part = await handle.getActionExecutionHistory(resolvedAddress, L.actionName, { limit: Math.max(limit, 100), outcomeFilter });
|
|
1076
|
+
records.push(...part);
|
|
1077
|
+
}
|
|
1078
|
+
records.sort((a, b) => b.startedAt - a.startedAt);
|
|
1079
|
+
respond(true, { history: records.slice(0, limit) });
|
|
1080
|
+
}
|
|
1081
|
+
catch (err) {
|
|
1082
|
+
api.logger.warn("[senpi-runtime] getActionHistory error", { runtimeId, err });
|
|
1083
|
+
respond(false, undefined, {
|
|
1084
|
+
code: "INTERNAL_ERROR",
|
|
1085
|
+
message: `Failed to read action history: ${formatGatewayError(err)}`,
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
678
1089
|
api.logger.info(`[senpi-runtime] v${VERSION} plugin registered — stateDir: ${baseStateDir}`);
|
|
679
1090
|
},
|
|
680
1091
|
};
|
|
@@ -689,6 +1100,43 @@ function getRuntimeHandleOrRespond(runtimeHandles, runtimeId, respond) {
|
|
|
689
1100
|
});
|
|
690
1101
|
return null;
|
|
691
1102
|
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Parse the gateway request shape for `senpi.ingestExternalScannerData`.
|
|
1105
|
+
*
|
|
1106
|
+
* The plugin contract keeps `address` at the gateway layer because the plugin
|
|
1107
|
+
* owns the map of running runtimes keyed by runtime id, while the runtime's
|
|
1108
|
+
* programmatic ingest API is already scoped to one strategy wallet. This
|
|
1109
|
+
* helper validates only the routing-critical fields (`address`, `scanner`) and
|
|
1110
|
+
* forwards the remaining payload as-is so the runtime keeps ownership of the
|
|
1111
|
+
* external-scanner data contract.
|
|
1112
|
+
*
|
|
1113
|
+
* @deprecated Used only by the `senpi.ingestExternalScannerData` gateway shim,
|
|
1114
|
+
* which itself is slated for removal in Task 5 of the runtime-phase-2-api plan
|
|
1115
|
+
* once external producers migrate to `POST /signals`. Delete alongside the
|
|
1116
|
+
* gateway-method registration in that task.
|
|
1117
|
+
*/
|
|
1118
|
+
function parseGatewayExternalScannerIngestParams(params) {
|
|
1119
|
+
const address = typeof params?.address === "string" ? params.address.trim() : "";
|
|
1120
|
+
if (!address) {
|
|
1121
|
+
throw new ExternalScannerIngestError("INVALID_REQUEST", "External scanner ingest requires address as a non-empty string.");
|
|
1122
|
+
}
|
|
1123
|
+
const scanner = typeof params?.scanner === "string" ? params.scanner.trim() : "";
|
|
1124
|
+
if (!scanner) {
|
|
1125
|
+
throw new ExternalScannerIngestError("INVALID_REQUEST", "External scanner ingest requires scanner as a non-empty string.");
|
|
1126
|
+
}
|
|
1127
|
+
return {
|
|
1128
|
+
address,
|
|
1129
|
+
request: {
|
|
1130
|
+
scanner,
|
|
1131
|
+
asset: params?.asset,
|
|
1132
|
+
direction: params?.direction,
|
|
1133
|
+
score: params?.score,
|
|
1134
|
+
signal_type: params?.signal_type,
|
|
1135
|
+
data: params?.data,
|
|
1136
|
+
signals: params?.signals,
|
|
1137
|
+
},
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
692
1140
|
async function collectRuntimeHealthStatuses(runtimeHandles, logger) {
|
|
693
1141
|
return (await Promise.all(Array.from(runtimeHandles, async ([runtimeId, handle]) => {
|
|
694
1142
|
try {
|
|
@@ -722,6 +1170,7 @@ function createGatewayHealthErrorStatus(runtimeId, error) {
|
|
|
722
1170
|
startedAt: now,
|
|
723
1171
|
generatedAt: now,
|
|
724
1172
|
health: "unhealthy",
|
|
1173
|
+
logLevel: getLogLevel(),
|
|
725
1174
|
components: {
|
|
726
1175
|
scanners: {
|
|
727
1176
|
component: "scanners",
|
|
@@ -751,6 +1200,7 @@ function createGatewaySystemStateError(runtimeId, stateDir, error) {
|
|
|
751
1200
|
startedAt: now,
|
|
752
1201
|
generatedAt: now,
|
|
753
1202
|
health: "unhealthy",
|
|
1203
|
+
logLevel: getLogLevel(),
|
|
754
1204
|
components: {
|
|
755
1205
|
scanners: {
|
|
756
1206
|
component: "scanners",
|