@lucid-agents/taskmarket 1.20.2 → 1.21.0

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,11 +1,11 @@
1
1
  import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
2
2
  import {
3
3
  x402FeePost
4
- } from "./chunk-WUSEHQHR.js";
4
+ } from "./chunk-TAMXCFLT.js";
5
5
  import {
6
6
  createWalletAccountFromKeystore,
7
7
  signMessage
8
- } from "./chunk-AT2VG32A.js";
8
+ } from "./chunk-HE2N4GEO.js";
9
9
  import {
10
10
  READ_AUTH_ADDRESS_HEADER,
11
11
  READ_AUTH_SIGNATURE_HEADER,
@@ -19,7 +19,7 @@ import {
19
19
  getTaskmarketHome,
20
20
  isRecordingPendingResponse,
21
21
  loadKeystore
22
- } from "./chunk-2JTB3UFM.js";
22
+ } from "./chunk-3IIVNF5F.js";
23
23
 
24
24
  // src/lib/read-auth.ts
25
25
  async function signReadAuth() {
@@ -11,7 +11,7 @@ import {
11
11
  loadKeystore,
12
12
  mppAttributionMemo,
13
13
  parseMppChallenge
14
- } from "./chunk-2JTB3UFM.js";
14
+ } from "./chunk-3IIVNF5F.js";
15
15
 
16
16
  // ../../packages/x402-payer/dist/api.js
17
17
  var X402_PAYER_API_VERSION = 1;
@@ -11,12 +11,12 @@ import {
11
11
  listX402Payments,
12
12
  loadX402Policy,
13
13
  rpcUrlForNetwork
14
- } from "./chunk-AT2VG32A.js";
14
+ } from "./chunk-HE2N4GEO.js";
15
15
  import {
16
16
  getTaskmarketHome,
17
17
  keystoreExists,
18
18
  loadKeystore
19
- } from "./chunk-2JTB3UFM.js";
19
+ } from "./chunk-3IIVNF5F.js";
20
20
  import {
21
21
  failureDetail,
22
22
  failureDetailOf,
@@ -16,7 +16,7 @@ import {
16
16
  readMppTempoChallenge,
17
17
  reconcileX402Payment,
18
18
  withX402FileLock
19
- } from "./chunk-AT2VG32A.js";
19
+ } from "./chunk-HE2N4GEO.js";
20
20
  import {
21
21
  ApiError,
22
22
  ComputeCreditBuyOutputSchema,
@@ -39,7 +39,7 @@ import {
39
39
  selectedNetwork,
40
40
  withChainId,
41
41
  withIdempotentWrite
42
- } from "./chunk-2JTB3UFM.js";
42
+ } from "./chunk-3IIVNF5F.js";
43
43
 
44
44
  // src/lib/x402-fee.ts
45
45
  import { randomUUID as randomUUID3 } from "crypto";
@@ -22,7 +22,7 @@ import {
22
22
  unresolvedCount,
23
23
  updateSyncState,
24
24
  uploadWorkspace
25
- } from "./chunk-6LKXMM4U.js";
25
+ } from "./chunk-ZU33L5X5.js";
26
26
  import {
27
27
  AgentLaunchError
28
28
  } from "./chunk-YM4S6IE4.js";
@@ -6,14 +6,14 @@ import {
6
6
  loadDeliverableRecord,
7
7
  readComputeView,
8
8
  taskStage
9
- } from "./chunk-F7ENDHGG.js";
9
+ } from "./chunk-ZZTCFKR3.js";
10
10
  import {
11
11
  activeClaim,
12
12
  captureProblem,
13
13
  killedSession,
14
14
  loadSyncState,
15
15
  orphanOf
16
- } from "./chunk-6LKXMM4U.js";
16
+ } from "./chunk-ZU33L5X5.js";
17
17
  import {
18
18
  allocationViews,
19
19
  channelView,
@@ -21,12 +21,12 @@ import {
21
21
  openAgentChannels,
22
22
  uncertainPurchases,
23
23
  withdrawalHatch
24
- } from "./chunk-5D4HN65V.js";
24
+ } from "./chunk-OCQKVV4A.js";
25
25
  import {
26
26
  SandboxListOutputSchema,
27
27
  apiUrl,
28
28
  selectedNetwork
29
- } from "./chunk-2JTB3UFM.js";
29
+ } from "./chunk-3IIVNF5F.js";
30
30
  import {
31
31
  AGENT_VIEW_VERSION,
32
32
  blockingPurchases,
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
2
2
  import {
3
3
  getTaskmarketHome
4
- } from "./chunk-2JTB3UFM.js";
4
+ } from "./chunk-3IIVNF5F.js";
5
5
  import {
6
6
  AgentLaunchError
7
7
  } from "./chunk-YM4S6IE4.js";
