rl-rock 1.3.6 → 1.3.8

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.mjs CHANGED
@@ -597,6 +597,9 @@ var envVars = {
597
597
  get ROCK_OSS_BUCKET_REGION() {
598
598
  return getEnv("ROCK_OSS_BUCKET_REGION");
599
599
  },
600
+ get ROCK_OSS_TIMEOUT() {
601
+ return parseInt(getEnv("ROCK_OSS_TIMEOUT", "300000"), 10);
602
+ },
600
603
  // Pip
601
604
  get ROCK_PIP_INDEX_URL() {
602
605
  return getEnv("ROCK_PIP_INDEX_URL", "https://pypi.org/simple/");
@@ -2291,7 +2294,7 @@ var Sandbox = class extends AbstractSandbox {
2291
2294
  async upload(request) {
2292
2295
  return this.uploadByPath(request.sourcePath, request.targetPath);
2293
2296
  }
2294
- async uploadByPath(sourcePath, targetPath, uploadMode = "auto") {
2297
+ async uploadByPath(sourcePath, targetPath, uploadMode = "auto", timeout) {
2295
2298
  const url = `${this.url}/upload`;
2296
2299
  const headers = this.buildHeaders();
2297
2300
  try {
@@ -2306,7 +2309,7 @@ var Sandbox = class extends AbstractSandbox {
2306
2309
  const ossEnabled = envVars.ROCK_OSS_ENABLE;
2307
2310
  const ossThreshold = 1024 * 1024;
2308
2311
  if (uploadMode === "oss" || uploadMode === "auto" && ossEnabled && fileSize > ossThreshold) {
2309
- return this.uploadViaOss(sourcePath, targetPath);
2312
+ return this.uploadViaOss(sourcePath, targetPath, timeout);
2310
2313
  }
2311
2314
  const fileBuffer = await fs.readFile(sourcePath);
2312
2315
  const fileName = sourcePath.split("/").pop() ?? "file";
@@ -2357,7 +2360,7 @@ var Sandbox = class extends AbstractSandbox {
2357
2360
  /**
2358
2361
  * Download file from sandbox via OSS
2359
2362
  */
2360
- async downloadFile(remotePath, localPath) {
2363
+ async downloadFile(remotePath, localPath, timeout) {
2361
2364
  if (!envVars.ROCK_OSS_ENABLE) {
2362
2365
  return {
2363
2366
  success: false,
@@ -2373,7 +2376,7 @@ var Sandbox = class extends AbstractSandbox {
2373
2376
  return { success: false, message: `Remote file does not exist: ${remotePath}` };
2374
2377
  }
2375
2378
  if (this.ossBucket === null || this.isTokenExpired()) {
2376
- await this.setupOss();
2379
+ await this.setupOss(timeout);
2377
2380
  }
2378
2381
  if (!this.ossBucket) {
2379
2382
  return { success: false, message: "Failed to setup OSS bucket" };
@@ -2386,12 +2389,14 @@ var Sandbox = class extends AbstractSandbox {
2386
2389
  const bucketName = envVars.ROCK_OSS_BUCKET_NAME ?? "";
2387
2390
  const region = (envVars.ROCK_OSS_BUCKET_REGION ?? "").replace(/^oss-/, "");
2388
2391
  const endpoint = envVars.ROCK_OSS_BUCKET_ENDPOINT ?? `oss-${region}.aliyuncs.com`;
2389
- const uploadToOssCmd = `ossutil cp '${remotePath}' 'oss://${bucketName}/${objectName}' --access-key-id '${credentials.accessKeyId}' --access-key-secret '${credentials.accessKeySecret}' --sts-token '${credentials.securityToken}' --endpoint '${endpoint}' --region '${region}'`;
2392
+ const ossutilInnerCmd = `ossutil cp '${remotePath}' 'oss://${bucketName}/${objectName}' --access-key-id '${credentials.accessKeyId}' --access-key-secret '${credentials.accessKeySecret}' --sts-token '${credentials.securityToken}' --endpoint '${endpoint}' --region '${region}'`;
2393
+ const uploadToOssCmd = `bash -c '${ossutilInnerCmd.replace(/'/g, `'"'"'`)}'`;
2390
2394
  const uploadResult = await this.arun(uploadToOssCmd, { mode: "nohup", waitTimeout: 600 });
2391
2395
  if (uploadResult.exitCode !== 0) {
2392
2396
  return { success: false, message: `Sandbox to OSS upload failed: ${uploadResult.output}` };
2393
2397
  }
2394
- const result = await this.ossBucket.get(objectName, localPath);
2398
+ const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
2399
+ const result = await this.ossBucket.get(objectName, localPath, { timeout: ossTimeout });
2395
2400
  try {
2396
2401
  await this.ossBucket.delete(objectName);
2397
2402
  } catch {
@@ -2403,11 +2408,12 @@ var Sandbox = class extends AbstractSandbox {
2403
2408
  }
2404
2409
  /**
2405
2410
  * Upload file via OSS (internal method)
2411
+ * @param timeout - Optional timeout in milliseconds
2406
2412
  */
2407
- async uploadViaOss(sourcePath, targetPath) {
2413
+ async uploadViaOss(sourcePath, targetPath, timeout) {
2408
2414
  try {
2409
2415
  if (this.ossBucket === null || this.isTokenExpired()) {
2410
- await this.setupOss();
2416
+ await this.setupOss(timeout);
2411
2417
  }
2412
2418
  if (!this.ossBucket) {
2413
2419
  return { success: false, message: "Failed to setup OSS bucket" };
@@ -2415,7 +2421,8 @@ var Sandbox = class extends AbstractSandbox {
2415
2421
  const timestamp = Date.now();
2416
2422
  const fileName = sourcePath.split("/").pop() ?? "file";
2417
2423
  const objectName = `${timestamp}-${fileName}`;
2418
- await this.ossBucket.put(objectName, sourcePath);
2424
+ const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
2425
+ await this.ossBucket.put(objectName, sourcePath, { timeout: ossTimeout });
2419
2426
  const signedUrl = this.ossBucket.signatureUrl(objectName, { expires: 600 });
2420
2427
  const downloadCmd = `wget -c -O '${targetPath}' '${signedUrl}'`;
2421
2428
  await this.arun(downloadCmd, { mode: "nohup", waitTimeout: 600 });
@@ -2430,13 +2437,16 @@ var Sandbox = class extends AbstractSandbox {
2430
2437
  }
2431
2438
  /**
2432
2439
  * Setup OSS bucket with STS credentials
2440
+ * @param timeout - Optional timeout in milliseconds (defaults to ROCK_OSS_TIMEOUT env var or 300000ms)
2433
2441
  */
2434
- async setupOss() {
2442
+ async setupOss(timeout) {
2435
2443
  const credentials = await this.getOssStsCredentials();
2436
2444
  const OSS = (await import('ali-oss')).default;
2445
+ const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
2437
2446
  this.ossBucket = new OSS({
2438
2447
  secure: true,
2439
2448
  // Use HTTPS for OSS connections
2449
+ timeout: ossTimeout,
2440
2450
  region: envVars.ROCK_OSS_BUCKET_REGION ?? "",
2441
2451
  accessKeyId: credentials.accessKeyId,
2442
2452
  accessKeySecret: credentials.accessKeySecret,