@gendive/chatllm 0.22.0 → 0.22.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.
- package/dist/react/index.js +32 -13
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +32 -13
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -2184,15 +2184,22 @@ var convertAttachmentsToBase64 = async (attachments) => Promise.all(
|
|
|
2184
2184
|
size: att.size
|
|
2185
2185
|
}))
|
|
2186
2186
|
);
|
|
2187
|
-
var
|
|
2188
|
-
attachments.map(async (att) =>
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2187
|
+
var convertAttachmentsWithUploaderCached = async (attachments, uploader, cache) => Promise.all(
|
|
2188
|
+
attachments.map(async (att) => {
|
|
2189
|
+
let url = cache.get(att.id);
|
|
2190
|
+
if (!url) {
|
|
2191
|
+
url = await uploader(att.file);
|
|
2192
|
+
cache.set(att.id, url);
|
|
2193
|
+
}
|
|
2194
|
+
return {
|
|
2195
|
+
name: att.name,
|
|
2196
|
+
mimeType: att.mimeType,
|
|
2197
|
+
base64: "",
|
|
2198
|
+
url,
|
|
2199
|
+
size: att.size,
|
|
2200
|
+
source: "uploader"
|
|
2201
|
+
};
|
|
2202
|
+
})
|
|
2196
2203
|
);
|
|
2197
2204
|
var findPreviousResultImage = (messages) => {
|
|
2198
2205
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
@@ -3466,6 +3473,7 @@ ${finalContent}`;
|
|
|
3466
3473
|
const actionPrompt = selectedAction?.systemPrompt;
|
|
3467
3474
|
const isHidden = options2?.hiddenUserMessage ?? false;
|
|
3468
3475
|
const currentAttachments = attachments;
|
|
3476
|
+
const uploadedUrlMap = /* @__PURE__ */ new Map();
|
|
3469
3477
|
let userContentParts;
|
|
3470
3478
|
if (currentAttachments.length > 0) {
|
|
3471
3479
|
userContentParts = [];
|
|
@@ -3474,8 +3482,19 @@ ${finalContent}`;
|
|
|
3474
3482
|
}
|
|
3475
3483
|
for (const att of currentAttachments) {
|
|
3476
3484
|
if (att.type === "image" && att.file) {
|
|
3477
|
-
|
|
3478
|
-
|
|
3485
|
+
let imageUrl;
|
|
3486
|
+
try {
|
|
3487
|
+
if (fileUploaderRef.current) {
|
|
3488
|
+
imageUrl = await fileUploaderRef.current(att.file);
|
|
3489
|
+
} else {
|
|
3490
|
+
const dataUri = await fileToDataUri(att.file);
|
|
3491
|
+
imageUrl = onUploadImageRef.current ? await onUploadImageRef.current(dataUri, att.name) : dataUri;
|
|
3492
|
+
}
|
|
3493
|
+
} catch (err) {
|
|
3494
|
+
console.error("[chatllm] image upload failed, falling back to data URI:", err);
|
|
3495
|
+
imageUrl = await fileToDataUri(att.file);
|
|
3496
|
+
}
|
|
3497
|
+
uploadedUrlMap.set(att.id, imageUrl);
|
|
3479
3498
|
userContentParts.push({ type: "image", url: imageUrl, alt: att.name, fileName: att.name });
|
|
3480
3499
|
} else {
|
|
3481
3500
|
userContentParts.push({ type: "file", name: att.name, url: att.previewUrl || "", mimeType: att.mimeType, size: att.size });
|
|
@@ -3574,7 +3593,7 @@ ${finalContent}`;
|
|
|
3574
3593
|
})
|
|
3575
3594
|
);
|
|
3576
3595
|
try {
|
|
3577
|
-
const filesToPass = fileUploaderRef.current ? await
|
|
3596
|
+
const filesToPass = fileUploaderRef.current ? await convertAttachmentsWithUploaderCached(matchedFiles, fileUploaderRef.current, uploadedUrlMap) : skillConfig.autoConvertBase64 ? await convertAttachmentsToBase64(matchedFiles) : matchedFiles;
|
|
3578
3597
|
const result = await skillConfig.execute({ files: filesToPass, userMessage: finalContent });
|
|
3579
3598
|
const attachResultType = result.metadata?.type || result.metadata?.resultType || "text";
|
|
3580
3599
|
const toolResultPart = {
|
|
@@ -3633,7 +3652,7 @@ ${finalContent}`;
|
|
|
3633
3652
|
if (hasImageAttachments && hasUserText) {
|
|
3634
3653
|
const imageAttachments = currentAttachments.filter((a) => a.type === "image");
|
|
3635
3654
|
try {
|
|
3636
|
-
pendingAttachmentDataRef.current = fileUploaderRef.current ? await
|
|
3655
|
+
pendingAttachmentDataRef.current = fileUploaderRef.current ? await convertAttachmentsWithUploaderCached(imageAttachments, fileUploaderRef.current, uploadedUrlMap) : await convertAttachmentsToBase64(imageAttachments);
|
|
3637
3656
|
} catch (err) {
|
|
3638
3657
|
console.error("[chatllm] pendingAttachment conversion failed:", err);
|
|
3639
3658
|
pendingAttachmentDataRef.current = null;
|