@myrialabs/clopen 0.2.15 → 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/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/bun.lock +0 -4
- package/frontend/App.svelte +2 -1
- package/frontend/components/settings/SettingsModal.svelte +5 -0
- package/frontend/components/settings/SettingsView.svelte +4 -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/WorkspaceLayout.svelte +31 -1
- package/frontend/services/favicon.service.ts +103 -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/package.json +1 -2
|
@@ -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
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tunnel Store
|
|
3
|
-
* Manages cloudflared tunnel state
|
|
3
|
+
* Manages cloudflared tunnel runtime state (active tunnels, progress, errors)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { debug } from '$shared/utils/logger';
|
|
7
7
|
import ws from '$frontend/utils/ws';
|
|
8
8
|
|
|
9
|
+
type TunnelType = 'quick' | 'remote' | 'local';
|
|
10
|
+
|
|
9
11
|
type TunnelProgress =
|
|
10
12
|
| { stage: 'idle' }
|
|
11
13
|
| { stage: 'checking-binary' }
|
|
@@ -16,14 +18,23 @@ type TunnelProgress =
|
|
|
16
18
|
| { stage: 'connected' }
|
|
17
19
|
| { stage: 'failed'; error: string };
|
|
18
20
|
|
|
21
|
+
interface IngressInfo {
|
|
22
|
+
hostname?: string;
|
|
23
|
+
service: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
interface TunnelInfo {
|
|
20
27
|
port: number;
|
|
21
28
|
publicUrl: string;
|
|
22
29
|
startedAt: string;
|
|
23
30
|
autoStopMinutes: number;
|
|
31
|
+
type: TunnelType;
|
|
32
|
+
label?: string;
|
|
33
|
+
configId?: string;
|
|
34
|
+
ingress?: IngressInfo[];
|
|
24
35
|
}
|
|
25
36
|
|
|
26
|
-
interface
|
|
37
|
+
interface LoadingState {
|
|
27
38
|
isLoading: boolean;
|
|
28
39
|
error: string | null;
|
|
29
40
|
progress: TunnelProgress;
|
|
@@ -31,133 +42,236 @@ interface PortState {
|
|
|
31
42
|
|
|
32
43
|
interface TunnelState {
|
|
33
44
|
tunnels: TunnelInfo[];
|
|
34
|
-
|
|
45
|
+
loadingStates: Record<string, LoadingState>;
|
|
35
46
|
}
|
|
36
47
|
|
|
37
|
-
// Tunnel store state
|
|
38
48
|
const tunnelState = $state<TunnelState>({
|
|
39
49
|
tunnels: [],
|
|
40
|
-
|
|
50
|
+
loadingStates: {}
|
|
41
51
|
});
|
|
42
52
|
|
|
53
|
+
function setLoading(key: string): void {
|
|
54
|
+
tunnelState.loadingStates[key] = {
|
|
55
|
+
isLoading: true,
|
|
56
|
+
error: null,
|
|
57
|
+
progress: { stage: 'starting-tunnel' }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function setConnected(key: string): void {
|
|
62
|
+
if (tunnelState.loadingStates[key]) {
|
|
63
|
+
tunnelState.loadingStates[key].progress = { stage: 'connected' };
|
|
64
|
+
tunnelState.loadingStates[key].isLoading = false;
|
|
65
|
+
}
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
if (tunnelState.loadingStates[key]) {
|
|
68
|
+
tunnelState.loadingStates[key].progress = { stage: 'idle' };
|
|
69
|
+
}
|
|
70
|
+
}, 1500);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function setFailed(key: string, error: string): void {
|
|
74
|
+
if (tunnelState.loadingStates[key]) {
|
|
75
|
+
tunnelState.loadingStates[key].error = error;
|
|
76
|
+
tunnelState.loadingStates[key].progress = { stage: 'failed', error };
|
|
77
|
+
tunnelState.loadingStates[key].isLoading = false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
43
81
|
export const tunnelStore = {
|
|
44
82
|
get tunnels() {
|
|
45
83
|
return tunnelState.tunnels;
|
|
46
84
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
85
|
+
|
|
86
|
+
get activeDomainCount() {
|
|
87
|
+
let count = 0;
|
|
88
|
+
for (const tunnel of tunnelState.tunnels) {
|
|
89
|
+
const hostRules = tunnel.ingress?.filter((r) => r.hostname) ?? [];
|
|
90
|
+
count += hostRules.length > 0 ? hostRules.length : (tunnel.publicUrl ? 1 : 0);
|
|
91
|
+
}
|
|
92
|
+
return count;
|
|
52
93
|
},
|
|
53
|
-
|
|
54
|
-
|
|
94
|
+
|
|
95
|
+
getLoadingState(key: string): LoadingState {
|
|
96
|
+
return tunnelState.loadingStates[key] ?? { isLoading: false, error: null, progress: { stage: 'idle' } };
|
|
55
97
|
},
|
|
98
|
+
|
|
56
99
|
getTunnel(port: number) {
|
|
57
|
-
return tunnelState.tunnels.find((t) => t.port === port)
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* Start tunnel globally
|
|
62
|
-
* Note: First time may take 30-90 seconds (downloading binary + starting tunnel)
|
|
63
|
-
*/
|
|
64
|
-
async startTunnel(port: number, autoStopMinutes?: number) {
|
|
65
|
-
// Initialize port state
|
|
66
|
-
tunnelState.portStates[port] = {
|
|
67
|
-
isLoading: true,
|
|
68
|
-
error: null,
|
|
69
|
-
progress: { stage: 'starting-tunnel' }
|
|
70
|
-
};
|
|
100
|
+
return tunnelState.tunnels.find((t) => t.port === port && t.type === 'quick') ?? null;
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
// --- Quick tunnel ---
|
|
71
104
|
|
|
72
|
-
|
|
105
|
+
async startQuickTunnel(port: number, autoStopMinutes?: number) {
|
|
106
|
+
const key = String(port);
|
|
107
|
+
setLoading(key);
|
|
73
108
|
|
|
74
109
|
try {
|
|
75
|
-
|
|
76
|
-
const result = await ws.http('tunnel:start', { port, autoStopMinutes });
|
|
110
|
+
const result = await ws.http('tunnel:quick:start', { port, autoStopMinutes });
|
|
77
111
|
|
|
78
|
-
if (!result
|
|
79
|
-
throw new Error('No result received from server');
|
|
80
|
-
}
|
|
112
|
+
if (!result?.publicUrl) throw new Error('No result received from server');
|
|
81
113
|
|
|
82
|
-
// Add tunnel to the list
|
|
83
114
|
tunnelState.tunnels.push({
|
|
84
115
|
port,
|
|
85
116
|
publicUrl: result.publicUrl,
|
|
86
117
|
startedAt: new Date().toISOString(),
|
|
87
|
-
autoStopMinutes: autoStopMinutes
|
|
118
|
+
autoStopMinutes: autoStopMinutes ?? 60,
|
|
119
|
+
type: 'quick'
|
|
88
120
|
});
|
|
89
121
|
|
|
90
|
-
|
|
91
|
-
|
|
122
|
+
setConnected(key);
|
|
123
|
+
debug.log('tunnel', `Quick tunnel started on port ${port}: ${result.publicUrl}`);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
126
|
+
setFailed(key, msg);
|
|
127
|
+
debug.error('tunnel', 'Quick tunnel error:', msg);
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
},
|
|
92
131
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
132
|
+
async stopQuickTunnel(port: number) {
|
|
133
|
+
try {
|
|
134
|
+
const response = await ws.http('tunnel:quick:stop', { port });
|
|
135
|
+
if (!response.stopped) throw new Error('Failed to stop tunnel');
|
|
97
136
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
}, 1500);
|
|
137
|
+
tunnelState.tunnels = tunnelState.tunnels.filter(
|
|
138
|
+
(t) => !(t.port === port && t.type === 'quick')
|
|
139
|
+
);
|
|
140
|
+
delete tunnelState.loadingStates[String(port)];
|
|
104
141
|
} catch (error) {
|
|
105
|
-
|
|
106
|
-
tunnelState.portStates[port].error = error.message;
|
|
107
|
-
tunnelState.portStates[port].progress = { stage: 'failed', error: error.message };
|
|
108
|
-
debug.error('tunnel', '[Frontend] Error:', error.message);
|
|
109
|
-
} else {
|
|
110
|
-
const errorMsg = 'Unknown error';
|
|
111
|
-
tunnelState.portStates[port].error = errorMsg;
|
|
112
|
-
tunnelState.portStates[port].progress = { stage: 'failed', error: errorMsg };
|
|
113
|
-
debug.error('tunnel', '[Frontend] Unknown error:', error);
|
|
114
|
-
}
|
|
115
|
-
tunnelState.portStates[port].isLoading = false;
|
|
142
|
+
debug.error('tunnel', 'Failed to stop quick tunnel:', error);
|
|
116
143
|
throw error;
|
|
117
144
|
}
|
|
118
145
|
},
|
|
119
146
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
147
|
+
// --- Remote tunnel ---
|
|
148
|
+
|
|
149
|
+
async startRemoteTunnel(configId: string) {
|
|
150
|
+
setLoading(configId);
|
|
151
|
+
|
|
124
152
|
try {
|
|
125
|
-
|
|
153
|
+
await ws.http('tunnel:remote:start', { configId });
|
|
154
|
+
setConnected(configId);
|
|
155
|
+
debug.log('tunnel', `Remote tunnel started: ${configId}`);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
158
|
+
setFailed(configId, msg);
|
|
159
|
+
debug.error('tunnel', 'Remote tunnel error:', msg);
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
},
|
|
126
163
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
164
|
+
async stopRemoteTunnel(configId: string) {
|
|
165
|
+
try {
|
|
166
|
+
const response = await ws.http('tunnel:remote:stop', { configId });
|
|
167
|
+
if (!response.stopped) throw new Error('Failed to stop tunnel');
|
|
130
168
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
169
|
+
tunnelState.tunnels = tunnelState.tunnels.filter(
|
|
170
|
+
(t) => !(t.configId === configId && t.type === 'remote')
|
|
171
|
+
);
|
|
172
|
+
delete tunnelState.loadingStates[configId];
|
|
173
|
+
} catch (error) {
|
|
174
|
+
debug.error('tunnel', 'Failed to stop remote tunnel:', error);
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
// --- Local tunnel ---
|
|
180
|
+
|
|
181
|
+
async startLocalTunnel(configId: string) {
|
|
182
|
+
setLoading(configId);
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
await ws.http('tunnel:local:start', { id: configId });
|
|
186
|
+
setConnected(configId);
|
|
187
|
+
debug.log('tunnel', `Local tunnel started: ${configId}`);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
190
|
+
setFailed(configId, msg);
|
|
191
|
+
debug.error('tunnel', 'Local tunnel error:', msg);
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
async stopLocalTunnel(configId: string) {
|
|
197
|
+
try {
|
|
198
|
+
const response = await ws.http('tunnel:local:stop', { id: configId });
|
|
199
|
+
if (!response.stopped) throw new Error('Failed to stop tunnel');
|
|
134
200
|
|
|
135
|
-
|
|
201
|
+
tunnelState.tunnels = tunnelState.tunnels.filter(
|
|
202
|
+
(t) => !(t.configId === configId && t.type === 'local')
|
|
203
|
+
);
|
|
204
|
+
delete tunnelState.loadingStates[configId];
|
|
136
205
|
} catch (error) {
|
|
137
|
-
debug.error('tunnel', 'Failed to stop tunnel:', error);
|
|
206
|
+
debug.error('tunnel', 'Failed to stop local tunnel:', error);
|
|
138
207
|
throw error;
|
|
139
208
|
}
|
|
140
209
|
},
|
|
141
210
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
211
|
+
// --- Local auth ---
|
|
212
|
+
|
|
213
|
+
async checkAuth(): Promise<{ authenticated: boolean; certPath: string; zone: string | null }> {
|
|
214
|
+
return await ws.http('tunnel:local:auth-status', {});
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
async logout(): Promise<void> {
|
|
218
|
+
await ws.http('tunnel:local:logout', {});
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
async setZone(zone: string): Promise<void> {
|
|
222
|
+
await ws.http('tunnel:local:set-zone', { zone });
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
startLogin() {
|
|
226
|
+
ws.emit('tunnel:local:login-start', {});
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
cancelLogin() {
|
|
230
|
+
ws.emit('tunnel:local:login-cancel', {});
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
// --- Status ---
|
|
234
|
+
|
|
145
235
|
async checkStatus() {
|
|
146
236
|
try {
|
|
147
237
|
const response = await ws.http('tunnel:status', {});
|
|
148
|
-
|
|
149
|
-
// Update tunnels list from server
|
|
150
|
-
tunnelState.tunnels = response.tunnels || [];
|
|
238
|
+
tunnelState.tunnels = response.tunnels ?? [];
|
|
151
239
|
} catch (error) {
|
|
152
240
|
debug.error('tunnel', 'Failed to check tunnel status:', error);
|
|
153
241
|
}
|
|
154
242
|
},
|
|
155
243
|
|
|
156
|
-
/**
|
|
157
|
-
* Reset tunnel state
|
|
158
|
-
*/
|
|
159
244
|
reset() {
|
|
160
245
|
tunnelState.tunnels = [];
|
|
161
|
-
tunnelState.
|
|
246
|
+
tunnelState.loadingStates = {};
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
/** Update ingress for a specific tunnel (used by remote ingress-update events) */
|
|
250
|
+
updateTunnelIngress(configId: string, ingress: IngressInfo[]) {
|
|
251
|
+
const tunnel = tunnelState.tunnels.find((t) => t.configId === configId);
|
|
252
|
+
if (tunnel) {
|
|
253
|
+
tunnel.ingress = ingress;
|
|
254
|
+
// Also update publicUrl from first hostname
|
|
255
|
+
const firstHostname = ingress.find((r) => r.hostname)?.hostname;
|
|
256
|
+
if (firstHostname) {
|
|
257
|
+
tunnel.publicUrl = `https://${firstHostname}`;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
/** Initialize realtime tunnel status listener. Call once on app mount. */
|
|
263
|
+
initRealtimeListener() {
|
|
264
|
+
const cleanupStatus = ws.on('tunnel:status-changed', (data: { tunnels: TunnelInfo[] }) => {
|
|
265
|
+
tunnelState.tunnels = data.tunnels;
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const cleanupIngress = ws.on('tunnel:remote:ingress-update', (data: { configId: string; ingress: IngressInfo[] }) => {
|
|
269
|
+
tunnelStore.updateTunnelIngress(data.configId, data.ingress);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
return () => {
|
|
273
|
+
cleanupStatus();
|
|
274
|
+
cleanupIngress();
|
|
275
|
+
};
|
|
162
276
|
}
|
|
163
277
|
};
|
|
@@ -10,6 +10,7 @@ export type SettingsSection =
|
|
|
10
10
|
| 'engines'
|
|
11
11
|
| 'appearance'
|
|
12
12
|
| 'notifications'
|
|
13
|
+
| 'tunnel'
|
|
13
14
|
| 'account'
|
|
14
15
|
| 'team'
|
|
15
16
|
| 'security'
|
|
@@ -48,6 +49,12 @@ export const settingsSections: SettingsSectionMeta[] = [
|
|
|
48
49
|
icon: 'lucide:bell',
|
|
49
50
|
description: 'Sound and push notifications'
|
|
50
51
|
},
|
|
52
|
+
{
|
|
53
|
+
id: 'tunnel',
|
|
54
|
+
label: 'Tunnel',
|
|
55
|
+
icon: 'lucide:globe',
|
|
56
|
+
description: 'Cloudflare tunnel services'
|
|
57
|
+
},
|
|
51
58
|
{
|
|
52
59
|
id: 'account',
|
|
53
60
|
label: 'User Profile',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myrialabs/clopen",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"description": "All-in-one web workspace for Claude Code & OpenCode — chat, terminal, git, browser preview, checkpoints, and real-time collaboration",
|
|
5
5
|
"author": "Myria Labs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -92,7 +92,6 @@
|
|
|
92
92
|
"@xterm/headless": "^6.0.0",
|
|
93
93
|
"@xterm/xterm": "^6.0.0",
|
|
94
94
|
"bun-pty": "^0.4.2",
|
|
95
|
-
"cloudflared": "^0.7.1",
|
|
96
95
|
"elysia": "^1.4.19",
|
|
97
96
|
"file-type": "^21.0.0",
|
|
98
97
|
"is-text-path": "^3.0.0",
|