neckbeard-agent 0.0.1
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 +106 -0
- package/dist/index.cjs +590 -0
- package/dist/index.d.cts +188 -0
- package/dist/index.d.ts +188 -0
- package/dist/index.js +556 -0
- package/package.json +73 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-neckbeard - Deploy AI agents to E2B sandboxes
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Base error class for agent-neckbeard errors.
|
|
6
|
+
* All custom errors extend this class.
|
|
7
|
+
*/
|
|
8
|
+
declare class NeckbeardError extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when sandbox deployment fails.
|
|
13
|
+
* This includes sandbox creation, dependency installation, and file upload failures.
|
|
14
|
+
*/
|
|
15
|
+
declare class DeploymentError extends NeckbeardError {
|
|
16
|
+
readonly cause?: Error | undefined;
|
|
17
|
+
constructor(message: string, cause?: Error | undefined);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error thrown when input or output schema validation fails.
|
|
21
|
+
*/
|
|
22
|
+
declare class ValidationError extends NeckbeardError {
|
|
23
|
+
readonly cause?: Error | undefined;
|
|
24
|
+
constructor(message: string, cause?: Error | undefined);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Error thrown when agent execution fails in the sandbox.
|
|
28
|
+
*/
|
|
29
|
+
declare class ExecutionError extends NeckbeardError {
|
|
30
|
+
readonly cause?: Error | undefined;
|
|
31
|
+
constructor(message: string, cause?: Error | undefined);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Error thrown when required environment variables are missing.
|
|
35
|
+
*/
|
|
36
|
+
declare class ConfigurationError extends NeckbeardError {
|
|
37
|
+
constructor(message: string);
|
|
38
|
+
}
|
|
39
|
+
interface AgentRunContext {
|
|
40
|
+
executionId: string;
|
|
41
|
+
signal: AbortSignal;
|
|
42
|
+
env: Record<string, string>;
|
|
43
|
+
logger: {
|
|
44
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
45
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
46
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
47
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
type AgentRunResult<TOutput> = {
|
|
51
|
+
ok: true;
|
|
52
|
+
executionId: string;
|
|
53
|
+
output: TOutput;
|
|
54
|
+
} | {
|
|
55
|
+
ok: false;
|
|
56
|
+
executionId: string;
|
|
57
|
+
error: Error | NeckbeardError;
|
|
58
|
+
};
|
|
59
|
+
interface SchemaLike<T> {
|
|
60
|
+
parse: (data: unknown) => T;
|
|
61
|
+
}
|
|
62
|
+
interface OsDependencies {
|
|
63
|
+
/** APT packages to install (e.g., ['curl', 'git']) */
|
|
64
|
+
apt?: string[];
|
|
65
|
+
/** Custom shell commands to run during setup */
|
|
66
|
+
commands?: string[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Configuration for downloading a file into the sandbox filesystem.
|
|
70
|
+
* Files are downloaded during deploy() before the agent runs.
|
|
71
|
+
*/
|
|
72
|
+
interface FileDownload {
|
|
73
|
+
/** URL to download the file from (supports http/https) */
|
|
74
|
+
url: string;
|
|
75
|
+
/**
|
|
76
|
+
* Destination path in the sandbox.
|
|
77
|
+
* Can be absolute (e.g., '/home/user/data/model.bin') or
|
|
78
|
+
* relative to /home/user/ (e.g., 'data/model.bin').
|
|
79
|
+
* Parent directories are created automatically.
|
|
80
|
+
*/
|
|
81
|
+
path: string;
|
|
82
|
+
}
|
|
83
|
+
/** Default dependencies - empty by default, specify what you need */
|
|
84
|
+
declare const DEFAULT_DEPENDENCIES: OsDependencies;
|
|
85
|
+
interface AgentConfig<TInput, TOutput> {
|
|
86
|
+
/**
|
|
87
|
+
* E2B template name or ID to use for the sandbox.
|
|
88
|
+
* Templates define the sandbox's CPU, memory, and pre-installed software.
|
|
89
|
+
*
|
|
90
|
+
* Common templates:
|
|
91
|
+
* - 'code-interpreter-v1': 2 cores, 2048 MB (recommended for Claude Agent SDK)
|
|
92
|
+
* - 'base': 2 cores, 512 MB (minimal)
|
|
93
|
+
* - 'desktop': 8 cores, 8192 MB (for heavy workloads)
|
|
94
|
+
*
|
|
95
|
+
* Create custom templates via E2B CLI:
|
|
96
|
+
* e2b template build --cpu-count 4 --memory-mb 4096 --name my-template
|
|
97
|
+
*
|
|
98
|
+
* @see https://e2b.dev/docs/template/overview
|
|
99
|
+
*/
|
|
100
|
+
template: string;
|
|
101
|
+
inputSchema: SchemaLike<TInput>;
|
|
102
|
+
outputSchema: SchemaLike<TOutput>;
|
|
103
|
+
run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
|
|
104
|
+
maxDuration?: number;
|
|
105
|
+
sandboxId?: string;
|
|
106
|
+
/** OS-level dependencies to install in the sandbox. Defaults to Claude Code. Set to {} to skip. */
|
|
107
|
+
dependencies?: OsDependencies;
|
|
108
|
+
/**
|
|
109
|
+
* Files to download and initialize in the sandbox filesystem.
|
|
110
|
+
* Downloaded during deploy() before the agent code runs.
|
|
111
|
+
* Useful for pre-loading models, datasets, configuration files, etc.
|
|
112
|
+
*/
|
|
113
|
+
files?: FileDownload[];
|
|
114
|
+
/**
|
|
115
|
+
* Local path to a .claude directory containing skills and settings.
|
|
116
|
+
* The directory will be uploaded to /home/user/agent/.claude/ in the sandbox.
|
|
117
|
+
* This enables Claude Agent SDK to access skills defined in SKILL.md files
|
|
118
|
+
* within .claude/skills/ subdirectories.
|
|
119
|
+
*
|
|
120
|
+
* Example: claudeDir: './my-project/.claude'
|
|
121
|
+
*
|
|
122
|
+
* The Claude Agent SDK will discover skills when:
|
|
123
|
+
* - cwd is set to /home/user/agent/ (containing .claude/)
|
|
124
|
+
* - settingSources includes 'project'
|
|
125
|
+
* - allowedTools includes 'Skill'
|
|
126
|
+
*/
|
|
127
|
+
claudeDir?: string;
|
|
128
|
+
}
|
|
129
|
+
declare class Agent<TInput, TOutput> {
|
|
130
|
+
readonly template: string;
|
|
131
|
+
readonly inputSchema: SchemaLike<TInput>;
|
|
132
|
+
readonly outputSchema: SchemaLike<TOutput>;
|
|
133
|
+
readonly maxDuration: number;
|
|
134
|
+
readonly dependencies: OsDependencies;
|
|
135
|
+
readonly files: FileDownload[];
|
|
136
|
+
readonly claudeDir?: string;
|
|
137
|
+
/** @internal Used by the sandbox runner - must be public for bundled code access */
|
|
138
|
+
_run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
|
|
139
|
+
private _sourceFile;
|
|
140
|
+
private _sandboxId?;
|
|
141
|
+
constructor(config: AgentConfig<TInput, TOutput>);
|
|
142
|
+
get sandboxId(): string | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Deploys the agent to an E2B sandbox.
|
|
145
|
+
*
|
|
146
|
+
* This method bundles the agent code using esbuild, creates a new E2B sandbox,
|
|
147
|
+
* installs any specified OS dependencies, downloads configured files, and
|
|
148
|
+
* uploads the agent code to the sandbox.
|
|
149
|
+
*
|
|
150
|
+
* The sandbox ID is stored and can be accessed via the `sandboxId` property
|
|
151
|
+
* after deployment completes.
|
|
152
|
+
*
|
|
153
|
+
* @throws {ConfigurationError} If E2B_API_KEY environment variable is not set
|
|
154
|
+
* @throws {DeploymentError} If sandbox creation, dependency installation, or file upload fails
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const agent = new Agent({ ... });
|
|
159
|
+
* await agent.deploy();
|
|
160
|
+
* console.log(`Deployed to sandbox: ${agent.sandboxId}`);
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
deploy(): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Executes the agent with the given input.
|
|
166
|
+
*
|
|
167
|
+
* The agent must be deployed before calling this method. Input is validated
|
|
168
|
+
* against the input schema, then the agent runs in the sandbox with the
|
|
169
|
+
* validated input. Output is validated against the output schema before
|
|
170
|
+
* being returned.
|
|
171
|
+
*
|
|
172
|
+
* @param input - The input data for the agent, must conform to inputSchema
|
|
173
|
+
* @returns A result object indicating success or failure with output or error
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const result = await agent.run({ prompt: 'Hello, world!' });
|
|
178
|
+
* if (result.ok) {
|
|
179
|
+
* console.log('Output:', result.output);
|
|
180
|
+
* } else {
|
|
181
|
+
* console.error('Error:', result.error.message);
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
run(input: TInput): Promise<AgentRunResult<TOutput>>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export { Agent, type AgentConfig, type AgentRunContext, type AgentRunResult, ConfigurationError, DEFAULT_DEPENDENCIES, DeploymentError, ExecutionError, type FileDownload, NeckbeardError, type OsDependencies, ValidationError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-neckbeard - Deploy AI agents to E2B sandboxes
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Base error class for agent-neckbeard errors.
|
|
6
|
+
* All custom errors extend this class.
|
|
7
|
+
*/
|
|
8
|
+
declare class NeckbeardError extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when sandbox deployment fails.
|
|
13
|
+
* This includes sandbox creation, dependency installation, and file upload failures.
|
|
14
|
+
*/
|
|
15
|
+
declare class DeploymentError extends NeckbeardError {
|
|
16
|
+
readonly cause?: Error | undefined;
|
|
17
|
+
constructor(message: string, cause?: Error | undefined);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error thrown when input or output schema validation fails.
|
|
21
|
+
*/
|
|
22
|
+
declare class ValidationError extends NeckbeardError {
|
|
23
|
+
readonly cause?: Error | undefined;
|
|
24
|
+
constructor(message: string, cause?: Error | undefined);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Error thrown when agent execution fails in the sandbox.
|
|
28
|
+
*/
|
|
29
|
+
declare class ExecutionError extends NeckbeardError {
|
|
30
|
+
readonly cause?: Error | undefined;
|
|
31
|
+
constructor(message: string, cause?: Error | undefined);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Error thrown when required environment variables are missing.
|
|
35
|
+
*/
|
|
36
|
+
declare class ConfigurationError extends NeckbeardError {
|
|
37
|
+
constructor(message: string);
|
|
38
|
+
}
|
|
39
|
+
interface AgentRunContext {
|
|
40
|
+
executionId: string;
|
|
41
|
+
signal: AbortSignal;
|
|
42
|
+
env: Record<string, string>;
|
|
43
|
+
logger: {
|
|
44
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
45
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
46
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
47
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
type AgentRunResult<TOutput> = {
|
|
51
|
+
ok: true;
|
|
52
|
+
executionId: string;
|
|
53
|
+
output: TOutput;
|
|
54
|
+
} | {
|
|
55
|
+
ok: false;
|
|
56
|
+
executionId: string;
|
|
57
|
+
error: Error | NeckbeardError;
|
|
58
|
+
};
|
|
59
|
+
interface SchemaLike<T> {
|
|
60
|
+
parse: (data: unknown) => T;
|
|
61
|
+
}
|
|
62
|
+
interface OsDependencies {
|
|
63
|
+
/** APT packages to install (e.g., ['curl', 'git']) */
|
|
64
|
+
apt?: string[];
|
|
65
|
+
/** Custom shell commands to run during setup */
|
|
66
|
+
commands?: string[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Configuration for downloading a file into the sandbox filesystem.
|
|
70
|
+
* Files are downloaded during deploy() before the agent runs.
|
|
71
|
+
*/
|
|
72
|
+
interface FileDownload {
|
|
73
|
+
/** URL to download the file from (supports http/https) */
|
|
74
|
+
url: string;
|
|
75
|
+
/**
|
|
76
|
+
* Destination path in the sandbox.
|
|
77
|
+
* Can be absolute (e.g., '/home/user/data/model.bin') or
|
|
78
|
+
* relative to /home/user/ (e.g., 'data/model.bin').
|
|
79
|
+
* Parent directories are created automatically.
|
|
80
|
+
*/
|
|
81
|
+
path: string;
|
|
82
|
+
}
|
|
83
|
+
/** Default dependencies - empty by default, specify what you need */
|
|
84
|
+
declare const DEFAULT_DEPENDENCIES: OsDependencies;
|
|
85
|
+
interface AgentConfig<TInput, TOutput> {
|
|
86
|
+
/**
|
|
87
|
+
* E2B template name or ID to use for the sandbox.
|
|
88
|
+
* Templates define the sandbox's CPU, memory, and pre-installed software.
|
|
89
|
+
*
|
|
90
|
+
* Common templates:
|
|
91
|
+
* - 'code-interpreter-v1': 2 cores, 2048 MB (recommended for Claude Agent SDK)
|
|
92
|
+
* - 'base': 2 cores, 512 MB (minimal)
|
|
93
|
+
* - 'desktop': 8 cores, 8192 MB (for heavy workloads)
|
|
94
|
+
*
|
|
95
|
+
* Create custom templates via E2B CLI:
|
|
96
|
+
* e2b template build --cpu-count 4 --memory-mb 4096 --name my-template
|
|
97
|
+
*
|
|
98
|
+
* @see https://e2b.dev/docs/template/overview
|
|
99
|
+
*/
|
|
100
|
+
template: string;
|
|
101
|
+
inputSchema: SchemaLike<TInput>;
|
|
102
|
+
outputSchema: SchemaLike<TOutput>;
|
|
103
|
+
run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
|
|
104
|
+
maxDuration?: number;
|
|
105
|
+
sandboxId?: string;
|
|
106
|
+
/** OS-level dependencies to install in the sandbox. Defaults to Claude Code. Set to {} to skip. */
|
|
107
|
+
dependencies?: OsDependencies;
|
|
108
|
+
/**
|
|
109
|
+
* Files to download and initialize in the sandbox filesystem.
|
|
110
|
+
* Downloaded during deploy() before the agent code runs.
|
|
111
|
+
* Useful for pre-loading models, datasets, configuration files, etc.
|
|
112
|
+
*/
|
|
113
|
+
files?: FileDownload[];
|
|
114
|
+
/**
|
|
115
|
+
* Local path to a .claude directory containing skills and settings.
|
|
116
|
+
* The directory will be uploaded to /home/user/agent/.claude/ in the sandbox.
|
|
117
|
+
* This enables Claude Agent SDK to access skills defined in SKILL.md files
|
|
118
|
+
* within .claude/skills/ subdirectories.
|
|
119
|
+
*
|
|
120
|
+
* Example: claudeDir: './my-project/.claude'
|
|
121
|
+
*
|
|
122
|
+
* The Claude Agent SDK will discover skills when:
|
|
123
|
+
* - cwd is set to /home/user/agent/ (containing .claude/)
|
|
124
|
+
* - settingSources includes 'project'
|
|
125
|
+
* - allowedTools includes 'Skill'
|
|
126
|
+
*/
|
|
127
|
+
claudeDir?: string;
|
|
128
|
+
}
|
|
129
|
+
declare class Agent<TInput, TOutput> {
|
|
130
|
+
readonly template: string;
|
|
131
|
+
readonly inputSchema: SchemaLike<TInput>;
|
|
132
|
+
readonly outputSchema: SchemaLike<TOutput>;
|
|
133
|
+
readonly maxDuration: number;
|
|
134
|
+
readonly dependencies: OsDependencies;
|
|
135
|
+
readonly files: FileDownload[];
|
|
136
|
+
readonly claudeDir?: string;
|
|
137
|
+
/** @internal Used by the sandbox runner - must be public for bundled code access */
|
|
138
|
+
_run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
|
|
139
|
+
private _sourceFile;
|
|
140
|
+
private _sandboxId?;
|
|
141
|
+
constructor(config: AgentConfig<TInput, TOutput>);
|
|
142
|
+
get sandboxId(): string | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Deploys the agent to an E2B sandbox.
|
|
145
|
+
*
|
|
146
|
+
* This method bundles the agent code using esbuild, creates a new E2B sandbox,
|
|
147
|
+
* installs any specified OS dependencies, downloads configured files, and
|
|
148
|
+
* uploads the agent code to the sandbox.
|
|
149
|
+
*
|
|
150
|
+
* The sandbox ID is stored and can be accessed via the `sandboxId` property
|
|
151
|
+
* after deployment completes.
|
|
152
|
+
*
|
|
153
|
+
* @throws {ConfigurationError} If E2B_API_KEY environment variable is not set
|
|
154
|
+
* @throws {DeploymentError} If sandbox creation, dependency installation, or file upload fails
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const agent = new Agent({ ... });
|
|
159
|
+
* await agent.deploy();
|
|
160
|
+
* console.log(`Deployed to sandbox: ${agent.sandboxId}`);
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
deploy(): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Executes the agent with the given input.
|
|
166
|
+
*
|
|
167
|
+
* The agent must be deployed before calling this method. Input is validated
|
|
168
|
+
* against the input schema, then the agent runs in the sandbox with the
|
|
169
|
+
* validated input. Output is validated against the output schema before
|
|
170
|
+
* being returned.
|
|
171
|
+
*
|
|
172
|
+
* @param input - The input data for the agent, must conform to inputSchema
|
|
173
|
+
* @returns A result object indicating success or failure with output or error
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const result = await agent.run({ prompt: 'Hello, world!' });
|
|
178
|
+
* if (result.ok) {
|
|
179
|
+
* console.log('Output:', result.output);
|
|
180
|
+
* } else {
|
|
181
|
+
* console.error('Error:', result.error.message);
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
run(input: TInput): Promise<AgentRunResult<TOutput>>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export { Agent, type AgentConfig, type AgentRunContext, type AgentRunResult, ConfigurationError, DEFAULT_DEPENDENCIES, DeploymentError, ExecutionError, type FileDownload, NeckbeardError, type OsDependencies, ValidationError };
|