rl-rock 1.2.2 → 1.2.3

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.js CHANGED
@@ -94,14 +94,21 @@ var ChmodRequestSchema = zod.z.object({
94
94
  mode: zod.z.string().default("755"),
95
95
  recursive: zod.z.boolean().default(false)
96
96
  });
97
+ var HeaderFieldsSchema = {
98
+ cluster: zod.z.string().optional(),
99
+ requestId: zod.z.string().optional(),
100
+ eagleeyeTraceid: zod.z.string().optional()
101
+ };
97
102
  var SandboxResponseSchema = zod.z.object({
98
103
  code: zod.z.nativeEnum(Codes).optional(),
99
104
  exitCode: zod.z.number().optional(),
100
- failureReason: zod.z.string().optional()
105
+ failureReason: zod.z.string().optional(),
106
+ ...HeaderFieldsSchema
101
107
  });
102
108
  var IsAliveResponseSchema = zod.z.object({
103
109
  isAlive: zod.z.boolean(),
104
- message: zod.z.string().default("")
110
+ message: zod.z.string().default(""),
111
+ ...HeaderFieldsSchema
105
112
  });
106
113
  var SandboxStatusResponseSchema = zod.z.object({
107
114
  sandboxId: zod.z.string().optional(),
@@ -118,54 +125,68 @@ var SandboxStatusResponseSchema = zod.z.object({
118
125
  namespace: zod.z.string().optional(),
119
126
  cpus: zod.z.number().optional(),
120
127
  memory: zod.z.string().optional(),
121
- state: zod.z.unknown().optional()
128
+ state: zod.z.unknown().optional(),
129
+ ...HeaderFieldsSchema
122
130
  });
123
131
  var CommandResponseSchema = zod.z.object({
124
132
  stdout: zod.z.string().default(""),
125
133
  stderr: zod.z.string().default(""),
126
- exitCode: zod.z.number().optional()
134
+ exitCode: zod.z.number().optional(),
135
+ ...HeaderFieldsSchema
127
136
  });
128
137
  var WriteFileResponseSchema = zod.z.object({
129
138
  success: zod.z.boolean().default(false),
130
- message: zod.z.string().default("")
139
+ message: zod.z.string().default(""),
140
+ ...HeaderFieldsSchema
131
141
  });
132
142
  var ReadFileResponseSchema = zod.z.object({
133
- content: zod.z.string().default("")
143
+ content: zod.z.string().default(""),
144
+ ...HeaderFieldsSchema
134
145
  });
135
146
  var UploadResponseSchema = zod.z.object({
136
147
  success: zod.z.boolean().default(false),
137
148
  message: zod.z.string().default(""),
138
- fileName: zod.z.string().optional()
149
+ fileName: zod.z.string().optional(),
150
+ ...HeaderFieldsSchema
139
151
  });
140
152
  var ObservationSchema = zod.z.object({
141
153
  output: zod.z.string().default(""),
142
154
  exitCode: zod.z.number().optional(),
143
155
  failureReason: zod.z.string().default(""),
144
- expectString: zod.z.string().default("")
156
+ expectString: zod.z.string().default(""),
157
+ ...HeaderFieldsSchema
145
158
  });
146
159
  var CreateSessionResponseSchema = zod.z.object({
147
160
  output: zod.z.string().default(""),
148
- sessionType: zod.z.literal("bash").default("bash")
161
+ sessionType: zod.z.literal("bash").default("bash"),
162
+ ...HeaderFieldsSchema
149
163
  });
150
164
  var CloseSessionResponseSchema = zod.z.object({
151
- sessionType: zod.z.literal("bash").default("bash")
165
+ sessionType: zod.z.literal("bash").default("bash"),
166
+ ...HeaderFieldsSchema
167
+ });
168
+ var CloseResponseSchema = zod.z.object({
169
+ ...HeaderFieldsSchema
152
170
  });
153
- var CloseResponseSchema = zod.z.object({});
154
171
  var ChownResponseSchema = zod.z.object({
155
172
  success: zod.z.boolean().default(false),
156
- message: zod.z.string().default("")
173
+ message: zod.z.string().default(""),
174
+ ...HeaderFieldsSchema
157
175
  });
158
176
  var ChmodResponseSchema = zod.z.object({
159
177
  success: zod.z.boolean().default(false),
160
- message: zod.z.string().default("")
178
+ message: zod.z.string().default(""),
179
+ ...HeaderFieldsSchema
161
180
  });
162
181
  var ExecuteBashSessionResponseSchema = zod.z.object({
163
182
  success: zod.z.boolean().default(false),
164
- message: zod.z.string().default("")
183
+ message: zod.z.string().default(""),
184
+ ...HeaderFieldsSchema
165
185
  });
166
186
  var OssSetupResponseSchema = zod.z.object({
167
187
  success: zod.z.boolean().default(false),
168
- message: zod.z.string().default("")
188
+ message: zod.z.string().default(""),
189
+ ...HeaderFieldsSchema
169
190
  });
170
191
 
171
192
  // src/common/constants.ts
@@ -281,6 +302,7 @@ var HttpUtils = class {
281
302
  * Send POST request
282
303
  * Automatically converts request body from camelCase to snake_case
283
304
  * Automatically converts response from snake_case to camelCase
305
+ * Returns structured response with headers
284
306
  */
285
307
  static async post(url, headers, data, readTimeout) {
286
308
  const client = this.createClient({
@@ -290,7 +312,18 @@ var HttpUtils = class {
290
312
  const snakeData = objectToSnake(data);
291
313
  try {
292
314
  const response = await client.post(url, snakeData);
293
- return objectToCamel(response.data);
315
+ const result = objectToCamel(response.data);
316
+ const responseHeaders = {};
317
+ for (const [key, value] of Object.entries(response.headers)) {
318
+ if (typeof value === "string") {
319
+ responseHeaders[key.toLowerCase()] = value;
320
+ }
321
+ }
322
+ return {
323
+ status: result?.status ?? "Success",
324
+ result,
325
+ headers: responseHeaders
326
+ };
294
327
  } catch (error) {
295
328
  if (error instanceof axios3.AxiosError) {
296
329
  throw new Error(`Failed to POST ${url}: ${error.message}`);
@@ -301,12 +334,24 @@ var HttpUtils = class {
301
334
  /**
302
335
  * Send GET request
303
336
  * Automatically converts response from snake_case to camelCase
337
+ * Returns structured response with headers
304
338
  */
305
339
  static async get(url, headers) {
306
340
  const client = this.createClient({ headers });
307
341
  try {
308
342
  const response = await client.get(url);
309
- return objectToCamel(response.data);
343
+ const result = objectToCamel(response.data);
344
+ const responseHeaders = {};
345
+ for (const [key, value] of Object.entries(response.headers)) {
346
+ if (typeof value === "string") {
347
+ responseHeaders[key.toLowerCase()] = value;
348
+ }
349
+ }
350
+ return {
351
+ status: result?.status ?? "Success",
352
+ result,
353
+ headers: responseHeaders
354
+ };
310
355
  } catch (error) {
311
356
  if (error instanceof axios3.AxiosError) {
312
357
  throw new Error(`Failed to GET ${url}: ${error.message}`);
@@ -324,6 +369,7 @@ var HttpUtils = class {
324
369
  * Send multipart/form-data request
325
370
  * Automatically converts form data keys to snake_case
326
371
  * Automatically converts response from snake_case to camelCase
372
+ * Returns structured response with headers
327
373
  */
328
374
  static async postMultipart(url, headers, data, files) {
329
375
  const formData = new FormData();
@@ -360,7 +406,18 @@ var HttpUtils = class {
360
406
  });
361
407
  try {
362
408
  const response = await client.post(url, formData);
363
- return objectToCamel(response.data);
409
+ const result = objectToCamel(response.data);
410
+ const responseHeaders = {};
411
+ for (const [key, value] of Object.entries(response.headers)) {
412
+ if (typeof value === "string") {
413
+ responseHeaders[key.toLowerCase()] = value;
414
+ }
415
+ }
416
+ return {
417
+ status: result?.status ?? "Success",
418
+ result,
419
+ headers: responseHeaders
420
+ };
364
421
  } catch (error) {
365
422
  if (error instanceof axios3.AxiosError) {
366
423
  throw new Error(`Failed to POST multipart ${url}: ${error.message}`);
@@ -571,7 +628,7 @@ var EnvHubClient = class {
571
628
  this.headers,
572
629
  payload
573
630
  );
574
- return createRockEnvInfo(response);
631
+ return createRockEnvInfo(response.result);
575
632
  } catch (e) {
576
633
  throw new EnvHubError(`Failed to register environment: ${e}`);
577
634
  }
@@ -588,7 +645,7 @@ var EnvHubClient = class {
588
645
  this.headers,
589
646
  payload
590
647
  );
591
- return createRockEnvInfo(response);
648
+ return createRockEnvInfo(response.result);
592
649
  } catch (e) {
593
650
  throw new EnvHubError(`Failed to get environment ${envName}: ${e}`);
594
651
  }
@@ -608,7 +665,7 @@ var EnvHubClient = class {
608
665
  this.headers,
609
666
  payload
610
667
  );
611
- const envsData = response.envs ?? [];
668
+ const envsData = response.result?.envs ?? [];
612
669
  return envsData.map((envData) => createRockEnvInfo(envData));
613
670
  } catch (e) {
614
671
  throw new EnvHubError(`Failed to list environments: ${e}`);
@@ -641,7 +698,7 @@ var EnvHubClient = class {
641
698
  url,
642
699
  this.headers
643
700
  );
644
- return response;
701
+ return response.result;
645
702
  } catch (e) {
646
703
  throw new EnvHubError(`Failed to health check: ${e}`);
647
704
  }
@@ -1090,7 +1147,7 @@ var Process = class {
1090
1147
  const scriptPath = `/tmp/${name}`;
1091
1148
  try {
1092
1149
  logger5.info(`[${sandboxId}] Uploading script to ${scriptPath}`);
1093
- const writeResult = await this.sandbox.write_file({
1150
+ const writeResult = await this.sandbox.writeFile({
1094
1151
  content: scriptContent,
1095
1152
  path: scriptPath
1096
1153
  });
@@ -1349,6 +1406,16 @@ var Sandbox = class extends AbstractSandbox {
1349
1406
  headers["X-Namespace"] = this.config.namespace;
1350
1407
  }
1351
1408
  }
1409
+ /**
1410
+ * Extract header-derived fields from response headers
1411
+ */
1412
+ extractHeaderFields(headers) {
1413
+ return {
1414
+ cluster: headers["x-rock-gateway-target-cluster"] || this.config.cluster || "N/A",
1415
+ requestId: headers["x-request-id"] || headers["request-id"] || "N/A",
1416
+ eagleeyeTraceid: headers["eagleeye-traceid"] || "N/A"
1417
+ };
1418
+ }
1352
1419
  // Lifecycle methods
1353
1420
  async start() {
1354
1421
  logger8.info("Starting sandbox...");
@@ -1432,7 +1499,11 @@ var Sandbox = class extends AbstractSandbox {
1432
1499
  if (response.status !== "Success") {
1433
1500
  throw new Error(`Failed to get status: ${JSON.stringify(response)}`);
1434
1501
  }
1435
- return response.result;
1502
+ const result = response.result;
1503
+ result.cluster = response.headers["x-rock-gateway-target-cluster"] || this.config.cluster || "N/A";
1504
+ result.requestId = response.headers["x-request-id"] || response.headers["request-id"] || "N/A";
1505
+ result.eagleeyeTraceid = response.headers["eagleeye-traceid"] || "N/A";
1506
+ return result;
1436
1507
  }
1437
1508
  // Command execution
1438
1509
  async execute(command) {
@@ -1454,7 +1525,9 @@ var Sandbox = class extends AbstractSandbox {
1454
1525
  if (response.status !== "Success") {
1455
1526
  throw new Error(`Failed to execute command: ${JSON.stringify(response)}`);
1456
1527
  }
1457
- return response.result;
1528
+ const result = response.result;
1529
+ Object.assign(result, this.extractHeaderFields(response.headers));
1530
+ return result;
1458
1531
  } catch (e) {
1459
1532
  throw new Error(`Failed to execute command: ${e}`);
1460
1533
  }
@@ -1476,7 +1549,9 @@ var Sandbox = class extends AbstractSandbox {
1476
1549
  if (response.status !== "Success") {
1477
1550
  throw new Error(`Failed to create session: ${JSON.stringify(response)}`);
1478
1551
  }
1479
- return response.result;
1552
+ const result = response.result;
1553
+ Object.assign(result, this.extractHeaderFields(response.headers));
1554
+ return result;
1480
1555
  } catch (e) {
1481
1556
  throw new Error(`Failed to create session: ${e}`);
1482
1557
  }
@@ -1497,7 +1572,9 @@ var Sandbox = class extends AbstractSandbox {
1497
1572
  if (response.status !== "Success") {
1498
1573
  throw new Error(`Failed to close session: ${JSON.stringify(response)}`);
1499
1574
  }
1500
- return response.result ?? { sessionType: "bash" };
1575
+ const result = response.result ?? { sessionType: "bash" };
1576
+ Object.assign(result, this.extractHeaderFields(response.headers));
1577
+ return result;
1501
1578
  } catch (e) {
1502
1579
  throw new Error(`Failed to close session: ${e}`);
1503
1580
  }
@@ -1543,7 +1620,9 @@ var Sandbox = class extends AbstractSandbox {
1543
1620
  if (response.status !== "Success") {
1544
1621
  throw new Error(`Failed to execute command: ${JSON.stringify(response)}`);
1545
1622
  }
1546
- return response.result;
1623
+ const result = response.result;
1624
+ Object.assign(result, this.extractHeaderFields(response.headers));
1625
+ return result;
1547
1626
  } catch (e) {
1548
1627
  throw new Error(`Failed to run in session: ${e}`);
1549
1628
  }
@@ -1582,7 +1661,10 @@ var Sandbox = class extends AbstractSandbox {
1582
1661
  output: "Failed to submit command, nohup failed to extract PID",
1583
1662
  exitCode: 1,
1584
1663
  failureReason: "PID extraction failed",
1585
- expectString: ""
1664
+ expectString: "",
1665
+ cluster: response.cluster,
1666
+ requestId: response.requestId,
1667
+ eagleeyeTraceid: response.eagleeyeTraceid
1586
1668
  };
1587
1669
  }
1588
1670
  const success = await this.waitForProcessCompletion(pid, tmpSession, waitTimeout, waitInterval);
@@ -1591,7 +1673,10 @@ var Sandbox = class extends AbstractSandbox {
1591
1673
  output: `Command executed in nohup mode. Output file: ${tmpFile}`,
1592
1674
  exitCode: success ? 0 : 1,
1593
1675
  failureReason: success ? "" : "Process did not complete successfully",
1594
- expectString: ""
1676
+ expectString: "",
1677
+ cluster: response.cluster,
1678
+ requestId: response.requestId,
1679
+ eagleeyeTraceid: response.eagleeyeTraceid
1595
1680
  };
1596
1681
  }
1597
1682
  const readCmd = responseLimitedBytesInNohup ? `head -c ${responseLimitedBytesInNohup} ${tmpFile}` : `cat ${tmpFile}`;
@@ -1603,7 +1688,10 @@ var Sandbox = class extends AbstractSandbox {
1603
1688
  output: outputResult.output,
1604
1689
  exitCode: success ? 0 : 1,
1605
1690
  failureReason: success ? "" : "Process did not complete successfully",
1606
- expectString: ""
1691
+ expectString: "",
1692
+ cluster: outputResult.cluster,
1693
+ requestId: outputResult.requestId,
1694
+ eagleeyeTraceid: outputResult.eagleeyeTraceid
1607
1695
  };
1608
1696
  }
1609
1697
  async waitForProcessCompletion(pid, session, waitTimeout, waitInterval) {
@@ -1629,7 +1717,7 @@ var Sandbox = class extends AbstractSandbox {
1629
1717
  return false;
1630
1718
  }
1631
1719
  // File operations
1632
- async write_file(request) {
1720
+ async writeFile(request) {
1633
1721
  const url = `${this.url}/write_file`;
1634
1722
  const headers = this.buildHeaders();
1635
1723
  const data = {
@@ -1638,12 +1726,13 @@ var Sandbox = class extends AbstractSandbox {
1638
1726
  sandboxId: this.sandboxId
1639
1727
  };
1640
1728
  const response = await HttpUtils.post(url, headers, data);
1729
+ const headerFields = this.extractHeaderFields(response.headers);
1641
1730
  if (response.status !== "Success") {
1642
- return { success: false, message: `Failed to write file ${request.path}` };
1731
+ return { success: false, message: `Failed to write file ${request.path}`, ...headerFields };
1643
1732
  }
1644
- return { success: true, message: `Successfully write content to file ${request.path}` };
1733
+ return { success: true, message: `Successfully write content to file ${request.path}`, ...headerFields };
1645
1734
  }
1646
- async read_file(request) {
1735
+ async readFile(request) {
1647
1736
  const url = `${this.url}/read_file`;
1648
1737
  const headers = this.buildHeaders();
1649
1738
  const data = {
@@ -1657,7 +1746,10 @@ var Sandbox = class extends AbstractSandbox {
1657
1746
  headers,
1658
1747
  data
1659
1748
  );
1660
- return { content: response.result?.content ?? "" };
1749
+ return {
1750
+ content: response.result?.content ?? "",
1751
+ ...this.extractHeaderFields(response.headers)
1752
+ };
1661
1753
  }
1662
1754
  // Upload
1663
1755
  async upload(request) {
@@ -1669,7 +1761,7 @@ var Sandbox = class extends AbstractSandbox {
1669
1761
  try {
1670
1762
  const fs = await import('fs');
1671
1763
  if (!fs.existsSync(sourcePath)) {
1672
- return { success: false, message: `File not found: ${sourcePath}` };
1764
+ return { success: false, message: `File not found: ${sourcePath}`, cluster: "N/A", requestId: "N/A", eagleeyeTraceid: "N/A" };
1673
1765
  }
1674
1766
  const fileBuffer = fs.readFileSync(sourcePath);
1675
1767
  const fileName = sourcePath.split("/").pop() ?? "file";
@@ -1679,12 +1771,13 @@ var Sandbox = class extends AbstractSandbox {
1679
1771
  { targetPath, sandboxId: this.sandboxId ?? "" },
1680
1772
  { file: [fileName, fileBuffer, "application/octet-stream"] }
1681
1773
  );
1774
+ const headerFields = this.extractHeaderFields(response.headers);
1682
1775
  if (response.status !== "Success") {
1683
- return { success: false, message: "Upload failed" };
1776
+ return { success: false, message: "Upload failed", ...headerFields };
1684
1777
  }
1685
- return { success: true, message: `Successfully uploaded file ${fileName} to ${targetPath}` };
1778
+ return { success: true, message: `Successfully uploaded file ${fileName} to ${targetPath}`, ...headerFields };
1686
1779
  } catch (e) {
1687
- return { success: false, message: `Upload failed: ${e}` };
1780
+ return { success: false, message: `Upload failed: ${e}`, cluster: "N/A", requestId: "N/A", eagleeyeTraceid: "N/A" };
1688
1781
  }
1689
1782
  }
1690
1783
  // Close
@@ -2011,6 +2104,7 @@ exports.EnvHubClient = EnvHubClient;
2011
2104
  exports.EnvHubClientConfigSchema = EnvHubClientConfigSchema;
2012
2105
  exports.EnvHubError = EnvHubError;
2013
2106
  exports.ExecuteBashSessionResponseSchema = ExecuteBashSessionResponseSchema;
2107
+ exports.HeaderFieldsSchema = HeaderFieldsSchema;
2014
2108
  exports.HttpUtils = HttpUtils;
2015
2109
  exports.InternalServerRockError = InternalServerRockError;
2016
2110
  exports.InvalidParameterRockException = InvalidParameterRockException;