@gendive/chatllm 0.17.41 → 0.17.43

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.
@@ -1720,6 +1720,12 @@ var fileToBase64 = (file) => new Promise((resolve, reject) => {
1720
1720
  reader.onerror = reject;
1721
1721
  reader.readAsDataURL(file);
1722
1722
  });
1723
+ var fileToDataUri = (file) => new Promise((resolve, reject) => {
1724
+ const reader = new FileReader();
1725
+ reader.onload = () => resolve(reader.result);
1726
+ reader.onerror = reject;
1727
+ reader.readAsDataURL(file);
1728
+ });
1723
1729
  var convertAttachmentsToBase64 = async (attachments) => Promise.all(
1724
1730
  attachments.map(async (att) => ({
1725
1731
  name: att.name,
@@ -1728,6 +1734,34 @@ var convertAttachmentsToBase64 = async (attachments) => Promise.all(
1728
1734
  size: att.size
1729
1735
  }))
1730
1736
  );
1737
+ var findPreviousResultImage = (messages) => {
1738
+ for (let i = messages.length - 1; i >= 0; i--) {
1739
+ const msg = messages[i];
1740
+ if (msg.role !== "assistant") continue;
1741
+ if (msg.contentParts) {
1742
+ for (let j = msg.contentParts.length - 1; j >= 0; j--) {
1743
+ const part = msg.contentParts[j];
1744
+ if (part.type === "tool_result" && part.result?.type === "image" && part.result?.content) {
1745
+ return { name: "\uC774\uC804 \uC0DD\uC131 \uC774\uBBF8\uC9C0", url: part.result.content };
1746
+ }
1747
+ if (part.type === "image" && part.url) {
1748
+ return { name: part.alt || "\uC774\uC804 \uC774\uBBF8\uC9C0", url: part.url };
1749
+ }
1750
+ }
1751
+ }
1752
+ if (msg.skillExecution?.result?.metadata?.type === "image" && msg.skillExecution.result.content) {
1753
+ return { name: "\uC774\uC804 \uC0DD\uC131 \uC774\uBBF8\uC9C0", url: msg.skillExecution.result.content };
1754
+ }
1755
+ if (msg.checklistBlock?.items) {
1756
+ for (let j = msg.checklistBlock.items.length - 1; j >= 0; j--) {
1757
+ if (msg.checklistBlock.items[j].imageUrl) {
1758
+ return { name: "\uC774\uC804 \uC0DD\uC131 \uC774\uBBF8\uC9C0", url: msg.checklistBlock.items[j].imageUrl };
1759
+ }
1760
+ }
1761
+ }
1762
+ }
1763
+ return null;
1764
+ };
1731
1765
  var generateTitle = (messages) => {
1732
1766
  const firstUserMessage = messages.find((m) => m.role === "user");
1733
1767
  if (!firstUserMessage) return "\uC0C8 \uB300\uD654";
@@ -2551,8 +2585,9 @@ ${finalContent}`;
2551
2585
  userContentParts.push({ type: "text", content: finalContent });
2552
2586
  }
2553
2587
  for (const att of currentAttachments) {
2554
- if (att.type === "image" && att.previewUrl) {
2555
- userContentParts.push({ type: "image", url: att.previewUrl, alt: att.name });
2588
+ if (att.type === "image" && att.file) {
2589
+ const dataUri = await fileToDataUri(att.file);
2590
+ userContentParts.push({ type: "image", url: dataUri, alt: att.name });
2556
2591
  } else {
2557
2592
  userContentParts.push({ type: "file", name: att.name, url: att.previewUrl || "", mimeType: att.mimeType, size: att.size });
2558
2593
  }
@@ -2607,8 +2642,11 @@ ${finalContent}`;
2607
2642
  const attachmentSkills = Object.entries(resolvedSkills).filter(
2608
2643
  ([, config]) => config.trigger === "attachment"
2609
2644
  );
2645
+ const hasImageAtts = currentAttachments.some((a) => a.type === "image");
2646
+ const hasText = finalContent.trim().length > 0;
2647
+ const skipImageAttachmentSkill = hasImageAtts && hasText;
2610
2648
  for (const [skillName, skillConfig] of attachmentSkills) {
2611
- const matchedFiles = currentAttachments.filter((att) => {
2649
+ let matchedFiles = currentAttachments.filter((att) => {
2612
2650
  if (!skillConfig.acceptedTypes || skillConfig.acceptedTypes.length === 0) return true;
2613
2651
  return skillConfig.acceptedTypes.some((type) => {
2614
2652
  if (type.startsWith(".")) return att.name.toLowerCase().endsWith(type.toLowerCase());
@@ -2619,6 +2657,9 @@ ${finalContent}`;
2619
2657
  return att.mimeType === type;
2620
2658
  });
2621
2659
  });
2660
+ if (skipImageAttachmentSkill) {
2661
+ matchedFiles = matchedFiles.filter((att) => att.type !== "image");
2662
+ }
2622
2663
  if (matchedFiles.length === 0) continue;
2623
2664
  setSessions(
2624
2665
  (prev) => prev.map((s) => {
@@ -2702,6 +2743,18 @@ ${finalContent}`;
2702
2743
  pendingAttachmentDataRef.current = null;
2703
2744
  }
2704
2745
  }
2746
+ if (currentAttachments.length === 0 && finalContent.trim().length > 0 && !pendingAttachmentDataRef.current) {
2747
+ const previousImage = findPreviousResultImage(existingMessages);
2748
+ if (previousImage) {
2749
+ pendingAttachmentDataRef.current = [{
2750
+ name: previousImage.name,
2751
+ mimeType: "image/png",
2752
+ base64: "",
2753
+ url: previousImage.url,
2754
+ size: 0
2755
+ }];
2756
+ }
2757
+ }
2705
2758
  let shouldContinueAfterAttachment = continueAfterToolResult;
2706
2759
  if (attachmentResults.length > 0) {
2707
2760
  for (const part of attachmentResults) {
@@ -2824,6 +2877,27 @@ ${attachmentContext}
2824
2877
  });
2825
2878
  }
2826
2879
  }
2880
+ } else if (attachmentResults.length === 0 && pendingAttachmentDataRef.current !== null) {
2881
+ const isReferenceImage = pendingAttachmentDataRef.current.some((d) => d.url && !d.base64);
2882
+ if (isReferenceImage) {
2883
+ chatMessages.push({
2884
+ role: "user",
2885
+ content: `\uC774\uC804 \uB300\uD654\uC5D0\uC11C \uC0DD\uC131/\uD3B8\uC9D1\uB41C \uC774\uBBF8\uC9C0\uAC00 \uC788\uC2B5\uB2C8\uB2E4. \uC774\uBBF8\uC9C0 \uB370\uC774\uD130\uB294 \uB3C4\uAD6C \uD638\uCD9C \uC2DC \uC790\uB3D9\uC73C\uB85C \uC804\uB2EC\uB429\uB2C8\uB2E4.
2886
+
2887
+ \uC0AC\uC6A9\uC790\uAC00 \uC774 \uC774\uBBF8\uC9C0\uB97C \uAE30\uBC18\uC73C\uB85C \uCD94\uAC00 \uC791\uC5C5\uC744 \uC694\uCCAD\uD558\uB294 \uACBD\uC6B0, \uC774\uBBF8\uC9C0\uB97C \uB2E4\uC2DC \uC694\uCCAD\uD558\uC9C0 \uB9D0\uACE0 \uBC14\uB85C \uC801\uC808\uD55C \uB3C4\uAD6C\uB97C \uD638\uCD9C\uD558\uC138\uC694.`
2888
+ });
2889
+ } else {
2890
+ chatMessages.push({
2891
+ role: "user",
2892
+ content: `\uC0AC\uC6A9\uC790\uAC00 \uC774\uBBF8\uC9C0\uB97C \uCCA8\uBD80\uD588\uC2B5\uB2C8\uB2E4. \uC774\uBBF8\uC9C0 \uB370\uC774\uD130\uB294 \uB3C4\uAD6C \uD638\uCD9C \uC2DC \uC790\uB3D9\uC73C\uB85C \uC804\uB2EC\uB429\uB2C8\uB2E4.
2893
+
2894
+ \uC0AC\uC6A9\uC790\uC758 \uC694\uCCAD \uC758\uB3C4\uB97C \uD30C\uC545\uD558\uC5EC \uC801\uC808\uD55C \uB3C4\uAD6C\uB97C \uC120\uD0DD\uD558\uC138\uC694:
2895
+ - \uC774\uBBF8\uC9C0 \uBD84\uC11D/\uC124\uBA85 \uC694\uCCAD \u2192 analyze_image \uB3C4\uAD6C
2896
+ - \uC774\uBBF8\uC9C0 \uD3B8\uC9D1/\uC218\uC815 \uC694\uCCAD \u2192 edit_image \uB3C4\uAD6C
2897
+ - \uC0C8 \uC774\uBBF8\uC9C0 \uC0DD\uC131 \uC694\uCCAD \u2192 generate_image \uB3C4\uAD6C
2898
+ - \uB3C4\uAD6C \uC5C6\uC774 \uB2F5\uBCC0 \uAC00\uB2A5 \u2192 \uBC14\uB85C \uB2F5\uBCC0`
2899
+ });
2900
+ }
2827
2901
  }
2828
2902
  console.log("[ChatUI] Messages to send:", chatMessages.length, chatMessages.map((m) => ({ role: m.role, content: m.content.slice(0, 50) })));
2829
2903
  const baseSystemPrompt = buildSystemPrompt();