ai 3.1.0-canary.4 → 3.1.1

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 (69) hide show
  1. package/dist/index.d.mts +982 -24
  2. package/dist/index.d.ts +982 -24
  3. package/dist/index.js +1748 -175
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +1723 -174
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +11 -28
  8. package/prompts/dist/index.d.mts +13 -1
  9. package/prompts/dist/index.d.ts +13 -1
  10. package/prompts/dist/index.js +13 -0
  11. package/prompts/dist/index.js.map +1 -1
  12. package/prompts/dist/index.mjs +12 -0
  13. package/prompts/dist/index.mjs.map +1 -1
  14. package/react/dist/index.d.mts +23 -6
  15. package/react/dist/index.d.ts +27 -8
  16. package/react/dist/index.js +154 -141
  17. package/react/dist/index.js.map +1 -1
  18. package/react/dist/index.mjs +153 -141
  19. package/react/dist/index.mjs.map +1 -1
  20. package/react/dist/index.server.d.mts +4 -2
  21. package/react/dist/index.server.d.ts +4 -2
  22. package/react/dist/index.server.js.map +1 -1
  23. package/react/dist/index.server.mjs.map +1 -1
  24. package/rsc/dist/index.d.ts +388 -21
  25. package/rsc/dist/rsc-client.d.mts +1 -1
  26. package/rsc/dist/rsc-client.mjs +2 -0
  27. package/rsc/dist/rsc-client.mjs.map +1 -1
  28. package/rsc/dist/rsc-server.d.mts +370 -21
  29. package/rsc/dist/rsc-server.mjs +677 -36
  30. package/rsc/dist/rsc-server.mjs.map +1 -1
  31. package/rsc/dist/rsc-shared.d.mts +24 -9
  32. package/rsc/dist/rsc-shared.mjs +98 -4
  33. package/rsc/dist/rsc-shared.mjs.map +1 -1
  34. package/solid/dist/index.d.mts +7 -3
  35. package/solid/dist/index.d.ts +7 -3
  36. package/solid/dist/index.js +106 -107
  37. package/solid/dist/index.js.map +1 -1
  38. package/solid/dist/index.mjs +106 -107
  39. package/solid/dist/index.mjs.map +1 -1
  40. package/svelte/dist/index.d.mts +7 -3
  41. package/svelte/dist/index.d.ts +7 -3
  42. package/svelte/dist/index.js +109 -109
  43. package/svelte/dist/index.js.map +1 -1
  44. package/svelte/dist/index.mjs +109 -109
  45. package/svelte/dist/index.mjs.map +1 -1
  46. package/vue/dist/index.d.mts +7 -3
  47. package/vue/dist/index.d.ts +7 -3
  48. package/vue/dist/index.js +106 -107
  49. package/vue/dist/index.js.map +1 -1
  50. package/vue/dist/index.mjs +106 -107
  51. package/vue/dist/index.mjs.map +1 -1
  52. package/ai-model-specification/dist/index.d.mts +0 -665
  53. package/ai-model-specification/dist/index.d.ts +0 -665
  54. package/ai-model-specification/dist/index.js +0 -716
  55. package/ai-model-specification/dist/index.js.map +0 -1
  56. package/ai-model-specification/dist/index.mjs +0 -656
  57. package/ai-model-specification/dist/index.mjs.map +0 -1
  58. package/core/dist/index.d.mts +0 -626
  59. package/core/dist/index.d.ts +0 -626
  60. package/core/dist/index.js +0 -1918
  61. package/core/dist/index.js.map +0 -1
  62. package/core/dist/index.mjs +0 -1873
  63. package/core/dist/index.mjs.map +0 -1
  64. package/openai/dist/index.d.mts +0 -429
  65. package/openai/dist/index.d.ts +0 -429
  66. package/openai/dist/index.js +0 -1231
  67. package/openai/dist/index.js.map +0 -1
  68. package/openai/dist/index.mjs +0 -1195
  69. package/openai/dist/index.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "3.1.0-canary.4",
3
+ "version": "3.1.1",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -14,9 +14,8 @@
14
14
  "solid/dist/**/*",
15
15
  "prompts/dist/**/*",
16
16
  "rsc/dist/**/*",
17
- "core/dist/**/*",
18
- "openai/dist/**/*",
19
- "ai-model-specification/dist/**/*"
17
+ "google/dist/**/*",
18
+ "mistral/dist/**/*"
20
19
  ],
21
20
  "exports": {
22
21
  "./package.json": "./package.json",
@@ -25,24 +24,6 @@
25
24
  "import": "./dist/index.mjs",
26
25
  "require": "./dist/index.js"
27
26
  },
28
- "./ai-model-specification": {
29
- "types": "./ai-model-specification/dist/index.d.ts",
30
- "import": "./ai-model-specification/dist/index.mjs",
31
- "module": "./ai-model-specification/dist/index.mjs",
32
- "require": "./ai-model-specification/dist/index.js"
33
- },
34
- "./core": {
35
- "types": "./core/dist/index.d.ts",
36
- "import": "./core/dist/index.mjs",
37
- "module": "./core/dist/index.mjs",
38
- "require": "./core/dist/index.js"
39
- },
40
- "./openai": {
41
- "types": "./openai/dist/index.d.ts",
42
- "import": "./openai/dist/index.mjs",
43
- "module": "./openai/dist/index.mjs",
44
- "require": "./openai/dist/index.js"
45
- },
46
27
  "./rsc": {
47
28
  "types": "./rsc/dist/index.d.ts",
48
29
  "react-server": "./rsc/dist/rsc-server.mjs",
@@ -76,17 +57,19 @@
76
57
  }
77
58
  },
78
59
  "dependencies": {
60
+ "@ai-sdk/provider": "0.0.3",
61
+ "@ai-sdk/provider-utils": "0.0.5",
79
62
  "secure-json-parse": "2.7.0",
80
63
  "eventsource-parser": "1.1.2",
81
- "jsondiffpatch": "^0.6.0",
64
+ "jsondiffpatch": "0.6.0",
65
+ "json-schema": "0.4.0",
82
66
  "nanoid": "3.3.6",
83
67
  "solid-swr-store": "0.10.7",
84
68
  "sswr": "2.0.0",
85
69
  "swr": "2.2.0",
86
70
  "swr-store": "0.10.6",
87
71
  "swrv": "1.0.4",
88
- "zod-to-json-schema": "^3.22.4",
89
- "type-fest": "4.10.3"
72
+ "zod-to-json-schema": "3.22.5"
90
73
  },
91
74
  "devDependencies": {
92
75
  "@anthropic-ai/sdk": "0.18.0",
@@ -100,6 +83,7 @@
100
83
  "@testing-library/react": "^14.0.0",
101
84
  "@testing-library/user-event": "^14.5.1",
102
85
  "@testing-library/vue": "^8.0.1",
86
+ "@types/json-schema": "7.0.15",
103
87
  "@types/node": "^17.0.12",
104
88
  "@types/react": "^18.2.8",
105
89
  "@types/react-dom": "^18.2.0",
@@ -146,7 +130,7 @@
146
130
  }
147
131
  },
148
132
  "engines": {
149
- "node": ">=14.6"
133
+ "node": ">=18"
150
134
  },
