rl-rock 1.2.7 → 1.3.0

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/README.md CHANGED
@@ -10,6 +10,8 @@ ROCK (Remote Operation Container Kit) TypeScript SDK - 用于管理远程沙箱
10
10
 
11
11
  - 🚀 **沙箱管理** - 创建、启动、停止远程容器沙箱
12
12
  - 📁 **文件系统** - 上传、下载、读取、写入文件
13
+ - OSS 大文件上传/下载支持
14
+ - 灵活的上传模式选择 (auto/direct/oss)
13
15
  - 🖥️ **命令执行** - 同步/异步执行 Shell 命令
14
16
  - 🔧 **运行时环境** - 支持 Python、Node.js 运行时环境管理(沙箱内安装)
15
17
  - 🤖 **模型服务** - 沙箱内模型服务安装与生命周期管理
@@ -88,6 +90,14 @@ await sandbox.upload({
88
90
  sourcePath: './local-file.txt',
89
91
  targetPath: '/remote/path/file.txt',
90
92
  });
93
+
94
+ // 上传大文件使用 OSS (自动选择)
95
+ await sandbox.uploadByPath('./large-file.zip', '/remote/large-file.zip', 'auto');
96
+ // 强制使用 OSS 上传
97
+ await sandbox.uploadByPath('./large-file.zip', '/remote/large-file.zip', 'oss');
98
+
99
+ // 从沙箱下载文件到本地 (需要配置 OSS)
100
+ await sandbox.downloadFile('/remote/file.txt', './local-file.txt');
91
101
  ```
92
102
 
93
103
  ### 使用 EnvHub
@@ -212,7 +222,7 @@ console.log(result.output);
212
222
  | `ROCK_BASE_URL` | ROCK 服务基础 URL | `http://localhost:8080` |
213
223
  | `ROCK_ENVHUB_BASE_URL` | EnvHub 服务 URL | `http://localhost:8081` |
214
224
  | `ROCK_SANDBOX_STARTUP_TIMEOUT_SECONDS` | 沙箱启动超时时间 | `180` |
215
- | `ROCK_OSS_ENABLE` | 是否启用 OSS 上传 | `false` |
225
+ | `ROCK_OSS_ENABLE` | 是否启用 OSS 上传/下载 | `false` |
216
226
  | `ROCK_OSS_BUCKET_ENDPOINT` | OSS Endpoint | - |
217
227
  | `ROCK_OSS_BUCKET_NAME` | OSS Bucket 名称 | - |
218
228
 
package/dist/index.d.mts CHANGED
@@ -151,18 +151,30 @@ declare const ReadFileRequestSchema: z.ZodObject<{
151
151
  errors?: string | undefined;
152
152
  }>;
153
153
  type ReadFileRequest = z.infer<typeof ReadFileRequestSchema>;
154
+ /**
155
+ * Upload mode enum
156
+ * - auto: Automatically choose upload method based on file size and OSS availability
157
+ * - direct: Force direct HTTP upload
158
+ * - oss: Force OSS upload
159
+ */
160
+ declare const UploadModeSchema: z.ZodEnum<["auto", "direct", "oss"]>;
161
+ type UploadMode = z.infer<typeof UploadModeSchema>;
154
162
  /**
155
163
  * Upload file request
164
+ * Note: uploadMode defaults to 'auto' in the implementation, not in the schema
156
165
  */
157
166
  declare const UploadRequestSchema: z.ZodObject<{
158
167
  sourcePath: z.ZodString;
159
168
  targetPath: z.ZodString;
169
+ uploadMode: z.ZodOptional<z.ZodEnum<["auto", "direct", "oss"]>>;
160
170
  }, "strip", z.ZodTypeAny, {
161
171
  sourcePath: string;
162
172
  targetPath: string;
173
+ uploadMode?: "auto" | "direct" | "oss" | undefined;
163
174
  }, {
164
175
  sourcePath: string;
165
176
  targetPath: string;
177
+ uploadMode?: "auto" | "direct" | "oss" | undefined;
166
178
  }>;
167
179
  type UploadRequest = z.infer<typeof UploadRequestSchema>;
