ai 5.0.0-canary.19 → 5.0.0-canary.20
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 +23 -0
- package/dist/index.d.mts +2335 -2332
- package/dist/index.d.ts +2335 -2332
- package/dist/index.js +3761 -3769
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3829 -3819
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +95 -677
- package/dist/internal/index.d.ts +95 -677
- package/dist/internal/index.js +210 -476
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +204 -471
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +3 -3
- package/dist/mcp-stdio/index.d.ts +3 -3
- package/dist/mcp-stdio/index.js +1 -4
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs +1 -16
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/dist/test/index.d.mts +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.js +5 -1
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +5 -1
- package/dist/test/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/internal/index.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import { ToolResultContent, Schema } from '@ai-sdk/provider-utils';
|
2
|
+
export { convertAsyncIteratorToReadableStream } from '@ai-sdk/provider-utils';
|
3
|
+
import { SharedV2ProviderOptions, LanguageModelV2Prompt, JSONValue, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice } from '@ai-sdk/provider';
|
3
4
|
import { z } from 'zod';
|
4
5
|
|
5
6
|
declare function download({ url }: {
|
@@ -240,215 +241,6 @@ It can be a user message, an assistant message, or a tool message.
|
|
240
241
|
*/
|
241
242
|
type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
242
243
|
|
243
|
-
/**
|
244
|
-
Tool choice for the generation. It supports the following settings:
|
245
|
-
|
246
|
-
- `auto` (default): the model can choose whether and which tools to call.
|
247
|
-
- `required`: the model must call a tool. It can choose which tool to call.
|
248
|
-
- `none`: the model must not call tools
|
249
|
-
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
250
|
-
*/
|
251
|
-
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
252
|
-
type: 'tool';
|
253
|
-
toolName: Extract<keyof TOOLS, string>;
|
254
|
-
};
|
255
|
-
|
256
|
-
/**
|
257
|
-
Tool invocations are either tool calls or tool results. For each assistant tool call,
|
258
|
-
there is one tool invocation. While the call is in progress, the invocation is a tool call.
|
259
|
-
Once the call is complete, the invocation is a tool result.
|
260
|
-
|
261
|
-
The step is used to track how to map an assistant UI message with many tool invocations
|
262
|
-
back to a sequence of LLM assistant/tool result message pairs.
|
263
|
-
It is optional for backwards compatibility.
|
264
|
-
*/
|
265
|
-
type ToolInvocation = ({
|
266
|
-
state: 'partial-call';
|
267
|
-
step?: number;
|
268
|
-
} & ToolCall<string, any>) | ({
|
269
|
-
state: 'call';
|
270
|
-
step?: number;
|
271
|
-
} & ToolCall<string, any>) | ({
|
272
|
-
state: 'result';
|
273
|
-
step?: number;
|
274
|
-
} & ToolResult<string, any, any>);
|
275
|
-
/**
|
276
|
-
* AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
277
|
-
*/
|
278
|
-
interface UIMessage {
|
279
|
-
/**
|
280
|
-
A unique identifier for the message.
|
281
|
-
*/
|
282
|
-
id: string;
|
283
|
-
/**
|
284
|
-
The timestamp of the message.
|
285
|
-
*/
|
286
|
-
createdAt?: Date;
|
287
|
-
/**
|
288
|
-
The role of the message.
|
289
|
-
*/
|
290
|
-
role: 'system' | 'user' | 'assistant';
|
291
|
-
/**
|
292
|
-
Additional message-specific information added on the server via StreamData
|
293
|
-
*/
|
294
|
-
annotations?: JSONValue[] | undefined;
|
295
|
-
/**
|
296
|
-
The parts of the message. Use this for rendering the message in the UI.
|
297
|
-
|
298
|
-
System messages should be avoided (set the system prompt on the server instead).
|
299
|
-
They can have text parts.
|
300
|
-
|
301
|
-
User messages can have text parts and file parts.
|
302
|
-
|
303
|
-
Assistant messages can have text, reasoning, tool invocation, and file parts.
|
304
|
-
*/
|
305
|
-
parts: Array<UIMessagePart>;
|
306
|
-
}
|
307
|
-
type UIMessagePart = TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart;
|
308
|
-
/**
|
309
|
-
* A text part of a message.
|
310
|
-
*/
|
311
|
-
type TextUIPart = {
|
312
|
-
type: 'text';
|
313
|
-
/**
|
314
|
-
* The text content.
|
315
|
-
*/
|
316
|
-
text: string;
|
317
|
-
};
|
318
|
-
/**
|
319
|
-
* A reasoning part of a message.
|
320
|
-
*/
|
321
|
-
type ReasoningUIPart = {
|
322
|
-
type: 'reasoning';
|
323
|
-
/**
|
324
|
-
* The reasoning text.
|
325
|
-
*/
|
326
|
-
text: string;
|
327
|
-
/**
|
328
|
-
* The provider metadata.
|
329
|
-
*/
|
330
|
-
providerMetadata?: Record<string, any>;
|
331
|
-
};
|
332
|
-
/**
|
333
|
-
* A tool invocation part of a message.
|
334
|
-
*/
|
335
|
-
type ToolInvocationUIPart = {
|
336
|
-
type: 'tool-invocation';
|
337
|
-
/**
|
338
|
-
* The tool invocation.
|
339
|
-
*/
|
340
|
-
toolInvocation: ToolInvocation;
|
341
|
-
};
|
342
|
-
/**
|
343
|
-
* A source part of a message.
|
344
|
-
*/
|
345
|
-
type SourceUIPart = {
|
346
|
-
type: 'source';
|
347
|
-
/**
|
348
|
-
* The source.
|
349
|
-
*/
|
350
|
-
source: LanguageModelV2Source;
|
351
|
-
};
|
352
|
-
/**
|
353
|
-
* A file part of a message.
|
354
|
-
*/
|
355
|
-
type FileUIPart = {
|
356
|
-
type: 'file';
|
357
|
-
/**
|
358
|
-
* IANA media type of the file.
|
359
|
-
*
|
360
|
-
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
361
|
-
*/
|
362
|
-
mediaType: string;
|
363
|
-
/**
|
364
|
-
* Optional filename of the file.
|
365
|
-
*/
|
366
|
-
filename?: string;
|
367
|
-
/**
|
368
|
-
* The URL of the file.
|
369
|
-
* 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).
|
370
|
-
*/
|
371
|
-
url: string;
|
372
|
-
};
|
373
|
-
/**
|
374
|
-
* A step boundary part of a message.
|
375
|
-
*/
|
376
|
-
type StepStartUIPart = {
|
377
|
-
type: 'step-start';
|
378
|
-
};
|
379
|
-
|
380
|
-
type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
|
381
|
-
interface ToolExecutionOptions {
|
382
|
-
/**
|
383
|
-
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
384
|
-
*/
|
385
|
-
toolCallId: string;
|
386
|
-
/**
|
387
|
-
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
388
|
-
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
389
|
-
*/
|
390
|
-
messages: ModelMessage[];
|
391
|
-
/**
|
392
|
-
* An optional abort signal that indicates that the overall operation should be aborted.
|
393
|
-
*/
|
394
|
-
abortSignal?: AbortSignal;
|
395
|
-
}
|
396
|
-
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
397
|
-
/**
|
398
|
-
A tool contains the description and the schema of the input that the tool expects.
|
399
|
-
This enables the language model to generate the input.
|
400
|
-
|
401
|
-
The tool can also contain an optional execute function for the actual execution function of the tool.
|
402
|
-
*/
|
403
|
-
type Tool<PARAMETERS extends JSONValue | unknown | never = any, RESULT = any> = {
|
404
|
-
/**
|
405
|
-
An optional description of what the tool does.
|
406
|
-
Will be used by the language model to decide whether to use the tool.
|
407
|
-
Not used for provider-defined tools.
|
408
|
-
*/
|
409
|
-
description?: string;
|
410
|
-
} & NeverOptional<PARAMETERS, {
|
411
|
-
/**
|
412
|
-
The schema of the input that the tool expects. The language model will use this to generate the input.
|
413
|
-
It is also used to validate the output of the language model.
|
414
|
-
Use descriptions to make the input understandable for the language model.
|
415
|
-
*/
|
416
|
-
parameters: ToolParameters<PARAMETERS>;
|
417
|
-
}> & NeverOptional<RESULT, {
|
418
|
-
/**
|
419
|
-
An async function that is called with the arguments from the tool call and produces a result.
|
420
|
-
If not provided, the tool will not be executed automatically.
|
421
|
-
|
422
|
-
@args is the input of the tool call.
|
423
|
-
@options.abortSignal is a signal that can be used to abort the tool call.
|
424
|
-
*/
|
425
|
-
execute: (args: [PARAMETERS] extends [never] ? undefined : PARAMETERS, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
426
|
-
/**
|
427
|
-
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
428
|
-
*/
|
429
|
-
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
430
|
-
}> & ({
|
431
|
-
/**
|
432
|
-
Function tool.
|
433
|
-
*/
|
434
|
-
type?: undefined | 'function';
|
435
|
-
} | {
|
436
|
-
/**
|
437
|
-
Provider-defined tool.
|
438
|
-
*/
|
439
|
-
type: 'provider-defined';
|
440
|
-
/**
|
441
|
-
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
442
|
-
*/
|
443
|
-
id: `${string}.${string}`;
|
444
|
-
/**
|
445
|
-
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
446
|
-
*/
|
447
|
-
args: Record<string, unknown>;
|
448
|
-
});
|
449
|
-
|
450
|
-
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute'>>;
|
451
|
-
|
452
244
|
/**
|
453
245
|
Prompt part of the AI function options.
|
454
246
|
It contains a system message, a simple text prompt, or a list of messages.
|
@@ -459,13 +251,17 @@ type Prompt = {
|
|
459
251
|
*/
|
460
252
|
system?: string;
|
461
253
|
/**
|
462
|
-
A
|
463
|
-
|
464
|
-
|
254
|
+
A prompt. It can be either a text prompt or a list of messages.
|
255
|
+
|
256
|
+
You can either use `prompt` or `messages` but not both.
|
257
|
+
*/
|
258
|
+
prompt?: string | Array<ModelMessage>;
|
465
259
|
/**
|
466
|
-
A list of messages.
|
260
|
+
A list of messages.
|
261
|
+
|
262
|
+
You can either use `prompt` or `messages` but not both.
|
467
263
|
*/
|
468
|
-
messages?: Array<ModelMessage
|
264
|
+
messages?: Array<ModelMessage>;
|
469
265
|
};
|
470
266
|
|
471
267
|
type StandardizedPrompt = {
|
@@ -478,10 +274,7 @@ type StandardizedPrompt = {
|
|
478
274
|
*/
|
479
275
|
messages: ModelMessage[];
|
480
276
|
};
|
481
|
-
declare function standardizePrompt
|
482
|
-
prompt: Prompt;
|
483
|
-
tools: undefined | TOOLS;
|
484
|
-
}): Promise<StandardizedPrompt>;
|
277
|
+
declare function standardizePrompt(prompt: Prompt): Promise<StandardizedPrompt>;
|
485
278
|
|
486
279
|
declare function convertToLanguageModelPrompt({ prompt, supportedUrls, downloadImplementation, }: {
|
487
280
|
prompt: StandardizedPrompt;
|
@@ -571,436 +364,90 @@ declare function prepareCallSettings({ maxOutputTokens, temperature, topP, topK,
|
|
571
364
|
temperature?: number;
|
572
365
|
};
|
573
366
|
|
574
|
-
type RetryFunction = <OUTPUT>(fn: () => PromiseLike<OUTPUT>) => PromiseLike<OUTPUT>;
|
575
|
-
|
576
367
|
/**
|
577
|
-
|
368
|
+
Tool choice for the generation. It supports the following settings:
|
369
|
+
|
370
|
+
- `auto` (default): the model can choose whether and which tools to call.
|
371
|
+
- `required`: the model must call a tool. It can choose which tool to call.
|
372
|
+
- `none`: the model must not call tools
|
373
|
+
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
578
374
|
*/
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
maxRetries: number;
|
583
|
-
retry: RetryFunction;
|
375
|
+
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
376
|
+
type: 'tool';
|
377
|
+
toolName: Extract<keyof TOOLS, string>;
|
584
378
|
};
|
585
379
|
|
586
|
-
|
587
|
-
|
588
|
-
value: z.ZodString;
|
589
|
-
}, "strip", z.ZodTypeAny, {
|
590
|
-
value: string;
|
591
|
-
type: "text";
|
592
|
-
}, {
|
593
|
-
value: string;
|
594
|
-
type: "text";
|
595
|
-
}>, z.ZodObject<{
|
596
|
-
type: z.ZodLiteral<"data">;
|
597
|
-
value: z.ZodArray<z.ZodAny, "many">;
|
598
|
-
}, "strip", z.ZodTypeAny, {
|
599
|
-
value: any[];
|
600
|
-
type: "data";
|
601
|
-
}, {
|
602
|
-
value: any[];
|
603
|
-
type: "data";
|
604
|
-
}>, z.ZodObject<{
|
605
|
-
type: z.ZodLiteral<"error">;
|
606
|
-
value: z.ZodString;
|
607
|
-
}, "strip", z.ZodTypeAny, {
|
608
|
-
value: string;
|
609
|
-
type: "error";
|
610
|
-
}, {
|
611
|
-
value: string;
|
612
|
-
type: "error";
|
613
|
-
}>, z.ZodObject<{
|
614
|
-
type: z.ZodLiteral<"message-annotations">;
|
615
|
-
value: z.ZodArray<z.ZodAny, "many">;
|
616
|
-
}, "strip", z.ZodTypeAny, {
|
617
|
-
value: any[];
|
618
|
-
type: "message-annotations";
|
619
|
-
}, {
|
620
|
-
value: any[];
|
621
|
-
type: "message-annotations";
|
622
|
-
}>, z.ZodObject<{
|
623
|
-
type: z.ZodLiteral<"tool-call">;
|
624
|
-
value: z.ZodObject<{
|
625
|
-
toolCallId: z.ZodString;
|
626
|
-
toolName: z.ZodString;
|
627
|
-
args: z.ZodUnknown;
|
628
|
-
}, "strip", z.ZodTypeAny, {
|
629
|
-
toolCallId: string;
|
630
|
-
toolName: string;
|
631
|
-
args?: unknown;
|
632
|
-
}, {
|
633
|
-
toolCallId: string;
|
634
|
-
toolName: string;
|
635
|
-
args?: unknown;
|
636
|
-
}>;
|
637
|
-
}, "strip", z.ZodTypeAny, {
|
638
|
-
value: {
|
639
|
-
toolCallId: string;
|
640
|
-
toolName: string;
|
641
|
-
args?: unknown;
|
642
|
-
};
|
643
|
-
type: "tool-call";
|
644
|
-
}, {
|
645
|
-
value: {
|
646
|
-
toolCallId: string;
|
647
|
-
toolName: string;
|
648
|
-
args?: unknown;
|
649
|
-
};
|
650
|
-
type: "tool-call";
|
651
|
-
}>, z.ZodObject<{
|
652
|
-
type: z.ZodLiteral<"tool-result">;
|
653
|
-
value: z.ZodObject<{
|
654
|
-
toolCallId: z.ZodString;
|
655
|
-
result: z.ZodUnknown;
|
656
|
-
providerMetadata: z.ZodOptional<z.ZodAny>;
|
657
|
-
}, "strip", z.ZodTypeAny, {
|
658
|
-
toolCallId: string;
|
659
|
-
result?: unknown;
|
660
|
-
providerMetadata?: any;
|
661
|
-
}, {
|
662
|
-
toolCallId: string;
|
663
|
-
result?: unknown;
|
664
|
-
providerMetadata?: any;
|
665
|
-
}>;
|
666
|
-
}, "strip", z.ZodTypeAny, {
|
667
|
-
value: {
|
668
|
-
toolCallId: string;
|
669
|
-
result?: unknown;
|
670
|
-
providerMetadata?: any;
|
671
|
-
};
|
672
|
-
type: "tool-result";
|
673
|
-
}, {
|
674
|
-
value: {
|
675
|
-
toolCallId: string;
|
676
|
-
result?: unknown;
|
677
|
-
providerMetadata?: any;
|
678
|
-
};
|
679
|
-
type: "tool-result";
|
680
|
-
}>, z.ZodObject<{
|
681
|
-
type: z.ZodLiteral<"tool-call-streaming-start">;
|
682
|
-
value: z.ZodObject<{
|
683
|
-
toolCallId: z.ZodString;
|
684
|
-
toolName: z.ZodString;
|
685
|
-
}, "strip", z.ZodTypeAny, {
|
686
|
-
toolCallId: string;
|
687
|
-
toolName: string;
|
688
|
-
}, {
|
689
|
-
toolCallId: string;
|
690
|
-
toolName: string;
|
691
|
-
}>;
|
692
|
-
}, "strip", z.ZodTypeAny, {
|
693
|
-
value: {
|
694
|
-
toolCallId: string;
|
695
|
-
toolName: string;
|
696
|
-
};
|
697
|
-
type: "tool-call-streaming-start";
|
698
|
-
}, {
|
699
|
-
value: {
|
700
|
-
toolCallId: string;
|
701
|
-
toolName: string;
|
702
|
-
};
|
703
|
-
type: "tool-call-streaming-start";
|
704
|
-
}>, z.ZodObject<{
|
705
|
-
type: z.ZodLiteral<"tool-call-delta">;
|
706
|
-
value: z.ZodObject<{
|
707
|
-
toolCallId: z.ZodString;
|
708
|
-
argsTextDelta: z.ZodString;
|
709
|
-
}, "strip", z.ZodTypeAny, {
|
710
|
-
toolCallId: string;
|
711
|
-
argsTextDelta: string;
|
712
|
-
}, {
|
713
|
-
toolCallId: string;
|
714
|
-
argsTextDelta: string;
|
715
|
-
}>;
|
716
|
-
}, "strip", z.ZodTypeAny, {
|
717
|
-
value: {
|
718
|
-
toolCallId: string;
|
719
|
-
argsTextDelta: string;
|
720
|
-
};
|
721
|
-
type: "tool-call-delta";
|
722
|
-
}, {
|
723
|
-
value: {
|
724
|
-
toolCallId: string;
|
725
|
-
argsTextDelta: string;
|
726
|
-
};
|
727
|
-
type: "tool-call-delta";
|
728
|
-
}>, z.ZodObject<{
|
729
|
-
type: z.ZodLiteral<"finish-message">;
|
730
|
-
value: z.ZodObject<{
|
731
|
-
finishReason: z.ZodEnum<["stop", "length", "tool-calls", "content-filter", "other", "error", "unknown"]>;
|
732
|
-
usage: z.ZodOptional<z.ZodObject<{
|
733
|
-
inputTokens: z.ZodOptional<z.ZodNumber>;
|
734
|
-
outputTokens: z.ZodOptional<z.ZodNumber>;
|
735
|
-
totalTokens: z.ZodOptional<z.ZodNumber>;
|
736
|
-
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
737
|
-
cachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
738
|
-
}, "strip", z.ZodTypeAny, {
|
739
|
-
inputTokens?: number | undefined;
|
740
|
-
outputTokens?: number | undefined;
|
741
|
-
totalTokens?: number | undefined;
|
742
|
-
reasoningTokens?: number | undefined;
|
743
|
-
cachedInputTokens?: number | undefined;
|
744
|
-
}, {
|
745
|
-
inputTokens?: number | undefined;
|
746
|
-
outputTokens?: number | undefined;
|
747
|
-
totalTokens?: number | undefined;
|
748
|
-
reasoningTokens?: number | undefined;
|
749
|
-
cachedInputTokens?: number | undefined;
|
750
|
-
}>>;
|
751
|
-
}, "strip", z.ZodTypeAny, {
|
752
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
753
|
-
usage?: {
|
754
|
-
inputTokens?: number | undefined;
|
755
|
-
outputTokens?: number | undefined;
|
756
|
-
totalTokens?: number | undefined;
|
757
|
-
reasoningTokens?: number | undefined;
|
758
|
-
cachedInputTokens?: number | undefined;
|
759
|
-
} | undefined;
|
760
|
-
}, {
|
761
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
762
|
-
usage?: {
|
763
|
-
inputTokens?: number | undefined;
|
764
|
-
outputTokens?: number | undefined;
|
765
|
-
totalTokens?: number | undefined;
|
766
|
-
reasoningTokens?: number | undefined;
|
767
|
-
cachedInputTokens?: number | undefined;
|
768
|
-
} | undefined;
|
769
|
-
}>;
|
770
|
-
}, "strip", z.ZodTypeAny, {
|
771
|
-
value: {
|
772
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
773
|
-
usage?: {
|
774
|
-
inputTokens?: number | undefined;
|
775
|
-
outputTokens?: number | undefined;
|
776
|
-
totalTokens?: number | undefined;
|
777
|
-
reasoningTokens?: number | undefined;
|
778
|
-
cachedInputTokens?: number | undefined;
|
779
|
-
} | undefined;
|
780
|
-
};
|
781
|
-
type: "finish-message";
|
782
|
-
}, {
|
783
|
-
value: {
|
784
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
785
|
-
usage?: {
|
786
|
-
inputTokens?: number | undefined;
|
787
|
-
outputTokens?: number | undefined;
|
788
|
-
totalTokens?: number | undefined;
|
789
|
-
reasoningTokens?: number | undefined;
|
790
|
-
cachedInputTokens?: number | undefined;
|
791
|
-
} | undefined;
|
792
|
-
};
|
793
|
-
type: "finish-message";
|
794
|
-
}>, z.ZodObject<{
|
795
|
-
type: z.ZodLiteral<"finish-step">;
|
796
|
-
value: z.ZodObject<{
|
797
|
-
isContinued: z.ZodBoolean;
|
798
|
-
finishReason: z.ZodEnum<["stop", "length", "tool-calls", "content-filter", "other", "error", "unknown"]>;
|
799
|
-
usage: z.ZodOptional<z.ZodObject<{
|
800
|
-
inputTokens: z.ZodOptional<z.ZodNumber>;
|
801
|
-
outputTokens: z.ZodOptional<z.ZodNumber>;
|
802
|
-
totalTokens: z.ZodOptional<z.ZodNumber>;
|
803
|
-
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
804
|
-
cachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
805
|
-
}, "strip", z.ZodTypeAny, {
|
806
|
-
inputTokens?: number | undefined;
|
807
|
-
outputTokens?: number | undefined;
|
808
|
-
totalTokens?: number | undefined;
|
809
|
-
reasoningTokens?: number | undefined;
|
810
|
-
cachedInputTokens?: number | undefined;
|
811
|
-
}, {
|
812
|
-
inputTokens?: number | undefined;
|
813
|
-
outputTokens?: number | undefined;
|
814
|
-
totalTokens?: number | undefined;
|
815
|
-
reasoningTokens?: number | undefined;
|
816
|
-
cachedInputTokens?: number | undefined;
|
817
|
-
}>>;
|
818
|
-
}, "strip", z.ZodTypeAny, {
|
819
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
820
|
-
isContinued: boolean;
|
821
|
-
usage?: {
|
822
|
-
inputTokens?: number | undefined;
|
823
|
-
outputTokens?: number | undefined;
|
824
|
-
totalTokens?: number | undefined;
|
825
|
-
reasoningTokens?: number | undefined;
|
826
|
-
cachedInputTokens?: number | undefined;
|
827
|
-
} | undefined;
|
828
|
-
}, {
|
829
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
830
|
-
isContinued: boolean;
|
831
|
-
usage?: {
|
832
|
-
inputTokens?: number | undefined;
|
833
|
-
outputTokens?: number | undefined;
|
834
|
-
totalTokens?: number | undefined;
|
835
|
-
reasoningTokens?: number | undefined;
|
836
|
-
cachedInputTokens?: number | undefined;
|
837
|
-
} | undefined;
|
838
|
-
}>;
|
839
|
-
}, "strip", z.ZodTypeAny, {
|
840
|
-
value: {
|
841
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
842
|
-
isContinued: boolean;
|
843
|
-
usage?: {
|
844
|
-
inputTokens?: number | undefined;
|
845
|
-
outputTokens?: number | undefined;
|
846
|
-
totalTokens?: number | undefined;
|
847
|
-
reasoningTokens?: number | undefined;
|
848
|
-
cachedInputTokens?: number | undefined;
|
849
|
-
} | undefined;
|
850
|
-
};
|
851
|
-
type: "finish-step";
|
852
|
-
}, {
|
853
|
-
value: {
|
854
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
855
|
-
isContinued: boolean;
|
856
|
-
usage?: {
|
857
|
-
inputTokens?: number | undefined;
|
858
|
-
outputTokens?: number | undefined;
|
859
|
-
totalTokens?: number | undefined;
|
860
|
-
reasoningTokens?: number | undefined;
|
861
|
-
cachedInputTokens?: number | undefined;
|
862
|
-
} | undefined;
|
863
|
-
};
|
864
|
-
type: "finish-step";
|
865
|
-
}>, z.ZodObject<{
|
866
|
-
type: z.ZodLiteral<"start-step">;
|
867
|
-
value: z.ZodObject<{
|
868
|
-
messageId: z.ZodString;
|
869
|
-
}, "strip", z.ZodTypeAny, {
|
870
|
-
messageId: string;
|
871
|
-
}, {
|
872
|
-
messageId: string;
|
873
|
-
}>;
|
874
|
-
}, "strip", z.ZodTypeAny, {
|
875
|
-
value: {
|
876
|
-
messageId: string;
|
877
|
-
};
|
878
|
-
type: "start-step";
|
879
|
-
}, {
|
880
|
-
value: {
|
881
|
-
messageId: string;
|
882
|
-
};
|
883
|
-
type: "start-step";
|
884
|
-
}>, z.ZodObject<{
|
885
|
-
type: z.ZodLiteral<"reasoning">;
|
886
|
-
value: z.ZodObject<{
|
887
|
-
text: z.ZodString;
|
888
|
-
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
889
|
-
}, "strip", z.ZodTypeAny, {
|
890
|
-
text: string;
|
891
|
-
providerMetadata?: Record<string, any> | undefined;
|
892
|
-
}, {
|
893
|
-
text: string;
|
894
|
-
providerMetadata?: Record<string, any> | undefined;
|
895
|
-
}>;
|
896
|
-
}, "strip", z.ZodTypeAny, {
|
897
|
-
value: {
|
898
|
-
text: string;
|
899
|
-
providerMetadata?: Record<string, any> | undefined;
|
900
|
-
};
|
901
|
-
type: "reasoning";
|
902
|
-
}, {
|
903
|
-
value: {
|
904
|
-
text: string;
|
905
|
-
providerMetadata?: Record<string, any> | undefined;
|
906
|
-
};
|
907
|
-
type: "reasoning";
|
908
|
-
}>, z.ZodObject<{
|
909
|
-
type: z.ZodLiteral<"source">;
|
910
|
-
value: z.ZodObject<{
|
911
|
-
type: z.ZodLiteral<"source">;
|
912
|
-
sourceType: z.ZodLiteral<"url">;
|
913
|
-
id: z.ZodString;
|
914
|
-
url: z.ZodString;
|
915
|
-
title: z.ZodOptional<z.ZodString>;
|
916
|
-
providerMetadata: z.ZodOptional<z.ZodAny>;
|
917
|
-
}, "strip", z.ZodTypeAny, {
|
918
|
-
url: string;
|
919
|
-
type: "source";
|
920
|
-
id: string;
|
921
|
-
sourceType: "url";
|
922
|
-
providerMetadata?: any;
|
923
|
-
title?: string | undefined;
|
924
|
-
}, {
|
925
|
-
url: string;
|
926
|
-
type: "source";
|
927
|
-
id: string;
|
928
|
-
sourceType: "url";
|
929
|
-
providerMetadata?: any;
|
930
|
-
title?: string | undefined;
|
931
|
-
}>;
|
932
|
-
}, "strip", z.ZodTypeAny, {
|
933
|
-
value: {
|
934
|
-
url: string;
|
935
|
-
type: "source";
|
936
|
-
id: string;
|
937
|
-
sourceType: "url";
|
938
|
-
providerMetadata?: any;
|
939
|
-
title?: string | undefined;
|
940
|
-
};
|
941
|
-
type: "source";
|
942
|
-
}, {
|
943
|
-
value: {
|
944
|
-
url: string;
|
945
|
-
type: "source";
|
946
|
-
id: string;
|
947
|
-
sourceType: "url";
|
948
|
-
providerMetadata?: any;
|
949
|
-
title?: string | undefined;
|
950
|
-
};
|
951
|
-
type: "source";
|
952
|
-
}>, z.ZodObject<{
|
953
|
-
type: z.ZodLiteral<"file">;
|
954
|
-
value: z.ZodObject<{
|
955
|
-
url: z.ZodString;
|
956
|
-
mediaType: z.ZodString;
|
957
|
-
}, "strip", z.ZodTypeAny, {
|
958
|
-
url: string;
|
959
|
-
mediaType: string;
|
960
|
-
}, {
|
961
|
-
url: string;
|
962
|
-
mediaType: string;
|
963
|
-
}>;
|
964
|
-
}, "strip", z.ZodTypeAny, {
|
965
|
-
value: {
|
966
|
-
url: string;
|
967
|
-
mediaType: string;
|
968
|
-
};
|
969
|
-
type: "file";
|
970
|
-
}, {
|
971
|
-
value: {
|
972
|
-
url: string;
|
973
|
-
mediaType: string;
|
974
|
-
};
|
975
|
-
type: "file";
|
976
|
-
}>, z.ZodObject<{
|
977
|
-
type: z.ZodLiteral<"reasoning-part-finish">;
|
978
|
-
value: z.ZodNull;
|
979
|
-
}, "strip", z.ZodTypeAny, {
|
980
|
-
value: null;
|
981
|
-
type: "reasoning-part-finish";
|
982
|
-
}, {
|
983
|
-
value: null;
|
984
|
-
type: "reasoning-part-finish";
|
985
|
-
}>]>;
|
986
|
-
type DataStreamPart = z.infer<typeof dataStreamPartSchema>;
|
987
|
-
|
988
|
-
interface DataStreamWriter {
|
380
|
+
type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
|
381
|
+
interface ToolExecutionOptions {
|
989
382
|
/**
|
990
|
-
*
|
383
|
+
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
991
384
|
*/
|
992
|
-
|
385
|
+
toolCallId: string;
|
993
386
|
/**
|
994
|
-
*
|
387
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
388
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
995
389
|
*/
|
996
|
-
|
390
|
+
messages: ModelMessage[];
|
997
391
|
/**
|
998
|
-
*
|
999
|
-
* This is intended for forwarding when merging streams
|
1000
|
-
* to prevent duplicated error masking.
|
392
|
+
* An optional abort signal that indicates that the overall operation should be aborted.
|
1001
393
|
*/
|
1002
|
-
|
394
|
+
abortSignal?: AbortSignal;
|
1003
395
|
}
|
396
|
+
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
397
|
+
/**
|
398
|
+
A tool contains the description and the schema of the input that the tool expects.
|
399
|
+
This enables the language model to generate the input.
|
400
|
+
|
401
|
+
The tool can also contain an optional execute function for the actual execution function of the tool.
|
402
|
+
*/
|
403
|
+
type Tool<PARAMETERS extends JSONValue | unknown | never = any, RESULT = any> = {
|
404
|
+
/**
|
405
|
+
An optional description of what the tool does.
|
406
|
+
Will be used by the language model to decide whether to use the tool.
|
407
|
+
Not used for provider-defined tools.
|
408
|
+
*/
|
409
|
+
description?: string;
|
410
|
+
} & NeverOptional<PARAMETERS, {
|
411
|
+
/**
|
412
|
+
The schema of the input that the tool expects. The language model will use this to generate the input.
|
413
|
+
It is also used to validate the output of the language model.
|
414
|
+
Use descriptions to make the input understandable for the language model.
|
415
|
+
*/
|
416
|
+
parameters: ToolParameters<PARAMETERS>;
|
417
|
+
}> & NeverOptional<RESULT, {
|
418
|
+
/**
|
419
|
+
An async function that is called with the arguments from the tool call and produces a result.
|
420
|
+
If not provided, the tool will not be executed automatically.
|
421
|
+
|
422
|
+
@args is the input of the tool call.
|
423
|
+
@options.abortSignal is a signal that can be used to abort the tool call.
|
424
|
+
*/
|
425
|
+
execute: (args: [PARAMETERS] extends [never] ? undefined : PARAMETERS, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
426
|
+
/**
|
427
|
+
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
428
|
+
*/
|
429
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
430
|
+
}> & ({
|
431
|
+
/**
|
432
|
+
Function tool.
|
433
|
+
*/
|
434
|
+
type?: undefined | 'function';
|
435
|
+
} | {
|
436
|
+
/**
|
437
|
+
Provider-defined tool.
|
438
|
+
*/
|
439
|
+
type: 'provider-defined';
|
440
|
+
/**
|
441
|
+
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
442
|
+
*/
|
443
|
+
id: `${string}.${string}`;
|
444
|
+
/**
|
445
|
+
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
446
|
+
*/
|
447
|
+
args: Record<string, unknown>;
|
448
|
+
});
|
449
|
+
|
450
|
+
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute'>>;
|
1004
451
|
|
1005
452
|
declare function prepareToolsAndToolChoice<TOOLS extends ToolSet>({ tools, toolChoice, activeTools, }: {
|
1006
453
|
tools: TOOLS | undefined;
|
@@ -1011,45 +458,16 @@ declare function prepareToolsAndToolChoice<TOOLS extends ToolSet>({ tools, toolC
|
|
1011
458
|
toolChoice: LanguageModelV2ToolChoice | undefined;
|
1012
459
|
};
|
1013
460
|
|
1014
|
-
|
1015
|
-
* Configuration options and helper callback methods for stream lifecycle events.
|
1016
|
-
*/
|
1017
|
-
interface StreamCallbacks {
|
1018
|
-
/** `onStart`: Called once when the stream is initialized. */
|
1019
|
-
onStart?: () => Promise<void> | void;
|
1020
|
-
/** `onFinal`: Called once when the stream is closed with the final completion message. */
|
1021
|
-
onFinal?: (completion: string) => Promise<void> | void;
|
1022
|
-
/** `onToken`: Called for each tokenized message. */
|
1023
|
-
onToken?: (token: string) => Promise<void> | void;
|
1024
|
-
/** `onText`: Called for each text chunk. */
|
1025
|
-
onText?: (text: string) => Promise<void> | void;
|
1026
|
-
}
|
1027
|
-
/**
|
1028
|
-
* Creates a transform stream that encodes input messages and invokes optional callback functions.
|
1029
|
-
* The transform stream uses the provided callbacks to execute custom logic at different stages of the stream's lifecycle.
|
1030
|
-
* - `onStart`: Called once when the stream is initialized.
|
1031
|
-
* - `onToken`: Called for each tokenized message.
|
1032
|
-
* - `onFinal`: Called once when the stream is closed with the final completion message.
|
1033
|
-
*
|
1034
|
-
* This function is useful when you want to process a stream of messages and perform specific actions during the stream's lifecycle.
|
1035
|
-
*
|
1036
|
-
* @param {StreamCallbacks} [callbacks] - An object containing the callback functions.
|
1037
|
-
* @return {TransformStream<string, Uint8Array>} A transform stream that encodes input messages as Uint8Array and allows the execution of custom logic through callbacks.
|
1038
|
-
*
|
1039
|
-
* @example
|
1040
|
-
* const callbacks = {
|
1041
|
-
* onStart: async () => console.log('Stream started'),
|
1042
|
-
* onToken: async (token) => console.log(`Token: ${token}`),
|
1043
|
-
* onFinal: async () => data.close()
|
1044
|
-
* };
|
1045
|
-
* const transformer = createCallbacksTransformer(callbacks);
|
1046
|
-
*/
|
1047
|
-
declare function createCallbacksTransformer(callbacks?: StreamCallbacks | undefined): TransformStream<string, string>;
|
461
|
+
type RetryFunction = <OUTPUT>(fn: () => PromiseLike<OUTPUT>) => PromiseLike<OUTPUT>;
|
1048
462
|
|
1049
463
|
/**
|
1050
|
-
*
|
1051
|
-
* using a console.warn.
|
464
|
+
* Validate and prepare retries.
|
1052
465
|
*/
|
1053
|
-
declare
|
466
|
+
declare function prepareRetries({ maxRetries, }: {
|
467
|
+
maxRetries: number | undefined;
|
468
|
+
}): {
|
469
|
+
maxRetries: number;
|
470
|
+
retry: RetryFunction;
|
471
|
+
};
|
1054
472
|
|
1055
|
-
export {
|
473
|
+
export { convertToLanguageModelPrompt, prepareCallSettings, prepareRetries, prepareToolsAndToolChoice, standardizePrompt };
|