@agentstep/agent-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/package.json +45 -0
- package/src/auth/middleware.ts +38 -0
- package/src/backends/claude/args.ts +88 -0
- package/src/backends/claude/index.ts +193 -0
- package/src/backends/claude/permission-hook.ts +152 -0
- package/src/backends/claude/tool-bridge.ts +211 -0
- package/src/backends/claude/translator.ts +209 -0
- package/src/backends/claude/wrapper-script.ts +45 -0
- package/src/backends/codex/args.ts +69 -0
- package/src/backends/codex/auth.ts +35 -0
- package/src/backends/codex/index.ts +57 -0
- package/src/backends/codex/setup.ts +37 -0
- package/src/backends/codex/translator.ts +223 -0
- package/src/backends/codex/wrapper-script.ts +26 -0
- package/src/backends/factory/args.ts +45 -0
- package/src/backends/factory/auth.ts +30 -0
- package/src/backends/factory/index.ts +56 -0
- package/src/backends/factory/setup.ts +34 -0
- package/src/backends/factory/translator.ts +139 -0
- package/src/backends/factory/wrapper-script.ts +33 -0
- package/src/backends/gemini/args.ts +44 -0
- package/src/backends/gemini/auth.ts +30 -0
- package/src/backends/gemini/index.ts +53 -0
- package/src/backends/gemini/setup.ts +34 -0
- package/src/backends/gemini/translator.ts +139 -0
- package/src/backends/gemini/wrapper-script.ts +26 -0
- package/src/backends/opencode/args.ts +53 -0
- package/src/backends/opencode/auth.ts +53 -0
- package/src/backends/opencode/index.ts +70 -0
- package/src/backends/opencode/mcp.ts +67 -0
- package/src/backends/opencode/setup.ts +54 -0
- package/src/backends/opencode/translator.ts +168 -0
- package/src/backends/opencode/wrapper-script.ts +46 -0
- package/src/backends/registry.ts +38 -0
- package/src/backends/shared/ndjson.ts +29 -0
- package/src/backends/shared/translator-types.ts +69 -0
- package/src/backends/shared/wrap-prompt.ts +17 -0
- package/src/backends/types.ts +85 -0
- package/src/config/index.ts +95 -0
- package/src/db/agents.ts +185 -0
- package/src/db/api_keys.ts +78 -0
- package/src/db/batch.ts +142 -0
- package/src/db/client.ts +81 -0
- package/src/db/environments.ts +127 -0
- package/src/db/events.ts +208 -0
- package/src/db/memory.ts +143 -0
- package/src/db/migrations.ts +295 -0
- package/src/db/proxy.ts +37 -0
- package/src/db/sessions.ts +295 -0
- package/src/db/vaults.ts +110 -0
- package/src/errors.ts +53 -0
- package/src/handlers/agents.ts +194 -0
- package/src/handlers/batch.ts +41 -0
- package/src/handlers/docs.ts +87 -0
- package/src/handlers/environments.ts +154 -0
- package/src/handlers/events.ts +234 -0
- package/src/handlers/index.ts +12 -0
- package/src/handlers/memory.ts +141 -0
- package/src/handlers/openapi.ts +14 -0
- package/src/handlers/sessions.ts +223 -0
- package/src/handlers/stream.ts +76 -0
- package/src/handlers/threads.ts +26 -0
- package/src/handlers/ui/app.js +984 -0
- package/src/handlers/ui/index.html +112 -0
- package/src/handlers/ui/style.css +164 -0
- package/src/handlers/ui.ts +1281 -0
- package/src/handlers/vaults.ts +99 -0
- package/src/http.ts +35 -0
- package/src/index.ts +104 -0
- package/src/init.ts +227 -0
- package/src/openapi/registry.ts +8 -0
- package/src/openapi/schemas.ts +625 -0
- package/src/openapi/spec.ts +691 -0
- package/src/providers/apple.ts +220 -0
- package/src/providers/daytona.ts +217 -0
- package/src/providers/docker.ts +264 -0
- package/src/providers/e2b.ts +203 -0
- package/src/providers/fly.ts +276 -0
- package/src/providers/modal.ts +222 -0
- package/src/providers/podman.ts +206 -0
- package/src/providers/registry.ts +28 -0
- package/src/providers/shared.ts +11 -0
- package/src/providers/sprites.ts +55 -0
- package/src/providers/types.ts +73 -0
- package/src/providers/vercel.ts +208 -0
- package/src/proxy/forward.ts +111 -0
- package/src/queue/index.ts +111 -0
- package/src/sessions/actor.ts +53 -0
- package/src/sessions/bus.ts +155 -0
- package/src/sessions/driver.ts +818 -0
- package/src/sessions/grader.ts +120 -0
- package/src/sessions/interrupt.ts +14 -0
- package/src/sessions/sweeper.ts +136 -0
- package/src/sessions/threads.ts +126 -0
- package/src/sessions/tools.ts +50 -0
- package/src/shutdown.ts +78 -0
- package/src/sprite/client.ts +294 -0
- package/src/sprite/exec.ts +161 -0
- package/src/sprite/lifecycle.ts +339 -0
- package/src/sprite/pool.ts +65 -0
- package/src/sprite/setup.ts +159 -0
- package/src/state.ts +61 -0
- package/src/types.ts +339 -0
- package/src/util/clock.ts +7 -0
- package/src/util/ids.ts +11 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared TypeScript types for managed-agents.
|
|
3
|
+
*
|
|
4
|
+
* Resource shapes mirror the Claude Managed Agents API as closely as possible
|
|
5
|
+
* so that the `@anthropic-ai/sdk` (with `baseURL` override) can be used as a
|
|
6
|
+
* client against this service.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Tool config (mirrors agent_toolset_20260401)
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
export const BUILT_IN_TOOL_NAMES = [
|
|
14
|
+
"Bash",
|
|
15
|
+
"Read",
|
|
16
|
+
"Write",
|
|
17
|
+
"Edit",
|
|
18
|
+
"Glob",
|
|
19
|
+
"Grep",
|
|
20
|
+
"WebFetch",
|
|
21
|
+
"WebSearch",
|
|
22
|
+
] as const;
|
|
23
|
+
|
|
24
|
+
export type BuiltInToolName = (typeof BUILT_IN_TOOL_NAMES)[number];
|
|
25
|
+
|
|
26
|
+
export interface AgentToolsetTool {
|
|
27
|
+
type: "agent_toolset_20260401";
|
|
28
|
+
configs?: Array<{ name: string; enabled?: boolean }>;
|
|
29
|
+
default_config?: { enabled?: boolean };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CustomTool {
|
|
33
|
+
type: "custom";
|
|
34
|
+
name: string;
|
|
35
|
+
description: string;
|
|
36
|
+
input_schema: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type ToolConfig = AgentToolsetTool | CustomTool;
|
|
40
|
+
|
|
41
|
+
export interface McpServerConfig {
|
|
42
|
+
type?: "stdio" | "http" | "sse";
|
|
43
|
+
url?: string;
|
|
44
|
+
command?: string | string[];
|
|
45
|
+
args?: string[];
|
|
46
|
+
headers?: Record<string, string>;
|
|
47
|
+
env?: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Agent / AgentVersion
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Which CLI engine powers a session's turns. Declared locally (not imported
|
|
56
|
+
* from lib/backends/types.ts) to avoid a circular import between types and
|
|
57
|
+
* the backend registry.
|
|
58
|
+
*/
|
|
59
|
+
export type BackendName = "claude" | "opencode" | "codex" | "anthropic" | "gemini" | "factory";
|
|
60
|
+
|
|
61
|
+
export interface AgentRow {
|
|
62
|
+
id: string;
|
|
63
|
+
current_version: number;
|
|
64
|
+
name: string;
|
|
65
|
+
created_at: number;
|
|
66
|
+
updated_at: number;
|
|
67
|
+
archived_at: number | null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface AgentVersionRow {
|
|
71
|
+
agent_id: string;
|
|
72
|
+
version: number;
|
|
73
|
+
model: string;
|
|
74
|
+
system: string | null;
|
|
75
|
+
tools_json: string;
|
|
76
|
+
mcp_servers_json: string;
|
|
77
|
+
backend: BackendName;
|
|
78
|
+
webhook_url: string | null;
|
|
79
|
+
webhook_events_json: string;
|
|
80
|
+
threads_enabled: number;
|
|
81
|
+
confirmation_mode: number;
|
|
82
|
+
callable_agents_json: string | null;
|
|
83
|
+
created_at: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface Agent {
|
|
87
|
+
id: string;
|
|
88
|
+
version: number;
|
|
89
|
+
name: string;
|
|
90
|
+
model: string;
|
|
91
|
+
system: string | null;
|
|
92
|
+
tools: ToolConfig[];
|
|
93
|
+
mcp_servers: Record<string, McpServerConfig>;
|
|
94
|
+
backend: BackendName;
|
|
95
|
+
webhook_url: string | null;
|
|
96
|
+
webhook_events: string[];
|
|
97
|
+
threads_enabled: boolean;
|
|
98
|
+
confirmation_mode: boolean;
|
|
99
|
+
callable_agents: Array<{ type: "agent"; id: string; version?: number }>;
|
|
100
|
+
created_at: string;
|
|
101
|
+
updated_at: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Environment
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
export type EnvironmentState = "preparing" | "ready" | "failed";
|
|
109
|
+
|
|
110
|
+
export interface EnvironmentConfig {
|
|
111
|
+
type: "cloud";
|
|
112
|
+
provider?: "sprites" | "docker" | "apple" | "podman" | "e2b" | "vercel" | "daytona" | "fly" | "modal";
|
|
113
|
+
packages?: {
|
|
114
|
+
apt?: string[];
|
|
115
|
+
cargo?: string[];
|
|
116
|
+
gem?: string[];
|
|
117
|
+
go?: string[];
|
|
118
|
+
npm?: string[];
|
|
119
|
+
pip?: string[];
|
|
120
|
+
};
|
|
121
|
+
networking?:
|
|
122
|
+
| { type: "unrestricted" }
|
|
123
|
+
| {
|
|
124
|
+
type: "limited";
|
|
125
|
+
allowed_hosts?: string[];
|
|
126
|
+
allow_mcp_servers?: boolean;
|
|
127
|
+
allow_package_managers?: boolean;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface EnvironmentRow {
|
|
132
|
+
id: string;
|
|
133
|
+
name: string;
|
|
134
|
+
config_json: string;
|
|
135
|
+
state: EnvironmentState;
|
|
136
|
+
state_message: string | null;
|
|
137
|
+
template_sprite: string | null;
|
|
138
|
+
checkpoint_id: string | null;
|
|
139
|
+
created_at: number;
|
|
140
|
+
archived_at: number | null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface Environment {
|
|
144
|
+
id: string;
|
|
145
|
+
name: string;
|
|
146
|
+
config: EnvironmentConfig;
|
|
147
|
+
state: EnvironmentState;
|
|
148
|
+
state_message: string | null;
|
|
149
|
+
created_at: string;
|
|
150
|
+
archived_at: string | null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
// Session
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
|
|
157
|
+
export type SessionStatus = "idle" | "running" | "rescheduling" | "terminated";
|
|
158
|
+
|
|
159
|
+
export interface SessionRow {
|
|
160
|
+
id: string;
|
|
161
|
+
agent_id: string;
|
|
162
|
+
agent_version: number;
|
|
163
|
+
environment_id: string;
|
|
164
|
+
sprite_name: string | null;
|
|
165
|
+
claude_session_id: string | null;
|
|
166
|
+
status: SessionStatus;
|
|
167
|
+
stop_reason: string | null;
|
|
168
|
+
title: string | null;
|
|
169
|
+
metadata_json: string;
|
|
170
|
+
turn_count: number;
|
|
171
|
+
tool_calls_count: number;
|
|
172
|
+
active_seconds: number;
|
|
173
|
+
duration_seconds: number;
|
|
174
|
+
usage_input_tokens: number;
|
|
175
|
+
usage_output_tokens: number;
|
|
176
|
+
usage_cache_read_input_tokens: number;
|
|
177
|
+
usage_cache_creation_input_tokens: number;
|
|
178
|
+
usage_cost_usd: number;
|
|
179
|
+
last_seq: number;
|
|
180
|
+
idle_since: number | null;
|
|
181
|
+
parked_checkpoint_id: string | null;
|
|
182
|
+
provider_name: string;
|
|
183
|
+
max_budget_usd: number | null;
|
|
184
|
+
outcome_criteria_json: string | null;
|
|
185
|
+
resources_json: string | null;
|
|
186
|
+
vault_ids_json: string | null;
|
|
187
|
+
parent_session_id: string | null;
|
|
188
|
+
thread_depth: number;
|
|
189
|
+
created_at: number;
|
|
190
|
+
updated_at: number;
|
|
191
|
+
archived_at: number | null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface SessionResource {
|
|
195
|
+
type: "uri" | "text";
|
|
196
|
+
uri?: string;
|
|
197
|
+
content?: string;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface Session {
|
|
201
|
+
id: string;
|
|
202
|
+
agent: { id: string; version: number };
|
|
203
|
+
environment_id: string;
|
|
204
|
+
status: SessionStatus;
|
|
205
|
+
stop_reason: string | null;
|
|
206
|
+
title: string | null;
|
|
207
|
+
metadata: Record<string, unknown>;
|
|
208
|
+
max_budget_usd: number | null;
|
|
209
|
+
outcome: Record<string, unknown> | null;
|
|
210
|
+
resources: SessionResource[] | null;
|
|
211
|
+
vault_ids: string[] | null;
|
|
212
|
+
parent_session_id: string | null;
|
|
213
|
+
thread_depth: number;
|
|
214
|
+
stats: {
|
|
215
|
+
turn_count: number;
|
|
216
|
+
tool_calls_count: number;
|
|
217
|
+
active_seconds: number;
|
|
218
|
+
duration_seconds: number;
|
|
219
|
+
};
|
|
220
|
+
usage: {
|
|
221
|
+
input_tokens: number;
|
|
222
|
+
output_tokens: number;
|
|
223
|
+
cache_read_input_tokens: number;
|
|
224
|
+
cache_creation_input_tokens: number;
|
|
225
|
+
cost_usd: number;
|
|
226
|
+
};
|
|
227
|
+
created_at: string;
|
|
228
|
+
updated_at: string;
|
|
229
|
+
archived_at: string | null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
233
|
+
// Vaults
|
|
234
|
+
// ---------------------------------------------------------------------------
|
|
235
|
+
|
|
236
|
+
export interface VaultRow {
|
|
237
|
+
id: string;
|
|
238
|
+
agent_id: string;
|
|
239
|
+
name: string;
|
|
240
|
+
created_at: number;
|
|
241
|
+
updated_at: number;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface Vault {
|
|
245
|
+
id: string;
|
|
246
|
+
agent_id: string;
|
|
247
|
+
name: string;
|
|
248
|
+
created_at: string;
|
|
249
|
+
updated_at: string;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface VaultEntryRow {
|
|
253
|
+
vault_id: string;
|
|
254
|
+
key: string;
|
|
255
|
+
value: string;
|
|
256
|
+
updated_at: number;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export interface VaultEntry {
|
|
260
|
+
key: string;
|
|
261
|
+
value: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// ---------------------------------------------------------------------------
|
|
265
|
+
// Memory Stores
|
|
266
|
+
// ---------------------------------------------------------------------------
|
|
267
|
+
|
|
268
|
+
export interface MemoryStoreRow {
|
|
269
|
+
id: string;
|
|
270
|
+
name: string;
|
|
271
|
+
description: string | null;
|
|
272
|
+
created_at: number;
|
|
273
|
+
updated_at: number;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface MemoryStore {
|
|
277
|
+
id: string;
|
|
278
|
+
name: string;
|
|
279
|
+
description: string | null;
|
|
280
|
+
created_at: string;
|
|
281
|
+
updated_at: string;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export interface MemoryRow {
|
|
285
|
+
id: string;
|
|
286
|
+
store_id: string;
|
|
287
|
+
path: string;
|
|
288
|
+
content: string;
|
|
289
|
+
content_sha256: string;
|
|
290
|
+
created_at: number;
|
|
291
|
+
updated_at: number;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export interface Memory {
|
|
295
|
+
id: string;
|
|
296
|
+
store_id: string;
|
|
297
|
+
path: string;
|
|
298
|
+
content: string;
|
|
299
|
+
content_sha256: string;
|
|
300
|
+
created_at: string;
|
|
301
|
+
updated_at: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ---------------------------------------------------------------------------
|
|
305
|
+
// Events
|
|
306
|
+
// ---------------------------------------------------------------------------
|
|
307
|
+
|
|
308
|
+
export type EventOrigin = "user" | "server";
|
|
309
|
+
|
|
310
|
+
export interface EventRow {
|
|
311
|
+
id: string;
|
|
312
|
+
session_id: string;
|
|
313
|
+
seq: number;
|
|
314
|
+
type: string;
|
|
315
|
+
payload_json: string;
|
|
316
|
+
processed_at: number | null;
|
|
317
|
+
received_at: number;
|
|
318
|
+
origin: EventOrigin;
|
|
319
|
+
idempotency_key: string | null;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface ManagedEvent {
|
|
323
|
+
id: string;
|
|
324
|
+
seq: number;
|
|
325
|
+
session_id: string;
|
|
326
|
+
type: string;
|
|
327
|
+
processed_at: string | null;
|
|
328
|
+
[key: string]: unknown;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ---------------------------------------------------------------------------
|
|
332
|
+
// Auth
|
|
333
|
+
// ---------------------------------------------------------------------------
|
|
334
|
+
|
|
335
|
+
export interface AuthContext {
|
|
336
|
+
keyId: string;
|
|
337
|
+
name: string;
|
|
338
|
+
permissions: string[];
|
|
339
|
+
}
|
package/src/util/ids.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ulid } from "ulid";
|
|
2
|
+
|
|
3
|
+
type Prefix = "agent" | "ver" | "env" | "sess" | "evt" | "key" | "ckpt" | "span" | "vault" | "ms" | "mem";
|
|
4
|
+
|
|
5
|
+
export function newId(prefix: Prefix): string {
|
|
6
|
+
return `${prefix}_${ulid()}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isId(prefix: Prefix, value: unknown): value is string {
|
|
10
|
+
return typeof value === "string" && value.startsWith(`${prefix}_`);
|
|
11
|
+
}
|