168
180
  /**
@@ -475,6 +487,41 @@ declare const OssSetupResponseSchema: z.ZodObject<{
475
487
  success?: boolean | undefined;
476
488
  }>;
477
489
  type OssSetupResponse = z.infer<typeof OssSetupResponseSchema>;
490
+ /**
491
+ * Download file response
492
+ */
493
+ declare const DownloadFileResponseSchema: z.ZodObject<{
494
+ success: z.ZodDefault<z.ZodBoolean>;
495
+ message: z.ZodDefault<z.ZodString>;
496
+ }, "strip", z.ZodTypeAny, {
497
+ message: string;
498
+ success: boolean;
499
+ }, {
500
+ message?: string | undefined;
501
+ success?: boolean | undefined;
502
+ }>;
503
+ type DownloadFileResponse = z.infer<typeof DownloadFileResponseSchema>;
504
+ /**
505
+ * OSS STS credentials from sandbox /get_token API
506
+ * API returns snake_case, which gets converted to camelCase by HttpUtils
507
+ */
508
+ declare const OssCredentialsSchema: z.ZodObject<{
509
+ accessKeyId: z.ZodString;
510
+ accessKeySecret: z.ZodString;
511
+ securityToken: z.ZodString;
512
+ expiration: z.ZodString;
513
+ }, "strip", z.ZodTypeAny, {
514
+ accessKeyId: string;
515
+ accessKeySecret: string;
516
+ securityToken: string;
517
+ expiration: string;
518
+ }, {
519
+ accessKeyId: string;
520
+ accessKeySecret: string;
521
+ securityToken: string;
522
+ expiration: string;
523
+ }>;
524
+ type OssCredentials = z.infer<typeof OssCredentialsSchema>;
478
525
 
479
526
  /**
480
527
  * Common constants
@@ -1196,6 +1243,8 @@ declare class Sandbox extends AbstractSandbox {
1196
1243
  private hostName;
1197
1244
  private hostIp;
1198
1245
  private cluster;
1246
+ private ossBucket;
1247
+ private ossTokenExpireTime;
1199
1248
  private deploy;
1200
1249
  private fs;
1201
1250
  private network;
@@ -1238,7 +1287,27 @@ declare class Sandbox extends AbstractSandbox {
1238
1287
  writeFile(request: WriteFileRequest): Promise<WriteFileResponse>;
1239
1288
  readFile(request: ReadFileRequest): Promise<ReadFileResponse>;
1240
1289
  upload(request: UploadRequest): Promise<UploadResponse>;
1241
- uploadByPath(sourcePath: string, targetPath: string): Promise<UploadResponse>;
1290
+ uploadByPath(sourcePath: string, targetPath: string, uploadMode?: UploadMode): Promise<UploadResponse>;
1291
+ /**
1292
+ * Get OSS STS credentials from sandbox
1293
+ */
1294
+ getOssStsCredentials(): Promise<OssCredentials>;
1295
+ /**
1296
+ * Check if OSS token is expired (with 5-minute buffer)
1297
+ */
1298
+ isTokenExpired(): boolean;
1299
+ /**
1300
+ * Download file from sandbox via OSS
1301
+ */
1302
+ downloadFile(remotePath: string, localPath: string): Promise<DownloadFileResponse>;
1303
+ /**
1304
+ * Upload file via OSS (internal method)
1305
+ */
1306
+ private uploadViaOss;
1307
+ /**
1308
+ * Setup OSS bucket with STS credentials
1309
+ */
1310
+ private setupOss;
1242
1311
  close(): Promise<void>;
1243
1312
  toString(): string;
1244
1313
  }
