(ctx context.Context, req sandboxclient.FileWriteRequest, content string)
| 1162 | } |
| 1163 | |
| 1164 | func buildWriteFileOutputFiles(ctx context.Context, req sandboxclient.FileWriteRequest, content string) ([]OutputFile, error) { |
| 1165 | outputPath, err := normalizeSandboxDeliverablePath(req.Path) |
| 1166 | if err != nil { |
| 1167 | return nil, err |
| 1168 | } |
| 1169 | if !isAllowedSandboxOutputPath(outputPath) { |
| 1170 | return nil, nil |
| 1171 | } |
| 1172 | |
| 1173 | finalContent := content |
| 1174 | if strings.TrimSpace(req.SessionID) != "" { |
| 1175 | readResp, err := getSandboxClient().ReadFile(ctx, sandboxclient.FileReadRequest{ |
| 1176 | Path: req.Path, |
| 1177 | SessionID: req.SessionID, |
| 1178 | Cwd: req.Cwd, |
| 1179 | }) |
| 1180 | if err != nil { |
| 1181 | return nil, wrapSandboxServiceError(err) |
| 1182 | } |
| 1183 | finalContent = readResp.Content |
| 1184 | } |
| 1185 | |
| 1186 | mimeType := mime.TypeByExtension(filepath.Ext(outputPath)) |
| 1187 | if strings.TrimSpace(mimeType) == "" { |
| 1188 | mimeType = "application/octet-stream" |
| 1189 | } |
| 1190 | |
| 1191 | return []OutputFile{ |
| 1192 | { |
| 1193 | FileName: outputPath, |
| 1194 | Content: base64.StdEncoding.EncodeToString([]byte(finalContent)), |
| 1195 | MimeType: mimeType, |
| 1196 | Size: len([]byte(finalContent)), |
| 1197 | }, |
| 1198 | }, nil |
| 1199 | } |
| 1200 | |
| 1201 | func executeListFiles(ctx context.Context, args map[string]interface{}) (*ToolResult, error) { |
| 1202 | path := "." |
no test coverage detected