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.mjs CHANGED
@@ -86,21 +86,14 @@ var ChmodRequestSchema = z.object({
86
86
  mode: z.string().default("755"),
87
87
  recursive: z.boolean().default(false)
88
88
  });
89
- var HeaderFieldsSchema = {
90
- cluster: z.string().optional(),
91
- requestId: z.string().optional(),
92
- eagleeyeTraceid: z.string().optional()
93
- };
94
89
  var SandboxResponseSchema = z.object({
95
90
  code: z.nativeEnum(Codes).optional(),
96
91
  exitCode: z.number().optional(),
97
- failureReason: z.string().optional(),
98
- ...HeaderFieldsSchema
92
+ failureReason: z.string().optional()
99
93
  });
100
94
  var IsAliveResponseSchema = z.object({
101
95
  isAlive: z.boolean(),
102
- message: z.string().default(""),
103
- ...HeaderFieldsSchema
96
+ message: z.string().default("")
104
97
  });
105
98
  var SandboxStatusResponseSchema = z.object({
106
99
  sandboxId: z.string().optional(),
@@ -118,67 +111,57 @@ var SandboxStatusResponseSchema = z.object({
118
111
  cpus: z.number().optional(),
119
112
  memory: z.string().optional(),
120
113
  state: z.unknown().optional(),
121
- ...HeaderFieldsSchema
114
+ // Response headers info
115
+ cluster: z.string().optional(),
116
+ requestId: z.string().optional(),
117
+ eagleeyeTraceid: z.string().optional()
122
118
  });
123
119
  var CommandResponseSchema = z.object({
124
120
  stdout: z.string().default(""),
125
121
  stderr: z.string().default(""),
126
- exitCode: z.number().optional(),
127
- ...HeaderFieldsSchema
122
+ exitCode: z.number().optional()
128
123
  });
129
124
  var WriteFileResponseSchema = z.object({
130
125
  success: z.boolean().default(false),
131
- message: z.string().default(""),
132
- ...HeaderFieldsSchema
126
+ message: z.string().default("")
133
127
  });
134
128
  var ReadFileResponseSchema = z.object({
135
- content: z.string().default(""),
136
- ...HeaderFieldsSchema
129
+ content: z.string().default("")
137
130
  });
138
131
  var UploadResponseSchema = z.object({
139
132
  success: z.boolean().default(false),
140
133
  message: z.string().default(""),
141
- fileName: z.string().optional(),
142
- ...HeaderFieldsSchema
134
+ fileName: z.string().optional()
143
135
  });
144
136
  var ObservationSchema = z.object({
145
137
  output: z.string().default(""),
146
138
  exitCode: z.number().optional(),
147
139
  failureReason: z.string().default(""),
148
- expectString: z.string().default(""),
149
- ...HeaderFieldsSchema
140
+ expectString: z.string().default("")
150
141
  });
151
142
  var CreateSessionResponseSchema = z.object({
152
143
  output: z.string().default(""),
153
- sessionType: z.literal("bash").default("bash"),
154
- ...HeaderFieldsSchema
144
+ sessionType: z.literal("bash").default("bash")
155
145
  });
156
146
  var CloseSessionResponseSchema = z.object({
157
- sessionType: z.literal("bash").default("bash"),
158
- ...HeaderFieldsSchema
159
- });
160
- var CloseResponseSchema = z.object({
161
- ...HeaderFieldsSchema
147
+ sessionType: z.literal("bash").default("bash")
162
148
  });
149
+ var CloseResponseSchema = z.object({});
163
150
  var ChownResponseSchema = z.object({
164
151
  success: z.boolean().default(false),
165
- message: z.string().default(""),
166
- ...HeaderFieldsSchema
152
+ message: z.string().default("")
167
153
  });
168
154
  var ChmodResponseSchema = z.object({
169
155
  success: z.boolean().default(false),
170
- message: z.string().default(""),
171
- ...HeaderFieldsSchema
156
+ message: z.string().default("")
172
157
  });
173
158
  var ExecuteBashSessionResponseSchema = z.object({
174
159
  success: z.boolean().default(false),
175
- message: z.string().default(""),
176
- ...HeaderFieldsSchema
160
+ message: z.string().default("")
177
161
  });
178
162
  var OssSetupResponseSchema = z.object({
179
163
  success: z.boolean().default(false),
180
- message: z.string().default(""),
181
- ...HeaderFieldsSchema
164
+ message: z.string().default("")
182
165
  });
183
166
 
184
167
  // src/common/constants.ts
@@ -294,7 +277,6 @@ var HttpUtils = class {
294
277
  * Send POST request
295
278
  * Automatically converts request body from camelCase to snake_case
296
279
  * Automatically converts response from snake_case to camelCase
297
- * Returns structured response with headers
298
280
  */
299
281
  static async post(url, headers, data, readTimeout) {
300
282
  const client = this.createClient({
@@ -304,18 +286,18 @@ var HttpUtils = class {
304
286
  const snakeData = objectToSnake(data);
305
287
  try {
306
288
  const response = await client.post(url, snakeData);
307
- const result = objectToCamel(response.data);
308
- const responseHeaders = {};
309
- for (const [key, value] of Object.entries(response.headers)) {
310
- if (typeof value === "string") {
311
- responseHeaders[key.toLowerCase()] = value;
312
- }
313
- }
314
- return {
315
- status: result?.status ?? "Success",
316
- result,
317
- headers: responseHeaders
289
+ const camelData = objectToCamel(response.data);
290
+ const httpResponse = {
291
+ status: camelData.status ?? "Success",
292
+ headers: this.extractHeaders(response)
318
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;
319
301
  } catch (error) {
320
302
  if (error instanceof AxiosError) {
321
303
  throw new Error(`Failed to POST ${url}: ${error.message}`);
@@ -326,24 +308,23 @@ var HttpUtils = class {
326
308
  /**
327
309
  * Send GET request
328
310
  * Automatically converts response from snake_case to camelCase
329
- * Returns structured response with headers
330
311
  */
331
312
  static async get(url, headers) {
332
313
  const client = this.createClient({ headers });
333
314
  try {
334
315
  const response = await client.get(url);
335
- const result = objectToCamel(response.data);
336
- const responseHeaders = {};
337
- for (const [key, value] of Object.entries(response.headers)) {
338
- if (typeof value === "string") {
339
- responseHeaders[key.toLowerCase()] = value;
340
- }
341
- }
342
- return {
343
- status: result?.status ?? "Success",
344
- result,
345
- headers: responseHeaders
316
+ const camelData = objectToCamel(response.data);
317
+ const httpResponse = {
318
+ status: camelData.status ?? "Success",
319
+ headers: this.extractHeaders(response)
346
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;
347
328
  } catch (error) {
348
329
  if (error instanceof AxiosError) {
349
330
  throw new Error(`Failed to GET ${url}: ${error.message}`);
@@ -351,6 +332,20 @@ var HttpUtils = class {
351
332
  throw error;
352
333
  }
353
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
+ }
354
349
  /**
355
350
  * Convert camelCase key to snake_case
356
351
  */
@@ -361,7 +356,6 @@ var HttpUtils = class {
361
356
  * Send multipart/form-data request
362
357
  * Automatically converts form data keys to snake_case
363
358
  * Automatically converts response from snake_case to camelCase
364
- * Returns structured response with headers
365
359
  */
366
360
  static async postMultipart(url, headers, data, files) {
367
361
  const formData = new FormData();
@@ -398,18 +392,18 @@ var HttpUtils = class {
398
392
  });
399
393
  try {
400
394
  const response = await client.post(url, formData);
401
- const result = objectToCamel(response.data);
402
- const responseHeaders = {};
403
- for (const [key, value] of Object.entries(response.headers)) {
404
- if (typeof value === "string") {
405
- responseHeaders[key.toLowerCase()] = value;
406
- }
407
- }
408
- return {
409
- status: result?.status ?? "Success",
410
- result,
411
- headers: responseHeaders
395
+ const camelData = objectToCamel(response.data);
396
+ const httpResponse = {
397
+ status: camelData.status ?? "Success",
398
+ headers: this.extractHeaders(response)
412
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;
413
407
  } catch (error) {
414
408
  if (error instanceof AxiosError) {
415
409
  throw new Error(`Failed to POST multipart ${url}: ${error.message}`);
@@ -690,7 +684,7 @@ var EnvHubClient = class {
690
684
  url,
691
685
  this.headers
692
686
  );
693
- return response.result;
687
+ return response.result ?? {};
694
688
  } catch (e) {
695
689
  throw new EnvHubError(`Failed to health check: ${e}`);
696
690
  }
@@ -1398,16 +1392,6 @@ var Sandbox = class extends AbstractSandbox {
1398
1392
  headers["X-Namespace"] = this.config.namespace;
1399
1393
  }
1400
1394
  }
1401
- /**
1402
- * Extract header-derived fields from response headers
1403
- */
1404
- extractHeaderFields(headers) {
1405
- return {
1406
- cluster: headers["x-rock-gateway-target-cluster"] || this.config.cluster || "N/A",
1407
- requestId: headers["x-request-id"] || headers["request-id"] || "N/A",
1408
- eagleeyeTraceid: headers["eagleeye-traceid"] || "N/A"
1409
- };
1410
- }
1411
1395
  // Lifecycle methods
1412
1396
  async start() {
1413
1397
  logger8.info("Starting sandbox...");
@@ -1489,7 +1473,8 @@ var Sandbox = class extends AbstractSandbox {
1489
1473
  const headers = this.buildHeaders();
1490
1474
  const response = await HttpUtils.get(url, headers);
1491
1475
  if (response.status !== "Success") {
1492
- throw new Error(`Failed to get status: ${JSON.stringify(response)}`);
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)}`);
1493
1478
  }
1494
1479
  const result = response.result;
1495
1480
  result.cluster = response.headers["x-rock-gateway-target-cluster"] || this.config.cluster || "N/A";
@@ -1515,11 +1500,10 @@ var Sandbox = class extends AbstractSandbox {
1515
1500
  data
1516
1501
  );
1517
1502
  if (response.status !== "Success") {
1518
- throw new Error(`Failed to execute command: ${JSON.stringify(response)}`);
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)}`);
1519
1505
  }
1520
- const result = response.result;
1521
- Object.assign(result, this.extractHeaderFields(response.headers));
1522
- return result;
1506
+ return response.result;
1523
1507
  } catch (e) {
1524
1508
  throw new Error(`Failed to execute command: ${e}`);
1525
1509
  }
@@ -1539,11 +1523,10 @@ var Sandbox = class extends AbstractSandbox {
1539
1523
  data
1540
1524
  );
1541
1525
  if (response.status !== "Success") {
1542
- throw new Error(`Failed to create session: ${JSON.stringify(response)}`);
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)}`);
1543
1528
  }
1544
- const result = response.result;
1545
- Object.assign(result, this.extractHeaderFields(response.headers));
1546
- return result;
1529
+ return response.result;
1547
1530
  } catch (e) {
1548
1531
  throw new Error(`Failed to create session: ${e}`);
1549
1532
  }
@@ -1562,11 +1545,10 @@ var Sandbox = class extends AbstractSandbox {
1562
1545
  data
1563
1546
  );
1564
1547
  if (response.status !== "Success") {
1565
- throw new Error(`Failed to close session: ${JSON.stringify(response)}`);
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)}`);
1566
1550
  }
1567
- const result = response.result ?? { sessionType: "bash" };
1568
- Object.assign(result, this.extractHeaderFields(response.headers));
1569
- return result;
1551
+ return response.result ?? { sessionType: "bash" };
1570
1552
  } catch (e) {
1571
1553
  throw new Error(`Failed to close session: ${e}`);
1572
1554
  }
@@ -1610,11 +1592,10 @@ var Sandbox = class extends AbstractSandbox {
1610
1592
  timeoutMs
1611
1593
  );
1612
1594
  if (response.status !== "Success") {
1613
- throw new Error(`Failed to execute command: ${JSON.stringify(response)}`);
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)}`);
1614
1597
  }
1615
- const result = response.result;
1616
- Object.assign(result, this.extractHeaderFields(response.headers));
1617
- return result;
1598
+ return response.result;
1618
1599
  } catch (e) {
1619
1600
  throw new Error(`Failed to run in session: ${e}`);
1620
1601
  }
@@ -1653,10 +1634,7 @@ var Sandbox = class extends AbstractSandbox {
1653
1634
  output: "Failed to submit command, nohup failed to extract PID",
1654
1635
  exitCode: 1,
1655
1636
  failureReason: "PID extraction failed",
1656
- expectString: "",
1657
- cluster: response.cluster,
1658
- requestId: response.requestId,
1659
- eagleeyeTraceid: response.eagleeyeTraceid
1637
+ expectString: ""
1660
1638
  };
1661
1639
  }
1662
1640
  const success = await this.waitForProcessCompletion(pid, tmpSession, waitTimeout, waitInterval);
@@ -1665,10 +1643,7 @@ var Sandbox = class extends AbstractSandbox {
1665
1643
  output: `Command executed in nohup mode. Output file: ${tmpFile}`,
1666
1644
  exitCode: success ? 0 : 1,
1667
1645
  failureReason: success ? "" : "Process did not complete successfully",
1668
- expectString: "",
1669
- cluster: response.cluster,
1670
- requestId: response.requestId,
1671
- eagleeyeTraceid: response.eagleeyeTraceid
1646
+ expectString: ""
1672
1647
  };
1673
1648
  }
1674
1649
  const readCmd = responseLimitedBytesInNohup ? `head -c ${responseLimitedBytesInNohup} ${tmpFile}` : `cat ${tmpFile}`;
@@ -1680,10 +1655,7 @@ var Sandbox = class extends AbstractSandbox {
1680
1655
  output: outputResult.output,
1681
1656
  exitCode: success ? 0 : 1,
1682
1657
  failureReason: success ? "" : "Process did not complete successfully",
1683
- expectString: "",
1684
- cluster: outputResult.cluster,
1685
- requestId: outputResult.requestId,
1686
- eagleeyeTraceid: outputResult.eagleeyeTraceid
1658
+ expectString: ""
1687
1659
  };
1688
1660
  }
1689
1661
  async waitForProcessCompletion(pid, session, waitTimeout, waitInterval) {
@@ -1718,11 +1690,10 @@ var Sandbox = class extends AbstractSandbox {
1718
1690
  sandboxId: this.sandboxId
1719
1691
  };
1720
1692
  const response = await HttpUtils.post(url, headers, data);
1721
- const headerFields = this.extractHeaderFields(response.headers);
1722
1693
  if (response.status !== "Success") {
1723
- return { success: false, message: `Failed to write file ${request.path}`, ...headerFields };
1694
+ return { success: false, message: `Failed to write file ${request.path}` };
1724
1695
  }
1725
- return { success: true, message: `Successfully write content to file ${request.path}`, ...headerFields };
1696
+ return { success: true, message: `Successfully write content to file ${request.path}` };
1726
1697
  }
1727
1698
  async readFile(request) {
1728
1699
  const url = `${this.url}/read_file`;
@@ -1738,10 +1709,7 @@ var Sandbox = class extends AbstractSandbox {
1738
1709
  headers,
1739
1710
  data
1740
1711
  );
1741
- return {
1742
- content: response.result?.content ?? "",
1743
- ...this.extractHeaderFields(response.headers)
1744
- };
1712
+ return { content: response.result?.content ?? "" };
1745
1713
  }
1746
1714
  // Upload
1747
1715
  async upload(request) {
@@ -1753,7 +1721,7 @@ var Sandbox = class extends AbstractSandbox {
1753
1721
  try {
1754
1722
  const fs = await import('fs');
1755
1723
  if (!fs.existsSync(sourcePath)) {
1756
- return { success: false, message: `File not found: ${sourcePath}`, cluster: "N/A", requestId: "N/A", eagleeyeTraceid: "N/A" };
1724
+ return { success: false, message: `File not found: ${sourcePath}` };
1757
1725
  }
1758
1726
  const fileBuffer = fs.readFileSync(sourcePath);
1759
1727
  const fileName = sourcePath.split("/").pop() ?? "file";
@@ -1763,13 +1731,12 @@ var Sandbox = class extends AbstractSandbox {
1763
1731
  { targetPath, sandboxId: this.sandboxId ?? "" },
1764
1732
  { file: [fileName, fileBuffer, "application/octet-stream"] }
1765
1733
  );
1766
- const headerFields = this.extractHeaderFields(response.headers);
1767
1734
  if (response.status !== "Success") {
1768
- return { success: false, message: "Upload failed", ...headerFields };
1735
+ return { success: false, message: "Upload failed" };
1769
1736
  }
1770
- return { success: true, message: `Successfully uploaded file ${fileName} to ${targetPath}`, ...headerFields };
1737
+ return { success: true, message: `Successfully uploaded file ${fileName} to ${targetPath}` };
1771
1738
  } catch (e) {
1772
- return { success: false, message: `Upload failed: ${e}`, cluster: "N/A", requestId: "N/A", eagleeyeTraceid: "N/A" };
1739
+ return { success: false, message: `Upload failed: ${e}` };
1773
1740
  }
1774
1741
  }
1775
1742
  // Close
@@ -2075,6 +2042,6 @@ var ModelService = class {
2075
2042
  // src/index.ts
2076
2043
  var VERSION = "1.2.1";
2077
2044
 
2078
- export { BadRequestRockError, BashActionSchema, ChmodRequestSchema, ChmodResponseSchema, ChownRequestSchema, ChownResponseSchema, CloseResponseSchema, CloseSessionRequestSchema, CloseSessionResponseSchema, Codes, CommandResponseSchema, CommandRockError, CommandSchema, Constants, CreateBashSessionRequestSchema, CreateSessionResponseSchema, Deploy, EnvHubClient, EnvHubClientConfigSchema, EnvHubError, ExecuteBashSessionResponseSchema, HeaderFieldsSchema, HttpUtils, InternalServerRockError, InvalidParameterRockException, IsAliveResponseSchema, LinuxFileSystem, LinuxRemoteUser, ModelClient, ModelService, Network, ObservationSchema, OssSetupResponseSchema, PID_PREFIX, PID_SUFFIX, Process, ReadFileRequestSchema, ReadFileResponseSchema, ReasonPhrases, RockEnv, RockEnvInfoSchema, RockException, RunMode, Sandbox, SandboxConfigSchema, SandboxGroup, SandboxGroupConfigSchema, SandboxResponseSchema, SandboxStatusResponseSchema, SpeedupType, UploadRequestSchema, UploadResponseSchema, VERSION, WriteFileRequestSchema, WriteFileResponseSchema, arunWithRetry, createRockEnvInfo, createSandboxConfig, createSandboxGroupConfig, deprecated, deprecatedClass, extractNohupPid as extractNohupPidFromSandbox, fromRockException, getEnv, getReasonPhrase, getRequiredEnv, isBrowser, isClientError, isCommandError, isEnvSet, isError, isNode, isServerError, isSuccess, make, raiseForCode, retryAsync, sleep, withRetry, withTimeLogging };
2045
+ export { BadRequestRockError, BashActionSchema, ChmodRequestSchema, ChmodResponseSchema, ChownRequestSchema, ChownResponseSchema, CloseResponseSchema, CloseSessionRequestSchema, CloseSessionResponseSchema, Codes, CommandResponseSchema, CommandRockError, CommandSchema, Constants, CreateBashSessionRequestSchema, CreateSessionResponseSchema, Deploy, EnvHubClient, EnvHubClientConfigSchema, EnvHubError, ExecuteBashSessionResponseSchema, HttpUtils, InternalServerRockError, InvalidParameterRockException, IsAliveResponseSchema, LinuxFileSystem, LinuxRemoteUser, ModelClient, ModelService, Network, ObservationSchema, OssSetupResponseSchema, PID_PREFIX, PID_SUFFIX, Process, ReadFileRequestSchema, ReadFileResponseSchema, ReasonPhrases, RockEnv, RockEnvInfoSchema, RockException, RunMode, Sandbox, SandboxConfigSchema, SandboxGroup, SandboxGroupConfigSchema, SandboxResponseSchema, SandboxStatusResponseSchema, SpeedupType, UploadRequestSchema, UploadResponseSchema, VERSION, WriteFileRequestSchema, WriteFileResponseSchema, arunWithRetry, createRockEnvInfo, createSandboxConfig, createSandboxGroupConfig, deprecated, deprecatedClass, extractNohupPid as extractNohupPidFromSandbox, fromRockException, getEnv, getReasonPhrase, getRequiredEnv, isBrowser, isClientError, isCommandError, isEnvSet, isError, isNode, isServerError, isSuccess, make, raiseForCode, retryAsync, sleep, withRetry, withTimeLogging };
2079
2046
  //# sourceMappingURL=index.mjs.map
2080
2047
  //# sourceMappingURL=index.mjs.map