openclacky 1.5.3 → 1.5.4
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.
- checksums.yaml +4 -4
- data/.dockerignore +13 -0
- data/CHANGELOG.md +26 -0
- data/Dockerfile +21 -1
- data/README.md +26 -7
- data/README_CN.md +26 -7
- data/README_JA.md +26 -7
- data/lib/clacky/agent/message_compressor.rb +4 -29
- data/lib/clacky/agent/message_compressor_helper.rb +13 -15
- data/lib/clacky/agent/session_serializer.rb +6 -0
- data/lib/clacky/agent.rb +13 -1
- data/lib/clacky/agent_config.rb +6 -3
- data/lib/clacky/brand_config.rb +32 -12
- data/lib/clacky/default_extensions/ext-studio/agents/ext-developer/system_prompt.md +15 -0
- data/lib/clacky/default_extensions/ext-studio/api/handler.rb +1 -5
- data/lib/clacky/default_extensions/ext-studio/panels/studio/view.js +1 -1
- data/lib/clacky/default_extensions/ext-studio/skills/ext-develop/SKILL.md +5 -1
- data/lib/clacky/default_parsers/xlsx_parser.py +66 -0
- data/lib/clacky/extension/api_extension.rb +3 -2
- data/lib/clacky/message_format/open_ai.rb +26 -3
- data/lib/clacky/providers.rb +16 -8
- data/lib/clacky/server/http_server.rb +341 -24
- data/lib/clacky/server/project_manager.rb +150 -0
- data/lib/clacky/server/server_master.rb +7 -0
- data/lib/clacky/server/session_registry.rb +14 -1
- data/lib/clacky/session_manager.rb +5 -4
- data/lib/clacky/tools/file_reader.rb +2 -1
- data/lib/clacky/utils/model_pricing.rb +69 -18
- data/lib/clacky/utils/parser_manager.rb +115 -7
- data/lib/clacky/version.rb +1 -1
- data/lib/clacky/web/app.css +903 -135
- data/lib/clacky/web/app.js +11 -2
- data/lib/clacky/web/components/notify.js +139 -22
- data/lib/clacky/web/core/aside.js +21 -0
- data/lib/clacky/web/features/brand/store.js +3 -1
- data/lib/clacky/web/features/brand/view.js +29 -5
- data/lib/clacky/web/features/new-session/view.js +2 -2
- data/lib/clacky/web/features/trash/store.js +23 -9
- data/lib/clacky/web/features/trash/view.js +51 -0
- data/lib/clacky/web/i18n.js +95 -4
- data/lib/clacky/web/index.html +69 -15
- data/lib/clacky/web/projects.js +1143 -0
- data/lib/clacky/web/sessions.js +318 -537
- data/lib/clacky/web/settings.js +138 -5
- data/lib/clacky/web/ws-dispatcher.js +59 -1
- data/scripts/build/src/install_system_deps.sh.cc +11 -3
- data/scripts/install_system_deps.sh +11 -3
- metadata +5 -2
- data/lib/clacky/default_parsers/xlsx_parser.rb +0 -121
data/lib/clacky/web/app.js
CHANGED
|
@@ -506,11 +506,20 @@ const Modal = (() => {
|
|
|
506
506
|
});
|
|
507
507
|
}
|
|
508
508
|
|
|
509
|
-
/** Show a rename dialog. Returns a Promise<string|null>.
|
|
510
|
-
|
|
509
|
+
/** Show a rename dialog. Returns a Promise<string|null>.
|
|
510
|
+
* @param {string} currentName - pre-filled value
|
|
511
|
+
* @param {string} [labelI18nKey] - i18n key for the field label (default: sessions.modal.name)
|
|
512
|
+
*/
|
|
513
|
+
function rename(currentName = "", labelI18nKey = "sessions.modal.name") {
|
|
511
514
|
return new Promise(resolve => {
|
|
512
515
|
const overlay = $("rename-modal-overlay");
|
|
513
516
|
const input = $("rename-modal-input");
|
|
517
|
+
// Update label text dynamically
|
|
518
|
+
const labelSpan = overlay.querySelector("label[for='rename-modal-input'] span[data-i18n]");
|
|
519
|
+
if (labelSpan) {
|
|
520
|
+
labelSpan.dataset.i18n = labelI18nKey;
|
|
521
|
+
labelSpan.textContent = I18n.t(labelI18nKey);
|
|
522
|
+
}
|
|
514
523
|
input.value = currentName;
|
|
515
524
|
input.classList.remove("input-error");
|
|
516
525
|
// Re-attach to <body> end so it stacks above dynamically-appended overlays.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
// notify.js — Task-complete sound notification module
|
|
1
|
+
// notify.js — Task-complete sound + desktop notification module
|
|
2
2
|
//
|
|
3
|
-
// Plays a short sound when
|
|
4
|
-
//
|
|
5
|
-
// task completes. We listen to
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
3
|
+
// Plays a short sound and (when permitted) shows a browser Notification when
|
|
4
|
+
// an agent task finishes, driven by the global `task_finished` event the
|
|
5
|
+
// server broadcasts (broadcast_all) the moment a task completes. We listen to
|
|
6
|
+
// this dedicated signal — rather than `complete` (only delivered to subscribers
|
|
7
|
+
// of that session) — so a background session finishing still reaches every
|
|
8
|
+
// browser. Whether a task *finished* is decided on the backend; this module
|
|
9
|
+
// only decides whether the user is looking.
|
|
9
10
|
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
11
|
+
// Alerts only fire when the user is NOT actively looking at the finished
|
|
12
|
+
// session. "Not looking" means ANY of:
|
|
12
13
|
// 1. The finished session is not the currently open one
|
|
13
14
|
// (sid !== Sessions.activeId)
|
|
14
15
|
// 2. The browser window has lost focus (!document.hasFocus())
|
|
@@ -18,15 +19,20 @@
|
|
|
18
19
|
// silent — they can already see the result.
|
|
19
20
|
//
|
|
20
21
|
// The feature is gated behind a header toggle (🔔/🔕) next to the theme
|
|
21
|
-
// switcher. Default OFF; the choice is persisted to localStorage.
|
|
22
|
+
// switcher. Default OFF; the choice is persisted to localStorage. Enabling
|
|
23
|
+
// the toggle also requests browser Notification permission (must happen in
|
|
24
|
+
// the click gesture) so desktop toasts work when the tab is in the background.
|
|
22
25
|
//
|
|
23
|
-
// No history replay: a chime is a live cue, never re-fired on page
|
|
24
|
-
// The audio file is served as a static asset (/notify.mp3)
|
|
26
|
+
// No history replay: a chime/toast is a live cue, never re-fired on page
|
|
27
|
+
// refresh. The audio file is served as a static asset (/assets/notify.mp3).
|
|
25
28
|
//
|
|
26
|
-
// Depends on: Sessions (sessions.js) for activeId,
|
|
27
|
-
//
|
|
29
|
+
// Depends on: Sessions (sessions.js) for activeId/find, Router (app.js) for
|
|
30
|
+
// focus-on-click navigation, I18n (i18n.js) for tooltip text.
|
|
31
|
+
// All are optional — guarded with typeof checks.
|
|
28
32
|
// ─────────────────────────────────────────────────────────────────────────
|
|
29
33
|
const Notify = (() => {
|
|
34
|
+
// Historical key name kept for existing installs; value now means
|
|
35
|
+
// "task alerts" (sound + desktop when permitted), not sound-only.
|
|
30
36
|
const STORAGE_KEY = "clacky-notify-sound";
|
|
31
37
|
const AUDIO_SRC = "/assets/notify.mp3";
|
|
32
38
|
|
|
@@ -41,13 +47,54 @@ const Notify = (() => {
|
|
|
41
47
|
function setEnabled(on) {
|
|
42
48
|
localStorage.setItem(STORAGE_KEY, on ? "on" : "off");
|
|
43
49
|
_updateToggleIcon();
|
|
44
|
-
// On enabling, "prime" the audio element within this user gesture so the
|
|
45
|
-
// browser's autoplay policy lets later programmatic play() calls through.
|
|
46
|
-
if (on) _prime();
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
function toggle() {
|
|
50
|
-
|
|
52
|
+
async function toggle() {
|
|
53
|
+
const next = !enabled();
|
|
54
|
+
if (next) {
|
|
55
|
+
// Prime audio inside the click gesture first, then request permission.
|
|
56
|
+
// Awaiting permission before priming can drop the user-gesture token.
|
|
57
|
+
_prime();
|
|
58
|
+
const perm = await _ensurePermission();
|
|
59
|
+
setEnabled(true);
|
|
60
|
+
if (perm === "denied" && typeof Modal !== "undefined" && Modal.toast) {
|
|
61
|
+
Modal.toast(
|
|
62
|
+
(typeof I18n !== "undefined" && I18n.t("notify.toast.denied")) ||
|
|
63
|
+
"Sound alerts enabled. Desktop notifications are blocked in browser settings.",
|
|
64
|
+
"warning"
|
|
65
|
+
);
|
|
66
|
+
} else if (perm === "unsupported" && typeof Modal !== "undefined" && Modal.toast) {
|
|
67
|
+
Modal.toast(
|
|
68
|
+
(typeof I18n !== "undefined" && I18n.t("notify.toast.noDesktop")) ||
|
|
69
|
+
"Sound alerts enabled. This browser has no desktop notifications.",
|
|
70
|
+
"info"
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
setEnabled(false);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ── Browser Notification permission ──────────────────────────────────
|
|
79
|
+
function _notificationsSupported() {
|
|
80
|
+
return typeof window !== "undefined" && "Notification" in window;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function permission() {
|
|
84
|
+
if (!_notificationsSupported()) return "unsupported";
|
|
85
|
+
return Notification.permission; // "granted" | "denied" | "default"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function _ensurePermission() {
|
|
89
|
+
if (!_notificationsSupported()) return "unsupported";
|
|
90
|
+
if (Notification.permission === "granted") return "granted";
|
|
91
|
+
if (Notification.permission === "denied") return "denied";
|
|
92
|
+
try {
|
|
93
|
+
const result = await Notification.requestPermission();
|
|
94
|
+
return result;
|
|
95
|
+
} catch (_e) {
|
|
96
|
+
return Notification.permission;
|
|
97
|
+
}
|
|
51
98
|
}
|
|
52
99
|
|
|
53
100
|
// ── Audio ────────────────────────────────────────────────────────────
|
|
@@ -88,6 +135,46 @@ const Notify = (() => {
|
|
|
88
135
|
} catch (_e) { /* ignore */ }
|
|
89
136
|
}
|
|
90
137
|
|
|
138
|
+
// ── Desktop notification ─────────────────────────────────────────────
|
|
139
|
+
function _notifyDesktop(sid) {
|
|
140
|
+
if (!_notificationsSupported()) return;
|
|
141
|
+
if (Notification.permission !== "granted") return;
|
|
142
|
+
|
|
143
|
+
// Keep body generic on purpose — session names can be sensitive on shared
|
|
144
|
+
// screens. Click focuses the window and navigates to the session.
|
|
145
|
+
const title = typeof I18n !== "undefined"
|
|
146
|
+
? I18n.t("notify.desktop.title")
|
|
147
|
+
: "Task complete";
|
|
148
|
+
const body = typeof I18n !== "undefined"
|
|
149
|
+
? I18n.t("notify.desktop.body")
|
|
150
|
+
: "A background task finished. Click to open it.";
|
|
151
|
+
|
|
152
|
+
let n;
|
|
153
|
+
try {
|
|
154
|
+
n = new Notification(title, {
|
|
155
|
+
body,
|
|
156
|
+
tag: sid ? `clacky-task-${sid}` : "clacky-task",
|
|
157
|
+
renotify: true,
|
|
158
|
+
silent: true, // sound is handled by our own chime
|
|
159
|
+
});
|
|
160
|
+
} catch (_e) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
n.onclick = () => {
|
|
165
|
+
try { window.focus(); } catch (_e) { /* ignore */ }
|
|
166
|
+
if (sid && typeof Router !== "undefined" && typeof Router.navigate === "function") {
|
|
167
|
+
Router.navigate("session", { id: sid });
|
|
168
|
+
}
|
|
169
|
+
try { n.close(); } catch (_e) { /* ignore */ }
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// Auto-dismiss so toasts don't pile up forever.
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
try { n.close(); } catch (_e) { /* ignore */ }
|
|
175
|
+
}, 8000);
|
|
176
|
+
}
|
|
177
|
+
|
|
91
178
|
// ── Trigger decision ───────────────────────────────────────────────────
|
|
92
179
|
// Returns true when the user is NOT actively viewing the given session.
|
|
93
180
|
function _userIsAway(sid) {
|
|
@@ -109,9 +196,19 @@ const Notify = (() => {
|
|
|
109
196
|
if (!enabled()) return;
|
|
110
197
|
if (!_userIsAway(sid)) return;
|
|
111
198
|
_play();
|
|
199
|
+
_notifyDesktop(sid);
|
|
112
200
|
}
|
|
113
201
|
|
|
114
202
|
// ── Toggle button UI ───────────────────────────────────────────────────
|
|
203
|
+
function _tooltipKey(on) {
|
|
204
|
+
if (!on) return "notify.tooltip.off";
|
|
205
|
+
const perm = permission();
|
|
206
|
+
if (perm === "denied") return "notify.tooltip.onDenied";
|
|
207
|
+
if (perm === "unsupported") return "notify.tooltip.onNoDesktop";
|
|
208
|
+
if (perm === "default") return "notify.tooltip.onPending";
|
|
209
|
+
return "notify.tooltip.on";
|
|
210
|
+
}
|
|
211
|
+
|
|
115
212
|
function _updateToggleIcon() {
|
|
116
213
|
const btn = document.getElementById("notify-toggle-header");
|
|
117
214
|
if (!btn) return;
|
|
@@ -130,9 +227,10 @@ const Notify = (() => {
|
|
|
130
227
|
</svg>`;
|
|
131
228
|
btn.classList.toggle("notify-on", on);
|
|
132
229
|
if (typeof I18n !== "undefined") {
|
|
133
|
-
const tip = I18n.t(on
|
|
230
|
+
const tip = I18n.t(_tooltipKey(on));
|
|
134
231
|
btn.title = tip;
|
|
135
232
|
btn.setAttribute("aria-label", tip);
|
|
233
|
+
btn.setAttribute("data-i18n-title", _tooltipKey(on));
|
|
136
234
|
}
|
|
137
235
|
}
|
|
138
236
|
|
|
@@ -140,10 +238,29 @@ const Notify = (() => {
|
|
|
140
238
|
function init() {
|
|
141
239
|
_updateToggleIcon();
|
|
142
240
|
const btn = document.getElementById("notify-toggle-header");
|
|
143
|
-
if (btn)
|
|
241
|
+
if (btn) {
|
|
242
|
+
btn.addEventListener("click", () => {
|
|
243
|
+
// Fire-and-forget; permission prompt is awaited inside toggle.
|
|
244
|
+
toggle().then(() => _updateToggleIcon()).catch(() => _updateToggleIcon());
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
// Permission may change outside the page (browser settings); refresh tip.
|
|
248
|
+
document.addEventListener("visibilitychange", () => {
|
|
249
|
+
if (!document.hidden) _updateToggleIcon();
|
|
250
|
+
});
|
|
251
|
+
if (typeof I18n !== "undefined") {
|
|
252
|
+
document.addEventListener("langchange", () => _updateToggleIcon());
|
|
253
|
+
}
|
|
144
254
|
}
|
|
145
255
|
|
|
146
|
-
return {
|
|
256
|
+
return {
|
|
257
|
+
init,
|
|
258
|
+
toggle,
|
|
259
|
+
enabled,
|
|
260
|
+
setEnabled,
|
|
261
|
+
permission,
|
|
262
|
+
onTaskFinished,
|
|
263
|
+
};
|
|
147
264
|
})();
|
|
148
265
|
|
|
149
266
|
Clacky.Notify = Notify;
|
|
@@ -42,6 +42,13 @@
|
|
|
42
42
|
if (overlay) overlay.classList.toggle("active", open && !empty);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
function isOpen() {
|
|
46
|
+
try {
|
|
47
|
+
const stored = localStorage.getItem(OPEN_KEY);
|
|
48
|
+
return stored !== null && stored !== "0";
|
|
49
|
+
} catch (_e) { return false; }
|
|
50
|
+
}
|
|
51
|
+
|
|
45
52
|
function setOpen(open) {
|
|
46
53
|
try { localStorage.setItem(OPEN_KEY, open ? "1" : "0"); } catch (_e) { /* ignore */ }
|
|
47
54
|
applyOpenState();
|
|
@@ -91,7 +98,21 @@
|
|
|
91
98
|
});
|
|
92
99
|
}
|
|
93
100
|
|
|
101
|
+
// ── Public API ────────────────────────────────────────────────────────
|
|
102
|
+
// Expose setOpen so external code (e.g. WS dispatcher) can open/close the
|
|
103
|
+
// aside panel programmatically without duplicating localStorage logic here.
|
|
104
|
+
// open() is a no-op when the panel is already open — safe to call unconditionally.
|
|
105
|
+
if (window.Clacky) Clacky.Aside = {
|
|
106
|
+
open: () => { if (!isOpen()) setOpen(true); },
|
|
107
|
+
close: () => setOpen(false),
|
|
108
|
+
};
|
|
109
|
+
|
|
94
110
|
function init() {
|
|
111
|
+
// Re-assign in case Clacky was not yet defined when the IIFE ran.
|
|
112
|
+
if (window.Clacky) Clacky.Aside = {
|
|
113
|
+
open: () => { if (!isOpen()) setOpen(true); },
|
|
114
|
+
close: () => setOpen(false),
|
|
115
|
+
};
|
|
95
116
|
const collapse = $("btn-aside-collapse");
|
|
96
117
|
const opener = $("btn-aside-open");
|
|
97
118
|
const overlay = $("workspace-overlay");
|
|
@@ -76,7 +76,7 @@ const BrandStore = (() => {
|
|
|
76
76
|
return false;
|
|
77
77
|
},
|
|
78
78
|
|
|
79
|
-
// Re-fetch status
|
|
79
|
+
// Re-fetch status and notify views without driving the main boot sequence.
|
|
80
80
|
async refresh() {
|
|
81
81
|
try {
|
|
82
82
|
const res = await fetch("/api/brand/status");
|
|
@@ -84,8 +84,10 @@ const BrandStore = (() => {
|
|
|
84
84
|
_testMode = !!data.test_mode;
|
|
85
85
|
_userLicensed = !!data.user_licensed;
|
|
86
86
|
_branded = !!data.branded;
|
|
87
|
+
_emit("brand:status", data);
|
|
87
88
|
return data;
|
|
88
89
|
} catch (_) {
|
|
90
|
+
_emit("brand:status", null);
|
|
89
91
|
return null;
|
|
90
92
|
}
|
|
91
93
|
},
|
|
@@ -15,7 +15,22 @@
|
|
|
15
15
|
const BrandView = (() => {
|
|
16
16
|
|
|
17
17
|
function _onStatus(data) {
|
|
18
|
-
if (!data
|
|
18
|
+
if (!data) return;
|
|
19
|
+
if (!data.branded) {
|
|
20
|
+
if (data.distribution_refresh_pending) {
|
|
21
|
+
_scheduleDistributionRefreshPoll();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
_applyBrandName("OpenClacky");
|
|
25
|
+
Brand.clearBrandCache();
|
|
26
|
+
_applyHeaderLogo();
|
|
27
|
+
const banner = document.getElementById("brand-activation-banner");
|
|
28
|
+
if (banner) banner.remove();
|
|
29
|
+
if (typeof Settings !== "undefined" && Settings.loadBrand) Settings.loadBrand();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (data.product_name) _applyBrandName(data.product_name);
|
|
19
34
|
|
|
20
35
|
if (data.needs_activation) {
|
|
21
36
|
if (data.theme_color) Settings.applyAccentColor(data.theme_color, { persist: true });
|
|
@@ -268,6 +283,7 @@ const BrandView = (() => {
|
|
|
268
283
|
logoImg.alt = "OpenClacky";
|
|
269
284
|
logoImg.style.display = "";
|
|
270
285
|
if (brandWrap) brandWrap.classList.add("has-logo");
|
|
286
|
+
_applyFavicon("/favicon.svg");
|
|
271
287
|
}
|
|
272
288
|
|
|
273
289
|
function _applyFavicon(url) {
|
|
@@ -333,11 +349,19 @@ const BrandView = (() => {
|
|
|
333
349
|
let attempt = 0;
|
|
334
350
|
|
|
335
351
|
const poll = () => {
|
|
336
|
-
Brand.
|
|
337
|
-
|
|
338
|
-
|
|
352
|
+
Brand.refresh().then(status => {
|
|
353
|
+
Brand.clearBrandCache();
|
|
354
|
+
return Brand.fetchInfo().then(info => ({ status, info }));
|
|
355
|
+
}).then(({ status, info }) => {
|
|
356
|
+
if (info && info.product_name) _applyBrandName(info.product_name);
|
|
339
357
|
_applyHeaderLogo();
|
|
340
|
-
|
|
358
|
+
const refreshSettled = !!(
|
|
359
|
+
status && status.branded && !status.distribution_refresh_pending
|
|
360
|
+
);
|
|
361
|
+
if (refreshSettled && typeof Settings !== "undefined" && Settings.loadBrand) {
|
|
362
|
+
Settings.loadBrand();
|
|
363
|
+
}
|
|
364
|
+
if (refreshSettled || attempt >= delays.length) {
|
|
341
365
|
_distRefreshPolling = false;
|
|
342
366
|
return;
|
|
343
367
|
}
|
|
@@ -306,7 +306,7 @@ const NewSessionView = (() => {
|
|
|
306
306
|
const MAX_IMAGE_SIZE = 5 * 1024 * 1024;
|
|
307
307
|
const MAX_IMAGE_BYTES_SEND = 512 * 1024;
|
|
308
308
|
const MAX_IMAGE_LONG_EDGE = 1920;
|
|
309
|
-
const MAX_FILE_BYTES =
|
|
309
|
+
const MAX_FILE_BYTES = 300 * 1024 * 1024;
|
|
310
310
|
const ACCEPTED_IMAGE_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
|
|
311
311
|
|
|
312
312
|
function _docTypeIcon(mimeType, filename) {
|
|
@@ -390,7 +390,7 @@ const NewSessionView = (() => {
|
|
|
390
390
|
|
|
391
391
|
function _addGenericFile(file) {
|
|
392
392
|
if (file.size > MAX_FILE_BYTES) {
|
|
393
|
-
alert(I18n.t("chat.file.tooLarge", { name: file.name, max: "
|
|
393
|
+
alert(I18n.t("chat.file.tooLarge", { name: file.name, max: "300 MB" }));
|
|
394
394
|
return;
|
|
395
395
|
}
|
|
396
396
|
const formData = new FormData();
|
|
@@ -20,6 +20,7 @@ const TrashStore = (() => {
|
|
|
20
20
|
let _sessions = [];
|
|
21
21
|
let _sessionTotals = { count: 0, size: 0 };
|
|
22
22
|
let _filterSource = SOURCES.ALL;
|
|
23
|
+
let _filterProjectId = null; // null = all projects
|
|
23
24
|
let _loading = false;
|
|
24
25
|
|
|
25
26
|
const _listeners = {};
|
|
@@ -48,19 +49,23 @@ const TrashStore = (() => {
|
|
|
48
49
|
get files() { return _files; },
|
|
49
50
|
get totals() { return _totals; },
|
|
50
51
|
get sessions() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
let list = _sessions;
|
|
53
|
+
if (_filterSource !== SOURCES.ALL) {
|
|
54
|
+
list = _filterSource === SOURCES.CRON
|
|
55
|
+
? list.filter(s => s.source === SOURCES.CRON)
|
|
56
|
+
: list.filter(s => s.source !== SOURCES.CRON);
|
|
57
|
+
}
|
|
58
|
+
if (_filterProjectId !== null) {
|
|
59
|
+
list = list.filter(s => String(s.project_id ?? "") === _filterProjectId);
|
|
60
|
+
}
|
|
61
|
+
return list;
|
|
55
62
|
},
|
|
56
63
|
get sessionTotals() {
|
|
57
|
-
const filtered =
|
|
58
|
-
: _filterSource === SOURCES.CRON
|
|
59
|
-
? _sessions.filter(s => s.source === SOURCES.CRON)
|
|
60
|
-
: _sessions.filter(s => s.source !== SOURCES.CRON);
|
|
64
|
+
const filtered = state.sessions;
|
|
61
65
|
return { count: filtered.length, size: filtered.reduce((sum, s) => sum + (s.file_size || 0), 0) };
|
|
62
66
|
},
|
|
63
|
-
get filterSource()
|
|
67
|
+
get filterSource() { return _filterSource; },
|
|
68
|
+
get filterProjectId() { return _filterProjectId; },
|
|
64
69
|
orphanCount() { return _files.filter(f => _isOrphanRoot(f.project_root)).length; },
|
|
65
70
|
isOrphan(file) { return _isOrphanRoot(file.project_root); },
|
|
66
71
|
};
|
|
@@ -76,6 +81,14 @@ const TrashStore = (() => {
|
|
|
76
81
|
_emit("trash:sessionsChanged");
|
|
77
82
|
},
|
|
78
83
|
|
|
84
|
+
setFilterProject(projectId) {
|
|
85
|
+
// projectId: string/number ID or null/empty (= all)
|
|
86
|
+
const normalized = (projectId != null && projectId !== "") ? String(projectId) : null;
|
|
87
|
+
if (normalized === _filterProjectId) return;
|
|
88
|
+
_filterProjectId = normalized;
|
|
89
|
+
_emit("trash:sessionsChanged");
|
|
90
|
+
},
|
|
91
|
+
|
|
79
92
|
async loadFiles() {
|
|
80
93
|
if (_loading) return;
|
|
81
94
|
_loading = true;
|
|
@@ -166,6 +179,7 @@ const TrashStore = (() => {
|
|
|
166
179
|
if (restored && typeof Sessions !== "undefined") {
|
|
167
180
|
Sessions.add(restored);
|
|
168
181
|
Sessions.renderList();
|
|
182
|
+
if (typeof Projects !== "undefined") Projects.renderSection();
|
|
169
183
|
}
|
|
170
184
|
return { ok: true, session: restored };
|
|
171
185
|
} catch (e) {
|
|
@@ -49,6 +49,32 @@ const TrashView = (() => {
|
|
|
49
49
|
return d.toLocaleDateString();
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
// ── Project filter select helpers ────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
function _refreshProjectOptions() {
|
|
55
|
+
const sel = $("trash-filter-project");
|
|
56
|
+
if (!sel) return;
|
|
57
|
+
|
|
58
|
+
const projects = (typeof Projects !== "undefined") ? Projects.all() : [];
|
|
59
|
+
const currentVal = sel.value;
|
|
60
|
+
|
|
61
|
+
// Rebuild options: keep the "all" placeholder, then one per project
|
|
62
|
+
sel.innerHTML = `<option value="">${I18n.t ? I18n.t("trash.filterAllProjects") : "所有项目"}</option>`;
|
|
63
|
+
projects.forEach(p => {
|
|
64
|
+
const opt = document.createElement("option");
|
|
65
|
+
opt.value = p.id;
|
|
66
|
+
opt.textContent = p.name || p.id;
|
|
67
|
+
sel.appendChild(opt);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Restore previous selection if still valid
|
|
71
|
+
if (currentVal && projects.some(p => String(p.id) === currentVal)) {
|
|
72
|
+
sel.value = currentVal;
|
|
73
|
+
} else {
|
|
74
|
+
sel.value = "";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
52
78
|
// ── Tab switching ────────────────────────────────────────────────────
|
|
53
79
|
|
|
54
80
|
function _switchTab(tab) {
|
|
@@ -221,6 +247,7 @@ const TrashView = (() => {
|
|
|
221
247
|
if (btnOld) btnOld.disabled = sessions.length === 0;
|
|
222
248
|
if (btnAll) btnAll.disabled = sessions.length === 0;
|
|
223
249
|
if (filterBar) filterBar.style.display = "";
|
|
250
|
+
_refreshProjectOptions();
|
|
224
251
|
|
|
225
252
|
if (sessions.length === 0) {
|
|
226
253
|
list.innerHTML = `<div class="trash-empty">${_t("trash.noSessionTrash")}</div>`;
|
|
@@ -242,6 +269,21 @@ const TrashView = (() => {
|
|
|
242
269
|
const whenStr = _humanTime(session.deleted_at || session.created_at);
|
|
243
270
|
const taskLabel = I18n.t("trash.sessionTasks", { n: taskCount });
|
|
244
271
|
|
|
272
|
+
// Project badge — resolve name + color from Projects store if available
|
|
273
|
+
let projectBadgeHtml = "";
|
|
274
|
+
if (session.project_id && typeof Projects !== "undefined") {
|
|
275
|
+
const proj = Projects.find(session.project_id);
|
|
276
|
+
if (proj) {
|
|
277
|
+
const projName = escapeHtml(proj.name || "");
|
|
278
|
+
const dotColor = proj.color ? `style="background:${escapeHtml(proj.color)}"` : "";
|
|
279
|
+
projectBadgeHtml = `
|
|
280
|
+
<span class="trash-session-project-badge" title="${projName}">
|
|
281
|
+
<span class="trash-session-project-dot" ${dotColor}></span>
|
|
282
|
+
${projName}
|
|
283
|
+
</span>`;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
245
287
|
card.innerHTML = `
|
|
246
288
|
<div class="trash-session-card-info">
|
|
247
289
|
<div class="trash-session-card-name" title="${escapeHtml(name)}">${escapeHtml(name)}</div>
|
|
@@ -250,6 +292,7 @@ const TrashView = (() => {
|
|
|
250
292
|
<span>${escapeHtml(taskLabel)}</span>
|
|
251
293
|
<span>${sizeStr}</span>
|
|
252
294
|
<span title="${escapeHtml(session.deleted_at || session.created_at || '')}">${escapeHtml(whenStr)}</span>
|
|
295
|
+
${projectBadgeHtml}
|
|
253
296
|
</div>
|
|
254
297
|
</div>
|
|
255
298
|
<div class="trash-session-card-actions">
|
|
@@ -419,6 +462,14 @@ const TrashView = (() => {
|
|
|
419
462
|
document.querySelectorAll(".trash-filter-chip").forEach(c => c.classList.toggle("active", c.dataset.filter === val));
|
|
420
463
|
});
|
|
421
464
|
});
|
|
465
|
+
|
|
466
|
+
// Project filter select
|
|
467
|
+
const projSel = $("trash-filter-project");
|
|
468
|
+
if (projSel) {
|
|
469
|
+
projSel.addEventListener("change", () => {
|
|
470
|
+
Trash.setFilterProject(projSel.value || null);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
422
473
|
}
|
|
423
474
|
|
|
424
475
|
function _subscribe() {
|