@dvmkit/dvm-cli 0.10.0 → 0.11.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/{chunk-BHR7QHJG.js → chunk-3R2GM6AD.js} +2 -2
  2. package/dist/{chunk-TGRY23IF.js → chunk-6EYBCGGD.js} +2 -2
  3. package/dist/{chunk-NXXU3BSJ.js → chunk-7N3HQJKE.js} +4 -4
  4. package/dist/{chunk-C3HMFGYP.js → chunk-BPWZNIMS.js} +2 -2
  5. package/dist/{chunk-MTGQK7KA.js → chunk-GEZVSJDM.js} +3 -3
  6. package/dist/{chunk-GD25CUI4.js → chunk-GHNF2I5C.js} +4 -4
  7. package/dist/{chunk-3YU6KRCX.js → chunk-HWWW7JEM.js} +3 -3
  8. package/dist/{chunk-Q45TAYK2.js → chunk-JJBRTWWS.js} +160 -7
  9. package/dist/{chunk-HUBCGZJL.js → chunk-K562SFVD.js} +2 -2
  10. package/dist/{chunk-CWWZM4M6.js → chunk-MBSCP52L.js} +564 -204
  11. package/dist/{chunk-GMOKL4PQ.js → chunk-MMXHV3KC.js} +2 -2
  12. package/dist/{chunk-IEWV3CM2.js → chunk-UVFFMKU4.js} +3 -1
  13. package/dist/{client-MFSKFSV4.js → client-DS4QJ346.js} +6 -6
  14. package/dist/dvm.js +1075 -251
  15. package/dist/{internal-5EGKBZAE.js → internal-ZZHCUKOM.js} +5 -5
  16. package/dist/{lifecycle-7AVB36WP.js → lifecycle-XGNIMPTB.js} +6 -6
  17. package/dist/{payout-reporter-NXWQVKXW-KHVN6C4Z.js → payout-reporter-DDQ7FGRC-OKICJCC2.js} +2 -2
  18. package/dist/{pocket-refill-SKECWGA3.js → pocket-refill-3ZV36DOA.js} +10 -10
  19. package/dist/{revenue-reporter-HD4GMXGD-LAZU45ZA.js → revenue-reporter-RIEHBKRA-75BDPVVX.js} +2 -2
  20. package/dist/{tempo-lifecycle-SVPMTND2.js → tempo-lifecycle-LGGBDCKK.js} +8 -8
  21. package/dist/{tempo-wallet-5PKLSWFX.js → tempo-wallet-PLFC443A.js} +7 -7
  22. package/dist/{wallet-7BBWAZYJ.js → wallet-UJ7EJNQA.js} +7 -7
  23. package/dist/{x402-RUJ4LUKF-ZB7JM22B.js → x402-AY6P5KV4-SIZF7YNW.js} +2 -2
  24. package/package.json +2 -2
  25. package/skills/dvm/calling.md +15 -1
@@ -6,9 +6,9 @@ import {
6
6
  } from "./chunk-R2DSAZBO.js";
7
7
  import {
8
8
  diagnosticConsole
9
- } from "./chunk-IEWV3CM2.js";
9
+ } from "./chunk-UVFFMKU4.js";
10
10
 
11
- // node_modules/@dvmkit/sdk/dist/chunk-ITRSITFP.js
11
+ // node_modules/@dvmkit/sdk/dist/chunk-2I6NXIPG.js
12
12
  import { createHash, randomUUID } from "crypto";
13
13
  async function x402EarnedCeiling(channel, earnedNative) {
14
14
  let earned;
@@ -5,10 +5,10 @@ import {
5
5
  formatUsdcMicrounits,
6
6
  listX402Channels,
7
7
  readX402ChannelGuardFacts
8
- } from "./chunk-CWWZM4M6.js";
8
+ } from "./chunk-MBSCP52L.js";
9
9
  import {
10
10
  DvmError
11
- } from "./chunk-GD25CUI4.js";
11
+ } from "./chunk-GHNF2I5C.js";
12
12
 
13
13
  // src/lib/x402/lifecycle.ts
