MCPcopy
hub / github.com/cli/cli / GetSessionLogs

Method GetSessionLogs

pkg/cmd/agent-task/capi/sessions.go:336–362  ·  view source on GitHub ↗

GetSessionLogs retrieves logs of an agent session identified by ID.

(ctx context.Context, id string)

Source from the content-addressed store, hash-verified

334
335// GetSessionLogs retrieves logs of an agent session identified by ID.
336func (c *CAPIClient) GetSessionLogs(ctx context.Context, id string) ([]byte, error) {
337 if id == "" {
338 return nil, fmt.Errorf("missing session ID")
339 }
340
341 url := fmt.Sprintf("%s/agents/sessions/%s/logs", c.capiBaseURL, url.PathEscape(id))
342
343 req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
344 if err != nil {
345 return nil, err
346 }
347
348 res, err := c.httpClient.Do(req)
349 if err != nil {
350 return nil, err
351 }
352
353 defer res.Body.Close()
354 if res.StatusCode != http.StatusOK {
355 if res.StatusCode == http.StatusNotFound {
356 return nil, ErrSessionNotFound
357 }
358 return nil, fmt.Errorf("failed to get session: %s", res.Status)
359 }
360
361 return io.ReadAll(res.Body)
362}
363
364// ListSessionsByResourceID retrieves sessions associated with the given resource type and ID.
365func (c *CAPIClient) ListSessionsByResourceID(ctx context.Context, resourceType string, resourceID int64, limit int) ([]*Session, error) {

Callers

nothing calls this directly

Calls 3

ErrorfMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected