ai 4.0.0-canary.3 → 4.0.0-canary.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # ai
2
2
 
3
+ ## 4.0.0-canary.4
4
+
5
+ ### Major Changes
6
+
7
+ - f0cb69d: chore (ai/core): remove experimental function exports
8
+ - da8c609: chore (ai): remove Tokens RSC helper
9
+ - cbab571: chore (ai): remove ExperimentalXXXMessage types
10
+ - 60e69ed: chore (ai/core): remove ai-stream related methods from streamText
11
+ - 073f282: chore (ai): remove AIStream and related exports
12
+ - 545d133: chore (ai): remove deprecated roundtrip settings from streamText / generateText
13
+
14
+ ### Patch Changes
15
+
16
+ - dce4158: chore (dependencies): update eventsource-parser to 3.0.0
17
+ - Updated dependencies [dce4158]
18
+ - Updated dependencies [ca3e586]
19
+ - Updated dependencies [dce4158]
20
+ - @ai-sdk/provider-utils@2.0.0-canary.2
21
+ - @ai-sdk/react@1.0.0-canary.4
22
+ - @ai-sdk/ui-utils@1.0.0-canary.4
23
+
3
24
  ## 4.0.0-canary.3
4
25
 
5
26
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { ToolInvocation, Attachment, Schema, DeepPartial, AssistantMessage, DataMessage, JSONValue as JSONValue$1 } from '@ai-sdk/ui-utils';
1
+ import { ToolInvocation, Attachment, Schema, DeepPartial, JSONValue as JSONValue$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
2
2
  export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, StreamPart, ToolInvocation, UseAssistantOptions, formatStreamPart, jsonSchema, parseStreamPart, processDataProtocolResponse, readDataStream } from '@ai-sdk/ui-utils';
3
+ export { ToolCall as CoreToolCall, ToolResult as CoreToolResult, generateId } from '@ai-sdk/provider-utils';
3
4
  import { AttributeValue, Tracer } from '@opentelemetry/api';
4
5
  import { EmbeddingModelV1, EmbeddingModelV1Embedding, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, JSONValue, LanguageModelV1CallOptions, NoSuchModelError, AISDKError } from '@ai-sdk/provider';
5
6
  export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LanguageModelV1, LanguageModelV1CallOptions, LanguageModelV1Prompt, LanguageModelV1StreamPart, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
@@ -8,7 +9,6 @@ import { ServerResponse } from 'http';
8
9
  import { ServerResponse as ServerResponse$1 } from 'node:http';
9
10
  import { AssistantStream } from 'openai/lib/AssistantStream';
10
11
  import { Run } from 'openai/resources/beta/threads/runs/runs';
11
- export { ToolCall as CoreToolCall, ToolResult as CoreToolResult } from '@ai-sdk/provider-utils';
12
12
 
13
13
  /**
14
14
  * Telemetry configuration.
@@ -561,10 +561,6 @@ type CoreSystemMessage = {
561
561
  */
562
562
  experimental_providerMetadata?: ProviderMetadata;
563
563
  };
564
- /**
565
- * @deprecated Use `CoreMessage` instead.
566
- */
567
- type ExperimentalMessage = CoreMessage;
568
564
  /**
569
565
  A user message. It can contain text or a combination of text and images.
570
566
  */
@@ -578,10 +574,6 @@ type CoreUserMessage = {
578
574
  */
579
575
  experimental_providerMetadata?: ProviderMetadata;
580
576
  };
581
- /**
582
- * @deprecated Use `CoreUserMessage` instead.
583
- */
584
- type ExperimentalUserMessage = CoreUserMessage;
585
577
  /**
586
578
  Content of a user message. It can be a string or an array of text and image parts.
587
579
  */
@@ -599,10 +591,6 @@ type CoreAssistantMessage = {
599
591
  */
600
592
  experimental_providerMetadata?: ProviderMetadata;
601
593
  };
602
- /**
603
- * @deprecated Use `CoreAssistantMessage` instead.
604
- */
605
- type ExperimentalAssistantMessage = CoreAssistantMessage;
606
594
  /**
607
595
  Content of an assistant message. It can be a string or an array of text and tool call parts.
608
596
  */
