ai 5.0.0-canary.17 → 5.0.0-canary.19
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 +36 -0
- package/README.md +4 -4
- package/dist/index.d.mts +747 -510
- package/dist/index.d.ts +747 -510
- package/dist/index.js +3345 -3688
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3349 -3690
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +441 -214
- package/dist/internal/index.d.ts +441 -214
- package/dist/internal/index.js +911 -1360
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +911 -1355
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +2 -2
- package/dist/mcp-stdio/index.d.ts +2 -2
- package/package.json +4 -4
@@ -1,19 +1,12 @@
|
|
1
|
-
import
|
2
|
-
import {
|
1
|
+
import { SharedV2ProviderOptions, JSONValue, LanguageModelV2Source, JSONObject, LanguageModelV2Prompt, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice } from '@ai-sdk/provider';
|
2
|
+
import { ToolResultContent, ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
|
3
3
|
import { z } from 'zod';
|
4
|
-
import { ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
data: string;
|
12
|
-
mediaType?: string;
|
13
|
-
/**
|
14
|
-
* @deprecated Use `mediaType` instead.
|
15
|
-
*/
|
16
|
-
mimeType?: string;
|
5
|
+
declare function download({ url }: {
|
6
|
+
url: URL;
|
7
|
+
}): Promise<{
|
8
|
+
data: Uint8Array;
|
9
|
+
mediaType: string | undefined;
|
17
10
|
}>;
|
18
11
|
|
19
12
|
/**
|
@@ -247,12 +240,6 @@ It can be a user message, an assistant message, or a tool message.
|
|
247
240
|
*/
|
248
241
|
type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
249
242
|
|
250
|
-
type JSONValue = JSONValue$1;
|
251
|
-
|
252
|
-
/**
|
253
|
-
A source that has been used as input to generate the response.
|
254
|
-
*/
|
255
|
-
type Source = LanguageModelV2Source;
|
256
243
|
/**
|
257
244
|
Tool choice for the generation. It supports the following settings:
|
258
245
|
|
@@ -298,17 +285,13 @@ interface UIMessage {
|
|
298
285
|
*/
|
299
286
|
createdAt?: Date;
|
300
287
|
/**
|
301
|
-
Text content of the message. Use parts when possible.
|
302
|
-
*/
|
303
|
-
content: string;
|
304
|
-
/**
|
305
288
|
The role of the message.
|
306
289
|
*/
|
307
290
|
role: 'system' | 'user' | 'assistant';
|
308
291
|
/**
|
309
292
|
Additional message-specific information added on the server via StreamData
|
310
293
|
*/
|
311
|
-
annotations?: JSONValue
|
294
|
+
annotations?: JSONValue[] | undefined;
|
312
295
|
/**
|
313
296
|
The parts of the message. Use this for rendering the message in the UI.
|
314
297
|
|
@@ -394,100 +377,6 @@ type StepStartUIPart = {
|
|
394
377
|
type: 'step-start';
|
395
378
|
};
|
396
379
|
|
397
|
-
/**
|
398
|
-
Represents the number of tokens used in a prompt and completion.
|
399
|
-
*/
|
400
|
-
type LanguageModelUsage = {
|
401
|
-
/**
|
402
|
-
The number of tokens used in the prompt.
|
403
|
-
*/
|
404
|
-
promptTokens: number;
|
405
|
-
/**
|
406
|
-
The number of tokens used in the completion.
|
407
|
-
*/
|
408
|
-
completionTokens: number;
|
409
|
-
/**
|
410
|
-
The total number of tokens used (promptTokens + completionTokens).
|
411
|
-
*/
|
412
|
-
totalTokens: number;
|
413
|
-
};
|
414
|
-
declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
|
415
|
-
|
416
|
-
type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
|
417
|
-
interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
|
418
|
-
code: CODE;
|
419
|
-
name: NAME;
|
420
|
-
parse: (value: JSONValue) => {
|
421
|
-
type: NAME;
|
422
|
-
value: TYPE;
|
423
|
-
};
|
424
|
-
}
|
425
|
-
declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "toolName" | "args">>, DataStreamPart<"b", "tool_call_streaming_start", {
|
426
|
-
toolCallId: string;
|
427
|
-
toolName: string;
|
428
|
-
}>, DataStreamPart<"c", "tool_call_delta", {
|
429
|
-
toolCallId: string;
|
430
|
-
argsTextDelta: string;
|
431
|
-
}>, DataStreamPart<"d", "finish_message", {
|
432
|
-
finishReason: LanguageModelV2FinishReason;
|
433
|
-
usage?: {
|
434
|
-
promptTokens: number;
|
435
|
-
completionTokens: number;
|
436
|
-
};
|
437
|
-
}>, DataStreamPart<"e", "finish_step", {
|
438
|
-
isContinued: boolean;
|
439
|
-
finishReason: LanguageModelV2FinishReason;
|
440
|
-
usage?: {
|
441
|
-
promptTokens: number;
|
442
|
-
completionTokens: number;
|
443
|
-
};
|
444
|
-
}>, DataStreamPart<"f", "start_step", {
|
445
|
-
messageId: string;
|
446
|
-
}>, DataStreamPart<"g", "reasoning", {
|
447
|
-
text: string;
|
448
|
-
providerMetadata?: Record<string, any> | undefined;
|
449
|
-
}>, DataStreamPart<"h", "source", LanguageModelV2Source>, DataStreamPart<"l", "reasoning_part_finish", {}>, DataStreamPart<"k", "file", {
|
450
|
-
url: string;
|
451
|
-
mediaType: string;
|
452
|
-
}>];
|
453
|
-
type DataStreamParts = (typeof dataStreamParts)[number];
|
454
|
-
/**
|
455
|
-
* Maps the type of a stream part to its value type.
|
456
|
-
*/
|
457
|
-
type DataStreamPartValueType = {
|
458
|
-
[P in DataStreamParts as P['name']]: ReturnType<P['parse']>['value'];
|
459
|
-
};
|
460
|
-
/**
|
461
|
-
* The map of prefixes for data in the stream
|
462
|
-
*
|
463
|
-
* - 0: Text from the LLM response
|
464
|
-
* - 1: (OpenAI) function_call responses
|
465
|
-
* - 2: custom JSON added by the user using `Data`
|
466
|
-
* - 6: (OpenAI) tool_call responses
|
467
|
-
*
|
468
|
-
* Example:
|
469
|
-
* ```
|
470
|
-
* 0:Vercel
|
471
|
-
* 0:'s
|
472
|
-
* 0: AI
|
473
|
-
* 0: AI
|
474
|
-
* 0: SDK
|
475
|
-
* 0: is great
|
476
|
-
* 0:!
|
477
|
-
* 2: { "someJson": "value" }
|
478
|
-
* 1: {"function_call": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}
|
479
|
-
* 6: {"tool_call": {"id": "tool_0", "type": "function", "function": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}}
|
480
|
-
*```
|
481
|
-
*/
|
482
|
-
declare const DataStreamStringPrefixes: { [K in DataStreamParts["name"]]: (typeof dataStreamParts)[number]["code"]; };
|
483
|
-
/**
|
484
|
-
Prepends a string with a prefix from the `StreamChunkPrefixes`, converts it to JSON,
|
485
|
-
and appends a new line.
|
486
|
-
|
487
|
-
It ensures type-safety for the part type and value.
|
488
|
-
*/
|
489
|
-
declare function formatDataStreamPart<T extends keyof DataStreamPartValueType>(type: T, value: DataStreamPartValueType[T]): DataStreamString;
|
490
|
-
|
491
380
|
type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
|
492
381
|
interface ToolExecutionOptions {
|
493
382
|
/**
|
@@ -511,7 +400,7 @@ This enables the language model to generate the input.
|
|
511
400
|
|
512
401
|
The tool can also contain an optional execute function for the actual execution function of the tool.
|
513
402
|
*/
|
514
|
-
type Tool<PARAMETERS extends JSONValue
|
403
|
+
type Tool<PARAMETERS extends JSONValue | unknown | never = any, RESULT = any> = {
|
515
404
|
/**
|
516
405
|
An optional description of what the tool does.
|
517
406
|
Will be used by the language model to decide whether to use the tool.
|
@@ -594,6 +483,12 @@ declare function standardizePrompt<TOOLS extends ToolSet>({ prompt, tools, }: {
|
|
594
483
|
tools: undefined | TOOLS;
|
595
484
|
}): Promise<StandardizedPrompt>;
|
596
485
|
|
486
|
+
declare function convertToLanguageModelPrompt({ prompt, supportedUrls, downloadImplementation, }: {
|
487
|
+
prompt: StandardizedPrompt;
|
488
|
+
supportedUrls: Record<string, RegExp[]>;
|
489
|
+
downloadImplementation?: typeof download;
|
490
|
+
}): Promise<LanguageModelV2Prompt>;
|
491
|
+
|
597
492
|
type CallSettings = {
|
598
493
|
/**
|
599
494
|
Maximum number of tokens to generate.
|
@@ -669,27 +564,436 @@ type CallSettings = {
|
|
669
564
|
headers?: Record<string, string | undefined>;
|
670
565
|
};
|
671
566
|
|
567
|
+
/**
|
568
|
+
* Validates call settings and sets default values.
|
569
|
+
*/
|
570
|
+
declare function prepareCallSettings({ maxOutputTokens, temperature, topP, topK, presencePenalty, frequencyPenalty, stopSequences, seed, }: Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries'>): Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries' | 'temperature'> & {
|
571
|
+
temperature?: number;
|
572
|
+
};
|
573
|
+
|
574
|
+
type RetryFunction = <OUTPUT>(fn: () => PromiseLike<OUTPUT>) => PromiseLike<OUTPUT>;
|
575
|
+
|
576
|
+
/**
|
577
|
+
* Validate and prepare retries.
|
578
|
+
*/
|
579
|
+
declare function prepareRetries({ maxRetries, }: {
|
580
|
+
maxRetries: number | undefined;
|
581
|
+
}): {
|
582
|
+
maxRetries: number;
|
583
|
+
retry: RetryFunction;
|
584
|
+
};
|
585
|
+
|
586
|
+
declare const dataStreamPartSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
587
|
+
type: z.ZodLiteral<"text">;
|
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
|
+
|
672
988
|
interface DataStreamWriter {
|
673
989
|
/**
|
674
|
-
* Appends a data part to the stream.
|
990
|
+
* Appends a data stream part to the stream.
|
675
991
|
*/
|
676
|
-
write(
|
677
|
-
/**
|
678
|
-
* Appends a data part to the stream.
|
679
|
-
*/
|
680
|
-
writeData(value: JSONValue$1): void;
|
681
|
-
/**
|
682
|
-
* Appends a message annotation to the stream.
|
683
|
-
*/
|
684
|
-
writeMessageAnnotation(value: JSONValue$1): void;
|
685
|
-
/**
|
686
|
-
* Appends a source part to the stream.
|
687
|
-
*/
|
688
|
-
writeSource(source: Source): void;
|
992
|
+
write(part: DataStreamPart): void;
|
689
993
|
/**
|
690
994
|
* Merges the contents of another stream to this stream.
|
691
995
|
*/
|
692
|
-
merge(stream: ReadableStream<
|
996
|
+
merge(stream: ReadableStream<DataStreamPart>): void;
|
693
997
|
/**
|
694
998
|
* Error handler that is used by the data stream writer.
|
695
999
|
* This is intended for forwarding when merging streams
|
@@ -698,23 +1002,6 @@ interface DataStreamWriter {
|
|
698
1002
|
onError: ((error: unknown) => string) | undefined;
|
699
1003
|
}
|
700
1004
|
|
701
|
-
/**
|
702
|
-
* A stream wrapper to send custom JSON-encoded data back to the client.
|
703
|
-
*
|
704
|
-
* @deprecated Please use `createDataStream`, `createDataStreamResponse`, and `pipeDataStreamToResponse` instead.
|
705
|
-
*/
|
706
|
-
declare class StreamData {
|
707
|
-
private encoder;
|
708
|
-
private controller;
|
709
|
-
stream: ReadableStream<Uint8Array>;
|
710
|
-
private isClosed;
|
711
|
-
private warningTimeout;
|
712
|
-
constructor();
|
713
|
-
close(): Promise<void>;
|
714
|
-
append(value: JSONValue): void;
|
715
|
-
appendMessageAnnotation(value: JSONValue): void;
|
716
|
-
}
|
717
|
-
|
718
1005
|
declare function prepareToolsAndToolChoice<TOOLS extends ToolSet>({ tools, toolChoice, activeTools, }: {
|
719
1006
|
tools: TOOLS | undefined;
|
720
1007
|
toolChoice: ToolChoice<TOOLS> | undefined;
|
@@ -724,70 +1011,12 @@ declare function prepareToolsAndToolChoice<TOOLS extends ToolSet>({ tools, toolC
|
|
724
1011
|
toolChoice: LanguageModelV2ToolChoice | undefined;
|
725
1012
|
};
|
726
1013
|
|
727
|
-
type RetryFunction = <OUTPUT>(fn: () => PromiseLike<OUTPUT>) => PromiseLike<OUTPUT>;
|
728
|
-
|
729
|
-
/**
|
730
|
-
* Validate and prepare retries.
|
731
|
-
*/
|
732
|
-
declare function prepareRetries({ maxRetries, }: {
|
733
|
-
maxRetries: number | undefined;
|
734
|
-
}): {
|
735
|
-
maxRetries: number;
|
736
|
-
retry: RetryFunction;
|
737
|
-
};
|
738
|
-
|
739
|
-
/**
|
740
|
-
* Validates call settings and sets default values.
|
741
|
-
*/
|
742
|
-
declare function prepareCallSettings({ maxOutputTokens, temperature, topP, topK, presencePenalty, frequencyPenalty, stopSequences, seed, }: Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries'>): Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries' | 'temperature'> & {
|
743
|
-
temperature?: number;
|
744
|
-
};
|
745
|
-
|
746
|
-
declare function download({ url }: {
|
747
|
-
url: URL;
|
748
|
-
}): Promise<{
|
749
|
-
data: Uint8Array;
|
750
|
-
mediaType: string | undefined;
|
751
|
-
}>;
|
752
|
-
|
753
|
-
declare function convertToLanguageModelPrompt({ prompt, supportedUrls, downloadImplementation, }: {
|
754
|
-
prompt: StandardizedPrompt;
|
755
|
-
supportedUrls: Record<string, RegExp[]>;
|
756
|
-
downloadImplementation?: typeof download;
|
757
|
-
}): Promise<LanguageModelV2Prompt>;
|
758
|
-
|
759
|
-
/**
|
760
|
-
* Merges two readable streams into a single readable stream, emitting values
|
761
|
-
* from each stream as they become available.
|
762
|
-
*
|
763
|
-
* The first stream is prioritized over the second stream. If both streams have
|
764
|
-
* values available, the first stream's value is emitted first.
|
765
|
-
*
|
766
|
-
* @template VALUE1 - The type of values emitted by the first stream.
|
767
|
-
* @template VALUE2 - The type of values emitted by the second stream.
|
768
|
-
* @param {ReadableStream<VALUE1>} stream1 - The first readable stream.
|
769
|
-
* @param {ReadableStream<VALUE2>} stream2 - The second readable stream.
|
770
|
-
* @returns {ReadableStream<VALUE1 | VALUE2>} A new readable stream that emits values from both input streams.
|
771
|
-
*/
|
772
|
-
declare function mergeStreams<VALUE1, VALUE2>(stream1: ReadableStream<VALUE1>, stream2: ReadableStream<VALUE2>): ReadableStream<VALUE1 | VALUE2>;
|
773
|
-
|
774
|
-
declare function prepareResponseHeaders(headers: HeadersInit | undefined, { contentType, dataStreamVersion, }: {
|
775
|
-
contentType: string;
|
776
|
-
dataStreamVersion?: 'v1' | undefined;
|
777
|
-
}): Headers;
|
778
|
-
|
779
1014
|
/**
|
780
1015
|
* Configuration options and helper callback methods for stream lifecycle events.
|
781
1016
|
*/
|
782
1017
|
interface StreamCallbacks {
|
783
1018
|
/** `onStart`: Called once when the stream is initialized. */
|
784
1019
|
onStart?: () => Promise<void> | void;
|
785
|
-
/**
|
786
|
-
* `onCompletion`: Called for each tokenized message.
|
787
|
-
*
|
788
|
-
* @deprecated Use `onFinal` instead.
|
789
|
-
*/
|
790
|
-
onCompletion?: (completion: string) => Promise<void> | void;
|
791
1020
|
/** `onFinal`: Called once when the stream is closed with the final completion message. */
|
792
1021
|
onFinal?: (completion: string) => Promise<void> | void;
|
793
1022
|
/** `onToken`: Called for each tokenized message. */
|
@@ -800,7 +1029,6 @@ interface StreamCallbacks {
|
|
800
1029
|
* The transform stream uses the provided callbacks to execute custom logic at different stages of the stream's lifecycle.
|
801
1030
|
* - `onStart`: Called once when the stream is initialized.
|
802
1031
|
* - `onToken`: Called for each tokenized message.
|
803
|
-
* - `onCompletion`: Called every time a completion message is received. This can occur multiple times when using e.g. OpenAI functions
|
804
1032
|
* - `onFinal`: Called once when the stream is closed with the final completion message.
|
805
1033
|
*
|
806
1034
|
* This function is useful when you want to process a stream of messages and perform specific actions during the stream's lifecycle.
|
@@ -812,12 +1040,11 @@ interface StreamCallbacks {
|
|
812
1040
|
* const callbacks = {
|
813
1041
|
* onStart: async () => console.log('Stream started'),
|
814
1042
|
* onToken: async (token) => console.log(`Token: ${token}`),
|
815
|
-
* onCompletion: async (completion) => console.log(`Completion: ${completion}`)
|
816
1043
|
* onFinal: async () => data.close()
|
817
1044
|
* };
|
818
1045
|
* const transformer = createCallbacksTransformer(callbacks);
|
819
1046
|
*/
|
820
|
-
declare function createCallbacksTransformer(callbacks?: StreamCallbacks | undefined): TransformStream<string,
|
1047
|
+
declare function createCallbacksTransformer(callbacks?: StreamCallbacks | undefined): TransformStream<string, string>;
|
821
1048
|
|
822
1049
|
/**
|
823
1050
|
* Warning time for notifying developers that a stream is hanging in dev mode
|
@@ -825,4 +1052,4 @@ declare function createCallbacksTransformer(callbacks?: StreamCallbacks | undefi
|
|
825
1052
|
*/
|
826
1053
|
declare const HANGING_STREAM_WARNING_TIME_MS: number;
|
827
1054
|
|
828
|
-
export { DataStreamWriter, HANGING_STREAM_WARNING_TIME_MS, StreamCallbacks,
|
1055
|
+
export { DataStreamWriter, HANGING_STREAM_WARNING_TIME_MS, StreamCallbacks, convertToLanguageModelPrompt, createCallbacksTransformer, prepareCallSettings, prepareRetries, prepareToolsAndToolChoice, standardizePrompt };
|