@tangle-network/sandbox 1.0.82 → 1.0.84

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.
@@ -1,4 +1,4 @@
1
- import { A as requestedPublicProfileDigest, C as encodeTextForWire, D as assertCurrentBackendType, E as applyRequestedModel, F as createAgentRunOutcomeTracker, I as deriveAgentResultOutcome, O as mergeRuntimeBackendConfig, P as withoutRuntimeSecrets, S as encodePromptForWire, U as normalizeEffectiveBackend, _ as mintTraceId, a as assertScopedTokenActive, b as resolveDispatchRunIdentity, c as SandboxRuntimeApi, d as appendSessionIdQuery, f as sessionHeaders, g as isTraceId, h as TRACE_ID_HEADER, i as terminalUpgradeHeadersSupported, j as requestedSecretProfilePublicDigest, k as normalizeRuntimeBackendConfig, l as normalizeSessionInfo, m as waitForRetryAfter, n as InteractiveSessionController, p as isRetryableCredentialRefusal, r as TerminalStream, s as requestScopedToken, u as sessionMessageRequestBody, v as resolveTraceId, w as canUseNodeHttp2, x as validateAcceptedDispatchRunRef, y as traceHeaders } from "./interactive-controller-CwZEKLoB.js";
1
+ import { A as requestedPublicProfileDigest, C as encodeTextForWire, D as assertCurrentBackendType, E as applyRequestedModel, F as createAgentRunOutcomeTracker, I as deriveAgentResultOutcome, O as mergeRuntimeBackendConfig, P as withoutRuntimeSecrets, S as encodePromptForWire, U as normalizeEffectiveBackend, _ as isTraceId, a as assertScopedTokenActive, b as resolveDispatchRunIdentity, c as SandboxRuntimeApi, d as appendSessionIdQuery, f as callHeaders, g as TRACE_ID_HEADER, h as waitForRetryAfter, i as terminalUpgradeHeadersSupported, j as requestedSecretProfilePublicDigest, k as normalizeRuntimeBackendConfig, l as normalizeSessionInfo, m as isRetryableCredentialRefusal, n as InteractiveSessionController, p as sessionHeaders, r as TerminalStream, s as requestScopedToken, u as sessionMessageRequestBody, v as mintTraceId, w as canUseNodeHttp2, x as validateAcceptedDispatchRunRef, y as resolveTraceId } from "./interactive-controller-BdGvy0jq.js";
2
2
  import { D as boundedStringSchema, _ as sha256, g as sha256DigestSchema$1, o as canonicalCandidateDigest$1, s as canonicalCandidateJson$1, u as isCanonicalJsonValue$1, w as boundedIdentifierSchema } from "./harness-D2TXEUu-.js";
3
3
  import { A as agentInteractiveSessionStatusMatchesRef, B as PlanContinuationSchema, C as AgentInteractiveSessionStopAcknowledgementSchema, D as agentInteractiveSessionControlClaimMatchesRef, E as agentInteractiveSessionControlClaimIsNewer, F as AgentRunCancellationAcknowledgementSchema, G as InteractionResponseSchema, H as InteractionBindingSchema, I as AgentRunCancellationRequestSchema, L as agentRunCancellationAcknowledgementMatchesRequest, M as agentInteractiveDimensionSchema, N as sameAgentExactRun, O as agentInteractiveSessionPromptAcknowledgementMatchesCommand, P as AgentExactRunControlRefSchema, S as AgentInteractiveSessionStatusSchema, T as agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, U as InteractionRequestSchema, V as InteractionAcknowledgementSchema, W as InteractionResponseCommandSchema, _ as AgentInteractiveSessionControlClaimRequestSchema, b as AgentInteractiveSessionPromptCommandSchema, d as interactiveSessionControlClaimResponseSchema, f as interactiveSessionControlReleaseResponseSchema, g as AgentInteractiveSessionControlClaimAcknowledgementSchema, h as AgentInteractiveSessionAttachSchema, j as agentInteractiveSessionStopAcknowledgementMatchesCommand, l as createInteractiveControlHolderId, m as interactiveSessionStatusResponseSchema, p as interactiveSessionControlValidationResponseSchema, v as AgentInteractiveSessionControlClaimSchema, w as AgentInteractiveSessionStopCommandSchema, x as AgentInteractiveSessionRefSchema, y as AgentInteractiveSessionPromptAcknowledgementSchema } from "./browser-interactive-control-controller-WLzM_Lyq.js";
4
4
  import { a as canonicalAgentProfileValue, r as agentProfileSchema } from "./profile-schema-D-XJLM1E.js";
