@declaw/sdk 1.0.2 → 1.0.4

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
@@ -153,7 +153,6 @@ declare enum InjectionSensitivity {
153
153
  /** Actions to take when injection is detected. */
154
154
  declare enum InjectionAction {
155
155
  Block = "block",
156
- Sanitize = "sanitize",
157
156
  LogOnly = "log_only"
158
157
  }
159
158
  /** Configuration for injection defense. */
@@ -818,6 +817,19 @@ declare class Filesystem {
818
817
  }): Promise<WatchHandle>;
819
818
  }
820
819
 
820
+ /** Outcome of a PTY session — produced by `PtyHandle.wait()`. */
821
+ interface PtyResult {
822
+ /** Remote shell exit code. `-1` if the stream dropped before a clean exit frame. */
823
+ exitCode: number;
824
+ }
825
+ /** Options for attaching to a running PTY via `Pty.connect()`. */
826
+ interface PtyConnectOpts {
827
+ /**
828
+ * Callback invoked with every chunk of PTY output as raw bytes.
829
+ * Optional — omit to drive the stream via the handle's async iterator.
830
+ */
831
+ onData?: (data: Uint8Array) => void;
832
+ }
821
833
  /** Options for creating a PTY session. */
822
834
  interface PtyCreateOpts {
823
835
  /** Terminal size. Defaults to { cols: 80, rows: 24 }. */
@@ -828,7 +840,11 @@ interface PtyCreateOpts {
828
840
  cwd?: string;
829
841
  /** Environment variables. */
830
842
  envs?: Record<string, string>;
831
- /** Command timeout in seconds. */
843
+ /**
844
+ * PTY session TTL in seconds. Defaults to 3600 (1 hour). Pass `0` to
845
+ * keep the session alive indefinitely — it will still die when the
846
+ * parent sandbox's timeout fires.
847
+ */
832
848
  timeout?: number;
833
849
  /** Per-request timeout in milliseconds (applies to the initial create call only). */
834
850
  requestTimeout?: number;
@@ -868,8 +884,8 @@ declare class PtyHandle {
868
884
  * running server-side and a fresh `stream()` call reattaches.
869
885
  */
870
886
  disconnect(): void;
871
- /** Resolves with the remote exit code when the PTY process exits. */
872
- wait(): Promise<number>;
887
+ /** Resolves with the remote exit result when the PTY process exits. */
888
+ wait(): Promise<PtyResult>;
873
889
  /**
874
890
  * Async iterator over raw output chunks. Use when you want to drive
875
891
  * the stream yourself:
@@ -894,6 +910,15 @@ declare class Pty {
894
910
  private readonly client;
895
911
  constructor(sandboxId: string, client: ApiClient);
896
912
  create(opts?: PtyCreateOpts): Promise<PtyHandle>;
913
+ /**
914
+ * Reattach to an already-running PTY by its pid.
915
+ *
916
+ * Returns a fresh `PtyHandle` that streams the live output of the
917
+ * existing session. Multiple clients can subscribe to the same pid
918
+ * concurrently — each receives output from the moment it connects
919
+ * (no scrollback replay).
920
+ */
921
+ connect(pid: number, opts?: PtyConnectOpts): PtyHandle;
897
922
  kill(pid: number, requestTimeout?: number): Promise<boolean>;
898
923
  sendStdin(pid: number, data: Uint8Array | string, requestTimeout?: number): Promise<void>;
899
924
  resize(pid: number, size: PtySize, requestTimeout?: number): Promise<void>;
@@ -1382,4 +1407,4 @@ declare class Template {
1382
1407
  static getBuildStatus(buildId: string, opts?: GetBuildStatusOpts): Promise<TemplateBuildStatus>;
1383
1408
  }
1384
1409
 
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 };
1410
+ 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
@@ -153,7 +153,6 @@ declare enum InjectionSensitivity {
153
153
  /** Actions to take when injection is detected. */
154
154
  declare enum InjectionAction {
155
155
  Block = "block",
156
- Sanitize = "sanitize",
157
156
  LogOnly = "log_only"
158
157
  }
159
158
  /** Configuration for injection defense. */
@@ -818,6 +817,19 @@ declare class Filesystem {
818
817
  }): Promise<WatchHandle>;
819
818
  }
820
819
 
820
+ /** Outcome of a PTY session — produced by `PtyHandle.wait()`. */
821
+ interface PtyResult {
822
+ /** Remote shell exit code. `-1` if the stream dropped before a clean exit frame. */
823
+ exitCode: number;
824
+ }
825
+ /** Options for attaching to a running PTY via `Pty.connect()`. */
826
+ interface PtyConnectOpts {
827
+ /**
828
+ * Callback invoked with every chunk of PTY output as raw bytes.
829
+ * Optional — omit to drive the stream via the handle's async iterator.
830
+ */
831
+ onData?: (data: Uint8Array) => void;
832
+ }
821
833
  /** Options for creating a PTY session. */
822
834
  interface PtyCreateOpts {
823
835
  /** Terminal size. Defaults to { cols: 80, rows: 24 }. */
@@ -828,7 +840,11 @@ interface PtyCreateOpts {
828
840
  cwd?: string;
829
841
  /** Environment variables. */
830
842
  envs?: Record<string, string>;
831
- /** Command timeout in seconds. */
843
+ /**
844
+ * PTY session TTL in seconds. Defaults to 3600 (1 hour). Pass `0` to
845
+ * keep the session alive indefinitely — it will still die when the
846
+ * parent sandbox's timeout fires.
847
+ */
832
848
  timeout?: number;
833
849
  /** Per-request timeout in milliseconds (applies to the initial create call only). */
834
850
  requestTimeout?: number;
@@ -868,8 +884,8 @@ declare class PtyHandle {
868
884
  * running server-side and a fresh `stream()` call reattaches.
869
885
  */
870
886
  disconnect(): void;
871
- /** Resolves with the remote exit code when the PTY process exits. */
872
- wait(): Promise<number>;
887
+ /** Resolves with the remote exit result when the PTY process exits. */
888
+ wait(): Promise<PtyResult>;
873
889
  /**
874
890
  * Async iterator over raw output chunks. Use when you want to drive
875
891
  * the stream yourself:
@@ -894,6 +910,15 @@ declare class Pty {
894
910
  private readonly client;
895
911
  constructor(sandboxId: string, client: ApiClient);
896
912
  create(opts?: PtyCreateOpts): Promise<PtyHandle>;
913
+ /**
914
+ * Reattach to an already-running PTY by its pid.
915
+ *
916
+ * Returns a fresh `PtyHandle` that streams the live output of the
917
+ * existing session. Multiple clients can subscribe to the same pid
918
+ * concurrently — each receives output from the moment it connects
919
+ * (no scrollback replay).
920
+ */
921
+ connect(pid: number, opts?: PtyConnectOpts): PtyHandle;
897
922
  kill(pid: number, requestTimeout?: number): Promise<boolean>;
898
923
  sendStdin(pid: number, data: Uint8Array | string, requestTimeout?: number): Promise<void>;
899
924
  resize(pid: number, size: PtySize, requestTimeout?: number): Promise<void>;
@@ -1382,4 +1407,4 @@ declare class Template {
1382
1407
  static getBuildStatus(buildId: string, opts?: GetBuildStatusOpts): Promise<TemplateBuildStatus>;
1383
1408
  }
1384
1409
 
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 };
1410
+ 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
@@ -404,7 +404,6 @@ var InjectionSensitivity = /* @__PURE__ */ ((InjectionSensitivity2) => {
404
404
  })(InjectionSensitivity || {});
405
405
  var InjectionAction = /* @__PURE__ */ ((InjectionAction2) => {
406
406
  InjectionAction2["Block"] = "block";
407
- InjectionAction2["Sanitize"] = "sanitize";
408
407
  InjectionAction2["LogOnly"] = "log_only";
409
408
  return InjectionAction2;
410
409
  })(InjectionAction || {});
@@ -414,7 +413,7 @@ function createInjectionDefenseConfig(opts) {
414
413
  const config = {
415
414
  enabled: opts?.enabled ?? false,
416
415
  sensitivity: opts?.sensitivity ?? "medium" /* Medium */,
417
- action: opts?.action ?? "sanitize" /* Sanitize */,
416
+ action: opts?.action ?? "log_only" /* LogOnly */,
418
417
  threshold: opts?.threshold ?? 0.8,
419
418
  domains: opts?.domains
420
419
  };
@@ -439,7 +438,7 @@ function parseInjectionDefenseConfig(data) {
439
438
  return {
440
439
  enabled: data.enabled ?? false,
441
440
  sensitivity: data.sensitivity ?? "medium" /* Medium */,
442
- action: data.action ?? "sanitize" /* Sanitize */,
441
+ action: data.action ?? "log_only" /* LogOnly */,
443
442
  threshold: data.threshold ?? 0.8,
444
443
  domains: data.domains
445
444
  };
@@ -1539,7 +1538,7 @@ var PtyHandle = class {
1539
1538
  disconnect() {
1540
1539
  this.aborter.abort();
1541
1540
  }
1542
- /** Resolves with the remote exit code when the PTY process exits. */
1541
+ /** Resolves with the remote exit result when the PTY process exits. */
1543
1542
  wait() {
1544
1543
  return this.exitPromise;
1545
1544
  }
@@ -1576,7 +1575,7 @@ var PtyHandle = class {
1576
1575
  const parsed = parseSSEFrame(frame);
1577
1576
  if (!parsed) continue;
1578
1577
  if (parsed.event === "exit") {
1579
- this.resolveExit(parsed.exitCode ?? -1);
1578
+ this.resolveExit({ exitCode: parsed.exitCode ?? -1 });
1580
1579
  return;
1581
1580
  }
1582
1581
  if (parsed.bytes) {
@@ -1598,7 +1597,7 @@ var PtyHandle = class {
1598
1597
  throw err;
1599
1598
  }
1600
1599
  } finally {
1601
- this.resolveExit(-1);
1600
+ this.resolveExit({ exitCode: -1 });
1602
1601
  }
1603
1602
  }
1604
1603
  };
@@ -1645,11 +1644,11 @@ var Pty = class {
1645
1644
  const user = opts?.user ?? "user";
1646
1645
  const body = {
1647
1646
  size: { cols: size.cols, rows: size.rows },
1648
- user
1647
+ user,
1648
+ timeout: opts?.timeout ?? 3600
1649
1649
  };
1650
1650
  if (opts?.cwd !== void 0) body.cwd = opts.cwd;
1651
1651
  if (opts?.envs !== void 0) body.envs = opts.envs;
1652
- if (opts?.timeout !== void 0) body.timeout = opts.timeout;
1653
1652
  const data = await this.client.post(
1654
1653
  `/sandboxes/${this.sandboxId}/pty`,
1655
1654
  { json: body, timeout: opts?.requestTimeout }
@@ -1657,7 +1656,18 @@ var Pty = class {
1657
1656
  const pid = data.pid;
1658
1657
  return new PtyHandle(pid, this.sandboxId, this.client, opts?.onData);
1659
1658
  }
1660
- // --- Legacy low-level API (kept for callers that already hold a pid). ---
1659
+ /**
1660
+ * Reattach to an already-running PTY by its pid.
1661
+ *
1662
+ * Returns a fresh `PtyHandle` that streams the live output of the
1663
+ * existing session. Multiple clients can subscribe to the same pid
1664
+ * concurrently — each receives output from the moment it connects
1665
+ * (no scrollback replay).
1666
+ */
1667
+ connect(pid, opts) {
1668
+ return new PtyHandle(pid, this.sandboxId, this.client, opts?.onData);
1669
+ }
1670
+ // --- Low-level API by pid (kept for callers that already hold one). ---
1661
1671
  async kill(pid, requestTimeout) {
1662
1672
  const data = await this.client.delete(
1663
1673
  `/sandboxes/${this.sandboxId}/pty/${pid}`,