nexus-ai-pro 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/telephony/providers/twilio.js +12 -0
  3. package/dist/types/telephony.d.ts +17 -0
  4. package/dist-cjs/agent/loop.d.ts +12 -0
  5. package/dist-cjs/agent/tool.d.ts +16 -0
  6. package/dist-cjs/cache/adapters.d.ts +42 -0
  7. package/dist-cjs/cache/memory-cache.d.ts +20 -0
  8. package/dist-cjs/cache/semantic-cache.d.ts +19 -0
  9. package/dist-cjs/connectors/web.d.ts +20 -0
  10. package/dist-cjs/context/index.d.ts +2 -0
  11. package/dist-cjs/context/window.d.ts +34 -0
  12. package/dist-cjs/core/config-builder.d.ts +97 -0
  13. package/dist-cjs/core/create-nexus.d.ts +33 -0
  14. package/dist-cjs/core/nexus.d.ts +222 -0
  15. package/dist-cjs/core/response-format.d.ts +8 -0
  16. package/dist-cjs/core/secure-stream.d.ts +3 -0
  17. package/dist-cjs/core/streaming.d.ts +4 -0
  18. package/dist-cjs/embeddings/providers.d.ts +20 -0
  19. package/dist-cjs/evals/index.d.ts +3 -0
  20. package/dist-cjs/evals/judge.d.ts +50 -0
  21. package/dist-cjs/evals/metrics.d.ts +75 -0
  22. package/dist-cjs/evals/runner.d.ts +47 -0
  23. package/dist-cjs/hallucination/consistency.d.ts +15 -0
  24. package/dist-cjs/hallucination/factual.d.ts +14 -0
  25. package/dist-cjs/hallucination/knowledge-graph.d.ts +31 -0
  26. package/dist-cjs/hallucination/rag.d.ts +21 -0
  27. package/dist-cjs/hallucination/retrieval.d.ts +24 -0
  28. package/dist-cjs/hallucination/verification.d.ts +36 -0
  29. package/dist-cjs/images/assets.d.ts +115 -0
  30. package/dist-cjs/images/errors.d.ts +35 -0
  31. package/dist-cjs/images/index.d.ts +4 -0
  32. package/dist-cjs/images/manager.d.ts +23 -0
  33. package/dist-cjs/images/mock.d.ts +17 -0
  34. package/dist-cjs/images/openai.d.ts +46 -0
  35. package/dist-cjs/index.d.ts +80 -0
  36. package/dist-cjs/jobs/batch.d.ts +11 -0
  37. package/dist-cjs/jobs/durable-adapters.d.ts +48 -0
  38. package/dist-cjs/jobs/queue.d.ts +24 -0
  39. package/dist-cjs/models/registry.d.ts +15 -0
  40. package/dist-cjs/next/route-handler.d.ts +6 -0
  41. package/dist-cjs/ops/audit-logger.d.ts +6 -0
  42. package/dist-cjs/ops/health.d.ts +29 -0
  43. package/dist-cjs/ops/metrics.d.ts +53 -0
  44. package/dist-cjs/ops/otel-tracing.d.ts +20 -0
  45. package/dist-cjs/ops/rate-limiter.d.ts +11 -0
  46. package/dist-cjs/optimizer/budget.d.ts +19 -0
  47. package/dist-cjs/optimizer/cost.d.ts +13 -0
  48. package/dist-cjs/optimizer/densifier.d.ts +10 -0
  49. package/dist-cjs/optimizer/index.d.ts +12 -0
  50. package/dist-cjs/pipeline/pipeline.d.ts +14 -0
  51. package/dist-cjs/pipeline/types.d.ts +48 -0
  52. package/dist-cjs/providers/anthropic.d.ts +20 -0
  53. package/dist-cjs/providers/azure-openai.d.ts +8 -0
  54. package/dist-cjs/providers/base.d.ts +23 -0
  55. package/dist-cjs/providers/cohere.d.ts +16 -0
  56. package/dist-cjs/providers/deepseek.d.ts +8 -0
  57. package/dist-cjs/providers/errors.d.ts +26 -0
  58. package/dist-cjs/providers/google.d.ts +22 -0
  59. package/dist-cjs/providers/groq.d.ts +15 -0
  60. package/dist-cjs/providers/llamacpp.d.ts +8 -0
  61. package/dist-cjs/providers/lmstudio.d.ts +8 -0
  62. package/dist-cjs/providers/mistral.d.ts +15 -0
  63. package/dist-cjs/providers/ollama.d.ts +16 -0
  64. package/dist-cjs/providers/openai.d.ts +33 -0
  65. package/dist-cjs/providers/openrouter.d.ts +14 -0
  66. package/dist-cjs/providers/type-guards.d.ts +8 -0
  67. package/dist-cjs/rag/file-ingestion.d.ts +20 -0
  68. package/dist-cjs/rag/ingestion.d.ts +21 -0
  69. package/dist-cjs/realtime/conversation.d.ts +19 -0
  70. package/dist-cjs/realtime/errors.d.ts +25 -0
  71. package/dist-cjs/realtime/events.d.ts +10 -0
  72. package/dist-cjs/realtime/id.d.ts +2 -0
  73. package/dist-cjs/realtime/index.d.ts +22 -0
  74. package/dist-cjs/realtime/mock.transport.d.ts +55 -0
  75. package/dist-cjs/realtime/openai-events.d.ts +5 -0
  76. package/dist-cjs/realtime/openai-server.d.ts +33 -0
  77. package/dist-cjs/realtime/openai-webrtc.transport.d.ts +153 -0
  78. package/dist-cjs/realtime/openai-websocket.transport.d.ts +65 -0
  79. package/dist-cjs/realtime/provider.d.ts +37 -0
  80. package/dist-cjs/realtime/session.d.ts +110 -0
  81. package/dist-cjs/realtime/tools.d.ts +47 -0
  82. package/dist-cjs/realtime/transport-utils.d.ts +55 -0
  83. package/dist-cjs/realtime/types.d.ts +544 -0
  84. package/dist-cjs/router/auto-router.d.ts +17 -0
  85. package/dist-cjs/router/failover.d.ts +31 -0
  86. package/dist-cjs/router/index.d.ts +12 -0
  87. package/dist-cjs/router/rules-router.d.ts +7 -0
  88. package/dist-cjs/router/types.d.ts +19 -0
  89. package/dist-cjs/security/index.d.ts +32 -0
  90. package/dist-cjs/security/injection-calibration.d.ts +17 -0
  91. package/dist-cjs/security/injection-detector.d.ts +8 -0
  92. package/dist-cjs/security/input-guard.d.ts +7 -0
  93. package/dist-cjs/security/output-guard.d.ts +14 -0
  94. package/dist-cjs/security/pii-detector.d.ts +8 -0
  95. package/dist-cjs/security/policies.d.ts +4 -0
  96. package/dist-cjs/security/prompt-hardening.d.ts +6 -0
  97. package/dist-cjs/security/schema-validator.d.ts +234 -0
  98. package/dist-cjs/security/semantic-injection-classifier.d.ts +19 -0
  99. package/dist-cjs/security/upload-scanner.d.ts +29 -0
  100. package/dist-cjs/telephony/errors.d.ts +8 -0
  101. package/dist-cjs/telephony/index.d.ts +6 -0
  102. package/dist-cjs/telephony/manager.d.ts +23 -0
  103. package/dist-cjs/telephony/providers/twilio.d.ts +32 -0
  104. package/dist-cjs/telephony/providers/twilio.js +12 -0
  105. package/dist-cjs/telephony/realtime-bridge.d.ts +58 -0
  106. package/dist-cjs/telephony/twiml.d.ts +2 -0
  107. package/dist-cjs/testing/image-provider-conformance.d.ts +33 -0
  108. package/dist-cjs/testing/provider-conformance.d.ts +27 -0
  109. package/dist-cjs/types/agent.d.ts +34 -0
  110. package/dist-cjs/types/config.d.ts +248 -0
  111. package/dist-cjs/types/context-window.d.ts +55 -0
  112. package/dist-cjs/types/images.d.ts +245 -0
  113. package/dist-cjs/types/messages.d.ts +97 -0
  114. package/dist-cjs/types/optimizer.d.ts +30 -0
  115. package/dist-cjs/types/planning.d.ts +29 -0
  116. package/dist-cjs/types/providers.d.ts +39 -0
  117. package/dist-cjs/types/response.d.ts +57 -0
  118. package/dist-cjs/types/security.d.ts +87 -0
  119. package/dist-cjs/types/telephony.d.ts +275 -0
  120. package/dist-cjs/types/voice.d.ts +191 -0
  121. package/dist-cjs/utils/ids.d.ts +1 -0
  122. package/dist-cjs/utils/logger.d.ts +11 -0
  123. package/dist-cjs/utils/tokenizer.d.ts +6 -0
  124. package/dist-cjs/voice/errors.d.ts +8 -0
  125. package/dist-cjs/voice/index.d.ts +4 -0
  126. package/dist-cjs/voice/manager.d.ts +23 -0
  127. package/dist-cjs/voice/providers/openai.d.ts +29 -0
  128. package/dist-cjs/voice/session.d.ts +33 -0
  129. package/dist-cjs/workflow/chains.d.ts +53 -0
  130. package/dist-cjs/workflow/domain.d.ts +22 -0
  131. package/package.json +598 -165
