ai 0.0.0-85f9a635-20240518005312

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 (56) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +37 -0
  3. package/dist/index.d.mts +2287 -0
  4. package/dist/index.d.ts +2287 -0
  5. package/dist/index.js +3531 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +3454 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +178 -0
  10. package/prompts/dist/index.d.mts +324 -0
  11. package/prompts/dist/index.d.ts +324 -0
  12. package/prompts/dist/index.js +178 -0
  13. package/prompts/dist/index.js.map +1 -0
  14. package/prompts/dist/index.mjs +146 -0
  15. package/prompts/dist/index.mjs.map +1 -0
  16. package/react/dist/index.d.mts +565 -0
  17. package/react/dist/index.d.ts +582 -0
  18. package/react/dist/index.js +1430 -0
  19. package/react/dist/index.js.map +1 -0
  20. package/react/dist/index.mjs +1391 -0
  21. package/react/dist/index.mjs.map +1 -0
  22. package/react/dist/index.server.d.mts +17 -0
  23. package/react/dist/index.server.d.ts +17 -0
  24. package/react/dist/index.server.js +50 -0
  25. package/react/dist/index.server.js.map +1 -0
  26. package/react/dist/index.server.mjs +23 -0
  27. package/react/dist/index.server.mjs.map +1 -0
  28. package/rsc/dist/index.d.ts +580 -0
  29. package/rsc/dist/index.mjs +18 -0
  30. package/rsc/dist/rsc-client.d.mts +1 -0
  31. package/rsc/dist/rsc-client.mjs +18 -0
  32. package/rsc/dist/rsc-client.mjs.map +1 -0
  33. package/rsc/dist/rsc-server.d.mts +516 -0
  34. package/rsc/dist/rsc-server.mjs +1900 -0
  35. package/rsc/dist/rsc-server.mjs.map +1 -0
  36. package/rsc/dist/rsc-shared.d.mts +94 -0
  37. package/rsc/dist/rsc-shared.mjs +346 -0
  38. package/rsc/dist/rsc-shared.mjs.map +1 -0
  39. package/solid/dist/index.d.mts +408 -0
  40. package/solid/dist/index.d.ts +408 -0
  41. package/solid/dist/index.js +1072 -0
  42. package/solid/dist/index.js.map +1 -0
  43. package/solid/dist/index.mjs +1044 -0
  44. package/solid/dist/index.mjs.map +1 -0
  45. package/svelte/dist/index.d.mts +484 -0
  46. package/svelte/dist/index.d.ts +484 -0
  47. package/svelte/dist/index.js +1778 -0
  48. package/svelte/dist/index.js.map +1 -0
  49. package/svelte/dist/index.mjs +1749 -0
  50. package/svelte/dist/index.mjs.map +1 -0
  51. package/vue/dist/index.d.mts +402 -0
  52. package/vue/dist/index.d.ts +402 -0
  53. package/vue/dist/index.js +1072 -0
  54. package/vue/dist/index.js.map +1 -0
  55. package/vue/dist/index.mjs +1034 -0
  56. package/vue/dist/index.mjs.map +1 -0
