@polos/sdk 0.2.0 → 0.2.1

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.cjs CHANGED
@@ -318,7 +318,7 @@ var OrchestratorClient = class {
318
318
  }
319
319
  if (attempt < retries) {
320
320
  const delay = Math.min(1e3 * Math.pow(2, attempt), 16e3);
321
- await new Promise((resolve8) => setTimeout(resolve8, delay));
321
+ await new Promise((resolve10) => setTimeout(resolve10, delay));
322
322
  }
323
323
  }
324
324
  }
@@ -770,7 +770,7 @@ var OrchestratorClient = class {
770
770
  if (execution.status === "completed" || execution.status === "failed" || execution.status === "cancelled") {
771
771
  return execution;
772
772
  }
773
- await new Promise((resolve8) => setTimeout(resolve8, pollInterval));
773
+ await new Promise((resolve10) => setTimeout(resolve10, pollInterval));
774
774
  }
775
775
  throw new Error(`Execution ${executionId} timed out after ${String(timeout)}ms`);
776
776
  }
@@ -1696,7 +1696,7 @@ function calculateDelay(attempt, options) {
1696
1696
  return Math.round(delay);
1697
1697
  }
1698
1698
  function sleep(ms) {
1699
- return new Promise((resolve8) => setTimeout(resolve8, ms));
1699
+ return new Promise((resolve10) => setTimeout(resolve10, ms));
1700
1700
  }
1701
1701
  async function retry(fn, options = {}) {
1702
1702
  const opts = { ...DEFAULT_OPTIONS, ...options };
@@ -1882,7 +1882,7 @@ function createStepHelper(options) {
1882
1882
  if (options2.days) totalSeconds += options2.days * 86400;
1883
1883
  if (options2.weeks) totalSeconds += options2.weeks * 604800;
1884
1884
  const totalMs = totalSeconds * 1e3;
1885
- await new Promise((resolve8) => setTimeout(resolve8, totalMs));
1885
+ await new Promise((resolve10) => setTimeout(resolve10, totalMs));
1886
1886
  store.set(key, { wait_until: new Date(Date.now() + totalMs).toISOString() });
1887
1887
  },
1888
1888
  async waitUntil(key, date) {
@@ -1890,7 +1890,7 @@ function createStepHelper(options) {
1890
1890
  if (cached) return;
1891
1891
  const now = Date.now();
1892
1892
  const waitMs = Math.max(0, date.getTime() - now);
1893
- await new Promise((resolve8) => setTimeout(resolve8, waitMs));
1893
+ await new Promise((resolve10) => setTimeout(resolve10, waitMs));
1894
1894
  store.set(key, { wait_until: date.toISOString() });
1895
1895
  },
1896
1896
  // eslint-disable-next-line @typescript-eslint/require-await -- stub implementation
@@ -4530,7 +4530,7 @@ function createOrchestratorStepHelper(orchestratorClient, cachedSteps, execCtx,
4530
4530
  });
4531
4531
  const waitThreshold = Number(process.env["POLOS_WAIT_THRESHOLD_SECONDS"] ?? "10");
4532
4532
  if (totalSeconds <= waitThreshold) {
4533
- await new Promise((resolve8) => setTimeout(resolve8, totalSeconds * 1e3));
4533
+ await new Promise((resolve10) => setTimeout(resolve10, totalSeconds * 1e3));
4534
4534
  await saveStepOutput(key, { wait_until: waitUntil.toISOString() });
4535
4535
  return;
4536
4536
  }
@@ -4566,7 +4566,7 @@ function createOrchestratorStepHelper(orchestratorClient, cachedSteps, execCtx,
4566
4566
  });
4567
4567
  const waitThreshold = Number(process.env["POLOS_WAIT_THRESHOLD_SECONDS"] ?? "10");
4568
4568
  if (waitSeconds <= waitThreshold) {
4569
- await new Promise((resolve8) => setTimeout(resolve8, waitSeconds * 1e3));
4569
+ await new Promise((resolve10) => setTimeout(resolve10, waitSeconds * 1e3));
4570
4570
  await saveStepOutput(key, { wait_until: date.toISOString() });
4571
4571
  return;
4572
4572
  }
@@ -5319,7 +5319,7 @@ var DEFAULT_CONTAINER_WORKDIR = "/workspace";
5319
5319
  var DEFAULT_TIMEOUT_SECONDS = 300;
5320
5320
  var DEFAULT_MAX_OUTPUT_CHARS = 1e5;
