ai 5.0.0-beta.6 → 5.0.0-beta.8
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 +1965 -1883
- package/dist/index.d.ts +1965 -1883
- package/dist/index.js +7371 -7340
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7398 -7368
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
@@ -1,27 +1,108 @@
|
|
1
|
-
import {
|
1
|
+
import { ModelMessage, Tool, InferToolInput, InferToolOutput, AssistantModelMessage, ToolModelMessage, ReasoningPart, Schema, SystemModelMessage, UserModelMessage, ProviderOptions, IdGenerator, Validator, StandardSchemaV1, ToolCall, FetchFunction, InferSchema, FlexibleSchema, DataContent } from '@ai-sdk/provider-utils';
|
2
2
|
export { AssistantContent, AssistantModelMessage, DataContent, FilePart, IdGenerator, ImagePart, InferToolInput, InferToolOutput, ModelMessage, Schema, SystemModelMessage, TextPart, Tool, ToolCallOptions, ToolCallPart, ToolContent, ToolExecuteFunction, ToolModelMessage, ToolResultPart, UserContent, UserModelMessage, asSchema, createIdGenerator, generateId, jsonSchema, tool } from '@ai-sdk/provider-utils';
|
3
|
-
import {
|
3
|
+
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
4
|
+
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SpeechModelV2, SpeechModelV2CallWarning, TranscriptionModelV2, TranscriptionModelV2CallWarning, LanguageModelV2Usage, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError, JSONObject } from '@ai-sdk/provider';
|
4
5
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
5
6
|
import * as z3 from 'zod/v3';
|
6
|
-
import * as z4 from 'zod/v4/core';
|
7
|
-
import { ServerResponse } from 'node:http';
|
8
|
-
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
9
7
|
import * as z4$1 from 'zod/v4';
|
10
8
|
import { z } from 'zod/v4';
|
9
|
+
import * as z4 from 'zod/v4/core';
|
10
|
+
import { ServerResponse } from 'node:http';
|
11
11
|
import { ServerResponse as ServerResponse$1 } from 'http';
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
13
|
+
type CallSettings = {
|
14
|
+
/**
|
15
|
+
Maximum number of tokens to generate.
|
16
|
+
*/
|
17
|
+
maxOutputTokens?: number;
|
18
|
+
/**
|
19
|
+
Temperature setting. The range depends on the provider and model.
|
20
|
+
|
21
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
22
|
+
*/
|
23
|
+
temperature?: number;
|
24
|
+
/**
|
25
|
+
Nucleus sampling. This is a number between 0 and 1.
|
26
|
+
|
27
|
+
E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
28
|
+
are considered.
|
29
|
+
|
30
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
31
|
+
*/
|
32
|
+
topP?: number;
|
33
|
+
/**
|
34
|
+
Only sample from the top K options for each subsequent token.
|
35
|
+
|
36
|
+
Used to remove "long tail" low probability responses.
|
37
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
38
|
+
*/
|
39
|
+
topK?: number;
|
40
|
+
/**
|
41
|
+
Presence penalty setting. It affects the likelihood of the model to
|
42
|
+
repeat information that is already in the prompt.
|
43
|
+
|
44
|
+
The presence penalty is a number between -1 (increase repetition)
|
45
|
+
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
46
|
+
*/
|
47
|
+
presencePenalty?: number;
|
48
|
+
/**
|
49
|
+
Frequency penalty setting. It affects the likelihood of the model
|
50
|
+
to repeatedly use the same words or phrases.
|
51
|
+
|
52
|
+
The frequency penalty is a number between -1 (increase repetition)
|
53
|
+
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
54
|
+
*/
|
55
|
+
frequencyPenalty?: number;
|
56
|
+
/**
|
57
|
+
Stop sequences.
|
58
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
59
|
+
Providers may have limits on the number of stop sequences.
|
60
|
+
*/
|
61
|
+
stopSequences?: string[];
|
62
|
+
/**
|
63
|
+
The seed (integer) to use for random sampling. If set and supported
|
64
|
+
by the model, calls will generate deterministic results.
|
65
|
+
*/
|
66
|
+
seed?: number;
|
67
|
+
/**
|
68
|
+
Maximum number of retries. Set to 0 to disable retries.
|
69
|
+
|
70
|
+
@default 2
|
71
|
+
*/
|
72
|
+
maxRetries?: number;
|
73
|
+
/**
|
74
|
+
Abort signal.
|
75
|
+
*/
|
76
|
+
abortSignal?: AbortSignal;
|
77
|
+
/**
|
78
|
+
Additional HTTP headers to be sent with the request.
|
79
|
+
Only applicable for HTTP-based providers.
|
80
|
+
*/
|
81
|
+
headers?: Record<string, string | undefined>;
|
82
|
+
};
|
83
|
+
|
84
|
+
/**
|
85
|
+
Prompt part of the AI function options.
|
86
|
+
It contains a system message, a simple text prompt, or a list of messages.
|
87
|
+
*/
|
88
|
+
type Prompt = {
|
89
|
+
/**
|
90
|
+
System message to include in the prompt. Can be used with `prompt` or `messages`.
|
91
|
+
*/
|
92
|
+
system?: string;
|
93
|
+
/**
|
94
|
+
A prompt. It can be either a text prompt or a list of messages.
|
95
|
+
|
96
|
+
You can either use `prompt` or `messages` but not both.
|
97
|
+
*/
|
98
|
+
prompt?: string | Array<ModelMessage>;
|
99
|
+
/**
|
100
|
+
A list of messages.
|
101
|
+
|
102
|
+
You can either use `prompt` or `messages` but not both.
|
103
|
+
*/
|
104
|
+
messages?: Array<ModelMessage>;
|
105
|
+
};
|
25
106
|
|
26
107
|
/**
|
27
108
|
* Telemetry configuration.
|
@@ -296,190 +377,448 @@ interface GeneratedFile {
|
|
296
377
|
readonly mediaType: string;
|
297
378
|
}
|
298
379
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
380
|
+
/**
|
381
|
+
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
382
|
+
|
383
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
384
|
+
|
385
|
+
@example
|
386
|
+
```
|
387
|
+
// data.json
|
388
|
+
{
|
389
|
+
'foo': 1,
|
390
|
+
'bar': 2,
|
391
|
+
'biz': 3
|
311
392
|
}
|
312
393
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
toolName: string;
|
320
|
-
availableTools?: string[] | undefined;
|
321
|
-
message?: string;
|
322
|
-
});
|
323
|
-
static isInstance(error: unknown): error is NoSuchToolError;
|
394
|
+
// main.ts
|
395
|
+
import type {ValueOf} from 'type-fest';
|
396
|
+
import data = require('./data.json');
|
397
|
+
|
398
|
+
export function getData(name: string): ValueOf<typeof data> {
|
399
|
+
return data[name];
|
324
400
|
}
|
325
401
|
|
326
|
-
|
402
|
+
export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
403
|
+
return data[name];
|
404
|
+
}
|
405
|
+
|
406
|
+
// file.ts
|
407
|
+
import {getData, onlyBar} from './main';
|
408
|
+
|
409
|
+
getData('foo');
|
410
|
+
//=> 1
|
411
|
+
|
412
|
+
onlyBar('foo');
|
413
|
+
//=> TypeError ...
|
414
|
+
|
415
|
+
onlyBar('bar');
|
416
|
+
//=> 2
|
417
|
+
```
|
418
|
+
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
419
|
+
*/
|
420
|
+
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
421
|
+
|
422
|
+
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta'>>;
|
423
|
+
|
424
|
+
type ToolCallUnion<TOOLS extends ToolSet> = ValueOf<{
|
425
|
+
[NAME in keyof TOOLS]: {
|
426
|
+
type: 'tool-call';
|
427
|
+
toolCallId: string;
|
428
|
+
toolName: NAME & string;
|
429
|
+
input: TOOLS[NAME] extends Tool<infer PARAMETERS> ? PARAMETERS : never;
|
430
|
+
providerExecuted?: boolean;
|
431
|
+
};
|
432
|
+
}>;
|
433
|
+
type ToolCallArray<TOOLS extends ToolSet> = Array<ToolCallUnion<TOOLS>>;
|
434
|
+
|
435
|
+
type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
|
436
|
+
[NAME in keyof TOOLS]: {
|
437
|
+
type: 'tool-result';
|
438
|
+
toolCallId: string;
|
439
|
+
toolName: NAME & string;
|
440
|
+
input: InferToolInput<TOOLS[NAME]>;
|
441
|
+
output: InferToolOutput<TOOLS[NAME]>;
|
442
|
+
providerExecuted?: boolean;
|
443
|
+
};
|
444
|
+
}>;
|
445
|
+
type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<TOOLS>;
|
446
|
+
type ToolResultArray<TOOLS extends ToolSet> = Array<ToolResultUnion<TOOLS>>;
|
447
|
+
type ToToolErrorObject<TOOLS extends ToolSet> = ValueOf<{
|
448
|
+
[NAME in keyof TOOLS]: {
|
449
|
+
type: 'tool-error';
|
450
|
+
toolCallId: string;
|
451
|
+
toolName: NAME & string;
|
452
|
+
input: InferToolInput<TOOLS[NAME]>;
|
453
|
+
error: unknown;
|
454
|
+
providerExecuted?: boolean;
|
455
|
+
};
|
456
|
+
}>;
|
457
|
+
type ToolErrorUnion<TOOLS extends ToolSet> = ToToolErrorObject<TOOLS>;
|
458
|
+
|
459
|
+
type ContentPart<TOOLS extends ToolSet> = {
|
460
|
+
type: 'text';
|
461
|
+
text: string;
|
462
|
+
} | {
|
463
|
+
type: 'reasoning';
|
464
|
+
text: string;
|
465
|
+
providerMetadata?: ProviderMetadata;
|
466
|
+
} | ({
|
467
|
+
type: 'source';
|
468
|
+
} & Source) | {
|
469
|
+
type: 'file';
|
470
|
+
file: GeneratedFile;
|
471
|
+
} | ({
|
472
|
+
type: 'tool-call';
|
473
|
+
} & ToolCallUnion<TOOLS>) | ({
|
474
|
+
type: 'tool-result';
|
475
|
+
} & ToolResultUnion<TOOLS>) | ({
|
476
|
+
type: 'tool-error';
|
477
|
+
} & ToolErrorUnion<TOOLS>);
|
478
|
+
|
479
|
+
/**
|
480
|
+
A message that was generated during the generation process.
|
481
|
+
It can be either an assistant message or a tool message.
|
482
|
+
*/
|
483
|
+
type ResponseMessage = AssistantModelMessage | ToolModelMessage;
|
484
|
+
|
485
|
+
/**
|
486
|
+
* The result of a single step in the generation process.
|
487
|
+
*/
|
488
|
+
type StepResult<TOOLS extends ToolSet> = {
|
327
489
|
/**
|
328
|
-
|
490
|
+
The content that was generated in the last step.
|
329
491
|
*/
|
330
|
-
|
492
|
+
readonly content: Array<ContentPart<TOOLS>>;
|
331
493
|
/**
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
*/
|
336
|
-
temperature?: number;
|
494
|
+
The generated text.
|
495
|
+
*/
|
496
|
+
readonly text: string;
|
337
497
|
/**
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
498
|
+
The reasoning that was generated during the generation.
|
499
|
+
*/
|
500
|
+
readonly reasoning: Array<ReasoningPart>;
|
501
|
+
/**
|
502
|
+
The reasoning text that was generated during the generation.
|
503
|
+
*/
|
504
|
+
readonly reasoningText: string | undefined;
|
505
|
+
/**
|
506
|
+
The files that were generated during the generation.
|
507
|
+
*/
|
508
|
+
readonly files: Array<GeneratedFile>;
|
509
|
+
/**
|
510
|
+
The sources that were used to generate the text.
|
511
|
+
*/
|
512
|
+
readonly sources: Array<Source>;
|
513
|
+
/**
|
514
|
+
The tool calls that were made during the generation.
|
515
|
+
*/
|
516
|
+
readonly toolCalls: ToolCallArray<TOOLS>;
|
517
|
+
/**
|
518
|
+
The results of the tool calls.
|
519
|
+
*/
|
520
|
+
readonly toolResults: ToolResultArray<TOOLS>;
|
521
|
+
/**
|
522
|
+
The reason why the generation finished.
|
523
|
+
*/
|
524
|
+
readonly finishReason: FinishReason;
|
525
|
+
/**
|
526
|
+
The token usage of the generated text.
|
527
|
+
*/
|
528
|
+
readonly usage: LanguageModelUsage;
|
529
|
+
/**
|
530
|
+
Warnings from the model provider (e.g. unsupported settings).
|
531
|
+
*/
|
532
|
+
readonly warnings: CallWarning[] | undefined;
|
533
|
+
/**
|
534
|
+
Additional request information.
|
344
535
|
*/
|
345
|
-
|
536
|
+
readonly request: LanguageModelRequestMetadata;
|
346
537
|
/**
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
538
|
+
Additional response information.
|
539
|
+
*/
|
540
|
+
readonly response: LanguageModelResponseMetadata & {
|
541
|
+
/**
|
542
|
+
The response messages that were generated during the call.
|
543
|
+
Response messages can be either assistant messages or tool messages.
|
544
|
+
They contain a generated id.
|
545
|
+
*/
|
546
|
+
readonly messages: Array<ResponseMessage>;
|
547
|
+
/**
|
548
|
+
Response body (available only for providers that use HTTP requests).
|
549
|
+
*/
|
550
|
+
body?: unknown;
|
551
|
+
};
|
552
|
+
/**
|
553
|
+
Additional provider-specific metadata. They are passed through
|
554
|
+
from the provider to the AI SDK and enable provider-specific
|
555
|
+
results that can be fully encapsulated in the provider.
|
351
556
|
*/
|
352
|
-
|
557
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
558
|
+
};
|
559
|
+
|
560
|
+
/**
|
561
|
+
The result of a `generateText` call.
|
562
|
+
It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
|
563
|
+
*/
|
564
|
+
interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
|
353
565
|
/**
|
354
|
-
|
355
|
-
repeat information that is already in the prompt.
|
356
|
-
|
357
|
-
The presence penalty is a number between -1 (increase repetition)
|
358
|
-
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
566
|
+
The content that was generated in the last step.
|
359
567
|
*/
|
360
|
-
|
568
|
+
readonly content: Array<ContentPart<TOOLS>>;
|
361
569
|
/**
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
570
|
+
The text that was generated in the last step.
|
571
|
+
*/
|
572
|
+
readonly text: string;
|
573
|
+
/**
|
574
|
+
The full reasoning that the model has generated in the last step.
|
367
575
|
*/
|
368
|
-
|
576
|
+
readonly reasoning: Array<ReasoningPart>;
|
369
577
|
/**
|
370
|
-
|
371
|
-
|
372
|
-
Providers may have limits on the number of stop sequences.
|
578
|
+
The reasoning text that the model has generated in the last step. Can be undefined if the model
|
579
|
+
has only generated text.
|
373
580
|
*/
|
374
|
-
|
581
|
+
readonly reasoningText: string | undefined;
|
375
582
|
/**
|
376
|
-
The
|
377
|
-
|
583
|
+
The files that were generated in the last step.
|
584
|
+
Empty array if no files were generated.
|
585
|
+
*/
|
586
|
+
readonly files: Array<GeneratedFile>;
|
587
|
+
/**
|
588
|
+
Sources that have been used as references in the last step.
|
378
589
|
*/
|
379
|
-
|
590
|
+
readonly sources: Array<Source>;
|
380
591
|
/**
|
381
|
-
|
382
|
-
|
383
|
-
@default 2
|
592
|
+
The tool calls that were made in the last step.
|
384
593
|
*/
|
385
|
-
|
594
|
+
readonly toolCalls: ToolCallArray<TOOLS>;
|
386
595
|
/**
|
387
|
-
|
596
|
+
The results of the tool calls from the last step.
|
388
597
|
*/
|
389
|
-
|
598
|
+
readonly toolResults: ToolResultArray<TOOLS>;
|
390
599
|
/**
|
391
|
-
|
392
|
-
Only applicable for HTTP-based providers.
|
600
|
+
The reason why the generation finished.
|
393
601
|
*/
|
394
|
-
|
395
|
-
};
|
396
|
-
|
397
|
-
/**
|
398
|
-
@deprecated Use `SystemModelMessage` instead.
|
399
|
-
*/
|
400
|
-
type CoreSystemMessage = SystemModelMessage;
|
401
|
-
declare const systemModelMessageSchema: z.ZodType<SystemModelMessage>;
|
402
|
-
/**
|
403
|
-
@deprecated Use `systemModelMessageSchema` instead.
|
404
|
-
*/
|
405
|
-
declare const coreSystemMessageSchema: z.ZodType<SystemModelMessage, unknown>;
|
406
|
-
/**
|
407
|
-
@deprecated Use `UserModelMessage` instead.
|
408
|
-
*/
|
409
|
-
type CoreUserMessage = UserModelMessage;
|
410
|
-
declare const userModelMessageSchema: z.ZodType<UserModelMessage>;
|
411
|
-
/**
|
412
|
-
@deprecated Use `userModelMessageSchema` instead.
|
413
|
-
*/
|
414
|
-
declare const coreUserMessageSchema: z.ZodType<UserModelMessage, unknown>;
|
415
|
-
/**
|
416
|
-
@deprecated Use `AssistantModelMessage` instead.
|
417
|
-
*/
|
418
|
-
type CoreAssistantMessage = AssistantModelMessage;
|
419
|
-
declare const assistantModelMessageSchema: z.ZodType<AssistantModelMessage>;
|
420
|
-
/**
|
421
|
-
@deprecated Use `assistantModelMessageSchema` instead.
|
422
|
-
*/
|
423
|
-
declare const coreAssistantMessageSchema: z.ZodType<AssistantModelMessage, unknown>;
|
424
|
-
/**
|
425
|
-
@deprecated Use `ToolModelMessage` instead.
|
426
|
-
*/
|
427
|
-
type CoreToolMessage = ToolModelMessage;
|
428
|
-
declare const toolModelMessageSchema: z.ZodType<ToolModelMessage>;
|
429
|
-
/**
|
430
|
-
@deprecated Use `toolModelMessageSchema` instead.
|
431
|
-
*/
|
432
|
-
declare const coreToolMessageSchema: z.ZodType<ToolModelMessage, unknown>;
|
433
|
-
/**
|
434
|
-
@deprecated Use `ModelMessage` instead.
|
435
|
-
*/
|
436
|
-
type CoreMessage = ModelMessage;
|
437
|
-
declare const modelMessageSchema: z.ZodType<ModelMessage>;
|
438
|
-
/**
|
439
|
-
@deprecated Use `modelMessageSchema` instead.
|
440
|
-
*/
|
441
|
-
declare const coreMessageSchema: z.ZodType<CoreMessage>;
|
442
|
-
|
443
|
-
/**
|
444
|
-
Prompt part of the AI function options.
|
445
|
-
It contains a system message, a simple text prompt, or a list of messages.
|
446
|
-
*/
|
447
|
-
type Prompt = {
|
602
|
+
readonly finishReason: FinishReason;
|
448
603
|
/**
|
449
|
-
|
604
|
+
The token usage of the last step.
|
450
605
|
*/
|
451
|
-
|
606
|
+
readonly usage: LanguageModelUsage;
|
452
607
|
/**
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
prompt?: string | Array<ModelMessage>;
|
608
|
+
The total token usage of all steps.
|
609
|
+
When there are multiple steps, the usage is the sum of all step usages.
|
610
|
+
*/
|
611
|
+
readonly totalUsage: LanguageModelUsage;
|
458
612
|
/**
|
459
|
-
|
460
|
-
|
461
|
-
You can either use `prompt` or `messages` but not both.
|
613
|
+
Warnings from the model provider (e.g. unsupported settings)
|
462
614
|
*/
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
615
|
+
readonly warnings: CallWarning[] | undefined;
|
616
|
+
/**
|
617
|
+
Additional request information.
|
618
|
+
*/
|
619
|
+
readonly request: LanguageModelRequestMetadata;
|
620
|
+
/**
|
621
|
+
Additional response information.
|
622
|
+
*/
|
623
|
+
readonly response: LanguageModelResponseMetadata & {
|
624
|
+
/**
|
625
|
+
The response messages that were generated during the call. It consists of an assistant message,
|
626
|
+
potentially containing tool calls.
|
627
|
+
|
628
|
+
When there are tool results, there is an additional tool message with the tool results that are available.
|
629
|
+
If there are tools that do not have execute functions, they are not included in the tool results and
|
630
|
+
need to be added separately.
|
631
|
+
*/
|
632
|
+
messages: Array<ResponseMessage>;
|
633
|
+
/**
|
634
|
+
Response body (available only for providers that use HTTP requests).
|
635
|
+
*/
|
636
|
+
body?: unknown;
|
637
|
+
};
|
638
|
+
/**
|
639
|
+
Additional provider-specific metadata. They are passed through
|
640
|
+
from the provider to the AI SDK and enable provider-specific
|
641
|
+
results that can be fully encapsulated in the provider.
|
642
|
+
*/
|
643
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
644
|
+
/**
|
645
|
+
Details for all steps.
|
646
|
+
You can use this to get information about intermediate steps,
|
647
|
+
such as the tool calls or the response headers.
|
648
|
+
*/
|
649
|
+
readonly steps: Array<StepResult<TOOLS>>;
|
650
|
+
/**
|
651
|
+
The generated structured output. It uses the `experimental_output` specification.
|
652
|
+
*/
|
653
|
+
readonly experimental_output: OUTPUT;
|
654
|
+
}
|
467
655
|
|
468
656
|
/**
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
* @param options.system - The system prompt.
|
475
|
-
* @param options.messages - The messages in the current generation step.
|
476
|
-
* @param options.toolCall - The tool call that failed to parse.
|
477
|
-
* @param options.tools - The tools that are available.
|
478
|
-
* @param options.inputSchema - A function that returns the JSON Schema for a tool.
|
479
|
-
* @param options.error - The error that occurred while parsing the tool call.
|
657
|
+
Create a type from an object with all keys and nested keys set to optional.
|
658
|
+
The helper supports normal objects and Zod schemas (which are resolved automatically).
|
659
|
+
It always recurses into arrays.
|
660
|
+
|
661
|
+
Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
480
662
|
*/
|
481
|
-
type
|
482
|
-
|
663
|
+
type DeepPartial<T> = T extends z3.ZodTypeAny ? DeepPartialInternal<z3.infer<T>> : T extends z4.$ZodType ? DeepPartialInternal<z4.infer<T>> : DeepPartialInternal<T>;
|
664
|
+
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
665
|
+
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
666
|
+
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
667
|
+
type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
668
|
+
type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
|
669
|
+
type PartialObject<ObjectType extends object> = {
|
670
|
+
[KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
|
671
|
+
};
|
672
|
+
|
673
|
+
interface Output<OUTPUT, PARTIAL> {
|
674
|
+
readonly type: 'object' | 'text';
|
675
|
+
responseFormat: LanguageModelV2CallOptions['responseFormat'];
|
676
|
+
parsePartial(options: {
|
677
|
+
text: string;
|
678
|
+
}): Promise<{
|
679
|
+
partial: PARTIAL;
|
680
|
+
} | undefined>;
|
681
|
+
parseOutput(options: {
|
682
|
+
text: string;
|
683
|
+
}, context: {
|
684
|
+
response: LanguageModelResponseMetadata;
|
685
|
+
usage: LanguageModelUsage;
|
686
|
+
finishReason: FinishReason;
|
687
|
+
}): Promise<OUTPUT>;
|
688
|
+
}
|
689
|
+
declare const text: () => Output<string, string>;
|
690
|
+
declare const object: <OUTPUT>({ schema: inputSchema, }: {
|
691
|
+
schema: z4$1.ZodType<OUTPUT, any> | z3.Schema<OUTPUT, z3.ZodTypeDef, any> | Schema<OUTPUT>;
|
692
|
+
}) => Output<OUTPUT, DeepPartial<OUTPUT>>;
|
693
|
+
|
694
|
+
type output_Output<OUTPUT, PARTIAL> = Output<OUTPUT, PARTIAL>;
|
695
|
+
declare const output_object: typeof object;
|
696
|
+
declare const output_text: typeof text;
|
697
|
+
declare namespace output {
|
698
|
+
export {
|
699
|
+
output_Output as Output,
|
700
|
+
output_object as object,
|
701
|
+
output_text as text,
|
702
|
+
};
|
703
|
+
}
|
704
|
+
|
705
|
+
/**
|
706
|
+
Function that you can use to provide different settings for a step.
|
707
|
+
|
708
|
+
@param options - The options for the step.
|
709
|
+
@param options.steps - The steps that have been executed so far.
|
710
|
+
@param options.stepNumber - The number of the step that is being executed.
|
711
|
+
@param options.model - The model that is being used.
|
712
|
+
|
713
|
+
@returns An object that contains the settings for the step.
|
714
|
+
If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
715
|
+
*/
|
716
|
+
type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
|
717
|
+
steps: Array<StepResult<NoInfer<TOOLS>>>;
|
718
|
+
stepNumber: number;
|
719
|
+
model: LanguageModel;
|
720
|
+
}) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
|
721
|
+
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
722
|
+
model?: LanguageModel;
|
723
|
+
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
724
|
+
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
725
|
+
system?: string;
|
726
|
+
} | undefined;
|
727
|
+
|
728
|
+
type StopCondition<TOOLS extends ToolSet> = (options: {
|
729
|
+
steps: Array<StepResult<TOOLS>>;
|
730
|
+
}) => PromiseLike<boolean> | boolean;
|
731
|
+
declare function stepCountIs(stepCount: number): StopCondition<any>;
|
732
|
+
declare function hasToolCall(toolName: string): StopCondition<any>;
|
733
|
+
|
734
|
+
declare const symbol$e: unique symbol;
|
735
|
+
declare class InvalidToolInputError extends AISDKError {
|
736
|
+
private readonly [symbol$e];
|
737
|
+
readonly toolName: string;
|
738
|
+
readonly toolInput: string;
|
739
|
+
constructor({ toolInput, toolName, cause, message, }: {
|
740
|
+
message?: string;
|
741
|
+
toolInput: string;
|
742
|
+
toolName: string;
|
743
|
+
cause: unknown;
|
744
|
+
});
|
745
|
+
static isInstance(error: unknown): error is InvalidToolInputError;
|
746
|
+
}
|
747
|
+
|
748
|
+
declare const symbol$d: unique symbol;
|
749
|
+
declare class NoSuchToolError extends AISDKError {
|
750
|
+
private readonly [symbol$d];
|
751
|
+
readonly toolName: string;
|
752
|
+
readonly availableTools: string[] | undefined;
|
753
|
+
constructor({ toolName, availableTools, message, }: {
|
754
|
+
toolName: string;
|
755
|
+
availableTools?: string[] | undefined;
|
756
|
+
message?: string;
|
757
|
+
});
|
758
|
+
static isInstance(error: unknown): error is NoSuchToolError;
|
759
|
+
}
|
760
|
+
|
761
|
+
/**
|
762
|
+
@deprecated Use `SystemModelMessage` instead.
|
763
|
+
*/
|
764
|
+
type CoreSystemMessage = SystemModelMessage;
|
765
|
+
declare const systemModelMessageSchema: z.ZodType<SystemModelMessage>;
|
766
|
+
/**
|
767
|
+
@deprecated Use `systemModelMessageSchema` instead.
|
768
|
+
*/
|
769
|
+
declare const coreSystemMessageSchema: z.ZodType<SystemModelMessage, unknown>;
|
770
|
+
/**
|
771
|
+
@deprecated Use `UserModelMessage` instead.
|
772
|
+
*/
|
773
|
+
type CoreUserMessage = UserModelMessage;
|
774
|
+
declare const userModelMessageSchema: z.ZodType<UserModelMessage>;
|
775
|
+
/**
|
776
|
+
@deprecated Use `userModelMessageSchema` instead.
|
777
|
+
*/
|
778
|
+
declare const coreUserMessageSchema: z.ZodType<UserModelMessage, unknown>;
|
779
|
+
/**
|
780
|
+
@deprecated Use `AssistantModelMessage` instead.
|
781
|
+
*/
|
782
|
+
type CoreAssistantMessage = AssistantModelMessage;
|
783
|
+
declare const assistantModelMessageSchema: z.ZodType<AssistantModelMessage>;
|
784
|
+
/**
|
785
|
+
@deprecated Use `assistantModelMessageSchema` instead.
|
786
|
+
*/
|
787
|
+
declare const coreAssistantMessageSchema: z.ZodType<AssistantModelMessage, unknown>;
|
788
|
+
/**
|
789
|
+
@deprecated Use `ToolModelMessage` instead.
|
790
|
+
*/
|
791
|
+
type CoreToolMessage = ToolModelMessage;
|
792
|
+
declare const toolModelMessageSchema: z.ZodType<ToolModelMessage>;
|
793
|
+
/**
|
794
|
+
@deprecated Use `toolModelMessageSchema` instead.
|
795
|
+
*/
|
796
|
+
declare const coreToolMessageSchema: z.ZodType<ToolModelMessage, unknown>;
|
797
|
+
/**
|
798
|
+
@deprecated Use `ModelMessage` instead.
|
799
|
+
*/
|
800
|
+
type CoreMessage = ModelMessage;
|
801
|
+
declare const modelMessageSchema: z.ZodType<ModelMessage>;
|
802
|
+
/**
|
803
|
+
@deprecated Use `modelMessageSchema` instead.
|
804
|
+
*/
|
805
|
+
declare const coreMessageSchema: z.ZodType<CoreMessage>;
|
806
|
+
|
807
|
+
/**
|
808
|
+
* A function that attempts to repair a tool call that failed to parse.
|
809
|
+
*
|
810
|
+
* It receives the error and the context as arguments and returns the repair
|
811
|
+
* tool call JSON as text.
|
812
|
+
*
|
813
|
+
* @param options.system - The system prompt.
|
814
|
+
* @param options.messages - The messages in the current generation step.
|
815
|
+
* @param options.toolCall - The tool call that failed to parse.
|
816
|
+
* @param options.tools - The tools that are available.
|
817
|
+
* @param options.inputSchema - A function that returns the JSON Schema for a tool.
|
818
|
+
* @param options.error - The error that occurred while parsing the tool call.
|
819
|
+
*/
|
820
|
+
type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
821
|
+
system: string | undefined;
|
483
822
|
messages: ModelMessage[];
|
484
823
|
toolCall: LanguageModelV2ToolCall;
|
485
824
|
tools: TOOLS;
|
@@ -490,2002 +829,1745 @@ type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
|
490
829
|
}) => Promise<LanguageModelV2ToolCall | null>;
|
491
830
|
|
492
831
|
/**
|
493
|
-
|
832
|
+
Callback that is set using the `onStepFinish` option.
|
494
833
|
|
495
|
-
|
834
|
+
@param stepResult - The result of the step.
|
835
|
+
*/
|
836
|
+
type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
|
837
|
+
/**
|
838
|
+
Generate a text and call tools for a given prompt using a language model.
|
496
839
|
|
497
|
-
|
498
|
-
```
|
499
|
-
// data.json
|
500
|
-
{
|
501
|
-
'foo': 1,
|
502
|
-
'bar': 2,
|
503
|
-
'biz': 3
|
504
|
-
}
|
840
|
+
This function does not stream the output. If you want to stream the output, use `streamText` instead.
|
505
841
|
|
506
|
-
|
507
|
-
import type {ValueOf} from 'type-fest';
|
508
|
-
import data = require('./data.json');
|
842
|
+
@param model - The language model to use.
|
509
843
|
|
510
|
-
|
511
|
-
|
512
|
-
}
|
844
|
+
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
845
|
+
@param toolChoice - The tool choice strategy. Default: 'auto'.
|
513
846
|
|
514
|
-
|
515
|
-
|
516
|
-
|
847
|
+
@param system - A system message that will be part of the prompt.
|
848
|
+
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
849
|
+
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
517
850
|
|
518
|
-
|
519
|
-
|
851
|
+
@param maxOutputTokens - Maximum number of tokens to generate.
|
852
|
+
@param temperature - Temperature setting.
|
853
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
854
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
855
|
+
@param topP - Nucleus sampling.
|
856
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
857
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
858
|
+
@param topK - Only sample from the top K options for each subsequent token.
|
859
|
+
Used to remove "long tail" low probability responses.
|
860
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
861
|
+
@param presencePenalty - Presence penalty setting.
|
862
|
+
It affects the likelihood of the model to repeat information that is already in the prompt.
|
863
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
864
|
+
@param frequencyPenalty - Frequency penalty setting.
|
865
|
+
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
866
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
867
|
+
@param stopSequences - Stop sequences.
|
868
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
869
|
+
@param seed - The seed (integer) to use for random sampling.
|
870
|
+
If set and supported by the model, calls will generate deterministic results.
|
520
871
|
|
521
|
-
|
522
|
-
|
872
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
873
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
874
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
523
875
|
|
524
|
-
|
525
|
-
//=> TypeError ...
|
876
|
+
@param experimental_generateMessageId - Generate a unique ID for each message.
|
526
877
|
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
878
|
+
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
879
|
+
|
880
|
+
@returns
|
881
|
+
A result object that contains the generated text, the results of the tool calls, and additional information.
|
882
|
+
*/
|
883
|
+
declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
|
884
|
+
/**
|
885
|
+
The language model to use.
|
886
|
+
*/
|
887
|
+
model: LanguageModel;
|
888
|
+
/**
|
889
|
+
The tools that the model can call. The model needs to support calling tools.
|
531
890
|
*/
|
532
|
-
|
891
|
+
tools?: TOOLS;
|
892
|
+
/**
|
893
|
+
The tool choice strategy. Default: 'auto'.
|
894
|
+
*/
|
895
|
+
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
896
|
+
/**
|
897
|
+
Condition for stopping the generation when there are tool results in the last step.
|
898
|
+
When the condition is an array, any of the conditions can be met to stop the generation.
|
533
899
|
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
900
|
+
@default stepCountIs(1)
|
901
|
+
*/
|
902
|
+
stopWhen?: StopCondition<NoInfer<TOOLS>> | Array<StopCondition<NoInfer<TOOLS>>>;
|
903
|
+
/**
|
904
|
+
Optional telemetry configuration (experimental).
|
905
|
+
*/
|
906
|
+
experimental_telemetry?: TelemetrySettings;
|
907
|
+
/**
|
908
|
+
Additional provider-specific options. They are passed through
|
909
|
+
to the provider from the AI SDK and enable provider-specific
|
910
|
+
functionality that can be fully encapsulated in the provider.
|
911
|
+
*/
|
912
|
+
providerOptions?: ProviderOptions;
|
913
|
+
/**
|
914
|
+
* @deprecated Use `activeTools` instead.
|
915
|
+
*/
|
916
|
+
experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
|
917
|
+
/**
|
918
|
+
Limits the tools that are available for the model to call without
|
919
|
+
changing the tool call and result types in the result.
|
920
|
+
*/
|
921
|
+
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
922
|
+
/**
|
923
|
+
Optional specification for parsing structured outputs from the LLM response.
|
924
|
+
*/
|
925
|
+
experimental_output?: Output<OUTPUT, OUTPUT_PARTIAL>;
|
926
|
+
/**
|
927
|
+
* @deprecated Use `prepareStep` instead.
|
928
|
+
*/
|
929
|
+
experimental_prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
|
930
|
+
/**
|
931
|
+
Optional function that you can use to provide different settings for a step.
|
932
|
+
*/
|
933
|
+
prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
|
934
|
+
/**
|
935
|
+
A function that attempts to repair a tool call that failed to parse.
|
936
|
+
*/
|
937
|
+
experimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
|
938
|
+
/**
|
939
|
+
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
940
|
+
*/
|
941
|
+
onStepFinish?: GenerateTextOnStepFinishCallback<NoInfer<TOOLS>>;
|
942
|
+
/**
|
943
|
+
* Internal. For test use only. May change without notice.
|
944
|
+
*/
|
945
|
+
_internal?: {
|
946
|
+
generateId?: IdGenerator;
|
947
|
+
currentDate?: () => Date;
|
554
948
|
};
|
555
|
-
}
|
556
|
-
type ToolErrorUnion<TOOLS extends ToolSet> = ToToolErrorObject<TOOLS>;
|
949
|
+
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
557
950
|
|
558
|
-
|
559
|
-
|
560
|
-
|
951
|
+
/**
|
952
|
+
The data types that can be used in the UI message for the UI message data parts.
|
953
|
+
*/
|
954
|
+
type UIDataTypes = Record<string, unknown>;
|
955
|
+
type UITool = {
|
956
|
+
input: unknown;
|
957
|
+
output: unknown | undefined;
|
958
|
+
};
|
959
|
+
type InferUITool<TOOL extends Tool> = {
|
960
|
+
input: InferToolInput<TOOL>;
|
961
|
+
output: InferToolOutput<TOOL>;
|
962
|
+
};
|
963
|
+
type UITools = Record<string, UITool>;
|
964
|
+
/**
|
965
|
+
AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
966
|
+
*/
|
967
|
+
interface UIMessage<METADATA = unknown, DATA_PARTS extends UIDataTypes = UIDataTypes, TOOLS extends UITools = UITools> {
|
968
|
+
/**
|
969
|
+
A unique identifier for the message.
|
970
|
+
*/
|
971
|
+
id: string;
|
972
|
+
/**
|
973
|
+
The role of the message.
|
974
|
+
*/
|
975
|
+
role: 'system' | 'user' | 'assistant';
|
976
|
+
/**
|
977
|
+
The metadata of the message.
|
978
|
+
*/
|
979
|
+
metadata?: METADATA;
|
980
|
+
/**
|
981
|
+
The parts of the message. Use this for rendering the message in the UI.
|
982
|
+
|
983
|
+
System messages should be avoided (set the system prompt on the server instead).
|
984
|
+
They can have text parts.
|
985
|
+
|
986
|
+
User messages can have text parts and file parts.
|
987
|
+
|
988
|
+
Assistant messages can have text, reasoning, tool invocation, and file parts.
|
989
|
+
*/
|
990
|
+
parts: Array<UIMessagePart<DATA_PARTS, TOOLS>>;
|
991
|
+
}
|
992
|
+
type UIMessagePart<DATA_TYPES extends UIDataTypes, TOOLS extends UITools> = TextUIPart | ReasoningUIPart | ToolUIPart<TOOLS> | SourceUrlUIPart | SourceDocumentUIPart | FileUIPart | DataUIPart<DATA_TYPES> | StepStartUIPart;
|
993
|
+
/**
|
994
|
+
* A text part of a message.
|
995
|
+
*/
|
996
|
+
type TextUIPart = {
|
997
|
+
type: 'text';
|
998
|
+
/**
|
999
|
+
* The text content.
|
1000
|
+
*/
|
1001
|
+
text: string;
|
1002
|
+
/**
|
1003
|
+
* The state of the text part.
|
1004
|
+
*/
|
1005
|
+
state?: 'streaming' | 'done';
|
1006
|
+
};
|
1007
|
+
/**
|
1008
|
+
* A reasoning part of a message.
|
1009
|
+
*/
|
1010
|
+
type ReasoningUIPart = {
|
1011
|
+
type: 'reasoning';
|
1012
|
+
/**
|
1013
|
+
* The reasoning text.
|
1014
|
+
*/
|
1015
|
+
text: string;
|
1016
|
+
/**
|
1017
|
+
* The state of the reasoning part.
|
1018
|
+
*/
|
1019
|
+
state?: 'streaming' | 'done';
|
1020
|
+
/**
|
1021
|
+
* The provider metadata.
|
1022
|
+
*/
|
1023
|
+
providerMetadata?: Record<string, any>;
|
1024
|
+
};
|
1025
|
+
/**
|
1026
|
+
* A source part of a message.
|
1027
|
+
*/
|
1028
|
+
type SourceUrlUIPart = {
|
1029
|
+
type: 'source-url';
|
1030
|
+
sourceId: string;
|
1031
|
+
url: string;
|
1032
|
+
title?: string;
|
1033
|
+
providerMetadata?: Record<string, any>;
|
1034
|
+
};
|
1035
|
+
/**
|
1036
|
+
* A document source part of a message.
|
1037
|
+
*/
|
1038
|
+
type SourceDocumentUIPart = {
|
1039
|
+
type: 'source-document';
|
1040
|
+
sourceId: string;
|
1041
|
+
mediaType: string;
|
1042
|
+
title: string;
|
1043
|
+
filename?: string;
|
1044
|
+
providerMetadata?: Record<string, any>;
|
1045
|
+
};
|
1046
|
+
/**
|
1047
|
+
* A file part of a message.
|
1048
|
+
*/
|
1049
|
+
type FileUIPart = {
|
1050
|
+
type: 'file';
|
1051
|
+
/**
|
1052
|
+
* IANA media type of the file.
|
1053
|
+
*
|
1054
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
1055
|
+
*/
|
1056
|
+
mediaType: string;
|
1057
|
+
/**
|
1058
|
+
* Optional filename of the file.
|
1059
|
+
*/
|
1060
|
+
filename?: string;
|
1061
|
+
/**
|
1062
|
+
* The URL of the file.
|
1063
|
+
* It can either be a URL to a hosted file or a [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs).
|
1064
|
+
*/
|
1065
|
+
url: string;
|
1066
|
+
};
|
1067
|
+
/**
|
1068
|
+
* A step boundary part of a message.
|
1069
|
+
*/
|
1070
|
+
type StepStartUIPart = {
|
1071
|
+
type: 'step-start';
|
1072
|
+
};
|
1073
|
+
type DataUIPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
|
1074
|
+
[NAME in keyof DATA_TYPES & string]: {
|
1075
|
+
type: `data-${NAME}`;
|
1076
|
+
id?: string;
|
1077
|
+
data: DATA_TYPES[NAME];
|
1078
|
+
};
|
1079
|
+
}>;
|
1080
|
+
type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
|
1081
|
+
[NAME in keyof TOOLS & string]: {
|
1082
|
+
type: `tool-${NAME}`;
|
561
1083
|
toolCallId: string;
|
562
|
-
|
563
|
-
|
1084
|
+
} & ({
|
1085
|
+
state: 'input-streaming';
|
1086
|
+
input: DeepPartial<TOOLS[NAME]['input']>;
|
564
1087
|
providerExecuted?: boolean;
|
565
|
-
}
|
1088
|
+
} | {
|
1089
|
+
state: 'input-available';
|
1090
|
+
input: TOOLS[NAME]['input'];
|
1091
|
+
providerExecuted?: boolean;
|
1092
|
+
} | {
|
1093
|
+
state: 'output-available';
|
1094
|
+
input: TOOLS[NAME]['input'];
|
1095
|
+
output: TOOLS[NAME]['output'];
|
1096
|
+
providerExecuted?: boolean;
|
1097
|
+
} | {
|
1098
|
+
state: 'output-error';
|
1099
|
+
input: TOOLS[NAME]['input'];
|
1100
|
+
errorText: string;
|
1101
|
+
providerExecuted?: boolean;
|
1102
|
+
});
|
566
1103
|
}>;
|
567
|
-
|
1104
|
+
declare function isToolUIPart<TOOLS extends UITools>(part: UIMessagePart<UIDataTypes, TOOLS>): part is ToolUIPart<TOOLS>;
|
1105
|
+
declare function getToolName<TOOLS extends UITools>(part: ToolUIPart<TOOLS>): keyof TOOLS;
|
1106
|
+
type InferUIMessageMetadata<T extends UIMessage> = T extends UIMessage<infer METADATA> ? METADATA : unknown;
|
1107
|
+
type InferUIMessageData<T extends UIMessage> = T extends UIMessage<unknown, infer DATA_TYPES> ? DATA_TYPES : UIDataTypes;
|
568
1108
|
|
569
|
-
type
|
1109
|
+
type DataUIMessageStreamPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
|
1110
|
+
[NAME in keyof DATA_TYPES & string]: {
|
1111
|
+
type: `data-${NAME}`;
|
1112
|
+
id?: string;
|
1113
|
+
data: DATA_TYPES[NAME];
|
1114
|
+
transient?: boolean;
|
1115
|
+
};
|
1116
|
+
}>;
|
1117
|
+
type UIMessageStreamPart<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataTypes> = {
|
570
1118
|
type: 'text-start';
|
571
|
-
providerMetadata?: ProviderMetadata;
|
572
1119
|
id: string;
|
573
1120
|
} | {
|
574
1121
|
type: 'text-delta';
|
575
|
-
id: string;
|
576
|
-
providerMetadata?: ProviderMetadata;
|
577
1122
|
delta: string;
|
1123
|
+
id: string;
|
578
1124
|
} | {
|
579
1125
|
type: 'text-end';
|
580
|
-
providerMetadata?: ProviderMetadata;
|
581
1126
|
id: string;
|
582
1127
|
} | {
|
583
1128
|
type: 'reasoning-start';
|
584
|
-
providerMetadata?: ProviderMetadata;
|
585
1129
|
id: string;
|
1130
|
+
providerMetadata?: ProviderMetadata;
|
586
1131
|
} | {
|
587
1132
|
type: 'reasoning-delta';
|
588
1133
|
id: string;
|
589
|
-
providerMetadata?: ProviderMetadata;
|
590
1134
|
delta: string;
|
1135
|
+
providerMetadata?: ProviderMetadata;
|
591
1136
|
} | {
|
592
1137
|
type: 'reasoning-end';
|
593
1138
|
id: string;
|
594
1139
|
providerMetadata?: ProviderMetadata;
|
595
1140
|
} | {
|
596
|
-
type: '
|
597
|
-
|
598
|
-
toolName: string;
|
599
|
-
providerMetadata?: ProviderMetadata;
|
1141
|
+
type: 'error';
|
1142
|
+
errorText: string;
|
600
1143
|
} | {
|
601
|
-
type: 'tool-input-
|
602
|
-
|
603
|
-
|
604
|
-
|
1144
|
+
type: 'tool-input-available';
|
1145
|
+
toolCallId: string;
|
1146
|
+
toolName: string;
|
1147
|
+
input: unknown;
|
1148
|
+
providerExecuted?: boolean;
|
605
1149
|
} | {
|
606
|
-
type: 'tool-
|
607
|
-
|
1150
|
+
type: 'tool-output-available';
|
1151
|
+
toolCallId: string;
|
1152
|
+
output: unknown;
|
1153
|
+
providerExecuted?: boolean;
|
1154
|
+
} | {
|
1155
|
+
type: 'tool-output-error';
|
1156
|
+
toolCallId: string;
|
1157
|
+
errorText: string;
|
1158
|
+
providerExecuted?: boolean;
|
1159
|
+
} | {
|
1160
|
+
type: 'tool-input-start';
|
1161
|
+
toolCallId: string;
|
1162
|
+
toolName: string;
|
1163
|
+
providerExecuted?: boolean;
|
1164
|
+
} | {
|
1165
|
+
type: 'tool-input-delta';
|
1166
|
+
toolCallId: string;
|
1167
|
+
inputTextDelta: string;
|
1168
|
+
} | {
|
1169
|
+
type: 'source-url';
|
1170
|
+
sourceId: string;
|
1171
|
+
url: string;
|
1172
|
+
title?: string;
|
608
1173
|
providerMetadata?: ProviderMetadata;
|
609
|
-
} |
|
610
|
-
type: 'source';
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
}
|
617
|
-
type: 'tool-result';
|
618
|
-
} & ToolResultUnion<TOOLS>) | ({
|
619
|
-
type: 'tool-error';
|
620
|
-
} & ToolErrorUnion<TOOLS>) | {
|
1174
|
+
} | {
|
1175
|
+
type: 'source-document';
|
1176
|
+
sourceId: string;
|
1177
|
+
mediaType: string;
|
1178
|
+
title: string;
|
1179
|
+
filename?: string;
|
1180
|
+
providerMetadata?: ProviderMetadata;
|
1181
|
+
} | {
|
621
1182
|
type: 'file';
|
622
|
-
|
1183
|
+
url: string;
|
1184
|
+
mediaType: string;
|
1185
|
+
} | DataUIMessageStreamPart<DATA_TYPES> | {
|
1186
|
+
type: 'start-step';
|
623
1187
|
} | {
|
624
|
-
type: '
|
625
|
-
warnings: LanguageModelV2CallWarning[];
|
1188
|
+
type: 'finish-step';
|
626
1189
|
} | {
|
627
|
-
type: '
|
628
|
-
|
629
|
-
|
630
|
-
modelId?: string;
|
1190
|
+
type: 'start';
|
1191
|
+
messageId?: string;
|
1192
|
+
messageMetadata?: METADATA;
|
631
1193
|
} | {
|
632
1194
|
type: 'finish';
|
633
|
-
|
634
|
-
usage: LanguageModelUsage;
|
635
|
-
providerMetadata?: ProviderMetadata;
|
636
|
-
} | {
|
637
|
-
type: 'error';
|
638
|
-
error: unknown;
|
1195
|
+
messageMetadata?: METADATA;
|
639
1196
|
} | {
|
640
|
-
type: '
|
641
|
-
|
1197
|
+
type: 'message-metadata';
|
1198
|
+
messageMetadata: METADATA;
|
642
1199
|
};
|
1200
|
+
type InferUIMessageStreamPart<T extends UIMessage> = UIMessageStreamPart<InferUIMessageMetadata<T>, InferUIMessageData<T>>;
|
643
1201
|
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
chunk: SingleRequestTextStreamPart<any>;
|
650
|
-
message: string;
|
651
|
-
});
|
652
|
-
static isInstance(error: unknown): error is InvalidStreamPartError;
|
653
|
-
}
|
1202
|
+
type UIMessageStreamResponseInit = ResponseInit & {
|
1203
|
+
consumeSseStream?: (options: {
|
1204
|
+
stream: ReadableStream<string>;
|
1205
|
+
}) => PromiseLike<void> | void;
|
1206
|
+
};
|
654
1207
|
|
655
|
-
|
656
|
-
/**
|
657
|
-
* An error occurred with the MCP client.
|
658
|
-
*/
|
659
|
-
declare class MCPClientError extends AISDKError {
|
660
|
-
private readonly [symbol$a];
|
661
|
-
constructor({ name, message, cause, }: {
|
662
|
-
name?: string;
|
663
|
-
message: string;
|
664
|
-
cause?: unknown;
|
665
|
-
});
|
666
|
-
static isInstance(error: unknown): error is MCPClientError;
|
667
|
-
}
|
1208
|
+
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
668
1209
|
|
669
|
-
|
670
|
-
/**
|
671
|
-
Thrown when no image could be generated. This can have multiple causes:
|
1210
|
+
type ErrorHandler = (error: unknown) => void;
|
672
1211
|
|
673
|
-
|
674
|
-
- The model generated a response that could not be parsed.
|
675
|
-
*/
|
676
|
-
declare class NoImageGeneratedError extends AISDKError {
|
677
|
-
private readonly [symbol$9];
|
1212
|
+
type UIMessageStreamOptions<UI_MESSAGE extends UIMessage> = {
|
678
1213
|
/**
|
679
|
-
|
1214
|
+
* The original messages. If they are provided, persistence mode is assumed,
|
1215
|
+
* and a message ID is provided for the response message.
|
680
1216
|
*/
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
The error contains the following properties:
|
699
|
-
|
700
|
-
- `text`: The text that was generated by the model. This can be the raw text or the tool call text, depending on the model.
|
701
|
-
*/
|
702
|
-
declare class NoObjectGeneratedError extends AISDKError {
|
703
|
-
private readonly [symbol$8];
|
1217
|
+
originalMessages?: UI_MESSAGE[];
|
1218
|
+
onFinish?: (options: {
|
1219
|
+
/**
|
1220
|
+
* The updates list of UI messages.
|
1221
|
+
*/
|
1222
|
+
messages: UI_MESSAGE[];
|
1223
|
+
/**
|
1224
|
+
* Indicates whether the response message is a continuation of the last original message,
|
1225
|
+
* or if a new message was created.
|
1226
|
+
*/
|
1227
|
+
isContinuation: boolean;
|
1228
|
+
/**
|
1229
|
+
* The message that was sent to the client as a response
|
1230
|
+
* (including the original message if it was extended).
|
1231
|
+
*/
|
1232
|
+
responseMessage: UI_MESSAGE;
|
1233
|
+
}) => void;
|
704
1234
|
/**
|
705
|
-
|
1235
|
+
* Extracts message metadata that will be send to the client.
|
1236
|
+
*
|
1237
|
+
* Called on `start` and `finish` events.
|
706
1238
|
*/
|
707
|
-
|
1239
|
+
messageMetadata?: (options: {
|
1240
|
+
part: TextStreamPart<ToolSet>;
|
1241
|
+
}) => InferUIMessageMetadata<UI_MESSAGE> | undefined;
|
708
1242
|
/**
|
709
|
-
|
1243
|
+
* Send reasoning parts to the client.
|
1244
|
+
* Default to true.
|
710
1245
|
*/
|
711
|
-
|
1246
|
+
sendReasoning?: boolean;
|
712
1247
|
/**
|
713
|
-
|
1248
|
+
* Send source parts to the client.
|
1249
|
+
* Default to false.
|
714
1250
|
*/
|
715
|
-
|
1251
|
+
sendSources?: boolean;
|
716
1252
|
/**
|
717
|
-
|
1253
|
+
* Send the finish event to the client.
|
1254
|
+
* Set to false if you are using additional streamText calls
|
1255
|
+
* that send additional data.
|
1256
|
+
* Default to true.
|
718
1257
|
*/
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
1258
|
+
sendFinish?: boolean;
|
1259
|
+
/**
|
1260
|
+
* Send the message start event to the client.
|
1261
|
+
* Set to false if you are using additional streamText calls
|
1262
|
+
* and the message start event has already been sent.
|
1263
|
+
* Default to true.
|
1264
|
+
*
|
1265
|
+
* Note: this setting is currently not used, but you should
|
1266
|
+
* already set it to false if you are using additional
|
1267
|
+
* streamText calls that send additional data to prevent
|
1268
|
+
* the message start event from being sent multiple times.
|
1269
|
+
*/
|
1270
|
+
sendStart?: boolean;
|
1271
|
+
/**
|
1272
|
+
* Process an error, e.g. to log it. Default to `() => 'An error occurred.'`.
|
1273
|
+
*
|
1274
|
+
* @return error message to include in the data stream.
|
1275
|
+
*/
|
1276
|
+
onError?: (error: unknown) => string;
|
1277
|
+
};
|
1278
|
+
type ConsumeStreamOptions = {
|
1279
|
+
onError?: ErrorHandler;
|
1280
|
+
};
|
732
1281
|
/**
|
733
|
-
|
1282
|
+
A result object for accessing different stream types and additional information.
|
734
1283
|
*/
|
735
|
-
|
736
|
-
private readonly [symbol$7];
|
737
|
-
constructor({ message }?: {
|
738
|
-
message?: string;
|
739
|
-
});
|
740
|
-
static isInstance(error: unknown): error is NoOutputSpecifiedError;
|
741
|
-
}
|
742
|
-
|
743
|
-
declare const symbol$6: unique symbol;
|
744
|
-
declare class ToolCallRepairError extends AISDKError {
|
745
|
-
private readonly [symbol$6];
|
746
|
-
readonly originalError: NoSuchToolError | InvalidToolInputError;
|
747
|
-
constructor({ cause, originalError, message, }: {
|
748
|
-
message?: string;
|
749
|
-
cause: unknown;
|
750
|
-
originalError: NoSuchToolError | InvalidToolInputError;
|
751
|
-
});
|
752
|
-
static isInstance(error: unknown): error is ToolCallRepairError;
|
753
|
-
}
|
754
|
-
|
755
|
-
declare const symbol$5: unique symbol;
|
756
|
-
declare class InvalidDataContentError extends AISDKError {
|
757
|
-
private readonly [symbol$5];
|
758
|
-
readonly content: unknown;
|
759
|
-
constructor({ content, cause, message, }: {
|
760
|
-
content: unknown;
|
761
|
-
cause?: unknown;
|
762
|
-
message?: string;
|
763
|
-
});
|
764
|
-
static isInstance(error: unknown): error is InvalidDataContentError;
|
765
|
-
}
|
766
|
-
|
767
|
-
declare const symbol$4: unique symbol;
|
768
|
-
declare class InvalidMessageRoleError extends AISDKError {
|
769
|
-
private readonly [symbol$4];
|
770
|
-
readonly role: string;
|
771
|
-
constructor({ role, message, }: {
|
772
|
-
role: string;
|
773
|
-
message?: string;
|
774
|
-
});
|
775
|
-
static isInstance(error: unknown): error is InvalidMessageRoleError;
|
776
|
-
}
|
777
|
-
|
778
|
-
/**
|
779
|
-
Create a type from an object with all keys and nested keys set to optional.
|
780
|
-
The helper supports normal objects and Zod schemas (which are resolved automatically).
|
781
|
-
It always recurses into arrays.
|
782
|
-
|
783
|
-
Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
784
|
-
*/
|
785
|
-
type DeepPartial<T> = T extends z3.ZodTypeAny ? DeepPartialInternal<z3.infer<T>> : T extends z4.$ZodType ? DeepPartialInternal<z4.infer<T>> : DeepPartialInternal<T>;
|
786
|
-
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
787
|
-
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
788
|
-
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
789
|
-
type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
790
|
-
type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
|
791
|
-
type PartialObject<ObjectType extends object> = {
|
792
|
-
[KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
|
793
|
-
};
|
794
|
-
|
795
|
-
/**
|
796
|
-
The data types that can be used in the UI message for the UI message data parts.
|
797
|
-
*/
|
798
|
-
type UIDataTypes = Record<string, unknown>;
|
799
|
-
type UITool = {
|
800
|
-
input: unknown;
|
801
|
-
output: unknown | undefined;
|
802
|
-
};
|
803
|
-
type InferUITool<TOOL extends Tool> = {
|
804
|
-
input: InferToolInput<TOOL>;
|
805
|
-
output: InferToolOutput<TOOL>;
|
806
|
-
};
|
807
|
-
type UITools = Record<string, UITool>;
|
808
|
-
/**
|
809
|
-
AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
810
|
-
*/
|
811
|
-
interface UIMessage<METADATA = unknown, DATA_PARTS extends UIDataTypes = UIDataTypes, TOOLS extends UITools = UITools> {
|
1284
|
+
interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
812
1285
|
/**
|
813
|
-
|
1286
|
+
The content that was generated in the last step.
|
1287
|
+
|
1288
|
+
Resolved when the response is finished.
|
814
1289
|
*/
|
815
|
-
|
1290
|
+
readonly content: Promise<Array<ContentPart<TOOLS>>>;
|
816
1291
|
/**
|
817
|
-
The
|
818
|
-
|
819
|
-
|
1292
|
+
The full text that has been generated by the last step.
|
1293
|
+
|
1294
|
+
Resolved when the response is finished.
|
1295
|
+
*/
|
1296
|
+
readonly text: Promise<string>;
|
820
1297
|
/**
|
821
|
-
The
|
1298
|
+
The full reasoning that the model has generated.
|
1299
|
+
|
1300
|
+
Resolved when the response is finished.
|
822
1301
|
*/
|
823
|
-
|
1302
|
+
readonly reasoning: Promise<Array<ReasoningPart>>;
|
824
1303
|
/**
|
825
|
-
The
|
826
|
-
|
827
|
-
System messages should be avoided (set the system prompt on the server instead).
|
828
|
-
They can have text parts.
|
1304
|
+
The reasoning that has been generated by the last step.
|
829
1305
|
|
830
|
-
|
1306
|
+
Resolved when the response is finished.
|
1307
|
+
*/
|
1308
|
+
readonly reasoningText: Promise<string | undefined>;
|
1309
|
+
/**
|
1310
|
+
Files that have been generated by the model in the last step.
|
831
1311
|
|
832
|
-
|
1312
|
+
Resolved when the response is finished.
|
833
1313
|
*/
|
834
|
-
|
835
|
-
}
|
836
|
-
type UIMessagePart<DATA_TYPES extends UIDataTypes, TOOLS extends UITools> = TextUIPart | ReasoningUIPart | ToolUIPart<TOOLS> | SourceUrlUIPart | SourceDocumentUIPart | FileUIPart | DataUIPart<DATA_TYPES> | StepStartUIPart;
|
837
|
-
/**
|
838
|
-
* A text part of a message.
|
839
|
-
*/
|
840
|
-
type TextUIPart = {
|
841
|
-
type: 'text';
|
1314
|
+
readonly files: Promise<GeneratedFile[]>;
|
842
1315
|
/**
|
843
|
-
|
1316
|
+
Sources that have been used as references in the last step.
|
1317
|
+
|
1318
|
+
Resolved when the response is finished.
|
844
1319
|
*/
|
845
|
-
|
1320
|
+
readonly sources: Promise<Source[]>;
|
846
1321
|
/**
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
* A reasoning part of a message.
|
853
|
-
*/
|
854
|
-
type ReasoningUIPart = {
|
855
|
-
type: 'reasoning';
|
1322
|
+
The tool calls that have been executed in the last step.
|
1323
|
+
|
1324
|
+
Resolved when the response is finished.
|
1325
|
+
*/
|
1326
|
+
readonly toolCalls: Promise<ToolCallUnion<TOOLS>[]>;
|
856
1327
|
/**
|
857
|
-
|
1328
|
+
The tool results that have been generated in the last step.
|
1329
|
+
|
1330
|
+
Resolved when the all tool executions are finished.
|
858
1331
|
*/
|
859
|
-
|
1332
|
+
readonly toolResults: Promise<ToolResultUnion<TOOLS>[]>;
|
860
1333
|
/**
|
861
|
-
|
862
|
-
|
863
|
-
|
1334
|
+
The reason why the generation finished. Taken from the last step.
|
1335
|
+
|
1336
|
+
Resolved when the response is finished.
|
1337
|
+
*/
|
1338
|
+
readonly finishReason: Promise<FinishReason>;
|
864
1339
|
/**
|
865
|
-
|
1340
|
+
The token usage of the last step.
|
1341
|
+
|
1342
|
+
Resolved when the response is finished.
|
866
1343
|
*/
|
867
|
-
|
868
|
-
};
|
869
|
-
/**
|
870
|
-
* A source part of a message.
|
871
|
-
*/
|
872
|
-
type SourceUrlUIPart = {
|
873
|
-
type: 'source-url';
|
874
|
-
sourceId: string;
|
875
|
-
url: string;
|
876
|
-
title?: string;
|
877
|
-
providerMetadata?: Record<string, any>;
|
878
|
-
};
|
879
|
-
/**
|
880
|
-
* A document source part of a message.
|
881
|
-
*/
|
882
|
-
type SourceDocumentUIPart = {
|
883
|
-
type: 'source-document';
|
884
|
-
sourceId: string;
|
885
|
-
mediaType: string;
|
886
|
-
title: string;
|
887
|
-
filename?: string;
|
888
|
-
providerMetadata?: Record<string, any>;
|
889
|
-
};
|
890
|
-
/**
|
891
|
-
* A file part of a message.
|
892
|
-
*/
|
893
|
-
type FileUIPart = {
|
894
|
-
type: 'file';
|
1344
|
+
readonly usage: Promise<LanguageModelUsage>;
|
895
1345
|
/**
|
896
|
-
|
897
|
-
|
898
|
-
|
1346
|
+
The total token usage of the generated response.
|
1347
|
+
When there are multiple steps, the usage is the sum of all step usages.
|
1348
|
+
|
1349
|
+
Resolved when the response is finished.
|
1350
|
+
*/
|
1351
|
+
readonly totalUsage: Promise<LanguageModelUsage>;
|
1352
|
+
/**
|
1353
|
+
Warnings from the model provider (e.g. unsupported settings) for the first step.
|
1354
|
+
*/
|
1355
|
+
readonly warnings: Promise<CallWarning[] | undefined>;
|
1356
|
+
/**
|
1357
|
+
Details for all steps.
|
1358
|
+
You can use this to get information about intermediate steps,
|
1359
|
+
such as the tool calls or the response headers.
|
899
1360
|
*/
|
900
|
-
|
1361
|
+
readonly steps: Promise<Array<StepResult<TOOLS>>>;
|
901
1362
|
/**
|
902
|
-
|
1363
|
+
Additional request information from the last step.
|
1364
|
+
*/
|
1365
|
+
readonly request: Promise<LanguageModelRequestMetadata>;
|
1366
|
+
/**
|
1367
|
+
Additional response information from the last step.
|
1368
|
+
*/
|
1369
|
+
readonly response: Promise<LanguageModelResponseMetadata & {
|
1370
|
+
/**
|
1371
|
+
The response messages that were generated during the call. It consists of an assistant message,
|
1372
|
+
potentially containing tool calls.
|
1373
|
+
|
1374
|
+
When there are tool results, there is an additional tool message with the tool results that are available.
|
1375
|
+
If there are tools that do not have execute functions, they are not included in the tool results and
|
1376
|
+
need to be added separately.
|
1377
|
+
*/
|
1378
|
+
messages: Array<ResponseMessage>;
|
1379
|
+
}>;
|
1380
|
+
/**
|
1381
|
+
Additional provider-specific metadata from the last step.
|
1382
|
+
Metadata is passed through from the provider to the AI SDK and
|
1383
|
+
enables provider-specific results that can be fully encapsulated in the provider.
|
903
1384
|
*/
|
904
|
-
|
1385
|
+
readonly providerMetadata: Promise<ProviderMetadata | undefined>;
|
905
1386
|
/**
|
906
|
-
|
907
|
-
|
1387
|
+
A text stream that returns only the generated text deltas. You can use it
|
1388
|
+
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
1389
|
+
stream will throw the error.
|
1390
|
+
*/
|
1391
|
+
readonly textStream: AsyncIterableStream<string>;
|
1392
|
+
/**
|
1393
|
+
A stream with all events, including text deltas, tool calls, tool results, and
|
1394
|
+
errors.
|
1395
|
+
You can use it as either an AsyncIterable or a ReadableStream.
|
1396
|
+
Only errors that stop the stream, such as network errors, are thrown.
|
1397
|
+
*/
|
1398
|
+
readonly fullStream: AsyncIterableStream<TextStreamPart<TOOLS>>;
|
1399
|
+
/**
|
1400
|
+
A stream of partial outputs. It uses the `experimental_output` specification.
|
908
1401
|
*/
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
constructor({ url, statusCode, statusText, cause, message, }: {
|
971
|
-
url: string;
|
972
|
-
statusCode?: number;
|
973
|
-
statusText?: string;
|
974
|
-
message?: string;
|
975
|
-
cause?: unknown;
|
976
|
-
});
|
977
|
-
static isInstance(error: unknown): error is DownloadError;
|
978
|
-
}
|
979
|
-
|
980
|
-
declare const symbol$1: unique symbol;
|
981
|
-
type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable' | 'abort';
|
982
|
-
declare class RetryError extends AISDKError {
|
983
|
-
private readonly [symbol$1];
|
984
|
-
readonly reason: RetryErrorReason;
|
985
|
-
readonly lastError: unknown;
|
986
|
-
readonly errors: Array<unknown>;
|
987
|
-
constructor({ message, reason, errors, }: {
|
988
|
-
message: string;
|
989
|
-
reason: RetryErrorReason;
|
990
|
-
errors: Array<unknown>;
|
991
|
-
});
|
992
|
-
static isInstance(error: unknown): error is RetryError;
|
1402
|
+
readonly experimental_partialOutputStream: AsyncIterableStream<PARTIAL_OUTPUT>;
|
1403
|
+
/**
|
1404
|
+
Consumes the stream without processing the parts.
|
1405
|
+
This is useful to force the stream to finish.
|
1406
|
+
It effectively removes the backpressure and allows the stream to finish,
|
1407
|
+
triggering the `onFinish` callback and the promise resolution.
|
1408
|
+
|
1409
|
+
If an error occurs, it is passed to the optional `onError` callback.
|
1410
|
+
*/
|
1411
|
+
consumeStream(options?: ConsumeStreamOptions): Promise<void>;
|
1412
|
+
/**
|
1413
|
+
Converts the result to a UI message stream.
|
1414
|
+
|
1415
|
+
@param options.getErrorMessage an optional function that converts an error to an error message.
|
1416
|
+
@param options.sendUsage whether to send the usage information to the client. Defaults to true.
|
1417
|
+
@param options.sendReasoning whether to send the reasoning information to the client. Defaults to false.
|
1418
|
+
@param options.sendSources whether to send the sources information to the client. Defaults to false.
|
1419
|
+
@param options.experimental_sendFinish whether to send the finish information to the client. Defaults to true.
|
1420
|
+
@param options.experimental_sendStart whether to send the start information to the client. Defaults to true.
|
1421
|
+
|
1422
|
+
@return A UI message stream.
|
1423
|
+
*/
|
1424
|
+
toUIMessageStream<UI_MESSAGE extends UIMessage>(options?: UIMessageStreamOptions<UI_MESSAGE>): ReadableStream<InferUIMessageStreamPart<UI_MESSAGE>>;
|
1425
|
+
/**
|
1426
|
+
Writes UI message stream output to a Node.js response-like object.
|
1427
|
+
@param response A Node.js response-like object (ServerResponse).
|
1428
|
+
@param options.status The status code.
|
1429
|
+
@param options.statusText The status text.
|
1430
|
+
@param options.headers The headers.
|
1431
|
+
@param options.getErrorMessage An optional function that converts an error to an error message.
|
1432
|
+
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
1433
|
+
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
1434
|
+
*/
|
1435
|
+
pipeUIMessageStreamToResponse<UI_MESSAGE extends UIMessage>(response: ServerResponse, options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): void;
|
1436
|
+
/**
|
1437
|
+
Writes text delta output to a Node.js response-like object.
|
1438
|
+
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
1439
|
+
writes each text delta as a separate chunk.
|
1440
|
+
@param response A Node.js response-like object (ServerResponse).
|
1441
|
+
@param init Optional headers, status code, and status text.
|
1442
|
+
*/
|
1443
|
+
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
|
1444
|
+
/**
|
1445
|
+
Converts the result to a streamed response object with a stream data part stream.
|
1446
|
+
|
1447
|
+
@param options.status The status code.
|
1448
|
+
@param options.statusText The status text.
|
1449
|
+
@param options.headers The headers.
|
1450
|
+
@param options.getErrorMessage An optional function that converts an error to an error message.
|
1451
|
+
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
1452
|
+
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
1453
|
+
@return A response object.
|
1454
|
+
*/
|
1455
|
+
toUIMessageStreamResponse<UI_MESSAGE extends UIMessage>(options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): Response;
|
1456
|
+
/**
|
1457
|
+
Creates a simple text stream response.
|
1458
|
+
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
1459
|
+
Non-text-delta events are ignored.
|
1460
|
+
@param init Optional headers, status code, and status text.
|
1461
|
+
*/
|
1462
|
+
toTextStreamResponse(init?: ResponseInit): Response;
|
993
1463
|
}
|
994
|
-
|
995
|
-
declare function createTextStreamResponse({ status, statusText, headers, textStream, }: ResponseInit & {
|
996
|
-
textStream: ReadableStream<string>;
|
997
|
-
}): Response;
|
998
|
-
|
999
|
-
declare function pipeTextStreamToResponse({ response, status, statusText, headers, textStream, }: {
|
1000
|
-
response: ServerResponse;
|
1001
|
-
textStream: ReadableStream<string>;
|
1002
|
-
} & ResponseInit): void;
|
1003
|
-
|
1004
|
-
declare const getOriginalFetch: () => typeof fetch;
|
1005
|
-
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onFinish, onError, fetch, }: {
|
1006
|
-
api: string;
|
1007
|
-
prompt: string;
|
1008
|
-
credentials: RequestCredentials | undefined;
|
1009
|
-
headers: HeadersInit | undefined;
|
1010
|
-
body: Record<string, any>;
|
1011
|
-
streamProtocol: 'data' | 'text' | undefined;
|
1012
|
-
setCompletion: (completion: string) => void;
|
1013
|
-
setLoading: (loading: boolean) => void;
|
1014
|
-
setError: (error: Error | undefined) => void;
|
1015
|
-
setAbortController: (abortController: AbortController | null) => void;
|
1016
|
-
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
1017
|
-
onError: ((error: Error) => void) | undefined;
|
1018
|
-
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
1019
|
-
}): Promise<string | null | undefined>;
|
1020
|
-
|
1021
|
-
type DataUIMessageStreamPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
|
1022
|
-
[NAME in keyof DATA_TYPES & string]: {
|
1023
|
-
type: `data-${NAME}`;
|
1024
|
-
id?: string;
|
1025
|
-
data: DATA_TYPES[NAME];
|
1026
|
-
transient?: boolean;
|
1027
|
-
};
|
1028
|
-
}>;
|
1029
|
-
type UIMessageStreamPart<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataTypes> = {
|
1464
|
+
type TextStreamPart<TOOLS extends ToolSet> = {
|
1030
1465
|
type: 'text-start';
|
1031
1466
|
id: string;
|
1032
|
-
|
1033
|
-
type: 'text-delta';
|
1034
|
-
delta: string;
|
1035
|
-
id: string;
|
1467
|
+
providerMetadata?: ProviderMetadata;
|
1036
1468
|
} | {
|
1037
1469
|
type: 'text-end';
|
1038
1470
|
id: string;
|
1471
|
+
providerMetadata?: ProviderMetadata;
|
1039
1472
|
} | {
|
1040
|
-
type: '
|
1473
|
+
type: 'text';
|
1041
1474
|
id: string;
|
1042
1475
|
providerMetadata?: ProviderMetadata;
|
1476
|
+
text: string;
|
1043
1477
|
} | {
|
1044
|
-
type: 'reasoning-
|
1478
|
+
type: 'reasoning-start';
|
1045
1479
|
id: string;
|
1046
|
-
delta: string;
|
1047
1480
|
providerMetadata?: ProviderMetadata;
|
1048
1481
|
} | {
|
1049
1482
|
type: 'reasoning-end';
|
1050
1483
|
id: string;
|
1051
1484
|
providerMetadata?: ProviderMetadata;
|
1052
1485
|
} | {
|
1053
|
-
type: '
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
toolCallId: string;
|
1058
|
-
toolName: string;
|
1059
|
-
input: unknown;
|
1060
|
-
providerExecuted?: boolean;
|
1061
|
-
} | {
|
1062
|
-
type: 'tool-output-available';
|
1063
|
-
toolCallId: string;
|
1064
|
-
output: unknown;
|
1065
|
-
providerExecuted?: boolean;
|
1066
|
-
} | {
|
1067
|
-
type: 'tool-output-error';
|
1068
|
-
toolCallId: string;
|
1069
|
-
errorText: string;
|
1070
|
-
providerExecuted?: boolean;
|
1486
|
+
type: 'reasoning';
|
1487
|
+
providerMetadata?: ProviderMetadata;
|
1488
|
+
id: string;
|
1489
|
+
text: string;
|
1071
1490
|
} | {
|
1072
1491
|
type: 'tool-input-start';
|
1073
|
-
|
1492
|
+
id: string;
|
1074
1493
|
toolName: string;
|
1494
|
+
providerMetadata?: ProviderMetadata;
|
1075
1495
|
providerExecuted?: boolean;
|
1076
1496
|
} | {
|
1077
|
-
type: 'tool-input-
|
1078
|
-
|
1079
|
-
inputTextDelta: string;
|
1080
|
-
} | {
|
1081
|
-
type: 'source-url';
|
1082
|
-
sourceId: string;
|
1083
|
-
url: string;
|
1084
|
-
title?: string;
|
1497
|
+
type: 'tool-input-end';
|
1498
|
+
id: string;
|
1085
1499
|
providerMetadata?: ProviderMetadata;
|
1086
1500
|
} | {
|
1087
|
-
type: '
|
1088
|
-
|
1089
|
-
|
1090
|
-
title: string;
|
1091
|
-
filename?: string;
|
1501
|
+
type: 'tool-input-delta';
|
1502
|
+
id: string;
|
1503
|
+
delta: string;
|
1092
1504
|
providerMetadata?: ProviderMetadata;
|
1093
|
-
} | {
|
1505
|
+
} | ({
|
1506
|
+
type: 'source';
|
1507
|
+
} & Source) | {
|
1094
1508
|
type: 'file';
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1509
|
+
file: GeneratedFile;
|
1510
|
+
} | ({
|
1511
|
+
type: 'tool-call';
|
1512
|
+
} & ToolCallUnion<TOOLS>) | ({
|
1513
|
+
type: 'tool-result';
|
1514
|
+
} & ToolResultUnion<TOOLS>) | ({
|
1515
|
+
type: 'tool-error';
|
1516
|
+
} & ToolErrorUnion<TOOLS>) | {
|
1098
1517
|
type: 'start-step';
|
1518
|
+
request: LanguageModelRequestMetadata;
|
1519
|
+
warnings: CallWarning[];
|
1099
1520
|
} | {
|
1100
1521
|
type: 'finish-step';
|
1522
|
+
response: LanguageModelResponseMetadata;
|
1523
|
+
usage: LanguageModelUsage;
|
1524
|
+
finishReason: FinishReason;
|
1525
|
+
providerMetadata: ProviderMetadata | undefined;
|
1101
1526
|
} | {
|
1102
1527
|
type: 'start';
|
1103
|
-
messageId?: string;
|
1104
|
-
messageMetadata?: METADATA;
|
1105
1528
|
} | {
|
1106
1529
|
type: 'finish';
|
1107
|
-
|
1530
|
+
finishReason: FinishReason;
|
1531
|
+
totalUsage: LanguageModelUsage;
|
1108
1532
|
} | {
|
1109
|
-
type: '
|
1110
|
-
|
1533
|
+
type: 'error';
|
1534
|
+
error: unknown;
|
1535
|
+
} | {
|
1536
|
+
type: 'raw';
|
1537
|
+
rawValue: unknown;
|
1111
1538
|
};
|
1112
|
-
type InferUIMessageStreamPart<T extends UIMessage> = UIMessageStreamPart<InferUIMessageMetadata<T>, InferUIMessageData<T>>;
|
1113
1539
|
|
1114
|
-
type
|
1115
|
-
|
1116
|
-
interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
|
1540
|
+
type AgentSettings<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never> = CallSettings & {
|
1117
1541
|
/**
|
1118
|
-
*
|
1542
|
+
* The system prompt to use.
|
1119
1543
|
*/
|
1120
|
-
|
1544
|
+
system?: string;
|
1121
1545
|
/**
|
1122
|
-
|
1546
|
+
The language model to use.
|
1123
1547
|
*/
|
1124
|
-
|
1548
|
+
model: LanguageModel;
|
1125
1549
|
/**
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1550
|
+
The tools that the model can call. The model needs to support calling tools.
|
1551
|
+
*/
|
1552
|
+
tools?: TOOLS;
|
1553
|
+
/**
|
1554
|
+
The tool choice strategy. Default: 'auto'.
|
1129
1555
|
*/
|
1130
|
-
|
1131
|
-
}
|
1132
|
-
|
1133
|
-
declare function createUIMessageStream<UI_MESSAGE extends UIMessage>({ execute, onError, originalMessages, onFinish, generateId, }: {
|
1134
|
-
execute: (options: {
|
1135
|
-
writer: UIMessageStreamWriter<UI_MESSAGE>;
|
1136
|
-
}) => Promise<void> | void;
|
1137
|
-
onError?: (error: unknown) => string;
|
1556
|
+
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
1138
1557
|
/**
|
1139
|
-
|
1140
|
-
|
1558
|
+
Condition for stopping the generation when there are tool results in the last step.
|
1559
|
+
When the condition is an array, any of the conditions can be met to stop the generation.
|
1560
|
+
|
1561
|
+
@default stepCountIs(1)
|
1141
1562
|
*/
|
1142
|
-
|
1143
|
-
onFinish?: (options: {
|
1144
|
-
/**
|
1145
|
-
* The updates list of UI messages.
|
1146
|
-
*/
|
1147
|
-
messages: UI_MESSAGE[];
|
1148
|
-
/**
|
1149
|
-
* Indicates whether the response message is a continuation of the last original message,
|
1150
|
-
* or if a new message was created.
|
1151
|
-
*/
|
1152
|
-
isContinuation: boolean;
|
1153
|
-
/**
|
1154
|
-
* The message that was sent to the client as a response
|
1155
|
-
* (including the original message if it was extended).
|
1156
|
-
*/
|
1157
|
-
responseMessage: UI_MESSAGE;
|
1158
|
-
}) => void;
|
1159
|
-
generateId?: IdGenerator;
|
1160
|
-
}): ReadableStream<InferUIMessageStreamPart<UI_MESSAGE>>;
|
1161
|
-
|
1162
|
-
type UIMessageStreamResponseInit = ResponseInit & {
|
1163
|
-
consumeSseStream?: (options: {
|
1164
|
-
stream: ReadableStream<string>;
|
1165
|
-
}) => PromiseLike<void> | void;
|
1166
|
-
};
|
1167
|
-
|
1168
|
-
declare function createUIMessageStreamResponse({ status, statusText, headers, stream, consumeSseStream, }: UIMessageStreamResponseInit & {
|
1169
|
-
stream: ReadableStream<UIMessageStreamPart>;
|
1170
|
-
}): Response;
|
1171
|
-
|
1172
|
-
declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
|
1173
|
-
constructor();
|
1174
|
-
}
|
1175
|
-
|
1176
|
-
declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, consumeSseStream, }: {
|
1177
|
-
response: ServerResponse;
|
1178
|
-
stream: ReadableStream<UIMessageStreamPart>;
|
1179
|
-
} & UIMessageStreamResponseInit): void;
|
1180
|
-
|
1181
|
-
declare const UI_MESSAGE_STREAM_HEADERS: {
|
1182
|
-
'content-type': string;
|
1183
|
-
'cache-control': string;
|
1184
|
-
connection: string;
|
1185
|
-
'x-vercel-ai-ui-message-stream': string;
|
1186
|
-
'x-accel-buffering': string;
|
1187
|
-
};
|
1188
|
-
|
1189
|
-
interface ChatTransport<UI_MESSAGE extends UIMessage> {
|
1190
|
-
sendMessages: (options: {
|
1191
|
-
chatId: string;
|
1192
|
-
messages: UI_MESSAGE[];
|
1193
|
-
abortSignal: AbortSignal | undefined;
|
1194
|
-
} & {
|
1195
|
-
trigger: 'submit-user-message' | 'submit-tool-result' | 'regenerate-assistant-message';
|
1196
|
-
messageId: string | undefined;
|
1197
|
-
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageStreamPart>>;
|
1198
|
-
reconnectToStream: (options: {
|
1199
|
-
chatId: string;
|
1200
|
-
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageStreamPart> | null>;
|
1201
|
-
}
|
1202
|
-
|
1203
|
-
type CreateUIMessage<UI_MESSAGE extends UIMessage> = Omit<UI_MESSAGE, 'id' | 'role'> & {
|
1204
|
-
id?: UI_MESSAGE['id'];
|
1205
|
-
role?: UI_MESSAGE['role'];
|
1206
|
-
};
|
1207
|
-
type UIDataPartSchemas = Record<string, Validator<any> | StandardSchemaV1<any>>;
|
1208
|
-
type UIDataTypesToSchemas<T extends UIDataTypes> = {
|
1209
|
-
[K in keyof T]: Validator<T[K]> | StandardSchemaV1<T[K]>;
|
1210
|
-
};
|
1211
|
-
type InferUIDataParts<T extends UIDataPartSchemas> = {
|
1212
|
-
[K in keyof T]: T[K] extends Validator<infer U> ? U : T[K] extends StandardSchemaV1<infer U> ? U : unknown;
|
1213
|
-
};
|
1214
|
-
type ChatRequestOptions = {
|
1215
|
-
/**
|
1216
|
-
Additional headers that should be to be passed to the API endpoint.
|
1217
|
-
*/
|
1218
|
-
headers?: Record<string, string> | Headers;
|
1219
|
-
/**
|
1220
|
-
Additional body JSON properties that should be sent to the API endpoint.
|
1221
|
-
*/
|
1222
|
-
body?: object;
|
1223
|
-
metadata?: unknown;
|
1224
|
-
};
|
1225
|
-
type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
|
1226
|
-
interface ChatState<UI_MESSAGE extends UIMessage> {
|
1227
|
-
status: ChatStatus;
|
1228
|
-
error: Error | undefined;
|
1229
|
-
messages: UI_MESSAGE[];
|
1230
|
-
pushMessage: (message: UI_MESSAGE) => void;
|
1231
|
-
popMessage: () => void;
|
1232
|
-
replaceMessage: (index: number, message: UI_MESSAGE) => void;
|
1233
|
-
snapshot: <T>(thing: T) => T;
|
1234
|
-
}
|
1235
|
-
type ChatOnErrorCallback = (error: Error) => void;
|
1236
|
-
type ChatOnToolCallCallback = ({ toolCall, }: {
|
1237
|
-
toolCall: ToolCall<string, unknown>;
|
1238
|
-
}) => void | Promise<unknown> | unknown;
|
1239
|
-
type ChatOnDataCallback<UI_MESSAGE extends UIMessage> = (dataPart: DataUIPart<InferUIMessageData<UI_MESSAGE>>) => void;
|
1240
|
-
type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
|
1241
|
-
message: UI_MESSAGE;
|
1242
|
-
}) => void;
|
1243
|
-
interface ChatInit<UI_MESSAGE extends UIMessage> {
|
1563
|
+
stopWhen?: StopCondition<NoInfer<TOOLS>> | Array<StopCondition<NoInfer<TOOLS>>>;
|
1244
1564
|
/**
|
1245
|
-
|
1246
|
-
* generated.
|
1565
|
+
Optional telemetry configuration (experimental).
|
1247
1566
|
*/
|
1248
|
-
|
1249
|
-
messageMetadataSchema?: Validator<InferUIMessageMetadata<UI_MESSAGE>> | StandardSchemaV1<InferUIMessageMetadata<UI_MESSAGE>>;
|
1250
|
-
dataPartSchemas?: UIDataTypesToSchemas<InferUIMessageData<UI_MESSAGE>>;
|
1251
|
-
messages?: UI_MESSAGE[];
|
1567
|
+
experimental_telemetry?: TelemetrySettings;
|
1252
1568
|
/**
|
1253
|
-
|
1254
|
-
|
1569
|
+
Limits the tools that are available for the model to call without
|
1570
|
+
changing the tool call and result types in the result.
|
1255
1571
|
*/
|
1256
|
-
|
1257
|
-
transport?: ChatTransport<UI_MESSAGE>;
|
1258
|
-
maxSteps?: number;
|
1572
|
+
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
1259
1573
|
/**
|
1260
|
-
|
1574
|
+
Optional specification for parsing structured outputs from the LLM response.
|
1261
1575
|
*/
|
1262
|
-
|
1263
|
-
/**
|
1264
|
-
Optional callback function that is invoked when a tool call is received.
|
1265
|
-
Intended for automatic client-side tool execution.
|
1266
|
-
|
1267
|
-
You can optionally return a result for the tool call,
|
1268
|
-
either synchronously or asynchronously.
|
1269
|
-
*/
|
1270
|
-
onToolCall?: ChatOnToolCallCallback;
|
1576
|
+
experimental_output?: Output<OUTPUT, OUTPUT_PARTIAL>;
|
1271
1577
|
/**
|
1272
|
-
*
|
1273
|
-
*
|
1274
|
-
* @param message The message that was streamed.
|
1578
|
+
* @deprecated Use `prepareStep` instead.
|
1275
1579
|
*/
|
1276
|
-
|
1580
|
+
experimental_prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
|
1277
1581
|
/**
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
*/
|
1282
|
-
onData?: ChatOnDataCallback<UI_MESSAGE>;
|
1283
|
-
}
|
1284
|
-
declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
1285
|
-
readonly id: string;
|
1286
|
-
readonly generateId: IdGenerator;
|
1287
|
-
protected state: ChatState<UI_MESSAGE>;
|
1288
|
-
private messageMetadataSchema;
|
1289
|
-
private dataPartSchemas;
|
1290
|
-
private readonly transport;
|
1291
|
-
private maxSteps;
|
1292
|
-
private onError?;
|
1293
|
-
private onToolCall?;
|
1294
|
-
private onFinish?;
|
1295
|
-
private onData?;
|
1296
|
-
private activeResponse;
|
1297
|
-
private jobExecutor;
|
1298
|
-
constructor({ generateId, id, transport, maxSteps, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
|
1299
|
-
state: ChatState<UI_MESSAGE>;
|
1300
|
-
});
|
1582
|
+
Optional function that you can use to provide different settings for a step.
|
1583
|
+
*/
|
1584
|
+
prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
|
1301
1585
|
/**
|
1302
|
-
|
1303
|
-
*
|
1304
|
-
* - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
|
1305
|
-
* - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
|
1306
|
-
* - `ready`: The full response has been received and processed; a new user message can be submitted.
|
1307
|
-
* - `error`: An error occurred during the API request, preventing successful completion.
|
1586
|
+
A function that attempts to repair a tool call that failed to parse.
|
1308
1587
|
*/
|
1309
|
-
|
1310
|
-
protected setStatus({ status, error, }: {
|
1311
|
-
status: ChatStatus;
|
1312
|
-
error?: Error;
|
1313
|
-
}): void;
|
1314
|
-
get error(): Error | undefined;
|
1315
|
-
get messages(): UI_MESSAGE[];
|
1316
|
-
get lastMessage(): UI_MESSAGE | undefined;
|
1317
|
-
set messages(messages: UI_MESSAGE[]);
|
1588
|
+
experimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
|
1318
1589
|
/**
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
* If a messageId is provided, the message will be replaced.
|
1323
|
-
*/
|
1324
|
-
sendMessage: (message: (CreateUIMessage<UI_MESSAGE> & {
|
1325
|
-
text?: never;
|
1326
|
-
files?: never;
|
1327
|
-
messageId?: string;
|
1328
|
-
}) | {
|
1329
|
-
text: string;
|
1330
|
-
files?: FileList | FileUIPart[];
|
1331
|
-
metadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
1332
|
-
parts?: never;
|
1333
|
-
messageId?: string;
|
1334
|
-
} | {
|
1335
|
-
files: FileList | FileUIPart[];
|
1336
|
-
metadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
1337
|
-
parts?: never;
|
1338
|
-
messageId?: string;
|
1339
|
-
}, options?: ChatRequestOptions) => Promise<void>;
|
1590
|
+
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
1591
|
+
*/
|
1592
|
+
onStepFinish?: GenerateTextOnStepFinishCallback<NoInfer<TOOLS>>;
|
1340
1593
|
/**
|
1341
|
-
*
|
1342
|
-
* If no message id is provided, the last assistant message will be regenerated.
|
1594
|
+
* Internal. For test use only. May change without notice.
|
1343
1595
|
*/
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1596
|
+
_internal?: {
|
1597
|
+
generateId?: IdGenerator;
|
1598
|
+
currentDate?: () => Date;
|
1599
|
+
};
|
1600
|
+
};
|
1601
|
+
declare class Agent<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never> {
|
1602
|
+
private readonly settings;
|
1603
|
+
constructor(settings: AgentSettings<TOOLS, OUTPUT, OUTPUT_PARTIAL>);
|
1604
|
+
generate(options: Prompt & {
|
1605
|
+
/**
|
1606
|
+
Additional provider-specific metadata. They are passed through
|
1607
|
+
from the provider to the AI SDK and enable provider-specific
|
1608
|
+
results that can be fully encapsulated in the provider.
|
1349
1609
|
*/
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1610
|
+
providerMetadata?: ProviderMetadata;
|
1611
|
+
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
1612
|
+
stream(options: Prompt & {
|
1613
|
+
/**
|
1614
|
+
Additional provider-specific metadata. They are passed through
|
1615
|
+
from the provider to the AI SDK and enable provider-specific
|
1616
|
+
results that can be fully encapsulated in the provider.
|
1357
1617
|
*/
|
1358
|
-
|
1359
|
-
|
1618
|
+
providerMetadata?: ProviderMetadata;
|
1619
|
+
}): StreamTextResult<TOOLS, OUTPUT_PARTIAL>;
|
1360
1620
|
}
|
1361
1621
|
|
1362
|
-
declare
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
declare const convertToCoreMessages: typeof convertToModelMessages;
|
1622
|
+
declare const symbol$c: unique symbol;
|
1623
|
+
declare class InvalidArgumentError extends AISDKError {
|
1624
|
+
private readonly [symbol$c];
|
1625
|
+
readonly parameter: string;
|
1626
|
+
readonly value: unknown;
|
1627
|
+
constructor({ parameter, value, message, }: {
|
1628
|
+
parameter: string;
|
1629
|
+
value: unknown;
|
1630
|
+
message: string;
|
1631
|
+
});
|
1632
|
+
static isInstance(error: unknown): error is InvalidArgumentError;
|
1633
|
+
}
|
1375
1634
|
|
1376
|
-
type
|
1635
|
+
type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
|
1636
|
+
type: 'text-start';
|
1637
|
+
providerMetadata?: ProviderMetadata;
|
1377
1638
|
id: string;
|
1378
|
-
|
1379
|
-
|
1380
|
-
body: Record<string, any> | undefined;
|
1381
|
-
credentials: RequestCredentials | undefined;
|
1382
|
-
headers: HeadersInit | undefined;
|
1383
|
-
api: string;
|
1384
|
-
} & {
|
1385
|
-
trigger: 'submit-user-message' | 'submit-tool-result' | 'regenerate-assistant-message';
|
1386
|
-
messageId: string | undefined;
|
1387
|
-
}) => {
|
1388
|
-
body: object;
|
1389
|
-
headers?: HeadersInit;
|
1390
|
-
credentials?: RequestCredentials;
|
1391
|
-
api?: string;
|
1392
|
-
} | PromiseLike<{
|
1393
|
-
body: object;
|
1394
|
-
headers?: HeadersInit;
|
1395
|
-
credentials?: RequestCredentials;
|
1396
|
-
api?: string;
|
1397
|
-
}>;
|
1398
|
-
type PrepareReconnectToStreamRequest = (options: {
|
1639
|
+
} | {
|
1640
|
+
type: 'text-delta';
|
1399
1641
|
id: string;
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1642
|
+
providerMetadata?: ProviderMetadata;
|
1643
|
+
delta: string;
|
1644
|
+
} | {
|
1645
|
+
type: 'text-end';
|
1646
|
+
providerMetadata?: ProviderMetadata;
|
1647
|
+
id: string;
|
1648
|
+
} | {
|
1649
|
+
type: 'reasoning-start';
|
1650
|
+
providerMetadata?: ProviderMetadata;
|
1651
|
+
id: string;
|
1652
|
+
} | {
|
1653
|
+
type: 'reasoning-delta';
|
1654
|
+
id: string;
|
1655
|
+
providerMetadata?: ProviderMetadata;
|
1656
|
+
delta: string;
|
1657
|
+
} | {
|
1658
|
+
type: 'reasoning-end';
|
1659
|
+
id: string;
|
1660
|
+
providerMetadata?: ProviderMetadata;
|
1661
|
+
} | {
|
1662
|
+
type: 'tool-input-start';
|
1663
|
+
id: string;
|
1664
|
+
toolName: string;
|
1665
|
+
providerMetadata?: ProviderMetadata;
|
1666
|
+
} | {
|
1667
|
+
type: 'tool-input-delta';
|
1668
|
+
id: string;
|
1669
|
+
delta: string;
|
1670
|
+
providerMetadata?: ProviderMetadata;
|
1671
|
+
} | {
|
1672
|
+
type: 'tool-input-end';
|
1673
|
+
id: string;
|
1674
|
+
providerMetadata?: ProviderMetadata;
|
1675
|
+
} | ({
|
1676
|
+
type: 'source';
|
1677
|
+
} & Source) | {
|
1678
|
+
type: 'file';
|
1679
|
+
file: GeneratedFile;
|
1680
|
+
} | ({
|
1681
|
+
type: 'tool-call';
|
1682
|
+
} & ToolCallUnion<TOOLS>) | ({
|
1683
|
+
type: 'tool-result';
|
1684
|
+
} & ToolResultUnion<TOOLS>) | ({
|
1685
|
+
type: 'tool-error';
|
1686
|
+
} & ToolErrorUnion<TOOLS>) | {
|
1687
|
+
type: 'file';
|
1688
|
+
file: GeneratedFile;
|
1689
|
+
} | {
|
1690
|
+
type: 'stream-start';
|
1691
|
+
warnings: LanguageModelV2CallWarning[];
|
1692
|
+
} | {
|
1693
|
+
type: 'response-metadata';
|
1694
|
+
id?: string;
|
1695
|
+
timestamp?: Date;
|
1696
|
+
modelId?: string;
|
1697
|
+
} | {
|
1698
|
+
type: 'finish';
|
1699
|
+
finishReason: FinishReason;
|
1700
|
+
usage: LanguageModelUsage;
|
1701
|
+
providerMetadata?: ProviderMetadata;
|
1702
|
+
} | {
|
1703
|
+
type: 'error';
|
1704
|
+
error: unknown;
|
1705
|
+
} | {
|
1706
|
+
type: 'raw';
|
1707
|
+
rawValue: unknown;
|
1455
1708
|
};
|
1456
|
-
declare abstract class HttpChatTransport<UI_MESSAGE extends UIMessage> implements ChatTransport<UI_MESSAGE> {
|
1457
|
-
protected api: string;
|
1458
|
-
protected credentials?: RequestCredentials;
|
1459
|
-
protected headers?: Record<string, string> | Headers;
|
1460
|
-
protected body?: object;
|
1461
|
-
protected fetch?: FetchFunction;
|
1462
|
-
protected prepareSendMessagesRequest?: PrepareSendMessagesRequest<UI_MESSAGE>;
|
1463
|
-
protected prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest;
|
1464
|
-
constructor({ api, credentials, headers, body, fetch, prepareSendMessagesRequest, prepareReconnectToStreamRequest, }: HttpChatTransportInitOptions<UI_MESSAGE>);
|
1465
|
-
sendMessages({ abortSignal, ...options }: Parameters<ChatTransport<UI_MESSAGE>['sendMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart>>;
|
1466
|
-
reconnectToStream(options: Parameters<ChatTransport<UI_MESSAGE>['reconnectToStream']>[0]): Promise<ReadableStream<UIMessageStreamPart> | null>;
|
1467
|
-
protected abstract processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageStreamPart>;
|
1468
|
-
}
|
1469
1709
|
|
1470
|
-
declare
|
1471
|
-
|
1472
|
-
|
1710
|
+
declare const symbol$b: unique symbol;
|
1711
|
+
declare class InvalidStreamPartError extends AISDKError {
|
1712
|
+
private readonly [symbol$b];
|
1713
|
+
readonly chunk: SingleRequestTextStreamPart<any>;
|
1714
|
+
constructor({ chunk, message, }: {
|
1715
|
+
chunk: SingleRequestTextStreamPart<any>;
|
1716
|
+
message: string;
|
1717
|
+
});
|
1718
|
+
static isInstance(error: unknown): error is InvalidStreamPartError;
|
1473
1719
|
}
|
1474
1720
|
|
1475
|
-
declare
|
1476
|
-
|
1477
|
-
|
1721
|
+
declare const symbol$a: unique symbol;
|
1722
|
+
/**
|
1723
|
+
* An error occurred with the MCP client.
|
1724
|
+
*/
|
1725
|
+
declare class MCPClientError extends AISDKError {
|
1726
|
+
private readonly [symbol$a];
|
1727
|
+
constructor({ name, message, cause, }: {
|
1728
|
+
name?: string;
|
1729
|
+
message: string;
|
1730
|
+
cause?: unknown;
|
1731
|
+
});
|
1732
|
+
static isInstance(error: unknown): error is MCPClientError;
|
1478
1733
|
}
|
1479
1734
|
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
};
|
1490
|
-
type UseCompletionOptions = {
|
1491
|
-
/**
|
1492
|
-
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
1493
|
-
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
1494
|
-
*/
|
1495
|
-
api?: string;
|
1496
|
-
/**
|
1497
|
-
* An unique identifier for the chat. If not provided, a random one will be
|
1498
|
-
* generated. When provided, the `useChat` hook with the same `id` will
|
1499
|
-
* have shared states across components.
|
1500
|
-
*/
|
1501
|
-
id?: string;
|
1502
|
-
/**
|
1503
|
-
* Initial prompt input of the completion.
|
1504
|
-
*/
|
1505
|
-
initialInput?: string;
|
1735
|
+
declare const symbol$9: unique symbol;
|
1736
|
+
/**
|
1737
|
+
Thrown when no image could be generated. This can have multiple causes:
|
1738
|
+
|
1739
|
+
- The model failed to generate a response.
|
1740
|
+
- The model generated a response that could not be parsed.
|
1741
|
+
*/
|
1742
|
+
declare class NoImageGeneratedError extends AISDKError {
|
1743
|
+
private readonly [symbol$9];
|
1506
1744
|
/**
|
1507
|
-
|
1745
|
+
The response metadata for each call.
|
1508
1746
|
*/
|
1509
|
-
|
1747
|
+
readonly responses: Array<ImageModelResponseMetadata> | undefined;
|
1748
|
+
constructor({ message, cause, responses, }: {
|
1749
|
+
message?: string;
|
1750
|
+
cause?: Error;
|
1751
|
+
responses?: Array<ImageModelResponseMetadata>;
|
1752
|
+
});
|
1753
|
+
static isInstance(error: unknown): error is NoImageGeneratedError;
|
1754
|
+
}
|
1755
|
+
|
1756
|
+
declare const symbol$8: unique symbol;
|
1757
|
+
/**
|
1758
|
+
Thrown when no object could be generated. This can have several causes:
|
1759
|
+
|
1760
|
+
- The model failed to generate a response.
|
1761
|
+
- The model generated a response that could not be parsed.
|
1762
|
+
- The model generated a response that could not be validated against the schema.
|
1763
|
+
|
1764
|
+
The error contains the following properties:
|
1765
|
+
|
1766
|
+
- `text`: The text that was generated by the model. This can be the raw text or the tool call text, depending on the model.
|
1767
|
+
*/
|
1768
|
+
declare class NoObjectGeneratedError extends AISDKError {
|
1769
|
+
private readonly [symbol$8];
|
1510
1770
|
/**
|
1511
|
-
|
1771
|
+
The text that was generated by the model. This can be the raw text or the tool call text, depending on the model.
|
1512
1772
|
*/
|
1513
|
-
|
1773
|
+
readonly text: string | undefined;
|
1514
1774
|
/**
|
1515
|
-
|
1775
|
+
The response metadata.
|
1516
1776
|
*/
|
1517
|
-
|
1777
|
+
readonly response: LanguageModelResponseMetadata | undefined;
|
1518
1778
|
/**
|
1519
|
-
|
1520
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
1521
|
-
* Defaults to 'same-origin'.
|
1779
|
+
The usage of the model.
|
1522
1780
|
*/
|
1523
|
-
|
1781
|
+
readonly usage: LanguageModelUsage | undefined;
|
1524
1782
|
/**
|
1525
|
-
|
1783
|
+
Reason why the model finished generating a response.
|
1526
1784
|
*/
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
* ```
|
1539
|
-
*/
|
1540
|
-
body?: object;
|
1541
|
-
/**
|
1542
|
-
Streaming protocol that is used. Defaults to `data`.
|
1543
|
-
*/
|
1544
|
-
streamProtocol?: 'data' | 'text';
|
1545
|
-
/**
|
1546
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
1547
|
-
or to provide a custom fetch implementation for e.g. testing.
|
1548
|
-
*/
|
1549
|
-
fetch?: FetchFunction;
|
1550
|
-
};
|
1551
|
-
|
1552
|
-
/**
|
1553
|
-
* Calculates the cosine similarity between two vectors. This is a useful metric for
|
1554
|
-
* comparing the similarity of two vectors such as embeddings.
|
1555
|
-
*
|
1556
|
-
* @param vector1 - The first vector.
|
1557
|
-
* @param vector2 - The second vector.
|
1558
|
-
*
|
1559
|
-
* @returns The cosine similarity between vector1 and vector2.
|
1560
|
-
* @returns 0 if either vector is the zero vector.
|
1561
|
-
*
|
1562
|
-
* @throws {InvalidArgumentError} If the vectors do not have the same length.
|
1563
|
-
*/
|
1564
|
-
declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
|
1785
|
+
readonly finishReason: FinishReason | undefined;
|
1786
|
+
constructor({ message, cause, text, response, usage, finishReason, }: {
|
1787
|
+
message?: string;
|
1788
|
+
cause?: Error;
|
1789
|
+
text?: string;
|
1790
|
+
response: LanguageModelResponseMetadata;
|
1791
|
+
usage: LanguageModelUsage;
|
1792
|
+
finishReason: FinishReason;
|
1793
|
+
});
|
1794
|
+
static isInstance(error: unknown): error is NoObjectGeneratedError;
|
1795
|
+
}
|
1565
1796
|
|
1797
|
+
declare const symbol$7: unique symbol;
|
1566
1798
|
/**
|
1567
|
-
|
1799
|
+
Thrown when no output type is specified and output-related methods are called.
|
1568
1800
|
*/
|
1569
|
-
declare
|
1801
|
+
declare class NoOutputSpecifiedError extends AISDKError {
|
1802
|
+
private readonly [symbol$7];
|
1803
|
+
constructor({ message }?: {
|
1804
|
+
message?: string;
|
1805
|
+
});
|
1806
|
+
static isInstance(error: unknown): error is NoOutputSpecifiedError;
|
1807
|
+
}
|
1570
1808
|
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1809
|
+
declare const symbol$6: unique symbol;
|
1810
|
+
declare class ToolCallRepairError extends AISDKError {
|
1811
|
+
private readonly [symbol$6];
|
1812
|
+
readonly originalError: NoSuchToolError | InvalidToolInputError;
|
1813
|
+
constructor({ cause, originalError, message, }: {
|
1814
|
+
message?: string;
|
1815
|
+
cause: unknown;
|
1816
|
+
originalError: NoSuchToolError | InvalidToolInputError;
|
1817
|
+
});
|
1818
|
+
static isInstance(error: unknown): error is ToolCallRepairError;
|
1819
|
+
}
|
1579
1820
|
|
1580
|
-
declare
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1821
|
+
declare const symbol$5: unique symbol;
|
1822
|
+
declare class InvalidDataContentError extends AISDKError {
|
1823
|
+
private readonly [symbol$5];
|
1824
|
+
readonly content: unknown;
|
1825
|
+
constructor({ content, cause, message, }: {
|
1826
|
+
content: unknown;
|
1827
|
+
cause?: unknown;
|
1828
|
+
message?: string;
|
1829
|
+
});
|
1830
|
+
static isInstance(error: unknown): error is InvalidDataContentError;
|
1831
|
+
}
|
1584
1832
|
|
1585
|
-
|
1833
|
+
declare const symbol$4: unique symbol;
|
1834
|
+
declare class InvalidMessageRoleError extends AISDKError {
|
1835
|
+
private readonly [symbol$4];
|
1836
|
+
readonly role: string;
|
1837
|
+
constructor({ role, message, }: {
|
1838
|
+
role: string;
|
1839
|
+
message?: string;
|
1840
|
+
});
|
1841
|
+
static isInstance(error: unknown): error is InvalidMessageRoleError;
|
1842
|
+
}
|
1586
1843
|
|
1587
|
-
declare
|
1588
|
-
|
1589
|
-
private
|
1590
|
-
|
1591
|
-
|
1844
|
+
declare const symbol$3: unique symbol;
|
1845
|
+
declare class MessageConversionError extends AISDKError {
|
1846
|
+
private readonly [symbol$3];
|
1847
|
+
readonly originalMessage: Omit<UIMessage, 'id'>;
|
1848
|
+
constructor({ originalMessage, message, }: {
|
1849
|
+
originalMessage: Omit<UIMessage, 'id'>;
|
1850
|
+
message: string;
|
1851
|
+
});
|
1852
|
+
static isInstance(error: unknown): error is MessageConversionError;
|
1592
1853
|
}
|
1593
1854
|
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
};
|
1610
|
-
}): ReadableStream<T>;
|
1855
|
+
declare const symbol$2: unique symbol;
|
1856
|
+
declare class DownloadError extends AISDKError {
|
1857
|
+
private readonly [symbol$2];
|
1858
|
+
readonly url: string;
|
1859
|
+
readonly statusCode?: number;
|
1860
|
+
readonly statusText?: string;
|
1861
|
+
constructor({ url, statusCode, statusText, cause, message, }: {
|
1862
|
+
url: string;
|
1863
|
+
statusCode?: number;
|
1864
|
+
statusText?: string;
|
1865
|
+
message?: string;
|
1866
|
+
cause?: unknown;
|
1867
|
+
});
|
1868
|
+
static isInstance(error: unknown): error is DownloadError;
|
1869
|
+
}
|
1611
1870
|
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
/**
|
1626
|
-
The embedding token usage.
|
1627
|
-
*/
|
1628
|
-
readonly usage: EmbeddingModelUsage;
|
1629
|
-
/**
|
1630
|
-
Optional response data.
|
1631
|
-
*/
|
1632
|
-
readonly response?: {
|
1633
|
-
/**
|
1634
|
-
Response headers.
|
1635
|
-
*/
|
1636
|
-
headers?: Record<string, string>;
|
1637
|
-
/**
|
1638
|
-
The response body.
|
1639
|
-
*/
|
1640
|
-
body?: unknown;
|
1641
|
-
};
|
1871
|
+
declare const symbol$1: unique symbol;
|
1872
|
+
type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable' | 'abort';
|
1873
|
+
declare class RetryError extends AISDKError {
|
1874
|
+
private readonly [symbol$1];
|
1875
|
+
readonly reason: RetryErrorReason;
|
1876
|
+
readonly lastError: unknown;
|
1877
|
+
readonly errors: Array<unknown>;
|
1878
|
+
constructor({ message, reason, errors, }: {
|
1879
|
+
message: string;
|
1880
|
+
reason: RetryErrorReason;
|
1881
|
+
errors: Array<unknown>;
|
1882
|
+
});
|
1883
|
+
static isInstance(error: unknown): error is RetryError;
|
1642
1884
|
}
|
1643
1885
|
|
1644
|
-
|
1645
|
-
|
1886
|
+
declare function createTextStreamResponse({ status, statusText, headers, textStream, }: ResponseInit & {
|
1887
|
+
textStream: ReadableStream<string>;
|
1888
|
+
}): Response;
|
1646
1889
|
|
1647
|
-
|
1648
|
-
|
1890
|
+
declare function pipeTextStreamToResponse({ response, status, statusText, headers, textStream, }: {
|
1891
|
+
response: ServerResponse;
|
1892
|
+
textStream: ReadableStream<string>;
|
1893
|
+
} & ResponseInit): void;
|
1649
1894
|
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1895
|
+
declare const getOriginalFetch: () => typeof fetch;
|
1896
|
+
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onFinish, onError, fetch, }: {
|
1897
|
+
api: string;
|
1898
|
+
prompt: string;
|
1899
|
+
credentials: RequestCredentials | undefined;
|
1900
|
+
headers: HeadersInit | undefined;
|
1901
|
+
body: Record<string, any>;
|
1902
|
+
streamProtocol: 'data' | 'text' | undefined;
|
1903
|
+
setCompletion: (completion: string) => void;
|
1904
|
+
setLoading: (loading: boolean) => void;
|
1905
|
+
setError: (error: Error | undefined) => void;
|
1906
|
+
setAbortController: (abortController: AbortController | null) => void;
|
1907
|
+
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
1908
|
+
onError: ((error: Error) => void) | undefined;
|
1909
|
+
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
1910
|
+
}): Promise<string | null | undefined>;
|
1653
1911
|
|
1654
|
-
|
1655
|
-
*/
|
1656
|
-
declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
|
1657
|
-
/**
|
1658
|
-
The embedding model to use.
|
1659
|
-
*/
|
1660
|
-
model: EmbeddingModel<VALUE>;
|
1912
|
+
interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
|
1661
1913
|
/**
|
1662
|
-
|
1914
|
+
* Appends a data stream part to the stream.
|
1663
1915
|
*/
|
1664
|
-
|
1916
|
+
write(part: InferUIMessageStreamPart<UI_MESSAGE>): void;
|
1665
1917
|
/**
|
1666
|
-
|
1667
|
-
|
1668
|
-
@default 2
|
1918
|
+
* Merges the contents of another stream to this stream.
|
1669
1919
|
*/
|
1670
|
-
|
1920
|
+
merge(stream: ReadableStream<InferUIMessageStreamPart<UI_MESSAGE>>): void;
|
1671
1921
|
/**
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1922
|
+
* Error handler that is used by the data stream writer.
|
1923
|
+
* This is intended for forwarding when merging streams
|
1924
|
+
* to prevent duplicated error masking.
|
1925
|
+
*/
|
1926
|
+
onError: ErrorHandler | undefined;
|
1927
|
+
}
|
1928
|
+
|
1929
|
+
declare function createUIMessageStream<UI_MESSAGE extends UIMessage>({ execute, onError, originalMessages, onFinish, generateId, }: {
|
1930
|
+
execute: (options: {
|
1931
|
+
writer: UIMessageStreamWriter<UI_MESSAGE>;
|
1932
|
+
}) => Promise<void> | void;
|
1933
|
+
onError?: (error: unknown) => string;
|
1675
1934
|
/**
|
1676
|
-
|
1677
|
-
|
1678
|
-
*/
|
1679
|
-
headers?: Record<string, string>;
|
1680
|
-
/**
|
1681
|
-
Additional provider-specific options. They are passed through
|
1682
|
-
to the provider from the AI SDK and enable provider-specific
|
1683
|
-
functionality that can be fully encapsulated in the provider.
|
1684
|
-
*/
|
1685
|
-
providerOptions?: ProviderOptions;
|
1686
|
-
/**
|
1687
|
-
* Optional telemetry configuration (experimental).
|
1935
|
+
* The original messages. If they are provided, persistence mode is assumed,
|
1936
|
+
* and a message ID is provided for the response message.
|
1688
1937
|
*/
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
/**
|
1693
|
-
The result of a `embedMany` call.
|
1694
|
-
It contains the embeddings, the values, and additional information.
|
1695
|
-
*/
|
1696
|
-
interface EmbedManyResult<VALUE> {
|
1697
|
-
/**
|
1698
|
-
The values that were embedded.
|
1699
|
-
*/
|
1700
|
-
readonly values: Array<VALUE>;
|
1701
|
-
/**
|
1702
|
-
The embeddings. They are in the same order as the values.
|
1703
|
-
*/
|
1704
|
-
readonly embeddings: Array<Embedding>;
|
1705
|
-
/**
|
1706
|
-
The embedding token usage.
|
1707
|
-
*/
|
1708
|
-
readonly usage: EmbeddingModelUsage;
|
1709
|
-
/**
|
1710
|
-
Optional raw response data.
|
1711
|
-
*/
|
1712
|
-
readonly responses?: Array<{
|
1938
|
+
originalMessages?: UI_MESSAGE[];
|
1939
|
+
onFinish?: (options: {
|
1713
1940
|
/**
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1941
|
+
* The updates list of UI messages.
|
1942
|
+
*/
|
1943
|
+
messages: UI_MESSAGE[];
|
1717
1944
|
/**
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1945
|
+
* Indicates whether the response message is a continuation of the last original message,
|
1946
|
+
* or if a new message was created.
|
1947
|
+
*/
|
1948
|
+
isContinuation: boolean;
|
1949
|
+
/**
|
1950
|
+
* The message that was sent to the client as a response
|
1951
|
+
* (including the original message if it was extended).
|
1952
|
+
*/
|
1953
|
+
responseMessage: UI_MESSAGE;
|
1954
|
+
}) => void;
|
1955
|
+
generateId?: IdGenerator;
|
1956
|
+
}): ReadableStream<InferUIMessageStreamPart<UI_MESSAGE>>;
|
1730
1957
|
|
1731
|
-
|
1732
|
-
|
1958
|
+
declare function createUIMessageStreamResponse({ status, statusText, headers, stream, consumeSseStream, }: UIMessageStreamResponseInit & {
|
1959
|
+
stream: ReadableStream<UIMessageStreamPart>;
|
1960
|
+
}): Response;
|
1733
1961
|
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1962
|
+
declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
|
1963
|
+
constructor();
|
1964
|
+
}
|
1737
1965
|
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
The embedding model to use.
|
1743
|
-
*/
|
1744
|
-
model: EmbeddingModel<VALUE>;
|
1745
|
-
/**
|
1746
|
-
The values that should be embedded.
|
1747
|
-
*/
|
1748
|
-
values: Array<VALUE>;
|
1749
|
-
/**
|
1750
|
-
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
1751
|
-
|
1752
|
-
@default 2
|
1753
|
-
*/
|
1754
|
-
maxRetries?: number;
|
1755
|
-
/**
|
1756
|
-
Abort signal.
|
1757
|
-
*/
|
1758
|
-
abortSignal?: AbortSignal;
|
1759
|
-
/**
|
1760
|
-
Additional headers to include in the request.
|
1761
|
-
Only applicable for HTTP-based providers.
|
1762
|
-
*/
|
1763
|
-
headers?: Record<string, string>;
|
1764
|
-
/**
|
1765
|
-
* Optional telemetry configuration (experimental).
|
1766
|
-
*/
|
1767
|
-
experimental_telemetry?: TelemetrySettings;
|
1768
|
-
/**
|
1769
|
-
Additional provider-specific options. They are passed through
|
1770
|
-
to the provider from the AI SDK and enable provider-specific
|
1771
|
-
functionality that can be fully encapsulated in the provider.
|
1772
|
-
*/
|
1773
|
-
providerOptions?: ProviderOptions;
|
1774
|
-
/**
|
1775
|
-
* Maximum number of concurrent requests.
|
1776
|
-
*
|
1777
|
-
* @default Infinity
|
1778
|
-
*/
|
1779
|
-
maxParallelCalls?: number;
|
1780
|
-
}): Promise<EmbedManyResult<VALUE>>;
|
1966
|
+
declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, consumeSseStream, }: {
|
1967
|
+
response: ServerResponse;
|
1968
|
+
stream: ReadableStream<UIMessageStreamPart>;
|
1969
|
+
} & UIMessageStreamResponseInit): void;
|
1781
1970
|
|
1782
|
-
|
1783
|
-
type:
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
} | ({
|
1790
|
-
type: 'source';
|
1791
|
-
} & Source) | {
|
1792
|
-
type: 'file';
|
1793
|
-
file: GeneratedFile;
|
1794
|
-
} | ({
|
1795
|
-
type: 'tool-call';
|
1796
|
-
} & ToolCallUnion<TOOLS>) | ({
|
1797
|
-
type: 'tool-result';
|
1798
|
-
} & ToolResultUnion<TOOLS>) | ({
|
1799
|
-
type: 'tool-error';
|
1800
|
-
} & ToolErrorUnion<TOOLS>);
|
1971
|
+
declare const UI_MESSAGE_STREAM_HEADERS: {
|
1972
|
+
'content-type': string;
|
1973
|
+
'cache-control': string;
|
1974
|
+
connection: string;
|
1975
|
+
'x-vercel-ai-ui-message-stream': string;
|
1976
|
+
'x-accel-buffering': string;
|
1977
|
+
};
|
1801
1978
|
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1979
|
+
interface ChatTransport<UI_MESSAGE extends UIMessage> {
|
1980
|
+
sendMessages: (options: {
|
1981
|
+
chatId: string;
|
1982
|
+
messages: UI_MESSAGE[];
|
1983
|
+
abortSignal: AbortSignal | undefined;
|
1984
|
+
} & {
|
1985
|
+
trigger: 'submit-user-message' | 'submit-tool-result' | 'regenerate-assistant-message';
|
1986
|
+
messageId: string | undefined;
|
1987
|
+
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageStreamPart>>;
|
1988
|
+
reconnectToStream: (options: {
|
1989
|
+
chatId: string;
|
1990
|
+
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageStreamPart> | null>;
|
1991
|
+
}
|
1807
1992
|
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
type StepResult<TOOLS extends ToolSet> = {
|
1812
|
-
/**
|
1813
|
-
The content that was generated in the last step.
|
1814
|
-
*/
|
1815
|
-
readonly content: Array<ContentPart<TOOLS>>;
|
1816
|
-
/**
|
1817
|
-
The generated text.
|
1818
|
-
*/
|
1819
|
-
readonly text: string;
|
1820
|
-
/**
|
1821
|
-
The reasoning that was generated during the generation.
|
1822
|
-
*/
|
1823
|
-
readonly reasoning: Array<ReasoningPart>;
|
1824
|
-
/**
|
1825
|
-
The reasoning text that was generated during the generation.
|
1826
|
-
*/
|
1827
|
-
readonly reasoningText: string | undefined;
|
1828
|
-
/**
|
1829
|
-
The files that were generated during the generation.
|
1830
|
-
*/
|
1831
|
-
readonly files: Array<GeneratedFile>;
|
1832
|
-
/**
|
1833
|
-
The sources that were used to generate the text.
|
1834
|
-
*/
|
1835
|
-
readonly sources: Array<Source>;
|
1836
|
-
/**
|
1837
|
-
The tool calls that were made during the generation.
|
1838
|
-
*/
|
1839
|
-
readonly toolCalls: ToolCallArray<TOOLS>;
|
1840
|
-
/**
|
1841
|
-
The results of the tool calls.
|
1842
|
-
*/
|
1843
|
-
readonly toolResults: ToolResultArray<TOOLS>;
|
1844
|
-
/**
|
1845
|
-
The reason why the generation finished.
|
1846
|
-
*/
|
1847
|
-
readonly finishReason: FinishReason;
|
1848
|
-
/**
|
1849
|
-
The token usage of the generated text.
|
1850
|
-
*/
|
1851
|
-
readonly usage: LanguageModelUsage;
|
1852
|
-
/**
|
1853
|
-
Warnings from the model provider (e.g. unsupported settings).
|
1854
|
-
*/
|
1855
|
-
readonly warnings: CallWarning[] | undefined;
|
1856
|
-
/**
|
1857
|
-
Additional request information.
|
1858
|
-
*/
|
1859
|
-
readonly request: LanguageModelRequestMetadata;
|
1860
|
-
/**
|
1861
|
-
Additional response information.
|
1862
|
-
*/
|
1863
|
-
readonly response: LanguageModelResponseMetadata & {
|
1864
|
-
/**
|
1865
|
-
The response messages that were generated during the call.
|
1866
|
-
Response messages can be either assistant messages or tool messages.
|
1867
|
-
They contain a generated id.
|
1868
|
-
*/
|
1869
|
-
readonly messages: Array<ResponseMessage>;
|
1870
|
-
/**
|
1871
|
-
Response body (available only for providers that use HTTP requests).
|
1872
|
-
*/
|
1873
|
-
body?: unknown;
|
1874
|
-
};
|
1875
|
-
/**
|
1876
|
-
Additional provider-specific metadata. They are passed through
|
1877
|
-
from the provider to the AI SDK and enable provider-specific
|
1878
|
-
results that can be fully encapsulated in the provider.
|
1879
|
-
*/
|
1880
|
-
readonly providerMetadata: ProviderMetadata | undefined;
|
1993
|
+
type CreateUIMessage<UI_MESSAGE extends UIMessage> = Omit<UI_MESSAGE, 'id' | 'role'> & {
|
1994
|
+
id?: UI_MESSAGE['id'];
|
1995
|
+
role?: UI_MESSAGE['role'];
|
1881
1996
|
};
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
*/
|
1891
|
-
readonly content: Array<ContentPart<TOOLS>>;
|
1892
|
-
/**
|
1893
|
-
The text that was generated in the last step.
|
1894
|
-
*/
|
1895
|
-
readonly text: string;
|
1896
|
-
/**
|
1897
|
-
The full reasoning that the model has generated in the last step.
|
1898
|
-
*/
|
1899
|
-
readonly reasoning: Array<ReasoningPart>;
|
1900
|
-
/**
|
1901
|
-
The reasoning text that the model has generated in the last step. Can be undefined if the model
|
1902
|
-
has only generated text.
|
1903
|
-
*/
|
1904
|
-
readonly reasoningText: string | undefined;
|
1905
|
-
/**
|
1906
|
-
The files that were generated in the last step.
|
1907
|
-
Empty array if no files were generated.
|
1908
|
-
*/
|
1909
|
-
readonly files: Array<GeneratedFile>;
|
1910
|
-
/**
|
1911
|
-
Sources that have been used as references in the last step.
|
1912
|
-
*/
|
1913
|
-
readonly sources: Array<Source>;
|
1914
|
-
/**
|
1915
|
-
The tool calls that were made in the last step.
|
1916
|
-
*/
|
1917
|
-
readonly toolCalls: ToolCallArray<TOOLS>;
|
1918
|
-
/**
|
1919
|
-
The results of the tool calls from the last step.
|
1920
|
-
*/
|
1921
|
-
readonly toolResults: ToolResultArray<TOOLS>;
|
1922
|
-
/**
|
1923
|
-
The reason why the generation finished.
|
1924
|
-
*/
|
1925
|
-
readonly finishReason: FinishReason;
|
1926
|
-
/**
|
1927
|
-
The token usage of the last step.
|
1928
|
-
*/
|
1929
|
-
readonly usage: LanguageModelUsage;
|
1930
|
-
/**
|
1931
|
-
The total token usage of all steps.
|
1932
|
-
When there are multiple steps, the usage is the sum of all step usages.
|
1933
|
-
*/
|
1934
|
-
readonly totalUsage: LanguageModelUsage;
|
1935
|
-
/**
|
1936
|
-
Warnings from the model provider (e.g. unsupported settings)
|
1937
|
-
*/
|
1938
|
-
readonly warnings: CallWarning[] | undefined;
|
1939
|
-
/**
|
1940
|
-
Additional request information.
|
1941
|
-
*/
|
1942
|
-
readonly request: LanguageModelRequestMetadata;
|
1997
|
+
type UIDataPartSchemas = Record<string, Validator<any> | StandardSchemaV1<any>>;
|
1998
|
+
type UIDataTypesToSchemas<T extends UIDataTypes> = {
|
1999
|
+
[K in keyof T]: Validator<T[K]> | StandardSchemaV1<T[K]>;
|
2000
|
+
};
|
2001
|
+
type InferUIDataParts<T extends UIDataPartSchemas> = {
|
2002
|
+
[K in keyof T]: T[K] extends Validator<infer U> ? U : T[K] extends StandardSchemaV1<infer U> ? U : unknown;
|
2003
|
+
};
|
2004
|
+
type ChatRequestOptions = {
|
1943
2005
|
/**
|
1944
|
-
|
2006
|
+
Additional headers that should be to be passed to the API endpoint.
|
1945
2007
|
*/
|
1946
|
-
|
1947
|
-
/**
|
1948
|
-
The response messages that were generated during the call. It consists of an assistant message,
|
1949
|
-
potentially containing tool calls.
|
1950
|
-
|
1951
|
-
When there are tool results, there is an additional tool message with the tool results that are available.
|
1952
|
-
If there are tools that do not have execute functions, they are not included in the tool results and
|
1953
|
-
need to be added separately.
|
1954
|
-
*/
|
1955
|
-
messages: Array<ResponseMessage>;
|
1956
|
-
/**
|
1957
|
-
Response body (available only for providers that use HTTP requests).
|
1958
|
-
*/
|
1959
|
-
body?: unknown;
|
1960
|
-
};
|
2008
|
+
headers?: Record<string, string> | Headers;
|
1961
2009
|
/**
|
1962
|
-
|
1963
|
-
from the provider to the AI SDK and enable provider-specific
|
1964
|
-
results that can be fully encapsulated in the provider.
|
2010
|
+
Additional body JSON properties that should be sent to the API endpoint.
|
1965
2011
|
*/
|
1966
|
-
|
2012
|
+
body?: object;
|
2013
|
+
metadata?: unknown;
|
2014
|
+
};
|
2015
|
+
type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
|
2016
|
+
interface ChatState<UI_MESSAGE extends UIMessage> {
|
2017
|
+
status: ChatStatus;
|
2018
|
+
error: Error | undefined;
|
2019
|
+
messages: UI_MESSAGE[];
|
2020
|
+
pushMessage: (message: UI_MESSAGE) => void;
|
2021
|
+
popMessage: () => void;
|
2022
|
+
replaceMessage: (index: number, message: UI_MESSAGE) => void;
|
2023
|
+
snapshot: <T>(thing: T) => T;
|
2024
|
+
}
|
2025
|
+
type ChatOnErrorCallback = (error: Error) => void;
|
2026
|
+
type ChatOnToolCallCallback = ({ toolCall, }: {
|
2027
|
+
toolCall: ToolCall<string, unknown>;
|
2028
|
+
}) => void | Promise<unknown> | unknown;
|
2029
|
+
type ChatOnDataCallback<UI_MESSAGE extends UIMessage> = (dataPart: DataUIPart<InferUIMessageData<UI_MESSAGE>>) => void;
|
2030
|
+
type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
|
2031
|
+
message: UI_MESSAGE;
|
2032
|
+
}) => void;
|
2033
|
+
interface ChatInit<UI_MESSAGE extends UIMessage> {
|
1967
2034
|
/**
|
1968
|
-
|
1969
|
-
|
1970
|
-
such as the tool calls or the response headers.
|
2035
|
+
* A unique identifier for the chat. If not provided, a random one will be
|
2036
|
+
* generated.
|
1971
2037
|
*/
|
1972
|
-
|
2038
|
+
id?: string;
|
2039
|
+
messageMetadataSchema?: Validator<InferUIMessageMetadata<UI_MESSAGE>> | StandardSchemaV1<InferUIMessageMetadata<UI_MESSAGE>>;
|
2040
|
+
dataPartSchemas?: UIDataTypesToSchemas<InferUIMessageData<UI_MESSAGE>>;
|
2041
|
+
messages?: UI_MESSAGE[];
|
1973
2042
|
/**
|
1974
|
-
|
2043
|
+
* A way to provide a function that is going to be used for ids for messages and the chat.
|
2044
|
+
* If not provided the default AI SDK `generateId` is used.
|
1975
2045
|
*/
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
interface Output<OUTPUT, PARTIAL> {
|
1980
|
-
readonly type: 'object' | 'text';
|
1981
|
-
responseFormat: LanguageModelV2CallOptions['responseFormat'];
|
1982
|
-
parsePartial(options: {
|
1983
|
-
text: string;
|
1984
|
-
}): Promise<{
|
1985
|
-
partial: PARTIAL;
|
1986
|
-
} | undefined>;
|
1987
|
-
parseOutput(options: {
|
1988
|
-
text: string;
|
1989
|
-
}, context: {
|
1990
|
-
response: LanguageModelResponseMetadata;
|
1991
|
-
usage: LanguageModelUsage;
|
1992
|
-
finishReason: FinishReason;
|
1993
|
-
}): Promise<OUTPUT>;
|
1994
|
-
}
|
1995
|
-
declare const text: () => Output<string, string>;
|
1996
|
-
declare const object: <OUTPUT>({ schema: inputSchema, }: {
|
1997
|
-
schema: z4$1.ZodType<OUTPUT, any> | z3.Schema<OUTPUT, z3.ZodTypeDef, any> | Schema<OUTPUT>;
|
1998
|
-
}) => Output<OUTPUT, DeepPartial<OUTPUT>>;
|
1999
|
-
|
2000
|
-
type output_Output<OUTPUT, PARTIAL> = Output<OUTPUT, PARTIAL>;
|
2001
|
-
declare const output_object: typeof object;
|
2002
|
-
declare const output_text: typeof text;
|
2003
|
-
declare namespace output {
|
2004
|
-
export {
|
2005
|
-
output_Output as Output,
|
2006
|
-
output_object as object,
|
2007
|
-
output_text as text,
|
2008
|
-
};
|
2009
|
-
}
|
2010
|
-
|
2011
|
-
/**
|
2012
|
-
Function that you can use to provide different settings for a step.
|
2013
|
-
|
2014
|
-
@param options - The options for the step.
|
2015
|
-
@param options.steps - The steps that have been executed so far.
|
2016
|
-
@param options.stepNumber - The number of the step that is being executed.
|
2017
|
-
@param options.model - The model that is being used.
|
2018
|
-
|
2019
|
-
@returns An object that contains the settings for the step.
|
2020
|
-
If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
2021
|
-
*/
|
2022
|
-
type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
|
2023
|
-
steps: Array<StepResult<NoInfer<TOOLS>>>;
|
2024
|
-
stepNumber: number;
|
2025
|
-
model: LanguageModel;
|
2026
|
-
}) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
|
2027
|
-
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
2028
|
-
model?: LanguageModel;
|
2029
|
-
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
2030
|
-
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
2031
|
-
system?: string;
|
2032
|
-
} | undefined;
|
2033
|
-
|
2034
|
-
type StopCondition<TOOLS extends ToolSet> = (options: {
|
2035
|
-
steps: Array<StepResult<TOOLS>>;
|
2036
|
-
}) => PromiseLike<boolean> | boolean;
|
2037
|
-
declare function stepCountIs(stepCount: number): StopCondition<any>;
|
2038
|
-
declare function hasToolCall(toolName: string): StopCondition<any>;
|
2039
|
-
|
2040
|
-
/**
|
2041
|
-
Callback that is set using the `onStepFinish` option.
|
2042
|
-
|
2043
|
-
@param stepResult - The result of the step.
|
2044
|
-
*/
|
2045
|
-
type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
|
2046
|
-
/**
|
2047
|
-
Generate a text and call tools for a given prompt using a language model.
|
2048
|
-
|
2049
|
-
This function does not stream the output. If you want to stream the output, use `streamText` instead.
|
2050
|
-
|
2051
|
-
@param model - The language model to use.
|
2052
|
-
|
2053
|
-
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2054
|
-
@param toolChoice - The tool choice strategy. Default: 'auto'.
|
2055
|
-
|
2056
|
-
@param system - A system message that will be part of the prompt.
|
2057
|
-
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
2058
|
-
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
2059
|
-
|
2060
|
-
@param maxOutputTokens - Maximum number of tokens to generate.
|
2061
|
-
@param temperature - Temperature setting.
|
2062
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
2063
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
2064
|
-
@param topP - Nucleus sampling.
|
2065
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
2066
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
2067
|
-
@param topK - Only sample from the top K options for each subsequent token.
|
2068
|
-
Used to remove "long tail" low probability responses.
|
2069
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
2070
|
-
@param presencePenalty - Presence penalty setting.
|
2071
|
-
It affects the likelihood of the model to repeat information that is already in the prompt.
|
2072
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
2073
|
-
@param frequencyPenalty - Frequency penalty setting.
|
2074
|
-
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
2075
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
2076
|
-
@param stopSequences - Stop sequences.
|
2077
|
-
If set, the model will stop generating text when one of the stop sequences is generated.
|
2078
|
-
@param seed - The seed (integer) to use for random sampling.
|
2079
|
-
If set and supported by the model, calls will generate deterministic results.
|
2080
|
-
|
2081
|
-
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
2082
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2083
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2084
|
-
|
2085
|
-
@param experimental_generateMessageId - Generate a unique ID for each message.
|
2086
|
-
|
2087
|
-
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
2088
|
-
|
2089
|
-
@returns
|
2090
|
-
A result object that contains the generated text, the results of the tool calls, and additional information.
|
2091
|
-
*/
|
2092
|
-
declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
|
2046
|
+
generateId?: IdGenerator;
|
2047
|
+
transport?: ChatTransport<UI_MESSAGE>;
|
2048
|
+
maxSteps?: number;
|
2093
2049
|
/**
|
2094
|
-
|
2050
|
+
* Callback function to be called when an error is encountered.
|
2095
2051
|
*/
|
2096
|
-
|
2052
|
+
onError?: ChatOnErrorCallback;
|
2097
2053
|
/**
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2054
|
+
Optional callback function that is invoked when a tool call is received.
|
2055
|
+
Intended for automatic client-side tool execution.
|
2056
|
+
|
2057
|
+
You can optionally return a result for the tool call,
|
2058
|
+
either synchronously or asynchronously.
|
2059
|
+
*/
|
2060
|
+
onToolCall?: ChatOnToolCallCallback;
|
2101
2061
|
/**
|
2102
|
-
|
2062
|
+
* Optional callback function that is called when the assistant message is finished streaming.
|
2063
|
+
*
|
2064
|
+
* @param message The message that was streamed.
|
2103
2065
|
*/
|
2104
|
-
|
2066
|
+
onFinish?: ChatOnFinishCallback<UI_MESSAGE>;
|
2105
2067
|
/**
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
@default stepCountIs(1)
|
2068
|
+
* Optional callback function that is called when a data part is received.
|
2069
|
+
*
|
2070
|
+
* @param data The data part that was received.
|
2110
2071
|
*/
|
2111
|
-
|
2072
|
+
onData?: ChatOnDataCallback<UI_MESSAGE>;
|
2073
|
+
}
|
2074
|
+
declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
2075
|
+
readonly id: string;
|
2076
|
+
readonly generateId: IdGenerator;
|
2077
|
+
protected state: ChatState<UI_MESSAGE>;
|
2078
|
+
private messageMetadataSchema;
|
2079
|
+
private dataPartSchemas;
|
2080
|
+
private readonly transport;
|
2081
|
+
private maxSteps;
|
2082
|
+
private onError?;
|
2083
|
+
private onToolCall?;
|
2084
|
+
private onFinish?;
|
2085
|
+
private onData?;
|
2086
|
+
private activeResponse;
|
2087
|
+
private jobExecutor;
|
2088
|
+
constructor({ generateId, id, transport, maxSteps, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
|
2089
|
+
state: ChatState<UI_MESSAGE>;
|
2090
|
+
});
|
2112
2091
|
/**
|
2113
|
-
|
2092
|
+
* Hook status:
|
2093
|
+
*
|
2094
|
+
* - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
|
2095
|
+
* - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
|
2096
|
+
* - `ready`: The full response has been received and processed; a new user message can be submitted.
|
2097
|
+
* - `error`: An error occurred during the API request, preventing successful completion.
|
2114
2098
|
*/
|
2115
|
-
|
2099
|
+
get status(): ChatStatus;
|
2100
|
+
protected setStatus({ status, error, }: {
|
2101
|
+
status: ChatStatus;
|
2102
|
+
error?: Error;
|
2103
|
+
}): void;
|
2104
|
+
get error(): Error | undefined;
|
2105
|
+
get messages(): UI_MESSAGE[];
|
2106
|
+
get lastMessage(): UI_MESSAGE | undefined;
|
2107
|
+
set messages(messages: UI_MESSAGE[]);
|
2116
2108
|
/**
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2109
|
+
* Appends or replaces a user message to the chat list. This triggers the API call to fetch
|
2110
|
+
* the assistant's response.
|
2111
|
+
*
|
2112
|
+
* If a messageId is provided, the message will be replaced.
|
2113
|
+
*/
|
2114
|
+
sendMessage: (message: (CreateUIMessage<UI_MESSAGE> & {
|
2115
|
+
text?: never;
|
2116
|
+
files?: never;
|
2117
|
+
messageId?: string;
|
2118
|
+
}) | {
|
2119
|
+
text: string;
|
2120
|
+
files?: FileList | FileUIPart[];
|
2121
|
+
metadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
2122
|
+
parts?: never;
|
2123
|
+
messageId?: string;
|
2124
|
+
} | {
|
2125
|
+
files: FileList | FileUIPart[];
|
2126
|
+
metadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
2127
|
+
parts?: never;
|
2128
|
+
messageId?: string;
|
2129
|
+
}, options?: ChatRequestOptions) => Promise<void>;
|
2122
2130
|
/**
|
2123
|
-
*
|
2131
|
+
* Regenerate the assistant message with the provided message id.
|
2132
|
+
* If no message id is provided, the last assistant message will be regenerated.
|
2124
2133
|
*/
|
2125
|
-
|
2134
|
+
regenerate: ({ messageId, ...options }?: {
|
2135
|
+
messageId?: string;
|
2136
|
+
} & ChatRequestOptions) => Promise<void>;
|
2126
2137
|
/**
|
2127
|
-
|
2128
|
-
changing the tool call and result types in the result.
|
2138
|
+
* Attempt to resume an ongoing streaming response.
|
2129
2139
|
*/
|
2130
|
-
|
2140
|
+
resumeStream: (options?: ChatRequestOptions) => Promise<void>;
|
2141
|
+
addToolResult: ({ toolCallId, output, }: {
|
2142
|
+
toolCallId: string;
|
2143
|
+
output: unknown;
|
2144
|
+
}) => Promise<void>;
|
2131
2145
|
/**
|
2132
|
-
|
2146
|
+
* Abort the current request immediately, keep the generated tokens if any.
|
2133
2147
|
*/
|
2134
|
-
|
2148
|
+
stop: () => Promise<void>;
|
2149
|
+
private makeRequest;
|
2150
|
+
}
|
2151
|
+
|
2152
|
+
declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
|
2153
|
+
|
2154
|
+
/**
|
2155
|
+
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
2156
|
+
with the AI core functions (e.g. `streamText`).
|
2157
|
+
*/
|
2158
|
+
declare function convertToModelMessages(messages: Array<Omit<UIMessage, 'id'>>, options?: {
|
2159
|
+
tools?: ToolSet;
|
2160
|
+
}): ModelMessage[];
|
2161
|
+
/**
|
2162
|
+
@deprecated Use `convertToModelMessages` instead.
|
2163
|
+
*/
|
2164
|
+
declare const convertToCoreMessages: typeof convertToModelMessages;
|
2165
|
+
|
2166
|
+
type PrepareSendMessagesRequest<UI_MESSAGE extends UIMessage> = (options: {
|
2167
|
+
id: string;
|
2168
|
+
messages: UI_MESSAGE[];
|
2169
|
+
requestMetadata: unknown;
|
2170
|
+
body: Record<string, any> | undefined;
|
2171
|
+
credentials: RequestCredentials | undefined;
|
2172
|
+
headers: HeadersInit | undefined;
|
2173
|
+
api: string;
|
2174
|
+
} & {
|
2175
|
+
trigger: 'submit-user-message' | 'submit-tool-result' | 'regenerate-assistant-message';
|
2176
|
+
messageId: string | undefined;
|
2177
|
+
}) => {
|
2178
|
+
body: object;
|
2179
|
+
headers?: HeadersInit;
|
2180
|
+
credentials?: RequestCredentials;
|
2181
|
+
api?: string;
|
2182
|
+
} | PromiseLike<{
|
2183
|
+
body: object;
|
2184
|
+
headers?: HeadersInit;
|
2185
|
+
credentials?: RequestCredentials;
|
2186
|
+
api?: string;
|
2187
|
+
}>;
|
2188
|
+
type PrepareReconnectToStreamRequest = (options: {
|
2189
|
+
id: string;
|
2190
|
+
requestMetadata: unknown;
|
2191
|
+
body: Record<string, any> | undefined;
|
2192
|
+
credentials: RequestCredentials | undefined;
|
2193
|
+
headers: HeadersInit | undefined;
|
2194
|
+
api: string;
|
2195
|
+
}) => {
|
2196
|
+
headers?: HeadersInit;
|
2197
|
+
credentials?: RequestCredentials;
|
2198
|
+
api?: string;
|
2199
|
+
} | PromiseLike<{
|
2200
|
+
headers?: HeadersInit;
|
2201
|
+
credentials?: RequestCredentials;
|
2202
|
+
api?: string;
|
2203
|
+
}>;
|
2204
|
+
type HttpChatTransportInitOptions<UI_MESSAGE extends UIMessage> = {
|
2205
|
+
api?: string;
|
2135
2206
|
/**
|
2136
|
-
*
|
2207
|
+
* The credentials mode to be used for the fetch request.
|
2208
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
2209
|
+
* Defaults to 'same-origin'.
|
2137
2210
|
*/
|
2138
|
-
|
2211
|
+
credentials?: RequestCredentials;
|
2139
2212
|
/**
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2213
|
+
* HTTP headers to be sent with the API request.
|
2214
|
+
*/
|
2215
|
+
headers?: Record<string, string> | Headers;
|
2143
2216
|
/**
|
2144
|
-
|
2217
|
+
* Extra body object to be sent with the API request.
|
2218
|
+
* @example
|
2219
|
+
* Send a `sessionId` to the API along with the messages.
|
2220
|
+
* ```js
|
2221
|
+
* useChat({
|
2222
|
+
* body: {
|
2223
|
+
* sessionId: '123',
|
2224
|
+
* }
|
2225
|
+
* })
|
2226
|
+
* ```
|
2145
2227
|
*/
|
2146
|
-
|
2228
|
+
body?: object;
|
2147
2229
|
/**
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2230
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
2231
|
+
or to provide a custom fetch implementation for e.g. testing.
|
2232
|
+
*/
|
2233
|
+
fetch?: FetchFunction;
|
2151
2234
|
/**
|
2152
|
-
*
|
2235
|
+
* When a function is provided, it will be used
|
2236
|
+
* to prepare the request body for the chat API. This can be useful for
|
2237
|
+
* customizing the request body based on the messages and data in the chat.
|
2238
|
+
*
|
2239
|
+
* @param id The id of the chat.
|
2240
|
+
* @param messages The current messages in the chat.
|
2241
|
+
* @param requestBody The request body object passed in the chat request.
|
2153
2242
|
*/
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2243
|
+
prepareSendMessagesRequest?: PrepareSendMessagesRequest<UI_MESSAGE>;
|
2244
|
+
prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest;
|
2245
|
+
};
|
2246
|
+
declare abstract class HttpChatTransport<UI_MESSAGE extends UIMessage> implements ChatTransport<UI_MESSAGE> {
|
2247
|
+
protected api: string;
|
2248
|
+
protected credentials?: RequestCredentials;
|
2249
|
+
protected headers?: Record<string, string> | Headers;
|
2250
|
+
protected body?: object;
|
2251
|
+
protected fetch?: FetchFunction;
|
2252
|
+
protected prepareSendMessagesRequest?: PrepareSendMessagesRequest<UI_MESSAGE>;
|
2253
|
+
protected prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest;
|
2254
|
+
constructor({ api, credentials, headers, body, fetch, prepareSendMessagesRequest, prepareReconnectToStreamRequest, }: HttpChatTransportInitOptions<UI_MESSAGE>);
|
2255
|
+
sendMessages({ abortSignal, ...options }: Parameters<ChatTransport<UI_MESSAGE>['sendMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart>>;
|
2256
|
+
reconnectToStream(options: Parameters<ChatTransport<UI_MESSAGE>['reconnectToStream']>[0]): Promise<ReadableStream<UIMessageStreamPart> | null>;
|
2257
|
+
protected abstract processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageStreamPart>;
|
2258
|
+
}
|
2161
2259
|
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
/**
|
2174
|
-
* Indicates whether the response message is a continuation of the last original message,
|
2175
|
-
* or if a new message was created.
|
2176
|
-
*/
|
2177
|
-
isContinuation: boolean;
|
2178
|
-
/**
|
2179
|
-
* The message that was sent to the client as a response
|
2180
|
-
* (including the original message if it was extended).
|
2181
|
-
*/
|
2182
|
-
responseMessage: UI_MESSAGE;
|
2183
|
-
}) => void;
|
2260
|
+
declare class DefaultChatTransport<UI_MESSAGE extends UIMessage> extends HttpChatTransport<UI_MESSAGE> {
|
2261
|
+
constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
|
2262
|
+
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageStreamPart>;
|
2263
|
+
}
|
2264
|
+
|
2265
|
+
declare class TextStreamChatTransport<UI_MESSAGE extends UIMessage> extends HttpChatTransport<UI_MESSAGE> {
|
2266
|
+
constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
|
2267
|
+
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageStreamPart>;
|
2268
|
+
}
|
2269
|
+
|
2270
|
+
type CompletionRequestOptions = {
|
2184
2271
|
/**
|
2185
|
-
|
2186
|
-
*
|
2187
|
-
* Called on `start` and `finish` events.
|
2272
|
+
An optional object of headers to be passed to the API endpoint.
|
2188
2273
|
*/
|
2189
|
-
|
2190
|
-
part: TextStreamPart<ToolSet>;
|
2191
|
-
}) => InferUIMessageMetadata<UI_MESSAGE> | undefined;
|
2274
|
+
headers?: Record<string, string> | Headers;
|
2192
2275
|
/**
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2276
|
+
An optional object to be passed to the API endpoint.
|
2277
|
+
*/
|
2278
|
+
body?: object;
|
2279
|
+
};
|
2280
|
+
type UseCompletionOptions = {
|
2197
2281
|
/**
|
2198
|
-
*
|
2199
|
-
*
|
2282
|
+
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
2283
|
+
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
2200
2284
|
*/
|
2201
|
-
|
2285
|
+
api?: string;
|
2202
2286
|
/**
|
2203
|
-
*
|
2204
|
-
*
|
2205
|
-
*
|
2206
|
-
* Default to true.
|
2287
|
+
* An unique identifier for the chat. If not provided, a random one will be
|
2288
|
+
* generated. When provided, the `useChat` hook with the same `id` will
|
2289
|
+
* have shared states across components.
|
2207
2290
|
*/
|
2208
|
-
|
2291
|
+
id?: string;
|
2209
2292
|
/**
|
2210
|
-
*
|
2211
|
-
* Set to false if you are using additional streamText calls
|
2212
|
-
* and the message start event has already been sent.
|
2213
|
-
* Default to true.
|
2214
|
-
*
|
2215
|
-
* Note: this setting is currently not used, but you should
|
2216
|
-
* already set it to false if you are using additional
|
2217
|
-
* streamText calls that send additional data to prevent
|
2218
|
-
* the message start event from being sent multiple times.
|
2293
|
+
* Initial prompt input of the completion.
|
2219
2294
|
*/
|
2220
|
-
|
2295
|
+
initialInput?: string;
|
2221
2296
|
/**
|
2222
|
-
*
|
2223
|
-
*
|
2224
|
-
* @return error message to include in the data stream.
|
2297
|
+
* Initial completion result. Useful to load an existing history.
|
2225
2298
|
*/
|
2226
|
-
|
2227
|
-
};
|
2228
|
-
type ConsumeStreamOptions = {
|
2229
|
-
onError?: ErrorHandler;
|
2230
|
-
};
|
2231
|
-
/**
|
2232
|
-
A result object for accessing different stream types and additional information.
|
2233
|
-
*/
|
2234
|
-
interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
2299
|
+
initialCompletion?: string;
|
2235
2300
|
/**
|
2236
|
-
|
2237
|
-
|
2238
|
-
Resolved when the response is finished.
|
2301
|
+
* Callback function to be called when the completion is finished streaming.
|
2239
2302
|
*/
|
2240
|
-
|
2241
|
-
/**
|
2242
|
-
The full text that has been generated by the last step.
|
2243
|
-
|
2244
|
-
Resolved when the response is finished.
|
2245
|
-
*/
|
2246
|
-
readonly text: Promise<string>;
|
2303
|
+
onFinish?: (prompt: string, completion: string) => void;
|
2247
2304
|
/**
|
2248
|
-
|
2249
|
-
|
2250
|
-
Resolved when the response is finished.
|
2305
|
+
* Callback function to be called when an error is encountered.
|
2251
2306
|
*/
|
2252
|
-
|
2307
|
+
onError?: (error: Error) => void;
|
2253
2308
|
/**
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2309
|
+
* The credentials mode to be used for the fetch request.
|
2310
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
2311
|
+
* Defaults to 'same-origin'.
|
2312
|
+
*/
|
2313
|
+
credentials?: RequestCredentials;
|
2259
2314
|
/**
|
2260
|
-
|
2261
|
-
|
2262
|
-
Resolved when the response is finished.
|
2315
|
+
* HTTP headers to be sent with the API request.
|
2263
2316
|
*/
|
2264
|
-
|
2317
|
+
headers?: Record<string, string> | Headers;
|
2265
2318
|
/**
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2319
|
+
* Extra body object to be sent with the API request.
|
2320
|
+
* @example
|
2321
|
+
* Send a `sessionId` to the API along with the prompt.
|
2322
|
+
* ```js
|
2323
|
+
* useChat({
|
2324
|
+
* body: {
|
2325
|
+
* sessionId: '123',
|
2326
|
+
* }
|
2327
|
+
* })
|
2328
|
+
* ```
|
2269
2329
|
*/
|
2270
|
-
|
2330
|
+
body?: object;
|
2271
2331
|
/**
|
2272
|
-
|
2273
|
-
|
2274
|
-
Resolved when the response is finished.
|
2332
|
+
Streaming protocol that is used. Defaults to `data`.
|
2275
2333
|
*/
|
2276
|
-
|
2334
|
+
streamProtocol?: 'data' | 'text';
|
2277
2335
|
/**
|
2278
|
-
|
2279
|
-
|
2280
|
-
|
2281
|
-
|
2282
|
-
|
2336
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
2337
|
+
or to provide a custom fetch implementation for e.g. testing.
|
2338
|
+
*/
|
2339
|
+
fetch?: FetchFunction;
|
2340
|
+
};
|
2341
|
+
|
2342
|
+
/**
|
2343
|
+
* Calculates the cosine similarity between two vectors. This is a useful metric for
|
2344
|
+
* comparing the similarity of two vectors such as embeddings.
|
2345
|
+
*
|
2346
|
+
* @param vector1 - The first vector.
|
2347
|
+
* @param vector2 - The second vector.
|
2348
|
+
*
|
2349
|
+
* @returns The cosine similarity between vector1 and vector2.
|
2350
|
+
* @returns 0 if either vector is the zero vector.
|
2351
|
+
*
|
2352
|
+
* @throws {InvalidArgumentError} If the vectors do not have the same length.
|
2353
|
+
*/
|
2354
|
+
declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
|
2355
|
+
|
2356
|
+
/**
|
2357
|
+
* Converts a data URL of type text/* to a text string.
|
2358
|
+
*/
|
2359
|
+
declare function getTextFromDataUrl(dataUrl: string): string;
|
2360
|
+
|
2361
|
+
/**
|
2362
|
+
* Performs a deep-equal comparison of two parsed JSON objects.
|
2363
|
+
*
|
2364
|
+
* @param {any} obj1 - The first object to compare.
|
2365
|
+
* @param {any} obj2 - The second object to compare.
|
2366
|
+
* @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
|
2367
|
+
*/
|
2368
|
+
declare function isDeepEqualData(obj1: any, obj2: any): boolean;
|
2369
|
+
|
2370
|
+
declare function parsePartialJson(jsonText: string | undefined): Promise<{
|
2371
|
+
value: JSONValue$1 | undefined;
|
2372
|
+
state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
|
2373
|
+
}>;
|
2374
|
+
|
2375
|
+
type Job = () => Promise<void>;
|
2376
|
+
|
2377
|
+
declare class SerialJobExecutor {
|
2378
|
+
private queue;
|
2379
|
+
private isProcessing;
|
2380
|
+
private processQueue;
|
2381
|
+
run(job: Job): Promise<void>;
|
2382
|
+
}
|
2383
|
+
|
2384
|
+
/**
|
2385
|
+
* Creates a ReadableStream that emits the provided values with an optional delay between each value.
|
2386
|
+
*
|
2387
|
+
* @param options - The configuration options
|
2388
|
+
* @param options.chunks - Array of values to be emitted by the stream
|
2389
|
+
* @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
|
2390
|
+
* @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
|
2391
|
+
* @returns A ReadableStream that emits the provided values
|
2392
|
+
*/
|
2393
|
+
declare function simulateReadableStream<T>({ chunks, initialDelayInMs, chunkDelayInMs, _internal, }: {
|
2394
|
+
chunks: T[];
|
2395
|
+
initialDelayInMs?: number | null;
|
2396
|
+
chunkDelayInMs?: number | null;
|
2397
|
+
_internal?: {
|
2398
|
+
delay?: (ms: number | null) => Promise<void>;
|
2399
|
+
};
|
2400
|
+
}): ReadableStream<T>;
|
2401
|
+
|
2402
|
+
/**
|
2403
|
+
The result of an `embed` call.
|
2404
|
+
It contains the embedding, the value, and additional information.
|
2405
|
+
*/
|
2406
|
+
interface EmbedResult<VALUE> {
|
2283
2407
|
/**
|
2284
|
-
|
2285
|
-
|
2286
|
-
Resolved when the response is finished.
|
2408
|
+
The value that was embedded.
|
2287
2409
|
*/
|
2288
|
-
readonly
|
2410
|
+
readonly value: VALUE;
|
2289
2411
|
/**
|
2290
|
-
|
2291
|
-
|
2292
|
-
|
2293
|
-
*/
|
2294
|
-
readonly usage: Promise<LanguageModelUsage>;
|
2412
|
+
The embedding of the value.
|
2413
|
+
*/
|
2414
|
+
readonly embedding: Embedding;
|
2295
2415
|
/**
|
2296
|
-
|
2297
|
-
|
2298
|
-
|
2299
|
-
|
2416
|
+
The embedding token usage.
|
2417
|
+
*/
|
2418
|
+
readonly usage: EmbeddingModelUsage;
|
2419
|
+
/**
|
2420
|
+
Optional response data.
|
2300
2421
|
*/
|
2301
|
-
readonly
|
2422
|
+
readonly response?: {
|
2423
|
+
/**
|
2424
|
+
Response headers.
|
2425
|
+
*/
|
2426
|
+
headers?: Record<string, string>;
|
2427
|
+
/**
|
2428
|
+
The response body.
|
2429
|
+
*/
|
2430
|
+
body?: unknown;
|
2431
|
+
};
|
2432
|
+
}
|
2433
|
+
|
2434
|
+
/**
|
2435
|
+
Embed a value using an embedding model. The type of the value is defined by the embedding model.
|
2436
|
+
|
2437
|
+
@param model - The embedding model to use.
|
2438
|
+
@param value - The value that should be embedded.
|
2439
|
+
|
2440
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
2441
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2442
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2443
|
+
|
2444
|
+
@returns A result object that contains the embedding, the value, and additional information.
|
2445
|
+
*/
|
2446
|
+
declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
|
2302
2447
|
/**
|
2303
|
-
|
2448
|
+
The embedding model to use.
|
2304
2449
|
*/
|
2305
|
-
|
2450
|
+
model: EmbeddingModel<VALUE>;
|
2306
2451
|
/**
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2452
|
+
The value that should be embedded.
|
2453
|
+
*/
|
2454
|
+
value: VALUE;
|
2455
|
+
/**
|
2456
|
+
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
2457
|
+
|
2458
|
+
@default 2
|
2310
2459
|
*/
|
2311
|
-
|
2460
|
+
maxRetries?: number;
|
2312
2461
|
/**
|
2313
|
-
|
2462
|
+
Abort signal.
|
2314
2463
|
*/
|
2315
|
-
|
2464
|
+
abortSignal?: AbortSignal;
|
2316
2465
|
/**
|
2317
|
-
Additional
|
2466
|
+
Additional headers to include in the request.
|
2467
|
+
Only applicable for HTTP-based providers.
|
2318
2468
|
*/
|
2319
|
-
|
2320
|
-
/**
|
2321
|
-
The response messages that were generated during the call. It consists of an assistant message,
|
2322
|
-
potentially containing tool calls.
|
2323
|
-
|
2324
|
-
When there are tool results, there is an additional tool message with the tool results that are available.
|
2325
|
-
If there are tools that do not have execute functions, they are not included in the tool results and
|
2326
|
-
need to be added separately.
|
2327
|
-
*/
|
2328
|
-
messages: Array<ResponseMessage>;
|
2329
|
-
}>;
|
2469
|
+
headers?: Record<string, string>;
|
2330
2470
|
/**
|
2331
|
-
|
2332
|
-
|
2333
|
-
|
2471
|
+
Additional provider-specific options. They are passed through
|
2472
|
+
to the provider from the AI SDK and enable provider-specific
|
2473
|
+
functionality that can be fully encapsulated in the provider.
|
2474
|
+
*/
|
2475
|
+
providerOptions?: ProviderOptions;
|
2476
|
+
/**
|
2477
|
+
* Optional telemetry configuration (experimental).
|
2334
2478
|
*/
|
2335
|
-
|
2479
|
+
experimental_telemetry?: TelemetrySettings;
|
2480
|
+
}): Promise<EmbedResult<VALUE>>;
|
2481
|
+
|
2482
|
+
/**
|
2483
|
+
The result of a `embedMany` call.
|
2484
|
+
It contains the embeddings, the values, and additional information.
|
2485
|
+
*/
|
2486
|
+
interface EmbedManyResult<VALUE> {
|
2336
2487
|
/**
|
2337
|
-
|
2338
|
-
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
2339
|
-
stream will throw the error.
|
2488
|
+
The values that were embedded.
|
2340
2489
|
*/
|
2341
|
-
readonly
|
2490
|
+
readonly values: Array<VALUE>;
|
2342
2491
|
/**
|
2343
|
-
|
2344
|
-
|
2345
|
-
|
2346
|
-
|
2492
|
+
The embeddings. They are in the same order as the values.
|
2493
|
+
*/
|
2494
|
+
readonly embeddings: Array<Embedding>;
|
2495
|
+
/**
|
2496
|
+
The embedding token usage.
|
2497
|
+
*/
|
2498
|
+
readonly usage: EmbeddingModelUsage;
|
2499
|
+
/**
|
2500
|
+
Optional raw response data.
|
2347
2501
|
*/
|
2348
|
-
readonly
|
2502
|
+
readonly responses?: Array<{
|
2503
|
+
/**
|
2504
|
+
Response headers.
|
2505
|
+
*/
|
2506
|
+
headers?: Record<string, string>;
|
2507
|
+
/**
|
2508
|
+
The response body.
|
2509
|
+
*/
|
2510
|
+
body?: unknown;
|
2511
|
+
} | undefined>;
|
2512
|
+
}
|
2513
|
+
|
2514
|
+
/**
|
2515
|
+
Embed several values using an embedding model. The type of the value is defined
|
2516
|
+
by the embedding model.
|
2517
|
+
|
2518
|
+
`embedMany` automatically splits large requests into smaller chunks if the model
|
2519
|
+
has a limit on how many embeddings can be generated in a single call.
|
2520
|
+
|
2521
|
+
@param model - The embedding model to use.
|
2522
|
+
@param values - The values that should be embedded.
|
2523
|
+
|
2524
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
2525
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2526
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2527
|
+
|
2528
|
+
@returns A result object that contains the embeddings, the value, and additional information.
|
2529
|
+
*/
|
2530
|
+
declare function embedMany<VALUE>({ model, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
2349
2531
|
/**
|
2350
|
-
|
2532
|
+
The embedding model to use.
|
2533
|
+
*/
|
2534
|
+
model: EmbeddingModel<VALUE>;
|
2535
|
+
/**
|
2536
|
+
The values that should be embedded.
|
2351
2537
|
*/
|
2352
|
-
|
2538
|
+
values: Array<VALUE>;
|
2353
2539
|
/**
|
2354
|
-
|
2355
|
-
This is useful to force the stream to finish.
|
2356
|
-
It effectively removes the backpressure and allows the stream to finish,
|
2357
|
-
triggering the `onFinish` callback and the promise resolution.
|
2540
|
+
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
2358
2541
|
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2542
|
+
@default 2
|
2543
|
+
*/
|
2544
|
+
maxRetries?: number;
|
2362
2545
|
/**
|
2363
|
-
|
2364
|
-
|
2365
|
-
|
2366
|
-
@param options.sendUsage whether to send the usage information to the client. Defaults to true.
|
2367
|
-
@param options.sendReasoning whether to send the reasoning information to the client. Defaults to false.
|
2368
|
-
@param options.sendSources whether to send the sources information to the client. Defaults to false.
|
2369
|
-
@param options.experimental_sendFinish whether to send the finish information to the client. Defaults to true.
|
2370
|
-
@param options.experimental_sendStart whether to send the start information to the client. Defaults to true.
|
2371
|
-
|
2372
|
-
@return A UI message stream.
|
2373
|
-
*/
|
2374
|
-
toUIMessageStream<UI_MESSAGE extends UIMessage>(options?: UIMessageStreamOptions<UI_MESSAGE>): ReadableStream<InferUIMessageStreamPart<UI_MESSAGE>>;
|
2546
|
+
Abort signal.
|
2547
|
+
*/
|
2548
|
+
abortSignal?: AbortSignal;
|
2375
2549
|
/**
|
2376
|
-
|
2377
|
-
|
2378
|
-
|
2379
|
-
|
2380
|
-
@param options.headers The headers.
|
2381
|
-
@param options.getErrorMessage An optional function that converts an error to an error message.
|
2382
|
-
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
2383
|
-
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
2384
|
-
*/
|
2385
|
-
pipeUIMessageStreamToResponse<UI_MESSAGE extends UIMessage>(response: ServerResponse, options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): void;
|
2550
|
+
Additional headers to include in the request.
|
2551
|
+
Only applicable for HTTP-based providers.
|
2552
|
+
*/
|
2553
|
+
headers?: Record<string, string>;
|
2386
2554
|
/**
|
2387
|
-
|
2388
|
-
|
2389
|
-
|
2390
|
-
@param response A Node.js response-like object (ServerResponse).
|
2391
|
-
@param init Optional headers, status code, and status text.
|
2392
|
-
*/
|
2393
|
-
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
|
2555
|
+
* Optional telemetry configuration (experimental).
|
2556
|
+
*/
|
2557
|
+
experimental_telemetry?: TelemetrySettings;
|
2394
2558
|
/**
|
2395
|
-
|
2396
|
-
|
2397
|
-
|
2398
|
-
|
2399
|
-
|
2400
|
-
@param options.getErrorMessage An optional function that converts an error to an error message.
|
2401
|
-
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
2402
|
-
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
2403
|
-
@return A response object.
|
2404
|
-
*/
|
2405
|
-
toUIMessageStreamResponse<UI_MESSAGE extends UIMessage>(options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): Response;
|
2559
|
+
Additional provider-specific options. They are passed through
|
2560
|
+
to the provider from the AI SDK and enable provider-specific
|
2561
|
+
functionality that can be fully encapsulated in the provider.
|
2562
|
+
*/
|
2563
|
+
providerOptions?: ProviderOptions;
|
2406
2564
|
/**
|
2407
|
-
|
2408
|
-
|
2409
|
-
|
2410
|
-
|
2411
|
-
|
2412
|
-
|
2413
|
-
}
|
2414
|
-
type TextStreamPart<TOOLS extends ToolSet> = {
|
2415
|
-
type: 'text-start';
|
2416
|
-
id: string;
|
2417
|
-
providerMetadata?: ProviderMetadata;
|
2418
|
-
} | {
|
2419
|
-
type: 'text-end';
|
2420
|
-
id: string;
|
2421
|
-
providerMetadata?: ProviderMetadata;
|
2422
|
-
} | {
|
2423
|
-
type: 'text';
|
2424
|
-
id: string;
|
2425
|
-
providerMetadata?: ProviderMetadata;
|
2426
|
-
text: string;
|
2427
|
-
} | {
|
2428
|
-
type: 'reasoning-start';
|
2429
|
-
id: string;
|
2430
|
-
providerMetadata?: ProviderMetadata;
|
2431
|
-
} | {
|
2432
|
-
type: 'reasoning-end';
|
2433
|
-
id: string;
|
2434
|
-
providerMetadata?: ProviderMetadata;
|
2435
|
-
} | {
|
2436
|
-
type: 'reasoning';
|
2437
|
-
providerMetadata?: ProviderMetadata;
|
2438
|
-
id: string;
|
2439
|
-
text: string;
|
2440
|
-
} | {
|
2441
|
-
type: 'tool-input-start';
|
2442
|
-
id: string;
|
2443
|
-
toolName: string;
|
2444
|
-
providerMetadata?: ProviderMetadata;
|
2445
|
-
providerExecuted?: boolean;
|
2446
|
-
} | {
|
2447
|
-
type: 'tool-input-end';
|
2448
|
-
id: string;
|
2449
|
-
providerMetadata?: ProviderMetadata;
|
2450
|
-
} | {
|
2451
|
-
type: 'tool-input-delta';
|
2452
|
-
id: string;
|
2453
|
-
delta: string;
|
2454
|
-
providerMetadata?: ProviderMetadata;
|
2455
|
-
} | ({
|
2456
|
-
type: 'source';
|
2457
|
-
} & Source) | {
|
2458
|
-
type: 'file';
|
2459
|
-
file: GeneratedFile;
|
2460
|
-
} | ({
|
2461
|
-
type: 'tool-call';
|
2462
|
-
} & ToolCallUnion<TOOLS>) | ({
|
2463
|
-
type: 'tool-result';
|
2464
|
-
} & ToolResultUnion<TOOLS>) | ({
|
2465
|
-
type: 'tool-error';
|
2466
|
-
} & ToolErrorUnion<TOOLS>) | {
|
2467
|
-
type: 'start-step';
|
2468
|
-
request: LanguageModelRequestMetadata;
|
2469
|
-
warnings: CallWarning[];
|
2470
|
-
} | {
|
2471
|
-
type: 'finish-step';
|
2472
|
-
response: LanguageModelResponseMetadata;
|
2473
|
-
usage: LanguageModelUsage;
|
2474
|
-
finishReason: FinishReason;
|
2475
|
-
providerMetadata: ProviderMetadata | undefined;
|
2476
|
-
} | {
|
2477
|
-
type: 'start';
|
2478
|
-
} | {
|
2479
|
-
type: 'finish';
|
2480
|
-
finishReason: FinishReason;
|
2481
|
-
totalUsage: LanguageModelUsage;
|
2482
|
-
} | {
|
2483
|
-
type: 'error';
|
2484
|
-
error: unknown;
|
2485
|
-
} | {
|
2486
|
-
type: 'raw';
|
2487
|
-
rawValue: unknown;
|
2488
|
-
};
|
2565
|
+
* Maximum number of concurrent requests.
|
2566
|
+
*
|
2567
|
+
* @default Infinity
|
2568
|
+
*/
|
2569
|
+
maxParallelCalls?: number;
|
2570
|
+
}): Promise<EmbedManyResult<VALUE>>;
|
2489
2571
|
|
2490
2572
|
/**
|
2491
2573
|
* Detects the first chunk in a buffer.
|
@@ -3826,4 +3908,4 @@ declare global {
|
|
3826
3908
|
var AI_SDK_DEFAULT_PROVIDER: ProviderV2 | undefined;
|
3827
3909
|
}
|
3828
3910
|
|
3829
|
-
export { AbstractChat, CallSettings, CallWarning, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferUIDataParts, InferUITool, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolErrorUnion, ToolResultUnion, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UITool, UITools, UI_MESSAGE_STREAM_HEADERS, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, hasToolCall, isDeepEqualData, isToolUIPart, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel };
|
3911
|
+
export { AbstractChat, CallSettings, CallWarning, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, Agent as Experimental_Agent, AgentSettings as Experimental_AgentSettings, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferUIDataParts, InferUITool, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolErrorUnion, ToolResultUnion, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UITool, UITools, UI_MESSAGE_STREAM_HEADERS, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, hasToolCall, isDeepEqualData, isToolUIPart, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel };
|