@petrgrishin/ai-sdk-ollama 3.0.2

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.
@@ -0,0 +1,790 @@
1
+ import { RerankingModelV3, RerankingModelV3CallOptions, JSONSchema7, ProviderV3, LanguageModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
2
+ import { Ollama, Config, ChatRequest, Options as Options$1, EmbedRequest } from 'ollama';
3
+ import { FetchFunction } from '@ai-sdk/provider-utils';
4
+ import * as ai from 'ai';
5
+ import { generateText as generateText$1, streamText as streamText$1 } from 'ai';
6
+ export { Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, ChunkDetector, LanguageModelMiddleware, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, defaultSettingsMiddleware, extractReasoningMiddleware, hasToolCall, parsePartialJson, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, wrapLanguageModel } from 'ai';
7
+
8
+ /**
9
+ * Configuration for the Ollama reranking model
10
+ */
11
+ interface OllamaRerankingConfig {
12
+ provider: string;
13
+ baseURL: string;
14
+ headers: () => Record<string, string | undefined>;
15
+ fetch?: FetchFunction;
16
+ }
17
+ /**
18
+ * Settings for configuring Ollama reranking models
19
+ */
20
+ interface OllamaRerankingSettings {
21
+ /**
22
+ * Custom instruction for the reranker model.
23
+ * Defaults to the model's built-in instruction (usually "Please judge relevance").
24
+ */
25
+ instruction?: string;
26
+ }
27
+ /**
28
+ * Ollama provider options for reranking calls
29
+ */
30
+ interface OllamaRerankingProviderOptions {
31
+ /**
32
+ * Custom instruction for this specific reranking call.
33
+ * Overrides the instruction set in model settings.
34
+ */
35
+ instruction?: string;
36
+ }
37
+ /**
38
+ * Native Ollama Reranking Model
39
+ *
40
+ * **WAITING FOR OFFICIAL SUPPORT**
41
+ *
42
+ * This implementation uses Ollama's /api/rerank endpoint from PR #11389.
43
+ * As of December 2024, this PR has NOT been merged into Ollama.
44
+ *
45
+ * **For a working solution, use `OllamaEmbeddingRerankingModel` instead:**
46
+ * ```ts
47
+ * import { ollama } from 'ai-sdk-ollama';
48
+ * import { rerank } from 'ai';
49
+ *
50
+ * const result = await rerank({
51
+ * model: ollama.embeddingReranking('bge-m3'),
52
+ * query: 'What is machine learning?',
53
+ * documents: [...],
54
+ * });
55
+ * ```
56
+ *
57
+ * This native implementation will work once Ollama adds reranking support:
58
+ * @see https://github.com/ollama/ollama/pull/11389
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * // NOT YET WORKING - requires Ollama reranking API
63
+ * import { ollama } from 'ai-sdk-ollama';
64
+ * import { rerank } from 'ai';
65
+ *
66
+ * const { rerankedDocuments } = await rerank({
67
+ * model: ollama.rerankingModel('bge-reranker-v2-m3'),
68
+ * query: 'What is machine learning?',
69
+ * documents: [
70
+ * 'Machine learning is a subset of AI...',
71
+ * 'The weather today is sunny...',
72
+ * 'Deep learning uses neural networks...',
73
+ * ],
74
+ * topN: 2,
75
+ * });
76
+ * ```
77
+ */
78
+ declare class OllamaRerankingModel implements RerankingModelV3 {
79
+ readonly specificationVersion: "v3";
80
+ readonly modelId: string;
81
+ private readonly config;
82
+ private readonly settings;
83
+ constructor(modelId: string, settings: OllamaRerankingSettings, config: OllamaRerankingConfig);
84
+ get provider(): string;
85
+ doRerank({ documents, headers, query, topN, abortSignal, providerOptions, }: RerankingModelV3CallOptions): Promise<Awaited<ReturnType<RerankingModelV3['doRerank']>>>;
86
+ }
87
+
88
+ /**
89
+ * Configuration for the Ollama embedding-based reranking model
90
+ */
91
+ interface OllamaEmbeddingRerankingConfig {
92
+ client: Ollama;
93
+ provider: string;
94
+ }
95
+ /**
96
+ * Settings for configuring Ollama embedding-based reranking
97
+ */
98
+ interface OllamaEmbeddingRerankingSettings {
99
+ /**
100
+ * Embedding model to use for computing document similarity.
101
+ * If not specified, uses the modelId passed to the constructor.
102
+ * Recommended models: 'bge-m3', 'nomic-embed-text', 'mxbai-embed-large'
103
+ */
104
+ embeddingModel?: string;
105
+ /**
106
+ * Maximum number of texts to embed per request. Smaller batches reduce
107
+ * memory/latency spikes for large document sets while still avoiding one
108
+ * request per document. Defaults to 16.
109
+ */
110
+ maxBatchSize?: number;
111
+ }
112
+ /**
113
+ * Embedding-Based Reranking Model (Workaround)
114
+ *
115
+ * Since Ollama doesn't have native reranking support yet (PR #11389 not merged),
116
+ * this implementation uses embedding similarity as a workaround:
117
+ *
118
+ * 1. Embed the query using an embedding model
119
+ * 2. Embed all documents using the same model
120
+ * 3. Calculate cosine similarity between query and each document
121
+ * 4. Sort documents by similarity score (descending)
122
+ *
123
+ * This approach works with any Ollama embedding model and provides
124
+ * reasonable reranking results for most use cases.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * import { ollama } from 'ai-sdk-ollama';
129
+ * import { rerank } from 'ai';
130
+ *
131
+ * const result = await rerank({
132
+ * model: ollama.embeddingReranking('bge-m3'),
133
+ * query: 'What is machine learning?',
134
+ * documents: [
135
+ * 'Machine learning is a subset of AI...',
136
+ * 'The weather today is sunny...',
137
+ * 'Deep learning uses neural networks...',
138
+ * ],
139
+ * topN: 2,
140
+ * });
141
+ *
142
+ * console.log(result.rerankedDocuments);
143
+ * // Documents sorted by relevance to the query
144
+ * ```
145
+ */
146
+ declare class OllamaEmbeddingRerankingModel implements RerankingModelV3 {
147
+ readonly specificationVersion: "v3";
148
+ readonly modelId: string;
149
+ private readonly config;
150
+ private readonly settings;
151
+ constructor(modelId: string, settings: OllamaEmbeddingRerankingSettings, config: OllamaEmbeddingRerankingConfig);
152
+ get provider(): string;
153
+ /**
154
+ * Get the effective embedding model to use
155
+ */
156
+ private get embeddingModelId();
157
+ /**
158
+ * Normalized batch size for embedding requests. Ensures we never request
159
+ * non-positive batch sizes.
160
+ */
161
+ private get embeddingBatchSize();
162
+ /**
163
+ * Embed a batch of texts while keeping their order aligned with the
164
+ * embeddings that are returned.
165
+ */
166
+ private embedBatch;
167
+ doRerank({ documents, query, topN, }: RerankingModelV3CallOptions): Promise<Awaited<ReturnType<RerankingModelV3['doRerank']>>>;
168
+ }
169
+
170
+ type OllamaWithWebSearch = Ollama;
171
+ /**
172
+ * Configuration options for the web search tool
173
+ */
174
+ interface WebSearchToolOptions {
175
+ /**
176
+ * Timeout for search requests in milliseconds
177
+ * @default 30000
178
+ */
179
+ timeout?: number;
180
+ /**
181
+ * Ollama client instance to use for web search
182
+ * If not provided, will need to be injected at runtime
183
+ */
184
+ client?: OllamaWithWebSearch;
185
+ }
186
+ /**
187
+ * Output schema for web search results
188
+ */
189
+ type WebSearchOutput = {
190
+ results: Array<{
191
+ title: string;
192
+ url: string;
193
+ snippet: string;
194
+ publishedDate?: string;
195
+ }>;
196
+ searchQuery: string;
197
+ totalResults: number;
198
+ };
199
+ declare function webSearch(options?: WebSearchToolOptions): ai.Tool<{
200
+ query: string;
201
+ maxResults?: number | undefined;
202
+ }, WebSearchOutput>;
203
+
204
+ type OllamaWithWebFetch = Ollama;
205
+ /**
206
+ * Configuration options for the web fetch tool
207
+ */
208
+ interface WebFetchToolOptions {
209
+ /**
210
+ * Timeout for fetch requests in milliseconds
211
+ * @default 30000
212
+ */
213
+ timeout?: number;
214
+ /**
215
+ * Maximum content length to return in characters
216
+ * @default 10000
217
+ */
218
+ maxContentLength?: number;
219
+ /**
220
+ * Ollama client instance to use for web fetch
221
+ * If not provided, will need to be injected at runtime
222
+ */
223
+ client?: OllamaWithWebFetch;
224
+ }
225
+ /**
226
+ * Output schema for web fetch results
227
+ */
228
+ type WebFetchOutput = {
229
+ content: string;
230
+ title?: string;
231
+ url: string;
232
+ contentLength: number;
233
+ error?: string;
234
+ };
235
+ /**
236
+ * Creates a web fetch tool that allows AI models to retrieve content from specific URLs.
237
+ *
238
+ * This tool uses Ollama's web fetch capabilities to retrieve and parse web page content,
239
+ * making it accessible to AI models for analysis, summarization, or answering questions
240
+ * about specific web pages.
241
+ *
242
+ * @param options - Configuration options for the web fetch tool
243
+ * @returns A tool that can be used in AI SDK generateText/streamText calls
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * import { generateText } from 'ai';
248
+ * import { ollama } from 'ai-sdk-ollama';
249
+ *
250
+ * const result = await generateText({
251
+ * model: ollama('llama3.2'),
252
+ * prompt: 'Summarize the main points from this article: https://example.com/article',
253
+ * tools: {
254
+ * webFetch: ollama.tools.webFetch()
255
+ * }
256
+ * });
257
+ * ```
258
+ */
259
+ declare function webFetch(options?: WebFetchToolOptions): ai.Tool<{
260
+ url: string;
261
+ }, WebFetchOutput>;
262
+
263
+ /**
264
+ * Ollama-specific tools that leverage the provider's web search capabilities.
265
+ * Follows the same pattern as Google and OpenAI providers.
266
+ */
267
+ declare const ollamaTools: {
268
+ /**
269
+ * Creates a web search tool that allows models to search the internet for current information.
270
+ *
271
+ * @param options - Configuration options for the web search tool
272
+ * @returns A tool that can search the web and return relevant results
273
+ *
274
+ * @example
275
+ * ```typescript
276
+ * import { ollama } from 'ai-sdk-ollama';
277
+ * import { generateText } from 'ai';
278
+ *
279
+ * const result = await generateText({
280
+ * model: ollama('llama3.2'),
281
+ * prompt: 'What are the latest AI developments?',
282
+ * tools: {
283
+ * webSearch: ollama.tools.webSearch({ maxResults: 5 })
284
+ * }
285
+ * });
286
+ * ```
287
+ */
288
+ readonly webSearch: typeof webSearch;
289
+ /**
290
+ * Creates a web fetch tool that allows models to retrieve content from specific URLs.
291
+ *
292
+ * @param options - Configuration options for the web fetch tool
293
+ * @returns A tool that can fetch web page content
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * import { ollama } from 'ai-sdk-ollama';
298
+ * import { generateText } from 'ai';
299
+ *
300
+ * const result = await generateText({
301
+ * model: ollama('llama3.2'),
302
+ * prompt: 'Summarize the content from https://example.com',
303
+ * tools: {
304
+ * webFetch: ollama.tools.webFetch()
305
+ * }
306
+ * });
307
+ * ```
308
+ */
309
+ readonly webFetch: typeof webFetch;
310
+ };
311
+
312
+ /**
313
+ * Object Generation Reliability Utilities for Ollama
314
+ *
315
+ * This module provides utilities to make Ollama object generation more reliable
316
+ * and deterministic. It addresses common issues like:
317
+ * - Schema validation failures
318
+ * - Inconsistent results across multiple attempts
319
+ * - Timeout and fetch errors
320
+ * - Malformed JSON responses
321
+ * - Type mismatches (strings vs numbers)
322
+ */
323
+
324
+ /**
325
+ * A function that attempts to repair the raw output of the model
326
+ * to enable JSON parsing and validation.
327
+ *
328
+ * Similar to AI SDK's RepairTextFunction but tailored for Ollama's output patterns.
329
+ */
330
+ type RepairTextFunction = (options: {
331
+ text: string;
332
+ error: Error;
333
+ schema?: JSONSchema7 | unknown;
334
+ }) => Promise<string | null>;
335
+ interface ObjectGenerationOptions {
336
+ /**
337
+ * Maximum number of retry attempts for object generation
338
+ */
339
+ maxRetries?: number;
340
+ /**
341
+ * Whether to attempt schema recovery when validation fails
342
+ */
343
+ attemptRecovery?: boolean;
344
+ /**
345
+ * Whether to use fallback values for failed generations
346
+ */
347
+ useFallbacks?: boolean;
348
+ /**
349
+ * Custom fallback values for specific fields
350
+ */
351
+ fallbackValues?: Record<string, unknown>;
352
+ /**
353
+ * Timeout for object generation in milliseconds
354
+ */
355
+ generationTimeout?: number;
356
+ /**
357
+ * Whether to validate and fix type mismatches
358
+ */
359
+ fixTypeMismatches?: boolean;
360
+ /**
361
+ * Custom repair function for malformed JSON or validation errors
362
+ * If provided, this will be used instead of the default jsonrepair
363
+ */
364
+ repairText?: RepairTextFunction;
365
+ /**
366
+ * Whether to enable automatic JSON repair for malformed LLM outputs
367
+ * Default: true (enabled by default for better reliability)
368
+ * Handles 14+ types of JSON issues including Python constants, JSONP, comments,
369
+ * escaped quotes, URLs in strings, trailing commas, unquoted keys, etc.
370
+ * Set to false to disable all automatic repair
371
+ */
372
+ enableTextRepair?: boolean;
373
+ }
374
+
375
+ interface Options extends Options$1 {
376
+ /**
377
+ * Minimum probability threshold for token selection
378
+ * This parameter is supported by Ollama API but missing from ollama-js TypeScript definitions
379
+ */
380
+ min_p?: number;
381
+ }
382
+
383
+ /**
384
+ * Settings for configuring the Ollama provider.
385
+ * Extends from Ollama's Config type for consistency with the underlying client.
386
+ */
387
+ interface OllamaProviderSettings extends Pick<Config, 'headers' | 'fetch'> {
388
+ /**
389
+ * Base URL for the Ollama API (defaults to http://127.0.0.1:11434)
390
+ * Maps to Config.host in the Ollama client
391
+ */
392
+ baseURL?: string;
393
+ /**
394
+ * Ollama API key for authentication with cloud services.
395
+ * The API key will be set as Authorization: Bearer {apiKey} header.
396
+ */
397
+ apiKey?: string;
398
+ /**
399
+ * Existing Ollama client instance to use instead of creating a new one.
400
+ * When provided, baseURL, headers, and fetch are ignored.
401
+ */
402
+ client?: Ollama;
403
+ }
404
+ interface OllamaProvider extends ProviderV3 {
405
+ /**
406
+ * Create a language model instance
407
+ */
408
+ (modelId: string, settings?: OllamaChatSettings): LanguageModelV3;
409
+ /**
410
+ * Create a language model instance with the `chat` method
411
+ */
412
+ chat(modelId: string, settings?: OllamaChatSettings): LanguageModelV3;
413
+ /**
414
+ * Create a language model instance with the `languageModel` method
415
+ */
416
+ languageModel(modelId: string, settings?: OllamaChatSettings): LanguageModelV3;
417
+ /**
418
+ * Create an embedding model instance
419
+ */
420
+ embedding(modelId: string, settings?: OllamaEmbeddingSettings): EmbeddingModelV3;
421
+ /**
422
+ * Create an embedding model instance with the `textEmbedding` method
423
+ */
424
+ textEmbedding(modelId: string, settings?: OllamaEmbeddingSettings): EmbeddingModelV3;
425
+ /**
426
+ * Create an embedding model instance with the `textEmbeddingModel` method
427
+ */
428
+ textEmbeddingModel(modelId: string, settings?: OllamaEmbeddingSettings): EmbeddingModelV3;
429
+ /**
430
+ * Create a reranking model instance
431
+ */
432
+ reranking(modelId: string, settings?: OllamaRerankingSettings): RerankingModelV3;
433
+ /**
434
+ * Create a reranking model instance with the `rerankingModel` method
435
+ *
436
+ * NOTE: This uses Ollama's native /api/rerank endpoint which is NOT YET AVAILABLE.
437
+ * Use `embeddingReranking()` for a working solution.
438
+ * @see https://github.com/ollama/ollama/pull/11389
439
+ */
440
+ rerankingModel(modelId: string, settings?: OllamaRerankingSettings): RerankingModelV3;
441
+ /**
442
+ * Create an embedding-based reranking model (RECOMMENDED - working now)
443
+ *
444
+ * This is a workaround that uses embedding similarity for reranking
445
+ * since Ollama doesn't have native reranking support yet.
446
+ *
447
+ * @param modelId - The embedding model to use (e.g., 'bge-m3', 'nomic-embed-text')
448
+ * @param settings - Optional settings for the reranking model
449
+ *
450
+ * @example
451
+ * ```ts
452
+ * const result = await rerank({
453
+ * model: ollama.embeddingReranking('bge-m3'),
454
+ * query: 'What is machine learning?',
455
+ * documents: [...],
456
+ * topN: 3,
457
+ * });
458
+ * ```
459
+ */
460
+ embeddingReranking(modelId: string, settings?: OllamaEmbeddingRerankingSettings): RerankingModelV3;
461
+ /**
462
+ * Ollama-specific tools that leverage web search capabilities
463
+ */
464
+ tools: {
465
+ webSearch: (options?: WebSearchToolOptions) => ReturnType<typeof ollamaTools.webSearch>;
466
+ webFetch: (options?: WebFetchToolOptions) => ReturnType<typeof ollamaTools.webFetch>;
467
+ };
468
+ }
469
+ interface OllamaChatSettings extends Pick<ChatRequest, 'keep_alive' | 'format' | 'tools' | 'think'> {
470
+ /**
471
+ * Additional model parameters - uses extended Options type that includes min_p
472
+ * This automatically includes ALL Ollama parameters including new ones like 'dimensions'
473
+ */
474
+ options?: Partial<Options>;
475
+ /**
476
+ * Enable structured output mode
477
+ */
478
+ structuredOutputs?: boolean;
479
+ /**
480
+ * Enable reliable tool calling with retry and completion mechanisms.
481
+ * Defaults to true whenever function tools are provided; set to false to opt out.
482
+ */
483
+ reliableToolCalling?: boolean;
484
+ /**
485
+ * Tool calling reliability options. These override the sensible defaults used by the
486
+ * built-in reliability layer (maxRetries=2, forceCompletion=true,
487
+ * normalizeParameters=true, validateResults=true).
488
+ */
489
+ toolCallingOptions?: {
490
+ /**
491
+ * Maximum number of retry attempts for tool calls
492
+ */
493
+ maxRetries?: number;
494
+ /**
495
+ * Whether to force completion when tool calls succeed but no final text is generated
496
+ */
497
+ forceCompletion?: boolean;
498
+ /**
499
+ * Whether to normalize parameter names to handle inconsistencies
500
+ */
501
+ normalizeParameters?: boolean;
502
+ /**
503
+ * Whether to validate tool results and attempt recovery
504
+ */
505
+ validateResults?: boolean;
506
+ /**
507
+ * Custom parameter normalization mappings
508
+ */
509
+ parameterMappings?: Record<string, string[]>;
510
+ /**
511
+ * Timeout for tool execution in milliseconds
512
+ */
513
+ toolTimeout?: number;
514
+ };
515
+ /**
516
+ * Enable reliable object generation with retry and repair mechanisms.
517
+ * Defaults to true whenever JSON schemas are used; set to false to opt out.
518
+ */
519
+ reliableObjectGeneration?: boolean;
520
+ /**
521
+ * Object generation reliability options. These override the sensible defaults used by the
522
+ * built-in reliability layer (maxRetries=3, attemptRecovery=true, useFallbacks=true,
523
+ * fixTypeMismatches=true, enableTextRepair=true).
524
+ */
525
+ objectGenerationOptions?: ObjectGenerationOptions;
526
+ }
527
+ /**
528
+ * Settings for configuring Ollama embedding models.
529
+ * Uses Pick from EmbedRequest for type consistency with the Ollama API.
530
+ */
531
+ interface OllamaEmbeddingSettings extends Pick<EmbedRequest, 'dimensions'> {
532
+ /**
533
+ * Additional embedding parameters (temperature, num_ctx, etc.)
534
+ */
535
+ options?: Partial<Options>;
536
+ }
537
+ /**
538
+ * Options for configuring Ollama provider calls
539
+ */
540
+ interface OllamaProviderOptions {
541
+ /**
542
+ * Additional headers to include in requests
543
+ */
544
+ headers?: Record<string, string>;
545
+ }
546
+ /**
547
+ * Options for configuring Ollama chat model calls
548
+ */
549
+ interface OllamaChatProviderOptions extends OllamaProviderOptions {
550
+ /**
551
+ * Enable structured output mode for object generation
552
+ */
553
+ structuredOutputs?: boolean;
554
+ }
555
+ /**
556
+ * Options for configuring Ollama embedding model calls
557
+ */
558
+ interface OllamaEmbeddingProviderOptions extends OllamaProviderOptions {
559
+ /**
560
+ * Maximum number of embeddings to process in a single call
561
+ */
562
+ maxEmbeddingsPerCall?: number;
563
+ }
564
+ /**
565
+ * Create an Ollama provider instance
566
+ */
567
+ declare function createOllama(options?: OllamaProviderSettings): OllamaProvider;
568
+ /**
569
+ * Default Ollama provider instance
570
+ */
571
+ declare const ollama: OllamaProvider;
572
+
573
+ interface OllamaErrorData {
574
+ message: string;
575
+ code?: string;
576
+ details?: unknown;
577
+ }
578
+ declare class OllamaError extends Error {
579
+ readonly cause?: unknown;
580
+ readonly data?: OllamaErrorData;
581
+ constructor({ message, cause, data, }: {
582
+ message: string;
583
+ cause?: unknown;
584
+ data?: OllamaErrorData;
585
+ });
586
+ static isOllamaError(error: unknown): error is OllamaError;
587
+ }
588
+
589
+ /**
590
+ * Calculate cosine similarity between two vectors.
591
+ *
592
+ * Cosine similarity measures the angle between two vectors in multi-dimensional space,
593
+ * returning a value between -1 and 1 where:
594
+ * - 1 means identical direction (most similar)
595
+ * - 0 means orthogonal (unrelated)
596
+ * - -1 means opposite direction (least similar)
597
+ *
598
+ * For normalized embedding vectors, this is equivalent to the dot product.
599
+ *
600
+ * @param a First vector
601
+ * @param b Second vector
602
+ * @returns Cosine similarity score between -1 and 1
603
+ * @throws Error if vectors have different dimensions
604
+ */
605
+ declare function cosineSimilarity(a: number[], b: number[]): number;
606
+
607
+ /**
608
+ * Tool Calling Reliability Utilities for Ollama
609
+ *
610
+ * This module provides utilities to make Ollama tool calling more reliable
611
+ * and deterministic. It addresses common issues like:
612
+ * - Empty final text responses after tool execution
613
+ * - Inconsistent parameter names
614
+ * - Incomplete agent loops
615
+ * - Tool result validation and recovery
616
+ */
617
+
618
+ interface ToolCallingOptions {
619
+ /**
620
+ * Maximum number of retry attempts for tool calls
621
+ */
622
+ maxRetries?: number;
623
+ /**
624
+ * Whether to force completion when tool calls succeed but no final text is generated
625
+ */
626
+ forceCompletion?: boolean;
627
+ /**
628
+ * Whether to normalize parameter names to handle inconsistencies
629
+ */
630
+ normalizeParameters?: boolean;
631
+ /**
632
+ * Whether to validate tool results and attempt recovery
633
+ */
634
+ validateResults?: boolean;
635
+ /**
636
+ * Custom parameter normalization mappings
637
+ */
638
+ parameterMappings?: Record<string, string[]>;
639
+ /**
640
+ * Timeout for tool execution in milliseconds
641
+ */
642
+ toolTimeout?: number;
643
+ }
644
+ interface ResolvedToolCallingOptions extends Omit<ToolCallingOptions, 'maxRetries' | 'forceCompletion' | 'normalizeParameters' | 'validateResults'> {
645
+ maxRetries: number;
646
+ forceCompletion: boolean;
647
+ normalizeParameters: boolean;
648
+ validateResults: boolean;
649
+ }
650
+ interface ToolCallResult {
651
+ success: boolean;
652
+ result?: unknown;
653
+ error?: string;
654
+ normalizedInput?: Record<string, unknown>;
655
+ }
656
+ interface ReliableToolCallResult {
657
+ text: string;
658
+ toolCalls: Array<{
659
+ toolName: string;
660
+ input: Record<string, unknown>;
661
+ }>;
662
+ toolResults?: Array<{
663
+ toolName: string;
664
+ input: Record<string, unknown>;
665
+ normalizedInput?: Record<string, unknown>;
666
+ result: unknown;
667
+ success: boolean;
668
+ error?: string;
669
+ }>;
670
+ completionMethod: 'natural' | 'forced' | 'incomplete';
671
+ retryCount: number;
672
+ errors?: string[];
673
+ }
674
+ interface ToolDefinition {
675
+ description: string;
676
+ inputSchema: Record<string, unknown>;
677
+ execute: (params: Record<string, unknown>) => Promise<unknown>;
678
+ }
679
+
680
+ /**
681
+ * generateText - Enhanced generateText with Ollama-specific reliability
682
+ *
683
+ * This wrapper provides response synthesis and enhanced tool calling reliability
684
+ * that addresses the core Ollama limitation: tools execute but no final text is generated.
685
+ */
686
+
687
+ /**
688
+ * Enhanced options for Ollama-specific reliability features
689
+ */
690
+ interface EnhancedOptions {
691
+ /**
692
+ * Enable response synthesis when tools are called but no text is generated
693
+ * @default true
694
+ */
695
+ enableSynthesis?: boolean;
696
+ /**
697
+ * Custom synthesis prompt template
698
+ */
699
+ synthesisPrompt?: string;
700
+ /**
701
+ * Maximum attempts for synthesis
702
+ * @default 2
703
+ */
704
+ maxSynthesisAttempts?: number;
705
+ /**
706
+ * Minimum response length to consider valid
707
+ * @default 10
708
+ */
709
+ minResponseLength?: number;
710
+ /**
711
+ * EXPERIMENTAL: Enable tool calling with structured output (experimental_output)
712
+ *
713
+ * The official AI SDK doesn't support combining toolChoice: 'required' with experimental_output.
714
+ * When enabled, this uses a two-phase approach:
715
+ * 1. Execute tools first (without experimental_output)
716
+ * 2. Generate structured output with tool results injected as context
717
+ *
718
+ * This is NOT standard AI SDK behavior - only enable if you need both features together.
719
+ *
720
+ * @default false
721
+ */
722
+ enableToolsWithStructuredOutput?: boolean;
723
+ }
724
+ /**
725
+ * Enhanced generateText options that extend the official AI SDK options
726
+ */
727
+ type GenerateTextOptions = Parameters<typeof generateText$1>[0] & {
728
+ /**
729
+ * Enhanced options for Ollama-specific reliability features
730
+ */
731
+ enhancedOptions?: EnhancedOptions;
732
+ };
733
+ /**
734
+ * Enhanced generateText function with Ollama-specific reliability improvements
735
+ *
736
+ * This function applies synthesis by default when tools execute but return empty responses.
737
+ * The enhancement preserves the original response prototype and all methods/getters.
738
+ *
739
+ * Type parameters are inferred from the options, preserving AI SDK's type inference.
740
+ */
741
+ declare function generateText(options: GenerateTextOptions): Promise<Awaited<ReturnType<typeof generateText$1>>>;
742
+
743
+ /**
744
+ * streamText - Enhanced streamText with Ollama-specific reliability
745
+ *
746
+ * This wrapper provides streaming tool calling reliability by detecting
747
+ * when tools execute but no text is streamed, then providing synthesis.
748
+ *
749
+ * Enhances both `textStream` and `fullStream` with synthesis support.
750
+ */
751
+
752
+ type AIStreamTextOptions = Parameters<typeof streamText$1>[0];
753
+ /**
754
+ * Enhanced streamText options that extend the official AI SDK options
755
+ * This ensures 100% compatibility - all AI SDK properties are supported
756
+ */
757
+ type StreamTextOptions = AIStreamTextOptions & {
758
+ /**
759
+ * Enhanced options for Ollama-specific reliability features
760
+ */
761
+ enhancedOptions?: {
762
+ /**
763
+ * Enable enhanced tool calling logging
764
+ * @default true
765
+ */
766
+ enableToolLogging?: boolean;
767
+ /**
768
+ * Enable streaming synthesis when tools execute but no text streams
769
+ * @default true
770
+ */
771
+ enableStreamingSynthesis?: boolean;
772
+ /**
773
+ * Minimum streamed characters before considering it successful
774
+ * @default 10
775
+ */
776
+ minStreamLength?: number;
777
+ /**
778
+ * Timeout in ms to wait for streaming before applying synthesis
779
+ * @default 3000
780
+ */
781
+ synthesisTimeout?: number;
782
+ };
783
+ };
784
+ /**
785
+ * Enhanced streamText function with Ollama-specific reliability improvements
786
+ * Enhances both textStream and fullStream with synthesis support
787
+ */
788
+ declare function streamText(options: StreamTextOptions): Promise<Awaited<ReturnType<typeof streamText$1>>>;
789
+
790
+ export { type GenerateTextOptions, type ObjectGenerationOptions, type OllamaChatProviderOptions, type OllamaChatSettings, type OllamaEmbeddingProviderOptions, OllamaEmbeddingRerankingModel, type OllamaEmbeddingRerankingSettings, type OllamaEmbeddingSettings, OllamaError, type OllamaErrorData, type OllamaProvider, type OllamaProviderOptions, type OllamaProviderSettings, OllamaRerankingModel, type OllamaRerankingProviderOptions, type OllamaRerankingSettings, type Options, type ReliableToolCallResult, type ResolvedToolCallingOptions, type StreamTextOptions, type ToolCallResult, type ToolCallingOptions, type ToolDefinition, cosineSimilarity, createOllama, generateText, ollama, streamText };