87214b9441
Phase 1 (基础设施): - ThinkChain 思考链连续性 + 差异化思考提示词 (persistent) - AutonomousToolPolicy 工具安全策略 (safe/unsafe/conditional) - MessageScheduler 自适应消息节奏 (Idle/Available/Busy) - SessionEnrichmentStore 渐进式上下文丰富 (5层) - ConversationBus 事件总线 + ResponseCache (dedup) - pkg/logger 统一日志 + 所有 handler 替换 fmt.Printf - NPE 守卫/链路优化/数据库表修复/Go workspace Phase 2 (人格交互): - EmotionState/EmotionTracker 情感状态机 (5种心情, 情绪衰减) - ProactiveGuard 主动消息多维决策 (静默时段/紧急度/频率/校验) - Gateway↔ai-core 在线状态感知链路 (presence notification) - 离线思考频率控制 + 重连问候 + 离线消息排队 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/yourname/cyrene-ai/pkg/logger"
|
|
"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() {
|
|
logger.SetDefault(logger.New("tool-engine"))
|
|
logger.Println("🔧 Tool-Engine 启动中...")
|
|
|
|
// 加载配置
|
|
cfg := config.Load()
|
|
|
|
logger.Printf("配置: 端口=%s, IoT服务=%s, 数据目录=%s, DB=%s", cfg.Port, cfg.IoTServiceURL, cfg.DataDir, cfg.DBUrl)
|
|
|
|
// 初始化调用日志存储
|
|
callLogStore, err := store.NewCallLogStore(cfg.DBUrl)
|
|
if err != nil {
|
|
logger.Printf("[main] 初始化调用日志存储失败: %v", err)
|
|
callLogStore = nil
|
|
}
|
|
|
|
// 初始化 IoT 客户端
|
|
var iotClient tools.IoTClientInterface
|
|
if cfg.IoTServiceURL != "" {
|
|
iotClient = tools.NewIoTClient(cfg.IoTServiceURL)
|
|
logger.Printf("[main] IoT 客户端已初始化: %s", cfg.IoTServiceURL)
|
|
} else {
|
|
logger.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() {
|
|
logger.Printf("🚀 Tool-Engine 已启动在端口 %s", cfg.Port)
|
|
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
logger.Fatalf("服务启动失败: %v", err)
|
|
}
|
|
}()
|
|
|
|
// 优雅关闭
|
|
quit := make(chan os.Signal, 1)
|
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
<-quit
|
|
logger.Println("正在关闭 Tool-Engine...")
|
|
|
|
if callLogStore != nil {
|
|
callLogStore.Close()
|
|
}
|
|
srv.Close()
|
|
logger.Println("Tool-Engine 已关闭")
|
|
}
|