rl-rock 1.3.8 → 1.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.d.mts +61 -4
- package/dist/index.d.ts +61 -4
- package/dist/index.js +103 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -76,6 +76,7 @@ var ReadFileRequestSchema = z.object({
|
|
|
76
76
|
errors: z.string().optional()
|
|
77
77
|
});
|
|
78
78
|
var UploadModeSchema = z.enum(["auto", "direct", "oss"]);
|
|
79
|
+
var DownloadModeSchema = z.enum(["auto", "direct", "oss"]);
|
|
79
80
|
var UploadRequestSchema = z.object({
|
|
80
81
|
sourcePath: z.string(),
|
|
81
82
|
targetPath: z.string(),
|
|
@@ -2294,9 +2295,12 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2294
2295
|
async upload(request) {
|
|
2295
2296
|
return this.uploadByPath(request.sourcePath, request.targetPath);
|
|
2296
2297
|
}
|
|
2297
|
-
async uploadByPath(sourcePath, targetPath,
|
|
2298
|
+
async uploadByPath(sourcePath, targetPath, options) {
|
|
2298
2299
|
const url = `${this.url}/upload`;
|
|
2299
2300
|
const headers = this.buildHeaders();
|
|
2301
|
+
const uploadMode = options?.uploadMode ?? "auto";
|
|
2302
|
+
const timeout = options?.timeout;
|
|
2303
|
+
const onProgress = options?.onProgress;
|
|
2300
2304
|
try {
|
|
2301
2305
|
const fs = await import('fs/promises');
|
|
2302
2306
|
try {
|
|
@@ -2309,7 +2313,7 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2309
2313
|
const ossEnabled = envVars.ROCK_OSS_ENABLE;
|
|
2310
2314
|
const ossThreshold = 1024 * 1024;
|
|
2311
2315
|
if (uploadMode === "oss" || uploadMode === "auto" && ossEnabled && fileSize > ossThreshold) {
|
|
2312
|
-
return this.uploadViaOss(sourcePath, targetPath, timeout);
|
|
2316
|
+
return this.uploadViaOss(sourcePath, targetPath, timeout, onProgress);
|
|
2313
2317
|
}
|
|
2314
2318
|
const fileBuffer = await fs.readFile(sourcePath);
|
|
2315
2319
|
const fileName = sourcePath.split("/").pop() ?? "file";
|
|
@@ -2358,9 +2362,61 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2358
2362
|
}
|
|
2359
2363
|
}
|
|
2360
2364
|
/**
|
|
2361
|
-
* Download file from sandbox
|
|
2365
|
+
* Download file from sandbox
|
|
2366
|
+
* @param remotePath - File path in sandbox
|
|
2367
|
+
* @param localPath - Local file path
|
|
2368
|
+
* @param downloadMode - Download mode: 'auto' (default), 'direct', or 'oss'
|
|
2369
|
+
* @param timeout - Optional timeout in milliseconds for OSS mode
|
|
2362
2370
|
*/
|
|
2363
|
-
async downloadFile(remotePath, localPath,
|
|
2371
|
+
async downloadFile(remotePath, localPath, options) {
|
|
2372
|
+
const downloadMode = options?.downloadMode ?? "auto";
|
|
2373
|
+
const timeout = options?.timeout;
|
|
2374
|
+
const onProgress = options?.onProgress;
|
|
2375
|
+
if (!remotePath || remotePath.trim() === "") {
|
|
2376
|
+
return { success: false, message: "Remote path is required" };
|
|
2377
|
+
}
|
|
2378
|
+
const checkResult = await this.execute({ command: ["test", "-f", remotePath], timeout: 60 });
|
|
2379
|
+
if (checkResult.exitCode !== 0) {
|
|
2380
|
+
return { success: false, message: `Remote file does not exist: ${remotePath}` };
|
|
2381
|
+
}
|
|
2382
|
+
if (downloadMode === "direct") {
|
|
2383
|
+
return this.downloadDirect(remotePath, localPath);
|
|
2384
|
+
}
|
|
2385
|
+
if (downloadMode === "oss") {
|
|
2386
|
+
return this.downloadViaOss(remotePath, localPath, timeout, onProgress);
|
|
2387
|
+
}
|
|
2388
|
+
const sizeResult = await this.execute({ command: ["stat", "-c", "%s", remotePath], timeout: 60 });
|
|
2389
|
+
if (sizeResult.exitCode !== 0) {
|
|
2390
|
+
return this.downloadDirect(remotePath, localPath);
|
|
2391
|
+
}
|
|
2392
|
+
const fileSize = parseInt(sizeResult.stdout.trim(), 10);
|
|
2393
|
+
const ossThreshold = 1024 * 1024;
|
|
2394
|
+
const ossEnabled = envVars.ROCK_OSS_ENABLE;
|
|
2395
|
+
if (ossEnabled && fileSize >= ossThreshold) {
|
|
2396
|
+
return this.downloadViaOss(remotePath, localPath, timeout, onProgress);
|
|
2397
|
+
}
|
|
2398
|
+
return this.downloadDirect(remotePath, localPath);
|
|
2399
|
+
}
|
|
2400
|
+
/**
|
|
2401
|
+
* Download file directly via readFile API
|
|
2402
|
+
*/
|
|
2403
|
+
async downloadDirect(remotePath, localPath) {
|
|
2404
|
+
try {
|
|
2405
|
+
const fs = await import('fs/promises');
|
|
2406
|
+
const path2 = await import('path');
|
|
2407
|
+
const response = await this.readFile({ path: remotePath });
|
|
2408
|
+
const parentDir = path2.dirname(localPath);
|
|
2409
|
+
await fs.mkdir(parentDir, { recursive: true });
|
|
2410
|
+
await fs.writeFile(localPath, response.content, "utf-8");
|
|
2411
|
+
return { success: true, message: `Successfully downloaded ${remotePath} to ${localPath}` };
|
|
2412
|
+
} catch (e) {
|
|
2413
|
+
return { success: false, message: `Direct download failed: ${e}` };
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
/**
|
|
2417
|
+
* Download file via OSS as intermediary
|
|
2418
|
+
*/
|
|
2419
|
+
async downloadViaOss(remotePath, localPath, timeout, onProgress) {
|
|
2364
2420
|
if (!envVars.ROCK_OSS_ENABLE) {
|
|
2365
2421
|
return {
|
|
2366
2422
|
success: false,
|
|
@@ -2368,13 +2424,6 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2368
2424
|
};
|
|
2369
2425
|
}
|
|
2370
2426
|
try {
|
|
2371
|
-
if (!remotePath || remotePath.trim() === "") {
|
|
2372
|
-
return { success: false, message: "Remote path is required" };
|
|
2373
|
-
}
|
|
2374
|
-
const checkResult = await this.execute({ command: ["test", "-f", remotePath], timeout: 60 });
|
|
2375
|
-
if (checkResult.exitCode !== 0) {
|
|
2376
|
-
return { success: false, message: `Remote file does not exist: ${remotePath}` };
|
|
2377
|
-
}
|
|
2378
2427
|
if (this.ossBucket === null || this.isTokenExpired()) {
|
|
2379
2428
|
await this.setupOss(timeout);
|
|
2380
2429
|
}
|
|
@@ -2396,21 +2445,29 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2396
2445
|
return { success: false, message: `Sandbox to OSS upload failed: ${uploadResult.output}` };
|
|
2397
2446
|
}
|
|
2398
2447
|
const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
|
|
2399
|
-
const result = await this.ossBucket.get(objectName, localPath, {
|
|
2448
|
+
const result = await this.ossBucket.get(objectName, localPath, {
|
|
2449
|
+
timeout: ossTimeout,
|
|
2450
|
+
progress: (p) => {
|
|
2451
|
+
onProgress?.({
|
|
2452
|
+
phase: "download-to-local",
|
|
2453
|
+
percent: Math.round(p * 100)
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
});
|
|
2400
2457
|
try {
|
|
2401
2458
|
await this.ossBucket.delete(objectName);
|
|
2402
2459
|
} catch {
|
|
2403
2460
|
}
|
|
2404
2461
|
return { success: true, message: `Successfully downloaded ${remotePath} to ${localPath}` };
|
|
2405
2462
|
} catch (e) {
|
|
2406
|
-
return { success: false, message: `
|
|
2463
|
+
return { success: false, message: `OSS download failed: ${e}` };
|
|
2407
2464
|
}
|
|
2408
2465
|
}
|
|
2409
2466
|
/**
|
|
2410
2467
|
* Upload file via OSS (internal method)
|
|
2411
2468
|
* @param timeout - Optional timeout in milliseconds
|
|
2412
2469
|
*/
|
|
2413
|
-
async uploadViaOss(sourcePath, targetPath, timeout) {
|
|
2470
|
+
async uploadViaOss(sourcePath, targetPath, timeout, onProgress) {
|
|
2414
2471
|
try {
|
|
2415
2472
|
if (this.ossBucket === null || this.isTokenExpired()) {
|
|
2416
2473
|
await this.setupOss(timeout);
|
|
@@ -2421,9 +2478,39 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2421
2478
|
const timestamp = Date.now();
|
|
2422
2479
|
const fileName = sourcePath.split("/").pop() ?? "file";
|
|
2423
2480
|
const objectName = `${timestamp}-${fileName}`;
|
|
2481
|
+
const fs = await import('fs/promises');
|
|
2482
|
+
const stats = await fs.stat(sourcePath);
|
|
2483
|
+
const fileSize = stats.size;
|
|
2484
|
+
const multipartThreshold = 1024 * 1024;
|
|
2424
2485
|
const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
|
|
2425
|
-
|
|
2486
|
+
if (fileSize >= multipartThreshold) {
|
|
2487
|
+
await this.ossBucket.multipartUpload(objectName, sourcePath, {
|
|
2488
|
+
timeout: ossTimeout,
|
|
2489
|
+
partSize: multipartThreshold,
|
|
2490
|
+
// 1MB per part
|
|
2491
|
+
progress: (p) => {
|
|
2492
|
+
onProgress?.({
|
|
2493
|
+
phase: "upload-to-oss",
|
|
2494
|
+
percent: Math.round(p * 100)
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
});
|
|
2498
|
+
} else {
|
|
2499
|
+
await this.ossBucket.put(objectName, sourcePath, {
|
|
2500
|
+
timeout: ossTimeout,
|
|
2501
|
+
progress: (p) => {
|
|
2502
|
+
onProgress?.({
|
|
2503
|
+
phase: "upload-to-oss",
|
|
2504
|
+
percent: Math.round(p * 100)
|
|
2505
|
+
});
|
|
2506
|
+
}
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2426
2509
|
const signedUrl = this.ossBucket.signatureUrl(objectName, { expires: 600 });
|
|
2510
|
+
onProgress?.({
|
|
2511
|
+
phase: "download-to-sandbox",
|
|
2512
|
+
percent: -1
|
|
2513
|
+
});
|
|
2427
2514
|
const downloadCmd = `wget -c -O '${targetPath}' '${signedUrl}'`;
|
|
2428
2515
|
await this.arun(downloadCmd, { mode: "nohup", waitTimeout: 600 });
|
|
2429
2516
|
const checkResult = await this.execute({ command: ["test", "-f", targetPath], timeout: 60 });
|
|
@@ -3407,6 +3494,6 @@ function getVersion() {
|
|
|
3407
3494
|
}
|
|
3408
3495
|
var VERSION = getVersion();
|
|
3409
3496
|
|
|
3410
|
-
export { Agent, AgentBashCommandSchema, AgentConfigSchema, BadRequestRockError, BashActionSchema, ChmodRequestSchema, ChmodResponseSchema, ChownRequestSchema, ChownResponseSchema, CloseResponseSchema, CloseSessionRequestSchema, CloseSessionResponseSchema, Codes, CommandResponseSchema, CommandRockError, CommandSchema, CreateBashSessionRequestSchema, CreateSessionResponseSchema, DefaultAgent, DefaultAgentConfigSchema, Deploy, DownloadFileResponseSchema, EnvHubClient, EnvHubClientConfigSchema, EnvHubError, ExecuteBashSessionResponseSchema, HttpUtils, InternalServerRockError, InvalidParameterRockException, IsAliveResponseSchema, LinuxFileSystem, LinuxRemoteUser, ModelClient, ModelService, ModelServiceConfigSchema, NODE_DEFAULT_VERSION, Network, NodeRuntimeEnv, NodeRuntimeEnvConfigSchema, ObservationSchema, OssCredentialsSchema, OssSetupResponseSchema, PID_PREFIX, PID_SUFFIX, Process, PythonRuntimeEnv, PythonRuntimeEnvConfigSchema, ReadFileRequestSchema, ReadFileResponseSchema, ReasonPhrases, RockAgentConfigSchema, RockEnv, RockEnvInfoSchema, RockException, RunMode, RuntimeEnv, RuntimeEnvConfigSchema, Sandbox, SandboxConfigSchema, SandboxGroup, SandboxGroupConfigSchema, SandboxResponseSchema, SandboxStatusResponseSchema, SpeedupType, UploadModeSchema, UploadRequestSchema, UploadResponseSchema, VERSION, WriteFileRequestSchema, WriteFileResponseSchema, arunWithRetry, createRockEnvInfo, createRuntimeEnvId, createSandboxConfig, createSandboxGroupConfig, deprecated, deprecatedClass, extractNohupPid as extractNohupPidFromSandbox, fromRockException, getDefaultPipIndexUrl, getEnv, getReasonPhrase, getRequiredEnv, isClientError, isCommandError, isEnvSet, isError, isNode, isServerError, isSuccess, make, raiseForCode, retryAsync, sleep, withRetry, withTimeLogging };
|
|
3497
|
+
export { Agent, AgentBashCommandSchema, AgentConfigSchema, BadRequestRockError, BashActionSchema, ChmodRequestSchema, ChmodResponseSchema, ChownRequestSchema, ChownResponseSchema, CloseResponseSchema, CloseSessionRequestSchema, CloseSessionResponseSchema, Codes, CommandResponseSchema, CommandRockError, CommandSchema, CreateBashSessionRequestSchema, CreateSessionResponseSchema, DefaultAgent, DefaultAgentConfigSchema, Deploy, DownloadFileResponseSchema, DownloadModeSchema, EnvHubClient, EnvHubClientConfigSchema, EnvHubError, ExecuteBashSessionResponseSchema, HttpUtils, InternalServerRockError, InvalidParameterRockException, IsAliveResponseSchema, LinuxFileSystem, LinuxRemoteUser, ModelClient, ModelService, ModelServiceConfigSchema, NODE_DEFAULT_VERSION, Network, NodeRuntimeEnv, NodeRuntimeEnvConfigSchema, ObservationSchema, OssCredentialsSchema, OssSetupResponseSchema, PID_PREFIX, PID_SUFFIX, Process, PythonRuntimeEnv, PythonRuntimeEnvConfigSchema, ReadFileRequestSchema, ReadFileResponseSchema, ReasonPhrases, RockAgentConfigSchema, RockEnv, RockEnvInfoSchema, RockException, RunMode, RuntimeEnv, RuntimeEnvConfigSchema, Sandbox, SandboxConfigSchema, SandboxGroup, SandboxGroupConfigSchema, SandboxResponseSchema, SandboxStatusResponseSchema, SpeedupType, UploadModeSchema, UploadRequestSchema, UploadResponseSchema, VERSION, WriteFileRequestSchema, WriteFileResponseSchema, arunWithRetry, createRockEnvInfo, createRuntimeEnvId, createSandboxConfig, createSandboxGroupConfig, deprecated, deprecatedClass, extractNohupPid as extractNohupPidFromSandbox, fromRockException, getDefaultPipIndexUrl, getEnv, getReasonPhrase, getRequiredEnv, isClientError, isCommandError, isEnvSet, isError, isNode, isServerError, isSuccess, make, raiseForCode, retryAsync, sleep, withRetry, withTimeLogging };
|
|
3411
3498
|
//# sourceMappingURL=index.mjs.map
|
|
3412
3499
|
//# sourceMappingURL=index.mjs.map
|