import * as _nestjs_common from '@nestjs/common'; import { Type, ModuleMetadata } from '@nestjs/common'; import { A as AiMessage, C as ConversationStore } from './conversation-store.interface-CtQY-qcc.cjs'; import { StepResult, LanguageModelUsage, FinishReason } from 'ai'; import { ZodType } from 'zod'; /** Price per 1M tokens, in USD. */ interface ModelPricing { input: number; output: number; } /** Maps a bare model id (no provider prefix) to its pricing. */ type PricingTable = Record; /** Minimal usage shape needed for cost. */ interface UsageLike { inputTokens?: number; outputTokens?: number; } /** * Default USD pricing per 1M tokens for common models. Override or extend via * `AiModule.forRoot({ pricing })`. Prices are indicative — verify against your * provider's current rates. */ declare const DEFAULT_PRICING: PricingTable; /** Strips a `"provider:"` prefix from a model id. */ declare function bareModelId(modelId: string): string; /** * Computes the USD cost of a usage record for a model. Returns 0 when the model * is not in the pricing table. */ declare function costOf(usage: UsageLike, modelId: string, pricing?: PricingTable): number; /** * A named, optionally versioned prompt template. */ interface PromptDefinition { /** Unique name used to look the prompt up. */ name: string; /** Optional version; when omitted the latest registered version is used. */ version?: string; /** Template body with `{{variable}}` placeholders. */ template: string; /** Optional human-readable description. */ description?: string; } /** Reference to a registered prompt for rendering. */ interface PromptRef { name: string; vars?: Record; version?: string; } /** * Replaces `{{var}}` placeholders in `template` with values from `vars`. * Throws if a referenced variable is missing, to catch typos early. */ declare function interpolate(template: string, vars?: Record): string; /** * Per-call overrides for an agent `.run()` / `.stream()`. */ interface AgentRunOptions { /** Override the agent's model for this call. Array = fallback chain. */ model?: string | string[]; /** Retry count forwarded to the underlying generate/stream call. */ maxRetries?: number; /** Override the agent's system prompt for this call. */ system?: string; /** Resolve the system prompt from the PromptRegistry (overrides `system`). */ systemPrompt?: PromptRef; /** * Recall relevant snippets from semantic memory and prepend them as context. * Requires `conversationId` and a `SemanticMemory` service. */ recall?: { query?: string; topK?: number; }; /** * Conversation id. When set, prior messages are loaded from the * `ConversationStore` before the call and the new exchange is persisted after. */ conversationId?: string; /** Override the maximum tool-calling steps. */ maxSteps?: number; /** Structured-output schema for this call (overrides the agent's `output`). */ schema?: ZodType; /** Sampling temperature. */ temperature?: number; /** Abort signal to cancel the underlying request. */ abortSignal?: AbortSignal; } /** * Result of an agent `.run()`. */ interface AgentResult { /** Generated text (empty string for structured-output runs). */ text: string; /** Parsed structured object, present only for structured-output runs. */ object?: T; /** Per-step details for multi-step tool runs. */ steps?: StepResult[]; /** Tool calls made during the run. */ toolCalls?: unknown[]; /** Aggregate token usage across all steps. */ usage?: LanguageModelUsage; /** Why generation stopped. */ finishReason?: FinishReason; /** Assistant/tool messages produced by the run. */ messages: AiMessage[]; } interface BudgetLimits { maxCostPerRun?: number; maxInputTokensPerRun?: number; maxOutputTokensPerRun?: number; maxTotalTokensPerRun?: number; } type BudgetExceededKind = 'cost' | 'inputTokens' | 'outputTokens' | 'totalTokens'; interface BudgetCheckContext { agent: string; model: string; conversationId?: string; messages: AiMessage[]; options: AgentRunOptions; } interface BudgetRunContext { agent: string; model: string; conversationId?: string; usage: LanguageModelUsage; cost: number; result: AgentResult; } interface BudgetExceededContext extends BudgetRunContext { exceeded: BudgetExceededKind; limit: number; } type BudgetDecision = { action: 'block'; reason?: string; } | { action: 'allow'; }; interface OnBudgetExceeded { /** * Called before the run. Use it to enforce dynamic limits (e.g. credits * stored in a database). Return block to abort the call, allow to proceed, * or void to defer to the global handler. */ beforeRunBudget?(ctx: BudgetCheckContext): BudgetDecision | Promise | void | Promise; /** * Called after the run with the actual cost and usage. Use it to deduct * credits or log spending. */ afterRunBudget?(ctx: BudgetRunContext): void | Promise; /** * Called when a configured static run limit is exceeded. Return a decision * to allow, block, or replace the result. */ onBudgetExceeded?(ctx: BudgetExceededContext): BudgetDecision | Promise; } interface BudgetExceededHandler { beforeRunBudget?(ctx: BudgetCheckContext): BudgetDecision | Promise | void | Promise; afterRunBudget?(ctx: BudgetRunContext): void | Promise; handleBudgetExceeded(ctx: BudgetExceededContext): BudgetDecision | Promise; } declare const BUDGET_EXCEEDED_HANDLER: unique symbol; /** * Ways to supply a custom conversation store: a class, or a class/factory/value * provider (registered under the internal store token). */ type ConversationStoreProvider = Type | { useClass: Type; } | { useFactory: (...args: any[]) => ConversationStore | Promise; inject?: any[]; } | { useValue: ConversationStore; }; /** * Per-provider configuration. Every field is optional so a provider can also * rely on its SDK's implicit environment variables (e.g. `OPENAI_API_KEY`). */ interface ProviderConfig { apiKey?: string; baseURL?: string; /** Extra headers forwarded on every request to this provider. */ headers?: Record; } /** * Providers the module knows how to instantiate out of the box. The matching * `@ai-sdk/*` package must be installed for a configured provider to resolve. */ interface ProvidersConfig { openai?: ProviderConfig; anthropic?: ProviderConfig; google?: ProviderConfig; } interface AiModuleOptions { /** Provider credentials keyed by provider name. */ providers?: ProvidersConfig; /** * Model used when a call does not specify one, e.g. `"openai:gpt-4o"` or a * bare `"gpt-4o"` when a single provider is configured. An array configures a * fallback chain (each tried in order). */ defaultModel?: string | string[]; /** Default retry count forwarded to generate/stream calls. */ maxRetries?: number; /** Default embedding model, e.g. `"openai:text-embedding-3-small"`. */ defaultEmbeddingModel?: string; /** Default image model, e.g. `"openai:dall-e-3"`. */ defaultImageModel?: string; /** Default speech (text-to-speech) model, e.g. `"openai:tts-1"`. */ defaultSpeechModel?: string; /** Default transcription model, e.g. `"openai:whisper-1"`. */ defaultTranscriptionModel?: string; /** Default maximum tool-calling steps for agent runs. */ defaultMaxSteps?: number; /** * OpenTelemetry settings forwarded to the AI SDK's `experimental_telemetry`. * Requires an OTel setup in the host app to actually export spans. */ telemetry?: { isEnabled?: boolean; functionId?: string; }; /** Prompt templates to register at startup. */ prompts?: PromptDefinition[]; /** Guardrail provider classes to register (also discovered via `@Guardrail`). */ guardrails?: _nestjs_common.Type[]; /** Custom vector store provider (defaults to `InMemoryVectorStore`). */ vectorStore?: _nestjs_common.Type | { useClass?: _nestjs_common.Type; useFactory?: (...args: any[]) => any; useValue?: any; inject?: any[]; }; /** * Response/embedding cache. When set, resolved language models are wrapped * with a caching middleware and embeddings are cached. */ cache?: _nestjs_common.Type | { useClass?: _nestjs_common.Type; useFactory?: (...args: any[]) => any; useValue?: any; inject?: any[]; }; /** TTL (ms) for cached generations/embeddings. Default: no expiry. */ cacheTtlMs?: number; /** Per-model USD pricing (per 1M tokens) for cost tracking. */ pricing?: PricingTable; /** Max accumulated USD cost per conversation before runs are blocked. */ maxCostPerConversation?: number; /** Per-run USD cost and token limits. */ budget?: BudgetLimits; /** Global handler invoked when a run exceeds its configured budget. */ budgetExceededHandler?: Type | { useClass?: Type; useFactory?: (...args: any[]) => BudgetExceededHandler | Promise; useValue?: BudgetExceededHandler; inject?: any[]; }; /** Rate limiter for throttling agent runs. */ rateLimiter?: _nestjs_common.Type | { useClass?: _nestjs_common.Type; useFactory?: (...args: any[]) => any; useValue?: any; inject?: any[]; }; /** Reranking model id (e.g. `"cohere:rerank-v3.5"`) for `ModelReranker`. */ rerankingModel?: string; /** Approval gate for tools flagged `requiresApproval` (defaults to auto-approve). */ approvalGate?: _nestjs_common.Type | { useClass?: _nestjs_common.Type; useFactory?: (...args: any[]) => any; useValue?: any; inject?: any[]; }; /** * Optional conversation store provider. When omitted an in-memory store is * registered. Use `useClass`/`useFactory`/`useValue` to plug a custom store. */ conversationStore?: ConversationStoreProvider; } /** * Async configuration for `AiModule.forRootAsync`, allowing the options to be * built from injected dependencies such as `ConfigService`. */ interface AiModuleAsyncOptions extends Pick { useFactory: (...args: any[]) => Promise | AiModuleOptions; inject?: any[]; /** * Optional conversation store provider registered alongside the async * options (the factory result's `conversationStore` is ignored for DI * reasons — declare it here instead). */ conversationStore?: ConversationStoreProvider; } /** * Classes registered via `AiModule.forFeature` for convenience so users do not * have to wire agents/tools into their own module's `providers` array. */ interface AiFeatureOptions { agents?: Type[]; tools?: Type[]; /** Guardrail provider classes to register for discovery. */ guardrails?: Type[]; /** Prompt templates to register at startup. */ prompts?: PromptDefinition[]; } export { type AiModuleOptions as A, type BudgetLimits as B, type ConversationStoreProvider as C, DEFAULT_PRICING as D, type ModelPricing as M, type OnBudgetExceeded as O, type PromptDefinition as P, type UsageLike as U, type AiModuleAsyncOptions as a, type AiFeatureOptions as b, type AgentRunOptions as c, type AgentResult as d, type BudgetExceededHandler as e, type BudgetExceededContext as f, BUDGET_EXCEEDED_HANDLER as g, type BudgetCheckContext as h, type BudgetDecision as i, type BudgetExceededKind as j, type BudgetRunContext as k, type PricingTable as l, type PromptRef as m, type ProviderConfig as n, type ProvidersConfig as o, bareModelId as p, costOf as q, interpolate as r };