@agent-commons/sdk 0.3.0 → 0.5.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,30 +1,95 @@
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
+ );
8
+ this.identityUrl = (config.identityUrl ?? "https://auth.agentcommons.io").replace(/\/api\/auth\/?$/, "").replace(/\/$/, "");
9
+ this.identityToken = config.identityToken;
5
10
  this.apiKey = config.apiKey;
6
11
  this.initiator = config.initiator;
7
12
  this._fetch = config.fetch ?? fetch;
8
13
  }
9
14
  // ── Helpers ───────────────────────────────────────────────────────────────
10
- headers(extra) {
11
- const h = { "Content-Type": "application/json" };
15
+ headers(extra, json = true) {
16
+ const h = {};
17
+ if (json) h["Content-Type"] = "application/json";
12
18
  if (this.apiKey) h["Authorization"] = `Bearer ${this.apiKey}`;
13
19
  if (this.initiator) h["x-initiator"] = this.initiator;
14
20
  return { ...h, ...extra };
15
21
  }
16
- async request(method, path, body) {
22
+ /**
23
+ * Call an API route that is not yet represented by a resource namespace.
24
+ * Most applications should use the typed helpers below.
25
+ */
26
+ async request(method, path, body, options = {}) {
27
+ const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
17
28
  const res = await this._fetch(`${this.baseUrl}${path}`, {
18
29
  method,
19
- headers: this.headers(),
20
- body: body !== void 0 ? JSON.stringify(body) : void 0
30
+ headers: this.headers(options.headers, !isFormData),
31
+ body: body === void 0 ? void 0 : isFormData ? body : JSON.stringify(body),
32
+ signal: options.signal
21
33
  });
22
34
  if (!res.ok) {
23
- const err = await res.json().catch(() => ({ message: res.statusText }));
24
- throw new CommonsError(err.message ?? res.statusText, res.status, err);
35
+ const err = await this.errorPayload(res);
36
+ throw new CommonsError(
37
+ this.errorMessage(err, res.statusText),
38
+ res.status,
39
+ err
40
+ );
41
+ }
42
+ if (res.status === 204) return void 0;
43
+ const contentType = res.headers.get("content-type") ?? "";
44
+ if (!contentType.includes("json")) {
45
+ return await res.text();
25
46
  }
26
47
  return res.json();
27
48
  }
49
+ async errorPayload(res) {
50
+ const contentType = res.headers.get("content-type") ?? "";
51
+ if (contentType.includes("json")) {
52
+ return res.json().catch(() => ({ message: res.statusText }));
53
+ }
54
+ const message = await res.text().catch(() => "");
55
+ return { message: message || res.statusText };
56
+ }
57
+ errorMessage(error, fallback) {
58
+ if (!error || typeof error !== "object") return fallback;
59
+ if ("message" in error && typeof error.message === "string") {
60
+ return error.message;
61
+ }
62
+ if ("error" in error) {
63
+ if (typeof error.error === "string") return error.error;
64
+ if (error.error && typeof error.error === "object" && "message" in error.error && typeof error.error.message === "string") {
65
+ return error.error.message;
66
+ }
67
+ }
68
+ return fallback;
69
+ }
70
+ async identityRequest(method, path, body) {
71
+ const headers = {};
72
+ if (body !== void 0) headers["Content-Type"] = "application/json";
73
+ if (this.identityToken) {
74
+ headers.Authorization = `Bearer ${this.identityToken}`;
75
+ }
76
+ const response = await this._fetch(`${this.identityUrl}${path}`, {
77
+ method,
78
+ headers,
79
+ credentials: "include",
80
+ body: body === void 0 ? void 0 : JSON.stringify(body)
81
+ });
82
+ if (!response.ok) {
83
+ const error = await this.errorPayload(response);
84
+ throw new CommonsError(
85
+ this.errorMessage(error, response.statusText),
86
+ response.status,
87
+ error
88
+ );
89
+ }
90
+ if (response.status === 204) return void 0;
91
+ return response.json();
92
+ }
28
93
  // ── Models ────────────────────────────────────────────────────────────────
29
94
  get models() {
30
95
  return {
@@ -39,12 +104,31 @@ var CommonsClient = class {
39
104
  list: (owner) => this.request("GET", `/v1/agents${owner ? `?owner=${owner}` : ""}`),
40
105
  get: (agentId) => this.request("GET", `/v1/agents/${agentId}`),
41
106
  update: (agentId, params) => this.request("PUT", `/v1/agents/${agentId}`, params),
107
+ getRuntime: (agentId) => this.request("GET", `/v1/agents/${agentId}/runtime`),
108
+ configureRuntime: (agentId, params) => this.request("PUT", `/v1/agents/${agentId}/runtime`, params),
109
+ deployRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/deploy`),
110
+ sleepRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/sleep`),
111
+ restartRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/restart`),
112
+ manageRuntimeChannel: (agentId, channel, action, params = {}) => this.request(
113
+ "POST",
114
+ `/v1/agents/${encodeURIComponent(agentId)}/runtime/channels/${encodeURIComponent(channel)}/${encodeURIComponent(action)}`,
115
+ params
116
+ ),
42
117
  /** List tools assigned to an agent. */
43
118
  listTools: (agentId) => this.request("GET", `/v1/agents/${agentId}/tools`),
44
119
  /** Assign a tool to an agent. */
45
120
  addTool: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/tools`, params),
121
+ /** Update an agent tool assignment. */
122
+ updateTool: (assignmentId, params) => this.request(
123
+ "PATCH",
124
+ `/v1/agents/tools/${encodeURIComponent(assignmentId)}`,
125
+ params
126
+ ),
46
127
  /** Remove a tool assignment from an agent. */
47
- removeTool: (assignmentId) => this.request("DELETE", `/v1/agents/tools/${assignmentId}`),
128
+ removeTool: (assignmentId) => this.request(
129
+ "DELETE",
130
+ `/v1/agents/tools/${encodeURIComponent(assignmentId)}`
131
+ ),
48
132
  /** Create a liaison agent for an external agent. */
49
133
  createLiaison: (params) => this.request("POST", "/v1/liaison", params),
50
134
  /**
@@ -57,6 +141,11 @@ var CommonsClient = class {
57
141
  * }
58
142
  */
59
143
  stream: (params) => this._streamAgentRun(params),
144
+ /** Resume a streamed run after executing a caller-owned CLI tool. */
145
+ submitCliToolResult: (requestId, result) => this.request("POST", "/v1/agents/cli-tool-result", {
146
+ requestId,
147
+ result
148
+ }),
60
149
  // ── Heartbeat ─────────────────────────────────────────────────────────
61
150
  /** Get the current heartbeat status for an agent. */
62
151
  getAutonomy: (agentId) => this.request("GET", `/v1/agents/${agentId}/autonomy`),
@@ -73,32 +162,100 @@ var CommonsClient = class {
73
162
  /** Get the knowledgebase entries for an agent. */
74
163
  getKnowledgebase: (agentId) => this.request("GET", `/v1/agents/${agentId}/knowledgebase`),
75
164
  /** Replace the knowledgebase entries for an agent. */
76
- updateKnowledgebase: (agentId, knowledgebase) => this.request("PUT", `/v1/agents/${agentId}/knowledgebase`, { knowledgebase }),
165
+ updateKnowledgebase: (agentId, knowledgebase) => this.request("PUT", `/v1/agents/${agentId}/knowledgebase`, {
166
+ knowledgebase
167
+ }),
77
168
  // ── Preferred Connections ────────────────────────────────────────────
78
169
  /** List agents that this agent prefers to collaborate with. */
79
170
  getPreferredConnections: (agentId) => this.request("GET", `/v1/agents/${agentId}/preferred-connections`),
80
171
  /** Add a preferred agent connection. */
81
- addPreferredConnection: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/preferred-connections`, params),
172
+ addPreferredConnection: (agentId, params) => this.request(
173
+ "POST",
174
+ `/v1/agents/${agentId}/preferred-connections`,
175
+ params
176
+ ),
82
177
  /** Remove a preferred agent connection by its record ID. */
83
178
  removePreferredConnection: (id) => this.request("DELETE", `/v1/agents/preferred-connections/${id}`),
84
179
  // ── Computers ────────────────────────────────────────────────────────
85
180
  getComputerConfig: (agentId) => this.request("GET", `/v1/agents/${agentId}/computer/config`),
86
181
  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}` : ""}`);
93
- },
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}` : ""}`),
182
+ /** Get the agent's one persistent cloud computer. */
183
+ getComputer: (agentId, _legacyComputerId) => this.request("GET", `/v1/agents/${agentId}/computer`),
184
+ /** Wake the agent's persistent cloud computer, provisioning it if needed. */
185
+ wakeComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/wake`, params),
186
+ /** Sleep the runtime while preserving the computer's durable workspace. */
187
+ sleepComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/sleep`, params),
188
+ /** Replace the runtime without replacing the persistent computer. */
189
+ restartComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/restart`, params),
190
+ resizeComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/resize`, params),
191
+ execComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/exec`, params),
192
+ readComputerFile: (agentId, pathOrLegacyComputerId, legacyPath) => {
193
+ const path = legacyPath ?? pathOrLegacyComputerId;
194
+ return this.request(
195
+ "GET",
196
+ `/v1/agents/${agentId}/computer/files/read?path=${encodeURIComponent(path)}`
197
+ );
198
+ },
199
+ writeComputerFile: (agentId, params) => this.request(
200
+ "POST",
201
+ `/v1/agents/${encodeURIComponent(agentId)}/computer/files/write`,
202
+ params
203
+ ),
204
+ openComputerBrowser: (agentId, paramsOrLegacyComputerId, legacyParams) => {
205
+ const params = typeof paramsOrLegacyComputerId === "string" ? legacyParams : paramsOrLegacyComputerId;
206
+ if (!params) {
207
+ return Promise.reject(new TypeError("Browser options are required."));
208
+ }
209
+ return this.request(
210
+ "POST",
211
+ `/v1/agents/${agentId}/computer/browser/open`,
212
+ params
213
+ );
214
+ },
215
+ testComputerBrowser: (agentId) => this.request(
216
+ "POST",
217
+ `/v1/agents/${encodeURIComponent(agentId)}/computer/browser/test`,
218
+ {}
219
+ ),
220
+ listComputerEvents: (agentId, limitOrLegacyComputerId, legacyLimit) => {
221
+ const limit = typeof limitOrLegacyComputerId === "number" ? limitOrLegacyComputerId : legacyLimit;
222
+ return this.request(
223
+ "GET",
224
+ `/v1/agents/${agentId}/computer/events${limit ? `?limit=${limit}` : ""}`
225
+ );
226
+ },
227
+ // ── Deprecated per-instance compatibility ────────────────────────────
228
+ /** @deprecated Use getComputer. The singleton is returned as a one-item list. */
229
+ listComputers: (agentId, _filter) => {
230
+ return this.request(
231
+ "GET",
232
+ `/v1/agents/${agentId}/computer`
233
+ ).then(({ data }) => ({
234
+ data: data ? [data] : []
235
+ }));
236
+ },
237
+ /** @deprecated Use wakeComputer. Lifecycle, name, and session are ignored. */
238
+ startComputer: (agentId, params) => this.request(
239
+ "POST",
240
+ `/v1/agents/${agentId}/computer/wake`,
241
+ params?.reason ? { reason: params.reason } : void 0
242
+ ),
243
+ /** @deprecated Use getComputer. Computer IDs are ignored. */
244
+ refreshComputer: (agentId, _computerId) => this.request("GET", `/v1/agents/${agentId}/computer`),
245
+ /** @deprecated Use sleepComputer. Computer IDs are ignored. */
246
+ stopComputer: (agentId, _computerId) => this.request("POST", `/v1/agents/${agentId}/computer/sleep`),
247
+ /** @deprecated Use execComputer. Computer IDs are ignored. */
248
+ runComputerCommand: (agentId, paramsOrLegacyComputerId, legacyParams) => {
249
+ const params = typeof paramsOrLegacyComputerId === "string" ? legacyParams : paramsOrLegacyComputerId;
250
+ if (!params) {
251
+ return Promise.reject(new TypeError("Command options are required."));
252
+ }
253
+ return this.request(
254
+ "POST",
255
+ `/v1/agents/${agentId}/computer/exec`,
256
+ params
257
+ );
258
+ },
102
259
  // ── TTS Voices ───────────────────────────────────────────────────────
