@lucid-agents/taskmarket 1.46.0 → 1.48.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.
Files changed (25) hide show
  1. package/dist/agent-compatibility.json +1 -1
  2. package/dist/{api-56KWZFR4.js → api-2PFUP432.js} +2 -2
  3. package/dist/{channels-YKCZU2Q7.js → channels-Z6VN7FXP.js} +4 -4
  4. package/dist/{chunk-66HELSIU.js → chunk-AB3BDUMS.js} +3 -3
  5. package/dist/{chunk-7KZOHF7R.js → chunk-DKBI3SE3.js} +1 -1
  6. package/dist/{chunk-Y3B7POF2.js → chunk-GPKAJ7QH.js} +41 -5
  7. package/dist/{chunk-HFG7TSVD.js → chunk-JXBWKGXC.js} +10996 -10673
  8. package/dist/{chunk-MMODVSSS.js → chunk-KTT6PSHQ.js} +1 -1
  9. package/dist/{chunk-3MITXF2F.js → chunk-QRNIBDYX.js} +3 -3
  10. package/dist/{chunk-AS3N5L25.js → chunk-SV6LNVI5.js} +2 -2
  11. package/dist/{chunk-MUFEOBRQ.js → chunk-UJ3FRWUU.js} +7 -13
  12. package/dist/{chunk-64NUUQBC.js → chunk-VENFZBAZ.js} +1 -1
  13. package/dist/{chunk-DPJIDICA.js → chunk-VYYJ7FUB.js} +3 -3
  14. package/dist/{chunk-E3J2J3PZ.js → chunk-WPJRL4F7.js} +8 -8
  15. package/dist/{chunk-O5C2CWWL.js → chunk-YAUYTYQI.js} +5 -5
  16. package/dist/{doctor-TA3AZMPJ.js → doctor-6ASEDCCF.js} +8 -8
  17. package/dist/index.js +1141 -626
  18. package/dist/{launch-2RINYQTU.js → launch-JVXJSXJF.js} +11 -11
  19. package/dist/pi-extensions/xgate.cjs +657 -215
  20. package/dist/{read-auth-FFCZKAFN.js → read-auth-OQ3VVA4V.js} +3 -3
  21. package/dist/{reconcile-O6LVP2Z3.js → reconcile-TJ2VXC6R.js} +4 -4
  22. package/dist/{status-FRMTSDIG.js → status-LU7AKAKJ.js} +8 -8
  23. package/dist/{sync-pull-OUXRL6A2.js → sync-pull-52G7XZZT.js} +4 -4
  24. package/dist/{task-access-grants-WV3HVN5V.js → task-access-grants-HUYBGG5E.js} +2 -2
  25. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  {
2
- "taskmarket": "1.46.0",
2
+ "taskmarket": "1.48.0",
3
3
  "manifestVersion": 1,
4
4
  "pi": {
5
5
  "package": "@earendil-works/pi-coding-agent",
@@ -14,8 +14,8 @@ import {
14
14
  parseFailureBody,
15
15
  readFailureBody,
16
16
  withErrorContext
17
- } from "./chunk-MUFEOBRQ.js";
18
- import "./chunk-HFG7TSVD.js";
17
+ } from "./chunk-UJ3FRWUU.js";
18
+ import "./chunk-JXBWKGXC.js";
19
19
  import "./chunk-S7SJMJ2I.js";
20
20
  export {
21
21
  ApiError,
@@ -10,10 +10,10 @@ import {
10
10
  selectRail,
11
11
  uncertainPurchases,
12
12
  withdrawalHatch
13
- } from "./chunk-3MITXF2F.js";
14
- import "./chunk-Y3B7POF2.js";
15
- import "./chunk-MUFEOBRQ.js";
16
- import "./chunk-HFG7TSVD.js";
13
+ } from "./chunk-QRNIBDYX.js";
14
+ import "./chunk-GPKAJ7QH.js";
15
+ import "./chunk-UJ3FRWUU.js";
16
+ import "./chunk-JXBWKGXC.js";
17
17
  import "./chunk-YM4S6IE4.js";
18
18
  import "./chunk-XJOB4NMV.js";
19
19
  import "./chunk-S7SJMJ2I.js";
@@ -8,7 +8,7 @@ import {
8
8
  unsafeHostPath,
9
9
  withFileLock,
10
10
  writeAtomic
11
- } from "./chunk-64NUUQBC.js";
11
+ } from "./chunk-VENFZBAZ.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-DPJIDICA.js";
19
+ } from "./chunk-VYYJ7FUB.js";
20
20
  import {
21
21
  getTaskmarketHome
22
- } from "./chunk-HFG7TSVD.js";
22
+ } from "./chunk-JXBWKGXC.js";
23
23
  import {
24
24
  AgentLaunchError
25
25
  } from "./chunk-YM4S6IE4.js";
