@agent-commons/sdk 0.4.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/LICENSE +21 -0
- package/README.md +230 -0
- package/dist/index.cjs +656 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +942 -15
- package/dist/index.d.ts +942 -15
- package/dist/index.mjs +656 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +27 -3
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 = {
|
|
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
|
-
|
|
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
|
|
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
|
|
56
|
-
throw new CommonsError(
|
|
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 {
|
|
@@ -76,12 +138,26 @@ var CommonsClient = class {
|
|
|
76
138
|
deployRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/deploy`),
|
|
77
139
|
sleepRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/sleep`),
|
|
78
140
|
restartRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/restart`),
|
|
141
|
+
manageRuntimeChannel: (agentId, channel, action, params = {}) => this.request(
|
|
142
|
+
"POST",
|
|
143
|
+
`/v1/agents/${encodeURIComponent(agentId)}/runtime/channels/${encodeURIComponent(channel)}/${encodeURIComponent(action)}`,
|
|
144
|
+
params
|
|
145
|
+
),
|
|
79
146
|
/** List tools assigned to an agent. */
|
|
80
147
|
listTools: (agentId) => this.request("GET", `/v1/agents/${agentId}/tools`),
|
|
81
148
|
/** Assign a tool to an agent. */
|
|
82
149
|
addTool: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/tools`, params),
|
|
150
|
+
/** Update an agent tool assignment. */
|
|
151
|
+
updateTool: (assignmentId, params) => this.request(
|
|
152
|
+
"PATCH",
|
|
153
|
+
`/v1/agents/tools/${encodeURIComponent(assignmentId)}`,
|
|
154
|
+
params
|
|
155
|
+
),
|
|
83
156
|
/** Remove a tool assignment from an agent. */
|
|
84
|
-
removeTool: (assignmentId) => this.request(
|
|
157
|
+
removeTool: (assignmentId) => this.request(
|
|
158
|
+
"DELETE",
|
|
159
|
+
`/v1/agents/tools/${encodeURIComponent(assignmentId)}`
|
|
160
|
+
),
|
|
85
161
|
/** Create a liaison agent for an external agent. */
|
|
86
162
|
createLiaison: (params) => this.request("POST", "/v1/liaison", params),
|
|
87
163
|
/**
|
|
@@ -94,6 +170,11 @@ var CommonsClient = class {
|
|
|
94
170
|
* }
|
|
95
171
|
*/
|
|
96
172
|
stream: (params) => this._streamAgentRun(params),
|
|
173
|
+
/** Resume a streamed run after executing a caller-owned CLI tool. */
|
|
174
|
+
submitCliToolResult: (requestId, result) => this.request("POST", "/v1/agents/cli-tool-result", {
|
|
175
|
+
requestId,
|
|
176
|
+
result
|
|
177
|
+
}),
|
|
97
178
|
// ── Heartbeat ─────────────────────────────────────────────────────────
|
|
98
179
|
/** Get the current heartbeat status for an agent. */
|
|
99
180
|
getAutonomy: (agentId) => this.request("GET", `/v1/agents/${agentId}/autonomy`),
|
|
@@ -144,6 +225,11 @@ var CommonsClient = class {
|
|
|
144
225
|
`/v1/agents/${agentId}/computer/files/read?path=${encodeURIComponent(path)}`
|
|
145
226
|
);
|
|
146
227
|
},
|
|
228
|
+
writeComputerFile: (agentId, params) => this.request(
|
|
229
|
+
"POST",
|
|
230
|
+
`/v1/agents/${encodeURIComponent(agentId)}/computer/files/write`,
|
|
231
|
+
params
|
|
232
|
+
),
|
|
147
233
|
openComputerBrowser: (agentId, paramsOrLegacyComputerId, legacyParams) => {
|
|
148
234
|
const params = typeof paramsOrLegacyComputerId === "string" ? legacyParams : paramsOrLegacyComputerId;
|
|
149
235
|
if (!params) {
|
|
@@ -155,6 +241,11 @@ var CommonsClient = class {
|
|
|
155
241
|
params
|
|
156
242
|
);
|
|
157
243
|
},
|
|
244
|
+
testComputerBrowser: (agentId) => this.request(
|
|
245
|
+
"POST",
|
|
246
|
+
`/v1/agents/${encodeURIComponent(agentId)}/computer/browser/test`,
|
|
247
|
+
{}
|
|
248
|
+
),
|
|
158
249
|
listComputerEvents: (agentId, limitOrLegacyComputerId, legacyLimit) => {
|
|
159
250
|
const limit = typeof limitOrLegacyComputerId === "number" ? limitOrLegacyComputerId : legacyLimit;
|
|
160
251
|
return this.request(
|
|
@@ -212,6 +303,26 @@ var CommonsClient = class {
|
|
|
212
303
|
}
|
|
213
304
|
};
|
|
214
305
|
}
|
|
306
|
+
get copilot() {
|
|
307
|
+
return {
|
|
308
|
+
get: () => this.request("GET", "/v1/copilot"),
|
|
309
|
+
updateSettings: (params) => this.request("PUT", "/v1/copilot/settings", params),
|
|
310
|
+
listChanges: (filter) => {
|
|
311
|
+
const query = new URLSearchParams();
|
|
312
|
+
if (filter?.status) query.set("status", filter.status);
|
|
313
|
+
if (filter?.resourceType)
|
|
314
|
+
query.set("resourceType", filter.resourceType);
|
|
315
|
+
if (filter?.resourceId) query.set("resourceId", filter.resourceId);
|
|
316
|
+
return this.request(
|
|
317
|
+
"GET",
|
|
318
|
+
`/v1/copilot/changes${query.size ? `?${query}` : ""}`
|
|
319
|
+
);
|
|
320
|
+
},
|
|
321
|
+
acceptChange: (changeId) => this.request("POST", `/v1/copilot/changes/${changeId}/accept`),
|
|
322
|
+
rejectChange: (changeId) => this.request("POST", `/v1/copilot/changes/${changeId}/reject`),
|
|
323
|
+
revertChange: (changeId) => this.request("POST", `/v1/copilot/changes/${changeId}/revert`)
|
|
324
|
+
};
|
|
325
|
+
}
|
|
215
326
|
// ── Run (non-streaming) ───────────────────────────────────────────────────
|
|
216
327
|
get run() {
|
|
217
328
|
return {
|
|
@@ -226,9 +337,45 @@ var CommonsClient = class {
|
|
|
226
337
|
"GET",
|
|
227
338
|
`/v1/workflows?ownerId=${ownerId}&ownerType=${ownerType}`
|
|
228
339
|
),
|
|
340
|
+
discoverPublic: (filter) => {
|
|
341
|
+
const query = new URLSearchParams();
|
|
342
|
+
if (filter?.category) query.set("category", filter.category);
|
|
343
|
+
if (filter?.tags?.length) query.set("tags", filter.tags.join(","));
|
|
344
|
+
if (filter?.limit) query.set("limit", String(filter.limit));
|
|
345
|
+
return this.request(
|
|
346
|
+
"GET",
|
|
347
|
+
`/v1/workflows/public${query.size ? `?${query}` : ""}`
|
|
348
|
+
);
|
|
349
|
+
},
|
|
229
350
|
get: (workflowId) => this.request("GET", `/v1/workflows/${workflowId}`),
|
|
230
351
|
update: (workflowId, updates) => this.request("PUT", `/v1/workflows/${workflowId}`, updates),
|
|
231
352
|
delete: (workflowId) => this.request("DELETE", `/v1/workflows/${workflowId}`),
|
|
353
|
+
fork: (workflowId, params) => this.request(
|
|
354
|
+
"POST",
|
|
355
|
+
`/v1/workflows/${encodeURIComponent(workflowId)}/fork`,
|
|
356
|
+
params
|
|
357
|
+
),
|
|
358
|
+
getWebhook: (workflowId) => this.request(
|
|
359
|
+
"GET",
|
|
360
|
+
`/v1/workflows/${encodeURIComponent(workflowId)}/webhook`
|
|
361
|
+
),
|
|
362
|
+
rotateWebhookToken: (workflowId) => this.request(
|
|
363
|
+
"POST",
|
|
364
|
+
`/v1/workflows/${encodeURIComponent(workflowId)}/webhook-token`,
|
|
365
|
+
{}
|
|
366
|
+
),
|
|
367
|
+
disableWebhook: (workflowId) => this.request(
|
|
368
|
+
"DELETE",
|
|
369
|
+
`/v1/workflows/${encodeURIComponent(workflowId)}/webhook-token`
|
|
370
|
+
),
|
|
371
|
+
executeWebhook: (token, payload, query) => {
|
|
372
|
+
const search = query ? new URLSearchParams(query).toString() : "";
|
|
373
|
+
return this.request(
|
|
374
|
+
"POST",
|
|
375
|
+
`/v1/workflows/webhooks/${encodeURIComponent(token)}${search ? `?${search}` : ""}`,
|
|
376
|
+
payload
|
|
377
|
+
);
|
|
378
|
+
},
|
|
232
379
|
execute: (workflowId, params) => this.request("POST", `/v1/workflows/${workflowId}/execute`, params),
|
|
233
380
|
getExecution: (workflowId, executionId) => this.request(
|
|
234
381
|
"GET",
|
|
@@ -294,7 +441,23 @@ var CommonsClient = class {
|
|
|
294
441
|
create: (params) => this.request("POST", "/v1/sessions", params),
|
|
295
442
|
get: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}`),
|
|
296
443
|
/** Get full session with history, tasks, childSessions, and spaces. */
|
|
297
|
-
getFull: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}/full`)
|
|
444
|
+
getFull: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}/full`),
|
|
445
|
+
/** Rename a session. */
|
|
446
|
+
rename: (sessionId, title) => this.request(
|
|
447
|
+
"PATCH",
|
|
448
|
+
`/v1/sessions/${encodeURIComponent(sessionId)}`,
|
|
449
|
+
{ title }
|
|
450
|
+
),
|
|
451
|
+
/** Delete a session and its owned session data. */
|
|
452
|
+
delete: (sessionId) => this.request(
|
|
453
|
+
"DELETE",
|
|
454
|
+
`/v1/sessions/${encodeURIComponent(sessionId)}`
|
|
455
|
+
),
|
|
456
|
+
/** Get the full chat transcript for a session. */
|
|
457
|
+
getChat: (sessionId) => this.request(
|
|
458
|
+
"GET",
|
|
459
|
+
`/v1/agents/sessions/${encodeURIComponent(sessionId)}/chat`
|
|
460
|
+
)
|
|
298
461
|
};
|
|
299
462
|
}
|
|
300
463
|
// ── Tools ─────────────────────────────────────────────────────────────────
|
|
@@ -330,39 +493,123 @@ var CommonsClient = class {
|
|
|
330
493
|
const q = params ? new URLSearchParams(params).toString() : "";
|
|
331
494
|
return this.request("GET", `/v1/oauth/connections${q ? `?${q}` : ""}`);
|
|
332
495
|
},
|
|
496
|
+
/** Get one OAuth connection. */
|
|
497
|
+
getConnection: (connectionId) => this.request(
|
|
498
|
+
"GET",
|
|
499
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}`
|
|
500
|
+
),
|
|
501
|
+
/** Update connection metadata or its active status. */
|
|
502
|
+
updateConnection: (connectionId, params) => this.request(
|
|
503
|
+
"PUT",
|
|
504
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}`,
|
|
505
|
+
params
|
|
506
|
+
),
|
|
333
507
|
/**
|
|
334
508
|
* Start an OAuth connect flow. Returns the authorization URL the user
|
|
335
509
|
* must open in a browser to grant access.
|
|
336
510
|
*/
|
|
337
511
|
connect: (params) => this.request("POST", "/v1/oauth/connect", params),
|
|
338
512
|
/** Refresh a connection's access token now. */
|
|
339
|
-
refresh: (connectionId) => this.request(
|
|
513
|
+
refresh: (connectionId) => this.request(
|
|
514
|
+
"POST",
|
|
515
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}/refresh`
|
|
516
|
+
),
|
|
340
517
|
/** Check whether a connection's token is valid. */
|
|
341
|
-
test: (connectionId) => this.request(
|
|
518
|
+
test: (connectionId) => this.request(
|
|
519
|
+
"GET",
|
|
520
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}/test`
|
|
521
|
+
),
|
|
342
522
|
/** Revoke a connection and delete its tokens. */
|
|
343
|
-
revoke: (connectionId) => this.request(
|
|
523
|
+
revoke: (connectionId) => this.request(
|
|
524
|
+
"DELETE",
|
|
525
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}`
|
|
526
|
+
)
|
|
344
527
|
};
|
|
345
528
|
}
|
|
346
529
|
// ── Tool Keys ─────────────────────────────────────────────────────────────
|
|
347
530
|
get toolKeys() {
|
|
348
531
|
return {
|
|
349
|
-
list: (
|
|
350
|
-
const q = new URLSearchParams(filter).toString();
|
|
351
|
-
return this.request("GET", `/v1/tool-keys${q ? `?${q}` : ""}`);
|
|
352
|
-
},
|
|
532
|
+
list: () => this.request("GET", "/v1/tool-keys"),
|
|
353
533
|
create: (params) => this.request("POST", "/v1/tool-keys", params),
|
|
354
|
-
|
|
534
|
+
get: (keyId) => this.request(
|
|
535
|
+
"GET",
|
|
536
|
+
`/v1/tool-keys/${encodeURIComponent(keyId)}`
|
|
537
|
+
),
|
|
538
|
+
updateMetadata: (keyId, params) => this.request(
|
|
539
|
+
"PUT",
|
|
540
|
+
`/v1/tool-keys/${encodeURIComponent(keyId)}/metadata`,
|
|
541
|
+
params
|
|
542
|
+
),
|
|
543
|
+
updateValue: (keyId, value) => this.request(
|
|
544
|
+
"PUT",
|
|
545
|
+
`/v1/tool-keys/${encodeURIComponent(keyId)}/value`,
|
|
546
|
+
{ value }
|
|
547
|
+
),
|
|
548
|
+
test: (keyId) => this.request(
|
|
549
|
+
"POST",
|
|
550
|
+
`/v1/tool-keys/${encodeURIComponent(keyId)}/test`,
|
|
551
|
+
{}
|
|
552
|
+
),
|
|
553
|
+
mapToTool: (params) => this.request("POST", "/v1/tool-keys/map", params),
|
|
554
|
+
removeMapping: (mappingId) => this.request(
|
|
555
|
+
"DELETE",
|
|
556
|
+
`/v1/tool-keys/map/${encodeURIComponent(mappingId)}`
|
|
557
|
+
),
|
|
558
|
+
delete: (keyId) => this.request(
|
|
559
|
+
"DELETE",
|
|
560
|
+
`/v1/tool-keys/${encodeURIComponent(keyId)}`
|
|
561
|
+
)
|
|
355
562
|
};
|
|
356
563
|
}
|
|
357
564
|
// ── Tool Permissions ──────────────────────────────────────────────────────
|
|
358
565
|
get toolPermissions() {
|
|
359
566
|
return {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
567
|
+
/** @deprecated Use listForTool with a tool ID. */
|
|
568
|
+
list: (toolId) => this.request(
|
|
569
|
+
"GET",
|
|
570
|
+
`/v1/tool-permissions/tool/${encodeURIComponent(toolId)}`
|
|
571
|
+
),
|
|
572
|
+
listForTool: (toolId) => this.request(
|
|
573
|
+
"GET",
|
|
574
|
+
`/v1/tool-permissions/tool/${encodeURIComponent(toolId)}`
|
|
575
|
+
),
|
|
576
|
+
listForSubject: (subjectId, subjectType) => {
|
|
577
|
+
const query = new URLSearchParams({ subjectId, subjectType });
|
|
578
|
+
return this.request(
|
|
579
|
+
"GET",
|
|
580
|
+
`/v1/tool-permissions/subject?${query}`
|
|
581
|
+
);
|
|
582
|
+
},
|
|
583
|
+
accessibleTools: (subjectId, subjectType) => {
|
|
584
|
+
const query = new URLSearchParams({ subjectId, subjectType });
|
|
585
|
+
return this.request(
|
|
586
|
+
"GET",
|
|
587
|
+
`/v1/tool-permissions/accessible-tools?${query}`
|
|
588
|
+
);
|
|
363
589
|
},
|
|
364
590
|
grant: (params) => this.request("POST", "/v1/tool-permissions/grant", params),
|
|
365
|
-
|
|
591
|
+
batchGrant: (params) => this.request("POST", "/v1/tool-permissions/batch-grant", params),
|
|
592
|
+
revoke: (permissionId) => this.request(
|
|
593
|
+
"DELETE",
|
|
594
|
+
`/v1/tool-permissions/${encodeURIComponent(permissionId)}`
|
|
595
|
+
),
|
|
596
|
+
check: (params) => this.request(
|
|
597
|
+
"GET",
|
|
598
|
+
`/v1/tool-permissions/check?${new URLSearchParams(params)}`
|
|
599
|
+
),
|
|
600
|
+
checkAgentAccess: (toolId, agentId, userId) => {
|
|
601
|
+
const query = new URLSearchParams({ toolId, agentId });
|
|
602
|
+
if (userId) query.set("userId", userId);
|
|
603
|
+
return this.request(
|
|
604
|
+
"GET",
|
|
605
|
+
`/v1/tool-permissions/check-agent-access?${query}`
|
|
606
|
+
);
|
|
607
|
+
},
|
|
608
|
+
transferOwnership: (params) => this.request(
|
|
609
|
+
"POST",
|
|
610
|
+
"/v1/tool-permissions/transfer-ownership",
|
|
611
|
+
params
|
|
612
|
+
)
|
|
366
613
|
};
|
|
367
614
|
}
|
|
368
615
|
// ── Skills ────────────────────────────────────────────────────────────────
|
|
@@ -425,7 +672,34 @@ var CommonsClient = class {
|
|
|
425
672
|
me: () => this.request("GET", "/v1/auth/me")
|
|
426
673
|
};
|
|
427
674
|
}
|
|
428
|
-
// ── API
|
|
675
|
+
// ── Developer projects and project API keys ──────────────────────────────
|
|
676
|
+
get developer() {
|
|
677
|
+
return {
|
|
678
|
+
scopes: () => this.identityRequest("GET", "/api/platform/scopes"),
|
|
679
|
+
listProjects: () => this.identityRequest("GET", "/api/platform/projects"),
|
|
680
|
+
createProject: (params) => this.identityRequest("POST", "/api/platform/projects", params),
|
|
681
|
+
listApiKeys: (projectId) => this.identityRequest(
|
|
682
|
+
"GET",
|
|
683
|
+
`/api/platform/projects/${encodeURIComponent(projectId)}/api-keys`
|
|
684
|
+
),
|
|
685
|
+
createApiKey: (projectId, params) => this.identityRequest(
|
|
686
|
+
"POST",
|
|
687
|
+
`/api/platform/projects/${encodeURIComponent(projectId)}/api-keys`,
|
|
688
|
+
params
|
|
689
|
+
),
|
|
690
|
+
revokeApiKey: (keyId) => this.identityRequest(
|
|
691
|
+
"DELETE",
|
|
692
|
+
`/api/platform/api-keys/${encodeURIComponent(keyId)}`
|
|
693
|
+
)
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
// ── Legacy principal API keys ─────────────────────────────────────────────
|
|
697
|
+
/**
|
|
698
|
+
* Legacy per-principal keys (`sk-ac-*`).
|
|
699
|
+
*
|
|
700
|
+
* New developer integrations should use `client.developer`, which creates
|
|
701
|
+
* project-scoped `csk_*` keys with explicit environments and scopes.
|
|
702
|
+
*/
|
|
429
703
|
get apiKeys() {
|
|
430
704
|
return {
|
|
431
705
|
/**
|
|
@@ -643,6 +917,331 @@ var CommonsClient = class {
|
|
|
643
917
|
getSessionUsage: (sessionId) => this.request("GET", `/v1/usage/sessions/${sessionId}`)
|
|
644
918
|
};
|
|
645
919
|
}
|
|
920
|
+
// ── Activity and logs ────────────────────────────────────────────────────
|
|
921
|
+
get activity() {
|
|
922
|
+
return {
|
|
923
|
+
list: (filter) => {
|
|
924
|
+
const query = new URLSearchParams();
|
|
925
|
+
if (filter?.actorId) query.set("actorId", filter.actorId);
|
|
926
|
+
if (filter?.eventType) query.set("eventType", filter.eventType);
|
|
927
|
+
if (filter?.since) query.set("since", filter.since);
|
|
928
|
+
if (filter?.limit) query.set("limit", String(filter.limit));
|
|
929
|
+
return this.request(
|
|
930
|
+
"GET",
|
|
931
|
+
`/v1/activity/events${query.size ? `?${query}` : ""}`
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
get logs() {
|
|
937
|
+
return {
|
|
938
|
+
list: (agentId, filter) => {
|
|
939
|
+
const query = new URLSearchParams();
|
|
940
|
+
if (filter?.sessionId) query.set("sessionId", filter.sessionId);
|
|
941
|
+
if (filter?.limit) query.set("limit", String(filter.limit));
|
|
942
|
+
return this.request(
|
|
943
|
+
"GET",
|
|
944
|
+
`/v1/logs/agents/${encodeURIComponent(agentId)}${query.size ? `?${query}` : ""}`
|
|
945
|
+
);
|
|
946
|
+
},
|
|
947
|
+
observability: (agentId, filter) => {
|
|
948
|
+
const query = new URLSearchParams();
|
|
949
|
+
if (filter?.from) query.set("from", filter.from);
|
|
950
|
+
if (filter?.to) query.set("to", filter.to);
|
|
951
|
+
if (filter?.limit) query.set("limit", String(filter.limit));
|
|
952
|
+
return this.request(
|
|
953
|
+
"GET",
|
|
954
|
+
`/v1/logs/agents/${encodeURIComponent(agentId)}/observability${query.size ? `?${query}` : ""}`
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
// ── Files and library ────────────────────────────────────────────────────
|
|
960
|
+
get files() {
|
|
961
|
+
return {
|
|
962
|
+
upload: (files, params) => {
|
|
963
|
+
const body = new FormData();
|
|
964
|
+
for (const file of files) {
|
|
965
|
+
body.append("files", file.data, file.name);
|
|
966
|
+
}
|
|
967
|
+
if (params?.agentId) body.set("agentId", params.agentId);
|
|
968
|
+
if (params?.sessionId) body.set("sessionId", params.sessionId);
|
|
969
|
+
if (params?.workspaceId) body.set("workspaceId", params.workspaceId);
|
|
970
|
+
if (params?.storageProvider)
|
|
971
|
+
body.set("storageProvider", params.storageProvider);
|
|
972
|
+
return this.request("POST", "/v1/files/upload", body);
|
|
973
|
+
},
|
|
974
|
+
get: (fileId, context) => {
|
|
975
|
+
const query = new URLSearchParams();
|
|
976
|
+
if (context?.agentId) query.set("agentId", context.agentId);
|
|
977
|
+
if (context?.sessionId) query.set("sessionId", context.sessionId);
|
|
978
|
+
return this.request(
|
|
979
|
+
"GET",
|
|
980
|
+
`/v1/files/${encodeURIComponent(fileId)}${query.size ? `?${query}` : ""}`
|
|
981
|
+
);
|
|
982
|
+
},
|
|
983
|
+
content: (fileId, options) => {
|
|
984
|
+
const query = new URLSearchParams();
|
|
985
|
+
if (options?.agentId) query.set("agentId", options.agentId);
|
|
986
|
+
if (options?.sessionId) query.set("sessionId", options.sessionId);
|
|
987
|
+
if (options?.offset !== void 0)
|
|
988
|
+
query.set("offset", String(options.offset));
|
|
989
|
+
if (options?.maxChars !== void 0)
|
|
990
|
+
query.set("maxChars", String(options.maxChars));
|
|
991
|
+
if (options?.includeImageUrls !== void 0)
|
|
992
|
+
query.set("includeImageUrls", String(options.includeImageUrls));
|
|
993
|
+
if (options?.includeDownloadUrl !== void 0)
|
|
994
|
+
query.set("includeDownloadUrl", String(options.includeDownloadUrl));
|
|
995
|
+
return this.request(
|
|
996
|
+
"GET",
|
|
997
|
+
`/v1/files/${encodeURIComponent(fileId)}/content${query.size ? `?${query}` : ""}`
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
get library() {
|
|
1003
|
+
return {
|
|
1004
|
+
list: (filter) => {
|
|
1005
|
+
const query = new URLSearchParams();
|
|
1006
|
+
if (filter?.query) query.set("query", filter.query);
|
|
1007
|
+
if (filter?.view) query.set("view", filter.view);
|
|
1008
|
+
if (filter?.source) query.set("source", filter.source);
|
|
1009
|
+
if (filter?.favorite !== void 0)
|
|
1010
|
+
query.set("favorite", String(filter.favorite));
|
|
1011
|
+
if (filter?.sessionId) query.set("sessionId", filter.sessionId);
|
|
1012
|
+
if (filter?.limit !== void 0)
|
|
1013
|
+
query.set("limit", String(filter.limit));
|
|
1014
|
+
if (filter?.offset !== void 0)
|
|
1015
|
+
query.set("offset", String(filter.offset));
|
|
1016
|
+
return this.request(
|
|
1017
|
+
"GET",
|
|
1018
|
+
`/v1/library${query.size ? `?${query}` : ""}`
|
|
1019
|
+
);
|
|
1020
|
+
},
|
|
1021
|
+
get: (itemId) => this.request(
|
|
1022
|
+
"GET",
|
|
1023
|
+
`/v1/library/${encodeURIComponent(itemId)}`
|
|
1024
|
+
),
|
|
1025
|
+
download: (itemId) => this.request(
|
|
1026
|
+
"GET",
|
|
1027
|
+
`/v1/library/${encodeURIComponent(itemId)}/download`
|
|
1028
|
+
),
|
|
1029
|
+
preview: (itemId) => this.request(
|
|
1030
|
+
"GET",
|
|
1031
|
+
`/v1/library/${encodeURIComponent(itemId)}/preview`
|
|
1032
|
+
),
|
|
1033
|
+
update: (itemId, params) => this.request(
|
|
1034
|
+
"PATCH",
|
|
1035
|
+
`/v1/library/${encodeURIComponent(itemId)}`,
|
|
1036
|
+
params
|
|
1037
|
+
),
|
|
1038
|
+
delete: (itemId) => this.request(
|
|
1039
|
+
"DELETE",
|
|
1040
|
+
`/v1/library/${encodeURIComponent(itemId)}`
|
|
1041
|
+
),
|
|
1042
|
+
storagePreference: () => this.request("GET", "/v1/library/preferences/storage"),
|
|
1043
|
+
setStoragePreference: (defaultStorageProvider) => this.request("PATCH", "/v1/library/preferences/storage", {
|
|
1044
|
+
defaultStorageProvider
|
|
1045
|
+
}),
|
|
1046
|
+
grant: (itemId, params) => this.request(
|
|
1047
|
+
"POST",
|
|
1048
|
+
`/v1/library/${encodeURIComponent(itemId)}/grants`,
|
|
1049
|
+
params
|
|
1050
|
+
),
|
|
1051
|
+
revokeGrant: (itemId, grantId) => this.request(
|
|
1052
|
+
"DELETE",
|
|
1053
|
+
`/v1/library/${encodeURIComponent(itemId)}/grants/${encodeURIComponent(grantId)}`
|
|
1054
|
+
),
|
|
1055
|
+
createShareLink: (itemId, expiresAt) => this.request(
|
|
1056
|
+
"POST",
|
|
1057
|
+
`/v1/library/${encodeURIComponent(itemId)}/share-links`,
|
|
1058
|
+
{ expiresAt }
|
|
1059
|
+
),
|
|
1060
|
+
revokeShareLink: (itemId, shareId) => this.request(
|
|
1061
|
+
"DELETE",
|
|
1062
|
+
`/v1/library/${encodeURIComponent(itemId)}/share-links/${encodeURIComponent(shareId)}`
|
|
1063
|
+
),
|
|
1064
|
+
resolveShare: (token) => this.request(
|
|
1065
|
+
"GET",
|
|
1066
|
+
`/v1/shared/artifacts/${encodeURIComponent(token)}`
|
|
1067
|
+
)
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
// ── Spaces, projects, and goals ──────────────────────────────────────────
|
|
1071
|
+
get spaces() {
|
|
1072
|
+
return {
|
|
1073
|
+
list: (filter) => {
|
|
1074
|
+
const query = new URLSearchParams();
|
|
1075
|
+
if (filter?.memberId) query.set("memberId", filter.memberId);
|
|
1076
|
+
if (filter?.memberType) query.set("memberType", filter.memberType);
|
|
1077
|
+
if (filter?.agentIds?.length)
|
|
1078
|
+
query.set("agentIds", filter.agentIds.join(","));
|
|
1079
|
+
if (filter?.publicOnly !== void 0)
|
|
1080
|
+
query.set("publicOnly", String(filter.publicOnly));
|
|
1081
|
+
if (filter?.search) query.set("search", filter.search);
|
|
1082
|
+
if (filter?.includeMembers !== void 0)
|
|
1083
|
+
query.set("includeMembers", String(filter.includeMembers));
|
|
1084
|
+
if (filter?.limit !== void 0)
|
|
1085
|
+
query.set("limit", String(filter.limit));
|
|
1086
|
+
if (filter?.offset !== void 0)
|
|
1087
|
+
query.set("offset", String(filter.offset));
|
|
1088
|
+
return this.request(
|
|
1089
|
+
"GET",
|
|
1090
|
+
`/v1/spaces${query.size ? `?${query}` : ""}`
|
|
1091
|
+
);
|
|
1092
|
+
},
|
|
1093
|
+
create: (params, creator) => this.request("POST", "/v1/spaces", params, {
|
|
1094
|
+
headers: {
|
|
1095
|
+
"x-creator-id": creator.id,
|
|
1096
|
+
"x-creator-type": creator.type
|
|
1097
|
+
}
|
|
1098
|
+
}),
|
|
1099
|
+
get: (spaceId) => this.request(
|
|
1100
|
+
"GET",
|
|
1101
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}`
|
|
1102
|
+
),
|
|
1103
|
+
getFull: (spaceId) => this.request(
|
|
1104
|
+
"GET",
|
|
1105
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/full`
|
|
1106
|
+
),
|
|
1107
|
+
update: (spaceId, params) => this.request(
|
|
1108
|
+
"PUT",
|
|
1109
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}`,
|
|
1110
|
+
params
|
|
1111
|
+
),
|
|
1112
|
+
delete: (spaceId) => this.request(
|
|
1113
|
+
"DELETE",
|
|
1114
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}`
|
|
1115
|
+
),
|
|
1116
|
+
issueRtcTicket: (spaceId) => this.request(
|
|
1117
|
+
"POST",
|
|
1118
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/rtc-ticket`,
|
|
1119
|
+
{}
|
|
1120
|
+
),
|
|
1121
|
+
listMembers: (spaceId) => this.request(
|
|
1122
|
+
"GET",
|
|
1123
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/members`
|
|
1124
|
+
),
|
|
1125
|
+
addMember: (spaceId, params) => this.request(
|
|
1126
|
+
"POST",
|
|
1127
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/members`,
|
|
1128
|
+
params
|
|
1129
|
+
),
|
|
1130
|
+
updateMember: (spaceId, memberId, memberType, params) => this.request(
|
|
1131
|
+
"PUT",
|
|
1132
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/members/${encodeURIComponent(memberId)}?memberType=${memberType}`,
|
|
1133
|
+
params
|
|
1134
|
+
),
|
|
1135
|
+
removeMember: (spaceId, memberId, memberType) => this.request(
|
|
1136
|
+
"DELETE",
|
|
1137
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/members/${encodeURIComponent(memberId)}?memberType=${memberType}`
|
|
1138
|
+
),
|
|
1139
|
+
listMessages: (spaceId, filter) => {
|
|
1140
|
+
const query = new URLSearchParams();
|
|
1141
|
+
if (filter?.limit !== void 0)
|
|
1142
|
+
query.set("limit", String(filter.limit));
|
|
1143
|
+
if (filter?.offset !== void 0)
|
|
1144
|
+
query.set("offset", String(filter.offset));
|
|
1145
|
+
if (filter?.memberId) query.set("memberId", filter.memberId);
|
|
1146
|
+
return this.request(
|
|
1147
|
+
"GET",
|
|
1148
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/messages${query.size ? `?${query}` : ""}`
|
|
1149
|
+
);
|
|
1150
|
+
},
|
|
1151
|
+
sendMessage: (spaceId, params, sender) => this.request(
|
|
1152
|
+
"POST",
|
|
1153
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/messages`,
|
|
1154
|
+
params,
|
|
1155
|
+
{
|
|
1156
|
+
headers: {
|
|
1157
|
+
"x-sender-id": sender.id,
|
|
1158
|
+
"x-sender-type": sender.type
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
),
|
|
1162
|
+
updateMessage: (spaceId, messageId, params) => this.request(
|
|
1163
|
+
"PUT",
|
|
1164
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/messages/${encodeURIComponent(messageId)}`,
|
|
1165
|
+
params
|
|
1166
|
+
),
|
|
1167
|
+
deleteMessage: (spaceId, messageId) => this.request(
|
|
1168
|
+
"DELETE",
|
|
1169
|
+
`/v1/spaces/${encodeURIComponent(spaceId)}/messages/${encodeURIComponent(messageId)}`
|
|
1170
|
+
)
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
get projects() {
|
|
1174
|
+
const base = (agentId) => `/v1/agents/${encodeURIComponent(agentId)}/projects`;
|
|
1175
|
+
return {
|
|
1176
|
+
list: (agentId) => this.request("GET", base(agentId)),
|
|
1177
|
+
create: (agentId, params) => this.request("POST", base(agentId), params),
|
|
1178
|
+
get: (agentId, projectId) => this.request(
|
|
1179
|
+
"GET",
|
|
1180
|
+
`${base(agentId)}/${encodeURIComponent(projectId)}`
|
|
1181
|
+
),
|
|
1182
|
+
writeFiles: (agentId, projectId, files, replace = false) => this.request(
|
|
1183
|
+
"PUT",
|
|
1184
|
+
`${base(agentId)}/${encodeURIComponent(projectId)}/files`,
|
|
1185
|
+
{ files, replace }
|
|
1186
|
+
),
|
|
1187
|
+
publish: (agentId, projectId) => this.request(
|
|
1188
|
+
"POST",
|
|
1189
|
+
`${base(agentId)}/${encodeURIComponent(projectId)}/publish`,
|
|
1190
|
+
{}
|
|
1191
|
+
),
|
|
1192
|
+
verify: (agentId, projectId, actions) => this.request(
|
|
1193
|
+
"POST",
|
|
1194
|
+
`${base(agentId)}/${encodeURIComponent(projectId)}/verify`,
|
|
1195
|
+
{ actions }
|
|
1196
|
+
),
|
|
1197
|
+
exportToComputer: (agentId, projectId, params) => this.request(
|
|
1198
|
+
"POST",
|
|
1199
|
+
`${base(agentId)}/${encodeURIComponent(projectId)}/export`,
|
|
1200
|
+
params ?? {}
|
|
1201
|
+
),
|
|
1202
|
+
exportToGitHub: (agentId, projectId, params) => this.request(
|
|
1203
|
+
"POST",
|
|
1204
|
+
`${base(agentId)}/${encodeURIComponent(projectId)}/github`,
|
|
1205
|
+
params ?? {}
|
|
1206
|
+
)
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
|
+
get goals() {
|
|
1210
|
+
return {
|
|
1211
|
+
create: (params) => this.request("POST", "/v1/goals", params),
|
|
1212
|
+
get: (goalId) => this.request("GET", `/v1/goals/${encodeURIComponent(goalId)}`),
|
|
1213
|
+
updateProgress: (goalId, progress, status) => this.request(
|
|
1214
|
+
"PUT",
|
|
1215
|
+
`/v1/goals/${encodeURIComponent(goalId)}`,
|
|
1216
|
+
{ progress, status }
|
|
1217
|
+
)
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
// ── Audio and liaison agents ─────────────────────────────────────────────
|
|
1221
|
+
get audio() {
|
|
1222
|
+
return {
|
|
1223
|
+
transcribe: (file, options) => {
|
|
1224
|
+
const body = new FormData();
|
|
1225
|
+
body.append("file", file.data, file.name);
|
|
1226
|
+
if (options?.durationMs !== void 0)
|
|
1227
|
+
body.set("durationMs", String(options.durationMs));
|
|
1228
|
+
return this.request("POST", "/v1/audio/transcriptions", body, {
|
|
1229
|
+
headers: options?.idempotencyKey ? { "x-idempotency-key": options.idempotencyKey } : void 0
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
get liaisons() {
|
|
1235
|
+
return {
|
|
1236
|
+
create: (params) => this.request("POST", "/v1/liaison", params),
|
|
1237
|
+
interact: (liaisonAgentId, liaisonKey, message) => this.request(
|
|
1238
|
+
"POST",
|
|
1239
|
+
"/v1/liaison/interact",
|
|
1240
|
+
{ liaisonAgentId, message },
|
|
1241
|
+
{ headers: { "x-api-key": liaisonKey } }
|
|
1242
|
+
)
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
646
1245
|
// ── Credits ──────────────────────────────────────────────────────────────
|
|
647
1246
|
get credits() {
|
|
648
1247
|
return {
|
|
@@ -661,10 +1260,45 @@ var CommonsClient = class {
|
|
|
661
1260
|
const qs = params.toString();
|
|
662
1261
|
return this.request("GET", `/v1/credits/ledger${qs ? `?${qs}` : ""}`);
|
|
663
1262
|
},
|
|
1263
|
+
summary: () => this.request("GET", "/v1/credits/summary"),
|
|
1264
|
+
campaigns: () => this.request("GET", "/v1/credits/campaigns"),
|
|
1265
|
+
claimCampaign: (params) => this.request("POST", "/v1/credits/campaigns/claim", params),
|
|
1266
|
+
transfers: () => this.request("GET", "/v1/credits/transfers"),
|
|
1267
|
+
gift: (params) => this.request("POST", "/v1/credits/gifts", params),
|
|
664
1268
|
grant: (params) => this.request("POST", "/v1/credits/grants", params),
|
|
665
1269
|
debit: (params) => this.request("POST", "/v1/credits/debits", params)
|
|
666
1270
|
};
|
|
667
1271
|
}
|
|
1272
|
+
// ── Billing ────────────────────────────────────────────────────────────────
|
|
1273
|
+
get billing() {
|
|
1274
|
+
return {
|
|
1275
|
+
/** Public product catalog served from the backend source of truth. */
|
|
1276
|
+
catalog: () => this.request("GET", "/v1/billing/catalog"),
|
|
1277
|
+
/** Current plan, status, and entitlements for the caller. */
|
|
1278
|
+
subscription: () => this.request("GET", "/v1/billing/subscription"),
|
|
1279
|
+
/** Entitlements only (what paid features the caller may use). */
|
|
1280
|
+
entitlements: () => this.request("GET", "/v1/billing/entitlements"),
|
|
1281
|
+
/** Stripe invoice history for the caller. */
|
|
1282
|
+
invoices: () => this.request("GET", "/v1/billing/invoices"),
|
|
1283
|
+
/** Saved Stripe payment methods for the caller. */
|
|
1284
|
+
paymentMethods: () => this.request("GET", "/v1/billing/payment-methods"),
|
|
1285
|
+
/** Create a Stripe Checkout session for a subscription plan. */
|
|
1286
|
+
subscribe: (planKey) => this.request("POST", "/v1/billing/checkout/subscription", { planKey }),
|
|
1287
|
+
/** Create a Stripe Checkout session for a one-time credit top-up. */
|
|
1288
|
+
topup: (packKey) => this.request("POST", "/v1/billing/checkout/topup", { packKey }),
|
|
1289
|
+
/** Open the Stripe billing portal. */
|
|
1290
|
+
portal: () => this.request("POST", "/v1/billing/portal", {})
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
// ── Feature flags ────────────────────────────────────────────────────────
|
|
1294
|
+
get flags() {
|
|
1295
|
+
return {
|
|
1296
|
+
/** Evaluate all active flags for the caller (call once at boot). */
|
|
1297
|
+
all: () => this.request("GET", "/v1/flags"),
|
|
1298
|
+
/** Evaluate a single flag for the caller. */
|
|
1299
|
+
evaluate: (key) => this.request("GET", `/v1/flags/${encodeURIComponent(key)}`)
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
668
1302
|
};
|
|
669
1303
|
var CommonsError = class extends Error {
|
|
670
1304
|
constructor(message, status, data) {
|