@neondatabase/ai-sdk-provider 0.0.0 → 0.1.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/LICENSE.md +178 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -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 +101 -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 +5 -0
- package/dist/lib/neon-chat-options.d.ts.map +1 -0
- package/dist/lib/neon-chat-options.js +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 +26 -0
- package/dist/lib/neon-responses-language-model.d.ts.map +1 -0
- package/dist/lib/neon-responses-language-model.js +44 -0
- package/dist/lib/neon-responses-language-model.js.map +1 -0
- package/dist/lib/provider.d.ts +48 -0
- package/dist/lib/provider.d.ts.map +1 -0
- package/dist/lib/provider.js +112 -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 +6 -0
- package/package.json +74 -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
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { OpenAICompatibleChatLanguageModel } from "@ai-sdk/openai-compatible";
|
|
2
|
-
import type {
|
|
3
|
-
LanguageModelV4,
|
|
4
|
-
LanguageModelV4CallOptions,
|
|
5
|
-
LanguageModelV4GenerateResult,
|
|
6
|
-
LanguageModelV4StreamResult,
|
|
7
|
-
} from "@ai-sdk/provider";
|
|
8
|
-
import {
|
|
9
|
-
applyNeonCapabilities,
|
|
10
|
-
mergeStreamStartWarnings,
|
|
11
|
-
} from "./neon-capabilities.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Language model for the Neon AI Gateway unified (MLflow) endpoint.
|
|
15
|
-
*
|
|
16
|
-
* Used for every model that is not routed to a provider-native endpoint
|
|
17
|
-
* (Gemini, Llama, Qwen, gpt-oss, ...). It is a thin specialization of the shared
|
|
18
|
-
* OpenAI-compatible chat model that adds per-model capability handling:
|
|
19
|
-
* parameters an upstream backend is known to reject are dropped and reported as
|
|
20
|
-
* warnings instead of failing the request.
|
|
21
|
-
*/
|
|
22
|
-
export class NeonChatLanguageModel
|
|
23
|
-
extends OpenAICompatibleChatLanguageModel
|
|
24
|
-
implements LanguageModelV4
|
|
25
|
-
{
|
|
26
|
-
override async doGenerate(
|
|
27
|
-
options: LanguageModelV4CallOptions,
|
|
28
|
-
): Promise<LanguageModelV4GenerateResult> {
|
|
29
|
-
const { options: adjusted, warnings } = applyNeonCapabilities(
|
|
30
|
-
this.modelId,
|
|
31
|
-
options,
|
|
32
|
-
);
|
|
33
|
-
const result = await super.doGenerate(adjusted);
|
|
34
|
-
return warnings.length > 0
|
|
35
|
-
? { ...result, warnings: [...warnings, ...result.warnings] }
|
|
36
|
-
: result;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
override async doStream(
|
|
40
|
-
options: LanguageModelV4CallOptions,
|
|
41
|
-
): Promise<LanguageModelV4StreamResult> {
|
|
42
|
-
const { options: adjusted, warnings } = applyNeonCapabilities(
|
|
43
|
-
this.modelId,
|
|
44
|
-
options,
|
|
45
|
-
);
|
|
46
|
-
const result = await super.doStream(adjusted);
|
|
47
|
-
return warnings.length > 0
|
|
48
|
-
? {
|
|
49
|
-
...result,
|
|
50
|
-
stream: result.stream.pipeThrough(
|
|
51
|
-
mergeStreamStartWarnings(warnings),
|
|
52
|
-
),
|
|
53
|
-
}
|
|
54
|
-
: result;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// Models served by the Neon AI Gateway. Anthropic and OpenAI models are routed
|
|
2
|
-
// to their provider-native endpoints; everything else uses the unified MLflow
|
|
3
|
-
// (OpenAI-compatible) endpoint.
|
|
4
|
-
//
|
|
5
|
-
// The authoritative, always-current catalog is shown in the Neon Console under
|
|
6
|
-
// the branch's "AI Gateway" tab. Any other id can be passed as a plain string
|
|
7
|
-
// via the `(string & {})` fallback.
|
|
8
|
-
export type NeonChatModelId =
|
|
9
|
-
// Anthropic (native Messages API)
|
|
10
|
-
| "databricks-claude-opus-4-8"
|
|
11
|
-
| "databricks-claude-opus-4-7"
|
|
12
|
-
| "databricks-claude-opus-4-6"
|
|
13
|
-
| "databricks-claude-opus-4-5"
|
|
14
|
-
| "databricks-claude-opus-4-1"
|
|
15
|
-
| "databricks-claude-sonnet-4-6"
|
|
16
|
-
| "databricks-claude-sonnet-4-5"
|
|
17
|
-
| "databricks-claude-sonnet-4"
|
|
18
|
-
| "databricks-claude-haiku-4-5"
|
|
19
|
-
// OpenAI (native Responses API, incl. Codex)
|
|
20
|
-
| "databricks-gpt-5"
|
|
21
|
-
| "databricks-gpt-5-mini"
|
|
22
|
-
| "databricks-gpt-5-nano"
|
|
23
|
-
| "databricks-gpt-5-1"
|
|
24
|
-
| "databricks-gpt-5-2"
|
|
25
|
-
| "databricks-gpt-5-2-codex"
|
|
26
|
-
| "databricks-gpt-5-3-codex"
|
|
27
|
-
| "databricks-gpt-5-4"
|
|
28
|
-
| "databricks-gpt-5-4-mini"
|
|
29
|
-
| "databricks-gpt-5-4-nano"
|
|
30
|
-
| "databricks-gpt-5-5"
|
|
31
|
-
| "databricks-gpt-5-5-pro"
|
|
32
|
-
// OpenAI open-weight (unified MLflow endpoint)
|
|
33
|
-
| "databricks-gpt-oss-120b"
|
|
34
|
-
| "databricks-gpt-oss-20b"
|
|
35
|
-
// Google (unified MLflow endpoint)
|
|
36
|
-
| "databricks-gemini-3-5-flash"
|
|
37
|
-
| "databricks-gemini-3-1-flash-lite"
|
|
38
|
-
| "databricks-gemini-2-5-pro"
|
|
39
|
-
| "databricks-gemini-2-5-flash"
|
|
40
|
-
| "databricks-gemma-3-12b"
|
|
41
|
-
// Meta (unified MLflow endpoint)
|
|
42
|
-
| "databricks-llama-4-maverick"
|
|
43
|
-
| "databricks-meta-llama-3-3-70b-instruct"
|
|
44
|
-
| "databricks-meta-llama-3-1-8b-instruct"
|
|
45
|
-
// Alibaba (unified MLflow endpoint)
|
|
46
|
-
| "databricks-qwen3-next-80b-a3b-instruct"
|
|
47
|
-
| "databricks-qwen35-122b-a10b"
|
|
48
|
-
| (string & {});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
getNeonModelCapabilities,
|
|
4
|
-
getNeonModelRoute,
|
|
5
|
-
} from "./neon-model-capabilities.js";
|
|
6
|
-
|
|
7
|
-
describe("getNeonModelRoute", () => {
|
|
8
|
-
it("routes Anthropic and OpenAI models to their native endpoints", () => {
|
|
9
|
-
expect(getNeonModelRoute("databricks-claude-opus-4-8")).toBe(
|
|
10
|
-
"anthropic",
|
|
11
|
-
);
|
|
12
|
-
expect(getNeonModelRoute("databricks-claude-haiku-4-5")).toBe(
|
|
13
|
-
"anthropic",
|
|
14
|
-
);
|
|
15
|
-
expect(getNeonModelRoute("databricks-gpt-5")).toBe("openai");
|
|
16
|
-
expect(getNeonModelRoute("databricks-gpt-5-mini")).toBe("openai");
|
|
17
|
-
expect(getNeonModelRoute("databricks-gpt-5-3-codex")).toBe("openai");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("falls back to the unified MLflow endpoint for everything else", () => {
|
|
21
|
-
// Gemini is routed to MLflow because its native endpoint cannot stream.
|
|
22
|
-
expect(getNeonModelRoute("databricks-gemini-2-5-flash")).toBe("mlflow");
|
|
23
|
-
expect(getNeonModelRoute("databricks-llama-4-maverick")).toBe("mlflow");
|
|
24
|
-
expect(getNeonModelRoute("databricks-qwen35-122b-a10b")).toBe("mlflow");
|
|
25
|
-
// gpt-oss is open-weight and served on the unified endpoint, not Responses.
|
|
26
|
-
expect(getNeonModelRoute("databricks-gpt-oss-120b")).toBe("mlflow");
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe("getNeonModelCapabilities", () => {
|
|
31
|
-
it("marks Anthropic models correctly", () => {
|
|
32
|
-
const caps = getNeonModelCapabilities("databricks-claude-haiku-4-5");
|
|
33
|
-
expect(caps.family).toBe("anthropic");
|
|
34
|
-
expect(caps.supportsPenalties).toBe(false);
|
|
35
|
-
expect(caps.supportsSeed).toBe(false);
|
|
36
|
-
expect(caps.temperatureTopPMutuallyExclusive).toBe(true);
|
|
37
|
-
expect(caps.supportsReasoningEffort).toBe(false);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("marks plain GPT-5 reasoning models without temperature/topP support", () => {
|
|
41
|
-
const caps = getNeonModelCapabilities("databricks-gpt-5-mini");
|
|
42
|
-
expect(caps.family).toBe("openai");
|
|
43
|
-
expect(caps.supportsTemperature).toBe(false);
|
|
44
|
-
expect(caps.supportsTopP).toBe(false);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("keeps temperature for gpt-5.1+ models", () => {
|
|
48
|
-
const caps = getNeonModelCapabilities("databricks-gpt-5-1");
|
|
49
|
-
expect(caps.supportsTemperature).toBe(true);
|
|
50
|
-
expect(caps.supportsTopP).toBe(true);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("marks Meta models without penalties/seed support", () => {
|
|
54
|
-
const caps = getNeonModelCapabilities("databricks-llama-4-maverick");
|
|
55
|
-
expect(caps.family).toBe("meta");
|
|
56
|
-
expect(caps.supportsPenalties).toBe(false);
|
|
57
|
-
expect(caps.supportsSeed).toBe(false);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("is permissive for unknown models", () => {
|
|
61
|
-
const caps = getNeonModelCapabilities("databricks-qwen35-122b-a10b");
|
|
62
|
-
expect(caps.family).toBe("other");
|
|
63
|
-
expect(caps.supportsPenalties).toBe(true);
|
|
64
|
-
expect(caps.supportsReasoningEffort).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
export type NeonModelFamily =
|
|
2
|
-
| "anthropic"
|
|
3
|
-
| "google"
|
|
4
|
-
| "openai"
|
|
5
|
-
| "meta"
|
|
6
|
-
| "other";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Which gateway endpoint a model should be routed to.
|
|
10
|
-
*
|
|
11
|
-
* - `anthropic`: native Messages API — streaming structured output + native reasoning.
|
|
12
|
-
* - `openai`: native Responses API — models served only natively (e.g. Codex),
|
|
13
|
-
* native reasoning, and the image-generation tool.
|
|
14
|
-
* - `mlflow`: the unified, OpenAI-compatible endpoint (the fallback). Gemini is
|
|
15
|
-
* routed here because the gateway's native Gemini endpoint does not support
|
|
16
|
-
* streaming (`streamGenerateContent` is rejected).
|
|
17
|
-
*/
|
|
18
|
-
export type NeonModelRoute = "anthropic" | "openai" | "mlflow";
|
|
19
|
-
|
|
20
|
-
export function getNeonModelRoute(modelId: string): NeonModelRoute {
|
|
21
|
-
const id = modelId.toLowerCase();
|
|
22
|
-
if (id.includes("claude")) {
|
|
23
|
-
return "anthropic";
|
|
24
|
-
}
|
|
25
|
-
// OpenAI proprietary models (gpt-4/gpt-5 families, Codex) are served only via
|
|
26
|
-
// the native Responses API. `gpt-oss` is open-weight and served on the
|
|
27
|
-
// unified chat endpoint, so it is intentionally excluded here.
|
|
28
|
-
if (
|
|
29
|
-
(id.includes("gpt-") && !id.includes("gpt-oss")) ||
|
|
30
|
-
id.includes("codex")
|
|
31
|
-
) {
|
|
32
|
-
return "openai";
|
|
33
|
-
}
|
|
34
|
-
return "mlflow";
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface NeonModelCapabilities {
|
|
38
|
-
family: NeonModelFamily;
|
|
39
|
-
supportsTemperature: boolean;
|
|
40
|
-
supportsTopP: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Whether `temperature` and `topP` may be sent together. Anthropic models
|
|
43
|
-
* accept only one of the two.
|
|
44
|
-
*/
|
|
45
|
-
temperatureTopPMutuallyExclusive: boolean;
|
|
46
|
-
supportsPenalties: boolean;
|
|
47
|
-
supportsSeed: boolean;
|
|
48
|
-
supportsStopSequences: boolean;
|
|
49
|
-
supportsReasoningEffort: boolean;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const PERMISSIVE: Omit<NeonModelCapabilities, "family"> = {
|
|
53
|
-
supportsTemperature: true,
|
|
54
|
-
supportsTopP: true,
|
|
55
|
-
temperatureTopPMutuallyExclusive: false,
|
|
56
|
-
supportsPenalties: true,
|
|
57
|
-
supportsSeed: true,
|
|
58
|
-
supportsStopSequences: true,
|
|
59
|
-
supportsReasoningEffort: true,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Heuristic, prefix-based capability detection for MLflow-routed Neon models.
|
|
64
|
-
*
|
|
65
|
-
* The unified endpoint proxies to heterogeneous upstream providers, each of
|
|
66
|
-
* which accepts a different subset of the OpenAI-style parameters the AI SDK
|
|
67
|
-
* emits. Sending a parameter an upstream rejects results in a hard `400`, so we
|
|
68
|
-
* strip the parameters a family is known to reject and surface a warning
|
|
69
|
-
* instead. Unknown/untested models stay permissive (passed through unchanged).
|
|
70
|
-
*/
|
|
71
|
-
export function getNeonModelCapabilities(
|
|
72
|
-
modelId: string,
|
|
73
|
-
): NeonModelCapabilities {
|
|
74
|
-
const id = modelId.toLowerCase();
|
|
75
|
-
|
|
76
|
-
// Anthropic (Claude): rejects penalties and seed, accepts only one of
|
|
77
|
-
// temperature/topP, and rejects the OpenAI `reasoning_effort` field.
|
|
78
|
-
if (id.includes("claude")) {
|
|
79
|
-
return {
|
|
80
|
-
family: "anthropic",
|
|
81
|
-
supportsTemperature: true,
|
|
82
|
-
supportsTopP: true,
|
|
83
|
-
temperatureTopPMutuallyExclusive: true,
|
|
84
|
-
supportsPenalties: false,
|
|
85
|
-
supportsSeed: false,
|
|
86
|
-
supportsStopSequences: true,
|
|
87
|
-
supportsReasoningEffort: false,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Google (Gemini): accepts standard sampling params but rejects the OpenAI
|
|
92
|
-
// `reasoning_effort` field (not part of Gemini's generation config).
|
|
93
|
-
if (id.includes("gemini")) {
|
|
94
|
-
return {
|
|
95
|
-
family: "google",
|
|
96
|
-
...PERMISSIVE,
|
|
97
|
-
supportsReasoningEffort: false,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// OpenAI GPT-5 reasoning family (routed to the native Responses API). The
|
|
102
|
-
// Responses model strips parameters the Responses API doesn't accept
|
|
103
|
-
// (penalties, seed, stop), but its reasoning-model detection matches the bare
|
|
104
|
-
// model id (`gpt-5`), which the gateway's `databricks-` prefix defeats. So we
|
|
105
|
-
// only handle the temperature/topP restriction here: the original gpt-5 /
|
|
106
|
-
// gpt-5-mini / gpt-5-nano require the default temperature and reject topP,
|
|
107
|
-
// while gpt-5.1+ (a minor version digit follows) accept them again.
|
|
108
|
-
if (/gpt-5/.test(id)) {
|
|
109
|
-
const hasMinorVersion = /gpt-5[.-]\d/.test(id);
|
|
110
|
-
return {
|
|
111
|
-
family: "openai",
|
|
112
|
-
supportsTemperature: hasMinorVersion,
|
|
113
|
-
supportsTopP: hasMinorVersion,
|
|
114
|
-
temperatureTopPMutuallyExclusive: false,
|
|
115
|
-
supportsPenalties: true,
|
|
116
|
-
supportsSeed: true,
|
|
117
|
-
supportsStopSequences: true,
|
|
118
|
-
supportsReasoningEffort: true,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Meta (Llama): rejects penalties and seed; accepts sampling params and stop.
|
|
123
|
-
if (id.includes("llama")) {
|
|
124
|
-
return {
|
|
125
|
-
family: "meta",
|
|
126
|
-
supportsTemperature: true,
|
|
127
|
-
supportsTopP: true,
|
|
128
|
-
temperatureTopPMutuallyExclusive: false,
|
|
129
|
-
supportsPenalties: false,
|
|
130
|
-
supportsSeed: false,
|
|
131
|
-
supportsStopSequences: true,
|
|
132
|
-
supportsReasoningEffort: true,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return { family: "other", ...PERMISSIVE };
|
|
137
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { OpenAIResponsesLanguageModel } from "@ai-sdk/openai/internal";
|
|
2
|
-
import type {
|
|
3
|
-
LanguageModelV4,
|
|
4
|
-
LanguageModelV4CallOptions,
|
|
5
|
-
LanguageModelV4GenerateResult,
|
|
6
|
-
LanguageModelV4StreamResult,
|
|
7
|
-
} from "@ai-sdk/provider";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Language model for OpenAI models served via the Neon AI Gateway's native
|
|
11
|
-
* Responses API (`/ai-gateway/openai/v1/responses`). This route is required for
|
|
12
|
-
* models that are only served natively (e.g. Codex) and unlocks native
|
|
13
|
-
* reasoning and the image-generation tool.
|
|
14
|
-
*
|
|
15
|
-
* The shared OpenAI Responses model shapes a request based on whether the model
|
|
16
|
-
* is a reasoning model, but it detects that from the bare model id (`gpt-5`),
|
|
17
|
-
* which the gateway's required `databricks-` prefix defeats. For the GPT-5
|
|
18
|
-
* reasoning family we set the model's own `forceReasoning` provider option so it
|
|
19
|
-
* applies the correct reasoning behavior. Users can still override it.
|
|
20
|
-
*/
|
|
21
|
-
export class NeonResponsesLanguageModel
|
|
22
|
-
extends OpenAIResponsesLanguageModel
|
|
23
|
-
implements LanguageModelV4
|
|
24
|
-
{
|
|
25
|
-
private get isReasoningFamily(): boolean {
|
|
26
|
-
return /gpt-5/.test(this.modelId.toLowerCase());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private withForcedReasoning(
|
|
30
|
-
options: LanguageModelV4CallOptions,
|
|
31
|
-
): LanguageModelV4CallOptions {
|
|
32
|
-
if (!this.isReasoningFamily) {
|
|
33
|
-
return options;
|
|
34
|
-
}
|
|
35
|
-
const openai = options.providerOptions?.openai;
|
|
36
|
-
// Respect an explicit user setting.
|
|
37
|
-
if (openai != null && "forceReasoning" in openai) {
|
|
38
|
-
return options;
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
...options,
|
|
42
|
-
providerOptions: {
|
|
43
|
-
...options.providerOptions,
|
|
44
|
-
openai: { ...openai, forceReasoning: true },
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
override doGenerate(
|
|
50
|
-
options: LanguageModelV4CallOptions,
|
|
51
|
-
): Promise<LanguageModelV4GenerateResult> {
|
|
52
|
-
return super.doGenerate(this.withForcedReasoning(options));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
override doStream(
|
|
56
|
-
options: LanguageModelV4CallOptions,
|
|
57
|
-
): Promise<LanguageModelV4StreamResult> {
|
|
58
|
-
return super.doStream(this.withForcedReasoning(options));
|
|
59
|
-
}
|
|
60
|
-
}
|
package/src/lib/provider.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Community Vercel AI SDK provider for the Neon AI Gateway.
|
|
3
|
-
*
|
|
4
|
-
* `createNeon()` returns a provider that routes each model to the best gateway
|
|
5
|
-
* endpoint based on its id (Anthropic → native Messages, OpenAI → native
|
|
6
|
-
* Responses incl. Codex, everything else → unified MLflow), so a single
|
|
7
|
-
* `neon('databricks-...')` call (same base URL + token) reaches the whole
|
|
8
|
-
* catalog. Configure with the branch-scoped `NEON_AI_GATEWAY_BASE_URL` +
|
|
9
|
-
* `NEON_AI_GATEWAY_TOKEN` emitted by `neonctl env pull` / `neon dev`, or pass
|
|
10
|
-
* `baseURL` / `apiKey` explicitly.
|
|
11
|
-
*/
|
|
12
|
-
import type { ProviderErrorStructure } from "@ai-sdk/openai-compatible";
|
|
13
|
-
import {
|
|
14
|
-
type LanguageModelV4,
|
|
15
|
-
NoSuchModelError,
|
|
16
|
-
type ProviderV4,
|
|
17
|
-
} from "@ai-sdk/provider";
|
|
18
|
-
import {
|
|
19
|
-
type FetchFunction,
|
|
20
|
-
generateId,
|
|
21
|
-
loadApiKey,
|
|
22
|
-
loadSetting,
|
|
23
|
-
withoutTrailingSlash,
|
|
24
|
-
withUserAgentSuffix,
|
|
25
|
-
} from "@ai-sdk/provider-utils";
|
|
26
|
-
import { z } from "zod/v4";
|
|
27
|
-
import { NeonAnthropicLanguageModel } from "./neon-anthropic-language-model.js";
|
|
28
|
-
import { NeonChatLanguageModel } from "./neon-chat-language-model.js";
|
|
29
|
-
import type { NeonChatModelId } from "./neon-chat-options.js";
|
|
30
|
-
import { getNeonModelRoute } from "./neon-model-capabilities.js";
|
|
31
|
-
import { NeonResponsesLanguageModel } from "./neon-responses-language-model.js";
|
|
32
|
-
import { VERSION } from "./version.js";
|
|
33
|
-
|
|
34
|
-
const neonErrorSchema = z.object({
|
|
35
|
-
error: z.object({
|
|
36
|
-
message: z.string(),
|
|
37
|
-
type: z.string().nullish(),
|
|
38
|
-
param: z.unknown().nullish(),
|
|
39
|
-
code: z.unknown().nullish(),
|
|
40
|
-
}),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
export type NeonErrorData = z.infer<typeof neonErrorSchema>;
|
|
44
|
-
|
|
45
|
-
const neonErrorStructure: ProviderErrorStructure<NeonErrorData> = {
|
|
46
|
-
errorSchema: neonErrorSchema,
|
|
47
|
-
errorToMessage: (data) => data.error.message,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Recursively remove the JSON Schema `$schema` marker, which some gateway
|
|
52
|
-
* backends (notably Gemini) reject in tool/structured-output schemas. Other
|
|
53
|
-
* backends ignore its absence, so stripping it everywhere is safe.
|
|
54
|
-
*/
|
|
55
|
-
function stripJsonSchemaMarker(value: unknown): unknown {
|
|
56
|
-
if (Array.isArray(value)) {
|
|
57
|
-
return value.map(stripJsonSchemaMarker);
|
|
58
|
-
}
|
|
59
|
-
if (value !== null && typeof value === "object") {
|
|
60
|
-
const result: Record<string, unknown> = {};
|
|
61
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
62
|
-
if (key === "$schema") {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
result[key] = stripJsonSchemaMarker(entry);
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
return value;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function transformNeonRequestBody(
|
|
73
|
-
args: Record<string, unknown>,
|
|
74
|
-
): Record<string, unknown> {
|
|
75
|
-
const transformed = { ...args };
|
|
76
|
-
if (transformed.tools != null) {
|
|
77
|
-
transformed.tools = stripJsonSchemaMarker(transformed.tools);
|
|
78
|
-
}
|
|
79
|
-
if (transformed.response_format != null) {
|
|
80
|
-
transformed.response_format = stripJsonSchemaMarker(
|
|
81
|
-
transformed.response_format,
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return transformed;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface NeonProviderSettings {
|
|
88
|
-
/**
|
|
89
|
-
* Neon AI Gateway base URL — the branch-scoped host root, e.g.
|
|
90
|
-
* `https://<branch-id>-api.ai.<region>.aws.neon.tech`. The gateway paths are
|
|
91
|
-
* appended internally. Falls back to the `NEON_AI_GATEWAY_BASE_URL` env var.
|
|
92
|
-
*/
|
|
93
|
-
baseURL?: string;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Neon AI Gateway platform token (the `nt_live_...` value). Falls back to the
|
|
97
|
-
* `NEON_AI_GATEWAY_TOKEN` env var.
|
|
98
|
-
*/
|
|
99
|
-
apiKey?: string;
|
|
100
|
-
|
|
101
|
-
/** Custom headers to include in the requests. */
|
|
102
|
-
headers?: Record<string, string>;
|
|
103
|
-
|
|
104
|
-
/** Custom fetch implementation (e.g. for testing or middleware). */
|
|
105
|
-
fetch?: FetchFunction;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export interface NeonProvider extends ProviderV4 {
|
|
109
|
-
/** Creates a Neon AI Gateway model for text generation. */
|
|
110
|
-
(modelId: NeonChatModelId): LanguageModelV4;
|
|
111
|
-
|
|
112
|
-
/** Creates a Neon AI Gateway model for text generation. */
|
|
113
|
-
languageModel(modelId: NeonChatModelId): LanguageModelV4;
|
|
114
|
-
|
|
115
|
-
/** Creates a Neon AI Gateway chat model for text generation. */
|
|
116
|
-
chat(modelId: NeonChatModelId): LanguageModelV4;
|
|
117
|
-
|
|
118
|
-
/** @deprecated Use `embeddingModel` instead. */
|
|
119
|
-
textEmbeddingModel(modelId: string): never;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function createNeon(options: NeonProviderSettings = {}): NeonProvider {
|
|
123
|
-
// Resolved lazily so that `createNeon()` and the default `neon` instance do
|
|
124
|
-
// not throw at import time when configuration comes from the environment.
|
|
125
|
-
const getHost = () =>
|
|
126
|
-
withoutTrailingSlash(
|
|
127
|
-
loadSetting({
|
|
128
|
-
settingValue: options.baseURL,
|
|
129
|
-
environmentVariableName: "NEON_AI_GATEWAY_BASE_URL",
|
|
130
|
-
settingName: "baseURL",
|
|
131
|
-
description: "Neon AI Gateway base URL",
|
|
132
|
-
}),
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
const getHeaders = (extra?: Record<string, string>) =>
|
|
136
|
-
withUserAgentSuffix(
|
|
137
|
-
{
|
|
138
|
-
Authorization: `Bearer ${loadApiKey({
|
|
139
|
-
apiKey: options.apiKey,
|
|
140
|
-
environmentVariableName: "NEON_AI_GATEWAY_TOKEN",
|
|
141
|
-
description: "Neon AI Gateway token",
|
|
142
|
-
})}`,
|
|
143
|
-
...extra,
|
|
144
|
-
...options.headers,
|
|
145
|
-
},
|
|
146
|
-
`neondatabase/ai-sdk-provider/${VERSION}`,
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
// Anthropic models -> native Messages API.
|
|
150
|
-
const createAnthropicModel = (modelId: NeonChatModelId) =>
|
|
151
|
-
new NeonAnthropicLanguageModel(modelId, {
|
|
152
|
-
provider: "neon.anthropic",
|
|
153
|
-
baseURL: `${getHost()}/ai-gateway/anthropic/v1`,
|
|
154
|
-
headers: () => getHeaders({ "anthropic-version": "2023-06-01" }),
|
|
155
|
-
fetch: options.fetch,
|
|
156
|
-
generateId,
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// OpenAI models (incl. Codex, only served natively) -> Responses API.
|
|
160
|
-
const createOpenAIModel = (modelId: NeonChatModelId) =>
|
|
161
|
-
new NeonResponsesLanguageModel(modelId, {
|
|
162
|
-
provider: "neon.openai.responses",
|
|
163
|
-
url: ({ path }) => `${getHost()}/ai-gateway/openai/v1${path}`,
|
|
164
|
-
headers: getHeaders,
|
|
165
|
-
fetch: options.fetch,
|
|
166
|
-
fileIdPrefixes: ["file-"],
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
// Everything else (Gemini, Llama, Qwen, gpt-oss, ...) -> unified MLflow
|
|
170
|
-
// endpoint. Gemini is here because its native endpoint can't stream.
|
|
171
|
-
const createChatModel = (modelId: NeonChatModelId) =>
|
|
172
|
-
new NeonChatLanguageModel(modelId, {
|
|
173
|
-
provider: "neon.chat",
|
|
174
|
-
url: ({ path }) => `${getHost()}/ai-gateway/mlflow/v1${path}`,
|
|
175
|
-
headers: getHeaders,
|
|
176
|
-
fetch: options.fetch,
|
|
177
|
-
errorStructure: neonErrorStructure,
|
|
178
|
-
transformRequestBody: transformNeonRequestBody,
|
|
179
|
-
supportsStructuredOutputs: true,
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
const createLanguageModel = (modelId: NeonChatModelId): LanguageModelV4 => {
|
|
183
|
-
switch (getNeonModelRoute(modelId)) {
|
|
184
|
-
case "anthropic":
|
|
185
|
-
return createAnthropicModel(modelId);
|
|
186
|
-
case "openai":
|
|
187
|
-
return createOpenAIModel(modelId);
|
|
188
|
-
default:
|
|
189
|
-
return createChatModel(modelId);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const provider = (modelId: NeonChatModelId) => createLanguageModel(modelId);
|
|
194
|
-
|
|
195
|
-
provider.specificationVersion = "v4" as const;
|
|
196
|
-
provider.languageModel = createLanguageModel;
|
|
197
|
-
provider.chat = createLanguageModel;
|
|
198
|
-
|
|
199
|
-
provider.embeddingModel = (modelId: string) => {
|
|
200
|
-
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
201
|
-
};
|
|
202
|
-
provider.textEmbeddingModel = provider.embeddingModel;
|
|
203
|
-
provider.imageModel = (modelId: string) => {
|
|
204
|
-
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
return provider;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/** Default Neon provider instance (reads `NEON_AI_GATEWAY_*` env vars). */
|
|
211
|
-
export const neon = createNeon();
|
package/src/lib/version.ts
DELETED
package/src/v1.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@neondatabase/ai-sdk-provider/v1` — community Vercel AI SDK provider for the
|
|
3
|
-
* Neon AI Gateway.
|
|
4
|
-
*
|
|
5
|
-
* - `createNeon()` / `neon` — the provider. Routes each model to the best
|
|
6
|
-
* gateway endpoint (Anthropic → native Messages, OpenAI → native Responses
|
|
7
|
-
* incl. Codex, everything else → unified MLflow).
|
|
8
|
-
*/
|
|
9
|
-
export { NeonAnthropicLanguageModel } from "./lib/neon-anthropic-language-model.js";
|
|
10
|
-
export { NeonChatLanguageModel } from "./lib/neon-chat-language-model.js";
|
|
11
|
-
export type { NeonChatModelId } from "./lib/neon-chat-options.js";
|
|
12
|
-
export {
|
|
13
|
-
getNeonModelCapabilities,
|
|
14
|
-
getNeonModelRoute,
|
|
15
|
-
type NeonModelCapabilities,
|
|
16
|
-
type NeonModelFamily,
|
|
17
|
-
type NeonModelRoute,
|
|
18
|
-
} from "./lib/neon-model-capabilities.js";
|
|
19
|
-
export { NeonResponsesLanguageModel } from "./lib/neon-responses-language-model.js";
|
|
20
|
-
export {
|
|
21
|
-
createNeon,
|
|
22
|
-
type NeonErrorData,
|
|
23
|
-
type NeonProvider,
|
|
24
|
-
type NeonProviderSettings,
|
|
25
|
-
neon,
|
|
26
|
-
} from "./lib/provider.js";
|
package/tsconfig.json
DELETED
package/tsdown.config.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsdown";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
name: "@neondatabase/ai-sdk-provider",
|
|
5
|
-
bundle: false,
|
|
6
|
-
clean: true,
|
|
7
|
-
dts: true,
|
|
8
|
-
entry: ["src/index.ts", "src/v1.ts", "src/lib/**/*.ts", "!src/**/*.test.*"],
|
|
9
|
-
format: "esm",
|
|
10
|
-
outDir: "dist",
|
|
11
|
-
treeshake: true,
|
|
12
|
-
});
|
package/vitest.config.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vitest/config";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
clearMocks: true,
|
|
6
|
-
mockReset: true,
|
|
7
|
-
unstubEnvs: true,
|
|
8
|
-
coverage: {
|
|
9
|
-
all: true,
|
|
10
|
-
include: ["src"],
|
|
11
|
-
exclude: ["src/**/*.test.ts"],
|
|
12
|
-
reporter: ["html", "lcov"],
|
|
13
|
-
},
|
|
14
|
-
exclude: ["lib", "node_modules", "dist"],
|
|
15
|
-
setupFiles: ["console-fail-test/setup"],
|
|
16
|
-
},
|
|
17
|
-
});
|