@declaw/sdk 1.0.2 → 1.0.3

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
@@ -818,6 +818,19 @@ declare class Filesystem {
818
818
  }): Promise<WatchHandle>;
819
819
  }
820
820
 
821
+ /** Outcome of a PTY session — produced by `PtyHandle.wait()`. */
822
+ interface PtyResult {
823
+ /** Remote shell exit code. `-1` if the stream dropped before a clean exit frame. */
824
+ exitCode: number;
825
+ }
826
+ /** Options for attaching to a running PTY via `Pty.connect()`. */
827
+ interface PtyConnectOpts {
828
+ /**
829
+ * Callback invoked with every chunk of PTY output as raw bytes.
830
+ * Optional — omit to drive the stream via the handle's async iterator.
831
+ */
832
+ onData?: (data: Uint8Array) => void;
833
+ }
821
834
  /** Options for creating a PTY session. */
822
835
  interface PtyCreateOpts {
823
836
  /** Terminal size. Defaults to { cols: 80, rows: 24 }. */
@@ -828,7 +841,11 @@ interface PtyCreateOpts {
828
841
  cwd?: string;
829
842
  /** Environment variables. */
830
843
  envs?: Record<string, string>;
831
- /** Command timeout in seconds. */
844
+ /**
845
+ * PTY session TTL in seconds. Defaults to 3600 (1 hour). Pass `0` to
846
+ * keep the session alive indefinitely — it will still die when the
847
+ * parent sandbox's timeout fires.
848
+ */
832
849
  timeout?: number;
833
850
  /** Per-request timeout in milliseconds (applies to the initial create call only). */
834
851
  requestTimeout?: number;
@@ -868,8 +885,8 @@ declare class PtyHandle {
868
885
  * running server-side and a fresh `stream()` call reattaches.
869
886
  */
870
887
  disconnect(): void;
871
- /** Resolves with the remote exit code when the PTY process exits. */
872
- wait(): Promise<number>;
888
+ /** Resolves with the remote exit result when the PTY process exits. */
889
+ wait(): Promise<PtyResult>;
873
890
  /**
874
891
  * Async iterator over raw output chunks. Use when you want to drive
875
892
  * the stream yourself:
@@ -894,6 +911,15 @@ declare class Pty {
894
911
  private readonly client;
895
912
  constructor(sandboxId: string, client: ApiClient);
896
913
  create(opts?: PtyCreateOpts): Promise<PtyHandle>;
914
+ /**
915
+ * Reattach to an already-running PTY by its pid.
916
+ *
917
+ * Returns a fresh `PtyHandle` that streams the live output of the
918
+ * existing session. Multiple clients can subscribe to the same pid
919
+ * concurrently — each receives output from the moment it connects
920
+ * (no scrollback replay).
921
+ */
922
+ connect(pid: number, opts?: PtyConnectOpts): PtyHandle;
897
923
  kill(pid: number, requestTimeout?: number): Promise<boolean>;
898
924
  sendStdin(pid: number, data: Uint8Array | string, requestTimeout?: number): Promise<void>;
899
925
  resize(pid: number, size: PtySize, requestTimeout?: number): Promise<void>;
@@ -1382,4 +1408,4 @@ declare class Template {
1382
1408
  static getBuildStatus(buildId: string, opts?: GetBuildStatusOpts): Promise<TemplateBuildStatus>;
1383
1409
  }
1384
1410
 
1385
- 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 PtyCreateOpts, PtyHandle, type PtyOutput, 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, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseWriteInfo, requiresTlsInterception, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry };
1411
+ 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, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseWriteInfo, requiresTlsInterception, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry };
package/dist/index.d.ts CHANGED
@@ -818,6 +818,19 @@ declare class Filesystem {
818
818
  }): Promise<WatchHandle>;
819
819
  }
820
820
 
821
+ /** Outcome of a PTY session — produced by `PtyHandle.wait()`. */
822
+ interface PtyResult {
823
+ /** Remote shell exit code. `-1` if the stream dropped before a clean exit frame. */
824
+ exitCode: number;
825
+ }
826
+ /** Options for attaching to a running PTY via `Pty.connect()`. */
827
+ interface PtyConnectOpts {
828
+ /**
829
+ * Callback invoked with every chunk of PTY output as raw bytes.
830
+ * Optional — omit to drive the stream via the handle's async iterator.
831
+ */
832
+ onData?: (data: Uint8Array) => void;
833
+ }
821
834
  /** Options for creating a PTY session. */
