@coder/ai-sdk-provider 0.3.3 → 0.3.5
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.
- package/README.md +10 -3
- package/dist/index.d.ts +6 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -76,12 +76,19 @@ coder("gpt-4o"); // → OpenAI surface
|
|
|
76
76
|
coder("claude-sonnet-4-6"); // → Anthropic surface (heuristic)
|
|
77
77
|
coder.openai("claude-sonnet-4"); // → OpenAI surface (e.g. Copilot)
|
|
78
78
|
coder.anthropic("claude-opus-4-5"); // → Anthropic surface (explicit)
|
|
79
|
-
coder.textEmbeddingModel("text-embedding-3-small"); // → OpenAI surface
|
|
80
79
|
```
|
|
81
80
|
|
|
82
81
|
Model ids are passed through **unchanged** to the upstream provider (no
|
|
83
82
|
`vendor/model` namespacing) — use whatever ids your deployment's providers accept.
|
|
84
83
|
|
|
84
|
+
**Embeddings are not supported yet.** AI Gateway does not intercept
|
|
85
|
+
`/v1/embeddings`, so `coder.textEmbeddingModel(id)` — and the embedding
|
|
86
|
+
accessors on `coder.openai` — throw the AI SDK's `NoSuchModelError`
|
|
87
|
+
immediately instead of emitting a request the gateway rejects with a 404. The
|
|
88
|
+
accessors stay so they can light up without a breaking change once the gateway
|
|
89
|
+
adds an embeddings route — see
|
|
90
|
+
[coder/ai-sdk#69](https://github.com/coder/ai-sdk/issues/69).
|
|
91
|
+
|
|
85
92
|
## Authentication
|
|
86
93
|
|
|
87
94
|
**Centralized mode (default).** Pass your Coder API token as `apiKey`. AI Gateway
|
|
@@ -140,8 +147,8 @@ no telemetry of its own; each request is exactly what the AI SDK builds for a
|
|
|
140
147
|
normal provider call:
|
|
141
148
|
|
|
142
149
|
- **URL** — `POST <baseURL>/api/v2/aibridge/<provider>/v1/chat/completions`
|
|
143
|
-
(OpenAI surface
|
|
144
|
-
|
|
150
|
+
(OpenAI surface) or `…/v1/messages` (Anthropic surface). `/api/v2/aibridge`
|
|
151
|
+
is this package's
|
|
145
152
|
default; deployments also serve the post-rename alias `/api/v2/ai-gateway`
|
|
146
153
|
(see `aiGatewayPath`).
|
|
147
154
|
- **Auth headers** — per the mode matrix below.
|
package/dist/index.d.ts
CHANGED
|
@@ -63,7 +63,12 @@ interface CoderProvider {
|
|
|
63
63
|
chat(modelId: string): LanguageModelV4;
|
|
64
64
|
/** Shorthand for an {@link CoderProvider.anthropic} messages model. */
|
|
65
65
|
messages(modelId: string): LanguageModelV4;
|
|
66
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Text embeddings are not supported: AI Gateway does not yet intercept
|
|
68
|
+
* `/v1/embeddings`, so this always throws {@link NoSuchModelError} instead of
|
|
69
|
+
* emitting a request that the gateway rejects with a 404. Tracked in
|
|
70
|
+
* https://github.com/coder/ai-sdk/issues/69.
|
|
71
|
+
*/
|
|
67
72
|
textEmbeddingModel(modelId: string): EmbeddingModelV4;
|
|
68
73
|
}
|
|
69
74
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/provider.ts
|
|
2
2
|
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
3
3
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
4
|
+
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
4
5
|
var DEFAULT_AI_GATEWAY_PATH = "/api/v2/aibridge";
|
|
5
6
|
var DEFAULT_OPENAI_PROVIDER = "openai";
|
|
6
7
|
var DEFAULT_ANTHROPIC_PROVIDER = "anthropic";
|
|
@@ -11,6 +12,13 @@ function isAnthropicModelId(modelId) {
|
|
|
11
12
|
function trimTrailingSlash(url) {
|
|
12
13
|
return url.replace(/\/+$/, "");
|
|
13
14
|
}
|
|
15
|
+
function unsupportedEmbeddingModel(modelId) {
|
|
16
|
+
throw new NoSuchModelError({
|
|
17
|
+
modelId,
|
|
18
|
+
modelType: "embeddingModel",
|
|
19
|
+
message: `Coder AI Gateway does not yet intercept /v1/embeddings, so the embedding model "${modelId}" cannot be reached through it. See https://github.com/coder/ai-sdk/issues/69 for status.`
|
|
20
|
+
});
|
|
21
|
+
}
|
|
14
22
|
function createCoder(settings) {
|
|
15
23
|
if (!settings.baseURL) {
|
|
16
24
|
throw new Error(
|
|
@@ -37,6 +45,8 @@ function createCoder(settings) {
|
|
|
37
45
|
fetch: settings.fetch,
|
|
38
46
|
includeUsage: true
|
|
39
47
|
});
|
|
48
|
+
openai.embeddingModel = unsupportedEmbeddingModel;
|
|
49
|
+
openai.textEmbeddingModel = unsupportedEmbeddingModel;
|
|
40
50
|
const anthropic = createAnthropic({
|
|
41
51
|
name: "coder.anthropic",
|
|
42
52
|
baseURL: anthropicBaseURL,
|
|
@@ -53,7 +63,7 @@ function createCoder(settings) {
|
|
|
53
63
|
anthropic,
|
|
54
64
|
chat: (modelId) => openai(modelId),
|
|
55
65
|
messages: (modelId) => anthropic(modelId),
|
|
56
|
-
textEmbeddingModel:
|
|
66
|
+
textEmbeddingModel: unsupportedEmbeddingModel
|
|
57
67
|
});
|
|
58
68
|
}
|
|
59
69
|
var coder = createCoder;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/provider.ts"],"sourcesContent":["import { type AnthropicProvider, createAnthropic } from \"@ai-sdk/anthropic\";\nimport { createOpenAICompatible, type OpenAICompatibleProvider } from \"@ai-sdk/openai-compatible\";\nimport type { EmbeddingModelV4, LanguageModelV4 } from \"@ai-sdk/provider\";\n\n/** Default mount path of AI Gateway on a Coder deployment. */\nconst DEFAULT_AI_GATEWAY_PATH = \"/api/v2/aibridge\";\n/** Default provider path segments (the admin-configured provider names). */\nconst DEFAULT_OPENAI_PROVIDER = \"openai\";\nconst DEFAULT_ANTHROPIC_PROVIDER = \"anthropic\";\n/** Header that carries the Coder token to AI Gateway in bring-your-own-key mode. */\nconst CODER_TOKEN_HEADER = \"X-Coder-AI-Governance-Token\";\n\nexport interface CoderProviderSettings {\n /**\n * Base URL of your Coder deployment, e.g. `https://coder.example.com`. Do NOT\n * include the AI Gateway path (`/api/v2/aibridge/...`) — it is appended for you.\n */\n baseURL: string;\n /**\n * The credential sent to AI Gateway.\n *\n * - **Centralized mode (default):** your **Coder API token**. AI Gateway holds\n * the upstream provider keys and brokers the call, so this is all you need.\n * - **BYOK mode** (when {@link CoderProviderSettings.coderToken} is also set):\n * your **upstream provider key**, which AI Gateway forwards to the upstream.\n */\n apiKey?: string;\n /**\n * Enables bring-your-own-key (BYOK) mode. This Coder API token is sent in the\n * `X-Coder-AI-Governance-Token` header to authenticate you to the gateway,\n * while {@link CoderProviderSettings.apiKey} carries your upstream provider key.\n * Leave unset for the default centralized mode.\n */\n coderToken?: string;\n /** Extra headers merged into every request to both surfaces. */\n headers?: Record<string, string>;\n /**\n * Mount path of AI Gateway on the deployment. Defaults to `/api/v2/aibridge`.\n * Exposed because the `aibridge` path segment may change in a future Coder\n * release (the feature was renamed \"AI Gateway\").\n */\n aiGatewayPath?: string;\n /**\n * Override the provider path segments — the *admin-configured provider names*\n * on the deployment (e.g. `anthropic-corp`). Default to `openai` / `anthropic`.\n */\n providers?: {\n openai?: string;\n anthropic?: string;\n };\n /** Custom fetch implementation (useful for testing or middleware). */\n fetch?: typeof globalThis.fetch;\n}\n\nexport interface CoderProvider {\n /** Route a model id to a surface by heuristic (Claude ids → Anthropic surface). */\n (modelId: string): LanguageModelV4;\n /** Route a model id to a surface by heuristic (Claude ids → Anthropic surface). */\n languageModel(modelId: string): LanguageModelV4;\n /**\n * AI Gateway's OpenAI-compatible surface (`/aibridge/openai/v1`). Reaches the\n * OpenAI / Azure / Google / OpenRouter / Vercel / openai-compat and Copilot\n * upstreams. Routing is by URL, so any model id sent here hits this surface.\n */\n openai: OpenAICompatibleProvider;\n /**\n * AI Gateway's Anthropic-compatible surface (`/aibridge/anthropic`). Reaches\n * native Claude and Bedrock-hosted Claude.\n */\n anthropic: AnthropicProvider;\n /** Shorthand for an {@link CoderProvider.openai} chat model. */\n chat(modelId: string): LanguageModelV4;\n /** Shorthand for an {@link CoderProvider.anthropic} messages model. */\n messages(modelId: string): LanguageModelV4;\n /** Text-embedding model via the OpenAI-compatible surface. */\n textEmbeddingModel(modelId: string): EmbeddingModelV4;\n}\n\n/**\n * Heuristic for the bare {@link CoderProvider} call: which AI Gateway surface\n * should a model id route to? Claude / Anthropic ids go to the Anthropic\n * surface; everything else to the OpenAI-compatible surface. Use the explicit\n * `.openai(id)` / `.anthropic(id)` accessors to override (e.g. to reach Claude\n * through a Copilot-typed provider on the OpenAI surface).\n */\nexport function isAnthropicModelId(modelId: string): boolean {\n return /^(?:claude|anthropic[./:])/i.test(modelId);\n}\n\nfunction trimTrailingSlash(url: string): string {\n return url.replace(/\\/+$/, \"\");\n}\n\n/**\n * Create a {@link CoderProvider} that routes Vercel AI SDK calls through a Coder\n * deployment's AI Gateway (formerly \"AI Bridge\"). AI Gateway exposes two\n * provider-namespaced surfaces; this provider fronts both and selects between\n * them per model.\n *\n * @example\n * ```ts\n * import { generateText } from \"ai\";\n * import { createCoder } from \"@coder/ai-sdk-provider\";\n *\n * const coder = createCoder({\n * baseURL: \"https://coder.example.com\",\n * apiKey: process.env.CODER_API_TOKEN!,\n * });\n *\n * await generateText({ model: coder(\"gpt-4o\"), prompt: \"Hi\" }); // OpenAI surface\n * await generateText({ model: coder(\"claude-sonnet-4-6\"), prompt: \"Hi\" }); // Anthropic surface\n * ```\n */\nexport function createCoder(settings: CoderProviderSettings): CoderProvider {\n if (!settings.baseURL) {\n throw new Error(\n \"createCoder: `baseURL` is required (your Coder deployment URL, e.g. https://coder.example.com).\",\n );\n }\n\n const deployment = trimTrailingSlash(settings.baseURL);\n const gatewayPath = settings.aiGatewayPath ?? DEFAULT_AI_GATEWAY_PATH;\n const openaiName = settings.providers?.openai ?? DEFAULT_OPENAI_PROVIDER;\n const anthropicName = settings.providers?.anthropic ?? DEFAULT_ANTHROPIC_PROVIDER;\n\n // Both sub-providers append their route to a baseURL that INCLUDES `/v1`:\n // openai-compatible POSTs `${baseURL}/chat/completions`, and @ai-sdk/anthropic\n // POSTs `${baseURL}/messages`. AI Gateway's intercepted routes are\n // `/aibridge/<name>/v1/chat/completions` and `/aibridge/<name>/v1/messages`.\n const openaiBaseURL = `${deployment}${gatewayPath}/${openaiName}/v1`;\n const anthropicBaseURL = `${deployment}${gatewayPath}/${anthropicName}/v1`;\n\n // BYOK mode: the Coder token authenticates via a dedicated header and `apiKey`\n // carries the upstream key. Centralized mode (default): `apiKey` is the Coder\n // token itself, sent in the standard provider auth header.\n const byok = settings.coderToken !== undefined;\n const headers: Record<string, string> = {\n ...(byok ? { [CODER_TOKEN_HEADER]: settings.coderToken as string } : {}),\n ...settings.headers,\n };\n\n const openai = createOpenAICompatible({\n name: \"coder.openai\",\n baseURL: openaiBaseURL,\n apiKey: settings.apiKey, // → `Authorization: Bearer <apiKey>`\n headers,\n fetch: settings.fetch,\n includeUsage: true,\n });\n\n const anthropic = createAnthropic({\n name: \"coder.anthropic\",\n baseURL: anthropicBaseURL,\n // Centralized: send the Coder token via `Authorization: Bearer` (the\n // documented path). BYOK: send the upstream key via `x-api-key`.\n ...(byok ? { apiKey: settings.apiKey } : { authToken: settings.apiKey }),\n headers,\n fetch: settings.fetch,\n });\n\n const languageModel = (modelId: string): LanguageModelV4 =>\n isAnthropicModelId(modelId) ? anthropic(modelId) : openai(modelId);\n\n return Object.assign(languageModel, {\n languageModel,\n openai,\n anthropic,\n chat: (modelId: string): LanguageModelV4 => openai(modelId),\n messages: (modelId: string): LanguageModelV4 => anthropic(modelId),\n textEmbeddingModel: (modelId: string): EmbeddingModelV4 => openai.textEmbeddingModel(modelId),\n });\n}\n\n/** Convenience alias mirroring other AI SDK providers' `createX` naming. */\nexport const coder = createCoder;\n"],"mappings":";AAAA,SAAiC,uBAAuB;AACxD,SAAS,8BAA6D;AAItE,IAAM,0BAA0B;AAEhC,IAAM,0BAA0B;AAChC,IAAM,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AAM,CAAC,YAAqC,OAAO,OAAO;AAAA,IAC1D,UAAU,CAAC,YAAqC,UAAU,OAAO;AAAA,IACjE,oBAAoB,CAAC,YAAsC,OAAO,mBAAmB,OAAO;AAAA,EAC9F,CAAC;AACH;AAGO,IAAM,QAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/provider.ts"],"sourcesContent":["import { type AnthropicProvider, createAnthropic } from \"@ai-sdk/anthropic\";\nimport { createOpenAICompatible, type OpenAICompatibleProvider } from \"@ai-sdk/openai-compatible\";\nimport { type EmbeddingModelV4, type LanguageModelV4, NoSuchModelError } from \"@ai-sdk/provider\";\n\n/** Default mount path of AI Gateway on a Coder deployment. */\nconst DEFAULT_AI_GATEWAY_PATH = \"/api/v2/aibridge\";\n/** Default provider path segments (the admin-configured provider names). */\nconst DEFAULT_OPENAI_PROVIDER = \"openai\";\nconst DEFAULT_ANTHROPIC_PROVIDER = \"anthropic\";\n/** Header that carries the Coder token to AI Gateway in bring-your-own-key mode. */\nconst CODER_TOKEN_HEADER = \"X-Coder-AI-Governance-Token\";\n\nexport interface CoderProviderSettings {\n /**\n * Base URL of your Coder deployment, e.g. `https://coder.example.com`. Do NOT\n * include the AI Gateway path (`/api/v2/aibridge/...`) — it is appended for you.\n */\n baseURL: string;\n /**\n * The credential sent to AI Gateway.\n *\n * - **Centralized mode (default):** your **Coder API token**. AI Gateway holds\n * the upstream provider keys and brokers the call, so this is all you need.\n * - **BYOK mode** (when {@link CoderProviderSettings.coderToken} is also set):\n * your **upstream provider key**, which AI Gateway forwards to the upstream.\n */\n apiKey?: string;\n /**\n * Enables bring-your-own-key (BYOK) mode. This Coder API token is sent in the\n * `X-Coder-AI-Governance-Token` header to authenticate you to the gateway,\n * while {@link CoderProviderSettings.apiKey} carries your upstream provider key.\n * Leave unset for the default centralized mode.\n */\n coderToken?: string;\n /** Extra headers merged into every request to both surfaces. */\n headers?: Record<string, string>;\n /**\n * Mount path of AI Gateway on the deployment. Defaults to `/api/v2/aibridge`.\n * Exposed because the `aibridge` path segment may change in a future Coder\n * release (the feature was renamed \"AI Gateway\").\n */\n aiGatewayPath?: string;\n /**\n * Override the provider path segments — the *admin-configured provider names*\n * on the deployment (e.g. `anthropic-corp`). Default to `openai` / `anthropic`.\n */\n providers?: {\n openai?: string;\n anthropic?: string;\n };\n /** Custom fetch implementation (useful for testing or middleware). */\n fetch?: typeof globalThis.fetch;\n}\n\nexport interface CoderProvider {\n /** Route a model id to a surface by heuristic (Claude ids → Anthropic surface). */\n (modelId: string): LanguageModelV4;\n /** Route a model id to a surface by heuristic (Claude ids → Anthropic surface). */\n languageModel(modelId: string): LanguageModelV4;\n /**\n * AI Gateway's OpenAI-compatible surface (`/aibridge/openai/v1`). Reaches the\n * OpenAI / Azure / Google / OpenRouter / Vercel / openai-compat and Copilot\n * upstreams. Routing is by URL, so any model id sent here hits this surface.\n */\n openai: OpenAICompatibleProvider;\n /**\n * AI Gateway's Anthropic-compatible surface (`/aibridge/anthropic`). Reaches\n * native Claude and Bedrock-hosted Claude.\n */\n anthropic: AnthropicProvider;\n /** Shorthand for an {@link CoderProvider.openai} chat model. */\n chat(modelId: string): LanguageModelV4;\n /** Shorthand for an {@link CoderProvider.anthropic} messages model. */\n messages(modelId: string): LanguageModelV4;\n /**\n * Text embeddings are not supported: AI Gateway does not yet intercept\n * `/v1/embeddings`, so this always throws {@link NoSuchModelError} instead of\n * emitting a request that the gateway rejects with a 404. Tracked in\n * https://github.com/coder/ai-sdk/issues/69.\n */\n textEmbeddingModel(modelId: string): EmbeddingModelV4;\n}\n\n/**\n * Heuristic for the bare {@link CoderProvider} call: which AI Gateway surface\n * should a model id route to? Claude / Anthropic ids go to the Anthropic\n * surface; everything else to the OpenAI-compatible surface. Use the explicit\n * `.openai(id)` / `.anthropic(id)` accessors to override (e.g. to reach Claude\n * through a Copilot-typed provider on the OpenAI surface).\n */\nexport function isAnthropicModelId(modelId: string): boolean {\n return /^(?:claude|anthropic[./:])/i.test(modelId);\n}\n\nfunction trimTrailingSlash(url: string): string {\n return url.replace(/\\/+$/, \"\");\n}\n\n/**\n * Fail fast at accessor time: AI Gateway intercepts only\n * `/v1/chat/completions`, `/v1/responses`, and `/v1/messages`, so an\n * embeddings request would always die with a 404 at request time.\n */\nfunction unsupportedEmbeddingModel(modelId: string): EmbeddingModelV4 {\n throw new NoSuchModelError({\n modelId,\n modelType: \"embeddingModel\",\n message:\n `Coder AI Gateway does not yet intercept /v1/embeddings, so the ` +\n `embedding model \"${modelId}\" cannot be reached through it. ` +\n `See https://github.com/coder/ai-sdk/issues/69 for status.`,\n });\n}\n\n/**\n * Create a {@link CoderProvider} that routes Vercel AI SDK calls through a Coder\n * deployment's AI Gateway (formerly \"AI Bridge\"). AI Gateway exposes two\n * provider-namespaced surfaces; this provider fronts both and selects between\n * them per model.\n *\n * @example\n * ```ts\n * import { generateText } from \"ai\";\n * import { createCoder } from \"@coder/ai-sdk-provider\";\n *\n * const coder = createCoder({\n * baseURL: \"https://coder.example.com\",\n * apiKey: process.env.CODER_API_TOKEN!,\n * });\n *\n * await generateText({ model: coder(\"gpt-4o\"), prompt: \"Hi\" }); // OpenAI surface\n * await generateText({ model: coder(\"claude-sonnet-4-6\"), prompt: \"Hi\" }); // Anthropic surface\n * ```\n */\nexport function createCoder(settings: CoderProviderSettings): CoderProvider {\n if (!settings.baseURL) {\n throw new Error(\n \"createCoder: `baseURL` is required (your Coder deployment URL, e.g. https://coder.example.com).\",\n );\n }\n\n const deployment = trimTrailingSlash(settings.baseURL);\n const gatewayPath = settings.aiGatewayPath ?? DEFAULT_AI_GATEWAY_PATH;\n const openaiName = settings.providers?.openai ?? DEFAULT_OPENAI_PROVIDER;\n const anthropicName = settings.providers?.anthropic ?? DEFAULT_ANTHROPIC_PROVIDER;\n\n // Both sub-providers append their route to a baseURL that INCLUDES `/v1`:\n // openai-compatible POSTs `${baseURL}/chat/completions`, and @ai-sdk/anthropic\n // POSTs `${baseURL}/messages`. AI Gateway's intercepted routes are\n // `/aibridge/<name>/v1/chat/completions` and `/aibridge/<name>/v1/messages`.\n const openaiBaseURL = `${deployment}${gatewayPath}/${openaiName}/v1`;\n const anthropicBaseURL = `${deployment}${gatewayPath}/${anthropicName}/v1`;\n\n // BYOK mode: the Coder token authenticates via a dedicated header and `apiKey`\n // carries the upstream key. Centralized mode (default): `apiKey` is the Coder\n // token itself, sent in the standard provider auth header.\n const byok = settings.coderToken !== undefined;\n const headers: Record<string, string> = {\n ...(byok ? { [CODER_TOKEN_HEADER]: settings.coderToken as string } : {}),\n ...settings.headers,\n };\n\n const openai = createOpenAICompatible({\n name: \"coder.openai\",\n baseURL: openaiBaseURL,\n apiKey: settings.apiKey, // → `Authorization: Bearer <apiKey>`\n headers,\n fetch: settings.fetch,\n includeUsage: true,\n });\n\n // `coder.openai` is public, so its embedding accessors must fail fast too —\n // otherwise they bypass the top-level guard and hit the gateway 404.\n openai.embeddingModel = unsupportedEmbeddingModel;\n openai.textEmbeddingModel = unsupportedEmbeddingModel;\n\n const anthropic = createAnthropic({\n name: \"coder.anthropic\",\n baseURL: anthropicBaseURL,\n // Centralized: send the Coder token via `Authorization: Bearer` (the\n // documented path). BYOK: send the upstream key via `x-api-key`.\n ...(byok ? { apiKey: settings.apiKey } : { authToken: settings.apiKey }),\n headers,\n fetch: settings.fetch,\n });\n\n const languageModel = (modelId: string): LanguageModelV4 =>\n isAnthropicModelId(modelId) ? anthropic(modelId) : openai(modelId);\n\n return Object.assign(languageModel, {\n languageModel,\n openai,\n anthropic,\n chat: (modelId: string): LanguageModelV4 => openai(modelId),\n messages: (modelId: string): LanguageModelV4 => anthropic(modelId),\n textEmbeddingModel: unsupportedEmbeddingModel,\n });\n}\n\n/** Convenience alias mirroring other AI SDK providers' `createX` naming. */\nexport const coder = createCoder;\n"],"mappings":";AAAA,SAAiC,uBAAuB;AACxD,SAAS,8BAA6D;AACtE,SAAsD,wBAAwB;AAG9E,IAAM,0BAA0B;AAEhC,IAAM,0BAA0B;AAChC,IAAM,6BAA6B;A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ClB,CAAC;AAED,QAAM,gBAAgB,CAAC,YACrB,mBAAmB,OAAO,IAAI,UAAU,OAAO,IAAI,OAAO,OAAO;AAEnE,SAAO,OAAO,OAAO,eAAe;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,CAAC,YAAqC,OAAO,OAAO;AAAA,IAC1D,UAAU,CAAC,YAAqC,UAAU,OAAO;AAAA,IACjE,oBAAoB;AAAA,EACtB,CAAC;AACH;AAGO,IAAM,QAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coder/ai-sdk-provider",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Vercel AI SDK provider for Coder AI Gateway. Point the AI SDK at your Coder deployment with a Coder API token and use any model your deployment proxies — across AI Gateway's OpenAI- and Anthropic-compatible surfaces.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -47,20 +47,20 @@
|
|
|
47
47
|
"provenance": true
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@ai-sdk/anthropic": "^4.0.
|
|
51
|
-
"@ai-sdk/openai-compatible": "^3.0.
|
|
52
|
-
"@ai-sdk/provider": "4.0.
|
|
50
|
+
"@ai-sdk/anthropic": "^4.0.42",
|
|
51
|
+
"@ai-sdk/openai-compatible": "^3.0.37",
|
|
52
|
+
"@ai-sdk/provider": "4.0.8"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
56
56
|
"@types/node": "^26.2.0",
|
|
57
|
-
"@vitest/coverage-v8": "^4.1.
|
|
58
|
-
"ai": "^7.0.
|
|
59
|
-
"publint": "^0.3.
|
|
57
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
58
|
+
"ai": "^7.0.79",
|
|
59
|
+
"publint": "^0.3.24",
|
|
60
60
|
"tsup": "^8.5.1",
|
|
61
61
|
"tsx": "^4.23.12",
|
|
62
62
|
"typescript": "^6.0.3",
|
|
63
|
-
"vitest": "^4.1.
|
|
63
|
+
"vitest": "^4.1.11",
|
|
64
64
|
"zod": "4.4.3"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|