rl-rock 1.3.8 → 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 +61 -4
- package/dist/index.d.ts +61 -4
- package/dist/index.js +103 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -16
- 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,9 +1342,21 @@ 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)
|
|
1305
1362
|
* @param timeout - Optional timeout in milliseconds
|
|
@@ -2427,4 +2484,4 @@ declare class DefaultAgent extends Agent {
|
|
|
2427
2484
|
*/
|
|
2428
2485
|
declare const VERSION: string;
|
|
2429
2486
|
|
|
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 };
|
|
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,9 +1342,21 @@ 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)
|
|
1305
1362
|
* @param timeout - Optional timeout in milliseconds
|
|
@@ -2427,4 +2484,4 @@ declare class DefaultAgent extends Agent {
|
|
|
2427
2484
|
*/
|
|
2428
2485
|
declare const VERSION: string;
|
|
2429
2486
|
|
|
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 };
|
|
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(),
|
|
@@ -2298,9 +2299,12 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2298
2299
|
async upload(request) {
|
|
2299
2300
|
return this.uploadByPath(request.sourcePath, request.targetPath);
|
|
2300
2301
|
}
|
|
2301
|
-
async uploadByPath(sourcePath, targetPath,
|
|
2302
|
+
async uploadByPath(sourcePath, targetPath, options) {
|
|
2302
2303
|
const url = `${this.url}/upload`;
|
|
2303
2304
|
const headers = this.buildHeaders();
|
|
2305
|
+
const uploadMode = options?.uploadMode ?? "auto";
|
|
2306
|
+
const timeout = options?.timeout;
|
|
2307
|
+
const onProgress = options?.onProgress;
|
|
2304
2308
|
try {
|
|
2305
2309
|
const fs = await import('fs/promises');
|
|
2306
2310
|
try {
|
|
@@ -2313,7 +2317,7 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2313
2317
|
const ossEnabled = envVars.ROCK_OSS_ENABLE;
|
|
2314
2318
|
const ossThreshold = 1024 * 1024;
|
|
2315
2319
|
if (uploadMode === "oss" || uploadMode === "auto" && ossEnabled && fileSize > ossThreshold) {
|
|
2316
|
-
return this.uploadViaOss(sourcePath, targetPath, timeout);
|
|
2320
|
+
return this.uploadViaOss(sourcePath, targetPath, timeout, onProgress);
|
|
2317
2321
|
}
|
|
2318
2322
|
const fileBuffer = await fs.readFile(sourcePath);
|
|
2319
2323
|
const fileName = sourcePath.split("/").pop() ?? "file";
|
|
@@ -2362,9 +2366,61 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2362
2366
|
}
|
|
2363
2367
|
}
|
|
2364
2368
|
/**
|
|
2365
|
-
* 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
|
|
2366
2374
|
*/
|
|
2367
|
-
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) {
|
|
2368
2424
|
if (!envVars.ROCK_OSS_ENABLE) {
|
|
2369
2425
|
return {
|
|
2370
2426
|
success: false,
|
|
@@ -2372,13 +2428,6 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2372
2428
|
};
|
|
2373
2429
|
}
|
|
2374
2430
|
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
2431
|
if (this.ossBucket === null || this.isTokenExpired()) {
|
|
2383
2432
|
await this.setupOss(timeout);
|
|
2384
2433
|
}
|
|
@@ -2400,21 +2449,29 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2400
2449
|
return { success: false, message: `Sandbox to OSS upload failed: ${uploadResult.output}` };
|
|
2401
2450
|
}
|
|
2402
2451
|
const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
|
|
2403
|
-
const result = await this.ossBucket.get(objectName, localPath, {
|
|
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
|
+
});
|
|
2404
2461
|
try {
|
|
2405
2462
|
await this.ossBucket.delete(objectName);
|
|
2406
2463
|
} catch {
|
|
2407
2464
|
}
|
|
2408
2465
|
return { success: true, message: `Successfully downloaded ${remotePath} to ${localPath}` };
|
|
2409
2466
|
} catch (e) {
|
|
2410
|
-
return { success: false, message: `
|
|
2467
|
+
return { success: false, message: `OSS download failed: ${e}` };
|
|
2411
2468
|
}
|
|
2412
2469
|
}
|
|
2413
2470
|
/**
|
|
2414
2471
|
* Upload file via OSS (internal method)
|
|
2415
2472
|
* @param timeout - Optional timeout in milliseconds
|
|
2416
2473
|
*/
|
|
2417
|
-
async uploadViaOss(sourcePath, targetPath, timeout) {
|
|
2474
|
+
async uploadViaOss(sourcePath, targetPath, timeout, onProgress) {
|
|
2418
2475
|
try {
|
|
2419
2476
|
if (this.ossBucket === null || this.isTokenExpired()) {
|
|
2420
2477
|
await this.setupOss(timeout);
|
|
@@ -2425,9 +2482,39 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
2425
2482
|
const timestamp = Date.now();
|
|
2426
2483
|
const fileName = sourcePath.split("/").pop() ?? "file";
|
|
2427
2484
|
const objectName = `${timestamp}-${fileName}`;
|
|
2485
|
+
const fs = await import('fs/promises');
|
|
2486
|
+
const stats = await fs.stat(sourcePath);
|
|
2487
|
+
const fileSize = stats.size;
|
|
2488
|
+
const multipartThreshold = 1024 * 1024;
|
|
2428
2489
|
const ossTimeout = timeout ?? envVars.ROCK_OSS_TIMEOUT;
|
|
2429
|
-
|
|
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
|
+
}
|
|
2430
2513
|
const signedUrl = this.ossBucket.signatureUrl(objectName, { expires: 600 });
|
|
2514
|
+
onProgress?.({
|
|
2515
|
+
phase: "download-to-sandbox",
|
|
2516
|
+
percent: -1
|
|
2517
|
+
});
|
|
2431
2518
|
const downloadCmd = `wget -c -O '${targetPath}' '${signedUrl}'`;
|
|
2432
2519
|
await this.arun(downloadCmd, { mode: "nohup", waitTimeout: 600 });
|
|
2433
2520
|
const checkResult = await this.execute({ command: ["test", "-f", targetPath], timeout: 60 });
|
|
@@ -3433,6 +3520,7 @@ exports.DefaultAgent = DefaultAgent;
|
|
|
3433
3520
|
exports.DefaultAgentConfigSchema = DefaultAgentConfigSchema;
|
|
3434
3521
|
exports.Deploy = Deploy;
|
|
3435
3522
|
exports.DownloadFileResponseSchema = DownloadFileResponseSchema;
|
|
3523
|
+
exports.DownloadModeSchema = DownloadModeSchema;
|
|
3436
3524
|
exports.EnvHubClient = EnvHubClient;
|
|
3437
3525
|
exports.EnvHubClientConfigSchema = EnvHubClientConfigSchema;
|
|
3438
3526
|
exports.EnvHubError = EnvHubError;
|