@agent-link/server 0.1.32 → 0.1.34

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.
@@ -1,188 +1,186 @@
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
- */
25
- export function createSidebar(deps) {
26
- const {
27
- wsSend, messages, isProcessing, sidebarOpen,
28
- historySessions, currentClaudeSessionId, needsResume,
29
- loadingSessions, loadingHistory, workDir, visibleLimit,
30
- folderPickerOpen, folderPickerPath, folderPickerEntries,
31
- folderPickerLoading, folderPickerSelected, streaming,
32
- } = deps;
33
-
34
- // ── Session management ──
35
-
36
- function requestSessionList() {
37
- loadingSessions.value = true;
38
- wsSend({ type: 'list_sessions' });
39
- }
40
-
41
- function resumeSession(session) {
42
- if (isProcessing.value) return;
43
- if (window.innerWidth <= 768) sidebarOpen.value = false;
44
- messages.value = [];
45
- visibleLimit.value = 50;
46
- streaming.setMessageIdCounter(0);
47
- streaming.setStreamingMessageId(null);
48
- streaming.reset();
49
-
50
- currentClaudeSessionId.value = session.sessionId;
51
- needsResume.value = true;
52
- loadingHistory.value = true;
53
- localStorage.setItem('agentlink-claude-session', session.sessionId);
54
-
55
- wsSend({
56
- type: 'resume_conversation',
57
- claudeSessionId: session.sessionId,
58
- });
59
- }
60
-
61
- function newConversation() {
62
- if (isProcessing.value) return;
63
- if (window.innerWidth <= 768) sidebarOpen.value = false;
64
- messages.value = [];
65
- visibleLimit.value = 50;
66
- streaming.setMessageIdCounter(0);
67
- streaming.setStreamingMessageId(null);
68
- streaming.reset();
69
- currentClaudeSessionId.value = null;
70
- needsResume.value = false;
71
- localStorage.removeItem('agentlink-claude-session');
72
-
73
- messages.value.push({
74
- id: streaming.nextId(), role: 'system',
75
- content: 'New conversation started.',
76
- timestamp: new Date(),
77
- });
78
- }
79
-
80
- function toggleSidebar() {
81
- sidebarOpen.value = !sidebarOpen.value;
82
- }
83
-
84
- // ── Folder picker ──
85
-
86
- function openFolderPicker() {
87
- folderPickerOpen.value = true;
88
- folderPickerSelected.value = '';
89
- folderPickerLoading.value = true;
90
- folderPickerPath.value = workDir.value || '';
91
- folderPickerEntries.value = [];
92
- wsSend({ type: 'list_directory', dirPath: workDir.value || '' });
93
- }
94
-
95
- function loadFolderPickerDir(dirPath) {
96
- folderPickerLoading.value = true;
97
- folderPickerSelected.value = '';
98
- folderPickerEntries.value = [];
99
- wsSend({ type: 'list_directory', dirPath });
100
- }
101
-
102
- function folderPickerNavigateUp() {
103
- if (!folderPickerPath.value) return;
104
- const isWin = folderPickerPath.value.includes('\\');
105
- const parts = folderPickerPath.value.replace(/[/\\]$/, '').split(/[/\\]/);
106
- parts.pop();
107
- if (parts.length === 0) {
108
- folderPickerPath.value = '';
109
- loadFolderPickerDir('');
110
- } else if (isWin && parts.length === 1 && /^[A-Za-z]:$/.test(parts[0])) {
111
- folderPickerPath.value = parts[0] + '\\';
112
- loadFolderPickerDir(parts[0] + '\\');
113
- } else {
114
- const sep = isWin ? '\\' : '/';
115
- const parent = parts.join(sep);
116
- folderPickerPath.value = parent;
117
- loadFolderPickerDir(parent);
118
- }
119
- }
120
-
121
- function folderPickerSelectItem(entry) {
122
- folderPickerSelected.value = entry.name;
123
- }
124
-
125
- function folderPickerEnter(entry) {
126
- const sep = folderPickerPath.value.includes('\\') || /^[A-Z]:/.test(entry.name) ? '\\' : '/';
127
- let newPath;
128
- if (!folderPickerPath.value) {
129
- newPath = entry.name + (entry.name.endsWith('\\') ? '' : '\\');
130
- } else {
131
- newPath = folderPickerPath.value.replace(/[/\\]$/, '') + sep + entry.name;
132
- }
133
- folderPickerPath.value = newPath;
134
- folderPickerSelected.value = '';
135
- loadFolderPickerDir(newPath);
136
- }
137
-
138
- function folderPickerGoToPath() {
139
- const path = folderPickerPath.value.trim();
140
- if (!path) {
141
- loadFolderPickerDir('');
142
- return;
143
- }
144
- folderPickerSelected.value = '';
145
- loadFolderPickerDir(path);
146
- }
147
-
148
- function confirmFolderPicker() {
149
- let path = folderPickerPath.value;
150
- if (!path) return;
151
- if (folderPickerSelected.value) {
152
- const sep = path.includes('\\') ? '\\' : '/';
153
- path = path.replace(/[/\\]$/, '') + sep + folderPickerSelected.value;
154
- }
155
- folderPickerOpen.value = false;
156
- wsSend({ type: 'change_workdir', workDir: path });
157
- }
158
-
159
- // ── Grouped sessions ──
160
-
161
- const groupedSessions = computed(() => {
162
- if (!historySessions.value.length) return [];
163
- const now = new Date();
164
- const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
165
- const yesterdayStart = todayStart - 86400000;
166
- const weekStart = todayStart - 6 * 86400000;
167
-
168
- const groups = {};
169
- for (const s of historySessions.value) {
170
- let label;
171
- if (s.lastModified >= todayStart) label = 'Today';
172
- else if (s.lastModified >= yesterdayStart) label = 'Yesterday';
173
- else if (s.lastModified >= weekStart) label = 'This week';
174
- else label = 'Earlier';
175
- if (!groups[label]) groups[label] = [];
176
- groups[label].push(s);
177
- }
178
- const order = ['Today', 'Yesterday', 'This week', 'Earlier'];
179
- return order.filter(k => groups[k]).map(k => ({ label: k, sessions: groups[k] }));
180
- });
181
-
182
- return {
183
- requestSessionList, resumeSession, newConversation, toggleSidebar,
184
- openFolderPicker, folderPickerNavigateUp, folderPickerSelectItem,
185
- folderPickerEnter, folderPickerGoToPath, confirmFolderPicker,
186
- groupedSessions,
187
- };
188
- }
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
+ */
25
+ export function createSidebar(deps) {
26
+ const {
27
+ wsSend, messages, isProcessing, sidebarOpen,
28
+ historySessions, currentClaudeSessionId, needsResume,
29
+ loadingSessions, loadingHistory, workDir, visibleLimit,
30
+ folderPickerOpen, folderPickerPath, folderPickerEntries,
31
+ folderPickerLoading, folderPickerSelected, streaming,
32
+ } = deps;
33
+
34
+ // ── Session management ──
35
+
36
+ function requestSessionList() {
37
+ loadingSessions.value = true;
38
+ wsSend({ type: 'list_sessions' });
39
+ }
40
+
41
+ function resumeSession(session) {
42
+ if (isProcessing.value) return;
43
+ if (window.innerWidth <= 768) sidebarOpen.value = false;
44
+ messages.value = [];
45
+ visibleLimit.value = 50;
46
+ streaming.setMessageIdCounter(0);
47
+ streaming.setStreamingMessageId(null);
48
+ streaming.reset();
49
+
50
+ currentClaudeSessionId.value = session.sessionId;
51
+ needsResume.value = true;
52
+ loadingHistory.value = true;
53
+
54
+ wsSend({
55
+ type: 'resume_conversation',
56
+ claudeSessionId: session.sessionId,
57
+ });
58
+ }
59
+
60
+ function newConversation() {
61
+ if (isProcessing.value) return;
62
+ if (window.innerWidth <= 768) sidebarOpen.value = false;
63
+ messages.value = [];
64
+ visibleLimit.value = 50;
65
+ streaming.setMessageIdCounter(0);
66
+ streaming.setStreamingMessageId(null);
67
+ streaming.reset();
68
+ currentClaudeSessionId.value = null;
69
+ needsResume.value = false;
70
+
71
+ messages.value.push({
72
+ id: streaming.nextId(), role: 'system',
73
+ content: 'New conversation started.',
74
+ timestamp: new Date(),
75
+ });
76
+ }
77
+
78
+ function toggleSidebar() {
79
+ sidebarOpen.value = !sidebarOpen.value;
80
+ }
81
+
82
+ // ── Folder picker ──
83
+
84
+ function openFolderPicker() {
85
+ folderPickerOpen.value = true;
86
+ folderPickerSelected.value = '';
87
+ folderPickerLoading.value = true;
88
+ folderPickerPath.value = workDir.value || '';
89
+ folderPickerEntries.value = [];
90
+ wsSend({ type: 'list_directory', dirPath: workDir.value || '' });
91
+ }
92
+
93
+ function loadFolderPickerDir(dirPath) {
94
+ folderPickerLoading.value = true;
95
+ folderPickerSelected.value = '';
96
+ folderPickerEntries.value = [];
97
+ wsSend({ type: 'list_directory', dirPath });
98
+ }
99
+
100
+ function folderPickerNavigateUp() {
101
+ if (!folderPickerPath.value) return;
102
+ const isWin = folderPickerPath.value.includes('\\');
103
+ const parts = folderPickerPath.value.replace(/[/\\]$/, '').split(/[/\\]/);
104
+ parts.pop();
105
+ if (parts.length === 0) {
106
+ folderPickerPath.value = '';
107
+ loadFolderPickerDir('');
108
+ } else if (isWin && parts.length === 1 && /^[A-Za-z]:$/.test(parts[0])) {
109
+ folderPickerPath.value = parts[0] + '\\';
110
+ loadFolderPickerDir(parts[0] + '\\');
111
+ } else {
112
+ const sep = isWin ? '\\' : '/';
113
+ const parent = parts.join(sep);
114
+ folderPickerPath.value = parent;
115
+ loadFolderPickerDir(parent);
116
+ }
117
+ }
118
+
119
+ function folderPickerSelectItem(entry) {
120
+ folderPickerSelected.value = entry.name;
121
+ }
122
+
123
+ function folderPickerEnter(entry) {
124
+ const sep = folderPickerPath.value.includes('\\') || /^[A-Z]:/.test(entry.name) ? '\\' : '/';
125
+ let newPath;
126
+ if (!folderPickerPath.value) {
127
+ newPath = entry.name + (entry.name.endsWith('\\') ? '' : '\\');
128
+ } else {
129
+ newPath = folderPickerPath.value.replace(/[/\\]$/, '') + sep + entry.name;
130
+ }
131
+ folderPickerPath.value = newPath;
132
+ folderPickerSelected.value = '';
133
+ loadFolderPickerDir(newPath);
134
+ }
135
+
136
+ function folderPickerGoToPath() {
137
+ const path = folderPickerPath.value.trim();
138
+ if (!path) {
139
+ loadFolderPickerDir('');
140
+ return;
141
+ }
142
+ folderPickerSelected.value = '';
143
+ loadFolderPickerDir(path);
144
+ }
145
+
146
+ function confirmFolderPicker() {
147
+ let path = folderPickerPath.value;
148
+ if (!path) return;
149
+ if (folderPickerSelected.value) {
150
+ const sep = path.includes('\\') ? '\\' : '/';
151
+ path = path.replace(/[/\\]$/, '') + sep + folderPickerSelected.value;
152
+ }
153
+ folderPickerOpen.value = false;
154
+ wsSend({ type: 'change_workdir', workDir: path });
155
+ }
156
+
157
+ // ── Grouped sessions ──
158
+
159
+ const groupedSessions = computed(() => {
160
+ if (!historySessions.value.length) return [];
161
+ const now = new Date();
162
+ const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
163
+ const yesterdayStart = todayStart - 86400000;
164
+ const weekStart = todayStart - 6 * 86400000;
165
+
166
+ const groups = {};
167
+ for (const s of historySessions.value) {
168
+ let label;
169
+ if (s.lastModified >= todayStart) label = 'Today';
170
+ else if (s.lastModified >= yesterdayStart) label = 'Yesterday';
171
+ else if (s.lastModified >= weekStart) label = 'This week';
172
+ else label = 'Earlier';
173
+ if (!groups[label]) groups[label] = [];
174
+ groups[label].push(s);
175
+ }
176
+ const order = ['Today', 'Yesterday', 'This week', 'Earlier'];
177
+ return order.filter(k => groups[k]).map(k => ({ label: k, sessions: groups[k] }));
178
+ });
179
+
180
+ return {
181
+ requestSessionList, resumeSession, newConversation, toggleSidebar,
182
+ openFolderPicker, folderPickerNavigateUp, folderPickerSelectItem,
183
+ folderPickerEnter, folderPickerGoToPath, confirmFolderPicker,
184
+ groupedSessions,
185
+ };
186
+ }