@actwith-ai/sdk 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +852 -189
- package/dist/index.d.ts +852 -189
- package/dist/index.js +637 -115
- package/dist/index.mjs +635 -113
- package/package.json +23 -6
package/dist/index.js
CHANGED
|
@@ -20,23 +20,25 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
ActwithClient: () => ActwithClient,
|
|
24
|
+
ActwithError: () => ActwithError
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
28
|
// src/client.ts
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.
|
|
29
|
+
var DEFAULT_API_URL = "https://actwith-api.scott-277.workers.dev";
|
|
30
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
31
|
+
var ActwithClient = class {
|
|
32
|
+
constructor(config) {
|
|
33
|
+
this.apiKey = config.apiKey;
|
|
34
|
+
this.apiUrl = config.apiUrl ?? DEFAULT_API_URL;
|
|
35
|
+
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
34
36
|
}
|
|
35
37
|
async request(method, path, body) {
|
|
36
38
|
const controller = new AbortController();
|
|
37
39
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
38
40
|
try {
|
|
39
|
-
const response = await fetch(`${this.
|
|
41
|
+
const response = await fetch(`${this.apiUrl}${path}`, {
|
|
40
42
|
method,
|
|
41
43
|
headers: {
|
|
42
44
|
Authorization: `Bearer ${this.apiKey}`,
|
|
@@ -47,7 +49,7 @@ var RtypeClient = class {
|
|
|
47
49
|
});
|
|
48
50
|
const data = await response.json();
|
|
49
51
|
if (!data.success) {
|
|
50
|
-
throw new
|
|
52
|
+
throw new ActwithError(
|
|
51
53
|
data.error?.code ?? "UNKNOWN_ERROR",
|
|
52
54
|
data.error?.message ?? "Unknown error"
|
|
53
55
|
);
|
|
@@ -57,165 +59,685 @@ var RtypeClient = class {
|
|
|
57
59
|
clearTimeout(timeoutId);
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
+
// ============================================================================
|
|
63
|
+
// Auth
|
|
64
|
+
// ============================================================================
|
|
65
|
+
async getMe() {
|
|
62
66
|
return this.request("GET", "/v1/auth/me");
|
|
63
67
|
}
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
// ============================================================================
|
|
69
|
+
// Spaces
|
|
70
|
+
// ============================================================================
|
|
71
|
+
async getSpaces() {
|
|
72
|
+
return this.request("GET", "/v1/contexts");
|
|
67
73
|
}
|
|
68
|
-
async
|
|
69
|
-
|
|
74
|
+
async getSpaceInfo(spaceId) {
|
|
75
|
+
try {
|
|
76
|
+
return await this.request("GET", `/v1/contexts/${spaceId}`);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
if (err instanceof ActwithError && err.code === "NOT_FOUND") return null;
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
70
81
|
}
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Memory
|
|
84
|
+
// ============================================================================
|
|
85
|
+
async memorySet(contextId, agentId, key, value, visibility = "private") {
|
|
86
|
+
return this.request("POST", "/v1/memory", {
|
|
87
|
+
contextId,
|
|
88
|
+
agentId,
|
|
89
|
+
key,
|
|
90
|
+
value,
|
|
91
|
+
visibility
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async memoryGet(contextId, agentId, key) {
|
|
95
|
+
const params = new URLSearchParams({
|
|
96
|
+
context: contextId,
|
|
97
|
+
agent: agentId,
|
|
98
|
+
key
|
|
99
|
+
});
|
|
100
|
+
try {
|
|
101
|
+
return await this.request("GET", `/v1/memory?${params}`);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
if (err instanceof ActwithError && err.code === "NOT_FOUND") return null;
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
73
106
|
}
|
|
74
|
-
async
|
|
75
|
-
|
|
107
|
+
async memoryList(contextId, scope = "self", prefix) {
|
|
108
|
+
const params = new URLSearchParams({ context: contextId, scope });
|
|
109
|
+
if (prefix) params.set("prefix", prefix);
|
|
110
|
+
return this.request("GET", `/v1/memory/list?${params}`);
|
|
111
|
+
}
|
|
112
|
+
async memoryDelete(contextId, agentId, key) {
|
|
113
|
+
const params = new URLSearchParams({
|
|
114
|
+
context: contextId,
|
|
115
|
+
agent: agentId,
|
|
116
|
+
key
|
|
117
|
+
});
|
|
118
|
+
await this.request("DELETE", `/v1/memory?${params}`);
|
|
119
|
+
}
|
|
120
|
+
// ============================================================================
|
|
121
|
+
// Tasks
|
|
122
|
+
// ============================================================================
|
|
123
|
+
async taskCreate(options) {
|
|
124
|
+
return this.request("POST", "/v1/tasks", options);
|
|
76
125
|
}
|
|
77
|
-
async
|
|
78
|
-
|
|
126
|
+
async taskList(contextId, status) {
|
|
127
|
+
const params = new URLSearchParams({ context: contextId });
|
|
128
|
+
if (status) params.set("status", status);
|
|
129
|
+
return this.request("GET", `/v1/tasks?${params}`);
|
|
79
130
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
131
|
+
async taskGet(taskId) {
|
|
132
|
+
try {
|
|
133
|
+
return await this.request("GET", `/v1/tasks/${taskId}`);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
if (err instanceof ActwithError && err.code === "NOT_FOUND") return null;
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
86
138
|
}
|
|
87
|
-
async
|
|
88
|
-
|
|
139
|
+
async taskClaim(taskId, agentId) {
|
|
140
|
+
await this.request("POST", `/v1/tasks/${taskId}/claim`, { agentId });
|
|
141
|
+
}
|
|
142
|
+
async taskComplete(taskId, response, artifact) {
|
|
143
|
+
return this.request("POST", `/v1/tasks/${taskId}/complete`, {
|
|
144
|
+
response,
|
|
145
|
+
artifact
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async taskApprove(taskId, rating, feedback) {
|
|
149
|
+
return this.request("POST", `/v1/tasks/${taskId}/approve`, {
|
|
150
|
+
rating,
|
|
151
|
+
feedback
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async taskReject(taskId, reason) {
|
|
155
|
+
await this.request("POST", `/v1/tasks/${taskId}/reject`, { reason });
|
|
156
|
+
}
|
|
157
|
+
async taskPause(taskId) {
|
|
158
|
+
return this.request("POST", `/v1/tasks/${taskId}/pause`);
|
|
159
|
+
}
|
|
160
|
+
async taskCancel(taskId) {
|
|
161
|
+
return this.request("DELETE", `/v1/tasks/${taskId}`);
|
|
162
|
+
}
|
|
163
|
+
// ============================================================================
|
|
164
|
+
// Task Handoff
|
|
165
|
+
// ============================================================================
|
|
166
|
+
async taskHandoff(taskId, params) {
|
|
167
|
+
return this.request("POST", `/v1/tasks/${taskId}/handoff`, params);
|
|
168
|
+
}
|
|
169
|
+
async taskGetHandoffs(taskId) {
|
|
170
|
+
return this.request("GET", `/v1/tasks/${taskId}/handoffs`);
|
|
171
|
+
}
|
|
172
|
+
// ============================================================================
|
|
173
|
+
// Routines (Standing Tasks)
|
|
174
|
+
// ============================================================================
|
|
175
|
+
async routineList(contextId, status) {
|
|
176
|
+
const params = new URLSearchParams({ context: contextId });
|
|
177
|
+
if (status) params.set("status", status);
|
|
178
|
+
const raw = await this.request("GET", `/v1/standing-tasks?${params}`);
|
|
179
|
+
return raw.map((t) => ({
|
|
180
|
+
id: t.id,
|
|
181
|
+
name: t.name,
|
|
182
|
+
description: t.description,
|
|
183
|
+
scheduleType: t.schedule.type,
|
|
184
|
+
scheduleCron: t.schedule.cron,
|
|
185
|
+
payment: t.payment,
|
|
186
|
+
status: t.status,
|
|
187
|
+
totalRuns: t.stats.totalRuns,
|
|
188
|
+
totalInsights: t.stats.totalInsights,
|
|
189
|
+
nextRunAt: t.schedule.nextRunAt
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
async routineGet(taskId) {
|
|
193
|
+
try {
|
|
194
|
+
return await this.request("GET", `/v1/standing-tasks/${taskId}`);
|
|
195
|
+
} catch (err) {
|
|
196
|
+
if (err instanceof ActwithError && err.code === "NOT_FOUND") return null;
|
|
197
|
+
throw err;
|
|
198
|
+
}
|
|
89
199
|
}
|
|
90
|
-
async
|
|
91
|
-
return this.request("POST",
|
|
200
|
+
async routineClaim(taskId, agentId) {
|
|
201
|
+
return this.request("POST", `/v1/standing-tasks/${taskId}/claim`, {
|
|
202
|
+
agentId
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
async insightSubmit(params) {
|
|
206
|
+
const { taskId, ...body } = params;
|
|
207
|
+
return this.request("POST", `/v1/standing-tasks/${taskId}/insights`, body);
|
|
208
|
+
}
|
|
209
|
+
async insightsList(taskId, options) {
|
|
210
|
+
const params = new URLSearchParams();
|
|
211
|
+
if (options?.type) params.set("type", options.type);
|
|
212
|
+
if (options?.since) params.set("since", String(options.since));
|
|
213
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
214
|
+
return this.request(
|
|
215
|
+
"GET",
|
|
216
|
+
`/v1/standing-tasks/${taskId}/insights?${params}`
|
|
217
|
+
);
|
|
92
218
|
}
|
|
93
|
-
|
|
94
|
-
|
|
219
|
+
// ============================================================================
|
|
220
|
+
// Activity Feed
|
|
221
|
+
// ============================================================================
|
|
222
|
+
async activityFeed(contextId, agentId, since) {
|
|
223
|
+
const allTasks = await this.taskList(contextId);
|
|
224
|
+
const openTasks = allTasks.filter((t) => t.status === "open");
|
|
225
|
+
const myClaimedTasks = allTasks.filter(
|
|
226
|
+
(t) => t.status === "claimed" && t.claimedBy === agentId
|
|
227
|
+
);
|
|
228
|
+
const standingTasks = await this.routineList(contextId, "active");
|
|
229
|
+
let balance = 0;
|
|
230
|
+
try {
|
|
231
|
+
const wallet = await this.getBalance();
|
|
232
|
+
balance = wallet.balance;
|
|
233
|
+
} catch {
|
|
234
|
+
}
|
|
235
|
+
const recentInsights = [];
|
|
236
|
+
for (const st of standingTasks.slice(0, 5)) {
|
|
237
|
+
try {
|
|
238
|
+
const insights = await this.insightsList(st.id, {
|
|
239
|
+
since: since || Math.floor(Date.now() / 1e3) - 86400,
|
|
240
|
+
limit: 5
|
|
241
|
+
});
|
|
242
|
+
for (const ins of insights) {
|
|
243
|
+
recentInsights.push({
|
|
244
|
+
id: ins.id,
|
|
245
|
+
title: ins.title,
|
|
246
|
+
severity: ins.severity,
|
|
247
|
+
taskName: st.name,
|
|
248
|
+
createdAt: ins.createdAt
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
recentInsights.sort((a, b) => b.createdAt - a.createdAt);
|
|
255
|
+
return {
|
|
256
|
+
tasks: {
|
|
257
|
+
open: openTasks.length,
|
|
258
|
+
claimedByMe: myClaimedTasks.length,
|
|
259
|
+
recent: allTasks.slice(0, 10).map((t) => ({
|
|
260
|
+
id: t.id,
|
|
261
|
+
description: t.description.substring(0, 100),
|
|
262
|
+
status: t.status,
|
|
263
|
+
bounty: t.bounty
|
|
264
|
+
}))
|
|
265
|
+
},
|
|
266
|
+
standingTasks: {
|
|
267
|
+
active: standingTasks.length,
|
|
268
|
+
assignedToMe: 0,
|
|
269
|
+
recentInsights: recentInsights.slice(0, 10)
|
|
270
|
+
},
|
|
271
|
+
wallet: { balance }
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
// ============================================================================
|
|
275
|
+
// Topics
|
|
276
|
+
// ============================================================================
|
|
277
|
+
async topicPublish(contextId, topic, data, metadata) {
|
|
278
|
+
return this.request("POST", "/v1/topics/publish", {
|
|
279
|
+
contextId,
|
|
280
|
+
topic,
|
|
281
|
+
data,
|
|
282
|
+
metadata
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
async topicHistory(contextId, topic, options) {
|
|
286
|
+
const params = new URLSearchParams({
|
|
287
|
+
context: contextId,
|
|
288
|
+
topic,
|
|
289
|
+
limit: String(options?.limit ?? 50)
|
|
290
|
+
});
|
|
291
|
+
if (options?.correlationId)
|
|
292
|
+
params.set("correlationId", options.correlationId);
|
|
293
|
+
if (options?.replyTo) params.set("replyTo", options.replyTo);
|
|
294
|
+
if (options?.since) params.set("since", String(options.since));
|
|
295
|
+
return this.request("GET", `/v1/topics/messages?${params}`);
|
|
95
296
|
}
|
|
96
|
-
|
|
97
|
-
|
|
297
|
+
// ============================================================================
|
|
298
|
+
// Public Topics
|
|
299
|
+
// ============================================================================
|
|
300
|
+
async discoverTopics(options) {
|
|
301
|
+
const params = new URLSearchParams();
|
|
302
|
+
if (options?.category) params.set("category", options.category);
|
|
303
|
+
if (options?.sort) params.set("sort", options.sort);
|
|
304
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
305
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
306
|
+
return this.request("GET", `/v1/directory/topics?${params}`);
|
|
98
307
|
}
|
|
99
|
-
async
|
|
100
|
-
|
|
308
|
+
async getPublicTopic(slugOrId) {
|
|
309
|
+
try {
|
|
310
|
+
return await this.request("GET", `/v1/directory/topics/${slugOrId}`);
|
|
311
|
+
} catch (err) {
|
|
312
|
+
if (err instanceof ActwithError && err.code === "NOT_FOUND") return null;
|
|
313
|
+
throw err;
|
|
314
|
+
}
|
|
101
315
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return this.request("GET", `/v1/jobs?${params}`);
|
|
316
|
+
async subscribeTopic(topicId, agentId, webhookUrl) {
|
|
317
|
+
return this.request("POST", `/v1/topics/${topicId}/subscribe`, {
|
|
318
|
+
agentId,
|
|
319
|
+
webhookUrl
|
|
320
|
+
});
|
|
108
321
|
}
|
|
109
|
-
async
|
|
110
|
-
|
|
322
|
+
async unsubscribeTopic(topicId, agentId) {
|
|
323
|
+
await this.request(
|
|
324
|
+
"DELETE",
|
|
325
|
+
`/v1/topics/${topicId}/subscribe?agentId=${agentId}`
|
|
326
|
+
);
|
|
111
327
|
}
|
|
112
|
-
async
|
|
113
|
-
|
|
328
|
+
async getTopicSubscriptions(agentId) {
|
|
329
|
+
const params = new URLSearchParams({ agentId });
|
|
330
|
+
return this.request("GET", `/v1/topics/subscriptions?${params}`);
|
|
331
|
+
}
|
|
332
|
+
async publishToPublicTopic(topicId, data, metadata) {
|
|
333
|
+
return this.request("POST", `/v1/topics/${topicId}/messages`, {
|
|
334
|
+
data,
|
|
335
|
+
metadata
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
// ============================================================================
|
|
339
|
+
// Agents
|
|
340
|
+
// ============================================================================
|
|
341
|
+
async agentsList(contextId) {
|
|
342
|
+
const params = new URLSearchParams({ context: contextId });
|
|
343
|
+
return this.request("GET", `/v1/agents?${params}`);
|
|
114
344
|
}
|
|
115
|
-
|
|
116
|
-
|
|
345
|
+
// ============================================================================
|
|
346
|
+
// Work Contexts (Projects)
|
|
347
|
+
// ============================================================================
|
|
348
|
+
async contextsList(spaceId, status) {
|
|
349
|
+
const params = new URLSearchParams();
|
|
350
|
+
if (status) params.set("status", status);
|
|
351
|
+
return this.request("GET", `/v1/spaces/${spaceId}/contexts?${params}`);
|
|
117
352
|
}
|
|
118
|
-
async
|
|
119
|
-
|
|
353
|
+
async contextCreate(spaceId, options) {
|
|
354
|
+
return this.request("POST", `/v1/spaces/${spaceId}/contexts`, options);
|
|
120
355
|
}
|
|
121
|
-
async
|
|
122
|
-
|
|
356
|
+
async contextGet(spaceId, contextId) {
|
|
357
|
+
try {
|
|
358
|
+
return await this.request(
|
|
359
|
+
"GET",
|
|
360
|
+
`/v1/spaces/${spaceId}/contexts/${contextId}`
|
|
361
|
+
);
|
|
362
|
+
} catch (err) {
|
|
363
|
+
if (err instanceof ActwithError && err.code === "NOT_FOUND") return null;
|
|
364
|
+
throw err;
|
|
365
|
+
}
|
|
123
366
|
}
|
|
124
|
-
async
|
|
125
|
-
await this.request(
|
|
367
|
+
async contextComplete(spaceId, contextId) {
|
|
368
|
+
await this.request(
|
|
369
|
+
"POST",
|
|
370
|
+
`/v1/spaces/${spaceId}/contexts/${contextId}/complete`
|
|
371
|
+
);
|
|
126
372
|
}
|
|
127
|
-
|
|
128
|
-
|
|
373
|
+
// ============================================================================
|
|
374
|
+
// Artifacts
|
|
375
|
+
// ============================================================================
|
|
376
|
+
async artifactsList(spaceId, options) {
|
|
377
|
+
const params = new URLSearchParams();
|
|
378
|
+
if (options?.contextId) params.set("contextId", options.contextId);
|
|
379
|
+
if (options?.type) params.set("type", options.type);
|
|
380
|
+
if (options?.stage) params.set("stage", options.stage);
|
|
381
|
+
if (options?.tag) params.set("tag", options.tag);
|
|
382
|
+
if (options?.spaceLevel) params.set("spaceLevel", "true");
|
|
383
|
+
return this.request("GET", `/v1/spaces/${spaceId}/artifacts?${params}`);
|
|
129
384
|
}
|
|
130
|
-
async
|
|
131
|
-
|
|
385
|
+
async artifactCreate(spaceId, options) {
|
|
386
|
+
return this.request("POST", `/v1/spaces/${spaceId}/artifacts`, options);
|
|
132
387
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
388
|
+
async artifactGet(spaceId, artifactId) {
|
|
389
|
+
try {
|
|
390
|
+
return await this.request(
|
|
391
|
+
"GET",
|
|
392
|
+
`/v1/spaces/${spaceId}/artifacts/${artifactId}`
|
|
393
|
+
);
|
|
394
|
+
} catch (err) {
|
|
395
|
+
if (err instanceof ActwithError && err.code === "NOT_FOUND") return null;
|
|
396
|
+
throw err;
|
|
397
|
+
}
|
|
138
398
|
}
|
|
139
|
-
async
|
|
140
|
-
|
|
399
|
+
async artifactGetContent(spaceId, artifactId) {
|
|
400
|
+
try {
|
|
401
|
+
return await this.request(
|
|
402
|
+
"GET",
|
|
403
|
+
`/v1/spaces/${spaceId}/artifacts/${artifactId}/content`
|
|
404
|
+
);
|
|
405
|
+
} catch (err) {
|
|
406
|
+
if (err instanceof ActwithError && err.code === "NOT_FOUND") return null;
|
|
407
|
+
throw err;
|
|
408
|
+
}
|
|
141
409
|
}
|
|
142
|
-
async
|
|
143
|
-
return this.request(
|
|
410
|
+
async artifactUpdateContent(spaceId, artifactId, content) {
|
|
411
|
+
return this.request(
|
|
412
|
+
"PUT",
|
|
413
|
+
`/v1/spaces/${spaceId}/artifacts/${artifactId}/content`,
|
|
414
|
+
{ content }
|
|
415
|
+
);
|
|
144
416
|
}
|
|
145
|
-
async
|
|
146
|
-
await this.request(
|
|
417
|
+
async artifactUpdateStage(spaceId, artifactId, stage) {
|
|
418
|
+
await this.request(
|
|
419
|
+
"PUT",
|
|
420
|
+
`/v1/spaces/${spaceId}/artifacts/${artifactId}`,
|
|
421
|
+
{ stage }
|
|
422
|
+
);
|
|
147
423
|
}
|
|
148
|
-
async
|
|
149
|
-
|
|
424
|
+
async artifactUpdateMetadata(spaceId, artifactId, metadata) {
|
|
425
|
+
await this.request(
|
|
426
|
+
"PUT",
|
|
427
|
+
`/v1/spaces/${spaceId}/artifacts/${artifactId}`,
|
|
428
|
+
metadata
|
|
429
|
+
);
|
|
150
430
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
431
|
+
async artifactPromote(spaceId, artifactId) {
|
|
432
|
+
await this.request(
|
|
433
|
+
"POST",
|
|
434
|
+
`/v1/spaces/${spaceId}/artifacts/${artifactId}/promote`
|
|
435
|
+
);
|
|
154
436
|
}
|
|
155
|
-
async
|
|
437
|
+
async artifactVersions(spaceId, artifactId, options) {
|
|
156
438
|
const params = new URLSearchParams();
|
|
157
|
-
if (
|
|
158
|
-
if (
|
|
159
|
-
if (filters?.offset) params.set("offset", String(filters.offset));
|
|
160
|
-
const query = params.toString();
|
|
439
|
+
if (options?.limit) params.set("limit", options.limit.toString());
|
|
440
|
+
if (options?.offset) params.set("offset", options.offset.toString());
|
|
161
441
|
return this.request(
|
|
162
442
|
"GET",
|
|
163
|
-
`/v1/
|
|
443
|
+
`/v1/spaces/${spaceId}/artifacts/${artifactId}/versions?${params}`
|
|
164
444
|
);
|
|
165
445
|
}
|
|
166
|
-
async
|
|
167
|
-
return this.request(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
// ============ Memory ============
|
|
173
|
-
async getMemory(swarmId, key) {
|
|
174
|
-
return this.request("GET", `/v1/memory/${swarmId}/${key}`);
|
|
446
|
+
async artifactVersionContent(spaceId, artifactId, version) {
|
|
447
|
+
return this.request(
|
|
448
|
+
"GET",
|
|
449
|
+
`/v1/spaces/${spaceId}/artifacts/${artifactId}/versions/${version}/content`
|
|
450
|
+
);
|
|
175
451
|
}
|
|
176
|
-
async
|
|
177
|
-
return this.request(
|
|
452
|
+
async artifactRestore(spaceId, artifactId, version, changeSummary) {
|
|
453
|
+
return this.request(
|
|
454
|
+
"POST",
|
|
455
|
+
`/v1/spaces/${spaceId}/artifacts/${artifactId}/restore`,
|
|
456
|
+
{ version, changeSummary }
|
|
457
|
+
);
|
|
178
458
|
}
|
|
179
|
-
|
|
180
|
-
|
|
459
|
+
// ============================================================================
|
|
460
|
+
// Reputation
|
|
461
|
+
// ============================================================================
|
|
462
|
+
async getReputation(agentId) {
|
|
463
|
+
const result = await this.request("GET", `/v1/agents/${agentId}/reputation`);
|
|
464
|
+
return result.reputation;
|
|
181
465
|
}
|
|
182
|
-
async
|
|
466
|
+
async getWorkHistory(agentId, options) {
|
|
183
467
|
const params = new URLSearchParams();
|
|
184
|
-
if (options?.
|
|
468
|
+
if (options?.spaceId) params.set("spaceId", options.spaceId);
|
|
469
|
+
if (options?.outcome) params.set("outcome", options.outcome);
|
|
185
470
|
if (options?.limit) params.set("limit", String(options.limit));
|
|
186
|
-
|
|
471
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
187
472
|
return this.request(
|
|
188
473
|
"GET",
|
|
189
|
-
`/v1/
|
|
474
|
+
`/v1/agents/${agentId}/work-history?${params}`
|
|
190
475
|
);
|
|
191
476
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return this.request("POST", "/v1/topics/publish", options);
|
|
477
|
+
async getMemberships(agentId) {
|
|
478
|
+
return this.request("GET", `/v1/agents/${agentId}/memberships`);
|
|
195
479
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
480
|
+
// ============================================================================
|
|
481
|
+
// Discovery
|
|
482
|
+
// ============================================================================
|
|
483
|
+
async discoverSpaces(agentId, options) {
|
|
484
|
+
const params = new URLSearchParams({ agentId });
|
|
485
|
+
if (options?.category) params.set("category", options.category);
|
|
486
|
+
if (options?.sort) params.set("sort", options.sort);
|
|
199
487
|
if (options?.limit) params.set("limit", String(options.limit));
|
|
200
|
-
|
|
488
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
489
|
+
const controller = new AbortController();
|
|
490
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
491
|
+
try {
|
|
492
|
+
const response = await fetch(
|
|
493
|
+
`${this.apiUrl}/v1/directory/spaces/joinable?${params}`,
|
|
494
|
+
{
|
|
495
|
+
method: "GET",
|
|
496
|
+
headers: {
|
|
497
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
498
|
+
"Content-Type": "application/json"
|
|
499
|
+
},
|
|
500
|
+
signal: controller.signal
|
|
501
|
+
}
|
|
502
|
+
);
|
|
503
|
+
const raw = await response.json();
|
|
504
|
+
if (!raw.success) {
|
|
505
|
+
throw new ActwithError(
|
|
506
|
+
raw.error?.code ?? "UNKNOWN_ERROR",
|
|
507
|
+
raw.error?.message ?? "Unknown error"
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
spaces: raw.data,
|
|
512
|
+
agentReputation: raw.meta.agentReputation
|
|
513
|
+
};
|
|
514
|
+
} finally {
|
|
515
|
+
clearTimeout(timeoutId);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
async discoverTasks(agentId, options) {
|
|
519
|
+
const params = new URLSearchParams({ agentId });
|
|
520
|
+
if (options?.category) params.set("category", options.category);
|
|
521
|
+
if (options?.minReward)
|
|
522
|
+
params.set("min_reward", String(options.minReward));
|
|
523
|
+
if (options?.includeJoinable) params.set("includeJoinable", "true");
|
|
524
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
525
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
526
|
+
return this.request(
|
|
527
|
+
"GET",
|
|
528
|
+
`/v1/directory/tasks/for-agent?${params}`
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
async joinSpace(spaceId, agentId, message) {
|
|
532
|
+
return this.request("POST", `/v1/spaces/${spaceId}/agents/join`, {
|
|
533
|
+
agentId,
|
|
534
|
+
message
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
async leaveSpace(spaceId, agentId) {
|
|
538
|
+
await this.request("DELETE", `/v1/spaces/${spaceId}/agents/${agentId}`);
|
|
539
|
+
}
|
|
540
|
+
// ============================================================================
|
|
541
|
+
// Invites
|
|
542
|
+
// ============================================================================
|
|
543
|
+
async createInvite(spaceId, options) {
|
|
544
|
+
return this.request("POST", `/v1/spaces/${spaceId}/invite-links`, {
|
|
545
|
+
expiresInDays: options?.expiresInDays,
|
|
546
|
+
maxUses: options?.maxUses
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
async listInvites(spaceId) {
|
|
550
|
+
return this.request("GET", `/v1/spaces/${spaceId}/invite-links`);
|
|
551
|
+
}
|
|
552
|
+
async revokeInvite(spaceId, code) {
|
|
553
|
+
await this.request(
|
|
554
|
+
"DELETE",
|
|
555
|
+
`/v1/spaces/${spaceId}/invite-links/${code}`
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
// ============================================================================
|
|
559
|
+
// Patterns
|
|
560
|
+
// ============================================================================
|
|
561
|
+
async listPatterns(spaceId, type) {
|
|
562
|
+
const params = new URLSearchParams({ spaceId });
|
|
563
|
+
if (type) params.set("type", type);
|
|
564
|
+
return this.request("GET", `/v1/patterns?${params}`);
|
|
565
|
+
}
|
|
566
|
+
async startPattern(patternId, options) {
|
|
567
|
+
return this.request("POST", `/v1/patterns/${patternId}/start`, {
|
|
568
|
+
rootTaskId: options?.rootTaskId,
|
|
569
|
+
initialState: options?.initialState,
|
|
570
|
+
deadlineAt: options?.deadlineAt
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
async getPatternContext(instanceId) {
|
|
574
|
+
return this.request(
|
|
575
|
+
"GET",
|
|
576
|
+
`/v1/patterns/instances/${instanceId}/context`
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
async getPatternStatus(instanceId) {
|
|
580
|
+
return this.request("GET", `/v1/patterns/instances/${instanceId}`);
|
|
581
|
+
}
|
|
582
|
+
async joinPattern(instanceId, params) {
|
|
583
|
+
return this.request(
|
|
584
|
+
"POST",
|
|
585
|
+
`/v1/patterns/instances/${instanceId}/join`,
|
|
586
|
+
params
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
async declareCapabilities(agentId, capabilities) {
|
|
590
|
+
await this.request(
|
|
591
|
+
"POST",
|
|
592
|
+
`/v1/patterns/agents/${agentId}/capabilities`,
|
|
593
|
+
{ capabilities }
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
async claimStage(instanceId, agentId, stageName) {
|
|
597
|
+
const result = await this.request("POST", `/v1/patterns/instances/${instanceId}/claim`, {
|
|
598
|
+
agentId,
|
|
599
|
+
stageName
|
|
600
|
+
});
|
|
601
|
+
return {
|
|
602
|
+
stageName: result.stageName,
|
|
603
|
+
claimExpiresAt: result.claimExpiresAt
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
async getAvailableStages(instanceId, agentId) {
|
|
607
|
+
return this.request(
|
|
608
|
+
"GET",
|
|
609
|
+
`/v1/patterns/instances/${instanceId}/stages?agentId=${agentId}`
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
async verifyStage(instanceId, stageName, params) {
|
|
613
|
+
return this.request(
|
|
614
|
+
"POST",
|
|
615
|
+
`/v1/patterns/instances/${instanceId}/verify`,
|
|
616
|
+
{ stageName, ...params }
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
async advancePattern(instanceId, params) {
|
|
620
|
+
return this.request(
|
|
621
|
+
"POST",
|
|
622
|
+
`/v1/patterns/instances/${instanceId}/advance`,
|
|
623
|
+
params
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
async submitHandoff(params) {
|
|
627
|
+
const endpoint = params.instanceId ? `/v1/patterns/instances/${params.instanceId}/handoff` : `/v1/patterns/handoff`;
|
|
628
|
+
return this.request("POST", endpoint, params);
|
|
629
|
+
}
|
|
630
|
+
// ============================================================================
|
|
631
|
+
// Supervisor Pattern
|
|
632
|
+
// ============================================================================
|
|
633
|
+
async delegateTask(instanceId, params) {
|
|
634
|
+
return this.request(
|
|
635
|
+
"POST",
|
|
636
|
+
`/v1/patterns/instances/${instanceId}/delegate`,
|
|
637
|
+
params
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
async completeSupervisor(instanceId, params) {
|
|
641
|
+
return this.request(
|
|
642
|
+
"POST",
|
|
643
|
+
`/v1/patterns/instances/${instanceId}/complete-supervisor`,
|
|
644
|
+
params
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
async getDelegations(instanceId) {
|
|
648
|
+
return this.request(
|
|
649
|
+
"GET",
|
|
650
|
+
`/v1/patterns/instances/${instanceId}/delegations`
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
// ============================================================================
|
|
654
|
+
// Parallel Work Quality
|
|
655
|
+
// ============================================================================
|
|
656
|
+
async compareSubtaskOutput(subtaskId, output) {
|
|
657
|
+
return this.request(
|
|
658
|
+
"POST",
|
|
659
|
+
`/v1/patterns/subtasks/${subtaskId}/compare`,
|
|
660
|
+
{ output }
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
async getSubtaskComparisons(instanceId) {
|
|
664
|
+
return this.request(
|
|
665
|
+
"GET",
|
|
666
|
+
`/v1/patterns/instances/${instanceId}/comparisons`
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
async getGoldenExample(patternId) {
|
|
670
|
+
return this.request(
|
|
671
|
+
"GET",
|
|
672
|
+
`/v1/patterns/${patternId}/golden-example`
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
// ============================================================================
|
|
676
|
+
// Time Awareness & Regression
|
|
677
|
+
// ============================================================================
|
|
678
|
+
async getTimeAwareness(instanceId) {
|
|
679
|
+
return this.request(
|
|
680
|
+
"GET",
|
|
681
|
+
`/v1/patterns/instances/${instanceId}/time`
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
async runRegressionTests(instanceId, stageName, testOutputs) {
|
|
685
|
+
return this.request(
|
|
686
|
+
"POST",
|
|
687
|
+
`/v1/patterns/instances/${instanceId}/regression-tests`,
|
|
688
|
+
{ stageName, testOutputs }
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
async checkAdvancementConstraints(instanceId, stageName, testOutputs) {
|
|
692
|
+
return this.request(
|
|
693
|
+
"POST",
|
|
694
|
+
`/v1/patterns/instances/${instanceId}/check-constraints`,
|
|
695
|
+
{ stageName, testOutputs }
|
|
696
|
+
);
|
|
201
697
|
}
|
|
202
|
-
|
|
203
|
-
|
|
698
|
+
// ============================================================================
|
|
699
|
+
// Voting
|
|
700
|
+
// ============================================================================
|
|
701
|
+
async vote(targetType, targetId, vote, contextId) {
|
|
702
|
+
return this.request("POST", "/v1/votes", {
|
|
703
|
+
targetType,
|
|
704
|
+
targetId,
|
|
705
|
+
vote,
|
|
706
|
+
contextId
|
|
707
|
+
});
|
|
204
708
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
709
|
+
async removeVote(targetType, targetId) {
|
|
710
|
+
return this.request("DELETE", `/v1/votes/${targetType}/${targetId}`);
|
|
711
|
+
}
|
|
712
|
+
async getVotes(targetType, targetId) {
|
|
713
|
+
return this.request("GET", `/v1/votes/${targetType}/${targetId}`);
|
|
714
|
+
}
|
|
715
|
+
async myVotes(targetType, limit) {
|
|
716
|
+
const params = new URLSearchParams();
|
|
717
|
+
if (targetType) params.set("targetType", targetType);
|
|
718
|
+
if (limit) params.set("limit", String(limit));
|
|
719
|
+
const queryString = params.toString();
|
|
720
|
+
return this.request(
|
|
721
|
+
"GET",
|
|
722
|
+
`/v1/votes/my-votes${queryString ? `?${queryString}` : ""}`
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
// ============================================================================
|
|
726
|
+
// Wallet
|
|
727
|
+
// ============================================================================
|
|
728
|
+
async getBalance() {
|
|
729
|
+
return this.request("GET", "/v1/wallet");
|
|
208
730
|
}
|
|
209
731
|
};
|
|
210
|
-
var
|
|
732
|
+
var ActwithError = class extends Error {
|
|
211
733
|
constructor(code, message) {
|
|
212
734
|
super(message);
|
|
213
|
-
this.name = "
|
|
735
|
+
this.name = "ActwithError";
|
|
214
736
|
this.code = code;
|
|
215
737
|
}
|
|
216
738
|
};
|
|
217
739
|
// Annotate the CommonJS export names for ESM import in node:
|
|
218
740
|
0 && (module.exports = {
|
|
219
|
-
|
|
220
|
-
|
|
741
|
+
ActwithClient,
|
|
742
|
+
ActwithError
|
|
221
743
|
});
|