rl-rock 1.3.8 → 1.10.0-beta.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/dist/index.d.mts CHANGED
@@ -159,6 +159,14 @@ type ReadFileRequest = z.infer<typeof ReadFileRequestSchema>;
159
159
  */
160
160
  declare const UploadModeSchema: z.ZodEnum<["auto", "direct", "oss"]>;
161
161
  type UploadMode = z.infer<typeof UploadModeSchema>;
162
+ /**
163
+ * Download mode enum
164
+ * - auto: Automatically choose download method based on file size and OSS availability
165
+ * - direct: Force direct HTTP download via readFile API
166
+ * - oss: Force OSS download
167
+ */
168
+ declare const DownloadModeSchema: z.ZodEnum<["auto", "direct", "oss"]>;
169
+ type DownloadMode = z.infer<typeof DownloadModeSchema>;
162
170
  /**
163
171
  * Upload file request
164
172
  * Note: uploadMode defaults to 'auto' in the implementation, not in the schema
@@ -222,6 +230,43 @@ declare const ChmodRequestSchema: z.ZodObject<{
222
230
  mode?: string | undefined;
223
231
  }>;
224
232
  type ChmodRequest = z.infer<typeof ChmodRequestSchema>;
233
+ /**
234
+ * Progress phase for upload operations
235
+ * - upload-to-oss: Uploading from local to OSS
236
+ * - download-to-sandbox: Downloading from OSS to sandbox (via wget)
237
+ */
238
+ type UploadPhase = 'upload-to-oss' | 'download-to-sandbox';
239
+ /**
240
+ * Progress phase for download operations
241
+ * - upload-to-oss-from-sandbox: Uploading from sandbox to OSS (via ossutil)
242
+ * - download-to-local: Downloading from OSS to local
243
+ */
244
+ type DownloadPhase = 'upload-to-oss-from-sandbox' | 'download-to-local';
245
+ /**
246
+ * Progress information callback
247
+ * @param phase - Current phase of the transfer
248
+ * @param percent - Progress percentage (0-100), or -1 if not available
249
+ */
250
+ interface ProgressInfo {
251
+ phase: UploadPhase | DownloadPhase;
252
+ percent: number;
253
+ }
254
+ /**
255
+ * Upload options
256
+ */
257
+ interface UploadOptions {
258
+ uploadMode?: UploadMode;
259
+ timeout?: number;
260
+ onProgress?: (info: ProgressInfo) => void;
261
+ }
262
+ /**
263
+ * Download options
264
+ */
265
+ interface DownloadOptions {
266
+ downloadMode?: DownloadMode;
267
+ timeout?: number;
268
+ onProgress?: (info: ProgressInfo) => void;
269
+ }
225
270
 