103
260
  /**
104
261
  * List available TTS voices for a provider.
@@ -110,10 +267,33 @@ var CommonsClient = class {
110
267
  if (provider) params.set("provider", provider);
111
268
  if (q) params.set("q", q);
112
269
  const qs = params.toString();
113
- return this.request("GET", `/v1/agents/tts/voices${qs ? `?${qs}` : ""}`);
270
+ return this.request(
271
+ "GET",
272
+ `/v1/agents/tts/voices${qs ? `?${qs}` : ""}`
273
+ );
114
274
  }
115
275
  };
116
276
  }
277
+ get copilot() {
278
+ return {
279
+ get: () => this.request("GET", "/v1/copilot"),
280
+ updateSettings: (params) => this.request("PUT", "/v1/copilot/settings", params),
281
+ listChanges: (filter) => {
282
+ const query = new URLSearchParams();
283
+ if (filter?.status) query.set("status", filter.status);
284
+ if (filter?.resourceType)
285
+ query.set("resourceType", filter.resourceType);
286
+ if (filter?.resourceId) query.set("resourceId", filter.resourceId);
287
+ return this.request(
288
+ "GET",
289
+ `/v1/copilot/changes${query.size ? `?${query}` : ""}`
290
+ );
291
+ },
292
+ acceptChange: (changeId) => this.request("POST", `/v1/copilot/changes/${changeId}/accept`),
293
+ rejectChange: (changeId) => this.request("POST", `/v1/copilot/changes/${changeId}/reject`),
294
+ revertChange: (changeId) => this.request("POST", `/v1/copilot/changes/${changeId}/revert`)
295
+ };
296
+ }
117
297
  // ── Run (non-streaming) ───────────────────────────────────────────────────
118
298
  get run() {
119
299
  return {
@@ -124,20 +304,78 @@ var CommonsClient = class {
124
304
  get workflows() {
125
305
  return {
126
306
  create: (params) => this.request("POST", "/v1/workflows", params),
127
- list: (ownerId, ownerType) => this.request("GET", `/v1/workflows?ownerId=${ownerId}&ownerType=${ownerType}`),
307
+ list: (ownerId, ownerType) => this.request(
308
+ "GET",
309
+ `/v1/workflows?ownerId=${ownerId}&ownerType=${ownerType}`
310
+ ),
311
+ discoverPublic: (filter) => {
312
+ const query = new URLSearchParams();
313
+ if (filter?.category) query.set("category", filter.category);
314
+ if (filter?.tags?.length) query.set("tags", filter.tags.join(","));
315
+ if (filter?.limit) query.set("limit", String(filter.limit));
316
+ return this.request(
317
+ "GET",
318
+ `/v1/workflows/public${query.size ? `?${query}` : ""}`
319
+ );
320
+ },
128
321
  get: (workflowId) => this.request("GET", `/v1/workflows/${workflowId}`),
129
322
  update: (workflowId, updates) => this.request("PUT", `/v1/workflows/${workflowId}`, updates),
130
323
  delete: (workflowId) => this.request("DELETE", `/v1/workflows/${workflowId}`),
324
+ fork: (workflowId, params) => this.request(
325
+ "POST",
326
+ `/v1/workflows/${encodeURIComponent(workflowId)}/fork`,
327
+ params
328
+ ),
329
+ getWebhook: (workflowId) => this.request(
330
+ "GET",
331
+ `/v1/workflows/${encodeURIComponent(workflowId)}/webhook`
332
+ ),
333
+ rotateWebhookToken: (workflowId) => this.request(
334
+ "POST",
335
+ `/v1/workflows/${encodeURIComponent(workflowId)}/webhook-token`,
336
+ {}
337
+ ),
338
+ disableWebhook: (workflowId) => this.request(
339
+ "DELETE",
340
+ `/v1/workflows/${encodeURIComponent(workflowId)}/webhook-token`
341
+ ),
342
+ executeWebhook: (token, payload, query) => {
343
+ const search = query ? new URLSearchParams(query).toString() : "";
344
+ return this.request(
345
+ "POST",
346
+ `/v1/workflows/webhooks/${encodeURIComponent(token)}${search ? `?${search}` : ""}`,
347
+ payload
348
+ );
349
+ },
131
350
  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`),
351
+ getExecution: (workflowId, executionId) => this.request(
352
+ "GET",
353
+ `/v1/workflows/${workflowId}/executions/${executionId}`
354
+ ),
355
+ listExecutions: (workflowId, limit) => this.request(
356
+ "GET",
357
+ `/v1/workflows/${workflowId}/executions${limit ? `?limit=${limit}` : ""}`
358
+ ),
359
+ cancelExecution: (workflowId, executionId) => this.request(
360
+ "POST",
361
+ `/v1/workflows/${workflowId}/executions/${executionId}/cancel`
362
+ ),
135
363
  /** Approve a paused human_approval node and resume execution. */
