computer-agents 1.0.3 → 2.0.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.
- package/README.md +253 -385
- package/dist/ComputerAgentsClient.d.ts +358 -0
- package/dist/ComputerAgentsClient.js +360 -0
- package/dist/ComputerAgentsClient.js.map +1 -0
- package/dist/cloud/ApiClient.d.ts +62 -0
- package/dist/cloud/ApiClient.js +150 -0
- package/dist/cloud/ApiClient.js.map +1 -0
- package/dist/cloud/resources/AgentsResource.d.ts +39 -0
- package/dist/cloud/resources/AgentsResource.js +58 -0
- package/dist/cloud/resources/AgentsResource.js.map +1 -0
- package/dist/cloud/resources/BudgetResource.d.ts +167 -0
- package/dist/cloud/resources/BudgetResource.js +179 -0
- package/dist/cloud/resources/BudgetResource.js.map +1 -0
- package/dist/cloud/resources/EnvironmentsResource.d.ts +167 -0
- package/dist/cloud/resources/EnvironmentsResource.js +256 -0
- package/dist/cloud/resources/EnvironmentsResource.js.map +1 -0
- package/dist/cloud/resources/FilesResource.d.ts +201 -0
- package/dist/cloud/resources/FilesResource.js +204 -0
- package/dist/cloud/resources/FilesResource.js.map +1 -0
- package/dist/cloud/resources/GitResource.d.ts +28 -0
- package/dist/cloud/resources/GitResource.js +45 -0
- package/dist/cloud/resources/GitResource.js.map +1 -0
- package/dist/cloud/resources/ProjectsResource.d.ts +78 -0
- package/dist/cloud/resources/ProjectsResource.js +117 -0
- package/dist/cloud/resources/ProjectsResource.js.map +1 -0
- package/dist/cloud/resources/RunsResource.d.ts +61 -0
- package/dist/cloud/resources/RunsResource.js +84 -0
- package/dist/cloud/resources/RunsResource.js.map +1 -0
- package/dist/cloud/resources/SchedulesResource.d.ts +58 -0
- package/dist/cloud/resources/SchedulesResource.js +82 -0
- package/dist/cloud/resources/SchedulesResource.js.map +1 -0
- package/dist/cloud/resources/ThreadsResource.d.ts +124 -0
- package/dist/cloud/resources/ThreadsResource.js +178 -0
- package/dist/cloud/resources/ThreadsResource.js.map +1 -0
- package/dist/cloud/resources/index.d.ts +17 -0
- package/dist/cloud/resources/index.js +28 -0
- package/dist/cloud/resources/index.js.map +1 -0
- package/dist/cloud/types.d.ts +676 -0
- package/dist/cloud/types.js +9 -0
- package/dist/cloud/types.js.map +1 -0
- package/dist/index.d.ts +28 -5
- package/dist/index.js +51 -194
- package/dist/index.js.map +1 -1
- package/package.json +25 -24
- package/dist/metadata.d.ts +0 -8
- package/dist/metadata.js +0 -13
- package/dist/metadata.js.map +0 -1
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ComputerAgentsClient - The Official Computer Agents SDK
|
|
3
|
+
*
|
|
4
|
+
* A clean, simple SDK for interacting with the Computer Agents Cloud API.
|
|
5
|
+
* This SDK provides typed access to all API resources with streaming support.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { ComputerAgentsClient } from 'computer-agents';
|
|
10
|
+
*
|
|
11
|
+
* const client = new ComputerAgentsClient({
|
|
12
|
+
* apiKey: process.env.COMPUTER_AGENTS_API_KEY
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Execute a task (simplest usage)
|
|
16
|
+
* const result = await client.run('Create a REST API with Flask', {
|
|
17
|
+
* environmentId: 'env_xxx',
|
|
18
|
+
* onEvent: (event) => console.log(event.type)
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Or use the thread API for multi-turn conversations
|
|
22
|
+
* const thread = await client.threads.create({
|
|
23
|
+
* environmentId: 'env_xxx'
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const response = await client.threads.sendMessage(thread.id, {
|
|
27
|
+
* content: 'Create a REST API',
|
|
28
|
+
* onEvent: (event) => console.log(event)
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
import { ApiClientError } from './cloud/ApiClient';
|
|
33
|
+
import type { ApiClientConfig } from './cloud/ApiClient';
|
|
34
|
+
import { EnvironmentsResource, ThreadsResource, AgentsResource, BudgetResource, BillingResource, SchedulesResource, GitResource, FilesResource } from './cloud/resources';
|
|
35
|
+
import type { HealthCheck, Metrics, Project, Environment, MessageStreamEvent } from './cloud/types';
|
|
36
|
+
export { ApiClientError };
|
|
37
|
+
export type { ApiClientConfig };
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for ComputerAgentsClient
|
|
40
|
+
*/
|
|
41
|
+
export interface ComputerAgentsClientConfig {
|
|
42
|
+
/**
|
|
43
|
+
* API key for authentication (required)
|
|
44
|
+
* Can also be set via COMPUTER_AGENTS_API_KEY environment variable
|
|
45
|
+
*/
|
|
46
|
+
apiKey?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Base URL for the API
|
|
49
|
+
* @default 'https://api.computer-agents.com'
|
|
50
|
+
*/
|
|
51
|
+
baseUrl?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Enable debug logging
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
debug?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Request timeout in milliseconds
|
|
59
|
+
* @default 60000 (1 minute)
|
|
60
|
+
*/
|
|
61
|
+
timeout?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Options for the run() convenience method
|
|
65
|
+
*/
|
|
66
|
+
export interface RunOptions {
|
|
67
|
+
/**
|
|
68
|
+
* Environment ID to execute in (required)
|
|
69
|
+
*/
|
|
70
|
+
environmentId: string;
|
|
71
|
+
/**
|
|
72
|
+
* Thread ID to continue (optional - creates new thread if not provided)
|
|
73
|
+
*/
|
|
74
|
+
threadId?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Agent configuration override
|
|
77
|
+
*/
|
|
78
|
+
agentConfig?: {
|
|
79
|
+
model?: 'claude-opus-4-5' | 'claude-sonnet-4-5' | 'claude-haiku-4-5';
|
|
80
|
+
instructions?: string;
|
|
81
|
+
reasoningEffort?: 'minimal' | 'low' | 'medium' | 'high';
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Callback for streaming events
|
|
85
|
+
*/
|
|
86
|
+
onEvent?: (event: MessageStreamEvent) => void;
|
|
87
|
+
/**
|
|
88
|
+
* Execution timeout in milliseconds
|
|
89
|
+
* @default 600000 (10 minutes)
|
|
90
|
+
*/
|
|
91
|
+
timeout?: number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Result from the run() method
|
|
95
|
+
*/
|
|
96
|
+
export interface RunResult {
|
|
97
|
+
/**
|
|
98
|
+
* The final response content
|
|
99
|
+
*/
|
|
100
|
+
content: string;
|
|
101
|
+
/**
|
|
102
|
+
* The thread ID (for continuing conversations)
|
|
103
|
+
*/
|
|
104
|
+
threadId: string;
|
|
105
|
+
/**
|
|
106
|
+
* Run details if available
|
|
107
|
+
*/
|
|
108
|
+
run?: {
|
|
109
|
+
id: string;
|
|
110
|
+
status: string;
|
|
111
|
+
tokens?: {
|
|
112
|
+
input: number;
|
|
113
|
+
output: number;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* ComputerAgentsClient - Complete SDK for Computer Agents Cloud API
|
|
119
|
+
*
|
|
120
|
+
* This is the main entry point for the SDK. It provides access to all API
|
|
121
|
+
* resources through typed methods:
|
|
122
|
+
*
|
|
123
|
+
* - `threads` - Conversation management with SSE streaming
|
|
124
|
+
* - `environments` - Environment configuration and container lifecycle
|
|
125
|
+
* - `agents` - Agent configuration
|
|
126
|
+
* - `files` - File management (via projects resource)
|
|
127
|
+
* - `schedules` - Scheduled task management
|
|
128
|
+
* - `billing` - Budget and usage tracking
|
|
129
|
+
* - `git` - Git operations on workspaces
|
|
130
|
+
*
|
|
131
|
+
* For simple use cases, use the `run()` method which handles thread
|
|
132
|
+
* creation and streaming automatically.
|
|
133
|
+
*/
|
|
134
|
+
export declare class ComputerAgentsClient {
|
|
135
|
+
/**
|
|
136
|
+
* Thread (conversation) management
|
|
137
|
+
*
|
|
138
|
+
* Create threads for multi-turn conversations with agents.
|
|
139
|
+
* Use sendMessage() for SSE streaming execution.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const thread = await client.threads.create({
|
|
144
|
+
* environmentId: 'env_xxx'
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* const result = await client.threads.sendMessage(thread.id, {
|
|
148
|
+
* content: 'Fix the TypeScript errors',
|
|
149
|
+
* onEvent: (event) => console.log(event)
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
readonly threads: ThreadsResource;
|
|
154
|
+
/**
|
|
155
|
+
* Environment management
|
|
156
|
+
*
|
|
157
|
+
* Create and manage isolated execution environments.
|
|
158
|
+
* Environments define variables, secrets, MCP servers, and setup scripts.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const env = await client.environments.create({
|
|
163
|
+
* name: 'production',
|
|
164
|
+
* internetAccess: true
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
readonly environments: EnvironmentsResource;
|
|
169
|
+
/**
|
|
170
|
+
* Agent configuration
|
|
171
|
+
*
|
|
172
|
+
* Create and manage agent configurations with Claude models, instructions, and skills.
|
|
173
|
+
* All agents execute via Claude Code CLI in isolated containers.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const agent = await client.agents.create({
|
|
178
|
+
* name: 'Code Assistant',
|
|
179
|
+
* model: 'claude-sonnet-4-5',
|
|
180
|
+
* instructions: 'You are a helpful coding assistant.'
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
readonly agents: AgentsResource;
|
|
185
|
+
/**
|
|
186
|
+
* File operations
|
|
187
|
+
*
|
|
188
|
+
* Upload, download, and manage files in environment workspaces.
|
|
189
|
+
* Files are scoped to environments.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* // List files in an environment
|
|
194
|
+
* const files = await client.files.listFiles('env_xxx');
|
|
195
|
+
*
|
|
196
|
+
* // Upload a file
|
|
197
|
+
* await client.files.uploadFile({
|
|
198
|
+
* environmentId: 'env_xxx',
|
|
199
|
+
* filename: 'app.py',
|
|
200
|
+
* path: 'src',
|
|
201
|
+
* content: 'print("hello")'
|
|
202
|
+
* });
|
|
203
|
+
*
|
|
204
|
+
* // Download a file
|
|
205
|
+
* const content = await client.files.getFile('env_xxx', 'src/app.py');
|
|
206
|
+
*
|
|
207
|
+
* // Delete a file
|
|
208
|
+
* await client.files.deleteFile('env_xxx', 'src/app.py');
|
|
209
|
+
*
|
|
210
|
+
* // Move/rename a file
|
|
211
|
+
* await client.files.moveFile({
|
|
212
|
+
* environmentId: 'env_xxx',
|
|
213
|
+
* sourcePath: 'old.py',
|
|
214
|
+
* destPath: 'new.py'
|
|
215
|
+
* });
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
readonly files: FilesResource;
|
|
219
|
+
/**
|
|
220
|
+
* Scheduled tasks
|
|
221
|
+
*
|
|
222
|
+
* Create and manage scheduled task execution.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const schedule = await client.schedules.create({
|
|
227
|
+
* name: 'Daily Report',
|
|
228
|
+
* agentId: 'agent_xxx',
|
|
229
|
+
* agentName: 'Reporter',
|
|
230
|
+
* task: 'Generate daily report',
|
|
231
|
+
* scheduleType: 'recurring',
|
|
232
|
+
* cronExpression: '0 9 * * *'
|
|
233
|
+
* });
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
readonly schedules: SchedulesResource;
|
|
237
|
+
/**
|
|
238
|
+
* Budget management
|
|
239
|
+
*
|
|
240
|
+
* Check and manage execution budgets.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const status = await client.budget.getStatus();
|
|
245
|
+
* const canRun = await client.budget.canExecute();
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
readonly budget: BudgetResource;
|
|
249
|
+
/**
|
|
250
|
+
* Billing and usage
|
|
251
|
+
*
|
|
252
|
+
* Access billing records and usage statistics.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const stats = await client.billing.getStats({ period: 'month' });
|
|
257
|
+
* const records = await client.billing.listRecords({ limit: 10 });
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
readonly billing: BillingResource;
|
|
261
|
+
/**
|
|
262
|
+
* Git operations
|
|
263
|
+
*
|
|
264
|
+
* Perform git operations on cloud workspaces.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* const diff = await client.git.diff('env_xxx');
|
|
269
|
+
* await client.git.commit('env_xxx', { message: 'Add feature' });
|
|
270
|
+
* await client.git.push('env_xxx');
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
readonly git: GitResource;
|
|
274
|
+
constructor(config?: ComputerAgentsClientConfig);
|
|
275
|
+
/**
|
|
276
|
+
* Execute a task with automatic thread management
|
|
277
|
+
*
|
|
278
|
+
* This is the simplest way to run an agent task. It handles:
|
|
279
|
+
* - Creating a thread (if threadId not provided)
|
|
280
|
+
* - Sending the message with SSE streaming
|
|
281
|
+
* - Returning the result with thread ID for follow-ups
|
|
282
|
+
*
|
|
283
|
+
* @param task - The task to execute (e.g., "Create a REST API with Flask")
|
|
284
|
+
* @param options - Execution options including environmentId (required)
|
|
285
|
+
* @returns The execution result with content and thread ID
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* // Simple one-shot execution
|
|
290
|
+
* const result = await client.run('Create hello.py', {
|
|
291
|
+
* environmentId: 'env_xxx'
|
|
292
|
+
* });
|
|
293
|
+
* console.log(result.content);
|
|
294
|
+
*
|
|
295
|
+
* // With streaming progress
|
|
296
|
+
* const result = await client.run('Build a REST API', {
|
|
297
|
+
* environmentId: 'env_xxx',
|
|
298
|
+
* onEvent: (event) => {
|
|
299
|
+
* if (event.type === 'response.item.completed') {
|
|
300
|
+
* console.log(event.item);
|
|
301
|
+
* }
|
|
302
|
+
* }
|
|
303
|
+
* });
|
|
304
|
+
*
|
|
305
|
+
* // Continue the conversation
|
|
306
|
+
* const followUp = await client.run('Add authentication', {
|
|
307
|
+
* environmentId: 'env_xxx',
|
|
308
|
+
* threadId: result.threadId
|
|
309
|
+
* });
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
run(task: string, options: RunOptions): Promise<RunResult>;
|
|
313
|
+
/**
|
|
314
|
+
* Quick setup with default environment
|
|
315
|
+
*
|
|
316
|
+
* Creates a default environment if none exists, returning both
|
|
317
|
+
* the project and environment ready for execution.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```typescript
|
|
321
|
+
* const { project, environment } = await client.quickSetup({
|
|
322
|
+
* internetAccess: true
|
|
323
|
+
* });
|
|
324
|
+
*
|
|
325
|
+
* // Ready to execute
|
|
326
|
+
* await client.run('Hello world!', {
|
|
327
|
+
* environmentId: environment.id
|
|
328
|
+
* });
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
quickSetup(options?: {
|
|
332
|
+
internetAccess?: boolean;
|
|
333
|
+
environmentName?: string;
|
|
334
|
+
}): Promise<{
|
|
335
|
+
project: Project;
|
|
336
|
+
environment: Environment;
|
|
337
|
+
}>;
|
|
338
|
+
/**
|
|
339
|
+
* Check API health status
|
|
340
|
+
*/
|
|
341
|
+
health(): Promise<HealthCheck>;
|
|
342
|
+
/**
|
|
343
|
+
* Get API metrics
|
|
344
|
+
*/
|
|
345
|
+
metrics(): Promise<Metrics>;
|
|
346
|
+
/**
|
|
347
|
+
* Get API base URL
|
|
348
|
+
*/
|
|
349
|
+
getBaseUrl(): string;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* @deprecated Use ComputerAgentsClient instead
|
|
353
|
+
*/
|
|
354
|
+
export { ComputerAgentsClient as CloudClient };
|
|
355
|
+
/**
|
|
356
|
+
* @deprecated Use ComputerAgentsClient instead
|
|
357
|
+
*/
|
|
358
|
+
export { ComputerAgentsClient as TestbaseClient };
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ComputerAgentsClient - The Official Computer Agents SDK
|
|
4
|
+
*
|
|
5
|
+
* A clean, simple SDK for interacting with the Computer Agents Cloud API.
|
|
6
|
+
* This SDK provides typed access to all API resources with streaming support.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { ComputerAgentsClient } from 'computer-agents';
|
|
11
|
+
*
|
|
12
|
+
* const client = new ComputerAgentsClient({
|
|
13
|
+
* apiKey: process.env.COMPUTER_AGENTS_API_KEY
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Execute a task (simplest usage)
|
|
17
|
+
* const result = await client.run('Create a REST API with Flask', {
|
|
18
|
+
* environmentId: 'env_xxx',
|
|
19
|
+
* onEvent: (event) => console.log(event.type)
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Or use the thread API for multi-turn conversations
|
|
23
|
+
* const thread = await client.threads.create({
|
|
24
|
+
* environmentId: 'env_xxx'
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const response = await client.threads.sendMessage(thread.id, {
|
|
28
|
+
* content: 'Create a REST API',
|
|
29
|
+
* onEvent: (event) => console.log(event)
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.TestbaseClient = exports.CloudClient = exports.ComputerAgentsClient = exports.ApiClientError = void 0;
|
|
35
|
+
const ApiClient_1 = require("./cloud/ApiClient");
|
|
36
|
+
Object.defineProperty(exports, "ApiClientError", { enumerable: true, get: function () { return ApiClient_1.ApiClientError; } });
|
|
37
|
+
const resources_1 = require("./cloud/resources");
|
|
38
|
+
/**
|
|
39
|
+
* ComputerAgentsClient - Complete SDK for Computer Agents Cloud API
|
|
40
|
+
*
|
|
41
|
+
* This is the main entry point for the SDK. It provides access to all API
|
|
42
|
+
* resources through typed methods:
|
|
43
|
+
*
|
|
44
|
+
* - `threads` - Conversation management with SSE streaming
|
|
45
|
+
* - `environments` - Environment configuration and container lifecycle
|
|
46
|
+
* - `agents` - Agent configuration
|
|
47
|
+
* - `files` - File management (via projects resource)
|
|
48
|
+
* - `schedules` - Scheduled task management
|
|
49
|
+
* - `billing` - Budget and usage tracking
|
|
50
|
+
* - `git` - Git operations on workspaces
|
|
51
|
+
*
|
|
52
|
+
* For simple use cases, use the `run()` method which handles thread
|
|
53
|
+
* creation and streaming automatically.
|
|
54
|
+
*/
|
|
55
|
+
class ComputerAgentsClient {
|
|
56
|
+
/**
|
|
57
|
+
* Low-level API client (for advanced usage)
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
api;
|
|
61
|
+
/**
|
|
62
|
+
* Thread (conversation) management
|
|
63
|
+
*
|
|
64
|
+
* Create threads for multi-turn conversations with agents.
|
|
65
|
+
* Use sendMessage() for SSE streaming execution.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const thread = await client.threads.create({
|
|
70
|
+
* environmentId: 'env_xxx'
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const result = await client.threads.sendMessage(thread.id, {
|
|
74
|
+
* content: 'Fix the TypeScript errors',
|
|
75
|
+
* onEvent: (event) => console.log(event)
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
threads;
|
|
80
|
+
/**
|
|
81
|
+
* Environment management
|
|
82
|
+
*
|
|
83
|
+
* Create and manage isolated execution environments.
|
|
84
|
+
* Environments define variables, secrets, MCP servers, and setup scripts.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const env = await client.environments.create({
|
|
89
|
+
* name: 'production',
|
|
90
|
+
* internetAccess: true
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
environments;
|
|
95
|
+
/**
|
|
96
|
+
* Agent configuration
|
|
97
|
+
*
|
|
98
|
+
* Create and manage agent configurations with Claude models, instructions, and skills.
|
|
99
|
+
* All agents execute via Claude Code CLI in isolated containers.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const agent = await client.agents.create({
|
|
104
|
+
* name: 'Code Assistant',
|
|
105
|
+
* model: 'claude-sonnet-4-5',
|
|
106
|
+
* instructions: 'You are a helpful coding assistant.'
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
agents;
|
|
111
|
+
/**
|
|
112
|
+
* File operations
|
|
113
|
+
*
|
|
114
|
+
* Upload, download, and manage files in environment workspaces.
|
|
115
|
+
* Files are scoped to environments.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* // List files in an environment
|
|
120
|
+
* const files = await client.files.listFiles('env_xxx');
|
|
121
|
+
*
|
|
122
|
+
* // Upload a file
|
|
123
|
+
* await client.files.uploadFile({
|
|
124
|
+
* environmentId: 'env_xxx',
|
|
125
|
+
* filename: 'app.py',
|
|
126
|
+
* path: 'src',
|
|
127
|
+
* content: 'print("hello")'
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* // Download a file
|
|
131
|
+
* const content = await client.files.getFile('env_xxx', 'src/app.py');
|
|
132
|
+
*
|
|
133
|
+
* // Delete a file
|
|
134
|
+
* await client.files.deleteFile('env_xxx', 'src/app.py');
|
|
135
|
+
*
|
|
136
|
+
* // Move/rename a file
|
|
137
|
+
* await client.files.moveFile({
|
|
138
|
+
* environmentId: 'env_xxx',
|
|
139
|
+
* sourcePath: 'old.py',
|
|
140
|
+
* destPath: 'new.py'
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
files;
|
|
145
|
+
/**
|
|
146
|
+
* Scheduled tasks
|
|
147
|
+
*
|
|
148
|
+
* Create and manage scheduled task execution.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const schedule = await client.schedules.create({
|
|
153
|
+
* name: 'Daily Report',
|
|
154
|
+
* agentId: 'agent_xxx',
|
|
155
|
+
* agentName: 'Reporter',
|
|
156
|
+
* task: 'Generate daily report',
|
|
157
|
+
* scheduleType: 'recurring',
|
|
158
|
+
* cronExpression: '0 9 * * *'
|
|
159
|
+
* });
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
schedules;
|
|
163
|
+
/**
|
|
164
|
+
* Budget management
|
|
165
|
+
*
|
|
166
|
+
* Check and manage execution budgets.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const status = await client.budget.getStatus();
|
|
171
|
+
* const canRun = await client.budget.canExecute();
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
budget;
|
|
175
|
+
/**
|
|
176
|
+
* Billing and usage
|
|
177
|
+
*
|
|
178
|
+
* Access billing records and usage statistics.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const stats = await client.billing.getStats({ period: 'month' });
|
|
183
|
+
* const records = await client.billing.listRecords({ limit: 10 });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
billing;
|
|
187
|
+
/**
|
|
188
|
+
* Git operations
|
|
189
|
+
*
|
|
190
|
+
* Perform git operations on cloud workspaces.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* const diff = await client.git.diff('env_xxx');
|
|
195
|
+
* await client.git.commit('env_xxx', { message: 'Add feature' });
|
|
196
|
+
* await client.git.push('env_xxx');
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
git;
|
|
200
|
+
/**
|
|
201
|
+
* Run tracking (internal)
|
|
202
|
+
* @internal
|
|
203
|
+
*/
|
|
204
|
+
runs;
|
|
205
|
+
/**
|
|
206
|
+
* Project access (internal - use files for file operations)
|
|
207
|
+
* @internal
|
|
208
|
+
*/
|
|
209
|
+
projects;
|
|
210
|
+
constructor(config = {}) {
|
|
211
|
+
// Get API key from config or environment variable
|
|
212
|
+
const apiKey = config.apiKey
|
|
213
|
+
|| process.env.COMPUTER_AGENTS_API_KEY
|
|
214
|
+
|| process.env.TESTBASE_API_KEY;
|
|
215
|
+
if (!apiKey) {
|
|
216
|
+
throw new Error('ComputerAgentsClient requires an API key. Provide it via:\n' +
|
|
217
|
+
'1. Constructor: new ComputerAgentsClient({ apiKey: "..." })\n' +
|
|
218
|
+
'2. Environment variable: COMPUTER_AGENTS_API_KEY');
|
|
219
|
+
}
|
|
220
|
+
// Create low-level API client
|
|
221
|
+
this.api = new ApiClient_1.ApiClient({
|
|
222
|
+
apiKey,
|
|
223
|
+
baseUrl: config.baseUrl,
|
|
224
|
+
timeout: config.timeout,
|
|
225
|
+
debug: config.debug,
|
|
226
|
+
});
|
|
227
|
+
// Initialize all resource managers
|
|
228
|
+
this.threads = new resources_1.ThreadsResource(this.api);
|
|
229
|
+
this.environments = new resources_1.EnvironmentsResource(this.api);
|
|
230
|
+
this.agents = new resources_1.AgentsResource(this.api);
|
|
231
|
+
this.files = new resources_1.FilesResource(this.api);
|
|
232
|
+
this.schedules = new resources_1.SchedulesResource(this.api);
|
|
233
|
+
this.budget = new resources_1.BudgetResource(this.api);
|
|
234
|
+
this.billing = new resources_1.BillingResource(this.api);
|
|
235
|
+
this.git = new resources_1.GitResource(this.api);
|
|
236
|
+
this.runs = new resources_1.RunsResource(this.api);
|
|
237
|
+
this.projects = new resources_1.ProjectsResource(this.api);
|
|
238
|
+
}
|
|
239
|
+
// =========================================================================
|
|
240
|
+
// High-Level Convenience Methods
|
|
241
|
+
// =========================================================================
|
|
242
|
+
/**
|
|
243
|
+
* Execute a task with automatic thread management
|
|
244
|
+
*
|
|
245
|
+
* This is the simplest way to run an agent task. It handles:
|
|
246
|
+
* - Creating a thread (if threadId not provided)
|
|
247
|
+
* - Sending the message with SSE streaming
|
|
248
|
+
* - Returning the result with thread ID for follow-ups
|
|
249
|
+
*
|
|
250
|
+
* @param task - The task to execute (e.g., "Create a REST API with Flask")
|
|
251
|
+
* @param options - Execution options including environmentId (required)
|
|
252
|
+
* @returns The execution result with content and thread ID
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* // Simple one-shot execution
|
|
257
|
+
* const result = await client.run('Create hello.py', {
|
|
258
|
+
* environmentId: 'env_xxx'
|
|
259
|
+
* });
|
|
260
|
+
* console.log(result.content);
|
|
261
|
+
*
|
|
262
|
+
* // With streaming progress
|
|
263
|
+
* const result = await client.run('Build a REST API', {
|
|
264
|
+
* environmentId: 'env_xxx',
|
|
265
|
+
* onEvent: (event) => {
|
|
266
|
+
* if (event.type === 'response.item.completed') {
|
|
267
|
+
* console.log(event.item);
|
|
268
|
+
* }
|
|
269
|
+
* }
|
|
270
|
+
* });
|
|
271
|
+
*
|
|
272
|
+
* // Continue the conversation
|
|
273
|
+
* const followUp = await client.run('Add authentication', {
|
|
274
|
+
* environmentId: 'env_xxx',
|
|
275
|
+
* threadId: result.threadId
|
|
276
|
+
* });
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
async run(task, options) {
|
|
280
|
+
// Create or reuse thread
|
|
281
|
+
let threadId = options.threadId;
|
|
282
|
+
if (!threadId) {
|
|
283
|
+
const thread = await this.threads.create({
|
|
284
|
+
environmentId: options.environmentId,
|
|
285
|
+
});
|
|
286
|
+
threadId = thread.id;
|
|
287
|
+
}
|
|
288
|
+
// Send message and stream response
|
|
289
|
+
const result = await this.threads.sendMessage(threadId, {
|
|
290
|
+
content: task,
|
|
291
|
+
agentConfig: options.agentConfig,
|
|
292
|
+
onEvent: options.onEvent,
|
|
293
|
+
timeout: options.timeout,
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
content: result.content,
|
|
297
|
+
threadId,
|
|
298
|
+
run: result.run,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Quick setup with default environment
|
|
303
|
+
*
|
|
304
|
+
* Creates a default environment if none exists, returning both
|
|
305
|
+
* the project and environment ready for execution.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```typescript
|
|
309
|
+
* const { project, environment } = await client.quickSetup({
|
|
310
|
+
* internetAccess: true
|
|
311
|
+
* });
|
|
312
|
+
*
|
|
313
|
+
* // Ready to execute
|
|
314
|
+
* await client.run('Hello world!', {
|
|
315
|
+
* environmentId: environment.id
|
|
316
|
+
* });
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
async quickSetup(options = {}) {
|
|
320
|
+
// Get the project (bound to API key)
|
|
321
|
+
const project = await this.projects.get();
|
|
322
|
+
// Check for existing default environment
|
|
323
|
+
const environments = await this.environments.list();
|
|
324
|
+
let environment = environments.find(e => e.isDefault);
|
|
325
|
+
// Create default environment if none exists
|
|
326
|
+
if (!environment) {
|
|
327
|
+
environment = await this.environments.create({
|
|
328
|
+
name: options.environmentName || 'default',
|
|
329
|
+
internetAccess: options.internetAccess ?? true,
|
|
330
|
+
isDefault: true,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
return { project, environment };
|
|
334
|
+
}
|
|
335
|
+
// =========================================================================
|
|
336
|
+
// Health & Monitoring
|
|
337
|
+
// =========================================================================
|
|
338
|
+
/**
|
|
339
|
+
* Check API health status
|
|
340
|
+
*/
|
|
341
|
+
async health() {
|
|
342
|
+
return this.api.get('/health');
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Get API metrics
|
|
346
|
+
*/
|
|
347
|
+
async metrics() {
|
|
348
|
+
return this.api.get('/metrics');
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Get API base URL
|
|
352
|
+
*/
|
|
353
|
+
getBaseUrl() {
|
|
354
|
+
return this.api.getBaseUrl();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
exports.ComputerAgentsClient = ComputerAgentsClient;
|
|
358
|
+
exports.CloudClient = ComputerAgentsClient;
|
|
359
|
+
exports.TestbaseClient = ComputerAgentsClient;
|
|
360
|
+
//# sourceMappingURL=ComputerAgentsClient.js.map
|