@tangle-network/sandbox 0.10.2 → 0.10.3
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/LICENSE +11 -0
- package/dist/agent/index.d.ts +3 -2
- package/dist/auth/index.d.ts +1 -1
- package/dist/{client-8wOu9raV.d.ts → client-Cr39zlgv.d.ts} +2 -1
- package/dist/{client-B3oM6E-L.js → client-Df1K1d_Q.js} +1 -1
- package/dist/collaboration/index.d.ts +1 -1
- package/dist/collaboration/index.js +1 -1
- package/dist/core.d.ts +4 -3
- package/dist/core.js +2 -2
- package/dist/{index-DS4SOkKG.d.ts → index-DzEUjav-.d.ts} +2 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +5 -4
- package/dist/runtime-api-CYA2DUQw.js +434 -0
- package/dist/runtime.d.ts +62 -0
- package/dist/runtime.js +81 -0
- package/dist/sandbox-BhYmj7L3.d.ts +1489 -0
- package/dist/{sandbox-CeimsfC8.js → sandbox-CxBHIBV1.js} +3 -393
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-DayyZe-i.js → tangle-BdRRHMpX.js} +1 -1
- package/dist/{sandbox-Bm2C9Phd.d.ts → types-Cmpv-ox_.d.ts} +6 -1491
- package/package.json +44 -80
- /package/dist/{collaboration-D17lnOJX.js → collaboration-QZXrXdIb.js} +0 -0
- /package/dist/{errors-H9268M_g.d.ts → errors--P_nbLzM.d.ts} +0 -0
- /package/dist/{index-D-2pH_70.d.ts → index-CyHojkuA.d.ts} +0 -0
- /package/dist/{index-D7bwmNs8.d.ts → index-DKzapw-9.d.ts} +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { A as CommitTaskSessionOptions, B as CreateTaskSessionOptions, Cr as SandboxTerminalInfo, Gr as SessionMessage, Kt as ListMessagesOptions, Lr as SendSessionMessageOptions, Rr as SendSessionMessageRequest, Si as WriteFileOptions, Sr as SandboxTerminalCreateOptions, Tr as SandboxTerminalRequestOptions, Ur as SessionInfo, ai as TaskSessionCommitResult, br as SandboxRuntimeProfileList, dt as FileWriteResult, ii as TaskSessionChanges, it as FileReadBatchResult, lt as FileTreeOptions, pr as SandboxPortBinding, rt as FileReadBatchOptions, si as TaskSessionInfo, ut as FileTreeResult, vr as SandboxRuntimeHealth, wr as SandboxTerminalManager, z as CreateSessionOptions, zr as SentSessionMessage } from "./types-Cmpv-ox_.js";
|
|
2
|
+
import { a as NotFoundError, c as SandboxError, d as ServerError, f as StateError, i as NetworkError, l as SandboxErrorJson, m as ValidationError, n as CapabilityError, o as PartialFailureError, p as TimeoutError, s as QuotaError, t as AuthError, u as SandboxFailureDetail } from "./errors--P_nbLzM.js";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime-api.d.ts
|
|
5
|
+
interface RuntimeTransport {
|
|
6
|
+
ensureRunning(): Promise<void>;
|
|
7
|
+
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
8
|
+
}
|
|
9
|
+
/** Internal typed client for routes served by a sandbox runtime. */
|
|
10
|
+
declare class SandboxRuntimeApi {
|
|
11
|
+
private readonly transport;
|
|
12
|
+
readonly terminals: SandboxTerminalManager;
|
|
13
|
+
constructor(transport: RuntimeTransport);
|
|
14
|
+
health(): Promise<SandboxRuntimeHealth>;
|
|
15
|
+
ports(): Promise<SandboxPortBinding[]>;
|
|
16
|
+
profiles(): Promise<SandboxRuntimeProfileList>;
|
|
17
|
+
readFiles(paths: string[], options?: FileReadBatchOptions): Promise<FileReadBatchResult>;
|
|
18
|
+
writeFile(path: string, content: string, options?: WriteFileOptions): Promise<FileWriteResult>;
|
|
19
|
+
deleteFile(path: string, options?: Pick<WriteFileOptions, "sessionId">): Promise<void>;
|
|
20
|
+
fileTree(path: string, options?: FileTreeOptions): Promise<FileTreeResult>;
|
|
21
|
+
createSession(options: CreateSessionOptions): Promise<SessionInfo>;
|
|
22
|
+
messages(id: string, options?: Omit<ListMessagesOptions, "sessionId">): Promise<SessionMessage[]>;
|
|
23
|
+
createTaskSession(options: CreateTaskSessionOptions): Promise<TaskSessionInfo>;
|
|
24
|
+
sendSessionMessage(id: string, request: SendSessionMessageRequest, options?: SendSessionMessageOptions): Promise<SentSessionMessage>;
|
|
25
|
+
deleteSession(id: string): Promise<void>;
|
|
26
|
+
taskSessionChanges(id: string): Promise<TaskSessionChanges>;
|
|
27
|
+
commitTaskSession(id: string, options?: CommitTaskSessionOptions): Promise<TaskSessionCommitResult>;
|
|
28
|
+
private createTerminal;
|
|
29
|
+
private writeTerminal;
|
|
30
|
+
private listTerminals;
|
|
31
|
+
private getTerminal;
|
|
32
|
+
private json;
|
|
33
|
+
private request;
|
|
34
|
+
private assertOk;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/runtime-client.d.ts
|
|
38
|
+
interface SandboxRuntimeClientConfig {
|
|
39
|
+
/** Browser-safe proxy base returned by `box.mintScopedToken()`. */
|
|
40
|
+
baseUrl: string;
|
|
41
|
+
/** Short-lived scoped token returned by `box.mintScopedToken()`. */
|
|
42
|
+
token: string;
|
|
43
|
+
/** Request timeout in milliseconds. Defaults to 30 seconds. */
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
/** Fetch implementation override for Workers, tests, or custom runtimes. */
|
|
46
|
+
fetch?: typeof globalThis.fetch;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Browser- and Worker-safe client for one sandbox runtime.
|
|
50
|
+
*
|
|
51
|
+
* Construct it from the scoped token response returned by
|
|
52
|
+
* `box.mintScopedToken()`. The full Sandbox API key remains server-side.
|
|
53
|
+
*/
|
|
54
|
+
declare class SandboxRuntimeClient extends SandboxRuntimeApi {
|
|
55
|
+
private readonly auth;
|
|
56
|
+
constructor(config: SandboxRuntimeClientConfig);
|
|
57
|
+
/** Replace an expiring scoped token without rebuilding consumers. */
|
|
58
|
+
updateToken(token: string): void;
|
|
59
|
+
}
|
|
60
|
+
declare function createSandboxRuntimeClient(config: SandboxRuntimeClientConfig): SandboxRuntimeClient;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { AuthError, CapabilityError, type FileReadBatchOptions, type FileReadBatchResult, type FileTreeOptions, type FileTreeResult, type FileWriteResult, type ListMessagesOptions, NetworkError, NotFoundError, PartialFailureError, QuotaError, SandboxError, type SandboxErrorJson, type SandboxFailureDetail, SandboxRuntimeClient, type SandboxRuntimeClientConfig, type SandboxRuntimeHealth, type SandboxTerminalCreateOptions, type SandboxTerminalInfo, type SandboxTerminalManager, type SandboxTerminalRequestOptions, ServerError, type SessionMessage, StateError, TimeoutError, ValidationError, type WriteFileOptions, createSandboxRuntimeClient };
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { t as SandboxRuntimeApi } from "./runtime-api-CYA2DUQw.js";
|
|
2
|
+
import { a as NotFoundError, c as SandboxError, d as TimeoutError, f as ValidationError, i as NetworkError, l as ServerError, n as CapabilityError, o as PartialFailureError, s as QuotaError, t as AuthError, u as StateError } from "./errors-DSz87Rkk.js";
|
|
3
|
+
//#region src/runtime-client.ts
|
|
4
|
+
const DEFAULT_RUNTIME_TIMEOUT_MS = 3e4;
|
|
5
|
+
function requireToken(token) {
|
|
6
|
+
const value = token.trim();
|
|
7
|
+
if (!value) throw new ValidationError("Scoped runtime token is required");
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
function requireBaseUrl(baseUrl) {
|
|
11
|
+
let url;
|
|
12
|
+
try {
|
|
13
|
+
url = new URL(baseUrl);
|
|
14
|
+
} catch {
|
|
15
|
+
throw new ValidationError("Scoped runtime base URL must be absolute");
|
|
16
|
+
}
|
|
17
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") throw new ValidationError("Scoped runtime base URL must use HTTP or HTTPS");
|
|
18
|
+
if (url.username || url.password) throw new ValidationError("Scoped runtime base URL must not include credentials");
|
|
19
|
+
if (url.search || url.hash) throw new ValidationError("Scoped runtime base URL must not include a query or fragment");
|
|
20
|
+
return url.toString().replace(/\/+$/, "");
|
|
21
|
+
}
|
|
22
|
+
function requireTimeout(timeoutMs) {
|
|
23
|
+
const value = timeoutMs ?? DEFAULT_RUNTIME_TIMEOUT_MS;
|
|
24
|
+
if (!Number.isFinite(value) || value <= 0) throw new ValidationError("Scoped runtime timeout must be positive");
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Browser- and Worker-safe client for one sandbox runtime.
|
|
29
|
+
*
|
|
30
|
+
* Construct it from the scoped token response returned by
|
|
31
|
+
* `box.mintScopedToken()`. The full Sandbox API key remains server-side.
|
|
32
|
+
*/
|
|
33
|
+
var SandboxRuntimeClient = class extends SandboxRuntimeApi {
|
|
34
|
+
auth;
|
|
35
|
+
constructor(config) {
|
|
36
|
+
const baseUrl = requireBaseUrl(config.baseUrl);
|
|
37
|
+
const auth = { token: requireToken(config.token) };
|
|
38
|
+
const timeoutMs = requireTimeout(config.timeoutMs);
|
|
39
|
+
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
40
|
+
if (typeof fetchImpl !== "function") throw new ValidationError("Scoped runtime client requires a fetch implementation");
|
|
41
|
+
super({
|
|
42
|
+
ensureRunning: async () => void 0,
|
|
43
|
+
fetch: async (path, init = {}) => {
|
|
44
|
+
if (!path.startsWith("/") || path.startsWith("//")) throw new ValidationError("Scoped runtime request paths must start with one slash");
|
|
45
|
+
const headers = new Headers(init.headers);
|
|
46
|
+
headers.set("Authorization", `Bearer ${auth.token}`);
|
|
47
|
+
const isFormData = typeof FormData !== "undefined" && init.body instanceof FormData;
|
|
48
|
+
if (init.body !== void 0 && !isFormData && !headers.has("Content-Type")) headers.set("Content-Type", "application/json");
|
|
49
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
50
|
+
const signal = init.signal ? AbortSignal.any([init.signal, timeoutSignal]) : timeoutSignal;
|
|
51
|
+
try {
|
|
52
|
+
return await fetchImpl(`${baseUrl}${path}`, {
|
|
53
|
+
...init,
|
|
54
|
+
headers,
|
|
55
|
+
signal
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (timeoutSignal.aborted && !init.signal?.aborted) throw new TimeoutError(timeoutMs, void 0, {
|
|
59
|
+
origin: "runtime",
|
|
60
|
+
endpoint: path
|
|
61
|
+
});
|
|
62
|
+
if (init.signal?.aborted) throw error;
|
|
63
|
+
throw new NetworkError(`Scoped runtime request failed: ${path}`, error instanceof Error ? error : new Error(String(error)), {
|
|
64
|
+
origin: "runtime",
|
|
65
|
+
endpoint: path
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this.auth = auth;
|
|
71
|
+
}
|
|
72
|
+
/** Replace an expiring scoped token without rebuilding consumers. */
|
|
73
|
+
updateToken(token) {
|
|
74
|
+
this.auth.token = requireToken(token);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
function createSandboxRuntimeClient(config) {
|
|
78
|
+
return new SandboxRuntimeClient(config);
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
export { AuthError, CapabilityError, NetworkError, NotFoundError, PartialFailureError, QuotaError, SandboxError, SandboxRuntimeClient, ServerError, StateError, TimeoutError, ValidationError, createSandboxRuntimeClient };
|