822
835
  interface PtyCreateOpts {
823
836
  /** Terminal size. Defaults to { cols: 80, rows: 24 }. */
@@ -828,7 +841,11 @@ interface PtyCreateOpts {
828
841
  cwd?: string;
829
842
  /** Environment variables. */
830
843
  envs?: Record<string, string>;
831
- /** Command timeout in seconds. */
844
+ /**
845
+ * PTY session TTL in seconds. Defaults to 3600 (1 hour). Pass `0` to
846
+ * keep the session alive indefinitely — it will still die when the
847
+ * parent sandbox's timeout fires.
848
+ */
832
849
  timeout?: number;
833
850
  /** Per-request timeout in milliseconds (applies to the initial create call only). */
834
851
  requestTimeout?: number;
@@ -868,8 +885,8 @@ declare class PtyHandle {
868
885
  * running server-side and a fresh `stream()` call reattaches.
869
886
  */
870
887
  disconnect(): void;
871
- /** Resolves with the remote exit code when the PTY process exits. */
872
- wait(): Promise<number>;
888
+ /** Resolves with the remote exit result when the PTY process exits. */
889
+ wait(): Promise<PtyResult>;
873
890
  /**
874
891
  * Async iterator over raw output chunks. Use when you want to drive
875
892
  * the stream yourself:
@@ -894,6 +911,15 @@ declare class Pty {
894
911
  private readonly client;
895
912
  constructor(sandboxId: string, client: ApiClient);
896
913
  create(opts?: PtyCreateOpts): Promise<PtyHandle>;
914
+ /**
915
+ * Reattach to an already-running PTY by its pid.
916
+ *
917
+ * Returns a fresh `PtyHandle` that streams the live output of the
918
+ * existing session. Multiple clients can subscribe to the same pid
919
+ * concurrently — each receives output from the moment it connects
920
+ * (no scrollback replay).
921
+ */
922
+ connect(pid: number, opts?: PtyConnectOpts): PtyHandle;
897
923
  kill(pid: number, requestTimeout?: number): Promise<boolean>;
898
924
  sendStdin(pid: number, data: Uint8Array | string, requestTimeout?: number): Promise<void>;
899
925
  resize(pid: number, size: PtySize, requestTimeout?: number): Promise<void>;
@@ -1382,4 +1408,4 @@ declare class Template {
1382
1408
  static getBuildStatus(buildId: string, opts?: GetBuildStatusOpts): Promise<TemplateBuildStatus>;
1383
1409
  }
1384
1410
 
1385
- 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 PtyCreateOpts, PtyHandle, type PtyOutput, 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, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseWriteInfo, requiresTlsInterception, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry };
1411
+ 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, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseWriteInfo, requiresTlsInterception, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry };
package/dist/index.js CHANGED
@@ -1539,7 +1539,7 @@ var PtyHandle = class {
1539
1539
  disconnect() {
1540
1540
  this.aborter.abort();
1541
1541
  }
1542
- /** Resolves with the remote exit code when the PTY process exits. */
1542
+ /** Resolves with the remote exit result when the PTY process exits. */
1543
1543
  wait() {
1544
1544
  return this.exitPromise;
1545
1545
  }
@@ -1576,7 +1576,7 @@ var PtyHandle = class {
1576
1576
  const parsed = parseSSEFrame(frame);
1577
1577
  if (!parsed) continue;
1578
1578
  if (parsed.event === "exit") {
1579
- this.resolveExit(parsed.exitCode ?? -1);
1579
+ this.resolveExit({ exitCode: parsed.exitCode ?? -1 });
1580
1580
  return;
1581
1581
  }
1582
1582
  if (parsed.bytes) {
@@ -1598,7 +1598,7 @@ var PtyHandle = class {
1598
1598
  throw err;
1599
1599
  }
1600
1600
  } finally {
1601
- this.resolveExit(-1);
1601
+ this.resolveExit({ exitCode: -1 });
1602
1602
  }
1603
1603
  }
1604
1604
  };
@@ -1645,11 +1645,11 @@ var Pty = class {
1645
1645
  const user = opts?.user ?? "user";
1646
1646
  const body = {
1647
1647
  size: { cols: size.cols, rows: size.rows },
1648
- user
1648
+ user,
1649
+ timeout: opts?.timeout ?? 3600
1649
1650
  };
1650
1651
  if (opts?.cwd !== void 0) body.cwd = opts.cwd;
1651
1652
  if (opts?.envs !== void 0) body.envs = opts.envs;
1652
- if (opts?.timeout !== void 0) body.timeout = opts.timeout;
1653
1653
  const data = await this.client.post(
1654
1654
  `/sandboxes/${this.sandboxId}/pty`,
1655
1655
  { json: body, timeout: opts?.requestTimeout }
@@ -1657,7 +1657,18 @@ var Pty = class {
1657
1657
  const pid = data.pid;
1658
1658
  return new PtyHandle(pid, this.sandboxId, this.client, opts?.onData);
1659
1659
  }
1660
- // --- Legacy low-level API (kept for callers that already hold a pid). ---
1660
+ /**
1661
+ * Reattach to an already-running PTY by its pid.
1662
+ *
1663
+ * Returns a fresh `PtyHandle` that streams the live output of the
1664
+ * existing session. Multiple clients can subscribe to the same pid
1665
+ * concurrently — each receives output from the moment it connects
1666
+ * (no scrollback replay).
1667
+ */
1668
+ connect(pid, opts) {
1669
+ return new PtyHandle(pid, this.sandboxId, this.client, opts?.onData);
1670
+ }
1671
+ // --- Low-level API by pid (kept for callers that already hold one). ---
1661
1672
  async kill(pid, requestTimeout) {
1662
1673
  const data = await this.client.delete(
1663
1674
  `/sandboxes/${this.sandboxId}/pty/${pid}`,