feat: 更新 Server 后端服务
- 更新 agent handler 和 service 层 - 新增 chat_group handler 和 service - 删除废弃的 chat_handler - 更新 tool 相关处理 - 更新 API 文档和依赖 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,56 @@ func (s *ToolService) InitDefaultTools() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SyncToolsFromPython 从Python端同步工具
|
||||
func (s *ToolService) SyncToolsFromPython(pythonTools []map[string]interface{}) (int, error) {
|
||||
count := 0
|
||||
for _, pt := range pythonTools {
|
||||
// 提取工具信息
|
||||
name, _ := pt["name"].(string)
|
||||
description, _ := pt["description"].(string)
|
||||
parameters, _ := pt["parameters"].(string)
|
||||
category, _ := pt["category"].(string)
|
||||
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查工具是否已存在
|
||||
existing, err := s.toolRepo.FindByName(name)
|
||||
if err == nil && existing != nil {
|
||||
// 更新现有工具
|
||||
existing.Description = description
|
||||
existing.Parameters = parameters
|
||||
if category != "" {
|
||||
existing.Category = category
|
||||
}
|
||||
if err := s.toolRepo.Update(existing); err != nil {
|
||||
log.Printf("[ToolService] Failed to update tool %s: %v", name, err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
// 创建新工具
|
||||
tool := model.Tool{
|
||||
Name: name,
|
||||
Description: description,
|
||||
Parameters: parameters,
|
||||
Category: category,
|
||||
Provider: "python",
|
||||
Status: "active",
|
||||
SecurityLevel: "safe",
|
||||
RequireApproval: false,
|
||||
}
|
||||
if err := s.toolRepo.Create(&tool); err != nil {
|
||||
log.Printf("[ToolService] Failed to create tool %s: %v", name, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
count++
|
||||
}
|
||||
log.Printf("[ToolService] Synced %d tools from Python", count)
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// getDefaultTools 获取默认工具列表
|
||||
func (s *ToolService) getDefaultTools() []model.Tool {
|
||||
return []model.Tool{
|
||||
|
||||
Reference in New Issue
Block a user