MCPcopy Index your code
hub / github.com/docker/docker-agent / ResolveSessionID

Function ResolveSessionID

pkg/session/store.go:58–75  ·  view source on GitHub ↗

ResolveSessionID resolves a session reference to an actual session ID. Supports relative references like "-1" (last session), "-2" (second to last), etc. If the reference is not relative, it returns the input unchanged.

(ctx context.Context, store Store, ref string)

Source from the content-addressed store, hash-verified

56// Supports relative references like "-1" (last session), "-2" (second to last), etc.
57// If the reference is not relative, it returns the input unchanged.
58func ResolveSessionID(ctx context.Context, store Store, ref string) (string, error) {
59 offset, isRelative := parseRelativeSessionRef(ref)
60 if !isRelative {
61 return ref, nil
62 }
63
64 summaries, err := store.GetSessionSummaries(ctx)
65 if err != nil {
66 return "", fmt.Errorf("getting session summaries: %w", err)
67 }
68
69 index := offset - 1
70 if index >= len(summaries) {
71 return "", fmt.Errorf("session offset %d out of range (have %d sessions)", offset, len(summaries))
72 }
73
74 return summaries[index].ID, nil
75}
76
77// Summary contains lightweight session metadata for listing purposes.
78// This is used instead of loading full Session objects with all messages.

Calls 2

parseRelativeSessionRefFunction · 0.85
GetSessionSummariesMethod · 0.65