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.
- package/README.md +319 -0
- package/dist/activities/client.d.ts +79 -0
- package/dist/activities/types.d.ts +56 -0
- package/dist/api.d.ts +21 -0
- package/dist/artifacts.d.ts +54 -0
- package/dist/browser.d.ts +12 -0
- package/dist/browser.es.js +158 -0
- package/dist/client-D2GRjxRE.mjs +927 -0
- package/dist/client.d.ts +112 -0
- package/dist/errors.d.ts +69 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.es.js +140 -0
- package/dist/mappers.d.ts +34 -0
- package/dist/network/adapter.d.ts +32 -0
- package/dist/platform/browser.d.ts +25 -0
- package/dist/platform/node.d.ts +16 -0
- package/dist/platform/types.d.ts +18 -0
- package/dist/polling.d.ts +24 -0
- package/dist/session.d.ts +121 -0
- package/dist/sources.d.ts +8 -0
- package/dist/storage/browser.d.ts +48 -0
- package/dist/storage/memory.d.ts +40 -0
- package/dist/storage/node-fs.d.ts +54 -0
- package/dist/storage/types.d.ts +38 -0
- package/dist/streaming.d.ts +16 -0
- package/dist/types.d.ts +799 -0
- package/dist/utils.d.ts +12 -0
- package/package.json +81 -0
package/README.md
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# modjules - the agent-ready SDK for Jules
|
|
2
|
+
|
|
3
|
+
> **Disclaimer:** This is a 100% total, absolute, **just-for-fun** prototype.
|
|
4
|
+
|
|
5
|
+
## Making Jules Agent-Ready
|
|
6
|
+
|
|
7
|
+
Agents thrive on simple actions, persistent memory, and reactive updates. `modjules` provides an tool and memory agent toolkit on top of the Jules REST API.
|
|
8
|
+
|
|
9
|
+
- **Tool Oriented:** Abstracts multi-step API choreographies into single, awaitable tool calls that an agent can easily execute. (e.g., `create session → poll for status → fetch result`)
|
|
10
|
+
- **Persistent State:** Provides external memory, retaining conversational context across turns without burdening your agent's context window.
|
|
11
|
+
- **Reactive Streams:** Converts passive REST polling into push-style Async Iterators, allowing your agent to efficiently _observe_ progress in real-time without managing complex polling logic.
|
|
12
|
+
|
|
13
|
+
## Core Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { jules } from 'modjules';
|
|
17
|
+
|
|
18
|
+
const session = jules.run({
|
|
19
|
+
prompt: `Fix visibility issues in the examples/nextjs app.
|
|
20
|
+
|
|
21
|
+
**Visibility issues**
|
|
22
|
+
- White text on white backgrounds
|
|
23
|
+
- Low contrast on button hover
|
|
24
|
+
|
|
25
|
+
**Instructions**
|
|
26
|
+
- Update the global styles and page components to a dark theme with the shadcn zinc palette.
|
|
27
|
+
`,
|
|
28
|
+
source: { github: 'davideast/modjules', branch: 'main' },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
for await (const activity of session.stream()) {
|
|
32
|
+
switch (activity.type) {
|
|
33
|
+
case 'progressUpdated':
|
|
34
|
+
console.log(`[BUSY] ${activity.title}`);
|
|
35
|
+
break;
|
|
36
|
+
case 'planGenerated':
|
|
37
|
+
console.log(`[PLAN] ${activity.plan.steps.length} steps.`);
|
|
38
|
+
break;
|
|
39
|
+
case 'sessionCompleted':
|
|
40
|
+
console.log('[DONE] Session finished successfully.');
|
|
41
|
+
break;
|
|
42
|
+
case 'sessionFailed':
|
|
43
|
+
console.error(`[FAIL] ${activity.reason}`);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Get the pull-request URL once complete
|
|
49
|
+
const { pullRequest } = await session;
|
|
50
|
+
if (pullRequest) {
|
|
51
|
+
console.log(`PR: ${pullRequest.url}`);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Batch Processing
|
|
56
|
+
|
|
57
|
+
Process multiple items in parallel with `jules.all()`. This method is designed to feel like `Promise.all()` but with built-in concurrency control.
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
const todos = ['Fix login bug', 'Update README', 'Refactor tests'];
|
|
61
|
+
|
|
62
|
+
// Processes items concurrently (default: 4 at a time)
|
|
63
|
+
const sessions = await jules.all(todos, (task) => ({
|
|
64
|
+
prompt: task,
|
|
65
|
+
source: { github: 'user/repo', branch: 'main' },
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
// The results array preserves the order of the input array
|
|
69
|
+
console.log(`Created ${sessions.length} sessions.`);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
For more control, you can pass an options object:
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
const sessions = await jules.all(largeList, mapFn, {
|
|
76
|
+
concurrency: 10, // Run 10 at a time
|
|
77
|
+
stopOnError: false, // Don't stop if one fails
|
|
78
|
+
delayMs: 500, // Wait 500ms between starting each item
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Rich Local Querying
|
|
83
|
+
|
|
84
|
+
The local cache can be queried instantly without network latency using the `.select()` method.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// Query your local cache instantly without network latency.
|
|
88
|
+
const errors = await session.select({
|
|
89
|
+
type: 'sessionFailed',
|
|
90
|
+
limit: 10,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Installation
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm i modjules
|
|
98
|
+
# OR
|
|
99
|
+
bun add modjules
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Cross-Platform Usage
|
|
103
|
+
|
|
104
|
+
The `modjules` SDK is designed to work seamlessly in both Node.js and browser environments. It uses conditional exports in its `package.json` to automatically provide the correct implementation for your platform.
|
|
105
|
+
|
|
106
|
+
### Node.js (Default)
|
|
107
|
+
|
|
108
|
+
In a Node.js environment, the SDK defaults to using the local filesystem for caching session activities in a `.jules/cache` directory. This provides a persistent, restart-safe experience.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// Imports the Node.js version by default
|
|
112
|
+
import { jules } from 'modjules';
|
|
113
|
+
|
|
114
|
+
const session = await jules.session({
|
|
115
|
+
prompt: 'Refactor the user authentication module.',
|
|
116
|
+
source: { github: 'your-org/your-repo', branch: 'develop' },
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Browser
|
|
121
|
+
|
|
122
|
+
When used in a browser environment (e.g., in a web application bundled with Vite, Webpack, or Rollup), the SDK automatically uses a browser-specific implementation that leverages IndexedDB for storage. This allows your web application to maintain session state locally.
|
|
123
|
+
|
|
124
|
+
> **Warning:** Never expose your `JULES_API_KEY` in a production or public-facing application. The browser module is designed for trusted client environments like Electron apps or websites running exclusively on a local machine.
|
|
125
|
+
|
|
126
|
+
To use the browser version, you can explicitly import it:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
// Explicitly import the browser-optimized version
|
|
130
|
+
import { jules } from 'modjules/browser';
|
|
131
|
+
|
|
132
|
+
// The rest of your code remains the same
|
|
133
|
+
const session = await jules.session({
|
|
134
|
+
prompt: 'Refactor the user authentication module.',
|
|
135
|
+
source: { github: 'your-org/your-repo', branch: 'develop' },
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Bundler Resolution vs. Explicit Imports
|
|
140
|
+
|
|
141
|
+
There are two primary strategies for handling platform-specific code, and `modjules` is designed to support both.
|
|
142
|
+
|
|
143
|
+
1. **Automatic Resolution (Recommended for most cases):** Modern bundlers that support the `exports` field in `package.json` can automatically select the correct file based on the environment. For example, Vite, when building for the browser, will see the `browser` condition in the `exports` map and use the `dist/browser.es.js` file. This is the ideal scenario, as it requires no changes to your import statements.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// In a browser environment, the bundler will automatically
|
|
147
|
+
// resolve this to the browser-specific build.
|
|
148
|
+
import { jules } from 'modjules';
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
2. **Explicit Imports:** In some cases, you may want to be explicit about which version you are using, or your tooling may not fully support conditional exports. In these situations, you can use a direct import path.
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
// Always imports the browser version, regardless of bundler configuration
|
|
155
|
+
import { jules } from 'modjules/browser';
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**When to choose which?**
|
|
159
|
+
|
|
160
|
+
- Use the **default import (`modjules`)** whenever possible. It's cleaner and relies on the standard module resolution features of the JavaScript ecosystem.
|
|
161
|
+
- Use the **explicit import (`modjules/browser`)** if you need to override the bundler's resolution, if you are working in an environment that doesn't support conditional exports, or if you want to be very clear in your code that you are using the browser-specific version.
|
|
162
|
+
|
|
163
|
+
## Authentication / API Key
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
export JULES_API_KEY=<api-key>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Interactive Usage
|
|
170
|
+
|
|
171
|
+
Use `jules.session()` for interactive workflows to observe, provide feedback, and guide the process. The `SessionClient` object maintains state across multiple interactions.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { jules } from 'modjules';
|
|
175
|
+
|
|
176
|
+
const session = await jules.session({
|
|
177
|
+
prompt: 'Refactor the user authentication module.',
|
|
178
|
+
source: { github: 'your-org/your-repo', branch: 'develop' },
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
console.log(`Session created: ${session.id}`);
|
|
182
|
+
console.log('Waiting for the agent to generate a plan...');
|
|
183
|
+
|
|
184
|
+
// Wait for the specific state where the plan is ready for review
|
|
185
|
+
await session.waitFor('awaitingPlanApproval');
|
|
186
|
+
console.log('Plan is ready. Approving it now.');
|
|
187
|
+
await session.approve();
|
|
188
|
+
|
|
189
|
+
// Ask a follow-up question
|
|
190
|
+
const reply = await session.ask(
|
|
191
|
+
'Start with the first step and let me know when it is done.',
|
|
192
|
+
);
|
|
193
|
+
console.log(`[AGENT] ${reply.message}`);
|
|
194
|
+
|
|
195
|
+
// Wait for the final result of the session
|
|
196
|
+
const outcome = await session.result();
|
|
197
|
+
console.log(`✅ Session finished with state: ${outcome.state}`);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Deep Dive
|
|
201
|
+
|
|
202
|
+
### Reactive Streams
|
|
203
|
+
|
|
204
|
+
Sessions progress is observed through the `.stream()` method that is available on both the `AutomatedSession` and `SessionClient` objects. An `AutomatedSession` is created via `jules.run()` and a `SessionClient` is create via `jules.session()`. The `.stream()` method returns an `AsyncIterator` to observe the agent's progress.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
for await (const activity of session.stream()) {
|
|
208
|
+
switch (activity.type) {
|
|
209
|
+
case 'planGenerated':
|
|
210
|
+
console.log(
|
|
211
|
+
'Plan:',
|
|
212
|
+
activity.plan.steps.map((s) => s.title),
|
|
213
|
+
);
|
|
214
|
+
break;
|
|
215
|
+
case 'agentMessaged':
|
|
216
|
+
console.log('Agent says:', activity.message);
|
|
217
|
+
break;
|
|
218
|
+
case 'sessionCompleted':
|
|
219
|
+
console.log('Session complete!');
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Artifacts (change sets, bash outputs, images)
|
|
226
|
+
|
|
227
|
+
Session progress is represented through an `Activity` object. Activities can contain artifacts, such as code changes (`changeSet`), shell output (`bashOutput`), or images (`media`). The SDK provides rich objects with helper methods for interacting with them.
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// (Inside a stream loop)
|
|
231
|
+
for (const artifact of activity.artifacts) {
|
|
232
|
+
if (artifact.type === 'bashOutput') {
|
|
233
|
+
// The .toString() helper formats the command, output, and exit code
|
|
234
|
+
console.log(artifact.toString());
|
|
235
|
+
}
|
|
236
|
+
if (artifact.type === 'media' && artifact.format === 'image/png') {
|
|
237
|
+
// The .save() helper works in both Node.js and browser environments
|
|
238
|
+
await artifact.save(`./screenshots/${activity.id}.png`);
|
|
239
|
+
|
|
240
|
+
// Get a URL for display or download (works cross-platform)
|
|
241
|
+
const url = artifact.toUrl();
|
|
242
|
+
console.log('Screenshot URL:', url);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Configuration
|
|
248
|
+
|
|
249
|
+
You can configure timeouts and polling intervals by creating a configured client.
|
|
250
|
+
|
|
251
|
+
#### Multiple API Keys
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { jules } from 'modjules';
|
|
255
|
+
|
|
256
|
+
// The default jules client initialized with process.env.JULES_API_KEY
|
|
257
|
+
const session = jules.session('<session-id-here>');
|
|
258
|
+
|
|
259
|
+
// Initializes a jules client with another API key
|
|
260
|
+
const customJules = jules.with({ apiKey: 'other-api-key' });
|
|
261
|
+
const session = customJules.session('<session-id-here>');
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
#### Polling & Timeouts
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
import { jules } from 'modjules';
|
|
268
|
+
|
|
269
|
+
const customJules = jules.with({
|
|
270
|
+
pollingIntervalMs: 2000, // Poll every 2 seconds
|
|
271
|
+
requestTimeoutMs: 60000, // 1 minute request timeout
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// Use the jules client the same as the default
|
|
275
|
+
const session = jules.session('<session-id-here>');
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Error Handling
|
|
279
|
+
|
|
280
|
+
The SDK throws custom errors that extend a base `JulesError`. This makes it easy to catch all SDK-related exceptions.
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import { jules, JulesError } from 'modjules';
|
|
284
|
+
|
|
285
|
+
try {
|
|
286
|
+
const session = await jules.session({ ... });
|
|
287
|
+
} catch (error) {
|
|
288
|
+
if (error instanceof JulesError) {
|
|
289
|
+
console.error(`An SDK error occurred: ${error.message}`);
|
|
290
|
+
} else {
|
|
291
|
+
console.error(`An unexpected error occurred: ${error}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## API Overview
|
|
297
|
+
|
|
298
|
+
This is a high-level overview of the main SDK components.
|
|
299
|
+
|
|
300
|
+
- **Core:**
|
|
301
|
+
- `jules`: The pre-initialized client.
|
|
302
|
+
- `jules.with(options)`: Creates a new client with custom configuration.
|
|
303
|
+
- `jules.session()`: Creates or rehydrates a session. Returns a `SessionClient`.
|
|
304
|
+
- **Session Control:**
|
|
305
|
+
- `session.ask()`: Sends a message and awaits the agent's reply.
|
|
306
|
+
- `session.send()`: Sends a fire-and-forget message.
|
|
307
|
+
- `session.approve()`: Approves a pending plan.
|
|
308
|
+
- `session.waitFor()`: Pauses until the session reaches a specific state.
|
|
309
|
+
- `session.waitForCompletion()`: Awaits the final outcome of the session.
|
|
310
|
+
- **Observation:**
|
|
311
|
+
- `session.stream()`: Returns an async iterator of all activities (history + live).
|
|
312
|
+
- `session.history()`: Returns a stream of locally cached activities.
|
|
313
|
+
- `session.updates()`: Returns a stream of live activities from the network.
|
|
314
|
+
- `session.select(query)`: Queries the local activity cache.
|
|
315
|
+
- `session.info()`: Fetches the latest session state.
|
|
316
|
+
- **Artifact Management:**
|
|
317
|
+
- `artifact.save()`: Decodes the base64 `data` and saves it. In Node.js, it writes to the filesystem. In the browser, it saves to IndexedDB.
|
|
318
|
+
- `artifact.toUrl()`: Returns a `data:` URI for the artifact data, usable in both Node.js and browser.
|
|
319
|
+
- `artifact.toString()`: Returns a formatted string that combines the command, exit code, `stdout`, and `stderr`, to simplify log display.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Activity } from '../types.js';
|
|
2
|
+
import { ActivityStorage } from '../storage/types.js';
|
|
3
|
+
import { ActivityClient, ListOptions, SelectOptions } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Interface for the network layer used by the activity client.
|
|
6
|
+
* Abstracts away the details of polling and fetching from the API.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface NetworkClient {
|
|
10
|
+
rawStream(): AsyncIterable<Activity>;
|
|
11
|
+
listActivities(options?: ListOptions): Promise<{
|
|
12
|
+
activities: Activity[];
|
|
13
|
+
nextPageToken?: string;
|
|
14
|
+
}>;
|
|
15
|
+
fetchActivity(activityId: string): Promise<Activity>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The default implementation of the ActivityClient.
|
|
19
|
+
* Implements a "local-first" architecture where activities are fetched from
|
|
20
|
+
* the network, cached locally, and then served from the cache.
|
|
21
|
+
*/
|
|
22
|
+
export declare class DefaultActivityClient implements ActivityClient {
|
|
23
|
+
private storage;
|
|
24
|
+
private network;
|
|
25
|
+
constructor(storage: ActivityStorage, network: NetworkClient);
|
|
26
|
+
/**
|
|
27
|
+
* Returns an async iterable of all activities stored locally.
|
|
28
|
+
*/
|
|
29
|
+
history(): AsyncIterable<Activity>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns an async iterable of new activities from the network.
|
|
32
|
+
* This method polls the network and updates the local storage.
|
|
33
|
+
*
|
|
34
|
+
* **Side Effects:**
|
|
35
|
+
* - Polls the network continuously.
|
|
36
|
+
* - Appends new activities to local storage (write-through caching).
|
|
37
|
+
*
|
|
38
|
+
* **Logic:**
|
|
39
|
+
* - Reads the latest activity from storage to determine the "high-water mark".
|
|
40
|
+
* - Ignores incoming activities older than or equal to the high-water mark.
|
|
41
|
+
*/
|
|
42
|
+
updates(): AsyncIterable<Activity>;
|
|
43
|
+
/**
|
|
44
|
+
* Returns a combined stream of history and updates.
|
|
45
|
+
* This is the primary method for consuming the activity stream.
|
|
46
|
+
*
|
|
47
|
+
* **Behavior:**
|
|
48
|
+
* 1. Yields all historical activities from local storage (offline capable).
|
|
49
|
+
* 2. Switches to `updates()` to yield new activities from the network (real-time).
|
|
50
|
+
*/
|
|
51
|
+
stream(): AsyncIterable<Activity>;
|
|
52
|
+
/**
|
|
53
|
+
* Queries local storage for activities matching the given options.
|
|
54
|
+
*/
|
|
55
|
+
select(options?: SelectOptions): Promise<Activity[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Lists activities from the network directly.
|
|
58
|
+
* @param options Pagination options.
|
|
59
|
+
*/
|
|
60
|
+
list(options?: ListOptions): Promise<{
|
|
61
|
+
activities: Activity[];
|
|
62
|
+
nextPageToken?: string;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Gets a single activity by ID.
|
|
66
|
+
* Implements a "read-through" caching strategy.
|
|
67
|
+
*
|
|
68
|
+
* **Logic:**
|
|
69
|
+
* 1. Checks local storage. If found, returns it immediately (fast).
|
|
70
|
+
* 2. If missing, fetches from the network.
|
|
71
|
+
* 3. Persists the fetched activity to storage (future reads will hit cache).
|
|
72
|
+
* 4. Returns the activity.
|
|
73
|
+
*
|
|
74
|
+
* **Side Effects:**
|
|
75
|
+
* - May perform a network request.
|
|
76
|
+
* - May write to local storage.
|
|
77
|
+
*/
|
|
78
|
+
get(activityId: string): Promise<Activity>;
|
|
79
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Activity } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Standard pagination options for network requests.
|
|
4
|
+
*/
|
|
5
|
+
export interface ListOptions {
|
|
6
|
+
pageSize?: number;
|
|
7
|
+
pageToken?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Options for filtering activities locally.
|
|
11
|
+
*/
|
|
12
|
+
export interface SelectOptions {
|
|
13
|
+
after?: string;
|
|
14
|
+
before?: string;
|
|
15
|
+
type?: string;
|
|
16
|
+
limit?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Interface for managing session activities.
|
|
20
|
+
* This interface handles both local caching and network synchronization.
|
|
21
|
+
*/
|
|
22
|
+
export interface ActivityClient {
|
|
23
|
+
/**
|
|
24
|
+
* COLD STREAM: Yields all known past activities from local storage.
|
|
25
|
+
* Ends immediately after yielding the last known activity.
|
|
26
|
+
* Does NOT open a network connection.
|
|
27
|
+
*/
|
|
28
|
+
history(): AsyncIterable<Activity>;
|
|
29
|
+
/**
|
|
30
|
+
* HOT STREAM: Yields ONLY future activities as they arrive from the network.
|
|
31
|
+
* Blocks indefinitely.
|
|
32
|
+
*/
|
|
33
|
+
updates(): AsyncIterable<Activity>;
|
|
34
|
+
/**
|
|
35
|
+
* HYBRID STREAM: Yields full history(), then seamlessly switches to updates().
|
|
36
|
+
* The standard choice for most applications.
|
|
37
|
+
*/
|
|
38
|
+
stream(): AsyncIterable<Activity>;
|
|
39
|
+
/**
|
|
40
|
+
* LOCAL QUERY: Performs rich filtering against local storage only.
|
|
41
|
+
* Fast, but might be incomplete if not synced.
|
|
42
|
+
*/
|
|
43
|
+
select(options?: SelectOptions): Promise<Activity[]>;
|
|
44
|
+
/**
|
|
45
|
+
* NETWORK LIST: Honest wrapper around standard REST pagination.
|
|
46
|
+
* Uses opaque tokens.
|
|
47
|
+
*/
|
|
48
|
+
list(options?: ListOptions): Promise<{
|
|
49
|
+
activities: Activity[];
|
|
50
|
+
nextPageToken?: string;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* NETWORK GET: Fetches a specific activity from the network and caches it.
|
|
54
|
+
*/
|
|
55
|
+
get(activityId: string): Promise<Activity>;
|
|
56
|
+
}
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type ApiClientOptions = {
|
|
2
|
+
apiKey: string | undefined;
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
requestTimeoutMs: number;
|
|
5
|
+
};
|
|
6
|
+
export type ApiRequestOptions = {
|
|
7
|
+
method?: 'GET' | 'POST';
|
|
8
|
+
body?: Record<string, unknown>;
|
|
9
|
+
params?: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A simple internal API client to handle HTTP requests to the Jules API.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare class ApiClient {
|
|
16
|
+
private readonly apiKey;
|
|
17
|
+
private readonly baseUrl;
|
|
18
|
+
private readonly requestTimeoutMs;
|
|
19
|
+
constructor(options: ApiClientOptions);
|
|
20
|
+
request<T>(endpoint: string, options?: ApiRequestOptions): Promise<T>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RestMediaArtifact, RestBashOutputArtifact } from './types.js';
|
|
2
|
+
import { Platform } from './platform/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a media artifact (e.g. image) produced by an activity.
|
|
5
|
+
* Provides helper methods for saving and viewing the media.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MediaArtifact {
|
|
8
|
+
readonly type = "media";
|
|
9
|
+
readonly data: string;
|
|
10
|
+
readonly format: string;
|
|
11
|
+
private platform;
|
|
12
|
+
private activityId?;
|
|
13
|
+
constructor(artifact: RestMediaArtifact['media'], platform: Platform, activityId?: string);
|
|
14
|
+
/**
|
|
15
|
+
* Saves the media artifact to a file.
|
|
16
|
+
*
|
|
17
|
+
* **Side Effects:**
|
|
18
|
+
* - Node.js: Writes the file to disk (overwrites if exists).
|
|
19
|
+
* - Browser: Saves the file to the 'artifacts' object store in IndexedDB.
|
|
20
|
+
*
|
|
21
|
+
* @param filepath The path where the file should be saved.
|
|
22
|
+
*/
|
|
23
|
+
save(filepath: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Converts the media artifact to a data URL.
|
|
26
|
+
* Useful for displaying images in a browser.
|
|
27
|
+
*
|
|
28
|
+
* **Data Transformation:**
|
|
29
|
+
* - Prefixes the base64 data with `data:<mimeType>;base64,`.
|
|
30
|
+
*
|
|
31
|
+
* @returns A valid Data URI string.
|
|
32
|
+
*/
|
|
33
|
+
toUrl(): string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Represents the output of a bash command executed by the agent.
|
|
37
|
+
*/
|
|
38
|
+
export declare class BashArtifact {
|
|
39
|
+
readonly type = "bashOutput";
|
|
40
|
+
readonly command: string;
|
|
41
|
+
readonly stdout: string;
|
|
42
|
+
readonly stderr: string;
|
|
43
|
+
readonly exitCode: number | null;
|
|
44
|
+
constructor(artifact: RestBashOutputArtifact['bashOutput']);
|
|
45
|
+
/**
|
|
46
|
+
* Formats the bash output as a string, mimicking a terminal session.
|
|
47
|
+
*
|
|
48
|
+
* **Data Transformation:**
|
|
49
|
+
* - Combines `stdout` and `stderr`.
|
|
50
|
+
* - Formats the command with a `$` prompt.
|
|
51
|
+
* - Appends the exit code.
|
|
52
|
+
*/
|
|
53
|
+
toString(): string;
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JulesClient } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The main entry point for the Jules SDK for browser environments.
|
|
4
|
+
* This is a pre-initialized client that can be used immediately with default settings.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import { jules } from 'modjules/browser';
|
|
8
|
+
* const session = await jules.session({ ... });
|
|
9
|
+
*/
|
|
10
|
+
export declare const jules: JulesClient;
|
|
11
|
+
export * from './errors.js';
|
|
12
|
+
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';
|