dsh-dock 0.23.1 → 0.25.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 (38) hide show
  1. package/README.md +50 -40
  2. package/client.js +2552 -472
  3. package/features/animation/host.js +3 -2
  4. package/features/balance/host.js +3 -3
  5. package/features/dshtools/host.js +319 -0
  6. package/features/dshtools/view.jsx +403 -0
  7. package/features/git/host.js +884 -0
  8. package/features/git/rpc.js +156 -0
  9. package/features/git/view.jsx +1946 -0
  10. package/features/mcpconfig/host.js +3 -3
  11. package/features/mcpconfig/view.js +8 -8
  12. package/features/mobile-relay/host.js +42 -9
  13. package/features/modelconfig/host.js +3 -3
  14. package/features/notify/host.js +3 -2
  15. package/features/notify/view.jsx +38 -46
  16. package/features/providerconfig/host.js +3 -3
  17. package/features/runstate/host.js +3 -2
  18. package/features/tokenlog/host.js +3 -2
  19. package/features/tts/host.js +3 -2
  20. package/index.js +8 -2
  21. package/package.json +5 -6
  22. package/src/client.jsx +21 -2
  23. package/src/host-core.js +52 -13
  24. package/screenshots/dock-animation.png +0 -0
  25. package/screenshots/dock-balance.png +0 -0
  26. package/screenshots/dock-games.png +0 -0
  27. package/screenshots/dock-home.png +0 -0
  28. package/screenshots/dock-modelconfig-provider-create.png +0 -0
  29. package/screenshots/dock-modelconfig-provider-edit.png +0 -0
  30. package/screenshots/dock-modelconfig-providers.png +0 -0
  31. package/screenshots/dock-modelconfig.png +0 -0
  32. package/screenshots/dock-notify.png +0 -0
  33. package/screenshots/dock-runstate.png +0 -0
  34. package/screenshots/dock-settings.png +0 -0
  35. package/screenshots/dock-tokenlog-charts-2.png +0 -0
  36. package/screenshots/dock-tokenlog-charts-3.png +0 -0
  37. package/screenshots/dock-tokenlog-charts.png +0 -0
  38. package/screenshots/dock-tokenlog.png +0 -0
