diff --git a/src/cli/loop/optionsSchema.ts b/src/cli/loop/optionsSchema.ts index 4081b3d46..06aefdf65 100644 --- a/src/cli/loop/optionsSchema.ts +++ b/src/cli/loop/optionsSchema.ts @@ -1,7 +1,5 @@ -import { - AIProviderName, - type TextGenerationOptions, -} from "../../lib/core/types.js"; +import { AIProviderName } from "../../lib/types/providers.js"; +import type { TextGenerationOptions } from "../../lib/types/generateTypes.js"; /** * Defines the schema for a session variable or a generation option. diff --git a/src/lib/core/types.ts b/src/lib/core/types.ts deleted file mode 100644 index e4526cf9e..000000000 --- a/src/lib/core/types.ts +++ /dev/null @@ -1,369 +0,0 @@ -import type { Tool, Schema } from "ai"; -import type { - ZodUnknownSchema, - ValidationSchema, -} from "../types/typeAliases.js"; -import type { GenerateResult } from "../types/generateTypes.js"; -import type { StreamOptions, StreamResult } from "../types/streamTypes.js"; -import type { JsonValue } from "../types/common.js"; -import type { - ChatMessage, - ConversationMemoryConfig, -} from "../types/conversation.js"; -import type { TokenUsage, AnalyticsData } from "../types/analytics.js"; -import type { EvaluationData } from "../index.js"; - -// Re-export EvaluationData for use in other modules -export type { EvaluationData }; -import type { MiddlewareFactoryOptions } from "../types/middlewareTypes.js"; - -export interface TextGenerationResult { - content: string; - provider?: string; - model?: string; - usage?: TokenUsage; - responseTime?: number; - toolsUsed?: string[]; - toolExecutions?: Array<{ - toolName: string; - executionTime: number; - success: boolean; - serverId?: string; - }>; - enhancedWithTools?: boolean; - availableTools?: Array<{ - name: string; - description: string; - server: string; - category?: string; - }>; - // Analytics and evaluation data - analytics?: AnalyticsData; - evaluation?: EvaluationData; -} - -/** - * Supported AI Provider Names - */ -export enum AIProviderName { - BEDROCK = "bedrock", - OPENAI = "openai", - OPENAI_COMPATIBLE = "openai-compatible", - VERTEX = "vertex", - ANTHROPIC = "anthropic", - AZURE = "azure", - GOOGLE_AI = "google-ai", - HUGGINGFACE = "huggingface", - OLLAMA = "ollama", - MISTRAL = "mistral", - LITELLM = "litellm", - SAGEMAKER = "sagemaker", - AUTO = "auto", -} - -/** - * Supported Models for Amazon Bedrock - */ -export enum BedrockModels { - CLAUDE_3_SONNET = "anthropic.claude-3-sonnet-20240229-v1:0", - CLAUDE_3_HAIKU = "anthropic.claude-3-haiku-20240307-v1:0", - CLAUDE_3_5_SONNET = "anthropic.claude-3-5-sonnet-20240620-v1:0", - CLAUDE_3_7_SONNET = "arn:aws:bedrock:us-east-2:225681119357:inference-profile/us.anthropic.claude-3-7-sonnet-20250219-v1:0", -} - -/** - * Supported Models for OpenAI - */ -export enum OpenAIModels { - GPT_4 = "gpt-4", - GPT_4_TURBO = "gpt-4-turbo", - GPT_4O = "gpt-4o", - GPT_4O_MINI = "gpt-4o-mini", - GPT_3_5_TURBO = "gpt-3.5-turbo", - O1_PREVIEW = "o1-preview", - O1_MINI = "o1-mini", -} - -/** - * Supported Models for Google Vertex AI - */ -export enum VertexModels { - // Claude 4 Series (Latest - May 2025) - CLAUDE_4_0_SONNET = "claude-sonnet-4@20250514", - CLAUDE_4_0_OPUS = "claude-opus-4@20250514", - - // Claude 3.5 Series (Still supported) - CLAUDE_3_5_SONNET = "claude-3-5-sonnet-20241022", - CLAUDE_3_5_HAIKU = "claude-3-5-haiku-20241022", - - // Claude 3 Series (Legacy support) - CLAUDE_3_SONNET = "claude-3-sonnet-20240229", - CLAUDE_3_OPUS = "claude-3-opus-20240229", - CLAUDE_3_HAIKU = "claude-3-haiku-20240307", - - // Gemini 2.5 Series (Latest - 2025) - GEMINI_2_5_PRO = "gemini-2.5-pro", - GEMINI_2_5_FLASH = "gemini-2.5-flash", - GEMINI_2_5_FLASH_LITE = "gemini-2.5-flash-lite", - - // Gemini 2.0 Series - GEMINI_2_0_FLASH_001 = "gemini-2.0-flash-001", - - // Gemini 1.5 Series (Legacy support) - GEMINI_1_5_PRO = "gemini-1.5-pro", - GEMINI_1_5_FLASH = "gemini-1.5-flash", -} - -/** - * Supported Models for Google AI Studio - */ -export enum GoogleAIModels { - // Gemini 2.5 Series (Latest - 2025) - GEMINI_2_5_PRO = "gemini-2.5-pro", - GEMINI_2_5_FLASH = "gemini-2.5-flash", - GEMINI_2_5_FLASH_LITE = "gemini-2.5-flash-lite", - - // Gemini 2.0 Series - GEMINI_2_0_FLASH_001 = "gemini-2.0-flash-001", - - // Gemini 1.5 Series (Legacy support) - GEMINI_1_5_PRO = "gemini-1.5-pro", - GEMINI_1_5_FLASH = "gemini-1.5-flash", - GEMINI_1_5_FLASH_LITE = "gemini-1.5-flash-lite", -} - -/** - * Supported Models for Anthropic (Direct API) - */ -export enum AnthropicModels { - // Claude 3.5 Series (Latest) - CLAUDE_3_5_SONNET = "claude-3-5-sonnet-20241022", - CLAUDE_3_5_HAIKU = "claude-3-5-haiku-20241022", - - // Claude 3 Series (Legacy support) - CLAUDE_3_SONNET = "claude-3-sonnet-20240229", - CLAUDE_3_OPUS = "claude-3-opus-20240229", - CLAUDE_3_HAIKU = "claude-3-haiku-20240307", -} - -/** - * API Versions for various providers - */ -export enum APIVersions { - // Azure OpenAI API versions - AZURE_LATEST = "2025-04-01-preview", - AZURE_STABLE = "2024-10-21", - AZURE_LEGACY = "2023-12-01-preview", - - // OpenAI API versions - OPENAI_CURRENT = "v1", - OPENAI_BETA = "v1-beta", - - // Google AI API versions - GOOGLE_AI_CURRENT = "v1", - GOOGLE_AI_BETA = "v1beta", - - // Anthropic API versions - ANTHROPIC_CURRENT = "2023-06-01", - - // Other provider versions can be added here -} - -/** - * Default model aliases for easy reference - */ -export const DEFAULT_MODEL_ALIASES = { - // Latest recommended models per provider - LATEST_OPENAI: OpenAIModels.GPT_4O, - FASTEST_OPENAI: OpenAIModels.GPT_4O_MINI, - LATEST_ANTHROPIC: AnthropicModels.CLAUDE_3_5_SONNET, - FASTEST_ANTHROPIC: AnthropicModels.CLAUDE_3_5_HAIKU, - LATEST_GOOGLE: GoogleAIModels.GEMINI_2_5_PRO, - FASTEST_GOOGLE: GoogleAIModels.GEMINI_2_5_FLASH, - - // Best models by use case - BEST_CODING: AnthropicModels.CLAUDE_3_5_SONNET, - BEST_ANALYSIS: GoogleAIModels.GEMINI_2_5_PRO, - BEST_CREATIVE: AnthropicModels.CLAUDE_3_5_SONNET, - BEST_VALUE: GoogleAIModels.GEMINI_2_5_FLASH, -} as const; - -/** - * @deprecated Use DEFAULT_MODEL_ALIASES instead. Will be removed in future version. - */ -export const ModelAliases = DEFAULT_MODEL_ALIASES; - -/** - * Union type of all supported model names - */ -export type SupportedModelName = - | BedrockModels - | OpenAIModels - | VertexModels - | GoogleAIModels - | AnthropicModels; - -/** - * Provider configuration specifying provider and its available models - */ -export interface ProviderConfig { - provider: AIProviderName; - models: SupportedModelName[]; -} - -/** - * Options for AI requests with unified provider configuration - */ -export interface StreamingOptions { - providers: ProviderConfig[]; - temperature?: number; - maxTokens?: number; - systemPrompt?: string; -} - -/** - * Text generation options interface - * Extended to support multimodal content with zero breaking changes - */ -export interface TextGenerationOptions { - prompt?: string; - input?: { - text: string; - // NEW: Multimodal support - zero breaking changes - images?: Array; // Simple image support - content?: Array< - | import("../types/content.js").TextContent - | import("../types/content.js").ImageContent - >; // Advanced multimodal content - }; // Alternative to prompt for SDK compatibility - provider?: AIProviderName; - model?: string; - temperature?: number; - maxTokens?: number; - systemPrompt?: string; - schema?: ZodUnknownSchema | Schema; - tools?: Record; // Enable MCP tools integration - timeout?: number | string; // Optional timeout (e.g., 30000, '30s', '2m', '1h') - disableTools?: boolean; // Disable tools (tools are enabled by default) - maxSteps?: number; // Maximum tool execution steps (default: 5) - // NEW: Analytics and Evaluation Support - enableEvaluation?: boolean; // Default: false - AI quality scoring - enableAnalytics?: boolean; // Default: false - Usage tracking - context?: Record; // Default: undefined - Custom context - - // NEW: Domain-Aware Evaluation - evaluationDomain?: string; // Domain expertise (e.g., "general AI assistant", "D2C analytics expert") - toolUsageContext?: string; // Tools/MCPs used in this interaction - conversationHistory?: Array<{ role: string; content: string }>; // Previous conversation context - - // NEW: Message Array Support for Conversation Memory - conversationMessages?: ChatMessage[]; // Previous conversation as message array - - // NEW: Conversation Memory Configuration - conversationMemoryConfig?: Partial; - originalPrompt?: string; // Original prompt for context summarization - - // NEW: Middleware related configs - middleware?: MiddlewareFactoryOptions; - - // NEW: Evaluation Context Parameters - expectedOutcome?: string; // Expected outcome for evaluation - evaluationCriteria?: string[]; // Criteria for evaluation -} - -export type { AnalyticsData } from "../types/analytics.js"; - -/** - * Enhanced result interfaces with optional analytics/evaluation - */ -export interface EnhancedGenerateResult extends GenerateResult { - analytics?: AnalyticsData; - evaluation?: EvaluationData; -} - -/** - * Phase 2: Enhanced Streaming Infrastructure - * Progress tracking and metadata for streaming operations - */ -export interface StreamingProgressData { - chunkCount: number; - totalBytes: number; - chunkSize: number; - elapsedTime: number; - estimatedRemaining?: number; - streamId?: string; - phase: "initializing" | "streaming" | "processing" | "complete" | "error"; -} - -export interface StreamingMetadata { - startTime: number; - endTime?: number; - totalDuration?: number; - averageChunkSize: number; - maxChunkSize: number; - minChunkSize: number; - throughputBytesPerSecond?: number; - streamingProvider: string; - modelUsed: string; -} - -export type ProgressCallback = (progress: StreamingProgressData) => void; - -/** - * AI Provider interface with flexible parameter support - */ -export interface AIProvider { - // NEW: Primary streaming method - stream( - optionsOrPrompt: StreamOptions | string, - analysisSchema?: ValidationSchema, - ): Promise; - - generate( - optionsOrPrompt: TextGenerationOptions | string, - analysisSchema?: ValidationSchema, - ): Promise; - - gen( - optionsOrPrompt: TextGenerationOptions | string, - analysisSchema?: ValidationSchema, - ): Promise; - - // Tool execution setup - consolidated from NeuroLink SDK - setupToolExecutor( - sdk: { - customTools: Map; - executeTool: (toolName: string, params: unknown) => Promise; - }, - functionTag: string, - ): void; -} - -/** - * Provider attempt result for iteration tracking - */ -export interface ProviderAttempt { - provider: AIProviderName; - model: SupportedModelName; - success: boolean; - error?: string; - stack?: string; -} - -/** - * Default provider configurations - */ -export const DEFAULT_PROVIDER_CONFIGS: ProviderConfig[] = [ - { - provider: AIProviderName.BEDROCK, - models: [BedrockModels.CLAUDE_3_7_SONNET, BedrockModels.CLAUDE_3_5_SONNET], - }, - { - provider: AIProviderName.VERTEX, - models: [VertexModels.CLAUDE_4_0_SONNET, VertexModels.GEMINI_2_5_FLASH], - }, - { - provider: AIProviderName.OPENAI, - models: [OpenAIModels.GPT_4O, OpenAIModels.GPT_4O_MINI], - }, -]; diff --git a/src/lib/index.ts b/src/lib/index.ts index 6faa57a9d..fe08505c6 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -234,8 +234,8 @@ export type { * ``` */ export async function generateText( - options: import("./core/types.js").TextGenerationOptions, -): Promise { + options: import("./types/index.js").TextGenerationOptions, +): Promise { // Create instance on-demand without auto-instantiation const neurolink = new NeuroLink(); return await neurolink.generateText(options); diff --git a/src/lib/models/modelRegistry.ts b/src/lib/models/modelRegistry.ts index c8ab99494..5e151b619 100644 --- a/src/lib/models/modelRegistry.ts +++ b/src/lib/models/modelRegistry.ts @@ -10,7 +10,7 @@ import { GoogleAIModels, AnthropicModels, DEFAULT_MODEL_ALIASES, -} from "../core/types.js"; +} from "../types/providers.js"; import type { JsonValue } from "../types/common.js"; /** diff --git a/src/lib/providers/azureOpenai.ts b/src/lib/providers/azureOpenai.ts index 800f6119a..a295b8bae 100644 --- a/src/lib/providers/azureOpenai.ts +++ b/src/lib/providers/azureOpenai.ts @@ -1,8 +1,8 @@ import { createAzure } from "@ai-sdk/azure"; import { streamText, type LanguageModelV1 } from "ai"; import { BaseProvider } from "../core/baseProvider.js"; -import type { AIProviderName } from "../core/types.js"; -import { APIVersions } from "../core/types.js"; +import { APIVersions } from "../types/providers.js"; +import type { AIProviderName } from "../types/providers.js"; import type { StreamOptions, StreamResult } from "../types/streamTypes.js"; import type { UnknownRecord } from "../types/common.js"; import type { NeuroLink } from "../neurolink.js"; diff --git a/src/lib/types/providers.ts b/src/lib/types/providers.ts index 48b65b6ae..c9d02342c 100644 --- a/src/lib/types/providers.ts +++ b/src/lib/types/providers.ts @@ -59,6 +59,8 @@ export enum OpenAIModels { GPT_4O = "gpt-4o", GPT_4O_MINI = "gpt-4o-mini", GPT_3_5_TURBO = "gpt-3.5-turbo", + O1_PREVIEW = "o1-preview", + O1_MINI = "o1-mini", } /** @@ -123,6 +125,29 @@ export enum AnthropicModels { CLAUDE_3_HAIKU = "claude-3-haiku-20240307", } +/** + * API Versions for various providers + */ +export enum APIVersions { + // Azure OpenAI API versions + AZURE_LATEST = "2025-04-01-preview", + AZURE_STABLE = "2024-10-21", + AZURE_LEGACY = "2023-12-01-preview", + + // OpenAI API versions + OPENAI_CURRENT = "v1", + OPENAI_BETA = "v1-beta", + + // Google AI API versions + GOOGLE_AI_CURRENT = "v1", + GOOGLE_AI_BETA = "v1beta", + + // Anthropic API versions + ANTHROPIC_CURRENT = "2023-06-01", + + // Other provider versions can be added here +} + /** * Union type of all supported model names */ @@ -533,6 +558,30 @@ export type AISDKGenerateResult = GenerateResult & { [key: string]: unknown; }; +/** + * Default model aliases for easy reference + */ +export const DEFAULT_MODEL_ALIASES = { + // Latest recommended models per provider + LATEST_OPENAI: OpenAIModels.GPT_4O, + FASTEST_OPENAI: OpenAIModels.GPT_4O_MINI, + LATEST_ANTHROPIC: AnthropicModels.CLAUDE_3_5_SONNET, + FASTEST_ANTHROPIC: AnthropicModels.CLAUDE_3_5_HAIKU, + LATEST_GOOGLE: GoogleAIModels.GEMINI_2_5_PRO, + FASTEST_GOOGLE: GoogleAIModels.GEMINI_2_5_FLASH, + + // Best models by use case + BEST_CODING: AnthropicModels.CLAUDE_3_5_SONNET, + BEST_ANALYSIS: GoogleAIModels.GEMINI_2_5_PRO, + BEST_CREATIVE: AnthropicModels.CLAUDE_3_5_SONNET, + BEST_VALUE: GoogleAIModels.GEMINI_2_5_FLASH, +} as const; + +/** + * @deprecated Use DEFAULT_MODEL_ALIASES instead. Will be removed in future version. + */ +export const ModelAliases = DEFAULT_MODEL_ALIASES; + /** * Default provider configurations */ diff --git a/src/lib/types/streamTypes.ts b/src/lib/types/streamTypes.ts index 75af82301..9173c88c5 100644 --- a/src/lib/types/streamTypes.ts +++ b/src/lib/types/streamTypes.ts @@ -2,7 +2,7 @@ import type { Tool } from "ai"; import type { ValidationSchema, StandardRecord } from "./typeAliases.js"; import type { ProviderConfig } from "./providers.js"; import type { TextContent, ImageContent } from "./content.js"; -import type { AIProviderName, AnalyticsData } from "../core/types.js"; +import type { AIProviderName, AnalyticsData } from "../types/index.js"; import type { TokenUsage } from "./analytics.js"; import type { EvaluationData } from "../index.js"; import type { diff --git a/src/lib/utils/conversationMemory.ts b/src/lib/utils/conversationMemory.ts index 712440b34..2385163fd 100644 --- a/src/lib/utils/conversationMemory.ts +++ b/src/lib/utils/conversationMemory.ts @@ -12,7 +12,7 @@ import type { RedisConversationMemoryManager } from "../core/redisConversationMe import type { TextGenerationOptions, TextGenerationResult, -} from "../core/types.js"; +} from "../types/generateTypes.js"; import { getConversationMemoryDefaults } from "../config/conversationMemory.js"; import { logger } from "./logger.js"; diff --git a/src/lib/utils/providerHealth.ts b/src/lib/utils/providerHealth.ts index c66881696..170c30541 100644 --- a/src/lib/utils/providerHealth.ts +++ b/src/lib/utils/providerHealth.ts @@ -10,7 +10,7 @@ import { GoogleAIModels, AnthropicModels, BedrockModels, -} from "../core/types.js"; +} from "../types/providers.js"; import { API_KEY_LENGTHS, PROJECT_ID_FORMAT } from "./providerConfig.js"; import { basename } from "path"; import { createProxyFetch } from "../proxy/proxyFetch.js"; diff --git a/src/lib/utils/providerSetupMessages.ts b/src/lib/utils/providerSetupMessages.ts index 37f08b40f..5820e36a2 100644 --- a/src/lib/utils/providerSetupMessages.ts +++ b/src/lib/utils/providerSetupMessages.ts @@ -8,7 +8,7 @@ import { GoogleAIModels, AnthropicModels, APIVersions, -} from "../core/types.js"; +} from "../types/providers.js"; /** * Generate enhanced error message with setup instructions diff --git a/test/factory-timeout.test.ts b/test/factory-timeout.test.ts index 671bc5fe0..15e5eea53 100644 --- a/test/factory-timeout.test.ts +++ b/test/factory-timeout.test.ts @@ -3,7 +3,7 @@ import { AIProviderFactory } from "../src/lib/core/factory.js"; import { dynamicModelProvider } from "../src/lib/core/dynamicModels.js"; import { logger } from "../src/lib/utils/logger.js"; import { ProviderFactory } from "../src/lib/factories/providerFactory.js"; -import type { AIProvider } from "../src/lib/core/types.js"; +import type { AIProvider } from "../src/lib/types/providers.js"; // Mock dependencies vi.mock("../src/lib/core/dynamicModels.js"); @@ -18,9 +18,8 @@ describe("AIProviderFactory Timeout Handling", () => { // Add default stub for ProviderFactory.createProvider so tests don't return undefined const mockPF = vi.mocked(ProviderFactory); mockPF.createProvider.mockResolvedValue({ - provider: "mock-provider", - model: "mock-model", generate: vi.fn(), + gen: vi.fn(), stream: vi.fn(), setupToolExecutor: vi.fn(), } as AIProvider); diff --git a/test/provider-edge-cases.test.ts b/test/provider-edge-cases.test.ts index cca59475e..2837fedc9 100644 --- a/test/provider-edge-cases.test.ts +++ b/test/provider-edge-cases.test.ts @@ -3,13 +3,15 @@ import { AIProviderFactory } from "../src/lib/core/factory.js"; import { ProviderFactory } from "../src/lib/factories/providerFactory.js"; import { ProviderRegistry } from "../src/lib/factories/providerRegistry.js"; import { logger } from "../src/lib/utils/logger.js"; -import type { AIProvider } from "../src/lib/core/types.js"; +import type { AIProvider } from "../src/lib/types/providers.js"; import type { StreamOptions, StreamResult, } from "../src/lib/types/streamTypes.js"; -import type { TextGenerationOptions } from "../src/lib/core/types.js"; -import type { EnhancedGenerateResult } from "../src/lib/core/types.js"; +import type { + TextGenerationOptions, + EnhancedGenerateResult, +} from "../src/lib/types/generateTypes.js"; import type { ValidationSchema } from "../src/lib/types/typeAliases.js"; // Mock dependencies @@ -34,9 +36,9 @@ describe("AIProviderFactory Edge Cases", () => { provider: "mock", model: "mock-model", usage: { - inputTokens: 20, - outputTokens: 30, - totalTokens: 50, + input: 20, + output: 30, + total: 50, }, }; } @@ -50,9 +52,9 @@ describe("AIProviderFactory Edge Cases", () => { provider: "mock", model: "mock-model", usage: { - inputTokens: 20, - outputTokens: 30, - totalTokens: 50, + input: 20, + output: 30, + total: 50, }, }; } @@ -90,9 +92,9 @@ describe("AIProviderFactory Edge Cases", () => { provider: "fallback", model: "fallback-model", usage: { - inputTokens: 10, - outputTokens: 20, - totalTokens: 30, + input: 10, + output: 20, + total: 30, }, }; } @@ -106,9 +108,9 @@ describe("AIProviderFactory Edge Cases", () => { provider: "fallback", model: "fallback-model", usage: { - inputTokens: 10, - outputTokens: 20, - totalTokens: 30, + input: 10, + output: 20, + total: 30, }, }; } diff --git a/test/provider-middleware.test.ts b/test/provider-middleware.test.ts index 00a53b7eb..cd2fe1f0e 100644 --- a/test/provider-middleware.test.ts +++ b/test/provider-middleware.test.ts @@ -1,10 +1,6 @@ import { describe, it, expect, vi, beforeEach, Mock } from "vitest"; import { BaseProvider } from "../src/lib/core/baseProvider.js"; -import { AIProviderName } from "../src/lib/core/types.js"; -import type { - EnhancedGenerateResult, - TextGenerationOptions, -} from "../src/lib/core/types.js"; +import { AIProviderName } from "../src/lib/types/providers.js"; import type { LanguageModelV1, LanguageModelV1Middleware } from "ai"; import type { MiddlewareFactoryOptions, diff --git a/test/providers/sagemaker.test.ts b/test/providers/sagemaker.test.ts index 002097f5e..d39a4325a 100644 --- a/test/providers/sagemaker.test.ts +++ b/test/providers/sagemaker.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, beforeAll, vi } from "vitest"; import { AmazonSageMakerProvider } from "../../src/lib/providers/amazonSagemaker.js"; -import { AIProviderName } from "../../src/lib/core/types.js"; +import { AIProviderName } from "../../src/lib/types/providers.js"; describe("AmazonSageMakerProvider", () => { beforeAll(() => {