rl-rock 1.3.7 → 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" };
@@ -2392,7 +2395,8 @@ var Sandbox = class extends AbstractSandbox {
2392
2395
  if (uploadResult.exitCode !== 0) {
2393
2396
  return { success: false, message: `Sandbox to OSS upload failed: ${uploadResult.output}` };
2394
2397
  }
2395
- 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 });
2396
2400
  try {
2397
2401
  await this.ossBucket.delete(objectName);
2398
2402
  } catch {
@@ -2404,11 +2408,12 @@ var Sandbox = class extends AbstractSandbox {
2404
2408
  }
2405
2409
  /**
2406
2410
  * Upload file via OSS (internal method)
2411
+ * @param timeout - Optional timeout in milliseconds
2407
2412
  */
2408
- async uploadViaOss(sourcePath, targetPath) {
2413
+ async uploadViaOss(sourcePath, targetPath, timeout) {
2409
2414
  try {
2410
2415
  if (this.ossBucket === null || this.isTokenExpired()) {
2411
- await this.setupOss();
2416
+ await this.setupOss(timeout);
2412
2417
  }
2413
2418
  if (!this.ossBucket) {
2414
2419
  return { success: false, message: "Failed to setup OSS bucket" };
@@ -2416,7 +2421,8 @@ var Sandbox = class extends AbstractSandbox {
2416
2421
  const timestamp = Date.now();
2417
2422
  const fileName = sourcePath.split("/").pop() ?? "file";
2418
2423
  const objectName = `${timestamp}-${fileName}`;
2419
- await this.ossBucket.put(objectName, sourcePath);
2424
+ const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
2425
+ await this.ossBucket.put(objectName, sourcePath, { timeout: ossTimeout });
2420
2426
  const signedUrl = this.ossBucket.signatureUrl(objectName, { expires: 600 });
2421
2427
  const downloadCmd = `wget -c -O '${targetPath}' '${signedUrl}'`;
2422
2428
  await this.arun(downloadCmd, { mode: "nohup", waitTimeout: 600 });
@@ -2431,13 +2437,16 @@ var Sandbox = class extends AbstractSandbox {
2431
2437
  }
2432
2438
  /**
2433
2439
  * Setup OSS bucket with STS credentials
2440
+ * @param timeout - Optional timeout in milliseconds (defaults to ROCK_OSS_TIMEOUT env var or 300000ms)
2434
2441
  */
2435
- async setupOss() {
2442
+ async setupOss(timeout) {
2436
2443
  const credentials = await this.getOssStsCredentials();
2437
2444
  const OSS = (await import('ali-oss')).default;
2445
+ const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
2438
2446
  this.ossBucket = new OSS({
2439
2447
  secure: true,
2440
2448
  // Use HTTPS for OSS connections
2449
+ timeout: ossTimeout,
2441
2450
  region: envVars.ROCK_OSS_BUCKET_REGION ?? "",
2442
2451
  accessKeyId: credentials.accessKeyId,
2443
2452
  accessKeySecret: credentials.accessKeySecret,