ai 4.1.7 → 4.1.9
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 +16 -0
- package/dist/index.d.mts +67 -37
- package/dist/index.d.ts +67 -37
- package/dist/index.js +253 -144
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +252 -144
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/rsc/dist/index.d.ts +2 -2
- package/rsc/dist/rsc-server.d.mts +2 -2
- package/rsc/dist/rsc-server.mjs +144 -144
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# ai
|
2
2
|
|
3
|
+
## 4.1.9
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 3a602ca: chore (core): rename CoreTool to Tool
|
8
|
+
- Updated dependencies [3a602ca]
|
9
|
+
- @ai-sdk/provider-utils@2.1.5
|
10
|
+
- @ai-sdk/ui-utils@1.1.6
|
11
|
+
- @ai-sdk/react@1.1.6
|
12
|
+
|
13
|
+
## 4.1.8
|
14
|
+
|
15
|
+
### Patch Changes
|
16
|
+
|
17
|
+
- 92f5f36: feat (core): add extractReasoningMiddleware
|
18
|
+
|
3
19
|
## 4.1.7
|
4
20
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { IDGenerator } from '@ai-sdk/provider-utils';
|
2
|
-
export {
|
2
|
+
export { CoreToolCall, CoreToolResult, IDGenerator, ToolCall, ToolResult, createIdGenerator, generateId } from '@ai-sdk/provider-utils';
|
3
3
|
import { DataStreamString, ToolInvocation, Attachment, Schema, DeepPartial, Message, JSONValue as JSONValue$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
|
4
4
|
export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DataStreamPart, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, ToolInvocation, UseAssistantOptions, formatAssistantStreamPart, formatDataStreamPart, jsonSchema, parseAssistantStreamPart, parseDataStreamPart, processDataStream, processTextStream } from '@ai-sdk/ui-utils';
|
5
5
|
import { JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, LanguageModelV1CallOptions, AISDKError, LanguageModelV1FunctionToolCall, JSONSchema7, NoSuchModelError } from '@ai-sdk/provider';
|
@@ -150,10 +150,14 @@ Tool choice for the generation. It supports the following settings:
|
|
150
150
|
- `none`: the model must not call tools
|
151
151
|
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
152
152
|
*/
|
153
|
-
type
|
153
|
+
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
154
154
|
type: 'tool';
|
155
155
|
toolName: keyof TOOLS;
|
156
156
|
};
|
157
|
+
/**
|
158
|
+
* @deprecated Use `ToolChoice` instead.
|
159
|
+
*/
|
160
|
+
type CoreToolChoice<TOOLS extends Record<string, unknown>> = ToolChoice<TOOLS>;
|
157
161
|
|
158
162
|
type LanguageModelRequestMetadata = {
|
159
163
|
/**
|
@@ -1356,6 +1360,16 @@ Callback that is called when the LLM response and the final object validation ar
|
|
1356
1360
|
};
|
1357
1361
|
}): StreamObjectResult<JSONValue, JSONValue, never>;
|
1358
1362
|
|
1363
|
+
/**
|
1364
|
+
* Appends a client message to the messages array.
|
1365
|
+
* If the last message in the array has the same id as the new message, it will be replaced.
|
1366
|
+
* Otherwise, the new message will be appended.
|
1367
|
+
*/
|
1368
|
+
declare function appendClientMessage({ messages, message, }: {
|
1369
|
+
messages: Message[];
|
1370
|
+
message: Message;
|
1371
|
+
}): Message[];
|
1372
|
+
|
1359
1373
|
type Parameters = z.ZodTypeAny | Schema<any>;
|
1360
1374
|
type inferParameters<PARAMETERS extends Parameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
|
1361
1375
|
interface ToolExecutionOptions {
|
@@ -1379,7 +1393,7 @@ This enables the language model to generate the input.
|
|
1379
1393
|
|
1380
1394
|
The tool can also contain an optional execute function for the actual execution function of the tool.
|
1381
1395
|
*/
|
1382
|
-
type
|
1396
|
+
type Tool<PARAMETERS extends Parameters = any, RESULT = any> = {
|
1383
1397
|
/**
|
1384
1398
|
The schema of the input that the tool expects. The language model will use this to generate the input.
|
1385
1399
|
It is also used to validate the output of the language model.
|
@@ -1421,30 +1435,24 @@ The arguments for configuring the tool. Must match the expected arguments define
|
|
1421
1435
|
*/
|
1422
1436
|
args: Record<string, unknown>;
|
1423
1437
|
});
|
1438
|
+
/**
|
1439
|
+
* @deprecated Use `Tool` instead.
|
1440
|
+
*/
|
1441
|
+
type CoreTool<PARAMETERS extends Parameters = any, RESULT = any> = Tool<PARAMETERS, RESULT>;
|
1424
1442
|
/**
|
1425
1443
|
Helper function for inferring the execute args of a tool.
|
1426
1444
|
*/
|
1427
|
-
declare function tool<PARAMETERS extends Parameters, RESULT>(tool:
|
1445
|
+
declare function tool<PARAMETERS extends Parameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
|
1428
1446
|
execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
1429
|
-
}):
|
1447
|
+
}): Tool<PARAMETERS, RESULT> & {
|
1430
1448
|
execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
1431
1449
|
};
|
1432
|
-
declare function tool<PARAMETERS extends Parameters, RESULT>(tool:
|
1450
|
+
declare function tool<PARAMETERS extends Parameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
|
1433
1451
|
execute?: undefined;
|
1434
|
-
}):
|
1452
|
+
}): Tool<PARAMETERS, RESULT> & {
|
1435
1453
|
execute: undefined;
|
1436
1454
|
};
|
1437
1455
|
|
1438
|
-
/**
|
1439
|
-
* Appends a client message to the messages array.
|
1440
|
-
* If the last message in the array has the same id as the new message, it will be replaced.
|
1441
|
-
* Otherwise, the new message will be appended.
|
1442
|
-
*/
|
1443
|
-
declare function appendClientMessage({ messages, message, }: {
|
1444
|
-
messages: Message[];
|
1445
|
-
message: Message;
|
1446
|
-
}): Message[];
|
1447
|
-
|
1448
1456
|
/**
|
1449
1457
|
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
1450
1458
|
|
@@ -1487,7 +1495,9 @@ onlyBar('bar');
|
|
1487
1495
|
*/
|
1488
1496
|
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
1489
1497
|
|
1490
|
-
type
|
1498
|
+
type ToolSet = Record<string, Tool>;
|
1499
|
+
|
1500
|
+
type ToolCallUnion<TOOLS extends ToolSet> = ValueOf<{
|
1491
1501
|
[NAME in keyof TOOLS]: {
|
1492
1502
|
type: 'tool-call';
|
1493
1503
|
toolCallId: string;
|
@@ -1495,17 +1505,21 @@ type ToolCallUnion<TOOLS extends Record<string, CoreTool>> = ValueOf<{
|
|
1495
1505
|
args: inferParameters<TOOLS[NAME]['parameters']>;
|
1496
1506
|
};
|
1497
1507
|
}>;
|
1498
|
-
|
1508
|
+
/**
|
1509
|
+
* @deprecated Use `ToolCallUnion` instead.
|
1510
|
+
*/
|
1511
|
+
type CoreToolCallUnion<TOOLS extends ToolSet> = ToolCallUnion<ToolSet>;
|
1512
|
+
type ToolCallArray<TOOLS extends ToolSet> = Array<ToolCallUnion<TOOLS>>;
|
1499
1513
|
|
1500
|
-
type ToToolsWithExecute<TOOLS extends
|
1514
|
+
type ToToolsWithExecute<TOOLS extends ToolSet> = {
|
1501
1515
|
[K in keyof TOOLS as TOOLS[K] extends {
|
1502
1516
|
execute: any;
|
1503
1517
|
} ? K : never]: TOOLS[K];
|
1504
1518
|
};
|
1505
|
-
type ToToolsWithDefinedExecute<TOOLS extends
|
1519
|
+
type ToToolsWithDefinedExecute<TOOLS extends ToolSet> = {
|
1506
1520
|
[K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
|
1507
1521
|
};
|
1508
|
-
type ToToolResultObject<TOOLS extends
|
1522
|
+
type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
|
1509
1523
|
[NAME in keyof TOOLS]: {
|
1510
1524
|
type: 'tool-result';
|
1511
1525
|
toolCallId: string;
|
@@ -1514,8 +1528,12 @@ type ToToolResultObject<TOOLS extends Record<string, CoreTool>> = ValueOf<{
|
|
1514
1528
|
result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
|
1515
1529
|
};
|
1516
1530
|
}>;
|
1517
|
-
type ToolResultUnion<TOOLS extends
|
1518
|
-
|
1531
|
+
type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
|
1532
|
+
/**
|
1533
|
+
* @deprecated Use `ToolResultUnion` instead.
|
1534
|
+
*/
|
1535
|
+
type CoreToolResultUnion<TOOLS extends ToolSet> = ToolResultUnion<TOOLS>;
|
1536
|
+
type ToolResultArray<TOOLS extends ToolSet> = Array<ToolResultUnion<TOOLS>>;
|
1519
1537
|
|
1520
1538
|
/**
|
1521
1539
|
A message that was generated during the generation process.
|
@@ -1530,7 +1548,7 @@ Message ID generated by the AI SDK.
|
|
1530
1548
|
/**
|
1531
1549
|
* The result of a single step in the generation process.
|
1532
1550
|
*/
|
1533
|
-
type StepResult<TOOLS extends
|
1551
|
+
type StepResult<TOOLS extends ToolSet> = {
|
1534
1552
|
/**
|
1535
1553
|
The generated text.
|
1536
1554
|
*/
|
@@ -1613,7 +1631,7 @@ declare function appendResponseMessages({ messages, responseMessages, }: {
|
|
1613
1631
|
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
1614
1632
|
with the AI core functions (e.g. `streamText`).
|
1615
1633
|
*/
|
1616
|
-
declare function convertToCoreMessages<TOOLS extends
|
1634
|
+
declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages: Array<UIMessage>, options?: {
|
1617
1635
|
tools?: TOOLS;
|
1618
1636
|
}): CoreMessage[];
|
1619
1637
|
|
@@ -1621,7 +1639,7 @@ declare function convertToCoreMessages<TOOLS extends Record<string, CoreTool> =
|
|
1621
1639
|
The result of a `generateText` call.
|
1622
1640
|
It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
|
1623
1641
|
*/
|
1624
|
-
interface GenerateTextResult<TOOLS extends
|
1642
|
+
interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
|
1625
1643
|
/**
|
1626
1644
|
The generated text.
|
1627
1645
|
*/
|
@@ -1771,7 +1789,7 @@ declare class NoSuchToolError extends AISDKError {
|
|
1771
1789
|
* @param options.parameterSchema - A function that returns the JSON Schema for a tool.
|
1772
1790
|
* @param options.error - The error that occurred while parsing the tool call.
|
1773
1791
|
*/
|
1774
|
-
type ToolCallRepairFunction<TOOLS extends
|
1792
|
+
type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
1775
1793
|
system: string | undefined;
|
1776
1794
|
messages: CoreMessage[];
|
1777
1795
|
toolCall: LanguageModelV1FunctionToolCall;
|
@@ -1829,7 +1847,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
1829
1847
|
@returns
|
1830
1848
|
A result object that contains the generated text, the results of the tool calls, and additional information.
|
1831
1849
|
*/
|
1832
|
-
declare function generateText<TOOLS extends
|
1850
|
+
declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
|
1833
1851
|
/**
|
1834
1852
|
The language model to use.
|
1835
1853
|
*/
|
@@ -1841,7 +1859,7 @@ The tools that the model can call. The model needs to support calling tools.
|
|
1841
1859
|
/**
|
1842
1860
|
The tool choice strategy. Default: 'auto'.
|
1843
1861
|
*/
|
1844
|
-
toolChoice?:
|
1862
|
+
toolChoice?: ToolChoice<TOOLS>;
|
1845
1863
|
/**
|
1846
1864
|
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
|
1847
1865
|
|
@@ -1916,7 +1934,7 @@ declare class StreamData {
|
|
1916
1934
|
/**
|
1917
1935
|
A result object for accessing different stream types and additional information.
|
1918
1936
|
*/
|
1919
|
-
interface StreamTextResult<TOOLS extends
|
1937
|
+
interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
1920
1938
|
/**
|
1921
1939
|
Warnings from the model provider (e.g. unsupported settings) for the first step.
|
1922
1940
|
*/
|
@@ -2087,7 +2105,7 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
|
|
2087
2105
|
*/
|
2088
2106
|
toTextStreamResponse(init?: ResponseInit): Response;
|
2089
2107
|
}
|
2090
|
-
type TextStreamPart<TOOLS extends
|
2108
|
+
type TextStreamPart<TOOLS extends ToolSet> = {
|
2091
2109
|
type: 'text-delta';
|
2092
2110
|
textDelta: string;
|
2093
2111
|
} | {
|
@@ -2148,7 +2166,7 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
|
|
2148
2166
|
*
|
2149
2167
|
* @returns A transform stream that smooths text streaming output.
|
2150
2168
|
*/
|
2151
|
-
declare function smoothStream<TOOLS extends
|
2169
|
+
declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
|
2152
2170
|
delayInMs?: number | null;
|
2153
2171
|
chunking?: 'word' | 'line' | RegExp;
|
2154
2172
|
/**
|
@@ -2167,7 +2185,7 @@ A transformation that is applied to the stream.
|
|
2167
2185
|
@param stopStream - A function that stops the source stream.
|
2168
2186
|
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2169
2187
|
*/
|
2170
|
-
type StreamTextTransform<TOOLS extends
|
2188
|
+
type StreamTextTransform<TOOLS extends ToolSet> = (options: {
|
2171
2189
|
tools: TOOLS;
|
2172
2190
|
stopStream: () => void;
|
2173
2191
|
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
@@ -2219,7 +2237,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
2219
2237
|
@return
|
2220
2238
|
A result object for accessing different stream types and additional information.
|
2221
2239
|
*/
|
2222
|
-
declare function streamText<TOOLS extends
|
2240
|
+
declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
2223
2241
|
/**
|
2224
2242
|
The language model to use.
|
2225
2243
|
*/
|
@@ -2231,7 +2249,7 @@ The tools that the model can call. The model needs to support calling tools.
|
|
2231
2249
|
/**
|
2232
2250
|
The tool choice strategy. Default: 'auto'.
|
2233
2251
|
*/
|
2234
|
-
toolChoice?:
|
2252
|
+
toolChoice?: ToolChoice<TOOLS>;
|
2235
2253
|
/**
|
2236
2254
|
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
|
2237
2255
|
|
@@ -2387,6 +2405,18 @@ declare const experimental_wrapLanguageModel: ({ model, middleware: { transformP
|
|
2387
2405
|
providerId?: string;
|
2388
2406
|
}) => LanguageModelV1;
|
2389
2407
|
|
2408
|
+
/**
|
2409
|
+
* Extract an XML-tagged reasoning section from the generated text and exposes it
|
2410
|
+
* as a `reasoning` property on the result.
|
2411
|
+
*
|
2412
|
+
* @param tagName - The name of the XML tag to extract reasoning from.
|
2413
|
+
* @param separator - The separator to use between reasoning and text sections.
|
2414
|
+
*/
|
2415
|
+
declare function extractReasoningMiddleware({ tagName, separator, }: {
|
2416
|
+
tagName: string;
|
2417
|
+
separator?: string;
|
2418
|
+
}): Experimental_LanguageModelV1Middleware;
|
2419
|
+
|
2390
2420
|
/**
|
2391
2421
|
* Creates a custom provider with specified language models, text embedding models, and an optional fallback provider.
|
2392
2422
|
*
|
@@ -2768,4 +2798,4 @@ declare namespace llamaindexAdapter {
|
|
2768
2798
|
};
|
2769
2799
|
}
|
2770
2800
|
|
2771
|
-
export { AssistantContent, AssistantResponse, CallWarning, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool,
|
2801
|
+
export { AssistantContent, AssistantResponse, CallWarning, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolCallUnion, CoreToolChoice, CoreToolMessage, CoreToolResultUnion, CoreUserMessage, DataContent, DataStreamWriter, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedImage as Experimental_GeneratedImage, Experimental_LanguageModelV1Middleware, FilePart, FinishReason, GenerateObjectResult, GenerateTextResult, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Provider, ProviderMetadata, RetryError, StepResult, StreamData, StreamObjectResult, StreamTextResult, StreamTextTransform, TelemetrySettings, TextPart, TextStreamPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolResultPart, ToolResultUnion, ToolSet, UserContent, appendClientMessage, appendResponseMessages, convertToCoreMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, experimental_wrapLanguageModel, extractReasoningMiddleware, generateObject, generateText, pipeDataStreamToResponse, simulateReadableStream, smoothStream, streamObject, streamText, tool };
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { IDGenerator } from '@ai-sdk/provider-utils';
|
2
|
-
export {
|
2
|
+
export { CoreToolCall, CoreToolResult, IDGenerator, ToolCall, ToolResult, createIdGenerator, generateId } from '@ai-sdk/provider-utils';
|
3
3
|
import { DataStreamString, ToolInvocation, Attachment, Schema, DeepPartial, Message, JSONValue as JSONValue$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
|
4
4
|
export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DataStreamPart, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, ToolInvocation, UseAssistantOptions, formatAssistantStreamPart, formatDataStreamPart, jsonSchema, parseAssistantStreamPart, parseDataStreamPart, processDataStream, processTextStream } from '@ai-sdk/ui-utils';
|
5
5
|
import { JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, LanguageModelV1CallOptions, AISDKError, LanguageModelV1FunctionToolCall, JSONSchema7, NoSuchModelError } from '@ai-sdk/provider';
|
@@ -150,10 +150,14 @@ Tool choice for the generation. It supports the following settings:
|
|
150
150
|
- `none`: the model must not call tools
|
151
151
|
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
152
152
|
*/
|
153
|
-
type
|
153
|
+
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
154
154
|
type: 'tool';
|
155
155
|
toolName: keyof TOOLS;
|
156
156
|
};
|
157
|
+
/**
|
158
|
+
* @deprecated Use `ToolChoice` instead.
|
159
|
+
*/
|
160
|
+
type CoreToolChoice<TOOLS extends Record<string, unknown>> = ToolChoice<TOOLS>;
|
157
161
|
|
158
162
|
type LanguageModelRequestMetadata = {
|
159
163
|
/**
|
@@ -1356,6 +1360,16 @@ Callback that is called when the LLM response and the final object validation ar
|
|
1356
1360
|
};
|
1357
1361
|
}): StreamObjectResult<JSONValue, JSONValue, never>;
|
1358
1362
|
|
1363
|
+
/**
|
1364
|
+
* Appends a client message to the messages array.
|
1365
|
+
* If the last message in the array has the same id as the new message, it will be replaced.
|
1366
|
+
* Otherwise, the new message will be appended.
|
1367
|
+
*/
|
1368
|
+
declare function appendClientMessage({ messages, message, }: {
|
1369
|
+
messages: Message[];
|
1370
|
+
message: Message;
|
1371
|
+
}): Message[];
|
1372
|
+
|
1359
1373
|
type Parameters = z.ZodTypeAny | Schema<any>;
|
1360
1374
|
type inferParameters<PARAMETERS extends Parameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
|
1361
1375
|
interface ToolExecutionOptions {
|
@@ -1379,7 +1393,7 @@ This enables the language model to generate the input.
|
|
1379
1393
|
|
1380
1394
|
The tool can also contain an optional execute function for the actual execution function of the tool.
|
1381
1395
|
*/
|
1382
|
-
type
|
1396
|
+
type Tool<PARAMETERS extends Parameters = any, RESULT = any> = {
|
1383
1397
|
/**
|
1384
1398
|
The schema of the input that the tool expects. The language model will use this to generate the input.
|
1385
1399
|
It is also used to validate the output of the language model.
|
@@ -1421,30 +1435,24 @@ The arguments for configuring the tool. Must match the expected arguments define
|
|
1421
1435
|
*/
|
1422
1436
|
args: Record<string, unknown>;
|
1423
1437
|
});
|
1438
|
+
/**
|
1439
|
+
* @deprecated Use `Tool` instead.
|
1440
|
+
*/
|
1441
|
+
type CoreTool<PARAMETERS extends Parameters = any, RESULT = any> = Tool<PARAMETERS, RESULT>;
|
1424
1442
|
/**
|
1425
1443
|
Helper function for inferring the execute args of a tool.
|
1426
1444
|
*/
|
1427
|
-
declare function tool<PARAMETERS extends Parameters, RESULT>(tool:
|
1445
|
+
declare function tool<PARAMETERS extends Parameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
|
1428
1446
|
execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
1429
|
-
}):
|
1447
|
+
}): Tool<PARAMETERS, RESULT> & {
|
1430
1448
|
execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
1431
1449
|
};
|
1432
|
-
declare function tool<PARAMETERS extends Parameters, RESULT>(tool:
|
1450
|
+
declare function tool<PARAMETERS extends Parameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
|
1433
1451
|
execute?: undefined;
|
1434
|
-
}):
|
1452
|
+
}): Tool<PARAMETERS, RESULT> & {
|
1435
1453
|
execute: undefined;
|
1436
1454
|
};
|
1437
1455
|
|
1438
|
-
/**
|
1439
|
-
* Appends a client message to the messages array.
|
1440
|
-
* If the last message in the array has the same id as the new message, it will be replaced.
|
1441
|
-
* Otherwise, the new message will be appended.
|
1442
|
-
*/
|
1443
|
-
declare function appendClientMessage({ messages, message, }: {
|
1444
|
-
messages: Message[];
|
1445
|
-
message: Message;
|
1446
|
-
}): Message[];
|
1447
|
-
|
1448
1456
|
/**
|
1449
1457
|
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
1450
1458
|
|
@@ -1487,7 +1495,9 @@ onlyBar('bar');
|
|
1487
1495
|
*/
|
1488
1496
|
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
1489
1497
|
|
1490
|
-
type
|
1498
|
+
type ToolSet = Record<string, Tool>;
|
1499
|
+
|
1500
|
+
type ToolCallUnion<TOOLS extends ToolSet> = ValueOf<{
|
1491
1501
|
[NAME in keyof TOOLS]: {
|
1492
1502
|
type: 'tool-call';
|
1493
1503
|
toolCallId: string;
|
@@ -1495,17 +1505,21 @@ type ToolCallUnion<TOOLS extends Record<string, CoreTool>> = ValueOf<{
|
|
1495
1505
|
args: inferParameters<TOOLS[NAME]['parameters']>;
|
1496
1506
|
};
|
1497
1507
|
}>;
|
1498
|
-
|
1508
|
+
/**
|
1509
|
+
* @deprecated Use `ToolCallUnion` instead.
|
1510
|
+
*/
|
1511
|
+
type CoreToolCallUnion<TOOLS extends ToolSet> = ToolCallUnion<ToolSet>;
|
1512
|
+
type ToolCallArray<TOOLS extends ToolSet> = Array<ToolCallUnion<TOOLS>>;
|
1499
1513
|
|
1500
|
-
type ToToolsWithExecute<TOOLS extends
|
1514
|
+
type ToToolsWithExecute<TOOLS extends ToolSet> = {
|
1501
1515
|
[K in keyof TOOLS as TOOLS[K] extends {
|
1502
1516
|
execute: any;
|
1503
1517
|
} ? K : never]: TOOLS[K];
|
1504
1518
|
};
|
1505
|
-
type ToToolsWithDefinedExecute<TOOLS extends
|
1519
|
+
type ToToolsWithDefinedExecute<TOOLS extends ToolSet> = {
|
1506
1520
|
[K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
|
1507
1521
|
};
|
1508
|
-
type ToToolResultObject<TOOLS extends
|
1522
|
+
type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
|
1509
1523
|
[NAME in keyof TOOLS]: {
|
1510
1524
|
type: 'tool-result';
|
1511
1525
|
toolCallId: string;
|
@@ -1514,8 +1528,12 @@ type ToToolResultObject<TOOLS extends Record<string, CoreTool>> = ValueOf<{
|
|
1514
1528
|
result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
|
1515
1529
|
};
|
1516
1530
|
}>;
|
1517
|
-
type ToolResultUnion<TOOLS extends
|
1518
|
-
|
1531
|
+
type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
|
1532
|
+
/**
|
1533
|
+
* @deprecated Use `ToolResultUnion` instead.
|
1534
|
+
*/
|
1535
|
+
type CoreToolResultUnion<TOOLS extends ToolSet> = ToolResultUnion<TOOLS>;
|
1536
|
+
type ToolResultArray<TOOLS extends ToolSet> = Array<ToolResultUnion<TOOLS>>;
|
1519
1537
|
|
1520
1538
|
/**
|
1521
1539
|
A message that was generated during the generation process.
|
@@ -1530,7 +1548,7 @@ Message ID generated by the AI SDK.
|
|
1530
1548
|
/**
|
1531
1549
|
* The result of a single step in the generation process.
|
1532
1550
|
*/
|
1533
|
-
type StepResult<TOOLS extends
|
1551
|
+
type StepResult<TOOLS extends ToolSet> = {
|
1534
1552
|
/**
|
1535
1553
|
The generated text.
|
1536
1554
|
*/
|
@@ -1613,7 +1631,7 @@ declare function appendResponseMessages({ messages, responseMessages, }: {
|
|
1613
1631
|
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
1614
1632
|
with the AI core functions (e.g. `streamText`).
|
1615
1633
|
*/
|
1616
|
-
declare function convertToCoreMessages<TOOLS extends
|
1634
|
+
declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages: Array<UIMessage>, options?: {
|
1617
1635
|
tools?: TOOLS;
|
1618
1636
|
}): CoreMessage[];
|
1619
1637
|
|
@@ -1621,7 +1639,7 @@ declare function convertToCoreMessages<TOOLS extends Record<string, CoreTool> =
|
|
1621
1639
|
The result of a `generateText` call.
|
1622
1640
|
It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
|
1623
1641
|
*/
|
1624
|
-
interface GenerateTextResult<TOOLS extends
|
1642
|
+
interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
|
1625
1643
|
/**
|
1626
1644
|
The generated text.
|
1627
1645
|
*/
|
@@ -1771,7 +1789,7 @@ declare class NoSuchToolError extends AISDKError {
|
|
1771
1789
|
* @param options.parameterSchema - A function that returns the JSON Schema for a tool.
|
1772
1790
|
* @param options.error - The error that occurred while parsing the tool call.
|
1773
1791
|
*/
|
1774
|
-
type ToolCallRepairFunction<TOOLS extends
|
1792
|
+
type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
1775
1793
|
system: string | undefined;
|
1776
1794
|
messages: CoreMessage[];
|
1777
1795
|
toolCall: LanguageModelV1FunctionToolCall;
|
@@ -1829,7 +1847,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
1829
1847
|
@returns
|
1830
1848
|
A result object that contains the generated text, the results of the tool calls, and additional information.
|
1831
1849
|
*/
|
1832
|
-
declare function generateText<TOOLS extends
|
1850
|
+
declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
|
1833
1851
|
/**
|
1834
1852
|
The language model to use.
|
1835
1853
|
*/
|
@@ -1841,7 +1859,7 @@ The tools that the model can call. The model needs to support calling tools.
|
|
1841
1859
|
/**
|
1842
1860
|
The tool choice strategy. Default: 'auto'.
|
1843
1861
|
*/
|
1844
|
-
toolChoice?:
|
1862
|
+
toolChoice?: ToolChoice<TOOLS>;
|
1845
1863
|
/**
|
1846
1864
|
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
|
1847
1865
|
|
@@ -1916,7 +1934,7 @@ declare class StreamData {
|
|
1916
1934
|
/**
|
1917
1935
|
A result object for accessing different stream types and additional information.
|
1918
1936
|
*/
|
1919
|
-
interface StreamTextResult<TOOLS extends
|
1937
|
+
interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
1920
1938
|
/**
|
1921
1939
|
Warnings from the model provider (e.g. unsupported settings) for the first step.
|
1922
1940
|
*/
|
@@ -2087,7 +2105,7 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
|
|
2087
2105
|
*/
|
2088
2106
|
toTextStreamResponse(init?: ResponseInit): Response;
|
2089
2107
|
}
|
2090
|
-
type TextStreamPart<TOOLS extends
|
2108
|
+
type TextStreamPart<TOOLS extends ToolSet> = {
|
2091
2109
|
type: 'text-delta';
|
2092
2110
|
textDelta: string;
|
2093
2111
|
} | {
|
@@ -2148,7 +2166,7 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
|
|
2148
2166
|
*
|
2149
2167
|
* @returns A transform stream that smooths text streaming output.
|
2150
2168
|
*/
|
2151
|
-
declare function smoothStream<TOOLS extends
|
2169
|
+
declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
|
2152
2170
|
delayInMs?: number | null;
|
2153
2171
|
chunking?: 'word' | 'line' | RegExp;
|
2154
2172
|
/**
|
@@ -2167,7 +2185,7 @@ A transformation that is applied to the stream.
|
|
2167
2185
|
@param stopStream - A function that stops the source stream.
|
2168
2186
|
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2169
2187
|
*/
|
2170
|
-
type StreamTextTransform<TOOLS extends
|
2188
|
+
type StreamTextTransform<TOOLS extends ToolSet> = (options: {
|
2171
2189
|
tools: TOOLS;
|
2172
2190
|
stopStream: () => void;
|
2173
2191
|
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
@@ -2219,7 +2237,7 @@ If set and supported by the model, calls will generate deterministic results.
|
|
2219
2237
|
@return
|
2220
2238
|
A result object for accessing different stream types and additional information.
|
2221
2239
|
*/
|
2222
|
-
declare function streamText<TOOLS extends
|
2240
|
+
declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
2223
2241
|
/**
|
2224
2242
|
The language model to use.
|
2225
2243
|
*/
|
@@ -2231,7 +2249,7 @@ The tools that the model can call. The model needs to support calling tools.
|
|
2231
2249
|
/**
|
2232
2250
|
The tool choice strategy. Default: 'auto'.
|
2233
2251
|
*/
|
2234
|
-
toolChoice?:
|
2252
|
+
toolChoice?: ToolChoice<TOOLS>;
|
2235
2253
|
/**
|
2236
2254
|
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
|
2237
2255
|
|
@@ -2387,6 +2405,18 @@ declare const experimental_wrapLanguageModel: ({ model, middleware: { transformP
|
|
2387
2405
|
providerId?: string;
|
2388
2406
|
}) => LanguageModelV1;
|
2389
2407
|
|
2408
|
+
/**
|
2409
|
+
* Extract an XML-tagged reasoning section from the generated text and exposes it
|
2410
|
+
* as a `reasoning` property on the result.
|
2411
|
+
*
|
2412
|
+
* @param tagName - The name of the XML tag to extract reasoning from.
|
2413
|
+
* @param separator - The separator to use between reasoning and text sections.
|
2414
|
+
*/
|
2415
|
+
declare function extractReasoningMiddleware({ tagName, separator, }: {
|
2416
|
+
tagName: string;
|
2417
|
+
separator?: string;
|
2418
|
+
}): Experimental_LanguageModelV1Middleware;
|
2419
|
+
|
2390
2420
|
/**
|
2391
2421
|
* Creates a custom provider with specified language models, text embedding models, and an optional fallback provider.
|
2392
2422
|
*
|
@@ -2768,4 +2798,4 @@ declare namespace llamaindexAdapter {
|
|
2768
2798
|
};
|
2769
2799
|
}
|
2770
2800
|
|
2771
|
-
export { AssistantContent, AssistantResponse, CallWarning, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool,
|
2801
|
+
export { AssistantContent, AssistantResponse, CallWarning, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolCallUnion, CoreToolChoice, CoreToolMessage, CoreToolResultUnion, CoreUserMessage, DataContent, DataStreamWriter, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedImage as Experimental_GeneratedImage, Experimental_LanguageModelV1Middleware, FilePart, FinishReason, GenerateObjectResult, GenerateTextResult, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Provider, ProviderMetadata, RetryError, StepResult, StreamData, StreamObjectResult, StreamTextResult, StreamTextTransform, TelemetrySettings, TextPart, TextStreamPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolResultPart, ToolResultUnion, ToolSet, UserContent, appendClientMessage, appendResponseMessages, convertToCoreMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, experimental_wrapLanguageModel, extractReasoningMiddleware, generateObject, generateText, pipeDataStreamToResponse, simulateReadableStream, smoothStream, streamObject, streamText, tool };
|