rl-rock 1.3.7 → 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 +63 -4
- package/dist/index.d.ts +63 -4
- package/dist/index.js +115 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
@@ -1287,7 +1332,7 @@ declare class Sandbox extends AbstractSandbox {
|
|
|
1287
1332
|
writeFile(request: WriteFileRequest): Promise<WriteFileResponse>;
|
|
1288
1333
|
readFile(request: ReadFileRequest): Promise<ReadFileResponse>;
|
|
1289
1334
|
upload(request: UploadRequest): Promise<UploadResponse>;
|
|
1290
|
-
uploadByPath(sourcePath: string, targetPath: string,
|
|
1335
|
+
uploadByPath(sourcePath: string, targetPath: string, options?: UploadOptions): Promise<UploadResponse>;
|
|
1291
1336
|
/**
|
|
1292
1337
|
* Get OSS STS credentials from sandbox
|
|
1293
1338
|
*/
|
|
@@ -1297,15 +1342,29 @@ declare class Sandbox extends AbstractSandbox {
|
|
|
1297
1342
|
*/
|
|
1298
1343
|
isTokenExpired(): boolean;
|
|
1299
1344
|
/**
|
|
1300
|
-
* Download file from sandbox
|
|
1345
|
+
* Download file from sandbox
|
|
1346
|
+
* @param remotePath - File path in sandbox
|
|
1347
|
+
* @param localPath - Local file path
|
|
1348
|
+
* @param downloadMode - Download mode: 'auto' (default), 'direct', or 'oss'
|
|
1349
|
+
* @param timeout - Optional timeout in milliseconds for OSS mode
|
|
1350
|
+
*/
|
|
1351
|
+
downloadFile(remotePath: string, localPath: string, options?: DownloadOptions): Promise<DownloadFileResponse>;
|
|
1352
|
+
/**
|
|
1353
|
+
* Download file directly via readFile API
|
|
1354
|
+
*/
|
|
1355
|
+
private downloadDirect;
|
|
1356
|
+
/**
|
|
1357
|
+
* Download file via OSS as intermediary
|
|
1301
1358
|
*/
|
|
1302
|
-
|
|
1359
|
+
private downloadViaOss;
|
|
1303
1360
|
/**
|
|
1304
1361
|
* Upload file via OSS (internal method)
|
|
1362
|
+
* @param timeout - Optional timeout in milliseconds
|
|
1305
1363
|
*/
|
|
1306
1364
|
private uploadViaOss;
|
|
1307
1365
|
/**
|
|
1308
1366
|
* Setup OSS bucket with STS credentials
|
|
1367
|
+
* @param timeout - Optional timeout in milliseconds (defaults to ROCK_OSS_TIMEOUT env var or 300000ms)
|
|
1309
1368
|
*/
|
|
1310
1369
|
private setupOss;
|
|
1311
1370
|
close(): Promise<void>;
|
|
@@ -2425,4 +2484,4 @@ declare class DefaultAgent extends Agent {
|
|
|
2425
2484
|
*/
|
|
2426
2485
|
declare const VERSION: string;
|
|
2427
2486
|
|
|
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 };
|
|
2487
|
+
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
|
|
@@ -1287,7 +1332,7 @@ declare class Sandbox extends AbstractSandbox {
|
|
|
1287
1332
|
writeFile(request: WriteFileRequest): Promise<WriteFileResponse>;
|
|
1288
1333
|
readFile(request: ReadFileRequest): Promise<ReadFileResponse>;
|
|
1289
1334
|
upload(request: UploadRequest): Promise<UploadResponse>;
|
|
1290
|
-
uploadByPath(sourcePath: string, targetPath: string,
|
|
1335
|
+
uploadByPath(sourcePath: string, targetPath: string, options?: UploadOptions): Promise<UploadResponse>;
|
|
1291
1336
|
/**
|
|
1292
1337
|
* Get OSS STS credentials from sandbox
|
|
1293
1338
|
*/
|
|
@@ -1297,15 +1342,29 @@ declare class Sandbox extends AbstractSandbox {
|
|
|
1297
1342
|
*/
|
|
1298
1343
|
isTokenExpired(): boolean;
|
|
1299
1344
|
/**
|
|
1300
|
-
* Download file from sandbox
|
|
1345
|
+
* Download file from sandbox
|
|
1346
|
+
* @param remotePath - File path in sandbox
|
|
1347
|
+
* @param localPath - Local file path
|
|
1348
|
+
* @param downloadMode - Download mode: 'auto' (default), 'direct', or 'oss'
|
|
1349
|
+
* @param timeout - Optional timeout in milliseconds for OSS mode
|
|
1350
|
+
*/
|
|
1351
|
+
downloadFile(remotePath: string, localPath: string, options?: DownloadOptions): Promise<DownloadFileResponse>;
|
|
1352
|
+
/**
|
|
1353
|
+
* Download file directly via readFile API
|
|
1354
|
+
*/
|
|
1355
|
+
private downloadDirect;
|
|
1356
|
+
/**
|
|
1357
|
+
* Download file via OSS as intermediary
|
|
1301
1358
|
*/
|
|
1302
|
-
|
|
1359
|
+
private downloadViaOss;
|
|
1303
1360
|
/**
|
|
1304
1361
|
* Upload file via OSS (internal method)
|
|
1362
|
+
* @param timeout - Optional timeout in milliseconds
|
|
1305
1363
|
*/
|
|
1306
1364
|
private uploadViaOss;
|
|
1307
1365
|
/**
|
|
1308
1366
|
* Setup OSS bucket with STS credentials
|
|
1367
|
+
* @param timeout - Optional timeout in milliseconds (defaults to ROCK_OSS_TIMEOUT env var or 300000ms)
|
|
1309
1368
|
*/
|
|
1310
1369
|
private setupOss;
|
|
1311
1370
|
close(): Promise<void>;
|
|
@@ -2425,4 +2484,4 @@ declare class DefaultAgent extends Agent {
|
|
|
2425
2484
|
*/
|
|
2426
2485
|
declare const VERSION: string;
|
|
2427
2486
|
|
|
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 };
|
|
2487
|
+
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(),
|
|
@@ -601,6 +602,9 @@ var envVars = {
|
|
|
601
602
|
get ROCK_OSS_BUCKET_REGION() {
|
|
602
603
|
return getEnv("ROCK_OSS_BUCKET_REGION");
|
|
603
604
|
},
|
|
605
|
+
get ROCK_OSS_TIMEOUT() {
|
|
606
|
+
return parseInt(getEnv("ROCK_OSS_TIMEOUT", "300000"), 10);
|
|
607
|
+
},
|
|
604
608
|
// Pip
|
|
605
609
|
get ROCK_PIP_INDEX_URL() {
|
|
606
610
|
return getEnv("ROCK_PIP_INDEX_URL", "https://pypi.org/simple/");
|
|
@@ -2295,9 +2299,12 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2295
2299
|
async upload(request) {
|
|
2296
2300
|
return this.uploadByPath(request.sourcePath, request.targetPath);
|
|
2297
2301
|
}
|
|
2298
|
-
async uploadByPath(sourcePath, targetPath,
|
|
2302
|
+
async uploadByPath(sourcePath, targetPath, options) {
|
|
2299
2303
|
const url = `${this.url}/upload`;
|
|
2300
2304
|
const headers = this.buildHeaders();
|
|
2305
|
+
const uploadMode = options?.uploadMode ?? "auto";
|
|
2306
|
+
const timeout = options?.timeout;
|
|
2307
|
+
const onProgress = options?.onProgress;
|
|
2301
2308
|
try {
|
|
2302
2309
|
const fs = await import('fs/promises');
|
|
2303
2310
|
try {
|
|
@@ -2310,7 +2317,7 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2310
2317
|
const ossEnabled = envVars.ROCK_OSS_ENABLE;
|
|
2311
2318
|
const ossThreshold = 1024 * 1024;
|
|
2312
2319
|
if (uploadMode === "oss" || uploadMode === "auto" && ossEnabled && fileSize > ossThreshold) {
|
|
2313
|
-
return this.uploadViaOss(sourcePath, targetPath);
|
|
2320
|
+
return this.uploadViaOss(sourcePath, targetPath, timeout, onProgress);
|
|
2314
2321
|
}
|
|
2315
2322
|
const fileBuffer = await fs.readFile(sourcePath);
|
|
2316
2323
|
const fileName = sourcePath.split("/").pop() ?? "file";
|
|
@@ -2359,9 +2366,61 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2359
2366
|
}
|
|
2360
2367
|
}
|
|
2361
2368
|
/**
|
|
2362
|
-
* Download file from sandbox
|
|
2369
|
+
* Download file from sandbox
|
|
2370
|
+
* @param remotePath - File path in sandbox
|
|
2371
|
+
* @param localPath - Local file path
|
|
2372
|
+
* @param downloadMode - Download mode: 'auto' (default), 'direct', or 'oss'
|
|
2373
|
+
* @param timeout - Optional timeout in milliseconds for OSS mode
|
|
2363
2374
|
*/
|
|
2364
|
-
async downloadFile(remotePath, localPath) {
|
|
2375
|
+
async downloadFile(remotePath, localPath, options) {
|
|
2376
|
+
const downloadMode = options?.downloadMode ?? "auto";
|
|
2377
|
+
const timeout = options?.timeout;
|
|
2378
|
+
const onProgress = options?.onProgress;
|
|
2379
|
+
if (!remotePath || remotePath.trim() === "") {
|
|
2380
|
+
return { success: false, message: "Remote path is required" };
|
|
2381
|
+
}
|
|
2382
|
+
const checkResult = await this.execute({ command: ["test", "-f", remotePath], timeout: 60 });
|
|
2383
|
+
if (checkResult.exitCode !== 0) {
|
|
2384
|
+
return { success: false, message: `Remote file does not exist: ${remotePath}` };
|
|
2385
|
+
}
|
|
2386
|
+
if (downloadMode === "direct") {
|
|
2387
|
+
return this.downloadDirect(remotePath, localPath);
|
|
2388
|
+
}
|
|
2389
|
+
if (downloadMode === "oss") {
|
|
2390
|
+
return this.downloadViaOss(remotePath, localPath, timeout, onProgress);
|
|
2391
|
+
}
|
|
2392
|
+
const sizeResult = await this.execute({ command: ["stat", "-c", "%s", remotePath], timeout: 60 });
|
|
2393
|
+
if (sizeResult.exitCode !== 0) {
|
|
2394
|
+
return this.downloadDirect(remotePath, localPath);
|
|
2395
|
+
}
|
|
2396
|
+
const fileSize = parseInt(sizeResult.stdout.trim(), 10);
|
|
2397
|
+
const ossThreshold = 1024 * 1024;
|
|
2398
|
+
const ossEnabled = envVars.ROCK_OSS_ENABLE;
|
|
2399
|
+
if (ossEnabled && fileSize >= ossThreshold) {
|
|
2400
|
+
return this.downloadViaOss(remotePath, localPath, timeout, onProgress);
|
|
2401
|
+
}
|
|
2402
|
+
return this.downloadDirect(remotePath, localPath);
|
|
2403
|
+
}
|
|
2404
|
+
/**
|
|
2405
|
+
* Download file directly via readFile API
|
|
2406
|
+
*/
|
|
2407
|
+
async downloadDirect(remotePath, localPath) {
|
|
2408
|
+
try {
|
|
2409
|
+
const fs = await import('fs/promises');
|
|
2410
|
+
const path = await import('path');
|
|
2411
|
+
const response = await this.readFile({ path: remotePath });
|
|
2412
|
+
const parentDir = path.dirname(localPath);
|
|
2413
|
+
await fs.mkdir(parentDir, { recursive: true });
|
|
2414
|
+
await fs.writeFile(localPath, response.content, "utf-8");
|
|
2415
|
+
return { success: true, message: `Successfully downloaded ${remotePath} to ${localPath}` };
|
|
2416
|
+
} catch (e) {
|
|
2417
|
+
return { success: false, message: `Direct download failed: ${e}` };
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
/**
|
|
2421
|
+
* Download file via OSS as intermediary
|
|
2422
|
+
*/
|
|
2423
|
+
async downloadViaOss(remotePath, localPath, timeout, onProgress) {
|
|
2365
2424
|
if (!envVars.ROCK_OSS_ENABLE) {
|
|
2366
2425
|
return {
|
|
2367
2426
|
success: false,
|
|
@@ -2369,15 +2428,8 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2369
2428
|
};
|
|
2370
2429
|
}
|
|
2371
2430
|
try {
|
|
2372
|
-
if (!remotePath || remotePath.trim() === "") {
|
|
2373
|
-
return { success: false, message: "Remote path is required" };
|
|
2374
|
-
}
|
|
2375
|
-
const checkResult = await this.execute({ command: ["test", "-f", remotePath], timeout: 60 });
|
|
2376
|
-
if (checkResult.exitCode !== 0) {
|
|
2377
|
-
return { success: false, message: `Remote file does not exist: ${remotePath}` };
|
|
2378
|
-
}
|
|
2379
2431
|
if (this.ossBucket === null || this.isTokenExpired()) {
|
|
2380
|
-
await this.setupOss();
|
|
2432
|
+
await this.setupOss(timeout);
|
|
2381
2433
|
}
|
|
2382
2434
|
if (!this.ossBucket) {
|
|
2383
2435
|
return { success: false, message: "Failed to setup OSS bucket" };
|
|
@@ -2396,23 +2448,33 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2396
2448
|
if (uploadResult.exitCode !== 0) {
|
|
2397
2449
|
return { success: false, message: `Sandbox to OSS upload failed: ${uploadResult.output}` };
|
|
2398
2450
|
}
|
|
2399
|
-
const
|
|
2451
|
+
const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
|
|
2452
|
+
const result = await this.ossBucket.get(objectName, localPath, {
|
|
2453
|
+
timeout: ossTimeout,
|
|
2454
|
+
progress: (p) => {
|
|
2455
|
+
onProgress?.({
|
|
2456
|
+
phase: "download-to-local",
|
|
2457
|
+
percent: Math.round(p * 100)
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
});
|
|
2400
2461
|
try {
|
|
2401
2462
|
await this.ossBucket.delete(objectName);
|
|
2402
2463
|
} catch {
|
|
2403
2464
|
}
|
|
2404
2465
|
return { success: true, message: `Successfully downloaded ${remotePath} to ${localPath}` };
|
|
2405
2466
|
} catch (e) {
|
|
2406
|
-
return { success: false, message: `
|
|
2467
|
+
return { success: false, message: `OSS download failed: ${e}` };
|
|
2407
2468
|
}
|
|
2408
2469
|
}
|
|
2409
2470
|
/**
|
|
2410
2471
|
* Upload file via OSS (internal method)
|
|
2472
|
+
* @param timeout - Optional timeout in milliseconds
|
|
2411
2473
|
*/
|
|
2412
|
-
async uploadViaOss(sourcePath, targetPath) {
|
|
2474
|
+
async uploadViaOss(sourcePath, targetPath, timeout, onProgress) {
|
|
2413
2475
|
try {
|
|
2414
2476
|
if (this.ossBucket === null || this.isTokenExpired()) {
|
|
2415
|
-
await this.setupOss();
|
|
2477
|
+
await this.setupOss(timeout);
|
|
2416
2478
|
}
|
|
2417
2479
|
if (!this.ossBucket) {
|
|
2418
2480
|
return { success: false, message: "Failed to setup OSS bucket" };
|
|
@@ -2420,8 +2482,39 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2420
2482
|
const timestamp = Date.now();
|
|
2421
2483
|
const fileName = sourcePath.split("/").pop() ?? "file";
|
|
2422
2484
|
const objectName = `${timestamp}-${fileName}`;
|
|
2423
|
-
await
|
|
2485
|
+
const fs = await import('fs/promises');
|
|
2486
|
+
const stats = await fs.stat(sourcePath);
|
|
2487
|
+
const fileSize = stats.size;
|
|
2488
|
+
const multipartThreshold = 1024 * 1024;
|
|
2489
|
+
const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
|
|
2490
|
+
if (fileSize >= multipartThreshold) {
|
|
2491
|
+
await this.ossBucket.multipartUpload(objectName, sourcePath, {
|
|
2492
|
+
timeout: ossTimeout,
|
|
2493
|
+
partSize: multipartThreshold,
|
|
2494
|
+
// 1MB per part
|
|
2495
|
+
progress: (p) => {
|
|
2496
|
+
onProgress?.({
|
|
2497
|
+
phase: "upload-to-oss",
|
|
2498
|
+
percent: Math.round(p * 100)
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
});
|
|
2502
|
+
} else {
|
|
2503
|
+
await this.ossBucket.put(objectName, sourcePath, {
|
|
2504
|
+
timeout: ossTimeout,
|
|
2505
|
+
progress: (p) => {
|
|
2506
|
+
onProgress?.({
|
|
2507
|
+
phase: "upload-to-oss",
|
|
2508
|
+
percent: Math.round(p * 100)
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2511
|
+
});
|
|
2512
|
+
}
|
|
2424
2513
|
const signedUrl = this.ossBucket.signatureUrl(objectName, { expires: 600 });
|
|
2514
|
+
onProgress?.({
|
|
2515
|
+
phase: "download-to-sandbox",
|
|
2516
|
+
percent: -1
|
|
2517
|
+
});
|
|
2425
2518
|
const downloadCmd = `wget -c -O '${targetPath}' '${signedUrl}'`;
|
|
2426
2519
|
await this.arun(downloadCmd, { mode: "nohup", waitTimeout: 600 });
|
|
2427
2520
|
const checkResult = await this.execute({ command: ["test", "-f", targetPath], timeout: 60 });
|
|
@@ -2435,13 +2528,16 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2435
2528
|
}
|
|
2436
2529
|
/**
|
|
2437
2530
|
* Setup OSS bucket with STS credentials
|
|
2531
|
+
* @param timeout - Optional timeout in milliseconds (defaults to ROCK_OSS_TIMEOUT env var or 300000ms)
|
|
2438
2532
|
*/
|
|
2439
|
-
async setupOss() {
|
|
2533
|
+
async setupOss(timeout) {
|
|
2440
2534
|
const credentials = await this.getOssStsCredentials();
|
|
2441
2535
|
const OSS = (await import('ali-oss')).default;
|
|
2536
|
+
const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
|
|
2442
2537
|
this.ossBucket = new OSS({
|
|
2443
2538
|
secure: true,
|
|
2444
2539
|
// Use HTTPS for OSS connections
|
|
2540
|
+
timeout: ossTimeout,
|
|
2445
2541
|
region: envVars.ROCK_OSS_BUCKET_REGION ?? "",
|
|
2446
2542
|
accessKeyId: credentials.accessKeyId,
|
|
2447
2543
|
accessKeySecret: credentials.accessKeySecret,
|
|
@@ -3424,6 +3520,7 @@ exports.DefaultAgent = DefaultAgent;
|
|
|
3424
3520
|
exports.DefaultAgentConfigSchema = DefaultAgentConfigSchema;
|
|
3425
3521
|
exports.Deploy = Deploy;
|
|
3426
3522
|
exports.DownloadFileResponseSchema = DownloadFileResponseSchema;
|
|
3523
|
+
exports.DownloadModeSchema = DownloadModeSchema;
|
|
3427
3524
|
exports.EnvHubClient = EnvHubClient;
|
|
3428
3525
|
exports.EnvHubClientConfigSchema = EnvHubClientConfigSchema;
|
|
3429
3526
|
exports.EnvHubError = EnvHubError;
|