ai 3.2.24 → 3.2.25
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.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +78 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/rsc/dist/rsc-server.mjs +1 -1
- package/rsc/dist/rsc-server.mjs.map +1 -1
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
|
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 {
|
@@ -2097,13 +2104,79 @@ var StreamTextResult = class {
|
|
2097
2104
|
};
|
2098
2105
|
var experimental_streamText = streamText;
|
2099
2106
|
|
2107
|
+
// core/prompt/attachments-to-parts.ts
|
2108
|
+
function attachmentsToParts(attachments) {
|
2109
|
+
var _a, _b, _c;
|
2110
|
+
const parts = [];
|
2111
|
+
for (const attachment of attachments) {
|
2112
|
+
let url;
|
2113
|
+
try {
|
2114
|
+
url = new URL(attachment.url);
|
2115
|
+
} catch (error) {
|
2116
|
+
throw new Error(`Invalid URL: ${attachment.url}`);
|
2117
|
+
}
|
2118
|
+
switch (url.protocol) {
|
2119
|
+
case "http:":
|
2120
|
+
case "https:": {
|
2121
|
+
if ((_a = attachment.contentType) == null ? void 0 : _a.startsWith("image/")) {
|
2122
|
+
parts.push({ type: "image", image: url });
|
2123
|
+
}
|
2124
|
+
break;
|
2125
|
+
}
|
2126
|
+
case "data:": {
|
2127
|
+
let header;
|
2128
|
+
let base64Content;
|
2129
|
+
let mimeType;
|
2130
|
+
try {
|
2131
|
+
[header, base64Content] = attachment.url.split(",");
|
2132
|
+
mimeType = header.split(";")[0].split(":")[1];
|
2133
|
+
} catch (error) {
|
2134
|
+
throw new Error(`Error processing data URL: ${attachment.url}`);
|
2135
|
+
}
|
2136
|
+
if (mimeType == null || base64Content == null) {
|
2137
|
+
throw new Error(`Invalid data URL format: ${attachment.url}`);
|
2138
|
+
}
|
2139
|
+
if ((_b = attachment.contentType) == null ? void 0 : _b.startsWith("image/")) {
|
2140
|
+
parts.push({
|
2141
|
+
type: "image",
|
2142
|
+
image: convertDataContentToUint8Array(base64Content)
|
2143
|
+
});
|
2144
|
+
} else if ((_c = attachment.contentType) == null ? void 0 : _c.startsWith("text/")) {
|
2145
|
+
parts.push({
|
2146
|
+
type: "text",
|
2147
|
+
text: convertUint8ArrayToText(
|
2148
|
+
convertDataContentToUint8Array(base64Content)
|
2149
|
+
)
|
2150
|
+
});
|
2151
|
+
}
|
2152
|
+
break;
|
2153
|
+
}
|
2154
|
+
default: {
|
2155
|
+
throw new Error(`Unsupported URL protocol: ${url.protocol}`);
|
2156
|
+
}
|
2157
|
+
}
|
2158
|
+
}
|
2159
|
+
return parts;
|
2160
|
+
}
|
2161
|
+
|
2100
2162
|
// core/prompt/convert-to-core-messages.ts
|
2101
2163
|
function convertToCoreMessages(messages) {
|
2102
2164
|
const coreMessages = [];
|
2103
|
-
for (const {
|
2165
|
+
for (const {
|
2166
|
+
role,
|
2167
|
+
content,
|
2168
|
+
toolInvocations,
|
2169
|
+
experimental_attachments
|
2170
|
+
} of messages) {
|
2104
2171
|
switch (role) {
|
2105
2172
|
case "user": {
|
2106
|
-
coreMessages.push({
|
2173
|
+
coreMessages.push({
|
2174
|
+
role: "user",
|
2175
|
+
content: experimental_attachments ? [
|
2176
|
+
{ type: "text", text: content },
|
2177
|
+
...attachmentsToParts(experimental_attachments)
|
2178
|
+
] : content
|
2179
|
+
});
|
2107
2180
|
break;
|
2108
2181
|
}
|
2109
2182
|
case "assistant": {
|
@@ -3470,6 +3543,7 @@ export {
|
|
3470
3543
|
convertDataContentToBase64String,
|
3471
3544
|
convertDataContentToUint8Array,
|
3472
3545
|
convertToCoreMessages,
|
3546
|
+
convertUint8ArrayToText,
|
3473
3547
|
cosineSimilarity,
|
3474
3548
|
createCallbacksTransformer,
|
3475
3549
|
createEventStreamTransformer,
|