@vite-plugin-opencode-assistant/opencode 1.0.20 → 1.0.22

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,12 +1,12 @@
1
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]);
2
+ var E = Object.defineProperty, b = Object.defineProperties, w = Object.getOwnPropertyDescriptors, y = Object.getOwnPropertySymbols, C = Object.prototype.hasOwnProperty, S = Object.prototype.propertyIsEnumerable, _ = (r, e, t) => e in r ? E(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, c = (r, e) => {
3
+ for (var t in e || (e = {}))
4
+ C.call(e, t) && _(r, t, e[t]);
5
5
  if (y)
6
- for (var e of y(t))
7
- C.call(t, e) && _(r, e, t[e]);
6
+ for (var t of y(e))
7
+ S.call(e, t) && _(r, t, e[t]);
8
8
  return r;
9
- }, p = (r, t) => w(r, b(t)), O = (r, t, e) => _(r, typeof t != "symbol" ? t + "" : t, e);
9
+ }, p = (r, e) => b(r, w(e)), O = (r, e, t) => _(r, typeof e != "symbol" ? e + "" : e, t);
10
10
  const s = {
11
11
  reset: "\x1B[0m",
12
12
  dim: "\x1B[2m",
@@ -34,13 +34,13 @@ let N = {
34
34
  /* INFO */
35
35
  };
36
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}`;
37
+ const r = /* @__PURE__ */ new Date(), e = String(r.getHours()).padStart(2, "0"), t = String(r.getMinutes()).padStart(2, "0"), n = String(r.getSeconds()).padStart(2, "0"), o = String(r.getMilliseconds()).padStart(3, "0");
38
+ return `${e}:${t}:${n}.${o}`;
39
39
  }
40
40
  function R(r = 3) {
41
- const t = new Error().stack;
42
- if (!t) return "";
43
- const n = t.split(`
41
+ const e = new Error().stack;
42
+ if (!e) return "";
43
+ const n = e.split(`
44
44
  `)[r];
45
45
  if (!n) return "";
46
46
  const o = n.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/);
@@ -48,110 +48,110 @@ function R(r = 3) {
48
48
  const [, a, m, l] = o;
49
49
  return `${m.split("/").pop() || m}:${l} ${a || "<anonymous>"}`;
50
50
  }
51
- function u(r, t = 0) {
52
- if (t > 3) return "...";
51
+ function u(r, e = 0) {
52
+ if (e > 3) return "...";
53
53
  if (r === null) return "null";
54
54
  if (r === void 0) return "undefined";
55
- if (typeof r == "string") return t > 0 ? `"${r}"` : r;
55
+ if (typeof r == "string") return e > 0 ? `"${r}"` : r;
56
56
  if (typeof r == "number" || typeof r == "boolean") return String(r);
57
57
  if (r instanceof Error)
58
58
  return `${r.name}: ${r.message}${r.stack ? `
59
59
  ${r.stack}` : ""}`;
60
60
  if (Array.isArray(r))
61
- return r.length === 0 ? "[]" : r.length > 5 ? `[${r.slice(0, 3).map((o) => u(o, t + 1)).join(", ")}, ... ${r.length - 3} more items]` : `[${r.map((n) => u(n, t + 1)).join(", ")}]`;
61
+ return r.length === 0 ? "[]" : r.length > 5 ? `[${r.slice(0, 3).map((o) => u(o, e + 1)).join(", ")}, ... ${r.length - 3} more items]` : `[${r.map((n) => u(n, e + 1)).join(", ")}]`;
62
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}: ${u(m, t + 1)}`).join(", ")}, ... ${e.length - 3} more keys}` : `{${e.map(([o, a]) => `${o}: ${u(a, t + 1)}`).join(", ")}}`;
63
+ const t = Object.entries(r);
64
+ return t.length === 0 ? "{}" : t.length > 5 ? `{${t.slice(0, 3).map(([a, m]) => `${a}: ${u(m, e + 1)}`).join(", ")}, ... ${t.length - 3} more keys}` : `{${t.map(([o, a]) => `${o}: ${u(a, e + 1)}`).join(", ")}}`;
65
65
  }
66
66
  return String(r);
67
67
  }