@@ -0,0 +1,156 @@
1
+ // dsh-dock · 功能模块【Git 管理】· 客户端 Host 通信
2
+ //
3
+ // 路由一律用文档相对路径(不带前导斜杠):DSH 的 index.html 带 <base href="./">,
4
+ // 子路径反代(如 /ui/)下自动解析为 /ui/dsh-dock/...,根挂载下即 dsh-dock/...。
5
+ // 写死前导斜杠会绕过反代挂载前缀,请求被 302 打回应用入口。
6
+
7
+ /** 调一条 git 路由;失败时抛带宿主错误说明的 Error。 */
8
+ export async function rpc(method, body) {
9
+ const res = await fetch("dsh-dock/git/" + method, {
10
+ method: body === undefined ? "GET" : "POST",
11
+ headers: body === undefined ? undefined : { "content-type": "application/json" },
12
+ body: body === undefined ? undefined : JSON.stringify(body),
13
+ });
14
+ const data = await res.json().catch(() => ({}));
15
+ if (res.ok && data && data.ok === true) return data.data;
16
+ if (res.status === 404 || res.status === 405) {
17
+ throw new Error("宿主侧没有「Git 管理」接口:宿主进程可能是旧版本,或该功能在宿主侧未启用(重启 dsh web,或把功能坞里的开关关掉再打开)");
18
+ }
19
+ const message = data && data.error && data.error.message;
20
+ throw new Error(message || ("HTTP " + res.status));
21
+ }
22
+
23
+ /** 时间格式:列表里用相对时间更好扫读,悬停再给完整时间。 */
24
+ export function fmtAgo(iso) {
25
+ if (!iso) return "";
26
+ const t = new Date(iso).getTime();
27
+ if (Number.isNaN(t)) return "";
28
+ const diff = Math.max(0, Date.now() - t);
29
+ const min = Math.floor(diff / 60000);
30
+ if (min < 1) return "刚刚";
31
+ if (min < 60) return min + " 分钟前";
32
+ const hour = Math.floor(min / 60);
33
+ if (hour < 24) return hour + " 小时前";
34
+ const day = Math.floor(hour / 24);
35
+ if (day < 30) return day + " 天前";
36
+ const month = Math.floor(day / 30);
37
+ if (month < 12) return month + " 个月前";
38
+ return Math.floor(month / 12) + " 年前";
39
+ }
40
+
41
+ /** 完整时间:YYYY-MM-DD HH:mm。 */
42
+ export function fmtTime(iso) {
43
+ if (!iso) return "";
44
+ const d = new Date(iso);
45
+ if (Number.isNaN(d.getTime())) return String(iso);
46
+ const p = (x) => String(x).padStart(2, "0");
47
+ return d.getFullYear() + "-" + p(d.getMonth() + 1) + "-" + p(d.getDate()) + " " + p(d.getHours()) + ":" + p(d.getMinutes());
48
+ }
49
+
50
+ /**
51
+ * 完整时间:年月日时分秒,形如 2026-11-26 23:26:32。
52
+ *
53
+ * 为什么单独一个函数:列表里的「13 分钟前」适合扫读,但排查问题、对日志、写记录时要的是
54
+ * 精确到秒的绝对时间。两者都留,各管一种场景。
55
+ * @param {string} iso ISO 时间字符串
56
+ * @returns {string} 本地时间;无效输入原样返回
57
+ */
58
+ export function fmtDateTime(iso) {
59
+ if (!iso) return "";
60
+ const d = new Date(iso);
61
+ if (Number.isNaN(d.getTime())) return String(iso);
62
+ const p = (x) => String(x).padStart(2, "0");
63
+ return d.getFullYear() + "-" + p(d.getMonth() + 1) + "-" + p(d.getDate())
64
+ + " " + p(d.getHours()) + ":" + p(d.getMinutes()) + ":" + p(d.getSeconds());
65
+ }
66
+
67
+ /** 截断长串(保留结尾省略号)。 */
68
+ export function truncate(str, max) {
69
+ if (!str) return "";
70
+ const s = String(str);
71
+ return s.length > max ? s.slice(0, max) + "…" : s;
72
+ }
73
+
74
+ /** 引用标签精简:HEAD -> main 只留 HEAD;tag: xxx 去掉前缀。 */
75
+ export function shortRefs(refs) {
76
+ if (!Array.isArray(refs) || refs.length === 0) return [];
77
+ const out = [];
78
+ for (const raw of refs) {
79
+ const ref = String(raw).trim();
80
+ if (!ref) continue;
81
+ if (ref.indexOf("HEAD -> ") === 0) { out.push("HEAD"); continue; }
82
+ out.push(ref.replace(/^tag:\s*/, ""));
83
+ }
84
+ return out.slice(0, 3);
85
+ }
86
+
87
+ /** 从一个会话的行数据里读工作目录:投影优先,其次 cwd。 */
88
+ function dirOfSessionState(state, sessionId) {
89
+ if (!state || !sessionId) return "";
90
+ const projected = state.projectionsBySession && state.projectionsBySession[sessionId]
91
+ ? state.projectionsBySession[sessionId].values
92
+ : undefined;
93
+ if (projected && typeof projected.workingDirectory === "string" && projected.workingDirectory) {
94
+ return projected.workingDirectory;
95
+ }
96
+ const row = state.byId ? state.byId[sessionId] : undefined;
97
+ if (row) {
98
+ const rowProjected = row.projectionValues;
99
+ if (rowProjected && typeof rowProjected.workingDirectory === "string" && rowProjected.workingDirectory) {
100
+ return rowProjected.workingDirectory;
101
+ }
102
+ if (typeof row.cwd === "string" && row.cwd) return row.cwd;
103
+ }
104
+ return "";
105
+ }
106
+
107
+ /**
108
+ * 指定会话的工作目录。
109
+ *
110
+ * **必须按 sessionId 查,不能读「界面上当前那个会话」**:
111
+ * 抽屉页签的作用域就是它所属的会话,而 uiSession.adapter.current 是全局的
112
+ * 「当前可见会话」——在侧栏里切换、或同时开多个面板时,两者会不一致,
113
+ * 表现为「从哪个会话打开都显示同一个目录」。
114
+ *
115
+ * @param {object} ctx 客户端 context
116
+ * @param {string} [sessionId] 目标会话;不传才退回全局当前会话
117
+ * @returns {string} 绝对路径;取不到返回空串
118
+ */
119
+ export function currentSessionDir(ctx, sessionId) {
120
+ if (!ctx || typeof ctx.get !== "function") return "";
121
+ try {
122
+ const sessions = ctx.get("sessions");
123
+ if (!sessions || typeof sessions.list.getSnapshot !== "function") return "";
124
+ const state = sessions.list.getSnapshot();
125
+
126
+ // 1) 调用方明确给了会话:直接按 id 取(正确路径)
127
+ if (sessionId) {
128
+ const direct = dirOfSessionState(state, sessionId);
129
+ if (direct) return direct;
130
+ }
131
+
132
+ // 2) 没给会话:退回「当前可见会话」
133
+ let fallbackId = "";
134
+ try {
135
+ const uiSession = ctx.get("uiSession");
136
+ const snap = uiSession && uiSession.adapter && uiSession.adapter.current
137
+ ? uiSession.adapter.current.getSnapshot()
138
+ : null;
139
+ fallbackId = snap && snap.props ? snap.props.sessionId : "";
140
+ } catch {
141
+ fallbackId = "";
142
+ }
143
+ return dirOfSessionState(state, fallbackId);
144
+ } catch {
145
+ return "";
146
+ }
147
+ }
148
+
149
+ /** 原生选目录:uiWorkspace.pickDirectory()。服务缺失(桌面端 / 测试桩)返回 null。 */
150
+ export async function pickDirectory(ctx) {
151
+ if (!ctx || typeof ctx.get !== "function") return null;
152
+ let uiw = null;
153
+ try { uiw = ctx.get("uiWorkspace"); } catch { return null; }
154
+ if (!uiw || typeof uiw.pickDirectory !== "function") return null;
155
+ try { return await uiw.pickDirectory(); } catch { return null; }
156
+ }