|
| 1 | +// Types copied from the "ai" npm package so we don't need to install the entire package |
| 2 | +// filename is added to FilePart and ImagePart |
| 3 | + |
| 4 | +export type AiMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage; |
| 5 | + |
| 6 | +type JSONValue = null | string | number | boolean | JSONObject | JSONArray; |
| 7 | +type JSONObject = { |
| 8 | + [key: string]: JSONValue; |
| 9 | +}; |
| 10 | +type JSONArray = JSONValue[]; |
| 11 | + |
| 12 | +type LanguageModelV1ProviderMetadata = Record<string, Record<string, JSONValue>>; |
| 13 | +type ProviderMetadata = LanguageModelV1ProviderMetadata; |
| 14 | + |
| 15 | +/** |
| 16 | + Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer. |
| 17 | + */ |
| 18 | +type DataContent = string | Uint8Array | ArrayBuffer; |
| 19 | + |
| 20 | +/** |
| 21 | + Text content part of a prompt. It contains a string of text. |
| 22 | + */ |
| 23 | +export interface TextPart { |
| 24 | + type: 'text'; |
| 25 | + /** |
| 26 | + The text content. |
| 27 | + */ |
| 28 | + text: string; |
| 29 | + /** |
| 30 | + Additional provider-specific metadata. They are passed through |
| 31 | + to the provider from the AI SDK and enable provider-specific |
| 32 | + functionality that can be fully encapsulated in the provider. |
| 33 | + */ |
| 34 | + experimental_providerMetadata?: ProviderMetadata; |
| 35 | +} |
| 36 | +/** |
| 37 | + Image content part of a prompt. It contains an image. |
| 38 | + */ |
| 39 | +export interface ImagePart { |
| 40 | + type: 'image'; |
| 41 | + /** |
| 42 | + Image data. Can either be: |
| 43 | +
|
| 44 | + - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer |
| 45 | + - URL: a URL that points to the image |
| 46 | + */ |
| 47 | + image: DataContent | URL; |
| 48 | + /** |
| 49 | + Optional mime type of the image. |
| 50 | + */ |
| 51 | + mimeType?: string; |
| 52 | + /** File name */ |
| 53 | + filename: string; |
| 54 | + /** |
| 55 | + Additional provider-specific metadata. They are passed through |
| 56 | + to the provider from the AI SDK and enable provider-specific |
| 57 | + functionality that can be fully encapsulated in the provider. |
| 58 | + */ |
| 59 | + experimental_providerMetadata?: ProviderMetadata; |
| 60 | +} |
| 61 | +/** |
| 62 | + File content part of a prompt. It contains a file. |
| 63 | + */ |
| 64 | +export interface FilePart { |
| 65 | + type: 'file'; |
| 66 | + /** |
| 67 | + File data. Can either be: |
| 68 | +
|
| 69 | + - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer |
| 70 | + - URL: a URL that points to the image |
| 71 | + */ |
| 72 | + data: DataContent | URL; |
| 73 | + /** |
| 74 | + Mime type of the file. |
| 75 | + */ |
| 76 | + mimeType: string; |
| 77 | + /** File name */ |
| 78 | + filename: string; |
| 79 | + /** |
| 80 | + Additional provider-specific metadata. They are passed through |
| 81 | + to the provider from the AI SDK and enable provider-specific |
| 82 | + functionality that can be fully encapsulated in the provider. |
| 83 | + */ |
| 84 | + experimental_providerMetadata?: ProviderMetadata; |
| 85 | +} |
| 86 | + |
| 87 | +type ToolResultContent = Array<{ |
| 88 | + type: 'text'; |
| 89 | + text: string; |
| 90 | +} | { |
| 91 | + type: 'image'; |
| 92 | + data: string; |
| 93 | + mimeType?: string; |
| 94 | +}>; |
| 95 | +/** |
| 96 | + Tool call content part of a prompt. It contains a tool call (usually generated by the AI model). |
| 97 | + */ |
| 98 | +export interface ToolCallPart { |
| 99 | + type: 'tool-call'; |
| 100 | + /** |
| 101 | + ID of the tool call. This ID is used to match the tool call with the tool result. |
| 102 | + */ |
| 103 | + toolCallId: string; |
| 104 | + /** |
| 105 | + Name of the tool that is being called. |
| 106 | + */ |
| 107 | + toolName: string; |
| 108 | + /** |
| 109 | + Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema. |
| 110 | + */ |
| 111 | + args: unknown; |
| 112 | + /** |
| 113 | + Additional provider-specific metadata. They are passed through |
| 114 | + to the provider from the AI SDK and enable provider-specific |
| 115 | + functionality that can be fully encapsulated in the provider. |
| 116 | + */ |
| 117 | + experimental_providerMetadata?: ProviderMetadata; |
| 118 | +} |
| 119 | +/** |
| 120 | + Tool result content part of a prompt. It contains the result of the tool call with the matching ID. |
| 121 | + */ |
| 122 | +interface ToolResultPart { |
| 123 | + type: 'tool-result'; |
| 124 | + /** |
| 125 | + ID of the tool call that this result is associated with. |
| 126 | + */ |
| 127 | + toolCallId: string; |
| 128 | + /** |
| 129 | + Name of the tool that generated this result. |
| 130 | + */ |
| 131 | + toolName: string; |
| 132 | + /** |
| 133 | + Result of the tool call. This is a JSON-serializable object. |
| 134 | + */ |
| 135 | + result: unknown; |
| 136 | + /** |
| 137 | + Multi-part content of the tool result. Only for tools that support multipart results. |
| 138 | + */ |
| 139 | + experimental_content?: ToolResultContent; |
| 140 | + /** |
| 141 | + Optional flag if the result is an error or an error message. |
| 142 | + */ |
| 143 | + isError?: boolean; |
| 144 | + /** |
| 145 | + Additional provider-specific metadata. They are passed through |
| 146 | + to the provider from the AI SDK and enable provider-specific |
| 147 | + functionality that can be fully encapsulated in the provider. |
| 148 | + */ |
| 149 | + experimental_providerMetadata?: ProviderMetadata; |
| 150 | +} |
| 151 | + |
| 152 | +/** |
| 153 | + A system message. It can contain system information. |
| 154 | +
|
| 155 | + Note: using the "system" part of the prompt is strongly preferred |
| 156 | + to increase the resilience against prompt injection attacks, |
| 157 | + and because not all providers support several system messages. |
| 158 | + */ |
| 159 | +type CoreSystemMessage = { |
| 160 | + role: 'system'; |
| 161 | + content: string; |
| 162 | + /** |
| 163 | + Additional provider-specific metadata. They are passed through |
| 164 | + to the provider from the AI SDK and enable provider-specific |
| 165 | + functionality that can be fully encapsulated in the provider. |
| 166 | + */ |
| 167 | + experimental_providerMetadata?: ProviderMetadata; |
| 168 | +}; |
| 169 | +/** |
| 170 | + A user message. It can contain text or a combination of text and images. |
| 171 | + */ |
| 172 | +type CoreUserMessage = { |
| 173 | + role: 'user'; |
| 174 | + content: UserContent; |
| 175 | + /** |
| 176 | + Additional provider-specific metadata. They are passed through |
| 177 | + to the provider from the AI SDK and enable provider-specific |
| 178 | + functionality that can be fully encapsulated in the provider. |
| 179 | + */ |
| 180 | + experimental_providerMetadata?: ProviderMetadata; |
| 181 | +}; |
| 182 | +/** |
| 183 | + Content of a user message. It can be a string or an array of text and image parts. |
| 184 | + */ |
| 185 | +type UserContent = string | Array<TextPart | ImagePart | FilePart>; |
| 186 | +/** |
| 187 | + An assistant message. It can contain text, tool calls, or a combination of text and tool calls. |
| 188 | + */ |
| 189 | +type CoreAssistantMessage = { |
| 190 | + role: 'assistant'; |
| 191 | + content: AssistantContent; |
| 192 | + /** |
| 193 | + Additional provider-specific metadata. They are passed through |
| 194 | + to the provider from the AI SDK and enable provider-specific |
| 195 | + functionality that can be fully encapsulated in the provider. |
| 196 | + */ |
| 197 | + experimental_providerMetadata?: ProviderMetadata; |
| 198 | +}; |
| 199 | +/** |
| 200 | + Content of an assistant message. It can be a string or an array of text and tool call parts. |
| 201 | + */ |
| 202 | +type AssistantContent = string | Array<TextPart | ToolCallPart>; |
| 203 | +/** |
| 204 | + A tool message. It contains the result of one or more tool calls. |
| 205 | + */ |
| 206 | +type CoreToolMessage = { |
| 207 | + role: 'tool'; |
| 208 | + content: ToolContent; |
| 209 | + /** |
| 210 | + Additional provider-specific metadata. They are passed through |
| 211 | + to the provider from the AI SDK and enable provider-specific |
| 212 | + functionality that can be fully encapsulated in the provider. |
| 213 | + */ |
| 214 | + experimental_providerMetadata?: ProviderMetadata; |
| 215 | +}; |
| 216 | +/** |
| 217 | + Content of a tool message. It is an array of tool result parts. |
| 218 | + */ |
| 219 | +type ToolContent = Array<ToolResultPart>; |
| 220 | +/** |
| 221 | + A message that can be used in the `messages` field of a prompt. |
| 222 | + It can be a user message, an assistant message, or a tool message. |
| 223 | + */ |
| 224 | +type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage; |
0 commit comments