Execute executes a tool
(c *gin.Context)
| 294 | |
| 295 | // Execute executes a tool |
| 296 | func (h *ToolHandler) Execute(c *gin.Context) { |
| 297 | ctx := c.Request.Context() |
| 298 | id := c.Param("id") |
| 299 | |
| 300 | var req struct { |
| 301 | Input map[string]any `json:"input" binding:"required"` |
| 302 | } |
| 303 | |
| 304 | if err := c.ShouldBindJSON(&req); err != nil { |
| 305 | c.JSON(http.StatusBadRequest, gin.H{ |
| 306 | "success": false, |
| 307 | "error": gin.H{ |
| 308 | "code": "bad_request", |
| 309 | "message": err.Error(), |
| 310 | }, |
| 311 | }) |
| 312 | return |
| 313 | } |
| 314 | |
| 315 | // Check if tool exists |
| 316 | var tool ToolRecord |
| 317 | if err := (*h.store).Get(ctx, "tools", id, &tool); err != nil { |
| 318 | if errors.Is(err, store.ErrNotFound) { |
| 319 | c.JSON(http.StatusNotFound, gin.H{ |
| 320 | "success": false, |
| 321 | "error": gin.H{ |
| 322 | "code": "not_found", |
| 323 | "message": "Tool not found", |
| 324 | }, |
| 325 | }) |
| 326 | return |
| 327 | } |
| 328 | c.JSON(http.StatusInternalServerError, gin.H{ |
| 329 | "success": false, |
| 330 | "error": gin.H{ |
| 331 | "code": "internal_error", |
| 332 | "message": err.Error(), |
| 333 | }, |
| 334 | }) |
| 335 | return |
| 336 | } |
| 337 | |
| 338 | // Create execution record |
| 339 | execution := &ToolExecution{ |
| 340 | ID: uuid.New().String(), |
| 341 | ToolID: id, |
| 342 | Input: req.Input, |
| 343 | Status: "pending", |
| 344 | StartedAt: time.Now(), |
| 345 | } |
| 346 | |
| 347 | if err := (*h.store).Set(ctx, "tool_executions", execution.ID, execution); err != nil { |
| 348 | c.JSON(http.StatusInternalServerError, gin.H{ |
| 349 | "success": false, |
| 350 | "error": gin.H{ |
| 351 | "code": "internal_error", |
| 352 | "message": err.Error(), |
| 353 | }, |