@gendive/chatllm 0.21.8 → 0.22.0

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,6 +2184,16 @@ 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
+ }))
2196
+ );
2187
2197
  var findPreviousResultImage = (messages) => {
2188
2198
  for (let i = messages.length - 1; i >= 0; i--) {
2189
2199
  const msg = messages[i];
@@ -2245,6 +2255,8 @@ var useChatUI = (options) => {
2245
2255
  // Image upload
2246
2256
  onUploadImage,
2247
2257
  onImageError,
2258
+ // File upload
2259
+ fileUploader,
2248
2260
  // External storage options
2249
2261
  useExternalStorage = false,
2250
2262
  startWithNewSession = false,
@@ -2352,6 +2364,7 @@ var useChatUI = (options) => {
2352
2364
  const onLoadModelsRef = useRef5(onLoadModels);
2353
2365
  const onUploadImageRef = useRef5(onUploadImage);
2354
2366
  const onImageErrorRef = useRef5(onImageError);
2367
+ const fileUploaderRef = useRef5(fileUploader);
2355
2368
  const globalMemoryRef = useRef5(null);
2356
2369
  useEffect4(() => {
2357
2370
  onSendMessageRef.current = onSendMessage;
@@ -2373,6 +2386,7 @@ var useChatUI = (options) => {
2373
2386
  onSessionContextChangeRef.current = onSessionContextChange;
2374
2387
  onUploadImageRef.current = onUploadImage;
2375
2388
  onImageErrorRef.current = onImageError;
2389
+ fileUploaderRef.current = fileUploader;
2376
2390
  onLoadModelsRef.current = onLoadModels;
2377
2391
  });
2378
2392
  const abortControllersRef = useRef5(/* @__PURE__ */ new Map());
@@ -3560,7 +3574,7 @@ ${finalContent}`;
3560
3574
  })
3561
3575
  );
3562
3576
  try {
3563
- const filesToPass = skillConfig.autoConvertBase64 ? await convertAttachmentsToBase64(matchedFiles) : matchedFiles;
3577
+ const filesToPass = fileUploaderRef.current ? await convertAttachmentsWithUploader(matchedFiles, fileUploaderRef.current) : skillConfig.autoConvertBase64 ? await convertAttachmentsToBase64(matchedFiles) : matchedFiles;
3564
3578
  const result = await skillConfig.execute({ files: filesToPass, userMessage: finalContent });
3565
3579
  const attachResultType = result.metadata?.type || result.metadata?.resultType || "text";
3566
3580
  const toolResultPart = {
@@ -3618,7 +3632,12 @@ ${finalContent}`;
3618
3632
  const hasUserText = finalContent.trim().length > 0;
3619
3633
  if (hasImageAttachments && hasUserText) {
3620
3634
  const imageAttachments = currentAttachments.filter((a) => a.type === "image");
3621
- pendingAttachmentDataRef.current = await convertAttachmentsToBase64(imageAttachments);
3635
+ try {
3636
+ pendingAttachmentDataRef.current = fileUploaderRef.current ? await convertAttachmentsWithUploader(imageAttachments, fileUploaderRef.current) : await convertAttachmentsToBase64(imageAttachments);
3637
+ } catch (err) {
3638
+ console.error("[chatllm] pendingAttachment conversion failed:", err);
3639
+ pendingAttachmentDataRef.current = null;
3640
+ }
3622
3641
  } else {
3623
3642
  pendingAttachmentDataRef.current = null;
3624
3643
  }
@@ -3766,7 +3785,9 @@ ${attachmentContext}
3766
3785
  }
3767
3786
  }
3768
3787
  } else if (attachmentResults.length === 0 && pendingAttachmentDataRef.current !== null) {
3769
- const isReferenceImage = pendingAttachmentDataRef.current.some((d) => d.url && !d.base64);
3788
+ const isReferenceImage = pendingAttachmentDataRef.current.some(
3789
+ (d) => d.url && !d.base64 && d.source !== "uploader"
3790
+ );
3770
3791
  if (isReferenceImage) {
3771
3792
  chatMessages.push({
3772
3793
  role: "user",
@@ -6495,9 +6516,9 @@ var ImageWithCopyButton = ({ src, alt, imageKey }) => {
6495
6516
  console.log("Canvas method failed (CORS), trying fetch...");
6496
6517
  }
6497
6518
  }
6498
- if (!src.startsWith("data:")) {
6519
+ if (!imgSrc.startsWith("data:")) {
6499
6520
  try {
6500
- const response = await fetch(src, { mode: "cors" });
6521
+ const response = await fetch(imgSrc, { mode: "cors" });
6501
6522
  if (response.ok) {
6502
6523
  const blob = await response.blob();
6503
6524
  if (blob.type === "image/png") return blob;
@@ -6537,7 +6558,7 @@ var ImageWithCopyButton = ({ src, alt, imageKey }) => {
6537
6558
  setCopyState("copying");
6538
6559
  try {
6539
6560
  if (!navigator.clipboard?.write) {
6540
- await navigator.clipboard.writeText(src);
6561
+ await navigator.clipboard.writeText(imgSrc);
6541
6562
  setCopyState("copied");
6542
6563
  setTimeout(() => setCopyState("idle"), 2e3);
6543
6564
  return;
@@ -6547,7 +6568,7 @@ var ImageWithCopyButton = ({ src, alt, imageKey }) => {
6547
6568
  await navigator.clipboard.write([new ClipboardItem({ "image/png": blob })]);
6548
6569
  setCopyState("copied");
6549
6570
  } else {
6550
- await navigator.clipboard.writeText(src);
6571
+ await navigator.clipboard.writeText(imgSrc);
6551
6572
  setCopyState("copied");
6552
6573
  }
6553
6574
  setTimeout(() => setCopyState("idle"), 2e3);
@@ -6560,7 +6581,7 @@ var ImageWithCopyButton = ({ src, alt, imageKey }) => {
6560
6581
  const handleDownload = async () => {
6561
6582
  try {
6562
6583
  const blob = await getImageBlob();
6563
- const url = blob ? URL.createObjectURL(blob) : src;
6584
+ const url = blob ? URL.createObjectURL(blob) : imgSrc;
6564
6585
  const link = document.createElement("a");
6565
6586
  link.href = url;
6566
6587
  link.download = alt || `image-${Date.now()}.png`;
@@ -6570,7 +6591,7 @@ var ImageWithCopyButton = ({ src, alt, imageKey }) => {
6570
6591
  if (blob) URL.revokeObjectURL(url);
6571
6592
  } catch (error) {
6572
6593
  console.error("Failed to download image:", error);
6573
- window.open(src, "_blank");
6594
+ window.open(imgSrc, "_blank");
6574
6595
  }
6575
6596
  };
6576
6597
  return /* @__PURE__ */ jsxs2(
@@ -15077,7 +15098,9 @@ var ChatUIWithHook = ({
15077
15098
  onAnalyzePatterns,
15078
15099
  // Image upload
15079
15100
  onUploadImage,
15080
- onImageError
15101
+ onImageError,
15102
+ // File upload
15103
+ fileUploader
15081
15104
  }) => {
15082
15105
  const hookOptions = {
15083
15106
  models,
@@ -15128,7 +15151,9 @@ var ChatUIWithHook = ({
15128
15151
  onAnalyzePatterns,
15129
15152
  // Image upload
15130
15153
  onUploadImage,
15131
- onImageError
15154
+ onImageError,
15155
+ // File upload
15156
+ fileUploader
15132
15157
  };
15133
15158
  const state = useChatUI(hookOptions);
15134
15159
  return /* @__PURE__ */ jsx23(ImageErrorContext.Provider, { value: onImageError || null, children: /* @__PURE__ */ jsx23(