@convex-dev/ai-sdk-provider 0.2.0-alpha.1 → 0.2.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.
Files changed (38) hide show
  1. package/README.md +183 -4
  2. package/dist/commonjs/evaluation-model.d.ts +5 -0
  3. package/dist/commonjs/evaluation-model.d.ts.map +1 -0
  4. package/dist/commonjs/evaluation-model.js +94 -0
  5. package/dist/commonjs/evaluation-model.js.map +1 -0
  6. package/dist/commonjs/index.d.ts +37 -5
  7. package/dist/commonjs/index.d.ts.map +1 -1
  8. package/dist/commonjs/index.js +21 -7
  9. package/dist/commonjs/index.js.map +1 -1
  10. package/dist/commonjs/video-model.d.ts +33 -0
  11. package/dist/commonjs/video-model.d.ts.map +1 -0
  12. package/dist/commonjs/video-model.js +195 -0
  13. package/dist/commonjs/video-model.js.map +1 -0
  14. package/dist/commonjs/video-webhook.d.ts +14 -0
  15. package/dist/commonjs/video-webhook.d.ts.map +1 -0
  16. package/dist/commonjs/video-webhook.js +33 -0
  17. package/dist/commonjs/video-webhook.js.map +1 -0
  18. package/dist/esm/evaluation-model.d.ts +5 -0
  19. package/dist/esm/evaluation-model.d.ts.map +1 -0
  20. package/dist/esm/evaluation-model.js +91 -0
  21. package/dist/esm/evaluation-model.js.map +1 -0
  22. package/dist/esm/index.d.ts +9 -5
  23. package/dist/esm/index.d.ts.map +1 -1
  24. package/dist/esm/index.js +19 -7
  25. package/dist/esm/index.js.map +1 -1
  26. package/dist/esm/video-model.d.ts +33 -0
  27. package/dist/esm/video-model.d.ts.map +1 -0
  28. package/dist/esm/video-model.js +192 -0
  29. package/dist/esm/video-model.js.map +1 -0
  30. package/dist/esm/video-webhook.d.ts +14 -0
  31. package/dist/esm/video-webhook.d.ts.map +1 -0
  32. package/dist/esm/video-webhook.js +30 -0
  33. package/dist/esm/video-webhook.js.map +1 -0
  34. package/package.json +9 -5
  35. package/src/evaluation-model.ts +118 -0
  36. package/src/index.ts +39 -13
  37. package/src/video-model.ts +262 -0
  38. package/src/video-webhook.ts +62 -0
package/README.md CHANGED
@@ -47,8 +47,187 @@ convexGateway.messages("anthropic/claude-sonnet-4.5");
47
47
  convexGateway.responses("openai/gpt-5");
