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.mjs CHANGED
@@ -86,14 +86,21 @@ 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
+ };
89
94
  var SandboxResponseSchema = z.object({
90
95
  code: z.nativeEnum(Codes).optional(),
91
96
  exitCode: z.number().optional(),
92
- failureReason: z.string().optional()
97
+ failureReason: z.string().optional(),
98
+ ...HeaderFieldsSchema
93
99
  });
94
100
  var IsAliveResponseSchema = z.object({
95
101
  isAlive: z.boolean(),
96
- message: z.string().default("")
102
+ message: z.string().default(""),
103
+ ...HeaderFieldsSchema
97
104
  });
98
105
  var SandboxStatusResponseSchema = z.object({
99
106
  sandboxId: z.string().optional(),
@@ -110,54 +117,68 @@ var SandboxStatusResponseSchema = z.object({
110
117
  namespace: z.string().optional(),
111
118
  cpus: z.number().optional(),
112
119
  memory: z.string().optional(),
113
- state: z.unknown().optional()
120
+ state: z.unknown().optional(),
121
+ ...HeaderFieldsSchema
114
122
  });
115
123
  var CommandResponseSchema = z.object({
116
124
  stdout: z.string().default(""),
117
125
  stderr: z.string().default(""),
118
- exitCode: z.number().optional()
126
+ exitCode: z.number().optional(),
127
+ ...HeaderFieldsSchema
119
128
  });
120
129
  var WriteFileResponseSchema = z.object({
121
130
  success: z.boolean().default(false),
122
- message: z.string().default("")
131
+ message: z.string().default(""),
132
+ ...HeaderFieldsSchema
123
133
  });
124
134
  var ReadFileResponseSchema = z.object({
125
- content: z.string().default("")
135
+ content: z.string().default(""),
136
+ ...HeaderFieldsSchema
126
137
  });
127
138
  var UploadResponseSchema = z.object({
128
139
  success: z.boolean().default(false),
129
140
  message: z.string().default(""),
130
- fileName: z.string().optional()
141
+ fileName: z.string().optional(),
142
+ ...HeaderFieldsSchema
131
143
  });
132
144
  var ObservationSchema = z.object({
133
145
  output: z.string().default(""),
134
146
  exitCode: z.number().optional(),
135
147
  failureReason: z.string().default(""),
136
- expectString: z.string().default("")
148
+ expectString: z.string().default(""),
149
+ ...HeaderFieldsSchema
137
150
  });
138
151
  var CreateSessionResponseSchema = z.object({
139
152
  output: z.string().default(""),
140
- sessionType: z.literal("bash").default("bash")
153
+ sessionType: z.literal("bash").default("bash"),
154
+ ...HeaderFieldsSchema
141
155
  });
142
156
  var CloseSessionResponseSchema = z.object({
143
- sessionType: z.literal("bash").default("bash")
157
+ sessionType: z.literal("bash").default("bash"),
158
+ ...HeaderFieldsSchema
159
+ });
160
+ var CloseResponseSchema = z.object({
161
+ ...HeaderFieldsSchema
144
162
  });
145
- var CloseResponseSchema = z.object({});
146
163
  var ChownResponseSchema = z.object({
147
164
  success: z.boolean().default(false),
148
- message: z.string().default("")
165
+ message: z.string().default(""),
166
+ ...HeaderFieldsSchema
149
167
  });
150
168
  var ChmodResponseSchema = z.object({
151
169
  success: z.boolean().default(false),
152
- message: z.string().default("")
170
+ message: z.string().default(""),
171
+ ...HeaderFieldsSchema
153
172
  });
154
173
  var ExecuteBashSessionResponseSchema = z.object({
155
174
  success: z.boolean().default(false),
156
- message: z.string().default("")
175
+ message: z.string().default(""),
176
+ ...HeaderFieldsSchema
157
177
  });
158
178
  var OssSetupResponseSchema = z.object({
159
179
  success: z.boolean().default(false),
160
- message: z.string().default("")
180
+ message: z.string().default(""),
181
+ ...HeaderFieldsSchema
161
182
  });
162
183
 
163
184
  // src/common/constants.ts
@@ -273,6 +294,7 @@ var HttpUtils = class {
273
294
  * Send POST request
274
295
  * Automatically converts request body from camelCase to snake_case
275
296
  * Automatically converts response from snake_case to camelCase
297
+ * Returns structured response with headers
276
298
  */
277
299
  static async post(url, headers, data, readTimeout) {
278
300
  const client = this.createClient({
@@ -282,7 +304,18 @@ var HttpUtils = class {
282
304
  const snakeData = objectToSnake(data);
283
305
  try {
284
306
  const response = await client.post(url, snakeData);
285
- return objectToCamel(response.data);
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
318
+ };
286
319
  } catch (error) {
287
320
  if (error instanceof AxiosError) {
288
321
  throw new Error(`Failed to POST ${url}: ${error.message}`);
@@ -293,12 +326,24 @@ var HttpUtils = class {
293
326
  /**
294
327
  * Send GET request
295
328
  * Automatically converts response from snake_case to camelCase
329
+ * Returns structured response with headers
296
330
  */
297
331
  static async get(url, headers) {
298
332
  const client = this.createClient({ headers });
299
333
  try {
300
334
  const response = await client.get(url);
301
- return objectToCamel(response.data);
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
346
+ };
302
347
  } catch (error) {
303
348
  if (error instanceof AxiosError) {
304
349
  throw new Error(`Failed to GET ${url}: ${error.message}`);
@@ -316,6 +361,7 @@ var HttpUtils = class {
316
361
  * Send multipart/form-data request
317
362
  * Automatically converts form data keys to snake_case
318
363
  * Automatically converts response from snake_case to camelCase
364
+ * Returns structured response with headers
319
365
  */
320
366
  static async postMultipart(url, headers, data, files) {
321
367
  const formData = new FormData();
@@ -352,7 +398,18 @@ var HttpUtils = class {
352
398
  });
353
399
  try {
354
400
  const response = await client.post(url, formData);
355
- return objectToCamel(response.data);
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
412
+ };
356
413
  } catch (error) {
357
414
  if (error instanceof AxiosError) {
358
415
  throw new Error(`Failed to POST multipart ${url}: ${error.message}`);
@@ -563,7 +620,7 @@ var EnvHubClient = class {
563
620
  this.headers,
564
621
  payload
565
622
  );
566
- return createRockEnvInfo(response);
623
+ return createRockEnvInfo(response.result);
567
624
  } catch (e) {
568
625
  throw new EnvHubError(`Failed to register environment: ${e}`);
569
626
  }
@@ -580,7 +637,7 @@ var EnvHubClient = class {
580
637
  this.headers,
581
638
  payload
582
639
  );
583
- return createRockEnvInfo(response);
640
+ return createRockEnvInfo(response.result);
584
641
  } catch (e) {
585
642
  throw new EnvHubError(`Failed to get environment ${envName}: ${e}`);
586
643
  }
@@ -600,7 +657,7 @@ var EnvHubClient = class {
600
657
  this.headers,
601
658
  payload
602
659
  );
603
- const envsData = response.envs ?? [];
660
+ const envsData = response.result?.envs ?? [];
604
661
  return envsData.map((envData) => createRockEnvInfo(envData));
605
662
  } catch (e) {
606
663
  throw new EnvHubError(`Failed to list environments: ${e}`);
@@ -633,7 +690,7 @@ var EnvHubClient = class {
633
690
  url,
634
691
  this.headers
635
692
  );
636
- return response;
693
+ return response.result;
637
694
  } catch (e) {
638
695
  throw new EnvHubError(`Failed to health check: ${e}`);
639
696
  }
@@ -1082,7 +1139,7 @@ var Process = class {
1082
1139
  const scriptPath = `/tmp/${name}`;
1083
1140
  try {
1084
1141
  logger5.info(`[${sandboxId}] Uploading script to ${scriptPath}`);
1085
- const writeResult = await this.sandbox.write_file({
1142
+ const writeResult = await this.sandbox.writeFile({
1086
1143
  content: scriptContent,
1087
1144
  path: scriptPath
1088
1145
  });
@@ -1341,6 +1398,16 @@ var Sandbox = class extends AbstractSandbox {
1341
1398
  headers["X-Namespace"] = this.config.namespace;
1342
1399
  }
1343
1400
  }
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
+ }
1344
1411
  // Lifecycle methods
1345
1412
  async start() {
1346
1413
  logger8.info("Starting sandbox...");
@@ -1424,7 +1491,11 @@ var Sandbox = class extends AbstractSandbox {
1424
1491
  if (response.status !== "Success") {
1425
1492
  throw new Error(`Failed to get status: ${JSON.stringify(response)}`);
1426
1493
  }
1427
- return response.result;
1494
+ const result = response.result;
1495
+ result.cluster = response.headers["x-rock-gateway-target-cluster"] || this.config.cluster || "N/A";
1496
+ result.requestId = response.headers["x-request-id"] || response.headers["request-id"] || "N/A";
1497
+ result.eagleeyeTraceid = response.headers["eagleeye-traceid"] || "N/A";
1498
+ return result;
1428
1499
  }
1429
1500
  // Command execution
1430
1501
  async execute(command) {
@@ -1446,7 +1517,9 @@ var Sandbox = class extends AbstractSandbox {
1446
1517
  if (response.status !== "Success") {
1447
1518
  throw new Error(`Failed to execute command: ${JSON.stringify(response)}`);
1448
1519
  }
1449
- return response.result;
1520
+ const result = response.result;
1521
+ Object.assign(result, this.extractHeaderFields(response.headers));
1522
+ return result;
1450
1523
  } catch (e) {
1451
1524
  throw new Error(`Failed to execute command: ${e}`);
1452
1525
  }
@@ -1468,7 +1541,9 @@ var Sandbox = class extends AbstractSandbox {
1468
1541
  if (response.status !== "Success") {
1469
1542
  throw new Error(`Failed to create session: ${JSON.stringify(response)}`);
1470
1543
  }
1471
- return response.result;
1544
+ const result = response.result;
1545
+ Object.assign(result, this.extractHeaderFields(response.headers));
1546
+ return result;
1472
1547
  } catch (e) {
1473
1548
  throw new Error(`Failed to create session: ${e}`);
1474
1549
  }
@@ -1489,7 +1564,9 @@ var Sandbox = class extends AbstractSandbox {
1489
1564
  if (response.status !== "Success") {
1490
1565
  throw new Error(`Failed to close session: ${JSON.stringify(response)}`);
1491
1566
  }
1492
- return response.result ?? { sessionType: "bash" };
1567
+ const result = response.result ?? { sessionType: "bash" };
1568
+ Object.assign(result, this.extractHeaderFields(response.headers));
1569
+ return result;
1493
1570
  } catch (e) {
1494
1571
  throw new Error(`Failed to close session: ${e}`);
1495
1572
  }
@@ -1535,7 +1612,9 @@ var Sandbox = class extends AbstractSandbox {
1535
1612
  if (response.status !== "Success") {
1536
1613
  throw new Error(`Failed to execute command: ${JSON.stringify(response)}`);
1537
1614
  }
1538
- return response.result;
1615
+ const result = response.result;
1616
+ Object.assign(result, this.extractHeaderFields(response.headers));
1617
+ return result;
1539
1618
  } catch (e) {
1540
1619
  throw new Error(`Failed to run in session: ${e}`);
1541
1620
  }
@@ -1574,7 +1653,10 @@ var Sandbox = class extends AbstractSandbox {
1574
1653
  output: "Failed to submit command, nohup failed to extract PID",
1575
1654
  exitCode: 1,
1576
1655
  failureReason: "PID extraction failed",
1577
- expectString: ""
1656
+ expectString: "",
1657
+ cluster: response.cluster,
1658
+ requestId: response.requestId,
1659
+ eagleeyeTraceid: response.eagleeyeTraceid
1578
1660
  };
1579
1661
  }
1580
1662
  const success = await this.waitForProcessCompletion(pid, tmpSession, waitTimeout, waitInterval);
@@ -1583,7 +1665,10 @@ var Sandbox = class extends AbstractSandbox {
1583
1665
  output: `Command executed in nohup mode. Output file: ${tmpFile}`,
1584
1666
  exitCode: success ? 0 : 1,
1585
1667
  failureReason: success ? "" : "Process did not complete successfully",
1586
- expectString: ""
1668
+ expectString: "",
1669
+ cluster: response.cluster,
1670
+ requestId: response.requestId,
1671
+ eagleeyeTraceid: response.eagleeyeTraceid
1587
1672
  };
1588
1673
  }
1589
1674
  const readCmd = responseLimitedBytesInNohup ? `head -c ${responseLimitedBytesInNohup} ${tmpFile}` : `cat ${tmpFile}`;
@@ -1595,7 +1680,10 @@ var Sandbox = class extends AbstractSandbox {
1595
1680
  output: outputResult.output,
1596
1681
  exitCode: success ? 0 : 1,
1597
1682
  failureReason: success ? "" : "Process did not complete successfully",
1598
- expectString: ""
1683
+ expectString: "",
1684
+ cluster: outputResult.cluster,
1685
+ requestId: outputResult.requestId,
1686
+ eagleeyeTraceid: outputResult.eagleeyeTraceid
1599
1687
  };
1600
1688
  }
1601
1689
  async waitForProcessCompletion(pid, session, waitTimeout, waitInterval) {
@@ -1621,7 +1709,7 @@ var Sandbox = class extends AbstractSandbox {
1621
1709
  return false;
1622
1710
  }
1623
1711
  // File operations
1624
- async write_file(request) {
1712
+ async writeFile(request) {
1625
1713
  const url = `${this.url}/write_file`;
1626
1714
  const headers = this.buildHeaders();
1627
1715
  const data = {
@@ -1630,12 +1718,13 @@ var Sandbox = class extends AbstractSandbox {
1630
1718
  sandboxId: this.sandboxId
1631
1719
  };
1632
1720
  const response = await HttpUtils.post(url, headers, data);
1721
+ const headerFields = this.extractHeaderFields(response.headers);
1633
1722
  if (response.status !== "Success") {
1634
- return { success: false, message: `Failed to write file ${request.path}` };
1723
+ return { success: false, message: `Failed to write file ${request.path}`, ...headerFields };
1635
1724
  }
1636
- return { success: true, message: `Successfully write content to file ${request.path}` };
1725
+ return { success: true, message: `Successfully write content to file ${request.path}`, ...headerFields };
1637
1726
  }
1638
- async read_file(request) {
1727
+ async readFile(request) {
1639
1728
  const url = `${this.url}/read_file`;
1640
1729
  const headers = this.buildHeaders();
1641
1730
  const data = {
@@ -1649,7 +1738,10 @@ var Sandbox = class extends AbstractSandbox {
1649
1738
  headers,
1650
1739
  data
1651
1740
  );
1652
- return { content: response.result?.content ?? "" };
1741
+ return {
1742
+ content: response.result?.content ?? "",
1743
+ ...this.extractHeaderFields(response.headers)
1744
+ };
1653
1745
  }
1654
1746
  // Upload
1655
1747
  async upload(request) {
@@ -1661,7 +1753,7 @@ var Sandbox = class extends AbstractSandbox {
1661
1753
  try {
1662
1754
  const fs = await import('fs');
1663
1755
  if (!fs.existsSync(sourcePath)) {
1664
- return { success: false, message: `File not found: ${sourcePath}` };
1756
+ return { success: false, message: `File not found: ${sourcePath}`, cluster: "N/A", requestId: "N/A", eagleeyeTraceid: "N/A" };
1665
1757
  }
1666
1758
  const fileBuffer = fs.readFileSync(sourcePath);
1667
1759
  const fileName = sourcePath.split("/").pop() ?? "file";
@@ -1671,12 +1763,13 @@ var Sandbox = class extends AbstractSandbox {
1671
1763
  { targetPath, sandboxId: this.sandboxId ?? "" },
1672
1764
  { file: [fileName, fileBuffer, "application/octet-stream"] }
1673
1765
  );
1766
+ const headerFields = this.extractHeaderFields(response.headers);
1674
1767
  if (response.status !== "Success") {
1675
- return { success: false, message: "Upload failed" };
1768
+ return { success: false, message: "Upload failed", ...headerFields };
1676
1769
  }
1677
- return { success: true, message: `Successfully uploaded file ${fileName} to ${targetPath}` };
1770
+ return { success: true, message: `Successfully uploaded file ${fileName} to ${targetPath}`, ...headerFields };
1678
1771
  } catch (e) {
1679
- return { success: false, message: `Upload failed: ${e}` };
1772
+ return { success: false, message: `Upload failed: ${e}`, cluster: "N/A", requestId: "N/A", eagleeyeTraceid: "N/A" };
1680
1773
  }
1681
1774
  }
1682
1775
  // Close
@@ -1982,6 +2075,6 @@ var ModelService = class {
1982
2075
  // src/index.ts
1983
2076
  var VERSION = "1.2.1";
1984
2077
 
1985
- 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 };
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 };
1986
2079
  //# sourceMappingURL=index.mjs.map
1987
2080
  //# sourceMappingURL=index.mjs.map