@@ -24413,7 +24413,7 @@ var SshSandboxBackend = class {
24413
24413
  }
24414
24414
  async ensure(signal) {
24415
24415
  if (this.conn && this.files && !this.conn.closed) {
24416
- this.touch();
24416
+ await this.keepAlive();
24417
24417
  return { conn: this.conn, files: this.files };
24418
24418
  }
24419
24419
  if (this.failure && Date.now() < this.failure.until)
@@ -24457,6 +24457,7 @@ var SshSandboxBackend = class {
24457
24457
  this.files = files;
24458
24458
  this.info = { label: `${this.user}@${endpoint.host} (${this.root})` };
24459
24459
  this.failure = void 0;
24460
+ this.lastHeartbeat = Date.now();
24460
24461
  this.log(`${this.dialed ? "Reconnected" : "Connected"} to the sandbox at ${endpoint.host}`);
24461
24462
  this.dialed = true;
24462
24463
  conn.onClose(() => {
@@ -24477,13 +24478,59 @@ var SshSandboxBackend = class {
24477
24478
  throw failure;
24478
24479
  }
24479
24480
  }
24480
- /** Tells the broker the sandbox is in use, at most once a minute, without waiting. */
24481
- touch() {
24481
+ get heartbeatIntervalMs() {
24482
+ return this.options.heartbeatIntervalMs ?? HEARTBEAT_INTERVAL_MS;
24483
+ }
24484
+ /**
24485
+ * Tells the broker the sandbox is in use, and waits for the answer. A refusal means the broker is
24486
+ * stopping the sandbox for inactivity, so the call fails instead of running on a machine that is
24487
+ * going away. Skipped when the last answer is under an interval old.
24488
+ */
24489
+ async keepAlive(force = false) {
24482
24490
  const heartbeat = this.options.connector.heartbeat;
24483
- if (!heartbeat || Date.now() - this.lastHeartbeat < HEARTBEAT_INTERVAL_MS)
24491
+ if (!heartbeat || !force && Date.now() - this.lastHeartbeat < this.heartbeatIntervalMs)
24484
24492
  return;
24493
+ try {
24494
+ await heartbeat.call(this.options.connector);
24495
+ } catch (error) {
24496
+ const message = `the sandbox could not be kept alive: ${error.message}`;
24497
+ this.log(message);
24498
+ throw new SandboxUnavailableError(message, { cause: error });
24499
+ }
24485
24500
  this.lastHeartbeat = Date.now();
24486
- heartbeat.call(this.options.connector).catch((error) => this.log(`Heartbeat failed: ${error.message}`));
24501
+ }
24502
+ /**
24503
+ * Runs a command while heartbeating every interval, so the idle stop never takes the sandbox
24504
+ * under it. A refused heartbeat kills the command and fails the call with the refusal.
24505
+ */
24506
+ async leased(signal, run) {
24507
+ const controller = new AbortController();
24508
+ const onAbort = () => controller.abort();
24509
+ if (signal?.aborted)
24510
+ controller.abort();
24511
+ else
24512
+ signal?.addEventListener("abort", onAbort, { once: true });
24513
+ let refusal;
24514
+ let beating = false;
24515
+ const timer = setInterval(() => {
24516
+ if (beating)
24517
+ return;
24518
+ beating = true;
24519
+ this.keepAlive(true).catch((error) => {
24520
+ refusal = error;
24521
+ controller.abort();
24522
+ }).finally(() => {
24523
+ beating = false;
24524
+ });
24525
+ }, this.heartbeatIntervalMs);
24526
+ try {
24527
+ return await run(controller.signal);
24528
+ } catch (error) {
24529
+ throw refusal ?? error;
24530
+ } finally {
24531
+ clearInterval(timer);
24532
+ signal?.removeEventListener("abort", onAbort);
24533
+ }
24487
24534
  }
24488
24535
  async close() {
24489
24536
  this.generation++;
@@ -24520,18 +24567,18 @@ var SshSandboxBackend = class {
24520
24567
  const unit = this.nextUnit();
24521
24568
  const stderr = [];
24522
24569
  let stderrBytes = 0;
24523
- const { exitCode } = await conn.stream(wrapInScope(command, this.root, unit), {
24570
+ const { exitCode } = await this.leased(signal, (leaseSignal) => conn.stream(wrapInScope(command, this.root, unit), {
24524
24571
  onData: onStdout,
24525
24572
  onStderr: (chunk) => {
24526
24573
  stderrBytes += chunk.length;
24527
24574
  if (stderrBytes <= 16 * 1024)
24528
24575
  stderr.push(chunk);
24529
24576
  },
24530
- signal,
24577
+ signal: leaseSignal,
24531
24578
  maxStreamBytes: this.maxStreamBytes,
24532
24579
  killCommand: stopScopeCommand(unit),
24533
24580
  untilClose: true
24534
- });
24581
+ }));
24535
24582
  return { exitCode, stderr: Buffer.concat(stderr).toString("utf8").trim().slice(0, 2e3) };
24536
24583
  }
24537
24584
  async glob(dir, pattern, options) {
@@ -24658,13 +24705,13 @@ var SshSandboxBackend = class {
24658
24705
  async exec(command, cwd, options) {
24659
24706
  const { conn } = await this.ensure(options.signal);
24660
24707
  const unit = this.nextUnit();
24661
- return conn.stream(wrapInScope(command, cwd, unit), {
24708
+ return this.leased(options.signal, (signal) => conn.stream(wrapInScope(command, cwd, unit), {
24662
24709
  onData: options.onData,
24663
- signal: options.signal,
24710
+ signal,
24664
24711
  timeout: options.timeout,
24665
24712
  maxStreamBytes: this.maxStreamBytes,
24666
24713
  killCommand: stopScopeCommand(unit)
24667
- });
24714
+ }));
24668
24715
  }
24669
24716
  };
24670
24717
 
@@ -8,7 +8,7 @@ import {
8
8
  unsafeHostPath,
9
9
  withFileLock,
10
10
  writeAtomic
11
- } from "./chunk-6LKXMM4U.js";
11
+ } from "./chunk-ZU33L5X5.js";
12
12
  import {
13
13
  buyComputeCredit,
14
14
  fetchComputePricing,
@@ -16,10 +16,10 @@ import {
16
16
  loadComputeCreditConfig,
17
17
  onComputeBalanceObserved,
18
18
  readComputeCreditStatus
19
- } from "./chunk-WUSEHQHR.js";
19
+ } from "./chunk-TAMXCFLT.js";
20
20
  import {
21
21
  getTaskmarketHome
22
- } from "./chunk-2JTB3UFM.js";
22
+ } from "./chunk-3IIVNF5F.js";
23
23
  import {
24
24
  burnRate,
25
25
  computeLow
@@ -6,26 +6,26 @@ import {
6
6
  } from "./chunk-4ZC6SH7H.js";
7
7
  import {
8
8
  listSandboxes
9
- } from "./chunk-D7U7SB2R.js";
10
- import "./chunk-F7ENDHGG.js";
11
- import "./chunk-6LKXMM4U.js";
12
- import "./chunk-WUSEHQHR.js";
9
+ } from "./chunk-VVAUDP3D.js";
10
+ import "./chunk-ZZTCFKR3.js";
11
+ import "./chunk-ZU33L5X5.js";
12
+ import "./chunk-TAMXCFLT.js";
13
13
  import {
14
14
  channelView,
15
15
  loadAgentPolicy,
16
16
  openAgentChannels
17
- } from "./chunk-5D4HN65V.js";
17
+ } from "./chunk-OCQKVV4A.js";
18
18
  import {
19
19
  getX402PolicyPath,
20
20
  loadX402Policy,
21
21
  rpcUrlForNetwork
22
- } from "./chunk-AT2VG32A.js";
22
+ } from "./chunk-HE2N4GEO.js";
23
23
  import {
24
24
  apiUrl,
25
25
  keystoreExists,
26
26
  loadKeystore,
27
27
  withChainId
28
- } from "./chunk-2JTB3UFM.js";
28
+ } from "./chunk-3IIVNF5F.js";
29
29
  import {
30
30
  AGENT_VIEW_VERSION
31
31
  } from "./chunk-XJOB4NMV.js";