{"_id":"@doshi/ollama-ai-provider","name":"@doshi/ollama-ai-provider","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@doshi/ollama-ai-provider","version":"0.1.0","description":"Vercel AI SDK v6 Ollama provider with auto JSON instruction injection","type":"module","main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"sideEffects":false,"dependencies":{"@ai-sdk/provider":"^3.0.0","@ai-sdk/provider-utils":"^4.0.0","jsonrepair":"^3.0.0"},"peerDependencies":{"ai":"^6.0.0"},"devDependencies":{"@biomejs/biome":"^1.9.0","@types/node":"^22.0.0","ai":"^6.0.0","dotenv":"^17.4.2","msw":"^2.0.0","tsup":"^8.0.0","tsx":"^4.21.0","typescript":"^5.5.0","vitest":"^3.0.0"},"engines":{"node":">=18"},"keywords":["ollama","ai","ai-sdk","vercel-ai","llm","structured-output","json-mode","language-model"],"author":{"name":"Doshi"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/Doshi-App/ollama-ai-provider.git"},"bugs":{"url":"https://github.com/Doshi-App/ollama-ai-provider/issues"},"homepage":"https://github.com/Doshi-App/ollama-ai-provider#readme","publishConfig":{"access":"public"},"scripts":{"build":"tsup","dev":"tsup --watch","test":"vitest run","test:unit":"vitest run src","test:watch":"vitest","typecheck":"tsc --noEmit","lint":"biome lint .","format":"biome format --write .","smoke":"tsx scripts/smoke.ts"},"_id":"@doshi/ollama-ai-provider@0.1.0","_integrity":"sha512-sh/hN+gcknM/SjahM5KJErK7p9Ef+iP3+OfsKvLFKkHDihvTF6LDD4u8V8eP3suRoDxa8tLnyvvksMaoFLNHXw==","_resolved":"/private/var/folders/xq/lwlx1wlx38q4c7sk1twgsk980000gn/T/37912a132231e9f95aa6c3be3b03ed1d/doshi-ollama-ai-provider-0.1.0.tgz","_from":"file:doshi-ollama-ai-provider-0.1.0.tgz","_nodeVersion":"24.14.1","_npmVersion":"11.11.0","dist":{"integrity":"sha512-sh/hN+gcknM/SjahM5KJErK7p9Ef+iP3+OfsKvLFKkHDihvTF6LDD4u8V8eP3suRoDxa8tLnyvvksMaoFLNHXw==","shasum":"432269e67f46a7b572a99f693dfb1f5b45e35c5b","tarball":"https://registry.npmjs.org/@doshi/ollama-ai-provider/-/ollama-ai-provider-0.1.0.tgz","fileCount":10,"unpackedSize":118807,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIEI8YaK2iQPpZI49x6T65BgmEkDqOiBHTBApJetGbt9QAiEAwf2RQ+5x/72neBDE9QPdEQc2jI2JgxHSkgBwVR+M4Ps="}]},"_npmUser":{"name":"vendoshi","email":"ven@doshi.app"},"directories":{},"maintainers":[{"name":"vendoshi","email":"ven@doshi.app"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ollama-ai-provider_0.1.0_1778585257975_0.5010378451828534"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-12T11:27:37.775Z","0.1.0":"2026-05-12T11:27:38.111Z","modified":"2026-05-12T11:27:38.458Z"},"maintainers":[{"name":"vendoshi","email":"ven@doshi.app"}],"description":"Vercel AI SDK v6 Ollama provider with auto JSON instruction injection","homepage":"https://github.com/Doshi-App/ollama-ai-provider#readme","keywords":["ollama","ai","ai-sdk","vercel-ai","llm","structured-output","json-mode","language-model"],"repository":{"type":"git","url":"git+https://github.com/Doshi-App/ollama-ai-provider.git"},"author":{"name":"Doshi"},"bugs":{"url":"https://github.com/Doshi-App/ollama-ai-provider/issues"},"license":"MIT","readme":"# @doshi/ollama-ai-provider\n\nOllama provider for the [Vercel AI SDK](https://sdk.vercel.ai) (v6) with\nautomatic JSON-instruction injection and response repair.\n\nUse it anywhere you'd use `@ai-sdk/openai`, `@ai-sdk/anthropic`, or\n`@ai-sdk/google` — same `generateText` / `streamText` API, including\n`Output.object({ schema })` for typed structured output.\n\n```ts\nimport { generateText, Output } from 'ai';\nimport { ollama } from '@doshi/ollama-ai-provider';\nimport { z } from 'zod';\nimport { zodSchema } from '@ai-sdk/provider-utils';\n\nconst Rating = zodSchema(\n  z.object({\n    rating: z.number().min(0).max(10).describe('Quality score'),\n    reason: z.string().describe('Why this rating'),\n  }),\n);\n\nconst { output } = await generateText({\n  model: ollama('gpt-oss:20b-cloud'),\n  output: Output.object({ schema: Rating }),\n  system: 'You are a content evaluator.',\n  prompt: 'Rate this content: \"Hello world\".',\n});\n\nconsole.log(output); // { rating: 2, reason: '...' }\n```\n\n## Install\n\n```sh\npnpm add @doshi/ollama-ai-provider ai\n# or\nnpm install @doshi/ollama-ai-provider ai\n```\n\n## Why this exists\n\nOllama Cloud honors a JSON Schema via its native `format` field, but\nreasoning-heavy models (gpt-oss, qwen3-thinking) still benefit from being told\n**what shape to produce** and **where to put it** in plain English. Otherwise\nthey sometimes consume the entire output-token budget on internal \"thinking\"\nand return empty content.\n\nThis package handles that automatically. Every time you use\n`Output.object({ schema })`, the provider:\n\n1. Renders your JSON Schema as a compact, readable instruction (including\n   `.describe()` annotations, enum unions, ranges, defaults).\n2. Appends it to the system prompt along with directives telling the model to\n   put the JSON in its **reply content**, not in `<think>` / reasoning.\n3. Sends the raw schema as Ollama's `format` field for server-side grammar\n   constraints.\n4. Repairs the response with [`jsonrepair`](https://github.com/josdejong/jsonrepair)\n   before the SDK parses it (strips markdown fences, fixes trailing commas,\n   etc.).\n\nResult: `generateText({ output: Output.object(...) }).output` returns a parsed\nobject, reliably, with the same call signature you'd use for OpenAI.\n\n## Configuration\n\n```ts\nimport { createOllama } from '@doshi/ollama-ai-provider';\n\nconst ollama = createOllama({\n  baseURL: 'https://ollama.com',     // default\n  apiKey: process.env.OLLAMA_API_KEY, // required for Ollama Cloud\n  headers: { 'X-Trace-Id': '...' },   // optional, merged into every request\n  fetch: customFetch,                 // optional, for testing or proxying\n});\n```\n\nThe default singleton `ollama` reads `OLLAMA_BASE_URL` and `OLLAMA_API_KEY`\nfrom `process.env`.\n\n## API\n\n```ts\n// Factory\ncreateOllama(options?: OllamaProviderSettings): OllamaProvider\n\n// Default singleton\nollama: OllamaProvider\n\n// The schema → human-readable instruction renderer (exported for tests)\njsonSchemaToInstruction(schema: JSONSchema7, options?): string\n\n// The JSON repair wrapper (exported for tests)\njsonRepairText(text: string): string\n```\n\n`OllamaProvider` is callable: `ollama('model-id')` returns a `LanguageModelV3`\nsuitable for any AI SDK v6 helper (`generateText`, `streamText`,\n`generateObject`, agents, etc.).\n\n## Streaming\n\n`streamText` works as in any other provider. Reasoning models'\n`message.thinking` deltas are surfaced as AI SDK reasoning parts, so:\n\n```ts\nconst result = streamText({ model: ollama('gpt-oss:20b-cloud'), prompt });\nfor await (const chunk of result.fullStream) {\n  if (chunk.type === 'reasoning-delta') /* … */;\n  if (chunk.type === 'text-delta')      /* … */;\n}\nconsole.log(await result.reasoningText); // model's chain-of-thought\nconsole.log(await result.text);          // model's reply\n```\n\nIn JSON mode (`output: Output.object(...)`), content deltas are buffered until\ncompletion so the final text can be `jsonrepair`'d in one pass — necessary\nbecause partial structured-output streams can't be repaired piecewise. Plain\nstreaming (no `output:`) is unbuffered.\n\n## What's NOT supported\n\n- **Image / file content parts in prompts** — Ollama `/api/chat` is text-only.\n  Surfaces as a warning rather than silently dropping.\n- **Tool calls** — the base AI SDK tool-call shape isn't wired through to\n  Ollama's `tools` field yet.\n- **Embeddings / reranking / speech** — text completion only for now.\n\n## Development\n\n```sh\npnpm install\npnpm test          # unit + integration + packaging e2e\npnpm typecheck\npnpm build         # emits dist/ (ESM + CJS + .d.ts)\npnpm smoke         # against real Ollama Cloud, needs OLLAMA_API_KEY\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-dd655eef44c1ec276e2b46a940d46a1f"}