ai 3.2.30 → 3.2.32

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.mts CHANGED
@@ -2098,6 +2098,10 @@ type LangChainMessageContent = string | LangChainMessageContentComplex[];
2098
2098
  type LangChainAIMessageChunk = {
2099
2099
  content: LangChainMessageContent;
2100
2100
  };
2101
+ type LangChainStreamEvent = {
2102
+ event: string;
2103
+ data: any;
2104
+ };
2101
2105
  /**
2102
2106
  Converts LangChain output streams to AIStream.
2103
2107
 
@@ -2105,7 +2109,7 @@ The following streams are supported:
2105
2109
  - `LangChainAIMessageChunk` streams (LangChain `model.stream` output)
2106
2110
  - `string` streams (LangChain `StringOutputParser` output)
2107
2111
  */
2108
- declare function toAIStream(stream: ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2112
+ declare function toAIStream(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2109
2113
 
2110
2114
  declare const langchainAdapter_toAIStream: typeof toAIStream;
2111
2115
  declare namespace langchainAdapter {
package/dist/index.d.ts CHANGED
@@ -2098,6 +2098,10 @@ type LangChainMessageContent = string | LangChainMessageContentComplex[];
2098
2098
  type LangChainAIMessageChunk = {
2099
2099
  content: LangChainMessageContent;
2100
2100
  };
2101
+ type LangChainStreamEvent = {
2102
+ event: string;
2103
+ data: any;
2104
+ };
2101
2105
  /**
2102
2106
  Converts LangChain output streams to AIStream.
2103
2107
 
@@ -2105,7 +2109,7 @@ The following streams are supported:
2105
2109
  - `LangChainAIMessageChunk` streams (LangChain `model.stream` output)
2106
2110
  - `string` streams (LangChain `StringOutputParser` output)
2107
2111
  */
2108
- declare function toAIStream(stream: ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2112
+ declare function toAIStream(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2109
2113
 
2110
2114
  declare const langchainAdapter_toAIStream: typeof toAIStream;
2111
2115
  declare namespace langchainAdapter {
package/dist/index.js CHANGED
@@ -3201,23 +3201,38 @@ __export(langchain_adapter_exports, {
3201
3201
  function toAIStream(stream, callbacks) {
3202
3202
  return stream.pipeThrough(
3203
3203
  new TransformStream({
3204
- transform: async (chunk, controller) => {
3205
- if (typeof chunk === "string") {
3206
- controller.enqueue(chunk);
3207
- } else if (typeof chunk.content === "string") {
3208
- controller.enqueue(chunk.content);
3209
- } else {
3210
- const content = chunk.content;
3211
- for (const item of content) {
3212
- if (item.type === "text") {
3213
- controller.enqueue(item.text);
3214
- }
3204
+ transform: async (value, controller) => {
3205
+ var _a;
3206
+ if (typeof value === "string") {
3207
+ controller.enqueue(value);
3208
+ return;
3209
+ }
3210
+ if ("event" in value) {
3211
+ if (value.event === "on_chat_model_stream") {
3212
+ forwardAIMessageChunk(
3213
+ (_a = value.data) == null ? void 0 : _a.chunk,
3214
+ controller
3215
+ );
3215
3216
  }
3217
+ return;
3216
3218
  }
3219
+ forwardAIMessageChunk(value, controller);
3217
3220
  }
3218
3221
  })
3219
3222
  ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
3220
3223
  }
3224
+ function forwardAIMessageChunk(chunk, controller) {
3225
+ if (typeof chunk.content === "string") {
3226
+ controller.enqueue(chunk.content);
3227
+ } else {
3228
+ const content = chunk.content;
3229
+ for (const item of content) {
3230
+ if (item.type === "text") {
3231
+ controller.enqueue(item.text);
3232
+ }
3233
+ }
3234
+ }
3235
+ }
3221
3236
 
3222
3237
  // streams/langchain-stream.ts
3223
3238
  function LangChainStream(callbacks) {