136
- approveExecution: (workflowId, executionId, params) => this.request("POST", `/v1/workflows/${workflowId}/executions/${executionId}/approve`, params),
364
+ approveExecution: (workflowId, executionId, params) => this.request(
365
+ "POST",
366
+ `/v1/workflows/${workflowId}/executions/${executionId}/approve`,
367
+ params
368
+ ),
137
369
  /** Reject a paused human_approval node and terminate execution. */
138
- rejectExecution: (workflowId, executionId, params) => this.request("POST", `/v1/workflows/${workflowId}/executions/${executionId}/reject`, params),
370
+ rejectExecution: (workflowId, executionId, params) => this.request(
371
+ "POST",
372
+ `/v1/workflows/${workflowId}/executions/${executionId}/reject`,
373
+ params
374
+ ),
139
375
  /** Stream execution progress via SSE. Returns an async generator. */
140
- stream: (workflowId, executionId) => this._streamSse(`/v1/workflows/${workflowId}/executions/${executionId}/stream`)
376
+ stream: (workflowId, executionId) => this._streamSse(
377
+ `/v1/workflows/${workflowId}/executions/${executionId}/stream`
378
+ )
141
379
  };
142
380
  }
143
381
  // ── Tasks ─────────────────────────────────────────────────────────────────