5321
5321
  function spawnCommand(command, args, options) {
5322
- return new Promise((resolve8, reject) => {
5322
+ return new Promise((resolve10, reject) => {
5323
5323
  let settled = false;
5324
5324
  const settle = (fn) => {
5325
5325
  if (!settled) {
@@ -5352,13 +5352,13 @@ function spawnCommand(command, args, options) {
5352
5352
  clearTimeout(timer);
5353
5353
  settle(() => {
5354
5354
  if (killed) {
5355
- resolve8({
5355
+ resolve10({
5356
5356
  exitCode: 137,
5357
5357
  stdout,
5358
5358
  stderr: stderr + "\n[Process killed: timeout exceeded]"
5359
5359
  });
5360
5360
  } else {
5361
- resolve8({ exitCode: code ?? 1, stdout, stderr });
5361
+ resolve10({ exitCode: code ?? 1, stdout, stderr });
5362
5362
  }
5363
5363
  });
5364
5364
  });
@@ -5575,7 +5575,7 @@ var DockerEnvironment = class {
5575
5575
  var DEFAULT_TIMEOUT_SECONDS2 = 300;
5576
5576
  var DEFAULT_MAX_OUTPUT_CHARS2 = 1e5;
5577
5577
  function spawnLocal(command, options) {
5578
- return new Promise((resolve8, reject) => {
5578
+ return new Promise((resolve10, reject) => {
5579
5579
  let settled = false;
5580
5580
  const settle = (fn) => {
5581
5581
  if (!settled) {
@@ -5612,13 +5612,13 @@ function spawnLocal(command, options) {
5612
5612
  clearTimeout(timer);
5613
5613
  settle(() => {
5614
5614
  if (killed) {
5615
- resolve8({
5615
+ resolve10({
5616
5616
  exitCode: 137,
5617
5617
  stdout,
5618
5618
  stderr: stderr + "\n[Process killed: timeout exceeded]"
5619
5619
  });
5620
5620
  } else {
5621
- resolve8({ exitCode: code ?? 1, stdout, stderr });
5621
+ resolve10({ exitCode: code ?? 1, stdout, stderr });
5622
5622
  }
5623
5623
  });
5624
5624
  });
@@ -6026,8 +6026,8 @@ var SandboxManager = class {
6026
6026
  }
6027
6027
  let resolveLock;
6028
6028
  let rejectLock;
6029
- const lockPromise = new Promise((resolve8, reject) => {
6030
- resolveLock = resolve8;
6029
+ const lockPromise = new Promise((resolve10, reject) => {
6030
+ resolveLock = resolve10;
6031
6031
  rejectLock = reject;
6032
6032
  });
6033
6033
  this.sessionCreationLocks.set(ctx.sessionId, lockPromise);
@@ -6219,7 +6219,7 @@ var SandboxManager = class {
6219
6219
  }
6220
6220
  };
6221
6221
  function spawnSimple(command, args) {
6222
- return new Promise((resolve8, reject) => {
6222
+ return new Promise((resolve10, reject) => {
6223
6223
  const proc = child_process.spawn(command, args, { stdio: ["pipe", "pipe", "pipe"] });
6224
6224
  let stdout = "";
6225
6225
  let stderr = "";
@@ -6230,7 +6230,7 @@ function spawnSimple(command, args) {
6230
6230
  stderr += data.toString();
6231
6231
  });
6232
6232
  proc.on("close", (code) => {
6233
- resolve8({ exitCode: code ?? 1, stdout, stderr });
6233
+ resolve10({ exitCode: code ?? 1, stdout, stderr });
6234
6234
  });
6235
6235
  proc.on("error", reject);
6236
6236
  });
@@ -6365,10 +6365,10 @@ var Worker = class {
6365
6365
  process.on("SIGINT", signalHandler);
6366
6366
  process.on("SIGTERM", signalHandler);
6367
6367
  this.signalHandler = signalHandler;
6368
- await new Promise((resolve8) => {
6368
+ await new Promise((resolve10) => {
6369
6369
  const checkState = () => {
6370
6370
  if (this.state === "stopping" || this.state === "stopped") {
6371
- resolve8();
6371
+ resolve10();
6372
6372
  } else {
6373
6373
  setTimeout(checkState, 100);
6374
6374
  }
@@ -6402,7 +6402,7 @@ var Worker = class {
6402
6402
  const waitTimeout = 3e4;
6403
6403
  const waitStart = Date.now();
6404
6404
  while (this.activeExecutions.size > 0 && Date.now() - waitStart < waitTimeout) {
6405
- await new Promise((resolve8) => setTimeout(resolve8, 100));
6405
+ await new Promise((resolve10) => setTimeout(resolve10, 100));
6406
6406
  }
6407
6407
  if (this.activeExecutions.size > 0) {
6408
6408
  logger9.warn(`${String(this.activeExecutions.size)} executions did not complete in time`);
@@ -7507,7 +7507,7 @@ function createReadTool(getEnv, pathConfig) {
7507
7507
  }
7508
7508
  );
7509
7509
  }
7510
- function createWriteTool(getEnv, approval) {
7510
+ function createWriteTool(getEnv, config) {
7511
7511
  return defineTool(
7512
7512
  {
7513
7513
  id: "write",
@@ -7516,16 +7516,23 @@ function createWriteTool(getEnv, approval) {
7516
7516
  path: zod.z.string().describe("Path to the file to write"),
7517
7517
  content: zod.z.string().describe("Content to write to the file")
7518
7518
  }),
7519
- approval
7519
+ // Only use blanket approval if explicitly set to 'always'
7520
+ approval: config?.approval === "always" ? "always" : void 0
7520
7521
  },
7521
- async (_ctx, input) => {
7522
+ async (ctx, input) => {
7522
7523
  const env = await getEnv();
7524
+ if (!config?.approval && config?.pathConfig?.pathRestriction) {
7525
+ const resolved = path.resolve(env.getCwd(), input.path);
7526
+ if (!isPathAllowed(resolved, config.pathConfig.pathRestriction)) {
7527
+ await requirePathApproval(ctx, "write", resolved, config.pathConfig.pathRestriction);
7528
+ }
7529
+ }
7523
7530
  await env.writeFile(input.path, input.content);
7524
7531
  return { success: true, path: input.path };
7525
7532
  }
7526
7533
  );
7527
7534
  }
7528
- function createEditTool(getEnv, approval) {
7535
+ function createEditTool(getEnv, config) {
7529
7536
  return defineTool(
7530
7537
  {
7531
7538
  id: "edit",
@@ -7535,10 +7542,17 @@ function createEditTool(getEnv, approval) {
7535
7542
  old_text: zod.z.string().describe("Exact text to find and replace"),
7536
7543
  new_text: zod.z.string().describe("Text to replace the old_text with")
7537
7544
  }),
7538
- approval
7545
+ // Only use blanket approval if explicitly set to 'always'
7546
+ approval: config?.approval === "always" ? "always" : void 0
7539
7547
  },
7540
- async (_ctx, input) => {
7548
+ async (ctx, input) => {
7541
7549
  const env = await getEnv();
7550
+ if (!config?.approval && config?.pathConfig?.pathRestriction) {
7551
+ const resolved = path.resolve(env.getCwd(), input.path);
7552
+ if (!isPathAllowed(resolved, config.pathConfig.pathRestriction)) {
7553
+ await requirePathApproval(ctx, "edit", resolved, config.pathConfig.pathRestriction);
7554
+ }
7555
+ }
7542
7556
  const content = await env.readFile(input.path);
7543
7557
  if (!content.includes(input.old_text)) {
7544
7558
  throw new Error(
@@ -7643,16 +7657,17 @@ function sandboxTools(config) {
7643
7657
  throw new Error("E2B environment is not yet implemented.");
7644
7658
  }
7645
7659
  const effectiveExecConfig = envType === "local" && !config?.exec?.security ? { ...config?.exec, security: "approval-always" } : config?.exec;
7646
- const fileApproval = config?.fileApproval ?? (envType === "local" ? "always" : void 0);
7647
7660
  const pathConfig = config?.local?.pathRestriction ? { pathRestriction: config.local.pathRestriction } : void 0;
7661
+ const fileApproval = config?.fileApproval;
7662
+ const writeEditConfig = fileApproval ? { approval: fileApproval } : pathConfig ? { pathConfig } : void 0;
7648
7663
  const include = new Set(
7649
7664
  config?.tools ?? ["exec", "read", "write", "edit", "glob", "grep"]
7650
7665
  );
7651
7666
  const tools = [];
7652
7667
  if (include.has("exec")) tools.push(createExecTool(getEnv, effectiveExecConfig));
7653
7668
  if (include.has("read")) tools.push(createReadTool(getEnv, pathConfig));
7654
- if (include.has("write")) tools.push(createWriteTool(getEnv, fileApproval));
7655
- if (include.has("edit")) tools.push(createEditTool(getEnv, fileApproval));
7669
+ if (include.has("write")) tools.push(createWriteTool(getEnv, writeEditConfig));
7670
+ if (include.has("edit")) tools.push(createEditTool(getEnv, writeEditConfig));
7656
7671
  if (include.has("glob")) tools.push(createGlobTool(getEnv, pathConfig));
7657
7672
  if (include.has("grep")) tools.push(createGrepTool(getEnv, pathConfig));
7658
7673
  return tools;