@agent-commons/sdk 0.3.0 → 0.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.
package/dist/index.mjs CHANGED
@@ -1,7 +1,10 @@
1
1
  // src/client.ts
2
2
  var CommonsClient = class {
3
3
  constructor(config) {
4
- this.baseUrl = (config.baseUrl ?? "https://api.agentcommons.io").replace(/\/$/, "");
4
+ this.baseUrl = (config.baseUrl ?? "https://api.agentcommons.io").replace(
5
+ /\/$/,
6
+ ""
7
+ );
5
8
  this.apiKey = config.apiKey;
6
9
  this.initiator = config.initiator;
7
10
  this._fetch = config.fetch ?? fetch;
@@ -39,6 +42,11 @@ var CommonsClient = class {
39
42
  list: (owner) => this.request("GET", `/v1/agents${owner ? `?owner=${owner}` : ""}`),
40
43
  get: (agentId) => this.request("GET", `/v1/agents/${agentId}`),
41
44
  update: (agentId, params) => this.request("PUT", `/v1/agents/${agentId}`, params),
45
+ getRuntime: (agentId) => this.request("GET", `/v1/agents/${agentId}/runtime`),
46
+ configureRuntime: (agentId, params) => this.request("PUT", `/v1/agents/${agentId}/runtime`, params),
47
+ deployRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/deploy`),
48
+ sleepRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/sleep`),
49
+ restartRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/restart`),
42
50
  /** List tools assigned to an agent. */
43
51
  listTools: (agentId) => this.request("GET", `/v1/agents/${agentId}/tools`),
44
52
  /** Assign a tool to an agent. */
@@ -73,32 +81,90 @@ var CommonsClient = class {
73
81
  /** Get the knowledgebase entries for an agent. */
74
82
  getKnowledgebase: (agentId) => this.request("GET", `/v1/agents/${agentId}/knowledgebase`),
75
83
  /** Replace the knowledgebase entries for an agent. */
76
- updateKnowledgebase: (agentId, knowledgebase) => this.request("PUT", `/v1/agents/${agentId}/knowledgebase`, { knowledgebase }),
84
+ updateKnowledgebase: (agentId, knowledgebase) => this.request("PUT", `/v1/agents/${agentId}/knowledgebase`, {
85
+ knowledgebase
86
+ }),
77
87
  // ── Preferred Connections ────────────────────────────────────────────
78
88
  /** List agents that this agent prefers to collaborate with. */
79
89
  getPreferredConnections: (agentId) => this.request("GET", `/v1/agents/${agentId}/preferred-connections`),
80
90
  /** Add a preferred agent connection. */
81
- addPreferredConnection: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/preferred-connections`, params),
91
+ addPreferredConnection: (agentId, params) => this.request(
92
+ "POST",
93
+ `/v1/agents/${agentId}/preferred-connections`,
94
+ params
95
+ ),
82
96
  /** Remove a preferred agent connection by its record ID. */
83
97
  removePreferredConnection: (id) => this.request("DELETE", `/v1/agents/preferred-connections/${id}`),
84
98
  // ── Computers ────────────────────────────────────────────────────────
85
99
  getComputerConfig: (agentId) => this.request("GET", `/v1/agents/${agentId}/computer/config`),
86
100
  updateComputerConfig: (agentId, params) => this.request("PUT", `/v1/agents/${agentId}/computer/config`, params),
87
- listComputers: (agentId, filter) => {
88
- const qs = new URLSearchParams();
89
- if (filter?.sessionId) qs.set("sessionId", filter.sessionId);
90
- if (filter?.includeTerminated) qs.set("includeTerminated", "true");
91
- const query = qs.toString();
92
- return this.request("GET", `/v1/agents/${agentId}/computers${query ? `?${query}` : ""}`);
101
+ /** Get the agent's one persistent cloud computer. */
102
+ getComputer: (agentId, _legacyComputerId) => this.request("GET", `/v1/agents/${agentId}/computer`),
103
+ /** Wake the agent's persistent cloud computer, provisioning it if needed. */
104
+ wakeComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/wake`, params),
105
+ /** Sleep the runtime while preserving the computer's durable workspace. */
106
+ sleepComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/sleep`, params),
107
+ /** Replace the runtime without replacing the persistent computer. */
108
+ restartComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/restart`, params),
109
+ resizeComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/resize`, params),
110
+ execComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/exec`, params),
111
+ readComputerFile: (agentId, pathOrLegacyComputerId, legacyPath) => {
112
+ const path = legacyPath ?? pathOrLegacyComputerId;
113
+ return this.request(
114
+ "GET",
115
+ `/v1/agents/${agentId}/computer/files/read?path=${encodeURIComponent(path)}`
116
+ );
117
+ },
118
+ openComputerBrowser: (agentId, paramsOrLegacyComputerId, legacyParams) => {
119
+ const params = typeof paramsOrLegacyComputerId === "string" ? legacyParams : paramsOrLegacyComputerId;
120
+ if (!params) {
121
+ return Promise.reject(new TypeError("Browser options are required."));
122
+ }
123
+ return this.request(
124
+ "POST",
125
+ `/v1/agents/${agentId}/computer/browser/open`,
126
+ params
127
+ );
128
+ },
129
+ listComputerEvents: (agentId, limitOrLegacyComputerId, legacyLimit) => {
130
+ const limit = typeof limitOrLegacyComputerId === "number" ? limitOrLegacyComputerId : legacyLimit;
131
+ return this.request(
132
+ "GET",
133
+ `/v1/agents/${agentId}/computer/events${limit ? `?limit=${limit}` : ""}`
134
+ );
135
+ },
136
+ // ── Deprecated per-instance compatibility ────────────────────────────
137
+ /** @deprecated Use getComputer. The singleton is returned as a one-item list. */
138
+ listComputers: (agentId, _filter) => {
139
+ return this.request(
140
+ "GET",
141
+ `/v1/agents/${agentId}/computer`
142
+ ).then(({ data }) => ({
143
+ data: data ? [data] : []
144
+ }));
145
+ },
146
+ /** @deprecated Use wakeComputer. Lifecycle, name, and session are ignored. */
147
+ startComputer: (agentId, params) => this.request(
148
+ "POST",
149
+ `/v1/agents/${agentId}/computer/wake`,
150
+ params?.reason ? { reason: params.reason } : void 0
151
+ ),
152
+ /** @deprecated Use getComputer. Computer IDs are ignored. */
153
+ refreshComputer: (agentId, _computerId) => this.request("GET", `/v1/agents/${agentId}/computer`),
154
+ /** @deprecated Use sleepComputer. Computer IDs are ignored. */
155
+ stopComputer: (agentId, _computerId) => this.request("POST", `/v1/agents/${agentId}/computer/sleep`),
156
+ /** @deprecated Use execComputer. Computer IDs are ignored. */
157
+ runComputerCommand: (agentId, paramsOrLegacyComputerId, legacyParams) => {
158
+ const params = typeof paramsOrLegacyComputerId === "string" ? legacyParams : paramsOrLegacyComputerId;
159
+ if (!params) {
160
+ return Promise.reject(new TypeError("Command options are required."));
161
+ }
162
+ return this.request(
163
+ "POST",
164
+ `/v1/agents/${agentId}/computer/exec`,
165
+ params
166
+ );
93
167
  },
94
- startComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computers`, params),
95
- getComputer: (agentId, computerId) => this.request("GET", `/v1/agents/${agentId}/computers/${computerId}`),
96
- refreshComputer: (agentId, computerId) => this.request("POST", `/v1/agents/${agentId}/computers/${computerId}/refresh`),
97
- stopComputer: (agentId, computerId) => this.request("POST", `/v1/agents/${agentId}/computers/${computerId}/stop`),
98
- readComputerFile: (agentId, computerId, path) => this.request("GET", `/v1/agents/${agentId}/computers/${computerId}/files/read?path=${encodeURIComponent(path)}`),
99
- runComputerCommand: (agentId, computerId, params) => this.request("POST", `/v1/agents/${agentId}/computers/${computerId}/commands`, params),
100
- openComputerBrowser: (agentId, computerId, params) => this.request("POST", `/v1/agents/${agentId}/computers/${computerId}/browser/open`, params),
101
- listComputerEvents: (agentId, computerId, limit) => this.request("GET", `/v1/agents/${agentId}/computers/${computerId}/events${limit ? `?limit=${limit}` : ""}`),
102
168
  // ── TTS Voices ───────────────────────────────────────────────────────
103
169
  /**
104
170
  * List available TTS voices for a provider.
@@ -110,7 +176,10 @@ var CommonsClient = class {
110
176
  if (provider) params.set("provider", provider);
111
177
  if (q) params.set("q", q);
112
178
  const qs = params.toString();
113
- return this.request("GET", `/v1/agents/tts/voices${qs ? `?${qs}` : ""}`);
179
+ return this.request(
180
+ "GET",
181
+ `/v1/agents/tts/voices${qs ? `?${qs}` : ""}`
182
+ );
114
183
  }
115
184
  };
116
185
  }
@@ -124,20 +193,42 @@ var CommonsClient = class {
124
193
  get workflows() {
125
194
  return {
126
195
  create: (params) => this.request("POST", "/v1/workflows", params),
127
- list: (ownerId, ownerType) => this.request("GET", `/v1/workflows?ownerId=${ownerId}&ownerType=${ownerType}`),
196
+ list: (ownerId, ownerType) => this.request(
197
+ "GET",
198
+ `/v1/workflows?ownerId=${ownerId}&ownerType=${ownerType}`
199
+ ),
128
200
  get: (workflowId) => this.request("GET", `/v1/workflows/${workflowId}`),
129
201
  update: (workflowId, updates) => this.request("PUT", `/v1/workflows/${workflowId}`, updates),
130
202
  delete: (workflowId) => this.request("DELETE", `/v1/workflows/${workflowId}`),
131
203
  execute: (workflowId, params) => this.request("POST", `/v1/workflows/${workflowId}/execute`, params),
132
- getExecution: (workflowId, executionId) => this.request("GET", `/v1/workflows/${workflowId}/executions/${executionId}`),
133
- listExecutions: (workflowId, limit) => this.request("GET", `/v1/workflows/${workflowId}/executions${limit ? `?limit=${limit}` : ""}`),
134
- cancelExecution: (workflowId, executionId) => this.request("POST", `/v1/workflows/${workflowId}/executions/${executionId}/cancel`),
204
+ getExecution: (workflowId, executionId) => this.request(
205
+ "GET",
206
+ `/v1/workflows/${workflowId}/executions/${executionId}`
207
+ ),
208
+ listExecutions: (workflowId, limit) => this.request(
209
+ "GET",
210
+ `/v1/workflows/${workflowId}/executions${limit ? `?limit=${limit}` : ""}`
211
+ ),
212
+ cancelExecution: (workflowId, executionId) => this.request(
213
+ "POST",
214
+ `/v1/workflows/${workflowId}/executions/${executionId}/cancel`
215
+ ),
135
216
  /** Approve a paused human_approval node and resume execution. */
