-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
130 lines (115 loc) · 2.91 KB
/
config.go
File metadata and controls
130 lines (115 loc) · 2.91 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
package main
import (
"fmt"
"os"
"strconv"
"strings"
"time"
)
type Config struct {
TelegramToken string
AllowedChatIDs map[int64]bool
WorkDir string
ClaudePath string
GeminiAPIKey string
GeminiModel string
DefaultProvider string
CommandTimeout time.Duration
AllowedTools []string
SkipPermissions bool
SystemPrompt string
MaxToolRounds int
WhisperCmd string
GitSSHKey string
GitlabToken string
GitUserName string
GitUserEmail string
NgrokToken string
}
func LoadConfig() (*Config, error) {
token := os.Getenv("TELEGRAM_BOT_TOKEN")
if token == "" {
return nil, fmt.Errorf("TELEGRAM_BOT_TOKEN is required")
}
allowedRaw := os.Getenv("ALLOWED_CHAT_IDS")
if allowedRaw == "" {
return nil, fmt.Errorf("ALLOWED_CHAT_IDS is required")
}
allowed := make(map[int64]bool)
for _, s := range strings.Split(allowedRaw, ",") {
s = strings.TrimSpace(s)
if s == "" {
continue
}
id, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid chat ID %q: %v", s, err)
}
allowed[id] = true
}
workDir := os.Getenv("WORK_DIR")
if workDir == "" {
workDir = "."
}
claudePath := os.Getenv("CLAUDE_PATH")
if claudePath == "" {
claudePath = "claude"
}
geminiModel := os.Getenv("GEMINI_MODEL")
if geminiModel == "" {
geminiModel = "gemini-2.5-flash"
}
defaultProvider := os.Getenv("DEFAULT_PROVIDER")
if defaultProvider == "" {
defaultProvider = "claude"
}
timeout := 5 * time.Minute
if t := os.Getenv("COMMAND_TIMEOUT"); t != "" {
var err error
timeout, err = time.ParseDuration(t)
if err != nil {
return nil, fmt.Errorf("invalid COMMAND_TIMEOUT %q: %v", t, err)
}
}
var allowedTools []string
if toolsRaw := os.Getenv("ALLOWED_TOOLS"); toolsRaw != "" {
for _, t := range strings.Split(toolsRaw, ",") {
t = strings.TrimSpace(t)
if t != "" {
allowedTools = append(allowedTools, t)
}
}
}
skipPerms := os.Getenv("SKIP_PERMISSIONS") == "true"
systemPrompt := os.Getenv("SYSTEM_PROMPT")
whisperCmd := os.Getenv("WHISPER_CMD")
if whisperCmd == "" {
whisperCmd = "whisper"
}
maxRounds := 20
if r := os.Getenv("MAX_TOOL_ROUNDS"); r != "" {
if v, err := strconv.Atoi(r); err == nil && v > 0 {
maxRounds = v
}
}
return &Config{
TelegramToken: token,
AllowedChatIDs: allowed,
WorkDir: workDir,
ClaudePath: claudePath,
GeminiAPIKey: os.Getenv("GEMINI_API_KEY"),
GeminiModel: geminiModel,
DefaultProvider: defaultProvider,
CommandTimeout: timeout,
AllowedTools: allowedTools,
SkipPermissions: skipPerms,
SystemPrompt: systemPrompt,
MaxToolRounds: maxRounds,
WhisperCmd: whisperCmd,
GitSSHKey: os.Getenv("GIT_SSH_KEY"),
GitlabToken: os.Getenv("GITLAB_TOKEN"),
GitUserName: os.Getenv("GIT_USER_NAME"),
GitUserEmail: os.Getenv("GIT_USER_EMAIL"),
NgrokToken: os.Getenv("NGROK_AUTHTOKEN"),
}, nil
}