@vite-plugin-opencode-assistant/opencode 1.0.13 → 1.0.14

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,13 @@
1
1
  const T = "[vite-plugin-opencode]";
2
- var S = Object.defineProperty, N = Object.defineProperties, L = Object.getOwnPropertyDescriptors, w = Object.getOwnPropertySymbols, j = Object.prototype.hasOwnProperty, M = Object.prototype.propertyIsEnumerable, b = (e, t, r) => t in e ? S(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, g = (e, t) => {
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) => {
3
4
  for (var r in t || (t = {}))
4
- j.call(t, r) && b(e, r, t[r]);
5
- if (w)
6
- for (var r of w(t))
5
+ L.call(t, r) && b(e, r, t[r]);
6
+ if (x)
7
+ for (var r of x(t))
7
8
  M.call(t, r) && b(e, r, t[r]);
8
9
  return e;
9
- }, m = (e, t) => N(e, L(t)), y = (e, t, r) => b(e, typeof t != "symbol" ? t + "" : t, r);
10
+ }, m = (e, t) => S(e, N(t)), O = (e, t, r) => b(e, typeof t != "symbol" ? t + "" : t, r);
10
11
  const c = {
11
12
  reset: "\x1B[0m",
12
13
  dim: "\x1B[2m",
@@ -16,7 +17,7 @@ const c = {
16
17
  yellow: "\x1B[33m",
17
18
  magenta: "\x1B[35m",
18
19
  cyan: "\x1B[36m"
19
- }, R = {
20
+ }, j = {
20
21
  0: c.cyan,
21
22
  1: c.green,
22
23
  2: c.yellow,
@@ -29,15 +30,15 @@ const c = {
29
30
  3: "ERROR",
30
31
  4: "NONE"
31
32
  };
32
- let x = {
33
- level: 1,
34
- showTrace: !1
33
+ let R = {
34
+ level: 1
35
+ /* INFO */
35
36
  };
36
- function I() {
37
+ function B() {
37
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");
38
39
  return `${t}:${r}:${o}.${i}`;
39
40
  }
40
- function U(e = 3) {
41
+ function I(e = 3) {
41
42
  const t = new Error().stack;
42
43
  if (!t) return "";
43
44
  const o = t.split(`
@@ -48,7 +49,7 @@ function U(e = 3) {
48
49
  const [, p, n, a] = i;
49
50
  return `${n.split("/").pop() || n}:${a} ${p || "<anonymous>"}`;
50
51
  }
51
- function $(e, t = 0) {
52
+ function h(e, t = 0) {
52
53
  if (t > 3) return "...";
53
54
  if (e === null) return "null";
54
55
  if (e === void 0) return "undefined";
@@ -58,14 +59,14 @@ function $(e, t = 0) {
58
59
  return `${e.name}: ${e.message}${e.stack ? `
59
60
  ${e.stack}` : ""}`;
60
61
  if (Array.isArray(e))
61
- return e.length === 0 ? "[]" : e.length > 5 ? `[${e.slice(0, 3).map((i) => $(i, t + 1)).join(", ")}, ... ${e.length - 3} more items]` : `[${e.map((o) => $(o, t + 1)).join(", ")}]`;
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(", ")}]`;
62
63
  if (typeof e == "object") {
63
64
  const r = Object.entries(e);
64
- return r.length === 0 ? "{}" : r.length > 5 ? `{${r.slice(0, 3).map(([p, n]) => `${p}: ${$(n, t + 1)}`).join(", ")}, ... ${r.length - 3} more keys}` : `{${r.map(([i, p]) => `${i}: ${$(p, t + 1)}`).join(", ")}}`;
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(", ")}}`;
65
66
  }
66
67
  return String(e);
67
68
  }
68
- function B(e) {
69
+ function U(e) {
69
70
  if (!e || Object.keys(e).length === 0) return "";
70
71
  const t = [];
71
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`);
@@ -74,27 +75,30 @@ function B(e) {
74
75
  );
75
76
  if (r.length > 0) {
76
77
  const o = {};
77
- r.forEach((i) => o[i] = e[i]), t.push($(o));
78
+ r.forEach((i) => o[i] = e[i]), t.push(h(o));
78
79
  }
79
80
  return t.join(" ");
80
81
  }
81
82
  function P(e, t, r, ...o) {
82
- if (e < x.level) return;
83
+ if (e < R.level) return;
83
84
  const i = [];
84
- i.push(`${c.dim}[${process.pid}]${c.reset}`), i.push(`${c.dim}${I()}${c.reset}`);
85
- const p = R[e], n = A[e].padEnd(5);
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);
86
87
  i.push(`${p}${n}${c.reset}`), i.push(`${c.bright}${T}${c.reset}`);
87
- const a = B(r);
88
+ const a = U(r);
88
89
  if (a && i.push(`${c.magenta}${a}${c.reset}`), i.push(t), e >= 2) {
89
- const u = U(4);
90
+ const u = I(4);
90
91
  u && i.push(`${c.dim}(${u})${c.reset}`);
91
92
  }
92
- const s = o.map((u) => $(u)).join(" ");
93
- s && i.push(s);
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}`);
97
+ }
94
98
  const f = i.join(" ");
95
- e >= 3 ? console.error(f) : e === 2 ? console.warn(f) : console.log(f), r != null && r.error && e >= 3 && x.showTrace;
99
+ e >= 3 ? console.error(f) : e === 2 ? console.warn(f) : console.log(f);
96
100
  }
97
- const h = {
101
+ const $ = {
98
102
  debug(e, t, ...r) {
99
103
  P(0, e, t, ...r);
100
104
  },
@@ -114,37 +118,37 @@ const h = {
114
118
  };
115
119
  class D {
116
120
  constructor(t, r) {
117
- y(this, "startTime"), y(this, "context"), y(this, "operation"), this.operation = t, this.context = r || {}, this.startTime = performance.now(), h.debug(`⏱️ Starting: ${t}`, this.context);
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
122
  }
119
123
  end(t) {
120
124
  const r = Math.round(performance.now() - this.startTime), o = t || `✓ Completed: ${this.operation}`;
121
- return h.debug(o, m(g({}, this.context), { duration: r })), r;
125
+ return $.debug(o, m(g({}, this.context), { duration: r })), r;
122
126
  }
123
127
  checkpoint(t) {
124
128
  const r = Math.round(performance.now() - this.startTime);
125
- return h.debug(` ↳ ${t}`, m(g({}, this.context), { duration: r })), r;
129
+ return $.debug(` ↳ ${t}`, m(g({}, this.context), { duration: r })), r;
126
130
  }
127
131
  }
128
132
  function k(e) {
129
133
  return {
130
134
  debug(t, r, ...o) {
131
- h.debug(t, m(g({}, r), { module: e }), ...o);
135
+ $.debug(t, m(g({}, r), { module: e }), ...o);
132
136
  },
133
137
  info(t, r, ...o) {
134
- h.info(t, m(g({}, r), { module: e }), ...o);
138
+ $.info(t, m(g({}, r), { module: e }), ...o);
135
139
  },
136
140
  warn(t, r, ...o) {
137
- h.warn(t, m(g({}, r), { module: e }), ...o);
141
+ $.warn(t, m(g({}, r), { module: e }), ...o);
138
142
  },
139
143
  error(t, r, ...o) {
140
- h.error(t, m(g({}, r), { module: e }), ...o);
144
+ $.error(t, m(g({}, r), { module: e }), ...o);
141
145
  },
142
146
  timer(t, r) {
143
147
  return new D(t, m(g({}, r), { module: e }));
144
148
  }
145
149
  };
146
150
  }
147
- const C = 1e4, F = "__OPENCODE_CONTEXT__", l = k("OpenCodePluginPageContext"), V = async () => {
151
+ const l = k("OpenCodePluginPageContext"), X = async () => {
148
152
  l.info("PageContextPlugin loading...");
149
153
  const e = process.env.OPENCODE_CONTEXT_API_URL;
150
154
  if (l.debug("Context API URL:", { contextApiUrl: e }), !e)
@@ -205,11 +209,11 @@ const C = 1e4, F = "__OPENCODE_CONTEXT__", l = k("OpenCodePluginPageContext"), V
205
209
  } else {
206
210
  let d = n.filePath;
207
211
  if (n.line && (d += `:${n.line}`, n.column && (d += `:${n.column}`)), s.push(`- **文件位置**: \`${d}\``), (u = n.innerText) != null && u.trim()) {
208
- const O = n.innerText.trim().substring(0, C), E = n.innerText.length > C ? `
212
+ const y = n.innerText.trim().substring(0, 100), E = n.innerText.length > 100 ? `
209
213
  ... (已省略部分内容)` : "";
210
214
  s.push(`- **节点文本**:
211
215
  \`\`\`text
212
- ${O}${E}
216
+ ${y}${E}
213
217
  \`\`\``);
214
218
  }
