@dvmkit/dvm-cli 0.8.0 → 0.8.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.
package/dist/dvm.js CHANGED
@@ -11470,10 +11470,49 @@ function findLastYield(messages2) {
11470
11470
  return void 0;
11471
11471
  }
11472
11472
 
11473
+ // src/lib/schema-defaults.ts
11474
+ function applyJsonSchemaDefaults(schema, data) {
11475
+ const applied = {};
11476
+ if (!schema || typeof schema !== "object") return { data: { ...data }, applied };
11477
+ const properties = schema.properties;
11478
+ if (!properties || typeof properties !== "object") return { data: { ...data }, applied };
11479
+ const merged = { ...data };
11480
+ for (const [key, propSchema] of Object.entries(properties)) {
11481
+ if (key in merged) continue;
11482
+ if (!propSchema || typeof propSchema !== "object") continue;
11483
+ if (!("default" in propSchema)) continue;
11484
+ const defaultValue = propSchema.default;
11485
+ merged[key] = defaultValue;
11486
+ applied[key] = defaultValue;
11487
+ }
11488
+ return { data: merged, applied };
11489
+ }
11490
+ function formatAppliedDefaults(applied) {
11491
+ return Object.entries(applied).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join(", ");
11492
+ }
11493
+
11473
11494
  // src/lib/discovery-lifecycle.ts
