computer-agents 2.3.0 → 2.4.0
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.
|
@@ -8,24 +8,20 @@
|
|
|
8
8
|
* ```typescript
|
|
9
9
|
* import { ComputerAgentsClient } from 'computer-agents';
|
|
10
10
|
*
|
|
11
|
-
* const client = new ComputerAgentsClient(
|
|
12
|
-
* apiKey: process.env.COMPUTER_AGENTS_API_KEY
|
|
13
|
-
* });
|
|
11
|
+
* const client = new ComputerAgentsClient();
|
|
14
12
|
*
|
|
15
|
-
* // Execute a task
|
|
16
|
-
* const result = await client.run('Create a REST API with Flask'
|
|
17
|
-
*
|
|
18
|
-
* onEvent: (event) => console.log(event.type)
|
|
19
|
-
* });
|
|
13
|
+
* // Execute a task — that's it. No setup needed.
|
|
14
|
+
* const result = await client.run('Create a REST API with Flask');
|
|
15
|
+
* console.log(result.content);
|
|
20
16
|
*
|
|
21
|
-
* //
|
|
22
|
-
* const
|
|
23
|
-
*
|
|
17
|
+
* // With streaming events
|
|
18
|
+
* const result2 = await client.run('Build a web scraper', {
|
|
19
|
+
* onEvent: (event) => console.log(event.type)
|
|
24
20
|
* });
|
|
25
21
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
22
|
+
* // Continue the conversation
|
|
23
|
+
* const followUp = await client.run('Add error handling', {
|
|
24
|
+
* threadId: result2.threadId
|
|
29
25
|
* });
|
|
30
26
|
* ```
|
|
31
27
|
*/
|
|
@@ -65,9 +61,10 @@ export interface ComputerAgentsClientConfig {
|
|
|
65
61
|
*/
|
|
66
62
|
export interface RunOptions {
|
|
67
63
|
/**
|
|
68
|
-
* Environment ID to execute in
|
|
64
|
+
* Environment ID to execute in.
|
|
65
|
+
* If not provided, a default environment is created automatically.
|
|
69
66
|
*/
|
|
70
|
-
environmentId
|
|
67
|
+
environmentId?: string;
|
|
71
68
|
/**
|
|
72
69
|
* Thread ID to continue (optional - creates new thread if not provided)
|
|
73
70
|
*/
|
|
@@ -316,25 +313,23 @@ export declare class ComputerAgentsClient {
|
|
|
316
313
|
* Execute a task with automatic thread management
|
|
317
314
|
*
|
|
318
315
|
* This is the simplest way to run an agent task. It handles:
|
|
316
|
+
* - Auto-creating a default environment (if environmentId not provided)
|
|
319
317
|
* - Creating a thread (if threadId not provided)
|
|
320
318
|
* - Sending the message with SSE streaming
|
|
321
319
|
* - Returning the result with thread ID for follow-ups
|
|
322
320
|
*
|
|
323
321
|
* @param task - The task to execute (e.g., "Create a REST API with Flask")
|
|
324
|
-
* @param options - Execution options
|
|
322
|
+
* @param options - Execution options (all optional)
|
|
325
323
|
* @returns The execution result with content and thread ID
|
|
326
324
|
*
|
|
327
325
|
* @example
|
|
328
326
|
* ```typescript
|
|
329
|
-
* //
|
|
330
|
-
* const result = await client.run('Create hello.py'
|
|
331
|
-
* environmentId: 'env_xxx'
|
|
332
|
-
* });
|
|
327
|
+
* // Simplest usage — no setup needed
|
|
328
|
+
* const result = await client.run('Create hello.py');
|
|
333
329
|
* console.log(result.content);
|
|
334
330
|
*
|
|
335
331
|
* // With streaming progress
|
|
336
332
|
* const result = await client.run('Build a REST API', {
|
|
337
|
-
* environmentId: 'env_xxx',
|
|
338
333
|
* onEvent: (event) => {
|
|
339
334
|
* if (event.type === 'response.item.completed') {
|
|
340
335
|
* console.log(event.item);
|
|
@@ -344,28 +339,30 @@ export declare class ComputerAgentsClient {
|
|
|
344
339
|
*
|
|
345
340
|
* // Continue the conversation
|
|
346
341
|
* const followUp = await client.run('Add authentication', {
|
|
347
|
-
* environmentId: 'env_xxx',
|
|
348
342
|
* threadId: result.threadId
|
|
349
343
|
* });
|
|
344
|
+
*
|
|
345
|
+
* // Explicit environment
|
|
346
|
+
* const result = await client.run('Deploy', {
|
|
347
|
+
* environmentId: 'env_xxx'
|
|
348
|
+
* });
|
|
350
349
|
* ```
|
|
351
350
|
*/
|
|
352
|
-
run(task: string, options
|
|
351
|
+
run(task: string, options?: RunOptions): Promise<RunResult>;
|
|
353
352
|
/**
|
|
354
353
|
* Quick setup with default environment
|
|
355
354
|
*
|
|
356
355
|
* Creates a default environment if none exists, returning both
|
|
357
356
|
* the project and environment ready for execution.
|
|
358
357
|
*
|
|
358
|
+
* Note: You usually don't need to call this directly. `run()` auto-creates
|
|
359
|
+
* a default environment when `environmentId` is omitted.
|
|
360
|
+
*
|
|
359
361
|
* @example
|
|
360
362
|
* ```typescript
|
|
361
363
|
* const { project, environment } = await client.quickSetup({
|
|
362
364
|
* internetAccess: true
|
|
363
365
|
* });
|
|
364
|
-
*
|
|
365
|
-
* // Ready to execute
|
|
366
|
-
* await client.run('Hello world!', {
|
|
367
|
-
* environmentId: environment.id
|
|
368
|
-
* });
|
|
369
366
|
* ```
|
|
370
367
|
*/
|
|
371
368
|
quickSetup(options?: {
|
|
@@ -9,24 +9,20 @@
|
|
|
9
9
|
* ```typescript
|
|
10
10
|
* import { ComputerAgentsClient } from 'computer-agents';
|
|
11
11
|
*
|
|
12
|
-
* const client = new ComputerAgentsClient(
|
|
13
|
-
* apiKey: process.env.COMPUTER_AGENTS_API_KEY
|
|
14
|
-
* });
|
|
12
|
+
* const client = new ComputerAgentsClient();
|
|
15
13
|
*
|
|
16
|
-
* // Execute a task
|
|
17
|
-
* const result = await client.run('Create a REST API with Flask'
|
|
18
|
-
*
|
|
19
|
-
* onEvent: (event) => console.log(event.type)
|
|
20
|
-
* });
|
|
14
|
+
* // Execute a task — that's it. No setup needed.
|
|
15
|
+
* const result = await client.run('Create a REST API with Flask');
|
|
16
|
+
* console.log(result.content);
|
|
21
17
|
*
|
|
22
|
-
* //
|
|
23
|
-
* const
|
|
24
|
-
*
|
|
18
|
+
* // With streaming events
|
|
19
|
+
* const result2 = await client.run('Build a web scraper', {
|
|
20
|
+
* onEvent: (event) => console.log(event.type)
|
|
25
21
|
* });
|
|
26
22
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
23
|
+
* // Continue the conversation
|
|
24
|
+
* const followUp = await client.run('Add error handling', {
|
|
25
|
+
* threadId: result2.threadId
|
|
30
26
|
* });
|
|
31
27
|
* ```
|
|
32
28
|
*/
|
|
@@ -247,6 +243,11 @@ class ComputerAgentsClient {
|
|
|
247
243
|
* @internal
|
|
248
244
|
*/
|
|
249
245
|
projects;
|
|
246
|
+
/**
|
|
247
|
+
* Cached default environment ID (populated on first run without environmentId)
|
|
248
|
+
* @internal
|
|
249
|
+
*/
|
|
250
|
+
_defaultEnvironmentId = null;
|
|
250
251
|
constructor(config = {}) {
|
|
251
252
|
// Get API key from config or environment variable
|
|
252
253
|
const apiKey = config.apiKey
|
|
@@ -285,25 +286,23 @@ class ComputerAgentsClient {
|
|
|
285
286
|
* Execute a task with automatic thread management
|
|
286
287
|
*
|
|
287
288
|
* This is the simplest way to run an agent task. It handles:
|
|
289
|
+
* - Auto-creating a default environment (if environmentId not provided)
|
|
288
290
|
* - Creating a thread (if threadId not provided)
|
|
289
291
|
* - Sending the message with SSE streaming
|
|
290
292
|
* - Returning the result with thread ID for follow-ups
|
|
291
293
|
*
|
|
292
294
|
* @param task - The task to execute (e.g., "Create a REST API with Flask")
|
|
293
|
-
* @param options - Execution options
|
|
295
|
+
* @param options - Execution options (all optional)
|
|
294
296
|
* @returns The execution result with content and thread ID
|
|
295
297
|
*
|
|
296
298
|
* @example
|
|
297
299
|
* ```typescript
|
|
298
|
-
* //
|
|
299
|
-
* const result = await client.run('Create hello.py'
|
|
300
|
-
* environmentId: 'env_xxx'
|
|
301
|
-
* });
|
|
300
|
+
* // Simplest usage — no setup needed
|
|
301
|
+
* const result = await client.run('Create hello.py');
|
|
302
302
|
* console.log(result.content);
|
|
303
303
|
*
|
|
304
304
|
* // With streaming progress
|
|
305
305
|
* const result = await client.run('Build a REST API', {
|
|
306
|
-
* environmentId: 'env_xxx',
|
|
307
306
|
* onEvent: (event) => {
|
|
308
307
|
* if (event.type === 'response.item.completed') {
|
|
309
308
|
* console.log(event.item);
|
|
@@ -313,17 +312,23 @@ class ComputerAgentsClient {
|
|
|
313
312
|
*
|
|
314
313
|
* // Continue the conversation
|
|
315
314
|
* const followUp = await client.run('Add authentication', {
|
|
316
|
-
* environmentId: 'env_xxx',
|
|
317
315
|
* threadId: result.threadId
|
|
318
316
|
* });
|
|
317
|
+
*
|
|
318
|
+
* // Explicit environment
|
|
319
|
+
* const result = await client.run('Deploy', {
|
|
320
|
+
* environmentId: 'env_xxx'
|
|
321
|
+
* });
|
|
319
322
|
* ```
|
|
320
323
|
*/
|
|
321
|
-
async run(task, options) {
|
|
324
|
+
async run(task, options = {}) {
|
|
325
|
+
// Auto-resolve environment if not provided
|
|
326
|
+
const environmentId = options.environmentId || await this._ensureDefaultEnvironment();
|
|
322
327
|
// Create or reuse thread
|
|
323
328
|
let threadId = options.threadId;
|
|
324
329
|
if (!threadId) {
|
|
325
330
|
const thread = await this.threads.create({
|
|
326
|
-
environmentId
|
|
331
|
+
environmentId,
|
|
327
332
|
});
|
|
328
333
|
threadId = thread.id;
|
|
329
334
|
}
|
|
@@ -340,22 +345,40 @@ class ComputerAgentsClient {
|
|
|
340
345
|
run: result.run,
|
|
341
346
|
};
|
|
342
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* Return the cached default environment ID, creating one if needed.
|
|
350
|
+
* @internal
|
|
351
|
+
*/
|
|
352
|
+
async _ensureDefaultEnvironment() {
|
|
353
|
+
if (this._defaultEnvironmentId) {
|
|
354
|
+
return this._defaultEnvironmentId;
|
|
355
|
+
}
|
|
356
|
+
const environments = await this.environments.list();
|
|
357
|
+
let environment = environments.find(e => e.isDefault);
|
|
358
|
+
if (!environment) {
|
|
359
|
+
environment = await this.environments.create({
|
|
360
|
+
name: 'default',
|
|
361
|
+
internetAccess: true,
|
|
362
|
+
isDefault: true,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
this._defaultEnvironmentId = environment.id;
|
|
366
|
+
return this._defaultEnvironmentId;
|
|
367
|
+
}
|
|
343
368
|
/**
|
|
344
369
|
* Quick setup with default environment
|
|
345
370
|
*
|
|
346
371
|
* Creates a default environment if none exists, returning both
|
|
347
372
|
* the project and environment ready for execution.
|
|
348
373
|
*
|
|
374
|
+
* Note: You usually don't need to call this directly. `run()` auto-creates
|
|
375
|
+
* a default environment when `environmentId` is omitted.
|
|
376
|
+
*
|
|
349
377
|
* @example
|
|
350
378
|
* ```typescript
|
|
351
379
|
* const { project, environment } = await client.quickSetup({
|
|
352
380
|
* internetAccess: true
|
|
353
381
|
* });
|
|
354
|
-
*
|
|
355
|
-
* // Ready to execute
|
|
356
|
-
* await client.run('Hello world!', {
|
|
357
|
-
* environmentId: environment.id
|
|
358
|
-
* });
|
|
359
382
|
* ```
|
|
360
383
|
*/
|
|
361
384
|
async quickSetup(options = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComputerAgentsClient.js","sourceRoot":"","sources":["../src/ComputerAgentsClient.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"ComputerAgentsClient.js","sourceRoot":"","sources":["../src/ComputerAgentsClient.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAEH,iDAA8D;AAyBrD,+FAzBW,0BAAc,OAyBX;AAvBvB,iDAa2B;AAyG3B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,oBAAoB;IAC/B;;;OAGG;IACM,GAAG,CAAY;IAExB;;;;;;;;;;;;;;;;;OAiBG;IACM,OAAO,CAAkB;IAElC;;;;;;;;;;;;;OAaG;IACM,YAAY,CAAuB;IAE5C;;;;;;;;;;;;;;OAcG;IACM,MAAM,CAAiB;IAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACM,KAAK,CAAgB;IAE9B;;;;;;;;;;;;;;;;OAgBG;IACM,SAAS,CAAoB;IAEtC;;;;;;;;;;;;;;;;;OAiBG;IACM,QAAQ,CAAmB;IAEpC;;;;;;;;;;;;;;;;;;;OAmBG;IACM,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C;gBAC3C,IAAI,EAAE,OAAO,CAAC,eAAe,IAAI,SAAS;gBAC1C,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,IAAI;gBAC9C,SAAS,EAAE,IAAI;aAChB,CAAC,CAAC;QACL,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAClC,CAAC;IAED,4EAA4E;IAC5E,sBAAsB;IACtB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAc,SAAS,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAU,UAAU,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;IAC/B,CAAC;CACF;AA5ZD,oDA4ZC;AASgC,2CAAW;AAKX,8CAAc"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "computer-agents",
|
|
3
3
|
"repository": "https://github.com/computer-agents/computer-agents-sdk",
|
|
4
4
|
"homepage": "https://computer-agents.com",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.4.0",
|
|
6
6
|
"description": "Official SDK for the Computer Agents Cloud API. Execute Claude-powered AI agents in isolated cloud containers.",
|
|
7
7
|
"author": "Computer Agents",
|
|
8
8
|
"main": "dist/index.js",
|