@declaw/sdk 1.1.9 → 1.1.11
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 +12 -0
- package/dist/index.cjs +143 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -6
- package/dist/index.d.ts +54 -6
- package/dist/index.js +141 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -945,6 +945,53 @@ declare class Pty {
|
|
|
945
945
|
resize(pid: number, size: PtySize, requestTimeout?: number): Promise<void>;
|
|
946
946
|
}
|
|
947
947
|
|
|
948
|
+
/** Options for starting an interactive stdio process. */
|
|
949
|
+
interface StdioStartOpts {
|
|
950
|
+
envs?: Record<string, string>;
|
|
951
|
+
user?: string;
|
|
952
|
+
cwd?: string;
|
|
953
|
+
onStdout?: (data: Uint8Array) => void;
|
|
954
|
+
onStderr?: (data: Uint8Array) => void;
|
|
955
|
+
requestTimeout?: number;
|
|
956
|
+
}
|
|
957
|
+
/** Result returned when a stdio process exits. */
|
|
958
|
+
interface StdioResult {
|
|
959
|
+
exitCode: number;
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Handle for an interactive subprocess with stdin pipe.
|
|
963
|
+
*/
|
|
964
|
+
declare class StdioProcess {
|
|
965
|
+
readonly cmdId: string;
|
|
966
|
+
private readonly sandboxId;
|
|
967
|
+
private readonly client;
|
|
968
|
+
private lastEntryId;
|
|
969
|
+
private _exitCode;
|
|
970
|
+
private _bgStream;
|
|
971
|
+
constructor(cmdId: string, sandboxId: string, client: ApiClient, opts?: {
|
|
972
|
+
onStdout?: (data: Uint8Array) => void;
|
|
973
|
+
onStderr?: (data: Uint8Array) => void;
|
|
974
|
+
});
|
|
975
|
+
get exitCode(): number | null;
|
|
976
|
+
sendStdin(data: string | Uint8Array, requestTimeout?: number): Promise<void>;
|
|
977
|
+
closeStdin(requestTimeout?: number): Promise<void>;
|
|
978
|
+
kill(requestTimeout?: number): Promise<boolean>;
|
|
979
|
+
wait(): Promise<StdioResult>;
|
|
980
|
+
stream(opts?: {
|
|
981
|
+
onStdout?: (data: Uint8Array) => void;
|
|
982
|
+
onStderr?: (data: Uint8Array) => void;
|
|
983
|
+
}): Promise<StdioResult>;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Module for interactive stdio subprocess sessions in the sandbox.
|
|
987
|
+
*/
|
|
988
|
+
declare class Stdio {
|
|
989
|
+
private readonly sandboxId;
|
|
990
|
+
private readonly client;
|
|
991
|
+
constructor(sandboxId: string, client: ApiClient);
|
|
992
|
+
start(cmd: string, opts?: StdioStartOpts): Promise<StdioProcess>;
|
|
993
|
+
}
|
|
994
|
+
|
|
948
995
|
/** Request-side shape of a volume attachment on Sandbox.create. */
|
|
949
996
|
interface VolumeAttachment {
|
|
950
997
|
volumeId: string;
|
|
@@ -1016,6 +1063,7 @@ declare class Sandbox {
|
|
|
1016
1063
|
private readonly _commands;
|
|
1017
1064
|
private readonly _files;
|
|
1018
1065
|
private readonly _pty;
|
|
1066
|
+
private readonly _stdio;
|
|
1019
1067
|
private constructor();
|
|
1020
1068
|
/** The unique sandbox identifier. */
|
|
1021
1069
|
get sandboxId(): string;
|
|
@@ -1033,6 +1081,8 @@ declare class Sandbox {
|
|
|
1033
1081
|
get files(): Filesystem;
|
|
1034
1082
|
/** PTY sub-module for pseudo-terminal sessions. */
|
|
1035
1083
|
get pty(): Pty;
|
|
1084
|
+
/** Stdio sub-module for interactive subprocess sessions with stdin pipe. */
|
|
1085
|
+
get stdio(): Stdio;
|
|
1036
1086
|
/**
|
|
1037
1087
|
* Base URL for this sandbox's namespace on the Declaw API.
|
|
1038
1088
|
*
|
|
@@ -1044,15 +1094,13 @@ declare class Sandbox {
|
|
|
1044
1094
|
/**
|
|
1045
1095
|
* Return the path-based URL that reverse-proxies to `port` inside the sandbox.
|
|
1046
1096
|
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
*
|
|
1097
|
+
* Requires `allowPublicTraffic` to be enabled on the sandbox's network
|
|
1098
|
+
* config (the default). The returned URL is authenticated via the same
|
|
1099
|
+
* API key as all other sandbox operations.
|
|
1050
1100
|
*/
|
|
1051
1101
|
getHost(port: number): string;
|
|
1052
1102
|
/**
|
|
1053
1103
|
* Return the URL for an MCP server listening on port 50005 inside the sandbox.
|
|
1054
|
-
*
|
|
1055
|
-
* Same deployment caveat as {@link getHost}.
|
|
1056
1104
|
*/
|
|
1057
1105
|
getMcpUrl(): string;
|
|
1058
1106
|
/**
|
|
@@ -1574,4 +1622,4 @@ declare class Volumes {
|
|
|
1574
1622
|
static delete(volumeId: string, opts?: VolumeRequestOpts): Promise<void>;
|
|
1575
1623
|
}
|
|
1576
1624
|
|
|
1577
|
-
export { ALL_TRAFFIC, ApiClient, type AuditConfig, type AuditEntry, AuthenticationError, BuildError, type BuildInfo, type CodeSecurityConfig, CommandExitError, CommandHandle, type CommandResult, type CommandWaitOpts, Commands, ConnectionConfig, type ConnectionConfigOptions, type CopyItem, DEFAULT_MASK_PATTERNS, type EntryInfo, type EnvSecurityConfig, FileType, FileUploadError, Filesystem, type FilesystemEvent, FilesystemEventType, type GetBuildStatusOpts, GitAuthError, GitUpstreamError, InjectionAction, type InjectionDefenseConfig, InjectionSensitivity, InvalidArgumentError, type InvisibleTextConfig, type NetworkPolicy, NotEnoughSpaceError, NotFoundError, type PIIConfig, PIIType, type ProcessInfo, Pty, type PtyConnectOpts, type PtyCreateOpts, PtyHandle, type PtyOutput, type PtyResult, type PtySize, RedactionAction, type RequestOpts, type RunOpts, type RunStreamOpts, Sandbox, SandboxError, type SandboxInfo, type SandboxLifecycle, type SandboxMetrics, type SandboxNetworkOpts, type SandboxOpts, SandboxPaginator, type SandboxQuery, SandboxState, type SecureEnvVar, type SecurityPolicy, type Snapshot, type SnapshotInfo, SnapshotPaginator, type SnapshotSource, type Stderr, type Stdout, Template, TemplateBase, type TemplateBuildOpts, type TemplateBuildStatus, TemplateError, TimeoutError, type ToxicityConfig, TransformDirection, type TransformationRule, type VolumeAttachment, type VolumeCreateOpts, type VolumeInfo, type VolumeRequestOpts, Volumes, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, getSharedClient, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseVolumeInfo, parseWriteInfo, requiresTlsInterception, resetSharedClients, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry, volumeAttachmentToJSON };
|
|
1625
|
+
export { ALL_TRAFFIC, ApiClient, type AuditConfig, type AuditEntry, AuthenticationError, BuildError, type BuildInfo, type CodeSecurityConfig, CommandExitError, CommandHandle, type CommandResult, type CommandWaitOpts, Commands, ConnectionConfig, type ConnectionConfigOptions, type CopyItem, DEFAULT_MASK_PATTERNS, type EntryInfo, type EnvSecurityConfig, FileType, FileUploadError, Filesystem, type FilesystemEvent, FilesystemEventType, type GetBuildStatusOpts, GitAuthError, GitUpstreamError, InjectionAction, type InjectionDefenseConfig, InjectionSensitivity, InvalidArgumentError, type InvisibleTextConfig, type NetworkPolicy, NotEnoughSpaceError, NotFoundError, type PIIConfig, PIIType, type ProcessInfo, Pty, type PtyConnectOpts, type PtyCreateOpts, PtyHandle, type PtyOutput, type PtyResult, type PtySize, RedactionAction, type RequestOpts, type RunOpts, type RunStreamOpts, Sandbox, SandboxError, type SandboxInfo, type SandboxLifecycle, type SandboxMetrics, type SandboxNetworkOpts, type SandboxOpts, SandboxPaginator, type SandboxQuery, SandboxState, type SecureEnvVar, type SecurityPolicy, type Snapshot, type SnapshotInfo, SnapshotPaginator, type SnapshotSource, type Stderr, Stdio, StdioProcess, type StdioResult, type StdioStartOpts, type Stdout, Template, TemplateBase, type TemplateBuildOpts, type TemplateBuildStatus, TemplateError, TimeoutError, type ToxicityConfig, TransformDirection, type TransformationRule, type VolumeAttachment, type VolumeCreateOpts, type VolumeInfo, type VolumeRequestOpts, Volumes, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, getSharedClient, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseVolumeInfo, parseWriteInfo, requiresTlsInterception, resetSharedClients, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry, volumeAttachmentToJSON };
|
package/dist/index.d.ts
CHANGED
|
@@ -945,6 +945,53 @@ declare class Pty {
|
|
|
945
945
|
resize(pid: number, size: PtySize, requestTimeout?: number): Promise<void>;
|
|
946
946
|
}
|
|
947
947
|
|
|
948
|
+
/** Options for starting an interactive stdio process. */
|
|
949
|
+
interface StdioStartOpts {
|
|
950
|
+
envs?: Record<string, string>;
|
|
951
|
+
user?: string;
|
|
952
|
+
cwd?: string;
|
|
953
|
+
onStdout?: (data: Uint8Array) => void;
|
|
954
|
+
onStderr?: (data: Uint8Array) => void;
|
|
955
|
+
requestTimeout?: number;
|
|
956
|
+
}
|
|
957
|
+
/** Result returned when a stdio process exits. */
|
|
958
|
+
interface StdioResult {
|
|
959
|
+
exitCode: number;
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Handle for an interactive subprocess with stdin pipe.
|
|
963
|
+
*/
|
|
964
|
+
declare class StdioProcess {
|
|
965
|
+
readonly cmdId: string;
|
|
966
|
+
private readonly sandboxId;
|
|
967
|
+
private readonly client;
|
|
968
|
+
private lastEntryId;
|
|
969
|
+
private _exitCode;
|
|
970
|
+
private _bgStream;
|
|
971
|
+
constructor(cmdId: string, sandboxId: string, client: ApiClient, opts?: {
|
|
972
|
+
onStdout?: (data: Uint8Array) => void;
|
|
973
|
+
onStderr?: (data: Uint8Array) => void;
|
|
974
|
+
});
|
|
975
|
+
get exitCode(): number | null;
|
|
976
|
+
sendStdin(data: string | Uint8Array, requestTimeout?: number): Promise<void>;
|
|
977
|
+
closeStdin(requestTimeout?: number): Promise<void>;
|
|
978
|
+
kill(requestTimeout?: number): Promise<boolean>;
|
|
979
|
+
wait(): Promise<StdioResult>;
|
|
980
|
+
stream(opts?: {
|
|
981
|
+
onStdout?: (data: Uint8Array) => void;
|
|
982
|
+
onStderr?: (data: Uint8Array) => void;
|
|
983
|
+
}): Promise<StdioResult>;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Module for interactive stdio subprocess sessions in the sandbox.
|
|
987
|
+
*/
|
|
988
|
+
declare class Stdio {
|
|
989
|
+
private readonly sandboxId;
|
|
990
|
+
private readonly client;
|
|
991
|
+
constructor(sandboxId: string, client: ApiClient);
|
|
992
|
+
start(cmd: string, opts?: StdioStartOpts): Promise<StdioProcess>;
|
|
993
|
+
}
|
|
994
|
+
|
|
948
995
|
/** Request-side shape of a volume attachment on Sandbox.create. */
|
|
949
996
|
interface VolumeAttachment {
|
|
950
997
|
volumeId: string;
|
|
@@ -1016,6 +1063,7 @@ declare class Sandbox {
|
|
|
1016
1063
|
private readonly _commands;
|
|
1017
1064
|
private readonly _files;
|
|
1018
1065
|
private readonly _pty;
|
|
1066
|
+
private readonly _stdio;
|
|
1019
1067
|
private constructor();
|
|
1020
1068
|
/** The unique sandbox identifier. */
|
|
1021
1069
|
get sandboxId(): string;
|
|
@@ -1033,6 +1081,8 @@ declare class Sandbox {
|
|
|
1033
1081
|
get files(): Filesystem;
|
|
1034
1082
|
/** PTY sub-module for pseudo-terminal sessions. */
|
|
1035
1083
|
get pty(): Pty;
|
|
1084
|
+
/** Stdio sub-module for interactive subprocess sessions with stdin pipe. */
|
|
1085
|
+
get stdio(): Stdio;
|
|
1036
1086
|
/**
|
|
1037
1087
|
* Base URL for this sandbox's namespace on the Declaw API.
|
|
1038
1088
|
*
|
|
@@ -1044,15 +1094,13 @@ declare class Sandbox {
|
|
|
1044
1094
|
/**
|
|
1045
1095
|
* Return the path-based URL that reverse-proxies to `port` inside the sandbox.
|
|
1046
1096
|
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
*
|
|
1097
|
+
* Requires `allowPublicTraffic` to be enabled on the sandbox's network
|
|
1098
|
+
* config (the default). The returned URL is authenticated via the same
|
|
1099
|
+
* API key as all other sandbox operations.
|
|
1050
1100
|
*/
|
|
1051
1101
|
getHost(port: number): string;
|
|
1052
1102
|
/**
|
|
1053
1103
|
* Return the URL for an MCP server listening on port 50005 inside the sandbox.
|
|
1054
|
-
*
|
|
1055
|
-
* Same deployment caveat as {@link getHost}.
|
|
1056
1104
|
*/
|
|
1057
1105
|
getMcpUrl(): string;
|
|
1058
1106
|
/**
|
|
@@ -1574,4 +1622,4 @@ declare class Volumes {
|
|
|
1574
1622
|
static delete(volumeId: string, opts?: VolumeRequestOpts): Promise<void>;
|
|
1575
1623
|
}
|
|
1576
1624
|
|
|
1577
|
-
export { ALL_TRAFFIC, ApiClient, type AuditConfig, type AuditEntry, AuthenticationError, BuildError, type BuildInfo, type CodeSecurityConfig, CommandExitError, CommandHandle, type CommandResult, type CommandWaitOpts, Commands, ConnectionConfig, type ConnectionConfigOptions, type CopyItem, DEFAULT_MASK_PATTERNS, type EntryInfo, type EnvSecurityConfig, FileType, FileUploadError, Filesystem, type FilesystemEvent, FilesystemEventType, type GetBuildStatusOpts, GitAuthError, GitUpstreamError, InjectionAction, type InjectionDefenseConfig, InjectionSensitivity, InvalidArgumentError, type InvisibleTextConfig, type NetworkPolicy, NotEnoughSpaceError, NotFoundError, type PIIConfig, PIIType, type ProcessInfo, Pty, type PtyConnectOpts, type PtyCreateOpts, PtyHandle, type PtyOutput, type PtyResult, type PtySize, RedactionAction, type RequestOpts, type RunOpts, type RunStreamOpts, Sandbox, SandboxError, type SandboxInfo, type SandboxLifecycle, type SandboxMetrics, type SandboxNetworkOpts, type SandboxOpts, SandboxPaginator, type SandboxQuery, SandboxState, type SecureEnvVar, type SecurityPolicy, type Snapshot, type SnapshotInfo, SnapshotPaginator, type SnapshotSource, type Stderr, type Stdout, Template, TemplateBase, type TemplateBuildOpts, type TemplateBuildStatus, TemplateError, TimeoutError, type ToxicityConfig, TransformDirection, type TransformationRule, type VolumeAttachment, type VolumeCreateOpts, type VolumeInfo, type VolumeRequestOpts, Volumes, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, getSharedClient, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseVolumeInfo, parseWriteInfo, requiresTlsInterception, resetSharedClients, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry, volumeAttachmentToJSON };
|
|
1625
|
+
export { ALL_TRAFFIC, ApiClient, type AuditConfig, type AuditEntry, AuthenticationError, BuildError, type BuildInfo, type CodeSecurityConfig, CommandExitError, CommandHandle, type CommandResult, type CommandWaitOpts, Commands, ConnectionConfig, type ConnectionConfigOptions, type CopyItem, DEFAULT_MASK_PATTERNS, type EntryInfo, type EnvSecurityConfig, FileType, FileUploadError, Filesystem, type FilesystemEvent, FilesystemEventType, type GetBuildStatusOpts, GitAuthError, GitUpstreamError, InjectionAction, type InjectionDefenseConfig, InjectionSensitivity, InvalidArgumentError, type InvisibleTextConfig, type NetworkPolicy, NotEnoughSpaceError, NotFoundError, type PIIConfig, PIIType, type ProcessInfo, Pty, type PtyConnectOpts, type PtyCreateOpts, PtyHandle, type PtyOutput, type PtyResult, type PtySize, RedactionAction, type RequestOpts, type RunOpts, type RunStreamOpts, Sandbox, SandboxError, type SandboxInfo, type SandboxLifecycle, type SandboxMetrics, type SandboxNetworkOpts, type SandboxOpts, SandboxPaginator, type SandboxQuery, SandboxState, type SecureEnvVar, type SecurityPolicy, type Snapshot, type SnapshotInfo, SnapshotPaginator, type SnapshotSource, type Stderr, Stdio, StdioProcess, type StdioResult, type StdioStartOpts, type Stdout, Template, TemplateBase, type TemplateBuildOpts, type TemplateBuildStatus, TemplateError, TimeoutError, type ToxicityConfig, TransformDirection, type TransformationRule, type VolumeAttachment, type VolumeCreateOpts, type VolumeInfo, type VolumeRequestOpts, Volumes, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, getSharedClient, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseVolumeInfo, parseWriteInfo, requiresTlsInterception, resetSharedClients, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry, volumeAttachmentToJSON };
|
package/dist/index.js
CHANGED
|
@@ -1768,6 +1768,136 @@ var Pty = class {
|
|
|
1768
1768
|
}
|
|
1769
1769
|
};
|
|
1770
1770
|
|
|
1771
|
+
// src/sandbox/stdio/stdio.ts
|
|
1772
|
+
import { EventSourceParserStream as EventSourceParserStream2 } from "eventsource-parser/stream";
|
|
1773
|
+
var StdioProcess = class {
|
|
1774
|
+
cmdId;
|
|
1775
|
+
sandboxId;
|
|
1776
|
+
client;
|
|
1777
|
+
lastEntryId = 0;
|
|
1778
|
+
_exitCode = null;
|
|
1779
|
+
_bgStream = null;
|
|
1780
|
+
constructor(cmdId, sandboxId, client, opts) {
|
|
1781
|
+
this.cmdId = cmdId;
|
|
1782
|
+
this.sandboxId = sandboxId;
|
|
1783
|
+
this.client = client;
|
|
1784
|
+
if (opts?.onStdout || opts?.onStderr) {
|
|
1785
|
+
this._bgStream = this.stream({
|
|
1786
|
+
onStdout: opts.onStdout,
|
|
1787
|
+
onStderr: opts.onStderr
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
get exitCode() {
|
|
1792
|
+
return this._exitCode;
|
|
1793
|
+
}
|
|
1794
|
+
async sendStdin(data, requestTimeout) {
|
|
1795
|
+
const raw = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
1796
|
+
let binary = "";
|
|
1797
|
+
for (let i = 0; i < raw.length; i++) {
|
|
1798
|
+
binary += String.fromCharCode(raw[i]);
|
|
1799
|
+
}
|
|
1800
|
+
const encoded = btoa(binary);
|
|
1801
|
+
await this.client.post(
|
|
1802
|
+
`/sandboxes/${this.sandboxId}/stdio/${this.cmdId}/stdin`,
|
|
1803
|
+
{
|
|
1804
|
+
json: { data: encoded },
|
|
1805
|
+
timeout: requestTimeout
|
|
1806
|
+
}
|
|
1807
|
+
);
|
|
1808
|
+
}
|
|
1809
|
+
async closeStdin(requestTimeout) {
|
|
1810
|
+
await this.client.post(
|
|
1811
|
+
`/sandboxes/${this.sandboxId}/stdio/${this.cmdId}/stdin/close`,
|
|
1812
|
+
{ timeout: requestTimeout }
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
async kill(requestTimeout) {
|
|
1816
|
+
const resp = await this.client.delete(
|
|
1817
|
+
`/sandboxes/${this.sandboxId}/stdio/${this.cmdId}`,
|
|
1818
|
+
{ timeout: requestTimeout }
|
|
1819
|
+
);
|
|
1820
|
+
return Boolean(resp.killed);
|
|
1821
|
+
}
|
|
1822
|
+
async wait() {
|
|
1823
|
+
if (this._bgStream) {
|
|
1824
|
+
return this._bgStream;
|
|
1825
|
+
}
|
|
1826
|
+
return this.stream();
|
|
1827
|
+
}
|
|
1828
|
+
async stream(opts) {
|
|
1829
|
+
if (this._bgStream && !opts) {
|
|
1830
|
+
return this._bgStream;
|
|
1831
|
+
}
|
|
1832
|
+
let url = `/sandboxes/${this.sandboxId}/stdio/${this.cmdId}/stream`;
|
|
1833
|
+
if (this.lastEntryId > 0) {
|
|
1834
|
+
url += `?last_entry_id=${this.lastEntryId}`;
|
|
1835
|
+
}
|
|
1836
|
+
const response = await this.client.streamGet(url);
|
|
1837
|
+
const stream = response.body;
|
|
1838
|
+
if (!stream) {
|
|
1839
|
+
throw new SandboxError("No response body for stdio stream");
|
|
1840
|
+
}
|
|
1841
|
+
const eventStream = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream2());
|
|
1842
|
+
for await (const event of eventStream) {
|
|
1843
|
+
if (event.event === "exit") {
|
|
1844
|
+
try {
|
|
1845
|
+
const parsed = JSON.parse(event.data);
|
|
1846
|
+
this._exitCode = parsed.exit_code ?? -1;
|
|
1847
|
+
} catch {
|
|
1848
|
+
this._exitCode = -1;
|
|
1849
|
+
}
|
|
1850
|
+
break;
|
|
1851
|
+
}
|
|
1852
|
+
if (event.event === "stdout" || event.event === "stderr") {
|
|
1853
|
+
try {
|
|
1854
|
+
const parsed = JSON.parse(event.data);
|
|
1855
|
+
const entryId = parsed.entry_id ?? 0;
|
|
1856
|
+
if (entryId > this.lastEntryId) {
|
|
1857
|
+
this.lastEntryId = entryId;
|
|
1858
|
+
}
|
|
1859
|
+
const raw = atob(parsed.data ?? "");
|
|
1860
|
+
const bytes = new Uint8Array(raw.length);
|
|
1861
|
+
for (let i = 0; i < raw.length; i++) {
|
|
1862
|
+
bytes[i] = raw.charCodeAt(i);
|
|
1863
|
+
}
|
|
1864
|
+
if (event.event === "stdout" && opts?.onStdout) {
|
|
1865
|
+
opts.onStdout(bytes);
|
|
1866
|
+
} else if (event.event === "stderr" && opts?.onStderr) {
|
|
1867
|
+
opts.onStderr(bytes);
|
|
1868
|
+
}
|
|
1869
|
+
} catch {
|
|
1870
|
+
continue;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
return { exitCode: this._exitCode ?? -1 };
|
|
1875
|
+
}
|
|
1876
|
+
};
|
|
1877
|
+
var Stdio = class {
|
|
1878
|
+
sandboxId;
|
|
1879
|
+
client;
|
|
1880
|
+
constructor(sandboxId, client) {
|
|
1881
|
+
this.sandboxId = sandboxId;
|
|
1882
|
+
this.client = client;
|
|
1883
|
+
}
|
|
1884
|
+
async start(cmd, opts) {
|
|
1885
|
+
const user = opts?.user ?? "user";
|
|
1886
|
+
const body = { cmd, user };
|
|
1887
|
+
if (opts?.envs) body.envs = opts.envs;
|
|
1888
|
+
if (opts?.cwd) body.cwd = opts.cwd;
|
|
1889
|
+
const data = await this.client.post(
|
|
1890
|
+
`/sandboxes/${this.sandboxId}/stdio`,
|
|
1891
|
+
{ json: body, timeout: opts?.requestTimeout }
|
|
1892
|
+
);
|
|
1893
|
+
const cmdId = data.cmd_id;
|
|
1894
|
+
return new StdioProcess(cmdId, this.sandboxId, this.client, {
|
|
1895
|
+
onStdout: opts?.onStdout,
|
|
1896
|
+
onStderr: opts?.onStderr
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
|
|
1771
1901
|
// src/volumes/models.ts
|
|
1772
1902
|
function parseVolumeInfo(data) {
|
|
1773
1903
|
return {
|
|
@@ -1807,6 +1937,7 @@ var Sandbox = class _Sandbox {
|
|
|
1807
1937
|
_commands;
|
|
1808
1938
|
_files;
|
|
1809
1939
|
_pty;
|
|
1940
|
+
_stdio;
|
|
1810
1941
|
constructor(sandboxId, config, client, envdAccessToken, sandboxDomain, trafficAccessToken) {
|
|
1811
1942
|
this._sandboxId = sandboxId;
|
|
1812
1943
|
this._config = config;
|
|
@@ -1817,6 +1948,7 @@ var Sandbox = class _Sandbox {
|
|
|
1817
1948
|
this._commands = new Commands(sandboxId, client);
|
|
1818
1949
|
this._files = new Filesystem(sandboxId, client);
|
|
1819
1950
|
this._pty = new Pty(sandboxId, client);
|
|
1951
|
+
this._stdio = new Stdio(sandboxId, client);
|
|
1820
1952
|
}
|
|
1821
1953
|
/** The unique sandbox identifier. */
|
|
1822
1954
|
get sandboxId() {
|
|
@@ -1850,6 +1982,10 @@ var Sandbox = class _Sandbox {
|
|
|
1850
1982
|
get pty() {
|
|
1851
1983
|
return this._pty;
|
|
1852
1984
|
}
|
|
1985
|
+
/** Stdio sub-module for interactive subprocess sessions with stdin pipe. */
|
|
1986
|
+
get stdio() {
|
|
1987
|
+
return this._stdio;
|
|
1988
|
+
}
|
|
1853
1989
|
/**
|
|
1854
1990
|
* Base URL for this sandbox's namespace on the Declaw API.
|
|
1855
1991
|
*
|
|
@@ -1863,17 +1999,15 @@ var Sandbox = class _Sandbox {
|
|
|
1863
1999
|
/**
|
|
1864
2000
|
* Return the path-based URL that reverse-proxies to `port` inside the sandbox.
|
|
1865
2001
|
*
|
|
1866
|
-
*
|
|
1867
|
-
*
|
|
1868
|
-
*
|
|
2002
|
+
* Requires `allowPublicTraffic` to be enabled on the sandbox's network
|
|
2003
|
+
* config (the default). The returned URL is authenticated via the same
|
|
2004
|
+
* API key as all other sandbox operations.
|
|
1869
2005
|
*/
|
|
1870
2006
|
getHost(port) {
|
|
1871
2007
|
return `${this.envdApiUrl}/ports/${port}`;
|
|
1872
2008
|
}
|
|
1873
2009
|
/**
|
|
1874
2010
|
* Return the URL for an MCP server listening on port 50005 inside the sandbox.
|
|
1875
|
-
*
|
|
1876
|
-
* Same deployment caveat as {@link getHost}.
|
|
1877
2011
|
*/
|
|
1878
2012
|
getMcpUrl() {
|
|
1879
2013
|
return `${this.getHost(MCP_PORT)}/mcp`;
|
|
@@ -2708,6 +2842,8 @@ export {
|
|
|
2708
2842
|
SandboxPaginator,
|
|
2709
2843
|
SandboxState,
|
|
2710
2844
|
SnapshotPaginator,
|
|
2845
|
+
Stdio,
|
|
2846
|
+
StdioProcess,
|
|
2711
2847
|
Template,
|
|
2712
2848
|
TemplateBase,
|
|
2713
2849
|
TemplateError,
|