@@ -1397,6 +1397,428 @@ const REFRESH_REASON_HEADER = "x-tangle-refresh-reason";
1397
1397
  function sendsRefreshReason() {
1398
1398
  return !("document" in globalThis);
1399
1399
  }
1400
+ const routes = Object.values({
1401
+ "codeExec": {
1402
+ "method": "POST",
1403
+ "path": "/code/exec",
1404
+ "auth": {
1405
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1406
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1407
+ "hostAgent": "ingress-and-scoped-token",
1408
+ "sidecar": "control-or-scoped-session-token"
1409
+ },
1410
+ "layers": [
1411
+ "worker",
1412
+ "orchestrator",
1413
+ "hostAgent",
1414
+ "sidecar",
1415
+ "typescript",
1416
+ "python"
1417
+ ],
1418
+ "auditAction": "sandbox.exec",
1419
+ "rateFamily": "process",
1420
+ "shortTokenRequired": true,
1421
+ "startsWork": true,
1422
+ "blocking": true
1423
+ },
1424
+ "processSpawn": {
1425
+ "method": "POST",
1426
+ "path": "/process/spawn",
1427
+ "auth": {
1428
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1429
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1430
+ "hostAgent": "ingress-and-scoped-token",
1431
+ "sidecar": "control-or-scoped-session-token"
1432
+ },
1433
+ "layers": [
1434
+ "worker",
1435
+ "orchestrator",
1436
+ "hostAgent",
1437
+ "sidecar",
1438
+ "typescript",
1439
+ "python"
1440
+ ],
1441
+ "auditAction": "sandbox.exec",
1442
+ "rateFamily": "process",
1443
+ "shortTokenRequired": true,
1444
+ "startsWork": true,
1445
+ "blocking": "blocking"
1446
+ },
1447
+ "ensureDevServer": {
1448
+ "method": "POST",
1449
+ "path": "/process/ensure-dev-server",
1450
+ "auth": {
1451
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1452
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1453
+ "hostAgent": "ingress-and-scoped-token",
1454
+ "sidecar": "control-or-scoped-session-token"
1455
+ },
1456
+ "layers": [
1457
+ "worker",
1458
+ "orchestrator",
1459
+ "hostAgent",
1460
+ "sidecar",
1461
+ "typescript",
1462
+ "python"
1463
+ ],
1464
+ "auditAction": "sandbox.exec",
1465
+ "rateFamily": "process",
1466
+ "shortTokenRequired": true,
1467
+ "startsWork": true,
1468
+ "blocking": true
1469
+ },
1470
+ "processList": {
1471
+ "method": "GET",
1472
+ "path": "/process",
1473
+ "auth": {
1474
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1475
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1476
+ "hostAgent": "ingress-and-scoped-token",
1477
+ "sidecar": "control-or-scoped-session-token"
1478
+ },
1479
+ "layers": [
1480
+ "worker",
1481
+ "orchestrator",
1482
+ "hostAgent",
1483
+ "sidecar",
1484
+ "typescript",
1485
+ "python"
1486
+ ],
1487
+ "auditAction": null,
1488
+ "rateFamily": null,
1489
+ "shortTokenRequired": false,
1490
+ "startsWork": false,
1491
+ "blocking": false
1492
+ },
1493
+ "processGet": {
1494
+ "method": "GET",
1495
+ "path": "/process/{pid}",
1496
+ "auth": {
1497
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1498
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1499
+ "hostAgent": "ingress-and-scoped-token",
1500
+ "sidecar": "control-or-scoped-session-token"
1501
+ },
1502
+ "layers": [
1503
+ "worker",
1504
+ "orchestrator",
1505
+ "hostAgent",
1506
+ "sidecar",
1507
+ "typescript",
1508
+ "python"
1509
+ ],
1510
+ "auditAction": null,
1511
+ "rateFamily": null,
1512
+ "shortTokenRequired": false,
1513
+ "startsWork": false,
1514
+ "blocking": false
1515
+ },
1516
+ "kill": {
1517
+ "method": "DELETE",
1518
+ "path": "/process/{pid}",
1519
+ "auth": {
1520
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1521
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1522
+ "hostAgent": "ingress-and-scoped-token",
1523
+ "sidecar": "control-or-scoped-session-token"
1524
+ },
1525
+ "layers": [
1526
+ "worker",
1527
+ "orchestrator",
1528
+ "hostAgent",
1529
+ "sidecar",
1530
+ "typescript",
1531
+ "python"
1532
+ ],
1533
+ "auditAction": null,
1534
+ "rateFamily": null,
1535
+ "shortTokenRequired": false,
1536
+ "startsWork": true,
1537
+ "blocking": false
1538
+ },
1539
+ "logs": {
1540
+ "method": "GET",
1541
+ "path": "/process/{pid}/logs",
1542
+ "auth": {
1543
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1544
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1545
+ "hostAgent": "ingress-and-scoped-token",
1546
+ "sidecar": "control-or-scoped-session-token"
1547
+ },
1548
+ "layers": [
1549
+ "worker",
1550
+ "orchestrator",
1551
+ "hostAgent",
1552
+ "sidecar",
1553
+ "typescript",
1554
+ "python"
1555
+ ],
1556
+ "auditAction": null,
1557
+ "rateFamily": null,
1558
+ "shortTokenRequired": false,
1559
+ "startsWork": false,
1560
+ "blocking": false
1561
+ },
1562
+ "listKernels": {
1563
+ "method": "GET",
1564
+ "path": "/code/kernels",
1565
+ "auth": {
1566
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1567
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1568
+ "hostAgent": "ingress-and-scoped-token",
1569
+ "sidecar": "control-or-scoped-session-token"
1570
+ },
1571
+ "layers": [
1572
+ "worker",
1573
+ "orchestrator",
1574
+ "hostAgent",
1575
+ "sidecar",
1576
+ "typescript",
1577
+ "python"
1578
+ ],
1579
+ "auditAction": null,
1580
+ "rateFamily": null,
1581
+ "shortTokenRequired": false,
1582
+ "startsWork": false,
1583
+ "blocking": false
1584
+ },
1585
+ "restartKernel": {
1586
+ "method": "POST",
1587
+ "path": "/code/kernels/{key}/restart",
1588
+ "auth": {
1589
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1590
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1591
+ "hostAgent": "ingress-and-scoped-token",
1592
+ "sidecar": "control-or-scoped-session-token"
1593
+ },
1594
+ "layers": [
1595
+ "worker",
1596
+ "orchestrator",
1597
+ "hostAgent",
1598
+ "sidecar",
1599
+ "typescript",
1600
+ "python"
1601
+ ],
1602
+ "auditAction": null,
1603
+ "rateFamily": null,
1604
+ "shortTokenRequired": false,
1605
+ "startsWork": true,
1606
+ "blocking": false
1607
+ },
1608
+ "disposeKernel": {
1609
+ "method": "DELETE",
1610
+ "path": "/code/kernels/{key}",
1611
+ "auth": {
1612
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1613
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1614
+ "hostAgent": "ingress-and-scoped-token",
1615
+ "sidecar": "control-or-scoped-session-token"
1616
+ },
1617
+ "layers": [
1618
+ "worker",
1619
+ "orchestrator",
1620
+ "hostAgent",
1621
+ "sidecar",
1622
+ "typescript",
1623
+ "python"
1624
+ ],
1625
+ "auditAction": null,
1626
+ "rateFamily": null,
1627
+ "shortTokenRequired": false,
1628
+ "startsWork": false,
1629
+ "blocking": false
1630
+ },
1631
+ "fileWrite": {
1632
+ "method": "POST",
1633
+ "path": "/files/write",
1634
+ "auth": {
1635
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1636
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1637
+ "hostAgent": "ingress-and-scoped-token",
1638
+ "sidecar": "control-or-scoped-session-token"
1639
+ },
1640
+ "layers": [
1641
+ "worker",
1642
+ "orchestrator",
1643
+ "hostAgent",
1644
+ "sidecar",
1645
+ "typescript",
1646
+ "python"
1647
+ ],
1648
+ "auditAction": null,
1649
+ "rateFamily": null,
1650
+ "shortTokenRequired": false,
1651
+ "startsWork": true,
1652
+ "blocking": false
1653
+ },
1654
+ "fileRead": {
1655
+ "method": "POST",
1656
+ "path": "/files/read",
1657
+ "auth": {
1658
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1659
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1660
+ "hostAgent": "ingress-and-scoped-token",
1661
+ "sidecar": "control-or-scoped-session-token"
1662
+ },
1663
+ "layers": [
1664
+ "worker",
1665
+ "orchestrator",
1666
+ "hostAgent",
1667
+ "sidecar",
1668
+ "typescript",
1669
+ "python"
1670
+ ],
1671
+ "auditAction": null,
1672
+ "rateFamily": null,
1673
+ "shortTokenRequired": false,
1674
+ "startsWork": false,
1675
+ "blocking": false
1676
+ },
1677
+ "fileInfo": {
1678
+ "method": "POST",
1679
+ "path": "/files/info",
1680
+ "auth": {
1681
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1682
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1683
+ "hostAgent": "ingress-and-scoped-token",
1684
+ "sidecar": "control-or-scoped-session-token"
1685
+ },
1686
+ "layers": [
1687
+ "worker",
1688
+ "orchestrator",
1689
+ "hostAgent",
1690
+ "sidecar",
1691
+ "typescript",
1692
+ "python"
1693
+ ],
1694
+ "auditAction": null,
1695
+ "rateFamily": null,
1696
+ "shortTokenRequired": false,
1697
+ "startsWork": false,
1698
+ "blocking": false
1699
+ },
1700
+ "fileReadBatch": {
1701
+ "method": "POST",
1702
+ "path": "/files/read-batch",
1703
+ "auth": {
1704
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1705
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1706
+ "hostAgent": "ingress-and-scoped-token",
1707
+ "sidecar": "control-or-scoped-session-token"
1708
+ },
1709
+ "layers": [
1710
+ "worker",
1711
+ "orchestrator",
1712
+ "hostAgent",
1713
+ "sidecar",
1714
+ "typescript",
1715
+ "python"
1716
+ ],
1717
+ "auditAction": null,
1718
+ "rateFamily": null,
1719
+ "shortTokenRequired": false,
1720
+ "startsWork": false,
1721
+ "blocking": false
1722
+ },
1723
+ "fileWriteBatch": {
1724
+ "method": "POST",
1725
+ "path": "/files/write-batch",
1726
+ "auth": {
1727
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1728
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1729
+ "hostAgent": "ingress-and-scoped-token",
1730
+ "sidecar": "control-or-scoped-session-token"
1731
+ },
1732
+ "layers": [
1733
+ "worker",
1734
+ "orchestrator",
1735
+ "hostAgent",
1736
+ "sidecar",
1737
+ "typescript",
1738
+ "python"
1739
+ ],
1740
+ "auditAction": null,
1741
+ "rateFamily": null,
1742
+ "shortTokenRequired": false,
1743
+ "startsWork": true,
1744
+ "blocking": false
1745
+ },
1746
+ "fileTree": {
1747
+ "method": "GET",
1748
+ "path": "/files/tree",
1749
+ "auth": {
1750
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1751
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1752
+ "hostAgent": "ingress-and-scoped-token",
1753
+ "sidecar": "control-or-scoped-session-token"
1754
+ },
1755
+ "layers": [
1756
+ "worker",
1757
+ "orchestrator",
1758
+ "hostAgent",
1759
+ "sidecar",
1760
+ "typescript",
1761
+ "python"
1762
+ ],
1763
+ "auditAction": null,
1764
+ "rateFamily": null,
1765
+ "shortTokenRequired": false,
1766
+ "startsWork": false,
1767
+ "blocking": false
1768
+ },
1769
+ "fileDelete": {
1770
+ "method": "POST",
1771
+ "path": "/files/delete",
1772
+ "auth": {
1773
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1774
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1775
+ "hostAgent": "ingress-and-scoped-token",
1776
+ "sidecar": "control-or-scoped-session-token"
1777
+ },
1778
+ "layers": [
1779
+ "worker",
1780
+ "orchestrator",
1781
+ "hostAgent",
1782
+ "sidecar",
1783
+ "typescript",
1784
+ "python"
1785
+ ],
1786
+ "auditAction": null,
1787
+ "rateFamily": null,
1788
+ "shortTokenRequired": false,
1789
+ "startsWork": true,
1790
+ "blocking": false
1791
+ },
1792
+ "fileRename": {
1793
+ "method": "POST",
1794
+ "path": "/files/rename",
1795
+ "auth": {
1796
+ "worker": "sandbox-owner-or-scoped-runtime-token",
1797
+ "orchestrator": "sandbox-owner-or-scoped-runtime-token",
1798
+ "hostAgent": "ingress-and-scoped-token",
1799
+ "sidecar": "control-or-scoped-session-token"
1800
+ },
1801
+ "layers": [
1802
+ "worker",
1803
+ "orchestrator",
1804
+ "hostAgent",
1805
+ "sidecar",
1806
+ "typescript",
1807
+ "python"
1808
+ ],
1809
+ "auditAction": null,
1810
+ "rateFamily": null,
1811
+ "shortTokenRequired": false,
1812
+ "startsWork": true,
1813
+ "blocking": false
1814
+ }
1815
+ }).map((operation) => ({
1816
+ ...operation,
1817
+ matcher: new RegExp("^" + operation.path.replace(/\{[^}]+\}/g, "[^/]+") + "$")
1818
+ }));
1819
+ function sandboxOperation(path, method, layer) {
1820
+ return routes.find((operation) => operation.method === method && operation.layers.includes(layer) && operation.matcher.test(path));
1821
+ }
1400
1822
  //#endregion
