@cloudflare/sandbox 0.12.0 → 0.13.0-next.632.1
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/README.md +2 -3
- package/dist/bridge/index.js +2 -2
- package/dist/{dist-B_eXrP83.js → dist-mAH_7Ui7.js} +2 -122
- package/dist/dist-mAH_7Ui7.js.map +1 -0
- package/dist/index.d.ts +14 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/openai/index.d.ts +1 -1
- package/dist/openai/index.js +1 -1
- package/dist/opencode/index.d.ts +1 -1
- package/dist/opencode/index.d.ts.map +1 -1
- package/dist/opencode/index.js +1 -1
- package/dist/{sandbox-Duj2gvUC.js → sandbox-B7ewRruX.js} +985 -2761
- package/dist/sandbox-B7ewRruX.js.map +1 -0
- package/dist/{sandbox-D3N9M5EI.d.ts → sandbox-Cz8DRoAm.d.ts} +46 -826
- package/dist/sandbox-Cz8DRoAm.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/dist-B_eXrP83.js.map +0 -1
- package/dist/sandbox-D3N9M5EI.d.ts.map +0 -1
- package/dist/sandbox-Duj2gvUC.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Container, ContainerProxy } from "@cloudflare/containers";
|
|
2
|
-
import "capnweb";
|
|
2
|
+
import { RpcTarget } from "capnweb";
|
|
3
3
|
|
|
4
4
|
//#region ../shared/dist/logger/types.d.ts
|
|
5
5
|
|
|
@@ -688,7 +688,6 @@ interface SessionOptions {
|
|
|
688
688
|
*/
|
|
689
689
|
commandTimeoutMs?: number;
|
|
690
690
|
}
|
|
691
|
-
type SandboxTransport = 'http' | 'websocket' | 'rpc';
|
|
692
691
|
interface SandboxOptions {
|
|
693
692
|
/**
|
|
694
693
|
* Duration after which the sandbox instance will sleep if no requests are received
|
|
@@ -786,25 +785,6 @@ interface SandboxOptions {
|
|
|
786
785
|
*/
|
|
787
786
|
waitIntervalMS?: number;
|
|
788
787
|
};
|
|
789
|
-
/**
|
|
790
|
-
* Transport/control path for communication between the Sandbox DO and the
|
|
791
|
-
* container runtime.
|
|
792
|
-
*
|
|
793
|
-
* - `"http"` (default): Route-based HTTP compatibility path.
|
|
794
|
-
* - `"websocket"`: Route-based compatibility path multiplexed over a custom
|
|
795
|
-
* WebSocket connection.
|
|
796
|
-
* - `"rpc"`: Primary container-control path over capnweb RPC.
|
|
797
|
-
*
|
|
798
|
-
* When set via `getSandbox()` options, this overrides the `SANDBOX_TRANSPORT` env var.
|
|
799
|
-
*
|
|
800
|
-
* **Important:** Set this once at creation time and pass the same value on every
|
|
801
|
-
* subsequent `getSandbox()` call for a given sandbox ID. Changing the transport after
|
|
802
|
-
* the sandbox is in use disconnects the active client, which drops any in-flight
|
|
803
|
-
* requests and resets WebSocket connections.
|
|
804
|
-
*
|
|
805
|
-
* @default "http"
|
|
806
|
-
*/
|
|
807
|
-
transport?: SandboxTransport;
|
|
808
788
|
}
|
|
809
789
|
/**
|
|
810
790
|
* Execution session - isolated execution context within a sandbox
|
|
@@ -829,7 +809,7 @@ interface WriteFileResult {
|
|
|
829
809
|
*
|
|
830
810
|
* - `'utf-8'` / `'utf8'` — treat content as text.
|
|
831
811
|
* - `'base64'` — treat content as base64-encoded binary.
|
|
832
|
-
* - `'none'` —
|
|
812
|
+
* - `'none'` — streaming variant of `readFile`, returns a
|
|
833
813
|
* `ReadableStream<Uint8Array>` of raw bytes (see `ReadFileStreamResult`).
|
|
834
814
|
*/
|
|
835
815
|
type FileEncoding = 'utf-8' | 'utf8' | 'base64' | 'none';
|
|
@@ -857,11 +837,10 @@ interface ReadFileResult {
|
|
|
857
837
|
size?: number;
|
|
858
838
|
}
|
|
859
839
|
/**
|
|
860
|
-
* Result of `readFile()` with `encoding: 'none'
|
|
840
|
+
* Result of `readFile()` with `encoding: 'none'`.
|
|
861
841
|
*
|
|
862
842
|
* `content` is a raw binary `ReadableStream<Uint8Array>` delivered directly
|
|
863
843
|
* over the capnp channel — no base64 encoding, no SSE framing, no buffering.
|
|
864
|
-
* Only supported on the `rpc` transport; HTTP/WebSocket transports throw.
|
|
865
844
|
*/
|
|
866
845
|
interface ReadFileStreamResult {
|
|
867
846
|
success: true;
|
|
@@ -1456,79 +1435,6 @@ declare function isProcess(value: any): value is Process;
|
|
|
1456
1435
|
declare function isProcessStatus(value: string): value is ProcessStatus;
|
|
1457
1436
|
//#endregion
|
|
1458
1437
|
//#region ../shared/dist/request-types.d.ts
|
|
1459
|
-
/**
|
|
1460
|
-
* Request types for API calls to the container
|
|
1461
|
-
* Single source of truth for the contract between SDK clients and container handlers
|
|
1462
|
-
*/
|
|
1463
|
-
/**
|
|
1464
|
-
* Request to execute a command
|
|
1465
|
-
*/
|
|
1466
|
-
interface ExecuteRequest {
|
|
1467
|
-
command: string;
|
|
1468
|
-
sessionId?: string;
|
|
1469
|
-
background?: boolean;
|
|
1470
|
-
timeoutMs?: number;
|
|
1471
|
-
env?: Record<string, string | undefined>;
|
|
1472
|
-
cwd?: string;
|
|
1473
|
-
origin?: 'user' | 'internal';
|
|
1474
|
-
}
|
|
1475
|
-
/**
|
|
1476
|
-
* Request to start a background process
|
|
1477
|
-
* Uses flat structure consistent with other endpoints
|
|
1478
|
-
*/
|
|
1479
|
-
interface StartProcessRequest {
|
|
1480
|
-
command: string;
|
|
1481
|
-
sessionId?: string;
|
|
1482
|
-
processId?: string;
|
|
1483
|
-
timeoutMs?: number;
|
|
1484
|
-
env?: Record<string, string | undefined>;
|
|
1485
|
-
cwd?: string;
|
|
1486
|
-
encoding?: string;
|
|
1487
|
-
autoCleanup?: boolean;
|
|
1488
|
-
origin?: 'user' | 'internal';
|
|
1489
|
-
}
|
|
1490
|
-
/**
|
|
1491
|
-
* Request to create a backup archive from a directory.
|
|
1492
|
-
* The container creates a squashfs archive at archivePath.
|
|
1493
|
-
* The DO then reads it and uploads to R2.
|
|
1494
|
-
*/
|
|
1495
|
-
interface CreateBackupRequest {
|
|
1496
|
-
/** Directory to back up */
|
|
1497
|
-
dir: string;
|
|
1498
|
-
/** Path where the container should write the archive */
|
|
1499
|
-
archivePath: string;
|
|
1500
|
-
/** Respect git ignore rules when the directory is inside a git repository */
|
|
1501
|
-
gitignore?: boolean;
|
|
1502
|
-
/** Glob patterns to exclude from the backup */
|
|
1503
|
-
excludes?: string[];
|
|
1504
|
-
compression?: BackupCompressionOptions;
|
|
1505
|
-
sessionId?: string;
|
|
1506
|
-
}
|
|
1507
|
-
/**
|
|
1508
|
-
* A single part to upload in a multipart upload.
|
|
1509
|
-
* The container reads the byte range from the local archive and PUTs it
|
|
1510
|
-
* to the presigned URL.
|
|
1511
|
-
*/
|
|
1512
|
-
interface UploadPart {
|
|
1513
|
-
partNumber: number;
|
|
1514
|
-
/** Presigned PUT URL for this part */
|
|
1515
|
-
url: string;
|
|
1516
|
-
/** Byte offset within the archive file */
|
|
1517
|
-
offset: number;
|
|
1518
|
-
/** Number of bytes in this part */
|
|
1519
|
-
size: number;
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
* Request to upload parts of a backup archive directly from the container to R2.
|
|
1523
|
-
* Used for parallel multipart upload of large archives.
|
|
1524
|
-
*/
|
|
1525
|
-
interface UploadPartsRequest {
|
|
1526
|
-
/** Path to the archive file in the container */
|
|
1527
|
-
archivePath: string;
|
|
1528
|
-
/** Parts to upload in parallel */
|
|
1529
|
-
parts: UploadPart[];
|
|
1530
|
-
sessionId?: string;
|
|
1531
|
-
}
|
|
1532
1438
|
/**
|
|
1533
1439
|
* Result for a single uploaded part (ETag returned by R2).
|
|
1534
1440
|
*/
|
|
@@ -1756,692 +1662,23 @@ interface SandboxTunnelsAPI {
|
|
|
1756
1662
|
/** List tunnels currently running inside the container. */
|
|
1757
1663
|
listTunnels(): Promise<TunnelInfo[]>;
|
|
1758
1664
|
}
|
|
1759
|
-
//#endregion
|
|
1760
|
-
//#region src/clients/types.d.ts
|
|
1761
1665
|
/**
|
|
1762
|
-
*
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
/**
|
|
1767
|
-
* Fetch that can handle WebSocket upgrades (routes through parent Container class).
|
|
1768
|
-
* Required for WebSocket transport to establish control plane connections.
|
|
1769
|
-
*/
|
|
1770
|
-
fetch(request: Request): Promise<Response>;
|
|
1771
|
-
}
|
|
1772
|
-
/**
|
|
1773
|
-
* Shared HTTP client configuration options
|
|
1774
|
-
*/
|
|
1775
|
-
interface HttpClientOptions {
|
|
1776
|
-
logger?: Logger;
|
|
1777
|
-
baseUrl?: string;
|
|
1778
|
-
port?: number;
|
|
1779
|
-
stub?: ContainerStub;
|
|
1780
|
-
onCommandComplete?: (success: boolean, exitCode: number, stdout: string, stderr: string, command: string) => void;
|
|
1781
|
-
onError?: (error: string, command?: string) => void;
|
|
1782
|
-
/**
|
|
1783
|
-
* Route-based transport mode: 'http' (default) or 'websocket'.
|
|
1784
|
-
* WebSocket mode multiplexes HTTP API requests over a single connection.
|
|
1785
|
-
*/
|
|
1786
|
-
transportMode?: RouteTransportMode;
|
|
1787
|
-
/**
|
|
1788
|
-
* WebSocket URL for WebSocket transport mode.
|
|
1789
|
-
* Required when transportMode is 'websocket'.
|
|
1790
|
-
*/
|
|
1791
|
-
wsUrl?: string;
|
|
1792
|
-
/**
|
|
1793
|
-
* Shared transport instance (for internal use).
|
|
1794
|
-
* When provided, clients will use this transport instead of creating their own.
|
|
1795
|
-
*/
|
|
1796
|
-
transport?: ITransport;
|
|
1797
|
-
/**
|
|
1798
|
-
* Total retry budget in milliseconds for 503 retries during container startup.
|
|
1799
|
-
* Passed through to the transport layer. Defaults to 120_000 (2 minutes).
|
|
1800
|
-
*/
|
|
1801
|
-
retryTimeoutMs?: number;
|
|
1802
|
-
/**
|
|
1803
|
-
* Headers merged into every outgoing container request.
|
|
1804
|
-
* Used to propagate stable context (e.g. sandboxId) from the Durable Object
|
|
1805
|
-
* to the container so container logs carry the same identifiers as DO logs.
|
|
1806
|
-
*/
|
|
1807
|
-
defaultHeaders?: Record<string, string>;
|
|
1808
|
-
}
|
|
1809
|
-
/**
|
|
1810
|
-
* Base response interface for all API responses
|
|
1811
|
-
*/
|
|
1812
|
-
interface BaseApiResponse {
|
|
1813
|
-
success: boolean;
|
|
1814
|
-
timestamp: string;
|
|
1815
|
-
}
|
|
1816
|
-
/**
|
|
1817
|
-
* Legacy error response interface - deprecated, use ApiErrorResponse
|
|
1818
|
-
*/
|
|
1819
|
-
interface ErrorResponse {
|
|
1820
|
-
error: string;
|
|
1821
|
-
details?: string;
|
|
1822
|
-
code?: string;
|
|
1823
|
-
}
|
|
1824
|
-
/**
|
|
1825
|
-
* HTTP request configuration
|
|
1826
|
-
*/
|
|
1827
|
-
interface RequestConfig extends RequestInit {
|
|
1828
|
-
endpoint: string;
|
|
1829
|
-
data?: Record<string, any>;
|
|
1830
|
-
}
|
|
1831
|
-
/**
|
|
1832
|
-
* Typed response handler
|
|
1833
|
-
*/
|
|
1834
|
-
type ResponseHandler<T> = (response: Response) => Promise<T>;
|
|
1835
|
-
/**
|
|
1836
|
-
* Common session-aware request interface
|
|
1837
|
-
*/
|
|
1838
|
-
interface SessionRequest {
|
|
1839
|
-
sessionId?: string;
|
|
1840
|
-
}
|
|
1841
|
-
//#endregion
|
|
1842
|
-
//#region src/clients/transport/types.d.ts
|
|
1843
|
-
/**
|
|
1844
|
-
* Transport modes supported by the route-based compatibility layer.
|
|
1845
|
-
*/
|
|
1846
|
-
type RouteTransportMode = 'http' | 'websocket';
|
|
1847
|
-
interface TransportRequestInit extends RequestInit {
|
|
1848
|
-
/** Override the non-streaming request timeout for this single request. */
|
|
1849
|
-
requestTimeoutMs?: number;
|
|
1850
|
-
}
|
|
1851
|
-
/**
|
|
1852
|
-
* Route transport interface.
|
|
1666
|
+
* RPC surface the Sandbox DO exposes to the container over the existing
|
|
1667
|
+
* capnweb session. The container reaches it via
|
|
1668
|
+
* `session.getRemoteMain<SandboxControlCallback>()` and invokes methods
|
|
1669
|
+
* to push control-plane events (today: tunnel exits) back to the DO.
|
|
1853
1670
|
*
|
|
1854
|
-
*
|
|
1855
|
-
*
|
|
1856
|
-
* requests and streaming.
|
|
1671
|
+
* One stable target per sandbox; not per-tunnel. Reusable seam for
|
|
1672
|
+
* future container→DO events.
|
|
1857
1673
|
*/
|
|
1858
|
-
interface
|
|
1859
|
-
/**
|
|
1860
|
-
* Make a fetch-compatible request
|
|
1861
|
-
* @returns Standard Response object
|
|
1862
|
-
*/
|
|
1863
|
-
fetch(path: string, options?: TransportRequestInit): Promise<Response>;
|
|
1864
|
-
/**
|
|
1865
|
-
* Make a streaming request
|
|
1866
|
-
* @returns ReadableStream for consuming SSE/streaming data
|
|
1867
|
-
*/
|
|
1868
|
-
fetchStream(path: string, body?: unknown, method?: 'GET' | 'POST', headers?: Record<string, string>): Promise<ReadableStream<Uint8Array>>;
|
|
1674
|
+
interface SandboxControlCallback {
|
|
1869
1675
|
/**
|
|
1870
|
-
*
|
|
1676
|
+
* Called by the container when a `cloudflared` process exits for any
|
|
1677
|
+
* reason — SIGTERM from `destroyTunnel`, container-initiated SIGKILL,
|
|
1678
|
+
* network failure, segfault. `exitCode` is `null` if the process was
|
|
1679
|
+
* signalled rather than exited cleanly.
|
|
1871
1680
|
*/
|
|
1872
|
-
|
|
1873
|
-
/**
|
|
1874
|
-
* Connect the transport (no-op for HTTP)
|
|
1875
|
-
*/
|
|
1876
|
-
connect(): Promise<void>;
|
|
1877
|
-
/**
|
|
1878
|
-
* Disconnect the transport (no-op for HTTP)
|
|
1879
|
-
*/
|
|
1880
|
-
disconnect(): void;
|
|
1881
|
-
/**
|
|
1882
|
-
* Check if connected (always true for HTTP)
|
|
1883
|
-
*/
|
|
1884
|
-
isConnected(): boolean;
|
|
1885
|
-
/**
|
|
1886
|
-
* Update the 503 retry budget without recreating the transport
|
|
1887
|
-
*/
|
|
1888
|
-
setRetryTimeoutMs(ms: number): void;
|
|
1889
|
-
}
|
|
1890
|
-
//#endregion
|
|
1891
|
-
//#region src/clients/base-client.d.ts
|
|
1892
|
-
/**
|
|
1893
|
-
* Abstract base class for route-based HTTP/WebSocket compatibility clients.
|
|
1894
|
-
*
|
|
1895
|
-
* Requests go through the Transport abstraction layer, which handles:
|
|
1896
|
-
* - HTTP and WebSocket route-based modes transparently
|
|
1897
|
-
* - Automatic retry for 503 errors while the container is starting
|
|
1898
|
-
* - Streaming responses for the existing route API
|
|
1899
|
-
*
|
|
1900
|
-
* DO-to-container control-channel capabilities live in `container-control/`.
|
|
1901
|
-
* This layer supports the route-based compatibility API.
|
|
1902
|
-
*/
|
|
1903
|
-
declare abstract class BaseHttpClient {
|
|
1904
|
-
protected options: HttpClientOptions;
|
|
1905
|
-
protected logger: Logger;
|
|
1906
|
-
protected transport: ITransport;
|
|
1907
|
-
constructor(options?: HttpClientOptions);
|
|
1908
|
-
/**
|
|
1909
|
-
* Update the transport's 503 retry budget
|
|
1910
|
-
*/
|
|
1911
|
-
setRetryTimeoutMs(ms: number): void;
|
|
1912
|
-
/**
|
|
1913
|
-
* Check if using WebSocket transport
|
|
1914
|
-
*/
|
|
1915
|
-
protected isWebSocketMode(): boolean;
|
|
1916
|
-
/**
|
|
1917
|
-
* Core fetch method - delegates to Transport which handles retry logic
|
|
1918
|
-
*/
|
|
1919
|
-
protected doFetch(path: string, options?: TransportRequestInit): Promise<Response>;
|
|
1920
|
-
/**
|
|
1921
|
-
* Make a POST request with JSON body
|
|
1922
|
-
*/
|
|
1923
|
-
protected post<T>(endpoint: string, data: unknown, responseHandler?: ResponseHandler<T>, requestOptions?: Pick<TransportRequestInit, 'requestTimeoutMs'>): Promise<T>;
|
|
1924
|
-
/**
|
|
1925
|
-
* Make a GET request
|
|
1926
|
-
*/
|
|
1927
|
-
protected get<T>(endpoint: string, responseHandler?: ResponseHandler<T>): Promise<T>;
|
|
1928
|
-
/**
|
|
1929
|
-
* Make a DELETE request
|
|
1930
|
-
*/
|
|
1931
|
-
protected delete<T>(endpoint: string, responseHandler?: ResponseHandler<T>): Promise<T>;
|
|
1932
|
-
/**
|
|
1933
|
-
* Handle HTTP response with error checking and parsing
|
|
1934
|
-
*/
|
|
1935
|
-
protected handleResponse<T>(response: Response, customHandler?: ResponseHandler<T>): Promise<T>;
|
|
1936
|
-
/**
|
|
1937
|
-
* Handle error responses with consistent error throwing
|
|
1938
|
-
*/
|
|
1939
|
-
protected handleErrorResponse(response: Response): Promise<never>;
|
|
1940
|
-
/**
|
|
1941
|
-
* Create a streaming response handler for Server-Sent Events
|
|
1942
|
-
*/
|
|
1943
|
-
protected handleStreamResponse(response: Response): Promise<ReadableStream<Uint8Array>>;
|
|
1944
|
-
/**
|
|
1945
|
-
* Stream request handler
|
|
1946
|
-
*
|
|
1947
|
-
* HTTP mode uses doFetch + handleStreamResponse for typed error handling.
|
|
1948
|
-
* For WebSocket mode, uses Transport's streaming support.
|
|
1949
|
-
*
|
|
1950
|
-
* @param path - The API path to call
|
|
1951
|
-
* @param body - Optional request body (for POST requests)
|
|
1952
|
-
* @param method - HTTP method (default: POST, use GET for process logs)
|
|
1953
|
-
*/
|
|
1954
|
-
protected doStreamFetch(path: string, body?: unknown, method?: 'GET' | 'POST'): Promise<ReadableStream<Uint8Array>>;
|
|
1955
|
-
}
|
|
1956
|
-
//#endregion
|
|
1957
|
-
//#region src/clients/backup-client.d.ts
|
|
1958
|
-
/**
|
|
1959
|
-
* Client for backup operations.
|
|
1960
|
-
*
|
|
1961
|
-
* Handles communication with the container's backup endpoints.
|
|
1962
|
-
* The container creates/extracts squashfs archives locally.
|
|
1963
|
-
* R2 upload/download is handled by the Sandbox DO, not by this client.
|
|
1964
|
-
*/
|
|
1965
|
-
declare class BackupClient extends BaseHttpClient implements SandboxBackupAPI {
|
|
1966
|
-
/**
|
|
1967
|
-
* Tell the container to create a squashfs archive from a directory.
|
|
1968
|
-
* @param dir - Directory to back up
|
|
1969
|
-
* @param archivePath - Where the container should write the archive
|
|
1970
|
-
* @param sessionId - Session context
|
|
1971
|
-
*/
|
|
1972
|
-
createArchive(dir: string, archivePath: string, sessionId: string, options?: {
|
|
1973
|
-
excludes?: string[];
|
|
1974
|
-
gitignore?: boolean;
|
|
1975
|
-
compression?: CreateBackupRequest['compression'];
|
|
1976
|
-
}): Promise<CreateBackupResponse>;
|
|
1977
|
-
/**
|
|
1978
|
-
* Tell the container to restore a squashfs archive into a directory.
|
|
1979
|
-
* @param dir - Target directory
|
|
1980
|
-
* @param archivePath - Path to the archive file in the container
|
|
1981
|
-
* @param sessionId - Session context
|
|
1982
|
-
*/
|
|
1983
|
-
restoreArchive(dir: string, archivePath: string, sessionId: string): Promise<RestoreBackupResponse>;
|
|
1984
|
-
uploadParts(request: UploadPartsRequest, sessionId?: string): Promise<UploadPartsResponse>;
|
|
1985
|
-
}
|
|
1986
|
-
//#endregion
|
|
1987
|
-
//#region src/clients/command-client.d.ts
|
|
1988
|
-
/**
|
|
1989
|
-
* Response interface for command execution
|
|
1990
|
-
*/
|
|
1991
|
-
interface ExecuteResponse extends BaseApiResponse {
|
|
1992
|
-
stdout: string;
|
|
1993
|
-
stderr: string;
|
|
1994
|
-
exitCode: number;
|
|
1995
|
-
command: string;
|
|
1996
|
-
}
|
|
1997
|
-
/**
|
|
1998
|
-
* Client for command execution operations
|
|
1999
|
-
*/
|
|
2000
|
-
declare class CommandClient extends BaseHttpClient implements SandboxCommandsAPI {
|
|
2001
|
-
/**
|
|
2002
|
-
* Execute a command and return the complete result
|
|
2003
|
-
* @param command - The command to execute
|
|
2004
|
-
* @param sessionId - The session ID for this command execution
|
|
2005
|
-
* @param timeoutMs - Optional timeout in milliseconds (unlimited by default)
|
|
2006
|
-
* @param env - Optional environment variables for this command
|
|
2007
|
-
* @param cwd - Optional working directory for this command
|
|
2008
|
-
*/
|
|
2009
|
-
execute(command: string, sessionId: string, options?: {
|
|
2010
|
-
timeoutMs?: number;
|
|
2011
|
-
env?: Record<string, string | undefined>;
|
|
2012
|
-
cwd?: string;
|
|
2013
|
-
origin?: 'user' | 'internal';
|
|
2014
|
-
}): Promise<ExecuteResponse>;
|
|
2015
|
-
/**
|
|
2016
|
-
* Execute a command and return a stream of events
|
|
2017
|
-
* @param command - The command to execute
|
|
2018
|
-
* @param sessionId - The session ID for this command execution
|
|
2019
|
-
* @param options - Optional per-command execution settings
|
|
2020
|
-
*/
|
|
2021
|
-
executeStream(command: string, sessionId: string, options?: {
|
|
2022
|
-
timeoutMs?: number;
|
|
2023
|
-
env?: Record<string, string | undefined>;
|
|
2024
|
-
cwd?: string;
|
|
2025
|
-
origin?: 'user' | 'internal';
|
|
2026
|
-
}): Promise<ReadableStream<Uint8Array>>;
|
|
2027
|
-
}
|
|
2028
|
-
//#endregion
|
|
2029
|
-
//#region src/clients/file-client.d.ts
|
|
2030
|
-
/**
|
|
2031
|
-
* Request interface for creating directories
|
|
2032
|
-
*/
|
|
2033
|
-
interface MkdirRequest extends SessionRequest {
|
|
2034
|
-
path: string;
|
|
2035
|
-
recursive?: boolean;
|
|
2036
|
-
}
|
|
2037
|
-
/**
|
|
2038
|
-
* Request interface for writing files
|
|
2039
|
-
*/
|
|
2040
|
-
interface WriteFileRequest extends SessionRequest {
|
|
2041
|
-
path: string;
|
|
2042
|
-
content: string;
|
|
2043
|
-
encoding?: string;
|
|
2044
|
-
}
|
|
2045
|
-
/**
|
|
2046
|
-
* Request interface for reading files
|
|
2047
|
-
*/
|
|
2048
|
-
interface ReadFileRequest extends SessionRequest {
|
|
2049
|
-
path: string;
|
|
2050
|
-
encoding?: string;
|
|
2051
|
-
}
|
|
2052
|
-
/**
|
|
2053
|
-
* Request interface for file operations (delete, rename, move)
|
|
2054
|
-
*/
|
|
2055
|
-
interface FileOperationRequest extends SessionRequest {
|
|
2056
|
-
path: string;
|
|
2057
|
-
newPath?: string;
|
|
2058
|
-
}
|
|
2059
|
-
/**
|
|
2060
|
-
* Client for file system operations
|
|
2061
|
-
*/
|
|
2062
|
-
declare class FileClient extends BaseHttpClient implements SandboxFilesAPI {
|
|
2063
|
-
/**
|
|
2064
|
-
* Create a directory
|
|
2065
|
-
* @param path - Directory path to create
|
|
2066
|
-
* @param sessionId - The session ID for this operation
|
|
2067
|
-
* @param options - Optional settings (recursive)
|
|
2068
|
-
*/
|
|
2069
|
-
mkdir(path: string, sessionId: string, options?: {
|
|
2070
|
-
recursive?: boolean;
|
|
2071
|
-
}): Promise<MkdirResult>;
|
|
2072
|
-
/**
|
|
2073
|
-
* Write content to a file
|
|
2074
|
-
* @param path - File path to write to
|
|
2075
|
-
* @param content - Content to write
|
|
2076
|
-
* @param sessionId - The session ID for this operation
|
|
2077
|
-
* @param options - Optional settings (encoding)
|
|
2078
|
-
*/
|
|
2079
|
-
writeFile(path: string, content: string, sessionId: string, options?: {
|
|
2080
|
-
encoding?: string;
|
|
2081
|
-
}): Promise<WriteFileResult>;
|
|
2082
|
-
/**
|
|
2083
|
-
* Read content from a file.
|
|
2084
|
-
*
|
|
2085
|
-
* @param path - File path to read from
|
|
2086
|
-
* @param sessionId - The session ID for this operation
|
|
2087
|
-
* @param options - Optional settings (encoding)
|
|
2088
|
-
*
|
|
2089
|
-
* When `encoding` is `'none'`, returns a `ReadFileStreamResult` whose
|
|
2090
|
-
* `content` is a raw `ReadableStream<Uint8Array>`. This variant only works
|
|
2091
|
-
* on the `rpc` transport; HTTP and WebSocket transports throw at runtime.
|
|
2092
|
-
*/
|
|
2093
|
-
readFile(path: string, sessionId: string, options: {
|
|
2094
|
-
encoding: 'none';
|
|
2095
|
-
}): Promise<ReadFileStreamResult>;
|
|
2096
|
-
readFile(path: string, sessionId: string, options?: {
|
|
2097
|
-
encoding?: Exclude<FileEncoding, 'none'>;
|
|
2098
|
-
}): Promise<ReadFileResult>;
|
|
2099
|
-
/**
|
|
2100
|
-
* Stream a file using Server-Sent Events
|
|
2101
|
-
* Returns a ReadableStream of SSE events containing metadata, chunks, and completion
|
|
2102
|
-
* @param path - File path to stream
|
|
2103
|
-
* @param sessionId - The session ID for this operation
|
|
2104
|
-
*/
|
|
2105
|
-
readFileStream(path: string, sessionId: string): Promise<ReadableStream<Uint8Array>>;
|
|
2106
|
-
/**
|
|
2107
|
-
* Delete a file
|
|
2108
|
-
* @param path - File path to delete
|
|
2109
|
-
* @param sessionId - The session ID for this operation
|
|
2110
|
-
*/
|
|
2111
|
-
deleteFile(path: string, sessionId: string): Promise<DeleteFileResult>;
|
|
2112
|
-
/**
|
|
2113
|
-
* Rename a file
|
|
2114
|
-
* @param path - Current file path
|
|
2115
|
-
* @param newPath - New file path
|
|
2116
|
-
* @param sessionId - The session ID for this operation
|
|
2117
|
-
*/
|
|
2118
|
-
renameFile(path: string, newPath: string, sessionId: string): Promise<RenameFileResult>;
|
|
2119
|
-
/**
|
|
2120
|
-
* Move a file
|
|
2121
|
-
* @param path - Current file path
|
|
2122
|
-
* @param newPath - Destination file path
|
|
2123
|
-
* @param sessionId - The session ID for this operation
|
|
2124
|
-
*/
|
|
2125
|
-
moveFile(path: string, newPath: string, sessionId: string): Promise<MoveFileResult>;
|
|
2126
|
-
/**
|
|
2127
|
-
* List files in a directory
|
|
2128
|
-
* @param path - Directory path to list
|
|
2129
|
-
* @param sessionId - The session ID for this operation
|
|
2130
|
-
* @param options - Optional settings (recursive, includeHidden)
|
|
2131
|
-
*/
|
|
2132
|
-
listFiles(path: string, sessionId: string, options?: ListFilesOptions): Promise<ListFilesResult>;
|
|
2133
|
-
/**
|
|
2134
|
-
* Check if a file or directory exists
|
|
2135
|
-
* @param path - Path to check
|
|
2136
|
-
* @param sessionId - The session ID for this operation
|
|
2137
|
-
*/
|
|
2138
|
-
exists(path: string, sessionId: string): Promise<FileExistsResult>;
|
|
2139
|
-
/**
|
|
2140
|
-
* Write a file via a raw binary stream over the RPC transport.
|
|
2141
|
-
* Throws on HTTP and WebSocket transports — use writeFile() with a string instead.
|
|
2142
|
-
*/
|
|
2143
|
-
writeFileStream(_path: string, _content: ReadableStream<Uint8Array>, _sessionId: string): Promise<{
|
|
2144
|
-
success: boolean;
|
|
2145
|
-
path: string;
|
|
2146
|
-
bytesWritten: number;
|
|
2147
|
-
timestamp: string;
|
|
2148
|
-
}>;
|
|
2149
|
-
}
|
|
2150
|
-
//#endregion
|
|
2151
|
-
//#region src/clients/git-client.d.ts
|
|
2152
|
-
/**
|
|
2153
|
-
* Request interface for Git checkout operations
|
|
2154
|
-
*/
|
|
2155
|
-
interface GitCheckoutRequest extends SessionRequest {
|
|
2156
|
-
repoUrl: string;
|
|
2157
|
-
branch?: string;
|
|
2158
|
-
targetDir?: string;
|
|
2159
|
-
/** Clone depth for shallow clones (e.g., 1 for latest commit only) */
|
|
2160
|
-
depth?: number;
|
|
2161
|
-
/** Maximum wall-clock time for the git clone subprocess in milliseconds */
|
|
2162
|
-
timeoutMs?: number;
|
|
2163
|
-
}
|
|
2164
|
-
/**
|
|
2165
|
-
* Client for Git repository operations
|
|
2166
|
-
*/
|
|
2167
|
-
declare class GitClient extends BaseHttpClient implements SandboxGitAPI {
|
|
2168
|
-
private static readonly REQUEST_TIMEOUT_BUFFER_MS;
|
|
2169
|
-
constructor(options?: HttpClientOptions);
|
|
2170
|
-
/**
|
|
2171
|
-
* Clone a Git repository
|
|
2172
|
-
* @param repoUrl - URL of the Git repository to clone
|
|
2173
|
-
* @param sessionId - The session ID for this operation
|
|
2174
|
-
* @param options - Optional settings (branch, targetDir, depth, timeoutMs)
|
|
2175
|
-
*/
|
|
2176
|
-
checkout(repoUrl: string, sessionId: string, options?: {
|
|
2177
|
-
branch?: string;
|
|
2178
|
-
targetDir?: string;
|
|
2179
|
-
/** Clone depth for shallow clones (e.g., 1 for latest commit only) */
|
|
2180
|
-
depth?: number;
|
|
2181
|
-
/** Maximum wall-clock time for the git clone subprocess in milliseconds */
|
|
2182
|
-
timeoutMs?: number;
|
|
2183
|
-
}): Promise<GitCheckoutResult>;
|
|
2184
|
-
}
|
|
2185
|
-
//#endregion
|
|
2186
|
-
//#region src/clients/interpreter-client.d.ts
|
|
2187
|
-
interface ExecutionCallbacks {
|
|
2188
|
-
onStdout?: (output: OutputMessage) => void | Promise<void>;
|
|
2189
|
-
onStderr?: (output: OutputMessage) => void | Promise<void>;
|
|
2190
|
-
onResult?: (result: Result) => void | Promise<void>;
|
|
2191
|
-
onError?: (error: ExecutionError) => void | Promise<void>;
|
|
2192
|
-
}
|
|
2193
|
-
declare class InterpreterClient extends BaseHttpClient implements SandboxInterpreterAPI {
|
|
2194
|
-
private readonly maxRetries;
|
|
2195
|
-
private readonly retryDelayMs;
|
|
2196
|
-
createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
|
|
2197
|
-
runCodeStream(contextId: string | undefined, code: string, language: string | undefined, callbacks: ExecutionCallbacks, timeoutMs?: number): Promise<void>;
|
|
2198
|
-
listCodeContexts(): Promise<CodeContext[]>;
|
|
2199
|
-
deleteCodeContext(contextId: string): Promise<void>;
|
|
2200
|
-
/**
|
|
2201
|
-
* Get a raw stream for code execution.
|
|
2202
|
-
* Used by CodeInterpreter.runCodeStreaming() for direct stream access.
|
|
2203
|
-
*/
|
|
2204
|
-
streamCode(contextId: string, code: string, language?: string): Promise<ReadableStream<Uint8Array>>;
|
|
2205
|
-
/**
|
|
2206
|
-
* Execute an operation with automatic retry for transient errors
|
|
2207
|
-
*/
|
|
2208
|
-
private executeWithRetry;
|
|
2209
|
-
private isRetryableError;
|
|
2210
|
-
private parseErrorResponse;
|
|
2211
|
-
private readLines;
|
|
2212
|
-
private parseExecutionResult;
|
|
2213
|
-
}
|
|
2214
|
-
//#endregion
|
|
2215
|
-
//#region src/clients/port-client.d.ts
|
|
2216
|
-
/**
|
|
2217
|
-
* Client for port readiness operations.
|
|
2218
|
-
*/
|
|
2219
|
-
declare class PortClient extends BaseHttpClient {
|
|
2220
|
-
/**
|
|
2221
|
-
* Watch a port for readiness via SSE stream
|
|
2222
|
-
* @param request - Port watch configuration
|
|
2223
|
-
* @returns SSE stream that emits PortWatchEvent objects
|
|
2224
|
-
*/
|
|
2225
|
-
watchPort(request: PortWatchRequest): Promise<ReadableStream<Uint8Array>>;
|
|
2226
|
-
}
|
|
2227
|
-
//#endregion
|
|
2228
|
-
//#region src/clients/process-client.d.ts
|
|
2229
|
-
/**
|
|
2230
|
-
* Client for background process management
|
|
2231
|
-
*/
|
|
2232
|
-
declare class ProcessClient extends BaseHttpClient implements SandboxProcessesAPI {
|
|
2233
|
-
/**
|
|
2234
|
-
* Start a background process
|
|
2235
|
-
* @param command - Command to execute as a background process
|
|
2236
|
-
* @param sessionId - The session ID for this operation
|
|
2237
|
-
* @param options - Optional settings (processId)
|
|
2238
|
-
*/
|
|
2239
|
-
startProcess(command: string, sessionId: string, options?: {
|
|
2240
|
-
processId?: string;
|
|
2241
|
-
timeoutMs?: number;
|
|
2242
|
-
env?: Record<string, string | undefined>;
|
|
2243
|
-
cwd?: string;
|
|
2244
|
-
encoding?: string;
|
|
2245
|
-
autoCleanup?: boolean;
|
|
2246
|
-
origin?: 'user' | 'internal';
|
|
2247
|
-
}): Promise<ProcessStartResult>;
|
|
2248
|
-
/**
|
|
2249
|
-
* List all processes (sandbox-scoped, not session-scoped)
|
|
2250
|
-
*/
|
|
2251
|
-
listProcesses(): Promise<ProcessListResult>;
|
|
2252
|
-
/**
|
|
2253
|
-
* Get information about a specific process (sandbox-scoped, not session-scoped)
|
|
2254
|
-
* @param processId - ID of the process to retrieve
|
|
2255
|
-
*/
|
|
2256
|
-
getProcess(processId: string): Promise<ProcessInfoResult>;
|
|
2257
|
-
/**
|
|
2258
|
-
* Kill a specific process (sandbox-scoped, not session-scoped)
|
|
2259
|
-
* @param processId - ID of the process to kill
|
|
2260
|
-
*/
|
|
2261
|
-
killProcess(processId: string): Promise<ProcessKillResult>;
|
|
2262
|
-
/**
|
|
2263
|
-
* Kill all running processes (sandbox-scoped, not session-scoped)
|
|
2264
|
-
*/
|
|
2265
|
-
killAllProcesses(): Promise<ProcessCleanupResult>;
|
|
2266
|
-
/**
|
|
2267
|
-
* Get logs from a specific process (sandbox-scoped, not session-scoped)
|
|
2268
|
-
* @param processId - ID of the process to get logs from
|
|
2269
|
-
*/
|
|
2270
|
-
getProcessLogs(processId: string): Promise<ProcessLogsResult>;
|
|
2271
|
-
/**
|
|
2272
|
-
* Stream logs from a specific process (sandbox-scoped, not session-scoped)
|
|
2273
|
-
* @param processId - ID of the process to stream logs from
|
|
2274
|
-
*/
|
|
2275
|
-
streamProcessLogs(processId: string): Promise<ReadableStream<Uint8Array>>;
|
|
2276
|
-
}
|
|
2277
|
-
//#endregion
|
|
2278
|
-
//#region src/clients/utility-client.d.ts
|
|
2279
|
-
/**
|
|
2280
|
-
* Response interface for ping operations
|
|
2281
|
-
*/
|
|
2282
|
-
interface PingResponse extends BaseApiResponse {
|
|
2283
|
-
message: string;
|
|
2284
|
-
uptime?: number;
|
|
2285
|
-
}
|
|
2286
|
-
/**
|
|
2287
|
-
* Response interface for getting available commands
|
|
2288
|
-
*/
|
|
2289
|
-
interface CommandsResponse extends BaseApiResponse {
|
|
2290
|
-
availableCommands: string[];
|
|
2291
|
-
count: number;
|
|
2292
|
-
}
|
|
2293
|
-
/**
|
|
2294
|
-
* Request interface for creating sessions
|
|
2295
|
-
*/
|
|
2296
|
-
interface CreateSessionRequest {
|
|
2297
|
-
id: string;
|
|
2298
|
-
env?: Record<string, string | undefined>;
|
|
2299
|
-
cwd?: string;
|
|
2300
|
-
commandTimeoutMs?: number;
|
|
2301
|
-
}
|
|
2302
|
-
/**
|
|
2303
|
-
* Response interface for creating sessions.
|
|
2304
|
-
*
|
|
2305
|
-
* `containerPlacementId` carries the container's `CLOUDFLARE_PLACEMENT_ID` at session
|
|
2306
|
-
* creation time so the DO can capture it without a separate request. It is
|
|
2307
|
-
* `null` when the environment variable is not set, such as in local dev.
|
|
2308
|
-
*/
|
|
2309
|
-
interface CreateSessionResponse extends BaseApiResponse {
|
|
2310
|
-
id: string;
|
|
2311
|
-
message: string;
|
|
2312
|
-
containerPlacementId?: string | null;
|
|
2313
|
-
}
|
|
2314
|
-
/**
|
|
2315
|
-
* Request interface for deleting sessions
|
|
2316
|
-
*/
|
|
2317
|
-
interface DeleteSessionRequest {
|
|
2318
|
-
sessionId: string;
|
|
2319
|
-
}
|
|
2320
|
-
/**
|
|
2321
|
-
* Response interface for deleting sessions
|
|
2322
|
-
*/
|
|
2323
|
-
interface DeleteSessionResponse extends BaseApiResponse {
|
|
2324
|
-
sessionId: string;
|
|
2325
|
-
}
|
|
2326
|
-
/**
|
|
2327
|
-
* Client for health checks and utility operations
|
|
2328
|
-
*/
|
|
2329
|
-
declare class UtilityClient extends BaseHttpClient implements SandboxUtilsAPI {
|
|
2330
|
-
/**
|
|
2331
|
-
* Ping the sandbox to check if it's responsive
|
|
2332
|
-
*/
|
|
2333
|
-
ping(): Promise<string>;
|
|
2334
|
-
/**
|
|
2335
|
-
* Get list of available commands in the sandbox environment
|
|
2336
|
-
*/
|
|
2337
|
-
getCommands(): Promise<string[]>;
|
|
2338
|
-
/**
|
|
2339
|
-
* Create a new execution session
|
|
2340
|
-
* @param options - Session configuration (id, env, cwd)
|
|
2341
|
-
*/
|
|
2342
|
-
createSession(options: CreateSessionRequest): Promise<CreateSessionResponse>;
|
|
2343
|
-
/**
|
|
2344
|
-
* Delete an execution session
|
|
2345
|
-
* @param sessionId - Session ID to delete
|
|
2346
|
-
*/
|
|
2347
|
-
deleteSession(sessionId: string): Promise<DeleteSessionResponse>;
|
|
2348
|
-
/**
|
|
2349
|
-
* Get the container version
|
|
2350
|
-
* Returns the version embedded in the Docker image during build
|
|
2351
|
-
*/
|
|
2352
|
-
getVersion(): Promise<string>;
|
|
2353
|
-
listSessions(): Promise<{
|
|
2354
|
-
sessions: string[];
|
|
2355
|
-
}>;
|
|
2356
|
-
}
|
|
2357
|
-
//#endregion
|
|
2358
|
-
//#region src/clients/watch-client.d.ts
|
|
2359
|
-
/**
|
|
2360
|
-
* Client for file watch operations
|
|
2361
|
-
* Uses inotify under the hood for native filesystem event notifications
|
|
2362
|
-
*
|
|
2363
|
-
* @internal This client is used internally by the SDK.
|
|
2364
|
-
* Users should use `sandbox.watch()` or `sandbox.checkChanges()` instead.
|
|
2365
|
-
*/
|
|
2366
|
-
declare class WatchClient extends BaseHttpClient implements SandboxWatchAPI {
|
|
2367
|
-
/**
|
|
2368
|
-
* Check whether a path changed since a previously returned version.
|
|
2369
|
-
*/
|
|
2370
|
-
checkChanges(request: CheckChangesRequest): Promise<CheckChangesResult>;
|
|
2371
|
-
/**
|
|
2372
|
-
* Start watching a directory for changes.
|
|
2373
|
-
* The returned promise resolves only after the watcher is established
|
|
2374
|
-
* on the filesystem (i.e. the `watching` SSE event has been received).
|
|
2375
|
-
* The returned stream still contains the `watching` event so consumers
|
|
2376
|
-
* using `parseSSEStream` will see the full event sequence.
|
|
2377
|
-
*
|
|
2378
|
-
* @param request - Watch request with path and options
|
|
2379
|
-
*/
|
|
2380
|
-
watch(request: WatchRequest): Promise<ReadableStream<Uint8Array>>;
|
|
2381
|
-
/**
|
|
2382
|
-
* Read SSE chunks until the `watching` event appears, then return a
|
|
2383
|
-
* wrapper stream that replays the buffered chunks followed by the
|
|
2384
|
-
* remaining original stream data.
|
|
2385
|
-
*/
|
|
2386
|
-
private waitForReadiness;
|
|
2387
|
-
}
|
|
2388
|
-
//#endregion
|
|
2389
|
-
//#region src/clients/sandbox-client.d.ts
|
|
2390
|
-
/**
|
|
2391
|
-
* Route-based compatibility sandbox client that composes all domain-specific
|
|
2392
|
-
* HTTP API clients.
|
|
2393
|
-
*
|
|
2394
|
-
* This client supports the route-based HTTP and custom WebSocket transports.
|
|
2395
|
-
* The primary DO-to-container control path is ContainerControlClient under
|
|
2396
|
-
* `container-control/`. This client supports route-based compatibility,
|
|
2397
|
-
* debugging, local development, and fallback behavior.
|
|
2398
|
-
*/
|
|
2399
|
-
declare class SandboxClient {
|
|
2400
|
-
readonly backup: BackupClient;
|
|
2401
|
-
readonly commands: CommandClient;
|
|
2402
|
-
readonly files: FileClient;
|
|
2403
|
-
readonly processes: ProcessClient;
|
|
2404
|
-
readonly ports: PortClient;
|
|
2405
|
-
readonly git: GitClient;
|
|
2406
|
-
readonly interpreter: InterpreterClient;
|
|
2407
|
-
readonly utils: UtilityClient;
|
|
2408
|
-
readonly watch: WatchClient;
|
|
2409
|
-
/**
|
|
2410
|
-
* Tunnels are RPC-only — the route-based transport does not implement them.
|
|
2411
|
-
* This getter exists so the `PublicKeys<SandboxClient> satisfies
|
|
2412
|
-
* PublicKeys<SandboxAPI>` compile-time check holds. Calling any method on
|
|
2413
|
-
* the returned proxy throws a clear `RPC transport required` error.
|
|
2414
|
-
*/
|
|
2415
|
-
readonly tunnels: never;
|
|
2416
|
-
private transport;
|
|
2417
|
-
constructor(options: HttpClientOptions);
|
|
2418
|
-
/**
|
|
2419
|
-
* Update the 503 retry budget on all transports without recreating the client.
|
|
2420
|
-
*
|
|
2421
|
-
* In WebSocket mode a single shared transport is used, so one update covers
|
|
2422
|
-
* every sub-client. In HTTP mode each sub-client owns its own transport, so
|
|
2423
|
-
* all of them are updated individually.
|
|
2424
|
-
*/
|
|
2425
|
-
setRetryTimeoutMs(ms: number): void;
|
|
2426
|
-
/**
|
|
2427
|
-
* Get the current transport mode
|
|
2428
|
-
*/
|
|
2429
|
-
getTransportMode(): RouteTransportMode;
|
|
2430
|
-
/**
|
|
2431
|
-
* Check if WebSocket is connected (only relevant in WebSocket mode)
|
|
2432
|
-
*/
|
|
2433
|
-
isWebSocketConnected(): boolean;
|
|
2434
|
-
/**
|
|
2435
|
-
* Connect WebSocket transport (no-op in HTTP mode)
|
|
2436
|
-
* Called automatically on first request, but can be called explicitly
|
|
2437
|
-
* to establish connection upfront.
|
|
2438
|
-
*/
|
|
2439
|
-
connect(): Promise<void>;
|
|
2440
|
-
/**
|
|
2441
|
-
* Disconnect WebSocket transport (no-op in HTTP mode)
|
|
2442
|
-
* Should be called when the sandbox is destroyed.
|
|
2443
|
-
*/
|
|
2444
|
-
disconnect(): void;
|
|
1681
|
+
onTunnelExit(id: string, port: number, exitCode: number | null): Promise<void>;
|
|
2445
1682
|
}
|
|
2446
1683
|
//#endregion
|
|
2447
1684
|
//#region src/container-control/connection.d.ts
|
|
@@ -2454,9 +1691,9 @@ interface ContainerControlConnectionOptions {
|
|
|
2454
1691
|
port?: number;
|
|
2455
1692
|
logger?: Logger;
|
|
2456
1693
|
/**
|
|
2457
|
-
* Total retry budget (ms) for
|
|
2458
|
-
* is
|
|
2459
|
-
*
|
|
1694
|
+
* Total retry budget (ms) for retryable upgrade responses while the
|
|
1695
|
+
* container is unavailable. Defaults to 120 000 (2 minutes). Set to 0 to
|
|
1696
|
+
* disable retries.
|
|
2460
1697
|
*/
|
|
2461
1698
|
retryTimeoutMs?: number;
|
|
2462
1699
|
/**
|
|
@@ -2466,7 +1703,7 @@ interface ContainerControlConnectionOptions {
|
|
|
2466
1703
|
* (e.g. notifying the DO when a tunnel's cloudflared process has
|
|
2467
1704
|
* exited). When omitted, the container sees an empty remote main.
|
|
2468
1705
|
*/
|
|
2469
|
-
localMain?:
|
|
1706
|
+
localMain?: SandboxControlCallback & RpcTarget;
|
|
2470
1707
|
/**
|
|
2471
1708
|
* Invoked when an active WebSocket transitions to closed/errored.
|
|
2472
1709
|
* Fired at most once per successful connection from the WS event
|
|
@@ -2474,8 +1711,10 @@ interface ContainerControlConnectionOptions {
|
|
|
2474
1711
|
* signal so recovery doesn't depend on a periodic poller running
|
|
2475
1712
|
* inside what may be an idle isolate.
|
|
2476
1713
|
*
|
|
2477
|
-
*
|
|
2478
|
-
*
|
|
1714
|
+
* Also fired for `doConnect` failures after the deferred transport is
|
|
1715
|
+
* aborted. A failed upgrade poisons the transport, so owners must discard
|
|
1716
|
+
* the connection and create a fresh one for subsequent calls. Not fired for
|
|
1717
|
+
* `disconnect()`.
|
|
2479
1718
|
*/
|
|
2480
1719
|
onClose?: () => void;
|
|
2481
1720
|
}
|
|
@@ -2495,8 +1734,9 @@ interface ContainerControlClientOptions extends ContainerControlConnectionOption
|
|
|
2495
1734
|
/**
|
|
2496
1735
|
* Fires once when the capnweb session transitions from idle to busy
|
|
2497
1736
|
* (an RPC call was started or a stream return is now in flight). The
|
|
2498
|
-
* Sandbox DO wires this to
|
|
2499
|
-
* `isActivityExpired()` skip the
|
|
1737
|
+
* Sandbox DO wires this to increment the Container base class's
|
|
1738
|
+
* in-flight request counter, which makes `isActivityExpired()` skip the
|
|
1739
|
+
* sleepAfter comparison.
|
|
2500
1740
|
*/
|
|
2501
1741
|
onSessionBusy?: () => void;
|
|
2502
1742
|
/**
|
|
@@ -2509,7 +1749,7 @@ interface ContainerControlClientOptions extends ContainerControlConnectionOption
|
|
|
2509
1749
|
onSessionIdle?: () => void;
|
|
2510
1750
|
}
|
|
2511
1751
|
/**
|
|
2512
|
-
*
|
|
1752
|
+
* Sandbox control facade backed by direct capnweb RPC.
|
|
2513
1753
|
*
|
|
2514
1754
|
* All operations call the container's SandboxAPI control interface directly
|
|
2515
1755
|
* over capnweb, bypassing the HTTP handler/router layer entirely.
|
|
@@ -2574,12 +1814,11 @@ declare class ContainerControlClient {
|
|
|
2574
1814
|
get tunnels(): SandboxTunnelsAPI;
|
|
2575
1815
|
get interpreter(): SandboxInterpreterAPI;
|
|
2576
1816
|
/**
|
|
2577
|
-
* Update the
|
|
1817
|
+
* Update the upgrade retry budget. Applies to the current connection
|
|
2578
1818
|
* (if any) and is remembered for any future connections created after the
|
|
2579
1819
|
* client is torn down and reconnected.
|
|
2580
1820
|
*/
|
|
2581
1821
|
setRetryTimeoutMs(ms: number): void;
|
|
2582
|
-
getTransportMode(): SandboxTransport;
|
|
2583
1822
|
isWebSocketConnected(): boolean;
|
|
2584
1823
|
connect(): Promise<void>;
|
|
2585
1824
|
disconnect(): void;
|
|
@@ -2601,7 +1840,6 @@ type SandboxConfiguration = {
|
|
|
2601
1840
|
sleepAfter?: string | number;
|
|
2602
1841
|
keepAlive?: boolean;
|
|
2603
1842
|
containerTimeouts?: NonNullable<SandboxOptions['containerTimeouts']>;
|
|
2604
|
-
transport?: SandboxTransport;
|
|
2605
1843
|
};
|
|
2606
1844
|
/**
|
|
2607
1845
|
* SDK-level ContainerProxy that directly dispatches SDK-internal mount hosts
|
|
@@ -2619,7 +1857,7 @@ declare function getSandbox<T extends Sandbox<any>>(ns: DurableObjectNamespace<T
|
|
|
2619
1857
|
declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox {
|
|
2620
1858
|
defaultPort: number;
|
|
2621
1859
|
sleepAfter: string | number;
|
|
2622
|
-
client:
|
|
1860
|
+
client: ContainerControlClient;
|
|
2623
1861
|
private codeInterpreter;
|
|
2624
1862
|
private sandboxName;
|
|
2625
1863
|
private tunnelsHandler;
|
|
@@ -2636,14 +1874,6 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
|
|
|
2636
1874
|
private activeMounts;
|
|
2637
1875
|
private mountOperationQueue;
|
|
2638
1876
|
private currentRuntime;
|
|
2639
|
-
private transport;
|
|
2640
|
-
/**
|
|
2641
|
-
* True once transport has been written to storage at least once (either
|
|
2642
|
-
* via setTransport or restored on cold start). Gates the idempotency
|
|
2643
|
-
* check so a first explicit call persists even when the requested value
|
|
2644
|
-
* already equals the env-derived in-memory default.
|
|
2645
|
-
*/
|
|
2646
|
-
private hasStoredTransport;
|
|
2647
1877
|
private backupBucket;
|
|
2648
1878
|
/**
|
|
2649
1879
|
* Serializes backup operations to prevent concurrent create/restore on the same sandbox.
|
|
@@ -2704,26 +1934,18 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
|
|
|
2704
1934
|
*/
|
|
2705
1935
|
callTunnels(method: string, args: unknown[]): Promise<unknown>;
|
|
2706
1936
|
/**
|
|
2707
|
-
* Compute the
|
|
1937
|
+
* Compute the control-channel upgrade retry budget from current container
|
|
1938
|
+
* timeouts.
|
|
2708
1939
|
*
|
|
2709
1940
|
* The budget covers the full container startup window (instance provisioning
|
|
2710
|
-
* + port readiness) plus a 30s margin for the maximum single backoff delay
|
|
2711
|
-
*
|
|
2712
|
-
* default for short timeout configurations.
|
|
1941
|
+
* + port readiness) plus a 30s margin for the maximum single backoff delay.
|
|
1942
|
+
* The 120s floor preserves the default for short timeout configurations.
|
|
2713
1943
|
*/
|
|
2714
1944
|
private computeRetryTimeoutMs;
|
|
2715
1945
|
/**
|
|
2716
|
-
* Create the
|
|
2717
|
-
* transport settings.
|
|
2718
|
-
*/
|
|
2719
|
-
private createSandboxClient;
|
|
2720
|
-
/**
|
|
2721
|
-
* Create the appropriate client for the configured control path.
|
|
2722
|
-
*
|
|
2723
|
-
* `rpc` currently selects the primary container-control client. `http` and
|
|
2724
|
-
* `websocket` select the route-based compatibility client.
|
|
1946
|
+
* Create the single control-plane client used for all SDK operations.
|
|
2725
1947
|
*/
|
|
2726
|
-
private
|
|
1948
|
+
private createClient;
|
|
2727
1949
|
constructor(ctx: DurableObjectState<{}>, env: Env);
|
|
2728
1950
|
setSandboxName(name: string, normalizeId?: boolean): Promise<void>;
|
|
2729
1951
|
configure(configuration: SandboxConfiguration): Promise<void>;
|
|
@@ -2731,7 +1953,6 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
|
|
|
2731
1953
|
setKeepAlive(keepAlive: boolean): Promise<void>;
|
|
2732
1954
|
setEnvVars(envVars: Record<string, string | undefined>): Promise<void>;
|
|
2733
1955
|
setContainerTimeouts(timeouts: NonNullable<SandboxOptions['containerTimeouts']>): Promise<void>;
|
|
2734
|
-
setTransport(transport: SandboxTransport): Promise<void>;
|
|
2735
1956
|
private validateTimeout;
|
|
2736
1957
|
private getDefaultTimeouts;
|
|
2737
1958
|
/**
|
|
@@ -3063,7 +2284,7 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
|
|
|
3063
2284
|
* - `'utf-8'` / `'utf8'`: always return as UTF-8 string
|
|
3064
2285
|
* - `'base64'`: always return as base64-encoded string
|
|
3065
2286
|
* - `'none'`: return a result whose `content` is a raw binary `ReadableStream<Uint8Array>`
|
|
3066
|
-
* with no encoding overhead.
|
|
2287
|
+
* with no encoding overhead.
|
|
3067
2288
|
*/
|
|
3068
2289
|
readFile(path: string, options: {
|
|
3069
2290
|
encoding: 'none';
|
|
@@ -3166,7 +2387,8 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
|
|
|
3166
2387
|
}[]>;
|
|
3167
2388
|
/**
|
|
3168
2389
|
* Namespaced tunnel API. Quick tunnels are zero-config preview URLs
|
|
3169
|
-
* backed by Cloudflare's trycloudflare service.
|
|
2390
|
+
* backed by Cloudflare's trycloudflare service. Named tunnels bind a
|
|
2391
|
+
* stable hostname under the configured Cloudflare zone.
|
|
3170
2392
|
*
|
|
3171
2393
|
* - `tunnels.get(port)` — idempotent. Returns the cached tunnel for
|
|
3172
2394
|
* `port` if one exists in DO storage, otherwise spawns a fresh
|
|
@@ -3176,19 +2398,17 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
|
|
|
3176
2398
|
* - `tunnels.destroy(portOrInfo)` — tear down by port number or by
|
|
3177
2399
|
* the record returned from `get()`.
|
|
3178
2400
|
*
|
|
3179
|
-
*
|
|
3180
|
-
*
|
|
3181
|
-
*
|
|
3182
|
-
*
|
|
3183
|
-
*
|
|
3184
|
-
* throws "RPC transport required".
|
|
2401
|
+
* Container restarts drop quick-tunnel records because their
|
|
2402
|
+
* `*.trycloudflare.com` URLs are tied to the dead cloudflared process.
|
|
2403
|
+
* Named-tunnel records stay in storage and are marked for respawn so the
|
|
2404
|
+
* next `get(port, { name })` call reuses the Cloudflare tunnel and DNS
|
|
2405
|
+
* record while starting a fresh cloudflared process.
|
|
3185
2406
|
*/
|
|
3186
2407
|
get tunnels(): TunnelsHandler;
|
|
3187
2408
|
/**
|
|
3188
2409
|
* Lazily construct both the public tunnels handler and its sibling
|
|
3189
2410
|
* exit-handler callback. Called from the `tunnels` getter on first
|
|
3190
|
-
* access
|
|
3191
|
-
* fields.
|
|
2411
|
+
* access.
|
|
3192
2412
|
*/
|
|
3193
2413
|
private ensureTunnelsBuilt;
|
|
3194
2414
|
/**
|
|
@@ -3426,5 +2646,5 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
|
|
|
3426
2646
|
private configureS3CredentialProxyOutbound;
|
|
3427
2647
|
}
|
|
3428
2648
|
//#endregion
|
|
3429
|
-
export {
|
|
3430
|
-
//# sourceMappingURL=sandbox-
|
|
2649
|
+
export { Process as A, WatchOptions as B, FileWatchSSEEvent as C, LocalMountBucketOptions as D, ListFilesOptions as E, SandboxOptions as F, CodeContext as G, isProcess as H, SessionOptions as I, ExecutionResult as J, CreateContextOptions as K, StreamOptions as L, ProcessStatus as M, RemoteMountBucketOptions as N, LogEvent as O, RestoreBackupResult as P, WaitForLogResult as R, FileStreamEvent as S, ISandbox as T, isProcessStatus as U, isExecResult as V, PtyOptions as W, RunCodeOptions as Y, ExecOptions as _, QuickTunnelInfo as a, FileChunk as b, TunnelOptions as c, BucketCredentials as d, BucketProvider as f, ExecEvent as g, DirectoryBackup as h, NamedTunnelInfo as i, ProcessOptions as j, MountBucketOptions as k, BackupOptions as l, CheckChangesResult as m, Sandbox as n, SandboxInterpreterAPI as o, CheckChangesOptions as p, Execution as q, getSandbox as r, TunnelInfo as s, ContainerProxy$1 as t, BaseExecOptions as u, ExecResult as v, GitCheckoutResult as w, FileMetadata as x, ExecutionSession as y, WaitForPortOptions as z };
|
|
2650
|
+
//# sourceMappingURL=sandbox-Cz8DRoAm.d.ts.map
|