@convex-dev/ai-sdk-provider 0.2.0-alpha.1 → 0.2.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 +186 -4
- package/dist/commonjs/evaluation-model.d.ts +5 -0
- package/dist/commonjs/evaluation-model.d.ts.map +1 -0
- package/dist/commonjs/evaluation-model.js +96 -0
- package/dist/commonjs/evaluation-model.js.map +1 -0
- package/dist/commonjs/index.d.ts +37 -5
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +21 -7
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/video-model.d.ts +33 -0
- package/dist/commonjs/video-model.d.ts.map +1 -0
- package/dist/commonjs/video-model.js +195 -0
- package/dist/commonjs/video-model.js.map +1 -0
- package/dist/commonjs/video-webhook.d.ts +14 -0
- package/dist/commonjs/video-webhook.d.ts.map +1 -0
- package/dist/commonjs/video-webhook.js +33 -0
- package/dist/commonjs/video-webhook.js.map +1 -0
- package/dist/esm/evaluation-model.d.ts +5 -0
- package/dist/esm/evaluation-model.d.ts.map +1 -0
- package/dist/esm/evaluation-model.js +93 -0
- package/dist/esm/evaluation-model.js.map +1 -0
- package/dist/esm/index.d.ts +9 -5
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +19 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/video-model.d.ts +33 -0
- package/dist/esm/video-model.d.ts.map +1 -0
- package/dist/esm/video-model.js +192 -0
- package/dist/esm/video-model.js.map +1 -0
- package/dist/esm/video-webhook.d.ts +14 -0
- package/dist/esm/video-webhook.d.ts.map +1 -0
- package/dist/esm/video-webhook.js +30 -0
- package/dist/esm/video-webhook.js.map +1 -0
- package/package.json +9 -5
- package/src/evaluation-model.ts +120 -0
- package/src/index.ts +39 -13
- package/src/video-model.ts +262 -0
- package/src/video-webhook.ts +62 -0
package/README.md
CHANGED
|
@@ -47,8 +47,190 @@ convexGateway.messages("anthropic/claude-sonnet-4.5");
|
|
|
47
47
|
convexGateway.responses("openai/gpt-5");
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
in an action and reuses it for later calls, so `convexGateway(...)` is fine to
|
|
52
|
-
call more than once. The provider takes no API key.
|
|
50
|
+
## Structured decisions
|
|
53
51
|
|
|
54
|
-
|
|
52
|
+
Use provider version 0.2.1 or later for correct validation of Jev's rounded
|
|
53
|
+
scores and probabilities.
|
|
54
|
+
|
|
55
|
+
[Jev](https://docs.typesafe.ai/introduction) evaluates `choice`, `score`, and
|
|
56
|
+
`boolean` questions about the context you provide in `state`. Call AI SDK's
|
|
57
|
+
experimental `evaluate` from an action:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { experimental_evaluate as evaluate } from "ai";
|
|
61
|
+
import { convexGateway } from "@convex-dev/ai-sdk-provider";
|
|
62
|
+
|
|
63
|
+
const decision = await evaluate({
|
|
64
|
+
model: convexGateway.evaluationModel("typesafe/jev-1.13"),
|
|
65
|
+
state: { ticket: "Customer cannot sign in" },
|
|
66
|
+
questions: {
|
|
67
|
+
priority: {
|
|
68
|
+
type: "choice",
|
|
69
|
+
instructions: "Choose the response priority",
|
|
70
|
+
criteria: {
|
|
71
|
+
urgent: "Respond now",
|
|
72
|
+
normal: "Respond today",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
needsReview: {
|
|
76
|
+
type: "boolean",
|
|
77
|
+
instructions: "Does a human need to review this?",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
console.log(decision.answers.priority.choice);
|
|
83
|
+
console.log(decision.answers.needsReview.probability);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
This requires AI SDK 7.0.105 or later. The evaluation interface and
|
|
87
|
+
`/alpha/decisions` endpoint are experimental. Authentication is handled
|
|
88
|
+
automatically. Pass `abortSignal` to `evaluate` to cancel a request. Dollar cost
|
|
89
|
+
is available in `decision.providerMetadata?.convexGateway?.cost`. The original
|
|
90
|
+
gateway response, including provider-specific fields such as `confidence`, is
|
|
91
|
+
available in `decision.response.body`.
|
|
92
|
+
|
|
93
|
+
`getServiceToken("ai-gateway")` supplies a short-lived deployment JWT. The
|
|
94
|
+
action runtime caches and refreshes the credential as needed, so
|
|
95
|
+
`convexGateway(...)` is recommended to call it repeatedly.
|
|
96
|
+
|
|
97
|
+
Requires Convex 1.45 or later, AI SDK 7.0.105 or later, and Node.js 22 or later.
|
|
98
|
+
|
|
99
|
+
## Generate images
|
|
100
|
+
|
|
101
|
+
Image generation is in alpha. The request and response format may change.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { generateImage } from "ai";
|
|
105
|
+
import { convexGateway } from "@convex-dev/ai-sdk-provider";
|
|
106
|
+
|
|
107
|
+
const { images } = await generateImage({
|
|
108
|
+
model: convexGateway.imageModel("openai/gpt-image-1"),
|
|
109
|
+
prompt: "A mountain lake at sunrise",
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Generate videos
|
|
114
|
+
|
|
115
|
+
Video generation is in alpha. APIs may change, and completion callbacks are best
|
|
116
|
+
effort. Save async operation handles to check status and retrieve results.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { experimental_generateVideo as generateVideo } from "ai";
|
|
120
|
+
import { convexGateway } from "@convex-dev/ai-sdk-provider";
|
|
121
|
+
|
|
122
|
+
const { video, providerMetadata } = await generateVideo({
|
|
123
|
+
model: convexGateway.videoModel("google/veo-3.1"),
|
|
124
|
+
prompt: "A camera pan across a mountain lake",
|
|
125
|
+
duration: 8,
|
|
126
|
+
aspectRatio: "16:9",
|
|
127
|
+
resolution: "1280x720",
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const bytes = video.uint8Array;
|
|
131
|
+
const cost = providerMetadata?.convexGateway?.cost;
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The call waits for generation and download, with a ten-minute default timeout
|
|
135
|
+
and a 64 MiB limit per video. Store the returned bytes in Convex file storage.
|
|
136
|
+
The AI SDK splits `n > 1` into separate requests. Cancelling a request does not
|
|
137
|
+
cancel the upstream job and can still incur a charge.
|
|
138
|
+
|
|
139
|
+
An image in the prompt becomes the first frame. Use `frameImages` for explicit
|
|
140
|
+
frames, `inputReferences` for image/audio/video references, and `generateAudio`
|
|
141
|
+
for audio. `fps` returns an unsupported-option warning.
|
|
142
|
+
|
|
143
|
+
`providerOptions.convexGateway` accepts `resolution` (such as `720p`),
|
|
144
|
+
`generate_audio`, `frame_images`, and `input_references`. Standard SDK options
|
|
145
|
+
take precedence. Supported values depend on the
|
|
146
|
+
[OpenRouter model](https://openrouter.ai/docs/guides/overview/multimodal/video-generation).
|
|
147
|
+
|
|
148
|
+
## Async videos
|
|
149
|
+
|
|
150
|
+
With AI SDK 7.0.83, use `experimental_startVideo` to submit a job without
|
|
151
|
+
waiting for the video. See the
|
|
152
|
+
[async availability requirements](https://docs.convex.dev/ai-gateway/images-and-videos#async-videos)
|
|
153
|
+
before using these routes.
|
|
154
|
+
|
|
155
|
+
Create an application job first. Use its ID as `requestId` in the callback URL
|
|
156
|
+
so the receiver can find the job and its saved secret.
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
import { experimental_startVideo as startVideo } from "ai";
|
|
160
|
+
import { convexGateway } from "@convex-dev/ai-sdk-provider";
|
|
161
|
+
|
|
162
|
+
async function startJob(requestId: string) {
|
|
163
|
+
const modelId = "google/veo-3.1";
|
|
164
|
+
const started = await startVideo({
|
|
165
|
+
model: convexGateway.videoModel(modelId),
|
|
166
|
+
prompt: "A camera pan across a mountain lake",
|
|
167
|
+
duration: 8,
|
|
168
|
+
webhookUrl: `${process.env.CONVEX_SITE_URL}/video-complete?requestId=${requestId}`,
|
|
169
|
+
maxRetries: 0,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
modelId,
|
|
174
|
+
operation: started.operation,
|
|
175
|
+
inferenceId: started.providerMetadata?.convexGateway?.inferenceId,
|
|
176
|
+
webhookSecret: started.providerMetadata?.convexGateway?.webhookSecret,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Save the returned job in private application storage before the action returns.
|
|
182
|
+
Automatic submission retries are disabled because a lost response can still mean
|
|
183
|
+
a paid job was accepted. Callback URLs must use the deployment's own HTTPS
|
|
184
|
+
`<deployment>.convex.site` origin; redirects are rejected. If `CONVEX_SITE_URL`
|
|
185
|
+
uses a custom domain, use the deployment's default `convex.site` origin in the
|
|
186
|
+
example instead.
|
|
187
|
+
|
|
188
|
+
### Receive a callback
|
|
189
|
+
|
|
190
|
+
Load the saved job and verify the raw request body before updating application
|
|
191
|
+
state:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import { verifyVideoWebhook } from "@convex-dev/ai-sdk-provider";
|
|
195
|
+
|
|
196
|
+
const event = await verifyVideoWebhook({
|
|
197
|
+
body: await request.text(),
|
|
198
|
+
signature: request.headers.get("x-convex-video-signature"),
|
|
199
|
+
secret: savedJob.webhookSecret,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
if (event.id !== savedJob.inferenceId) {
|
|
203
|
+
return new Response("Wrong job", { status: 400 });
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Deduplicate `(event.id, event.status)` in the same mutation that saves the
|
|
208
|
+
event. For `completed`, schedule an action to download the video. Record
|
|
209
|
+
`failed`, `cancelled`, or `expired` as terminal failures. Return 204 after
|
|
210
|
+
saving the event; return a non-2xx response if the job's secret has not been
|
|
211
|
+
saved yet.
|
|
212
|
+
|
|
213
|
+
### Retrieve the video
|
|
214
|
+
|
|
215
|
+
In a later action, use the saved operation to check status and download:
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
const model = convexGateway.videoModel(savedJob.modelId);
|
|
219
|
+
const status = await model.getStatus({ operation: savedJob.operation });
|
|
220
|
+
|
|
221
|
+
if (status.status === "completed") {
|
|
222
|
+
const result = await model.download({ operation: savedJob.operation });
|
|
223
|
+
const video = result.videos[0];
|
|
224
|
+
const cost = result.providerMetadata?.convexGateway?.cost;
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
`getStatus` returns `pending`, `completed`, or `error`. When the status is
|
|
229
|
+
`error`, the `error` field contains the error message. Store the downloaded
|
|
230
|
+
video in application storage, since each `download` call fetches it again.
|
|
231
|
+
Operations expire after seven days; upstream video retention may be shorter.
|
|
232
|
+
|
|
233
|
+
Omit `webhookUrl` to use status checks alone. If a completion callback is
|
|
234
|
+
missed, use the saved operation to check the job and retrieve its result.
|
|
235
|
+
Applications that need automatic recovery can periodically check unfinished
|
|
236
|
+
jobs.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type experimental_evaluate, type ProviderMetadata } from "ai";
|
|
2
|
+
type EvaluationModel = Exclude<Parameters<typeof experimental_evaluate>[0]["model"], string>;
|
|
3
|
+
export declare function createEvaluationModel(modelId: string, baseURL: string, fetch: typeof globalThis.fetch, usageMetadata: (usage: unknown) => ProviderMetadata | undefined): EvaluationModel;
|
|
4
|
+
export {};
|
|
5
|
+
//# sourceMappingURL=evaluation-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluation-model.d.ts","sourceRoot":"","sources":["../../src/evaluation-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACtB,MAAM,IAAI,CAAC;AAGZ,KAAK,eAAe,GAAG,OAAO,CAC5B,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EACpD,MAAM,CACP,CAAC;AAyBF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,aAAa,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,gBAAgB,GAAG,SAAS,GAC9D,eAAe,CA+EjB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEvaluationModel = createEvaluationModel;
|
|
4
|
+
const ai_1 = require("ai");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const probabilities = zod_1.z.record(zod_1.z.string(), zod_1.z.number()).optional();
|
|
7
|
+
const responseSchema = zod_1.z.object({
|
|
8
|
+
id: zod_1.z.string(),
|
|
9
|
+
model: zod_1.z.string(),
|
|
10
|
+
answers: zod_1.z.record(zod_1.z.string(), zod_1.z.discriminatedUnion("type", [
|
|
11
|
+
zod_1.z.object({
|
|
12
|
+
type: zod_1.z.literal("choice"),
|
|
13
|
+
choice: zod_1.z.string(),
|
|
14
|
+
probabilities,
|
|
15
|
+
}),
|
|
16
|
+
zod_1.z.object({ type: zod_1.z.literal("score"), score: zod_1.z.number(), probabilities }),
|
|
17
|
+
zod_1.z.object({ type: zod_1.z.literal("noul"), noul: zod_1.z.number() }),
|
|
18
|
+
])),
|
|
19
|
+
usage: zod_1.z.object({
|
|
20
|
+
input_tokens: zod_1.z.number().int().nonnegative(),
|
|
21
|
+
output_tokens: zod_1.z.number().int().nonnegative(),
|
|
22
|
+
cost: zod_1.z.number().nonnegative().optional(),
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
function createEvaluationModel(modelId, baseURL, fetch, usageMetadata) {
|
|
26
|
+
return {
|
|
27
|
+
specificationVersion: "v4",
|
|
28
|
+
provider: "convexGateway",
|
|
29
|
+
modelId,
|
|
30
|
+
supportedQuestionTypes: ["choice", "score", "boolean"],
|
|
31
|
+
async doEvaluate({ state, questions, abortSignal, headers, providerOptions, }) {
|
|
32
|
+
const url = `${baseURL}/decisions`;
|
|
33
|
+
const body = {
|
|
34
|
+
model: modelId,
|
|
35
|
+
state,
|
|
36
|
+
questions: Object.fromEntries(Object.entries(questions).map(([id, question]) => [
|
|
37
|
+
id,
|
|
38
|
+
question.type === "boolean"
|
|
39
|
+
? { ...question, type: "noul" }
|
|
40
|
+
: question,
|
|
41
|
+
])),
|
|
42
|
+
};
|
|
43
|
+
const requestHeaders = new Headers();
|
|
44
|
+
for (const [key, value] of Object.entries(headers ?? {})) {
|
|
45
|
+
if (value !== undefined)
|
|
46
|
+
requestHeaders.set(key, value);
|
|
47
|
+
}
|
|
48
|
+
requestHeaders.set("Content-Type", "application/json");
|
|
49
|
+
const response = await fetch(url, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: requestHeaders,
|
|
52
|
+
signal: abortSignal,
|
|
53
|
+
body: JSON.stringify(body),
|
|
54
|
+
});
|
|
55
|
+
const responseBody = await response.text();
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
throw new ai_1.APICallError({
|
|
58
|
+
message: `Evaluation failed (${response.status}): ${responseBody}`,
|
|
59
|
+
url,
|
|
60
|
+
requestBodyValues: body,
|
|
61
|
+
statusCode: response.status,
|
|
62
|
+
responseHeaders: Object.fromEntries(response.headers),
|
|
63
|
+
responseBody,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const rawBody = JSON.parse(responseBody);
|
|
67
|
+
const result = responseSchema.parse(rawBody);
|
|
68
|
+
return {
|
|
69
|
+
answers: Object.fromEntries(Object.entries(result.answers).map(([id, answer]) => [
|
|
70
|
+
id,
|
|
71
|
+
answer.type === "noul"
|
|
72
|
+
? { type: "boolean", probability: answer.noul }
|
|
73
|
+
: answer,
|
|
74
|
+
])),
|
|
75
|
+
usage: {
|
|
76
|
+
inputTokens: result.usage.input_tokens,
|
|
77
|
+
outputTokens: result.usage.output_tokens,
|
|
78
|
+
},
|
|
79
|
+
// Jev rounds scores and probabilities independently to two decimal places.
|
|
80
|
+
rounding: { probabilityDecimals: 2, scoreDecimals: 2 },
|
|
81
|
+
providerMetadata: usageMetadata(result.usage),
|
|
82
|
+
warnings: Object.keys(providerOptions ?? {}).map((provider) => ({
|
|
83
|
+
type: "unsupported",
|
|
84
|
+
feature: `providerOptions.${provider}`,
|
|
85
|
+
})),
|
|
86
|
+
response: {
|
|
87
|
+
id: result.id,
|
|
88
|
+
modelId: result.model,
|
|
89
|
+
headers: Object.fromEntries(response.headers),
|
|
90
|
+
body: rawBody,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=evaluation-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluation-model.js","sourceRoot":"","sources":["../../src/evaluation-model.ts"],"names":[],"mappings":";;AAmCA,sDAoFC;AAvHD,2BAIY;AACZ,6BAAwB;AAOxB,MAAM,aAAa,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AAClE,MAAM,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9B,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;IACd,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;IACjB,OAAO,EAAE,OAAC,CAAC,MAAM,CACf,OAAC,CAAC,MAAM,EAAE,EACV,OAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;QAC3B,OAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;YACzB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;YAClB,aAAa;SACd,CAAC;QACF,OAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,CAAC;QACxE,OAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,E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AAM,CAAC,IAAI,EAAE;wBACxD,CAAC,CAAC,MAAM;iBACX,CAAC,CACH;gBACD,KAAK,EAAE;oBACL,WAAW,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY;oBACtC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,aAAa;iBACzC;gBACD,2EAA2E;gBAC3E,QAAQ,EAAE,EAAE,mBAAmB,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE;gBACtD,gBAAgB,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7C,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;oBAC9D,IAAI,EAAE,aAAsB;oBAC5B,OAAO,EAAE,mBAAmB,QAAQ,EAAE;iBACvC,CAAC,CAAC;gBACH,QAAQ,EAAE;oBACR,EAAE,EAAE,MAAM,CAAC,EAAE;oBACb,OAAO,EAAE,MAAM,CAAC,KAAK;oBACrB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC;oBAC7C,IAAI,EAAE,OAAO;iBACd;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,21 +1,53 @@
|
|
|
1
1
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
2
|
-
import { wrapLanguageModel } from "ai";
|
|
2
|
+
import { wrapEmbeddingModel, wrapLanguageModel } from "ai";
|
|
3
3
|
type Provider = ReturnType<typeof createOpenAICompatible>;
|
|
4
4
|
type ChatModel = ReturnType<Provider>;
|
|
5
|
-
type EmbeddingModel = ReturnType<
|
|
5
|
+
type EmbeddingModel = ReturnType<typeof wrapEmbeddingModel>;
|
|
6
|
+
type ImageModel = ReturnType<Provider["imageModel"]>;
|
|
6
7
|
type GatewayLanguageModel = ReturnType<typeof wrapLanguageModel>;
|
|
7
8
|
/**
|
|
8
9
|
* The recommended model interface for text generation through the Convex AI gateway.
|
|
9
10
|
* Use `messages` or `responses` only for endpoint-specific features.
|
|
10
11
|
*
|
|
11
|
-
* `getServiceToken`
|
|
12
|
-
* more than once in the same action is fine.
|
|
12
|
+
* `getServiceToken` caches and refreshes credentials within the current action,
|
|
13
|
+
* so calling this more than once in the same action is fine.
|
|
13
14
|
*/
|
|
14
15
|
export declare function convexGateway(modelId: string): ChatModel;
|
|
15
16
|
export declare namespace convexGateway {
|
|
16
17
|
var messages: (modelId: string) => GatewayLanguageModel;
|
|
17
18
|
var responses: (modelId: string) => GatewayLanguageModel;
|
|
19
|
+
var evaluationModel: (modelId: string) => import(".pnpm/@ai-sdk+provider@4.0.17/node_modules/@ai-sdk/provider", { with: { "resolution-mode": "import" } }).Experimental_EvaluationModelV4;
|
|
18
20
|
var embeddingModel: (modelId: string) => EmbeddingModel;
|
|
21
|
+
var imageModel: (modelId: string) => ImageModel;
|
|
22
|
+
var videoModel: (modelId: string) => Omit<import(".pnpm/@ai-sdk+provider@4.0.17/node_modules/@ai-sdk/provider", { with: { "resolution-mode": "import" } }).Experimental_VideoModelV4, "doStatus" | "handleWebhookOption"> & {
|
|
23
|
+
doStart(options: import(".pnpm/@ai-sdk+provider@4.0.17/node_modules/@ai-sdk/provider", { with: { "resolution-mode": "import" } }).Experimental_VideoModelV4CallOptions & {
|
|
24
|
+
webhookUrl?: string;
|
|
25
|
+
}): Promise<Omit<import(".pnpm/@ai-sdk+provider@4.0.17/node_modules/@ai-sdk/provider", { with: { "resolution-mode": "import" } }).Experimental_VideoModelV4Result, "videos"> & {
|
|
26
|
+
operation: import("ai", { with: { "resolution-mode": "import" } }).JSONValue;
|
|
27
|
+
}>;
|
|
28
|
+
getStatus(options: {
|
|
29
|
+
operation: import("ai", { with: { "resolution-mode": "import" } }).JSONValue;
|
|
30
|
+
headers?: Record<string, string | undefined>;
|
|
31
|
+
abortSignal?: AbortSignal;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
providerMetadata?: import("ai", { with: { "resolution-mode": "import" } }).ProviderMetadata;
|
|
34
|
+
response: {
|
|
35
|
+
timestamp: Date;
|
|
36
|
+
modelId: string;
|
|
37
|
+
headers: Record<string, string> | undefined;
|
|
38
|
+
};
|
|
39
|
+
} & ({
|
|
40
|
+
status: "pending" | "completed";
|
|
41
|
+
} | {
|
|
42
|
+
status: "error";
|
|
43
|
+
error: string;
|
|
44
|
+
})>;
|
|
45
|
+
download(options: {
|
|
46
|
+
operation: import("ai", { with: { "resolution-mode": "import" } }).JSONValue;
|
|
47
|
+
headers?: Record<string, string | undefined>;
|
|
48
|
+
abortSignal?: AbortSignal;
|
|
49
|
+
}): Promise<import(".pnpm/@ai-sdk+provider@4.0.17/node_modules/@ai-sdk/provider", { with: { "resolution-mode": "import" } }).Experimental_VideoModelV4Result>;
|
|
50
|
+
};
|
|
19
51
|
}
|
|
20
|
-
export {};
|
|
52
|
+
export { verifyVideoWebhook, type VideoWebhookEvent } from "./video-webhook.js";
|
|
21
53
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EAEvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EAEvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,IAAI,CAAC;AAKZ,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAC1D,KAAK,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AACtC,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAI5D,KAAK,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC;AAErD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AA2GjE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAExD;yBAFe,aAAa;4BAIe,MAAM,KAAG,oBAAoB;6BAa5B,MAAM,KAAG,oBAAoB;mCAiBvB,MAAM;kCASP,MAAM,KAAG,cAAc;8BAW3B,MAAM,KAAG,UAAU;8BAKnB,MAAM;;sBA3KpB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoLjC,OAAO,EAAE,kBAAkB,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyVideoWebhook = void 0;
|
|
3
4
|
exports.convexGateway = convexGateway;
|
|
4
5
|
const anthropic_1 = require("@ai-sdk/anthropic");
|
|
5
6
|
const openai_1 = require("@ai-sdk/openai");
|
|
6
7
|
const openai_compatible_1 = require("@ai-sdk/openai-compatible");
|
|
7
8
|
const ai_1 = require("ai");
|
|
8
9
|
const server_1 = require("convex/server");
|
|
10
|
+
const evaluation_model_js_1 = require("./evaluation-model.js");
|
|
11
|
+
const video_model_js_1 = require("./video-model.js");
|
|
9
12
|
const maxEmbeddingsPerCall = 512;
|
|
10
13
|
// Official providers require a credential before gatewayFetch replaces it with a deployment JWT.
|
|
11
14
|
const placeholderCredential = "convex-gateway";
|
|
@@ -14,13 +17,10 @@ const placeholderCredential = "convex-gateway";
|
|
|
14
17
|
* gateway, which is how internal apps use staging.
|
|
15
18
|
*/
|
|
16
19
|
const productionGatewayHost = "https://ai-gateway.convex.dev";
|
|
17
|
-
function gatewayBaseURL() {
|
|
18
|
-
return `${process.env.CONVEX_INTERNAL_AI_GATEWAY_HOST || productionGatewayHost}
|
|
20
|
+
function gatewayBaseURL(version = "v1") {
|
|
21
|
+
return `${process.env.CONVEX_INTERNAL_AI_GATEWAY_HOST || productionGatewayHost}/${version}`;
|
|
19
22
|
}
|
|
20
23
|
async function gatewayFetch(input, init) {
|
|
21
|
-
if (typeof server_1.getServiceToken !== "function") {
|
|
22
|
-
throw new Error("@convex-dev/ai-sdk-provider requires convex >= 1.45 with getServiceToken support");
|
|
23
|
-
}
|
|
24
24
|
const token = await (0, server_1.getServiceToken)("ai-gateway");
|
|
25
25
|
const headers = new Headers(init?.headers);
|
|
26
26
|
// Deployment JWT is the only accepted credential for the hosted gateway.
|
|
@@ -92,8 +92,8 @@ function gatewayLanguageModel(modelId, model, middleware) {
|
|
|
92
92
|
* The recommended model interface for text generation through the Convex AI gateway.
|
|
93
93
|
* Use `messages` or `responses` only for endpoint-specific features.
|
|
94
94
|
*
|
|
95
|
-
* `getServiceToken`
|
|
96
|
-
* more than once in the same action is fine.
|
|
95
|
+
* `getServiceToken` caches and refreshes credentials within the current action,
|
|
96
|
+
* so calling this more than once in the same action is fine.
|
|
97
97
|
*/
|
|
98
98
|
function convexGateway(modelId) {
|
|
99
99
|
return createGatewayProvider()(modelId);
|
|
@@ -118,6 +118,10 @@ convexGateway.responses = function (modelId) {
|
|
|
118
118
|
settings: { providerOptions: { openai: { store: false } } },
|
|
119
119
|
}));
|
|
120
120
|
};
|
|
121
|
+
/** Evaluate typed questions through the alpha Decisions API. */
|
|
122
|
+
convexGateway.evaluationModel = function (modelId) {
|
|
123
|
+
return (0, evaluation_model_js_1.createEvaluationModel)(modelId, gatewayBaseURL("alpha"), gatewayFetch, convexGatewayUsageMetadata);
|
|
124
|
+
};
|
|
121
125
|
convexGateway.embeddingModel = function (modelId) {
|
|
122
126
|
return (0, ai_1.wrapEmbeddingModel)({
|
|
123
127
|
model: createGatewayProvider().embeddingModel(modelId),
|
|
@@ -127,4 +131,14 @@ convexGateway.embeddingModel = function (modelId) {
|
|
|
127
131
|
},
|
|
128
132
|
});
|
|
129
133
|
};
|
|
134
|
+
/** Image model for the AI SDK's `generateImage`. */
|
|
135
|
+
convexGateway.imageModel = function (modelId) {
|
|
136
|
+
return createGatewayProvider().imageModel(modelId);
|
|
137
|
+
};
|
|
138
|
+
/** Video generation for the AI SDK's `experimental_generateVideo`. */
|
|
139
|
+
convexGateway.videoModel = function (modelId) {
|
|
140
|
+
return (0, video_model_js_1.createVideoModel)(modelId, gatewayBaseURL(), gatewayFetch, convexGatewayUsageMetadata);
|
|
141
|
+
};
|
|
142
|
+
var video_webhook_js_1 = require("./video-webhook.js");
|
|
143
|
+
Object.defineProperty(exports, "verifyVideoWebhook", { enumerable: true, get: function () { return video_webhook_js_1.verifyVideoWebhook; } });
|
|
130
144
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAyIA,sCAEC;AA3ID,iDAAoD;AACpD,2CAA8C;AAC9C,iEAGmC;AACnC,2BAIY;AACZ,0CAAgD;AAChD,+DAA8D;AAC9D,qDAAoD;AAYpD,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,iGAAiG;AACjG,MAAM,qBAAqB,GAAG,gBAAgB,CAAC;AAE/C;;;GAGG;AACH,MAAM,qBAAqB,GAAG,+BAA+B,CAAC;AAE9D,SAAS,cAAc,CAAC,UAA0B,IAAI;IACpD,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,qBAAqB,IAAI,OAAO,EAAE,CAAC;AAC9F,CAAC;AAED,KAAK,UAAU,YAAY,CACzB,KAAwB,EACxB,IAAkB;IAElB,MAAM,KAAK,GAAG,MAAM,IAAA,wBAAe,EAAC,YAAY,CAAC,CAAC;IAClD,MAAM,OAAO,GA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AChE,aAAa,CAAC,eAAe,GAAG,UAAU,OAAe;IACvD,OAAO,IAAA,2CAAqB,EAC1B,OAAO,EACP,cAAc,CAAC,OAAO,CAAC,EACvB,YAAY,EACZ,0BAA0B,CAC3B,CAAC;AACJ,CAAC,CAAC;AAEF,aAAa,CAAC,cAAc,GAAG,UAAU,OAAe;IACtD,OAAO,IAAA,uBAAkB,EAAC;QACxB,KAAK,EAAE,qBAAqB,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC;QACtD,UAAU,EAAE;YACV,oBAAoB,EAAE,IAAI;YAC1B,4BAA4B,EAAE,GAAG,EAAE,CAAC,oBAAoB;SACzD;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,oDAAoD;AACpD,aAAa,CAAC,UAAU,GAAG,UAAU,OAAe;IAClD,OAAO,qBAAqB,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,sEAAsE;AACtE,aAAa,CAAC,UAAU,GAAG,UAAU,OAAe;IAClD,OAAO,IAAA,iCAAgB,EACrB,OAAO,EACP,cAAc,EAAE,EAChB,YAAY,EACZ,0BAA0B,CAC3B,CAAC;AACJ,CAAC,CAAC;AAEF,uDAAgF;AAAvE,sHAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { experimental_generateVideo, JSONValue, ProviderMetadata } from "ai";
|
|
2
|
+
type VideoModel = Extract<Parameters<typeof experimental_generateVideo>[0]["model"], {
|
|
3
|
+
specificationVersion: "v4";
|
|
4
|
+
}>;
|
|
5
|
+
type VideoOptions = Parameters<NonNullable<VideoModel["doGenerate"]>>[0];
|
|
6
|
+
type VideoResult = Awaited<ReturnType<NonNullable<VideoModel["doGenerate"]>>>;
|
|
7
|
+
type StatusOptions = {
|
|
8
|
+
operation: JSONValue;
|
|
9
|
+
headers?: Record<string, string | undefined>;
|
|
10
|
+
abortSignal?: AbortSignal;
|
|
11
|
+
};
|
|
12
|
+
type StartResult = Omit<VideoResult, "videos"> & {
|
|
13
|
+
operation: JSONValue;
|
|
14
|
+
};
|
|
15
|
+
type StatusResult = {
|
|
16
|
+
providerMetadata?: ProviderMetadata;
|
|
17
|
+
response: VideoResult["response"];
|
|
18
|
+
} & ({
|
|
19
|
+
status: "pending" | "completed";
|
|
20
|
+
} | {
|
|
21
|
+
status: "error";
|
|
22
|
+
error: string;
|
|
23
|
+
});
|
|
24
|
+
type GatewayVideoModel = Omit<VideoModel, "doStatus" | "handleWebhookOption"> & {
|
|
25
|
+
doStart(options: VideoOptions & {
|
|
26
|
+
webhookUrl?: string;
|
|
27
|
+
}): Promise<StartResult>;
|
|
28
|
+
getStatus(options: StatusOptions): Promise<StatusResult>;
|
|
29
|
+
download(options: StatusOptions): Promise<VideoResult>;
|
|
30
|
+
};
|
|
31
|
+
export declare function createVideoModel(modelId: string, baseURL: string, fetch: typeof globalThis.fetch, usageMetadata: (usage: unknown) => ProviderMetadata | undefined): GatewayVideoModel;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=video-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-model.d.ts","sourceRoot":"","sources":["../../src/video-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,SAAS,EACT,gBAAgB,EACjB,MAAM,IAAI,CAAC;AAEZ,KAAK,UAAU,GAAG,OAAO,CACvB,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EACzD;IAAE,oBAAoB,EAAE,IAAI,CAAA;CAAE,CAC/B,CAAC;AACF,KAAK,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,KAAK,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9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