226
271
  /**
227
272
  * Response types
@@ -938,6 +983,7 @@ declare const SandboxConfigSchema: z.ZodObject<{
938
983
  experimentId: z.ZodOptional<z.ZodString>;
939
984
  cluster: z.ZodDefault<z.ZodString>;
940
985
  namespace: z.ZodOptional<z.ZodString>;
986
+ autoDeleteSeconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
941
987
  }, "strip", z.ZodTypeAny, {
942
988
  image: string;
943
989
  cpus: number;
@@ -952,6 +998,7 @@ declare const SandboxConfigSchema: z.ZodObject<{
952
998
  namespace?: string | undefined;
953
999
  xrlAuthorization?: string | undefined;
954
1000
  routeKey?: string | undefined;
1001
+ autoDeleteSeconds?: number | null | undefined;
955
1002
  }, {
956
1003
  image?: string | undefined;
957
1004
  userId?: string | undefined;
@@ -966,6 +1013,7 @@ declare const SandboxConfigSchema: z.ZodObject<{
966
1013
  autoClearSeconds?: number | undefined;
967
1014
  routeKey?: string | undefined;
968
1015
  startupTimeout?: number | undefined;
1016
+ autoDeleteSeconds?: number | null | undefined;
969
1017
  }>;
970
1018
  type SandboxConfig = z.infer<typeof SandboxConfigSchema>;
971
1019
  /**
@@ -986,6 +1034,7 @@ declare const SandboxGroupConfigSchema: z.ZodObject<{
986
1034
  experimentId: z.ZodOptional<z.ZodString>;
987
1035
  cluster: z.ZodDefault<z.ZodString>;
988
1036
  namespace: z.ZodOptional<z.ZodString>;
1037
+ autoDeleteSeconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
989
1038
  } & {
990
1039
  size: z.ZodDefault<z.ZodNumber>;
991
1040
  startConcurrency: z.ZodDefault<z.ZodNumber>;
@@ -1007,6 +1056,7 @@ declare const SandboxGroupConfigSchema: z.ZodObject<{
1007
1056
  namespace?: string | undefined;
1008
1057
  xrlAuthorization?: string | undefined;
1009
1058
  routeKey?: string | undefined;
1059
+ autoDeleteSeconds?: number | null | undefined;
1010
1060
  }, {
1011
1061
  image?: string | undefined;
1012
1062
  userId?: string | undefined;
@@ -1021,6 +1071,7 @@ declare const SandboxGroupConfigSchema: z.ZodObject<{
1021
1071
  autoClearSeconds?: number | undefined;
1022
1072
  routeKey?: string | undefined;
1023
1073
  startupTimeout?: number | undefined;
1074
+ autoDeleteSeconds?: number | null | undefined;
1024
1075
  size?: number | undefined;
1025
1076
  startConcurrency?: number | undefined;
1026
1077
  startRetryTimes?: number | undefined;
@@ -1267,7 +1318,9 @@ declare class Sandbox extends AbstractSandbox {
1267
1318
  start(): Promise<void>;
1268
1319
  stop(): Promise<void>;
1269
1320
  isAlive(): Promise<IsAliveResponse>;
1270
- getStatus(): Promise<SandboxStatusResponse>;
1321
+ getStatus(options?: {
1322
+ includeAllStates?: boolean;
1323
+ }): Promise<SandboxStatusResponse>;
1271
1324
  execute(command: Command): Promise<CommandResponse>;
1272
1325
  createSession(request: CreateBashSessionRequest): Promise<CreateSessionResponse>;
1273
1326
  closeSession(request: CloseSessionRequest): Promise<CloseSessionResponse>;
@@ -1287,7 +1340,7 @@ declare class Sandbox extends AbstractSandbox {
1287
1340
  writeFile(request: WriteFileRequest): Promise<WriteFileResponse>;
1288
1341
  readFile(request: ReadFileRequest): Promise<ReadFileResponse>;
1289
1342
  upload(request: UploadRequest): Promise<UploadResponse>;
1290
- uploadByPath(sourcePath: string, targetPath: string, uploadMode?: UploadMode, timeout?: number): Promise<UploadResponse>;
1343
+ uploadByPath(sourcePath: string, targetPath: string, options?: UploadOptions): Promise<UploadResponse>;
1291
1344
  /**
1292
1345
  * Get OSS STS credentials from sandbox
1293
1346
  */
@@ -1297,9 +1350,21 @@ declare class Sandbox extends AbstractSandbox {
1297
1350
  */
1298
1351
  isTokenExpired(): boolean;
1299
1352
  /**
1300
- * Download file from sandbox via OSS
1353
+ * Download file from sandbox
1354
+ * @param remotePath - File path in sandbox
1355
+ * @param localPath - Local file path
1356
+ * @param downloadMode - Download mode: 'auto' (default), 'direct', or 'oss'
1357
+ * @param timeout - Optional timeout in milliseconds for OSS mode
1358
+ */
1359
+ downloadFile(remotePath: string, localPath: string, options?: DownloadOptions): Promise<DownloadFileResponse>;
1360
+ /**
1361
+ * Download file directly via readFile API
1362
+ */
1363
+ private downloadDirect;
1364
+ /**
1365
+ * Download file via OSS as intermediary
1301
1366
  */
1302
- downloadFile(remotePath: string, localPath: string, timeout?: number): Promise<DownloadFileResponse>;
1367
+ private downloadViaOss;
1303
1368
  /**
1304
1369
  * Upload file via OSS (internal method)
1305
1370
  * @param timeout - Optional timeout in milliseconds
@@ -1310,6 +1375,9 @@ declare class Sandbox extends AbstractSandbox {
1310
1375
  * @param timeout - Optional timeout in milliseconds (defaults to ROCK_OSS_TIMEOUT env var or 300000ms)
1311
1376
  */
1312
1377
  private setupOss;
1378
+ restart(): Promise<void>;
1379
+ private waitForAlive;
1380
+ private parseErrorMessageFromStatus;
1313
1381
  close(): Promise<void>;
1314
1382
  toString(): string;
1315
1383
  }