68
- function I(r) {
68
+ function T(r) {
69
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(
70
+ const e = [];
71
+ r.module && e.push(`[${r.module}]`), r.operation && e.push(`(${r.operation})`), r.traceId && e.push(`trace:${r.traceId}`), r.duration !== void 0 && e.push(`${r.duration}ms`);
72
+ const t = Object.keys(r).filter(
73
73
  (n) => !["module", "operation", "traceId", "duration", "error"].includes(n)
74
74
  );
75
- if (e.length > 0) {
75
+ if (t.length > 0) {
76
76
  const n = {};
77
- e.forEach((o) => n[o] = r[o]), t.push(u(n));
77
+ t.forEach((o) => n[o] = r[o]), e.push(u(n));
78
78
  }
79
- return t.join(" ");
79
+ return e.join(" ");
80
80
  }
81
- function $(r, t, e, ...n) {
81
+ function $(r, e, t, ...n) {
82
82
  if (r < N.level) return;
83
83
  const o = [];
84
84
  o.push(`${s.dim}[${process.pid}]${s.reset}`), o.push(`${s.dim}${x()}${s.reset}`);
85
85
  const a = j[r], m = L[r].padEnd(5);
86
86
  o.push(`${a}${m}${s.reset}`), o.push(`${s.bright}${P}${s.reset}`);
87
- const l = I(e);
88
- if (l && o.push(`${s.magenta}${l}${s.reset}`), o.push(t), r >= 2) {
87
+ const l = T(t);
88
+ if (l && o.push(`${s.magenta}${l}${s.reset}`), o.push(e), r >= 2) {
89
89
  const i = R(4);
90
90
  i && o.push(`${s.dim}(${i})${s.reset}`);
91
91
  }
92
92
  const h = n.map((i) => u(i)).join(" ");
93
- if (h && o.push(h), e != null && e.error) {
94
- const i = e.error;
93
+ if (h && o.push(h), t != null && t.error) {
94
+ const i = t.error;
95
95
  i instanceof Error ? o.push(`${s.red}Error: ${i.message}${s.reset}`) : o.push(`${s.red}Error: ${u(i)}${s.reset}`);
96
96
  }
97
97
  const d = o.join(" ");
98
98
  r >= 3 ? console.error(d) : r === 2 ? console.warn(d) : console.log(d);
99
99
  }
100
100
  const f = {
101
- debug(r, t, ...e) {
102
- $(0, r, t, ...e);
101
+ debug(r, e, ...t) {
102
+ $(0, r, e, ...t);
103
103
  },
104
- info(r, t, ...e) {
105
- $(1, r, t, ...e);
104
+ info(r, e, ...t) {
105
+ $(1, r, e, ...t);
106
106
  },
107
- warn(r, t, ...e) {
108
- $(2, r, t, ...e);
107
+ warn(r, e, ...t) {
108
+ $(2, r, e, ...t);
109
109
  },
110
- error(r, t, ...e) {
111
- $(3, r, t, ...e);
110
+ error(r, e, ...t) {
111
+ $(3, r, e, ...t);
112
112
  },
113
- group(r, t) {
113
+ group(r, e) {
114
114
  },
115
115
  groupEnd() {
116
116
  }
117
117
  };
118
- class T {
119
- constructor(t, e) {
120
- O(this, "startTime"), O(this, "context"), O(this, "operation"), this.operation = t, this.context = e || {}, this.startTime = performance.now(), f.debug(`⏱️ Starting: ${t}`, this.context);
118
+ class I {
119
+ constructor(e, t) {
120
+ O(this, "startTime"), O(this, "context"), O(this, "operation"), this.operation = e, this.context = t || {}, this.startTime = performance.now(), f.debug(`⏱️ Starting: ${e}`, this.context);
121
121
  }
122
- end(t) {
123
- const e = Math.round(performance.now() - this.startTime), n = t || `✓ Completed: ${this.operation}`;
124
- return f.debug(n, p(c({}, this.context), { duration: e })), e;
122
+ end(e) {
123
+ const t = Math.round(performance.now() - this.startTime), n = e || `✓ Completed: ${this.operation}`;
124
+ return f.debug(n, p(c({}, this.context), { duration: t })), t;
125
125
  }
126
- checkpoint(t) {
127
- const e = Math.round(performance.now() - this.startTime);
128
- return f.debug(` ↳ ${t}`, p(c({}, this.context), { duration: e })), e;
126
+ checkpoint(e) {
127
+ const t = Math.round(performance.now() - this.startTime);
128
+ return f.debug(` ↳ ${e}`, p(c({}, this.context), { duration: t })), t;
129
129
  }
130
130
  }
131
131
  function B(r) {
132
132
  return {
133
- debug(t, e, ...n) {
134
- f.debug(t, p(c({}, e), { module: r }), ...n);
133
+ debug(e, t, ...n) {
134
+ f.debug(e, p(c({}, t), { module: r }), ...n);
135
135
  },
136
- info(t, e, ...n) {
137
- f.info(t, p(c({}, e), { module: r }), ...n);
136
+ info(e, t, ...n) {
137
+ f.info(e, p(c({}, t), { module: r }), ...n);
138
138
  },
139
- warn(t, e, ...n) {
140
- f.warn(t, p(c({}, e), { module: r }), ...n);
139
+ warn(e, t, ...n) {
140
+ f.warn(e, p(c({}, t), { module: r }), ...n);
141
141
  },
142
- error(t, e, ...n) {
143
- f.error(t, p(c({}, e), { module: r }), ...n);
142
+ error(e, t, ...n) {
143
+ f.error(e, p(c({}, t), { module: r }), ...n);
144
144
  },
145
- timer(t, e) {
146
- return new T(t, p(c({}, e), { module: r }));
145
+ timer(e, t) {
146
+ return new I(e, p(c({}, t), { module: r }));
147
147
  }
148
148
  };
149
149
  }
150
- const g = B("OpenCodePluginPageContext"), A = async () => {
150
+ const g = B("OpenCodePluginPageContext"), D = async () => {
151
151
  g.info("PageContextPlugin loading...");
152
152
  const r = process.env.OPENCODE_CONTEXT_API_URL;
153
153
  return g.debug("Context API URL:", { contextApiUrl: r }), r ? (g.info("Plugin initialized successfully"), {
154
- "experimental.chat.system.transform": async (t, e) => {
154
+ "experimental.chat.system.transform": async (e, t) => {
155
155
  g.debug("System transform hook called");
156
156
  const n = `
157
157
  你是一个专业的前端开发助手,运行在 **OpenCode** 平台中,并通过 **vite-plugin-opencode-assistant** 插件集成到用户的 Vite 开发环境。
@@ -189,12 +189,16 @@ const g = B("OpenCodePluginPageContext"), A = async () => {
189
189
  2. **理解上下文**:将页面 URL、标题和选中节点信息作为用户请求的背景,帮助理解用户的真实意图。
190
190
 
191
191
  3. **直接行动**:在明确节点位置后,针对用户的实际请求给出清晰、可执行的方案。
192
+
193
+ ### Chrome DevTools Mcp 最佳实践
194
+
195
+ 1. **快照获取** 在没有获取到需要的节点信息时,使用 verbose 模式来获取更详细的节点信息。
192
196
  `.trim();
193
- e.system.push(n);
197
+ t.system.push(n);
194
198
  }
195
199
  }) : (g.warn("OPENCODE_CONTEXT_API_URL is not set, page context plugin will not work"), {});
196
200
  };
197
201
  export {
198
- A as PageContextPlugin,
199
- A as default
202
+ D as PageContextPlugin,
203
+ D as default
200
204
  };
@@ -91,6 +91,10 @@ const PageContextPlugin = () => __async(null, null, function* () {
91
91
  2. **\u7406\u89E3\u4E0A\u4E0B\u6587**\uFF1A\u5C06\u9875\u9762 URL\u3001\u6807\u9898\u548C\u9009\u4E2D\u8282\u70B9\u4FE1\u606F\u4F5C\u4E3A\u7528\u6237\u8BF7\u6C42\u7684\u80CC\u666F\uFF0C\u5E2E\u52A9\u7406\u89E3\u7528\u6237\u7684\u771F\u5B9E\u610F\u56FE\u3002
92
92
 
93
93
  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
94
+
95
+ ### Chrome DevTools Mcp \u6700\u4F73\u5B9E\u8DF5
96
+
97
+ 1. **\u5FEB\u7167\u83B7\u53D6** \u5728\u6CA1\u6709\u83B7\u53D6\u5230\u9700\u8981\u7684\u8282\u70B9\u4FE1\u606F\u65F6\uFF0C\u4F7F\u7528 verbose \u6A21\u5F0F\u6765\u83B7\u53D6\u66F4\u8BE6\u7EC6\u7684\u8282\u70B9\u4FE1\u606F\u3002
94
98
  `.trim();
95
99
  output.system.push(systemPrompt);
96
100
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-plugin-opencode-assistant/opencode",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
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.20"
25
+ "@vite-plugin-opencode-assistant/shared": "1.0.22"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@opencode-ai/plugin": "^1.3.15",