@aipanel/core 1.2.8 → 1.2.10

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 (73) hide show
  1. package/es/{logger.d.ts → client/logger.d.ts} +1 -1
  2. package/es/{logger.mjs → client/logger.mjs} +4 -10
  3. package/es/client/storage.d.ts +15 -0
  4. package/es/client/storage.mjs +33 -0
  5. package/es/client/theme.d.ts +15 -0
  6. package/es/client/theme.mjs +11 -0
  7. package/es/client.d.ts +3 -0
  8. package/es/client.mjs +3 -0
  9. package/es/{constants.d.ts → common/constants.d.ts} +34 -6
  10. package/es/{constants.mjs → common/constants.mjs} +31 -8
  11. package/{lib → es/common}/options.d.ts +40 -0
  12. package/{lib → es/common}/types.d.ts +36 -11
  13. package/es/{utils.d.ts → common/utils.d.ts} +26 -3
  14. package/es/{utils.mjs → common/utils.mjs} +42 -1
  15. package/es/index.d.ts +6 -7
  16. package/es/index.mjs +6 -7
  17. package/es/node/diagnostics.d.ts +5 -0
  18. package/es/node/diagnostics.mjs +26 -4
  19. package/es/{file-log-watcher.mjs → node/file-log-watcher.mjs} +1 -1
  20. package/{lib → es/node}/node-logger.d.ts +1 -1
  21. package/es/{node-logger.mjs → node/node-logger.mjs} +4 -17
  22. package/es/node/node-utils.d.ts +69 -0
  23. package/es/node/node-utils.mjs +291 -0
  24. package/es/node.d.ts +6 -6
  25. package/es/node.mjs +6 -6
  26. package/lib/{logger.cjs → client/logger.cjs} +3 -10
  27. package/lib/{logger.d.ts → client/logger.d.ts} +1 -1
  28. package/lib/client/storage.cjs +58 -0
  29. package/lib/client/storage.d.ts +15 -0
  30. package/lib/client/theme.cjs +35 -0
  31. package/lib/client/theme.d.ts +15 -0
  32. package/lib/client.cjs +25 -0
  33. package/lib/client.d.ts +3 -0
  34. package/lib/{constants.cjs → common/constants.cjs} +38 -12
  35. package/lib/{constants.d.ts → common/constants.d.ts} +34 -6
  36. package/{es → lib/common}/options.d.ts +40 -0
  37. package/{es → lib/common}/types.d.ts +36 -11
  38. package/lib/{utils.cjs → common/utils.cjs} +47 -2
  39. package/lib/{utils.d.ts → common/utils.d.ts} +26 -3
  40. package/lib/index.cjs +12 -14
  41. package/lib/index.d.ts +6 -7
  42. package/lib/node/diagnostics.cjs +27 -4
  43. package/lib/node/diagnostics.d.ts +5 -0
  44. package/lib/{file-log-watcher.cjs → node/file-log-watcher.cjs} +1 -1
  45. package/lib/{node-logger.cjs → node/node-logger.cjs} +4 -19
  46. package/{es → lib/node}/node-logger.d.ts +1 -1
  47. package/lib/node/node-utils.cjs +329 -0
  48. package/lib/node/node-utils.d.ts +69 -0
  49. package/lib/node.cjs +12 -12
  50. package/lib/node.d.ts +6 -6
  51. package/package.json +6 -1
  52. package/es/node-utils.d.ts +0 -28
  53. package/es/node-utils.mjs +0 -56
  54. package/lib/node-utils.cjs +0 -93
  55. package/lib/node-utils.d.ts +0 -28
  56. /package/es/{logger-core.d.ts → common/logger-core.d.ts} +0 -0
  57. /package/es/{logger-core.mjs → common/logger-core.mjs} +0 -0
  58. /package/es/{options.mjs → common/options.mjs} +0 -0
  59. /package/es/{provider.d.ts → common/provider.d.ts} +0 -0
  60. /package/es/{provider.mjs → common/provider.mjs} +0 -0
  61. /package/es/{types.mjs → common/types.mjs} +0 -0
  62. /package/es/{file-log-watcher.d.ts → node/file-log-watcher.d.ts} +0 -0
  63. /package/es/{process-logger.d.ts → node/process-logger.d.ts} +0 -0
  64. /package/es/{process-logger.mjs → node/process-logger.mjs} +0 -0
  65. /package/lib/{logger-core.cjs → common/logger-core.cjs} +0 -0
  66. /package/lib/{logger-core.d.ts → common/logger-core.d.ts} +0 -0
  67. /package/lib/{options.cjs → common/options.cjs} +0 -0
  68. /package/lib/{provider.cjs → common/provider.cjs} +0 -0
  69. /package/lib/{provider.d.ts → common/provider.d.ts} +0 -0
  70. /package/lib/{types.cjs → common/types.cjs} +0 -0
  71. /package/lib/{file-log-watcher.d.ts → node/file-log-watcher.d.ts} +0 -0
  72. /package/lib/{process-logger.cjs → node/process-logger.cjs} +0 -0
  73. /package/lib/{process-logger.d.ts → node/process-logger.d.ts} +0 -0
