@dvmkit/dvm-cli 0.9.1 → 0.9.2

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.
@@ -1841,20 +1841,24 @@ async function abandonPendingSubmission(args) {
1841
1841
  await withWalletLock(() => {
1842
1842
  const wallet = loadAgentWallet();
1843
1843
  if (!wallet) return;
1844
- const submission = wallet.pending_submissions.find((s) => s.request_id === args.requestId);
1845
- const shippedKeys = new Set(submission?.output_proofs.map((p) => `${p.secret}:${p.C}`) ?? []);
1846
- const next = {
1847
- ...wallet,
1848
- proofs: wallet.proofs.map(
1849
- (p) => shippedKeys.has(`${p.secret}:${p.C}`) && p.status === "in_flight" ? { ...p, status: "valid", in_flight_until_ms: void 0 } : p
1850
- ),
1851
- pending_submissions: wallet.pending_submissions.filter(
1852
- (s) => s.request_id !== args.requestId
1853
- )
1854
- };
1855
- saveAgentWallet(next);
1844
+ saveAgentWallet(abandonSubmissionInWallet(wallet, args));
1856
1845
  });
1857
1846
  }
1847
+ function abandonSubmissionInWallet(wallet, args) {
1848
+ const submission = wallet.pending_submissions.find((s) => s.request_id === args.requestId);
1849
+ const shippedKeys = new Set(submission?.output_proofs.map((p) => `${p.secret}:${p.C}`) ?? []);
1850
+ const walletKeys = new Set(wallet.proofs.map((p) => `${p.secret}:${p.C}`));
1851
+ const retain = args.preserveRecovery && [...shippedKeys].some((key) => !walletKeys.has(key));
1852
+ return {
1853
+ ...wallet,
1854
+ proofs: wallet.proofs.map(
1855
+ (p) => shippedKeys.has(`${p.secret}:${p.C}`) && p.status === "in_flight" ? { ...p, status: "valid", in_flight_until_ms: void 0 } : p
1856
+ ),
1857
+ pending_submissions: retain ? wallet.pending_submissions.map(
1858
+ (s) => s.request_id === args.requestId ? { ...s, context: void 0 } : s
1859
+ ) : wallet.pending_submissions.filter((s) => s.request_id !== args.requestId)
1860
+ };
1861
+ }
1858
1862
  async function markPendingSubmissionUnresolved(args) {
1859
1863
  await withWalletLock(() => {
1860
1864
  const wallet = loadAgentWallet();
@@ -3300,21 +3304,21 @@ async function fundOverCashu(args, fundId) {
3300
3304
  } catch (err) {
3301
3305
  const required = boundRail(err);
3302
3306
  if (required) {
3303
- await abandonPendingSubmission({ requestId: prepared.requestId }).catch(() => void 0);
3307
+ await abandonPendingSubmission({ requestId: prepared.requestId, preserveRecovery: true });
3304
3308
  return {
3305
3309
  ...base,
3306
3310
  status: "unavailable",
3307
3311
  requiredRail: required,
3308
- display: `This credit was opened over ${required}, so an ecash top-up can't be added to it.`
3312
+ display: `This credit was opened over ${required}, so an ecash top-up can't be added to it. The prepared ecash remains tracked for recovery.`
3309
3313
  };
3310
3314
  }
3311
3315
  if (err instanceof DvmError && CREDIT_PERMANENT_REFUSALS.has(err.code)) {
3312
- await abandonPendingSubmission({ requestId: prepared.requestId }).catch(() => void 0);
3316
+ await abandonPendingSubmission({ requestId: prepared.requestId, preserveRecovery: true });
3313
3317
  return {
3314
3318
  ...base,
3315
3319
  status: "refused",
3316
3320
  error: err,
3317
- display: `The DVM refused the funding (${err.code}) \u2014 the ${String(prepared.totalSats)} sats spend was dropped. ${err.message}`,
3321
+ display: `The DVM refused the funding (${err.code}). The ${String(prepared.totalSats)} sats of prepared ecash remain tracked for recovery. ${err.message}`,
3318
3322
  hint: err.hint
3319
3323
  };
3320
3324
  }
@@ -5508,6 +5512,7 @@ export {
5508
5512
  commitAgentSpend,
5509
5513
  correctPendingFundAmount,
5510
5514
  abandonPendingSubmission,
5515
+ abandonSubmissionInWallet,
5511
5516
  markPendingSubmissionUnresolved,
5512
5517
  withAcceptedUnresolved,
5513
5518
  fundCredit,
package/dist/dvm.js CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  DEFAULT_RESERVE_LOCKTIME_SECONDS,
15
15
  NWC_FUNDING_FLOAT_ROLE,
16
16
  abandonPendingSubmission,
17
+ abandonSubmissionInWallet,
17
18
  addPayment,
18
19
  assertFloatBudget,
19
20
  automaticCreditBoundRail,
@@ -90,7 +91,7 @@ import {
90
91
  unrecordedFloatBudgetWarning,
91
92
  updateJob,
92
93
  withAcceptedUnresolved
93
- } from "./chunk-Y3X74XH2.js";
94
+ } from "./chunk-MVVKMKWR.js";
94
95
  import {
95
96
  connectedTempoAccount,
96
97
  generateTempoKey,
@@ -11256,7 +11257,13 @@ function applyOutcome(wallet, outcome, now) {
11256
11257
  recent_spends: [...dropped.recent_spends, recentSpend].slice(-RECENT_SPENDS_CAP)
11257
11258
  };
11258
11259
  }
11259
- if (outcome.kind === "abandoned" || outcome.kind === "pruned") {
11260
+ if (outcome.kind === "abandoned") {
11261
+ return abandonSubmissionInWallet(wallet, {
11262
+ requestId: outcome.entry.request_id,
11263
+ preserveRecovery: true
11264
+ });
11265
+ }
11266
+ if (outcome.kind === "pruned") {
11260
11267
  return drop();
11261
11268
  }
11262
11269
  if (outcome.kind === "swap_restored") {
@@ -11867,7 +11874,7 @@ async function tryAgentWalletMidJobPayment(args) {
11867
11874
  });
11868
11875
  } catch (err) {
11869
11876
  if (err instanceof DvmError && err.code === "payment_invalid") {
11870
- await abandonPendingSubmission({ requestId: prepared.requestId });
11877
+ await abandonPendingSubmission({ requestId: prepared.requestId, preserveRecovery: true });
11871
11878
  }
11872
11879
  throw err;
11873
11880
  }
@@ -16714,6 +16721,14 @@ async function runCreditFund(dvm, opts) {
16714
16721
  });
16715
16722
  const configPin = effectiveFundingRail(config?.credit, endpoint, attestedIdentity);
16716
16723
  const boundRail = pinnedRail(stored, opts.creditId);
16724
+ if (!pending4 && !signedPending && flagRail && boundRail && flagRail !== boundRail) {
16725
+ throw new DvmError(
16726
+ "credit_rail_conflict",
16727
+ `This credit was opened over ${boundRail}, so it cannot be topped up over ${flagRail}. Nothing was paid.`,
16728
+ `Use --rail ${boundRail} for this credit, or supply a new --credit-id to open a separate credit over ${flagRail}.`,
16729
+ { credit_id: stored?.creditId, credit_rail: boundRail, requested_rail: flagRail }
16730
+ );
16731
+ }
16717
16732
  const railSource = flagRail ? "flag" : boundRail ? "credit_bound" : configPin.source === "per_dvm" || configPin.source === "global" ? configPin.source : void 0;
16718
16733
  const rail = pending4?.rail ?? flagRail ?? boundRail ?? configPin.rail;
16719
16734
  let amountMicro = pending4?.amountMicro ?? signedPending?.amountMicro ?? explicitMicro ?? (targetJobs === void 0 ? defaultFundMicro(stored) : void 0);
@@ -23294,7 +23309,7 @@ async function settleCreditAfterJob(args) {
23294
23309
  }
23295
23310
  }
23296
23311
  if (args.allowTopup !== false) {
23297
- const refill = args.refillPocket ?? (await import("./pocket-refill-DGA7UD7L.js")).refillPocketIfLow;
23312
+ const refill = args.refillPocket ?? (await import("./pocket-refill-J3BME4O3.js")).refillPocketIfLow;
23298
23313
  await refill({ human: args.human }).catch(() => void 0);
23299
23314
  }
23300
23315
  }
@@ -13,7 +13,7 @@ import {
13
13
  recordFloatSpend,
14
14
  resolveFundMint,
15
15
  sweepPendingMints
16
- } from "./chunk-Y3X74XH2.js";
16
+ } from "./chunk-MVVKMKWR.js";
17
17
  import "./chunk-BCDMVIPI.js";
18
18
  import {
19
19
  info,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvmkit/dvm-cli",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "Command-line client and agent skill for Digital Vending Machines: pay-per-use HTTPS services AI agents can find, pay, and call with no account or API key",
5
5
  "author": "DVM Technologies Ltd",
6
6
  "keywords": [