MCPcopy Create free account
hub / github.com/astercloud/aster / GetTaskStatus

Method GetTaskStatus

pkg/a2a/handler.go:214–299  ·  view source on GitHub ↗

GetTaskStatus 获取任务状态的便捷端点 GET /a2a/{agentId}/tasks/{taskId}

(c *gin.Context)

Source from the content-addressed store, hash-verified

212// GetTaskStatus 获取任务状态的便捷端点
213// GET /a2a/{agentId}/tasks/{taskId}
214func (h *Handler) GetTaskStatus(c *gin.Context) {
215 ctx := c.Request.Context()
216 agentID := c.Param("agentId")
217 taskID := c.Param("taskId")
218
219 if agentID == "" || taskID == "" {
220 c.JSON(http.StatusBadRequest, gin.H{
221 "success": false,
222 "error": gin.H{
223 "code": "bad_request",
224 "message": "Missing agentId or taskId parameter",
225 },
226 })
227 return
228 }
229
230 logging.Info(ctx, "a2a.get_task_status", map[string]any{
231 "agent_id": agentID,
232 "task_id": taskID,
233 })
234
235 // 构造 tasks/get JSON-RPC 请求
236 params := TasksGetParams{
237 TaskID: taskID,
238 }
239 paramsJSON, _ := json.Marshal(params)
240
241 req := &JSONRPCRequest{
242 JSONRPC: "2.0",
243 ID: taskID, // 使用 taskID 作为请求 ID
244 Method: "tasks/get",
245 Params: paramsJSON,
246 }
247
248 resp := h.server.HandleRequest(ctx, agentID, req)
249
250 if resp.Error != nil {
251 var statusCode int
252 switch resp.Error.Code {
253 case -32602: // Invalid params
254 statusCode = http.StatusBadRequest
255 case -32001: // Task not found
256 statusCode = http.StatusNotFound
257 default:
258 statusCode = http.StatusInternalServerError
259 }
260
261 c.JSON(statusCode, gin.H{
262 "success": false,
263 "error": gin.H{
264 "code": resp.Error.Message,
265 "message": fmt.Sprintf("%v", resp.Error.Data),
266 },
267 })
268 return
269 }
270
271 // 解析任务响应

Callers

nothing calls this directly

Calls 4

InfoFunction · 0.92
JSONMethod · 0.80
HandleRequestMethod · 0.80
ContextMethod · 0.65

Tested by

no test coverage detected