DeactivateTool 停用工具(移回延迟状态)
(name string)
| 192 | |
| 193 | // DeactivateTool 停用工具(移回延迟状态) |
| 194 | func (tm *ToolManager) DeactivateTool(name string) error { |
| 195 | tm.mu.Lock() |
| 196 | defer tm.mu.Unlock() |
| 197 | |
| 198 | ctx := context.Background() // 用于日志记录 |
| 199 | |
| 200 | // 不能停用核心工具 |
| 201 | if tm.isCoreToolLocked(name) { |
| 202 | return fmt.Errorf("cannot deactivate core tool: %s", name) |
| 203 | } |
| 204 | |
| 205 | // 检查是否在活跃工具列表中 |
| 206 | tool, ok := tm.activeTools[name] |
| 207 | if !ok { |
| 208 | return nil // 已经不活跃 |
| 209 | } |
| 210 | |
| 211 | // 移动到延迟工具列表 |
| 212 | entry := tm.index.GetTool(name) |
| 213 | if entry != nil { |
| 214 | entry.Deferred = true |
| 215 | tm.deferredTools[name] = *entry |
| 216 | if err := tm.index.IndexToolEntry(*entry); err != nil { |
| 217 | toolMgrLog.Warn(ctx, "failed to update tool index", map[string]any{"error": err}) |
| 218 | } |
| 219 | } |
| 220 | delete(tm.activeTools, name) |
| 221 | |
| 222 | toolMgrLog.Debug(ctx, "tool deactivated", map[string]any{"name": name, "tool_type": fmt.Sprintf("%T", tool)}) |
| 223 | return nil |
| 224 | } |
| 225 | |
| 226 | // AddTool 添加新工具 |
| 227 | func (tm *ToolManager) AddTool(tool tools.Tool, source string, deferred bool) error { |
nothing calls this directly
no test coverage detected