plato-sandbox-sdk 1.1.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/BaseClient.ts +28 -0
- package/Client.ts +1849 -0
- package/README.md +339 -0
- package/api/client/index.ts +1 -0
- package/api/client/requests/CreateSandboxRequest.ts +37 -0
- package/api/client/requests/CreateSnapshotRequest.ts +11 -0
- package/api/client/requests/EvaluateRequest.ts +9 -0
- package/api/client/requests/GetEnvironmentStateRequest.ts +11 -0
- package/api/client/requests/GetTestCasesRequest.ts +15 -0
- package/api/client/requests/LogRequest.ts +19 -0
- package/api/client/requests/MakeEnvironmentRequest.ts +27 -0
- package/api/client/requests/PostEvaluationResultRequest.ts +14 -0
- package/api/client/requests/ResetEnvironmentRequest.ts +11 -0
- package/api/client/requests/SetupRootAccessRequest.ts +14 -0
- package/api/client/requests/SetupSandboxRequest.ts +29 -0
- package/api/client/requests/StartWorkerRequest.ts +28 -0
- package/api/client/requests/index.ts +12 -0
- package/api/errors/BadRequestError.ts +17 -0
- package/api/errors/index.ts +1 -0
- package/api/index.ts +3 -0
- package/api/types/ActiveSessionResponse.ts +6 -0
- package/api/types/BackupEnvironmentResponse.ts +7 -0
- package/api/types/CdpUrlResponse.ts +12 -0
- package/api/types/CloseEnvironmentResponse.ts +6 -0
- package/api/types/CreateSandboxResponse.ts +14 -0
- package/api/types/CreateSnapshotResponse.ts +10 -0
- package/api/types/DeleteSandboxResponse.ts +6 -0
- package/api/types/Environment.ts +7 -0
- package/api/types/EnvironmentStateResponse.ts +11 -0
- package/api/types/ErrorResponse.ts +6 -0
- package/api/types/EvaluateResponse.ts +21 -0
- package/api/types/EvaluationResult.ts +9 -0
- package/api/types/HeartbeatResponse.ts +6 -0
- package/api/types/JobStatusResponse.ts +7 -0
- package/api/types/LogResponse.ts +5 -0
- package/api/types/MakeEnvironmentResponse.ts +6 -0
- package/api/types/OperationEvent.ts +42 -0
- package/api/types/PlatoConfig.ts +8 -0
- package/api/types/PlatoTask.ts +21 -0
- package/api/types/PlatoTaskMetadata.ts +20 -0
- package/api/types/PostEvaluationResultResponse.ts +6 -0
- package/api/types/ProxyUrlResponse.ts +12 -0
- package/api/types/ResetEnvironmentResponse.ts +13 -0
- package/api/types/RunningSessionsCountResponse.ts +6 -0
- package/api/types/Sandbox.ts +10 -0
- package/api/types/ScoringType.ts +7 -0
- package/api/types/SetupRootAccessResponse.ts +7 -0
- package/api/types/SetupSandboxResponse.ts +6 -0
- package/api/types/SimConfigCompute.ts +9 -0
- package/api/types/SimConfigDataset.ts +10 -0
- package/api/types/SimConfigListener.ts +27 -0
- package/api/types/SimConfigMetadata.ts +14 -0
- package/api/types/SimConfigService.ts +8 -0
- package/api/types/Simulator.ts +10 -0
- package/api/types/SimulatorListItem.ts +7 -0
- package/api/types/SshInfo.ts +18 -0
- package/api/types/StartWorkerResponse.ts +7 -0
- package/api/types/TaskMetadata.ts +20 -0
- package/api/types/TestCase.ts +40 -0
- package/api/types/TestCasesResponse.ts +10 -0
- package/api/types/Variable.ts +6 -0
- package/api/types/WorkerReadyResponse.ts +9 -0
- package/api/types/index.ts +42 -0
- package/core/fetcher/APIResponse.ts +23 -0
- package/core/fetcher/BinaryResponse.ts +36 -0
- package/core/fetcher/EndpointMetadata.ts +13 -0
- package/core/fetcher/EndpointSupplier.ts +14 -0
- package/core/fetcher/Fetcher.ts +165 -0
- package/core/fetcher/Headers.ts +93 -0
- package/core/fetcher/HttpResponsePromise.ts +116 -0
- package/core/fetcher/RawResponse.ts +61 -0
- package/core/fetcher/ResponseWithBody.ts +7 -0
- package/core/fetcher/Supplier.ts +11 -0
- package/core/fetcher/createRequestUrl.ts +6 -0
- package/core/fetcher/getErrorResponseBody.ts +33 -0
- package/core/fetcher/getFetchFn.ts +3 -0
- package/core/fetcher/getHeader.ts +8 -0
- package/core/fetcher/getRequestBody.ts +16 -0
- package/core/fetcher/getResponseBody.ts +43 -0
- package/core/fetcher/index.ts +11 -0
- package/core/fetcher/makeRequest.ts +44 -0
- package/core/fetcher/requestWithRetries.ts +73 -0
- package/core/fetcher/signals.ts +38 -0
- package/core/headers.ts +33 -0
- package/core/index.ts +4 -0
- package/core/json.ts +27 -0
- package/core/runtime/index.ts +1 -0
- package/core/runtime/runtime.ts +133 -0
- package/core/stream/Stream.ts +155 -0
- package/core/stream/index.ts +1 -0
- package/core/url/encodePathParam.ts +18 -0
- package/core/url/index.ts +3 -0
- package/core/url/join.ts +80 -0
- package/core/url/qs.ts +74 -0
- package/dist/BaseClient.d.ts +25 -0
- package/dist/Client.d.ts +376 -0
- package/dist/api/client/index.d.ts +2 -0
- package/dist/api/client/requests/CreateSandboxRequest.d.ts +35 -0
- package/dist/api/client/requests/CreateSnapshotRequest.d.ts +10 -0
- package/dist/api/client/requests/EvaluateRequest.d.ts +8 -0
- package/dist/api/client/requests/GetEnvironmentStateRequest.d.ts +10 -0
- package/dist/api/client/requests/GetTestCasesRequest.d.ts +14 -0
- package/dist/api/client/requests/LogRequest.d.ts +18 -0
- package/dist/api/client/requests/MakeEnvironmentRequest.d.ts +26 -0
- package/dist/api/client/requests/PostEvaluationResultRequest.d.ts +13 -0
- package/dist/api/client/requests/ResetEnvironmentRequest.d.ts +10 -0
- package/dist/api/client/requests/SetupRootAccessRequest.d.ts +13 -0
- package/dist/api/client/requests/SetupSandboxRequest.d.ts +27 -0
- package/dist/api/client/requests/StartWorkerRequest.d.ts +26 -0
- package/dist/api/client/requests/index.d.ts +13 -0
- package/dist/api/errors/BadRequestError.d.ts +7 -0
- package/dist/api/errors/index.d.ts +2 -0
- package/dist/api/index.d.ts +4 -0
- package/dist/api/types/ActiveSessionResponse.d.ts +5 -0
- package/dist/api/types/BackupEnvironmentResponse.d.ts +6 -0
- package/dist/api/types/CdpUrlResponse.d.ts +10 -0
- package/dist/api/types/CloseEnvironmentResponse.d.ts +5 -0
- package/dist/api/types/CreateSandboxResponse.d.ts +13 -0
- package/dist/api/types/CreateSnapshotResponse.d.ts +9 -0
- package/dist/api/types/DeleteSandboxResponse.d.ts +5 -0
- package/dist/api/types/Environment.d.ts +6 -0
- package/dist/api/types/EnvironmentStateResponse.d.ts +9 -0
- package/dist/api/types/ErrorResponse.d.ts +5 -0
- package/dist/api/types/EvaluateResponse.d.ts +18 -0
- package/dist/api/types/EvaluationResult.d.ts +8 -0
- package/dist/api/types/HeartbeatResponse.d.ts +5 -0
- package/dist/api/types/JobStatusResponse.d.ts +6 -0
- package/dist/api/types/LogResponse.d.ts +4 -0
- package/dist/api/types/MakeEnvironmentResponse.d.ts +5 -0
- package/dist/api/types/OperationEvent.d.ts +40 -0
- package/dist/api/types/PlatoConfig.d.ts +6 -0
- package/dist/api/types/PlatoTask.d.ts +19 -0
- package/dist/api/types/PlatoTaskMetadata.d.ts +18 -0
- package/dist/api/types/PostEvaluationResultResponse.d.ts +5 -0
- package/dist/api/types/ProxyUrlResponse.d.ts +10 -0
- package/dist/api/types/ResetEnvironmentResponse.d.ts +11 -0
- package/dist/api/types/RunningSessionsCountResponse.d.ts +5 -0
- package/dist/api/types/Sandbox.d.ts +9 -0
- package/dist/api/types/ScoringType.d.ts +6 -0
- package/dist/api/types/SetupRootAccessResponse.d.ts +6 -0
- package/dist/api/types/SetupSandboxResponse.d.ts +5 -0
- package/dist/api/types/SimConfigCompute.d.ts +8 -0
- package/dist/api/types/SimConfigDataset.d.ts +8 -0
- package/dist/api/types/SimConfigListener.d.ts +25 -0
- package/dist/api/types/SimConfigMetadata.d.ts +12 -0
- package/dist/api/types/SimConfigService.d.ts +7 -0
- package/dist/api/types/Simulator.d.ts +9 -0
- package/dist/api/types/SimulatorListItem.d.ts +6 -0
- package/dist/api/types/SshInfo.d.ts +17 -0
- package/dist/api/types/StartWorkerResponse.d.ts +6 -0
- package/dist/api/types/TaskMetadata.d.ts +18 -0
- package/dist/api/types/TestCase.d.ts +34 -0
- package/dist/api/types/TestCasesResponse.d.ts +8 -0
- package/dist/api/types/Variable.d.ts +5 -0
- package/dist/api/types/WorkerReadyResponse.d.ts +8 -0
- package/dist/api/types/index.d.ts +43 -0
- package/dist/core/fetcher/APIResponse.d.ts +21 -0
- package/dist/core/fetcher/BinaryResponse.d.ts +21 -0
- package/dist/core/fetcher/EndpointMetadata.d.ts +14 -0
- package/dist/core/fetcher/EndpointSupplier.d.ts +13 -0
- package/dist/core/fetcher/Fetcher.d.ts +43 -0
- package/dist/core/fetcher/Headers.d.ts +3 -0
- package/dist/core/fetcher/HttpResponsePromise.d.ts +59 -0
- package/dist/core/fetcher/RawResponse.d.ts +30 -0
- package/dist/core/fetcher/ResponseWithBody.d.ts +5 -0
- package/dist/core/fetcher/Supplier.d.ts +5 -0
- package/dist/core/fetcher/createRequestUrl.d.ts +2 -0
- package/dist/core/fetcher/getErrorResponseBody.d.ts +2 -0
- package/dist/core/fetcher/getFetchFn.d.ts +2 -0
- package/dist/core/fetcher/getHeader.d.ts +2 -0
- package/dist/core/fetcher/getRequestBody.d.ts +8 -0
- package/dist/core/fetcher/getResponseBody.d.ts +2 -0
- package/dist/core/fetcher/index.d.ts +12 -0
- package/dist/core/fetcher/makeRequest.d.ts +2 -0
- package/dist/core/fetcher/requestWithRetries.d.ts +2 -0
- package/dist/core/fetcher/signals.d.ts +12 -0
- package/dist/core/headers.d.ts +3 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/json.d.ts +16 -0
- package/dist/core/runtime/index.d.ts +2 -0
- package/dist/core/runtime/runtime.d.ts +10 -0
- package/dist/core/stream/Stream.d.ts +48 -0
- package/dist/core/stream/index.d.ts +2 -0
- package/dist/core/url/encodePathParam.d.ts +2 -0
- package/dist/core/url/index.d.ts +4 -0
- package/dist/core/url/join.d.ts +2 -0
- package/dist/core/url/qs.d.ts +7 -0
- package/dist/errors/ApiError.d.ts +13 -0
- package/dist/errors/ApiTimeoutError.d.ts +4 -0
- package/dist/errors/index.d.ts +3 -0
- package/dist/helpers/SandboxHelpers.d.ts +127 -0
- package/dist/helpers/SandboxMonitor.d.ts +89 -0
- package/dist/helpers/index.d.ts +9 -0
- package/dist/index.d.ts +6 -0
- package/errors/ApiError.ts +53 -0
- package/errors/ApiTimeoutError.ts +8 -0
- package/errors/index.ts +2 -0
- package/helpers/README.md +229 -0
- package/helpers/SandboxHelpers.ts +213 -0
- package/helpers/SandboxMonitor.ts +252 -0
- package/helpers/index.ts +10 -0
- package/index.ts +7 -0
- package/package.json +54 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { WithRawResponse } from "./RawResponse.js";
|
|
2
|
+
/**
|
|
3
|
+
* A promise that returns the parsed response and lets you retrieve the raw response too.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpResponsePromise<T> extends Promise<T> {
|
|
6
|
+
private innerPromise;
|
|
7
|
+
private unwrappedPromise;
|
|
8
|
+
private constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Creates an `HttpResponsePromise` from a function that returns a promise.
|
|
11
|
+
*
|
|
12
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
13
|
+
* @param args - Arguments to pass to the function.
|
|
14
|
+
* @returns An `HttpResponsePromise` instance.
|
|
15
|
+
*/
|
|
16
|
+
static fromFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T>(fn: F, ...args: Parameters<F>): HttpResponsePromise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
|
|
19
|
+
*
|
|
20
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
21
|
+
* @returns A function that returns an `HttpResponsePromise` instance.
|
|
22
|
+
*/
|
|
23
|
+
static interceptFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T = Awaited<ReturnType<F>>["data"]>(fn: F): (...args: Parameters<F>) => HttpResponsePromise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an `HttpResponsePromise` from an existing promise.
|
|
26
|
+
*
|
|
27
|
+
* @param promise - A promise resolving to a `WithRawResponse` object.
|
|
28
|
+
* @returns An `HttpResponsePromise` instance.
|
|
29
|
+
*/
|
|
30
|
+
static fromPromise<T>(promise: Promise<WithRawResponse<T>>): HttpResponsePromise<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an `HttpResponsePromise` from an executor function.
|
|
33
|
+
*
|
|
34
|
+
* @param executor - A function that takes resolve and reject callbacks to create a promise.
|
|
35
|
+
* @returns An `HttpResponsePromise` instance.
|
|
36
|
+
*/
|
|
37
|
+
static fromExecutor<T>(executor: (resolve: (value: WithRawResponse<T>) => void, reject: (reason?: unknown) => void) => void): HttpResponsePromise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates an `HttpResponsePromise` from a resolved result.
|
|
40
|
+
*
|
|
41
|
+
* @param result - A `WithRawResponse` object to resolve immediately.
|
|
42
|
+
* @returns An `HttpResponsePromise` instance.
|
|
43
|
+
*/
|
|
44
|
+
static fromResult<T>(result: WithRawResponse<T>): HttpResponsePromise<T>;
|
|
45
|
+
private unwrap;
|
|
46
|
+
/** @inheritdoc */
|
|
47
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
48
|
+
/** @inheritdoc */
|
|
49
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
|
|
50
|
+
/** @inheritdoc */
|
|
51
|
+
finally(onfinally?: (() => void) | null): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the data and raw response.
|
|
54
|
+
*
|
|
55
|
+
* @returns A promise resolving to a `WithRawResponse` object.
|
|
56
|
+
*/
|
|
57
|
+
withRawResponse(): Promise<WithRawResponse<T>>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=HttpResponsePromise.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The raw response from the fetch call excluding the body.
|
|
3
|
+
*/
|
|
4
|
+
export type RawResponse = Omit<{
|
|
5
|
+
[K in keyof Response as Response[K] extends Function ? never : K]: Response[K];
|
|
6
|
+
}, "ok" | "body" | "bodyUsed">;
|
|
7
|
+
/**
|
|
8
|
+
* A raw response indicating that the request was aborted.
|
|
9
|
+
*/
|
|
10
|
+
export declare const abortRawResponse: RawResponse;
|
|
11
|
+
/**
|
|
12
|
+
* A raw response indicating an unknown error.
|
|
13
|
+
*/
|
|
14
|
+
export declare const unknownRawResponse: RawResponse;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a `RawResponse` object into a `RawResponse` by extracting its properties,
|
|
17
|
+
* excluding the `body` and `bodyUsed` fields.
|
|
18
|
+
*
|
|
19
|
+
* @param response - The `RawResponse` object to convert.
|
|
20
|
+
* @returns A `RawResponse` object containing the extracted properties of the input response.
|
|
21
|
+
*/
|
|
22
|
+
export declare function toRawResponse(response: Response): RawResponse;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a `RawResponse` from a standard `Response` object.
|
|
25
|
+
*/
|
|
26
|
+
export interface WithRawResponse<T> {
|
|
27
|
+
readonly data: T;
|
|
28
|
+
readonly rawResponse: RawResponse;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=RawResponse.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare namespace GetRequestBody {
|
|
2
|
+
interface Args {
|
|
3
|
+
body: unknown;
|
|
4
|
+
type: "json" | "file" | "bytes" | "other";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export declare function getRequestBody({ body, type }: GetRequestBody.Args): Promise<BodyInit | undefined>;
|
|
8
|
+
//# sourceMappingURL=getRequestBody.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { APIResponse } from "./APIResponse.js";
|
|
2
|
+
export type { BinaryResponse } from "./BinaryResponse.js";
|
|
3
|
+
export type { EndpointMetadata } from "./EndpointMetadata.js";
|
|
4
|
+
export { EndpointSupplier } from "./EndpointSupplier.js";
|
|
5
|
+
export type { Fetcher, FetchFunction } from "./Fetcher.js";
|
|
6
|
+
export { fetcher } from "./Fetcher.js";
|
|
7
|
+
export { getHeader } from "./getHeader.js";
|
|
8
|
+
export { HttpResponsePromise } from "./HttpResponsePromise.js";
|
|
9
|
+
export type { RawResponse, WithRawResponse } from "./RawResponse.js";
|
|
10
|
+
export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.js";
|
|
11
|
+
export { Supplier } from "./Supplier.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half") => Promise<Response>;
|
|
2
|
+
//# sourceMappingURL=makeRequest.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function getTimeoutSignal(timeoutMs: number): {
|
|
2
|
+
signal: AbortSignal;
|
|
3
|
+
abortId: NodeJS.Timeout;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Returns an abort signal that is getting aborted when
|
|
7
|
+
* at least one of the specified abort signals is aborted.
|
|
8
|
+
*
|
|
9
|
+
* Requires at least node.js 18.
|
|
10
|
+
*/
|
|
11
|
+
export declare function anySignal(...args: AbortSignal[] | [AbortSignal[]]): AbortSignal;
|
|
12
|
+
//# sourceMappingURL=signals.d.ts.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function mergeHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, string | THeaderValue>;
|
|
2
|
+
export declare function mergeOnlyDefinedHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, THeaderValue>;
|
|
3
|
+
//# sourceMappingURL=headers.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialize a value to JSON
|
|
3
|
+
* @param value A JavaScript value, usually an object or array, to be converted.
|
|
4
|
+
* @param replacer A function that transforms the results.
|
|
5
|
+
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
|
|
6
|
+
* @returns JSON string
|
|
7
|
+
*/
|
|
8
|
+
export declare const toJson: (value: unknown, replacer?: (this: unknown, key: string, value: unknown) => unknown, space?: string | number) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Parse JSON string to object, array, or other type
|
|
11
|
+
* @param text A valid JSON string.
|
|
12
|
+
* @param reviver A function that transforms the results. This function is called for each member of the object. If a member contains nested objects, the nested objects are transformed before the parent object is.
|
|
13
|
+
* @returns Parsed object, array, or other type
|
|
14
|
+
*/
|
|
15
|
+
export declare function fromJson<T = unknown>(text: string, reviver?: (this: unknown, key: string, value: unknown) => unknown): T;
|
|
16
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A constant that indicates which environment and version the SDK is running in.
|
|
3
|
+
*/
|
|
4
|
+
export declare const RUNTIME: Runtime;
|
|
5
|
+
export interface Runtime {
|
|
6
|
+
type: "browser" | "web-worker" | "deno" | "bun" | "node" | "react-native" | "unknown" | "workerd" | "edge-runtime";
|
|
7
|
+
version?: string;
|
|
8
|
+
parsedVersion?: number;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare namespace Stream {
|
|
2
|
+
interface Args {
|
|
3
|
+
/**
|
|
4
|
+
* The HTTP response stream to read from.
|
|
5
|
+
*/
|
|
6
|
+
stream: ReadableStream;
|
|
7
|
+
/**
|
|
8
|
+
* The event shape to use for parsing the stream data.
|
|
9
|
+
*/
|
|
10
|
+
eventShape: JsonEvent | SseEvent;
|
|
11
|
+
/**
|
|
12
|
+
* An abort signal to stop the stream.
|
|
13
|
+
*/
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
interface JsonEvent {
|
|
17
|
+
type: "json";
|
|
18
|
+
messageTerminator: string;
|
|
19
|
+
}
|
|
20
|
+
interface SseEvent {
|
|
21
|
+
type: "sse";
|
|
22
|
+
streamTerminator?: string;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export declare class Stream<T> implements AsyncIterable<T> {
|
|
26
|
+
private stream;
|
|
27
|
+
private parse;
|
|
28
|
+
/**
|
|
29
|
+
* The prefix to use for each message. For example,
|
|
30
|
+
* for SSE, the prefix is "data: ".
|
|
31
|
+
*/
|
|
32
|
+
private prefix;
|
|
33
|
+
private messageTerminator;
|
|
34
|
+
private streamTerminator;
|
|
35
|
+
private controller;
|
|
36
|
+
private decoder;
|
|
37
|
+
constructor({ stream, parse, eventShape, signal }: Stream.Args & {
|
|
38
|
+
parse: (val: unknown) => Promise<T>;
|
|
39
|
+
});
|
|
40
|
+
private iterMessages;
|
|
41
|
+
[Symbol.asyncIterator](): AsyncIterator<T, void, unknown>;
|
|
42
|
+
private decodeChunk;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Browser polyfill for ReadableStream
|
|
46
|
+
*/
|
|
47
|
+
export declare function readableStreamAsyncIterable<T>(stream: any): AsyncIterableIterator<T>;
|
|
48
|
+
//# sourceMappingURL=Stream.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type * as core from "../core/index.js";
|
|
2
|
+
export declare class ApiError extends Error {
|
|
3
|
+
readonly statusCode?: number;
|
|
4
|
+
readonly body?: unknown;
|
|
5
|
+
readonly rawResponse?: core.RawResponse;
|
|
6
|
+
constructor({ message, statusCode, body, rawResponse, }: {
|
|
7
|
+
message?: string;
|
|
8
|
+
statusCode?: number;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
rawResponse?: core.RawResponse;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ApiError.d.ts.map
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level helper functions for sandbox operations.
|
|
3
|
+
*
|
|
4
|
+
* This file is NOT generated by Fern and provides convenient wrappers
|
|
5
|
+
* around the generated API client with built-in operation monitoring.
|
|
6
|
+
*
|
|
7
|
+
* Based on the Go implementation in sdk/services/sandbox.go
|
|
8
|
+
*/
|
|
9
|
+
import type { ApiClient } from "../Client.js";
|
|
10
|
+
import type * as Api from "../api/index.js";
|
|
11
|
+
import { SandboxMonitor, type MonitorOptions } from "./SandboxMonitor.js";
|
|
12
|
+
export interface CreateSandboxOptions extends MonitorOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Whether to wait for the sandbox to be ready before returning.
|
|
15
|
+
* If true, monitors the operation until completion.
|
|
16
|
+
* Default: true
|
|
17
|
+
*/
|
|
18
|
+
wait?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface SetupSandboxOptions extends MonitorOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Whether to wait for setup to complete before returning.
|
|
23
|
+
* If true, monitors the operation until completion.
|
|
24
|
+
* Default: true
|
|
25
|
+
*/
|
|
26
|
+
wait?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* High-level helpers for sandbox operations that combine API calls
|
|
30
|
+
* with operation monitoring.
|
|
31
|
+
*/
|
|
32
|
+
export declare class SandboxHelpers {
|
|
33
|
+
private readonly client;
|
|
34
|
+
private monitor;
|
|
35
|
+
constructor(client: ApiClient);
|
|
36
|
+
/**
|
|
37
|
+
* Create a sandbox and optionally wait for it to be ready.
|
|
38
|
+
*
|
|
39
|
+
* This is a convenience wrapper that:
|
|
40
|
+
* 1. Calls createSandbox API
|
|
41
|
+
* 2. If wait=true (default), monitors the operation until completion
|
|
42
|
+
* 3. Returns the sandbox info
|
|
43
|
+
*
|
|
44
|
+
* @param request - Sandbox creation request
|
|
45
|
+
* @param options - Creation and monitoring options
|
|
46
|
+
* @returns Sandbox information
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const helpers = new SandboxHelpers(client);
|
|
51
|
+
*
|
|
52
|
+
* // Create and wait for ready (default)
|
|
53
|
+
* const sandbox = await helpers.createSandbox({
|
|
54
|
+
* dataset: "base",
|
|
55
|
+
* plato_dataset_config: config
|
|
56
|
+
* }, {
|
|
57
|
+
* onProgress: (msg) => console.log(msg)
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* // Create without waiting
|
|
61
|
+
* const sandbox = await helpers.createSandbox({
|
|
62
|
+
* dataset: "base",
|
|
63
|
+
* plato_dataset_config: config
|
|
64
|
+
* }, { wait: false });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
createSandbox(request: Api.CreateSandboxRequest, options?: CreateSandboxOptions): Promise<Api.CreateSandboxResponse>;
|
|
68
|
+
/**
|
|
69
|
+
* Setup a sandbox and optionally wait for completion.
|
|
70
|
+
*
|
|
71
|
+
* This is a convenience wrapper that:
|
|
72
|
+
* 1. Calls setupSandbox API
|
|
73
|
+
* 2. If wait=true (default), monitors the operation until completion
|
|
74
|
+
* 3. Returns the correlation ID
|
|
75
|
+
*
|
|
76
|
+
* @param jobId - Job ID of the sandbox
|
|
77
|
+
* @param request - Setup request with dataset config and optional SSH key
|
|
78
|
+
* @param options - Setup and monitoring options
|
|
79
|
+
* @returns Setup response with correlation ID
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const helpers = new SandboxHelpers(client);
|
|
84
|
+
*
|
|
85
|
+
* await helpers.setupSandbox("job_123", {
|
|
86
|
+
* dataset: "base",
|
|
87
|
+
* plato_dataset_config: config,
|
|
88
|
+
* ssh_public_key: publicKey
|
|
89
|
+
* }, {
|
|
90
|
+
* onProgress: (msg) => console.log(msg)
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
setupSandbox(jobId: string, request: Api.SetupSandboxRequest, options?: SetupSandboxOptions): Promise<Api.SetupSandboxResponse>;
|
|
95
|
+
/**
|
|
96
|
+
* Create a snapshot and optionally wait for completion.
|
|
97
|
+
*
|
|
98
|
+
* @param publicId - Public ID of the sandbox
|
|
99
|
+
* @param request - Snapshot request
|
|
100
|
+
* @param options - Monitoring options
|
|
101
|
+
* @returns Snapshot response
|
|
102
|
+
*/
|
|
103
|
+
createSnapshot(publicId: string, request: Api.CreateSnapshotRequest, options?: MonitorOptions): Promise<Api.CreateSnapshotResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* Start a Plato worker and optionally wait for completion.
|
|
106
|
+
*
|
|
107
|
+
* @param publicId - Public ID of the sandbox
|
|
108
|
+
* @param request - Worker start request
|
|
109
|
+
* @param options - Monitoring options
|
|
110
|
+
* @returns Worker start response
|
|
111
|
+
*/
|
|
112
|
+
startWorker(publicId: string, request: Api.StartWorkerRequest, options?: MonitorOptions): Promise<Api.StartWorkerResponse>;
|
|
113
|
+
/**
|
|
114
|
+
* Setup root access and optionally wait for completion.
|
|
115
|
+
*
|
|
116
|
+
* @param publicId - Public ID of the sandbox
|
|
117
|
+
* @param request - Root access setup request
|
|
118
|
+
* @param options - Monitoring options
|
|
119
|
+
* @returns Setup response
|
|
120
|
+
*/
|
|
121
|
+
setupRootAccess(publicId: string, request: Api.SetupRootAccessRequest, options?: MonitorOptions): Promise<Api.SetupRootAccessResponse>;
|
|
122
|
+
/**
|
|
123
|
+
* Get the underlying monitor for advanced use cases.
|
|
124
|
+
*/
|
|
125
|
+
getMonitor(): SandboxMonitor;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=SandboxHelpers.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper utilities for monitoring sandbox operations.
|
|
3
|
+
*
|
|
4
|
+
* This file is NOT generated by Fern and contains custom business logic
|
|
5
|
+
* for handling SSE streams from the Plato API.
|
|
6
|
+
*
|
|
7
|
+
* Based on the Go implementation in sdk/services/sandbox.go
|
|
8
|
+
*/
|
|
9
|
+
import type { ApiClient } from "../Client.js";
|
|
10
|
+
import type { OperationEvent } from "../api/types/OperationEvent.js";
|
|
11
|
+
export interface MonitorOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Timeout in milliseconds for the entire operation.
|
|
14
|
+
* Default: 600000 (10 minutes)
|
|
15
|
+
*/
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Callback for progress updates
|
|
19
|
+
*/
|
|
20
|
+
onProgress?: (message: string) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Abort signal to cancel the operation
|
|
23
|
+
*/
|
|
24
|
+
abortSignal?: AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
export declare class SandboxOperationError extends Error {
|
|
27
|
+
readonly event?: OperationEvent;
|
|
28
|
+
constructor(message: string, event?: OperationEvent);
|
|
29
|
+
}
|
|
30
|
+
export declare class SandboxMonitor {
|
|
31
|
+
private readonly client;
|
|
32
|
+
constructor(client: ApiClient);
|
|
33
|
+
/**
|
|
34
|
+
* Monitor a sandbox operation until completion.
|
|
35
|
+
*
|
|
36
|
+
* This implements the business logic from the Go SDK (sandbox.go):
|
|
37
|
+
* - Waits for terminal events (run_result, ssh_result, error)
|
|
38
|
+
* - Reports progress via callback
|
|
39
|
+
* - Throws on failure
|
|
40
|
+
* - Returns on success
|
|
41
|
+
*
|
|
42
|
+
* @param correlationId - Correlation ID from sandbox creation or setup
|
|
43
|
+
* @param options - Monitoring options
|
|
44
|
+
* @throws {SandboxOperationError} If the operation fails
|
|
45
|
+
* @throws {Error} If the stream ends unexpectedly
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const monitor = new SandboxMonitor(client);
|
|
50
|
+
* const sandbox = await client.createSandbox({ ... });
|
|
51
|
+
*
|
|
52
|
+
* // Wait for sandbox to be ready
|
|
53
|
+
* await monitor.waitForCompletion(sandbox.correlation_id, {
|
|
54
|
+
* onProgress: (msg) => console.log('Progress:', msg)
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
waitForCompletion(correlationId: string, options?: MonitorOptions): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Monitor operation and collect all events.
|
|
61
|
+
* Useful for debugging or detailed progress tracking.
|
|
62
|
+
*
|
|
63
|
+
* @param correlationId - Correlation ID from sandbox creation or setup
|
|
64
|
+
* @param options - Monitoring options
|
|
65
|
+
* @returns Array of all events received
|
|
66
|
+
* @throws {SandboxOperationError} If the operation fails
|
|
67
|
+
*/
|
|
68
|
+
waitForCompletionWithEvents(correlationId: string, options?: MonitorOptions): Promise<OperationEvent[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Handle a single operation event and determine if operation should terminate.
|
|
71
|
+
*
|
|
72
|
+
* This implements the state machine from sandbox.go MonitorOperation():
|
|
73
|
+
* - connected: Continue listening
|
|
74
|
+
* - progress: Report progress, continue listening
|
|
75
|
+
* - run_result/ssh_result: Terminal event, check success
|
|
76
|
+
* - error: Terminal event, always failure
|
|
77
|
+
*
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
private handleEvent;
|
|
81
|
+
/**
|
|
82
|
+
* Combine multiple abort signals into one.
|
|
83
|
+
* If any signal aborts, the combined signal aborts.
|
|
84
|
+
*
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
private combineAbortSignals;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=SandboxMonitor.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom helpers for the Plato SDK.
|
|
3
|
+
*
|
|
4
|
+
* These utilities are NOT generated by Fern and provide high-level
|
|
5
|
+
* convenience functions built on top of the generated API client.
|
|
6
|
+
*/
|
|
7
|
+
export { SandboxMonitor, SandboxOperationError, type MonitorOptions } from "./SandboxMonitor.js";
|
|
8
|
+
export { SandboxHelpers, type CreateSandboxOptions, type SetupSandboxOptions } from "./SandboxHelpers.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * as Api from "./api/index.js";
|
|
2
|
+
export type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.js";
|
|
3
|
+
export { ApiClient } from "./Client.js";
|
|
4
|
+
export { ApiError, ApiTimeoutError } from "./errors/index.js";
|
|
5
|
+
export * from "./helpers/index.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import type * as core from "../core/index.js";
|
|
4
|
+
import { toJson } from "../core/json.js";
|
|
5
|
+
|
|
6
|
+
export class ApiError extends Error {
|
|
7
|
+
public readonly statusCode?: number;
|
|
8
|
+
public readonly body?: unknown;
|
|
9
|
+
public readonly rawResponse?: core.RawResponse;
|
|
10
|
+
|
|
11
|
+
constructor({
|
|
12
|
+
message,
|
|
13
|
+
statusCode,
|
|
14
|
+
body,
|
|
15
|
+
rawResponse,
|
|
16
|
+
}: {
|
|
17
|
+
message?: string;
|
|
18
|
+
statusCode?: number;
|
|
19
|
+
body?: unknown;
|
|
20
|
+
rawResponse?: core.RawResponse;
|
|
21
|
+
}) {
|
|
22
|
+
super(buildMessage({ message, statusCode, body }));
|
|
23
|
+
Object.setPrototypeOf(this, ApiError.prototype);
|
|
24
|
+
this.statusCode = statusCode;
|
|
25
|
+
this.body = body;
|
|
26
|
+
this.rawResponse = rawResponse;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function buildMessage({
|
|
31
|
+
message,
|
|
32
|
+
statusCode,
|
|
33
|
+
body,
|
|
34
|
+
}: {
|
|
35
|
+
message: string | undefined;
|
|
36
|
+
statusCode: number | undefined;
|
|
37
|
+
body: unknown | undefined;
|
|
38
|
+
}): string {
|
|
39
|
+
const lines: string[] = [];
|
|
40
|
+
if (message != null) {
|
|
41
|
+
lines.push(message);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (statusCode != null) {
|
|
45
|
+
lines.push(`Status code: ${statusCode.toString()}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (body != null) {
|
|
49
|
+
lines.push(`Body: ${toJson(body, undefined, 2)}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return lines.join("\n");
|
|
53
|
+
}
|
package/errors/index.ts
ADDED