@@ -620,10 +608,6 @@ type CoreToolMessage = {
620
608
  */
621
609
  experimental_providerMetadata?: ProviderMetadata;
622
610
  };
623
- /**
624
- * @deprecated Use `CoreToolMessage` instead.
625
- */
626
- type ExperimentalToolMessage = CoreToolMessage;
627
611
  /**
628
612
  Content of a tool message. It is an array of tool result parts.
629
613
  */
@@ -929,10 +913,6 @@ functionality that can be fully encapsulated in the provider.
929
913
  currentDate?: () => Date;
930
914
  };
931
915
  }): Promise<GenerateObjectResult<JSONValue>>;
932
- /**
933
- * @deprecated Use `generateObject` instead.
934
- */
935
- declare const experimental_generateObject: typeof generateObject;
936
916
 
937
917
  type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
938
918
 
@@ -1249,10 +1229,6 @@ Callback that is called when the LLM response and the final object validation ar
1249
1229
  now?: () => number;
1250
1230
  };
1251
1231
  }): Promise<StreamObjectResult<JSONValue, JSONValue, never>>;
1252
- /**
1253
- * @deprecated Use `streamObject` instead.
1254
- */
1255
- declare const experimental_streamObject: typeof streamObject;
1256
1232
 
1257
1233
  type Parameters = z.ZodTypeAny | Schema<any>;
1258
1234
  type inferParameters<PARAMETERS extends Parameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
