swarmlord 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zach Grimaldi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,198 @@
1
+ # swarmlord
2
+
3
+ TypeScript SDK for [Swarmlord](https://swarmlord.ai) — spawn AI coding agents natively on Cloudflare.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install swarmlord
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { createClient } from "swarmlord";
15
+
16
+ const client = createClient({
17
+ apiKey: "your-api-key",
18
+ baseUrl: "https://your-worker.your-account.workers.dev",
19
+ });
20
+ ```
21
+
22
+ ## Core Concepts
23
+
24
+ Everything flows from **Agents**. An agent is a configured template — model, tools, instructions, permissions. From an agent you create **Sessions** (interactive), **Tasks** (one-shot), or **Schedules** (recurring).
25
+
26
+ ```
27
+ Agent
28
+ ├── Session (interactive, multi-turn, streaming)
29
+ ├── Task (fire-and-forget, await result)
30
+ └── Schedule (cron-triggered, manageable)
31
+ ```
32
+
33
+ ## Agents
34
+
35
+ ```typescript
36
+ // Use a built-in agent type
37
+ const build = client.agent("build");
38
+
39
+ // Or configure a custom agent
40
+ const reviewer = client.agent({
41
+ name: "build",
42
+ model: "anthropic/claude-sonnet-4-20250514",
43
+ instructions: ["Focus on security and correctness"],
44
+ config: { permission: "allow" },
45
+ });
46
+ ```
47
+
48
+ ## Sessions — Interactive Conversations
49
+
50
+ Sessions are stateful, multi-turn conversations with an agent. They support streaming, tool calls, and permission gates.
51
+
52
+ ```typescript
53
+ const session = await build.createSession({ title: "Build Todo App" });
54
+
55
+ // Stream a message with callbacks
56
+ const result = await session.send("Create a REST API with Hono", {
57
+ onText: delta => process.stdout.write(delta),
58
+ onToolStart: part => console.log(`[tool] ${part["tool"]}`),
59
+ onToolComplete: part => console.log(`[done] ${part["tool"]}`),
60
+ onPermission: async req => "once",
61
+ onError: err => console.error(err),
62
+ });
63
+
64
+ console.log(result.text); // full response text
65
+ console.log(result.parts); // all tool call parts
66
+
67
+ // Continue the conversation
68
+ await session.send("Now add authentication");
69
+
70
+ // Or use the async iterator for full control
71
+ for await (const event of session.stream("Add tests")) {
72
+ switch (event.type) {
73
+ case "text-delta":
74
+ process.stdout.write(event.delta);
75
+ break;
76
+ case "tool-start":
77
+ console.log(`Running: ${event.part["tool"]}`);
78
+ break;
79
+ }
80
+ }
81
+
82
+ // Session management
83
+ await session.summarize(); // trigger context compaction
84
+ await session.revert(messageId); // undo to a specific message
85
+ await session.abort(); // cancel current turn
86
+ await session.delete(); // clean up
87
+
88
+ // Direct sandbox access
89
+ const shellResult = await session.shell("npm test");
90
+ console.log(shellResult.stdout, shellResult.exitCode);
91
+ ```
92
+
93
+ ### Resume an existing session
94
+
95
+ ```typescript
96
+ const session = build.session("existing-session-id");
97
+ await session.send("Continue where we left off");
98
+ ```
99
+
100
+ ### Fork a session
101
+
102
+ ```typescript
103
+ const fork = await build.forkSession("session-to-fork");
104
+ await fork.send("Try a different approach");
105
+ ```
106
+
107
+ ## Tasks — One-Shot Jobs
108
+
109
+ Tasks are fire-and-forget agent runs. Create a session, send a prompt, get back a handle. The agent runs in the background.
110
+
111
+ ```typescript
112
+ // Launch a task
113
+ const task = await build.run("Refactor the auth module to use JWT");
114
+
115
+ // Check on it
116
+ const status = await task.poll(); // "accepted" | "busy" | "idle" | "error"
117
+
118
+ // Block until done
119
+ const result = await task.result({ timeoutMs: 300_000 });
120
+ console.log(result.text); // the agent's final output
121
+ console.log(result.status); // "completed" | "error"
122
+
123
+ // Cancel if needed
124
+ await task.cancel();
125
+ ```
126
+
127
+ ### Tasks with webhooks
128
+
129
+ ```typescript
130
+ const task = await build.run("Update all dependencies", {
131
+ webhook: "https://my-app.com/hooks/agent-done",
132
+ });
133
+ // Webhook receives: { sessionId, status, result, tokens, timestamp }
134
+ ```
135
+
136
+ ### Resume a task from another process
137
+
138
+ ```typescript
139
+ // Save the task ID
140
+ const taskId = task.id;
141
+
142
+ // Later, in another process
143
+ const resumed = client.task(taskId);
144
+ const result = await resumed.result();
145
+ ```
146
+
147
+ ## Schedules — Recurring Jobs
148
+
149
+ Schedules trigger agent runs on a cron. Each trigger creates a Task you can inspect.
150
+
151
+ ```typescript
152
+ const schedule = await reviewer.schedule({
153
+ cron: "0 9 * * 1-5", // weekdays at 9am
154
+ prompt: "Review recent commits for security issues",
155
+ });
156
+
157
+ // Manual trigger — returns a Task handle
158
+ const task = await schedule.trigger();
159
+ const result = await task.result();
160
+
161
+ // Management
162
+ await schedule.pause();
163
+ await schedule.resume();
164
+ await schedule.update({ cron: "0 9 * * *" }); // change to daily
165
+ await schedule.delete();
166
+
167
+ // List all schedules
168
+ const schedules = await client.listSchedules();
169
+ ```
170
+
171
+ ## Client-Level Operations
172
+
173
+ ```typescript
174
+ // List sessions
175
+ const sessions = await client.listSessions({ limit: 20, archived: false });
176
+
177
+ // Resume any handle by ID
178
+ const session = client.session("session-id");
179
+ const task = client.task("task-session-id");
180
+ const schedule = client.schedule("schedule-id");
181
+ ```
182
+
183
+ ## Types
184
+
185
+ All types are exported for use in your own code:
186
+
187
+ ```typescript
188
+ import type {
189
+ AgentHandle,
190
+ SessionHandle,
191
+ TaskHandle,
192
+ ScheduleHandle,
193
+ AgentEvent,
194
+ SendResult,
195
+ TaskResult,
196
+ StreamCallbacks,
197
+ } from "swarmlord";
198
+ ```