@jiyr0119/dsh-service-console 0.7.2 → 0.9.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.
- package/README.md +7 -5
- package/README.zh.md +7 -5
- package/docs/local-debugging.md +1 -1
- package/docs/rc5-upgrade-review.zh.md +182 -0
- package/docs/release-checklist.md +15 -12
- package/icon.svg +8 -0
- package/lib/client/dictionaries.js +19 -2
- package/lib/client/i18n.js +29 -70
- package/lib/client/service-list-view.js +186 -0
- package/lib/client.js +1284 -685
- package/lib/host/config.js +1 -2
- package/lib/host/ledger.js +2 -3
- package/lib/host/lifecycle.js +2 -3
- package/lib/host/ownership.js +8 -4
- package/lib/host/process-inspector.js +1 -2
- package/lib/host/protection.js +1 -2
- package/lib/host/redaction.js +1 -2
- package/lib/host/service-registry.js +4 -5
- package/lib/host/service-tool.js +42 -4
- package/lib/index.js +54 -11
- package/lib/types/client/ServiceConsole.d.ts +35 -15
- package/lib/types/client/ServiceDockPill.d.ts +29 -0
- package/lib/types/client/ServiceListCard.d.ts +17 -0
- package/lib/types/client/api.d.ts +19 -0
- package/lib/types/client/dictionaries.d.ts +18 -0
- package/lib/types/client/i18n.d.ts +33 -40
- package/lib/types/client/index.d.ts +21 -10
- package/lib/types/client/service-list-view.d.ts +92 -0
- package/lib/types/host/ledger.d.ts +7 -0
- package/lib/types/host/ownership.d.ts +9 -1
- package/lib/types/host/service-registry.d.ts +2 -1
- package/lib/types/host/service-tool.d.ts +7 -2
- package/lib/types/index.d.ts +18 -2
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +34 -33
- package/dsh.plugin.json +0 -16
- package/dynamic/client.js +0 -193
- package/dynamic/host.js +0 -337
- package/manifest.json +0 -24
package/lib/host/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
|
|
4
|
+
// src/host/config.ts
|
|
5
5
|
const DEFAULT_CONFIG = {
|
|
6
6
|
refreshInterval: 5e3,
|
|
7
7
|
defaultScope: "workspace",
|
|
@@ -85,5 +85,4 @@ function validateConfigPatch(patch) {
|
|
|
85
85
|
next
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
//#endregion
|
|
89
88
|
export { CONFIG_LIMITS, DEFAULT_CONFIG, REFRESH_INTERVAL_CHOICES, loadConfigFromFile, saveConfigToFile, validateConfigPatch };
|
package/lib/host/ledger.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { redact } from "./redaction.js";
|
|
2
|
-
|
|
2
|
+
// src/host/ledger.ts
|
|
3
3
|
const DEV_COMMAND_RE = /(npm (run|start|dev)|pnpm (run|dev|start)|yarn (dev|start)|next dev|vite|uvicorn|gunicorn|flask run|django runserver|cargo run|node (server|app|index)|python3? -m (http.server|uvicorn)|serve|http-server|nodemon|tsx watch|deno run)/;
|
|
4
4
|
var SessionLedger = class {
|
|
5
5
|
entries = [];
|
|
@@ -9,7 +9,7 @@ var SessionLedger = class {
|
|
|
9
9
|
observe(exec) {
|
|
10
10
|
try {
|
|
11
11
|
if (!exec || exec.name !== "bash") return;
|
|
12
|
-
const args = exec.args
|
|
12
|
+
const args = exec.arguments ?? exec.args ?? {};
|
|
13
13
|
const command = String(args.command || "");
|
|
14
14
|
if (!DEV_COMMAND_RE.test(command)) return;
|
|
15
15
|
let sessionKey = null;
|
|
@@ -29,5 +29,4 @@ var SessionLedger = class {
|
|
|
29
29
|
} catch (err) {}
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
//#endregion
|
|
33
32
|
export { DEV_COMMAND_RE, SessionLedger };
|
package/lib/host/lifecycle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { redact } from "./redaction.js";
|
|
2
1
|
import { runCommand, shellQuote } from "./process-inspector.js";
|
|
3
|
-
|
|
2
|
+
import { redact } from "./redaction.js";
|
|
3
|
+
// src/host/lifecycle.ts
|
|
4
4
|
function ok(data) {
|
|
5
5
|
return {
|
|
6
6
|
ok: true,
|
|
@@ -55,5 +55,4 @@ async function restartService(deps, serviceId) {
|
|
|
55
55
|
command: redact(entry.command) ?? entry.command
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
//#endregion
|
|
59
58
|
export { restartService, stopService };
|
package/lib/host/ownership.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
// src/host/ownership.ts
|
|
2
2
|
const SYSTEM_CWD_RE = /^(\/usr\/|\/System\/|\/Library\/|\/bin\/|\/sbin\/|\/private\/)/;
|
|
3
3
|
const LEDGER_WINDOW_MS = 6e5;
|
|
4
|
-
function classifyOwnership(proc, ledgers, workspaces) {
|
|
4
|
+
function classifyOwnership(proc, ledgers, workspaces, context = {}) {
|
|
5
5
|
const cwd = proc.cwd;
|
|
6
6
|
proc.command;
|
|
7
7
|
const evidence = [];
|
|
8
8
|
let ownership = "unknown";
|
|
9
9
|
let confidence = "unknown";
|
|
10
10
|
let ledgerEntry = null;
|
|
11
|
-
if (cwd && ledgers.length > 0)
|
|
11
|
+
if (cwd && ledgers.length > 0) {
|
|
12
|
+
const candidate = ledgers.find((l) => l.cwd && cwd.indexOf(l.cwd) === 0 && proc.startedAt !== null && Math.abs(proc.startedAt - l.at) < LEDGER_WINDOW_MS) ?? null;
|
|
13
|
+
const sessionId = context.sessionId ?? null;
|
|
14
|
+
if (candidate !== null && sessionId !== null && candidate.sessionKey !== null && candidate.sessionKey !== sessionId) evidence.push("launch ledger entry belongs to another session: " + String(candidate.sessionKey).slice(0, 16));
|
|
15
|
+
else ledgerEntry = candidate;
|
|
16
|
+
}
|
|
12
17
|
if (ledgerEntry) {
|
|
13
18
|
ownership = "conversation-confirmed";
|
|
14
19
|
confidence = "confirmed";
|
|
@@ -32,5 +37,4 @@ function classifyOwnership(proc, ledgers, workspaces) {
|
|
|
32
37
|
ledgerEntry
|
|
33
38
|
};
|
|
34
39
|
}
|
|
35
|
-
//#endregion
|
|
36
40
|
export { classifyOwnership };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
|
-
|
|
2
|
+
// src/host/process-inspector.ts
|
|
3
3
|
const MONTHS = {
|
|
4
4
|
Jan: 1,
|
|
5
5
|
Feb: 2,
|
|
@@ -174,5 +174,4 @@ async function scanRaw(commandRunner = runCommand) {
|
|
|
174
174
|
partialWarnings
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
|
-
//#endregion
|
|
178
177
|
export { parseAddress, parseListenRows, parseLstart, parsePsRows, runCommand, scanRaw, shellQuote };
|
package/lib/host/protection.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/host/protection.ts
|
|
2
2
|
const CRITICAL_NAMES = /* @__PURE__ */ new Set([
|
|
3
3
|
"launchd",
|
|
4
4
|
"kernel_task",
|
|
@@ -37,5 +37,4 @@ function classifyProtection(proc, guard = {}) {
|
|
|
37
37
|
evidence: unique
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
//#endregion
|
|
41
40
|
export { classifyProtection };
|
package/lib/host/redaction.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/host/redaction.ts
|
|
2
2
|
const REDACT_RULES = [
|
|
3
3
|
{
|
|
4
4
|
re: /(--(?:token|password|passwd|secret|key|api[-_]?key|client[-_]?secret|cookie|session))\s*[=:]\s*(\S+)/gi,
|
|
@@ -23,5 +23,4 @@ function redact(command) {
|
|
|
23
23
|
for (const rule of REDACT_RULES) out = out.replace(rule.re, (match, p1, p2, p3) => rule.replace(match, p1, p2, p3));
|
|
24
24
|
return out;
|
|
25
25
|
}
|
|
26
|
-
//#endregion
|
|
27
26
|
export { redact };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { redact } from "./redaction.js";
|
|
2
1
|
import { runCommand, scanRaw } from "./process-inspector.js";
|
|
2
|
+
import { redact } from "./redaction.js";
|
|
3
3
|
import { classifyOwnership } from "./ownership.js";
|
|
4
4
|
import { classifyProtection } from "./protection.js";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
|
-
|
|
6
|
+
// src/host/service-registry.ts
|
|
7
7
|
function sha256Hex(input) {
|
|
8
8
|
return createHash("sha256").update(input).digest("hex");
|
|
9
9
|
}
|
|
10
10
|
function isLocalhost(host) {
|
|
11
11
|
return host === "127.0.0.1" || host === "::1" || host === "localhost";
|
|
12
12
|
}
|
|
13
|
-
async function buildSnapshot(ledgers, workspaces, commandRunner = runCommand, guard = {}) {
|
|
13
|
+
async function buildSnapshot(ledgers, workspaces, commandRunner = runCommand, guard = {}, context = {}) {
|
|
14
14
|
const raw = await scanRaw(commandRunner);
|
|
15
15
|
const byPid = /* @__PURE__ */ new Map();
|
|
16
16
|
for (const l of raw.listeners) {
|
|
@@ -40,7 +40,7 @@ async function buildSnapshot(ledgers, workspaces, commandRunner = runCommand, gu
|
|
|
40
40
|
cwd,
|
|
41
41
|
command,
|
|
42
42
|
startedAt
|
|
43
|
-
}, ledgers, workspaces);
|
|
43
|
+
}, ledgers, workspaces, context);
|
|
44
44
|
const listenersFinal = listeners.map((l) => ({
|
|
45
45
|
...l,
|
|
46
46
|
url: isLocalhost(l.host) ? "http://localhost:" + l.port : null
|
|
@@ -80,5 +80,4 @@ async function buildSnapshot(ledgers, workspaces, commandRunner = runCommand, gu
|
|
|
80
80
|
ledgerCount: ledgers.length
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
//#endregion
|
|
84
83
|
export { buildSnapshot };
|
package/lib/host/service-tool.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
2
|
-
|
|
2
|
+
// src/host/service-tool.ts
|
|
3
3
|
/** 与 host/types.ts 的 Ownership 联合一致(运行时无从推导,双写靠测试对齐) */
|
|
4
4
|
const OWNERSHIP_LEVELS = [
|
|
5
5
|
"conversation-confirmed",
|
|
@@ -95,6 +95,16 @@ function buildServiceTool(deps) {
|
|
|
95
95
|
required: true,
|
|
96
96
|
description: "Comma-separated listening ports"
|
|
97
97
|
},
|
|
98
|
+
restartable: {
|
|
99
|
+
type: "boolean",
|
|
100
|
+
required: true,
|
|
101
|
+
description: "True when the launch ledger can safely reproduce this service (restart entry point)"
|
|
102
|
+
},
|
|
103
|
+
url: {
|
|
104
|
+
type: "string",
|
|
105
|
+
required: true,
|
|
106
|
+
description: "Openable localhost URL for the first listener, empty when the service does not listen on a loopback address"
|
|
107
|
+
},
|
|
98
108
|
cwd: {
|
|
99
109
|
type: "string",
|
|
100
110
|
required: true,
|
|
@@ -111,6 +121,20 @@ function buildServiceTool(deps) {
|
|
|
111
121
|
}
|
|
112
122
|
}
|
|
113
123
|
},
|
|
124
|
+
presentationMeta: (_args, value) => ({
|
|
125
|
+
scannedAt: value.scannedAt,
|
|
126
|
+
total: value.total,
|
|
127
|
+
count: value.count,
|
|
128
|
+
services: value.services.slice(0, 20).map((s) => ({
|
|
129
|
+
id: s.id,
|
|
130
|
+
name: s.name.slice(0, 80),
|
|
131
|
+
ports: s.ports,
|
|
132
|
+
ownership: s.ownership,
|
|
133
|
+
protected: s.protected,
|
|
134
|
+
restartable: s.restartable,
|
|
135
|
+
url: typeof s.url === "string" && s.url !== "" ? s.url.slice(0, 2048) : null
|
|
136
|
+
}))
|
|
137
|
+
}),
|
|
114
138
|
render: (_args, value) => {
|
|
115
139
|
const lines = value.services.map((s) => {
|
|
116
140
|
const tag = s.protected ? "[protected] " : "";
|
|
@@ -124,8 +148,21 @@ function buildServiceTool(deps) {
|
|
|
124
148
|
}
|
|
125
149
|
},
|
|
126
150
|
isConcurrencySafe: () => true,
|
|
127
|
-
|
|
128
|
-
|
|
151
|
+
presentCall: () => ({
|
|
152
|
+
card: "generic",
|
|
153
|
+
title: "List local services",
|
|
154
|
+
kind: "execute"
|
|
155
|
+
}),
|
|
156
|
+
presentResult: (_args, result) => {
|
|
157
|
+
const first = result.content.flatMap((item) => item.type === "text" ? [item.text] : []).join("\n").split("\n")[0] ?? "";
|
|
158
|
+
return {
|
|
159
|
+
card: "generic",
|
|
160
|
+
...first === "" ? {} : { title: first.slice(0, 120) }
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
async execute(args, exec) {
|
|
164
|
+
const sessionId = exec?.agent?.id ?? null;
|
|
165
|
+
const snap = await deps.snapshot(sessionId);
|
|
129
166
|
let rows = snap.services;
|
|
130
167
|
if (args.ownership !== void 0) rows = rows.filter((s) => s.ownership === args.ownership);
|
|
131
168
|
if (args.query) {
|
|
@@ -141,7 +178,9 @@ function buildServiceTool(deps) {
|
|
|
141
178
|
status: s.status,
|
|
142
179
|
ownership: s.ownership,
|
|
143
180
|
protected: s.protected,
|
|
181
|
+
restartable: s.restartable,
|
|
144
182
|
ports: s.listeners.map((l) => String(l.port)).join(", "),
|
|
183
|
+
url: s.listeners.map((l) => l.url).filter((u) => typeof u === "string" && u !== "")[0] ?? "",
|
|
145
184
|
cwd: s.cwd ?? "",
|
|
146
185
|
evidence: [...s.ownershipEvidence]
|
|
147
186
|
}));
|
|
@@ -154,5 +193,4 @@ function buildServiceTool(deps) {
|
|
|
154
193
|
}
|
|
155
194
|
});
|
|
156
195
|
}
|
|
157
|
-
//#endregion
|
|
158
196
|
export { buildServiceTool };
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { buildSnapshot } from "./host/service-registry.js";
|
|
|
3
3
|
import { restartService, stopService } from "./host/lifecycle.js";
|
|
4
4
|
import { buildServiceTool } from "./host/service-tool.js";
|
|
5
5
|
import { loadConfigFromFile, saveConfigToFile, validateConfigPatch } from "./host/config.js";
|
|
6
|
-
|
|
6
|
+
// src/index.ts
|
|
7
7
|
async function readJsonBody(req) {
|
|
8
8
|
try {
|
|
9
9
|
let body = "";
|
|
@@ -21,6 +21,24 @@ function sendJson(res, status, payload) {
|
|
|
21
21
|
r.writeHead(status, { "content-type": "application/json; charset=utf-8" });
|
|
22
22
|
r.end(JSON.stringify(payload));
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* 调用方是否来自本机回环。
|
|
26
|
+
*
|
|
27
|
+
* rc.5 的 `dsh-host-webserver` 允许绑非 loopback 地址(容器 / Pod 场景),
|
|
28
|
+
* 此时同网段的任何客户端都能请求这些路由。停止/重启进程是**本机**操作,
|
|
29
|
+
* 变更类路由必须只接受回环来源,否则暴露 Web UI 就等于开放一个远程杀进程入口。
|
|
30
|
+
*
|
|
31
|
+
* 只信任 peer socket 地址(不读 `x-forwarded-for` 之类可伪造的请求头);
|
|
32
|
+
* 无法判定来源(例如同进程直调、Unix socket)时按本机处理,保持既有行为。
|
|
33
|
+
*/
|
|
34
|
+
function isLoopbackCaller(remoteAddress) {
|
|
35
|
+
if (!remoteAddress) return true;
|
|
36
|
+
const addr = remoteAddress.trim().toLowerCase();
|
|
37
|
+
const v4 = addr.startsWith("::ffff:") ? addr.slice(7) : addr;
|
|
38
|
+
if (v4 === "::1" || v4 === "localhost") return true;
|
|
39
|
+
if (v4 === "127.0.0.1") return true;
|
|
40
|
+
return /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v4);
|
|
41
|
+
}
|
|
24
42
|
var src_default = {
|
|
25
43
|
inject: ["timer", "webServer"],
|
|
26
44
|
apply(ctx) {
|
|
@@ -69,21 +87,27 @@ var src_default = {
|
|
|
69
87
|
} catch {}
|
|
70
88
|
return guard;
|
|
71
89
|
}
|
|
72
|
-
|
|
73
|
-
|
|
90
|
+
/** 快照(可带调用方会话 id → 「本次对话」归属按 sessionKey 收窄) */
|
|
91
|
+
function snapshot(sessionId) {
|
|
92
|
+
return buildSnapshot(ledger.list, workspaces(), void 0, protectionGuard(), { sessionId: sessionId ?? null });
|
|
93
|
+
}
|
|
94
|
+
/** 请求体里的会话 id(可缺省:HTTP/旧客户端保持启发式归属) */
|
|
95
|
+
function sessionIdOf(args) {
|
|
96
|
+
const v = args?.sessionId;
|
|
97
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
74
98
|
}
|
|
75
99
|
const routes = [
|
|
76
100
|
{
|
|
77
101
|
path: "/dsh-sc/api/services/scan",
|
|
78
|
-
handler: async () => ({
|
|
102
|
+
handler: async (args) => ({
|
|
79
103
|
ok: true,
|
|
80
|
-
data: await snapshot()
|
|
104
|
+
data: await snapshot(sessionIdOf(args))
|
|
81
105
|
})
|
|
82
106
|
},
|
|
83
107
|
{
|
|
84
108
|
path: "/dsh-sc/api/services/detail",
|
|
85
109
|
handler: async (args) => {
|
|
86
|
-
const svc = (await snapshot()).services.find((x) => x.id === String(args.serviceId ?? ""));
|
|
110
|
+
const svc = (await snapshot(sessionIdOf(args))).services.find((x) => x.id === String(args.serviceId ?? ""));
|
|
87
111
|
if (!svc) return {
|
|
88
112
|
ok: false,
|
|
89
113
|
error: {
|
|
@@ -102,16 +126,25 @@ var src_default = {
|
|
|
102
126
|
},
|
|
103
127
|
{
|
|
104
128
|
path: "/dsh-sc/api/services/stop",
|
|
129
|
+
mutating: true,
|
|
105
130
|
handler: async (args) => stopService(deps, String(args.serviceId ?? ""), String(args.mode ?? "graceful"))
|
|
106
131
|
},
|
|
107
132
|
{
|
|
108
133
|
path: "/dsh-sc/api/services/restart",
|
|
134
|
+
mutating: true,
|
|
109
135
|
handler: async (args) => restartService(deps, String(args.serviceId ?? ""))
|
|
110
136
|
},
|
|
111
137
|
{
|
|
112
138
|
path: "/dsh-sc/api/config",
|
|
113
|
-
handler: async (args) => {
|
|
139
|
+
handler: async (args, info) => {
|
|
114
140
|
const a = args || {};
|
|
141
|
+
if (a.action === "update" && !info.loopback) return {
|
|
142
|
+
ok: false,
|
|
143
|
+
error: {
|
|
144
|
+
code: "FORBIDDEN_REMOTE",
|
|
145
|
+
message: "non-loopback caller"
|
|
146
|
+
}
|
|
147
|
+
};
|
|
115
148
|
if (a.action === "update" && a.patch && typeof a.patch === "object") {
|
|
116
149
|
const v = validateConfigPatch(a.patch);
|
|
117
150
|
if (!v.ok) return {
|
|
@@ -151,6 +184,17 @@ var src_default = {
|
|
|
151
184
|
kind: "exact",
|
|
152
185
|
path: route.path,
|
|
153
186
|
handler: async (req, res) => {
|
|
187
|
+
const info = { loopback: isLoopbackCaller(req?.socket?.remoteAddress) };
|
|
188
|
+
if (route.mutating === true && !info.loopback) {
|
|
189
|
+
sendJson(res, 403, {
|
|
190
|
+
ok: false,
|
|
191
|
+
error: {
|
|
192
|
+
code: "FORBIDDEN_REMOTE",
|
|
193
|
+
message: "non-loopback caller"
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
154
198
|
const body = await readJsonBody(req);
|
|
155
199
|
if (body === null) {
|
|
156
200
|
sendJson(res, 400, {
|
|
@@ -163,7 +207,7 @@ var src_default = {
|
|
|
163
207
|
return;
|
|
164
208
|
}
|
|
165
209
|
try {
|
|
166
|
-
const result = await route.handler(body);
|
|
210
|
+
const result = await route.handler(body, info);
|
|
167
211
|
sendJson(res, result.ok ? 200 : 400, result);
|
|
168
212
|
} catch (e) {
|
|
169
213
|
sendJson(res, 500, {
|
|
@@ -184,7 +228,7 @@ var src_default = {
|
|
|
184
228
|
const tools = ctx.get("tools");
|
|
185
229
|
if (tools) ctx.effect(() => {
|
|
186
230
|
try {
|
|
187
|
-
const off = tools.register(buildServiceTool({ snapshot }));
|
|
231
|
+
const off = tools.register(buildServiceTool({ snapshot: (sessionId) => snapshot(sessionId) }));
|
|
188
232
|
if (process.env.DSH_SC_DEBUG === "1") console.log(`[dsh-sc] service_list registered: ${String(Boolean(tools.get("service_list")))}`);
|
|
189
233
|
return off;
|
|
190
234
|
} catch (e) {
|
|
@@ -195,5 +239,4 @@ var src_default = {
|
|
|
195
239
|
else if (process.env.DSH_SC_DEBUG === "1") console.log("[dsh-sc] tools service absent — service_list not registered");
|
|
196
240
|
}
|
|
197
241
|
};
|
|
198
|
-
|
|
199
|
-
export { src_default as default };
|
|
242
|
+
export { src_default as default, isLoopbackCaller };
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-service-console —
|
|
2
|
+
* dsh-service-console — 控制台内容组件(rc.5 右侧栏 tab 版)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* -
|
|
6
|
-
*
|
|
7
|
-
* -
|
|
4
|
+
* 结构(M1 迁移后):
|
|
5
|
+
* - `ServiceConsoleTab`:tab 内容体(工具条 + 服务列表 + 详情 + Toast)。
|
|
6
|
+
* 面板的边框/拖拽/停靠/焦点/关闭由右侧栏拥有,这里只画内容。
|
|
7
|
+
* - `ServiceConsoleEntry`:header 入口按钮,点击由侧栏打开 tab。
|
|
8
|
+
* - `ServiceConsoleSettings` / `ServiceConsoleIcon`:全局设置页与其导航图标。
|
|
9
|
+
*
|
|
10
|
+
* i18n:组件从 slot 注册项的 `locale:` 拿到框架合成的 `t`(按 namespace 类型化),
|
|
11
|
+
* 语言切换由渲染器按 locale revision 重渲染,不需要手动订阅。
|
|
12
|
+
* API:fetch 直连 webServer JSON 路由(不走 host.call / LLM)。
|
|
8
13
|
*/
|
|
9
14
|
import * as React from 'react';
|
|
10
|
-
import type {
|
|
15
|
+
import type { Translate } from './i18n';
|
|
16
|
+
/** rc.5 框架注入的 namespace 翻译函数(注册项声明 `locale:` 后出现在 props 上) */
|
|
17
|
+
export type ConsoleT = Translate;
|
|
11
18
|
interface TimerLike {
|
|
12
19
|
timeout(callback: () => void, delay: number): () => void;
|
|
13
20
|
}
|
|
14
|
-
/** 类型化翻译函数:key 为词典键(拼写错误=编译错误),params 替换 {vars}(locale 运行时完成) */
|
|
15
|
-
type Translate = (key: ConsoleKey, params?: Record<string, unknown>) => string;
|
|
16
21
|
export declare function bindTimer(t: TimerLike): void;
|
|
17
|
-
export declare function bindLocale(locale: {
|
|
18
|
-
t: Translate;
|
|
19
|
-
subscribe(fn: () => void): () => void;
|
|
20
|
-
}): void;
|
|
21
22
|
type ServiceScope = 'conversation' | 'workspace' | 'machine';
|
|
22
23
|
interface ConfigData {
|
|
23
24
|
refreshInterval: number;
|
|
@@ -26,10 +27,29 @@ interface ConfigData {
|
|
|
26
27
|
showUnknown: boolean;
|
|
27
28
|
forceKill: boolean;
|
|
28
29
|
}
|
|
29
|
-
export declare function ServiceConsoleEntry(
|
|
30
|
+
export declare function ServiceConsoleEntry({ t, openConsole }: {
|
|
31
|
+
t: ConsoleT;
|
|
32
|
+
openConsole: () => void;
|
|
33
|
+
}): React.ReactElement;
|
|
34
|
+
export interface SettingsSectionIconProps {
|
|
35
|
+
/** 请求的正方形边长(px)。 */
|
|
36
|
+
size: number;
|
|
37
|
+
/** 该 section 当前是否被选中。 */
|
|
38
|
+
active: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare function ServiceConsoleIcon({ size }: SettingsSectionIconProps): React.ReactElement;
|
|
30
41
|
export interface SettingsProps {
|
|
31
42
|
onSaved?: (config: ConfigData) => void;
|
|
32
43
|
}
|
|
33
|
-
export declare function ServiceConsoleSettings({ onSaved }: SettingsProps
|
|
34
|
-
|
|
44
|
+
export declare function ServiceConsoleSettings({ t, onSaved }: SettingsProps & {
|
|
45
|
+
t: ConsoleT;
|
|
46
|
+
}): React.ReactElement;
|
|
47
|
+
export interface ConsoleTabProps {
|
|
48
|
+
t: ConsoleT;
|
|
49
|
+
/** 调用方会话 id(注入自框架的 session 作用域 inject face) */
|
|
50
|
+
sessionId: string;
|
|
51
|
+
/** tab 是否可见(侧栏折叠 / 后台会话时为 false)——不可见时停止扫描与轮询 */
|
|
52
|
+
visible: boolean;
|
|
53
|
+
}
|
|
54
|
+
export declare function ServiceConsoleTab({ t, sessionId, visible }: ConsoleTabProps): React.ReactElement;
|
|
35
55
|
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* composer 常驻 pill(`conversation.composer.dock`)
|
|
3
|
+
*
|
|
4
|
+
* 只在**本会话**有归属服务(`conversation-confirmed`)时出现:
|
|
5
|
+
* `2 services · :5173 :3000` → 点击打开控制台 tab。
|
|
6
|
+
*
|
|
7
|
+
* 设计取舍:
|
|
8
|
+
* - 数据来自与面板同一个 `/dsh-sc/api/services/scan`(带 sessionId → 宿主按台账
|
|
9
|
+
* `sessionKey` 收窄归属),选择/摘要全部走纯函数(`service-list-view.ts`,有单测)。
|
|
10
|
+
* - 轮询**慢且可停**:20s 一次、页面隐藏时跳过、卸载即清;不为一个环境提示
|
|
11
|
+
* 引入高频 `lsof`。
|
|
12
|
+
* - 无归属服务时不渲染任何 DOM(不占位、不抢焦点)。
|
|
13
|
+
*/
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import type { ConsoleT } from './ServiceConsole';
|
|
16
|
+
/** 轮询间隔:环境提示够用,且不让 lsof 跑得太勤 */
|
|
17
|
+
export declare const POLL_INTERVAL_MS = 30000;
|
|
18
|
+
interface TimerLike {
|
|
19
|
+
interval(callback: () => void, delay: number): () => void;
|
|
20
|
+
}
|
|
21
|
+
/** 注入平台 timer(与面板共用 `bindTimer` 的同一份服务,但这里需要 interval) */
|
|
22
|
+
export declare function bindDockTimer(t: TimerLike): void;
|
|
23
|
+
export interface ServiceDockPillProps {
|
|
24
|
+
t: ConsoleT;
|
|
25
|
+
/** 会话作用域 inject face 注入 */
|
|
26
|
+
sessionId: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function ServiceDockPill({ t, sessionId }: ServiceDockPillProps): React.ReactElement | null;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* service_list 的聊天卡片(`tool.call.toolview`,keyed by wire tool name)
|
|
3
|
+
*
|
|
4
|
+
* 数据来自工具 `output.presentationMeta`(随会话日志持久化 → 视为不可信),
|
|
5
|
+
* 投影成视图模型由纯函数 `projectServiceListMeta` 完成;任何坏形状都回退成
|
|
6
|
+
* 纯文本行,**绝不抛错**——toolview 抛错会让该 key 粘性空白。
|
|
7
|
+
*
|
|
8
|
+
* 交互约束(与面板同一语义,不新增策略):
|
|
9
|
+
* - 受保护目标只读;「重启」还要求 meta 里的 `restartable`(无安全启动记录不提供);
|
|
10
|
+
* - 停止/重启二次确认 + 在途去重;错误码走词典;
|
|
11
|
+
* - 卡片是一次调用的**快照**,不轮询;折叠状态由平台的 `useDisclosure` 拥有。
|
|
12
|
+
*/
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
15
|
+
import type { ToolCallViewProps } from '@deepseek-ai/dsh-client-ui-tool/client';
|
|
16
|
+
export type ServiceListCardProps = ToolCallViewProps & PropsLocale<'dsh-service-console'>;
|
|
17
|
+
export declare function ServiceListCard(props: ServiceListCardProps): React.ReactElement;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host API 客户端(fetch 直连 webServer JSON 路由,不经过 LLM)
|
|
3
|
+
*
|
|
4
|
+
* 面板 tab 与聊天卡片共用同一份调用约定:统一信封 `{ ok, data | error }`。
|
|
5
|
+
*/
|
|
6
|
+
export interface Envelope<T> {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
data?: T;
|
|
9
|
+
error?: {
|
|
10
|
+
code?: string;
|
|
11
|
+
message?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 调用一条 `/dsh-sc/api/*` 路由。
|
|
16
|
+
* @param path 路由尾段(例如 `services/scan`)
|
|
17
|
+
* @param payload JSON 请求体
|
|
18
|
+
*/
|
|
19
|
+
export declare function api<T>(path: string, payload: Record<string, unknown>): Promise<T>;
|
|
@@ -17,6 +17,12 @@ export declare const ZH_DICT: {
|
|
|
17
17
|
'status.lastScan': string;
|
|
18
18
|
'status.error': string;
|
|
19
19
|
'svc.noSvc': string;
|
|
20
|
+
'card.summary': string;
|
|
21
|
+
'card.more': string;
|
|
22
|
+
'card.confirm': string;
|
|
23
|
+
'svc.restartable': string;
|
|
24
|
+
'dock.pill': string;
|
|
25
|
+
'dock.open': string;
|
|
20
26
|
'svc.ports': string;
|
|
21
27
|
'svc.pid': string;
|
|
22
28
|
'svc.command': string;
|
|
@@ -24,6 +30,7 @@ export declare const ZH_DICT: {
|
|
|
24
30
|
'action.stop': string;
|
|
25
31
|
'action.restart': string;
|
|
26
32
|
'action.detail': string;
|
|
33
|
+
'action.open': string;
|
|
27
34
|
'action.confirm': string;
|
|
28
35
|
'action.cancel': string;
|
|
29
36
|
'action.pending': string;
|
|
@@ -38,6 +45,7 @@ export declare const ZH_DICT: {
|
|
|
38
45
|
'own.other': string;
|
|
39
46
|
'own.unknown': string;
|
|
40
47
|
'own.protected': string;
|
|
48
|
+
'scope.filter': string;
|
|
41
49
|
'scope.conversation': string;
|
|
42
50
|
'scope.workspace': string;
|
|
43
51
|
'scope.machine': string;
|
|
@@ -58,6 +66,7 @@ export declare const ZH_DICT: {
|
|
|
58
66
|
'err.RESTART_UNSAFE': string;
|
|
59
67
|
'err.PORT_CONFLICT': string;
|
|
60
68
|
'err.START_TIMEOUT': string;
|
|
69
|
+
'err.FORBIDDEN_REMOTE': string;
|
|
61
70
|
'tab.services': string;
|
|
62
71
|
'tab.settings': string;
|
|
63
72
|
'settings.title': string;
|
|
@@ -93,6 +102,12 @@ export declare const EN_DICT: {
|
|
|
93
102
|
'status.lastScan': string;
|
|
94
103
|
'status.error': string;
|
|
95
104
|
'svc.noSvc': string;
|
|
105
|
+
'card.summary': string;
|
|
106
|
+
'card.more': string;
|
|
107
|
+
'card.confirm': string;
|
|
108
|
+
'svc.restartable': string;
|
|
109
|
+
'dock.pill': string;
|
|
110
|
+
'dock.open': string;
|
|
96
111
|
'svc.ports': string;
|
|
97
112
|
'svc.pid': string;
|
|
98
113
|
'svc.command': string;
|
|
@@ -100,6 +115,7 @@ export declare const EN_DICT: {
|
|
|
100
115
|
'action.stop': string;
|
|
101
116
|
'action.restart': string;
|
|
102
117
|
'action.detail': string;
|
|
118
|
+
'action.open': string;
|
|
103
119
|
'action.confirm': string;
|
|
104
120
|
'action.cancel': string;
|
|
105
121
|
'action.pending': string;
|
|
@@ -114,6 +130,7 @@ export declare const EN_DICT: {
|
|
|
114
130
|
'own.other': string;
|
|
115
131
|
'own.unknown': string;
|
|
116
132
|
'own.protected': string;
|
|
133
|
+
'scope.filter': string;
|
|
117
134
|
'scope.conversation': string;
|
|
118
135
|
'scope.workspace': string;
|
|
119
136
|
'scope.machine': string;
|
|
@@ -134,6 +151,7 @@ export declare const EN_DICT: {
|
|
|
134
151
|
'err.RESTART_UNSAFE': string;
|
|
135
152
|
'err.PORT_CONFLICT': string;
|
|
136
153
|
'err.START_TIMEOUT': string;
|
|
154
|
+
'err.FORBIDDEN_REMOTE': string;
|
|
137
155
|
'tab.services': string;
|
|
138
156
|
'tab.settings': string;
|
|
139
157
|
'settings.title': string;
|