ai 3.0.18 → 3.0.20

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.
Files changed (61) hide show
  1. package/anthropic/dist/index.d.mts +66 -34
  2. package/anthropic/dist/index.d.ts +66 -34
  3. package/anthropic/dist/index.js +98 -94
  4. package/anthropic/dist/index.js.map +1 -1
  5. package/anthropic/dist/index.mjs +98 -94
  6. package/anthropic/dist/index.mjs.map +1 -1
  7. package/dist/index.d.mts +119 -45
  8. package/dist/index.d.ts +119 -45
  9. package/dist/index.js +83 -154
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +81 -153
  12. package/dist/index.mjs.map +1 -1
  13. package/google/dist/index.d.mts +65 -31
  14. package/google/dist/index.d.ts +65 -31
  15. package/google/dist/index.js +47 -43
  16. package/google/dist/index.js.map +1 -1
  17. package/google/dist/index.mjs +47 -43
  18. package/google/dist/index.mjs.map +1 -1
  19. package/mistral/dist/index.d.mts +65 -31
  20. package/mistral/dist/index.d.ts +65 -31
  21. package/mistral/dist/index.js +6 -21
  22. package/mistral/dist/index.js.map +1 -1
  23. package/mistral/dist/index.mjs +6 -21
  24. package/mistral/dist/index.mjs.map +1 -1
  25. package/openai/dist/index.d.mts +65 -31
  26. package/openai/dist/index.d.ts +65 -31
  27. package/openai/dist/index.js +9 -29
  28. package/openai/dist/index.js.map +1 -1
  29. package/openai/dist/index.mjs +9 -29
  30. package/openai/dist/index.mjs.map +1 -1
  31. package/package.json +5 -3
  32. package/react/dist/index.d.mts +8 -4
  33. package/react/dist/index.d.ts +12 -6
  34. package/react/dist/index.js +23 -105
  35. package/react/dist/index.js.map +1 -1
  36. package/react/dist/index.mjs +22 -105
  37. package/react/dist/index.mjs.map +1 -1
  38. package/react/dist/index.server.d.mts +4 -2
  39. package/react/dist/index.server.d.ts +4 -2
  40. package/react/dist/index.server.js.map +1 -1
  41. package/react/dist/index.server.mjs.map +1 -1
  42. package/rsc/dist/rsc-server.mjs +6 -16
  43. package/rsc/dist/rsc-server.mjs.map +1 -1
  44. package/solid/dist/index.js +19 -104
  45. package/solid/dist/index.js.map +1 -1
  46. package/solid/dist/index.mjs +19 -104
  47. package/solid/dist/index.mjs.map +1 -1
  48. package/spec/dist/index.d.mts +112 -40
  49. package/spec/dist/index.d.ts +112 -40
  50. package/spec/dist/index.js +71 -13
  51. package/spec/dist/index.js.map +1 -1
  52. package/spec/dist/index.mjs +69 -13
  53. package/spec/dist/index.mjs.map +1 -1
  54. package/svelte/dist/index.js +19 -104
  55. package/svelte/dist/index.js.map +1 -1
  56. package/svelte/dist/index.mjs +19 -104
  57. package/svelte/dist/index.mjs.map +1 -1
  58. package/vue/dist/index.js +19 -104
  59. package/vue/dist/index.js.map +1 -1
  60. package/vue/dist/index.mjs +19 -104
  61. package/vue/dist/index.mjs.map +1 -1
package/dist/index.d.ts CHANGED
@@ -1,10 +1,29 @@
1
1
  import { z } from 'zod';
2
+ import { JSONSchema7 } from 'json-schema';
2
3
  import { AssistantStream } from 'openai/lib/AssistantStream';
3
4
  import { Run } from 'openai/resources/beta/threads/runs/runs';
4
5
  import { ChatCompletionResponseChunk } from '@mistralai/mistralai';
5
6
  import { ServerResponse } from 'node:http';
6
7
 
7
- type JsonSchema = Record<string, unknown>;
8
+ /**
9
+ A tool has a name, a description, and a set of parameters.
10
+
11
+ Note: this is **not** the user-facing tool definition. The AI SDK methods will
12
+ map the user-facing tool definitions to this format.
13
+ */
14
+ type LanguageModelV1FunctionTool = {
15
+ /**
16
+ The type of the tool. Only functions for now, but this gives us room to
17
+ add more specific tool types in the future and use a discriminated union.
18
+ */
19
+ type: 'function';
20
+ /**
21
+ The name of the tool. Unique within this model call.
22
+ */
23
+ name: string;
24
+ description?: string;
25
+ parameters: JSONSchema7;
26
+ };
8
27
 
