import { JulesClient, JulesOptions, SessionConfig, SourceManager, AutomatedSession, SessionClient, SessionResource, StorageFactory, JulesQuery, JulesDomain, QueryResult, SyncOptions, SyncStats } from './types.js'; import { SessionCursor, ListSessionsOptions } from './sessions.js'; import { Platform } from './platform/types.js'; import { SessionStorage } from './storage/types.js'; /** * The fully resolved internal configuration for the SDK. * @internal */ export type InternalConfig = { pollingIntervalMs: number; requestTimeoutMs: number; }; /** * Implementation of the main JulesClient interface. * This class acts as the central hub for creating and managing sessions, * as well as accessing other resources like sources. */ export declare class JulesClientImpl implements JulesClient { /** * Manages source connections (e.g., GitHub repositories). */ sources: SourceManager; readonly storage: SessionStorage; private apiClient; private config; private options; private storageFactory; private platform; /** * Lock to prevent concurrent sync operations. * Using a simple boolean for in-process locking. */ private syncInProgress; /** * Creates a new instance of the JulesClient. * * @param options Configuration options for the client. * @param defaultStorageFactory Factory for creating storage instances. * @param defaultPlatform Platform-specific implementation. */ constructor(options: JulesOptions | undefined, defaultStorageFactory: StorageFactory, defaultPlatform: Platform); /** * Fluent API for rich local querying across sessions and activities. * This method uses the modular query engine internally. */ select(query: JulesQuery): Promise[]>; /** * Synchronizes local state with the server. * Logic: * 1. Find High-Water Mark (newest local record). * 2. Stream latest sessions from API. * 3. Terminate stream early if 'incremental' and High-Water Mark is hit. * 4. Throttled hydration of activities if depth is 'activities'. */ sync(options?: SyncOptions): Promise; private getCheckpointPath; private loadCheckpoint; private saveCheckpoint; private clearCheckpoint; private _getHighWaterMark; /** * Helper to resolve environment variables with support for frontend prefixes. */ private getEnv; /** * Creates a new Jules client instance with updated configuration. * This is an immutable operation; the original client instance remains unchanged. * * @param options The new configuration options to merge with the existing ones. * @returns A new JulesClient instance with the updated configuration. */ with(options: JulesOptions): JulesClient; /** * Connects to the Jules service with the provided configuration. * Acts as a factory method for creating a new client instance. * * @param options Configuration options for the client. * @returns A new JulesClient instance. */ connect(options: JulesOptions): JulesClient; /** * Retrieves a session resource using the "Iceberg" caching strategy. * * - **Tier 3 (Frozen):** > 30 days old. Returns from cache immediately. * - **Tier 2 (Warm):** Terminal state + Verified < 24h ago. Returns from cache. * - **Tier 1 (Hot):** Active or Stale. Fetches from network, updates cache, returns. */ getSessionResource(id: string): Promise; /** * Lists sessions with a fluent, pagination-friendly API. * @param options Configuration for pagination (pageSize, limit, pageToken) * @returns A SessionCursor that can be awaited (first page) or iterated (all pages). */ sessions(options?: ListSessionsOptions): SessionCursor; all(items: T[], mapper: (item: T) => SessionConfig | Promise, options?: { concurrency?: number; stopOnError?: boolean; delayMs?: number; }): Promise; private _prepareSessionCreation; /** * Executes a task in automated mode. * This is a high-level abstraction for "fire-and-forget" tasks. * * **Side Effects:** * - Creates a new session on the Jules API (`POST /sessions`). * - Initiates background polling for activity updates. * - May create a Pull Request if `autoPr` is true (default). * * **Data Transformation:** * - Resolves the `github` source identifier (e.g., `owner/repo`) to a full resource name. * - Defaults `requirePlanApproval` to `false` for automated runs. * * @param config The configuration for the run. * @returns A `AutomatedSession` object, which is an enhanced Promise that resolves to the final outcome. * @throws {SourceNotFoundError} If the specified GitHub repository cannot be found or accessed. * @throws {JulesApiError} If the session creation fails (e.g., 401 Unauthorized). * * @example * const run = await jules.run({ * prompt: "Fix the login bug", * source: { github: "my-org/repo", branch: "main" } * }); * const outcome = await run.result(); */ run(config: SessionConfig): Promise; /** * Creates a new interactive session for workflows requiring human oversight. * * **Side Effects:** * - Creates a new session on the Jules API (`POST /sessions`). * - Initializes local storage for the session. * * **Data Transformation:** * - Defaults `requirePlanApproval` to `true` for interactive sessions. * * @param config The configuration for the session. * @returns A Promise resolving to the interactive `SessionClient`. * @throws {SourceNotFoundError} If the source cannot be found. * * @example * const session = await jules.session({ * prompt: "Let's explore the codebase", * source: { github: "owner/repo", branch: "main" } * }); */ session(config: SessionConfig): Promise; /** * Rehydrates an existing session from its ID, allowing you to resume interaction. * This is useful for stateless environments (like serverless functions) where you need to * reconnect to a long-running session. * * **Side Effects:** * - Initializes local storage for the existing session ID. * - Does NOT make a network request immediately (lazy initialization). * * @param sessionId The ID of the existing session. * @returns The interactive `SessionClient`. * * @example * const session = jules.session("12345"); * const info = await session.info(); // Now makes a request */ session(sessionId: string): SessionClient; }