11474
11495
  async function runDiscoveryLifecycle(options) {
11475
11496
  const { transport, provider, capability, input, timeoutMs } = options;
11476
- const receipt = await transport.submit(provider, { capability, input });
11497
+ const providerInfo = await transport.describe(provider);
11498
+ const schema = providerInfo.capabilities?.[capability]?.input_schema ?? providerInfo.inputSchema;
11499
+ const normalized = applyJsonSchemaDefaults(schema, JSON.parse(input)).data;
11500
+ let data;
11501
+ if (providerInfo.auth?.includes(SIGNED_REQUEST_AUTH_ID) || providerInfo.auth?.includes("secp256k1-schnorr")) {
11502
+ const signer = resolveSigningIdentity({ config: loadConfig() });
11503
+ data = signDvmRequestData(signer.privkey, normalized, signedRequestDomain({
11504
+ provider: providerInfo,
11505
+ endpoint: provider.endpoint,
11506
+ method: "POST",
11507
+ path: "v1/job",
11508
+ capability
11509
+ }));
11510
+ }
11511
+ const receipt = await transport.submit(provider, {
11512
+ capability,
11513
+ input: JSON.stringify(normalized),
11514
+ ...data ? { data } : {}
11515
+ });
11477
11516
  if (receipt.status === "completed" && receipt.summary) {
11478
11517
  return { summary: receipt.summary, messages: [], nextAction: null };
11479
11518
  }
@@ -12571,6 +12610,9 @@ var CREDIT_CONTEXT_FIELDS = [
12571
12610
  ];
12572
12611
  function withCreditErrorContext(err, body) {
12573
12612
  const extra = {};
12613
+ if (err.code === "tempo_channel_exit_required" && typeof body.status === "string") {
12614
+ extra.status = body.status;
12615
+ }
12574
12616
  for (const key of CREDIT_CONTEXT_FIELDS) {
12575
12617
  if (typeof body[key] === "number") extra[key] = body[key];
12576
12618
  }
@@ -12585,6 +12627,7 @@ function withCreditErrorContext(err, body) {
12585
12627
  "credit_rail",
12586
12628
  "credit_instrument",
12587
12629
  "credit_channel_id",
12630
+ "channel_id",
12588
12631
  "bound_credit_id",
12589
12632
  "rail",
12590
12633
  "settlement_drain_id"
@@ -15373,7 +15416,19 @@ async function runCreditDrain(dvm, opts) {
15373
15416
  "Run 'dvm credit balance <dvm>' to check the server, or pass --credit-id explicitly."
15374
15417
  );
15375
15418
  }
15419
+ const exitCommand = [
15420
+ "dvm wallet tempo-exit",
15421
+ shellQuoteArg(endpoint),
15422
+ "--credit-id",
15423
+ shellQuoteArg(creditId),
15424
+ ..."name" in signer.source ? ["--as", shellQuoteArg(signer.source.name)] : []
15425
+ ].join(" ");
15376
15426
  const tempoSession = !!loadTempoChannelAssociation(endpoint, signer.pubkey, creditId);
15427
+ const exitRecovery = {
15428
+ command: exitCommand,
15429
+ hasLocalChannel: tempoSession,
15430
+ envSigner: signer.source.kind === "env"
15431
+ };
15377
15432
  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
15433
  if (opts.recoverFromReceipts && (method !== "x402" || !opts.creditId || !opts.drainId || opts.address !== void 0)) {
15379
15434
  throw new DvmError(
@@ -15666,6 +15721,8 @@ async function runCreditDrain(dvm, opts) {
15666
15721
  anchorRead = await fetchTrustAnchor(transport, { endpoint });
15667
15722
  }
15668
15723
  } catch (err) {
15724
+ const originalDisplay = err instanceof DvmError ? typeof err.data?.display === "string" ? err.data.display : err.display : void 0;
15725
+ let retirement;
15669
15726
  if (err instanceof DvmError && err.data?.drain_id_retired === true) {
15670
15727
  clearPendingDrain(endpoint, signer.pubkey, drain, ...identityArg);
15671
15728
  } else if (
@@ -15696,7 +15753,7 @@ async function runCreditDrain(dvm, opts) {
15696
15753
  );
15697
15754
  } else if (err instanceof DvmError && err.data?.drain_registered === false) {
15698
15755
  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.`;
15756
+ retirement = `The DVM confirmed drain ${drain.drainId} was never registered, so its stale local record was retired. No refund was created or paid.`;
15700
15757
  const serverDisplay = typeof err.data.display === "string" ? err.data.display : err.display;
15701
15758
  const displayWasProvider = err.proseSources?.display === "provider";
15702
15759
  err.display = serverDisplay ? `${serverDisplay} ${retirement}` : retirement;
@@ -15714,6 +15771,21 @@ async function runCreditDrain(dvm, opts) {
15714
15771
  if (!stored) forgetCredit(endpoint, signer.pubkey, ...identityArg);
15715
15772
  else if (mintedThisRun) clearPendingDrain(endpoint, signer.pubkey, drain, ...identityArg);
15716
15773
  }
15774
+ if (err instanceof DvmError && err.code === "tempo_channel_exit_required") {
15775
+ const local2 = tempoExitRequiredCopy(exitRecovery, err.data?.channel_id, err.data?.status);
15776
+ const display2 = retirement ? `${local2.display} ${retirement}` : local2.display;
15777
+ const providerDisplay2 = asProviderTextOpt(originalDisplay);
15778
+ const providerHint2 = asProviderTextOpt(err.hint);
15779
+ throw new DvmError(err.code, display2, local2.hint, {
15780
+ ...err.data,
15781
+ credit_id: creditId,
15782
+ drain_id: drain.drainId,
15783
+ retryable: err.data?.status === "pending",
15784
+ ...providerDisplay2 ? { provider_display: providerDisplay2 } : {},
15785
+ ...providerHint2 ? { provider_hint: providerHint2 } : {},
15786
+ display: display2
15787
+ });
15788
+ }
15717
15789
  throw err;
15718
15790
  } finally {
15719
15791
  transport.close();
@@ -15758,6 +15830,7 @@ async function runCreditDrain(dvm, opts) {
15758
15830
  `Warning: a drain receipt did not verify. ${receiptFailureDetail(firstBroken.reason ?? "signature_invalid")}`
15759
15831
  );
15760
15832
  }
15833
+ const local = localDrainCopy(wireDrain, drain, exitRecovery);
15761
15834
  let claimedSats;
15762
15835
  if (wireDrain.token && drain.method === "cashu") {
15763
15836
  try {
@@ -15798,7 +15871,6 @@ async function runCreditDrain(dvm, opts) {
15798
15871
  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
15872
  const providerDisplay = asProviderTextOpt(result.display);
15800
15873
  const providerHint = asProviderTextOpt(result.hint);
15801
- const local = localDrainCopy(wireDrain, drain);
15802
15874
  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
15875
  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
15876
  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 +16160,7 @@ async function runCreditReceipts(dvm, opts) {
16088
16160
  }
16089
16161
  });
16090
16162
  }
16091
- function localDrainCopy(wire, requested) {
16163
+ function localDrainCopy(wire, requested, exitRecovery) {
16092
16164
  const amount = formatFiat(wire.amount_micro / 1e6, wire.currency);
16093
16165
  const poll = "Re-run this command to poll; the same drain id is request, poll, and pickup.";
16094
16166
  switch (wire.status) {
@@ -16125,15 +16197,34 @@ function localDrainCopy(wire, requested) {
16125
16197
  display: `The DVM reports ${amount} of refund was paid out to the destination this drain named.`,
16126
16198
  hint: "The settlement reference is in drain.sent. The drain receipts are your signed evidence of the reclaim."
16127
16199
  };
16200
+ case "exit_required":
16201
+ return tempoExitRequiredCopy(exitRecovery, "channel_id" in wire ? wire.channel_id : void 0);
16128
16202
  case "released":
16129
16203
  return {
16130
16204
  display: `The refund could not complete, so the DVM restored ${amount} to the prepaid balance.`,
16131
16205
  hint: "This released drain is terminal \u2014 do not poll it again. The balance is spendable, or reclaimable on a fresh drain."
16132
16206
  };
16133
16207
  default:
16134
- return { display: `Drain ${wire.status}.`, hint: poll };
16208
+ throw new DvmError(
16209
+ "unknown_drain_status",
16210
+ `The DVM reported an unknown drain status: ${wire.status}. The refund outcome is not understood by this version of dvm.`,
16211
+ "Upgrade dvm before continuing; do not poll this drain with this version. Keep the recovery records and signed receipts until the refund is confirmed.",
16212
+ { status: wire.status, drain_id: wire.drain_id, credit_id: wire.credit_id },
16213
+ `Unknown drain status '${wire.status}'; this version of dvm cannot determine the refund outcome.`
16214
+ );
16135
16215
  }
16136
16216
  }
16217
+ function tempoExitRequiredCopy(recovery, channelId, status2) {
16218
+ const channel = typeof channelId === "string" ? ` Channel ID: ${channelId}.` : "";
16219
+ const pending4 = status2 === "pending";
16220
+ 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.";
16221
+ 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.`;
16222
+ const signer = recovery.envSigner ? " Set the same DVM_IDENTITY_KEY used for this credit when running that command." : "";
16223
+ return {
16224
+ 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.",
16225
+ 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}`
16226
+ };
16227
+ }
16137
16228
  function drainReceiptEvent(receipt) {
16138
16229
  return isDrainReceipt(receipt) ? receipt.event : null;
16139
16230
  }
@@ -22398,27 +22489,6 @@ function isPlainObject3(value) {
22398
22489
  return typeof value === "object" && value !== null && !Array.isArray(value);
22399
22490
  }
22400
22491
 
22401
- // src/lib/schema-defaults.ts
22402
- function applyJsonSchemaDefaults(schema, data) {
22403
- const applied = {};
22404
- if (!schema || typeof schema !== "object") return { data: { ...data }, applied };
22405
- const properties = schema.properties;
22406
- if (!properties || typeof properties !== "object") return { data: { ...data }, applied };
22407
- const merged = { ...data };
22408
- for (const [key, propSchema] of Object.entries(properties)) {
22409
- if (key in merged) continue;
22410
- if (!propSchema || typeof propSchema !== "object") continue;
22411
- if (!("default" in propSchema)) continue;
22412
- const defaultValue = propSchema.default;
22413
- merged[key] = defaultValue;
22414
- applied[key] = defaultValue;
22415
- }
22416
- return { data: merged, applied };
22417
- }
22418
- function formatAppliedDefaults(applied) {
22419
- return Object.entries(applied).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join(", ");
22420
- }
22421
-
22422
22492
  // src/lib/warmup-provider.ts
22423
22493
  var DEFAULT_BUDGET_MS = 3e4;
22424
22494
  var DEFAULT_MAX_ATTEMPTS = 4;
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.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": [
@@ -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).