136
- approveExecution: (workflowId, executionId, params) => this.request("POST", `/v1/workflows/${workflowId}/executions/${executionId}/approve`, params),
217
+ approveExecution: (workflowId, executionId, params) => this.request(
218
+ "POST",
219
+ `/v1/workflows/${workflowId}/executions/${executionId}/approve`,
220
+ params
221
+ ),
137
222
  /** Reject a paused human_approval node and terminate execution. */
138
- rejectExecution: (workflowId, executionId, params) => this.request("POST", `/v1/workflows/${workflowId}/executions/${executionId}/reject`, params),
223
+ rejectExecution: (workflowId, executionId, params) => this.request(
224
+ "POST",
225
+ `/v1/workflows/${workflowId}/executions/${executionId}/reject`,
226
+ params
227
+ ),
139
228
  /** Stream execution progress via SSE. Returns an async generator. */
140
- stream: (workflowId, executionId) => this._streamSse(`/v1/workflows/${workflowId}/executions/${executionId}/stream`)
229
+ stream: (workflowId, executionId) => this._streamSse(
230
+ `/v1/workflows/${workflowId}/executions/${executionId}/stream`
231
+ )
141
232
  };
142
233
  }
143
234
  // ── Tasks ─────────────────────────────────────────────────────────────────
