ai 3.2.29 → 3.2.31

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.mjs CHANGED
@@ -3132,23 +3132,38 @@ __export(langchain_adapter_exports, {
3132
3132
  function toAIStream(stream, callbacks) {
3133
3133
  return stream.pipeThrough(
3134
3134
  new TransformStream({
3135
- transform: async (chunk, controller) => {
3136
- if (typeof chunk === "string") {
3137
- controller.enqueue(chunk);
3138
- } else if (typeof chunk.content === "string") {
3139
- controller.enqueue(chunk.content);
3140
- } else {
3141
- const content = chunk.content;
3142
- for (const item of content) {
3143
- if (item.type === "text") {
3144
- controller.enqueue(item.text);
3145
- }
3135
+ transform: async (value, controller) => {
3136
+ var _a;
3137
+ if (typeof value === "string") {
3138
+ controller.enqueue(value);
3139
+ return;
3140
+ }
3141
+ if ("event" in value) {
3142
+ if (value.event === "on_chat_model_stream") {
3143
+ forwardAIMessageChunk(
3144
+ (_a = value.data) == null ? void 0 : _a.chunk,
3145
+ controller
3146
+ );
3146
3147
  }
3148
+ return;
3147
3149
  }
3150
+ forwardAIMessageChunk(value, controller);
3148
3151
  }
3149
3152
  })
3150
3153
  ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
3151
3154
  }
3155
+ function forwardAIMessageChunk(chunk, controller) {
3156
+ if (typeof chunk.content === "string") {
3157
+ controller.enqueue(chunk.content);
3158
+ } else {
3159
+ const content = chunk.content;
3160
+ for (const item of content) {
3161
+ if (item.type === "text") {
3162
+ controller.enqueue(item.text);
3163
+ }
3164
+ }
3165
+ }
3166
+ }
3152
3167
 
3153
3168
  // streams/langchain-stream.ts
3154
3169
  function LangChainStream(callbacks) {