151
135
  "publishConfig": {
152
136
  "access": "public"
@@ -168,7 +152,7 @@
168
152
  ],
169
153
  "scripts": {
170
154
  "build": "tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts",
171
- "clean": "rm -rf dist && rm -rf core/dist && rm -rf openai/dist && rm -rf ai-model-specification/dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist && rm -rf solid/dist && rm -rf rsc/dist",
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",
172
156
  "dev": "tsup --watch",
173
157
  "lint": "eslint \"./**/*.ts*\"",
174
158
  "type-check": "tsc --noEmit",
@@ -177,7 +161,6 @@
177
161
  "test:edge": "vitest --config vitest.edge.config.js --run --threads=false",
178
162
  "test:node": "vitest --config vitest.node.config.js --run --threads=false",
179
163
  "test:node:core": "pnpm vitest --config vitest.node.config.js --run --threads=false ./core/",
180
- "test:node:openai": "pnpm vitest --config vitest.node.config.js --run --threads=false ./openai/",
181
164
  "test:ui": "pnpm test:ui:react && pnpm test:ui:vue && pnpm test:ui:solid",
182
165
  "test:ui:react": "vitest --config vitest.ui.react.config.js --run",
183
166
  "test:ui:solid": "vitest --config vitest.ui.solid.config.js --run",
@@ -64,6 +64,18 @@ type JSONValue = null | string | number | boolean | {
64
64
  * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api
65
65
  */
66
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
+ }[];
67
79
 
68
80
  /**
69
81
  * A prompt constructor for the HuggingFace StarChat Beta model.
@@ -252,4 +264,4 @@ interface ChatCompletionFunctionMessageParam {
252
264
  role: 'function';
253
265
  }
254
266
 
255
- export { ChatCompletionAssistantMessageParam, ChatCompletionContentPart, ChatCompletionContentPartImage, ChatCompletionContentPartText, ChatCompletionFunctionMessageParam, ChatCompletionMessageParam, ChatCompletionMessageToolCall, ChatCompletionSystemMessageParam, ChatCompletionToolMessageParam, ChatCompletionUserMessageParam, experimental_buildAnthropicPrompt, experimental_buildLlama2Prompt, experimental_buildOpenAIMessages, experimental_buildOpenAssistantPrompt, experimental_buildStarChatBetaPrompt };
267
+ export { ChatCompletionAssistantMessageParam, ChatCompletionContentPart, ChatCompletionContentPartImage, ChatCompletionContentPartText, ChatCompletionFunctionMessageParam, ChatCompletionMessageParam, ChatCompletionMessageToolCall, ChatCompletionSystemMessageParam, ChatCompletionToolMessageParam, ChatCompletionUserMessageParam, experimental_buildAnthropicMessages, experimental_buildAnthropicPrompt, experimental_buildLlama2Prompt, experimental_buildOpenAIMessages, experimental_buildOpenAssistantPrompt, experimental_buildStarChatBetaPrompt };
@@ -64,6 +64,18 @@ type JSONValue = null | string | number | boolean | {
64
64
  * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api
65
65
  */
66
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
+ }[];
67
79
 
