modal 0.3.8 → 0.3.9
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/index.cjs +184 -54
- package/dist/index.d.cts +38 -1
- package/dist/index.d.ts +38 -1
- package/dist/index.js +183 -54
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,7 @@ __export(index_exports, {
|
|
|
46
46
|
QueueFullError: () => QueueFullError,
|
|
47
47
|
RemoteError: () => RemoteError,
|
|
48
48
|
Sandbox: () => Sandbox2,
|
|
49
|
+
SandboxFile: () => SandboxFile,
|
|
49
50
|
Secret: () => Secret
|
|
50
51
|
});
|
|
51
52
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -38086,6 +38087,156 @@ ${result.exception}`
|
|
|
38086
38087
|
return new Image2(resp.imageId);
|
|
38087
38088
|
}
|
|
38088
38089
|
|
|
38090
|
+
// src/errors.ts
|
|
38091
|
+
var FunctionTimeoutError = class extends Error {
|
|
38092
|
+
constructor(message) {
|
|
38093
|
+
super(message);
|
|
38094
|
+
this.name = "FunctionTimeoutError";
|
|
38095
|
+
}
|
|
38096
|
+
};
|
|
38097
|
+
var RemoteError = class extends Error {
|
|
38098
|
+
constructor(message) {
|
|
38099
|
+
super(message);
|
|
38100
|
+
this.name = "RemoteError";
|
|
38101
|
+
}
|
|
38102
|
+
};
|
|
38103
|
+
var InternalFailure = class extends Error {
|
|
38104
|
+
constructor(message) {
|
|
38105
|
+
super(message);
|
|
38106
|
+
this.name = "InternalFailure";
|
|
38107
|
+
}
|
|
38108
|
+
};
|
|
38109
|
+
var NotFoundError = class extends Error {
|
|
38110
|
+
constructor(message) {
|
|
38111
|
+
super(message);
|
|
38112
|
+
this.name = "NotFoundError";
|
|
38113
|
+
}
|
|
38114
|
+
};
|
|
38115
|
+
var InvalidError = class extends Error {
|
|
38116
|
+
constructor(message) {
|
|
38117
|
+
super(message);
|
|
38118
|
+
this.name = "InvalidError";
|
|
38119
|
+
}
|
|
38120
|
+
};
|
|
38121
|
+
var QueueEmptyError = class extends Error {
|
|
38122
|
+
constructor(message) {
|
|
38123
|
+
super(message);
|
|
38124
|
+
this.name = "QueueEmptyError";
|
|
38125
|
+
}
|
|
38126
|
+
};
|
|
38127
|
+
var QueueFullError = class extends Error {
|
|
38128
|
+
constructor(message) {
|
|
38129
|
+
super(message);
|
|
38130
|
+
this.name = "QueueFullError";
|
|
38131
|
+
}
|
|
38132
|
+
};
|
|
38133
|
+
var SandboxFilesystemError = class extends Error {
|
|
38134
|
+
constructor(message) {
|
|
38135
|
+
super(message);
|
|
38136
|
+
this.name = "SandboxFilesystemError";
|
|
38137
|
+
}
|
|
38138
|
+
};
|
|
38139
|
+
|
|
38140
|
+
// src/sandbox_filesystem.ts
|
|
38141
|
+
var SandboxFile = class {
|
|
38142
|
+
#fileDescriptor;
|
|
38143
|
+
#taskId;
|
|
38144
|
+
/** @ignore */
|
|
38145
|
+
constructor(fileDescriptor, taskId) {
|
|
38146
|
+
this.#fileDescriptor = fileDescriptor;
|
|
38147
|
+
this.#taskId = taskId;
|
|
38148
|
+
}
|
|
38149
|
+
/**
|
|
38150
|
+
* Read data from the file.
|
|
38151
|
+
* @returns Promise that resolves to the read data as Uint8Array
|
|
38152
|
+
*/
|
|
38153
|
+
async read() {
|
|
38154
|
+
const resp = await runFilesystemExec({
|
|
38155
|
+
fileReadRequest: {
|
|
38156
|
+
fileDescriptor: this.#fileDescriptor
|
|
38157
|
+
},
|
|
38158
|
+
taskId: this.#taskId
|
|
38159
|
+
});
|
|
38160
|
+
const chunks = resp.chunks;
|
|
38161
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
38162
|
+
const result = new Uint8Array(totalLength);
|
|
38163
|
+
let offset = 0;
|
|
38164
|
+
for (const chunk of chunks) {
|
|
38165
|
+
result.set(chunk, offset);
|
|
38166
|
+
offset += chunk.length;
|
|
38167
|
+
}
|
|
38168
|
+
return result;
|
|
38169
|
+
}
|
|
38170
|
+
/**
|
|
38171
|
+
* Write data to the file.
|
|
38172
|
+
* @param data - Data to write (string or Uint8Array)
|
|
38173
|
+
*/
|
|
38174
|
+
async write(data) {
|
|
38175
|
+
await runFilesystemExec({
|
|
38176
|
+
fileWriteRequest: {
|
|
38177
|
+
fileDescriptor: this.#fileDescriptor,
|
|
38178
|
+
data
|
|
38179
|
+
},
|
|
38180
|
+
taskId: this.#taskId
|
|
38181
|
+
});
|
|
38182
|
+
}
|
|
38183
|
+
/**
|
|
38184
|
+
* Flush any buffered data to the file.
|
|
38185
|
+
*/
|
|
38186
|
+
async flush() {
|
|
38187
|
+
await runFilesystemExec({
|
|
38188
|
+
fileFlushRequest: {
|
|
38189
|
+
fileDescriptor: this.#fileDescriptor
|
|
38190
|
+
},
|
|
38191
|
+
taskId: this.#taskId
|
|
38192
|
+
});
|
|
38193
|
+
}
|
|
38194
|
+
/**
|
|
38195
|
+
* Close the file handle.
|
|
38196
|
+
*/
|
|
38197
|
+
async close() {
|
|
38198
|
+
await runFilesystemExec({
|
|
38199
|
+
fileCloseRequest: {
|
|
38200
|
+
fileDescriptor: this.#fileDescriptor
|
|
38201
|
+
},
|
|
38202
|
+
taskId: this.#taskId
|
|
38203
|
+
});
|
|
38204
|
+
}
|
|
38205
|
+
};
|
|
38206
|
+
async function runFilesystemExec(request) {
|
|
38207
|
+
const response = await client.containerFilesystemExec(request);
|
|
38208
|
+
const chunks = [];
|
|
38209
|
+
let retries = 10;
|
|
38210
|
+
let completed = false;
|
|
38211
|
+
while (!completed) {
|
|
38212
|
+
try {
|
|
38213
|
+
const outputIterator = client.containerFilesystemExecGetOutput({
|
|
38214
|
+
execId: response.execId,
|
|
38215
|
+
timeout: 55
|
|
38216
|
+
});
|
|
38217
|
+
for await (const batch of outputIterator) {
|
|
38218
|
+
chunks.push(...batch.output);
|
|
38219
|
+
if (batch.eof) {
|
|
38220
|
+
completed = true;
|
|
38221
|
+
break;
|
|
38222
|
+
}
|
|
38223
|
+
if (batch.error !== void 0) {
|
|
38224
|
+
if (retries > 0) {
|
|
38225
|
+
retries--;
|
|
38226
|
+
break;
|
|
38227
|
+
}
|
|
38228
|
+
throw new SandboxFilesystemError(batch.error.errorMessage);
|
|
38229
|
+
}
|
|
38230
|
+
}
|
|
38231
|
+
} catch (err) {
|
|
38232
|
+
if (isRetryableGrpc(err) && retries > 0) {
|
|
38233
|
+
retries--;
|
|
38234
|
+
} else throw err;
|
|
38235
|
+
}
|
|
38236
|
+
}
|
|
38237
|
+
return { chunks, response };
|
|
38238
|
+
}
|
|
38239
|
+
|
|
38089
38240
|
// src/streams.ts
|
|
38090
38241
|
function toModalReadStream(stream) {
|
|
38091
38242
|
return Object.assign(stream, readMixin);
|
|
@@ -38218,28 +38369,50 @@ var Sandbox2 = class {
|
|
|
38218
38369
|
).pipeThrough(new TextDecoderStream())
|
|
38219
38370
|
);
|
|
38220
38371
|
}
|
|
38372
|
+
/**
|
|
38373
|
+
* Open a file in the sandbox filesystem.
|
|
38374
|
+
* @param path - Path to the file to open
|
|
38375
|
+
* @param mode - File open mode (r, w, a, r+, w+, a+)
|
|
38376
|
+
* @returns Promise that resolves to a SandboxFile
|
|
38377
|
+
*/
|
|
38378
|
+
async open(path2, mode = "r") {
|
|
38379
|
+
const taskId = await this.#getTaskId();
|
|
38380
|
+
const resp = await runFilesystemExec({
|
|
38381
|
+
fileOpenRequest: {
|
|
38382
|
+
path: path2,
|
|
38383
|
+
mode
|
|
38384
|
+
},
|
|
38385
|
+
taskId
|
|
38386
|
+
});
|
|
38387
|
+
const fileDescriptor = resp.response.fileDescriptor;
|
|
38388
|
+
return new SandboxFile(fileDescriptor, taskId);
|
|
38389
|
+
}
|
|
38221
38390
|
async exec(command, options) {
|
|
38391
|
+
const taskId = await this.#getTaskId();
|
|
38392
|
+
const resp = await client.containerExec({
|
|
38393
|
+
taskId,
|
|
38394
|
+
command
|
|
38395
|
+
});
|
|
38396
|
+
return new ContainerProcess(resp.execId, options);
|
|
38397
|
+
}
|
|
38398
|
+
async #getTaskId() {
|
|
38222
38399
|
if (this.#taskId === void 0) {
|
|
38223
|
-
const
|
|
38400
|
+
const resp = await client.sandboxGetTaskId({
|
|
38224
38401
|
sandboxId: this.sandboxId
|
|
38225
38402
|
});
|
|
38226
|
-
if (!
|
|
38403
|
+
if (!resp.taskId) {
|
|
38227
38404
|
throw new Error(
|
|
38228
38405
|
`Sandbox ${this.sandboxId} does not have a task ID. It may not be running.`
|
|
38229
38406
|
);
|
|
38230
38407
|
}
|
|
38231
|
-
if (
|
|
38408
|
+
if (resp.taskResult) {
|
|
38232
38409
|
throw new Error(
|
|
38233
|
-
`Sandbox ${this.sandboxId} has already completed with result: ${
|
|
38410
|
+
`Sandbox ${this.sandboxId} has already completed with result: ${resp.taskResult}`
|
|
38234
38411
|
);
|
|
38235
38412
|
}
|
|
38236
|
-
this.#taskId =
|
|
38413
|
+
this.#taskId = resp.taskId;
|
|
38237
38414
|
}
|
|
38238
|
-
|
|
38239
|
-
taskId: this.#taskId,
|
|
38240
|
-
command
|
|
38241
|
-
});
|
|
38242
|
-
return new ContainerProcess(resp.execId, options);
|
|
38415
|
+
return this.#taskId;
|
|
38243
38416
|
}
|
|
38244
38417
|
async terminate() {
|
|
38245
38418
|
await client.sandboxTerminate({ sandboxId: this.sandboxId });
|
|
@@ -38409,50 +38582,6 @@ function encodeIfString(chunk) {
|
|
|
38409
38582
|
return typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk;
|
|
38410
38583
|
}
|
|
38411
38584
|
|
|
38412
|
-
// src/errors.ts
|
|
38413
|
-
var FunctionTimeoutError = class extends Error {
|
|
38414
|
-
constructor(message) {
|
|
38415
|
-
super(message);
|
|
38416
|
-
this.name = "FunctionTimeoutError";
|
|
38417
|
-
}
|
|
38418
|
-
};
|
|
38419
|
-
var RemoteError = class extends Error {
|
|
38420
|
-
constructor(message) {
|
|
38421
|
-
super(message);
|
|
38422
|
-
this.name = "RemoteError";
|
|
38423
|
-
}
|
|
38424
|
-
};
|
|
38425
|
-
var InternalFailure = class extends Error {
|
|
38426
|
-
constructor(message) {
|
|
38427
|
-
super(message);
|
|
38428
|
-
this.name = "InternalFailure";
|
|
38429
|
-
}
|
|
38430
|
-
};
|
|
38431
|
-
var NotFoundError = class extends Error {
|
|
38432
|
-
constructor(message) {
|
|
38433
|
-
super(message);
|
|
38434
|
-
this.name = "NotFoundError";
|
|
38435
|
-
}
|
|
38436
|
-
};
|
|
38437
|
-
var InvalidError = class extends Error {
|
|
38438
|
-
constructor(message) {
|
|
38439
|
-
super(message);
|
|
38440
|
-
this.name = "InvalidError";
|
|
38441
|
-
}
|
|
38442
|
-
};
|
|
38443
|
-
var QueueEmptyError = class extends Error {
|
|
38444
|
-
constructor(message) {
|
|
38445
|
-
super(message);
|
|
38446
|
-
this.name = "QueueEmptyError";
|
|
38447
|
-
}
|
|
38448
|
-
};
|
|
38449
|
-
var QueueFullError = class extends Error {
|
|
38450
|
-
constructor(message) {
|
|
38451
|
-
super(message);
|
|
38452
|
-
this.name = "QueueFullError";
|
|
38453
|
-
}
|
|
38454
|
-
};
|
|
38455
|
-
|
|
38456
38585
|
// src/secret.ts
|
|
38457
38586
|
var import_nice_grpc2 = require("nice-grpc");
|
|
38458
38587
|
var Secret = class _Secret {
|
|
@@ -39570,5 +39699,6 @@ var Queue = class _Queue {
|
|
|
39570
39699
|
QueueFullError,
|
|
39571
39700
|
RemoteError,
|
|
39572
39701
|
Sandbox,
|
|
39702
|
+
SandboxFile,
|
|
39573
39703
|
Secret
|
|
39574
39704
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -57,6 +57,36 @@ declare class Image {
|
|
|
57
57
|
constructor(imageId: string);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/** File open modes supported by the filesystem API. */
|
|
61
|
+
type SandboxFileMode = "r" | "w" | "a" | "r+" | "w+" | "a+";
|
|
62
|
+
/**
|
|
63
|
+
* SandboxFile represents an open file in the sandbox filesystem.
|
|
64
|
+
* Provides read/write operations similar to Node.js `fsPromises.FileHandle`.
|
|
65
|
+
*/
|
|
66
|
+
declare class SandboxFile {
|
|
67
|
+
#private;
|
|
68
|
+
/** @ignore */
|
|
69
|
+
constructor(fileDescriptor: string, taskId: string);
|
|
70
|
+
/**
|
|
71
|
+
* Read data from the file.
|
|
72
|
+
* @returns Promise that resolves to the read data as Uint8Array
|
|
73
|
+
*/
|
|
74
|
+
read(): Promise<Uint8Array>;
|
|
75
|
+
/**
|
|
76
|
+
* Write data to the file.
|
|
77
|
+
* @param data - Data to write (string or Uint8Array)
|
|
78
|
+
*/
|
|
79
|
+
write(data: Uint8Array): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Flush any buffered data to the file.
|
|
82
|
+
*/
|
|
83
|
+
flush(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Close the file handle.
|
|
86
|
+
*/
|
|
87
|
+
close(): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
|
|
60
90
|
/**
|
|
61
91
|
* Wrapper around `ReadableStream` with convenience functions.
|
|
62
92
|
*
|
|
@@ -122,6 +152,13 @@ declare class Sandbox {
|
|
|
122
152
|
stderr: ModalReadStream<string>;
|
|
123
153
|
/** @ignore */
|
|
124
154
|
constructor(sandboxId: string);
|
|
155
|
+
/**
|
|
156
|
+
* Open a file in the sandbox filesystem.
|
|
157
|
+
* @param path - Path to the file to open
|
|
158
|
+
* @param mode - File open mode (r, w, a, r+, w+, a+)
|
|
159
|
+
* @returns Promise that resolves to a SandboxFile
|
|
160
|
+
*/
|
|
161
|
+
open(path: string, mode?: SandboxFileMode): Promise<SandboxFile>;
|
|
125
162
|
exec(command: string[], options?: ExecOptions & {
|
|
126
163
|
mode?: "text";
|
|
127
164
|
}): Promise<ContainerProcess<string>>;
|
|
@@ -377,4 +414,4 @@ declare class Queue {
|
|
|
377
414
|
iterate(options?: QueueIterateOptions): AsyncGenerator<any, void, unknown>;
|
|
378
415
|
}
|
|
379
416
|
|
|
380
|
-
export { App, Cls, ClsInstance, ContainerProcess, type DeleteOptions, type EphemeralOptions, type ExecOptions, FunctionCall, type FunctionCallCancelOptions, type FunctionCallGetOptions, FunctionTimeoutError, Function_, Image, InternalFailure, InvalidError, type LookupOptions, type ModalReadStream, type ModalWriteStream, NotFoundError, Queue, type QueueClearOptions, QueueEmptyError, QueueFullError, type QueueGetOptions, type QueueIterateOptions, type QueueLenOptions, type QueuePutOptions, RemoteError, Sandbox, type SandboxCreateOptions, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode };
|
|
417
|
+
export { App, Cls, ClsInstance, ContainerProcess, type DeleteOptions, type EphemeralOptions, type ExecOptions, FunctionCall, type FunctionCallCancelOptions, type FunctionCallGetOptions, FunctionTimeoutError, Function_, Image, InternalFailure, InvalidError, type LookupOptions, type ModalReadStream, type ModalWriteStream, NotFoundError, Queue, type QueueClearOptions, QueueEmptyError, QueueFullError, type QueueGetOptions, type QueueIterateOptions, type QueueLenOptions, type QueuePutOptions, RemoteError, Sandbox, type SandboxCreateOptions, SandboxFile, type SandboxFileMode, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode };
|
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,36 @@ declare class Image {
|
|
|
57
57
|
constructor(imageId: string);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/** File open modes supported by the filesystem API. */
|
|
61
|
+
type SandboxFileMode = "r" | "w" | "a" | "r+" | "w+" | "a+";
|
|
62
|
+
/**
|
|
63
|
+
* SandboxFile represents an open file in the sandbox filesystem.
|
|
64
|
+
* Provides read/write operations similar to Node.js `fsPromises.FileHandle`.
|
|
65
|
+
*/
|
|
66
|
+
declare class SandboxFile {
|
|
67
|
+
#private;
|
|
68
|
+
/** @ignore */
|
|
69
|
+
constructor(fileDescriptor: string, taskId: string);
|
|
70
|
+
/**
|
|
71
|
+
* Read data from the file.
|
|
72
|
+
* @returns Promise that resolves to the read data as Uint8Array
|
|
73
|
+
*/
|
|
74
|
+
read(): Promise<Uint8Array>;
|
|
75
|
+
/**
|
|
76
|
+
* Write data to the file.
|
|
77
|
+
* @param data - Data to write (string or Uint8Array)
|
|
78
|
+
*/
|
|
79
|
+
write(data: Uint8Array): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Flush any buffered data to the file.
|
|
82
|
+
*/
|
|
83
|
+
flush(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Close the file handle.
|
|
86
|
+
*/
|
|
87
|
+
close(): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
|
|
60
90
|
/**
|
|
61
91
|
* Wrapper around `ReadableStream` with convenience functions.
|
|
62
92
|
*
|
|
@@ -122,6 +152,13 @@ declare class Sandbox {
|
|
|
122
152
|
stderr: ModalReadStream<string>;
|
|
123
153
|
/** @ignore */
|
|
124
154
|
constructor(sandboxId: string);
|
|
155
|
+
/**
|
|
156
|
+
* Open a file in the sandbox filesystem.
|
|
157
|
+
* @param path - Path to the file to open
|
|
158
|
+
* @param mode - File open mode (r, w, a, r+, w+, a+)
|
|
159
|
+
* @returns Promise that resolves to a SandboxFile
|
|
160
|
+
*/
|
|
161
|
+
open(path: string, mode?: SandboxFileMode): Promise<SandboxFile>;
|
|
125
162
|
exec(command: string[], options?: ExecOptions & {
|
|
126
163
|
mode?: "text";
|
|
127
164
|
}): Promise<ContainerProcess<string>>;
|
|
@@ -377,4 +414,4 @@ declare class Queue {
|
|
|
377
414
|
iterate(options?: QueueIterateOptions): AsyncGenerator<any, void, unknown>;
|
|
378
415
|
}
|
|
379
416
|
|
|
380
|
-
export { App, Cls, ClsInstance, ContainerProcess, type DeleteOptions, type EphemeralOptions, type ExecOptions, FunctionCall, type FunctionCallCancelOptions, type FunctionCallGetOptions, FunctionTimeoutError, Function_, Image, InternalFailure, InvalidError, type LookupOptions, type ModalReadStream, type ModalWriteStream, NotFoundError, Queue, type QueueClearOptions, QueueEmptyError, QueueFullError, type QueueGetOptions, type QueueIterateOptions, type QueueLenOptions, type QueuePutOptions, RemoteError, Sandbox, type SandboxCreateOptions, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode };
|
|
417
|
+
export { App, Cls, ClsInstance, ContainerProcess, type DeleteOptions, type EphemeralOptions, type ExecOptions, FunctionCall, type FunctionCallCancelOptions, type FunctionCallGetOptions, FunctionTimeoutError, Function_, Image, InternalFailure, InvalidError, type LookupOptions, type ModalReadStream, type ModalWriteStream, NotFoundError, Queue, type QueueClearOptions, QueueEmptyError, QueueFullError, type QueueGetOptions, type QueueIterateOptions, type QueueLenOptions, type QueuePutOptions, RemoteError, Sandbox, type SandboxCreateOptions, SandboxFile, type SandboxFileMode, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode };
|
package/dist/index.js
CHANGED
|
@@ -38040,6 +38040,156 @@ ${result.exception}`
|
|
|
38040
38040
|
return new Image2(resp.imageId);
|
|
38041
38041
|
}
|
|
38042
38042
|
|
|
38043
|
+
// src/errors.ts
|
|
38044
|
+
var FunctionTimeoutError = class extends Error {
|
|
38045
|
+
constructor(message) {
|
|
38046
|
+
super(message);
|
|
38047
|
+
this.name = "FunctionTimeoutError";
|
|
38048
|
+
}
|
|
38049
|
+
};
|
|
38050
|
+
var RemoteError = class extends Error {
|
|
38051
|
+
constructor(message) {
|
|
38052
|
+
super(message);
|
|
38053
|
+
this.name = "RemoteError";
|
|
38054
|
+
}
|
|
38055
|
+
};
|
|
38056
|
+
var InternalFailure = class extends Error {
|
|
38057
|
+
constructor(message) {
|
|
38058
|
+
super(message);
|
|
38059
|
+
this.name = "InternalFailure";
|
|
38060
|
+
}
|
|
38061
|
+
};
|
|
38062
|
+
var NotFoundError = class extends Error {
|
|
38063
|
+
constructor(message) {
|
|
38064
|
+
super(message);
|
|
38065
|
+
this.name = "NotFoundError";
|
|
38066
|
+
}
|
|
38067
|
+
};
|
|
38068
|
+
var InvalidError = class extends Error {
|
|
38069
|
+
constructor(message) {
|
|
38070
|
+
super(message);
|
|
38071
|
+
this.name = "InvalidError";
|
|
38072
|
+
}
|
|
38073
|
+
};
|
|
38074
|
+
var QueueEmptyError = class extends Error {
|
|
38075
|
+
constructor(message) {
|
|
38076
|
+
super(message);
|
|
38077
|
+
this.name = "QueueEmptyError";
|
|
38078
|
+
}
|
|
38079
|
+
};
|
|
38080
|
+
var QueueFullError = class extends Error {
|
|
38081
|
+
constructor(message) {
|
|
38082
|
+
super(message);
|
|
38083
|
+
this.name = "QueueFullError";
|
|
38084
|
+
}
|
|
38085
|
+
};
|
|
38086
|
+
var SandboxFilesystemError = class extends Error {
|
|
38087
|
+
constructor(message) {
|
|
38088
|
+
super(message);
|
|
38089
|
+
this.name = "SandboxFilesystemError";
|
|
38090
|
+
}
|
|
38091
|
+
};
|
|
38092
|
+
|
|
38093
|
+
// src/sandbox_filesystem.ts
|
|
38094
|
+
var SandboxFile = class {
|
|
38095
|
+
#fileDescriptor;
|
|
38096
|
+
#taskId;
|
|
38097
|
+
/** @ignore */
|
|
38098
|
+
constructor(fileDescriptor, taskId) {
|
|
38099
|
+
this.#fileDescriptor = fileDescriptor;
|
|
38100
|
+
this.#taskId = taskId;
|
|
38101
|
+
}
|
|
38102
|
+
/**
|
|
38103
|
+
* Read data from the file.
|
|
38104
|
+
* @returns Promise that resolves to the read data as Uint8Array
|
|
38105
|
+
*/
|
|
38106
|
+
async read() {
|
|
38107
|
+
const resp = await runFilesystemExec({
|
|
38108
|
+
fileReadRequest: {
|
|
38109
|
+
fileDescriptor: this.#fileDescriptor
|
|
38110
|
+
},
|
|
38111
|
+
taskId: this.#taskId
|
|
38112
|
+
});
|
|
38113
|
+
const chunks = resp.chunks;
|
|
38114
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
38115
|
+
const result = new Uint8Array(totalLength);
|
|
38116
|
+
let offset = 0;
|
|
38117
|
+
for (const chunk of chunks) {
|
|
38118
|
+
result.set(chunk, offset);
|
|
38119
|
+
offset += chunk.length;
|
|
38120
|
+
}
|
|
38121
|
+
return result;
|
|
38122
|
+
}
|
|
38123
|
+
/**
|
|
38124
|
+
* Write data to the file.
|
|
38125
|
+
* @param data - Data to write (string or Uint8Array)
|
|
38126
|
+
*/
|
|
38127
|
+
async write(data) {
|
|
38128
|
+
await runFilesystemExec({
|
|
38129
|
+
fileWriteRequest: {
|
|
38130
|
+
fileDescriptor: this.#fileDescriptor,
|
|
38131
|
+
data
|
|
38132
|
+
},
|
|
38133
|
+
taskId: this.#taskId
|
|
38134
|
+
});
|
|
38135
|
+
}
|
|
38136
|
+
/**
|
|
38137
|
+
* Flush any buffered data to the file.
|
|
38138
|
+
*/
|
|
38139
|
+
async flush() {
|
|
38140
|
+
await runFilesystemExec({
|
|
38141
|
+
fileFlushRequest: {
|
|
38142
|
+
fileDescriptor: this.#fileDescriptor
|
|
38143
|
+
},
|
|
38144
|
+
taskId: this.#taskId
|
|
38145
|
+
});
|
|
38146
|
+
}
|
|
38147
|
+
/**
|
|
38148
|
+
* Close the file handle.
|
|
38149
|
+
*/
|
|
38150
|
+
async close() {
|
|
38151
|
+
await runFilesystemExec({
|
|
38152
|
+
fileCloseRequest: {
|
|
38153
|
+
fileDescriptor: this.#fileDescriptor
|
|
38154
|
+
},
|
|
38155
|
+
taskId: this.#taskId
|
|
38156
|
+
});
|
|
38157
|
+
}
|
|
38158
|
+
};
|
|
38159
|
+
async function runFilesystemExec(request) {
|
|
38160
|
+
const response = await client.containerFilesystemExec(request);
|
|
38161
|
+
const chunks = [];
|
|
38162
|
+
let retries = 10;
|
|
38163
|
+
let completed = false;
|
|
38164
|
+
while (!completed) {
|
|
38165
|
+
try {
|
|
38166
|
+
const outputIterator = client.containerFilesystemExecGetOutput({
|
|
38167
|
+
execId: response.execId,
|
|
38168
|
+
timeout: 55
|
|
38169
|
+
});
|
|
38170
|
+
for await (const batch of outputIterator) {
|
|
38171
|
+
chunks.push(...batch.output);
|
|
38172
|
+
if (batch.eof) {
|
|
38173
|
+
completed = true;
|
|
38174
|
+
break;
|
|
38175
|
+
}
|
|
38176
|
+
if (batch.error !== void 0) {
|
|
38177
|
+
if (retries > 0) {
|
|
38178
|
+
retries--;
|
|
38179
|
+
break;
|
|
38180
|
+
}
|
|
38181
|
+
throw new SandboxFilesystemError(batch.error.errorMessage);
|
|
38182
|
+
}
|
|
38183
|
+
}
|
|
38184
|
+
} catch (err) {
|
|
38185
|
+
if (isRetryableGrpc(err) && retries > 0) {
|
|
38186
|
+
retries--;
|
|
38187
|
+
} else throw err;
|
|
38188
|
+
}
|
|
38189
|
+
}
|
|
38190
|
+
return { chunks, response };
|
|
38191
|
+
}
|
|
38192
|
+
|
|
38043
38193
|
// src/streams.ts
|
|
38044
38194
|
function toModalReadStream(stream) {
|
|
38045
38195
|
return Object.assign(stream, readMixin);
|
|
@@ -38172,28 +38322,50 @@ var Sandbox2 = class {
|
|
|
38172
38322
|
).pipeThrough(new TextDecoderStream())
|
|
38173
38323
|
);
|
|
38174
38324
|
}
|
|
38325
|
+
/**
|
|
38326
|
+
* Open a file in the sandbox filesystem.
|
|
38327
|
+
* @param path - Path to the file to open
|
|
38328
|
+
* @param mode - File open mode (r, w, a, r+, w+, a+)
|
|
38329
|
+
* @returns Promise that resolves to a SandboxFile
|
|
38330
|
+
*/
|
|
38331
|
+
async open(path2, mode = "r") {
|
|
38332
|
+
const taskId = await this.#getTaskId();
|
|
38333
|
+
const resp = await runFilesystemExec({
|
|
38334
|
+
fileOpenRequest: {
|
|
38335
|
+
path: path2,
|
|
38336
|
+
mode
|
|
38337
|
+
},
|
|
38338
|
+
taskId
|
|
38339
|
+
});
|
|
38340
|
+
const fileDescriptor = resp.response.fileDescriptor;
|
|
38341
|
+
return new SandboxFile(fileDescriptor, taskId);
|
|
38342
|
+
}
|
|
38175
38343
|
async exec(command, options) {
|
|
38344
|
+
const taskId = await this.#getTaskId();
|
|
38345
|
+
const resp = await client.containerExec({
|
|
38346
|
+
taskId,
|
|
38347
|
+
command
|
|
38348
|
+
});
|
|
38349
|
+
return new ContainerProcess(resp.execId, options);
|
|
38350
|
+
}
|
|
38351
|
+
async #getTaskId() {
|
|
38176
38352
|
if (this.#taskId === void 0) {
|
|
38177
|
-
const
|
|
38353
|
+
const resp = await client.sandboxGetTaskId({
|
|
38178
38354
|
sandboxId: this.sandboxId
|
|
38179
38355
|
});
|
|
38180
|
-
if (!
|
|
38356
|
+
if (!resp.taskId) {
|
|
38181
38357
|
throw new Error(
|
|
38182
38358
|
`Sandbox ${this.sandboxId} does not have a task ID. It may not be running.`
|
|
38183
38359
|
);
|
|
38184
38360
|
}
|
|
38185
|
-
if (
|
|
38361
|
+
if (resp.taskResult) {
|
|
38186
38362
|
throw new Error(
|
|
38187
|
-
`Sandbox ${this.sandboxId} has already completed with result: ${
|
|
38363
|
+
`Sandbox ${this.sandboxId} has already completed with result: ${resp.taskResult}`
|
|
38188
38364
|
);
|
|
38189
38365
|
}
|
|
38190
|
-
this.#taskId =
|
|
38366
|
+
this.#taskId = resp.taskId;
|
|
38191
38367
|
}
|
|
38192
|
-
|
|
38193
|
-
taskId: this.#taskId,
|
|
38194
|
-
command
|
|
38195
|
-
});
|
|
38196
|
-
return new ContainerProcess(resp.execId, options);
|
|
38368
|
+
return this.#taskId;
|
|
38197
38369
|
}
|
|
38198
38370
|
async terminate() {
|
|
38199
38371
|
await client.sandboxTerminate({ sandboxId: this.sandboxId });
|
|
@@ -38363,50 +38535,6 @@ function encodeIfString(chunk) {
|
|
|
38363
38535
|
return typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk;
|
|
38364
38536
|
}
|
|
38365
38537
|
|
|
38366
|
-
// src/errors.ts
|
|
38367
|
-
var FunctionTimeoutError = class extends Error {
|
|
38368
|
-
constructor(message) {
|
|
38369
|
-
super(message);
|
|
38370
|
-
this.name = "FunctionTimeoutError";
|
|
38371
|
-
}
|
|
38372
|
-
};
|
|
38373
|
-
var RemoteError = class extends Error {
|
|
38374
|
-
constructor(message) {
|
|
38375
|
-
super(message);
|
|
38376
|
-
this.name = "RemoteError";
|
|
38377
|
-
}
|
|
38378
|
-
};
|
|
38379
|
-
var InternalFailure = class extends Error {
|
|
38380
|
-
constructor(message) {
|
|
38381
|
-
super(message);
|
|
38382
|
-
this.name = "InternalFailure";
|
|
38383
|
-
}
|
|
38384
|
-
};
|
|
38385
|
-
var NotFoundError = class extends Error {
|
|
38386
|
-
constructor(message) {
|
|
38387
|
-
super(message);
|
|
38388
|
-
this.name = "NotFoundError";
|
|
38389
|
-
}
|
|
38390
|
-
};
|
|
38391
|
-
var InvalidError = class extends Error {
|
|
38392
|
-
constructor(message) {
|
|
38393
|
-
super(message);
|
|
38394
|
-
this.name = "InvalidError";
|
|
38395
|
-
}
|
|
38396
|
-
};
|
|
38397
|
-
var QueueEmptyError = class extends Error {
|
|
38398
|
-
constructor(message) {
|
|
38399
|
-
super(message);
|
|
38400
|
-
this.name = "QueueEmptyError";
|
|
38401
|
-
}
|
|
38402
|
-
};
|
|
38403
|
-
var QueueFullError = class extends Error {
|
|
38404
|
-
constructor(message) {
|
|
38405
|
-
super(message);
|
|
38406
|
-
this.name = "QueueFullError";
|
|
38407
|
-
}
|
|
38408
|
-
};
|
|
38409
|
-
|
|
38410
38538
|
// src/secret.ts
|
|
38411
38539
|
import { ClientError as ClientError2, Status as Status2 } from "nice-grpc";
|
|
38412
38540
|
var Secret = class _Secret {
|
|
@@ -39523,5 +39651,6 @@ export {
|
|
|
39523
39651
|
QueueFullError,
|
|
39524
39652
|
RemoteError,
|
|
39525
39653
|
Sandbox2 as Sandbox,
|
|
39654
|
+
SandboxFile,
|
|
39526
39655
|
Secret
|
|
39527
39656
|
};
|