@@ -167,7 +258,10 @@ var CommonsClient = class {
167
258
  /** List all sessions for a given agent (all initiators). */
168
259
  listByAgent: (agentId) => this.request("GET", `/v1/sessions/agent/${agentId}`),
169
260
  /** List all sessions for a user across all agents. */
170
- listByUser: (initiator) => this.request("GET", `/v1/sessions/user/${encodeURIComponent(initiator)}`),
261
+ listByUser: (initiator) => this.request(
262
+ "GET",
263
+ `/v1/sessions/user/${encodeURIComponent(initiator)}`
264
+ ),
171
265
  create: (params) => this.request("POST", "/v1/sessions", params),
172
266
  get: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}`),
173
267
  /** Get full session with history, tasks, childSessions, and spaces. */
@@ -189,6 +283,37 @@ var CommonsClient = class {
189
283
  listStatic: () => this.request("GET", "/v1/tools/static")
190
284
  };
191
285
  }
286
+ // ── OAuth Connections ─────────────────────────────────────────────────────
287
+ get oauth() {
288
+ return {
289
+ /** List OAuth providers available on the platform (Google Workspace, GitHub, …). */
290
+ listProviders: () => this.request("GET", "/v1/oauth/providers"),
291
+ /** Get one provider's details, including its scope groups. */
292
+ getProvider: (providerKey) => this.request(
293
+ "GET",
294
+ `/v1/oauth/providers/${encodeURIComponent(providerKey)}`
295
+ ),
296
+ /**
297
+ * List the caller's OAuth connections (the accounts agents act with).
298
+ * `ownerId` is only needed when authenticating with a management key.
299
+ */
300
+ listConnections: (params) => {
301
+ const q = params ? new URLSearchParams(params).toString() : "";
302
+ return this.request("GET", `/v1/oauth/connections${q ? `?${q}` : ""}`);
303
+ },
304
+ /**
305
+ * Start an OAuth connect flow. Returns the authorization URL the user
306
+ * must open in a browser to grant access.
307
+ */
308
+ connect: (params) => this.request("POST", "/v1/oauth/connect", params),
309
+ /** Refresh a connection's access token now. */
310
+ refresh: (connectionId) => this.request("POST", `/v1/oauth/connections/${connectionId}/refresh`),
311
+ /** Check whether a connection's token is valid. */
312
+ test: (connectionId) => this.request("GET", `/v1/oauth/connections/${connectionId}/test`),
313
+ /** Revoke a connection and delete its tokens. */
314
+ revoke: (connectionId) => this.request("DELETE", `/v1/oauth/connections/${connectionId}`)
315
+ };
316
+ }
192
317
  // ── Tool Keys ─────────────────────────────────────────────────────────────
193
318
  get toolKeys() {
194
319
  return {
@@ -218,7 +343,8 @@ var CommonsClient = class {
218
343
  const params = new URLSearchParams();
219
344
  if (filter?.ownerId) params.set("ownerId", filter.ownerId);
220
345
  if (filter?.ownerType) params.set("ownerType", filter.ownerType);
221
- if (filter?.isPublic !== void 0) params.set("isPublic", String(filter.isPublic));
346
+ if (filter?.isPublic !== void 0)
347
+ params.set("isPublic", String(filter.isPublic));
222
348
  const qs = params.toString();
223
349
  return this.request("GET", `/v1/skills${qs ? `?${qs}` : ""}`);
224
350
  },
@@ -280,7 +406,10 @@ var CommonsClient = class {
280
406
  create: (params) => this.request("POST", "/v1/auth/api-keys", params),
281
407
  /** List all active API keys for a principal (key values not included). */
282
408
  list: (principalId, principalType) => {
283
- const q = new URLSearchParams({ principalId, principalType }).toString();
409
+ const q = new URLSearchParams({
410
+ principalId,
411
+ principalType
412
+ }).toString();
284
413
  return this.request("GET", `/v1/auth/api-keys?${q}`);
285
414
  },
286
415
  /** Revoke (soft-delete) an API key by its UUID. */
@@ -363,7 +492,10 @@ var CommonsClient = class {
363
492
  params: { id: taskId }
364
493
  }).then((r) => r.result),
365
494
  /** List recent A2A tasks for an agent. */
366
- listTasks: (agentId, limit) => this.request("GET", `/v1/a2a/${agentId}/tasks${limit ? `?limit=${limit}` : ""}`),
495
+ listTasks: (agentId, limit) => this.request(
496
+ "GET",
497
+ `/v1/a2a/${agentId}/tasks${limit ? `?limit=${limit}` : ""}`
498
+ ),
367
499
  /** Stream A2A task updates (SSE). */
368
500
  stream: (agentId, taskId) => this._streamSse(`/v1/a2a/${agentId}/tasks/${taskId}/stream`)
369
501
  };
@@ -372,11 +504,18 @@ var CommonsClient = class {
372
504
  get mcp() {
373
505
  return {
374
506
  /** List MCP servers for an owner. */
375
- listServers: (ownerId, ownerType) => this.request("GET", `/v1/mcp/servers?ownerId=${ownerId}&ownerType=${ownerType}`),
507
+ listServers: (ownerId, ownerType) => this.request(
508
+ "GET",
509
+ `/v1/mcp/servers?ownerId=${ownerId}&ownerType=${ownerType}`
510
+ ),
376
511
  /** Create a new MCP server. */
377
512
  createServer: (params) => {
378
513
  const { ownerId, ownerType, ...dto } = params;
379
- return this.request("POST", `/v1/mcp/servers?ownerId=${ownerId}&ownerType=${ownerType}`, dto);
514
+ return this.request(
515
+ "POST",
516
+ `/v1/mcp/servers?ownerId=${ownerId}&ownerType=${ownerType}`,
517
+ dto
518
+ );
380
519
  },
381
520
  /** Get MCP server by ID. */
382
521
  getServer: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}`),