@@ -167,11 +405,30 @@ var CommonsClient = class {
167
405
  /** List all sessions for a given agent (all initiators). */
168
406
  listByAgent: (agentId) => this.request("GET", `/v1/sessions/agent/${agentId}`),
169
407
  /** List all sessions for a user across all agents. */
170
- listByUser: (initiator) => this.request("GET", `/v1/sessions/user/${encodeURIComponent(initiator)}`),
408
+ listByUser: (initiator) => this.request(
409
+ "GET",
410
+ `/v1/sessions/user/${encodeURIComponent(initiator)}`
411
+ ),
171
412
  create: (params) => this.request("POST", "/v1/sessions", params),
172
413
  get: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}`),
173
414
  /** Get full session with history, tasks, childSessions, and spaces. */
174
- getFull: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}/full`)
415
+ getFull: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}/full`),
416
+ /** Rename a session. */
417
+ rename: (sessionId, title) => this.request(
418
+ "PATCH",
419
+ `/v1/sessions/${encodeURIComponent(sessionId)}`,
420
+ { title }
421
+ ),
422
+ /** Delete a session and its owned session data. */
423
+ delete: (sessionId) => this.request(
424
+ "DELETE",
425
+ `/v1/sessions/${encodeURIComponent(sessionId)}`
426
+ ),
427
+ /** Get the full chat transcript for a session. */
428
+ getChat: (sessionId) => this.request(
429
+ "GET",
430
+ `/v1/agents/sessions/${encodeURIComponent(sessionId)}/chat`
431
+ )
175
432
  };
176
433
  }
177
434
  // ── Tools ─────────────────────────────────────────────────────────────────
@@ -189,26 +446,141 @@ var CommonsClient = class {
189
446
  listStatic: () => this.request("GET", "/v1/tools/static")
190
447
  };
191
448
  }
449
+ // ── OAuth Connections ─────────────────────────────────────────────────────
450
+ get oauth() {
451
+ return {
452
+ /** List OAuth providers available on the platform (Google Workspace, GitHub, …). */
453
+ listProviders: () => this.request("GET", "/v1/oauth/providers"),
454
+ /** Get one provider's details, including its scope groups. */
455
+ getProvider: (providerKey) => this.request(
456
+ "GET",
457
+ `/v1/oauth/providers/${encodeURIComponent(providerKey)}`
458
+ ),
459
+ /**
460
+ * List the caller's OAuth connections (the accounts agents act with).
461
+ * `ownerId` is only needed when authenticating with a management key.
462
+ */
463
+ listConnections: (params) => {
464
+ const q = params ? new URLSearchParams(params).toString() : "";
465
+ return this.request("GET", `/v1/oauth/connections${q ? `?${q}` : ""}`);
466
+ },
467
+ /** Get one OAuth connection. */
468
+ getConnection: (connectionId) => this.request(
469
+ "GET",
470
+ `/v1/oauth/connections/${encodeURIComponent(connectionId)}`
471
+ ),
472
+ /** Update connection metadata or its active status. */
473
+ updateConnection: (connectionId, params) => this.request(
474
+ "PUT",
475
+ `/v1/oauth/connections/${encodeURIComponent(connectionId)}`,
476
+ params
477
+ ),
478
+ /**
479
+ * Start an OAuth connect flow. Returns the authorization URL the user
480
+ * must open in a browser to grant access.
481
+ */
482
+ connect: (params) => this.request("POST", "/v1/oauth/connect", params),
483
+ /** Refresh a connection's access token now. */
484
+ refresh: (connectionId) => this.request(
485
+ "POST",
486
+ `/v1/oauth/connections/${encodeURIComponent(connectionId)}/refresh`
487
+ ),
488
+ /** Check whether a connection's token is valid. */
489
+ test: (connectionId) => this.request(
490
+ "GET",
491
+ `/v1/oauth/connections/${encodeURIComponent(connectionId)}/test`
492
+ ),
493
+ /** Revoke a connection and delete its tokens. */
494
+ revoke: (connectionId) => this.request(
495
+ "DELETE",
496
+ `/v1/oauth/connections/${encodeURIComponent(connectionId)}`
497
+ )
498
+ };
499
+ }
192
500
  // ── Tool Keys ─────────────────────────────────────────────────────────────
193
501
  get toolKeys() {
194
502
  return {
195
- list: (filter) => {
196
- const q = new URLSearchParams(filter).toString();
197
- return this.request("GET", `/v1/tool-keys${q ? `?${q}` : ""}`);
198
- },
503
+ list: () => this.request("GET", "/v1/tool-keys"),
199
504
  create: (params) => this.request("POST", "/v1/tool-keys", params),
200
- delete: (keyId) => this.request("DELETE", `/v1/tool-keys/${keyId}`)
505
+ get: (keyId) => this.request(
506
+ "GET",
507
+ `/v1/tool-keys/${encodeURIComponent(keyId)}`
508
+ ),
509
+ updateMetadata: (keyId, params) => this.request(
510
+ "PUT",
511
+ `/v1/tool-keys/${encodeURIComponent(keyId)}/metadata`,
512
+ params
513
+ ),
514
+ updateValue: (keyId, value) => this.request(
515
+ "PUT",
516
+ `/v1/tool-keys/${encodeURIComponent(keyId)}/value`,
517
+ { value }
518
+ ),
519
+ test: (keyId) => this.request(
520
+ "POST",
521
+ `/v1/tool-keys/${encodeURIComponent(keyId)}/test`,
522
+ {}
523
+ ),
524
+ mapToTool: (params) => this.request("POST", "/v1/tool-keys/map", params),
525
+ removeMapping: (mappingId) => this.request(
526
+ "DELETE",
527
+ `/v1/tool-keys/map/${encodeURIComponent(mappingId)}`
528
+ ),
529
+ delete: (keyId) => this.request(
530
+ "DELETE",
531
+ `/v1/tool-keys/${encodeURIComponent(keyId)}`
532
+ )
201
533
  };
202
534
  }
203
535
  // ── Tool Permissions ──────────────────────────────────────────────────────
204
536
  get toolPermissions() {
205
537
  return {
206
- list: (toolId) => {
207
- const q = toolId ? `?toolId=${toolId}` : "";
208
- return this.request("GET", `/v1/tool-permissions${q}`);
538
+ /** @deprecated Use listForTool with a tool ID. */
539
+ list: (toolId) => this.request(
540
+ "GET",
541
+ `/v1/tool-permissions/tool/${encodeURIComponent(toolId)}`
542
+ ),
543
+ listForTool: (toolId) => this.request(
544
+ "GET",
545
+ `/v1/tool-permissions/tool/${encodeURIComponent(toolId)}`
546
+ ),
547
+ listForSubject: (subjectId, subjectType) => {
548
+ const query = new URLSearchParams({ subjectId, subjectType });
549
+ return this.request(
550
+ "GET",
551
+ `/v1/tool-permissions/subject?${query}`
552
+ );
553
+ },
554
+ accessibleTools: (subjectId, subjectType) => {
555
+ const query = new URLSearchParams({ subjectId, subjectType });
556
+ return this.request(
557
+ "GET",
558
+ `/v1/tool-permissions/accessible-tools?${query}`
559
+ );
209
560
  },
210
561
  grant: (params) => this.request("POST", "/v1/tool-permissions/grant", params),
211
- revoke: (permissionId) => this.request("DELETE", `/v1/tool-permissions/revoke/${permissionId}`)
562
+ batchGrant: (params) => this.request("POST", "/v1/tool-permissions/batch-grant", params),
563
+ revoke: (permissionId) => this.request(
564
+ "DELETE",
565
+ `/v1/tool-permissions/${encodeURIComponent(permissionId)}`
566
+ ),
567
+ check: (params) => this.request(
568
+ "GET",
569
+ `/v1/tool-permissions/check?${new URLSearchParams(params)}`
570
+ ),
571
+ checkAgentAccess: (toolId, agentId, userId) => {
572
+ const query = new URLSearchParams({ toolId, agentId });
573
+ if (userId) query.set("userId", userId);
574
+ return this.request(
575
+ "GET",
576
+ `/v1/tool-permissions/check-agent-access?${query}`
577
+ );
578
+ },
579
+ transferOwnership: (params) => this.request(
580
+ "POST",
581
+ "/v1/tool-permissions/transfer-ownership",
582
+ params
583
+ )
212
584
  };
213
585
  }
214
586
  // ── Skills ────────────────────────────────────────────────────────────────
@@ -218,7 +590,8 @@ var CommonsClient = class {
218
590
  const params = new URLSearchParams();
219
591
  if (filter?.ownerId) params.set("ownerId", filter.ownerId);
220
592
  if (filter?.ownerType) params.set("ownerType", filter.ownerType);
221
- if (filter?.isPublic !== void 0) params.set("isPublic", String(filter.isPublic));
593
+ if (filter?.isPublic !== void 0)
594
+ params.set("isPublic", String(filter.isPublic));
222
595
  const qs = params.toString();
223
596
  return this.request("GET", `/v1/skills${qs ? `?${qs}` : ""}`);
224
597
  },
@@ -270,7 +643,34 @@ var CommonsClient = class {
270
643
  me: () => this.request("GET", "/v1/auth/me")
271
644
  };
272
645
  }
273
- // ── API Keys ──────────────────────────────────────────────────────────────
646
+ // ── Developer projects and project API keys ──────────────────────────────
647
+ get developer() {
648
+ return {
649
+ scopes: () => this.identityRequest("GET", "/api/platform/scopes"),
650
+ listProjects: () => this.identityRequest("GET", "/api/platform/projects"),
651
+ createProject: (params) => this.identityRequest("POST", "/api/platform/projects", params),
652
+ listApiKeys: (projectId) => this.identityRequest(
653
+ "GET",
654
+ `/api/platform/projects/${encodeURIComponent(projectId)}/api-keys`
655
+ ),
656
+ createApiKey: (projectId, params) => this.identityRequest(
657
+ "POST",
658
+ `/api/platform/projects/${encodeURIComponent(projectId)}/api-keys`,
659
+ params
660
+ ),
661
+ revokeApiKey: (keyId) => this.identityRequest(
662
+ "DELETE",
663
+ `/api/platform/api-keys/${encodeURIComponent(keyId)}`
664
+ )
665
+ };
666
+ }
667
+ // ── Legacy principal API keys ─────────────────────────────────────────────
668
+ /**
669
+ * Legacy per-principal keys (`sk-ac-*`).
670
+ *
671
+ * New developer integrations should use `client.developer`, which creates
672
+ * project-scoped `csk_*` keys with explicit environments and scopes.
673
+ */
274
674
  get apiKeys() {
275
675
  return {
276
676
  /**
@@ -280,7 +680,10 @@ var CommonsClient = class {
280
680
  create: (params) => this.request("POST", "/v1/auth/api-keys", params),
281
681
  /** List all active API keys for a principal (key values not included). */
282
682
  list: (principalId, principalType) => {
283
- const q = new URLSearchParams({ principalId, principalType }).toString();
683
+ const q = new URLSearchParams({
684
+ principalId,
685
+ principalType
686
+ }).toString();
284
687
  return this.request("GET", `/v1/auth/api-keys?${q}`);
285
688
  },
286
689
  /** Revoke (soft-delete) an API key by its UUID. */
@@ -363,7 +766,10 @@ var CommonsClient = class {
363
766
  params: { id: taskId }
364
767
  }).then((r) => r.result),
365
768
  /** List recent A2A tasks for an agent. */
366
- listTasks: (agentId, limit) => this.request("GET", `/v1/a2a/${agentId}/tasks${limit ? `?limit=${limit}` : ""}`),
769
+ listTasks: (agentId, limit) => this.request(
770
+ "GET",
771
+ `/v1/a2a/${agentId}/tasks${limit ? `?limit=${limit}` : ""}`
772
+ ),
367
773
  /** Stream A2A task updates (SSE). */
368
774
  stream: (agentId, taskId) => this._streamSse(`/v1/a2a/${agentId}/tasks/${taskId}/stream`)
369
775
  };
@@ -372,11 +778,18 @@ var CommonsClient = class {
372
778
  get mcp() {
373
779
  return {
374
780
  /** List MCP servers for an owner. */
375
- listServers: (ownerId, ownerType) => this.request("GET", `/v1/mcp/servers?ownerId=${ownerId}&ownerType=${ownerType}`),
781
+ listServers: (ownerId, ownerType) => this.request(
782
+ "GET",
783
+ `/v1/mcp/servers?ownerId=${ownerId}&ownerType=${ownerType}`
784
+ ),
376
785
  /** Create a new MCP server. */
377
786
  createServer: (params) => {
378
787
  const { ownerId, ownerType, ...dto } = params;
379
- return this.request("POST", `/v1/mcp/servers?ownerId=${ownerId}&ownerType=${ownerType}`, dto);
788
+ return this.request(
789
+ "POST",
790
+ `/v1/mcp/servers?ownerId=${ownerId}&ownerType=${ownerType}`,
791
+ dto
792
+ );
380
793
  },
381
794
  /** Get MCP server by ID. */
382
795
  getServer: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}`),
