@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.mjs
CHANGED
|
@@ -5,29 +5,91 @@ var CommonsClient = class {
|
|
|
5
5
|
/\/$/,
|
|
6
6
|
""
|
|
7
7
|
);
|
|
8
|
+
this.identityUrl = (config.identityUrl ?? "https://auth.agentcommons.io").replace(/\/api\/auth\/?$/, "").replace(/\/$/, "");
|
|
9
|
+
this.identityToken = config.identityToken;
|
|
8
10
|
this.apiKey = config.apiKey;
|
|
9
11
|
this.initiator = config.initiator;
|
|
10
12
|
this._fetch = config.fetch ?? fetch;
|
|
11
13
|
}
|
|
12
14
|
// ── Helpers ───────────────────────────────────────────────────────────────
|
|
13
|
-
headers(extra) {
|
|
14
|
-
const h = {
|
|
15
|
+
headers(extra, json = true) {
|
|
16
|
+
const h = {};
|
|
17
|
+
if (json) h["Content-Type"] = "application/json";
|
|
15
18
|
if (this.apiKey) h["Authorization"] = `Bearer ${this.apiKey}`;
|
|
16
19
|
if (this.initiator) h["x-initiator"] = this.initiator;
|
|
17
20
|
return { ...h, ...extra };
|
|
18
21
|
}
|
|
19
|
-
|
|
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;
|
|
20
28
|
const res = await this._fetch(`${this.baseUrl}${path}`, {
|
|
21
29
|
method,
|
|
22
|
-
headers: this.headers(),
|
|
23
|
-
body: body
|
|
30
|
+
headers: this.headers(options.headers, !isFormData),
|
|
31
|
+
body: body === void 0 ? void 0 : isFormData ? body : JSON.stringify(body),
|
|
32
|
+
signal: options.signal
|
|
24
33
|
});
|
|
25
34
|
if (!res.ok) {
|
|
26
|
-
const err = await
|
|
27
|
-
throw new CommonsError(
|
|
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();
|
|
28
46
|
}
|
|
29
47
|
return res.json();
|
|
30
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
|
+
}
|
|
31
93
|
// ── Models ────────────────────────────────────────────────────────────────
|
|
32
94
|
get models() {
|
|
33
95
|
return {
|
|
@@ -47,12 +109,26 @@ var CommonsClient = class {
|
|
|
47
109
|
deployRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/deploy`),
|
|
48
110
|
sleepRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/sleep`),
|
|
49
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
|
+
),
|
|
50
117
|
/** List tools assigned to an agent. */
|
|
51
118
|
listTools: (agentId) => this.request("GET", `/v1/agents/${agentId}/tools`),
|
|
52
119
|
/** Assign a tool to an agent. */
|
|
53
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
|
+
),
|
|
54
127
|
/** Remove a tool assignment from an agent. */
|
|
55
|
-
removeTool: (assignmentId) => this.request(
|
|
128
|
+
removeTool: (assignmentId) => this.request(
|
|
129
|
+
"DELETE",
|
|
130
|
+
`/v1/agents/tools/${encodeURIComponent(assignmentId)}`
|
|
131
|
+
),
|
|
56
132
|
/** Create a liaison agent for an external agent. */
|
|
57
133
|
createLiaison: (params) => this.request("POST", "/v1/liaison", params),
|
|
58
134
|
/**
|
|
@@ -65,6 +141,11 @@ var CommonsClient = class {
|
|
|
65
141
|
* }
|
|
66
142
|
*/
|
|
67
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
|
+
}),
|
|
68
149
|
// ── Heartbeat ─────────────────────────────────────────────────────────
|
|
69
150
|
/** Get the current heartbeat status for an agent. */
|
|
70
151
|
getAutonomy: (agentId) => this.request("GET", `/v1/agents/${agentId}/autonomy`),
|
|
@@ -115,6 +196,11 @@ var CommonsClient = class {
|
|
|
115
196
|
`/v1/agents/${agentId}/computer/files/read?path=${encodeURIComponent(path)}`
|
|
116
197
|
);
|
|
117
198
|
},
|
|
199
|
+
writeComputerFile: (agentId, params) => this.request(
|
|
200
|
+
"POST",
|
|
201
|
+
`/v1/agents/${encodeURIComponent(agentId)}/computer/files/write`,
|
|
202
|
+
params
|
|
203
|
+
),
|
|
118
204
|
openComputerBrowser: (agentId, paramsOrLegacyComputerId, legacyParams) => {
|
|
119
205
|
const params = typeof paramsOrLegacyComputerId === "string" ? legacyParams : paramsOrLegacyComputerId;
|
|
120
206
|
if (!params) {
|
|
@@ -126,6 +212,11 @@ var CommonsClient = class {
|
|
|
126
212
|
params
|
|
127
213
|
);
|
|
128
214
|
},
|
|
215
|
+
testComputerBrowser: (agentId) => this.request(
|
|
216
|
+
"POST",
|
|
217
|
+
`/v1/agents/${encodeURIComponent(agentId)}/computer/browser/test`,
|
|
218
|
+
{}
|
|
219
|
+
),
|
|
129
220
|
listComputerEvents: (agentId, limitOrLegacyComputerId, legacyLimit) => {
|
|
130
221
|
const limit = typeof limitOrLegacyComputerId === "number" ? limitOrLegacyComputerId : legacyLimit;
|
|
131
222
|
return this.request(
|
|
@@ -183,6 +274,26 @@ var CommonsClient = class {
|
|
|
183
274
|
}
|
|
184
275
|
};
|
|
185
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
|
+
}
|
|
186
297
|
// ── Run (non-streaming) ───────────────────────────────────────────────────
|
|
187
298
|
get run() {
|
|
188
299
|
return {
|
|
@@ -197,9 +308,45 @@ var CommonsClient = class {
|
|
|
197
308
|
"GET",
|
|
198
309
|
`/v1/workflows?ownerId=${ownerId}&ownerType=${ownerType}`
|
|
199
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
|
+
},
|
|
200
321
|
get: (workflowId) => this.request("GET", `/v1/workflows/${workflowId}`),
|
|
201
322
|
update: (workflowId, updates) => this.request("PUT", `/v1/workflows/${workflowId}`, updates),
|
|
202
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
|
+
},
|
|
203
350
|
execute: (workflowId, params) => this.request("POST", `/v1/workflows/${workflowId}/execute`, params),
|
|
204
351
|
getExecution: (workflowId, executionId) => this.request(
|
|
205
352
|
"GET",
|
|
@@ -265,7 +412,23 @@ var CommonsClient = class {
|
|
|
265
412
|
create: (params) => this.request("POST", "/v1/sessions", params),
|
|
266
413
|
get: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}`),
|
|
267
414
|
/** Get full session with history, tasks, childSessions, and spaces. */
|
|
268
|
-
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
|
+
)
|
|
269
432
|
};
|
|
270
433
|
}
|
|
271
434
|
// ── Tools ─────────────────────────────────────────────────────────────────
|
|
@@ -301,39 +464,123 @@ var CommonsClient = class {
|
|
|
301
464
|
const q = params ? new URLSearchParams(params).toString() : "";
|
|
302
465
|
return this.request("GET", `/v1/oauth/connections${q ? `?${q}` : ""}`);
|
|
303
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
|
+
),
|
|
304
478
|
/**
|
|
305
479
|
* Start an OAuth connect flow. Returns the authorization URL the user
|
|
306
480
|
* must open in a browser to grant access.
|
|
307
481
|
*/
|
|
308
482
|
connect: (params) => this.request("POST", "/v1/oauth/connect", params),
|
|
309
483
|
/** Refresh a connection's access token now. */
|
|
310
|
-
refresh: (connectionId) => this.request(
|
|
484
|
+
refresh: (connectionId) => this.request(
|
|
485
|
+
"POST",
|
|
486
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}/refresh`
|
|
487
|
+
),
|
|
311
488
|
/** Check whether a connection's token is valid. */
|
|
312
|
-
test: (connectionId) => this.request(
|
|
489
|
+
test: (connectionId) => this.request(
|
|
490
|
+
"GET",
|
|
491
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}/test`
|
|
492
|
+
),
|
|
313
493
|
/** Revoke a connection and delete its tokens. */
|
|
314
|
-
revoke: (connectionId) => this.request(
|
|
494
|
+
revoke: (connectionId) => this.request(
|
|
495
|
+
"DELETE",
|
|
496
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}`
|
|
497
|
+
)
|
|
315
498
|
};
|
|
316
499
|
}
|
|
317
500
|
// ── Tool Keys ─────────────────────────────────────────────────────────────
|
|
318
501
|
get toolKeys() {
|
|
319
502
|
return {
|
|
320
|
-
list: (
|
|
321
|
-
const q = new URLSearchParams(filter).toString();
|
|
322
|
-
return this.request("GET", `/v1/tool-keys${q ? `?${q}` : ""}`);
|
|
323
|
-
},
|
|
503
|
+
list: () => this.request("GET", "/v1/tool-keys"),
|
|
324
504
|
create: (params) => this.request("POST", "/v1/tool-keys", params),
|
|
325
|
-
|
|
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
|
+
)
|
|
326
533
|
};
|
|
327
534
|
}
|
|
328
535
|
// ── Tool Permissions ──────────────────────────────────────────────────────
|
|
329
536
|
get toolPermissions() {
|
|
330
537
|
return {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
+
);
|
|
334
560
|
},
|
|
335
561
|
grant: (params) => this.request("POST", "/v1/tool-permissions/grant", params),
|
|
336
|
-
|
|
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
|
+
)
|
|
337
584
|
};
|
|
338
585
|
}
|
|
339
586
|
// ── Skills ────────────────────────────────────────────────────────────────
|
|
@@ -396,7 +643,34 @@ var CommonsClient = class {
|
|
|
396
643
|
me: () => this.request("GET", "/v1/auth/me")
|
|
397
644
|
};
|
|
398
645
|
}
|
|
399
|
-
// ── API
|
|
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
|
+
*/
|
|
400
674
|
get apiKeys() {
|
|
401
675
|
return {
|
|
402
676
|
/**
|
|
@@ -614,6 +888,331 @@ var CommonsClient = class {
|
|
|
614
888
|
getSessionUsage: (sessionId) => this.request("GET", `/v1/usage/sessions/${sessionId}`)
|
|
615
889
|
};
|
|
616
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
|
+
}
|
|
617
1216
|
// ── Credits ──────────────────────────────────────────────────────────────
|
|
618
1217
|
get credits() {
|
|
619
1218
|
return {
|
|
@@ -632,10 +1231,45 @@ var CommonsClient = class {
|
|
|
632
1231
|
const qs = params.toString();
|
|
633
1232
|
return this.request("GET", `/v1/credits/ledger${qs ? `?${qs}` : ""}`);
|
|
634
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),
|
|
635
1239
|
grant: (params) => this.request("POST", "/v1/credits/grants", params),
|
|
636
1240
|
debit: (params) => this.request("POST", "/v1/credits/debits", params)
|
|
637
1241
|
};
|
|
638
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
|
+
}
|
|
639
1273
|
};
|
|
640
1274
|
var CommonsError = class extends Error {
|
|
641
1275
|
constructor(message, status, data) {
|