@senpi/runtime 3.0.108 → 3.0.111
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 +21 -7
- package/dist/actions/action-events.d.ts.map +1 -1
- package/dist/actions/action-events.js +54 -26
- package/dist/actions/action-events.js.map +1 -1
- package/dist/actions/action-runtime-module.d.ts.map +1 -1
- package/dist/actions/action-runtime-module.js +38 -7
- package/dist/actions/action-runtime-module.js.map +1 -1
- package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
- package/dist/actions/close-position/close-position.action.js +122 -15
- 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 +15 -2
- package/dist/actions/decision-engine.js.map +1 -1
- package/dist/actions/event-derivation.d.ts +71 -2
- package/dist/actions/event-derivation.d.ts.map +1 -1
- package/dist/actions/event-derivation.js +251 -8
- package/dist/actions/event-derivation.js.map +1 -1
- package/dist/actions/open-position/open-position.action.d.ts +28 -2
- package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
- package/dist/actions/open-position/open-position.action.js +220 -52
- package/dist/actions/open-position/open-position.action.js.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.d.ts +2 -1
- package/dist/actions/position-tracker/position-tracker.action.d.ts.map +1 -1
- package/dist/actions/position-tracker/position-tracker.action.js +62 -17
- package/dist/actions/position-tracker/position-tracker.action.js.map +1 -1
- package/dist/actions/skipped-signal-results.d.ts +25 -0
- package/dist/actions/skipped-signal-results.d.ts.map +1 -0
- package/dist/actions/skipped-signal-results.js +71 -0
- package/dist/actions/skipped-signal-results.js.map +1 -0
- package/dist/actions/store/types.d.ts +9 -2
- package/dist/actions/store/types.d.ts.map +1 -1
- package/dist/actions/store/types.js.map +1 -1
- package/dist/actions/types.d.ts +13 -0
- package/dist/actions/types.d.ts.map +1 -1
- package/dist/actions/types.js +13 -0
- package/dist/actions/types.js.map +1 -1
- package/dist/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +3 -0
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/constants/dsl/index.d.ts +15 -0
- package/dist/constants/dsl/index.d.ts.map +1 -1
- package/dist/constants/dsl/index.js +15 -0
- package/dist/constants/dsl/index.js.map +1 -1
- package/dist/dsl/engine-client/event-mapping.d.ts.map +1 -1
- package/dist/dsl/engine-client/event-mapping.js +14 -0
- package/dist/dsl/engine-client/event-mapping.js.map +1 -1
- package/dist/dsl/events/build-closed-event.d.ts +16 -1
- package/dist/dsl/events/build-closed-event.d.ts.map +1 -1
- package/dist/dsl/events/build-closed-event.js +6 -0
- package/dist/dsl/events/build-closed-event.js.map +1 -1
- package/dist/dsl/events/handlers.d.ts +7 -0
- package/dist/dsl/events/handlers.d.ts.map +1 -1
- package/dist/dsl/events/handlers.js +37 -7
- package/dist/dsl/events/handlers.js.map +1 -1
- package/dist/dsl/monitor/create-monitor.d.ts +6 -2
- package/dist/dsl/monitor/create-monitor.d.ts.map +1 -1
- package/dist/dsl/monitor/create-monitor.js +15 -9
- package/dist/dsl/monitor/create-monitor.js.map +1 -1
- package/dist/dsl/monitor/dsl-failure-events.d.ts +2 -0
- package/dist/dsl/monitor/dsl-failure-events.d.ts.map +1 -1
- package/dist/dsl/monitor/dsl-failure-events.js +2 -1
- package/dist/dsl/monitor/dsl-failure-events.js.map +1 -1
- package/dist/dsl/monitor/process-one-position.d.ts +1 -0
- package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
- package/dist/dsl/monitor/process-one-position.js +72 -29
- package/dist/dsl/monitor/process-one-position.js.map +1 -1
- package/dist/dsl/plugin/index.d.ts +8 -2
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +8 -6
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/health/types.d.ts +13 -0
- package/dist/health/types.d.ts.map +1 -1
- package/dist/health/types.js +12 -0
- package/dist/health/types.js.map +1 -1
- package/dist/index.d.ts +16 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +230 -39
- package/dist/index.js.map +1 -1
- package/dist/runtime/action-registry.d.ts.map +1 -1
- package/dist/runtime/action-registry.js +4 -3
- package/dist/runtime/action-registry.js.map +1 -1
- package/dist/runtime/domain-events.d.ts.map +1 -1
- package/dist/runtime/domain-events.js +7 -0
- package/dist/runtime/domain-events.js.map +1 -1
- package/dist/runtime/lifecycle-events.d.ts +9 -1
- package/dist/runtime/lifecycle-events.d.ts.map +1 -1
- package/dist/runtime/lifecycle-events.js +11 -2
- package/dist/runtime/lifecycle-events.js.map +1 -1
- package/dist/runtime/reconcile-run.d.ts +13 -3
- package/dist/runtime/reconcile-run.d.ts.map +1 -1
- package/dist/runtime/reconcile-run.js +4 -3
- package/dist/runtime/reconcile-run.js.map +1 -1
- package/dist/runtime/reconcile-state.d.ts +8 -0
- package/dist/runtime/reconcile-state.d.ts.map +1 -1
- package/dist/runtime/reconcile-state.js +4 -1
- package/dist/runtime/reconcile-state.js.map +1 -1
- package/dist/runtime/run.d.ts +1 -0
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime-schema.js +3 -3
- package/dist/runtime/runtime-schema.js.map +1 -1
- package/dist/runtime/runtime.d.ts +1 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +27 -3
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/supervisor/long-running-supervisor.d.ts +13 -0
- package/dist/runtime/supervisor/long-running-supervisor.d.ts.map +1 -1
- package/dist/runtime/supervisor/long-running-supervisor.js +1 -0
- package/dist/runtime/supervisor/long-running-supervisor.js.map +1 -1
- package/dist/runtime/validate-dsl-position-tracking.d.ts.map +1 -1
- package/dist/runtime/validate-dsl-position-tracking.js +2 -1
- package/dist/runtime/validate-dsl-position-tracking.js.map +1 -1
- package/dist/runtime-api/handlers/ingest-signals.d.ts.map +1 -1
- package/dist/runtime-api/handlers/ingest-signals.js +1 -0
- package/dist/runtime-api/handlers/ingest-signals.js.map +1 -1
- package/dist/runtime-api/handlers/types.d.ts +5 -0
- package/dist/runtime-api/handlers/types.d.ts.map +1 -1
- package/dist/runtime-api/intake/ingest-request.d.ts +17 -0
- package/dist/runtime-api/intake/ingest-request.d.ts.map +1 -0
- package/dist/runtime-api/intake/ingest-request.js +34 -0
- package/dist/runtime-api/intake/ingest-request.js.map +1 -0
- package/dist/runtime-api/intake/intake-events.d.ts +1 -1
- package/dist/runtime-api/intake/intake-events.d.ts.map +1 -1
- package/dist/runtime-api/intake/intake-events.js +9 -3
- package/dist/runtime-api/intake/intake-events.js.map +1 -1
- package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
- package/dist/runtime-api/intake/intake-mount.js +4 -19
- package/dist/runtime-api/intake/intake-mount.js.map +1 -1
- package/dist/runtime-api/intake/scaffold-error-router.js.map +1 -1
- package/dist/runtime-api/intake/scanner-launcher.d.ts.map +1 -1
- package/dist/runtime-api/intake/scanner-launcher.js +15 -0
- package/dist/runtime-api/intake/scanner-launcher.js.map +1 -1
- package/dist/runtime-api/intake/types.d.ts +6 -0
- package/dist/runtime-api/intake/types.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.js +2 -1
- package/dist/runtime-api/routes/signals.js.map +1 -1
- package/dist/runtime-api/routes/signals.schema.d.ts +1 -0
- package/dist/runtime-api/routes/signals.schema.d.ts.map +1 -1
- package/dist/runtime-api/routes/signals.schema.js +6 -0
- package/dist/runtime-api/routes/signals.schema.js.map +1 -1
- package/dist/scanners/engine/engine.d.ts +22 -1
- package/dist/scanners/engine/engine.d.ts.map +1 -1
- package/dist/scanners/engine/engine.js +78 -11
- package/dist/scanners/engine/engine.js.map +1 -1
- package/dist/scanners/engine/lifecycle.d.ts +7 -1
- package/dist/scanners/engine/lifecycle.d.ts.map +1 -1
- package/dist/scanners/events.d.ts +4 -0
- package/dist/scanners/events.d.ts.map +1 -1
- package/dist/scanners/events.js +2 -0
- package/dist/scanners/events.js.map +1 -1
- package/dist/scanners/external/scaffold/delivery.py +136 -14
- package/dist/scanners/external/scaffold/scaffold.py +61 -8
- package/dist/scanners/external/scaffold/ulid.py +58 -0
- package/dist/scanners/external-scanner-receiver.d.ts +17 -0
- package/dist/scanners/external-scanner-receiver.d.ts.map +1 -1
- package/dist/scanners/external-scanner-receiver.js +8 -0
- package/dist/scanners/external-scanner-receiver.js.map +1 -1
- package/dist/scanners/runtime-module.d.ts +1 -0
- package/dist/scanners/runtime-module.d.ts.map +1 -1
- package/dist/scanners/runtime-module.js +59 -9
- package/dist/scanners/runtime-module.js.map +1 -1
- package/dist/scripts/run-dsl-standalone-mock.js +6 -2
- package/dist/scripts/run-dsl-standalone-mock.js.map +1 -1
- package/dist/senpi/client.d.ts +16 -3
- package/dist/senpi/client.d.ts.map +1 -1
- package/dist/senpi/client.js +44 -13
- package/dist/senpi/client.js.map +1 -1
- package/dist/strategy/strategy-state.d.ts +9 -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/telemetry/attributes.d.ts +20 -0
- package/dist/telemetry/attributes.d.ts.map +1 -1
- package/dist/telemetry/attributes.js +24 -0
- package/dist/telemetry/attributes.js.map +1 -1
- package/dist/telemetry/event-builders.d.ts +81 -6
- package/dist/telemetry/event-builders.d.ts.map +1 -1
- package/dist/telemetry/event-builders.js +141 -17
- package/dist/telemetry/event-builders.js.map +1 -1
- package/dist/telemetry/event-store.d.ts +6 -0
- package/dist/telemetry/event-store.d.ts.map +1 -1
- package/dist/telemetry/event-store.js +12 -8
- package/dist/telemetry/event-store.js.map +1 -1
- package/dist/telemetry/live-telemetry.d.ts +192 -0
- package/dist/telemetry/live-telemetry.d.ts.map +1 -0
- package/dist/telemetry/live-telemetry.js +676 -0
- package/dist/telemetry/live-telemetry.js.map +1 -0
- package/dist/telemetry/metrics.d.ts +14 -2
- package/dist/telemetry/metrics.d.ts.map +1 -1
- package/dist/telemetry/metrics.js +19 -4
- package/dist/telemetry/metrics.js.map +1 -1
- package/dist/telemetry/scanner-stats.d.ts +143 -0
- package/dist/telemetry/scanner-stats.d.ts.map +1 -0
- package/dist/telemetry/scanner-stats.js +426 -0
- package/dist/telemetry/scanner-stats.js.map +1 -0
- package/dist/telemetry/spans/redact-pii.d.ts.map +1 -1
- package/dist/telemetry/spans/redact-pii.js +18 -2
- package/dist/telemetry/spans/redact-pii.js.map +1 -1
- package/dist/telemetry/strategy-topology.d.ts +99 -0
- package/dist/telemetry/strategy-topology.d.ts.map +1 -0
- package/dist/telemetry/strategy-topology.js +93 -0
- package/dist/telemetry/strategy-topology.js.map +1 -0
- package/dist/telemetry/telemetry-publisher.d.ts +63 -0
- package/dist/telemetry/telemetry-publisher.d.ts.map +1 -0
- package/dist/telemetry/telemetry-publisher.js +229 -0
- package/dist/telemetry/telemetry-publisher.js.map +1 -0
- package/dist/telemetry/timeline-buffer.d.ts +95 -0
- package/dist/telemetry/timeline-buffer.d.ts.map +1 -0
- package/dist/telemetry/timeline-buffer.js +237 -0
- package/dist/telemetry/timeline-buffer.js.map +1 -0
- package/dist/telemetry/tracing.d.ts +9 -0
- package/dist/telemetry/tracing.d.ts.map +1 -1
- package/dist/telemetry/tracing.js +36 -0
- package/dist/telemetry/tracing.js.map +1 -1
- package/dist/types/dsl/index.d.ts +11 -0
- package/dist/types/dsl/index.d.ts.map +1 -1
- package/dist/types/scanner.d.ts +15 -0
- package/dist/types/scanner.d.ts.map +1 -1
- package/dist/types/strategy.d.ts +5 -1
- package/dist/types/strategy.d.ts.map +1 -1
- package/dist/utils/event-catalog.d.ts +166 -0
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js +18 -0
- package/dist/utils/event-catalog.js.map +1 -1
- package/dist/utils/logger.d.ts +4 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/telemetry-required-log.d.ts +27 -0
- package/dist/utils/telemetry-required-log.d.ts.map +1 -0
- package/dist/utils/telemetry-required-log.js +68 -0
- package/dist/utils/telemetry-required-log.js.map +1 -0
- package/dist/utils/ulid.d.ts +9 -0
- package/dist/utils/ulid.d.ts.map +1 -0
- package/dist/utils/ulid.js +43 -0
- package/dist/utils/ulid.js.map +1 -0
- package/dist/validate/recipe-checks.d.ts.map +1 -1
- package/dist/validate/recipe-checks.js +2 -2
- package/dist/validate/recipe-checks.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder for the `plugin.senpi.strategies` payload — the topology view of the live telemetry
|
|
3
|
+
* stream: which strategies exist, whether each is up, how healthy it is, and which scanners it
|
|
4
|
+
* declares.
|
|
5
|
+
*
|
|
6
|
+
* Pure. Every fact arrives as an input, nothing is read from the registry or a runtime handle here,
|
|
7
|
+
* so the shape on the wire is testable without booting a runtime.
|
|
8
|
+
*
|
|
9
|
+
* Two properties this module exists to hold:
|
|
10
|
+
* - `status` distinguishes a runtime that is down from one that is up but has no live entry
|
|
11
|
+
* scanners. The second reads as healthy unless it is named, and it is not.
|
|
12
|
+
* - The raw scanner `config` never reaches the wire. It is an unbounded passthrough record and it
|
|
13
|
+
* has been through `resolveEnvInObject`, so it may hold resolved secrets. Only the declared,
|
|
14
|
+
* typed fields below are copied, each by name.
|
|
15
|
+
*/
|
|
16
|
+
import { createLogger } from "../utils/logger.js";
|
|
17
|
+
import { normalizeStrategyAddress } from "./event-store.js";
|
|
18
|
+
const logger = createLogger("[senpi-core][strategy-topology]");
|
|
19
|
+
/** Payload schema version. Bump when a field changes meaning, not when one is added. */
|
|
20
|
+
export const STRATEGY_TOPOLOGY_VERSION = 1;
|
|
21
|
+
/**
|
|
22
|
+
* Mirrors the three-way distinction `senpi.listRuntimes` draws: no handle is stopped, a handle in
|
|
23
|
+
* the unwired set is running blind, anything else is running. The wire carries the machine token —
|
|
24
|
+
* the operator-facing string is the frontend's to choose.
|
|
25
|
+
*/
|
|
26
|
+
function resolveStatus(runtimeId, running, unwired) {
|
|
27
|
+
if (!running.has(runtimeId))
|
|
28
|
+
return "stopped";
|
|
29
|
+
return unwired.has(runtimeId) ? "running_no_entry_scanners" : "running";
|
|
30
|
+
}
|
|
31
|
+
/** Health is advisory here: a lookup that fails must degrade the row, never the payload. */
|
|
32
|
+
function resolveHealth(runtimeId, readHealth) {
|
|
33
|
+
let status;
|
|
34
|
+
try {
|
|
35
|
+
status = readHealth?.(runtimeId);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
logger.warn("strategy topology could not read runtime health; reporting unknown", err, {
|
|
39
|
+
runtimeId,
|
|
40
|
+
});
|
|
41
|
+
return { health: "unknown", startedAt: null };
|
|
42
|
+
}
|
|
43
|
+
if (!status)
|
|
44
|
+
return { health: "unknown", startedAt: null };
|
|
45
|
+
const parsed = status.startedAt === undefined ? NaN : Date.parse(status.startedAt);
|
|
46
|
+
return {
|
|
47
|
+
health: status.health,
|
|
48
|
+
startedAt: Number.isFinite(parsed) ? parsed : null,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Copies the declared scanner fields one by one. Never spread `entry` and never copy `config` —
|
|
53
|
+
* see the module note.
|
|
54
|
+
*/
|
|
55
|
+
function buildScanner(source) {
|
|
56
|
+
const { entry, registration } = source;
|
|
57
|
+
const declaredSchema = entry.signal_data_schema;
|
|
58
|
+
return {
|
|
59
|
+
scannerId: entry.name,
|
|
60
|
+
scheduleMode: registration?.scheduleMode ?? (entry.type === "external_scanner" ? "external" : "interval"),
|
|
61
|
+
enabled: registration?.enabled ?? true,
|
|
62
|
+
intervalSeconds: registration?.intervalSeconds ?? entry.interval_seconds ?? null,
|
|
63
|
+
configVersion: registration?.configVersion ?? null,
|
|
64
|
+
signalDataSchema: declaredSchema ?? null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Builds one `plugin.senpi.strategies` payload from an already-gathered set of facts. */
|
|
68
|
+
export function buildStrategyTopology(input) {
|
|
69
|
+
const now = input.now ?? Date.now;
|
|
70
|
+
const strategies = input.strategies.map((source) => {
|
|
71
|
+
const { health, startedAt } = resolveHealth(source.runtimeId, input.readHealth);
|
|
72
|
+
return {
|
|
73
|
+
runtimeId: source.runtimeId,
|
|
74
|
+
// `(address, scannerId)` is the join key across all four payloads, and the other three
|
|
75
|
+
// normalize their own address input. A checksummed EIP-55 wallet reaching the wire raw would
|
|
76
|
+
// spell this strategy differently from its own scanner rows and timeline rows, and nothing
|
|
77
|
+
// downstream rejects that — the join just returns nothing.
|
|
78
|
+
address: normalizeStrategyAddress(source.address),
|
|
79
|
+
name: source.name,
|
|
80
|
+
status: resolveStatus(source.runtimeId, input.runningRuntimeIds, input.unwiredRuntimeIds),
|
|
81
|
+
health,
|
|
82
|
+
startedAt,
|
|
83
|
+
scanners: source.scanners.map(buildScanner),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
v: STRATEGY_TOPOLOGY_VERSION,
|
|
88
|
+
epoch: input.epoch,
|
|
89
|
+
generatedAt: now(),
|
|
90
|
+
strategies,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=strategy-topology.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-topology.js","sourceRoot":"","sources":["../../src/telemetry/strategy-topology.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAI5D,MAAM,MAAM,GAAG,YAAY,CAAC,iCAAiC,CAAC,CAAC;AAE/D,wFAAwF;AACxF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAyF3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,WAAW,EAAE,GAAG,EAAE;QAClB,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The producer tap for the live telemetry stream: a second {@link EventSink} that copies selected
|
|
3
|
+
* `logger.event` records into the in-memory {@link TimelineBuffer} while the on-disk ring keeps
|
|
4
|
+
* receiving every one of them. It sits on the serial trading path, so it resolves the scanner id,
|
|
5
|
+
* picks a fixed set of fields, appends, and returns — no I/O, no await, no counting, no serialization.
|
|
6
|
+
*
|
|
7
|
+
* Two lists govern the stream, and this module owns only the first:
|
|
8
|
+
* - ADMISSION ({@link ADMITTED_EVENT_NAMES}) — what enters the buffer. Every name the timeline
|
|
9
|
+
* displays PLUS every name a counter is derived from, because a counting source that never enters
|
|
10
|
+
* the buffer makes the stats read zero with nothing logged anywhere.
|
|
11
|
+
* - PUBLICATION — what leaves on the timeline event. Applied at flush time, not here. Admission is
|
|
12
|
+
* deliberately the wider of the two: filtering for display at append time is unrecoverable.
|
|
13
|
+
*/
|
|
14
|
+
import { type EventName } from "../utils/event-catalog.js";
|
|
15
|
+
import { type EventSink } from "./event-store.js";
|
|
16
|
+
import { type TimelineBuffer } from "./timeline-buffer.js";
|
|
17
|
+
/**
|
|
18
|
+
* The names that may enter the buffer. Volume control for a bounded ring, so it is an allow-list of
|
|
19
|
+
* the strategy's own narrative: what its scanners did, what each signal became, what was traded, and
|
|
20
|
+
* why the strategy's status changed. It excludes the box-operations and agent-plane families —
|
|
21
|
+
* `auto_update.*`, `tool.*`, `tool_approval.*`, the installer and state/mcp faults — and the
|
|
22
|
+
* mechanical, poll-frequency records (`dsl.sl_updated`, `dsl.close_pending`, `dsl.close_attempt`,
|
|
23
|
+
* `dsl.price_fetch_stale`), which would evict a strategy's recent window without adding a line
|
|
24
|
+
* anyone reads.
|
|
25
|
+
*
|
|
26
|
+
* Typed as `EventName`, so renaming a catalog entry out from under this list is a compile error
|
|
27
|
+
* rather than a silently empty counter.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ADMITTED_EVENT_NAMES: ReadonlySet<EventName>;
|
|
30
|
+
/**
|
|
31
|
+
* What the tap cost, in nanoseconds, since the last read. Two plain numbers and a maximum — no span,
|
|
32
|
+
* no histogram, no allocation: a span per event is exactly the blocking cost the buffer exists to
|
|
33
|
+
* avoid, and this sits on the same serial trading path the records describe.
|
|
34
|
+
*/
|
|
35
|
+
export interface TapCounters {
|
|
36
|
+
/** Tap invocations, admitted or not: the admission check is cost the trading path already paid. */
|
|
37
|
+
calls: number;
|
|
38
|
+
nsTotal: number;
|
|
39
|
+
/** The longest single call. An average hides the one append that had to evict. */
|
|
40
|
+
nsMax: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Take the window and zero it. The reader owns the window: a counter that is never reset reports a
|
|
44
|
+
* lifetime total forever, which sizes nothing. Process-wide, like the buffer the tap feeds.
|
|
45
|
+
*/
|
|
46
|
+
export declare function readAndResetTapCounters(): TapCounters;
|
|
47
|
+
export interface TelemetryPublisherOptions {
|
|
48
|
+
/** Buffer to feed. Defaults to the process buffer — one per process, shared by every address. */
|
|
49
|
+
buffer?: TimelineBuffer;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A sink that copies admitted records into the timeline buffer under `address`. One instance per
|
|
53
|
+
* registered address; every instance writes into the same process buffer, which is what makes the
|
|
54
|
+
* publisher process-wide and address-partitioned rather than per-runtime.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createTelemetryPublisherSink(address: string, options?: TelemetryPublisherOptions): EventSink;
|
|
57
|
+
/**
|
|
58
|
+
* One sink that feeds several. `registerEventSink` keys a single sink per address, so this is how
|
|
59
|
+
* the publisher rides alongside the on-disk ring instead of replacing it. Each branch already
|
|
60
|
+
* swallows its own failures; the loop keeps one branch's throw from starving the rest regardless.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createFanOutEventSink(sinks: readonly EventSink[]): EventSink;
|
|
63
|
+
//# sourceMappingURL=telemetry-publisher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-publisher.d.ts","sourceRoot":"","sources":["../../src/telemetry/telemetry-publisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEvF,OAAO,EAA4B,KAAK,SAAS,EAAoB,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAS9E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,SAAS,CAqDtD,CAAC;AAEH;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,mGAAmG;IACnG,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC;CACf;AAMD;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,WAAW,CAMrD;AASD,MAAM,WAAW,yBAAyB;IACxC,iGAAiG;IACjG,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAqCD;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,yBAA8B,GACtC,SAAS,CAkDX;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAuB5E"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The producer tap for the live telemetry stream: a second {@link EventSink} that copies selected
|
|
3
|
+
* `logger.event` records into the in-memory {@link TimelineBuffer} while the on-disk ring keeps
|
|
4
|
+
* receiving every one of them. It sits on the serial trading path, so it resolves the scanner id,
|
|
5
|
+
* picks a fixed set of fields, appends, and returns — no I/O, no await, no counting, no serialization.
|
|
6
|
+
*
|
|
7
|
+
* Two lists govern the stream, and this module owns only the first:
|
|
8
|
+
* - ADMISSION ({@link ADMITTED_EVENT_NAMES}) — what enters the buffer. Every name the timeline
|
|
9
|
+
* displays PLUS every name a counter is derived from, because a counting source that never enters
|
|
10
|
+
* the buffer makes the stats read zero with nothing logged anywhere.
|
|
11
|
+
* - PUBLICATION — what leaves on the timeline event. Applied at flush time, not here. Admission is
|
|
12
|
+
* deliberately the wider of the two: filtering for display at append time is unrecoverable.
|
|
13
|
+
*/
|
|
14
|
+
import { EVENT_NAME } from "../utils/event-catalog.js";
|
|
15
|
+
import { createLogger } from "../utils/logger.js";
|
|
16
|
+
import { normalizeStrategyAddress } from "./event-store.js";
|
|
17
|
+
import { getTimelineBuffer } from "./timeline-buffer.js";
|
|
18
|
+
const logger = createLogger("[senpi-core][telemetry-publisher]");
|
|
19
|
+
/** The scanner's STABLE id. Carried by every event whose `senpi.scanner.id` is ephemeral. */
|
|
20
|
+
const SCANNER_NAME_ATTR = "senpi.scanner.name";
|
|
21
|
+
/** Stable on `signal.outcome` and `scanner.summary`; the ephemeral per-launch id everywhere else. */
|
|
22
|
+
const SCANNER_ID_ATTR = "senpi.scanner.id";
|
|
23
|
+
/**
|
|
24
|
+
* The names that may enter the buffer. Volume control for a bounded ring, so it is an allow-list of
|
|
25
|
+
* the strategy's own narrative: what its scanners did, what each signal became, what was traded, and
|
|
26
|
+
* why the strategy's status changed. It excludes the box-operations and agent-plane families —
|
|
27
|
+
* `auto_update.*`, `tool.*`, `tool_approval.*`, the installer and state/mcp faults — and the
|
|
28
|
+
* mechanical, poll-frequency records (`dsl.sl_updated`, `dsl.close_pending`, `dsl.close_attempt`,
|
|
29
|
+
* `dsl.price_fetch_stale`), which would evict a strategy's recent window without adding a line
|
|
30
|
+
* anyone reads.
|
|
31
|
+
*
|
|
32
|
+
* Typed as `EventName`, so renaming a catalog entry out from under this list is a compile error
|
|
33
|
+
* rather than a silently empty counter.
|
|
34
|
+
*/
|
|
35
|
+
export const ADMITTED_EVENT_NAMES = new Set([
|
|
36
|
+
// Counting sources. `opens` and `skips` come from `signal.outcome`, `errors` from the two
|
|
37
|
+
// `scaffold.tick_*` names. These four are load-bearing, not display-driven.
|
|
38
|
+
EVENT_NAME.signalOutcome,
|
|
39
|
+
EVENT_NAME.decisionMade,
|
|
40
|
+
EVENT_NAME.scaffoldTickError,
|
|
41
|
+
EVENT_NAME.scaffoldTickTimeout,
|
|
42
|
+
// Scanner run and health: the per-run heartbeat plus every supervisor transition behind a
|
|
43
|
+
// scanner's health, degraded reason and restart count.
|
|
44
|
+
EVENT_NAME.scannerSummary,
|
|
45
|
+
EVENT_NAME.scannerSpawned,
|
|
46
|
+
EVENT_NAME.scannerExited,
|
|
47
|
+
EVENT_NAME.scannerRestarted,
|
|
48
|
+
EVENT_NAME.scannerDegraded,
|
|
49
|
+
EVENT_NAME.scannerRecovered,
|
|
50
|
+
EVENT_NAME.scannerSilenceKilled,
|
|
51
|
+
EVENT_NAME.scannerLaunchFailed,
|
|
52
|
+
// Signal intake: what arrived and what was dropped before an action ever evaluated it.
|
|
53
|
+
EVENT_NAME.signalAccepted,
|
|
54
|
+
EVENT_NAME.signalRejected,
|
|
55
|
+
EVENT_NAME.signalExpired,
|
|
56
|
+
EVENT_NAME.signalSuperseded,
|
|
57
|
+
// Execution: the order and position story behind an accepted signal.
|
|
58
|
+
EVENT_NAME.orderPlaced,
|
|
59
|
+
EVENT_NAME.orderFilled,
|
|
60
|
+
EVENT_NAME.orderFailed,
|
|
61
|
+
EVENT_NAME.positionOpened,
|
|
62
|
+
EVENT_NAME.positionClosed,
|
|
63
|
+
EVENT_NAME.positionIncreased,
|
|
64
|
+
EVENT_NAME.positionDecreased,
|
|
65
|
+
EVENT_NAME.positionFlipped,
|
|
66
|
+
EVENT_NAME.positionReconciled,
|
|
67
|
+
// Exit engine: the state changes of an armed exit, not its per-tick floor arithmetic.
|
|
68
|
+
EVENT_NAME.dslCreated,
|
|
69
|
+
EVENT_NAME.dslPhaseChanged,
|
|
70
|
+
EVENT_NAME.dslTierAdvanced,
|
|
71
|
+
EVENT_NAME.dslClosed,
|
|
72
|
+
EVENT_NAME.dslDeleted,
|
|
73
|
+
EVENT_NAME.dslSlSyncFailed,
|
|
74
|
+
EVENT_NAME.dslHandoffFailed,
|
|
75
|
+
// Strategy status, and the two faults that explain a strategy that is up but not trading.
|
|
76
|
+
EVENT_NAME.runtimeStarted,
|
|
77
|
+
EVENT_NAME.runtimeStopped,
|
|
78
|
+
EVENT_NAME.runtimePaused,
|
|
79
|
+
EVENT_NAME.runtimeResumed,
|
|
80
|
+
EVENT_NAME.runtimeError,
|
|
81
|
+
EVENT_NAME.runtimeQueueBackpressure,
|
|
82
|
+
EVENT_NAME.runtimeScannersUnwired,
|
|
83
|
+
]);
|
|
84
|
+
let tapCalls = 0;
|
|
85
|
+
let tapNsTotal = 0;
|
|
86
|
+
let tapNsMax = 0;
|
|
87
|
+
/**
|
|
88
|
+
* Take the window and zero it. The reader owns the window: a counter that is never reset reports a
|
|
89
|
+
* lifetime total forever, which sizes nothing. Process-wide, like the buffer the tap feeds.
|
|
90
|
+
*/
|
|
91
|
+
export function readAndResetTapCounters() {
|
|
92
|
+
const window = { calls: tapCalls, nsTotal: tapNsTotal, nsMax: tapNsMax };
|
|
93
|
+
tapCalls = 0;
|
|
94
|
+
tapNsTotal = 0;
|
|
95
|
+
tapNsMax = 0;
|
|
96
|
+
return window;
|
|
97
|
+
}
|
|
98
|
+
function noteTapCall(startedAt) {
|
|
99
|
+
const ns = Number(process.hrtime.bigint() - startedAt);
|
|
100
|
+
tapCalls += 1;
|
|
101
|
+
tapNsTotal += ns;
|
|
102
|
+
if (ns > tapNsMax)
|
|
103
|
+
tapNsMax = ns;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The scanner this record belongs to. The name attribute wins: `senpi.scanner.id` carries a
|
|
107
|
+
* per-launch id on the intake, scaffold and supervisor events, so reading it unqualified files one
|
|
108
|
+
* scanner under a new key on every external-scanner restart. Absent — never empty — when the record
|
|
109
|
+
* has no scanner at all; the record is still buffered and the client buckets it as unattributed.
|
|
110
|
+
*/
|
|
111
|
+
function resolveScannerId(attrs) {
|
|
112
|
+
const name = attrs[SCANNER_NAME_ATTR];
|
|
113
|
+
if (typeof name === "string" && name !== "")
|
|
114
|
+
return name;
|
|
115
|
+
const id = attrs[SCANNER_ID_ATTR];
|
|
116
|
+
return typeof id === "string" && id !== "" ? id : undefined;
|
|
117
|
+
}
|
|
118
|
+
function isScalar(value) {
|
|
119
|
+
const t = typeof value;
|
|
120
|
+
return t === "string" || t === "number" || t === "boolean";
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The bag minus any non-scalar value. Unlike the disk ring — which serializes and forgets — the
|
|
124
|
+
* buffer holds this reference for the whole retention window and then puts it on the wire, so a
|
|
125
|
+
* nested object would pin an arbitrary graph in memory and break the payload's scalar contract.
|
|
126
|
+
* The common case allocates nothing: a copy is made only once a bad value is actually seen.
|
|
127
|
+
*/
|
|
128
|
+
function scalarAttrs(attrs, onDropped) {
|
|
129
|
+
let clean = attrs;
|
|
130
|
+
for (const key of Object.keys(attrs)) {
|
|
131
|
+
if (isScalar(attrs[key]))
|
|
132
|
+
continue;
|
|
133
|
+
if (clean === attrs)
|
|
134
|
+
clean = { ...attrs };
|
|
135
|
+
delete clean[key];
|
|
136
|
+
onDropped();
|
|
137
|
+
}
|
|
138
|
+
return clean;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A sink that copies admitted records into the timeline buffer under `address`. One instance per
|
|
142
|
+
* registered address; every instance writes into the same process buffer, which is what makes the
|
|
143
|
+
* publisher process-wide and address-partitioned rather than per-runtime.
|
|
144
|
+
*/
|
|
145
|
+
export function createTelemetryPublisherSink(address, options = {}) {
|
|
146
|
+
const bufferAddress = normalizeStrategyAddress(address);
|
|
147
|
+
// Reset on a later success so a transient failure can warn again if it recurs, but a persistently
|
|
148
|
+
// wedged buffer cannot spam a per-event warn on the trading path.
|
|
149
|
+
let warnedAppendFailure = false;
|
|
150
|
+
let warnedNonScalarAttr = false;
|
|
151
|
+
function noteNonScalarAttr(name) {
|
|
152
|
+
if (warnedNonScalarAttr)
|
|
153
|
+
return;
|
|
154
|
+
warnedNonScalarAttr = true;
|
|
155
|
+
logger.warn("telemetry publisher dropped a non-scalar event attribute", {
|
|
156
|
+
"senpi.event.name": name,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
append(event) {
|
|
161
|
+
// Measured in a `finally` so the rejected and the failed paths count too: they are the cheapest
|
|
162
|
+
// and the most expensive calls the trading path makes, and an average of neither is honest.
|
|
163
|
+
const startedAt = process.hrtime.bigint();
|
|
164
|
+
try {
|
|
165
|
+
if (!ADMITTED_EVENT_NAMES.has(event.name))
|
|
166
|
+
return;
|
|
167
|
+
const attrs = event.attrs ?? {};
|
|
168
|
+
// Named fields only: whatever else rides the record — a redact slot, resource attributes —
|
|
169
|
+
// is not copied because it is never read.
|
|
170
|
+
(options.buffer ?? getTimelineBuffer()).append({
|
|
171
|
+
ts: event.ts,
|
|
172
|
+
name: event.name,
|
|
173
|
+
level: event.level,
|
|
174
|
+
address: bufferAddress,
|
|
175
|
+
scannerId: resolveScannerId(attrs),
|
|
176
|
+
body: event.body,
|
|
177
|
+
attrs: scalarAttrs(attrs, () => noteNonScalarAttr(event.name)),
|
|
178
|
+
});
|
|
179
|
+
warnedAppendFailure = false;
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
// The tap must never disturb the logging caller, and a wedged tap must not be silent.
|
|
183
|
+
if (!warnedAppendFailure) {
|
|
184
|
+
warnedAppendFailure = true;
|
|
185
|
+
logger.warn("telemetry publisher append failed; the live stream may be incomplete", {
|
|
186
|
+
address: bufferAddress,
|
|
187
|
+
err: err instanceof Error ? err.message : String(err),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
noteTapCall(startedAt);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
flush: () => Promise.resolve(),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* One sink that feeds several. `registerEventSink` keys a single sink per address, so this is how
|
|
200
|
+
* the publisher rides alongside the on-disk ring instead of replacing it. Each branch already
|
|
201
|
+
* swallows its own failures; the loop keeps one branch's throw from starving the rest regardless.
|
|
202
|
+
*/
|
|
203
|
+
export function createFanOutEventSink(sinks) {
|
|
204
|
+
return {
|
|
205
|
+
append(event) {
|
|
206
|
+
for (const sink of sinks) {
|
|
207
|
+
try {
|
|
208
|
+
sink.append(event);
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
// A branch that breaks its own no-throw contract must not cost the others their record.
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
async flush() {
|
|
216
|
+
// Sequential and individually guarded: a graceful stop awaits this, so one branch's rejection
|
|
217
|
+
// must not skip another's drain or surface as a failed stop.
|
|
218
|
+
for (const sink of sinks) {
|
|
219
|
+
try {
|
|
220
|
+
await sink.flush();
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
// A branch that cannot drain has already reported it; the stop path carries on.
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=telemetry-publisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-publisher.js","sourceRoot":"","sources":["../../src/telemetry/telemetry-publisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAkC,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAoC,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAuB,MAAM,sBAAsB,CAAC;AAE9E,MAAM,MAAM,GAAG,YAAY,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,CAAC;gBAAC,MAAM,CAAC;oBACP,wFAAwF;gBAC1F,CAAC;YACH,CAAC;QACH,CAAC;QACD,KAAK,CAAC,KAAK;YACT,8FAA8F;YAC9F,6DAA6D;YAC7D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,IAAI,CAAC;oBACH,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;gBACrB,CAAC;gBAAC,MAAM,CAAC;oBACP,gFAAgF;gBAClF,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory recent-window buffer for the live telemetry stream: the records a client replays on
|
|
3
|
+
* subscribe and the records the stats view is computed from. One buffer per process, partitioned by
|
|
4
|
+
* strategy address — the same shape as the disk ring's process-global sink map, because the tap that
|
|
5
|
+
* feeds it (`appendDomainEvent`) is process-global too.
|
|
6
|
+
*
|
|
7
|
+
* Three things make a client's state recoverable across a reconnect:
|
|
8
|
+
* - `epoch`, a ULID minted when the buffer is created. A change means the plugin restarted, not that
|
|
9
|
+
* frames were lost.
|
|
10
|
+
* - `seq`, monotonic per epoch across every address, so `(epoch, seq)` is a dedupe and resume key and
|
|
11
|
+
* a single `afterSeq` cursor is unambiguous. It never rewinds while the epoch holds — not on
|
|
12
|
+
* teardown, not on eviction.
|
|
13
|
+
* - {@link TimelineBuffer.oldestTs}, the stamp of the oldest record still held. A client whose cursor
|
|
14
|
+
* predates it knows it has a gap that no replay can fill.
|
|
15
|
+
*
|
|
16
|
+
* The write path is on the serial trading path: it takes one bounded slot write and returns. It does
|
|
17
|
+
* no I/O, awaits nothing, computes nothing, and never throws.
|
|
18
|
+
*/
|
|
19
|
+
import type { AttrValue } from "../utils/event-catalog.js";
|
|
20
|
+
import { type LogLevel } from "../utils/logger.js";
|
|
21
|
+
/**
|
|
22
|
+
* Records held per address before the oldest is overwritten. The bound is a record COUNT, per
|
|
23
|
+
* address: a fixed-size ring makes eviction a single slot write (no scan, no shift) and makes the
|
|
24
|
+
* oldest stamp an O(1) read, both of which a byte or age bound would cost the write path. Per address
|
|
25
|
+
* rather than process-wide so one chatty strategy cannot evict a quiet one's window.
|
|
26
|
+
*
|
|
27
|
+
* This is the number to change when the retention window is measured — see also the
|
|
28
|
+
* `maxRecordsPerAddress` option, which overrides it per buffer.
|
|
29
|
+
*/
|
|
30
|
+
export declare const DEFAULT_MAX_RECORDS_PER_ADDRESS = 2000;
|
|
31
|
+
/** The seq of the first record of an epoch. Records start at 1, so `afterSeq: 0` means "everything". */
|
|
32
|
+
export declare const FIRST_SEQ = 1;
|
|
33
|
+
/** One record as the tap hands it over, before the buffer stamps a seq. */
|
|
34
|
+
export interface TimelineRecordInput {
|
|
35
|
+
/** Call-time epoch ms, stamped by `logger.event`. */
|
|
36
|
+
ts: number;
|
|
37
|
+
name: string;
|
|
38
|
+
level: LogLevel;
|
|
39
|
+
address: string;
|
|
40
|
+
/** The engine scanner id. Absent — never empty — on a record that has no scanner. */
|
|
41
|
+
scannerId?: string;
|
|
42
|
+
body: string;
|
|
43
|
+
attrs: Record<string, AttrValue>;
|
|
44
|
+
}
|
|
45
|
+
/** A buffered record: the tap's input plus its position in the epoch. */
|
|
46
|
+
export interface TimelineRecord extends TimelineRecordInput {
|
|
47
|
+
seq: number;
|
|
48
|
+
}
|
|
49
|
+
/** Filters for {@link TimelineBuffer.read}; all optional, all combinable. Time bounds are inclusive. */
|
|
50
|
+
export interface TimelineQuery {
|
|
51
|
+
/** Exclusive lower bound on seq — the client's resume cursor. */
|
|
52
|
+
afterSeq?: number;
|
|
53
|
+
address?: string;
|
|
54
|
+
scannerId?: string;
|
|
55
|
+
sinceMs?: number;
|
|
56
|
+
untilMs?: number;
|
|
57
|
+
/** Keep the last N after filtering (newest tail). */
|
|
58
|
+
limit?: number;
|
|
59
|
+
}
|
|
60
|
+
export interface TimelineBufferOptions {
|
|
61
|
+
/** Overrides {@link DEFAULT_MAX_RECORDS_PER_ADDRESS}. Clamped to at least one record. */
|
|
62
|
+
maxRecordsPerAddress?: number;
|
|
63
|
+
}
|
|
64
|
+
export interface TimelineBuffer {
|
|
65
|
+
/** ULID minted with this buffer. Rides every published payload. */
|
|
66
|
+
readonly epoch: string;
|
|
67
|
+
/** Copy one record in and return. Never blocks, never throws. */
|
|
68
|
+
append(input: TimelineRecordInput): void;
|
|
69
|
+
/** Records matching `query`, oldest first. */
|
|
70
|
+
read(query?: TimelineQuery): TimelineRecord[];
|
|
71
|
+
/** Stamp of the oldest record still held across every address; undefined when nothing is held. */
|
|
72
|
+
oldestTs(): number | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* The largest seq this buffer has thrown away, or zero when it has thrown away nothing. A client
|
|
75
|
+
* resuming from a cursor BELOW this lost at least one record; a cursor at or above it lost none.
|
|
76
|
+
*
|
|
77
|
+
* It is not the oldest seq still held. The rings are per address, so a quiet strategy keeps a low
|
|
78
|
+
* seq alive long after a chatty one has evicted everything above it, and the oldest record held
|
|
79
|
+
* then says nothing about what a resuming client is missing.
|
|
80
|
+
*/
|
|
81
|
+
highestDroppedSeq(): number;
|
|
82
|
+
/** Records appended since the last drain, oldest first. Reads the publish frontier — does not evict. */
|
|
83
|
+
drain(): TimelineRecord[];
|
|
84
|
+
/** Drop every record. The seq counter is deliberately not rewound. */
|
|
85
|
+
teardown(): void;
|
|
86
|
+
}
|
|
87
|
+
export declare function createTimelineBuffer(options?: TimelineBufferOptions): TimelineBuffer;
|
|
88
|
+
/** The process's telemetry buffer, minted (with its epoch) on first use. */
|
|
89
|
+
export declare function getTimelineBuffer(): TimelineBuffer;
|
|
90
|
+
/**
|
|
91
|
+
* Drop the process buffer on plugin reload or shutdown. The next {@link getTimelineBuffer} mints a
|
|
92
|
+
* fresh epoch, so the restarted seq run cannot collide with the one a client already holds.
|
|
93
|
+
*/
|
|
94
|
+
export declare function teardownTimelineBuffer(): void;
|
|
95
|
+
//# sourceMappingURL=timeline-buffer.d.ts.map
|
|
@@ -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