ListRunning 返回运行中的工具调用
(c *gin.Context)
| 53 | |
| 54 | // ListRunning 返回运行中的工具调用 |
| 55 | func (h *ToolRuntimeHandler) ListRunning(c *gin.Context) { |
| 56 | agentID := c.Query("agent_id") |
| 57 | if agentID == "" { |
| 58 | c.JSON(http.StatusBadRequest, gin.H{"error": "agent_id is required"}) |
| 59 | return |
| 60 | } |
| 61 | |
| 62 | // 优先返回实时运行表 |
| 63 | if h.reg != nil { |
| 64 | if ag := h.reg.Get(agentID); ag != nil { |
| 65 | c.JSON(http.StatusOK, gin.H{"running": ag.ListRunningToolSnapshots()}) |
| 66 | return |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | records, err := (*h.store).LoadToolCallRecords(c.Request.Context(), agentID) |
| 71 | if err != nil { |
| 72 | c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | running := make([]types.ToolCallSnapshot, 0) |
| 77 | for _, rec := range records { |
| 78 | if rec.State == types.ToolCallStateExecuting || rec.State == types.ToolCallStateQueued || rec.State == types.ToolCallStatePending || rec.State == types.ToolCallStateCancelling { |
| 79 | snapshot := mapRecordToSnapshot(&rec) |
| 80 | running = append(running, snapshot) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | c.JSON(http.StatusOK, gin.H{ |
| 85 | "running": running, |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | // GetResult 导出工具执行结果 |
| 90 | func (h *ToolRuntimeHandler) GetResult(c *gin.Context) { |
nothing calls this directly
no test coverage detected