@@ -397,15 +810,25 @@ var CommonsClient = class {
397
810
  /** List tools discovered from an MCP server. */
398
811
  listTools: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}/tools`),
399
812
  /** 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}`),
813
+ listToolsByOwner: (ownerId, ownerType) => this.request(
814
+ "GET",
815
+ `/v1/mcp/tools?ownerId=${ownerId}&ownerType=${ownerType}`
816
+ ),
401
817
  /** List resources from an MCP server. */
402
818
  listResources: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}/resources`),
403
819
  /** Read a resource by URI. */
404
- readResource: (serverId, uri) => this.request("GET", `/v1/mcp/servers/${serverId}/resources/read?uri=${encodeURIComponent(uri)}`),
820
+ readResource: (serverId, uri) => this.request(
821
+ "GET",
822
+ `/v1/mcp/servers/${serverId}/resources/read?uri=${encodeURIComponent(uri)}`
823
+ ),
405
824
  /** List prompts from an MCP server. */
406
825
  listPrompts: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}/prompts`),
407
826
  /** Render a prompt with arguments. */
408
- getPrompt: (serverId, promptName, args) => this.request("POST", `/v1/mcp/servers/${serverId}/prompts/${promptName}`, { arguments: args })
827
+ getPrompt: (serverId, promptName, args) => this.request(
828
+ "POST",
829
+ `/v1/mcp/servers/${serverId}/prompts/${promptName}`,
830
+ { arguments: args }
831
+ )
409
832
  };
410
833
  }
411
834
  // ── Memory ────────────────────────────────────────────────────────────────
@@ -417,7 +840,10 @@ var CommonsClient = class {
417
840
  if (opts?.type) params.set("type", opts.type);
418
841
  if (opts?.limit) params.set("limit", String(opts.limit));
419
842
  const qs = params.toString();
420
- return this.request("GET", `/v1/memory/agents/${agentId}${qs ? `?${qs}` : ""}`);
843
+ return this.request(
844
+ "GET",
845
+ `/v1/memory/agents/${agentId}${qs ? `?${qs}` : ""}`
846
+ );
421
847
  },
