import { ActivityClient, SelectOptions } from './activities/types.js'; import { ApiClient } from './api.js'; import { InternalConfig } from './client.js'; import { ActivityStorage, SessionStorage } from './storage/types.js'; import { StreamActivitiesOptions } from './streaming.js'; import { Activity, ActivityAgentMessaged, Outcome, SessionClient, SessionResource, SessionState, SessionSnapshot } from './types.js'; /** * Implementation of the SessionClient interface. * Manages an interactive session with the Jules agent. */ export declare class SessionClientImpl implements SessionClient { readonly id: string; private apiClient; private config; private sessionStorage; private _activities; /** * Creates a new instance of SessionClientImpl. * * @param sessionId The ID of the session. * @param apiClient The API client to use for network requests. * @param config The configuration options. * @param activityStorage The storage engine for activities. * @param sessionStorage The storage engine for sessions. * @param platform The platform adapter. */ constructor(sessionId: string, apiClient: ApiClient, config: InternalConfig, activityStorage: ActivityStorage, sessionStorage: SessionStorage, // Injected dependency platform: any); private request; /** * COLD STREAM: Yields all known past activities from local storage. * If local cache is empty, fetches from network first. */ history(): AsyncIterable; /** * Forces a full sync of activities from the network to local cache. * @returns The number of new activities synced. */ hydrate(): Promise; /** * HOT STREAM: Yields ONLY future activities as they arrive from the network. */ updates(): AsyncIterable; /** * LOCAL QUERY: Performs rich filtering against local storage only. * * @deprecated Use `session.activities.select()` instead. */ select(options?: SelectOptions): Promise; /** * Scoped access to activity-specific operations. */ get activities(): ActivityClient; /** * Provides a real-time stream of activities for the session. * * @param options Options to control the stream. */ stream(options?: StreamActivitiesOptions): AsyncIterable; /** * Approves the currently pending plan. * Only valid if the session state is `awaitingPlanApproval`. * * **Side Effects:** * - Sends a POST request to `sessions/{id}:approvePlan`. * - Transitions the session state from `awaitingPlanApproval` to `inProgress` (eventually). * * @throws {InvalidStateError} If the session is not in the `awaitingPlanApproval` state. * * @example * await session.waitFor('awaitingPlanApproval'); * await session.approve(); */ approve(): Promise; /** * Sends a message (prompt) to the agent in the context of the current session. * This is a fire-and-forget operation. To see the response, use `stream()` or `ask()`. * * **Side Effects:** * - Sends a POST request to `sessions/{id}:sendMessage`. * - Appends a new `userMessaged` activity to the session history. * * @param prompt The message to send. * * @example * await session.send("Please clarify step 2."); */ send(prompt: string): Promise; /** * Sends a message to the agent and waits specifically for the agent's immediate reply. * This provides a convenient request/response flow for conversational interactions. * * **Behavior:** * - Sends the prompt using `send()`. * - Subscribes to the activity stream. * - Resolves with the first `agentMessaged` activity that appears *after* the prompt was sent. * * @param prompt The message to send. * @returns The agent's reply activity. * @throws {JulesError} If the session terminates before the agent replies. * * @example * const reply = await session.ask("What is the status?"); * console.log(reply.message); */ ask(prompt: string): Promise; /** * Waits for the session to reach a terminal state and returns the result. * * **Behavior:** * - Polls the session API until state is 'completed' or 'failed'. * - Maps the final session resource to a friendly `Outcome` object. * * @returns The final outcome of the session. * @throws {AutomatedSessionFailedError} If the session ends in a 'failed' state. */ result(): Promise; /** * Pauses execution and waits until the session reaches a specific state. * Also returns if the session reaches a terminal state ('completed' or 'failed') * to prevent infinite waiting. * * **Behavior:** * - Polls the session API at the configured interval. * - Resolves immediately if the session is already in the target state (or terminal). * * @param targetState The target state to wait for. * * @example * await session.waitFor('awaitingPlanApproval'); */ waitFor(targetState: SessionState): Promise; /** * Retrieves the latest state of the underlying session resource. * Implements "Iceberg" Read-Through caching. */ info(): Promise; /** * Creates a point-in-time snapshot of the session. * This is a network operation that fetches the latest session info and all activities. * * @returns A `SessionSnapshot` instance. */ snapshot(): Promise; }