handleAddToCart handles add to cart tool calls
(arguments string, sessionID string, toolCallID string)
| 113 | |
| 114 | // handleAddToCart handles add to cart tool calls |
| 115 | func (te *ToolExecutor) handleAddToCart(arguments string, sessionID string, toolCallID string) models.ToolCallResult { |
| 116 | var args struct { |
| 117 | ProductName string `json:"product_name"` |
| 118 | Quantity int `json:"quantity"` |
| 119 | } |
| 120 | |
| 121 | if err := json.Unmarshal([]byte(arguments), &args); err != nil { |
| 122 | return models.ToolCallResult{ |
| 123 | CallID: toolCallID, |
| 124 | ToolName: "add_to_cart", |
| 125 | Success: false, |
| 126 | Error: "Invalid arguments", |
| 127 | Arguments: arguments, |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if args.Quantity == 0 { |
| 132 | args.Quantity = 1 |
| 133 | } |
| 134 | |
| 135 | cartSummary, err := te.cartService.AddToCart(sessionID, args.ProductName, args.Quantity) |
| 136 | if err != nil { |
| 137 | return models.ToolCallResult{ |
| 138 | CallID: toolCallID, |
| 139 | ToolName: "add_to_cart", |
| 140 | Success: false, |
| 141 | Error: err.Error(), |
| 142 | Arguments: arguments, |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | return models.ToolCallResult{ |
| 147 | CallID: toolCallID, |
| 148 | ToolName: "add_to_cart", |
| 149 | Success: true, |
| 150 | Result: cartSummary, |
| 151 | Arguments: arguments, |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // handleRemoveFromCart handles remove from cart tool calls |
| 156 | func (te *ToolExecutor) handleRemoveFromCart(arguments string, sessionID string, toolCallID string) models.ToolCallResult { |
no test coverage detected