@xinleibird/bridge-opencode 0.2.7 → 0.2.9
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.
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/bridge.ts
CHANGED
|
@@ -126,7 +126,7 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
|
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
128
|
|
|
129
|
-
"chat.
|
|
129
|
+
"experimental.chat.messages.transform": async (_, output) => {
|
|
130
130
|
let selections: Awaited<ReturnType<typeof getVisualSelections>>;
|
|
131
131
|
try {
|
|
132
132
|
selections = await getVisualSelections();
|
|
@@ -138,23 +138,64 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
|
|
|
138
138
|
const filteredSelections = selections.filter((s) => !s.cwd || s.cwd === cwd);
|
|
139
139
|
if (filteredSelections.length === 0) return;
|
|
140
140
|
|
|
141
|
-
const
|
|
142
|
-
|
|
141
|
+
const userMessages = output.messages.filter((m) => m.info.role === "user");
|
|
142
|
+
if (userMessages.length === 0) return;
|
|
143
|
+
|
|
144
|
+
const latestUserMessage = userMessages[userMessages.length - 1];
|
|
145
|
+
if (!latestUserMessage.parts) {
|
|
146
|
+
latestUserMessage.parts = [];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const blocks: string[] = [];
|
|
143
150
|
for (const s of filteredSelections) {
|
|
144
151
|
try {
|
|
145
152
|
await access(s.filePath);
|
|
146
153
|
} catch {
|
|
147
154
|
continue;
|
|
148
155
|
}
|
|
149
|
-
if (!s.startLine) continue;
|
|
156
|
+
if (!s.startLine || !s.content) continue;
|
|
150
157
|
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
158
|
+
const fileName = basename(s.filePath);
|
|
159
|
+
blocks.push(
|
|
160
|
+
`Visual selection from nvim:\n## ${fileName}(${s.filePath}:${s.startLine}-${s.endLine})\n\`\`\`\n${s.content}\n\`\`\``,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
154
163
|
|
|
155
|
-
|
|
164
|
+
if (blocks.length === 0) return;
|
|
156
165
|
|
|
157
|
-
|
|
166
|
+
const textPart = latestUserMessage.parts.findLast((p) => p.type === "text");
|
|
167
|
+
if (textPart && typeof textPart.text === "string") {
|
|
168
|
+
textPart.text += `\n\n${blocks.join("\n\n")}`;
|
|
169
|
+
} else {
|
|
170
|
+
latestUserMessage.parts.push({
|
|
171
|
+
id: crypto.randomUUID(),
|
|
172
|
+
sessionID: latestUserMessage.info.sessionID,
|
|
173
|
+
messageID: latestUserMessage.info.id,
|
|
174
|
+
type: "text",
|
|
175
|
+
text: blocks.join("\n\n"),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
"chat.message": async (input, output) => {
|
|
181
|
+
let selections: Awaited<ReturnType<typeof getVisualSelections>>;
|
|
182
|
+
try {
|
|
183
|
+
selections = await getVisualSelections();
|
|
184
|
+
} catch {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (!selections || selections.length === 0) return;
|
|
188
|
+
|
|
189
|
+
const filteredSelections = selections.filter((s) => !s.cwd || s.cwd === cwd);
|
|
190
|
+
if (filteredSelections.length === 0) return;
|
|
191
|
+
|
|
192
|
+
for (const s of filteredSelections) {
|
|
193
|
+
try {
|
|
194
|
+
await access(s.filePath);
|
|
195
|
+
} catch {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (!s.startLine) continue;
|
|
158
199
|
|
|
159
200
|
const fileName = basename(s.filePath);
|
|
160
201
|
|
|
@@ -164,20 +205,11 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
|
|
|
164
205
|
sessionID: input.sessionID,
|
|
165
206
|
messageID: input.messageID ?? "",
|
|
166
207
|
mime: "text/plain",
|
|
167
|
-
filename: fileName
|
|
208
|
+
filename: `${fileName}:${s.startLine}-${s.endLine}`,
|
|
168
209
|
url: `file://${s.filePath}?start=${s.startLine}&end=${s.endLine}`,
|
|
169
210
|
});
|
|
170
|
-
attached++;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (attached === 0) return;
|
|
174
|
-
|
|
175
|
-
const textPart = output.parts.find((p: any) => p.type === "text") as any;
|
|
176
|
-
if (textPart && typeof textPart.text === "string") {
|
|
177
|
-
textPart.text = `${refs.join("\n")}\n\n${textPart.text}`;
|
|
178
211
|
}
|
|
179
212
|
},
|
|
180
213
|
};
|
|
181
214
|
};
|
|
182
|
-
|
|
183
215
|
export default BridgePlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xinleibird/bridge-opencode",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,5 +38,8 @@
|
|
|
38
38
|
"aarch64-unknown-linux-gnu"
|
|
39
39
|
]
|
|
40
40
|
}
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@opencode-ai/sdk": "^1.15.12"
|
|
41
44
|
}
|
|
42
45
|
}
|