agent-neckbeard 1.1.4 → 1.1.6

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/dist/index.d.cts CHANGED
@@ -102,12 +102,10 @@ interface FileDownload {
102
102
  }
103
103
  /** Default dependencies - empty by default, specify what you need */
104
104
  declare const DEFAULT_DEPENDENCIES: OsDependencies;
105
- interface AgentCommonConfig<TInput, TOutput> {
105
+ interface AgentSharedConfig<TInput> {
106
106
  /** Sandbox provider selection and base environment template/snapshot */
107
107
  sandbox: SandboxConfig;
108
108
  inputSchema: SchemaLike<TInput>;
109
- outputSchema: SchemaLike<TOutput>;
110
- run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
111
109
  maxDuration?: number;
112
110
  /** OS-level dependencies to install in the sandbox. Defaults to Claude Code. Set to {} to skip. */
113
111
  dependencies?: OsDependencies;
@@ -148,6 +146,42 @@ interface AgentCommonConfig<TInput, TOutput> {
148
146
  /** Build-time options for bundling */
149
147
  build?: BuildOptions;
150
148
  }
149
+ /**
150
+ * One-shot agent config: a handler that receives input and returns a single
151
+ * validated output. Each run invokes the handler as a one-shot subprocess
152
+ * inside the sandbox. This is the original neckbeard execution model.
153
+ */
154
+ interface OneShotAgentConfig<TInput, TOutput> extends AgentSharedConfig<TInput> {
155
+ outputSchema: SchemaLike<TOutput>;
156
+ run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
157
+ }
158
+ /**
159
+ * Server-mode agent config: deploys a long-running HTTP server into the
160
+ * sandbox that accepts POST /invoke calls and streams emitted frames as SSE.
161
+ * Use this when turns benefit from real-time progress streaming, cancel
162
+ * signals, or bidirectional tool approvals.
163
+ *
164
+ * See .plans/server-mode-agents.md for the full design.
165
+ */
166
+ interface ServerAgentConfig<TInput, TFrame> extends AgentSharedConfig<TInput> {
167
+ server: {
168
+ /** Port the in-sandbox HTTP server listens on. @default 3000 */
169
+ port?: number;
170
+ /** Schema used to validate each frame the server emits. */
171
+ frameSchema: SchemaLike<TFrame>;
172
+ /**
173
+ * User-provided async handler. Receives validated input, a cancel signal
174
+ * wired from the host, and an `emit` callback used to push SSE frames to
175
+ * the host as the handler runs.
176
+ */
177
+ handler: (args: {
178
+ input: TInput;
179
+ ctx: AgentRunContext;
180
+ signal: AbortSignal;
181
+ emit: (frame: TFrame) => Promise<void>;
182
+ }) => Promise<void>;
183
+ };
184
+ }
151
185
  interface E2BSandboxConfig {
152
186
  provider: 'e2b';
153
187
  /**
@@ -175,7 +209,26 @@ interface DaytonaSandboxConfig {
175
209
  template: string;
176
210
  }
177
211
  type SandboxConfig = E2BSandboxConfig | DaytonaSandboxConfig;
178
- type AgentConfig<TInput, TOutput> = AgentCommonConfig<TInput, TOutput>;
212
+ /**
213
+ * Agent config accepted by `new Agent(config)`. Can be either one-shot
214
+ * (original model) or server-mode (persistent HTTP server, SSE streaming).
215
+ * Mode is discriminated at runtime by the presence of `server` vs `run`.
216
+ */
217
+ type AgentConfig<TInput, TOutput, TFrame = unknown> = OneShotAgentConfig<TInput, TOutput> | ServerAgentConfig<TInput, TFrame>;
218
+ /**
219
+ * Returned by `deploy()` for server-mode agents. Callers should persist
220
+ * `sandboxId`, `serverUrl`, `authToken`, and `previewToken` so subsequent
221
+ * invocations can reconnect without redeploying.
222
+ */
223
+ interface ServerDeployResult {
224
+ mode: 'server';
225
+ sandboxId: string;
226
+ serverUrl: string;
227
+ /** Bearer token for the `Authorization` header on invoke() calls. */
228
+ authToken: string;
229
+ /** Daytona preview URL auth token; appended by invoke() as `?token=...`. */
230
+ previewToken: string;
231
+ }
179
232
  /**
180
233
  * Normalizes a path captured from a stack trace into a real on-disk file
181
234
  * path. Handles plain paths, `file://` URLs, and `webpack-internal://` URLs
@@ -189,23 +242,37 @@ type AgentConfig<TInput, TOutput> = AgentCommonConfig<TInput, TOutput>;
189
242
  * @internal Exported for testing.
190
243
  */
191
244
  declare function normalizeStackFramePath(rawPath: string, cwd?: string): string | null;
192
- declare class Agent<TInput, TOutput> {
245
+ type AgentMode = 'one-shot' | 'server';
246
+ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
193
247
  readonly sandbox: SandboxConfig;
194
248
  readonly provider: SandboxProvider;
195
249
  readonly template: string;
196
250
  readonly inputSchema: SchemaLike<TInput>;
197
- readonly outputSchema: SchemaLike<TOutput>;
251
+ /** Only populated for one-shot agents; undefined for server-mode. */
252
+ readonly outputSchema?: SchemaLike<TOutput>;
253
+ /** Only populated for server-mode agents; undefined for one-shot. */
254
+ readonly frameSchema?: SchemaLike<TFrame>;
255
+ readonly mode: AgentMode;
198
256
  readonly maxDuration: number;
199
257
  readonly dependencies: OsDependencies;
200
258
  readonly files: FileDownload[];
201
259
  readonly claudeDir?: string;
202
260
  readonly envs: Record<string, string | undefined>;
203
261
  readonly build: BuildOptions;
204
- /** @internal Used by the sandbox runner - must be public for bundled code access */
205
- _run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
262
+ /** @internal Used by the sandbox runner for one-shot agents. */
263
+ _run?: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
264
+ /** @internal Used by the in-sandbox HTTP server for server-mode agents. */
265
+ _server?: ServerAgentConfig<TInput, TFrame>['server'];
266
+ /** @internal Runtime state populated by deploy() for server-mode agents. */
267
+ _serverRuntime?: {
268
+ sessionId: string;
269
+ serverUrl: string;
270
+ authToken: string;
271
+ previewToken: string;
272
+ };
206
273
  private _sourceFile;
207
274
  private _sandboxId?;
208
- constructor(config: AgentConfig<TInput, TOutput>);
275
+ constructor(config: AgentConfig<TInput, TOutput, TFrame>);
209
276
  get sandboxId(): string | undefined;
210
277
  private get sandboxEnv();
211
278
  private createSandboxHandle;
@@ -253,9 +320,23 @@ declare class Agent<TInput, TOutput> {
253
320
  * await agent.kill(id);
254
321
  * ```
255
322
  */
323
+ /**
324
+ * Deploy a one-shot agent. Throws if called on a server-mode agent; use
325
+ * `deployServer()` for those. Returns the sandbox id so callers can pass it
326
+ * to `run(input, { sandboxId })`.
327
+ */
256
328
  deploy(options?: {
257
329
  fresh?: boolean;
258
330
  }): Promise<string>;
331
+ /**
332
+ * Deploy a server-mode agent. Throws if called on a one-shot agent; use
333
+ * `deploy()` for those. Returns the sandbox id, public server URL, bearer
334
+ * token, and Daytona preview token that `invoke()` needs to stream.
335
+ */
336
+ deployServer(options?: {
337
+ fresh?: boolean;
338
+ }): Promise<ServerDeployResult>;
339
+ private _deploy;
259
340
  /**
260
341
  * Executes the agent with the given input.
261
342
  *
@@ -281,6 +362,22 @@ declare class Agent<TInput, TOutput> {
281
362
  run(input: TInput, options?: {
282
363
  sandboxId?: string;
283
364
  }): Promise<AgentRunResult<TOutput>>;
365
+ /**
366
+ * Invoke a server-mode agent. Streams the agent's emitted frames back as an
367
+ * async iterator as the handler runs. Only valid for agents constructed with
368
+ * `server: {...}` config; one-shot agents should use `run()` instead.
369
+ *
370
+ * Requires the agent to be deployed via `deploy()` (returns `serverUrl` and
371
+ * `authToken`) — callers must persist those values and pass them on each
372
+ * invocation. Deploy is not yet implemented for server mode; this method
373
+ * currently throws `ConfigurationError` if `serverUrl` is not supplied.
374
+ */
375
+ invoke(input: TInput, options?: {
376
+ serverUrl?: string;
377
+ authToken?: string;
378
+ previewToken?: string;
379
+ signal?: AbortSignal;
380
+ }): AsyncGenerator<TFrame>;
284
381
  }
285
382
 
286
- export { Agent, type AgentConfig, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, NeckbeardError, type OsDependencies, type SandboxConfig, type SandboxProvider, ValidationError, normalizeStackFramePath };
383
+ export { Agent, type AgentConfig, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, NeckbeardError, type OneShotAgentConfig, type OsDependencies, type SandboxConfig, type SandboxProvider, type ServerAgentConfig, type ServerDeployResult, ValidationError, normalizeStackFramePath };
package/dist/index.d.ts CHANGED
@@ -102,12 +102,10 @@ interface FileDownload {
102
102
  }
103
103
  /** Default dependencies - empty by default, specify what you need */
104
104
  declare const DEFAULT_DEPENDENCIES: OsDependencies;
105
- interface AgentCommonConfig<TInput, TOutput> {
105
+ interface AgentSharedConfig<TInput> {
106
106
  /** Sandbox provider selection and base environment template/snapshot */
107
107
  sandbox: SandboxConfig;
108
108
  inputSchema: SchemaLike<TInput>;
109
- outputSchema: SchemaLike<TOutput>;
110
- run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
111
109
  maxDuration?: number;
112
110
  /** OS-level dependencies to install in the sandbox. Defaults to Claude Code. Set to {} to skip. */
113
111
  dependencies?: OsDependencies;
@@ -148,6 +146,42 @@ interface AgentCommonConfig<TInput, TOutput> {
148
146
  /** Build-time options for bundling */
149
147
  build?: BuildOptions;
150
148
  }
149
+ /**
150
+ * One-shot agent config: a handler that receives input and returns a single
151
+ * validated output. Each run invokes the handler as a one-shot subprocess
152
+ * inside the sandbox. This is the original neckbeard execution model.
153
+ */
154
+ interface OneShotAgentConfig<TInput, TOutput> extends AgentSharedConfig<TInput> {
155
+ outputSchema: SchemaLike<TOutput>;
156
+ run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
157
+ }
158
+ /**
159
+ * Server-mode agent config: deploys a long-running HTTP server into the
160
+ * sandbox that accepts POST /invoke calls and streams emitted frames as SSE.
161
+ * Use this when turns benefit from real-time progress streaming, cancel
162
+ * signals, or bidirectional tool approvals.
163
+ *
164
+ * See .plans/server-mode-agents.md for the full design.
165
+ */
166
+ interface ServerAgentConfig<TInput, TFrame> extends AgentSharedConfig<TInput> {
167
+ server: {
168
+ /** Port the in-sandbox HTTP server listens on. @default 3000 */
169
+ port?: number;
170
+ /** Schema used to validate each frame the server emits. */
171
+ frameSchema: SchemaLike<TFrame>;
172
+ /**
173
+ * User-provided async handler. Receives validated input, a cancel signal
174
+ * wired from the host, and an `emit` callback used to push SSE frames to
175
+ * the host as the handler runs.
176
+ */
177
+ handler: (args: {
178
+ input: TInput;
179
+ ctx: AgentRunContext;
180
+ signal: AbortSignal;
181
+ emit: (frame: TFrame) => Promise<void>;
182
+ }) => Promise<void>;
183
+ };
184
+ }
151
185
  interface E2BSandboxConfig {
152
186
  provider: 'e2b';
153
187
  /**
@@ -175,7 +209,26 @@ interface DaytonaSandboxConfig {
175
209
  template: string;
176
210
  }
177
211
  type SandboxConfig = E2BSandboxConfig | DaytonaSandboxConfig;
178
- type AgentConfig<TInput, TOutput> = AgentCommonConfig<TInput, TOutput>;
212
+ /**
213
+ * Agent config accepted by `new Agent(config)`. Can be either one-shot
214
+ * (original model) or server-mode (persistent HTTP server, SSE streaming).
215
+ * Mode is discriminated at runtime by the presence of `server` vs `run`.
216
+ */
217
+ type AgentConfig<TInput, TOutput, TFrame = unknown> = OneShotAgentConfig<TInput, TOutput> | ServerAgentConfig<TInput, TFrame>;
218
+ /**
219
+ * Returned by `deploy()` for server-mode agents. Callers should persist
220
+ * `sandboxId`, `serverUrl`, `authToken`, and `previewToken` so subsequent
221
+ * invocations can reconnect without redeploying.
222
+ */
223
+ interface ServerDeployResult {
224
+ mode: 'server';
225
+ sandboxId: string;
226
+ serverUrl: string;
227
+ /** Bearer token for the `Authorization` header on invoke() calls. */
228
+ authToken: string;
229
+ /** Daytona preview URL auth token; appended by invoke() as `?token=...`. */
230
+ previewToken: string;
231
+ }
179
232
  /**
180
233
  * Normalizes a path captured from a stack trace into a real on-disk file
181
234
  * path. Handles plain paths, `file://` URLs, and `webpack-internal://` URLs
@@ -189,23 +242,37 @@ type AgentConfig<TInput, TOutput> = AgentCommonConfig<TInput, TOutput>;
189
242
  * @internal Exported for testing.
190
243
  */
191
244
  declare function normalizeStackFramePath(rawPath: string, cwd?: string): string | null;
192
- declare class Agent<TInput, TOutput> {
245
+ type AgentMode = 'one-shot' | 'server';
246
+ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
193
247
  readonly sandbox: SandboxConfig;
194
248
  readonly provider: SandboxProvider;
195
249
  readonly template: string;
196
250
  readonly inputSchema: SchemaLike<TInput>;
197
- readonly outputSchema: SchemaLike<TOutput>;
251
+ /** Only populated for one-shot agents; undefined for server-mode. */
252
+ readonly outputSchema?: SchemaLike<TOutput>;
253
+ /** Only populated for server-mode agents; undefined for one-shot. */
254
+ readonly frameSchema?: SchemaLike<TFrame>;
255
+ readonly mode: AgentMode;
198
256
  readonly maxDuration: number;
199
257
  readonly dependencies: OsDependencies;
200
258
  readonly files: FileDownload[];
201
259
  readonly claudeDir?: string;
202
260
  readonly envs: Record<string, string | undefined>;
203
261
  readonly build: BuildOptions;
204
- /** @internal Used by the sandbox runner - must be public for bundled code access */
205
- _run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
262
+ /** @internal Used by the sandbox runner for one-shot agents. */
263
+ _run?: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
264
+ /** @internal Used by the in-sandbox HTTP server for server-mode agents. */
265
+ _server?: ServerAgentConfig<TInput, TFrame>['server'];
266
+ /** @internal Runtime state populated by deploy() for server-mode agents. */
267
+ _serverRuntime?: {
268
+ sessionId: string;
269
+ serverUrl: string;
270
+ authToken: string;
271
+ previewToken: string;
272
+ };
206
273
  private _sourceFile;
207
274
  private _sandboxId?;
208
- constructor(config: AgentConfig<TInput, TOutput>);
275
+ constructor(config: AgentConfig<TInput, TOutput, TFrame>);
209
276
  get sandboxId(): string | undefined;
210
277
  private get sandboxEnv();
211
278
  private createSandboxHandle;
@@ -253,9 +320,23 @@ declare class Agent<TInput, TOutput> {
253
320
  * await agent.kill(id);
254
321
  * ```
255
322
  */
323
+ /**
324
+ * Deploy a one-shot agent. Throws if called on a server-mode agent; use
325
+ * `deployServer()` for those. Returns the sandbox id so callers can pass it
326
+ * to `run(input, { sandboxId })`.
327
+ */
256
328
  deploy(options?: {
257
329
  fresh?: boolean;
258
330
  }): Promise<string>;
331
+ /**
332
+ * Deploy a server-mode agent. Throws if called on a one-shot agent; use
333
+ * `deploy()` for those. Returns the sandbox id, public server URL, bearer
334
+ * token, and Daytona preview token that `invoke()` needs to stream.
335
+ */
336
+ deployServer(options?: {
337
+ fresh?: boolean;
338
+ }): Promise<ServerDeployResult>;
339
+ private _deploy;
259
340
  /**
260
341
  * Executes the agent with the given input.
261
342
  *
@@ -281,6 +362,22 @@ declare class Agent<TInput, TOutput> {
281
362
  run(input: TInput, options?: {
282
363
  sandboxId?: string;
283
364
  }): Promise<AgentRunResult<TOutput>>;
365
+ /**
366
+ * Invoke a server-mode agent. Streams the agent's emitted frames back as an
367
+ * async iterator as the handler runs. Only valid for agents constructed with
368
+ * `server: {...}` config; one-shot agents should use `run()` instead.
369
+ *
370
+ * Requires the agent to be deployed via `deploy()` (returns `serverUrl` and
371
+ * `authToken`) — callers must persist those values and pass them on each
372
+ * invocation. Deploy is not yet implemented for server mode; this method
373
+ * currently throws `ConfigurationError` if `serverUrl` is not supplied.
374
+ */
375
+ invoke(input: TInput, options?: {
376
+ serverUrl?: string;
377
+ authToken?: string;
378
+ previewToken?: string;
379
+ signal?: AbortSignal;
380
+ }): AsyncGenerator<TFrame>;
284
381
  }
285
382
 
286
- export { Agent, type AgentConfig, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, NeckbeardError, type OsDependencies, type SandboxConfig, type SandboxProvider, ValidationError, normalizeStackFramePath };
383
+ export { Agent, type AgentConfig, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, NeckbeardError, type OneShotAgentConfig, type OsDependencies, type SandboxConfig, type SandboxProvider, type ServerAgentConfig, type ServerDeployResult, ValidationError, normalizeStackFramePath };