@declaw/sdk 1.3.0 → 1.5.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/CHANGELOG.md +56 -0
- package/dist/index.cjs +253 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +110 -11
- package/dist/index.d.ts +110 -11
- package/dist/index.js +250 -55
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
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. */
|
|
@@ -1523,38 +1565,54 @@ declare class Sandbox {
|
|
|
1523
1565
|
*/
|
|
1524
1566
|
declare class SandboxError extends Error {
|
|
1525
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;
|
|
1526
1578
|
constructor(message: string, opts?: {
|
|
1527
1579
|
sandboxId?: string;
|
|
1580
|
+
code?: string;
|
|
1528
1581
|
});
|
|
1529
1582
|
}
|
|
1530
1583
|
/** Thrown when an operation exceeds its timeout. */
|
|
1531
1584
|
declare class TimeoutError extends SandboxError {
|
|
1532
1585
|
constructor(message: string, opts?: {
|
|
1533
1586
|
sandboxId?: string;
|
|
1587
|
+
code?: string;
|
|
1534
1588
|
});
|
|
1535
1589
|
}
|
|
1536
1590
|
/** Thrown when a sandbox or resource is not found. */
|
|
1537
1591
|
declare class NotFoundError extends SandboxError {
|
|
1538
1592
|
constructor(message: string, opts?: {
|
|
1539
1593
|
sandboxId?: string;
|
|
1594
|
+
code?: string;
|
|
1540
1595
|
});
|
|
1541
1596
|
}
|
|
1542
1597
|
/** Thrown when authentication fails. */
|
|
1543
1598
|
declare class AuthenticationError extends SandboxError {
|
|
1544
1599
|
constructor(message: string, opts?: {
|
|
1545
1600
|
sandboxId?: string;
|
|
1601
|
+
code?: string;
|
|
1546
1602
|
});
|
|
1547
1603
|
}
|
|
1548
1604
|
/** Thrown when an argument is invalid. */
|
|
1549
1605
|
declare class InvalidArgumentError extends SandboxError {
|
|
1550
1606
|
constructor(message: string, opts?: {
|
|
1551
1607
|
sandboxId?: string;
|
|
1608
|
+
code?: string;
|
|
1552
1609
|
});
|
|
1553
1610
|
}
|
|
1554
1611
|
/** Thrown when there is not enough disk space. */
|
|
1555
1612
|
declare class NotEnoughSpaceError extends SandboxError {
|
|
1556
1613
|
constructor(message: string, opts?: {
|
|
1557
1614
|
sandboxId?: string;
|
|
1615
|
+
code?: string;
|
|
1558
1616
|
});
|
|
1559
1617
|
}
|
|
1560
1618
|
/**
|
|
@@ -1569,36 +1627,48 @@ declare class NotEnoughSpaceError extends SandboxError {
|
|
|
1569
1627
|
declare class ConflictError extends SandboxError {
|
|
1570
1628
|
constructor(message: string, opts?: {
|
|
1571
1629
|
sandboxId?: string;
|
|
1630
|
+
code?: string;
|
|
1572
1631
|
});
|
|
1573
1632
|
}
|
|
1574
1633
|
/** Thrown for template-related errors. */
|
|
1575
1634
|
declare class TemplateError extends SandboxError {
|
|
1576
1635
|
constructor(message: string, opts?: {
|
|
1577
1636
|
sandboxId?: string;
|
|
1637
|
+
code?: string;
|
|
1578
1638
|
});
|
|
1579
1639
|
}
|
|
1580
1640
|
/** Thrown when a template build fails. */
|
|
1581
1641
|
declare class BuildError extends TemplateError {
|
|
1642
|
+
/** The failed build's ID, when the error comes from a build that ran (`Template.build`). */
|
|
1643
|
+
buildId?: string;
|
|
1644
|
+
/** The failed build's full output, when the error comes from a build that ran. */
|
|
1645
|
+
logs: string[];
|
|
1582
1646
|
constructor(message: string, opts?: {
|
|
1583
1647
|
sandboxId?: string;
|
|
1648
|
+
code?: string;
|
|
1649
|
+
buildId?: string;
|
|
1650
|
+
logs?: string[];
|
|
1584
1651
|
});
|
|
1585
1652
|
}
|
|
1586
1653
|
/** Thrown when a file upload fails. */
|
|
1587
1654
|
declare class FileUploadError extends SandboxError {
|
|
1588
1655
|
constructor(message: string, opts?: {
|
|
1589
1656
|
sandboxId?: string;
|
|
1657
|
+
code?: string;
|
|
1590
1658
|
});
|
|
1591
1659
|
}
|
|
1592
1660
|
/** Thrown when git authentication fails inside a sandbox. */
|
|
1593
1661
|
declare class GitAuthError extends SandboxError {
|
|
1594
1662
|
constructor(message: string, opts?: {
|
|
1595
1663
|
sandboxId?: string;
|
|
1664
|
+
code?: string;
|
|
1596
1665
|
});
|
|
1597
1666
|
}
|
|
1598
1667
|
/** Thrown when a git upstream operation fails. */
|
|
1599
1668
|
declare class GitUpstreamError extends SandboxError {
|
|
1600
1669
|
constructor(message: string, opts?: {
|
|
1601
1670
|
sandboxId?: string;
|
|
1671
|
+
code?: string;
|
|
1602
1672
|
});
|
|
1603
1673
|
}
|
|
1604
1674
|
/** Thrown when a command exits with a non-zero exit code. */
|
|
@@ -1705,7 +1775,13 @@ declare class TemplateBase {
|
|
|
1705
1775
|
fromDockerfile(content: string): this;
|
|
1706
1776
|
/** Add a run command (as array of command + args). */
|
|
1707
1777
|
runCmd(cmds: string[]): this;
|
|
1708
|
-
/**
|
|
1778
|
+
/**
|
|
1779
|
+
* Copy a local file into the template.
|
|
1780
|
+
*
|
|
1781
|
+
* Not supported yet: a template build cannot upload local files, so
|
|
1782
|
+
* building a template that uses `copy()` throws `InvalidArgumentError`.
|
|
1783
|
+
* Fetch the file in a `runCmd` step, or use `fromDockerfile`.
|
|
1784
|
+
*/
|
|
1709
1785
|
copy(src: string, dst: string, mode?: number): this;
|
|
1710
1786
|
/** Set environment variables. */
|
|
1711
1787
|
setEnvs(envs: Record<string, string>): this;
|
|
@@ -1713,22 +1789,37 @@ declare class TemplateBase {
|
|
|
1713
1789
|
aptInstall(...packages: string[]): this;
|
|
1714
1790
|
/** Set the start command. */
|
|
1715
1791
|
setStartCmd(cmd: string): this;
|
|
1792
|
+
/**
|
|
1793
|
+
* Whether `copy()` was used. Builds reject such a template until builds can
|
|
1794
|
+
* upload local files.
|
|
1795
|
+
* @internal
|
|
1796
|
+
*/
|
|
1797
|
+
hasCopies(): boolean;
|
|
1716
1798
|
/** Serialize the template to a JSON-friendly object. */
|
|
1717
1799
|
toJSON(): Record<string, any>;
|
|
1718
1800
|
}
|
|
1719
1801
|
/** Information about a template build. */
|
|
1720
1802
|
interface BuildInfo {
|
|
1721
1803
|
buildId: string;
|
|
1804
|
+
/** `building`, then `completed` or `failed`. */
|
|
1722
1805
|
status: string;
|
|
1723
1806
|
templateId?: string;
|
|
1807
|
+
/**
|
|
1808
|
+
* Build output. Empty in the response to starting a build; filled when
|
|
1809
|
+
* `Template.build()` returns a finished build.
|
|
1810
|
+
*/
|
|
1811
|
+
logs: string[];
|
|
1724
1812
|
}
|
|
1725
1813
|
/** Parse raw JSON data into BuildInfo. */
|
|
1726
1814
|
declare function parseBuildInfo(data: Record<string, any>): BuildInfo;
|
|
1727
1815
|
/** Status of a template build. */
|
|
1728
1816
|
interface TemplateBuildStatus {
|
|
1729
1817
|
buildId: string;
|
|
1818
|
+
/** `building`, then `completed` or `failed`. */
|
|
1730
1819
|
status: string;
|
|
1820
|
+
/** Build output so far. */
|
|
1731
1821
|
logs: string[];
|
|
1822
|
+
templateId?: string;
|
|
1732
1823
|
}
|
|
1733
1824
|
/** Parse raw JSON data into TemplateBuildStatus. */
|
|
1734
1825
|
declare function parseTemplateBuildStatus(data: Record<string, any>): TemplateBuildStatus;
|
|
@@ -1741,8 +1832,10 @@ interface TemplateBuildOpts {
|
|
|
1741
1832
|
memoryMb?: number;
|
|
1742
1833
|
/** Disk size in MB for the build (128–102400). */
|
|
1743
1834
|
diskMb?: number;
|
|
1744
|
-
/**
|
|
1835
|
+
/** Called with each new line of build output while `build()` waits. */
|
|
1745
1836
|
onBuildLogs?: (log: string) => void;
|
|
1837
|
+
/** How long `build()` waits for the build to finish, in milliseconds. Defaults to one hour. */
|
|
1838
|
+
buildTimeout?: number;
|
|
1746
1839
|
/** API key override. */
|
|
1747
1840
|
apiKey?: string;
|
|
1748
1841
|
/** Domain override. */
|
|
@@ -1767,20 +1860,26 @@ interface GetBuildStatusOpts {
|
|
|
1767
1860
|
*/
|
|
1768
1861
|
declare class Template {
|
|
1769
1862
|
/**
|
|
1770
|
-
* Build a template and wait for
|
|
1863
|
+
* Build a template and wait for the build to finish.
|
|
1864
|
+
*
|
|
1865
|
+
* Builds usually take several minutes. While waiting, each new line of build
|
|
1866
|
+
* output is passed to `onBuildLogs`. Sandboxes are created from the finished
|
|
1867
|
+
* template by its alias: `Sandbox.create({ template: alias })`.
|
|
1771
1868
|
*
|
|
1772
|
-
*
|
|
1773
|
-
*
|
|
1869
|
+
* @throws {BuildError} The build failed; the error carries its logs.
|
|
1870
|
+
* @throws {TimeoutError} The build was still running after `buildTimeout`.
|
|
1871
|
+
* It keeps running; follow it with `getBuildStatus()`.
|
|
1872
|
+
* @throws {InvalidArgumentError} The template uses `copy()`, which is not
|
|
1873
|
+
* supported yet.
|
|
1774
1874
|
*/
|
|
1775
1875
|
static build(template: TemplateBase, alias: string, opts?: TemplateBuildOpts): Promise<BuildInfo>;
|
|
1776
1876
|
/**
|
|
1777
|
-
* Start a template build
|
|
1778
|
-
*
|
|
1779
|
-
* Sends POST /templates/build with `background: true`.
|
|
1877
|
+
* Start a template build and return as soon as the server has accepted it,
|
|
1878
|
+
* with status `building`. Follow the build with `getBuildStatus()`.
|
|
1780
1879
|
*/
|
|
1781
|
-
static buildInBackground(template: TemplateBase, alias: string, opts?: Omit<TemplateBuildOpts, 'onBuildLogs'>): Promise<BuildInfo>;
|
|
1880
|
+
static buildInBackground(template: TemplateBase, alias: string, opts?: Omit<TemplateBuildOpts, 'onBuildLogs' | 'buildTimeout'>): Promise<BuildInfo>;
|
|
1782
1881
|
/**
|
|
1783
|
-
* Get the status of a template build.
|
|
1882
|
+
* Get the status of a template build, including its logs so far.
|
|
1784
1883
|
*
|
|
1785
1884
|
* Sends GET /templates/builds/:buildId.
|
|
1786
1885
|
*/
|
|
@@ -2150,4 +2249,4 @@ declare class Vault {
|
|
|
2150
2249
|
private static _resolveSecretId;
|
|
2151
2250
|
}
|
|
2152
2251
|
|
|
2153
|
-
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, 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 };
|
|
2252
|
+
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 };
|
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. */
|
|
@@ -1523,38 +1565,54 @@ declare class Sandbox {
|
|
|
1523
1565
|
*/
|
|
1524
1566
|
declare class SandboxError extends Error {
|
|
1525
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;
|
|
1526
1578
|
constructor(message: string, opts?: {
|
|
1527
1579
|
sandboxId?: string;
|
|
1580
|
+
code?: string;
|
|
1528
1581
|
});
|
|
1529
1582
|
}
|
|
1530
1583
|
/** Thrown when an operation exceeds its timeout. */
|
|
1531
1584
|
declare class TimeoutError extends SandboxError {
|
|
1532
1585
|
constructor(message: string, opts?: {
|
|
1533
1586
|
sandboxId?: string;
|
|
1587
|
+
code?: string;
|
|
1534
1588
|
});
|
|
1535
1589
|
}
|
|
1536
1590
|
/** Thrown when a sandbox or resource is not found. */
|
|
1537
1591
|
declare class NotFoundError extends SandboxError {
|
|
1538
1592
|
constructor(message: string, opts?: {
|
|
1539
1593
|
sandboxId?: string;
|
|
1594
|
+
code?: string;
|
|
1540
1595
|
});
|
|
1541
1596
|
}
|
|
1542
1597
|
/** Thrown when authentication fails. */
|
|
1543
1598
|
declare class AuthenticationError extends SandboxError {
|
|
1544
1599
|
constructor(message: string, opts?: {
|
|
1545
1600
|
sandboxId?: string;
|
|
1601
|
+
code?: string;
|
|
1546
1602
|
});
|
|
1547
1603
|
}
|
|
1548
1604
|
/** Thrown when an argument is invalid. */
|
|
1549
1605
|
declare class InvalidArgumentError extends SandboxError {
|
|
1550
1606
|
constructor(message: string, opts?: {
|
|
1551
1607
|
sandboxId?: string;
|
|
1608
|
+
code?: string;
|
|
1552
1609
|
});
|
|
1553
1610
|
}
|
|
1554
1611
|
/** Thrown when there is not enough disk space. */
|
|
1555
1612
|
declare class NotEnoughSpaceError extends SandboxError {
|
|
1556
1613
|
constructor(message: string, opts?: {
|
|
1557
1614
|
sandboxId?: string;
|
|
1615
|
+
code?: string;
|
|
1558
1616
|
});
|
|
1559
1617
|
}
|
|
1560
1618
|
/**
|
|
@@ -1569,36 +1627,48 @@ declare class NotEnoughSpaceError extends SandboxError {
|
|
|
1569
1627
|
declare class ConflictError extends SandboxError {
|
|
1570
1628
|
constructor(message: string, opts?: {
|
|
1571
1629
|
sandboxId?: string;
|
|
1630
|
+
code?: string;
|
|
1572
1631
|
});
|
|
1573
1632
|
}
|
|
1574
1633
|
/** Thrown for template-related errors. */
|
|
1575
1634
|
declare class TemplateError extends SandboxError {
|
|
1576
1635
|
constructor(message: string, opts?: {
|
|
1577
1636
|
sandboxId?: string;
|
|
1637
|
+
code?: string;
|
|
1578
1638
|
});
|
|
1579
1639
|
}
|
|
1580
1640
|
/** Thrown when a template build fails. */
|
|
1581
1641
|
declare class BuildError extends TemplateError {
|
|
1642
|
+
/** The failed build's ID, when the error comes from a build that ran (`Template.build`). */
|
|
1643
|
+
buildId?: string;
|
|
1644
|
+
/** The failed build's full output, when the error comes from a build that ran. */
|
|
1645
|
+
logs: string[];
|
|
1582
1646
|
constructor(message: string, opts?: {
|
|
1583
1647
|
sandboxId?: string;
|
|
1648
|
+
code?: string;
|
|
1649
|
+
buildId?: string;
|
|
1650
|
+
logs?: string[];
|
|
1584
1651
|
});
|
|
1585
1652
|
}
|
|
1586
1653
|
/** Thrown when a file upload fails. */
|
|
1587
1654
|
declare class FileUploadError extends SandboxError {
|
|
1588
1655
|
constructor(message: string, opts?: {
|
|
1589
1656
|
sandboxId?: string;
|
|
1657
|
+
code?: string;
|
|
1590
1658
|
});
|
|
1591
1659
|
}
|
|
1592
1660
|
/** Thrown when git authentication fails inside a sandbox. */
|
|
1593
1661
|
declare class GitAuthError extends SandboxError {
|
|
1594
1662
|
constructor(message: string, opts?: {
|
|
1595
1663
|
sandboxId?: string;
|
|
1664
|
+
code?: string;
|
|
1596
1665
|
});
|
|
1597
1666
|
}
|
|
1598
1667
|
/** Thrown when a git upstream operation fails. */
|
|
1599
1668
|
declare class GitUpstreamError extends SandboxError {
|
|
1600
1669
|
constructor(message: string, opts?: {
|
|
1601
1670
|
sandboxId?: string;
|
|
1671
|
+
code?: string;
|
|
1602
1672
|
});
|
|
1603
1673
|
}
|
|
1604
1674
|
/** Thrown when a command exits with a non-zero exit code. */
|
|
@@ -1705,7 +1775,13 @@ declare class TemplateBase {
|
|
|
1705
1775
|
fromDockerfile(content: string): this;
|
|
1706
1776
|
/** Add a run command (as array of command + args). */
|
|
1707
1777
|
runCmd(cmds: string[]): this;
|
|
1708
|
-
/**
|
|
1778
|
+
/**
|
|
1779
|
+
* Copy a local file into the template.
|
|
1780
|
+
*
|
|
1781
|
+
* Not supported yet: a template build cannot upload local files, so
|
|
1782
|
+
* building a template that uses `copy()` throws `InvalidArgumentError`.
|
|
1783
|
+
* Fetch the file in a `runCmd` step, or use `fromDockerfile`.
|
|
1784
|
+
*/
|
|
1709
1785
|
copy(src: string, dst: string, mode?: number): this;
|
|
1710
1786
|
/** Set environment variables. */
|
|
1711
1787
|
setEnvs(envs: Record<string, string>): this;
|
|
@@ -1713,22 +1789,37 @@ declare class TemplateBase {
|
|
|
1713
1789
|
aptInstall(...packages: string[]): this;
|
|
1714
1790
|
/** Set the start command. */
|
|
1715
1791
|
setStartCmd(cmd: string): this;
|
|
1792
|
+
/**
|
|
1793
|
+
* Whether `copy()` was used. Builds reject such a template until builds can
|
|
1794
|
+
* upload local files.
|
|
1795
|
+
* @internal
|
|
1796
|
+
*/
|
|
1797
|
+
hasCopies(): boolean;
|
|
1716
1798
|
/** Serialize the template to a JSON-friendly object. */
|
|
1717
1799
|
toJSON(): Record<string, any>;
|
|
1718
1800
|
}
|
|
1719
1801
|
/** Information about a template build. */
|
|
1720
1802
|
interface BuildInfo {
|
|
1721
1803
|
buildId: string;
|
|
1804
|
+
/** `building`, then `completed` or `failed`. */
|
|
1722
1805
|
status: string;
|
|
1723
1806
|
templateId?: string;
|
|
1807
|
+
/**
|
|
1808
|
+
* Build output. Empty in the response to starting a build; filled when
|
|
1809
|
+
* `Template.build()` returns a finished build.
|
|
1810
|
+
*/
|
|
1811
|
+
logs: string[];
|
|
1724
1812
|
}
|
|
1725
1813
|
/** Parse raw JSON data into BuildInfo. */
|
|
1726
1814
|
declare function parseBuildInfo(data: Record<string, any>): BuildInfo;
|
|
1727
1815
|
/** Status of a template build. */
|
|
1728
1816
|
interface TemplateBuildStatus {
|
|
1729
1817
|
buildId: string;
|
|
1818
|
+
/** `building`, then `completed` or `failed`. */
|
|
1730
1819
|
status: string;
|
|
1820
|
+
/** Build output so far. */
|
|
1731
1821
|
logs: string[];
|
|
1822
|
+
templateId?: string;
|
|
1732
1823
|
}
|
|
1733
1824
|
/** Parse raw JSON data into TemplateBuildStatus. */
|
|
1734
1825
|
declare function parseTemplateBuildStatus(data: Record<string, any>): TemplateBuildStatus;
|
|
@@ -1741,8 +1832,10 @@ interface TemplateBuildOpts {
|
|
|
1741
1832
|
memoryMb?: number;
|
|
1742
1833
|
/** Disk size in MB for the build (128–102400). */
|
|
1743
1834
|
diskMb?: number;
|
|
1744
|
-
/**
|
|
1835
|
+
/** Called with each new line of build output while `build()` waits. */
|
|
1745
1836
|
onBuildLogs?: (log: string) => void;
|
|
1837
|
+
/** How long `build()` waits for the build to finish, in milliseconds. Defaults to one hour. */
|
|
1838
|
+
buildTimeout?: number;
|
|
1746
1839
|
/** API key override. */
|
|
1747
1840
|
apiKey?: string;
|
|
1748
1841
|
/** Domain override. */
|
|
@@ -1767,20 +1860,26 @@ interface GetBuildStatusOpts {
|
|
|
1767
1860
|
*/
|
|
1768
1861
|
declare class Template {
|
|
1769
1862
|
/**
|
|
1770
|
-
* Build a template and wait for
|
|
1863
|
+
* Build a template and wait for the build to finish.
|
|
1864
|
+
*
|
|
1865
|
+
* Builds usually take several minutes. While waiting, each new line of build
|
|
1866
|
+
* output is passed to `onBuildLogs`. Sandboxes are created from the finished
|
|
1867
|
+
* template by its alias: `Sandbox.create({ template: alias })`.
|
|
1771
1868
|
*
|
|
1772
|
-
*
|
|
1773
|
-
*
|
|
1869
|
+
* @throws {BuildError} The build failed; the error carries its logs.
|
|
1870
|
+
* @throws {TimeoutError} The build was still running after `buildTimeout`.
|
|
1871
|
+
* It keeps running; follow it with `getBuildStatus()`.
|
|
1872
|
+
* @throws {InvalidArgumentError} The template uses `copy()`, which is not
|
|
1873
|
+
* supported yet.
|
|
1774
1874
|
*/
|
|
1775
1875
|
static build(template: TemplateBase, alias: string, opts?: TemplateBuildOpts): Promise<BuildInfo>;
|
|
1776
1876
|
/**
|
|
1777
|
-
* Start a template build
|
|
1778
|
-
*
|
|
1779
|
-
* Sends POST /templates/build with `background: true`.
|
|
1877
|
+
* Start a template build and return as soon as the server has accepted it,
|
|
1878
|
+
* with status `building`. Follow the build with `getBuildStatus()`.
|
|
1780
1879
|
*/
|
|
1781
|
-
static buildInBackground(template: TemplateBase, alias: string, opts?: Omit<TemplateBuildOpts, 'onBuildLogs'>): Promise<BuildInfo>;
|
|
1880
|
+
static buildInBackground(template: TemplateBase, alias: string, opts?: Omit<TemplateBuildOpts, 'onBuildLogs' | 'buildTimeout'>): Promise<BuildInfo>;
|
|
1782
1881
|
/**
|
|
1783
|
-
* Get the status of a template build.
|
|
1882
|
+
* Get the status of a template build, including its logs so far.
|
|
1784
1883
|
*
|
|
1785
1884
|
* Sends GET /templates/builds/:buildId.
|
|
1786
1885
|
*/
|
|
@@ -2150,4 +2249,4 @@ declare class Vault {
|
|
|
2150
2249
|
private static _resolveSecretId;
|
|
2151
2250
|
}
|
|
2152
2251
|
|
|
2153
|
-
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, 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 };
|
|
2252
|
+
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 };
|