@@ -397,15 +536,25 @@ var CommonsClient = class {
397
536
  /** List tools discovered from an MCP server. */
398
537
  listTools: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}/tools`),
399
538
  /** List all MCP tools across all servers for a given owner. */
400
- listToolsByOwner: (ownerId, ownerType) => this.request("GET", `/v1/mcp/tools?ownerId=${ownerId}&ownerType=${ownerType}`),
539
+ listToolsByOwner: (ownerId, ownerType) => this.request(
540
+ "GET",
541
+ `/v1/mcp/tools?ownerId=${ownerId}&ownerType=${ownerType}`
542
+ ),
401
543
  /** List resources from an MCP server. */
402
544
  listResources: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}/resources`),
403
545
  /** Read a resource by URI. */
404
- readResource: (serverId, uri) => this.request("GET", `/v1/mcp/servers/${serverId}/resources/read?uri=${encodeURIComponent(uri)}`),
546
+ readResource: (serverId, uri) => this.request(
547
+ "GET",
548
+ `/v1/mcp/servers/${serverId}/resources/read?uri=${encodeURIComponent(uri)}`
549
+ ),
405
550
  /** List prompts from an MCP server. */
406
551
  listPrompts: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}/prompts`),
407
552
  /** Render a prompt with arguments. */
408
- getPrompt: (serverId, promptName, args) => this.request("POST", `/v1/mcp/servers/${serverId}/prompts/${promptName}`, { arguments: args })
553
+ getPrompt: (serverId, promptName, args) => this.request(
554
+ "POST",
555
+ `/v1/mcp/servers/${serverId}/prompts/${promptName}`,
556
+ { arguments: args }
557
+ )
409
558
  };
410
559
  }
411
560
  // ── Memory ────────────────────────────────────────────────────────────────
@@ -417,7 +566,10 @@ var CommonsClient = class {
417
566
  if (opts?.type) params.set("type", opts.type);
418
567
  if (opts?.limit) params.set("limit", String(opts.limit));
419
568
  const qs = params.toString();
420
- return this.request("GET", `/v1/memory/agents/${agentId}${qs ? `?${qs}` : ""}`);
569
+ return this.request(
570
+ "GET",
571
+ `/v1/memory/agents/${agentId}${qs ? `?${qs}` : ""}`
572
+ );
421
573
  },
422
574
  /** Get memory stats for an agent. */
423
575
  stats: (agentId) => this.request("GET", `/v1/memory/agents/${agentId}/stats`),
@@ -425,7 +577,10 @@ var CommonsClient = class {
425
577
  retrieve: (agentId, query, limit) => {
426
578
  const params = new URLSearchParams({ q: query });
427
579
  if (limit) params.set("limit", String(limit));
428
- return this.request("GET", `/v1/memory/agents/${agentId}/retrieve?${params}`);
580
+ return this.request(
581
+ "GET",
582
+ `/v1/memory/agents/${agentId}/retrieve?${params}`
583
+ );
429
584
  },
430
585
  /** Get a single memory by ID. */
431
586
  get: (memoryId) => this.request("GET", `/v1/memory/${memoryId}`),
@@ -434,7 +589,11 @@ var CommonsClient = class {
434
589
  /** Update a memory. */
435
590
  update: (memoryId, params) => this.request("PATCH", `/v1/memory/${memoryId}`, params),
436
591
  /** Soft-delete (deactivate) a memory. */
437
- delete: (memoryId) => this.request("DELETE", `/v1/memory/${memoryId}`)
592
+ delete: (memoryId) => this.request("DELETE", `/v1/memory/${memoryId}`),
593
+ /** Create an append-only memory scope shared by a set of owned agents. */
594
+ createSharedScope: (params) => this.request("POST", "/v1/memory/shared-scopes", params),
595
+ /** List shared-memory scopes available to an agent. */
596
+ listSharedScopes: (agentId) => this.request("GET", `/v1/memory/shared-scopes/agents/${agentId}`)
438
597
  };
439
598
  }
440
599
  // ── Usage / Observability ─────────────────────────────────────────────────
@@ -446,7 +605,10 @@ var CommonsClient = class {
446
605
  if (opts?.from) params.set("from", opts.from);
447
606
  if (opts?.to) params.set("to", opts.to);
448
607
  const qs = params.toString();
449
- return this.request("GET", `/v1/usage/agents/${agentId}${qs ? `?${qs}` : ""}`);
608
+ return this.request(
609
+ "GET",
610
+ `/v1/usage/agents/${agentId}${qs ? `?${qs}` : ""}`
611
+ );
450
612
  },
451
613
  /** Get aggregated token + cost usage for a session. */
452
614
  getSessionUsage: (sessionId) => this.request("GET", `/v1/usage/sessions/${sessionId}`)