@ai-sdk/gateway 4.0.0-beta.22 → 4.0.0-beta.24
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 +12 -0
- package/dist/index.d.mts +64 -3
- package/dist/index.d.ts +64 -3
- package/dist/index.js +246 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +298 -176
- package/dist/index.mjs.map +1 -1
- package/docs/00-ai-gateway.mdx +87 -14
- package/package.json +1 -1
- package/src/gateway-provider-options.ts +2 -4
- package/src/gateway-provider.ts +29 -0
- package/src/gateway-spend-report.ts +191 -0
- package/src/index.ts +8 -3
package/dist/index.mjs
CHANGED
|
@@ -558,16 +558,125 @@ var gatewayCreditsResponseSchema = lazySchema4(
|
|
|
558
558
|
)
|
|
559
559
|
);
|
|
560
560
|
|
|
561
|
+
// src/gateway-spend-report.ts
|
|
562
|
+
import {
|
|
563
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
564
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
565
|
+
getFromApi as getFromApi2,
|
|
566
|
+
lazySchema as lazySchema5,
|
|
567
|
+
resolve as resolve2,
|
|
568
|
+
zodSchema as zodSchema5
|
|
569
|
+
} from "@ai-sdk/provider-utils";
|
|
570
|
+
import { z as z5 } from "zod/v4";
|
|
571
|
+
var GatewaySpendReport = class {
|
|
572
|
+
constructor(config) {
|
|
573
|
+
this.config = config;
|
|
574
|
+
}
|
|
575
|
+
async getSpendReport(params) {
|
|
576
|
+
try {
|
|
577
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
578
|
+
const searchParams = new URLSearchParams();
|
|
579
|
+
searchParams.set("start_date", params.startDate);
|
|
580
|
+
searchParams.set("end_date", params.endDate);
|
|
581
|
+
if (params.groupBy) {
|
|
582
|
+
searchParams.set("group_by", params.groupBy);
|
|
583
|
+
}
|
|
584
|
+
if (params.datePart) {
|
|
585
|
+
searchParams.set("date_part", params.datePart);
|
|
586
|
+
}
|
|
587
|
+
if (params.userId) {
|
|
588
|
+
searchParams.set("user_id", params.userId);
|
|
589
|
+
}
|
|
590
|
+
if (params.model) {
|
|
591
|
+
searchParams.set("model", params.model);
|
|
592
|
+
}
|
|
593
|
+
if (params.provider) {
|
|
594
|
+
searchParams.set("provider", params.provider);
|
|
595
|
+
}
|
|
596
|
+
if (params.credentialType) {
|
|
597
|
+
searchParams.set("credential_type", params.credentialType);
|
|
598
|
+
}
|
|
599
|
+
if (params.tags && params.tags.length > 0) {
|
|
600
|
+
searchParams.set("tags", params.tags.join(","));
|
|
601
|
+
}
|
|
602
|
+
const { value } = await getFromApi2({
|
|
603
|
+
url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
|
|
604
|
+
headers: await resolve2(this.config.headers()),
|
|
605
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
606
|
+
gatewaySpendReportResponseSchema
|
|
607
|
+
),
|
|
608
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
609
|
+
errorSchema: z5.any(),
|
|
610
|
+
errorToMessage: (data) => data
|
|
611
|
+
}),
|
|
612
|
+
fetch: this.config.fetch
|
|
613
|
+
});
|
|
614
|
+
return value;
|
|
615
|
+
} catch (error) {
|
|
616
|
+
throw await asGatewayError(error);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
var gatewaySpendReportResponseSchema = lazySchema5(
|
|
621
|
+
() => zodSchema5(
|
|
622
|
+
z5.object({
|
|
623
|
+
results: z5.array(
|
|
624
|
+
z5.object({
|
|
625
|
+
day: z5.string().optional(),
|
|
626
|
+
hour: z5.string().optional(),
|
|
627
|
+
user: z5.string().optional(),
|
|
628
|
+
model: z5.string().optional(),
|
|
629
|
+
tag: z5.string().optional(),
|
|
630
|
+
provider: z5.string().optional(),
|
|
631
|
+
credential_type: z5.enum(["byok", "system"]).optional(),
|
|
632
|
+
total_cost: z5.number(),
|
|
633
|
+
market_cost: z5.number().optional(),
|
|
634
|
+
input_tokens: z5.number().optional(),
|
|
635
|
+
output_tokens: z5.number().optional(),
|
|
636
|
+
cached_input_tokens: z5.number().optional(),
|
|
637
|
+
cache_creation_input_tokens: z5.number().optional(),
|
|
638
|
+
reasoning_tokens: z5.number().optional(),
|
|
639
|
+
request_count: z5.number().optional()
|
|
640
|
+
}).transform(
|
|
641
|
+
({
|
|
642
|
+
credential_type,
|
|
643
|
+
total_cost,
|
|
644
|
+
market_cost,
|
|
645
|
+
input_tokens,
|
|
646
|
+
output_tokens,
|
|
647
|
+
cached_input_tokens,
|
|
648
|
+
cache_creation_input_tokens,
|
|
649
|
+
reasoning_tokens,
|
|
650
|
+
request_count,
|
|
651
|
+
...rest
|
|
652
|
+
}) => ({
|
|
653
|
+
...rest,
|
|
654
|
+
...credential_type !== void 0 ? { credentialType: credential_type } : {},
|
|
655
|
+
totalCost: total_cost,
|
|
656
|
+
...market_cost !== void 0 ? { marketCost: market_cost } : {},
|
|
657
|
+
...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
|
|
658
|
+
...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
|
|
659
|
+
...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
|
|
660
|
+
...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
|
|
661
|
+
...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
|
|
662
|
+
...request_count !== void 0 ? { requestCount: request_count } : {}
|
|
663
|
+
})
|
|
664
|
+
)
|
|
665
|
+
)
|
|
666
|
+
})
|
|
667
|
+
)
|
|
668
|
+
);
|
|
669
|
+
|
|
561
670
|
// src/gateway-language-model.ts
|
|
562
671
|
import {
|
|
563
672
|
combineHeaders,
|
|
564
673
|
createEventSourceResponseHandler,
|
|
565
|
-
createJsonErrorResponseHandler as
|
|
566
|
-
createJsonResponseHandler as
|
|
674
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
675
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
567
676
|
postJsonToApi,
|
|
568
|
-
resolve as
|
|
677
|
+
resolve as resolve3
|
|
569
678
|
} from "@ai-sdk/provider-utils";
|
|
570
|
-
import { z as
|
|
679
|
+
import { z as z6 } from "zod/v4";
|
|
571
680
|
var GatewayLanguageModel = class {
|
|
572
681
|
constructor(modelId, config) {
|
|
573
682
|
this.modelId = modelId;
|
|
@@ -588,7 +697,7 @@ var GatewayLanguageModel = class {
|
|
|
588
697
|
async doGenerate(options) {
|
|
589
698
|
const { args, warnings } = await this.getArgs(options);
|
|
590
699
|
const { abortSignal } = options;
|
|
591
|
-
const resolvedHeaders = await
|
|
700
|
+
const resolvedHeaders = await resolve3(this.config.headers());
|
|
592
701
|
try {
|
|
593
702
|
const {
|
|
594
703
|
responseHeaders,
|
|
@@ -600,12 +709,12 @@ var GatewayLanguageModel = class {
|
|
|
600
709
|
resolvedHeaders,
|
|
601
710
|
options.headers,
|
|
602
711
|
this.getModelConfigHeaders(this.modelId, false),
|
|
603
|
-
await
|
|
712
|
+
await resolve3(this.config.o11yHeaders)
|
|
604
713
|
),
|
|
605
714
|
body: args,
|
|
606
|
-
successfulResponseHandler:
|
|
607
|
-
failedResponseHandler:
|
|
608
|
-
errorSchema:
|
|
715
|
+
successfulResponseHandler: createJsonResponseHandler3(z6.any()),
|
|
716
|
+
failedResponseHandler: createJsonErrorResponseHandler3({
|
|
717
|
+
errorSchema: z6.any(),
|
|
609
718
|
errorToMessage: (data) => data
|
|
610
719
|
}),
|
|
611
720
|
...abortSignal && { abortSignal },
|
|
@@ -624,7 +733,7 @@ var GatewayLanguageModel = class {
|
|
|
624
733
|
async doStream(options) {
|
|
625
734
|
const { args, warnings } = await this.getArgs(options);
|
|
626
735
|
const { abortSignal } = options;
|
|
627
|
-
const resolvedHeaders = await
|
|
736
|
+
const resolvedHeaders = await resolve3(this.config.headers());
|
|
628
737
|
try {
|
|
629
738
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
630
739
|
url: this.getUrl(),
|
|
@@ -632,12 +741,12 @@ var GatewayLanguageModel = class {
|
|
|
632
741
|
resolvedHeaders,
|
|
633
742
|
options.headers,
|
|
634
743
|
this.getModelConfigHeaders(this.modelId, true),
|
|
635
|
-
await
|
|
744
|
+
await resolve3(this.config.o11yHeaders)
|
|
636
745
|
),
|
|
637
746
|
body: args,
|
|
638
|
-
successfulResponseHandler: createEventSourceResponseHandler(
|
|
639
|
-
failedResponseHandler:
|
|
640
|
-
errorSchema:
|
|
747
|
+
successfulResponseHandler: createEventSourceResponseHandler(z6.any()),
|
|
748
|
+
failedResponseHandler: createJsonErrorResponseHandler3({
|
|
749
|
+
errorSchema: z6.any(),
|
|
641
750
|
errorToMessage: (data) => data
|
|
642
751
|
}),
|
|
643
752
|
...abortSignal && { abortSignal },
|
|
@@ -717,14 +826,14 @@ var GatewayLanguageModel = class {
|
|
|
717
826
|
// src/gateway-embedding-model.ts
|
|
718
827
|
import {
|
|
719
828
|
combineHeaders as combineHeaders2,
|
|
720
|
-
createJsonErrorResponseHandler as
|
|
721
|
-
createJsonResponseHandler as
|
|
722
|
-
lazySchema as
|
|
829
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
|
|
830
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
831
|
+
lazySchema as lazySchema6,
|
|
723
832
|
postJsonToApi as postJsonToApi2,
|
|
724
|
-
resolve as
|
|
725
|
-
zodSchema as
|
|
833
|
+
resolve as resolve4,
|
|
834
|
+
zodSchema as zodSchema6
|
|
726
835
|
} from "@ai-sdk/provider-utils";
|
|
727
|
-
import { z as
|
|
836
|
+
import { z as z7 } from "zod/v4";
|
|
728
837
|
var GatewayEmbeddingModel = class {
|
|
729
838
|
constructor(modelId, config) {
|
|
730
839
|
this.modelId = modelId;
|
|
@@ -743,7 +852,7 @@ var GatewayEmbeddingModel = class {
|
|
|
743
852
|
providerOptions
|
|
744
853
|
}) {
|
|
745
854
|
var _a9;
|
|
746
|
-
const resolvedHeaders = await
|
|
855
|
+
const resolvedHeaders = await resolve4(this.config.headers());
|
|
747
856
|
try {
|
|
748
857
|
const {
|
|
749
858
|
responseHeaders,
|
|
@@ -755,17 +864,17 @@ var GatewayEmbeddingModel = class {
|
|
|
755
864
|
resolvedHeaders,
|
|
756
865
|
headers != null ? headers : {},
|
|
757
866
|
this.getModelConfigHeaders(),
|
|
758
|
-
await
|
|
867
|
+
await resolve4(this.config.o11yHeaders)
|
|
759
868
|
),
|
|
760
869
|
body: {
|
|
761
870
|
values,
|
|
762
871
|
...providerOptions ? { providerOptions } : {}
|
|
763
872
|
},
|
|
764
|
-
successfulResponseHandler:
|
|
873
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
765
874
|
gatewayEmbeddingResponseSchema
|
|
766
875
|
),
|
|
767
|
-
failedResponseHandler:
|
|
768
|
-
errorSchema:
|
|
876
|
+
failedResponseHandler: createJsonErrorResponseHandler4({
|
|
877
|
+
errorSchema: z7.any(),
|
|
769
878
|
errorToMessage: (data) => data
|
|
770
879
|
}),
|
|
771
880
|
...abortSignal && { abortSignal },
|
|
@@ -792,12 +901,12 @@ var GatewayEmbeddingModel = class {
|
|
|
792
901
|
};
|
|
793
902
|
}
|
|
794
903
|
};
|
|
795
|
-
var gatewayEmbeddingResponseSchema =
|
|
796
|
-
() =>
|
|
797
|
-
|
|
798
|
-
embeddings:
|
|
799
|
-
usage:
|
|
800
|
-
providerMetadata:
|
|
904
|
+
var gatewayEmbeddingResponseSchema = lazySchema6(
|
|
905
|
+
() => zodSchema6(
|
|
906
|
+
z7.object({
|
|
907
|
+
embeddings: z7.array(z7.array(z7.number())),
|
|
908
|
+
usage: z7.object({ tokens: z7.number() }).nullish(),
|
|
909
|
+
providerMetadata: z7.record(z7.string(), z7.record(z7.string(), z7.unknown())).optional()
|
|
801
910
|
})
|
|
802
911
|
)
|
|
803
912
|
);
|
|
@@ -806,12 +915,12 @@ var gatewayEmbeddingResponseSchema = lazySchema5(
|
|
|
806
915
|
import {
|
|
807
916
|
combineHeaders as combineHeaders3,
|
|
808
917
|
convertUint8ArrayToBase64,
|
|
809
|
-
createJsonResponseHandler as
|
|
810
|
-
createJsonErrorResponseHandler as
|
|
918
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
919
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler5,
|
|
811
920
|
postJsonToApi as postJsonToApi3,
|
|
812
|
-
resolve as
|
|
921
|
+
resolve as resolve5
|
|
813
922
|
} from "@ai-sdk/provider-utils";
|
|
814
|
-
import { z as
|
|
923
|
+
import { z as z8 } from "zod/v4";
|
|
815
924
|
var GatewayImageModel = class {
|
|
816
925
|
constructor(modelId, config) {
|
|
817
926
|
this.modelId = modelId;
|
|
@@ -836,7 +945,7 @@ var GatewayImageModel = class {
|
|
|
836
945
|
abortSignal
|
|
837
946
|
}) {
|
|
838
947
|
var _a9, _b9, _c, _d;
|
|
839
|
-
const resolvedHeaders = await
|
|
948
|
+
const resolvedHeaders = await resolve5(this.config.headers());
|
|
840
949
|
try {
|
|
841
950
|
const {
|
|
842
951
|
responseHeaders,
|
|
@@ -848,7 +957,7 @@ var GatewayImageModel = class {
|
|
|
848
957
|
resolvedHeaders,
|
|
849
958
|
headers != null ? headers : {},
|
|
850
959
|
this.getModelConfigHeaders(),
|
|
851
|
-
await
|
|
960
|
+
await resolve5(this.config.o11yHeaders)
|
|
852
961
|
),
|
|
853
962
|
body: {
|
|
854
963
|
prompt,
|
|
@@ -862,11 +971,11 @@ var GatewayImageModel = class {
|
|
|
862
971
|
},
|
|
863
972
|
...mask && { mask: maybeEncodeImageFile(mask) }
|
|
864
973
|
},
|
|
865
|
-
successfulResponseHandler:
|
|
974
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
866
975
|
gatewayImageResponseSchema
|
|
867
976
|
),
|
|
868
|
-
failedResponseHandler:
|
|
869
|
-
errorSchema:
|
|
977
|
+
failedResponseHandler: createJsonErrorResponseHandler5({
|
|
978
|
+
errorSchema: z8.any(),
|
|
870
979
|
errorToMessage: (data) => data
|
|
871
980
|
}),
|
|
872
981
|
...abortSignal && { abortSignal },
|
|
@@ -913,35 +1022,35 @@ function maybeEncodeImageFile(file) {
|
|
|
913
1022
|
}
|
|
914
1023
|
return file;
|
|
915
1024
|
}
|
|
916
|
-
var providerMetadataEntrySchema =
|
|
917
|
-
images:
|
|
918
|
-
}).catchall(
|
|
919
|
-
var gatewayImageWarningSchema =
|
|
920
|
-
|
|
921
|
-
type:
|
|
922
|
-
feature:
|
|
923
|
-
details:
|
|
1025
|
+
var providerMetadataEntrySchema = z8.object({
|
|
1026
|
+
images: z8.array(z8.unknown()).optional()
|
|
1027
|
+
}).catchall(z8.unknown());
|
|
1028
|
+
var gatewayImageWarningSchema = z8.discriminatedUnion("type", [
|
|
1029
|
+
z8.object({
|
|
1030
|
+
type: z8.literal("unsupported"),
|
|
1031
|
+
feature: z8.string(),
|
|
1032
|
+
details: z8.string().optional()
|
|
924
1033
|
}),
|
|
925
|
-
|
|
926
|
-
type:
|
|
927
|
-
feature:
|
|
928
|
-
details:
|
|
1034
|
+
z8.object({
|
|
1035
|
+
type: z8.literal("compatibility"),
|
|
1036
|
+
feature: z8.string(),
|
|
1037
|
+
details: z8.string().optional()
|
|
929
1038
|
}),
|
|
930
|
-
|
|
931
|
-
type:
|
|
932
|
-
message:
|
|
1039
|
+
z8.object({
|
|
1040
|
+
type: z8.literal("other"),
|
|
1041
|
+
message: z8.string()
|
|
933
1042
|
})
|
|
934
1043
|
]);
|
|
935
|
-
var gatewayImageUsageSchema =
|
|
936
|
-
inputTokens:
|
|
937
|
-
outputTokens:
|
|
938
|
-
totalTokens:
|
|
1044
|
+
var gatewayImageUsageSchema = z8.object({
|
|
1045
|
+
inputTokens: z8.number().nullish(),
|
|
1046
|
+
outputTokens: z8.number().nullish(),
|
|
1047
|
+
totalTokens: z8.number().nullish()
|
|
939
1048
|
});
|
|
940
|
-
var gatewayImageResponseSchema =
|
|
941
|
-
images:
|
|
1049
|
+
var gatewayImageResponseSchema = z8.object({
|
|
1050
|
+
images: z8.array(z8.string()),
|
|
942
1051
|
// Always base64 strings over the wire
|
|
943
|
-
warnings:
|
|
944
|
-
providerMetadata:
|
|
1052
|
+
warnings: z8.array(gatewayImageWarningSchema).optional(),
|
|
1053
|
+
providerMetadata: z8.record(z8.string(), providerMetadataEntrySchema).optional(),
|
|
945
1054
|
usage: gatewayImageUsageSchema.optional()
|
|
946
1055
|
});
|
|
947
1056
|
|
|
@@ -950,12 +1059,12 @@ import { APICallError as APICallError2 } from "@ai-sdk/provider";
|
|
|
950
1059
|
import {
|
|
951
1060
|
combineHeaders as combineHeaders4,
|
|
952
1061
|
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
953
|
-
createJsonErrorResponseHandler as
|
|
1062
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler6,
|
|
954
1063
|
parseJsonEventStream,
|
|
955
1064
|
postJsonToApi as postJsonToApi4,
|
|
956
|
-
resolve as
|
|
1065
|
+
resolve as resolve6
|
|
957
1066
|
} from "@ai-sdk/provider-utils";
|
|
958
|
-
import { z as
|
|
1067
|
+
import { z as z9 } from "zod/v4";
|
|
959
1068
|
var GatewayVideoModel = class {
|
|
960
1069
|
constructor(modelId, config) {
|
|
961
1070
|
this.modelId = modelId;
|
|
@@ -981,7 +1090,7 @@ var GatewayVideoModel = class {
|
|
|
981
1090
|
abortSignal
|
|
982
1091
|
}) {
|
|
983
1092
|
var _a9;
|
|
984
|
-
const resolvedHeaders = await
|
|
1093
|
+
const resolvedHeaders = await resolve6(this.config.headers());
|
|
985
1094
|
try {
|
|
986
1095
|
const { responseHeaders, value: responseBody } = await postJsonToApi4({
|
|
987
1096
|
url: this.getUrl(),
|
|
@@ -989,7 +1098,7 @@ var GatewayVideoModel = class {
|
|
|
989
1098
|
resolvedHeaders,
|
|
990
1099
|
headers != null ? headers : {},
|
|
991
1100
|
this.getModelConfigHeaders(),
|
|
992
|
-
await
|
|
1101
|
+
await resolve6(this.config.o11yHeaders),
|
|
993
1102
|
{ accept: "text/event-stream" }
|
|
994
1103
|
),
|
|
995
1104
|
body: {
|
|
@@ -1067,8 +1176,8 @@ var GatewayVideoModel = class {
|
|
|
1067
1176
|
responseHeaders: Object.fromEntries([...response.headers])
|
|
1068
1177
|
};
|
|
1069
1178
|
},
|
|
1070
|
-
failedResponseHandler:
|
|
1071
|
-
errorSchema:
|
|
1179
|
+
failedResponseHandler: createJsonErrorResponseHandler6({
|
|
1180
|
+
errorSchema: z9.any(),
|
|
1072
1181
|
errorToMessage: (data) => data
|
|
1073
1182
|
}),
|
|
1074
1183
|
...abortSignal && { abortSignal },
|
|
@@ -1107,115 +1216,115 @@ function maybeEncodeVideoFile(file) {
|
|
|
1107
1216
|
}
|
|
1108
1217
|
return file;
|
|
1109
1218
|
}
|
|
1110
|
-
var providerMetadataEntrySchema2 =
|
|
1111
|
-
videos:
|
|
1112
|
-
}).catchall(
|
|
1113
|
-
var gatewayVideoDataSchema =
|
|
1114
|
-
|
|
1115
|
-
type:
|
|
1116
|
-
url:
|
|
1117
|
-
mediaType:
|
|
1219
|
+
var providerMetadataEntrySchema2 = z9.object({
|
|
1220
|
+
videos: z9.array(z9.unknown()).optional()
|
|
1221
|
+
}).catchall(z9.unknown());
|
|
1222
|
+
var gatewayVideoDataSchema = z9.union([
|
|
1223
|
+
z9.object({
|
|
1224
|
+
type: z9.literal("url"),
|
|
1225
|
+
url: z9.string(),
|
|
1226
|
+
mediaType: z9.string()
|
|
1118
1227
|
}),
|
|
1119
|
-
|
|
1120
|
-
type:
|
|
1121
|
-
data:
|
|
1122
|
-
mediaType:
|
|
1228
|
+
z9.object({
|
|
1229
|
+
type: z9.literal("base64"),
|
|
1230
|
+
data: z9.string(),
|
|
1231
|
+
mediaType: z9.string()
|
|
1123
1232
|
})
|
|
1124
1233
|
]);
|
|
1125
|
-
var gatewayVideoWarningSchema =
|
|
1126
|
-
|
|
1127
|
-
type:
|
|
1128
|
-
feature:
|
|
1129
|
-
details:
|
|
1234
|
+
var gatewayVideoWarningSchema = z9.discriminatedUnion("type", [
|
|
1235
|
+
z9.object({
|
|
1236
|
+
type: z9.literal("unsupported"),
|
|
1237
|
+
feature: z9.string(),
|
|
1238
|
+
details: z9.string().optional()
|
|
1130
1239
|
}),
|
|
1131
|
-
|
|
1132
|
-
type:
|
|
1133
|
-
feature:
|
|
1134
|
-
details:
|
|
1240
|
+
z9.object({
|
|
1241
|
+
type: z9.literal("compatibility"),
|
|
1242
|
+
feature: z9.string(),
|
|
1243
|
+
details: z9.string().optional()
|
|
1135
1244
|
}),
|
|
1136
|
-
|
|
1137
|
-
type:
|
|
1138
|
-
message:
|
|
1245
|
+
z9.object({
|
|
1246
|
+
type: z9.literal("other"),
|
|
1247
|
+
message: z9.string()
|
|
1139
1248
|
})
|
|
1140
1249
|
]);
|
|
1141
|
-
var gatewayVideoEventSchema =
|
|
1142
|
-
|
|
1143
|
-
type:
|
|
1144
|
-
videos:
|
|
1145
|
-
warnings:
|
|
1146
|
-
providerMetadata:
|
|
1250
|
+
var gatewayVideoEventSchema = z9.discriminatedUnion("type", [
|
|
1251
|
+
z9.object({
|
|
1252
|
+
type: z9.literal("result"),
|
|
1253
|
+
videos: z9.array(gatewayVideoDataSchema),
|
|
1254
|
+
warnings: z9.array(gatewayVideoWarningSchema).optional(),
|
|
1255
|
+
providerMetadata: z9.record(z9.string(), providerMetadataEntrySchema2).optional()
|
|
1147
1256
|
}),
|
|
1148
|
-
|
|
1149
|
-
type:
|
|
1150
|
-
message:
|
|
1151
|
-
errorType:
|
|
1152
|
-
statusCode:
|
|
1153
|
-
param:
|
|
1257
|
+
z9.object({
|
|
1258
|
+
type: z9.literal("error"),
|
|
1259
|
+
message: z9.string(),
|
|
1260
|
+
errorType: z9.string(),
|
|
1261
|
+
statusCode: z9.number(),
|
|
1262
|
+
param: z9.unknown().nullable()
|
|
1154
1263
|
})
|
|
1155
1264
|
]);
|
|
1156
1265
|
|
|
1157
1266
|
// src/tool/parallel-search.ts
|
|
1158
1267
|
import {
|
|
1159
1268
|
createProviderToolFactoryWithOutputSchema,
|
|
1160
|
-
lazySchema as
|
|
1161
|
-
zodSchema as
|
|
1269
|
+
lazySchema as lazySchema7,
|
|
1270
|
+
zodSchema as zodSchema7
|
|
1162
1271
|
} from "@ai-sdk/provider-utils";
|
|
1163
|
-
import { z as
|
|
1164
|
-
var parallelSearchInputSchema =
|
|
1165
|
-
() =>
|
|
1166
|
-
|
|
1167
|
-
objective:
|
|
1272
|
+
import { z as z10 } from "zod";
|
|
1273
|
+
var parallelSearchInputSchema = lazySchema7(
|
|
1274
|
+
() => zodSchema7(
|
|
1275
|
+
z10.object({
|
|
1276
|
+
objective: z10.string().describe(
|
|
1168
1277
|
"Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
|
|
1169
1278
|
),
|
|
1170
|
-
search_queries:
|
|
1279
|
+
search_queries: z10.array(z10.string()).optional().describe(
|
|
1171
1280
|
"Optional search queries to supplement the objective. Maximum 200 characters per query."
|
|
1172
1281
|
),
|
|
1173
|
-
mode:
|
|
1282
|
+
mode: z10.enum(["one-shot", "agentic"]).optional().describe(
|
|
1174
1283
|
'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
|
|
1175
1284
|
),
|
|
1176
|
-
max_results:
|
|
1285
|
+
max_results: z10.number().optional().describe(
|
|
1177
1286
|
"Maximum number of results to return (1-20). Defaults to 10 if not specified."
|
|
1178
1287
|
),
|
|
1179
|
-
source_policy:
|
|
1180
|
-
include_domains:
|
|
1181
|
-
exclude_domains:
|
|
1182
|
-
after_date:
|
|
1288
|
+
source_policy: z10.object({
|
|
1289
|
+
include_domains: z10.array(z10.string()).optional().describe("List of domains to include in search results."),
|
|
1290
|
+
exclude_domains: z10.array(z10.string()).optional().describe("List of domains to exclude from search results."),
|
|
1291
|
+
after_date: z10.string().optional().describe(
|
|
1183
1292
|
"Only include results published after this date (ISO 8601 format)."
|
|
1184
1293
|
)
|
|
1185
1294
|
}).optional().describe(
|
|
1186
1295
|
"Source policy for controlling which domains to include/exclude and freshness."
|
|
1187
1296
|
),
|
|
1188
|
-
excerpts:
|
|
1189
|
-
max_chars_per_result:
|
|
1190
|
-
max_chars_total:
|
|
1297
|
+
excerpts: z10.object({
|
|
1298
|
+
max_chars_per_result: z10.number().optional().describe("Maximum characters per result."),
|
|
1299
|
+
max_chars_total: z10.number().optional().describe("Maximum total characters across all results.")
|
|
1191
1300
|
}).optional().describe("Excerpt configuration for controlling result length."),
|
|
1192
|
-
fetch_policy:
|
|
1193
|
-
max_age_seconds:
|
|
1301
|
+
fetch_policy: z10.object({
|
|
1302
|
+
max_age_seconds: z10.number().optional().describe(
|
|
1194
1303
|
"Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
|
|
1195
1304
|
)
|
|
1196
1305
|
}).optional().describe("Fetch policy for controlling content freshness.")
|
|
1197
1306
|
})
|
|
1198
1307
|
)
|
|
1199
1308
|
);
|
|
1200
|
-
var parallelSearchOutputSchema =
|
|
1201
|
-
() =>
|
|
1202
|
-
|
|
1309
|
+
var parallelSearchOutputSchema = lazySchema7(
|
|
1310
|
+
() => zodSchema7(
|
|
1311
|
+
z10.union([
|
|
1203
1312
|
// Success response
|
|
1204
|
-
|
|
1205
|
-
searchId:
|
|
1206
|
-
results:
|
|
1207
|
-
|
|
1208
|
-
url:
|
|
1209
|
-
title:
|
|
1210
|
-
excerpt:
|
|
1211
|
-
publishDate:
|
|
1212
|
-
relevanceScore:
|
|
1313
|
+
z10.object({
|
|
1314
|
+
searchId: z10.string(),
|
|
1315
|
+
results: z10.array(
|
|
1316
|
+
z10.object({
|
|
1317
|
+
url: z10.string(),
|
|
1318
|
+
title: z10.string(),
|
|
1319
|
+
excerpt: z10.string(),
|
|
1320
|
+
publishDate: z10.string().nullable().optional(),
|
|
1321
|
+
relevanceScore: z10.number().optional()
|
|
1213
1322
|
})
|
|
1214
1323
|
)
|
|
1215
1324
|
}),
|
|
1216
1325
|
// Error response
|
|
1217
|
-
|
|
1218
|
-
error:
|
|
1326
|
+
z10.object({
|
|
1327
|
+
error: z10.enum([
|
|
1219
1328
|
"api_error",
|
|
1220
1329
|
"rate_limit",
|
|
1221
1330
|
"timeout",
|
|
@@ -1223,8 +1332,8 @@ var parallelSearchOutputSchema = lazySchema6(
|
|
|
1223
1332
|
"configuration_error",
|
|
1224
1333
|
"unknown"
|
|
1225
1334
|
]),
|
|
1226
|
-
statusCode:
|
|
1227
|
-
message:
|
|
1335
|
+
statusCode: z10.number().optional(),
|
|
1336
|
+
message: z10.string()
|
|
1228
1337
|
})
|
|
1229
1338
|
])
|
|
1230
1339
|
)
|
|
@@ -1239,79 +1348,79 @@ var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
|
|
|
1239
1348
|
// src/tool/perplexity-search.ts
|
|
1240
1349
|
import {
|
|
1241
1350
|
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema2,
|
|
1242
|
-
lazySchema as
|
|
1243
|
-
zodSchema as
|
|
1351
|
+
lazySchema as lazySchema8,
|
|
1352
|
+
zodSchema as zodSchema8
|
|
1244
1353
|
} from "@ai-sdk/provider-utils";
|
|
1245
|
-
import { z as
|
|
1246
|
-
var perplexitySearchInputSchema =
|
|
1247
|
-
() =>
|
|
1248
|
-
|
|
1249
|
-
query:
|
|
1354
|
+
import { z as z11 } from "zod";
|
|
1355
|
+
var perplexitySearchInputSchema = lazySchema8(
|
|
1356
|
+
() => zodSchema8(
|
|
1357
|
+
z11.object({
|
|
1358
|
+
query: z11.union([z11.string(), z11.array(z11.string())]).describe(
|
|
1250
1359
|
"Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
|
|
1251
1360
|
),
|
|
1252
|
-
max_results:
|
|
1361
|
+
max_results: z11.number().optional().describe(
|
|
1253
1362
|
"Maximum number of search results to return (1-20, default: 10)"
|
|
1254
1363
|
),
|
|
1255
|
-
max_tokens_per_page:
|
|
1364
|
+
max_tokens_per_page: z11.number().optional().describe(
|
|
1256
1365
|
"Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
|
|
1257
1366
|
),
|
|
1258
|
-
max_tokens:
|
|
1367
|
+
max_tokens: z11.number().optional().describe(
|
|
1259
1368
|
"Maximum total tokens across all search results (default: 25000, max: 1000000)"
|
|
1260
1369
|
),
|
|
1261
|
-
country:
|
|
1370
|
+
country: z11.string().optional().describe(
|
|
1262
1371
|
"Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
|
|
1263
1372
|
),
|
|
1264
|
-
search_domain_filter:
|
|
1373
|
+
search_domain_filter: z11.array(z11.string()).optional().describe(
|
|
1265
1374
|
"List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
|
|
1266
1375
|
),
|
|
1267
|
-
search_language_filter:
|
|
1376
|
+
search_language_filter: z11.array(z11.string()).optional().describe(
|
|
1268
1377
|
"List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
|
|
1269
1378
|
),
|
|
1270
|
-
search_after_date:
|
|
1379
|
+
search_after_date: z11.string().optional().describe(
|
|
1271
1380
|
"Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
1272
1381
|
),
|
|
1273
|
-
search_before_date:
|
|
1382
|
+
search_before_date: z11.string().optional().describe(
|
|
1274
1383
|
"Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
1275
1384
|
),
|
|
1276
|
-
last_updated_after_filter:
|
|
1385
|
+
last_updated_after_filter: z11.string().optional().describe(
|
|
1277
1386
|
"Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
1278
1387
|
),
|
|
1279
|
-
last_updated_before_filter:
|
|
1388
|
+
last_updated_before_filter: z11.string().optional().describe(
|
|
1280
1389
|
"Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
1281
1390
|
),
|
|
1282
|
-
search_recency_filter:
|
|
1391
|
+
search_recency_filter: z11.enum(["day", "week", "month", "year"]).optional().describe(
|
|
1283
1392
|
"Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
|
|
1284
1393
|
)
|
|
1285
1394
|
})
|
|
1286
1395
|
)
|
|
1287
1396
|
);
|
|
1288
|
-
var perplexitySearchOutputSchema =
|
|
1289
|
-
() =>
|
|
1290
|
-
|
|
1397
|
+
var perplexitySearchOutputSchema = lazySchema8(
|
|
1398
|
+
() => zodSchema8(
|
|
1399
|
+
z11.union([
|
|
1291
1400
|
// Success response
|
|
1292
|
-
|
|
1293
|
-
results:
|
|
1294
|
-
|
|
1295
|
-
title:
|
|
1296
|
-
url:
|
|
1297
|
-
snippet:
|
|
1298
|
-
date:
|
|
1299
|
-
lastUpdated:
|
|
1401
|
+
z11.object({
|
|
1402
|
+
results: z11.array(
|
|
1403
|
+
z11.object({
|
|
1404
|
+
title: z11.string(),
|
|
1405
|
+
url: z11.string(),
|
|
1406
|
+
snippet: z11.string(),
|
|
1407
|
+
date: z11.string().optional(),
|
|
1408
|
+
lastUpdated: z11.string().optional()
|
|
1300
1409
|
})
|
|
1301
1410
|
),
|
|
1302
|
-
id:
|
|
1411
|
+
id: z11.string()
|
|
1303
1412
|
}),
|
|
1304
1413
|
// Error response
|
|
1305
|
-
|
|
1306
|
-
error:
|
|
1414
|
+
z11.object({
|
|
1415
|
+
error: z11.enum([
|
|
1307
1416
|
"api_error",
|
|
1308
1417
|
"rate_limit",
|
|
1309
1418
|
"timeout",
|
|
1310
1419
|
"invalid_input",
|
|
1311
1420
|
"unknown"
|
|
1312
1421
|
]),
|
|
1313
|
-
statusCode:
|
|
1314
|
-
message:
|
|
1422
|
+
statusCode: z11.number().optional(),
|
|
1423
|
+
message: z11.string()
|
|
1315
1424
|
})
|
|
1316
1425
|
])
|
|
1317
1426
|
)
|
|
@@ -1356,7 +1465,7 @@ async function getVercelRequestId() {
|
|
|
1356
1465
|
import { withUserAgentSuffix } from "@ai-sdk/provider-utils";
|
|
1357
1466
|
|
|
1358
1467
|
// src/version.ts
|
|
1359
|
-
var VERSION = true ? "4.0.0-beta.
|
|
1468
|
+
var VERSION = true ? "4.0.0-beta.24" : "0.0.0-test";
|
|
1360
1469
|
|
|
1361
1470
|
// src/gateway-provider.ts
|
|
1362
1471
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
@@ -1458,6 +1567,18 @@ function createGatewayProvider(options = {}) {
|
|
|
1458
1567
|
);
|
|
1459
1568
|
});
|
|
1460
1569
|
};
|
|
1570
|
+
const getSpendReport = async (params) => {
|
|
1571
|
+
return new GatewaySpendReport({
|
|
1572
|
+
baseURL,
|
|
1573
|
+
headers: getHeaders,
|
|
1574
|
+
fetch: options.fetch
|
|
1575
|
+
}).getSpendReport(params).catch(async (error) => {
|
|
1576
|
+
throw await asGatewayError(
|
|
1577
|
+
error,
|
|
1578
|
+
await parseAuthMethod(await getHeaders())
|
|
1579
|
+
);
|
|
1580
|
+
});
|
|
1581
|
+
};
|
|
1461
1582
|
const provider = function(modelId) {
|
|
1462
1583
|
if (new.target) {
|
|
1463
1584
|
throw new Error(
|
|
@@ -1469,6 +1590,7 @@ function createGatewayProvider(options = {}) {
|
|
|
1469
1590
|
provider.specificationVersion = "v4";
|
|
1470
1591
|
provider.getAvailableModels = getAvailableModels;
|
|
1471
1592
|
provider.getCredits = getCredits;
|
|
1593
|
+
provider.getSpendReport = getSpendReport;
|
|
1472
1594
|
provider.imageModel = (modelId) => {
|
|
1473
1595
|
return new GatewayImageModel(modelId, {
|
|
1474
1596
|
provider: "gateway",
|