215
219
  }
@@ -301,7 +305,7 @@ ${O}${E}
301
305
  a.system.push(s);
302
306
  },
303
307
  "experimental.chat.messages.transform": async (n, a) => {
304
- var d, O;
308
+ var d, y;
305
309
  l.debug("Message transform hook called");
306
310
  const s = await r();
307
311
  if (l.debug("Context data", {
@@ -311,13 +315,13 @@ ${O}${E}
311
315
  const f = [...a.messages].reverse().find((E) => E.info.role === "user");
312
316
  if (!f) return;
313
317
  const u = f.parts.find((E) => E.type === "text");
314
- if (!u || !("text" in u) || u.text.includes(F)) return;
318
+ if (!u || !("text" in u) || u.text.includes(w)) return;
315
319
  const _ = p(s);
316
- u.text = _ + u.text, (O = s.selectedElements) != null && O.length && (l.debug("Selected elements found, clearing..."), await o());
320
+ u.text = _ + u.text, (y = s.selectedElements) != null && y.length && (l.debug("Selected elements found, clearing..."), await o());
317
321
  }
318
322
  };
319
323
  };
320
324
  export {
321
- V as PageContextPlugin,
322
- V as default
325
+ X as PageContextPlugin,
326
+ X as default
323
327
  };
@@ -42,8 +42,6 @@ __export(page_context_exports, {
42
42
  });
43
43
  module.exports = __toCommonJS(page_context_exports);
44
44
  var import_shared = require("@vite-plugin-opencode-assistant/shared");
45
- const MAX_TEXT_LENGTH = 1e4;
46
- const CONTEXT_MARKER = "__OPENCODE_CONTEXT__";
47
45
  const log = (0, import_shared.createLogger)("OpenCodePluginPageContext");
48
46
  const PageContextPlugin = () => __async(null, null, function* () {
49
47
  log.info("PageContextPlugin loading...");
@@ -129,8 +127,8 @@ const PageContextPlugin = () => __async(null, null, function* () {
129
127
  }
130
128
  parts.push(`- **\u6587\u4EF6\u4F4D\u7F6E**: \`${location}\``);
131
129
  if ((_b = element.innerText) == null ? void 0 : _b.trim()) {
132
- const text = element.innerText.trim().substring(0, MAX_TEXT_LENGTH);
133
- const suffix = element.innerText.length > MAX_TEXT_LENGTH ? "\n... (\u5DF2\u7701\u7565\u90E8\u5206\u5185\u5BB9)" : "";
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)" : "";
134
132
  parts.push(`- **\u8282\u70B9\u6587\u672C**:
135
133
  \`\`\`text
136
134
  ${text}${suffix}
@@ -241,7 +239,7 @@ ${text}${suffix}
241
239
  if (!lastUserMsg) return;
242
240
  const textPart = lastUserMsg.parts.find((p) => p.type === "text");
243
241
  if (!textPart || !("text" in textPart)) return;
244
- if (textPart.text.includes(CONTEXT_MARKER)) return;
242
+ if (textPart.text.includes(import_shared.CONTEXT_MARKER)) return;
245
243
  const prefix = buildContextPrefix(context);
246
244
  textPart.text = prefix + textPart.text;
247
245
  if ((_b = context.selectedElements) == null ? void 0 : _b.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-plugin-opencode-assistant/opencode",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
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.13"
25
+ "@vite-plugin-opencode-assistant/shared": "1.0.14"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@opencode-ai/plugin": "^1.3.15",
@@ -30,6 +30,6 @@
30
30
  },
31
31
  "scripts": {
32
32
  "build": "pagoda-cli build && vite build -c vite.plugin.config.ts",
33
- "typecheck": "tsc -p tsconfig.json --noEmit"
33
+ "typecheck": "tsc -p tsconfig.declaration.json --noEmit"
34
34
  }
35
35
  }