14
14
  async function assertX402WalletIdle(wallet, intent) {
@@ -4,14 +4,14 @@ const require = __dvmCreateRequire(import.meta.url);
4
4
  import {
5
5
  loadConfig,
6
6
  updateConfig
7
- } from "./chunk-GMOKL4PQ.js";
7
+ } from "./chunk-MMXHV3KC.js";
8
8
  import {
9
9
  tempoAccountFromConfig,
10
10
  tryResolveTempoAsset
11
- } from "./chunk-CWWZM4M6.js";
11
+ } from "./chunk-MBSCP52L.js";
12
12
  import {
13
13
  DvmError
14
- } from "./chunk-GD25CUI4.js";
14
+ } from "./chunk-GHNF2I5C.js";
15
15
 
16
16
  // src/lib/payment-rails/tempo-wallet.ts
17
17
  function tempoBalanceCheckHint(token) {
@@ -46,7 +46,7 @@ async function generateTempoKey(opts = {}) {
46
46
  );
47
47
  }
48
48
  if (existing && opts.force) {
49
- const { assertTempoWalletIdle } = await import("./tempo-lifecycle-SVPMTND2.js");
49
+ const { assertTempoWalletIdle } = await import("./tempo-lifecycle-LGGBDCKK.js");
50
50
  await assertTempoWalletIdle("replace");
51
51
  }
52
52
  const { privateKeyToAccount, generatePrivateKey } = await import("./accounts-2WZE4N5F.js");
@@ -12,7 +12,7 @@ import {
12
12
  isSignableExactRequirement,
13
13
  maxAdvertisedMicro,
14
14
  withinAdvertisedTolerance
15
- } from "./chunk-CWWZM4M6.js";
15
+ } from "./chunk-MBSCP52L.js";
16
16
  import {
17
17
  DvmError,
18
18
  X402_V1_VERSION,
@@ -30,7 +30,7 @@ import {
30
30
  usdcToMsats,
31
31
  x402NetworkByCaip2,
32
32
  x402NetworkToCaip2
33
- } from "./chunk-GD25CUI4.js";
33
+ } from "./chunk-GHNF2I5C.js";
34
34
 
35
35
  // src/lib/x402/client.ts
36
36
  import { randomBytes } from "crypto";
@@ -5,11 +5,11 @@ import {
5
5
  authorizeProtectedRemoval,
6
6
  loadConfig,
7
7
  updateConfig
8
- } from "./chunk-GMOKL4PQ.js";
8
+ } from "./chunk-MMXHV3KC.js";
9
9
  import {
10
10
  withX402ChannelLock,
11
11
  x402WalletFromConfig
12
- } from "./chunk-CWWZM4M6.js";
12
+ } from "./chunk-MBSCP52L.js";
13
13
  import {
14
14
  DvmError,
15
15
  X402_DEFAULT_NETWORK,
@@ -17,7 +17,7 @@ import {
17
17
  ensureAddress,
18
18
  isValidEvmPrivateKey,
19
19
  x402NetworkByCaip2
20
- } from "./chunk-GD25CUI4.js";
20
+ } from "./chunk-GHNF2I5C.js";
21
21
 
22
22
  // src/lib/x402/networks.ts
23
23
  function x402NetworkLabel(network) {
@@ -3,7 +3,7 @@ import { createRequire as __dvmCreateRequire } from "node:module";
3
3
  const require = __dvmCreateRequire(import.meta.url);
4
4
  import {
5
5
  diagnosticConsole
6
- } from "./chunk-IEWV3CM2.js";
6
+ } from "./chunk-UVFFMKU4.js";
7
7
  import {
8
8
  __export
9
9
  } from "./chunk-IYHTITNZ.js";
@@ -3105,7 +3105,7 @@ function buildNoopLoggers() {
3105
3105
  };
3106
3106
  }
3107
3107
 
3108
- // node_modules/@dvmkit/sdk/dist/chunk-E7ZBCT5U.js
3108
+ // node_modules/@dvmkit/sdk/dist/chunk-I2H2XYQV.js
3109
3109
  import { AsyncLocalStorage } from "async_hooks";
3110
3110
  import { createPrivateKey, randomBytes as randomBytes2 } from "crypto";
3111
3111
 
@@ -10597,7 +10597,7 @@ var SignJWT = class {
10597
10597
  }
