ai 0.0.0-e27b4ed4-20240419203611

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 +1770 -0
  4. package/dist/index.d.ts +1770 -0
  5. package/dist/index.js +2958 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +2887 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +174 -0
  10. package/prompts/dist/index.d.mts +267 -0
  11. package/prompts/dist/index.d.ts +267 -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 +487 -0
  17. package/react/dist/index.d.ts +504 -0
  18. package/react/dist/index.js +1310 -0
  19. package/react/dist/index.js.map +1 -0
  20. package/react/dist/index.mjs +1271 -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 +289 -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 +225 -0
  34. package/rsc/dist/rsc-server.mjs +1246 -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 +351 -0
  40. package/solid/dist/index.d.ts +351 -0
  41. package/solid/dist/index.js +1002 -0
  42. package/solid/dist/index.js.map +1 -0
  43. package/solid/dist/index.mjs +974 -0
  44. package/solid/dist/index.mjs.map +1 -0
  45. package/svelte/dist/index.d.mts +348 -0
  46. package/svelte/dist/index.d.ts +348 -0
  47. package/svelte/dist/index.js +1556 -0
  48. package/svelte/dist/index.js.map +1 -0
  49. package/svelte/dist/index.mjs +1528 -0
  50. package/svelte/dist/index.mjs.map +1 -0
  51. package/vue/dist/index.d.mts +345 -0
  52. package/vue/dist/index.d.ts +345 -0
  53. package/vue/dist/index.js +1002 -0
  54. package/vue/dist/index.js.map +1 -0
  55. package/vue/dist/index.mjs +964 -0
  56. package/vue/dist/index.mjs.map +1 -0