422
848
  /** Get memory stats for an agent. */
423
849
  stats: (agentId) => this.request("GET", `/v1/memory/agents/${agentId}/stats`),
@@ -425,7 +851,10 @@ var CommonsClient = class {
425
851
  retrieve: (agentId, query, limit) => {
426
852
  const params = new URLSearchParams({ q: query });
427
853
  if (limit) params.set("limit", String(limit));
428
- return this.request("GET", `/v1/memory/agents/${agentId}/retrieve?${params}`);
854
+ return this.request(
855
+ "GET",
856
+ `/v1/memory/agents/${agentId}/retrieve?${params}`
857
+ );
429
858
  },
430
859
  /** Get a single memory by ID. */
431
860
  get: (memoryId) => this.request("GET", `/v1/memory/${memoryId}`),
@@ -434,7 +863,11 @@ var CommonsClient = class {
434
863
  /** Update a memory. */
435
864
  update: (memoryId, params) => this.request("PATCH", `/v1/memory/${memoryId}`, params),
436
865
  /** Soft-delete (deactivate) a memory. */
437
- delete: (memoryId) => this.request("DELETE", `/v1/memory/${memoryId}`)
866
+ delete: (memoryId) => this.request("DELETE", `/v1/memory/${memoryId}`),
867
+ /** Create an append-only memory scope shared by a set of owned agents. */
868
+ createSharedScope: (params) => this.request("POST", "/v1/memory/shared-scopes", params),
869
+ /** List shared-memory scopes available to an agent. */
870
+ listSharedScopes: (agentId) => this.request("GET", `/v1/memory/shared-scopes/agents/${agentId}`)
438
871
  };
439
872
  }
440
873
  // ── Usage / Observability ─────────────────────────────────────────────────
@@ -446,12 +879,340 @@ var CommonsClient = class {
446
879
  if (opts?.from) params.set("from", opts.from);
447
880
  if (opts?.to) params.set("to", opts.to);
448
881
  const qs = params.toString();
449
- return this.request("GET", `/v1/usage/agents/${agentId}${qs ? `?${qs}` : ""}`);
882
+ return this.request(
883
+ "GET",
884
+ `/v1/usage/agents/${agentId}${qs ? `?${qs}` : ""}`
885
+ );
450
886
  },
451
887
  /** Get aggregated token + cost usage for a session. */
452
888
  getSessionUsage: (sessionId) => this.request("GET", `/v1/usage/sessions/${sessionId}`)
453
889
  };
454
890
  }
