@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.
@@ -2184,15 +2184,22 @@ var convertAttachmentsToBase64 = async (attachments) => Promise.all(
2184
2184
  size: att.size
2185
2185
  }))
2186
2186
  );
2187
- var convertAttachmentsWithUploader = async (attachments, uploader) => Promise.all(
2188
- attachments.map(async (att) => ({
2189
- name: att.name,
2190
- mimeType: att.mimeType,
2191
- base64: "",
2192
- url: await uploader(att.file),
2193
- size: att.size,
2194
- source: "uploader"
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
- const dataUri = await fileToDataUri(att.file);
3478
- const imageUrl = onUploadImageRef.current ? await onUploadImageRef.current(dataUri, att.name) : dataUri;
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 convertAttachmentsWithUploader(matchedFiles, fileUploaderRef.current) : skillConfig.autoConvertBase64 ? await convertAttachmentsToBase64(matchedFiles) : matchedFiles;
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 convertAttachmentsWithUploader(imageAttachments, fileUploaderRef.current) : await convertAttachmentsToBase64(imageAttachments);
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;