add
This commit is contained in:
Binary file not shown.
@@ -461,23 +461,30 @@ func GenerateAndWriteConfig(opts ConfigOptions) error {
|
|||||||
},
|
},
|
||||||
Tools: ToolsConfig{
|
Tools: ToolsConfig{
|
||||||
Elevated: ElevatedConfig{
|
Elevated: ElevatedConfig{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
AllowFrom: map[string][]string{
|
AllowFrom: map[string][]string{},
|
||||||
"telegram": {opts.AdminID},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Allow: []string{"exec", "process", "read", "write", "edit", "web_search", "web_fetch", "cron"},
|
Allow: []string{"exec", "process", "read", "write", "edit", "web_search", "web_fetch", "cron"},
|
||||||
},
|
},
|
||||||
Channels: ChannelsConfig{
|
Channels: ChannelsConfig{
|
||||||
Telegram: TelegramConfig{
|
Telegram: TelegramConfig{
|
||||||
Enabled: true,
|
Enabled: false,
|
||||||
BotToken: opts.BotToken,
|
|
||||||
DMPolicy: "pairing",
|
DMPolicy: "pairing",
|
||||||
AllowFrom: []string{opts.AdminID},
|
AllowFrom: []string{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure Telegram if token provided
|
||||||
|
if opts.BotToken != "" {
|
||||||
|
config.Channels.Telegram.Enabled = true
|
||||||
|
config.Channels.Telegram.BotToken = opts.BotToken
|
||||||
|
if opts.AdminID != "" {
|
||||||
|
config.Channels.Telegram.AllowFrom = []string{opts.AdminID}
|
||||||
|
config.Tools.Elevated.AllowFrom["telegram"] = []string{opts.AdminID}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if opts.ApiType == "anthropic" {
|
if opts.ApiType == "anthropic" {
|
||||||
config.Env = map[string]string{
|
config.Env = map[string]string{
|
||||||
"ANTHROPIC_API_KEY": opts.AnthropicKey,
|
"ANTHROPIC_API_KEY": opts.AnthropicKey,
|
||||||
@@ -489,6 +496,16 @@ func GenerateAndWriteConfig(opts ConfigOptions) error {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
} else if opts.ApiType == "skip" {
|
||||||
|
// Minimal config for Web UI setup
|
||||||
|
config.Channels.Telegram.Enabled = false
|
||||||
|
config.Agents = AgentsConfig{
|
||||||
|
Defaults: AgentDefaults{
|
||||||
|
Model: ModelRef{
|
||||||
|
Primary: "anthropic/claude-opus-4-5", // Default placeholder
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// OpenAI Compatible
|
// OpenAI Compatible
|
||||||
config.Agents = AgentsConfig{
|
config.Agents = AgentsConfig{
|
||||||
|
|||||||
@@ -159,14 +159,14 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.configOpts.ApiType = "anthropic"
|
m.configOpts.ApiType = "anthropic"
|
||||||
m.state = StateConfigInput
|
m.state = StateConfigInput
|
||||||
m.configStep = 0
|
m.configStep = 0
|
||||||
m.input.Placeholder = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
|
m.input.Placeholder = "sk-ant-api03-..."
|
||||||
m.input.EchoMode = textinput.EchoNormal
|
m.input.EchoMode = textinput.EchoPassword
|
||||||
m.input.SetValue("")
|
m.input.SetValue("")
|
||||||
case "2":
|
case "2":
|
||||||
m.configOpts.ApiType = "openai"
|
m.configOpts.ApiType = "openai"
|
||||||
m.state = StateConfigInput
|
m.state = StateConfigInput
|
||||||
m.configStep = 0
|
m.configStep = 0
|
||||||
m.input.Placeholder = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
|
m.input.Placeholder = "https://api.openai.com/v1"
|
||||||
m.input.EchoMode = textinput.EchoNormal
|
m.input.EchoMode = textinput.EchoNormal
|
||||||
m.input.SetValue("")
|
m.input.SetValue("")
|
||||||
case "q", "esc":
|
case "q", "esc":
|
||||||
@@ -180,46 +180,57 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "enter":
|
case "enter":
|
||||||
val := m.input.Value()
|
val := m.input.Value()
|
||||||
// Save current step value
|
// Step logic:
|
||||||
switch m.configStep {
|
// Anthropic: 0(Key) -> 1(TG Token) -> 2(TG ID) -> Finish
|
||||||
case 0: // Bot Token
|
// OpenAI: 0(BaseURL) -> 1(Key) -> 2(Model) -> 3(TG Token) -> 4(TG ID) -> Finish
|
||||||
m.configOpts.BotToken = val
|
|
||||||
m.configStep++
|
if m.configOpts.ApiType == "anthropic" {
|
||||||
m.input.Placeholder = "123456789"
|
switch m.configStep {
|
||||||
m.input.SetValue("")
|
case 0: // API Key
|
||||||
case 1: // Admin ID
|
|
||||||
m.configOpts.AdminID = val
|
|
||||||
m.configStep++
|
|
||||||
if m.configOpts.ApiType == "anthropic" {
|
|
||||||
m.input.Placeholder = "sk-ant-api03-..."
|
|
||||||
m.input.EchoMode = textinput.EchoPassword
|
|
||||||
} else {
|
|
||||||
m.input.Placeholder = "https://api.openai.com/v1"
|
|
||||||
m.input.EchoMode = textinput.EchoNormal
|
|
||||||
}
|
|
||||||
m.input.SetValue("")
|
|
||||||
case 2: // Key (Anthropic) OR BaseURL (OpenAI)
|
|
||||||
if m.configOpts.ApiType == "anthropic" {
|
|
||||||
m.configOpts.AnthropicKey = val
|
m.configOpts.AnthropicKey = val
|
||||||
// Finish Anthropic
|
m.configStep++
|
||||||
|
m.input.Placeholder = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
|
||||||
|
m.input.EchoMode = textinput.EchoNormal
|
||||||
|
m.input.SetValue("")
|
||||||
|
case 1: // TG Token
|
||||||
|
m.configOpts.BotToken = val
|
||||||
|
m.configStep++
|
||||||
|
m.input.Placeholder = "123456789"
|
||||||
|
m.input.SetValue("")
|
||||||
|
case 2: // TG Admin ID
|
||||||
|
m.configOpts.AdminID = val
|
||||||
return m, saveConfigCmd(m.configOpts)
|
return m, saveConfigCmd(m.configOpts)
|
||||||
} else {
|
}
|
||||||
|
} else {
|
||||||
|
// OpenAI
|
||||||
|
switch m.configStep {
|
||||||
|
case 0: // BaseURL
|
||||||
m.configOpts.OpenAIBaseURL = val
|
m.configOpts.OpenAIBaseURL = val
|
||||||
m.configStep++
|
m.configStep++
|
||||||
m.input.Placeholder = "sk-..."
|
m.input.Placeholder = "sk-..."
|
||||||
m.input.EchoMode = textinput.EchoPassword
|
m.input.EchoMode = textinput.EchoPassword
|
||||||
m.input.SetValue("")
|
m.input.SetValue("")
|
||||||
|
case 1: // Key
|
||||||
|
m.configOpts.OpenAIKey = val
|
||||||
|
m.configStep++
|
||||||
|
m.input.Placeholder = "gpt-4o / claude-3-5-sonnet"
|
||||||
|
m.input.EchoMode = textinput.EchoNormal
|
||||||
|
m.input.SetValue("")
|
||||||
|
case 2: // Model
|
||||||
|
m.configOpts.OpenAIModel = val
|
||||||
|
m.configStep++
|
||||||
|
m.input.Placeholder = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
|
||||||
|
m.input.EchoMode = textinput.EchoNormal
|
||||||
|
m.input.SetValue("")
|
||||||
|
case 3: // TG Token
|
||||||
|
m.configOpts.BotToken = val
|
||||||
|
m.configStep++
|
||||||
|
m.input.Placeholder = "123456789"
|
||||||
|
m.input.SetValue("")
|
||||||
|
case 4: // TG Admin ID
|
||||||
|
m.configOpts.AdminID = val
|
||||||
|
return m, saveConfigCmd(m.configOpts)
|
||||||
}
|
}
|
||||||
case 3: // Key (OpenAI)
|
|
||||||
m.configOpts.OpenAIKey = val
|
|
||||||
m.configStep++
|
|
||||||
m.input.Placeholder = "gpt-4o / claude-3-5-sonnet"
|
|
||||||
m.input.EchoMode = textinput.EchoNormal
|
|
||||||
m.input.SetValue("")
|
|
||||||
case 4: // Model (OpenAI)
|
|
||||||
m.configOpts.OpenAIModel = val
|
|
||||||
// Finish OpenAI
|
|
||||||
return m, saveConfigCmd(m.configOpts)
|
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
@@ -430,7 +441,7 @@ func (m Model) View() string {
|
|||||||
|
|
||||||
case StateConfigApiSelect:
|
case StateConfigApiSelect:
|
||||||
s += style.HeaderStyle.Render("配置向导 - 选择 API 类型") + "\n\n"
|
s += style.HeaderStyle.Render("配置向导 - 选择 API 类型") + "\n\n"
|
||||||
s += "1. Anthropic 官方 API\n"
|
s += "1. Anthropic 官方 API (推荐)\n"
|
||||||
s += "2. OpenAI 兼容 API (中转站/其他模型)\n\n"
|
s += "2. OpenAI 兼容 API (中转站/其他模型)\n\n"
|
||||||
s += style.SubtleStyle.Render("按 1 或 2 选择,Esc 返回") + "\n"
|
s += style.SubtleStyle.Render("按 1 或 2 选择,Esc 返回") + "\n"
|
||||||
|
|
||||||
@@ -438,25 +449,36 @@ func (m Model) View() string {
|
|||||||
s += style.HeaderStyle.Render("配置向导") + "\n\n"
|
s += style.HeaderStyle.Render("配置向导") + "\n\n"
|
||||||
|
|
||||||
label := ""
|
label := ""
|
||||||
switch m.configStep {
|
if m.configOpts.ApiType == "anthropic" {
|
||||||
case 0:
|
switch m.configStep {
|
||||||
label = "Telegram Bot Token:"
|
case 0:
|
||||||
case 1:
|
|
||||||
label = "Telegram User ID (管理员):"
|
|
||||||
case 2:
|
|
||||||
if m.configOpts.ApiType == "anthropic" {
|
|
||||||
label = "Anthropic API Key (sk-ant-...):"
|
label = "Anthropic API Key (sk-ant-...):"
|
||||||
} else {
|
case 1:
|
||||||
label = "API Base URL (例如 https://api.example.com/v1):"
|
label = "Telegram Bot Token (选填, 回车跳过):"
|
||||||
|
case 2:
|
||||||
|
label = "Telegram User ID (管理员) (选填, 回车跳过):"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// OpenAI
|
||||||
|
switch m.configStep {
|
||||||
|
case 0:
|
||||||
|
label = "API Base URL (例如 https://api.example.com/v1):"
|
||||||
|
case 1:
|
||||||
|
label = "API Key:"
|
||||||
|
case 2:
|
||||||
|
label = "模型名称 (例如 gpt-4o):"
|
||||||
|
case 3:
|
||||||
|
label = "Telegram Bot Token (选填, 回车跳过):"
|
||||||
|
case 4:
|
||||||
|
label = "Telegram User ID (管理员) (选填, 回车跳过):"
|
||||||
}
|
}
|
||||||
case 3:
|
|
||||||
label = "API Key:"
|
|
||||||
case 4:
|
|
||||||
label = "模型名称 (例如 gpt-4o):"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s += fmt.Sprintf("%s\n\n%s\n\n", label, m.input.View())
|
s += fmt.Sprintf("%s\n\n%s\n\n", label, m.input.View())
|
||||||
s += style.SubtleStyle.Render("按 Enter 确认") + "\n"
|
s += style.SubtleStyle.Render("按 Enter 确认") + "\n"
|
||||||
|
if (m.configOpts.ApiType == "anthropic" && m.configStep >= 1) || (m.configOpts.ApiType == "openai" && m.configStep >= 3) {
|
||||||
|
s += style.SubtleStyle.Render("跳过后可通过 http://127.0.0.1:18789/ Web UI 交互") + "\n"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return style.AppStyle.Render(s)
|
return style.AppStyle.Render(s)
|
||||||
|
|||||||
Reference in New Issue
Block a user