package/package.json ADDED
@@ -0,0 +1,178 @@
1
+ {
2
+ "name": "ai",
3
+ "version": "0.0.0-85f9a635-20240518005312",
4
+ "license": "Apache-2.0",
5
+ "sideEffects": false,
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist/**/*",
11
+ "react/dist/**/*",
12
+ "svelte/dist/**/*",
13
+ "vue/dist/**/*",
14
+ "solid/dist/**/*",
15
+ "prompts/dist/**/*",
16
+ "rsc/dist/**/*",
17
+ "google/dist/**/*",
18
+ "mistral/dist/**/*"
19
+ ],
20
+ "exports": {
21
+ "./package.json": "./package.json",
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.mjs",
25
+ "require": "./dist/index.js"
26
+ },
27
+ "./rsc": {
28
+ "types": "./rsc/dist/index.d.ts",
29
+ "react-server": "./rsc/dist/rsc-server.mjs",
30
+ "import": "./rsc/dist/rsc-client.mjs"
31
+ },
32
+ "./prompts": {
33
+ "types": "./prompts/dist/index.d.ts",
34
+ "import": "./prompts/dist/index.mjs",
35
+ "require": "./prompts/dist/index.js"
36
+ },
37
+ "./react": {
38
+ "types": "./react/dist/index.d.ts",
39
+ "react-server": "./react/dist/index.server.mjs",
40
+ "import": "./react/dist/index.mjs",
41
+ "require": "./react/dist/index.js"
42
+ },
43
+ "./svelte": {
44
+ "types": "./svelte/dist/index.d.ts",
45
+ "import": "./svelte/dist/index.mjs",
46
+ "require": "./svelte/dist/index.js"
47
+ },
48
+ "./vue": {
49
+ "types": "./vue/dist/index.d.ts",
50
+ "import": "./vue/dist/index.mjs",
51
+ "require": "./vue/dist/index.js"
52
+ },
53
+ "./solid": {
54
+ "types": "./solid/dist/index.d.ts",
55
+ "import": "./solid/dist/index.mjs",
56
+ "require": "./solid/dist/index.js"
57
+ }
58
+ },
59
+ "dependencies": {
60
+ "@ai-sdk/provider": "0.0.0-85f9a635-20240518005312",
61
+ "@ai-sdk/provider-utils": "0.0.0-85f9a635-20240518005312",
62
+ "secure-json-parse": "2.7.0",
63
+ "eventsource-parser": "1.1.2",
64
+ "jsondiffpatch": "0.6.0",
65
+ "json-schema": "0.4.0",
66
+ "nanoid": "3.3.6",
67
+ "solid-swr-store": "0.10.7",
68
+ "sswr": "2.0.0",
69
+ "swr": "2.2.0",
70
+ "swr-store": "0.10.6",
71
+ "swrv": "1.0.4",
72
+ "zod-to-json-schema": "3.22.5"
73
+ },
74
+ "devDependencies": {
75
+ "@anthropic-ai/sdk": "0.18.0",
76
+ "@aws-sdk/client-bedrock-runtime": "3.451.0",
77
+ "@edge-runtime/vm": "^3.2.0",
78
+ "@google/generative-ai": "0.1.1",
79
+ "@huggingface/inference": "2.6.4",
80
+ "@mistralai/mistralai": "0.1.3",
81
+ "@solidjs/testing-library": "0.8.4",
82
+ "@testing-library/jest-dom": "^6.4.5",
83
+ "@testing-library/react": "^14.0.0",
84
+ "@testing-library/user-event": "^14.5.1",
85
+ "@testing-library/vue": "^8.0.1",
86
+ "@types/json-schema": "7.0.15",
87
+ "@types/node": "^17.0.12",
88
+ "@types/react": "^18.2.8",
89
+ "@types/react-dom": "^18.2.0",
90
+ "@vitejs/plugin-react": "4.2.0",
91
+ "@vitejs/plugin-vue": "4.5.0",
92
+ "cohere-ai": "^7.6.2",
93
+ "eslint": "^7.32.0",
94
+ "jsdom": "^24.0.0",
95
+ "langchain": "0.0.196",
96
+ "msw": "2.0.9",
97
+ "openai": "4.47.1",
98
+ "react-dom": "^18.2.0",
99
+ "react-server-dom-webpack": "18.3.0-canary-eb33bd747-20240312",
100
+ "solid-js": "^1.8.7",
101
+ "tsup": "^7.2.0",
102
+ "typescript": "5.1.3",
103
+ "vite-plugin-solid": "2.7.2",
104
+ "zod": "3.22.4",
105
+ "@vercel/ai-tsconfig": "0.0.0",
106
+ "eslint-config-vercel-ai": "0.0.0"
107
+ },
108
+ "peerDependencies": {
109
+ "openai": "^4.42.0",
110
+ "react": "^18.2.0",
111
+ "solid-js": "^1.7.7",
112
+ "svelte": "^3.0.0 || ^4.0.0",
113
+ "vue": "^3.3.4",
114
+ "zod": "^3.0.0"
115
+ },
116
+ "peerDependenciesMeta": {
117
+ "react": {
118
+ "optional": true
119
+ },
120
+ "svelte": {
121
+ "optional": true
122
+ },
123
+ "vue": {
124
+ "optional": true
125
+ },
126
+ "solid-js": {
127
+ "optional": true
128
+ },
129
+ "zod": {
130
+ "optional": true
131
+ },
132
+ "openai": {
133
+ "optional": true
134
+ }
135
+ },
136
+ "engines": {
137
+ "node": ">=18"
138
+ },
139
+ "publishConfig": {
140
+ "access": "public"
141
+ },
142
+ "homepage": "https://sdk.vercel.ai/docs",
143
+ "repository": {
144
+ "type": "git",
145
+ "url": "git+https://github.com/vercel/ai.git"
146
+ },
147
+ "bugs": {
148
+ "url": "https://github.com/vercel/ai/issues"
149
+ },
150
+ "keywords": [
151
+ "ai",
152
+ "nextjs",
153
+ "svelte",
154
+ "react",
155
+ "vue"
156
+ ],
157
+ "scripts": {
158
+ "build": "tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts",
159
+ "clean": "rm -rf dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist && rm -rf solid/dist && rm -rf rsc/dist",
160
+ "dev": "tsup --watch",
161
+ "lint": "eslint \"./**/*.ts*\"",
162
+ "type-check": "tsc --noEmit",
163
+ "prettier-check": "prettier --check \"./**/*.ts*\"",
164
+ "test": "pnpm test:node && pnpm test:edge && pnpm test:ui",
165
+ "test:edge": "vitest --config vitest.edge.config.js --run",
166
+ "test:node": "vitest --config vitest.node.config.js --run",
167
+ "test:node:core": "pnpm vitest --config vitest.node.config.js --run ./core/",
168
+ "test:ui": "pnpm test:ui:react && pnpm test:ui:vue && pnpm test:ui:solid",
169
+ "test:ui:react": "vitest --config vitest.ui.react.config.js --run",
170
+ "test:ui:solid": "vitest --config vitest.ui.solid.config.js --run",
171
+ "test:ui:vue": "vitest --config vitest.ui.vue.config.js --run",
172
+ "test:edge:watch": "vitest --config vitest.edge.config.js",
173
+ "test:node:watch": "vitest --config vitest.node.config.js",
174
+ "test:ui:react:watch": "vitest --config vitest.ui.react.config.js",
175
+ "test:ui:solid:watch": "vitest --config vitest.ui.solid.config.js",
176
+ "test:ui:vue:watch": "vitest --config vitest.ui.vue.config.js"
177
+ }
178
+ }
@@ -0,0 +1,324 @@
1
+ /**
2
+ Typed tool call that is returned by generateText and streamText.
3
+ It contains the tool call ID, the tool name, and the tool arguments.
4
+ */
5
+ interface ToolCall$1<NAME extends string, ARGS> {
6
+ /**
7
+ ID of the tool call. This ID is used to match the tool call with the tool result.
8
+ */
9
+ toolCallId: string;
10
+ /**
11
+ Name of the tool that is being called.
12
+ */
13
+ toolName: NAME;
14
+ /**
15
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
16
+ */
17
+ args: ARGS;
18
+ }
19
+
20
+ /**
21
+ Typed tool result that is returned by generateText and streamText.
22
+ It contains the tool call ID, the tool name, the tool arguments, and the tool result.
23
+ */
24
+ interface ToolResult<NAME extends string, ARGS, RESULT> {
25
+ /**
26
+ ID of the tool call. This ID is used to match the tool call with the tool result.
27
+ */
28
+ toolCallId: string;
29
+ /**
30
+ Name of the tool that was called.
31
+ */
32
+ toolName: NAME;
33
+ /**
34
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
35
+ */
36
+ args: ARGS;
37
+ /**
38
+ Result of the tool call. This is the result of the tool's execution.
39
+ */
40
+ result: RESULT;
41
+ }
42
+
43
+ interface FunctionCall {
44
+ /**
45
+ * The arguments to call the function with, as generated by the model in JSON
46
+ * format. Note that the model does not always generate valid JSON, and may
47
+ * hallucinate parameters not defined by your function schema. Validate the
48
+ * arguments in your code before calling your function.
49
+ */
50
+ arguments?: string;
51
+ /**
52
+ * The name of the function to call.
53
+ */
54
+ name?: string;
55
+ }
56
+ /**
57
+ * The tool calls generated by the model, such as function calls.
58
+ */
59
+ interface ToolCall {
60
+ id: string;
61
+ type: string;
62
+ function: {
63
+ name: string;
64
+ arguments: string;
65
+ };
66
+ }
67
+ /**
68
+ Tool invocations are either tool calls or tool results. For each assistant tool call,
69
+ there is one tool invocation. While the call is in progress, the invocation is a tool call.
70
+ Once the call is complete, the invocation is a tool result.
71
+ */
72
+ type ToolInvocation = ToolCall$1<string, any> | ToolResult<string, any, any>;
73
+ /**
74
+ * Shared types between the API and UI packages.
75
+ */
76
+ interface Message {
77
+ id: string;
78
+ tool_call_id?: string;
79
+ createdAt?: Date;
80
+ content: string;
81
+ /**
82
+ @deprecated Use AI SDK RSC instead: https://sdk.vercel.ai/docs/ai-sdk-rsc
83
+ */
84
+ ui?: string | JSX.Element | JSX.Element[] | null | undefined;
85
+ role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
86
+ /**
87
+ *
88
+ * If the message has a role of `function`, the `name` field is the name of the function.
89
+ * Otherwise, the name field should not be set.
90
+ */
91
+ name?: string;
92
+ /**
93
+ * If the assistant role makes a function call, the `function_call` field
94
+ * contains the function call name and arguments. Otherwise, the field should
95
+ * not be set. (Deprecated and replaced by tool_calls.)
96
+ */
97
+ function_call?: string | FunctionCall;
98
+ data?: JSONValue;
99
+ /**
100
+ * If the assistant role makes a tool call, the `tool_calls` field contains
101
+ * the tool call name and arguments. Otherwise, the field should not be set.
102
+ */
103
+ tool_calls?: string | ToolCall[];
104
+ /**
105
+ * Additional message-specific information added on the server via StreamData
106
+ */
107
+ annotations?: JSONValue[] | undefined;
108
+ /**
109
+ Tool invocations (that can be tool calls or tool results, depending on whether or not the invocation has finished)
110
+ that the assistant made as part of this message.
111
+ */
112
+ toolInvocations?: Array<ToolInvocation>;
113
+ }
114
+ type JSONValue = null | string | number | boolean | {
115
+ [x: string]: JSONValue;
116
+ } | Array<JSONValue>;
117
+
118
+ /**
119
+ * A prompt constructor for Anthropic models.
120
+ * Does not support `function` messages.
121
+ * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api
122
+ */
123
+ declare function experimental_buildAnthropicPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
124
+ /**
125
+ * A prompt constructor for Anthropic V3 models which require Messages API.
126
+ * Does not support message with image content
127
+ * @see https://docs.anthropic.com/claude/reference/messages_post
128
+ */
129
+ declare function experimental_buildAnthropicMessages(messages: Pick<Message, 'content' | 'role'>[]): {
130
+ role: "function" | "system" | "user" | "assistant" | "data" | "tool";
131
+ content: {
132
+ type: string;
133
+ text: string;
134
+ }[];
135
+ }[];
136
+
137
+ /**
138
+ * A prompt constructor for the HuggingFace StarChat Beta model.
139
+ * Does not support `function` messages.
140
+ * @see https://huggingface.co/HuggingFaceH4/starchat-beta
141
+ */
142
+ declare function experimental_buildStarChatBetaPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
143
+ /**
144
+ * A prompt constructor for HuggingFace OpenAssistant models.
145
+ * Does not support `function` or `system` messages.
146
+ * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5
147
+ */
148
+ declare function experimental_buildOpenAssistantPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
149
+ /**
150
+ * A prompt constructor for HuggingFace LLama 2 chat models.
151
+ * Does not support `function` messages.
152
+ * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2
153
+ */
154
+ declare function experimental_buildLlama2Prompt(messages: Pick<Message, 'content' | 'role'>[]): string;
155
+
156
+ declare function experimental_buildOpenAIMessages(messages: Message[]): ChatCompletionMessageParam[];
157
+ type ChatCompletionMessageParam = ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam;
158
+ interface ChatCompletionSystemMessageParam {
159
+ /**
160
+ * The contents of the system message.
161
+ */
162
+ content: string;
163
+ /**
164
+ * The role of the messages author, in this case `system`.
165
+ */
166
+ role: 'system';
167
+ /**
168
+ * An optional name for the participant. Provides the model information to
169
+ * differentiate between participants of the same role.
170
+ */
171
+ name?: string;
172
+ }
173
+ interface ChatCompletionUserMessageParam {
174
+ /**
175
+ * The contents of the user message.
176
+ */
177
+ content: string | Array<ChatCompletionContentPart>;
178
+ /**
179
+ * The role of the messages author, in this case `user`.
180
+ */
181
+ role: 'user';
182
+ /**
183
+ * An optional name for the participant. Provides the model information to
184
+ * differentiate between participants of the same role.
185
+ */
186
+ name?: string;
187
+ }
188
+ type ChatCompletionContentPart = ChatCompletionContentPartText | ChatCompletionContentPartImage;
189
+ interface ChatCompletionContentPartText {
190
+ /**
191
+ * The text content.
192
+ */
193
+ text: string;
194
+ /**
195
+ * The type of the content part.
196
+ */
197
+ type: 'text';
198
+ }
199
+ interface ChatCompletionContentPartImage {
200
+ image_url: ChatCompletionContentPartImage.ImageURL;
201
+ /**
202
+ * The type of the content part.
203
+ */
204
+ type: 'image_url';
205
+ }
206
+ declare namespace ChatCompletionContentPartImage {
207
+ interface ImageURL {
208
+ /**
209
+ * Either a URL of the image or the base64 encoded image data.
210
+ */
211
+ url: string;
212
+ /**
213
+ * Specifies the detail level of the image. Learn more in the
214
+ * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).
215
+ */
216
+ detail?: 'auto' | 'low' | 'high';
217
+ }
218
+ }
219
+ interface ChatCompletionAssistantMessageParam {
220
+ /**
221
+ * The role of the messages author, in this case `assistant`.
222
+ */
223
+ role: 'assistant';
224
+ /**
225
+ * The contents of the assistant message. Required unless `tool_calls` or
226
+ * `function_call` is specified.
227
+ */
228
+ content?: string | null;
229
+ /**
230
+ * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of
231
+ * a function that should be called, as generated by the model.
232
+ */
233
+ function_call?: ChatCompletionAssistantMessageParam.FunctionCall;
234
+ /**
235
+ * An optional name for the participant. Provides the model information to
236
+ * differentiate between participants of the same role.
237
+ */
238
+ name?: string;
239
+ /**
240
+ * The tool calls generated by the model, such as function calls.
241
+ */
242
+ tool_calls?: Array<ChatCompletionMessageToolCall>;
243
+ }
244
+ declare namespace ChatCompletionAssistantMessageParam {
245
+ /**
246
+ * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of
247
+ * a function that should be called, as generated by the model.
248
+ */
249
+ interface FunctionCall {
250
+ /**
251
+ * The arguments to call the function with, as generated by the model in JSON
252
+ * format. Note that the model does not always generate valid JSON, and may
253
+ * hallucinate parameters not defined by your function schema. Validate the
254
+ * arguments in your code before calling your function.
255
+ */
256
+ arguments: string;
257
+ /**
258
+ * The name of the function to call.
259
+ */
260
+ name: string;
261
+ }
262
+ }
263
+ interface ChatCompletionMessageToolCall {
264
+ /**
265
+ * The ID of the tool call.
266
+ */
267
+ id: string;
268
+ /**
269
+ * The function that the model called.
270
+ */
271
+ function: ChatCompletionMessageToolCall.Function;
272
+ /**
273
+ * The type of the tool. Currently, only `function` is supported.
274
+ */
275
+ type: 'function';
276
+ }
277
+ declare namespace ChatCompletionMessageToolCall {
278
+ /**
279
+ * The function that the model called.
280
+ */
281
+ interface Function {
282
+ /**
283
+ * The arguments to call the function with, as generated by the model in JSON
284
+ * format. Note that the model does not always generate valid JSON, and may
285
+ * hallucinate parameters not defined by your function schema. Validate the
286
+ * arguments in your code before calling your function.
287
+ */
288
+ arguments: string;
289
+ /**
290
+ * The name of the function to call.
291
+ */
292
+ name: string;
293
+ }
294
+ }
295
+ interface ChatCompletionToolMessageParam {
296
+ /**
297
+ * The contents of the tool message.
298
+ */
299
+ content: string;
300
+ /**
301
+ * The role of the messages author, in this case `tool`.
302
+ */
303
+ role: 'tool';
304
+ /**
305
+ * Tool call that this message is responding to.
306
+ */
307
+ tool_call_id: string;
308
+ }
309
+ interface ChatCompletionFunctionMessageParam {
310
+ /**
311
+ * The return value from the function call, to return to the model.
312
+ */
313
+ content: string | null;
314
+ /**
315
+ * The name of the function to call.
316
+ */
317
+ name: string;
318
+ /**
319
+ * The role of the messages author, in this case `function`.
320
+ */
321
+ role: 'function';
322
+ }
323
+
324
+ export { ChatCompletionAssistantMessageParam, ChatCompletionContentPart, ChatCompletionContentPartImage, ChatCompletionContentPartText, ChatCompletionFunctionMessageParam, ChatCompletionMessageParam, ChatCompletionMessageToolCall, ChatCompletionSystemMessageParam, ChatCompletionToolMessageParam, ChatCompletionUserMessageParam, experimental_buildAnthropicMessages, experimental_buildAnthropicPrompt, experimental_buildLlama2Prompt, experimental_buildOpenAIMessages, experimental_buildOpenAssistantPrompt, experimental_buildStarChatBetaPrompt };