@agent-commons/sdk 0.4.0 → 0.6.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.cjs CHANGED
@@ -34,29 +34,91 @@ var CommonsClient = class {
34
34
  /\/$/,
35
35
  ""
36
36
  );
37
+ this.identityUrl = (config.identityUrl ?? "https://auth.agentcommons.io").replace(/\/api\/auth\/?$/, "").replace(/\/$/, "");
38
+ this.identityToken = config.identityToken;
37
39
  this.apiKey = config.apiKey;
38
40
  this.initiator = config.initiator;
39
41
  this._fetch = config.fetch ?? fetch;
40
42
  }
41
43
  // ── Helpers ───────────────────────────────────────────────────────────────
42
- headers(extra) {
43
- const h = { "Content-Type": "application/json" };
44
+ headers(extra, json = true) {
45
+ const h = {};
46
+ if (json) h["Content-Type"] = "application/json";
44
47
  if (this.apiKey) h["Authorization"] = `Bearer ${this.apiKey}`;
45
48
  if (this.initiator) h["x-initiator"] = this.initiator;
46
49
  return { ...h, ...extra };
47
50
  }
48
- async request(method, path, body) {
51
+ /**
52
+ * Call an API route that is not yet represented by a resource namespace.
53
+ * Most applications should use the typed helpers below.
54
+ */
55
+ async request(method, path, body, options = {}) {
56
+ const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
49
57
  const res = await this._fetch(`${this.baseUrl}${path}`, {
50
58
  method,
51
- headers: this.headers(),
52
- body: body !== void 0 ? JSON.stringify(body) : void 0
59
+ headers: this.headers(options.headers, !isFormData),
60
+ body: body === void 0 ? void 0 : isFormData ? body : JSON.stringify(body),
61
+ signal: options.signal
53
62
  });
54
63
  if (!res.ok) {
55
- const err = await res.json().catch(() => ({ message: res.statusText }));
56
- throw new CommonsError(err.message ?? res.statusText, res.status, err);
64
+ const err = await this.errorPayload(res);
65
+ throw new CommonsError(
66
+ this.errorMessage(err, res.statusText),
67
+ res.status,
68
+ err
69
+ );
70
+ }
71
+ if (res.status === 204) return void 0;
72
+ const contentType = res.headers.get("content-type") ?? "";
73
+ if (!contentType.includes("json")) {
74
+ return await res.text();
57
75
  }
58
76
  return res.json();
59
77
  }
78
+ async errorPayload(res) {
79
+ const contentType = res.headers.get("content-type") ?? "";
80
+ if (contentType.includes("json")) {
81
+ return res.json().catch(() => ({ message: res.statusText }));
82
+ }
83
+ const message = await res.text().catch(() => "");
84
+ return { message: message || res.statusText };
85
+ }
86
+ errorMessage(error, fallback) {
87
+ if (!error || typeof error !== "object") return fallback;
88
+ if ("message" in error && typeof error.message === "string") {
89
+ return error.message;
90
+ }
91
+ if ("error" in error) {
92
+ if (typeof error.error === "string") return error.error;
93
+ if (error.error && typeof error.error === "object" && "message" in error.error && typeof error.error.message === "string") {
94
+ return error.error.message;
95
+ }
96
+ }
97
+ return fallback;
98
+ }
99
+ async identityRequest(method, path, body) {
100
+ const headers = {};
101
+ if (body !== void 0) headers["Content-Type"] = "application/json";
102
+ if (this.identityToken) {
103
+ headers.Authorization = `Bearer ${this.identityToken}`;
104
+ }
105
+ const response = await this._fetch(`${this.identityUrl}${path}`, {
106
+ method,
107
+ headers,
108
+ credentials: "include",
109
+ body: body === void 0 ? void 0 : JSON.stringify(body)
110
+ });
111
+ if (!response.ok) {
112
+ const error = await this.errorPayload(response);
113
+ throw new CommonsError(
114
+ this.errorMessage(error, response.statusText),
115
+ response.status,
116
+ error
117
+ );
118
+ }
119
+ if (response.status === 204) return void 0;
120
+ return response.json();
121
+ }
60
122
  // ── Models ────────────────────────────────────────────────────────────────
61
123
  get models() {
62
124
  return {
@@ -71,17 +133,40 @@ var CommonsClient = class {
71
133
  list: (owner) => this.request("GET", `/v1/agents${owner ? `?owner=${owner}` : ""}`),
72
134
  get: (agentId) => this.request("GET", `/v1/agents/${agentId}`),
73
135
  update: (agentId, params) => this.request("PUT", `/v1/agents/${agentId}`, params),
136
+ /**
137
+ * Generate durable image assets for this agent without routing a
138
+ * deterministic image operation through an LLM tool-selection turn.
139
+ */
140
+ generateImage: (agentId, params) => this.request(
141
+ "POST",
142
+ `/v1/agents/${encodeURIComponent(agentId)}/assets/images`,
143
+ params
144
+ ),
74
145
  getRuntime: (agentId) => this.request("GET", `/v1/agents/${agentId}/runtime`),
75
146
  configureRuntime: (agentId, params) => this.request("PUT", `/v1/agents/${agentId}/runtime`, params),
76
147
  deployRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/deploy`),
77
148
  sleepRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/sleep`),
78
149
  restartRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/restart`),
150
+ manageRuntimeChannel: (agentId, channel, action, params = {}) => this.request(
151
+ "POST",
152
+ `/v1/agents/${encodeURIComponent(agentId)}/runtime/channels/${encodeURIComponent(channel)}/${encodeURIComponent(action)}`,
153
+ params
154
+ ),
79
155
  /** List tools assigned to an agent. */
80
156
  listTools: (agentId) => this.request("GET", `/v1/agents/${agentId}/tools`),
81
157
  /** Assign a tool to an agent. */
82
158
  addTool: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/tools`, params),
159
+ /** Update an agent tool assignment. */
160
+ updateTool: (assignmentId, params) => this.request(
161
+ "PATCH",
162
+ `/v1/agents/tools/${encodeURIComponent(assignmentId)}`,
163
+ params
164
+ ),
83
165
  /** Remove a tool assignment from an agent. */
84
- removeTool: (assignmentId) => this.request("DELETE", `/v1/agents/tools/${assignmentId}`),
166
+ removeTool: (assignmentId) => this.request(
167
+ "DELETE",
168
+ `/v1/agents/tools/${encodeURIComponent(assignmentId)}`
169
+ ),
85
170
  /** Create a liaison agent for an external agent. */
86
171
  createLiaison: (params) => this.request("POST", "/v1/liaison", params),
87
172
  /**
@@ -94,6 +179,11 @@ var CommonsClient = class {
94
179
  * }
95
180
  */
96
181
  stream: (params) => this._streamAgentRun(params),
182
+ /** Resume a streamed run after executing a caller-owned CLI tool. */
183
+ submitCliToolResult: (requestId, result) => this.request("POST", "/v1/agents/cli-tool-result", {
184
+ requestId,
185
+ result
186
+ }),
97
187
  // ── Heartbeat ─────────────────────────────────────────────────────────
98
188
  /** Get the current heartbeat status for an agent. */
99
189
  getAutonomy: (agentId) => this.request("GET", `/v1/agents/${agentId}/autonomy`),
@@ -144,6 +234,11 @@ var CommonsClient = class {
144
234
  `/v1/agents/${agentId}/computer/files/read?path=${encodeURIComponent(path)}`
145
235
  );
146
236
  },
237
+ writeComputerFile: (agentId, params) => this.request(
238
+ "POST",
239
+ `/v1/agents/${encodeURIComponent(agentId)}/computer/files/write`,
240
+ params
241
+ ),
147
242
  openComputerBrowser: (agentId, paramsOrLegacyComputerId, legacyParams) => {
148
243
  const params = typeof paramsOrLegacyComputerId === "string" ? legacyParams : paramsOrLegacyComputerId;
149
244
  if (!params) {
@@ -155,6 +250,11 @@ var CommonsClient = class {
155
250
  params
156
251
  );
157
252
  },
253
+ testComputerBrowser: (agentId) => this.request(
254
+ "POST",
255
+ `/v1/agents/${encodeURIComponent(agentId)}/computer/browser/test`,
256
+ {}
257
+ ),
158
258
  listComputerEvents: (agentId, limitOrLegacyComputerId, legacyLimit) => {
159
259
  const limit = typeof limitOrLegacyComputerId === "number" ? limitOrLegacyComputerId : legacyLimit;
160
260
  return this.request(
@@ -212,6 +312,26 @@ var CommonsClient = class {
212
312
  }
213
313
  };
214
314
  }
315
+ get copilot() {
316
+ return {
317
+ get: () => this.request("GET", "/v1/copilot"),
318
+ updateSettings: (params) => this.request("PUT", "/v1/copilot/settings", params),
319
+ listChanges: (filter) => {
320
+ const query = new URLSearchParams();
321
+ if (filter?.status) query.set("status", filter.status);
322
+ if (filter?.resourceType)
323
+ query.set("resourceType", filter.resourceType);
324
+ if (filter?.resourceId) query.set("resourceId", filter.resourceId);
325
+ return this.request(
326
+ "GET",
327
+ `/v1/copilot/changes${query.size ? `?${query}` : ""}`
328
+ );
329
+ },
330
+ acceptChange: (changeId) => this.request("POST", `/v1/copilot/changes/${changeId}/accept`),
331
+ rejectChange: (changeId) => this.request("POST", `/v1/copilot/changes/${changeId}/reject`),
332
+ revertChange: (changeId) => this.request("POST", `/v1/copilot/changes/${changeId}/revert`)
333
+ };
334
+ }
215
335
  // ── Run (non-streaming) ───────────────────────────────────────────────────
216
336
  get run() {
217
337
  return {
@@ -226,9 +346,45 @@ var CommonsClient = class {
226
346
  "GET",
227
347
  `/v1/workflows?ownerId=${ownerId}&ownerType=${ownerType}`
228
348
  ),
349
+ discoverPublic: (filter) => {
350
+ const query = new URLSearchParams();
351
+ if (filter?.category) query.set("category", filter.category);
352
+ if (filter?.tags?.length) query.set("tags", filter.tags.join(","));
353
+ if (filter?.limit) query.set("limit", String(filter.limit));
354
+ return this.request(
355
+ "GET",
356
+ `/v1/workflows/public${query.size ? `?${query}` : ""}`
357
+ );
358
+ },
229
359
  get: (workflowId) => this.request("GET", `/v1/workflows/${workflowId}`),
230
360
  update: (workflowId, updates) => this.request("PUT", `/v1/workflows/${workflowId}`, updates),
231
361
  delete: (workflowId) => this.request("DELETE", `/v1/workflows/${workflowId}`),
362
+ fork: (workflowId, params) => this.request(
363
+ "POST",
364
+ `/v1/workflows/${encodeURIComponent(workflowId)}/fork`,
365
+ params
366
+ ),
367
+ getWebhook: (workflowId) => this.request(
368
+ "GET",
369
+ `/v1/workflows/${encodeURIComponent(workflowId)}/webhook`
370
+ ),
371
+ rotateWebhookToken: (workflowId) => this.request(
372
+ "POST",
373
+ `/v1/workflows/${encodeURIComponent(workflowId)}/webhook-token`,
374
+ {}
375
+ ),
376
+ disableWebhook: (workflowId) => this.request(
377
+ "DELETE",
378
+ `/v1/workflows/${encodeURIComponent(workflowId)}/webhook-token`
379
+ ),
380
+ executeWebhook: (token, payload, query) => {
381
+ const search = query ? new URLSearchParams(query).toString() : "";
382
+ return this.request(
383
+ "POST",
384
+ `/v1/workflows/webhooks/${encodeURIComponent(token)}${search ? `?${search}` : ""}`,
385
+ payload
386
+ );
387
+ },
232
388
  execute: (workflowId, params) => this.request("POST", `/v1/workflows/${workflowId}/execute`, params),
233
389
  getExecution: (workflowId, executionId) => this.request(
234
390
  "GET",
@@ -294,7 +450,23 @@ var CommonsClient = class {
294
450
  create: (params) => this.request("POST", "/v1/sessions", params),
295
451
  get: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}`),
296
452
  /** Get full session with history, tasks, childSessions, and spaces. */
297
- getFull: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}/full`)
453
+ getFull: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}/full`),
454
+ /** Rename a session. */
455
+ rename: (sessionId, title) => this.request(
456
+ "PATCH",
457
+ `/v1/sessions/${encodeURIComponent(sessionId)}`,
458
+ { title }
459
+ ),
460
+ /** Delete a session and its owned session data. */
461
+ delete: (sessionId) => this.request(
462
+ "DELETE",
463
+ `/v1/sessions/${encodeURIComponent(sessionId)}`
464
+ ),
465
+ /** Get the full chat transcript for a session. */
466
+ getChat: (sessionId) => this.request(
467
+ "GET",
468
+ `/v1/agents/sessions/${encodeURIComponent(sessionId)}/chat`
469
+ )
298
470
  };
299
471
  }
300
472
  // ── Tools ─────────────────────────────────────────────────────────────────
@@ -330,39 +502,123 @@ var CommonsClient = class {
330
502
  const q = params ? new URLSearchParams(params).toString() : "";
331
503
  return this.request("GET", `/v1/oauth/connections${q ? `?${q}` : ""}`);
332
504
  },
505
+ /** Get one OAuth connection. */
506
+ getConnection: (connectionId) => this.request(
507
+ "GET",
508
+ `/v1/oauth/connections/${encodeURIComponent(connectionId)}`
509
+ ),
510
+ /** Update connection metadata or its active status. */
511
+ updateConnection: (connectionId, params) => this.request(
512
+ "PUT",
513
+ `/v1/oauth/connections/${encodeURIComponent(connectionId)}`,
514
+ params
515
+ ),
333
516
  /**
334
517
  * Start an OAuth connect flow. Returns the authorization URL the user
335
518
  * must open in a browser to grant access.
336
519
  */
337
520
  connect: (params) => this.request("POST", "/v1/oauth/connect", params),
338
521
  /** Refresh a connection's access token now. */
339
- refresh: (connectionId) => this.request("POST", `/v1/oauth/connections/${connectionId}/refresh`),
522
+ refresh: (connectionId) => this.request(
523
+ "POST",
524
+ `/v1/oauth/connections/${encodeURIComponent(connectionId)}/refresh`
525
+ ),
340
526
  /** Check whether a connection's token is valid. */
341
- test: (connectionId) => this.request("GET", `/v1/oauth/connections/${connectionId}/test`),
527
+ test: (connectionId) => this.request(
528
+ "GET",
529
+ `/v1/oauth/connections/${encodeURIComponent(connectionId)}/test`
530
+ ),
342
531
  /** Revoke a connection and delete its tokens. */
343
- revoke: (connectionId) => this.request("DELETE", `/v1/oauth/connections/${connectionId}`)
532
+ revoke: (connectionId) => this.request(
533
+ "DELETE",
534
+ `/v1/oauth/connections/${encodeURIComponent(connectionId)}`
535
+ )
344
536
  };
345
537
  }
346
538
  // ── Tool Keys ─────────────────────────────────────────────────────────────
347
539
  get toolKeys() {
348
540
  return {
349
- list: (filter) => {
350
- const q = new URLSearchParams(filter).toString();
351
- return this.request("GET", `/v1/tool-keys${q ? `?${q}` : ""}`);
352
- },
541
+ list: () => this.request("GET", "/v1/tool-keys"),
353
542
  create: (params) => this.request("POST", "/v1/tool-keys", params),
354
- delete: (keyId) => this.request("DELETE", `/v1/tool-keys/${keyId}`)
543
+ get: (keyId) => this.request(
544
+ "GET",
545
+ `/v1/tool-keys/${encodeURIComponent(keyId)}`
546
+ ),
547
+ updateMetadata: (keyId, params) => this.request(
548
+ "PUT",
549
+ `/v1/tool-keys/${encodeURIComponent(keyId)}/metadata`,
550
+ params
551
+ ),
552
+ updateValue: (keyId, value) => this.request(
553
+ "PUT",
554
+ `/v1/tool-keys/${encodeURIComponent(keyId)}/value`,
555
+ { value }
556
+ ),
557
+ test: (keyId) => this.request(
558
+ "POST",
559
+ `/v1/tool-keys/${encodeURIComponent(keyId)}/test`,
560
+ {}
561
+ ),
562
+ mapToTool: (params) => this.request("POST", "/v1/tool-keys/map", params),
563
+ removeMapping: (mappingId) => this.request(
564
+ "DELETE",
565
+ `/v1/tool-keys/map/${encodeURIComponent(mappingId)}`
566
+ ),
567
+ delete: (keyId) => this.request(
568
+ "DELETE",
569
+ `/v1/tool-keys/${encodeURIComponent(keyId)}`
570
+ )
355
571
  };
356
572
  }
357
573
  // ── Tool Permissions ──────────────────────────────────────────────────────
358
574
  get toolPermissions() {
359
575
  return {
360
- list: (toolId) => {
361
- const q = toolId ? `?toolId=${toolId}` : "";
362
- return this.request("GET", `/v1/tool-permissions${q}`);
576
+ /** @deprecated Use listForTool with a tool ID. */
577
+ list: (toolId) => this.request(
578
+ "GET",
579
+ `/v1/tool-permissions/tool/${encodeURIComponent(toolId)}`
580
+ ),
581
+ listForTool: (toolId) => this.request(
582
+ "GET",
583
+ `/v1/tool-permissions/tool/${encodeURIComponent(toolId)}`
584
+ ),
585
+ listForSubject: (subjectId, subjectType) => {
586
+ const query = new URLSearchParams({ subjectId, subjectType });
587
+ return this.request(
588
+ "GET",
589
+ `/v1/tool-permissions/subject?${query}`
590
+ );
591
+ },
592
+ accessibleTools: (subjectId, subjectType) => {
593
+ const query = new URLSearchParams({ subjectId, subjectType });
594
+ return this.request(
595
+ "GET",
596
+ `/v1/tool-permissions/accessible-tools?${query}`
597
+ );
363
598
  },
364
599
  grant: (params) => this.request("POST", "/v1/tool-permissions/grant", params),
365
- revoke: (permissionId) => this.request("DELETE", `/v1/tool-permissions/revoke/${permissionId}`)
600
+ batchGrant: (params) => this.request("POST", "/v1/tool-permissions/batch-grant", params),
601
+ revoke: (permissionId) => this.request(
602
+ "DELETE",
603
+ `/v1/tool-permissions/${encodeURIComponent(permissionId)}`
604
+ ),
605
+ check: (params) => this.request(
606
+ "GET",
607
+ `/v1/tool-permissions/check?${new URLSearchParams(params)}`
608
+ ),
609
+ checkAgentAccess: (toolId, agentId, userId) => {
610
+ const query = new URLSearchParams({ toolId, agentId });
611
+ if (userId) query.set("userId", userId);
612
+ return this.request(
613
+ "GET",
614
+ `/v1/tool-permissions/check-agent-access?${query}`
615
+ );
616
+ },
617
+ transferOwnership: (params) => this.request(
618
+ "POST",
619
+ "/v1/tool-permissions/transfer-ownership",
620
+ params
621
+ )
366
622
  };
367
623
  }
368
624
  // ── Skills ────────────────────────────────────────────────────────────────
@@ -377,14 +633,71 @@ var CommonsClient = class {
377
633
  const qs = params.toString();
378
634
  return this.request("GET", `/v1/skills${qs ? `?${qs}` : ""}`);
379
635
  },
380
- get: (skillIdOrSlug) => this.request("GET", `/v1/skills/${skillIdOrSlug}`),
636
+ get: (skillIdOrSlug) => this.request("GET", `/v1/skills/${encodeURIComponent(skillIdOrSlug)}`),
381
637
  getIndex: (ownerId) => {
382
638
  const qs = ownerId ? `?ownerId=${ownerId}` : "";
383
639
  return this.request("GET", `/v1/skills/index${qs}`);
384
640
  },
641
+ listForAgent: (agentId) => this.request("GET", `/v1/skills/agents/${encodeURIComponent(agentId)}`),
642
+ setAgentAvailability: (skillIdOrSlug, agentId, isEnabled) => this.request(
643
+ "PUT",
644
+ `/v1/skills/${encodeURIComponent(skillIdOrSlug)}/agents/${encodeURIComponent(agentId)}`,
645
+ { isEnabled }
646
+ ),
385
647
  create: (params) => this.request("POST", "/v1/skills", params),
386
- update: (skillIdOrSlug, updates) => this.request("PUT", `/v1/skills/${skillIdOrSlug}`, updates),
387
- delete: (skillIdOrSlug) => this.request("DELETE", `/v1/skills/${skillIdOrSlug}`)
648
+ update: (skillIdOrSlug, updates) => this.request(
649
+ "PUT",
650
+ `/v1/skills/${encodeURIComponent(skillIdOrSlug)}`,
651
+ updates
652
+ ),
653
+ delete: (skillIdOrSlug) => this.request(
654
+ "DELETE",
655
+ `/v1/skills/${encodeURIComponent(skillIdOrSlug)}`
656
+ ),
657
+ import: (file, options) => {
658
+ const body = new FormData();
659
+ body.append("file", file, options?.fileName || "SKILL.md");
660
+ if (options?.agentId) body.set("agentId", options.agentId);
661
+ return this.request("POST", "/v1/skills/import", body);
662
+ }
663
+ };
664
+ }
665
+ // ── Capability providers ─────────────────────────────────────────────────
666
+ get providers() {
667
+ return {
668
+ list: () => this.request("GET", "/v1/providers"),
669
+ configure: (capability, input) => this.request(
670
+ "PUT",
671
+ `/v1/providers/${encodeURIComponent(capability)}`,
672
+ input
673
+ ),
674
+ remove: (capability) => this.request(
675
+ "DELETE",
676
+ `/v1/providers/${encodeURIComponent(capability)}`
677
+ )
678
+ };
679
+ }
680
+ // ── Sandboxed UI plugins ─────────────────────────────────────────────────
681
+ get uiPlugins() {
682
+ return {
683
+ list: (activeOnly = false) => this.request(
684
+ "GET",
685
+ `/v1/ui-plugins${activeOnly ? "?active=true" : ""}`
686
+ ),
687
+ getBySlug: (slug) => this.request(
688
+ "GET",
689
+ `/v1/ui-plugins/slug/${encodeURIComponent(slug)}`
690
+ ),
691
+ create: (input) => this.request("PUT", "/v1/ui-plugins", input),
692
+ setStatus: (pluginId, status) => this.request(
693
+ "PUT",
694
+ `/v1/ui-plugins/${encodeURIComponent(pluginId)}/status`,
695
+ { status }
696
+ ),
697
+ delete: (pluginId) => this.request(
698
+ "DELETE",
699
+ `/v1/ui-plugins/${encodeURIComponent(pluginId)}`
700
+ )
388
701
  };
389
702
  }
390
703
  // ── Wallets ───────────────────────────────────────────────────────────────
@@ -425,7 +738,34 @@ var CommonsClient = class {
425
738
  me: () => this.request("GET", "/v1/auth/me")
426
739
  };
427
740
  }
428
- // ── API Keys ──────────────────────────────────────────────────────────────
741
+ // ── Developer projects and project API keys ──────────────────────────────
742
+ get developer() {
743
+ return {
744
+ scopes: () => this.identityRequest("GET", "/api/platform/scopes"),
745
+ listProjects: () => this.identityRequest("GET", "/api/platform/projects"),
746
+ createProject: (params) => this.identityRequest("POST", "/api/platform/projects", params),
747
+ listApiKeys: (projectId) => this.identityRequest(
748
+ "GET",
749
+ `/api/platform/projects/${encodeURIComponent(projectId)}/api-keys`
750
+ ),
751
+ createApiKey: (projectId, params) => this.identityRequest(
752
+ "POST",
753
+ `/api/platform/projects/${encodeURIComponent(projectId)}/api-keys`,
754
+ params
755
+ ),
756
+ revokeApiKey: (keyId) => this.identityRequest(
757
+ "DELETE",
758
+ `/api/platform/api-keys/${encodeURIComponent(keyId)}`
759
+ )
760
+ };
761
+ }
762
+ // ── Legacy principal API keys ─────────────────────────────────────────────
763
+ /**
764
+ * Legacy per-principal keys (`sk-ac-*`).
765
+ *
766
+ * New developer integrations should use `client.developer`, which creates
767
+ * project-scoped `csk_*` keys with explicit environments and scopes.
768
+ */
429
769
  get apiKeys() {
430
770
  return {
431
771
  /**
@@ -643,6 +983,332 @@ var CommonsClient = class {
643
983
  getSessionUsage: (sessionId) => this.request("GET", `/v1/usage/sessions/${sessionId}`)
644
984
  };
645
985
  }
986
+ // ── Activity and logs ────────────────────────────────────────────────────
987
+ get activity() {
988
+ return {
989
+ list: (filter) => {
990
+ const query = new URLSearchParams();
991
+ if (filter?.actorId) query.set("actorId", filter.actorId);
992
+ if (filter?.eventType) query.set("eventType", filter.eventType);
993
+ if (filter?.since) query.set("since", filter.since);
994
+ if (filter?.limit) query.set("limit", String(filter.limit));
995
+ return this.request(
996
+ "GET",
997
+ `/v1/activity/events${query.size ? `?${query}` : ""}`
998
+ );
999
+ }
1000
+ };
1001
+ }
1002
+ get logs() {
1003
+ return {
1004
+ list: (agentId, filter) => {
1005
+ const query = new URLSearchParams();
1006
+ if (filter?.sessionId) query.set("sessionId", filter.sessionId);
1007
+ if (filter?.limit) query.set("limit", String(filter.limit));
1008
+ return this.request(
1009
+ "GET",
1010
+ `/v1/logs/agents/${encodeURIComponent(agentId)}${query.size ? `?${query}` : ""}`
1011
+ );
1012
+ },
1013
+ observability: (agentId, filter) => {
1014
+ const query = new URLSearchParams();
1015
+ if (filter?.from) query.set("from", filter.from);
1016
+ if (filter?.to) query.set("to", filter.to);
1017
+ if (filter?.limit) query.set("limit", String(filter.limit));
1018
+ return this.request(
1019
+ "GET",
1020
+ `/v1/logs/agents/${encodeURIComponent(agentId)}/observability${query.size ? `?${query}` : ""}`
1021
+ );
1022
+ }
1023
+ };
1024
+ }
1025
+ // ── Files and library ────────────────────────────────────────────────────
1026
+ get files() {
1027
+ return {
1028
+ upload: (files, params) => {
1029
+ const body = new FormData();
1030
+ for (const file of files) {
1031
+ body.append("files", file.data, file.name);
1032
+ }
1033
+ if (params?.agentId) body.set("agentId", params.agentId);
1034
+ if (params?.sessionId) body.set("sessionId", params.sessionId);
1035
+ if (params?.workspaceId) body.set("workspaceId", params.workspaceId);
1036
+ if (params?.storageProvider)
1037
+ body.set("storageProvider", params.storageProvider);
1038
+ return this.request("POST", "/v1/files/upload", body);
1039
+ },
1040
+ get: (fileId, context) => {
1041
+ const query = new URLSearchParams();
1042
+ if (context?.agentId) query.set("agentId", context.agentId);
1043
+ if (context?.sessionId) query.set("sessionId", context.sessionId);
1044
+ return this.request(
1045
+ "GET",
1046
+ `/v1/files/${encodeURIComponent(fileId)}${query.size ? `?${query}` : ""}`
1047
+ );
1048
+ },
1049
+ content: (fileId, options) => {
1050
+ const query = new URLSearchParams();
1051
+ if (options?.agentId) query.set("agentId", options.agentId);
1052
+ if (options?.sessionId) query.set("sessionId", options.sessionId);
1053
+ if (options?.offset !== void 0)
1054
+ query.set("offset", String(options.offset));
1055
+ if (options?.maxChars !== void 0)
1056
+ query.set("maxChars", String(options.maxChars));
1057
+ if (options?.includeImageUrls !== void 0)
1058
+ query.set("includeImageUrls", String(options.includeImageUrls));
1059
+ if (options?.includeDownloadUrl !== void 0)
1060
+ query.set("includeDownloadUrl", String(options.includeDownloadUrl));
1061
+ return this.request(
1062
+ "GET",
1063
+ `/v1/files/${encodeURIComponent(fileId)}/content${query.size ? `?${query}` : ""}`
1064
+ );
1065
+ }
1066
+ };
1067
+ }
1068
+ get library() {
1069
+ return {
1070
+ list: (filter) => {
1071
+ const query = new URLSearchParams();
1072
+ if (filter?.query) query.set("query", filter.query);
1073
+ if (filter?.view) query.set("view", filter.view);
1074
+ if (filter?.source) query.set("source", filter.source);
1075
+ if (filter?.favorite !== void 0)
1076
+ query.set("favorite", String(filter.favorite));
1077
+ if (filter?.sessionId) query.set("sessionId", filter.sessionId);
1078
+ if (filter?.agentId) query.set("agentId", filter.agentId);
1079
+ if (filter?.limit !== void 0)
1080
+ query.set("limit", String(filter.limit));
1081
+ if (filter?.offset !== void 0)
1082
+ query.set("offset", String(filter.offset));
1083
+ return this.request(
1084
+ "GET",
1085
+ `/v1/library${query.size ? `?${query}` : ""}`
1086
+ );
1087
+ },
1088
+ get: (itemId) => this.request(
1089
+ "GET",
1090
+ `/v1/library/${encodeURIComponent(itemId)}`
1091
+ ),
1092
+ download: (itemId) => this.request(
1093
+ "GET",
1094
+ `/v1/library/${encodeURIComponent(itemId)}/download`
1095
+ ),
1096
+ preview: (itemId) => this.request(
1097
+ "GET",
1098
+ `/v1/library/${encodeURIComponent(itemId)}/preview`
1099
+ ),
1100
+ update: (itemId, params) => this.request(
1101
+ "PATCH",
1102
+ `/v1/library/${encodeURIComponent(itemId)}`,
1103
+ params
1104
+ ),
1105
+ delete: (itemId) => this.request(
1106
+ "DELETE",
1107
+ `/v1/library/${encodeURIComponent(itemId)}`
1108
+ ),
1109
+ storagePreference: () => this.request("GET", "/v1/library/preferences/storage"),
1110
+ setStoragePreference: (defaultStorageProvider) => this.request("PATCH", "/v1/library/preferences/storage", {
1111
+ defaultStorageProvider
1112
+ }),
1113
+ grant: (itemId, params) => this.request(
1114
+ "POST",
1115
+ `/v1/library/${encodeURIComponent(itemId)}/grants`,
1116
+ params
1117
+ ),
1118
+ revokeGrant: (itemId, grantId) => this.request(
1119
+ "DELETE",
1120
+ `/v1/library/${encodeURIComponent(itemId)}/grants/${encodeURIComponent(grantId)}`
1121
+ ),
1122
+ createShareLink: (itemId, expiresAt) => this.request(
1123
+ "POST",
1124
+ `/v1/library/${encodeURIComponent(itemId)}/share-links`,
1125
+ { expiresAt }
1126
+ ),
1127
+ revokeShareLink: (itemId, shareId) => this.request(
1128
+ "DELETE",
1129
+ `/v1/library/${encodeURIComponent(itemId)}/share-links/${encodeURIComponent(shareId)}`
1130
+ ),
1131
+ resolveShare: (token) => this.request(
1132
+ "GET",
1133
+ `/v1/shared/artifacts/${encodeURIComponent(token)}`
1134
+ )
1135
+ };
1136
+ }
1137
+ // ── Spaces, projects, and goals ──────────────────────────────────────────
1138
+ get spaces() {
1139
+ return {
1140
+ list: (filter) => {
1141
+ const query = new URLSearchParams();
1142
+ if (filter?.memberId) query.set("memberId", filter.memberId);
1143
+ if (filter?.memberType) query.set("memberType", filter.memberType);
1144
+ if (filter?.agentIds?.length)
1145
+ query.set("agentIds", filter.agentIds.join(","));
1146
+ if (filter?.publicOnly !== void 0)
1147
+ query.set("publicOnly", String(filter.publicOnly));
1148
+ if (filter?.search) query.set("search", filter.search);
1149
+ if (filter?.includeMembers !== void 0)
1150
+ query.set("includeMembers", String(filter.includeMembers));
1151
+ if (filter?.limit !== void 0)
1152
+ query.set("limit", String(filter.limit));
1153
+ if (filter?.offset !== void 0)
1154
+ query.set("offset", String(filter.offset));
1155
+ return this.request(
1156
+ "GET",
1157
+ `/v1/spaces${query.size ? `?${query}` : ""}`
1158
+ );
1159
+ },
1160
+ create: (params, creator) => this.request("POST", "/v1/spaces", params, {
1161
+ headers: {
1162
+ "x-creator-id": creator.id,
1163
+ "x-creator-type": creator.type
1164
+ }
1165
+ }),
1166
+ get: (spaceId) => this.request(
1167
+ "GET",
1168
+ `/v1/spaces/${encodeURIComponent(spaceId)}`
1169
+ ),
1170
+ getFull: (spaceId) => this.request(
1171
+ "GET",
1172
+ `/v1/spaces/${encodeURIComponent(spaceId)}/full`
1173
+ ),
1174
+ update: (spaceId, params) => this.request(
1175
+ "PUT",
1176
+ `/v1/spaces/${encodeURIComponent(spaceId)}`,
1177
+ params
1178
+ ),
1179
+ delete: (spaceId) => this.request(
1180
+ "DELETE",
1181
+ `/v1/spaces/${encodeURIComponent(spaceId)}`
1182
+ ),
1183
+ issueRtcTicket: (spaceId) => this.request(
1184
+ "POST",
1185
+ `/v1/spaces/${encodeURIComponent(spaceId)}/rtc-ticket`,
1186
+ {}
1187
+ ),
1188
+ listMembers: (spaceId) => this.request(
1189
+ "GET",
1190
+ `/v1/spaces/${encodeURIComponent(spaceId)}/members`
1191
+ ),
1192
+ addMember: (spaceId, params) => this.request(
1193
+ "POST",
1194
+ `/v1/spaces/${encodeURIComponent(spaceId)}/members`,
1195
+ params
1196
+ ),
1197
+ updateMember: (spaceId, memberId, memberType, params) => this.request(
1198
+ "PUT",
1199
+ `/v1/spaces/${encodeURIComponent(spaceId)}/members/${encodeURIComponent(memberId)}?memberType=${memberType}`,
1200
+ params
1201
+ ),
1202
+ removeMember: (spaceId, memberId, memberType) => this.request(
1203
+ "DELETE",
1204
+ `/v1/spaces/${encodeURIComponent(spaceId)}/members/${encodeURIComponent(memberId)}?memberType=${memberType}`
1205
+ ),
1206
+ listMessages: (spaceId, filter) => {
1207
+ const query = new URLSearchParams();
1208
+ if (filter?.limit !== void 0)
1209
+ query.set("limit", String(filter.limit));
1210
+ if (filter?.offset !== void 0)
1211
+ query.set("offset", String(filter.offset));
1212
+ if (filter?.memberId) query.set("memberId", filter.memberId);
1213
+ return this.request(
1214
+ "GET",
1215
+ `/v1/spaces/${encodeURIComponent(spaceId)}/messages${query.size ? `?${query}` : ""}`
1216
+ );
1217
+ },
1218
+ sendMessage: (spaceId, params, sender) => this.request(
1219
+ "POST",
1220
+ `/v1/spaces/${encodeURIComponent(spaceId)}/messages`,
1221
+ params,
1222
+ {
1223
+ headers: {
1224
+ "x-sender-id": sender.id,
1225
+ "x-sender-type": sender.type
1226
+ }
1227
+ }
1228
+ ),
1229
+ updateMessage: (spaceId, messageId, params) => this.request(
1230
+ "PUT",
1231
+ `/v1/spaces/${encodeURIComponent(spaceId)}/messages/${encodeURIComponent(messageId)}`,
1232
+ params
1233
+ ),
1234
+ deleteMessage: (spaceId, messageId) => this.request(
1235
+ "DELETE",
1236
+ `/v1/spaces/${encodeURIComponent(spaceId)}/messages/${encodeURIComponent(messageId)}`
1237
+ )
1238
+ };
1239
+ }
1240
+ get projects() {
1241
+ const base = (agentId) => `/v1/agents/${encodeURIComponent(agentId)}/projects`;
1242
+ return {
1243
+ list: (agentId) => this.request("GET", base(agentId)),
1244
+ create: (agentId, params) => this.request("POST", base(agentId), params),
1245
+ get: (agentId, projectId) => this.request(
1246
+ "GET",
1247
+ `${base(agentId)}/${encodeURIComponent(projectId)}`
1248
+ ),
1249
+ writeFiles: (agentId, projectId, files, replace = false) => this.request(
1250
+ "PUT",
1251
+ `${base(agentId)}/${encodeURIComponent(projectId)}/files`,
1252
+ { files, replace }
1253
+ ),
1254
+ publish: (agentId, projectId) => this.request(
1255
+ "POST",
1256
+ `${base(agentId)}/${encodeURIComponent(projectId)}/publish`,
1257
+ {}
1258
+ ),
1259
+ verify: (agentId, projectId, actions) => this.request(
1260
+ "POST",
1261
+ `${base(agentId)}/${encodeURIComponent(projectId)}/verify`,
1262
+ { actions }
1263
+ ),
1264
+ exportToComputer: (agentId, projectId, params) => this.request(
1265
+ "POST",
1266
+ `${base(agentId)}/${encodeURIComponent(projectId)}/export`,
1267
+ params ?? {}
1268
+ ),
1269
+ exportToGitHub: (agentId, projectId, params) => this.request(
1270
+ "POST",
1271
+ `${base(agentId)}/${encodeURIComponent(projectId)}/github`,
1272
+ params ?? {}
1273
+ )
1274
+ };
1275
+ }
1276
+ get goals() {
1277
+ return {
1278
+ create: (params) => this.request("POST", "/v1/goals", params),
1279
+ get: (goalId) => this.request("GET", `/v1/goals/${encodeURIComponent(goalId)}`),
1280
+ updateProgress: (goalId, progress, status) => this.request(
1281
+ "PUT",
1282
+ `/v1/goals/${encodeURIComponent(goalId)}`,
1283
+ { progress, status }
1284
+ )
1285
+ };
1286
+ }
1287
+ // ── Audio and liaison agents ─────────────────────────────────────────────
1288
+ get audio() {
1289
+ return {
1290
+ transcribe: (file, options) => {
1291
+ const body = new FormData();
1292
+ body.append("file", file.data, file.name);
1293
+ if (options?.durationMs !== void 0)
1294
+ body.set("durationMs", String(options.durationMs));
1295
+ return this.request("POST", "/v1/audio/transcriptions", body, {
1296
+ headers: options?.idempotencyKey ? { "x-idempotency-key": options.idempotencyKey } : void 0
1297
+ });
1298
+ }
1299
+ };
1300
+ }
1301
+ get liaisons() {
1302
+ return {
1303
+ create: (params) => this.request("POST", "/v1/liaison", params),
1304
+ interact: (liaisonAgentId, liaisonKey, message) => this.request(
1305
+ "POST",
1306
+ "/v1/liaison/interact",
1307
+ { liaisonAgentId, message },
1308
+ { headers: { "x-api-key": liaisonKey } }
1309
+ )
1310
+ };
1311
+ }
646
1312
  // ── Credits ──────────────────────────────────────────────────────────────
647
1313
  get credits() {
648
1314
  return {
@@ -661,10 +1327,45 @@ var CommonsClient = class {
661
1327
  const qs = params.toString();
662
1328
  return this.request("GET", `/v1/credits/ledger${qs ? `?${qs}` : ""}`);
663
1329
  },
1330
+ summary: () => this.request("GET", "/v1/credits/summary"),
1331
+ campaigns: () => this.request("GET", "/v1/credits/campaigns"),
1332
+ claimCampaign: (params) => this.request("POST", "/v1/credits/campaigns/claim", params),
1333
+ transfers: () => this.request("GET", "/v1/credits/transfers"),
1334
+ gift: (params) => this.request("POST", "/v1/credits/gifts", params),
664
1335
  grant: (params) => this.request("POST", "/v1/credits/grants", params),
665
1336
  debit: (params) => this.request("POST", "/v1/credits/debits", params)
666
1337
  };
667
1338
  }
1339
+ // ── Billing ────────────────────────────────────────────────────────────────
1340
+ get billing() {
1341
+ return {
1342
+ /** Public product catalog served from the backend source of truth. */
1343
+ catalog: () => this.request("GET", "/v1/billing/catalog"),
1344
+ /** Current plan, status, and entitlements for the caller. */
1345
+ subscription: () => this.request("GET", "/v1/billing/subscription"),
1346
+ /** Entitlements only (what paid features the caller may use). */
1347
+ entitlements: () => this.request("GET", "/v1/billing/entitlements"),
1348
+ /** Stripe invoice history for the caller. */
1349
+ invoices: () => this.request("GET", "/v1/billing/invoices"),
1350
+ /** Saved Stripe payment methods for the caller. */
1351
+ paymentMethods: () => this.request("GET", "/v1/billing/payment-methods"),
1352
+ /** Create a Stripe Checkout session for a subscription plan. */
1353
+ subscribe: (planKey) => this.request("POST", "/v1/billing/checkout/subscription", { planKey }),
1354
+ /** Create a Stripe Checkout session for a one-time credit top-up. */
1355
+ topup: (packKey) => this.request("POST", "/v1/billing/checkout/topup", { packKey }),
1356
+ /** Open the Stripe billing portal. */
1357
+ portal: () => this.request("POST", "/v1/billing/portal", {})
1358
+ };
1359
+ }
1360
+ // ── Feature flags ────────────────────────────────────────────────────────
1361
+ get flags() {
1362
+ return {
1363
+ /** Evaluate all active flags for the caller (call once at boot). */
1364
+ all: () => this.request("GET", "/v1/flags"),
1365
+ /** Evaluate a single flag for the caller. */
1366
+ evaluate: (key) => this.request("GET", `/v1/flags/${encodeURIComponent(key)}`)
1367
+ };
1368
+ }
668
1369
  };
669
1370
  var CommonsError = class extends Error {
670
1371
  constructor(message, status, data) {