1401
1823
  //#region ../../../packages/runtime-contracts/dist/sidecar-request.js
1402
1824
  /**
@@ -1415,7 +1837,7 @@ function normalizeSidecarPathname(input) {
1415
1837
  }
1416
1838
  let probe = decoded;
1417
1839
  for (let layer = 0; layer <= 8; layer++) {
1418
- if (probe.includes("\\") || [...probe].some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127) || probe.split("/").some((segment) => segment === "." || segment === "..")) return null;
1840
+ if (/[\\\u0000-\u001f\u007f]/.test(probe) || probe.split("/").some((segment) => segment === "." || segment === "..")) return null;
1419
1841
  const next = probe.replace(/%(25|2e|2f|5c)/gi, (_, hex) => String.fromCharCode(Number.parseInt(hex, 16)));
1420
1842
  if (next === probe) {
1421
1843
  const pathname = decoded.split("/").map((segment) => encodeURIComponent(segment).replace(/%(3a|40|24|26|2b|2c|3b|3d)/gi, (escaped) => String.fromCharCode(Number.parseInt(escaped.slice(1), 16)))).join("/");
@@ -1429,45 +1851,31 @@ function normalizeSidecarPathname(input) {
1429
1851
  }
1430
1852
  return null;
1431
1853
  }
1432
- const EXEC_ROUTES = [
1433
- {
1434
- path: "exec",
1435
- rateFamily: "process"
1436
- },
1437
- {
1438
- path: "code/exec",
1439
- rateFamily: "process"
1440
- },
1441
- {
1442
- path: "process/spawn",
1443
- rateFamily: "process"
1444
- },
1445
- {
1446
- path: "process/ensure-dev-server",
1447
- rateFamily: "process"
1448
- },
1449
- {
1450
- path: "terminals/commands",
1451
- rateFamily: "terminal"
1452
- }
1453
- ];
1854
+ const EXEC_ROUTES = [{
1855
+ path: "exec",
1856
+ rateFamily: "process"
1857
+ }, {
1858
+ path: "terminals/commands",
1859
+ rateFamily: "terminal"
1860
+ }];
1454
1861
  /** Classify once, before constructing a URL that could erase dot segments. */