@@ -2,7 +2,7 @@ import { createRequire as __tmCreateRequire } from 'node:module'; import { fileU
2
2
  import {
3
3
  TASK_ACCESS_GRANT_HEADER,
4
4
  getTaskmarketHome
5
- } from "./chunk-HFG7TSVD.js";
5
+ } from "./chunk-JXBWKGXC.js";
6
6
 
7
7
  // src/lib/task-access-grants.ts
8
8
  import { promises as fs } from "fs";
@@ -11,7 +11,7 @@ import {
11
11
  getTaskmarketHome,
12
12
  mppAttributionMemo,
13
13
  parseMppChallenge
14
- } from "./chunk-HFG7TSVD.js";
14
+ } from "./chunk-JXBWKGXC.js";
15
15
 
16
16
  // ../../packages/x402-payer/dist/api.js
17
17
  var X402_PAYER_API_VERSION = 1;
@@ -4113,7 +4113,7 @@ function firstPartyAuthorization(input) {
4113
4113
  windowStartedAt: new Date(now.getTime() - spendWindow.seconds * 1e3).toISOString()
4114
4114
  };
4115
4115
  }
4116
- function selectX402Payment(input) {
4116
+ async function selectX402Payment(input) {
4117
4117
  const offered = input.firstParty ? [
4118
4118
  ...input.rails.filter((rail) => rail.firstPartyOnly === true),
4119
4119
  ...input.rails.filter((rail) => rail.firstPartyOnly !== true)
@@ -4200,7 +4200,20 @@ function selectX402Payment(input) {
4200
4200
  continue;
4201
4201
  }
4202
4202
  }
4203
- authorized.sort((left, right) => right.authorization.rule.priority - left.authorization.rule.priority || left.paymentIndex - right.paymentIndex || left.index - right.index);
4203
+ const bestPriority = authorized.reduce((best, option) => Math.max(best, option.authorization.rule.priority), Number.NEGATIVE_INFINITY);
4204
+ const top = authorized.filter((option) => option.authorization.rule.priority === bestPriority);
4205
+ const affordable = /* @__PURE__ */ new Map();
4206
+ if (top.length > 1 && input.canAfford) {
4207
+ for (const option of top) {
4208
+ affordable.set(option, option.rail.canAfford ? await input.canAfford(option).catch(() => true) : true);
4209
+ }
4210
+ }
4211
+ const funded = (option) => affordable.get(option) === false ? 1 : 0;
4212
+ top.sort((left, right) => {
4213
+ const cost = BigInt(left.maxAmount) - BigInt(right.maxAmount);
4214
+ return funded(left) - funded(right) || (cost < 0n ? -1 : cost > 0n ? 1 : 0) || left.paymentIndex - right.paymentIndex || left.index - right.index;
4215
+ });
4216
+ authorized.splice(0, authorized.length, ...top);
4204
4217
  if (authorized[0])
4205
4218
  return authorized[0];
4206
4219
  const denied = new X402PayError("No advertised x402 payment option is authorized by policy", {
@@ -4523,7 +4536,8 @@ async function runX402Exchange(runtime, input, options, context) {
4523
4536
  throw fail("challenge_invalid", protocol === "mpp" ? "The response carries no Payment challenge" : "Invalid x402 payment challenge", { status: 402 });
4524
4537
  }
4525
4538
  }
4526
- const selection = selectX402Payment({
4539
+ let payerAddress;
4540
+ const selection = await selectX402Payment({
4527
4541
  rails,
4528
4542
  paymentRequired,
4529
4543
  policy,
@@ -4533,6 +4547,11 @@ async function runX402Exchange(runtime, input, options, context) {
4533
4547
  invocationId,
4534
4548
  now: runtime.now(),
4535
4549
  firstParty,
4550
+ // The wallet is asked only when the policy leaves several options of equal standing.
4551
+ canAfford: async ({ requirement: requirement2, rail: rail2 }) => {
4552
+ payerAddress ??= getAccount().then((account2) => account2.address);
4553
+ return await rail2.canAfford?.({ requirement: requirement2, payer: await payerAddress, policy, signal }) ?? true;
4554
+ },
4536
4555
  ...allocation ? {
4537
4556
  allocation: {
4538
4557
  allocationId: allocation.id,
@@ -7710,6 +7729,7 @@ var FEE_UNITS_PER_BASE_UNIT = 10n ** 12n;
7710
7729
  var SPONSORED_MIN_REMAINING_SECONDS = 15;
7711
7730
  var VALIDITY_SECONDS = 25;
7712
7731
  var MAX_LOG_RANGE = 100000n;
7732
+ var UNSPENT_CONFIRMATION_BLOCKS = 30n;
7713
7733
  var MAX_LOG_RANGES = 16;
7714
7734
  var AUTHORIZATION_KIND = "tempo-transfer-with-memo";
7715
7735
  var TRANSFER_WITH_MEMO = parseAbiItem2("event TransferWithMemo(address indexed from, address indexed to, uint256 amount, bytes32 indexed memo)");
@@ -7855,6 +7875,16 @@ function createMppTempoChargeRail(options = {}) {
7855
7875
  const charge = readCharge(requirement);
7856
7876
  return { maxAmount: (charge.amount + (charge.sponsored ? 0n : feeUnits)).toString() };
7857
7877
  },
7878
+ async canAfford({ requirement, payer, policy }) {
7879
+ const charge = readCharge(requirement);
7880
+ try {
7881
+ const chain = await reader(requirement.network, policy);
7882
+ const balance = await chain.tokenBalance(charge.token, getAddress8(payer));
7883
+ return balance >= charge.amount + (charge.sponsored ? 0n : feeUnits);
7884
+ } catch {
7885
+ return true;
7886
+ }
7887
+ },
7858
7888
  feeTerms(requirement) {
7859
7889
  const charge = readCharge(requirement);
7860
7890
  return {
@@ -8021,6 +8051,9 @@ function createMppTempoChargeRail(options = {}) {
8021
8051
  }
8022
8052
  end = low;
8023
8053
  }
8054
+ const confirmed = end + UNSPENT_CONFIRMATION_BLOCKS;
8055
+ if (past)
8056
+ end = confirmed < latest.number ? confirmed : latest.number;
8024
8057
  let from = start;
8025
8058
  for (let range = 0; from <= end; range += 1) {
8026
8059
  if (range === MAX_LOG_RANGES)
@@ -8043,7 +8076,10 @@ function createMppTempoChargeRail(options = {}) {
8043
8076
  };
8044
8077
  from = to + 1n;
8045
8078
  }
8046
- if (!past || !data.sponsored && data.txHash === null)
8079
+ if (!past || !data.sponsored && data.txHash === null || end < confirmed)
8080
+ return { outcome: "pending" };
8081
+ const after = await chain.latestBlock();
8082
+ if (after.number < end || after.number < latest.number || after.timestamp <= data.validBefore)
8047
8083
  return { outcome: "pending" };
8048
8084
  return { outcome: "unspent" };
8049
8085
  } catch (error) {