@aipanel/core 1.2.0-beta.0

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.
Files changed (53) hide show
  1. package/es/constants.d.ts +145 -0
  2. package/es/constants.mjs +124 -0
  3. package/es/file-log-watcher.d.ts +20 -0
  4. package/es/file-log-watcher.mjs +126 -0
  5. package/es/index.d.ts +7 -0
  6. package/es/index.mjs +7 -0
  7. package/es/logger-core.d.ts +37 -0
  8. package/es/logger-core.mjs +143 -0
  9. package/es/logger.d.ts +15 -0
  10. package/es/logger.mjs +127 -0
  11. package/es/node-logger.d.ts +38 -0
  12. package/es/node-logger.mjs +230 -0
  13. package/es/node-utils.d.ts +28 -0
  14. package/es/node-utils.mjs +56 -0
  15. package/es/node.d.ts +6 -0
  16. package/es/node.mjs +6 -0
  17. package/es/options.d.ts +63 -0
  18. package/es/options.mjs +30 -0
  19. package/es/process-logger.d.ts +97 -0
  20. package/es/process-logger.mjs +193 -0
  21. package/es/provider.d.ts +160 -0
  22. package/es/provider.mjs +0 -0
  23. package/es/types.d.ts +275 -0
  24. package/es/types.mjs +40 -0
  25. package/es/utils.d.ts +34 -0
  26. package/es/utils.mjs +53 -0
  27. package/lib/constants.cjs +188 -0
  28. package/lib/constants.d.ts +145 -0
  29. package/lib/file-log-watcher.cjs +160 -0
  30. package/lib/file-log-watcher.d.ts +20 -0
  31. package/lib/index.cjs +33 -0
  32. package/lib/index.d.ts +7 -0
  33. package/lib/logger-core.cjs +177 -0
  34. package/lib/logger-core.d.ts +37 -0
  35. package/lib/logger.cjs +145 -0
  36. package/lib/logger.d.ts +15 -0
  37. package/lib/node-logger.cjs +252 -0
  38. package/lib/node-logger.d.ts +38 -0
  39. package/lib/node-utils.cjs +93 -0
  40. package/lib/node-utils.d.ts +28 -0
  41. package/lib/node.cjs +31 -0
  42. package/lib/node.d.ts +6 -0
  43. package/lib/options.cjs +54 -0
  44. package/lib/options.d.ts +63 -0
  45. package/lib/process-logger.cjs +217 -0
  46. package/lib/process-logger.d.ts +97 -0
  47. package/lib/provider.cjs +15 -0
  48. package/lib/provider.d.ts +160 -0
  49. package/lib/types.cjs +64 -0
  50. package/lib/types.d.ts +275 -0
  51. package/lib/utils.cjs +80 -0
  52. package/lib/utils.d.ts +34 -0
  53. package/package.json +34 -0
