ai 2.2.36 → 3.0.0

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 CHANGED
@@ -1,3 +1,4 @@
1
+ import { ChatCompletionResponseChunk } from '@mistralai/mistralai';
1
2
  import { ServerResponse } from 'node:http';
2
3
 
3
4
  interface FunctionCall {
@@ -854,6 +855,8 @@ declare function LangChainStream(callbacks?: AIStreamCallbacksAndOptions): {
854
855
  };
855
856
  };
856
857
 
858
+ declare function MistralStream(response: AsyncGenerator<ChatCompletionResponseChunk, void, unknown>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
859
+
857
860
  interface Prediction {
858
861
  id: string;
859
862
  status: 'starting' | 'processing' | 'succeeded' | 'failed' | 'canceled';
@@ -969,4 +972,4 @@ declare function streamToResponse(res: ReadableStream, response: ServerResponse,
969
972
  status?: number;
970
973
  }): void;
971
974
 
972
- 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, 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 };
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 };
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ __export(streams_exports, {
32
32
  HuggingFaceStream: () => HuggingFaceStream,
33
33
  InkeepStream: () => InkeepStream,
34
34
  LangChainStream: () => LangChainStream,
35
+ MistralStream: () => MistralStream,
35
36
  OpenAIStream: () => OpenAIStream,
36
37
  ReplicateStream: () => ReplicateStream,
37
38
  StreamingTextResponse: () => StreamingTextResponse,
@@ -830,12 +831,30 @@ function LangChainStream(callbacks) {
830
831
  };
831
832
  }
832
833
 
834
+ // streams/mistral-stream.ts
835
+ async function* streamable4(stream) {
836
+ var _a, _b;
837
+ for await (const chunk of stream) {
838
+ const content = (_b = (_a = chunk.choices[0]) == null ? void 0 : _a.delta) == null ? void 0 : _b.content;
839
+ if (content === void 0 || content === "") {
840
+ continue;
841
+ }
842
+ yield content;
843
+ }
844
+ }
845
+ function MistralStream(response, callbacks) {
846
+ const stream = readableFromAsyncIterable(streamable4(response));
847
+ return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
848
+ createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
849
+ );
850
+ }
851
+
833
852
  // streams/openai-stream.ts
834
853
  function parseOpenAIStream() {
835
854
  const extract = chunkToText();
836
855
  return (data) => extract(JSON.parse(data));
837
856
  }
838
- async function* streamable4(stream) {
857
+ async function* streamable5(stream) {
839
858
  const extract = chunkToText();
840
859
  for await (let chunk of stream) {
841
860
  if ("promptFilterResults" in chunk) {
@@ -875,7 +894,7 @@ function chunkToText() {
875
894
  const trimStartOfStream = trimStartOfStreamHelper();
876
895
  let isFunctionStreamingIn;
877
896
  return (json) => {
878
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
897
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
879
898
  if (isChatCompletionChunk(json)) {
880
899
  const delta = (_a = json.choices[0]) == null ? void 0 : _a.delta;
881
900
  if ((_b = delta.function_call) == null ? void 0 : _b.name) {
@@ -891,12 +910,12 @@ function chunkToText() {
891
910
  }
892
911
  } else if ((_h = delta.function_call) == null ? void 0 : _h.arguments) {
893
912
  return cleanupArguments((_i = delta.function_call) == null ? void 0 : _i.arguments);
894
- } else if ((_k = (_j = delta.tool_calls) == null ? void 0 : _j[0].function) == null ? void 0 : _k.arguments) {
895
- return cleanupArguments((_n = (_m = (_l = delta.tool_calls) == null ? void 0 : _l[0]) == null ? void 0 : _m.function) == null ? void 0 : _n.arguments);
896
- } else if (isFunctionStreamingIn && (((_o = json.choices[0]) == null ? void 0 : _o.finish_reason) === "function_call" || ((_p = json.choices[0]) == null ? void 0 : _p.finish_reason) === "stop")) {
913
+ } else if ((_l = (_k = (_j = delta.tool_calls) == null ? void 0 : _j[0]) == null ? void 0 : _k.function) == null ? void 0 : _l.arguments) {
914
+ return cleanupArguments((_o = (_n = (_m = delta.tool_calls) == null ? void 0 : _m[0]) == null ? void 0 : _n.function) == null ? void 0 : _o.arguments);
915
+ } else if (isFunctionStreamingIn && (((_p = json.choices[0]) == null ? void 0 : _p.finish_reason) === "function_call" || ((_q = json.choices[0]) == null ? void 0 : _q.finish_reason) === "stop")) {
897
916
  isFunctionStreamingIn = false;
898
917
  return '"}}';
899
- } else if (isFunctionStreamingIn && ((_q = json.choices[0]) == null ? void 0 : _q.finish_reason) === "tool_calls") {
918
+ } else if (isFunctionStreamingIn && ((_r = json.choices[0]) == null ? void 0 : _r.finish_reason) === "tool_calls") {
900
919
  isFunctionStreamingIn = false;
901
920
  return '"}}]}';
902
921
  }
@@ -924,7 +943,7 @@ function OpenAIStream(res, callbacks) {
924
943
  const cb = callbacks;
925
944
  let stream;
926
945
  if (Symbol.asyncIterator in res) {
927
- stream = readableFromAsyncIterable(streamable4(res)).pipeThrough(
946
+ stream = readableFromAsyncIterable(streamable5(res)).pipeThrough(
928
947
  createCallbacksTransformer(
929
948
  (cb == null ? void 0 : cb.experimental_onFunctionCall) || (cb == null ? void 0 : cb.experimental_onToolCall) ? {
930
949
  ...cb,
@@ -1431,6 +1450,7 @@ function streamToResponse(res, response, init) {
1431
1450
  HuggingFaceStream,
1432
1451
  InkeepStream,
1433
1452
  LangChainStream,
1453
+ MistralStream,
1434
1454
  OpenAIStream,
1435
1455
  ReplicateStream,
1436
1456
  StreamingTextResponse,