@senpi/trading-recipe 1.0.69 → 1.0.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/senpi-commands.d.ts.map +1 -1
- package/dist/cli/senpi-commands.js +135 -0
- package/dist/cli/senpi-commands.js.map +1 -1
- package/dist/dsl/plugin/index.d.ts +22 -0
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +189 -58
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/health/index.d.ts +22 -2
- package/dist/health/index.d.ts.map +1 -1
- package/dist/health/index.js +186 -4
- package/dist/health/index.js.map +1 -1
- package/dist/health/types.d.ts +114 -0
- package/dist/health/types.d.ts.map +1 -0
- package/dist/health/types.js +2 -0
- package/dist/health/types.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +147 -3
- package/dist/index.js.map +1 -1
- package/dist/runtime/run.d.ts +3 -0
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +6 -0
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime.d.ts +5 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +59 -2
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/scanners/engine/engine.d.ts +7 -0
- package/dist/scanners/engine/engine.d.ts.map +1 -1
- package/dist/scanners/engine/engine.js +20 -5
- package/dist/scanners/engine/engine.js.map +1 -1
- package/dist/scanners/engine/strategy-registry.d.ts +3 -0
- package/dist/scanners/engine/strategy-registry.d.ts.map +1 -1
- package/dist/scanners/engine/strategy-registry.js +10 -0
- package/dist/scanners/engine/strategy-registry.js.map +1 -1
- package/dist/scanners/runtime-module.d.ts +5 -0
- package/dist/scanners/runtime-module.d.ts.map +1 -1
- package/dist/scanners/runtime-module.js +247 -2
- package/dist/scanners/runtime-module.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/health/index.d.ts
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
|
+
import type { ComponentHealth, DslComponentHealthStatus, DslSystemState, RuntimeHealthStatus, RuntimeSystemState, ScannerComponentHealthStatus, ScannerSystemState, StateStatusProvider } from "./types.js";
|
|
2
|
+
export type { ComponentHealth, ComponentHealthStatus, ComponentSystemState, DslComponentHealthStatus, DslSystemState, RuntimeHealthStatus, RuntimeSystemState, ScannerComponentHealthStatus, ScannerRegistrationSystemState, ScannerSystemState, StateStatusProvider, } from "./types.js";
|
|
3
|
+
type HealthProviderMap = {
|
|
4
|
+
scanners: StateStatusProvider<ScannerComponentHealthStatus, ScannerSystemState>;
|
|
5
|
+
dsl?: StateStatusProvider<DslComponentHealthStatus, DslSystemState>;
|
|
6
|
+
};
|
|
7
|
+
export interface CreateHealthStateModuleOptions {
|
|
8
|
+
recipeId?: string;
|
|
9
|
+
recipeName: string;
|
|
10
|
+
stateDir: string;
|
|
11
|
+
startedAt?: number;
|
|
12
|
+
providers: HealthProviderMap;
|
|
13
|
+
}
|
|
14
|
+
export interface HealthStateModule {
|
|
15
|
+
getHealthStatus(): Promise<RuntimeHealthStatus>;
|
|
16
|
+
getSystemState(): Promise<RuntimeSystemState>;
|
|
17
|
+
registerProvider<Name extends keyof HealthProviderMap>(name: Name, provider: HealthProviderMap[Name]): void;
|
|
18
|
+
}
|
|
19
|
+
export declare function createHealthStateModule(options: CreateHealthStateModuleOptions): HealthStateModule;
|
|
20
|
+
export declare function deriveRuntimeHealth(healths: Array<ComponentHealth | undefined>): ComponentHealth;
|
|
1
21
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
22
|
+
* Legacy hook-based health initializer retained for compatibility.
|
|
23
|
+
* Runtime health/state aggregation is now handled by createHealthStateModule().
|
|
4
24
|
*/
|
|
5
25
|
export declare function initHealth(_bus: {
|
|
6
26
|
emit: (e: string, p?: unknown) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/health/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/health/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAGf,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAE5B,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAC5B,8BAA8B,EAC9B,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,mBAAmB,CAAC,4BAA4B,EAAE,kBAAkB,CAAC,CAAC;IAChF,GAAG,CAAC,EAAE,mBAAmB,CAAC,wBAAwB,EAAE,cAAc,CAAC,CAAC;CACrE,CAAC;AAEF,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,eAAe,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAChD,cAAc,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC9C,gBAAgB,CAAC,IAAI,SAAS,MAAM,iBAAiB,EACnD,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC,GAChC,IAAI,CAAC;CACT;AAUD,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,iBAAiB,CAmEnB;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,KAAK,CAAC,eAAe,GAAG,SAAS,CAAC,GAC1C,eAAe,CAgBjB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE;IAC/B,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,KAAK,IAAI,CAAC;CACnD,GAAG,IAAI,CAEP"}
|
package/dist/health/index.js
CHANGED
|
@@ -1,9 +1,191 @@
|
|
|
1
|
+
const HEALTH_ORDER = {
|
|
2
|
+
healthy: 0,
|
|
3
|
+
disabled: 0,
|
|
4
|
+
unknown: 1,
|
|
5
|
+
degraded: 2,
|
|
6
|
+
unhealthy: 3,
|
|
7
|
+
};
|
|
8
|
+
export function createHealthStateModule(options) {
|
|
9
|
+
const startedAtMs = options.startedAt ?? Date.now();
|
|
10
|
+
const providers = { ...options.providers };
|
|
11
|
+
return {
|
|
12
|
+
async getHealthStatus() {
|
|
13
|
+
const [scanners, dsl] = await Promise.all([
|
|
14
|
+
readProviderHealth({
|
|
15
|
+
component: "scanners",
|
|
16
|
+
provider: providers.scanners,
|
|
17
|
+
fallback: buildScannerHealthFallback("Scanners provider is not registered."),
|
|
18
|
+
}),
|
|
19
|
+
readProviderHealth({
|
|
20
|
+
component: "dsl",
|
|
21
|
+
provider: providers.dsl,
|
|
22
|
+
fallback: buildDslHealthFallback("DSL provider is not registered."),
|
|
23
|
+
}),
|
|
24
|
+
]);
|
|
25
|
+
return {
|
|
26
|
+
...(options.recipeId ? { recipeId: options.recipeId } : {}),
|
|
27
|
+
recipeName: options.recipeName,
|
|
28
|
+
startedAt: new Date(startedAtMs).toISOString(),
|
|
29
|
+
generatedAt: new Date().toISOString(),
|
|
30
|
+
health: deriveRuntimeHealth([scanners.health, providers.dsl ? dsl.health : undefined]),
|
|
31
|
+
components: {
|
|
32
|
+
scanners,
|
|
33
|
+
...(providers.dsl ? { dsl } : {}),
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
async getSystemState() {
|
|
38
|
+
const [scanners, dsl] = await Promise.all([
|
|
39
|
+
readProviderState({
|
|
40
|
+
component: "scanners",
|
|
41
|
+
provider: providers.scanners,
|
|
42
|
+
fallback: buildScannerStateFallback("Scanners provider is not registered."),
|
|
43
|
+
}),
|
|
44
|
+
readProviderState({
|
|
45
|
+
component: "dsl",
|
|
46
|
+
provider: providers.dsl,
|
|
47
|
+
fallback: buildDslStateFallback("DSL provider is not registered."),
|
|
48
|
+
}),
|
|
49
|
+
]);
|
|
50
|
+
return {
|
|
51
|
+
...(options.recipeId ? { recipeId: options.recipeId } : {}),
|
|
52
|
+
recipeName: options.recipeName,
|
|
53
|
+
stateDir: options.stateDir,
|
|
54
|
+
startedAt: new Date(startedAtMs).toISOString(),
|
|
55
|
+
generatedAt: new Date().toISOString(),
|
|
56
|
+
health: deriveRuntimeHealth([scanners.health, providers.dsl ? dsl.health : undefined]),
|
|
57
|
+
components: {
|
|
58
|
+
scanners,
|
|
59
|
+
...(providers.dsl ? { dsl } : {}),
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
registerProvider(name, provider) {
|
|
64
|
+
providers[name] = provider;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function deriveRuntimeHealth(healths) {
|
|
69
|
+
const values = healths.filter((value) => value !== undefined);
|
|
70
|
+
if (values.length === 0) {
|
|
71
|
+
return "unknown";
|
|
72
|
+
}
|
|
73
|
+
const active = values.filter((value) => value !== "disabled");
|
|
74
|
+
const source = active.length > 0 ? active : values;
|
|
75
|
+
let worst = source[0] ?? "unknown";
|
|
76
|
+
for (const value of source) {
|
|
77
|
+
if (HEALTH_ORDER[value] > HEALTH_ORDER[worst]) {
|
|
78
|
+
worst = value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return worst;
|
|
82
|
+
}
|
|
1
83
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
84
|
+
* Legacy hook-based health initializer retained for compatibility.
|
|
85
|
+
* Runtime health/state aggregation is now handled by createHealthStateModule().
|
|
4
86
|
*/
|
|
5
|
-
// TODO: implement health module (liveness, readiness, metrics, etc.)
|
|
6
87
|
export function initHealth(_bus) {
|
|
7
|
-
// no-op
|
|
88
|
+
// no-op
|
|
89
|
+
}
|
|
90
|
+
async function readProviderHealth(options) {
|
|
91
|
+
if (!options.provider) {
|
|
92
|
+
return options.fallback;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
return await options.provider.getHealthStatus();
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return {
|
|
99
|
+
...options.fallback,
|
|
100
|
+
summary: `Failed to query ${options.component} health.`,
|
|
101
|
+
updatedAt: new Date().toISOString(),
|
|
102
|
+
error: formatProviderError(error),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function readProviderState(options) {
|
|
107
|
+
if (!options.provider) {
|
|
108
|
+
return options.fallback;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
return await options.provider.getSystemState();
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return {
|
|
115
|
+
...options.fallback,
|
|
116
|
+
updatedAt: new Date().toISOString(),
|
|
117
|
+
error: formatProviderError(error),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function buildScannerHealthFallback(error) {
|
|
122
|
+
return {
|
|
123
|
+
component: "scanners",
|
|
124
|
+
health: "unhealthy",
|
|
125
|
+
updatedAt: new Date().toISOString(),
|
|
126
|
+
summary: "Failed to query scanners health.",
|
|
127
|
+
error,
|
|
128
|
+
totals: {
|
|
129
|
+
registered: 0,
|
|
130
|
+
enabled: 0,
|
|
131
|
+
inFlight: 0,
|
|
132
|
+
degraded: 0,
|
|
133
|
+
unhealthy: 1,
|
|
134
|
+
},
|
|
135
|
+
scanners: [],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function buildDslHealthFallback(error) {
|
|
139
|
+
return {
|
|
140
|
+
component: "dsl",
|
|
141
|
+
health: "unhealthy",
|
|
142
|
+
updatedAt: new Date().toISOString(),
|
|
143
|
+
summary: "Failed to query DSL health.",
|
|
144
|
+
error,
|
|
145
|
+
enabled: false,
|
|
146
|
+
activePositions: 0,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function buildScannerStateFallback(error) {
|
|
150
|
+
return {
|
|
151
|
+
component: "scanners",
|
|
152
|
+
health: "unhealthy",
|
|
153
|
+
updatedAt: new Date().toISOString(),
|
|
154
|
+
error,
|
|
155
|
+
state: {
|
|
156
|
+
totalRegistered: 0,
|
|
157
|
+
totalEnabled: 0,
|
|
158
|
+
scanners: [],
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function buildDslStateFallback(error) {
|
|
163
|
+
return {
|
|
164
|
+
component: "dsl",
|
|
165
|
+
health: "unhealthy",
|
|
166
|
+
updatedAt: new Date().toISOString(),
|
|
167
|
+
error,
|
|
168
|
+
state: {
|
|
169
|
+
enabled: false,
|
|
170
|
+
intervalMs: 0,
|
|
171
|
+
preset: "unknown",
|
|
172
|
+
monitor: {
|
|
173
|
+
running: false,
|
|
174
|
+
inFlight: false,
|
|
175
|
+
lastTickStartedAt: null,
|
|
176
|
+
lastTickFinishedAt: null,
|
|
177
|
+
lastTickError: null,
|
|
178
|
+
nextTickAt: null,
|
|
179
|
+
tickAttemptCount: 0,
|
|
180
|
+
tickSuccessCount: 0,
|
|
181
|
+
tickErrorCount: 0,
|
|
182
|
+
},
|
|
183
|
+
activePositions: [],
|
|
184
|
+
positions: [],
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function formatProviderError(error) {
|
|
189
|
+
return error instanceof Error ? error.message : String(error);
|
|
8
190
|
}
|
|
9
191
|
//# sourceMappingURL=index.js.map
|
package/dist/health/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/health/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/health/index.ts"],"names":[],"mappings":"AAkDA,MAAM,YAAY,GAAoC;IACpD,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,SAAS,EAAE,CAAC;CACb,CAAC;AAEF,MAAM,UAAU,uBAAuB,CACrC,OAAuC;IAEvC,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IACpD,MAAM,SAAS,GAA+B,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAEvE,OAAO;QACL,KAAK,CAAC,eAAe;YACnB,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBACxC,kBAAkB,CAAC;oBACjB,SAAS,EAAE,UAAU;oBACrB,QAAQ,EAAE,SAAS,CAAC,QAAQ;oBAC5B,QAAQ,EAAE,0BAA0B,CAAC,sCAAsC,CAAC;iBAC7E,CAAC;gBACF,kBAAkB,CAAC;oBACjB,SAAS,EAAE,KAAK;oBAChB,QAAQ,EAAE,SAAS,CAAC,GAAG;oBACvB,QAAQ,EAAE,sBAAsB,CAAC,iCAAiC,CAAC;iBACpE,CAAC;aACH,CAAC,CAAC;YAEH,OAAO;gBACL,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC3D,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,SAAS,EAA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AC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export type ComponentHealth = "healthy" | "degraded" | "unhealthy" | "disabled" | "unknown";
|
|
2
|
+
export interface ComponentHealthStatus {
|
|
3
|
+
component: string;
|
|
4
|
+
health: ComponentHealth;
|
|
5
|
+
updatedAt: string;
|
|
6
|
+
summary: string;
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ComponentSystemState<TState = unknown> {
|
|
10
|
+
component: string;
|
|
11
|
+
health: ComponentHealth;
|
|
12
|
+
updatedAt: string;
|
|
13
|
+
state: TState;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface StateStatusProvider<THealth extends ComponentHealthStatus = ComponentHealthStatus, TState extends ComponentSystemState = ComponentSystemState> {
|
|
17
|
+
getHealthStatus(): Promise<THealth>;
|
|
18
|
+
getSystemState(): Promise<TState>;
|
|
19
|
+
}
|
|
20
|
+
export interface ScannerRegistrationHealth {
|
|
21
|
+
address: string;
|
|
22
|
+
scannerId: string;
|
|
23
|
+
health: ComponentHealth;
|
|
24
|
+
}
|
|
25
|
+
export interface ScannerComponentHealthStatus extends ComponentHealthStatus {
|
|
26
|
+
component: "scanners";
|
|
27
|
+
totals: {
|
|
28
|
+
registered: number;
|
|
29
|
+
enabled: number;
|
|
30
|
+
inFlight: number;
|
|
31
|
+
degraded: number;
|
|
32
|
+
unhealthy: number;
|
|
33
|
+
};
|
|
34
|
+
scanners: ScannerRegistrationHealth[];
|
|
35
|
+
}
|
|
36
|
+
export interface ScannerRegistrationSystemState {
|
|
37
|
+
address: string;
|
|
38
|
+
scannerId: string;
|
|
39
|
+
health: ComponentHealth;
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
initialized: boolean;
|
|
42
|
+
intervalSeconds: number;
|
|
43
|
+
inFlight: boolean;
|
|
44
|
+
lastRunStartedAt: number | null;
|
|
45
|
+
lastRunFinishedAt: number | null;
|
|
46
|
+
lastRunStatus: string | null;
|
|
47
|
+
lastRunReason: string | null;
|
|
48
|
+
lastError: string | null;
|
|
49
|
+
lastErrorAt: number | null;
|
|
50
|
+
nextRunAt: number | null;
|
|
51
|
+
runCount: number;
|
|
52
|
+
errorCount: number;
|
|
53
|
+
consecutiveErrorCount: number;
|
|
54
|
+
configVersion: number | null;
|
|
55
|
+
runtimeUpdatedAt: number | null;
|
|
56
|
+
config: unknown;
|
|
57
|
+
state: unknown;
|
|
58
|
+
}
|
|
59
|
+
export interface ScannerSystemState extends ComponentSystemState<{
|
|
60
|
+
totalRegistered: number;
|
|
61
|
+
totalEnabled: number;
|
|
62
|
+
scanners: ScannerRegistrationSystemState[];
|
|
63
|
+
}> {
|
|
64
|
+
component: "scanners";
|
|
65
|
+
}
|
|
66
|
+
export interface DslComponentHealthStatus extends ComponentHealthStatus {
|
|
67
|
+
component: "dsl";
|
|
68
|
+
enabled: boolean;
|
|
69
|
+
activePositions: number;
|
|
70
|
+
}
|
|
71
|
+
export interface DslSystemState extends ComponentSystemState<{
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
intervalMs: number;
|
|
74
|
+
preset: string;
|
|
75
|
+
monitor: {
|
|
76
|
+
running: boolean;
|
|
77
|
+
inFlight: boolean;
|
|
78
|
+
lastTickStartedAt: number | null;
|
|
79
|
+
lastTickFinishedAt: number | null;
|
|
80
|
+
lastTickError: string | null;
|
|
81
|
+
nextTickAt: number | null;
|
|
82
|
+
tickAttemptCount: number;
|
|
83
|
+
tickSuccessCount: number;
|
|
84
|
+
tickErrorCount: number;
|
|
85
|
+
};
|
|
86
|
+
activePositions: unknown[];
|
|
87
|
+
positions: unknown[];
|
|
88
|
+
}> {
|
|
89
|
+
component: "dsl";
|
|
90
|
+
}
|
|
91
|
+
export interface RuntimeHealthStatus {
|
|
92
|
+
recipeId?: string;
|
|
93
|
+
recipeName: string;
|
|
94
|
+
startedAt: string;
|
|
95
|
+
generatedAt: string;
|
|
96
|
+
health: ComponentHealth;
|
|
97
|
+
components: {
|
|
98
|
+
scanners: ScannerComponentHealthStatus;
|
|
99
|
+
dsl?: DslComponentHealthStatus;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export interface RuntimeSystemState {
|
|
103
|
+
recipeId?: string;
|
|
104
|
+
recipeName: string;
|
|
105
|
+
stateDir: string;
|
|
106
|
+
startedAt: string;
|
|
107
|
+
generatedAt: string;
|
|
108
|
+
health: ComponentHealth;
|
|
109
|
+
components: {
|
|
110
|
+
scanners: ScannerSystemState;
|
|
111
|
+
dsl?: DslSystemState;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/health/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,UAAU,GACV,WAAW,GACX,UAAU,GACV,SAAS,CAAC;AAEd,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,oBAAoB,CAAC,MAAM,GAAG,OAAO;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB,CAClC,OAAO,SAAS,qBAAqB,GAAG,qBAAqB,EAC7D,MAAM,SAAS,oBAAoB,GAAG,oBAAoB;IAE1D,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACn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AAkB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC;IACxB,UAAU,EAAE;QACV,QAAQ,EAAE,kBAAkB,CAAC;QAC7B,GAAG,CAAC,EAAE,cAAc,CAAC;KACtB,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/health/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export declare function initCore(bus: SenpiEventBus): void;
|
|
|
10
10
|
export { initDsl, DslPlugin, dslLogger, setDslLogLevel, parseDslPluginConfig, DslConfigValidationError, dslValidationIssue, EVENTS as DslEvents, DSL_EVENTS, } from "./dsl/index.js";
|
|
11
11
|
export type { DslArchivedClose, DslPluginConfig, DslPositionSummary, DslState, DslTickResult, ExitBlockConfig, DslValidationIssue, DslValidationIssueCode, } from "./dsl/index.js";
|
|
12
12
|
export { initRisk } from "./risk/index.js";
|
|
13
|
-
export { initHealth } from "./health/index.js";
|
|
13
|
+
export { createHealthStateModule, initHealth } from "./health/index.js";
|
|
14
|
+
export type { ComponentHealth, ComponentHealthStatus, ComponentSystemState, DslComponentHealthStatus, DslSystemState, RuntimeHealthStatus, RuntimeSystemState, ScannerComponentHealthStatus, ScannerRegistrationSystemState, ScannerSystemState, StateStatusProvider, } from "./health/index.js";
|
|
14
15
|
export { HOOK_EVENT } from './types/index.js';
|
|
15
16
|
export type { HookEventType, HookEvent, HookSystem, StrategyConfig, StateManager, GateCheckResult, RiskGuard, NotificationService, Signal, ScanResult, } from './types/index.js';
|
|
16
17
|
export { ScanStatus } from './types/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAQ3D,+EAA+E;AAC/E,wBAAgB,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAIjD;AAGD,OAAO,EACL,OAAO,EACP,SAAS,EACT,SAAS,EACT,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,MAAM,IAAI,SAAS,EACnB,UAAU,GACX,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACxE,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAC5B,8BAA8B,EAC9B,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACV,cAAc,EACd,YAAY,EACZ,eAAe,EACf,SAAS,EACT,mBAAmB,EACnB,MAAM,EACN,UAAU,GACX,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,YAAY,EACV,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,cAAc,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AAE,GAC3B,IAAI,CAAC;CACT;AAqGD;;;GAGG;AACH,QAAA,MAAM,iBAAiB;;;;;;qBAON,OAAO;;kBAQR,SAAS;CAqYxB,CAAC;AA4HF,eAAe,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -26,8 +26,8 @@ export function initCore(bus) {
|
|
|
26
26
|
export { initDsl, DslPlugin, dslLogger, setDslLogLevel, parseDslPluginConfig, DslConfigValidationError, dslValidationIssue, EVENTS as DslEvents, DSL_EVENTS, } from "./dsl/index.js";
|
|
27
27
|
// Risk feature (placeholder)
|
|
28
28
|
export { initRisk } from "./risk/index.js";
|
|
29
|
-
// Health feature
|
|
30
|
-
export { initHealth } from "./health/index.js";
|
|
29
|
+
// Health feature
|
|
30
|
+
export { createHealthStateModule, initHealth } from "./health/index.js";
|
|
31
31
|
// Shared types
|
|
32
32
|
export { HOOK_EVENT } from './types/index.js';
|
|
33
33
|
export { ScanStatus } from './types/index.js';
|
|
@@ -261,6 +261,7 @@ const senpiRecipePlugin = {
|
|
|
261
261
|
pluginLogger.info("[senpi-recipe] CLI registrar callback invoked — attaching senpi subcommands to program");
|
|
262
262
|
registerSenpiCli(ctx.program);
|
|
263
263
|
}, { commands: ["senpi"] });
|
|
264
|
+
/** Gateway respond accepts (ok, payload?, error?) with error as { code, message }; plugin SDK types may omit the third arg. */
|
|
264
265
|
api.registerGatewayMethod("senpi.installRecipe", async (ctx) => {
|
|
265
266
|
const { params } = ctx;
|
|
266
267
|
const respond = ctx.respond;
|
|
@@ -446,8 +447,151 @@ const senpiRecipePlugin = {
|
|
|
446
447
|
closes = closes.slice(0, limit);
|
|
447
448
|
respond(true, { closes });
|
|
448
449
|
});
|
|
449
|
-
|
|
450
|
+
api.registerGatewayMethod("senpi.getHealthStatus", async (ctx) => {
|
|
451
|
+
const respond = ctx.respond;
|
|
452
|
+
const recipeId = typeof ctx.params?.recipeId === "string" ? ctx.params.recipeId : undefined;
|
|
453
|
+
if (recipeId) {
|
|
454
|
+
const handle = getRuntimeHandleOrRespond(runtimeHandles, recipeId, respond);
|
|
455
|
+
if (!handle) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
try {
|
|
459
|
+
const status = await handle.getHealthStatus();
|
|
460
|
+
respond(true, {
|
|
461
|
+
status: status ? { ...status, recipeId } : null,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
catch (err) {
|
|
465
|
+
api.logger.warn("[senpi-recipe] getHealthStatus error", { recipeId, err });
|
|
466
|
+
respond(false, undefined, {
|
|
467
|
+
code: "INTERNAL_ERROR",
|
|
468
|
+
message: `Failed to get health status for recipe ${recipeId}: ${formatGatewayError(err)}`,
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const statuses = await collectRuntimeHealthStatuses(runtimeHandles, api.logger);
|
|
474
|
+
respond(true, { statuses });
|
|
475
|
+
});
|
|
476
|
+
api.registerGatewayMethod("senpi.getSystemState", async (ctx) => {
|
|
477
|
+
const respond = ctx.respond;
|
|
478
|
+
const recipeId = typeof ctx.params?.recipeId === "string" ? ctx.params.recipeId : undefined;
|
|
479
|
+
if (recipeId) {
|
|
480
|
+
const handle = getRuntimeHandleOrRespond(runtimeHandles, recipeId, respond);
|
|
481
|
+
if (!handle) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
const state = await handle.getSystemState();
|
|
486
|
+
respond(true, {
|
|
487
|
+
state: state ? { ...state, recipeId } : null,
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
catch (err) {
|
|
491
|
+
api.logger.warn("[senpi-recipe] getSystemState error", { recipeId, err });
|
|
492
|
+
respond(false, undefined, {
|
|
493
|
+
code: "INTERNAL_ERROR",
|
|
494
|
+
message: `Failed to get system state for recipe ${recipeId}: ${formatGatewayError(err)}`,
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const states = await collectRuntimeSystemStates(runtimeHandles, api.logger, baseStateDir);
|
|
500
|
+
respond(true, { states });
|
|
501
|
+
});
|
|
502
|
+
api.logger.info(`[senpi-recipe] v${VERSION} plugin registered — stateDir: ${baseStateDir}`);
|
|
450
503
|
},
|
|
451
504
|
};
|
|
505
|
+
function getRuntimeHandleOrRespond(runtimeHandles, recipeId, respond) {
|
|
506
|
+
const handle = runtimeHandles.get(recipeId);
|
|
507
|
+
if (handle) {
|
|
508
|
+
return handle;
|
|
509
|
+
}
|
|
510
|
+
respond(false, undefined, {
|
|
511
|
+
code: "NOT_FOUND",
|
|
512
|
+
message: `No running recipe found for id ${recipeId}`,
|
|
513
|
+
});
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
async function collectRuntimeHealthStatuses(runtimeHandles, logger) {
|
|
517
|
+
return (await Promise.all(Array.from(runtimeHandles, async ([recipeId, handle]) => {
|
|
518
|
+
try {
|
|
519
|
+
const status = await handle.getHealthStatus();
|
|
520
|
+
return status ? { ...status, recipeId } : null;
|
|
521
|
+
}
|
|
522
|
+
catch (err) {
|
|
523
|
+
logger.warn("[senpi-recipe] getHealthStatus error", { recipeId, err });
|
|
524
|
+
return createGatewayHealthErrorStatus(recipeId, err);
|
|
525
|
+
}
|
|
526
|
+
}))).filter((status) => status !== null);
|
|
527
|
+
}
|
|
528
|
+
async function collectRuntimeSystemStates(runtimeHandles, logger, baseStateDir) {
|
|
529
|
+
return (await Promise.all(Array.from(runtimeHandles, async ([recipeId, handle]) => {
|
|
530
|
+
try {
|
|
531
|
+
const state = await handle.getSystemState();
|
|
532
|
+
return state ? { ...state, recipeId } : null;
|
|
533
|
+
}
|
|
534
|
+
catch (err) {
|
|
535
|
+
logger.warn("[senpi-recipe] getSystemState error", { recipeId, err });
|
|
536
|
+
return createGatewaySystemStateError(recipeId, join(baseStateDir, recipeId), err);
|
|
537
|
+
}
|
|
538
|
+
}))).filter((state) => state !== null);
|
|
539
|
+
}
|
|
540
|
+
function createGatewayHealthErrorStatus(recipeId, error) {
|
|
541
|
+
const now = new Date().toISOString();
|
|
542
|
+
const message = formatGatewayError(error);
|
|
543
|
+
return {
|
|
544
|
+
recipeId,
|
|
545
|
+
recipeName: recipeId,
|
|
546
|
+
startedAt: now,
|
|
547
|
+
generatedAt: now,
|
|
548
|
+
health: "unhealthy",
|
|
549
|
+
components: {
|
|
550
|
+
scanners: {
|
|
551
|
+
component: "scanners",
|
|
552
|
+
health: "unhealthy",
|
|
553
|
+
updatedAt: now,
|
|
554
|
+
summary: "Failed to query scanners health.",
|
|
555
|
+
error: message,
|
|
556
|
+
totals: {
|
|
557
|
+
registered: 0,
|
|
558
|
+
enabled: 0,
|
|
559
|
+
inFlight: 0,
|
|
560
|
+
degraded: 0,
|
|
561
|
+
unhealthy: 1,
|
|
562
|
+
},
|
|
563
|
+
scanners: [],
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
function createGatewaySystemStateError(recipeId, stateDir, error) {
|
|
569
|
+
const now = new Date().toISOString();
|
|
570
|
+
const message = formatGatewayError(error);
|
|
571
|
+
return {
|
|
572
|
+
recipeId,
|
|
573
|
+
recipeName: recipeId,
|
|
574
|
+
stateDir,
|
|
575
|
+
startedAt: now,
|
|
576
|
+
generatedAt: now,
|
|
577
|
+
health: "unhealthy",
|
|
578
|
+
components: {
|
|
579
|
+
scanners: {
|
|
580
|
+
component: "scanners",
|
|
581
|
+
health: "unhealthy",
|
|
582
|
+
updatedAt: now,
|
|
583
|
+
error: message,
|
|
584
|
+
state: {
|
|
585
|
+
totalRegistered: 0,
|
|
586
|
+
totalEnabled: 0,
|
|
587
|
+
scanners: [],
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
},
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function formatGatewayError(error) {
|
|
594
|
+
return error instanceof Error ? error.message : String(error);
|
|
595
|
+
}
|
|
452
596
|
export default senpiRecipePlugin;
|
|
453
597
|
//# sourceMappingURL=index.js.map
|