@actwith-ai/sdk 0.1.0 → 0.2.0

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