GetLastSessionID returns the ID of the most recently updated session. This is useful for resuming the last conversation when the session ID was not stored. Returns nil if no sessions exist. Example: lastID, err := client.GetLastSessionID(context.Background()) if err != nil { log.Fatal(err)
(ctx context.Context)
| 1355 | // }) |
| 1356 | // } |
| 1357 | func (c *Client) GetLastSessionID(ctx context.Context) (*string, error) { |
| 1358 | if err := c.ensureConnected(ctx); err != nil { |
| 1359 | return nil, err |
| 1360 | } |
| 1361 | |
| 1362 | result, err := c.client.Request(ctx, "session.getLastId", getLastSessionIDRequest{}) |
| 1363 | if err != nil { |
| 1364 | return nil, err |
| 1365 | } |
| 1366 | |
| 1367 | var response getLastSessionIDResponse |
| 1368 | if err := json.Unmarshal(result, &response); err != nil { |
| 1369 | return nil, fmt.Errorf("failed to unmarshal getLastId response: %w", err) |
| 1370 | } |
| 1371 | |
| 1372 | return response.SessionID, nil |
| 1373 | } |
| 1374 | |
| 1375 | // GetForegroundSessionID returns the ID of the session currently displayed in the TUI. |
| 1376 | // |