import { ApiClient } from './api.js'; import { SessionResource } from './types.js'; import { SessionStorage } from './storage/types.js'; export type ListSessionsOptions = { pageSize?: number; pageToken?: string; /** * Hard limit on the number of items to yield when iterating. * Useful if you want "The last 50" without manual counting. */ limit?: number; /** * Whether to persist fetched sessions to local storage. * Defaults to `true` (Write-Through Caching). * Set to `false` to disable side effects. */ persist?: boolean; }; export type ListSessionsResponse = { sessions: SessionResource[]; nextPageToken?: string; }; /** * The SessionCursor handles the complexity of pagination state. * It is "Thenable" (acts like a Promise) and "AsyncIterable". * * This allows two usage patterns: * 1. `await jules.sessions()` - Get the first page (Promise behavior). * 2. `for await (const session of jules.sessions())` - Stream all sessions (AsyncIterable behavior). * * **Design Notes:** * - **Pagination:** Handles `nextPageToken` automatically during iteration. For manual control, * access the `nextPageToken` property on the promised response. * - **Limiting:** The `limit` option hard-stops the iteration after N items, preventing over-fetching. * - **Write-Through Caching:** Fetched sessions are automatically persisted to local storage * using `storage.upsertMany()`. This ensures the local graph is populated during listing. * - **Platform:** Fully platform-agnostic (Node.js/Browser/GAS) via the injected `ApiClient`. */ export declare class SessionCursor implements PromiseLike, AsyncIterable { private apiClient; private storage; private options; constructor(apiClient: ApiClient, storage: SessionStorage, options?: ListSessionsOptions); /** * DX Feature: Promise Compatibility. * Allows `const page = await jules.sessions()` to just get the first page. * This is great for UIs that render a list and a "Load More" button. */ then(onfulfilled?: ((value: ListSessionsResponse) => TResult1 | PromiseLike) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | null): PromiseLike; /** * DX Feature: Async Iterator. * Allows `for await (const s of jules.sessions())` to stream ALL items. * Automatically handles page tokens and fetching behind the scenes. */ [Symbol.asyncIterator](): AsyncIterator; /** * Helper to fetch all pages into a single array. * WARNING: Use with caution on large datasets. */ all(): Promise; /** * Internal fetcher that maps the options to the REST parameters. */ private fetchPage; }