forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppForm.tsx
More file actions
1173 lines (1094 loc) · 42.2 KB
/
Copy pathAppForm.tsx
File metadata and controls
1173 lines (1094 loc) · 42.2 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
'use client';
import { useState, useEffect, useCallback, useRef } from 'react';
import { useRouter } from '@tschk/moonshine-next/navigation';
import Image from '@tschk/moonshine-next/image';
import { cn } from '@/lib/utils';
import {
getAppCategories,
getAppCapabilities,
getNotificationScopes,
getPaymentPlans,
createApp,
updateApp,
uploadAppThumbnail,
generateAppDescription,
deleteApp,
} from '@/lib/api';
import type {
App,
AppCategory,
AppCapability,
NotificationScope,
PaymentPlan,
CreateAppRequest,
ThumbnailUploadResponse,
} from '@/types/apps';
import { PageHeader } from '@/components/layout/PageHeader';
import { LayoutGrid } from 'lucide-react';
// Icons
function ImageIcon({ className }: { className?: string }) {
return (
<svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={1.5}
d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
/>
</svg>
);
}
function SparklesIcon({ className }: { className?: string }) {
return (
<svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={1.5}
d="M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 00-2.456 2.456zM16.894 20.567L16.5 21.75l-.394-1.183a2.25 2.25 0 00-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 001.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 001.423 1.423l1.183.394-1.183.394a2.25 2.25 0 00-1.423 1.423z"
/>
</svg>
);
}
function PlusIcon({ className }: { className?: string }) {
return (
<svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M12 4v16m8-8H4"
/>
</svg>
);
}
function XIcon({ className }: { className?: string }) {
return (
<svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
);
}
function TrashIcon({ className }: { className?: string }) {
return (
<svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={1.5}
d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"
/>
</svg>
);
}
function ChevronDownIcon({ className }: { className?: string }) {
return (
<svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M19 9l-7 7-7-7"
/>
</svg>
);
}
function ArrowLeftIcon({ className }: { className?: string }) {
return (
<svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M10 19l-7-7m0 0l7-7m-7 7h18"
/>
</svg>
);
}
interface AppFormProps {
mode: 'create' | 'edit';
app?: App;
}
// Design system constants
const sectionCardClass =
'rounded-2xl p-5 bg-gradient-to-b from-white/[0.03] to-white/[0.01] shadow-[0_0_0_1px_rgba(255,255,255,0.04),0_2px_4px_rgba(0,0,0,0.1),0_8px_16px_rgba(0,0,0,0.1)]';
const inputClass =
'w-full px-4 py-3 rounded-xl bg-bg-tertiary border border-bg-quaternary text-text-primary placeholder:text-text-tertiary focus:outline-none focus:ring-2 focus:ring-white/50';
const textareaClass =
'w-full px-4 py-3 rounded-xl resize-none bg-bg-tertiary border border-bg-quaternary text-text-primary placeholder:text-text-tertiary focus:outline-none focus:ring-2 focus:ring-white/50';
export function AppForm({ mode, app }: AppFormProps) {
const router = useRouter();
const fileInputRef = useRef<HTMLInputElement>(null);
const thumbnailInputRef = useRef<HTMLInputElement>(null);
const categoryDropdownRef = useRef<HTMLDivElement>(null);
// Dropdown states
const [isCategoryOpen, setIsCategoryOpen] = useState(false);
// Close dropdown when clicking outside
useEffect(() => {
function handleClickOutside(event: MouseEvent) {
if (
categoryDropdownRef.current &&
!categoryDropdownRef.current.contains(event.target as Node)
) {
setIsCategoryOpen(false);
}
}
document.addEventListener('mousedown', handleClickOutside);
return () => document.removeEventListener('mousedown', handleClickOutside);
}, []);
// Loading states
const [isLoading, setIsLoading] = useState(true);
const [isSubmitting, setIsSubmitting] = useState(false);
const [isGeneratingDescription, setIsGeneratingDescription] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
// Metadata from API
const [categories, setCategories] = useState<AppCategory[]>([]);
const [capabilities, setCapabilities] = useState<AppCapability[]>([]);
const [notificationScopes, setNotificationScopes] = useState<NotificationScope[]>([]);
const [paymentPlans, setPaymentPlans] = useState<PaymentPlan[]>([]);
// Form data
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [category, setCategory] = useState('');
const [selectedCapabilities, setSelectedCapabilities] = useState<string[]>([]);
// Logo
const [logoFile, setLogoFile] = useState<File | null>(null);
const [logoPreview, setLogoPreview] = useState<string | null>(null);
// Thumbnails
const [thumbnails, setThumbnails] = useState<{ url: string; id: string }[]>([]);
const [uploadingThumbnail, setUploadingThumbnail] = useState(false);
// Prompts
const [chatPrompt, setChatPrompt] = useState('');
const [memoryPrompt, setMemoryPrompt] = useState('');
const [personaPrompt, setPersonaPrompt] = useState('');
// External integration
const [triggerEvent, setTriggerEvent] = useState('');
const [webhookUrl, setWebhookUrl] = useState('');
const [setupCompletedUrl, setSetupCompletedUrl] = useState('');
const [appHomeUrl, setAppHomeUrl] = useState('');
// Notification scopes
const [selectedScopes, setSelectedScopes] = useState<string[]>([]);
// Privacy & Payment
const [isPrivate, setIsPrivate] = useState(true);
const [isPaid, setIsPaid] = useState(false);
const [price, setPrice] = useState('');
const [paymentPlan, setPaymentPlan] = useState('');
// Source code URL
const [sourceCodeUrl, setSourceCodeUrl] = useState('');
// Error state
const [error, setError] = useState<string | null>(null);
// Load metadata
useEffect(() => {
async function loadMetadata() {
try {
const [cats, caps, scopes, plans] = await Promise.all([
getAppCategories(),
getAppCapabilities(),
getNotificationScopes(),
getPaymentPlans(),
]);
setCategories(cats);
setCapabilities(caps);
setNotificationScopes(scopes);
setPaymentPlans(plans);
} catch (err) {
console.error('Failed to load metadata:', err);
setError('Failed to load form data');
} finally {
setIsLoading(false);
}
}
loadMetadata();
}, []);
// Load app data for edit mode
useEffect(() => {
if (mode === 'edit' && app) {
setName(app.name);
setDescription(app.description);
setCategory(app.category);
setSelectedCapabilities(app.capabilities || []);
setLogoPreview(app.image || null);
setChatPrompt(app.chat_prompt || '');
setMemoryPrompt(app.memory_prompt || '');
setPersonaPrompt(app.persona_prompt || '');
setIsPrivate(app.private || false);
setIsPaid(app.is_paid || false);
setPrice(app.price?.toString() || '');
setPaymentPlan(app.payment_plan || '');
setSourceCodeUrl(app.source_code_url || '');
if (app.external_integration) {
setTriggerEvent(app.external_integration.triggers_on || '');
setWebhookUrl(app.external_integration.webhook_url || '');
setSetupCompletedUrl(app.external_integration.setup_completed_url || '');
setAppHomeUrl(app.external_integration.app_home_url || '');
}
if (app.thumbnail_urls) {
setThumbnails(app.thumbnail_urls.map((url, i) => ({ url, id: `existing-${i}` })));
}
}
}, [mode, app]);
// Capability helpers
const hasCapability = (cap: string) => selectedCapabilities.includes(cap);
const hasChat = hasCapability('chat');
const hasMemories = hasCapability('memories');
const hasPersona = hasCapability('persona');
const hasExternalIntegration = hasCapability('external_integration');
const hasProactiveNotification = hasCapability('proactive_notification');
const toggleCapability = (capId: string) => {
setSelectedCapabilities((prev) => {
// Persona is exclusive
if (capId === 'persona') {
if (prev.includes('persona')) {
return prev.filter((c) => c !== 'persona');
}
return ['persona'];
}
// If selecting other capability while persona is selected, remove persona
if (prev.includes('persona')) {
return [capId];
}
if (prev.includes(capId)) {
return prev.filter((c) => c !== capId);
}
return [...prev, capId];
});
};
// Logo handling
const handleLogoSelect = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) {
setLogoFile(file);
const reader = new FileReader();
reader.onloadend = () => {
setLogoPreview(reader.result as string);
};
reader.readAsDataURL(file);
}
};
// Thumbnail handling
const handleThumbnailSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (!file) return;
setUploadingThumbnail(true);
try {
const result = await uploadAppThumbnail(file);
setThumbnails((prev) => [
...prev,
{ url: result.thumbnail_url, id: result.thumbnail_id },
]);
} catch (err) {
console.error('Failed to upload thumbnail:', err);
setError('Failed to upload screenshot');
} finally {
setUploadingThumbnail(false);
if (thumbnailInputRef.current) {
thumbnailInputRef.current.value = '';
}
}
};
const removeThumbnail = (id: string) => {
setThumbnails((prev) => prev.filter((t) => t.id !== id));
};
// AI description generation
const handleGenerateDescription = async () => {
if (!name) {
setError('Please enter an app name first');
return;
}
setIsGeneratingDescription(true);
try {
const generated = await generateAppDescription(name, description);
setDescription(generated);
} catch (err) {
console.error('Failed to generate description:', err);
setError('Failed to generate description');
} finally {
setIsGeneratingDescription(false);
}
};
// Form validation
const validateForm = (): boolean => {
if (!name.trim()) {
setError('App name is required');
return false;
}
if (!description.trim()) {
setError('App description is required');
return false;
}
if (!category) {
setError('Please select a category');
return false;
}
if (selectedCapabilities.length === 0) {
setError('Please select at least one capability');
return false;
}
if (mode === 'create' && !logoFile && !logoPreview) {
setError('Please upload an app logo');
return false;
}
if (hasChat && !chatPrompt.trim()) {
setError('Chat prompt is required for chat capability');
return false;
}
if (hasMemories && !memoryPrompt.trim()) {
setError('Memory prompt is required for memories capability');
return false;
}
if (hasExternalIntegration && !webhookUrl.trim()) {
setError('Webhook URL is required for external integration');
return false;
}
if (hasProactiveNotification && selectedScopes.length === 0) {
setError('Please select at least one notification scope');
return false;
}
if ((hasExternalIntegration || hasProactiveNotification) && !sourceCodeUrl.trim()) {
setError(
'GitHub repository URL is required for external integration and notification apps',
);
return false;
}
if (isPaid) {
if (!price || parseFloat(price) < 1) {
setError('Price must be at least $1.00');
return false;
}
if (!paymentPlan) {
setError('Please select a payment plan');
return false;
}
}
setError(null);
return true;
};
// Submit handler
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!validateForm()) return;
setIsSubmitting(true);
setError(null);
try {
const data: CreateAppRequest = {
name: name.trim(),
description: description.trim(),
category,
capabilities: selectedCapabilities,
private: isPrivate,
};
if (hasChat) {
data.chat_prompt = chatPrompt.trim();
}
if (hasMemories) {
data.memory_prompt = memoryPrompt.trim();
}
if (hasPersona) {
data.persona_prompt = personaPrompt.trim();
}
if (hasExternalIntegration) {
data.external_integration = {
triggers_on: triggerEvent || undefined,
webhook_url: webhookUrl.trim(),
setup_completed_url: setupCompletedUrl.trim() || undefined,
app_home_url: appHomeUrl.trim() || undefined,
};
}
if (hasProactiveNotification) {
data.proactive_notification_scopes = selectedScopes;
}
if ((hasExternalIntegration || hasProactiveNotification) && sourceCodeUrl.trim()) {
data.source_code_url = sourceCodeUrl.trim();
}
if (isPaid) {
data.is_paid = true;
data.price = parseFloat(price);
data.payment_plan = paymentPlan;
}
if (mode === 'create') {
const result = await createApp(data, logoFile || undefined);
router.push(`/connectors/${result.app_id}`);
} else if (app) {
await updateApp(app.id, data, logoFile || undefined);
router.push(`/connectors/${app.id}`);
}
} catch (err) {
console.error('Failed to save app:', err);
setError(err instanceof Error ? err.message : 'Failed to save app');
} finally {
setIsSubmitting(false);
}
};
// Delete handler
const handleDelete = async () => {
if (!app || mode !== 'edit') return;
const confirmed = window.confirm(
'Are you sure you want to delete this app? This action cannot be undone.',
);
if (!confirmed) return;
setIsDeleting(true);
try {
await deleteApp(app.id);
router.push('/connectors');
} catch (err) {
console.error('Failed to delete app:', err);
setError('Failed to delete app');
} finally {
setIsDeleting(false);
}
};
if (isLoading) {
return (
<div className="flex items-center justify-center p-8">
<div className="animate-spin rounded-full h-8 w-8 border-2 border-accent-primary border-t-transparent" />
</div>
);
}
return (
<div className="flex flex-col h-full">
{/* Page Header */}
<PageHeader
title={mode === 'create' ? 'Create App' : 'Edit App'}
icon={LayoutGrid}
showBackButton
/>
{/* Toolbar with Actions */}
<div className="flex-shrink-0 px-6 py-3 border-b border-bg-tertiary bg-bg-secondary">
<div className="max-w-2xl mx-auto flex items-center justify-end gap-3">
{mode === 'edit' && (
<button
type="button"
onClick={handleDelete}
disabled={isDeleting}
className={cn(
'flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-medium',
'bg-error/10 text-error',
'hover:bg-error/20 transition-colors',
'disabled:opacity-50 disabled:cursor-not-allowed',
)}
>
<TrashIcon className="w-4 h-4" />
{isDeleting ? 'Deleting...' : 'Delete'}
</button>
)}
<button
type="submit"
form="app-form"
disabled={isSubmitting}
className={cn(
'flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-medium',
'bg-white text-black',
'hover:bg-white/90 transition-colors',
'disabled:opacity-50 disabled:cursor-not-allowed',
)}
>
{isSubmitting
? 'Saving...'
: mode === 'create'
? 'Create App'
: 'Save Changes'}
</button>
</div>
</div>
<form id="app-form" onSubmit={handleSubmit} className="flex-1 overflow-y-auto">
<div className="max-w-2xl mx-auto p-6 space-y-6">
{/* Error display */}
{error && (
<div className="p-4 bg-error/10 border border-error/20 rounded-xl text-error">
{error}
</div>
)}
{/* Metadata Section */}
<section className={cn(sectionCardClass, 'space-y-5')}>
<h2 className="text-lg font-medium text-text-primary">Basic Info</h2>
{/* Logo */}
<div>
<label className="block text-sm text-text-secondary mb-2">App Logo *</label>
<div className="flex items-center gap-4">
<button
type="button"
onClick={() => fileInputRef.current?.click()}
className={cn(
'w-20 h-20 rounded-2xl border border-dashed flex items-center justify-center',
'transition-colors hover:border-white/50',
logoPreview ? 'border-transparent' : 'border-bg-quaternary',
)}
>
{logoPreview ? (
<Image
src={logoPreview}
alt="App logo"
width={80}
height={80}
className="rounded-2xl object-cover"
/>
) : (
<ImageIcon className="w-8 h-8 text-text-tertiary" />
)}
</button>
<input
ref={fileInputRef}
type="file"
accept="image/*"
onChange={handleLogoSelect}
className="hidden"
/>
<span className="text-sm text-text-tertiary">
Click to upload logo image
</span>
</div>
</div>
{/* Name */}
<div>
<label className="block text-sm text-text-secondary mb-2">App Name *</label>
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="My Awesome App"
className={inputClass}
/>
</div>
{/* Description */}
<div>
<div className="flex items-center justify-between mb-2">
<label className="text-sm text-text-secondary">Description *</label>
<button
type="button"
onClick={handleGenerateDescription}
disabled={isGeneratingDescription || !name}
className={cn(
'flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm',
'bg-white/10 text-text-primary',
'hover:bg-white/20 transition-colors',
'disabled:opacity-50 disabled:cursor-not-allowed',
)}
>
<SparklesIcon className="w-4 h-4" />
{isGeneratingDescription ? 'Generating...' : 'Generate with AI'}
</button>
</div>
<textarea
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="Describe what your app does..."
rows={4}
className={textareaClass}
/>
</div>
{/* Category */}
<div>
<label className="block text-sm text-text-secondary mb-2">Category *</label>
<div className="relative" ref={categoryDropdownRef}>
<button
type="button"
onClick={() => setIsCategoryOpen(!isCategoryOpen)}
className={cn(
'w-full px-4 py-3 pr-10 rounded-xl text-left',
'border transition-all',
category
? 'bg-white/10 border-white/50 text-white'
: 'bg-bg-tertiary border-bg-quaternary text-text-primary',
'focus:outline-none focus:ring-2 focus:ring-white/50',
)}
>
{category
? categories.find((c) => c.id === category)?.title ||
'Select a category'
: 'Select a category'}
</button>
<ChevronDownIcon
className={cn(
'w-5 h-5 absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none transition-all',
category ? 'text-text-primary' : 'text-text-tertiary',
isCategoryOpen && 'rotate-180',
)}
/>
{/* Dropdown menu */}
{isCategoryOpen && (
<div className="absolute z-50 w-full mt-2 py-2 rounded-xl bg-bg-secondary border border-bg-quaternary shadow-xl max-h-64 overflow-y-auto">
{categories.map((cat) => {
const isSelected = category === cat.id;
return (
<button
key={cat.id}
type="button"
onClick={() => {
setCategory(cat.id);
setIsCategoryOpen(false);
}}
className={cn(
'w-full px-4 py-2.5 text-left transition-colors flex items-center justify-between',
isSelected
? 'bg-white/20 text-white'
: 'text-text-primary hover:bg-bg-tertiary',
)}
>
<span>{cat.title}</span>
{isSelected && (
<svg
className="w-4 h-4 text-text-primary"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={3}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M5 13l4 4L19 7"
/>
</svg>
)}
</button>
);
})}
</div>
)}
</div>
</div>
</section>
{/* Screenshots Section */}
<section className={cn(sectionCardClass, 'space-y-4')}>
<h2 className="text-lg font-medium text-text-primary">Screenshots</h2>
<div className="flex gap-3 overflow-x-auto pb-2">
{thumbnails.map((thumb) => (
<div key={thumb.id} className="relative flex-shrink-0">
<Image
src={thumb.url}
alt="Screenshot"
width={120}
height={180}
className="rounded-xl object-cover"
/>
<button
type="button"
onClick={() => removeThumbnail(thumb.id)}
className="absolute -top-2 -right-2 p-1 bg-error rounded-full"
>
<XIcon className="w-3 h-3 text-white" />
</button>
</div>
))}
<button
type="button"
onClick={() => thumbnailInputRef.current?.click()}
disabled={uploadingThumbnail}
className={cn(
'flex-shrink-0 w-[120px] h-[180px] rounded-xl',
'border border-dashed border-bg-quaternary',
'flex items-center justify-center',
'hover:border-white/50 transition-colors',
'disabled:opacity-50',
)}
>
{uploadingThumbnail ? (
<div className="animate-spin rounded-full h-6 w-6 border-2 border-white/30 border-t-transparent" />
) : (
<PlusIcon className="w-6 h-6 text-text-tertiary" />
)}
</button>
<input
ref={thumbnailInputRef}
type="file"
accept="image/*"
onChange={handleThumbnailSelect}
className="hidden"
/>
</div>
</section>
{/* Capabilities Section */}
<section className={cn(sectionCardClass, 'space-y-4')}>
<h2 className="text-lg font-medium text-text-primary">Capabilities *</h2>
<p className="text-sm text-text-tertiary">
Select what your app can do. Persona is exclusive and cannot be combined
with other capabilities.
</p>
<div className="grid grid-cols-2 gap-3">
{capabilities.map((cap) => {
const isSelected = hasCapability(cap.id);
return (
<button
key={cap.id}
type="button"
onClick={() => toggleCapability(cap.id)}
className={cn(
'relative px-4 py-4 rounded-xl text-left transition-all',
'border flex items-center justify-between',
isSelected
? 'bg-white/10 text-white border-white/50 ring-1 ring-white/30'
: 'bg-bg-tertiary border-transparent text-text-primary hover:bg-bg-quaternary',
)}
>
<span
className={cn(
'font-medium',
isSelected ? 'text-white' : 'text-text-primary',
)}
>
{cap.title}
</span>
<div
className={cn(
'w-5 h-5 rounded-full flex items-center justify-center border-2 transition-all',
isSelected
? 'bg-white border-white/30'
: 'border-text-quaternary bg-transparent',
)}
>
{isSelected && (
<svg
className="w-3 h-3 text-black"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={3}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M5 13l4 4L19 7"
/>
</svg>
)}
</div>
</button>
);
})}
</div>
</section>
{/* Chat Prompt Section */}
{hasChat && (
<section className={cn(sectionCardClass, 'space-y-4')}>
<h2 className="text-lg font-medium text-text-primary">Chat Prompt *</h2>
<textarea
value={chatPrompt}
onChange={(e) => setChatPrompt(e.target.value)}
placeholder="You are an awesome app, your job is to respond to the user queries..."
rows={4}
className={textareaClass}
/>
</section>
)}
{/* Memory Prompt Section */}
{hasMemories && (
<section className={cn(sectionCardClass, 'space-y-4')}>
<h2 className="text-lg font-medium text-text-primary">Memory Prompt *</h2>
<textarea
value={memoryPrompt}
onChange={(e) => setMemoryPrompt(e.target.value)}
placeholder="You are an awesome app, you will be given transcript and summary..."
rows={4}
className={textareaClass}
/>
</section>
)}
{/* Persona Prompt Section */}
{hasPersona && (
<section className={cn(sectionCardClass, 'space-y-4')}>
<h2 className="text-lg font-medium text-text-primary">Persona Prompt</h2>
<textarea
value={personaPrompt}
onChange={(e) => setPersonaPrompt(e.target.value)}
placeholder="Define the personality and behavior of your persona..."
rows={4}
className={textareaClass}
/>
</section>
)}
{/* External Integration Section */}
{hasExternalIntegration && (
<section className={cn(sectionCardClass, 'space-y-4')}>
<h2 className="text-lg font-medium text-text-primary">
External Integration
</h2>
{/* Trigger Event */}
<div>
<label className="block text-sm text-text-secondary mb-2">
Trigger Event
</label>
<div className="relative">
<select
value={triggerEvent}
onChange={(e) => setTriggerEvent(e.target.value)}
className={cn(
'w-full px-4 py-3 rounded-xl appearance-none',
'bg-bg-tertiary border border-bg-quaternary',
'text-text-primary',
'focus:outline-none focus:ring-2 focus:ring-white/50',
)}
>
<option value="">Select a trigger</option>
<option value="memory_creation">Memory Creation</option>
<option value="transcript_processed">
Transcript Segment Processed
</option>
<option value="audio_bytes">Audio Bytes Streamed</option>
</select>
<ChevronDownIcon className="w-5 h-5 absolute right-3 top-1/2 -translate-y-1/2 text-text-tertiary pointer-events-none" />
</div>
</div>
{/* Webhook URL */}
<div>
<label className="block text-sm text-text-secondary mb-2">
Webhook URL *
</label>
<input
type="url"
value={webhookUrl}
onChange={(e) => setWebhookUrl(e.target.value)}
placeholder="https://your-api.com/webhook"
className={inputClass}
/>
</div>
{/* Setup Completed URL */}
<div>
<label className="block text-sm text-text-secondary mb-2">
Setup Completed URL
</label>
<input
type="url"
value={setupCompletedUrl}
onChange={(e) => setSetupCompletedUrl(e.target.value)}
placeholder="https://your-api.com/setup-complete"
className={inputClass}
/>
</div>
{/* App Home URL */}
<div>
<label className="block text-sm text-text-secondary mb-2">
App Home URL
</label>
<input
type="url"
value={appHomeUrl}
onChange={(e) => setAppHomeUrl(e.target.value)}
placeholder="https://your-app.com"
className={inputClass}
/>
</div>
</section>
)}
{/* Notification Scopes Section */}
{hasProactiveNotification && notificationScopes.length > 0 && (
<section className={cn(sectionCardClass, 'space-y-4')}>
<h2 className="text-lg font-medium text-text-primary">
Notification Scopes *
</h2>
<div className="grid grid-cols-2 gap-3">
{notificationScopes.map((scope) => {
const isSelected = selectedScopes.includes(scope.id);
return (
<button
key={scope.id}
type="button"
onClick={() => {
setSelectedScopes((prev) =>
prev.includes(scope.id)
? prev.filter((s) => s !== scope.id)
: [...prev, scope.id],
);
}}
className={cn(
'px-4 py-4 rounded-xl text-left transition-all',
'border flex items-center justify-between',
isSelected
? 'bg-white/10 text-white border-white/50 ring-1 ring-white/30'
: 'bg-bg-tertiary border-transparent text-text-primary hover:bg-bg-quaternary',
)}
>
<span
className={cn(
'font-medium',
isSelected ? 'text-white' : 'text-text-primary',
)}
>
{scope.title}
</span>
<div
className={cn(
'w-5 h-5 rounded-full flex items-center justify-center border-2 transition-all',
isSelected
? 'bg-white border-white/30'
: 'border-text-quaternary bg-transparent',
)}
>
{isSelected && (
<svg
className="w-3 h-3 text-black"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={3}
>