package/package.json ADDED
@@ -0,0 +1,174 @@
1
+ {
2
+ "name": "ai",
3
+ "version": "0.0.0-e27b4ed4-20240419203611",
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",
61
+ "@ai-sdk/provider-utils": "0.0.1",
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.1.7",
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.1.4",
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": "^23.0.0",
95
+ "langchain": "0.0.196",
96
+ "msw": "2.0.9",
97
+ "openai": "4.29.0",
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
+ "react": "^18.2.0",
110
+ "solid-js": "^1.7.7",
111
+ "svelte": "^3.0.0 || ^4.0.0",
112
+ "vue": "^3.3.4",
113
+ "zod": "^3.0.0"
114
+ },
115
+ "peerDependenciesMeta": {
116
+ "react": {
117
+ "optional": true
118
+ },
119
+ "svelte": {
120
+ "optional": true
121
+ },
122
+ "vue": {
123
+ "optional": true
124
+ },
125
+ "solid-js": {
126
+ "optional": true
127
+ },
128
+ "zod": {
129
+ "optional": true
130
+ }
131
+ },
132
+ "engines": {
133
+ "node": ">=18"
134
+ },
135
+ "publishConfig": {
136
+ "access": "public"
137
+ },
138
+ "homepage": "https://sdk.vercel.ai/docs",
139
+ "repository": {
140
+ "type": "git",
141
+ "url": "git+https://github.com/vercel/ai.git"
142
+ },
143
+ "bugs": {
144
+ "url": "https://github.com/vercel/ai/issues"
145
+ },
146
+ "keywords": [
147
+ "ai",
148
+ "nextjs",
149
+ "svelte",
150
+ "react",
151
+ "vue"
152
+ ],
153
+ "scripts": {
154
+ "build": "tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts",
155
+ "clean": "rm -rf dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist && rm -rf solid/dist && rm -rf rsc/dist",
156
+ "dev": "tsup --watch",
157
+ "lint": "eslint \"./**/*.ts*\"",
158
+ "type-check": "tsc --noEmit",
159
+ "prettier-check": "prettier --check \"./**/*.ts*\"",
160
+ "test": "pnpm test:node && pnpm test:edge && pnpm test:ui",
161
+ "test:edge": "vitest --config vitest.edge.config.js --run --threads=false",
162
+ "test:node": "vitest --config vitest.node.config.js --run --threads=false",
163
+ "test:node:core": "pnpm vitest --config vitest.node.config.js --run --threads=false ./core/",
164
+ "test:ui": "pnpm test:ui:react && pnpm test:ui:vue && pnpm test:ui:solid",
165
+ "test:ui:react": "vitest --config vitest.ui.react.config.js --run",
166
+ "test:ui:solid": "vitest --config vitest.ui.solid.config.js --run",
167
+ "test:ui:vue": "vitest --config vitest.ui.vue.config.js --run",
168
+ "test:edge:watch": "vitest --config vitest.edge.config.js --threads=false",
169
+ "test:node:watch": "vitest --config vitest.node.config.js --threads=false",
170
+ "test:ui:react:watch": "vitest --config vitest.ui.react.config.js",
171
+ "test:ui:solid:watch": "vitest --config vitest.ui.solid.config.js",
172
+ "test:ui:vue:watch": "vitest --config vitest.ui.vue.config.js"
173
+ }
174
+ }
@@ -0,0 +1,267 @@
1
+ interface FunctionCall {
2
+ /**
3
+ * The arguments to call the function with, as generated by the model in JSON
4
+ * format. Note that the model does not always generate valid JSON, and may
5
+ * hallucinate parameters not defined by your function schema. Validate the
6
+ * arguments in your code before calling your function.
7
+ */
8
+ arguments?: string;
9
+ /**
10
+ * The name of the function to call.
11
+ */
12
+ name?: string;
13
+ }
14
+ /**
15
+ * The tool calls generated by the model, such as function calls.
16
+ */
17
+ interface ToolCall {
18
+ id: string;
19
+ type: string;
20
+ function: {
21
+ name: string;
22
+ arguments: string;
23
+ };
24
+ }
25
+ /**
26
+ * Shared types between the API and UI packages.
27
+ */
28
+ interface Message {
29
+ id: string;
30
+ tool_call_id?: string;
31
+ createdAt?: Date;
32
+ content: string;
33
+ ui?: string | JSX.Element | JSX.Element[] | null | undefined;
34
+ role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
35
+ /**
36
+ * If the message has a role of `function`, the `name` field is the name of the function.
37
+ * Otherwise, the name field should not be set.
38
+ */
39
+ name?: string;
40
+ /**
41
+ * If the assistant role makes a function call, the `function_call` field
42
+ * contains the function call name and arguments. Otherwise, the field should
43
+ * not be set. (Deprecated and replaced by tool_calls.)
44
+ */
45
+ function_call?: string | FunctionCall;
46
+ data?: JSONValue;
47
+ /**
48
+ * If the assistant role makes a tool call, the `tool_calls` field contains
49
+ * the tool call name and arguments. Otherwise, the field should not be set.
50
+ */
51
+ tool_calls?: string | ToolCall[];
52
+ /**
53
+ * Additional message-specific information added on the server via StreamData
54
+ */
55
+ annotations?: JSONValue[] | undefined;
56
+ }
57
+ type JSONValue = null | string | number | boolean | {
58
+ [x: string]: JSONValue;
59
+ } | Array<JSONValue>;
60
+
61
+ /**
62
+ * A prompt constructor for Anthropic models.
63
+ * Does not support `function` messages.
64
+ * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api
65
+ */
66
+ declare function experimental_buildAnthropicPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
67
+ /**
68
+ * A prompt constructor for Anthropic V3 models which require Messages API.
69
+ * Does not support message with image content
70
+ * @see https://docs.anthropic.com/claude/reference/messages_post
71
+ */
72
+ declare function experimental_buildAnthropicMessages(messages: Pick<Message, 'content' | 'role'>[]): {
73
+ role: "function" | "system" | "user" | "assistant" | "data" | "tool";
74
+ content: {
75
+ type: string;
76
+ text: string;
77
+ }[];
78
+ }[];
79
+
80
+ /**
81
+ * A prompt constructor for the HuggingFace StarChat Beta model.
82
+ * Does not support `function` messages.
83
+ * @see https://huggingface.co/HuggingFaceH4/starchat-beta
84
+ */
85
+ declare function experimental_buildStarChatBetaPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
86
+ /**
87
+ * A prompt constructor for HuggingFace OpenAssistant models.
88
+ * Does not support `function` or `system` messages.
89
+ * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5
90
+ */
91
+ declare function experimental_buildOpenAssistantPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
92
+ /**
93
+ * A prompt constructor for HuggingFace LLama 2 chat models.
94
+ * Does not support `function` messages.
95
+ * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2
96
+ */
97
+ declare function experimental_buildLlama2Prompt(messages: Pick<Message, 'content' | 'role'>[]): string;
98
+
99
+ declare function experimental_buildOpenAIMessages(messages: Message[]): ChatCompletionMessageParam[];
100
+ type ChatCompletionMessageParam = ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam;
101
+ interface ChatCompletionSystemMessageParam {
102
+ /**
103
+ * The contents of the system message.
104
+ */
105
+ content: string;
106
+ /**
107
+ * The role of the messages author, in this case `system`.
108
+ */
109
+ role: 'system';
110
+ /**
111
+ * An optional name for the participant. Provides the model information to
112
+ * differentiate between participants of the same role.
113
+ */
114
+ name?: string;
115
+ }
116
+ interface ChatCompletionUserMessageParam {
117
+ /**
118
+ * The contents of the user message.
119
+ */
120
+ content: string | Array<ChatCompletionContentPart>;
121
+ /**
122
+ * The role of the messages author, in this case `user`.
123
+ */
124
+ role: 'user';
125
+ /**
126
+ * An optional name for the participant. Provides the model information to
127
+ * differentiate between participants of the same role.
128
+ */
129
+ name?: string;
130
+ }
131
+ type ChatCompletionContentPart = ChatCompletionContentPartText | ChatCompletionContentPartImage;
132
+ interface ChatCompletionContentPartText {
133
+ /**
134
+ * The text content.
135
+ */
136
+ text: string;
137
+ /**
138
+ * The type of the content part.
139
+ */
140
+ type: 'text';
141
+ }
142
+ interface ChatCompletionContentPartImage {
143
+ image_url: ChatCompletionContentPartImage.ImageURL;
144
+ /**
145
+ * The type of the content part.
146
+ */
147
+ type: 'image_url';
148
+ }
149
+ declare namespace ChatCompletionContentPartImage {
150
+ interface ImageURL {
151
+ /**
152
+ * Either a URL of the image or the base64 encoded image data.
153
+ */
154
+ url: string;
155
+ /**
156
+ * Specifies the detail level of the image. Learn more in the
157
+ * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).
158
+ */
159
+ detail?: 'auto' | 'low' | 'high';
160
+ }
161
+ }
162
+ interface ChatCompletionAssistantMessageParam {
163
+ /**
164
+ * The role of the messages author, in this case `assistant`.
165
+ */
166
+ role: 'assistant';
167
+ /**
168
+ * The contents of the assistant message. Required unless `tool_calls` or
169
+ * `function_call` is specified.
170
+ */
171
+ content?: string | null;
172
+ /**
173
+ * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of
174
+ * a function that should be called, as generated by the model.
175
+ */
176
+ function_call?: ChatCompletionAssistantMessageParam.FunctionCall;
177
+ /**
178
+ * An optional name for the participant. Provides the model information to
179
+ * differentiate between participants of the same role.
180
+ */
181
+ name?: string;
182
+ /**
183
+ * The tool calls generated by the model, such as function calls.
184
+ */
185
+ tool_calls?: Array<ChatCompletionMessageToolCall>;
186
+ }
187
+ declare namespace ChatCompletionAssistantMessageParam {
188
+ /**
189
+ * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of
190
+ * a function that should be called, as generated by the model.
191
+ */
192
+ interface FunctionCall {
193
+ /**
194
+ * The arguments to call the function with, as generated by the model in JSON
195
+ * format. Note that the model does not always generate valid JSON, and may
196
+ * hallucinate parameters not defined by your function schema. Validate the
197
+ * arguments in your code before calling your function.
198
+ */
199
+ arguments: string;
200
+ /**
201
+ * The name of the function to call.
202
+ */
203
+ name: string;
204
+ }
205
+ }
206
+ interface ChatCompletionMessageToolCall {
207
+ /**
208
+ * The ID of the tool call.
209
+ */
210
+ id: string;
211
+ /**
212
+ * The function that the model called.
213
+ */
214
+ function: ChatCompletionMessageToolCall.Function;
215
+ /**
216
+ * The type of the tool. Currently, only `function` is supported.
217
+ */
218
+ type: 'function';
219
+ }
220
+ declare namespace ChatCompletionMessageToolCall {
221
+ /**
222
+ * The function that the model called.
223
+ */
224
+ interface Function {
225
+ /**
226
+ * The arguments to call the function with, as generated by the model in JSON
227
+ * format. Note that the model does not always generate valid JSON, and may
228
+ * hallucinate parameters not defined by your function schema. Validate the
229
+ * arguments in your code before calling your function.
230
+ */
231
+ arguments: string;
232
+ /**
233
+ * The name of the function to call.
234
+ */
235
+ name: string;
236
+ }
237
+ }
238
+ interface ChatCompletionToolMessageParam {
239
+ /**
240
+ * The contents of the tool message.
241
+ */
242
+ content: string;
243
+ /**
244
+ * The role of the messages author, in this case `tool`.
245
+ */
246
+ role: 'tool';
247
+ /**
248
+ * Tool call that this message is responding to.
249
+ */
250
+ tool_call_id: string;
251
+ }
252
+ interface ChatCompletionFunctionMessageParam {
253
+ /**
254
+ * The return value from the function call, to return to the model.
255
+ */
256
+ content: string | null;
257
+ /**
258
+ * The name of the function to call.
259
+ */
260
+ name: string;
261
+ /**
262
+ * The role of the messages author, in this case `function`.
263
+ */
264
+ role: 'function';
265
+ }
266
+
267
+ export { ChatCompletionAssistantMessageParam, ChatCompletionContentPart, ChatCompletionContentPartImage, ChatCompletionContentPartText, ChatCompletionFunctionMessageParam, ChatCompletionMessageParam, ChatCompletionMessageToolCall, ChatCompletionSystemMessageParam, ChatCompletionToolMessageParam, ChatCompletionUserMessageParam, experimental_buildAnthropicMessages, experimental_buildAnthropicPrompt, experimental_buildLlama2Prompt, experimental_buildOpenAIMessages, experimental_buildOpenAssistantPrompt, experimental_buildStarChatBetaPrompt };