agent-neckbeard 1.1.18 → 1.1.20
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/CHANGELOG.md +32 -0
- package/README.md +171 -67
- package/dist/chunk-33IXN6MM.js +21 -0
- package/dist/chunk-3EB4CT5S.js +2516 -0
- package/dist/{chunk-AM2J5KBI.js → chunk-DHFC3O44.js} +4 -8
- package/dist/index.cjs +3652 -535
- package/dist/index.d.cts +150 -56
- package/dist/index.d.ts +150 -56
- package/dist/index.js +1167 -501
- package/dist/{invoke-client-XEH6FVRH.js → invoke-client-D5TMTOYM.js} +2 -1
- package/dist/sandbox-capabilities-CFjnZ_kB.d.cts +77 -0
- package/dist/sandbox-capabilities-CFjnZ_kB.d.ts +77 -0
- package/dist/supervisor.cjs +6043 -0
- package/dist/supervisor.d.cts +470 -0
- package/dist/supervisor.d.ts +470 -0
- package/dist/supervisor.js +3535 -0
- package/docs/SUPERVISOR.md +248 -0
- package/package.json +20 -8
package/dist/index.d.cts
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.cjs';
|
|
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
|
-
|
|
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;
|
|
@@ -253,30 +293,36 @@ interface RunAgentConfig<TInput, TOutput> extends AgentSharedConfig<TInput> {
|
|
|
253
293
|
outputSchema: SchemaLike<TOutput>;
|
|
254
294
|
run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
|
|
255
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
|
+
}
|
|
256
313
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* Use this when turns benefit from real-time progress streaming, cancel
|
|
260
|
-
* 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()`.
|
|
261
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. */
|
|
262
322
|
interface ServerAgentConfig<TInput, TFrame> extends AgentSharedConfig<TInput> {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
/** Schema used to validate each frame the server emits. */
|
|
267
|
-
frameSchema: SchemaLike<TFrame>;
|
|
268
|
-
/**
|
|
269
|
-
* User-provided async handler. Receives validated input, a cancel signal
|
|
270
|
-
* wired from the host, and an `emit` callback used to push SSE frames to
|
|
271
|
-
* the host as the handler runs.
|
|
272
|
-
*/
|
|
273
|
-
handler: (args: {
|
|
274
|
-
input: TInput;
|
|
275
|
-
ctx: AgentRunContext;
|
|
276
|
-
signal: AbortSignal;
|
|
277
|
-
emit: (frame: TFrame) => Promise<void>;
|
|
278
|
-
}) => Promise<void>;
|
|
279
|
-
};
|
|
323
|
+
/** @deprecated Use `session`. */
|
|
324
|
+
server: AgentSessionHandler<TInput, TFrame>;
|
|
325
|
+
session?: never;
|
|
280
326
|
}
|
|
281
327
|
interface E2BSandboxConfig {
|
|
282
328
|
provider: 'e2b';
|
|
@@ -325,28 +371,12 @@ interface DaytonaSandboxConfig {
|
|
|
325
371
|
}
|
|
326
372
|
type SandboxConfig = E2BSandboxConfig | DaytonaSandboxConfig;
|
|
327
373
|
/**
|
|
328
|
-
* Agent config accepted by `new Agent(config)`. Can be either
|
|
329
|
-
* (`run`) or
|
|
330
|
-
* in-sandbox HTTP server.
|
|
331
|
-
*
|
|
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.
|
|
332
378
|
*/
|
|
333
|
-
type AgentConfig<TInput, TOutput, TFrame = unknown> = RunAgentConfig<TInput, TOutput> | ServerAgentConfig<TInput, TFrame>;
|
|
334
|
-
type SandboxFileContent = string | ArrayBuffer | Uint8Array | Buffer;
|
|
335
|
-
interface SandboxCommandOptions {
|
|
336
|
-
cwd?: string;
|
|
337
|
-
envs?: Record<string, string>;
|
|
338
|
-
timeoutMs: number;
|
|
339
|
-
onStdout?: (data: string) => void;
|
|
340
|
-
onStderr?: (data: string) => void;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Result from running a sandbox command with captured output.
|
|
344
|
-
*/
|
|
345
|
-
interface SandboxCommandResult {
|
|
346
|
-
exitCode: number;
|
|
347
|
-
stdout: string;
|
|
348
|
-
stderr: string;
|
|
349
|
-
}
|
|
379
|
+
type AgentConfig<TInput, TOutput, TFrame = unknown> = RunAgentConfig<TInput, TOutput> | SessionAgentConfig<TInput, TFrame> | ServerAgentConfig<TInput, TFrame>;
|
|
350
380
|
type SandboxClientCreateOptions = {
|
|
351
381
|
provider: 'e2b';
|
|
352
382
|
template?: string;
|
|
@@ -361,6 +391,7 @@ type SandboxClientCreateOptions = {
|
|
|
361
391
|
apiKey?: string;
|
|
362
392
|
envs?: Record<string, string | undefined>;
|
|
363
393
|
createTimeoutSec?: number;
|
|
394
|
+
autoStopInterval?: number;
|
|
364
395
|
autoDeleteInterval?: number;
|
|
365
396
|
networkBlockAll?: boolean;
|
|
366
397
|
networkAllowList?: string;
|
|
@@ -381,7 +412,27 @@ type SandboxClientConnectOptions = {
|
|
|
381
412
|
declare class SandboxClient {
|
|
382
413
|
private readonly handle;
|
|
383
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
|
+
}>;
|
|
384
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
|
+
}>;
|
|
385
436
|
static connect(options: SandboxClientConnectOptions): Promise<SandboxClient>;
|
|
386
437
|
get id(): string;
|
|
387
438
|
get provider(): SandboxProvider;
|
|
@@ -391,20 +442,54 @@ declare class SandboxClient {
|
|
|
391
442
|
readFile(path: string): Promise<string>;
|
|
392
443
|
readFileBytes(path: string): Promise<Uint8Array>;
|
|
393
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>;
|
|
394
472
|
setTimeout(timeoutMs: number): Promise<void>;
|
|
395
473
|
kill(): Promise<void>;
|
|
396
474
|
destroy(): Promise<void>;
|
|
397
475
|
}
|
|
476
|
+
/** @deprecated Use `AgentKind` for user-facing task/session terminology. */
|
|
398
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';
|
|
399
481
|
declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
|
|
400
482
|
readonly sandbox: SandboxConfig;
|
|
401
483
|
readonly provider: SandboxProvider;
|
|
402
484
|
readonly template: string;
|
|
403
485
|
readonly inputSchema: SchemaLike<TInput>;
|
|
404
|
-
/** Only populated for
|
|
486
|
+
/** Only populated for structured-task agents; undefined for session agents. */
|
|
405
487
|
readonly outputSchema?: SchemaLike<TOutput>;
|
|
406
|
-
/** Only populated for
|
|
488
|
+
/** Only populated for attached-session agents; undefined for run-output agents. */
|
|
407
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. */
|
|
408
493
|
readonly mode: AgentMode;
|
|
409
494
|
readonly maxDuration: number;
|
|
410
495
|
readonly dependencies: OsDependencies;
|
|
@@ -417,6 +502,7 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
|
|
|
417
502
|
private _sandboxId?;
|
|
418
503
|
private _sourceFile;
|
|
419
504
|
constructor(config: RunAgentConfig<TInput, TOutput>);
|
|
505
|
+
constructor(config: SessionAgentConfig<TInput, TFrame>);
|
|
420
506
|
constructor(config: ServerAgentConfig<TInput, TFrame>);
|
|
421
507
|
constructor(config: AgentConfig<TInput, TOutput, TFrame>);
|
|
422
508
|
get sandboxId(): string | undefined;
|
|
@@ -501,8 +587,16 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
|
|
|
501
587
|
sandboxId?: string;
|
|
502
588
|
}): Promise<AgentRunResult<TOutput>>;
|
|
503
589
|
/**
|
|
504
|
-
*
|
|
505
|
-
*
|
|
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.
|
|
506
600
|
*/
|
|
507
601
|
invoke(input: TInput, options?: {
|
|
508
602
|
sandboxId?: string;
|
|
@@ -510,4 +604,4 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
|
|
|
510
604
|
}): AsyncGenerator<TFrame>;
|
|
511
605
|
}
|
|
512
606
|
|
|
513
|
-
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, type LocalDirectoryUpload, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type ResolveAgentSourceFileOptions, type RunAgentConfig, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions,
|
|
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 };
|
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
|
-
|
|
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;
|
|
@@ -253,30 +293,36 @@ interface RunAgentConfig<TInput, TOutput> extends AgentSharedConfig<TInput> {
|
|
|
253
293
|
outputSchema: SchemaLike<TOutput>;
|
|
254
294
|
run: (input: TInput, ctx: AgentRunContext) => Promise<TOutput>;
|
|
255
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
|
+
}
|
|
256
313
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* Use this when turns benefit from real-time progress streaming, cancel
|
|
260
|
-
* 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()`.
|
|
261
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. */
|
|
262
322
|
interface ServerAgentConfig<TInput, TFrame> extends AgentSharedConfig<TInput> {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
/** Schema used to validate each frame the server emits. */
|
|
267
|
-
frameSchema: SchemaLike<TFrame>;
|
|
268
|
-
/**
|
|
269
|
-
* User-provided async handler. Receives validated input, a cancel signal
|
|
270
|
-
* wired from the host, and an `emit` callback used to push SSE frames to
|
|
271
|
-
* the host as the handler runs.
|
|
272
|
-
*/
|
|
273
|
-
handler: (args: {
|
|
274
|
-
input: TInput;
|
|
275
|
-
ctx: AgentRunContext;
|
|
276
|
-
signal: AbortSignal;
|
|
277
|
-
emit: (frame: TFrame) => Promise<void>;
|
|
278
|
-
}) => Promise<void>;
|
|
279
|
-
};
|
|
323
|
+
/** @deprecated Use `session`. */
|
|
324
|
+
server: AgentSessionHandler<TInput, TFrame>;
|
|
325
|
+
session?: never;
|
|
280
326
|
}
|
|
281
327
|
interface E2BSandboxConfig {
|
|
282
328
|
provider: 'e2b';
|
|
@@ -325,28 +371,12 @@ interface DaytonaSandboxConfig {
|
|
|
325
371
|
}
|
|
326
372
|
type SandboxConfig = E2BSandboxConfig | DaytonaSandboxConfig;
|
|
327
373
|
/**
|
|
328
|
-
* Agent config accepted by `new Agent(config)`. Can be either
|
|
329
|
-
* (`run`) or
|
|
330
|
-
* in-sandbox HTTP server.
|
|
331
|
-
*
|
|
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.
|
|
332
378
|
*/
|
|
333
|
-
type AgentConfig<TInput, TOutput, TFrame = unknown> = RunAgentConfig<TInput, TOutput> | ServerAgentConfig<TInput, TFrame>;
|
|
334
|
-
type SandboxFileContent = string | ArrayBuffer | Uint8Array | Buffer;
|
|
335
|
-
interface SandboxCommandOptions {
|
|
336
|
-
cwd?: string;
|
|
337
|
-
envs?: Record<string, string>;
|
|
338
|
-
timeoutMs: number;
|
|
339
|
-
onStdout?: (data: string) => void;
|
|
340
|
-
onStderr?: (data: string) => void;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Result from running a sandbox command with captured output.
|
|
344
|
-
*/
|
|
345
|
-
interface SandboxCommandResult {
|
|
346
|
-
exitCode: number;
|
|
347
|
-
stdout: string;
|
|
348
|
-
stderr: string;
|
|
349
|
-
}
|
|
379
|
+
type AgentConfig<TInput, TOutput, TFrame = unknown> = RunAgentConfig<TInput, TOutput> | SessionAgentConfig<TInput, TFrame> | ServerAgentConfig<TInput, TFrame>;
|
|
350
380
|
type SandboxClientCreateOptions = {
|
|
351
381
|
provider: 'e2b';
|
|
352
382
|
template?: string;
|
|
@@ -361,6 +391,7 @@ type SandboxClientCreateOptions = {
|
|
|
361
391
|
apiKey?: string;
|
|
362
392
|
envs?: Record<string, string | undefined>;
|
|
363
393
|
createTimeoutSec?: number;
|
|
394
|
+
autoStopInterval?: number;
|
|
364
395
|
autoDeleteInterval?: number;
|
|
365
396
|
networkBlockAll?: boolean;
|
|
366
397
|
networkAllowList?: string;
|
|
@@ -381,7 +412,27 @@ type SandboxClientConnectOptions = {
|
|
|
381
412
|
declare class SandboxClient {
|
|
382
413
|
private readonly handle;
|
|
383
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
|
+
}>;
|
|
384
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
|
+
}>;
|
|
385
436
|
static connect(options: SandboxClientConnectOptions): Promise<SandboxClient>;
|
|
386
437
|
get id(): string;
|
|
387
438
|
get provider(): SandboxProvider;
|
|
@@ -391,20 +442,54 @@ declare class SandboxClient {
|
|
|
391
442
|
readFile(path: string): Promise<string>;
|
|
392
443
|
readFileBytes(path: string): Promise<Uint8Array>;
|
|
393
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>;
|
|
394
472
|
setTimeout(timeoutMs: number): Promise<void>;
|
|
395
473
|
kill(): Promise<void>;
|
|
396
474
|
destroy(): Promise<void>;
|
|
397
475
|
}
|
|
476
|
+
/** @deprecated Use `AgentKind` for user-facing task/session terminology. */
|
|
398
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';
|
|
399
481
|
declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
|
|
400
482
|
readonly sandbox: SandboxConfig;
|
|
401
483
|
readonly provider: SandboxProvider;
|
|
402
484
|
readonly template: string;
|
|
403
485
|
readonly inputSchema: SchemaLike<TInput>;
|
|
404
|
-
/** Only populated for
|
|
486
|
+
/** Only populated for structured-task agents; undefined for session agents. */
|
|
405
487
|
readonly outputSchema?: SchemaLike<TOutput>;
|
|
406
|
-
/** Only populated for
|
|
488
|
+
/** Only populated for attached-session agents; undefined for run-output agents. */
|
|
407
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. */
|
|
408
493
|
readonly mode: AgentMode;
|
|
409
494
|
readonly maxDuration: number;
|
|
410
495
|
readonly dependencies: OsDependencies;
|
|
@@ -417,6 +502,7 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
|
|
|
417
502
|
private _sandboxId?;
|
|
418
503
|
private _sourceFile;
|
|
419
504
|
constructor(config: RunAgentConfig<TInput, TOutput>);
|
|
505
|
+
constructor(config: SessionAgentConfig<TInput, TFrame>);
|
|
420
506
|
constructor(config: ServerAgentConfig<TInput, TFrame>);
|
|
421
507
|
constructor(config: AgentConfig<TInput, TOutput, TFrame>);
|
|
422
508
|
get sandboxId(): string | undefined;
|
|
@@ -501,8 +587,16 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
|
|
|
501
587
|
sandboxId?: string;
|
|
502
588
|
}): Promise<AgentRunResult<TOutput>>;
|
|
503
589
|
/**
|
|
504
|
-
*
|
|
505
|
-
*
|
|
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.
|
|
506
600
|
*/
|
|
507
601
|
invoke(input: TInput, options?: {
|
|
508
602
|
sandboxId?: string;
|
|
@@ -510,4 +604,4 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
|
|
|
510
604
|
}): AsyncGenerator<TFrame>;
|
|
511
605
|
}
|
|
512
606
|
|
|
513
|
-
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, type LocalDirectoryUpload, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type ResolveAgentSourceFileOptions, type RunAgentConfig, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions,
|
|
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 };
|