@vite-plugin-opencode-assistant/opencode 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.
@@ -1,14 +1,13 @@
1
- const T = "[vite-plugin-opencode]";
2
- const w = "[元素上下文]";
3
- var C = Object.defineProperty, S = Object.defineProperties, N = Object.getOwnPropertyDescriptors, x = Object.getOwnPropertySymbols, L = Object.prototype.hasOwnProperty, M = Object.prototype.propertyIsEnumerable, b = (e, t, r) => t in e ? C(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, g = (e, t) => {
4
- for (var r in t || (t = {}))
5
- L.call(t, r) && b(e, r, t[r]);
6
- if (x)
7
- for (var r of x(t))
8
- M.call(t, r) && b(e, r, t[r]);
9
- return e;
10
- }, m = (e, t) => S(e, N(t)), O = (e, t, r) => b(e, typeof t != "symbol" ? t + "" : t, r);
11
- const c = {
1
+ const P = "[vite-plugin-opencode]";
2
+ var E = Object.defineProperty, w = Object.defineProperties, b = Object.getOwnPropertyDescriptors, y = Object.getOwnPropertySymbols, S = Object.prototype.hasOwnProperty, C = Object.prototype.propertyIsEnumerable, _ = (r, t, e) => t in r ? E(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, c = (r, t) => {
3
+ for (var e in t || (t = {}))
4
+ S.call(t, e) && _(r, e, t[e]);
5
+ if (y)
6
+ for (var e of y(t))
7
+ C.call(t, e) && _(r, e, t[e]);
8
+ return r;
9
+ }, u = (r, t) => w(r, b(t)), O = (r, t, e) => _(r, typeof t != "symbol" ? t + "" : t, e);
10
+ const s = {
12
11
  reset: "\x1B[0m",
13
12
  dim: "\x1B[2m",
14
13
  bright: "\x1B[1m",
@@ -18,231 +17,143 @@ const c = {
18
17
  magenta: "\x1B[35m",
19
18
  cyan: "\x1B[36m"
20
19
  }, j = {
21
- 0: c.cyan,
22
- 1: c.green,
23
- 2: c.yellow,
24
- 3: c.red,
25
- 4: c.reset
26
- }, A = {
20
+ 0: s.cyan,
21
+ 1: s.green,
22
+ 2: s.yellow,
23
+ 3: s.red,
24
+ 4: s.reset
25
+ }, L = {
27
26
  0: "DEBUG",
28
27
  1: "INFO",
29
28
  2: "WARN",
30
29
  3: "ERROR",
31
30
  4: "NONE"
32
31
  };
33
- let R = {
32
+ let N = {
34
33
  level: 1
35
34
  /* INFO */
36
35
  };
37
- function B() {
38
- const e = /* @__PURE__ */ new Date(), t = String(e.getHours()).padStart(2, "0"), r = String(e.getMinutes()).padStart(2, "0"), o = String(e.getSeconds()).padStart(2, "0"), i = String(e.getMilliseconds()).padStart(3, "0");
39
- return `${t}:${r}:${o}.${i}`;
36
+ function x() {
37
+ const r = /* @__PURE__ */ new Date(), t = String(r.getHours()).padStart(2, "0"), e = String(r.getMinutes()).padStart(2, "0"), n = String(r.getSeconds()).padStart(2, "0"), o = String(r.getMilliseconds()).padStart(3, "0");
38
+ return `${t}:${e}:${n}.${o}`;
40
39
  }
41
- function I(e = 3) {
40
+ function I(r = 3) {
42
41
  const t = new Error().stack;
43
42
  if (!t) return "";
44
- const o = t.split(`
45
- `)[e];
43
+ const n = t.split(`
44
+ `)[r];
45
+ if (!n) return "";
46
+ const o = n.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/);
46
47
  if (!o) return "";
47
- const i = o.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/);
48
- if (!i) return "";
49
- const [, p, n, a] = i;
50
- return `${n.split("/").pop() || n}:${a} ${p || "<anonymous>"}`;
48
+ const [, a, m, l] = o;
49
+ return `${m.split("/").pop() || m}:${l} ${a || "<anonymous>"}`;
51
50
  }
52
- function h(e, t = 0) {
51
+ function f(r, t = 0) {
53
52
  if (t > 3) return "...";
54
- if (e === null) return "null";
55
- if (e === void 0) return "undefined";
56
- if (typeof e == "string") return t > 0 ? `"${e}"` : e;
57
- if (typeof e == "number" || typeof e == "boolean") return String(e);
58
- if (e instanceof Error)
59
- return `${e.name}: ${e.message}${e.stack ? `
60
- ${e.stack}` : ""}`;
61
- if (Array.isArray(e))
62
- return e.length === 0 ? "[]" : e.length > 5 ? `[${e.slice(0, 3).map((i) => h(i, t + 1)).join(", ")}, ... ${e.length - 3} more items]` : `[${e.map((o) => h(o, t + 1)).join(", ")}]`;
63
- if (typeof e == "object") {
64
- const r = Object.entries(e);
65
- return r.length === 0 ? "{}" : r.length > 5 ? `{${r.slice(0, 3).map(([p, n]) => `${p}: ${h(n, t + 1)}`).join(", ")}, ... ${r.length - 3} more keys}` : `{${r.map(([i, p]) => `${i}: ${h(p, t + 1)}`).join(", ")}}`;
53
+ if (r === null) return "null";
54
+ if (r === void 0) return "undefined";
55
+ if (typeof r == "string") return t > 0 ? `"${r}"` : r;
56
+ if (typeof r == "number" || typeof r == "boolean") return String(r);
57
+ if (r instanceof Error)
58
+ return `${r.name}: ${r.message}${r.stack ? `
59
+ ${r.stack}` : ""}`;
60
+ if (Array.isArray(r))
61
+ return r.length === 0 ? "[]" : r.length > 5 ? `[${r.slice(0, 3).map((o) => f(o, t + 1)).join(", ")}, ... ${r.length - 3} more items]` : `[${r.map((n) => f(n, t + 1)).join(", ")}]`;
62
+ if (typeof r == "object") {
63
+ const e = Object.entries(r);
64
+ return e.length === 0 ? "{}" : e.length > 5 ? `{${e.slice(0, 3).map(([a, m]) => `${a}: ${f(m, t + 1)}`).join(", ")}, ... ${e.length - 3} more keys}` : `{${e.map(([o, a]) => `${o}: ${f(a, t + 1)}`).join(", ")}}`;
66
65
  }
67
- return String(e);
66
+ return String(r);
68
67
  }
69
- function U(e) {
70
- if (!e || Object.keys(e).length === 0) return "";
68
+ function R(r) {
69
+ if (!r || Object.keys(r).length === 0) return "";
71
70
  const t = [];
72
- e.module && t.push(`[${e.module}]`), e.operation && t.push(`(${e.operation})`), e.traceId && t.push(`trace:${e.traceId}`), e.duration !== void 0 && t.push(`${e.duration}ms`);
73
- const r = Object.keys(e).filter(
74
- (o) => !["module", "operation", "traceId", "duration", "error"].includes(o)
71
+ r.module && t.push(`[${r.module}]`), r.operation && t.push(`(${r.operation})`), r.traceId && t.push(`trace:${r.traceId}`), r.duration !== void 0 && t.push(`${r.duration}ms`);
72
+ const e = Object.keys(r).filter(
73
+ (n) => !["module", "operation", "traceId", "duration", "error"].includes(n)
75
74
  );
76
- if (r.length > 0) {
77
- const o = {};
78
- r.forEach((i) => o[i] = e[i]), t.push(h(o));
75
+ if (e.length > 0) {
76
+ const n = {};
77
+ e.forEach((o) => n[o] = r[o]), t.push(f(n));
79
78
  }
80
79
  return t.join(" ");
81
80
  }
82
- function P(e, t, r, ...o) {
83
- if (e < R.level) return;
84
- const i = [];
85
- i.push(`${c.dim}[${process.pid}]${c.reset}`), i.push(`${c.dim}${B()}${c.reset}`);
86
- const p = j[e], n = A[e].padEnd(5);
87
- i.push(`${p}${n}${c.reset}`), i.push(`${c.bright}${T}${c.reset}`);
88
- const a = U(r);
89
- if (a && i.push(`${c.magenta}${a}${c.reset}`), i.push(t), e >= 2) {
90
- const u = I(4);
91
- u && i.push(`${c.dim}(${u})${c.reset}`);
81
+ function $(r, t, e, ...n) {
82
+ if (r < N.level) return;
83
+ const o = [];
84
+ o.push(`${s.dim}[${process.pid}]${s.reset}`), o.push(`${s.dim}${x()}${s.reset}`);
85
+ const a = j[r], m = L[r].padEnd(5);
86
+ o.push(`${a}${m}${s.reset}`), o.push(`${s.bright}${P}${s.reset}`);
87
+ const l = R(e);
88
+ if (l && o.push(`${s.magenta}${l}${s.reset}`), o.push(t), r >= 2) {
89
+ const i = I(4);
90
+ i && o.push(`${s.dim}(${i})${s.reset}`);
92
91
  }
93
- const s = o.map((u) => h(u)).join(" ");
94
- if (s && i.push(s), r != null && r.error) {
95
- const u = r.error;
96
- u instanceof Error ? i.push(`${c.red}Error: ${u.message}${c.reset}`) : i.push(`${c.red}Error: ${h(u)}${c.reset}`);
92
+ const h = n.map((i) => f(i)).join(" ");
93
+ if (h && o.push(h), e != null && e.error) {
94
+ const i = e.error;
95
+ i instanceof Error ? o.push(`${s.red}Error: ${i.message}${s.reset}`) : o.push(`${s.red}Error: ${f(i)}${s.reset}`);
97
96
  }
98
- const f = i.join(" ");
99
- e >= 3 ? console.error(f) : e === 2 ? console.warn(f) : console.log(f);
97
+ const d = o.join(" ");
98
+ r >= 3 ? console.error(d) : r === 2 ? console.warn(d) : console.log(d);
100
99
  }
101
- const $ = {
102
- debug(e, t, ...r) {
103
- P(0, e, t, ...r);
100
+ const p = {
101
+ debug(r, t, ...e) {
102
+ $(0, r, t, ...e);
104
103
  },
105
- info(e, t, ...r) {
106
- P(1, e, t, ...r);
104
+ info(r, t, ...e) {
105
+ $(1, r, t, ...e);
107
106
  },
108
- warn(e, t, ...r) {
109
- P(2, e, t, ...r);
107
+ warn(r, t, ...e) {
108
+ $(2, r, t, ...e);
110
109
  },
111
- error(e, t, ...r) {
112
- P(3, e, t, ...r);
110
+ error(r, t, ...e) {
111
+ $(3, r, t, ...e);
113
112
  },
114
- group(e, t) {
113
+ group(r, t) {
115
114
  },
116
115
  groupEnd() {
117
116
  }
118
117
  };
119
- class D {
120
- constructor(t, r) {
121
- O(this, "startTime"), O(this, "context"), O(this, "operation"), this.operation = t, this.context = r || {}, this.startTime = performance.now(), $.debug(`⏱️ Starting: ${t}`, this.context);
118
+ class A {
119
+ constructor(t, e) {
120
+ O(this, "startTime"), O(this, "context"), O(this, "operation"), this.operation = t, this.context = e || {}, this.startTime = performance.now(), p.debug(`⏱️ Starting: ${t}`, this.context);
122
121
  }
123
122
  end(t) {
124
- const r = Math.round(performance.now() - this.startTime), o = t || `✓ Completed: ${this.operation}`;
125
- return $.debug(o, m(g({}, this.context), { duration: r })), r;
123
+ const e = Math.round(performance.now() - this.startTime), n = t || `✓ Completed: ${this.operation}`;
124
+ return p.debug(n, u(c({}, this.context), { duration: e })), e;
126
125
  }
127
126
  checkpoint(t) {
128
- const r = Math.round(performance.now() - this.startTime);
129
- return $.debug(` ↳ ${t}`, m(g({}, this.context), { duration: r })), r;
127
+ const e = Math.round(performance.now() - this.startTime);
128
+ return p.debug(` ↳ ${t}`, u(c({}, this.context), { duration: e })), e;
130
129
  }
131
130
  }
132
- function k(e) {
131
+ function B(r) {
133
132
  return {
134
- debug(t, r, ...o) {
135
- $.debug(t, m(g({}, r), { module: e }), ...o);
133
+ debug(t, e, ...n) {
134
+ p.debug(t, u(c({}, e), { module: r }), ...n);
136
135
  },
137
- info(t, r, ...o) {
138
- $.info(t, m(g({}, r), { module: e }), ...o);
136
+ info(t, e, ...n) {
137
+ p.info(t, u(c({}, e), { module: r }), ...n);
139
138
  },
140
- warn(t, r, ...o) {
141
- $.warn(t, m(g({}, r), { module: e }), ...o);
139
+ warn(t, e, ...n) {
140
+ p.warn(t, u(c({}, e), { module: r }), ...n);
142
141
  },
143
- error(t, r, ...o) {
144
- $.error(t, m(g({}, r), { module: e }), ...o);
142
+ error(t, e, ...n) {
143
+ p.error(t, u(c({}, e), { module: r }), ...n);
145
144
  },
146
- timer(t, r) {
147
- return new D(t, m(g({}, r), { module: e }));
145
+ timer(t, e) {
146
+ return new A(t, u(c({}, e), { module: r }));
148
147
  }
149
148
  };
150
149
  }
151
- const l = k("OpenCodePluginPageContext"), X = async () => {
152
- l.info("PageContextPlugin loading...");
153
- const e = process.env.OPENCODE_CONTEXT_API_URL;
154
- if (l.debug("Context API URL:", { contextApiUrl: e }), !e)
155
- return l.warn("OPENCODE_CONTEXT_API_URL is not set, page context plugin will not work"), {};
156
- const t = e;
157
- l.info("Plugin initialized successfully");
158
- async function r() {
159
- try {
160
- l.debug("Fetching context...", { apiUrl: t });
161
- const n = await fetch(t);
162
- if (!n.ok)
163
- return l.error("Context API returned error status", {
164
- status: n.status,
165
- statusText: n.statusText,
166
- apiUrl: t
167
- }), null;
168
- const a = await n.json();
169
- return l.debug("Context received", { url: a.url, title: a.title }), {
170
- url: a.url || "",
171
- title: a.title || "",
172
- selectedElements: a.selectedElements
173
- };
174
- } catch (n) {
175
- const a = n instanceof Error ? n.message : String(n), s = n instanceof Error ? n.name : "UnknownError";
176
- return l.error("Failed to get context", {
177
- error: a,
178
- errorType: s,
179
- apiUrl: t
180
- }), null;
181
- }
182
- }
183
- async function o() {
184
- try {
185
- l.debug("Clearing selected elements", { apiUrl: t });
186
- const n = await fetch(t, { method: "DELETE" });
187
- l.debug("Clear response", { status: n.status });
188
- } catch (n) {
189
- const a = n instanceof Error ? n.message : String(n), s = n instanceof Error ? n.name : "UnknownError";
190
- l.error("Failed to clear selected elements", {
191
- error: a,
192
- errorType: s,
193
- apiUrl: t
194
- });
195
- }
196
- }
197
- function i(n, a) {
198
- var f, u;
199
- const s = [];
200
- if (s.push(`### 选中节点 ${a + 1}`), n.filePath)
201
- if (n.filePath.includes("node_modules")) {
202
- if (s.push(`- **元素描述**: \`${n.description}\``), (f = n.innerText) != null && f.trim()) {
203
- const d = n.innerText.trim().substring(0, 100);
204
- s.push(`- **节点文本**: \`${d}${n.innerText.length > 100 ? "..." : ""}\``);
205
- }
206
- s.push(
207
- `- **分析建议**: 请使用 Chrome DevTools MCP 获取当前页面快照,结合 CSS 选择器 \`${n.description}\` 来获取更多的页面上下文`
208
- );
209
- } else {
210
- let d = n.filePath;
211
- if (n.line && (d += `:${n.line}`, n.column && (d += `:${n.column}`)), s.push(`- **文件位置**: \`${d}\``), (u = n.innerText) != null && u.trim()) {
212
- const y = n.innerText.trim().substring(0, 100), E = n.innerText.length > 100 ? `
213
- ... (已省略部分内容)` : "";
214
- s.push(`- **节点文本**:
215
- \`\`\`text
216
- ${y}${E}
217
- \`\`\``);
218
- }
219
- }
220
- return s.join(`
221
- `) + `
222
- `;
223
- }
224
- function p(n) {
225
- var f;
226
- const a = n.title ? `[${n.title}](${n.url})` : n.url;
227
- let s = `【系统提示:以下是用户当前正在浏览的页面上下文,请将其作为最高优先级的背景信息来理解和响应用户的请求。】
228
-
229
- `;
230
- return s += `用户现在正在浏览项目中的这个页面:${a}
231
-
232
- `, (f = n.selectedElements) != null && f.length && (s += `用户选中了以下节点:
233
-
234
- `, n.selectedElements.forEach((u, _) => {
235
- s += i(u, _) + `
236
- `;
237
- })), s += `---
238
- **用户的请求**:
239
-
240
- `, s;
241
- }
242
- return {
243
- "experimental.chat.system.transform": async (n, a) => {
244
- l.debug("System transform hook called");
245
- const s = `
150
+ const g = B("OpenCodePluginPageContext"), T = async () => {
151
+ g.info("PageContextPlugin loading...");
152
+ const r = process.env.OPENCODE_CONTEXT_API_URL;
153
+ return g.debug("Context API URL:", { contextApiUrl: r }), r ? (g.info("Plugin initialized successfully"), {
154
+ "experimental.chat.system.transform": async (t, e) => {
155
+ g.debug("System transform hook called");
156
+ const n = `
246
157
  你是一个专业的前端开发助手,运行在 **OpenCode** 平台中,并通过 **vite-plugin-opencode-assistant** 插件集成到用户的 Vite 开发环境。
247
158
 
248
159
  ## 你的工作环境
@@ -269,27 +180,14 @@ ${y}${E}
269
180
 
270
181
  当用户与你对话时,系统会自动收集并注入以下页面上下文信息:
271
182
 
272
- 1. **页面信息**:用户当前浏览的页面 URL 和标题
273
- 2. **选中元素**:用户在页面上选中的 DOM 元素信息,包括:
274
- - 源码文件路径(如 \`src/components/Button.tsx\`)
275
- - 行号和列号(精确定位到代码位置)
276
- - 元素的文本内容
183
+ **选中元素**:用户在页面上选中的 DOM 元素信息,包括:
184
+ - 元素的预览页面 URL 和标题
185
+ - 元素的选择器
186
+ - 元素的文本内容
187
+ - 源码文件路径
277
188
 
278
189
  这些信息由 Vite 插件通过内部 API 收集,并在用户发送消息时自动附加到消息前缀中。
279
190
 
280
- ## 上下文处理规则
281
-
282
- 当你在对话中看到类似以下格式的上下文信息时:
283
-
284
- \`\`\`
285
- 【系统提示:以下是用户当前正在浏览的页面上下文...】
286
- 用户现在正在浏览项目中的这个页面:[页面标题](URL)
287
- 用户选中了以下节点:
288
- ### 选中节点 1
289
- - **文件位置**: \`src/components/Button.tsx:42:10\`
290
- - **节点文本**: ...
291
- \`\`\`
292
-
293
191
  请遵循以下规则:
294
192
 
295
193
  1. **前置要求:定位节点位置**(强制)
@@ -302,26 +200,11 @@ ${y}${E}
302
200
 
303
201
  3. **直接行动**:在明确节点位置后,针对用户的实际请求给出清晰、可执行的方案。
304
202
  `.trim();
305
- a.system.push(s);
306
- },
307
- "experimental.chat.messages.transform": async (n, a) => {
308
- var d, y;
309
- l.debug("Message transform hook called");
310
- const s = await r();
311
- if (l.debug("Context data", {
312
- hasUrl: !!(s != null && s.url),
313
- hasElements: !!((d = s == null ? void 0 : s.selectedElements) != null && d.length)
314
- }), !(s != null && s.url)) return;
315
- const f = [...a.messages].reverse().find((E) => E.info.role === "user");
316
- if (!f) return;
317
- const u = f.parts.find((E) => E.type === "text");
318
- if (!u || !("text" in u) || u.text.includes(w)) return;
319
- const _ = p(s);
320
- u.text = _ + u.text, (y = s.selectedElements) != null && y.length && (l.debug("Selected elements found, clearing..."), await o());
203
+ e.system.push(n);
321
204
  }
322
- };
205
+ }) : (g.warn("OPENCODE_CONTEXT_API_URL is not set, page context plugin will not work"), {});
323
206
  };
324
207
  export {
325
- X as PageContextPlugin,
326
- X as default
208
+ T as PageContextPlugin,
209
+ T as default
327
210
  };
@@ -51,116 +51,7 @@ const PageContextPlugin = () => __async(null, null, function* () {
51
51
  log.warn("OPENCODE_CONTEXT_API_URL is not set, page context plugin will not work");
52
52
  return {};
53
53
  }
54
- const apiUrl = contextApiUrl;
55
54
  log.info("Plugin initialized successfully");
56
- function getPageContext() {
57
- return __async(this, null, function* () {
58
- try {
59
- log.debug("Fetching context...", { apiUrl });
60
- const response = yield fetch(apiUrl);
61
- if (!response.ok) {
62
- log.error("Context API returned error status", {
63
- status: response.status,
64
- statusText: response.statusText,
65
- apiUrl
66
- });
67
- return null;
68
- }
69
- const data = yield response.json();
70
- log.debug("Context received", { url: data.url, title: data.title });
71
- return {
72
- url: data.url || "",
73
- title: data.title || "",
74
- selectedElements: data.selectedElements
75
- };
76
- } catch (error) {
77
- const errorMessage = error instanceof Error ? error.message : String(error);
78
- const errorName = error instanceof Error ? error.name : "UnknownError";
79
- log.error("Failed to get context", {
80
- error: errorMessage,
81
- errorType: errorName,
82
- apiUrl
83
- });
84
- return null;
85
- }
86
- });
87
- }
88
- function clearSelectedElements() {
89
- return __async(this, null, function* () {
90
- try {
91
- log.debug("Clearing selected elements", { apiUrl });
92
- const response = yield fetch(apiUrl, { method: "DELETE" });
93
- log.debug("Clear response", { status: response.status });
94
- } catch (error) {
95
- const errorMessage = error instanceof Error ? error.message : String(error);
96
- const errorName = error instanceof Error ? error.name : "UnknownError";
97
- log.error("Failed to clear selected elements", {
98
- error: errorMessage,
99
- errorType: errorName,
100
- apiUrl
101
- });
102
- }
103
- });
104
- }
105
- function formatSelectedElement(element, index) {
106
- var _a, _b;
107
- const parts = [];
108
- parts.push(`### \u9009\u4E2D\u8282\u70B9 ${index + 1}`);
109
- if (element.filePath) {
110
- const isNodeModule = element.filePath.includes("node_modules");
111
- if (isNodeModule) {
112
- parts.push(`- **\u5143\u7D20\u63CF\u8FF0**: \`${element.description}\``);
113
- if ((_a = element.innerText) == null ? void 0 : _a.trim()) {
114
- const text = element.innerText.trim().substring(0, 100);
115
- parts.push(`- **\u8282\u70B9\u6587\u672C**: \`${text}${element.innerText.length > 100 ? "..." : ""}\``);
116
- }
117
- parts.push(
118
- `- **\u5206\u6790\u5EFA\u8BAE**: \u8BF7\u4F7F\u7528 Chrome DevTools MCP \u83B7\u53D6\u5F53\u524D\u9875\u9762\u5FEB\u7167\uFF0C\u7ED3\u5408 CSS \u9009\u62E9\u5668 \`${element.description}\` \u6765\u83B7\u53D6\u66F4\u591A\u7684\u9875\u9762\u4E0A\u4E0B\u6587`
119
- );
120
- } else {
121
- let location = element.filePath;
122
- if (element.line) {
123
- location += `:${element.line}`;
124
- if (element.column) {
125
- location += `:${element.column}`;
126
- }
127
- }
128
- parts.push(`- **\u6587\u4EF6\u4F4D\u7F6E**: \`${location}\``);
129
- if ((_b = element.innerText) == null ? void 0 : _b.trim()) {
130
- const text = element.innerText.trim().substring(0, import_shared.MAX_TEXT_LENGTH);
131
- const suffix = element.innerText.length > import_shared.MAX_TEXT_LENGTH ? "\n... (\u5DF2\u7701\u7565\u90E8\u5206\u5185\u5BB9)" : "";
132
- parts.push(`- **\u8282\u70B9\u6587\u672C**:
133
- \`\`\`text
134
- ${text}${suffix}
135
- \`\`\``);
136
- }
137
- }
138
- }
139
- return parts.join("\n") + "\n";
140
- }
141
- function buildContextPrefix(context) {
142
- var _a;
143
- const pageLink = context.title ? `[${context.title}](${context.url})` : context.url;
144
- let prefix = `\u3010\u7CFB\u7EDF\u63D0\u793A\uFF1A\u4EE5\u4E0B\u662F\u7528\u6237\u5F53\u524D\u6B63\u5728\u6D4F\u89C8\u7684\u9875\u9762\u4E0A\u4E0B\u6587\uFF0C\u8BF7\u5C06\u5176\u4F5C\u4E3A\u6700\u9AD8\u4F18\u5148\u7EA7\u7684\u80CC\u666F\u4FE1\u606F\u6765\u7406\u89E3\u548C\u54CD\u5E94\u7528\u6237\u7684\u8BF7\u6C42\u3002\u3011
145
-
146
- `;
147
- prefix += `\u7528\u6237\u73B0\u5728\u6B63\u5728\u6D4F\u89C8\u9879\u76EE\u4E2D\u7684\u8FD9\u4E2A\u9875\u9762\uFF1A${pageLink}
148
-
149
- `;
150
- if ((_a = context.selectedElements) == null ? void 0 : _a.length) {
151
- prefix += `\u7528\u6237\u9009\u4E2D\u4E86\u4EE5\u4E0B\u8282\u70B9\uFF1A
152
-
153
- `;
154
- context.selectedElements.forEach((element, index) => {
155
- prefix += formatSelectedElement(element, index) + "\n";
156
- });
157
- }
158
- prefix += `---
159
- **\u7528\u6237\u7684\u8BF7\u6C42**\uFF1A
160
-
161
- `;
162
- return prefix;
163
- }
164
55
  return {
165
56
  "experimental.chat.system.transform": (_input, output) => __async(null, null, function* () {
166
57
  log.debug("System transform hook called");
@@ -191,27 +82,14 @@ ${text}${suffix}
191
82
 
192
83
  \u5F53\u7528\u6237\u4E0E\u4F60\u5BF9\u8BDD\u65F6\uFF0C\u7CFB\u7EDF\u4F1A\u81EA\u52A8\u6536\u96C6\u5E76\u6CE8\u5165\u4EE5\u4E0B\u9875\u9762\u4E0A\u4E0B\u6587\u4FE1\u606F\uFF1A
193
84
 
194
- 1. **\u9875\u9762\u4FE1\u606F**\uFF1A\u7528\u6237\u5F53\u524D\u6D4F\u89C8\u7684\u9875\u9762 URL \u548C\u6807\u9898
195
- 2. **\u9009\u4E2D\u5143\u7D20**\uFF1A\u7528\u6237\u5728\u9875\u9762\u4E0A\u9009\u4E2D\u7684 DOM \u5143\u7D20\u4FE1\u606F\uFF0C\u5305\u62EC\uFF1A
196
- - \u6E90\u7801\u6587\u4EF6\u8DEF\u5F84\uFF08\u5982 \`src/components/Button.tsx\`\uFF09
197
- - \u884C\u53F7\u548C\u5217\u53F7\uFF08\u7CBE\u786E\u5B9A\u4F4D\u5230\u4EE3\u7801\u4F4D\u7F6E\uFF09
198
- - \u5143\u7D20\u7684\u6587\u672C\u5185\u5BB9
85
+ **\u9009\u4E2D\u5143\u7D20**\uFF1A\u7528\u6237\u5728\u9875\u9762\u4E0A\u9009\u4E2D\u7684 DOM \u5143\u7D20\u4FE1\u606F\uFF0C\u5305\u62EC\uFF1A
86
+ - \u5143\u7D20\u7684\u9884\u89C8\u9875\u9762 URL \u548C\u6807\u9898
87
+ - \u5143\u7D20\u7684\u9009\u62E9\u5668
88
+ - \u5143\u7D20\u7684\u6587\u672C\u5185\u5BB9
89
+ - \u6E90\u7801\u6587\u4EF6\u8DEF\u5F84
199
90
 
200
91
  \u8FD9\u4E9B\u4FE1\u606F\u7531 Vite \u63D2\u4EF6\u901A\u8FC7\u5185\u90E8 API \u6536\u96C6\uFF0C\u5E76\u5728\u7528\u6237\u53D1\u9001\u6D88\u606F\u65F6\u81EA\u52A8\u9644\u52A0\u5230\u6D88\u606F\u524D\u7F00\u4E2D\u3002
201
92
 
202
- ## \u4E0A\u4E0B\u6587\u5904\u7406\u89C4\u5219
203
-
204
- \u5F53\u4F60\u5728\u5BF9\u8BDD\u4E2D\u770B\u5230\u7C7B\u4F3C\u4EE5\u4E0B\u683C\u5F0F\u7684\u4E0A\u4E0B\u6587\u4FE1\u606F\u65F6\uFF1A
205
-
206
- \`\`\`
207
- \u3010\u7CFB\u7EDF\u63D0\u793A\uFF1A\u4EE5\u4E0B\u662F\u7528\u6237\u5F53\u524D\u6B63\u5728\u6D4F\u89C8\u7684\u9875\u9762\u4E0A\u4E0B\u6587...\u3011
208
- \u7528\u6237\u73B0\u5728\u6B63\u5728\u6D4F\u89C8\u9879\u76EE\u4E2D\u7684\u8FD9\u4E2A\u9875\u9762\uFF1A[\u9875\u9762\u6807\u9898](URL)
209
- \u7528\u6237\u9009\u4E2D\u4E86\u4EE5\u4E0B\u8282\u70B9\uFF1A
210
- ### \u9009\u4E2D\u8282\u70B9 1
211
- - **\u6587\u4EF6\u4F4D\u7F6E**: \`src/components/Button.tsx:42:10\`
212
- - **\u8282\u70B9\u6587\u672C**: ...
213
- \`\`\`
214
-
215
93
  \u8BF7\u9075\u5FAA\u4EE5\u4E0B\u89C4\u5219\uFF1A
216
94
 
217
95
  1. **\u524D\u7F6E\u8981\u6C42\uFF1A\u5B9A\u4F4D\u8282\u70B9\u4F4D\u7F6E**\uFF08\u5F3A\u5236\uFF09
@@ -225,27 +103,6 @@ ${text}${suffix}
225
103
  3. **\u76F4\u63A5\u884C\u52A8**\uFF1A\u5728\u660E\u786E\u8282\u70B9\u4F4D\u7F6E\u540E\uFF0C\u9488\u5BF9\u7528\u6237\u7684\u5B9E\u9645\u8BF7\u6C42\u7ED9\u51FA\u6E05\u6670\u3001\u53EF\u6267\u884C\u7684\u65B9\u6848\u3002
226
104
  `.trim();
227
105
  output.system.push(systemPrompt);
228
- }),
229
- "experimental.chat.messages.transform": (_input, output) => __async(null, null, function* () {
230
- var _a, _b;
231
- log.debug("Message transform hook called");
232
- const context = yield getPageContext();
233
- log.debug("Context data", {
234
- hasUrl: !!(context == null ? void 0 : context.url),
235
- hasElements: !!((_a = context == null ? void 0 : context.selectedElements) == null ? void 0 : _a.length)
236
- });
237
- if (!(context == null ? void 0 : context.url)) return;
238
- const lastUserMsg = [...output.messages].reverse().find((m) => m.info.role === "user");
239
- if (!lastUserMsg) return;
240
- const textPart = lastUserMsg.parts.find((p) => p.type === "text");
241
- if (!textPart || !("text" in textPart)) return;
242
- if (textPart.text.includes(import_shared.CONTEXT_MARKER)) return;
243
- const prefix = buildContextPrefix(context);
244
- textPart.text = prefix + textPart.text;
245
- if ((_b = context.selectedElements) == null ? void 0 : _b.length) {
246
- log.debug("Selected elements found, clearing...");
247
- yield clearSelectedElements();
248
- }
249
106
  })
250
107
  };
251
108
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-plugin-opencode-assistant/opencode",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "execa": "^9.6.1",
25
- "@vite-plugin-opencode-assistant/shared": "1.0.15"
25
+ "@vite-plugin-opencode-assistant/shared": "1.0.17"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@opencode-ai/plugin": "^1.3.15",