import { EmbeddingManager } from '../embeddings/manager.js'; import type { EvalCase, EvalRunResult } from '../evals/runner.js'; import type { SelfConsistencyOptions } from '../hallucination/consistency.js'; import type { VerificationOptions } from '../hallucination/verification.js'; import { ImageManager } from '../images/manager.js'; import { type BatchItemResult, type BatchOptions } from '../jobs/batch.js'; import { JobQueue, type QueueOptions } from '../jobs/queue.js'; import type { PipelineStep } from '../pipeline/types.js'; import type { BaseProvider } from '../providers/base.js'; import { TelephonyManager } from '../telephony/manager.js'; import type { AgentConfig, AgentResult } from '../types/agent.js'; import type { NexusAIConfig } from '../types/config.js'; import type { EmbeddingRequest, EmbeddingResponse, EmbeddingsProvider } from '../types/embeddings.js'; import type { ImageProvider } from '../types/images.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 { CreateCallRequest, CreateCallResponse, EndCallRequest, GetCallRequest, ListPhoneNumbersRequest, TelephonyCallDetails, TelephonyMediaStreamEvent, TelephonyOutboundAudioMessage, TelephonyPhoneNumber, TelephonyProvider, TelephonyResponseRequest, TelephonyStatusCallback, TelephonyWebhookResponse, TelephonyWebhookValidationRequest, UpdatePhoneNumberRequest } from '../types/telephony.js'; import type { SpeechRequest, SpeechResponse, TranscriptionRequest, TranscriptionResponse, VoiceProvider, VoiceSessionConfig, VoiceTurnRequest, VoiceTurnResponse } from '../types/voice.js'; import type { VoiceSession } from '../voice/session.js'; import type { SummarizeVerifyFormatOptions, WorkflowResult } from '../workflow/chains.js'; import { OperationLifecycle } from './lifecycle.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; /** * What every operation of this client runs through: authorization, the rate limit, the budget, * hooks, audit, and metrics. Hand it to a graph, an agent, or a realtime session so its runs are * operations of this client too. */ readonly lifecycle: OperationLifecycle; 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; /** Loaded on the first semantic lookup, so a client without one never imports it. */ private semanticCache?; private semanticCacheLoading?; /** * Creates a configured Nexus runtime. * * Provider adapters and their SDKs load on each provider's first call, so unused providers add no * import cost and no 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. * * The stream opens on its first read: authorization, the rate limit, guardrails, routing, and the * budget run then, so an error from any of them surfaces from the iterator rather than from this * call. The operation finishes when the stream does, with the cost of the usage the provider * reported. */ stream(request: CompletionRequest): NexusStream; /** * Runs an agent loop with registered tools and iteration limits, as one operation of this * client whose model calls are operations of their own. */ 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; /** * The client's telephony, for what its own methods leave out: answering a call the same way on * every provider, transfer, conferences, recordings, and messages. Its operations run through the * client's lifecycle, so they are authorized, rate-limited, budgeted, and audited. */ get telephony(): TelephonyManager; /** * 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 lifecycle, 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. Each job is one completion, and so one * operation of this client's lifecycle. */ 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; /** 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. With `staleOnly`, only the providers * whose health is `unknown` are checked: never called, or not since `health.observationTtlMs`. Run * it on a schedule to keep an idle provider's health current. */ checkProviders(options?: { staleOnly?: boolean; }): 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; }; /** A completion as the lifecycle sees it. */ private describe; private startOptions; /** * A route kept inside the regions the operation may reach: each attempt sent to its provider when * that runs inside them, to the provider's twin inside them when there is one, and dropped when * neither. With nothing left, the operation is refused with a `ResidencyError` naming the rule. */ private placeRoute; /** * How failover runs the provider calls of one operation, with the context each attempt hands on, * and, given the operation's ticket, how a refused credential is resolved again and every error * cleaned of the credentials it resolved. */ private executionOptions; /** * Times a lifecycle stage into the trace when the lifecycle has work to do, so a client with * nothing configured keeps the trace it always had. */ private lifecycleStep; /** * Applies the per-request cost limit and holds the estimate against the shared budget. The * estimate is priced once for both. */ private applyBudgets; /** * Prices a response on the model the request was routed to, as the registry names it, unless the * provider reported an authoritative charge. A provider echoes back names such as a dated snapshot * that the registry does not file, so its own pricing can miss. */ private reconcileCost; private isCacheEnabled; private isCostBudgetEnabled; private isSecurityEnabled; private isTokenOptimizerEnabled; private isContextWindowEnabled; private hasResponseFormat; /** Every stage of a stream before the provider: guardrails, routing, and the budget. */ private openStream; /** The final chunk's metadata: the operation's id, the context-window usage, and the reconciled cost. */ private finishStreamMeta; /** * Summarizes earlier turns for the context window. The summary is a paid model call, so it runs * as an operation of its own: authorized, budgeted, and audited like any other. */ private summarizeContext; private attachTrace; private usesSemanticCache; private loadSemanticCache; /** * Where a request's cached response lives: its key, its namespace, and the scope a semantic match * must share, which is always at least the request's tenant. */ private cachePlan; /** Looks a request up in the cache. A cache that fails is reported as an `error` outcome and treated as a miss. */ private getCachedResponse; private setCachedResponse; private estimateRequestCost; private enforceCostBudget; private estimatedOutputTokens; }