@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.
@@ -2269,15 +2269,22 @@ var convertAttachmentsToBase64 = async (attachments) => Promise.all(
2269
2269
  size: att.size
2270
2270
  }))
2271
2271
  );
2272
- var convertAttachmentsWithUploader = async (attachments, uploader) => Promise.all(
2273
- attachments.map(async (att) => ({
2274
- name: att.name,
2275
- mimeType: att.mimeType,
2276
- base64: "",
2277
- url: await uploader(att.file),
2278
- size: att.size,
2279
- source: "uploader"
2280
- }))
2272
+ var convertAttachmentsWithUploaderCached = async (attachments, uploader, cache) => Promise.all(
2273
+ attachments.map(async (att) => {
2274
+ let url = cache.get(att.id);
2275
+ if (!url) {
2276
+ url = await uploader(att.file);
2277
+ cache.set(att.id, url);
2278
+ }
2279
+ return {
2280
+ name: att.name,
2281
+ mimeType: att.mimeType,
2282
+ base64: "",
2283
+ url,
2284
+ size: att.size,
2285
+ source: "uploader"
2286
+ };
2287
+ })
2281
2288
  );
2282
2289
  var findPreviousResultImage = (messages) => {
2283
2290
  for (let i = messages.length - 1; i >= 0; i--) {
@@ -3551,6 +3558,7 @@ ${finalContent}`;
3551
3558
  const actionPrompt = selectedAction?.systemPrompt;
3552
3559
  const isHidden = options2?.hiddenUserMessage ?? false;
3553
3560
  const currentAttachments = attachments;
3561
+ const uploadedUrlMap = /* @__PURE__ */ new Map();
3554
3562
  let userContentParts;
3555
3563
  if (currentAttachments.length > 0) {
3556
3564
  userContentParts = [];
@@ -3559,8 +3567,19 @@ ${finalContent}`;
3559
3567
  }
3560
3568
  for (const att of currentAttachments) {
3561
3569
  if (att.type === "image" && att.file) {
3562
- const dataUri = await fileToDataUri(att.file);
3563
- const imageUrl = onUploadImageRef.current ? await onUploadImageRef.current(dataUri, att.name) : dataUri;
3570
+ let imageUrl;
3571
+ try {
3572
+ if (fileUploaderRef.current) {
3573
+ imageUrl = await fileUploaderRef.current(att.file);
3574
+ } else {
3575
+ const dataUri = await fileToDataUri(att.file);
3576
+ imageUrl = onUploadImageRef.current ? await onUploadImageRef.current(dataUri, att.name) : dataUri;
3577
+ }
3578
+ } catch (err) {
3579
+ console.error("[chatllm] image upload failed, falling back to data URI:", err);
3580
+ imageUrl = await fileToDataUri(att.file);
3581
+ }
3582
+ uploadedUrlMap.set(att.id, imageUrl);
3564
3583
  userContentParts.push({ type: "image", url: imageUrl, alt: att.name, fileName: att.name });
3565
3584
  } else {
3566
3585
  userContentParts.push({ type: "file", name: att.name, url: att.previewUrl || "", mimeType: att.mimeType, size: att.size });
@@ -3659,7 +3678,7 @@ ${finalContent}`;
3659
3678
  })
3660
3679
  );
3661
3680
  try {
3662
- const filesToPass = fileUploaderRef.current ? await convertAttachmentsWithUploader(matchedFiles, fileUploaderRef.current) : skillConfig.autoConvertBase64 ? await convertAttachmentsToBase64(matchedFiles) : matchedFiles;
3681
+ const filesToPass = fileUploaderRef.current ? await convertAttachmentsWithUploaderCached(matchedFiles, fileUploaderRef.current, uploadedUrlMap) : skillConfig.autoConvertBase64 ? await convertAttachmentsToBase64(matchedFiles) : matchedFiles;
3663
3682
  const result = await skillConfig.execute({ files: filesToPass, userMessage: finalContent });
3664
3683
  const attachResultType = result.metadata?.type || result.metadata?.resultType || "text";
3665
3684
  const toolResultPart = {
@@ -3718,7 +3737,7 @@ ${finalContent}`;
3718
3737
  if (hasImageAttachments && hasUserText) {
3719
3738
  const imageAttachments = currentAttachments.filter((a) => a.type === "image");
3720
3739
  try {
3721
- pendingAttachmentDataRef.current = fileUploaderRef.current ? await convertAttachmentsWithUploader(imageAttachments, fileUploaderRef.current) : await convertAttachmentsToBase64(imageAttachments);
3740
+ pendingAttachmentDataRef.current = fileUploaderRef.current ? await convertAttachmentsWithUploaderCached(imageAttachments, fileUploaderRef.current, uploadedUrlMap) : await convertAttachmentsToBase64(imageAttachments);
3722
3741
  } catch (err) {
3723
3742
  console.error("[chatllm] pendingAttachment conversion failed:", err);
3724
3743
  pendingAttachmentDataRef.current = null;