@neondatabase/ai-sdk-provider 0.0.0 → 0.4.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.
- package/LICENSE.md +178 -0
- package/README.md +24 -9
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/lib/neon-anthropic-language-model.d.ts +23 -0
- package/dist/lib/neon-anthropic-language-model.d.ts.map +1 -0
- package/dist/lib/neon-anthropic-language-model.js +38 -0
- package/dist/lib/neon-anthropic-language-model.js.map +1 -0
- package/dist/lib/neon-capabilities.d.ts +20 -0
- package/dist/lib/neon-capabilities.d.ts.map +1 -0
- package/dist/lib/neon-capabilities.js +97 -0
- package/dist/lib/neon-capabilities.js.map +1 -0
- package/dist/lib/neon-chat-language-model.d.ts +21 -0
- package/dist/lib/neon-chat-language-model.d.ts.map +1 -0
- package/dist/lib/neon-chat-language-model.js +34 -0
- package/dist/lib/neon-chat-language-model.js.map +1 -0
- package/dist/lib/neon-chat-options.d.ts +21 -0
- package/dist/lib/neon-chat-options.d.ts.map +1 -0
- package/dist/lib/neon-chat-options.js +52 -0
- package/dist/lib/neon-chat-options.js.map +1 -0
- package/dist/lib/neon-model-capabilities.d.ts +41 -0
- package/dist/lib/neon-model-capabilities.d.ts.map +1 -0
- package/dist/lib/neon-model-capabilities.js +74 -0
- package/dist/lib/neon-model-capabilities.js.map +1 -0
- package/dist/lib/neon-responses-language-model.d.ts +27 -0
- package/dist/lib/neon-responses-language-model.d.ts.map +1 -0
- package/dist/lib/neon-responses-language-model.js +45 -0
- package/dist/lib/neon-responses-language-model.js.map +1 -0
- package/dist/lib/provider.d.ts +52 -0
- package/dist/lib/provider.d.ts.map +1 -0
- package/dist/lib/provider.js +126 -0
- package/dist/lib/provider.js.map +1 -0
- package/dist/lib/version.d.ts +5 -0
- package/dist/lib/version.d.ts.map +1 -0
- package/dist/lib/version.js +7 -0
- package/dist/lib/version.js.map +1 -0
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/v1.d.ts +7 -0
- package/dist/v1.js +7 -0
- package/package.json +78 -23
- package/src/index.ts +0 -5
- package/src/lib/neon-anthropic-language-model.ts +0 -51
- package/src/lib/neon-capabilities.ts +0 -133
- package/src/lib/neon-chat-language-model.ts +0 -56
- package/src/lib/neon-chat-options.ts +0 -48
- package/src/lib/neon-model-capabilities.test.ts +0 -66
- package/src/lib/neon-model-capabilities.ts +0 -137
- package/src/lib/neon-responses-language-model.ts +0 -60
- package/src/lib/provider.ts +0 -211
- package/src/lib/version.ts +0 -2
- package/src/v1.ts +0 -26
- package/tsconfig.json +0 -4
- package/tsdown.config.ts +0 -12
- package/vitest.config.ts +0 -17
package/LICENSE.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# @neondatabase/ai-sdk-provider
|
|
2
2
|
|
|
3
|
-
Community [Vercel AI SDK](https://ai-sdk.dev) provider for the [Neon](https://neon.com) AI Gateway.
|
|
3
|
+
Community [Vercel AI SDK](https://ai-sdk.dev) provider for the [Neon](https://neon.com) AI Gateway. Requires **AI SDK v6** (`ai@^6`).
|
|
4
4
|
|
|
5
|
-
The Neon AI Gateway is **branch-scoped**: each Neon project branch gets its own gateway host, and a platform token authorizes requests for that branch. This provider routes each model to the best gateway endpoint (Anthropic → native Messages, OpenAI → native Responses incl. **Codex**, everything else → unified OpenAI-compatible MLflow endpoint), so a single `neon('
|
|
5
|
+
The Neon AI Gateway is **branch-scoped**: each Neon project branch gets its own gateway host, and a platform token authorizes requests for that branch. This provider routes each model to the best gateway endpoint (Anthropic → native Messages, OpenAI → native Responses incl. **Codex**, everything else → unified OpenAI-compatible MLflow endpoint), so a single `neon('claude-...')` call reaches the whole catalog.
|
|
6
|
+
|
|
7
|
+
Model ids use the canonical Neon (unprefixed) form — `claude-sonnet-4-6`, `gpt-5`, `gemini-2-5-flash` — matching the [`neon` provider on models.dev](https://models.dev). The typed catalog mirrors that provider exactly (kept in sync by a scheduled drift check), plus a few extra gateway-served ids that models.dev doesn't list yet (e.g. Codex, Llama, Qwen). Any other id — including the legacy `databricks-` prefixed form (`databricks-claude-sonnet-4-6`) — is still accepted as a plain string, so existing code keeps working.
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
|
9
11
|
```bash
|
|
10
|
-
npm install @neondatabase/ai-sdk-provider
|
|
12
|
+
npm install @neondatabase/ai-sdk-provider ai@^6
|
|
11
13
|
```
|
|
12
14
|
|
|
13
15
|
## Configuration
|
|
@@ -27,7 +29,7 @@ import { generateText } from "ai";
|
|
|
27
29
|
|
|
28
30
|
// Reads NEON_AI_GATEWAY_BASE_URL + NEON_AI_GATEWAY_TOKEN from the environment.
|
|
29
31
|
const { text } = await generateText({
|
|
30
|
-
model: neon("
|
|
32
|
+
model: neon("claude-haiku-4-5"), // or 'gpt-5-3-codex', etc.
|
|
31
33
|
prompt: "Summarize Postgres for me.",
|
|
32
34
|
});
|
|
33
35
|
```
|
|
@@ -47,10 +49,12 @@ const neon = createNeon({
|
|
|
47
49
|
|
|
48
50
|
| Model family | Endpoint | Why |
|
|
49
51
|
| --- | --- | --- |
|
|
50
|
-
| Anthropic (`
|
|
51
|
-
| OpenAI (`
|
|
52
|
+
| Anthropic (`claude-*`) | native Messages API | streaming structured output + native reasoning |
|
|
53
|
+
| OpenAI (`gpt-*`, `*-codex`) | native Responses API | Codex (native-only), native reasoning, image-gen tool |
|
|
52
54
|
| Everything else (Gemini, Llama, Qwen, gpt-oss, ...) | unified MLflow endpoint | broad coverage; Gemini is here because its native endpoint does not support streaming |
|
|
53
55
|
|
|
56
|
+
Routing matches on the model id, so both the canonical (`gpt-5`) and the legacy `databricks-`-prefixed (`databricks-gpt-5`) forms route identically.
|
|
57
|
+
|
|
54
58
|
## Capabilities
|
|
55
59
|
|
|
56
60
|
Verified across Anthropic, OpenAI (incl. Codex), Google, and Meta models: `generateText` / `streamText` (text, system prompts, multi-turn), tool calling (single and multi-step, generate and stream), `generateObject` / `streamObject`, and image (vision) input.
|
|
@@ -64,12 +68,11 @@ Available on OpenAI models via the Responses `image_generation` tool (there is n
|
|
|
64
68
|
```ts
|
|
65
69
|
import { streamText } from "ai";
|
|
66
70
|
import { neon } from "@neondatabase/ai-sdk-provider/v1";
|
|
67
|
-
import { imageGeneration } from "@ai-sdk/openai/internal";
|
|
68
71
|
|
|
69
72
|
const result = streamText({
|
|
70
|
-
model: neon("
|
|
73
|
+
model: neon("gpt-5-mini"),
|
|
71
74
|
prompt: "Generate an image of a red apple on a wooden table",
|
|
72
|
-
tools: { image: imageGeneration({ partialImages: 3 }) },
|
|
75
|
+
tools: { image: neon.tools.imageGeneration({ partialImages: 3 }) },
|
|
73
76
|
});
|
|
74
77
|
|
|
75
78
|
for await (const part of result.fullStream) {
|
|
@@ -84,6 +87,18 @@ for await (const part of result.fullStream) {
|
|
|
84
87
|
|
|
85
88
|
- `generateImage()` and embeddings (`embed` / `embedMany`) are not offered by the gateway and throw `NoSuchModelError`.
|
|
86
89
|
- `gpt-oss-*` models return a non-standard ("harmony") response shape on the unified endpoint and are not fully supported.
|
|
90
|
+
- OpenAI Responses multi-turn tool flows (`generateText` + `stepCountIs`) can return 502 from the gateway; tool calling is covered on Anthropic/Google/Meta in e2e.
|
|
91
|
+
|
|
92
|
+
## End-to-end tests
|
|
93
|
+
|
|
94
|
+
Against a live branch with AI Gateway enabled:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
cp .env.example .env # fill NEON_AI_GATEWAY_BASE_URL + NEON_AI_GATEWAY_TOKEN from `neonctl env pull`
|
|
98
|
+
pnpm test:e2e
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The matrix covers one models.dev `neon` model per family (Anthropic, OpenAI, Codex, Gemini, Meta) across `generateText`, `streamText`, `generateObject`, tool calling, and `neon.tools.imageGeneration`. Skipped when gateway env vars are absent.
|
|
87
102
|
|
|
88
103
|
## Versioning
|
|
89
104
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NeonAnthropicLanguageModel } from "./lib/neon-anthropic-language-model.js";
|
|
2
|
+
import { NeonChatLanguageModel } from "./lib/neon-chat-language-model.js";
|
|
3
|
+
import { NEON_EXTRA_MODEL_IDS, NEON_MODELS_DEV_IDS, NeonChatModelId, NeonKnownModelId } from "./lib/neon-chat-options.js";
|
|
4
|
+
import { NeonModelCapabilities, NeonModelFamily, NeonModelRoute, getNeonModelCapabilities, getNeonModelRoute } from "./lib/neon-model-capabilities.js";
|
|
5
|
+
import { NeonResponsesLanguageModel } from "./lib/neon-responses-language-model.js";
|
|
6
|
+
import { NeonErrorData, NeonProvider, NeonProviderSettings, createNeon, neon } from "./lib/provider.js";
|
|
7
|
+
export { NEON_EXTRA_MODEL_IDS, NEON_MODELS_DEV_IDS, NeonAnthropicLanguageModel, NeonChatLanguageModel, NeonChatModelId, NeonErrorData, NeonKnownModelId, NeonModelCapabilities, NeonModelFamily, NeonModelRoute, NeonProvider, NeonProviderSettings, NeonResponsesLanguageModel, createNeon, getNeonModelCapabilities, getNeonModelRoute, neon };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NeonAnthropicLanguageModel } from "./lib/neon-anthropic-language-model.js";
|
|
2
|
+
import { getNeonModelCapabilities, getNeonModelRoute } from "./lib/neon-model-capabilities.js";
|
|
3
|
+
import { NeonChatLanguageModel } from "./lib/neon-chat-language-model.js";
|
|
4
|
+
import { NEON_EXTRA_MODEL_IDS, NEON_MODELS_DEV_IDS } from "./lib/neon-chat-options.js";
|
|
5
|
+
import { NeonResponsesLanguageModel } from "./lib/neon-responses-language-model.js";
|
|
6
|
+
import { createNeon, neon } from "./lib/provider.js";
|
|
7
|
+
import "./v1.js";
|
|
8
|
+
export { NEON_EXTRA_MODEL_IDS, NEON_MODELS_DEV_IDS, NeonAnthropicLanguageModel, NeonChatLanguageModel, NeonResponsesLanguageModel, createNeon, getNeonModelCapabilities, getNeonModelRoute, neon };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AnthropicMessagesLanguageModel } from "@ai-sdk/anthropic/internal";
|
|
2
|
+
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from "@ai-sdk/provider";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/neon-anthropic-language-model.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Language model for Anthropic models served via the Neon AI Gateway's native
|
|
8
|
+
* Messages API (`/ai-gateway/anthropic/v1/messages`). Unlocks streaming
|
|
9
|
+
* structured output and native reasoning for Claude.
|
|
10
|
+
*
|
|
11
|
+
* The shared Anthropic model defaults to fine-grained tool-input streaming
|
|
12
|
+
* (`eager_input_streaming: true`) on streaming tool calls, which the gateway
|
|
13
|
+
* rejects (`Extra inputs are not permitted`). We disable it via the model's own
|
|
14
|
+
* `toolStreaming` option so streaming tool calls work. Users can still override.
|
|
15
|
+
*/
|
|
16
|
+
declare class NeonAnthropicLanguageModel extends AnthropicMessagesLanguageModel implements LanguageModelV3 {
|
|
17
|
+
private withGatewayCompat;
|
|
18
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
19
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { NeonAnthropicLanguageModel };
|
|
23
|
+
//# sourceMappingURL=neon-anthropic-language-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neon-anthropic-language-model.d.ts","names":[],"sources":["../../src/lib/neon-anthropic-language-model.ts"],"mappings":";;;;;;;AAkBA;;;;;;;;AACS,cADI,0BAAA,SACJ,8BAAA,YACG,eADH,CAAA;UACG,iBAAA;EAAe,UAAA,CAAA,OAAA,EAoBhB,0BApBgB,CAAA,EAqBvB,OArBuB,CAqBf,6BArBe,CAAA;oBA0BhB,6BACP,QAAQ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AnthropicMessagesLanguageModel } from "@ai-sdk/anthropic/internal";
|
|
2
|
+
//#region src/lib/neon-anthropic-language-model.ts
|
|
3
|
+
/**
|
|
4
|
+
* Language model for Anthropic models served via the Neon AI Gateway's native
|
|
5
|
+
* Messages API (`/ai-gateway/anthropic/v1/messages`). Unlocks streaming
|
|
6
|
+
* structured output and native reasoning for Claude.
|
|
7
|
+
*
|
|
8
|
+
* The shared Anthropic model defaults to fine-grained tool-input streaming
|
|
9
|
+
* (`eager_input_streaming: true`) on streaming tool calls, which the gateway
|
|
10
|
+
* rejects (`Extra inputs are not permitted`). We disable it via the model's own
|
|
11
|
+
* `toolStreaming` option so streaming tool calls work. Users can still override.
|
|
12
|
+
*/
|
|
13
|
+
var NeonAnthropicLanguageModel = class extends AnthropicMessagesLanguageModel {
|
|
14
|
+
withGatewayCompat(options) {
|
|
15
|
+
const anthropic = options.providerOptions?.anthropic;
|
|
16
|
+
if (anthropic != null && "toolStreaming" in anthropic) return options;
|
|
17
|
+
return {
|
|
18
|
+
...options,
|
|
19
|
+
providerOptions: {
|
|
20
|
+
...options.providerOptions,
|
|
21
|
+
anthropic: {
|
|
22
|
+
...anthropic,
|
|
23
|
+
toolStreaming: false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
doGenerate(options) {
|
|
29
|
+
return super.doGenerate(this.withGatewayCompat(options));
|
|
30
|
+
}
|
|
31
|
+
doStream(options) {
|
|
32
|
+
return super.doStream(this.withGatewayCompat(options));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { NeonAnthropicLanguageModel };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=neon-anthropic-language-model.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LanguageModelV3CallOptions, LanguageModelV3StreamPart, SharedV3Warning } from "@ai-sdk/provider";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/neon-capabilities.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Drop call options the resolved model's upstream backend does not accept and
|
|
7
|
+
* collect a warning for each, so callers get a clear signal instead of a hard
|
|
8
|
+
* `400` from the gateway.
|
|
9
|
+
*/
|
|
10
|
+
declare function applyNeonCapabilities(modelId: string, options: LanguageModelV3CallOptions): {
|
|
11
|
+
options: LanguageModelV3CallOptions;
|
|
12
|
+
warnings: SharedV3Warning[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Merge additional warnings into the `stream-start` part of a model stream.
|
|
16
|
+
*/
|
|
17
|
+
declare function mergeStreamStartWarnings(extra: SharedV3Warning[]): TransformStream<LanguageModelV3StreamPart, LanguageModelV3StreamPart>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { applyNeonCapabilities, mergeStreamStartWarnings };
|
|
20
|
+
//# sourceMappingURL=neon-capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neon-capabilities.d.ts","names":[],"sources":["../../src/lib/neon-capabilities.ts"],"mappings":";;;;;;AAaA;;;AAGc,iBAHE,qBAAA,CAGF,OAAA,EAAA,MAAA,EAAA,OAAA,EADJ,0BACI,CAAA,EAAA;SAAsC,EAAtC,0BAAsC;EAAe,QAAA,EAAf,eAAe,EAAA;AA4FnE,CAAA;;;;AAAiE,iBAAjD,wBAAA,CAAiD,KAAA,EAAjB,eAAiB,EAAA,CAAA,EAAA,eAAA,CAAA,yBAAA,EAAA,yBAAA,CAAA"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { getNeonModelCapabilities } from "./neon-model-capabilities.js";
|
|
2
|
+
//#region src/lib/neon-capabilities.ts
|
|
3
|
+
/**
|
|
4
|
+
* Drop call options the resolved model's upstream backend does not accept and
|
|
5
|
+
* collect a warning for each, so callers get a clear signal instead of a hard
|
|
6
|
+
* `400` from the gateway.
|
|
7
|
+
*/
|
|
8
|
+
function applyNeonCapabilities(modelId, options) {
|
|
9
|
+
const caps = getNeonModelCapabilities(modelId);
|
|
10
|
+
const warnings = [];
|
|
11
|
+
const patch = {};
|
|
12
|
+
const dropUnsupported = (feature) => {
|
|
13
|
+
warnings.push({
|
|
14
|
+
type: "unsupported",
|
|
15
|
+
feature,
|
|
16
|
+
details: `${feature} is not supported by the Neon AI Gateway for ${caps.family} model "${modelId}" and was dropped.`
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
if (options.temperature != null && !caps.supportsTemperature) {
|
|
20
|
+
patch.temperature = void 0;
|
|
21
|
+
dropUnsupported("temperature");
|
|
22
|
+
}
|
|
23
|
+
if (options.topP != null && !caps.supportsTopP) {
|
|
24
|
+
patch.topP = void 0;
|
|
25
|
+
dropUnsupported("topP");
|
|
26
|
+
}
|
|
27
|
+
const effectiveTemperature = "temperature" in patch ? patch.temperature : options.temperature;
|
|
28
|
+
const effectiveTopP = "topP" in patch ? patch.topP : options.topP;
|
|
29
|
+
if (caps.temperatureTopPMutuallyExclusive && effectiveTemperature != null && effectiveTopP != null) {
|
|
30
|
+
patch.topP = void 0;
|
|
31
|
+
warnings.push({
|
|
32
|
+
type: "compatibility",
|
|
33
|
+
feature: "topP",
|
|
34
|
+
details: `${caps.family} models accept only one of temperature or topP; topP was dropped.`
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (options.frequencyPenalty != null && !caps.supportsPenalties) {
|
|
38
|
+
patch.frequencyPenalty = void 0;
|
|
39
|
+
dropUnsupported("frequencyPenalty");
|
|
40
|
+
}
|
|
41
|
+
if (options.presencePenalty != null && !caps.supportsPenalties) {
|
|
42
|
+
patch.presencePenalty = void 0;
|
|
43
|
+
dropUnsupported("presencePenalty");
|
|
44
|
+
}
|
|
45
|
+
if (options.seed != null && !caps.supportsSeed) {
|
|
46
|
+
patch.seed = void 0;
|
|
47
|
+
dropUnsupported("seed");
|
|
48
|
+
}
|
|
49
|
+
if (options.stopSequences != null && !caps.supportsStopSequences) {
|
|
50
|
+
patch.stopSequences = void 0;
|
|
51
|
+
dropUnsupported("stopSequences");
|
|
52
|
+
}
|
|
53
|
+
if (!caps.supportsReasoningEffort) {
|
|
54
|
+
const { providerOptions } = options;
|
|
55
|
+
if (providerOptions != null && Object.values(providerOptions).some((group) => "reasoningEffort" in group && group.reasoningEffort != null)) {
|
|
56
|
+
dropUnsupported("reasoningEffort");
|
|
57
|
+
if (providerOptions != null) {
|
|
58
|
+
const cleaned = {};
|
|
59
|
+
for (const [key, group] of Object.entries(providerOptions)) if ("reasoningEffort" in group) {
|
|
60
|
+
const { reasoningEffort: _removed, ...rest } = group;
|
|
61
|
+
cleaned[key] = rest;
|
|
62
|
+
} else cleaned[key] = group;
|
|
63
|
+
patch.providerOptions = cleaned;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (Object.keys(patch).length === 0) return {
|
|
68
|
+
options,
|
|
69
|
+
warnings
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
options: {
|
|
73
|
+
...options,
|
|
74
|
+
...patch
|
|
75
|
+
},
|
|
76
|
+
warnings
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Merge additional warnings into the `stream-start` part of a model stream.
|
|
81
|
+
*/
|
|
82
|
+
function mergeStreamStartWarnings(extra) {
|
|
83
|
+
let merged = false;
|
|
84
|
+
return new TransformStream({ transform(part, controller) {
|
|
85
|
+
if (!merged && part.type === "stream-start") {
|
|
86
|
+
merged = true;
|
|
87
|
+
controller.enqueue({
|
|
88
|
+
...part,
|
|
89
|
+
warnings: [...extra, ...part.warnings]
|
|
90
|
+
});
|
|
91
|
+
} else controller.enqueue(part);
|
|
92
|
+
} });
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { applyNeonCapabilities, mergeStreamStartWarnings };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=neon-capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neon-capabilities.js","names":[],"sources":["../../src/lib/neon-capabilities.ts"],"sourcesContent":["import type {\n\tLanguageModelV3CallOptions,\n\tLanguageModelV3StreamPart,\n\tSharedV3ProviderOptions,\n\tSharedV3Warning,\n} from \"@ai-sdk/provider\";\nimport { getNeonModelCapabilities } from \"./neon-model-capabilities.js\";\n\n/**\n * Drop call options the resolved model's upstream backend does not accept and\n * collect a warning for each, so callers get a clear signal instead of a hard\n * `400` from the gateway.\n */\nexport function applyNeonCapabilities(\n\tmodelId: string,\n\toptions: LanguageModelV3CallOptions,\n): { options: LanguageModelV3CallOptions; warnings: SharedV3Warning[] } {\n\tconst caps = getNeonModelCapabilities(modelId);\n\tconst warnings: SharedV3Warning[] = [];\n\tconst patch: Partial<LanguageModelV3CallOptions> = {};\n\n\tconst dropUnsupported = (feature: string) => {\n\t\twarnings.push({\n\t\t\ttype: \"unsupported\",\n\t\t\tfeature,\n\t\t\tdetails: `${feature} is not supported by the Neon AI Gateway for ${caps.family} model \"${modelId}\" and was dropped.`,\n\t\t});\n\t};\n\n\tif (options.temperature != null && !caps.supportsTemperature) {\n\t\tpatch.temperature = undefined;\n\t\tdropUnsupported(\"temperature\");\n\t}\n\tif (options.topP != null && !caps.supportsTopP) {\n\t\tpatch.topP = undefined;\n\t\tdropUnsupported(\"topP\");\n\t}\n\n\t// Anthropic-style models accept only one of temperature / topP.\n\tconst effectiveTemperature =\n\t\t\"temperature\" in patch ? patch.temperature : options.temperature;\n\tconst effectiveTopP = \"topP\" in patch ? patch.topP : options.topP;\n\tif (\n\t\tcaps.temperatureTopPMutuallyExclusive &&\n\t\teffectiveTemperature != null &&\n\t\teffectiveTopP != null\n\t) {\n\t\tpatch.topP = undefined;\n\t\twarnings.push({\n\t\t\ttype: \"compatibility\",\n\t\t\tfeature: \"topP\",\n\t\t\tdetails: `${caps.family} models accept only one of temperature or topP; topP was dropped.`,\n\t\t});\n\t}\n\n\tif (options.frequencyPenalty != null && !caps.supportsPenalties) {\n\t\tpatch.frequencyPenalty = undefined;\n\t\tdropUnsupported(\"frequencyPenalty\");\n\t}\n\tif (options.presencePenalty != null && !caps.supportsPenalties) {\n\t\tpatch.presencePenalty = undefined;\n\t\tdropUnsupported(\"presencePenalty\");\n\t}\n\tif (options.seed != null && !caps.supportsSeed) {\n\t\tpatch.seed = undefined;\n\t\tdropUnsupported(\"seed\");\n\t}\n\n\tif (options.stopSequences != null && !caps.supportsStopSequences) {\n\t\tpatch.stopSequences = undefined;\n\t\tdropUnsupported(\"stopSequences\");\n\t}\n\n\tif (!caps.supportsReasoningEffort) {\n\t\tconst { providerOptions } = options;\n\t\tconst hasProviderEffort =\n\t\t\tproviderOptions != null &&\n\t\t\tObject.values(providerOptions).some(\n\t\t\t\t(group) =>\n\t\t\t\t\t\"reasoningEffort\" in group && group.reasoningEffort != null,\n\t\t\t);\n\n\t\tif (hasProviderEffort) {\n\t\t\tdropUnsupported(\"reasoningEffort\");\n\t\t\tif (providerOptions != null) {\n\t\t\t\tconst cleaned: SharedV3ProviderOptions = {};\n\t\t\t\tfor (const [key, group] of Object.entries(providerOptions)) {\n\t\t\t\t\tif (\"reasoningEffort\" in group) {\n\t\t\t\t\t\tconst { reasoningEffort: _removed, ...rest } = group;\n\t\t\t\t\t\tcleaned[key] = rest;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcleaned[key] = group;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpatch.providerOptions = cleaned;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (Object.keys(patch).length === 0) {\n\t\treturn { options, warnings };\n\t}\n\treturn { options: { ...options, ...patch }, warnings };\n}\n\n/**\n * Merge additional warnings into the `stream-start` part of a model stream.\n */\nexport function mergeStreamStartWarnings(extra: SharedV3Warning[]) {\n\tlet merged = false;\n\treturn new TransformStream<\n\t\tLanguageModelV3StreamPart,\n\t\tLanguageModelV3StreamPart\n\t>({\n\t\ttransform(part, controller) {\n\t\t\tif (!merged && part.type === \"stream-start\") {\n\t\t\t\tmerged = true;\n\t\t\t\tcontroller.enqueue({\n\t\t\t\t\t...part,\n\t\t\t\t\twarnings: [...extra, ...part.warnings],\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tcontroller.enqueue(part);\n\t\t\t}\n\t\t},\n\t});\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,sBACf,SACA,SACuE;CACvE,MAAM,OAAO,yBAAyB,OAAO;CAC7C,MAAM,WAA8B,CAAC;CACrC,MAAM,QAA6C,CAAC;CAEpD,MAAM,mBAAmB,YAAoB;EAC5C,SAAS,KAAK;GACb,MAAM;GACN;GACA,SAAS,GAAG,QAAQ,+CAA+C,KAAK,OAAO,UAAU,QAAQ;EAClG,CAAC;CACF;CAEA,IAAI,QAAQ,eAAe,QAAQ,CAAC,KAAK,qBAAqB;EAC7D,MAAM,cAAc,KAAA;EACpB,gBAAgB,aAAa;CAC9B;CACA,IAAI,QAAQ,QAAQ,QAAQ,CAAC,KAAK,cAAc;EAC/C,MAAM,OAAO,KAAA;EACb,gBAAgB,MAAM;CACvB;CAGA,MAAM,uBACL,iBAAiB,QAAQ,MAAM,cAAc,QAAQ;CACtD,MAAM,gBAAgB,UAAU,QAAQ,MAAM,OAAO,QAAQ;CAC7D,IACC,KAAK,oCACL,wBAAwB,QACxB,iBAAiB,MAChB;EACD,MAAM,OAAO,KAAA;EACb,SAAS,KAAK;GACb,MAAM;GACN,SAAS;GACT,SAAS,GAAG,KAAK,OAAO;EACzB,CAAC;CACF;CAEA,IAAI,QAAQ,oBAAoB,QAAQ,CAAC,KAAK,mBAAmB;EAChE,MAAM,mBAAmB,KAAA;EACzB,gBAAgB,kBAAkB;CACnC;CACA,IAAI,QAAQ,mBAAmB,QAAQ,CAAC,KAAK,mBAAmB;EAC/D,MAAM,kBAAkB,KAAA;EACxB,gBAAgB,iBAAiB;CAClC;CACA,IAAI,QAAQ,QAAQ,QAAQ,CAAC,KAAK,cAAc;EAC/C,MAAM,OAAO,KAAA;EACb,gBAAgB,MAAM;CACvB;CAEA,IAAI,QAAQ,iBAAiB,QAAQ,CAAC,KAAK,uBAAuB;EACjE,MAAM,gBAAgB,KAAA;EACtB,gBAAgB,eAAe;CAChC;CAEA,IAAI,CAAC,KAAK,yBAAyB;EAClC,MAAM,EAAE,oBAAoB;EAQ5B,IANC,mBAAmB,QACnB,OAAO,OAAO,eAAe,CAAC,CAAC,MAC7B,UACA,qBAAqB,SAAS,MAAM,mBAAmB,IACzD,GAEsB;GACtB,gBAAgB,iBAAiB;GACjC,IAAI,mBAAmB,MAAM;IAC5B,MAAM,UAAmC,CAAC;IAC1C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,eAAe,GACxD,IAAI,qBAAqB,OAAO;KAC/B,MAAM,EAAE,iBAAiB,UAAU,GAAG,SAAS;KAC/C,QAAQ,OAAO;IAChB,OACC,QAAQ,OAAO;IAGjB,MAAM,kBAAkB;GACzB;EACD;CACD;CAEA,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,GACjC,OAAO;EAAE;EAAS;CAAS;CAE5B,OAAO;EAAE,SAAS;GAAE,GAAG;GAAS,GAAG;EAAM;EAAG;CAAS;AACtD;;;;AAKA,SAAgB,yBAAyB,OAA0B;CAClE,IAAI,SAAS;CACb,OAAO,IAAI,gBAGT,EACD,UAAU,MAAM,YAAY;EAC3B,IAAI,CAAC,UAAU,KAAK,SAAS,gBAAgB;GAC5C,SAAS;GACT,WAAW,QAAQ;IAClB,GAAG;IACH,UAAU,CAAC,GAAG,OAAO,GAAG,KAAK,QAAQ;GACtC,CAAC;EACF,OACC,WAAW,QAAQ,IAAI;CAEzB,EACD,CAAC;AACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { OpenAICompatibleChatLanguageModel } from "@ai-sdk/openai-compatible";
|
|
2
|
+
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from "@ai-sdk/provider";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/neon-chat-language-model.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Language model for the Neon AI Gateway unified (MLflow) endpoint.
|
|
8
|
+
*
|
|
9
|
+
* Used for every model that is not routed to a provider-native endpoint
|
|
10
|
+
* (Gemini, Llama, Qwen, gpt-oss, ...). It is a thin specialization of the shared
|
|
11
|
+
* OpenAI-compatible chat model that adds per-model capability handling:
|
|
12
|
+
* parameters an upstream backend is known to reject are dropped and reported as
|
|
13
|
+
* warnings instead of failing the request.
|
|
14
|
+
*/
|
|
15
|
+
declare class NeonChatLanguageModel extends OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
|
|
16
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
17
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { NeonChatLanguageModel };
|
|
21
|
+
//# sourceMappingURL=neon-chat-language-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neon-chat-language-model.d.ts","names":[],"sources":["../../src/lib/neon-chat-language-model.ts"],"mappings":";;;;;;;AAqBA;;;;;;;AAmBI,cAnBS,qBAAA,SACJ,iCAAA,YACG,eAiBR,CAAA;YAlBK,CAAA,OAAA,EAIE,0BAJF,CAAA,EAKL,OALK,CAKG,6BALH,CAAA;UACG,CAAA,OAAA,EAgBD,0BAhBC,CAAA,EAiBR,OAjBQ,CAiBA,2BAjBA,CAAA;AAAe"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { applyNeonCapabilities, mergeStreamStartWarnings } from "./neon-capabilities.js";
|
|
2
|
+
import { OpenAICompatibleChatLanguageModel } from "@ai-sdk/openai-compatible";
|
|
3
|
+
//#region src/lib/neon-chat-language-model.ts
|
|
4
|
+
/**
|
|
5
|
+
* Language model for the Neon AI Gateway unified (MLflow) endpoint.
|
|
6
|
+
*
|
|
7
|
+
* Used for every model that is not routed to a provider-native endpoint
|
|
8
|
+
* (Gemini, Llama, Qwen, gpt-oss, ...). It is a thin specialization of the shared
|
|
9
|
+
* OpenAI-compatible chat model that adds per-model capability handling:
|
|
10
|
+
* parameters an upstream backend is known to reject are dropped and reported as
|
|
11
|
+
* warnings instead of failing the request.
|
|
12
|
+
*/
|
|
13
|
+
var NeonChatLanguageModel = class extends OpenAICompatibleChatLanguageModel {
|
|
14
|
+
async doGenerate(options) {
|
|
15
|
+
const { options: adjusted, warnings } = applyNeonCapabilities(this.modelId, options);
|
|
16
|
+
const result = await super.doGenerate(adjusted);
|
|
17
|
+
return warnings.length > 0 ? {
|
|
18
|
+
...result,
|
|
19
|
+
warnings: [...warnings, ...result.warnings]
|
|
20
|
+
} : result;
|
|
21
|
+
}
|
|
22
|
+
async doStream(options) {
|
|
23
|
+
const { options: adjusted, warnings } = applyNeonCapabilities(this.modelId, options);
|
|
24
|
+
const result = await super.doStream(adjusted);
|
|
25
|
+
return warnings.length > 0 ? {
|
|
26
|
+
...result,
|
|
27
|
+
stream: result.stream.pipeThrough(mergeStreamStartWarnings(warnings))
|
|
28
|
+
} : result;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { NeonChatLanguageModel };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=neon-chat-language-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neon-chat-language-model.js","names":[],"sources":["../../src/lib/neon-chat-language-model.ts"],"sourcesContent":["import { OpenAICompatibleChatLanguageModel } from \"@ai-sdk/openai-compatible\";\nimport type {\n\tLanguageModelV3,\n\tLanguageModelV3CallOptions,\n\tLanguageModelV3GenerateResult,\n\tLanguageModelV3StreamResult,\n} from \"@ai-sdk/provider\";\nimport {\n\tapplyNeonCapabilities,\n\tmergeStreamStartWarnings,\n} from \"./neon-capabilities.js\";\n\n/**\n * Language model for the Neon AI Gateway unified (MLflow) endpoint.\n *\n * Used for every model that is not routed to a provider-native endpoint\n * (Gemini, Llama, Qwen, gpt-oss, ...). It is a thin specialization of the shared\n * OpenAI-compatible chat model that adds per-model capability handling:\n * parameters an upstream backend is known to reject are dropped and reported as\n * warnings instead of failing the request.\n */\nexport class NeonChatLanguageModel\n\textends OpenAICompatibleChatLanguageModel\n\timplements LanguageModelV3\n{\n\toverride async doGenerate(\n\t\toptions: LanguageModelV3CallOptions,\n\t): Promise<LanguageModelV3GenerateResult> {\n\t\tconst { options: adjusted, warnings } = applyNeonCapabilities(\n\t\t\tthis.modelId,\n\t\t\toptions,\n\t\t);\n\t\tconst result = await super.doGenerate(adjusted);\n\t\treturn warnings.length > 0\n\t\t\t? { ...result, warnings: [...warnings, ...result.warnings] }\n\t\t\t: result;\n\t}\n\n\toverride async doStream(\n\t\toptions: LanguageModelV3CallOptions,\n\t): Promise<LanguageModelV3StreamResult> {\n\t\tconst { options: adjusted, warnings } = applyNeonCapabilities(\n\t\t\tthis.modelId,\n\t\t\toptions,\n\t\t);\n\t\tconst result = await super.doStream(adjusted);\n\t\treturn warnings.length > 0\n\t\t\t? {\n\t\t\t\t\t...result,\n\t\t\t\t\tstream: result.stream.pipeThrough(\n\t\t\t\t\t\tmergeStreamStartWarnings(warnings),\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: result;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,IAAa,wBAAb,cACS,kCAET;CACC,MAAe,WACd,SACyC;EACzC,MAAM,EAAE,SAAS,UAAU,aAAa,sBACvC,KAAK,SACL,OACD;EACA,MAAM,SAAS,MAAM,MAAM,WAAW,QAAQ;EAC9C,OAAO,SAAS,SAAS,IACtB;GAAE,GAAG;GAAQ,UAAU,CAAC,GAAG,UAAU,GAAG,OAAO,QAAQ;EAAE,IACzD;CACJ;CAEA,MAAe,SACd,SACuC;EACvC,MAAM,EAAE,SAAS,UAAU,aAAa,sBACvC,KAAK,SACL,OACD;EACA,MAAM,SAAS,MAAM,MAAM,SAAS,QAAQ;EAC5C,OAAO,SAAS,SAAS,IACtB;GACA,GAAG;GACH,QAAQ,OAAO,OAAO,YACrB,yBAAyB,QAAQ,CAClC;EACD,IACC;CACJ;AACD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/lib/neon-chat-options.d.ts
|
|
2
|
+
/** The models.dev `neon` catalog (canonical, unprefixed ids). */
|
|
3
|
+
declare const NEON_MODELS_DEV_IDS: readonly ["claude-opus-4-7", "claude-opus-4-6", "claude-opus-4-5", "claude-opus-4-1", "claude-sonnet-4-6", "claude-sonnet-4-5", "claude-sonnet-4", "claude-haiku-4-5", "gpt-5", "gpt-5-mini", "gpt-5-nano", "gpt-5-1", "gpt-5-2", "gpt-5-4", "gpt-5-4-mini", "gpt-5-4-nano", "gpt-5-5", "gpt-oss-120b", "gpt-oss-20b", "gemini-3-pro", "gemini-3-flash", "gemini-3-1-pro", "gemini-3-1-flash-lite", "gemini-2-5-pro", "gemini-2-5-flash"];
|
|
4
|
+
/**
|
|
5
|
+
* Ids the gateway serves that the models.dev `neon` provider does not list.
|
|
6
|
+
* Verified to resolve against the gateway; retained for autocomplete. If
|
|
7
|
+
* models.dev later lists one of these, the drift check flags it for promotion
|
|
8
|
+
* into `NEON_MODELS_DEV_IDS`.
|
|
9
|
+
*/
|
|
10
|
+
declare const NEON_EXTRA_MODEL_IDS: readonly ["claude-opus-4-8", "gpt-5-2-codex", "gpt-5-3-codex", "gpt-5-5-pro", "gemini-3-5-flash", "gemma-3-12b", "llama-4-maverick", "meta-llama-3-3-70b-instruct", "meta-llama-3-1-8b-instruct", "qwen3-next-80b-a3b-instruct", "qwen35-122b-a10b"];
|
|
11
|
+
/** A known Neon AI Gateway model id (models.dev catalog + gateway extras). */
|
|
12
|
+
type NeonKnownModelId = (typeof NEON_MODELS_DEV_IDS)[number] | (typeof NEON_EXTRA_MODEL_IDS)[number];
|
|
13
|
+
/**
|
|
14
|
+
* A Neon AI Gateway model id. Known ids are listed for autocomplete; any other
|
|
15
|
+
* id (e.g. a brand-new model, or the legacy `databricks-` prefixed form) is
|
|
16
|
+
* accepted via the `(string & {})` fallback.
|
|
17
|
+
*/
|
|
18
|
+
type NeonChatModelId = NeonKnownModelId | (string & {});
|
|
19
|
+
//#endregion
|
|
20
|
+
export { NEON_EXTRA_MODEL_IDS, NEON_MODELS_DEV_IDS, NeonChatModelId, NeonKnownModelId };
|
|
21
|
+
//# sourceMappingURL=neon-chat-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neon-chat-options.d.ts","names":[],"sources":["../../src/lib/neon-chat-options.ts"],"mappings":";;AAiBa,cAAA,mBA8BH,EAAA,SAAA,CAAA,iBAAA,EAAA,iBAAA,EAAA,iBAAA,EAAA,iBAAA,EAAA,mBAAA,EAAA,mBAAA,EAAA,iBAAA,EAAA,kBAAA,EAAA,OAAA,EAAA,YAAA,EAAA,YAAA,EAAA,SAAA,EAAA,SAAA,EAAA,SAAA,EAAA,cAAA,EAAA,cAAA,EAAA,SAAA,EAAA,cAAA,EAAA,aAAA,EAAA,cAAA,EAAA,gBAAA,EAAA,gBAAA,EAAA,uBAAA,EAAA,gBAAA,EAAA,kBAAA,CAAA;AAQV;AAoBA;;;;AAE+B;AAOnB,cA7BC,oBA6BiB,EAAA,SAAgB,CAAA,iBAAA,EAAA,eAAA,EAAA,eAAA,EAAA,aAAA,EAAA,kBAAA,EAAA,aAAA,EAAA,kBAAA,EAAA,6BAAA,EAAA,4BAAA,EAAA,6BAAA,EAAA,kBAAA,CAAA;;KATlC,gBAAA,WACD,uCACA;;;;;;KAOC,eAAA,GAAkB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/lib/neon-chat-options.ts
|
|
2
|
+
/** The models.dev `neon` catalog (canonical, unprefixed ids). */
|
|
3
|
+
const NEON_MODELS_DEV_IDS = [
|
|
4
|
+
"claude-opus-4-7",
|
|
5
|
+
"claude-opus-4-6",
|
|
6
|
+
"claude-opus-4-5",
|
|
7
|
+
"claude-opus-4-1",
|
|
8
|
+
"claude-sonnet-4-6",
|
|
9
|
+
"claude-sonnet-4-5",
|
|
10
|
+
"claude-sonnet-4",
|
|
11
|
+
"claude-haiku-4-5",
|
|
12
|
+
"gpt-5",
|
|
13
|
+
"gpt-5-mini",
|
|
14
|
+
"gpt-5-nano",
|
|
15
|
+
"gpt-5-1",
|
|
16
|
+
"gpt-5-2",
|
|
17
|
+
"gpt-5-4",
|
|
18
|
+
"gpt-5-4-mini",
|
|
19
|
+
"gpt-5-4-nano",
|
|
20
|
+
"gpt-5-5",
|
|
21
|
+
"gpt-oss-120b",
|
|
22
|
+
"gpt-oss-20b",
|
|
23
|
+
"gemini-3-pro",
|
|
24
|
+
"gemini-3-flash",
|
|
25
|
+
"gemini-3-1-pro",
|
|
26
|
+
"gemini-3-1-flash-lite",
|
|
27
|
+
"gemini-2-5-pro",
|
|
28
|
+
"gemini-2-5-flash"
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* Ids the gateway serves that the models.dev `neon` provider does not list.
|
|
32
|
+
* Verified to resolve against the gateway; retained for autocomplete. If
|
|
33
|
+
* models.dev later lists one of these, the drift check flags it for promotion
|
|
34
|
+
* into `NEON_MODELS_DEV_IDS`.
|
|
35
|
+
*/
|
|
36
|
+
const NEON_EXTRA_MODEL_IDS = [
|
|
37
|
+
"claude-opus-4-8",
|
|
38
|
+
"gpt-5-2-codex",
|
|
39
|
+
"gpt-5-3-codex",
|
|
40
|
+
"gpt-5-5-pro",
|
|
41
|
+
"gemini-3-5-flash",
|
|
42
|
+
"gemma-3-12b",
|
|
43
|
+
"llama-4-maverick",
|
|
44
|
+
"meta-llama-3-3-70b-instruct",
|
|
45
|
+
"meta-llama-3-1-8b-instruct",
|
|
46
|
+
"qwen3-next-80b-a3b-instruct",
|
|
47
|
+
"qwen35-122b-a10b"
|
|
48
|
+
];
|
|
49
|
+
//#endregion
|
|
50
|
+
export { NEON_EXTRA_MODEL_IDS, NEON_MODELS_DEV_IDS };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=neon-chat-options.js.map
|