@@ -2356,4 +2425,4 @@ declare class DefaultAgent extends Agent {
2356
2425
  */
2357
2426
  declare const VERSION: string;
2358
2427
 
2359
- export { Agent, type AgentBashCommand, AgentBashCommandSchema, type AgentConfig, AgentConfigSchema, BadRequestRockError, type BaseConfig, type BashAction, BashActionSchema, type ChmodRequest, ChmodRequestSchema, type ChmodResponse, ChmodResponseSchema, type ChownRequest, ChownRequestSchema, type ChownResponse, ChownResponseSchema, type CloseResponse, CloseResponseSchema, type CloseSessionRequest, CloseSessionRequestSchema, type CloseSessionResponse, CloseSessionResponseSchema, Codes, type Command, type CommandResponse, CommandResponseSchema, CommandRockError, CommandSchema, type CreateBashSessionRequest, CreateBashSessionRequestSchema, type CreateSessionResponse, CreateSessionResponseSchema, DefaultAgent, type DefaultAgentConfig, DefaultAgentConfigSchema, Deploy, EnvHubClient, type EnvHubClientConfig, EnvHubClientConfigSchema, EnvHubError, type ExecuteBashSessionResponse, ExecuteBashSessionResponseSchema, HttpUtils, InternalServerRockError, InvalidParameterRockException, type IsAliveResponse, IsAliveResponseSchema, LinuxFileSystem, LinuxRemoteUser, ModelClient, type ModelClientConfig, ModelService, type ModelServiceConfig, ModelServiceConfigSchema, NODE_DEFAULT_VERSION, Network, NodeRuntimeEnv, type NodeRuntimeEnvConfig, NodeRuntimeEnvConfigSchema, type Observation, ObservationSchema, type OssSetupResponse, OssSetupResponseSchema, PID_PREFIX, PID_SUFFIX, type PollOptions, Process, PythonRuntimeEnv, type PythonRuntimeEnvConfig, PythonRuntimeEnvConfigSchema, type ReadFileRequest, ReadFileRequestSchema, type ReadFileResponse, ReadFileResponseSchema, ReasonPhrases, type ResetResult, type RockAgentConfig, RockAgentConfigSchema, RockEnv, type RockEnvConfig, type RockEnvInfo, RockEnvInfoSchema, RockException, RunMode, type RunModeType, RuntimeEnv, type RuntimeEnvConfig, RuntimeEnvConfigSchema, type RuntimeEnvId, Sandbox, type SandboxConfig, SandboxConfigSchema, SandboxGroup, type SandboxGroupConfig, SandboxGroupConfigSchema, type SandboxLike, type SandboxResponse, SandboxResponseSchema, type RunModeType as SandboxRunModeType, type SandboxStatusResponse, SandboxStatusResponseSchema, SpeedupType, type StepResult, type UploadRequest, UploadRequestSchema, type UploadResponse, UploadResponseSchema, VERSION, type WriteFileRequest, WriteFileRequestSchema, type WriteFileResponse, 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 };
2428
+ export { Agent, type AgentBashCommand, AgentBashCommandSchema, type AgentConfig, AgentConfigSchema, BadRequestRockError, type BaseConfig, type BashAction, BashActionSchema, type ChmodRequest, ChmodRequestSchema, type ChmodResponse, ChmodResponseSchema, type ChownRequest, ChownRequestSchema, type ChownResponse, ChownResponseSchema, type CloseResponse, CloseResponseSchema, type CloseSessionRequest, CloseSessionRequestSchema, type CloseSessionResponse, CloseSessionResponseSchema, Codes, type Command, type CommandResponse, CommandResponseSchema, CommandRockError, CommandSchema, type CreateBashSessionRequest, CreateBashSessionRequestSchema, type CreateSessionResponse, CreateSessionResponseSchema, DefaultAgent, type DefaultAgentConfig, DefaultAgentConfigSchema, Deploy, type DownloadFileResponse, DownloadFileResponseSchema, EnvHubClient, type EnvHubClientConfig, EnvHubClientConfigSchema, EnvHubError, type ExecuteBashSessionResponse, ExecuteBashSessionResponseSchema, HttpUtils, InternalServerRockError, InvalidParameterRockException, type IsAliveResponse, IsAliveResponseSchema, LinuxFileSystem, LinuxRemoteUser, ModelClient, type ModelClientConfig, ModelService, type ModelServiceConfig, ModelServiceConfigSchema, NODE_DEFAULT_VERSION, Network, NodeRuntimeEnv, type NodeRuntimeEnvConfig, NodeRuntimeEnvConfigSchema, type Observation, ObservationSchema, type OssCredentials, OssCredentialsSchema, type OssSetupResponse, OssSetupResponseSchema, PID_PREFIX, PID_SUFFIX, type PollOptions, Process, PythonRuntimeEnv, type PythonRuntimeEnvConfig, PythonRuntimeEnvConfigSchema, type ReadFileRequest, ReadFileRequestSchema, type ReadFileResponse, ReadFileResponseSchema, ReasonPhrases, type ResetResult, type RockAgentConfig, RockAgentConfigSchema, RockEnv, type RockEnvConfig, type RockEnvInfo, RockEnvInfoSchema, RockException, RunMode, type RunModeType, RuntimeEnv, type RuntimeEnvConfig, RuntimeEnvConfigSchema, type RuntimeEnvId, Sandbox, type SandboxConfig, SandboxConfigSchema, SandboxGroup, type SandboxGroupConfig, SandboxGroupConfigSchema, type SandboxLike, type SandboxResponse, SandboxResponseSchema, type RunModeType as SandboxRunModeType, type SandboxStatusResponse, SandboxStatusResponseSchema, SpeedupType, type StepResult, type UploadMode, UploadModeSchema, type UploadRequest, UploadRequestSchema, type UploadResponse, UploadResponseSchema, VERSION, type WriteFileRequest, WriteFileRequestSchema, type WriteFileResponse, 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 };
package/dist/index.d.ts CHANGED
@@ -151,18 +151,30 @@ declare const ReadFileRequestSchema: z.ZodObject<{
151
151
  errors?: string | undefined;
152
152
  }>;
153
153
  type ReadFileRequest = z.infer<typeof ReadFileRequestSchema>;
154
+ /**
155
+ * Upload mode enum
156
+ * - auto: Automatically choose upload method based on file size and OSS availability
157
+ * - direct: Force direct HTTP upload
158
+ * - oss: Force OSS upload
159
+ */
160
+ declare const UploadModeSchema: z.ZodEnum<["auto", "direct", "oss"]>;
161
+ type UploadMode = z.infer<typeof UploadModeSchema>;
154
162
  /**
155
163
  * Upload file request
164
+ * Note: uploadMode defaults to 'auto' in the implementation, not in the schema
156
165
  */
157
166
  declare const UploadRequestSchema: z.ZodObject<{
158
167
  sourcePath: z.ZodString;
159
168
  targetPath: z.ZodString;
169
+ uploadMode: z.ZodOptional<z.ZodEnum<["auto", "direct", "oss"]>>;
160
170
  }, "strip", z.ZodTypeAny, {
161
171
  sourcePath: string;
162
172
  targetPath: string;
173
+ uploadMode?: "auto" | "direct" | "oss" | undefined;
163
174
  }, {
164
175
  sourcePath: string;
165
176
  targetPath: string;
177
+ uploadMode?: "auto" | "direct" | "oss" | undefined;
166
178
  }>;
167
179
  type UploadRequest = z.infer<typeof UploadRequestSchema>;
168
180
  /**
@@ -475,6 +487,41 @@ declare const OssSetupResponseSchema: z.ZodObject<{
475
487
  success?: boolean | undefined;
476
488
  }>;
477
489
  type OssSetupResponse = z.infer<typeof OssSetupResponseSchema>;
490
+ /**
491
+ * Download file response
492
+ */
493
+ declare const DownloadFileResponseSchema: z.ZodObject<{
494
+ success: z.ZodDefault<z.ZodBoolean>;
495
+ message: z.ZodDefault<z.ZodString>;
496
+ }, "strip", z.ZodTypeAny, {
497
+ message: string;
498
+ success: boolean;
499
+ }, {
500
+ message?: string | undefined;
501
+ success?: boolean | undefined;
502
+ }>;
503
+ type DownloadFileResponse = z.infer<typeof DownloadFileResponseSchema>;
504
+ /**
505
+ * OSS STS credentials from sandbox /get_token API
506
+ * API returns snake_case, which gets converted to camelCase by HttpUtils
507
+ */
508
+ declare const OssCredentialsSchema: z.ZodObject<{
509
+ accessKeyId: z.ZodString;
510
+ accessKeySecret: z.ZodString;
511
+ securityToken: z.ZodString;
512
+ expiration: z.ZodString;
513
+ }, "strip", z.ZodTypeAny, {
514
+ accessKeyId: string;
515
+ accessKeySecret: string;
516
+ securityToken: string;
517
+ expiration: string;
518
+ }, {
519
+ accessKeyId: string;
520
+ accessKeySecret: string;
521
+ securityToken: string;
522
+ expiration: string;
523
+ }>;
524
+ type OssCredentials = z.infer<typeof OssCredentialsSchema>;
478
525
 
479
526
  /**
480
527
  * Common constants
@@ -1196,6 +1243,8 @@ declare class Sandbox extends AbstractSandbox {
1196
1243
  private hostName;
1197
1244
  private hostIp;
1198
1245
  private cluster;
1246
+ private ossBucket;
1247
+ private ossTokenExpireTime;
1199
1248
  private deploy;
1200
1249
  private fs;
1201
1250
  private network;
@@ -1238,7 +1287,27 @@ declare class Sandbox extends AbstractSandbox {
1238
1287
  writeFile(request: WriteFileRequest): Promise<WriteFileResponse>;
1239
1288
  readFile(request: ReadFileRequest): Promise<ReadFileResponse>;
1240
1289
  upload(request: UploadRequest): Promise<UploadResponse>;
1241
- uploadByPath(sourcePath: string, targetPath: string): Promise<UploadResponse>;
1290
+ uploadByPath(sourcePath: string, targetPath: string, uploadMode?: UploadMode): Promise<UploadResponse>;
1291
+ /**
1292
+ * Get OSS STS credentials from sandbox
1293
+ */
1294
+ getOssStsCredentials(): Promise<OssCredentials>;
1295
+ /**
1296
+ * Check if OSS token is expired (with 5-minute buffer)
1297
+ */
1298
+ isTokenExpired(): boolean;
1299
+ /**
1300
+ * Download file from sandbox via OSS
1301
+ */
1302
+ downloadFile(remotePath: string, localPath: string): Promise<DownloadFileResponse>;
1303
+ /**
1304
+ * Upload file via OSS (internal method)
1305
+ */
1306
+ private uploadViaOss;
1307
+ /**
1308
+ * Setup OSS bucket with STS credentials
1309
+ */
1310
+ private setupOss;
1242
1311
  close(): Promise<void>;
1243
1312
  toString(): string;
1244
1313
  }
