| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 1 | package dodo_tools |
| 2 | |
| 3 | import ( |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 4 | "bytes" |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 5 | "context" |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 6 | "encoding/json" |
| 7 | "fmt" |
| 8 | "io" |
| 9 | "net/http" |
| 10 | |
| 11 | "sketch.dev/llm" |
| 12 | ) |
| 13 | |
| 14 | type GetProjectConfigTool struct { |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 15 | apiBaseAddress string |
| 16 | projectId string |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 17 | } |
| 18 | |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 19 | func NewGetProjectConfigTool(apiBaseAddress string, projectId string) *llm.Tool { |
| 20 | tool := &GetProjectConfigTool{ |
| 21 | apiBaseAddress: apiBaseAddress, |
| 22 | projectId: projectId, |
| 23 | } |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 24 | return &llm.Tool{ |
| 25 | Name: "dodo_get_project_config", |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 26 | Description: "A tool for getting current state of the infrastructure configuration of a dodo project. You might want to use dodo_get_project_env tool to resolve ingress domains.", |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 27 | InputSchema: llm.EmptySchema(), |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 28 | Run: tool.Run, |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 29 | EndsTurn: false, |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
| 33 | type GetProjectConfigInput struct { |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | type GetProjectConfigOutput struct { |
| 37 | Config string `json:"config"` |
| 38 | } |
| 39 | |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 40 | func (d *GetProjectConfigTool) Run(ctx context.Context, m json.RawMessage) llm.ToolOut { |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 41 | resp, err := http.Get(fmt.Sprintf("%s/api/project/%s/config", d.apiBaseAddress, d.projectId)) |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 42 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 43 | return llm.ErrorToolOut(err) |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 44 | } |
| 45 | defer resp.Body.Close() |
| 46 | body, err := io.ReadAll(resp.Body) |
| 47 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 48 | return llm.ErrorToolOut(err) |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 49 | } |
| 50 | if resp.StatusCode != http.StatusOK { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 51 | return llm.ErrorfToolOut("failed to get project config: %s", string(body)) |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 52 | } |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 53 | output := GetProjectConfigOutput{ |
| 54 | Config: string(body), |
| 55 | } |
| 56 | jsonOutput, err := json.Marshal(output) |
| 57 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 58 | return llm.ErrorToolOut(err) |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 59 | } |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 60 | return llm.ToolOut{LLMContent: llm.TextContent(string(jsonOutput))} |
| gio | 3050307 | 2025-06-17 10:50:15 +0000 | [diff] [blame] | 61 | } |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 62 | |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 63 | // Env |
| 64 | |
| 65 | type GetProjectEnvTool struct { |
| 66 | apiBaseAddress string |
| 67 | projectId string |
| 68 | } |
| 69 | |
| 70 | func NewGetProjectEnvTool(apiBaseAddress string, projectId string) *llm.Tool { |
| 71 | tool := &GetProjectEnvTool{ |
| 72 | apiBaseAddress: apiBaseAddress, |
| 73 | projectId: projectId, |
| 74 | } |
| 75 | return &llm.Tool{ |
| 76 | Name: "dodo_get_project_env", |
| 77 | Description: `A tool for getting GitHub PAT (Personal Access Token) and available networks of the dodo project. Use if you need to: |
| 78 | 1. Interact with GitHub and do not have PAT cached. |
| 79 | 2. Want to resolve network domains of dodo service ingresses. |
| 80 | 3. Access application wide environment variables. |
| 81 | |
| 82 | Returns JSON object conforming following schema which you can cache: |
| 83 | |
| 84 | { |
| 85 | "type": "object", |
| 86 | "properties": { |
| 87 | "githubToken": { |
| 88 | "type": "string", |
| 89 | "description": "Github PAT (Personal Access Token)" |
| 90 | }, |
| 91 | "networks": { |
| 92 | "type": "array", |
| 93 | "description": "List of available networks", |
| 94 | "items": { |
| 95 | "type": "object", |
| 96 | "required": ["name", "domain", "hasAuth"], |
| 97 | "properties": { |
| 98 | "name": { |
| 99 | "type": "string", |
| 100 | "description": "The name of the network" |
| 101 | }, |
| 102 | "domain": { |
| 103 | "type": "string", |
| 104 | "description": "The domain of the network" |
| 105 | }, |
| 106 | "hasAuth": { |
| 107 | "type": "boolean", |
| 108 | "description": "Represents if services published on this network can use built-in authorization" |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | }, |
| 113 | "envVars": { |
| 114 | "type": "array", |
| 115 | "description": "List of application wide environment variables", |
| 116 | "items": { |
| 117 | "type": "object", |
| 118 | "required": ["name", "value"], |
| 119 | "properties": { |
| 120 | "name": { |
| 121 | "type": "string", |
| 122 | "description": "The name of the environment variable" |
| 123 | }, |
| 124 | "value": { |
| 125 | "type": "string", |
| 126 | "description": "The value of the environment variable" |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | `, |
| 134 | InputSchema: llm.EmptySchema(), |
| 135 | Run: tool.Run, |
| 136 | EndsTurn: false, |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | type GetProjectEnvInput struct { |
| 141 | } |
| 142 | |
| 143 | type Network struct { |
| 144 | Name string `json:"name"` |
| 145 | Domain string `json:"domain"` |
| 146 | HasAuth bool `json:"hasAuth"` |
| 147 | } |
| 148 | |
| Giorgi Lekveishvili | b953294 | 2025-07-20 14:48:37 +0400 | [diff] [blame] | 149 | type EnvVar struct { |
| 150 | Name string `json:"name"` |
| 151 | Value string `json:"value"` |
| 152 | } |
| 153 | |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 154 | type GetProjectEnvOutput struct { |
| 155 | GithubToken string `json:"githubToken,omitempty"` |
| 156 | Networks []Network `json:"networks,omitempty"` |
| Giorgi Lekveishvili | b953294 | 2025-07-20 14:48:37 +0400 | [diff] [blame] | 157 | EnvVars []EnvVar `json:"envVars"` |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 158 | } |
| 159 | |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 160 | func (d *GetProjectEnvTool) Run(ctx context.Context, m json.RawMessage) llm.ToolOut { |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 161 | resp, err := http.Get(fmt.Sprintf("%s/api/project/%s/env", d.apiBaseAddress, d.projectId)) |
| 162 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 163 | return llm.ErrorToolOut(err) |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 164 | } |
| 165 | defer resp.Body.Close() |
| 166 | body, err := io.ReadAll(resp.Body) |
| 167 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 168 | return llm.ErrorToolOut(err) |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 169 | } |
| 170 | if resp.StatusCode != http.StatusOK { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 171 | return llm.ErrorfToolOut("failed to get project env: %s", string(body)) |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 172 | } |
| 173 | var output GetProjectEnvOutput |
| 174 | if err := json.Unmarshal(body, &output); err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 175 | return llm.ErrorToolOut(err) |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 176 | } |
| 177 | jsonOutput, err := json.Marshal(output) |
| 178 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 179 | return llm.ErrorToolOut(err) |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 180 | } |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 181 | return llm.ToolOut{LLMContent: llm.TextContent(string(jsonOutput))} |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // Validate |
| 185 | |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 186 | type ValidateConfigTool struct { |
| 187 | apiBaseAddress string |
| 188 | } |
| 189 | |
| 190 | const ( |
| 191 | validateConfigSchemaInputSchema = ` |
| 192 | { |
| 193 | "type": "object", |
| 194 | "properties": { |
| 195 | "config": { |
| 196 | "type": "string", |
| 197 | "description": "The dodo-app configuration to validate" |
| 198 | } |
| 199 | }, |
| 200 | "required": ["config"] |
| 201 | } |
| 202 | ` |
| 203 | ) |
| 204 | |
| 205 | func NewValidateConfigTool(apiBaseAddress string) *llm.Tool { |
| 206 | tool := &ValidateConfigTool{ |
| 207 | apiBaseAddress: apiBaseAddress, |
| 208 | } |
| 209 | return &llm.Tool{ |
| 210 | Name: "dodo_validate_config", |
| 211 | Description: "A tool for validating the dodo-app configuration", |
| 212 | InputSchema: llm.MustSchema(validateConfigSchemaInputSchema), |
| 213 | Run: tool.Run, |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 214 | EndsTurn: false, |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
| 218 | type ValidateConfigInput struct { |
| 219 | Config string `json:"config"` |
| 220 | } |
| 221 | |
| 222 | type ValidateConfigOutput struct { |
| 223 | Success bool `json:"success"` |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 224 | Errors any `json:"errors,omitempty"` |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 227 | func (d *ValidateConfigTool) Run(ctx context.Context, m json.RawMessage) llm.ToolOut { |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 228 | var input ValidateConfigInput |
| 229 | if err := json.Unmarshal(m, &input); err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 230 | return llm.ErrorToolOut(err) |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 231 | } |
| 232 | resp, err := http.Post(fmt.Sprintf("%s/api/validate-config", d.apiBaseAddress), "application/json", bytes.NewBuffer([]byte(input.Config))) |
| 233 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 234 | return llm.ErrorToolOut(err) |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 235 | } |
| 236 | defer resp.Body.Close() |
| 237 | body, err := io.ReadAll(resp.Body) |
| 238 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 239 | return llm.ErrorToolOut(err) |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 240 | } |
| 241 | if resp.StatusCode != http.StatusOK { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 242 | return llm.ErrorfToolOut("failed to validate config: %s", string(body)) |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 243 | } |
| 244 | var output ValidateConfigOutput |
| 245 | if err := json.Unmarshal(body, &output); err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 246 | return llm.ErrorToolOut(err) |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 247 | } |
| 248 | jsonOutput, err := json.Marshal(output) |
| 249 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 250 | return llm.ErrorToolOut(err) |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 251 | } |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 252 | return llm.ToolOut{LLMContent: llm.TextContent(string(jsonOutput))} |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | type DeployProjectTool struct { |
| 256 | apiBaseAddress string |
| 257 | projectId string |
| 258 | } |
| 259 | |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 260 | func NewDeployProjectTool(apiBaseAddress string, projectId string) *llm.Tool { |
| 261 | tool := &DeployProjectTool{ |
| 262 | apiBaseAddress: apiBaseAddress, |
| 263 | projectId: projectId, |
| 264 | } |
| 265 | |
| 266 | return &llm.Tool{ |
| 267 | Name: "dodo_deploy_project", |
| 268 | Description: "A tool for deploying the dodo-app configuration", |
| Giorgi Lekveishvili | f9d7fc5 | 2025-07-07 07:09:42 +0400 | [diff] [blame] | 269 | InputSchema: llm.EmptySchema(), |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 270 | Run: tool.Run, |
| 271 | EndsTurn: true, |
| 272 | } |
| 273 | } |
| 274 | |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 275 | type deployProjectReq struct { |
| Giorgi Lekveishvili | f9d7fc5 | 2025-07-07 07:09:42 +0400 | [diff] [blame] | 276 | Type string `json:"type"` |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 279 | func (d *DeployProjectTool) Run(ctx context.Context, m json.RawMessage) llm.ToolOut { |
| Giorgi Lekveishvili | f9d7fc5 | 2025-07-07 07:09:42 +0400 | [diff] [blame] | 280 | req := deployProjectReq{ |
| 281 | Type: "draft", |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 282 | } |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 283 | jsonReq, err := json.Marshal(req) |
| 284 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 285 | return llm.ErrorToolOut(err) |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 286 | } |
| 287 | resp, err := http.Post(fmt.Sprintf("%s/api/project/%s/deploy", d.apiBaseAddress, d.projectId), "application/json", bytes.NewBuffer(jsonReq)) |
| 288 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 289 | return llm.ErrorToolOut(err) |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 290 | } |
| 291 | defer resp.Body.Close() |
| 292 | body, err := io.ReadAll(resp.Body) |
| 293 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 294 | return llm.ErrorToolOut(err) |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 295 | } |
| 296 | if resp.StatusCode != http.StatusOK { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 297 | return llm.ErrorfToolOut("failed to deploy project: %s", string(body)) |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 298 | } |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 299 | return llm.ToolOut{LLMContent: llm.TextContent(string("Project deployed successfully"))} |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 302 | // Save |
| 303 | |
| 304 | type SaveProjectTool struct { |
| 305 | apiBaseAddress string |
| 306 | projectId string |
| 307 | } |
| 308 | |
| 309 | const ( |
| 310 | saveProjectSchemaInputSchema = ` |
| 311 | { |
| 312 | "type": "object", |
| 313 | "properties": { |
| Giorgi Lekveishvili | 49b7b0a | 2025-07-07 13:52:35 +0400 | [diff] [blame] | 314 | "config": { |
| 315 | "type": "string", |
| 316 | "description": "Serialized dodo-app configuration to save" |
| 317 | } |
| 318 | }, |
| 319 | "required": ["config"] |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 320 | } |
| 321 | ` |
| 322 | ) |
| 323 | |
| 324 | func NewSaveProjectTool(apiBaseAddress string, projectId string) *llm.Tool { |
| 325 | tool := &SaveProjectTool{ |
| 326 | apiBaseAddress: apiBaseAddress, |
| 327 | projectId: projectId, |
| 328 | } |
| 329 | |
| 330 | return &llm.Tool{ |
| 331 | Name: "dodo_save_config", |
| 332 | Description: "A tool for saving the dodo-app configuration", |
| 333 | InputSchema: llm.MustSchema(saveProjectSchemaInputSchema), |
| 334 | Run: tool.Run, |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 335 | EndsTurn: false, |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
| 339 | type SaveProjectInput struct { |
| 340 | Config string `json:"config"` |
| 341 | } |
| 342 | |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 343 | type saveProjectReq struct { |
| 344 | Type string `json:"type"` |
| 345 | Config map[string]any `json:"config"` |
| 346 | } |
| 347 | |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 348 | func (d *SaveProjectTool) Run(ctx context.Context, m json.RawMessage) llm.ToolOut { |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 349 | var input SaveProjectInput |
| 350 | if err := json.Unmarshal(m, &input); err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 351 | return llm.ErrorToolOut(err) |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 352 | } |
| 353 | req := saveProjectReq{ |
| 354 | Type: "config", |
| 355 | } |
| 356 | if err := json.Unmarshal([]byte(input.Config), &req.Config); err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 357 | return llm.ErrorToolOut(err) |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 358 | } |
| 359 | jsonReq, err := json.Marshal(req) |
| 360 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 361 | return llm.ErrorToolOut(err) |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 362 | } |
| 363 | resp, err := http.Post(fmt.Sprintf("%s/api/project/%s/saved", d.apiBaseAddress, d.projectId), "application/json", bytes.NewBuffer(jsonReq)) |
| 364 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 365 | return llm.ErrorToolOut(err) |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 366 | } |
| 367 | defer resp.Body.Close() |
| 368 | body, err := io.ReadAll(resp.Body) |
| 369 | if err != nil { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 370 | return llm.ErrorToolOut(err) |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 371 | } |
| 372 | if resp.StatusCode != http.StatusOK { |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 373 | return llm.ErrorfToolOut("failed to save project: %s", string(body)) |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 374 | } |
| Sketch🕴️ | 9988c51 | 2025-07-31 16:45:04 +0400 | [diff] [blame^] | 375 | return llm.ToolOut{LLMContent: llm.TextContent(string("Project saved successfully"))} |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 376 | } |
| 377 | |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 378 | func NewDodoTools(apiBaseAddress string, projectId string) []*llm.Tool { |
| 379 | return []*llm.Tool{ |
| 380 | NewGetProjectConfigTool(apiBaseAddress, projectId), |
| Giorgi Lekveishvili | 737ac87 | 2025-07-08 06:07:51 +0400 | [diff] [blame] | 381 | NewGetProjectEnvTool(apiBaseAddress, projectId), |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 382 | NewValidateConfigTool(apiBaseAddress), |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 383 | NewSaveProjectTool(apiBaseAddress, projectId), |
| Giorgi Lekveishvili | f9d7fc5 | 2025-07-07 07:09:42 +0400 | [diff] [blame] | 384 | NewDeployProjectTool(apiBaseAddress, projectId), |
| gio | fe6e714 | 2025-06-18 08:51:23 +0000 | [diff] [blame] | 385 | } |
| Giorgi Lekveishvili | 0556983 | 2025-07-06 09:16:29 +0400 | [diff] [blame] | 386 | } |