smolmachines 1.25.2 → 1.26.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/dist/transport.d.ts +7 -0
- package/dist/transport.js +23 -0
- package/package.json +4 -4
package/dist/transport.d.ts
CHANGED
|
@@ -122,6 +122,13 @@ interface CloudConn {
|
|
|
122
122
|
fetch?: typeof fetch;
|
|
123
123
|
readResponseBytes?: (response: Response) => Promise<Uint8Array>;
|
|
124
124
|
}
|
|
125
|
+
/** The largest file the cloud's file routes accept. */
|
|
126
|
+
export declare const CLOUD_MAX_FILE_BYTES: number;
|
|
127
|
+
/** How long moving `bytes` may take (ms): the request timeout plus the time
|
|
128
|
+
* `bytes` needs at the floor rate. */
|
|
129
|
+
export declare function transferTimeoutMs(bytes: number): number;
|
|
130
|
+
/** Refuse a file the cloud would refuse, before sending any of it. */
|
|
131
|
+
export declare function checkCloudFileSize(path: string, bytes: number): void;
|
|
125
132
|
/** The sentence a person should read from a failed response's body. The
|
|
126
133
|
* control plane answers errors as RFC 9457 problem+json, whose `detail` is the
|
|
127
134
|
* sentence; older builds sent `{"error": …}` or plain text. A JSON object
|
package/dist/transport.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* Cloud-only/local-only capability gaps surface as `NotSupportedError`.
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.CLOUD_MAX_FILE_BYTES = void 0;
|
|
11
12
|
exports.cliConfigApiKey = cliConfigApiKey;
|
|
12
13
|
exports.resolveNetwork = resolveNetwork;
|
|
13
14
|
exports.networkMode = networkMode;
|
|
@@ -15,6 +16,8 @@ exports.cloudNetwork = cloudNetwork;
|
|
|
15
16
|
exports.egressPolicy = egressPolicy;
|
|
16
17
|
exports.resolveBranchable = resolveBranchable;
|
|
17
18
|
exports.toNativeConfig = toNativeConfig;
|
|
19
|
+
exports.transferTimeoutMs = transferTimeoutMs;
|
|
20
|
+
exports.checkCloudFileSize = checkCloudFileSize;
|
|
18
21
|
exports.errorSentence = errorSentence;
|
|
19
22
|
exports.encodePath = encodePath;
|
|
20
23
|
exports.selectsCloud = selectsCloud;
|
|
@@ -699,6 +702,23 @@ function cloudConnOf(conn, baseUrl, apiKey) {
|
|
|
699
702
|
const DEFAULT_CLOUD_URL = "https://api.smolmachines.com";
|
|
700
703
|
/** Default per-request timeout for cloud calls (ms). Override via opts.timeoutMs. */
|
|
701
704
|
const CLOUD_TIMEOUT_MS = 30_000;
|
|
705
|
+
// A file transfer is given time for the slowest link it should survive: a
|
|
706
|
+
// large file over a slow uplink must not fail at CLOUD_TIMEOUT_MS while it is
|
|
707
|
+
// still moving. Same floor as the Rust and Python SDKs.
|
|
708
|
+
const CLOUD_TRANSFER_FLOOR_BYTES_PER_S = 256 * 1024;
|
|
709
|
+
/** The largest file the cloud's file routes accept. */
|
|
710
|
+
exports.CLOUD_MAX_FILE_BYTES = 100 * 1024 * 1024;
|
|
711
|
+
/** How long moving `bytes` may take (ms): the request timeout plus the time
|
|
712
|
+
* `bytes` needs at the floor rate. */
|
|
713
|
+
function transferTimeoutMs(bytes) {
|
|
714
|
+
return CLOUD_TIMEOUT_MS + Math.ceil(bytes / CLOUD_TRANSFER_FLOOR_BYTES_PER_S) * 1_000;
|
|
715
|
+
}
|
|
716
|
+
/** Refuse a file the cloud would refuse, before sending any of it. */
|
|
717
|
+
function checkCloudFileSize(path, bytes) {
|
|
718
|
+
if (bytes > exports.CLOUD_MAX_FILE_BYTES) {
|
|
719
|
+
throw new errors_1.SmolError("SMOLVM_ERROR", `${path} is ${(bytes / (1024 * 1024)).toFixed(1)} MiB; cloud machines accept files up to ${exports.CLOUD_MAX_FILE_BYTES / (1024 * 1024)} MiB`);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
702
722
|
// Starting can include a cold image pull. Keep ordinary API calls short, but
|
|
703
723
|
// give this explicitly long-running operation the same bounded window already
|
|
704
724
|
// used by checkpoint restore.
|
|
@@ -1132,11 +1152,14 @@ class CloudTransport {
|
|
|
1132
1152
|
async readFile(path) {
|
|
1133
1153
|
return cloudFetch(this.conn, "GET", `/v1/machines/${this.id}/files/${encodePath(path)}`, {
|
|
1134
1154
|
accept: "bytes",
|
|
1155
|
+
timeoutMs: transferTimeoutMs(exports.CLOUD_MAX_FILE_BYTES),
|
|
1135
1156
|
});
|
|
1136
1157
|
}
|
|
1137
1158
|
async writeFile(path, data, mode) {
|
|
1159
|
+
checkCloudFileSize(path, data.length);
|
|
1138
1160
|
await cloudFetch(this.conn, "PUT", `/v1/machines/${this.id}/files/${encodePath(path)}`, {
|
|
1139
1161
|
body: data,
|
|
1162
|
+
timeoutMs: transferTimeoutMs(data.length),
|
|
1140
1163
|
});
|
|
1141
1164
|
// The cloud /files PUT carries no file mode, so apply it with chmod when
|
|
1142
1165
|
// requested — e.g. writing an executable script the caller then runs.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smolmachines",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.1",
|
|
4
4
|
"description": "Embed isolated microVM sandboxes directly in your code — no server to run.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "smol-machines",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"typescript": "^5.6.0"
|
|
64
64
|
},
|
|
65
65
|
"optionalDependencies": {
|
|
66
|
-
"smolmachines-darwin-arm64": "1.
|
|
67
|
-
"smolmachines-linux-x64-gnu": "1.
|
|
68
|
-
"smolmachines-linux-arm64-gnu": "1.
|
|
66
|
+
"smolmachines-darwin-arm64": "1.26.1",
|
|
67
|
+
"smolmachines-linux-x64-gnu": "1.26.1",
|
|
68
|
+
"smolmachines-linux-arm64-gnu": "1.26.1"
|
|
69
69
|
}
|
|
70
70
|
}
|