@@ -2356,4 +2425,4 @@ declare class DefaultAgent extends Agent {
2356
2425
  */
2357
2426
  declare const VERSION: string;
2358
2427
 
2359
- export { Agent, type AgentBashCommand, AgentBashCommandSchema, type AgentConfig, AgentConfigSchema, BadRequestRockError, type BaseConfig, type BashAction, BashActionSchema, type ChmodRequest, ChmodRequestSchema, type ChmodResponse, ChmodResponseSchema, type ChownRequest, ChownRequestSchema, type ChownResponse, ChownResponseSchema, type CloseResponse, CloseResponseSchema, type CloseSessionRequest, CloseSessionRequestSchema, type CloseSessionResponse, CloseSessionResponseSchema, Codes, type Command, type CommandResponse, CommandResponseSchema, CommandRockError, CommandSchema, type CreateBashSessionRequest, CreateBashSessionRequestSchema, type CreateSessionResponse, CreateSessionResponseSchema, DefaultAgent, type DefaultAgentConfig, DefaultAgentConfigSchema, Deploy, EnvHubClient, type EnvHubClientConfig, EnvHubClientConfigSchema, EnvHubError, type ExecuteBashSessionResponse, ExecuteBashSessionResponseSchema, HttpUtils, InternalServerRockError, InvalidParameterRockException, type IsAliveResponse, IsAliveResponseSchema, LinuxFileSystem, LinuxRemoteUser, ModelClient, type ModelClientConfig, ModelService, type ModelServiceConfig, ModelServiceConfigSchema, NODE_DEFAULT_VERSION, Network, NodeRuntimeEnv, type NodeRuntimeEnvConfig, NodeRuntimeEnvConfigSchema, type Observation, ObservationSchema, type OssSetupResponse, OssSetupResponseSchema, PID_PREFIX, PID_SUFFIX, type PollOptions, Process, PythonRuntimeEnv, type PythonRuntimeEnvConfig, PythonRuntimeEnvConfigSchema, type ReadFileRequest, ReadFileRequestSchema, type ReadFileResponse, ReadFileResponseSchema, ReasonPhrases, type ResetResult, type RockAgentConfig, RockAgentConfigSchema, RockEnv, type RockEnvConfig, type RockEnvInfo, RockEnvInfoSchema, RockException, RunMode, type RunModeType, RuntimeEnv, type RuntimeEnvConfig, RuntimeEnvConfigSchema, type RuntimeEnvId, Sandbox, type SandboxConfig, SandboxConfigSchema, SandboxGroup, type SandboxGroupConfig, SandboxGroupConfigSchema, type SandboxLike, type SandboxResponse, SandboxResponseSchema, type RunModeType as SandboxRunModeType, type SandboxStatusResponse, SandboxStatusResponseSchema, SpeedupType, type StepResult, type UploadRequest, UploadRequestSchema, type UploadResponse, UploadResponseSchema, VERSION, type WriteFileRequest, WriteFileRequestSchema, type WriteFileResponse, 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 };
2428
+ export { Agent, type AgentBashCommand, AgentBashCommandSchema, type AgentConfig, AgentConfigSchema, BadRequestRockError, type BaseConfig, type BashAction, BashActionSchema, type ChmodRequest, ChmodRequestSchema, type ChmodResponse, ChmodResponseSchema, type ChownRequest, ChownRequestSchema, type ChownResponse, ChownResponseSchema, type CloseResponse, CloseResponseSchema, type CloseSessionRequest, CloseSessionRequestSchema, type CloseSessionResponse, CloseSessionResponseSchema, Codes, type Command, type CommandResponse, CommandResponseSchema, CommandRockError, CommandSchema, type CreateBashSessionRequest, CreateBashSessionRequestSchema, type CreateSessionResponse, CreateSessionResponseSchema, DefaultAgent, type DefaultAgentConfig, DefaultAgentConfigSchema, Deploy, type DownloadFileResponse, DownloadFileResponseSchema, EnvHubClient, type EnvHubClientConfig, EnvHubClientConfigSchema, EnvHubError, type ExecuteBashSessionResponse, ExecuteBashSessionResponseSchema, HttpUtils, InternalServerRockError, InvalidParameterRockException, type IsAliveResponse, IsAliveResponseSchema, LinuxFileSystem, LinuxRemoteUser, ModelClient, type ModelClientConfig, ModelService, type ModelServiceConfig, ModelServiceConfigSchema, NODE_DEFAULT_VERSION, Network, NodeRuntimeEnv, type NodeRuntimeEnvConfig, NodeRuntimeEnvConfigSchema, type Observation, ObservationSchema, type OssCredentials, OssCredentialsSchema, type OssSetupResponse, OssSetupResponseSchema, PID_PREFIX, PID_SUFFIX, type PollOptions, Process, PythonRuntimeEnv, type PythonRuntimeEnvConfig, PythonRuntimeEnvConfigSchema, type ReadFileRequest, ReadFileRequestSchema, type ReadFileResponse, ReadFileResponseSchema, ReasonPhrases, type ResetResult, type RockAgentConfig, RockAgentConfigSchema, RockEnv, type RockEnvConfig, type RockEnvInfo, RockEnvInfoSchema, RockException, RunMode, type RunModeType, RuntimeEnv, type RuntimeEnvConfig, RuntimeEnvConfigSchema, type RuntimeEnvId, Sandbox, type SandboxConfig, SandboxConfigSchema, SandboxGroup, type SandboxGroupConfig, SandboxGroupConfigSchema, type SandboxLike, type SandboxResponse, SandboxResponseSchema, type RunModeType as SandboxRunModeType, type SandboxStatusResponse, SandboxStatusResponseSchema, SpeedupType, type StepResult, type UploadMode, UploadModeSchema, type UploadRequest, UploadRequestSchema, type UploadResponse, UploadResponseSchema, VERSION, type WriteFileRequest, WriteFileRequestSchema, type WriteFileResponse, 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 };
package/dist/index.js CHANGED
@@ -79,9 +79,11 @@ var ReadFileRequestSchema = zod.z.object({
79
79
  encoding: zod.z.string().optional(),
80
80
  errors: zod.z.string().optional()
81
81
  });
82
+ var UploadModeSchema = zod.z.enum(["auto", "direct", "oss"]);
82
83
  var UploadRequestSchema = zod.z.object({
83
84
  sourcePath: zod.z.string(),
84
- targetPath: zod.z.string()
85
+ targetPath: zod.z.string(),
86
+ uploadMode: UploadModeSchema.optional()
85
87
  });
86
88
  var CloseSessionRequestSchema = zod.z.object({
87
89
  session: zod.z.string().default("default")
@@ -173,6 +175,16 @@ var OssSetupResponseSchema = zod.z.object({
173
175
  success: zod.z.boolean().default(false),
174
176
  message: zod.z.string().default("")
175
177
  });
178
+ var DownloadFileResponseSchema = zod.z.object({
179
+ success: zod.z.boolean().default(false),
180
+ message: zod.z.string().default("")
181
+ });
182
+ var OssCredentialsSchema = zod.z.object({
183
+ accessKeyId: zod.z.string(),
184
+ accessKeySecret: zod.z.string(),
185
+ securityToken: zod.z.string(),
186
+ expiration: zod.z.string()
187
+ });
176
188
 
177
189
  // src/common/constants.ts
178
190
  var RunMode = {
@@ -1436,6 +1448,53 @@ var LinuxFileSystem = class extends FileSystem {
1436
1448
  }
1437
1449
  };
1438
1450
 
1451
+ // src/sandbox/constants.ts
1452
+ var ENSURE_OSSUTIL_SCRIPT = `#!/bin/bash
1453
+ set -e
1454
+
1455
+ # Check downloader
1456
+ if command -v wget >/dev/null 2>&1; then
1457
+ DOWNLOADER="wget"
1458
+ elif command -v curl >/dev/null 2>&1; then
1459
+ DOWNLOADER="curl"
1460
+ else
1461
+ echo "ERROR: neither wget nor curl is available. Please install one first." >&2
1462
+ exit 1
1463
+ fi
1464
+
1465
+ # Check unzip
1466
+ if ! command -v unzip >/dev/null 2>&1; then
1467
+ echo "ERROR: unzip is not available. Please install unzip first." >&2
1468
+ exit 1
1469
+ fi
1470
+
1471
+ # Skip if already installed
1472
+ if command -v ossutil >/dev/null 2>&1; then
1473
+ echo "ossutil already installed, skipping."
1474
+ exit 0
1475
+ fi
1476
+
1477
+ # Download
1478
+ cd /tmp
1479
+ if [ "$DOWNLOADER" = "wget" ]; then
1480
+ wget -q https://gosspublic.alicdn.com/ossutil/v2/2.2.1/ossutil-2.2.1-linux-amd64.zip -O /tmp/ossutil.zip
1481
+ else
1482
+ curl -sL -o /tmp/ossutil.zip https://gosspublic.alicdn.com/ossutil/v2/2.2.1/ossutil-2.2.1-linux-amd64.zip
1483
+ fi
1484
+
1485
+ # Extract and install
1486
+ unzip -o -q ossutil.zip
1487
+ chmod 755 /tmp/ossutil-2.2.1-linux-amd64/ossutil
1488
+ mkdir -p /usr/local/bin
1489
+ mv /tmp/ossutil-2.2.1-linux-amd64/ossutil /usr/local/bin/
1490
+
1491
+ # Cleanup
1492
+ rm -rf /tmp/ossutil.zip /tmp/ossutil-2.2.1-linux-amd64
1493
+
1494
+ # Verify
1495
+ ossutil version
1496
+ `;
1497
+
1439
1498
  // src/sandbox/network.ts
1440
1499
  var logger4 = initLogger("rock.sandbox.network");
1441
1500
  var SpeedupType = /* @__PURE__ */ ((SpeedupType2) => {
@@ -1839,6 +1898,10 @@ var Sandbox = class extends AbstractSandbox {
1839
1898
  hostName = null;
1840
1899
  hostIp = null;
1841
1900
  cluster;
1901
+ // OSS-related properties
1902
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1903
+ ossBucket = null;
1904
+ ossTokenExpireTime = "";
1842
1905
  // Sub-components
1843
1906
  deploy;
1844
1907
  fs;
@@ -2226,7 +2289,7 @@ var Sandbox = class extends AbstractSandbox {
2226
2289
  async upload(request) {
2227
2290
  return this.uploadByPath(request.sourcePath, request.targetPath);
2228
2291
  }
2229
- async uploadByPath(sourcePath, targetPath) {
2292
+ async uploadByPath(sourcePath, targetPath, uploadMode = "auto") {
2230
2293
  const url = `${this.url}/upload`;
2231
2294
  const headers = this.buildHeaders();
2232
2295
  try {
@@ -2236,6 +2299,13 @@ var Sandbox = class extends AbstractSandbox {
2236
2299
  } catch {
2237
2300
  return { success: false, message: `File not found: ${sourcePath}` };
2238
2301
  }
2302
+ const stats = await fs.stat(sourcePath);
2303
+ const fileSize = stats.size;
2304
+ const ossEnabled = envVars.ROCK_OSS_ENABLE;
2305
+ const ossThreshold = 1024 * 1024;
2306
+ if (uploadMode === "oss" || uploadMode === "auto" && ossEnabled && fileSize > ossThreshold) {
2307
+ return this.uploadViaOss(sourcePath, targetPath);
2308
+ }
2239
2309
  const fileBuffer = await fs.readFile(sourcePath);
2240
2310
  const fileName = sourcePath.split("/").pop() ?? "file";
2241
2311
  const response = await HttpUtils.postMultipart(
@@ -2252,6 +2322,136 @@ var Sandbox = class extends AbstractSandbox {
2252
2322
  return { success: false, message: `Upload failed: ${e}` };
2253
2323
  }
2254
2324
  }
2325
+ /**
2326
+ * Get OSS STS credentials from sandbox
2327
+ */
2328
+ async getOssStsCredentials() {
2329
+ const url = `${this.url}/get_token`;
2330
+ const headers = this.buildHeaders();
2331
+ const response = await HttpUtils.get(url, headers);
2332
+ if (response.status !== "Success") {
2333
+ throw new Error(`Failed to get OSS STS token: ${JSON.stringify(response)}`);
2334
+ }
2335
+ const credentials = OssCredentialsSchema.parse(response.result);
2336
+ this.ossTokenExpireTime = credentials.expiration;
2337
+ return credentials;
2338
+ }
2339
+ /**
2340
+ * Check if OSS token is expired (with 5-minute buffer)
2341
+ */
2342
+ isTokenExpired() {
2343
+ if (!this.ossTokenExpireTime) {
2344
+ return true;
2345
+ }
2346
+ try {
2347
+ const expireTime = new Date(this.ossTokenExpireTime);
2348
+ const currentTime = /* @__PURE__ */ new Date();
2349
+ const bufferMs = 5 * 60 * 1e3;
2350
+ return currentTime.getTime() >= expireTime.getTime() - bufferMs;
2351
+ } catch {
2352
+ return true;
2353
+ }
2354
+ }
2355
+ /**
2356
+ * Download file from sandbox via OSS
2357
+ */
2358
+ async downloadFile(remotePath, localPath) {
2359
+ if (!envVars.ROCK_OSS_ENABLE) {
2360
+ return {
2361
+ success: false,
2362
+ message: "OSS download is not enabled. Please set ROCK_OSS_ENABLE=true"
2363
+ };
2364
+ }
2365
+ try {
2366
+ if (!remotePath || remotePath.trim() === "") {
2367
+ return { success: false, message: "Remote path is required" };
2368
+ }
2369
+ const checkResult = await this.execute({ command: ["test", "-f", remotePath], timeout: 60 });
2370
+ if (checkResult.exitCode !== 0) {
2371
+ return { success: false, message: `Remote file does not exist: ${remotePath}` };
2372
+ }
2373
+ if (this.ossBucket === null || this.isTokenExpired()) {
2374
+ await this.setupOss();
2375
+ }
2376
+ if (!this.ossBucket) {
2377
+ return { success: false, message: "Failed to setup OSS bucket" };
2378
+ }
2379
+ await this.arun(ENSURE_OSSUTIL_SCRIPT, { mode: "nohup", waitTimeout: 300 });
2380
+ const timestamp = Date.now();
2381
+ const fileName = remotePath.split("/").pop() ?? "file";
2382
+ const objectName = `download-${timestamp}-${fileName}`;
2383
+ const credentials = await this.getOssStsCredentials();
2384
+ const bucketName = envVars.ROCK_OSS_BUCKET_NAME ?? "";
2385
+ const region = envVars.ROCK_OSS_BUCKET_REGION ?? "";
2386
+ const endpoint = `https://oss-${region}.aliyuncs.com`;
2387
+ const ossutilConfigCmd = `ossutil config -e ${endpoint} -i ${credentials.accessKeyId} -k ${credentials.accessKeySecret} -t ${credentials.securityToken} -b ${bucketName}`;
2388
+ await this.arun(ossutilConfigCmd, { mode: "nohup", waitTimeout: 60 });
2389
+ const uploadToOssCmd = `ossutil cp ${remotePath} oss://${bucketName}/${objectName}`;
2390
+ const uploadResult = await this.arun(uploadToOssCmd, { mode: "nohup", waitTimeout: 600 });
2391
+ if (uploadResult.exitCode !== 0) {
2392
+ return { success: false, message: `Sandbox to OSS upload failed: ${uploadResult.output}` };
2393
+ }
2394
+ const result = await this.ossBucket.get(objectName, localPath);
2395
+ try {
2396
+ await this.ossBucket.delete(objectName);
2397
+ } catch {
2398
+ }
2399
+ return { success: true, message: `Successfully downloaded ${remotePath} to ${localPath}` };
2400
+ } catch (e) {
2401
+ return { success: false, message: `Download failed: ${e}` };
2402
+ }
2403
+ }
2404
+ /**
2405
+ * Upload file via OSS (internal method)
2406
+ */
2407
+ async uploadViaOss(sourcePath, targetPath) {
2408
+ try {
2409
+ if (this.ossBucket === null || this.isTokenExpired()) {
2410
+ await this.setupOss();
2411
+ }
2412
+ if (!this.ossBucket) {
2413
+ return { success: false, message: "Failed to setup OSS bucket" };
2414
+ }
2415
+ const timestamp = Date.now();
2416
+ const fileName = sourcePath.split("/").pop() ?? "file";
2417
+ const objectName = `${timestamp}-${fileName}`;
2418
+ await this.ossBucket.put(objectName, sourcePath);
2419
+ const signedUrl = this.ossBucket.signatureUrl(objectName, 600);
2420
+ const downloadCmd = `wget -c -O '${targetPath}' '${signedUrl}'`;
2421
+ await this.arun(downloadCmd, { mode: "nohup", waitTimeout: 600 });
2422
+ const checkResult = await this.execute({ command: ["test", "-f", targetPath], timeout: 60 });
2423
+ if (checkResult.exitCode !== 0) {
2424
+ return { success: false, message: "Sandbox download phase failed" };
2425
+ }
2426
+ return { success: true, message: `Successfully uploaded file ${fileName} to ${targetPath} via OSS` };
2427
+ } catch (e) {
2428
+ return { success: false, message: `OSS upload failed: ${e}` };
2429
+ }
2430
+ }
2431
+ /**
2432
+ * Setup OSS bucket with STS credentials
2433
+ */
2434
+ async setupOss() {
2435
+ const credentials = await this.getOssStsCredentials();
2436
+ const OSS = (await import('ali-oss')).default;
2437
+ this.ossBucket = new OSS({
2438
+ region: envVars.ROCK_OSS_BUCKET_REGION ?? "",
2439
+ accessKeyId: credentials.accessKeyId,
2440
+ accessKeySecret: credentials.accessKeySecret,
2441
+ stsToken: credentials.securityToken,
2442
+ bucket: envVars.ROCK_OSS_BUCKET_NAME ?? "",
2443
+ refreshSTSToken: async () => {
2444
+ const newCreds = await this.getOssStsCredentials();
2445
+ return {
2446
+ accessKeyId: newCreds.accessKeyId,
2447
+ accessKeySecret: newCreds.accessKeySecret,
2448
+ stsToken: newCreds.securityToken
2449
+ };
2450
+ },
2451
+ refreshSTSTokenInterval: 3e5
2452
+ // 5 minutes
2453
+ });
2454
+ }
2255
2455
  // Close
2256
2456
  async close() {
2257
2457
  await this.stop();
@@ -3216,6 +3416,7 @@ exports.CreateSessionResponseSchema = CreateSessionResponseSchema;
3216
3416
  exports.DefaultAgent = DefaultAgent;
3217
3417
  exports.DefaultAgentConfigSchema = DefaultAgentConfigSchema;
3218
3418
  exports.Deploy = Deploy;
3419
+ exports.DownloadFileResponseSchema = DownloadFileResponseSchema;
3219
3420
  exports.EnvHubClient = EnvHubClient;
3220
3421
  exports.EnvHubClientConfigSchema = EnvHubClientConfigSchema;
3221
3422
  exports.EnvHubError = EnvHubError;
@@ -3234,6 +3435,7 @@ exports.Network = Network;
3234
3435
  exports.NodeRuntimeEnv = NodeRuntimeEnv;
3235
3436
  exports.NodeRuntimeEnvConfigSchema = NodeRuntimeEnvConfigSchema;
3236
3437
  exports.ObservationSchema = ObservationSchema;
3438
+ exports.OssCredentialsSchema = OssCredentialsSchema;
3237
3439
  exports.OssSetupResponseSchema = OssSetupResponseSchema;
3238
3440
  exports.PID_PREFIX = PID_PREFIX;
3239
3441
  exports.PID_SUFFIX = PID_SUFFIX;
@@ -3257,6 +3459,7 @@ exports.SandboxGroupConfigSchema = SandboxGroupConfigSchema;
3257
3459
  exports.SandboxResponseSchema = SandboxResponseSchema;
3258
3460
  exports.SandboxStatusResponseSchema = SandboxStatusResponseSchema;
3259
3461
  exports.SpeedupType = SpeedupType;
3462
+ exports.UploadModeSchema = UploadModeSchema;
3260
3463
  exports.UploadRequestSchema = UploadRequestSchema;
3261
3464
  exports.UploadResponseSchema = UploadResponseSchema;
3262
3465
  exports.VERSION = VERSION;