@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.
@@ -2,7 +2,6 @@
2
2
  * Provider-specific type definitions for NeuroLink
3
3
  */
4
4
  import type { UnknownRecord, JsonValue, StreamingCapability } from "./common.js";
5
- import type { ProviderError } from "./errors.js";
6
5
  import { AIProviderName, AnthropicModels, BedrockModels, DeepSeekModels, GoogleAIModels, LlamaCppModels, LMStudioModels, NvidiaNimModels, OpenAIModels, VertexModels } from "../constants/enums.js";
7
6
  import type { ValidationSchema } from "./aliases.js";
8
7
  import type { EnhancedGenerateResult, GenerateResult, TextGenerationOptions } from "./generate.js";
@@ -149,6 +148,7 @@ export type NeurolinkCredentials = {
149
148
  };
150
149
  ollama?: {
151
150
  baseURL?: string;
151
+ apiKey?: string;
152
152
  };
153
153
  deepseek?: {
154
154
  apiKey?: string;
@@ -919,37 +919,6 @@ export type ModelsResponse = {
919
919
  owned_by?: string;
920
920
  }>;
921
921
  };
922
- /**
923
- * Ollama tool call structure
924
- */
925
- export type OllamaToolCall = {
926
- id: string;
927
- type: "function";
928
- function: {
929
- name: string;
930
- arguments: string;
931
- };
932
- };
933
- /**
934
- * Ollama tool result structure
935
- */
936
- export type OllamaToolResult = {
937
- tool_call_id: string;
938
- content: string;
939
- };
940
- /**
941
- * Ollama message structure for conversation and tool execution
942
- */
943
- export type OllamaMessage = {
944
- role: "system" | "user" | "assistant" | "tool";
945
- content: string | Array<{
946
- type: string;
947
- text?: string;
948
- [key: string]: unknown;
949
- }>;
950
- tool_calls?: OllamaToolCall[];
951
- images?: string[];
952
- };
953
922
  /**
954
923
  * Default model aliases for easy reference
955
924
  */
@@ -1465,22 +1434,6 @@ export type ProviderHealthStatusOptions = {
1465
1434
  configurationIssues: string[];
1466
1435
  recommendations: string[];
1467
1436
  };
1468
- /**
1469
- * Structural adapter type capturing what AI SDK's `streamText` / `generateText`
1470
- * actually invoke at runtime on a model object.
1471
- *
1472
- * `OllamaLanguageModel` satisfies this type. The provider can cast
1473
- * `new OllamaLanguageModel(...)` to `LanguageModel` via this
1474
- * intermediate type, avoiding `as unknown as LanguageModel`.
1475
- */
1476
- export type OllamaAsLanguageModel = {
1477
- readonly specificationVersion: string;
1478
- readonly provider: string;
1479
- readonly modelId: string;
1480
- readonly supportedUrls: Record<string, RegExp[]>;
1481
- doGenerate(options: Record<string, unknown>): Promise<unknown>;
1482
- doStream(options: Record<string, unknown>): Promise<unknown>;
1483
- };
1484
1437
  /**
1485
1438
  * Structural type that captures what AI SDK's `streamText` / `generateText`
1486
1439
  * actually invoke at runtime on a model object.
@@ -1703,12 +1656,6 @@ export type ProviderRegistration = {
1703
1656
  export type NeuroLinkInstance = {
1704
1657
  generate: (options: Record<string, unknown>) => Promise<unknown>;
1705
1658
  };
1706
- /** ProviderError enriched with HTTP response fields from Ollama. */
1707
- export type OllamaHttpError = ProviderError & {
1708
- statusCode: number;
1709
- statusText: string;
1710
- responseBody: string;
1711
- };
1712
1659
  /** Model type detection result. */
1713
1660
  export type ModelDetectionResult = {
1714
1661
  type: StreamingCapability["modelType"];
@@ -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;