rl-rock 1.2.3 → 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.js CHANGED
@@ -94,21 +94,14 @@ 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
- };
102
97
  var SandboxResponseSchema = zod.z.object({
103
98
  code: zod.z.nativeEnum(Codes).optional(),
104
99
  exitCode: zod.z.number().optional(),
105
- failureReason: zod.z.string().optional(),
106
- ...HeaderFieldsSchema
100
+ failureReason: zod.z.string().optional()
107
101
  });
108
102
  var IsAliveResponseSchema = zod.z.object({
109
103
  isAlive: zod.z.boolean(),
110
- message: zod.z.string().default(""),
111
- ...HeaderFieldsSchema
104
+ message: zod.z.string().default("")
112
105
  });
113
106
  var SandboxStatusResponseSchema = zod.z.object({
114
107
  sandboxId: zod.z.string().optional(),
@@ -126,67 +119,57 @@ var SandboxStatusResponseSchema = zod.z.object({
126
119
  cpus: zod.z.number().optional(),
127
120
  memory: zod.z.string().optional(),
128
121
  state: zod.z.unknown().optional(),
129
- ...HeaderFieldsSchema
122
+ // Response headers info
123
+ cluster: zod.z.string().optional(),
124
+ requestId: zod.z.string().optional(),
125
+ eagleeyeTraceid: zod.z.string().optional()
130
126
  });
131
127
  var CommandResponseSchema = zod.z.object({
132
128
  stdout: zod.z.string().default(""),
133
129
  stderr: zod.z.string().default(""),
134
- exitCode: zod.z.number().optional(),
135
- ...HeaderFieldsSchema
130
+ exitCode: zod.z.number().optional()
136
131
  });
137
132
  var WriteFileResponseSchema = zod.z.object({
138
133
  success: zod.z.boolean().default(false),
139
- message: zod.z.string().default(""),
140
- ...HeaderFieldsSchema
134
+ message: zod.z.string().default("")
141
135
  });
142
136
  var ReadFileResponseSchema = zod.z.object({
143
- content: zod.z.string().default(""),
144
- ...HeaderFieldsSchema
137
+ content: zod.z.string().default("")
145
138
  });
146
139
  var UploadResponseSchema = zod.z.object({
147
140
  success: zod.z.boolean().default(false),
148
141
  message: zod.z.string().default(""),
149
- fileName: zod.z.string().optional(),
150
- ...HeaderFieldsSchema
142
+ fileName: zod.z.string().optional()
151
143
  });
152
144
  var ObservationSchema = zod.z.object({
153
145
  output: zod.z.string().default(""),
154
146
  exitCode: zod.z.number().optional(),
155
147
  failureReason: zod.z.string().default(""),
156
- expectString: zod.z.string().default(""),
157
- ...HeaderFieldsSchema
148
+ expectString: zod.z.string().default("")
158
149
  });
159
150
  var CreateSessionResponseSchema = zod.z.object({
160
151
  output: zod.z.string().default(""),
161
- sessionType: zod.z.literal("bash").default("bash"),
162
- ...HeaderFieldsSchema
152
+ sessionType: zod.z.literal("bash").default("bash")
163
153
  });
164
154
  var CloseSessionResponseSchema = zod.z.object({
165
- sessionType: zod.z.literal("bash").default("bash"),
166
- ...HeaderFieldsSchema
167
- });
168
- var CloseResponseSchema = zod.z.object({
169
- ...HeaderFieldsSchema
155
+ sessionType: zod.z.literal("bash").default("bash")
170
156
  });
157
+ var CloseResponseSchema = zod.z.object({});
171
158
  var ChownResponseSchema = zod.z.object({
172
159
  success: zod.z.boolean().default(false),
173
- message: zod.z.string().default(""),
174
- ...HeaderFieldsSchema
160
+ message: zod.z.string().default("")
175
161
  });
176
162
  var ChmodResponseSchema = zod.z.object({
177
163
  success: zod.z.boolean().default(false),
178
- message: zod.z.string().default(""),
179
- ...HeaderFieldsSchema
164
+ message: zod.z.string().default("")
180
165
  });
181
166
  var ExecuteBashSessionResponseSchema = zod.z.object({
182
167
  success: zod.z.boolean().default(false),
183
- message: zod.z.string().default(""),
184
- ...HeaderFieldsSchema
168
+ message: zod.z.string().default("")
185
169
  });
186
170
  var OssSetupResponseSchema = zod.z.object({
187
171
  success: zod.z.boolean().default(false),
188
- message: zod.z.string().default(""),
189
- ...HeaderFieldsSchema
172
+ message: zod.z.string().default("")
190
173
  });
191
174
 
192
175
  // src/common/constants.ts
@@ -302,7 +285,6 @@ var HttpUtils = class {
302
285
  * Send POST request
303
286
  * Automatically converts request body from camelCase to snake_case
304
287
  * Automatically converts response from snake_case to camelCase
305
- * Returns structured response with headers
306
288
  */
307
289
  static async post(url, headers, data, readTimeout) {
308
290
  const client = this.createClient({
@@ -312,18 +294,18 @@ var HttpUtils = class {
312
294
  const snakeData = objectToSnake(data);
313
295
  try {
314
296
  const response = await client.post(url, snakeData);
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
297
+ const camelData = objectToCamel(response.data);
298
+ const httpResponse = {
299
+ status: camelData.status ?? "Success",
300
+ headers: this.extractHeaders(response)
326
301
  };
302
+ if (camelData.result !== void 0) {
303
+ httpResponse.result = camelData.result;
304
+ }
305
+ if (camelData.error !== void 0) {
306
+ httpResponse.error = camelData.error;
307
+ }
308
+ return httpResponse;
327
309
  } catch (error) {
328
310
  if (error instanceof axios3.AxiosError) {
329
311
  throw new Error(`Failed to POST ${url}: ${error.message}`);
@@ -334,24 +316,23 @@ var HttpUtils = class {
334
316
  /**
335
317
  * Send GET request
336
318
  * Automatically converts response from snake_case to camelCase
337
- * Returns structured response with headers
338
319
  */
339
320
  static async get(url, headers) {
340
321
  const client = this.createClient({ headers });
341
322
  try {
342
323
  const response = await client.get(url);
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
324
+ const camelData = objectToCamel(response.data);
325
+ const httpResponse = {
326
+ status: camelData.status ?? "Success",
327
+ headers: this.extractHeaders(response)
354
328
  };
329
+ if (camelData.result !== void 0) {
330
+ httpResponse.result = camelData.result;
331
+ }
332
+ if (camelData.error !== void 0) {
333
+ httpResponse.error = camelData.error;
334
+ }
335
+ return httpResponse;
355
336
  } catch (error) {
356
337
  if (error instanceof axios3.AxiosError) {
357
338
  throw new Error(`Failed to GET ${url}: ${error.message}`);
@@ -359,6 +340,20 @@ var HttpUtils = class {
359
340
  throw error;
360
341
  }
361
342
  }
343
+ /**
344
+ * Extract headers from axios response
345
+ */
346
+ static extractHeaders(response) {
347
+ const headers = {};
348
+ for (const [key, value] of Object.entries(response.headers)) {
349
+ if (typeof value === "string") {
350
+ headers[key.toLowerCase()] = value;
351
+ } else if (Array.isArray(value)) {
352
+ headers[key.toLowerCase()] = value.join(", ");
353
+ }
354
+ }
355
+ return headers;
356
+ }
362
357
  /**
363
358
  * Convert camelCase key to snake_case
364
359
  */
@@ -369,7 +364,6 @@ var HttpUtils = class {
369
364
  * Send multipart/form-data request
370
365
  * Automatically converts form data keys to snake_case
371
366
  * Automatically converts response from snake_case to camelCase
372
- * Returns structured response with headers
373
367
  */
374
368
  static async postMultipart(url, headers, data, files) {
375
369
  const formData = new FormData();
@@ -406,18 +400,18 @@ var HttpUtils = class {
406
400
  });
407
401
  try {
408
402
  const response = await client.post(url, formData);
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
403
+ const camelData = objectToCamel(response.data);
404
+ const httpResponse = {
405
+ status: camelData.status ?? "Success",
406
+ headers: this.extractHeaders(response)
420
407
  };
408
+ if (camelData.result !== void 0) {
409
+ httpResponse.result = camelData.result;
410
+ }
411
+ if (camelData.error !== void 0) {
412
+ httpResponse.error = camelData.error;
413
+ }
414
+ return httpResponse;
421
415
  } catch (error) {
422
416
  if (error instanceof axios3.AxiosError) {
423
417
  throw new Error(`Failed to POST multipart ${url}: ${error.message}`);
@@ -698,7 +692,7 @@ var EnvHubClient = class {
698
692
  url,
699
693
  this.headers
700
694
  );
701
- return response.result;
695
+ return response.result ?? {};
702
696
  } catch (e) {
703
697
  throw new EnvHubError(`Failed to health check: ${e}`);
704
698
  }
@@ -1406,16 +1400,6 @@ var Sandbox = class extends AbstractSandbox {
1406
1400
  headers["X-Namespace"] = this.config.namespace;
1407
1401
  }
1408
1402
  }
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
- }
1419
1403
  // Lifecycle methods
1420
1404
  async start() {
1421
1405
  logger8.info("Starting sandbox...");
@@ -1497,7 +1481,8 @@ var Sandbox = class extends AbstractSandbox {
1497
1481
  const headers = this.buildHeaders();
1498
1482
  const response = await HttpUtils.get(url, headers);
1499
1483
  if (response.status !== "Success") {
1500
- throw new Error(`Failed to get status: ${JSON.stringify(response)}`);
1484
+ const errorDetail = response.error ? `, error=${response.error}` : "";
1485
+ throw new Error(`Failed to get status: status=${response.status}${errorDetail}, result=${JSON.stringify(response.result)}`);
1501
1486
  }
1502
1487
  const result = response.result;
1503
1488
  result.cluster = response.headers["x-rock-gateway-target-cluster"] || this.config.cluster || "N/A";
@@ -1523,11 +1508,10 @@ var Sandbox = class extends AbstractSandbox {
1523
1508
  data
1524
1509
  );
1525
1510
  if (response.status !== "Success") {
1526
- throw new Error(`Failed to execute command: ${JSON.stringify(response)}`);
1511
+ const errorDetail = response.error ? `, error=${response.error}` : "";
1512
+ throw new Error(`Failed to execute command: status=${response.status}${errorDetail}, result=${JSON.stringify(response.result)}`);
1527
1513
  }
1528
- const result = response.result;
1529
- Object.assign(result, this.extractHeaderFields(response.headers));
1530
- return result;
1514
+ return response.result;
1531
1515
  } catch (e) {
1532
1516
  throw new Error(`Failed to execute command: ${e}`);
1533
1517
  }
@@ -1547,11 +1531,10 @@ var Sandbox = class extends AbstractSandbox {
1547
1531
  data
1548
1532
  );
1549
1533
  if (response.status !== "Success") {
1550
- throw new Error(`Failed to create session: ${JSON.stringify(response)}`);
1534
+ const errorDetail = response.error ? `, error=${response.error}` : "";
1535
+ throw new Error(`Failed to create session: status=${response.status}${errorDetail}, result=${JSON.stringify(response.result)}`);
1551
1536
  }
1552
- const result = response.result;
1553
- Object.assign(result, this.extractHeaderFields(response.headers));
1554
- return result;
1537
+ return response.result;
1555
1538
  } catch (e) {
1556
1539
  throw new Error(`Failed to create session: ${e}`);
1557
1540
  }
@@ -1570,11 +1553,10 @@ var Sandbox = class extends AbstractSandbox {
1570
1553
  data
1571
1554
  );
1572
1555
  if (response.status !== "Success") {
1573
- throw new Error(`Failed to close session: ${JSON.stringify(response)}`);
1556
+ const errorDetail = response.error ? `, error=${response.error}` : "";
1557
+ throw new Error(`Failed to close session: status=${response.status}${errorDetail}, result=${JSON.stringify(response.result)}`);
1574
1558
  }
1575
- const result = response.result ?? { sessionType: "bash" };
1576
- Object.assign(result, this.extractHeaderFields(response.headers));
1577
- return result;
1559
+ return response.result ?? { sessionType: "bash" };
1578
1560
  } catch (e) {
1579
1561
  throw new Error(`Failed to close session: ${e}`);
1580
1562
  }
@@ -1618,11 +1600,10 @@ var Sandbox = class extends AbstractSandbox {
1618
1600
  timeoutMs
1619
1601
  );
1620
1602
  if (response.status !== "Success") {
1621
- throw new Error(`Failed to execute command: ${JSON.stringify(response)}`);
1603
+ const errorDetail = response.error ? `, error=${response.error}` : "";
1604
+ throw new Error(`Failed to run in session: status=${response.status}${errorDetail}, result=${JSON.stringify(response.result)}`);
1622
1605
  }
1623
- const result = response.result;
1624
- Object.assign(result, this.extractHeaderFields(response.headers));
1625
- return result;
1606
+ return response.result;
1626
1607
  } catch (e) {
1627
1608
  throw new Error(`Failed to run in session: ${e}`);
1628
1609
  }
@@ -1661,10 +1642,7 @@ var Sandbox = class extends AbstractSandbox {
1661
1642
  output: "Failed to submit command, nohup failed to extract PID",
1662
1643
  exitCode: 1,
1663
1644
  failureReason: "PID extraction failed",
1664
- expectString: "",
1665
- cluster: response.cluster,
1666
- requestId: response.requestId,
1667
- eagleeyeTraceid: response.eagleeyeTraceid
1645
+ expectString: ""
1668
1646
  };
1669
1647
  }
1670
1648
  const success = await this.waitForProcessCompletion(pid, tmpSession, waitTimeout, waitInterval);
@@ -1673,10 +1651,7 @@ var Sandbox = class extends AbstractSandbox {
1673
1651
  output: `Command executed in nohup mode. Output file: ${tmpFile}`,
1674
1652
  exitCode: success ? 0 : 1,
1675
1653
  failureReason: success ? "" : "Process did not complete successfully",
1676
- expectString: "",
1677
- cluster: response.cluster,
1678
- requestId: response.requestId,
1679
- eagleeyeTraceid: response.eagleeyeTraceid
1654
+ expectString: ""
1680
1655
  };
1681
1656
  }
1682
1657
  const readCmd = responseLimitedBytesInNohup ? `head -c ${responseLimitedBytesInNohup} ${tmpFile}` : `cat ${tmpFile}`;
@@ -1688,10 +1663,7 @@ var Sandbox = class extends AbstractSandbox {
1688
1663
  output: outputResult.output,
1689
1664
  exitCode: success ? 0 : 1,
1690
1665
  failureReason: success ? "" : "Process did not complete successfully",
1691
- expectString: "",
1692
- cluster: outputResult.cluster,
1693
- requestId: outputResult.requestId,
1694
- eagleeyeTraceid: outputResult.eagleeyeTraceid
1666
+ expectString: ""
1695
1667
  };
1696
1668
  }
1697
1669
  async waitForProcessCompletion(pid, session, waitTimeout, waitInterval) {
@@ -1726,11 +1698,10 @@ var Sandbox = class extends AbstractSandbox {
1726
1698
  sandboxId: this.sandboxId
1727
1699
  };
1728
1700
  const response = await HttpUtils.post(url, headers, data);
1729
- const headerFields = this.extractHeaderFields(response.headers);
1730
1701
  if (response.status !== "Success") {
1731
- return { success: false, message: `Failed to write file ${request.path}`, ...headerFields };
1702
+ return { success: false, message: `Failed to write file ${request.path}` };
1732
1703
  }
1733
- return { success: true, message: `Successfully write content to file ${request.path}`, ...headerFields };
1704
+ return { success: true, message: `Successfully write content to file ${request.path}` };
1734
1705
  }
1735
1706
  async readFile(request) {
1736
1707
  const url = `${this.url}/read_file`;
@@ -1746,10 +1717,7 @@ var Sandbox = class extends AbstractSandbox {
1746
1717
  headers,
1747
1718
  data
1748
1719
  );
1749
- return {
1750
- content: response.result?.content ?? "",
1751
- ...this.extractHeaderFields(response.headers)
1752
- };
1720
+ return { content: response.result?.content ?? "" };
1753
1721
  }
1754
1722
  // Upload
1755
1723
  async upload(request) {
@@ -1761,7 +1729,7 @@ var Sandbox = class extends AbstractSandbox {
1761
1729
  try {
1762
1730
  const fs = await import('fs');
1763
1731
  if (!fs.existsSync(sourcePath)) {
1764
- return { success: false, message: `File not found: ${sourcePath}`, cluster: "N/A", requestId: "N/A", eagleeyeTraceid: "N/A" };
1732
+ return { success: false, message: `File not found: ${sourcePath}` };
1765
1733
  }
1766
1734
  const fileBuffer = fs.readFileSync(sourcePath);
1767
1735
  const fileName = sourcePath.split("/").pop() ?? "file";
@@ -1771,13 +1739,12 @@ var Sandbox = class extends AbstractSandbox {
1771
1739
  { targetPath, sandboxId: this.sandboxId ?? "" },
1772
1740
  { file: [fileName, fileBuffer, "application/octet-stream"] }
1773
1741
  );
1774
- const headerFields = this.extractHeaderFields(response.headers);
1775
1742
  if (response.status !== "Success") {
1776
- return { success: false, message: "Upload failed", ...headerFields };
1743
+ return { success: false, message: "Upload failed" };
1777
1744
  }
1778
- return { success: true, message: `Successfully uploaded file ${fileName} to ${targetPath}`, ...headerFields };
1745
+ return { success: true, message: `Successfully uploaded file ${fileName} to ${targetPath}` };
1779
1746
  } catch (e) {
1780
- return { success: false, message: `Upload failed: ${e}`, cluster: "N/A", requestId: "N/A", eagleeyeTraceid: "N/A" };
1747
+ return { success: false, message: `Upload failed: ${e}` };
1781
1748
  }
1782
1749
  }
1783
1750
  // Close
@@ -2104,7 +2071,6 @@ exports.EnvHubClient = EnvHubClient;
2104
2071
  exports.EnvHubClientConfigSchema = EnvHubClientConfigSchema;
2105
2072
  exports.EnvHubError = EnvHubError;
2106
2073
  exports.ExecuteBashSessionResponseSchema = ExecuteBashSessionResponseSchema;
2107
- exports.HeaderFieldsSchema = HeaderFieldsSchema;
2108
2074
  exports.HttpUtils = HttpUtils;
2109
2075
  exports.InternalServerRockError = InternalServerRockError;
2110
2076
  exports.InvalidParameterRockException = InvalidParameterRockException;