ai 4.0.0-canary.3 → 4.0.0-canary.5

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,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
  */
@@ -681,17 +665,6 @@ interface GenerateObjectResult<T> {
681
665
  */
682
666
  readonly warnings: CallWarning[] | undefined;
683
667
  /**
684
- Optional raw response data.
685
-
686
- @deprecated Use `response.headers` instead.
687
- */
688
- readonly rawResponse?: {
689
- /**
690
- Response headers.
691
- */
692
- headers?: Record<string, string>;
693
- };
694
- /**
695
668
  Additional request information.
696
669
  */
697
670
  readonly request: LanguageModelRequestMetadata;
@@ -929,10 +902,6 @@ functionality that can be fully encapsulated in the provider.
929
902
  currentDate?: () => Date;
930
903
  };
931
904
  }): Promise<GenerateObjectResult<JSONValue>>;
932
- /**
933
- * @deprecated Use `generateObject` instead.
934
- */
935
- declare const experimental_generateObject: typeof generateObject;
936
905
 
937
906
  type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
938
907
 
@@ -955,17 +924,6 @@ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
955
924
  */
956
925
  readonly experimental_providerMetadata: Promise<ProviderMetadata | undefined>;
957
926
  /**
958
- Optional raw response data.
959
-
960
- @deprecated Use `response` instead.
961
- */
962
- readonly rawResponse?: {
963
- /**
964
- Response headers.
965
- */
966
- headers?: Record<string, string>;
967
- };
968
- /**
969
927
  Additional request information from the last step.
970
928
  */
971
929
  readonly request: Promise<LanguageModelRequestMetadata>;
@@ -1049,17 +1007,6 @@ type OnFinishCallback<RESULT> = (event: {
1049
1007
  */
1050
1008
  error: unknown | undefined;
1051
1009
  /**
1052
- Optional raw response data.
1053
-
1054
- @deprecated Use `response` instead.
1055
- */
1056
- rawResponse?: {
1057
- /**
1058
- Response headers.
1059
- */
1060
- headers?: Record<string, string>;
1061
- };
1062
- /**
1063
1010
  Response metadata.
1064
1011
  */
1065
1012
  response: LanguageModelResponseMetadata;
@@ -1249,10 +1196,6 @@ Callback that is called when the LLM response and the final object validation ar
1249
1196
  now?: () => number;
1250
1197
  };
1251
1198
  }): Promise<StreamObjectResult<JSONValue, JSONValue, never>>;
1252
- /**
1253
- * @deprecated Use `streamObject` instead.
1254
- */
1255
- declare const experimental_streamObject: typeof streamObject;
1256
1199
 
1257
1200
  type Parameters = z.ZodTypeAny | Schema<any>;
1258
1201
  type inferParameters<PARAMETERS extends Parameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
