@senpi-ai/runtime 3.0.147 → 3.0.151
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/actions/action-events.d.ts.map +1 -1
- package/dist/actions/action-events.js +1 -2
- package/dist/actions/action-events.js.map +1 -1
- package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +0 -3
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +5 -0
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
- package/dist/dsl/monitor/process-one-position.js +2 -6
- package/dist/dsl/monitor/process-one-position.js.map +1 -1
- package/dist/dsl/plugin/index.d.ts +1 -0
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +17 -4
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -76
- package/dist/index.js.map +1 -1
- package/dist/runtime/domain-events.d.ts.map +1 -1
- package/dist/runtime/domain-events.js +0 -2
- package/dist/runtime/domain-events.js.map +1 -1
- package/dist/runtime/run.d.ts +0 -7
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +0 -7
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime.d.ts +0 -21
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +3 -51
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime-api/intake/intake-mount.d.ts +0 -2
- package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
- package/dist/runtime-api/intake/intake-mount.js +3 -6
- package/dist/runtime-api/intake/intake-mount.js.map +1 -1
- package/dist/runtime-api/routes/signals.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.js +0 -10
- package/dist/runtime-api/routes/signals.js.map +1 -1
- package/dist/state/state-manager.d.ts +0 -2
- package/dist/state/state-manager.d.ts.map +1 -1
- package/dist/state/state-manager.js +0 -8
- package/dist/state/state-manager.js.map +1 -1
- package/dist/telemetry/event-builders.d.ts +0 -6
- package/dist/telemetry/event-builders.d.ts.map +1 -1
- package/dist/telemetry/event-builders.js +0 -6
- package/dist/telemetry/event-builders.js.map +1 -1
- package/dist/telemetry/event-store.d.ts +0 -6
- package/dist/telemetry/event-store.d.ts.map +1 -1
- package/dist/telemetry/event-store.js +6 -6
- package/dist/telemetry/event-store.js.map +1 -1
- package/dist/telemetry/spans/redact-pii.d.ts.map +1 -1
- package/dist/telemetry/spans/redact-pii.js +2 -13
- package/dist/telemetry/spans/redact-pii.js.map +1 -1
- package/dist/utils/event-catalog.d.ts +0 -6
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/dist/constants/telemetry.d.ts +0 -17
- package/dist/constants/telemetry.d.ts.map +0 -1
- package/dist/constants/telemetry.js +0 -30
- package/dist/constants/telemetry.js.map +0 -1
- package/dist/runtime/events-telemetry.d.ts +0 -120
- package/dist/runtime/events-telemetry.d.ts.map +0 -1
- package/dist/runtime/events-telemetry.js +0 -305
- package/dist/runtime/events-telemetry.js.map +0 -1
- package/dist/runtime/strategies-store.d.ts +0 -26
- package/dist/runtime/strategies-store.d.ts.map +0 -1
- package/dist/runtime/strategies-store.js +0 -47
- package/dist/runtime/strategies-store.js.map +0 -1
- package/dist/runtime/strategies-telemetry.d.ts +0 -124
- package/dist/runtime/strategies-telemetry.d.ts.map +0 -1
- package/dist/runtime/strategies-telemetry.js +0 -143
- package/dist/runtime/strategies-telemetry.js.map +0 -1
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Events telemetry: the in-memory buffer of runtime event records, the tap that fills it from the
|
|
3
|
-
* per-wallet event sink, and the loop that broadcasts new records as `plugin.senpi.events`.
|
|
4
|
-
*/
|
|
5
|
-
import { type EventSink, type StoredEvent } from "../telemetry/event-store.js";
|
|
6
|
-
import { type PiiRedactor } from "../telemetry/spans/redact-pii.js";
|
|
7
|
-
import type { LogLevel } from "../utils/logger.js";
|
|
8
|
-
import { type StrategiesBroadcastFn } from "./strategies-telemetry.js";
|
|
9
|
-
/** One event as broadcast. `address` is the wallet whose sink received the event. */
|
|
10
|
-
export interface EventRecord {
|
|
11
|
-
seq: number;
|
|
12
|
-
ts: number;
|
|
13
|
-
name: string;
|
|
14
|
-
level: LogLevel;
|
|
15
|
-
address: string;
|
|
16
|
-
body: string;
|
|
17
|
-
attrs: Record<string, string | number | boolean>;
|
|
18
|
-
}
|
|
19
|
-
export interface EventsMessage {
|
|
20
|
-
v: 1;
|
|
21
|
-
epoch: string;
|
|
22
|
-
batchSeq: number;
|
|
23
|
-
events: EventRecord[];
|
|
24
|
-
}
|
|
25
|
-
export interface EventsReplay {
|
|
26
|
-
epoch: string;
|
|
27
|
-
events: EventRecord[];
|
|
28
|
-
truncated: boolean;
|
|
29
|
-
}
|
|
30
|
-
export interface EventsCursor {
|
|
31
|
-
afterEpoch: string;
|
|
32
|
-
afterSeq: number;
|
|
33
|
-
}
|
|
34
|
-
export interface EventsBuffer {
|
|
35
|
-
/** Gives the event the next `seq` and appends it to the ring of `address`. */
|
|
36
|
-
add(address: string, event: StoredEvent): void;
|
|
37
|
-
/** Held records with `seq` greater than `seq`, in `seq` order. */
|
|
38
|
-
after(seq: number): EventRecord[];
|
|
39
|
-
/** The highest `seq` held in any ring, `0` when nothing is held. */
|
|
40
|
-
newestSeq(): number;
|
|
41
|
-
/**
|
|
42
|
-
* The highest `seq` evicted from any ring, `0` when nothing was evicted. Deleting a closed ring
|
|
43
|
-
* evicts its records.
|
|
44
|
-
*/
|
|
45
|
-
maxEvictedSeq(): number;
|
|
46
|
-
/**
|
|
47
|
-
* Closes the ring of `address`. A closed ring takes no new records and stays in `after` until
|
|
48
|
-
* `dropSent` deletes it. The next record for `address` starts a new, empty ring. Closing does not
|
|
49
|
-
* change `maxEvictedSeq`.
|
|
50
|
-
*/
|
|
51
|
-
remove(address: string): void;
|
|
52
|
-
/**
|
|
53
|
-
* Deletes each closed ring whose newest `seq` is at most `sentSeq`, and each closed ring closed at
|
|
54
|
-
* least `EVENTS_CLOSED_RING_TTL_MS` ago. `maxEvictedSeq` rises to the newest `seq` of each deleted ring.
|
|
55
|
-
*/
|
|
56
|
-
dropSent(sentSeq: number): void;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* One ring of `capacity` records per address. `seq` starts at 1 and counts across every address.
|
|
60
|
-
* `now` is the clock, in epoch ms, that times a closed ring.
|
|
61
|
-
*/
|
|
62
|
-
export declare function createEventsBuffer(capacity?: number, now?: () => number): EventsBuffer;
|
|
63
|
-
/** The process buffer. Its `seq` run belongs to `PROCESS_EPOCH`. */
|
|
64
|
-
export declare const eventsBuffer: EventsBuffer;
|
|
65
|
-
/**
|
|
66
|
-
* Adds a record to `buffer` under `address` for a case that is not a runtime event. It does not go
|
|
67
|
-
* through `logger.event`, so no event sink, disk ring or OTel record receives it. A blank `address`
|
|
68
|
-
* adds nothing. Never throws.
|
|
69
|
-
*/
|
|
70
|
-
export declare function addEventRecord(address: string, event: StoredEvent, buffer?: EventsBuffer): void;
|
|
71
|
-
/**
|
|
72
|
-
* Wraps a wallet's event sink. Every event goes to `sink`. An event whose name is in
|
|
73
|
-
* `EVENTS_BROADCAST_NAMES` is also added to `buffer` under `address`.
|
|
74
|
-
*/
|
|
75
|
-
export declare function withEventsTap(address: string, sink: EventSink, buffer?: EventsBuffer): EventSink;
|
|
76
|
-
/**
|
|
77
|
-
* A copy of the record with every string in `body` and `attrs` run through the redactor, except the
|
|
78
|
-
* join-id attrs in `UNSCRUBBED_ATTRS`. A string attr the redactor cannot produce is left out; such a
|
|
79
|
-
* `body` becomes `""`.
|
|
80
|
-
*/
|
|
81
|
-
export declare function scrubEventRecord(record: EventRecord, redactor: PiiRedactor): Promise<EventRecord>;
|
|
82
|
-
/**
|
|
83
|
-
* The events part of the subscribe reply. A cursor whose `afterEpoch` is `epoch` selects the held
|
|
84
|
-
* records after `afterSeq`; any other cursor, or none, selects every held record. The newest
|
|
85
|
-
* selected records that fit `maxBytes` are served, scrubbed, in `seq` order. `truncated` is `true`
|
|
86
|
-
* when a record owed to the cursor was evicted, or a selected record was not served. A cursor of
|
|
87
|
-
* the current epoch is owed the records after `afterSeq`; a cursor of another epoch is owed every
|
|
88
|
-
* record of the current epoch; no cursor is owed nothing. Without a redactor no record is served.
|
|
89
|
-
*/
|
|
90
|
-
export declare function buildEventsReplay(input: {
|
|
91
|
-
buffer?: EventsBuffer;
|
|
92
|
-
epoch?: string;
|
|
93
|
-
cursor?: EventsCursor;
|
|
94
|
-
redactor: PiiRedactor | null;
|
|
95
|
-
maxBytes?: number;
|
|
96
|
-
}): Promise<EventsReplay>;
|
|
97
|
-
export interface EventsPublisher {
|
|
98
|
-
/** Sends every interval. A second call while running does nothing. */
|
|
99
|
-
start(): void;
|
|
100
|
-
/** Stops the sends. */
|
|
101
|
-
stop(): void;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Each tick takes the records added since the previous tick. With a broadcast function, it scrubs
|
|
105
|
-
* them and broadcasts them as one or more messages of at most `maxFrameBytes` serialized bytes. A
|
|
106
|
-
* record that does not fit an empty message is dropped and passed to `warn`. Without a broadcast
|
|
107
|
-
* function, the records are not sent. While there is no redactor, the tick sends nothing and keeps
|
|
108
|
-
* the records for the first tick that has one. Each tick ends with `dropSent`: it deletes the closed
|
|
109
|
-
* rings whose records it has passed, and the closed rings held past `EVENTS_CLOSED_RING_TTL_MS`.
|
|
110
|
-
*/
|
|
111
|
-
export declare function createEventsPublisher(deps: {
|
|
112
|
-
getBroadcast: () => StrategiesBroadcastFn | undefined;
|
|
113
|
-
buffer?: EventsBuffer;
|
|
114
|
-
getRedactor?: () => PiiRedactor | null;
|
|
115
|
-
epoch?: string;
|
|
116
|
-
maxFrameBytes?: number;
|
|
117
|
-
warn?: (message: string, meta: Record<string, unknown>) => void;
|
|
118
|
-
onError?: (err: unknown) => void;
|
|
119
|
-
}): EventsPublisher;
|
|
120
|
-
//# sourceMappingURL=events-telemetry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"events-telemetry.d.ts","sourceRoot":"","sources":["../../src/runtime/events-telemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAA4B,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AACzG,OAAO,EAAyB,KAAK,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAE3F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAiB,KAAK,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEtF,qFAAqF;AACrF,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,CAAC,CAAC;IACL,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,C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AC;CACnB,GAAG,OAAO,CAAC,YAAY,CAAC,CAoBxB;AAED,MAAM,WAAW,eAAe;IAC9B,sEAAsE;IACtE,KAAK,IAAI,IAAI,CAAC;IACd,uBAAuB;IACvB,IAAI,IAAI,IAAI,CAAC;CACd;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC1C,YAAY,EAAE,MAAM,qBAAqB,GAAG,SAAS,CAAC;IACtD,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAChE,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;CAClC,GAAG,eAAe,CAuElB"}
|
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Events telemetry: the in-memory buffer of runtime event records, the tap that fills it from the
|
|
3
|
-
* per-wallet event sink, and the loop that broadcasts new records as `plugin.senpi.events`.
|
|
4
|
-
*/
|
|
5
|
-
import { EVENTS_BROADCAST_NAMES, EVENTS_CLOSED_RING_TTL_MS, EVENTS_EVENT_NAME, EVENTS_MAX_FRAME_BYTES, EVENTS_PER_STRATEGY, EVENTS_SEND_INTERVAL_MS, } from "../constants/telemetry.js";
|
|
6
|
-
import { normalizeStrategyAddress } from "../telemetry/event-store.js";
|
|
7
|
-
import { getDefaultPiiRedactor } from "../telemetry/spans/redact-pii.js";
|
|
8
|
-
import { JOIN_ATTR } from "../utils/event-catalog.js";
|
|
9
|
-
import { PROCESS_EPOCH } from "./strategies-telemetry.js";
|
|
10
|
-
const BROADCAST_NAMES = new Set(EVENTS_BROADCAST_NAMES);
|
|
11
|
-
/**
|
|
12
|
-
* One ring of `capacity` records per address. `seq` starts at 1 and counts across every address.
|
|
13
|
-
* `now` is the clock, in epoch ms, that times a closed ring.
|
|
14
|
-
*/
|
|
15
|
-
export function createEventsBuffer(capacity = EVENTS_PER_STRATEGY, now = () => Date.now()) {
|
|
16
|
-
const rings = new Map();
|
|
17
|
-
// Rings closed by `remove`, each with the time it was closed. Kept apart from `rings` so a new
|
|
18
|
-
// ring for the same address never mixes with them.
|
|
19
|
-
const closed = new Map();
|
|
20
|
-
let seq = 0;
|
|
21
|
-
let maxEvicted = 0;
|
|
22
|
-
return {
|
|
23
|
-
add(address, event) {
|
|
24
|
-
const key = normalizeStrategyAddress(address);
|
|
25
|
-
const attrs = {};
|
|
26
|
-
for (const [k, v] of Object.entries(event.attrs)) {
|
|
27
|
-
if (typeof v === "string" || typeof v === "boolean" || (typeof v === "number" && Number.isFinite(v)))
|
|
28
|
-
attrs[k] = v;
|
|
29
|
-
}
|
|
30
|
-
let ring = rings.get(key);
|
|
31
|
-
if (ring === undefined) {
|
|
32
|
-
ring = [];
|
|
33
|
-
rings.set(key, ring);
|
|
34
|
-
}
|
|
35
|
-
ring.push({ seq: ++seq, ts: event.ts, name: event.name, level: event.level, address: key, body: event.body, attrs });
|
|
36
|
-
if (ring.length > capacity)
|
|
37
|
-
maxEvicted = Math.max(maxEvicted, ring.shift().seq);
|
|
38
|
-
},
|
|
39
|
-
after(after) {
|
|
40
|
-
const out = [];
|
|
41
|
-
const collect = (ring) => {
|
|
42
|
-
let i = ring.length;
|
|
43
|
-
while (i > 0 && ring[i - 1].seq > after)
|
|
44
|
-
i--;
|
|
45
|
-
for (; i < ring.length; i++)
|
|
46
|
-
out.push(ring[i]);
|
|
47
|
-
};
|
|
48
|
-
for (const ring of rings.values())
|
|
49
|
-
collect(ring);
|
|
50
|
-
for (const ring of closed.keys())
|
|
51
|
-
collect(ring);
|
|
52
|
-
return out.sort((a, b) => a.seq - b.seq);
|
|
53
|
-
},
|
|
54
|
-
newestSeq() {
|
|
55
|
-
let newest = 0;
|
|
56
|
-
for (const ring of rings.values()) {
|
|
57
|
-
if (ring.length > 0)
|
|
58
|
-
newest = Math.max(newest, ring[ring.length - 1].seq);
|
|
59
|
-
}
|
|
60
|
-
// A closed ring is never empty.
|
|
61
|
-
for (const ring of closed.keys())
|
|
62
|
-
newest = Math.max(newest, ring[ring.length - 1].seq);
|
|
63
|
-
return newest;
|
|
64
|
-
},
|
|
65
|
-
maxEvictedSeq: () => maxEvicted,
|
|
66
|
-
remove(address) {
|
|
67
|
-
const key = normalizeStrategyAddress(address);
|
|
68
|
-
const ring = rings.get(key);
|
|
69
|
-
if (ring === undefined)
|
|
70
|
-
return;
|
|
71
|
-
rings.delete(key);
|
|
72
|
-
if (ring.length > 0)
|
|
73
|
-
closed.set(ring, now());
|
|
74
|
-
},
|
|
75
|
-
dropSent(sentSeq) {
|
|
76
|
-
const expiredAt = now() - EVENTS_CLOSED_RING_TTL_MS;
|
|
77
|
-
for (const [ring, closedAt] of closed) {
|
|
78
|
-
const newest = ring[ring.length - 1].seq;
|
|
79
|
-
if (newest > sentSeq && closedAt > expiredAt)
|
|
80
|
-
continue;
|
|
81
|
-
closed.delete(ring);
|
|
82
|
-
maxEvicted = Math.max(maxEvicted, newest);
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/** The process buffer. Its `seq` run belongs to `PROCESS_EPOCH`. */
|
|
88
|
-
export const eventsBuffer = createEventsBuffer();
|
|
89
|
-
/**
|
|
90
|
-
* Adds a record to `buffer` under `address` for a case that is not a runtime event. It does not go
|
|
91
|
-
* through `logger.event`, so no event sink, disk ring or OTel record receives it. A blank `address`
|
|
92
|
-
* adds nothing. Never throws.
|
|
93
|
-
*/
|
|
94
|
-
export function addEventRecord(address, event, buffer = eventsBuffer) {
|
|
95
|
-
try {
|
|
96
|
-
if (normalizeStrategyAddress(address) !== "")
|
|
97
|
-
buffer.add(address, event);
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
// Callers are request handlers; a buffer failure must not fail the request.
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Wraps a wallet's event sink. Every event goes to `sink`. An event whose name is in
|
|
105
|
-
* `EVENTS_BROADCAST_NAMES` is also added to `buffer` under `address`.
|
|
106
|
-
*/
|
|
107
|
-
export function withEventsTap(address, sink, buffer = eventsBuffer) {
|
|
108
|
-
return {
|
|
109
|
-
append(event) {
|
|
110
|
-
sink.append(event);
|
|
111
|
-
try {
|
|
112
|
-
if (BROADCAST_NAMES.has(event.name))
|
|
113
|
-
buffer.add(address, event);
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
// The tap runs inside `logger.event` and must not throw into it.
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
flush: () => sink.flush(),
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
/** The redacted value, or `undefined` when the redactor throws. `""` is kept as is. */
|
|
123
|
-
async function scrubString(value, redactor) {
|
|
124
|
-
if (value === "")
|
|
125
|
-
return value;
|
|
126
|
-
try {
|
|
127
|
-
const out = await redactor.redact(value);
|
|
128
|
-
return typeof out === "string" ? out : undefined;
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
return undefined;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/** Join-id attrs. They hold ids, never free text, and are sent as they are. */
|
|
135
|
-
const UNSCRUBBED_ATTRS = new Set([
|
|
136
|
-
...Object.values(JOIN_ATTR),
|
|
137
|
-
"senpi.strategy.address",
|
|
138
|
-
"senpi.scanner.id",
|
|
139
|
-
]);
|
|
140
|
-
/**
|
|
141
|
-
* A copy of the record with every string in `body` and `attrs` run through the redactor, except the
|
|
142
|
-
* join-id attrs in `UNSCRUBBED_ATTRS`. A string attr the redactor cannot produce is left out; such a
|
|
143
|
-
* `body` becomes `""`.
|
|
144
|
-
*/
|
|
145
|
-
export async function scrubEventRecord(record, redactor) {
|
|
146
|
-
const attrs = {};
|
|
147
|
-
for (const [key, value] of Object.entries(record.attrs)) {
|
|
148
|
-
if (typeof value !== "string" || UNSCRUBBED_ATTRS.has(key)) {
|
|
149
|
-
attrs[key] = value;
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
const scrubbed = await scrubString(value, redactor);
|
|
153
|
-
if (scrubbed !== undefined)
|
|
154
|
-
attrs[key] = scrubbed;
|
|
155
|
-
}
|
|
156
|
-
return { ...record, body: (await scrubString(record.body, redactor)) ?? "", attrs };
|
|
157
|
-
}
|
|
158
|
-
const bytes = (value) => Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
159
|
-
/**
|
|
160
|
-
* Fills one frame of records: a JSON envelope of `envelopeBytes` whose `events` array holds the
|
|
161
|
-
* records, at most `maxBytes` serialized in total. `offer` answers `"added"`, `"full"` (the record
|
|
162
|
-
* does not fit what is already in the frame; it is not added) or `"oversize"` (the record does not
|
|
163
|
-
* fit an empty frame; it is not added). `take` returns the frame and starts an empty one.
|
|
164
|
-
*/
|
|
165
|
-
function createFramePacker(envelopeBytes, maxBytes) {
|
|
166
|
-
let frame = [];
|
|
167
|
-
let used = envelopeBytes;
|
|
168
|
-
return {
|
|
169
|
-
offer(record) {
|
|
170
|
-
const size = bytes(record);
|
|
171
|
-
if (envelopeBytes + size > maxBytes)
|
|
172
|
-
return { result: "oversize", bytes: size };
|
|
173
|
-
// One comma between two records.
|
|
174
|
-
const added = size + (frame.length > 0 ? 1 : 0);
|
|
175
|
-
if (used + added > maxBytes)
|
|
176
|
-
return { result: "full", bytes: size };
|
|
177
|
-
used += added;
|
|
178
|
-
frame.push(record);
|
|
179
|
-
return { result: "added", bytes: size };
|
|
180
|
-
},
|
|
181
|
-
take() {
|
|
182
|
-
const out = frame;
|
|
183
|
-
frame = [];
|
|
184
|
-
used = envelopeBytes;
|
|
185
|
-
return out;
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* The events part of the subscribe reply. A cursor whose `afterEpoch` is `epoch` selects the held
|
|
191
|
-
* records after `afterSeq`; any other cursor, or none, selects every held record. The newest
|
|
192
|
-
* selected records that fit `maxBytes` are served, scrubbed, in `seq` order. `truncated` is `true`
|
|
193
|
-
* when a record owed to the cursor was evicted, or a selected record was not served. A cursor of
|
|
194
|
-
* the current epoch is owed the records after `afterSeq`; a cursor of another epoch is owed every
|
|
195
|
-
* record of the current epoch; no cursor is owed nothing. Without a redactor no record is served.
|
|
196
|
-
*/
|
|
197
|
-
export async function buildEventsReplay(input) {
|
|
198
|
-
const buffer = input.buffer ?? eventsBuffer;
|
|
199
|
-
const epoch = input.epoch ?? PROCESS_EPOCH;
|
|
200
|
-
const maxBytes = input.maxBytes ?? EVENTS_MAX_FRAME_BYTES;
|
|
201
|
-
const redactor = input.redactor;
|
|
202
|
-
const afterSeq = input.cursor?.afterEpoch === epoch ? input.cursor.afterSeq : undefined;
|
|
203
|
-
let truncated = input.cursor !== undefined && buffer.maxEvictedSeq() > (afterSeq ?? 0);
|
|
204
|
-
if (redactor === null)
|
|
205
|
-
return { epoch, events: [], truncated: truncated || buffer.newestSeq() > (afterSeq ?? 0) };
|
|
206
|
-
const selected = buffer.after(afterSeq ?? 0);
|
|
207
|
-
const packer = createFramePacker(bytes({ epoch, events: [], truncated: false }), maxBytes);
|
|
208
|
-
// Newest first, one record at a time, until the frame is full.
|
|
209
|
-
for (let i = selected.length - 1; i >= 0; i--) {
|
|
210
|
-
const { result } = packer.offer(await scrubEventRecord(selected[i], redactor));
|
|
211
|
-
if (result === "added")
|
|
212
|
-
continue;
|
|
213
|
-
truncated = true;
|
|
214
|
-
// An oversize record is skipped and the older records are still served. A full reply ends here.
|
|
215
|
-
if (result === "full")
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
return { epoch, events: packer.take().reverse(), truncated };
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Each tick takes the records added since the previous tick. With a broadcast function, it scrubs
|
|
222
|
-
* them and broadcasts them as one or more messages of at most `maxFrameBytes` serialized bytes. A
|
|
223
|
-
* record that does not fit an empty message is dropped and passed to `warn`. Without a broadcast
|
|
224
|
-
* function, the records are not sent. While there is no redactor, the tick sends nothing and keeps
|
|
225
|
-
* the records for the first tick that has one. Each tick ends with `dropSent`: it deletes the closed
|
|
226
|
-
* rings whose records it has passed, and the closed rings held past `EVENTS_CLOSED_RING_TTL_MS`.
|
|
227
|
-
*/
|
|
228
|
-
export function createEventsPublisher(deps) {
|
|
229
|
-
const buffer = deps.buffer ?? eventsBuffer;
|
|
230
|
-
const getRedactor = deps.getRedactor ?? getDefaultPiiRedactor;
|
|
231
|
-
const epoch = deps.epoch ?? PROCESS_EPOCH;
|
|
232
|
-
const maxFrameBytes = deps.maxFrameBytes ?? EVENTS_MAX_FRAME_BYTES;
|
|
233
|
-
// Upper bound of the message without its records.
|
|
234
|
-
const envelopeBytes = bytes({ v: 1, epoch, batchSeq: Number.MAX_SAFE_INTEGER, events: [] });
|
|
235
|
-
let lastSeq = 0;
|
|
236
|
-
let batchSeq = 0;
|
|
237
|
-
let timer;
|
|
238
|
-
let inFlight = false;
|
|
239
|
-
const send = (broadcast, events) => {
|
|
240
|
-
const message = { v: 1, epoch, batchSeq: ++batchSeq, events };
|
|
241
|
-
broadcast(EVENTS_EVENT_NAME, message, { dropIfSlow: true });
|
|
242
|
-
};
|
|
243
|
-
const tick = async () => {
|
|
244
|
-
if (inFlight)
|
|
245
|
-
return;
|
|
246
|
-
inFlight = true;
|
|
247
|
-
try {
|
|
248
|
-
if (deps.getBroadcast() === undefined) {
|
|
249
|
-
lastSeq = Math.max(lastSeq, buffer.newestSeq());
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
const redactor = getRedactor();
|
|
253
|
-
if (redactor === null)
|
|
254
|
-
return;
|
|
255
|
-
const records = buffer.after(lastSeq);
|
|
256
|
-
if (records.length === 0)
|
|
257
|
-
return;
|
|
258
|
-
lastSeq = records[records.length - 1].seq;
|
|
259
|
-
const scrubbed = await Promise.all(records.map((record) => scrubEventRecord(record, redactor)));
|
|
260
|
-
const broadcast = deps.getBroadcast();
|
|
261
|
-
if (broadcast === undefined || timer === undefined)
|
|
262
|
-
return;
|
|
263
|
-
const packer = createFramePacker(envelopeBytes, maxFrameBytes);
|
|
264
|
-
for (const record of scrubbed) {
|
|
265
|
-
let offered = packer.offer(record);
|
|
266
|
-
if (offered.result === "full") {
|
|
267
|
-
send(broadcast, packer.take());
|
|
268
|
-
offered = packer.offer(record);
|
|
269
|
-
}
|
|
270
|
-
if (offered.result === "oversize") {
|
|
271
|
-
deps.warn?.("[senpi-runtime] event record exceeds the events frame size; dropped", {
|
|
272
|
-
seq: record.seq,
|
|
273
|
-
name: record.name,
|
|
274
|
-
address: record.address,
|
|
275
|
-
bytes: offered.bytes,
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
const last = packer.take();
|
|
280
|
-
if (last.length > 0)
|
|
281
|
-
send(broadcast, last);
|
|
282
|
-
}
|
|
283
|
-
catch (err) {
|
|
284
|
-
deps.onError?.(err);
|
|
285
|
-
}
|
|
286
|
-
finally {
|
|
287
|
-
buffer.dropSent(lastSeq);
|
|
288
|
-
inFlight = false;
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
return {
|
|
292
|
-
start() {
|
|
293
|
-
if (timer !== undefined)
|
|
294
|
-
return;
|
|
295
|
-
timer = setInterval(() => void tick(), EVENTS_SEND_INTERVAL_MS);
|
|
296
|
-
timer.unref?.();
|
|
297
|
-
},
|
|
298
|
-
stop() {
|
|
299
|
-
if (timer !== undefined)
|
|
300
|
-
clearInterval(timer);
|
|
301
|
-
timer = undefined;
|
|
302
|
-
},
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
//# sourceMappingURL=events-telemetry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"events-telemetry.js","sourceRoot":"","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E,MAAM,CAAC,OAAO;wBACvB,KAAK,EAAE,OAAO,CAAC,KAAK;qBACrB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;YAC3B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;gBAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC7C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACzB,QAAQ,GAAG,KAAK,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,KAAK;YACH,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO;YAChC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,EAAE,EAAE,uBAAuB,CAAC,CAAC;YAChE,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;QAClB,CAAC;QACD,IAAI;YACF,IAAI,KAAK,KAAK,SAAS;gBAAE,aAAa,CAAC,KAAK,CAAC,CAAC;YAC9C,KAAK,GAAG,SAAS,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Process-global store of running strategies for the `plugin.senpi.strategies` broadcast, keyed by
|
|
3
|
-
* runtime id. `run()` writes an entry after a runtime starts. The plugin replaces an entry after an
|
|
4
|
-
* in-place update, removes it on delete and boot rollback, and clears the store on service stop.
|
|
5
|
-
*/
|
|
6
|
-
import type { RuntimeConfig } from "./runtime-schema.js";
|
|
7
|
-
/** One running strategy. */
|
|
8
|
-
export interface StrategyRecord {
|
|
9
|
-
address: string;
|
|
10
|
-
name: string;
|
|
11
|
-
scanners: {
|
|
12
|
-
scannerId: string;
|
|
13
|
-
intervalSeconds: number;
|
|
14
|
-
}[];
|
|
15
|
-
}
|
|
16
|
-
/** The store entry for a loaded recipe: address, name and the scanners of `type: external_scanner`. */
|
|
17
|
-
export declare function strategyRecordFromConfig(config: RuntimeConfig): StrategyRecord;
|
|
18
|
-
export declare const strategiesStore: {
|
|
19
|
-
set(runtimeId: string, record: StrategyRecord): void;
|
|
20
|
-
get(runtimeId: string): StrategyRecord | undefined;
|
|
21
|
-
delete(runtimeId: string): void;
|
|
22
|
-
clear(): void;
|
|
23
|
-
/** The live map, typed read-only. */
|
|
24
|
-
view(): ReadonlyMap<string, StrategyRecord>;
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=strategies-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strategies-store.d.ts","sourceRoot":"","sources":["../../src/runtime/strategies-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,4BAA4B;AAC5B,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC5D;AAED,uGAAuG;AACvG,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc,CAc9E;AAWD,eAAO,MAAM,eAAe;mBACX,MAAM,UAAU,cAAc,GAAG,IAAI;mBAGrC,MAAM,GAAG,cAAc,GAAG,SAAS;sBAGhC,MAAM,GAAG,IAAI;aAGtB,IAAI;IAGb,qCAAqC;YAC7B,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC;CAG5C,CAAC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Process-global store of running strategies for the `plugin.senpi.strategies` broadcast, keyed by
|
|
3
|
-
* runtime id. `run()` writes an entry after a runtime starts. The plugin replaces an entry after an
|
|
4
|
-
* in-place update, removes it on delete and boot rollback, and clears the store on service stop.
|
|
5
|
-
*/
|
|
6
|
-
import { EXTERNAL_SCANNER_DEFAULT_INTERVAL_SECONDS } from "../runtime-api/intake/intake-mount.js";
|
|
7
|
-
/** The store entry for a loaded recipe: address, name and the scanners of `type: external_scanner`. */
|
|
8
|
-
export function strategyRecordFromConfig(config) {
|
|
9
|
-
return {
|
|
10
|
-
address: config.strategy?.wallet ?? "",
|
|
11
|
-
name: config.name,
|
|
12
|
-
scanners: (config.scanners ?? [])
|
|
13
|
-
.filter((scanner) => scanner.type === "external_scanner")
|
|
14
|
-
.map((scanner) => ({
|
|
15
|
-
scannerId: scanner.name,
|
|
16
|
-
intervalSeconds: typeof scanner.interval_seconds === "number"
|
|
17
|
-
? scanner.interval_seconds
|
|
18
|
-
: EXTERNAL_SCANNER_DEFAULT_INTERVAL_SECONDS,
|
|
19
|
-
})),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const STORE_KEY = Symbol.for("senpi.runtime.strategiesStore");
|
|
23
|
-
/** One map per process, pinned on `globalThis`, so every module copy reads and writes the same map. */
|
|
24
|
-
function storeMap() {
|
|
25
|
-
const holder = globalThis;
|
|
26
|
-
holder[STORE_KEY] ??= new Map();
|
|
27
|
-
return holder[STORE_KEY];
|
|
28
|
-
}
|
|
29
|
-
export const strategiesStore = {
|
|
30
|
-
set(runtimeId, record) {
|
|
31
|
-
storeMap().set(runtimeId, record);
|
|
32
|
-
},
|
|
33
|
-
get(runtimeId) {
|
|
34
|
-
return storeMap().get(runtimeId);
|
|
35
|
-
},
|
|
36
|
-
delete(runtimeId) {
|
|
37
|
-
storeMap().delete(runtimeId);
|
|
38
|
-
},
|
|
39
|
-
clear() {
|
|
40
|
-
storeMap().clear();
|
|
41
|
-
},
|
|
42
|
-
/** The live map, typed read-only. */
|
|
43
|
-
view() {
|
|
44
|
-
return storeMap();
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=strategies-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strategies-store.js","sourceRoot":"","sources":["../../src/runtime/strategies-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,yCAAyC,EAAE,MAAM,uCAAuC,CAAC;AAUlG,uGAAuG;AACvG,MAAM,UAAU,wBAAwB,CAAC,MAAqB;IAC5D,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE;QACtC,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;aAC9B,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC;aACxD,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACjB,SAAS,EAAE,OAAO,CAAC,IAAI;YACvB,eAAe,EACb,OAAO,OAAO,CAAC,gBAAgB,KAAK,QAAQ;gBAC1C,CAAC,CAAC,OAAO,CAAC,gBAAgB;gBAC1B,CAAC,CAAC,yCAAyC;SAChD,CAAC,CAAC;KACN,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAE9D,uGAAuG;AACvG,SAAS,QAAQ;IACf,MAAM,MAAM,GAAG,UAA2D,CAAC;IAC3E,MAAM,CAAC,SAAS,CAAC,KAAK,IAAI,GAAG,EAA0B,CAAC;IACxD,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,GAAG,CAAC,SAAiB,EAAE,MAAsB;QAC3C,QAAQ,EAAE,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IACD,GAAG,CAAC,SAAiB;QACnB,OAAO,QAAQ,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IACD,MAAM,CAAC,SAAiB;QACtB,QAAQ,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IACD,KAAK;QACH,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IACD,qCAAqC;IACrC,IAAI;QACF,OAAO,QAAQ,EAAE,CAAC;IACpB,CAAC;CACF,CAAC"}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Strategies telemetry: the payload built from the strategies store, and the loop that broadcasts
|
|
3
|
-
* that payload as `plugin.senpi.strategies`.
|
|
4
|
-
*/
|
|
5
|
-
import type { DslState } from "../types/dsl/index.js";
|
|
6
|
-
import type { StrategyRecord } from "./strategies-store.js";
|
|
7
|
-
/** Minted once per plugin process. `plugin.senpi.events` carries the same value. */
|
|
8
|
-
export declare const PROCESS_EPOCH: `${string}-${string}-${string}-${string}-${string}`;
|
|
9
|
-
export interface StrategyScannerPayload {
|
|
10
|
-
scannerId: string;
|
|
11
|
-
intervalSeconds: number;
|
|
12
|
-
lastAliveAt: number | null;
|
|
13
|
-
}
|
|
14
|
-
/** One tier of a DSL state, in the same order as the state's `tiers`. */
|
|
15
|
-
export interface StrategyDslTierPayload {
|
|
16
|
-
/** ROE % that reaches the tier. */
|
|
17
|
-
triggerPct: number;
|
|
18
|
-
/** % of high-water ROE locked as floor at the tier. */
|
|
19
|
-
lockHwPct: number;
|
|
20
|
-
/**
|
|
21
|
-
* Price that reaches the tier: `entryPrice * (1 + sign * triggerPct / 100 / leverage)`, with
|
|
22
|
-
* `sign` 1 for LONG and -1 for SHORT. Not rounded. It solves the move check of
|
|
23
|
-
* `tierIndexFromPrice` (`src/dsl/engine/floors.ts`) for equality.
|
|
24
|
-
*/
|
|
25
|
-
triggerPrice: number;
|
|
26
|
-
/**
|
|
27
|
-
* `currentTierIndex !== null && i <= currentTierIndex`, where `i` is this tier's index: the
|
|
28
|
-
* current tier is this tier or a higher one.
|
|
29
|
-
*/
|
|
30
|
-
reached: boolean;
|
|
31
|
-
}
|
|
32
|
-
/** One active DSL state of a strategy wallet. Fields are copied from the DSL state unless noted. */
|
|
33
|
-
export interface StrategyDslPayload {
|
|
34
|
-
asset: string;
|
|
35
|
-
/** Position dex. `""` for the main dex. */
|
|
36
|
-
dex: string;
|
|
37
|
-
direction: "LONG" | "SHORT";
|
|
38
|
-
entryPrice: number;
|
|
39
|
-
leverage: number;
|
|
40
|
-
phase: 1 | 2;
|
|
41
|
-
/** Phase 1 absolute floor price: DSL state `phase1.absoluteFloor`. */
|
|
42
|
-
firstStopLoss: number;
|
|
43
|
-
/** Price at the last monitor check. */
|
|
44
|
-
lastPrice: number;
|
|
45
|
-
/** Epoch ms of the last monitor check (`lastCheck`). `null` when the ISO string does not parse. */
|
|
46
|
-
lastPriceAt: number | null;
|
|
47
|
-
/** Current floor price. */
|
|
48
|
-
floorPrice: number;
|
|
49
|
-
/** Index into `tiers` of the current tier. `null` before the first tier is reached. */
|
|
50
|
-
currentTierIndex: number | null;
|
|
51
|
-
/**
|
|
52
|
-
* Epoch ms when the current tier was reached. `null` when the state has none or its ISO string
|
|
53
|
-
* does not parse.
|
|
54
|
-
*/
|
|
55
|
-
tierSince: number | null;
|
|
56
|
-
tiers: StrategyDslTierPayload[];
|
|
57
|
-
}
|
|
58
|
-
export interface StrategyPayload {
|
|
59
|
-
address: string;
|
|
60
|
-
name: string;
|
|
61
|
-
scanners: StrategyScannerPayload[];
|
|
62
|
-
/**
|
|
63
|
-
* One row per active DSL state of the strategy wallet. `[]` when the runtime has no handle, is
|
|
64
|
-
* not started, has no DSL, has no active DSL state, or when reading or copying its DSL states
|
|
65
|
-
* throws.
|
|
66
|
-
*/
|
|
67
|
-
dsl: StrategyDslPayload[];
|
|
68
|
-
}
|
|
69
|
-
export interface StrategiesPayload {
|
|
70
|
-
v: 1;
|
|
71
|
-
epoch: string;
|
|
72
|
-
generatedAt: number;
|
|
73
|
-
strategies: StrategyPayload[];
|
|
74
|
-
}
|
|
75
|
-
/** Liveness of one external scanner, epoch ms, or `null` when nothing was heard since the child (re)started. */
|
|
76
|
-
export type LastAliveAtFn = (runtimeId: string, scannerName: string) => number | null;
|
|
77
|
-
/** Active DSL states of one runtime, read from memory. `[]` when the runtime has no handle or no DSL. */
|
|
78
|
-
export type DslStatesFn = (runtimeId: string) => readonly DslState[];
|
|
79
|
-
export type StrategiesBroadcastFn = (event: string, payload: unknown, opts?: {
|
|
80
|
-
dropIfSlow?: boolean;
|
|
81
|
-
}) => void;
|
|
82
|
-
/**
|
|
83
|
-
* Builds the payload from the store and the DSL states. Copies only the payload fields from each
|
|
84
|
-
* DSL state. A runtime's state manager loads every address directory under its state directory.
|
|
85
|
-
* Only DSL states with a string `address` equal to the strategy wallet are kept.
|
|
86
|
-
*/
|
|
87
|
-
export declare function buildStrategiesPayload(input: {
|
|
88
|
-
epoch: string;
|
|
89
|
-
generatedAt: number;
|
|
90
|
-
store: ReadonlyMap<string, StrategyRecord>;
|
|
91
|
-
lastAliveAt: LastAliveAtFn;
|
|
92
|
-
dslStates: DslStatesFn;
|
|
93
|
-
/** Called with the runtime id when reading or copying that runtime's DSL states throws. */
|
|
94
|
-
onDslError?: (runtimeId: string, err: unknown) => void;
|
|
95
|
-
}): StrategiesPayload;
|
|
96
|
-
export interface StrategiesPublisher {
|
|
97
|
-
/** Ticks once, then every interval. A second call while running does nothing. */
|
|
98
|
-
start(): void;
|
|
99
|
-
/** Stops the ticks and resets the last payload to `strategies: []`. */
|
|
100
|
-
stop(): void;
|
|
101
|
-
/** The payload of the last tick. Before the first tick and after stop: `strategies: []`. */
|
|
102
|
-
lastPayload(): StrategiesPayload;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Each tick builds the payload from the store, the liveness reader and the DSL state reader, keeps
|
|
106
|
-
* it as the last payload, and broadcasts it when a broadcast function is available. The loop reads
|
|
107
|
-
* the store and never writes it.
|
|
108
|
-
*/
|
|
109
|
-
export declare function createStrategiesPublisher(deps: {
|
|
110
|
-
store: ReadonlyMap<string, StrategyRecord>;
|
|
111
|
-
lastAliveAt: LastAliveAtFn;
|
|
112
|
-
dslStates: DslStatesFn;
|
|
113
|
-
getBroadcast: () => StrategiesBroadcastFn | undefined;
|
|
114
|
-
onError?: (err: unknown) => void;
|
|
115
|
-
/**
|
|
116
|
-
* Called when a runtime's DSL read throws, once per runtime id and error message. A tick in
|
|
117
|
-
* which that runtime's read does not throw, including a tick where the runtime is no longer in
|
|
118
|
-
* the store, re-arms it for that runtime.
|
|
119
|
-
*/
|
|
120
|
-
onDslError?: (runtimeId: string, err: unknown) => void;
|
|
121
|
-
epoch?: string;
|
|
122
|
-
now?: () => number;
|
|
123
|
-
}): StrategiesPublisher;
|
|
124
|
-
//# sourceMappingURL=strategies-telemetry.d.ts.map
|