@declaw/sdk 1.2.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -88,6 +88,17 @@ declare class ApiClient {
88
88
  private buildUrl;
89
89
  private buildHeaders;
90
90
  private requestWithRetry;
91
+ /**
92
+ * Read an error body ONCE.
93
+ *
94
+ * `Response` bodies are single-read streams, so the 409 path cannot inspect
95
+ * the code and then hand the response to a separate error builder — the
96
+ * second read yields nothing and the error loses its message. Everything that
97
+ * needs the body goes through here, and the parsed result is passed around
98
+ * instead of the response.
99
+ */
100
+ private readErrorBody;
101
+ private errorFrom;
91
102
  private buildError;
92
103
  private parseResponseBody;
93
104
  /**
@@ -98,6 +109,37 @@ declare class ApiClient {
98
109
  declare function getSharedClient(config: ConnectionConfig): ApiClient;
99
110
  declare function resetSharedClients(): void;
100
111
 
112
+ /**
113
+ * Idempotency keys and retry pacing for `POST /sandboxes`.
114
+ *
115
+ * Note this SDK already jitters its backoff (see `ApiClient.delay` —
116
+ * exponential with an equal-jitter multiplier), unlike the Go and Python
117
+ * clients which used a deterministic `delay * attempt`. Only the key and the
118
+ * response-code handling are new here.
119
+ */
120
+ /**
121
+ * Machine-readable error codes returned by `POST /sandboxes`.
122
+ *
123
+ * Branch on these, never on the message. It matters most where one status means
124
+ * several unrelated things, and only one of them is retryable.
125
+ */
126
+ /**
127
+ * 409 — the original create carrying this key is still running. Retrying the
128
+ * IDENTICAL request is correct, and is how a caller recovers the sandbox ID
129
+ * after a lost response. `Retry-After` is set.
130
+ */
131
+ declare const CODE_IDEMPOTENCY_IN_PROGRESS = "idempotency_in_progress";
132
+ /**
133
+ * 422 — the key was already used with different parameters. Not retryable; the
134
+ * caller must generate a fresh key per logical create.
135
+ */
136
+ declare const CODE_IDEMPOTENCY_KEY_REUSED = "idempotency_key_reused";
137
+ /**
138
+ * 409 — unrelated to idempotency; the template needs a rebuild. Retrying the
139
+ * request unchanged cannot fix it.
140
+ */
141
+ declare const CODE_TEMPLATE_NOT_READY = "template_not_ready";
142
+
101
143
  /** CIDR for all traffic. */
102
144
  declare const ALL_TRAFFIC = "0.0.0.0/0";
103
145
  /** Network configuration options for a sandbox. */
@@ -186,9 +228,15 @@ interface InjectionDefenseConfig {
186
228
  enabled: boolean;
187
229
  sensitivity: string;
188
230
  action: string;
189
- /** Detection threshold (0.0–1.0). Defaults to 0.8. */
231
+ /** Detection threshold (0.0–1.0). Defaults to 0.95. */
190
232
  threshold: number;
191
- /** Optional domain allowlist; when undefined, applies to all domains. */
233
+ /**
234
+ * Scopes injection scanning to these destination hosts. Injection is
235
+ * OPT-IN per domain: with an empty or omitted list NO injection scanning
236
+ * runs (unlike PII/toxicity, where an empty list means all egress).
237
+ * Entries support exact hosts (`"api.example.com"`), `"*.suffix.com"`
238
+ * wildcards, and `"~regex"` patterns.
239
+ */
192
240
  domains?: string[];
193
241
  /** Optional Tier-2 LLM judge. */
194
242
  judge?: InjectionJudgeConfig;
@@ -451,9 +499,13 @@ interface FullInjectionDefenseOptions {
451
499
  action?: string;
452
500
  /** Run the judge on EVERY egress (high-assurance, costlier). Default false. */
453
501
  alwaysJudge?: boolean;
454
- /** Optional egress allowlist to scan; omit = all domains. */
502
+ /**
503
+ * Destination hosts to scan for injection. Injection is opt-in per domain:
504
+ * omit or leave empty to scan none. Entries support exact hosts,
505
+ * `"*.suffix.com"` wildcards, and `"~regex"` patterns.
506
+ */
455
507
  domains?: string[];
456
- /** Tier-1 classifier confidence threshold (0.0–1.0). Default 0.8. */
508
+ /** Tier-1 classifier confidence threshold (0.0–1.0). Default 0.95. */
457
509
  threshold?: number;
458
510
  }
459
511
  /**
@@ -1191,6 +1243,10 @@ interface SandboxOpts {
1191
1243
  metadata?: Record<string, string>;
1192
1244
  /** Environment variables. */
1193
1245
  envs?: Record<string, string>;
1246
+ /** Vault secret references: ENV_NAME -> "vault://team/env/secret". The real
1247
+ * value is resolved server+worker-side and injected at the egress proxy —
1248
+ * the sandbox only ever sees a placeholder, never the secret value. */
1249
+ vaultRefs?: Record<string, string>;
1194
1250
  /** Whether to create a secure sandbox. Defaults to true. */
1195
1251
  secure?: boolean;
1196
1252
  /** If false, denies all outbound traffic. Defaults to true. */
@@ -1509,38 +1565,54 @@ declare class Sandbox {
1509
1565
  */
1510
1566
  declare class SandboxError extends Error {
1511
1567
  sandboxId?: string;
1568
+ /**
1569
+ * Machine-readable error code from the API's `code` field, when present.
1570
+ *
1571
+ * Branch on this, never on `message`. Messages are prose and change; codes are
1572
+ * contract. It matters most where one status means several unrelated things:
1573
+ * a 409 from `POST /sandboxes` is either `idempotency_in_progress` (the
1574
+ * original create is still running — retry the identical request) or
1575
+ * `template_not_ready` (rebuild the template; retrying cannot help).
1576
+ */
1577
+ code?: string;
1512
1578
  constructor(message: string, opts?: {
1513
1579
  sandboxId?: string;
1580
+ code?: string;
1514
1581
  });
1515
1582
  }
1516
1583
  /** Thrown when an operation exceeds its timeout. */
1517
1584
  declare class TimeoutError extends SandboxError {
1518
1585
  constructor(message: string, opts?: {
1519
1586
  sandboxId?: string;
1587
+ code?: string;
1520
1588
  });
1521
1589
  }
1522
1590
  /** Thrown when a sandbox or resource is not found. */
1523
1591
  declare class NotFoundError extends SandboxError {
1524
1592
  constructor(message: string, opts?: {
1525
1593
  sandboxId?: string;
1594
+ code?: string;
1526
1595
  });
1527
1596
  }
1528
1597
  /** Thrown when authentication fails. */
1529
1598
  declare class AuthenticationError extends SandboxError {
1530
1599
  constructor(message: string, opts?: {
1531
1600
  sandboxId?: string;
1601
+ code?: string;
1532
1602
  });
1533
1603
  }
1534
1604
  /** Thrown when an argument is invalid. */
1535
1605
  declare class InvalidArgumentError extends SandboxError {
1536
1606
  constructor(message: string, opts?: {
1537
1607
  sandboxId?: string;
1608
+ code?: string;
1538
1609
  });
1539
1610
  }
1540
1611
  /** Thrown when there is not enough disk space. */
1541
1612
  declare class NotEnoughSpaceError extends SandboxError {
1542
1613
  constructor(message: string, opts?: {
1543
1614
  sandboxId?: string;
1615
+ code?: string;
1544
1616
  });
1545
1617
  }
1546
1618
  /**
@@ -1555,36 +1627,42 @@ declare class NotEnoughSpaceError extends SandboxError {
1555
1627
  declare class ConflictError extends SandboxError {
1556
1628
  constructor(message: string, opts?: {
1557
1629
  sandboxId?: string;
1630
+ code?: string;
1558
1631
  });
1559
1632
  }
1560
1633
  /** Thrown for template-related errors. */
1561
1634
  declare class TemplateError extends SandboxError {
1562
1635
  constructor(message: string, opts?: {
1563
1636
  sandboxId?: string;
1637
+ code?: string;
1564
1638
  });
1565
1639
  }
1566
1640
  /** Thrown when a template build fails. */
1567
1641
  declare class BuildError extends TemplateError {
1568
1642
  constructor(message: string, opts?: {
1569
1643
  sandboxId?: string;
1644
+ code?: string;
1570
1645
  });
1571
1646
  }
1572
1647
  /** Thrown when a file upload fails. */
1573
1648
  declare class FileUploadError extends SandboxError {
1574
1649
  constructor(message: string, opts?: {
1575
1650
  sandboxId?: string;
1651
+ code?: string;
1576
1652
  });
1577
1653
  }
1578
1654
  /** Thrown when git authentication fails inside a sandbox. */
1579
1655
  declare class GitAuthError extends SandboxError {
1580
1656
  constructor(message: string, opts?: {
1581
1657
  sandboxId?: string;
1658
+ code?: string;
1582
1659
  });
1583
1660
  }
1584
1661
  /** Thrown when a git upstream operation fails. */
1585
1662
  declare class GitUpstreamError extends SandboxError {
1586
1663
  constructor(message: string, opts?: {
1587
1664
  sandboxId?: string;
1665
+ code?: string;
1588
1666
  });
1589
1667
  }
1590
1668
  /** Thrown when a command exits with a non-zero exit code. */
@@ -1870,8 +1948,17 @@ interface VolumeCreateOpts extends VolumeRequestOpts {
1870
1948
  * are dropped on the server for safety.
1871
1949
  */
1872
1950
  declare class Volumes {
1873
- /** Create a volume by streaming a tarball (gzip tar.gz) to the server. */
1874
- static create(name: string, data: Uint8Array | ArrayBuffer, opts?: VolumeCreateOpts): Promise<VolumeInfo>;
1951
+ /**
1952
+ * Create a volume named `name`, optionally populated with `data`.
1953
+ *
1954
+ * `POST /volumes` is the canonical create endpoint. With `data` (a gzip tar.gz)
1955
+ * the body is ingested into a new file-granular volume (or a legacy tarball
1956
+ * blob if no file-granular backend is configured). Creating an empty volume
1957
+ * (no `data`, or an empty buffer) requires a file-granular backend.
1958
+ * `empty(name)` / `ingest(name, data)` remain available for explicit,
1959
+ * backend-specific control.
1960
+ */
1961
+ static create(name: string, data?: Uint8Array | ArrayBuffer, opts?: VolumeCreateOpts): Promise<VolumeInfo>;
1875
1962
  /**
1876
1963
  * Capture the attached volume's mount path in `sandboxId` into a NEW volume.
1877
1964
  *
@@ -1995,4 +2082,136 @@ declare class Governance {
1995
2082
  static getPack(name: string, opts?: GovernanceRequestOpts): Promise<GovernancePack>;
1996
2083
  }
1997
2084
 
1998
- export { ALL_TRAFFIC, ApiClient, type AuditConfig, type AuditEntry, AuthenticationError, BuildError, type BuildInfo, type CodeSecurityConfig, CommandExitError, CommandHandle, type CommandResult, type CommandWaitOpts, Commands, ConflictError, ConnectionConfig, type ConnectionConfigOptions, type ContentGateConfig, type CopyItem, DEFAULT_MASK_PATTERNS, type EntryInfo, type EnvSecurityConfig, type FileEntry, type FileInfo, FileType, FileUploadError, Filesystem, type FilesystemEvent, FilesystemEventType, type FullInjectionDefenseOptions, type GetBuildStatusOpts, GitAuthError, GitUpstreamError, Governance, type GovernanceAdvisory, type GovernanceControl, type GovernancePack, type GovernanceRequestOpts, InjectionAction, type InjectionDefenseConfig, type InjectionJudgeConfig, InjectionSensitivity, InvalidArgumentError, type InvisibleTextConfig, type LockLease, type LockStatus, 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 VolumeAttachMode, type VolumeAttachment, type VolumeCreateOpts, VolumeFiles, type VolumeInfo, VolumeLocks, type VolumeRemoveOpts, type VolumeRequestOpts, type VolumeWriteOpts, Volumes, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, contentGateConfigToJSON, createAuditConfig, createCodeSecurityConfig, createContentGateConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, fullInjectionDefensePolicy, getSharedClient, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseContentGateConfig, parseEntryInfo, parseEnvSecurityConfig, parseFileEntry, parseFileInfo, parseFilesystemEvent, parseGovernancePack, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseLockLease, parseLockStatus, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseVolumeInfo, parseWriteInfo, requiresTlsInterception, resetSharedClients, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry, volumeAttachmentToJSON };
2085
+ /**
2086
+ * One per-destination injection rule on a secret. The egress proxy matches
2087
+ * a request host against domainRegex and injects the secret as injectionType
2088
+ * (bearer|header|basic|query|sigv4|oidc|hmac|redis|postgres|mysql|smtp|mongodb).
2089
+ * The optional fields express a provider's full contract.
2090
+ */
2091
+ interface VaultScope {
2092
+ domainRegex: string;
2093
+ injectionType?: string;
2094
+ headerName?: string;
2095
+ valuePrefix?: string;
2096
+ basicUsername?: string;
2097
+ extraHeaders?: Record<string, string>;
2098
+ queryParams?: Record<string, string>;
2099
+ }
2100
+ /**
2101
+ * Metadata for a stored secret — never the value. The value lives
2102
+ * server-side (OpenBao) and is not returned after create.
2103
+ */
2104
+ interface VaultSecret {
2105
+ secretId: string;
2106
+ name: string;
2107
+ scopes?: VaultScope[];
2108
+ createdAt: string;
2109
+ updatedAt: string;
2110
+ rotatedAt?: string;
2111
+ rotationIntervalDays?: number;
2112
+ rotationDue?: boolean;
2113
+ }
2114
+ /**
2115
+ * A built-in provider template (domain + injection rules). Used so a caller
2116
+ * can store a credential by naming the provider and supplying only the value.
2117
+ * Carries no secret material.
2118
+ */
2119
+ interface VaultPreset {
2120
+ key: string;
2121
+ name: string;
2122
+ category: string;
2123
+ keyHint: string;
2124
+ docsUrl?: string;
2125
+ scopes: VaultScope[];
2126
+ }
2127
+ /** Parse a raw wire-format scope into a VaultScope. */
2128
+ declare function parseVaultScope(data: Record<string, unknown>): VaultScope;
2129
+ /** Parse a raw wire-format secret row into a VaultSecret. */
2130
+ declare function parseVaultSecret(data: Record<string, unknown>): VaultSecret;
2131
+ /** Parse a raw wire-format preset into a VaultPreset. */
2132
+ declare function parseVaultPreset(data: Record<string, unknown>): VaultPreset;
2133
+ /** Render a VaultScope in wire (snake_case) form for request bodies. */
2134
+ declare function vaultScopeToJSON(scope: VaultScope): Record<string, unknown>;
2135
+
2136
+ /** Shared per-call options for Vault methods. */
2137
+ interface VaultRequestOpts {
2138
+ /** API key override. */
2139
+ apiKey?: string;
2140
+ /** Domain override. */
2141
+ domain?: string;
2142
+ /** Full API URL override. */
2143
+ apiUrl?: string;
2144
+ /** Per-request timeout in milliseconds. */
2145
+ requestTimeout?: number;
2146
+ }
2147
+ /**
2148
+ * Input for creating a vault secret. The team and environment are resolved
2149
+ * automatically (a single "default" team + "prod" environment per account) —
2150
+ * those concepts are not part of the public API.
2151
+ */
2152
+ interface CreateSecretInput {
2153
+ /** The secret value (required; never returned after create). */
2154
+ value: string;
2155
+ /** Secret name. Defaults to provider when omitted. */
2156
+ name?: string;
2157
+ /** Optional preset provider key, e.g. "openai". Supplies scopes automatically. */
2158
+ provider?: string;
2159
+ /** Explicit injection scopes. Required unless provider is set. */
2160
+ scopes?: VaultScope[];
2161
+ /** Rotation policy in days. Omitted when 0 or not set. */
2162
+ rotationIntervalDays?: number;
2163
+ }
2164
+ /**
2165
+ * Vault secret management. All methods are static and derive their connection
2166
+ * from the trailing VaultRequestOpts argument (or env vars when opts is
2167
+ * omitted). The team/environment concepts are handled automatically — every
2168
+ * secret lives under a single auto-provisioned "default" team and "prod"
2169
+ * environment. Secrets are addressed by name only.
2170
+ */
2171
+ declare class Vault {
2172
+ /**
2173
+ * Store a secret's value (server-side, in OpenBao) plus its injection
2174
+ * scopes, under the auto-provisioned default team + "prod" environment.
2175
+ * Returns metadata only — the value is never echoed.
2176
+ *
2177
+ * POST /teams/{teamId}/vault/secrets
2178
+ */
2179
+ static createSecret(input: CreateSecretInput, opts?: VaultRequestOpts): Promise<VaultSecret>;
2180
+ /**
2181
+ * List secret metadata for the default team. Returns an empty array if no
2182
+ * default team has been provisioned yet.
2183
+ *
2184
+ * GET /teams/{teamId}/vault/secrets -> {secrets}
2185
+ */
2186
+ static listSecrets(opts?: VaultRequestOpts): Promise<VaultSecret[]>;
2187
+ /**
2188
+ * Replace a secret's value by name (server-side); scopes are unchanged.
2189
+ *
2190
+ * POST /teams/{teamId}/vault/secrets/{secretId}/rotate {value}
2191
+ */
2192
+ static rotateSecret(name: string, value: string, opts?: VaultRequestOpts): Promise<void>;
2193
+ /**
2194
+ * Delete a secret by name — metadata and stored value.
2195
+ *
2196
+ * DELETE /teams/{teamId}/vault/secrets/{secretId}
2197
+ */
2198
+ static deleteSecret(name: string, opts?: VaultRequestOpts): Promise<void>;
2199
+ /**
2200
+ * Replace a secret's injection scopes by name; the value is unchanged. Use
2201
+ * this to change a secret's destination(s) or injection format in place
2202
+ * instead of delete + recreate. At least one scope is required.
2203
+ *
2204
+ * POST /teams/{teamId}/vault/secrets/{secretId}/scopes
2205
+ */
2206
+ static updateScopes(name: string, scopes: VaultScope[], opts?: VaultRequestOpts): Promise<void>;
2207
+ /**
2208
+ * List built-in provider preset catalog (templates only, no secret material).
2209
+ *
2210
+ * GET /vault/presets -> {presets}
2211
+ */
2212
+ static listPresets(opts?: VaultRequestOpts): Promise<VaultPreset[]>;
2213
+ /** Maps a secret name to its id within the given team. */
2214
+ private static _resolveSecretId;
2215
+ }
2216
+
2217
+ export { ALL_TRAFFIC, ApiClient, type AuditConfig, type AuditEntry, AuthenticationError, BuildError, type BuildInfo, CODE_IDEMPOTENCY_IN_PROGRESS, CODE_IDEMPOTENCY_KEY_REUSED, CODE_TEMPLATE_NOT_READY, type CodeSecurityConfig, CommandExitError, CommandHandle, type CommandResult, type CommandWaitOpts, Commands, ConflictError, ConnectionConfig, type ConnectionConfigOptions, type ContentGateConfig, type CopyItem, type CreateSecretInput, DEFAULT_MASK_PATTERNS, type EntryInfo, type EnvSecurityConfig, type FileEntry, type FileInfo, FileType, FileUploadError, Filesystem, type FilesystemEvent, FilesystemEventType, type FullInjectionDefenseOptions, type GetBuildStatusOpts, GitAuthError, GitUpstreamError, Governance, type GovernanceAdvisory, type GovernanceControl, type GovernancePack, type GovernanceRequestOpts, InjectionAction, type InjectionDefenseConfig, type InjectionJudgeConfig, InjectionSensitivity, InvalidArgumentError, type InvisibleTextConfig, type LockLease, type LockStatus, 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, Vault, type VaultPreset, type VaultRequestOpts, type VaultScope, type VaultSecret, type VolumeAttachMode, type VolumeAttachment, type VolumeCreateOpts, VolumeFiles, type VolumeInfo, VolumeLocks, type VolumeRemoveOpts, type VolumeRequestOpts, type VolumeWriteOpts, Volumes, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, contentGateConfigToJSON, createAuditConfig, createCodeSecurityConfig, createContentGateConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, fullInjectionDefensePolicy, getSharedClient, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseContentGateConfig, parseEntryInfo, parseEnvSecurityConfig, parseFileEntry, parseFileInfo, parseFilesystemEvent, parseGovernancePack, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseLockLease, parseLockStatus, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseVaultPreset, parseVaultScope, parseVaultSecret, parseVolumeInfo, parseWriteInfo, requiresTlsInterception, resetSharedClients, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry, vaultScopeToJSON, volumeAttachmentToJSON };