/** * SMI-5016: In-process telemetry HOF + Set-based registry. * * `withTelemetry` wraps a handler function with timing + emit + error-safe * envelope. A module-scoped `Set` tracks all wrapped functions so * the three-tree snapshot test (SMI-5018) can assert 100% dispatcher coverage * via `isTelemetered()`. * * Applied review change H3: registry is an exported Set (not function-object * mutation) so arrow-const exports can be wrapped without mutation. * Applied review change H4: `framework` is captured per-call, not memoised. */ import type { AgentMarker } from './agent-marker.js'; type AnyFunction = (...args: never[]) => unknown; /** * Run `fn` with `enabled` installed as the emission-gate decision for every * telemetry emit inside its async continuation. Concurrency-safe: parallel * invocations each see only their own value; code outside any * `runWithEmissionGate` scope falls back to the module `let` (default-suppress * when that too is unset). * * Takes a resolved boolean VALUE (consent resolved once at dispatch) — contrast * `setEmissionGate`, which takes a predicate thunk. The value is read live in * the emit path, so an in-flight call always observes the gate active for ITS * OWN scope, never a sibling's. */ export declare function runWithEmissionGate(enabled: boolean, fn: () => Promise): Promise; /** * Install (or clear) the process-wide FALLBACK emission gate. * * @deprecated Prefer `runWithEmissionGate`, which scopes the decision to a * single call's async continuation and auto-unwinds — no reset discipline, no * cross-call leak. `setEmissionGate` survives only as a test seam and the * pre-SMI-5479 fallback: its predicate is consulted (evaluated once per wrapped * call, in the `finally` block) ONLY when no `runWithEmissionGate` scope is * active. Pass a predicate to enable emission when it returns true; pass * `undefined` to revert to default-suppress. */ export declare function setEmissionGate(gate: (() => boolean) | undefined): void; /** * Run `fn` with `marker` installed as the agent-mediation context for every * telemetry emit inside its async continuation. Concurrency-safe: parallel * invocations each see only their own marker; code outside any * `runWithMarkerContext` scope sees no marker (fields default false/false/null). */ export declare function runWithMarkerContext(marker: AgentMarker, fn: () => Promise): Promise; /** * Run `fn` with `toolName` installed as the dispatch-level tool-name context * for every `emitToolCallEvent` inside its async continuation. Mirrors * `runWithMarkerContext` — concurrency-safe, no manual clearing. */ export declare function runWithToolNameContext(toolName: string, fn: () => Promise): Promise; /** * Options for `withTelemetry`. * * `extractSkillId` and `extractFramework` receive the arguments array at * call-time so they can derive values from the live request context. * `extractFramework` is intentionally per-call (H4) — not memoised. */ export interface WithTelemetryOpts { /** Discriminator stored with the event — which invocation surface this is. */ source: 'mcp-tool' | 'cli' | 'vscode-extension'; /** Derive the skill ID from the handler's arguments at call-time. */ extractSkillId: (args: TArgs) => string; /** * Derive the framework string from the handler's arguments at call-time. * Per H4: called once per invocation, never memoised. * Returns `'unknown'` if omitted. */ extractFramework?: (args: TArgs) => string; } /** * Wraps `handler` with a timing + telemetry emit envelope and registers the * returned function in the module-scoped `wrapped` Set. * * Guarantees: * - The emit happens even when `handler` throws (`finally` block). * - Telemetry errors are swallowed — they never affect the caller. * - The returned function preserves the original call signature (`F`). * - Calling `withTelemetry` on the same original function twice produces two * distinct wrapped functions (both registered in the Set). * * @example * // Arrow-const export — the critical H3 case: * export const myTool = withTelemetry( * async (args) => { ... }, * { source: 'mcp-tool', extractSkillId: (a) => a[0].skill } * ) */ export declare function withTelemetry(handler: (...args: TArgs) => Promise | TReturn, opts: WithTelemetryOpts): (...args: TArgs) => Promise; /** * Returns `true` if `fn` was produced by `withTelemetry`. * * Used by the three-tree snapshot test (SMI-5018) to assert that every * dispatcher export is telemetry-wrapped. * * Note: checks the *wrapped* function reference, not the original handler. * `isTelemetered(originalHandler)` is always `false`. */ export declare function isTelemetered(fn: AnyFunction): boolean; export {}; //# sourceMappingURL=wrap.d.ts.map