opencode-tui-image-clipboard-fix 1.0.14 → 1.0.15
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 +7 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -126,6 +126,9 @@ export const ImageClipboardFix = async ({ client, directory }) => {
|
|
|
126
126
|
* experimental.chat.messages.transform hook - 在发送给模型前转换消息
|
|
127
127
|
* 在这里进行文本替换,确保模型收到的是完整的图片路径
|
|
128
128
|
* 这个修改只影响发送给模型的内容,不影响界面显示
|
|
129
|
+
*
|
|
130
|
+
* 重要:只对当前会话的消息添加 [Image Reference:] 提示
|
|
131
|
+
* 历史消息不添加提示,避免模型每次都"思考"处理图片
|
|
129
132
|
*/
|
|
130
133
|
"experimental.chat.messages.transform": async (input, output) => {
|
|
131
134
|
for (const message of output.messages) {
|
|
@@ -133,26 +136,20 @@ export const ImageClipboardFix = async ({ client, directory }) => {
|
|
|
133
136
|
if (message.info?.role !== "user")
|
|
134
137
|
continue;
|
|
135
138
|
const { parts } = message;
|
|
136
|
-
//
|
|
139
|
+
// 只处理当前会话的消息(缓存中有记录的)
|
|
140
|
+
// 历史消息不在缓存中,跳过添加提示
|
|
137
141
|
let imagePaths;
|
|
138
142
|
if (message.info?.id) {
|
|
139
143
|
imagePaths = messageImagePaths.get(message.info.id);
|
|
140
144
|
}
|
|
141
|
-
//
|
|
142
|
-
if (!imagePaths || imagePaths.size === 0) {
|
|
143
|
-
const result = await processImageParts(parts, false);
|
|
144
|
-
if (result.modified) {
|
|
145
|
-
imagePaths = result.imagePaths;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
// 如果有图片路径,替换文本中的占位符
|
|
145
|
+
// 如果缓存中有路径(当前消息),替换文本并添加提示
|
|
149
146
|
if (imagePaths && imagePaths.size > 0) {
|
|
150
147
|
const textPart = parts.find((p) => p.type === "text");
|
|
151
148
|
if (textPart && textPart.text && !textPart.text.includes("[Image Reference:")) {
|
|
152
149
|
textPart.text = modifyTextContent(textPart.text, imagePaths);
|
|
153
150
|
}
|
|
154
151
|
}
|
|
155
|
-
// 移除图片 FilePart
|
|
152
|
+
// 移除图片 FilePart(所有消息都移除,避免模型报错)
|
|
156
153
|
removeImagePartsSilently(parts);
|
|
157
154
|
}
|
|
158
155
|
},
|
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.15",
|
|
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",
|