ai 3.2.38 → 3.2.40

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/README.md CHANGED
@@ -97,7 +97,7 @@ export async function POST(req: Request) {
97
97
  messages,
98
98
  });
99
99
 
100
- return result.toDataStreamamResponse();
100
+ return result.toDataStreamResponse();
101
101
  }
102
102
  ```
103
103
 
package/dist/index.d.mts CHANGED
@@ -2223,6 +2223,31 @@ type InkeepChatResultCallbacks = {
2223
2223
  type InkeepAIStreamCallbacksAndOptions = AIStreamCallbacksAndOptions & InkeepChatResultCallbacks;
2224
2224
  declare function InkeepStream(res: Response, callbacks?: InkeepAIStreamCallbacksAndOptions): ReadableStream;
2225
2225
 
2226
+ /**
2227
+ * A stream wrapper to send custom JSON-encoded data back to the client.
2228
+ */
2229
+ declare class StreamData {
2230
+ private encoder;
2231
+ private controller;
2232
+ stream: ReadableStream<Uint8Array>;
2233
+ private isClosed;
2234
+ private warningTimeout;
2235
+ constructor();
2236
+ close(): Promise<void>;
2237
+ append(value: JSONValue): void;
2238
+ appendMessageAnnotation(value: JSONValue): void;
2239
+ }
2240
+ /**
2241
+ * A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
2242
+ * This assumes every chunk is a 'text' chunk.
2243
+ */
2244
+ declare function createStreamDataTransformer(): TransformStream<any, any>;
2245
+ /**
2246
+ @deprecated Use `StreamData` instead.
2247
+ */
2248
+ declare class experimental_StreamData extends StreamData {
2249
+ }
2250
+
2226
2251
  type LangChainImageDetail = 'auto' | 'low' | 'high';
2227
2252
  type LangChainMessageContentText = {
2228
2253
  type: 'text';
@@ -2266,13 +2291,20 @@ The following streams are supported:
2266
2291
  - `string` streams (LangChain `StringOutputParser` output)
2267
2292
  */
2268
2293
  declare function toDataStream(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2294
+ declare function toDataStreamResponse(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, options?: {
2295
+ init?: ResponseInit;
2296
+ data?: StreamData;
2297
+ callbacks?: AIStreamCallbacksAndOptions;
2298
+ }): Response;
2269
2299
 
2270
2300
  declare const langchainAdapter_toAIStream: typeof toAIStream;
2271
2301
  declare const langchainAdapter_toDataStream: typeof toDataStream;
2302
+ declare const langchainAdapter_toDataStreamResponse: typeof toDataStreamResponse;
2272
2303
  declare namespace langchainAdapter {
2273
2304
  export {
2274
2305
  langchainAdapter_toAIStream as toAIStream,
2275
2306
  langchainAdapter_toDataStream as toDataStream,
2307
+ langchainAdapter_toDataStreamResponse as toDataStreamResponse,
2276
2308
  };
2277
2309
  }
2278
2310
 
@@ -2369,31 +2401,6 @@ declare function ReplicateStream(res: Prediction, cb?: AIStreamCallbacksAndOptio
2369
2401
  headers?: Record<string, string>;
2370
2402
  }): Promise<ReadableStream>;
2371
2403
 
2372
- /**
2373
- * A stream wrapper to send custom JSON-encoded data back to the client.
2374
- */
2375
- declare class StreamData {
2376
- private encoder;
2377
- private controller;
2378
- stream: ReadableStream<Uint8Array>;
2379
- private isClosed;
2380
- private warningTimeout;
2381
- constructor();
2382
- close(): Promise<void>;
2383
- append(value: JSONValue): void;
2384
- appendMessageAnnotation(value: JSONValue): void;
2385
- }
2386
- /**
2387
- * A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
2388
- * This assumes every chunk is a 'text' chunk.
2389
- */
2390
- declare function createStreamDataTransformer(): TransformStream<any, any>;
2391
- /**
2392
- @deprecated Use `StreamData` instead.
2393
- */
2394
- declare class experimental_StreamData extends StreamData {
2395
- }
2396
-
2397
2404
  /**
2398
2405
  * A utility function to stream a ReadableStream to a Node.js response-like object.
2399
2406
  */
package/dist/index.d.ts CHANGED
@@ -2223,6 +2223,31 @@ type InkeepChatResultCallbacks = {
2223
2223
  type InkeepAIStreamCallbacksAndOptions = AIStreamCallbacksAndOptions & InkeepChatResultCallbacks;
2224
2224
  declare function InkeepStream(res: Response, callbacks?: InkeepAIStreamCallbacksAndOptions): ReadableStream;
2225
2225
 
2226
+ /**
2227
+ * A stream wrapper to send custom JSON-encoded data back to the client.
2228
+ */
2229
+ declare class StreamData {
2230
+ private encoder;
2231
+ private controller;
2232
+ stream: ReadableStream<Uint8Array>;
2233
+ private isClosed;
2234
+ private warningTimeout;
2235
+ constructor();
2236
+ close(): Promise<void>;
2237
+ append(value: JSONValue): void;
2238
+ appendMessageAnnotation(value: JSONValue): void;
2239
+ }
2240
+ /**
2241
+ * A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
2242
+ * This assumes every chunk is a 'text' chunk.
2243
+ */
2244
+ declare function createStreamDataTransformer(): TransformStream<any, any>;
2245
+ /**
2246
+ @deprecated Use `StreamData` instead.
2247
+ */
2248
+ declare class experimental_StreamData extends StreamData {
2249
+ }
2250
+
2226
2251
  type LangChainImageDetail = 'auto' | 'low' | 'high';
2227
2252
  type LangChainMessageContentText = {
2228
2253
  type: 'text';
@@ -2266,13 +2291,20 @@ The following streams are supported:
2266
2291
  - `string` streams (LangChain `StringOutputParser` output)
2267
2292
  */
2268
2293
  declare function toDataStream(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2294
+ declare function toDataStreamResponse(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, options?: {
2295
+ init?: ResponseInit;
2296
+ data?: StreamData;
2297
+ callbacks?: AIStreamCallbacksAndOptions;
2298
+ }): Response;
2269
2299
 
2270
2300
  declare const langchainAdapter_toAIStream: typeof toAIStream;
2271
2301
  declare const langchainAdapter_toDataStream: typeof toDataStream;
2302
+ declare const langchainAdapter_toDataStreamResponse: typeof toDataStreamResponse;
2272
2303
  declare namespace langchainAdapter {
2273
2304
  export {
2274
2305
  langchainAdapter_toAIStream as toAIStream,
2275
2306
  langchainAdapter_toDataStream as toDataStream,
2307
+ langchainAdapter_toDataStreamResponse as toDataStreamResponse,
2276
2308
  };
2277
2309
  }
2278
2310
 
@@ -2369,31 +2401,6 @@ declare function ReplicateStream(res: Prediction, cb?: AIStreamCallbacksAndOptio
2369
2401
  headers?: Record<string, string>;
2370
2402
  }): Promise<ReadableStream>;
2371
2403
 
2372
- /**
2373
- * A stream wrapper to send custom JSON-encoded data back to the client.
2374
- */
2375
- declare class StreamData {
2376
- private encoder;
2377
- private controller;
2378
- stream: ReadableStream<Uint8Array>;
2379
- private isClosed;
2380
- private warningTimeout;
2381
- constructor();
2382
- close(): Promise<void>;
2383
- append(value: JSONValue): void;
2384
- appendMessageAnnotation(value: JSONValue): void;
2385
- }
2386
- /**
2387
- * A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
2388
- * This assumes every chunk is a 'text' chunk.
2389
- */
2390
- declare function createStreamDataTransformer(): TransformStream<any, any>;
2391
- /**
2392
- @deprecated Use `StreamData` instead.
2393
- */
2394
- declare class experimental_StreamData extends StreamData {
2395
- }
2396
-
2397
2404
  /**
2398
2405
  * A utility function to stream a ReadableStream to a Node.js response-like object.
2399
2406
  */
package/dist/index.js CHANGED
@@ -3476,7 +3476,8 @@ function InkeepStream(res, callbacks) {
3476
3476
  var langchain_adapter_exports = {};
3477
3477
  __export(langchain_adapter_exports, {
3478
3478
  toAIStream: () => toAIStream,
3479
- toDataStream: () => toDataStream
3479
+ toDataStream: () => toDataStream,
3480
+ toDataStreamResponse: () => toDataStreamResponse
3480
3481
  });
3481
3482
  function toAIStream(stream, callbacks) {
3482
3483
  return toDataStream(stream, callbacks);
@@ -3504,6 +3505,21 @@ function toDataStream(stream, callbacks) {
3504
3505
  })
3505
3506
  ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
3506
3507
  }
3508
+ function toDataStreamResponse(stream, options) {
3509
+ var _a;
3510
+ const dataStream = toDataStream(stream, options == null ? void 0 : options.callbacks);
3511
+ const data = options == null ? void 0 : options.data;
3512
+ const init = options == null ? void 0 : options.init;
3513
+ const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
3514
+ return new Response(responseStream, {
3515
+ status: (_a = init == null ? void 0 : init.status) != null ? _a : 200,
3516
+ statusText: init == null ? void 0 : init.statusText,
3517
+ headers: prepareResponseHeaders(init, {
3518
+ contentType: "text/plain; charset=utf-8",
3519
+ dataStreamVersion: "v1"
3520
+ })
3521
+ });
3522
+ }
3507
3523
  function forwardAIMessageChunk(chunk, controller) {
3508
3524
  if (typeof chunk.content === "string") {
3509
3525
  controller.enqueue(chunk.content);