@ai-sdk/provider-utils 5.0.0-beta.15 → 5.0.0-beta.17
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 +13 -0
- package/dist/index.d.mts +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/has-required-key.ts +6 -0
- package/src/index.ts +1 -0
- package/src/types/infer-tool-context.ts +7 -2
- package/src/types/tool.ts +14 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.0-beta.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3ae1786: fix: better context type inference
|
|
8
|
+
|
|
9
|
+
## 5.0.0-beta.16
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [176466a]
|
|
14
|
+
- @ai-sdk/provider@4.0.0-beta.10
|
|
15
|
+
|
|
3
16
|
## 5.0.0-beta.15
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -384,6 +384,13 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
|
|
|
384
384
|
|
|
385
385
|
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
|
386
386
|
|
|
387
|
+
/**
|
|
388
|
+
* Checks if an object has required keys.
|
|
389
|
+
* @param OBJECT - The object to check.
|
|
390
|
+
* @returns True if the object has required keys, false otherwise.
|
|
391
|
+
*/
|
|
392
|
+
type HasRequiredKey<OBJECT> = {} extends OBJECT ? false : true;
|
|
393
|
+
|
|
387
394
|
declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
|
|
388
395
|
messages: LanguageModelV4Prompt;
|
|
389
396
|
schema?: JSONSchema7;
|
|
@@ -1097,7 +1104,7 @@ type Context = Record<string, unknown>;
|
|
|
1097
1104
|
/**
|
|
1098
1105
|
* Additional options that are sent into each tool execution.
|
|
1099
1106
|
*/
|
|
1100
|
-
interface ToolExecutionOptions<CONTEXT extends Context> {
|
|
1107
|
+
interface ToolExecutionOptions<CONTEXT extends Context | unknown | never> {
|
|
1101
1108
|
/**
|
|
1102
1109
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1103
1110
|
*/
|
|
@@ -1126,7 +1133,7 @@ interface ToolExecutionOptions<CONTEXT extends Context> {
|
|
|
1126
1133
|
/**
|
|
1127
1134
|
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
1128
1135
|
*/
|
|
1129
|
-
type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context> = (input: INPUT, options: {
|
|
1136
|
+
type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: {
|
|
1130
1137
|
/**
|
|
1131
1138
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1132
1139
|
*/
|
|
@@ -1151,12 +1158,12 @@ type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context> = (input: INPUT,
|
|
|
1151
1158
|
/**
|
|
1152
1159
|
* Function that executes the tool and returns either a single result or a stream of results.
|
|
1153
1160
|
*/
|
|
1154
|
-
type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
1161
|
+
type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
1155
1162
|
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
|
1156
1163
|
/**
|
|
1157
1164
|
* Helper type to determine the output properties of a tool.
|
|
1158
1165
|
*/
|
|
1159
|
-
type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context> = NeverOptional<OUTPUT, {
|
|
1166
|
+
type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = NeverOptional<OUTPUT, {
|
|
1160
1167
|
/**
|
|
1161
1168
|
* An async function that is called with the arguments from the tool call and produces a result.
|
|
1162
1169
|
* If not provided, the tool will not be executed automatically.
|
|
@@ -1176,7 +1183,7 @@ type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context> = NeverOptiona
|
|
|
1176
1183
|
*
|
|
1177
1184
|
* The tool can also contain an optional execute function for the actual execution function of the tool.
|
|
1178
1185
|
*/
|
|
1179
|
-
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context =
|
|
1186
|
+
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = {
|
|
1180
1187
|
/**
|
|
1181
1188
|
* An optional description of what the tool does.
|
|
1182
1189
|
* Will be used by the language model to decide whether to use the tool.
|
|
@@ -1524,7 +1531,7 @@ declare function executeTool<INPUT, OUTPUT, CONTEXT extends Context>({ execute,
|
|
|
1524
1531
|
/**
|
|
1525
1532
|
* Infer the context type of a tool.
|
|
1526
1533
|
*/
|
|
1527
|
-
type InferToolContext<TOOL extends Tool
|
|
1534
|
+
type InferToolContext<TOOL extends Tool> = TOOL extends Tool<any, any, infer CONTEXT> ? HasRequiredKey<CONTEXT> extends true ? CONTEXT : never : never;
|
|
1528
1535
|
|
|
1529
1536
|
/**
|
|
1530
1537
|
* Infer the input type of a tool.
|
|
@@ -1626,4 +1633,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1626
1633
|
dynamic?: boolean;
|
|
1627
1634
|
}
|
|
1628
1635
|
|
|
1629
|
-
export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderReference, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isProviderReference, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveProviderReference, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1636
|
+
export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderReference, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isProviderReference, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveProviderReference, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -384,6 +384,13 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
|
|
|
384
384
|
|
|
385
385
|
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
|
386
386
|
|
|
387
|
+
/**
|
|
388
|
+
* Checks if an object has required keys.
|
|
389
|
+
* @param OBJECT - The object to check.
|
|
390
|
+
* @returns True if the object has required keys, false otherwise.
|
|
391
|
+
*/
|
|
392
|
+
type HasRequiredKey<OBJECT> = {} extends OBJECT ? false : true;
|
|
393
|
+
|
|
387
394
|
declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
|
|
388
395
|
messages: LanguageModelV4Prompt;
|
|
389
396
|
schema?: JSONSchema7;
|
|
@@ -1097,7 +1104,7 @@ type Context = Record<string, unknown>;
|
|
|
1097
1104
|
/**
|
|
1098
1105
|
* Additional options that are sent into each tool execution.
|
|
1099
1106
|
*/
|
|
1100
|
-
interface ToolExecutionOptions<CONTEXT extends Context> {
|
|
1107
|
+
interface ToolExecutionOptions<CONTEXT extends Context | unknown | never> {
|
|
1101
1108
|
/**
|
|
1102
1109
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1103
1110
|
*/
|
|
@@ -1126,7 +1133,7 @@ interface ToolExecutionOptions<CONTEXT extends Context> {
|
|
|
1126
1133
|
/**
|
|
1127
1134
|
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
1128
1135
|
*/
|
|
1129
|
-
type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context> = (input: INPUT, options: {
|
|
1136
|
+
type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: {
|
|
1130
1137
|
/**
|
|
1131
1138
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1132
1139
|
*/
|
|
@@ -1151,12 +1158,12 @@ type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context> = (input: INPUT,
|
|
|
1151
1158
|
/**
|
|
1152
1159
|
* Function that executes the tool and returns either a single result or a stream of results.
|
|
1153
1160
|
*/
|
|
1154
|
-
type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
1161
|
+
type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
1155
1162
|
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
|
1156
1163
|
/**
|
|
1157
1164
|
* Helper type to determine the output properties of a tool.
|
|
1158
1165
|
*/
|
|
1159
|
-
type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context> = NeverOptional<OUTPUT, {
|
|
1166
|
+
type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = NeverOptional<OUTPUT, {
|
|
1160
1167
|
/**
|
|
1161
1168
|
* An async function that is called with the arguments from the tool call and produces a result.
|
|
1162
1169
|
* If not provided, the tool will not be executed automatically.
|
|
@@ -1176,7 +1183,7 @@ type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context> = NeverOptiona
|
|
|
1176
1183
|
*
|
|
1177
1184
|
* The tool can also contain an optional execute function for the actual execution function of the tool.
|
|
1178
1185
|
*/
|
|
1179
|
-
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context =
|
|
1186
|
+
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = {
|
|
1180
1187
|
/**
|
|
1181
1188
|
* An optional description of what the tool does.
|
|
1182
1189
|
* Will be used by the language model to decide whether to use the tool.
|
|
@@ -1524,7 +1531,7 @@ declare function executeTool<INPUT, OUTPUT, CONTEXT extends Context>({ execute,
|
|
|
1524
1531
|
/**
|
|
1525
1532
|
* Infer the context type of a tool.
|
|
1526
1533
|
*/
|
|
1527
|
-
type InferToolContext<TOOL extends Tool
|
|
1534
|
+
type InferToolContext<TOOL extends Tool> = TOOL extends Tool<any, any, infer CONTEXT> ? HasRequiredKey<CONTEXT> extends true ? CONTEXT : never : never;
|
|
1528
1535
|
|
|
1529
1536
|
/**
|
|
1530
1537
|
* Infer the input type of a tool.
|
|
@@ -1626,4 +1633,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1626
1633
|
dynamic?: boolean;
|
|
1627
1634
|
}
|
|
1628
1635
|
|
|
1629
|
-
export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderReference, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isProviderReference, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveProviderReference, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1636
|
+
export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderReference, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isProviderReference, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveProviderReference, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -678,7 +678,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
678
678
|
}
|
|
679
679
|
|
|
680
680
|
// src/version.ts
|
|
681
|
-
var VERSION = true ? "5.0.0-beta.
|
|
681
|
+
var VERSION = true ? "5.0.0-beta.17" : "0.0.0-test";
|
|
682
682
|
|
|
683
683
|
// src/get-from-api.ts
|
|
684
684
|
var getOriginalFetch = () => globalThis.fetch;
|