@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.
- package/dist/react/index.js +77 -3
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +77 -3
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -1651,6 +1651,12 @@ var fileToBase64 = (file) => new Promise((resolve, reject) => {
|
|
|
1651
1651
|
reader.onerror = reject;
|
|
1652
1652
|
reader.readAsDataURL(file);
|
|
1653
1653
|
});
|
|
1654
|
+
var fileToDataUri = (file) => new Promise((resolve, reject) => {
|
|
1655
|
+
const reader = new FileReader();
|
|
1656
|
+
reader.onload = () => resolve(reader.result);
|
|
1657
|
+
reader.onerror = reject;
|
|
1658
|
+
reader.readAsDataURL(file);
|
|
1659
|
+
});
|
|
1654
1660
|
var convertAttachmentsToBase64 = async (attachments) => Promise.all(
|
|
1655
1661
|
attachments.map(async (att) => ({
|
|
1656
1662
|
name: att.name,
|
|
@@ -1659,6 +1665,34 @@ var convertAttachmentsToBase64 = async (attachments) => Promise.all(
|
|
|
1659
1665
|
size: att.size
|
|
1660
1666
|
}))
|
|
1661
1667
|
);
|
|
1668
|
+
var findPreviousResultImage = (messages) => {
|
|
1669
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1670
|
+
const msg = messages[i];
|
|
1671
|
+
if (msg.role !== "assistant") continue;
|
|
1672
|
+
if (msg.contentParts) {
|
|
1673
|
+
for (let j = msg.contentParts.length - 1; j >= 0; j--) {
|
|
1674
|
+
const part = msg.contentParts[j];
|
|
1675
|
+
if (part.type === "tool_result" && part.result?.type === "image" && part.result?.content) {
|
|
1676
|
+
return { name: "\uC774\uC804 \uC0DD\uC131 \uC774\uBBF8\uC9C0", url: part.result.content };
|
|
1677
|
+
}
|
|
1678
|
+
if (part.type === "image" && part.url) {
|
|
1679
|
+
return { name: part.alt || "\uC774\uC804 \uC774\uBBF8\uC9C0", url: part.url };
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
if (msg.skillExecution?.result?.metadata?.type === "image" && msg.skillExecution.result.content) {
|
|
1684
|
+
return { name: "\uC774\uC804 \uC0DD\uC131 \uC774\uBBF8\uC9C0", url: msg.skillExecution.result.content };
|
|
1685
|
+
}
|
|
1686
|
+
if (msg.checklistBlock?.items) {
|
|
1687
|
+
for (let j = msg.checklistBlock.items.length - 1; j >= 0; j--) {
|
|
1688
|
+
if (msg.checklistBlock.items[j].imageUrl) {
|
|
1689
|
+
return { name: "\uC774\uC804 \uC0DD\uC131 \uC774\uBBF8\uC9C0", url: msg.checklistBlock.items[j].imageUrl };
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
return null;
|
|
1695
|
+
};
|
|
1662
1696
|
var generateTitle = (messages) => {
|
|
1663
1697
|
const firstUserMessage = messages.find((m) => m.role === "user");
|
|
1664
1698
|
if (!firstUserMessage) return "\uC0C8 \uB300\uD654";
|
|
@@ -2482,8 +2516,9 @@ ${finalContent}`;
|
|
|
2482
2516
|
userContentParts.push({ type: "text", content: finalContent });
|
|
2483
2517
|
}
|
|
2484
2518
|
for (const att of currentAttachments) {
|
|
2485
|
-
if (att.type === "image" && att.
|
|
2486
|
-
|
|
2519
|
+
if (att.type === "image" && att.file) {
|
|
2520
|
+
const dataUri = await fileToDataUri(att.file);
|
|
2521
|
+
userContentParts.push({ type: "image", url: dataUri, alt: att.name });
|
|
2487
2522
|
} else {
|
|
2488
2523
|
userContentParts.push({ type: "file", name: att.name, url: att.previewUrl || "", mimeType: att.mimeType, size: att.size });
|
|
2489
2524
|
}
|
|
@@ -2538,8 +2573,11 @@ ${finalContent}`;
|
|
|
2538
2573
|
const attachmentSkills = Object.entries(resolvedSkills).filter(
|
|
2539
2574
|
([, config]) => config.trigger === "attachment"
|
|
2540
2575
|
);
|
|
2576
|
+
const hasImageAtts = currentAttachments.some((a) => a.type === "image");
|
|
2577
|
+
const hasText = finalContent.trim().length > 0;
|
|
2578
|
+
const skipImageAttachmentSkill = hasImageAtts && hasText;
|
|
2541
2579
|
for (const [skillName, skillConfig] of attachmentSkills) {
|
|
2542
|
-
|
|
2580
|
+
let matchedFiles = currentAttachments.filter((att) => {
|
|
2543
2581
|
if (!skillConfig.acceptedTypes || skillConfig.acceptedTypes.length === 0) return true;
|
|
2544
2582
|
return skillConfig.acceptedTypes.some((type) => {
|
|
2545
2583
|
if (type.startsWith(".")) return att.name.toLowerCase().endsWith(type.toLowerCase());
|
|
@@ -2550,6 +2588,9 @@ ${finalContent}`;
|
|
|
2550
2588
|
return att.mimeType === type;
|
|
2551
2589
|
});
|
|
2552
2590
|
});
|
|
2591
|
+
if (skipImageAttachmentSkill) {
|
|
2592
|
+
matchedFiles = matchedFiles.filter((att) => att.type !== "image");
|
|
2593
|
+
}
|
|
2553
2594
|
if (matchedFiles.length === 0) continue;
|
|
2554
2595
|
setSessions(
|
|
2555
2596
|
(prev) => prev.map((s) => {
|
|
@@ -2633,6 +2674,18 @@ ${finalContent}`;
|
|
|
2633
2674
|
pendingAttachmentDataRef.current = null;
|
|
2634
2675
|
}
|
|
2635
2676
|
}
|
|
2677
|
+
if (currentAttachments.length === 0 && finalContent.trim().length > 0 && !pendingAttachmentDataRef.current) {
|
|
2678
|
+
const previousImage = findPreviousResultImage(existingMessages);
|
|
2679
|
+
if (previousImage) {
|
|
2680
|
+
pendingAttachmentDataRef.current = [{
|
|
2681
|
+
name: previousImage.name,
|
|
2682
|
+
mimeType: "image/png",
|
|
2683
|
+
base64: "",
|
|
2684
|
+
url: previousImage.url,
|
|
2685
|
+
size: 0
|
|
2686
|
+
}];
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2636
2689
|
let shouldContinueAfterAttachment = continueAfterToolResult;
|
|
2637
2690
|
if (attachmentResults.length > 0) {
|
|
2638
2691
|
for (const part of attachmentResults) {
|
|
@@ -2755,6 +2808,27 @@ ${attachmentContext}
|
|
|
2755
2808
|
});
|
|
2756
2809
|
}
|
|
2757
2810
|
}
|
|
2811
|
+
} else if (attachmentResults.length === 0 && pendingAttachmentDataRef.current !== null) {
|
|
2812
|
+
const isReferenceImage = pendingAttachmentDataRef.current.some((d) => d.url && !d.base64);
|
|
2813
|
+
if (isReferenceImage) {
|
|
2814
|
+
chatMessages.push({
|
|
2815
|
+
role: "user",
|
|
2816
|
+
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.
|
|
2817
|
+
|
|
2818
|
+
\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.`
|
|
2819
|
+
});
|
|
2820
|
+
} else {
|
|
2821
|
+
chatMessages.push({
|
|
2822
|
+
role: "user",
|
|
2823
|
+
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.
|
|
2824
|
+
|
|
2825
|
+
\uC0AC\uC6A9\uC790\uC758 \uC694\uCCAD \uC758\uB3C4\uB97C \uD30C\uC545\uD558\uC5EC \uC801\uC808\uD55C \uB3C4\uAD6C\uB97C \uC120\uD0DD\uD558\uC138\uC694:
|
|
2826
|
+
- \uC774\uBBF8\uC9C0 \uBD84\uC11D/\uC124\uBA85 \uC694\uCCAD \u2192 analyze_image \uB3C4\uAD6C
|
|
2827
|
+
- \uC774\uBBF8\uC9C0 \uD3B8\uC9D1/\uC218\uC815 \uC694\uCCAD \u2192 edit_image \uB3C4\uAD6C
|
|
2828
|
+
- \uC0C8 \uC774\uBBF8\uC9C0 \uC0DD\uC131 \uC694\uCCAD \u2192 generate_image \uB3C4\uAD6C
|
|
2829
|
+
- \uB3C4\uAD6C \uC5C6\uC774 \uB2F5\uBCC0 \uAC00\uB2A5 \u2192 \uBC14\uB85C \uB2F5\uBCC0`
|
|
2830
|
+
});
|
|
2831
|
+
}
|
|
2758
2832
|
}
|
|
2759
2833
|
console.log("[ChatUI] Messages to send:", chatMessages.length, chatMessages.map((m) => ({ role: m.role, content: m.content.slice(0, 50) })));
|
|
2760
2834
|
const baseSystemPrompt = buildSystemPrompt();
|