@opencoredev/sandbox-sdk 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -11
- package/README.md +357 -25
- package/dist/ai.d.ts +5 -0
- package/dist/ai.js +1 -0
- package/dist/chunk-23tjmd39.js +8 -0
- package/dist/chunk-2ts3evzh.js +2 -0
- package/dist/chunk-83avbjns.js +2 -0
- package/dist/chunk-8786zrns.js +2 -0
- package/dist/chunk-8wq767xb.js +17 -0
- package/dist/chunk-9w9rddra.js +2 -0
- package/dist/chunk-bd481sb7.js +2 -0
- package/dist/chunk-ckym4cht.js +23 -0
- package/dist/chunk-gw3n7sx7.js +5 -0
- package/dist/chunk-hgrwyjrb.js +2 -0
- package/dist/chunk-hzbssbep.js +31 -0
- package/dist/chunk-k60b4r27.js +2 -0
- package/dist/chunk-kk1hw8wa.js +1 -0
- package/dist/chunk-nw845a93.js +27 -0
- package/dist/chunk-q5vqajhg.js +2 -0
- package/dist/chunk-vy1j4r8f.js +2 -0
- package/dist/chunk-x681p5d2.js +68 -0
- package/dist/chunk-xgxfy2n8.js +4 -0
- package/dist/core/process-records.d.ts +25 -0
- package/dist/errors.d.ts +126 -0
- package/dist/files.d.ts +64 -0
- package/dist/git.d.ts +28 -0
- package/dist/handle.d.ts +4 -0
- package/dist/http.d.ts +225 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +1 -0
- package/dist/keys.d.ts +10 -0
- package/dist/logs.d.ts +8 -0
- package/dist/mastra.d.ts +43 -0
- package/dist/mastra.js +1 -0
- package/dist/memory.d.ts +37 -0
- package/dist/memory.js +13 -0
- package/dist/native.d.ts +127 -0
- package/dist/openai.d.ts +39 -0
- package/dist/openai.js +1 -0
- package/dist/peer.d.ts +14 -0
- package/dist/processes.d.ts +71 -0
- package/dist/provider.d.ts +171 -0
- package/dist/provider.js +1 -0
- package/dist/providers/agentos/errors.d.ts +5 -0
- package/dist/providers/agentos/index.d.ts +4 -0
- package/dist/providers/agentos/index.js +2 -0
- package/dist/providers/agentos/provider.d.ts +50 -0
- package/dist/providers/boat/index.d.ts +66 -0
- package/dist/providers/boat/index.js +1 -0
- package/dist/providers/boat-api/errors.d.ts +6 -0
- package/dist/providers/boat-api/exec.d.ts +24 -0
- package/dist/providers/boat-api/follow.d.ts +24 -0
- package/dist/providers/boat-api/index.d.ts +60 -0
- package/dist/providers/boat-api/transport.d.ts +77 -0
- package/dist/providers/boxd/errors.d.ts +3 -0
- package/dist/providers/boxd/execute.d.ts +3 -0
- package/dist/providers/boxd/index.d.ts +3 -0
- package/dist/providers/boxd/index.js +105 -0
- package/dist/providers/boxd/provider.d.ts +74 -0
- package/dist/providers/boxd/transfers.d.ts +28 -0
- package/dist/providers/daytona/api.d.ts +124 -0
- package/dist/providers/daytona/buffered.d.ts +3 -0
- package/dist/providers/daytona/errors.d.ts +19 -0
- package/dist/providers/daytona/exec.d.ts +14 -0
- package/dist/providers/daytona/index.d.ts +73 -0
- package/dist/providers/daytona/index.js +96 -0
- package/dist/providers/daytona/multipart.d.ts +25 -0
- package/dist/providers/e2b/envd.d.ts +113 -0
- package/dist/providers/e2b/errors.d.ts +20 -0
- package/dist/providers/e2b/index.d.ts +53 -0
- package/dist/providers/e2b/index.js +1 -0
- package/dist/providers/freestyle/client.d.ts +87 -0
- package/dist/providers/freestyle/deadline.d.ts +5 -0
- package/dist/providers/freestyle/errors.d.ts +29 -0
- package/dist/providers/freestyle/execute.d.ts +8 -0
- package/dist/providers/freestyle/index.d.ts +40 -0
- package/dist/providers/freestyle/index.js +105 -0
- package/dist/providers/local/docker.d.ts +36 -0
- package/dist/providers/local/index.d.ts +46 -0
- package/dist/providers/local/index.js +2 -0
- package/dist/providers/railway/errors.d.ts +10 -0
- package/dist/providers/railway/index.d.ts +3 -0
- package/dist/providers/railway/index.js +1 -0
- package/dist/providers/railway/provider.d.ts +53 -0
- package/dist/providers/sandboxer/index.d.ts +40 -0
- package/dist/providers/sandboxer/index.js +1 -0
- package/dist/providers/superserve/bootstrap.d.ts +11 -0
- package/dist/providers/superserve/errors.d.ts +3 -0
- package/dist/providers/superserve/execute.d.ts +8 -0
- package/dist/providers/superserve/index.d.ts +52 -0
- package/dist/providers/superserve/index.js +94 -0
- package/dist/providers/superserve/routes.d.ts +80 -0
- package/dist/providers/superserve/session.d.ts +33 -0
- package/dist/providers/tenki/deadline.d.ts +2 -0
- package/dist/providers/tenki/errors.d.ts +10 -0
- package/dist/providers/tenki/exec.d.ts +4 -0
- package/dist/providers/tenki/files.d.ts +3 -0
- package/dist/providers/tenki/index.d.ts +3 -0
- package/dist/providers/tenki/index.js +175 -0
- package/dist/providers/tenki/provider.d.ts +95 -0
- package/dist/providers/tenki/ready.d.ts +7 -0
- package/dist/providers/tenki/records.d.ts +16 -0
- package/dist/providers/tenki/stream.d.ts +3 -0
- package/dist/providers/upstash/buffered.d.ts +3 -0
- package/dist/providers/upstash/errors.d.ts +3 -0
- package/dist/providers/upstash/exec.d.ts +18 -0
- package/dist/providers/upstash/files.d.ts +15 -0
- package/dist/providers/upstash/index.d.ts +6 -0
- package/dist/providers/upstash/index.js +105 -0
- package/dist/providers/upstash/provider.d.ts +81 -0
- package/dist/providers/vercel/errors.d.ts +5 -0
- package/dist/providers/vercel/index.d.ts +22 -0
- package/dist/providers/vercel/index.js +1 -0
- package/dist/providers/vercel/provider.d.ts +58 -0
- package/dist/providers/vercel/transport.d.ts +43 -0
- package/dist/run.d.ts +43 -0
- package/dist/shared/deadline.d.ts +12 -0
- package/dist/shared/guest.d.ts +18 -0
- package/dist/shared/json.d.ts +11 -0
- package/dist/shared/metadata.d.ts +19 -0
- package/dist/shared/narrow.d.ts +8 -0
- package/dist/shared/native-error.d.ts +42 -0
- package/dist/shared/paged-exec.d.ts +22 -0
- package/dist/shared/shell.d.ts +2 -0
- package/dist/shared/wire.d.ts +10 -0
- package/dist/shell/process-records.d.ts +44 -0
- package/dist/streams.d.ts +72 -0
- package/dist/testing.d.ts +27 -0
- package/dist/testing.js +9 -0
- package/dist/tool-security.d.ts +9 -0
- package/dist/tools.d.ts +118 -0
- package/dist/tools.js +1 -0
- package/dist/types.d.ts +197 -0
- package/package.json +143 -102
- package/dist/agentos-CbrZW7R0.mjs +0 -390
- package/dist/agentos-CbrZW7R0.mjs.map +0 -1
- package/dist/ai/harness.d.mts +0 -16
- package/dist/ai/harness.mjs +0 -69
- package/dist/ai/harness.mjs.map +0 -1
- package/dist/ai/index.d.mts +0 -54
- package/dist/ai/index.mjs +0 -4
- package/dist/ai-DeFa8yPk.mjs +0 -243
- package/dist/ai-DeFa8yPk.mjs.map +0 -1
- package/dist/capabilities-BWvOVFbH.d.mts +0 -15
- package/dist/capabilities-CaSNd6J1.mjs +0 -125
- package/dist/capabilities-CaSNd6J1.mjs.map +0 -1
- package/dist/capabilities-xs9kaHrK.mjs +0 -28
- package/dist/capabilities-xs9kaHrK.mjs.map +0 -1
- package/dist/errors-BuF9bYOQ.mjs +0 -68
- package/dist/errors-BuF9bYOQ.mjs.map +0 -1
- package/dist/eve/index.d.mts +0 -19
- package/dist/eve/index.mjs +0 -155
- package/dist/eve/index.mjs.map +0 -1
- package/dist/index-CkTwqD0X.d.mts +0 -25
- package/dist/index-Dh9xob2s.d.mts +0 -31
- package/dist/index.d.mts +0 -5
- package/dist/index.mjs +0 -40
- package/dist/index.mjs.map +0 -1
- package/dist/managed-provider-BsZGVQ4I.mjs +0 -148
- package/dist/managed-provider-BsZGVQ4I.mjs.map +0 -1
- package/dist/mastra/index.d.mts +0 -118
- package/dist/mastra/index.mjs +0 -662
- package/dist/mastra/index.mjs.map +0 -1
- package/dist/metadata.d.mts +0 -34
- package/dist/metadata.mjs +0 -135
- package/dist/metadata.mjs.map +0 -1
- package/dist/provider-DOBErkBO.d.mts +0 -91
- package/dist/provider-utils-CfB9nvJx.mjs +0 -57
- package/dist/provider-utils-CfB9nvJx.mjs.map +0 -1
- package/dist/providers/agentos/index.d.mts +0 -7
- package/dist/providers/agentos/index.mjs +0 -9
- package/dist/providers/box/index.d.mts +0 -34
- package/dist/providers/box/index.mjs +0 -348
- package/dist/providers/box/index.mjs.map +0 -1
- package/dist/providers/daytona/index.d.mts +0 -21
- package/dist/providers/daytona/index.mjs +0 -206
- package/dist/providers/daytona/index.mjs.map +0 -1
- package/dist/providers/e2b/index.d.mts +0 -17
- package/dist/providers/e2b/index.mjs +0 -169
- package/dist/providers/e2b/index.mjs.map +0 -1
- package/dist/providers/local/index.d.mts +0 -22
- package/dist/providers/local/index.mjs +0 -22
- package/dist/providers/local/index.mjs.map +0 -1
- package/dist/providers/railway/index.d.mts +0 -29
- package/dist/providers/railway/index.mjs +0 -211
- package/dist/providers/railway/index.mjs.map +0 -1
- package/dist/providers/upstash/index.d.mts +0 -17
- package/dist/providers/upstash/index.mjs +0 -211
- package/dist/providers/upstash/index.mjs.map +0 -1
- package/dist/providers/vercel/index.d.mts +0 -28
- package/dist/providers/vercel/index.mjs +0 -186
- package/dist/providers/vercel/index.mjs.map +0 -1
- package/dist/sandbox-DdEqoXJF.d.mts +0 -26
- package/dist/sandbox-DgtY5hvt.mjs +0 -112
- package/dist/sandbox-DgtY5hvt.mjs.map +0 -1
- package/dist/testing/index.d.mts +0 -27
- package/dist/testing/index.mjs +0 -173
- package/dist/testing/index.mjs.map +0 -1
- package/dist/types-Bv6I2U1c.d.mts +0 -103
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a {@link SandboxError} was thrown. A non-zero exit, a command timeout, or an
|
|
3
|
+
* aborted `run` is never an error; those resolve with `ok: false`.
|
|
4
|
+
*
|
|
5
|
+
* - `auth`: credentials are missing or rejected.
|
|
6
|
+
* - `not_found`: the sandbox or handle no longer exists, or the handle was closed.
|
|
7
|
+
* - `quota`: a provider limit or billing stopped the request. Usually retryable.
|
|
8
|
+
* - `unavailable`: the provider is down or unreachable. Usually retryable.
|
|
9
|
+
* - `unsupported`: the provider cannot do what was asked (size, network policy, lifetime).
|
|
10
|
+
* - `timeout`: a provider operation or a readiness check took too long.
|
|
11
|
+
* - `aborted`: your `AbortSignal` fired.
|
|
12
|
+
* - `outcome_unknown`: the request may or may not have happened.
|
|
13
|
+
* - `process_exited`: a background process exited before it was ready.
|
|
14
|
+
* - `port_not_ready`: a preview did not answer with a 2xx before `waitMs` ran out.
|
|
15
|
+
* - `edit_not_found` / `edit_not_unique`: `files.edit` matched zero or several times.
|
|
16
|
+
* - `file_not_found`: the path does not exist.
|
|
17
|
+
* - `invalid_argument`: the input is invalid. Retrying will not help.
|
|
18
|
+
* - `provider`: any other provider or adapter failure.
|
|
19
|
+
*/
|
|
20
|
+
export type ErrorCode = "auth" | "not_found" | "quota" | "unavailable" | "unsupported" | "timeout" | "aborted" | "outcome_unknown" | "process_exited" | "port_not_ready" | "edit_not_found" | "edit_not_unique" | "file_not_found" | "invalid_argument" | "provider";
|
|
21
|
+
/** Second argument to the {@link SandboxError} constructor. */
|
|
22
|
+
export interface ErrorOptions {
|
|
23
|
+
code: ErrorCode;
|
|
24
|
+
/** Provider name. Default: `"unknown"`. */
|
|
25
|
+
provider?: string;
|
|
26
|
+
sandboxId?: string;
|
|
27
|
+
/** Whether the same call can succeed on retry. Default: `false`. */
|
|
28
|
+
retryable?: boolean;
|
|
29
|
+
/** The next step, on its own. Default: a generic step for `code`. */
|
|
30
|
+
hint?: string;
|
|
31
|
+
cause?: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The only error type the SDK throws. Branch on `code` and `retryable`; show `hint` to users.
|
|
35
|
+
* Secrets registered with the sandbox are redacted from `message`, `hint`, and `cause`.
|
|
36
|
+
*/
|
|
37
|
+
export declare class SandboxError extends Error {
|
|
38
|
+
/** What kind of failure this is. */
|
|
39
|
+
readonly code: ErrorCode;
|
|
40
|
+
/** Whether the same call can succeed if you retry it. */
|
|
41
|
+
readonly retryable: boolean;
|
|
42
|
+
/** The next step, on its own, for logs and UIs. */
|
|
43
|
+
readonly hint: string;
|
|
44
|
+
/** Provider name, or `"unknown"`. */
|
|
45
|
+
readonly provider: string;
|
|
46
|
+
/** The sandbox involved, when there is one. */
|
|
47
|
+
readonly sandboxId?: string;
|
|
48
|
+
constructor(message: string, options: ErrorOptions);
|
|
49
|
+
}
|
|
50
|
+
/** @internal Whether an error says the path or the sandbox does not exist. */
|
|
51
|
+
export declare function isNotFound(error: unknown): error is SandboxError & {
|
|
52
|
+
code: "file_not_found" | "not_found";
|
|
53
|
+
};
|
|
54
|
+
/** @internal Redacts registered secrets from text and errors. */
|
|
55
|
+
export declare class Redactor {
|
|
56
|
+
private values;
|
|
57
|
+
add(values: Iterable<string>): void;
|
|
58
|
+
text(value: string): string;
|
|
59
|
+
get secrets(): string[];
|
|
60
|
+
get maxLength(): number;
|
|
61
|
+
/** Map any thrown value to a scrubbed SandboxError. */
|
|
62
|
+
error(cause: unknown, provider: string, sandboxId?: string): SandboxError;
|
|
63
|
+
}
|
|
64
|
+
/** @internal Removes credential-shaped text (URLs, auth headers, key=value secrets, control characters) and bounds the length. */
|
|
65
|
+
export declare function scrub(text: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* @internal `Name: message` of a native failure, redacted, scrubbed and bounded, with up to two nested causes.
|
|
68
|
+
* Undefined for thrown values that are not Errors, which carry no message to keep.
|
|
69
|
+
*/
|
|
70
|
+
export declare function nativeDetail(cause: unknown, redact?: (text: string) => string, depth?: number): string | undefined;
|
|
71
|
+
/** @internal What {@link describeNative} keeps: text for the message, and the error's cause. */
|
|
72
|
+
export interface NativeDescription {
|
|
73
|
+
detail?: string;
|
|
74
|
+
cause?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @internal What an adapter keeps from a native failure. Only a failure the adapter did not recognize
|
|
78
|
+
* (`code` is `provider`, unless `known` says otherwise) and that carries no `status` keeps its text:
|
|
79
|
+
* that is an SDK bug or a network error, and the text is the only clue. A recognized error type or a response may carry server text that
|
|
80
|
+
* echoes the request, so it keeps only its name and status. `detail` is the kept text, for the message;
|
|
81
|
+
* `cause` is the detail, or else the name and status.
|
|
82
|
+
*/
|
|
83
|
+
export declare function describeNative(cause: unknown, options: {
|
|
84
|
+
code: ErrorCode;
|
|
85
|
+
known?: boolean;
|
|
86
|
+
status?: string;
|
|
87
|
+
redact?: (text: string) => string;
|
|
88
|
+
}): NativeDescription;
|
|
89
|
+
/**
|
|
90
|
+
* @internal Bounded machine fields an adapter copies from a native failure, each already checked
|
|
91
|
+
* against an allowlist and the secrets it knows. Never a response's message, body, headers or URL;
|
|
92
|
+
* `native` is at most the scrubbed text {@link describeNative} keeps.
|
|
93
|
+
*/
|
|
94
|
+
export interface NativeEvidence {
|
|
95
|
+
operation?: string;
|
|
96
|
+
status?: number;
|
|
97
|
+
providerCode?: string | number;
|
|
98
|
+
requestId?: string;
|
|
99
|
+
source?: string;
|
|
100
|
+
nativeName?: string;
|
|
101
|
+
native?: string;
|
|
102
|
+
/** Tenki create: the session this call created, and how far it got. */
|
|
103
|
+
admittedByThisCall?: true;
|
|
104
|
+
stage?: string;
|
|
105
|
+
sandboxId?: string;
|
|
106
|
+
state?: string;
|
|
107
|
+
cleanupCode?: ErrorCode;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @internal The one form an adapter passes {@link NativeEvidence} to the core in: the `cause` of its
|
|
111
|
+
* SandboxError, an Error whose message is the fields as JSON. {@link Redactor.error} reduces every
|
|
112
|
+
* cause to its message, so the JSON is what reaches users; the fields stay readable on the adapter's
|
|
113
|
+
* own error.
|
|
114
|
+
*/
|
|
115
|
+
export declare function evidenceCause(evidence: NativeEvidence): Error & NativeEvidence;
|
|
116
|
+
/** @internal A redact function for values an adapter knows, such as its API key. Empty values are skipped. */
|
|
117
|
+
export declare function redacting(values: Iterable<string | undefined>): (text: string) => string;
|
|
118
|
+
/** @internal Why an adapter request failed, as a clause, never the code itself: the kept detail, or what `code` means. */
|
|
119
|
+
export declare function reason(code: ErrorCode, detail?: string): string;
|
|
120
|
+
/**
|
|
121
|
+
* @internal The shared HTTP status mapper. Provider hooks refine it (a 404 for a missing file, a stale route).
|
|
122
|
+
* A 504 is a timeout; the HTTP client turns it into `outcome_unknown` for a request that may have had an effect.
|
|
123
|
+
*/
|
|
124
|
+
export declare function statusCode(status: number): ErrorCode;
|
|
125
|
+
/** @internal Throws an `invalid_argument` SandboxError. */
|
|
126
|
+
export declare function invalid(message: string): never;
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Provider, FileInfo, WriteOptions } from "./provider.js";
|
|
2
|
+
import { SandboxError, type Redactor } from "./errors.js";
|
|
3
|
+
export interface FileEvent {
|
|
4
|
+
type: "added" | "modified" | "removed";
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FileDiff {
|
|
8
|
+
added: string[];
|
|
9
|
+
modified: string[];
|
|
10
|
+
removed: string[];
|
|
11
|
+
patch: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Files {
|
|
14
|
+
read(path: string): Promise<string>;
|
|
15
|
+
read(path: string, options: {
|
|
16
|
+
as: "bytes";
|
|
17
|
+
}): Promise<Uint8Array>;
|
|
18
|
+
write(path: string, data: string | Uint8Array, options?: WriteOptions): Promise<void>;
|
|
19
|
+
write(files: Record<string, string | Uint8Array>, options?: WriteOptions): Promise<void>;
|
|
20
|
+
edit(path: string, edit: {
|
|
21
|
+
find: string;
|
|
22
|
+
replace: string;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
list(path?: string, options?: {
|
|
25
|
+
recursive?: boolean;
|
|
26
|
+
glob?: string;
|
|
27
|
+
}): Promise<FileInfo[]>;
|
|
28
|
+
stat(path: string): Promise<FileInfo>;
|
|
29
|
+
exists(path: string): Promise<boolean>;
|
|
30
|
+
remove(path: string, options?: {
|
|
31
|
+
recursive?: boolean;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
upload(source: string, target: string, options?: {
|
|
34
|
+
ignore?: string[];
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
download(source: string, target: string): Promise<void>;
|
|
37
|
+
search(query: string, options?: {
|
|
38
|
+
path?: string;
|
|
39
|
+
glob?: string;
|
|
40
|
+
maxMatches?: number;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
path: string;
|
|
43
|
+
line: number;
|
|
44
|
+
text: string;
|
|
45
|
+
}[]>;
|
|
46
|
+
watch(path: string, callback: (event: FileEvent) => void, options?: {
|
|
47
|
+
recursive?: boolean;
|
|
48
|
+
intervalMs?: number;
|
|
49
|
+
onError?: (error: SandboxError) => void;
|
|
50
|
+
}): () => void;
|
|
51
|
+
mark(name?: string): Promise<string>;
|
|
52
|
+
changes(options?: {
|
|
53
|
+
since?: string;
|
|
54
|
+
}): Promise<FileDiff>;
|
|
55
|
+
}
|
|
56
|
+
/** @internal Remove a file; one that is already gone is not an error. Some adapters report
|
|
57
|
+
* a missing path as a generic provider error, so a stat confirms that case. */
|
|
58
|
+
export declare function removeIfPresent(files: Pick<Files, "remove" | "exists">, path: string): Promise<void>;
|
|
59
|
+
export declare function globMatch(path: string, glob: string): boolean;
|
|
60
|
+
/** @internal Read at most `maxBytes + 1` bytes when the adapter has ranged reads, so a caller can
|
|
61
|
+
* refuse an oversized file without downloading all of it. Without them, read the whole file. */
|
|
62
|
+
export declare function readAtMost(files: Files, path: string, maxBytes: number): Promise<Uint8Array<ArrayBufferLike>>;
|
|
63
|
+
/** `guard` throws synchronously when the handle is closed; `ready` resolves once the handle may touch the sandbox (secret recovery). */
|
|
64
|
+
export declare function makeFiles(provider: Provider, id: string, redactor: Redactor, guard?: () => void, ready?: () => Promise<void>): Files & Disposable;
|
package/dist/git.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RunHandle, RunOptions, RunResult } from "./types.js";
|
|
2
|
+
import { type Files } from "./files.js";
|
|
3
|
+
import type { Redactor } from "./errors.js";
|
|
4
|
+
export interface Git {
|
|
5
|
+
clone(url: string, options?: {
|
|
6
|
+
dir?: string;
|
|
7
|
+
branch?: string;
|
|
8
|
+
depth?: number;
|
|
9
|
+
token?: string;
|
|
10
|
+
}): Promise<RunResult>;
|
|
11
|
+
status(dir?: string): Promise<RunResult>;
|
|
12
|
+
diff(dir?: string): Promise<RunResult>;
|
|
13
|
+
commit(dir: string, options: {
|
|
14
|
+
message: string;
|
|
15
|
+
all?: boolean;
|
|
16
|
+
author?: string;
|
|
17
|
+
}): Promise<RunResult>;
|
|
18
|
+
push(dir: string, options?: {
|
|
19
|
+
token?: string;
|
|
20
|
+
remote?: string;
|
|
21
|
+
branch?: string;
|
|
22
|
+
}): Promise<RunResult>;
|
|
23
|
+
checkout(dir: string, options: {
|
|
24
|
+
branch: string;
|
|
25
|
+
create?: boolean;
|
|
26
|
+
}): Promise<RunResult>;
|
|
27
|
+
}
|
|
28
|
+
export declare function makeGit(run: (command: string, options?: RunOptions) => RunHandle, files: Files, redactor: Redactor): Git;
|
package/dist/handle.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Provider, SandboxInfo } from "./provider.js";
|
|
2
|
+
import type { CreateOptions, SandboxBase } from "./types.js";
|
|
3
|
+
import { Redactor } from "./errors.js";
|
|
4
|
+
export declare function makeHandle<N>(provider: Provider<N>, info: SandboxInfo, created: boolean, options: CreateOptions, redactor: Redactor, recoverSecrets?: boolean): Promise<SandboxBase<N>>;
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP client converted adapters and `box.native` share. One client per provider instance.
|
|
3
|
+
*
|
|
4
|
+
* - Planes: each provider API surface (control plane, Daytona's toolbox, Superserve's data plane) has a base
|
|
5
|
+
* URL, possibly per sandbox, and its own credentials. Credentials attach only to that plane's origin; an
|
|
6
|
+
* absolute URL or redirect elsewhere (signed upload URLs, poll URLs) gets none. That holds for credential
|
|
7
|
+
* headers a caller passes too (`authorization`, `cookie`, `*-token`, `*-key`, the plane's own auth headers).
|
|
8
|
+
* - Retries: at most `retries` more attempts on 429, 502, 503, 504 and network errors, only for GET, HEAD, PUT
|
|
9
|
+
* and DELETE, or a POST/PATCH that carries a server-supported idempotency key. Never with a streamed body.
|
|
10
|
+
* `Retry-After` is honoured up to 20 s and never past the deadline.
|
|
11
|
+
* - Outcomes: a POST or PATCH that fails after it may have reached the server (a network error once sent, a
|
|
12
|
+
* timeout, a 504) is `outcome_unknown`, not `unavailable`: the caller must check before repeating it.
|
|
13
|
+
* - Deadlines: `timeoutMs` (or a shared {@link Deadline}) covers credentials, every attempt, backoff and the
|
|
14
|
+
* body. Streams have a startup timeout (until headers) and an idle timeout (between chunks) instead.
|
|
15
|
+
* - Redaction: credential header values (the adapter's and the caller's, with and without a `Bearer` scheme),
|
|
16
|
+
* `secrets()` and credential-shaped text never reach a SandboxError.
|
|
17
|
+
* Response text is kept only for native calls (`detail: "message"`), scrubbed; adapter calls keep the
|
|
18
|
+
* status and the provider's error code.
|
|
19
|
+
*/
|
|
20
|
+
import { type JsonValue } from "./shared/json.js";
|
|
21
|
+
import { type ErrorCode } from "./errors.js";
|
|
22
|
+
import type { HttpMethod } from "./native.js";
|
|
23
|
+
/** Blocks inference from a position, like TypeScript 5.4's `NoInfer`, for consumers on older compilers. */
|
|
24
|
+
type NoInfer<T> = [T][T extends unknown ? 0 : never];
|
|
25
|
+
/** The subset of `fetch` the client calls. `globalThis.fetch` and test doubles both fit. */
|
|
26
|
+
export type Fetch = (input: string, init: RequestInit) => Promise<Response>;
|
|
27
|
+
/** What a plane's base URL and credential callbacks get. One call passes the same object to every callback. */
|
|
28
|
+
export interface PlaneContext {
|
|
29
|
+
/** The sandbox the request is for, when there is one. */
|
|
30
|
+
sandboxId?: string;
|
|
31
|
+
/** Fires when the request's deadline or the caller's signal does. */
|
|
32
|
+
signal: AbortSignal;
|
|
33
|
+
}
|
|
34
|
+
/** One API surface of a provider. */
|
|
35
|
+
export interface HttpPlane {
|
|
36
|
+
/**
|
|
37
|
+
* The base URL, including any path prefix (`https://app.daytona.io/api`). Paths are appended to it. A
|
|
38
|
+
* function can resolve it per sandbox, such as a regional proxy; cache inside it.
|
|
39
|
+
*/
|
|
40
|
+
baseUrl: string | ((context: PlaneContext) => string | Promise<string>);
|
|
41
|
+
/** Credential headers, read once per attempt so rotated tokens apply. Sent only to the base URL's origin. */
|
|
42
|
+
auth?: (context: PlaneContext) => Record<string, string> | Promise<Record<string, string>>;
|
|
43
|
+
/**
|
|
44
|
+
* Refresh the credentials `auth` returns. Called once after a 401 from this plane, shared between
|
|
45
|
+
* concurrent requests, and the request is sent again with fresh credentials. `context` is the first
|
|
46
|
+
* waiter's; a waiter whose signal fires stops waiting, so do not abort the shared work on `context.signal`.
|
|
47
|
+
*/
|
|
48
|
+
refresh?: (context: PlaneContext) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Which failed responses besides a 401 mean stale credentials or a stale route, such as a 404 whose error
|
|
51
|
+
* code says the route moved. Either verdict refreshes once. `"refused"` resends any request, like a 401;
|
|
52
|
+
* `"unsure"` resends only a request that may be retried, and an unconfirmed write is `outcome_unknown`.
|
|
53
|
+
* `credentials` are the headers `auth` returned for that attempt. Default: only a 401.
|
|
54
|
+
*/
|
|
55
|
+
stale?: (failure: {
|
|
56
|
+
status: number;
|
|
57
|
+
body: ErrorBody;
|
|
58
|
+
credentials: Readonly<Record<string, string>>;
|
|
59
|
+
}, context: PlaneContext) => StaleVerdict | undefined;
|
|
60
|
+
/** Headers for every request to this plane that are not credentials (`Accept`, API version pins). */
|
|
61
|
+
headers?: Record<string, string>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Why a response means stale credentials or a stale route. `"refused"`: the server turned the request away
|
|
65
|
+
* before running anything (a moved route, a stopped sandbox), so any request may be sent again. `"unsure"`:
|
|
66
|
+
* the request may have run before the failure.
|
|
67
|
+
*/
|
|
68
|
+
export type StaleVerdict = "refused" | "unsure";
|
|
69
|
+
/** What a provider error hook sees. `body` is bounded to 64 KB and must never be copied into messages. */
|
|
70
|
+
export type HttpFailure = {
|
|
71
|
+
kind: "status";
|
|
72
|
+
status: number;
|
|
73
|
+
headers: Headers;
|
|
74
|
+
body: ErrorBody;
|
|
75
|
+
} | {
|
|
76
|
+
kind: "network";
|
|
77
|
+
sent: boolean;
|
|
78
|
+
error: unknown;
|
|
79
|
+
} | {
|
|
80
|
+
kind: "timeout";
|
|
81
|
+
sent: boolean;
|
|
82
|
+
} | {
|
|
83
|
+
kind: "aborted";
|
|
84
|
+
};
|
|
85
|
+
/** A non-2xx response's body, as far as the client parsed it. */
|
|
86
|
+
export interface ErrorBody {
|
|
87
|
+
/** The first 64 KB of the body, decoded as UTF-8. */
|
|
88
|
+
text: string;
|
|
89
|
+
/** `text` parsed as JSON, or `undefined` when it is not JSON. */
|
|
90
|
+
json: JsonValue | undefined;
|
|
91
|
+
/** The provider's error code (`sandbox_not_found`), from `code`, `error.code`, `error` or `type`. */
|
|
92
|
+
code?: string;
|
|
93
|
+
/** The provider's error message, from `message`, `error.message`, `error`, `detail` or `title`. */
|
|
94
|
+
message?: string;
|
|
95
|
+
}
|
|
96
|
+
/** The request a hook classifies. */
|
|
97
|
+
export interface FailedRequest {
|
|
98
|
+
method: HttpMethod;
|
|
99
|
+
plane: string;
|
|
100
|
+
/** `METHOD /path/{template}`, without query strings or filled values. */
|
|
101
|
+
operation: string;
|
|
102
|
+
sandboxId?: string;
|
|
103
|
+
}
|
|
104
|
+
export interface HttpClientOptions<Plane extends string> {
|
|
105
|
+
/** Provider name on errors: `"daytona"`. */
|
|
106
|
+
provider: string;
|
|
107
|
+
/** Display name in messages: `"Daytona"`. */
|
|
108
|
+
label: string;
|
|
109
|
+
planes: Record<Plane, HttpPlane>;
|
|
110
|
+
/** The plane a request without `plane` uses. Plane names are inferred from `planes` only. */
|
|
111
|
+
defaultPlane: NoInfer<Plane>;
|
|
112
|
+
/** Default: `globalThis.fetch`, looked up per request so test stubs apply. */
|
|
113
|
+
fetch?: Fetch;
|
|
114
|
+
/** Default overall deadline per call, in ms. Default: 60000. */
|
|
115
|
+
timeoutMs?: number;
|
|
116
|
+
/** Extra attempts for retryable failures. Default: 2. */
|
|
117
|
+
retries?: number;
|
|
118
|
+
/** First backoff, doubled per attempt with jitter. Default: 250. */
|
|
119
|
+
backoffMs?: number;
|
|
120
|
+
/** Values to redact besides the credential headers, read on each error (API keys, tokens). */
|
|
121
|
+
secrets?: () => Iterable<string | undefined>;
|
|
122
|
+
/** Header that carries `idempotencyKey`. Leave it out when the key travels in the body. */
|
|
123
|
+
idempotencyHeader?: string;
|
|
124
|
+
/** Next step for `auth` errors: `"Set DAYTONA_API_KEY to a valid Daytona API key."` */
|
|
125
|
+
authHint?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Refine the shared status mapping, such as a 404 for a missing file (`file_not_found`) or a stale route.
|
|
128
|
+
* Return `undefined` to keep the default. Never put `failure.body` text in errors.
|
|
129
|
+
*/
|
|
130
|
+
mapError?: (failure: HttpFailure, request: FailedRequest) => ErrorCode | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Build the error's `cause` instead of the default `HTTP <status> (request <id>)` text, such as an Error with
|
|
133
|
+
* machine-readable evidence fields. Return `undefined` to keep the default. It is not redacted: copy only
|
|
134
|
+
* bounded, validated values, never `failure.body` text.
|
|
135
|
+
*/
|
|
136
|
+
cause?: (failure: HttpFailure, request: FailedRequest) => Error | undefined;
|
|
137
|
+
}
|
|
138
|
+
/** One request. */
|
|
139
|
+
export interface HttpRequest<Plane extends string = string> {
|
|
140
|
+
method: HttpMethod;
|
|
141
|
+
/** A path under the plane's base URL, with `{name}` placeholders, or an absolute `https:` URL. */
|
|
142
|
+
path: string;
|
|
143
|
+
plane?: Plane;
|
|
144
|
+
/** The sandbox this is for: passed to plane callbacks and put on errors. */
|
|
145
|
+
sandboxId?: string;
|
|
146
|
+
/** Values for every `{name}` placeholder in `path`, URI-encoded. Missing or unused names are `invalid_argument`. */
|
|
147
|
+
params?: Readonly<Record<string, string | number>>;
|
|
148
|
+
query?: Readonly<Record<string, string | number | boolean | undefined>>;
|
|
149
|
+
/** Sent as is when it is a `BodyInit` (string, bytes, Blob, FormData, URLSearchParams, ReadableStream), else as JSON. */
|
|
150
|
+
body?: unknown;
|
|
151
|
+
headers?: Readonly<Record<string, string>>;
|
|
152
|
+
signal?: AbortSignal;
|
|
153
|
+
/** Overall deadline for this call. Ignored when `deadline` is given. Default: the client's `timeoutMs`. */
|
|
154
|
+
timeoutMs?: number;
|
|
155
|
+
/** A deadline shared with other calls of the same operation (create then poll). */
|
|
156
|
+
deadline?: Deadline;
|
|
157
|
+
/** A server-supported idempotency key. It makes a POST or PATCH retryable; with `idempotencyHeader`, the client sends it. */
|
|
158
|
+
idempotencyKey?: string;
|
|
159
|
+
/** A POST or PATCH that changes nothing (a search). Failures after sending map like a GET's, not `outcome_unknown`. Still not retried. */
|
|
160
|
+
readOnly?: boolean;
|
|
161
|
+
/** `false` sends no credentials, even to the plane's origin (signed URLs). */
|
|
162
|
+
auth?: false;
|
|
163
|
+
/** Largest buffered response body in bytes. Default: 32 MiB. */
|
|
164
|
+
maxBytes?: number;
|
|
165
|
+
/** `"message"` keeps the provider's scrubbed error message in the error (native calls). Default: `"status"`. */
|
|
166
|
+
detail?: "status" | "message";
|
|
167
|
+
}
|
|
168
|
+
/** A stream request: the overall deadline is off unless `timeoutMs` or `deadline` is set. */
|
|
169
|
+
export interface StreamRequest<Plane extends string = string> extends HttpRequest<Plane> {
|
|
170
|
+
/** Time until response headers. Default: the client's `timeoutMs`. */
|
|
171
|
+
startupTimeoutMs?: number;
|
|
172
|
+
/** Longest gap between body chunks. Default: none. */
|
|
173
|
+
idleTimeoutMs?: number;
|
|
174
|
+
}
|
|
175
|
+
/** A buffered response. */
|
|
176
|
+
export interface HttpResponse {
|
|
177
|
+
readonly status: number;
|
|
178
|
+
readonly headers: Headers;
|
|
179
|
+
readonly body: Uint8Array;
|
|
180
|
+
/** The body as UTF-8 text. */
|
|
181
|
+
text(): string;
|
|
182
|
+
/** The body parsed as JSON, or `undefined` when it is empty. Invalid JSON is a `provider` SandboxError. */
|
|
183
|
+
json(): JsonValue | undefined;
|
|
184
|
+
}
|
|
185
|
+
export interface HttpClient<Plane extends string = string> {
|
|
186
|
+
readonly provider: string;
|
|
187
|
+
readonly label: string;
|
|
188
|
+
/** Redacts credentials seen so far, `secrets()` and credential-shaped text. */
|
|
189
|
+
readonly redact: (text: string) => string;
|
|
190
|
+
/** Send a request and buffer the response body (bounded by `maxBytes`). Non-2xx rejects. */
|
|
191
|
+
request(request: HttpRequest<Plane>): Promise<HttpResponse>;
|
|
192
|
+
/** `request(...).json()`. */
|
|
193
|
+
json(request: HttpRequest<Plane>): Promise<JsonValue | undefined>;
|
|
194
|
+
/** Send a request and return once headers arrive. The body enforces the idle timeout and deadline; the caller reads or cancels it. */
|
|
195
|
+
stream(request: StreamRequest<Plane>): Promise<Response>;
|
|
196
|
+
/** A best-effort request after an abort: no caller signal, its own deadline of at most 10 s. */
|
|
197
|
+
cleanup(request: HttpRequest<Plane>): Promise<HttpResponse>;
|
|
198
|
+
}
|
|
199
|
+
/** A deadline several calls share. */
|
|
200
|
+
export interface Deadline {
|
|
201
|
+
/** Fires on the timeout or the caller's signal. */
|
|
202
|
+
readonly signal: AbortSignal;
|
|
203
|
+
/** Fires only on the timeout. */
|
|
204
|
+
readonly timeout: AbortSignal;
|
|
205
|
+
/** The caller's signal, if any. */
|
|
206
|
+
readonly parent?: AbortSignal;
|
|
207
|
+
/** Milliseconds left, never negative. */
|
|
208
|
+
remaining(): number;
|
|
209
|
+
}
|
|
210
|
+
export declare function createDeadline(timeoutMs: number, parent?: AbortSignal): Deadline;
|
|
211
|
+
/** Waits `ms`, rejecting with a `timeout` or `aborted` SandboxError when `deadline` fires first. For polling loops. */
|
|
212
|
+
export declare function sleep(ms: number, deadline: Deadline, provider: string): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* The HTTP status and provider error code (when it is a safe token) behind a client error, or `undefined`
|
|
215
|
+
* for errors that are not a non-2xx response. For adapters that branch on a status, such as a 409 retry.
|
|
216
|
+
*/
|
|
217
|
+
export declare function httpStatus(cause: unknown): {
|
|
218
|
+
status: number;
|
|
219
|
+
code?: string;
|
|
220
|
+
} | undefined;
|
|
221
|
+
/** Pulls the code and message out of the error shapes providers use: `{ code, message }`, `{ error: { code, message } }`, `{ error: "text" }`, RFC 7807. */
|
|
222
|
+
export declare function parseErrorBody(text: string): ErrorBody;
|
|
223
|
+
/** Builds the client. Planes are fixed; their base URLs and credentials are read per request. */
|
|
224
|
+
export declare function createHttpClient<Plane extends string>(options: HttpClientOptions<Plane>): HttpClient<Plane>;
|
|
225
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Provider, Capability, SandboxInfo } from "./provider.js";
|
|
2
|
+
import type { ConnectOptions, CreateOptions, ListOptions, MethodsFor, ProviderSandbox, ReapOptions, SandboxBase } from "./types.js";
|
|
3
|
+
export { SandboxError } from "./errors.js";
|
|
4
|
+
export type { ErrorCode, ErrorOptions } from "./errors.js";
|
|
5
|
+
export type { Sandbox, SandboxBase, ProviderSandbox, CreateOptions, ConnectOptions, ListOptions, ReapOptions, PreviewOptions, Usage, Locator, RunOptions, RunHandle, RunResult, OutputChunk, Capability, CapabilityMethods, MethodsFor, SandboxInfo, FileInfo, Labels, Preview, Terminal, } from "./types.js";
|
|
6
|
+
export type { WriteOptions, SnapshotOptions } from "./provider.js";
|
|
7
|
+
export type { NativeApi, NativeRequestOptions, HttpMethod } from "./native.js";
|
|
8
|
+
export type { Files, FileDiff, FileEvent } from "./files.js";
|
|
9
|
+
export type { ProcessHandle, ProcessInfo, StartOptions, Readiness } from "./processes.js";
|
|
10
|
+
export type { Git } from "./git.js";
|
|
11
|
+
/**
|
|
12
|
+
* Check a capability at runtime and narrow the sandbox type to include its methods.
|
|
13
|
+
* Use it when the provider is chosen at runtime: `if (hasCapability(box, "pause")) await box.pause();`
|
|
14
|
+
*/
|
|
15
|
+
export declare function hasCapability<B extends SandboxBase<unknown>, K extends Capability>(box: B, capability: K): box is B & (K extends Capability ? MethodsFor<K> : never);
|
|
16
|
+
export declare function createSandbox<P extends Provider>(provider: P, options?: CreateOptions): Promise<ProviderSandbox<P>>;
|
|
17
|
+
export declare function connectSandbox<P extends Provider>(provider: P, id: string, options?: ConnectOptions): Promise<ProviderSandbox<P>>;
|
|
18
|
+
export declare function listSandboxes(provider: Provider, options?: ListOptions): Promise<SandboxInfo[]>;
|
|
19
|
+
export declare function reapSandboxes(provider: Provider, options?: ReapOptions): Promise<number>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{X,O,j,W,Q}from"./chunk-hgrwyjrb.js";import{e}from"./chunk-xgxfy2n8.js";export{e as SandboxError,j as connectSandbox,O as createSandbox,X as hasCapability,W as listSandboxes,Q as reapSandboxes};
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Provider } from "./provider.js";
|
|
2
|
+
import type { CreateOptions } from "./types.js";
|
|
3
|
+
export declare const knownKey: (provider: Provider, key: string) => string | undefined;
|
|
4
|
+
export declare function rememberKey(provider: Provider, key: string, id: string): void;
|
|
5
|
+
export declare function forgetKey(provider: Provider, key: string): void;
|
|
6
|
+
export declare function forgetSandbox(provider: Provider, id: string): void;
|
|
7
|
+
export declare function withKeyLock<T>(provider: Provider, key: string, options: Pick<CreateOptions, "keyMode" | "locator">, action: () => Promise<T>): Promise<T>;
|
|
8
|
+
export declare function attachHandle(provider: Provider, id: string): void;
|
|
9
|
+
/** Drop one handle's claim. Returns whether it was the last open handle for the sandbox. */
|
|
10
|
+
export declare function detachHandle(provider: Provider, id: string): boolean;
|
package/dist/logs.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { OutputChunk } from "./provider.js";
|
|
2
|
+
export declare function encodeChunk(chunk: OutputChunk): string[];
|
|
3
|
+
export declare function decodePage(bytes: Uint8Array, offset: number, max: number, base: number): {
|
|
4
|
+
events: (OutputChunk & {
|
|
5
|
+
cursor: string;
|
|
6
|
+
})[];
|
|
7
|
+
offset: number;
|
|
8
|
+
};
|
package/dist/mastra.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Sandbox } from "./types.js";
|
|
2
|
+
import { type SandboxToolsOptions } from "./tools.js";
|
|
3
|
+
export type { SandboxToolsOptions } from "./tools.js";
|
|
4
|
+
export declare function sandboxTools(box: Sandbox, options?: SandboxToolsOptions): {
|
|
5
|
+
[k: string]: import("@mastra/core/tools").Tool<{
|
|
6
|
+
command: string;
|
|
7
|
+
cwd?: string | undefined;
|
|
8
|
+
timeoutMs?: number | undefined;
|
|
9
|
+
} | {
|
|
10
|
+
path: string;
|
|
11
|
+
offset?: number | undefined;
|
|
12
|
+
limit?: number | undefined;
|
|
13
|
+
} | {
|
|
14
|
+
path: string;
|
|
15
|
+
content: string;
|
|
16
|
+
} | {
|
|
17
|
+
path: string;
|
|
18
|
+
find: string;
|
|
19
|
+
replace: string;
|
|
20
|
+
} | {
|
|
21
|
+
name: string;
|
|
22
|
+
command: string;
|
|
23
|
+
cwd?: string | undefined;
|
|
24
|
+
port?: number | undefined;
|
|
25
|
+
} | {
|
|
26
|
+
name: string;
|
|
27
|
+
cursor?: string | undefined;
|
|
28
|
+
} | {
|
|
29
|
+
name: string;
|
|
30
|
+
} | {
|
|
31
|
+
query: string;
|
|
32
|
+
path?: string | undefined;
|
|
33
|
+
glob?: string | undefined;
|
|
34
|
+
} | {
|
|
35
|
+
path?: string | undefined;
|
|
36
|
+
glob?: string | undefined;
|
|
37
|
+
} | Record<string, never> | {
|
|
38
|
+
port: number;
|
|
39
|
+
path?: string | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
text: string;
|
|
42
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "search" | "changes" | "run" | "read_file" | "write_file" | "edit_file" | "start_process" | "process_logs" | "stop_process" | "list_files" | "preview", unknown>;
|
|
43
|
+
};
|
package/dist/mastra.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunk-23tjmd39.js";import{M}from"./chunk-nw845a93.js";import"./chunk-ckym4cht.js";import{createTool as s}from"@mastra/core/tools";import{z as e}from"zod";function c(p,r){return Object.fromEntries(M(p,r).map((o)=>[o.name,s({id:o.name,description:o.description,inputSchema:o.inputSchema,outputSchema:e.object({text:e.string()}),execute:(t,a)=>o.execute(t,void 0,a?.abortSignal),toModelOutput:(t)=>({type:"text",value:t.text})})]))}export{c as sandboxTools};
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Provider, FileInfo } from "./provider.js";
|
|
2
|
+
export interface CommandContext {
|
|
3
|
+
args: string[];
|
|
4
|
+
cwd: string;
|
|
5
|
+
env: Record<string, string>;
|
|
6
|
+
stdin: string;
|
|
7
|
+
signal: AbortSignal;
|
|
8
|
+
stdout(text: string): void;
|
|
9
|
+
stderr(text: string): void;
|
|
10
|
+
files: {
|
|
11
|
+
read(path: string): Promise<Uint8Array>;
|
|
12
|
+
write(path: string, data: string | Uint8Array): Promise<void>;
|
|
13
|
+
list(path: string): Promise<FileInfo[]>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export type CommandHandler = (context: CommandContext) => number | Promise<number>;
|
|
17
|
+
/** `mode` holds POSIX permission bits; `stat -c %a` and `chmod` read and set them. */
|
|
18
|
+
interface Node {
|
|
19
|
+
data: Uint8Array | null;
|
|
20
|
+
modifiedAt: number;
|
|
21
|
+
mode: number;
|
|
22
|
+
}
|
|
23
|
+
export interface MemoryOptions {
|
|
24
|
+
handlers?: Record<string, CommandHandler>;
|
|
25
|
+
}
|
|
26
|
+
export interface MemoryNative {
|
|
27
|
+
readonly files: Map<string, Node>;
|
|
28
|
+
}
|
|
29
|
+
/** Offline fake. No git, shell programs outside the handler table (plus `cd`, `export`,
|
|
30
|
+
* `kill`, `chmod MODE PATH...` and `stat -c %a PATH...`), PTYs, or real
|
|
31
|
+
* sockets. Preview URLs use memory.invalid and must never be fetched. Register
|
|
32
|
+
* handlers with memory({handlers}) or provider.register(name, handler).
|
|
33
|
+
*/
|
|
34
|
+
export declare function memory(options?: MemoryOptions): Provider<MemoryNative, "network-policy"> & {
|
|
35
|
+
register(name: string, handler: CommandHandler): void;
|
|
36
|
+
};
|
|
37
|
+
export {};
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{e}from"./chunk-xgxfy2n8.js";import{posix as u}from"node:path";function V(L={}){let b=new Map,g=new Map,w=(r,t)=>new e(`${r}. Memory resource does not exist or request is invalid. Check the path or ID.`,{code:t,provider:"memory"}),v=(r)=>{let t=b.get(r);if(!t)throw w(`Sandbox ${r} not found`,"not_found");if(t.idleTimeoutMs)clearTimeout(t.idleTimer),t.idleTimer=setTimeout(()=>{if(t.active.size)v(r);else S.destroy(r)},t.idleTimeoutMs),t.idleTimer.unref?.();return t},M=(r,t)=>{let n=v(r).nodes.get(u.resolve("/",t));if(!n)throw w(`File ${t} not found`,"file_not_found");return n},I=()=>Date.now();function P(r,t){let n=v(r);for(let o=u.resolve("/",t);;o=u.dirname(o)){let s=n.nodes.get(o);if(s?.data)throw w(`${o} is not a directory`,"invalid_argument");if(!s)n.nodes.set(o,{data:null,modifiedAt:I(),mode:493});if(o==="/")break}}let C={transfer:"files",checkpoints:"files",writeCreatesParents:!0,writeSupportsMode:!0,async readRange(r,t,n){let o=M(r,t);if(o.data===null)throw w(`${t} is a directory`,"invalid_argument");return o.data.slice(n.offset,n.offset+n.length)},async read(r,t){let n=M(r,t);if(n.data===null)throw w(`${t} is a directory`,"invalid_argument");return n.data.slice()},async write(r,t,n,o){let s=v(r);P(r,u.dirname(t));let i=u.resolve("/",t),m=s.nodes.get(i);s.nodes.set(i,{data:n.slice(),modifiedAt:Math.max(I(),(m?.modifiedAt??0)+1),mode:o?.mode??m?.mode??420})},async stat(r,t){let n=M(r,t);return{path:u.resolve("/",t),type:n.data===null?"directory":"file",size:n.data?.length??0,modifiedAt:n.modifiedAt}},async list(r,t){let n=u.resolve("/",t);if(M(r,t).data!==null)throw w(`${t} is not a directory`,"invalid_argument");let o=[];for(let s of v(r).nodes.keys())if(s!==n&&u.dirname(s)===n)o.push(await C.stat(r,s));return o.sort((s,i)=>s.path.localeCompare(i.path))},async remove(r,t,n){let o=v(r),s=u.resolve("/",t);M(r,s);let i=[...o.nodes.keys()].filter((m)=>m.startsWith(s+"/"));if(i.length&&!n.recursive)throw w(`${t} is not empty`,"invalid_argument");for(let m of i)o.nodes.delete(m);o.nodes.delete(s)},async mkdir(r,t){P(r,t)}},Z=({args:r,signal:t})=>new Promise((n)=>{if(t.aborted){n(137);return}let o=setTimeout(()=>{t.removeEventListener("abort",s),n(0)},Math.max(0,Number(r[0]??0)*1000)),s=()=>{clearTimeout(o),n(137)};t.addEventListener("abort",s,{once:!0})});g.set("echo",({args:r,stdout:t})=>{let n=r[0]==="-n";return t((n?r.slice(1):r).join(" ")+(n?"":`
|
|
2
|
+
`)),0}),g.set("printf",({args:r,stdout:t})=>{let n=1;return t((r[0]??"").replace(/\\n/g,`
|
|
3
|
+
`).replace(/\\t/g,"\t").replace(/%[sd%]/g,(o)=>o==="%%"?"%":r[n++]??"")),0}),g.set("pwd",({cwd:r,stdout:t})=>(t(r+`
|
|
4
|
+
`),0)),g.set("true",()=>0),g.set("false",()=>1),g.set("exit",({args:r})=>Number(r[0]??0)),g.set("sleep",Z),g.set("cat",async({args:r,stdin:t,stdout:n,stderr:o,files:s})=>{if(!r.length)n(t);else for(let i of r)try{n(new TextDecoder().decode(await s.read(i)))}catch{return o(`cat: ${i}: No such file or directory
|
|
5
|
+
`),1}return 0}),g.set("ls",async({args:r,stdout:t,files:n})=>(t((await n.list(r.find((o)=>!o.startsWith("-"))??".")).map((o)=>u.basename(o.path)).join(`
|
|
6
|
+
`)+`
|
|
7
|
+
`),0)),g.set("printenv",({args:r,env:t,stdout:n})=>(n((r.length?r.map((o)=>t[o]??""):Object.entries(t).map(([o,s])=>`${o}=${s}`)).join(`
|
|
8
|
+
`)+`
|
|
9
|
+
`),0));for(let[r,t]of Object.entries(L.handlers??{}))g.set(r,t);function q(r,t){let n=[],o="",s=!1,i="plain",m=()=>{if(s)n.push({text:o,operator:!1});o="",s=!1};for(let l=0;l<r.length;l++){let f=r[l]??"";if(i==="single"){if(f==="'")i="plain";else o+=f;continue}if(f==="'"&&i==="plain"){i="single",s=!0;continue}if(f==='"'){i=i==="double"?"plain":"double",s=!0;continue}if(f==="\\"){let d=r[++l]??"";o+=d==="n"?"\\n":d,s=!0;continue}if(f==="$"){let d=r.slice(l+1),k=/^(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))/.exec(d);if(k){o+=t[k[1]??k[2]??""]??"",l+=k[0].length,s=!0;continue}}if(i==="plain"&&/\s/.test(f)){m();continue}if(i==="plain"&&"><".includes(f)&&s&&/^\d+$/.test(o)){let d=o;o="",s=!1,n.push({text:d+f,operator:!0});continue}if(i==="plain"&&f===">"&&r.slice(l,l+3)===">&2"){m(),n.push({text:">&2",operator:!0}),l+=2;continue}if(i==="plain"&&";&>|<".includes(f)){m();let d=f;if(r[l+1]===f)d+=r[++l];n.push({text:d,operator:!0});continue}o+=f,s=!0}if(i!=="plain")throw w("Unclosed shell quote","invalid_argument");return m(),n}async function z(r,t){let n=v(r),o=new AbortController;n.active.add(o);let s=!1,i=()=>{s=!0,o.abort()};if(t.signal?.addEventListener("abort",i,{once:!0}),t.signal?.aborted)i();let m=setTimeout(i,t.timeoutMs),l=t.cwd,f={...n.env,...t.env},d=0,k=!1;try{if(t.activityPath)P(r,u.dirname(t.activityPath)),await C.write(r,t.activityPath,new Uint8Array([1]));let h=q(t.command,f),W=h.find((c)=>c.operator&&![";","&&","||",">",">&2"].includes(c.text)),G=h.find((c,p)=>c.operator&&c.text===">"&&(!h[p+1]||h[p+1]?.operator||h[p+2]&&!h[p+2]?.operator)),K=h.find((c,p)=>c.operator&&["&&","||"].includes(c.text)&&(!h[p-1]||[";","&&","||"].includes(h[p-1]?.text??"")||!h[p+1]||h[p+1]?.operator)),O=0,B=h.find((c)=>{if(!c.operator)return!1;if([";","&&","||"].includes(c.text))O=0;else if([">",">&2"].includes(c.text))return++O>1;return!1}),U=W??G??K??B;if(U)return t.onChunk({stream:"stderr",text:`Unsupported shell syntax: ${U.text} (memory provider)
|
|
10
|
+
`}),{exitCode:127,timedOut:!1};let N=[],A=";";async function j(c){let p=N;N=[];let E=p.findIndex((a)=>a.operator&&a.text===">&2");if(E>=0)p.splice(E,1);let _=p.findIndex((a)=>a.operator&&a.text===">"),R=_>=0?p[_+1]?.text:void 0;if(_>=0)p.splice(_);let x=p.map((a)=>a.text);if(!x.length||k||o.signal.aborted||A==="&&"&&d!==0||A==="||"&&d===0){A=c;return}A=c;let T=x.shift()??"";if(T==="cd"){if(l=u.resolve(l,x[0]??"/workspace"),M(r,l).data!==null)throw w("Not a directory","invalid_argument");d=0;return}if(T==="export"){for(let a of x){let y=a.indexOf("=");if(y>=0)f[a.slice(0,y)]=a.slice(y+1)}return}if(T==="kill"){let a=Math.abs(Number(x.find((y)=>/^-?\d+$/.test(y))));n.processes.get(a)?.controller.abort();return}if(T==="exit")k=!0;if(T==="chmod"){let a=Number.parseInt(x[0]??"",8);if(!/^[0-7]{1,4}$/.test(x[0]??"")||x.length<2){t.onChunk({stream:"stderr",text:`chmod: only octal modes are supported (memory provider)
|
|
11
|
+
`}),d=1;return}for(let y of x.slice(1))M(r,u.resolve(l,y)).mode=a;d=0;return}if(T==="stat"&&x[0]==="-c"&&x[1]==="%a"){for(let a of x.slice(2))t.onChunk({stream:"stdout",text:`${M(r,u.resolve(l,a)).mode.toString(8)}
|
|
12
|
+
`});d=0;return}let H=g.get(T);if(!H){t.onChunk({stream:"stderr",text:`${T}: command not found (memory handler not registered)
|
|
13
|
+
`}),d=127;return}let D="",F=(a,y)=>{if(!o.signal.aborted)if(R&&a==="stdout")D+=y;else t.onChunk({stream:a,text:y})};if(d=await H({args:x,cwd:l,env:f,stdin:t.stdin??"",signal:o.signal,stdout:(a)=>F(E>=0?"stderr":"stdout",a),stderr:(a)=>F("stderr",a),files:{read:(a)=>C.read(r,u.resolve(l,a)),write:(a,y)=>C.write(r,u.resolve(l,a),y instanceof Uint8Array?y:new TextEncoder().encode(y)),list:(a)=>C.list(r,u.resolve(l,a))}}),R)await C.write(r,u.resolve(l,R),new TextEncoder().encode(D))}for(let c of h)if(c.operator&&[";","&&","||"].includes(c.text))await j(c.text);else N.push(c);return await j(";"),{exitCode:s?null:d,timedOut:s}}finally{if(t.activityPath){if(n.nodes.delete(t.activityPath),b.has(r))v(r)}n.active.delete(o),clearTimeout(m),t.signal?.removeEventListener("abort",i)}}let S={name:"memory",inlineActivity:!0,processMode:"stream",previewMode:"placeholder",keyMode:"exact",capabilities:new Set(["network-policy"]),files:C,register(r,t){g.set(r,t)},async create(r){if(r.size!==void 0)throw new e("Memory cannot enforce machine size. Omit size or choose a provider with size support.",{code:"unsupported",provider:"memory"});if(r.key){if([...b.values()].find((s)=>s.info.key===r.key))throw new e("Key already exists. Another caller created it. Find the existing sandbox.",{code:"provider",provider:"memory"})}let t=`mem-${crypto.randomUUID()}`,n={id:t,key:r.key,labels:{...r.labels},state:"running",createdAt:I()};if(b.set(t,{info:n,nodes:new Map,env:{...r.env},processes:new Map,nextPid:100,active:new Set,idleTimeoutMs:r.idleTimeoutMs}),r.timeoutMs){let o=v(t);o.lifetimeTimer=setTimeout(()=>{S.destroy(t)},r.timeoutMs),o.lifetimeTimer.unref?.()}return P(t,"/workspace"),P(t,"/tmp"),n},async find(r){return[...b.values()].find((t)=>t.info.key===r)?.info},async connect(r){return v(r).info},async list(r){let t=[];for(let{info:n}of b.values())if(Object.entries(r).every(([o,s])=>n.labels[o]===s))t.push(n);return t},async destroy(r){let t=b.get(r);if(!t)return;clearTimeout(t.idleTimer),clearTimeout(t.lifetimeTimer);for(let n of t.active)n.abort();for(let n of t.processes.values())n.controller.abort();await Promise.allSettled([...t.processes.values()].map((n)=>n.result)),b.delete(r)},exec:z,async readSecretEnvironment(r){let t=v(r),n=t.nodes.get("/tmp/.sandbox-sdk/secret-names.json");if(!n?.data)return;return{record:new TextDecoder().decode(n.data),environment:{...t.env}}},async previewUrl(r,t){return v(r),{url:`https://${r}-${t}.memory.invalid/`}},native(r){return{files:v(r).nodes}},async startProcess(r,t){let n=v(r),o=n.nextPid++,s=new AbortController,i=z(r,{...t,timeoutMs:2147483647,signal:s.signal});return n.processes.set(o,{controller:s,result:i}),i.then(()=>n.processes.delete(o),()=>n.processes.delete(o)),{pid:o,wait:async()=>{let m=await i;return{exitCode:m.timedOut?143:m.exitCode,signal:m.timedOut?"SIGTERM":null}},stop:async()=>{s.abort(),await i}}}};return S}export{V as memory};
|