@ai-sdk/gateway 4.0.92 → 4.0.95
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 +23 -0
- package/dist/index.d.ts +183 -9
- package/dist/index.js +364 -222
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +192 -4
- package/package.json +3 -3
- package/src/gateway-evaluation-model.ts +16 -2
- package/src/gateway-provider-options.ts +209 -7
- package/src/gateway-tools.ts +18 -0
- package/src/index.ts +3 -0
- package/src/tool/browserbase-fetch.ts +157 -0
- package/src/tool/browserbase-search.ts +137 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @ai-sdk/gateway
|
|
2
2
|
|
|
3
|
+
## 4.0.95
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b67b1b7: feat(provider/gateway): type conditional evaluation fallbacks
|
|
8
|
+
|
|
9
|
+
## 4.0.94
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [af9597b]
|
|
14
|
+
- Updated dependencies [bc49f78]
|
|
15
|
+
- @ai-sdk/provider-utils@5.0.49
|
|
16
|
+
|
|
17
|
+
## 4.0.93
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 80b9100: feat (provider/gateway): add Browserbase Search and Fetch tool support
|
|
22
|
+
- d3cc6ae: feat(provider/gateway): accept structured-output in the has provider option
|
|
23
|
+
- Updated dependencies [be877ff]
|
|
24
|
+
- @ai-sdk/provider-utils@5.0.48
|
|
25
|
+
|
|
3
26
|
## 4.0.92
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -868,10 +868,130 @@ interface ExaSearchInput {
|
|
|
868
868
|
type ExaSearchOutput = ExaSearchResponse | ExaSearchError;
|
|
869
869
|
declare const exaSearchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolFactory<ExaSearchInput, ExaSearchOutput, ExaSearchConfig, {}>;
|
|
870
870
|
|
|
871
|
+
interface BrowserbaseSearchConfig {
|
|
872
|
+
/**
|
|
873
|
+
* Default maximum number of results to return (1-25, default: 10).
|
|
874
|
+
*/
|
|
875
|
+
numResults?: number;
|
|
876
|
+
}
|
|
877
|
+
interface BrowserbaseSearchInput {
|
|
878
|
+
/**
|
|
879
|
+
* Web search query (1-200 characters).
|
|
880
|
+
*/
|
|
881
|
+
query: string;
|
|
882
|
+
/**
|
|
883
|
+
* Maximum number of results to return (1-25, default: 10).
|
|
884
|
+
*/
|
|
885
|
+
num_results?: number;
|
|
886
|
+
}
|
|
887
|
+
interface BrowserbaseSearchResult {
|
|
888
|
+
/** Unique identifier for the result. */
|
|
889
|
+
id: string;
|
|
890
|
+
/** Title of the search result. */
|
|
891
|
+
title: string;
|
|
892
|
+
/** URL of the search result. */
|
|
893
|
+
url: string;
|
|
894
|
+
/** Author of the content, when available. */
|
|
895
|
+
author?: string;
|
|
896
|
+
/** Favicon URL, when available. */
|
|
897
|
+
favicon?: string;
|
|
898
|
+
/** Image URL, when available. */
|
|
899
|
+
image?: string;
|
|
900
|
+
/** Publication date in ISO 8601 format, when available. */
|
|
901
|
+
publishedDate?: string;
|
|
902
|
+
}
|
|
903
|
+
interface BrowserbaseSearchResponse {
|
|
904
|
+
/** The search query that was executed. */
|
|
905
|
+
query: string;
|
|
906
|
+
/** Unique identifier for the request. */
|
|
907
|
+
requestId: string;
|
|
908
|
+
/** Search results. */
|
|
909
|
+
results: BrowserbaseSearchResult[];
|
|
910
|
+
}
|
|
911
|
+
interface BrowserbaseSearchError {
|
|
912
|
+
error: 'api_error' | 'configuration_error' | 'execution_error' | 'invalid_input' | 'rate_limit' | 'timeout' | 'unknown';
|
|
913
|
+
statusCode?: number;
|
|
914
|
+
message: string;
|
|
915
|
+
}
|
|
916
|
+
type BrowserbaseSearchOutput = BrowserbaseSearchError | BrowserbaseSearchResponse;
|
|
917
|
+
declare const browserbaseSearchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolFactory<BrowserbaseSearchInput, BrowserbaseSearchOutput, BrowserbaseSearchConfig, {}>;
|
|
918
|
+
|
|
919
|
+
type BrowserbaseFetchFormat = 'raw' | 'json' | 'markdown';
|
|
920
|
+
interface BrowserbaseFetchConfig {
|
|
921
|
+
/** Whether to follow HTTP redirects (default: false). */
|
|
922
|
+
allowRedirects?: boolean;
|
|
923
|
+
/** Whether to bypass TLS certificate verification (default: false). */
|
|
924
|
+
allowInsecureSsl?: boolean;
|
|
925
|
+
/** Whether to route the request through Browserbase proxies (default: false). */
|
|
926
|
+
proxies?: boolean;
|
|
927
|
+
/** Output format for the response content (default: raw). */
|
|
928
|
+
format?: BrowserbaseFetchFormat;
|
|
929
|
+
/**
|
|
930
|
+
* JSON Schema describing the desired response content. Only used when format
|
|
931
|
+
* is json.
|
|
932
|
+
*/
|
|
933
|
+
schema?: Record<string, unknown>;
|
|
934
|
+
}
|
|
935
|
+
interface BrowserbaseFetchInput {
|
|
936
|
+
/** URL of the page to fetch. */
|
|
937
|
+
url: string;
|
|
938
|
+
/** Whether to follow HTTP redirects. */
|
|
939
|
+
allow_redirects?: boolean;
|
|
940
|
+
/** Whether to bypass TLS certificate verification. */
|
|
941
|
+
allow_insecure_ssl?: boolean;
|
|
942
|
+
/** Whether to route the request through Browserbase proxies. */
|
|
943
|
+
proxies?: boolean;
|
|
944
|
+
/** Output format for the response content. */
|
|
945
|
+
format?: BrowserbaseFetchFormat;
|
|
946
|
+
/**
|
|
947
|
+
* JSON Schema describing the desired response content. Only used when format
|
|
948
|
+
* is json.
|
|
949
|
+
*/
|
|
950
|
+
schema?: Record<string, unknown>;
|
|
951
|
+
}
|
|
952
|
+
interface BrowserbaseFetchResponse {
|
|
953
|
+
/** Unique identifier for the fetch request. */
|
|
954
|
+
id: string;
|
|
955
|
+
/**
|
|
956
|
+
* Response body. Raw and markdown responses return strings; JSON extraction
|
|
957
|
+
* returns an object matching the requested schema.
|
|
958
|
+
*/
|
|
959
|
+
content: string | Record<string, unknown>;
|
|
960
|
+
/** MIME type of the response. */
|
|
961
|
+
contentType: string;
|
|
962
|
+
/** Character encoding of the response. */
|
|
963
|
+
encoding: string;
|
|
964
|
+
/** Response headers from the fetched page. */
|
|
965
|
+
headers: Record<string, string>;
|
|
966
|
+
/** HTTP status code returned by the fetched page. */
|
|
967
|
+
statusCode: number;
|
|
968
|
+
}
|
|
969
|
+
interface BrowserbaseFetchError {
|
|
970
|
+
error: 'api_error' | 'configuration_error' | 'execution_error' | 'invalid_input' | 'rate_limit' | 'timeout' | 'unknown';
|
|
971
|
+
statusCode?: number;
|
|
972
|
+
message: string;
|
|
973
|
+
}
|
|
974
|
+
type BrowserbaseFetchOutput = BrowserbaseFetchError | BrowserbaseFetchResponse;
|
|
975
|
+
declare const browserbaseFetchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolFactory<BrowserbaseFetchInput, BrowserbaseFetchOutput, BrowserbaseFetchConfig, {}>;
|
|
976
|
+
|
|
871
977
|
/**
|
|
872
978
|
* Gateway-specific provider-defined tools.
|
|
873
979
|
*/
|
|
874
980
|
declare const gatewayTools: {
|
|
981
|
+
/**
|
|
982
|
+
* Fetch page content using Browserbase's lightweight Fetch API.
|
|
983
|
+
*
|
|
984
|
+
* Supports raw, Markdown, and schema-driven JSON output as well as redirects,
|
|
985
|
+
* proxy routing, and TLS controls.
|
|
986
|
+
*/
|
|
987
|
+
browserbaseFetch: (config?: BrowserbaseFetchConfig) => ReturnType<typeof browserbaseFetchToolFactory>;
|
|
988
|
+
/**
|
|
989
|
+
* Search the web using Browserbase's Search API for fast, structured results.
|
|
990
|
+
*
|
|
991
|
+
* Returns titles, URLs, and available publication metadata without requiring
|
|
992
|
+
* a browser session.
|
|
993
|
+
*/
|
|
994
|
+
browserbaseSearch: (config?: BrowserbaseSearchConfig) => ReturnType<typeof browserbaseSearchToolFactory>;
|
|
875
995
|
/**
|
|
876
996
|
* Search the web using Exa for current information and token-efficient
|
|
877
997
|
* excerpts optimized for agent workflows.
|
|
@@ -1107,6 +1227,31 @@ type GatewayProviderMetadata = {
|
|
|
1107
1227
|
readonly [key: string]: JSONValue | undefined;
|
|
1108
1228
|
};
|
|
1109
1229
|
|
|
1230
|
+
/**
|
|
1231
|
+
* A condition on the primary model's answers. `QUESTION_ID` narrows
|
|
1232
|
+
* `question` to your question IDs. Groups nest at most five levels deep,
|
|
1233
|
+
* which the SDK checks at runtime.
|
|
1234
|
+
*/
|
|
1235
|
+
type EvaluationFallbackCondition<QUESTION_ID extends string = string> = ExclusiveCondition<{
|
|
1236
|
+
question: QUESTION_ID;
|
|
1237
|
+
confidenceBelow: number;
|
|
1238
|
+
}> | ExclusiveCondition<{
|
|
1239
|
+
question: QUESTION_ID;
|
|
1240
|
+
probabilityBetween: [number, number];
|
|
1241
|
+
}> | ExclusiveCondition<{
|
|
1242
|
+
any: EvaluationFallbackConditionList<QUESTION_ID>;
|
|
1243
|
+
}> | ExclusiveCondition<{
|
|
1244
|
+
all: EvaluationFallbackConditionList<QUESTION_ID>;
|
|
1245
|
+
}> | ExclusiveCondition<{
|
|
1246
|
+
atLeast: {
|
|
1247
|
+
count: number;
|
|
1248
|
+
conditions: EvaluationFallbackConditionList<QUESTION_ID>;
|
|
1249
|
+
};
|
|
1250
|
+
}>;
|
|
1251
|
+
type GatewayModelFallback<QUESTION_ID extends string = string> = string | {
|
|
1252
|
+
model: string;
|
|
1253
|
+
when: EvaluationFallbackCondition<QUESTION_ID>;
|
|
1254
|
+
};
|
|
1110
1255
|
type GatewayProviderOptions = {
|
|
1111
1256
|
/**
|
|
1112
1257
|
* Service-owned options may be added by the Gateway without requiring an SDK
|
|
@@ -1123,20 +1268,25 @@ type GatewayProviderOptions = {
|
|
|
1123
1268
|
* Restrict routing to provider models that satisfy every given entry.
|
|
1124
1269
|
*
|
|
1125
1270
|
* Entries are capability tags (`'implicit-caching'`, `'reasoning'`,
|
|
1126
|
-
* `'tool-use'`, `'vision'`
|
|
1127
|
-
*
|
|
1128
|
-
* `'
|
|
1129
|
-
*
|
|
1130
|
-
*
|
|
1131
|
-
*
|
|
1271
|
+
* `'tool-use'`, `'vision'` (image input), `'structured-output'`
|
|
1272
|
+
* (schema-constrained output)) or weight-format conditions:
|
|
1273
|
+
* `'quantization:fp8'` requires the serving provider to report that weight
|
|
1274
|
+
* format, `'!quantization:fp8'` excludes it (providers with no recorded
|
|
1275
|
+
* format still pass an exclusion). Format values are an open space but must
|
|
1276
|
+
* match `[a-zA-Z0-9._-]{1,32}` and compare case-insensitively. Unknown
|
|
1277
|
+
* capability names are rejected by the Gateway with a 400.
|
|
1132
1278
|
*/
|
|
1133
|
-
has?: Array<'implicit-caching' | 'reasoning' | 'tool-use' | 'vision' | `quantization:${string}` | `!quantization:${string}`>;
|
|
1279
|
+
has?: Array<'implicit-caching' | 'reasoning' | 'structured-output' | 'tool-use' | 'vision' | `quantization:${string}` | `!quantization:${string}`>;
|
|
1134
1280
|
/**
|
|
1135
1281
|
* Idempotency key for `experimental_startBatch`: retries with the same
|
|
1136
1282
|
* key replay the original batch instead of creating a duplicate.
|
|
1137
1283
|
*/
|
|
1138
1284
|
idempotencyKey?: string;
|
|
1139
|
-
/**
|
|
1285
|
+
/**
|
|
1286
|
+
* Array of model slugs specifying fallback models to use in order.
|
|
1287
|
+
* Conditional entries are only valid on evaluation requests, see
|
|
1288
|
+
* `GatewayEvaluationProviderOptions`.
|
|
1289
|
+
*/
|
|
1140
1290
|
models?: string[];
|
|
1141
1291
|
/** Array of provider slugs that are the only ones allowed to be used. */
|
|
1142
1292
|
only?: string[];
|
|
@@ -1159,6 +1309,30 @@ type GatewayProviderOptions = {
|
|
|
1159
1309
|
/** Filter to providers with zero data retention agreements. */
|
|
1160
1310
|
zeroDataRetention?: boolean;
|
|
1161
1311
|
};
|
|
1312
|
+
/**
|
|
1313
|
+
* Gateway provider options for evaluation requests. Same as
|
|
1314
|
+
* `GatewayProviderOptions`, except `models` may start with one conditional
|
|
1315
|
+
* `{ model, when }` entry followed by string error fallbacks.
|
|
1316
|
+
*
|
|
1317
|
+
* The SDK validates `models` strictly before sending the request, so new
|
|
1318
|
+
* condition shapes need an SDK release. Other keys pass through unchanged.
|
|
1319
|
+
*/
|
|
1320
|
+
type GatewayEvaluationProviderOptions<QUESTION_ID extends string = string> = GatewayProviderOptionsWithoutModels & {
|
|
1321
|
+
models?: GatewayModelFallbackList<QUESTION_ID>;
|
|
1322
|
+
};
|
|
1323
|
+
type EvaluationFallbackConditionList<QUESTION_ID extends string> = [
|
|
1324
|
+
EvaluationFallbackCondition<QUESTION_ID>,
|
|
1325
|
+
...EvaluationFallbackCondition<QUESTION_ID>[]
|
|
1326
|
+
];
|
|
1327
|
+
type ConditionKey = 'question' | 'confidenceBelow' | 'probabilityBetween' | 'any' | 'all' | 'atLeast';
|
|
1328
|
+
type ExclusiveCondition<CONDITION> = CONDITION & {
|
|
1329
|
+
[KEY in Exclude<ConditionKey, keyof CONDITION>]?: never;
|
|
1330
|
+
};
|
|
1331
|
+
type GatewayProviderOptionsWithoutModels = {
|
|
1332
|
+
[KEY in keyof GatewayProviderOptions as KEY extends 'models' ? never : KEY]: GatewayProviderOptions[KEY];
|
|
1333
|
+
};
|
|
1334
|
+
type ConditionalGatewayModelFallback<QUESTION_ID extends string> = Exclude<GatewayModelFallback<QUESTION_ID>, string>;
|
|
1335
|
+
type GatewayModelFallbackList<QUESTION_ID extends string> = string[] | [ConditionalGatewayModelFallback<QUESTION_ID>, ...string[]];
|
|
1162
1336
|
|
|
1163
1337
|
declare const symbol$9: unique symbol;
|
|
1164
1338
|
declare abstract class GatewayError extends Error {
|
|
@@ -1376,4 +1550,4 @@ declare class GatewayResponseError extends GatewayError {
|
|
|
1376
1550
|
|
|
1377
1551
|
declare const VERSION: string;
|
|
1378
1552
|
|
|
1379
|
-
export { GATEWAY_AUTH_SUBPROTOCOL_PREFIX, GATEWAY_REALTIME_SUBPROTOCOL, GATEWAY_TEAM_SUBPROTOCOL_PREFIX, GATEWAY_TRANSCRIPTION_SUBPROTOCOL, type GatewayAsyncJobMetadata, GatewayAuthenticationError, type GatewayCreditsResponse, type GatewayEmbeddingModelId, GatewayError, type GatewayErrorResponse, type GatewayEvaluationModelId, GatewayFailedDependencyError, GatewayForbiddenError, type GatewayGenerationInfo, type GatewayGenerationInfoParams, type GatewayImageModelId, GatewayInternalServerError, GatewayInvalidRequestError, type GatewayLanguageModelEntry, type GatewayProviderOptions as GatewayLanguageModelOptions, type GatewayLanguageModelSpecification, type GatewayLanguageModelEntry as GatewayModelEntry, type GatewayModelId, GatewayModelNotFoundError, GatewayNotFoundError, type GatewayProvider, type GatewayProviderMetadata, type GatewayProviderOptions, type GatewayProviderSettings, GatewayRateLimitError, type GatewayRealtimeModelId, type GatewayRerankingModelId, GatewayResponseError, type GatewaySpeechModelId, type GatewaySpendReportParams, type GatewaySpendReportResponse, type GatewaySpendReportRow, type GatewayTranscriptionModelId, type GatewayVideoModelId, VERSION, createGateway, createGateway as createGatewayProvider, gateway, getGatewayRealtimeAuthToken, getGatewayRealtimeProtocols, getGatewayRealtimeTeamIdOrSlug, getGatewayTranscriptionProtocols };
|
|
1553
|
+
export { type EvaluationFallbackCondition, GATEWAY_AUTH_SUBPROTOCOL_PREFIX, GATEWAY_REALTIME_SUBPROTOCOL, GATEWAY_TEAM_SUBPROTOCOL_PREFIX, GATEWAY_TRANSCRIPTION_SUBPROTOCOL, type GatewayAsyncJobMetadata, GatewayAuthenticationError, type GatewayCreditsResponse, type GatewayEmbeddingModelId, GatewayError, type GatewayErrorResponse, type GatewayEvaluationModelId, type GatewayEvaluationProviderOptions, GatewayFailedDependencyError, GatewayForbiddenError, type GatewayGenerationInfo, type GatewayGenerationInfoParams, type GatewayImageModelId, GatewayInternalServerError, GatewayInvalidRequestError, type GatewayLanguageModelEntry, type GatewayProviderOptions as GatewayLanguageModelOptions, type GatewayLanguageModelSpecification, type GatewayLanguageModelEntry as GatewayModelEntry, type GatewayModelFallback, type GatewayModelId, GatewayModelNotFoundError, GatewayNotFoundError, type GatewayProvider, type GatewayProviderMetadata, type GatewayProviderOptions, type GatewayProviderSettings, GatewayRateLimitError, type GatewayRealtimeModelId, type GatewayRerankingModelId, GatewayResponseError, type GatewaySpeechModelId, type GatewaySpendReportParams, type GatewaySpendReportResponse, type GatewaySpendReportRow, type GatewayTranscriptionModelId, type GatewayVideoModelId, VERSION, createGateway, createGateway as createGatewayProvider, gateway, getGatewayRealtimeAuthToken, getGatewayRealtimeProtocols, getGatewayRealtimeTeamIdOrSlug, getGatewayTranscriptionProtocols };
|