1455
1862
  function classifySidecarRequest(input, method, upgrade = false) {
1456
1863
  const normalized = normalizeSidecarPathname(input);
1457
1864
  if (!normalized) return null;
1458
1865
  const { path, pathname } = normalized;
1866
+ const operation = !upgrade ? sandboxOperation(`/${path}`, method, "hostAgent") : void 0;
1459
1867
  const exec = method === "POST" && !upgrade ? EXEC_ROUTES.find((route) => route.path === path) : void 0;
1460
- let auditAction = exec ? "sandbox.exec" : null;
1868
+ let auditAction = operation?.auditAction ?? (exec ? "sandbox.exec" : null);
1461
1869
  if (upgrade && /^terminals\/[^/]+\/ws$/.test(path)) auditAction = "sandbox.terminal.attach";
1462
1870
  else if (upgrade && path === "ssh") auditAction = "sandbox.ssh.open";
1463
1871
  else if (!upgrade && method === "POST" && path === "terminals") auditAction = "sandbox.terminal.attach";
1464
- const rateFamily = exec?.rateFamily ?? (auditAction ? "terminal-open" : null) ?? (path === "process" || path.startsWith("process/") ? "process" : null);
1872
+ const rateFamily = operation?.rateFamily ?? exec?.rateFamily ?? (auditAction ? "terminal-open" : null) ?? (path === "process" || path.startsWith("process/") ? "process" : null);
1465
1873
  return {
1466
1874
  path,
1467
1875
  pathname,
1468
1876
  auditAction,
1469
1877
  rateFamily,
1470
- shortTokenRequired: !!exec
1878
+ shortTokenRequired: operation?.shortTokenRequired ?? !!exec
1471
1879
  };
1472
1880
  }
