@vite-plugin-opencode-assistant/opencode 1.0.63 → 1.0.65
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.
- package/es/index.js +1 -0
- package/es/plugins/page-context.js +97 -74
- package/es/plugins/service-logs.js +46 -158
- package/es/plugins/vite-logs.js +90 -67
- package/es/{web.mjs → web.js} +1 -1
- package/lib/{index.cjs → index.js} +2 -2
- package/lib/{web.cjs → web.js} +1 -1
- package/package.json +7 -7
- package/es/index.mjs +0 -1
- package/es/plugins/logger.js +0 -255
- package/es/plugins/page-context.mjs +0 -151
- package/es/plugins/service-logs.mjs +0 -113
- package/es/plugins/vite-logs.mjs +0 -123
- /package/lib/plugins/{page-context.cjs → page-context.js} +0 -0
- /package/lib/plugins/{service-logs.cjs → service-logs.js} +0 -0
- /package/lib/plugins/{vite-logs.cjs → vite-logs.js} +0 -0
package/es/plugins/vite-logs.js
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
1
21
|
import { tool } from "@opencode-ai/plugin";
|
|
2
|
-
import {
|
|
22
|
+
import { createLogger } from "@vite-plugin-opencode-assistant/shared";
|
|
3
23
|
const log = createLogger("OpenCodePluginViteLogs");
|
|
4
|
-
const ViteLogsPlugin =
|
|
24
|
+
const ViteLogsPlugin = () => __async(null, null, function* () {
|
|
5
25
|
log.info("ViteLogsPlugin loading...");
|
|
6
26
|
const logsApiUrl = process.env.OPENCODE_VITE_LOGS_API_URL;
|
|
7
27
|
log.debug("Vite Logs API URL:", { logsApiUrl });
|
|
@@ -11,81 +31,83 @@ const ViteLogsPlugin = async () => {
|
|
|
11
31
|
}
|
|
12
32
|
log.info("Plugin initialized successfully");
|
|
13
33
|
const getViteDevLogsTool = tool({
|
|
14
|
-
description:
|
|
34
|
+
description: `\u83B7\u53D6 Vite \u5F00\u53D1\u670D\u52A1\u5668\u7684\u8FD0\u884C\u65E5\u5FD7\u3002
|
|
15
35
|
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
36
|
+
**\u4F55\u65F6\u4F7F\u7528\u6B64\u5DE5\u5177**\uFF1A
|
|
37
|
+
- \u7528\u6237\u62A5\u544A"\u9875\u9762\u6CA1\u66F4\u65B0"\u3001"\u70ED\u66F4\u65B0\u4E0D\u5DE5\u4F5C"\u3001"HMR \u5931\u6548"\u65F6
|
|
38
|
+
- \u6784\u5EFA\u62A5\u9519\u6216\u7F16\u8BD1\u5931\u8D25\uFF0C\u9700\u8981\u67E5\u770B\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F
|
|
39
|
+
- \u9875\u9762\u767D\u5C4F\u3001\u6837\u5F0F\u4E22\u5931\u3001\u6A21\u5757\u52A0\u8F7D\u5931\u8D25\u7B49\u5F00\u53D1\u95EE\u9898
|
|
40
|
+
- \u7528\u6237\u63D0\u5230"\u5F00\u53D1\u670D\u52A1\u5668\u6709\u95EE\u9898"\u3001"vite \u62A5\u9519"
|
|
41
|
+
- \u9700\u8981\u786E\u8BA4\u6700\u8FD1\u7684\u6587\u4EF6\u53D8\u66F4\u662F\u5426\u88AB Vite \u6B63\u786E\u5904\u7406
|
|
22
42
|
|
|
23
|
-
|
|
24
|
-
- Vite HMR
|
|
25
|
-
-
|
|
26
|
-
- OpenCode Web
|
|
27
|
-
-
|
|
43
|
+
**\u65E5\u5FD7\u5185\u5BB9**\uFF1A
|
|
44
|
+
- Vite HMR \u70ED\u66F4\u65B0\u65E5\u5FD7\uFF08\u54EA\u4E9B\u6587\u4EF6\u88AB\u66F4\u65B0\u3001\u66F4\u65B0\u72B6\u6001\uFF09
|
|
45
|
+
- \u6784\u5EFA\u7F16\u8BD1\u65E5\u5FD7\uFF08\u9519\u8BEF\u3001\u8B66\u544A\u3001\u6210\u529F\u4FE1\u606F\uFF09
|
|
46
|
+
- OpenCode Web \u8FDB\u7A0B\u8F93\u51FA
|
|
47
|
+
- \u63D2\u4EF6\u8FD0\u884C\u65E5\u5FD7
|
|
28
48
|
|
|
29
|
-
|
|
49
|
+
\u65E5\u5FD7\u4FDD\u5B58\u5728\u5185\u5B58\u7F13\u51B2\u533A\uFF08\u6700\u8FD1 500 \u6761\uFF09\u3002`,
|
|
30
50
|
args: {
|
|
31
51
|
level: tool.schema.string().optional().describe(
|
|
32
|
-
"
|
|
52
|
+
"\u65E5\u5FD7\u7EA7\u522B\u8FC7\u6EE4\uFF1Aerror(\u9519\u8BEF)\u3001warn(\u8B66\u544A)\u3001info(\u4FE1\u606F)\u3001debug(\u8C03\u8BD5)\u3001log(\u666E\u901A)\u3002\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF0C\u5982 'error,warn'"
|
|
33
53
|
),
|
|
34
|
-
limit: tool.schema.number().int().min(1).max(200).optional().default(50).describe("
|
|
35
|
-
source: tool.schema.string().optional().describe("
|
|
54
|
+
limit: tool.schema.number().int().min(1).max(200).optional().default(50).describe("\u8FD4\u56DE\u6761\u6570\uFF0C\u9ED8\u8BA4 50\uFF0C\u6700\u5927 200"),
|
|
55
|
+
source: tool.schema.string().optional().describe("\u6765\u6E90\u8FC7\u6EE4\uFF1Aconsole(\u63A7\u5236\u53F0)\u3001opencode-stdout(\u670D\u52A1\u8F93\u51FA)\u3001opencode-stderr(\u670D\u52A1\u9519\u8BEF)")
|
|
36
56
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
const url = new URL(logsApiUrl);
|
|
46
|
-
if (level) url.searchParams.set("level", level);
|
|
47
|
-
if (limit) url.searchParams.set("limit", String(limit));
|
|
48
|
-
if (source) url.searchParams.set("source", source);
|
|
49
|
-
log.debug("Fetching logs from", { url: url.toString() });
|
|
50
|
-
const response = await fetch(url.toString(), {
|
|
51
|
-
method: "GET",
|
|
52
|
-
headers: { Accept: "application/json" },
|
|
53
|
-
signal: context.abort
|
|
54
|
-
});
|
|
55
|
-
if (!response.ok) {
|
|
56
|
-
const errorText = await response.text();
|
|
57
|
-
log.error("Failed to fetch logs", { status: response.status, error: errorText });
|
|
58
|
-
return `获取日志失败: HTTP ${response.status} - ${errorText}`;
|
|
59
|
-
}
|
|
60
|
-
const data = await response.json();
|
|
61
|
-
log.debug("Logs fetched successfully", {
|
|
62
|
-
count: data.logs.length,
|
|
63
|
-
total: data.meta.total
|
|
57
|
+
execute(args, context) {
|
|
58
|
+
return __async(this, null, function* () {
|
|
59
|
+
const { level, limit, source } = args;
|
|
60
|
+
log.debug("get_vite_dev_logs called", {
|
|
61
|
+
args,
|
|
62
|
+
sessionID: context.sessionID,
|
|
63
|
+
directory: context.directory
|
|
64
64
|
});
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
try {
|
|
66
|
+
const url = new URL(logsApiUrl);
|
|
67
|
+
if (level) url.searchParams.set("level", level);
|
|
68
|
+
if (limit) url.searchParams.set("limit", String(limit));
|
|
69
|
+
if (source) url.searchParams.set("source", source);
|
|
70
|
+
log.debug("Fetching logs from", { url: url.toString() });
|
|
71
|
+
const response = yield fetch(url.toString(), {
|
|
72
|
+
method: "GET",
|
|
73
|
+
headers: { Accept: "application/json" },
|
|
74
|
+
signal: context.abort
|
|
75
|
+
});
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
const errorText = yield response.text();
|
|
78
|
+
log.error("Failed to fetch logs", { status: response.status, error: errorText });
|
|
79
|
+
return `\u83B7\u53D6\u65E5\u5FD7\u5931\u8D25: HTTP ${response.status} - ${errorText}`;
|
|
80
|
+
}
|
|
81
|
+
const data = yield response.json();
|
|
82
|
+
log.debug("Logs fetched successfully", {
|
|
83
|
+
count: data.logs.length,
|
|
84
|
+
total: data.meta.total
|
|
85
|
+
});
|
|
86
|
+
if (data.logs.length === 0) {
|
|
87
|
+
return `\u5F53\u524D\u6CA1\u6709\u7B26\u5408\u6761\u4EF6\u7684\u65E5\u5FD7\uFF08\u7F13\u51B2\u533A\u5171 ${data.meta.total} \u6761\uFF09\u3002
|
|
67
88
|
|
|
68
|
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
89
|
+
\u5EFA\u8BAE\uFF1A
|
|
90
|
+
- \u4E0D\u6307\u5B9A\u53C2\u6570\u83B7\u53D6\u6240\u6709\u65E5\u5FD7
|
|
91
|
+
- \u4F7F\u7528 level=error,warn \u83B7\u53D6\u9519\u8BEF\u548C\u8B66\u544A`;
|
|
92
|
+
}
|
|
93
|
+
const formattedLogs = data.logs.map((entry) => {
|
|
94
|
+
const time = new Date(entry.timestamp).toLocaleTimeString();
|
|
95
|
+
const levelIcon = entry.level === "error" ? "\u274C" : entry.level === "warn" ? "\u26A0\uFE0F" : entry.level === "info" ? "\u2139\uFE0F" : "";
|
|
96
|
+
return `${time} ${levelIcon} ${entry.message}`;
|
|
97
|
+
}).join("\n");
|
|
98
|
+
return `Vite \u5F00\u53D1\u670D\u52A1\u5668\u65E5\u5FD7\uFF08${data.meta.returned}/${data.meta.total} \u6761\uFF09\uFF1A
|
|
78
99
|
|
|
79
100
|
${formattedLogs}`;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const err = error;
|
|
103
|
+
if (context.abort.aborted) {
|
|
104
|
+
log.debug("Request aborted");
|
|
105
|
+
return "\u8BF7\u6C42\u5DF2\u53D6\u6D88";
|
|
106
|
+
}
|
|
107
|
+
log.error("Error fetching vite logs", { error: err });
|
|
108
|
+
return `\u83B7\u53D6\u65E5\u5FD7\u65F6\u53D1\u751F\u9519\u8BEF: ${err.message}`;
|
|
85
109
|
}
|
|
86
|
-
|
|
87
|
-
return `获取日志时发生错误: ${err.message}`;
|
|
88
|
-
}
|
|
110
|
+
});
|
|
89
111
|
}
|
|
90
112
|
});
|
|
91
113
|
return {
|
|
@@ -93,8 +115,9 @@ ${formattedLogs}`;
|
|
|
93
115
|
get_vite_dev_logs: getViteDevLogsTool
|
|
94
116
|
}
|
|
95
117
|
};
|
|
96
|
-
};
|
|
118
|
+
});
|
|
119
|
+
var vite_logs_default = ViteLogsPlugin;
|
|
97
120
|
export {
|
|
98
121
|
ViteLogsPlugin,
|
|
99
|
-
|
|
122
|
+
vite_logs_default as default
|
|
100
123
|
};
|
package/es/{web.mjs → web.js}
RENAMED
|
@@ -146,7 +146,7 @@ function resolveSourcePluginsDir() {
|
|
|
146
146
|
return candidatePaths[0];
|
|
147
147
|
}
|
|
148
148
|
function copyPluginFiles(sourceDir, targetDir) {
|
|
149
|
-
const files = fs.readdirSync(sourceDir).filter((f) => f.endsWith(".js"));
|
|
149
|
+
const files = fs.readdirSync(sourceDir).filter((f) => f.endsWith(".js") || f.endsWith(".d.ts"));
|
|
150
150
|
for (const file of files) {
|
|
151
151
|
const sourcePath = path.join(sourceDir, file);
|
|
152
152
|
const targetPath = path.join(targetDir, file);
|
|
@@ -14,8 +14,8 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
15
|
var lib_exports = {};
|
|
16
16
|
module.exports = __toCommonJS(lib_exports);
|
|
17
|
-
__reExport(lib_exports, require("./web
|
|
17
|
+
__reExport(lib_exports, require("./web"), module.exports);
|
|
18
18
|
// Annotate the CommonJS export names for ESM import in node:
|
|
19
19
|
0 && (module.exports = {
|
|
20
|
-
...require("./web
|
|
20
|
+
...require("./web")
|
|
21
21
|
});
|
package/lib/{web.cjs → web.js}
RENAMED
|
@@ -177,7 +177,7 @@ function resolveSourcePluginsDir() {
|
|
|
177
177
|
return candidatePaths[0];
|
|
178
178
|
}
|
|
179
179
|
function copyPluginFiles(sourceDir, targetDir) {
|
|
180
|
-
const files = import_fs.default.readdirSync(sourceDir).filter((f) => f.endsWith(".js"));
|
|
180
|
+
const files = import_fs.default.readdirSync(sourceDir).filter((f) => f.endsWith(".js") || f.endsWith(".d.ts"));
|
|
181
181
|
for (const file of files) {
|
|
182
182
|
const sourcePath = import_path.default.join(sourceDir, file);
|
|
183
183
|
const targetPath = import_path.default.join(targetDir, file);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-plugin-opencode-assistant/opencode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.65",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "lib/index.
|
|
6
|
-
"module": "es/index.
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"module": "es/index.js",
|
|
7
7
|
"types": "es/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"es",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./es/index.d.ts",
|
|
15
|
-
"import": "./es/index.
|
|
16
|
-
"require": "./lib/index.
|
|
15
|
+
"import": "./es/index.js",
|
|
16
|
+
"require": "./lib/index.js"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"publishConfig": {
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"execa": "^9.6.1",
|
|
25
|
-
"@vite-plugin-opencode-assistant/shared": "1.0.
|
|
25
|
+
"@vite-plugin-opencode-assistant/shared": "1.0.65"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@opencode-ai/plugin": "^1.3.15",
|
|
29
29
|
"vite": "^5.4.21"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "pagoda-cli build
|
|
32
|
+
"build": "pagoda-cli build",
|
|
33
33
|
"typecheck": "tsc -p tsconfig.declaration.json --noEmit"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/es/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./web.mjs";
|
package/es/plugins/logger.js
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
const LOG_PREFIX = "[vite-plugin-opencode]";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
const COLORS = {
|
|
23
|
-
reset: "\x1B[0m",
|
|
24
|
-
dim: "\x1B[2m",
|
|
25
|
-
bright: "\x1B[1m",
|
|
26
|
-
red: "\x1B[31m",
|
|
27
|
-
green: "\x1B[32m",
|
|
28
|
-
yellow: "\x1B[33m",
|
|
29
|
-
magenta: "\x1B[35m",
|
|
30
|
-
cyan: "\x1B[36m"
|
|
31
|
-
};
|
|
32
|
-
const LEVEL_COLORS = {
|
|
33
|
-
[
|
|
34
|
-
0
|
|
35
|
-
/* DEBUG */
|
|
36
|
-
]: COLORS.cyan,
|
|
37
|
-
[
|
|
38
|
-
1
|
|
39
|
-
/* INFO */
|
|
40
|
-
]: COLORS.green,
|
|
41
|
-
[
|
|
42
|
-
2
|
|
43
|
-
/* WARN */
|
|
44
|
-
]: COLORS.yellow,
|
|
45
|
-
[
|
|
46
|
-
3
|
|
47
|
-
/* ERROR */
|
|
48
|
-
]: COLORS.red,
|
|
49
|
-
[
|
|
50
|
-
4
|
|
51
|
-
/* NONE */
|
|
52
|
-
]: COLORS.reset
|
|
53
|
-
};
|
|
54
|
-
const LEVEL_NAMES = {
|
|
55
|
-
[
|
|
56
|
-
0
|
|
57
|
-
/* DEBUG */
|
|
58
|
-
]: "DEBUG",
|
|
59
|
-
[
|
|
60
|
-
1
|
|
61
|
-
/* INFO */
|
|
62
|
-
]: "INFO",
|
|
63
|
-
[
|
|
64
|
-
2
|
|
65
|
-
/* WARN */
|
|
66
|
-
]: "WARN",
|
|
67
|
-
[
|
|
68
|
-
3
|
|
69
|
-
/* ERROR */
|
|
70
|
-
]: "ERROR",
|
|
71
|
-
[
|
|
72
|
-
4
|
|
73
|
-
/* NONE */
|
|
74
|
-
]: "NONE"
|
|
75
|
-
};
|
|
76
|
-
let globalConfig = {
|
|
77
|
-
level: 1
|
|
78
|
-
/* INFO */
|
|
79
|
-
};
|
|
80
|
-
function getTimestamp() {
|
|
81
|
-
const now = /* @__PURE__ */ new Date();
|
|
82
|
-
const hours = String(now.getHours()).padStart(2, "0");
|
|
83
|
-
const minutes = String(now.getMinutes()).padStart(2, "0");
|
|
84
|
-
const seconds = String(now.getSeconds()).padStart(2, "0");
|
|
85
|
-
const ms = String(now.getMilliseconds()).padStart(3, "0");
|
|
86
|
-
return `${hours}:${minutes}:${seconds}.${ms}`;
|
|
87
|
-
}
|
|
88
|
-
function getCallerInfo(depth = 3) {
|
|
89
|
-
const stack = new Error().stack;
|
|
90
|
-
if (!stack) return "";
|
|
91
|
-
const lines = stack.split("\n");
|
|
92
|
-
const targetLine = lines[depth];
|
|
93
|
-
if (!targetLine) return "";
|
|
94
|
-
const match = targetLine.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/);
|
|
95
|
-
if (!match) return "";
|
|
96
|
-
const [, funcName, filePath, line] = match;
|
|
97
|
-
const fileName = filePath.split("/").pop() || filePath;
|
|
98
|
-
const func = funcName || "<anonymous>";
|
|
99
|
-
return `${fileName}:${line} ${func}`;
|
|
100
|
-
}
|
|
101
|
-
function formatValue(value, depth = 0) {
|
|
102
|
-
if (depth > 3) return "...";
|
|
103
|
-
if (value === null) return "null";
|
|
104
|
-
if (value === void 0) return "undefined";
|
|
105
|
-
if (typeof value === "string") return depth > 0 ? `"${value}"` : value;
|
|
106
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
107
|
-
if (value instanceof Error) {
|
|
108
|
-
return `${value.name}: ${value.message}${value.stack ? `
|
|
109
|
-
${value.stack}` : ""}`;
|
|
110
|
-
}
|
|
111
|
-
if (Array.isArray(value)) {
|
|
112
|
-
if (value.length === 0) return "[]";
|
|
113
|
-
if (value.length > 5) {
|
|
114
|
-
const items2 = value.slice(0, 3).map((v) => formatValue(v, depth + 1));
|
|
115
|
-
return `[${items2.join(", ")}, ... ${value.length - 3} more items]`;
|
|
116
|
-
}
|
|
117
|
-
const items = value.map((v) => formatValue(v, depth + 1));
|
|
118
|
-
return `[${items.join(", ")}]`;
|
|
119
|
-
}
|
|
120
|
-
if (typeof value === "object") {
|
|
121
|
-
const entries = Object.entries(value);
|
|
122
|
-
if (entries.length === 0) return "{}";
|
|
123
|
-
if (entries.length > 5) {
|
|
124
|
-
const shown = entries.slice(0, 3).map(([k, v]) => `${k}: ${formatValue(v, depth + 1)}`);
|
|
125
|
-
return `{${shown.join(", ")}, ... ${entries.length - 3} more keys}`;
|
|
126
|
-
}
|
|
127
|
-
const formatted = entries.map(([k, v]) => `${k}: ${formatValue(v, depth + 1)}`);
|
|
128
|
-
return `{${formatted.join(", ")}}`;
|
|
129
|
-
}
|
|
130
|
-
return String(value);
|
|
131
|
-
}
|
|
132
|
-
function formatContext(context) {
|
|
133
|
-
if (!context || Object.keys(context).length === 0) return "";
|
|
134
|
-
const parts = [];
|
|
135
|
-
if (context.module) parts.push(`[${context.module}]`);
|
|
136
|
-
if (context.operation) parts.push(`(${context.operation})`);
|
|
137
|
-
if (context.traceId) parts.push(`trace:${context.traceId}`);
|
|
138
|
-
if (context.duration !== void 0) parts.push(`${context.duration}ms`);
|
|
139
|
-
const extraKeys = Object.keys(context).filter(
|
|
140
|
-
(k) => !["module", "operation", "traceId", "duration", "error"].includes(k)
|
|
141
|
-
);
|
|
142
|
-
if (extraKeys.length > 0) {
|
|
143
|
-
const extra = {};
|
|
144
|
-
extraKeys.forEach((k) => extra[k] = context[k]);
|
|
145
|
-
parts.push(formatValue(extra));
|
|
146
|
-
}
|
|
147
|
-
return parts.join(" ");
|
|
148
|
-
}
|
|
149
|
-
function log(level, message, context, ...args) {
|
|
150
|
-
if (level < globalConfig.level) return;
|
|
151
|
-
const parts = [];
|
|
152
|
-
parts.push(`${COLORS.dim}[${process.pid}]${COLORS.reset}`);
|
|
153
|
-
{
|
|
154
|
-
parts.push(`${COLORS.dim}${getTimestamp()}${COLORS.reset}`);
|
|
155
|
-
}
|
|
156
|
-
const levelColor = LEVEL_COLORS[level];
|
|
157
|
-
const levelName = LEVEL_NAMES[level].padEnd(5);
|
|
158
|
-
parts.push(`${levelColor}${levelName}${COLORS.reset}`);
|
|
159
|
-
parts.push(`${COLORS.bright}${LOG_PREFIX}${COLORS.reset}`);
|
|
160
|
-
const contextStr = formatContext(context);
|
|
161
|
-
if (contextStr) {
|
|
162
|
-
parts.push(`${COLORS.magenta}${contextStr}${COLORS.reset}`);
|
|
163
|
-
}
|
|
164
|
-
parts.push(message);
|
|
165
|
-
if (level >= 2) {
|
|
166
|
-
const caller = getCallerInfo(4);
|
|
167
|
-
if (caller) {
|
|
168
|
-
parts.push(`${COLORS.dim}(${caller})${COLORS.reset}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
const formattedArgs = args.map((a) => formatValue(a)).join(" ");
|
|
172
|
-
if (formattedArgs) {
|
|
173
|
-
parts.push(formattedArgs);
|
|
174
|
-
}
|
|
175
|
-
if (context == null ? void 0 : context.error) {
|
|
176
|
-
const err = context.error;
|
|
177
|
-
if (err instanceof Error) {
|
|
178
|
-
parts.push(`${COLORS.red}Error: ${err.message}${COLORS.reset}`);
|
|
179
|
-
} else {
|
|
180
|
-
parts.push(`${COLORS.red}Error: ${formatValue(err)}${COLORS.reset}`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
const output = parts.join(" ");
|
|
184
|
-
if (level >= 3) {
|
|
185
|
-
console.error(output);
|
|
186
|
-
} else if (level === 2) {
|
|
187
|
-
console.warn(output);
|
|
188
|
-
} else {
|
|
189
|
-
console.log(output);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
const logger = {
|
|
193
|
-
debug(message, context, ...args) {
|
|
194
|
-
log(0, message, context, ...args);
|
|
195
|
-
},
|
|
196
|
-
info(message, context, ...args) {
|
|
197
|
-
log(1, message, context, ...args);
|
|
198
|
-
},
|
|
199
|
-
warn(message, context, ...args) {
|
|
200
|
-
log(2, message, context, ...args);
|
|
201
|
-
},
|
|
202
|
-
error(message, context, ...args) {
|
|
203
|
-
log(3, message, context, ...args);
|
|
204
|
-
},
|
|
205
|
-
group(label, context) {
|
|
206
|
-
return;
|
|
207
|
-
},
|
|
208
|
-
groupEnd() {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
class PerformanceTimer {
|
|
213
|
-
constructor(operation, context) {
|
|
214
|
-
__publicField(this, "startTime");
|
|
215
|
-
__publicField(this, "context");
|
|
216
|
-
__publicField(this, "operation");
|
|
217
|
-
this.operation = operation;
|
|
218
|
-
this.context = context || {};
|
|
219
|
-
this.startTime = performance.now();
|
|
220
|
-
logger.debug(`⏱️ Starting: ${operation}`, this.context);
|
|
221
|
-
}
|
|
222
|
-
end(message) {
|
|
223
|
-
const duration = Math.round(performance.now() - this.startTime);
|
|
224
|
-
const msg = message || `✓ Completed: ${this.operation}`;
|
|
225
|
-
logger.debug(msg, __spreadProps(__spreadValues({}, this.context), { duration }));
|
|
226
|
-
return duration;
|
|
227
|
-
}
|
|
228
|
-
checkpoint(label) {
|
|
229
|
-
const elapsed = Math.round(performance.now() - this.startTime);
|
|
230
|
-
logger.debug(` ↳ ${label}`, __spreadProps(__spreadValues({}, this.context), { duration: elapsed }));
|
|
231
|
-
return elapsed;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
function createLogger(module) {
|
|
235
|
-
return {
|
|
236
|
-
debug(message, context, ...args) {
|
|
237
|
-
logger.debug(message, __spreadProps(__spreadValues({}, context), { module }), ...args);
|
|
238
|
-
},
|
|
239
|
-
info(message, context, ...args) {
|
|
240
|
-
logger.info(message, __spreadProps(__spreadValues({}, context), { module }), ...args);
|
|
241
|
-
},
|
|
242
|
-
warn(message, context, ...args) {
|
|
243
|
-
logger.warn(message, __spreadProps(__spreadValues({}, context), { module }), ...args);
|
|
244
|
-
},
|
|
245
|
-
error(message, context, ...args) {
|
|
246
|
-
logger.error(message, __spreadProps(__spreadValues({}, context), { module }), ...args);
|
|
247
|
-
},
|
|
248
|
-
timer(operation, context) {
|
|
249
|
-
return new PerformanceTimer(operation, __spreadProps(__spreadValues({}, context), { module }));
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
export {
|
|
254
|
-
createLogger as c
|
|
255
|
-
};
|