@agent-link/server 0.1.124 → 0.1.126
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/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +54 -54
- package/web/app.js +1192 -1192
- package/web/favicon.svg +10 -10
- package/web/landing.html +1262 -1241
- package/web/landing.zh.html +1261 -0
- package/web/modules/connection.js +880 -880
- package/web/modules/fileBrowser.js +379 -379
- package/web/modules/filePreview.js +187 -187
- package/web/modules/sidebar.js +376 -376
- package/web/modules/streaming.js +110 -110
- package/web/style.css +2941 -2941
package/web/modules/sidebar.js
CHANGED
|
@@ -1,376 +1,376 @@
|
|
|
1
|
-
// ── Sidebar: session management, folder picker, grouped sessions ─────────────
|
|
2
|
-
const { computed } = Vue;
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates sidebar functionality bound to reactive state.
|
|
6
|
-
* @param {object} deps
|
|
7
|
-
* @param {Function} deps.wsSend
|
|
8
|
-
* @param {import('vue').Ref} deps.messages
|
|
9
|
-
* @param {import('vue').Ref} deps.isProcessing
|
|
10
|
-
* @param {import('vue').Ref} deps.sidebarOpen
|
|
11
|
-
* @param {import('vue').Ref} deps.historySessions
|
|
12
|
-
* @param {import('vue').Ref} deps.currentClaudeSessionId
|
|
13
|
-
* @param {import('vue').Ref} deps.needsResume
|
|
14
|
-
* @param {import('vue').Ref} deps.loadingSessions
|
|
15
|
-
* @param {import('vue').Ref} deps.loadingHistory
|
|
16
|
-
* @param {import('vue').Ref} deps.workDir
|
|
17
|
-
* @param {import('vue').Ref} deps.visibleLimit
|
|
18
|
-
* @param {import('vue').Ref} deps.folderPickerOpen
|
|
19
|
-
* @param {import('vue').Ref} deps.folderPickerPath
|
|
20
|
-
* @param {import('vue').Ref} deps.folderPickerEntries
|
|
21
|
-
* @param {import('vue').Ref} deps.folderPickerLoading
|
|
22
|
-
* @param {import('vue').Ref} deps.folderPickerSelected
|
|
23
|
-
* @param {object} deps.streaming - streaming controller
|
|
24
|
-
* @param {import('vue').Ref} deps.hostname
|
|
25
|
-
* @param {import('vue').Ref} deps.workdirHistory
|
|
26
|
-
*/
|
|
27
|
-
export function createSidebar(deps) {
|
|
28
|
-
const {
|
|
29
|
-
wsSend, messages, isProcessing, sidebarOpen,
|
|
30
|
-
historySessions, currentClaudeSessionId, needsResume,
|
|
31
|
-
loadingSessions, loadingHistory, workDir, visibleLimit,
|
|
32
|
-
folderPickerOpen, folderPickerPath, folderPickerEntries,
|
|
33
|
-
folderPickerLoading, folderPickerSelected, streaming,
|
|
34
|
-
hostname, workdirHistory,
|
|
35
|
-
// Multi-session parallel
|
|
36
|
-
currentConversationId, conversationCache, processingConversations,
|
|
37
|
-
switchConversation,
|
|
38
|
-
} = deps;
|
|
39
|
-
|
|
40
|
-
// ── Session management ──
|
|
41
|
-
|
|
42
|
-
let _sessionListTimer = null;
|
|
43
|
-
|
|
44
|
-
function requestSessionList() {
|
|
45
|
-
// Debounce: coalesce rapid calls (e.g. session_started + turn_completed)
|
|
46
|
-
// into a single request. First call fires immediately, subsequent calls
|
|
47
|
-
// within 2s are deferred.
|
|
48
|
-
if (_sessionListTimer) {
|
|
49
|
-
clearTimeout(_sessionListTimer);
|
|
50
|
-
_sessionListTimer = setTimeout(() => {
|
|
51
|
-
_sessionListTimer = null;
|
|
52
|
-
loadingSessions.value = true;
|
|
53
|
-
wsSend({ type: 'list_sessions' });
|
|
54
|
-
}, 2000);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
loadingSessions.value = true;
|
|
58
|
-
wsSend({ type: 'list_sessions' });
|
|
59
|
-
_sessionListTimer = setTimeout(() => { _sessionListTimer = null; }, 2000);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function resumeSession(session) {
|
|
63
|
-
if (window.innerWidth <= 768) sidebarOpen.value = false;
|
|
64
|
-
|
|
65
|
-
// Multi-session: check if we already have a conversation loaded for this claudeSessionId
|
|
66
|
-
if (switchConversation && conversationCache) {
|
|
67
|
-
// Check cache for existing conversation with this claudeSessionId
|
|
68
|
-
for (const [convId, cached] of Object.entries(conversationCache.value)) {
|
|
69
|
-
if (cached.claudeSessionId === session.sessionId) {
|
|
70
|
-
switchConversation(convId);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Check if current foreground already shows this session
|
|
75
|
-
if (currentClaudeSessionId.value === session.sessionId) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
// Create new conversationId, switch to it, then send resume
|
|
79
|
-
const newConvId = crypto.randomUUID();
|
|
80
|
-
switchConversation(newConvId);
|
|
81
|
-
currentClaudeSessionId.value = session.sessionId;
|
|
82
|
-
needsResume.value = true;
|
|
83
|
-
loadingHistory.value = true;
|
|
84
|
-
wsSend({
|
|
85
|
-
type: 'resume_conversation',
|
|
86
|
-
conversationId: newConvId,
|
|
87
|
-
claudeSessionId: session.sessionId,
|
|
88
|
-
});
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Legacy fallback (no multi-session)
|
|
93
|
-
if (isProcessing.value) return;
|
|
94
|
-
messages.value = [];
|
|
95
|
-
visibleLimit.value = 50;
|
|
96
|
-
streaming.setMessageIdCounter(0);
|
|
97
|
-
streaming.setStreamingMessageId(null);
|
|
98
|
-
streaming.reset();
|
|
99
|
-
|
|
100
|
-
currentClaudeSessionId.value = session.sessionId;
|
|
101
|
-
needsResume.value = true;
|
|
102
|
-
loadingHistory.value = true;
|
|
103
|
-
|
|
104
|
-
wsSend({
|
|
105
|
-
type: 'resume_conversation',
|
|
106
|
-
claudeSessionId: session.sessionId,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function newConversation() {
|
|
111
|
-
if (window.innerWidth <= 768) sidebarOpen.value = false;
|
|
112
|
-
|
|
113
|
-
// Multi-session: just switch to a new blank conversation
|
|
114
|
-
if (switchConversation) {
|
|
115
|
-
const newConvId = crypto.randomUUID();
|
|
116
|
-
switchConversation(newConvId);
|
|
117
|
-
messages.value.push({
|
|
118
|
-
id: streaming.nextId(), role: 'system',
|
|
119
|
-
content: 'New conversation started.',
|
|
120
|
-
timestamp: new Date(),
|
|
121
|
-
});
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Legacy fallback (no multi-session)
|
|
126
|
-
if (isProcessing.value) return;
|
|
127
|
-
messages.value = [];
|
|
128
|
-
visibleLimit.value = 50;
|
|
129
|
-
streaming.setMessageIdCounter(0);
|
|
130
|
-
streaming.setStreamingMessageId(null);
|
|
131
|
-
streaming.reset();
|
|
132
|
-
currentClaudeSessionId.value = null;
|
|
133
|
-
needsResume.value = false;
|
|
134
|
-
|
|
135
|
-
// Tell the agent to clear its lastClaudeSessionId so the next message
|
|
136
|
-
// starts a fresh session instead of auto-resuming the previous one.
|
|
137
|
-
wsSend({ type: 'new_conversation' });
|
|
138
|
-
|
|
139
|
-
messages.value.push({
|
|
140
|
-
id: streaming.nextId(), role: 'system',
|
|
141
|
-
content: 'New conversation started.',
|
|
142
|
-
timestamp: new Date(),
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function toggleSidebar() {
|
|
147
|
-
sidebarOpen.value = !sidebarOpen.value;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// ── Delete session ──
|
|
151
|
-
|
|
152
|
-
/** Session pending delete confirmation (null = dialog closed) */
|
|
153
|
-
let pendingDeleteSession = null;
|
|
154
|
-
const deleteConfirmOpen = deps.deleteConfirmOpen;
|
|
155
|
-
const deleteConfirmTitle = deps.deleteConfirmTitle;
|
|
156
|
-
|
|
157
|
-
function deleteSession(session) {
|
|
158
|
-
if (currentClaudeSessionId.value === session.sessionId) return; // guard: foreground
|
|
159
|
-
// Guard: check background conversations that are actively processing
|
|
160
|
-
if (conversationCache) {
|
|
161
|
-
for (const [, cached] of Object.entries(conversationCache.value)) {
|
|
162
|
-
if (cached.claudeSessionId === session.sessionId && cached.isProcessing) return;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
pendingDeleteSession = session;
|
|
166
|
-
deleteConfirmTitle.value = session.title || session.sessionId.slice(0, 8);
|
|
167
|
-
deleteConfirmOpen.value = true;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function confirmDeleteSession() {
|
|
171
|
-
if (!pendingDeleteSession) return;
|
|
172
|
-
wsSend({ type: 'delete_session', sessionId: pendingDeleteSession.sessionId });
|
|
173
|
-
deleteConfirmOpen.value = false;
|
|
174
|
-
pendingDeleteSession = null;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function cancelDeleteSession() {
|
|
178
|
-
deleteConfirmOpen.value = false;
|
|
179
|
-
pendingDeleteSession = null;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// ── Rename session ──
|
|
183
|
-
|
|
184
|
-
const renamingSessionId = deps.renamingSessionId;
|
|
185
|
-
const renameText = deps.renameText;
|
|
186
|
-
|
|
187
|
-
function startRename(session) {
|
|
188
|
-
renamingSessionId.value = session.sessionId;
|
|
189
|
-
renameText.value = session.title || '';
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function confirmRename() {
|
|
193
|
-
const sid = renamingSessionId.value;
|
|
194
|
-
const title = renameText.value.trim();
|
|
195
|
-
if (!sid || !title) {
|
|
196
|
-
cancelRename();
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
wsSend({ type: 'rename_session', sessionId: sid, newTitle: title });
|
|
200
|
-
renamingSessionId.value = null;
|
|
201
|
-
renameText.value = '';
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function cancelRename() {
|
|
205
|
-
renamingSessionId.value = null;
|
|
206
|
-
renameText.value = '';
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// ── Folder picker ──
|
|
210
|
-
|
|
211
|
-
function openFolderPicker() {
|
|
212
|
-
folderPickerOpen.value = true;
|
|
213
|
-
folderPickerSelected.value = '';
|
|
214
|
-
folderPickerLoading.value = true;
|
|
215
|
-
folderPickerPath.value = workDir.value || '';
|
|
216
|
-
folderPickerEntries.value = [];
|
|
217
|
-
wsSend({ type: 'list_directory', dirPath: workDir.value || '' });
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function loadFolderPickerDir(dirPath) {
|
|
221
|
-
folderPickerLoading.value = true;
|
|
222
|
-
folderPickerSelected.value = '';
|
|
223
|
-
folderPickerEntries.value = [];
|
|
224
|
-
wsSend({ type: 'list_directory', dirPath });
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function folderPickerNavigateUp() {
|
|
228
|
-
if (!folderPickerPath.value) return;
|
|
229
|
-
const isWin = folderPickerPath.value.includes('\\');
|
|
230
|
-
const parts = folderPickerPath.value.replace(/[/\\]$/, '').split(/[/\\]/);
|
|
231
|
-
parts.pop();
|
|
232
|
-
if (parts.length === 0) {
|
|
233
|
-
folderPickerPath.value = '';
|
|
234
|
-
loadFolderPickerDir('');
|
|
235
|
-
} else if (isWin && parts.length === 1 && /^[A-Za-z]:$/.test(parts[0])) {
|
|
236
|
-
folderPickerPath.value = parts[0] + '\\';
|
|
237
|
-
loadFolderPickerDir(parts[0] + '\\');
|
|
238
|
-
} else {
|
|
239
|
-
const sep = isWin ? '\\' : '/';
|
|
240
|
-
const parent = parts.join(sep);
|
|
241
|
-
folderPickerPath.value = parent;
|
|
242
|
-
loadFolderPickerDir(parent);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function folderPickerSelectItem(entry) {
|
|
247
|
-
folderPickerSelected.value = entry.name;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function folderPickerEnter(entry) {
|
|
251
|
-
const sep = folderPickerPath.value.includes('\\') || /^[A-Z]:/.test(entry.name) ? '\\' : '/';
|
|
252
|
-
let newPath;
|
|
253
|
-
if (!folderPickerPath.value) {
|
|
254
|
-
newPath = entry.name + (entry.name.endsWith('\\') ? '' : '\\');
|
|
255
|
-
} else {
|
|
256
|
-
newPath = folderPickerPath.value.replace(/[/\\]$/, '') + sep + entry.name;
|
|
257
|
-
}
|
|
258
|
-
folderPickerPath.value = newPath;
|
|
259
|
-
folderPickerSelected.value = '';
|
|
260
|
-
loadFolderPickerDir(newPath);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function folderPickerGoToPath() {
|
|
264
|
-
const path = folderPickerPath.value.trim();
|
|
265
|
-
if (!path) {
|
|
266
|
-
loadFolderPickerDir('');
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
folderPickerSelected.value = '';
|
|
270
|
-
loadFolderPickerDir(path);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function confirmFolderPicker() {
|
|
274
|
-
let path = folderPickerPath.value;
|
|
275
|
-
if (!path) return;
|
|
276
|
-
if (folderPickerSelected.value) {
|
|
277
|
-
const sep = path.includes('\\') ? '\\' : '/';
|
|
278
|
-
path = path.replace(/[/\\]$/, '') + sep + folderPickerSelected.value;
|
|
279
|
-
}
|
|
280
|
-
folderPickerOpen.value = false;
|
|
281
|
-
wsSend({ type: 'change_workdir', workDir: path });
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// ── Working directory history ──
|
|
285
|
-
|
|
286
|
-
const WORKDIR_HISTORY_MAX = 10;
|
|
287
|
-
|
|
288
|
-
function getWorkdirHistoryKey() {
|
|
289
|
-
return `agentlink-workdir-history-${hostname.value}`;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function loadWorkdirHistory() {
|
|
293
|
-
try {
|
|
294
|
-
const stored = localStorage.getItem(getWorkdirHistoryKey());
|
|
295
|
-
workdirHistory.value = stored ? JSON.parse(stored) : [];
|
|
296
|
-
} catch {
|
|
297
|
-
workdirHistory.value = [];
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function saveWorkdirHistory() {
|
|
302
|
-
localStorage.setItem(getWorkdirHistoryKey(), JSON.stringify(workdirHistory.value));
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function addToWorkdirHistory(path) {
|
|
306
|
-
if (!path) return;
|
|
307
|
-
const filtered = workdirHistory.value.filter(p => p !== path);
|
|
308
|
-
filtered.unshift(path);
|
|
309
|
-
workdirHistory.value = filtered.slice(0, WORKDIR_HISTORY_MAX);
|
|
310
|
-
saveWorkdirHistory();
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function removeFromWorkdirHistory(path) {
|
|
314
|
-
workdirHistory.value = workdirHistory.value.filter(p => p !== path);
|
|
315
|
-
saveWorkdirHistory();
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function switchToWorkdir(path) {
|
|
319
|
-
wsSend({ type: 'change_workdir', workDir: path });
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const filteredWorkdirHistory = computed(() => {
|
|
323
|
-
return workdirHistory.value.filter(p => p !== workDir.value);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
// ── isSessionProcessing ──
|
|
327
|
-
// Used by sidebar template to show processing indicator on session items
|
|
328
|
-
function isSessionProcessing(claudeSessionId) {
|
|
329
|
-
if (!conversationCache || !processingConversations) return false;
|
|
330
|
-
// Check cached background conversations
|
|
331
|
-
for (const [convId, cached] of Object.entries(conversationCache.value)) {
|
|
332
|
-
if (cached.claudeSessionId === claudeSessionId && cached.isProcessing) {
|
|
333
|
-
return true;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
// Check current foreground conversation
|
|
337
|
-
if (currentClaudeSessionId.value === claudeSessionId && isProcessing.value) {
|
|
338
|
-
return true;
|
|
339
|
-
}
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// ── Grouped sessions ──
|
|
344
|
-
|
|
345
|
-
const groupedSessions = computed(() => {
|
|
346
|
-
if (!historySessions.value.length) return [];
|
|
347
|
-
const now = new Date();
|
|
348
|
-
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
|
|
349
|
-
const yesterdayStart = todayStart - 86400000;
|
|
350
|
-
const weekStart = todayStart - 6 * 86400000;
|
|
351
|
-
|
|
352
|
-
const groups = {};
|
|
353
|
-
for (const s of historySessions.value) {
|
|
354
|
-
let label;
|
|
355
|
-
if (s.lastModified >= todayStart) label = 'Today';
|
|
356
|
-
else if (s.lastModified >= yesterdayStart) label = 'Yesterday';
|
|
357
|
-
else if (s.lastModified >= weekStart) label = 'This week';
|
|
358
|
-
else label = 'Earlier';
|
|
359
|
-
if (!groups[label]) groups[label] = [];
|
|
360
|
-
groups[label].push(s);
|
|
361
|
-
}
|
|
362
|
-
const order = ['Today', 'Yesterday', 'This week', 'Earlier'];
|
|
363
|
-
return order.filter(k => groups[k]).map(k => ({ label: k, sessions: groups[k] }));
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
return {
|
|
367
|
-
requestSessionList, resumeSession, newConversation, toggleSidebar,
|
|
368
|
-
deleteSession, confirmDeleteSession, cancelDeleteSession,
|
|
369
|
-
startRename, confirmRename, cancelRename,
|
|
370
|
-
openFolderPicker, folderPickerNavigateUp, folderPickerSelectItem,
|
|
371
|
-
folderPickerEnter, folderPickerGoToPath, confirmFolderPicker,
|
|
372
|
-
groupedSessions, isSessionProcessing,
|
|
373
|
-
loadWorkdirHistory, addToWorkdirHistory, removeFromWorkdirHistory,
|
|
374
|
-
switchToWorkdir, filteredWorkdirHistory,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
1
|
+
// ── Sidebar: session management, folder picker, grouped sessions ─────────────
|
|
2
|
+
const { computed } = Vue;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates sidebar functionality bound to reactive state.
|
|
6
|
+
* @param {object} deps
|
|
7
|
+
* @param {Function} deps.wsSend
|
|
8
|
+
* @param {import('vue').Ref} deps.messages
|
|
9
|
+
* @param {import('vue').Ref} deps.isProcessing
|
|
10
|
+
* @param {import('vue').Ref} deps.sidebarOpen
|
|
11
|
+
* @param {import('vue').Ref} deps.historySessions
|
|
12
|
+
* @param {import('vue').Ref} deps.currentClaudeSessionId
|
|
13
|
+
* @param {import('vue').Ref} deps.needsResume
|
|
14
|
+
* @param {import('vue').Ref} deps.loadingSessions
|
|
15
|
+
* @param {import('vue').Ref} deps.loadingHistory
|
|
16
|
+
* @param {import('vue').Ref} deps.workDir
|
|
17
|
+
* @param {import('vue').Ref} deps.visibleLimit
|
|
18
|
+
* @param {import('vue').Ref} deps.folderPickerOpen
|
|
19
|
+
* @param {import('vue').Ref} deps.folderPickerPath
|
|
20
|
+
* @param {import('vue').Ref} deps.folderPickerEntries
|
|
21
|
+
* @param {import('vue').Ref} deps.folderPickerLoading
|
|
22
|
+
* @param {import('vue').Ref} deps.folderPickerSelected
|
|
23
|
+
* @param {object} deps.streaming - streaming controller
|
|
24
|
+
* @param {import('vue').Ref} deps.hostname
|
|
25
|
+
* @param {import('vue').Ref} deps.workdirHistory
|
|
26
|
+
*/
|
|
27
|
+
export function createSidebar(deps) {
|
|
28
|
+
const {
|
|
29
|
+
wsSend, messages, isProcessing, sidebarOpen,
|
|
30
|
+
historySessions, currentClaudeSessionId, needsResume,
|
|
31
|
+
loadingSessions, loadingHistory, workDir, visibleLimit,
|
|
32
|
+
folderPickerOpen, folderPickerPath, folderPickerEntries,
|
|
33
|
+
folderPickerLoading, folderPickerSelected, streaming,
|
|
34
|
+
hostname, workdirHistory,
|
|
35
|
+
// Multi-session parallel
|
|
36
|
+
currentConversationId, conversationCache, processingConversations,
|
|
37
|
+
switchConversation,
|
|
38
|
+
} = deps;
|
|
39
|
+
|
|
40
|
+
// ── Session management ──
|
|
41
|
+
|
|
42
|
+
let _sessionListTimer = null;
|
|
43
|
+
|
|
44
|
+
function requestSessionList() {
|
|
45
|
+
// Debounce: coalesce rapid calls (e.g. session_started + turn_completed)
|
|
46
|
+
// into a single request. First call fires immediately, subsequent calls
|
|
47
|
+
// within 2s are deferred.
|
|
48
|
+
if (_sessionListTimer) {
|
|
49
|
+
clearTimeout(_sessionListTimer);
|
|
50
|
+
_sessionListTimer = setTimeout(() => {
|
|
51
|
+
_sessionListTimer = null;
|
|
52
|
+
loadingSessions.value = true;
|
|
53
|
+
wsSend({ type: 'list_sessions' });
|
|
54
|
+
}, 2000);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
loadingSessions.value = true;
|
|
58
|
+
wsSend({ type: 'list_sessions' });
|
|
59
|
+
_sessionListTimer = setTimeout(() => { _sessionListTimer = null; }, 2000);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function resumeSession(session) {
|
|
63
|
+
if (window.innerWidth <= 768) sidebarOpen.value = false;
|
|
64
|
+
|
|
65
|
+
// Multi-session: check if we already have a conversation loaded for this claudeSessionId
|
|
66
|
+
if (switchConversation && conversationCache) {
|
|
67
|
+
// Check cache for existing conversation with this claudeSessionId
|
|
68
|
+
for (const [convId, cached] of Object.entries(conversationCache.value)) {
|
|
69
|
+
if (cached.claudeSessionId === session.sessionId) {
|
|
70
|
+
switchConversation(convId);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Check if current foreground already shows this session
|
|
75
|
+
if (currentClaudeSessionId.value === session.sessionId) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Create new conversationId, switch to it, then send resume
|
|
79
|
+
const newConvId = crypto.randomUUID();
|
|
80
|
+
switchConversation(newConvId);
|
|
81
|
+
currentClaudeSessionId.value = session.sessionId;
|
|
82
|
+
needsResume.value = true;
|
|
83
|
+
loadingHistory.value = true;
|
|
84
|
+
wsSend({
|
|
85
|
+
type: 'resume_conversation',
|
|
86
|
+
conversationId: newConvId,
|
|
87
|
+
claudeSessionId: session.sessionId,
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Legacy fallback (no multi-session)
|
|
93
|
+
if (isProcessing.value) return;
|
|
94
|
+
messages.value = [];
|
|
95
|
+
visibleLimit.value = 50;
|
|
96
|
+
streaming.setMessageIdCounter(0);
|
|
97
|
+
streaming.setStreamingMessageId(null);
|
|
98
|
+
streaming.reset();
|
|
99
|
+
|
|
100
|
+
currentClaudeSessionId.value = session.sessionId;
|
|
101
|
+
needsResume.value = true;
|
|
102
|
+
loadingHistory.value = true;
|
|
103
|
+
|
|
104
|
+
wsSend({
|
|
105
|
+
type: 'resume_conversation',
|
|
106
|
+
claudeSessionId: session.sessionId,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function newConversation() {
|
|
111
|
+
if (window.innerWidth <= 768) sidebarOpen.value = false;
|
|
112
|
+
|
|
113
|
+
// Multi-session: just switch to a new blank conversation
|
|
114
|
+
if (switchConversation) {
|
|
115
|
+
const newConvId = crypto.randomUUID();
|
|
116
|
+
switchConversation(newConvId);
|
|
117
|
+
messages.value.push({
|
|
118
|
+
id: streaming.nextId(), role: 'system',
|
|
119
|
+
content: 'New conversation started.',
|
|
120
|
+
timestamp: new Date(),
|
|
121
|
+
});
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Legacy fallback (no multi-session)
|
|
126
|
+
if (isProcessing.value) return;
|
|
127
|
+
messages.value = [];
|
|
128
|
+
visibleLimit.value = 50;
|
|
129
|
+
streaming.setMessageIdCounter(0);
|
|
130
|
+
streaming.setStreamingMessageId(null);
|
|
131
|
+
streaming.reset();
|
|
132
|
+
currentClaudeSessionId.value = null;
|
|
133
|
+
needsResume.value = false;
|
|
134
|
+
|
|
135
|
+
// Tell the agent to clear its lastClaudeSessionId so the next message
|
|
136
|
+
// starts a fresh session instead of auto-resuming the previous one.
|
|
137
|
+
wsSend({ type: 'new_conversation' });
|
|
138
|
+
|
|
139
|
+
messages.value.push({
|
|
140
|
+
id: streaming.nextId(), role: 'system',
|
|
141
|
+
content: 'New conversation started.',
|
|
142
|
+
timestamp: new Date(),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function toggleSidebar() {
|
|
147
|
+
sidebarOpen.value = !sidebarOpen.value;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ── Delete session ──
|
|
151
|
+
|
|
152
|
+
/** Session pending delete confirmation (null = dialog closed) */
|
|
153
|
+
let pendingDeleteSession = null;
|
|
154
|
+
const deleteConfirmOpen = deps.deleteConfirmOpen;
|
|
155
|
+
const deleteConfirmTitle = deps.deleteConfirmTitle;
|
|
156
|
+
|
|
157
|
+
function deleteSession(session) {
|
|
158
|
+
if (currentClaudeSessionId.value === session.sessionId) return; // guard: foreground
|
|
159
|
+
// Guard: check background conversations that are actively processing
|
|
160
|
+
if (conversationCache) {
|
|
161
|
+
for (const [, cached] of Object.entries(conversationCache.value)) {
|
|
162
|
+
if (cached.claudeSessionId === session.sessionId && cached.isProcessing) return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
pendingDeleteSession = session;
|
|
166
|
+
deleteConfirmTitle.value = session.title || session.sessionId.slice(0, 8);
|
|
167
|
+
deleteConfirmOpen.value = true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function confirmDeleteSession() {
|
|
171
|
+
if (!pendingDeleteSession) return;
|
|
172
|
+
wsSend({ type: 'delete_session', sessionId: pendingDeleteSession.sessionId });
|
|
173
|
+
deleteConfirmOpen.value = false;
|
|
174
|
+
pendingDeleteSession = null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function cancelDeleteSession() {
|
|
178
|
+
deleteConfirmOpen.value = false;
|
|
179
|
+
pendingDeleteSession = null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ── Rename session ──
|
|
183
|
+
|
|
184
|
+
const renamingSessionId = deps.renamingSessionId;
|
|
185
|
+
const renameText = deps.renameText;
|
|
186
|
+
|
|
187
|
+
function startRename(session) {
|
|
188
|
+
renamingSessionId.value = session.sessionId;
|
|
189
|
+
renameText.value = session.title || '';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function confirmRename() {
|
|
193
|
+
const sid = renamingSessionId.value;
|
|
194
|
+
const title = renameText.value.trim();
|
|
195
|
+
if (!sid || !title) {
|
|
196
|
+
cancelRename();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
wsSend({ type: 'rename_session', sessionId: sid, newTitle: title });
|
|
200
|
+
renamingSessionId.value = null;
|
|
201
|
+
renameText.value = '';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function cancelRename() {
|
|
205
|
+
renamingSessionId.value = null;
|
|
206
|
+
renameText.value = '';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ── Folder picker ──
|
|
210
|
+
|
|
211
|
+
function openFolderPicker() {
|
|
212
|
+
folderPickerOpen.value = true;
|
|
213
|
+
folderPickerSelected.value = '';
|
|
214
|
+
folderPickerLoading.value = true;
|
|
215
|
+
folderPickerPath.value = workDir.value || '';
|
|
216
|
+
folderPickerEntries.value = [];
|
|
217
|
+
wsSend({ type: 'list_directory', dirPath: workDir.value || '' });
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function loadFolderPickerDir(dirPath) {
|
|
221
|
+
folderPickerLoading.value = true;
|
|
222
|
+
folderPickerSelected.value = '';
|
|
223
|
+
folderPickerEntries.value = [];
|
|
224
|
+
wsSend({ type: 'list_directory', dirPath });
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function folderPickerNavigateUp() {
|
|
228
|
+
if (!folderPickerPath.value) return;
|
|
229
|
+
const isWin = folderPickerPath.value.includes('\\');
|
|
230
|
+
const parts = folderPickerPath.value.replace(/[/\\]$/, '').split(/[/\\]/);
|
|
231
|
+
parts.pop();
|
|
232
|
+
if (parts.length === 0) {
|
|
233
|
+
folderPickerPath.value = '';
|
|
234
|
+
loadFolderPickerDir('');
|
|
235
|
+
} else if (isWin && parts.length === 1 && /^[A-Za-z]:$/.test(parts[0])) {
|
|
236
|
+
folderPickerPath.value = parts[0] + '\\';
|
|
237
|
+
loadFolderPickerDir(parts[0] + '\\');
|
|
238
|
+
} else {
|
|
239
|
+
const sep = isWin ? '\\' : '/';
|
|
240
|
+
const parent = parts.join(sep);
|
|
241
|
+
folderPickerPath.value = parent;
|
|
242
|
+
loadFolderPickerDir(parent);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function folderPickerSelectItem(entry) {
|
|
247
|
+
folderPickerSelected.value = entry.name;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function folderPickerEnter(entry) {
|
|
251
|
+
const sep = folderPickerPath.value.includes('\\') || /^[A-Z]:/.test(entry.name) ? '\\' : '/';
|
|
252
|
+
let newPath;
|
|
253
|
+
if (!folderPickerPath.value) {
|
|
254
|
+
newPath = entry.name + (entry.name.endsWith('\\') ? '' : '\\');
|
|
255
|
+
} else {
|
|
256
|
+
newPath = folderPickerPath.value.replace(/[/\\]$/, '') + sep + entry.name;
|
|
257
|
+
}
|
|
258
|
+
folderPickerPath.value = newPath;
|
|
259
|
+
folderPickerSelected.value = '';
|
|
260
|
+
loadFolderPickerDir(newPath);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function folderPickerGoToPath() {
|
|
264
|
+
const path = folderPickerPath.value.trim();
|
|
265
|
+
if (!path) {
|
|
266
|
+
loadFolderPickerDir('');
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
folderPickerSelected.value = '';
|
|
270
|
+
loadFolderPickerDir(path);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function confirmFolderPicker() {
|
|
274
|
+
let path = folderPickerPath.value;
|
|
275
|
+
if (!path) return;
|
|
276
|
+
if (folderPickerSelected.value) {
|
|
277
|
+
const sep = path.includes('\\') ? '\\' : '/';
|
|
278
|
+
path = path.replace(/[/\\]$/, '') + sep + folderPickerSelected.value;
|
|
279
|
+
}
|
|
280
|
+
folderPickerOpen.value = false;
|
|
281
|
+
wsSend({ type: 'change_workdir', workDir: path });
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// ── Working directory history ──
|
|
285
|
+
|
|
286
|
+
const WORKDIR_HISTORY_MAX = 10;
|
|
287
|
+
|
|
288
|
+
function getWorkdirHistoryKey() {
|
|
289
|
+
return `agentlink-workdir-history-${hostname.value}`;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function loadWorkdirHistory() {
|
|
293
|
+
try {
|
|
294
|
+
const stored = localStorage.getItem(getWorkdirHistoryKey());
|
|
295
|
+
workdirHistory.value = stored ? JSON.parse(stored) : [];
|
|
296
|
+
} catch {
|
|
297
|
+
workdirHistory.value = [];
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function saveWorkdirHistory() {
|
|
302
|
+
localStorage.setItem(getWorkdirHistoryKey(), JSON.stringify(workdirHistory.value));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function addToWorkdirHistory(path) {
|
|
306
|
+
if (!path) return;
|
|
307
|
+
const filtered = workdirHistory.value.filter(p => p !== path);
|
|
308
|
+
filtered.unshift(path);
|
|
309
|
+
workdirHistory.value = filtered.slice(0, WORKDIR_HISTORY_MAX);
|
|
310
|
+
saveWorkdirHistory();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function removeFromWorkdirHistory(path) {
|
|
314
|
+
workdirHistory.value = workdirHistory.value.filter(p => p !== path);
|
|
315
|
+
saveWorkdirHistory();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function switchToWorkdir(path) {
|
|
319
|
+
wsSend({ type: 'change_workdir', workDir: path });
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const filteredWorkdirHistory = computed(() => {
|
|
323
|
+
return workdirHistory.value.filter(p => p !== workDir.value);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// ── isSessionProcessing ──
|
|
327
|
+
// Used by sidebar template to show processing indicator on session items
|
|
328
|
+
function isSessionProcessing(claudeSessionId) {
|
|
329
|
+
if (!conversationCache || !processingConversations) return false;
|
|
330
|
+
// Check cached background conversations
|
|
331
|
+
for (const [convId, cached] of Object.entries(conversationCache.value)) {
|
|
332
|
+
if (cached.claudeSessionId === claudeSessionId && cached.isProcessing) {
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// Check current foreground conversation
|
|
337
|
+
if (currentClaudeSessionId.value === claudeSessionId && isProcessing.value) {
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// ── Grouped sessions ──
|
|
344
|
+
|
|
345
|
+
const groupedSessions = computed(() => {
|
|
346
|
+
if (!historySessions.value.length) return [];
|
|
347
|
+
const now = new Date();
|
|
348
|
+
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
|
|
349
|
+
const yesterdayStart = todayStart - 86400000;
|
|
350
|
+
const weekStart = todayStart - 6 * 86400000;
|
|
351
|
+
|
|
352
|
+
const groups = {};
|
|
353
|
+
for (const s of historySessions.value) {
|
|
354
|
+
let label;
|
|
355
|
+
if (s.lastModified >= todayStart) label = 'Today';
|
|
356
|
+
else if (s.lastModified >= yesterdayStart) label = 'Yesterday';
|
|
357
|
+
else if (s.lastModified >= weekStart) label = 'This week';
|
|
358
|
+
else label = 'Earlier';
|
|
359
|
+
if (!groups[label]) groups[label] = [];
|
|
360
|
+
groups[label].push(s);
|
|
361
|
+
}
|
|
362
|
+
const order = ['Today', 'Yesterday', 'This week', 'Earlier'];
|
|
363
|
+
return order.filter(k => groups[k]).map(k => ({ label: k, sessions: groups[k] }));
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
return {
|
|
367
|
+
requestSessionList, resumeSession, newConversation, toggleSidebar,
|
|
368
|
+
deleteSession, confirmDeleteSession, cancelDeleteSession,
|
|
369
|
+
startRename, confirmRename, cancelRename,
|
|
370
|
+
openFolderPicker, folderPickerNavigateUp, folderPickerSelectItem,
|
|
371
|
+
folderPickerEnter, folderPickerGoToPath, confirmFolderPicker,
|
|
372
|
+
groupedSessions, isSessionProcessing,
|
|
373
|
+
loadWorkdirHistory, addToWorkdirHistory, removeFromWorkdirHistory,
|
|
374
|
+
switchToWorkdir, filteredWorkdirHistory,
|
|
375
|
+
};
|
|
376
|
+
}
|