modjules 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ import { JulesClient, JulesOptions, SessionConfig, SourceManager, AutomatedSession, SessionClient, StorageFactory } from './types.js';
2
+ import { Platform } from './platform/types.js';
3
+ /**
4
+ * The fully resolved internal configuration for the SDK.
5
+ * @internal
6
+ */
7
+ export type InternalConfig = {
8
+ pollingIntervalMs: number;
9
+ requestTimeoutMs: number;
10
+ };
11
+ /**
12
+ * Implementation of the main JulesClient interface.
13
+ * This class acts as the central hub for creating and managing sessions,
14
+ * as well as accessing other resources like sources.
15
+ */
16
+ export declare class JulesClientImpl implements JulesClient {
17
+ /**
18
+ * Manages source connections (e.g., GitHub repositories).
19
+ */
20
+ sources: SourceManager;
21
+ private apiClient;
22
+ private config;
23
+ private options;
24
+ private storageFactory;
25
+ private platform;
26
+ /**
27
+ * Creates a new instance of the JulesClient.
28
+ *
29
+ * @param options Configuration options for the client.
30
+ * @param defaultStorageFactory Factory for creating storage instances.
31
+ * @param defaultPlatform Platform-specific implementation.
32
+ */
33
+ constructor(options: JulesOptions | undefined, defaultStorageFactory: StorageFactory, defaultPlatform: Platform);
34
+ /**
35
+ * Creates a new Jules client instance with updated configuration.
36
+ * This is an immutable operation; the original client instance remains unchanged.
37
+ *
38
+ * @param options The new configuration options to merge with the existing ones.
39
+ * @returns A new JulesClient instance with the updated configuration.
40
+ */
41
+ with(options: JulesOptions): JulesClient;
42
+ all<T>(items: T[], mapper: (item: T) => SessionConfig | Promise<SessionConfig>, options?: {
43
+ concurrency?: number;
44
+ stopOnError?: boolean;
45
+ delayMs?: number;
46
+ }): Promise<AutomatedSession[]>;
47
+ private _prepareSessionCreation;
48
+ /**
49
+ * Executes a task in automated mode.
50
+ * This is a high-level abstraction for "fire-and-forget" tasks.
51
+ *
52
+ * **Side Effects:**
53
+ * - Creates a new session on the Jules API (`POST /sessions`).
54
+ * - Initiates background polling for activity updates.
55
+ * - May create a Pull Request if `autoPr` is true (default).
56
+ *
57
+ * **Data Transformation:**
58
+ * - Resolves the `github` source identifier (e.g., `owner/repo`) to a full resource name.
59
+ * - Defaults `requirePlanApproval` to `false` for automated runs.
60
+ *
61
+ * @param config The configuration for the run.
62
+ * @returns A `AutomatedSession` object, which is an enhanced Promise that resolves to the final outcome.
63
+ * @throws {SourceNotFoundError} If the specified GitHub repository cannot be found or accessed.
64
+ * @throws {JulesApiError} If the session creation fails (e.g., 401 Unauthorized).
65
+ *
66
+ * @example
67
+ * const run = await jules.run({
68
+ * prompt: "Fix the login bug",
69
+ * source: { github: "my-org/repo", branch: "main" }
70
+ * });
71
+ * const outcome = await run.result();
72
+ */
73
+ run(config: SessionConfig): Promise<AutomatedSession>;
74
+ /**
75
+ * Creates a new interactive session for workflows requiring human oversight.
76
+ *
77
+ * **Side Effects:**
78
+ * - Creates a new session on the Jules API (`POST /sessions`).
79
+ * - Initializes local storage for the session.
80
+ *
81
+ * **Data Transformation:**
82
+ * - Defaults `requirePlanApproval` to `true` for interactive sessions.
83
+ *
84
+ * @param config The configuration for the session.
85
+ * @returns A Promise resolving to the interactive `SessionClient`.
86
+ * @throws {SourceNotFoundError} If the source cannot be found.
87
+ *
88
+ * @example
89
+ * const session = await jules.session({
90
+ * prompt: "Let's explore the codebase",
91
+ * source: { github: "owner/repo", branch: "main" }
92
+ * });
93
+ */
94
+ session(config: SessionConfig): Promise<SessionClient>;
95
+ /**
96
+ * Rehydrates an existing session from its ID, allowing you to resume interaction.
97
+ * This is useful for stateless environments (like serverless functions) where you need to
98
+ * reconnect to a long-running session.
99
+ *
100
+ * **Side Effects:**
101
+ * - Initializes local storage for the existing session ID.
102
+ * - Does NOT make a network request immediately (lazy initialization).
103
+ *
104
+ * @param sessionId The ID of the existing session.
105
+ * @returns The interactive `SessionClient`.
106
+ *
107
+ * @example
108
+ * const session = jules.session("12345");
109
+ * const info = await session.info(); // Now makes a request
110
+ */
111
+ session(sessionId: string): SessionClient;
112
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Base class for all SDK-specific errors.
3
+ * This allows consumers to catch all Jules SDK errors with a single `catch` block.
4
+ */
5
+ export declare class JulesError extends Error {
6
+ /** The original error that caused this error, if any. */
7
+ readonly cause?: Error;
8
+ constructor(message: string, options?: {
9
+ cause?: Error;
10
+ });
11
+ }
12
+ /**
13
+ * Thrown for fundamental network issues like fetch failures or timeouts.
14
+ */
15
+ export declare class JulesNetworkError extends JulesError {
16
+ readonly url: string;
17
+ constructor(url: string, options?: {
18
+ cause?: Error;
19
+ });
20
+ }
21
+ /**
22
+ * A generic wrapper for non-2xx API responses that don't match other specific errors.
23
+ */
24
+ export declare class JulesApiError extends JulesError {
25
+ readonly url: string;
26
+ readonly status: number;
27
+ readonly statusText: string;
28
+ constructor(url: string, status: number, statusText: string, message?: string, // optional override
29
+ options?: {
30
+ cause?: Error;
31
+ });
32
+ }
33
+ /**
34
+ * Thrown for 401 Unauthorized or 403 Forbidden API responses.
35
+ */
36
+ export declare class JulesAuthenticationError extends JulesApiError {
37
+ constructor(url: string, status: number, statusText: string);
38
+ }
39
+ /**
40
+ * Thrown for 429 Too Many Requests API responses.
41
+ */
42
+ export declare class JulesRateLimitError extends JulesApiError {
43
+ constructor(url: string, status: number, statusText: string);
44
+ }
45
+ /**
46
+ * Thrown when an API key is required but not provided.
47
+ */
48
+ export declare class MissingApiKeyError extends JulesError {
49
+ constructor();
50
+ }
51
+ /**
52
+ * Thrown when a requested source cannot be found.
53
+ */
54
+ export declare class SourceNotFoundError extends JulesError {
55
+ constructor(sourceIdentifier: string);
56
+ }
57
+ /**
58
+ * Thrown when a jules.run() operation terminates in a FAILED state.
59
+ */
60
+ export declare class AutomatedSessionFailedError extends JulesError {
61
+ constructor(reason?: string);
62
+ }
63
+ /**
64
+ * Thrown when an operation is attempted on a session that is not in a
65
+ * valid state for that operation.
66
+ */
67
+ export declare class InvalidStateError extends JulesError {
68
+ constructor(message: string);
69
+ }
@@ -0,0 +1,13 @@
1
+ import { JulesClient } from './types.js';
2
+ /**
3
+ * The main entry point for the Jules SDK.
4
+ * This is a pre-initialized client that can be used immediately with default settings
5
+ * (e.g., reading API keys from environment variables).
6
+ *
7
+ * @example
8
+ * import { jules } from 'modjules';
9
+ * const session = await jules.session({ ... });
10
+ */
11
+ export declare const jules: JulesClient;
12
+ export * from './errors.js';
13
+ export type { Activity, ActivityAgentMessaged, ActivityPlanApproved, ActivityPlanGenerated, ActivityProgressUpdated, ActivitySessionCompleted, ActivitySessionFailed, ActivityUserMessaged, Artifact, AutomatedSession, BashArtifact, ChangeSet, GitHubRepo, GitPatch, JulesClient, JulesOptions, MediaArtifact, Outcome, Plan, PlanStep, PullRequest, SessionClient, SessionConfig, SessionOutput, SessionResource, SessionState, Source, SourceContext, SourceInput, SourceManager, } from './types.js';
@@ -0,0 +1,140 @@
1
+ import { J as l } from "./client-D2GRjxRE.mjs";
2
+ import { A as P, I as F, c as z, d as I, a as A, b as O, e as b, M as j, S as $ } from "./client-D2GRjxRE.mjs";
3
+ import * as r from "fs/promises";
4
+ import { createReadStream as c } from "fs";
5
+ import * as s from "path";
6
+ import * as f from "readline";
7
+ import { writeFile as u } from "node:fs/promises";
8
+ import { Buffer as d } from "node:buffer";
9
+ import { setTimeout as h } from "node:timers/promises";
10
+ class m {
11
+ filePath;
12
+ initialized = !1;
13
+ constructor(i, t = process.cwd()) {
14
+ this.filePath = s.resolve(
15
+ t,
16
+ ".jules/cache",
17
+ i,
18
+ "activities.jsonl"
19
+ );
20
+ }
21
+ /**
22
+ * Initializes the storage by ensuring the cache directory exists.
23
+ *
24
+ * **Side Effects:**
25
+ * - Creates the `.jules/cache/<sessionId>` directory if it does not exist.
26
+ * - Sets the internal `initialized` flag.
27
+ */
28
+ async init() {
29
+ this.initialized || (await r.mkdir(s.dirname(this.filePath), { recursive: !0 }), this.initialized = !0);
30
+ }
31
+ /**
32
+ * Closes the storage.
33
+ */
34
+ async close() {
35
+ this.initialized = !1;
36
+ }
37
+ /**
38
+ * Appends an activity to the file.
39
+ *
40
+ * **Side Effects:**
41
+ * - Appends a new line containing the JSON representation of the activity to `activities.jsonl`.
42
+ * - Implicitly calls `init()` if not already initialized.
43
+ */
44
+ async append(i) {
45
+ this.initialized || await this.init();
46
+ const t = JSON.stringify(i) + `
47
+ `;
48
+ await r.appendFile(this.filePath, t, "utf8");
49
+ }
50
+ /**
51
+ * Retrieves an activity by ID.
52
+ * Uses a linear scan of the file.
53
+ */
54
+ async get(i) {
55
+ for await (const t of this.scan())
56
+ if (t.id === i)
57
+ return t;
58
+ }
59
+ /**
60
+ * Retrieves the latest activity.
61
+ * Scans the entire file to find the last entry.
62
+ */
63
+ async latest() {
64
+ let i;
65
+ for await (const t of this.scan())
66
+ i = t;
67
+ return i;
68
+ }
69
+ /**
70
+ * Yields all activities in the file.
71
+ *
72
+ * **Behavior:**
73
+ * - Opens a read stream to `activities.jsonl`.
74
+ * - Reads line-by-line using `readline`.
75
+ * - Parses each line as JSON.
76
+ *
77
+ * **Edge Cases:**
78
+ * - Logs a warning and skips lines if JSON parsing fails (corrupt data).
79
+ * - Returns immediately (yields nothing) if the file does not exist.
80
+ */
81
+ async *scan() {
82
+ this.initialized || await this.init();
83
+ try {
84
+ await r.access(this.filePath);
85
+ } catch (e) {
86
+ if (e.code === "ENOENT")
87
+ return;
88
+ throw e;
89
+ }
90
+ const i = c(this.filePath, { encoding: "utf8" }), t = f.createInterface({
91
+ input: i,
92
+ crlfDelay: 1 / 0
93
+ });
94
+ for await (const e of t)
95
+ if (e.trim().length !== 0)
96
+ try {
97
+ yield JSON.parse(e);
98
+ } catch {
99
+ console.warn(
100
+ `[NodeFileStorage] Corrupt JSON line ignored in ${this.filePath}`
101
+ );
102
+ }
103
+ }
104
+ }
105
+ class p {
106
+ /**
107
+ * Saves a file to the local filesystem using `node:fs/promises`.
108
+ *
109
+ * **Side Effects:**
110
+ * - Writes a file to disk.
111
+ * - Overwrites the file if it already exists.
112
+ */
113
+ async saveFile(i, t, e, o) {
114
+ const n = d.from(t, e);
115
+ await u(i, n);
116
+ }
117
+ async sleep(i) {
118
+ await h(i);
119
+ }
120
+ createDataUrl(i, t) {
121
+ return `data:${t};base64,${i}`;
122
+ }
123
+ }
124
+ const N = new l(
125
+ {},
126
+ (a) => new m(a),
127
+ new p()
128
+ );
129
+ export {
130
+ P as AutomatedSessionFailedError,
131
+ F as InvalidStateError,
132
+ z as JulesApiError,
133
+ I as JulesAuthenticationError,
134
+ A as JulesError,
135
+ O as JulesNetworkError,
136
+ b as JulesRateLimitError,
137
+ j as MissingApiKeyError,
138
+ $ as SourceNotFoundError,
139
+ N as jules
140
+ };
@@ -0,0 +1,34 @@
1
+ import { Activity, Artifact, Outcome, RestArtifact, SessionResource } from './types.js';
2
+ /**
3
+ * Maps a raw REST API Artifact resource to the SDK's `Artifact` type.
4
+ * This now instantiates rich classes for certain artifact types.
5
+ *
6
+ * @param restArtifact The raw artifact object from the REST API.
7
+ * @returns A structured `Artifact` object for the SDK.
8
+ * @internal
9
+ */
10
+ export declare function mapRestArtifactToSdkArtifact(restArtifact: RestArtifact, platform: any, activityId?: string): Artifact;
11
+ /**
12
+ * Maps a raw REST API Activity resource to the SDK's discriminated union `Activity` type.
13
+ *
14
+ * **Data Transformation:**
15
+ * - Flattens nested union fields (e.g., `agentMessaged`) into a top-level `type` property.
16
+ * - Extracts the short ID from the full resource `name`.
17
+ * - Recursively maps all artifacts within the activity.
18
+ *
19
+ * @param restActivity The raw activity object from the REST API.
20
+ * @param platform The platform adapter (needed for artifact mapping).
21
+ * @returns A structured `Activity` object for the SDK.
22
+ * @throws {Error} If the activity type is unknown.
23
+ * @internal
24
+ */
25
+ export declare function mapRestActivityToSdkActivity(restActivity: any, platform: any): Activity;
26
+ /**
27
+ * Maps the final state of a SessionResource to a user-facing Outcome object.
28
+ * This includes extracting the primary pull request and handling the failed state.
29
+ *
30
+ * @param session The final SessionResource from the API.
31
+ * @returns The corresponding Outcome object.
32
+ * @throws {AutomatedSessionFailedError} If the session state is 'failed'.
33
+ */
34
+ export declare function mapSessionResourceToOutcome(session: SessionResource): Outcome;
@@ -0,0 +1,32 @@
1
+ import { ApiClient } from '../api.js';
2
+ import { NetworkClient } from '../activities/client.js';
3
+ import { Activity } from '../types.js';
4
+ import { ListOptions } from '../activities/types.js';
5
+ import { Platform } from '../platform/types.js';
6
+ /**
7
+ * Concrete implementation of NetworkClient that communicates with the Jules API.
8
+ * Handles fetching activities and streaming them via polling.
9
+ */
10
+ export declare class NetworkAdapter implements NetworkClient {
11
+ private apiClient;
12
+ private sessionId;
13
+ private pollingIntervalMs;
14
+ private platform;
15
+ constructor(apiClient: ApiClient, sessionId: string, pollingIntervalMs: number | undefined, platform: Platform);
16
+ /**
17
+ * Fetches a single activity from the API.
18
+ */
19
+ fetchActivity(activityId: string): Promise<Activity>;
20
+ /**
21
+ * Lists activities from the API with pagination.
22
+ */
23
+ listActivities(options?: ListOptions): Promise<{
24
+ activities: Activity[];
25
+ nextPageToken?: string;
26
+ }>;
27
+ /**
28
+ * Polls the API for new activities and yields them.
29
+ * This stream never ends unless the process is terminated.
30
+ */
31
+ rawStream(): AsyncIterable<Activity>;
32
+ }
@@ -0,0 +1,25 @@
1
+ import { Platform } from './types.js';
2
+ /**
3
+ * Browser implementation of the Platform interface.
4
+ * Uses IndexedDB for file storage.
5
+ */
6
+ export declare class BrowserPlatform implements Platform {
7
+ private dbPromise;
8
+ private getDb;
9
+ /**
10
+ * Saves a file to IndexedDB.
11
+ *
12
+ * **Data Transformation:**
13
+ * - Decodes base64 data into a `Blob`.
14
+ *
15
+ * **Side Effects:**
16
+ * - Stores the blob in the `artifacts` object store.
17
+ * - Associates the file with the `activityId` (if provided).
18
+ *
19
+ * @throws {Error} If the encoding is not 'base64'.
20
+ */
21
+ saveFile(filepath: string, data: string, encoding: 'base64', activityId?: string): Promise<void>;
22
+ sleep(ms: number): Promise<void>;
23
+ createDataUrl(data: string, mimeType: string): string;
24
+ private base64ToBlob;
25
+ }
@@ -0,0 +1,16 @@
1
+ import { Platform } from './types.js';
2
+ /**
3
+ * Node.js implementation of the Platform interface.
4
+ */
5
+ export declare class NodePlatform implements Platform {
6
+ /**
7
+ * Saves a file to the local filesystem using `node:fs/promises`.
8
+ *
9
+ * **Side Effects:**
10
+ * - Writes a file to disk.
11
+ * - Overwrites the file if it already exists.
12
+ */
13
+ saveFile(filepath: string, data: string, encoding: 'base64', activityId?: string): Promise<void>;
14
+ sleep(ms: number): Promise<void>;
15
+ createDataUrl(data: string, mimeType: string): string;
16
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Abstract interface for platform-specific functionality.
3
+ * Allows the SDK to run in both Node.js and browser environments.
4
+ */
5
+ export interface Platform {
6
+ /**
7
+ * Saves a file to the platform's filesystem.
8
+ */
9
+ saveFile(filepath: string, data: string, encoding: 'base64', activityId?: string): Promise<void>;
10
+ /**
11
+ * Pauses execution for the specified duration.
12
+ */
13
+ sleep(ms: number): Promise<void>;
14
+ /**
15
+ * Creates a data URL for the given data.
16
+ */
17
+ createDataUrl(data: string, mimeType: string): string;
18
+ }
@@ -0,0 +1,24 @@
1
+ import { ApiClient } from './api.js';
2
+ import { SessionResource } from './types.js';
3
+ /**
4
+ * A generalized utility for polling the session resource until a specific
5
+ * condition is met.
6
+ *
7
+ * @param sessionId The ID of the session to poll.
8
+ * @param apiClient The API client for making requests.
9
+ * @param predicateFn A function that returns `true` if polling should stop.
10
+ * @param pollingInterval The interval in milliseconds between poll attempts.
11
+ * @returns The session resource that satisfied the predicate.
12
+ * @internal
13
+ */
14
+ export declare function pollSession(sessionId: string, apiClient: ApiClient, predicateFn: (session: SessionResource) => boolean, pollingInterval: number): Promise<SessionResource>;
15
+ /**
16
+ * Polls the `GET /sessions/{id}` endpoint until the session reaches a terminal state.
17
+ *
18
+ * @param sessionId The ID of the session to poll.
19
+ * @param apiClient The API client for making requests.
20
+ * @param pollingInterval The interval in milliseconds between poll attempts.
21
+ * @returns The final SessionResource.
22
+ * @internal
23
+ */
24
+ export declare function pollUntilCompletion(sessionId: string, apiClient: ApiClient, pollingInterval: number): Promise<SessionResource>;
@@ -0,0 +1,121 @@
1
+ import { SelectOptions } from './activities/types.js';
2
+ import { ApiClient } from './api.js';
3
+ import { InternalConfig } from './client.js';
4
+ import { ActivityStorage } from './storage/types.js';
5
+ import { StreamActivitiesOptions } from './streaming.js';
6
+ import { Activity, ActivityAgentMessaged, Outcome, SessionClient, SessionResource, SessionState } from './types.js';
7
+ /**
8
+ * Implementation of the SessionClient interface.
9
+ * Manages an interactive session with the Jules agent.
10
+ */
11
+ export declare class SessionClientImpl implements SessionClient {
12
+ readonly id: string;
13
+ private apiClient;
14
+ private config;
15
+ private _activities;
16
+ /**
17
+ * Creates a new instance of SessionClientImpl.
18
+ *
19
+ * @param sessionId The ID of the session.
20
+ * @param apiClient The API client to use for network requests.
21
+ * @param config The configuration options.
22
+ * @param storage The storage engine for activities.
23
+ * @param platform The platform adapter.
24
+ */
25
+ constructor(sessionId: string, apiClient: ApiClient, config: InternalConfig, storage: ActivityStorage, platform: any);
26
+ /**
27
+ * COLD STREAM: Yields all known past activities from local storage.
28
+ */
29
+ history(): AsyncIterable<Activity>;
30
+ /**
31
+ * HOT STREAM: Yields ONLY future activities as they arrive from the network.
32
+ */
33
+ updates(): AsyncIterable<Activity>;
34
+ /**
35
+ * LOCAL QUERY: Performs rich filtering against local storage only.
36
+ */
37
+ select(options?: SelectOptions): Promise<Activity[]>;
38
+ /**
39
+ * Provides a real-time stream of activities for the session.
40
+ *
41
+ * @param options Options to control the stream.
42
+ */
43
+ stream(options?: StreamActivitiesOptions): AsyncIterable<Activity>;
44
+ /**
45
+ * Approves the currently pending plan.
46
+ * Only valid if the session state is `awaitingPlanApproval`.
47
+ *
48
+ * **Side Effects:**
49
+ * - Sends a POST request to `sessions/{id}:approvePlan`.
50
+ * - Transitions the session state from `awaitingPlanApproval` to `inProgress` (eventually).
51
+ *
52
+ * @throws {InvalidStateError} If the session is not in the `awaitingPlanApproval` state.
53
+ *
54
+ * @example
55
+ * await session.waitFor('awaitingPlanApproval');
56
+ * await session.approve();
57
+ */
58
+ approve(): Promise<void>;
59
+ /**
60
+ * Sends a message (prompt) to the agent in the context of the current session.
61
+ * This is a fire-and-forget operation. To see the response, use `stream()` or `ask()`.
62
+ *
63
+ * **Side Effects:**
64
+ * - Sends a POST request to `sessions/{id}:sendMessage`.
65
+ * - Appends a new `userMessaged` activity to the session history.
66
+ *
67
+ * @param prompt The message to send.
68
+ *
69
+ * @example
70
+ * await session.send("Please clarify step 2.");
71
+ */
72
+ send(prompt: string): Promise<void>;
73
+ /**
74
+ * Sends a message to the agent and waits specifically for the agent's immediate reply.
75
+ * This provides a convenient request/response flow for conversational interactions.
76
+ *
77
+ * **Behavior:**
78
+ * - Sends the prompt using `send()`.
79
+ * - Subscribes to the activity stream.
80
+ * - Resolves with the first `agentMessaged` activity that appears *after* the prompt was sent.
81
+ *
82
+ * @param prompt The message to send.
83
+ * @returns The agent's reply activity.
84
+ * @throws {JulesError} If the session terminates before the agent replies.
85
+ *
86
+ * @example
87
+ * const reply = await session.ask("What is the status?");
88
+ * console.log(reply.message);
89
+ */
90
+ ask(prompt: string): Promise<ActivityAgentMessaged>;
91
+ /**
92
+ * Waits for the session to reach a terminal state and returns the result.
93
+ *
94
+ * **Behavior:**
95
+ * - Polls the session API until state is 'completed' or 'failed'.
96
+ * - Maps the final session resource to a friendly `Outcome` object.
97
+ *
98
+ * @returns The final outcome of the session.
99
+ * @throws {AutomatedSessionFailedError} If the session ends in a 'failed' state.
100
+ */
101
+ result(): Promise<Outcome>;
102
+ /**
103
+ * Pauses execution and waits until the session reaches a specific state.
104
+ * Also returns if the session reaches a terminal state ('completed' or 'failed')
105
+ * to prevent infinite waiting.
106
+ *
107
+ * **Behavior:**
108
+ * - Polls the session API at the configured interval.
109
+ * - Resolves immediately if the session is already in the target state (or terminal).
110
+ *
111
+ * @param targetState The target state to wait for.
112
+ *
113
+ * @example
114
+ * await session.waitFor('awaitingPlanApproval');
115
+ */
116
+ waitFor(targetState: SessionState): Promise<void>;
117
+ /**
118
+ * Retrieves the latest state of the underlying session resource from the API.
119
+ */
120
+ info(): Promise<SessionResource>;
121
+ }
@@ -0,0 +1,8 @@
1
+ import { ApiClient } from './api.js';
2
+ import { SourceManager } from './types.js';
3
+ /**
4
+ * Creates a SourceManager instance.
5
+ * The SourceManager is a callable object (an async iterator) with a `get` method attached.
6
+ * @internal
7
+ */
8
+ export declare function createSourceManager(apiClient: ApiClient): SourceManager;
@@ -0,0 +1,48 @@
1
+ import { Activity } from '../types.js';
2
+ import { ActivityStorage } from './types.js';
3
+ /**
4
+ * Browser implementation of ActivityStorage using IndexedDB.
5
+ * Allows for persistent storage of activities in the browser.
6
+ */
7
+ export declare class BrowserStorage implements ActivityStorage {
8
+ private sessionId;
9
+ private dbPromise;
10
+ constructor(sessionId: string);
11
+ private getDb;
12
+ /**
13
+ * Initializes the storage.
14
+ *
15
+ * **Side Effects:**
16
+ * - Opens an IndexedDB connection.
17
+ * - Upgrades the database schema to v2 if necessary (creating object stores).
18
+ */
19
+ init(): Promise<void>;
20
+ /**
21
+ * Closes the storage connection.
22
+ */
23
+ close(): Promise<void>;
24
+ /**
25
+ * Appends an activity to IndexedDB.
26
+ *
27
+ * **Side Effects:**
28
+ * - Adds a `sessionId` field to the activity for indexing.
29
+ * - Writes the modified activity to the `activities` object store.
30
+ */
31
+ append(activity: Activity): Promise<void>;
32
+ /**
33
+ * Retrieves an activity by ID.
34
+ */
35
+ get(activityId: string): Promise<Activity | undefined>;
36
+ /**
37
+ * Retrieves the latest activity for the current session.
38
+ *
39
+ * **Logic:**
40
+ * - Uses the `sessionTimestamp` index to query efficiently.
41
+ * - Opens a cursor in 'prev' direction to find the last entry first.
42
+ */
43
+ latest(): Promise<Activity | undefined>;
44
+ /**
45
+ * Yields all activities for the current session.
46
+ */
47
+ scan(): AsyncIterable<Activity>;
48
+ }