GetResult 导出工具执行结果
(c *gin.Context)
| 88 | |
| 89 | // GetResult 导出工具执行结果 |
| 90 | func (h *ToolRuntimeHandler) GetResult(c *gin.Context) { |
| 91 | agentID := c.Query("agent_id") |
| 92 | callID := c.Param("id") |
| 93 | format := c.DefaultQuery("format", "json") |
| 94 | if agentID == "" || callID == "" { |
| 95 | c.JSON(http.StatusBadRequest, gin.H{"error": "agent_id and call id are required"}) |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | if snap := h.runtimeSnapshot(agentID, callID); snap != nil { |
| 100 | switch format { |
| 101 | case "json": |
| 102 | c.JSON(http.StatusOK, gin.H{"result": snap.Result, "error": snap.Error}) |
| 103 | default: |
| 104 | c.String(http.StatusOK, "%v", snap.Result) |
| 105 | } |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | records, err := (*h.store).LoadToolCallRecords(c.Request.Context(), agentID) |
| 110 | if err != nil { |
| 111 | c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) |
| 112 | return |
| 113 | } |
| 114 | |
| 115 | for _, rec := range records { |
| 116 | if rec.ID != callID { |
| 117 | continue |
| 118 | } |
| 119 | switch format { |
| 120 | case "json": |
| 121 | c.JSON(http.StatusOK, gin.H{"result": rec.Result, "error": rec.Error}) |
| 122 | default: |
| 123 | c.String(http.StatusOK, "%v", rec.Result) |
| 124 | } |
| 125 | return |
| 126 | } |
| 127 | |
| 128 | c.JSON(http.StatusNotFound, gin.H{"error": "call not found"}) |
| 129 | } |
| 130 | |
| 131 | func (h *ToolRuntimeHandler) runtimeSnapshot(agentID, callID string) *types.ToolCallSnapshot { |
| 132 | if h.reg == nil { |
nothing calls this directly
no test coverage detected