@@ -1518,13 +1494,6 @@ interface GenerateTextResult<TOOLS extends Record<string, CoreTool>> {
1518
1494
  */
1519
1495
  readonly responseMessages: Array<CoreAssistantMessage | CoreToolMessage>;
1520
1496
  /**
1521
- Response information for every roundtrip.
1522
- You can use this to get information about intermediate steps, such as the tool calls or the response headers.
1523
-
1524
- @deprecated use `steps` instead.
1525
- */
1526
- readonly roundtrips: Array<StepResult<TOOLS>>;
1527
- /**
1528
1497
  Details for all steps.
1529
1498
  You can use this to get information about intermediate steps,
1530
1499
  such as the tool calls or the response headers.
@@ -1620,7 +1589,7 @@ If set and supported by the model, calls will generate deterministic results.
1620
1589
  @returns
1621
1590
  A result object that contains the generated text, the results of the tool calls, and additional information.
1622
1591
  */
1623
- declare function generateText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxAutomaticRoundtrips, maxToolRoundtrips, maxSteps, experimental_continuationSteps, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, experimental_activeTools: activeTools, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
1592
+ declare function generateText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_continuationSteps, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, experimental_activeTools: activeTools, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
1624
1593
  /**
1625
1594
  The language model to use.
1626
1595
  */
@@ -1634,25 +1603,6 @@ The tool choice strategy. Default: 'auto'.
1634
1603
  */
1635
1604
  toolChoice?: CoreToolChoice<TOOLS>;
1636
1605
  /**
1637
- @deprecated Use `maxToolRoundtrips` instead.
1638
- */
1639
- maxAutomaticRoundtrips?: number;
1640
- /**
1641
- Maximum number of automatic roundtrips for tool calls.
1642
-
1643
- An automatic tool call roundtrip is another LLM call with the
1644
- tool call results when all tool calls of the last assistant
1645
- message have results.
1646
-
1647
- A maximum number is required to prevent infinite loops in the
1648
- case of misconfigured tools.
1649
-
1650
- By default, it's set to 0, which will disable the feature.
1651
-
1652
- @deprecated Use `maxSteps` instead (which is `maxToolRoundtrips` + 1).
1653
- */
1654
- maxToolRoundtrips?: number;
1655
- /**
1656
1606
  Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
1657
1607
 
1658
1608
  A maximum number is required to prevent infinite loops in the case of misconfigured tools.
@@ -1697,10 +1647,31 @@ changing the tool call and result types in the result.
1697
1647
  currentDate?: () => Date;
1698
1648
  };
1699
1649
  }): Promise<GenerateTextResult<TOOLS>>;
1650
+
1651
+ /**
1652
+ * A stream wrapper to send custom JSON-encoded data back to the client.
1653
+ */
1654
+ declare class StreamData {
1655
+ private encoder;
1656
+ private controller;
1657
+ stream: ReadableStream<Uint8Array>;
1658
+ private isClosed;
1659
+ private warningTimeout;
1660
+ constructor();
1661
+ close(): Promise<void>;
1662
+ append(value: JSONValue$1): void;
1663
+ appendMessageAnnotation(value: JSONValue$1): void;
1664
+ }
1700
1665
  /**
1701
- * @deprecated Use `generateText` instead.
1666
+ * A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
1667
+ * This assumes every chunk is a 'text' chunk.
1702
1668
  */
1703
- declare const experimental_generateText: typeof generateText;
1669
+ declare function createStreamDataTransformer(): TransformStream<any, any>;
1670
+ /**
1671
+ @deprecated Use `StreamData` instead.
1672
+ */
1673
+ declare class experimental_StreamData extends StreamData {
1674
+ }
1704
1675
 
1705
1676
  /**
1706
1677
  A result object for accessing different stream types and additional information.
@@ -1800,18 +1771,6 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1800
1771
  */
1801
1772
  readonly fullStream: AsyncIterableStream<TextStreamPart<TOOLS>>;
1802
1773
  /**
1803
- Converts the result to an `AIStream` object that is compatible with `StreamingTextResponse`.
1804
- It can be used with the `useChat` and `useCompletion` hooks.
1805
-
1806
- @param callbacks
1807
- Stream callbacks that will be called when the stream emits events.
1808
-
1809
- @returns A data stream.
1810
-
1811
- @deprecated Use `toDataStream` instead.
1812
- */
1813
- toAIStream(callbacks?: AIStreamCallbacksAndOptions): ReadableStream<Uint8Array>;
1814
- /**
1815
1774
  Converts the result to a data stream.
1816
1775
 
1817
1776
  @param data an optional StreamData object that will be merged into the stream.
@@ -1826,20 +1785,6 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1826
1785
  sendUsage?: boolean;
1827
1786
  }): ReadableStream<Uint8Array>;
1828
1787
  /**
1829
- Writes stream data output to a Node.js response-like object.
1830
- It sets a `Content-Type` header to `text/plain; charset=utf-8` and
1831
- writes each stream data part as a separate chunk.
1832
-
1833
- @param response A Node.js response-like object (ServerResponse).
1834
- @param init Optional headers and status code.
1835
-
1836
- @deprecated Use `pipeDataStreamToResponse` instead.
1837
- */
1838
- pipeAIStreamToResponse(response: ServerResponse$1, init?: {
1839
- headers?: Record<string, string>;
1840
- status?: number;
1841
- }): void;
1842
- /**
1843
1788
  Writes data stream output to a Node.js response-like object.
1844
1789
 
1845
1790
  @param response A Node.js response-like object (ServerResponse).
@@ -1868,21 +1813,6 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1868
1813
  @param options An object with an init property (ResponseInit) and a data property.
1869
1814
  You can also pass in a ResponseInit directly (deprecated).
1870
1815
 
1871
- @return A response object.
1872
-
1873
- @deprecated Use `toDataStreamResponse` instead.
1874
- */
1875
- toAIStreamResponse(options?: ResponseInit | {
1876
- init?: ResponseInit;
1877
- data?: StreamData;
1878
- }): Response;
1879
- /**
1880
- Converts the result to a streamed response object with a stream data part stream.
1881
- It can be used with the `useChat` and `useCompletion` hooks.
1882
-
1883
- @param options An object with an init property (ResponseInit) and a data property.
1884
- You can also pass in a ResponseInit directly (deprecated).
1885
-
1886
1816
  @return A response object.
1887
1817
  */
1888
1818
  toDataStreamResponse(options?: ResponseInit | {
@@ -1983,7 +1913,7 @@ If set and supported by the model, calls will generate deterministic results.
1983
1913
  @return
1984
1914
  A result object for accessing different stream types and additional information.
1985
1915
  */
1986
- declare function streamText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxToolRoundtrips, maxSteps, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, experimental_toolCallStreaming: toolCallStreaming, experimental_activeTools: activeTools, onChunk, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
1916
+ declare function streamText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, experimental_toolCallStreaming: toolCallStreaming, experimental_activeTools: activeTools, onChunk, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
1987
1917
  /**
1988
1918
  The language model to use.
1989
1919
  */
@@ -1997,21 +1927,6 @@ The tool choice strategy. Default: 'auto'.
1997
1927
  */
1998
1928
  toolChoice?: CoreToolChoice<TOOLS>;
1999
1929
  /**
2000
- Maximum number of automatic roundtrips for tool calls.
2001
-
2002
- An automatic tool call roundtrip is another LLM call with the
2003
- tool call results when all tool calls of the last assistant
2004
- message have results.
2005
-
2006
- A maximum number is required to prevent infinite loops in the
2007
- case of misconfigured tools.
2008
-
2009
- By default, it's set to 0, which will disable the feature.
2010
-
2011
- @deprecated Use `maxSteps` instead (which is `maxToolRoundtrips` + 1).
2012
- */
2013
- maxToolRoundtrips?: number;
2014
- /**
2015
1930
  Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
2016
1931
 
2017
1932
  A maximum number is required to prevent infinite loops in the case of misconfigured tools.
@@ -2086,10 +2001,6 @@ need to be added separately.
2086
2001
  currentDate?: () => Date;
2087
2002
  };
2088
2003
  }): Promise<StreamTextResult<TOOLS>>;
2089
- /**
2090
- * @deprecated Use `streamText` instead.
2091
- */
2092
- declare const experimental_streamText: typeof streamText;
2093
2004
 
2094
2005
  /**
2095
2006
  * Experimental middleware for LanguageModelV1.
@@ -2291,10 +2202,6 @@ declare class InvalidToolArgumentsError extends AISDKError {
2291
2202
  cause: unknown;
2292
2203
  });
2293
2204
  static isInstance(error: unknown): error is InvalidToolArgumentsError;
2294
- /**
2295
- * @deprecated use `isInstance` instead
2296
- */
2297
- static isInvalidToolArgumentsError(error: unknown): error is InvalidToolArgumentsError;
2298
2205
  }
2299
2206
 
2300
2207
  declare const symbol$6: unique symbol;
@@ -2387,138 +2294,6 @@ declare class RetryError extends AISDKError {
2387
2294
  static isInstance(error: unknown): error is RetryError;
2388
2295
  }
2389
2296
 
2390
- interface FunctionCallPayload {
2391
- name: string;
2392
- arguments: Record<string, unknown>;
2393
- }
2394
- interface ToolCallPayload {
2395
- tools: {
2396
- id: string;
2397
- type: 'function';
2398
- func: {
2399
- name: string;
2400
- arguments: Record<string, unknown>;
2401
- };
2402
- }[];
2403
- }
2404
- /**
2405
- * Configuration options and helper callback methods for AIStream stream lifecycle events.
2406
- * @interface
2407
- */
2408
- interface AIStreamCallbacksAndOptions {
2409
- /** `onStart`: Called once when the stream is initialized. */
2410
- onStart?: () => Promise<void> | void;
2411
- /** `onCompletion`: Called for each tokenized message. */
2412
- onCompletion?: (completion: string) => Promise<void> | void;
2413
- /** `onFinal`: Called once when the stream is closed with the final completion message. */
2414
- onFinal?: (completion: string) => Promise<void> | void;
2415
- /** `onToken`: Called for each tokenized message. */
2416
- onToken?: (token: string) => Promise<void> | void;
2417
- /** `onText`: Called for each text chunk. */
2418
- onText?: (text: string) => Promise<void> | void;
2419
- /**
2420
- * @deprecated This flag is no longer used and only retained for backwards compatibility.
2421
- * You can remove it from your code.
2422
- */
2423
- experimental_streamData?: boolean;
2424
- }
2425
- /**
2426
- * Options for the AIStreamParser.
2427
- * @interface
2428
- * @property {string} event - The event (type) from the server side event stream.
2429
- */
2430
- interface AIStreamParserOptions {
2431
- event?: string;
2432
- }
2433
- /**
2434
- * Custom parser for AIStream data.
2435
- * @interface
2436
- * @param {string} data - The data to be parsed.
2437
- * @param {AIStreamParserOptions} options - The options for the parser.
2438
- * @returns {string | void} The parsed data or void.
2439
- */
2440
- interface AIStreamParser {
2441
- (data: string, options: AIStreamParserOptions): string | void | {
2442
- isText: false;
2443
- content: string;
2444
- };
2445
- }
2446
- /**
2447
- * Creates a TransformStream that parses events from an EventSource stream using a custom parser.
2448
- * @param {AIStreamParser} customParser - Function to handle event data.
2449
- * @returns {TransformStream<Uint8Array, string>} TransformStream parsing events.
2450
- */
2451
- declare function createEventStreamTransformer(customParser?: AIStreamParser): TransformStream<Uint8Array, string | {
2452
- isText: false;
2453
- content: string;
2454
- }>;
2455
- /**
2456
- * Creates a transform stream that encodes input messages and invokes optional callback functions.
2457
- * The transform stream uses the provided callbacks to execute custom logic at different stages of the stream's lifecycle.
2458
- * - `onStart`: Called once when the stream is initialized.
2459
- * - `onToken`: Called for each tokenized message.
2460
- * - `onCompletion`: Called every time an AIStream completion message is received. This can occur multiple times when using e.g. OpenAI functions
2461
- * - `onFinal`: Called once when the stream is closed with the final completion message.
2462
- *
2463
- * This function is useful when you want to process a stream of messages and perform specific actions during the stream's lifecycle.
2464
- *
2465
- * @param {AIStreamCallbacksAndOptions} [callbacks] - An object containing the callback functions.
2466
- * @return {TransformStream<string, Uint8Array>} A transform stream that encodes input messages as Uint8Array and allows the execution of custom logic through callbacks.
2467
- *
2468
- * @example
2469
- * const callbacks = {
2470
- * onStart: async () => console.log('Stream started'),
2471
- * onToken: async (token) => console.log(`Token: ${token}`),
2472
- * onCompletion: async (completion) => console.log(`Completion: ${completion}`)
2473
- * onFinal: async () => data.close()
2474
- * };
2475
- * const transformer = createCallbacksTransformer(callbacks);
2476
- */
2477
- declare function createCallbacksTransformer(cb: AIStreamCallbacksAndOptions | undefined): TransformStream<string | {
2478
- isText: false;
2479
- content: string;
2480
- }, Uint8Array>;
2481
- /**
2482
- * Returns a stateful function that, when invoked, trims leading whitespace
2483
- * from the input text. The trimming only occurs on the first invocation, ensuring that
2484
- * subsequent calls do not alter the input text. This is particularly useful in scenarios
2485
- * where a text stream is being processed and only the initial whitespace should be removed.
2486
- *
2487
- * @return {function(string): string} A function that takes a string as input and returns a string
2488
- * with leading whitespace removed if it is the first invocation; otherwise, it returns the input unchanged.
2489
- *
2490
- * @example
2491
- * const trimStart = trimStartOfStreamHelper();
2492
- * const output1 = trimStart(" text"); // "text"
2493
- * const output2 = trimStart(" text"); // " text"
2494
- *
2495
- */
2496
- declare function trimStartOfStreamHelper(): (text: string) => string;
2497
- /**
2498
- * Returns a ReadableStream created from the response, parsed and handled with custom logic.
2499
- * The stream goes through two transformation stages, first parsing the events and then
2500
- * invoking the provided callbacks.
2501
- *
2502
- * For 2xx HTTP responses:
2503
- * - The function continues with standard stream processing.
2504
- *
2505
- * For non-2xx HTTP responses:
2506
- * - If the response body is defined, it asynchronously extracts and decodes the response body.
2507
- * - It then creates a custom ReadableStream to propagate a detailed error message.
2508
- *
2509
- * @param {Response} response - The response.
2510
- * @param {AIStreamParser} customParser - The custom parser function.
2511
- * @param {AIStreamCallbacksAndOptions} callbacks - The callbacks.
2512
- * @return {ReadableStream} The AIStream.
2513
- * @throws Will throw an error if the response is not OK.
2514
- */
2515
- declare function AIStream(response: Response, customParser?: AIStreamParser, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<Uint8Array>;
2516
- /**
2517
- * Implements ReadableStream.from(asyncIterable), which isn't documented in MDN and isn't implemented in node.
2518
- * https://github.com/whatwg/streams/commit/8d7a0bf26eb2cc23e884ddbaac7c1da4b91cf2bc
2519
- */
2520
- declare function readableFromAsyncIterable<T>(iterable: AsyncIterable<T>): ReadableStream<T>;
2521
-
2522
2297
  /**
2523
2298
  You can pass the thread and the latest message into the `AssistantResponse`. This establishes the context for the response.
2524
2299
  */
@@ -2569,28 +2344,19 @@ declare function AssistantResponse({ threadId, messageId }: AssistantResponseSet
2569
2344
  declare const experimental_AssistantResponse: typeof AssistantResponse;
2570
2345
 
2571
2346
  /**
2572
- * A stream wrapper to send custom JSON-encoded data back to the client.
2573
- */
2574
- declare class StreamData {
2575
- private encoder;
2576
- private controller;
2577
- stream: ReadableStream<Uint8Array>;
2578
- private isClosed;
2579
- private warningTimeout;
2580
- constructor();
2581
- close(): Promise<void>;
2582
- append(value: JSONValue$1): void;
2583
- appendMessageAnnotation(value: JSONValue$1): void;
2584
- }
2585
- /**
2586
- * A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
2587
- * This assumes every chunk is a 'text' chunk.
2588
- */
2589
- declare function createStreamDataTransformer(): TransformStream<any, any>;
2590
- /**
2591
- @deprecated Use `StreamData` instead.
2347
+ * Configuration options and helper callback methods for stream lifecycle events.
2592
2348
  */
2593
- declare class experimental_StreamData extends StreamData {
2349
+ interface StreamCallbacks {
2350
+ /** `onStart`: Called once when the stream is initialized. */
2351
+ onStart?: () => Promise<void> | void;
2352
+ /** `onCompletion`: Called for each tokenized message. */
2353
+ onCompletion?: (completion: string) => Promise<void> | void;
2354
+ /** `onFinal`: Called once when the stream is closed with the final completion message. */
2355
+ onFinal?: (completion: string) => Promise<void> | void;
2356
+ /** `onToken`: Called for each tokenized message. */
2357
+ onToken?: (token: string) => Promise<void> | void;
2358
+ /** `onText`: Called for each text chunk. */
2359
+ onText?: (text: string) => Promise<void> | void;
2594
2360
  }
2595
2361
 
2596
2362
  type LangChainImageDetail = 'auto' | 'low' | 'high';
@@ -2627,7 +2393,7 @@ The following streams are supported:
2627
2393
 
2628
2394
  @deprecated Use `toDataStream` instead.
2629
2395
  */
2630
- declare function toAIStream(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2396
+ declare function toAIStream(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: StreamCallbacks): ReadableStream<any>;
2631
2397
  /**
2632
2398
  Converts LangChain output streams to AIStream.
2633
2399
 
@@ -2635,11 +2401,11 @@ The following streams are supported:
2635
2401
  - `LangChainAIMessageChunk` streams (LangChain `model.stream` output)
2636
2402
  - `string` streams (LangChain `StringOutputParser` output)
2637
2403
  */
2638
- declare function toDataStream$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2404
+ declare function toDataStream$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: StreamCallbacks): ReadableStream<any>;
2639
2405
  declare function toDataStreamResponse$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, options?: {
2640
2406
  init?: ResponseInit;
2641
2407
  data?: StreamData;
2642
- callbacks?: AIStreamCallbacksAndOptions;
2408
+ callbacks?: StreamCallbacks;
2643
2409
  }): Response;
2644
2410
 
2645
2411
  declare const langchainAdapter_toAIStream: typeof toAIStream;
@@ -2654,11 +2420,11 @@ declare namespace langchainAdapter {
2654
2420
  type EngineResponse = {
2655
2421
  delta: string;
2656
2422
  };
2657
- declare function toDataStream(stream: AsyncIterable<EngineResponse>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2423
+ declare function toDataStream(stream: AsyncIterable<EngineResponse>, callbacks?: StreamCallbacks): ReadableStream<any>;
2658
2424
  declare function toDataStreamResponse(stream: AsyncIterable<EngineResponse>, options?: {
2659
2425
  init?: ResponseInit;
2660
2426
  data?: StreamData;
2661
- callbacks?: AIStreamCallbacksAndOptions;
2427
+ callbacks?: StreamCallbacks;
2662
2428
  }): Response;
2663
2429
 
2664
2430
  declare const llamaindexAdapter_toDataStream: typeof toDataStream;
@@ -2697,6 +2463,4 @@ declare class StreamingTextResponse extends Response {
2697
2463
  constructor(res: ReadableStream, init?: ResponseInit, data?: StreamData);
2698
2464
  }
2699
2465
 
2700
- declare const generateId: (size?: number) => string;
2701
-
2702
- export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AssistantContent, AssistantResponse, CallWarning, CompletionTokenUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, ToolCallUnion as CoreToolCallUnion, CoreToolChoice, CoreToolMessage, ToolResultUnion as CoreToolResultUnion, CoreUserMessage, DataContent, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, EmbeddingTokenUsage, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, Experimental_LanguageModelV1Middleware, FilePart, FinishReason, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelResponseMetadataWithHeaders, LanguageModelUsage, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MessageConversionError, NoObjectGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, Provider, ProviderMetadata, RetryError, StepResult, StreamData, StreamObjectResult, StreamTextResult, StreamingTextResponse, TextPart, TextStreamPart, TokenUsage, ToolCallPart, ToolCallPayload, ToolContent, ToolResultPart, UserContent, convertToCoreMessages, cosineSimilarity, createCallbacksTransformer, createEventStreamTransformer, createStreamDataTransformer, embed, embedMany, experimental_AssistantResponse, experimental_ModelRegistry, experimental_Provider, experimental_ProviderRegistry, experimental_StreamData, experimental_createModelRegistry, experimental_createProviderRegistry, experimental_customProvider, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, experimental_wrapLanguageModel, generateId, generateObject, generateText, readableFromAsyncIterable, streamObject, streamText, streamToResponse, tool, trimStartOfStreamHelper };
2466
+ export { AssistantContent, AssistantResponse, CallWarning, CompletionTokenUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, ToolCallUnion as CoreToolCallUnion, CoreToolChoice, CoreToolMessage, ToolResultUnion as CoreToolResultUnion, CoreUserMessage, DataContent, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, EmbeddingTokenUsage, ExperimentalTool, Experimental_LanguageModelV1Middleware, FilePart, FinishReason, GenerateObjectResult, GenerateTextResult, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelResponseMetadataWithHeaders, LanguageModelUsage, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MessageConversionError, NoObjectGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, Provider, ProviderMetadata, RetryError, StepResult, StreamData, StreamObjectResult, StreamTextResult, StreamingTextResponse, TextPart, TextStreamPart, TokenUsage, ToolCallPart, ToolContent, ToolResultPart, UserContent, convertToCoreMessages, cosineSimilarity, createStreamDataTransformer, embed, embedMany, experimental_AssistantResponse, experimental_ModelRegistry, experimental_Provider, experimental_ProviderRegistry, experimental_StreamData, experimental_createModelRegistry, experimental_createProviderRegistry, experimental_customProvider, experimental_wrapLanguageModel, generateObject, generateText, streamObject, streamText, streamToResponse, tool };