@agent-commons/sdk 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +230 -0
- package/dist/index.cjs +854 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1307 -106
- package/dist/index.d.ts +1307 -106
- package/dist/index.mjs +854 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +27 -3
package/dist/index.cjs
CHANGED
|
@@ -30,30 +30,95 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
// src/client.ts
|
|
31
31
|
var CommonsClient = class {
|
|
32
32
|
constructor(config) {
|
|
33
|
-
this.baseUrl = (config.baseUrl ?? "https://api.agentcommons.io").replace(
|
|
33
|
+
this.baseUrl = (config.baseUrl ?? "https://api.agentcommons.io").replace(
|
|
34
|
+
/\/$/,
|
|
35
|
+
""
|
|
36
|
+
);
|
|
37
|
+
this.identityUrl = (config.identityUrl ?? "https://auth.agentcommons.io").replace(/\/api\/auth\/?$/, "").replace(/\/$/, "");
|
|
38
|
+
this.identityToken = config.identityToken;
|
|
34
39
|
this.apiKey = config.apiKey;
|
|
35
40
|
this.initiator = config.initiator;
|
|
36
41
|
this._fetch = config.fetch ?? fetch;
|
|
37
42
|
}
|
|
38
43
|
// ── Helpers ───────────────────────────────────────────────────────────────
|
|
39
|
-
headers(extra) {
|
|
40
|
-
const h = {
|
|
44
|
+
headers(extra, json = true) {
|
|
45
|
+
const h = {};
|
|
46
|
+
if (json) h["Content-Type"] = "application/json";
|
|
41
47
|
if (this.apiKey) h["Authorization"] = `Bearer ${this.apiKey}`;
|
|
42
48
|
if (this.initiator) h["x-initiator"] = this.initiator;
|
|
43
49
|
return { ...h, ...extra };
|
|
44
50
|
}
|
|
45
|
-
|
|
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;
|
|
46
57
|
const res = await this._fetch(`${this.baseUrl}${path}`, {
|
|
47
58
|
method,
|
|
48
|
-
headers: this.headers(),
|
|
49
|
-
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
|
|
50
62
|
});
|
|
51
63
|
if (!res.ok) {
|
|
52
|
-
const err = await
|
|
53
|
-
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();
|
|
54
75
|
}
|
|
55
76
|
return res.json();
|
|
56
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
|
+
}
|
|
57
122
|
// ── Models ────────────────────────────────────────────────────────────────
|
|
58
123
|
get models() {
|
|
59
124
|
return {
|
|
@@ -68,12 +133,31 @@ var CommonsClient = class {
|
|
|
68
133
|
list: (owner) => this.request("GET", `/v1/agents${owner ? `?owner=${owner}` : ""}`),
|
|
69
134
|
get: (agentId) => this.request("GET", `/v1/agents/${agentId}`),
|
|
70
135
|
update: (agentId, params) => this.request("PUT", `/v1/agents/${agentId}`, params),
|
|
136
|
+
getRuntime: (agentId) => this.request("GET", `/v1/agents/${agentId}/runtime`),
|
|
137
|
+
configureRuntime: (agentId, params) => this.request("PUT", `/v1/agents/${agentId}/runtime`, params),
|
|
138
|
+
deployRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/deploy`),
|
|
139
|
+
sleepRuntime: (agentId) => this.request("POST", `/v1/agents/${agentId}/runtime/sleep`),
|
|
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
|
+
),
|
|
71
146
|
/** List tools assigned to an agent. */
|
|
72
147
|
listTools: (agentId) => this.request("GET", `/v1/agents/${agentId}/tools`),
|
|
73
148
|
/** Assign a tool to an agent. */
|
|
74
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
|
+
),
|
|
75
156
|
/** Remove a tool assignment from an agent. */
|
|
76
|
-
removeTool: (assignmentId) => this.request(
|
|
157
|
+
removeTool: (assignmentId) => this.request(
|
|
158
|
+
"DELETE",
|
|
159
|
+
`/v1/agents/tools/${encodeURIComponent(assignmentId)}`
|
|
160
|
+
),
|
|
77
161
|
/** Create a liaison agent for an external agent. */
|
|
78
162
|
createLiaison: (params) => this.request("POST", "/v1/liaison", params),
|
|
79
163
|
/**
|
|
@@ -86,6 +170,11 @@ var CommonsClient = class {
|
|
|
86
170
|
* }
|
|
87
171
|
*/
|
|
88
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
|
+
}),
|
|
89
178
|
// ── Heartbeat ─────────────────────────────────────────────────────────
|
|
90
179
|
/** Get the current heartbeat status for an agent. */
|
|
91
180
|
getAutonomy: (agentId) => this.request("GET", `/v1/agents/${agentId}/autonomy`),
|
|
@@ -102,32 +191,100 @@ var CommonsClient = class {
|
|
|
102
191
|
/** Get the knowledgebase entries for an agent. */
|
|
103
192
|
getKnowledgebase: (agentId) => this.request("GET", `/v1/agents/${agentId}/knowledgebase`),
|
|
104
193
|
/** Replace the knowledgebase entries for an agent. */
|
|
105
|
-
updateKnowledgebase: (agentId, knowledgebase) => this.request("PUT", `/v1/agents/${agentId}/knowledgebase`, {
|
|
194
|
+
updateKnowledgebase: (agentId, knowledgebase) => this.request("PUT", `/v1/agents/${agentId}/knowledgebase`, {
|
|
195
|
+
knowledgebase
|
|
196
|
+
}),
|
|
106
197
|
// ── Preferred Connections ────────────────────────────────────────────
|
|
107
198
|
/** List agents that this agent prefers to collaborate with. */
|
|
108
199
|
getPreferredConnections: (agentId) => this.request("GET", `/v1/agents/${agentId}/preferred-connections`),
|
|
109
200
|
/** Add a preferred agent connection. */
|
|
110
|
-
addPreferredConnection: (agentId, params) => this.request(
|
|
201
|
+
addPreferredConnection: (agentId, params) => this.request(
|
|
202
|
+
"POST",
|
|
203
|
+
`/v1/agents/${agentId}/preferred-connections`,
|
|
204
|
+
params
|
|
205
|
+
),
|
|
111
206
|
/** Remove a preferred agent connection by its record ID. */
|
|
112
207
|
removePreferredConnection: (id) => this.request("DELETE", `/v1/agents/preferred-connections/${id}`),
|
|
113
208
|
// ── Computers ────────────────────────────────────────────────────────
|
|
114
209
|
getComputerConfig: (agentId) => this.request("GET", `/v1/agents/${agentId}/computer/config`),
|
|
115
210
|
updateComputerConfig: (agentId, params) => this.request("PUT", `/v1/agents/${agentId}/computer/config`, params),
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
211
|
+
/** Get the agent's one persistent cloud computer. */
|
|
212
|
+
getComputer: (agentId, _legacyComputerId) => this.request("GET", `/v1/agents/${agentId}/computer`),
|
|
213
|
+
/** Wake the agent's persistent cloud computer, provisioning it if needed. */
|
|
214
|
+
wakeComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/wake`, params),
|
|
215
|
+
/** Sleep the runtime while preserving the computer's durable workspace. */
|
|
216
|
+
sleepComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/sleep`, params),
|
|
217
|
+
/** Replace the runtime without replacing the persistent computer. */
|
|
218
|
+
restartComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/restart`, params),
|
|
219
|
+
resizeComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/resize`, params),
|
|
220
|
+
execComputer: (agentId, params) => this.request("POST", `/v1/agents/${agentId}/computer/exec`, params),
|
|
221
|
+
readComputerFile: (agentId, pathOrLegacyComputerId, legacyPath) => {
|
|
222
|
+
const path = legacyPath ?? pathOrLegacyComputerId;
|
|
223
|
+
return this.request(
|
|
224
|
+
"GET",
|
|
225
|
+
`/v1/agents/${agentId}/computer/files/read?path=${encodeURIComponent(path)}`
|
|
226
|
+
);
|
|
227
|
+
},
|
|
228
|
+
writeComputerFile: (agentId, params) => this.request(
|
|
229
|
+
"POST",
|
|
230
|
+
`/v1/agents/${encodeURIComponent(agentId)}/computer/files/write`,
|
|
231
|
+
params
|
|
232
|
+
),
|
|
233
|
+
openComputerBrowser: (agentId, paramsOrLegacyComputerId, legacyParams) => {
|
|
234
|
+
const params = typeof paramsOrLegacyComputerId === "string" ? legacyParams : paramsOrLegacyComputerId;
|
|
235
|
+
if (!params) {
|
|
236
|
+
return Promise.reject(new TypeError("Browser options are required."));
|
|
237
|
+
}
|
|
238
|
+
return this.request(
|
|
239
|
+
"POST",
|
|
240
|
+
`/v1/agents/${agentId}/computer/browser/open`,
|
|
241
|
+
params
|
|
242
|
+
);
|
|
243
|
+
},
|
|
244
|
+
testComputerBrowser: (agentId) => this.request(
|
|
245
|
+
"POST",
|
|
246
|
+
`/v1/agents/${encodeURIComponent(agentId)}/computer/browser/test`,
|
|
247
|
+
{}
|
|
248
|
+
),
|
|
249
|
+
listComputerEvents: (agentId, limitOrLegacyComputerId, legacyLimit) => {
|
|
250
|
+
const limit = typeof limitOrLegacyComputerId === "number" ? limitOrLegacyComputerId : legacyLimit;
|
|
251
|
+
return this.request(
|
|
252
|
+
"GET",
|
|
253
|
+
`/v1/agents/${agentId}/computer/events${limit ? `?limit=${limit}` : ""}`
|
|
254
|
+
);
|
|
255
|
+
},
|
|
256
|
+
// ── Deprecated per-instance compatibility ────────────────────────────
|
|
257
|
+
/** @deprecated Use getComputer. The singleton is returned as a one-item list. */
|
|
258
|
+
listComputers: (agentId, _filter) => {
|
|
259
|
+
return this.request(
|
|
260
|
+
"GET",
|
|
261
|
+
`/v1/agents/${agentId}/computer`
|
|
262
|
+
).then(({ data }) => ({
|
|
263
|
+
data: data ? [data] : []
|
|
264
|
+
}));
|
|
265
|
+
},
|
|
266
|
+
/** @deprecated Use wakeComputer. Lifecycle, name, and session are ignored. */
|
|
267
|
+
startComputer: (agentId, params) => this.request(
|
|
268
|
+
"POST",
|
|
269
|
+
`/v1/agents/${agentId}/computer/wake`,
|
|
270
|
+
params?.reason ? { reason: params.reason } : void 0
|
|
271
|
+
),
|
|
272
|
+
/** @deprecated Use getComputer. Computer IDs are ignored. */
|
|
273
|
+
refreshComputer: (agentId, _computerId) => this.request("GET", `/v1/agents/${agentId}/computer`),
|
|
274
|
+
/** @deprecated Use sleepComputer. Computer IDs are ignored. */
|
|
275
|
+
stopComputer: (agentId, _computerId) => this.request("POST", `/v1/agents/${agentId}/computer/sleep`),
|
|
276
|
+
/** @deprecated Use execComputer. Computer IDs are ignored. */
|
|
277
|
+
runComputerCommand: (agentId, paramsOrLegacyComputerId, legacyParams) => {
|
|
278
|
+
const params = typeof paramsOrLegacyComputerId === "string" ? legacyParams : paramsOrLegacyComputerId;
|
|
279
|
+
if (!params) {
|
|
280
|
+
return Promise.reject(new TypeError("Command options are required."));
|
|
281
|
+
}
|
|
282
|
+
return this.request(
|
|
283
|
+
"POST",
|
|
284
|
+
`/v1/agents/${agentId}/computer/exec`,
|
|
285
|
+
params
|
|
286
|
+
);
|
|
287
|
+
},
|
|
131
288
|
// ── TTS Voices ───────────────────────────────────────────────────────
|
|
132
289
|
/**
|
|
133
290
|
* List available TTS voices for a provider.
|
|
@@ -139,10 +296,33 @@ var CommonsClient = class {
|
|
|
139
296
|
if (provider) params.set("provider", provider);
|
|
140
297
|
if (q) params.set("q", q);
|
|
141
298
|
const qs = params.toString();
|
|
142
|
-
return this.request(
|
|
299
|
+
return this.request(
|
|
300
|
+
"GET",
|
|
301
|
+
`/v1/agents/tts/voices${qs ? `?${qs}` : ""}`
|
|
302
|
+
);
|
|
143
303
|
}
|
|
144
304
|
};
|
|
145
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
|
+
}
|
|
146
326
|
// ── Run (non-streaming) ───────────────────────────────────────────────────
|
|
147
327
|
get run() {
|
|
148
328
|
return {
|
|
@@ -153,20 +333,78 @@ var CommonsClient = class {
|
|
|
153
333
|
get workflows() {
|
|
154
334
|
return {
|
|
155
335
|
create: (params) => this.request("POST", "/v1/workflows", params),
|
|
156
|
-
list: (ownerId, ownerType) => this.request(
|
|
336
|
+
list: (ownerId, ownerType) => this.request(
|
|
337
|
+
"GET",
|
|
338
|
+
`/v1/workflows?ownerId=${ownerId}&ownerType=${ownerType}`
|
|
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
|
+
},
|
|
157
350
|
get: (workflowId) => this.request("GET", `/v1/workflows/${workflowId}`),
|
|
158
351
|
update: (workflowId, updates) => this.request("PUT", `/v1/workflows/${workflowId}`, updates),
|
|
159
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
|
+
},
|
|
160
379
|
execute: (workflowId, params) => this.request("POST", `/v1/workflows/${workflowId}/execute`, params),
|
|
161
|
-
getExecution: (workflowId, executionId) => this.request(
|
|
162
|
-
|
|
163
|
-
|
|
380
|
+
getExecution: (workflowId, executionId) => this.request(
|
|
381
|
+
"GET",
|
|
382
|
+
`/v1/workflows/${workflowId}/executions/${executionId}`
|
|
383
|
+
),
|
|
384
|
+
listExecutions: (workflowId, limit) => this.request(
|
|
385
|
+
"GET",
|
|
386
|
+
`/v1/workflows/${workflowId}/executions${limit ? `?limit=${limit}` : ""}`
|
|
387
|
+
),
|
|
388
|
+
cancelExecution: (workflowId, executionId) => this.request(
|
|
389
|
+
"POST",
|
|
390
|
+
`/v1/workflows/${workflowId}/executions/${executionId}/cancel`
|
|
391
|
+
),
|
|
164
392
|
/** Approve a paused human_approval node and resume execution. */
|
|
165
|
-
approveExecution: (workflowId, executionId, params) => this.request(
|
|
393
|
+
approveExecution: (workflowId, executionId, params) => this.request(
|
|
394
|
+
"POST",
|
|
395
|
+
`/v1/workflows/${workflowId}/executions/${executionId}/approve`,
|
|
396
|
+
params
|
|
397
|
+
),
|
|
166
398
|
/** Reject a paused human_approval node and terminate execution. */
|
|
167
|
-
rejectExecution: (workflowId, executionId, params) => this.request(
|
|
399
|
+
rejectExecution: (workflowId, executionId, params) => this.request(
|
|
400
|
+
"POST",
|
|
401
|
+
`/v1/workflows/${workflowId}/executions/${executionId}/reject`,
|
|
402
|
+
params
|
|
403
|
+
),
|
|
168
404
|
/** Stream execution progress via SSE. Returns an async generator. */
|
|
169
|
-
stream: (workflowId, executionId) => this._streamSse(
|
|
405
|
+
stream: (workflowId, executionId) => this._streamSse(
|
|
406
|
+
`/v1/workflows/${workflowId}/executions/${executionId}/stream`
|
|
407
|
+
)
|
|
170
408
|
};
|
|
171
409
|
}
|
|
172
410
|
// ── Tasks ─────────────────────────────────────────────────────────────────
|
|
@@ -196,11 +434,30 @@ var CommonsClient = class {
|
|
|
196
434
|
/** List all sessions for a given agent (all initiators). */
|
|
197
435
|
listByAgent: (agentId) => this.request("GET", `/v1/sessions/agent/${agentId}`),
|
|
198
436
|
/** List all sessions for a user across all agents. */
|
|
199
|
-
listByUser: (initiator) => this.request(
|
|
437
|
+
listByUser: (initiator) => this.request(
|
|
438
|
+
"GET",
|
|
439
|
+
`/v1/sessions/user/${encodeURIComponent(initiator)}`
|
|
440
|
+
),
|
|
200
441
|
create: (params) => this.request("POST", "/v1/sessions", params),
|
|
201
442
|
get: (sessionId) => this.request("GET", `/v1/sessions/${sessionId}`),
|
|
202
443
|
/** Get full session with history, tasks, childSessions, and spaces. */
|
|
203
|
-
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
|
+
)
|
|
204
461
|
};
|
|
205
462
|
}
|
|
206
463
|
// ── Tools ─────────────────────────────────────────────────────────────────
|
|
@@ -218,26 +475,141 @@ var CommonsClient = class {
|
|
|
218
475
|
listStatic: () => this.request("GET", "/v1/tools/static")
|
|
219
476
|
};
|
|
220
477
|
}
|
|
478
|
+
// ── OAuth Connections ─────────────────────────────────────────────────────
|
|
479
|
+
get oauth() {
|
|
480
|
+
return {
|
|
481
|
+
/** List OAuth providers available on the platform (Google Workspace, GitHub, …). */
|
|
482
|
+
listProviders: () => this.request("GET", "/v1/oauth/providers"),
|
|
483
|
+
/** Get one provider's details, including its scope groups. */
|
|
484
|
+
getProvider: (providerKey) => this.request(
|
|
485
|
+
"GET",
|
|
486
|
+
`/v1/oauth/providers/${encodeURIComponent(providerKey)}`
|
|
487
|
+
),
|
|
488
|
+
/**
|
|
489
|
+
* List the caller's OAuth connections (the accounts agents act with).
|
|
490
|
+
* `ownerId` is only needed when authenticating with a management key.
|
|
491
|
+
*/
|
|
492
|
+
listConnections: (params) => {
|
|
493
|
+
const q = params ? new URLSearchParams(params).toString() : "";
|
|
494
|
+
return this.request("GET", `/v1/oauth/connections${q ? `?${q}` : ""}`);
|
|
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
|
+
),
|
|
507
|
+
/**
|
|
508
|
+
* Start an OAuth connect flow. Returns the authorization URL the user
|
|
509
|
+
* must open in a browser to grant access.
|
|
510
|
+
*/
|
|
511
|
+
connect: (params) => this.request("POST", "/v1/oauth/connect", params),
|
|
512
|
+
/** Refresh a connection's access token now. */
|
|
513
|
+
refresh: (connectionId) => this.request(
|
|
514
|
+
"POST",
|
|
515
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}/refresh`
|
|
516
|
+
),
|
|
517
|
+
/** Check whether a connection's token is valid. */
|
|
518
|
+
test: (connectionId) => this.request(
|
|
519
|
+
"GET",
|
|
520
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}/test`
|
|
521
|
+
),
|
|
522
|
+
/** Revoke a connection and delete its tokens. */
|
|
523
|
+
revoke: (connectionId) => this.request(
|
|
524
|
+
"DELETE",
|
|
525
|
+
`/v1/oauth/connections/${encodeURIComponent(connectionId)}`
|
|
526
|
+
)
|
|
527
|
+
};
|
|
528
|
+
}
|
|
221
529
|
// ── Tool Keys ─────────────────────────────────────────────────────────────
|
|
222
530
|
get toolKeys() {
|
|
223
531
|
return {
|
|
224
|
-
list: (
|
|
225
|
-
const q = new URLSearchParams(filter).toString();
|
|
226
|
-
return this.request("GET", `/v1/tool-keys${q ? `?${q}` : ""}`);
|
|
227
|
-
},
|
|
532
|
+
list: () => this.request("GET", "/v1/tool-keys"),
|
|
228
533
|
create: (params) => this.request("POST", "/v1/tool-keys", params),
|
|
229
|
-
|
|
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
|
+
)
|
|
230
562
|
};
|
|
231
563
|
}
|
|
232
564
|
// ── Tool Permissions ──────────────────────────────────────────────────────
|
|
233
565
|
get toolPermissions() {
|
|
234
566
|
return {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
+
);
|
|
238
589
|
},
|
|
239
590
|
grant: (params) => this.request("POST", "/v1/tool-permissions/grant", params),
|
|
240
|
-
|
|
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
|
+
)
|
|
241
613
|
};
|
|
242
614
|
}
|
|
243
615
|
// ── Skills ────────────────────────────────────────────────────────────────
|
|
@@ -247,7 +619,8 @@ var CommonsClient = class {
|
|
|
247
619
|
const params = new URLSearchParams();
|
|
248
620
|
if (filter?.ownerId) params.set("ownerId", filter.ownerId);
|
|
249
621
|
if (filter?.ownerType) params.set("ownerType", filter.ownerType);
|
|
250
|
-
if (filter?.isPublic !== void 0)
|
|
622
|
+
if (filter?.isPublic !== void 0)
|
|
623
|
+
params.set("isPublic", String(filter.isPublic));
|
|
251
624
|
const qs = params.toString();
|
|
252
625
|
return this.request("GET", `/v1/skills${qs ? `?${qs}` : ""}`);
|
|
253
626
|
},
|
|
@@ -299,7 +672,34 @@ var CommonsClient = class {
|
|
|
299
672
|
me: () => this.request("GET", "/v1/auth/me")
|
|
300
673
|
};
|
|
301
674
|
}
|
|
302
|
-
// ── 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
|
+
*/
|
|
303
703
|
get apiKeys() {
|
|
304
704
|
return {
|
|
305
705
|
/**
|
|
@@ -309,7 +709,10 @@ var CommonsClient = class {
|
|
|
309
709
|
create: (params) => this.request("POST", "/v1/auth/api-keys", params),
|
|
310
710
|
/** List all active API keys for a principal (key values not included). */
|
|
311
711
|
list: (principalId, principalType) => {
|
|
312
|
-
const q = new URLSearchParams({
|
|
712
|
+
const q = new URLSearchParams({
|
|
713
|
+
principalId,
|
|
714
|
+
principalType
|
|
715
|
+
}).toString();
|
|
313
716
|
return this.request("GET", `/v1/auth/api-keys?${q}`);
|
|
314
717
|
},
|
|
315
718
|
/** Revoke (soft-delete) an API key by its UUID. */
|
|
@@ -392,7 +795,10 @@ var CommonsClient = class {
|
|
|
392
795
|
params: { id: taskId }
|
|
393
796
|
}).then((r) => r.result),
|
|
394
797
|
/** List recent A2A tasks for an agent. */
|
|
395
|
-
listTasks: (agentId, limit) => this.request(
|
|
798
|
+
listTasks: (agentId, limit) => this.request(
|
|
799
|
+
"GET",
|
|
800
|
+
`/v1/a2a/${agentId}/tasks${limit ? `?limit=${limit}` : ""}`
|
|
801
|
+
),
|
|
396
802
|
/** Stream A2A task updates (SSE). */
|
|
397
803
|
stream: (agentId, taskId) => this._streamSse(`/v1/a2a/${agentId}/tasks/${taskId}/stream`)
|
|
398
804
|
};
|
|
@@ -401,11 +807,18 @@ var CommonsClient = class {
|
|
|
401
807
|
get mcp() {
|
|
402
808
|
return {
|
|
403
809
|
/** List MCP servers for an owner. */
|
|
404
|
-
listServers: (ownerId, ownerType) => this.request(
|
|
810
|
+
listServers: (ownerId, ownerType) => this.request(
|
|
811
|
+
"GET",
|
|
812
|
+
`/v1/mcp/servers?ownerId=${ownerId}&ownerType=${ownerType}`
|
|
813
|
+
),
|
|
405
814
|
/** Create a new MCP server. */
|
|
406
815
|
createServer: (params) => {
|
|
407
816
|
const { ownerId, ownerType, ...dto } = params;
|
|
408
|
-
return this.request(
|
|
817
|
+
return this.request(
|
|
818
|
+
"POST",
|
|
819
|
+
`/v1/mcp/servers?ownerId=${ownerId}&ownerType=${ownerType}`,
|
|
820
|
+
dto
|
|
821
|
+
);
|
|
409
822
|
},
|
|
410
823
|
/** Get MCP server by ID. */
|
|
411
824
|
getServer: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}`),
|
|
@@ -426,15 +839,25 @@ var CommonsClient = class {
|
|
|
426
839
|
/** List tools discovered from an MCP server. */
|
|
427
840
|
listTools: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}/tools`),
|
|
428
841
|
/** List all MCP tools across all servers for a given owner. */
|
|
429
|
-
listToolsByOwner: (ownerId, ownerType) => this.request(
|
|
842
|
+
listToolsByOwner: (ownerId, ownerType) => this.request(
|
|
843
|
+
"GET",
|
|
844
|
+
`/v1/mcp/tools?ownerId=${ownerId}&ownerType=${ownerType}`
|
|
845
|
+
),
|
|
430
846
|
/** List resources from an MCP server. */
|
|
431
847
|
listResources: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}/resources`),
|
|
432
848
|
/** Read a resource by URI. */
|
|
433
|
-
readResource: (serverId, uri) => this.request(
|
|
849
|
+
readResource: (serverId, uri) => this.request(
|
|
850
|
+
"GET",
|
|
851
|
+
`/v1/mcp/servers/${serverId}/resources/read?uri=${encodeURIComponent(uri)}`
|
|
852
|
+
),
|
|
434
853
|
/** List prompts from an MCP server. */
|
|
435
854
|
listPrompts: (serverId) => this.request("GET", `/v1/mcp/servers/${serverId}/prompts`),
|
|
436
855
|
/** Render a prompt with arguments. */
|
|
437
|
-
getPrompt: (serverId, promptName, args) => this.request(
|
|
856
|
+
getPrompt: (serverId, promptName, args) => this.request(
|
|
857
|
+
"POST",
|
|
858
|
+
`/v1/mcp/servers/${serverId}/prompts/${promptName}`,
|
|
859
|
+
{ arguments: args }
|
|
860
|
+
)
|
|
438
861
|
};
|
|
439
862
|
}
|
|
440
863
|
// ── Memory ────────────────────────────────────────────────────────────────
|
|
@@ -446,7 +869,10 @@ var CommonsClient = class {
|
|
|
446
869
|
if (opts?.type) params.set("type", opts.type);
|
|
447
870
|
if (opts?.limit) params.set("limit", String(opts.limit));
|
|
448
871
|
const qs = params.toString();
|
|
449
|
-
return this.request(
|
|
872
|
+
return this.request(
|
|
873
|
+
"GET",
|
|
874
|
+
`/v1/memory/agents/${agentId}${qs ? `?${qs}` : ""}`
|
|
875
|
+
);
|
|
450
876
|
},
|
|
451
877
|
/** Get memory stats for an agent. */
|
|
452
878
|
stats: (agentId) => this.request("GET", `/v1/memory/agents/${agentId}/stats`),
|
|
@@ -454,7 +880,10 @@ var CommonsClient = class {
|
|
|
454
880
|
retrieve: (agentId, query, limit) => {
|
|
455
881
|
const params = new URLSearchParams({ q: query });
|
|
456
882
|
if (limit) params.set("limit", String(limit));
|
|
457
|
-
return this.request(
|
|
883
|
+
return this.request(
|
|
884
|
+
"GET",
|
|
885
|
+
`/v1/memory/agents/${agentId}/retrieve?${params}`
|
|
886
|
+
);
|
|
458
887
|
},
|
|
459
888
|
/** Get a single memory by ID. */
|
|
460
889
|
get: (memoryId) => this.request("GET", `/v1/memory/${memoryId}`),
|
|
@@ -463,7 +892,11 @@ var CommonsClient = class {
|
|
|
463
892
|
/** Update a memory. */
|
|
464
893
|
update: (memoryId, params) => this.request("PATCH", `/v1/memory/${memoryId}`, params),
|
|
465
894
|
/** Soft-delete (deactivate) a memory. */
|
|
466
|
-
delete: (memoryId) => this.request("DELETE", `/v1/memory/${memoryId}`)
|
|
895
|
+
delete: (memoryId) => this.request("DELETE", `/v1/memory/${memoryId}`),
|
|
896
|
+
/** Create an append-only memory scope shared by a set of owned agents. */
|
|
897
|
+
createSharedScope: (params) => this.request("POST", "/v1/memory/shared-scopes", params),
|
|
898
|
+
/** List shared-memory scopes available to an agent. */
|
|
899
|
+
listSharedScopes: (agentId) => this.request("GET", `/v1/memory/shared-scopes/agents/${agentId}`)
|
|
467
900
|
};
|
|
468
901
|
}
|
|
469
902
|
// ── Usage / Observability ─────────────────────────────────────────────────
|
|
@@ -475,12 +908,340 @@ var CommonsClient = class {
|
|
|
475
908
|
if (opts?.from) params.set("from", opts.from);
|
|
476
909
|
if (opts?.to) params.set("to", opts.to);
|
|
477
910
|
const qs = params.toString();
|
|
478
|
-
return this.request(
|
|
911
|
+
return this.request(
|
|
912
|
+
"GET",
|
|
913
|
+
`/v1/usage/agents/${agentId}${qs ? `?${qs}` : ""}`
|
|
914
|
+
);
|
|
479
915
|
},
|
|
480
916
|
/** Get aggregated token + cost usage for a session. */
|
|
481
917
|
getSessionUsage: (sessionId) => this.request("GET", `/v1/usage/sessions/${sessionId}`)
|
|
482
918
|
};
|
|
483
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
|
+
}
|
|
484
1245
|
// ── Credits ──────────────────────────────────────────────────────────────
|
|
485
1246
|
get credits() {
|
|
486
1247
|
return {
|
|
@@ -499,10 +1260,45 @@ var CommonsClient = class {
|
|
|
499
1260
|
const qs = params.toString();
|
|
500
1261
|
return this.request("GET", `/v1/credits/ledger${qs ? `?${qs}` : ""}`);
|
|
501
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),
|
|
502
1268
|
grant: (params) => this.request("POST", "/v1/credits/grants", params),
|
|
503
1269
|
debit: (params) => this.request("POST", "/v1/credits/debits", params)
|
|
504
1270
|
};
|
|
505
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
|
+
}
|
|
506
1302
|
};
|
|
507
1303
|
var CommonsError = class extends Error {
|
|
508
1304
|
constructor(message, status, data) {
|