1473
1881
  //#endregion
@@ -3161,7 +3569,7 @@ var SandboxOperation = class SandboxOperation {
3161
3569
  //#region src/lib/sandbox-command.ts
3162
3570
  const SANDBOX_COMMAND_SHELL = "/bin/sh";
3163
3571
  function sandboxShellCommandArgs(command) {
3164
- return ["-c", command];
3572
+ return [...["-c"], command];
3165
3573
  }
3166
3574
  //#endregion
3167
3575
  //#region src/managed-process.ts
@@ -5527,37 +5935,31 @@ var SandboxRuntimeOperations = class extends SandboxLifecycleCapabilities {
5527
5935
  }
5528
5936
  };
5529
5937
  //#endregion
5530
- //#region src/sandbox-exec.ts
5531
- const EXEC_DEFAULT_TIMEOUT_MS = 3e4;
5532
- const EXEC_MIN_TIMEOUT_MS = 100;
5533
- const EXEC_MAX_TIMEOUT_MS = 6e5;
5534
- const EXEC_TRANSPORT_MARGIN_MS = 15e3;
5535
- /**
5536
- * Headers for one exec, read, write or search call: the task session it runs in
5537
- * and the turn trace it belongs to. Undefined when it names neither.
5538
- */
5539
- function callHeaders(options) {
5540
- const session = sessionHeaders(options?.sessionId);
5541
- const trace = traceHeaders(options?.traceId);
5542
- return session || trace ? {
5543
- ...session,
5544
- ...trace
5545
- } : void 0;
5546
- }
5547
- function quoteForShell(value) {
5548
- if (value.includes("\0")) throw new Error("Shell argument contains NUL byte");
5549
- return `'${value.replace(/'/g, "'\\''")}'`;
5550
- }
5551
- var SandboxExecCapabilities = class extends SandboxRuntimeOperations {
5552
- /**
5553
- * Execute a command in the sandbox through a non-login POSIX shell.
5554
- * The command inherits the sandbox runtime environment.
5555
- */
5938
+ //#region src/generated/sandbox-code-operations.ts
5939
+ var SandboxCodeOperations = class extends SandboxRuntimeOperations {
5940
+ async runCode(language, source, options) {
5941
+ const headers = sessionHeaders(options?.sessionId) ?? {};
5942
+ await this.ensureRunning();
5943
+ if (options?.idempotencyKey) headers["X-Idempotency-Key"] = options.idempotencyKey;
5944
+ const payload = await readResponseJson(await this.runtimeFetch("/code/exec", {
5945
+ method: "POST",
5946
+ headers,
5947
+ body: JSON.stringify({
5948
+ language,
5949
+ source,
5950
+ timeoutMs: options?.timeoutMs,
5951
+ env: options?.env,
5952
+ cwd: options?.cwd
5953
+ })
5954
+ }));
5955
+ if (!payload.success || !payload.data) throw new Error(payload.error?.message ?? "runCode failed without a typed error");
5956
+ return payload.data;
5957
+ }
5556
5958
  async exec(command, options) {
5557
5959
  const headers = callHeaders(options);
5558
5960
  await this.ensureRunning(options?.signal);
5559
- const timeoutMs = options?.timeoutMs ?? EXEC_DEFAULT_TIMEOUT_MS;
5560
- if (!Number.isInteger(timeoutMs) || timeoutMs < EXEC_MIN_TIMEOUT_MS || timeoutMs > EXEC_MAX_TIMEOUT_MS) throw new ValidationError(`exec timeoutMs must be an integer between ${EXEC_MIN_TIMEOUT_MS} and ${EXEC_MAX_TIMEOUT_MS}`);
5961
+ const timeoutMs = options?.timeoutMs ?? 3e4;
5962
+ if (!Number.isInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 6e5) throw new ValidationError("exec timeoutMs must be an integer between 100 and 600000");
5561
5963
  const result = (await readResponseJson(await runPreparedProcess((path, init, budget) => this.runtimeFetch(path, init, { timeoutMs: budget }), "/process/spawn", {
5562
5964
  method: "POST",
5563
5965
  headers,
@@ -5570,7 +5972,7 @@ var SandboxExecCapabilities = class extends SandboxRuntimeOperations {
5570
5972
  timeoutMs,
5571
5973
  blocking: true
5572
5974
  })
5573
- }, timeoutMs + EXEC_TRANSPORT_MARGIN_MS))).data;
5975
+ }, timeoutMs + 15e3))).data;
5574
5976
  if (!result || typeof result.exitCode !== "number" || typeof result.stdout !== "string" || typeof result.stderr !== "string") throw new ServerError("Sandbox process response was malformed", 502);
