@neon/ai-sdk-provider 0.6.0 → 0.7.1

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 CHANGED
@@ -88,7 +88,7 @@ for await (const part of result.fullStream) {
88
88
  ## Limitations
89
89
 
90
90
  - `generateImage()` and embeddings (`embed` / `embedMany`) are not offered by the gateway and throw `NoSuchModelError`.
91
- - `gpt-oss-*` models return a non-standard ("harmony") response shape on the unified endpoint and are not fully supported.
91
+ - `gpt-oss-*` models return a non-standard ("harmony") response shape on the unified endpoint (`message.content` as an array of reasoning/text parts instead of a string). The provider normalizes this to the OpenAI Chat Completions contract (string `content` + `reasoning_content`) so `generateText`/`streamText` work and reasoning is surfaced. See neondatabase/neon-pkgs#308.
92
92
  - OpenAI Responses multi-turn tool flows (`generateText` + `stepCountIs`) can return 502 from the gateway; tool calling is covered on Anthropic/Google/Meta in e2e.
93
93
 
94
94
  ## End-to-end tests
@@ -5,7 +5,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
5
5
 
6
6
  /**
7
7
  * Language model for Anthropic models served via the Neon AI Gateway's native
8
- * Messages API (`/ai-gateway/anthropic/v1/messages`). Unlocks streaming
8
+ * Messages API (`/anthropic/v1/messages`). Unlocks streaming
9
9
  * structured output and native reasoning for Claude.
10
10
  *
11
11
  * The shared Anthropic model defaults to fine-grained tool-input streaming
@@ -2,7 +2,7 @@ import { AnthropicMessagesLanguageModel } from "@ai-sdk/anthropic/internal";
2
2
  //#region src/lib/neon-anthropic-language-model.ts
3
3
  /**
4
4
  * Language model for Anthropic models served via the Neon AI Gateway's native
5
- * Messages API (`/ai-gateway/anthropic/v1/messages`). Unlocks streaming
5
+ * Messages API (`/anthropic/v1/messages`). Unlocks streaming
6
6
  * structured output and native reasoning for Claude.
7
7
  *
8
8
  * The shared Anthropic model defaults to fine-grained tool-input streaming
@@ -1 +1 @@
1
- {"version":3,"file":"neon-anthropic-language-model.js","names":[],"sources":["../../src/lib/neon-anthropic-language-model.ts"],"sourcesContent":["import { AnthropicMessagesLanguageModel } from \"@ai-sdk/anthropic/internal\";\nimport type {\n\tLanguageModelV3,\n\tLanguageModelV3CallOptions,\n\tLanguageModelV3GenerateResult,\n\tLanguageModelV3StreamResult,\n} from \"@ai-sdk/provider\";\n\n/**\n * Language model for Anthropic models served via the Neon AI Gateway's native\n * Messages API (`/ai-gateway/anthropic/v1/messages`). Unlocks streaming\n * structured output and native reasoning for Claude.\n *\n * The shared Anthropic model defaults to fine-grained tool-input streaming\n * (`eager_input_streaming: true`) on streaming tool calls, which the gateway\n * rejects (`Extra inputs are not permitted`). We disable it via the model's own\n * `toolStreaming` option so streaming tool calls work. Users can still override.\n */\nexport class NeonAnthropicLanguageModel\n\textends AnthropicMessagesLanguageModel\n\timplements LanguageModelV3\n{\n\tprivate withGatewayCompat(\n\t\toptions: LanguageModelV3CallOptions,\n\t): LanguageModelV3CallOptions {\n\t\tconst anthropic = options.providerOptions?.anthropic;\n\t\t// Respect an explicit user setting.\n\t\tif (anthropic != null && \"toolStreaming\" in anthropic) {\n\t\t\treturn options;\n\t\t}\n\t\treturn {\n\t\t\t...options,\n\t\t\tproviderOptions: {\n\t\t\t\t...options.providerOptions,\n\t\t\t\tanthropic: { ...anthropic, toolStreaming: false },\n\t\t\t},\n\t\t};\n\t}\n\n\toverride doGenerate(\n\t\toptions: LanguageModelV3CallOptions,\n\t): Promise<LanguageModelV3GenerateResult> {\n\t\treturn super.doGenerate(this.withGatewayCompat(options));\n\t}\n\n\toverride doStream(\n\t\toptions: LanguageModelV3CallOptions,\n\t): Promise<LanguageModelV3StreamResult> {\n\t\treturn super.doStream(this.withGatewayCompat(options));\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAa,6BAAb,cACS,+BAET;CACC,kBACC,SAC6B;EAC7B,MAAM,YAAY,QAAQ,iBAAiB;EAE3C,IAAI,aAAa,QAAQ,mBAAmB,WAC3C,OAAO;EAER,OAAO;GACN,GAAG;GACH,iBAAiB;IAChB,GAAG,QAAQ;IACX,WAAW;KAAE,GAAG;KAAW,eAAe;IAAM;GACjD;EACD;CACD;CAEA,WACC,SACyC;EACzC,OAAO,MAAM,WAAW,KAAK,kBAAkB,OAAO,CAAC;CACxD;CAEA,SACC,SACuC;EACvC,OAAO,MAAM,SAAS,KAAK,kBAAkB,OAAO,CAAC;CACtD;AACD"}
1
+ {"version":3,"file":"neon-anthropic-language-model.js","names":[],"sources":["../../src/lib/neon-anthropic-language-model.ts"],"sourcesContent":["import { AnthropicMessagesLanguageModel } from \"@ai-sdk/anthropic/internal\";\nimport type {\n\tLanguageModelV3,\n\tLanguageModelV3CallOptions,\n\tLanguageModelV3GenerateResult,\n\tLanguageModelV3StreamResult,\n} from \"@ai-sdk/provider\";\n\n/**\n * Language model for Anthropic models served via the Neon AI Gateway's native\n * Messages API (`/anthropic/v1/messages`). Unlocks streaming\n * structured output and native reasoning for Claude.\n *\n * The shared Anthropic model defaults to fine-grained tool-input streaming\n * (`eager_input_streaming: true`) on streaming tool calls, which the gateway\n * rejects (`Extra inputs are not permitted`). We disable it via the model's own\n * `toolStreaming` option so streaming tool calls work. Users can still override.\n */\nexport class NeonAnthropicLanguageModel\n\textends AnthropicMessagesLanguageModel\n\timplements LanguageModelV3\n{\n\tprivate withGatewayCompat(\n\t\toptions: LanguageModelV3CallOptions,\n\t): LanguageModelV3CallOptions {\n\t\tconst anthropic = options.providerOptions?.anthropic;\n\t\t// Respect an explicit user setting.\n\t\tif (anthropic != null && \"toolStreaming\" in anthropic) {\n\t\t\treturn options;\n\t\t}\n\t\treturn {\n\t\t\t...options,\n\t\t\tproviderOptions: {\n\t\t\t\t...options.providerOptions,\n\t\t\t\tanthropic: { ...anthropic, toolStreaming: false },\n\t\t\t},\n\t\t};\n\t}\n\n\toverride doGenerate(\n\t\toptions: LanguageModelV3CallOptions,\n\t): Promise<LanguageModelV3GenerateResult> {\n\t\treturn super.doGenerate(this.withGatewayCompat(options));\n\t}\n\n\toverride doStream(\n\t\toptions: LanguageModelV3CallOptions,\n\t): Promise<LanguageModelV3StreamResult> {\n\t\treturn super.doStream(this.withGatewayCompat(options));\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAa,6BAAb,cACS,+BAET;CACC,kBACC,SAC6B;EAC7B,MAAM,YAAY,QAAQ,iBAAiB;EAE3C,IAAI,aAAa,QAAQ,mBAAmB,WAC3C,OAAO;EAER,OAAO;GACN,GAAG;GACH,iBAAiB;IAChB,GAAG,QAAQ;IACX,WAAW;KAAE,GAAG;KAAW,eAAe;IAAM;GACjD;EACD;CACD;CAEA,WACC,SACyC;EACzC,OAAO,MAAM,WAAW,KAAK,kBAAkB,OAAO,CAAC;CACxD;CAEA,SACC,SACuC;EACvC,OAAO,MAAM,SAAS,KAAK,kBAAkB,OAAO,CAAC;CACtD;AACD"}
@@ -0,0 +1,41 @@
1
+ import { FetchFunction } from "@ai-sdk/provider-utils";
2
+
3
+ //#region src/lib/neon-harmony-normalize.d.ts
4
+ interface ExtractedHarmony {
5
+ text: string;
6
+ reasoning: string;
7
+ }
8
+ /** The result of a normalization pass, flagging whether anything was rewritten. */
9
+ interface NormalizeResult {
10
+ body: unknown;
11
+ changed: boolean;
12
+ }
13
+ /**
14
+ * Pull the text and reasoning out of a harmony `content` array. Returns `null`
15
+ * when `content` is not an array (i.e. an already-compliant string response),
16
+ * signalling that no rewrite is needed.
17
+ */
18
+ declare function extractHarmonyContent(content: unknown): ExtractedHarmony | null;
19
+ /**
20
+ * Rewrite a non-streaming `chat.completion` body in place. `changed` is false
21
+ * when the body was already compliant (no harmony array found).
22
+ */
23
+ declare function normalizeCompletionBody(body: unknown): NormalizeResult;
24
+ /**
25
+ * Rewrite a streaming `chat.completion.chunk` body in place. `changed` is false
26
+ * when the chunk was already compliant (no harmony array found).
27
+ */
28
+ declare function normalizeChunkBody(body: unknown): NormalizeResult;
29
+ /**
30
+ * Wrap a fetch implementation so gpt-oss harmony responses are normalized to
31
+ * the OpenAI Chat Completions shape before the caller parses them. Composes
32
+ * with a user-supplied `fetch` (falls back to the global `fetch`).
33
+ *
34
+ * When the response is already compliant, the original response is returned
35
+ * untouched — a transparent pass-through that will not interfere once the
36
+ * gateway is fixed.
37
+ */
38
+ declare function wrapFetchWithHarmonyNormalization(baseFetch?: FetchFunction): FetchFunction;
39
+ //#endregion
40
+ export { extractHarmonyContent, normalizeChunkBody, normalizeCompletionBody, wrapFetchWithHarmonyNormalization };
41
+ //# sourceMappingURL=neon-harmony-normalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"neon-harmony-normalize.d.ts","names":[],"sources":["../../src/lib/neon-harmony-normalize.ts"],"mappings":";;;UAwCU,gBAAA;;EAAA,SAAA,EAAA,MAAA;AAAgB;AAgB1B;AAkDA,UA5DU,eAAA,CA4DM;EAkCA,IAAA,EAAA,OAAA;EAuGA,OAAA,EAAA,OAAA;;;;AAEA;;;iBA7LA,qBAAA,oBAEb;;;;;iBAgDa,uBAAA,iBAAwC;;;;;iBAkCxC,kBAAA,iBAAmC;;;;;;;;;;iBAuGnC,iCAAA,aACH,gBACV"}
@@ -0,0 +1,198 @@
1
+ //#region src/lib/neon-harmony-normalize.ts
2
+ /**
3
+ * Normalize the Neon AI Gateway's non-OpenAI-compliant `gpt-oss` ("harmony")
4
+ * response shape into the OpenAI Chat Completions contract before it reaches
5
+ * the AI SDK's schema validation.
6
+ *
7
+ * For `gpt-oss-*` the gateway returns `message.content` (and streaming
8
+ * `delta.content`) as an array of Responses-style parts:
9
+ *
10
+ * "content": [
11
+ * { "type": "reasoning", "summary": [{ "type": "summary_text", "text": "…" }] },
12
+ * { "type": "text", "text": "…" }
13
+ * ]
14
+ *
15
+ * The Chat Completions spec requires `content` to be a string, so any strict
16
+ * OpenAI-compatible client (incl. the Vercel AI SDK) rejects it. We flatten the
17
+ * `text` parts into the string `content` and hoist reasoning into
18
+ * `reasoning_content` (which `@ai-sdk/openai-compatible` already surfaces as an
19
+ * AI SDK reasoning part).
20
+ *
21
+ * The transform only rewrites when `content` is an array, and the fetch wrapper
22
+ * returns the response untouched when nothing was rewritten. So it is a true
23
+ * no-op / pass-through for every spec-compliant model (Llama, Gemini, Qwen, …)
24
+ * and self-retires the moment the gateway starts returning a compliant shape —
25
+ * it will not double-transform or otherwise interfere with the downstream fix.
26
+ *
27
+ * See neondatabase/neon-pkgs#308.
28
+ */
29
+ function isRecord(value) {
30
+ return typeof value === "object" && value !== null && !Array.isArray(value);
31
+ }
32
+ /**
33
+ * Pull the text and reasoning out of a harmony `content` array. Returns `null`
34
+ * when `content` is not an array (i.e. an already-compliant string response),
35
+ * signalling that no rewrite is needed.
36
+ */
37
+ function extractHarmonyContent(content) {
38
+ if (!Array.isArray(content)) return null;
39
+ const texts = [];
40
+ const reasonings = [];
41
+ for (const part of content) {
42
+ if (!isRecord(part)) continue;
43
+ if (part.type === "text") {
44
+ if (typeof part.text === "string") texts.push(part.text);
45
+ continue;
46
+ }
47
+ if (part.type === "reasoning") {
48
+ if (typeof part.text === "string") reasonings.push(part.text);
49
+ if (Array.isArray(part.summary)) {
50
+ for (const entry of part.summary) if (isRecord(entry) && typeof entry.text === "string") reasonings.push(entry.text);
51
+ }
52
+ if (Array.isArray(part.content)) {
53
+ for (const entry of part.content) if (isRecord(entry) && typeof entry.text === "string") reasonings.push(entry.text);
54
+ }
55
+ }
56
+ }
57
+ return {
58
+ text: texts.join(""),
59
+ reasoning: reasonings.join("\n")
60
+ };
61
+ }
62
+ /**
63
+ * Rewrite a non-streaming `chat.completion` body in place. `changed` is false
64
+ * when the body was already compliant (no harmony array found).
65
+ */
66
+ function normalizeCompletionBody(body) {
67
+ if (!isRecord(body) || !Array.isArray(body.choices)) return {
68
+ body,
69
+ changed: false
70
+ };
71
+ let changed = false;
72
+ for (const choice of body.choices) {
73
+ if (!isRecord(choice)) continue;
74
+ const message = choice.message;
75
+ if (!isRecord(message)) continue;
76
+ const extracted = extractHarmonyContent(message.content);
77
+ if (extracted === null) continue;
78
+ message.content = extracted.text;
79
+ changed = true;
80
+ if (extracted.reasoning.length > 0 && message.reasoning_content == null && message.reasoning == null) message.reasoning_content = extracted.reasoning;
81
+ }
82
+ return {
83
+ body,
84
+ changed
85
+ };
86
+ }
87
+ /**
88
+ * Rewrite a streaming `chat.completion.chunk` body in place. `changed` is false
89
+ * when the chunk was already compliant (no harmony array found).
90
+ */
91
+ function normalizeChunkBody(body) {
92
+ if (!isRecord(body) || !Array.isArray(body.choices)) return {
93
+ body,
94
+ changed: false
95
+ };
96
+ let changed = false;
97
+ for (const choice of body.choices) {
98
+ if (!isRecord(choice)) continue;
99
+ const delta = choice.delta;
100
+ if (!isRecord(delta)) continue;
101
+ const extracted = extractHarmonyContent(delta.content);
102
+ if (extracted === null) continue;
103
+ changed = true;
104
+ if (extracted.text.length > 0) delta.content = extracted.text;
105
+ else delta.content = void 0;
106
+ if (extracted.reasoning.length > 0 && delta.reasoning_content == null && delta.reasoning == null) delta.reasoning_content = extracted.reasoning;
107
+ }
108
+ return {
109
+ body,
110
+ changed
111
+ };
112
+ }
113
+ /**
114
+ * Rewrite each `data:` frame of an SSE stream. Compliant frames pass through
115
+ * verbatim; only harmony frames are re-serialized.
116
+ */
117
+ function normalizeEventStream(body) {
118
+ const decoder = new TextDecoder();
119
+ const encoder = new TextEncoder();
120
+ let buffer = "";
121
+ const rewriteLine = (line) => {
122
+ if (!line.startsWith("data:")) return line;
123
+ const payload = line.slice(5).trim();
124
+ if (payload === "" || payload === "[DONE]") return line;
125
+ let parsed;
126
+ try {
127
+ parsed = JSON.parse(payload);
128
+ } catch {
129
+ return line;
130
+ }
131
+ const { body: normalized, changed } = normalizeChunkBody(parsed);
132
+ return changed ? `data: ${JSON.stringify(normalized)}` : line;
133
+ };
134
+ return body.pipeThrough(new TransformStream({
135
+ transform(chunk, controller) {
136
+ buffer += decoder.decode(chunk, { stream: true });
137
+ const lines = buffer.split("\n");
138
+ buffer = lines.pop() ?? "";
139
+ for (const line of lines) controller.enqueue(encoder.encode(`${rewriteLine(line)}\n`));
140
+ },
141
+ flush(controller) {
142
+ if (buffer.length > 0) controller.enqueue(encoder.encode(rewriteLine(buffer)));
143
+ }
144
+ }));
145
+ }
146
+ function headersWithout(source, ...names) {
147
+ const copy = new Headers(source);
148
+ for (const name of names) copy.delete(name);
149
+ return copy;
150
+ }
151
+ /**
152
+ * Wrap a fetch implementation so gpt-oss harmony responses are normalized to
153
+ * the OpenAI Chat Completions shape before the caller parses them. Composes
154
+ * with a user-supplied `fetch` (falls back to the global `fetch`).
155
+ *
156
+ * When the response is already compliant, the original response is returned
157
+ * untouched — a transparent pass-through that will not interfere once the
158
+ * gateway is fixed.
159
+ */
160
+ function wrapFetchWithHarmonyNormalization(baseFetch) {
161
+ const doFetch = baseFetch ?? ((input, init) => globalThis.fetch(input, init));
162
+ return async (input, init) => {
163
+ const response = await doFetch(input, init);
164
+ if (!response.ok || response.body === null) return response;
165
+ const contentType = response.headers.get("content-type") ?? "";
166
+ if (contentType.includes("text/event-stream")) return new Response(normalizeEventStream(response.body), {
167
+ status: response.status,
168
+ statusText: response.statusText,
169
+ headers: headersWithout(response.headers, "content-length", "content-encoding")
170
+ });
171
+ if (contentType.includes("application/json")) {
172
+ let text;
173
+ try {
174
+ text = await response.clone().text();
175
+ } catch {
176
+ return response;
177
+ }
178
+ let parsed;
179
+ try {
180
+ parsed = JSON.parse(text);
181
+ } catch {
182
+ return response;
183
+ }
184
+ const { body: normalized, changed } = normalizeCompletionBody(parsed);
185
+ if (!changed) return response;
186
+ return new Response(JSON.stringify(normalized), {
187
+ status: response.status,
188
+ statusText: response.statusText,
189
+ headers: headersWithout(response.headers, "content-length", "content-encoding")
190
+ });
191
+ }
192
+ return response;
193
+ };
194
+ }
195
+ //#endregion
196
+ export { extractHarmonyContent, normalizeChunkBody, normalizeCompletionBody, wrapFetchWithHarmonyNormalization };
197
+
198
+ //# sourceMappingURL=neon-harmony-normalize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"neon-harmony-normalize.js","names":[],"sources":["../../src/lib/neon-harmony-normalize.ts"],"sourcesContent":["import type { FetchFunction } from \"@ai-sdk/provider-utils\";\n\n// TODO(#308): Temporary workaround. Remove this whole module (and its wiring in\n// provider.ts) once the Neon AI Gateway returns Chat Completions-compliant\n// gpt-oss responses (string `content` + `reasoning_content`). The wrapper is a\n// transparent pass-through for any already-compliant response, so it is safe to\n// leave in place until the gateway fix ships — but it should be deleted then.\n\n/**\n * Normalize the Neon AI Gateway's non-OpenAI-compliant `gpt-oss` (\"harmony\")\n * response shape into the OpenAI Chat Completions contract before it reaches\n * the AI SDK's schema validation.\n *\n * For `gpt-oss-*` the gateway returns `message.content` (and streaming\n * `delta.content`) as an array of Responses-style parts:\n *\n * \"content\": [\n * { \"type\": \"reasoning\", \"summary\": [{ \"type\": \"summary_text\", \"text\": \"…\" }] },\n * { \"type\": \"text\", \"text\": \"…\" }\n * ]\n *\n * The Chat Completions spec requires `content` to be a string, so any strict\n * OpenAI-compatible client (incl. the Vercel AI SDK) rejects it. We flatten the\n * `text` parts into the string `content` and hoist reasoning into\n * `reasoning_content` (which `@ai-sdk/openai-compatible` already surfaces as an\n * AI SDK reasoning part).\n *\n * The transform only rewrites when `content` is an array, and the fetch wrapper\n * returns the response untouched when nothing was rewritten. So it is a true\n * no-op / pass-through for every spec-compliant model (Llama, Gemini, Qwen, …)\n * and self-retires the moment the gateway starts returning a compliant shape —\n * it will not double-transform or otherwise interfere with the downstream fix.\n *\n * See neondatabase/neon-pkgs#308.\n */\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\ninterface ExtractedHarmony {\n\ttext: string;\n\treasoning: string;\n}\n\n/** The result of a normalization pass, flagging whether anything was rewritten. */\ninterface NormalizeResult {\n\tbody: unknown;\n\tchanged: boolean;\n}\n\n/**\n * Pull the text and reasoning out of a harmony `content` array. Returns `null`\n * when `content` is not an array (i.e. an already-compliant string response),\n * signalling that no rewrite is needed.\n */\nexport function extractHarmonyContent(\n\tcontent: unknown,\n): ExtractedHarmony | null {\n\tif (!Array.isArray(content)) {\n\t\treturn null;\n\t}\n\n\tconst texts: string[] = [];\n\tconst reasonings: string[] = [];\n\n\tfor (const part of content) {\n\t\tif (!isRecord(part)) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (part.type === \"text\") {\n\t\t\tif (typeof part.text === \"string\") {\n\t\t\t\ttexts.push(part.text);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (part.type === \"reasoning\") {\n\t\t\t// Reasoning items can carry the raw CoT in `text`, a `summary[]` of\n\t\t\t// `summary_text` parts, and/or a `content[]` of `reasoning_text` parts.\n\t\t\tif (typeof part.text === \"string\") {\n\t\t\t\treasonings.push(part.text);\n\t\t\t}\n\t\t\tif (Array.isArray(part.summary)) {\n\t\t\t\tfor (const entry of part.summary) {\n\t\t\t\t\tif (isRecord(entry) && typeof entry.text === \"string\") {\n\t\t\t\t\t\treasonings.push(entry.text);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Array.isArray(part.content)) {\n\t\t\t\tfor (const entry of part.content) {\n\t\t\t\t\tif (isRecord(entry) && typeof entry.text === \"string\") {\n\t\t\t\t\t\treasonings.push(entry.text);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { text: texts.join(\"\"), reasoning: reasonings.join(\"\\n\") };\n}\n\n/**\n * Rewrite a non-streaming `chat.completion` body in place. `changed` is false\n * when the body was already compliant (no harmony array found).\n */\nexport function normalizeCompletionBody(body: unknown): NormalizeResult {\n\tif (!isRecord(body) || !Array.isArray(body.choices)) {\n\t\treturn { body, changed: false };\n\t}\n\tlet changed = false;\n\tfor (const choice of body.choices) {\n\t\tif (!isRecord(choice)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst message = choice.message;\n\t\tif (!isRecord(message)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst extracted = extractHarmonyContent(message.content);\n\t\tif (extracted === null) {\n\t\t\tcontinue;\n\t\t}\n\t\tmessage.content = extracted.text;\n\t\tchanged = true;\n\t\tif (\n\t\t\textracted.reasoning.length > 0 &&\n\t\t\tmessage.reasoning_content == null &&\n\t\t\tmessage.reasoning == null\n\t\t) {\n\t\t\tmessage.reasoning_content = extracted.reasoning;\n\t\t}\n\t}\n\treturn { body, changed };\n}\n\n/**\n * Rewrite a streaming `chat.completion.chunk` body in place. `changed` is false\n * when the chunk was already compliant (no harmony array found).\n */\nexport function normalizeChunkBody(body: unknown): NormalizeResult {\n\tif (!isRecord(body) || !Array.isArray(body.choices)) {\n\t\treturn { body, changed: false };\n\t}\n\tlet changed = false;\n\tfor (const choice of body.choices) {\n\t\tif (!isRecord(choice)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst delta = choice.delta;\n\t\tif (!isRecord(delta)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst extracted = extractHarmonyContent(delta.content);\n\t\tif (extracted === null) {\n\t\t\tcontinue;\n\t\t}\n\t\tchanged = true;\n\t\t// Drop empty text so reasoning-only chunks don't emit spurious text deltas.\n\t\tif (extracted.text.length > 0) {\n\t\t\tdelta.content = extracted.text;\n\t\t} else {\n\t\t\tdelta.content = undefined;\n\t\t}\n\t\tif (\n\t\t\textracted.reasoning.length > 0 &&\n\t\t\tdelta.reasoning_content == null &&\n\t\t\tdelta.reasoning == null\n\t\t) {\n\t\t\tdelta.reasoning_content = extracted.reasoning;\n\t\t}\n\t}\n\treturn { body, changed };\n}\n\n/**\n * Rewrite each `data:` frame of an SSE stream. Compliant frames pass through\n * verbatim; only harmony frames are re-serialized.\n */\nfunction normalizeEventStream(\n\tbody: ReadableStream<Uint8Array>,\n): ReadableStream<Uint8Array> {\n\tconst decoder = new TextDecoder();\n\tconst encoder = new TextEncoder();\n\tlet buffer = \"\";\n\n\tconst rewriteLine = (line: string): string => {\n\t\tif (!line.startsWith(\"data:\")) {\n\t\t\treturn line;\n\t\t}\n\t\tconst payload = line.slice(\"data:\".length).trim();\n\t\tif (payload === \"\" || payload === \"[DONE]\") {\n\t\t\treturn line;\n\t\t}\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(payload);\n\t\t} catch {\n\t\t\treturn line;\n\t\t}\n\t\tconst { body: normalized, changed } = normalizeChunkBody(parsed);\n\t\t// Pass compliant frames through unchanged so we don't reshape a fixed gateway.\n\t\treturn changed ? `data: ${JSON.stringify(normalized)}` : line;\n\t};\n\n\treturn body.pipeThrough(\n\t\tnew TransformStream<Uint8Array, Uint8Array>({\n\t\t\ttransform(chunk, controller) {\n\t\t\t\tbuffer += decoder.decode(chunk, { stream: true });\n\t\t\t\tconst lines = buffer.split(\"\\n\");\n\t\t\t\tbuffer = lines.pop() ?? \"\";\n\t\t\t\tfor (const line of lines) {\n\t\t\t\t\tcontroller.enqueue(\n\t\t\t\t\t\tencoder.encode(`${rewriteLine(line)}\\n`),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t\tflush(controller) {\n\t\t\t\tif (buffer.length > 0) {\n\t\t\t\t\tcontroller.enqueue(encoder.encode(rewriteLine(buffer)));\n\t\t\t\t}\n\t\t\t},\n\t\t}),\n\t);\n}\n\nfunction headersWithout(source: Headers, ...names: string[]): Headers {\n\tconst copy = new Headers(source);\n\tfor (const name of names) {\n\t\tcopy.delete(name);\n\t}\n\treturn copy;\n}\n\n/**\n * Wrap a fetch implementation so gpt-oss harmony responses are normalized to\n * the OpenAI Chat Completions shape before the caller parses them. Composes\n * with a user-supplied `fetch` (falls back to the global `fetch`).\n *\n * When the response is already compliant, the original response is returned\n * untouched — a transparent pass-through that will not interfere once the\n * gateway is fixed.\n */\nexport function wrapFetchWithHarmonyNormalization(\n\tbaseFetch?: FetchFunction,\n): FetchFunction {\n\tconst doFetch: FetchFunction =\n\t\tbaseFetch ?? ((input, init) => globalThis.fetch(input, init));\n\n\treturn async (input, init) => {\n\t\tconst response = await doFetch(input, init);\n\t\tif (!response.ok || response.body === null) {\n\t\t\treturn response;\n\t\t}\n\t\tconst contentType = response.headers.get(\"content-type\") ?? \"\";\n\n\t\tif (contentType.includes(\"text/event-stream\")) {\n\t\t\t// Streaming is inspected frame-by-frame; compliant frames pass through\n\t\t\t// verbatim (see normalizeEventStream).\n\t\t\treturn new Response(normalizeEventStream(response.body), {\n\t\t\t\tstatus: response.status,\n\t\t\t\tstatusText: response.statusText,\n\t\t\t\t// content-length/encoding no longer describe the (possibly) rewritten body.\n\t\t\t\theaders: headersWithout(\n\t\t\t\t\tresponse.headers,\n\t\t\t\t\t\"content-length\",\n\t\t\t\t\t\"content-encoding\",\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\n\t\tif (contentType.includes(\"application/json\")) {\n\t\t\t// Inspect a clone so the original body stays intact for the pass-through case.\n\t\t\tlet text: string;\n\t\t\ttry {\n\t\t\t\ttext = await response.clone().text();\n\t\t\t} catch {\n\t\t\t\treturn response;\n\t\t\t}\n\t\t\tlet parsed: unknown;\n\t\t\ttry {\n\t\t\t\tparsed = JSON.parse(text);\n\t\t\t} catch {\n\t\t\t\treturn response;\n\t\t\t}\n\t\t\tconst { body: normalized, changed } =\n\t\t\t\tnormalizeCompletionBody(parsed);\n\t\t\tif (!changed) {\n\t\t\t\t// Already compliant: return the original response untouched.\n\t\t\t\treturn response;\n\t\t\t}\n\t\t\treturn new Response(JSON.stringify(normalized), {\n\t\t\t\tstatus: response.status,\n\t\t\t\tstatusText: response.statusText,\n\t\t\t\theaders: headersWithout(\n\t\t\t\t\tresponse.headers,\n\t\t\t\t\t\"content-length\",\n\t\t\t\t\t\"content-encoding\",\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\n\t\treturn response;\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAS,SAAS,OAAkD;CACnE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC3E;;;;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AAU,UAAU,GAAG;IAC/C,QAAQ,SAAS;IACjB,YAAY,SAAS;IACrB,SAAS,eACR,SAAS,SACT,kBACA,kBACD;GACD,CAAC;EACF;EAEA,OAAO;CACR;AACD"}
@@ -5,7 +5,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
5
5
 
6
6
  /**
7
7
  * Language model for OpenAI models served via the Neon AI Gateway's native
8
- * Responses API (`/ai-gateway/openai/v1/responses`). This route is required for
8
+ * Responses API (`/openai/v1/responses`). This route is required for
9
9
  * models that are only served natively (e.g. Codex) and unlocks native
10
10
  * reasoning and the image-generation tool.
11
11
  *
@@ -2,7 +2,7 @@ import { OpenAIResponsesLanguageModel } from "@ai-sdk/openai/internal";
2
2
  //#region src/lib/neon-responses-language-model.ts
3
3
  /**
4
4
  * Language model for OpenAI models served via the Neon AI Gateway's native
5
- * Responses API (`/ai-gateway/openai/v1/responses`). This route is required for
5
+ * Responses API (`/openai/v1/responses`). This route is required for
6
6
  * models that are only served natively (e.g. Codex) and unlocks native
7
7
  * reasoning and the image-generation tool.
8
8
  *
@@ -1 +1 @@
1
- {"version":3,"file":"neon-responses-language-model.js","names":[],"sources":["../../src/lib/neon-responses-language-model.ts"],"sourcesContent":["import { OpenAIResponsesLanguageModel } from \"@ai-sdk/openai/internal\";\nimport type {\n\tLanguageModelV3,\n\tLanguageModelV3CallOptions,\n\tLanguageModelV3GenerateResult,\n\tLanguageModelV3StreamResult,\n} from \"@ai-sdk/provider\";\n\n/**\n * Language model for OpenAI models served via the Neon AI Gateway's native\n * Responses API (`/ai-gateway/openai/v1/responses`). This route is required for\n * models that are only served natively (e.g. Codex) and unlocks native\n * reasoning and the image-generation tool.\n *\n * The shared OpenAI Responses model shapes a request based on whether the model\n * is a reasoning model, but its detection is brittle here: the gateway also\n * accepts the legacy `databricks-` prefix, which defeats the upstream bare-id\n * (`gpt-5`) match. For the GPT-5 reasoning family we set the model's own\n * `forceReasoning` provider option so it applies the correct reasoning behavior\n * for both id forms. Users can still override it.\n */\nexport class NeonResponsesLanguageModel\n\textends OpenAIResponsesLanguageModel\n\timplements LanguageModelV3\n{\n\tprivate get isReasoningFamily(): boolean {\n\t\treturn /gpt-5/.test(this.modelId.toLowerCase());\n\t}\n\n\tprivate withForcedReasoning(\n\t\toptions: LanguageModelV3CallOptions,\n\t): LanguageModelV3CallOptions {\n\t\tif (!this.isReasoningFamily) {\n\t\t\treturn options;\n\t\t}\n\t\tconst openai = options.providerOptions?.openai;\n\t\t// Respect an explicit user setting.\n\t\tif (openai != null && \"forceReasoning\" in openai) {\n\t\t\treturn options;\n\t\t}\n\t\treturn {\n\t\t\t...options,\n\t\t\tproviderOptions: {\n\t\t\t\t...options.providerOptions,\n\t\t\t\topenai: { ...openai, forceReasoning: true },\n\t\t\t},\n\t\t};\n\t}\n\n\toverride doGenerate(\n\t\toptions: LanguageModelV3CallOptions,\n\t): Promise<LanguageModelV3GenerateResult> {\n\t\treturn super.doGenerate(this.withForcedReasoning(options));\n\t}\n\n\toverride doStream(\n\t\toptions: LanguageModelV3CallOptions,\n\t): Promise<LanguageModelV3StreamResult> {\n\t\treturn super.doStream(this.withForcedReasoning(options));\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,IAAa,6BAAb,cACS,6BAET;CACC,IAAY,oBAA6B;EACxC,OAAO,QAAQ,KAAK,KAAK,QAAQ,YAAY,CAAC;CAC/C;CAEA,oBACC,SAC6B;EAC7B,IAAI,CAAC,KAAK,mBACT,OAAO;EAER,MAAM,SAAS,QAAQ,iBAAiB;EAExC,IAAI,UAAU,QAAQ,oBAAoB,QACzC,OAAO;EAER,OAAO;GACN,GAAG;GACH,iBAAiB;IAChB,GAAG,QAAQ;IACX,QAAQ;KAAE,GAAG;KAAQ,gBAAgB;IAAK;GAC3C;EACD;CACD;CAEA,WACC,SACyC;EACzC,OAAO,MAAM,WAAW,KAAK,oBAAoB,OAAO,CAAC;CAC1D;CAEA,SACC,SACuC;EACvC,OAAO,MAAM,SAAS,KAAK,oBAAoB,OAAO,CAAC;CACxD;AACD"}
1
+ {"version":3,"file":"neon-responses-language-model.js","names":[],"sources":["../../src/lib/neon-responses-language-model.ts"],"sourcesContent":["import { OpenAIResponsesLanguageModel } from \"@ai-sdk/openai/internal\";\nimport type {\n\tLanguageModelV3,\n\tLanguageModelV3CallOptions,\n\tLanguageModelV3GenerateResult,\n\tLanguageModelV3StreamResult,\n} from \"@ai-sdk/provider\";\n\n/**\n * Language model for OpenAI models served via the Neon AI Gateway's native\n * Responses API (`/openai/v1/responses`). This route is required for\n * models that are only served natively (e.g. Codex) and unlocks native\n * reasoning and the image-generation tool.\n *\n * The shared OpenAI Responses model shapes a request based on whether the model\n * is a reasoning model, but its detection is brittle here: the gateway also\n * accepts the legacy `databricks-` prefix, which defeats the upstream bare-id\n * (`gpt-5`) match. For the GPT-5 reasoning family we set the model's own\n * `forceReasoning` provider option so it applies the correct reasoning behavior\n * for both id forms. Users can still override it.\n */\nexport class NeonResponsesLanguageModel\n\textends OpenAIResponsesLanguageModel\n\timplements LanguageModelV3\n{\n\tprivate get isReasoningFamily(): boolean {\n\t\treturn /gpt-5/.test(this.modelId.toLowerCase());\n\t}\n\n\tprivate withForcedReasoning(\n\t\toptions: LanguageModelV3CallOptions,\n\t): LanguageModelV3CallOptions {\n\t\tif (!this.isReasoningFamily) {\n\t\t\treturn options;\n\t\t}\n\t\tconst openai = options.providerOptions?.openai;\n\t\t// Respect an explicit user setting.\n\t\tif (openai != null && \"forceReasoning\" in openai) {\n\t\t\treturn options;\n\t\t}\n\t\treturn {\n\t\t\t...options,\n\t\t\tproviderOptions: {\n\t\t\t\t...options.providerOptions,\n\t\t\t\topenai: { ...openai, forceReasoning: true },\n\t\t\t},\n\t\t};\n\t}\n\n\toverride doGenerate(\n\t\toptions: LanguageModelV3CallOptions,\n\t): Promise<LanguageModelV3GenerateResult> {\n\t\treturn super.doGenerate(this.withForcedReasoning(options));\n\t}\n\n\toverride doStream(\n\t\toptions: LanguageModelV3CallOptions,\n\t): Promise<LanguageModelV3StreamResult> {\n\t\treturn super.doStream(this.withForcedReasoning(options));\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,IAAa,6BAAb,cACS,6BAET;CACC,IAAY,oBAA6B;EACxC,OAAO,QAAQ,KAAK,KAAK,QAAQ,YAAY,CAAC;CAC/C;CAEA,oBACC,SAC6B;EAC7B,IAAI,CAAC,KAAK,mBACT,OAAO;EAER,MAAM,SAAS,QAAQ,iBAAiB;EAExC,IAAI,UAAU,QAAQ,oBAAoB,QACzC,OAAO;EAER,OAAO;GACN,GAAG;GACH,iBAAiB;IAChB,GAAG,QAAQ;IACX,QAAQ;KAAE,GAAG;KAAQ,gBAAgB;IAAK;GAC3C;EACD;CACD;CAEA,WACC,SACyC;EACzC,OAAO,MAAM,WAAW,KAAK,oBAAoB,OAAO,CAAC;CAC1D;CAEA,SACC,SACuC;EACvC,OAAO,MAAM,SAAS,KAAK,oBAAoB,OAAO,CAAC;CACxD;AACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","names":[],"sources":["../../src/lib/provider.ts"],"mappings":";;;;;;;;cAmCM,iBAAe,CAAA,CAAA;;;;;IAAA,IAAA,eAAA,cAAA,aAAA,CAAA,CAAA;EAAA,CAAA,eAAA,CAAA;AASrB,CAAA,eAAY,CAAA;AAAa,KAAb,aAAA,GAAgB,CAAA,CAAE,KAAL,CAAA,OAAkB,eAAlB,CAAA;AAAkB,UA4C1B,oBAAA,CA5C0B;;AAAR;AA4CnC;;;SAkBS,CAAA,EAAA,MAAA;EAAa;AAGtB;;;QAE6B,CAAA,EAAA,MAAA;;SAGa,CAAA,EAX/B,MAW+B,CAAA,MAAA,EAAA,MAAA,CAAA;;OAGT,CAAA,EAXxB,aAWwB;;AARK,UAArB,YAAA,SAAqB,UAAA,CAAA;EAAU;EAiBhC,CAAA,OAAA,EAfL,eAee,CAAA,EAfG,eAeH;EAAA;eAAU,CAAA,OAAA,EAZZ,eAYY,CAAA,EAZM,eAYN;;EAAwC,IAAA,CAAA,OAAA,EAT7D,eAS6D,CAAA,EAT3C,eAS2C;EA0F/D;gBAhGE,MAAA,CAAe;;;;iBAMd,UAAA,WAAoB,uBAA4B;;cA0FnD,MAAI"}
1
+ {"version":3,"file":"provider.d.ts","names":[],"sources":["../../src/lib/provider.ts"],"mappings":";;;;;;;;cAoCM,iBAAe,CAAA,CAAA;;;;;IAAA,IAAA,eAAA,cAAA,aAAA,CAAA,CAAA;EAAA,CAAA,eAAA,CAAA;AASrB,CAAA,eAAY,CAAA;AAAa,KAAb,aAAA,GAAgB,CAAA,CAAE,KAAL,CAAA,OAAkB,eAAlB,CAAA;AAAkB,UA4C1B,oBAAA,CA5C0B;;AAAR;AA4CnC;;;SAkBS,CAAA,EAAA,MAAA;EAAa;AAGtB;;;QAE6B,CAAA,EAAA,MAAA;;SAGa,CAAA,EAX/B,MAW+B,CAAA,MAAA,EAAA,MAAA,CAAA;;OAGT,CAAA,EAXxB,aAWwB;;AARK,UAArB,YAAA,SAAqB,UAAA,CAAA;EAAU;EAiBhC,CAAA,OAAA,EAfL,eAee,CAAA,EAfG,eAeH;EAAA;eAAU,CAAA,OAAA,EAZZ,eAYY,CAAA,EAZM,eAYN;;EAAwC,IAAA,CAAA,OAAA,EAT7D,eAS6D,CAAA,EAT3C,eAS2C;EA+F/D;gBArGE,MAAA,CAAe;;;;iBAMd,UAAA,WAAoB,uBAA4B;;cA+FnD,MAAI"}
@@ -2,6 +2,7 @@ import { NeonAnthropicLanguageModel } from "./neon-anthropic-language-model.js";
2
2
  import { getNeonModelRoute } from "./neon-model-capabilities.js";
3
3
  import { NeonChatLanguageModel } from "./neon-chat-language-model.js";
4
4
  import { NeonResponsesLanguageModel } from "./neon-responses-language-model.js";
5
+ import { wrapFetchWithHarmonyNormalization } from "./neon-harmony-normalize.js";
5
6
  import { VERSION } from "./version.js";
6
7
  import { openai } from "@ai-sdk/openai";
7
8
  import { NoSuchModelError } from "@ai-sdk/provider";
@@ -13,7 +14,7 @@ import { z } from "zod/v4";
13
14
  *
14
15
  * `createNeon()` returns a provider that routes each model to the best gateway
15
16
  * endpoint based on its id (Anthropic → native Messages, OpenAI → native
16
- * Responses incl. Codex, everything else → unified MLflow), so a single
17
+ * Responses incl. Codex, everything else → unified Chat Completions), so a single
17
18
  * `neon('claude-...')` call (same base URL + token) reaches the whole catalog.
18
19
  * Ids use the canonical Neon (unprefixed) form; the legacy `databricks-` prefix
19
20
  * is also accepted. Configure with the branch-scoped `NEON_AI_GATEWAY_BASE_URL` +
@@ -70,23 +71,23 @@ function createNeon(options = {}) {
70
71
  }, `neondatabase/ai-sdk-provider/${VERSION}`);
71
72
  const createAnthropicModel = (modelId) => new NeonAnthropicLanguageModel(modelId, {
72
73
  provider: "neon.anthropic",
73
- baseURL: `${getHost()}/ai-gateway/anthropic/v1`,
74
+ baseURL: `${getHost()}/anthropic/v1`,
74
75
  headers: () => getHeaders({ "anthropic-version": "2023-06-01" }),
75
76
  fetch: options.fetch,
76
77
  generateId
77
78
  });
78
79
  const createOpenAIModel = (modelId) => new NeonResponsesLanguageModel(modelId, {
79
80
  provider: "neon.openai.responses",
80
- url: ({ path }) => `${getHost()}/ai-gateway/openai/v1${path}`,
81
+ url: ({ path }) => `${getHost()}/openai/v1${path}`,
81
82
  headers: getHeaders,
82
83
  fetch: options.fetch,
83
84
  fileIdPrefixes: ["file-"]
84
85
  });
85
86
  const createChatModel = (modelId) => new NeonChatLanguageModel(modelId, {
86
87
  provider: "neon.chat",
87
- url: ({ path }) => `${getHost()}/ai-gateway/mlflow/v1${path}`,
88
+ url: ({ path }) => `${getHost()}/v1${path}`,
88
89
  headers: getHeaders,
89
- fetch: options.fetch,
90
+ fetch: wrapFetchWithHarmonyNormalization(options.fetch),
90
91
  errorStructure: neonErrorStructure,
91
92
  transformRequestBody: transformNeonRequestBody,
92
93
  supportsStructuredOutputs: true
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","names":["openaiProvider"],"sources":["../../src/lib/provider.ts"],"sourcesContent":["/**\n * Community Vercel AI SDK provider for the Neon AI Gateway.\n *\n * `createNeon()` returns a provider that routes each model to the best gateway\n * endpoint based on its id (Anthropic → native Messages, OpenAI → native\n * Responses incl. Codex, everything else → unified MLflow), so a single\n * `neon('claude-...')` call (same base URL + token) reaches the whole catalog.\n * Ids use the canonical Neon (unprefixed) form; the legacy `databricks-` prefix\n * is also accepted. Configure with the branch-scoped `NEON_AI_GATEWAY_BASE_URL` +\n * `NEON_AI_GATEWAY_TOKEN` emitted by `neonctl env pull` / `neon dev`, or pass\n * `baseURL` / `apiKey` explicitly.\n */\nimport { openai as openaiProvider } from \"@ai-sdk/openai\";\nimport type { ProviderErrorStructure } from \"@ai-sdk/openai-compatible\";\nimport {\n\ttype LanguageModelV3,\n\tNoSuchModelError,\n\ttype ProviderV3,\n} from \"@ai-sdk/provider\";\nimport {\n\ttype FetchFunction,\n\tgenerateId,\n\tloadApiKey,\n\tloadSetting,\n\twithoutTrailingSlash,\n\twithUserAgentSuffix,\n} from \"@ai-sdk/provider-utils\";\nimport { z } from \"zod/v4\";\nimport { NeonAnthropicLanguageModel } from \"./neon-anthropic-language-model.js\";\nimport { NeonChatLanguageModel } from \"./neon-chat-language-model.js\";\nimport type { NeonChatModelId } from \"./neon-chat-options.js\";\nimport { getNeonModelRoute } from \"./neon-model-capabilities.js\";\nimport { NeonResponsesLanguageModel } from \"./neon-responses-language-model.js\";\nimport { VERSION } from \"./version.js\";\n\nconst neonErrorSchema = z.object({\n\terror: z.object({\n\t\tmessage: z.string(),\n\t\ttype: z.string().nullish(),\n\t\tparam: z.unknown().nullish(),\n\t\tcode: z.unknown().nullish(),\n\t}),\n});\n\nexport type NeonErrorData = z.infer<typeof neonErrorSchema>;\n\nconst neonErrorStructure: ProviderErrorStructure<NeonErrorData> = {\n\terrorSchema: neonErrorSchema,\n\terrorToMessage: (data) => data.error.message,\n};\n\n/**\n * Recursively remove the JSON Schema `$schema` marker, which some gateway\n * backends (notably Gemini) reject in tool/structured-output schemas. Other\n * backends ignore its absence, so stripping it everywhere is safe.\n */\nfunction stripJsonSchemaMarker(value: unknown): unknown {\n\tif (Array.isArray(value)) {\n\t\treturn value.map(stripJsonSchemaMarker);\n\t}\n\tif (value !== null && typeof value === \"object\") {\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const [key, entry] of Object.entries(value)) {\n\t\t\tif (key === \"$schema\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tresult[key] = stripJsonSchemaMarker(entry);\n\t\t}\n\t\treturn result;\n\t}\n\treturn value;\n}\n\nfunction transformNeonRequestBody(\n\targs: Record<string, unknown>,\n): Record<string, unknown> {\n\tconst transformed = { ...args };\n\tif (transformed.tools != null) {\n\t\ttransformed.tools = stripJsonSchemaMarker(transformed.tools);\n\t}\n\tif (transformed.response_format != null) {\n\t\ttransformed.response_format = stripJsonSchemaMarker(\n\t\t\ttransformed.response_format,\n\t\t);\n\t}\n\treturn transformed;\n}\n\nexport interface NeonProviderSettings {\n\t/**\n\t * Neon AI Gateway base URL — the branch-scoped host root, e.g.\n\t * `https://<branch-id>-api.ai.<region>.aws.neon.tech`. The gateway paths are\n\t * appended internally. Falls back to the `NEON_AI_GATEWAY_BASE_URL` env var.\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * Neon AI Gateway platform token (the `nt_live_...` value). Falls back to the\n\t * `NEON_AI_GATEWAY_TOKEN` env var.\n\t */\n\tapiKey?: string;\n\n\t/** Custom headers to include in the requests. */\n\theaders?: Record<string, string>;\n\n\t/** Custom fetch implementation (e.g. for testing or middleware). */\n\tfetch?: FetchFunction;\n}\n\nexport interface NeonProvider extends ProviderV3 {\n\t/** Creates a Neon AI Gateway model for text generation. */\n\t(modelId: NeonChatModelId): LanguageModelV3;\n\n\t/** Creates a Neon AI Gateway model for text generation. */\n\tlanguageModel(modelId: NeonChatModelId): LanguageModelV3;\n\n\t/** Creates a Neon AI Gateway chat model for text generation. */\n\tchat(modelId: NeonChatModelId): LanguageModelV3;\n\n\t/** OpenAI Responses tools (e.g. `imageGeneration`) for OpenAI-routed models. */\n\ttools: typeof openaiProvider.tools;\n\n\t/** @deprecated Use `embeddingModel` instead. */\n\ttextEmbeddingModel(modelId: string): never;\n}\n\nexport function createNeon(options: NeonProviderSettings = {}): NeonProvider {\n\t// Resolved lazily so that `createNeon()` and the default `neon` instance do\n\t// not throw at import time when configuration comes from the environment.\n\tconst getHost = () =>\n\t\twithoutTrailingSlash(\n\t\t\tloadSetting({\n\t\t\t\tsettingValue: options.baseURL,\n\t\t\t\tenvironmentVariableName: \"NEON_AI_GATEWAY_BASE_URL\",\n\t\t\t\tsettingName: \"baseURL\",\n\t\t\t\tdescription: \"Neon AI Gateway base URL\",\n\t\t\t}),\n\t\t);\n\n\tconst getHeaders = (extra?: Record<string, string>) =>\n\t\twithUserAgentSuffix(\n\t\t\t{\n\t\t\t\tAuthorization: `Bearer ${loadApiKey({\n\t\t\t\t\tapiKey: options.apiKey,\n\t\t\t\t\tenvironmentVariableName: \"NEON_AI_GATEWAY_TOKEN\",\n\t\t\t\t\tdescription: \"Neon AI Gateway token\",\n\t\t\t\t})}`,\n\t\t\t\t...extra,\n\t\t\t\t...options.headers,\n\t\t\t},\n\t\t\t`neondatabase/ai-sdk-provider/${VERSION}`,\n\t\t);\n\n\t// Anthropic models -> native Messages API.\n\tconst createAnthropicModel = (modelId: NeonChatModelId) =>\n\t\tnew NeonAnthropicLanguageModel(modelId, {\n\t\t\tprovider: \"neon.anthropic\",\n\t\t\tbaseURL: `${getHost()}/ai-gateway/anthropic/v1`,\n\t\t\theaders: () => getHeaders({ \"anthropic-version\": \"2023-06-01\" }),\n\t\t\tfetch: options.fetch,\n\t\t\tgenerateId,\n\t\t});\n\n\t// OpenAI models (incl. Codex, only served natively) -> Responses API.\n\tconst createOpenAIModel = (modelId: NeonChatModelId) =>\n\t\tnew NeonResponsesLanguageModel(modelId, {\n\t\t\tprovider: \"neon.openai.responses\",\n\t\t\turl: ({ path }) => `${getHost()}/ai-gateway/openai/v1${path}`,\n\t\t\theaders: getHeaders,\n\t\t\tfetch: options.fetch,\n\t\t\tfileIdPrefixes: [\"file-\"],\n\t\t});\n\n\t// Everything else (Gemini, Llama, Qwen, gpt-oss, ...) -> unified MLflow\n\t// endpoint. Gemini is here because its native endpoint can't stream.\n\tconst createChatModel = (modelId: NeonChatModelId) =>\n\t\tnew NeonChatLanguageModel(modelId, {\n\t\t\tprovider: \"neon.chat\",\n\t\t\turl: ({ path }) => `${getHost()}/ai-gateway/mlflow/v1${path}`,\n\t\t\theaders: getHeaders,\n\t\t\tfetch: options.fetch,\n\t\t\terrorStructure: neonErrorStructure,\n\t\t\ttransformRequestBody: transformNeonRequestBody,\n\t\t\tsupportsStructuredOutputs: true,\n\t\t});\n\n\tconst createLanguageModel = (modelId: NeonChatModelId): LanguageModelV3 => {\n\t\tswitch (getNeonModelRoute(modelId)) {\n\t\t\tcase \"anthropic\":\n\t\t\t\treturn createAnthropicModel(modelId);\n\t\t\tcase \"openai\":\n\t\t\t\treturn createOpenAIModel(modelId);\n\t\t\tdefault:\n\t\t\t\treturn createChatModel(modelId);\n\t\t}\n\t};\n\n\tconst provider = (modelId: NeonChatModelId) => createLanguageModel(modelId);\n\n\tprovider.specificationVersion = \"v3\" as const;\n\tprovider.languageModel = createLanguageModel;\n\tprovider.chat = createLanguageModel;\n\tprovider.tools = openaiProvider.tools;\n\n\tprovider.embeddingModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({ modelId, modelType: \"embeddingModel\" });\n\t};\n\tprovider.textEmbeddingModel = provider.embeddingModel;\n\tprovider.imageModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({ modelId, modelType: \"imageModel\" });\n\t};\n\n\treturn provider;\n}\n\n/** Default Neon provider instance (reads `NEON_AI_GATEWAY_*` env vars). */\nexport const neon = createNeon();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAM,qBAA4D;CACjE,aAZuB,EAAE,OAAO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O,QAAQ;EACf;CACD,CAAC;CAGF,MAAM,qBAAqB,YAC1B,IAAI,2BAA2B,SAAS;EACvC,UAAU;EACV,MAAM,EAAE,WAAW,GAAG,QAAQ,EAAE,uBAAuB;EACvD,SAAS;EACT,OAAO,QAAQ;EACf,gBAAgB,CAAC,OAAO;CACzB,CAAC;CAIF,MAAM,mBAAmB,YACxB,IAAI,sBAAsB,SAAS;EAClC,UAAU;EACV,MAAM,EAAE,WAAW,GAAG,QAAQ,EAAE,uBAAuB;EACvD,SAAS;EACT,OAAO,QAAQ;EACf,gBAAgB;EAChB,sBAAsB;EACtB,2BAA2B;CAC5B,CAAC;CAEF,MAAM,uBAAuB,YAA8C;EAC1E,QAAQ,kBAAkB,OAAO,GAAjC;GACC,KAAK,aACJ,OAAO,qBAAqB,OAAO;GACpC,KAAK,UACJ,OAAO,kBAAkB,OAAO;GACjC,SACC,OAAO,gBAAgB,OAAO;EAChC;CACD;CAEA,MAAM,YAAY,YAA6B,oBAAoB,OAAO;CAE1E,SAAS,uBAAuB;CAChC,SAAS,gBAAgB;CACzB,SAAS,OAAO;CAChB,SAAS,QAAQA,OAAe;CAEhC,SAAS,kBAAkB,YAAoB;EAC9C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAiB,CAAC;CACpE;CACA,SAAS,qBAAqB,SAAS;CACvC,SAAS,cAAc,YAAoB;EAC1C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAa,CAAC;CAChE;CAEA,OAAO;AACR;;AAGA,MAAa,OAAO,WAAW"}
1
+ {"version":3,"file":"provider.js","names":["openaiProvider"],"sources":["../../src/lib/provider.ts"],"sourcesContent":["/**\n * Community Vercel AI SDK provider for the Neon AI Gateway.\n *\n * `createNeon()` returns a provider that routes each model to the best gateway\n * endpoint based on its id (Anthropic → native Messages, OpenAI → native\n * Responses incl. Codex, everything else → unified Chat Completions), so a single\n * `neon('claude-...')` call (same base URL + token) reaches the whole catalog.\n * Ids use the canonical Neon (unprefixed) form; the legacy `databricks-` prefix\n * is also accepted. Configure with the branch-scoped `NEON_AI_GATEWAY_BASE_URL` +\n * `NEON_AI_GATEWAY_TOKEN` emitted by `neonctl env pull` / `neon dev`, or pass\n * `baseURL` / `apiKey` explicitly.\n */\nimport { openai as openaiProvider } from \"@ai-sdk/openai\";\nimport type { ProviderErrorStructure } from \"@ai-sdk/openai-compatible\";\nimport {\n\ttype LanguageModelV3,\n\tNoSuchModelError,\n\ttype ProviderV3,\n} from \"@ai-sdk/provider\";\nimport {\n\ttype FetchFunction,\n\tgenerateId,\n\tloadApiKey,\n\tloadSetting,\n\twithoutTrailingSlash,\n\twithUserAgentSuffix,\n} from \"@ai-sdk/provider-utils\";\nimport { z } from \"zod/v4\";\nimport { NeonAnthropicLanguageModel } from \"./neon-anthropic-language-model.js\";\nimport { NeonChatLanguageModel } from \"./neon-chat-language-model.js\";\nimport type { NeonChatModelId } from \"./neon-chat-options.js\";\nimport { wrapFetchWithHarmonyNormalization } from \"./neon-harmony-normalize.js\";\nimport { getNeonModelRoute } from \"./neon-model-capabilities.js\";\nimport { NeonResponsesLanguageModel } from \"./neon-responses-language-model.js\";\nimport { VERSION } from \"./version.js\";\n\nconst neonErrorSchema = z.object({\n\terror: z.object({\n\t\tmessage: z.string(),\n\t\ttype: z.string().nullish(),\n\t\tparam: z.unknown().nullish(),\n\t\tcode: z.unknown().nullish(),\n\t}),\n});\n\nexport type NeonErrorData = z.infer<typeof neonErrorSchema>;\n\nconst neonErrorStructure: ProviderErrorStructure<NeonErrorData> = {\n\terrorSchema: neonErrorSchema,\n\terrorToMessage: (data) => data.error.message,\n};\n\n/**\n * Recursively remove the JSON Schema `$schema` marker, which some gateway\n * backends (notably Gemini) reject in tool/structured-output schemas. Other\n * backends ignore its absence, so stripping it everywhere is safe.\n */\nfunction stripJsonSchemaMarker(value: unknown): unknown {\n\tif (Array.isArray(value)) {\n\t\treturn value.map(stripJsonSchemaMarker);\n\t}\n\tif (value !== null && typeof value === \"object\") {\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const [key, entry] of Object.entries(value)) {\n\t\t\tif (key === \"$schema\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tresult[key] = stripJsonSchemaMarker(entry);\n\t\t}\n\t\treturn result;\n\t}\n\treturn value;\n}\n\nfunction transformNeonRequestBody(\n\targs: Record<string, unknown>,\n): Record<string, unknown> {\n\tconst transformed = { ...args };\n\tif (transformed.tools != null) {\n\t\ttransformed.tools = stripJsonSchemaMarker(transformed.tools);\n\t}\n\tif (transformed.response_format != null) {\n\t\ttransformed.response_format = stripJsonSchemaMarker(\n\t\t\ttransformed.response_format,\n\t\t);\n\t}\n\treturn transformed;\n}\n\nexport interface NeonProviderSettings {\n\t/**\n\t * Neon AI Gateway base URL — the branch-scoped host root, e.g.\n\t * `https://<branch-id>-api.ai.<region>.aws.neon.tech`. The gateway paths are\n\t * appended internally. Falls back to the `NEON_AI_GATEWAY_BASE_URL` env var.\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * Neon AI Gateway platform token (the `nt_live_...` value). Falls back to the\n\t * `NEON_AI_GATEWAY_TOKEN` env var.\n\t */\n\tapiKey?: string;\n\n\t/** Custom headers to include in the requests. */\n\theaders?: Record<string, string>;\n\n\t/** Custom fetch implementation (e.g. for testing or middleware). */\n\tfetch?: FetchFunction;\n}\n\nexport interface NeonProvider extends ProviderV3 {\n\t/** Creates a Neon AI Gateway model for text generation. */\n\t(modelId: NeonChatModelId): LanguageModelV3;\n\n\t/** Creates a Neon AI Gateway model for text generation. */\n\tlanguageModel(modelId: NeonChatModelId): LanguageModelV3;\n\n\t/** Creates a Neon AI Gateway chat model for text generation. */\n\tchat(modelId: NeonChatModelId): LanguageModelV3;\n\n\t/** OpenAI Responses tools (e.g. `imageGeneration`) for OpenAI-routed models. */\n\ttools: typeof openaiProvider.tools;\n\n\t/** @deprecated Use `embeddingModel` instead. */\n\ttextEmbeddingModel(modelId: string): never;\n}\n\nexport function createNeon(options: NeonProviderSettings = {}): NeonProvider {\n\t// Resolved lazily so that `createNeon()` and the default `neon` instance do\n\t// not throw at import time when configuration comes from the environment.\n\tconst getHost = () =>\n\t\twithoutTrailingSlash(\n\t\t\tloadSetting({\n\t\t\t\tsettingValue: options.baseURL,\n\t\t\t\tenvironmentVariableName: \"NEON_AI_GATEWAY_BASE_URL\",\n\t\t\t\tsettingName: \"baseURL\",\n\t\t\t\tdescription: \"Neon AI Gateway base URL\",\n\t\t\t}),\n\t\t);\n\n\tconst getHeaders = (extra?: Record<string, string>) =>\n\t\twithUserAgentSuffix(\n\t\t\t{\n\t\t\t\tAuthorization: `Bearer ${loadApiKey({\n\t\t\t\t\tapiKey: options.apiKey,\n\t\t\t\t\tenvironmentVariableName: \"NEON_AI_GATEWAY_TOKEN\",\n\t\t\t\t\tdescription: \"Neon AI Gateway token\",\n\t\t\t\t})}`,\n\t\t\t\t...extra,\n\t\t\t\t...options.headers,\n\t\t\t},\n\t\t\t`neondatabase/ai-sdk-provider/${VERSION}`,\n\t\t);\n\n\t// Anthropic models -> native Messages API.\n\tconst createAnthropicModel = (modelId: NeonChatModelId) =>\n\t\tnew NeonAnthropicLanguageModel(modelId, {\n\t\t\tprovider: \"neon.anthropic\",\n\t\t\tbaseURL: `${getHost()}/anthropic/v1`,\n\t\t\theaders: () => getHeaders({ \"anthropic-version\": \"2023-06-01\" }),\n\t\t\tfetch: options.fetch,\n\t\t\tgenerateId,\n\t\t});\n\n\t// OpenAI models (incl. Codex, only served natively) -> Responses API.\n\tconst createOpenAIModel = (modelId: NeonChatModelId) =>\n\t\tnew NeonResponsesLanguageModel(modelId, {\n\t\t\tprovider: \"neon.openai.responses\",\n\t\t\turl: ({ path }) => `${getHost()}/openai/v1${path}`,\n\t\t\theaders: getHeaders,\n\t\t\tfetch: options.fetch,\n\t\t\tfileIdPrefixes: [\"file-\"],\n\t\t});\n\n\t// Everything else (Gemini, Llama, Qwen, gpt-oss, ...) -> unified Chat\n\t// Completions endpoint. Gemini is here because its native endpoint can't stream.\n\tconst createChatModel = (modelId: NeonChatModelId) =>\n\t\tnew NeonChatLanguageModel(modelId, {\n\t\t\tprovider: \"neon.chat\",\n\t\t\turl: ({ path }) => `${getHost()}/v1${path}`,\n\t\t\theaders: getHeaders,\n\t\t\t// TODO(#308): Temporary workaround for gpt-oss. The gateway returns a\n\t\t\t// non-compliant \"harmony\" content-array shape; this wrapper normalizes it\n\t\t\t// to the Chat Completions contract and is a transparent pass-through for\n\t\t\t// every compliant response. Remove it (and neon-harmony-normalize.ts) once\n\t\t\t// the gateway returns spec-compliant gpt-oss responses.\n\t\t\tfetch: wrapFetchWithHarmonyNormalization(options.fetch),\n\t\t\terrorStructure: neonErrorStructure,\n\t\t\ttransformRequestBody: transformNeonRequestBody,\n\t\t\tsupportsStructuredOutputs: true,\n\t\t});\n\n\tconst createLanguageModel = (modelId: NeonChatModelId): LanguageModelV3 => {\n\t\tswitch (getNeonModelRoute(modelId)) {\n\t\t\tcase \"anthropic\":\n\t\t\t\treturn createAnthropicModel(modelId);\n\t\t\tcase \"openai\":\n\t\t\t\treturn createOpenAIModel(modelId);\n\t\t\tdefault:\n\t\t\t\treturn createChatModel(modelId);\n\t\t}\n\t};\n\n\tconst provider = (modelId: NeonChatModelId) => createLanguageModel(modelId);\n\n\tprovider.specificationVersion = \"v3\" as const;\n\tprovider.languageModel = createLanguageModel;\n\tprovider.chat = createLanguageModel;\n\tprovider.tools = openaiProvider.tools;\n\n\tprovider.embeddingModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({ modelId, modelType: \"embeddingModel\" });\n\t};\n\tprovider.textEmbeddingModel = provider.embeddingModel;\n\tprovider.imageModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({ modelId, modelType: \"imageModel\" });\n\t};\n\n\treturn provider;\n}\n\n/** Default Neon provider instance (reads `NEON_AI_GATEWAY_*` env vars). */\nexport const neon = createNeon();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,qBAA4D;CACjE,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,CAAC;EAC/D,OAAO,QAAQ;EACf;CACD,CAAC;CAGF,MAAM,qBAAqB,YAC1B,IAAI,2BAA2B,SAAS;EACvC,UAAU;EACV,MAAM,EAAE,WAAW,GAAG,QAAQ,EAAE,YAAY;EAC5C,SAAS;EACT,OAAO,QAAQ;EACf,gBAAgB,CAAC,OAAO;CACzB,CAAC;CAIF,MAAM,mBAAmB,YACxB,IAAI,sBAAsB,SAAS;EAClC,UAAU;EACV,MAAM,EAAE,WAAW,GAAG,QAAQ,EAAE,KAAK;EACrC,SAAS;EAMT,OAAO,kCAAkC,QAAQ,KAAK;EACtD,gBAAgB;EAChB,sBAAsB;EACtB,2BAA2B;CAC5B,CAAC;CAEF,MAAM,uBAAuB,YAA8C;EAC1E,QAAQ,kBAAkB,OAAO,GAAjC;GACC,KAAK,aACJ,OAAO,qBAAqB,OAAO;GACpC,KAAK,UACJ,OAAO,kBAAkB,OAAO;GACjC,SACC,OAAO,gBAAgB,OAAO;EAChC;CACD;CAEA,MAAM,YAAY,YAA6B,oBAAoB,OAAO;CAE1E,SAAS,uBAAuB;CAChC,SAAS,gBAAgB;CACzB,SAAS,OAAO;CAChB,SAAS,QAAQA,OAAe;CAEhC,SAAS,kBAAkB,YAAoB;EAC9C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAiB,CAAC;CACpE;CACA,SAAS,qBAAqB,SAAS;CACvC,SAAS,cAAc,YAAoB;EAC1C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAa,CAAC;CAChE;CAEA,OAAO;AACR;;AAGA,MAAa,OAAO,WAAW"}
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.6.0";
2
+ var version = "0.7.1";
3
3
  //#endregion
4
4
  export { version };
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neon/ai-sdk-provider",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Community Vercel AI SDK provider for the Neon AI Gateway.",
5
5
  "keywords": [
6
6
  "neon",
@@ -38,11 +38,11 @@
38
38
  ],
39
39
  "devDependencies": {
40
40
  "@types/node": "^20.19.0",
41
- "@vitest/coverage-v8": "3.0.9",
41
+ "@vitest/coverage-v8": "^3.0.9",
42
42
  "ai": "6.0.132",
43
43
  "console-fail-test": "0.5.0",
44
44
  "tsdown": "^0.14.1",
45
- "typescript": "^5.8.2",
45
+ "typescript": "^5.9.0",
46
46
  "vitest": "^3.0.9",
47
47
  "zod": "^4.4.3"
48
48
  },