@xinleibird/bridge-opencode 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/bridge.ts +13 -14
  2. package/package.json +1 -4
package/bridge.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
+ import crypto from "node:crypto";
2
3
  import { access } from "node:fs/promises";
3
- import { extname, isAbsolute, join } from "node:path";
4
- import { lookup } from "mime-types";
4
+ import { isAbsolute, join } from "node:path";
5
5
  import { checkBuffer, refreshBuffer, getVisualSelections, sendMessage } from "./index.cjs";
6
6
 
7
7
  type ToolName = "Edit" | "Write";
@@ -89,7 +89,7 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
89
89
  }
90
90
  },
91
91
 
92
- "chat.message": async (_input, output) => {
92
+ "chat.message": async (input, output) => {
93
93
  let selections;
94
94
  try {
95
95
  selections = await getVisualSelections();
@@ -101,6 +101,7 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
101
101
  const filteredSelections = selections.filter((s) => !s.cwd || s.cwd === cwd);
102
102
  if (filteredSelections.length === 0) return;
103
103
 
104
+ const refs: string[] = [];
104
105
  let attached = 0;
105
106
  for (const s of filteredSelections) {
106
107
  try {
@@ -108,24 +109,22 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
108
109
  } catch {
109
110
  continue;
110
111
  }
112
+ if (!s.startLine) continue;
111
113
 
112
114
  const filename = s.filePath.startsWith(cwd + "/")
113
115
  ? "./" + s.filePath.slice(cwd.length + 1)
114
116
  : s.filePath;
115
-
116
- const url = s.startLine
117
- ? `file://${s.filePath}?start=${s.startLine}&end=${s.endLine}`
118
- : `file://${s.filePath}`;
119
-
120
- const displayFilename = s.startLine
121
- ? `${filename}:${s.startLine}-${s.endLine}`
122
- : filename;
117
+ const displayFilename = `${filename}:${s.startLine}-${s.endLine}`;
118
+ refs.push(displayFilename);
123
119
 
124
120
  output.parts.push({
125
121
  type: "file",
126
- mime: lookup(extname(s.filePath)) || "text/plain",
122
+ id: crypto.randomUUID(),
123
+ sessionID: input.sessionID,
124
+ messageID: input.messageID ?? "",
125
+ mime: "text/plain",
127
126
  filename: displayFilename,
128
- url,
127
+ url: `file://${s.filePath}?start=${s.startLine}&end=${s.endLine}`,
129
128
  });
130
129
  attached++;
131
130
  }
@@ -134,7 +133,7 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
134
133
 
135
134
  const textPart = output.parts.find((p: any) => p.type === "text") as any;
136
135
  if (textPart && typeof textPart.text === "string") {
137
- textPart.text = `[Attached ${attached} selection(s)]\n\n${textPart.text}`;
136
+ textPart.text = `${refs.join("\n")}\n\n${textPart.text}`;
138
137
  }
139
138
  },
140
139
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xinleibird/bridge-opencode",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/xinleibird/bridge-opencode"
@@ -22,9 +22,6 @@
22
22
  "devDependencies": {
23
23
  "@napi-rs/cli": "^2.18.0"
24
24
  },
25
- "dependencies": {
26
- "mime-types": "^3.0.2"
27
- },
28
25
  "peerDependencies": {
29
26
  "@opencode-ai/plugin": ">=1.0.0"
30
27
  },