rl-rock 1.2.2 → 1.2.4
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 +33 -11
- package/dist/index.d.ts +33 -11
- package/dist/index.js +77 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -11
package/dist/index.mjs
CHANGED
|
@@ -110,7 +110,11 @@ var SandboxStatusResponseSchema = z.object({
|
|
|
110
110
|
namespace: z.string().optional(),
|
|
111
111
|
cpus: z.number().optional(),
|
|
112
112
|
memory: z.string().optional(),
|
|
113
|
-
state: z.unknown().optional()
|
|
113
|
+
state: z.unknown().optional(),
|
|
114
|
+
// Response headers info
|
|
115
|
+
cluster: z.string().optional(),
|
|
116
|
+
requestId: z.string().optional(),
|
|
117
|
+
eagleeyeTraceid: z.string().optional()
|
|
114
118
|
});
|
|
115
119
|
var CommandResponseSchema = z.object({
|
|
116
120
|
stdout: z.string().default(""),
|
|
@@ -282,7 +286,18 @@ var HttpUtils = class {
|
|
|
282
286
|
const snakeData = objectToSnake(data);
|
|
283
287
|
try {
|
|
284
288
|
const response = await client.post(url, snakeData);
|
|
285
|
-
|
|
289
|
+
const camelData = objectToCamel(response.data);
|
|
290
|
+
const httpResponse = {
|
|
291
|
+
status: camelData.status ?? "Success",
|
|
292
|
+
headers: this.extractHeaders(response)
|
|
293
|
+
};
|
|
294
|
+
if (camelData.result !== void 0) {
|
|
295
|
+
httpResponse.result = camelData.result;
|
|
296
|
+
}
|
|
297
|
+
if (camelData.error !== void 0) {
|
|
298
|
+
httpResponse.error = camelData.error;
|
|
299
|
+
}
|
|
300
|
+
return httpResponse;
|
|
286
301
|
} catch (error) {
|
|
287
302
|
if (error instanceof AxiosError) {
|
|
288
303
|
throw new Error(`Failed to POST ${url}: ${error.message}`);
|
|
@@ -298,7 +313,18 @@ var HttpUtils = class {
|
|
|
298
313
|
const client = this.createClient({ headers });
|
|
299
314
|
try {
|
|
300
315
|
const response = await client.get(url);
|
|
301
|
-
|
|
316
|
+
const camelData = objectToCamel(response.data);
|
|
317
|
+
const httpResponse = {
|
|
318
|
+
status: camelData.status ?? "Success",
|
|
319
|
+
headers: this.extractHeaders(response)
|
|
320
|
+
};
|
|
321
|
+
if (camelData.result !== void 0) {
|
|
322
|
+
httpResponse.result = camelData.result;
|
|
323
|
+
}
|
|
324
|
+
if (camelData.error !== void 0) {
|
|
325
|
+
httpResponse.error = camelData.error;
|
|
326
|
+
}
|
|
327
|
+
return httpResponse;
|
|
302
328
|
} catch (error) {
|
|
303
329
|
if (error instanceof AxiosError) {
|
|
304
330
|
throw new Error(`Failed to GET ${url}: ${error.message}`);
|
|
@@ -306,6 +332,20 @@ var HttpUtils = class {
|
|
|
306
332
|
throw error;
|
|
307
333
|
}
|
|
308
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Extract headers from axios response
|
|
337
|
+
*/
|
|
338
|
+
static extractHeaders(response) {
|
|
339
|
+
const headers = {};
|
|
340
|
+
for (const [key, value] of Object.entries(response.headers)) {
|
|
341
|
+
if (typeof value === "string") {
|
|
342
|
+
headers[key.toLowerCase()] = value;
|
|
343
|
+
} else if (Array.isArray(value)) {
|
|
344
|
+
headers[key.toLowerCase()] = value.join(", ");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return headers;
|
|
348
|
+
}
|
|
309
349
|
/**
|
|
310
350
|
* Convert camelCase key to snake_case
|
|
311
351
|
*/
|
|
@@ -352,7 +392,18 @@ var HttpUtils = class {
|
|
|
352
392
|
});
|
|
353
393
|
try {
|
|
354
394
|
const response = await client.post(url, formData);
|
|
355
|
-
|
|
395
|
+
const camelData = objectToCamel(response.data);
|
|
396
|
+
const httpResponse = {
|
|
397
|
+
status: camelData.status ?? "Success",
|
|
398
|
+
headers: this.extractHeaders(response)
|
|
399
|
+
};
|
|
400
|
+
if (camelData.result !== void 0) {
|
|
401
|
+
httpResponse.result = camelData.result;
|
|
402
|
+
}
|
|
403
|
+
if (camelData.error !== void 0) {
|
|
404
|
+
httpResponse.error = camelData.error;
|
|
405
|
+
}
|
|
406
|
+
return httpResponse;
|
|
356
407
|
} catch (error) {
|
|
357
408
|
if (error instanceof AxiosError) {
|
|
358
409
|
throw new Error(`Failed to POST multipart ${url}: ${error.message}`);
|
|
@@ -563,7 +614,7 @@ var EnvHubClient = class {
|
|
|
563
614
|
this.headers,
|
|
564
615
|
payload
|
|
565
616
|
);
|
|
566
|
-
return createRockEnvInfo(response);
|
|
617
|
+
return createRockEnvInfo(response.result);
|
|
567
618
|
} catch (e) {
|
|
568
619
|
throw new EnvHubError(`Failed to register environment: ${e}`);
|
|
569
620
|
}
|
|
@@ -580,7 +631,7 @@ var EnvHubClient = class {
|
|
|
580
631
|
this.headers,
|
|
581
632
|
payload
|
|
582
633
|
);
|
|
583
|
-
return createRockEnvInfo(response);
|
|
634
|
+
return createRockEnvInfo(response.result);
|
|
584
635
|
} catch (e) {
|
|
585
636
|
throw new EnvHubError(`Failed to get environment ${envName}: ${e}`);
|
|
586
637
|
}
|
|
@@ -600,7 +651,7 @@ var EnvHubClient = class {
|
|
|
600
651
|
this.headers,
|
|
601
652
|
payload
|
|
602
653
|
);
|
|
603
|
-
const envsData = response.envs ?? [];
|
|
654
|
+
const envsData = response.result?.envs ?? [];
|
|
604
655
|
return envsData.map((envData) => createRockEnvInfo(envData));
|
|
605
656
|
} catch (e) {
|
|
606
657
|
throw new EnvHubError(`Failed to list environments: ${e}`);
|
|
@@ -633,7 +684,7 @@ var EnvHubClient = class {
|
|
|
633
684
|
url,
|
|
634
685
|
this.headers
|
|
635
686
|
);
|
|
636
|
-
return response;
|
|
687
|
+
return response.result ?? {};
|
|
637
688
|
} catch (e) {
|
|
638
689
|
throw new EnvHubError(`Failed to health check: ${e}`);
|
|
639
690
|
}
|
|
@@ -1082,7 +1133,7 @@ var Process = class {
|
|
|
1082
1133
|
const scriptPath = `/tmp/${name}`;
|
|
1083
1134
|
try {
|
|
1084
1135
|
logger5.info(`[${sandboxId}] Uploading script to ${scriptPath}`);
|
|
1085
|
-
const writeResult = await this.sandbox.
|
|
1136
|
+
const writeResult = await this.sandbox.writeFile({
|
|
1086
1137
|
content: scriptContent,
|
|
1087
1138
|
path: scriptPath
|
|
1088
1139
|
});
|
|
@@ -1422,9 +1473,14 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
1422
1473
|
const headers = this.buildHeaders();
|
|
1423
1474
|
const response = await HttpUtils.get(url, headers);
|
|
1424
1475
|
if (response.status !== "Success") {
|
|
1425
|
-
|
|
1476
|
+
const errorDetail = response.error ? `, error=${response.error}` : "";
|
|
1477
|
+
throw new Error(`Failed to get status: status=${response.status}${errorDetail}, result=${JSON.stringify(response.result)}`);
|
|
1426
1478
|
}
|
|
1427
|
-
|
|
1479
|
+
const result = response.result;
|
|
1480
|
+
result.cluster = response.headers["x-rock-gateway-target-cluster"] || this.config.cluster || "N/A";
|
|
1481
|
+
result.requestId = response.headers["x-request-id"] || response.headers["request-id"] || "N/A";
|
|
1482
|
+
result.eagleeyeTraceid = response.headers["eagleeye-traceid"] || "N/A";
|
|
1483
|
+
return result;
|
|
1428
1484
|
}
|
|
1429
1485
|
// Command execution
|
|
1430
1486
|
async execute(command) {
|
|
@@ -1444,7 +1500,8 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
1444
1500
|
data
|
|
1445
1501
|
);
|
|
1446
1502
|
if (response.status !== "Success") {
|
|
1447
|
-
|
|
1503
|
+
const errorDetail = response.error ? `, error=${response.error}` : "";
|
|
1504
|
+
throw new Error(`Failed to execute command: status=${response.status}${errorDetail}, result=${JSON.stringify(response.result)}`);
|
|
1448
1505
|
}
|
|
1449
1506
|
return response.result;
|
|
1450
1507
|
} catch (e) {
|
|
@@ -1466,7 +1523,8 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
1466
1523
|
data
|
|
1467
1524
|
);
|
|
1468
1525
|
if (response.status !== "Success") {
|
|
1469
|
-
|
|
1526
|
+
const errorDetail = response.error ? `, error=${response.error}` : "";
|
|
1527
|
+
throw new Error(`Failed to create session: status=${response.status}${errorDetail}, result=${JSON.stringify(response.result)}`);
|
|
1470
1528
|
}
|
|
1471
1529
|
return response.result;
|
|
1472
1530
|
} catch (e) {
|
|
@@ -1487,7 +1545,8 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
1487
1545
|
data
|
|
1488
1546
|
);
|
|
1489
1547
|
if (response.status !== "Success") {
|
|
1490
|
-
|
|
1548
|
+
const errorDetail = response.error ? `, error=${response.error}` : "";
|
|
1549
|
+
throw new Error(`Failed to close session: status=${response.status}${errorDetail}, result=${JSON.stringify(response.result)}`);
|
|
1491
1550
|
}
|
|
1492
1551
|
return response.result ?? { sessionType: "bash" };
|
|
1493
1552
|
} catch (e) {
|
|
@@ -1533,7 +1592,8 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
1533
1592
|
timeoutMs
|
|
1534
1593
|
);
|
|
1535
1594
|
if (response.status !== "Success") {
|
|
1536
|
-
|
|
1595
|
+
const errorDetail = response.error ? `, error=${response.error}` : "";
|
|
1596
|
+
throw new Error(`Failed to run in session: status=${response.status}${errorDetail}, result=${JSON.stringify(response.result)}`);
|
|
1537
1597
|
}
|
|
1538
1598
|
return response.result;
|
|
1539
1599
|
} catch (e) {
|
|
@@ -1621,7 +1681,7 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
1621
1681
|
return false;
|
|
1622
1682
|
}
|
|
1623
1683
|
// File operations
|
|
1624
|
-
async
|
|
1684
|
+
async writeFile(request) {
|
|
1625
1685
|
const url = `${this.url}/write_file`;
|
|
1626
1686
|
const headers = this.buildHeaders();
|
|
1627
1687
|
const data = {
|
|
@@ -1635,7 +1695,7 @@ var Sandbox = class extends AbstractSandbox {
|
|
|
1635
1695
|
}
|
|
1636
1696
|
return { success: true, message: `Successfully write content to file ${request.path}` };
|
|
1637
1697
|
}
|
|
1638
|
-
async
|
|
1698
|
+
async readFile(request) {
|
|
1639
1699
|
const url = `${this.url}/read_file`;
|
|
1640
1700
|
const headers = this.buildHeaders();
|
|
1641
1701
|
const data = {
|