48
48
  ```
49
49
 
50
- `getServiceToken("ai-gateway")` mints a short-lived deployment JWT on first use
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
- Requires Convex 1.45 or later, AI SDK 7, and Node.js 22 or later.
52
+ [Jev](https://docs.typesafe.ai/introduction) evaluates `choice`, `score`, and
53
+ `boolean` questions about the context you provide in `state`. Call AI SDK's
54
+ experimental `evaluate` from an action:
55
+
56
+ ```ts
57
+ import { experimental_evaluate as evaluate } from "ai";
58
+ import { convexGateway } from "@convex-dev/ai-sdk-provider";
59
+
60
+ const decision = await evaluate({
61
+ model: convexGateway.evaluationModel("typesafe/jev-1.13"),
62
+ state: { ticket: "Customer cannot sign in" },
63
+ questions: {
64
+ priority: {
65
+ type: "choice",
66
+ instructions: "Choose the response priority",
67
+ criteria: {
68
+ urgent: "Respond now",
69
+ normal: "Respond today",
70
+ },
71
+ },
72
+ needsReview: {
73
+ type: "boolean",
74
+ instructions: "Does a human need to review this?",
75
+ },
76
+ },
77
+ });
78
+
79
+ console.log(decision.answers.priority.choice);
80
+ console.log(decision.answers.needsReview.probability);
81
+ ```
82
+
83
+ This requires AI SDK 7.0.105 or later. The evaluation interface and
84
+ `/alpha/decisions` endpoint are experimental. Authentication is handled
85
+ automatically. Pass `abortSignal` to `evaluate` to cancel a request. Dollar cost
86
+ is available in `decision.providerMetadata?.convexGateway?.cost`. The original
87
+ gateway response, including provider-specific fields such as `confidence`, is
88
+ available in `decision.response.body`.
89
+
90
+ `getServiceToken("ai-gateway")` supplies a short-lived deployment JWT. The
91
+ action runtime caches and refreshes the credential as needed, so
92
+ `convexGateway(...)` is recommended to call it repeatedly.
93
+
94
+ Requires Convex 1.45 or later, AI SDK 7.0.105 or later, and Node.js 22 or later.
95
+
96
+ ## Generate images
97
+
98
+ Image generation is in alpha. The request and response format may change.
99
+
100
+ ```ts
101
+ import { generateImage } from "ai";
102
+ import { convexGateway } from "@convex-dev/ai-sdk-provider";
103
+
104
+ const { images } = await generateImage({
105
+ model: convexGateway.imageModel("openai/gpt-image-1"),
106
+ prompt: "A mountain lake at sunrise",
107
+ });
108
+ ```
109
+
110
+ ## Generate videos
111
+
112
+ Video generation is in alpha. APIs may change, and completion callbacks are best
113
+ effort. Save async operation handles to check status and retrieve results.
114
+
115
+ ```ts
116
+ import { experimental_generateVideo as generateVideo } from "ai";
117
+ import { convexGateway } from "@convex-dev/ai-sdk-provider";
118
+
119
+ const { video, providerMetadata } = await generateVideo({
120
+ model: convexGateway.videoModel("google/veo-3.1"),
121
+ prompt: "A camera pan across a mountain lake",
122
+ duration: 8,
123
+ aspectRatio: "16:9",
124
+ resolution: "1280x720",
125
+ });
126
+
127
+ const bytes = video.uint8Array;
128
+ const cost = providerMetadata?.convexGateway?.cost;
129
+ ```
130
+
131
+ The call waits for generation and download, with a ten-minute default timeout
132
+ and a 64 MiB limit per video. Store the returned bytes in Convex file storage.
133
+ The AI SDK splits `n > 1` into separate requests. Cancelling a request does not
134
+ cancel the upstream job and can still incur a charge.
135
+
136
+ An image in the prompt becomes the first frame. Use `frameImages` for explicit
137
+ frames, `inputReferences` for image/audio/video references, and `generateAudio`
138
+ for audio. `fps` returns an unsupported-option warning.
139
+
140
+ `providerOptions.convexGateway` accepts `resolution` (such as `720p`),
141
+ `generate_audio`, `frame_images`, and `input_references`. Standard SDK options
142
+ take precedence. Supported values depend on the
143
+ [OpenRouter model](https://openrouter.ai/docs/guides/overview/multimodal/video-generation).
144
+
145
+ ## Async videos
146
+
147
+ With AI SDK 7.0.83, use `experimental_startVideo` to submit a job without
148
+ waiting for the video. See the
149
+ [async availability requirements](https://docs.convex.dev/ai-gateway/images-and-videos#async-videos)
150
+ before using these routes.
151
+
152
+ Create an application job first. Use its ID as `requestId` in the callback URL
153
+ so the receiver can find the job and its saved secret.
154
+
155
+ ```ts
156
+ import { experimental_startVideo as startVideo } from "ai";
157
+ import { convexGateway } from "@convex-dev/ai-sdk-provider";
158
+
159
+ async function startJob(requestId: string) {
160
+ const modelId = "google/veo-3.1";
161
+ const started = await startVideo({
162
+ model: convexGateway.videoModel(modelId),
163
+ prompt: "A camera pan across a mountain lake",
164
+ duration: 8,
165
+ webhookUrl: `${process.env.CONVEX_SITE_URL}/video-complete?requestId=${requestId}`,
166
+ maxRetries: 0,
167
+ });
168
+
169
+ return {
170
+ modelId,
171
+ operation: started.operation,
172
+ inferenceId: started.providerMetadata?.convexGateway?.inferenceId,
173
+ webhookSecret: started.providerMetadata?.convexGateway?.webhookSecret,
174
+ };
175
+ }
176
+ ```
177
+
178
+ Save the returned job in private application storage before the action returns.
179
+ Automatic submission retries are disabled because a lost response can still mean
180
+ a paid job was accepted. Callback URLs must use the deployment's own HTTPS
181
+ `<deployment>.convex.site` origin; redirects are rejected. If `CONVEX_SITE_URL`
182
+ uses a custom domain, use the deployment's default `convex.site` origin in the
183
+ example instead.
184
+
185
+ ### Receive a callback
186
+
187
+ Load the saved job and verify the raw request body before updating application
188
+ state:
189
+
190
+ ```ts
191
+ import { verifyVideoWebhook } from "@convex-dev/ai-sdk-provider";
192
+
193
+ const event = await verifyVideoWebhook({
194
+ body: await request.text(),
195
+ signature: request.headers.get("x-convex-video-signature"),
196
+ secret: savedJob.webhookSecret,
197
+ });
198
+
199
+ if (event.id !== savedJob.inferenceId) {
200
+ return new Response("Wrong job", { status: 400 });
201
+ }
202
+ ```
203
+
204
+ Deduplicate `(event.id, event.status)` in the same mutation that saves the
205
+ event. For `completed`, schedule an action to download the video. Record
206
+ `failed`, `cancelled`, or `expired` as terminal failures. Return 204 after
207
+ saving the event; return a non-2xx response if the job's secret has not been
208
+ saved yet.
209
+
210
+ ### Retrieve the video
211
+
212
+ In a later action, use the saved operation to check status and download:
213
+
214
+ ```ts
215
+ const model = convexGateway.videoModel(savedJob.modelId);
216
+ const status = await model.getStatus({ operation: savedJob.operation });
217
+
218
+ if (status.status === "completed") {
219
+ const result = await model.download({ operation: savedJob.operation });
220
+ const video = result.videos[0];
221
+ const cost = result.providerMetadata?.convexGateway?.cost;
222
+ }
223
+ ```
224
+
225
+ `getStatus` returns `pending`, `completed`, or `error`. When the status is
226
+ `error`, the `error` field contains the error message. Store the downloaded
227
+ video in application storage, since each `download` call fetches it again.
228
+ Operations expire after seven days; upstream video retention may be shorter.
229
+
230
+ Omit `webhookUrl` to use status checks alone. If a completion callback is
231
+ missed, use the saved operation to check the job and retrieve its result.
232
+ Applications that need automatic recovery can periodically check unfinished
233
+ 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,CA6EjB"}
@@ -0,0 +1,94 @@
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
+ providerMetadata: usageMetadata(result.usage),
80
+ warnings: Object.keys(providerOptions ?? {}).map((provider) => ({
81
+ type: "unsupported",
82
+ feature: `providerOptions.${provider}`,
83
+ })),
84
+ response: {
85
+ id: result.id,
86
+ modelId: result.model,
87
+ headers: Object.fromEntries(response.headers),
88
+ body: rawBody,
89
+ },
90
+ };
91
+ },
92
+ };
93
+ }
94
+ //# sourceMappingURL=evaluation-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluation-model.js","sourceRoot":"","sources":["../../src/evaluation-model.ts"],"names":[],"mappings":";;AAmCA,sDAkFC;AArHD,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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CAAC,CAAC;YAClD,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7C,OAAO;gBACL,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;oBACnD,EAAE;oBACF,MAAM,CAAC,IAAI,KAAK,MAAM;wBACpB,CAAC,CAAC,EAAE,IAAI,EAAE,SAAkB,EAAE,WAAW,EAAE,MAAM,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,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"}
@@ -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<Provider["embeddingModel"]>;
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` reuses one token for the current action, so calling this
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,EAKL,iBAAiB,EAClB,MAAM,IAAI,CAAC;AAGZ,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAC1D,KAAK,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AACtC,KAAK,cAAc,GAAG,UAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAE7D,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAgHjE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAExD;yBAFe,aAAa;4BAIe,MAAM,KAAG,oBAAoB;6BAa5B,MAAM,KAAG,oBAAoB;kCAgBxB,MAAM,KAAG,cAAc"}
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"}
@@ -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}/v1`;
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` reuses one token for the current action, so calling this
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":";;AA0IA,sCAEC;AA5ID,iDAAoD;AACpD,2CAA8C;AAC9C,iEAGmC;AACnC,2BAMY;AACZ,0CAAgD;AAQhD,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;IACrB,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,qBAAqB,KAAK,CAAC;AACtF,CAAC;AAED,KAAK,UAAU,YAAY,CACzB,KAAwB,EACxB,IAAkB;IAElB,IAAI,OAAO,wBAAe,KAAK,UAAU,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,IAAA,wBAAe,EAAC,YAAY,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3C,yEAAyE;IACzE,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAAC;IAChD,OAAO,UAAU,CAAC,KAAK,CAAC,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,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,EAC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