Read 读取文件
(ctx context.Context, path string)
| 224 | |
| 225 | // Read 读取文件 |
| 226 | func (vfs *VolcengineFS) Read(ctx context.Context, path string) (string, error) { |
| 227 | absPath := vfs.absPath(path) |
| 228 | |
| 229 | result, err := vfs.mcpClient.CallTool(ctx, "computer_read_file", map[string]any{ |
| 230 | "session_id": vfs.sessionID, |
| 231 | "path": absPath, |
| 232 | }) |
| 233 | if err != nil { |
| 234 | return "", fmt.Errorf("read file: %w", err) |
| 235 | } |
| 236 | |
| 237 | var fileContent struct { |
| 238 | Content string `json:"content"` |
| 239 | Size int64 `json:"size"` |
| 240 | } |
| 241 | if err := json.Unmarshal(result, &fileContent); err != nil { |
| 242 | return "", fmt.Errorf("parse file content: %w", err) |
| 243 | } |
| 244 | |
| 245 | return fileContent.Content, nil |
| 246 | } |
| 247 | |
| 248 | // Write 写入文件 |
| 249 | func (vfs *VolcengineFS) Write(ctx context.Context, path string, content string) error { |