@vite-plugin-opencode-assistant/opencode 1.0.30 → 1.0.32

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.
@@ -0,0 +1,152 @@
1
+ const b = "[vite-plugin-opencode]";
2
+ var w = Object.defineProperty, y = Object.defineProperties, E = Object.getOwnPropertyDescriptors, _ = Object.getOwnPropertySymbols, S = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable, O = (r, t, e) => t in r ? w(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) && O(r, e, t[e]);
5
+ if (_)
6
+ for (var e of _(t))
7
+ j.call(t, e) && O(r, e, t[e]);
8
+ return r;
9
+ }, f = (r, t) => y(r, E(t)), h = (r, t, e) => O(r, typeof t != "symbol" ? t + "" : t, e);
10
+ const s = {
11
+ reset: "\x1B[0m",
12
+ dim: "\x1B[2m",
13
+ bright: "\x1B[1m",
14
+ red: "\x1B[31m",
15
+ green: "\x1B[32m",
16
+ yellow: "\x1B[33m",
17
+ magenta: "\x1B[35m",
18
+ cyan: "\x1B[36m"
19
+ }, P = {
20
+ 0: s.cyan,
21
+ 1: s.green,
22
+ 2: s.yellow,
23
+ 3: s.red,
24
+ 4: s.reset
25
+ }, B = {
26
+ 0: "DEBUG",
27
+ 1: "INFO",
28
+ 2: "WARN",
29
+ 3: "ERROR",
30
+ 4: "NONE"
31
+ };
32
+ let N = {
33
+ level: 1
34
+ /* INFO */
35
+ };
36
+ function L() {
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}`;
39
+ }
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+)\)?/);
47
+ if (!o) return "";
48
+ const [, a, m, g] = o;
49
+ return `${m.split("/").pop() || m}:${g} ${a || "<anonymous>"}`;
50
+ }
51
+ function p(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) => p(o, t + 1)).join(", ")}, ... ${r.length - 3} more items]` : `[${r.map((n) => p(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}: ${p(m, t + 1)}`).join(", ")}, ... ${e.length - 3} more keys}` : `{${e.map(([o, a]) => `${o}: ${p(a, t + 1)}`).join(", ")}}`;
65
+ }
66
+ return String(r);
67
+ }
68
+ function C(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)
74
+ );
75
+ if (e.length > 0) {
76
+ const n = {};
77
+ e.forEach((o) => n[o] = r[o]), t.push(p(n));
78
+ }
79
+ return t.join(" ");
80
+ }
81
+ function d(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}${L()}${s.reset}`);
85
+ const a = P[r], m = B[r].padEnd(5);
86
+ o.push(`${a}${m}${s.reset}`), o.push(`${s.bright}${b}${s.reset}`);
87
+ const g = C(e);
88
+ if (g && o.push(`${s.magenta}${g}${s.reset}`), o.push(t), r >= 2) {
89
+ const i = I(4);
90
+ i && o.push(`${s.dim}(${i})${s.reset}`);
91
+ }
92
+ const l = n.map((i) => p(i)).join(" ");
93
+ if (l && o.push(l), 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: ${p(i)}${s.reset}`);
96
+ }
97
+ const $ = o.join(" ");
98
+ r >= 3 ? console.error($) : r === 2 ? console.warn($) : console.log($);
99
+ }
100
+ const u = {
101
+ debug(r, t, ...e) {
102
+ d(0, r, t, ...e);
103
+ },
104
+ info(r, t, ...e) {
105
+ d(1, r, t, ...e);
106
+ },
107
+ warn(r, t, ...e) {
108
+ d(2, r, t, ...e);
109
+ },
110
+ error(r, t, ...e) {
111
+ d(3, r, t, ...e);
112
+ },
113
+ group(r, t) {
114
+ },
115
+ groupEnd() {
116
+ }
117
+ };
118
+ class R {
119
+ constructor(t, e) {
120
+ h(this, "startTime"), h(this, "context"), h(this, "operation"), this.operation = t, this.context = e || {}, this.startTime = performance.now(), u.debug(`⏱️ Starting: ${t}`, this.context);
121
+ }
122
+ end(t) {
123
+ const e = Math.round(performance.now() - this.startTime), n = t || `✓ Completed: ${this.operation}`;
124
+ return u.debug(n, f(c({}, this.context), { duration: e })), e;
125
+ }
126
+ checkpoint(t) {
127
+ const e = Math.round(performance.now() - this.startTime);
128
+ return u.debug(` ↳ ${t}`, f(c({}, this.context), { duration: e })), e;
129
+ }
130
+ }
131
+ function F(r) {
132
+ return {
133
+ debug(t, e, ...n) {
134
+ u.debug(t, f(c({}, e), { module: r }), ...n);
135
+ },
136
+ info(t, e, ...n) {
137
+ u.info(t, f(c({}, e), { module: r }), ...n);
138
+ },
139
+ warn(t, e, ...n) {
140
+ u.warn(t, f(c({}, e), { module: r }), ...n);
141
+ },
142
+ error(t, e, ...n) {
143
+ u.error(t, f(c({}, e), { module: r }), ...n);
144
+ },
145
+ timer(t, e) {
146
+ return new R(t, f(c({}, e), { module: r }));
147
+ }
148
+ };
149
+ }
150
+ export {
151
+ F as c
152
+ };
@@ -1,184 +1,36 @@
1
- const _ = "[vite-plugin-opencode]";
2
- var b = Object.defineProperty, w = Object.defineProperties, E = Object.getOwnPropertyDescriptors, y = Object.getOwnPropertySymbols, C = Object.prototype.hasOwnProperty, S = Object.prototype.propertyIsEnumerable, O = (e, t, r) => t in e ? b(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, u = (e, t) => {
3
- for (var r in t || (t = {}))
4
- C.call(t, r) && O(e, r, t[r]);
5
- if (y)
6
- for (var r of y(t))
7
- S.call(t, r) && O(e, r, t[r]);
8
- return e;
9
- }, p = (e, t) => w(e, E(t)), P = (e, t, r) => O(e, typeof t != "symbol" ? t + "" : t, r);
10
- const s = {
11
- reset: "\x1B[0m",
12
- dim: "\x1B[2m",
13
- bright: "\x1B[1m",
14
- red: "\x1B[31m",
15
- green: "\x1B[32m",
16
- yellow: "\x1B[33m",
17
- magenta: "\x1B[35m",
18
- cyan: "\x1B[36m"
19
- }, T = {
20
- 0: s.cyan,
21
- 1: s.green,
22
- 2: s.yellow,
23
- 3: s.red,
24
- 4: s.reset
25
- }, j = {
26
- 0: "DEBUG",
27
- 1: "INFO",
28
- 2: "WARN",
29
- 3: "ERROR",
30
- 4: "NONE"
31
- };
32
- let x = {
33
- level: 1
34
- /* INFO */
35
- };
36
- function L() {
37
- const e = /* @__PURE__ */ new Date(), t = String(e.getHours()).padStart(2, "0"), r = String(e.getMinutes()).padStart(2, "0"), n = String(e.getSeconds()).padStart(2, "0"), o = String(e.getMilliseconds()).padStart(3, "0");
38
- return `${t}:${r}:${n}.${o}`;
39
- }
40
- function N(e = 3) {
41
- const t = new Error().stack;
42
- if (!t) return "";
43
- const n = t.split(`
44
- `)[e];
45
- if (!n) return "";
46
- const o = n.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/);
47
- if (!o) return "";
48
- const [, i, m, l] = o;
49
- return `${m.split("/").pop() || m}:${l} ${i || "<anonymous>"}`;
50
- }
51
- function f(e, t = 0) {
52
- if (t > 3) return "...";
53
- if (e === null) return "null";
54
- if (e === void 0) return "undefined";
55
- if (typeof e == "string") return t > 0 ? `"${e}"` : e;
56
- if (typeof e == "number" || typeof e == "boolean") return String(e);
57
- if (e instanceof Error)
58
- return `${e.name}: ${e.message}${e.stack ? `
59
- ${e.stack}` : ""}`;
60
- if (Array.isArray(e))
61
- return e.length === 0 ? "[]" : e.length > 5 ? `[${e.slice(0, 3).map((o) => f(o, t + 1)).join(", ")}, ... ${e.length - 3} more items]` : `[${e.map((n) => f(n, t + 1)).join(", ")}]`;
62
- if (typeof e == "object") {
63
- const r = Object.entries(e);
64
- return r.length === 0 ? "{}" : r.length > 5 ? `{${r.slice(0, 3).map(([i, m]) => `${i}: ${f(m, t + 1)}`).join(", ")}, ... ${r.length - 3} more keys}` : `{${r.map(([o, i]) => `${o}: ${f(i, t + 1)}`).join(", ")}}`;
65
- }
66
- return String(e);
67
- }
68
- function R(e) {
69
- if (!e || Object.keys(e).length === 0) return "";
70
- const t = [];
71
- 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`);
72
- const r = Object.keys(e).filter(
73
- (n) => !["module", "operation", "traceId", "duration", "error"].includes(n)
74
- );
75
- if (r.length > 0) {
76
- const n = {};
77
- r.forEach((o) => n[o] = e[o]), t.push(f(n));
78
- }
79
- return t.join(" ");
80
- }
81
- function h(e, t, r, ...n) {
82
- if (e < x.level) return;
83
- const o = [];
84
- o.push(`${s.dim}[${process.pid}]${s.reset}`), o.push(`${s.dim}${L()}${s.reset}`);
85
- const i = T[e], m = j[e].padEnd(5);
86
- o.push(`${i}${m}${s.reset}`), o.push(`${s.bright}${_}${s.reset}`);
87
- const l = R(r);
88
- if (l && o.push(`${s.magenta}${l}${s.reset}`), o.push(t), e >= 2) {
89
- const a = N(4);
90
- a && o.push(`${s.dim}(${a})${s.reset}`);
91
- }
92
- const $ = n.map((a) => f(a)).join(" ");
93
- if ($ && o.push($), r != null && r.error) {
94
- const a = r.error;
95
- a instanceof Error ? o.push(`${s.red}Error: ${a.message}${s.reset}`) : o.push(`${s.red}Error: ${f(a)}${s.reset}`);
96
- }
97
- const d = o.join(" ");
98
- e >= 3 ? console.error(d) : e === 2 ? console.warn(d) : console.log(d);
99
- }
100
- const g = {
101
- debug(e, t, ...r) {
102
- h(0, e, t, ...r);
103
- },
104
- info(e, t, ...r) {
105
- h(1, e, t, ...r);
106
- },
107
- warn(e, t, ...r) {
108
- h(2, e, t, ...r);
109
- },
110
- error(e, t, ...r) {
111
- h(3, e, t, ...r);
112
- },
113
- group(e, t) {
114
- },
115
- groupEnd() {
116
- }
117
- };
118
- class A {
119
- constructor(t, r) {
120
- P(this, "startTime"), P(this, "context"), P(this, "operation"), this.operation = t, this.context = r || {}, this.startTime = performance.now(), g.debug(`⏱️ Starting: ${t}`, this.context);
121
- }
122
- end(t) {
123
- const r = Math.round(performance.now() - this.startTime), n = t || `✓ Completed: ${this.operation}`;
124
- return g.debug(n, p(u({}, this.context), { duration: r })), r;
125
- }
126
- checkpoint(t) {
127
- const r = Math.round(performance.now() - this.startTime);
128
- return g.debug(` ↳ ${t}`, p(u({}, this.context), { duration: r })), r;
129
- }
130
- }
131
- function I(e) {
132
- return {
133
- debug(t, r, ...n) {
134
- g.debug(t, p(u({}, r), { module: e }), ...n);
135
- },
136
- info(t, r, ...n) {
137
- g.info(t, p(u({}, r), { module: e }), ...n);
138
- },
139
- warn(t, r, ...n) {
140
- g.warn(t, p(u({}, r), { module: e }), ...n);
141
- },
142
- error(t, r, ...n) {
143
- g.error(t, p(u({}, r), { module: e }), ...n);
144
- },
145
- timer(t, r) {
146
- return new A(t, p(u({}, r), { module: e }));
147
- }
148
- };
149
- }
150
- const c = I("OpenCodePluginPageContext");
151
- async function B(e) {
1
+ import { c as i } from "./logger.js";
2
+ const e = i("OpenCodePluginPageContext");
3
+ async function c(n) {
152
4
  try {
153
- const t = await fetch(e, {
5
+ const t = await fetch(n, {
154
6
  method: "GET",
155
7
  headers: { "Content-Type": "application/json" }
156
8
  });
157
- return t.ok ? await t.json() : (c.debug("Failed to fetch page context", { status: t.status }), null);
9
+ return t.ok ? await t.json() : (e.debug("Failed to fetch page context", { status: t.status }), null);
158
10
  } catch (t) {
159
- return c.debug("Error fetching page context", { error: t }), null;
11
+ return e.debug("Error fetching page context", { error: t }), null;
160
12
  }
161
13
  }
162
- const D = async () => {
163
- c.info("PageContextPlugin loading...");
164
- const e = process.env.OPENCODE_CONTEXT_API_URL;
165
- return c.debug("Context API URL:", { contextApiUrl: e }), e ? (c.info("Plugin initialized successfully"), {
166
- "experimental.chat.system.transform": async (t, r) => {
167
- c.debug("System transform hook called");
168
- const n = await B(e);
169
- c.debug("Page context fetched", { pageContext: n });
170
- let o = "";
171
- n && (o = `
14
+ const u = async () => {
15
+ e.info("PageContextPlugin loading...");
16
+ const n = process.env.OPENCODE_CONTEXT_API_URL;
17
+ return e.debug("Context API URL:", { contextApiUrl: n }), n ? (e.info("Plugin initialized successfully"), {
18
+ "experimental.chat.system.transform": async (t, s) => {
19
+ e.debug("System transform hook called");
20
+ const o = await c(n);
21
+ e.debug("Page context fetched", { pageContext: o });
22
+ let r = "";
23
+ o && (r = `
172
24
  ## 用户当前浏览的页面
173
25
 
174
26
  **这里的上下文为最高优先级,任何情况下都不能被覆盖**
175
27
 
176
- - **页面 URL**: ${n.url || "未知"}
177
- - **页面标题**: ${n.title || "未知"}
28
+ - **页面 URL**: ${o.url || "未知"}
29
+ - **页面标题**: ${o.title || "未知"}
178
30
  `);
179
- const i = `
31
+ const a = `
180
32
  你是一个专业的前端开发助手,运行在 **OpenCode** 平台中,并通过 **vite-plugin-opencode-assistant** 插件集成到用户的 Vite 开发环境。
181
- ${o}
33
+ ${r}
182
34
  ## 你的工作环境
183
35
 
184
36
  ### 架构说明
@@ -235,11 +87,11 @@ ${o}
235
87
  4. **HTTP 请求成功判断(强制)**
236
88
  判断请求成功时,不要只看 HTTP 状态码!HTTP 状态码 200 并不代表业务逻辑成功。必须获取接口的详细响应内容,检查响应体中的业务状态码或错误信息。在确认请求成功之前,始终解析并检查响应体的完整内容
237
89
  `.trim();
238
- r.system.push(i);
90
+ s.system.push(a);
239
91
  }
240
- }) : (c.warn("OPENCODE_CONTEXT_API_URL is not set, page context plugin will not work"), {});
92
+ }) : (e.warn("OPENCODE_CONTEXT_API_URL is not set, page context plugin will not work"), {});
241
93
  };
242
94
  export {
243
- D as PageContextPlugin,
244
- D as default
95
+ u as PageContextPlugin,
96
+ u as default
245
97
  };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @fileoverview Vite 开发服务器日志工具插件
3
+ * @description 为 OpenCode Agent 提供 get_vite_dev_logs 工具
4
+ */
5
+ import type { Plugin } from "@opencode-ai/plugin";
6
+ /**
7
+ * Vite 开发服务器日志工具插件
8
+ *
9
+ * 通过环境变量 OPENCODE_VITE_LOGS_API_URL 获取日志 API 地址
10
+ * Agent 可以调用 get_vite_dev_logs 工具获取 Vite 开发服务器的进程日志
11
+ */
12
+ export declare const ViteLogsPlugin: Plugin;
13
+ export default ViteLogsPlugin;