@dvmkit/dvm-cli 0.8.0 → 0.8.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/dvm.js CHANGED
@@ -12571,6 +12571,9 @@ var CREDIT_CONTEXT_FIELDS = [
12571
12571
  ];
12572
12572
  function withCreditErrorContext(err, body) {
12573
12573
  const extra = {};
12574
+ if (err.code === "tempo_channel_exit_required" && typeof body.status === "string") {
12575
+ extra.status = body.status;
12576
+ }
12574
12577
  for (const key of CREDIT_CONTEXT_FIELDS) {
12575
12578
  if (typeof body[key] === "number") extra[key] = body[key];
12576
12579
  }
@@ -12585,6 +12588,7 @@ function withCreditErrorContext(err, body) {
12585
12588
  "credit_rail",
12586
12589
  "credit_instrument",
12587
12590
  "credit_channel_id",
12591
+ "channel_id",
12588
12592
  "bound_credit_id",
12589
12593
  "rail",
12590
12594
  "settlement_drain_id"
@@ -15373,7 +15377,19 @@ async function runCreditDrain(dvm, opts) {
15373
15377
  "Run 'dvm credit balance <dvm>' to check the server, or pass --credit-id explicitly."
15374
15378
  );
15375
15379
  }
15380
+ const exitCommand = [
15381
+ "dvm wallet tempo-exit",
15382
+ shellQuoteArg(endpoint),
15383
+ "--credit-id",
15384
+ shellQuoteArg(creditId),
15385
+ ..."name" in signer.source ? ["--as", shellQuoteArg(signer.source.name)] : []
15386
+ ].join(" ");
15376
15387
  const tempoSession = !!loadTempoChannelAssociation(endpoint, signer.pubkey, creditId);
15388
+ const exitRecovery = {
15389
+ command: exitCommand,
15390
+ hasLocalChannel: tempoSession,
15391
+ envSigner: signer.source.kind === "env"
15392
+ };
15377
15393
  const method = (opts.method ?? (stored?.creditId === creditId && stored.rail === "tempo" || tempoSession ? "tempo" : stored?.creditId === creditId && (stored.rail === "x402" || stored.x402Instrument !== void 0) ? "x402" : "cashu")).toLowerCase();
15378
15394
  if (opts.recoverFromReceipts && (method !== "x402" || !opts.creditId || !opts.drainId || opts.address !== void 0)) {
15379
15395
  throw new DvmError(
@@ -15666,6 +15682,8 @@ async function runCreditDrain(dvm, opts) {
15666
15682
  anchorRead = await fetchTrustAnchor(transport, { endpoint });
15667
15683
  }
15668
15684
  } catch (err) {
15685
+ const originalDisplay = err instanceof DvmError ? typeof err.data?.display === "string" ? err.data.display : err.display : void 0;
15686
+ let retirement;
15669
15687
  if (err instanceof DvmError && err.data?.drain_id_retired === true) {
15670
15688
  clearPendingDrain(endpoint, signer.pubkey, drain, ...identityArg);
15671
15689
  } else if (
@@ -15696,7 +15714,7 @@ async function runCreditDrain(dvm, opts) {
15696
15714
  );
15697
15715
  } else if (err instanceof DvmError && err.data?.drain_registered === false) {
15698
15716
  clearPendingDrain(endpoint, signer.pubkey, drain, ...identityArg);
15699
- const retirement = `The DVM confirmed drain ${drain.drainId} was never registered, so its stale local record was retired. No refund was created or paid.`;
15717
+ retirement = `The DVM confirmed drain ${drain.drainId} was never registered, so its stale local record was retired. No refund was created or paid.`;
15700
15718
  const serverDisplay = typeof err.data.display === "string" ? err.data.display : err.display;
15701
15719
  const displayWasProvider = err.proseSources?.display === "provider";
15702
15720
  err.display = serverDisplay ? `${serverDisplay} ${retirement}` : retirement;
@@ -15714,6 +15732,21 @@ async function runCreditDrain(dvm, opts) {
15714
15732
  if (!stored) forgetCredit(endpoint, signer.pubkey, ...identityArg);
15715
15733
  else if (mintedThisRun) clearPendingDrain(endpoint, signer.pubkey, drain, ...identityArg);
15716
15734
  }
15735
+ if (err instanceof DvmError && err.code === "tempo_channel_exit_required") {
15736
+ const local2 = tempoExitRequiredCopy(exitRecovery, err.data?.channel_id, err.data?.status);
15737
+ const display2 = retirement ? `${local2.display} ${retirement}` : local2.display;
15738
+ const providerDisplay2 = asProviderTextOpt(originalDisplay);
15739
+ const providerHint2 = asProviderTextOpt(err.hint);
15740
+ throw new DvmError(err.code, display2, local2.hint, {
15741
+ ...err.data,
15742
+ credit_id: creditId,
15743
+ drain_id: drain.drainId,
15744
+ retryable: err.data?.status === "pending",
15745
+ ...providerDisplay2 ? { provider_display: providerDisplay2 } : {},
15746
+ ...providerHint2 ? { provider_hint: providerHint2 } : {},
15747
+ display: display2
15748
+ });
15749
+ }
15717
15750
  throw err;
15718
15751
  } finally {
15719
15752
  transport.close();
@@ -15758,6 +15791,7 @@ async function runCreditDrain(dvm, opts) {
15758
15791
  `Warning: a drain receipt did not verify. ${receiptFailureDetail(firstBroken.reason ?? "signature_invalid")}`
15759
15792
  );
15760
15793
  }
15794
+ const local = localDrainCopy(wireDrain, drain, exitRecovery);
15761
15795
  let claimedSats;
15762
15796
  if (wireDrain.token && drain.method === "cashu") {
15763
15797
  try {
@@ -15798,7 +15832,6 @@ async function runCreditDrain(dvm, opts) {
15798
15832
  const atRiskHint = x402AtRisk?.micro ? ` ${x402AtRiskInstruction(x402AtRisk.micro, x402AtRisk.pending)}` : mppAtRisk ? ` That authority outlives this released drain: the credit balance is spendable again, and the channel's collateral is only settled once the channel closes on-chain. 'dvm wallet tempo-exit ${dvm}' reads the chain and reports what the exit is guaranteed to return against what it likely returns.` : "";
15799
15833
  const providerDisplay = asProviderTextOpt(result.display);
15800
15834
  const providerHint = asProviderTextOpt(result.hint);
15801
- const local = localDrainCopy(wireDrain, drain);
15802
15835
  const channelExitHint = released && drain.method === "tempo" && channelBacked && !atRiskHint ? ` The channel itself is still open on-chain: 'dvm wallet tempo-exit ${dvm}' reads it and recovers the collateral.` : "";
15803
15836
  const display = (claimedSats !== void 0 ? `Reclaimed $${formatUsd(wireDrain.amount_micro / 1e6)} \u2014 ${String(claimedSats)} sats received into the agent wallet.` : local.display) + atRiskNote + channelNote;
15804
15837
  const hint = (claimedSats !== void 0 ? "The refund is in your wallet ('dvm wallet show'). The drain receipts are your signed evidence of the reclaim." : local.hint) + channelExitHint + atRiskHint + channelHint;
@@ -16088,7 +16121,7 @@ async function runCreditReceipts(dvm, opts) {
16088
16121
  }
16089
16122
  });
16090
16123
  }
16091
- function localDrainCopy(wire, requested) {
16124
+ function localDrainCopy(wire, requested, exitRecovery) {
16092
16125
  const amount = formatFiat(wire.amount_micro / 1e6, wire.currency);
16093
16126
  const poll = "Re-run this command to poll; the same drain id is request, poll, and pickup.";
16094
16127
  switch (wire.status) {
@@ -16125,15 +16158,34 @@ function localDrainCopy(wire, requested) {
16125
16158
  display: `The DVM reports ${amount} of refund was paid out to the destination this drain named.`,
16126
16159
  hint: "The settlement reference is in drain.sent. The drain receipts are your signed evidence of the reclaim."
16127
16160
  };
16161
+ case "exit_required":
16162
+ return tempoExitRequiredCopy(exitRecovery, "channel_id" in wire ? wire.channel_id : void 0);
16128
16163
  case "released":
16129
16164
  return {
16130
16165
  display: `The refund could not complete, so the DVM restored ${amount} to the prepaid balance.`,
16131
16166
  hint: "This released drain is terminal \u2014 do not poll it again. The balance is spendable, or reclaimable on a fresh drain."
16132
16167
  };
16133
16168
  default:
16134
- return { display: `Drain ${wire.status}.`, hint: poll };
16169
+ throw new DvmError(
16170
+ "unknown_drain_status",
16171
+ `The DVM reported an unknown drain status: ${wire.status}. The refund outcome is not understood by this version of dvm.`,
16172
+ "Upgrade dvm before continuing; do not poll this drain with this version. Keep the recovery records and signed receipts until the refund is confirmed.",
16173
+ { status: wire.status, drain_id: wire.drain_id, credit_id: wire.credit_id },
16174
+ `Unknown drain status '${wire.status}'; this version of dvm cannot determine the refund outcome.`
16175
+ );
16135
16176
  }
16136
16177
  }
16178
+ function tempoExitRequiredCopy(recovery, channelId, status2) {
16179
+ const channel = typeof channelId === "string" ? ` Channel ID: ${channelId}.` : "";
16180
+ const pending4 = status2 === "pending";
16181
+ const nextStep = pending4 ? "A retry of the same drain with a valid close credential (approval to close this deposit) may still work. The timed exit is the fallback." : "Do not retry the direct refund; do not poll this drain again.";
16182
+ const command = recovery.hasLocalChannel ? `Run '${recovery.command}' to start or finish the timed exit. Keep the channel recovery record until the funds are returned.` : `Run '${recovery.command}' from the wallet and machine that opened the channel; this machine has no channel recovery record for this credit.`;
16183
+ const signer = recovery.envSigner ? " Set the same DVM_IDENTITY_KEY used for this credit when running that command." : "";
16184
+ return {
16185
+ display: pending4 ? "The service cannot return this money directly with the current approval. A valid approval may still let it return the money, or the remaining funds come back through a timed exit after a delay." : "The service cannot return this money directly. The remaining funds come back through a timed exit after a delay.",
16186
+ hint: `${nextStep} ${command}${signer} The timed exit returns the remaining funds after its delay. The service can still collect payments you already approved, and chain fees apply.${channel}`
16187
+ };
16188
+ }
16137
16189
  function drainReceiptEvent(receipt) {
16138
16190
  return isDrainReceipt(receipt) ? receipt.event : null;
16139
16191
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvmkit/dvm-cli",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
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": [
@@ -24,6 +24,8 @@ Return to [calling](calling.md) for jobs. Keep the same signing identity. If the
24
24
 
25
25
  To reclaim unused credit, inspect the balance and use `dvm credit drain <dvm>` with the indicated credit ID when necessary. Distinguish a requested refund, a pending settlement, and funds actually returned. Provider-marked refund text is the provider's account of events; it does not override the CLI's verified state.
26
26
 
27
+ A Tempo drain with status `exit_required` cannot return the money directly. Relay the CLI's `display` and `hint` and stop polling a terminal drain. The `tempo_channel_exit_required` HTTP 409 form exits 1 and the `exit_required` status form exits 0; both mean run the timed exit, although a 409 with `status: "pending"` still permits a retry of the same drain with a valid close credential (approval to close the deposit). Use the named `dvm wallet tempo-exit <dvm> --credit-id <id>` command, preserving any `--as <name>` selector or the same `DVM_IDENTITY_KEY`. If this machine has no channel recovery record, run the exit from the wallet and machine that opened the channel. This timed exit returns the remaining channel funds after its delay; already approved payments and chain fees can reduce the return. Keep any recovery records until the funds arrive. An `unknown_drain_status` error requires upgrading `dvm` before continuing, not repeated polling.
28
+
27
29
  If the provider cannot answer, the available recovery depends on the original funding instrument. Channel exits can recover remaining collateral after the required delay; one-payment funding may depend on a provider refund. Follow [recovery](recovery.md) and the published contract before promising an amount or a completion time. Expiry alone is not proof of a refund or continued recoverability.
28
30
 
29
31
  Success means the selected credit can fund the intended jobs, the posture matches the user's authorization, or the reclaim has a verified result. Keep pending obligations explicit. Exact flags, posture scope, expiry, and settlement behavior live in [credits](https://dvmkit.com/docs/credits.md).