@dvmkit/dvm-cli 0.7.0-rc.3 → 0.7.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.
@@ -1770,13 +1770,14 @@ async function correctPendingFundAmount(args) {
1770
1770
  const data = s.context.submit_body.data;
1771
1771
  const fund = data?.fund;
1772
1772
  if (!fund) return s;
1773
+ const { request_id: _requestId, ...rest } = data ?? {};
1773
1774
  return {
1774
1775
  ...s,
1775
1776
  context: {
1776
1777
  ...s.context,
1777
1778
  submit_body: {
1778
1779
  ...s.context.submit_body,
1779
- data: { ...data, fund: { ...fund, amount_micro: args.amountMicro } }
1780
+ data: { ...rest, fund: { ...fund, amount_micro: args.amountMicro } }
1780
1781
  }
1781
1782
  }
1782
1783
  };
package/dist/dvm.js CHANGED
@@ -88,7 +88,7 @@ import {
88
88
  unrecordedFloatBudgetWarning,
89
89
  updateJob,
90
90
  withAcceptedUnresolved
91
- } from "./chunk-BHJLMVO2.js";
91
+ } from "./chunk-7674LYNL.js";
92
92
  import {
93
93
  assertSupportedX402Network,
94
94
  connectedX402Payer,
@@ -10363,6 +10363,7 @@ async function correctFundAmount(entry, body) {
10363
10363
  const expected = valuation.micro;
10364
10364
  if (expected === fund.amount_micro) return { kind: "hold" };
10365
10365
  await correctPendingFundAmount({ requestId: entry.request_id, amountMicro: expected });
10366
+ const { request_id: _requestId, ...rest } = data;
10366
10367
  return {
10367
10368
  kind: "corrected",
10368
10369
  entry: {
@@ -10371,7 +10372,7 @@ async function correctFundAmount(entry, body) {
10371
10372
  ...ctx,
10372
10373
  submit_body: {
10373
10374
  ...ctx.submit_body,
10374
- data: { ...data, fund: { ...fund, amount_micro: expected } }
10375
+ data: { ...rest, fund: { ...fund, amount_micro: expected } }
10375
10376
  }
10376
10377
  }
10377
10378
  }
@@ -22975,7 +22976,7 @@ async function settleCreditAfterJob(args) {
22975
22976
  }
22976
22977
  }
22977
22978
  if (args.allowTopup !== false) {
22978
- const refill = args.refillPocket ?? (await import("./pocket-refill-BHNKMENF.js")).refillPocketIfLow;
22979
+ const refill = args.refillPocket ?? (await import("./pocket-refill-YY55GISB.js")).refillPocketIfLow;
22979
22980
  await refill({ human: args.human }).catch(() => void 0);
22980
22981
  }
22981
22982
  }
@@ -24007,6 +24008,7 @@ async function request(opts) {
24007
24008
  );
24008
24009
  let signing;
24009
24010
  let probePlan = { mode: "none" };
24011
+ let drawRequestId;
24010
24012
  if (opts.requestId && !providerInfo.auth?.includes(SIGNED_REQUEST_AUTH_ID)) {
24011
24013
  transport.close();
24012
24014
  throw new DvmError(
@@ -24073,7 +24075,15 @@ async function request(opts) {
24073
24075
  if (probePlan.mode === "draw" && opts.requestId) {
24074
24076
  probePlan = { ...probePlan, drawId: opts.requestId };
24075
24077
  }
24076
- const probeData = probePlan.mode === "draw" ? { ...unsignedData, credit_id: probePlan.creditId, draw_id: probePlan.drawId } : unsignedData;
24078
+ if (probePlan.mode === "draw" && submitCanCarryGeneratedRequestId({ opts, providerInfo, signing })) {
24079
+ drawRequestId = randomUUID4();
24080
+ }
24081
+ const probeData = probePlan.mode === "draw" ? {
24082
+ ...unsignedData,
24083
+ credit_id: probePlan.creditId,
24084
+ draw_id: probePlan.drawId,
24085
+ ...drawRequestId ? { request_id: drawRequestId } : {}
24086
+ } : unsignedData;
24077
24087
  data = signDvmRequestData(signer.privkey, probeData, authDomain);
24078
24088
  if (opts.human) info(`Signed as ${signer.pubkey}.`);
24079
24089
  if (opts.human && probePlan.mode === "draw") {
@@ -24101,9 +24111,10 @@ async function request(opts) {
24101
24111
  outputType: opts.outputType,
24102
24112
  bidMsats: budgetMsats
24103
24113
  });
24104
- if (opts.requestId) {
24114
+ let jobRequestId = opts.requestId ?? drawRequestId;
24115
+ if (jobRequestId) {
24105
24116
  persistRequestIntent({
24106
- requestId: opts.requestId,
24117
+ requestId: jobRequestId,
24107
24118
  transport,
24108
24119
  envelope,
24109
24120
  signing,
@@ -24136,11 +24147,12 @@ async function request(opts) {
24136
24147
  );
24137
24148
  } catch (err) {
24138
24149
  if (!isIdentityFailure(err)) throw err;
24150
+ const publicRequestId = opts.requestId ?? envelopeRequestId(env);
24139
24151
  throw recordIdentityFailure(err, {
24140
24152
  endpoint,
24141
24153
  ...dvmId ? { dvmId } : {},
24142
24154
  capability,
24143
- ...opts.requestId ? { publicRequestId: opts.requestId } : {},
24155
+ ...publicRequestId ? { publicRequestId } : {},
24144
24156
  ...probeRailEvidence(env)
24145
24157
  }).error;
24146
24158
  }
@@ -24153,6 +24165,10 @@ async function request(opts) {
24153
24165
  transport.close();
24154
24166
  throw requestOutcomeUnknown(opts.requestId, err);
24155
24167
  }
24168
+ if (drawRequestId && outcomeUnknownAfterSubmit(err)) {
24169
+ transport.close();
24170
+ throw requestOutcomeUnknown(drawRequestId, err);
24171
+ }
24156
24172
  if (opts.creditOnly) throw err;
24157
24173
  if (probePlan.mode !== "draw" || !signing || !(err instanceof DvmError)) throw err;
24158
24174
  const drawPlan = probePlan;
@@ -24179,6 +24195,7 @@ async function request(opts) {
24179
24195
  receipt = recovered.receipt;
24180
24196
  envelope = recovered.envelope;
24181
24197
  probePlan = recovered.plan;
24198
+ jobRequestId = recovered.requestId;
24182
24199
  }
24183
24200
  if (receipt.status === "payment-required") {
24184
24201
  const quotes = receipt.quotes ?? [];
@@ -24235,7 +24252,7 @@ async function request(opts) {
24235
24252
  dvmId,
24236
24253
  feedbackClaim: receipt.feedbackClaim,
24237
24254
  capability,
24238
- requestId: opts.requestId,
24255
+ requestId: jobRequestId,
24239
24256
  status: "submitted",
24240
24257
  submittedAt: Date.now(),
24241
24258
  policy,
@@ -24264,7 +24281,7 @@ async function request(opts) {
24264
24281
  } else {
24265
24282
  json({
24266
24283
  jobId: receipt.jobId,
24267
- ...requestIdOutputFields(opts),
24284
+ ...requestIdOutputFields(jobRequestId),
24268
24285
  ...transactionOutputFields(receipt),
24269
24286
  ...dvmIdentity(dvmId, capability),
24270
24287
  // mirror `dvm quote`'s post-defaults diagnostic on the
@@ -24318,7 +24335,7 @@ async function request(opts) {
24318
24335
  } else {
24319
24336
  json({
24320
24337
  jobId: receipt.jobId,
24321
- ...requestIdOutputFields(opts),
24338
+ ...requestIdOutputFields(jobRequestId),
24322
24339
  ...transactionOutputFields(receipt),
24323
24340
  ...dvmIdentity(dvmId, capability),
24324
24341
  summary: receipt.summary,
@@ -24393,7 +24410,7 @@ async function request(opts) {
24393
24410
  } else {
24394
24411
  json({
24395
24412
  jobId: receipt.jobId,
24396
- ...requestIdOutputFields(opts),
24413
+ ...requestIdOutputFields(jobRequestId),
24397
24414
  ...transactionOutputFields(receipt),
24398
24415
  ...dvmIdentity(dvmId, capability),
24399
24416
  messages: result.messages.map(serializeMessageForOutput),
@@ -24618,9 +24635,40 @@ async function recoverDrawProbe(err, args) {
24618
24635
  drawId: randomUUID4(),
24619
24636
  ...args.probePlan.source ? { source: args.probePlan.source } : {}
24620
24637
  };
24621
- const env = reSign({ credit_id: plan.creditId, draw_id: plan.drawId });
24622
- const receipt = await args.submitProbe(env);
24623
- return { done: false, receipt, envelope: env, plan };
24638
+ const requestId = submitCanCarryGeneratedRequestId({
24639
+ opts: args.opts,
24640
+ providerInfo: args.providerInfo,
24641
+ signing
24642
+ }) ? randomUUID4() : void 0;
24643
+ const env = reSign({
24644
+ credit_id: plan.creditId,
24645
+ draw_id: plan.drawId,
24646
+ ...requestId ? { request_id: requestId } : {}
24647
+ });
24648
+ if (requestId) {
24649
+ persistRequestIntent({
24650
+ requestId,
24651
+ transport: args.transport,
24652
+ envelope: env,
24653
+ signing,
24654
+ endpoint: args.endpoint,
24655
+ identity: args.identity,
24656
+ policy: args.policy,
24657
+ opts: args.opts,
24658
+ providerInfo: args.providerInfo
24659
+ });
24660
+ }
24661
+ let receipt;
24662
+ try {
24663
+ receipt = await args.submitProbe(env);
24664
+ } catch (retryErr) {
24665
+ if (requestId && outcomeUnknownAfterSubmit(retryErr)) {
24666
+ args.transport.close?.();
24667
+ throw requestOutcomeUnknown(requestId, retryErr);
24668
+ }
24669
+ throw retryErr;
24670
+ }
24671
+ return { done: false, receipt, envelope: env, plan, ...requestId ? { requestId } : {} };
24624
24672
  }
24625
24673
  if (err.code === "insufficient_credit") {
24626
24674
  if (args.probePlan.source === "implicit") {
@@ -24899,7 +24947,7 @@ async function handleAutoPayQuotes(transport, ref, envelope, jobId, deadlineMs,
24899
24947
  let railOpts = opts;
24900
24948
  let railSigning = creditCtx?.signing;
24901
24949
  let generatedRequestId;
24902
- if (railSigning && perCallSubmitCanCarryRecoveryRequestId({ plan, opts, providerInfo, signing: railSigning })) {
24950
+ if (plan.mode === "none" && railSigning && submitCanCarryGeneratedRequestId({ opts, providerInfo, signing: railSigning })) {
24903
24951
  generatedRequestId = randomUUID4();
24904
24952
  railSigning = {
24905
24953
  ...railSigning,
@@ -25142,7 +25190,7 @@ async function payWithTempo(args, credential) {
25142
25190
  } else {
25143
25191
  json({
25144
25192
  ...dvmFields,
25145
- ...requestIdOutputFields(opts),
25193
+ ...requestIdOutputFields(opts.requestId),
25146
25194
  status: "paying",
25147
25195
  rail: "tempo",
25148
25196
  account: account.address,
@@ -25267,7 +25315,7 @@ async function payWithTempo(args, credential) {
25267
25315
  } else {
25268
25316
  json({
25269
25317
  jobId: effectiveJobId,
25270
- ...requestIdOutputFields(opts),
25318
+ ...requestIdOutputFields(opts.requestId),
25271
25319
  ...transactionOutputFields(receipt),
25272
25320
  ...dvmFields,
25273
25321
  summary: receipt.summary,
@@ -25297,7 +25345,7 @@ async function payWithTempo(args, credential) {
25297
25345
  paymentFields: {
25298
25346
  paidWith: "tempo",
25299
25347
  account: account.address,
25300
- ...requestIdOutputFields(opts),
25348
+ ...requestIdOutputFields(opts.requestId),
25301
25349
  ...transactionOutputFields(receipt)
25302
25350
  },
25303
25351
  dvmFields,
@@ -25358,8 +25406,12 @@ function persistRequestIntent(args) {
25358
25406
  );
25359
25407
  }
25360
25408
  }
25361
- function perCallSubmitCanCarryRecoveryRequestId(args) {
25362
- return args.plan.mode === "none" && args.opts.requestId === void 0 && args.opts.creditOnly === void 0 && args.providerInfo.requestRecovery === true && args.providerInfo.auth?.includes(SIGNED_REQUEST_AUTH_ID) === true && args.signing !== void 0;
25409
+ function submitCanCarryGeneratedRequestId(args) {
25410
+ return args.opts.requestId === void 0 && args.opts.creditOnly === void 0 && args.providerInfo.requestRecovery === true && args.providerInfo.auth?.includes(SIGNED_REQUEST_AUTH_ID) === true && args.signing !== void 0;
25411
+ }
25412
+ function outcomeUnknownAfterSubmit(err) {
25413
+ if (isIdentityFailure(err)) return true;
25414
+ return err instanceof DvmError && POST_PAYMENT_UNKNOWN_CODES.has(err.code);
25363
25415
  }
25364
25416
  function leavesOutcomeUnknown(err) {
25365
25417
  if (isIdentityFailure(err)) return true;
@@ -25394,8 +25446,12 @@ function probeRailEvidence(env) {
25394
25446
  railCorrelation: { credit_id: creditId, ...drawId ? { draw_id: drawId } : {} }
25395
25447
  };
25396
25448
  }
25397
- function requestIdOutputFields(opts) {
25398
- return opts.requestId ? { request_id: opts.requestId } : {};
25449
+ function envelopeRequestId(env) {
25450
+ const requestId = unsignRequestData(env.data)?.body?.request_id;
25451
+ return typeof requestId === "string" ? requestId : void 0;
25452
+ }
25453
+ function requestIdOutputFields(requestId) {
25454
+ return requestId ? { request_id: requestId } : {};
25399
25455
  }
25400
25456
  function normalizedLocalCorrelationId(opts) {
25401
25457
  return opts.localCorrelationId === void 0 ? void 0 : normalizeLocalCorrelationId(opts.localCorrelationId);
@@ -25479,10 +25535,20 @@ async function tryAgentWalletPayment(transport, ref, envelope, jobId, deadlineMs
25479
25535
  builderHandle = void 0;
25480
25536
  }
25481
25537
  const spendStartedMs = Date.now();
25482
- let finalEnvelope = envelope;
25538
+ const generatedRequestId = fundPlan && submitCanCarryGeneratedRequestId({ opts, providerInfo, signing }) ? randomUUID4() : void 0;
25539
+ const withGeneratedRequestId = (unsigned) => generatedRequestId ? { ...unsigned, request_id: generatedRequestId } : unsigned;
25540
+ const perCallEnvelope = generatedRequestId && signing ? {
25541
+ ...envelope,
25542
+ data: signDvmRequestData(
25543
+ signing.privkey,
25544
+ withGeneratedRequestId(signing.unsignedData),
25545
+ signing.domain
25546
+ )
25547
+ } : envelope;
25548
+ let finalEnvelope = perCallEnvelope;
25483
25549
  const buildPrepareArgs = () => {
25484
25550
  const activeFund = fundPlan;
25485
- const fundData = activeFund && signing ? {
25551
+ const fundData = activeFund && signing ? withGeneratedRequestId({
25486
25552
  ...signing.unsignedData,
25487
25553
  credit_id: activeFund.creditId,
25488
25554
  draw_id: activeFund.drawId,
@@ -25490,7 +25556,7 @@ async function tryAgentWalletPayment(transport, ref, envelope, jobId, deadlineMs
25490
25556
  amount_micro: activeFund.wireAmountMicro ?? activeFund.fundMicro,
25491
25557
  commitment: ""
25492
25558
  }
25493
- } : null;
25559
+ }) : null;
25494
25560
  const payload = envelopeToPayload(envelope);
25495
25561
  return {
25496
25562
  amountSats: activeFund ? activeFund.fundSats : priceSats,
@@ -25513,14 +25579,14 @@ async function tryAgentWalletPayment(transport, ref, envelope, jobId, deadlineMs
25513
25579
  submit_body: { ...payload, data: fundData },
25514
25580
  signing_pubkey: signing.pubkey,
25515
25581
  ...baseContext
25516
- } : { ...resumableSubmitBody(envelope, providerInfo), ...baseContext }
25582
+ } : { ...resumableSubmitBody(perCallEnvelope, providerInfo), ...baseContext }
25517
25583
  };
25518
25584
  };
25519
25585
  let prepared = await prepareAgentSpend(buildPrepareArgs());
25520
25586
  if ("error" in prepared && fundPlan && prepared.error.code === "insufficient_balance" && fundPlan.fundSats > priceSats) {
25521
25587
  info("Wallet balance can't cover the credit funding \u2014 paying this job per-call.");
25522
25588
  fundPlan = void 0;
25523
- finalEnvelope = envelope;
25589
+ finalEnvelope = perCallEnvelope;
25524
25590
  prepared = await prepareAgentSpend(buildPrepareArgs());
25525
25591
  }
25526
25592
  if ("error" in prepared) {
@@ -25550,7 +25616,7 @@ async function tryAgentWalletPayment(transport, ref, envelope, jobId, deadlineMs
25550
25616
  ...envelope,
25551
25617
  data: signDvmRequestData(
25552
25618
  signing.privkey,
25553
- {
25619
+ withGeneratedRequestId({
25554
25620
  ...signing.unsignedData,
25555
25621
  credit_id: fundPlan.creditId,
25556
25622
  draw_id: fundPlan.drawId,
@@ -25558,11 +25624,24 @@ async function tryAgentWalletPayment(transport, ref, envelope, jobId, deadlineMs
25558
25624
  amount_micro: fundPlan.wireAmountMicro ?? fundPlan.fundMicro,
25559
25625
  commitment: sha256Hex(prepared.cashuToken)
25560
25626
  }
25561
- },
25627
+ }),
25562
25628
  signing.domain
25563
25629
  )
25564
25630
  };
25565
25631
  }
25632
+ if (generatedRequestId) {
25633
+ persistRequestIntent({
25634
+ requestId: generatedRequestId,
25635
+ transport,
25636
+ envelope: finalEnvelope,
25637
+ signing,
25638
+ endpoint: ref.endpoint,
25639
+ identity,
25640
+ policy,
25641
+ opts,
25642
+ providerInfo
25643
+ });
25644
+ }
25566
25645
  if (fundPlan && signing) {
25567
25646
  ensureProvisionalCredit({
25568
25647
  endpoint: ref.endpoint,
@@ -25603,7 +25682,8 @@ async function tryAgentWalletPayment(transport, ref, envelope, jobId, deadlineMs
25603
25682
  providerInfo,
25604
25683
  btcRate,
25605
25684
  fundPlan,
25606
- signing
25685
+ signing,
25686
+ generatedRequestId
25607
25687
  );
25608
25688
  return { handled: true };
25609
25689
  }
@@ -25675,8 +25755,9 @@ async function submitAgentWalletWithRetry(transport, ref, envelope, prepared, de
25675
25755
  retryTransportFailureOnce: true
25676
25756
  });
25677
25757
  }
25678
- async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, chosen, prepared, opts, identity, policy, providerInfo, btcRate = 0, fundPlan, signing) {
25758
+ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, chosen, prepared, opts, identity, policy, providerInfo, btcRate = 0, fundPlan, signing, generatedRequestId) {
25679
25759
  const dvmFields = dvmIdentity(identity.dvmId, identity.capability);
25760
+ let publicRequestId = opts.requestId ?? generatedRequestId;
25680
25761
  info(
25681
25762
  `Paying ${quoteAmountLabel(chosen, { anchor: false })} via agent wallet (Cashu P2PK, mint: ${prepared.mint})...`
25682
25763
  );
@@ -25700,7 +25781,7 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
25700
25781
  endpoint: ref.endpoint,
25701
25782
  ...identity.dvmId ? { dvmId: identity.dvmId } : {},
25702
25783
  capability: identity.capability,
25703
- ...opts.requestId ? { publicRequestId: opts.requestId } : {},
25784
+ ...publicRequestId ? { publicRequestId } : {},
25704
25785
  cashuRequestId: prepared.requestId,
25705
25786
  rail: "cashu",
25706
25787
  railCorrelation: {
@@ -25715,6 +25796,9 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
25715
25796
  marker: journalMarkerFor(record)
25716
25797
  });
25717
25798
  }
25799
+ if (generatedRequestId && publicRequestId) {
25800
+ throw requestOutcomeUnknown(publicRequestId, error);
25801
+ }
25718
25802
  throw error;
25719
25803
  }
25720
25804
  const signedMicro = fundPlan ? fundPlan.wireAmountMicro ?? fundPlan.fundMicro : void 0;
@@ -25728,6 +25812,7 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
25728
25812
  requestId: prepared.requestId,
25729
25813
  amountMicro: expected
25730
25814
  });
25815
+ if (generatedRequestId) publicRequestId = void 0;
25731
25816
  activeEnvelope = {
25732
25817
  ...envelope,
25733
25818
  data: signDvmRequestData(
@@ -25747,7 +25832,11 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
25747
25832
  await abandonPendingSubmission({ requestId: prepared.requestId });
25748
25833
  }
25749
25834
  transport.close?.();
25750
- throw withSpentSpendContext(err, prepared, opts.requestId);
25835
+ const spent = withSpentSpendContext(err, prepared, publicRequestId);
25836
+ if (generatedRequestId && publicRequestId && leavesOutcomeUnknown(spent)) {
25837
+ throw requestOutcomeUnknown(publicRequestId, spent);
25838
+ }
25839
+ throw spent;
25751
25840
  }
25752
25841
  }
25753
25842
  if (receipt.status === "payment-required") {
@@ -25795,7 +25884,7 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
25795
25884
  dvmId: identity.dvmId,
25796
25885
  feedbackClaim: receipt.feedbackClaim,
25797
25886
  capability: identity.capability,
25798
- requestId: opts.requestId,
25887
+ requestId: publicRequestId,
25799
25888
  status: "submitted",
25800
25889
  submittedAt: Date.now(),
25801
25890
  policy,
@@ -25961,7 +26050,7 @@ async function payWithX402(args, proof) {
25961
26050
  } else {
25962
26051
  json({
25963
26052
  ...dvmFields,
25964
- ...requestIdOutputFields(opts),
26053
+ ...requestIdOutputFields(opts.requestId),
25965
26054
  status: "paying",
25966
26055
  rail: "x402",
25967
26056
  account: wallet.address,
@@ -26074,7 +26163,7 @@ async function payWithX402(args, proof) {
26074
26163
  } else {
26075
26164
  json({
26076
26165
  jobId: effectiveJobId,
26077
- ...requestIdOutputFields(opts),
26166
+ ...requestIdOutputFields(opts.requestId),
26078
26167
  ...transactionOutputFields(receipt),
26079
26168
  ...dvmFields,
26080
26169
  summary: receipt.summary,
@@ -26104,7 +26193,7 @@ async function payWithX402(args, proof) {
26104
26193
  paymentFields: {
26105
26194
  paidWith: "x402",
26106
26195
  account: wallet.address,
26107
- ...requestIdOutputFields(opts),
26196
+ ...requestIdOutputFields(opts.requestId),
26108
26197
  ...transactionOutputFields(receipt)
26109
26198
  },
26110
26199
  dvmFields,
@@ -13,7 +13,7 @@ import {
13
13
  recordFloatSpend,
14
14
  resolveFundMint,
15
15
  sweepPendingMints
16
- } from "./chunk-BHJLMVO2.js";
16
+ } from "./chunk-7674LYNL.js";
17
17
  import "./chunk-2I5XAIQ4.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.7.0-rc.3",
3
+ "version": "0.7.0",
4
4
  "description": "CLI for Digital Vending Machines — discover, pay, and use DVMs from the terminal",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {