forked from opxiahub/tanya
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·2192 lines (1912 loc) · 70.4 KB
/
setup
File metadata and controls
executable file
·2192 lines (1912 loc) · 70.4 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 bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET_ROOT="${TANYA_TARGET_ROOT:-/root/.openclaw}"
TARGET_WORKSPACE="$TARGET_ROOT/workspace"
TARGET_AGENT_DIR="$TARGET_ROOT/agents/main/agent"
TARGET_SCRIPTS="$TARGET_ROOT/scripts"
TARGET_MEDIA="$TARGET_ROOT/media/tanya-image"
MAIN_MODEL="${TANYA_MAIN_MODEL:-openai/gpt-5.4}"
MINI_MODEL="${TANYA_MINI_MODEL:-openai/gpt-5.4-mini}"
MODE="${1:-init}"
SUBMODE="${2:-}"
VERSION="1.1.0"
# ─────────────────────────────────────────────────────────────
# Terminal colors and styling
# ─────────────────────────────────────────────────────────────
init_colors() {
if [[ -t 1 ]] && command -v tput >/dev/null 2>&1; then
local colors
colors="$(tput colors 2>/dev/null || echo 0)"
if [[ "$colors" -ge 8 ]]; then
BOLD="$(tput bold)"
DIM="$(tput dim)"
RESET="$(tput sgr0)"
BLUE="$(tput setaf 4)"
CYAN="$(tput setaf 6)"
GREEN="$(tput setaf 2)"
MAGENTA="$(tput setaf 5)"
RED="$(tput setaf 1)"
YELLOW="$(tput setaf 3)"
WHITE="$(tput setaf 7)"
return
fi
fi
BOLD=""
DIM=""
RESET=""
BLUE=""
CYAN=""
GREEN=""
MAGENTA=""
RED=""
YELLOW=""
WHITE=""
}
# ─────────────────────────────────────────────────────────────
# Output helpers
# ─────────────────────────────────────────────────────────────
divider() {
printf '%s%s%s\n' "$DIM" "────────────────────────────────────────────────────────" "$RESET"
}
step_header() {
local step_num="$1"
local total="$2"
local title="$3"
echo
divider
printf ' %s%sStep %s of %s%s %s%s%s\n' "$BOLD" "$CYAN" "$step_num" "$total" "$RESET" "$BOLD" "$title" "$RESET"
divider
}
section() {
echo
printf ' %s%s%s %s\n' "$BOLD$MAGENTA" ">" "$RESET" "$BOLD$1$RESET"
echo
}
info() {
printf ' %s%s %s%s\n' "$BLUE" "i" "$RESET" "$1"
}
hint() {
printf ' %s%s %s%s\n' "$MAGENTA" "?" "$RESET" "$1"
}
good() {
printf ' %s%s %s%s\n' "$GREEN" "+" "$RESET" "$1"
}
warn() {
printf ' %s%s %s%s\n' "$YELLOW" "!" "$RESET" "$1"
}
die() {
echo
printf ' %s%s %s%s\n' "$RED" "x" "$RESET" "$1" >&2
echo
exit 1
}
status_line() {
local label="$1"
local value="$2"
local color="${3:-$GREEN}"
printf ' %-28s %s%s%s\n' "$label" "$color" "$value" "$RESET"
}
key_help() {
local service="$1"
local url="$2"
local note="$3"
echo
printf ' %s%sWhere to get this:%s\n' "$DIM" "$BOLD" "$RESET"
printf ' %s%s%s\n' "$CYAN" "$url" "$RESET"
if [[ -n "$note" ]]; then
printf ' %s%s%s\n' "$DIM" "$note" "$RESET"
fi
echo
}
usage() {
cat <<EOF
${BOLD}Tanya Setup — Available Commands${RESET}
${BOLD}Host install (bare-metal)${RESET}
${CYAN}./setup${RESET} First-time install on this machine
${CYAN}./setup init${RESET} Same as above
${CYAN}./setup configure${RESET} Update features or keys on an existing install
${CYAN}./setup uninstall${RESET} Remove Tanya and OpenClaw completely from this machine
${BOLD}Docker${RESET}
${CYAN}./setup docker${RESET} Install and run Tanya inside a Docker container
${CYAN}./setup docker uninstall${RESET} Stop container and guided cleanup (image, data, keys)
${BOLD}Help${RESET}
${CYAN}./setup help${RESET} Show this help menu
${CYAN}./setup -h${RESET} Same as above
EOF
}
# ─────────────────────────────────────────────────────────────
# Utilities
# ─────────────────────────────────────────────────────────────
need_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
die "Missing required command: $1"
fi
}
validator_any() {
return 0
}
validator_phone() {
local value="$1"
if [[ -z "$value" ]]; then
return 0
fi
if [[ "$value" =~ ^\+[0-9]{8,15}$ ]]; then
return 0
fi
warn "Use full international format like +919512345678 with no spaces, hyphens, or brackets."
return 1
}
validator_chat_id() {
local value="$1"
if [[ "$value" =~ ^-?[0-9]+$ ]]; then
return 0
fi
warn "Telegram chat ID should be digits only, for example 123456789."
return 1
}
prompt_yes_no() {
local label="$1"
local default="$2"
local reply
local prompt
local normalized
if [[ "$default" == "Y" ]]; then
prompt="${GREEN}Y${RESET}/n"
else
prompt="y/${RED}N${RESET}"
fi
while true; do
printf ' %s%s %s%s [%s] ' "$CYAN" ">" "$RESET" "$label" "$prompt"
read -r reply
if [[ -z "$reply" ]]; then
reply="$default"
fi
normalized="$(printf '%s' "$reply" | tr '[:upper:]' '[:lower:]')"
case "$normalized" in
y|yes) return 0 ;;
n|no) return 1 ;;
esac
done
}
prompt_value() {
local var_name="$1"
local label="$2"
local secret="${3:-0}"
local required="${4:-1}"
local default_value="${5:-}"
local example="${6:-}"
local help_text="${7:-}"
local validator="${8:-validator_any}"
local reply
local prompt_suffix=""
if [[ -n "$help_text" ]]; then
hint "$help_text"
fi
if [[ -n "$example" ]]; then
printf ' %s Example: %s%s\n' "$DIM" "$example" "$RESET"
fi
if [[ "$secret" == "1" && -n "$default_value" ]]; then
prompt_suffix=" ${DIM}[press Enter to keep current]${RESET}"
elif [[ -n "$default_value" ]]; then
prompt_suffix=" ${DIM}[$default_value]${RESET}"
fi
while true; do
if [[ "$secret" == "1" ]]; then
printf ' %s%s%s %s%s: ' "$CYAN" ">" "$RESET" "$label" "$prompt_suffix"
read -r -s reply
echo
else
printf ' %s%s%s %s%s: ' "$CYAN" ">" "$RESET" "$label" "$prompt_suffix"
read -r reply
fi
if [[ -z "$reply" && -n "$default_value" ]]; then
reply="$default_value"
fi
if [[ -z "$reply" && "$required" != "0" ]]; then
warn "This value is required."
continue
fi
if [[ -n "$reply" ]] && ! "$validator" "$reply"; then
continue
fi
printf -v "$var_name" '%s' "$reply"
return 0
done
}
generate_gateway_token() {
if command -v openssl >/dev/null 2>&1; then
openssl rand -hex 24
else
python3 - <<'PY'
import secrets
print(secrets.token_hex(24))
PY
fi
}
default_yes_no() {
if [[ "${1:-0}" == "1" ]]; then
printf 'Y'
else
printf 'N'
fi
}
# ─────────────────────────────────────────────────────────────
# Banner
# ─────────────────────────────────────────────────────────────
print_banner() {
echo
printf '%s' "$MAGENTA$BOLD"
cat <<'ART'
████████╗ █████╗ ███╗ ██╗██╗ ██╗ █████╗
╚══██╔══╝██╔══██╗████╗ ██║╚██╗ ██╔╝██╔══██╗
██║ ███████║██╔██╗ ██║ ╚████╔╝ ███████║
██║ ██╔══██║██║╚██╗██║ ╚██╔╝ ██╔══██║
██║ ██║ ██║██║ ╚████║ ██║ ██║ ██║
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝
ART
printf '%s' "$RESET"
printf ' %sAI Companion Setup%s %sv%s%s\n' "$BOLD" "$RESET" "$DIM" "$VERSION" "$RESET"
printf ' %sPowered by OpenClaw%s\n' "$DIM" "$RESET"
echo
divider
if [[ "$MODE" == "configure" ]]; then
echo
info "Configure mode: update features without touching live state or memory."
info "Press Enter on any prompt to keep the current value."
else
echo
info "This wizard will set up Tanya on this machine."
info "It takes about 5 minutes. You'll need a few API keys."
fi
echo
hint "You can come back later and update anything with ${BOLD}./setup configure${RESET}"
echo
}
# ─────────────────────────────────────────────────────────────
# Load existing config (for configure mode defaults)
# ─────────────────────────────────────────────────────────────
load_existing_defaults() {
DEFAULT_USER_NAME=""
DEFAULT_TELEGRAM_USERNAME=""
DEFAULT_TELEGRAM_CHAT_ID=""
DEFAULT_USER_PHONE=""
DEFAULT_TELEGRAM_BOT_TOKEN=""
DEFAULT_OPENAI_API_KEY=""
DEFAULT_GOOGLE_API_KEY=""
DEFAULT_WEB_SEARCH_API_KEY=""
DEFAULT_ELEVENLABS_API_KEY=""
DEFAULT_ELEVENLABS_VOICE_ID=""
DEFAULT_ELEVENLABS_AGENT_ID=""
DEFAULT_ELEVENLABS_PHONE_NUMBER_ID=""
DEFAULT_ENABLE_IMAGES=0
DEFAULT_ENABLE_VOICE=0
DEFAULT_ENABLE_CALLS=0
DEFAULT_ENABLE_WEB=0
eval "$(
python3 - <<'PY'
import json
import os
import pathlib
import re
import shlex
target_root = pathlib.Path(os.environ["TARGET_ROOT"])
workspace = target_root / "workspace"
agent_dir = target_root / "agents" / "main" / "agent"
call_script = target_root / "scripts" / "call_user.sh"
values = {
"DEFAULT_USER_NAME": "",
"DEFAULT_TELEGRAM_USERNAME": "",
"DEFAULT_TELEGRAM_CHAT_ID": "",
"DEFAULT_USER_PHONE": "",
"DEFAULT_TELEGRAM_BOT_TOKEN": "",
"DEFAULT_OPENAI_API_KEY": "",
"DEFAULT_GOOGLE_API_KEY": "",
"DEFAULT_WEB_SEARCH_API_KEY": "",
"DEFAULT_ELEVENLABS_API_KEY": "",
"DEFAULT_ELEVENLABS_VOICE_ID": "",
"DEFAULT_ELEVENLABS_AGENT_ID": "",
"DEFAULT_ELEVENLABS_PHONE_NUMBER_ID": "",
"DEFAULT_ENABLE_IMAGES": "0",
"DEFAULT_ENABLE_VOICE": "0",
"DEFAULT_ENABLE_CALLS": "0",
"DEFAULT_ENABLE_WEB": "0",
}
def clean(value: str) -> str:
if value in {"pending-pairing", "not-set", "not-shared", ""}:
return ""
return value.strip()
agents_path = workspace / "AGENTS.md"
if agents_path.exists():
text = agents_path.read_text()
patterns = {
"DEFAULT_USER_NAME": r"- Name:\s*(.+)",
"DEFAULT_TELEGRAM_USERNAME": r"- Telegram username:\s*(.+)",
"DEFAULT_TELEGRAM_CHAT_ID": r"- Telegram chat ID:\s*(.+)",
"DEFAULT_USER_PHONE": r"- Phone number:\s*(.+)",
}
for key, pattern in patterns.items():
match = re.search(pattern, text)
if match:
values[key] = clean(match.group(1))
openclaw_path = target_root / "openclaw.json"
if openclaw_path.exists():
try:
data = json.loads(openclaw_path.read_text())
except Exception:
data = {}
telegram = (((data.get("channels") or {}).get("telegram")) or {})
tools = data.get("tools") or {}
media_audio = ((tools.get("media") or {}).get("audio")) or {}
web_search = (((tools.get("web") or {}).get("search")) or {})
defaults = (((data.get("agents") or {}).get("defaults")) or {})
image_model = defaults.get("imageGenerationModel") or {}
messages = data.get("messages") or {}
eleven = ((messages.get("tts") or {}).get("elevenlabs")) or {}
plugins = (((data.get("plugins") or {}).get("entries")) or {})
google_plugin = (plugins.get("google") or {}).get("config") or {}
google_web = google_plugin.get("webSearch") or {}
values["DEFAULT_TELEGRAM_BOT_TOKEN"] = telegram.get("botToken", "")
values["DEFAULT_ENABLE_IMAGES"] = "1" if image_model.get("primary") else "0"
values["DEFAULT_ENABLE_VOICE"] = "1" if media_audio.get("enabled") else "0"
values["DEFAULT_ENABLE_WEB"] = "1" if web_search.get("enabled") else "0"
values["DEFAULT_ELEVENLABS_API_KEY"] = eleven.get("apiKey", "")
values["DEFAULT_ELEVENLABS_VOICE_ID"] = eleven.get("voiceId", "")
values["DEFAULT_WEB_SEARCH_API_KEY"] = google_web.get("apiKey", "")
auth_profiles_path = agent_dir / "auth-profiles.json"
if auth_profiles_path.exists():
try:
auth_data = json.loads(auth_profiles_path.read_text())
except Exception:
auth_data = {}
profiles = auth_data.get("profiles") or {}
values["DEFAULT_OPENAI_API_KEY"] = ((profiles.get("openai:default") or {}).get("key")) or values["DEFAULT_OPENAI_API_KEY"]
values["DEFAULT_GOOGLE_API_KEY"] = (profiles.get("google:default") or {}).get("key", "")
if call_script.exists():
call_text = call_script.read_text()
patterns = {
"DEFAULT_ELEVENLABS_API_KEY": r'ELEVENLABS_API_KEY="\$\{ELEVENLABS_API_KEY:-([^}]*)\}"',
"DEFAULT_ELEVENLABS_AGENT_ID": r'ELEVENLABS_AGENT_ID="\$\{ELEVENLABS_AGENT_ID:-([^}]*)\}"',
"DEFAULT_ELEVENLABS_PHONE_NUMBER_ID": r'ELEVENLABS_PHONE_NUMBER_ID="\$\{ELEVENLABS_PHONE_NUMBER_ID:-([^}]*)\}"',
}
for key, pattern in patterns.items():
match = re.search(pattern, call_text)
if match:
candidate = match.group(1).strip()
if not (candidate.startswith("<") and candidate.endswith(">")):
values[key] = candidate
if values["DEFAULT_ELEVENLABS_API_KEY"] and values["DEFAULT_ELEVENLABS_AGENT_ID"] and values["DEFAULT_ELEVENLABS_PHONE_NUMBER_ID"]:
values["DEFAULT_ENABLE_CALLS"] = "1"
for key, value in values.items():
print(f"{key}={shlex.quote(str(value))}")
PY
)"
}
# ─────────────────────────────────────────────────────────────
# Show current configuration status (configure mode)
# ─────────────────────────────────────────────────────────────
show_current_status() {
section "Current Configuration"
local mask="****"
if [[ -n "$DEFAULT_USER_NAME" ]]; then
status_line "Name:" "$DEFAULT_USER_NAME"
else
status_line "Name:" "not set" "$YELLOW"
fi
if [[ -n "$DEFAULT_TELEGRAM_BOT_TOKEN" ]]; then
status_line "Telegram bot:" "configured" "$GREEN"
else
status_line "Telegram bot:" "not configured" "$YELLOW"
fi
if [[ -n "$DEFAULT_TELEGRAM_CHAT_ID" ]]; then
status_line "Telegram chat ID:" "$DEFAULT_TELEGRAM_CHAT_ID"
else
status_line "Telegram chat ID:" "pending" "$YELLOW"
fi
if [[ -n "$DEFAULT_OPENAI_API_KEY" ]]; then
status_line "OpenAI API key:" "configured" "$GREEN"
else
status_line "OpenAI API key:" "not configured" "$RED"
fi
if [[ -n "$DEFAULT_GOOGLE_API_KEY" ]]; then
status_line "Google API key (images):" "configured" "$GREEN"
else
status_line "Google API key (images):" "not configured" "$DIM"
fi
if [[ -n "$DEFAULT_WEB_SEARCH_API_KEY" ]]; then
status_line "Google API key (web search):" "configured" "$GREEN"
else
status_line "Google API key (web search):" "not configured" "$DIM"
fi
echo
divider
echo
local img_status voice_status web_status call_status
if [[ "$DEFAULT_ENABLE_IMAGES" == "1" ]]; then
img_status="${GREEN}enabled${RESET}"
else
img_status="${DIM}disabled${RESET}"
fi
if [[ "$DEFAULT_ENABLE_VOICE" == "1" ]]; then
voice_status="${GREEN}enabled${RESET}"
else
voice_status="${DIM}disabled${RESET}"
fi
if [[ "$DEFAULT_ENABLE_WEB" == "1" ]]; then
web_status="${GREEN}enabled${RESET}"
else
web_status="${DIM}disabled${RESET}"
fi
if [[ "$DEFAULT_ENABLE_CALLS" == "1" ]]; then
call_status="${GREEN}enabled${RESET}"
else
call_status="${DIM}disabled${RESET}"
fi
printf ' %-28s %s\n' "Selfies & photos:" "$img_status"
printf ' %-28s %s\n' "Voice notes:" "$voice_status"
printf ' %-28s %s\n' "Web discovery:" "$web_status"
printf ' %-28s %s\n' "Phone calls:" "$call_status"
echo
}
# ─────────────────────────────────────────────────────────────
# Configure mode menu
# ─────────────────────────────────────────────────────────────
show_configure_menu() {
section "What would you like to configure?"
echo " ${BOLD}1${RESET} Core settings ${DIM}(name, Telegram bot, OpenAI key)${RESET}"
echo " ${BOLD}2${RESET} Selfies & photos ${DIM}(image generation via Google)${RESET}"
echo " ${BOLD}3${RESET} Voice notes ${DIM}(text-to-speech via ElevenLabs)${RESET}"
echo " ${BOLD}4${RESET} Web discovery ${DIM}(web search via Google)${RESET}"
echo " ${BOLD}5${RESET} Phone calls ${DIM}(calling via ElevenLabs + Twilio)${RESET}"
echo
echo " ${BOLD}6${RESET} Reinstall crons ${DIM}(re-add scheduled jobs)${RESET}"
echo " ${BOLD}7${RESET} Telegram pairing ${DIM}(pair or re-pair your Telegram account)${RESET}"
echo
echo " ${BOLD}8${RESET} Everything ${DIM}(walk through all settings + crons + pairing)${RESET}"
echo
local choice
while true; do
printf ' %s%s%s Pick an option [1-8]: ' "$CYAN" ">" "$RESET"
read -r choice
case "$choice" in
1|2|3|4|5|6|7|8) break ;;
*) warn "Please enter a number from 1 to 8." ;;
esac
done
CONFIGURE_CHOICE="$choice"
}
# ─────────────────────────────────────────────────────────────
# Step 1: Core setup
# ─────────────────────────────────────────────────────────────
show_core_setup() {
local total_steps="$1"
step_header "1" "$total_steps" "Core Settings"
info "These are the basics Tanya needs to come alive on Telegram."
echo
prompt_value USER_NAME \
"Your name" \
0 1 "$DEFAULT_USER_NAME" \
"Abhimanyu" \
"Tanya will know you by this name." \
validator_any
prompt_value USER_PHONE \
"Your phone number with country code (optional, press Enter to skip)" \
0 0 "$DEFAULT_USER_PHONE" \
"+919512345678" \
"Needed only if you want phone calls later." \
validator_phone
echo
divider
echo
info "Now let's set up your Telegram bot."
key_help "Telegram" \
"https://t.me/BotFather" \
"Message @BotFather on Telegram > /newbot > follow prompts > copy the token."
prompt_value TELEGRAM_BOT_TOKEN \
"Telegram bot token" \
1 1 "$DEFAULT_TELEGRAM_BOT_TOKEN" \
"123456789:AAExampleBotTokenHere" \
"" \
validator_any
echo
divider
echo
info "Tanya's brain runs on OpenAI. You'll need an API key with credits."
key_help "OpenAI" \
"https://platform.openai.com/api-keys" \
"Create an account > API Keys > Create new key. Requires a paid account with credits."
prompt_value OPENAI_API_KEY \
"OpenAI API key" \
1 1 "$DEFAULT_OPENAI_API_KEY" \
"sk-proj-..." \
"" \
validator_any
}
# ─────────────────────────────────────────────────────────────
# Feature: Selfies & photos
# ─────────────────────────────────────────────────────────────
configure_images() {
local total_steps="${1:-}"
if [[ -n "$total_steps" ]]; then
step_header "2" "$total_steps" "Selfies & Photo Sharing"
else
section "Selfies & Photo Sharing"
fi
info "Tanya can share selfies, paintings, food photos, and little moments."
info "Uses Google Gemini for image generation."
echo
printf ' %s%sRequires:%s Google API key with billing enabled\n' "$BOLD" "$WHITE" "$RESET"
echo
if prompt_yes_no "Enable selfies and photo sharing?" "$(default_yes_no "$DEFAULT_ENABLE_IMAGES")"; then
ENABLE_IMAGES=1
local _img_default="${GOOGLE_API_KEY:-$DEFAULT_GOOGLE_API_KEY}"
if [[ -z "$_img_default" ]]; then
key_help "Google AI" \
"https://aistudio.google.com/apikey" \
"Create a key in AI Studio or Cloud Console. Billing must be enabled."
else
info "A Google API key is configured. Press Enter to keep it, or enter a new one."
fi
prompt_value GOOGLE_API_KEY \
"Google API key for images" \
1 1 "$_img_default" \
"AIza..." \
"" \
validator_any
else
ENABLE_IMAGES=0
info "Skipped. Enable later with ${BOLD}./setup configure${RESET}"
fi
}
# ─────────────────────────────────────────────────────────────
# Feature: Voice notes
# ─────────────────────────────────────────────────────────────
configure_voice() {
local total_steps="${1:-}"
if [[ -n "$total_steps" ]]; then
step_header "3" "$total_steps" "Voice Notes"
else
section "Voice Notes"
fi
info "Send Tanya voice notes and hear her reply in her own voice."
info "Uses ElevenLabs for text-to-speech and OpenAI for transcription."
echo
printf ' %s%sRequires:%s ElevenLabs API key + voice ID %s(free tier: 10k chars/month)%s\n' "$BOLD" "$WHITE" "$RESET" "$DIM" "$RESET"
echo
if prompt_yes_no "Enable voice notes?" "$(default_yes_no "$DEFAULT_ENABLE_VOICE")"; then
ENABLE_VOICE=1
if [[ -z "$ELEVENLABS_API_KEY" ]]; then
key_help "ElevenLabs" \
"https://elevenlabs.io" \
"Create free account > Profile + API key (left sidebar) > copy key."
prompt_value ELEVENLABS_API_KEY \
"ElevenLabs API key" \
1 1 "$DEFAULT_ELEVENLABS_API_KEY" \
"sk_..." \
"" \
validator_any
else
good "Using the ElevenLabs API key already entered."
fi
echo
hint "Pick or create a voice in ElevenLabs > Voices > click the voice > copy Voice ID."
prompt_value ELEVENLABS_VOICE_ID \
"ElevenLabs voice ID" \
0 1 "${DEFAULT_ELEVENLABS_VOICE_ID:-ulZgFXalzbrnPUGQGs0S}" \
"ulZgFXalzbrnPUGQGs0S" \
"" \
validator_any
else
ENABLE_VOICE=0
info "Skipped. Enable later with ${BOLD}./setup configure${RESET}"
fi
}
# ─────────────────────────────────────────────────────────────
# Feature: Web discovery
# ─────────────────────────────────────────────────────────────
configure_web() {
local total_steps="${1:-}"
if [[ -n "$total_steps" ]]; then
step_header "4" "$total_steps" "Web Discovery"
else
section "Web Discovery"
fi
info "Tanya can look things up online, stay current, and share discoveries."
info "Uses Google search via Gemini."
echo
printf ' %s%sRequires:%s Google API key %s(free tier available)%s\n' "$BOLD" "$WHITE" "$RESET" "$DIM" "$RESET"
echo
if prompt_yes_no "Enable web discovery?" "$(default_yes_no "$DEFAULT_ENABLE_WEB")"; then
ENABLE_WEB=1
local _web_default="${WEB_SEARCH_API_KEY:-${GOOGLE_API_KEY:-$DEFAULT_WEB_SEARCH_API_KEY}}"
if [[ -z "$_web_default" ]]; then
key_help "Google AI" \
"https://aistudio.google.com/apikey" \
"Create a key in AI Studio or Cloud Console. Free tier works for web search."
else
info "A Google API key is available. Press Enter to keep it, or enter a new one."
fi
prompt_value WEB_SEARCH_API_KEY \
"Google API key for web search" \
1 1 "${WEB_SEARCH_API_KEY:-${GOOGLE_API_KEY:-$DEFAULT_WEB_SEARCH_API_KEY}}" \
"AIza..." \
"" \
validator_any
else
ENABLE_WEB=0
info "Skipped. Enable later with ${BOLD}./setup configure${RESET}"
fi
}
# ─────────────────────────────────────────────────────────────
# Feature: Phone calls
# ─────────────────────────────────────────────────────────────
configure_calls() {
local total_steps="${1:-}"
if [[ -n "$total_steps" ]]; then
step_header "5" "$total_steps" "Phone Calls"
else
section "Phone Calls"
fi
info "Tanya can call you and you can talk to her over the phone."
info "Uses ElevenLabs Conversational AI + a Twilio phone number."
echo
printf ' %s%sRequires:%s ElevenLabs API key + Agent ID + Twilio number\n' "$BOLD" "$WHITE" "$RESET"
printf ' %s(Twilio: free trial available with $15 credit)%s\n' "$DIM" "$RESET"
echo
if prompt_yes_no "Enable phone calls?" "$(default_yes_no "$DEFAULT_ENABLE_CALLS")"; then
ENABLE_CALLS=1
if [[ -z "$USER_PHONE" ]]; then
prompt_value USER_PHONE \
"Your phone number for calls" \
0 1 "$DEFAULT_USER_PHONE" \
"+919512345678" \
"Use full international format." \
validator_phone
fi
if [[ -z "$ELEVENLABS_API_KEY" ]]; then
key_help "ElevenLabs" \
"https://elevenlabs.io" \
"Create free account > Profile + API key (left sidebar) > copy key."
prompt_value ELEVENLABS_API_KEY \
"ElevenLabs API key" \
1 1 "$DEFAULT_ELEVENLABS_API_KEY" \
"sk_..." \
"" \
validator_any
else
good "Using the ElevenLabs API key already entered."
fi
echo
hint "Create an Agent in ElevenLabs > Agents > New Agent > copy the Agent ID."
key_help "ElevenLabs Agents" \
"https://elevenlabs.io/app/conversational-ai" \
"Create agent > configure voice & prompt > copy agent_id from settings."
prompt_value ELEVENLABS_AGENT_ID \
"ElevenLabs agent ID" \
0 1 "$DEFAULT_ELEVENLABS_AGENT_ID" \
"agent_4801kn0t38g8ehrae9rzvnq1x4d8" \
"" \
validator_any
echo
hint "Import your Twilio number into ElevenLabs to get a phone number ID."
key_help "Twilio" \
"https://console.twilio.com" \
"Create free account > buy a number > import into ElevenLabs Agents > Phone Numbers."
prompt_value ELEVENLABS_PHONE_NUMBER_ID \
"ElevenLabs phone number ID (from Twilio import)" \
0 1 "$DEFAULT_ELEVENLABS_PHONE_NUMBER_ID" \
"phnum_7901kn29j3zcfh1v9vphvvtaf624" \
"" \
validator_any
else
ENABLE_CALLS=0
info "Skipped. Enable later with ${BOLD}./setup configure${RESET}"
fi
}
# ─────────────────────────────────────────────────────────────
# Summary
# ─────────────────────────────────────────────────────────────
show_summary() {
echo
divider
section "Review Your Configuration"
status_line "Model:" "$MAIN_MODEL" "$CYAN"
status_line "Telegram bot:" "configured" "$GREEN"
echo
if [[ "$ENABLE_IMAGES" == "1" ]]; then
printf ' %s+%s Selfies & photos %senabled%s\n' "$GREEN" "$RESET" "$GREEN" "$RESET"
else
printf ' %s-%s Selfies & photos %sdisabled%s\n' "$DIM" "$RESET" "$DIM" "$RESET"
fi
if [[ "$ENABLE_VOICE" == "1" ]]; then
printf ' %s+%s Voice notes %senabled%s\n' "$GREEN" "$RESET" "$GREEN" "$RESET"
else
printf ' %s-%s Voice notes %sdisabled%s\n' "$DIM" "$RESET" "$DIM" "$RESET"
fi
if [[ "$ENABLE_WEB" == "1" ]]; then
printf ' %s+%s Web discovery %senabled%s\n' "$GREEN" "$RESET" "$GREEN" "$RESET"
else
printf ' %s-%s Web discovery %sdisabled%s\n' "$DIM" "$RESET" "$DIM" "$RESET"
fi
if [[ "$ENABLE_CALLS" == "1" ]]; then
printf ' %s+%s Phone calls %senabled%s\n' "$GREEN" "$RESET" "$GREEN" "$RESET"
else
printf ' %s-%s Phone calls %sdisabled%s\n' "$DIM" "$RESET" "$DIM" "$RESET"
fi
echo
}
# ─────────────────────────────────────────────────────────────
# Installation progress
# ─────────────────────────────────────────────────────────────
install_step() {
local label="$1"
printf ' %s...%s %s' "$DIM" "$RESET" "$label"
}
install_done() {
# Clear the entire line before printing the done message
printf '\r\033[2K %s+%s %s\n' "$GREEN" "$RESET" "$1"
}
# ─────────────────────────────────────────────────────────────
# Gateway and system operations
# ─────────────────────────────────────────────────────────────
ensure_gateway_running() {
section "OpenClaw Health Check"
install_step "Running openclaw doctor..."
if ! openclaw doctor --repair >/dev/null 2>&1; then
install_done "Doctor found issues (non-fatal)"
else
install_done "Doctor check passed"
fi
if openclaw gateway probe >/dev/null 2>&1; then
good "Gateway is running."
return 0
fi
install_step "Starting gateway..."
if ! openclaw gateway start >/dev/null 2>&1; then
printf '\n'
warn "Gateway start did not complete cleanly."
fi
local attempt
for attempt in 1 2 3 4 5 6 7 8 9 10; do
if openclaw gateway probe >/dev/null 2>&1; then
install_done "Gateway is ready"
return 0
fi
sleep 2
done
die "Gateway is still unreachable. Try: openclaw doctor --repair && openclaw gateway start"
}
# ─────────────────────────────────────────────────────────────
# Write runtime files (unchanged logic)
# ─────────────────────────────────────────────────────────────
write_runtime_files() {
export REPO_ROOT TARGET_ROOT TARGET_WORKSPACE TARGET_AGENT_DIR TARGET_SCRIPTS TARGET_MEDIA MAIN_MODEL MINI_MODEL
export USER_NAME TELEGRAM_USERNAME TELEGRAM_CHAT_ID USER_PHONE TELEGRAM_BOT_TOKEN OPENAI_API_KEY
export GOOGLE_API_KEY WEB_SEARCH_API_KEY ELEVENLABS_API_KEY ELEVENLABS_VOICE_ID ELEVENLABS_AGENT_ID ELEVENLABS_PHONE_NUMBER_ID
export ENABLE_IMAGES ENABLE_VOICE ENABLE_CALLS ENABLE_WEB GATEWAY_TOKEN MODE SETUP_LAST_RUN_COMMAND
python3 - <<'PY'
import json
import os
import pathlib
import shutil
from datetime import datetime, timezone
repo = pathlib.Path(os.environ["REPO_ROOT"])
target_root = pathlib.Path(os.environ["TARGET_ROOT"])
workspace = pathlib.Path(os.environ["TARGET_WORKSPACE"])
agent_dir = pathlib.Path(os.environ["TARGET_AGENT_DIR"])
scripts_dir = pathlib.Path(os.environ["TARGET_SCRIPTS"])
media_dir = pathlib.Path(os.environ["TARGET_MEDIA"])
mode = os.environ["MODE"]
enable_images = os.environ["ENABLE_IMAGES"] == "1"
enable_voice = os.environ["ENABLE_VOICE"] == "1"
enable_calls = os.environ["ENABLE_CALLS"] == "1"
enable_web = os.environ["ENABLE_WEB"] == "1"
google_key = os.environ.get("GOOGLE_API_KEY", "")
web_search_key = os.environ.get("WEB_SEARCH_API_KEY", "")
openai_key = os.environ["OPENAI_API_KEY"]
elevenlabs_key = os.environ.get("ELEVENLABS_API_KEY", "")
elevenlabs_voice_id = os.environ.get("ELEVENLABS_VOICE_ID", "")
elevenlabs_agent_id = os.environ.get("ELEVENLABS_AGENT_ID", "")
elevenlabs_phone_number_id = os.environ.get("ELEVENLABS_PHONE_NUMBER_ID", "")
for path in (workspace, workspace / "data", workspace / "memory", workspace / "skills", agent_dir, scripts_dir, media_dir):
path.mkdir(parents=True, exist_ok=True)
always_copy_static = [
"HEARTBEAT.md",
"IDENTITY.md",
"TOOLS.md",
"USER.md",
]
for name in always_copy_static:
shutil.copy2(repo / name, workspace / name)
if mode == "init":
shutil.copy2(repo / "MEMORY.md", workspace / "MEMORY.md")
for name in ("knowledge.md", "life.md", "relationship.md", "state.json"):
shutil.copy2(repo / "data" / name, workspace / "data" / name)
for memory_file in (repo / "memory").glob("*"):
if memory_file.is_file():
shutil.copy2(memory_file, workspace / "memory" / memory_file.name)
elif not (workspace / "MEMORY.md").exists():
shutil.copy2(repo / "MEMORY.md", workspace / "MEMORY.md")
for skill_file in (repo / "skills").glob("*.md"):
if skill_file.is_file():
shutil.copy2(skill_file, workspace / "skills" / skill_file.name)
for image_file in (repo / "tanya-image").glob("*"):
if image_file.is_file():
shutil.copy2(image_file, media_dir / image_file.name)
shutil.copy2(repo / "scripts" / "add_tanya_crons.sh", scripts_dir / "add_tanya_crons.sh")
shutil.copy2(repo / "scripts" / "call_user.sh", scripts_dir / "call_user.sh")
source_call = (repo / "scripts" / "call_user.sh").read_text()
if enable_calls:
source_call = source_call.replace("<ELEVENLABS_API_KEY>", elevenlabs_key)
source_call = source_call.replace("<ELEVENLABS_AGENT_ID>", elevenlabs_agent_id)
source_call = source_call.replace("<ELEVENLABS_PHONE_NUMBER_ID>", elevenlabs_phone_number_id)
(scripts_dir / "call_user.sh").write_text(source_call)
(scripts_dir / "call_user.sh").chmod(0o755)
(scripts_dir / "add_tanya_crons.sh").chmod(0o755)
agents_text = (repo / "AGENTS.md").read_text()
agents_text = agents_text.replace("<user-name>", os.environ["USER_NAME"])
agents_text = agents_text.replace("<telegram-username>", os.environ["TELEGRAM_USERNAME"])
agents_text = agents_text.replace("<telegram-chat-id>", os.environ["TELEGRAM_CHAT_ID"])
agents_text = agents_text.replace("<user-phone-number>", os.environ["USER_PHONE"])
(workspace / "AGENTS.md").write_text(agents_text)
def feature_line(name: str, enabled: bool, enabled_text: str, disabled_text: str) -> str:
if enabled:
return f"- {name}: enabled. {enabled_text}"
return f"- {name}: disabled. {disabled_text}"