forked from kortix-ai/suna
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
1366 lines (1186 loc) · 53.6 KB
/
setup.py
File metadata and controls
1366 lines (1186 loc) · 53.6 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
#!/usr/bin/env python3
import os
import sys
import time
import platform
import subprocess
import re
import json
import secrets
import base64
# --- Constants ---
IS_WINDOWS = platform.system() == "Windows"
PROGRESS_FILE = ".setup_progress"
ENV_DATA_FILE = ".setup_env.json"
# --- ANSI Colors ---
class Colors:
HEADER = "\033[95m"
BLUE = "\033[94m"
CYAN = "\033[96m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RED = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
# --- UI Helpers ---
def print_banner():
"""Prints the Suna setup banner."""
print(
f"""
{Colors.BLUE}{Colors.BOLD}
███████╗██╗ ██╗███╗ ██╗ █████╗
██╔════╝██║ ██║████╗ ██║██╔══██╗
███████╗██║ ██║██╔██╗ ██║███████║
╚════██║██║ ██║██║╚██╗██║██╔══██║
███████║╚██████╔╝██║ ╚████║██║ ██║
╚══════╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═╝
Installation Wizard
{Colors.ENDC}
"""
)
def print_step(step_num, total_steps, step_name):
"""Prints a formatted step header."""
print(
f"\n{Colors.BLUE}{Colors.BOLD}Step {step_num}/{total_steps}: {step_name}{Colors.ENDC}"
)
print(f"{Colors.CYAN}{'='*50}{Colors.ENDC}\n")
def print_info(message):
"""Prints an informational message."""
print(f"{Colors.CYAN}ℹ️ {message}{Colors.ENDC}")
def print_success(message):
"""Prints a success message."""
print(f"{Colors.GREEN}✅ {message}{Colors.ENDC}")
def print_warning(message):
"""Prints a warning message."""
print(f"{Colors.YELLOW}⚠️ {message}{Colors.ENDC}")
def print_error(message):
"""Prints an error message."""
print(f"{Colors.RED}❌ {message}{Colors.ENDC}")
# --- Environment File Parsing ---
def parse_env_file(filepath):
"""Parses a .env file and returns a dictionary of key-value pairs."""
env_vars = {}
if not os.path.exists(filepath):
return env_vars
try:
with open(filepath, "r") as f:
for line in f:
line = line.strip()
# Skip empty lines and comments
if not line or line.startswith("#"):
continue
# Handle key=value pairs
if "=" in line:
key, value = line.split("=", 1)
key = key.strip()
value = value.strip()
# Remove quotes if present
if value.startswith('"') and value.endswith('"'):
value = value[1:-1]
elif value.startswith("'") and value.endswith("'"):
value = value[1:-1]
env_vars[key] = value
except Exception as e:
print_warning(f"Could not parse {filepath}: {e}")
return env_vars
def load_existing_env_vars():
"""Loads existing environment variables from .env files."""
backend_env = parse_env_file(os.path.join("backend", ".env"))
frontend_env = parse_env_file(os.path.join("frontend", ".env.local"))
# Organize the variables by category
existing_vars = {
"supabase": {
"SUPABASE_URL": backend_env.get("SUPABASE_URL", ""),
"SUPABASE_ANON_KEY": backend_env.get("SUPABASE_ANON_KEY", ""),
"SUPABASE_SERVICE_ROLE_KEY": backend_env.get(
"SUPABASE_SERVICE_ROLE_KEY", ""
),
"SUPABASE_JWT_SECRET": backend_env.get("SUPABASE_JWT_SECRET", ""),
},
"daytona": {
"DAYTONA_API_KEY": backend_env.get("DAYTONA_API_KEY", ""),
"DAYTONA_SERVER_URL": backend_env.get("DAYTONA_SERVER_URL", ""),
"DAYTONA_TARGET": backend_env.get("DAYTONA_TARGET", ""),
},
"llm": {
"OPENAI_API_KEY": backend_env.get("OPENAI_API_KEY", ""),
"ANTHROPIC_API_KEY": backend_env.get("ANTHROPIC_API_KEY", ""),
"OPENROUTER_API_KEY": backend_env.get("OPENROUTER_API_KEY", ""),
"MORPH_API_KEY": backend_env.get("MORPH_API_KEY", ""),
"GEMINI_API_KEY": backend_env.get("GEMINI_API_KEY", ""),
},
"search": {
"TAVILY_API_KEY": backend_env.get("TAVILY_API_KEY", ""),
"FIRECRAWL_API_KEY": backend_env.get("FIRECRAWL_API_KEY", ""),
"FIRECRAWL_URL": backend_env.get("FIRECRAWL_URL", ""),
"EXA_API_KEY": backend_env.get("EXA_API_KEY", ""),
},
"rapidapi": {
"RAPID_API_KEY": backend_env.get("RAPID_API_KEY", ""),
},
"cron": {
# No secrets required. Make sure pg_cron and pg_net are enabled in Supabase
},
"webhook": {
"WEBHOOK_BASE_URL": backend_env.get("WEBHOOK_BASE_URL", ""),
"TRIGGER_WEBHOOK_SECRET": backend_env.get("TRIGGER_WEBHOOK_SECRET", ""),
},
"mcp": {
"MCP_CREDENTIAL_ENCRYPTION_KEY": backend_env.get(
"MCP_CREDENTIAL_ENCRYPTION_KEY", ""
),
},
"composio": {
"COMPOSIO_API_KEY": backend_env.get("COMPOSIO_API_KEY", ""),
"COMPOSIO_WEBHOOK_SECRET": backend_env.get("COMPOSIO_WEBHOOK_SECRET", ""),
},
"kortix": {
"KORTIX_ADMIN_API_KEY": backend_env.get("KORTIX_ADMIN_API_KEY", ""),
},
"frontend": {
"NEXT_PUBLIC_SUPABASE_URL": frontend_env.get(
"NEXT_PUBLIC_SUPABASE_URL", ""
),
"NEXT_PUBLIC_SUPABASE_ANON_KEY": frontend_env.get(
"NEXT_PUBLIC_SUPABASE_ANON_KEY", ""
),
"NEXT_PUBLIC_BACKEND_URL": frontend_env.get("NEXT_PUBLIC_BACKEND_URL", ""),
"NEXT_PUBLIC_URL": frontend_env.get("NEXT_PUBLIC_URL", ""),
"NEXT_PUBLIC_ENV_MODE": frontend_env.get("NEXT_PUBLIC_ENV_MODE", ""),
},
}
return existing_vars
def mask_sensitive_value(value, show_last=4):
"""Masks sensitive values for display, showing only the last few characters."""
if not value or len(value) <= show_last:
return value
return "*" * (len(value) - show_last) + value[-show_last:]
# --- State Management ---
def save_progress(step, data):
"""Saves the current step and collected data."""
with open(PROGRESS_FILE, "w") as f:
json.dump({"step": step, "data": data}, f)
def load_progress():
"""Loads the last saved step and data."""
if os.path.exists(PROGRESS_FILE):
with open(PROGRESS_FILE, "r") as f:
try:
return json.load(f)
except (json.JSONDecodeError, KeyError):
return {"step": 0, "data": {}}
return {"step": 0, "data": {}}
# --- Validators ---
def validate_url(url, allow_empty=False):
"""Validates a URL format."""
if allow_empty and not url:
return True
pattern = re.compile(
r"^(?:http|https)://"
r"(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|"
r"localhost|"
r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
r"(?::\d+)?"
r"(?:/?|[/?]\S+)$",
re.IGNORECASE,
)
return bool(pattern.match(url))
def validate_api_key(api_key, allow_empty=False):
"""Performs a basic validation for an API key."""
if allow_empty and not api_key:
return True
return bool(api_key and len(api_key) >= 10)
def generate_encryption_key():
"""Generates a secure base64-encoded encryption key for MCP credentials."""
# Generate 32 random bytes (256 bits)
key_bytes = secrets.token_bytes(32)
# Encode as base64
return base64.b64encode(key_bytes).decode("utf-8")
def generate_admin_api_key():
"""Generates a secure admin API key for Kortix."""
# Generate 32 random bytes and encode as hex for a readable API key
key_bytes = secrets.token_bytes(32)
return key_bytes.hex()
def generate_webhook_secret():
"""Generates a secure shared secret for trigger webhooks."""
# 32 random bytes as hex (64 hex chars)
return secrets.token_hex(32)
# --- Main Setup Class ---
class SetupWizard:
def __init__(self):
progress = load_progress()
self.current_step = progress.get("step", 0)
# Load existing environment variables from .env files
existing_env_vars = load_existing_env_vars()
# Start with existing values, then override with any saved progress
self.env_vars = {
"setup_method": None,
"supabase": existing_env_vars["supabase"],
"daytona": existing_env_vars["daytona"],
"llm": existing_env_vars["llm"],
"search": existing_env_vars["search"],
"rapidapi": existing_env_vars["rapidapi"],
"cron": existing_env_vars.get("cron", {}),
"webhook": existing_env_vars["webhook"],
"mcp": existing_env_vars["mcp"],
"composio": existing_env_vars["composio"],
"kortix": existing_env_vars["kortix"],
}
# Override with any progress data (in case user is resuming)
saved_data = progress.get("data", {})
for key, value in saved_data.items():
if key in self.env_vars and isinstance(value, dict):
self.env_vars[key].update(value)
else:
self.env_vars[key] = value
self.total_steps = 17
def show_current_config(self):
"""Shows the current configuration status."""
config_items = []
# Check Supabase
supabase_complete = (
self.env_vars["supabase"]["SUPABASE_URL"] and
self.env_vars["supabase"]["SUPABASE_ANON_KEY"] and
self.env_vars["supabase"]["SUPABASE_SERVICE_ROLE_KEY"]
)
supabase_secure = self.env_vars["supabase"]["SUPABASE_JWT_SECRET"]
if supabase_complete and supabase_secure:
config_items.append(f"{Colors.GREEN}✓{Colors.ENDC} Supabase (secure)")
elif supabase_complete:
config_items.append(f"{Colors.YELLOW}⚠{Colors.ENDC} Supabase (missing JWT secret)")
else:
config_items.append(f"{Colors.YELLOW}○{Colors.ENDC} Supabase")
# Check Daytona
if self.env_vars["daytona"]["DAYTONA_API_KEY"]:
config_items.append(f"{Colors.GREEN}✓{Colors.ENDC} Daytona")
else:
config_items.append(f"{Colors.YELLOW}○{Colors.ENDC} Daytona")
# Check LLM providers
llm_keys = [
k
for k in self.env_vars["llm"]
if self.env_vars["llm"][k] and k != "MORPH_API_KEY"
]
if llm_keys:
providers = [k.split("_")[0].capitalize() for k in llm_keys]
config_items.append(
f"{Colors.GREEN}✓{Colors.ENDC} LLM ({', '.join(providers)})"
)
else:
config_items.append(f"{Colors.YELLOW}○{Colors.ENDC} LLM providers")
# Check Search APIs
search_configured = (
self.env_vars["search"]["TAVILY_API_KEY"]
and self.env_vars["search"]["FIRECRAWL_API_KEY"]
)
if search_configured:
config_items.append(f"{Colors.GREEN}✓{Colors.ENDC} Search APIs")
else:
config_items.append(f"{Colors.YELLOW}○{Colors.ENDC} Search APIs")
# Check RapidAPI (optional)
if self.env_vars["rapidapi"]["RAPID_API_KEY"]:
config_items.append(
f"{Colors.GREEN}✓{Colors.ENDC} RapidAPI (optional)")
else:
config_items.append(
f"{Colors.CYAN}○{Colors.ENDC} RapidAPI (optional)")
# Check Cron/Webhook setup
if self.env_vars["webhook"]["WEBHOOK_BASE_URL"]:
config_items.append(
f"{Colors.GREEN}✓{Colors.ENDC} Supabase Cron & Webhooks")
else:
config_items.append(
f"{Colors.YELLOW}○{Colors.ENDC} Supabase Cron & Webhooks")
# Check MCP encryption key
if self.env_vars["mcp"]["MCP_CREDENTIAL_ENCRYPTION_KEY"]:
config_items.append(
f"{Colors.GREEN}✓{Colors.ENDC} MCP encryption key")
else:
config_items.append(
f"{Colors.YELLOW}○{Colors.ENDC} MCP encryption key")
# Check Composio configuration
if self.env_vars["composio"]["COMPOSIO_API_KEY"]:
config_items.append(
f"{Colors.GREEN}✓{Colors.ENDC} Composio (optional)")
else:
config_items.append(
f"{Colors.CYAN}○{Colors.ENDC} Composio (optional)")
# Check Webhook configuration
if self.env_vars["webhook"]["WEBHOOK_BASE_URL"]:
config_items.append(f"{Colors.GREEN}✓{Colors.ENDC} Webhook")
else:
config_items.append(f"{Colors.YELLOW}○{Colors.ENDC} Webhook")
# Check Morph (optional but recommended)
if self.env_vars["llm"].get("MORPH_API_KEY"):
config_items.append(
f"{Colors.GREEN}✓{Colors.ENDC} Morph (Code Editing)")
elif self.env_vars["llm"].get("OPENROUTER_API_KEY"):
config_items.append(
f"{Colors.CYAN}○{Colors.ENDC} Morph (fallback to OpenRouter)")
else:
config_items.append(
f"{Colors.YELLOW}○{Colors.ENDC} Morph (recommended)")
# Check Kortix configuration
if self.env_vars["kortix"]["KORTIX_ADMIN_API_KEY"]:
config_items.append(f"{Colors.GREEN}✓{Colors.ENDC} Kortix Admin")
else:
config_items.append(f"{Colors.YELLOW}○{Colors.ENDC} Kortix Admin")
if any("✓" in item for item in config_items):
print_info("Current configuration status:")
for item in config_items:
print(f" {item}")
print()
def run(self):
"""Runs the setup wizard."""
print_banner()
print(
"This wizard will guide you through setting up Suna, an open-source generalist AI Worker.\n"
)
# Show current configuration status
self.show_current_config()
try:
self.run_step(1, self.choose_setup_method)
self.run_step(2, self.check_requirements)
self.run_step(3, self.collect_supabase_info)
self.run_step(4, self.collect_daytona_info)
self.run_step(5, self.collect_llm_api_keys)
self.run_step(6, self.collect_morph_api_key)
self.run_step(7, self.collect_search_api_keys)
self.run_step(8, self.collect_rapidapi_keys)
self.run_step(9, self.collect_kortix_keys)
# Supabase Cron does not require keys; ensure DB migrations enable cron functions
self.run_step(10, self.collect_webhook_keys)
self.run_step(11, self.collect_mcp_keys)
self.run_step(12, self.collect_composio_keys)
# Removed duplicate webhook collection step
self.run_step(13, self.configure_env_files)
self.run_step(14, self.setup_supabase_database)
self.run_step(15, self.install_dependencies)
self.run_step(16, self.start_suna)
self.final_instructions()
except KeyboardInterrupt:
print("\n\nSetup interrupted. Your progress has been saved.")
print("You can resume setup anytime by running this script again.")
sys.exit(1)
except Exception as e:
print_error(f"An unexpected error occurred: {e}")
print_error(
"Please check the error message and try running the script again."
)
sys.exit(1)
def run_step(self, step_number, step_function, *args, **kwargs):
"""Executes a setup step if it hasn't been completed."""
if self.current_step < step_number:
step_function(*args, **kwargs)
self.current_step = step_number
save_progress(self.current_step, self.env_vars)
def choose_setup_method(self):
"""Asks the user to choose between Docker and manual setup."""
print_step(1, self.total_steps, "Choose Setup Method")
if self.env_vars.get("setup_method"):
print_info(
f"Continuing with '{self.env_vars['setup_method']}' setup method."
)
return
print_info(
"You can start Suna using either Docker Compose or by manually starting the services."
)
print(f"\n{Colors.CYAN}How would you like to set up Suna?{Colors.ENDC}")
print(
f"{Colors.CYAN}[1] {Colors.GREEN}Docker Compose{Colors.ENDC} {Colors.CYAN}(recommended, starts all services automatically){Colors.ENDC}"
)
print(
f"{Colors.CYAN}[2] {Colors.GREEN}Manual{Colors.ENDC} {Colors.CYAN}(requires installing dependencies and running services manually){Colors.ENDC}\n"
)
while True:
choice = input("Enter your choice (1 or 2): ").strip()
if choice == "1":
self.env_vars["setup_method"] = "docker"
break
elif choice == "2":
self.env_vars["setup_method"] = "manual"
break
else:
print_error(
"Invalid selection. Please enter '1' for Docker or '2' for Manual."
)
print_success(f"Selected '{self.env_vars['setup_method']}' setup.")
def check_requirements(self):
"""Checks if all required tools for the chosen setup method are installed."""
print_step(2, self.total_steps, "Checking Requirements")
if self.env_vars["setup_method"] == "docker":
requirements = {
"git": "https://git-scm.com/downloads",
"docker": "https://docs.docker.com/get-docker/",
}
else: # manual
requirements = {
"git": "https://git-scm.com/downloads",
"uv": "https://github.com/astral-sh/uv#installation",
"node": "https://nodejs.org/en/download/",
"npm": "https://docs.npmjs.com/downloading-and-installing-node-js-and-npm",
"docker": "https://docs.docker.com/get-docker/", # For Redis
}
missing = []
for cmd, url in requirements.items():
try:
cmd_to_check = cmd
# On Windows, python3 is just python
if IS_WINDOWS and cmd in ["python3", "pip3"]:
cmd_to_check = cmd.replace("3", "")
subprocess.run(
[cmd_to_check, "--version"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True,
shell=IS_WINDOWS,
)
print_success(f"{cmd} is installed.")
except (subprocess.SubprocessError, FileNotFoundError):
missing.append((cmd, url))
print_error(f"{cmd} is not installed.")
if missing:
print_error(
"\nMissing required tools. Please install them before continuing:"
)
for cmd, url in missing:
print(f" - {cmd}: {url}")
sys.exit(1)
self.check_docker_running()
self.check_suna_directory()
def check_docker_running(self):
"""Checks if the Docker daemon is running."""
print_info("Checking if Docker is running...")
try:
subprocess.run(
["docker", "info"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True,
shell=IS_WINDOWS,
)
print_success("Docker is running.")
return True
except subprocess.SubprocessError:
print_error(
"Docker is installed but not running. Please start Docker and try again."
)
sys.exit(1)
def check_suna_directory(self):
"""Checks if the script is run from the correct project root directory."""
print_info("Verifying project structure...")
required_dirs = ["backend", "frontend"]
required_files = ["README.md", "docker-compose.yaml"]
for directory in required_dirs:
if not os.path.isdir(directory):
print_error(
f"'{directory}' directory not found. Make sure you're in the Suna repository root."
)
sys.exit(1)
for file in required_files:
if not os.path.isfile(file):
print_error(
f"'{file}' not found. Make sure you're in the Suna repository root."
)
sys.exit(1)
print_success("Suna repository detected.")
return True
def _get_input(
self, prompt, validator, error_message, allow_empty=False, default_value=""
):
"""Helper to get validated user input with optional default value."""
while True:
# Show default value in prompt if it exists
if default_value:
# Mask sensitive values for display
if "key" in prompt.lower() or "token" in prompt.lower():
display_default = mask_sensitive_value(default_value)
else:
display_default = default_value
full_prompt = (
f"{prompt}[{Colors.GREEN}{display_default}{Colors.ENDC}]: "
)
else:
full_prompt = prompt
value = input(full_prompt).strip()
# Use default value if user just pressed Enter
if not value and default_value:
value = default_value
if validator(value, allow_empty=allow_empty):
return value
print_error(error_message)
def collect_supabase_info(self):
"""Collects Supabase project information from the user."""
print_step(3, self.total_steps, "Collecting Supabase Information")
# Check if we already have values configured
has_existing = any(self.env_vars["supabase"].values())
if has_existing:
print_info(
"Found existing Supabase configuration. Press Enter to keep current values or type new ones."
)
else:
print_info(
"You'll need a Supabase project. Visit https://supabase.com/dashboard/projects to create one."
)
print_info(
"In your project settings, go to 'API' to find the required information:"
)
print_info(" - Project URL (at the top)")
print_info(" - anon public key (under 'Project API keys')")
print_info(" - service_role secret key (under 'Project API keys')")
print_info(" - JWT Secret (under 'JWT Settings' - critical for security!)")
input("Press Enter to continue once you have your project details...")
self.env_vars["supabase"]["SUPABASE_URL"] = self._get_input(
"Enter your Supabase Project URL (e.g., https://xyz.supabase.co): ",
validate_url,
"Invalid URL format. Please enter a valid URL.",
default_value=self.env_vars["supabase"]["SUPABASE_URL"],
)
self.env_vars["supabase"]["SUPABASE_ANON_KEY"] = self._get_input(
"Enter your Supabase anon key: ",
validate_api_key,
"This does not look like a valid key. It should be at least 10 characters.",
default_value=self.env_vars["supabase"]["SUPABASE_ANON_KEY"],
)
self.env_vars["supabase"]["SUPABASE_SERVICE_ROLE_KEY"] = self._get_input(
"Enter your Supabase service role key: ",
validate_api_key,
"This does not look like a valid key. It should be at least 10 characters.",
default_value=self.env_vars["supabase"]["SUPABASE_SERVICE_ROLE_KEY"],
)
self.env_vars["supabase"]["SUPABASE_JWT_SECRET"] = self._get_input(
"Enter your Supabase JWT secret (for signature verification): ",
validate_api_key,
"This does not look like a valid JWT secret. It should be at least 10 characters.",
default_value=self.env_vars["supabase"]["SUPABASE_JWT_SECRET"],
)
print_success("Supabase information saved.")
def collect_daytona_info(self):
"""Collects Daytona API key."""
print_step(4, self.total_steps, "Collecting Daytona Information")
# Check if we already have values configured
has_existing = bool(self.env_vars["daytona"]["DAYTONA_API_KEY"])
if has_existing:
print_info(
"Found existing Daytona configuration. Press Enter to keep current values or type new ones."
)
else:
print_info(
"Suna uses Daytona for sandboxing. Visit https://app.daytona.io/ to create an account."
)
print_info("Then, generate an API key from the 'Keys' menu.")
input("Press Enter to continue once you have your API key...")
self.env_vars["daytona"]["DAYTONA_API_KEY"] = self._get_input(
"Enter your Daytona API key: ",
validate_api_key,
"Invalid API key format. It should be at least 10 characters long.",
default_value=self.env_vars["daytona"]["DAYTONA_API_KEY"],
)
# Set defaults if not already configured
if not self.env_vars["daytona"]["DAYTONA_SERVER_URL"]:
self.env_vars["daytona"][
"DAYTONA_SERVER_URL"
] = "https://app.daytona.io/api"
if not self.env_vars["daytona"]["DAYTONA_TARGET"]:
self.env_vars["daytona"]["DAYTONA_TARGET"] = "us"
print_success("Daytona information saved.")
print_warning(
"IMPORTANT: You must create a Suna snapshot in Daytona for it to work properly."
)
print_info(
f"Visit {Colors.GREEN}https://app.daytona.io/dashboard/snapshots{Colors.ENDC}{Colors.CYAN} to create a snapshot."
)
print_info("Create a snapshot with these exact settings:")
print_info(
f" - Name:\t\t{Colors.GREEN}kortix/suna:0.1.3.21{Colors.ENDC}")
print_info(
f" - Snapshot name:\t{Colors.GREEN}kortix/suna:0.1.3.21{Colors.ENDC}")
print_info(
f" - Entrypoint:\t{Colors.GREEN}/usr/bin/supervisord -n -c /etc/supervisor/conf.d/supervisord.conf{Colors.ENDC}"
)
input("Press Enter to continue once you have created the snapshot...")
def collect_llm_api_keys(self):
"""Collects LLM API keys for various providers."""
print_step(5, self.total_steps, "Collecting LLM API Keys")
# Check if we already have any LLM keys configured
existing_keys = {
k: v for k, v in self.env_vars["llm"].items() if v
}
has_existing = bool(existing_keys)
if has_existing:
print_info("Found existing LLM API keys:")
for key, value in existing_keys.items():
provider_name = key.split("_")[0].capitalize()
print_info(
f" - {provider_name}: {mask_sensitive_value(value)}")
print_info(
"You can add more providers or press Enter to keep existing configuration."
)
else:
print_info(
"Suna requires at least one LLM provider. Supported: OpenAI, Anthropic, Google Gemini, OpenRouter."
)
# Don't clear existing keys if we're updating
if not has_existing:
self.env_vars["llm"] = {}
while not any(
k
for k in self.env_vars["llm"]
if self.env_vars["llm"][k]
):
providers = {
"1": ("OpenAI", "OPENAI_API_KEY"),
"2": ("Anthropic", "ANTHROPIC_API_KEY"),
"3": ("Google Gemini", "GEMINI_API_KEY"),
"4": ("OpenRouter", "OPENROUTER_API_KEY"),
}
print(
f"\n{Colors.CYAN}Select LLM providers to configure (e.g., 1,3):{Colors.ENDC}"
)
for key, (name, env_key) in providers.items():
current_value = self.env_vars["llm"].get(env_key, "")
status = (
f" {Colors.GREEN}(configured){Colors.ENDC}" if current_value else ""
)
print(
f"{Colors.CYAN}[{key}] {Colors.GREEN}{name}{Colors.ENDC}{status}")
# Allow Enter to skip if we already have keys configured
if has_existing:
choices_input = input(
"Select providers (or press Enter to skip): "
).strip()
if not choices_input:
break
else:
choices_input = input("Select providers: ").strip()
choices = choices_input.replace(",", " ").split()
selected_keys = {providers[c][1]
for c in choices if c in providers}
if not selected_keys and not has_existing:
print_error(
"Invalid selection. Please choose at least one provider.")
continue
for key in selected_keys:
provider_name = key.split("_")[0].capitalize()
existing_value = self.env_vars["llm"].get(key, "")
api_key = self._get_input(
f"Enter your {provider_name} API key: ",
validate_api_key,
"Invalid API key format.",
default_value=existing_value,
)
self.env_vars["llm"][key] = api_key
print_success("LLM keys saved.")
def collect_morph_api_key(self):
"""Collects the optional MorphLLM API key for code editing."""
print_step(6, self.total_steps,
"Configure AI-Powered Code Editing (Optional)")
existing_key = self.env_vars["llm"].get("MORPH_API_KEY", "")
openrouter_key = self.env_vars["llm"].get("OPENROUTER_API_KEY", "")
if existing_key:
print_info(
f"Found existing Morph API key: {mask_sensitive_value(existing_key)}")
print_info("AI-powered code editing is enabled using Morph.")
return
print_info("Suna uses Morph for fast, intelligent code editing.")
print_info(
"This is optional but highly recommended for the best experience.")
if openrouter_key:
print_info(
f"An OpenRouter API key is already configured. It can be used as a fallback for code editing if you don't provide a Morph key."
)
while True:
choice = input(
"Do you want to add a Morph API key now? (y/n): ").lower().strip()
if choice in ['y', 'n', '']:
break
print_error("Invalid input. Please enter 'y' or 'n'.")
if choice == 'y':
print_info(
"Great! Please get your API key from: https://morphllm.com/api-keys")
morph_api_key = self._get_input(
"Enter your Morph API key (or press Enter to skip): ",
validate_api_key,
"The key seems invalid, but continuing. You can edit it later in backend/.env",
allow_empty=True,
default_value="",
)
if morph_api_key:
self.env_vars["llm"]["MORPH_API_KEY"] = morph_api_key
print_success(
"Morph API key saved. AI-powered code editing is enabled.")
else:
if openrouter_key:
print_info(
"Skipping Morph key. OpenRouter will be used for code editing.")
else:
print_warning(
"Skipping Morph key. Code editing will use a less capable model.")
else:
if openrouter_key:
print_info(
"Okay, OpenRouter will be used as a fallback for code editing.")
else:
print_warning(
"Okay, code editing will use a less capable model without a Morph or OpenRouter key.")
def collect_search_api_keys(self):
"""Collects API keys for search and web scraping tools."""
print_step(7, self.total_steps,
"Collecting Search and Scraping API Keys")
# Check if we already have values configured
has_existing = any(self.env_vars["search"].values())
if has_existing:
print_info(
"Found existing search API keys. Press Enter to keep current values or type new ones."
)
else:
print_info(
"Suna uses Tavily for search, Firecrawl for web scraping, and Exa for people search.")
print_info(
"Get a Tavily key at https://tavily.com, a Firecrawl key at https://firecrawl.dev, "
"and an Exa key at https://exa.ai"
)
input("Press Enter to continue once you have your keys...")
self.env_vars["search"]["TAVILY_API_KEY"] = self._get_input(
"Enter your Tavily API key: ",
validate_api_key,
"Invalid API key.",
default_value=self.env_vars["search"]["TAVILY_API_KEY"],
)
self.env_vars["search"]["FIRECRAWL_API_KEY"] = self._get_input(
"Enter your Firecrawl API key: ",
validate_api_key,
"Invalid API key.",
default_value=self.env_vars["search"]["FIRECRAWL_API_KEY"],
)
# Exa API key (optional for people search)
print_info(
"\nExa API enables advanced people search with LinkedIn/email enrichment using Websets."
)
print_info(
"This is optional but required for the People Search tool. Leave blank to skip."
)
self.env_vars["search"]["EXA_API_KEY"] = self._get_input(
"Enter your Exa API key (optional): ",
validate_api_key,
"Invalid API key.",
allow_empty=True,
default_value=self.env_vars["search"]["EXA_API_KEY"],
)
# Handle Firecrawl URL configuration
current_url = self.env_vars["search"]["FIRECRAWL_URL"]
is_self_hosted_default = (
current_url and current_url != "https://api.firecrawl.dev"
)
if current_url:
prompt = f"Are you self-hosting Firecrawl? (y/N) [Current: {'y' if is_self_hosted_default else 'N'}]: "
else:
prompt = "Are you self-hosting Firecrawl? (y/N): "
response = input(prompt).lower().strip()
if not response and current_url:
# Use existing configuration
is_self_hosted = is_self_hosted_default
else:
is_self_hosted = response == "y"
if is_self_hosted:
self.env_vars["search"]["FIRECRAWL_URL"] = self._get_input(
"Enter your self-hosted Firecrawl URL: ",
validate_url,
"Invalid URL.",
default_value=(
current_url if current_url != "https://api.firecrawl.dev" else ""
),
)
else:
self.env_vars["search"]["FIRECRAWL_URL"] = "https://api.firecrawl.dev"
print_success("Search and scraping keys saved.")
def collect_rapidapi_keys(self):
"""Collects the optional RapidAPI key."""
print_step(8, self.total_steps, "Collecting RapidAPI Key (Optional)")
# Check if we already have a value configured
existing_key = self.env_vars["rapidapi"]["RAPID_API_KEY"]
if existing_key:
print_info(
f"Found existing RapidAPI key: {mask_sensitive_value(existing_key)}"
)
print_info("Press Enter to keep current value or type a new one.")
else:
print_info(
"A RapidAPI key enables extra tools like LinkedIn scraping.")
print_info(
"Get a key at https://rapidapi.com/. You can skip this and add it later."
)
rapid_api_key = self._get_input(
"Enter your RapidAPI key (or press Enter to skip): ",
validate_api_key,
"The key seems invalid, but continuing. You can edit it later in backend/.env",
allow_empty=True,
default_value=existing_key,
)
self.env_vars["rapidapi"]["RAPID_API_KEY"] = rapid_api_key
if rapid_api_key:
print_success("RapidAPI key saved.")
else:
print_info("Skipping RapidAPI key.")
def collect_kortix_keys(self):
"""Generates or configures the Kortix admin API key."""
print_step(9, self.total_steps, "Configuring Kortix Admin API Key")
# Check if we already have a value configured
existing_key = self.env_vars["kortix"]["KORTIX_ADMIN_API_KEY"]
if existing_key:
print_info(
f"Found existing Kortix admin API key: {mask_sensitive_value(existing_key)}"
)
print_info("Using existing admin API key.")
else:
print_info(
"Generating a secure admin API key for Kortix administrative functions...")
self.env_vars["kortix"]["KORTIX_ADMIN_API_KEY"] = generate_admin_api_key()
print_success("Kortix admin API key generated.")
print_success("Kortix admin configuration saved.")
def collect_mcp_keys(self):
"""Collects the MCP configuration."""
print_step(11, self.total_steps, "Collecting MCP Configuration")
# Check if we already have an encryption key configured
existing_key = self.env_vars["mcp"]["MCP_CREDENTIAL_ENCRYPTION_KEY"]
if existing_key:
print_info(
f"Found existing MCP encryption key: {mask_sensitive_value(existing_key)}"
)
print_info("Using existing encryption key.")
else:
print_info(
"Generating a secure encryption key for MCP credentials...")
self.env_vars["mcp"][
"MCP_CREDENTIAL_ENCRYPTION_KEY"
] = generate_encryption_key()
print_success("MCP encryption key generated.")
print_success("MCP configuration saved.")
def collect_composio_keys(self):
"""Collects the optional Composio configuration."""
print_step(12, self.total_steps,
"Collecting Composio Configuration (Optional)")
# Check if we already have values configured
has_existing = any(self.env_vars["composio"].values())
if has_existing:
print_info(
"Found existing Composio configuration. Press Enter to keep current values or type new ones."
)