dsh-sidebar-sessions 0.1.6 → 0.2.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 +88 -68
- package/lib/client.js +746 -150
- package/lib/index.js +466 -3
- package/lib/rules.js +548 -0
- package/package.json +60 -56
package/lib/client.js
CHANGED
|
@@ -19,7 +19,6 @@ window.__ModuleLoader__.load({
|
|
|
19
19
|
const { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } = React;
|
|
20
20
|
const inject = ["slots", "sessions", "workspaces", "uiWorkspace", "uiSession", "remote", "remote.schedule"];
|
|
21
21
|
|
|
22
|
-
const STORE_KEY = "dsh-session-groups.v1";
|
|
23
22
|
const RECENT_LIMIT = 20;
|
|
24
23
|
|
|
25
24
|
const CSS = `
|
|
@@ -68,6 +67,29 @@ window.__ModuleLoader__.load({
|
|
|
68
67
|
.dsg-ws-btn{flex:1;display:flex;align-items:center;justify-content:center;height:34px;box-sizing:border-box;border:1px dashed var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:transparent;color:var(--dsw-alias-label-secondary,#6b7280);font-size:13px;line-height:1;border-radius:var(--dsw-radius-sm,8px);cursor:pointer}
|
|
69
68
|
.dsg-ws-btn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
70
69
|
.dsg-ws-row{display:flex;align-items:center;height:28px;padding:0 8px;font-size:12px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
70
|
+
.dsg-ws-row{display:flex;align-items:center;height:28px;padding:0 8px;font-size:12px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
71
|
+
.dsg-consent{margin:0 2px 8px;padding:8px 10px;border:1px solid var(--dsw-alias-state-business-primary,#4d6bfe);border-radius:var(--dsw-radius-md,12px);background:var(--dsw-alias-bg-layer-1,#1a1d21);display:flex;flex-direction:column;gap:6px}
|
|
72
|
+
.dsg-consent-title{font-size:12px;line-height:17px;color:var(--dsw-alias-label-primary,#e5e7eb)}
|
|
73
|
+
.dsg-consent-group{color:var(--dsw-alias-state-business-primary,#4d6bfe);font-weight:600}
|
|
74
|
+
.dsg-consent-note{font-size:11px;line-height:15px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
75
|
+
.dsg-consent-actions{display:flex;flex-wrap:wrap;gap:6px}
|
|
76
|
+
.dsg-btn{height:26px;padding:0 10px;font-size:12px;line-height:1;border-radius:var(--dsw-radius-s,8px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:transparent;color:var(--dsw-alias-label-primary,#e5e7eb);cursor:pointer}
|
|
77
|
+
.dsg-btn:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
78
|
+
.dsg-btn[data-tone="primary"]{border-color:var(--dsw-alias-state-business-primary,#4d6bfe);color:var(--dsw-alias-state-business-primary,#4d6bfe)}
|
|
79
|
+
.dsg-btn[data-tone="ghost"]{border-color:transparent;color:var(--dsw-alias-label-secondary,#6b7280)}
|
|
80
|
+
.dsg-panel{position:fixed;z-index:10000;left:8px;bottom:8px;width:min(380px,calc(100vw - 16px));max-height:min(72vh,600px);overflow:auto;box-sizing:border-box;padding:10px;background:var(--dsw-alias-bg-layer-2,#24272c);border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.3));border-radius:var(--dsw-radius-md,12px);box-shadow:0 12px 32px rgba(0,0,0,.32);font-size:12px;color:var(--dsw-alias-label-primary,#e5e7eb);display:flex;flex-direction:column;gap:8px}
|
|
81
|
+
.dsg-panel-title{font-size:13px;font-weight:600;display:flex;align-items:center;gap:6px}
|
|
82
|
+
.dsg-panel-title .dsg-spacer{flex:1}
|
|
83
|
+
.dsg-field{display:flex;flex-direction:column;gap:4px}
|
|
84
|
+
.dsg-field-label{font-size:11px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
|
|
85
|
+
.dsg-input,.dsg-select{height:28px;box-sizing:border-box;padding:0 8px;border-radius:var(--dsw-radius-s,8px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:var(--dsw-alias-bg-layer-1,#1a1d21);color:var(--dsw-alias-label-primary,#e5e7eb);font-size:12px}
|
|
86
|
+
.dsg-sched{display:flex;align-items:center;gap:6px;font-size:11px;color:var(--dsw-alias-label-secondary,#6b7280);height:22px}
|
|
87
|
+
.dsg-rule{padding:6px 8px;border-radius:var(--dsw-radius-s,8px);background:var(--dsw-alias-bg-layer-1,#1a1d21);display:flex;flex-direction:column;gap:4px}
|
|
88
|
+
.dsg-rule-head{display:flex;align-items:center;gap:6px;font-size:12px;font-weight:600}
|
|
89
|
+
.dsg-rule-meta{font-size:11px;line-height:15px;color:var(--dsw-alias-label-tertiary,#9ca3af);word-break:break-all}
|
|
90
|
+
.dsg-rule-actions{display:flex;gap:4px;margin-left:auto}
|
|
91
|
+
.dsg-warn{font-size:11px;line-height:15px;padding:6px 8px;border-radius:var(--dsw-radius-s,8px);background:var(--dsw-alias-state-warning-bg,rgba(247,173,49,.12));color:var(--dsw-alias-state-warning-primary,#f7ad31)}
|
|
92
|
+
.dsg-dialog-mask{position:fixed;inset:0;z-index:9999;background:transparent}
|
|
71
93
|
`;
|
|
72
94
|
|
|
73
95
|
function injectStyles() {
|
|
@@ -80,51 +102,203 @@ window.__ModuleLoader__.load({
|
|
|
80
102
|
return () => style.remove();
|
|
81
103
|
}
|
|
82
104
|
|
|
83
|
-
|
|
105
|
+
/* ── 状态由宿主侧持有 ───────────────────────────────────────────────
|
|
106
|
+
* 分组/规则/待确认建议存在宿主的一份 JSON 里(~/.dsh/sidebar-sessions/
|
|
107
|
+
* state.json),Web GUI 与桌面端(dsh-app://app)读同一份:桌面壳把同源
|
|
108
|
+
* 相对路径的请求原样转发给宿主 HTTP 服务,所以这里只发相对 URL。
|
|
109
|
+
* localStorage 只当首屏缓存,以及宿主没注册路由时(老版本)的降级。 */
|
|
110
|
+
const API = "/dsh-sidebar-sessions/api";
|
|
111
|
+
const CACHE_KEY = "dsh-session-groups.cache.v2";
|
|
112
|
+
const LEGACY_KEY = "dsh-session-groups.v1";
|
|
113
|
+
|
|
114
|
+
const EMPTY_STATE = {
|
|
115
|
+
version: 2,
|
|
116
|
+
groups: [],
|
|
117
|
+
assign: {},
|
|
118
|
+
autoDone: {},
|
|
119
|
+
autoAllow: {},
|
|
120
|
+
pending: {},
|
|
121
|
+
rules: [],
|
|
122
|
+
settings: { classifier: { mode: "off", provider: "", model: "" } },
|
|
123
|
+
order: {},
|
|
124
|
+
collapsed: {},
|
|
125
|
+
hiddenWorkspaces: [],
|
|
126
|
+
activeWorkspace: null,
|
|
127
|
+
imported: false,
|
|
128
|
+
online: false,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
function asObject(value) {
|
|
132
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function asArray(value) {
|
|
136
|
+
return Array.isArray(value) ? value : [];
|
|
137
|
+
}
|
|
84
138
|
|
|
85
|
-
function
|
|
139
|
+
function mergeState(raw, online) {
|
|
140
|
+
const source = asObject(raw);
|
|
141
|
+
const settings = asObject(source.settings);
|
|
142
|
+
const classifier = asObject(settings.classifier);
|
|
143
|
+
return {
|
|
144
|
+
...EMPTY_STATE,
|
|
145
|
+
groups: asArray(source.groups)
|
|
146
|
+
.filter((group) => group && group.id && group.name)
|
|
147
|
+
.map((group) => ({ id: String(group.id), name: String(group.name) })),
|
|
148
|
+
assign: { ...asObject(source.assign) },
|
|
149
|
+
autoDone: { ...asObject(source.autoDone) },
|
|
150
|
+
autoAllow: { ...asObject(source.autoAllow) },
|
|
151
|
+
pending: { ...asObject(source.pending) },
|
|
152
|
+
rules: asArray(source.rules)
|
|
153
|
+
.filter((rule) => rule && rule.groupName)
|
|
154
|
+
.map((rule) => ({
|
|
155
|
+
id: String(rule.id || ""),
|
|
156
|
+
groupName: String(rule.groupName),
|
|
157
|
+
any: asArray(rule.any).map(String),
|
|
158
|
+
none: asArray(rule.none).map(String),
|
|
159
|
+
scheduleIds: asArray(rule.scheduleIds).map(String),
|
|
160
|
+
scheduleTitles: asArray(rule.scheduleTitles).map(String),
|
|
161
|
+
})),
|
|
162
|
+
settings: {
|
|
163
|
+
classifier: {
|
|
164
|
+
mode: classifier.mode === "llm" ? "llm" : "off",
|
|
165
|
+
provider: String(classifier.provider || ""),
|
|
166
|
+
model: String(classifier.model || ""),
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
order: { ...asObject(source.order) },
|
|
170
|
+
collapsed: { ...asObject(source.collapsed) },
|
|
171
|
+
hiddenWorkspaces: asArray(source.hiddenWorkspaces).map(String),
|
|
172
|
+
activeWorkspace:
|
|
173
|
+
source.activeWorkspace === null || source.activeWorkspace === undefined ? null : String(source.activeWorkspace),
|
|
174
|
+
imported: source.imported === true,
|
|
175
|
+
online: online === undefined ? false : online === true,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function readCache() {
|
|
86
180
|
try {
|
|
87
|
-
const raw = window.localStorage.getItem(
|
|
88
|
-
if (!raw) return { ...
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
181
|
+
const raw = window.localStorage.getItem(CACHE_KEY);
|
|
182
|
+
if (!raw) return { ...EMPTY_STATE };
|
|
183
|
+
return mergeState(JSON.parse(raw), false);
|
|
184
|
+
} catch {
|
|
185
|
+
return { ...EMPTY_STATE };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function writeCache(state) {
|
|
190
|
+
try {
|
|
191
|
+
window.localStorage.setItem(CACHE_KEY, JSON.stringify({ ...state, online: false }));
|
|
192
|
+
} catch {}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function readLegacy() {
|
|
196
|
+
try {
|
|
197
|
+
const raw = window.localStorage.getItem(LEGACY_KEY);
|
|
198
|
+
return raw ? JSON.parse(raw) : undefined;
|
|
100
199
|
} catch {
|
|
101
|
-
return
|
|
200
|
+
return undefined;
|
|
102
201
|
}
|
|
103
202
|
}
|
|
104
203
|
|
|
105
|
-
function
|
|
204
|
+
async function request(path, init) {
|
|
205
|
+
const response = await fetch(API + path, { credentials: "same-origin", cache: "no-store", ...init });
|
|
206
|
+
const text = await response.text();
|
|
207
|
+
let value = {};
|
|
106
208
|
try {
|
|
107
|
-
|
|
209
|
+
value = text ? JSON.parse(text) : {};
|
|
108
210
|
} catch {}
|
|
211
|
+
if (!response.ok || value.ok === false) throw new Error(String((value && value.error) || "HTTP " + response.status));
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function apiOp(payload) {
|
|
216
|
+
return request("/op", {
|
|
217
|
+
method: "POST",
|
|
218
|
+
headers: { "content-type": "application/json", "x-dsg-request": "1" },
|
|
219
|
+
body: JSON.stringify(payload),
|
|
220
|
+
});
|
|
109
221
|
}
|
|
110
222
|
|
|
111
223
|
const store = (() => {
|
|
112
|
-
let state =
|
|
224
|
+
let state = readCache();
|
|
113
225
|
const listeners = new Set();
|
|
226
|
+
let lastSyncAt = 0;
|
|
227
|
+
let lastDigest = "";
|
|
228
|
+
let legacyTried = false;
|
|
229
|
+
let meta = { statePath: "" };
|
|
114
230
|
const emit = () => {
|
|
115
231
|
for (const fn of listeners) fn();
|
|
116
232
|
};
|
|
233
|
+
const commit = (next, online) => {
|
|
234
|
+
state = { ...next, online: online === undefined ? state.online : online === true };
|
|
235
|
+
writeCache(state);
|
|
236
|
+
emit();
|
|
237
|
+
};
|
|
117
238
|
return {
|
|
118
239
|
get: () => state,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
writeStore(state);
|
|
122
|
-
emit();
|
|
123
|
-
},
|
|
240
|
+
meta: () => meta,
|
|
241
|
+
commit,
|
|
124
242
|
subscribe(fn) {
|
|
125
243
|
listeners.add(fn);
|
|
126
244
|
return () => listeners.delete(fn);
|
|
127
245
|
},
|
|
246
|
+
async load() {
|
|
247
|
+
try {
|
|
248
|
+
const result = await request("/state");
|
|
249
|
+
meta = { statePath: String((result.meta && result.meta.statePath) || "") };
|
|
250
|
+
commit(mergeState(result.state), true);
|
|
251
|
+
return true;
|
|
252
|
+
} catch {
|
|
253
|
+
if (state.online) commit({ ...state }, false);
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
/** 把会话/定时任务快照交给宿主:判定与写入只有宿主一处。 */
|
|
258
|
+
async sync(sessions, schedules) {
|
|
259
|
+
const digest =
|
|
260
|
+
sessions.map((row) => row.id + "\u0001" + row.title).join("\u0002") +
|
|
261
|
+
"\u0003" +
|
|
262
|
+
schedules.map((row) => row.id + ":" + (row.targetSessionId || "") + ":" + (row.deliveredAt || "")).join("\u0002");
|
|
263
|
+
if (digest === lastDigest && Date.now() - lastSyncAt < 15000) return;
|
|
264
|
+
lastDigest = digest;
|
|
265
|
+
lastSyncAt = Date.now();
|
|
266
|
+
try {
|
|
267
|
+
const result = await request("/sync", {
|
|
268
|
+
method: "POST",
|
|
269
|
+
headers: { "content-type": "application/json", "x-dsg-request": "1" },
|
|
270
|
+
body: JSON.stringify({ sessions, schedules }),
|
|
271
|
+
});
|
|
272
|
+
meta = { statePath: String((result.meta && result.meta.statePath) || meta.statePath) };
|
|
273
|
+
commit(mergeState(result.state), true);
|
|
274
|
+
} catch {
|
|
275
|
+
if (state.online) commit({ ...state }, false);
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
async op(payload) {
|
|
279
|
+
const result = await apiOp(payload);
|
|
280
|
+
commit(mergeState(result.state), true);
|
|
281
|
+
return result;
|
|
282
|
+
},
|
|
283
|
+
/** v1(纯 localStorage 时代)的分组只在第一次接上宿主时导入一次。 */
|
|
284
|
+
async importLegacy() {
|
|
285
|
+
if (legacyTried || state.imported) return;
|
|
286
|
+
legacyTried = true;
|
|
287
|
+
const legacy = readLegacy();
|
|
288
|
+
if (!legacy || !asArray(legacy.groups).length) return;
|
|
289
|
+
try {
|
|
290
|
+
const result = await apiOp({ op: "import", state: legacy });
|
|
291
|
+
commit(mergeState(result.state), true);
|
|
292
|
+
} catch {}
|
|
293
|
+
},
|
|
294
|
+
async models() {
|
|
295
|
+
try {
|
|
296
|
+
const result = await request("/models");
|
|
297
|
+
return asArray(result.providers);
|
|
298
|
+
} catch {
|
|
299
|
+
return [];
|
|
300
|
+
}
|
|
301
|
+
},
|
|
128
302
|
};
|
|
129
303
|
})();
|
|
130
304
|
|
|
@@ -132,28 +306,9 @@ window.__ModuleLoader__.load({
|
|
|
132
306
|
return useSyncExternalStore(store.subscribe, store.get, store.get);
|
|
133
307
|
}
|
|
134
308
|
|
|
135
|
-
/*
|
|
136
|
-
*
|
|
137
|
-
* 处理过一次就记进 autoDone,之后你手动挪走也不会被拉回来。
|
|
138
|
-
* 想改规则:localStorage 里 dsh-session-groups.v1 的 autoRules 字段
|
|
139
|
-
* ([{ groupName, any: [关键词...], none: [排除词...] }]),留空用默认值。 */
|
|
140
|
-
const DEFAULT_AUTO_RULES = [
|
|
141
|
-
{ id: "r_brief", groupName: "每日简报", any: ["新闻简报", "每日简报"], schedules: ["新闻简报", "每日简报"] },
|
|
142
|
-
{ id: "r_radar", groupName: "个人开发工具", any: ["项目数据雷达", "数据雷达", "npm 与 GitHub 项目数据"], schedules: ["项目数据雷达", "数据雷达"] },
|
|
143
|
-
];
|
|
144
|
-
|
|
145
|
-
function matchAutoRule(rule, text) {
|
|
146
|
-
if (!rule || !text) return false;
|
|
147
|
-
const hay = String(text).toLowerCase();
|
|
148
|
-
const any = Array.isArray(rule.any) ? rule.any : [];
|
|
149
|
-
const none = Array.isArray(rule.none) ? rule.none : [];
|
|
150
|
-
if (none.some((k) => hay.includes(String(k).toLowerCase()))) return false;
|
|
151
|
-
return any.length === 0 || any.some((k) => hay.includes(String(k).toLowerCase()));
|
|
152
|
-
}
|
|
309
|
+
/* 分组判定(规则匹配、定时任务绑定、许可状态)全在宿主侧:客户端只
|
|
310
|
+
* 负责把那批会话/定时任务的快照送过去,并渲染宿主返回的待确认建议。 */
|
|
153
311
|
|
|
154
|
-
function newGroupId() {
|
|
155
|
-
return "g_" + Math.random().toString(36).slice(2, 9);
|
|
156
|
-
}
|
|
157
312
|
|
|
158
313
|
function titleOf(row, id) {
|
|
159
314
|
return String(row?.displayTitle || row?.title || id);
|
|
@@ -350,6 +505,365 @@ window.__ModuleLoader__.load({
|
|
|
350
505
|
return h(RegionBoundary, null, h(Region, props));
|
|
351
506
|
}
|
|
352
507
|
|
|
508
|
+
/* 许可条:自动分类永远先问人。四个选项就是产品约定:
|
|
509
|
+
* 是 / 否 / 始终允许该组别(以后同组不再问)/ 让我自己决定(手选)。 */
|
|
510
|
+
function ConsentBar(props) {
|
|
511
|
+
const { title, proposal, pendingCount, onAnswer, onPick } = props;
|
|
512
|
+
const reason = proposal.reason === "llm" ? "模型判断" : proposal.reason === "agent" ? "agent 建议" : "命中规则";
|
|
513
|
+
return h(
|
|
514
|
+
"div",
|
|
515
|
+
{ className: "dsg-consent", "data-dsg": "consent" },
|
|
516
|
+
h(
|
|
517
|
+
"div",
|
|
518
|
+
{ className: "dsg-consent-title" },
|
|
519
|
+
"「",
|
|
520
|
+
title,
|
|
521
|
+
"」建议归入 ",
|
|
522
|
+
h("span", { className: "dsg-consent-group" }, "「" + proposal.groupName + "」"),
|
|
523
|
+
h("span", { className: "dsg-consent-note" }, " · " + reason)
|
|
524
|
+
),
|
|
525
|
+
pendingCount > 1 ? h("div", { className: "dsg-consent-note" }, `另有 ${pendingCount - 1} 条待确认,先处理这一条`) : null,
|
|
526
|
+
h(
|
|
527
|
+
"div",
|
|
528
|
+
{ className: "dsg-consent-actions" },
|
|
529
|
+
h("button", { className: "dsg-btn", "data-tone": "primary", onClick: () => onAnswer("yes") }, "是"),
|
|
530
|
+
h("button", { className: "dsg-btn", onClick: () => onAnswer("no") }, "否"),
|
|
531
|
+
h("button", { className: "dsg-btn", onClick: () => onAnswer("always") }, "始终允许该组别"),
|
|
532
|
+
h("button", { className: "dsg-btn", "data-tone": "ghost", onClick: onPick }, "让我自己决定")
|
|
533
|
+
)
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/* Electron 没有 window.prompt,桌面端里它直接抛错——所以文本输入也必须自绘。 */
|
|
538
|
+
function TextDialog(props) {
|
|
539
|
+
const { state, onCancel } = props;
|
|
540
|
+
const [value, setValue] = useState(state.value || "");
|
|
541
|
+
const inputRef = useRef(null);
|
|
542
|
+
useEffect(() => {
|
|
543
|
+
const el = inputRef.current;
|
|
544
|
+
if (!el) return;
|
|
545
|
+
el.focus();
|
|
546
|
+
try {
|
|
547
|
+
el.select();
|
|
548
|
+
} catch {}
|
|
549
|
+
}, []);
|
|
550
|
+
const submit = () => {
|
|
551
|
+
const text = String(value || "").trim();
|
|
552
|
+
if (!text) return;
|
|
553
|
+
onCancel();
|
|
554
|
+
state.onOk(text);
|
|
555
|
+
};
|
|
556
|
+
return h(
|
|
557
|
+
"div",
|
|
558
|
+
{ className: "dsg-dialog-mask", onClick: onCancel },
|
|
559
|
+
h(
|
|
560
|
+
"div",
|
|
561
|
+
{ className: "dsg-panel", role: "dialog", "aria-label": state.title, onClick: (e) => e.stopPropagation() },
|
|
562
|
+
h("div", { className: "dsg-panel-title" }, state.title),
|
|
563
|
+
h("input", {
|
|
564
|
+
ref: inputRef,
|
|
565
|
+
className: "dsg-input",
|
|
566
|
+
value,
|
|
567
|
+
placeholder: state.placeholder,
|
|
568
|
+
onChange: (e) => setValue(e.target.value),
|
|
569
|
+
onKeyDown: (e) => {
|
|
570
|
+
if (e.key === "Enter") submit();
|
|
571
|
+
if (e.key === "Escape") onCancel();
|
|
572
|
+
},
|
|
573
|
+
}),
|
|
574
|
+
h(
|
|
575
|
+
"div",
|
|
576
|
+
{ className: "dsg-consent-actions" },
|
|
577
|
+
h("button", { className: "dsg-btn", "data-tone": "primary", onClick: submit }, "确定"),
|
|
578
|
+
h("button", { className: "dsg-btn", "data-tone": "ghost", onClick: onCancel }, "取消")
|
|
579
|
+
)
|
|
580
|
+
)
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function ConfirmDialog(props) {
|
|
585
|
+
const { state, onCancel } = props;
|
|
586
|
+
return h(
|
|
587
|
+
"div",
|
|
588
|
+
{ className: "dsg-dialog-mask", onClick: onCancel },
|
|
589
|
+
h(
|
|
590
|
+
"div",
|
|
591
|
+
{ className: "dsg-panel", role: "dialog", "aria-label": state.title, onClick: (e) => e.stopPropagation() },
|
|
592
|
+
h("div", { className: "dsg-panel-title" }, state.title),
|
|
593
|
+
h("div", { className: "dsg-consent-note" }, state.body),
|
|
594
|
+
h(
|
|
595
|
+
"div",
|
|
596
|
+
{ className: "dsg-consent-actions" },
|
|
597
|
+
h(
|
|
598
|
+
"button",
|
|
599
|
+
{
|
|
600
|
+
className: "dsg-btn",
|
|
601
|
+
"data-tone": "primary",
|
|
602
|
+
onClick: () => {
|
|
603
|
+
onCancel();
|
|
604
|
+
state.onOk();
|
|
605
|
+
},
|
|
606
|
+
},
|
|
607
|
+
"删除"
|
|
608
|
+
),
|
|
609
|
+
h("button", { className: "dsg-btn", "data-tone": "ghost", onClick: onCancel }, "取消")
|
|
610
|
+
)
|
|
611
|
+
)
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function GroupPickerPanel(props) {
|
|
616
|
+
const { title, groups, onPick, onNew, onCancel } = props;
|
|
617
|
+
return h(
|
|
618
|
+
"div",
|
|
619
|
+
{ className: "dsg-dialog-mask", onClick: onCancel },
|
|
620
|
+
h(
|
|
621
|
+
"div",
|
|
622
|
+
{ className: "dsg-panel", role: "dialog", "aria-label": "选择分组", onClick: (e) => e.stopPropagation() },
|
|
623
|
+
h("div", { className: "dsg-panel-title" }, "把「" + title + "」放到:"),
|
|
624
|
+
h(
|
|
625
|
+
"div",
|
|
626
|
+
{ className: "dsg-consent-actions", style: { flexDirection: "column", alignItems: "stretch" } },
|
|
627
|
+
groups.map((group) =>
|
|
628
|
+
h("button", { key: group.id, className: "dsg-btn", style: { textAlign: "left" }, onClick: () => onPick(group.id) }, group.name)),
|
|
629
|
+
h("button", { className: "dsg-btn", style: { textAlign: "left" }, onClick: () => onPick(null) }, "未分组"),
|
|
630
|
+
h("button", { className: "dsg-btn", "data-tone": "ghost", style: { textAlign: "left" }, onClick: onNew }, "+ 新建分组…")
|
|
631
|
+
),
|
|
632
|
+
h("div", { className: "dsg-consent-actions" },
|
|
633
|
+
h("button", { className: "dsg-btn", "data-tone": "ghost", onClick: onCancel }, "取消"))
|
|
634
|
+
)
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
/*
|
|
638
|
+
* 规则面板:定时任务可以按任务绑定(按 id,不再靠标题猜),关键词只是兜底。
|
|
639
|
+
* “始终允许”白名单也在这里撤销;状态文件路径直接显示,方便备份。
|
|
640
|
+
*/
|
|
641
|
+
function RulesPanel(props) {
|
|
642
|
+
const { groups, rules, schedules, autoAllow, classifier, statePath, online, onOp, onClose, loadModels } = props;
|
|
643
|
+
const [draft, setDraft] = useState({ id: "", groupName: "", keywords: "", scheduleIds: [] });
|
|
644
|
+
const [mode, setMode] = useState(classifier.mode);
|
|
645
|
+
const [provider, setProvider] = useState(classifier.provider);
|
|
646
|
+
const [model, setModel] = useState(classifier.model);
|
|
647
|
+
const [providers, setProviders] = useState([]);
|
|
648
|
+
|
|
649
|
+
useEffect(() => {
|
|
650
|
+
let alive = true;
|
|
651
|
+
void Promise.resolve(loadModels()).then((rows) => {
|
|
652
|
+
if (alive) setProviders(Array.isArray(rows) ? rows : []);
|
|
653
|
+
});
|
|
654
|
+
return () => {
|
|
655
|
+
alive = false;
|
|
656
|
+
};
|
|
657
|
+
}, [loadModels]);
|
|
658
|
+
|
|
659
|
+
const providerRow = providers.find((row) => row.id === provider);
|
|
660
|
+
const modelRows = providerRow ? providerRow.models || [] : [];
|
|
661
|
+
const scheduled = (schedules || []).filter((row) => row.id);
|
|
662
|
+
const canSaveRule = draft.groupName.trim().length > 0 && (draft.keywords.trim().length > 0 || draft.scheduleIds.length > 0);
|
|
663
|
+
|
|
664
|
+
const startEdit = (rule) =>
|
|
665
|
+
setDraft({
|
|
666
|
+
id: rule.id,
|
|
667
|
+
groupName: rule.groupName,
|
|
668
|
+
keywords: (rule.any || []).join(","),
|
|
669
|
+
scheduleIds: [...(rule.scheduleIds || [])],
|
|
670
|
+
});
|
|
671
|
+
const resetDraft = () => setDraft({ id: "", groupName: "", keywords: "", scheduleIds: [] });
|
|
672
|
+
const saveRule = () => {
|
|
673
|
+
if (!canSaveRule) return;
|
|
674
|
+
onOp({
|
|
675
|
+
op: "rule.upsert",
|
|
676
|
+
rule: {
|
|
677
|
+
id: draft.id,
|
|
678
|
+
groupName: draft.groupName.trim(),
|
|
679
|
+
any: draft.keywords.split(/[,,\n]/),
|
|
680
|
+
scheduleIds: draft.scheduleIds,
|
|
681
|
+
},
|
|
682
|
+
});
|
|
683
|
+
resetDraft();
|
|
684
|
+
};
|
|
685
|
+
const toggleSchedule = (id) =>
|
|
686
|
+
setDraft((current) => ({
|
|
687
|
+
...current,
|
|
688
|
+
scheduleIds: current.scheduleIds.includes(id)
|
|
689
|
+
? current.scheduleIds.filter((entry) => entry !== id)
|
|
690
|
+
: current.scheduleIds.concat([id]),
|
|
691
|
+
}));
|
|
692
|
+
|
|
693
|
+
return h(
|
|
694
|
+
"div",
|
|
695
|
+
{ className: "dsg-panel", role: "dialog", "aria-label": "自动归组设置", "data-dsg": "rules" },
|
|
696
|
+
h(
|
|
697
|
+
"div",
|
|
698
|
+
{ className: "dsg-panel-title" },
|
|
699
|
+
"自动归组",
|
|
700
|
+
h("span", { className: "dsg-spacer" }),
|
|
701
|
+
h("button", { className: "dsg-icon", title: "关闭", onClick: onClose }, "✕")
|
|
702
|
+
),
|
|
703
|
+
online
|
|
704
|
+
? null
|
|
705
|
+
: h("div", { className: "dsg-warn" }, "宿主端未连接:本次改动只进浏览器缓存,不会跨端同步。"),
|
|
706
|
+
|
|
707
|
+
h(
|
|
708
|
+
"div",
|
|
709
|
+
{ className: "dsg-field" },
|
|
710
|
+
h("div", { className: "dsg-field-label" }, "规则(定时任务绑定优先于关键词;命中后先问再归组)"),
|
|
711
|
+
rules.length === 0
|
|
712
|
+
? h("div", { className: "dsg-consent-note" }, "还没有规则。新会话就只能靠模型兜底或手动分组。")
|
|
713
|
+
: rules.map((rule) =>
|
|
714
|
+
h(
|
|
715
|
+
"div",
|
|
716
|
+
{ key: rule.id, className: "dsg-rule" },
|
|
717
|
+
h(
|
|
718
|
+
"div",
|
|
719
|
+
{ className: "dsg-rule-head" },
|
|
720
|
+
rule.groupName,
|
|
721
|
+
h(
|
|
722
|
+
"span",
|
|
723
|
+
{ className: "dsg-rule-actions" },
|
|
724
|
+
h("button", { className: "dsg-btn", style: { height: 22, fontSize: 11 }, onClick: () => startEdit(rule) }, "改"),
|
|
725
|
+
h("button", { className: "dsg-btn", style: { height: 22, fontSize: 11 }, onClick: () => onOp({ op: "rule.delete", ruleId: rule.id }) }, "删")
|
|
726
|
+
)
|
|
727
|
+
),
|
|
728
|
+
h(
|
|
729
|
+
"div",
|
|
730
|
+
{ className: "dsg-rule-meta" },
|
|
731
|
+
(rule.any || []).length ? "关键词:" + rule.any.join("、") : "无关键词",
|
|
732
|
+
(rule.scheduleIds || []).length
|
|
733
|
+
? " · 定时任务:" +
|
|
734
|
+
rule.scheduleIds
|
|
735
|
+
.map((id) => {
|
|
736
|
+
const found = scheduled.find((row) => row.id === id);
|
|
737
|
+
return found && found.title ? found.title : id;
|
|
738
|
+
})
|
|
739
|
+
.join("、")
|
|
740
|
+
: ""
|
|
741
|
+
)
|
|
742
|
+
)
|
|
743
|
+
)
|
|
744
|
+
),
|
|
745
|
+
|
|
746
|
+
h(
|
|
747
|
+
"div",
|
|
748
|
+
{ className: "dsg-field" },
|
|
749
|
+
h("div", { className: "dsg-field-label" }, draft.id ? "编辑规则" : "新增规则"),
|
|
750
|
+
h("input", {
|
|
751
|
+
className: "dsg-input",
|
|
752
|
+
list: "dsg-group-names",
|
|
753
|
+
value: draft.groupName,
|
|
754
|
+
placeholder: "分组名(可选已有或新建)",
|
|
755
|
+
onChange: (e) => setDraft({ ...draft, groupName: e.target.value }),
|
|
756
|
+
}),
|
|
757
|
+
h("datalist", { id: "dsg-group-names" }, groups.map((group) => h("option", { key: group.id, value: group.name }))),
|
|
758
|
+
h("input", {
|
|
759
|
+
className: "dsg-input",
|
|
760
|
+
value: draft.keywords,
|
|
761
|
+
placeholder: "关键词,逗号分隔(可留空)",
|
|
762
|
+
onChange: (e) => setDraft({ ...draft, keywords: e.target.value }),
|
|
763
|
+
}),
|
|
764
|
+
scheduled.length
|
|
765
|
+
? h(
|
|
766
|
+
"div",
|
|
767
|
+
{ style: { display: "flex", flexDirection: "column", gap: 2, maxHeight: 132, overflow: "auto" } },
|
|
768
|
+
scheduled.map((row) =>
|
|
769
|
+
h(
|
|
770
|
+
"label",
|
|
771
|
+
{ key: row.id, className: "dsg-sched" },
|
|
772
|
+
h("input", {
|
|
773
|
+
type: "checkbox",
|
|
774
|
+
checked: draft.scheduleIds.includes(row.id),
|
|
775
|
+
onChange: () => toggleSchedule(row.id),
|
|
776
|
+
}),
|
|
777
|
+
row.title || row.id
|
|
778
|
+
)
|
|
779
|
+
)
|
|
780
|
+
)
|
|
781
|
+
: null,
|
|
782
|
+
h(
|
|
783
|
+
"div",
|
|
784
|
+
{ className: "dsg-consent-actions" },
|
|
785
|
+
h("button", { className: "dsg-btn", "data-tone": "primary", disabled: !canSaveRule, onClick: saveRule }, draft.id ? "保存修改" : "添加规则"),
|
|
786
|
+
draft.id ? h("button", { className: "dsg-btn", "data-tone": "ghost", onClick: resetDraft }, "取消编辑") : null
|
|
787
|
+
)
|
|
788
|
+
),
|
|
789
|
+
|
|
790
|
+
h(
|
|
791
|
+
"div",
|
|
792
|
+
{ className: "dsg-field" },
|
|
793
|
+
h("div", { className: "dsg-field-label" }, "规则没命中时让模型判断(默认关,每次最多 3 个新会话)"),
|
|
794
|
+
h(
|
|
795
|
+
"div",
|
|
796
|
+
{ className: "dsg-consent-actions" },
|
|
797
|
+
h("button", { className: "dsg-btn", "data-tone": mode === "off" ? "primary" : undefined, onClick: () => setMode("off") }, "关闭"),
|
|
798
|
+
h("button", { className: "dsg-btn", "data-tone": mode === "llm" ? "primary" : undefined, onClick: () => setMode("llm") }, "模型判断")
|
|
799
|
+
),
|
|
800
|
+
mode === "llm"
|
|
801
|
+
? h(
|
|
802
|
+
React.Fragment,
|
|
803
|
+
null,
|
|
804
|
+
h(
|
|
805
|
+
"select",
|
|
806
|
+
{
|
|
807
|
+
className: "dsg-select",
|
|
808
|
+
value: provider,
|
|
809
|
+
onChange: (e) => {
|
|
810
|
+
setProvider(e.target.value);
|
|
811
|
+
setModel("");
|
|
812
|
+
},
|
|
813
|
+
},
|
|
814
|
+
h("option", { value: "" }, "选择提供方"),
|
|
815
|
+
providers.map((row) => h("option", { key: row.id, value: row.id }, row.name || row.id))
|
|
816
|
+
),
|
|
817
|
+
h(
|
|
818
|
+
"select",
|
|
819
|
+
{ className: "dsg-select", value: model, onChange: (e) => setModel(e.target.value) },
|
|
820
|
+
h("option", { value: "" }, "选择模型"),
|
|
821
|
+
modelRows.map((row) => h("option", { key: row.id, value: row.id }, row.name || row.id))
|
|
822
|
+
)
|
|
823
|
+
)
|
|
824
|
+
: null,
|
|
825
|
+
h(
|
|
826
|
+
"div",
|
|
827
|
+
{ className: "dsg-consent-actions" },
|
|
828
|
+
h(
|
|
829
|
+
"button",
|
|
830
|
+
{
|
|
831
|
+
className: "dsg-btn",
|
|
832
|
+
"data-tone": "primary",
|
|
833
|
+
disabled: mode === "llm" && (!provider || !model),
|
|
834
|
+
onClick: () => onOp({ op: "setting", classifier: { mode, provider, model } }),
|
|
835
|
+
},
|
|
836
|
+
"保存分类方式"
|
|
837
|
+
)
|
|
838
|
+
)
|
|
839
|
+
),
|
|
840
|
+
|
|
841
|
+
h(
|
|
842
|
+
"div",
|
|
843
|
+
{ className: "dsg-field" },
|
|
844
|
+
h("div", { className: "dsg-field-label" }, "始终允许(不再询问)的组别"),
|
|
845
|
+
Object.keys(autoAllow).length === 0
|
|
846
|
+
? h("div", { className: "dsg-consent-note" }, "暂无。在许可条上点「始终允许该组别」就会加进来。")
|
|
847
|
+
: h(
|
|
848
|
+
"div",
|
|
849
|
+
{ className: "dsg-consent-actions" },
|
|
850
|
+
Object.keys(autoAllow).map((groupId) => {
|
|
851
|
+
const group = groups.find((entry) => entry.id === groupId);
|
|
852
|
+
if (!group) return null;
|
|
853
|
+
return h(
|
|
854
|
+
"button",
|
|
855
|
+
{ key: groupId, className: "dsg-btn", title: "撤销,恢复逐次询问", onClick: () => onOp({ op: "autoAllow.revoke", groupId }) },
|
|
856
|
+
group.name + " ×"
|
|
857
|
+
);
|
|
858
|
+
})
|
|
859
|
+
)
|
|
860
|
+
),
|
|
861
|
+
|
|
862
|
+
h("div", { className: "dsg-consent-note" }, "状态文件:" + (statePath || "(未连接)"))
|
|
863
|
+
);
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
|
|
353
867
|
function Region(props) {
|
|
354
868
|
const {
|
|
355
869
|
useSessions, useWorkspaces, useSessionStatus, useScheduleCatalog, open,
|
|
@@ -421,57 +935,66 @@ window.__ModuleLoader__.load({
|
|
|
421
935
|
const assign = groups.assign || {};
|
|
422
936
|
const collapsed = groups.collapsed || {};
|
|
423
937
|
const orders = groups.order || {};
|
|
424
|
-
const hidden =
|
|
938
|
+
const hidden = groups.hiddenWorkspaces || [];
|
|
425
939
|
|
|
426
940
|
const ids = useMemo(() => (list?.ids || []).filter((id) => byId[id] && !isSubagent(byId[id])), [list, byId]);
|
|
427
941
|
const archived = useMemo(() => ids.filter((id) => archivedSet.has(id)), [ids, archivedSet]);
|
|
428
942
|
const live = useMemo(() => ids.filter((id) => !archivedSet.has(id)), [ids, archivedSet]);
|
|
429
943
|
|
|
430
|
-
/*
|
|
944
|
+
/* 会话/定时任务快照交给宿主。判定、许可状态与落盘都在宿主侧,
|
|
945
|
+
* 客户端只报数并渲染返回的待确认建议。 */
|
|
946
|
+
const scheduleDigest = useMemo(
|
|
947
|
+
() =>
|
|
948
|
+
(Array.isArray(schedules) ? schedules : []).map((row) => ({
|
|
949
|
+
/* 目录行有两种形状:存储里的 {record, target, lastDelivery}
|
|
950
|
+
* 与客户端目录拍扁后的同名行,两种都认。 */
|
|
951
|
+
id: String((row && ((row.record && row.record.id) || row.id)) || ""),
|
|
952
|
+
title: String((row && ((row.record && row.record.title) || row.title)) || ""),
|
|
953
|
+
targetSessionId: String((row && row.lastDelivery && row.lastDelivery.targetSessionId) || ""),
|
|
954
|
+
deliveredAt: String((row && row.lastDelivery && row.lastDelivery.deliveredAt) || ""),
|
|
955
|
+
})),
|
|
956
|
+
[schedules]
|
|
957
|
+
);
|
|
958
|
+
const sessionDigest = useMemo(
|
|
959
|
+
() =>
|
|
960
|
+
live.map((id) => ({
|
|
961
|
+
id,
|
|
962
|
+
title: titleOf(byId[id], id),
|
|
963
|
+
createdAt: Number(byId[id] && byId[id].createdAt) || undefined,
|
|
964
|
+
updatedAt: Number(byId[id] && byId[id].updatedAt) || undefined,
|
|
965
|
+
})),
|
|
966
|
+
[live, byId]
|
|
967
|
+
);
|
|
968
|
+
|
|
431
969
|
useEffect(() => {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (!rule) rule = rules.find((r) => matchAutoRule(r, sessionText));
|
|
461
|
-
if (!rule) continue;
|
|
462
|
-
const name = String(rule.groupName || "").trim();
|
|
463
|
-
if (!name) continue;
|
|
464
|
-
let g = groupsNext.find((x) => x.name === name);
|
|
465
|
-
if (!g) {
|
|
466
|
-
g = { id: newGroupId(), name: name.slice(0, 20) };
|
|
467
|
-
groupsNext.push(g);
|
|
468
|
-
}
|
|
469
|
-
assignNext[id] = g.id;
|
|
470
|
-
doneNext[id] = 1;
|
|
471
|
-
changed = true;
|
|
472
|
-
}
|
|
473
|
-
if (changed) store.set({ ...cur, groups: groupsNext, assign: assignNext, autoDone: doneNext });
|
|
474
|
-
}, [live, byId, schedules]);
|
|
970
|
+
void (async () => {
|
|
971
|
+
const reachable = await store.load();
|
|
972
|
+
if (!reachable) return;
|
|
973
|
+
await store.importLegacy();
|
|
974
|
+
await store.sync(sessionDigest, scheduleDigest);
|
|
975
|
+
})();
|
|
976
|
+
// 只在挂载时跑一次;后续靠下面的 digest 变化与轮询。
|
|
977
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
978
|
+
}, []);
|
|
979
|
+
|
|
980
|
+
useEffect(() => {
|
|
981
|
+
if (sessionDigest.length === 0 && scheduleDigest.length === 0) return undefined;
|
|
982
|
+
const timer = setTimeout(() => {
|
|
983
|
+
void store.sync(sessionDigest, scheduleDigest);
|
|
984
|
+
}, 400);
|
|
985
|
+
return () => clearTimeout(timer);
|
|
986
|
+
}, [sessionDigest, scheduleDigest]);
|
|
987
|
+
|
|
988
|
+
/* 另一扇窗、或桌面端刚 accept 过许可时让本窗跟上;页面隐藏时不跑。 */
|
|
989
|
+
useEffect(() => {
|
|
990
|
+
const timer = setInterval(() => {
|
|
991
|
+
try {
|
|
992
|
+
if (document.visibilityState === "hidden") return;
|
|
993
|
+
} catch {}
|
|
994
|
+
void store.load();
|
|
995
|
+
}, 20000);
|
|
996
|
+
return () => clearInterval(timer);
|
|
997
|
+
}, []);
|
|
475
998
|
const archivedOrdered = useMemo(() => applyManualOrder(archived, orders["archived"]), [archived, orders]);
|
|
476
999
|
const liveSorted = useMemo(() => sortRecent(live, byId), [live, byId]);
|
|
477
1000
|
const recentBase = useMemo(() => liveSorted.slice(0, recentLimit), [liveSorted, recentLimit]);
|
|
@@ -542,7 +1065,9 @@ window.__ModuleLoader__.load({
|
|
|
542
1065
|
if (Array.isArray(saved) && saved.length > 0) {
|
|
543
1066
|
const seen = new Set(saved);
|
|
544
1067
|
const revealed = liveSortedRef.current.slice(limit, next).filter((id) => !seen.has(id));
|
|
545
|
-
if (revealed.length > 0)
|
|
1068
|
+
if (revealed.length > 0) {
|
|
1069
|
+
void store.op({ op: "order.set", key: "recent", ids: saved.concat(revealed) }).catch(() => {});
|
|
1070
|
+
}
|
|
546
1071
|
}
|
|
547
1072
|
setRecentLimit(next);
|
|
548
1073
|
}, 140);
|
|
@@ -618,65 +1143,56 @@ window.__ModuleLoader__.load({
|
|
|
618
1143
|
return visibleWorkspaces[0]?.workspaceId;
|
|
619
1144
|
}, [groups.activeWorkspace, recent, ws, visibleWorkspaces]);
|
|
620
1145
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
store.
|
|
1146
|
+
/* 所有写操作都发给宿主:宿主是唯一写入方,返回的整份状态直接替换本地。 */
|
|
1147
|
+
const op = useCallback((payload) => {
|
|
1148
|
+
void store.op(payload).catch((err) => console.error("[dsh-sidebar-sessions] op failed", err));
|
|
624
1149
|
}, []);
|
|
625
1150
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
1151
|
+
/* 自绘输入/确认框:Electron 不实现 window.prompt,桌面端里它直接抛错,
|
|
1152
|
+
* 以前新建分组、重命名分组、重命名对话在桌面端全是静的。 */
|
|
1153
|
+
const [promptState, setPromptState] = useState(null);
|
|
1154
|
+
const [confirmState, setConfirmState] = useState(null);
|
|
1155
|
+
const [rulesOpen, setRulesOpen] = useState(false);
|
|
1156
|
+
const [picker, setPicker] = useState(null);
|
|
1157
|
+
|
|
1158
|
+
const askText = useCallback((title, value, placeholder, onOk) => {
|
|
1159
|
+
setPromptState({ title, value: value || "", placeholder: placeholder || "", onOk });
|
|
632
1160
|
}, []);
|
|
1161
|
+
const askConfirm = useCallback((title, body, onOk) => setConfirmState({ title, body: body || "", onOk }), []);
|
|
1162
|
+
|
|
1163
|
+
const toggle = useCallback((key) => op({ op: "collapsed", key, value: !(collapsed || {})[key] }), [collapsed, op]);
|
|
1164
|
+
const assignTo = useCallback((id, gid) => op({ op: "assign", sessionId: id, groupId: gid || null }), [op]);
|
|
1165
|
+
const consent = useCallback((sessionId, choice) => op({ op: "consent", sessionId, choice }), [op]);
|
|
633
1166
|
|
|
634
1167
|
const createGroup = useCallback((sessionId) => {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
const g = { id: newGroupId(), name: name.trim().slice(0, 20) };
|
|
638
|
-
const cur = store.get();
|
|
639
|
-
const next = { ...cur, groups: [...cur.groups, g] };
|
|
640
|
-
if (sessionId) next.assign = { ...cur.assign, [sessionId]: g.id };
|
|
641
|
-
store.set(next);
|
|
642
|
-
}, []);
|
|
1168
|
+
askText("新建分组", "", "分组名称", (name) => op({ op: "group.create", name, sessionId }));
|
|
1169
|
+
}, [askText, op]);
|
|
643
1170
|
|
|
644
1171
|
const renameGroup = useCallback((g) => {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const cur = store.get();
|
|
648
|
-
store.set({ ...cur, groups: cur.groups.map((x) => (x.id === g.id ? { ...x, name: name.trim().slice(0, 20) } : x)) });
|
|
649
|
-
}, []);
|
|
1172
|
+
askText("重命名分组", g.name, "分组名称", (name) => op({ op: "group.rename", groupId: g.id, name }));
|
|
1173
|
+
}, [askText, op]);
|
|
650
1174
|
|
|
651
1175
|
const deleteGroup = useCallback((g) => {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
for (const [sid, gid] of Object.entries(nextAssign)) if (gid === g.id) delete nextAssign[sid];
|
|
656
|
-
store.set({ ...cur, groups: cur.groups.filter((x) => x.id !== g.id), assign: nextAssign });
|
|
657
|
-
}, []);
|
|
1176
|
+
askConfirm(`删除分组「${g.name}」`, "组内会话会回到未分组,绑定该组的规则也会一起删掉。", () =>
|
|
1177
|
+
op({ op: "group.delete", groupId: g.id }));
|
|
1178
|
+
}, [askConfirm, op]);
|
|
658
1179
|
|
|
659
1180
|
const switchWorkspace = useCallback((item) => {
|
|
660
|
-
|
|
661
|
-
store.set({ ...cur, activeWorkspace: String(item.workspaceId) });
|
|
1181
|
+
op({ op: "workspace.active", id: String(item.workspaceId) });
|
|
662
1182
|
try {
|
|
663
1183
|
if (openWorkspace) Promise.resolve(openWorkspace(item.workspaceId)).catch((err) => console.error("[dsh-sidebar-sessions] switch workspace failed", err));
|
|
664
1184
|
} catch (err) {
|
|
665
1185
|
console.error("[dsh-sidebar-sessions] switch workspace failed", err);
|
|
666
1186
|
}
|
|
667
|
-
}, [openWorkspace]);
|
|
1187
|
+
}, [openWorkspace, op]);
|
|
668
1188
|
|
|
669
1189
|
const hideWorkspace = useCallback((item) => {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
store.set({ ...cur, hiddenWorkspaces: [...new Set([...(cur.hiddenWorkspaces || []), id])] });
|
|
673
|
-
}, []);
|
|
1190
|
+
op({ op: "workspaces.hidden", ids: [...new Set([...(hidden || []), String(item.workspaceId)])] });
|
|
1191
|
+
}, [hidden, op]);
|
|
674
1192
|
|
|
675
1193
|
const unhideWorkspace = useCallback((item) => {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
store.set({ ...cur, hiddenWorkspaces: (cur.hiddenWorkspaces || []).filter((x) => x !== id) });
|
|
679
|
-
}, []);
|
|
1194
|
+
op({ op: "workspaces.hidden", ids: (hidden || []).filter((id) => id !== String(item.workspaceId)) });
|
|
1195
|
+
}, [hidden, op]);
|
|
680
1196
|
|
|
681
1197
|
const closeMenu = useCallback(() => setMenu(null), []);
|
|
682
1198
|
const openMenu = useCallback((id, el) => {
|
|
@@ -684,15 +1200,16 @@ window.__ModuleLoader__.load({
|
|
|
684
1200
|
setMenu({ id, x: Math.min(r.right - 190, Math.max(8, window.innerWidth - 210)), y: Math.min(r.bottom + 2, window.innerHeight - 280) });
|
|
685
1201
|
}, []);
|
|
686
1202
|
|
|
687
|
-
const renameRow = useCallback(
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
1203
|
+
const renameRow = useCallback((id) => {
|
|
1204
|
+
askText("重命名对话", titleOf(byId[id], id), "对话标题", async (name) => {
|
|
1205
|
+
if (!renameSession) return;
|
|
1206
|
+
try {
|
|
1207
|
+
await renameSession(id, name);
|
|
1208
|
+
} catch (err) {
|
|
1209
|
+
console.error("[dsh-sidebar-sessions] rename failed", err);
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1212
|
+
}, [askText, byId, renameSession]);
|
|
696
1213
|
|
|
697
1214
|
const copy = useCallback((text) => {
|
|
698
1215
|
try {
|
|
@@ -702,17 +1219,10 @@ window.__ModuleLoader__.load({
|
|
|
702
1219
|
|
|
703
1220
|
const commitSectionOrder = useCallback((sectionKey, next) => {
|
|
704
1221
|
if (!next || sectionKey === "search") return;
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}, []);
|
|
1222
|
+
op({ op: "order.set", key: sectionKey, ids: next });
|
|
1223
|
+
}, [op]);
|
|
708
1224
|
|
|
709
|
-
const clearSectionOrder = useCallback((sectionKey) => {
|
|
710
|
-
const cur = store.get();
|
|
711
|
-
const order = { ...(cur.order || {}) };
|
|
712
|
-
if (!(sectionKey in order)) return;
|
|
713
|
-
delete order[sectionKey];
|
|
714
|
-
store.set({ ...cur, order });
|
|
715
|
-
}, []);
|
|
1225
|
+
const clearSectionOrder = useCallback((sectionKey) => op({ op: "order.clear", key: sectionKey }), [op]);
|
|
716
1226
|
|
|
717
1227
|
const handleDragOver = useCallback((section, id, half) => {
|
|
718
1228
|
if (!id) {
|
|
@@ -865,6 +1375,13 @@ window.__ModuleLoader__.load({
|
|
|
865
1375
|
}
|
|
866
1376
|
return null;
|
|
867
1377
|
})();
|
|
1378
|
+
/* 待确认建议:一次只问一条,其余条数在许可条里提示。 */
|
|
1379
|
+
const loadModels = useCallback(() => store.models(), []);
|
|
1380
|
+
const statePath = store.meta().statePath || "";
|
|
1381
|
+
const consentEntries = Object.entries(groups.pending || {}).filter(([id]) => byId[id]);
|
|
1382
|
+
const consentEntry = consentEntries[0];
|
|
1383
|
+
const consentTitle = consentEntry ? titleOf(byId[consentEntry[0]], consentEntry[0]) : "";
|
|
1384
|
+
|
|
868
1385
|
const menuEl = menu
|
|
869
1386
|
? h(
|
|
870
1387
|
"div",
|
|
@@ -883,6 +1400,28 @@ window.__ModuleLoader__.load({
|
|
|
883
1400
|
h("span", { className: "dsg-dot-sm" }, "●"), g.name)
|
|
884
1401
|
),
|
|
885
1402
|
h("div", { className: "dsg-menu-item", onClick: () => { createGroup(menu.id); closeMenu(); } }, "+ 新建分组…"),
|
|
1403
|
+
(() => {
|
|
1404
|
+
const current = groups.groups.find((g) => g.id === assign[menu.id]);
|
|
1405
|
+
if (!current) return null;
|
|
1406
|
+
const via = (Array.isArray(schedules) ? schedules : []).find(
|
|
1407
|
+
(row) => row && row.lastDelivery && row.lastDelivery.targetSessionId === menu.id
|
|
1408
|
+
);
|
|
1409
|
+
const viaId = via ? (via.record && via.record.id) || via.id : undefined;
|
|
1410
|
+
if (!viaId) return null;
|
|
1411
|
+
const scheduleId = String(viaId);
|
|
1412
|
+
return h(
|
|
1413
|
+
"div",
|
|
1414
|
+
{
|
|
1415
|
+
className: "dsg-menu-item",
|
|
1416
|
+
title: "为这个定时任务建规则:以后它新建的会话直接进这个组",
|
|
1417
|
+
onClick: () => {
|
|
1418
|
+
op({ op: "rule.upsert", rule: { groupName: current.name, scheduleIds: [scheduleId] } });
|
|
1419
|
+
closeMenu();
|
|
1420
|
+
},
|
|
1421
|
+
},
|
|
1422
|
+
"记住:该定时任务归这里"
|
|
1423
|
+
);
|
|
1424
|
+
})(),
|
|
886
1425
|
h("div", { className: "dsg-menu-sep" }),
|
|
887
1426
|
h("div", { className: "dsg-menu-item", onClick: () => { archivedSet.has(menu.id) ? unarchiveSession(menu.id) : archiveSession(menu.id); closeMenu(); } },
|
|
888
1427
|
archivedSet.has(menu.id) ? "取消归档" : "归档")
|
|
@@ -914,6 +1453,31 @@ window.__ModuleLoader__.load({
|
|
|
914
1453
|
console.error("[dsh-sidebar-sessions] create workspace failed", err);
|
|
915
1454
|
}
|
|
916
1455
|
} }, "+ 新建工作区")),
|
|
1456
|
+
h("div", { className: "dsg-consent-actions", style: { margin: "0 2px 6px" } },
|
|
1457
|
+
h(
|
|
1458
|
+
"button",
|
|
1459
|
+
{
|
|
1460
|
+
className: "dsg-btn",
|
|
1461
|
+
"data-tone": "ghost",
|
|
1462
|
+
style: { height: 24, fontSize: 11, padding: "0 8px" },
|
|
1463
|
+
title: "自动归组规则 / 模型分类 / 始终允许白名单",
|
|
1464
|
+
onClick: () => setRulesOpen(true),
|
|
1465
|
+
},
|
|
1466
|
+
"⚙ 自动归组" + (groups.rules.length ? `(${groups.rules.length})` : "")
|
|
1467
|
+
),
|
|
1468
|
+
groups.online ? null : h("span", { className: "dsg-consent-note" }, "宿主未连接")),
|
|
1469
|
+
consentEntry
|
|
1470
|
+
? h(ConsentBar, {
|
|
1471
|
+
title: consentTitle,
|
|
1472
|
+
proposal: consentEntry[1],
|
|
1473
|
+
pendingCount: consentEntries.length,
|
|
1474
|
+
onAnswer: (choice) => consent(consentEntry[0], choice),
|
|
1475
|
+
onPick: () => {
|
|
1476
|
+
setPicker({ sessionId: consentEntry[0], title: consentTitle });
|
|
1477
|
+
consent(consentEntry[0], "later");
|
|
1478
|
+
},
|
|
1479
|
+
})
|
|
1480
|
+
: null,
|
|
917
1481
|
h("div", { className: "dsg-search" },
|
|
918
1482
|
h("input", {
|
|
919
1483
|
value: query,
|
|
@@ -985,6 +1549,38 @@ window.__ModuleLoader__.load({
|
|
|
985
1549
|
: null)
|
|
986
1550
|
: null),
|
|
987
1551
|
),
|
|
1552
|
+
rulesOpen
|
|
1553
|
+
? h(RulesPanel, {
|
|
1554
|
+
groups: groups.groups,
|
|
1555
|
+
rules: groups.rules,
|
|
1556
|
+
schedules: scheduleDigest,
|
|
1557
|
+
autoAllow: groups.autoAllow,
|
|
1558
|
+
classifier: groups.settings.classifier,
|
|
1559
|
+
statePath: statePath,
|
|
1560
|
+
online: groups.online,
|
|
1561
|
+
onOp: op,
|
|
1562
|
+
onClose: () => setRulesOpen(false),
|
|
1563
|
+
loadModels: loadModels,
|
|
1564
|
+
})
|
|
1565
|
+
: null,
|
|
1566
|
+
picker
|
|
1567
|
+
? h(GroupPickerPanel, {
|
|
1568
|
+
title: picker.title,
|
|
1569
|
+
groups: groups.groups,
|
|
1570
|
+
onPick: (gid) => {
|
|
1571
|
+
assignTo(picker.sessionId, gid);
|
|
1572
|
+
setPicker(null);
|
|
1573
|
+
},
|
|
1574
|
+
onNew: () => {
|
|
1575
|
+
const sessionId = picker.sessionId;
|
|
1576
|
+
setPicker(null);
|
|
1577
|
+
createGroup(sessionId);
|
|
1578
|
+
},
|
|
1579
|
+
onCancel: () => setPicker(null),
|
|
1580
|
+
})
|
|
1581
|
+
: null,
|
|
1582
|
+
promptState ? h(TextDialog, { key: "prompt", state: promptState, onCancel: () => setPromptState(null) }) : null,
|
|
1583
|
+
confirmState ? h(ConfirmDialog, { key: "confirm", state: confirmState, onCancel: () => setConfirmState(null) }) : null,
|
|
988
1584
|
menuEl
|
|
989
1585
|
);
|
|
990
1586
|
}
|