ai 3.2.24 → 3.2.26

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.
package/dist/index.mjs CHANGED
@@ -201,7 +201,7 @@ function convertDataContentToUint8Array(content) {
201
201
  return convertBase64ToUint8Array(content);
202
202
  } catch (error) {
203
203
  throw new InvalidDataContentError({
204
- message: "Invalid data content. Content string is not a base64-encoded image.",
204
+ message: "Invalid data content. Content string is not a base64-encoded media.",
205
205
  content,
206
206
  cause: error
207
207
  });
@@ -212,6 +212,13 @@ function convertDataContentToUint8Array(content) {
212
212
  }
213
213
  throw new InvalidDataContentError({ content });
214
214
  }
215
+ function convertUint8ArrayToText(uint8Array) {
216
+ try {
217
+ return new TextDecoder().decode(uint8Array);
218
+ } catch (error) {
219
+ throw new Error("Error decoding Uint8Array to text");
220
+ }
221
+ }
215
222
 
216
223
  // core/prompt/invalid-message-role-error.ts
217
224
  var InvalidMessageRoleError = class extends Error {
@@ -620,7 +627,8 @@ async function generateObject({
620
627
  ...prepareCallSettings(settings),
621
628
  inputFormat: validatedPrompt.type,
622
629
  prompt: convertToLanguageModelPrompt(validatedPrompt),
623
- abortSignal
630
+ abortSignal,
631
+ headers
624
632
  })
625
633
  );
626
634
  if (generateResult.text === void 0) {
@@ -654,7 +662,8 @@ async function generateObject({
654
662
  ...prepareCallSettings(settings),
655
663
  inputFormat: validatedPrompt.type,
656
664
  prompt: convertToLanguageModelPrompt(validatedPrompt),
657
- abortSignal
665
+ abortSignal,
666
+ headers
658
667
  })
659
668
  );
660
669
  const functionArgs = (_b = (_a = generateResult.toolCalls) == null ? void 0 : _a[0]) == null ? void 0 : _b.args;
@@ -2097,13 +2106,79 @@ var StreamTextResult = class {
2097
2106
  };
2098
2107
  var experimental_streamText = streamText;
2099
2108
 
2109
+ // core/prompt/attachments-to-parts.ts
2110
+ function attachmentsToParts(attachments) {
2111
+ var _a, _b, _c;
2112
+ const parts = [];
2113
+ for (const attachment of attachments) {
2114
+ let url;
2115
+ try {
2116
+ url = new URL(attachment.url);
2117
+ } catch (error) {
2118
+ throw new Error(`Invalid URL: ${attachment.url}`);
2119
+ }
2120
+ switch (url.protocol) {
2121
+ case "http:":
2122
+ case "https:": {
2123
+ if ((_a = attachment.contentType) == null ? void 0 : _a.startsWith("image/")) {
2124
+ parts.push({ type: "image", image: url });
2125
+ }
2126
+ break;
2127
+ }
2128
+ case "data:": {
2129
+ let header;
2130
+ let base64Content;
2131
+ let mimeType;
2132
+ try {
2133
+ [header, base64Content] = attachment.url.split(",");
2134
+ mimeType = header.split(";")[0].split(":")[1];
2135
+ } catch (error) {
2136
+ throw new Error(`Error processing data URL: ${attachment.url}`);
2137
+ }
2138
+ if (mimeType == null || base64Content == null) {
2139
+ throw new Error(`Invalid data URL format: ${attachment.url}`);
2140
+ }
2141
+ if ((_b = attachment.contentType) == null ? void 0 : _b.startsWith("image/")) {
2142
+ parts.push({
2143
+ type: "image",
2144
+ image: convertDataContentToUint8Array(base64Content)
2145
+ });
2146
+ } else if ((_c = attachment.contentType) == null ? void 0 : _c.startsWith("text/")) {
2147
+ parts.push({
2148
+ type: "text",
2149
+ text: convertUint8ArrayToText(
2150
+ convertDataContentToUint8Array(base64Content)
2151
+ )
2152
+ });
2153
+ }
2154
+ break;
2155
+ }
2156
+ default: {
2157
+ throw new Error(`Unsupported URL protocol: ${url.protocol}`);
2158
+ }
2159
+ }
2160
+ }
2161
+ return parts;
2162
+ }
2163
+
2100
2164
  // core/prompt/convert-to-core-messages.ts
2101
2165
  function convertToCoreMessages(messages) {
2102
2166
  const coreMessages = [];
2103
- for (const { role, content, toolInvocations } of messages) {
2167
+ for (const {
2168
+ role,
2169
+ content,
2170
+ toolInvocations,
2171
+ experimental_attachments
2172
+ } of messages) {
2104
2173
  switch (role) {
2105
2174
  case "user": {
2106
- coreMessages.push({ role: "user", content });
2175
+ coreMessages.push({
2176
+ role: "user",
2177
+ content: experimental_attachments ? [
2178
+ { type: "text", text: content },
2179
+ ...attachmentsToParts(experimental_attachments)
2180
+ ] : content
2181
+ });
2107
2182
  break;
2108
2183
  }
2109
2184
  case "assistant": {
@@ -3470,6 +3545,7 @@ export {
3470
3545
  convertDataContentToBase64String,
3471
3546
  convertDataContentToUint8Array,
3472
3547
  convertToCoreMessages,
3548
+ convertUint8ArrayToText,
3473
3549
  cosineSimilarity,
3474
3550
  createCallbacksTransformer,
3475
3551
  createEventStreamTransformer,