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