@@ -2427,4 +2495,4 @@ declare class DefaultAgent extends Agent {
2427
2495
  */
2428
2496
  declare const VERSION: string;
2429
2497
 
2430
- 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 };
2498
+ 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, type DownloadMode, DownloadModeSchema, type DownloadOptions, type DownloadPhase, 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, type ProgressInfo, 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 UploadOptions, type UploadPhase, 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
@@ -159,6 +159,14 @@ type ReadFileRequest = z.infer<typeof ReadFileRequestSchema>;
159
159
  */
160
160
  declare const UploadModeSchema: z.ZodEnum<["auto", "direct", "oss"]>;
161
161
  type UploadMode = z.infer<typeof UploadModeSchema>;
162
+ /**
163
+ * Download mode enum
164
+ * - auto: Automatically choose download method based on file size and OSS availability
165
+ * - direct: Force direct HTTP download via readFile API
166
+ * - oss: Force OSS download
167
+ */
168
+ declare const DownloadModeSchema: z.ZodEnum<["auto", "direct", "oss"]>;
169
+ type DownloadMode = z.infer<typeof DownloadModeSchema>;
162
170
  /**
163
171
  * Upload file request
164
172
  * Note: uploadMode defaults to 'auto' in the implementation, not in the schema
@@ -222,6 +230,43 @@ declare const ChmodRequestSchema: z.ZodObject<{
222
230
  mode?: string | undefined;
223
231
  }>;
224
232
  type ChmodRequest = z.infer<typeof ChmodRequestSchema>;
233
+ /**
234
+ * Progress phase for upload operations
235
+ * - upload-to-oss: Uploading from local to OSS
236
+ * - download-to-sandbox: Downloading from OSS to sandbox (via wget)
237
+ */
238
+ type UploadPhase = 'upload-to-oss' | 'download-to-sandbox';
239
+ /**
240
+ * Progress phase for download operations
241
+ * - upload-to-oss-from-sandbox: Uploading from sandbox to OSS (via ossutil)
242
+ * - download-to-local: Downloading from OSS to local
243
+ */
244
+ type DownloadPhase = 'upload-to-oss-from-sandbox' | 'download-to-local';
245
+ /**
246
+ * Progress information callback
247
+ * @param phase - Current phase of the transfer
248
+ * @param percent - Progress percentage (0-100), or -1 if not available
249
+ */
250
+ interface ProgressInfo {
251
+ phase: UploadPhase | DownloadPhase;
252
+ percent: number;
253
+ }
254
+ /**
255
+ * Upload options
256
+ */
257
+ interface UploadOptions {
258
+ uploadMode?: UploadMode;
259
+ timeout?: number;
260
+ onProgress?: (info: ProgressInfo) => void;
261
+ }
262
+ /**
263
+ * Download options
264
+ */
265
+ interface DownloadOptions {
266
+ downloadMode?: DownloadMode;
267
+ timeout?: number;
268
+ onProgress?: (info: ProgressInfo) => void;
269
+ }
225
270
 
