ai 6.0.0-beta.111 → 6.0.0-beta.113
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 +12 -0
- package/dist/index.d.mts +257 -234
- package/dist/index.d.ts +257 -234
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -3
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.0-beta.113
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 79a8e7f: feat(agent): support abortSignal in createAgentUIStream
|
|
8
|
+
|
|
9
|
+
## 6.0.0-beta.112
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- e06b663: feat(agent): support experimental stream transforms
|
|
14
|
+
|
|
3
15
|
## 6.0.0-beta.111
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -6,8 +6,8 @@ export { AssistantContent, AssistantModelMessage, DataContent, FilePart, Flexibl
|
|
|
6
6
|
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
7
7
|
import { EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV3Embedding, ImageModelV3, ImageModelV2, ImageModelV3CallWarning, ImageModelV2CallWarning, ImageModelV3ProviderMetadata, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV3, LanguageModelV2, LanguageModelV3FinishReason, LanguageModelV3CallWarning, LanguageModelV3Source, LanguageModelV3Middleware, EmbeddingModelV3Middleware, RerankingModelV3, SharedV3ProviderMetadata, SpeechModelV3, SpeechModelV2, SpeechModelV3CallWarning, TranscriptionModelV3, TranscriptionModelV2, TranscriptionModelV3CallWarning, LanguageModelV3Usage, ImageModelV3Usage, LanguageModelV3CallOptions, AISDKError, LanguageModelV3ToolCall, JSONSchema7, JSONParseError, TypeValidationError, JSONObject, SharedV3Warning, EmbeddingModelCallOptions, ProviderV3, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
|
8
8
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
|
9
|
-
import { ServerResponse } from 'node:http';
|
|
10
9
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
|
10
|
+
import { ServerResponse } from 'node:http';
|
|
11
11
|
import { ServerResponse as ServerResponse$1 } from 'http';
|
|
12
12
|
import { z } from 'zod/v4';
|
|
13
13
|
|
|
@@ -1338,236 +1338,6 @@ declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _int
|
|
|
1338
1338
|
tools: TOOLS;
|
|
1339
1339
|
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
|
1340
1340
|
|
|
1341
|
-
/**
|
|
1342
|
-
A transformation that is applied to the stream.
|
|
1343
|
-
|
|
1344
|
-
@param stopStream - A function that stops the source stream.
|
|
1345
|
-
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
|
1346
|
-
*/
|
|
1347
|
-
type StreamTextTransform<TOOLS extends ToolSet> = (options: {
|
|
1348
|
-
tools: TOOLS;
|
|
1349
|
-
stopStream: () => void;
|
|
1350
|
-
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
|
1351
|
-
/**
|
|
1352
|
-
Callback that is set using the `onError` option.
|
|
1353
|
-
|
|
1354
|
-
@param event - The event that is passed to the callback.
|
|
1355
|
-
*/
|
|
1356
|
-
type StreamTextOnErrorCallback = (event: {
|
|
1357
|
-
error: unknown;
|
|
1358
|
-
}) => PromiseLike<void> | void;
|
|
1359
|
-
/**
|
|
1360
|
-
Callback that is set using the `onStepFinish` option.
|
|
1361
|
-
|
|
1362
|
-
@param stepResult - The result of the step.
|
|
1363
|
-
*/
|
|
1364
|
-
type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => PromiseLike<void> | void;
|
|
1365
|
-
/**
|
|
1366
|
-
Callback that is set using the `onChunk` option.
|
|
1367
|
-
|
|
1368
|
-
@param event - The event that is passed to the callback.
|
|
1369
|
-
*/
|
|
1370
|
-
type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
|
|
1371
|
-
chunk: Extract<TextStreamPart<TOOLS>, {
|
|
1372
|
-
type: 'text-delta' | 'reasoning-delta' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
|
|
1373
|
-
}>;
|
|
1374
|
-
}) => PromiseLike<void> | void;
|
|
1375
|
-
/**
|
|
1376
|
-
Callback that is set using the `onFinish` option.
|
|
1377
|
-
|
|
1378
|
-
@param event - The event that is passed to the callback.
|
|
1379
|
-
*/
|
|
1380
|
-
type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
|
|
1381
|
-
/**
|
|
1382
|
-
Details for all steps.
|
|
1383
|
-
*/
|
|
1384
|
-
readonly steps: StepResult<TOOLS>[];
|
|
1385
|
-
/**
|
|
1386
|
-
Total usage for all steps. This is the sum of the usage of all steps.
|
|
1387
|
-
*/
|
|
1388
|
-
readonly totalUsage: LanguageModelUsage;
|
|
1389
|
-
}) => PromiseLike<void> | void;
|
|
1390
|
-
/**
|
|
1391
|
-
Callback that is set using the `onAbort` option.
|
|
1392
|
-
|
|
1393
|
-
@param event - The event that is passed to the callback.
|
|
1394
|
-
*/
|
|
1395
|
-
type StreamTextOnAbortCallback<TOOLS extends ToolSet> = (event: {
|
|
1396
|
-
/**
|
|
1397
|
-
Details for all previously finished steps.
|
|
1398
|
-
*/
|
|
1399
|
-
readonly steps: StepResult<TOOLS>[];
|
|
1400
|
-
}) => PromiseLike<void> | void;
|
|
1401
|
-
/**
|
|
1402
|
-
Generate a text and call tools for a given prompt using a language model.
|
|
1403
|
-
|
|
1404
|
-
This function streams the output. If you do not want to stream the output, use `generateText` instead.
|
|
1405
|
-
|
|
1406
|
-
@param model - The language model to use.
|
|
1407
|
-
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
|
1408
|
-
|
|
1409
|
-
@param system - A system message that will be part of the prompt.
|
|
1410
|
-
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
|
1411
|
-
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
|
1412
|
-
|
|
1413
|
-
@param maxOutputTokens - Maximum number of tokens to generate.
|
|
1414
|
-
@param temperature - Temperature setting.
|
|
1415
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
|
1416
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
|
1417
|
-
@param topP - Nucleus sampling.
|
|
1418
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
|
1419
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
|
1420
|
-
@param topK - Only sample from the top K options for each subsequent token.
|
|
1421
|
-
Used to remove "long tail" low probability responses.
|
|
1422
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
|
1423
|
-
@param presencePenalty - Presence penalty setting.
|
|
1424
|
-
It affects the likelihood of the model to repeat information that is already in the prompt.
|
|
1425
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
|
1426
|
-
@param frequencyPenalty - Frequency penalty setting.
|
|
1427
|
-
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
|
1428
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
|
1429
|
-
@param stopSequences - Stop sequences.
|
|
1430
|
-
If set, the model will stop generating text when one of the stop sequences is generated.
|
|
1431
|
-
@param seed - The seed (integer) to use for random sampling.
|
|
1432
|
-
If set and supported by the model, calls will generate deterministic results.
|
|
1433
|
-
|
|
1434
|
-
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
|
1435
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
|
1436
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
|
1437
|
-
|
|
1438
|
-
@param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
|
1439
|
-
@param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
|
|
1440
|
-
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
1441
|
-
@param onFinish - Callback that is called when all steps are finished and the response is complete.
|
|
1442
|
-
|
|
1443
|
-
@return
|
|
1444
|
-
A result object for accessing different stream types and additional information.
|
|
1445
|
-
*/
|
|
1446
|
-
declare function streamText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, experimental_context, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
|
1447
|
-
/**
|
|
1448
|
-
The language model to use.
|
|
1449
|
-
*/
|
|
1450
|
-
model: LanguageModel;
|
|
1451
|
-
/**
|
|
1452
|
-
The tools that the model can call. The model needs to support calling tools.
|
|
1453
|
-
*/
|
|
1454
|
-
tools?: TOOLS;
|
|
1455
|
-
/**
|
|
1456
|
-
The tool choice strategy. Default: 'auto'.
|
|
1457
|
-
*/
|
|
1458
|
-
toolChoice?: ToolChoice<TOOLS>;
|
|
1459
|
-
/**
|
|
1460
|
-
Condition for stopping the generation when there are tool results in the last step.
|
|
1461
|
-
When the condition is an array, any of the conditions can be met to stop the generation.
|
|
1462
|
-
|
|
1463
|
-
@default stepCountIs(1)
|
|
1464
|
-
*/
|
|
1465
|
-
stopWhen?: StopCondition<NoInfer<TOOLS>> | Array<StopCondition<NoInfer<TOOLS>>>;
|
|
1466
|
-
/**
|
|
1467
|
-
Optional telemetry configuration (experimental).
|
|
1468
|
-
*/
|
|
1469
|
-
experimental_telemetry?: TelemetrySettings;
|
|
1470
|
-
/**
|
|
1471
|
-
Additional provider-specific options. They are passed through
|
|
1472
|
-
to the provider from the AI SDK and enable provider-specific
|
|
1473
|
-
functionality that can be fully encapsulated in the provider.
|
|
1474
|
-
*/
|
|
1475
|
-
providerOptions?: ProviderOptions;
|
|
1476
|
-
/**
|
|
1477
|
-
* @deprecated Use `activeTools` instead.
|
|
1478
|
-
*/
|
|
1479
|
-
experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
1480
|
-
/**
|
|
1481
|
-
Limits the tools that are available for the model to call without
|
|
1482
|
-
changing the tool call and result types in the result.
|
|
1483
|
-
*/
|
|
1484
|
-
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
1485
|
-
/**
|
|
1486
|
-
Optional specification for parsing structured outputs from the LLM response.
|
|
1487
|
-
*/
|
|
1488
|
-
output?: OUTPUT;
|
|
1489
|
-
/**
|
|
1490
|
-
Optional specification for parsing structured outputs from the LLM response.
|
|
1491
|
-
|
|
1492
|
-
@deprecated Use `output` instead.
|
|
1493
|
-
*/
|
|
1494
|
-
experimental_output?: OUTPUT;
|
|
1495
|
-
/**
|
|
1496
|
-
Optional function that you can use to provide different settings for a step.
|
|
1497
|
-
|
|
1498
|
-
@param options - The options for the step.
|
|
1499
|
-
@param options.steps - The steps that have been executed so far.
|
|
1500
|
-
@param options.stepNumber - The number of the step that is being executed.
|
|
1501
|
-
@param options.model - The model that is being used.
|
|
1502
|
-
|
|
1503
|
-
@returns An object that contains the settings for the step.
|
|
1504
|
-
If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
1505
|
-
*/
|
|
1506
|
-
prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
|
|
1507
|
-
/**
|
|
1508
|
-
A function that attempts to repair a tool call that failed to parse.
|
|
1509
|
-
*/
|
|
1510
|
-
experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
|
1511
|
-
/**
|
|
1512
|
-
Optional stream transformations.
|
|
1513
|
-
They are applied in the order they are provided.
|
|
1514
|
-
The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
1515
|
-
*/
|
|
1516
|
-
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
1517
|
-
/**
|
|
1518
|
-
Custom download function to use for URLs.
|
|
1519
|
-
|
|
1520
|
-
By default, files are downloaded if the model does not support the URL for the given media type.
|
|
1521
|
-
*/
|
|
1522
|
-
experimental_download?: DownloadFunction | undefined;
|
|
1523
|
-
/**
|
|
1524
|
-
Whether to include raw chunks from the provider in the stream.
|
|
1525
|
-
When enabled, you will receive raw chunks with type 'raw' that contain the unprocessed data from the provider.
|
|
1526
|
-
This allows access to cutting-edge provider features not yet wrapped by the AI SDK.
|
|
1527
|
-
Defaults to false.
|
|
1528
|
-
*/
|
|
1529
|
-
includeRawChunks?: boolean;
|
|
1530
|
-
/**
|
|
1531
|
-
Callback that is called for each chunk of the stream.
|
|
1532
|
-
The stream processing will pause until the callback promise is resolved.
|
|
1533
|
-
*/
|
|
1534
|
-
onChunk?: StreamTextOnChunkCallback<TOOLS>;
|
|
1535
|
-
/**
|
|
1536
|
-
Callback that is invoked when an error occurs during streaming.
|
|
1537
|
-
You can use it to log errors.
|
|
1538
|
-
The stream processing will pause until the callback promise is resolved.
|
|
1539
|
-
*/
|
|
1540
|
-
onError?: StreamTextOnErrorCallback;
|
|
1541
|
-
/**
|
|
1542
|
-
Callback that is called when the LLM response and all request tool executions
|
|
1543
|
-
(for tools that have an `execute` function) are finished.
|
|
1544
|
-
|
|
1545
|
-
The usage is the combined usage of all steps.
|
|
1546
|
-
*/
|
|
1547
|
-
onFinish?: StreamTextOnFinishCallback<TOOLS>;
|
|
1548
|
-
onAbort?: StreamTextOnAbortCallback<TOOLS>;
|
|
1549
|
-
/**
|
|
1550
|
-
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
1551
|
-
*/
|
|
1552
|
-
onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
|
|
1553
|
-
/**
|
|
1554
|
-
* Context that is passed into tool execution.
|
|
1555
|
-
*
|
|
1556
|
-
* Experimental (can break in patch releases).
|
|
1557
|
-
*
|
|
1558
|
-
* @default undefined
|
|
1559
|
-
*/
|
|
1560
|
-
experimental_context?: unknown;
|
|
1561
|
-
/**
|
|
1562
|
-
Internal. For test use only. May change without notice.
|
|
1563
|
-
*/
|
|
1564
|
-
_internal?: {
|
|
1565
|
-
now?: () => number;
|
|
1566
|
-
generateId?: IdGenerator;
|
|
1567
|
-
currentDate?: () => Date;
|
|
1568
|
-
};
|
|
1569
|
-
}): StreamTextResult<TOOLS, OUTPUT>;
|
|
1570
|
-
|
|
1571
1341
|
/**
|
|
1572
1342
|
* Tool output when the tool execution has been denied (for static tools).
|
|
1573
1343
|
*/
|
|
@@ -2569,6 +2339,239 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
|
2569
2339
|
rawValue: unknown;
|
|
2570
2340
|
};
|
|
2571
2341
|
|
|
2342
|
+
/**
|
|
2343
|
+
A transformation that is applied to the stream.
|
|
2344
|
+
|
|
2345
|
+
@param stopStream - A function that stops the source stream.
|
|
2346
|
+
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
|
2347
|
+
*/
|
|
2348
|
+
type StreamTextTransform<TOOLS extends ToolSet> = (options: {
|
|
2349
|
+
tools: TOOLS;
|
|
2350
|
+
stopStream: () => void;
|
|
2351
|
+
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
|
2352
|
+
/**
|
|
2353
|
+
Callback that is set using the `onError` option.
|
|
2354
|
+
|
|
2355
|
+
@param event - The event that is passed to the callback.
|
|
2356
|
+
*/
|
|
2357
|
+
type StreamTextOnErrorCallback = (event: {
|
|
2358
|
+
error: unknown;
|
|
2359
|
+
}) => PromiseLike<void> | void;
|
|
2360
|
+
/**
|
|
2361
|
+
Callback that is set using the `onStepFinish` option.
|
|
2362
|
+
|
|
2363
|
+
@param stepResult - The result of the step.
|
|
2364
|
+
*/
|
|
2365
|
+
type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => PromiseLike<void> | void;
|
|
2366
|
+
/**
|
|
2367
|
+
Callback that is set using the `onChunk` option.
|
|
2368
|
+
|
|
2369
|
+
@param event - The event that is passed to the callback.
|
|
2370
|
+
*/
|
|
2371
|
+
type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
|
|
2372
|
+
chunk: Extract<TextStreamPart<TOOLS>, {
|
|
2373
|
+
type: 'text-delta' | 'reasoning-delta' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
|
|
2374
|
+
}>;
|
|
2375
|
+
}) => PromiseLike<void> | void;
|
|
2376
|
+
/**
|
|
2377
|
+
Callback that is set using the `onFinish` option.
|
|
2378
|
+
|
|
2379
|
+
@param event - The event that is passed to the callback.
|
|
2380
|
+
*/
|
|
2381
|
+
type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
|
|
2382
|
+
/**
|
|
2383
|
+
Details for all steps.
|
|
2384
|
+
*/
|
|
2385
|
+
readonly steps: StepResult<TOOLS>[];
|
|
2386
|
+
/**
|
|
2387
|
+
Total usage for all steps. This is the sum of the usage of all steps.
|
|
2388
|
+
*/
|
|
2389
|
+
readonly totalUsage: LanguageModelUsage;
|
|
2390
|
+
}) => PromiseLike<void> | void;
|
|
2391
|
+
/**
|
|
2392
|
+
Callback that is set using the `onAbort` option.
|
|
2393
|
+
|
|
2394
|
+
@param event - The event that is passed to the callback.
|
|
2395
|
+
*/
|
|
2396
|
+
type StreamTextOnAbortCallback<TOOLS extends ToolSet> = (event: {
|
|
2397
|
+
/**
|
|
2398
|
+
Details for all previously finished steps.
|
|
2399
|
+
*/
|
|
2400
|
+
readonly steps: StepResult<TOOLS>[];
|
|
2401
|
+
}) => PromiseLike<void> | void;
|
|
2402
|
+
/**
|
|
2403
|
+
Generate a text and call tools for a given prompt using a language model.
|
|
2404
|
+
|
|
2405
|
+
This function streams the output. If you do not want to stream the output, use `generateText` instead.
|
|
2406
|
+
|
|
2407
|
+
@param model - The language model to use.
|
|
2408
|
+
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
|
2409
|
+
|
|
2410
|
+
@param system - A system message that will be part of the prompt.
|
|
2411
|
+
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
|
2412
|
+
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
|
2413
|
+
|
|
2414
|
+
@param maxOutputTokens - Maximum number of tokens to generate.
|
|
2415
|
+
@param temperature - Temperature setting.
|
|
2416
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
|
2417
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
|
2418
|
+
@param topP - Nucleus sampling.
|
|
2419
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
|
2420
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
|
2421
|
+
@param topK - Only sample from the top K options for each subsequent token.
|
|
2422
|
+
Used to remove "long tail" low probability responses.
|
|
2423
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
|
2424
|
+
@param presencePenalty - Presence penalty setting.
|
|
2425
|
+
It affects the likelihood of the model to repeat information that is already in the prompt.
|
|
2426
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
|
2427
|
+
@param frequencyPenalty - Frequency penalty setting.
|
|
2428
|
+
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
|
2429
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
|
2430
|
+
@param stopSequences - Stop sequences.
|
|
2431
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
|
2432
|
+
@param seed - The seed (integer) to use for random sampling.
|
|
2433
|
+
If set and supported by the model, calls will generate deterministic results.
|
|
2434
|
+
|
|
2435
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
|
2436
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
|
2437
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
|
2438
|
+
|
|
2439
|
+
@param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
|
2440
|
+
@param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
|
|
2441
|
+
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
2442
|
+
@param onFinish - Callback that is called when all steps are finished and the response is complete.
|
|
2443
|
+
|
|
2444
|
+
@return
|
|
2445
|
+
A result object for accessing different stream types and additional information.
|
|
2446
|
+
*/
|
|
2447
|
+
declare function streamText<TOOLS extends ToolSet, OUTPUT extends Output = Output<string, string>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output, output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, experimental_context, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
|
2448
|
+
/**
|
|
2449
|
+
The language model to use.
|
|
2450
|
+
*/
|
|
2451
|
+
model: LanguageModel;
|
|
2452
|
+
/**
|
|
2453
|
+
The tools that the model can call. The model needs to support calling tools.
|
|
2454
|
+
*/
|
|
2455
|
+
tools?: TOOLS;
|
|
2456
|
+
/**
|
|
2457
|
+
The tool choice strategy. Default: 'auto'.
|
|
2458
|
+
*/
|
|
2459
|
+
toolChoice?: ToolChoice<TOOLS>;
|
|
2460
|
+
/**
|
|
2461
|
+
Condition for stopping the generation when there are tool results in the last step.
|
|
2462
|
+
When the condition is an array, any of the conditions can be met to stop the generation.
|
|
2463
|
+
|
|
2464
|
+
@default stepCountIs(1)
|
|
2465
|
+
*/
|
|
2466
|
+
stopWhen?: StopCondition<NoInfer<TOOLS>> | Array<StopCondition<NoInfer<TOOLS>>>;
|
|
2467
|
+
/**
|
|
2468
|
+
Optional telemetry configuration (experimental).
|
|
2469
|
+
*/
|
|
2470
|
+
experimental_telemetry?: TelemetrySettings;
|
|
2471
|
+
/**
|
|
2472
|
+
Additional provider-specific options. They are passed through
|
|
2473
|
+
to the provider from the AI SDK and enable provider-specific
|
|
2474
|
+
functionality that can be fully encapsulated in the provider.
|
|
2475
|
+
*/
|
|
2476
|
+
providerOptions?: ProviderOptions;
|
|
2477
|
+
/**
|
|
2478
|
+
* @deprecated Use `activeTools` instead.
|
|
2479
|
+
*/
|
|
2480
|
+
experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
2481
|
+
/**
|
|
2482
|
+
Limits the tools that are available for the model to call without
|
|
2483
|
+
changing the tool call and result types in the result.
|
|
2484
|
+
*/
|
|
2485
|
+
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
2486
|
+
/**
|
|
2487
|
+
Optional specification for parsing structured outputs from the LLM response.
|
|
2488
|
+
*/
|
|
2489
|
+
output?: OUTPUT;
|
|
2490
|
+
/**
|
|
2491
|
+
Optional specification for parsing structured outputs from the LLM response.
|
|
2492
|
+
|
|
2493
|
+
@deprecated Use `output` instead.
|
|
2494
|
+
*/
|
|
2495
|
+
experimental_output?: OUTPUT;
|
|
2496
|
+
/**
|
|
2497
|
+
Optional function that you can use to provide different settings for a step.
|
|
2498
|
+
|
|
2499
|
+
@param options - The options for the step.
|
|
2500
|
+
@param options.steps - The steps that have been executed so far.
|
|
2501
|
+
@param options.stepNumber - The number of the step that is being executed.
|
|
2502
|
+
@param options.model - The model that is being used.
|
|
2503
|
+
|
|
2504
|
+
@returns An object that contains the settings for the step.
|
|
2505
|
+
If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
2506
|
+
*/
|
|
2507
|
+
prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
|
|
2508
|
+
/**
|
|
2509
|
+
A function that attempts to repair a tool call that failed to parse.
|
|
2510
|
+
*/
|
|
2511
|
+
experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
|
2512
|
+
/**
|
|
2513
|
+
Optional stream transformations.
|
|
2514
|
+
They are applied in the order they are provided.
|
|
2515
|
+
The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
2516
|
+
*/
|
|
2517
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
2518
|
+
/**
|
|
2519
|
+
Custom download function to use for URLs.
|
|
2520
|
+
|
|
2521
|
+
By default, files are downloaded if the model does not support the URL for the given media type.
|
|
2522
|
+
*/
|
|
2523
|
+
experimental_download?: DownloadFunction | undefined;
|
|
2524
|
+
/**
|
|
2525
|
+
Whether to include raw chunks from the provider in the stream.
|
|
2526
|
+
When enabled, you will receive raw chunks with type 'raw' that contain the unprocessed data from the provider.
|
|
2527
|
+
This allows access to cutting-edge provider features not yet wrapped by the AI SDK.
|
|
2528
|
+
Defaults to false.
|
|
2529
|
+
*/
|
|
2530
|
+
includeRawChunks?: boolean;
|
|
2531
|
+
/**
|
|
2532
|
+
Callback that is called for each chunk of the stream.
|
|
2533
|
+
The stream processing will pause until the callback promise is resolved.
|
|
2534
|
+
*/
|
|
2535
|
+
onChunk?: StreamTextOnChunkCallback<TOOLS>;
|
|
2536
|
+
/**
|
|
2537
|
+
Callback that is invoked when an error occurs during streaming.
|
|
2538
|
+
You can use it to log errors.
|
|
2539
|
+
The stream processing will pause until the callback promise is resolved.
|
|
2540
|
+
*/
|
|
2541
|
+
onError?: StreamTextOnErrorCallback;
|
|
2542
|
+
/**
|
|
2543
|
+
Callback that is called when the LLM response and all request tool executions
|
|
2544
|
+
(for tools that have an `execute` function) are finished.
|
|
2545
|
+
|
|
2546
|
+
The usage is the combined usage of all steps.
|
|
2547
|
+
*/
|
|
2548
|
+
onFinish?: StreamTextOnFinishCallback<TOOLS>;
|
|
2549
|
+
onAbort?: StreamTextOnAbortCallback<TOOLS>;
|
|
2550
|
+
/**
|
|
2551
|
+
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
2552
|
+
*/
|
|
2553
|
+
onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
|
|
2554
|
+
/**
|
|
2555
|
+
* Context that is passed into tool execution.
|
|
2556
|
+
*
|
|
2557
|
+
* Experimental (can break in patch releases).
|
|
2558
|
+
*
|
|
2559
|
+
* @default undefined
|
|
2560
|
+
*/
|
|
2561
|
+
experimental_context?: unknown;
|
|
2562
|
+
/**
|
|
2563
|
+
Internal. For test use only. May change without notice.
|
|
2564
|
+
*/
|
|
2565
|
+
_internal?: {
|
|
2566
|
+
now?: () => number;
|
|
2567
|
+
generateId?: IdGenerator;
|
|
2568
|
+
currentDate?: () => Date;
|
|
2569
|
+
};
|
|
2570
|
+
}): StreamTextResult<TOOLS, OUTPUT>;
|
|
2571
|
+
|
|
2572
|
+
/**
|
|
2573
|
+
* Parameters for calling an agent.
|
|
2574
|
+
*/
|
|
2572
2575
|
type AgentCallParameters<CALL_OPTIONS> = ([CALL_OPTIONS] extends [never] ? {
|
|
2573
2576
|
options?: never;
|
|
2574
2577
|
} : {
|
|
@@ -2605,6 +2608,17 @@ type AgentCallParameters<CALL_OPTIONS> = ([CALL_OPTIONS] extends [never] ? {
|
|
|
2605
2608
|
*/
|
|
2606
2609
|
abortSignal?: AbortSignal;
|
|
2607
2610
|
};
|
|
2611
|
+
/**
|
|
2612
|
+
* Parameters for streaming an output from an agent.
|
|
2613
|
+
*/
|
|
2614
|
+
type AgentStreamParameters<CALL_OPTIONS, TOOLS extends ToolSet> = AgentCallParameters<CALL_OPTIONS> & {
|
|
2615
|
+
/**
|
|
2616
|
+
* Optional stream transformations.
|
|
2617
|
+
* They are applied in the order they are provided.
|
|
2618
|
+
* The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
2619
|
+
*/
|
|
2620
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
2621
|
+
};
|
|
2608
2622
|
/**
|
|
2609
2623
|
* An Agent receives a prompt (text or messages) and generates or streams an output
|
|
2610
2624
|
* that consists of steps, tool calls, data parts, etc.
|
|
@@ -2633,7 +2647,7 @@ interface Agent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends
|
|
|
2633
2647
|
/**
|
|
2634
2648
|
* Streams an output from the agent (streaming).
|
|
2635
2649
|
*/
|
|
2636
|
-
stream(options:
|
|
2650
|
+
stream(options: AgentStreamParameters<CALL_OPTIONS, TOOLS>): PromiseLike<StreamTextResult<TOOLS, OUTPUT>>;
|
|
2637
2651
|
}
|
|
2638
2652
|
|
|
2639
2653
|
/**
|
|
@@ -2776,7 +2790,7 @@ declare class ToolLoopAgent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OU
|
|
|
2776
2790
|
/**
|
|
2777
2791
|
* Streams an output from the agent (streaming).
|
|
2778
2792
|
*/
|
|
2779
|
-
stream({ abortSignal, ...options }:
|
|
2793
|
+
stream({ abortSignal, experimental_transform, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
|
|
2780
2794
|
}
|
|
2781
2795
|
|
|
2782
2796
|
/**
|
|
@@ -2800,7 +2814,9 @@ type InferAgentUIMessage<AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_
|
|
|
2800
2814
|
declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ headers, status, statusText, consumeSseStream, ...options }: {
|
|
2801
2815
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
2802
2816
|
messages: unknown[];
|
|
2817
|
+
abortSignal?: AbortSignal;
|
|
2803
2818
|
options?: CALL_OPTIONS;
|
|
2819
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
2804
2820
|
} & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<Response>;
|
|
2805
2821
|
|
|
2806
2822
|
declare const getOriginalFetch: () => typeof fetch;
|
|
@@ -3466,13 +3482,18 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
|
|
|
3466
3482
|
*
|
|
3467
3483
|
* @param agent - The agent to run.
|
|
3468
3484
|
* @param messages - The input UI messages.
|
|
3485
|
+
* @param abortSignal - The abort signal. Optional.
|
|
3486
|
+
* @param options - The options for the agent.
|
|
3487
|
+
* @param experimental_transform - The stream transformations. Optional.
|
|
3469
3488
|
*
|
|
3470
3489
|
* @returns The UI message stream.
|
|
3471
3490
|
*/
|
|
3472
|
-
declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, messages, options, ...uiMessageStreamOptions }: {
|
|
3491
|
+
declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, messages, options, abortSignal, experimental_transform, ...uiMessageStreamOptions }: {
|
|
3473
3492
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3474
3493
|
messages: unknown[];
|
|
3494
|
+
abortSignal?: AbortSignal;
|
|
3475
3495
|
options?: CALL_OPTIONS;
|
|
3496
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3476
3497
|
} & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<AsyncIterableStream<InferUIMessageChunk<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>>>;
|
|
3477
3498
|
|
|
3478
3499
|
/**
|
|
@@ -3485,7 +3506,9 @@ declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends
|
|
|
3485
3506
|
response: ServerResponse;
|
|
3486
3507
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3487
3508
|
messages: unknown[];
|
|
3509
|
+
abortSignal?: AbortSignal;
|
|
3488
3510
|
options?: CALL_OPTIONS;
|
|
3511
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3489
3512
|
} & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<void>;
|
|
3490
3513
|
|
|
3491
3514
|
/**
|