agent-neckbeard 1.1.17 → 1.1.19

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.ts CHANGED
@@ -1,6 +1,54 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import { S as SandboxFileContent$1, a as SandboxCommandOptions, b as SandboxCommandResult, c as SandboxDetachedCommandOptions, d as SandboxDetachedCommand } from './sandbox-capabilities-CFjnZ_kB.js';
3
+
4
+ /** Sandbox providers supported by the public and in-sandbox runtimes. */
5
+ type SandboxProvider = 'e2b' | 'daytona';
6
+ /** Paths shared by host, runtime, and provider sandbox contexts. */
7
+ interface SandboxContext {
8
+ provider: SandboxProvider;
9
+ homeDir: string;
10
+ workDir: string;
11
+ agentDir: string;
12
+ ioDir: string;
13
+ inputJson: string;
14
+ outputJson: string;
15
+ }
16
+
17
+ interface CreateAttachedSessionOptions {
18
+ /**
19
+ * Attached sessions are owned by this client process and stop when their
20
+ * active request is cancelled. Durable sessions are launched through the
21
+ * `agent-neckbeard/supervisor` entrypoint because their control plane must
22
+ * outlive this object.
23
+ */
24
+ durability?: 'attached';
25
+ /** Existing sandbox runtime to reconnect to. Defaults to the deployed sandbox. */
26
+ sandboxId?: string;
27
+ /** Cancels the complete attached-session lifetime when aborted. */
28
+ signal?: AbortSignal;
29
+ }
30
+ interface AttachedAgentSession<TInput, TFrame> {
31
+ readonly durability: 'attached';
32
+ readonly sandboxId: string;
33
+ readonly closed: boolean;
34
+ /**
35
+ * Starts one attached turn. Turns may be issued sequentially against the
36
+ * same sandbox runtime; only one turn may be active at a time.
37
+ */
38
+ prompt(input: TInput): AsyncGenerator<TFrame>;
39
+ /** Cancels the active turn without destroying the reusable sandbox. */
40
+ stop(reason?: string): Promise<void>;
41
+ /** Cancels any active turn and permanently closes this local handle. */
42
+ close(): Promise<void>;
43
+ }
44
+
1
45
  /**
2
46
  * agent-neckbeard - Deploy AI agents to sandboxes
3
47
  */
48
+
49
+ /** File content accepted by the public Node.js sandbox client. */
50
+ type SandboxFileContent = SandboxFileContent$1 | Buffer;
51
+
4
52
  /**
5
53
  * Base error class for agent-neckbeard errors.
6
54
  * All custom errors extend this class.
@@ -36,15 +84,7 @@ declare class ExecutionError extends NeckbeardError {
36
84
  declare class ConfigurationError extends NeckbeardError {
37
85
  constructor(message: string);
38
86
  }
39
- type SandboxProvider = 'e2b' | 'daytona';
40
- interface AgentSandboxContext {
41
- provider: SandboxProvider;
42
- homeDir: string;
43
- workDir: string;
44
- agentDir: string;
45
- ioDir: string;
46
- inputJson: string;
47
- outputJson: string;
87
+ interface AgentSandboxContext extends SandboxContext {
48
88
  }
49
89
  interface AgentRunContext {
50
90
  executionId: string;
@@ -159,6 +199,23 @@ interface FileDownload {
159
199
  */
160
200
  path: string;
161
201
  }
202
+ /**
203
+ * Configuration for recursively copying a local directory into the sandbox
204
+ * agent directory during deploy().
205
+ */
206
+ interface LocalDirectoryUpload {
207
+ /**
208
+ * Local source directory. Relative paths resolve from the deploying
209
+ * process's current working directory.
210
+ */
211
+ source: string;
212
+ /**
213
+ * Destination directory relative to `ctx.sandbox.agentDir`.
214
+ * Absolute paths and paths that traverse outside the agent directory are
215
+ * rejected.
216
+ */
217
+ destination: string;
218
+ }
162
219
  /** Default dependencies - empty by default, specify what you need */
163
220
  declare const DEFAULT_DEPENDENCIES: OsDependencies;
