feat: Round 5 - Memory Service, Tool Engine, Call Records, Thinking Logs
- Fix: Session history flash (race condition + WS guard) - Fix: Chat background overlay + sidebar transparency - Fix: IoT device control (Chinese action names, status field) - Feat: Independent memory-service (port 8091, 13 endpoints) - Feat: Independent tool-engine service (port 8092, 13 tools) - Feat: Tool call logs with paginated DevTools panel - Feat: Thinking log records with DevTools panel - Feat: Future development roadmap document - Chore: Updated .gitignore, go.work, DevTools config - Chore: 5-service health check, project review docs
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/yourname/cyrene-ai/tool-engine/internal/config"
|
||||
"github.com/yourname/cyrene-ai/tool-engine/internal/handler"
|
||||
"github.com/yourname/cyrene-ai/tool-engine/internal/service"
|
||||
"github.com/yourname/cyrene-ai/tool-engine/internal/store"
|
||||
"github.com/yourname/cyrene-ai/tool-engine/internal/tools"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||
log.Println("🔧 Tool-Engine 启动中...")
|
||||
|
||||
// 加载配置
|
||||
cfg := config.Load()
|
||||
|
||||
log.Printf("配置: 端口=%s, IoT服务=%s, 数据目录=%s, DB=%s", cfg.Port, cfg.IoTServiceURL, cfg.DataDir, cfg.DBUrl)
|
||||
|
||||
// 初始化调用日志存储
|
||||
callLogStore, err := store.NewCallLogStore(cfg.DBUrl)
|
||||
if err != nil {
|
||||
log.Printf("[main] 初始化调用日志存储失败: %v", err)
|
||||
callLogStore = nil
|
||||
}
|
||||
|
||||
// 初始化 IoT 客户端
|
||||
var iotClient tools.IoTClientInterface
|
||||
if cfg.IoTServiceURL != "" {
|
||||
iotClient = tools.NewIoTClient(cfg.IoTServiceURL)
|
||||
log.Printf("[main] IoT 客户端已初始化: %s", cfg.IoTServiceURL)
|
||||
} else {
|
||||
log.Println("[main] IoT 服务 URL 未配置,IoT 工具将不可用")
|
||||
}
|
||||
|
||||
// 初始化服务层
|
||||
svc := service.NewToolService(iotClient, cfg.DataDir)
|
||||
|
||||
// 初始化 HTTP 处理器
|
||||
h := handler.NewToolHandler(svc, callLogStore)
|
||||
|
||||
// 注册路由
|
||||
mux := http.NewServeMux()
|
||||
h.RegisterRoutes(mux)
|
||||
|
||||
// 健康检查端点
|
||||
mux.HandleFunc("/api/v1/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(`{"status":"ok","service":"tool-engine"}`))
|
||||
})
|
||||
|
||||
// 启动 HTTP 服务
|
||||
srv := &http.Server{
|
||||
Addr: ":" + cfg.Port,
|
||||
Handler: mux,
|
||||
}
|
||||
|
||||
go func() {
|
||||
log.Printf("🚀 Tool-Engine 已启动在端口 %s", cfg.Port)
|
||||
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Fatalf("服务启动失败: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// 优雅关闭
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-quit
|
||||
log.Println("正在关闭 Tool-Engine...")
|
||||
|
||||
if callLogStore != nil {
|
||||
callLogStore.Close()
|
||||
}
|
||||
srv.Close()
|
||||
log.Println("Tool-Engine 已关闭")
|
||||
}
|
||||
Reference in New Issue
Block a user