import { LLMPurposes, type LLMModel, type LLMProviders } from '../LLMService.typedefs'; import { type LLMLoggerInterface } from '../utilities/logger'; import { type LLMFallbackMetricEmitter } from '../utilities/llmTracing'; import { type LLMGatewayPromptClient } from '../client/promptClientPort.typedefs'; import { type LLMPromptKind, type LLMPromptMessage, type LLMPromptSnapshot } from '../client/promptSnapshot.typedefs'; import { type LLMPromptConfig } from '../client/llmConfig.schema'; import { type LLMCapabilityRequirement } from '../client/defineLLMPrompts'; /** * The resolved, validated prompt the client uses for one call. For a `text` * prompt `text` is the compiled body; for a `chat` prompt `messages` is the * compiled role-tagged list (and `text` is their concatenation, kept for trace * IO + token counting). `config`/`model` passed the gate; `isFallback` flags * that the build-time snapshot was served (live fetch or gate failed), which the * generation observation records and the fallback metric counts. */ export interface ResolvedPrompt { name: string; kind: LLMPromptKind; text: string; messages: LLMPromptMessage[]; config: LLMPromptConfig; model: LLMModel; version: number; isFallback: boolean; } export interface ResolvePromptInput { name: string; kind: LLMPromptKind; variables: Record; requires: LLMCapabilityRequirement[]; purpose: LLMPurposes; label?: string; versionOverride?: number; labelOverride?: string; } export interface DescribePromptInput { name: string; kind: LLMPromptKind; requires: LLMCapabilityRequirement[]; purpose: LLMPurposes; label?: string; versionOverride?: number; labelOverride?: string; } /** * The live-resolved routing metadata for a prompt — what the runtime would serve * right now. `isFallback` flags that the build-time snapshot config was used * (live fetch unreachable or its config failed the gate). */ export interface ResolvedPromptMetadata { name: string; provider: LLMProviders; model: string; promptVersion: number; isFallback: boolean; } export interface PromptRegistryRuntimeConfig { promptClient: LLMGatewayPromptClient | undefined; snapshot: LLMPromptSnapshot; defaultLabel: string; cacheTtlSeconds?: number; logger?: LLMLoggerInterface; fallbackMetricEmitter?: LLMFallbackMetricEmitter; } /** * Owns prompt resolution at runtime: a live SDK fetch (cached 60s, * stale-while-revalidate) gated on every read, with the build-time snapshot as * the outage fallback. The single validation gate runs against both the live and * the fallback config; only a config that passes is ever served. When live and * fallback are both unusable the caller decides (throws `LLMConfigError`). */ export declare class PromptRegistryRuntime { private readonly promptClient; private readonly snapshot; private readonly defaultLabel; private readonly cacheTtlSeconds; private readonly logger; private readonly fallbackMetricEmitter; private hasWarnedThisProcess; constructor(config: PromptRegistryRuntimeConfig); /** * Warms the SDK cache for every snapshot prompt without blocking boot. Each * failure is swallowed so a Langfuse outage at pod start never delays serving; * the snapshot already covers the gap. Dispatches to `getChatPrompt` for a * chat-kind entry, else `getPrompt`. */ refreshAll(): Promise; resolve(input: ResolvePromptInput): Promise; /** * Resolves only the prompt's routing metadata (provider, model, version) via the * same live-fetch + gate + snapshot-fallback path `resolve` uses, without * compiling the body or requiring call-site variables. Config, model and * capability validation still applies, so a live config the gate would reject * falls back to the snapshot. * Returns what the runtime WOULD serve right now, including fallback. */ describe(input: DescribePromptInput): Promise; private describeFromSnapshot; private gateConfig; private tryResolveLive; private tryResolveFallback; private fetchLive; private buildFetchOptions; /** * Substitutes variables into the prompt body. For a `chat` prompt every * message's content is substituted and the roles are preserved; `text` is the * messages concatenated (newline-joined), which trace IO and `compilePrompt` * use. For a `text` prompt `messages` is empty. */ private compileBody; /** * Substitutes one variable at a time. The replacement is a function, not a * string: a string replacement would let `$&`, `$$`, `` $` `` and `$'` inside * a variable's value act as replacement patterns, so any user-authored text * carrying them would silently rewrite itself into the prompt. */ private substitute; private emitFallback; private warnOnce; } export declare function snapshotEntryNames(snapshot: LLMPromptSnapshot): string[];