9
28
  type LanguageModelV1CallSettings = {
10
29
  /**
@@ -61,33 +80,13 @@ type LanguageModelV1CallSettings = {
61
80
  };
62
81
 
63
82
  /**
64
- * A tool has a name, a description, and a set of parameters.
65
- *
66
- * Note: this is **not** the user-facing tool definition. The AI SDK methods will
67
- * map the user-facing tool definitions to this format.
68
- */
69
- type LanguageModelV1FunctionTool = {
70
- /**
71
- * The type of the tool. Only functions for now, but this gives us room to
72
- * add more specific tool types in the future and use a discriminated union.
73
- */
74
- type: 'function';
75
- /**
76
- * The name of the tool. Unique within this model call.
77
- */
78
- name: string;
79
- description?: string;
80
- parameters: JsonSchema;
81
- };
83
+ A prompt is a list of messages.
82
84
 
83
- /**
84
- * A prompt is a list of messages.
85
- *
86
- * Note: Not all models and prompt formats support multi-modal inputs and
87
- * tool calls. The validation happens at runtime.
88
- *
89
- * Note: This is not a user-facing prompt. The AI SDK methods will map the
90
- * user-facing prompt types such as chat or instruction prompts to this format.
85
+ Note: Not all models and prompt formats support multi-modal inputs and
86
+ tool calls. The validation happens at runtime.
87
+
88
+ Note: This is not a user-facing prompt. The AI SDK methods will map the
89
+ user-facing prompt types such as chat or instruction prompts to this format.
91
90
  */
92
91
  type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
93
92
  type LanguageModelV1Message = {
@@ -103,35 +102,69 @@ type LanguageModelV1Message = {
103
102
  role: 'tool';
104
103
  content: Array<LanguageModelV1ToolResultPart>;
105
104
  };
105
+ /**
106
+ Text content part of a prompt. It contains a string of text.
107
+ */
106
108
  interface LanguageModelV1TextPart {
107
109
  type: 'text';
108
110
  /**
109
- * The text content.
111
+ The text content.
110
112
  */
111
113
  text: string;
112
114
  }
115
+ /**
116
+ Image content part of a prompt. It contains an image.
117
+ */
113
118
  interface LanguageModelV1ImagePart {
114
119
  type: 'image';
115
120
  /**
116
- * Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
121
+ Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
117
122
  */
118
123
  image: Uint8Array | URL;
119
124
  /**
120
- * Optional mime type of the image.
125
+ Optional mime type of the image.
121
126
  */
122
127
  mimeType?: string;
123
128
  }
129
+ /**
130
+ Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
131
+ */
124
132
  interface LanguageModelV1ToolCallPart {
125
133
  type: 'tool-call';
134
+ /**
135
+ ID of the tool call. This ID is used to match the tool call with the tool result.
136
+ */
126
137
  toolCallId: string;
138
+ /**
139
+ Name of the tool that is being called.
140
+ */
127
141
  toolName: string;
142
+ /**
143
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
144
+ */
128
145
  args: unknown;
129
146
  }
147
+ /**
148
+ Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
149
+ */
130
150
  interface LanguageModelV1ToolResultPart {
131
151
  type: 'tool-result';
152
+ /**
153
+ ID of the tool call that this result is associated with.
154
+ */
132
155
  toolCallId: string;
156
+ /**
157
+ Name of the tool that generated this result.
158
+ */
133
159
  toolName: string;
160
+ /**
161
+ Result of the tool call. This is a JSON-serializable object.
162
+ */
134
163
  result: unknown;
164
+ /**
165
+ Optional flag if the result is an error or an error message.
166
+ */
167
+ isError?: boolean;
135
168
  }
136
169
 
137
170
  type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
@@ -157,7 +190,7 @@ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
157
190
  type: 'object-json';
158
191
  } | {
159
192
  type: 'object-grammar';
160
- schema: JsonSchema;
193
+ schema: JSONSchema7;
161
194
  } | {
162
195
  type: 'object-tool';
163
196
  tool: LanguageModelV1FunctionTool;
@@ -471,6 +504,10 @@ interface ToolResultPart {
471
504
  Result of the tool call. This is a JSON-serializable object.
472
505
  */
473
506
  result: unknown;
507
+ /**
508
+ Optional flag if the result is an error or an error message.
509
+ */
510
+ isError?: boolean;
474
511
  }
475
512
 
476
513
  /**
@@ -784,6 +821,7 @@ type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType>
784
821
 
785
822
  type ToToolCall<TOOLS extends Record<string, ExperimentalTool>> = ValueOf<{
786
823
  [NAME in keyof TOOLS]: {
824
+ type: 'tool-call';
787
825
  toolCallId: string;
788
826
  toolName: NAME & string;
789
827
  args: z.infer<TOOLS[NAME]['parameters']>;
@@ -801,6 +839,7 @@ type ToToolsWithDefinedExecute<TOOLS extends Record<string, ExperimentalTool>> =
801
839
  };
802
840
  type ToToolResultObject<TOOLS extends Record<string, ExperimentalTool>> = ValueOf<{
803
841
  [NAME in keyof TOOLS]: {
842
+ type: 'tool-result';
804
843
  toolCallId: string;
805
844
  toolName: NAME & string;
806
845
  args: z.infer<TOOLS[NAME]['parameters']>;
@@ -1349,10 +1388,6 @@ declare function createChunkDecoder(complex?: boolean): (chunk: Uint8Array | und
1349
1388
 
1350
1389
  declare const isStreamStringEqualToType: (type: keyof typeof StreamStringPrefixes, value: string) => value is `0:${string}\n` | `1:${string}\n` | `2:${string}\n` | `3:${string}\n` | `4:${string}\n` | `5:${string}\n` | `6:${string}\n` | `7:${string}\n` | `8:${string}\n`;
1351
1390
  type StreamString = `${(typeof StreamStringPrefixes)[keyof typeof StreamStringPrefixes]}:${string}\n`;
1352
- /**
1353
- * A header sent to the client so it knows how to handle parsing the stream (as a deprecated text response or using the new prefixed protocol)
1354
- */
1355
- declare const COMPLEX_HEADER = "X-Experimental-Stream-Data";
1356
1391
 
1357
1392
  declare interface AzureChatCompletions {
1358
1393
  id: string;
@@ -1606,10 +1641,8 @@ interface AIStreamCallbacksAndOptions {
1606
1641
  /** `onText`: Called for each text chunk. */
1607
1642
  onText?: (text: string) => Promise<void> | void;
1608
1643
  /**
1609
- * A flag for enabling the experimental_StreamData class and the new protocol.
1610
- * @see https://github.com/vercel-labs/ai/pull/425
1611
- *
1612
- * When StreamData is rolled out, this will be removed and the new protocol will be used by default.
1644
+ * @deprecated This flag is no longer used and only retained for backwards compatibility.
1645
+ * You can remove it from your code.
1613
1646
  */
1614
1647
  experimental_streamData?: boolean;
1615
1648
  }
@@ -1796,18 +1829,54 @@ interface MessageStopEvent {
1796
1829
  */
1797
1830
  declare function AnthropicStream(res: Response | AsyncIterable<CompletionChunk> | AsyncIterable<MessageStreamEvent>, cb?: AIStreamCallbacksAndOptions): ReadableStream;
1798
1831
 
1832
+ /**
1833
+ You can pass the thread and the latest message into the `AssistantResponse`. This establishes the context for the response.
1834
+ */
1799
1835
  type AssistantResponseSettings = {
1836
+ /**
1837
+ The thread ID that the response is associated with.
1838
+ */
1800
1839
  threadId: string;
1840
+ /**
1841
+ The ID of the latest message that the response is associated with.
1842
+ */
1801
1843
  messageId: string;
1802
1844
  };
1845
+ /**
1846
+ The process parameter is a callback in which you can run the assistant on threads, and send messages and data messages to the client.
1847
+ */
1803
1848
  type AssistantResponseCallback = (options: {
1849
+ /**
1850
+ @deprecated use variable from outer scope instead.
1851
+ */
1804
1852
  threadId: string;
1853
+ /**
1854
+ @deprecated use variable from outer scope instead.
1855
+ */
1805
1856
  messageId: string;
1857
+ /**
1858
+ Forwards an assistant message (non-streaming) to the client.
1859
+ */
1806
1860
  sendMessage: (message: AssistantMessage) => void;
1861
+ /**
1862
+ Send a data message to the client. You can use this to provide information for rendering custom UIs while the assistant is processing the thread.
1863
+ */
1807
1864
  sendDataMessage: (message: DataMessage) => void;
1865
+ /**
1866
+ Forwards the assistant response stream to the client. Returns the `Run` object after it completes, or when it requires an action.
1867
+ */
1808
1868
  forwardStream: (stream: AssistantStream) => Promise<Run | undefined>;
1809
1869
  }) => Promise<void>;
1810
- declare function experimental_AssistantResponse({ threadId, messageId }: AssistantResponseSettings, process: AssistantResponseCallback): Response;
1870
+ /**
1871
+ The `AssistantResponse` allows you to send a stream of assistant update to `useAssistant`.
1872
+ It is designed to facilitate streaming assistant responses to the `useAssistant` hook.
1873
+ It receives an assistant thread and a current message, and can send messages and data messages to the client.
1874
+ */
1875
+ declare function AssistantResponse({ threadId, messageId }: AssistantResponseSettings, process: AssistantResponseCallback): Response;
1876
+ /**
1877
+ @deprecated Use `AssistantResponse` instead.
1878
+ */
1879
+ declare const experimental_AssistantResponse: typeof AssistantResponse;
1811
1880
 
1812
1881
  interface AWSBedrockResponse {
1813
1882
  body?: AsyncIterable<{
@@ -1932,7 +2001,7 @@ declare function ReplicateStream(res: Prediction, cb?: AIStreamCallbacksAndOptio
1932
2001
  /**
1933
2002
  * A stream wrapper to send custom JSON-encoded data back to the client.
1934
2003
  */
1935
- declare class experimental_StreamData {
2004
+ declare class StreamData {
1936
2005
  private encoder;
1937
2006
  private controller;
1938
2007
  stream: TransformStream<Uint8Array, Uint8Array>;
@@ -1950,7 +2019,12 @@ declare class experimental_StreamData {
1950
2019
  * A TransformStream for LLMs that do not have their own transform stream handlers managing encoding (e.g. OpenAIStream has one for function call handling).
1951
2020
  * This assumes every chunk is a 'text' chunk.
1952
2021
  */
1953
- declare function createStreamDataTransformer(experimental_streamData: boolean | undefined): TransformStream<any, any>;
2022
+ declare function createStreamDataTransformer(): TransformStream<any, any>;
2023
+ /**
2024
+ @deprecated Use `StreamData` instead.
2025
+ */
2026
+ declare class experimental_StreamData extends StreamData {
2027
+ }
1954
2028
 
1955
2029
  /**
1956
2030
  * This is a naive implementation of the streaming React response API.
@@ -1979,7 +2053,7 @@ declare class experimental_StreamingReactResponse {
1979
2053
  content: string;
1980
2054
  data?: JSONValue[];
1981
2055
  }) => UINode | Promise<UINode>;
1982
- data?: experimental_StreamData;
2056
+ data?: StreamData;
1983
2057
  generateId?: IdGenerator;
1984
2058
  });
1985
2059
  }
@@ -1988,7 +2062,7 @@ declare class experimental_StreamingReactResponse {
1988
2062
  * A utility class for streaming text responses.
1989
2063
  */
1990
2064
  declare class StreamingTextResponse extends Response {
1991
- constructor(res: ReadableStream, init?: ResponseInit, data?: experimental_StreamData);
2065
+ constructor(res: ReadableStream, init?: ResponseInit, data?: StreamData);
1992
2066
  }
1993
2067
  /**
1994
2068
  * A utility function to stream a ReadableStream to a Node.js response-like object.
@@ -1998,4 +2072,4 @@ declare function streamToResponse(res: ReadableStream, response: ServerResponse,
1998
2072
  status?: number;
1999
2073
  }): void;
2000
2074
 
2001
- export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantMessage, COMPLEX_HEADER, ChatRequest, ChatRequestOptions, CohereStream, CompletionUsage, CreateMessage, DataContent, DataMessage, DeepPartial, ErrorStreamPart, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, Function, FunctionCall, FunctionCallHandler, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, IdGenerator, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, JSONValue, LangChainStream, Message$1 as Message, MistralStream, OpenAIStream, OpenAIStreamCallbacks, ReactResponseRow, ReplicateStream, RequestOptions, StreamObjectResult, StreamString, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, Tool, ToolCall, ToolCallHandler, ToolCallPart, ToolCallPayload, ToolChoice, ToolContent, ToolResultPart, UseChatOptions, UseCompletionOptions, UserContent, convertDataContentToBase64String, convertDataContentToUint8Array, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_AssistantResponse, experimental_StreamData, experimental_StreamingReactResponse, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, generateId, isStreamStringEqualToType, generateId as nanoid, readableFromAsyncIterable, streamToResponse, tool, trimStartOfStreamHelper };
2075
+ export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantMessage, AssistantResponse, ChatRequest, ChatRequestOptions, CohereStream, CompletionUsage, CreateMessage, DataContent, DataMessage, DeepPartial, ErrorStreamPart, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, Function, FunctionCall, FunctionCallHandler, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, IdGenerator, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, JSONValue, LangChainStream, Message$1 as Message, MistralStream, OpenAIStream, OpenAIStreamCallbacks, ReactResponseRow, ReplicateStream, RequestOptions, StreamData, StreamObjectResult, StreamString, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, Tool, ToolCall, ToolCallHandler, ToolCallPart, ToolCallPayload, ToolChoice, ToolContent, ToolResultPart, UseChatOptions, UseCompletionOptions, UserContent, convertDataContentToBase64String, convertDataContentToUint8Array, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_AssistantResponse, experimental_StreamData, experimental_StreamingReactResponse, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, generateId, isStreamStringEqualToType, generateId as nanoid, readableFromAsyncIterable, streamToResponse, tool, trimStartOfStreamHelper };