@xinleibird/bridge-opencode 0.2.8 → 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
package/bridge.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
- import type { FilePart, Part } from "@opencode-ai/sdk";
3
2
  import crypto from "node:crypto";
4
3
  import { access } from "node:fs/promises";
5
4
  import { basename, isAbsolute, join } from "node:path";
@@ -143,52 +142,38 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
143
142
  if (userMessages.length === 0) return;
144
143
 
145
144
  const latestUserMessage = userMessages[userMessages.length - 1];
146
- const msgInfo = latestUserMessage.info;
147
- if (!msgInfo || msgInfo.role !== "user") return;
148
145
  if (!latestUserMessage.parts) {
149
146
  latestUserMessage.parts = [];
150
147
  }
151
148
 
152
- const refs: string[] = [];
149
+ const blocks: string[] = [];
153
150
  for (const s of filteredSelections) {
154
151
  try {
155
152
  await access(s.filePath);
156
153
  } catch {
157
154
  continue;
158
155
  }
159
- if (!s.startLine) continue;
160
-
161
- const fileRef = `${s.filePath}:${s.startLine}-${s.endLine}`;
162
- refs.push(fileRef);
156
+ if (!s.startLine || !s.content) continue;
163
157
 
164
158
  const fileName = basename(s.filePath);
165
-
166
- const filePart: FilePart = {
167
- id: crypto.randomUUID(),
168
- sessionID: msgInfo.sessionID,
169
- messageID: msgInfo.id,
170
- type: "file",
171
- mime: "text/plain",
172
- filename: fileName,
173
- url: `file://${s.filePath}?start=${s.startLine}&end=${s.endLine}`,
174
- source: {
175
- text: {
176
- start: 0,
177
- value: fileRef,
178
- end: fileRef.length,
179
- },
180
- type: "file",
181
- path: s.filePath,
182
- },
183
- };
184
- latestUserMessage.parts.push(filePart);
159
+ blocks.push(
160
+ `Visual selection from nvim:\n## ${fileName}(${s.filePath}:${s.startLine}-${s.endLine})\n\`\`\`\n${s.content}\n\`\`\``,
161
+ );
185
162
  }
186
163
 
187
- if (refs.length === 0) return;
164
+ if (blocks.length === 0) return;
188
165
 
189
- const textPart = latestUserMessage.parts.find((p) => p.type === "text") as Part | undefined;
190
- if (textPart && textPart.type === "text" && typeof textPart.text === "string") {
191
- textPart.text = `${refs.join("\n")}\n\n${textPart.text}`;
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
+ });
192
177
  }
193
178
  },
194
179
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xinleibird/bridge-opencode",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",