/** * @pwngh/economy-lab * * Copyright (c) Preston Neal * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ import type { Clock, Logger, Meter } from '../ports.js'; /** * One buffered telemetry event. Meter counts and observations buffer as-is; a log call buffers * as name = event, value = 1, and tags = `{ level }` only — log fields are forwarded to the * host logger but never buffered, so detectors match on event names and levels alone. */ export type Signal = { /** Host-clock milliseconds at capture, the timestamp {@link SignalFeed.since} filters on. */ at: number; source: 'meter' | 'log'; name: string; value: number; tags: Readonly>; }; /** The read side of the buffer the detectors poll. */ export type SignalFeed = { /** Every buffered signal with `at >= t`, oldest first. Evicted signals are gone. */ since(t: number): ReadonlyArray; }; /** * What {@link createOpsRuntime} returns. The composition consumes `meter` and `logger` in place * of the host pair; `signals` is the feed the supervisor's detectors read. */ export type OpsRuntime = { meter: Meter; logger: Logger; signals: SignalFeed; }; /** * Wraps a host meter/logger pair with pass-through-plus-buffer instrumentation: every call is * forwarded to the host implementation unchanged (same arguments, host first), then recorded as * a {@link Signal} stamped from the host clock. The buffer is a bounded window — `capacity` * signals, 10,000 by default — and the oldest signals are dropped once it fills, so detectors * see recent history, never an unbounded log. Log fields are forwarded but never buffered, so * arbitrary field payloads never outlive the host's own log pipeline. * * @example * const ops = createOpsRuntime({ meter, logger, clock }); * // compose the economy with the wrapped pair; the host pair still sees every call * const ports = await openPorts(env, { clock, meter: ops.meter, logger: ops.logger }); * // ops.signals feeds createSupervisor / createSupervisorFrom */ export declare function createOpsRuntime(host: { meter: Meter; logger: Logger; clock: Clock; }, options?: { capacity?: number; }): OpsRuntime;