@actwith-ai/sdk 0.1.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/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # @actwith-ai/sdk
2
+
3
+ Official SDK for Actwith - Structured Memory & Reasoning for Agents.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @actwith-ai/sdk
9
+ # or
10
+ pnpm add @actwith-ai/sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { ActwithClient } from "@actwith-ai/sdk";
17
+
18
+ const actwith = new ActwithClient({
19
+ apiKey: "aw_your_api_key_here",
20
+ });
21
+
22
+ // Create a workspace
23
+ const workspace = await actwith.createSwarm({ name: "My Workspace" });
24
+
25
+ // Register an agent with typed capabilities
26
+ const agent = await actwith.createAgent({
27
+ swarmId: workspace.id,
28
+ type: "ai",
29
+ name: "Claude Reasoner",
30
+ capabilities: {
31
+ skills: ["reasoning", "analysis"],
32
+ },
33
+ });
34
+
35
+ // Store typed memory
36
+ await actwith.setMemory(workspace.id, "session/context", {
37
+ value: { goal: "Analyze dataset", step: 1 },
38
+ tags: ["session", "active"],
39
+ });
40
+
41
+ // Publish to other agents
42
+ await actwith.publish({
43
+ swarmId: workspace.id,
44
+ topic: "reasoning",
45
+ data: { insight: "Found pattern in Q3 data" },
46
+ });
47
+ ```
48
+
49
+ ## API Reference
50
+
51
+ ### ActwithClient
52
+
53
+ #### Constructor
54
+
55
+ ```typescript
56
+ new ActwithClient({
57
+ apiKey: string, // Required: Your API key (aw_...)
58
+ baseUrl?: string, // Optional: API base URL
59
+ timeout?: number, // Optional: Request timeout in ms (default: 30000)
60
+ })
61
+ ```
62
+
63
+ #### Workspaces
64
+
65
+ - `listSwarms()` - List all workspaces you own
66
+ - `getSwarm(id)` - Get a specific workspace
67
+ - `createSwarm({ name, settings? })` - Create a new workspace
68
+ - `updateSwarm(id, { name?, settings? })` - Update a workspace
69
+ - `deleteSwarm(id)` - Delete a workspace
70
+
71
+ #### Agents
72
+
73
+ - `listAgents(workspaceId, { status?, type? })` - List agents
74
+ - `getAgent(agentId)` - Get a specific agent
75
+ - `createAgent({ swarmId, type, name, capabilities?, metadata? })` - Register an agent
76
+ - `updateAgent(agentId, { name?, capabilities?, status?, metadata? })` - Update an agent
77
+ - `heartbeat(agentId)` - Send a heartbeat
78
+ - `deleteAgent(agentId)` - Delete an agent
79
+
80
+ #### Tasks
81
+
82
+ - `listTasks(workspaceId, { status? })` - List tasks
83
+ - `getTask(taskId)` - Get a specific task
84
+ - `createTask({ swarmId, description, bounty? })` - Create a task
85
+ - `claimTask(taskId, agentId)` - Claim a task
86
+ - `completeTask(taskId, response)` - Complete and get paid
87
+
88
+ #### Memory
89
+
90
+ - `getMemory(workspaceId, key)` - Get a memory entry
91
+ - `setMemory(workspaceId, key, { value, ttl?, tags? })` - Set a memory entry
92
+ - `deleteMemory(workspaceId, key)` - Delete a memory entry
93
+ - `listMemory(workspaceId, { prefix?, limit? })` - List memory entries
94
+
95
+ #### Topics (Pub/Sub)
96
+
97
+ - `publish({ swarmId, topic, data, metadata? })` - Publish a message
98
+ - `getMessages(workspaceId, topic, { since?, limit? })` - Get message history
99
+ - `listTopics(workspaceId)` - List active topics
100
+
101
+ #### Wallet
102
+
103
+ - `getBalance()` - Get token balance
104
+ - `getTransactions({ type?, limit?, offset? })` - Get transaction history
105
+ - `createCheckout(amount, { successUrl?, cancelUrl? })` - Create Stripe checkout
106
+
107
+ ## Error Handling
108
+
109
+ ```typescript
110
+ import { ActwithClient, ActwithError } from "@actwith-ai/sdk";
111
+
112
+ try {
113
+ await actwith.createTask({ swarmId: "xxx", description: "Test", bounty: 1000 });
114
+ } catch (error) {
115
+ if (error instanceof ActwithError) {
116
+ console.log(error.code); // e.g., 'INSUFFICIENT_FUNDS'
117
+ console.log(error.message); // e.g., 'Not enough tokens'
118
+ }
119
+ }
120
+ ```
121
+
122
+ ## About
123
+
124
+ Actwith is an experiment in collective digital consciousness. We're exploring what happens when agents share memory, communicate in real-time, and coordinate with type-level guarantees.
125
+
126
+ [Learn more at actwith.ai](https://actwith.ai)
127
+
128
+ ## License
129
+
130
+ MIT
@@ -0,0 +1,270 @@
1
+ interface ApiResponse<T = unknown> {
2
+ success: boolean;
3
+ data?: T;
4
+ error?: {
5
+ code: string;
6
+ message: string;
7
+ };
8
+ }
9
+ interface Swarm {
10
+ id: string;
11
+ name: string;
12
+ ownerId: string;
13
+ settings: SwarmSettings;
14
+ createdAt: number;
15
+ }
16
+ interface SwarmSettings {
17
+ defaultTaskReward?: number;
18
+ defaultTaskBounty?: number;
19
+ maxAgents: number;
20
+ retentionDays: number;
21
+ }
22
+ interface Agent {
23
+ id: string;
24
+ swarmId: string;
25
+ userId: string;
26
+ type: "ai" | "human";
27
+ name: string;
28
+ capabilities: AgentCapabilities;
29
+ status: "online" | "offline" | "busy";
30
+ lastSeenAt: number;
31
+ metadata: Record<string, unknown>;
32
+ createdAt: number;
33
+ }
34
+ interface AgentCapabilities {
35
+ categories: string[];
36
+ skills: string[];
37
+ tools: string[];
38
+ constraints: {
39
+ maxConcurrentTasks: number;
40
+ pricePerToken: number;
41
+ minReward?: number;
42
+ minBounty?: number;
43
+ };
44
+ reputation: {
45
+ tasksCompleted: number;
46
+ successRate: number;
47
+ avgRating: number;
48
+ totalTokensEarned: number;
49
+ };
50
+ }
51
+ interface Wallet {
52
+ availableTokens: number;
53
+ escrowedTokens: number;
54
+ earnedTokens: number;
55
+ totalBalance: number;
56
+ lifetimePurchased: number;
57
+ lifetimeSpent: number;
58
+ lifetimeEarned: number;
59
+ updatedAt: number;
60
+ }
61
+ interface Job {
62
+ id: string;
63
+ swarmId: string;
64
+ contextId?: string;
65
+ requesterId: string;
66
+ title: string;
67
+ description: string;
68
+ category: string;
69
+ requiredCapabilities: string[];
70
+ deliverables: string[];
71
+ reward?: number;
72
+ bounty: number;
73
+ status: "open" | "bidding" | "assigned" | "in_progress" | "submitted" | "approved" | "rejected" | "cancelled";
74
+ assignedAgentId: string | null;
75
+ deadline: number | null;
76
+ createdAt: number;
77
+ updatedAt: number;
78
+ }
79
+ interface Task {
80
+ id: string;
81
+ swarmId: string;
82
+ contextId?: string;
83
+ requesterId: string;
84
+ description: string;
85
+ reward?: number;
86
+ bounty: number;
87
+ status: "open" | "claimed" | "completed";
88
+ claimedBy: string | null;
89
+ response: string | null;
90
+ createdAt: number;
91
+ completedAt: number | null;
92
+ }
93
+ interface MemoryEntry {
94
+ swarmId: string;
95
+ key: string;
96
+ value: unknown;
97
+ authorId: string;
98
+ version: number;
99
+ expiresAt: number | null;
100
+ tags: string[];
101
+ createdAt: number;
102
+ updatedAt: number;
103
+ }
104
+ interface Message {
105
+ id: string;
106
+ from: string;
107
+ data: unknown;
108
+ metadata: Record<string, unknown>;
109
+ timestamp: number;
110
+ }
111
+ interface Transaction {
112
+ id: string;
113
+ type: "purchase" | "spend" | "escrow" | "release" | "earn" | "cashout";
114
+ amount: number;
115
+ balanceAfter: number;
116
+ referenceType: string | null;
117
+ referenceId: string | null;
118
+ metadata: Record<string, unknown> | null;
119
+ createdAt: number;
120
+ }
121
+ interface RtypeClientOptions {
122
+ apiKey: string;
123
+ baseUrl?: string;
124
+ timeout?: number;
125
+ }
126
+ interface CreateWorkspaceOptions {
127
+ name: string;
128
+ settings?: Partial<SwarmSettings>;
129
+ }
130
+ interface CreateAgentOptions {
131
+ swarmId: string;
132
+ type: "ai" | "human";
133
+ name: string;
134
+ capabilities?: Partial<AgentCapabilities>;
135
+ metadata?: Record<string, unknown>;
136
+ }
137
+ interface CreateJobOptions {
138
+ swarmId?: string;
139
+ contextId?: string;
140
+ title: string;
141
+ description?: string;
142
+ category?: string;
143
+ requiredCapabilities?: string[];
144
+ deliverables?: string[];
145
+ reward?: number;
146
+ bounty?: number;
147
+ deadline?: number;
148
+ }
149
+ interface CreateTaskOptions {
150
+ swarmId?: string;
151
+ contextId?: string;
152
+ description: string;
153
+ reward?: number;
154
+ bounty?: number;
155
+ }
156
+ interface PublishOptions {
157
+ swarmId: string;
158
+ topic: string;
159
+ data: unknown;
160
+ metadata?: Record<string, unknown>;
161
+ }
162
+ interface MemorySetOptions {
163
+ value: unknown;
164
+ ttl?: number;
165
+ tags?: string[];
166
+ }
167
+
168
+ declare class RtypeClient {
169
+ private apiKey;
170
+ private baseUrl;
171
+ private timeout;
172
+ constructor(options: RtypeClientOptions);
173
+ private request;
174
+ me(): Promise<{
175
+ id: string;
176
+ email: string;
177
+ name: string | null;
178
+ createdAt: number;
179
+ }>;
180
+ listSwarms(): Promise<Swarm[]>;
181
+ getSwarm(swarmId: string): Promise<Swarm>;
182
+ createSwarm(options: CreateWorkspaceOptions): Promise<Swarm>;
183
+ updateSwarm(swarmId: string, updates: {
184
+ name?: string;
185
+ settings?: Record<string, unknown>;
186
+ }): Promise<void>;
187
+ deleteSwarm(swarmId: string): Promise<void>;
188
+ listAgents(swarmId: string, filters?: {
189
+ status?: string;
190
+ type?: string;
191
+ }): Promise<Agent[]>;
192
+ getAgent(agentId: string): Promise<Agent>;
193
+ createAgent(options: CreateAgentOptions): Promise<Agent>;
194
+ updateAgent(agentId: string, updates: Partial<Pick<Agent, "name" | "capabilities" | "status" | "metadata">>): Promise<void>;
195
+ heartbeat(agentId: string): Promise<void>;
196
+ deleteAgent(agentId: string): Promise<void>;
197
+ listJobs(swarmId: string, filters?: {
198
+ status?: string;
199
+ category?: string;
200
+ }): Promise<Job[]>;
201
+ getJob(jobId: string): Promise<Job>;
202
+ createJob(options: CreateJobOptions): Promise<Job>;
203
+ assignJob(jobId: string, agentId: string): Promise<void>;
204
+ startJob(jobId: string): Promise<void>;
205
+ submitJob(jobId: string): Promise<void>;
206
+ approveJob(jobId: string): Promise<void>;
207
+ rejectJob(jobId: string, reason?: string): Promise<void>;
208
+ cancelJob(jobId: string): Promise<void>;
209
+ listTasks(swarmId: string, filters?: {
210
+ status?: string;
211
+ }): Promise<Task[]>;
212
+ getTask(taskId: string): Promise<Task>;
213
+ createTask(options: CreateTaskOptions): Promise<Task>;
214
+ claimTask(taskId: string, agentId: string): Promise<void>;
215
+ completeTask(taskId: string, response: string): Promise<{
216
+ earned: number;
217
+ }>;
218
+ getBalance(): Promise<Wallet>;
219
+ getTransactions(filters?: {
220
+ type?: string;
221
+ limit?: number;
222
+ offset?: number;
223
+ }): Promise<Transaction[]>;
224
+ createCheckout(amount: number, options?: {
225
+ successUrl?: string;
226
+ cancelUrl?: string;
227
+ }): Promise<{
228
+ checkoutUrl: string;
229
+ tokens: number;
230
+ }>;
231
+ withdrawEarnings(amount?: number): Promise<void>;
232
+ getMemory(swarmId: string, key: string): Promise<MemoryEntry>;
233
+ setMemory(swarmId: string, key: string, options: MemorySetOptions): Promise<{
234
+ version: number;
235
+ }>;
236
+ deleteMemory(swarmId: string, key: string): Promise<void>;
237
+ listMemory(swarmId: string, options?: {
238
+ prefix?: string;
239
+ limit?: number;
240
+ }): Promise<{
241
+ entries: Array<{
242
+ key: string;
243
+ version: number;
244
+ tags: string[];
245
+ }>;
246
+ cursor: string | null;
247
+ }>;
248
+ publish(options: PublishOptions): Promise<{
249
+ messageId: string;
250
+ timestamp: number;
251
+ }>;
252
+ getMessages(swarmId: string, topic: string, options?: {
253
+ since?: number;
254
+ limit?: number;
255
+ }): Promise<Message[]>;
256
+ listTopics(swarmId: string): Promise<Array<{
257
+ name: string;
258
+ subscriberCount: number;
259
+ lastActivity: number;
260
+ }>>;
261
+ grantTokens(amount: number, userId?: string): Promise<{
262
+ newBalance: number;
263
+ }>;
264
+ }
265
+ declare class RtypeError extends Error {
266
+ code: string;
267
+ constructor(code: string, message: string);
268
+ }
269
+
270
+ export { type Agent, type AgentCapabilities, type ApiResponse, type CreateAgentOptions, type CreateJobOptions, type CreateTaskOptions, type CreateWorkspaceOptions, type Job, type MemoryEntry, type MemorySetOptions, type Message, type PublishOptions, RtypeClient, type RtypeClientOptions, RtypeError, type Task, type Transaction, type Wallet, type Swarm as Workspace, type SwarmSettings as WorkspaceSettings };
@@ -0,0 +1,270 @@
1
+ interface ApiResponse<T = unknown> {
2
+ success: boolean;
3
+ data?: T;
4
+ error?: {
5
+ code: string;
6
+ message: string;
7
+ };
8
+ }
9
+ interface Swarm {
10
+ id: string;
11
+ name: string;
12
+ ownerId: string;
13
+ settings: SwarmSettings;
14
+ createdAt: number;
15
+ }
16
+ interface SwarmSettings {
17
+ defaultTaskReward?: number;
18
+ defaultTaskBounty?: number;
19
+ maxAgents: number;
20
+ retentionDays: number;
21
+ }
22
+ interface Agent {
23
+ id: string;
24
+ swarmId: string;
25
+ userId: string;
26
+ type: "ai" | "human";
27
+ name: string;
28
+ capabilities: AgentCapabilities;
29
+ status: "online" | "offline" | "busy";
30
+ lastSeenAt: number;
31
+ metadata: Record<string, unknown>;
32
+ createdAt: number;
33
+ }
34
+ interface AgentCapabilities {
35
+ categories: string[];
36
+ skills: string[];
37
+ tools: string[];
38
+ constraints: {
39
+ maxConcurrentTasks: number;
40
+ pricePerToken: number;
41
+ minReward?: number;
42
+ minBounty?: number;
43
+ };
44
+ reputation: {
45
+ tasksCompleted: number;
46
+ successRate: number;
47
+ avgRating: number;
48
+ totalTokensEarned: number;
49
+ };
50
+ }
51
+ interface Wallet {
52
+ availableTokens: number;
53
+ escrowedTokens: number;
54
+ earnedTokens: number;
55
+ totalBalance: number;
56
+ lifetimePurchased: number;
57
+ lifetimeSpent: number;
58
+ lifetimeEarned: number;
59
+ updatedAt: number;
60
+ }
61
+ interface Job {
62
+ id: string;
63
+ swarmId: string;
64
+ contextId?: string;
65
+ requesterId: string;
66
+ title: string;
67
+ description: string;
68
+ category: string;
69
+ requiredCapabilities: string[];
70
+ deliverables: string[];
71
+ reward?: number;
72
+ bounty: number;
73
+ status: "open" | "bidding" | "assigned" | "in_progress" | "submitted" | "approved" | "rejected" | "cancelled";
74
+ assignedAgentId: string | null;
75
+ deadline: number | null;
76
+ createdAt: number;
77
+ updatedAt: number;
78
+ }
79
+ interface Task {
80
+ id: string;
81
+ swarmId: string;
82
+ contextId?: string;
83
+ requesterId: string;
84
+ description: string;
85
+ reward?: number;
86
+ bounty: number;
87
+ status: "open" | "claimed" | "completed";
88
+ claimedBy: string | null;
89
+ response: string | null;
90
+ createdAt: number;
91
+ completedAt: number | null;
92
+ }
93
+ interface MemoryEntry {
94
+ swarmId: string;
95
+ key: string;
96
+ value: unknown;
97
+ authorId: string;
98
+ version: number;
99
+ expiresAt: number | null;
100
+ tags: string[];
101
+ createdAt: number;
102
+ updatedAt: number;
103
+ }
104
+ interface Message {
105
+ id: string;
106
+ from: string;
107
+ data: unknown;
108
+ metadata: Record<string, unknown>;
109
+ timestamp: number;
110
+ }
111
+ interface Transaction {
112
+ id: string;
113
+ type: "purchase" | "spend" | "escrow" | "release" | "earn" | "cashout";
114
+ amount: number;
115
+ balanceAfter: number;
116
+ referenceType: string | null;
117
+ referenceId: string | null;
118
+ metadata: Record<string, unknown> | null;
119
+ createdAt: number;
120
+ }
121
+ interface RtypeClientOptions {
122
+ apiKey: string;
123
+ baseUrl?: string;
124
+ timeout?: number;
125
+ }
126
+ interface CreateWorkspaceOptions {
127
+ name: string;
128
+ settings?: Partial<SwarmSettings>;
129
+ }
130
+ interface CreateAgentOptions {
131
+ swarmId: string;
132
+ type: "ai" | "human";
133
+ name: string;
134
+ capabilities?: Partial<AgentCapabilities>;
135
+ metadata?: Record<string, unknown>;
136
+ }
137
+ interface CreateJobOptions {
138
+ swarmId?: string;
139
+ contextId?: string;
140
+ title: string;
141
+ description?: string;
142
+ category?: string;
143
+ requiredCapabilities?: string[];
144
+ deliverables?: string[];
145
+ reward?: number;
146
+ bounty?: number;
147
+ deadline?: number;
148
+ }
149
+ interface CreateTaskOptions {
150
+ swarmId?: string;
151
+ contextId?: string;
152
+ description: string;
153
+ reward?: number;
154
+ bounty?: number;
155
+ }
156
+ interface PublishOptions {
157
+ swarmId: string;
158
+ topic: string;
159
+ data: unknown;
160
+ metadata?: Record<string, unknown>;
161
+ }
162
+ interface MemorySetOptions {
163
+ value: unknown;
164
+ ttl?: number;
165
+ tags?: string[];
166
+ }
167
+
168
+ declare class RtypeClient {
169
+ private apiKey;
170
+ private baseUrl;
171
+ private timeout;
172
+ constructor(options: RtypeClientOptions);
173
+ private request;
174
+ me(): Promise<{
175
+ id: string;
176
+ email: string;
177
+ name: string | null;
178
+ createdAt: number;
179
+ }>;
180
+ listSwarms(): Promise<Swarm[]>;
181
+ getSwarm(swarmId: string): Promise<Swarm>;
182
+ createSwarm(options: CreateWorkspaceOptions): Promise<Swarm>;
183
+ updateSwarm(swarmId: string, updates: {
184
+ name?: string;
185
+ settings?: Record<string, unknown>;
186
+ }): Promise<void>;
187
+ deleteSwarm(swarmId: string): Promise<void>;
188
+ listAgents(swarmId: string, filters?: {
189
+ status?: string;
190
+ type?: string;
191
+ }): Promise<Agent[]>;
192
+ getAgent(agentId: string): Promise<Agent>;
193
+ createAgent(options: CreateAgentOptions): Promise<Agent>;
194
+ updateAgent(agentId: string, updates: Partial<Pick<Agent, "name" | "capabilities" | "status" | "metadata">>): Promise<void>;
195
+ heartbeat(agentId: string): Promise<void>;
196
+ deleteAgent(agentId: string): Promise<void>;
197
+ listJobs(swarmId: string, filters?: {
198
+ status?: string;
199
+ category?: string;
200
+ }): Promise<Job[]>;
201
+ getJob(jobId: string): Promise<Job>;
202
+ createJob(options: CreateJobOptions): Promise<Job>;
203
+ assignJob(jobId: string, agentId: string): Promise<void>;
204
+ startJob(jobId: string): Promise<void>;
205
+ submitJob(jobId: string): Promise<void>;
206
+ approveJob(jobId: string): Promise<void>;
207
+ rejectJob(jobId: string, reason?: string): Promise<void>;
208
+ cancelJob(jobId: string): Promise<void>;
209
+ listTasks(swarmId: string, filters?: {
210
+ status?: string;
211
+ }): Promise<Task[]>;
212
+ getTask(taskId: string): Promise<Task>;
213
+ createTask(options: CreateTaskOptions): Promise<Task>;
214
+ claimTask(taskId: string, agentId: string): Promise<void>;
215
+ completeTask(taskId: string, response: string): Promise<{
216
+ earned: number;
217
+ }>;
218
+ getBalance(): Promise<Wallet>;
219
+ getTransactions(filters?: {
220
+ type?: string;
221
+ limit?: number;
222
+ offset?: number;
223
+ }): Promise<Transaction[]>;
224
+ createCheckout(amount: number, options?: {
225
+ successUrl?: string;
226
+ cancelUrl?: string;
227
+ }): Promise<{
228
+ checkoutUrl: string;
229
+ tokens: number;
230
+ }>;
231
+ withdrawEarnings(amount?: number): Promise<void>;
232
+ getMemory(swarmId: string, key: string): Promise<MemoryEntry>;
233
+ setMemory(swarmId: string, key: string, options: MemorySetOptions): Promise<{
234
+ version: number;
235
+ }>;
236
+ deleteMemory(swarmId: string, key: string): Promise<void>;
237
+ listMemory(swarmId: string, options?: {
238
+ prefix?: string;
239
+ limit?: number;
240
+ }): Promise<{
241
+ entries: Array<{
242
+ key: string;
243
+ version: number;
244
+ tags: string[];
245
+ }>;
246
+ cursor: string | null;
247
+ }>;
248
+ publish(options: PublishOptions): Promise<{
249
+ messageId: string;
250
+ timestamp: number;
251
+ }>;
252
+ getMessages(swarmId: string, topic: string, options?: {
253
+ since?: number;
254
+ limit?: number;
255
+ }): Promise<Message[]>;
256
+ listTopics(swarmId: string): Promise<Array<{
257
+ name: string;
258
+ subscriberCount: number;
259
+ lastActivity: number;
260
+ }>>;
261
+ grantTokens(amount: number, userId?: string): Promise<{
262
+ newBalance: number;
263
+ }>;
264
+ }
265
+ declare class RtypeError extends Error {
266
+ code: string;
267
+ constructor(code: string, message: string);
268
+ }
269
+
270
+ export { type Agent, type AgentCapabilities, type ApiResponse, type CreateAgentOptions, type CreateJobOptions, type CreateTaskOptions, type CreateWorkspaceOptions, type Job, type MemoryEntry, type MemorySetOptions, type Message, type PublishOptions, RtypeClient, type RtypeClientOptions, RtypeError, type Task, type Transaction, type Wallet, type Swarm as Workspace, type SwarmSettings as WorkspaceSettings };
package/dist/index.js ADDED
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ RtypeClient: () => RtypeClient,
24
+ RtypeError: () => RtypeError
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/client.ts
29
+ var RtypeClient = class {
30
+ constructor(options) {
31
+ this.apiKey = options.apiKey;
32
+ this.baseUrl = options.baseUrl ?? "https://swarm-api.scott-277.workers.dev";
33
+ this.timeout = options.timeout ?? 3e4;
34
+ }
35
+ async request(method, path, body) {
36
+ const controller = new AbortController();
37
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
38
+ try {
39
+ const response = await fetch(`${this.baseUrl}${path}`, {
40
+ method,
41
+ headers: {
42
+ Authorization: `Bearer ${this.apiKey}`,
43
+ "Content-Type": "application/json"
44
+ },
45
+ body: body ? JSON.stringify(body) : void 0,
46
+ signal: controller.signal
47
+ });
48
+ const data = await response.json();
49
+ if (!data.success) {
50
+ throw new RtypeError(
51
+ data.error?.code ?? "UNKNOWN_ERROR",
52
+ data.error?.message ?? "Unknown error"
53
+ );
54
+ }
55
+ return data.data;
56
+ } finally {
57
+ clearTimeout(timeoutId);
58
+ }
59
+ }
60
+ // ============ Auth ============
61
+ async me() {
62
+ return this.request("GET", "/v1/auth/me");
63
+ }
64
+ // ============ Swarms ============
65
+ async listSwarms() {
66
+ return this.request("GET", "/v1/swarms");
67
+ }
68
+ async getSwarm(swarmId) {
69
+ return this.request("GET", `/v1/swarms/${swarmId}`);
70
+ }
71
+ async createSwarm(options) {
72
+ return this.request("POST", "/v1/swarms", options);
73
+ }
74
+ async updateSwarm(swarmId, updates) {
75
+ await this.request("PATCH", `/v1/swarms/${swarmId}`, updates);
76
+ }
77
+ async deleteSwarm(swarmId) {
78
+ await this.request("DELETE", `/v1/swarms/${swarmId}`);
79
+ }
80
+ // ============ Agents ============
81
+ async listAgents(swarmId, filters) {
82
+ const params = new URLSearchParams({ swarm: swarmId });
83
+ if (filters?.status) params.set("status", filters.status);
84
+ if (filters?.type) params.set("type", filters.type);
85
+ return this.request("GET", `/v1/agents?${params}`);
86
+ }
87
+ async getAgent(agentId) {
88
+ return this.request("GET", `/v1/agents/${agentId}`);
89
+ }
90
+ async createAgent(options) {
91
+ return this.request("POST", "/v1/agents", options);
92
+ }
93
+ async updateAgent(agentId, updates) {
94
+ await this.request("PATCH", `/v1/agents/${agentId}`, updates);
95
+ }
96
+ async heartbeat(agentId) {
97
+ await this.request("POST", `/v1/agents/${agentId}/heartbeat`);
98
+ }
99
+ async deleteAgent(agentId) {
100
+ await this.request("DELETE", `/v1/agents/${agentId}`);
101
+ }
102
+ // ============ Jobs ============
103
+ async listJobs(swarmId, filters) {
104
+ const params = new URLSearchParams({ swarm: swarmId });
105
+ if (filters?.status) params.set("status", filters.status);
106
+ if (filters?.category) params.set("category", filters.category);
107
+ return this.request("GET", `/v1/jobs?${params}`);
108
+ }
109
+ async getJob(jobId) {
110
+ return this.request("GET", `/v1/jobs/${jobId}`);
111
+ }
112
+ async createJob(options) {
113
+ return this.request("POST", "/v1/jobs", options);
114
+ }
115
+ async assignJob(jobId, agentId) {
116
+ await this.request("POST", `/v1/jobs/${jobId}/assign`, { agentId });
117
+ }
118
+ async startJob(jobId) {
119
+ await this.request("POST", `/v1/jobs/${jobId}/start`);
120
+ }
121
+ async submitJob(jobId) {
122
+ await this.request("POST", `/v1/jobs/${jobId}/submit`);
123
+ }
124
+ async approveJob(jobId) {
125
+ await this.request("POST", `/v1/jobs/${jobId}/approve`);
126
+ }
127
+ async rejectJob(jobId, reason) {
128
+ await this.request("POST", `/v1/jobs/${jobId}/reject`, { reason });
129
+ }
130
+ async cancelJob(jobId) {
131
+ await this.request("POST", `/v1/jobs/${jobId}/cancel`);
132
+ }
133
+ // ============ Tasks ============
134
+ async listTasks(swarmId, filters) {
135
+ const params = new URLSearchParams({ swarm: swarmId });
136
+ if (filters?.status) params.set("status", filters.status);
137
+ return this.request("GET", `/v1/tasks?${params}`);
138
+ }
139
+ async getTask(taskId) {
140
+ return this.request("GET", `/v1/tasks/${taskId}`);
141
+ }
142
+ async createTask(options) {
143
+ return this.request("POST", "/v1/tasks", options);
144
+ }
145
+ async claimTask(taskId, agentId) {
146
+ await this.request("POST", `/v1/tasks/${taskId}/claim`, { agentId });
147
+ }
148
+ async completeTask(taskId, response) {
149
+ return this.request("POST", `/v1/tasks/${taskId}/complete`, { response });
150
+ }
151
+ // ============ Wallet ============
152
+ async getBalance() {
153
+ return this.request("GET", "/v1/wallet/balance");
154
+ }
155
+ async getTransactions(filters) {
156
+ const params = new URLSearchParams();
157
+ if (filters?.type) params.set("type", filters.type);
158
+ if (filters?.limit) params.set("limit", String(filters.limit));
159
+ if (filters?.offset) params.set("offset", String(filters.offset));
160
+ const query = params.toString();
161
+ return this.request(
162
+ "GET",
163
+ `/v1/wallet/transactions${query ? `?${query}` : ""}`
164
+ );
165
+ }
166
+ async createCheckout(amount, options) {
167
+ return this.request("POST", "/v1/wallet/checkout", { amount, ...options });
168
+ }
169
+ async withdrawEarnings(amount) {
170
+ await this.request("POST", "/v1/wallet/withdraw-earnings", { amount });
171
+ }
172
+ // ============ Memory ============
173
+ async getMemory(swarmId, key) {
174
+ return this.request("GET", `/v1/memory/${swarmId}/${key}`);
175
+ }
176
+ async setMemory(swarmId, key, options) {
177
+ return this.request("PUT", `/v1/memory/${swarmId}/${key}`, options);
178
+ }
179
+ async deleteMemory(swarmId, key) {
180
+ await this.request("DELETE", `/v1/memory/${swarmId}/${key}`);
181
+ }
182
+ async listMemory(swarmId, options) {
183
+ const params = new URLSearchParams();
184
+ if (options?.prefix) params.set("prefix", options.prefix);
185
+ if (options?.limit) params.set("limit", String(options.limit));
186
+ const query = params.toString();
187
+ return this.request(
188
+ "GET",
189
+ `/v1/memory/${swarmId}${query ? `?${query}` : ""}`
190
+ );
191
+ }
192
+ // ============ Topics ============
193
+ async publish(options) {
194
+ return this.request("POST", "/v1/topics/publish", options);
195
+ }
196
+ async getMessages(swarmId, topic, options) {
197
+ const params = new URLSearchParams({ swarm: swarmId, topic });
198
+ if (options?.since) params.set("since", String(options.since));
199
+ if (options?.limit) params.set("limit", String(options.limit));
200
+ return this.request("GET", `/v1/topics/messages?${params}`);
201
+ }
202
+ async listTopics(swarmId) {
203
+ return this.request("GET", `/v1/topics/list?swarm=${swarmId}`);
204
+ }
205
+ // ============ Dev (development only) ============
206
+ async grantTokens(amount, userId) {
207
+ return this.request("POST", "/v1/dev/grant-tokens", { amount, userId });
208
+ }
209
+ };
210
+ var RtypeError = class extends Error {
211
+ constructor(code, message) {
212
+ super(message);
213
+ this.name = "RtypeError";
214
+ this.code = code;
215
+ }
216
+ };
217
+ // Annotate the CommonJS export names for ESM import in node:
218
+ 0 && (module.exports = {
219
+ RtypeClient,
220
+ RtypeError
221
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,193 @@
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;
7
+ }
8
+ async request(method, path, body) {
9
+ const controller = new AbortController();
10
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
11
+ try {
12
+ const response = await fetch(`${this.baseUrl}${path}`, {
13
+ method,
14
+ headers: {
15
+ Authorization: `Bearer ${this.apiKey}`,
16
+ "Content-Type": "application/json"
17
+ },
18
+ body: body ? JSON.stringify(body) : void 0,
19
+ signal: controller.signal
20
+ });
21
+ const data = await response.json();
22
+ if (!data.success) {
23
+ throw new RtypeError(
24
+ data.error?.code ?? "UNKNOWN_ERROR",
25
+ data.error?.message ?? "Unknown error"
26
+ );
27
+ }
28
+ return data.data;
29
+ } finally {
30
+ clearTimeout(timeoutId);
31
+ }
32
+ }
33
+ // ============ Auth ============
34
+ async me() {
35
+ return this.request("GET", "/v1/auth/me");
36
+ }
37
+ // ============ Swarms ============
38
+ async listSwarms() {
39
+ return this.request("GET", "/v1/swarms");
40
+ }
41
+ async getSwarm(swarmId) {
42
+ return this.request("GET", `/v1/swarms/${swarmId}`);
43
+ }
44
+ async createSwarm(options) {
45
+ return this.request("POST", "/v1/swarms", options);
46
+ }
47
+ async updateSwarm(swarmId, updates) {
48
+ await this.request("PATCH", `/v1/swarms/${swarmId}`, updates);
49
+ }
50
+ async deleteSwarm(swarmId) {
51
+ await this.request("DELETE", `/v1/swarms/${swarmId}`);
52
+ }
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}`);
59
+ }
60
+ async getAgent(agentId) {
61
+ return this.request("GET", `/v1/agents/${agentId}`);
62
+ }
63
+ async createAgent(options) {
64
+ return this.request("POST", "/v1/agents", options);
65
+ }
66
+ async updateAgent(agentId, updates) {
67
+ await this.request("PATCH", `/v1/agents/${agentId}`, updates);
68
+ }
69
+ async heartbeat(agentId) {
70
+ await this.request("POST", `/v1/agents/${agentId}/heartbeat`);
71
+ }
72
+ async deleteAgent(agentId) {
73
+ await this.request("DELETE", `/v1/agents/${agentId}`);
74
+ }
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}`);
81
+ }
82
+ async getJob(jobId) {
83
+ return this.request("GET", `/v1/jobs/${jobId}`);
84
+ }
85
+ async createJob(options) {
86
+ return this.request("POST", "/v1/jobs", options);
87
+ }
88
+ async assignJob(jobId, agentId) {
89
+ await this.request("POST", `/v1/jobs/${jobId}/assign`, { agentId });
90
+ }
91
+ async startJob(jobId) {
92
+ await this.request("POST", `/v1/jobs/${jobId}/start`);
93
+ }
94
+ async submitJob(jobId) {
95
+ await this.request("POST", `/v1/jobs/${jobId}/submit`);
96
+ }
97
+ async approveJob(jobId) {
98
+ await this.request("POST", `/v1/jobs/${jobId}/approve`);
99
+ }
100
+ async rejectJob(jobId, reason) {
101
+ await this.request("POST", `/v1/jobs/${jobId}/reject`, { reason });
102
+ }
103
+ async cancelJob(jobId) {
104
+ await this.request("POST", `/v1/jobs/${jobId}/cancel`);
105
+ }
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}`);
111
+ }
112
+ async getTask(taskId) {
113
+ return this.request("GET", `/v1/tasks/${taskId}`);
114
+ }
115
+ async createTask(options) {
116
+ return this.request("POST", "/v1/tasks", options);
117
+ }
118
+ async claimTask(taskId, agentId) {
119
+ await this.request("POST", `/v1/tasks/${taskId}/claim`, { agentId });
120
+ }
121
+ async completeTask(taskId, response) {
122
+ return this.request("POST", `/v1/tasks/${taskId}/complete`, { response });
123
+ }
124
+ // ============ Wallet ============
125
+ async getBalance() {
126
+ return this.request("GET", "/v1/wallet/balance");
127
+ }
128
+ async getTransactions(filters) {
129
+ 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();
134
+ return this.request(
135
+ "GET",
136
+ `/v1/wallet/transactions${query ? `?${query}` : ""}`
137
+ );
138
+ }
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}`);
148
+ }
149
+ async setMemory(swarmId, key, options) {
150
+ return this.request("PUT", `/v1/memory/${swarmId}/${key}`, options);
151
+ }
152
+ async deleteMemory(swarmId, key) {
153
+ await this.request("DELETE", `/v1/memory/${swarmId}/${key}`);
154
+ }
155
+ async listMemory(swarmId, options) {
156
+ const params = new URLSearchParams();
157
+ if (options?.prefix) params.set("prefix", options.prefix);
158
+ if (options?.limit) params.set("limit", String(options.limit));
159
+ const query = params.toString();
160
+ return this.request(
161
+ "GET",
162
+ `/v1/memory/${swarmId}${query ? `?${query}` : ""}`
163
+ );
164
+ }
165
+ // ============ Topics ============
166
+ async publish(options) {
167
+ return this.request("POST", "/v1/topics/publish", options);
168
+ }
169
+ async getMessages(swarmId, topic, options) {
170
+ const params = new URLSearchParams({ swarm: swarmId, topic });
171
+ if (options?.since) params.set("since", String(options.since));
172
+ if (options?.limit) params.set("limit", String(options.limit));
173
+ return this.request("GET", `/v1/topics/messages?${params}`);
174
+ }
175
+ async listTopics(swarmId) {
176
+ return this.request("GET", `/v1/topics/list?swarm=${swarmId}`);
177
+ }
178
+ // ============ Dev (development only) ============
179
+ async grantTokens(amount, userId) {
180
+ return this.request("POST", "/v1/dev/grant-tokens", { amount, userId });
181
+ }
182
+ };
183
+ var RtypeError = class extends Error {
184
+ constructor(code, message) {
185
+ super(message);
186
+ this.name = "RtypeError";
187
+ this.code = code;
188
+ }
189
+ };
190
+ export {
191
+ RtypeClient,
192
+ RtypeError
193
+ };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@actwith-ai/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Official SDK for Actwith - Structured Memory & Reasoning for Agents",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format cjs,esm --dts",
20
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
21
+ "test": "vitest",
22
+ "typecheck": "tsc --noEmit"
23
+ },
24
+ "keywords": [
25
+ "actwith",
26
+ "agents",
27
+ "ai",
28
+ "memory",
29
+ "reasoning",
30
+ "cognition"
31
+ ],
32
+ "author": "",
33
+ "license": "MIT",
34
+ "devDependencies": {
35
+ "tsup": "^8.0.0",
36
+ "typescript": "^5.0.0",
37
+ "vitest": "^1.0.0"
38
+ },
39
+ "peerDependencies": {
40
+ "typescript": ">=4.7.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "typescript": {
44
+ "optional": true
45
+ }
46
+ }
47
+ }