@juspay/neurolink 9.68.19 → 9.68.20

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.
@@ -112,10 +112,10 @@ export class ProviderRegistry {
112
112
  return new MistralProvider(modelName, sdk, undefined, mistralCreds);
113
113
  }, MistralModels.MISTRAL_LARGE_LATEST, ["mistral"]);
114
114
  // Register Ollama provider
115
- ProviderFactory.registerProvider(AIProviderName.OLLAMA, async (modelName, _providerName, _sdk, _region, credentials) => {
115
+ ProviderFactory.registerProvider(AIProviderName.OLLAMA, async (modelName, _providerName, sdk, _region, credentials) => {
116
116
  const ollamaCreds = credentials;
117
117
  const { OllamaProvider } = await import("../providers/ollama.js");
118
- return new OllamaProvider(modelName, ollamaCreds);
118
+ return new OllamaProvider(modelName, sdk, undefined, ollamaCreds);
119
119
  }, process.env.OLLAMA_MODEL || OllamaModels.LLAMA3_2_LATEST, ["ollama", "local"]);
120
120
  // Register LiteLLM provider
121
121
  ProviderFactory.registerProvider(AIProviderName.LITELLM, async (modelName, _providerName, sdk, _region, credentials) => {
@@ -112,10 +112,10 @@ export class ProviderRegistry {
112
112
  return new MistralProvider(modelName, sdk, undefined, mistralCreds);
113
113
  }, MistralModels.MISTRAL_LARGE_LATEST, ["mistral"]);
114
114
  // Register Ollama provider
115
- ProviderFactory.registerProvider(AIProviderName.OLLAMA, async (modelName, _providerName, _sdk, _region, credentials) => {
115
+ ProviderFactory.registerProvider(AIProviderName.OLLAMA, async (modelName, _providerName, sdk, _region, credentials) => {
116
116
  const ollamaCreds = credentials;
117
117
  const { OllamaProvider } = await import("../providers/ollama.js");
118
- return new OllamaProvider(modelName, ollamaCreds);
118
+ return new OllamaProvider(modelName, sdk, undefined, ollamaCreds);
119
119
  }, process.env.OLLAMA_MODEL || OllamaModels.LLAMA3_2_LATEST, ["ollama", "local"]);
120
120
  // Register LiteLLM provider
121
121
  ProviderFactory.registerProvider(AIProviderName.LITELLM, async (modelName, _providerName, sdk, _region, credentials) => {
@@ -1,149 +1,71 @@
1
1
  import type { AIProviderName } from "../constants/enums.js";
2
- import { BaseProvider } from "../core/baseProvider.js";
3
- import type { StreamOptions, StreamResult, ZodUnknownSchema } from "../types/index.js";
4
- import type { LanguageModel, Schema } from "../types/index.js";
2
+ import type { NeurolinkCredentials, StreamOptions, TextGenerationOptions } from "../types/index.js";
3
+ import { OpenAIChatCompletionsProvider } from "./openaiChatCompletionsBase.js";
5
4
  /**
6
- * Ollama Provider v2 - BaseProvider Implementation
5
+ * Ollama Provider direct HTTP, no AI SDK.
7
6
  *
8
- * PHASE 3.7: BaseProvider wrap around existing custom Ollama implementation
7
+ * Wraps a local (or remote/Cloud) Ollama server via its OpenAI-compatible
8
+ * `/v1` API. All request / stream / multi-step tool-loop orchestration lives
9
+ * in `OpenAIChatCompletionsProvider`; this class declares configuration plus
10
+ * the Ollama-specific behaviour:
9
11
  *
10
- * Features:
11
- * - Extends BaseProvider for shared functionality
12
- * - Preserves custom OllamaLanguageModel implementation
13
- * - Local model management and health checking
14
- * - Enhanced error handling with Ollama-specific guidance
12
+ * 1. `/v1` base-URL normalization (accepts a bare `OLLAMA_BASE_URL` host).
13
+ * 2. No-auth-by-default with an optional `OLLAMA_API_KEY` for Ollama Cloud.
14
+ * 3. Configurable per-model tool gating via `OLLAMA_TOOL_CAPABLE_MODELS` /
15
+ * `modelConfig` (`supportsTools`).
16
+ * 4. Elevated request timeout for slow large local models (5-minute base
17
+ * default, overridable via `OLLAMA_TIMEOUT`).
18
+ * 5. Native `/v1/embeddings` (`embed` / `embedMany`).
19
+ * 6. Rich, actionable error mapping (`ollama serve` / `ollama pull` hints).
20
+ *
21
+ * Model discovery uses the base's `/v1/models` probe (Ollama supports it).
22
+ *
23
+ * @see https://docs.ollama.com/api/openai-compatibility
15
24
  */
16
- export declare class OllamaProvider extends BaseProvider {
17
- private ollamaModel;
18
- private baseUrl;
19
- private timeout;
20
- constructor(modelName?: string, credentials?: {
21
- baseURL?: string;
22
- });
25
+ export declare class OllamaProvider extends OpenAIChatCompletionsProvider {
26
+ constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["ollama"]);
23
27
  protected getProviderName(): AIProviderName;
24
28
  protected getDefaultModel(): string;
25
- /**
26
- * Returns the Vercel AI SDK model instance for Ollama.
27
- *
28
- * OllamaLanguageModel implements OllamaAsLanguageModel which is structurally
29
- * compatible with LanguageModelV2 (specificationVersion "v2", modelId, provider,
30
- * supportedUrls, doGenerate, doStream).
31
- */
32
- protected getAISDKModel(): LanguageModel;
33
- /**
34
- * Ollama Tool Calling Support (Enhanced 2025)
35
- *
36
- * Uses configurable model list from ModelConfiguration instead of hardcoded values.
37
- * Tool-capable models can be configured via OLLAMA_TOOL_CAPABLE_MODELS environment variable.
38
- *
39
- * **Configuration Options:**
40
- * - Environment variable: OLLAMA_TOOL_CAPABLE_MODELS (comma-separated list)
41
- * - Configuration file: providers.ollama.modelBehavior.toolCapableModels
42
- * - Fallback: Default list of known tool-capable models
43
- *
44
- * **Implementation Features:**
45
- * - Direct Ollama API integration (/v1/chat/completions)
46
- * - Automatic tool schema conversion to Ollama format
47
- * - Streaming tool calls with incremental response parsing
48
- * - Model compatibility validation and fallback handling
49
- *
50
- * @returns true for supported models, false for unsupported models
51
- */
52
- supportsTools(): boolean;
53
- /**
54
- * Extract images from multimodal messages for Ollama API
55
- * Returns array of base64-encoded images
56
- */
57
- private extractImagesFromMessages;
58
- /**
59
- * Convert multimodal messages to Ollama chat format
60
- * Extracts text content and handles images separately
61
- */
62
- private convertToOllamaMessages;
63
- protected executeStream(options: StreamOptions, analysisSchema?: ZodUnknownSchema | Schema<unknown>): Promise<StreamResult>;
64
- /**
65
- * Execute streaming with Ollama's function calling support
66
- * Uses conversation loop to handle multi-step tool execution
67
- */
68
- private executeStreamWithTools;
69
- /**
70
- * Execute streaming without tools using the generate API
71
- * Fallback for non-tool scenarios or when chat API is unavailable
72
- */
73
- private executeStreamWithoutTools;
74
- /**
75
- * Convert AI SDK tools format to Ollama's function calling format
76
- */
77
- private convertToolsToOllamaFormat;
78
- /**
79
- * Parse tool calls from Ollama API response
80
- */
81
- private parseToolCalls;
82
- /**
83
- * Process Ollama streaming response and stream content to controller
84
- * Returns aggregated content, tool calls, and finish reason
85
- */
86
- private processOllamaResponse;
87
- /**
88
- * Process individual stream data chunk from Ollama
89
- */
90
- private processOllamaStreamData;
91
- /**
92
- * Create stream generator for Ollama chat API with tool call support
93
- */
94
- private createOllamaChatStream;
95
- /**
96
- * Format tool calls for display when tools aren't executed directly
97
- */
98
- private formatToolCallForDisplay;
99
- /**
100
- * Convert AI SDK tools to ToolDefinition format
101
- */
102
- private convertAISDKToolsToToolDefinitions;
103
- /**
104
- * Execute a single tool and return the result
105
- */
106
- private executeSingleTool;
107
- /**
108
- * Execute tools and format results for Ollama API
109
- * Similar to Bedrock's executeStreamTools but for Ollama format
110
- */
111
- private executeOllamaTools;
112
- /**
113
- * Convert ReadableStream to AsyncIterable for compatibility with StreamResult interface
114
- */
115
- private convertToAsyncIterable;
116
- /**
117
- * Create stream generator for Ollama generate API (non-tool mode)
118
- */
119
- private createOllamaStream;
120
- private createOpenAIStream;
29
+ protected getFallbackModelName(): string;
121
30
  protected formatProviderError(error: unknown): Error;
122
31
  /**
123
- * Check if Ollama service is healthy and accessible
32
+ * Ollama proxies many local models with varying tool support. When
33
+ * `OLLAMA_TOOL_CAPABLE_MODELS` (or `modelConfig`'s
34
+ * `modelBehavior.toolCapableModels`) is configured, gate tools on a
35
+ * substring match against the current model; with no list configured,
36
+ * assume tools are supported (don't disable on absent evidence).
124
37
  */
125
- private checkOllamaHealth;
38
+ supportsTools(): boolean;
126
39
  /**
127
- * Get available models from Ollama
128
- */
129
- getAvailableModels(): Promise<string[]>;
40
+ * Local models are slow; the base already defaults Ollama to a 5-minute
41
+ * timeout and honors a per-call `options.timeout`. Preserve the legacy
42
+ * `OLLAMA_TIMEOUT` env override for callers who relied on it, applied only
43
+ * when no explicit per-call timeout is set. Parsed with the shared
44
+ * `parseTimeout` so both millisecond numbers ("240000") and duration strings
45
+ * ("4m", "30s") work; a malformed value is ignored in favour of the default.
46
+ */
47
+ getTimeout(options: TextGenerationOptions | StreamOptions): number;
48
+ /**
49
+ * Health check: probe `/v1/models` and require at least one installed model.
50
+ * A reachable server with zero models would let `resolveModelName()` fall
51
+ * back to a model that the first real request can't serve, so report unusable.
52
+ */
53
+ validateConfiguration(): Promise<boolean>;
54
+ getConfiguration(): {
55
+ provider: AIProviderName;
56
+ model: string;
57
+ defaultModel: string;
58
+ baseURL: string;
59
+ };
130
60
  /**
131
- * Check if a specific model is available
61
+ * Generate an embedding for a single text input via native /v1/embeddings.
62
+ * Uses `OLLAMA_EMBEDDING_MODEL` (default `nomic-embed-text`); the embedding
63
+ * model must be pulled locally (`ollama pull nomic-embed-text`).
132
64
  */
133
- isModelAvailable(modelName: string): Promise<boolean>;
65
+ embed(text: string, modelName?: string): Promise<number[]>;
134
66
  /**
135
- * Get recommendations for tool-calling capable Ollama models
136
- * Provides guidance for users who want to use function calling locally
67
+ * Generate embeddings for multiple text inputs via native /v1/embeddings.
137
68
  */
138
- static getToolCallingRecommendations(): {
139
- recommended: string[];
140
- performance: Record<string, {
141
- speed: number;
142
- quality: number;
143
- size: string;
144
- }>;
145
- notes: Record<string, string>;
146
- installation: Record<string, string>;
147
- };
69
+ embedMany(texts: string[], modelName?: string): Promise<number[][]>;
70
+ private callEmbeddings;
148
71
  }
149
- export default OllamaProvider;