164
221
  interface AgentSharedConfig<TInput> {
@@ -183,7 +240,19 @@ interface AgentSharedConfig<TInput> {
183
240
  */
184
241
  files?: FileDownload[];
185
242
  /**
186
- * Local path to a .claude directory containing skills and settings.
243
+ * Local directories to recursively upload beneath the sandbox agent
244
+ * directory. Dotfiles and exact file bytes are preserved. Symbolic links
245
+ * are rejected.
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * localDirectories: [{ source: './.agents', destination: '.agents' }]
250
+ * ```
251
+ */
252
+ localDirectories?: LocalDirectoryUpload[];
253
+ /**
254
+ * Legacy Claude-specific convenience option. Local path to a .claude
255
+ * directory containing skills and settings.
187
256
  * The directory will be uploaded to {homeDir}/agent/.claude/ in the sandbox.
188
257
  * This enables Claude Agent SDK to access skills defined in SKILL.md files
189
258
  * within .claude/skills/ subdirectories.
@@ -194,6 +263,8 @@ interface AgentSharedConfig<TInput> {
194
263
  * - cwd is set to {homeDir}/agent/ (containing .claude/)
195
264
  * - settingSources includes 'project'
196
265
  * - allowedTools includes 'Skill'
266
+ *
267
+ * @deprecated Use `localDirectories` with destination `.claude` instead.
197
268
  */
198
269
  claudeDir?: string;
199
270
  /**
@@ -222,30 +293,36 @@ interface RunAgentConfig<TInput, TOutput> extends AgentSharedConfig<TInput> {
222
293
  outputSchema: SchemaLike<TOutput>;
223
294
  run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
224
295
  }
296
+ interface AgentSessionHandler<TInput, TFrame> {
297
+ /** Port the in-sandbox HTTP server listens on. @default 3000 */
298
+ port?: number;
299
+ /** Schema used to validate each frame the session emits. */
300
+ frameSchema: SchemaLike<TFrame>;
301
+ /**
302
+ * User-provided async handler. Receives validated input, a cancel signal
303
+ * wired from the host, and an `emit` callback used to push session events to
304
+ * the caller as the turn runs.
305
+ */
306
+ handler: (args: {
307
+ input: TInput;
308
+ ctx: AgentRunContext;
309
+ signal: AbortSignal;
310
+ emit: (frame: TFrame) => Promise<void>;
311
+ }) => Promise<void>;
312
+ }
225
313
  /**
226
- * Streaming agent config: deploys the same long-running HTTP server into the
227
- * sandbox and streams emitted frames from POST /invoke calls as SSE.
228
- * Use this when turns benefit from real-time progress streaming, cancel
229
- * signals, or bidirectional tool approvals.
314
+ * Attached-session agent config. The sandbox runtime emits typed events for
315
+ * sequential caller-owned turns created with `Agent.createSession()`.
230
316
  */
317
+ interface SessionAgentConfig<TInput, TFrame> extends AgentSharedConfig<TInput> {
318
+ session: AgentSessionHandler<TInput, TFrame>;
319
+ server?: never;
320
+ }
321
+ /** @deprecated Use `SessionAgentConfig` with the `session` property. */
231
322
  interface ServerAgentConfig<TInput, TFrame> extends AgentSharedConfig<TInput> {
232
- server: {
233
- /** Port the in-sandbox HTTP server listens on. @default 3000 */
234
- port?: number;
235
- /** Schema used to validate each frame the server emits. */
236
- frameSchema: SchemaLike<TFrame>;
237
- /**
238
- * User-provided async handler. Receives validated input, a cancel signal
239
- * wired from the host, and an `emit` callback used to push SSE frames to
240
- * the host as the handler runs.
241
- */
242
- handler: (args: {
243
- input: TInput;
244
- ctx: AgentRunContext;
245
- signal: AbortSignal;
246
- emit: (frame: TFrame) => Promise<void>;
247
- }) => Promise<void>;
248
- };
323
+ /** @deprecated Use `session`. */
324
+ server: AgentSessionHandler<TInput, TFrame>;
325
+ session?: never;
249
326
  }
250
327
  interface E2BSandboxConfig {
251
328
  provider: 'e2b';
@@ -294,28 +371,12 @@ interface DaytonaSandboxConfig {
294
371
  }
295
372
  type SandboxConfig = E2BSandboxConfig | DaytonaSandboxConfig;
296
373
  /**
297
- * Agent config accepted by `new Agent(config)`. Can be either request/response
298
- * (`run`) or streaming (`server.handler`). Both run behind the same persistent
299
- * in-sandbox HTTP server.
300
- * Mode is discriminated at runtime by the presence of `server` vs `run`.
301
- */
302
- type AgentConfig<TInput, TOutput, TFrame = unknown> = RunAgentConfig<TInput, TOutput> | ServerAgentConfig<TInput, TFrame>;
303
- type SandboxFileContent = string | ArrayBuffer | Uint8Array | Buffer;
304
- interface SandboxCommandOptions {
305
- cwd?: string;
306
- envs?: Record<string, string>;
307
- timeoutMs: number;
308
- onStdout?: (data: string) => void;
309
- onStderr?: (data: string) => void;
310
- }
311
- /**
312
- * Result from running a sandbox command with captured output.
374
+ * Agent config accepted by `new Agent(config)`. Can be either a structured task
375
+ * (`run`) or an attached-session handler (`session.handler`). Both run behind
376
+ * the same persistent in-sandbox HTTP server.
377
+ * The deprecated `server.handler` spelling remains accepted.
313
378
  */
314
- interface SandboxCommandResult {
315
- exitCode: number;
316
- stdout: string;
317
- stderr: string;
318
- }
379
+ type AgentConfig<TInput, TOutput, TFrame = unknown> = RunAgentConfig<TInput, TOutput> | SessionAgentConfig<TInput, TFrame> | ServerAgentConfig<TInput, TFrame>;
319
380
  type SandboxClientCreateOptions = {
320
381
  provider: 'e2b';
321
382
  template?: string;
@@ -330,6 +391,7 @@ type SandboxClientCreateOptions = {
330
391
  apiKey?: string;
331
392
  envs?: Record<string, string | undefined>;
332
393
  createTimeoutSec?: number;
394
+ autoStopInterval?: number;
333
395
  autoDeleteInterval?: number;
334
396
  networkBlockAll?: boolean;
335
397
  networkAllowList?: string;
@@ -350,7 +412,27 @@ type SandboxClientConnectOptions = {
350
412
  declare class SandboxClient {
351
413
  private readonly handle;
352
414
  private constructor();
415
+ static create(options: Extract<SandboxClientCreateOptions, {
416
+ provider: 'daytona';
417
+ }>): Promise<SandboxClient & {
418
+ readonly provider: 'daytona';
419
+ }>;
420
+ static create(options: Extract<SandboxClientCreateOptions, {
421
+ provider: 'e2b';
422
+ }>): Promise<SandboxClient & {
423
+ readonly provider: 'e2b';
424
+ }>;
353
425
  static create(options: SandboxClientCreateOptions): Promise<SandboxClient>;
426
+ static connect(options: Extract<SandboxClientConnectOptions, {
427
+ provider: 'daytona';
428
+ }>): Promise<SandboxClient & {
429
+ readonly provider: 'daytona';
430
+ }>;
431
+ static connect(options: Extract<SandboxClientConnectOptions, {
432
+ provider: 'e2b';
433
+ }>): Promise<SandboxClient & {
434
+ readonly provider: 'e2b';
435
+ }>;
354
436
  static connect(options: SandboxClientConnectOptions): Promise<SandboxClient>;
355
437
  get id(): string;
356
438
  get provider(): SandboxProvider;
@@ -360,30 +442,67 @@ declare class SandboxClient {
360
442
  readFile(path: string): Promise<string>;
361
443
  readFileBytes(path: string): Promise<Uint8Array>;
362
444
  runCommand(command: string, options: SandboxCommandOptions): Promise<SandboxCommandResult>;
445
+ startDetachedCommand(command: string, options?: SandboxDetachedCommandOptions): Promise<SandboxDetachedCommand>;
446
+ /**
447
+ * Returns bounded, best-effort stdout/stderr diagnostics for a detached
448
+ * command. This is not lifecycle, transcript, completion, or acknowledgement
449
+ * state, and the two streams are captured independently rather than as an
450
+ * atomic pair.
451
+ */
452
+ readSessionLogs(command: SandboxDetachedCommand): Promise<{
453
+ stdout: string;
454
+ stderr: string;
455
+ }>;
456
+ /** @deprecated Pass the complete handle returned by `startDetachedCommand()`. */
457
+ readSessionLogs(sessionId: string, commandId: string): Promise<{
458
+ stdout: string;
459
+ stderr: string;
460
+ }>;
461
+ /** Stops a detached process and resolves only after provider-confirmed exit. */
462
+ stopSession(command: SandboxDetachedCommand): Promise<void>;
463
+ /** @deprecated Pass the complete handle returned by `startDetachedCommand()`. */
464
+ stopSession(sessionId: string): Promise<void>;
465
+ /**
466
+ * Irreversibly removes private lifecycle state and captured diagnostics for
467
+ * one managed detached command. Call `stopSession()` first, then perform any
468
+ * final `readSessionLogs()` before disposal. Disposal is idempotent after a
469
+ * confirmed stop but is not itself evidence that the process stopped.
470
+ */
471
+ disposeSessionArtifacts(command: SandboxDetachedCommand): Promise<void>;
363
472
  setTimeout(timeoutMs: number): Promise<void>;
364
473
  kill(): Promise<void>;
365
474
  destroy(): Promise<void>;
366
475
  }
476
+ /** @deprecated Use `AgentKind` for user-facing task/session terminology. */
367
477
  type AgentMode = 'run' | 'stream';
478
+ type AgentKind = 'task' | 'session';
479
+ /** @deprecated Durable sessions use the separate supervisor deployment API. */
480
+ type SessionDurability = 'attached' | 'durable';
368
481
  declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
369
482
  readonly sandbox: SandboxConfig;
370
483
  readonly provider: SandboxProvider;
371
484
  readonly template: string;
372
485
  readonly inputSchema: SchemaLike<TInput>;
373
- /** Only populated for run-output agents; undefined for streaming agents. */
486
+ /** Only populated for structured-task agents; undefined for session agents. */
374
487
  readonly outputSchema?: SchemaLike<TOutput>;
375
- /** Only populated for streaming agents; undefined for run-output agents. */
488
+ /** Only populated for attached-session agents; undefined for run-output agents. */
376
489
  readonly frameSchema?: SchemaLike<TFrame>;
490
+ /** User-facing execution shape. */
491
+ readonly kind: AgentKind;
492
+ /** @deprecated Use `kind`; retained for compatibility with `run | stream` checks. */
377
493
  readonly mode: AgentMode;
378
494
  readonly maxDuration: number;
379
495
  readonly dependencies: OsDependencies;
380
496
  readonly files: FileDownload[];
497
+ readonly localDirectories: LocalDirectoryUpload[];
498
+ /** @deprecated Use `localDirectories` with destination `.claude` instead. */
381
499
  readonly claudeDir?: string;
382
500
  readonly envs: Record<string, string | undefined>;
383
501
  readonly build: BuildOptions;
384
502
  private _sandboxId?;
385
503
  private _sourceFile;
386
504
  constructor(config: RunAgentConfig<TInput, TOutput>);
505
+ constructor(config: SessionAgentConfig<TInput, TFrame>);
387
506
  constructor(config: ServerAgentConfig<TInput, TFrame>);
388
507
  constructor(config: AgentConfig<TInput, TOutput, TFrame>);
389
508
  get sandboxId(): string | undefined;
@@ -468,8 +587,16 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
468
587
  sandboxId?: string;
469
588
  }): Promise<AgentRunResult<TOutput>>;
470
589
  /**
471
- * Invoke a streaming agent. Streams user frames emitted by the in-sandbox
472
- * handler as an async iterator.
590
+ * Creates a caller-owned session against the persistent sandbox runtime.
591
+ * The returned handle supports sequential prompts, active-turn cancellation,
592
+ * and explicit close without destroying the reusable sandbox.
593
+ */
594
+ createSession(options?: CreateAttachedSessionOptions): Promise<AttachedAgentSession<TInput, TFrame>>;
595
+ private streamSessionPrompt;
596
+ /**
597
+ * @deprecated Use `createSession()` and call `session.prompt(input)` instead.
598
+ * This compatibility wrapper creates one attached session, streams one turn,
599
+ * and closes the local handle afterward.
473
600
  */
474
601
  invoke(input: TInput, options?: {
475
602
  sandboxId?: string;
@@ -477,4 +604,4 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
477
604
  }): AsyncGenerator<TFrame>;
478
605
  }
479
606
 
480
- 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 NeckbeardNextConfigOptions, type OsDependencies, type ResolveAgentSourceFileOptions, type RunAgentConfig, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions, type SandboxCommandOptions, type SandboxCommandResult, type SandboxConfig, type SandboxFileContent, type SandboxProvider, type ServerAgentConfig, ValidationError, resolveAgentSourceFile, withNeckbeardNextConfig };
607
+ export { Agent, type AgentConfig, type AgentKind, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type AgentSessionHandler, type AttachedAgentSession, type BuildOptions, ConfigurationError, type CreateAttachedSessionOptions, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, type LocalDirectoryUpload, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type ResolveAgentSourceFileOptions, type RunAgentConfig, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions, SandboxCommandOptions, SandboxCommandResult, type SandboxConfig, SandboxDetachedCommand, SandboxDetachedCommandOptions, type SandboxFileContent, type SandboxProvider, type ServerAgentConfig, type SessionAgentConfig, type SessionDurability, ValidationError, resolveAgentSourceFile, withNeckbeardNextConfig };