891
+ // ── Activity and logs ────────────────────────────────────────────────────
892
+ get activity() {
893
+ return {
894
+ list: (filter) => {
895
+ const query = new URLSearchParams();
896
+ if (filter?.actorId) query.set("actorId", filter.actorId);
897
+ if (filter?.eventType) query.set("eventType", filter.eventType);
898
+ if (filter?.since) query.set("since", filter.since);
899
+ if (filter?.limit) query.set("limit", String(filter.limit));
900
+ return this.request(
901
+ "GET",
902
+ `/v1/activity/events${query.size ? `?${query}` : ""}`
903
+ );
904
+ }
905
+ };
906
+ }
907
+ get logs() {
908
+ return {
909
+ list: (agentId, filter) => {
910
+ const query = new URLSearchParams();
911
+ if (filter?.sessionId) query.set("sessionId", filter.sessionId);
912
+ if (filter?.limit) query.set("limit", String(filter.limit));
913
+ return this.request(
914
+ "GET",
915
+ `/v1/logs/agents/${encodeURIComponent(agentId)}${query.size ? `?${query}` : ""}`
916
+ );
917
+ },
918
+ observability: (agentId, filter) => {
919
+ const query = new URLSearchParams();
920
+ if (filter?.from) query.set("from", filter.from);
921
+ if (filter?.to) query.set("to", filter.to);
922
+ if (filter?.limit) query.set("limit", String(filter.limit));
923
+ return this.request(
924
+ "GET",
925
+ `/v1/logs/agents/${encodeURIComponent(agentId)}/observability${query.size ? `?${query}` : ""}`
926
+ );
927
+ }
928
+ };
929
+ }
930
+ // ── Files and library ────────────────────────────────────────────────────
931
+ get files() {
932
+ return {
933
+ upload: (files, params) => {
934
+ const body = new FormData();
935
+ for (const file of files) {
936
+ body.append("files", file.data, file.name);
937
+ }
938
+ if (params?.agentId) body.set("agentId", params.agentId);
939
+ if (params?.sessionId) body.set("sessionId", params.sessionId);
940
+ if (params?.workspaceId) body.set("workspaceId", params.workspaceId);
941
+ if (params?.storageProvider)
942
+ body.set("storageProvider", params.storageProvider);
943
+ return this.request("POST", "/v1/files/upload", body);
944
+ },
945
+ get: (fileId, context) => {
946
+ const query = new URLSearchParams();
947
+ if (context?.agentId) query.set("agentId", context.agentId);
948
+ if (context?.sessionId) query.set("sessionId", context.sessionId);
949
+ return this.request(
950
+ "GET",
951
+ `/v1/files/${encodeURIComponent(fileId)}${query.size ? `?${query}` : ""}`
952
+ );
953
+ },
954
+ content: (fileId, options) => {
955
+ const query = new URLSearchParams();
956
+ if (options?.agentId) query.set("agentId", options.agentId);
957
+ if (options?.sessionId) query.set("sessionId", options.sessionId);
958
+ if (options?.offset !== void 0)
959
+ query.set("offset", String(options.offset));
960
+ if (options?.maxChars !== void 0)
961
+ query.set("maxChars", String(options.maxChars));
962
+ if (options?.includeImageUrls !== void 0)
963
+ query.set("includeImageUrls", String(options.includeImageUrls));
964
+ if (options?.includeDownloadUrl !== void 0)
965
+ query.set("includeDownloadUrl", String(options.includeDownloadUrl));
966
+ return this.request(
967
+ "GET",
968
+ `/v1/files/${encodeURIComponent(fileId)}/content${query.size ? `?${query}` : ""}`
969
+ );
970
+ }
971
+ };
972
+ }
973
+ get library() {
974
+ return {
975
+ list: (filter) => {
976
+ const query = new URLSearchParams();
977
+ if (filter?.query) query.set("query", filter.query);
978
+ if (filter?.view) query.set("view", filter.view);
979
+ if (filter?.source) query.set("source", filter.source);
980
+ if (filter?.favorite !== void 0)
981
+ query.set("favorite", String(filter.favorite));
982
+ if (filter?.sessionId) query.set("sessionId", filter.sessionId);
983
+ if (filter?.limit !== void 0)
984
+ query.set("limit", String(filter.limit));
985
+ if (filter?.offset !== void 0)
986
+ query.set("offset", String(filter.offset));
987
+ return this.request(
988
+ "GET",
989
+ `/v1/library${query.size ? `?${query}` : ""}`
990
+ );
991
+ },
992
+ get: (itemId) => this.request(
993
+ "GET",
994
+ `/v1/library/${encodeURIComponent(itemId)}`
995
+ ),
996
+ download: (itemId) => this.request(
997
+ "GET",
998
+ `/v1/library/${encodeURIComponent(itemId)}/download`
999
+ ),
1000
+ preview: (itemId) => this.request(
1001
+ "GET",
1002
+ `/v1/library/${encodeURIComponent(itemId)}/preview`
1003
+ ),
1004
+ update: (itemId, params) => this.request(
1005
+ "PATCH",
1006
+ `/v1/library/${encodeURIComponent(itemId)}`,
1007
+ params
1008
+ ),
1009
+ delete: (itemId) => this.request(
1010
+ "DELETE",
1011
+ `/v1/library/${encodeURIComponent(itemId)}`
1012
+ ),
1013
+ storagePreference: () => this.request("GET", "/v1/library/preferences/storage"),
1014
+ setStoragePreference: (defaultStorageProvider) => this.request("PATCH", "/v1/library/preferences/storage", {
1015
+ defaultStorageProvider
1016
+ }),
1017
+ grant: (itemId, params) => this.request(
1018
+ "POST",
1019
+ `/v1/library/${encodeURIComponent(itemId)}/grants`,
1020
+ params
1021
+ ),
1022
+ revokeGrant: (itemId, grantId) => this.request(
1023
+ "DELETE",
1024
+ `/v1/library/${encodeURIComponent(itemId)}/grants/${encodeURIComponent(grantId)}`
1025
+ ),
1026
+ createShareLink: (itemId, expiresAt) => this.request(
1027
+ "POST",
1028
+ `/v1/library/${encodeURIComponent(itemId)}/share-links`,
1029
+ { expiresAt }
1030
+ ),
1031
+ revokeShareLink: (itemId, shareId) => this.request(
1032
+ "DELETE",
1033
+ `/v1/library/${encodeURIComponent(itemId)}/share-links/${encodeURIComponent(shareId)}`
1034
+ ),
1035
+ resolveShare: (token) => this.request(
1036
+ "GET",
1037
+ `/v1/shared/artifacts/${encodeURIComponent(token)}`
1038
+ )
1039
+ };
1040
+ }
1041
+ // ── Spaces, projects, and goals ──────────────────────────────────────────
1042
+ get spaces() {
1043
+ return {
1044
+ list: (filter) => {
1045
+ const query = new URLSearchParams();
1046
+ if (filter?.memberId) query.set("memberId", filter.memberId);
1047
+ if (filter?.memberType) query.set("memberType", filter.memberType);
1048
+ if (filter?.agentIds?.length)
1049
+ query.set("agentIds", filter.agentIds.join(","));
1050
+ if (filter?.publicOnly !== void 0)
1051
+ query.set("publicOnly", String(filter.publicOnly));
1052
+ if (filter?.search) query.set("search", filter.search);
1053
+ if (filter?.includeMembers !== void 0)
1054
+ query.set("includeMembers", String(filter.includeMembers));
1055
+ if (filter?.limit !== void 0)
1056
+ query.set("limit", String(filter.limit));
1057
+ if (filter?.offset !== void 0)
1058
+ query.set("offset", String(filter.offset));
1059
+ return this.request(
1060
+ "GET",
1061
+ `/v1/spaces${query.size ? `?${query}` : ""}`
1062
+ );
1063
+ },
1064
+ create: (params, creator) => this.request("POST", "/v1/spaces", params, {
1065
+ headers: {
1066
+ "x-creator-id": creator.id,
1067
+ "x-creator-type": creator.type
1068
+ }
1069
+ }),
1070
+ get: (spaceId) => this.request(
1071
+ "GET",
1072
+ `/v1/spaces/${encodeURIComponent(spaceId)}`
1073
+ ),
1074
+ getFull: (spaceId) => this.request(
1075
+ "GET",
1076
+ `/v1/spaces/${encodeURIComponent(spaceId)}/full`
1077
+ ),
1078
+ update: (spaceId, params) => this.request(
1079
+ "PUT",
1080
+ `/v1/spaces/${encodeURIComponent(spaceId)}`,
1081
+ params
1082
+ ),
1083
+ delete: (spaceId) => this.request(
1084
+ "DELETE",
1085
+ `/v1/spaces/${encodeURIComponent(spaceId)}`
1086
+ ),
1087
+ issueRtcTicket: (spaceId) => this.request(
1088
+ "POST",
1089
+ `/v1/spaces/${encodeURIComponent(spaceId)}/rtc-ticket`,
1090
+ {}
1091
+ ),
1092
+ listMembers: (spaceId) => this.request(
1093
+ "GET",
1094
+ `/v1/spaces/${encodeURIComponent(spaceId)}/members`
1095
+ ),
1096
+ addMember: (spaceId, params) => this.request(
1097
+ "POST",
1098
+ `/v1/spaces/${encodeURIComponent(spaceId)}/members`,
1099
+ params
1100
+ ),
1101
+ updateMember: (spaceId, memberId, memberType, params) => this.request(
1102
+ "PUT",
1103
+ `/v1/spaces/${encodeURIComponent(spaceId)}/members/${encodeURIComponent(memberId)}?memberType=${memberType}`,
1104
+ params
1105
+ ),
1106
+ removeMember: (spaceId, memberId, memberType) => this.request(
1107
+ "DELETE",
1108
+ `/v1/spaces/${encodeURIComponent(spaceId)}/members/${encodeURIComponent(memberId)}?memberType=${memberType}`
1109
+ ),
1110
+ listMessages: (spaceId, filter) => {
1111
+ const query = new URLSearchParams();
1112
+ if (filter?.limit !== void 0)
1113
+ query.set("limit", String(filter.limit));
1114
+ if (filter?.offset !== void 0)
1115
+ query.set("offset", String(filter.offset));
1116
+ if (filter?.memberId) query.set("memberId", filter.memberId);
1117
+ return this.request(
1118
+ "GET",
1119
+ `/v1/spaces/${encodeURIComponent(spaceId)}/messages${query.size ? `?${query}` : ""}`
1120
+ );
1121
+ },
1122
+ sendMessage: (spaceId, params, sender) => this.request(
1123
+ "POST",
1124
+ `/v1/spaces/${encodeURIComponent(spaceId)}/messages`,
1125
+ params,
1126
+ {
1127
+ headers: {
1128
+ "x-sender-id": sender.id,
1129
+ "x-sender-type": sender.type
1130
+ }
1131
+ }
1132
+ ),
1133
+ updateMessage: (spaceId, messageId, params) => this.request(
1134
+ "PUT",
1135
+ `/v1/spaces/${encodeURIComponent(spaceId)}/messages/${encodeURIComponent(messageId)}`,
1136
+ params
1137
+ ),
1138
+ deleteMessage: (spaceId, messageId) => this.request(
1139
+ "DELETE",
1140
+ `/v1/spaces/${encodeURIComponent(spaceId)}/messages/${encodeURIComponent(messageId)}`
1141
+ )
1142
+ };
1143
+ }
1144
+ get projects() {
1145
+ const base = (agentId) => `/v1/agents/${encodeURIComponent(agentId)}/projects`;
1146
+ return {
1147
+ list: (agentId) => this.request("GET", base(agentId)),
1148
+ create: (agentId, params) => this.request("POST", base(agentId), params),
1149
+ get: (agentId, projectId) => this.request(
1150
+ "GET",
1151
+ `${base(agentId)}/${encodeURIComponent(projectId)}`
1152
+ ),
1153
+ writeFiles: (agentId, projectId, files, replace = false) => this.request(
1154
+ "PUT",
1155
+ `${base(agentId)}/${encodeURIComponent(projectId)}/files`,
1156
+ { files, replace }
1157
+ ),
1158
+ publish: (agentId, projectId) => this.request(
1159
+ "POST",
1160
+ `${base(agentId)}/${encodeURIComponent(projectId)}/publish`,
1161
+ {}
1162
+ ),
1163
+ verify: (agentId, projectId, actions) => this.request(
1164
+ "POST",
1165
+ `${base(agentId)}/${encodeURIComponent(projectId)}/verify`,
1166
+ { actions }
1167
+ ),
1168
+ exportToComputer: (agentId, projectId, params) => this.request(
1169
+ "POST",
1170
+ `${base(agentId)}/${encodeURIComponent(projectId)}/export`,
1171
+ params ?? {}
1172
+ ),
1173
+ exportToGitHub: (agentId, projectId, params) => this.request(
1174
+ "POST",
1175
+ `${base(agentId)}/${encodeURIComponent(projectId)}/github`,
1176
+ params ?? {}
1177
+ )
1178
+ };
1179
+ }
1180
+ get goals() {
1181
+ return {
1182
+ create: (params) => this.request("POST", "/v1/goals", params),
1183
+ get: (goalId) => this.request("GET", `/v1/goals/${encodeURIComponent(goalId)}`),
1184
+ updateProgress: (goalId, progress, status) => this.request(
1185
+ "PUT",
1186
+ `/v1/goals/${encodeURIComponent(goalId)}`,
1187
+ { progress, status }
1188
+ )
1189
+ };
1190
+ }
1191
+ // ── Audio and liaison agents ─────────────────────────────────────────────
1192
+ get audio() {
1193
+ return {
1194
+ transcribe: (file, options) => {
1195
+ const body = new FormData();
1196
+ body.append("file", file.data, file.name);
1197
+ if (options?.durationMs !== void 0)
1198
+ body.set("durationMs", String(options.durationMs));
1199
+ return this.request("POST", "/v1/audio/transcriptions", body, {
1200
+ headers: options?.idempotencyKey ? { "x-idempotency-key": options.idempotencyKey } : void 0
1201
+ });
1202
+ }
1203
+ };
1204
+ }
1205
+ get liaisons() {
1206
+ return {
1207
+ create: (params) => this.request("POST", "/v1/liaison", params),
1208
+ interact: (liaisonAgentId, liaisonKey, message) => this.request(
1209
+ "POST",
1210
+ "/v1/liaison/interact",
1211
+ { liaisonAgentId, message },
1212
+ { headers: { "x-api-key": liaisonKey } }
1213
+ )
1214
+ };
1215
+ }
455
1216
  // ── Credits ──────────────────────────────────────────────────────────────
