-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWorkspaceSettingsPanel.tsx
More file actions
1719 lines (1583 loc) · 67.9 KB
/
WorkspaceSettingsPanel.tsx
File metadata and controls
1719 lines (1583 loc) · 67.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Workspace Settings Panel
*
* Manage workspace configuration including repositories,
* AI providers, custom domains, and agent policies.
*
* Design: Mission Control theme with deep space aesthetic
*/
import React, { useState, useEffect, useCallback } from 'react';
import { cloudApi } from '../../lib/cloudApi';
import { ProviderAuthFlow } from '../ProviderAuthFlow';
import { TerminalProviderSetup } from '../TerminalProviderSetup';
import { RepositoriesPanel } from '../RepositoriesPanel';
export interface WorkspaceSettingsPanelProps {
workspaceId: string;
csrfToken?: string;
onClose?: () => void;
onReposChanged?: () => void;
}
interface WorkspaceDetails {
id: string;
name: string;
status: string;
publicUrl?: string;
computeProvider: string;
config: {
providers: string[];
repositories: string[];
supervisorEnabled?: boolean;
maxAgents?: number;
};
customDomain?: string;
customDomainStatus?: string;
errorMessage?: string;
repositories: Array<{
id: string;
fullName: string;
syncStatus: string;
lastSyncedAt?: string;
}>;
createdAt: string;
updatedAt: string;
}
interface AvailableRepo {
id: string;
fullName: string;
isPrivate: boolean;
defaultBranch: string;
syncStatus: string;
hasNangoConnection: boolean;
lastSyncedAt?: string;
}
interface AIProvider {
id: string;
name: string;
displayName: string;
description: string;
color: string;
cliCommand: string;
apiKeyUrl?: string;
apiKeyName?: string;
supportsOAuth?: boolean;
preferApiKey?: boolean; // Show API key input by default (simpler for mobile/containers)
isConnected?: boolean;
comingSoon?: boolean; // Provider is not yet fully tested/available
}
const AI_PROVIDERS: AIProvider[] = [
{
id: 'anthropic',
name: 'anthropic', // Must be lowercase to match backend validation
displayName: 'Claude',
description: 'Claude Code - recommended for code tasks',
color: '#D97757',
cliCommand: 'claude',
apiKeyUrl: 'https://console.anthropic.com/settings/keys',
apiKeyName: 'API key',
supportsOAuth: true,
},
{
id: 'codex',
name: 'codex', // Must match backend provider key
displayName: 'Codex',
description: 'Codex - OpenAI coding assistant',
color: '#10A37F',
cliCommand: 'codex login',
apiKeyUrl: 'https://platform.openai.com/api-keys',
apiKeyName: 'API key',
supportsOAuth: true,
},
{
id: 'google',
name: 'google', // Must be lowercase to match backend validation
displayName: 'Gemini',
description: 'Gemini - Google AI coding assistant',
color: '#4285F4',
cliCommand: 'gemini',
// No apiKeyUrl - Gemini uses interactive terminal where user can choose OAuth or API key
supportsOAuth: true,
},
{
id: 'opencode',
name: 'opencode', // Must be lowercase to match backend validation
displayName: 'OpenCode',
description: 'OpenCode - AI coding assistant',
color: '#00D4AA',
cliCommand: 'opencode',
supportsOAuth: true,
comingSoon: true, // Not yet fully tested
},
{
id: 'droid',
name: 'factory', // Must be lowercase to match backend validation
displayName: 'Droid',
description: 'Droid - Factory AI coding agent',
color: '#6366F1',
cliCommand: 'droid',
supportsOAuth: true,
comingSoon: true, // Not yet fully tested
},
{
id: 'cursor',
name: 'cursor', // Must be lowercase to match backend validation
displayName: 'Cursor',
description: 'Cursor - AI-first code editor agent',
color: '#7C3AED',
cliCommand: 'agent',
supportsOAuth: true,
},
];
export function WorkspaceSettingsPanel({
workspaceId,
csrfToken,
onClose,
onReposChanged,
}: WorkspaceSettingsPanelProps) {
const [workspace, setWorkspace] = useState<WorkspaceDetails | null>(null);
const [availableRepos, setAvailableRepos] = useState<AvailableRepo[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [activeSection, setActiveSection] = useState<'general' | 'providers' | 'repos' | 'github-access' | 'automations' | 'domain' | 'danger'>('general');
// Provider connection state
const [providerStatus, setProviderStatus] = useState<Record<string, boolean>>({});
const [connectingProvider, setConnectingProvider] = useState<string | null>(null);
const [apiKeyInput, setApiKeyInput] = useState('');
const [providerError, setProviderError] = useState<string | null>(null);
const [showApiKeyFallback, setShowApiKeyFallback] = useState<Record<string, boolean>>({});
// Use terminal-based setup (default for Claude, Cursor, and Gemini - Codex uses CLI helper flow)
const [useTerminalSetup, setUseTerminalSetup] = useState<Record<string, boolean>>({
anthropic: false, // CLI-assisted SSH tunnel flow for Claude
cursor: false, // CLI-assisted SSH tunnel flow for Cursor
google: true, // Default to terminal for Gemini - allows choosing OAuth or API key
});
// CLI command copy state
// Provider disconnection state
const [disconnectingProvider, setDisconnectingProvider] = useState<string | null>(null);
// Repo sync state
const [syncingRepoId, setSyncingRepoId] = useState<string | null>(null);
// Custom domain form
const [customDomain, setCustomDomain] = useState('');
const [domainLoading, setDomainLoading] = useState(false);
const [domainError, setDomainError] = useState<string | null>(null);
const [domainInstructions, setDomainInstructions] = useState<{
type: string;
name: string;
value: string;
ttl: number;
} | null>(null);
// PR Review config state
const [prReviewConfig, setPrReviewConfig] = useState<{
enabled: boolean;
reviewers: string[];
excludeLabels: string[];
excludeAuthors: string[];
maxFilesChanged: number;
}>({
enabled: false,
reviewers: ['claude'],
excludeLabels: ['wip', 'do-not-review'],
excludeAuthors: ['dependabot[bot]'],
maxFilesChanged: 50,
});
const [prReviewLoading, setPrReviewLoading] = useState(false);
const [prReviewError, setPrReviewError] = useState<string | null>(null);
const [prReviewSuccess, setPrReviewSuccess] = useState(false);
const [excludeLabelInput, setExcludeLabelInput] = useState('');
const [excludeAuthorInput, setExcludeAuthorInput] = useState('');
// Load workspace details
useEffect(() => {
// Skip loading if workspaceId is invalid (not a UUID)
if (!workspaceId || workspaceId === 'default' || !/^[0-9a-f-]{36}$/i.test(workspaceId)) {
setIsLoading(false);
return;
}
async function loadWorkspace() {
setIsLoading(true);
setError(null);
const [wsResult, reposResult, providersResult] = await Promise.all([
cloudApi.getWorkspaceDetails(workspaceId),
cloudApi.getRepos(),
cloudApi.getProviders(workspaceId),
]);
if (wsResult.success) {
setWorkspace(wsResult.data);
if (wsResult.data.customDomain) {
setCustomDomain(wsResult.data.customDomain);
}
} else {
setError(wsResult.error);
}
if (reposResult.success) {
setAvailableRepos(reposResult.data.repositories);
}
// Mark connected providers for this workspace
if (providersResult.success) {
const connected: Record<string, boolean> = {};
providersResult.data.providers.forEach((p) => {
if (p.isConnected) {
connected[p.id] = true;
// Map backend 'openai' to frontend 'codex' for consistency
if (p.id === 'openai') {
connected['codex'] = true;
}
}
});
setProviderStatus(connected);
}
// Load PR review config
const configResult = await cloudApi.getWorkspaceConfig(workspaceId);
if (configResult.success && configResult.data.prReview) {
setPrReviewConfig(configResult.data.prReview);
}
setIsLoading(false);
}
loadWorkspace();
}, [workspaceId]);
// Save PR review config
const handleSavePrReviewConfig = useCallback(async () => {
if (!workspace) return;
setPrReviewLoading(true);
setPrReviewError(null);
setPrReviewSuccess(false);
const result = await cloudApi.updateWorkspaceConfig(workspace.id, {
prReview: prReviewConfig,
});
if (result.success) {
setPrReviewSuccess(true);
setTimeout(() => setPrReviewSuccess(false), 3000);
} else {
setPrReviewError(result.error);
}
setPrReviewLoading(false);
}, [workspace, prReviewConfig]);
// Toggle reviewer selection
const toggleReviewer = useCallback((reviewer: string) => {
setPrReviewConfig((prev) => ({
...prev,
reviewers: prev.reviewers.includes(reviewer)
? prev.reviewers.filter((r) => r !== reviewer)
: [...prev.reviewers, reviewer],
}));
}, []);
// Add exclude label
const addExcludeLabel = useCallback(() => {
const label = excludeLabelInput.trim();
if (label && !prReviewConfig.excludeLabels.includes(label)) {
setPrReviewConfig((prev) => ({
...prev,
excludeLabels: [...prev.excludeLabels, label],
}));
setExcludeLabelInput('');
}
}, [excludeLabelInput, prReviewConfig.excludeLabels]);
// Remove exclude label
const removeExcludeLabel = useCallback((label: string) => {
setPrReviewConfig((prev) => ({
...prev,
excludeLabels: prev.excludeLabels.filter((l) => l !== label),
}));
}, []);
// Add exclude author
const addExcludeAuthor = useCallback(() => {
const author = excludeAuthorInput.trim();
if (author && !prReviewConfig.excludeAuthors.includes(author)) {
setPrReviewConfig((prev) => ({
...prev,
excludeAuthors: [...prev.excludeAuthors, author],
}));
setExcludeAuthorInput('');
}
}, [excludeAuthorInput, prReviewConfig.excludeAuthors]);
// Remove exclude author
const removeExcludeAuthor = useCallback((author: string) => {
setPrReviewConfig((prev) => ({
...prev,
excludeAuthors: prev.excludeAuthors.filter((a) => a !== author),
}));
}, []);
// Start CLI-based OAuth flow for a provider
// This just sets state to show the ProviderAuthFlow component, which handles the actual auth
const startOAuthFlow = (provider: AIProvider) => {
setProviderError(null);
setConnectingProvider(provider.id);
// ProviderAuthFlow will handle the rest when it mounts
};
// Disconnect a provider
const handleDisconnectProvider = useCallback(async (provider: AIProvider) => {
const confirmed = window.confirm(
`Are you sure you want to disconnect ${provider.displayName}? This will remove the authentication and delete credential files from the workspace.`
);
if (!confirmed) return;
setDisconnectingProvider(provider.id);
setProviderError(null);
try {
const result = await cloudApi.disconnectProvider(provider.id, workspaceId);
if (result.success) {
setProviderStatus(prev => {
const updated = { ...prev };
delete updated[provider.id];
return updated;
});
} else {
setProviderError(result.error);
}
} catch (err) {
setProviderError(err instanceof Error ? err.message : 'Failed to disconnect provider');
} finally {
setDisconnectingProvider(null);
}
}, [workspaceId]);
const submitApiKey = async (provider: AIProvider) => {
if (!apiKeyInput.trim()) {
setProviderError('Please enter an API key');
return;
}
setProviderError(null);
setConnectingProvider(provider.id);
try {
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
if (csrfToken) headers['X-CSRF-Token'] = csrfToken;
const res = await fetch(`/api/onboarding/token/${provider.id}`, {
method: 'POST',
credentials: 'include',
headers,
body: JSON.stringify({ token: apiKeyInput.trim(), workspaceId }),
});
if (!res.ok) {
const data = await res.json();
throw new Error(data.error || 'Failed to connect');
}
setProviderStatus(prev => ({ ...prev, [provider.id]: true }));
setApiKeyInput('');
setConnectingProvider(null);
setShowApiKeyFallback(prev => ({ ...prev, [provider.id]: false }));
} catch (err) {
setProviderError(err instanceof Error ? err.message : 'Failed to connect');
setConnectingProvider(null);
}
};
// Restart workspace
const [isRestarting, setIsRestarting] = useState(false);
const [isRebuilding, setIsRebuilding] = useState(false);
const handleRestart = useCallback(async () => {
if (!workspace) return;
const confirmed = window.confirm('Are you sure you want to restart this workspace?');
if (!confirmed) return;
setIsRestarting(true);
setError(null);
const result = await cloudApi.restartWorkspace(workspace.id);
if (result.success) {
// If reprovisioning, update status to show provisioning state
if (result.data.action === 'reprovisioning') {
setWorkspace(prev => prev ? { ...prev, status: 'provisioning', errorMessage: undefined } : null);
}
const wsResult = await cloudApi.getWorkspaceDetails(workspaceId);
if (wsResult.success) {
setWorkspace(wsResult.data);
}
} else {
setError(result.error);
}
setIsRestarting(false);
}, [workspace, workspaceId]);
// Rebuild workspace from scratch
const handleRebuild = useCallback(async () => {
if (!workspace) return;
const confirmed = window.confirm(
'This will completely rebuild your workspace from scratch. All running processes will be stopped. Continue?'
);
if (!confirmed) return;
setIsRebuilding(true);
setError(null);
const result = await cloudApi.rebuildWorkspace(workspace.id);
if (result.success) {
setWorkspace(prev => prev ? { ...prev, status: 'provisioning', errorMessage: undefined } : null);
const wsResult = await cloudApi.getWorkspaceDetails(workspaceId);
if (wsResult.success) {
setWorkspace(wsResult.data);
}
} else {
setError(result.error);
}
setIsRebuilding(false);
}, [workspace, workspaceId]);
// Stop workspace
const handleStop = useCallback(async () => {
if (!workspace) return;
const confirmed = window.confirm('Are you sure you want to stop this workspace?');
if (!confirmed) return;
const result = await cloudApi.stopWorkspace(workspace.id);
if (result.success) {
const wsResult = await cloudApi.getWorkspaceDetails(workspaceId);
if (wsResult.success) {
setWorkspace(wsResult.data);
}
} else {
setError(result.error);
}
}, [workspace, workspaceId]);
// Add repository to workspace
const handleAddRepo = useCallback(async (repoId: string) => {
if (!workspace) return;
const result = await cloudApi.addReposToWorkspace(workspace.id, [repoId]);
if (result.success) {
const wsResult = await cloudApi.getWorkspaceDetails(workspaceId);
if (wsResult.success) {
setWorkspace(wsResult.data);
}
} else {
setError(result.error);
}
}, [workspace, workspaceId]);
// Sync repository to workspace (clone/pull)
const handleSyncRepo = useCallback(async (repoId: string) => {
if (!workspace) return;
setSyncingRepoId(repoId);
setError(null);
const result = await cloudApi.syncRepo(repoId);
if (result.success) {
// Refresh workspace to get updated sync status
const wsResult = await cloudApi.getWorkspaceDetails(workspaceId);
if (wsResult.success) {
setWorkspace(wsResult.data);
}
} else {
setError(result.error);
}
setSyncingRepoId(null);
}, [workspace, workspaceId]);
// Set custom domain
const handleSetDomain = useCallback(async () => {
if (!workspace || !customDomain.trim()) return;
setDomainLoading(true);
setDomainError(null);
setDomainInstructions(null);
const result = await cloudApi.setCustomDomain(workspace.id, customDomain.trim());
if (result.success) {
setDomainInstructions(result.data.instructions);
const wsResult = await cloudApi.getWorkspaceDetails(workspaceId);
if (wsResult.success) {
setWorkspace(wsResult.data);
}
} else {
setDomainError(result.error);
}
setDomainLoading(false);
}, [workspace, customDomain, workspaceId]);
// Verify custom domain
const handleVerifyDomain = useCallback(async () => {
if (!workspace) return;
setDomainLoading(true);
setDomainError(null);
const result = await cloudApi.verifyCustomDomain(workspace.id);
if (result.success) {
const wsResult = await cloudApi.getWorkspaceDetails(workspaceId);
if (wsResult.success) {
setWorkspace(wsResult.data);
}
if (result.data.status === 'active') {
setDomainInstructions(null);
}
} else {
setDomainError(result.error);
}
setDomainLoading(false);
}, [workspace, workspaceId]);
// Remove custom domain
const handleRemoveDomain = useCallback(async () => {
if (!workspace) return;
const confirmed = window.confirm('Are you sure you want to remove the custom domain?');
if (!confirmed) return;
setDomainLoading(true);
const result = await cloudApi.removeCustomDomain(workspace.id);
if (result.success) {
setCustomDomain('');
setDomainInstructions(null);
const wsResult = await cloudApi.getWorkspaceDetails(workspaceId);
if (wsResult.success) {
setWorkspace(wsResult.data);
}
} else {
setDomainError(result.error);
}
setDomainLoading(false);
}, [workspace, workspaceId]);
// Delete workspace
const handleDelete = useCallback(async () => {
if (!workspace) return;
const confirmed = window.confirm(
`Are you sure you want to delete "${workspace.name}"? This action cannot be undone.`
);
if (!confirmed) return;
const doubleConfirm = window.confirm(
'This will permanently delete all workspace data. Are you absolutely sure?'
);
if (!doubleConfirm) return;
const result = await cloudApi.deleteWorkspace(workspace.id);
if (result.success) {
// Redirect to onboarding page with deleted reason
window.location.href = '/app/onboarding?reason=deleted';
} else {
setError(result.error);
}
}, [workspace]);
if (isLoading) {
return (
<div className="flex items-center justify-center h-64">
<div className="relative">
<div className="w-12 h-12 rounded-full border-2 border-accent-cyan/20 border-t-accent-cyan animate-spin" />
<div className="absolute inset-0 flex items-center justify-center">
<div className="w-4 h-4 rounded-full bg-accent-cyan/40 animate-pulse" />
</div>
</div>
<span className="ml-4 text-text-muted font-mono text-sm tracking-wide">
LOADING WORKSPACE CONFIG...
</span>
</div>
);
}
if (error && !workspace) {
return (
<div className="p-6">
<div className="p-4 bg-error/10 border border-error/30 rounded-lg text-error flex items-center gap-3">
<AlertIcon />
<span>{error}</span>
</div>
</div>
);
}
if (!workspace) {
return null;
}
const unassignedRepos = availableRepos.filter(
(r) => !workspace.repositories.some((wr) => wr.id === r.id)
);
const sections = [
{ id: 'general', label: 'General', icon: <SettingsGearIcon /> },
{ id: 'providers', label: 'AI Providers', icon: <ProviderIcon /> },
{ id: 'repos', label: 'Repositories', icon: <RepoIcon /> },
{ id: 'automations', label: 'Automations', icon: <AutomationIcon /> },
{ id: 'domain', label: 'Domain', icon: <GlobeIcon /> },
{ id: 'danger', label: 'Danger', icon: <AlertIcon /> },
];
return (
<div className="flex flex-col h-full bg-bg-primary">
{/* Section Navigation - horizontally scrollable on mobile */}
<div
className="flex gap-1 p-2 sm:p-3 border-b border-border-subtle bg-gradient-to-b from-bg-tertiary to-bg-primary overflow-x-auto scrollbar-hide scroll-smooth snap-x snap-mandatory touch-pan-x"
style={{ WebkitOverflowScrolling: 'touch' }}
>
{sections.map((section) => (
<button
key={section.id}
onClick={() => setActiveSection(section.id as typeof activeSection)}
className={`flex items-center gap-1.5 sm:gap-2 px-3 sm:px-4 py-2 sm:py-2.5 rounded-lg text-xs sm:text-sm font-medium transition-all duration-200 whitespace-nowrap shrink-0 snap-start ${
activeSection === section.id
? 'bg-accent-cyan/15 text-accent-cyan border border-accent-cyan/30 shadow-[0_0_12px_rgba(0,217,255,0.15)]'
: 'text-text-secondary hover:bg-bg-hover hover:text-text-primary border border-transparent'
}`}
>
<span className={activeSection === section.id ? 'text-accent-cyan' : 'text-text-muted'}>
{section.icon}
</span>
{section.label}
</button>
))}
</div>
{/* Content */}
<div className="flex-1 overflow-y-auto p-4 sm:p-6">
{error && (
<div className="mb-6 p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm flex items-center gap-3">
<AlertIcon />
<span className="flex-1">{error}</span>
<button onClick={() => setError(null)} className="text-error/60 hover:text-error">
<CloseIcon />
</button>
</div>
)}
{/* General Section */}
{activeSection === 'general' && (
<div className="space-y-8">
<SectionHeader
title="Workspace Overview"
subtitle="Core configuration and status"
/>
{/* Error state banner */}
{workspace.status === 'error' && (
<div className="p-5 bg-error/10 border border-error/30 rounded-xl space-y-4">
<div className="flex items-start gap-3">
<div className="w-10 h-10 rounded-lg bg-error/20 flex items-center justify-center shrink-0 mt-0.5">
<AlertIcon className="text-error" />
</div>
<div className="flex-1">
<h4 className="text-sm font-semibold text-error">Workspace Error</h4>
<p className="text-xs text-text-secondary mt-1">
{workspace.errorMessage || 'The workspace encountered an error and is not running.'}
</p>
</div>
</div>
<div className="flex gap-3">
<ActionButton
onClick={handleRestart}
disabled={isRestarting || isRebuilding}
variant="primary"
icon={isRestarting ? <SpinnerIcon /> : <RestartIcon />}
>
{isRestarting ? 'Restarting...' : 'Restart Workspace'}
</ActionButton>
<ActionButton
onClick={handleRebuild}
disabled={isRestarting || isRebuilding}
variant="warning"
icon={isRebuilding ? <SpinnerIcon /> : <RebuildIcon />}
>
{isRebuilding ? 'Rebuilding...' : 'Rebuild from Scratch'}
</ActionButton>
</div>
</div>
)}
<div className="grid grid-cols-2 gap-4">
<InfoCard label="Name" value={workspace.name} />
<InfoCard
label="Status"
value={
(isRestarting || isRebuilding) ? 'Provisioning' :
workspace.status.charAt(0).toUpperCase() + workspace.status.slice(1)
}
valueColor={
(isRestarting || isRebuilding) ? 'text-accent-cyan' :
workspace.status === 'running' ? 'text-success' :
workspace.status === 'stopped' ? 'text-amber-400' :
workspace.status === 'error' ? 'text-error' : 'text-text-muted'
}
indicator={workspace.status === 'running' && !isRestarting && !isRebuilding}
/>
<InfoCard
label="Public URL"
value={workspace.publicUrl || 'Not available'}
mono
/>
<InfoCard
label="Compute Provider"
value={workspace.computeProvider.charAt(0).toUpperCase() + workspace.computeProvider.slice(1)}
/>
</div>
<div>
<SectionHeader title="Actions" subtitle="Manage workspace state" />
<div className="flex flex-wrap gap-3 mt-4">
{workspace.status === 'running' && (
<ActionButton
onClick={handleStop}
variant="warning"
icon={<StopIcon />}
>
Stop Workspace
</ActionButton>
)}
<ActionButton
onClick={handleRestart}
disabled={isRestarting || isRebuilding}
variant="primary"
icon={isRestarting ? <SpinnerIcon /> : <RestartIcon />}
>
{isRestarting ? 'Restarting...' : 'Restart Workspace'}
</ActionButton>
<ActionButton
onClick={handleRebuild}
disabled={isRestarting || isRebuilding}
variant="danger"
icon={isRebuilding ? <SpinnerIcon /> : <RebuildIcon />}
>
{isRebuilding ? 'Rebuilding...' : 'Rebuild Workspace'}
</ActionButton>
</div>
</div>
</div>
)}
{/* AI Providers Section */}
{activeSection === 'providers' && (
<div className="space-y-8">
<SectionHeader
title="AI Providers"
subtitle="Connect AI providers to spawn agents in this workspace"
/>
{providerError && (
<div className="p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm flex items-center gap-3">
<AlertIcon />
<span>{providerError}</span>
</div>
)}
<div className="space-y-4">
{AI_PROVIDERS.map((provider) => (
<div
key={provider.id}
className={`p-5 bg-bg-tertiary rounded-xl border border-border-subtle transition-all duration-200 ${
provider.comingSoon ? 'opacity-60' : 'hover:border-border-medium'
}`}
>
<div className="flex items-center justify-between">
<div className="flex items-center gap-4">
<div
className={`w-12 h-12 rounded-xl flex items-center justify-center text-white font-bold text-lg shadow-lg ${
provider.comingSoon ? 'grayscale' : ''
}`}
style={{
backgroundColor: provider.color,
boxShadow: provider.comingSoon ? 'none' : `0 4px 20px ${provider.color}40`,
}}
>
{provider.displayName[0]}
</div>
<div>
<h4 className="text-base font-semibold text-text-primary flex items-center gap-2">
{provider.displayName}
{provider.comingSoon && (
<span className="px-2 py-0.5 bg-amber-400/20 text-amber-400 text-xs font-medium rounded-full">
Coming Soon
</span>
)}
</h4>
<p className="text-sm text-text-muted">{provider.description}</p>
</div>
</div>
{provider.comingSoon ? (
<div className="px-4 py-2 bg-bg-card rounded-full border border-border-subtle">
<span className="text-sm text-text-muted">Not available yet</span>
</div>
) : providerStatus[provider.id] ? (
<div className="flex items-center gap-3">
<div className="flex items-center gap-2 px-4 py-2 bg-success/15 rounded-full border border-success/30">
<div className="w-2 h-2 rounded-full bg-success animate-pulse" />
<span className="text-sm font-medium text-success">Connected</span>
</div>
<button
onClick={() => handleDisconnectProvider(provider)}
disabled={disconnectingProvider === provider.id}
className="px-3 py-2 text-xs font-medium text-error/80 hover:text-error hover:bg-error/10 rounded-lg border border-transparent hover:border-error/30 transition-all disabled:opacity-50 disabled:cursor-not-allowed"
title={`Disconnect ${provider.displayName}`}
>
{disconnectingProvider === provider.id ? 'Disconnecting...' : 'Disconnect'}
</button>
</div>
) : null}
</div>
{!providerStatus[provider.id] && !provider.comingSoon && (
<div className="mt-5 pt-5 border-t border-border-subtle">
{connectingProvider === provider.id && !showApiKeyFallback[provider.id] ? (
useTerminalSetup[provider.id] ? (
<TerminalProviderSetup
provider={{
id: provider.id,
name: provider.name,
displayName: provider.displayName,
color: provider.color,
}}
workspaceId={workspaceId}
csrfToken={csrfToken}
maxHeight="350px"
onSuccess={() => {
setProviderStatus(prev => ({ ...prev, [provider.id]: true }));
setConnectingProvider(null);
}}
onCancel={() => {
setConnectingProvider(null);
}}
onError={(err) => {
setProviderError(err);
setConnectingProvider(null);
}}
onConnectAnother={() => {
// Mark current provider as connected and clear selection
// User can then click another provider to connect
setProviderStatus(prev => ({ ...prev, [provider.id]: true }));
setConnectingProvider(null);
}}
/>
) : (
<ProviderAuthFlow
provider={{
id: provider.id,
name: provider.name,
displayName: provider.displayName,
color: provider.color,
requiresUrlCopy: ['codex', 'anthropic', 'cursor'].includes(provider.id),
}}
workspaceId={workspaceId}
csrfToken={csrfToken}
onSuccess={() => {
setProviderStatus(prev => ({ ...prev, [provider.id]: true }));
setConnectingProvider(null);
}}
onCancel={() => {
setConnectingProvider(null);
}}
onError={(err) => {
setProviderError(err);
setConnectingProvider(null);
}}
/>
)
) : showApiKeyFallback[provider.id] ? (
<div className="space-y-4">
<div className="flex gap-3">
<input
type="password"
placeholder={`Enter ${provider.displayName} ${provider.apiKeyName || 'API key'}`}
value={connectingProvider === provider.id ? apiKeyInput : ''}
onChange={(e) => {
setConnectingProvider(provider.id);
setApiKeyInput(e.target.value);
}}
onFocus={() => setConnectingProvider(provider.id)}
className="flex-1 px-4 py-3 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent-cyan focus:ring-1 focus:ring-accent-cyan/30 transition-all"
/>
<button
onClick={() => submitApiKey(provider)}
disabled={connectingProvider !== provider.id || !apiKeyInput.trim()}
className="px-5 py-3 bg-accent-cyan text-bg-deep font-semibold rounded-lg text-sm hover:bg-accent-cyan/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all"
>
Connect
</button>
</div>
{provider.apiKeyUrl && (
<p className="text-xs text-text-muted">
Get your API key from{' '}
<a
href={provider.apiKeyUrl}
target="_blank"
rel="noopener noreferrer"
className="text-accent-cyan hover:underline"
>
{new URL(provider.apiKeyUrl).hostname}
</a>
</p>
)}
{provider.supportsOAuth && (
<button
onClick={() => setShowApiKeyFallback(prev => ({ ...prev, [provider.id]: false }))}
className="text-xs text-text-muted hover:text-text-secondary transition-colors"
>
← Back to OAuth login
</button>
)}
</div>
) : provider.supportsOAuth ? (
<div className="space-y-3">
{/* CLI info for providers using SSH tunnel auth */}
{['codex', 'anthropic', 'cursor'].includes(provider.id) && (
<div className="p-3 bg-accent-cyan/10 border border-accent-cyan/30 rounded-lg">
<p className="text-sm text-accent-cyan font-medium mb-1">CLI-assisted authentication</p>
<p className="text-xs text-accent-cyan/80">
Click the button below to get a CLI command with a unique session token.
Run it on your local machine to authenticate with {provider.displayName} via a secure SSH tunnel.
</p>
</div>
)}
<button
onClick={() => startOAuthFlow(provider)}
disabled={connectingProvider !== null}
className="w-full py-3 px-4 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold rounded-lg text-sm hover:shadow-glow-cyan hover:-translate-y-0.5 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:hover:shadow-none transition-all duration-200 flex items-center justify-center gap-2"
>
<LockIcon />
Connect with {provider.displayName}
</button>
{provider.apiKeyUrl && (
<button
onClick={() => setShowApiKeyFallback(prev => ({ ...prev, [provider.id]: true }))}
className="w-full text-xs text-text-muted hover:text-text-secondary transition-colors"
>
Or enter API key manually
</button>
)}
</div>
) : (
/* Provider doesn't support OAuth - show API key input directly */
<div className="space-y-4">
<div className="flex gap-3">
<input
type="password"
placeholder={`Enter ${provider.displayName} ${provider.apiKeyName || 'API key'}`}
value={connectingProvider === provider.id ? apiKeyInput : ''}
onChange={(e) => {
setConnectingProvider(provider.id);
setApiKeyInput(e.target.value);
}}
onFocus={() => setConnectingProvider(provider.id)}
className="flex-1 px-4 py-3 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent-cyan focus:ring-1 focus:ring-accent-cyan/30 transition-all"
/>
<button
onClick={() => submitApiKey(provider)}