import { t as SpanProcessor } from "./index-B6DbWwO_.js"; import { n as AiSdkEvaluationModel, o as WrapEvaluationModelOptions, t as AiSdkEvaluationAnswer } from "./ai-sdk-evaluate-E6JEPzHC.js"; import { AttributeRedactorConfig, AttributeRedactorPreset } from "autotel"; //#region src/signals.d.ts /** What a signal sees: the request span's attributes plus a few typed fields. */ export interface SignalInput extends Record { /** Span name, e.g. `POST /api/checkout`. */ name: string; /** `http.response.status_code` when present. */ status?: number; /** True when the span ended with an error status. */ error: boolean; durationMs: number; } /** Answer to a yes/no question. `confidence` is the probability of `value`. */ export interface BooleanVerdict { value: boolean; confidence: number; } /** Answer to a pick-one question; `confidence` when the model returns a distribution. */ export interface ChoiceVerdict { value: TOption; confidence?: number; } /** Answer to a rubric question; `score` is the weighted position between levels. */ export interface ScoreVerdict { value: TLevel; score: number; confidence?: number; } export type Verdict = BooleanVerdict | ChoiceVerdict | ScoreVerdict; /** The question shape the evaluation model receives. */ export type SignalQuestion = { type: 'boolean'; instructions: string; criteria?: { true?: string; false?: string; }; } | { type: 'choice'; instructions: string; criteria: Record; } | { type: 'score'; instructions: string; criteria: readonly string[]; }; interface SignalBase { /** Attribute name under `signals.`: letters, digits, `_` and `-`. */ name: string; /** Cheap predicate; no model call when it returns false. Required with `keep`. */ when?: (event: SignalInput) => boolean; /** The question, in plain English. */ ask: string; /** Keep the request past tail sampling when it returns true. Promote only. */ keep?: (verdict: TVerdict) => boolean; /** Reuse a verdict across requests with the same key. `undefined` skips the cache. */ cacheKey?: (event: SignalInput) => string | undefined; } export interface BooleanSignalInput extends SignalBase { criteria?: { true?: string; false?: string; }; } export interface ChoiceSignalInput extends SignalBase> { /** Options, each with the description the model matches against. */ choice: Record; } export interface ScoreSignalInput extends SignalBase> { /** Ordered levels, lowest first. */ score: readonly [TLevel, TLevel, ...TLevel[]]; } /** A validated signal. Create with {@link defineSignal}. */ export interface Signal { name: string; question: SignalQuestion; when?: (event: SignalInput) => boolean; keep?: (verdict: Verdict) => boolean; cacheKey?: (event: SignalInput) => string | undefined; } export interface DefineSignal { (signal: ChoiceSignalInput): Signal; (signal: ScoreSignalInput): Signal; (signal: BooleanSignalInput): Signal; } /** * Declare a signal. `ask` alone is yes/no, `ask` + `choice` picks one option, * `ask` + `score` places the request on a rubric. */ export declare const defineSignal: DefineSignal; /** Map a model answer to a verdict for the signal that asked it. */ export declare function toVerdict(signal: Signal, answer: AiSdkEvaluationAnswer): Verdict; export interface SignalsOptions { /** AI SDK evaluation model (`EvaluationModelV4`). Required: there is no default. */ model: AiSdkEvaluationModel; signals: Signal[]; /** Model calls per minute across all signals; over budget, requests go unjudged. */ budget?: { /** @default 600 */ perMinute?: number; /** Pause after a failed call, in milliseconds. @default 30000 */ cooldownMs?: number; }; /** Per-call timeout in milliseconds. @default 2000 */ timeoutMs?: number; /** Verdicts kept for `cacheKey` reuse. @default 1000 */ cacheSize?: number; /** * What the model reads. Defaults to the request's attributes after redaction, * minus `autotel.*` internals. Pick fields to bound tokens and what leaves * the process. */ state?: (event: SignalInput) => Record | string; /** Larger states (JSON characters) are skipped. @default 100000 */ maxStateChars?: number; /** * Redaction applied to attributes before they reach the model. Request spans * reach this processor before the export pipeline's redactor runs, so this is * the only redaction the model's input gets. `false` sends them as they are. * @default 'default' */ redact?: AttributeRedactorConfig | AttributeRedactorPreset | false; /** Passed to {@link wrapEvaluationModel} for the model call's span. */ evaluation?: WrapEvaluationModelOptions; } export interface SignalsStats { /** Model calls made. */ calls: number; /** Requests with due signals left unjudged: budget, breaker or state size. */ skipped: number; /** Model calls that failed or timed out. */ errors: number; /** Verdicts served from `cacheKey`. */ cached: number; /** Requests kept by a signal. */ kept: number; } export interface SignalsProcessor extends SpanProcessor { stats(): SignalsStats; } /** * A span processor that judges finished request spans. Register it with * `init({ spanEnrichers: [createSignals(...)] })` so it runs before tail * sampling and export. All signals due for one request go into one call. * Any failure, timeout or exhausted budget leaves the request as it was. */ export declare function createSignals(options: SignalsOptions): SignalsProcessor; /** * An evaluation model that answers from a function instead of a provider, for * tests and playgrounds without a key. `calls` records every request. */ export declare function scriptedEvaluationModel(answer: (name: string, question: SignalQuestion, state: unknown) => AiSdkEvaluationAnswer, modelId?: string): AiSdkEvaluationModel & { calls: Array<{ state: unknown; questions: Record; }>; }; //#endregion export {};