@gendive/chatllm 0.17.42 → 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.
@@ -1734,6 +1734,34 @@ var convertAttachmentsToBase64 = async (attachments) => Promise.all(
1734
1734
  size: att.size
1735
1735
  }))
1736
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
+ };
1737
1765
  var generateTitle = (messages) => {
1738
1766
  const firstUserMessage = messages.find((m) => m.role === "user");
1739
1767
  if (!firstUserMessage) return "\uC0C8 \uB300\uD654";
@@ -2614,8 +2642,11 @@ ${finalContent}`;
2614
2642
  const attachmentSkills = Object.entries(resolvedSkills).filter(
2615
2643
  ([, config]) => config.trigger === "attachment"
2616
2644
  );
2645
+ const hasImageAtts = currentAttachments.some((a) => a.type === "image");
2646
+ const hasText = finalContent.trim().length > 0;
2647
+ const skipImageAttachmentSkill = hasImageAtts && hasText;
2617
2648
  for (const [skillName, skillConfig] of attachmentSkills) {
2618
- const matchedFiles = currentAttachments.filter((att) => {
2649
+ let matchedFiles = currentAttachments.filter((att) => {
2619
2650
  if (!skillConfig.acceptedTypes || skillConfig.acceptedTypes.length === 0) return true;
2620
2651
  return skillConfig.acceptedTypes.some((type) => {
2621
2652
  if (type.startsWith(".")) return att.name.toLowerCase().endsWith(type.toLowerCase());
@@ -2626,6 +2657,9 @@ ${finalContent}`;
2626
2657
  return att.mimeType === type;
2627
2658
  });
2628
2659
  });
2660
+ if (skipImageAttachmentSkill) {
2661
+ matchedFiles = matchedFiles.filter((att) => att.type !== "image");
2662
+ }
2629
2663
  if (matchedFiles.length === 0) continue;
2630
2664
  setSessions(
2631
2665
  (prev) => prev.map((s) => {
@@ -2709,6 +2743,18 @@ ${finalContent}`;
2709
2743
  pendingAttachmentDataRef.current = null;
2710
2744
  }
2711
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
+ }
2712
2758
  let shouldContinueAfterAttachment = continueAfterToolResult;
2713
2759
  if (attachmentResults.length > 0) {
2714
2760
  for (const part of attachmentResults) {
@@ -2831,6 +2877,27 @@ ${attachmentContext}
2831
2877
  });
2832
2878
  }
2833
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
+ }
2834
2901
  }
2835
2902
  console.log("[ChatUI] Messages to send:", chatMessages.length, chatMessages.map((m) => ({ role: m.role, content: m.content.slice(0, 50) })));
2836
2903
  const baseSystemPrompt = buildSystemPrompt();