@dvmkit/dvm-cli 0.17.0 → 0.18.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.
package/README.md CHANGED
@@ -30,7 +30,7 @@ Keep the skill and CLI on the same package version. After `npm update --global @
30
30
 
31
31
  ## First job
32
32
 
33
- For a first job, ask your agent: "Load the dvm skill, find a service for my task, and show me its price before spending." The skill's calling procedure takes over from discovery through submitting a job and retrieving its result. If payment is needed, its wallet procedure explains the human steps for connecting or funding a wallet. Commands return structured JSON by default; use `--human` for direct terminal reading.
33
+ For a first job, ask your agent: "Load the dvm skill, find a service for my task, and show me its price before spending." The skill's calling procedure takes over from discovery through submitting a job and retrieving its result. If payment is needed, its wallet procedure explains the human steps for connecting or funding a wallet. Commands return structured JSON by default; use `--human` for direct terminal reading. `dvm messages <job-id> --wait` instead writes one JSON object per line as the job runs, ending with a `result` or `error` line; the [calling procedure](skills/dvm/calling.md#run-and-deliver) explains how to read it.
34
34
 
35
35
  ## What's in the package
36
36
 
@@ -106,6 +106,9 @@ function json(data) {
106
106
  const out = _traceId !== null && typeof data === "object" && data !== null && !Array.isArray(data) && !("trace_id" in data) ? { trace_id: _traceId, ...data } : data;
107
107
  writeAllSync(1, JSON.stringify(out) + "\n");
108
108
  }
109
+ function jsonEvent(data) {
110
+ writeAllSync(1, JSON.stringify(data) + "\n");
111
+ }
109
112
  function info(msg) {
110
113
  writeAllSync(2, msg + "\n");
111
114
  }
@@ -454,12 +457,10 @@ export {
454
457
  setOutputTraceId,
455
458
  getOutputTraceId,
456
459
  json,
460
+ jsonEvent,
457
461
  info,
458
462
  raw,
459
463
  progress,
460
- resolveBtcUsdRate,
461
- tryResolveBtcUsdRate,
462
- staleRateNotice,
463
464
  formatSats,
464
465
  formatAmount,
465
466
  formatPaymentAmount,
@@ -468,5 +469,8 @@ export {
468
469
  parseBudget,
469
470
  assertValidBudget,
470
471
  formatAmountBestEffort,
472
+ resolveBtcUsdRate,
473
+ tryResolveBtcUsdRate,
474
+ staleRateNotice,
471
475
  tryX402Payment
472
476
  };
@@ -26,7 +26,7 @@ import {
26
26
  resolveBtcUsdRate,
27
27
  tryResolveBtcUsdRate,
28
28
  tryX402Payment
29
- } from "./chunk-R6FZT6S2.js";
29
+ } from "./chunk-RYFCHR6Z.js";
30
30
  import {
31
31
  BUDGET_FILE,
32
32
  CONFIG_DIR,
@@ -352,6 +352,11 @@ function parseDurationMs(input) {
352
352
  };
353
353
  return count * unitMs[match[2]];
354
354
  }
355
+ function formatDurationMs(ms) {
356
+ for (const [unit, size] of [["d", 864e5], ["h", 36e5], ["m", 6e4]])
357
+ if (ms >= size && ms % size === 0) return `${ms / size}${unit}`;
358
+ return `${Math.ceil(ms / 1e3)}s`;
359
+ }
355
360
 
356
361
  // src/commands/wallet-history.ts
357
362
  var DEFAULT_LIMIT = 50;
@@ -2476,17 +2481,36 @@ function fsyncDirectory2(path) {
2476
2481
  }
2477
2482
  }
2478
2483
 
2484
+ // src/lib/payment-bookings.ts
2485
+ var listeners = /* @__PURE__ */ new Set();
2486
+ function observePaymentBookings(listener) {
2487
+ listeners.add(listener);
2488
+ return () => {
2489
+ listeners.delete(listener);
2490
+ };
2491
+ }
2492
+ function notifyPaymentBooked(booking) {
2493
+ for (const listener of listeners) listener(booking);
2494
+ }
2495
+
2479
2496
  // src/lib/job-store.ts
2480
2497
  import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3, renameSync, openSync as openSync3, closeSync as closeSync3, fsyncSync as fsyncSync3 } from "fs";
2481
2498
  var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
2482
2499
  import { dirname } from "path";
2483
2500
 
2484
2501
  // src/lib/upfront-payment.ts
2502
+ function upfrontRailPayment(method, amountMsats, usdMicro2) {
2503
+ return { method, amountMsats, ...usdMicro2 !== void 0 ? { usdMicro: usdMicro2 } : {} };
2504
+ }
2485
2505
  function parseUpfrontRailPayment(value) {
2486
2506
  if (!value || typeof value !== "object") return void 0;
2487
2507
  const raw = value;
2488
2508
  if (!["cashu", "x402", "tempo"].includes(raw.method) || !Number.isSafeInteger(raw.amountMsats) || raw.amountMsats < 0) return void 0;
2489
- return { method: raw.method, amountMsats: raw.amountMsats };
2509
+ return {
2510
+ method: raw.method,
2511
+ amountMsats: raw.amountMsats,
2512
+ ...Number.isSafeInteger(raw.usdMicro) && raw.usdMicro >= 0 ? { usdMicro: raw.usdMicro } : {}
2513
+ };
2490
2514
  }
2491
2515
  function parseUpfrontPayment(value) {
2492
2516
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
@@ -2511,6 +2535,52 @@ function parseUpfrontPayment(value) {
2511
2535
  };
2512
2536
  }
2513
2537
 
2538
+ // src/lib/job-budget.ts
2539
+ var ASK_SAT_ROUNDING_MSATS = 1e3;
2540
+ function budgetVerdict(policy, ledger, ask) {
2541
+ const spentMsats = ledger?.totalPaidMsats ?? 0;
2542
+ const cap = policy.maxTotalUsdMicro;
2543
+ const paidUsd = ledger?.paidUsdMicro ?? 0;
2544
+ const askUsd = dollarBoundUsdMicro(ask);
2545
+ if (validMicro(cap) && askUsd !== void 0 && dollarLedgerComplete(ledger) && validMicro(paidUsd)) {
2546
+ const total2 = paidUsd + askUsd;
2547
+ return total2 > cap ? { fits: false, unit: "usd", spent: paidUsd, ask: askUsd, total: total2, cap } : { fits: true, unit: "usd" };
2548
+ }
2549
+ const total = spentMsats + ask.msats;
2550
+ return total > policy.maxTotalMsats ? { fits: false, unit: "msats", spent: spentMsats, ask: ask.msats, total, cap: policy.maxTotalMsats } : { fits: true, unit: "msats" };
2551
+ }
2552
+ function dollarBoundUsdMicro(ask) {
2553
+ const { msats, usdMicro: dollars, rate } = ask;
2554
+ if (dollars === void 0 || !validMicro(dollars) || dollars <= 0 || !Number.isSafeInteger(msats) || msats < 0 || rate === void 0 || !Number.isFinite(rate) || rate <= 0) return void 0;
2555
+ return msats <= usdToMsats(dollars / 1e6, rate) + ASK_SAT_ROUNDING_MSATS ? dollars : void 0;
2556
+ }
2557
+ function askUsdMicro(request) {
2558
+ const credit = request.credit;
2559
+ if (credit) return usdMicro(credit.amount_micro, credit.currency);
2560
+ const required = request.x402?.required_usdc_micro;
2561
+ return typeof required === "string" && /^\d+$/.test(required) ? usdMicro(Number(required), "usd") : void 0;
2562
+ }
2563
+ function usdMicro(amountMicro, currency) {
2564
+ return typeof currency === "string" && currency.toLowerCase() === "usd" && validMicro(amountMicro) ? amountMicro : void 0;
2565
+ }
2566
+ function describeBudgetOverrun(verdict, policy) {
2567
+ const figures = [verdict.spent, verdict.ask, verdict.total, verdict.cap];
2568
+ const format = verdict.unit === "usd" ? formatUsdMicro : figures.every((msats) => msats % 1e3 === 0) ? formatSats : (msats) => `${msats.toLocaleString("en-US")} msats`;
2569
+ const declared = verdict.unit === "msats" && policy?.maxTotalUsdMicro !== void 0 ? ` (your ${formatUsdMicro(policy.maxTotalUsdMicro)} budget, converted to sats when the budget was set)` : "";
2570
+ return `This charge would take the job past its budget: ${format(verdict.spent)} spent so far plus ${format(verdict.ask)} asked comes to ${format(verdict.total)}, ${format(verdict.total - verdict.cap)} over the ${format(verdict.cap)} budget${declared}.`;
2571
+ }
2572
+ function formatUsdMicro(micro) {
2573
+ const whole = Math.floor(micro / 1e6);
2574
+ const fraction = String(micro % 1e6).padStart(6, "0").replace(/0+$/, "").padEnd(2, "0");
2575
+ return `$${whole.toLocaleString("en-US")}.${fraction}`;
2576
+ }
2577
+ function dollarLedgerComplete(ledger) {
2578
+ return (ledger?.paidUsdMsats ?? 0) === (ledger?.totalPaidMsats ?? 0);
2579
+ }
2580
+ function validMicro(value) {
2581
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
2582
+ }
2583
+
2514
2584
  // src/lib/job-store.ts
2515
2585
  function saveJob(job) {
2516
2586
  mutateJobs((jobs) => {
@@ -2556,6 +2626,7 @@ function recordUpfrontCreditPayment(jobId, value, paidOnRail = false) {
2556
2626
  job.paymentMethod = "credit";
2557
2627
  if (job.upfrontCreditBooked) return;
2558
2628
  job.totalPaidMsats = (job.totalPaidMsats ?? 0) + payment.amount_msats;
2629
+ bookUsd(job, payment.amount_msats, usdMicro(payment.amount_micro, payment.currency));
2559
2630
  job.paymentsHonoured = (job.paymentsHonoured ?? 0) + (payment.amount_msats > 0 ? 1 : 0);
2560
2631
  job.upfrontCreditBooked = true;
2561
2632
  }, true);
@@ -2583,6 +2654,7 @@ function recordUpfrontRailPayment(jobId, value, freshSubmit = false) {
2583
2654
  return;
2584
2655
  }
2585
2656
  job.totalPaidMsats = (job.totalPaidMsats ?? 0) + payment.amountMsats;
2657
+ bookUsd(job, payment.amountMsats, payment.usdMicro);
2586
2658
  job.paymentsHonoured = (job.paymentsHonoured ?? 0) + (payment.amountMsats > 0 ? 1 : 0);
2587
2659
  job.paymentMethod = payment.method;
2588
2660
  job.upfrontRailPayment = payment;
@@ -2633,18 +2705,30 @@ function loadAllJobs() {
2633
2705
  return [];
2634
2706
  }
2635
2707
  }
2636
- function addPayment(jobId, amountMsats, approval) {
2708
+ function addPayment(jobId, amountMsats, approval, usdMicro2) {
2637
2709
  mutateJobs((jobs) => {
2638
2710
  const job = jobs.find((entry) => entry.id === jobId);
2639
- if (job) bookPayment(job, amountMsats, approval);
2711
+ if (job) bookPayment(job, amountMsats, approval, usdMicro2);
2640
2712
  }, true);
2641
2713
  }
2642
- function bookPayment(job, amountMsats, approval) {
2714
+ function bookPayment(job, amountMsats, approval, usdMicro2) {
2643
2715
  job.totalPaidMsats = (job.totalPaidMsats ?? 0) + amountMsats;
2716
+ bookUsd(job, amountMsats, usdMicro2);
2644
2717
  job.paymentsHonoured = (job.paymentsHonoured ?? 0) + 1;
2645
2718
  if (approval) (job.paymentApprovals ??= []).push(approval);
2646
2719
  if (job.creditBinding && "unbound" in job.creditBinding) delete job.creditBinding;
2647
2720
  }
2721
+ function bookUsd(job, amountMsats, usdMicro2) {
2722
+ if (usdMicro2 === void 0 || !Number.isSafeInteger(usdMicro2) || usdMicro2 < 0) return;
2723
+ job.paidUsdMicro = (job.paidUsdMicro ?? 0) + usdMicro2;
2724
+ job.paidUsdMsats = (job.paidUsdMsats ?? 0) + amountMsats;
2725
+ }
2726
+ function recordBudgetRefusal(jobId, requestSeq, overrun) {
2727
+ mutateJobs((jobs) => {
2728
+ const job = jobs.find((entry) => entry.id === jobId);
2729
+ if (job) (job.budgetRefusals ??= {})[String(requestSeq)] = overrun;
2730
+ }, true);
2731
+ }
2648
2732
  function markPaymentRequestInFlight(jobId, requestSeq, submission) {
2649
2733
  mutateJobs((jobs) => {
2650
2734
  const job = jobs.find((entry) => entry.id === jobId);
@@ -2685,14 +2769,24 @@ function markPaymentRequestPaid(jobId, requestSeq) {
2685
2769
  clearPaymentRequestStartTime(job, requestSeq);
2686
2770
  const booked3 = job.unconfirmedPaymentSubmissions?.[requestSeq];
2687
2771
  clearUnconfirmedSubmission(job, requestSeq);
2688
- if (booked3) bookPayment(job, booked3.amountMsats, booked3.approval ? { requestSeq, approval: booked3.approval } : void 0);
2772
+ if (booked3) bookPayment(job, booked3.amountMsats, booked3.approval ? { requestSeq, approval: booked3.approval } : void 0, booked3.usdMicro);
2689
2773
  if (booked3 && !booked3.blocked && job.askPaymentBlocks?.[requestSeq]) {
2690
2774
  delete job.askPaymentBlocks[requestSeq];
2691
2775
  if (!Object.keys(job.askPaymentBlocks).length) delete job.askPaymentBlocks;
2692
2776
  }
2693
2777
  return booked3;
2694
2778
  }, true);
2695
- return hasUnsavedJobState() ? void 0 : booked2;
2779
+ if (!booked2 || hasUnsavedJobState()) return void 0;
2780
+ notifyPaymentBooked({
2781
+ jobId,
2782
+ requestSeq,
2783
+ approval: booked2.approval,
2784
+ rail: booked2.rail,
2785
+ amountMsats: booked2.amountMsats,
2786
+ reason: booked2.reason,
2787
+ ...booked2.rail !== "cashu_p2pk" && booked2.amountUsdcMicro !== void 0 ? { amountUsdcMicro: booked2.amountUsdcMicro } : {}
2788
+ });
2789
+ return booked2;
2696
2790
  }
2697
2791
  function markPaymentRequestAnswered(jobId, requestSeq) {
2698
2792
  mutateJobs((jobs) => {
@@ -2924,9 +3018,13 @@ function mutateCreditPayment(jobId, change, observed = false) {
2924
3018
  }, observed);
2925
3019
  }
2926
3020
  function bookCreditPayment(jobId, intent) {
2927
- mutateCreditPayment(jobId, (job) => {
3021
+ const booked2 = mutateCreditPayment(jobId, (job) => {
3022
+ let booked3 = false;
2928
3023
  if (!job.bookedCreditPayments?.some((entry) => entry.authorization.payment_id === intent.authorization.payment_id)) {
2929
- job.totalPaidMsats = (job.totalPaidMsats ?? 0) + (intent.amountMsats ?? intent.request.amount_msats);
3024
+ booked3 = true;
3025
+ const amountMsats = intent.amountMsats ?? intent.request.amount_msats;
3026
+ job.totalPaidMsats = (job.totalPaidMsats ?? 0) + amountMsats;
3027
+ bookUsd(job, amountMsats, usdMicro(intent.authorization.amount_micro, intent.authorization.currency));
2930
3028
  job.paymentsHonoured = (job.paymentsHonoured ?? 0) + 1;
2931
3029
  (job.bookedCreditPayments ??= []).push(intent);
2932
3030
  if (intent.approval) (job.paymentApprovals ??= []).push({
@@ -2936,7 +3034,16 @@ function bookCreditPayment(jobId, intent) {
2936
3034
  }
2937
3035
  if (job.pendingCreditPayment?.authorization.payment_id === intent.authorization.payment_id)
2938
3036
  delete job.pendingCreditPayment;
3037
+ return booked3;
2939
3038
  }, true);
3039
+ if (booked2 && !hasUnsavedJobState()) notifyPaymentBooked({
3040
+ jobId,
3041
+ requestSeq: intent.authorization.request_seq,
3042
+ approval: intent.approval,
3043
+ rail: "credit",
3044
+ amountMsats: intent.amountMsats ?? intent.request.amount_msats,
3045
+ reason: intent.request.reason
3046
+ });
2940
3047
  }
2941
3048
 
2942
3049
  // src/lib/favorites.ts
@@ -4800,13 +4907,24 @@ function computeNextAction(jobId, messages, nowMs = Date.now(), context) {
4800
4907
  const deadline = deadlineClause(expiresAtMs === validDeadline(c.expires_at_ms) ? "Pay" : "Reply", expiresAtMs, nowMs, jobId);
4801
4908
  const expired = expiresAtMs !== void 0 && expiresAtMs <= nowMs;
4802
4909
  const policy = context?.policy;
4803
- const thresholdHint = !expired && policy && Number.isSafeInteger(c.amount_msats) && c.amount_msats > policy.autoPayBelowMsats && (context?.totalPaidMsats ?? 0) + c.amount_msats <= policy.maxTotalMsats && (policy.maxIncrementMsats === 0 || c.amount_msats <= policy.maxIncrementMsats) ? ` For the next run, use --auto-pay-below ${c.amount_msats} within your approved budget; other payment limits still apply.` : "";
4910
+ const budget = policy && (context?.budgetRefusals?.[String(msg.seq)] ?? (Number.isSafeInteger(c.amount_msats) ? budgetVerdict(policy, context, {
4911
+ msats: c.amount_msats,
4912
+ usdMicro: askUsdMicro(c),
4913
+ // The payer resolves a live rate; a next step reads the last one this machine saw.
4914
+ rate: getLastKnownBtcRate()?.rate
4915
+ }) : void 0));
4916
+ const thresholdHint = !expired && policy && budget?.fits && c.amount_msats > policy.autoPayBelowMsats && (policy.maxIncrementMsats === 0 || c.amount_msats <= policy.maxIncrementMsats) ? ` For the next run, use --auto-pay-below ${c.amount_msats} within your approved budget; other payment limits still apply.` : "";
4917
+ const countExhausted = !expired && policy && (context?.paymentsHonoured ?? 0) >= policy.maxPayments;
4918
+ const explicitIncrement = policy && (policy.maxIncrementExplicit ?? policy.maxIncrementMsats !== policy.maxTotalMsats);
4919
+ const overIncrement = !expired && explicitIncrement && policy && policy.maxIncrementMsats > 0 && c.amount_msats > policy.maxIncrementMsats;
4920
+ const incrementHint = `This charge exceeds the job's --max-increment limit, which cannot be changed on a running job. Relay it to your human. To stop, run \`dvm decline ${guidanceJobArg(jobId)}\`; further work needs a new request with approved limits.`;
4804
4921
  const stopping = declineTerms(c);