10598
10598
  };
10599
10599
 
10600
- // node_modules/@dvmkit/sdk/dist/chunk-E7ZBCT5U.js
10600
+ // node_modules/@dvmkit/sdk/dist/chunk-I2H2XYQV.js
10601
10601
  var scopes = new AsyncLocalStorage();
10602
10602
  function withPaymentDiagnostics(fn) {
10603
10603
  return scopes.run({}, fn);
@@ -10772,7 +10772,7 @@ function logRejected(stage) {
10772
10772
  });
10773
10773
  }
10774
10774
 
10775
- // node_modules/@dvmkit/sdk/dist/chunk-3YFFZLW7.js
10775
+ // node_modules/@dvmkit/sdk/dist/chunk-IUODXRQN.js
10776
10776
  async function verifyX402Payment(paymentHeader, config, requiredUsdcMicro, resource, btcUsdRate, exactVersions = { v1: true, v2: true }) {
10777
10777
  return callerLoggers.x402.span(
10778
10778
  "x402.verify_payment",
@@ -3,7 +3,7 @@ import { createRequire as __dvmCreateRequire } from "node:module";
3
3
  const require = __dvmCreateRequire(import.meta.url);
4
4
  import {
5
5
  connectedTempoAccount
6
- } from "./chunk-NXXU3BSJ.js";
6
+ } from "./chunk-7N3HQJKE.js";
7
7
  import {
8
8
  deriveIdentityFromPrivkey,
9
9
  formatUsdcMicrounits,
@@ -13,10 +13,10 @@ import {
13
13
  reconcileTempoChannelOnChain,
14
14
  shellQuoteArg,
15
15
  tempoChannelControlledBy
16
- } from "./chunk-CWWZM4M6.js";
16
+ } from "./chunk-MBSCP52L.js";
17
17
  import {
18
18
  DvmError
19
- } from "./chunk-GD25CUI4.js";
19
+ } from "./chunk-GHNF2I5C.js";
20
20
 
21
21
  // src/lib/cli-identity-resolve.ts
22
22
  function resolveSigningIdentity(opts) {
@@ -3,7 +3,7 @@ import { createRequire as __dvmCreateRequire } from "node:module";
3
3
  const require = __dvmCreateRequire(import.meta.url);
4
4
  import {
5
5
  connectedTempoAccount
6
- } from "./chunk-NXXU3BSJ.js";
6
+ } from "./chunk-7N3HQJKE.js";
7
7
  import {
8
8
  costAnchor,
9
9
  info,
@@ -11,15 +11,15 @@ import {
11
11
  resolveBtcUsdRate,
12
12
  tryResolveBtcUsdRate,
13
13
  tryX402Payment
14
- } from "./chunk-C3HMFGYP.js";
14
+ } from "./chunk-BPWZNIMS.js";
15
15
  import {
16
16
  loadX402Wallet,
17
17
  x402NetworkLabel
18
- } from "./chunk-MTGQK7KA.js";
18
+ } from "./chunk-GEZVSJDM.js";
19
19
  import {
20
20
  isCreditPosture,
21
21
  loadConfig
22
- } from "./chunk-GMOKL4PQ.js";
22
+ } from "./chunk-MMXHV3KC.js";
23
23
  import {
24
24
  BUDGET_FILE,
25
25
  CONFIG_DIR,
@@ -166,7 +166,7 @@ import {
166
166
  x402PendingUnsettled,
167
167
  x402RequiredFromError,
168
168
  x402VoucherPendingState
169
- } from "./chunk-CWWZM4M6.js";
169
+ } from "./chunk-MBSCP52L.js";
170
170
  import {
171
171
  Challenge_exports,
172
172
  Credential_exports
@@ -183,7 +183,7 @@ import {
183
183
  redactUrlsInText,
184
184
  usdToMsats,
185
185
  x402NetworkToCaip2
186
- } from "./chunk-GD25CUI4.js";
186
+ } from "./chunk-GHNF2I5C.js";
187
187
  import {
188
188
  privateKeyToAccount
189
189
  } from "./chunk-EVQERRCP.js";
