ai 2.2.35 → 2.2.37
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/dist/index.d.ts +163 -160
- package/dist/index.js +751 -728
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +752 -730
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { ChatCompletionResponseChunk } from '@mistralai/mistralai';
|
1
2
|
import { ServerResponse } from 'node:http';
|
2
3
|
|
3
4
|
interface FunctionCall {
|
@@ -280,6 +281,78 @@ type DataMessage = {
|
|
280
281
|
data: JSONValue;
|
281
282
|
};
|
282
283
|
|
284
|
+
interface StreamPart<CODE extends string, NAME extends string, TYPE> {
|
285
|
+
code: CODE;
|
286
|
+
name: NAME;
|
287
|
+
parse: (value: JSONValue) => {
|
288
|
+
type: NAME;
|
289
|
+
value: TYPE;
|
290
|
+
};
|
291
|
+
}
|
292
|
+
declare const textStreamPart: StreamPart<'0', 'text', string>;
|
293
|
+
declare const functionCallStreamPart: StreamPart<'1', 'function_call', {
|
294
|
+
function_call: FunctionCall;
|
295
|
+
}>;
|
296
|
+
declare const dataStreamPart: StreamPart<'2', 'data', Array<JSONValue>>;
|
297
|
+
declare const errorStreamPart: StreamPart<'3', 'error', string>;
|
298
|
+
declare const assistantMessageStreamPart: StreamPart<'4', 'assistant_message', AssistantMessage>;
|
299
|
+
declare const assistantControlDataStreamPart: StreamPart<'5', 'assistant_control_data', {
|
300
|
+
threadId: string;
|
301
|
+
messageId: string;
|
302
|
+
}>;
|
303
|
+
declare const dataMessageStreamPart: StreamPart<'6', 'data_message', DataMessage>;
|
304
|
+
declare const toolCallStreamPart: StreamPart<'7', 'tool_calls', {
|
305
|
+
tool_calls: ToolCall[];
|
306
|
+
}>;
|
307
|
+
declare const messageAnnotationsStreamPart: StreamPart<'8', 'message_annotations', Array<JSONValue>>;
|
308
|
+
type StreamPartType = ReturnType<typeof textStreamPart.parse> | ReturnType<typeof functionCallStreamPart.parse> | ReturnType<typeof dataStreamPart.parse> | ReturnType<typeof errorStreamPart.parse> | ReturnType<typeof assistantMessageStreamPart.parse> | ReturnType<typeof assistantControlDataStreamPart.parse> | ReturnType<typeof dataMessageStreamPart.parse> | ReturnType<typeof toolCallStreamPart.parse> | ReturnType<typeof messageAnnotationsStreamPart.parse>;
|
309
|
+
/**
|
310
|
+
* The map of prefixes for data in the stream
|
311
|
+
*
|
312
|
+
* - 0: Text from the LLM response
|
313
|
+
* - 1: (OpenAI) function_call responses
|
314
|
+
* - 2: custom JSON added by the user using `Data`
|
315
|
+
* - 6: (OpenAI) tool_call responses
|
316
|
+
*
|
317
|
+
* Example:
|
318
|
+
* ```
|
319
|
+
* 0:Vercel
|
320
|
+
* 0:'s
|
321
|
+
* 0: AI
|
322
|
+
* 0: AI
|
323
|
+
* 0: SDK
|
324
|
+
* 0: is great
|
325
|
+
* 0:!
|
326
|
+
* 2: { "someJson": "value" }
|
327
|
+
* 1: {"function_call": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}
|
328
|
+
* 6: {"tool_call": {"id": "tool_0", "type": "function", "function": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}}
|
329
|
+
*```
|
330
|
+
*/
|
331
|
+
declare const StreamStringPrefixes: {
|
332
|
+
readonly text: "0";
|
333
|
+
readonly function_call: "1";
|
334
|
+
readonly data: "2";
|
335
|
+
readonly error: "3";
|
336
|
+
readonly assistant_message: "4";
|
337
|
+
readonly assistant_control_data: "5";
|
338
|
+
readonly data_message: "6";
|
339
|
+
readonly tool_calls: "7";
|
340
|
+
readonly message_annotations: "8";
|
341
|
+
};
|
342
|
+
|
343
|
+
declare const nanoid: (size?: number | undefined) => string;
|
344
|
+
declare function createChunkDecoder(): (chunk: Uint8Array | undefined) => string;
|
345
|
+
declare function createChunkDecoder(complex: false): (chunk: Uint8Array | undefined) => string;
|
346
|
+
declare function createChunkDecoder(complex: true): (chunk: Uint8Array | undefined) => StreamPartType[];
|
347
|
+
declare function createChunkDecoder(complex?: boolean): (chunk: Uint8Array | undefined) => StreamPartType[] | string;
|
348
|
+
|
349
|
+
declare const isStreamStringEqualToType: (type: keyof typeof StreamStringPrefixes, value: string) => value is `0:${string}\n` | `1:${string}\n` | `2:${string}\n` | `3:${string}\n` | `4:${string}\n` | `5:${string}\n` | `6:${string}\n` | `7:${string}\n` | `8:${string}\n`;
|
350
|
+
type StreamString = `${(typeof StreamStringPrefixes)[keyof typeof StreamStringPrefixes]}:${string}\n`;
|
351
|
+
/**
|
352
|
+
* A header sent to the client so it knows how to handle parsing the stream (as a deprecated text response or using the new prefixed protocol)
|
353
|
+
*/
|
354
|
+
declare const COMPLEX_HEADER = "X-Experimental-Stream-Data";
|
355
|
+
|
283
356
|
declare interface AzureChatCompletions {
|
284
357
|
id: string;
|
285
358
|
created: Date;
|
@@ -625,63 +698,6 @@ declare function AIStream(response: Response, customParser?: AIStreamParser, cal
|
|
625
698
|
*/
|
626
699
|
declare function readableFromAsyncIterable<T>(iterable: AsyncIterable<T>): ReadableStream<T>;
|
627
700
|
|
628
|
-
interface AWSBedrockResponse {
|
629
|
-
body?: AsyncIterable<{
|
630
|
-
chunk?: {
|
631
|
-
bytes?: Uint8Array;
|
632
|
-
};
|
633
|
-
}>;
|
634
|
-
}
|
635
|
-
declare function AWSBedrockAnthropicStream(response: AWSBedrockResponse, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
636
|
-
declare function AWSBedrockCohereStream(response: AWSBedrockResponse, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
637
|
-
declare function AWSBedrockLlama2Stream(response: AWSBedrockResponse, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
638
|
-
declare function AWSBedrockStream(response: AWSBedrockResponse, callbacks: AIStreamCallbacksAndOptions | undefined, extractTextDeltaFromChunk: (chunk: any) => string): ReadableStream<any>;
|
639
|
-
|
640
|
-
/**
|
641
|
-
* A stream wrapper to send custom JSON-encoded data back to the client.
|
642
|
-
*/
|
643
|
-
declare class experimental_StreamData {
|
644
|
-
private encoder;
|
645
|
-
private controller;
|
646
|
-
stream: TransformStream<Uint8Array, Uint8Array>;
|
647
|
-
private isClosedPromise;
|
648
|
-
private isClosedPromiseResolver;
|
649
|
-
private isClosed;
|
650
|
-
private data;
|
651
|
-
private messageAnnotations;
|
652
|
-
constructor();
|
653
|
-
close(): Promise<void>;
|
654
|
-
append(value: JSONValue): void;
|
655
|
-
appendMessageAnnotation(value: JSONValue): void;
|
656
|
-
}
|
657
|
-
/**
|
658
|
-
* A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
|
659
|
-
* This assumes every chunk is a 'text' chunk.
|
660
|
-
*/
|
661
|
-
declare function createStreamDataTransformer(experimental_streamData: boolean | undefined): TransformStream<any, any>;
|
662
|
-
|
663
|
-
/**
|
664
|
-
* A utility class for streaming text responses.
|
665
|
-
*/
|
666
|
-
declare class StreamingTextResponse extends Response {
|
667
|
-
constructor(res: ReadableStream, init?: ResponseInit, data?: experimental_StreamData);
|
668
|
-
}
|
669
|
-
/**
|
670
|
-
* A utility function to stream a ReadableStream to a Node.js response-like object.
|
671
|
-
*/
|
672
|
-
declare function streamToResponse(res: ReadableStream, response: ServerResponse, init?: {
|
673
|
-
headers?: Record<string, string>;
|
674
|
-
status?: number;
|
675
|
-
}): void;
|
676
|
-
|
677
|
-
declare function HuggingFaceStream(res: AsyncGenerator<any>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
678
|
-
|
679
|
-
interface StreamChunk {
|
680
|
-
text?: string;
|
681
|
-
eventType: 'stream-start' | 'search-queries-generation' | 'search-results' | 'text-generation' | 'citation-generation' | 'stream-end';
|
682
|
-
}
|
683
|
-
declare function CohereStream(reader: Response | AsyncIterable<StreamChunk>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
684
|
-
|
685
701
|
interface CompletionChunk {
|
686
702
|
/**
|
687
703
|
* The resulting completion up to and excluding the stop sequences.
|
@@ -756,6 +772,61 @@ interface MessageStopEvent {
|
|
756
772
|
*/
|
757
773
|
declare function AnthropicStream(res: Response | AsyncIterable<CompletionChunk> | AsyncIterable<MessageStreamEvent>, cb?: AIStreamCallbacksAndOptions): ReadableStream;
|
758
774
|
|
775
|
+
type AssistantResponseSettings = {
|
776
|
+
threadId: string;
|
777
|
+
messageId: string;
|
778
|
+
};
|
779
|
+
type AssistantResponseCallback = (stream: {
|
780
|
+
threadId: string;
|
781
|
+
messageId: string;
|
782
|
+
sendMessage: (message: AssistantMessage) => void;
|
783
|
+
sendDataMessage: (message: DataMessage) => void;
|
784
|
+
}) => Promise<void>;
|
785
|
+
declare function experimental_AssistantResponse({ threadId, messageId }: AssistantResponseSettings, process: AssistantResponseCallback): Response;
|
786
|
+
|
787
|
+
interface AWSBedrockResponse {
|
788
|
+
body?: AsyncIterable<{
|
789
|
+
chunk?: {
|
790
|
+
bytes?: Uint8Array;
|
791
|
+
};
|
792
|
+
}>;
|
793
|
+
}
|
794
|
+
declare function AWSBedrockAnthropicStream(response: AWSBedrockResponse, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
795
|
+
declare function AWSBedrockCohereStream(response: AWSBedrockResponse, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
796
|
+
declare function AWSBedrockLlama2Stream(response: AWSBedrockResponse, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
797
|
+
declare function AWSBedrockStream(response: AWSBedrockResponse, callbacks: AIStreamCallbacksAndOptions | undefined, extractTextDeltaFromChunk: (chunk: any) => string): ReadableStream<any>;
|
798
|
+
|
799
|
+
interface StreamChunk {
|
800
|
+
text?: string;
|
801
|
+
eventType: 'stream-start' | 'search-queries-generation' | 'search-results' | 'text-generation' | 'citation-generation' | 'stream-end';
|
802
|
+
}
|
803
|
+
declare function CohereStream(reader: Response | AsyncIterable<StreamChunk>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
804
|
+
|
805
|
+
interface GenerateContentResponse {
|
806
|
+
candidates?: GenerateContentCandidate[];
|
807
|
+
}
|
808
|
+
interface GenerateContentCandidate {
|
809
|
+
index: number;
|
810
|
+
content: Content;
|
811
|
+
}
|
812
|
+
interface Content {
|
813
|
+
role: string;
|
814
|
+
parts: Part[];
|
815
|
+
}
|
816
|
+
type Part = TextPart | InlineDataPart;
|
817
|
+
interface InlineDataPart {
|
818
|
+
text?: never;
|
819
|
+
}
|
820
|
+
interface TextPart {
|
821
|
+
text: string;
|
822
|
+
inlineData?: never;
|
823
|
+
}
|
824
|
+
declare function GoogleGenerativeAIStream(response: {
|
825
|
+
stream: AsyncIterable<GenerateContentResponse>;
|
826
|
+
}, cb?: AIStreamCallbacksAndOptions): ReadableStream;
|
827
|
+
|
828
|
+
declare function HuggingFaceStream(res: AsyncGenerator<any>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
829
|
+
|
759
830
|
type InkeepOnFinalMetadata = {
|
760
831
|
chat_session_id: string;
|
761
832
|
records_cited: any;
|
@@ -784,6 +855,8 @@ declare function LangChainStream(callbacks?: AIStreamCallbacksAndOptions): {
|
|
784
855
|
};
|
785
856
|
};
|
786
857
|
|
858
|
+
declare function MistralStream(response: AsyncGenerator<ChatCompletionResponseChunk, void, unknown>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
859
|
+
|
787
860
|
interface Prediction {
|
788
861
|
id: string;
|
789
862
|
status: 'starting' | 'processing' | 'succeeded' | 'failed' | 'canceled';
|
@@ -830,112 +903,28 @@ declare function ReplicateStream(res: Prediction, cb?: AIStreamCallbacksAndOptio
|
|
830
903
|
headers?: Record<string, string>;
|
831
904
|
}): Promise<ReadableStream>;
|
832
905
|
|
833
|
-
interface StreamPart<CODE extends string, NAME extends string, TYPE> {
|
834
|
-
code: CODE;
|
835
|
-
name: NAME;
|
836
|
-
parse: (value: JSONValue) => {
|
837
|
-
type: NAME;
|
838
|
-
value: TYPE;
|
839
|
-
};
|
840
|
-
}
|
841
|
-
declare const textStreamPart: StreamPart<'0', 'text', string>;
|
842
|
-
declare const functionCallStreamPart: StreamPart<'1', 'function_call', {
|
843
|
-
function_call: FunctionCall;
|
844
|
-
}>;
|
845
|
-
declare const dataStreamPart: StreamPart<'2', 'data', Array<JSONValue>>;
|
846
|
-
declare const errorStreamPart: StreamPart<'3', 'error', string>;
|
847
|
-
declare const assistantMessageStreamPart: StreamPart<'4', 'assistant_message', AssistantMessage>;
|
848
|
-
declare const assistantControlDataStreamPart: StreamPart<'5', 'assistant_control_data', {
|
849
|
-
threadId: string;
|
850
|
-
messageId: string;
|
851
|
-
}>;
|
852
|
-
declare const dataMessageStreamPart: StreamPart<'6', 'data_message', DataMessage>;
|
853
|
-
declare const toolCallStreamPart: StreamPart<'7', 'tool_calls', {
|
854
|
-
tool_calls: ToolCall[];
|
855
|
-
}>;
|
856
|
-
declare const messageAnnotationsStreamPart: StreamPart<'8', 'message_annotations', Array<JSONValue>>;
|
857
|
-
type StreamPartType = ReturnType<typeof textStreamPart.parse> | ReturnType<typeof functionCallStreamPart.parse> | ReturnType<typeof dataStreamPart.parse> | ReturnType<typeof errorStreamPart.parse> | ReturnType<typeof assistantMessageStreamPart.parse> | ReturnType<typeof assistantControlDataStreamPart.parse> | ReturnType<typeof dataMessageStreamPart.parse> | ReturnType<typeof toolCallStreamPart.parse> | ReturnType<typeof messageAnnotationsStreamPart.parse>;
|
858
906
|
/**
|
859
|
-
*
|
860
|
-
*
|
861
|
-
* - 0: Text from the LLM response
|
862
|
-
* - 1: (OpenAI) function_call responses
|
863
|
-
* - 2: custom JSON added by the user using `Data`
|
864
|
-
* - 6: (OpenAI) tool_call responses
|
865
|
-
*
|
866
|
-
* Example:
|
867
|
-
* ```
|
868
|
-
* 0:Vercel
|
869
|
-
* 0:'s
|
870
|
-
* 0: AI
|
871
|
-
* 0: AI
|
872
|
-
* 0: SDK
|
873
|
-
* 0: is great
|
874
|
-
* 0:!
|
875
|
-
* 2: { "someJson": "value" }
|
876
|
-
* 1: {"function_call": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}
|
877
|
-
* 6: {"tool_call": {"id": "tool_0", "type": "function", "function": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}}
|
878
|
-
*```
|
907
|
+
* A stream wrapper to send custom JSON-encoded data back to the client.
|
879
908
|
*/
|
880
|
-
declare
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
declare function createChunkDecoder(complex: false): (chunk: Uint8Array | undefined) => string;
|
895
|
-
declare function createChunkDecoder(complex: true): (chunk: Uint8Array | undefined) => StreamPartType[];
|
896
|
-
declare function createChunkDecoder(complex?: boolean): (chunk: Uint8Array | undefined) => StreamPartType[] | string;
|
897
|
-
|
898
|
-
declare const isStreamStringEqualToType: (type: keyof typeof StreamStringPrefixes, value: string) => value is `0:${string}\n` | `1:${string}\n` | `2:${string}\n` | `3:${string}\n` | `4:${string}\n` | `5:${string}\n` | `6:${string}\n` | `7:${string}\n` | `8:${string}\n`;
|
899
|
-
type StreamString = `${(typeof StreamStringPrefixes)[keyof typeof StreamStringPrefixes]}:${string}\n`;
|
909
|
+
declare class experimental_StreamData {
|
910
|
+
private encoder;
|
911
|
+
private controller;
|
912
|
+
stream: TransformStream<Uint8Array, Uint8Array>;
|
913
|
+
private isClosedPromise;
|
914
|
+
private isClosedPromiseResolver;
|
915
|
+
private isClosed;
|
916
|
+
private data;
|
917
|
+
private messageAnnotations;
|
918
|
+
constructor();
|
919
|
+
close(): Promise<void>;
|
920
|
+
append(value: JSONValue): void;
|
921
|
+
appendMessageAnnotation(value: JSONValue): void;
|
922
|
+
}
|
900
923
|
/**
|
901
|
-
* A
|
924
|
+
* A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
|
925
|
+
* This assumes every chunk is a 'text' chunk.
|
902
926
|
*/
|
903
|
-
declare
|
904
|
-
|
905
|
-
type AssistantResponseSettings = {
|
906
|
-
threadId: string;
|
907
|
-
messageId: string;
|
908
|
-
};
|
909
|
-
type AssistantResponseCallback = (stream: {
|
910
|
-
threadId: string;
|
911
|
-
messageId: string;
|
912
|
-
sendMessage: (message: AssistantMessage) => void;
|
913
|
-
sendDataMessage: (message: DataMessage) => void;
|
914
|
-
}) => Promise<void>;
|
915
|
-
declare function experimental_AssistantResponse({ threadId, messageId }: AssistantResponseSettings, process: AssistantResponseCallback): Response;
|
916
|
-
|
917
|
-
interface GenerateContentResponse {
|
918
|
-
candidates?: GenerateContentCandidate[];
|
919
|
-
}
|
920
|
-
interface GenerateContentCandidate {
|
921
|
-
index: number;
|
922
|
-
content: Content;
|
923
|
-
}
|
924
|
-
interface Content {
|
925
|
-
role: string;
|
926
|
-
parts: Part[];
|
927
|
-
}
|
928
|
-
type Part = TextPart | InlineDataPart;
|
929
|
-
interface InlineDataPart {
|
930
|
-
text?: never;
|
931
|
-
}
|
932
|
-
interface TextPart {
|
933
|
-
text: string;
|
934
|
-
inlineData?: never;
|
935
|
-
}
|
936
|
-
declare function GoogleGenerativeAIStream(response: {
|
937
|
-
stream: AsyncIterable<GenerateContentResponse>;
|
938
|
-
}, cb?: AIStreamCallbacksAndOptions): ReadableStream;
|
927
|
+
declare function createStreamDataTransformer(experimental_streamData: boolean | undefined): TransformStream<any, any>;
|
939
928
|
|
940
929
|
/**
|
941
930
|
* This is a naive implementation of the streaming React response API.
|
@@ -969,4 +958,18 @@ declare class experimental_StreamingReactResponse {
|
|
969
958
|
});
|
970
959
|
}
|
971
960
|
|
972
|
-
|
961
|
+
/**
|
962
|
+
* A utility class for streaming text responses.
|
963
|
+
*/
|
964
|
+
declare class StreamingTextResponse extends Response {
|
965
|
+
constructor(res: ReadableStream, init?: ResponseInit, data?: experimental_StreamData);
|
966
|
+
}
|
967
|
+
/**
|
968
|
+
* A utility function to stream a ReadableStream to a Node.js response-like object.
|
969
|
+
*/
|
970
|
+
declare function streamToResponse(res: ReadableStream, response: ServerResponse, init?: {
|
971
|
+
headers?: Record<string, string>;
|
972
|
+
status?: number;
|
973
|
+
}): void;
|
974
|
+
|
975
|
+
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantMessage, COMPLEX_HEADER, ChatRequest, ChatRequestOptions, CohereStream, CompletionUsage, CreateMessage, DataMessage, Function, FunctionCall, FunctionCallHandler, FunctionCallPayload, GoogleGenerativeAIStream, HuggingFaceStream, IdGenerator, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, JSONValue, LangChainStream, Message$1 as Message, MistralStream, OpenAIStream, OpenAIStreamCallbacks, ReactResponseRow, ReplicateStream, RequestOptions, StreamString, StreamingTextResponse, Tool, ToolCall, ToolCallHandler, ToolCallPayload, ToolChoice, UseChatOptions, UseCompletionOptions, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_AssistantResponse, experimental_StreamData, experimental_StreamingReactResponse, isStreamStringEqualToType, nanoid, readableFromAsyncIterable, streamToResponse, trimStartOfStreamHelper };
|