4805
4922
  const providerFields2 = [];
4806
4923
  if (c.fiat_amount && c.fiat_amount.amount > 0) providerFields2.push("fiat_amount");
4807
4924
  if (stopping?.credit) providerFields2.push("credit");
4808
4925
  if (stopping) providerFields2.push("charged_if_declined_micro");
4809
4926
  const declineHint = stopping ? ` If your human does not approve, run \`dvm decline ${guidanceJobArg(jobId)}\`: ${stopping.clause} Letting the deadline pass also ends the job.` : "";
4927
+ const overBudget = !expired && budget && !budget.fits ? describeBudgetOverrun(budget, policy) : void 0;
4810
4928
  return {
4811
4929
  type: "pay",
4812
4930
  job_id: jobId,
@@ -4816,9 +4934,9 @@ function computeNextAction(jobId, messages, nowMs = Date.now(), context) {
4816
4934
  ...stopping ? { charged_if_declined_micro: stopping.micro } : {},
4817
4935
  ...providerFields2.length ? { _provider_fields: providerFields2 } : {},
4818
4936
  ...expiresAtMs !== void 0 ? { expires_at_ms: expiresAtMs } : {},
4819
- display: withDeadline(stopping ? `${withPeriod(display)} ${stopping.clause}` : display, deadline),
4937
+ display: withDeadline(overBudget || stopping ? [withPeriod(display), overBudget, stopping?.clause].filter(Boolean).join(" ") : display, deadline),
4820
4938
  reason: asProviderText(c.reason),
4821
- hint: expired ? deadline : withDeadline(`Payment required to continue: ${priceGuidance}. Relay that amount to your human and get approval, then run \`dvm pay ${guidanceJobArg(jobId)}\`. Provider's stated reason is wrapped as { _source: "provider", text: ... } \u2014 verify it matches the work you expect.${declineHint}`, deadline) + thresholdHint
4939
+ hint: expired ? deadline : countExhausted ? withDeadline(paymentCountHint(jobId, policy.maxPayments), deadline) : overIncrement ? withDeadline(incrementHint + declineHint, deadline) : overBudget ? withDeadline(overBudgetHint(jobId, overBudget, stopping?.clause), deadline) : withDeadline(`Payment required to continue: ${priceGuidance}. Relay that amount to your human and get approval, then run \`dvm pay ${guidanceJobArg(jobId)}\`. Provider's stated reason is wrapped as { _source: "provider", text: ... } \u2014 verify it matches the work you expect.${declineHint}`, deadline) + thresholdHint
4822
4940
  };
4823
4941
  }