@@ -872,11 +872,112 @@ import { randomUUID as randomUUID3 } from "crypto";
872
872
  import { existsSync, readFileSync, writeFileSync, renameSync, openSync, closeSync, fsyncSync } from "fs";
873
873
  var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
874
874
  import { dirname } from "path";
875
+
876
+ // src/lib/upfront-payment.ts
877
+ function parseUpfrontRailPayment(value) {
878
+ if (!value || typeof value !== "object") return void 0;
879
+ const raw = value;
880
+ if (!["cashu", "x402", "tempo"].includes(raw.method) || !Number.isSafeInteger(raw.amountMsats) || raw.amountMsats < 0) return void 0;
881
+ return { method: raw.method, amountMsats: raw.amountMsats };
882
+ }
883
+ function parseUpfrontPayment(value) {
884
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
885
+ const raw = value;
886
+ if (!Number.isSafeInteger(raw.amount_msats) || Number(raw.amount_msats) < 0) return void 0;
887
+ for (const key of ["amount_micro", "native_amount"]) {
888
+ if (raw[key] !== void 0 && (!Number.isSafeInteger(raw[key]) || Number(raw[key]) < 0)) return void 0;
889
+ }
890
+ if (raw.amount_micro === void 0 !== (raw.currency === void 0) || raw.currency !== void 0 && (typeof raw.currency !== "string" || !/^[a-z]{3}$/.test(raw.currency))) return void 0;
891
+ if (raw.credit_id === void 0 !== (raw.draw_id === void 0)) return void 0;
892
+ for (const key of ["credit_id", "draw_id", "native_asset"]) {
893
+ if (raw[key] !== void 0 && (typeof raw[key] !== "string" || raw[key].trim().length === 0)) return void 0;
894
+ }
895
+ if (raw.rail !== void 0 && !["cashu", "x402", "tempo", "lightning"].includes(String(raw.rail))) return void 0;
896
+ return {
897
+ amount_msats: raw.amount_msats,
898
+ ...raw.amount_micro !== void 0 ? { amount_micro: raw.amount_micro, currency: raw.currency } : {},
899
+ ...raw.rail !== void 0 ? { rail: raw.rail } : {},
900
+ ...raw.native_amount !== void 0 ? { native_amount: raw.native_amount } : {},
901
+ ...raw.native_asset !== void 0 ? { native_asset: raw.native_asset } : {},
902
+ ...raw.credit_id !== void 0 ? { credit_id: raw.credit_id, draw_id: raw.draw_id } : {}
903
+ };
904
+ }
905
+
906
+ // src/lib/job-store.ts
875
907
  function saveJob(job) {
876
908
  mutateJobs((jobs) => {
877
909
  jobs.push(job);
878
910
  });
879
911
  }
