@ai-sdk/gateway 4.0.0-beta.47 → 4.0.0-beta.49
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/CHANGELOG.md +19 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +412 -371
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +1 -1
- package/package.json +7 -7
- package/src/gateway-image-model-settings.ts +3 -0
- package/src/gateway-provider-options.ts +1 -1
- package/dist/index.d.mts +0 -725
- package/dist/index.mjs +0 -1866
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,46 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name8 in all)
|
|
8
|
-
__defProp(target, name8, { get: all[name8], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
GatewayAuthenticationError: () => GatewayAuthenticationError,
|
|
24
|
-
GatewayError: () => GatewayError,
|
|
25
|
-
GatewayInternalServerError: () => GatewayInternalServerError,
|
|
26
|
-
GatewayInvalidRequestError: () => GatewayInvalidRequestError,
|
|
27
|
-
GatewayModelNotFoundError: () => GatewayModelNotFoundError,
|
|
28
|
-
GatewayRateLimitError: () => GatewayRateLimitError,
|
|
29
|
-
GatewayResponseError: () => GatewayResponseError,
|
|
30
|
-
createGateway: () => createGatewayProvider,
|
|
31
|
-
createGatewayProvider: () => createGatewayProvider,
|
|
32
|
-
gateway: () => gateway
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(index_exports);
|
|
35
|
-
|
|
36
1
|
// src/gateway-provider.ts
|
|
37
|
-
|
|
2
|
+
import {
|
|
3
|
+
loadOptionalSetting,
|
|
4
|
+
withoutTrailingSlash
|
|
5
|
+
} from "@ai-sdk/provider-utils";
|
|
38
6
|
|
|
39
7
|
// src/errors/as-gateway-error.ts
|
|
40
|
-
|
|
8
|
+
import { APICallError } from "@ai-sdk/provider";
|
|
41
9
|
|
|
42
10
|
// src/errors/create-gateway-error.ts
|
|
43
|
-
|
|
11
|
+
import { z as z2 } from "zod/v4";
|
|
44
12
|
|
|
45
13
|
// src/errors/gateway-error.ts
|
|
46
14
|
var marker = "vercel.ai.gateway.error";
|
|
@@ -182,15 +150,15 @@ var GatewayRateLimitError = class extends (_b4 = GatewayError, _a4 = symbol4, _b
|
|
|
182
150
|
};
|
|
183
151
|
|
|
184
152
|
// src/errors/gateway-model-not-found-error.ts
|
|
185
|
-
|
|
186
|
-
|
|
153
|
+
import { z } from "zod/v4";
|
|
154
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
187
155
|
var name4 = "GatewayModelNotFoundError";
|
|
188
156
|
var marker5 = `vercel.ai.gateway.error.${name4}`;
|
|
189
157
|
var symbol5 = Symbol.for(marker5);
|
|
190
|
-
var modelNotFoundParamSchema =
|
|
191
|
-
() =>
|
|
192
|
-
|
|
193
|
-
modelId:
|
|
158
|
+
var modelNotFoundParamSchema = lazySchema(
|
|
159
|
+
() => zodSchema(
|
|
160
|
+
z.object({
|
|
161
|
+
modelId: z.string()
|
|
194
162
|
})
|
|
195
163
|
)
|
|
196
164
|
);
|
|
@@ -266,7 +234,11 @@ var GatewayResponseError = class extends (_b7 = GatewayError, _a7 = symbol7, _b7
|
|
|
266
234
|
};
|
|
267
235
|
|
|
268
236
|
// src/errors/create-gateway-error.ts
|
|
269
|
-
|
|
237
|
+
import {
|
|
238
|
+
lazySchema as lazySchema2,
|
|
239
|
+
safeValidateTypes,
|
|
240
|
+
zodSchema as zodSchema2
|
|
241
|
+
} from "@ai-sdk/provider-utils";
|
|
270
242
|
async function createGatewayErrorFromResponse({
|
|
271
243
|
response,
|
|
272
244
|
statusCode,
|
|
@@ -275,7 +247,7 @@ async function createGatewayErrorFromResponse({
|
|
|
275
247
|
authMethod
|
|
276
248
|
}) {
|
|
277
249
|
var _a9;
|
|
278
|
-
const parseResult = await
|
|
250
|
+
const parseResult = await safeValidateTypes({
|
|
279
251
|
value: response,
|
|
280
252
|
schema: gatewayErrorResponseSchema
|
|
281
253
|
});
|
|
@@ -318,7 +290,7 @@ async function createGatewayErrorFromResponse({
|
|
|
318
290
|
generationId
|
|
319
291
|
});
|
|
320
292
|
case "model_not_found": {
|
|
321
|
-
const modelResult = await
|
|
293
|
+
const modelResult = await safeValidateTypes({
|
|
322
294
|
value: validatedResponse.error.param,
|
|
323
295
|
schema: modelNotFoundParamSchema
|
|
324
296
|
});
|
|
@@ -346,16 +318,16 @@ async function createGatewayErrorFromResponse({
|
|
|
346
318
|
});
|
|
347
319
|
}
|
|
348
320
|
}
|
|
349
|
-
var gatewayErrorResponseSchema = (
|
|
350
|
-
() => (
|
|
351
|
-
|
|
352
|
-
error:
|
|
353
|
-
message:
|
|
354
|
-
type:
|
|
355
|
-
param:
|
|
356
|
-
code:
|
|
321
|
+
var gatewayErrorResponseSchema = lazySchema2(
|
|
322
|
+
() => zodSchema2(
|
|
323
|
+
z2.object({
|
|
324
|
+
error: z2.object({
|
|
325
|
+
message: z2.string(),
|
|
326
|
+
type: z2.string().nullish(),
|
|
327
|
+
param: z2.unknown().nullish(),
|
|
328
|
+
code: z2.union([z2.string(), z2.number()]).nullish()
|
|
357
329
|
}),
|
|
358
|
-
generationId:
|
|
330
|
+
generationId: z2.string().nullish()
|
|
359
331
|
})
|
|
360
332
|
)
|
|
361
333
|
);
|
|
@@ -429,7 +401,7 @@ async function asGatewayError(error, authMethod) {
|
|
|
429
401
|
cause: error
|
|
430
402
|
});
|
|
431
403
|
}
|
|
432
|
-
if (
|
|
404
|
+
if (APICallError.isInstance(error)) {
|
|
433
405
|
if (error.cause && isTimeoutError(error.cause)) {
|
|
434
406
|
return GatewayTimeoutError.createTimeoutError({
|
|
435
407
|
originalMessage: error.message,
|
|
@@ -469,37 +441,48 @@ function extractApiCallResponse(error) {
|
|
|
469
441
|
}
|
|
470
442
|
|
|
471
443
|
// src/errors/parse-auth-method.ts
|
|
472
|
-
|
|
473
|
-
|
|
444
|
+
import { z as z3 } from "zod/v4";
|
|
445
|
+
import {
|
|
446
|
+
lazySchema as lazySchema3,
|
|
447
|
+
safeValidateTypes as safeValidateTypes2,
|
|
448
|
+
zodSchema as zodSchema3
|
|
449
|
+
} from "@ai-sdk/provider-utils";
|
|
474
450
|
var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
|
|
475
451
|
async function parseAuthMethod(headers) {
|
|
476
|
-
const result = await (
|
|
452
|
+
const result = await safeValidateTypes2({
|
|
477
453
|
value: headers[GATEWAY_AUTH_METHOD_HEADER],
|
|
478
454
|
schema: gatewayAuthMethodSchema
|
|
479
455
|
});
|
|
480
456
|
return result.success ? result.value : void 0;
|
|
481
457
|
}
|
|
482
|
-
var gatewayAuthMethodSchema = (
|
|
483
|
-
() => (
|
|
458
|
+
var gatewayAuthMethodSchema = lazySchema3(
|
|
459
|
+
() => zodSchema3(z3.union([z3.literal("api-key"), z3.literal("oidc")]))
|
|
484
460
|
);
|
|
485
461
|
|
|
486
462
|
// src/gateway-fetch-metadata.ts
|
|
487
|
-
|
|
488
|
-
|
|
463
|
+
import {
|
|
464
|
+
createJsonErrorResponseHandler,
|
|
465
|
+
createJsonResponseHandler,
|
|
466
|
+
getFromApi,
|
|
467
|
+
lazySchema as lazySchema4,
|
|
468
|
+
resolve,
|
|
469
|
+
zodSchema as zodSchema4
|
|
470
|
+
} from "@ai-sdk/provider-utils";
|
|
471
|
+
import { z as z4 } from "zod/v4";
|
|
489
472
|
var GatewayFetchMetadata = class {
|
|
490
473
|
constructor(config) {
|
|
491
474
|
this.config = config;
|
|
492
475
|
}
|
|
493
476
|
async getAvailableModels() {
|
|
494
477
|
try {
|
|
495
|
-
const { value } = await
|
|
478
|
+
const { value } = await getFromApi({
|
|
496
479
|
url: `${this.config.baseURL}/config`,
|
|
497
|
-
headers: await
|
|
498
|
-
successfulResponseHandler:
|
|
480
|
+
headers: await resolve(this.config.headers()),
|
|
481
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
499
482
|
gatewayAvailableModelsResponseSchema
|
|
500
483
|
),
|
|
501
|
-
failedResponseHandler:
|
|
502
|
-
errorSchema:
|
|
484
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
485
|
+
errorSchema: z4.any(),
|
|
503
486
|
errorToMessage: (data) => data
|
|
504
487
|
}),
|
|
505
488
|
fetch: this.config.fetch
|
|
@@ -512,14 +495,14 @@ var GatewayFetchMetadata = class {
|
|
|
512
495
|
async getCredits() {
|
|
513
496
|
try {
|
|
514
497
|
const baseUrl = new URL(this.config.baseURL);
|
|
515
|
-
const { value } = await
|
|
498
|
+
const { value } = await getFromApi({
|
|
516
499
|
url: `${baseUrl.origin}/v1/credits`,
|
|
517
|
-
headers: await
|
|
518
|
-
successfulResponseHandler:
|
|
500
|
+
headers: await resolve(this.config.headers()),
|
|
501
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
519
502
|
gatewayCreditsResponseSchema
|
|
520
503
|
),
|
|
521
|
-
failedResponseHandler:
|
|
522
|
-
errorSchema:
|
|
504
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
505
|
+
errorSchema: z4.any(),
|
|
523
506
|
errorToMessage: (data) => data
|
|
524
507
|
}),
|
|
525
508
|
fetch: this.config.fetch
|
|
@@ -530,19 +513,19 @@ var GatewayFetchMetadata = class {
|
|
|
530
513
|
}
|
|
531
514
|
}
|
|
532
515
|
};
|
|
533
|
-
var gatewayAvailableModelsResponseSchema = (
|
|
534
|
-
() => (
|
|
535
|
-
|
|
536
|
-
models:
|
|
537
|
-
|
|
538
|
-
id:
|
|
539
|
-
name:
|
|
540
|
-
description:
|
|
541
|
-
pricing:
|
|
542
|
-
input:
|
|
543
|
-
output:
|
|
544
|
-
input_cache_read:
|
|
545
|
-
input_cache_write:
|
|
516
|
+
var gatewayAvailableModelsResponseSchema = lazySchema4(
|
|
517
|
+
() => zodSchema4(
|
|
518
|
+
z4.object({
|
|
519
|
+
models: z4.array(
|
|
520
|
+
z4.object({
|
|
521
|
+
id: z4.string(),
|
|
522
|
+
name: z4.string(),
|
|
523
|
+
description: z4.string().nullish(),
|
|
524
|
+
pricing: z4.object({
|
|
525
|
+
input: z4.string(),
|
|
526
|
+
output: z4.string(),
|
|
527
|
+
input_cache_read: z4.string().nullish(),
|
|
528
|
+
input_cache_write: z4.string().nullish()
|
|
546
529
|
}).transform(
|
|
547
530
|
({ input, output, input_cache_read, input_cache_write }) => ({
|
|
548
531
|
input,
|
|
@@ -551,22 +534,22 @@ var gatewayAvailableModelsResponseSchema = (0, import_provider_utils4.lazySchema
|
|
|
551
534
|
...input_cache_write ? { cacheCreationInputTokens: input_cache_write } : {}
|
|
552
535
|
})
|
|
553
536
|
).nullish(),
|
|
554
|
-
specification:
|
|
555
|
-
specificationVersion:
|
|
556
|
-
provider:
|
|
557
|
-
modelId:
|
|
537
|
+
specification: z4.object({
|
|
538
|
+
specificationVersion: z4.literal("v4"),
|
|
539
|
+
provider: z4.string(),
|
|
540
|
+
modelId: z4.string()
|
|
558
541
|
}),
|
|
559
|
-
modelType:
|
|
542
|
+
modelType: z4.enum(["embedding", "image", "language", "video"]).nullish()
|
|
560
543
|
})
|
|
561
544
|
)
|
|
562
545
|
})
|
|
563
546
|
)
|
|
564
547
|
);
|
|
565
|
-
var gatewayCreditsResponseSchema = (
|
|
566
|
-
() => (
|
|
567
|
-
|
|
568
|
-
balance:
|
|
569
|
-
total_used:
|
|
548
|
+
var gatewayCreditsResponseSchema = lazySchema4(
|
|
549
|
+
() => zodSchema4(
|
|
550
|
+
z4.object({
|
|
551
|
+
balance: z4.string(),
|
|
552
|
+
total_used: z4.string()
|
|
570
553
|
}).transform(({ balance, total_used }) => ({
|
|
571
554
|
balance,
|
|
572
555
|
totalUsed: total_used
|
|
@@ -575,8 +558,15 @@ var gatewayCreditsResponseSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
575
558
|
);
|
|
576
559
|
|
|
577
560
|
// src/gateway-spend-report.ts
|
|
578
|
-
|
|
579
|
-
|
|
561
|
+
import {
|
|
562
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
563
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
564
|
+
getFromApi as getFromApi2,
|
|
565
|
+
lazySchema as lazySchema5,
|
|
566
|
+
resolve as resolve2,
|
|
567
|
+
zodSchema as zodSchema5
|
|
568
|
+
} from "@ai-sdk/provider-utils";
|
|
569
|
+
import { z as z5 } from "zod/v4";
|
|
580
570
|
var GatewaySpendReport = class {
|
|
581
571
|
constructor(config) {
|
|
582
572
|
this.config = config;
|
|
@@ -608,14 +598,14 @@ var GatewaySpendReport = class {
|
|
|
608
598
|
if (params.tags && params.tags.length > 0) {
|
|
609
599
|
searchParams.set("tags", params.tags.join(","));
|
|
610
600
|
}
|
|
611
|
-
const { value } = await (
|
|
601
|
+
const { value } = await getFromApi2({
|
|
612
602
|
url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
|
|
613
|
-
headers: await (
|
|
614
|
-
successfulResponseHandler: (
|
|
603
|
+
headers: await resolve2(this.config.headers()),
|
|
604
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
615
605
|
gatewaySpendReportResponseSchema
|
|
616
606
|
),
|
|
617
|
-
failedResponseHandler: (
|
|
618
|
-
errorSchema:
|
|
607
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
608
|
+
errorSchema: z5.any(),
|
|
619
609
|
errorToMessage: (data) => data
|
|
620
610
|
}),
|
|
621
611
|
fetch: this.config.fetch
|
|
@@ -626,26 +616,26 @@ var GatewaySpendReport = class {
|
|
|
626
616
|
}
|
|
627
617
|
}
|
|
628
618
|
};
|
|
629
|
-
var gatewaySpendReportResponseSchema = (
|
|
630
|
-
() => (
|
|
631
|
-
|
|
632
|
-
results:
|
|
633
|
-
|
|
634
|
-
day:
|
|
635
|
-
hour:
|
|
636
|
-
user:
|
|
637
|
-
model:
|
|
638
|
-
tag:
|
|
639
|
-
provider:
|
|
640
|
-
credential_type:
|
|
641
|
-
total_cost:
|
|
642
|
-
market_cost:
|
|
643
|
-
input_tokens:
|
|
644
|
-
output_tokens:
|
|
645
|
-
cached_input_tokens:
|
|
646
|
-
cache_creation_input_tokens:
|
|
647
|
-
reasoning_tokens:
|
|
648
|
-
request_count:
|
|
619
|
+
var gatewaySpendReportResponseSchema = lazySchema5(
|
|
620
|
+
() => zodSchema5(
|
|
621
|
+
z5.object({
|
|
622
|
+
results: z5.array(
|
|
623
|
+
z5.object({
|
|
624
|
+
day: z5.string().optional(),
|
|
625
|
+
hour: z5.string().optional(),
|
|
626
|
+
user: z5.string().optional(),
|
|
627
|
+
model: z5.string().optional(),
|
|
628
|
+
tag: z5.string().optional(),
|
|
629
|
+
provider: z5.string().optional(),
|
|
630
|
+
credential_type: z5.enum(["byok", "system"]).optional(),
|
|
631
|
+
total_cost: z5.number(),
|
|
632
|
+
market_cost: z5.number().optional(),
|
|
633
|
+
input_tokens: z5.number().optional(),
|
|
634
|
+
output_tokens: z5.number().optional(),
|
|
635
|
+
cached_input_tokens: z5.number().optional(),
|
|
636
|
+
cache_creation_input_tokens: z5.number().optional(),
|
|
637
|
+
reasoning_tokens: z5.number().optional(),
|
|
638
|
+
request_count: z5.number().optional()
|
|
649
639
|
}).transform(
|
|
650
640
|
({
|
|
651
641
|
credential_type,
|
|
@@ -677,8 +667,15 @@ var gatewaySpendReportResponseSchema = (0, import_provider_utils5.lazySchema)(
|
|
|
677
667
|
);
|
|
678
668
|
|
|
679
669
|
// src/gateway-generation-info.ts
|
|
680
|
-
|
|
681
|
-
|
|
670
|
+
import {
|
|
671
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
672
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
673
|
+
getFromApi as getFromApi3,
|
|
674
|
+
lazySchema as lazySchema6,
|
|
675
|
+
resolve as resolve3,
|
|
676
|
+
zodSchema as zodSchema6
|
|
677
|
+
} from "@ai-sdk/provider-utils";
|
|
678
|
+
import { z as z6 } from "zod/v4";
|
|
682
679
|
var GatewayGenerationInfoFetcher = class {
|
|
683
680
|
constructor(config) {
|
|
684
681
|
this.config = config;
|
|
@@ -686,14 +683,14 @@ var GatewayGenerationInfoFetcher = class {
|
|
|
686
683
|
async getGenerationInfo(params) {
|
|
687
684
|
try {
|
|
688
685
|
const baseUrl = new URL(this.config.baseURL);
|
|
689
|
-
const { value } = await (
|
|
686
|
+
const { value } = await getFromApi3({
|
|
690
687
|
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
691
|
-
headers: await (
|
|
692
|
-
successfulResponseHandler: (
|
|
688
|
+
headers: await resolve3(this.config.headers()),
|
|
689
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
693
690
|
gatewayGenerationInfoResponseSchema
|
|
694
691
|
),
|
|
695
|
-
failedResponseHandler: (
|
|
696
|
-
errorSchema:
|
|
692
|
+
failedResponseHandler: createJsonErrorResponseHandler3({
|
|
693
|
+
errorSchema: z6.any(),
|
|
697
694
|
errorToMessage: (data) => data
|
|
698
695
|
}),
|
|
699
696
|
fetch: this.config.fetch
|
|
@@ -704,28 +701,28 @@ var GatewayGenerationInfoFetcher = class {
|
|
|
704
701
|
}
|
|
705
702
|
}
|
|
706
703
|
};
|
|
707
|
-
var gatewayGenerationInfoResponseSchema = (
|
|
708
|
-
() => (
|
|
709
|
-
|
|
710
|
-
data:
|
|
711
|
-
id:
|
|
712
|
-
total_cost:
|
|
713
|
-
upstream_inference_cost:
|
|
714
|
-
usage:
|
|
715
|
-
created_at:
|
|
716
|
-
model:
|
|
717
|
-
is_byok:
|
|
718
|
-
provider_name:
|
|
719
|
-
streamed:
|
|
720
|
-
finish_reason:
|
|
721
|
-
latency:
|
|
722
|
-
generation_time:
|
|
723
|
-
native_tokens_prompt:
|
|
724
|
-
native_tokens_completion:
|
|
725
|
-
native_tokens_reasoning:
|
|
726
|
-
native_tokens_cached:
|
|
727
|
-
native_tokens_cache_creation:
|
|
728
|
-
billable_web_search_calls:
|
|
704
|
+
var gatewayGenerationInfoResponseSchema = lazySchema6(
|
|
705
|
+
() => zodSchema6(
|
|
706
|
+
z6.object({
|
|
707
|
+
data: z6.object({
|
|
708
|
+
id: z6.string(),
|
|
709
|
+
total_cost: z6.number(),
|
|
710
|
+
upstream_inference_cost: z6.number(),
|
|
711
|
+
usage: z6.number(),
|
|
712
|
+
created_at: z6.string(),
|
|
713
|
+
model: z6.string(),
|
|
714
|
+
is_byok: z6.boolean(),
|
|
715
|
+
provider_name: z6.string(),
|
|
716
|
+
streamed: z6.boolean(),
|
|
717
|
+
finish_reason: z6.string(),
|
|
718
|
+
latency: z6.number(),
|
|
719
|
+
generation_time: z6.number(),
|
|
720
|
+
native_tokens_prompt: z6.number(),
|
|
721
|
+
native_tokens_completion: z6.number(),
|
|
722
|
+
native_tokens_reasoning: z6.number(),
|
|
723
|
+
native_tokens_cached: z6.number(),
|
|
724
|
+
native_tokens_cache_creation: z6.number(),
|
|
725
|
+
billable_web_search_calls: z6.number()
|
|
729
726
|
}).transform(
|
|
730
727
|
({
|
|
731
728
|
total_cost,
|
|
@@ -764,8 +761,15 @@ var gatewayGenerationInfoResponseSchema = (0, import_provider_utils6.lazySchema)
|
|
|
764
761
|
);
|
|
765
762
|
|
|
766
763
|
// src/gateway-language-model.ts
|
|
767
|
-
|
|
768
|
-
|
|
764
|
+
import {
|
|
765
|
+
combineHeaders,
|
|
766
|
+
createEventSourceResponseHandler,
|
|
767
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
|
|
768
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
769
|
+
postJsonToApi,
|
|
770
|
+
resolve as resolve4
|
|
771
|
+
} from "@ai-sdk/provider-utils";
|
|
772
|
+
import { z as z7 } from "zod/v4";
|
|
769
773
|
var GatewayLanguageModel = class {
|
|
770
774
|
constructor(modelId, config) {
|
|
771
775
|
this.modelId = modelId;
|
|
@@ -786,24 +790,24 @@ var GatewayLanguageModel = class {
|
|
|
786
790
|
async doGenerate(options) {
|
|
787
791
|
const { args, warnings } = await this.getArgs(options);
|
|
788
792
|
const { abortSignal } = options;
|
|
789
|
-
const resolvedHeaders = await (
|
|
793
|
+
const resolvedHeaders = await resolve4(this.config.headers());
|
|
790
794
|
try {
|
|
791
795
|
const {
|
|
792
796
|
responseHeaders,
|
|
793
797
|
value: responseBody,
|
|
794
798
|
rawValue: rawResponse
|
|
795
|
-
} = await
|
|
799
|
+
} = await postJsonToApi({
|
|
796
800
|
url: this.getUrl(),
|
|
797
|
-
headers:
|
|
801
|
+
headers: combineHeaders(
|
|
798
802
|
resolvedHeaders,
|
|
799
803
|
options.headers,
|
|
800
804
|
this.getModelConfigHeaders(this.modelId, false),
|
|
801
|
-
await (
|
|
805
|
+
await resolve4(this.config.o11yHeaders)
|
|
802
806
|
),
|
|
803
807
|
body: args,
|
|
804
|
-
successfulResponseHandler: (
|
|
805
|
-
failedResponseHandler: (
|
|
806
|
-
errorSchema:
|
|
808
|
+
successfulResponseHandler: createJsonResponseHandler4(z7.any()),
|
|
809
|
+
failedResponseHandler: createJsonErrorResponseHandler4({
|
|
810
|
+
errorSchema: z7.any(),
|
|
807
811
|
errorToMessage: (data) => data
|
|
808
812
|
}),
|
|
809
813
|
...abortSignal && { abortSignal },
|
|
@@ -822,20 +826,20 @@ var GatewayLanguageModel = class {
|
|
|
822
826
|
async doStream(options) {
|
|
823
827
|
const { args, warnings } = await this.getArgs(options);
|
|
824
828
|
const { abortSignal } = options;
|
|
825
|
-
const resolvedHeaders = await (
|
|
829
|
+
const resolvedHeaders = await resolve4(this.config.headers());
|
|
826
830
|
try {
|
|
827
|
-
const { value: response, responseHeaders } = await
|
|
831
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
828
832
|
url: this.getUrl(),
|
|
829
|
-
headers:
|
|
833
|
+
headers: combineHeaders(
|
|
830
834
|
resolvedHeaders,
|
|
831
835
|
options.headers,
|
|
832
836
|
this.getModelConfigHeaders(this.modelId, true),
|
|
833
|
-
await (
|
|
837
|
+
await resolve4(this.config.o11yHeaders)
|
|
834
838
|
),
|
|
835
839
|
body: args,
|
|
836
|
-
successfulResponseHandler:
|
|
837
|
-
failedResponseHandler: (
|
|
838
|
-
errorSchema:
|
|
840
|
+
successfulResponseHandler: createEventSourceResponseHandler(z7.any()),
|
|
841
|
+
failedResponseHandler: createJsonErrorResponseHandler4({
|
|
842
|
+
errorSchema: z7.any(),
|
|
839
843
|
errorToMessage: (data) => data
|
|
840
844
|
}),
|
|
841
845
|
...abortSignal && { abortSignal },
|
|
@@ -913,8 +917,16 @@ var GatewayLanguageModel = class {
|
|
|
913
917
|
};
|
|
914
918
|
|
|
915
919
|
// src/gateway-embedding-model.ts
|
|
916
|
-
|
|
917
|
-
|
|
920
|
+
import {
|
|
921
|
+
combineHeaders as combineHeaders2,
|
|
922
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler5,
|
|
923
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
924
|
+
lazySchema as lazySchema7,
|
|
925
|
+
postJsonToApi as postJsonToApi2,
|
|
926
|
+
resolve as resolve5,
|
|
927
|
+
zodSchema as zodSchema7
|
|
928
|
+
} from "@ai-sdk/provider-utils";
|
|
929
|
+
import { z as z8 } from "zod/v4";
|
|
918
930
|
var GatewayEmbeddingModel = class {
|
|
919
931
|
constructor(modelId, config) {
|
|
920
932
|
this.modelId = modelId;
|
|
@@ -933,29 +945,29 @@ var GatewayEmbeddingModel = class {
|
|
|
933
945
|
providerOptions
|
|
934
946
|
}) {
|
|
935
947
|
var _a9;
|
|
936
|
-
const resolvedHeaders = await (
|
|
948
|
+
const resolvedHeaders = await resolve5(this.config.headers());
|
|
937
949
|
try {
|
|
938
950
|
const {
|
|
939
951
|
responseHeaders,
|
|
940
952
|
value: responseBody,
|
|
941
953
|
rawValue
|
|
942
|
-
} = await (
|
|
954
|
+
} = await postJsonToApi2({
|
|
943
955
|
url: this.getUrl(),
|
|
944
|
-
headers: (
|
|
956
|
+
headers: combineHeaders2(
|
|
945
957
|
resolvedHeaders,
|
|
946
958
|
headers != null ? headers : {},
|
|
947
959
|
this.getModelConfigHeaders(),
|
|
948
|
-
await (
|
|
960
|
+
await resolve5(this.config.o11yHeaders)
|
|
949
961
|
),
|
|
950
962
|
body: {
|
|
951
963
|
values,
|
|
952
964
|
...providerOptions ? { providerOptions } : {}
|
|
953
965
|
},
|
|
954
|
-
successfulResponseHandler: (
|
|
966
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
955
967
|
gatewayEmbeddingResponseSchema
|
|
956
968
|
),
|
|
957
|
-
failedResponseHandler: (
|
|
958
|
-
errorSchema:
|
|
969
|
+
failedResponseHandler: createJsonErrorResponseHandler5({
|
|
970
|
+
errorSchema: z8.any(),
|
|
959
971
|
errorToMessage: (data) => data
|
|
960
972
|
}),
|
|
961
973
|
...abortSignal && { abortSignal },
|
|
@@ -982,19 +994,26 @@ var GatewayEmbeddingModel = class {
|
|
|
982
994
|
};
|
|
983
995
|
}
|
|
984
996
|
};
|
|
985
|
-
var gatewayEmbeddingResponseSchema = (
|
|
986
|
-
() => (
|
|
987
|
-
|
|
988
|
-
embeddings:
|
|
989
|
-
usage:
|
|
990
|
-
providerMetadata:
|
|
997
|
+
var gatewayEmbeddingResponseSchema = lazySchema7(
|
|
998
|
+
() => zodSchema7(
|
|
999
|
+
z8.object({
|
|
1000
|
+
embeddings: z8.array(z8.array(z8.number())),
|
|
1001
|
+
usage: z8.object({ tokens: z8.number() }).nullish(),
|
|
1002
|
+
providerMetadata: z8.record(z8.string(), z8.record(z8.string(), z8.unknown())).optional()
|
|
991
1003
|
})
|
|
992
1004
|
)
|
|
993
1005
|
);
|
|
994
1006
|
|
|
995
1007
|
// src/gateway-image-model.ts
|
|
996
|
-
|
|
997
|
-
|
|
1008
|
+
import {
|
|
1009
|
+
combineHeaders as combineHeaders3,
|
|
1010
|
+
convertUint8ArrayToBase64,
|
|
1011
|
+
createJsonResponseHandler as createJsonResponseHandler6,
|
|
1012
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler6,
|
|
1013
|
+
postJsonToApi as postJsonToApi3,
|
|
1014
|
+
resolve as resolve6
|
|
1015
|
+
} from "@ai-sdk/provider-utils";
|
|
1016
|
+
import { z as z9 } from "zod/v4";
|
|
998
1017
|
var GatewayImageModel = class {
|
|
999
1018
|
constructor(modelId, config) {
|
|
1000
1019
|
this.modelId = modelId;
|
|
@@ -1019,15 +1038,15 @@ var GatewayImageModel = class {
|
|
|
1019
1038
|
abortSignal
|
|
1020
1039
|
}) {
|
|
1021
1040
|
var _a9, _b9, _c, _d;
|
|
1022
|
-
const resolvedHeaders = await (
|
|
1041
|
+
const resolvedHeaders = await resolve6(this.config.headers());
|
|
1023
1042
|
try {
|
|
1024
|
-
const { responseHeaders, value: responseBody } = await (
|
|
1043
|
+
const { responseHeaders, value: responseBody } = await postJsonToApi3({
|
|
1025
1044
|
url: this.getUrl(),
|
|
1026
|
-
headers: (
|
|
1045
|
+
headers: combineHeaders3(
|
|
1027
1046
|
resolvedHeaders,
|
|
1028
1047
|
headers != null ? headers : {},
|
|
1029
1048
|
this.getModelConfigHeaders(),
|
|
1030
|
-
await (
|
|
1049
|
+
await resolve6(this.config.o11yHeaders)
|
|
1031
1050
|
),
|
|
1032
1051
|
body: {
|
|
1033
1052
|
prompt,
|
|
@@ -1041,11 +1060,11 @@ var GatewayImageModel = class {
|
|
|
1041
1060
|
},
|
|
1042
1061
|
...mask && { mask: maybeEncodeImageFile(mask) }
|
|
1043
1062
|
},
|
|
1044
|
-
successfulResponseHandler: (
|
|
1063
|
+
successfulResponseHandler: createJsonResponseHandler6(
|
|
1045
1064
|
gatewayImageResponseSchema
|
|
1046
1065
|
),
|
|
1047
|
-
failedResponseHandler: (
|
|
1048
|
-
errorSchema:
|
|
1066
|
+
failedResponseHandler: createJsonErrorResponseHandler6({
|
|
1067
|
+
errorSchema: z9.any(),
|
|
1049
1068
|
errorToMessage: (data) => data
|
|
1050
1069
|
}),
|
|
1051
1070
|
...abortSignal && { abortSignal },
|
|
@@ -1087,47 +1106,54 @@ function maybeEncodeImageFile(file) {
|
|
|
1087
1106
|
if (file.type === "file" && file.data instanceof Uint8Array) {
|
|
1088
1107
|
return {
|
|
1089
1108
|
...file,
|
|
1090
|
-
data:
|
|
1109
|
+
data: convertUint8ArrayToBase64(file.data)
|
|
1091
1110
|
};
|
|
1092
1111
|
}
|
|
1093
1112
|
return file;
|
|
1094
1113
|
}
|
|
1095
|
-
var providerMetadataEntrySchema =
|
|
1096
|
-
images:
|
|
1097
|
-
}).catchall(
|
|
1098
|
-
var gatewayImageWarningSchema =
|
|
1099
|
-
|
|
1100
|
-
type:
|
|
1101
|
-
feature:
|
|
1102
|
-
details:
|
|
1114
|
+
var providerMetadataEntrySchema = z9.object({
|
|
1115
|
+
images: z9.array(z9.unknown()).optional()
|
|
1116
|
+
}).catchall(z9.unknown());
|
|
1117
|
+
var gatewayImageWarningSchema = z9.discriminatedUnion("type", [
|
|
1118
|
+
z9.object({
|
|
1119
|
+
type: z9.literal("unsupported"),
|
|
1120
|
+
feature: z9.string(),
|
|
1121
|
+
details: z9.string().optional()
|
|
1103
1122
|
}),
|
|
1104
|
-
|
|
1105
|
-
type:
|
|
1106
|
-
feature:
|
|
1107
|
-
details:
|
|
1123
|
+
z9.object({
|
|
1124
|
+
type: z9.literal("compatibility"),
|
|
1125
|
+
feature: z9.string(),
|
|
1126
|
+
details: z9.string().optional()
|
|
1108
1127
|
}),
|
|
1109
|
-
|
|
1110
|
-
type:
|
|
1111
|
-
message:
|
|
1128
|
+
z9.object({
|
|
1129
|
+
type: z9.literal("other"),
|
|
1130
|
+
message: z9.string()
|
|
1112
1131
|
})
|
|
1113
1132
|
]);
|
|
1114
|
-
var gatewayImageUsageSchema =
|
|
1115
|
-
inputTokens:
|
|
1116
|
-
outputTokens:
|
|
1117
|
-
totalTokens:
|
|
1133
|
+
var gatewayImageUsageSchema = z9.object({
|
|
1134
|
+
inputTokens: z9.number().nullish(),
|
|
1135
|
+
outputTokens: z9.number().nullish(),
|
|
1136
|
+
totalTokens: z9.number().nullish()
|
|
1118
1137
|
});
|
|
1119
|
-
var gatewayImageResponseSchema =
|
|
1120
|
-
images:
|
|
1138
|
+
var gatewayImageResponseSchema = z9.object({
|
|
1139
|
+
images: z9.array(z9.string()),
|
|
1121
1140
|
// Always base64 strings over the wire
|
|
1122
|
-
warnings:
|
|
1123
|
-
providerMetadata:
|
|
1141
|
+
warnings: z9.array(gatewayImageWarningSchema).optional(),
|
|
1142
|
+
providerMetadata: z9.record(z9.string(), providerMetadataEntrySchema).optional(),
|
|
1124
1143
|
usage: gatewayImageUsageSchema.optional()
|
|
1125
1144
|
});
|
|
1126
1145
|
|
|
1127
1146
|
// src/gateway-video-model.ts
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1147
|
+
import { APICallError as APICallError2 } from "@ai-sdk/provider";
|
|
1148
|
+
import {
|
|
1149
|
+
combineHeaders as combineHeaders4,
|
|
1150
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
1151
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler7,
|
|
1152
|
+
parseJsonEventStream,
|
|
1153
|
+
postJsonToApi as postJsonToApi4,
|
|
1154
|
+
resolve as resolve7
|
|
1155
|
+
} from "@ai-sdk/provider-utils";
|
|
1156
|
+
import { z as z10 } from "zod/v4";
|
|
1131
1157
|
var GatewayVideoModel = class {
|
|
1132
1158
|
constructor(modelId, config) {
|
|
1133
1159
|
this.modelId = modelId;
|
|
@@ -1153,15 +1179,15 @@ var GatewayVideoModel = class {
|
|
|
1153
1179
|
abortSignal
|
|
1154
1180
|
}) {
|
|
1155
1181
|
var _a9;
|
|
1156
|
-
const resolvedHeaders = await (
|
|
1182
|
+
const resolvedHeaders = await resolve7(this.config.headers());
|
|
1157
1183
|
try {
|
|
1158
|
-
const { responseHeaders, value: responseBody } = await (
|
|
1184
|
+
const { responseHeaders, value: responseBody } = await postJsonToApi4({
|
|
1159
1185
|
url: this.getUrl(),
|
|
1160
|
-
headers: (
|
|
1186
|
+
headers: combineHeaders4(
|
|
1161
1187
|
resolvedHeaders,
|
|
1162
1188
|
headers != null ? headers : {},
|
|
1163
1189
|
this.getModelConfigHeaders(),
|
|
1164
|
-
await (
|
|
1190
|
+
await resolve7(this.config.o11yHeaders),
|
|
1165
1191
|
{ accept: "text/event-stream" }
|
|
1166
1192
|
),
|
|
1167
1193
|
body: {
|
|
@@ -1181,14 +1207,14 @@ var GatewayVideoModel = class {
|
|
|
1181
1207
|
requestBodyValues
|
|
1182
1208
|
}) => {
|
|
1183
1209
|
if (response.body == null) {
|
|
1184
|
-
throw new
|
|
1210
|
+
throw new APICallError2({
|
|
1185
1211
|
message: "SSE response body is empty",
|
|
1186
1212
|
url,
|
|
1187
1213
|
requestBodyValues,
|
|
1188
1214
|
statusCode: response.status
|
|
1189
1215
|
});
|
|
1190
1216
|
}
|
|
1191
|
-
const eventStream =
|
|
1217
|
+
const eventStream = parseJsonEventStream({
|
|
1192
1218
|
stream: response.body,
|
|
1193
1219
|
schema: gatewayVideoEventSchema
|
|
1194
1220
|
});
|
|
@@ -1196,7 +1222,7 @@ var GatewayVideoModel = class {
|
|
|
1196
1222
|
const { done, value: parseResult } = await reader.read();
|
|
1197
1223
|
reader.releaseLock();
|
|
1198
1224
|
if (done || !parseResult) {
|
|
1199
|
-
throw new
|
|
1225
|
+
throw new APICallError2({
|
|
1200
1226
|
message: "SSE stream ended without a data event",
|
|
1201
1227
|
url,
|
|
1202
1228
|
requestBodyValues,
|
|
@@ -1204,7 +1230,7 @@ var GatewayVideoModel = class {
|
|
|
1204
1230
|
});
|
|
1205
1231
|
}
|
|
1206
1232
|
if (!parseResult.success) {
|
|
1207
|
-
throw new
|
|
1233
|
+
throw new APICallError2({
|
|
1208
1234
|
message: "Failed to parse video SSE event",
|
|
1209
1235
|
cause: parseResult.error,
|
|
1210
1236
|
url,
|
|
@@ -1214,7 +1240,7 @@ var GatewayVideoModel = class {
|
|
|
1214
1240
|
}
|
|
1215
1241
|
const event = parseResult.value;
|
|
1216
1242
|
if (event.type === "error") {
|
|
1217
|
-
throw new
|
|
1243
|
+
throw new APICallError2({
|
|
1218
1244
|
message: event.message,
|
|
1219
1245
|
statusCode: event.statusCode,
|
|
1220
1246
|
url,
|
|
@@ -1239,8 +1265,8 @@ var GatewayVideoModel = class {
|
|
|
1239
1265
|
responseHeaders: Object.fromEntries([...response.headers])
|
|
1240
1266
|
};
|
|
1241
1267
|
},
|
|
1242
|
-
failedResponseHandler: (
|
|
1243
|
-
errorSchema:
|
|
1268
|
+
failedResponseHandler: createJsonErrorResponseHandler7({
|
|
1269
|
+
errorSchema: z10.any(),
|
|
1244
1270
|
errorToMessage: (data) => data
|
|
1245
1271
|
}),
|
|
1246
1272
|
...abortSignal && { abortSignal },
|
|
@@ -1274,61 +1300,69 @@ function maybeEncodeVideoFile(file) {
|
|
|
1274
1300
|
if (file.type === "file" && file.data instanceof Uint8Array) {
|
|
1275
1301
|
return {
|
|
1276
1302
|
...file,
|
|
1277
|
-
data: (
|
|
1303
|
+
data: convertUint8ArrayToBase642(file.data)
|
|
1278
1304
|
};
|
|
1279
1305
|
}
|
|
1280
1306
|
return file;
|
|
1281
1307
|
}
|
|
1282
|
-
var providerMetadataEntrySchema2 =
|
|
1283
|
-
videos:
|
|
1284
|
-
}).catchall(
|
|
1285
|
-
var gatewayVideoDataSchema =
|
|
1286
|
-
|
|
1287
|
-
type:
|
|
1288
|
-
url:
|
|
1289
|
-
mediaType:
|
|
1308
|
+
var providerMetadataEntrySchema2 = z10.object({
|
|
1309
|
+
videos: z10.array(z10.unknown()).optional()
|
|
1310
|
+
}).catchall(z10.unknown());
|
|
1311
|
+
var gatewayVideoDataSchema = z10.union([
|
|
1312
|
+
z10.object({
|
|
1313
|
+
type: z10.literal("url"),
|
|
1314
|
+
url: z10.string(),
|
|
1315
|
+
mediaType: z10.string()
|
|
1290
1316
|
}),
|
|
1291
|
-
|
|
1292
|
-
type:
|
|
1293
|
-
data:
|
|
1294
|
-
mediaType:
|
|
1317
|
+
z10.object({
|
|
1318
|
+
type: z10.literal("base64"),
|
|
1319
|
+
data: z10.string(),
|
|
1320
|
+
mediaType: z10.string()
|
|
1295
1321
|
})
|
|
1296
1322
|
]);
|
|
1297
|
-
var gatewayVideoWarningSchema =
|
|
1298
|
-
|
|
1299
|
-
type:
|
|
1300
|
-
feature:
|
|
1301
|
-
details:
|
|
1323
|
+
var gatewayVideoWarningSchema = z10.discriminatedUnion("type", [
|
|
1324
|
+
z10.object({
|
|
1325
|
+
type: z10.literal("unsupported"),
|
|
1326
|
+
feature: z10.string(),
|
|
1327
|
+
details: z10.string().optional()
|
|
1302
1328
|
}),
|
|
1303
|
-
|
|
1304
|
-
type:
|
|
1305
|
-
feature:
|
|
1306
|
-
details:
|
|
1329
|
+
z10.object({
|
|
1330
|
+
type: z10.literal("compatibility"),
|
|
1331
|
+
feature: z10.string(),
|
|
1332
|
+
details: z10.string().optional()
|
|
1307
1333
|
}),
|
|
1308
|
-
|
|
1309
|
-
type:
|
|
1310
|
-
message:
|
|
1334
|
+
z10.object({
|
|
1335
|
+
type: z10.literal("other"),
|
|
1336
|
+
message: z10.string()
|
|
1311
1337
|
})
|
|
1312
1338
|
]);
|
|
1313
|
-
var gatewayVideoEventSchema =
|
|
1314
|
-
|
|
1315
|
-
type:
|
|
1316
|
-
videos:
|
|
1317
|
-
warnings:
|
|
1318
|
-
providerMetadata:
|
|
1339
|
+
var gatewayVideoEventSchema = z10.discriminatedUnion("type", [
|
|
1340
|
+
z10.object({
|
|
1341
|
+
type: z10.literal("result"),
|
|
1342
|
+
videos: z10.array(gatewayVideoDataSchema),
|
|
1343
|
+
warnings: z10.array(gatewayVideoWarningSchema).optional(),
|
|
1344
|
+
providerMetadata: z10.record(z10.string(), providerMetadataEntrySchema2).optional()
|
|
1319
1345
|
}),
|
|
1320
|
-
|
|
1321
|
-
type:
|
|
1322
|
-
message:
|
|
1323
|
-
errorType:
|
|
1324
|
-
statusCode:
|
|
1325
|
-
param:
|
|
1346
|
+
z10.object({
|
|
1347
|
+
type: z10.literal("error"),
|
|
1348
|
+
message: z10.string(),
|
|
1349
|
+
errorType: z10.string(),
|
|
1350
|
+
statusCode: z10.number(),
|
|
1351
|
+
param: z10.unknown().nullable()
|
|
1326
1352
|
})
|
|
1327
1353
|
]);
|
|
1328
1354
|
|
|
1329
1355
|
// src/gateway-reranking-model.ts
|
|
1330
|
-
|
|
1331
|
-
|
|
1356
|
+
import {
|
|
1357
|
+
combineHeaders as combineHeaders5,
|
|
1358
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler8,
|
|
1359
|
+
createJsonResponseHandler as createJsonResponseHandler7,
|
|
1360
|
+
lazySchema as lazySchema8,
|
|
1361
|
+
postJsonToApi as postJsonToApi5,
|
|
1362
|
+
resolve as resolve8,
|
|
1363
|
+
zodSchema as zodSchema8
|
|
1364
|
+
} from "@ai-sdk/provider-utils";
|
|
1365
|
+
import { z as z11 } from "zod/v4";
|
|
1332
1366
|
var GatewayRerankingModel = class {
|
|
1333
1367
|
constructor(modelId, config) {
|
|
1334
1368
|
this.modelId = modelId;
|
|
@@ -1346,19 +1380,19 @@ var GatewayRerankingModel = class {
|
|
|
1346
1380
|
abortSignal,
|
|
1347
1381
|
providerOptions
|
|
1348
1382
|
}) {
|
|
1349
|
-
const resolvedHeaders = await (
|
|
1383
|
+
const resolvedHeaders = await resolve8(this.config.headers());
|
|
1350
1384
|
try {
|
|
1351
1385
|
const {
|
|
1352
1386
|
responseHeaders,
|
|
1353
1387
|
value: responseBody,
|
|
1354
1388
|
rawValue
|
|
1355
|
-
} = await (
|
|
1389
|
+
} = await postJsonToApi5({
|
|
1356
1390
|
url: this.getUrl(),
|
|
1357
|
-
headers: (
|
|
1391
|
+
headers: combineHeaders5(
|
|
1358
1392
|
resolvedHeaders,
|
|
1359
1393
|
headers != null ? headers : {},
|
|
1360
1394
|
this.getModelConfigHeaders(),
|
|
1361
|
-
await (
|
|
1395
|
+
await resolve8(this.config.o11yHeaders)
|
|
1362
1396
|
),
|
|
1363
1397
|
body: {
|
|
1364
1398
|
documents,
|
|
@@ -1366,11 +1400,11 @@ var GatewayRerankingModel = class {
|
|
|
1366
1400
|
...topN != null ? { topN } : {},
|
|
1367
1401
|
...providerOptions ? { providerOptions } : {}
|
|
1368
1402
|
},
|
|
1369
|
-
successfulResponseHandler: (
|
|
1403
|
+
successfulResponseHandler: createJsonResponseHandler7(
|
|
1370
1404
|
gatewayRerankingResponseSchema
|
|
1371
1405
|
),
|
|
1372
|
-
failedResponseHandler: (
|
|
1373
|
-
errorSchema:
|
|
1406
|
+
failedResponseHandler: createJsonErrorResponseHandler8({
|
|
1407
|
+
errorSchema: z11.any(),
|
|
1374
1408
|
errorToMessage: (data) => data
|
|
1375
1409
|
}),
|
|
1376
1410
|
...abortSignal && { abortSignal },
|
|
@@ -1396,78 +1430,82 @@ var GatewayRerankingModel = class {
|
|
|
1396
1430
|
};
|
|
1397
1431
|
}
|
|
1398
1432
|
};
|
|
1399
|
-
var gatewayRerankingResponseSchema = (
|
|
1400
|
-
() => (
|
|
1401
|
-
|
|
1402
|
-
ranking:
|
|
1403
|
-
|
|
1404
|
-
index:
|
|
1405
|
-
relevanceScore:
|
|
1433
|
+
var gatewayRerankingResponseSchema = lazySchema8(
|
|
1434
|
+
() => zodSchema8(
|
|
1435
|
+
z11.object({
|
|
1436
|
+
ranking: z11.array(
|
|
1437
|
+
z11.object({
|
|
1438
|
+
index: z11.number(),
|
|
1439
|
+
relevanceScore: z11.number()
|
|
1406
1440
|
})
|
|
1407
1441
|
),
|
|
1408
|
-
providerMetadata:
|
|
1442
|
+
providerMetadata: z11.record(z11.string(), z11.record(z11.string(), z11.unknown())).optional()
|
|
1409
1443
|
})
|
|
1410
1444
|
)
|
|
1411
1445
|
);
|
|
1412
1446
|
|
|
1413
1447
|
// src/tool/parallel-search.ts
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1448
|
+
import {
|
|
1449
|
+
createProviderToolFactoryWithOutputSchema,
|
|
1450
|
+
lazySchema as lazySchema9,
|
|
1451
|
+
zodSchema as zodSchema9
|
|
1452
|
+
} from "@ai-sdk/provider-utils";
|
|
1453
|
+
import { z as z12 } from "zod";
|
|
1454
|
+
var parallelSearchInputSchema = lazySchema9(
|
|
1455
|
+
() => zodSchema9(
|
|
1456
|
+
z12.object({
|
|
1457
|
+
objective: z12.string().describe(
|
|
1420
1458
|
"Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
|
|
1421
1459
|
),
|
|
1422
|
-
search_queries:
|
|
1460
|
+
search_queries: z12.array(z12.string()).optional().describe(
|
|
1423
1461
|
"Optional search queries to supplement the objective. Maximum 200 characters per query."
|
|
1424
1462
|
),
|
|
1425
|
-
mode:
|
|
1463
|
+
mode: z12.enum(["one-shot", "agentic"]).optional().describe(
|
|
1426
1464
|
'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
|
|
1427
1465
|
),
|
|
1428
|
-
max_results:
|
|
1466
|
+
max_results: z12.number().optional().describe(
|
|
1429
1467
|
"Maximum number of results to return (1-20). Defaults to 10 if not specified."
|
|
1430
1468
|
),
|
|
1431
|
-
source_policy:
|
|
1432
|
-
include_domains:
|
|
1433
|
-
exclude_domains:
|
|
1434
|
-
after_date:
|
|
1469
|
+
source_policy: z12.object({
|
|
1470
|
+
include_domains: z12.array(z12.string()).optional().describe("List of domains to include in search results."),
|
|
1471
|
+
exclude_domains: z12.array(z12.string()).optional().describe("List of domains to exclude from search results."),
|
|
1472
|
+
after_date: z12.string().optional().describe(
|
|
1435
1473
|
"Only include results published after this date (ISO 8601 format)."
|
|
1436
1474
|
)
|
|
1437
1475
|
}).optional().describe(
|
|
1438
1476
|
"Source policy for controlling which domains to include/exclude and freshness."
|
|
1439
1477
|
),
|
|
1440
|
-
excerpts:
|
|
1441
|
-
max_chars_per_result:
|
|
1442
|
-
max_chars_total:
|
|
1478
|
+
excerpts: z12.object({
|
|
1479
|
+
max_chars_per_result: z12.number().optional().describe("Maximum characters per result."),
|
|
1480
|
+
max_chars_total: z12.number().optional().describe("Maximum total characters across all results.")
|
|
1443
1481
|
}).optional().describe("Excerpt configuration for controlling result length."),
|
|
1444
|
-
fetch_policy:
|
|
1445
|
-
max_age_seconds:
|
|
1482
|
+
fetch_policy: z12.object({
|
|
1483
|
+
max_age_seconds: z12.number().optional().describe(
|
|
1446
1484
|
"Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
|
|
1447
1485
|
)
|
|
1448
1486
|
}).optional().describe("Fetch policy for controlling content freshness.")
|
|
1449
1487
|
})
|
|
1450
1488
|
)
|
|
1451
1489
|
);
|
|
1452
|
-
var parallelSearchOutputSchema = (
|
|
1453
|
-
() => (
|
|
1454
|
-
|
|
1490
|
+
var parallelSearchOutputSchema = lazySchema9(
|
|
1491
|
+
() => zodSchema9(
|
|
1492
|
+
z12.union([
|
|
1455
1493
|
// Success response
|
|
1456
|
-
|
|
1457
|
-
searchId:
|
|
1458
|
-
results:
|
|
1459
|
-
|
|
1460
|
-
url:
|
|
1461
|
-
title:
|
|
1462
|
-
excerpt:
|
|
1463
|
-
publishDate:
|
|
1464
|
-
relevanceScore:
|
|
1494
|
+
z12.object({
|
|
1495
|
+
searchId: z12.string(),
|
|
1496
|
+
results: z12.array(
|
|
1497
|
+
z12.object({
|
|
1498
|
+
url: z12.string(),
|
|
1499
|
+
title: z12.string(),
|
|
1500
|
+
excerpt: z12.string(),
|
|
1501
|
+
publishDate: z12.string().nullable().optional(),
|
|
1502
|
+
relevanceScore: z12.number().optional()
|
|
1465
1503
|
})
|
|
1466
1504
|
)
|
|
1467
1505
|
}),
|
|
1468
1506
|
// Error response
|
|
1469
|
-
|
|
1470
|
-
error:
|
|
1507
|
+
z12.object({
|
|
1508
|
+
error: z12.enum([
|
|
1471
1509
|
"api_error",
|
|
1472
1510
|
"rate_limit",
|
|
1473
1511
|
"timeout",
|
|
@@ -1475,13 +1513,13 @@ var parallelSearchOutputSchema = (0, import_provider_utils12.lazySchema)(
|
|
|
1475
1513
|
"configuration_error",
|
|
1476
1514
|
"unknown"
|
|
1477
1515
|
]),
|
|
1478
|
-
statusCode:
|
|
1479
|
-
message:
|
|
1516
|
+
statusCode: z12.number().optional(),
|
|
1517
|
+
message: z12.string()
|
|
1480
1518
|
})
|
|
1481
1519
|
])
|
|
1482
1520
|
)
|
|
1483
1521
|
);
|
|
1484
|
-
var parallelSearchToolFactory =
|
|
1522
|
+
var parallelSearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
1485
1523
|
id: "gateway.parallel_search",
|
|
1486
1524
|
inputSchema: parallelSearchInputSchema,
|
|
1487
1525
|
outputSchema: parallelSearchOutputSchema
|
|
@@ -1489,82 +1527,86 @@ var parallelSearchToolFactory = (0, import_provider_utils12.createProviderToolFa
|
|
|
1489
1527
|
var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
|
|
1490
1528
|
|
|
1491
1529
|
// src/tool/perplexity-search.ts
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1530
|
+
import {
|
|
1531
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema2,
|
|
1532
|
+
lazySchema as lazySchema10,
|
|
1533
|
+
zodSchema as zodSchema10
|
|
1534
|
+
} from "@ai-sdk/provider-utils";
|
|
1535
|
+
import { z as z13 } from "zod";
|
|
1536
|
+
var perplexitySearchInputSchema = lazySchema10(
|
|
1537
|
+
() => zodSchema10(
|
|
1538
|
+
z13.object({
|
|
1539
|
+
query: z13.union([z13.string(), z13.array(z13.string())]).describe(
|
|
1498
1540
|
"Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
|
|
1499
1541
|
),
|
|
1500
|
-
max_results:
|
|
1542
|
+
max_results: z13.number().optional().describe(
|
|
1501
1543
|
"Maximum number of search results to return (1-20, default: 10)"
|
|
1502
1544
|
),
|
|
1503
|
-
max_tokens_per_page:
|
|
1545
|
+
max_tokens_per_page: z13.number().optional().describe(
|
|
1504
1546
|
"Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
|
|
1505
1547
|
),
|
|
1506
|
-
max_tokens:
|
|
1548
|
+
max_tokens: z13.number().optional().describe(
|
|
1507
1549
|
"Maximum total tokens across all search results (default: 25000, max: 1000000)"
|
|
1508
1550
|
),
|
|
1509
|
-
country:
|
|
1551
|
+
country: z13.string().optional().describe(
|
|
1510
1552
|
"Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
|
|
1511
1553
|
),
|
|
1512
|
-
search_domain_filter:
|
|
1554
|
+
search_domain_filter: z13.array(z13.string()).optional().describe(
|
|
1513
1555
|
"List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
|
|
1514
1556
|
),
|
|
1515
|
-
search_language_filter:
|
|
1557
|
+
search_language_filter: z13.array(z13.string()).optional().describe(
|
|
1516
1558
|
"List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
|
|
1517
1559
|
),
|
|
1518
|
-
search_after_date:
|
|
1560
|
+
search_after_date: z13.string().optional().describe(
|
|
1519
1561
|
"Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
1520
1562
|
),
|
|
1521
|
-
search_before_date:
|
|
1563
|
+
search_before_date: z13.string().optional().describe(
|
|
1522
1564
|
"Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
1523
1565
|
),
|
|
1524
|
-
last_updated_after_filter:
|
|
1566
|
+
last_updated_after_filter: z13.string().optional().describe(
|
|
1525
1567
|
"Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
1526
1568
|
),
|
|
1527
|
-
last_updated_before_filter:
|
|
1569
|
+
last_updated_before_filter: z13.string().optional().describe(
|
|
1528
1570
|
"Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
1529
1571
|
),
|
|
1530
|
-
search_recency_filter:
|
|
1572
|
+
search_recency_filter: z13.enum(["day", "week", "month", "year"]).optional().describe(
|
|
1531
1573
|
"Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
|
|
1532
1574
|
)
|
|
1533
1575
|
})
|
|
1534
1576
|
)
|
|
1535
1577
|
);
|
|
1536
|
-
var perplexitySearchOutputSchema = (
|
|
1537
|
-
() => (
|
|
1538
|
-
|
|
1578
|
+
var perplexitySearchOutputSchema = lazySchema10(
|
|
1579
|
+
() => zodSchema10(
|
|
1580
|
+
z13.union([
|
|
1539
1581
|
// Success response
|
|
1540
|
-
|
|
1541
|
-
results:
|
|
1542
|
-
|
|
1543
|
-
title:
|
|
1544
|
-
url:
|
|
1545
|
-
snippet:
|
|
1546
|
-
date:
|
|
1547
|
-
lastUpdated:
|
|
1582
|
+
z13.object({
|
|
1583
|
+
results: z13.array(
|
|
1584
|
+
z13.object({
|
|
1585
|
+
title: z13.string(),
|
|
1586
|
+
url: z13.string(),
|
|
1587
|
+
snippet: z13.string(),
|
|
1588
|
+
date: z13.string().optional(),
|
|
1589
|
+
lastUpdated: z13.string().optional()
|
|
1548
1590
|
})
|
|
1549
1591
|
),
|
|
1550
|
-
id:
|
|
1592
|
+
id: z13.string()
|
|
1551
1593
|
}),
|
|
1552
1594
|
// Error response
|
|
1553
|
-
|
|
1554
|
-
error:
|
|
1595
|
+
z13.object({
|
|
1596
|
+
error: z13.enum([
|
|
1555
1597
|
"api_error",
|
|
1556
1598
|
"rate_limit",
|
|
1557
1599
|
"timeout",
|
|
1558
1600
|
"invalid_input",
|
|
1559
1601
|
"unknown"
|
|
1560
1602
|
]),
|
|
1561
|
-
statusCode:
|
|
1562
|
-
message:
|
|
1603
|
+
statusCode: z13.number().optional(),
|
|
1604
|
+
message: z13.string()
|
|
1563
1605
|
})
|
|
1564
1606
|
])
|
|
1565
1607
|
)
|
|
1566
1608
|
);
|
|
1567
|
-
var perplexitySearchToolFactory = (
|
|
1609
|
+
var perplexitySearchToolFactory = createProviderToolFactoryWithOutputSchema2({
|
|
1568
1610
|
id: "gateway.perplexity_search",
|
|
1569
1611
|
inputSchema: perplexitySearchInputSchema,
|
|
1570
1612
|
outputSchema: perplexitySearchOutputSchema
|
|
@@ -1593,18 +1635,18 @@ var gatewayTools = {
|
|
|
1593
1635
|
};
|
|
1594
1636
|
|
|
1595
1637
|
// src/vercel-environment.ts
|
|
1596
|
-
|
|
1597
|
-
|
|
1638
|
+
import { getContext } from "@vercel/oidc";
|
|
1639
|
+
import { getVercelOidcToken } from "@vercel/oidc";
|
|
1598
1640
|
async function getVercelRequestId() {
|
|
1599
1641
|
var _a9;
|
|
1600
|
-
return (_a9 =
|
|
1642
|
+
return (_a9 = getContext().headers) == null ? void 0 : _a9["x-vercel-id"];
|
|
1601
1643
|
}
|
|
1602
1644
|
|
|
1603
1645
|
// src/gateway-provider.ts
|
|
1604
|
-
|
|
1646
|
+
import { withUserAgentSuffix } from "@ai-sdk/provider-utils";
|
|
1605
1647
|
|
|
1606
1648
|
// src/version.ts
|
|
1607
|
-
var VERSION = true ? "4.0.0-beta.
|
|
1649
|
+
var VERSION = true ? "4.0.0-beta.49" : "0.0.0-test";
|
|
1608
1650
|
|
|
1609
1651
|
// src/gateway-provider.ts
|
|
1610
1652
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
@@ -1614,11 +1656,11 @@ function createGatewayProvider(options = {}) {
|
|
|
1614
1656
|
let metadataCache = null;
|
|
1615
1657
|
const cacheRefreshMillis = (_a9 = options.metadataCacheRefreshMillis) != null ? _a9 : 1e3 * 60 * 5;
|
|
1616
1658
|
let lastFetchTime = 0;
|
|
1617
|
-
const baseURL = (_b9 =
|
|
1659
|
+
const baseURL = (_b9 = withoutTrailingSlash(options.baseURL)) != null ? _b9 : "https://ai-gateway.vercel.sh/v3/ai";
|
|
1618
1660
|
const getHeaders = async () => {
|
|
1619
1661
|
try {
|
|
1620
1662
|
const auth = await getGatewayAuthToken(options);
|
|
1621
|
-
return
|
|
1663
|
+
return withUserAgentSuffix(
|
|
1622
1664
|
{
|
|
1623
1665
|
Authorization: `Bearer ${auth.token}`,
|
|
1624
1666
|
"ai-gateway-protocol-version": AI_GATEWAY_PROTOCOL_VERSION,
|
|
@@ -1637,19 +1679,19 @@ function createGatewayProvider(options = {}) {
|
|
|
1637
1679
|
}
|
|
1638
1680
|
};
|
|
1639
1681
|
const createO11yHeaders = () => {
|
|
1640
|
-
const deploymentId =
|
|
1682
|
+
const deploymentId = loadOptionalSetting({
|
|
1641
1683
|
settingValue: void 0,
|
|
1642
1684
|
environmentVariableName: "VERCEL_DEPLOYMENT_ID"
|
|
1643
1685
|
});
|
|
1644
|
-
const environment =
|
|
1686
|
+
const environment = loadOptionalSetting({
|
|
1645
1687
|
settingValue: void 0,
|
|
1646
1688
|
environmentVariableName: "VERCEL_ENV"
|
|
1647
1689
|
});
|
|
1648
|
-
const region =
|
|
1690
|
+
const region = loadOptionalSetting({
|
|
1649
1691
|
settingValue: void 0,
|
|
1650
1692
|
environmentVariableName: "VERCEL_REGION"
|
|
1651
1693
|
});
|
|
1652
|
-
const projectId =
|
|
1694
|
+
const projectId = loadOptionalSetting({
|
|
1653
1695
|
settingValue: void 0,
|
|
1654
1696
|
environmentVariableName: "VERCEL_PROJECT_ID"
|
|
1655
1697
|
});
|
|
@@ -1793,7 +1835,7 @@ function createGatewayProvider(options = {}) {
|
|
|
1793
1835
|
}
|
|
1794
1836
|
var gateway = createGatewayProvider();
|
|
1795
1837
|
async function getGatewayAuthToken(options) {
|
|
1796
|
-
const apiKey =
|
|
1838
|
+
const apiKey = loadOptionalSetting({
|
|
1797
1839
|
settingValue: options.apiKey,
|
|
1798
1840
|
environmentVariableName: "AI_GATEWAY_API_KEY"
|
|
1799
1841
|
});
|
|
@@ -1803,14 +1845,13 @@ async function getGatewayAuthToken(options) {
|
|
|
1803
1845
|
authMethod: "api-key"
|
|
1804
1846
|
};
|
|
1805
1847
|
}
|
|
1806
|
-
const oidcToken = await
|
|
1848
|
+
const oidcToken = await getVercelOidcToken();
|
|
1807
1849
|
return {
|
|
1808
1850
|
token: oidcToken,
|
|
1809
1851
|
authMethod: "oidc"
|
|
1810
1852
|
};
|
|
1811
1853
|
}
|
|
1812
|
-
|
|
1813
|
-
0 && (module.exports = {
|
|
1854
|
+
export {
|
|
1814
1855
|
GatewayAuthenticationError,
|
|
1815
1856
|
GatewayError,
|
|
1816
1857
|
GatewayInternalServerError,
|
|
@@ -1818,8 +1859,8 @@ async function getGatewayAuthToken(options) {
|
|
|
1818
1859
|
GatewayModelNotFoundError,
|
|
1819
1860
|
GatewayRateLimitError,
|
|
1820
1861
|
GatewayResponseError,
|
|
1821
|
-
createGateway,
|
|
1862
|
+
createGatewayProvider as createGateway,
|
|
1822
1863
|
createGatewayProvider,
|
|
1823
1864
|
gateway
|
|
1824
|
-
}
|
|
1865
|
+
};
|
|
1825
1866
|
//# sourceMappingURL=index.js.map
|