initSession 初始化沙箱会话
(ctx context.Context)
| 172 | |
| 173 | // initSession 初始化沙箱会话 |
| 174 | func (vs *VolcengineSandbox) initSession(ctx context.Context) error { |
| 175 | params := map[string]any{ |
| 176 | "work_dir": vs.config.WorkDir, |
| 177 | "cpu": vs.config.CPU, |
| 178 | "memory": vs.config.Memory, |
| 179 | } |
| 180 | |
| 181 | if vs.config.Image != "" { |
| 182 | params["image"] = vs.config.Image |
| 183 | } |
| 184 | if vs.config.Environment != nil { |
| 185 | params["environment"] = vs.config.Environment |
| 186 | } |
| 187 | |
| 188 | result, err := vs.mcpClient.CallTool(ctx, "computer_init", params) |
| 189 | if err != nil { |
| 190 | return fmt.Errorf("init computer: %w", err) |
| 191 | } |
| 192 | |
| 193 | // 解析会话 ID |
| 194 | var initResult struct { |
| 195 | SessionID string `json:"session_id"` |
| 196 | } |
| 197 | if err := json.Unmarshal(result, &initResult); err != nil { |
| 198 | return fmt.Errorf("parse init result: %w", err) |
| 199 | } |
| 200 | |
| 201 | vs.sessionID = initResult.SessionID |
| 202 | vs.SetSessionID(initResult.SessionID) |
| 203 | |
| 204 | return nil |
| 205 | } |
| 206 | |
| 207 | // VolcengineFS 火山引擎文件系统 |
| 208 | type VolcengineFS struct { |
no test coverage detected