@vite-plugin-opencode-assistant/opencode 1.0.16 → 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.
- package/es/plugins/page-context.js +115 -202
- package/lib/plugins/page-context.js +5 -111
- package/package.json +2 -2
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
N.call(e, r) && P(t, r, e[r]);
|
|
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]);
|
|
6
5
|
if (y)
|
|
7
|
-
for (var
|
|
8
|
-
|
|
9
|
-
return
|
|
10
|
-
},
|
|
11
|
-
const
|
|
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,214 +17,143 @@ const u = {
|
|
|
18
17
|
magenta: "\x1B[35m",
|
|
19
18
|
cyan: "\x1B[36m"
|
|
20
19
|
}, j = {
|
|
21
|
-
0:
|
|
22
|
-
1:
|
|
23
|
-
2:
|
|
24
|
-
3:
|
|
25
|
-
4:
|
|
26
|
-
},
|
|
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
|
|
32
|
+
let N = {
|
|
34
33
|
level: 1
|
|
35
34
|
/* INFO */
|
|
36
35
|
};
|
|
37
|
-
function
|
|
38
|
-
const
|
|
39
|
-
return `${
|
|
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(
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
44
|
-
const
|
|
45
|
-
`)[
|
|
40
|
+
function I(r = 3) {
|
|
41
|
+
const t = new Error().stack;
|
|
42
|
+
if (!t) return "";
|
|
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
|
|
48
|
-
|
|
49
|
-
const [, n, a, s] = i;
|
|
50
|
-
return `${a.split("/").pop() || a}:${s} ${n || "<anonymous>"}`;
|
|
48
|
+
const [, a, m, l] = o;
|
|
49
|
+
return `${m.split("/").pop() || m}:${l} ${a || "<anonymous>"}`;
|
|
51
50
|
}
|
|
52
|
-
function
|
|
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
|
|
65
|
-
return
|
|
51
|
+
function f(r, t = 0) {
|
|
52
|
+
if (t > 3) return "...";
|
|
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(
|
|
66
|
+
return String(r);
|
|
68
67
|
}
|
|
69
|
-
function
|
|
70
|
-
if (!
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
(
|
|
68
|
+
function R(r) {
|
|
69
|
+
if (!r || Object.keys(r).length === 0) return "";
|
|
70
|
+
const t = [];
|
|
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 (
|
|
77
|
-
const
|
|
78
|
-
|
|
75
|
+
if (e.length > 0) {
|
|
76
|
+
const n = {};
|
|
77
|
+
e.forEach((o) => n[o] = r[o]), t.push(f(n));
|
|
79
78
|
}
|
|
80
|
-
return
|
|
79
|
+
return t.join(" ");
|
|
81
80
|
}
|
|
82
|
-
function
|
|
83
|
-
if (
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
const
|
|
91
|
-
|
|
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
|
|
94
|
-
if (
|
|
95
|
-
const
|
|
96
|
-
|
|
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
|
|
99
|
-
|
|
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(
|
|
103
|
-
|
|
100
|
+
const p = {
|
|
101
|
+
debug(r, t, ...e) {
|
|
102
|
+
$(0, r, t, ...e);
|
|
104
103
|
},
|
|
105
|
-
info(
|
|
106
|
-
|
|
104
|
+
info(r, t, ...e) {
|
|
105
|
+
$(1, r, t, ...e);
|
|
107
106
|
},
|
|
108
|
-
warn(
|
|
109
|
-
|
|
107
|
+
warn(r, t, ...e) {
|
|
108
|
+
$(2, r, t, ...e);
|
|
110
109
|
},
|
|
111
|
-
error(
|
|
112
|
-
|
|
110
|
+
error(r, t, ...e) {
|
|
111
|
+
$(3, r, t, ...e);
|
|
113
112
|
},
|
|
114
|
-
group(
|
|
113
|
+
group(r, t) {
|
|
115
114
|
},
|
|
116
115
|
groupEnd() {
|
|
117
116
|
}
|
|
118
117
|
};
|
|
119
|
-
class
|
|
120
|
-
constructor(
|
|
121
|
-
O(this, "startTime"), O(this, "context"), O(this, "operation"), this.operation =
|
|
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
|
-
end(
|
|
124
|
-
const
|
|
125
|
-
return
|
|
122
|
+
end(t) {
|
|
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
|
-
checkpoint(
|
|
128
|
-
const
|
|
129
|
-
return
|
|
126
|
+
checkpoint(t) {
|
|
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
|
|
131
|
+
function B(r) {
|
|
133
132
|
return {
|
|
134
|
-
debug(
|
|
135
|
-
|
|
133
|
+
debug(t, e, ...n) {
|
|
134
|
+
p.debug(t, u(c({}, e), { module: r }), ...n);
|
|
136
135
|
},
|
|
137
|
-
info(
|
|
138
|
-
|
|
136
|
+
info(t, e, ...n) {
|
|
137
|
+
p.info(t, u(c({}, e), { module: r }), ...n);
|
|
139
138
|
},
|
|
140
|
-
warn(
|
|
141
|
-
|
|
139
|
+
warn(t, e, ...n) {
|
|
140
|
+
p.warn(t, u(c({}, e), { module: r }), ...n);
|
|
142
141
|
},
|
|
143
|
-
error(
|
|
144
|
-
|
|
142
|
+
error(t, e, ...n) {
|
|
143
|
+
p.error(t, u(c({}, e), { module: r }), ...n);
|
|
145
144
|
},
|
|
146
|
-
timer(
|
|
147
|
-
return new
|
|
145
|
+
timer(t, e) {
|
|
146
|
+
return new A(t, u(c({}, e), { module: r }));
|
|
148
147
|
}
|
|
149
148
|
};
|
|
150
149
|
}
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
async function r() {
|
|
159
|
-
try {
|
|
160
|
-
p.debug("Fetching context...", { apiUrl: e });
|
|
161
|
-
const n = await fetch(e);
|
|
162
|
-
if (!n.ok)
|
|
163
|
-
return p.error("Context API returned error status", {
|
|
164
|
-
status: n.status,
|
|
165
|
-
statusText: n.statusText,
|
|
166
|
-
apiUrl: e
|
|
167
|
-
}), null;
|
|
168
|
-
const a = await n.json();
|
|
169
|
-
return p.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 p.error("Failed to get context", {
|
|
177
|
-
error: a,
|
|
178
|
-
errorType: s,
|
|
179
|
-
apiUrl: e
|
|
180
|
-
}), null;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
function o(n, a) {
|
|
184
|
-
var l, c;
|
|
185
|
-
const s = [];
|
|
186
|
-
if (s.push(`### 用户选中节点 ${a + 1}`), n.filePath)
|
|
187
|
-
if (n.filePath.includes("node_modules")) {
|
|
188
|
-
if (s.push(`- **元素选择器**: \`${n.description}\``), (l = n.innerText) != null && l.trim()) {
|
|
189
|
-
const d = n.innerText.trim().substring(0, 100);
|
|
190
|
-
s.push(`- **节点文本**: \`${d}${n.innerText.length > 100 ? "..." : ""}\``);
|
|
191
|
-
}
|
|
192
|
-
} else {
|
|
193
|
-
let d = n.filePath;
|
|
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 ? `
|
|
196
|
-
... (已省略部分内容)` : "";
|
|
197
|
-
s.push(`- **节点文本**:
|
|
198
|
-
\`\`\`text
|
|
199
|
-
${E}${b}
|
|
200
|
-
\`\`\``);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return s.join(`
|
|
204
|
-
`) + `
|
|
205
|
-
`;
|
|
206
|
-
}
|
|
207
|
-
function i(n) {
|
|
208
|
-
var l;
|
|
209
|
-
const a = n.title ? `[${n.title}](${n.url})` : n.url;
|
|
210
|
-
let s = `【系统提示:以下是用户当前正在浏览的页面上下文,请将其作为最高优先级的背景信息来理解和响应用户的请求。】
|
|
211
|
-
|
|
212
|
-
`;
|
|
213
|
-
return s += `用户现在正在浏览项目中的这个页面:${a}
|
|
214
|
-
|
|
215
|
-
`, (l = n.selectedElements) != null && l.length && (s += `用户选中了以下节点:
|
|
216
|
-
|
|
217
|
-
`, n.selectedElements.forEach((c, f) => {
|
|
218
|
-
s += o(c, f) + `
|
|
219
|
-
`;
|
|
220
|
-
})), s += `---
|
|
221
|
-
**用户的请求**:
|
|
222
|
-
|
|
223
|
-
`, s;
|
|
224
|
-
}
|
|
225
|
-
return {
|
|
226
|
-
"experimental.chat.system.transform": async (n, a) => {
|
|
227
|
-
p.debug("System transform hook called");
|
|
228
|
-
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 = `
|
|
229
157
|
你是一个专业的前端开发助手,运行在 **OpenCode** 平台中,并通过 **vite-plugin-opencode-assistant** 插件集成到用户的 Vite 开发环境。
|
|
230
158
|
|
|
231
159
|
## 你的工作环境
|
|
@@ -252,11 +180,11 @@ ${E}${b}
|
|
|
252
180
|
|
|
253
181
|
当用户与你对话时,系统会自动收集并注入以下页面上下文信息:
|
|
254
182
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
183
|
+
**选中元素**:用户在页面上选中的 DOM 元素信息,包括:
|
|
184
|
+
- 元素的预览页面 URL 和标题
|
|
185
|
+
- 元素的选择器
|
|
186
|
+
- 元素的文本内容
|
|
187
|
+
- 源码文件路径
|
|
260
188
|
|
|
261
189
|
这些信息由 Vite 插件通过内部 API 收集,并在用户发送消息时自动附加到消息前缀中。
|
|
262
190
|
|
|
@@ -272,26 +200,11 @@ ${E}${b}
|
|
|
272
200
|
|
|
273
201
|
3. **直接行动**:在明确节点位置后,针对用户的实际请求给出清晰、可执行的方案。
|
|
274
202
|
`.trim();
|
|
275
|
-
|
|
276
|
-
},
|
|
277
|
-
"experimental.chat.messages.transform": async (n, a) => {
|
|
278
|
-
var d;
|
|
279
|
-
p.debug("Message transform hook called");
|
|
280
|
-
const s = await r();
|
|
281
|
-
if (p.debug("Context data", {
|
|
282
|
-
hasUrl: !!(s != null && s.url),
|
|
283
|
-
hasElements: !!((d = s == null ? void 0 : s.selectedElements) != null && d.length)
|
|
284
|
-
}), !(s != null && s.url)) return;
|
|
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;
|
|
203
|
+
e.system.push(n);
|
|
291
204
|
}
|
|
292
|
-
};
|
|
205
|
+
}) : (g.warn("OPENCODE_CONTEXT_API_URL is not set, page context plugin will not work"), {});
|
|
293
206
|
};
|
|
294
207
|
export {
|
|
295
|
-
|
|
296
|
-
|
|
208
|
+
T as PageContextPlugin,
|
|
209
|
+
T as default
|
|
297
210
|
};
|
|
@@ -51,96 +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 formatSelectedElement(element, index) {
|
|
89
|
-
var _a, _b;
|
|
90
|
-
const parts = [];
|
|
91
|
-
parts.push(`### \u7528\u6237\u9009\u4E2D\u8282\u70B9 ${index + 1}`);
|
|
92
|
-
if (element.filePath) {
|
|
93
|
-
const isNodeModule = element.filePath.includes("node_modules");
|
|
94
|
-
if (isNodeModule) {
|
|
95
|
-
parts.push(`- **\u5143\u7D20\u9009\u62E9\u5668**: \`${element.description}\``);
|
|
96
|
-
if ((_a = element.innerText) == null ? void 0 : _a.trim()) {
|
|
97
|
-
const text = element.innerText.trim().substring(0, 100);
|
|
98
|
-
parts.push(`- **\u8282\u70B9\u6587\u672C**: \`${text}${element.innerText.length > 100 ? "..." : ""}\``);
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
let location = element.filePath;
|
|
102
|
-
if (element.line) {
|
|
103
|
-
location += `:${element.line}`;
|
|
104
|
-
if (element.column) {
|
|
105
|
-
location += `:${element.column}`;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
parts.push(`- **\u6587\u4EF6\u4F4D\u7F6E**: \`${location}\``);
|
|
109
|
-
if ((_b = element.innerText) == null ? void 0 : _b.trim()) {
|
|
110
|
-
const text = element.innerText.trim().substring(0, import_shared.MAX_TEXT_LENGTH);
|
|
111
|
-
const suffix = element.innerText.length > import_shared.MAX_TEXT_LENGTH ? "\n... (\u5DF2\u7701\u7565\u90E8\u5206\u5185\u5BB9)" : "";
|
|
112
|
-
parts.push(`- **\u8282\u70B9\u6587\u672C**:
|
|
113
|
-
\`\`\`text
|
|
114
|
-
${text}${suffix}
|
|
115
|
-
\`\`\``);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return parts.join("\n") + "\n";
|
|
120
|
-
}
|
|
121
|
-
function buildContextPrefix(context) {
|
|
122
|
-
var _a;
|
|
123
|
-
const pageLink = context.title ? `[${context.title}](${context.url})` : context.url;
|
|
124
|
-
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
|
|
125
|
-
|
|
126
|
-
`;
|
|
127
|
-
prefix += `\u7528\u6237\u73B0\u5728\u6B63\u5728\u6D4F\u89C8\u9879\u76EE\u4E2D\u7684\u8FD9\u4E2A\u9875\u9762\uFF1A${pageLink}
|
|
128
|
-
|
|
129
|
-
`;
|
|
130
|
-
if ((_a = context.selectedElements) == null ? void 0 : _a.length) {
|
|
131
|
-
prefix += `\u7528\u6237\u9009\u4E2D\u4E86\u4EE5\u4E0B\u8282\u70B9\uFF1A
|
|
132
|
-
|
|
133
|
-
`;
|
|
134
|
-
context.selectedElements.forEach((element, index) => {
|
|
135
|
-
prefix += formatSelectedElement(element, index) + "\n";
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
prefix += `---
|
|
139
|
-
**\u7528\u6237\u7684\u8BF7\u6C42**\uFF1A
|
|
140
|
-
|
|
141
|
-
`;
|
|
142
|
-
return prefix;
|
|
143
|
-
}
|
|
144
55
|
return {
|
|
145
56
|
"experimental.chat.system.transform": (_input, output) => __async(null, null, function* () {
|
|
146
57
|
log.debug("System transform hook called");
|
|
@@ -171,11 +82,11 @@ ${text}${suffix}
|
|
|
171
82
|
|
|
172
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
|
|
173
84
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
|
179
90
|
|
|
180
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
|
|
181
92
|
|
|
@@ -192,23 +103,6 @@ ${text}${suffix}
|
|
|
192
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
|
|
193
104
|
`.trim();
|
|
194
105
|
output.system.push(systemPrompt);
|
|
195
|
-
}),
|
|
196
|
-
"experimental.chat.messages.transform": (_input, output) => __async(null, null, function* () {
|
|
197
|
-
var _a;
|
|
198
|
-
log.debug("Message transform hook called");
|
|
199
|
-
const context = yield getPageContext();
|
|
200
|
-
log.debug("Context data", {
|
|
201
|
-
hasUrl: !!(context == null ? void 0 : context.url),
|
|
202
|
-
hasElements: !!((_a = context == null ? void 0 : context.selectedElements) == null ? void 0 : _a.length)
|
|
203
|
-
});
|
|
204
|
-
if (!(context == null ? void 0 : context.url)) return;
|
|
205
|
-
const lastUserMsg = [...output.messages].reverse().find((m) => m.info.role === "user");
|
|
206
|
-
if (!lastUserMsg) return;
|
|
207
|
-
const textPart = lastUserMsg.parts.find((p) => p.type === "text");
|
|
208
|
-
if (!textPart || !("text" in textPart)) return;
|
|
209
|
-
if (textPart.text.includes(import_shared.CONTEXT_MARKER)) return;
|
|
210
|
-
const prefix = buildContextPrefix(context);
|
|
211
|
-
textPart.text = prefix + textPart.text;
|
|
212
106
|
})
|
|
213
107
|
};
|
|
214
108
|
});
|
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.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.
|
|
25
|
+
"@vite-plugin-opencode-assistant/shared": "1.0.17"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@opencode-ai/plugin": "^1.3.15",
|