456
1217
  get credits() {
457
1218
  return {
@@ -470,10 +1231,45 @@ var CommonsClient = class {
470
1231
  const qs = params.toString();
471
1232
  return this.request("GET", `/v1/credits/ledger${qs ? `?${qs}` : ""}`);
472
1233
  },
1234
+ summary: () => this.request("GET", "/v1/credits/summary"),
1235
+ campaigns: () => this.request("GET", "/v1/credits/campaigns"),
1236
+ claimCampaign: (params) => this.request("POST", "/v1/credits/campaigns/claim", params),
1237
+ transfers: () => this.request("GET", "/v1/credits/transfers"),
1238
+ gift: (params) => this.request("POST", "/v1/credits/gifts", params),
473
1239
  grant: (params) => this.request("POST", "/v1/credits/grants", params),
474
1240
  debit: (params) => this.request("POST", "/v1/credits/debits", params)
475
1241
  };
476
1242
  }
1243
+ // ── Billing ────────────────────────────────────────────────────────────────
1244
+ get billing() {
1245
+ return {
1246
+ /** Public product catalog served from the backend source of truth. */
1247
+ catalog: () => this.request("GET", "/v1/billing/catalog"),
1248
+ /** Current plan, status, and entitlements for the caller. */
1249
+ subscription: () => this.request("GET", "/v1/billing/subscription"),
1250
+ /** Entitlements only (what paid features the caller may use). */
1251
+ entitlements: () => this.request("GET", "/v1/billing/entitlements"),
1252
+ /** Stripe invoice history for the caller. */
1253
+ invoices: () => this.request("GET", "/v1/billing/invoices"),
1254
+ /** Saved Stripe payment methods for the caller. */
1255
+ paymentMethods: () => this.request("GET", "/v1/billing/payment-methods"),
1256
+ /** Create a Stripe Checkout session for a subscription plan. */
1257
+ subscribe: (planKey) => this.request("POST", "/v1/billing/checkout/subscription", { planKey }),
1258
+ /** Create a Stripe Checkout session for a one-time credit top-up. */
1259
+ topup: (packKey) => this.request("POST", "/v1/billing/checkout/topup", { packKey }),
1260
+ /** Open the Stripe billing portal. */
1261
+ portal: () => this.request("POST", "/v1/billing/portal", {})
1262
+ };
1263
+ }
1264
+ // ── Feature flags ────────────────────────────────────────────────────────
1265
+ get flags() {
1266
+ return {
1267
+ /** Evaluate all active flags for the caller (call once at boot). */
1268
+ all: () => this.request("GET", "/v1/flags"),
1269
+ /** Evaluate a single flag for the caller. */
1270
+ evaluate: (key) => this.request("GET", `/v1/flags/${encodeURIComponent(key)}`)
1271
+ };
1272
+ }
477
1273
  };
478
1274
  var CommonsError = class extends Error {
479
1275
  constructor(message, status, data) {