@@ -1,14 +1,16 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { LOG_PREFIX } from "./constants.mjs";
4
+ import { LOG_PREFIX } from "../common/constants.mjs";
5
5
  import {
6
+ LEVEL_NAMES,
6
7
  LogLevel,
7
8
  getConfig,
9
+ getTimestamp,
8
10
  formatContext,
9
11
  formatValue,
10
12
  generateTraceId as _generateTraceId
11
- } from "./logger-core.mjs";
13
+ } from "../common/logger-core.mjs";
12
14
  const COLORS = {
13
15
  reset: "\x1B[0m",
14
16
  dim: "\x1B[2m",
@@ -28,21 +30,6 @@ const LEVEL_COLORS = {
28
30
  [LogLevel.ERROR]: COLORS.red,
29
31
  [LogLevel.NONE]: COLORS.reset
30
32
  };
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
33
  function getCallerInfo(depth = 3) {
47
34
  const stack = new Error().stack;
48
35
  if (!stack) return "";
@@ -0,0 +1,69 @@
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>;
29
+ /**
30
+ * 可等待的进程接口(ResultPromise 等匹配就够)
31
+ */
32
+ export interface WaitableProcess {
33
+ exitCode: number | null | undefined;
34
+ }
35
+ /**
36
+ * 轮询等待服务准备就绪(HTTP 状态码 < 500 即当作 ready);超时或进程退出时 reject
37
+ * @param url - 检查的服务 URL
38
+ * @param timeout - 超时毫秒数
39
+ * @param proc - 可选进程,提前退出时直接失败
40
+ */
41
+ export declare function waitForServer(url: string, timeout?: number, proc?: WaitableProcess): Promise<void>;
42
+ /**
43
+ * 从指定目录往上查找 .git 根目录(找不到时返回起始目录)
44
+ */
45
+ export declare function findGitRoot(startDir: string, maxDepth?: number): string;
46
+ /**
47
+ * 检查某 CLI 是否安装(运行 <bin> --version,退出码 0 即存在)
48
+ */
49
+ export declare function checkCliInstalled(bin: string): Promise<boolean>;
50
+ /**
51
+ * 获取某 CLI 版本号(<bin> --version 的第一行,败路返回 null)
52
+ */
53
+ export declare function getCliVersion(bin: string): Promise<string | null>;
54
+ /** 孤儿进程清理配置(提供商的 check/kill 统一实现) */
55
+ export interface KillOrphanCliOptions {
56
+ /** 进程命令行/参数中需匹配的子串(如 opencode / dsh) */
57
+ match: string;
58
+ /** Windows wmic 按名称查询的进程名(如 opencode.exe / node.exe) */
59
+ winName: string;
60
+ /** 超时毫秒(默认 5000) */
61
+ timeout?: number;
62
+ /** 运行名(仅用于日志,默认等于 match) */
63
+ label?: string;
64
+ }
65
+ /**
66
+ * 清理被 reparent 到 init(PPID=1)的孤儿进程(win: wmic+taskkill;unix: ps+kill)
67
+ * @returns 被成功结束的进程数
68
+ */
69
+ export declare function killOrphanCliProcesses(bin: string, options: KillOrphanCliOptions): Promise<number>;
@@ -0,0 +1,291 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createRequire } from "node:module";
3
+ import fs from "node:fs";
4
+ import http from "node:http";
5
+ import path from "node:path";
6
+ import {
7
+ CHROME_DEVTOOLS_PORT,
8
+ CHROME_DEVTOOLS_CHECK_TIMEOUT,
9
+ SERVER_CHECK_INTERVAL
10
+ } from "../common/constants.mjs";
11
+ import { PerformanceTimer, createLogger } from "./node-logger.mjs";
12
+ const log = createLogger("NodeUtils");
13
+ function createPackageRequire(baseDir = process.cwd()) {
14
+ return createRequire(path.join(baseDir, "package.json"));
15
+ }
16
+ function resolvePackageDir(packageName, baseDir = process.cwd()) {
17
+ const require2 = createPackageRequire(baseDir);
18
+ const entryPath = require2.resolve(packageName);
19
+ return path.dirname(path.dirname(entryPath));
20
+ }
21
+ async function checkChromeDevToolsAvailable(port = CHROME_DEVTOOLS_PORT, timeout = CHROME_DEVTOOLS_CHECK_TIMEOUT) {
22
+ const net = await import("net");
23
+ return new Promise((resolve) => {
24
+ const socket = new net.Socket();
25
+ const timer = setTimeout(() => {
26
+ socket.destroy();
27
+ resolve(false);
28
+ }, timeout);
29
+ socket.connect(port, "localhost", () => {
30
+ clearTimeout(timer);
31
+ socket.removeAllListeners();
32
+ socket.destroy();
33
+ resolve(true);
34
+ });
35
+ socket.on("error", () => {
36
+ clearTimeout(timer);
37
+ resolve(false);
38
+ });
39
+ });
40
+ }
41
+ async function isPortAvailable(port, hostname) {
42
+ const net = await import("net");
43
+ return new Promise((resolve) => {
44
+ const server = net.createServer();
45
+ server.once("error", () => resolve(false));
46
+ server.once("listening", () => {
47
+ server.close();
48
+ resolve(true);
49
+ });
50
+ server.listen(port, hostname);
51
+ });
52
+ }
53
+ async function findAvailablePort(startPort, hostname, maxTries = 100) {
54
+ for (let port = startPort; port < startPort + maxTries; port++) {
55
+ if (await isPortAvailable(port, hostname)) return port;
56
+ }
57
+ throw new Error(`No available port in range ${startPort}-${startPort + maxTries}`);
58
+ }
59
+ function waitForServer(url, timeout = 1e4, proc) {
60
+ const timer = new PerformanceTimer("waitForServer", { url, timeout });
61
+ return new Promise((resolve, reject) => {
62
+ const startTime = Date.now();
63
+ let attempts = 0;
64
+ const check = () => {
65
+ attempts++;
66
+ log.debug(`Checking server availability (attempt ${attempts})`, { url });
67
+ if (proc?.exitCode !== null && proc?.exitCode !== void 0) {
68
+ timer.end(`\u2716 Process exited with code ${proc.exitCode}`);
69
+ reject(new Error(`Process exited with code ${proc.exitCode}`));
70
+ return;
71
+ }
72
+ const req = http.get(url, (res) => {
73
+ if (res.statusCode && res.statusCode < 500) {
74
+ timer.end(`\u2713 Server ready after ${attempts} attempts`);
75
+ resolve();
76
+ } else {
77
+ log.debug(`Server returned status ${res.statusCode}, retrying...`);
78
+ retryOrReject();
79
+ }
80
+ });
81
+ req.on("error", (err) => {
82
+ log.debug(`Server check failed: ${err.message}`);
83
+ retryOrReject();
84
+ });
85
+ };
86
+ const retryOrReject = () => {
87
+ const elapsed = Date.now() - startTime;
88
+ if (elapsed < timeout) {
89
+ setTimeout(check, SERVER_CHECK_INTERVAL);
90
+ } else {
91
+ timer.end("\u2716 Timeout");
92
+ reject(new Error(`Server not ready after ${timeout}ms (${attempts} attempts)`));
93
+ }
94
+ };
95
+ check();
96
+ });
97
+ }
98
+ function findGitRoot(startDir, maxDepth = 10) {
99
+ const timer = new PerformanceTimer("findGitRoot", { startDir, maxDepth });
100
+ let currentDir = startDir;
101
+ let depth = 0;
102
+ while (depth < maxDepth) {
103
+ const gitDir = path.join(currentDir, ".git");
104
+ try {
105
+ if (fs.existsSync(gitDir)) {
106
+ timer.end(`\u2713 Found git root at depth ${depth}: ${currentDir}`);
107
+ return currentDir;
108
+ }
109
+ } catch (err) {
110
+ log.debug(`Error checking .git directory at ${currentDir}`, {
111
+ error: err.message
112
+ });
113
+ }
114
+ const parentDir = path.dirname(currentDir);
115
+ if (parentDir === currentDir) {
116
+ log.debug("Reached filesystem root");
117
+ break;
118
+ }
119
+ currentDir = parentDir;
120
+ depth++;
121
+ }
122
+ timer.end(`\u2716 No git root found after ${depth} levels, using start directory`);
123
+ return startDir;
124
+ }
125
+ async function checkCliInstalled(bin) {
126
+ const timer = new PerformanceTimer(`checkCliInstalled:${bin}`);
127
+ return new Promise((resolve) => {
128
+ const proc = spawn(bin, ["--version"], { stdio: "ignore", shell: true });
129
+ proc.on("close", (code) => {
130
+ const installed = code === 0;
131
+ timer.end(installed ? `\u2713 ${bin} is installed` : `\u2716 ${bin} not found`);
132
+ resolve(installed);
133
+ });
134
+ proc.on("error", (err) => {
135
+ log.debug(`Failed to check ${bin} installation`, { error: err.message });
136
+ timer.end("\u2716 Check failed");
137
+ resolve(false);
138
+ });
139
+ });
140
+ }
141
+ function getCliVersion(bin) {
142
+ return new Promise((resolve) => {
143
+ const proc = spawn(bin, ["--version"], { stdio: "pipe", shell: true });
144
+ let output = "";
145
+ proc.stdout?.on("data", (data) => {
146
+ output += data.toString();
147
+ });
148
+ proc.on("close", (code) => {
149
+ resolve(code === 0 && output.trim() ? output.trim() : null);
150
+ });
151
+ proc.on("error", () => resolve(null));
152
+ });
153
+ }
154
+ function killOrphanCliProcesses(bin, options) {
155
+ const label = options.label ?? bin;
156
+ const timeoutMs = options.timeout ?? 5e3;
157
+ const timer = new PerformanceTimer(`killOrphanCliProcesses:${label}`);
158
+ log.debug(`Looking for orphan ${label} processes (PPID=1)`);
159
+ return new Promise((resolve) => {
160
+ let settled = false;
161
+ const done = (count) => {
162
+ if (!settled) {
163
+ settled = true;
164
+ resolve(count);
165
+ }
166
+ };
167
+ const timeout = setTimeout(() => {
168
+ log.warn(`Kill orphan ${label} processes timed out, skipping`);
169
+ timer.end("\u26A0 Timeout, skipped");
170
+ done(0);
171
+ }, timeoutMs);
172
+ const wrappedResolve = (count) => {
173
+ clearTimeout(timeout);
174
+ done(count);
175
+ };
176
+ if (process.platform === "win32") {
177
+ killOrphansOnWindows(wrappedResolve, options, label, timer);
178
+ } else {
179
+ killOrphansOnUnix(wrappedResolve, options, label, timer);
180
+ }
181
+ });
182
+ }
183
+ function killOrphansOnWindows(resolve, options, label, timer) {
184
+ log.debug(`Using Windows method to find orphan ${label} processes`);
185
+ const proc = spawn(
186
+ "wmic",
187
+ ["process", "where", `name="${options.winName}"`, "get", "processid,parentprocessid,commandline"],
188
+ { stdio: "pipe" }
189
+ );
190
+ let output = "";
191
+ proc.stdout?.on("data", (data) => {
192
+ output += data.toString();
193
+ });
194
+ proc.on("close", () => {
195
+ const pidsToKill = [];
196
+ output.split("\n").forEach((rawLine) => {
197
+ const line = rawLine.trim();
198
+ if (!line.includes(options.match)) return;
199
+ const parts = line.split(/\s+/);
200
+ if (parts.length >= 3) {
201
+ const ppid = parts[0];
202
+ const pid = parts[1];
203
+ if (ppid === "1" && pid && !Number.isNaN(Number(pid))) pidsToKill.push(pid);
204
+ }
205
+ });
206
+ finishOrphanKillWindows(pidsToKill, resolve, label, timer);
207
+ });
208
+ proc.on("error", (err) => {
209
+ log.debug(`Failed to find orphan ${label} processes`, { error: err.message });
210
+ timer.end("\u2716 Failed to find orphan processes");
211
+ resolve(0);
212
+ });
213
+ }
214
+ function finishOrphanKillWindows(pidsToKill, resolve, label, timer) {
215
+ if (pidsToKill.length === 0) {
216
+ log.debug("No orphan processes found");
217
+ timer.end("No orphan processes found");
218
+ resolve(0);
219
+ return;
220
+ }
221
+ log.debug(`Found ${pidsToKill.length} orphan processes`, { pids: pidsToKill });
222
+ let killedCount = 0;
223
+ let completedCount = 0;
224
+ pidsToKill.forEach((pid) => {
225
+ const killProc = spawn("taskkill", ["/F", "/PID", pid], { stdio: "ignore" });
226
+ killProc.on("close", (code) => {
227
+ completedCount++;
228
+ if (code === 0) killedCount++;
229
+ if (completedCount === pidsToKill.length) {
230
+ timer.end(`\u2713 Killed ${killedCount} orphan ${label} processes`);
231
+ resolve(killedCount);
232
+ }
233
+ });
234
+ });
235
+ }
236
+ function killOrphansOnUnix(resolve, options, label, timer) {
237
+ log.debug(`Using Unix method to find orphan ${label} processes`);
238
+ const proc = spawn("ps", ["-e", "-o", "pid,ppid,args"], { stdio: "pipe" });
239
+ let output = "";
240
+ proc.stdout?.on("data", (data) => {
241
+ output += data.toString();
242
+ });
243
+ proc.on("close", () => {
244
+ const pidsToKill = [];
245
+ output.split("\n").forEach((line) => {
246
+ if (!line.includes(options.match)) return;
247
+ const parts = line.trim().split(/\s+/);
248
+ if (parts.length >= 3) {
249
+ const pid = parts[0];
250
+ const ppid = parts[1];
251
+ if (ppid === "1" && pid && !Number.isNaN(Number(pid))) pidsToKill.push(pid);
252
+ }
253
+ });
254
+ if (pidsToKill.length === 0) {
255
+ log.debug("No orphan processes found");
256
+ timer.end("No orphan processes found");
257
+ resolve(0);
258
+ return;
259
+ }
260
+ log.debug(`Found ${pidsToKill.length} orphan processes`, { pids: pidsToKill });
261
+ const killProc = spawn("kill", ["-9", ...pidsToKill], { stdio: "ignore" });
262
+ killProc.on("close", (code) => {
263
+ const killedCount = code === 0 ? pidsToKill.length : 0;
264
+ timer.end(
265
+ killedCount > 0 ? `\u2713 Killed ${killedCount} orphan ${label} processes` : "\u2716 Failed to kill processes"
266
+ );
267
+ resolve(killedCount);
268
+ });
269
+ killProc.on("error", () => {
270
+ timer.end("\u2716 Failed to kill processes");
271
+ resolve(0);
272
+ });
273
+ });
274
+ proc.on("error", (err) => {
275
+ log.debug(`Failed to find orphan ${label} processes`, { error: err.message });
276
+ timer.end("\u2716 Failed to find orphan processes");
277
+ resolve(0);
278
+ });
279
+ }
280
+ export {
281
+ checkChromeDevToolsAvailable,
282
+ checkCliInstalled,
283
+ createPackageRequire,
284
+ findAvailablePort,
285
+ findGitRoot,
286
+ getCliVersion,
287
+ isPortAvailable,
288
+ killOrphanCliProcesses,
289
+ resolvePackageDir,
290
+ waitForServer
291
+ };
package/es/node.d.ts CHANGED
@@ -1,7 +1,7 @@
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";
1
+ export * from "./common/constants";
2
+ export * from "./common/logger-core";
3
+ export * from "./node/node-logger";
4
+ export * from "./node/process-logger";
5
+ export * from "./node/file-log-watcher";
6
+ export * from "./node/node-utils";
7
7
  export * from "./node/diagnostics";
package/es/node.mjs CHANGED
@@ -1,7 +1,7 @@
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";
1
+ export * from "./common/constants.mjs";
2
+ export * from "./common/logger-core.mjs";
3
+ export * from "./node/node-logger.mjs";
4
+ export * from "./node/process-logger.mjs";
5
+ export * from "./node/file-log-watcher.mjs";
6
+ export * from "./node/node-utils.mjs";
7
7
  export * from "./node/diagnostics.mjs";
@@ -21,15 +21,8 @@ __export(logger_exports, {
21
21
  logger: () => logger
22
22
  });
23
23
  module.exports = __toCommonJS(logger_exports);
24
- var import_constants = require("./constants.cjs");
25
- var import_logger_core = require("./logger-core.cjs");
26
- const LEVEL_NAMES = {
27
- [import_logger_core.LogLevel.DEBUG]: "DEBUG",
28
- [import_logger_core.LogLevel.INFO]: "INFO ",
29
- [import_logger_core.LogLevel.WARN]: "WARN ",
30
- [import_logger_core.LogLevel.ERROR]: "ERROR",
31
- [import_logger_core.LogLevel.NONE]: "NONE "
32
- };
24
+ var import_constants = require("../common/constants.cjs");
25
+ var import_logger_core = require("../common/logger-core.cjs");
33
26
  const C = {
34
27
  dim: "color: #888",
35
28
  bright: "font-weight: bold",
@@ -56,7 +49,7 @@ function log(level, message, context, ...args) {
56
49
  segments.push("%c%s");
57
50
  styles.push(C.dim, (0, import_logger_core.getTimestamp)());
58
51
  }
59
- segments.push(`%c${LEVEL_NAMES[level]}`);
52
+ segments.push(`%c${import_logger_core.LEVEL_NAMES[level].padEnd(5)}`);
60
53
  styles.push(LEVEL_COLORS[level]);
61
54
  segments.push(`%c${import_constants.LOG_PREFIX}`);
62
55
  styles.push(C.bright);
@@ -1,4 +1,4 @@
1
- import { type LogContext } from "./logger-core";
1
+ import { type LogContext } from "../common/logger-core";
2
2
  export declare const logger: {
3
3
  debug(message: string, context?: LogContext, ...args: unknown[]): void;
4
4
  info(message: string, context?: LogContext, ...args: unknown[]): void;
@@ -0,0 +1,58 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var storage_exports = {};
19
+ __export(storage_exports, {
20
+ storageGet: () => storageGet,
21
+ storageRemove: () => storageRemove,
22
+ storageSet: () => storageSet
23
+ });
24
+ module.exports = __toCommonJS(storage_exports);
25
+ function storageArea(area) {
26
+ try {
27
+ if (typeof window === "undefined") return void 0;
28
+ return area === "local" ? window.localStorage : window.sessionStorage;
29
+ } catch {
30
+ return void 0;
31
+ }
32
+ }
33
+ function storageGet(area, key) {
34
+ try {
35
+ const raw = storageArea(area)?.getItem(key);
36
+ return raw == null ? null : JSON.parse(raw);
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+ function storageSet(area, key, value) {
42
+ try {
43
+ storageArea(area)?.setItem(key, JSON.stringify(value));
44
+ } catch {
45
+ }
46
+ }
47
+ function storageRemove(area, key) {
48
+ try {
49
+ storageArea(area)?.removeItem(key);
50
+ } catch {
51
+ }
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ storageGet,
56
+ storageRemove,
57
+ storageSet
58
+ });
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 浏览器存储辅助(window.localStorage/sessionStorage,仅 client 端;通过 @aipanel/core/client 导出)
3
+ */
4
+ /**
5
+ * 安全读取浏览器存储(JSON 解码;不可用/异常返回 null)
6
+ */
7
+ export declare function storageGet<T>(area: "local" | "session", key: string): T | null;
8
+ /**
9
+ * 安全写入浏览器存储(JSON 序列化;异常忽略)
10
+ */
11
+ export declare function storageSet(area: "local" | "session", key: string, value: unknown): void;
12
+ /**
13
+ * 安全删除浏览器存储项
14
+ */
15
+ export declare function storageRemove(area: "local" | "session", key: string): void;
@@ -0,0 +1,35 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var theme_exports = {};
19
+ __export(theme_exports, {
20
+ getSystemTheme: () => getSystemTheme,
21
+ resolveWidgetTheme: () => resolveWidgetTheme
22
+ });
23
+ module.exports = __toCommonJS(theme_exports);
24
+ function getSystemTheme() {
25
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return "light";
26
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
27
+ }
28
+ function resolveWidgetTheme(theme, system = getSystemTheme()) {
29
+ return theme === "auto" ? system : theme;
30
+ }
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ getSystemTheme,
34
+ resolveWidgetTheme
35
+ });
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 浏览器主题辅助(依赖 window.matchMedia,仅 client 端使用;通过 @aipanel/core/client 导出)
3
+ */
4
+ import type { AIPanelWidgetTheme } from "../common/types";
5
+ /**
6
+ * 当前系统主题(仅浏览器有效;SSR/无 window 环境返回 light)
7
+ */
8
+ export declare function getSystemTheme(): "light" | "dark";
9
+ /**
10
+ * 挂件主题偏好解析:auto 按系统主题折算为 light/dark
11
+ * @param theme - 挂件主题偏好(AIPanelWidgetTheme)
12
+ * @param system - 系统主题(默认当前系统)
13
+ * @returns 实际应用主题
14
+ */
15
+ export declare function resolveWidgetTheme(theme: AIPanelWidgetTheme, system?: "light" | "dark"): "light" | "dark";
package/lib/client.cjs ADDED
@@ -0,0 +1,25 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var client_exports = {};
16
+ module.exports = __toCommonJS(client_exports);
17
+ __reExport(client_exports, require("./client/logger.cjs"), module.exports);
18
+ __reExport(client_exports, require("./client/storage.cjs"), module.exports);
19
+ __reExport(client_exports, require("./client/theme.cjs"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("./client/logger.cjs"),
23
+ ...require("./client/storage.cjs"),
24
+ ...require("./client/theme.cjs")
25
+ });
@@ -0,0 +1,3 @@
1
+ export * from "./client/logger";
2
+ export * from "./client/storage";
3
+ export * from "./client/theme";