import type { NexusAIConfig } from '../types/config.js'; import type { CompletionRequest } from '../types/messages.js'; import type { NexusPlan } from '../types/planning.js'; import type { NexusResponse, NexusStream } from '../types/response.js'; import type { AgentConfig, AgentResult } from '../types/agent.js'; import type { SpeechRequest, SpeechResponse, TranscriptionRequest, TranscriptionResponse, VoiceProvider, VoiceSessionConfig, VoiceTurnRequest, VoiceTurnResponse } from '../types/voice.js'; import type { ImageProvider } from '../types/images.js'; import type { EmbeddingRequest, EmbeddingResponse, EmbeddingsProvider } from '../types/embeddings.js'; import type { CreateCallRequest, CreateCallResponse, EndCallRequest, GetCallRequest, ListPhoneNumbersRequest, TelephonyCallDetails, TelephonyMediaStreamEvent, TelephonyOutboundAudioMessage, TelephonyPhoneNumber, TelephonyProvider, TelephonyResponseRequest, TelephonyStatusCallback, TelephonyWebhookResponse, TelephonyWebhookValidationRequest, UpdatePhoneNumberRequest } from '../types/telephony.js'; import type { PipelineStep } from '../pipeline/types.js'; import type { BaseProvider } from '../providers/base.js'; import { type VoiceSession } from '../voice/index.js'; import { ImageManager } from '../images/manager.js'; import { EmbeddingManager } from '../embeddings/manager.js'; import { type VerificationOptions } from '../hallucination/verification.js'; import { type SelfConsistencyOptions } from '../hallucination/consistency.js'; import { type BatchOptions, type BatchItemResult } from '../jobs/batch.js'; import { JobQueue, type QueueOptions } from '../jobs/queue.js'; import { type EvalCase, type EvalRunResult } from '../evals/runner.js'; import { type SummarizeVerifyFormatOptions, type WorkflowResult } from '../workflow/chains.js'; /** * Main runtime facade for provider routing, security, optimization, evals, voice, jobs, and observability. * * Use `new NexusAI(config)` when you want full control, or `createNexus()` for the beginner shorthand. */ export declare class NexusAI { /** Provider-neutral image generation and editing operations. */ readonly images: ImageManager; private config; private embeddingManager?; private providers; private router; private failover; private logger; private security; private contextWindow; private voiceManager; private telephonyManager; private optimizer; private cache; private auditLogger; private rateLimiter; private pipeline; private metrics; private health; private circuitBreaker; /** * Health, circuit, and probe-slot hooks for every provider call. Built once, not per request; the * arrow functions read `this` when called, after the constructor has run. */ private readonly attemptHooks; private semanticCache; /** * Creates a configured Nexus runtime. * * Provider SDKs are loaded lazily by each provider adapter, so unused providers do not add runtime work. */ constructor(config: NexusAIConfig); /** * Runs a completion through the full configured pipeline and returns one normalized response. */ complete(request: CompletionRequest): Promise; /** * Completes a request and verifies generated claims against provided context. */ completeVerified(request: CompletionRequest, options: VerificationOptions): Promise; /** * Samples multiple completions and returns the most self-consistent answer. */ completeConsistent(request: CompletionRequest, options?: SelfConsistencyOptions): Promise; /** * Previews routing, token usage, context fit, cost, and guardrail findings without calling a provider. */ plan(request: CompletionRequest): NexusPlan; /** * Streams a completion through the configured pipeline using normalized stream chunks. */ stream(request: CompletionRequest): NexusStream; /** * Runs an agent loop with registered tools and iteration limits. */ agent(config: AgentConfig): Promise; /** * Transcribes audio through a registered voice provider. */ transcribe(request: TranscriptionRequest): Promise; /** * Synthesizes speech through a registered voice provider. */ speak(request: SpeechRequest): Promise; /** * Runs one voice turn: optional transcription, completion, and optional speech synthesis. */ voice(request: VoiceTurnRequest): Promise; /** * Alias for `voice()` for apps that model calls as turns. */ voiceTurn(request: VoiceTurnRequest): Promise; /** * Creates a stateful voice session with transcript history, task prompts, and optional tools. */ createVoiceSession(config: VoiceSessionConfig): VoiceSession; /** * Creates an outbound call through a registered telephony provider. */ createCall(request: CreateCallRequest): Promise; /** * Creates a provider-specific webhook response such as TwiML. */ createTelephonyResponse(request: TelephonyResponseRequest): Promise; /** * Validates a telephony webhook signature when the provider supports it. */ validateTelephonyWebhook(request: TelephonyWebhookValidationRequest): Promise; /** Parses a telephony media-stream message into a neutral event, through the named provider. */ parseTelephonyMediaEvent(providerName: string, message: string | Record): TelephonyMediaStreamEvent | undefined; /** Formats outbound audio, a mark, or a clear as the named provider's media-stream message. */ formatTelephonyAudioMessage(providerName: string, streamId: string, payload: string, options?: { event?: 'media' | 'mark' | 'clear'; markName?: string; }): TelephonyOutboundAudioMessage; /** * Reads a call's current provider-side state, including the duration usage metering bills on. */ getCall(request: GetCallRequest): Promise; /** * Hangs up a live call through the provider's call-control API. */ endCall(request: EndCallRequest): Promise; /** * Parses a provider status webhook into a normalized record. Prefer this over media-stream * lifecycle events when metering usage. */ parseTelephonyStatusCallback(providerName: string, body: string | URLSearchParams | Record): TelephonyStatusCallback | undefined; /** * Lists phone numbers owned by the provider account. */ listPhoneNumbers(request?: ListPhoneNumbersRequest): Promise; /** * Points a phone number at a voice webhook and/or status callback. */ updatePhoneNumber(request: UpdatePhoneNumberRequest): Promise; /** * Provider-neutral embeddings, sharing this runtime's metrics, audit log, and rate limiter. * * Built on first access, so a runtime that never embeds pays nothing for the family. Adapters are * derived from the provider credentials already in `providers`, which makes `ai.embed('text')` * work without any embedding-specific configuration. */ get embeddings(): EmbeddingManager; /** * Embeds one text or a batch through the configured embedding provider. * * `vectors[0]` is the answer for the single-string form; a batch comes back in input order no * matter how many provider calls the model's batch limit required. */ embed(request: EmbeddingRequest): Promise; /** Embeds one text and returns the vector alone. */ embedOne(text: string, options?: Omit): Promise; /** * Registers a custom text provider at runtime. */ registerProvider(name: string, provider: BaseProvider): this; /** * Registers a custom voice provider at runtime. */ registerVoiceProvider(name: string, provider: VoiceProvider): this; /** * Registers a custom image provider at runtime. */ registerImageProvider(name: string, provider: ImageProvider): this; /** * Registers a custom telephony provider at runtime. */ registerTelephonyProvider(name: string, provider: TelephonyProvider): this; /** * Registers a custom embedding provider at runtime. */ registerEmbeddingProvider(name: string, provider: EmbeddingsProvider): this; /** Whether a text provider is configured. */ hasProvider(name: string): boolean; /** Whether a voice provider is configured. */ hasVoiceProvider(name: string): boolean; /** Whether an image provider is registered. */ hasImageProvider(name: string): boolean; /** Whether a telephony provider is configured. */ hasTelephonyProvider(name: string): boolean; /** Whether an embeddings provider is registered. */ hasEmbeddingProvider(name: string): boolean; /** * Lists configured text providers. */ listProviders(): string[]; /** Lists configured voice providers. */ listVoiceProviders(): string[]; /** Lists registered image providers. */ listImageProviders(): string[]; /** Lists configured telephony providers. */ listTelephonyProviders(): string[]; /** Lists registered embeddings providers. */ listEmbeddingProviders(): string[]; /** * Adds a custom pipeline step. */ use(step: PipelineStep): this; /** * Runs multiple completion requests with optional concurrency control. */ batchComplete(requests: CompletionRequest[], options?: BatchOptions): Promise>>; /** * Creates an in-process job queue for completion requests. */ createQueue(options?: QueueOptions): JobQueue; /** * Runs eval cases against this Nexus instance. */ runEvals(cases: EvalCase[]): Promise>; /** Runs the summarize, verify, and format workflow on this client. */ summarizeVerifyFormat(options: SummarizeVerifyFormatOptions): Promise; /** * Returns current provider health snapshots. */ /** Circuit state per provider, for a health endpoint or dashboard. */ getCircuitBreakerStatus(): import("../ops/circuit-breaker.js").CircuitSnapshot[]; /** Forces a circuit closed, for an operator override. Omit the name to reset every provider. */ resetCircuitBreaker(providerName?: string): void; /** * Loads circuit decisions other workers have published, when `circuitBreaker.store` is set. * Checks refresh shared state in the background on their own; awaiting this at startup means the * first request already avoids providers that are open elsewhere. */ syncCircuitBreaker(): Promise; /** Health of every provider seen so far, when health tracking is on. */ getProviderHealth(): import("../ops/health.js").ProviderHealthSnapshot[]; /** * Calls each provider's health check and records the result. */ checkProviders(): Promise>; /** * Returns an in-memory metrics snapshot. */ getMetricsSnapshot(): Record; /** * Returns Prometheus-formatted metrics when metrics are enabled. */ getPrometheusMetrics(): string; /** * Clears exact and semantic caches. */ clearCache(): void; /** Removes expired response-cache entries, returning how many went. */ clearExpiredCache(): number; /** Response-cache size, capacity, and expired entries not yet removed. */ getCacheStats(): { size: number; maxEntries: number; expiredEntries: number; }; private isAuditLogEnabled; private isCacheEnabled; private isCostBudgetEnabled; private isSecurityEnabled; private isTokenOptimizerEnabled; private isContextWindowEnabled; private hasResponseFormat; private streamWithContextWindow; private attachContextWindowToStream; private summarizeContext; private registerConfiguredProviders; private attachTrace; private getCachedResponse; private setCachedResponse; private enforceCostBudget; private estimatedOutputTokens; }