912
+ function saveSubmittedJob(job) {
913
+ mutateJobs((jobs) => {
914
+ const existing = jobs.find((entry) => entry.id === job.id);
915
+ if (!existing) jobs.push(job);
916
+ else if (existing.endpoint !== job.endpoint || existing.requestId && existing.requestId !== job.requestId)
917
+ throw new Error("Submitted job conflicts with an existing local job.");
918
+ });
919
+ }
920
+ function recordUpfrontCreditPayment(jobId, value, paidOnRail = false) {
921
+ const payment = parseUpfrontPayment(value);
922
+ mutateJobs((jobs) => {
923
+ const job = jobs.find((entry) => entry.id === jobId);
924
+ if (!job || !payment) return;
925
+ if (paidOnRail || job.paymentMethod && job.paymentMethod !== "credit") {
926
+ job.upfrontPayment ??= payment;
927
+ return;
928
+ }
929
+ if (!payment.credit_id || !payment.draw_id) {
930
+ if (job.paymentMethod === "credit") job.upfrontCreditConflict = true;
931
+ return;
932
+ }
933
+ const binding = job.creditBinding;
934
+ if (!binding || "unbound" in binding || binding.creditId !== payment.credit_id || binding.drawId !== payment.draw_id) {
935
+ job.upfrontCreditConflict = true;
936
+ return;
937
+ }
938
+ if (job.upfrontPayment && JSON.stringify(job.upfrontPayment) !== JSON.stringify(payment)) {
939
+ job.upfrontCreditConflict = true;
940
+ return;
941
+ }
942
+ job.upfrontPayment = payment;
943
+ job.paymentMethod = "credit";
944
+ if (job.upfrontCreditBooked) return;
945
+ job.totalPaidMsats = (job.totalPaidMsats ?? 0) + payment.amount_msats;
946
+ job.paymentsHonoured = (job.paymentsHonoured ?? 0) + (payment.amount_msats > 0 ? 1 : 0);
947
+ job.upfrontCreditBooked = true;
948
+ });
949
+ }
950
+ function hasUnknownUpfrontCredit(job) {
951
+ return job.upfrontCreditConflict === true || job.paymentMethod === "credit" && (!job.upfrontCreditBooked || !parseUpfrontPayment(job.upfrontPayment));
952
+ }
953
+ function recordUpfrontRailPayment(jobId, value, freshSubmit = false) {
954
+ const payment = parseUpfrontRailPayment(value);
955
+ mutateJobs((jobs) => {
956
+ const job = jobs.find((entry) => entry.id === jobId);
957
+ if (!job) return;
958
+ const booked = parseUpfrontRailPayment(job.upfrontRailPayment);
959
+ if (booked) {
960
+ if (payment && (booked.method !== payment.method || booked.amountMsats !== payment.amountMsats))
961
+ job.upfrontRailConflict = true;
962
+ return;
963
+ }
964
+ if (value === "free" || job.upfrontRailPayment === "free" && !payment) {
965
+ job.upfrontRailPayment = "free";
966
+ return;
967
+ }
968
+ if (!payment || !freshSubmit && ((job.totalPaidMsats ?? 0) !== 0 || (job.paymentsHonoured ?? 0) !== 0)) {
969
+ job.upfrontRailPayment = "unknown";
970
+ return;
971
+ }
972
+ job.totalPaidMsats = (job.totalPaidMsats ?? 0) + payment.amountMsats;
973
+ job.paymentsHonoured = (job.paymentsHonoured ?? 0) + (payment.amountMsats > 0 ? 1 : 0);
974
+ job.paymentMethod = payment.method;
975
+ job.upfrontRailPayment = payment;
976
+ });
977
+ }
978
+ function hasUnknownUpfrontRail(job) {
979
+ return job.upfrontRailPayment === "unknown" || job.upfrontRailConflict === true;
980
+ }
880
981
  function updateJob(id, update) {
881
982
  mutateJobs((jobs) => {
882
983
  const idx = jobs.findIndex((j) => j.id === id);
@@ -905,15 +1006,53 @@ function loadAllJobs() {
905
1006
  return [];
906
1007
  }
907
1008
  }
908
- function addPayment(jobId, amountMsats) {
1009
+ function addPayment(jobId, amountMsats, approval) {
909
1010
  mutateJobs((jobs) => {
910
1011
  const job = jobs.find((entry) => entry.id === jobId);
911
1012
  if (!job) return;
912
1013
  job.totalPaidMsats = (job.totalPaidMsats ?? 0) + amountMsats;
913
1014
  job.paymentsHonoured = (job.paymentsHonoured ?? 0) + 1;
1015
+ if (approval) (job.paymentApprovals ??= []).push(approval);
914
1016
  if (job.creditBinding && "unbound" in job.creditBinding) delete job.creditBinding;
915
1017
  });
916
1018
  }
1019
+ function markPaymentRequestInFlight(jobId, requestSeq) {
1020
+ mutateJobs((jobs) => {
1021
+ const job = jobs.find((entry) => entry.id === jobId);
1022
+ if (job) {
1023
+ if (!job.inFlightPaymentRequestSeqs?.includes(requestSeq))
1024
+ (job.inFlightPaymentRequestSeqs ??= []).push(requestSeq);
1025
+ (job.inFlightPaymentRequestStartedAtMs ??= {})[requestSeq] = Date.now();
1026
+ }
1027
+ });
1028
+ }
1029
+ function clearPaymentRequestInFlight(jobId, requestSeq) {
1030
+ mutateJobs((jobs) => {
1031
+ const job = jobs.find((entry) => entry.id === jobId);
1032
+ if (!job?.inFlightPaymentRequestSeqs) return;
1033
+ job.inFlightPaymentRequestSeqs = job.inFlightPaymentRequestSeqs.filter((seq) => seq !== requestSeq);
1034
+ if (!job.inFlightPaymentRequestSeqs.length) delete job.inFlightPaymentRequestSeqs;
1035
+ clearPaymentRequestStartTime(job, requestSeq);
1036
+ });
1037
+ }
1038
+ function markPaymentRequestPaid(jobId, requestSeq) {
1039
+ mutateJobs((jobs) => {
1040
+ const job = jobs.find((entry) => entry.id === jobId);
1041
+ if (!job) return;
1042
+ if (!job.paidPaymentRequestSeqs?.includes(requestSeq))
1043
+ (job.paidPaymentRequestSeqs ??= []).push(requestSeq);
1044
+ if (job.inFlightPaymentRequestSeqs) {
1045
+ job.inFlightPaymentRequestSeqs = job.inFlightPaymentRequestSeqs.filter((seq) => seq !== requestSeq);
1046
+ if (!job.inFlightPaymentRequestSeqs.length) delete job.inFlightPaymentRequestSeqs;
1047
+ }
1048
+ clearPaymentRequestStartTime(job, requestSeq);
1049
+ });
1050
+ }
1051
+ function clearPaymentRequestStartTime(job, requestSeq) {
1052
+ if (!job.inFlightPaymentRequestStartedAtMs) return;
1053
+ delete job.inFlightPaymentRequestStartedAtMs[requestSeq];
1054
+ if (!Object.keys(job.inFlightPaymentRequestStartedAtMs).length) delete job.inFlightPaymentRequestStartedAtMs;
1055
+ }
917
1056
  function writeJobs(jobs) {
918
1057
  ensureConfigDir();
919
1058
  const temporary = `${JOBS_FILE}.${process.pid}.tmp`;
@@ -960,6 +1099,10 @@ function bookCreditPayment(jobId, intent) {
960
1099
  job.totalPaidMsats = (job.totalPaidMsats ?? 0) + (intent.amountMsats ?? intent.request.amount_msats);
961
1100
  job.paymentsHonoured = (job.paymentsHonoured ?? 0) + 1;
962
1101
  (job.bookedCreditPayments ??= []).push(intent);
1102
+ if (intent.approval) (job.paymentApprovals ??= []).push({
1103
+ requestSeq: intent.authorization.request_seq,
1104
+ approval: intent.approval
1105
+ });
963
1106
  }
964
1107
  if (job.pendingCreditPayment?.authorization.payment_id === intent.authorization.payment_id)
965
1108
  delete job.pendingCreditPayment;
@@ -6231,12 +6374,22 @@ function errorMessage(err) {
6231
6374
  }
6232
6375
 
6233
6376
  export {
6377
+ parseUpfrontRailPayment,
6378
+ parseUpfrontPayment,
6234
6379
  saveJob,
6380
+ saveSubmittedJob,
6381
+ recordUpfrontCreditPayment,
6382
+ hasUnknownUpfrontCredit,
6383
+ recordUpfrontRailPayment,
6384
+ hasUnknownUpfrontRail,
6235
6385
  updateJob,
6236
6386
  markJobTerminal,
6237
6387
  loadJob,
6238
6388
  loadAllJobs,
6239
6389
  addPayment,
6390
+ markPaymentRequestInFlight,
6391
+ clearPaymentRequestInFlight,
6392
+ markPaymentRequestPaid,
6240
6393
  mutateCreditPayment,
6241
6394
  bookCreditPayment,
6242
6395
  loadFavorites,
@@ -6,9 +6,9 @@ import {
6
6
  } from "./chunk-R2DSAZBO.js";
7
7
  import {
8
8
  diagnosticConsole
9
- } from "./chunk-IEWV3CM2.js";
9
+ } from "./chunk-UVFFMKU4.js";
10
10
 
11
- // node_modules/@dvmkit/sdk/dist/chunk-566CFXGU.js
11
+ // node_modules/@dvmkit/sdk/dist/chunk-IVW5UMD3.js
12
12
  import { randomUUID } from "crypto";
13
13
  var ENDPOINTS = {
14
14
  job_terminal: "/_internal/job-terminal",