package/CHANGELOG.md CHANGED
@@ -4,6 +4,28 @@ Notable changes to this project are recorded here. The format follows [Keep a Ch
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ### Added
8
+
9
+ - SMS routing on `updatePhoneNumber`. `UpdatePhoneNumberRequest` now carries `smsUrl`, `smsMethod`,
10
+ `smsFallbackUrl`, and `smsFallbackMethod`, and the Twilio provider maps them to `SmsUrl`,
11
+ `SmsMethod`, `SmsFallbackUrl`, and `SmsFallbackMethod`. Only the voice leg could be repointed
12
+ before, so an application holding SMS-enabled numbers had to drop to the provider SDK to say where
13
+ inbound messages should be delivered.
14
+ - `TelephonyPhoneNumber` reports the number's current `smsUrl`, `smsMethod`, `smsFallbackUrl`, and
15
+ `smsFallbackMethod`, so message routing can be verified the same way voice routing already is.
16
+
17
+ ## [1.2.1] - 2026-08-10
18
+
19
+ ### Fixed
20
+
21
+ - TypeScript consumers of the CommonJS build no longer resolve ESM declarations. The CommonJS build
22
+ now emits its own `.d.ts` files, and each export subpath carries per-condition types, so `require()`
23
+ resolves CommonJS declarations instead of reporting TS1479 against the ESM ones.
24
+ - Subpath types are discoverable under `moduleResolution: "node10"`, which ignores `exports` and is
25
+ still the default for NestJS projects. A `typesVersions` map now points each subpath at its
26
+ CommonJS declarations, so `nexus-ai-pro/telephony` and friends type-check without a consumer having
27
+ to migrate its `tsconfig.json` to `node16`.
28
+
7
29
  ## [1.2.0] - 2026-08-10
8
30
 
9
31
  ### Added
@@ -158,6 +158,14 @@ export class TwilioTelephonyProvider {
158
158
  body.set('StatusCallback', request.statusCallbackUrl);
159
159
  if (request.statusCallbackMethod !== undefined)
160
160
  body.set('StatusCallbackMethod', request.statusCallbackMethod);
161
+ if (request.smsUrl !== undefined)
162
+ body.set('SmsUrl', request.smsUrl);
163
+ if (request.smsMethod !== undefined)
164
+ body.set('SmsMethod', request.smsMethod);
165
+ if (request.smsFallbackUrl !== undefined)
166
+ body.set('SmsFallbackUrl', request.smsFallbackUrl);
167
+ if (request.smsFallbackMethod !== undefined)
168
+ body.set('SmsFallbackMethod', request.smsFallbackMethod);
161
169
  if (!body.size) {
162
170
  throw new TelephonyProviderError('Twilio phone number update requires at least one field to change', 'twilio');
163
171
  }
@@ -296,6 +304,10 @@ export class TwilioTelephonyProvider {
296
304
  voiceMethod: normalizeHttpMethod(stringValue(raw.voice_method)),
297
305
  statusCallbackUrl: stringValue(raw.status_callback),
298
306
  statusCallbackMethod: normalizeHttpMethod(stringValue(raw.status_callback_method)),
307
+ smsUrl: stringValue(raw.sms_url),
308
+ smsMethod: normalizeHttpMethod(stringValue(raw.sms_method)),
309
+ smsFallbackUrl: stringValue(raw.sms_fallback_url),
310
+ smsFallbackMethod: normalizeHttpMethod(stringValue(raw.sms_fallback_method)),
299
311
  capabilities: {
300
312
  voice: capabilities.voice === true,
301
313
  sms: capabilities.sms === true,
@@ -139,6 +139,11 @@ export interface TelephonyPhoneNumber {
139
139
  voiceMethod?: TelephonyHttpMethod;
140
140
  statusCallbackUrl?: string;
141
141
  statusCallbackMethod?: TelephonyHttpMethod;
142
+ /** Where the provider currently posts inbound SMS for this number. */
143
+ smsUrl?: string;
144
+ smsMethod?: TelephonyHttpMethod;
145
+ smsFallbackUrl?: string;
146
+ smsFallbackMethod?: TelephonyHttpMethod;
142
147
  capabilities?: {
143
148
  voice?: boolean;
144
149
  sms?: boolean;
@@ -160,8 +165,20 @@ export interface UpdatePhoneNumberRequest {
160
165
  friendlyName?: string;
161
166
  voiceUrl?: string;
162
167
  voiceMethod?: TelephonyHttpMethod;
168
+ /**
169
+ * Where the provider posts call status events.
170
+ *
171
+ * This covers the voice leg only. Message delivery receipts are requested per message when
172
+ * sending, rather than being configured on the number.
173
+ */
163
174
  statusCallbackUrl?: string;
164
175
  statusCallbackMethod?: TelephonyHttpMethod;
176
+ /** Where the provider posts inbound SMS sent to this number. */
177
+ smsUrl?: string;
178
+ smsMethod?: TelephonyHttpMethod;
179
+ /** Used by the provider when {@link smsUrl} errors or times out. */
180
+ smsFallbackUrl?: string;
181
+ smsFallbackMethod?: TelephonyHttpMethod;
165
182
  signal?: AbortSignal;
166
183
  }
167
184
  export interface TelephonyWebhookValidationRequest {
@@ -0,0 +1,12 @@
1
+ import type { AgentConfig, AgentResult } from '../types/agent.js';
2
+ import type { CompletionRequest } from '../types/messages.js';
3
+ import type { NexusResponse } from '../types/response.js';
4
+ export interface AgentModelClient {
5
+ complete(request: CompletionRequest): Promise<NexusResponse>;
6
+ }
7
+ export declare class AgentLoop {
8
+ private client;
9
+ constructor(client: AgentModelClient);
10
+ run(config: AgentConfig): Promise<AgentResult>;
11
+ private parseToolArgs;
12
+ }
@@ -0,0 +1,16 @@
1
+ import type { ToolDefinition } from '../types/messages.js';
2
+ import type { ToolExecutionResult } from '../types/agent.js';
3
+ export declare function tool<TArgs extends Record<string, unknown> = Record<string, unknown>>(definition: {
4
+ name: string;
5
+ description: string;
6
+ parameters: Record<string, unknown>;
7
+ execute: (args: TArgs) => Promise<unknown> | unknown;
8
+ }): ToolDefinition;
9
+ export declare class ToolExecutor {
10
+ private tools;
11
+ constructor(tools?: ToolDefinition[]);
12
+ register(toolDefinition: ToolDefinition): this;
13
+ has(name: string): boolean;
14
+ list(): ToolDefinition[];
15
+ execute(name: string, args: Record<string, unknown>): Promise<ToolExecutionResult>;
16
+ }
@@ -0,0 +1,42 @@
1
+ export interface CacheAdapter<T = unknown> {
2
+ get(key: string): Promise<T | undefined> | T | undefined;
3
+ set(key: string, value: T, ttlSeconds?: number): Promise<void> | void;
4
+ delete?(key: string): Promise<boolean> | boolean;
5
+ clear?(): Promise<void> | void;
6
+ }
7
+ export declare class MemoryCacheAdapter<T = unknown> implements CacheAdapter<T> {
8
+ private entries;
9
+ get(key: string): T | undefined;
10
+ set(key: string, value: T, ttlSeconds?: number): void;
11
+ delete(key: string): boolean;
12
+ clear(): void;
13
+ }
14
+ export interface RedisLikeClient {
15
+ get(key: string): Promise<string | null> | string | null;
16
+ set(key: string, value: string, mode?: string, ttlSeconds?: number): Promise<unknown> | unknown;
17
+ del?(key: string): Promise<number> | number;
18
+ }
19
+ export declare class RedisCacheAdapter<T = unknown> implements CacheAdapter<T> {
20
+ private client;
21
+ private prefix;
22
+ constructor(client: RedisLikeClient, prefix?: string);
23
+ get(key: string): Promise<T | undefined>;
24
+ set(key: string, value: T, ttlSeconds?: number): Promise<void>;
25
+ delete(key: string): Promise<boolean>;
26
+ }
27
+ export interface SQLiteLikeDatabase {
28
+ prepare(sql: string): {
29
+ get?: (...args: unknown[]) => unknown;
30
+ run?: (...args: unknown[]) => unknown;
31
+ };
32
+ exec?(sql: string): unknown;
33
+ }
34
+ export declare class SQLiteCacheAdapter<T = unknown> implements CacheAdapter<T> {
35
+ private db;
36
+ private table;
37
+ constructor(db: SQLiteLikeDatabase, table?: string);
38
+ get(key: string): T | undefined;
39
+ set(key: string, value: T, ttlSeconds?: number): void;
40
+ delete(key: string): boolean;
41
+ clear(): void;
42
+ }
@@ -0,0 +1,20 @@
1
+ export interface CacheEntry<T> {
2
+ value: T;
3
+ expiresAt: number;
4
+ }
5
+ export declare class MemoryCache<T> {
6
+ private maxEntries;
7
+ private entries;
8
+ constructor(maxEntries?: number);
9
+ get(key: string): T | undefined;
10
+ set(key: string, value: T, ttlSeconds?: number): void;
11
+ clear(): void;
12
+ delete(key: string): boolean;
13
+ clearExpired(): number;
14
+ stats(): {
15
+ size: number;
16
+ maxEntries: number;
17
+ expiredEntries: number;
18
+ };
19
+ }
20
+ export declare function createCacheKey(value: unknown): string;
@@ -0,0 +1,19 @@
1
+ import type { CompletionRequest } from '../types/messages.js';
2
+ import type { NexusResponse } from '../types/response.js';
3
+ import { type EmbeddingProvider } from '../hallucination/retrieval.js';
4
+ export interface SemanticCacheOptions {
5
+ enabled?: boolean;
6
+ similarityThreshold?: number;
7
+ maxEntries?: number;
8
+ ttlSeconds?: number;
9
+ embed?: EmbeddingProvider;
10
+ }
11
+ export declare class SemanticCache {
12
+ private options;
13
+ private entries;
14
+ private embed;
15
+ constructor(options?: SemanticCacheOptions);
16
+ get(request: CompletionRequest): Promise<NexusResponse | undefined>;
17
+ set(key: string, request: CompletionRequest, response: NexusResponse): Promise<void>;
18
+ clear(): void;
19
+ }
@@ -0,0 +1,20 @@
1
+ import type { ToolDefinition } from '../types/messages.js';
2
+ export type WebResolvedAddress = string | {
3
+ address: string;
4
+ family?: 4 | 6;
5
+ };
6
+ export interface WebConnectorOptions {
7
+ allowedDomains?: string[];
8
+ timeoutMs?: number;
9
+ userAgent?: string;
10
+ maxResponseBytes?: number;
11
+ maxRedirects?: number;
12
+ /** Explicitly allow loopback/private targets, for example a trusted local development service. */
13
+ allowPrivateNetworks?: boolean;
14
+ /** Cloud metadata endpoints remain denied unless this separate high-risk opt-in is enabled. */
15
+ allowCloudMetadata?: boolean;
16
+ /** Optional resolver for split-horizon DNS or deterministic tests. Every returned address is validated. */
17
+ resolveHostname?: (hostname: string) => Promise<readonly WebResolvedAddress[]>;
18
+ }
19
+ export declare function createFetchUrlTool(options?: WebConnectorOptions): ToolDefinition;
20
+ export declare function createSearchTool(search: (query: string) => Promise<unknown>, name?: string): ToolDefinition;
@@ -0,0 +1,2 @@
1
+ export { ContextWindowManager, type ContextWindowRuntime, } from './window.js';
2
+ export type { ContextSummaryConfig, ContextSummaryInput, ContextSummaryMode, ContextSummarizer, ContextWindowConfig, ContextWindowResult, ContextWindowStrategy, ContextWindowUsage, } from '../types/context-window.js';
@@ -0,0 +1,34 @@
1
+ import type { CompletionRequest } from '../types/messages.js';
2
+ import type { ContextSummarizer, ContextWindowConfig, ContextWindowResult } from '../types/context-window.js';
3
+ export interface ContextWindowRuntime {
4
+ summarizer?: ContextSummarizer;
5
+ }
6
+ export declare class ContextWindowManager {
7
+ private config;
8
+ private tokenizer;
9
+ constructor(config?: ContextWindowConfig);
10
+ optimize(request: CompletionRequest, runtime?: ContextWindowRuntime): Promise<ContextWindowResult<CompletionRequest>>;
11
+ preview(request: CompletionRequest): ContextWindowResult<CompletionRequest>;
12
+ private optimizeInternal;
13
+ private optimizeInternalSync;
14
+ private resultFromSelection;
15
+ private selectMessages;
16
+ private selectByCount;
17
+ private selectByTokens;
18
+ private createSummary;
19
+ private createLocalSummary;
20
+ private summaryInput;
21
+ private summaryMessage;
22
+ private splitMessages;
23
+ private effectiveStrategy;
24
+ private strategy;
25
+ private shouldSummarize;
26
+ private summaryEnabled;
27
+ private summaryMode;
28
+ private summaryConfig;
29
+ private identity;
30
+ private serializeMessages;
31
+ private messageText;
32
+ private partText;
33
+ }
34
+ export type { ContextSummaryConfig, ContextSummaryInput, ContextSummaryMode, ContextSummarizer, ContextWindowConfig, ContextWindowResult, ContextWindowStrategy, ContextWindowUsage, } from '../types/context-window.js';
@@ -0,0 +1,97 @@
1
+ import { NexusAI } from './nexus.js';
2
+ import type { AnthropicProviderConfig, AuditLogConfig, AzureOpenAIProviderConfig, CacheConfig, CohereProviderConfig, CostBudgetConfig, CustomProviderConfig, DeepSeekProviderConfig, GoogleProviderConfig, GroqProviderConfig, LMStudioProviderConfig, LlamaCppProviderConfig, LoggerConfig, MistralProviderConfig, NexusAIConfig, OllamaProviderConfig, OpenAIProviderConfig, OpenRouterProviderConfig, ProvidersConfig, RateLimitConfig, ResponseFormatConfig, RetryConfig, RoutingConfig, RoutingStrategy } from '../types/config.js';
3
+ import type { ContextWindowConfig } from '../types/context-window.js';
4
+ import type { ImageConfig } from '../types/images.js';
5
+ import type { SecurityConfig, SecurityLevel } from '../types/security.js';
6
+ import type { TokenOptimizerConfig } from '../types/optimizer.js';
7
+ import type { PipelineConfig } from '../pipeline/types.js';
8
+ import type { MetricsConfig } from '../ops/metrics.js';
9
+ import type { HealthConfig } from '../ops/health.js';
10
+ /**
11
+ * Fluent, typed builder for `NexusAIConfig`.
12
+ *
13
+ * The builder is intentionally thin: every method maps directly to a normal config field, so advanced users
14
+ * can still call `build()` and edit the plain object before passing it to `new NexusAI(...)`.
15
+ */
16
+ export declare class NexusConfigBuilder {
17
+ private config;
18
+ constructor(seed?: Partial<NexusAIConfig>);
19
+ /** Adds or replaces a provider config by its `ProvidersConfig` key. */
20
+ provider<Name extends keyof ProvidersConfig>(name: Name, config: NonNullable<ProvidersConfig[Name]>): this;
21
+ /** Adds OpenAI. */
22
+ openai(config: OpenAIProviderConfig | string): this;
23
+ /** Adds Anthropic. */
24
+ anthropic(config: AnthropicProviderConfig | string): this;
25
+ /** Adds Google Gemini. */
26
+ google(config: GoogleProviderConfig | string): this;
27
+ /** Adds a local Ollama server. */
28
+ ollama(config?: OllamaProviderConfig): this;
29
+ /** Adds Groq. */
30
+ groq(config: GroqProviderConfig | string): this;
31
+ /** Adds Mistral. */
32
+ mistral(config: MistralProviderConfig | string): this;
33
+ /** Adds Cohere. */
34
+ cohere(config: CohereProviderConfig | string): this;
35
+ /** Adds OpenRouter. */
36
+ openrouter(config: OpenRouterProviderConfig | string): this;
37
+ /** Adds DeepSeek. */
38
+ deepseek(config: DeepSeekProviderConfig | string): this;
39
+ /** Adds Azure OpenAI. */
40
+ azureOpenAI(config: AzureOpenAIProviderConfig): this;
41
+ /** Adds a local LM Studio OpenAI-compatible server. */
42
+ lmstudio(config?: LMStudioProviderConfig): this;
43
+ /** Adds a local llama.cpp OpenAI-compatible server. */
44
+ llamaCpp(config?: LlamaCppProviderConfig): this;
45
+ /** Adds a user-defined OpenAI- or Anthropic-compatible endpoint. */
46
+ custom(config: CustomProviderConfig): this;
47
+ /** Sets raw routing config. */
48
+ routing(config: RoutingConfig): this;
49
+ /** Uses direct routing through a single default model. */
50
+ direct(model: string): this;
51
+ /** Uses automatic routing with an optional strategy. */
52
+ auto(strategy?: RoutingStrategy): this;
53
+ /** Sets input/output security behavior. */
54
+ security(config: SecurityLevel | SecurityConfig): this;
55
+ /** Sets context-window compaction behavior. */
56
+ contextWindow(config: ContextWindowConfig): this;
57
+ /** Sets image-provider defaults and registrations. */
58
+ images(config: ImageConfig): this;
59
+ /** Sets token optimization behavior. */
60
+ tokenOptimizer(config: TokenOptimizerConfig): this;
61
+ /** Sets exact, semantic, or hybrid cache behavior. */
62
+ cache(config: CacheConfig): this;
63
+ /** Sets rate limiting behavior. */
64
+ rateLimit(config: RateLimitConfig): this;
65
+ /** Sets audit logging behavior. */
66
+ auditLog(config: AuditLogConfig): this;
67
+ /** Sets response-format defaults. */
68
+ responseFormat(config: ResponseFormatConfig): this;
69
+ /** Sets provider retry behavior. */
70
+ retry(config: RetryConfig): this;
71
+ /** Sets request cost-budget behavior. */
72
+ costBudget(config: CostBudgetConfig): this;
73
+ /** Sets pipeline hook and trace behavior. */
74
+ pipeline(config: PipelineConfig): this;
75
+ /** Sets metrics sink behavior. */
76
+ metrics(config: MetricsConfig): this;
77
+ /** Sets provider health scoring behavior. */
78
+ health(config: HealthConfig): this;
79
+ /** Sets structured logger behavior. */
80
+ logger(config: LoggerConfig): this;
81
+ /** Sets global provider timeout in milliseconds. */
82
+ timeout(ms: number): this;
83
+ /** Toggles debug logging. */
84
+ debug(enabled?: boolean): this;
85
+ /** Returns a plain `NexusAIConfig` object. */
86
+ build(): NexusAIConfig;
87
+ /** Creates a `NexusAI` instance from the current builder state. */
88
+ create(): NexusAI;
89
+ }
90
+ /**
91
+ * Starts a fluent `NexusAIConfig` builder.
92
+ */
93
+ export declare function createNexusConfig(seed?: Partial<NexusAIConfig>): NexusConfigBuilder;
94
+ /**
95
+ * Identity helper for users who prefer object literals but want type inference and validation in editors.
96
+ */
97
+ export declare function defineNexusConfig(config: NexusAIConfig): NexusAIConfig;
@@ -0,0 +1,33 @@
1
+ import { NexusAI } from './nexus.js';
2
+ import type { NexusAIConfig, ProvidersConfig } from '../types/config.js';
3
+ export type CreateNexusProvider = 'openai' | 'anthropic' | 'google' | 'ollama' | 'groq' | 'mistral' | 'cohere' | 'openrouter' | 'deepseek' | 'azureOpenAI' | 'lmstudio' | 'llamaCpp';
4
+ export interface CreateNexusOptions extends Omit<Partial<NexusAIConfig>, 'providers'> {
5
+ providers?: ProvidersConfig;
6
+ provider?: CreateNexusProvider;
7
+ apiKey?: string;
8
+ baseUrl?: string;
9
+ endpoint?: string;
10
+ deployment?: string;
11
+ apiVersion?: string;
12
+ model?: string;
13
+ }
14
+ /**
15
+ * Creates a `NexusAI` instance from either the full production config or a small beginner shorthand.
16
+ *
17
+ * Use the full `NexusAIConfig` when you need routing, retries, budgets, hooks, or multiple providers.
18
+ * Use the shorthand when you only want one provider and one model.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const ai = createNexus({
23
+ * provider: 'openai',
24
+ * apiKey: process.env.OPENAI_API_KEY!,
25
+ * model: 'gpt-5.4-mini',
26
+ * });
27
+ * ```
28
+ */
29
+ export declare function createNexus(config?: NexusAIConfig | CreateNexusOptions): NexusAI;
30
+ /**
31
+ * Converts the beginner shorthand accepted by `createNexus()` into a normal `NexusAIConfig`.
32
+ */
33
+ export declare function normalizeCreateNexusConfig(config: NexusAIConfig | CreateNexusOptions): NexusAIConfig;
@@ -0,0 +1,222 @@
1
+ import type { NexusAIConfig } from '../types/config.js';
2
+ import type { CompletionRequest } from '../types/messages.js';
3
+ import type { NexusPlan } from '../types/planning.js';
4
+ import type { NexusResponse, NexusStream } from '../types/response.js';
5
+ import type { AgentConfig, AgentResult } from '../types/agent.js';
6
+ import type { SpeechRequest, SpeechResponse, TranscriptionRequest, TranscriptionResponse, VoiceProvider, VoiceSessionConfig, VoiceTurnRequest, VoiceTurnResponse } from '../types/voice.js';
7
+ import type { ImageProvider } from '../types/images.js';
8
+ import type { CreateCallRequest, CreateCallResponse, EndCallRequest, GetCallRequest, ListPhoneNumbersRequest, TelephonyCallDetails, TelephonyMediaStreamEvent, TelephonyOutboundAudioMessage, TelephonyPhoneNumber, TelephonyProvider, TelephonyResponseRequest, TelephonyStatusCallback, TelephonyWebhookResponse, TelephonyWebhookValidationRequest, UpdatePhoneNumberRequest } from '../types/telephony.js';
9
+ import type { PipelineStep } from '../pipeline/types.js';
10
+ import type { BaseProvider } from '../providers/base.js';
11
+ import { type VoiceSession } from '../voice/index.js';
12
+ import { ImageManager } from '../images/manager.js';
13
+ import { type VerificationOptions } from '../hallucination/verification.js';
14
+ import { type SelfConsistencyOptions } from '../hallucination/consistency.js';
15
+ import { type BatchOptions, type BatchItemResult } from '../jobs/batch.js';
16
+ import { JobQueue, type QueueOptions } from '../jobs/queue.js';
17
+ import { type EvalCase, type EvalRunResult } from '../evals/runner.js';
18
+ import { type SummarizeVerifyFormatOptions, type WorkflowResult } from '../workflow/chains.js';
19
+ /**
20
+ * Main runtime facade for provider routing, security, optimization, evals, voice, jobs, and observability.
21
+ *
22
+ * Use `new NexusAI(config)` when you want full control, or `createNexus()` for the beginner shorthand.
23
+ */
24
+ export declare class NexusAI {
25
+ /** Provider-neutral image generation and editing operations. */
26
+ readonly images: ImageManager;
27
+ private config;
28
+ private providers;
29
+ private router;
30
+ private failover;
31
+ private logger;
32
+ private security;
33
+ private contextWindow;
34
+ private voiceManager;
35
+ private telephonyManager;
36
+ private optimizer;
37
+ private cache;
38
+ private auditLogger;
39
+ private rateLimiter;
40
+ private pipeline;
41
+ private metrics;
42
+ private health;
43
+ private semanticCache;
44
+ /**
45
+ * Creates a configured Nexus runtime.
46
+ *
47
+ * Provider SDKs are loaded lazily by each provider adapter, so unused providers do not add runtime work.
48
+ */
49
+ constructor(config: NexusAIConfig);
50
+ /**
51
+ * Runs a completion through the full configured pipeline and returns one normalized response.
52
+ */
53
+ complete(request: CompletionRequest): Promise<NexusResponse>;
54
+ /**
55
+ * Completes a request and verifies generated claims against provided context.
56
+ */
57
+ completeVerified(request: CompletionRequest, options: VerificationOptions): Promise<NexusResponse>;
58
+ /**
59
+ * Samples multiple completions and returns the most self-consistent answer.
60
+ */
61
+ completeConsistent(request: CompletionRequest, options?: SelfConsistencyOptions): Promise<NexusResponse>;
62
+ /**
63
+ * Previews routing, token usage, context fit, cost, and guardrail findings without calling a provider.
64
+ */
65
+ plan(request: CompletionRequest): NexusPlan;
66
+ /**
67
+ * Streams a completion through the configured pipeline using normalized stream chunks.
68
+ */
69
+ stream(request: CompletionRequest): NexusStream;
70
+ /**
71
+ * Runs an agent loop with registered tools and iteration limits.
72
+ */
73
+ agent(config: AgentConfig): Promise<AgentResult>;
74
+ /**
75
+ * Transcribes audio through a registered voice provider.
76
+ */
77
+ transcribe(request: TranscriptionRequest): Promise<TranscriptionResponse>;
78
+ /**
79
+ * Synthesizes speech through a registered voice provider.
80
+ */
81
+ speak(request: SpeechRequest): Promise<SpeechResponse>;
82
+ /**
83
+ * Runs one voice turn: optional transcription, completion, and optional speech synthesis.
84
+ */
85
+ voice(request: VoiceTurnRequest): Promise<VoiceTurnResponse>;
86
+ /**
87
+ * Alias for `voice()` for apps that model calls as turns.
88
+ */
89
+ voiceTurn(request: VoiceTurnRequest): Promise<VoiceTurnResponse>;
90
+ /**
91
+ * Creates a stateful voice session with transcript history, task prompts, and optional tools.
92
+ */
93
+ createVoiceSession(config: VoiceSessionConfig): VoiceSession;
94
+ /**
95
+ * Creates an outbound call through a registered telephony provider.
96
+ */
97
+ createCall(request: CreateCallRequest): Promise<CreateCallResponse>;
98
+ /**
99
+ * Creates a provider-specific webhook response such as TwiML.
100
+ */
101
+ createTelephonyResponse(request: TelephonyResponseRequest): Promise<TelephonyWebhookResponse>;
102
+ /**
103
+ * Validates a telephony webhook signature when the provider supports it.
104
+ */
105
+ validateTelephonyWebhook(request: TelephonyWebhookValidationRequest): Promise<boolean>;
106
+ parseTelephonyMediaEvent(providerName: string, message: string | Record<string, unknown>): TelephonyMediaStreamEvent | undefined;
107
+ formatTelephonyAudioMessage(providerName: string, streamId: string, payload: string, options?: {
108
+ event?: 'media' | 'mark' | 'clear';
109
+ markName?: string;
110
+ }): TelephonyOutboundAudioMessage;
111
+ /**
112
+ * Reads a call's current provider-side state, including the duration usage metering bills on.
113
+ */
114
+ getCall(request: GetCallRequest): Promise<TelephonyCallDetails>;
115
+ /**
116
+ * Hangs up a live call through the provider's call-control API.
117
+ */
118
+ endCall(request: EndCallRequest): Promise<TelephonyCallDetails>;
119
+ /**
120
+ * Parses a provider status webhook into a normalized record. Prefer this over media-stream
121
+ * lifecycle events when metering usage.
122
+ */
123
+ parseTelephonyStatusCallback(providerName: string, body: string | URLSearchParams | Record<string, string | number | boolean | undefined>): TelephonyStatusCallback | undefined;
124
+ /**
125
+ * Lists phone numbers owned by the provider account.
126
+ */
127
+ listPhoneNumbers(request?: ListPhoneNumbersRequest): Promise<TelephonyPhoneNumber[]>;
128
+ /**
129
+ * Points a phone number at a voice webhook and/or status callback.
130
+ */
131
+ updatePhoneNumber(request: UpdatePhoneNumberRequest): Promise<TelephonyPhoneNumber>;
132
+ /**
133
+ * Registers a custom text provider at runtime.
134
+ */
135
+ registerProvider(name: string, provider: BaseProvider): this;
136
+ /**
137
+ * Registers a custom voice provider at runtime.
138
+ */
139
+ registerVoiceProvider(name: string, provider: VoiceProvider): this;
140
+ /**
141
+ * Registers a custom image provider at runtime.
142
+ */
143
+ registerImageProvider(name: string, provider: ImageProvider): this;
144
+ /**
145
+ * Registers a custom telephony provider at runtime.
146
+ */
147
+ registerTelephonyProvider(name: string, provider: TelephonyProvider): this;
148
+ hasProvider(name: string): boolean;
149
+ hasVoiceProvider(name: string): boolean;
150
+ hasImageProvider(name: string): boolean;
151
+ hasTelephonyProvider(name: string): boolean;
152
+ /**
153
+ * Lists configured text providers.
154
+ */
155
+ listProviders(): string[];
156
+ listVoiceProviders(): string[];
157
+ listImageProviders(): string[];
158
+ listTelephonyProviders(): string[];
159
+ /**
160
+ * Adds a custom pipeline step.
161
+ */
162
+ use(step: PipelineStep): this;
163
+ /**
164
+ * Runs multiple completion requests with optional concurrency control.
165
+ */
166
+ batchComplete(requests: CompletionRequest[], options?: BatchOptions): Promise<Array<BatchItemResult<NexusResponse>>>;
167
+ /**
168
+ * Creates an in-process job queue for completion requests.
169
+ */
170
+ createQueue(options?: QueueOptions): JobQueue<CompletionRequest, NexusResponse>;
171
+ /**
172
+ * Runs eval cases against this Nexus instance.
173
+ */
174
+ runEvals(cases: EvalCase<NexusResponse>[]): Promise<EvalRunResult<NexusResponse>>;
175
+ summarizeVerifyFormat(options: SummarizeVerifyFormatOptions): Promise<WorkflowResult>;
176
+ /**
177
+ * Returns current provider health snapshots.
178
+ */
179
+ getProviderHealth(): import("../ops/health.js").ProviderHealthSnapshot[];
180
+ /**
181
+ * Calls each provider's health check and records the result.
182
+ */
183
+ checkProviders(): Promise<Array<{
184
+ providerName: string;
185
+ ok: boolean;
186
+ error?: string;
187
+ }>>;
188
+ /**
189
+ * Returns an in-memory metrics snapshot.
190
+ */
191
+ getMetricsSnapshot(): Record<string, unknown>;
192
+ /**
193
+ * Returns Prometheus-formatted metrics when metrics are enabled.
194
+ */
195
+ getPrometheusMetrics(): string;
196
+ /**
197
+ * Clears exact and semantic caches.
198
+ */
199
+ clearCache(): void;
200
+ clearExpiredCache(): number;
201
+ getCacheStats(): {
202
+ size: number;
203
+ maxEntries: number;
204
+ expiredEntries: number;
205
+ };
206
+ private isAuditLogEnabled;
207
+ private isCacheEnabled;
208
+ private isCostBudgetEnabled;
209
+ private isSecurityEnabled;
210
+ private isTokenOptimizerEnabled;
211
+ private isContextWindowEnabled;
212
+ private hasResponseFormat;
213
+ private streamWithContextWindow;
214
+ private attachContextWindowToStream;
215
+ private summarizeContext;
216
+ private registerConfiguredProviders;
217
+ private attachTrace;
218
+ private getCachedResponse;
219
+ private setCachedResponse;
220
+ private enforceCostBudget;
221
+ private estimatedOutputTokens;
222
+ }
@@ -0,0 +1,8 @@
1
+ import type { CompletionRequest } from '../types/messages.js';
2
+ import type { NexusResponse } from '../types/response.js';
3
+ import type { ResponseFormatConfig } from '../types/config.js';
4
+ export declare class ResponseFormatError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export declare function applyResponseFormat(response: NexusResponse, config?: ResponseFormatConfig): NexusResponse;
8
+ export declare function withResponseFormat(request: CompletionRequest, config?: ResponseFormatConfig): CompletionRequest;
@@ -0,0 +1,3 @@
1
+ import type { SecurityPipeline } from '../security/index.js';
2
+ import type { NexusStream } from '../types/response.js';
3
+ export declare function protectStreamOutput(stream: NexusStream, security: SecurityPipeline, requestSignal?: AbortSignal): NexusStream;
@@ -0,0 +1,4 @@
1
+ import type { NexusStream, StreamChunk } from '../types/response.js';
2
+ export declare function collectStream(stream: NexusStream): Promise<string>;
3
+ export declare function mapStream(stream: NexusStream, mapChunk: (chunk: StreamChunk) => StreamChunk | Promise<StreamChunk>): AsyncGenerator<StreamChunk>;
4
+ export declare function createTextStream(text: string): NexusStream;
@@ -0,0 +1,20 @@
1
+ import type { EmbeddingProvider } from '../hallucination/retrieval.js';
2
+ export interface OpenAIEmbeddingOptions {
3
+ apiKey: string;
4
+ model?: string;
5
+ baseUrl?: string;
6
+ }
7
+ export interface GeminiEmbeddingOptions {
8
+ apiKey: string;
9
+ model?: string;
10
+ baseUrl?: string;
11
+ }
12
+ export interface CohereEmbeddingOptions {
13
+ apiKey: string;
14
+ model?: string;
15
+ baseUrl?: string;
16
+ inputType?: 'search_document' | 'search_query' | 'classification' | 'clustering';
17
+ }
18
+ export declare function createOpenAIEmbeddingProvider(options: OpenAIEmbeddingOptions): EmbeddingProvider;
19
+ export declare function createGeminiEmbeddingProvider(options: GeminiEmbeddingOptions): EmbeddingProvider;
20
+ export declare function createCohereEmbeddingProvider(options: CohereEmbeddingOptions): EmbeddingProvider;