ai-sdk-ollama 0.3.0 โ†’ 0.5.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 (86) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +95 -1
  3. package/dist/index.browser.cjs +663 -0
  4. package/dist/index.browser.cjs.map +1 -0
  5. package/dist/index.browser.d.cts +219 -0
  6. package/dist/index.browser.d.ts +219 -0
  7. package/dist/index.browser.js +642 -0
  8. package/dist/index.browser.js.map +1 -0
  9. package/dist/index.cjs +100 -23
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +5 -1
  12. package/dist/index.d.ts +5 -1
  13. package/dist/index.js +100 -23
  14. package/dist/index.js.map +1 -1
  15. package/package.json +34 -15
  16. package/dist/compatibility.test.d.ts +0 -2
  17. package/dist/compatibility.test.d.ts.map +0 -1
  18. package/dist/compatibility.test.js +0 -123
  19. package/dist/index.d.ts.map +0 -1
  20. package/dist/integration.test.d.ts +0 -2
  21. package/dist/integration.test.d.ts.map +0 -1
  22. package/dist/integration.test.js +0 -221
  23. package/dist/internal/index.cjs +0 -135
  24. package/dist/internal/index.cjs.map +0 -1
  25. package/dist/internal/index.d.cts +0 -18
  26. package/dist/internal/index.d.ts +0 -18
  27. package/dist/internal/index.d.ts.map +0 -1
  28. package/dist/internal/index.js +0 -107
  29. package/dist/internal/index.js.map +0 -1
  30. package/dist/models/chat-language-model.d.ts +0 -49
  31. package/dist/models/chat-language-model.d.ts.map +0 -1
  32. package/dist/models/chat-language-model.js +0 -278
  33. package/dist/models/chat-language-model.test.d.ts +0 -2
  34. package/dist/models/chat-language-model.test.d.ts.map +0 -1
  35. package/dist/models/chat-language-model.test.js +0 -486
  36. package/dist/models/embedding-model.d.ts +0 -24
  37. package/dist/models/embedding-model.d.ts.map +0 -1
  38. package/dist/models/embedding-model.js +0 -77
  39. package/dist/models/embedding-model.test.d.ts +0 -2
  40. package/dist/models/embedding-model.test.d.ts.map +0 -1
  41. package/dist/models/embedding-model.test.js +0 -281
  42. package/dist/provider-dual-parameters.test.d.ts +0 -2
  43. package/dist/provider-dual-parameters.test.d.ts.map +0 -1
  44. package/dist/provider-dual-parameters.test.js +0 -223
  45. package/dist/provider.d.ts +0 -123
  46. package/dist/provider.d.ts.map +0 -1
  47. package/dist/provider.js +0 -52
  48. package/dist/provider.test.d.ts +0 -2
  49. package/dist/provider.test.d.ts.map +0 -1
  50. package/dist/provider.test.js +0 -192
  51. package/dist/test-setup.d.ts +0 -4
  52. package/dist/test-setup.d.ts.map +0 -1
  53. package/dist/test-setup.js +0 -31
  54. package/dist/utils/convert-to-ollama-messages.d.ts +0 -4
  55. package/dist/utils/convert-to-ollama-messages.d.ts.map +0 -1
  56. package/dist/utils/convert-to-ollama-messages.js +0 -105
  57. package/dist/utils/convert-to-ollama-messages.test.d.ts +0 -2
  58. package/dist/utils/convert-to-ollama-messages.test.d.ts.map +0 -1
  59. package/dist/utils/convert-to-ollama-messages.test.js +0 -433
  60. package/dist/utils/map-ollama-finish-reason.d.ts +0 -3
  61. package/dist/utils/map-ollama-finish-reason.d.ts.map +0 -1
  62. package/dist/utils/map-ollama-finish-reason.js +0 -15
  63. package/dist/utils/map-ollama-finish-reason.test.d.ts +0 -2
  64. package/dist/utils/map-ollama-finish-reason.test.d.ts.map +0 -1
  65. package/dist/utils/map-ollama-finish-reason.test.js +0 -47
  66. package/dist/utils/model-capabilities.d.ts +0 -28
  67. package/dist/utils/model-capabilities.d.ts.map +0 -1
  68. package/dist/utils/model-capabilities.js +0 -327
  69. package/dist/utils/model-suggestions.d.ts +0 -38
  70. package/dist/utils/model-suggestions.d.ts.map +0 -1
  71. package/dist/utils/model-suggestions.js +0 -158
  72. package/dist/utils/normalize-tool-parameters.d.ts +0 -17
  73. package/dist/utils/normalize-tool-parameters.d.ts.map +0 -1
  74. package/dist/utils/normalize-tool-parameters.js +0 -63
  75. package/dist/utils/normalize-tool-parameters.test.d.ts +0 -2
  76. package/dist/utils/normalize-tool-parameters.test.d.ts.map +0 -1
  77. package/dist/utils/normalize-tool-parameters.test.js +0 -100
  78. package/dist/utils/ollama-error.d.ts +0 -16
  79. package/dist/utils/ollama-error.d.ts.map +0 -1
  80. package/dist/utils/ollama-error.js +0 -13
  81. package/dist/utils/ollama-error.test.d.ts +0 -2
  82. package/dist/utils/ollama-error.test.d.ts.map +0 -1
  83. package/dist/utils/ollama-error.test.js +0 -94
  84. package/dist/utils/validate-model.d.ts +0 -32
  85. package/dist/utils/validate-model.d.ts.map +0 -1
  86. package/dist/utils/validate-model.js +0 -32
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add browser support with automatic environment detection
8
+ - Add browser-specific provider using ollama/browser package
9
+ - Implement dual package exports for Node.js and browser environments
10
+ - Add comprehensive browser example with Vite and interactive UI
11
+ - Update build configuration to generate separate browser and Node.js bundles
12
+ - Add browser compatibility tests and examples
13
+
14
+ - e02f8af: Feature: Browser support and streaming improvements. Closes https://github.com/jagreehal/ai-sdk-ollama/issues/14
15
+ - feat(browser): Automatic browser support via `ollama/browser` with dedicated `index.browser` export. Works seamlessly with bundlers and `ai` v5 in browser contexts.
16
+ - fix(streaming): Emit trailing `text-delta` on the final `done` chunk to avoid empty streams for models that only flush content at the end. Note: streams may include one additional text chunk now.
17
+ - tests: Add `gpt-oss:20b` integration coverage and make prompts/token limits more robust; update unit tests to reflect final text emission on `done`.
18
+ - docs/examples: Switch Node examples to per-file `tsx` execution and update READMEs; clarify how to run browser and node examples.
19
+ - chore(repo): Monorepo migration (no user-facing API changes), Dependabot config for package folder, and CI refinements.
20
+
21
+ No breaking changes to the public API.
22
+
23
+ ## 0.4.0
24
+
25
+ ### Minor Changes
26
+
27
+ - **Reasoning Support**: Added support for reasoning (chain-of-thought) output
28
+ - ๐Ÿง  **Reasoning Content**: Models that support reasoning can now output their thinking process
29
+ - ๐Ÿ“ **Content Types**: Support for `LanguageModelV2Reasoning` content type in both non-streaming and streaming responses
30
+ - ๐Ÿ”„ **Streaming Support**: Full streaming support with `reasoning-start`, `reasoning-delta`, and `reasoning-end` events
31
+ - โš™๏ธ **Configurable**: Enable reasoning with `{ reasoning: true }` setting
32
+ - ๐Ÿงช **Comprehensive Testing**: Added unit tests for reasoning functionality
33
+ - ๐Ÿ“š **Documentation**: Updated README and examples with reasoning usage
34
+ - ๐ŸŽฏ **Backward Compatible**: Reasoning is disabled by default, existing code continues to work
35
+
36
+ ### Technical Improvements
37
+
38
+ - Added `reasoning` setting to `OllamaChatSettings` interface
39
+ - Enhanced `doGenerate` method to handle `thinking` field from Ollama responses
40
+ - Enhanced `doStream` method to emit reasoning stream parts
41
+ - Added reasoning support to content conversion logic
42
+ - Updated type definitions to include reasoning content types
43
+
3
44
  ## 0.3.0