226
271
  /**
227
272
  * Response types
@@ -938,6 +983,7 @@ declare const SandboxConfigSchema: z.ZodObject<{
938
983
  experimentId: z.ZodOptional<z.ZodString>;
939
984
  cluster: z.ZodDefault<z.ZodString>;
940
985
  namespace: z.ZodOptional<z.ZodString>;
986
+ autoDeleteSeconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
941
987
  }, "strip", z.ZodTypeAny, {
942
988
  image: string;
943
989
  cpus: number;
@@ -952,6 +998,7 @@ declare const SandboxConfigSchema: z.ZodObject<{
952
998
  namespace?: string | undefined;
953
999
  xrlAuthorization?: string | undefined;
954
1000
  routeKey?: string | undefined;
1001
+ autoDeleteSeconds?: number | null | undefined;
955
1002
  }, {
956
1003
  image?: string | undefined;
957
1004
  userId?: string | undefined;
@@ -966,6 +1013,7 @@ declare const SandboxConfigSchema: z.ZodObject<{
966
1013
  autoClearSeconds?: number | undefined;
967
1014
  routeKey?: string | undefined;
968
1015
  startupTimeout?: number | undefined;
1016
+ autoDeleteSeconds?: number | null | undefined;
969
1017
  }>;
970
1018
  type SandboxConfig = z.infer<typeof SandboxConfigSchema>;
971
1019
  /**
@@ -986,6 +1034,7 @@ declare const SandboxGroupConfigSchema: z.ZodObject<{
986
1034
  experimentId: z.ZodOptional<z.ZodString>;
987
1035
  cluster: z.ZodDefault<z.ZodString>;
988
1036
  namespace: z.ZodOptional<z.ZodString>;
1037
+ autoDeleteSeconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
989
1038
  } & {
990
1039
  size: z.ZodDefault<z.ZodNumber>;
991
1040
  startConcurrency: z.ZodDefault<z.ZodNumber>;
@@ -1007,6 +1056,7 @@ declare const SandboxGroupConfigSchema: z.ZodObject<{
1007
1056
  namespace?: string | undefined;
1008
1057
  xrlAuthorization?: string | undefined;
1009
1058
  routeKey?: string | undefined;
1059
+ autoDeleteSeconds?: number | null | undefined;
1010
1060
  }, {
1011
1061
  image?: string | undefined;
1012
1062
  userId?: string | undefined;
@@ -1021,6 +1071,7 @@ declare const SandboxGroupConfigSchema: z.ZodObject<{
1021
1071
  autoClearSeconds?: number | undefined;
1022
1072
  routeKey?: string | undefined;
1023
1073
  startupTimeout?: number | undefined;
1074
+ autoDeleteSeconds?: number | null | undefined;
1024
1075
  size?: number | undefined;
1025
1076
  startConcurrency?: number | undefined;
1026
1077
  startRetryTimes?: number | undefined;
@@ -1267,7 +1318,9 @@ declare class Sandbox extends AbstractSandbox {
1267
1318
  start(): Promise<void>;
1268
1319
  stop(): Promise<void>;
1269
1320
  isAlive(): Promise<IsAliveResponse>;
1270
- getStatus(): Promise<SandboxStatusResponse>;
1321
+ getStatus(options?: {
1322
+ includeAllStates?: boolean;
1323
+ }): Promise<SandboxStatusResponse>;
1271
1324
  execute(command: Command): Promise<CommandResponse>;
1272
1325
  createSession(request: CreateBashSessionRequest): Promise<CreateSessionResponse>;
1273
1326
  closeSession(request: CloseSessionRequest): Promise<CloseSessionResponse>;
@@ -1287,7 +1340,7 @@ declare class Sandbox extends AbstractSandbox {
1287
1340
  writeFile(request: WriteFileRequest): Promise<WriteFileResponse>;
1288
1341
  readFile(request: ReadFileRequest): Promise<ReadFileResponse>;
1289
1342
  upload(request: UploadRequest): Promise<UploadResponse>;
1290
- uploadByPath(sourcePath: string, targetPath: string, uploadMode?: UploadMode, timeout?: number): Promise<UploadResponse>;
1343
+ uploadByPath(sourcePath: string, targetPath: string, options?: UploadOptions): Promise<UploadResponse>;
1291
1344
  /**
1292
1345
  * Get OSS STS credentials from sandbox
1293
1346
  */
@@ -1297,9 +1350,21 @@ declare class Sandbox extends AbstractSandbox {
1297
1350
  */
1298
1351
  isTokenExpired(): boolean;
1299
1352
  /**
1300
- * Download file from sandbox via OSS
1353
+ * Download file from sandbox
1354
+ * @param remotePath - File path in sandbox
1355
+ * @param localPath - Local file path
1356
+ * @param downloadMode - Download mode: 'auto' (default), 'direct', or 'oss'
1357
+ * @param timeout - Optional timeout in milliseconds for OSS mode
1358
+ */
1359
+ downloadFile(remotePath: string, localPath: string, options?: DownloadOptions): Promise<DownloadFileResponse>;
1360
+ /**
1361
+ * Download file directly via readFile API
1362
+ */
1363
+ private downloadDirect;
1364
+ /**
1365
+ * Download file via OSS as intermediary
1301
1366
  */
1302
- downloadFile(remotePath: string, localPath: string, timeout?: number): Promise<DownloadFileResponse>;
1367
+ private downloadViaOss;
1303
1368
  /**
1304
1369
  * Upload file via OSS (internal method)
1305
1370
  * @param timeout - Optional timeout in milliseconds
@@ -1310,6 +1375,9 @@ declare class Sandbox extends AbstractSandbox {
1310
1375
  * @param timeout - Optional timeout in milliseconds (defaults to ROCK_OSS_TIMEOUT env var or 300000ms)
1311
1376
  */
1312
1377
  private setupOss;
1378
+ restart(): Promise<void>;
1379
+ private waitForAlive;
1380
+ private parseErrorMessageFromStatus;
1313
1381
  close(): Promise<void>;
1314
1382
  toString(): string;
1315
1383
  }
