handleSearchProducts handles product search tool calls
(arguments string, toolCallID string)
| 65 | |
| 66 | // handleSearchProducts handles product search tool calls |
| 67 | func (te *ToolExecutor) handleSearchProducts(arguments string, toolCallID string) models.ToolCallResult { |
| 68 | var args struct { |
| 69 | Query string `json:"query"` |
| 70 | Category string `json:"category"` |
| 71 | Limit int `json:"limit"` |
| 72 | } |
| 73 | |
| 74 | if err := json.Unmarshal([]byte(arguments), &args); err != nil { |
| 75 | return models.ToolCallResult{ |
| 76 | CallID: toolCallID, |
| 77 | ToolName: "search_products", |
| 78 | Success: false, |
| 79 | Error: "Invalid arguments", |
| 80 | Arguments: arguments, |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if args.Limit == 0 { |
| 85 | args.Limit = 10 |
| 86 | } |
| 87 | |
| 88 | filter := models.ProductFilter{ |
| 89 | Query: args.Query, |
| 90 | Category: args.Category, |
| 91 | Limit: args.Limit, |
| 92 | } |
| 93 | |
| 94 | results, err := te.productService.SearchProducts(filter) |
| 95 | if err != nil { |
| 96 | return models.ToolCallResult{ |
| 97 | CallID: toolCallID, |
| 98 | ToolName: "search_products", |
| 99 | Success: false, |
| 100 | Error: err.Error(), |
| 101 | Arguments: arguments, |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return models.ToolCallResult{ |
| 106 | CallID: toolCallID, |
| 107 | ToolName: "search_products", |
| 108 | Success: true, |
| 109 | Result: results, |
| 110 | Arguments: arguments, |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // handleAddToCart handles add to cart tool calls |
| 115 | func (te *ToolExecutor) handleAddToCart(arguments string, sessionID string, toolCallID string) models.ToolCallResult { |
no test coverage detected