@ai-sdk/gateway 4.0.0-beta.4 → 4.0.0-beta.40
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 +246 -4
- package/dist/index.d.mts +143 -21
- package/dist/index.d.ts +143 -21
- package/dist/index.js +454 -144
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +518 -186
- package/dist/index.mjs.map +1 -1
- package/docs/00-ai-gateway.mdx +292 -44
- package/package.json +4 -6
- package/src/gateway-embedding-model-settings.ts +1 -0
- package/src/gateway-embedding-model.ts +8 -8
- package/src/gateway-fetch-metadata.ts +1 -1
- package/src/gateway-generation-info.ts +147 -0
- package/src/gateway-image-model-settings.ts +6 -0
- package/src/gateway-image-model.ts +10 -10
- package/src/gateway-language-model-settings.ts +21 -9
- package/src/gateway-language-model.ts +19 -19
- package/src/gateway-model-entry.ts +2 -2
- package/src/gateway-provider-options.ts +27 -8
- package/src/gateway-provider.ts +99 -17
- package/src/gateway-reranking-model-settings.ts +1 -0
- package/src/gateway-reranking-model.ts +114 -0
- package/src/gateway-spend-report.ts +191 -0
- package/src/gateway-video-model.ts +15 -15
- package/src/index.ts +13 -3
package/dist/index.mjs
CHANGED
|
@@ -536,7 +536,7 @@ var gatewayAvailableModelsResponseSchema = lazySchema4(
|
|
|
536
536
|
})
|
|
537
537
|
).nullish(),
|
|
538
538
|
specification: z4.object({
|
|
539
|
-
specificationVersion: z4.literal("
|
|
539
|
+
specificationVersion: z4.literal("v4"),
|
|
540
540
|
provider: z4.string(),
|
|
541
541
|
modelId: z4.string()
|
|
542
542
|
}),
|
|
@@ -558,21 +558,224 @@ 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
|
+
|
|
670
|
+
// src/gateway-generation-info.ts
|
|
671
|
+
import {
|
|
672
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
673
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
674
|
+
getFromApi as getFromApi3,
|
|
675
|
+
lazySchema as lazySchema6,
|
|
676
|
+
resolve as resolve3,
|
|
677
|
+
zodSchema as zodSchema6
|
|
678
|
+
} from "@ai-sdk/provider-utils";
|
|
679
|
+
import { z as z6 } from "zod/v4";
|
|
680
|
+
var GatewayGenerationInfoFetcher = class {
|
|
681
|
+
constructor(config) {
|
|
682
|
+
this.config = config;
|
|
683
|
+
}
|
|
684
|
+
async getGenerationInfo(params) {
|
|
685
|
+
try {
|
|
686
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
687
|
+
const { value } = await getFromApi3({
|
|
688
|
+
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
689
|
+
headers: await resolve3(this.config.headers()),
|
|
690
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
691
|
+
gatewayGenerationInfoResponseSchema
|
|
692
|
+
),
|
|
693
|
+
failedResponseHandler: createJsonErrorResponseHandler3({
|
|
694
|
+
errorSchema: z6.any(),
|
|
695
|
+
errorToMessage: (data) => data
|
|
696
|
+
}),
|
|
697
|
+
fetch: this.config.fetch
|
|
698
|
+
});
|
|
699
|
+
return value;
|
|
700
|
+
} catch (error) {
|
|
701
|
+
throw await asGatewayError(error);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
var gatewayGenerationInfoResponseSchema = lazySchema6(
|
|
706
|
+
() => zodSchema6(
|
|
707
|
+
z6.object({
|
|
708
|
+
data: z6.object({
|
|
709
|
+
id: z6.string(),
|
|
710
|
+
total_cost: z6.number(),
|
|
711
|
+
upstream_inference_cost: z6.number(),
|
|
712
|
+
usage: z6.number(),
|
|
713
|
+
created_at: z6.string(),
|
|
714
|
+
model: z6.string(),
|
|
715
|
+
is_byok: z6.boolean(),
|
|
716
|
+
provider_name: z6.string(),
|
|
717
|
+
streamed: z6.boolean(),
|
|
718
|
+
finish_reason: z6.string(),
|
|
719
|
+
latency: z6.number(),
|
|
720
|
+
generation_time: z6.number(),
|
|
721
|
+
native_tokens_prompt: z6.number(),
|
|
722
|
+
native_tokens_completion: z6.number(),
|
|
723
|
+
native_tokens_reasoning: z6.number(),
|
|
724
|
+
native_tokens_cached: z6.number(),
|
|
725
|
+
native_tokens_cache_creation: z6.number(),
|
|
726
|
+
billable_web_search_calls: z6.number()
|
|
727
|
+
}).transform(
|
|
728
|
+
({
|
|
729
|
+
total_cost,
|
|
730
|
+
upstream_inference_cost,
|
|
731
|
+
created_at,
|
|
732
|
+
is_byok,
|
|
733
|
+
provider_name,
|
|
734
|
+
finish_reason,
|
|
735
|
+
generation_time,
|
|
736
|
+
native_tokens_prompt,
|
|
737
|
+
native_tokens_completion,
|
|
738
|
+
native_tokens_reasoning,
|
|
739
|
+
native_tokens_cached,
|
|
740
|
+
native_tokens_cache_creation,
|
|
741
|
+
billable_web_search_calls,
|
|
742
|
+
...rest
|
|
743
|
+
}) => ({
|
|
744
|
+
...rest,
|
|
745
|
+
totalCost: total_cost,
|
|
746
|
+
upstreamInferenceCost: upstream_inference_cost,
|
|
747
|
+
createdAt: created_at,
|
|
748
|
+
isByok: is_byok,
|
|
749
|
+
providerName: provider_name,
|
|
750
|
+
finishReason: finish_reason,
|
|
751
|
+
generationTime: generation_time,
|
|
752
|
+
promptTokens: native_tokens_prompt,
|
|
753
|
+
completionTokens: native_tokens_completion,
|
|
754
|
+
reasoningTokens: native_tokens_reasoning,
|
|
755
|
+
cachedTokens: native_tokens_cached,
|
|
756
|
+
cacheCreationTokens: native_tokens_cache_creation,
|
|
757
|
+
billableWebSearchCalls: billable_web_search_calls
|
|
758
|
+
})
|
|
759
|
+
)
|
|
760
|
+
}).transform(({ data }) => data)
|
|
761
|
+
)
|
|
762
|
+
);
|
|
763
|
+
|
|
561
764
|
// src/gateway-language-model.ts
|
|
562
765
|
import {
|
|
563
766
|
combineHeaders,
|
|
564
767
|
createEventSourceResponseHandler,
|
|
565
|
-
createJsonErrorResponseHandler as
|
|
566
|
-
createJsonResponseHandler as
|
|
768
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
|
|
769
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
567
770
|
postJsonToApi,
|
|
568
|
-
resolve as
|
|
771
|
+
resolve as resolve4
|
|
569
772
|
} from "@ai-sdk/provider-utils";
|
|
570
|
-
import { z as
|
|
773
|
+
import { z as z7 } from "zod/v4";
|
|
571
774
|
var GatewayLanguageModel = class {
|
|
572
775
|
constructor(modelId, config) {
|
|
573
776
|
this.modelId = modelId;
|
|
574
777
|
this.config = config;
|
|
575
|
-
this.specificationVersion = "
|
|
778
|
+
this.specificationVersion = "v4";
|
|
576
779
|
this.supportedUrls = { "*/*": [/.*/] };
|
|
577
780
|
}
|
|
578
781
|
get provider() {
|
|
@@ -588,7 +791,7 @@ var GatewayLanguageModel = class {
|
|
|
588
791
|
async doGenerate(options) {
|
|
589
792
|
const { args, warnings } = await this.getArgs(options);
|
|
590
793
|
const { abortSignal } = options;
|
|
591
|
-
const resolvedHeaders = await
|
|
794
|
+
const resolvedHeaders = await resolve4(this.config.headers());
|
|
592
795
|
try {
|
|
593
796
|
const {
|
|
594
797
|
responseHeaders,
|
|
@@ -600,12 +803,12 @@ var GatewayLanguageModel = class {
|
|
|
600
803
|
resolvedHeaders,
|
|
601
804
|
options.headers,
|
|
602
805
|
this.getModelConfigHeaders(this.modelId, false),
|
|
603
|
-
await
|
|
806
|
+
await resolve4(this.config.o11yHeaders)
|
|
604
807
|
),
|
|
605
808
|
body: args,
|
|
606
|
-
successfulResponseHandler:
|
|
607
|
-
failedResponseHandler:
|
|
608
|
-
errorSchema:
|
|
809
|
+
successfulResponseHandler: createJsonResponseHandler4(z7.any()),
|
|
810
|
+
failedResponseHandler: createJsonErrorResponseHandler4({
|
|
811
|
+
errorSchema: z7.any(),
|
|
609
812
|
errorToMessage: (data) => data
|
|
610
813
|
}),
|
|
611
814
|
...abortSignal && { abortSignal },
|
|
@@ -624,7 +827,7 @@ var GatewayLanguageModel = class {
|
|
|
624
827
|
async doStream(options) {
|
|
625
828
|
const { args, warnings } = await this.getArgs(options);
|
|
626
829
|
const { abortSignal } = options;
|
|
627
|
-
const resolvedHeaders = await
|
|
830
|
+
const resolvedHeaders = await resolve4(this.config.headers());
|
|
628
831
|
try {
|
|
629
832
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
630
833
|
url: this.getUrl(),
|
|
@@ -632,12 +835,12 @@ var GatewayLanguageModel = class {
|
|
|
632
835
|
resolvedHeaders,
|
|
633
836
|
options.headers,
|
|
634
837
|
this.getModelConfigHeaders(this.modelId, true),
|
|
635
|
-
await
|
|
838
|
+
await resolve4(this.config.o11yHeaders)
|
|
636
839
|
),
|
|
637
840
|
body: args,
|
|
638
|
-
successfulResponseHandler: createEventSourceResponseHandler(
|
|
639
|
-
failedResponseHandler:
|
|
640
|
-
errorSchema:
|
|
841
|
+
successfulResponseHandler: createEventSourceResponseHandler(z7.any()),
|
|
842
|
+
failedResponseHandler: createJsonErrorResponseHandler4({
|
|
843
|
+
errorSchema: z7.any(),
|
|
641
844
|
errorToMessage: (data) => data
|
|
642
845
|
}),
|
|
643
846
|
...abortSignal && { abortSignal },
|
|
@@ -707,7 +910,7 @@ var GatewayLanguageModel = class {
|
|
|
707
910
|
}
|
|
708
911
|
getModelConfigHeaders(modelId, streaming) {
|
|
709
912
|
return {
|
|
710
|
-
"ai-language-model-specification-version": "
|
|
913
|
+
"ai-language-model-specification-version": "4",
|
|
711
914
|
"ai-language-model-id": modelId,
|
|
712
915
|
"ai-language-model-streaming": String(streaming)
|
|
713
916
|
};
|
|
@@ -717,19 +920,19 @@ var GatewayLanguageModel = class {
|
|
|
717
920
|
// src/gateway-embedding-model.ts
|
|
718
921
|
import {
|
|
719
922
|
combineHeaders as combineHeaders2,
|
|
720
|
-
createJsonErrorResponseHandler as
|
|
721
|
-
createJsonResponseHandler as
|
|
722
|
-
lazySchema as
|
|
923
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler5,
|
|
924
|
+
createJsonResponseHandler as createJsonResponseHandler5,
|
|
925
|
+
lazySchema as lazySchema7,
|
|
723
926
|
postJsonToApi as postJsonToApi2,
|
|
724
|
-
resolve as
|
|
725
|
-
zodSchema as
|
|
927
|
+
resolve as resolve5,
|
|
928
|
+
zodSchema as zodSchema7
|
|
726
929
|
} from "@ai-sdk/provider-utils";
|
|
727
|
-
import { z as
|
|
930
|
+
import { z as z8 } from "zod/v4";
|
|
728
931
|
var GatewayEmbeddingModel = class {
|
|
729
932
|
constructor(modelId, config) {
|
|
730
933
|
this.modelId = modelId;
|
|
731
934
|
this.config = config;
|
|
732
|
-
this.specificationVersion = "
|
|
935
|
+
this.specificationVersion = "v4";
|
|
733
936
|
this.maxEmbeddingsPerCall = 2048;
|
|
734
937
|
this.supportsParallelCalls = true;
|
|
735
938
|
}
|
|
@@ -743,7 +946,7 @@ var GatewayEmbeddingModel = class {
|
|
|
743
946
|
providerOptions
|
|
744
947
|
}) {
|
|
745
948
|
var _a9;
|
|
746
|
-
const resolvedHeaders = await
|
|
949
|
+
const resolvedHeaders = await resolve5(this.config.headers());
|
|
747
950
|
try {
|
|
748
951
|
const {
|
|
749
952
|
responseHeaders,
|
|
@@ -755,17 +958,17 @@ var GatewayEmbeddingModel = class {
|
|
|
755
958
|
resolvedHeaders,
|
|
756
959
|
headers != null ? headers : {},
|
|
757
960
|
this.getModelConfigHeaders(),
|
|
758
|
-
await
|
|
961
|
+
await resolve5(this.config.o11yHeaders)
|
|
759
962
|
),
|
|
760
963
|
body: {
|
|
761
964
|
values,
|
|
762
965
|
...providerOptions ? { providerOptions } : {}
|
|
763
966
|
},
|
|
764
|
-
successfulResponseHandler:
|
|
967
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
765
968
|
gatewayEmbeddingResponseSchema
|
|
766
969
|
),
|
|
767
|
-
failedResponseHandler:
|
|
768
|
-
errorSchema:
|
|
970
|
+
failedResponseHandler: createJsonErrorResponseHandler5({
|
|
971
|
+
errorSchema: z8.any(),
|
|
769
972
|
errorToMessage: (data) => data
|
|
770
973
|
}),
|
|
771
974
|
...abortSignal && { abortSignal },
|
|
@@ -787,17 +990,17 @@ var GatewayEmbeddingModel = class {
|
|
|
787
990
|
}
|
|
788
991
|
getModelConfigHeaders() {
|
|
789
992
|
return {
|
|
790
|
-
"ai-embedding-model-specification-version": "
|
|
993
|
+
"ai-embedding-model-specification-version": "4",
|
|
791
994
|
"ai-model-id": this.modelId
|
|
792
995
|
};
|
|
793
996
|
}
|
|
794
997
|
};
|
|
795
|
-
var gatewayEmbeddingResponseSchema =
|
|
796
|
-
() =>
|
|
797
|
-
|
|
798
|
-
embeddings:
|
|
799
|
-
usage:
|
|
800
|
-
providerMetadata:
|
|
998
|
+
var gatewayEmbeddingResponseSchema = lazySchema7(
|
|
999
|
+
() => zodSchema7(
|
|
1000
|
+
z8.object({
|
|
1001
|
+
embeddings: z8.array(z8.array(z8.number())),
|
|
1002
|
+
usage: z8.object({ tokens: z8.number() }).nullish(),
|
|
1003
|
+
providerMetadata: z8.record(z8.string(), z8.record(z8.string(), z8.unknown())).optional()
|
|
801
1004
|
})
|
|
802
1005
|
)
|
|
803
1006
|
);
|
|
@@ -806,17 +1009,17 @@ var gatewayEmbeddingResponseSchema = lazySchema5(
|
|
|
806
1009
|
import {
|
|
807
1010
|
combineHeaders as combineHeaders3,
|
|
808
1011
|
convertUint8ArrayToBase64,
|
|
809
|
-
createJsonResponseHandler as
|
|
810
|
-
createJsonErrorResponseHandler as
|
|
1012
|
+
createJsonResponseHandler as createJsonResponseHandler6,
|
|
1013
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler6,
|
|
811
1014
|
postJsonToApi as postJsonToApi3,
|
|
812
|
-
resolve as
|
|
1015
|
+
resolve as resolve6
|
|
813
1016
|
} from "@ai-sdk/provider-utils";
|
|
814
|
-
import { z as
|
|
1017
|
+
import { z as z9 } from "zod/v4";
|
|
815
1018
|
var GatewayImageModel = class {
|
|
816
1019
|
constructor(modelId, config) {
|
|
817
1020
|
this.modelId = modelId;
|
|
818
1021
|
this.config = config;
|
|
819
|
-
this.specificationVersion = "
|
|
1022
|
+
this.specificationVersion = "v4";
|
|
820
1023
|
// Set a very large number to prevent client-side splitting of requests
|
|
821
1024
|
this.maxImagesPerCall = Number.MAX_SAFE_INTEGER;
|
|
822
1025
|
}
|
|
@@ -836,7 +1039,7 @@ var GatewayImageModel = class {
|
|
|
836
1039
|
abortSignal
|
|
837
1040
|
}) {
|
|
838
1041
|
var _a9, _b9, _c, _d;
|
|
839
|
-
const resolvedHeaders = await
|
|
1042
|
+
const resolvedHeaders = await resolve6(this.config.headers());
|
|
840
1043
|
try {
|
|
841
1044
|
const {
|
|
842
1045
|
responseHeaders,
|
|
@@ -848,7 +1051,7 @@ var GatewayImageModel = class {
|
|
|
848
1051
|
resolvedHeaders,
|
|
849
1052
|
headers != null ? headers : {},
|
|
850
1053
|
this.getModelConfigHeaders(),
|
|
851
|
-
await
|
|
1054
|
+
await resolve6(this.config.o11yHeaders)
|
|
852
1055
|
),
|
|
853
1056
|
body: {
|
|
854
1057
|
prompt,
|
|
@@ -862,11 +1065,11 @@ var GatewayImageModel = class {
|
|
|
862
1065
|
},
|
|
863
1066
|
...mask && { mask: maybeEncodeImageFile(mask) }
|
|
864
1067
|
},
|
|
865
|
-
successfulResponseHandler:
|
|
1068
|
+
successfulResponseHandler: createJsonResponseHandler6(
|
|
866
1069
|
gatewayImageResponseSchema
|
|
867
1070
|
),
|
|
868
|
-
failedResponseHandler:
|
|
869
|
-
errorSchema:
|
|
1071
|
+
failedResponseHandler: createJsonErrorResponseHandler6({
|
|
1072
|
+
errorSchema: z9.any(),
|
|
870
1073
|
errorToMessage: (data) => data
|
|
871
1074
|
}),
|
|
872
1075
|
...abortSignal && { abortSignal },
|
|
@@ -899,7 +1102,7 @@ var GatewayImageModel = class {
|
|
|
899
1102
|
}
|
|
900
1103
|
getModelConfigHeaders() {
|
|
901
1104
|
return {
|
|
902
|
-
"ai-image-model-specification-version": "
|
|
1105
|
+
"ai-image-model-specification-version": "4",
|
|
903
1106
|
"ai-model-id": this.modelId
|
|
904
1107
|
};
|
|
905
1108
|
}
|
|
@@ -913,35 +1116,35 @@ function maybeEncodeImageFile(file) {
|
|
|
913
1116
|
}
|
|
914
1117
|
return file;
|
|
915
1118
|
}
|
|
916
|
-
var providerMetadataEntrySchema =
|
|
917
|
-
images:
|
|
918
|
-
}).catchall(
|
|
919
|
-
var gatewayImageWarningSchema =
|
|
920
|
-
|
|
921
|
-
type:
|
|
922
|
-
feature:
|
|
923
|
-
details:
|
|
1119
|
+
var providerMetadataEntrySchema = z9.object({
|
|
1120
|
+
images: z9.array(z9.unknown()).optional()
|
|
1121
|
+
}).catchall(z9.unknown());
|
|
1122
|
+
var gatewayImageWarningSchema = z9.discriminatedUnion("type", [
|
|
1123
|
+
z9.object({
|
|
1124
|
+
type: z9.literal("unsupported"),
|
|
1125
|
+
feature: z9.string(),
|
|
1126
|
+
details: z9.string().optional()
|
|
924
1127
|
}),
|
|
925
|
-
|
|
926
|
-
type:
|
|
927
|
-
feature:
|
|
928
|
-
details:
|
|
1128
|
+
z9.object({
|
|
1129
|
+
type: z9.literal("compatibility"),
|
|
1130
|
+
feature: z9.string(),
|
|
1131
|
+
details: z9.string().optional()
|
|
929
1132
|
}),
|
|
930
|
-
|
|
931
|
-
type:
|
|
932
|
-
message:
|
|
1133
|
+
z9.object({
|
|
1134
|
+
type: z9.literal("other"),
|
|
1135
|
+
message: z9.string()
|
|
933
1136
|
})
|
|
934
1137
|
]);
|
|
935
|
-
var gatewayImageUsageSchema =
|
|
936
|
-
inputTokens:
|
|
937
|
-
outputTokens:
|
|
938
|
-
totalTokens:
|
|
1138
|
+
var gatewayImageUsageSchema = z9.object({
|
|
1139
|
+
inputTokens: z9.number().nullish(),
|
|
1140
|
+
outputTokens: z9.number().nullish(),
|
|
1141
|
+
totalTokens: z9.number().nullish()
|
|
939
1142
|
});
|
|
940
|
-
var gatewayImageResponseSchema =
|
|
941
|
-
images:
|
|
1143
|
+
var gatewayImageResponseSchema = z9.object({
|
|
1144
|
+
images: z9.array(z9.string()),
|
|
942
1145
|
// Always base64 strings over the wire
|
|
943
|
-
warnings:
|
|
944
|
-
providerMetadata:
|
|
1146
|
+
warnings: z9.array(gatewayImageWarningSchema).optional(),
|
|
1147
|
+
providerMetadata: z9.record(z9.string(), providerMetadataEntrySchema).optional(),
|
|
945
1148
|
usage: gatewayImageUsageSchema.optional()
|
|
946
1149
|
});
|
|
947
1150
|
|
|
@@ -950,17 +1153,17 @@ import { APICallError as APICallError2 } from "@ai-sdk/provider";
|
|
|
950
1153
|
import {
|
|
951
1154
|
combineHeaders as combineHeaders4,
|
|
952
1155
|
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
953
|
-
createJsonErrorResponseHandler as
|
|
1156
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler7,
|
|
954
1157
|
parseJsonEventStream,
|
|
955
1158
|
postJsonToApi as postJsonToApi4,
|
|
956
|
-
resolve as
|
|
1159
|
+
resolve as resolve7
|
|
957
1160
|
} from "@ai-sdk/provider-utils";
|
|
958
|
-
import { z as
|
|
1161
|
+
import { z as z10 } from "zod/v4";
|
|
959
1162
|
var GatewayVideoModel = class {
|
|
960
1163
|
constructor(modelId, config) {
|
|
961
1164
|
this.modelId = modelId;
|
|
962
1165
|
this.config = config;
|
|
963
|
-
this.specificationVersion = "
|
|
1166
|
+
this.specificationVersion = "v4";
|
|
964
1167
|
// Set a very large number to prevent client-side splitting of requests
|
|
965
1168
|
this.maxVideosPerCall = Number.MAX_SAFE_INTEGER;
|
|
966
1169
|
}
|
|
@@ -981,7 +1184,7 @@ var GatewayVideoModel = class {
|
|
|
981
1184
|
abortSignal
|
|
982
1185
|
}) {
|
|
983
1186
|
var _a9;
|
|
984
|
-
const resolvedHeaders = await
|
|
1187
|
+
const resolvedHeaders = await resolve7(this.config.headers());
|
|
985
1188
|
try {
|
|
986
1189
|
const { responseHeaders, value: responseBody } = await postJsonToApi4({
|
|
987
1190
|
url: this.getUrl(),
|
|
@@ -989,7 +1192,7 @@ var GatewayVideoModel = class {
|
|
|
989
1192
|
resolvedHeaders,
|
|
990
1193
|
headers != null ? headers : {},
|
|
991
1194
|
this.getModelConfigHeaders(),
|
|
992
|
-
await
|
|
1195
|
+
await resolve7(this.config.o11yHeaders),
|
|
993
1196
|
{ accept: "text/event-stream" }
|
|
994
1197
|
),
|
|
995
1198
|
body: {
|
|
@@ -1067,8 +1270,8 @@ var GatewayVideoModel = class {
|
|
|
1067
1270
|
responseHeaders: Object.fromEntries([...response.headers])
|
|
1068
1271
|
};
|
|
1069
1272
|
},
|
|
1070
|
-
failedResponseHandler:
|
|
1071
|
-
errorSchema:
|
|
1273
|
+
failedResponseHandler: createJsonErrorResponseHandler7({
|
|
1274
|
+
errorSchema: z10.any(),
|
|
1072
1275
|
errorToMessage: (data) => data
|
|
1073
1276
|
}),
|
|
1074
1277
|
...abortSignal && { abortSignal },
|
|
@@ -1093,7 +1296,7 @@ var GatewayVideoModel = class {
|
|
|
1093
1296
|
}
|
|
1094
1297
|
getModelConfigHeaders() {
|
|
1095
1298
|
return {
|
|
1096
|
-
"ai-video-model-specification-version": "
|
|
1299
|
+
"ai-video-model-specification-version": "4",
|
|
1097
1300
|
"ai-model-id": this.modelId
|
|
1098
1301
|
};
|
|
1099
1302
|
}
|
|
@@ -1107,115 +1310,207 @@ function maybeEncodeVideoFile(file) {
|
|
|
1107
1310
|
}
|
|
1108
1311
|
return file;
|
|
1109
1312
|
}
|
|
1110
|
-
var providerMetadataEntrySchema2 =
|
|
1111
|
-
videos:
|
|
1112
|
-
}).catchall(
|
|
1113
|
-
var gatewayVideoDataSchema =
|
|
1114
|
-
|
|
1115
|
-
type:
|
|
1116
|
-
url:
|
|
1117
|
-
mediaType:
|
|
1313
|
+
var providerMetadataEntrySchema2 = z10.object({
|
|
1314
|
+
videos: z10.array(z10.unknown()).optional()
|
|
1315
|
+
}).catchall(z10.unknown());
|
|
1316
|
+
var gatewayVideoDataSchema = z10.union([
|
|
1317
|
+
z10.object({
|
|
1318
|
+
type: z10.literal("url"),
|
|
1319
|
+
url: z10.string(),
|
|
1320
|
+
mediaType: z10.string()
|
|
1118
1321
|
}),
|
|
1119
|
-
|
|
1120
|
-
type:
|
|
1121
|
-
data:
|
|
1122
|
-
mediaType:
|
|
1322
|
+
z10.object({
|
|
1323
|
+
type: z10.literal("base64"),
|
|
1324
|
+
data: z10.string(),
|
|
1325
|
+
mediaType: z10.string()
|
|
1123
1326
|
})
|
|
1124
1327
|
]);
|
|
1125
|
-
var gatewayVideoWarningSchema =
|
|
1126
|
-
|
|
1127
|
-
type:
|
|
1128
|
-
feature:
|
|
1129
|
-
details:
|
|
1328
|
+
var gatewayVideoWarningSchema = z10.discriminatedUnion("type", [
|
|
1329
|
+
z10.object({
|
|
1330
|
+
type: z10.literal("unsupported"),
|
|
1331
|
+
feature: z10.string(),
|
|
1332
|
+
details: z10.string().optional()
|
|
1130
1333
|
}),
|
|
1131
|
-
|
|
1132
|
-
type:
|
|
1133
|
-
feature:
|
|
1134
|
-
details:
|
|
1334
|
+
z10.object({
|
|
1335
|
+
type: z10.literal("compatibility"),
|
|
1336
|
+
feature: z10.string(),
|
|
1337
|
+
details: z10.string().optional()
|
|
1135
1338
|
}),
|
|
1136
|
-
|
|
1137
|
-
type:
|
|
1138
|
-
message:
|
|
1339
|
+
z10.object({
|
|
1340
|
+
type: z10.literal("other"),
|
|
1341
|
+
message: z10.string()
|
|
1139
1342
|
})
|
|
1140
1343
|
]);
|
|
1141
|
-
var gatewayVideoEventSchema =
|
|
1142
|
-
|
|
1143
|
-
type:
|
|
1144
|
-
videos:
|
|
1145
|
-
warnings:
|
|
1146
|
-
providerMetadata:
|
|
1344
|
+
var gatewayVideoEventSchema = z10.discriminatedUnion("type", [
|
|
1345
|
+
z10.object({
|
|
1346
|
+
type: z10.literal("result"),
|
|
1347
|
+
videos: z10.array(gatewayVideoDataSchema),
|
|
1348
|
+
warnings: z10.array(gatewayVideoWarningSchema).optional(),
|
|
1349
|
+
providerMetadata: z10.record(z10.string(), providerMetadataEntrySchema2).optional()
|
|
1147
1350
|
}),
|
|
1148
|
-
|
|
1149
|
-
type:
|
|
1150
|
-
message:
|
|
1151
|
-
errorType:
|
|
1152
|
-
statusCode:
|
|
1153
|
-
param:
|
|
1351
|
+
z10.object({
|
|
1352
|
+
type: z10.literal("error"),
|
|
1353
|
+
message: z10.string(),
|
|
1354
|
+
errorType: z10.string(),
|
|
1355
|
+
statusCode: z10.number(),
|
|
1356
|
+
param: z10.unknown().nullable()
|
|
1154
1357
|
})
|
|
1155
1358
|
]);
|
|
1156
1359
|
|
|
1360
|
+
// src/gateway-reranking-model.ts
|
|
1361
|
+
import {
|
|
1362
|
+
combineHeaders as combineHeaders5,
|
|
1363
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler8,
|
|
1364
|
+
createJsonResponseHandler as createJsonResponseHandler7,
|
|
1365
|
+
lazySchema as lazySchema8,
|
|
1366
|
+
postJsonToApi as postJsonToApi5,
|
|
1367
|
+
resolve as resolve8,
|
|
1368
|
+
zodSchema as zodSchema8
|
|
1369
|
+
} from "@ai-sdk/provider-utils";
|
|
1370
|
+
import { z as z11 } from "zod/v4";
|
|
1371
|
+
var GatewayRerankingModel = class {
|
|
1372
|
+
constructor(modelId, config) {
|
|
1373
|
+
this.modelId = modelId;
|
|
1374
|
+
this.config = config;
|
|
1375
|
+
this.specificationVersion = "v4";
|
|
1376
|
+
}
|
|
1377
|
+
get provider() {
|
|
1378
|
+
return this.config.provider;
|
|
1379
|
+
}
|
|
1380
|
+
async doRerank({
|
|
1381
|
+
documents,
|
|
1382
|
+
query,
|
|
1383
|
+
topN,
|
|
1384
|
+
headers,
|
|
1385
|
+
abortSignal,
|
|
1386
|
+
providerOptions
|
|
1387
|
+
}) {
|
|
1388
|
+
const resolvedHeaders = await resolve8(this.config.headers());
|
|
1389
|
+
try {
|
|
1390
|
+
const {
|
|
1391
|
+
responseHeaders,
|
|
1392
|
+
value: responseBody,
|
|
1393
|
+
rawValue
|
|
1394
|
+
} = await postJsonToApi5({
|
|
1395
|
+
url: this.getUrl(),
|
|
1396
|
+
headers: combineHeaders5(
|
|
1397
|
+
resolvedHeaders,
|
|
1398
|
+
headers != null ? headers : {},
|
|
1399
|
+
this.getModelConfigHeaders(),
|
|
1400
|
+
await resolve8(this.config.o11yHeaders)
|
|
1401
|
+
),
|
|
1402
|
+
body: {
|
|
1403
|
+
documents,
|
|
1404
|
+
query,
|
|
1405
|
+
...topN != null ? { topN } : {},
|
|
1406
|
+
...providerOptions ? { providerOptions } : {}
|
|
1407
|
+
},
|
|
1408
|
+
successfulResponseHandler: createJsonResponseHandler7(
|
|
1409
|
+
gatewayRerankingResponseSchema
|
|
1410
|
+
),
|
|
1411
|
+
failedResponseHandler: createJsonErrorResponseHandler8({
|
|
1412
|
+
errorSchema: z11.any(),
|
|
1413
|
+
errorToMessage: (data) => data
|
|
1414
|
+
}),
|
|
1415
|
+
...abortSignal && { abortSignal },
|
|
1416
|
+
fetch: this.config.fetch
|
|
1417
|
+
});
|
|
1418
|
+
return {
|
|
1419
|
+
ranking: responseBody.ranking,
|
|
1420
|
+
providerMetadata: responseBody.providerMetadata,
|
|
1421
|
+
response: { headers: responseHeaders, body: rawValue },
|
|
1422
|
+
warnings: []
|
|
1423
|
+
};
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
getUrl() {
|
|
1429
|
+
return `${this.config.baseURL}/reranking-model`;
|
|
1430
|
+
}
|
|
1431
|
+
getModelConfigHeaders() {
|
|
1432
|
+
return {
|
|
1433
|
+
"ai-reranking-model-specification-version": "4",
|
|
1434
|
+
"ai-model-id": this.modelId
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
var gatewayRerankingResponseSchema = lazySchema8(
|
|
1439
|
+
() => zodSchema8(
|
|
1440
|
+
z11.object({
|
|
1441
|
+
ranking: z11.array(
|
|
1442
|
+
z11.object({
|
|
1443
|
+
index: z11.number(),
|
|
1444
|
+
relevanceScore: z11.number()
|
|
1445
|
+
})
|
|
1446
|
+
),
|
|
1447
|
+
providerMetadata: z11.record(z11.string(), z11.record(z11.string(), z11.unknown())).optional()
|
|
1448
|
+
})
|
|
1449
|
+
)
|
|
1450
|
+
);
|
|
1451
|
+
|
|
1157
1452
|
// src/tool/parallel-search.ts
|
|
1158
1453
|
import {
|
|
1159
1454
|
createProviderToolFactoryWithOutputSchema,
|
|
1160
|
-
lazySchema as
|
|
1161
|
-
zodSchema as
|
|
1455
|
+
lazySchema as lazySchema9,
|
|
1456
|
+
zodSchema as zodSchema9
|
|
1162
1457
|
} from "@ai-sdk/provider-utils";
|
|
1163
|
-
import { z as
|
|
1164
|
-
var parallelSearchInputSchema =
|
|
1165
|
-
() =>
|
|
1166
|
-
|
|
1167
|
-
objective:
|
|
1458
|
+
import { z as z12 } from "zod";
|
|
1459
|
+
var parallelSearchInputSchema = lazySchema9(
|
|
1460
|
+
() => zodSchema9(
|
|
1461
|
+
z12.object({
|
|
1462
|
+
objective: z12.string().describe(
|
|
1168
1463
|
"Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
|
|
1169
1464
|
),
|
|
1170
|
-
search_queries:
|
|
1465
|
+
search_queries: z12.array(z12.string()).optional().describe(
|
|
1171
1466
|
"Optional search queries to supplement the objective. Maximum 200 characters per query."
|
|
1172
1467
|
),
|
|
1173
|
-
mode:
|
|
1468
|
+
mode: z12.enum(["one-shot", "agentic"]).optional().describe(
|
|
1174
1469
|
'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
|
|
1175
1470
|
),
|
|
1176
|
-
max_results:
|
|
1471
|
+
max_results: z12.number().optional().describe(
|
|
1177
1472
|
"Maximum number of results to return (1-20). Defaults to 10 if not specified."
|
|
1178
1473
|
),
|
|
1179
|
-
source_policy:
|
|
1180
|
-
include_domains:
|
|
1181
|
-
exclude_domains:
|
|
1182
|
-
after_date:
|
|
1474
|
+
source_policy: z12.object({
|
|
1475
|
+
include_domains: z12.array(z12.string()).optional().describe("List of domains to include in search results."),
|
|
1476
|
+
exclude_domains: z12.array(z12.string()).optional().describe("List of domains to exclude from search results."),
|
|
1477
|
+
after_date: z12.string().optional().describe(
|
|
1183
1478
|
"Only include results published after this date (ISO 8601 format)."
|
|
1184
1479
|
)
|
|
1185
1480
|
}).optional().describe(
|
|
1186
1481
|
"Source policy for controlling which domains to include/exclude and freshness."
|
|
1187
1482
|
),
|
|
1188
|
-
excerpts:
|
|
1189
|
-
max_chars_per_result:
|
|
1190
|
-
max_chars_total:
|
|
1483
|
+
excerpts: z12.object({
|
|
1484
|
+
max_chars_per_result: z12.number().optional().describe("Maximum characters per result."),
|
|
1485
|
+
max_chars_total: z12.number().optional().describe("Maximum total characters across all results.")
|
|
1191
1486
|
}).optional().describe("Excerpt configuration for controlling result length."),
|
|
1192
|
-
fetch_policy:
|
|
1193
|
-
max_age_seconds:
|
|
1487
|
+
fetch_policy: z12.object({
|
|
1488
|
+
max_age_seconds: z12.number().optional().describe(
|
|
1194
1489
|
"Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
|
|
1195
1490
|
)
|
|
1196
1491
|
}).optional().describe("Fetch policy for controlling content freshness.")
|
|
1197
1492
|
})
|
|
1198
1493
|
)
|
|
1199
1494
|
);
|
|
1200
|
-
var parallelSearchOutputSchema =
|
|
1201
|
-
() =>
|
|
1202
|
-
|
|
1495
|
+
var parallelSearchOutputSchema = lazySchema9(
|
|
1496
|
+
() => zodSchema9(
|
|
1497
|
+
z12.union([
|
|
1203
1498
|
// Success response
|
|
1204
|
-
|
|
1205
|
-
searchId:
|
|
1206
|
-
results:
|
|
1207
|
-
|
|
1208
|
-
url:
|
|
1209
|
-
title:
|
|
1210
|
-
excerpt:
|
|
1211
|
-
publishDate:
|
|
1212
|
-
relevanceScore:
|
|
1499
|
+
z12.object({
|
|
1500
|
+
searchId: z12.string(),
|
|
1501
|
+
results: z12.array(
|
|
1502
|
+
z12.object({
|
|
1503
|
+
url: z12.string(),
|
|
1504
|
+
title: z12.string(),
|
|
1505
|
+
excerpt: z12.string(),
|
|
1506
|
+
publishDate: z12.string().nullable().optional(),
|
|
1507
|
+
relevanceScore: z12.number().optional()
|
|
1213
1508
|
})
|
|
1214
1509
|
)
|
|
1215
1510
|
}),
|
|
1216
1511
|
// Error response
|
|
1217
|
-
|
|
1218
|
-
error:
|
|
1512
|
+
z12.object({
|
|
1513
|
+
error: z12.enum([
|
|
1219
1514
|
"api_error",
|
|
1220
1515
|
"rate_limit",
|
|
1221
1516
|
"timeout",
|
|
@@ -1223,8 +1518,8 @@ var parallelSearchOutputSchema = lazySchema6(
|
|
|
1223
1518
|
"configuration_error",
|
|
1224
1519
|
"unknown"
|
|
1225
1520
|
]),
|
|
1226
|
-
statusCode:
|
|
1227
|
-
message:
|
|
1521
|
+
statusCode: z12.number().optional(),
|
|
1522
|
+
message: z12.string()
|
|
1228
1523
|
})
|
|
1229
1524
|
])
|
|
1230
1525
|
)
|
|
@@ -1239,79 +1534,79 @@ var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
|
|
|
1239
1534
|
// src/tool/perplexity-search.ts
|
|
1240
1535
|
import {
|
|
1241
1536
|
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema2,
|
|
1242
|
-
lazySchema as
|
|
1243
|
-
zodSchema as
|
|
1537
|
+
lazySchema as lazySchema10,
|
|
1538
|
+
zodSchema as zodSchema10
|
|
1244
1539
|
} from "@ai-sdk/provider-utils";
|
|
1245
|
-
import { z as
|
|
1246
|
-
var perplexitySearchInputSchema =
|
|
1247
|
-
() =>
|
|
1248
|
-
|
|
1249
|
-
query:
|
|
1540
|
+
import { z as z13 } from "zod";
|
|
1541
|
+
var perplexitySearchInputSchema = lazySchema10(
|
|
1542
|
+
() => zodSchema10(
|
|
1543
|
+
z13.object({
|
|
1544
|
+
query: z13.union([z13.string(), z13.array(z13.string())]).describe(
|
|
1250
1545
|
"Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
|
|
1251
1546
|
),
|
|
1252
|
-
max_results:
|
|
1547
|
+
max_results: z13.number().optional().describe(
|
|
1253
1548
|
"Maximum number of search results to return (1-20, default: 10)"
|
|
1254
1549
|
),
|
|
1255
|
-
max_tokens_per_page:
|
|
1550
|
+
max_tokens_per_page: z13.number().optional().describe(
|
|
1256
1551
|
"Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
|
|
1257
1552
|
),
|
|
1258
|
-
max_tokens:
|
|
1553
|
+
max_tokens: z13.number().optional().describe(
|
|
1259
1554
|
"Maximum total tokens across all search results (default: 25000, max: 1000000)"
|
|
1260
1555
|
),
|
|
1261
|
-
country:
|
|
1556
|
+
country: z13.string().optional().describe(
|
|
1262
1557
|
"Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
|
|
1263
1558
|
),
|
|
1264
|
-
search_domain_filter:
|
|
1559
|
+
search_domain_filter: z13.array(z13.string()).optional().describe(
|
|
1265
1560
|
"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
1561
|
),
|
|
1267
|
-
search_language_filter:
|
|
1562
|
+
search_language_filter: z13.array(z13.string()).optional().describe(
|
|
1268
1563
|
"List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
|
|
1269
1564
|
),
|
|
1270
|
-
search_after_date:
|
|
1565
|
+
search_after_date: z13.string().optional().describe(
|
|
1271
1566
|
"Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
1272
1567
|
),
|
|
1273
|
-
search_before_date:
|
|
1568
|
+
search_before_date: z13.string().optional().describe(
|
|
1274
1569
|
"Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
1275
1570
|
),
|
|
1276
|
-
last_updated_after_filter:
|
|
1571
|
+
last_updated_after_filter: z13.string().optional().describe(
|
|
1277
1572
|
"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
1573
|
),
|
|
1279
|
-
last_updated_before_filter:
|
|
1574
|
+
last_updated_before_filter: z13.string().optional().describe(
|
|
1280
1575
|
"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
1576
|
),
|
|
1282
|
-
search_recency_filter:
|
|
1577
|
+
search_recency_filter: z13.enum(["day", "week", "month", "year"]).optional().describe(
|
|
1283
1578
|
"Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
|
|
1284
1579
|
)
|
|
1285
1580
|
})
|
|
1286
1581
|
)
|
|
1287
1582
|
);
|
|
1288
|
-
var perplexitySearchOutputSchema =
|
|
1289
|
-
() =>
|
|
1290
|
-
|
|
1583
|
+
var perplexitySearchOutputSchema = lazySchema10(
|
|
1584
|
+
() => zodSchema10(
|
|
1585
|
+
z13.union([
|
|
1291
1586
|
// Success response
|
|
1292
|
-
|
|
1293
|
-
results:
|
|
1294
|
-
|
|
1295
|
-
title:
|
|
1296
|
-
url:
|
|
1297
|
-
snippet:
|
|
1298
|
-
date:
|
|
1299
|
-
lastUpdated:
|
|
1587
|
+
z13.object({
|
|
1588
|
+
results: z13.array(
|
|
1589
|
+
z13.object({
|
|
1590
|
+
title: z13.string(),
|
|
1591
|
+
url: z13.string(),
|
|
1592
|
+
snippet: z13.string(),
|
|
1593
|
+
date: z13.string().optional(),
|
|
1594
|
+
lastUpdated: z13.string().optional()
|
|
1300
1595
|
})
|
|
1301
1596
|
),
|
|
1302
|
-
id:
|
|
1597
|
+
id: z13.string()
|
|
1303
1598
|
}),
|
|
1304
1599
|
// Error response
|
|
1305
|
-
|
|
1306
|
-
error:
|
|
1600
|
+
z13.object({
|
|
1601
|
+
error: z13.enum([
|
|
1307
1602
|
"api_error",
|
|
1308
1603
|
"rate_limit",
|
|
1309
1604
|
"timeout",
|
|
1310
1605
|
"invalid_input",
|
|
1311
1606
|
"unknown"
|
|
1312
1607
|
]),
|
|
1313
|
-
statusCode:
|
|
1314
|
-
message:
|
|
1608
|
+
statusCode: z13.number().optional(),
|
|
1609
|
+
message: z13.string()
|
|
1315
1610
|
})
|
|
1316
1611
|
])
|
|
1317
1612
|
)
|
|
@@ -1356,7 +1651,7 @@ async function getVercelRequestId() {
|
|
|
1356
1651
|
import { withUserAgentSuffix } from "@ai-sdk/provider-utils";
|
|
1357
1652
|
|
|
1358
1653
|
// src/version.ts
|
|
1359
|
-
var VERSION = true ? "4.0.0-beta.
|
|
1654
|
+
var VERSION = true ? "4.0.0-beta.40" : "0.0.0-test";
|
|
1360
1655
|
|
|
1361
1656
|
// src/gateway-provider.ts
|
|
1362
1657
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
@@ -1458,6 +1753,30 @@ function createGatewayProvider(options = {}) {
|
|
|
1458
1753
|
);
|
|
1459
1754
|
});
|
|
1460
1755
|
};
|
|
1756
|
+
const getSpendReport = async (params) => {
|
|
1757
|
+
return new GatewaySpendReport({
|
|
1758
|
+
baseURL,
|
|
1759
|
+
headers: getHeaders,
|
|
1760
|
+
fetch: options.fetch
|
|
1761
|
+
}).getSpendReport(params).catch(async (error) => {
|
|
1762
|
+
throw await asGatewayError(
|
|
1763
|
+
error,
|
|
1764
|
+
await parseAuthMethod(await getHeaders())
|
|
1765
|
+
);
|
|
1766
|
+
});
|
|
1767
|
+
};
|
|
1768
|
+
const getGenerationInfo = async (params) => {
|
|
1769
|
+
return new GatewayGenerationInfoFetcher({
|
|
1770
|
+
baseURL,
|
|
1771
|
+
headers: getHeaders,
|
|
1772
|
+
fetch: options.fetch
|
|
1773
|
+
}).getGenerationInfo(params).catch(async (error) => {
|
|
1774
|
+
throw await asGatewayError(
|
|
1775
|
+
error,
|
|
1776
|
+
await parseAuthMethod(await getHeaders())
|
|
1777
|
+
);
|
|
1778
|
+
});
|
|
1779
|
+
};
|
|
1461
1780
|
const provider = function(modelId) {
|
|
1462
1781
|
if (new.target) {
|
|
1463
1782
|
throw new Error(
|
|
@@ -1466,9 +1785,11 @@ function createGatewayProvider(options = {}) {
|
|
|
1466
1785
|
}
|
|
1467
1786
|
return createLanguageModel(modelId);
|
|
1468
1787
|
};
|
|
1469
|
-
provider.specificationVersion = "
|
|
1788
|
+
provider.specificationVersion = "v4";
|
|
1470
1789
|
provider.getAvailableModels = getAvailableModels;
|
|
1471
1790
|
provider.getCredits = getCredits;
|
|
1791
|
+
provider.getSpendReport = getSpendReport;
|
|
1792
|
+
provider.getGenerationInfo = getGenerationInfo;
|
|
1472
1793
|
provider.imageModel = (modelId) => {
|
|
1473
1794
|
return new GatewayImageModel(modelId, {
|
|
1474
1795
|
provider: "gateway",
|
|
@@ -1499,6 +1820,17 @@ function createGatewayProvider(options = {}) {
|
|
|
1499
1820
|
o11yHeaders: createO11yHeaders()
|
|
1500
1821
|
});
|
|
1501
1822
|
};
|
|
1823
|
+
const createRerankingModel = (modelId) => {
|
|
1824
|
+
return new GatewayRerankingModel(modelId, {
|
|
1825
|
+
provider: "gateway",
|
|
1826
|
+
baseURL,
|
|
1827
|
+
headers: getHeaders,
|
|
1828
|
+
fetch: options.fetch,
|
|
1829
|
+
o11yHeaders: createO11yHeaders()
|
|
1830
|
+
});
|
|
1831
|
+
};
|
|
1832
|
+
provider.rerankingModel = createRerankingModel;
|
|
1833
|
+
provider.reranking = createRerankingModel;
|
|
1502
1834
|
provider.chat = provider.languageModel;
|
|
1503
1835
|
provider.embedding = provider.embeddingModel;
|
|
1504
1836
|
provider.image = provider.imageModel;
|