@@ -2427,4 +2495,4 @@ declare class DefaultAgent extends Agent {
2427
2495
  */
2428
2496
  declare const VERSION: string;
2429
2497
 
2430
- 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 };
2498
+ 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, type DownloadMode, DownloadModeSchema, type DownloadOptions, type DownloadPhase, 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, type ProgressInfo, 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 UploadOptions, type UploadPhase, 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
@@ -80,6 +80,7 @@ var ReadFileRequestSchema = zod.z.object({
80
80
  errors: zod.z.string().optional()
81
81
  });
82
82
  var UploadModeSchema = zod.z.enum(["auto", "direct", "oss"]);
83
+ var DownloadModeSchema = zod.z.enum(["auto", "direct", "oss"]);
83
84
  var UploadRequestSchema = zod.z.object({
84
85
  sourcePath: zod.z.string(),
85
86
  targetPath: zod.z.string(),
@@ -1113,7 +1114,8 @@ var SandboxConfigSchema = BaseConfigSchema.extend({
1113
1114
  userId: zod.z.string().optional(),
1114
1115
  experimentId: zod.z.string().optional(),
1115
1116
  cluster: zod.z.string().default(() => envVars.ROCK_DEFAULT_CLUSTER),
1116
- namespace: zod.z.string().optional()
1117
+ namespace: zod.z.string().optional(),
1118
+ autoDeleteSeconds: zod.z.number().min(0, "autoDeleteSeconds must be >= 0").nullish()
1117
1119
  });
1118
1120
  var SandboxGroupConfigSchema = SandboxConfigSchema.extend({
1119
1121
  size: zod.z.number().default(() => envVars.ROCK_DEFAULT_GROUP_SIZE),
@@ -1994,7 +1996,8 @@ var Sandbox = class extends AbstractSandbox {
1994
1996
  autoClearTimeMinutes: this.config.autoClearSeconds / 60,
1995
1997
  startupTimeout: this.config.startupTimeout,
1996
1998
  memory: this.config.memory,
1997
- cpus: this.config.cpus
1999
+ cpus: this.config.cpus,
2000
+ autoDeleteSeconds: this.config.autoDeleteSeconds
1998
2001
  };
1999
2002
  logger8.debug(`Calling start_async API: ${url}`);
2000
2003
  logger8.debug(`Request data: ${JSON.stringify(data)}`);
@@ -2013,30 +2016,7 @@ var Sandbox = class extends AbstractSandbox {
2013
2016
  this.hostName = response.result?.hostName ?? null;
2014
2017
  this.hostIp = response.result?.hostIp ?? null;
2015
2018
  logger8.info(`Sandbox ID: ${this.sandboxId}`);
2016
- await sleep(2e3);
2017
- const startTime = Date.now();
2018
- const checkTimeout = 1e4;
2019
- const checkInterval = 3e3;
2020
- while (Date.now() - startTime < this.config.startupTimeout * 1e3) {
2021
- try {
2022
- logger8.info(`Checking status... (elapsed: ${Math.round((Date.now() - startTime) / 1e3)}s)`);
2023
- const statusPromise = this.getStatus();
2024
- const timeoutPromise = new Promise(
2025
- (_, reject) => setTimeout(() => reject(new Error("Status check timeout")), checkTimeout)
2026
- );
2027
- const status = await Promise.race([statusPromise, timeoutPromise]);
2028
- if (status && status.isAlive) {
2029
- logger8.info("Sandbox is alive");
2030
- return;
2031
- }
2032
- } catch (e) {
2033
- logger8.debug(`Status check failed (will retry): ${e}`);
2034
- }
2035
- await sleep(checkInterval);
2036
- }
2037
- throw new InternalServerRockError(
2038
- `Failed to start sandbox within ${this.config.startupTimeout}s, sandbox: ${this.toString()}`
2039
- );
2019
+ await this.waitForAlive();
2040
2020
  }
2041
2021
  async stop() {
2042
2022
  if (!this.sandboxId) return;
@@ -2059,8 +2039,11 @@ var Sandbox = class extends AbstractSandbox {
2059
2039
  throw new Error(`Failed to get is alive: ${e}`);
2060
2040
  }
2061
2041
  }
2062
- async getStatus() {
2063
- const url = `${this.url}/get_status?sandbox_id=${this.sandboxId}`;
2042
+ async getStatus(options) {
2043
+ let url = `${this.url}/get_status?sandbox_id=${this.sandboxId}`;
2044
+ if (options?.includeAllStates) {
2045
+ url += "&include_all_states=true";
2046
+ }
2064
2047
  const headers = this.buildHeaders();
2065
2048
  const response = await HttpUtils.get(url, headers);
2066
2049
  if (response.status !== "Success") {
@@ -2298,9 +2281,12 @@ var Sandbox = class extends AbstractSandbox {
2298
2281
  async upload(request) {
2299
2282
  return this.uploadByPath(request.sourcePath, request.targetPath);
2300
2283
  }
2301
- async uploadByPath(sourcePath, targetPath, uploadMode = "auto", timeout) {
2284
+ async uploadByPath(sourcePath, targetPath, options) {
2302
2285
  const url = `${this.url}/upload`;
2303
2286
  const headers = this.buildHeaders();
2287
+ const uploadMode = options?.uploadMode ?? "auto";
2288
+ const timeout = options?.timeout;
2289
+ const onProgress = options?.onProgress;
2304
2290
  try {
2305
2291
  const fs = await import('fs/promises');
2306
2292
  try {
@@ -2313,7 +2299,7 @@ var Sandbox = class extends AbstractSandbox {
2313
2299
  const ossEnabled = envVars.ROCK_OSS_ENABLE;
2314
2300
  const ossThreshold = 1024 * 1024;
2315
2301
  if (uploadMode === "oss" || uploadMode === "auto" && ossEnabled && fileSize > ossThreshold) {
2316
- return this.uploadViaOss(sourcePath, targetPath, timeout);
2302
+ return this.uploadViaOss(sourcePath, targetPath, timeout, onProgress);
2317
2303
  }
2318
2304
  const fileBuffer = await fs.readFile(sourcePath);
2319
2305
  const fileName = sourcePath.split("/").pop() ?? "file";
@@ -2362,9 +2348,61 @@ var Sandbox = class extends AbstractSandbox {
2362
2348
  }
2363
2349
  }
2364
2350
  /**
2365
- * Download file from sandbox via OSS
2351
+ * Download file from sandbox
2352
+ * @param remotePath - File path in sandbox
2353
+ * @param localPath - Local file path
2354
+ * @param downloadMode - Download mode: 'auto' (default), 'direct', or 'oss'
2355
+ * @param timeout - Optional timeout in milliseconds for OSS mode
2366
2356
  */
2367
- async downloadFile(remotePath, localPath, timeout) {
2357
+ async downloadFile(remotePath, localPath, options) {
2358
+ const downloadMode = options?.downloadMode ?? "auto";
2359
+ const timeout = options?.timeout;
2360
+ const onProgress = options?.onProgress;
2361
+ if (!remotePath || remotePath.trim() === "") {
2362
+ return { success: false, message: "Remote path is required" };
2363
+ }
2364
+ const checkResult = await this.execute({ command: ["test", "-f", remotePath], timeout: 60 });
2365
+ if (checkResult.exitCode !== 0) {
2366
+ return { success: false, message: `Remote file does not exist: ${remotePath}` };
2367
+ }
2368
+ if (downloadMode === "direct") {
2369
+ return this.downloadDirect(remotePath, localPath);
2370
+ }
2371
+ if (downloadMode === "oss") {
2372
+ return this.downloadViaOss(remotePath, localPath, timeout, onProgress);
2373
+ }
2374
+ const sizeResult = await this.execute({ command: ["stat", "-c", "%s", remotePath], timeout: 60 });
2375
+ if (sizeResult.exitCode !== 0) {
2376
+ return this.downloadDirect(remotePath, localPath);
2377
+ }
2378
+ const fileSize = parseInt(sizeResult.stdout.trim(), 10);
2379
+ const ossThreshold = 1024 * 1024;
2380
+ const ossEnabled = envVars.ROCK_OSS_ENABLE;
2381
+ if (ossEnabled && fileSize >= ossThreshold) {
2382
+ return this.downloadViaOss(remotePath, localPath, timeout, onProgress);
2383
+ }
2384
+ return this.downloadDirect(remotePath, localPath);
2385
+ }
2386
+ /**
2387
+ * Download file directly via readFile API
2388
+ */
2389
+ async downloadDirect(remotePath, localPath) {
2390
+ try {
2391
+ const fs = await import('fs/promises');
2392
+ const path = await import('path');
2393
+ const response = await this.readFile({ path: remotePath });
2394
+ const parentDir = path.dirname(localPath);
2395
+ await fs.mkdir(parentDir, { recursive: true });
2396
+ await fs.writeFile(localPath, response.content, "utf-8");
2397
+ return { success: true, message: `Successfully downloaded ${remotePath} to ${localPath}` };
2398
+ } catch (e) {
2399
+ return { success: false, message: `Direct download failed: ${e}` };
2400
+ }
2401
+ }
2402
+ /**
2403
+ * Download file via OSS as intermediary
2404
+ */
2405
+ async downloadViaOss(remotePath, localPath, timeout, onProgress) {
2368
2406
  if (!envVars.ROCK_OSS_ENABLE) {
2369
2407
  return {
2370
2408
  success: false,
@@ -2372,13 +2410,6 @@ var Sandbox = class extends AbstractSandbox {
2372
2410
  };
2373
2411
  }
2374
2412
  try {
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
2413
  if (this.ossBucket === null || this.isTokenExpired()) {
2383
2414
  await this.setupOss(timeout);
2384
2415
  }
@@ -2400,21 +2431,29 @@ var Sandbox = class extends AbstractSandbox {
2400
2431
  return { success: false, message: `Sandbox to OSS upload failed: ${uploadResult.output}` };
2401
2432
  }
2402
2433
  const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
2403
- const result = await this.ossBucket.get(objectName, localPath, { timeout: ossTimeout });
2434
+ const result = await this.ossBucket.get(objectName, localPath, {
2435
+ timeout: ossTimeout,
2436
+ progress: (p) => {
2437
+ onProgress?.({
2438
+ phase: "download-to-local",
2439
+ percent: Math.round(p * 100)
2440
+ });
2441
+ }
2442
+ });
2404
2443
  try {
2405
2444
  await this.ossBucket.delete(objectName);
2406
2445
  } catch {
2407
2446
  }
2408
2447
  return { success: true, message: `Successfully downloaded ${remotePath} to ${localPath}` };
2409
2448
  } catch (e) {
2410
- return { success: false, message: `Download failed: ${e}` };
2449
+ return { success: false, message: `OSS download failed: ${e}` };
2411
2450
  }
2412
2451
  }
2413
2452
  /**
2414
2453
  * Upload file via OSS (internal method)
2415
2454
  * @param timeout - Optional timeout in milliseconds
2416
2455
  */
2417
- async uploadViaOss(sourcePath, targetPath, timeout) {
2456
+ async uploadViaOss(sourcePath, targetPath, timeout, onProgress) {
2418
2457
  try {
2419
2458
  if (this.ossBucket === null || this.isTokenExpired()) {
2420
2459
  await this.setupOss(timeout);
@@ -2425,9 +2464,39 @@ var Sandbox = class extends AbstractSandbox {
2425
2464
  const timestamp = Date.now();
2426
2465
  const fileName = sourcePath.split("/").pop() ?? "file";
2427
2466
  const objectName = `${timestamp}-${fileName}`;
2467
+ const fs = await import('fs/promises');
2468
+ const stats = await fs.stat(sourcePath);
2469
+ const fileSize = stats.size;
2470
+ const multipartThreshold = 1024 * 1024;
2428
2471
  const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
2429
- await this.ossBucket.put(objectName, sourcePath, { timeout: ossTimeout });
2472
+ if (fileSize >= multipartThreshold) {
2473
+ await this.ossBucket.multipartUpload(objectName, sourcePath, {
2474
+ timeout: ossTimeout,
2475
+ partSize: multipartThreshold,
2476
+ // 1MB per part
2477
+ progress: (p) => {
2478
+ onProgress?.({
2479
+ phase: "upload-to-oss",
2480
+ percent: Math.round(p * 100)
2481
+ });
2482
+ }
2483
+ });
2484
+ } else {
2485
+ await this.ossBucket.put(objectName, sourcePath, {
2486
+ timeout: ossTimeout,
2487
+ progress: (p) => {
2488
+ onProgress?.({
2489
+ phase: "upload-to-oss",
2490
+ percent: Math.round(p * 100)
2491
+ });
2492
+ }
2493
+ });
2494
+ }
2430
2495
  const signedUrl = this.ossBucket.signatureUrl(objectName, { expires: 600 });
2496
+ onProgress?.({
2497
+ phase: "download-to-sandbox",
2498
+ percent: -1
2499
+ });
2431
2500
  const downloadCmd = `wget -c -O '${targetPath}' '${signedUrl}'`;
2432
2501
  await this.arun(downloadCmd, { mode: "nohup", waitTimeout: 600 });
2433
2502
  const checkResult = await this.execute({ command: ["test", "-f", targetPath], timeout: 60 });
@@ -2468,6 +2537,74 @@ var Sandbox = class extends AbstractSandbox {
2468
2537
  // 5 minutes
2469
2538
  });
2470
2539
  }
2540
+ async restart() {
2541
+ if (!this.sandboxId) {
2542
+ throw new Error("sandbox_id is not set, cannot restart");
2543
+ }
2544
+ const url = `${this.url}/restart`;
2545
+ const headers = this.buildHeaders();
2546
+ const data = { sandboxId: this.sandboxId };
2547
+ const response = await HttpUtils.post(url, headers, data);
2548
+ logger8.debug(`Restart sandbox response: ${JSON.stringify(response)}`);
2549
+ if (response.status !== "Success") {
2550
+ const code = response.result?.code;
2551
+ raiseForCode(code, `Failed to restart sandbox: ${JSON.stringify(response)}`);
2552
+ throw new Error(`Failed to restart sandbox: ${JSON.stringify(response)}`);
2553
+ }
2554
+ await this.waitForAlive({ includeAllStates: true });
2555
+ }
2556
+ async waitForAlive(options) {
2557
+ await sleep(2e3);
2558
+ const startTime = Date.now();
2559
+ const checkTimeout = 1e4;
2560
+ const checkInterval = 3e3;
2561
+ while (Date.now() - startTime < this.config.startupTimeout * 1e3) {
2562
+ let timeoutId;
2563
+ try {
2564
+ logger8.info(`Checking status... (elapsed: ${Math.round((Date.now() - startTime) / 1e3)}s)`);
2565
+ const statusPromise = this.getStatus(options);
2566
+ const timeoutPromise = new Promise((_, reject) => {
2567
+ timeoutId = setTimeout(() => reject(new Error("Status check timeout")), checkTimeout);
2568
+ });
2569
+ const status = await Promise.race([statusPromise, timeoutPromise]);
2570
+ if (status && status.isAlive) {
2571
+ logger8.info("Sandbox is alive");
2572
+ return;
2573
+ }
2574
+ if (options?.includeAllStates && status) {
2575
+ const errorMsg = this.parseErrorMessageFromStatus(status.status);
2576
+ if (errorMsg) {
2577
+ throw new InternalServerRockError(
2578
+ `Failed to restart sandbox because ${errorMsg}, sandbox: ${this.toString()}`
2579
+ );
2580
+ }
2581
+ }
2582
+ } catch (e) {
2583
+ if (e instanceof InternalServerRockError) {
2584
+ throw e;
2585
+ }
2586
+ logger8.debug(`Status check failed (will retry): ${e}`);
2587
+ } finally {
2588
+ clearTimeout(timeoutId);
2589
+ }
2590
+ await sleep(checkInterval);
2591
+ }
2592
+ throw new InternalServerRockError(
2593
+ `Failed to start sandbox within ${this.config.startupTimeout}s, sandbox: ${this.toString()}`
2594
+ );
2595
+ }
2596
+ parseErrorMessageFromStatus(status) {
2597
+ if (!status) return null;
2598
+ for (const [stage, details] of Object.entries(status)) {
2599
+ if (details && typeof details === "object") {
2600
+ const d = details;
2601
+ if (d.status === "failed" || d.status === "timeout") {
2602
+ return `${stage}: ${d.message ?? "No message provided"}`;
2603
+ }
2604
+ }
2605
+ }
2606
+ return null;
2607
+ }
2471
2608
  // Close
2472
2609
  async close() {
2473
2610
  await this.stop();
@@ -3433,6 +3570,7 @@ exports.DefaultAgent = DefaultAgent;
3433
3570
  exports.DefaultAgentConfigSchema = DefaultAgentConfigSchema;
3434
3571
  exports.Deploy = Deploy;
3435
3572
  exports.DownloadFileResponseSchema = DownloadFileResponseSchema;
3573
+ exports.DownloadModeSchema = DownloadModeSchema;
3436
3574
  exports.EnvHubClient = EnvHubClient;
3437
3575
  exports.EnvHubClientConfigSchema = EnvHubClientConfigSchema;
3438
3576
  exports.EnvHubError = EnvHubError;