@ai-sdk/provider-utils 5.0.0-beta.2 → 5.0.0-beta.4
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 +83 -0
- package/dist/index.d.mts +37 -15
- package/dist/index.d.ts +37 -15
- package/dist/index.js +8 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/convert-image-model-file-to-data-uri.ts +3 -3
- package/src/create-tool-name-mapping.ts +5 -21
- package/src/inject-json-instruction.ts +5 -5
- package/src/types/assistant-model-message.ts +2 -0
- package/src/types/content-part.ts +29 -0
- package/src/types/index.ts +1 -0
- package/src/types/provider-options.ts +2 -2
- package/src/types/tool.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,88 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.0-beta.4
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 61753c3: ### `@ai-sdk/openai`: remove redundant `name` argument from `openai.tools.customTool()`
|
|
8
|
+
|
|
9
|
+
`openai.tools.customTool()` no longer accepts a `name` field. the tool name is now derived from the sdk tool key (the object key in the `tools` object).
|
|
10
|
+
|
|
11
|
+
migration: remove the `name` property from `customTool()` calls. the object key is now used as the tool name sent to the openai api.
|
|
12
|
+
|
|
13
|
+
before:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
tools: {
|
|
17
|
+
write_sql: openai.tools.customTool({
|
|
18
|
+
name: 'write_sql',
|
|
19
|
+
description: '...',
|
|
20
|
+
}),
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
after:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
tools: {
|
|
28
|
+
write_sql: openai.tools.customTool({
|
|
29
|
+
description: '...',
|
|
30
|
+
}),
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### `@ai-sdk/provider-utils`: `createToolNameMapping()` no longer accepts the `resolveProviderToolName` parameter
|
|
35
|
+
|
|
36
|
+
before: tool name can be set dynamically
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const toolNameMapping = createToolNameMapping({
|
|
40
|
+
tools,
|
|
41
|
+
providerToolNames: {
|
|
42
|
+
'openai.code_interpreter': 'code_interpreter',
|
|
43
|
+
'openai.file_search': 'file_search',
|
|
44
|
+
'openai.image_generation': 'image_generation',
|
|
45
|
+
'openai.local_shell': 'local_shell',
|
|
46
|
+
'openai.shell': 'shell',
|
|
47
|
+
'openai.web_search': 'web_search',
|
|
48
|
+
'openai.web_search_preview': 'web_search_preview',
|
|
49
|
+
'openai.mcp': 'mcp',
|
|
50
|
+
'openai.apply_patch': 'apply_patch',
|
|
51
|
+
},
|
|
52
|
+
resolveProviderToolName: tool =>
|
|
53
|
+
tool.id === 'openai.custom'
|
|
54
|
+
? (tool.args as { name?: string }).name
|
|
55
|
+
: undefined,
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
after: tool name is static based on `tools` keys
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
const toolNameMapping = createToolNameMapping({
|
|
63
|
+
tools,
|
|
64
|
+
providerToolNames: {
|
|
65
|
+
'openai.code_interpreter': 'code_interpreter',
|
|
66
|
+
'openai.file_search': 'file_search',
|
|
67
|
+
'openai.image_generation': 'image_generation',
|
|
68
|
+
'openai.local_shell': 'local_shell',
|
|
69
|
+
'openai.shell': 'shell',
|
|
70
|
+
'openai.web_search': 'web_search',
|
|
71
|
+
'openai.web_search_preview': 'web_search_preview',
|
|
72
|
+
'openai.mcp': 'mcp',
|
|
73
|
+
'openai.apply_patch': 'apply_patch',
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## 5.0.0-beta.3
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- f7d4f01: feat(provider): add support for `reasoning-file` type for files that are part of reasoning
|
|
83
|
+
- Updated dependencies [f7d4f01]
|
|
84
|
+
- @ai-sdk/provider@4.0.0-beta.2
|
|
85
|
+
|
|
3
86
|
## 5.0.0-beta.2
|
|
4
87
|
|
|
5
88
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, ImageModelV4File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, SharedV4ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
2
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
export * from '@standard-schema/spec';
|
|
4
4
|
import * as z3 from 'zod/v3';
|
|
@@ -41,20 +41,15 @@ interface ToolNameMapping {
|
|
|
41
41
|
* @param tools - Tools that were passed to the language model.
|
|
42
42
|
* @param providerToolNames - Maps the provider tool ids to the provider tool names.
|
|
43
43
|
*/
|
|
44
|
-
declare function createToolNameMapping({ tools, providerToolNames,
|
|
44
|
+
declare function createToolNameMapping({ tools, providerToolNames, }: {
|
|
45
45
|
/**
|
|
46
46
|
* Tools that were passed to the language model.
|
|
47
47
|
*/
|
|
48
|
-
tools: Array<
|
|
48
|
+
tools: Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool> | undefined;
|
|
49
49
|
/**
|
|
50
50
|
* Maps the provider tool ids to the provider tool names.
|
|
51
51
|
*/
|
|
52
52
|
providerToolNames: Record<`${string}.${string}`, string>;
|
|
53
|
-
/**
|
|
54
|
-
* Optional resolver for provider tool names that cannot be represented as
|
|
55
|
-
* static id -> name mappings (e.g. dynamic provider names).
|
|
56
|
-
*/
|
|
57
|
-
resolveProviderToolName?: (tool: LanguageModelV3ProviderTool) => string | undefined;
|
|
58
53
|
}): ToolNameMapping;
|
|
59
54
|
|
|
60
55
|
/**
|
|
@@ -97,13 +92,13 @@ declare function extractResponseHeaders(response: Response): {
|
|
|
97
92
|
};
|
|
98
93
|
|
|
99
94
|
/**
|
|
100
|
-
* Convert an
|
|
95
|
+
* Convert an ImageModelV4File to a URL or data URI string.
|
|
101
96
|
*
|
|
102
97
|
* If the file is a URL, it returns the URL as-is.
|
|
103
98
|
* If the file is base64 data, it returns a data URI with the base64 data.
|
|
104
99
|
* If the file is a Uint8Array, it converts it to base64 and returns a data URI.
|
|
105
100
|
*/
|
|
106
|
-
declare function convertImageModelFileToDataUri(file:
|
|
101
|
+
declare function convertImageModelFileToDataUri(file: ImageModelV4File): string;
|
|
107
102
|
|
|
108
103
|
/**
|
|
109
104
|
* Converts an input object to FormData for multipart/form-data requests.
|
|
@@ -390,11 +385,11 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
|
|
|
390
385
|
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
|
391
386
|
|
|
392
387
|
declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
|
|
393
|
-
messages:
|
|
388
|
+
messages: LanguageModelV4Prompt;
|
|
394
389
|
schema?: JSONSchema7;
|
|
395
390
|
schemaPrefix?: string;
|
|
396
391
|
schemaSuffix?: string;
|
|
397
|
-
}):
|
|
392
|
+
}): LanguageModelV4Prompt;
|
|
398
393
|
|
|
399
394
|
declare function isAbortError(error: unknown): error is Error;
|
|
400
395
|
|
|
@@ -549,7 +544,7 @@ type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
|
|
549
544
|
* They are passed through to the provider from the AI SDK and enable
|
|
550
545
|
* provider-specific functionality that can be fully encapsulated in the provider.
|
|
551
546
|
*/
|
|
552
|
-
type ProviderOptions =
|
|
547
|
+
type ProviderOptions = SharedV4ProviderOptions;
|
|
553
548
|
|
|
554
549
|
/**
|
|
555
550
|
* Text content part of a prompt. It contains a string of text.
|
|
@@ -637,6 +632,31 @@ interface ReasoningPart {
|
|
|
637
632
|
*/
|
|
638
633
|
providerOptions?: ProviderOptions;
|
|
639
634
|
}
|
|
635
|
+
/**
|
|
636
|
+
* Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
|
|
637
|
+
*/
|
|
638
|
+
interface ReasoningFilePart {
|
|
639
|
+
type: 'reasoning-file';
|
|
640
|
+
/**
|
|
641
|
+
* File data. Can either be:
|
|
642
|
+
*
|
|
643
|
+
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
644
|
+
* - URL: a URL that points to the file
|
|
645
|
+
*/
|
|
646
|
+
data: DataContent | URL;
|
|
647
|
+
/**
|
|
648
|
+
* IANA media type of the file.
|
|
649
|
+
*
|
|
650
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
651
|
+
*/
|
|
652
|
+
mediaType: string;
|
|
653
|
+
/**
|
|
654
|
+
* Additional provider-specific metadata. They are passed through
|
|
655
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
656
|
+
* functionality that can be fully encapsulated in the provider.
|
|
657
|
+
*/
|
|
658
|
+
providerOptions?: ProviderOptions;
|
|
659
|
+
}
|
|
640
660
|
/**
|
|
641
661
|
* Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
|
642
662
|
*/
|
|
@@ -893,7 +913,7 @@ type AssistantModelMessage = {
|
|
|
893
913
|
* Content of an assistant message.
|
|
894
914
|
* It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
|
|
895
915
|
*/
|
|
896
|
-
type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
|
|
916
|
+
type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ReasoningFilePart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
|
|
897
917
|
|
|
898
918
|
/**
|
|
899
919
|
* A system message. It can contain system information.
|
|
@@ -1120,6 +1140,8 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1120
1140
|
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
1121
1141
|
*
|
|
1122
1142
|
* If not provided, the tool result will be sent as a JSON object.
|
|
1143
|
+
*
|
|
1144
|
+
* This function is invoked on the server by `convertToModelMessages`, so ensure that you pass the same "tools" (ToolSet) to both "convertToModelMessages" and "streamText" (or other generation APIs).
|
|
1123
1145
|
*/
|
|
1124
1146
|
toModelOutput?: (options: {
|
|
1125
1147
|
/**
|
|
@@ -1430,4 +1452,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1430
1452
|
*/
|
|
1431
1453
|
type ToolCallOptions = ToolExecutionOptions;
|
|
1432
1454
|
|
|
1433
|
-
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, 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, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1455
|
+
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, 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 ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, 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, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, ImageModelV4File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, SharedV4ProviderOptions, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
2
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
export * from '@standard-schema/spec';
|
|
4
4
|
import * as z3 from 'zod/v3';
|
|
@@ -41,20 +41,15 @@ interface ToolNameMapping {
|
|
|
41
41
|
* @param tools - Tools that were passed to the language model.
|
|
42
42
|
* @param providerToolNames - Maps the provider tool ids to the provider tool names.
|
|
43
43
|
*/
|
|
44
|
-
declare function createToolNameMapping({ tools, providerToolNames,
|
|
44
|
+
declare function createToolNameMapping({ tools, providerToolNames, }: {
|
|
45
45
|
/**
|
|
46
46
|
* Tools that were passed to the language model.
|
|
47
47
|
*/
|
|
48
|
-
tools: Array<
|
|
48
|
+
tools: Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool> | undefined;
|
|
49
49
|
/**
|
|
50
50
|
* Maps the provider tool ids to the provider tool names.
|
|
51
51
|
*/
|
|
52
52
|
providerToolNames: Record<`${string}.${string}`, string>;
|
|
53
|
-
/**
|
|
54
|
-
* Optional resolver for provider tool names that cannot be represented as
|
|
55
|
-
* static id -> name mappings (e.g. dynamic provider names).
|
|
56
|
-
*/
|
|
57
|
-
resolveProviderToolName?: (tool: LanguageModelV3ProviderTool) => string | undefined;
|
|
58
53
|
}): ToolNameMapping;
|
|
59
54
|
|
|
60
55
|
/**
|
|
@@ -97,13 +92,13 @@ declare function extractResponseHeaders(response: Response): {
|
|
|
97
92
|
};
|
|
98
93
|
|
|
99
94
|
/**
|
|
100
|
-
* Convert an
|
|
95
|
+
* Convert an ImageModelV4File to a URL or data URI string.
|
|
101
96
|
*
|
|
102
97
|
* If the file is a URL, it returns the URL as-is.
|
|
103
98
|
* If the file is base64 data, it returns a data URI with the base64 data.
|
|
104
99
|
* If the file is a Uint8Array, it converts it to base64 and returns a data URI.
|
|
105
100
|
*/
|
|
106
|
-
declare function convertImageModelFileToDataUri(file:
|
|
101
|
+
declare function convertImageModelFileToDataUri(file: ImageModelV4File): string;
|
|
107
102
|
|
|
108
103
|
/**
|
|
109
104
|
* Converts an input object to FormData for multipart/form-data requests.
|
|
@@ -390,11 +385,11 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
|
|
|
390
385
|
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
|
391
386
|
|
|
392
387
|
declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
|
|
393
|
-
messages:
|
|
388
|
+
messages: LanguageModelV4Prompt;
|
|
394
389
|
schema?: JSONSchema7;
|
|
395
390
|
schemaPrefix?: string;
|
|
396
391
|
schemaSuffix?: string;
|
|
397
|
-
}):
|
|
392
|
+
}): LanguageModelV4Prompt;
|
|
398
393
|
|
|
399
394
|
declare function isAbortError(error: unknown): error is Error;
|
|
400
395
|
|
|
@@ -549,7 +544,7 @@ type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
|
|
549
544
|
* They are passed through to the provider from the AI SDK and enable
|
|
550
545
|
* provider-specific functionality that can be fully encapsulated in the provider.
|
|
551
546
|
*/
|
|
552
|
-
type ProviderOptions =
|
|
547
|
+
type ProviderOptions = SharedV4ProviderOptions;
|
|
553
548
|
|
|
554
549
|
/**
|
|
555
550
|
* Text content part of a prompt. It contains a string of text.
|
|
@@ -637,6 +632,31 @@ interface ReasoningPart {
|
|
|
637
632
|
*/
|
|
638
633
|
providerOptions?: ProviderOptions;
|
|
639
634
|
}
|
|
635
|
+
/**
|
|
636
|
+
* Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
|
|
637
|
+
*/
|
|
638
|
+
interface ReasoningFilePart {
|
|
639
|
+
type: 'reasoning-file';
|
|
640
|
+
/**
|
|
641
|
+
* File data. Can either be:
|
|
642
|
+
*
|
|
643
|
+
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
644
|
+
* - URL: a URL that points to the file
|
|
645
|
+
*/
|
|
646
|
+
data: DataContent | URL;
|
|
647
|
+
/**
|
|
648
|
+
* IANA media type of the file.
|
|
649
|
+
*
|
|
650
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
651
|
+
*/
|
|
652
|
+
mediaType: string;
|
|
653
|
+
/**
|
|
654
|
+
* Additional provider-specific metadata. They are passed through
|
|
655
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
656
|
+
* functionality that can be fully encapsulated in the provider.
|
|
657
|
+
*/
|
|
658
|
+
providerOptions?: ProviderOptions;
|
|
659
|
+
}
|
|
640
660
|
/**
|
|
641
661
|
* Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
|
642
662
|
*/
|
|
@@ -893,7 +913,7 @@ type AssistantModelMessage = {
|
|
|
893
913
|
* Content of an assistant message.
|
|
894
914
|
* It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
|
|
895
915
|
*/
|
|
896
|
-
type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
|
|
916
|
+
type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ReasoningFilePart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
|
|
897
917
|
|
|
898
918
|
/**
|
|
899
919
|
* A system message. It can contain system information.
|
|
@@ -1120,6 +1140,8 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1120
1140
|
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
1121
1141
|
*
|
|
1122
1142
|
* If not provided, the tool result will be sent as a JSON object.
|
|
1143
|
+
*
|
|
1144
|
+
* This function is invoked on the server by `convertToModelMessages`, so ensure that you pass the same "tools" (ToolSet) to both "convertToModelMessages" and "streamText" (or other generation APIs).
|
|
1123
1145
|
*/
|
|
1124
1146
|
toModelOutput?: (options: {
|
|
1125
1147
|
/**
|
|
@@ -1430,4 +1452,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1430
1452
|
*/
|
|
1431
1453
|
type ToolCallOptions = ToolExecutionOptions;
|
|
1432
1454
|
|
|
1433
|
-
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, 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, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1455
|
+
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, 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 ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, 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, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -146,30 +146,25 @@ function convertAsyncIteratorToReadableStream(iterator) {
|
|
|
146
146
|
// src/create-tool-name-mapping.ts
|
|
147
147
|
function createToolNameMapping({
|
|
148
148
|
tools = [],
|
|
149
|
-
providerToolNames
|
|
150
|
-
resolveProviderToolName
|
|
149
|
+
providerToolNames
|
|
151
150
|
}) {
|
|
152
|
-
var _a2;
|
|
153
151
|
const customToolNameToProviderToolName = {};
|
|
154
152
|
const providerToolNameToCustomToolName = {};
|
|
155
153
|
for (const tool2 of tools) {
|
|
156
|
-
if (tool2.type === "provider") {
|
|
157
|
-
const providerToolName =
|
|
158
|
-
if (providerToolName == null) {
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
154
|
+
if (tool2.type === "provider" && tool2.id in providerToolNames) {
|
|
155
|
+
const providerToolName = providerToolNames[tool2.id];
|
|
161
156
|
customToolNameToProviderToolName[tool2.name] = providerToolName;
|
|
162
157
|
providerToolNameToCustomToolName[providerToolName] = tool2.name;
|
|
163
158
|
}
|
|
164
159
|
}
|
|
165
160
|
return {
|
|
166
161
|
toProviderToolName: (customToolName) => {
|
|
167
|
-
var
|
|
168
|
-
return (
|
|
162
|
+
var _a2;
|
|
163
|
+
return (_a2 = customToolNameToProviderToolName[customToolName]) != null ? _a2 : customToolName;
|
|
169
164
|
},
|
|
170
165
|
toCustomToolName: (providerToolName) => {
|
|
171
|
-
var
|
|
172
|
-
return (
|
|
166
|
+
var _a2;
|
|
167
|
+
return (_a2 = providerToolNameToCustomToolName[providerToolName]) != null ? _a2 : providerToolName;
|
|
173
168
|
}
|
|
174
169
|
};
|
|
175
170
|
}
|
|
@@ -675,7 +670,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
675
670
|
}
|
|
676
671
|
|
|
677
672
|
// src/version.ts
|
|
678
|
-
var VERSION = true ? "5.0.0-beta.
|
|
673
|
+
var VERSION = true ? "5.0.0-beta.4" : "0.0.0-test";
|
|
679
674
|
|
|
680
675
|
// src/get-from-api.ts
|
|
681
676
|
var getOriginalFetch = () => globalThis.fetch;
|