ai 5.0.0-canary.18 → 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 +17 -0
- package/dist/index.d.mts +717 -432
- package/dist/index.d.ts +717 -432
- package/dist/index.js +3261 -3615
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3274 -3626
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +442 -177
- package/dist/internal/index.d.ts +442 -177
- package/dist/internal/index.js +911 -1352
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +911 -1348
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
@@ -1,7 +1,13 @@
|
|
1
|
+
import { SharedV2ProviderOptions, JSONValue, LanguageModelV2Source, JSONObject, LanguageModelV2Prompt, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice } from '@ai-sdk/provider';
|
1
2
|
import { ToolResultContent, ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
|
2
3
|
import { z } from 'zod';
|
3
|
-
|
4
|
-
|
4
|
+
|
5
|
+
declare function download({ url }: {
|
6
|
+
url: URL;
|
7
|
+
}): Promise<{
|
8
|
+
data: Uint8Array;
|
9
|
+
mediaType: string | undefined;
|
10
|
+
}>;
|
5
11
|
|
6
12
|
/**
|
7
13
|
Additional provider-specific options.
|
@@ -234,12 +240,6 @@ It can be a user message, an assistant message, or a tool message.
|
|
234
240
|
*/
|
235
241
|
type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
236
242
|
|
237
|
-
type JSONValue = JSONValue$1;
|
238
|
-
|
239
|
-
/**
|
240
|
-
A source that has been used as input to generate the response.
|
241
|
-
*/
|
242
|
-
type Source = LanguageModelV2Source;
|
243
243
|
/**
|
244
244
|
Tool choice for the generation. It supports the following settings:
|
245
245
|
|
@@ -285,17 +285,13 @@ interface UIMessage {
|
|
285
285
|
*/
|
286
286
|
createdAt?: Date;
|
287
287
|
/**
|
288
|
-
Text content of the message. Use parts when possible.
|
289
|
-
*/
|
290
|
-
content: string;
|
291
|
-
/**
|
292
288
|
The role of the message.
|
293
289
|
*/
|
294
290
|
role: 'system' | 'user' | 'assistant';
|
295
291
|
/**
|
296
292
|
Additional message-specific information added on the server via StreamData
|
297
293
|
*/
|
298
|
-
annotations?: JSONValue
|
294
|
+
annotations?: JSONValue[] | undefined;
|
299
295
|
/**
|
300
296
|
The parts of the message. Use this for rendering the message in the UI.
|
301
297
|
|
@@ -381,75 +377,6 @@ type StepStartUIPart = {
|
|
381
377
|
type: 'step-start';
|
382
378
|
};
|
383
379
|
|
384
|
-
type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
|
385
|
-
interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
|
386
|
-
code: CODE;
|
387
|
-
name: NAME;
|
388
|
-
parse: (value: JSONValue) => {
|
389
|
-
type: NAME;
|
390
|
-
value: TYPE;
|
391
|
-
};
|
392
|
-
}
|
393
|
-
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", {
|
394
|
-
toolCallId: string;
|
395
|
-
toolName: string;
|
396
|
-
}>, DataStreamPart<"c", "tool_call_delta", {
|
397
|
-
toolCallId: string;
|
398
|
-
argsTextDelta: string;
|
399
|
-
}>, DataStreamPart<"d", "finish_message", {
|
400
|
-
finishReason: LanguageModelV2FinishReason;
|
401
|
-
usage?: LanguageModelV2Usage;
|
402
|
-
}>, DataStreamPart<"e", "finish_step", {
|
403
|
-
isContinued: boolean;
|
404
|
-
finishReason: LanguageModelV2FinishReason;
|
405
|
-
usage?: LanguageModelV2Usage;
|
406
|
-
}>, DataStreamPart<"f", "start_step", {
|
407
|
-
messageId: string;
|
408
|
-
}>, DataStreamPart<"g", "reasoning", {
|
409
|
-
text: string;
|
410
|
-
providerMetadata?: Record<string, any> | undefined;
|
411
|
-
}>, DataStreamPart<"h", "source", LanguageModelV2Source>, DataStreamPart<"l", "reasoning_part_finish", {}>, DataStreamPart<"k", "file", {
|
412
|
-
url: string;
|
413
|
-
mediaType: string;
|
414
|
-
}>];
|
415
|
-
type DataStreamParts = (typeof dataStreamParts)[number];
|
416
|
-
/**
|
417
|
-
* Maps the type of a stream part to its value type.
|
418
|
-
*/
|
419
|
-
type DataStreamPartValueType = {
|
420
|
-
[P in DataStreamParts as P['name']]: ReturnType<P['parse']>['value'];
|
421
|
-
};
|
422
|
-
/**
|
423
|
-
* The map of prefixes for data in the stream
|
424
|
-
*
|
425
|
-
* - 0: Text from the LLM response
|
426
|
-
* - 1: (OpenAI) function_call responses
|
427
|
-
* - 2: custom JSON added by the user using `Data`
|
428
|
-
* - 6: (OpenAI) tool_call responses
|
429
|
-
*
|
430
|
-
* Example:
|
431
|
-
* ```
|
432
|
-
* 0:Vercel
|
433
|
-
* 0:'s
|
434
|
-
* 0: AI
|
435
|
-
* 0: AI
|
436
|
-
* 0: SDK
|
437
|
-
* 0: is great
|
438
|
-
* 0:!
|
439
|
-
* 2: { "someJson": "value" }
|
440
|
-
* 1: {"function_call": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}
|
441
|
-
* 6: {"tool_call": {"id": "tool_0", "type": "function", "function": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}}
|
442
|
-
*```
|
443
|
-
*/
|
444
|
-
declare const DataStreamStringPrefixes: { [K in DataStreamParts["name"]]: (typeof dataStreamParts)[number]["code"]; };
|
445
|
-
/**
|
446
|
-
Prepends a string with a prefix from the `StreamChunkPrefixes`, converts it to JSON,
|
447
|
-
and appends a new line.
|
448
|
-
|
449
|
-
It ensures type-safety for the part type and value.
|
450
|
-
*/
|
451
|
-
declare function formatDataStreamPart<T extends keyof DataStreamPartValueType>(type: T, value: DataStreamPartValueType[T]): DataStreamString;
|
452
|
-
|
453
380
|
type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
|
454
381
|
interface ToolExecutionOptions {
|
455
382
|
/**
|
@@ -473,7 +400,7 @@ This enables the language model to generate the input.
|
|
473
400
|
|
474
401
|
The tool can also contain an optional execute function for the actual execution function of the tool.
|
475
402
|
*/
|
476
|
-
type Tool<PARAMETERS extends JSONValue
|
403
|
+
type Tool<PARAMETERS extends JSONValue | unknown | never = any, RESULT = any> = {
|
477
404
|
/**
|
478
405
|
An optional description of what the tool does.
|
479
406
|
Will be used by the language model to decide whether to use the tool.
|
@@ -556,6 +483,12 @@ declare function standardizePrompt<TOOLS extends ToolSet>({ prompt, tools, }: {
|
|
556
483
|
tools: undefined | TOOLS;
|
557
484
|
}): Promise<StandardizedPrompt>;
|
558
485
|
|
486
|
+
declare function convertToLanguageModelPrompt({ prompt, supportedUrls, downloadImplementation, }: {
|
487
|
+
prompt: StandardizedPrompt;
|
488
|
+
supportedUrls: Record<string, RegExp[]>;
|
489
|
+
downloadImplementation?: typeof download;
|
490
|
+
}): Promise<LanguageModelV2Prompt>;
|
491
|
+
|
559
492
|
type CallSettings = {
|
560
493
|
/**
|
561
494
|
Maximum number of tokens to generate.
|
@@ -631,27 +564,436 @@ type CallSettings = {
|
|
631
564
|
headers?: Record<string, string | undefined>;
|
632
565
|
};
|
633
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
|
+
|
634
988
|
interface DataStreamWriter {
|
635
989
|
/**
|
636
|
-
* Appends a data part to the stream.
|
637
|
-
*/
|
638
|
-
write(data: DataStreamString): void;
|
639
|
-
/**
|
640
|
-
* Appends a data part to the stream.
|
641
|
-
*/
|
642
|
-
writeData(value: JSONValue$1): void;
|
643
|
-
/**
|
644
|
-
* Appends a message annotation to the stream.
|
990
|
+
* Appends a data stream part to the stream.
|
645
991
|
*/
|
646
|
-
|
647
|
-
/**
|
648
|
-
* Appends a source part to the stream.
|
649
|
-
*/
|
650
|
-
writeSource(source: Source): void;
|
992
|
+
write(part: DataStreamPart): void;
|
651
993
|
/**
|
652
994
|
* Merges the contents of another stream to this stream.
|
653
995
|
*/
|
654
|
-
merge(stream: ReadableStream<
|
996
|
+
merge(stream: ReadableStream<DataStreamPart>): void;
|
655
997
|
/**
|
656
998
|
* Error handler that is used by the data stream writer.
|
657
999
|
* This is intended for forwarding when merging streams
|
@@ -660,23 +1002,6 @@ interface DataStreamWriter {
|
|
660
1002
|
onError: ((error: unknown) => string) | undefined;
|
661
1003
|
}
|
662
1004
|
|
663
|
-
/**
|
664
|
-
* A stream wrapper to send custom JSON-encoded data back to the client.
|
665
|
-
*
|
666
|
-
* @deprecated Please use `createDataStream`, `createDataStreamResponse`, and `pipeDataStreamToResponse` instead.
|
667
|
-
*/
|
668
|
-
declare class StreamData {
|
669
|
-
private encoder;
|
670
|
-
private controller;
|
671
|
-
stream: ReadableStream<Uint8Array>;
|
672
|
-
private isClosed;
|
673
|
-
private warningTimeout;
|
674
|
-
constructor();
|
675
|
-
close(): Promise<void>;
|
676
|
-
append(value: JSONValue): void;
|
677
|
-
appendMessageAnnotation(value: JSONValue): void;
|
678
|
-
}
|
679
|
-
|
680
1005
|
declare function prepareToolsAndToolChoice<TOOLS extends ToolSet>({ tools, toolChoice, activeTools, }: {
|
681
1006
|
tools: TOOLS | undefined;
|
682
1007
|
toolChoice: ToolChoice<TOOLS> | undefined;
|
@@ -686,70 +1011,12 @@ declare function prepareToolsAndToolChoice<TOOLS extends ToolSet>({ tools, toolC
|
|
686
1011
|
toolChoice: LanguageModelV2ToolChoice | undefined;
|
687
1012
|
};
|
688
1013
|
|
689
|
-
type RetryFunction = <OUTPUT>(fn: () => PromiseLike<OUTPUT>) => PromiseLike<OUTPUT>;
|
690
|
-
|
691
|
-
/**
|
692
|
-
* Validate and prepare retries.
|
693
|
-
*/
|
694
|
-
declare function prepareRetries({ maxRetries, }: {
|
695
|
-
maxRetries: number | undefined;
|
696
|
-
}): {
|
697
|
-
maxRetries: number;
|
698
|
-
retry: RetryFunction;
|
699
|
-
};
|
700
|
-
|
701
|
-
/**
|
702
|
-
* Validates call settings and sets default values.
|
703
|
-
*/
|
704
|
-
declare function prepareCallSettings({ maxOutputTokens, temperature, topP, topK, presencePenalty, frequencyPenalty, stopSequences, seed, }: Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries'>): Omit<CallSettings, 'abortSignal' | 'headers' | 'maxRetries' | 'temperature'> & {
|
705
|
-
temperature?: number;
|
706
|
-
};
|
707
|
-
|
708
|
-
declare function download({ url }: {
|
709
|
-
url: URL;
|
710
|
-
}): Promise<{
|
711
|
-
data: Uint8Array;
|
712
|
-
mediaType: string | undefined;
|
713
|
-
}>;
|
714
|
-
|
715
|
-
declare function convertToLanguageModelPrompt({ prompt, supportedUrls, downloadImplementation, }: {
|
716
|
-
prompt: StandardizedPrompt;
|
717
|
-
supportedUrls: Record<string, RegExp[]>;
|
718
|
-
downloadImplementation?: typeof download;
|
719
|
-
}): Promise<LanguageModelV2Prompt>;
|
720
|
-
|
721
|
-
/**
|
722
|
-
* Merges two readable streams into a single readable stream, emitting values
|
723
|
-
* from each stream as they become available.
|
724
|
-
*
|
725
|
-
* The first stream is prioritized over the second stream. If both streams have
|
726
|
-
* values available, the first stream's value is emitted first.
|
727
|
-
*
|
728
|
-
* @template VALUE1 - The type of values emitted by the first stream.
|
729
|
-
* @template VALUE2 - The type of values emitted by the second stream.
|
730
|
-
* @param {ReadableStream<VALUE1>} stream1 - The first readable stream.
|
731
|
-
* @param {ReadableStream<VALUE2>} stream2 - The second readable stream.
|
732
|
-
* @returns {ReadableStream<VALUE1 | VALUE2>} A new readable stream that emits values from both input streams.
|
733
|
-
*/
|
734
|
-
declare function mergeStreams<VALUE1, VALUE2>(stream1: ReadableStream<VALUE1>, stream2: ReadableStream<VALUE2>): ReadableStream<VALUE1 | VALUE2>;
|
735
|
-
|
736
|
-
declare function prepareResponseHeaders(headers: HeadersInit | undefined, { contentType, dataStreamVersion, }: {
|
737
|
-
contentType: string;
|
738
|
-
dataStreamVersion?: 'v1' | undefined;
|
739
|
-
}): Headers;
|
740
|
-
|
741
1014
|
/**
|
742
1015
|
* Configuration options and helper callback methods for stream lifecycle events.
|
743
1016
|
*/
|
744
1017
|
interface StreamCallbacks {
|
745
1018
|
/** `onStart`: Called once when the stream is initialized. */
|
746
1019
|
onStart?: () => Promise<void> | void;
|
747
|
-
/**
|
748
|
-
* `onCompletion`: Called for each tokenized message.
|
749
|
-
*
|
750
|
-
* @deprecated Use `onFinal` instead.
|
751
|
-
*/
|
752
|
-
onCompletion?: (completion: string) => Promise<void> | void;
|
753
1020
|
/** `onFinal`: Called once when the stream is closed with the final completion message. */
|
754
1021
|
onFinal?: (completion: string) => Promise<void> | void;
|
755
1022
|
/** `onToken`: Called for each tokenized message. */
|
@@ -762,7 +1029,6 @@ interface StreamCallbacks {
|
|
762
1029
|
* The transform stream uses the provided callbacks to execute custom logic at different stages of the stream's lifecycle.
|
763
1030
|
* - `onStart`: Called once when the stream is initialized.
|
764
1031
|
* - `onToken`: Called for each tokenized message.
|
765
|
-
* - `onCompletion`: Called every time a completion message is received. This can occur multiple times when using e.g. OpenAI functions
|
766
1032
|
* - `onFinal`: Called once when the stream is closed with the final completion message.
|
767
1033
|
*
|
768
1034
|
* This function is useful when you want to process a stream of messages and perform specific actions during the stream's lifecycle.
|
@@ -774,12 +1040,11 @@ interface StreamCallbacks {
|
|
774
1040
|
* const callbacks = {
|
775
1041
|
* onStart: async () => console.log('Stream started'),
|
776
1042
|
* onToken: async (token) => console.log(`Token: ${token}`),
|
777
|
-
* onCompletion: async (completion) => console.log(`Completion: ${completion}`)
|
778
1043
|
* onFinal: async () => data.close()
|
779
1044
|
* };
|
780
1045
|
* const transformer = createCallbacksTransformer(callbacks);
|
781
1046
|
*/
|
782
|
-
declare function createCallbacksTransformer(callbacks?: StreamCallbacks | undefined): TransformStream<string,
|
1047
|
+
declare function createCallbacksTransformer(callbacks?: StreamCallbacks | undefined): TransformStream<string, string>;
|
783
1048
|
|
784
1049
|
/**
|
785
1050
|
* Warning time for notifying developers that a stream is hanging in dev mode
|
@@ -787,4 +1052,4 @@ declare function createCallbacksTransformer(callbacks?: StreamCallbacks | undefi
|
|
787
1052
|
*/
|
788
1053
|
declare const HANGING_STREAM_WARNING_TIME_MS: number;
|
789
1054
|
|
790
|
-
export { DataStreamWriter, HANGING_STREAM_WARNING_TIME_MS, StreamCallbacks,
|
1055
|
+
export { DataStreamWriter, HANGING_STREAM_WARNING_TIME_MS, StreamCallbacks, convertToLanguageModelPrompt, createCallbacksTransformer, prepareCallSettings, prepareRetries, prepareToolsAndToolChoice, standardizePrompt };
|