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)
| 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. |
| 58 | func 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. |