refactor: 项目结构重组,src/ 扁平化为根目录,提取 pkg/ 子包
- 模块名重命名 yunshu -> hub.gaomia.site/titor/YunShu - Go 版本升级 1.21 -> 1.25 - src/ 目录删除,所有文件移至根目录 - 新增 pkg/mdprint/: Markdown AST 解析+ANSI 渲染 - 新增 pkg/style/: 终端颜色样式(8色 ANSI + 24位真彩色) - 新增 pkg/termui/: 终端输入组件(交互式输入/密码/确认) - 更新文档:AGENTS.md、architecture.md、changelog.md、taolun.md - gitignore 通配符修复 yunshu.exe -> yunshu.exe*
This commit is contained in:
101
onboard.go
Normal file
101
onboard.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"hub.gaomia.site/titor/YunShu/pkg/style"
|
||||
"hub.gaomia.site/titor/YunShu/pkg/termui"
|
||||
)
|
||||
|
||||
func runOnboard() {
|
||||
fmt.Println()
|
||||
fmt.Println(style.Cyan.Render("☁ 云枢·Agent · 初始化配置"))
|
||||
fmt.Println()
|
||||
fmt.Println("配置说明 · 以下信息将保存在", style.Dim.Render(ConfigDir()))
|
||||
fmt.Println()
|
||||
|
||||
host := termui.TextInput("LLM 接口地址",
|
||||
termui.WithRequired(true),
|
||||
termui.WithHelp("支持 OpenAI 兼容格式"),
|
||||
termui.WithDefault("https://ark.cn-beijing.volces.com/api/v3/chat/completions"),
|
||||
termui.WithValidator(termui.And(termui.NonEmpty, termui.IsURL)),
|
||||
)
|
||||
|
||||
key := termui.PasswordInput("API Key",
|
||||
termui.WithRequired(true),
|
||||
termui.WithHelp("输入已隐藏"),
|
||||
termui.WithValidator(termui.NonEmpty),
|
||||
)
|
||||
|
||||
model := termui.TextInput("模型名称",
|
||||
termui.WithHelp("默认: doubao-seed-2-0-pro-260215"),
|
||||
termui.WithDefault("doubao-seed-2-0-pro-260215"),
|
||||
)
|
||||
|
||||
fmt.Println()
|
||||
ok := termui.Confirm("保存配置?", true)
|
||||
if !ok {
|
||||
fmt.Println(style.Yellow.Render("取消配置"))
|
||||
return
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
LLM: LLMConfig{
|
||||
Host: host,
|
||||
Model: model,
|
||||
Key: key,
|
||||
},
|
||||
}
|
||||
|
||||
if err := SaveConfig(cfg); err != nil {
|
||||
fmt.Fprintln(os.Stderr, style.Red.Render("保存配置失败: "+err.Error()))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
CopyDefaultDir("agents", "agents")
|
||||
CopyDefaultDir("skills", "skills")
|
||||
CopyDefaultDir("data", "data")
|
||||
|
||||
fmt.Println()
|
||||
|
||||
testOk := termui.Confirm("测试连通性?", true)
|
||||
if testOk {
|
||||
testLLM()
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println(style.Green.Render("✔ 配置完成!"))
|
||||
fmt.Println(" 配置文件:", style.Dim.Render(filepath.Join(ConfigDir(), "config.yaml")))
|
||||
fmt.Println()
|
||||
fmt.Println(" 运行示例:")
|
||||
fmt.Println(" " + style.Cyan.Render("yunshu \"北京今天天气\""))
|
||||
fmt.Println(" " + style.Cyan.Render("yunshu"))
|
||||
}
|
||||
|
||||
func testLLM() {
|
||||
fmt.Print(style.Dim.Render("测试中 ..."))
|
||||
|
||||
oldKey, oldHost, oldModel := llmKey, llmHost, llmModel
|
||||
defer func() {
|
||||
llmKey, llmHost, llmModel = oldKey, oldHost, oldModel
|
||||
}()
|
||||
|
||||
cfg, err := LoadConfig()
|
||||
if err != nil {
|
||||
fmt.Println(style.Red.Render("\r⚠ 读取配置失败: " + err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
llmKey, llmHost, llmModel = cfg.LLM.Key, cfg.LLM.Host, cfg.LLM.Model
|
||||
|
||||
msg := Message{Role: RoleUser, Content: "ping"}
|
||||
_, err = CallLLM([]Message{msg}, nil)
|
||||
if err != nil {
|
||||
fmt.Println(style.Red.Render("\r⚠ 连接失败: " + err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(style.Green.Render("\r✔ 连接成功!"))
|
||||
}
|
||||
Reference in New Issue
Block a user