@@ -1442,17 +1385,6 @@ type StepResult<TOOLS extends Record<string, CoreTool>> = {
1442
1385
  */
1443
1386
  readonly logprobs: LogProbs | undefined;
1444
1387
  /**
1445
- Optional raw response data.
1446
-
1447
- @deprecated Use `response.headers` instead.
1448
- */
1449
- readonly rawResponse?: {
1450
- /**
1451
- Response headers.
1452
- */
1453
- readonly headers?: Record<string, string>;
1454
- };
1455
- /**
1456
1388
  Additional request information.
1457
1389
  */
1458
1390
  readonly request: LanguageModelRequestMetadata;
@@ -1518,30 +1450,12 @@ interface GenerateTextResult<TOOLS extends Record<string, CoreTool>> {
1518
1450
  */
1519
1451
  readonly responseMessages: Array<CoreAssistantMessage | CoreToolMessage>;
1520
1452
  /**
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
1453
  Details for all steps.
1529
1454
  You can use this to get information about intermediate steps,
1530
1455
  such as the tool calls or the response headers.
1531
1456
  */
1532
1457
  readonly steps: Array<StepResult<TOOLS>>;
1533
1458
  /**
1534
- Optional raw response data.
1535
-
1536
- @deprecated Use `response.headers` instead.
1537
- */
1538
- readonly rawResponse?: {
1539
- /**
1540
- Response headers.
1541
- */
1542
- readonly headers?: Record<string, string>;
1543
- };
1544
- /**
1545
1459
  Additional request information.
1546
1460
  */
1547
1461
  readonly request: LanguageModelRequestMetadata;
@@ -1620,7 +1534,7 @@ If set and supported by the model, calls will generate deterministic results.
1620
1534
  @returns
1621
1535
  A result object that contains the generated text, the results of the tool calls, and additional information.
1622
1536
  */
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 & {
1537
+ 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
1538
  /**
1625
1539
  The language model to use.
1626
1540
  */
@@ -1634,25 +1548,6 @@ The tool choice strategy. Default: 'auto'.
1634
1548
  */
1635
1549
  toolChoice?: CoreToolChoice<TOOLS>;
1636
1550
  /**
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
1551
  Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
1657
1552
 
1658
1553
  A maximum number is required to prevent infinite loops in the case of misconfigured tools.
@@ -1697,10 +1592,31 @@ changing the tool call and result types in the result.
1697
1592
  currentDate?: () => Date;
1698
1593
  };
1699
1594
  }): Promise<GenerateTextResult<TOOLS>>;
1595
+
1596
+ /**
1597
+ * A stream wrapper to send custom JSON-encoded data back to the client.
1598
+ */
1599
+ declare class StreamData {
1600
+ private encoder;
1601
+ private controller;
1602
+ stream: ReadableStream<Uint8Array>;
1603
+ private isClosed;
1604
+ private warningTimeout;
1605
+ constructor();
1606
+ close(): Promise<void>;
1607
+ append(value: JSONValue$1): void;
1608
+ appendMessageAnnotation(value: JSONValue$1): void;
1609
+ }
1700
1610
  /**
1701
- * @deprecated Use `generateText` instead.
1611
+ * A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
1612
+ * This assumes every chunk is a 'text' chunk.
1702
1613
  */
1703
- declare const experimental_generateText: typeof generateText;
1614
+ declare function createStreamDataTransformer(): TransformStream<any, any>;
1615
+ /**
1616
+ @deprecated Use `StreamData` instead.
1617
+ */
1618
+ declare class experimental_StreamData extends StreamData {
1619
+ }
1704
1620
 
1705
1621
  /**
1706
1622
  A result object for accessing different stream types and additional information.
@@ -1748,17 +1664,6 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1748
1664
  */
1749
1665
  readonly toolResults: Promise<ToolResultUnion<TOOLS>[]>;
1750
1666
  /**
1751
- Optional raw response data.
1752
-
1753
- @deprecated Use `response` instead.
1754
- */
1755
- readonly rawResponse?: {
1756
- /**
1757
- Response headers.
1758
- */
1759
- headers?: Record<string, string>;
1760
- };
1761
- /**
1762
1667
  @deprecated use `response.messages` instead.
1763
1668
  */
1764
1669
  readonly responseMessages: Promise<Array<CoreAssistantMessage | CoreToolMessage>>;
@@ -1800,18 +1705,6 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1800
1705
  */
1801
1706
  readonly fullStream: AsyncIterableStream<TextStreamPart<TOOLS>>;
1802
1707
  /**
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
1708
  Converts the result to a data stream.
1816
1709
 
1817
1710
  @param data an optional StreamData object that will be merged into the stream.
@@ -1826,20 +1719,6 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1826
1719
  sendUsage?: boolean;
1827
1720
  }): ReadableStream<Uint8Array>;
1828
1721
  /**
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
1722
  Writes data stream output to a Node.js response-like object.
1844
1723
 
1845
1724
  @param response A Node.js response-like object (ServerResponse).
@@ -1868,21 +1747,6 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1868
1747
  @param options An object with an init property (ResponseInit) and a data property.
1869
1748
  You can also pass in a ResponseInit directly (deprecated).
1870
1749
 
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
1750
  @return A response object.
1887
1751
  */
1888
1752
  toDataStreamResponse(options?: ResponseInit | {
@@ -1983,7 +1847,7 @@ If set and supported by the model, calls will generate deterministic results.
1983
1847
  @return
1984
1848
  A result object for accessing different stream types and additional information.
1985
1849
  */
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 & {
1850
+ 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
1851
  /**
1988
1852
  The language model to use.
1989
1853
  */
@@ -1997,21 +1861,6 @@ The tool choice strategy. Default: 'auto'.
1997
1861
  */
1998
1862
  toolChoice?: CoreToolChoice<TOOLS>;
1999
1863
  /**
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
1864
  Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
2016
1865
 
2017
1866
  A maximum number is required to prevent infinite loops in the case of misconfigured tools.
@@ -2086,10 +1935,6 @@ need to be added separately.
2086
1935
  currentDate?: () => Date;
2087
1936
  };
2088
1937
  }): Promise<StreamTextResult<TOOLS>>;
2089
- /**
2090
- * @deprecated Use `streamText` instead.
2091
- */
2092
- declare const experimental_streamText: typeof streamText;
2093
1938
 
2094
1939
  /**
2095
1940
  * Experimental middleware for LanguageModelV1.
@@ -2291,10 +2136,6 @@ declare class InvalidToolArgumentsError extends AISDKError {
2291
2136
  cause: unknown;
2292
2137
  });
2293
2138
  static isInstance(error: unknown): error is InvalidToolArgumentsError;
2294
- /**
2295
- * @deprecated use `isInstance` instead
2296
- */
2297
- static isInvalidToolArgumentsError(error: unknown): error is InvalidToolArgumentsError;
2298
2139
  }
2299
2140
 
2300
2141
  declare const symbol$6: unique symbol;
@@ -2387,138 +2228,6 @@ declare class RetryError extends AISDKError {
2387
2228
  static isInstance(error: unknown): error is RetryError;
2388
2229
  }
2389
2230
 
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
2231
  /**
2523
2232
  You can pass the thread and the latest message into the `AssistantResponse`. This establishes the context for the response.
2524
2233
  */
@@ -2569,28 +2278,19 @@ declare function AssistantResponse({ threadId, messageId }: AssistantResponseSet
2569
2278
  declare const experimental_AssistantResponse: typeof AssistantResponse;
2570
2279
 
2571
2280
  /**
2572
- * A stream wrapper to send custom JSON-encoded data back to the client.
2281
+ * Configuration options and helper callback methods for stream lifecycle events.
2573
2282
  */
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.
2592
- */
2593
- declare class experimental_StreamData extends StreamData {
2283
+ interface StreamCallbacks {
2284
+ /** `onStart`: Called once when the stream is initialized. */
2285
+ onStart?: () => Promise<void> | void;
2286
+ /** `onCompletion`: Called for each tokenized message. */
2287
+ onCompletion?: (completion: string) => Promise<void> | void;
2288
+ /** `onFinal`: Called once when the stream is closed with the final completion message. */
2289
+ onFinal?: (completion: string) => Promise<void> | void;
2290
+ /** `onToken`: Called for each tokenized message. */
2291
+ onToken?: (token: string) => Promise<void> | void;
2292
+ /** `onText`: Called for each text chunk. */
2293
+ onText?: (text: string) => Promise<void> | void;
2594
2294
  }
2595
2295
 
2596
2296
  type LangChainImageDetail = 'auto' | 'low' | 'high';
@@ -2627,7 +2327,7 @@ The following streams are supported:
2627
2327
 
2628
2328
  @deprecated Use `toDataStream` instead.
2629
2329
  */
2630
- declare function toAIStream(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2330
+ declare function toAIStream(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: StreamCallbacks): ReadableStream<any>;
2631
2331
  /**
2632
2332
  Converts LangChain output streams to AIStream.
2633
2333
 
@@ -2635,11 +2335,11 @@ The following streams are supported:
2635
2335
  - `LangChainAIMessageChunk` streams (LangChain `model.stream` output)
2636
2336
  - `string` streams (LangChain `StringOutputParser` output)
2637
2337
  */
2638
- declare function toDataStream$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2338
+ declare function toDataStream$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, callbacks?: StreamCallbacks): ReadableStream<any>;
2639
2339
  declare function toDataStreamResponse$1(stream: ReadableStream<LangChainStreamEvent> | ReadableStream<LangChainAIMessageChunk> | ReadableStream<string>, options?: {
2640
2340
  init?: ResponseInit;
2641
2341
  data?: StreamData;
2642
- callbacks?: AIStreamCallbacksAndOptions;
2342
+ callbacks?: StreamCallbacks;
2643
2343
  }): Response;
2644
2344
 
2645
2345
  declare const langchainAdapter_toAIStream: typeof toAIStream;
@@ -2654,11 +2354,11 @@ declare namespace langchainAdapter {
2654
2354
  type EngineResponse = {
2655
2355
  delta: string;
2656
2356
  };
2657
- declare function toDataStream(stream: AsyncIterable<EngineResponse>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
2357
+ declare function toDataStream(stream: AsyncIterable<EngineResponse>, callbacks?: StreamCallbacks): ReadableStream<any>;
2658
2358
  declare function toDataStreamResponse(stream: AsyncIterable<EngineResponse>, options?: {
2659
2359
  init?: ResponseInit;
2660
2360
  data?: StreamData;
2661
- callbacks?: AIStreamCallbacksAndOptions;
2361
+ callbacks?: StreamCallbacks;
2662
2362
  }): Response;
2663
2363
 
2664
2364
  declare const llamaindexAdapter_toDataStream: typeof toDataStream;
@@ -2670,33 +2370,4 @@ declare namespace llamaindexAdapter {
2670
2370
  };
2671
2371
  }
2672
2372
 
2673
- /**
2674
- * A utility function to stream a ReadableStream to a Node.js response-like object.
2675
- *
2676
- * @deprecated Use `pipeDataStreamToResponse` (part of `StreamTextResult`) instead.
2677
- */
2678
- declare function streamToResponse(res: ReadableStream, response: ServerResponse$1, init?: {
2679
- headers?: Record<string, string>;
2680
- status?: number;
2681
- }, data?: StreamData): void;
2682
-
2683
- /**
2684
- * A utility class for streaming text responses.
2685
- *
2686
- * @deprecated Use `streamText.toDataStreamResponse()` (if you did send StreamData)
2687
- * or a regular `Response` instead (if you did not send any StreamData):
2688
- *
2689
- * ```ts
2690
- * return new Response(stream, {
2691
- * status: 200,
2692
- * contentType: 'text/plain; charset=utf-8',
2693
- * })
2694
- * ```
2695
- */
2696
- declare class StreamingTextResponse extends Response {
2697
- constructor(res: ReadableStream, init?: ResponseInit, data?: StreamData);
2698
- }
2699
-
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 };
2373
+ 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, 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, tool };