GetSession retrieves a specific agent session by ID.
(ctx context.Context, id string)
| 295 | |
| 296 | // GetSession retrieves a specific agent session by ID. |
| 297 | func (c *CAPIClient) GetSession(ctx context.Context, id string) (*Session, error) { |
| 298 | if id == "" { |
| 299 | return nil, fmt.Errorf("missing session ID") |
| 300 | } |
| 301 | |
| 302 | u, err := safeurl.JoinPathWithHostPrefix(c.capiBaseURL, "agents", "sessions", id) |
| 303 | if err != nil { |
| 304 | return nil, err |
| 305 | } |
| 306 | |
| 307 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), http.NoBody) |
| 308 | if err != nil { |
| 309 | return nil, err |
| 310 | } |
| 311 | |
| 312 | res, err := c.httpClient.Do(req) |
| 313 | if err != nil { |
| 314 | return nil, err |
| 315 | } |
| 316 | |
| 317 | defer res.Body.Close() |
| 318 | if res.StatusCode != http.StatusOK { |
| 319 | if res.StatusCode == http.StatusNotFound { |
| 320 | return nil, ErrSessionNotFound |
| 321 | } |
| 322 | return nil, fmt.Errorf("failed to get session: %s", res.Status) |
| 323 | } |
| 324 | |
| 325 | var rawSession session |
| 326 | if err := json.NewDecoder(res.Body).Decode(&rawSession); err != nil { |
| 327 | return nil, fmt.Errorf("failed to decode session response: %w", err) |
| 328 | } |
| 329 | |
| 330 | sessions, err := c.hydrateSessionPullRequestsAndUsers([]session{rawSession}) |
| 331 | if err != nil { |
| 332 | return nil, fmt.Errorf("failed to fetch session resources: %w", err) |
| 333 | } |
| 334 | |
| 335 | return sessions[0], nil |
| 336 | } |
| 337 | |
| 338 | // GetSessionLogs retrieves logs of an agent session identified by ID. |
| 339 | func (c *CAPIClient) GetSessionLogs(ctx context.Context, id string) ([]byte, error) { |