opencode-tui-image-clipboard-fix 1.0.15 → 1.0.17
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/lib/index.js +11 -21
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -66,30 +66,21 @@ export const ImageClipboardFix = async ({ client, directory }) => {
|
|
|
66
66
|
}
|
|
67
67
|
return { modified: imagePathMap.size > 0, imagePaths: imagePathMap };
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
* 修改文本内容:替换占位符、去重路径、添加提示
|
|
71
|
-
* 只在 transform hook 中使用,不影响界面显示
|
|
72
|
-
*/
|
|
69
|
+
const IMAGE_MARKER = "📷IMG";
|
|
73
70
|
function modifyTextContent(text, imagePathMap) {
|
|
74
71
|
let newText = text;
|
|
75
72
|
const allPaths = Array.from(imagePathMap.values());
|
|
76
|
-
// 1. 先从文本中移除所有已知的图片路径(去重)
|
|
77
73
|
for (const imagePath of allPaths) {
|
|
78
74
|
const escapedPath = imagePath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
79
75
|
const pathPattern = new RegExp(`\\s*${escapedPath}`, "g");
|
|
80
76
|
newText = newText.replace(pathPattern, "");
|
|
81
77
|
}
|
|
82
|
-
// 2. 替换 [Image N] 占位符为路径
|
|
83
78
|
for (const [placeholder, imagePath] of imagePathMap) {
|
|
84
79
|
const escapedPlaceholder = placeholder.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
85
80
|
const placeholderPattern = new RegExp(escapedPlaceholder, "g");
|
|
86
|
-
newText = newText.replace(placeholderPattern, imagePath);
|
|
81
|
+
newText = newText.replace(placeholderPattern, `[${IMAGE_MARKER}:${imagePath}]`);
|
|
87
82
|
}
|
|
88
|
-
// 3. 清理多余的空格和换行
|
|
89
83
|
newText = newText.replace(/\s+/g, " ").trim();
|
|
90
|
-
// 4. 添加图片读取提示
|
|
91
|
-
const hint = `\n\n[Image Reference: The above path(s) point to local image file(s). Please use the "read" tool to view the image content.]`;
|
|
92
|
-
newText = newText + hint;
|
|
93
84
|
return newText;
|
|
94
85
|
}
|
|
95
86
|
/**
|
|
@@ -132,24 +123,23 @@ export const ImageClipboardFix = async ({ client, directory }) => {
|
|
|
132
123
|
*/
|
|
133
124
|
"experimental.chat.messages.transform": async (input, output) => {
|
|
134
125
|
for (const message of output.messages) {
|
|
135
|
-
// 只处理用户消息
|
|
136
126
|
if (message.info?.role !== "user")
|
|
137
127
|
continue;
|
|
138
128
|
const { parts } = message;
|
|
139
|
-
|
|
140
|
-
|
|
129
|
+
const textPart = parts.find((p) => p.type === "text");
|
|
130
|
+
if (textPart?.text) {
|
|
131
|
+
// 清理旧格式: [Image Reference:...]
|
|
132
|
+
textPart.text = textPart.text.replace(/\n\n\[Image Reference:[^\]]*\]/g, "");
|
|
133
|
+
// 清理新格式标记(历史消息),保留路径
|
|
134
|
+
textPart.text = textPart.text.replace(/\[📷IMG:([^\]]+)\]/g, "$1");
|
|
135
|
+
}
|
|
141
136
|
let imagePaths;
|
|
142
137
|
if (message.info?.id) {
|
|
143
138
|
imagePaths = messageImagePaths.get(message.info.id);
|
|
144
139
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const textPart = parts.find((p) => p.type === "text");
|
|
148
|
-
if (textPart && textPart.text && !textPart.text.includes("[Image Reference:")) {
|
|
149
|
-
textPart.text = modifyTextContent(textPart.text, imagePaths);
|
|
150
|
-
}
|
|
140
|
+
if (imagePaths && imagePaths.size > 0 && textPart?.text) {
|
|
141
|
+
textPart.text = modifyTextContent(textPart.text, imagePaths);
|
|
151
142
|
}
|
|
152
|
-
// 移除图片 FilePart(所有消息都移除,避免模型报错)
|
|
153
143
|
removeImagePartsSilently(parts);
|
|
154
144
|
}
|
|
155
145
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-tui-image-clipboard-fix",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"displayName": "Image Clipboard Fix",
|
|
6
6
|
"description": "OpenCode TUI plugin to fix image paste issues - saves clipboard images locally and replaces [Image N] with file paths",
|