@agento-nexus/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.
@@ -0,0 +1,369 @@
1
+ import { Sandbox } from 'e2b';
2
+
3
+ /** Configuration for creating a FangBox sandbox */
4
+ interface FangBoxConfig {
5
+ /** E2B template ID (default: "openfang-claude") */
6
+ templateId?: string;
7
+ /** Environment variables to inject into the sandbox */
8
+ envs?: Record<string, string>;
9
+ /** Sandbox timeout in seconds (default: 300) */
10
+ timeout?: number;
11
+ /** OpenFang daemon port inside sandbox (default: 4200) */
12
+ openfangPort?: number;
13
+ /** Metadata tags for the sandbox */
14
+ metadata?: Record<string, string>;
15
+ }
16
+ /** OpenFang Hand manifest (agent definition) */
17
+ interface HandManifest {
18
+ name: string;
19
+ description?: string;
20
+ model?: string;
21
+ system_prompt?: string;
22
+ tools?: string[];
23
+ max_turns?: number;
24
+ temperature?: number;
25
+ }
26
+ /** Running agent info returned by OpenFang */
27
+ interface AgentInfo {
28
+ id: string;
29
+ name: string;
30
+ status: "running" | "idle" | "error" | "completed";
31
+ created_at: string;
32
+ metadata?: Record<string, unknown>;
33
+ }
34
+ /** Agent message for conversation */
35
+ interface AgentMessage {
36
+ role: "user" | "assistant" | "system";
37
+ content: string;
38
+ timestamp?: string;
39
+ }
40
+ /** Response from messaging an agent */
41
+ interface AgentResponse {
42
+ id: string;
43
+ agent_id: string;
44
+ content: string;
45
+ role: "assistant";
46
+ metadata?: Record<string, unknown>;
47
+ }
48
+ /** Claude Code execution request */
49
+ interface ClaudeCodeRequest {
50
+ prompt: string;
51
+ /** Output format: "text" or "json" (default: "text") */
52
+ outputFormat?: "text" | "json";
53
+ /** Working directory inside sandbox */
54
+ cwd?: string;
55
+ /** Additional CLI flags */
56
+ flags?: string[];
57
+ /** Session ID for multi-turn conversations */
58
+ sessionId?: string;
59
+ /** Max tokens for response */
60
+ maxTokens?: number;
61
+ }
62
+ /** Claude Code execution result */
63
+ interface ClaudeCodeResult {
64
+ output: string;
65
+ exitCode: number;
66
+ /** Parsed JSON output if outputFormat was "json" */
67
+ parsed?: unknown;
68
+ /** Duration in milliseconds */
69
+ durationMs: number;
70
+ sessionId?: string;
71
+ }
72
+ /** OpenFang daemon health response */
73
+ interface HealthResponse {
74
+ status: "ok" | "degraded" | "error";
75
+ version: string;
76
+ uptime_seconds: number;
77
+ agents_running: number;
78
+ }
79
+ /** Tool definition for OpenFang agents */
80
+ interface ToolDefinition {
81
+ name: string;
82
+ description: string;
83
+ parameters?: Record<string, unknown>;
84
+ }
85
+ /** Workflow definition for fleet orchestration */
86
+ interface WorkflowDefinition {
87
+ name: string;
88
+ description?: string;
89
+ version?: string;
90
+ steps: WorkflowStep[];
91
+ /** Global environment variables for all steps */
92
+ envs?: Record<string, string>;
93
+ }
94
+ /** Single step in a workflow */
95
+ interface WorkflowStep {
96
+ id: string;
97
+ name: string;
98
+ /** Hand manifest name or inline definition */
99
+ hand: string | HandManifest;
100
+ /** Prompt template (supports {{outputKey}} interpolation) */
101
+ prompt: string;
102
+ /** Step IDs this step depends on */
103
+ dependsOn?: string[];
104
+ /** Condition to evaluate before running (JS expression) */
105
+ condition?: string;
106
+ /** Key to store output under for downstream steps */
107
+ outputKey?: string;
108
+ /** Override sandbox config for this step */
109
+ config?: FangBoxConfig;
110
+ /** Timeout for this step in seconds */
111
+ timeout?: number;
112
+ }
113
+ /** Result of a single workflow step */
114
+ interface StepResult {
115
+ stepId: string;
116
+ status: "success" | "failure" | "skipped";
117
+ output?: string;
118
+ error?: string;
119
+ durationMs: number;
120
+ }
121
+ /** Result of a complete workflow run */
122
+ interface WorkflowResult {
123
+ workflowName: string;
124
+ status: "success" | "partial" | "failure";
125
+ steps: StepResult[];
126
+ totalDurationMs: number;
127
+ outputs: Record<string, string>;
128
+ }
129
+ /** Events emitted by FangBox and Fleet */
130
+ type FangBoxEvent = {
131
+ type: "sandbox:creating";
132
+ } | {
133
+ type: "sandbox:ready";
134
+ sandboxId: string;
135
+ } | {
136
+ type: "sandbox:error";
137
+ error: Error;
138
+ } | {
139
+ type: "sandbox:destroyed";
140
+ sandboxId: string;
141
+ } | {
142
+ type: "daemon:starting";
143
+ } | {
144
+ type: "daemon:healthy";
145
+ version: string;
146
+ } | {
147
+ type: "daemon:unhealthy";
148
+ error: string;
149
+ } | {
150
+ type: "agent:spawned";
151
+ agentId: string;
152
+ name: string;
153
+ } | {
154
+ type: "agent:message";
155
+ agentId: string;
156
+ content: string;
157
+ } | {
158
+ type: "agent:completed";
159
+ agentId: string;
160
+ } | {
161
+ type: "agent:error";
162
+ agentId: string;
163
+ error: string;
164
+ };
165
+ type FleetEvent = {
166
+ type: "workflow:start";
167
+ name: string;
168
+ } | {
169
+ type: "workflow:complete";
170
+ result: WorkflowResult;
171
+ } | {
172
+ type: "step:start";
173
+ stepId: string;
174
+ } | {
175
+ type: "step:complete";
176
+ stepId: string;
177
+ result: StepResult;
178
+ } | {
179
+ type: "step:skip";
180
+ stepId: string;
181
+ reason: string;
182
+ };
183
+ /** E2B template build configuration */
184
+ interface TemplateBuildConfig {
185
+ /** Base E2B template to extend (default: "claude") */
186
+ baseTemplate?: string;
187
+ /** OpenFang version to install */
188
+ openfangVersion?: string;
189
+ /** Additional packages to install */
190
+ packages?: string[];
191
+ /** Custom setup script to run */
192
+ setupScript?: string;
193
+ }
194
+
195
+ interface RetryOptions {
196
+ maxAttempts?: number;
197
+ initialDelayMs?: number;
198
+ maxDelayMs?: number;
199
+ backoffMultiplier?: number;
200
+ retryIf?: (error: unknown) => boolean;
201
+ }
202
+ declare function retry<T>(fn: () => Promise<T>, opts?: RetryOptions): Promise<T>;
203
+
204
+ interface OpenFangClientConfig {
205
+ /** Base URL for the OpenFang REST API */
206
+ baseUrl: string;
207
+ /** Request timeout in ms (default: 30000) */
208
+ timeoutMs?: number;
209
+ /** Retry options for failed requests */
210
+ retryOptions?: RetryOptions;
211
+ }
212
+ declare class OpenFangClient {
213
+ private baseUrl;
214
+ private timeoutMs;
215
+ private retryOpts;
216
+ private log;
217
+ constructor(config: OpenFangClientConfig);
218
+ /** Check daemon health */
219
+ health(): Promise<HealthResponse>;
220
+ /** Wait for daemon to become healthy */
221
+ waitForHealthy(maxWaitMs?: number): Promise<HealthResponse>;
222
+ /** Spawn a new agent from a Hand manifest */
223
+ spawnAgent(manifest: HandManifest): Promise<AgentInfo>;
224
+ /** List all running agents */
225
+ listAgents(): Promise<AgentInfo[]>;
226
+ /** Get agent info by ID */
227
+ getAgent(agentId: string): Promise<AgentInfo>;
228
+ /** Send a message to an agent */
229
+ messageAgent(agentId: string, content: string): Promise<AgentResponse>;
230
+ /** Stop an agent */
231
+ stopAgent(agentId: string): Promise<void>;
232
+ /** List available tools */
233
+ listTools(): Promise<ToolDefinition[]>;
234
+ private request;
235
+ }
236
+ declare class OpenFangError extends Error {
237
+ statusCode: number;
238
+ constructor(message: string, statusCode: number);
239
+ }
240
+
241
+ declare class ClaudeBridge {
242
+ private sandbox;
243
+ private log;
244
+ constructor(sandbox: Sandbox);
245
+ /** Execute a Claude Code prompt inside the sandbox */
246
+ execute(request: ClaudeCodeRequest): Promise<ClaudeCodeResult>;
247
+ /** Check if Claude Code is installed in the sandbox */
248
+ isAvailable(): Promise<boolean>;
249
+ private buildArgs;
250
+ private shellEscape;
251
+ }
252
+
253
+ type Listener<T> = (event: T) => void;
254
+ declare class TypedEmitter<T> {
255
+ private listeners;
256
+ on(listener: Listener<T>): () => void;
257
+ emit(event: T): void;
258
+ removeAll(): void;
259
+ }
260
+
261
+ declare class FangBox {
262
+ readonly sandbox: Sandbox;
263
+ readonly client: OpenFangClient;
264
+ readonly claudeBridge: ClaudeBridge;
265
+ readonly events: TypedEmitter<FangBoxEvent>;
266
+ private log;
267
+ private constructor();
268
+ /**
269
+ * Create a new FangBox — spins up sandbox, starts daemon, waits for health.
270
+ * All commands run inside the E2B cloud sandbox (not local shell).
271
+ */
272
+ static create(config?: FangBoxConfig): Promise<FangBox>;
273
+ get sandboxId(): string;
274
+ /** Check daemon health */
275
+ health(): Promise<HealthResponse>;
276
+ /** Spawn an agent from a Hand manifest or name */
277
+ spawnAgent(handOrName: HandManifest | string): Promise<AgentInfo>;
278
+ /** Send a message to a running agent */
279
+ messageAgent(agentId: string, content: string): Promise<AgentResponse>;
280
+ /** List all running agents */
281
+ listAgents(): Promise<AgentInfo[]>;
282
+ /** Stop an agent */
283
+ stopAgent(agentId: string): Promise<void>;
284
+ /** Execute Claude Code in the sandbox */
285
+ runClaude(request: ClaudeCodeRequest): Promise<ClaudeCodeResult>;
286
+ /** Upload a file to the sandbox */
287
+ uploadFile(path: string, content: string): Promise<void>;
288
+ /** Read a file from the sandbox */
289
+ readFile(path: string): Promise<string>;
290
+ /**
291
+ * Run a command inside the E2B cloud sandbox.
292
+ * This uses E2B's sandbox.commands.run() which executes remotely,
293
+ * not on the local machine.
294
+ */
295
+ runInSandbox(command: string, opts?: {
296
+ cwd?: string;
297
+ timeoutMs?: number;
298
+ }): Promise<{
299
+ stdout: string;
300
+ stderr: string;
301
+ exitCode: number;
302
+ }>;
303
+ /** Destroy the sandbox */
304
+ destroy(): Promise<void>;
305
+ }
306
+ /** Convenience function to create a FangBox */
307
+ declare function createFangBox(config?: FangBoxConfig): Promise<FangBox>;
308
+
309
+ interface FleetConfig {
310
+ /** Max concurrent sandboxes (default: 3) */
311
+ maxConcurrency?: number;
312
+ /** Default sandbox timeout in seconds */
313
+ defaultTimeout?: number;
314
+ /** Default environment variables for all sandboxes */
315
+ envs?: Record<string, string>;
316
+ }
317
+ declare class Fleet {
318
+ readonly events: TypedEmitter<FleetEvent>;
319
+ private log;
320
+ private maxConcurrency;
321
+ private defaultTimeout;
322
+ private envs;
323
+ constructor(config?: FleetConfig);
324
+ /** Run a workflow from a parsed definition */
325
+ run(workflow: WorkflowDefinition): Promise<WorkflowResult>;
326
+ /** Load and run a workflow from a JSON file path */
327
+ runFromFile(filePath: string): Promise<WorkflowResult>;
328
+ private executeStep;
329
+ /** Interpolate {{outputKey}} placeholders in a string */
330
+ private interpolate;
331
+ /**
332
+ * Evaluate a condition against available outputs.
333
+ * Supports safe expressions: "outputKey", "!outputKey",
334
+ * "outputKey == 'value'", "outputKey != 'value'"
335
+ */
336
+ private evaluateCondition;
337
+ /** Topological sort of workflow steps using Kahn's algorithm */
338
+ private topologicalSort;
339
+ }
340
+
341
+ declare class TemplateBuilder {
342
+ private log;
343
+ constructor();
344
+ /** Build an E2B template with OpenFang installed */
345
+ build(config?: TemplateBuildConfig): Promise<{
346
+ templateId: string;
347
+ openfangVersion: string;
348
+ }>;
349
+ /** Verify an existing template has OpenFang ready */
350
+ verify(templateId: string): Promise<{
351
+ healthy: boolean;
352
+ version?: string;
353
+ error?: string;
354
+ }>;
355
+ }
356
+
357
+ type LogLevel = "debug" | "info" | "warn" | "error";
358
+ declare class Logger {
359
+ private prefix;
360
+ private minLevel;
361
+ constructor(prefix: string, level?: LogLevel);
362
+ debug(msg: string, data?: Record<string, unknown>): void;
363
+ info(msg: string, data?: Record<string, unknown>): void;
364
+ warn(msg: string, data?: Record<string, unknown>): void;
365
+ error(msg: string, data?: Record<string, unknown>): void;
366
+ private log;
367
+ }
368
+
369
+ export { type AgentInfo, type AgentMessage, type AgentResponse, ClaudeBridge, type ClaudeCodeRequest, type ClaudeCodeResult, FangBox, type FangBoxConfig, type FangBoxEvent, Fleet, type FleetEvent, type HandManifest, type HealthResponse, Logger, OpenFangClient, OpenFangError, type StepResult, type TemplateBuildConfig, TemplateBuilder, type ToolDefinition, TypedEmitter, type WorkflowDefinition, type WorkflowResult, type WorkflowStep, createFangBox, retry };
@@ -0,0 +1,25 @@
1
+ import {
2
+ ClaudeBridge,
3
+ FangBox,
4
+ Fleet,
5
+ Logger,
6
+ OpenFangClient,
7
+ OpenFangError,
8
+ TemplateBuilder,
9
+ TypedEmitter,
10
+ createFangBox,
11
+ retry
12
+ } from "../chunk-UXIUTT4T.js";
13
+ export {
14
+ ClaudeBridge,
15
+ FangBox,
16
+ Fleet,
17
+ Logger,
18
+ OpenFangClient,
19
+ OpenFangError,
20
+ TemplateBuilder,
21
+ TypedEmitter,
22
+ createFangBox,
23
+ retry
24
+ };
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@agento-nexus/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Agent OS in Cloud Sandboxes — OpenFang + E2B + Claude Code",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "agento-sdk": "./dist/cli/bin.js"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "build": "tsup",
19
+ "dev": "tsup --watch",
20
+ "typecheck": "tsc --noEmit",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest",
23
+ "lint": "tsc --noEmit"
24
+ },
25
+ "dependencies": {
26
+ "e2b": "^1.2.0",
27
+ "commander": "^13.1.0",
28
+ "chalk": "^5.4.1"
29
+ },
30
+ "devDependencies": {
31
+ "typescript": "^5.7.3",
32
+ "tsup": "^8.4.0",
33
+ "vitest": "^3.0.0",
34
+ "@types/node": "^22.12.0"
35
+ },
36
+ "files": [
37
+ "dist"
38
+ ],
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/agento-nexus/sdk.git"
43
+ },
44
+ "engines": {
45
+ "node": ">=20"
46
+ }
47
+ }