4824
4942
  case "working": {
@@ -4834,6 +4952,13 @@ function computeNextAction(jobId, messages, nowMs = Date.now(), context) {
4834
4952
  }
4835
4953
  return null;
4836
4954
  }
4955
+ function paymentCountHint(jobId, cap) {
4956
+ return `This job has used its ${cap}-payment limit. A higher budget cannot authorize another payment. To stop and keep finished work, run \`dvm decline ${guidanceJobArg(jobId)}\`. Further work needs a new request with human-approved limits.`;
4957
+ }
4958
+ function overBudgetHint(jobId, overrun, declineClause) {
4959
+ const job = guidanceJobArg(jobId);
4960
+ return `${overrun} Ask your human to approve a new total budget first, then run \`dvm pay ${job} --budget <new total>\` to save it and pay this ask. Other payment limits still apply. To stop, run \`dvm decline ${job}\`${declineClause ? `: ${declineClause}` : "."}`;
4961
+ }
4837
4962
  function declineTerms(ask) {
4838
4963
  const micro = ask.charged_if_declined_micro;
4839
4964
  if (typeof micro !== "number" || !Number.isSafeInteger(micro) || micro < 0) return void 0;
@@ -5050,7 +5175,7 @@ function paidCeiling(job, messages, settlement, currency, ending) {
5050
5175
  asks.set(message.seq, message.content);
5051
5176
  latestAsk = message.seq;
5052
5177
  const declined = message.content.charged_if_declined_micro;
5053
- if (validMicro(declined) && sameCurrency(message.content.credit?.currency, currency)) {
5178
+ if (validMicro2(declined) && sameCurrency(message.content.credit?.currency, currency)) {
5054
5179
  finished = declined;
5055
5180
  afterAsk = 0;
5056
5181
  }
@@ -5058,7 +5183,7 @@ function paidCeiling(job, messages, settlement, currency, ending) {
5058
5183
  const credit = message.content.credit;
5059
5184
  const ask = asks.get(credit?.request_seq ?? latestAsk ?? -1)?.credit;
5060
5185
  const price = credit ? credit : ask;
5061
- if (!price || !validMicro(price.amount_micro) || !sameCurrency(price.currency, currency)) return void 0;
5186
+ if (!price || !validMicro2(price.amount_micro) || !sameCurrency(price.currency, currency)) return void 0;
5062
5187
  paid += price.amount_micro;
5063
5188
  afterAsk += price.amount_micro;
5064
5189
  }
@@ -5068,7 +5193,7 @@ function paidCeiling(job, messages, settlement, currency, ending) {
5068
5193
  }
5069
5194
  function declineCap(job, messages) {
5070
5195
  const ask = messages.findLast((message) => message.from === "provider" && message.type === "payment-request");
5071
- if (!ask || !validMicro(ask.content.charged_if_declined_micro)) return void 0;
5196
+ if (!ask || !validMicro2(ask.content.charged_if_declined_micro)) return void 0;
5072
5197
  const recorded = [
5073
5198
  ...job.paidPaymentRequestSeqs ?? [],
5074
5199
  ...job.inFlightPaymentRequestSeqs ?? [],
@@ -5078,7 +5203,7 @@ function declineCap(job, messages) {
5078
5203
  const paidAsk = answeredYieldSeqs(messages).has(ask.seq) || recorded.includes(ask.seq);
5079
5204
  if (!paidAsk) return ask.content.charged_if_declined_micro;
5080
5205
  const price = ask.content.credit?.amount_micro;
5081
- return validMicro(price) ? ask.content.charged_if_declined_micro + price : void 0;
5206
+ return validMicro2(price) ? ask.content.charged_if_declined_micro + price : void 0;
5082
5207
  }
5083
5208
  function wholeThroughEnd(messages) {
5084
5209
  if (messages.length === 0 || messages[0].seq > 1) return false;
@@ -5107,13 +5232,13 @@ function safeCredits() {
5107
5232
  function sameCurrency(a, b) {
5108
5233
  return typeof a === "string" && a.toLowerCase() === b;
5109
5234
  }
5110
- function validMicro(value) {
5235
+ function validMicro2(value) {
5111
5236
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
5112
5237
  }
5113
5238
  function isSettlement(value) {
5114
5239
  if (!value || typeof value !== "object") return false;
5115
5240
  const s = value;
5116
- return validMicro(s.held) && validMicro(s.charged) && validMicro(s.released) && Array.isArray(s.pieces) && s.pieces.every((piece) => piece && typeof piece === "object" && validMicro(piece.amount) && validMicro(piece.charged) && typeof piece.state === "string");
5241
+ return validMicro2(s.held) && validMicro2(s.charged) && validMicro2(s.released) && Array.isArray(s.pieces) && s.pieces.every((piece) => piece && typeof piece === "object" && validMicro2(piece.amount) && validMicro2(piece.charged) && typeof piece.state === "string");
5117
5242
  }
5118
5243
 
5119
5244
  // src/lib/job-settlement.ts
@@ -9177,8 +9302,16 @@ export {
9177
9302
  loadSubmissionEvidence,
9178
9303
  listSubmissionEvidence,
9179
9304
  journalMarkerFor,
9305
+ observePaymentBookings,
9306
+ upfrontRailPayment,
9180
9307
  parseUpfrontRailPayment,
9181
9308
  parseUpfrontPayment,
9309
+ budgetVerdict,
9310
+ dollarBoundUsdMicro,
9311
+ askUsdMicro,
9312
+ usdMicro,
9313
+ describeBudgetOverrun,
9314
+ formatUsdMicro,
9182
9315
  saveJob,
9183
9316
  saveAcceptedJob,
9184
9317
  saveSubmittedJob,
@@ -9193,6 +9326,7 @@ export {
9193
9326
  loadJob,
9194
9327
  loadAllJobs,
9195
9328
  addPayment,
9329
+ recordBudgetRefusal,
9196
9330
  markPaymentRequestInFlight,
9197
9331
  clearPaymentRequestInFlight,
9198
9332
  markPaymentRequestPaid,
@@ -9264,12 +9398,15 @@ export {
9264
9398
  paymentInFlightHint,
9265
9399
  unresendablePaymentHint,
9266
9400
  computeNextAction,
9401
+ paymentCountHint,
9402
+ overBudgetHint,
9267
9403
  buildTempoCredential,
9268
9404
  completedCreditHistory,
9269
9405
  completedDrainMatches,
9270
9406
  completedServiceMatches,
9271
9407
  completedOriginsOverlap,
9272
9408
  parseDurationMs,
9409
+ formatDurationMs,
9273
9410
  walletHistory,
9274
9411
  dvmLabelFromEndpoint,
9275
9412
  listPendingCardFundings,
@@ -3,7 +3,7 @@ import { createRequire as __dvmCreateRequire } from "node:module";
3
3
  const require = __dvmCreateRequire(import.meta.url);
4
4
  import {
5
5
  tryX402Payment
6
- } from "./chunk-R6FZT6S2.js";
6
+ } from "./chunk-RYFCHR6Z.js";
7
7
  import "./chunk-THTPKBZX.js";
8
8
  import "./chunk-JBU7RKQ3.js";
9
9
  import "./chunk-KDNFUDOG.js";