68
80
  /**
69
81
  * A prompt constructor for the HuggingFace StarChat Beta model.
@@ -252,4 +264,4 @@ interface ChatCompletionFunctionMessageParam {
252
264
  role: 'function';
253
265
  }
254
266
 
255
- export { ChatCompletionAssistantMessageParam, ChatCompletionContentPart, ChatCompletionContentPartImage, ChatCompletionContentPartText, ChatCompletionFunctionMessageParam, ChatCompletionMessageParam, ChatCompletionMessageToolCall, ChatCompletionSystemMessageParam, ChatCompletionToolMessageParam, ChatCompletionUserMessageParam, experimental_buildAnthropicPrompt, experimental_buildLlama2Prompt, experimental_buildOpenAIMessages, experimental_buildOpenAssistantPrompt, experimental_buildStarChatBetaPrompt };
267
+ export { ChatCompletionAssistantMessageParam, ChatCompletionContentPart, ChatCompletionContentPartImage, ChatCompletionContentPartText, ChatCompletionFunctionMessageParam, ChatCompletionMessageParam, ChatCompletionMessageToolCall, ChatCompletionSystemMessageParam, ChatCompletionToolMessageParam, ChatCompletionUserMessageParam, experimental_buildAnthropicMessages, experimental_buildAnthropicPrompt, experimental_buildLlama2Prompt, experimental_buildOpenAIMessages, experimental_buildOpenAssistantPrompt, experimental_buildStarChatBetaPrompt };
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // prompts/index.ts
21
21
  var prompts_exports = {};
22
22
  __export(prompts_exports, {
23
+ experimental_buildAnthropicMessages: () => experimental_buildAnthropicMessages,
23
24
  experimental_buildAnthropicPrompt: () => experimental_buildAnthropicPrompt,
24
25
  experimental_buildLlama2Prompt: () => experimental_buildLlama2Prompt,
25
26
  experimental_buildOpenAIMessages: () => experimental_buildOpenAIMessages,
@@ -42,6 +43,17 @@ Assistant: ${content}`;
42
43
  }
43
44
  }) + "\n\nAssistant:";
44
45
  }
46
+ function experimental_buildAnthropicMessages(messages) {
47
+ return messages.map(({ content, role }) => {
48
+ if (!["assistant", "user"].includes(role)) {
49
+ throw new Error(`Cannot use ${role} on Anthropic V3 Messages API`);
50
+ }
51
+ return {
52
+ role,
53
+ content: [{ type: "text", text: content }]
54
+ };
55
+ });
56
+ }
45
57
 
46
58
  // prompts/huggingface.ts
47
59
  function experimental_buildStarChatBetaPrompt(messages) {
@@ -156,6 +168,7 @@ function experimental_buildOpenAIMessages(messages) {
156
168
  }
157
169
  // Annotate the CommonJS export names for ESM import in node:
158
170
  0 && (module.exports = {
171
+ experimental_buildAnthropicMessages,
159
172
  experimental_buildAnthropicPrompt,
160
173
  experimental_buildLlama2Prompt,
161
174
  experimental_buildOpenAIMessages,
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../anthropic.ts","../huggingface.ts","../openai.tsx"],"sourcesContent":["export * from './anthropic';\nexport * from './huggingface';\nexport * from './openai';\n","import { Message } from '../shared/types';\n\n/**\n * A prompt constructor for Anthropic models.\n * Does not support `function` messages.\n * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api\n */\nexport function experimental_buildAnthropicPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages.map(({ content, role }) => {\n if (role === 'user') {\n return `\\n\\nHuman: ${content}`;\n } else {\n return `\\n\\nAssistant: ${content}`;\n }\n }) + '\\n\\nAssistant:'\n );\n}\n","import { Message } from '../shared/types';\n\n/**\n * A prompt constructor for the HuggingFace StarChat Beta model.\n * Does not support `function` messages.\n * @see https://huggingface.co/HuggingFaceH4/starchat-beta\n */\nexport function experimental_buildStarChatBetaPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|user|>\\n${content}<|end|>\\n`;\n } else if (role === 'assistant') {\n return `<|assistant|>\\n${content}<|end|>\\n`;\n } else if (role === 'system') {\n return `<|system|>\\n${content}<|end|>\\n`;\n } else if (role === 'function') {\n throw new Error('StarChat Beta does not support function calls.');\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace OpenAssistant models.\n * Does not support `function` or `system` messages.\n * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5\n */\nexport function experimental_buildOpenAssistantPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|prompter|>${content}<|endoftext|>`;\n } else if (role === 'function') {\n throw new Error('OpenAssistant does not support function calls.');\n } else if (role === 'system') {\n throw new Error('OpenAssistant does not support system messages.');\n } else {\n return `<|assistant|>${content}<|endoftext|>`;\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace LLama 2 chat models.\n * Does not support `function` messages.\n * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2\n */\nexport function experimental_buildLlama2Prompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n const startPrompt = `<s>[INST] `;\n const endPrompt = ` [/INST]`;\n const conversation = messages.map(({ content, role }, index) => {\n if (role === 'user') {\n return content.trim();\n } else if (role === 'assistant') {\n return ` [/INST] ${content}</s><s>[INST] `;\n } else if (role === 'function') {\n throw new Error('Llama 2 does not support function calls.');\n } else if (role === 'system' && index === 0) {\n return `<<SYS>>\\n${content}\\n<</SYS>>\\n\\n`;\n } else {\n throw new Error(`Invalid message role: ${role}`);\n }\n });\n\n return startPrompt + conversation.join('') + endPrompt;\n}\n","import { Message } from '../shared/types';\n\nexport function experimental_buildOpenAIMessages(\n messages: Message[],\n): ChatCompletionMessageParam[] {\n return messages.map(message => {\n switch (message.role) {\n case 'system':\n case 'user':\n return {\n role: message.role,\n content: message.content,\n } satisfies ChatCompletionMessageParam;\n\n case 'assistant': {\n const function_call = message.function_call;\n\n if (\n function_call !== undefined &&\n (typeof function_call === 'string' ||\n function_call.arguments === undefined ||\n function_call.name === undefined)\n ) {\n throw new Error(\n 'Invalid function call in message. Expected a function call object',\n );\n }\n\n return {\n role: message.role,\n content: message.content,\n function_call:\n function_call === undefined\n ? undefined\n : {\n name: function_call.name!,\n arguments: function_call.arguments!,\n },\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'function': {\n if (message.name === undefined) {\n throw new Error('Invalid function call in message. Expected a name');\n }\n\n return {\n role: message.role,\n content: message.content,\n name: message.name,\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'data': {\n throw \"unsupported message role 'data'\";\n }\n\n case 'tool': {\n if (message.name === undefined) {\n throw new Error('Invalid tool message. Expected a name');\n }\n\n if (message.tool_call_id === undefined) {\n throw new Error('Invalid tool message. Expected a tool_call_id');\n }\n\n return {\n role: message.role,\n content: message.content,\n tool_call_id: message.tool_call_id,\n } satisfies ChatCompletionMessageParam;\n }\n }\n });\n}\n\n// copy of open ai messages (so we don't have a dependency on the openai package)\nexport type ChatCompletionMessageParam =\n | ChatCompletionSystemMessageParam\n | ChatCompletionUserMessageParam\n | ChatCompletionAssistantMessageParam\n | ChatCompletionToolMessageParam\n | ChatCompletionFunctionMessageParam;\n\nexport interface ChatCompletionSystemMessageParam {\n /**\n * The contents of the system message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `system`.\n */\n role: 'system';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport interface ChatCompletionUserMessageParam {\n /**\n * The contents of the user message.\n */\n content: string | Array<ChatCompletionContentPart>;\n\n /**\n * The role of the messages author, in this case `user`.\n */\n role: 'user';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport type ChatCompletionContentPart =\n | ChatCompletionContentPartText\n | ChatCompletionContentPartImage;\n\nexport interface ChatCompletionContentPartText {\n /**\n * The text content.\n */\n text: string;\n\n /**\n * The type of the content part.\n */\n type: 'text';\n}\n\nexport interface ChatCompletionContentPartImage {\n image_url: ChatCompletionContentPartImage.ImageURL;\n\n /**\n * The type of the content part.\n */\n type: 'image_url';\n}\n\nexport namespace ChatCompletionContentPartImage {\n export interface ImageURL {\n /**\n * Either a URL of the image or the base64 encoded image data.\n */\n url: string;\n\n /**\n * Specifies the detail level of the image. Learn more in the\n * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).\n */\n detail?: 'auto' | 'low' | 'high';\n }\n}\n\nexport interface ChatCompletionAssistantMessageParam {\n /**\n * The role of the messages author, in this case `assistant`.\n */\n role: 'assistant';\n\n /**\n * The contents of the assistant message. Required unless `tool_calls` or\n * `function_call` is specified.\n */\n content?: string | null;\n\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n function_call?: ChatCompletionAssistantMessageParam.FunctionCall;\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n\n /**\n * The tool calls generated by the model, such as function calls.\n */\n tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionAssistantMessageParam {\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionMessageToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: ChatCompletionMessageToolCall.Function;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: 'function';\n}\n\nexport namespace ChatCompletionMessageToolCall {\n /**\n * The function that the model called.\n */\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionToolMessageParam {\n /**\n * The contents of the tool message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `tool`.\n */\n role: 'tool';\n\n /**\n * Tool call that this message is responding to.\n */\n tool_call_id: string;\n}\n\nexport interface ChatCompletionFunctionMessageParam {\n /**\n * The return value from the function call, to return to the model.\n */\n content: string | null;\n\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * The role of the messages author, in this case `function`.\n */\n role: 'function';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,SAAS,kCACd,UACA;AACA,SACE,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAClC,QAAI,SAAS,QAAQ;AACnB,aAAO;AAAA;AAAA,SAAc,OAAO;AAAA,IAC9B,OAAO;AACL,aAAO;AAAA;AAAA,aAAkB,OAAO;AAAA,IAClC;AAAA,EACF,CAAC,IAAI;AAET;;;ACZO,SAAS,qCACd,UACA;AACA,SACE,SACG,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAC1B,QAAI,SAAS,QAAQ;AACnB,aAAO;AAAA,EAAa,OAAO;AAAA;AAAA,IAC7B,WAAW,SAAS,aAAa;AAC/B,aAAO;AAAA,EAAkB,OAAO;AAAA;AAAA,IAClC,WAAW,SAAS,UAAU;AAC5B,aAAO;AAAA,EAAe,OAAO;AAAA;AAAA,IAC/B,WAAW,SAAS,YAAY;AAC9B,YAAM,IAAI,MAAM,gDAAgD;AAAA,IAClE;AAAA,EACF,CAAC,EACA,KAAK,EAAE,IAAI;AAElB;AAOO,SAAS,sCACd,UACA;AACA,SACE,SACG,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAC1B,QAAI,SAAS,QAAQ;AACnB,aAAO,eAAe,OAAO;AAAA,IAC/B,WAAW,SAAS,YAAY;AAC9B,YAAM,IAAI,MAAM,gDAAgD;AAAA,IAClE,WAAW,SAAS,UAAU;AAC5B,YAAM,IAAI,MAAM,iDAAiD;AAAA,IACnE,OAAO;AACL,aAAO,gBAAgB,OAAO;AAAA,IAChC;AAAA,EACF,CAAC,EACA,KAAK,E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QAAQ;AAAA,UACd,SAAS,QAAQ;AAAA,UACjB,MAAM,QAAQ;AAAA,QAChB;AAAA,MACF;AAAA,MAEA,KAAK,QAAQ;AACX,cAAM;AAAA,MACR;AAAA,MAEA,KAAK,QAAQ;AACX,YAAI,QAAQ,SAAS,QAAW;AAC9B,gBAAM,IAAI,MAAM,uCAAuC;AAAA,QACzD;AAEA,YAAI,QAAQ,iBAAiB,QAAW;AACtC,gBAAM,IAAI,MAAM,+CAA+C;AAAA,QACjE;AAEA,eAAO;AAAA,UACL,MAAM,QAAQ;AAAA,UACd,SAAS,QAAQ;AAAA,UACjB,cAAc,QAAQ;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../index.ts","../anthropic.ts","../huggingface.ts","../openai.tsx"],"sourcesContent":["export * from './anthropic';\nexport * from './huggingface';\nexport * from './openai';\n","import { Message } from '../shared/types';\n\n/**\n * A prompt constructor for Anthropic models.\n * Does not support `function` messages.\n * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api\n */\nexport function experimental_buildAnthropicPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages.map(({ content, role }) => {\n if (role === 'user') {\n return `\\n\\nHuman: ${content}`;\n } else {\n return `\\n\\nAssistant: ${content}`;\n }\n }) + '\\n\\nAssistant:'\n );\n}\n\n/**\n * A prompt constructor for Anthropic V3 models which require Messages API.\n * Does not support message with image content\n * @see https://docs.anthropic.com/claude/reference/messages_post\n */\nexport function experimental_buildAnthropicMessages(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return messages.map(({ content, role }) => {\n if (!['assistant', 'user'].includes(role)) {\n throw new Error(`Cannot use ${role} on Anthropic V3 Messages API`);\n }\n return {\n role,\n content: [{ type: 'text', text: content }],\n };\n });\n}\n","import { Message } from '../shared/types';\n\n/**\n * A prompt constructor for the HuggingFace StarChat Beta model.\n * Does not support `function` messages.\n * @see https://huggingface.co/HuggingFaceH4/starchat-beta\n */\nexport function experimental_buildStarChatBetaPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|user|>\\n${content}<|end|>\\n`;\n } else if (role === 'assistant') {\n return `<|assistant|>\\n${content}<|end|>\\n`;\n } else if (role === 'system') {\n return `<|system|>\\n${content}<|end|>\\n`;\n } else if (role === 'function') {\n throw new Error('StarChat Beta does not support function calls.');\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace OpenAssistant models.\n * Does not support `function` or `system` messages.\n * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5\n */\nexport function experimental_buildOpenAssistantPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|prompter|>${content}<|endoftext|>`;\n } else if (role === 'function') {\n throw new Error('OpenAssistant does not support function calls.');\n } else if (role === 'system') {\n throw new Error('OpenAssistant does not support system messages.');\n } else {\n return `<|assistant|>${content}<|endoftext|>`;\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace LLama 2 chat models.\n * Does not support `function` messages.\n * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2\n */\nexport function experimental_buildLlama2Prompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n const startPrompt = `<s>[INST] `;\n const endPrompt = ` [/INST]`;\n const conversation = messages.map(({ content, role }, index) => {\n if (role === 'user') {\n return content.trim();\n } else if (role === 'assistant') {\n return ` [/INST] ${content}</s><s>[INST] `;\n } else if (role === 'function') {\n throw new Error('Llama 2 does not support function calls.');\n } else if (role === 'system' && index === 0) {\n return `<<SYS>>\\n${content}\\n<</SYS>>\\n\\n`;\n } else {\n throw new Error(`Invalid message role: ${role}`);\n }\n });\n\n return startPrompt + conversation.join('') + endPrompt;\n}\n","import { Message } from '../shared/types';\n\nexport function experimental_buildOpenAIMessages(\n messages: Message[],\n): ChatCompletionMessageParam[] {\n return messages.map(message => {\n switch (message.role) {\n case 'system':\n case 'user':\n return {\n role: message.role,\n content: message.content,\n } satisfies ChatCompletionMessageParam;\n\n case 'assistant': {\n const function_call = message.function_call;\n\n if (\n function_call !== undefined &&\n (typeof function_call === 'string' ||\n function_call.arguments === undefined ||\n function_call.name === undefined)\n ) {\n throw new Error(\n 'Invalid function call in message. Expected a function call object',\n );\n }\n\n return {\n role: message.role,\n content: message.content,\n function_call:\n function_call === undefined\n ? undefined\n : {\n name: function_call.name!,\n arguments: function_call.arguments!,\n },\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'function': {\n if (message.name === undefined) {\n throw new Error('Invalid function call in message. Expected a name');\n }\n\n return {\n role: message.role,\n content: message.content,\n name: message.name,\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'data': {\n throw \"unsupported message role 'data'\";\n }\n\n case 'tool': {\n if (message.name === undefined) {\n throw new Error('Invalid tool message. Expected a name');\n }\n\n if (message.tool_call_id === undefined) {\n throw new Error('Invalid tool message. Expected a tool_call_id');\n }\n\n return {\n role: message.role,\n content: message.content,\n tool_call_id: message.tool_call_id,\n } satisfies ChatCompletionMessageParam;\n }\n }\n });\n}\n\n// copy of open ai messages (so we don't have a dependency on the openai package)\nexport type ChatCompletionMessageParam =\n | ChatCompletionSystemMessageParam\n | ChatCompletionUserMessageParam\n | ChatCompletionAssistantMessageParam\n | ChatCompletionToolMessageParam\n | ChatCompletionFunctionMessageParam;\n\nexport interface ChatCompletionSystemMessageParam {\n /**\n * The contents of the system message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `system`.\n */\n role: 'system';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport interface ChatCompletionUserMessageParam {\n /**\n * The contents of the user message.\n */\n content: string | Array<ChatCompletionContentPart>;\n\n /**\n * The role of the messages author, in this case `user`.\n */\n role: 'user';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport type ChatCompletionContentPart =\n | ChatCompletionContentPartText\n | ChatCompletionContentPartImage;\n\nexport interface ChatCompletionContentPartText {\n /**\n * The text content.\n */\n text: string;\n\n /**\n * The type of the content part.\n */\n type: 'text';\n}\n\nexport interface ChatCompletionContentPartImage {\n image_url: ChatCompletionContentPartImage.ImageURL;\n\n /**\n * The type of the content part.\n */\n type: 'image_url';\n}\n\nexport namespace ChatCompletionContentPartImage {\n export interface ImageURL {\n /**\n * Either a URL of the image or the base64 encoded image data.\n */\n url: string;\n\n /**\n * Specifies the detail level of the image. Learn more in the\n * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).\n */\n detail?: 'auto' | 'low' | 'high';\n }\n}\n\nexport interface ChatCompletionAssistantMessageParam {\n /**\n * The role of the messages author, in this case `assistant`.\n */\n role: 'assistant';\n\n /**\n * The contents of the assistant message. Required unless `tool_calls` or\n * `function_call` is specified.\n */\n content?: string | null;\n\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n function_call?: ChatCompletionAssistantMessageParam.FunctionCall;\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n\n /**\n * The tool calls generated by the model, such as function calls.\n */\n tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionAssistantMessageParam {\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionMessageToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: ChatCompletionMessageToolCall.Function;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: 'function';\n}\n\nexport namespace ChatCompletionMessageToolCall {\n /**\n * The function that the model called.\n */\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionToolMessageParam {\n /**\n * The contents of the tool message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `tool`.\n */\n role: 'tool';\n\n /**\n * Tool call that this message is responding to.\n */\n tool_call_id: string;\n}\n\nexport interface ChatCompletionFunctionMessageParam {\n /**\n * The return value from the function call, to return to the model.\n */\n content: string | null;\n\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * The role of the messages author, in this case `function`.\n */\n role: 'function';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,SAAS,kCACd,UACA;AACA,SACE,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAClC,QAAI,SAAS,QAAQ;AACnB,aAAO;AAAA;AAAA,SAAc,OAAO;AAAA,IAC9B,OAAO;AACL,aAAO;AAAA;AAAA,aAAkB,OAAO;AAAA,IAClC;AAAA,EACF,CAAC,IAAI;AAET;AAOO,SAAS,oCACd,UACA;AACA,SAAO,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AACzC,QAAI,CAAC,CAAC,aAAa,MAAM,EAAE,SAAS,IAAI,GAAG;AACzC,YAAM,IAAI,MAAM,cAAc,IAAI,+BAA+B;AAAA,IACnE;AACA,WAAO;AAAA,MACL;AAAA,MACA,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ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]}
@@ -12,6 +12,17 @@ Assistant: ${content}`;
12
12
  }
13
13
  }) + "\n\nAssistant:";
14
14
  }
15
+ function experimental_buildAnthropicMessages(messages) {
16
+ return messages.map(({ content, role }) => {
17
+ if (!["assistant", "user"].includes(role)) {
18
+ throw new Error(`Cannot use ${role} on Anthropic V3 Messages API`);
19
+ }
20
+ return {
21
+ role,
22
+ content: [{ type: "text", text: content }]
23
+ };
24
+ });
25
+ }
15
26
 
16
27
  // prompts/huggingface.ts
17
28
  function experimental_buildStarChatBetaPrompt(messages) {
@@ -125,6 +136,7 @@ function experimental_buildOpenAIMessages(messages) {
125
136
  });
126
137
  }
127
138
  export {
139
+ experimental_buildAnthropicMessages,
128
140
  experimental_buildAnthropicPrompt,
129
141
  experimental_buildLlama2Prompt,
130
142
  experimental_buildOpenAIMessages,
@@ -1 +1 @@
1
- {"version":3,"sources":["../anthropic.ts","../huggingface.ts","../openai.tsx"],"sourcesContent":["import { Message } from '../shared/types';\n\n/**\n * A prompt constructor for Anthropic models.\n * Does not support `function` messages.\n * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api\n */\nexport function experimental_buildAnthropicPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages.map(({ content, role }) => {\n if (role === 'user') {\n return `\\n\\nHuman: ${content}`;\n } else {\n return `\\n\\nAssistant: ${content}`;\n }\n }) + '\\n\\nAssistant:'\n );\n}\n","import { Message } from '../shared/types';\n\n/**\n * A prompt constructor for the HuggingFace StarChat Beta model.\n * Does not support `function` messages.\n * @see https://huggingface.co/HuggingFaceH4/starchat-beta\n */\nexport function experimental_buildStarChatBetaPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|user|>\\n${content}<|end|>\\n`;\n } else if (role === 'assistant') {\n return `<|assistant|>\\n${content}<|end|>\\n`;\n } else if (role === 'system') {\n return `<|system|>\\n${content}<|end|>\\n`;\n } else if (role === 'function') {\n throw new Error('StarChat Beta does not support function calls.');\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace OpenAssistant models.\n * Does not support `function` or `system` messages.\n * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5\n */\nexport function experimental_buildOpenAssistantPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|prompter|>${content}<|endoftext|>`;\n } else if (role === 'function') {\n throw new Error('OpenAssistant does not support function calls.');\n } else if (role === 'system') {\n throw new Error('OpenAssistant does not support system messages.');\n } else {\n return `<|assistant|>${content}<|endoftext|>`;\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace LLama 2 chat models.\n * Does not support `function` messages.\n * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2\n */\nexport function experimental_buildLlama2Prompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n const startPrompt = `<s>[INST] `;\n const endPrompt = ` [/INST]`;\n const conversation = messages.map(({ content, role }, index) => {\n if (role === 'user') {\n return content.trim();\n } else if (role === 'assistant') {\n return ` [/INST] ${content}</s><s>[INST] `;\n } else if (role === 'function') {\n throw new Error('Llama 2 does not support function calls.');\n } else if (role === 'system' && index === 0) {\n return `<<SYS>>\\n${content}\\n<</SYS>>\\n\\n`;\n } else {\n throw new Error(`Invalid message role: ${role}`);\n }\n });\n\n return startPrompt + conversation.join('') + endPrompt;\n}\n","import { Message } from '../shared/types';\n\nexport function experimental_buildOpenAIMessages(\n messages: Message[],\n): ChatCompletionMessageParam[] {\n return messages.map(message => {\n switch (message.role) {\n case 'system':\n case 'user':\n return {\n role: message.role,\n content: message.content,\n } satisfies ChatCompletionMessageParam;\n\n case 'assistant': {\n const function_call = message.function_call;\n\n if (\n function_call !== undefined &&\n (typeof function_call === 'string' ||\n function_call.arguments === undefined ||\n function_call.name === undefined)\n ) {\n throw new Error(\n 'Invalid function call in message. Expected a function call object',\n );\n }\n\n return {\n role: message.role,\n content: message.content,\n function_call:\n function_call === undefined\n ? undefined\n : {\n name: function_call.name!,\n arguments: function_call.arguments!,\n },\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'function': {\n if (message.name === undefined) {\n throw new Error('Invalid function call in message. Expected a name');\n }\n\n return {\n role: message.role,\n content: message.content,\n name: message.name,\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'data': {\n throw \"unsupported message role 'data'\";\n }\n\n case 'tool': {\n if (message.name === undefined) {\n throw new Error('Invalid tool message. Expected a name');\n }\n\n if (message.tool_call_id === undefined) {\n throw new Error('Invalid tool message. Expected a tool_call_id');\n }\n\n return {\n role: message.role,\n content: message.content,\n tool_call_id: message.tool_call_id,\n } satisfies ChatCompletionMessageParam;\n }\n }\n });\n}\n\n// copy of open ai messages (so we don't have a dependency on the openai package)\nexport type ChatCompletionMessageParam =\n | ChatCompletionSystemMessageParam\n | ChatCompletionUserMessageParam\n | ChatCompletionAssistantMessageParam\n | ChatCompletionToolMessageParam\n | ChatCompletionFunctionMessageParam;\n\nexport interface ChatCompletionSystemMessageParam {\n /**\n * The contents of the system message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `system`.\n */\n role: 'system';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport interface ChatCompletionUserMessageParam {\n /**\n * The contents of the user message.\n */\n content: string | Array<ChatCompletionContentPart>;\n\n /**\n * The role of the messages author, in this case `user`.\n */\n role: 'user';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport type ChatCompletionContentPart =\n | ChatCompletionContentPartText\n | ChatCompletionContentPartImage;\n\nexport interface ChatCompletionContentPartText {\n /**\n * The text content.\n */\n text: string;\n\n /**\n * The type of the content part.\n */\n type: 'text';\n}\n\nexport interface ChatCompletionContentPartImage {\n image_url: ChatCompletionContentPartImage.ImageURL;\n\n /**\n * The type of the content part.\n */\n type: 'image_url';\n}\n\nexport namespace ChatCompletionContentPartImage {\n export interface ImageURL {\n /**\n * Either a URL of the image or the base64 encoded image data.\n */\n url: string;\n\n /**\n * Specifies the detail level of the image. Learn more in the\n * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).\n */\n detail?: 'auto' | 'low' | 'high';\n }\n}\n\nexport interface ChatCompletionAssistantMessageParam {\n /**\n * The role of the messages author, in this case `assistant`.\n */\n role: 'assistant';\n\n /**\n * The contents of the assistant message. Required unless `tool_calls` or\n * `function_call` is specified.\n */\n content?: string | null;\n\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n function_call?: ChatCompletionAssistantMessageParam.FunctionCall;\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n\n /**\n * The tool calls generated by the model, such as function calls.\n */\n tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionAssistantMessageParam {\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionMessageToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: ChatCompletionMessageToolCall.Function;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: 'function';\n}\n\nexport namespace ChatCompletionMessageToolCall {\n /**\n * The function that the model called.\n */\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionToolMessageParam {\n /**\n * The contents of the tool message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `tool`.\n */\n role: 'tool';\n\n /**\n * Tool call that this message is responding to.\n */\n tool_call_id: string;\n}\n\nexport interface ChatCompletionFunctionMessageParam {\n /**\n * The return value from the function call, to return to the model.\n */\n content: string | null;\n\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * The role of the messages author, in this case `function`.\n */\n role: 'function';\n}\n"],"mappings":";AAOO,SAAS,kCACd,UACA;AACA,SACE,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAClC,QAAI,SAAS,QAAQ;AACnB,aAAO;AAAA;AAAA,SAAc,OAAO;AAAA,IAC9B,OAAO;AACL,aAAO;AAAA;AAAA,aAAkB,OAAO;AAAA,IAClC;AAAA,EACF,CAAC,IAAI;AAET;;;ACZO,SAAS,qCACd,UACA;AACA,SACE,SACG,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAC1B,QAAI,SAAS,QAAQ;AACnB,aAAO;AAAA,EAAa,OAAO;AAAA;AAAA,IAC7B,WAAW,SAAS,aAAa;AAC/B,aAAO;AAAA,EAAkB,OAAO;AAAA;AAAA,IAClC,WAAW,SAAS,UAAU;AAC5B,aAAO;AAAA,EAAe,OAAO;AAAA;AAAA,IAC/B,WAAW,SAAS,YAAY;AAC9B,YAAM,IAAI,MAAM,gDAAgD;AAAA,IAClE;AAAA,EACF,CAAC,EACA,KAAK,EAAE,IAAI;AAElB;AAOO,SAAS,sCACd,UACA;AACA,SACE,SACG,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAC1B,QAAI,SAAS,QAAQ;AACnB,aAAO,eAAe,OAAO;AAAA,IAC/B,WAAW,SAAS,YAAY;AAC9B,YAAM,IAAI,MAAM,gDAAgD;AAAA,IAClE,WAAW,SAAS,UAA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A,KAAK,YAAY;AACf,YAAI,QAAQ,SAAS,QAAW;AAC9B,gBAAM,IAAI,MAAM,mDAAmD;AAAA,QACrE;AAEA,eAAO;AAAA,UACL,MAAM,QAAQ;AAAA,UACd,SAAS,QAAQ;AAAA,UACjB,MAAM,QAAQ;AAAA,QAChB;AAAA,MACF;AAAA,MAEA,KAAK,QAAQ;AACX,cAAM;AAAA,MACR;AAAA,MAEA,KAAK,QAAQ;AACX,YAAI,QAAQ,SAAS,QAAW;AAC9B,gBAAM,IAAI,MAAM,uCAAuC;AAAA,QACzD;AAEA,YAAI,QAAQ,iBAAiB,QAAW;AACtC,gBAAM,IAAI,MAAM,+CAA+C;AAAA,QACjE;AAEA,eAAO;AAAA,UACL,MAAM,QAAQ;AAAA,UACd,SAAS,QAAQ;AAAA,UACjB,cAAc,QAAQ;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../anthropic.ts","../huggingface.ts","../openai.tsx"],"sourcesContent":["import { Message } from '../shared/types';\n\n/**\n * A prompt constructor for Anthropic models.\n * Does not support `function` messages.\n * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api\n */\nexport function experimental_buildAnthropicPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages.map(({ content, role }) => {\n if (role === 'user') {\n return `\\n\\nHuman: ${content}`;\n } else {\n return `\\n\\nAssistant: ${content}`;\n }\n }) + '\\n\\nAssistant:'\n );\n}\n\n/**\n * A prompt constructor for Anthropic V3 models which require Messages API.\n * Does not support message with image content\n * @see https://docs.anthropic.com/claude/reference/messages_post\n */\nexport function experimental_buildAnthropicMessages(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return messages.map(({ content, role }) => {\n if (!['assistant', 'user'].includes(role)) {\n throw new Error(`Cannot use ${role} on Anthropic V3 Messages API`);\n }\n return {\n role,\n content: [{ type: 'text', text: content }],\n };\n });\n}\n","import { Message } from '../shared/types';\n\n/**\n * A prompt constructor for the HuggingFace StarChat Beta model.\n * Does not support `function` messages.\n * @see https://huggingface.co/HuggingFaceH4/starchat-beta\n */\nexport function experimental_buildStarChatBetaPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|user|>\\n${content}<|end|>\\n`;\n } else if (role === 'assistant') {\n return `<|assistant|>\\n${content}<|end|>\\n`;\n } else if (role === 'system') {\n return `<|system|>\\n${content}<|end|>\\n`;\n } else if (role === 'function') {\n throw new Error('StarChat Beta does not support function calls.');\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace OpenAssistant models.\n * Does not support `function` or `system` messages.\n * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5\n */\nexport function experimental_buildOpenAssistantPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|prompter|>${content}<|endoftext|>`;\n } else if (role === 'function') {\n throw new Error('OpenAssistant does not support function calls.');\n } else if (role === 'system') {\n throw new Error('OpenAssistant does not support system messages.');\n } else {\n return `<|assistant|>${content}<|endoftext|>`;\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace LLama 2 chat models.\n * Does not support `function` messages.\n * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2\n */\nexport function experimental_buildLlama2Prompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n const startPrompt = `<s>[INST] `;\n const endPrompt = ` [/INST]`;\n const conversation = messages.map(({ content, role }, index) => {\n if (role === 'user') {\n return content.trim();\n } else if (role === 'assistant') {\n return ` [/INST] ${content}</s><s>[INST] `;\n } else if (role === 'function') {\n throw new Error('Llama 2 does not support function calls.');\n } else if (role === 'system' && index === 0) {\n return `<<SYS>>\\n${content}\\n<</SYS>>\\n\\n`;\n } else {\n throw new Error(`Invalid message role: ${role}`);\n }\n });\n\n return startPrompt + conversation.join('') + endPrompt;\n}\n","import { Message } from '../shared/types';\n\nexport function experimental_buildOpenAIMessages(\n messages: Message[],\n): ChatCompletionMessageParam[] {\n return messages.map(message => {\n switch (message.role) {\n case 'system':\n case 'user':\n return {\n role: message.role,\n content: message.content,\n } satisfies ChatCompletionMessageParam;\n\n case 'assistant': {\n const function_call = message.function_call;\n\n if (\n function_call !== undefined &&\n (typeof function_call === 'string' ||\n function_call.arguments === undefined ||\n function_call.name === undefined)\n ) {\n throw new Error(\n 'Invalid function call in message. Expected a function call object',\n );\n }\n\n return {\n role: message.role,\n content: message.content,\n function_call:\n function_call === undefined\n ? undefined\n : {\n name: function_call.name!,\n arguments: function_call.arguments!,\n },\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'function': {\n if (message.name === undefined) {\n throw new Error('Invalid function call in message. Expected a name');\n }\n\n return {\n role: message.role,\n content: message.content,\n name: message.name,\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'data': {\n throw \"unsupported message role 'data'\";\n }\n\n case 'tool': {\n if (message.name === undefined) {\n throw new Error('Invalid tool message. Expected a name');\n }\n\n if (message.tool_call_id === undefined) {\n throw new Error('Invalid tool message. Expected a tool_call_id');\n }\n\n return {\n role: message.role,\n content: message.content,\n tool_call_id: message.tool_call_id,\n } satisfies ChatCompletionMessageParam;\n }\n }\n });\n}\n\n// copy of open ai messages (so we don't have a dependency on the openai package)\nexport type ChatCompletionMessageParam =\n | ChatCompletionSystemMessageParam\n | ChatCompletionUserMessageParam\n | ChatCompletionAssistantMessageParam\n | ChatCompletionToolMessageParam\n | ChatCompletionFunctionMessageParam;\n\nexport interface ChatCompletionSystemMessageParam {\n /**\n * The contents of the system message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `system`.\n */\n role: 'system';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport interface ChatCompletionUserMessageParam {\n /**\n * The contents of the user message.\n */\n content: string | Array<ChatCompletionContentPart>;\n\n /**\n * The role of the messages author, in this case `user`.\n */\n role: 'user';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport type ChatCompletionContentPart =\n | ChatCompletionContentPartText\n | ChatCompletionContentPartImage;\n\nexport interface ChatCompletionContentPartText {\n /**\n * The text content.\n */\n text: string;\n\n /**\n * The type of the content part.\n */\n type: 'text';\n}\n\nexport interface ChatCompletionContentPartImage {\n image_url: ChatCompletionContentPartImage.ImageURL;\n\n /**\n * The type of the content part.\n */\n type: 'image_url';\n}\n\nexport namespace ChatCompletionContentPartImage {\n export interface ImageURL {\n /**\n * Either a URL of the image or the base64 encoded image data.\n */\n url: string;\n\n /**\n * Specifies the detail level of the image. Learn more in the\n * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).\n */\n detail?: 'auto' | 'low' | 'high';\n }\n}\n\nexport interface ChatCompletionAssistantMessageParam {\n /**\n * The role of the messages author, in this case `assistant`.\n */\n role: 'assistant';\n\n /**\n * The contents of the assistant message. Required unless `tool_calls` or\n * `function_call` is specified.\n */\n content?: string | null;\n\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n function_call?: ChatCompletionAssistantMessageParam.FunctionCall;\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n\n /**\n * The tool calls generated by the model, such as function calls.\n */\n tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionAssistantMessageParam {\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionMessageToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: ChatCompletionMessageToolCall.Function;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: 'function';\n}\n\nexport namespace ChatCompletionMessageToolCall {\n /**\n * The function that the model called.\n */\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionToolMessageParam {\n /**\n * The contents of the tool message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `tool`.\n */\n role: 'tool';\n\n /**\n * Tool call that this message is responding to.\n */\n tool_call_id: string;\n}\n\nexport interface ChatCompletionFunctionMessageParam {\n /**\n * The return value from the function call, to return to the model.\n */\n content: string | null;\n\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * The role of the messages author, in this case `function`.\n */\n role: 'function';\n}\n"],"mappings":";AAOO,SAAS,kCACd,UACA;AACA,SACE,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAClC,QAAI,SAAS,QAAQ;AACnB,aAAO;AAAA;AAAA,SAAc,OAAO;AAAA,IAC9B,OAAO;AACL,aAAO;AAAA;AAAA,aAAkB,OAAO;AAAA,IAClC;AAAA,EACF,CAAC,IAAI;AAET;AAOO,SAAS,oCACd,UACA;AACA,SAAO,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AACzC,QAAI,CAAC,CAAC,aAAa,MAAM,EAAE,SAAS,IAAI,GAAG;AACzC,YAAM,IAAI,MAAM,cAAc,IAAI,+BAA+B;AAAA,IACnE;AACA,WAAO;AAAA,MACL;AAAA,MACA,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,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+202,8 @@ type UseChatOptions = {
202
202
  * handle the extra fields before forwarding the request to the AI service.
203
203
  */
204
204
  sendExtraMessageFields?: boolean;
205
+ /** Stream mode (default to "stream-data") */
206
+ streamMode?: 'stream-data' | 'text';
205
207
  };
206
208
  type UseCompletionOptions = {
207
209
  /**
@@ -258,6 +260,8 @@ type UseCompletionOptions = {
258
260
  * ```
259
261
  */
260
262
  body?: object;
263
+ /** Stream mode (default to "stream-data") */
264
+ streamMode?: 'stream-data' | 'text';
261
265
  };
262
266
  type JSONValue = null | string | number | boolean | {
263
267
  [x: string]: JSONValue;
@@ -266,7 +270,7 @@ type JSONValue = null | string | number | boolean | {
266
270
  /**
267
271
  * A stream wrapper to send custom JSON-encoded data back to the client.
268
272
  */
269
- declare class experimental_StreamData {
273
+ declare class StreamData {
270
274
  private encoder;
271
275
  private controller;
272
276
  stream: TransformStream<Uint8Array, Uint8Array>;
@@ -301,7 +305,7 @@ declare class experimental_StreamingReactResponse {
301
305
  content: string;
302
306
  data?: JSONValue[];
303
307
  }) => UINode | Promise<UINode>;
304
- data?: experimental_StreamData;
308
+ data?: StreamData;
305
309
  generateId?: IdGenerator;
306
310
  });
307
311
  }
@@ -352,7 +356,7 @@ type StreamingReactResponseAction = (payload: {
352
356
  messages: Message[];
353
357
  data?: Record<string, string>;
354
358
  }) => Promise<experimental_StreamingReactResponse>;
355
- declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, experimental_onToolCall, onResponse, onFinish, onError, credentials, headers, body, generateId, }?: Omit<UseChatOptions, 'api'> & {
359
+ declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, experimental_onToolCall, streamMode, onResponse, onFinish, onError, credentials, headers, body, generateId, }?: Omit<UseChatOptions, 'api'> & {
356
360
  api?: string | StreamingReactResponseAction;
357
361
  key?: string;
358
362
  }): UseChatHelpers;
@@ -401,7 +405,7 @@ type UseCompletionHelpers = {
401
405
  /** Additional data added on the server via StreamData */
402
406
  data?: JSONValue[];
403
407
  };
404
- declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
408
+ declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamMode, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
405
409
 
406
410
  type AssistantStatus = 'in_progress' | 'awaiting_message';
407
411
  type UseAssistantHelpers = {
@@ -421,6 +425,15 @@ type UseAssistantHelpers = {
421
425
  * The current value of the input field.
422
426
  */
423
427
  input: string;
428
+ /**
429
+ * Append a user message to the chat list. This triggers the API call to fetch
430
+ * the assistant's response.
431
+ * @param message The message to append
432
+ * @param requestOptions Additional options to pass to the API call
433
+ */
434
+ append: (message: Message | CreateMessage, requestOptions?: {
435
+ data?: Record<string, string>;
436
+ }) => Promise<void>;
424
437
  /**
425
438
  * setState-powered method to update the input value.
426
439
  */
@@ -474,6 +487,10 @@ type UseAssistantOptions = {
474
487
  */
475
488
  onError?: (error: Error) => void;
476
489
  };
477
- declare function experimental_useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
490
+ declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
491
+ /**
492
+ @deprecated Use `useAssistant` instead.
493
+ */
494
+ declare const experimental_useAssistant: typeof useAssistant;
478
495
 
479
- export { AssistantStatus, CreateMessage, Message, UseAssistantHelpers, UseAssistantOptions, UseChatHelpers, UseChatOptions, UseCompletionHelpers, experimental_useAssistant, useChat, useCompletion };
496
+ export { AssistantStatus, CreateMessage, Message, UseAssistantHelpers, UseAssistantOptions, UseChatHelpers, UseChatOptions, UseCompletionHelpers, UseCompletionOptions, experimental_useAssistant, useAssistant, useChat, useCompletion };
@@ -202,6 +202,8 @@ type UseChatOptions = {
202
202
  * handle the extra fields before forwarding the request to the AI service.
203
203
  */
204
204
  sendExtraMessageFields?: boolean;
205
+ /** Stream mode (default to "stream-data") */
206
+ streamMode?: 'stream-data' | 'text';
205
207
  };
206
208
  type UseCompletionOptions = {
207
209
  /**
@@ -258,6 +260,8 @@ type UseCompletionOptions = {
258
260
  * ```
259
261
  */
260
262
  body?: object;
263
+ /** Stream mode (default to "stream-data") */
264
+ streamMode?: 'stream-data' | 'text';
261
265
  };
262
266
  type JSONValue = null | string | number | boolean | {
263
267
  [x: string]: JSONValue;
@@ -266,7 +270,7 @@ type JSONValue = null | string | number | boolean | {
266
270
  /**
267
271
  * A stream wrapper to send custom JSON-encoded data back to the client.
268
272
  */
269
- declare class experimental_StreamData {
273
+ declare class StreamData {
270
274
  private encoder;
271
275
  private controller;
272
276
  stream: TransformStream<Uint8Array, Uint8Array>;
@@ -301,7 +305,7 @@ declare class experimental_StreamingReactResponse {
301
305
  content: string;
302
306
  data?: JSONValue[];
303
307
  }) => UINode | Promise<UINode>;
304
- data?: experimental_StreamData;
308
+ data?: StreamData;
305
309
  generateId?: IdGenerator;
306
310
  });
307
311
  }
@@ -352,7 +356,7 @@ type StreamingReactResponseAction = (payload: {
352
356
  messages: Message[];
353
357
  data?: Record<string, string>;
354
358
  }) => Promise<experimental_StreamingReactResponse>;
355
- declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, experimental_onToolCall, onResponse, onFinish, onError, credentials, headers, body, generateId, }?: Omit<UseChatOptions, 'api'> & {
359
+ declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, experimental_onFunctionCall, experimental_onToolCall, streamMode, onResponse, onFinish, onError, credentials, headers, body, generateId, }?: Omit<UseChatOptions, 'api'> & {
356
360
  api?: string | StreamingReactResponseAction;
357
361
  key?: string;
358
362
  }): UseChatHelpers;
@@ -401,7 +405,7 @@ type UseCompletionHelpers = {
401
405
  /** Additional data added on the server via StreamData */
402
406
  data?: JSONValue[];
403
407
  };
404
- declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
408
+ declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamMode, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
405
409
 
406
410
  type AssistantStatus = 'in_progress' | 'awaiting_message';
407
411
  type UseAssistantHelpers = {
@@ -421,6 +425,15 @@ type UseAssistantHelpers = {
421
425
  * The current value of the input field.
422
426
  */
423
427
  input: string;
428
+ /**
429
+ * Append a user message to the chat list. This triggers the API call to fetch
430
+ * the assistant's response.
431
+ * @param message The message to append
432
+ * @param requestOptions Additional options to pass to the API call
433
+ */
434
+ append: (message: Message | CreateMessage, requestOptions?: {
435
+ data?: Record<string, string>;
436
+ }) => Promise<void>;
424
437
  /**
425
438
  * setState-powered method to update the input value.
426
439
  */
@@ -474,9 +487,13 @@ type UseAssistantOptions = {
474
487
  */
475
488
  onError?: (error: Error) => void;
476
489
  };
477
- declare function experimental_useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
490
+ declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, }: UseAssistantOptions): UseAssistantHelpers;
491
+ /**
492
+ @deprecated Use `useAssistant` instead.
493
+ */
494
+ declare const experimental_useAssistant: typeof useAssistant;
478
495
 
479
- export { AssistantStatus, CreateMessage, Message, UseAssistantHelpers, UseAssistantOptions, UseChatHelpers, UseChatOptions, UseCompletionHelpers, experimental_useAssistant, useChat, useCompletion };
496
+ export { AssistantStatus, CreateMessage, Message, UseAssistantHelpers, UseAssistantOptions, UseChatHelpers, UseChatOptions, UseCompletionHelpers, UseCompletionOptions, experimental_useAssistant, useAssistant, useChat, useCompletion };
480
497
  import * as react_jsx_runtime from 'react/jsx-runtime';
481
498
 
482
499
  type Props = {
@@ -486,8 +503,10 @@ type Props = {
486
503
  stream: ReadableStream;
487
504
  };
488
505
  /**
489
- * A React Server Component that recursively renders a stream of tokens.
490
- * Can only be used inside of server components.
506
+ A React Server Component that recursively renders a stream of tokens.
507
+ Can only be used inside of server components.
508
+
509
+ @deprecated Use RSCs / Generative AI instead.
491
510
  */
492
511
  declare function Tokens(props: Props): Promise<react_jsx_runtime.JSX.Element>;
493
512