5575
5977
  return {
5576
5978
  exitCode: result.exitCode,
@@ -5578,51 +5980,14 @@ var SandboxExecCapabilities = class extends SandboxRuntimeOperations {
5578
5980
  stderr: result.stderr
5579
5981
  };
5580
5982
  }
5581
- /**
5582
- * Run code in a persistent language kernel.
5583
- *
5584
- * Each `(sessionId, language)` pair gets its own long-lived kernel that
5585
- * keeps variable state across calls — like Jupyter cells. Without a
5586
- * `sessionId`, calls share a process-wide kernel per language.
5587
- *
5588
- * Returns typed results: stdout/stderr text plus a `results` array of
5589
- * structured outputs (matplotlib images as base64 PNG, pandas DataFrames,
5590
- * explicit `display(value)` calls as JSON/HTML, errors with traceback).
5591
- *
5592
- * @example Persistent Python session
5593
- * ```ts
5594
- * await box.runCode("python", "import pandas as pd; df = pd.DataFrame({'x': range(5)})", { sessionId: "s1" });
5595
- * const r = await box.runCode("python", "df.describe()", { sessionId: "s1" });
5596
- * // r.results[0] is a `dataframe` part with columns + rows from the describe()
5597
- * ```
5598
- *
5599
- * @example Matplotlib chart
5600
- * ```ts
5601
- * const r = await box.runCode("python",
5602
- * "import matplotlib.pyplot as plt; plt.plot([1,2,3,4]); plt.show()",
5603
- * { sessionId: "s1" });
5604
- * const png = r.results.find(p => p.type === "image");
5605
- * // png.data is a base64 PNG ready to render or hand back to an LLM
5606
- * ```
5607
- */
5608
- async runCode(language, source, options) {
5609
- const headers = sessionHeaders(options?.sessionId) ?? {};
5610
- await this.ensureRunning();
5611
- if (options?.idempotencyKey) headers["X-Idempotency-Key"] = options.idempotencyKey;
5612
- const payload = await readResponseJson(await this.runtimeFetch("/code/exec", {
5613
- method: "POST",
5614
- headers,
5615
- body: JSON.stringify({
5616
- language,
5617
- source,
5618
- timeoutMs: options?.timeoutMs,
5619
- env: options?.env,
5620
- cwd: options?.cwd
5621
- })
5622
- }));
5623
- if (!payload.success || !payload.data) throw new Error(payload.error?.message ?? "runCode failed without a typed error");
5624
- return payload.data;
5625
- }
5983
+ };
5984
+ //#endregion
5985
+ //#region src/sandbox-exec.ts
5986
+ function quoteForShell(value) {
5987
+ if (value.includes("\0")) throw new Error("Shell argument contains NUL byte");
5988
+ return `'${value.replace(/'/g, "'\\''")}'`;
5989
+ }
5990
+ var SandboxExecCapabilities = class extends SandboxCodeOperations {
5626
5991
  /**
5627
5992
  * Search for text patterns in files using ripgrep.
5628
5993
  *
@@ -5769,48 +6134,8 @@ var SandboxExecCapabilities = class extends SandboxRuntimeOperations {
5769
6134
  }
5770
6135
  };
5771
6136
  //#endregion
5772
- //#region src/sandbox-file-write.ts
5773
- var SandboxFileWriteCapabilities = class extends SandboxExecCapabilities {
5774
- /**
5775
- * Read a file from the sandbox.
5776
- *
5777
- * @param path - Path to the file. Relative paths resolve from the workspace root.
5778
- * Absolute paths (e.g., `/tmp/output.json`) access the container filesystem directly.
5779
- * @returns File content as string
5780
- *
5781
- * @example
5782
- * ```typescript
5783
- * const content = await box.read("src/index.ts");
5784
- * const report = await box.read("/output/report.json");
5785
- * ```
5786
- */
5787
- async read(path, options) {
5788
- const headers = callHeaders(options);
5789
- await this.ensureRunning();
5790
- const response = await this.runtimeFetch("/files/read", {
5791
- method: "POST",
5792
- headers,
5793
- body: JSON.stringify({
5794
- path,
5795
- encoding: "utf8"
5796
- })
5797
- });
5798
- if (!response.ok) throw await parseResponseError(response);
5799
- return parseTextFileReadResponse(await response.text());
5800
- }
5801
- /**
5802
- * Write content to a file in the sandbox.
5803
- *
5804
- * @param path - Path to the file. Relative paths resolve from the workspace root.
5805
- * Absolute paths (e.g., `/tmp/cases.json`) write to the container filesystem directly.
5806
- * @param content - Content to write
5807
- *
5808
- * @example
5809
- * ```typescript
5810
- * await box.write("src/fix.ts", "export const fix = () => {}");
5811
- * await box.write("/tmp/config.json", JSON.stringify(config));
5812
- * ```
5813
- */
6137
+ //#region src/generated/sandbox-file-operations.ts
6138
+ var SandboxFileOperations = class extends SandboxExecCapabilities {
5814
6139
  async write(path, content, options) {
5815
6140
  await this.ensureRunning();
5816
6141
  return this.writeFileRequest(path, content, options);
@@ -5819,7 +6144,7 @@ var SandboxFileWriteCapabilities = class extends SandboxExecCapabilities {
5819
6144
  const params = new URLSearchParams();
5820
6145
  appendSessionIdQuery(params, options?.sessionId);
5821
6146
  const query = params.toString();
5822
- const data = await readResponseJson(await this.runtimeFetch(`/files/write${query ? `?${query}` : ""}`, {
6147
+ const data = await readResponseJson(await this.runtimeFetch("/files/write" + (query ? "?" + query : ""), {
5823
6148
  method: "POST",
5824
6149
  headers: callHeaders({ traceId: options?.traceId }),
5825
6150
  body: JSON.stringify({
@@ -5838,6 +6163,38 @@ var SandboxFileWriteCapabilities = class extends SandboxExecCapabilities {
5838
6163
  });
5839
6164
  return data.data;
5840
6165
  }
6166
+ async read(path, options) {
6167
+ const headers = callHeaders(options);
6168
+ await this.ensureRunning();
6169
+ const response = await this.runtimeFetch("/files/read", {
6170
+ method: "POST",
6171
+ headers,
6172
+ body: JSON.stringify({
6173
+ path,
6174
+ encoding: "utf8"
6175
+ })
6176
+ });
6177
+ if (!response.ok) throw await parseResponseError(response);
6178
+ let payload;
6179
+ try {
6180
+ payload = JSON.parse(await response.text());
6181
+ } catch (error) {
6182
+ if (!(error instanceof SyntaxError)) throw error;
6183
+ throw new ServerError("Runtime returned invalid JSON for file read", 502, {
6184
+ origin: "runtime",
6185
+ endpoint: "/files/read"
6186
+ });
6187
+ }
6188
+ if (typeof payload !== "object" || payload === null || !("success" in payload) || payload.success !== true || !("data" in payload) || typeof payload.data !== "object" || payload.data === null || !("content" in payload.data) || typeof payload.data.content !== "string" || !("encoding" in payload.data) || payload.data.encoding !== "utf8") throw new ServerError("Runtime returned a malformed text file response", 502, {
6189
+ origin: "runtime",
6190
+ endpoint: "/files/read"
6191
+ });
6192
+ return payload.data.content;
6193
+ }
6194
+ };
6195
+ //#endregion
6196
+ //#region src/sandbox-file-write.ts
6197
+ var SandboxFileWriteCapabilities = class extends SandboxFileOperations {
5841
6198
  assertWritePreconditions(result, requested) {
5842
6199
  if ([...requested.expectedHash !== void 0 ? ["ifHash"] : [], ...requested.ifAbsent ? ["ifAbsent"] : []].some((precondition) => !result.preconditionsApplied?.includes(precondition))) throw new CapabilityError("sidecar does not support write preconditions");
5843
6200
  }
@@ -6000,22 +6357,6 @@ function splitWriteManyBatches(files) {
6000
6357
  function hasDuplicateWriteManyPaths(files) {
6001
6358
  return new Set(files.map((file) => file.path)).size !== files.length;
6002
6359
  }
6003
- function parseTextFileReadResponse(body) {
6004
- let payload;
6005
- try {
6006
- payload = JSON.parse(body);
6007
- } catch {
6008
- throw new ServerError("Runtime returned invalid JSON for file read", 502, {
6009
- origin: "runtime",
6010
- endpoint: "/files/read"
6011
- });
6012
- }
6013
- if (typeof payload !== "object" || payload === null || !("success" in payload) || payload.success !== true || !("data" in payload) || typeof payload.data !== "object" || payload.data === null || !("content" in payload.data) || typeof payload.data.content !== "string" || !("encoding" in payload.data) || payload.data.encoding !== "utf8") throw new ServerError("Runtime returned a malformed text file response", 502, {
6014
- origin: "runtime",
6015
- endpoint: "/files/read"
6016
- });
6017
- return payload.data.content;
6018
- }
6019
6360
  const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
6020
6361
  /** Transient file-write failures worth retrying: rate-limit (quota), 5xx,
6021
6362
  * transport (network), and request timeouts. A non-transient error (bad path,