4
45
 
5
46
  ### Minor Changes
package/README.md CHANGED
@@ -15,6 +15,10 @@ A Vercel AI SDK v5+ provider for Ollama built on the official `ollama` package.
15
15
  - [Quick Start](#quick-start)
16
16
  - [Installation](#installation)
17
17
  - [Basic Usage](#basic-usage)
18
+ - [Browser Support](#browser-support)
19
+ - [Browser Usage](#browser-usage)
20
+ - [Explicit Browser Import](#explicit-browser-import)
21
+ - [CORS Configuration](#cors-configuration)
18
22
  - [Key Features](#key-features)
19
23
  - [Cross Provider Compatibility](#cross-provider-compatibility)
20
24
  - [Native Ollama Power](#native-ollama-power)
@@ -24,6 +28,7 @@ A Vercel AI SDK v5+ provider for Ollama built on the official `ollama` package.
24
28
  - [Custom Ollama Instance](#custom-ollama-instance)
25
29
  - [Structured Output](#structured-output)
26
30
  - [Auto-Detection of Structured Outputs](#auto-detection-of-structured-outputs)
31
+ - [Reasoning Support](#reasoning-support)
27
32
  - [Common Issues](#common-issues)
28
33
  - [Supported Models](#supported-models)
29
34
  - [Testing](#testing)
@@ -114,6 +119,52 @@ const { embedding } = await embed({
114
119
  console.log(embedding.length); // 768 dimensions
115
120
  ```
116
121
 
122
+ ## Browser Support
123
+
124
+ See the [browser example](../../examples/browser/).
125
+
126
+ This provider works in both Node.js and browser environments. The library automatically selects the correct Ollama client based on the environment.
127
+
128
+ ### Browser Usage
129
+
130
+ The same API works in browsers with automatic environment detection:
131
+
132
+ ```typescript
133
+ import { ollama } from 'ai-sdk-ollama'; // Automatically uses browser version
134
+ import { generateText } from 'ai';
135
+
136
+ const { text } = await generateText({
137
+ model: ollama('llama3.2'),
138
+ prompt: 'Write a haiku about coding',
139
+ });
140
+ ```
141
+
142
+ ### Explicit Browser Import
143
+
144
+ You can also explicitly import the browser version:
145
+
146
+ ```typescript
147
+ import { ollama } from 'ai-sdk-ollama/browser';
148
+ ```
149
+
150
+ ### CORS Configuration
151
+
152
+ For browser usage, you have several options to handle CORS:
153
+
154
+ ```bash
155
+ # Option 1: Use a proxy (recommended for development)
156
+ # Configure your bundler (Vite, Webpack, etc.) to proxy /api/* to Ollama
157
+ # See browser example for Vite proxy configuration
158
+
159
+ # Option 2: Allow all origins (development only)
160
+ OLLAMA_ORIGINS=* ollama serve
161
+
162
+ # Option 3: Allow specific origins
163
+ OLLAMA_ORIGINS="http://localhost:3000,https://myapp.com" ollama serve
164
+ ```
165
+
166
+ **Recommended**: Use a development proxy (like Vite proxy) to avoid CORS issues entirely. See the browser example for a complete working setup.
167
+
117
168
  ## Key Features
118
169
 
119
170
  ### Cross Provider Compatibility
@@ -274,6 +325,48 @@ const { text } = await generateText({
274
325
  });
275
326
  ```
276
327
 
328
+ ### Reasoning Support
329
+
330
+ Some models like DeepSeek-R1 support reasoning (chain-of-thought) output. Enable this feature to see the model's thinking process:
331
+
332
+ ```typescript
333
+ // Enable reasoning for models that support it (e.g., deepseek-r1:7b)
334
+ const model = ollama('deepseek-r1:7b', { reasoning: true });
335
+
336
+ // Generate text with reasoning
337
+ const { text } = await generateText({
338
+ model,
339
+ prompt:
340
+ 'Solve: If I have 3 boxes, each with 4 smaller boxes, and each smaller box has 5 items, how many items total?',
341
+ });
342
+
343
+ console.log('Answer:', text);
344
+ // DeepSeek-R1 includes reasoning in the output with <think> tags:
345
+ // <think>
346
+ // First, I'll calculate the number of smaller boxes: 3 ร— 4 = 12
347
+ // Then, the total items: 12 ร— 5 = 60
348
+ // </think>
349
+ // You have 60 items in total.
350
+
351
+ // Compare with reasoning disabled
352
+ const modelNoReasoning = ollama('deepseek-r1:7b', { reasoning: false });
353
+ const { text: noReasoningText } = await generateText({
354
+ model: modelNoReasoning,
355
+ prompt: 'Calculate 3 ร— 4 ร— 5',
356
+ });
357
+ // Output: 60 (without showing the thinking process)
358
+ ```
359
+
360
+ **Recommended Reasoning Models**:
361
+
362
+ - `deepseek-r1:7b` - Balanced performance and reasoning capability (5GB)
363
+ - `deepseek-r1:1.5b` - Lightweight option (2.5GB)
364
+ - `deepseek-r1:8b` - Llama-based distilled version (5.5GB)
365
+
366
+ Install with: `ollama pull deepseek-r1:7b`
367
+
368
+ **Note**: The reasoning feature is model-dependent. Models without reasoning support will work normally without showing thinking process.
369
+
277
370
  ## Common Issues
278
371
 
279
372
  - **Make sure Ollama is running** - Run `ollama serve` before using the provider
@@ -287,9 +380,10 @@ const { text } = await generateText({
287
380
 
288
381
  Works with any model in your Ollama installation:
289
382
 
290
- - **Chat**: `llama3.2`, `mistral`, `phi4-mini`, `qwen2.5`, `codellama`
383
+ - **Chat**: `llama3.2`, `mistral`, `phi4-mini`, `qwen2.5`, `codellama`, `gpt-oss:20b`
291
384
  - **Vision**: `llava`, `bakllava`, `llama3.2-vision`, `minicpm-v`
292
385
  - **Embeddings**: `nomic-embed-text`, `all-minilm`, `mxbai-embed-large`
386
+ - **Reasoning**: `deepseek-r1:7b`, `deepseek-r1:1.5b`, `deepseek-r1:8b`
293
387
 
294
388
  ## Testing
295
389