@myrialabs/clopen 0.2.14 → 0.2.16
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/backend/engine/adapters/opencode/server.ts +72 -33
- package/backend/snapshot/helpers.ts +8 -0
- package/backend/tunnel/cloudflared/binary.ts +153 -0
- package/backend/tunnel/cloudflared/index.ts +21 -0
- package/backend/tunnel/cloudflared/tunnel.ts +389 -0
- package/backend/tunnel/global-tunnel-manager.ts +538 -152
- package/backend/tunnel/project-tunnel-manager.ts +6 -14
- package/backend/tunnel/tunnel-config.ts +234 -0
- package/backend/ws/tunnel/config.ts +108 -0
- package/backend/ws/tunnel/index.ts +3 -1
- package/backend/ws/tunnel/operations.ts +290 -43
- package/bin/clopen.ts +1 -1
- package/bun.lock +0 -4
- package/frontend/App.svelte +2 -1
- package/frontend/components/chat/ChatInterface.svelte +6 -1
- package/frontend/components/chat/formatters/Tools.svelte +3 -1
- package/frontend/components/chat/input/components/EngineModelPicker.svelte +12 -1
- package/frontend/components/chat/message/ChatMessage.svelte +0 -29
- package/frontend/components/chat/message/ChatMessages.svelte +2 -2
- package/frontend/components/chat/message/MessageBubble.svelte +0 -6
- package/frontend/components/chat/message/MessageHeader.svelte +0 -16
- package/frontend/components/chat/tools/SkillTool.svelte +21 -0
- package/frontend/components/chat/tools/index.ts +1 -0
- package/frontend/components/chat/widgets/ContextIndicator.svelte +186 -0
- package/frontend/components/history/HistoryModal.svelte +3 -3
- package/frontend/components/settings/SettingsModal.svelte +5 -0
- package/frontend/components/settings/SettingsView.svelte +4 -0
- package/frontend/components/settings/model/EngineModelPicker.svelte +9 -0
- package/frontend/components/settings/tunnel/TunnelSettings.svelte +1060 -0
- package/frontend/components/tunnel/TunnelActive.svelte +132 -71
- package/frontend/components/tunnel/TunnelButton.svelte +4 -4
- package/frontend/components/tunnel/TunnelInactive.svelte +38 -65
- package/frontend/components/tunnel/TunnelModal.svelte +55 -2
- package/frontend/components/workspace/PanelHeader.svelte +4 -0
- package/frontend/components/workspace/WorkspaceLayout.svelte +31 -1
- package/frontend/components/workspace/panels/ChatPanel.svelte +6 -0
- package/frontend/services/favicon.service.ts +103 -0
- package/frontend/services/terminal/project.service.ts +52 -0
- package/frontend/stores/features/tunnel-config.svelte.ts +205 -0
- package/frontend/stores/features/tunnel.svelte.ts +194 -80
- package/frontend/stores/ui/settings-modal.svelte.ts +7 -0
- package/frontend/utils/chat/message-grouper.ts +33 -5
- package/frontend/utils/chat/message-processor.ts +2 -1
- package/frontend/utils/chat/tool-handler.ts +38 -3
- package/frontend/utils/context-manager.ts +35 -237
- package/package.json +1 -2
- package/shared/types/messaging/index.ts +1 -0
- package/shared/types/messaging/tool.ts +24 -1
- package/shared/utils/ws-client.ts +23 -1
- package/frontend/components/chat/modal/TokenUsageModal.svelte +0 -124
- package/frontend/components/chat/widgets/TokenUsage.svelte +0 -78
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { chatService } from '$frontend/services/chat/chat.service';
|
|
17
17
|
import { setSkipNextRestore } from '$frontend/stores/ui/chat-input.svelte';
|
|
18
18
|
import { userStore } from '$frontend/stores/features/user.svelte';
|
|
19
|
+
import { cancelEdit, editModeState } from '$frontend/stores/ui/edit-mode.svelte';
|
|
19
20
|
|
|
20
21
|
// Props
|
|
21
22
|
interface Props {
|
|
@@ -147,6 +148,11 @@
|
|
|
147
148
|
return;
|
|
148
149
|
}
|
|
149
150
|
|
|
151
|
+
// Clear edit mode if active
|
|
152
|
+
if (editModeState.isEditing) {
|
|
153
|
+
cancelEdit();
|
|
154
|
+
}
|
|
155
|
+
|
|
150
156
|
// Reset frontend state without killing the backend stream
|
|
151
157
|
// The old session's stream continues running in the background
|
|
152
158
|
if (appState.isLoading) {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Favicon Badge Service
|
|
3
|
+
*
|
|
4
|
+
* Dynamically renders a badge on the favicon showing the count of
|
|
5
|
+
* non-idle status indicators across all projects (streaming, waiting
|
|
6
|
+
* input, unread).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { debug } from '$shared/utils/logger';
|
|
10
|
+
|
|
11
|
+
const FAVICON_HREF = '/favicon.svg';
|
|
12
|
+
const BADGE_COLOR = '#000000';
|
|
13
|
+
const BADGE_TEXT_COLOR = '#FFFFFF';
|
|
14
|
+
const ICON_SIZE = 128; // canvas resolution — higher for crisp badge text
|
|
15
|
+
|
|
16
|
+
let originalIconUrl: string | null = null;
|
|
17
|
+
let currentCount = -1; // -1 = not yet rendered
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Update the favicon badge.
|
|
21
|
+
* Renders the original SVG favicon with an optional numeric badge
|
|
22
|
+
* in the bottom-right corner.
|
|
23
|
+
*
|
|
24
|
+
* @param count Number of active indicators (0 = remove badge)
|
|
25
|
+
*/
|
|
26
|
+
export function updateFaviconBadge(count: number): void {
|
|
27
|
+
// Avoid unnecessary re-renders
|
|
28
|
+
if (count === currentCount) return;
|
|
29
|
+
currentCount = count;
|
|
30
|
+
|
|
31
|
+
if (count <= 0) {
|
|
32
|
+
restoreOriginalFavicon();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const img = new Image();
|
|
37
|
+
img.onload = () => {
|
|
38
|
+
try {
|
|
39
|
+
const canvas = document.createElement('canvas');
|
|
40
|
+
canvas.width = ICON_SIZE;
|
|
41
|
+
canvas.height = ICON_SIZE;
|
|
42
|
+
const ctx = canvas.getContext('2d');
|
|
43
|
+
if (!ctx) return;
|
|
44
|
+
|
|
45
|
+
// Draw original favicon
|
|
46
|
+
ctx.drawImage(img, 0, 0, ICON_SIZE, ICON_SIZE);
|
|
47
|
+
|
|
48
|
+
// Badge text with outline (bottom-right)
|
|
49
|
+
const displayText = count > 9 ? '9+' : String(count);
|
|
50
|
+
const fontSize = count > 9 ? 56 : 64;
|
|
51
|
+
const textX = ICON_SIZE - (count > 9 ? 32 : 24);
|
|
52
|
+
const textY = ICON_SIZE - 20;
|
|
53
|
+
|
|
54
|
+
ctx.font = `bold ${fontSize}px sans-serif`;
|
|
55
|
+
ctx.textAlign = 'center';
|
|
56
|
+
ctx.textBaseline = 'middle';
|
|
57
|
+
|
|
58
|
+
// Black outline
|
|
59
|
+
ctx.strokeStyle = BADGE_COLOR;
|
|
60
|
+
ctx.lineWidth = 14;
|
|
61
|
+
ctx.lineJoin = 'round';
|
|
62
|
+
ctx.strokeText(displayText, textX, textY);
|
|
63
|
+
|
|
64
|
+
// White fill
|
|
65
|
+
ctx.fillStyle = BADGE_TEXT_COLOR;
|
|
66
|
+
ctx.fillText(displayText, textX, textY);
|
|
67
|
+
|
|
68
|
+
// Apply to favicon
|
|
69
|
+
const dataUrl = canvas.toDataURL('image/png');
|
|
70
|
+
setFaviconHref(dataUrl);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
debug.error('workspace', 'Failed to render favicon badge:', err);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
img.onerror = () => {
|
|
77
|
+
debug.error('workspace', 'Failed to load favicon SVG for badge rendering');
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
img.src = FAVICON_HREF;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function setFaviconHref(href: string): void {
|
|
84
|
+
let link = document.querySelector<HTMLLinkElement>('link[rel="icon"]');
|
|
85
|
+
if (!link) {
|
|
86
|
+
link = document.createElement('link');
|
|
87
|
+
link.rel = 'icon';
|
|
88
|
+
document.head.appendChild(link);
|
|
89
|
+
}
|
|
90
|
+
if (!originalIconUrl) {
|
|
91
|
+
originalIconUrl = FAVICON_HREF;
|
|
92
|
+
}
|
|
93
|
+
link.href = href;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function restoreOriginalFavicon(): void {
|
|
97
|
+
if (originalIconUrl) {
|
|
98
|
+
const link = document.querySelector<HTMLLinkElement>('link[rel="icon"]');
|
|
99
|
+
if (link) {
|
|
100
|
+
link.href = originalIconUrl;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -9,6 +9,7 @@ import { terminalStore } from '$frontend/stores/features/terminal.svelte';
|
|
|
9
9
|
import type { TerminalSession } from '$shared/types/terminal';
|
|
10
10
|
import { terminalService } from './terminal.service';
|
|
11
11
|
import { debug } from '$shared/utils/logger';
|
|
12
|
+
import { onWsReconnect } from '$frontend/utils/ws';
|
|
12
13
|
interface ProjectTerminalContext {
|
|
13
14
|
projectId: string;
|
|
14
15
|
projectPath: string;
|
|
@@ -838,6 +839,57 @@ class TerminalProjectManager {
|
|
|
838
839
|
|
|
839
840
|
debug.log('terminal', '✅ Terminal collaborative listeners registered');
|
|
840
841
|
});
|
|
842
|
+
|
|
843
|
+
// Validate terminal sessions after WebSocket reconnect.
|
|
844
|
+
// When the server restarts, all PTY sessions die. We need to detect
|
|
845
|
+
// dead tabs and clean them up, then auto-create a fresh session.
|
|
846
|
+
onWsReconnect(() => {
|
|
847
|
+
this.validateSessionsAfterReconnect();
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* After WebSocket reconnects, check which terminal sessions are still
|
|
853
|
+
* alive on the backend. Remove dead tabs and auto-create a new one
|
|
854
|
+
* if none remain.
|
|
855
|
+
*/
|
|
856
|
+
private async validateSessionsAfterReconnect(): Promise<void> {
|
|
857
|
+
if (!this.currentProjectId) return;
|
|
858
|
+
const context = this.projectContexts.get(this.currentProjectId);
|
|
859
|
+
if (!context || context.sessionIds.length === 0) return;
|
|
860
|
+
|
|
861
|
+
debug.log('terminal', 'Validating terminal sessions after reconnect...');
|
|
862
|
+
|
|
863
|
+
try {
|
|
864
|
+
// Query backend for alive PTY sessions
|
|
865
|
+
const aliveSessions = await terminalService.listProjectSessions(this.currentProjectId);
|
|
866
|
+
const aliveSessionIds = new Set(aliveSessions.map(s => s.sessionId));
|
|
867
|
+
|
|
868
|
+
// Find dead sessions (in UI but not on backend)
|
|
869
|
+
const deadSessionIds = context.sessionIds.filter(id => !aliveSessionIds.has(id));
|
|
870
|
+
|
|
871
|
+
if (deadSessionIds.length === 0) {
|
|
872
|
+
debug.log('terminal', 'All terminal sessions still alive after reconnect');
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
debug.log('terminal', `Found ${deadSessionIds.length} dead terminal session(s) after reconnect, cleaning up`);
|
|
877
|
+
|
|
878
|
+
// Remove dead sessions from context and store
|
|
879
|
+
for (const sessionId of deadSessionIds) {
|
|
880
|
+
this.removeSessionFromContext(sessionId);
|
|
881
|
+
terminalStore.removeSessionFromStore(sessionId);
|
|
882
|
+
terminalService.cleanupListeners(sessionId);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// If no sessions remain, auto-create a new one
|
|
886
|
+
if (context.sessionIds.length === 0) {
|
|
887
|
+
debug.log('terminal', 'All terminal sessions dead after reconnect, creating new session');
|
|
888
|
+
await this.createProjectTerminalSessions(this.currentProjectId, context.projectPath);
|
|
889
|
+
}
|
|
890
|
+
} catch (err) {
|
|
891
|
+
debug.error('terminal', 'Failed to validate terminal sessions after reconnect:', err);
|
|
892
|
+
}
|
|
841
893
|
}
|
|
842
894
|
|
|
843
895
|
/**
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tunnel Config Store
|
|
3
|
+
* Manages Cloudflare Tunnel configurations (remote + local)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { debug } from '$shared/utils/logger';
|
|
7
|
+
import ws from '$frontend/utils/ws';
|
|
8
|
+
|
|
9
|
+
// --- Remote (dashboard-managed) ---
|
|
10
|
+
|
|
11
|
+
export interface RemoteIngressRule {
|
|
12
|
+
hostname?: string;
|
|
13
|
+
service: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RemoteConfigItem {
|
|
17
|
+
id: string;
|
|
18
|
+
label: string;
|
|
19
|
+
isActive: boolean;
|
|
20
|
+
ingress: RemoteIngressRule[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// --- Local (locally-managed) ---
|
|
24
|
+
|
|
25
|
+
export interface LocalTunnelIngressRule {
|
|
26
|
+
hostname: string;
|
|
27
|
+
service: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface LocalConfigItem {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
tunnelId: string;
|
|
34
|
+
ingress: LocalTunnelIngressRule[];
|
|
35
|
+
isActive: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// --- State ---
|
|
39
|
+
|
|
40
|
+
interface TunnelConfigState {
|
|
41
|
+
remotes: RemoteConfigItem[];
|
|
42
|
+
locals: LocalConfigItem[];
|
|
43
|
+
isLoading: boolean;
|
|
44
|
+
isSaving: boolean;
|
|
45
|
+
error: string | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const state = $state<TunnelConfigState>({
|
|
49
|
+
remotes: [],
|
|
50
|
+
locals: [],
|
|
51
|
+
isLoading: false,
|
|
52
|
+
isSaving: false,
|
|
53
|
+
error: null
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const tunnelConfigStore = {
|
|
57
|
+
get remotes() { return state.remotes; },
|
|
58
|
+
get hasRemotes() { return state.remotes.length > 0; },
|
|
59
|
+
get locals() { return state.locals; },
|
|
60
|
+
get hasLocals() { return state.locals.length > 0; },
|
|
61
|
+
get isLoading() { return state.isLoading; },
|
|
62
|
+
get isSaving() { return state.isSaving; },
|
|
63
|
+
get error() { return state.error; },
|
|
64
|
+
|
|
65
|
+
// --- Remote ---
|
|
66
|
+
|
|
67
|
+
async refreshRemotes() {
|
|
68
|
+
state.isLoading = true;
|
|
69
|
+
state.error = null;
|
|
70
|
+
try {
|
|
71
|
+
const result = await ws.http('tunnel:remote:config:list', {});
|
|
72
|
+
state.remotes = result.configs ?? [];
|
|
73
|
+
} catch (error) {
|
|
74
|
+
debug.error('tunnel', 'Failed to load remote configs:', error);
|
|
75
|
+
state.error = error instanceof Error ? error.message : 'Failed to load configs';
|
|
76
|
+
}
|
|
77
|
+
state.isLoading = false;
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
async addRemote(label: string, token: string) {
|
|
81
|
+
state.isSaving = true;
|
|
82
|
+
state.error = null;
|
|
83
|
+
try {
|
|
84
|
+
const result = await ws.http('tunnel:remote:config:add', { label, token });
|
|
85
|
+
state.remotes.push({ id: result.id, label: result.label, isActive: false, ingress: [] });
|
|
86
|
+
} catch (error) {
|
|
87
|
+
debug.error('tunnel', 'Failed to add remote config:', error);
|
|
88
|
+
state.error = error instanceof Error ? error.message : 'Failed to add config';
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
state.isSaving = false;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
async removeRemote(id: string) {
|
|
95
|
+
state.isSaving = true;
|
|
96
|
+
state.error = null;
|
|
97
|
+
try {
|
|
98
|
+
await ws.http('tunnel:remote:config:remove', { id });
|
|
99
|
+
state.remotes = state.remotes.filter((c) => c.id !== id);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
debug.error('tunnel', 'Failed to remove remote config:', error);
|
|
102
|
+
state.error = error instanceof Error ? error.message : 'Failed to remove config';
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
state.isSaving = false;
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
setRemoteActive(id: string, isActive: boolean) {
|
|
109
|
+
const item = state.remotes.find((c) => c.id === id);
|
|
110
|
+
if (item) item.isActive = isActive;
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
updateRemoteIngress(id: string, ingress: RemoteIngressRule[]) {
|
|
114
|
+
const item = state.remotes.find((c) => c.id === id);
|
|
115
|
+
if (item) item.ingress = ingress;
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
// --- Local ---
|
|
119
|
+
|
|
120
|
+
async refreshLocals() {
|
|
121
|
+
state.isLoading = true;
|
|
122
|
+
state.error = null;
|
|
123
|
+
try {
|
|
124
|
+
const result = await ws.http('tunnel:local:config:list', {});
|
|
125
|
+
state.locals = result.configs ?? [];
|
|
126
|
+
} catch (error) {
|
|
127
|
+
debug.error('tunnel', 'Failed to load local configs:', error);
|
|
128
|
+
state.error = error instanceof Error ? error.message : 'Failed to load configs';
|
|
129
|
+
}
|
|
130
|
+
state.isLoading = false;
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
async createLocal(name: string) {
|
|
134
|
+
state.isSaving = true;
|
|
135
|
+
state.error = null;
|
|
136
|
+
try {
|
|
137
|
+
const result = await ws.http('tunnel:local:create', { name });
|
|
138
|
+
state.locals.push({
|
|
139
|
+
id: result.id,
|
|
140
|
+
name: result.name,
|
|
141
|
+
tunnelId: result.tunnelId,
|
|
142
|
+
ingress: [],
|
|
143
|
+
isActive: false
|
|
144
|
+
});
|
|
145
|
+
return result;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
debug.error('tunnel', 'Failed to create local tunnel:', error);
|
|
148
|
+
state.error = error instanceof Error ? error.message : 'Failed to create tunnel';
|
|
149
|
+
throw error;
|
|
150
|
+
} finally {
|
|
151
|
+
state.isSaving = false;
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
async deleteLocal(id: string) {
|
|
156
|
+
state.isSaving = true;
|
|
157
|
+
state.error = null;
|
|
158
|
+
try {
|
|
159
|
+
await ws.http('tunnel:local:delete', { id });
|
|
160
|
+
state.locals = state.locals.filter((c) => c.id !== id);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
debug.error('tunnel', 'Failed to delete local tunnel:', error);
|
|
163
|
+
state.error = error instanceof Error ? error.message : 'Failed to delete tunnel';
|
|
164
|
+
throw error;
|
|
165
|
+
} finally {
|
|
166
|
+
state.isSaving = false;
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
async addIngress(id: string, hostname: string, service: string): Promise<{ dnsRouted: boolean; dnsError: string | null }> {
|
|
171
|
+
state.error = null;
|
|
172
|
+
try {
|
|
173
|
+
const result = await ws.http('tunnel:local:ingress:add', { id, hostname, service });
|
|
174
|
+
const config = state.locals.find((c) => c.id === id);
|
|
175
|
+
if (config) config.ingress = result.ingress;
|
|
176
|
+
return { dnsRouted: result.dnsRouted ?? false, dnsError: result.dnsError ?? null };
|
|
177
|
+
} catch (error) {
|
|
178
|
+
debug.error('tunnel', 'Failed to add subdomain:', error);
|
|
179
|
+
state.error = error instanceof Error ? error.message : 'Failed to add subdomain';
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
async removeIngress(id: string, hostname: string) {
|
|
185
|
+
state.error = null;
|
|
186
|
+
try {
|
|
187
|
+
const result = await ws.http('tunnel:local:ingress:remove', { id, hostname });
|
|
188
|
+
const config = state.locals.find((c) => c.id === id);
|
|
189
|
+
if (config) config.ingress = result.ingress;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
debug.error('tunnel', 'Failed to remove domain:', error);
|
|
192
|
+
state.error = error instanceof Error ? error.message : 'Failed to remove domain';
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
setLocalActive(id: string, isActive: boolean) {
|
|
198
|
+
const item = state.locals.find((c) => c.id === id);
|
|
199
|
+
if (item) item.isActive = isActive;
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
async refresh() {
|
|
203
|
+
await Promise.all([this.refreshRemotes(), this.refreshLocals()]);
|
|
204
|
+
}
|
|
205
|
+
};
|