skillmkt 0.3.7 → 0.3.9
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/client/commands/serve.js +18 -2
- package/package.json +1 -1
package/client/commands/serve.js
CHANGED
|
@@ -49,11 +49,25 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
|
49
49
|
};
|
|
50
50
|
const body = (req) => new Promise((r) => { let b = ''; req.on('data', (c) => b += c); req.on('end', () => r(b || '{}')); });
|
|
51
51
|
|
|
52
|
+
// 只记关键事件:打开网页 + 真正落盘的写操作;点击/读取/静态资源一律不打扰
|
|
53
|
+
const action = (req, u) => {
|
|
54
|
+
const p = u.pathname;
|
|
55
|
+
if (req.method === 'GET' && (p === '/' || p === '/index.html')) return '打开了网页';
|
|
56
|
+
if (req.method === 'POST' && p === '/api/config') return '保存了设置';
|
|
57
|
+
if (req.method === 'POST' && p === '/api/targets') return '修改了 skill 的安装位置';
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
|
|
52
61
|
const server = http.createServer(async (req, res) => {
|
|
53
62
|
lastActive = Date.now();
|
|
54
|
-
const t0 = Date.now();
|
|
55
|
-
if (!quiet) res.on('finish', () => console.log(` ${req.method} ${req.url.replace(/token=[^&\s]+/g, 'token=***')} → ${res.statusCode} ${Date.now() - t0}ms`));
|
|
56
63
|
const u = new URL(req.url, 'http://x');
|
|
64
|
+
if (!quiet) res.on('finish', () => {
|
|
65
|
+
const a = req.logNote ?? action(req, u);
|
|
66
|
+
if (a == null) return;
|
|
67
|
+
const tail = res.statusCode === 401 ? '(被拒绝:链接已过期,重新打开)'
|
|
68
|
+
: res.statusCode >= 400 ? `(失败 ${res.statusCode})` : '';
|
|
69
|
+
console.log(` ${new Date().toTimeString().slice(0, 8)} ${a}${tail}`);
|
|
70
|
+
});
|
|
57
71
|
// auth:Bearer header 或 ?token=(SSE/img 用 query,服务端不下发 cookie)
|
|
58
72
|
const authed = req.headers.authorization === `Bearer ${token}` || u.searchParams.get('token') === token;
|
|
59
73
|
if (u.pathname === '/api/events') { // SSE
|
|
@@ -76,6 +90,7 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
|
76
90
|
const c = loadConflicts(ctx.hub).find((x) => x.id === b.id);
|
|
77
91
|
if (!c) { res.writeHead(404); return res.end('{"error":"not found"}'); }
|
|
78
92
|
if (!b.reason?.trim()) { res.writeHead(400); return res.end('{"error":"reason required"}'); }
|
|
93
|
+
req.logNote = `裁决了一个冲突(${{ 'keep-a': '采用方案 A', 'keep-b': '采用方案 B', merge: '合并两条', dismissed: '其实不冲突' }[b.resolution] || b.resolution})`;
|
|
79
94
|
decide(ctx.hub, c, { resolution: b.resolution, custom: b.custom || null, reason: b.reason, by: 'web-ui' });
|
|
80
95
|
c.status = 'resolved';
|
|
81
96
|
const { writeConflict } = await import('../lib/conflicts.js');
|
|
@@ -121,6 +136,7 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
|
121
136
|
}
|
|
122
137
|
if (u.pathname === '/api/targets') { // web 改投影目标
|
|
123
138
|
const name = b.name, targets = b.targets || [];
|
|
139
|
+
req.logNote = `修改了「${name}」的安装位置`;
|
|
124
140
|
const lib = readLibrary(ctx.hub);
|
|
125
141
|
const s = lib.skills?.[name];
|
|
126
142
|
if (!s) { res.writeHead(404); return res.end('{"error":"not found"}'); }
|