package/es/logger.mjs ADDED
@@ -0,0 +1,127 @@
1
+ import { LOG_PREFIX } from "./constants.mjs";
2
+ import {
3
+ LogLevel,
4
+ getConfig,
5
+ getTimestamp,
6
+ formatContext,
7
+ formatValue
8
+ } from "./logger-core.mjs";
9
+ const LEVEL_NAMES = {
10
+ [LogLevel.DEBUG]: "DEBUG",
11
+ [LogLevel.INFO]: "INFO ",
12
+ [LogLevel.WARN]: "WARN ",
13
+ [LogLevel.ERROR]: "ERROR",
14
+ [LogLevel.NONE]: "NONE "
15
+ };
16
+ const C = {
17
+ dim: "color: #888",
18
+ bright: "font-weight: bold",
19
+ red: "color: #cd0000; font-weight: bold",
20
+ green: "color: #00cd00",
21
+ yellow: "color: #cdcd00",
22
+ blue: "color: #0000cd",
23
+ magenta: "color: #cd00cd",
24
+ cyan: "color: #00cdcd",
25
+ reset: ""
26
+ };
27
+ const LEVEL_COLORS = {
28
+ [LogLevel.DEBUG]: C.cyan,
29
+ [LogLevel.INFO]: C.green,
30
+ [LogLevel.WARN]: C.yellow,
31
+ [LogLevel.ERROR]: C.red,
32
+ [LogLevel.NONE]: C.reset
33
+ };
34
+ function log(level, message, context, ...args) {
35
+ if (level < getConfig().level) return;
36
+ const segments = [];
37
+ const styles = [];
38
+ if (getConfig().showTimestamp) {
39
+ segments.push("%c%s");
40
+ styles.push(C.dim, getTimestamp());
41
+ }
42
+ segments.push(`%c${LEVEL_NAMES[level]}`);
43
+ styles.push(LEVEL_COLORS[level]);
44
+ segments.push(`%c${LOG_PREFIX}`);
45
+ styles.push(C.bright);
46
+ const ctxStr = formatContext(context);
47
+ if (ctxStr) {
48
+ segments.push(`%c${ctxStr}`);
49
+ styles.push(C.magenta);
50
+ }
51
+ const formattedArgs = args.length > 0 ? ` ${args.map((a) => formatValue(a)).join(" ")}` : "";
52
+ segments.push(`%c${message}${formattedArgs}`);
53
+ styles.push(C.reset);
54
+ const output = segments.join(" ");
55
+ if (context?.error) {
56
+ const err = context.error;
57
+ if (err instanceof Error) {
58
+ if (level >= LogLevel.ERROR && getConfig().showTrace && err.stack) {
59
+ console.error(output, ...styles, `
60
+ ${err.stack}`);
61
+ } else {
62
+ console.error(output, ...styles, `
63
+ %cError: ${err.message}`, C.red);
64
+ }
65
+ } else {
66
+ console.error(output, ...styles, `
67
+ %cError: ${formatValue(err)}`, C.red);
68
+ }
69
+ return;
70
+ }
71
+ if (level >= LogLevel.ERROR) {
72
+ console.error(output, ...styles);
73
+ } else if (level === LogLevel.WARN) {
74
+ console.warn(output, ...styles);
75
+ } else if (level === LogLevel.DEBUG) {
76
+ console.debug(output, ...styles);
77
+ } else {
78
+ console.log(output, ...styles);
79
+ }
80
+ }
81
+ const logger = {
82
+ debug(message, context, ...args) {
83
+ log(LogLevel.DEBUG, message, context, ...args);
84
+ },
85
+ info(message, context, ...args) {
86
+ log(LogLevel.INFO, message, context, ...args);
87
+ },
88
+ warn(message, context, ...args) {
89
+ log(LogLevel.WARN, message, context, ...args);
90
+ },
91
+ error(message, context, ...args) {
92
+ log(LogLevel.ERROR, message, context, ...args);
93
+ },
94
+ group(label, context) {
95
+ if (!getConfig().verbose) return;
96
+ console.group(
97
+ `%c${LOG_PREFIX}%c ${label}`,
98
+ C.bright,
99
+ context?.module ? `%c[${context.module}]%c ` : C.reset,
100
+ ...context?.module ? [C.magenta, C.reset] : []
101
+ );
102
+ },
103
+ groupEnd() {
104
+ if (!getConfig().verbose) return;
105
+ console.groupEnd();
106
+ }
107
+ };
108
+ function createLogger(module) {
109
+ return {
110
+ debug(message, context, ...args) {
111
+ logger.debug(message, { ...context, module }, ...args);
112
+ },
113
+ info(message, context, ...args) {
114
+ logger.info(message, { ...context, module }, ...args);
115
+ },
116
+ warn(message, context, ...args) {
117
+ logger.warn(message, { ...context, module }, ...args);
118
+ },
119
+ error(message, context, ...args) {
120
+ logger.error(message, { ...context, module }, ...args);
121
+ }
122
+ };
123
+ }
124
+ export {
125
+ createLogger,
126
+ logger
127
+ };
@@ -0,0 +1,38 @@
1
+ import { type LogContext } from "./logger-core";
2
+ export declare const nodeLogger: {
3
+ debug(message: string, context?: LogContext, ...args: unknown[]): void;
4
+ info(message: string, context?: LogContext, ...args: unknown[]): void;
5
+ warn(message: string, context?: LogContext, ...args: unknown[]): void;
6
+ error(message: string, context?: LogContext, ...args: unknown[]): void;
7
+ group(label: string, context?: LogContext): void;
8
+ groupEnd(): void;
9
+ };
10
+ export declare function createNodeLogger(module: string): {
11
+ debug(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
12
+ info(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
13
+ warn(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
14
+ error(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
15
+ timer(operation: string, context?: Omit<LogContext, "module">): PerformanceTimer;
16
+ };
17
+ export declare class PerformanceTimer {
18
+ private startTime;
19
+ private context;
20
+ private operation;
21
+ constructor(operation: string, context?: LogContext);
22
+ end(message?: string): number;
23
+ checkpoint(label: string): number;
24
+ }
25
+ export declare class RequestContext {
26
+ traceId: string;
27
+ method: string;
28
+ path: string;
29
+ startTime: number;
30
+ private checkpoints;
31
+ constructor(method: string, path: string);
32
+ checkpoint(label: string): void;
33
+ end(statusCode: number): void;
34
+ error(error: Error | unknown): void;
35
+ }
36
+ export declare function logMethod(target: unknown, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
37
+ export { nodeLogger as logger };
38
+ export { createNodeLogger as createLogger };
@@ -0,0 +1,230 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { LOG_PREFIX } from "./constants.mjs";
5
+ import {
6
+ LogLevel,
7
+ getConfig,
8
+ formatContext,
9
+ formatValue,
10
+ generateTraceId as _generateTraceId
11
+ } from "./logger-core.mjs";
12
+ const COLORS = {
13
+ reset: "\x1B[0m",
14
+ dim: "\x1B[2m",
15
+ bright: "\x1B[1m",
16
+ red: "\x1B[31m",
17
+ green: "\x1B[32m",
18
+ yellow: "\x1B[33m",
19
+ blue: "\x1B[34m",
20
+ magenta: "\x1B[35m",
21
+ cyan: "\x1B[36m",
22
+ white: "\x1B[37m"
23
+ };
24
+ const LEVEL_COLORS = {
25
+ [LogLevel.DEBUG]: COLORS.cyan,
26
+ [LogLevel.INFO]: COLORS.green,
27
+ [LogLevel.WARN]: COLORS.yellow,
28
+ [LogLevel.ERROR]: COLORS.red,
29
+ [LogLevel.NONE]: COLORS.reset
30
+ };
31
+ const LEVEL_NAMES = {
32
+ [LogLevel.DEBUG]: "DEBUG",
33
+ [LogLevel.INFO]: "INFO",
34
+ [LogLevel.WARN]: "WARN",
35
+ [LogLevel.ERROR]: "ERROR",
36
+ [LogLevel.NONE]: "NONE"
37
+ };
38
+ function getTimestamp() {
39
+ const now = /* @__PURE__ */ new Date();
40
+ const hours = String(now.getHours()).padStart(2, "0");
41
+ const minutes = String(now.getMinutes()).padStart(2, "0");
42
+ const seconds = String(now.getSeconds()).padStart(2, "0");
43
+ const ms = String(now.getMilliseconds()).padStart(3, "0");
44
+ return `${hours}:${minutes}:${seconds}.${ms}`;
45
+ }
46
+ function getCallerInfo(depth = 3) {
47
+ const stack = new Error().stack;
48
+ if (!stack) return "";
49
+ const lines = stack.split("\n");
50
+ const targetLine = lines[depth];
51
+ if (!targetLine) return "";
52
+ const match = targetLine.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/);
53
+ if (!match) return "";
54
+ const [, funcName, filePath, line] = match;
55
+ const fileName = filePath.split("/").pop() || filePath;
56
+ const func = funcName || "<anonymous>";
57
+ return `${fileName}:${line} ${func}`;
58
+ }
59
+ function log(level, message, context, ...args) {
60
+ if (level < getConfig().level) return;
61
+ const parts = [];
62
+ parts.push(`${COLORS.dim}[${process.pid}]${COLORS.reset}`);
63
+ if (getConfig().showTimestamp) {
64
+ parts.push(`${COLORS.dim}${getTimestamp()}${COLORS.reset}`);
65
+ }
66
+ const levelColor = LEVEL_COLORS[level];
67
+ const levelName = LEVEL_NAMES[level].padEnd(5);
68
+ parts.push(`${levelColor}${levelName}${COLORS.reset}`);
69
+ parts.push(`${COLORS.bright}${LOG_PREFIX}${COLORS.reset}`);
70
+ const contextStr = formatContext(context);
71
+ if (contextStr) {
72
+ parts.push(`${COLORS.magenta}${contextStr}${COLORS.reset}`);
73
+ }
74
+ parts.push(message);
75
+ if (getConfig().showCaller && level >= LogLevel.WARN) {
76
+ const caller = getCallerInfo(4);
77
+ if (caller) {
78
+ parts.push(`${COLORS.dim}(${caller})${COLORS.reset}`);
79
+ }
80
+ }
81
+ const formattedArgs = args.map((a) => formatValue(a)).join(" ");
82
+ if (formattedArgs) {
83
+ parts.push(formattedArgs);
84
+ }
85
+ if (context?.error) {
86
+ const err = context.error;
87
+ if (err instanceof Error) {
88
+ parts.push(`${COLORS.red}Error: ${err.message}${COLORS.reset}`);
89
+ if (level >= LogLevel.ERROR && getConfig().showTrace && err.stack) {
90
+ console.error(`${COLORS.dim}${err.stack}${COLORS.reset}`);
91
+ }
92
+ } else {
93
+ parts.push(`${COLORS.red}Error: ${formatValue(err)}${COLORS.reset}`);
94
+ }
95
+ }
96
+ const output = parts.join(" ");
97
+ if (level >= LogLevel.ERROR) {
98
+ console.error(output);
99
+ } else if (level === LogLevel.WARN) {
100
+ console.warn(output);
101
+ } else {
102
+ console.log(output);
103
+ }
104
+ }
105
+ const nodeLogger = {
106
+ debug(message, context, ...args) {
107
+ log(LogLevel.DEBUG, message, context, ...args);
108
+ },
109
+ info(message, context, ...args) {
110
+ log(LogLevel.INFO, message, context, ...args);
111
+ },
112
+ warn(message, context, ...args) {
113
+ log(LogLevel.WARN, message, context, ...args);
114
+ },
115
+ error(message, context, ...args) {
116
+ log(LogLevel.ERROR, message, context, ...args);
117
+ },
118
+ group(label, context) {
119
+ if (!getConfig().verbose) return;
120
+ const contextStr = formatContext(context);
121
+ console.log(
122
+ `${COLORS.dim}[${process.pid}]${COLORS.reset} ${COLORS.bright}${LOG_PREFIX}${COLORS.reset} ${COLORS.blue}\u25BC${COLORS.reset} ${label}${contextStr ? ` ${contextStr}` : ""}`
123
+ );
124
+ },
125
+ groupEnd() {
126
+ if (!getConfig().verbose) return;
127
+ }
128
+ };
129
+ function createNodeLogger(module) {
130
+ return {
131
+ debug(message, context, ...args) {
132
+ nodeLogger.debug(message, { ...context, module }, ...args);
133
+ },
134
+ info(message, context, ...args) {
135
+ nodeLogger.info(message, { ...context, module }, ...args);
136
+ },
137
+ warn(message, context, ...args) {
138
+ nodeLogger.warn(message, { ...context, module }, ...args);
139
+ },
140
+ error(message, context, ...args) {
141
+ nodeLogger.error(message, { ...context, module }, ...args);
142
+ },
143
+ timer(operation, context) {
144
+ return new PerformanceTimer(operation, { ...context, module });
145
+ }
146
+ };
147
+ }
148
+ class PerformanceTimer {
149
+ constructor(operation, context) {
150
+ __publicField(this, "startTime");
151
+ __publicField(this, "context");
152
+ __publicField(this, "operation");
153
+ this.operation = operation;
154
+ this.context = context || {};
155
+ this.startTime = performance.now();
156
+ nodeLogger.debug(`\u23F1\uFE0F Starting: ${operation}`, this.context);
157
+ }
158
+ end(message) {
159
+ const duration = Math.round(performance.now() - this.startTime);
160
+ const msg = message || `\u2713 Completed: ${this.operation}`;
161
+ nodeLogger.debug(msg, { ...this.context, duration });
162
+ return duration;
163
+ }
164
+ checkpoint(label) {
165
+ const elapsed = Math.round(performance.now() - this.startTime);
166
+ nodeLogger.debug(` \u21B3 ${label}`, { ...this.context, duration: elapsed });
167
+ return elapsed;
168
+ }
169
+ }
170
+ class RequestContext {
171
+ constructor(method, path) {
172
+ __publicField(this, "traceId");
173
+ __publicField(this, "method");
174
+ __publicField(this, "path");
175
+ __publicField(this, "startTime");
176
+ __publicField(this, "checkpoints", []);
177
+ this.traceId = _generateTraceId();
178
+ this.method = method;
179
+ this.path = path;
180
+ this.startTime = performance.now();
181
+ nodeLogger.debug(`\u2192 ${method} ${path}`, { traceId: this.traceId, module: "HTTP" });
182
+ }
183
+ checkpoint(label) {
184
+ const elapsed = Math.round(performance.now() - this.startTime);
185
+ this.checkpoints.push({ time: elapsed, label });
186
+ nodeLogger.debug(` \u2192 ${label}`, { traceId: this.traceId, duration: elapsed });
187
+ }
188
+ end(statusCode) {
189
+ const duration = Math.round(performance.now() - this.startTime);
190
+ const statusColor = statusCode < 400 ? COLORS.green : COLORS.red;
191
+ nodeLogger.debug(`\u2190 ${this.method} ${this.path} ${statusColor}${statusCode}${COLORS.reset}`, {
192
+ traceId: this.traceId,
193
+ duration,
194
+ checkpoints: this.checkpoints.length
195
+ });
196
+ }
197
+ error(error) {
198
+ const duration = Math.round(performance.now() - this.startTime);
199
+ nodeLogger.error(`\u2717 ${this.method} ${this.path}`, {
200
+ traceId: this.traceId,
201
+ duration,
202
+ error
203
+ });
204
+ }
205
+ }
206
+ function logMethod(target, propertyKey, descriptor) {
207
+ const originalMethod = descriptor.value;
208
+ const className = target.constructor.name;
209
+ descriptor.value = async function(...args) {
210
+ const timer = new PerformanceTimer(`${className}.${propertyKey}`);
211
+ try {
212
+ const result = await originalMethod.apply(this, args);
213
+ timer.end();
214
+ return result;
215
+ } catch (error) {
216
+ timer.end("\u274C Failed");
217
+ throw error;
218
+ }
219
+ };
220
+ return descriptor;
221
+ }
222
+ export {
223
+ PerformanceTimer,
224
+ RequestContext,
225
+ createNodeLogger as createLogger,
226
+ createNodeLogger,
227
+ logMethod,
228
+ nodeLogger as logger,
229
+ nodeLogger
230
+ };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @fileoverview Node.js 专用工具函数(仅服务端可用)
3
+ */
4
+ /**
5
+ * 创建一个锚定到指定目录(默认 process.cwd())的 require。
6
+ * 跨 ESM/CJS 安全,避免依赖 __dirname / import.meta.url(CJS 打包时会与 Node 内置变量冲突或被置空)。
7
+ */
8
+ export declare function createPackageRequire(baseDir?: string): NodeJS.Require;
9
+ /**
10
+ * 解析 npm 包根目录(跨 ESM/CJS 安全)。
11
+ * @param packageName - 包名,例如 "vite-plugin-aipanel"
12
+ * @param baseDir - 解析基准目录,默认当前工作目录
13
+ */
14
+ export declare function resolvePackageDir(packageName: string, baseDir?: string): string;
15
+ /**
16
+ * 检查 Chrome DevTools 是否可用
17
+ * @param timeout - 超时时间(毫秒),默认 2000ms
18
+ * @returns Chrome DevTools 是否可用
19
+ */
20
+ export declare function checkChromeDevToolsAvailable(port?: number, timeout?: number): Promise<boolean>;
21
+ /**
22
+ * 检查指定端口是否可用
23
+ */
24
+ export declare function isPortAvailable(port: number, hostname?: string): Promise<boolean>;
25
+ /**
26
+ * 从 startPort 开始寻找可用端口
27
+ */
28
+ export declare function findAvailablePort(startPort: number, hostname?: string, maxTries?: number): Promise<number>;
@@ -0,0 +1,56 @@
1
+ import { createRequire } from "node:module";
2
+ import path from "node:path";
3
+ import { CHROME_DEVTOOLS_PORT, CHROME_DEVTOOLS_CHECK_TIMEOUT } from "./constants.mjs";
4
+ function createPackageRequire(baseDir = process.cwd()) {
5
+ return createRequire(path.join(baseDir, "package.json"));
6
+ }
7
+ function resolvePackageDir(packageName, baseDir = process.cwd()) {
8
+ const require2 = createPackageRequire(baseDir);
9
+ const entryPath = require2.resolve(packageName);
10
+ return path.dirname(path.dirname(entryPath));
11
+ }
12
+ async function checkChromeDevToolsAvailable(port = CHROME_DEVTOOLS_PORT, timeout = CHROME_DEVTOOLS_CHECK_TIMEOUT) {
13
+ const net = await import("net");
14
+ return new Promise((resolve) => {
15
+ const socket = new net.Socket();
16
+ const timer = setTimeout(() => {
17
+ socket.destroy();
18
+ resolve(false);
19
+ }, timeout);
20
+ socket.connect(port, "localhost", () => {
21
+ clearTimeout(timer);
22
+ socket.removeAllListeners();
23
+ socket.destroy();
24
+ resolve(true);
25
+ });
26
+ socket.on("error", () => {
27
+ clearTimeout(timer);
28
+ resolve(false);
29
+ });
30
+ });
31
+ }
32
+ async function isPortAvailable(port, hostname) {
33
+ const net = await import("net");
34
+ return new Promise((resolve) => {
35
+ const server = net.createServer();
36
+ server.once("error", () => resolve(false));
37
+ server.once("listening", () => {
38
+ server.close();
39
+ resolve(true);
40
+ });
41
+ server.listen(port, hostname);
42
+ });
43
+ }
44
+ async function findAvailablePort(startPort, hostname, maxTries = 100) {
45
+ for (let port = startPort; port < startPort + maxTries; port++) {
46
+ if (await isPortAvailable(port, hostname)) return port;
47
+ }
48
+ throw new Error(`No available port in range ${startPort}-${startPort + maxTries}`);
49
+ }
50
+ export {
51
+ checkChromeDevToolsAvailable,
52
+ createPackageRequire,
53
+ findAvailablePort,
54
+ isPortAvailable,
55
+ resolvePackageDir
56
+ };
package/es/node.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./constants";
2
+ export * from "./logger-core";
3
+ export * from "./node-logger";
4
+ export * from "./process-logger";
5
+ export * from "./file-log-watcher";
6
+ export * from "./node-utils";
package/es/node.mjs ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./constants.mjs";
2
+ export * from "./logger-core.mjs";
3
+ export * from "./node-logger.mjs";
4
+ export * from "./process-logger.mjs";
5
+ export * from "./file-log-watcher.mjs";
6
+ export * from "./node-utils.mjs";
@@ -0,0 +1,63 @@
1
+ /**
2
+ * 插件通用配置(Provider 无关)
3
+ * Provider 专属配置通过泛型 P 注入,核心层不感知具体 schema。
4
+ */
5
+ import type { DisplayMode, LogFileConfig, SplitModeOptions } from "./types";
6
+ /**
7
+ * 插件配置选项
8
+ * @typeParam P - 当前 Provider 的专属配置段(schema 由具体 Provider 声明)
9
+ */
10
+ export interface PluginOptions<P extends Record<string, unknown> = Record<string, unknown>> {
11
+ /** 是否启用插件,默认 true */
12
+ enabled?: boolean;
13
+ /** 选择的 Web Provider 标识,默认 "default" */
14
+ provider?: string;
15
+ /** Web 服务端口,默认 5097 */
16
+ webPort?: number;
17
+ /** 代理服务端口,默认 6097 */
18
+ proxyPort?: number;
19
+ /** 服务主机名,默认 '127.0.0.1' */
20
+ hostname?: string;
21
+ /** 挂件位置,默认 'bottom-right' */
22
+ position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
23
+ /** 主题模式,默认 'dark' */
24
+ theme?: "light" | "dark" | "auto";
25
+ /** 是否自动打开面板,默认 false */
26
+ open?: boolean;
27
+ /** 是否输出详细日志,默认 false */
28
+ verbose?: boolean;
29
+ /** 纯净 MCP 模式:只暴露 MCP 工具服务,不注入挂件、不启动 provider Web 进程,默认为 false */
30
+ mcpOnly?: boolean;
31
+ /** 快捷键配置,默认 'ctrl+k' */
32
+ hotkey?: string;
33
+ /** 服务启动后是否立即预热 Chrome MCP,默认 true */
34
+ warmupChromeMcp?: boolean;
35
+ /** Chrome DevTools Protocol 端口,默认 9222 */
36
+ chromeDevtoolsPort?: number;
37
+ /** 展示模式,默认 'bubble' */
38
+ displayMode?: DisplayMode;
39
+ /** 分屏模式配置 */
40
+ splitMode?: SplitModeOptions;
41
+ /** 自定义日志文件配置,为 Agent 提供查看外部服务日志的能力 */
42
+ logFiles?: LogFileConfig[];
43
+ /** Provider 专属配置段(schema 由具体 Provider 声明,核心层不感知) */
44
+ providerOptions?: P;
45
+ /** @deprecated 使用 providerOptions.language */
46
+ language?: string;
47
+ /** @deprecated 使用 providerOptions.settings */
48
+ settings?: unknown;
49
+ /** @deprecated 使用 providerOptions.enableLsp */
50
+ enableLsp?: boolean;
51
+ /** @deprecated 使用 providerOptions.enableBlockOnError */
52
+ enableBlockOnError?: boolean;
53
+ /** @deprecated 使用 providerOptions.enablePrettier */
54
+ enablePrettier?: boolean;
55
+ }
56
+ /** 插件通用配置默认值(Provider 无关部分) */
57
+ export declare const DEFAULT_PLUGIN_OPTIONS: Partial<PluginOptions>;
58
+ /**
59
+ * 组装运行时配置(通用默认 + 用户配置)
60
+ * Provider 专属段原样合并透传,schema 由 Provider 自行解析;
61
+ * deprecated 顶层字段不在此迁移,保留在 config 顶层,由 Provider 读取兜底。
62
+ */
63
+ export declare function resolvePluginConfig<P extends Record<string, unknown> = Record<string, unknown>>(options?: PluginOptions<P>): Required<PluginOptions<P>>;
package/es/options.mjs ADDED
@@ -0,0 +1,30 @@
1
+ import { CHROME_DEVTOOLS_PORT, DEFAULT_HOSTNAME, DEFAULT_WEB_PORT } from "./constants.mjs";
2
+ const DEFAULT_PLUGIN_OPTIONS = {
3
+ enabled: true,
4
+ provider: "default",
5
+ webPort: DEFAULT_WEB_PORT,
6
+ hostname: DEFAULT_HOSTNAME,
7
+ theme: "dark",
8
+ open: false,
9
+ verbose: false,
10
+ mcpOnly: false,
11
+ hotkey: "ctrl+k",
12
+ warmupChromeMcp: true,
13
+ chromeDevtoolsPort: CHROME_DEVTOOLS_PORT,
14
+ displayMode: "extension",
15
+ splitMode: void 0,
16
+ providerOptions: void 0
17
+ };
18
+ function resolvePluginConfig(options = {}) {
19
+ return {
20
+ ...DEFAULT_PLUGIN_OPTIONS,
21
+ ...options,
22
+ providerOptions: {
23
+ ...options.providerOptions ?? {}
24
+ }
25
+ };
26
+ }
27
+ export {
28
+ DEFAULT_PLUGIN_OPTIONS,
29
+ resolvePluginConfig
30
+ };
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @fileoverview 进程日志捕获器
3
+ * @description 拦截 console 方法并存储日志到内存缓冲区,供 agent 通过工具获取
4
+ */
5
+ export interface ProcessLogEntry {
6
+ /** 日志级别 */
7
+ level: "log" | "info" | "warn" | "error" | "debug";
8
+ /** 日志内容(已序列化为字符串) */
9
+ message: string;
10
+ /** 时间戳(ISO 格式) */
11
+ timestamp: string;
12
+ /** 来源标识 */
13
+ source?: "console" | "provider-stdout" | "provider-stderr" | "vite";
14
+ }
15
+ export interface ProcessLogBufferOptions {
16
+ /** 最大日志条数,默认 500 */
17
+ maxSize?: number;
18
+ /** 是否启用捕获,默认 true */
19
+ enabled?: boolean;
20
+ }
21
+ /**
22
+ * 进程日志缓冲区
23
+ */
24
+ declare class ProcessLogBuffer {
25
+ private buffer;
26
+ private maxSize;
27
+ private enabled;
28
+ private originalConsole;
29
+ constructor(options?: ProcessLogBufferOptions);
30
+ /**
31
+ * 启动 console 拦截
32
+ */
33
+ intercept(): void;
34
+ /**
35
+ * 停止拦截,恢复原始 console
36
+ */
37
+ restore(): void;
38
+ /**
39
+ * 创建拦截器函数
40
+ */
41
+ private createInterceptor;
42
+ /**
43
+ * 序列化参数为字符串
44
+ */
45
+ private serializeArgs;
46
+ /**
47
+ * 添加日志条目
48
+ */
49
+ addEntry(entry: ProcessLogEntry): void;
50
+ /**
51
+ * 添加 Provider stdout 日志
52
+ */
53
+ addProviderStdout(message: string): void;
54
+ /**
55
+ * 添加 Provider stderr 日志
56
+ */
57
+ addProviderStderr(message: string): void;
58
+ /**
59
+ * 获取日志
60
+ * @param options 过滤选项
61
+ */
62
+ getLogs(options?: {
63
+ level?: ProcessLogEntry["level"] | ProcessLogEntry["level"][];
64
+ limit?: number;
65
+ source?: ProcessLogEntry["source"];
66
+ since?: string;
67
+ }): ProcessLogEntry[];
68
+ /**
69
+ * 清空缓冲区
70
+ */
71
+ clear(): void;
72
+ /**
73
+ * 获取缓冲区大小
74
+ */
75
+ size(): number;
76
+ /**
77
+ * 启用/禁用捕获
78
+ */
79
+ setEnabled(enabled: boolean): void;
80
+ /**
81
+ * 获取是否启用
82
+ */
83
+ isEnabled(): boolean;
84
+ }
85
+ /**
86
+ * 获取全局日志缓冲区
87
+ */
88
+ export declare function getProcessLogBuffer(options?: ProcessLogBufferOptions): ProcessLogBuffer;
89
+ /**
90
+ * 初始化进程日志捕获
91
+ */
92
+ export declare function initProcessLogCapture(options?: ProcessLogBufferOptions): ProcessLogBuffer;
93
+ /**
94
+ * 停止进程日志捕获
95
+ */
96
+ export declare function stopProcessLogCapture(): void;
97
+ export {};