@dvmkit/dvm-cli 0.13.0 → 0.14.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/dist/{chunk-GWLOO5XD.js → chunk-2MCZ4QOK.js} +2 -2
- package/dist/{chunk-C2BJETRG.js → chunk-57PXJ56K.js} +4 -4
- package/dist/{chunk-RPM5XEVS.js → chunk-CO2TD5RO.js} +2 -2
- package/dist/{chunk-PS4AUWK3.js → chunk-D5CGDS3V.js} +2 -2
- package/dist/{chunk-NLUOHCX2.js → chunk-DU7YCGCQ.js} +214 -21
- package/dist/{chunk-ZDWZT6NA.js → chunk-EZL4IVCU.js} +3 -3
- package/dist/{chunk-I2C3YEUN.js → chunk-HJ2JYBTT.js} +4 -4
- package/dist/{chunk-CCF4QONY.js → chunk-HXTASGHL.js} +2 -2
- package/dist/{chunk-C2EZ3VY2.js → chunk-I7ZBID4L.js} +2 -2
- package/dist/{chunk-ZV57FFIL.js → chunk-UCCT5IKU.js} +9 -1
- package/dist/{chunk-KQQALLOL.js → chunk-UWVMG4VG.js} +3 -3
- package/dist/{chunk-SEJWBDGY.js → chunk-YQJRKWNT.js} +1739 -788
- package/dist/{client-6JRGRKFQ.js → client-DC7TVYNU.js} +6 -6
- package/dist/dvm.js +690 -487
- package/dist/{internal-KPPGYK5N.js → internal-O7IQD6EQ.js} +5 -5
- package/dist/{lifecycle-7YRNRLDQ.js → lifecycle-MIJH3JE4.js} +6 -6
- package/dist/{payout-reporter-KTLBNJJ7-WDT6M4GN.js → payout-reporter-Y6OW3FYD-K6MRWQXK.js} +2 -2
- package/dist/{pocket-refill-E2QVQDME.js → pocket-refill-HEVLAMKN.js} +10 -10
- package/dist/{revenue-reporter-FD3GDQZS-COUBEUDN.js → revenue-reporter-CIG2MEDN-ZXMO6NWG.js} +2 -2
- package/dist/{tempo-lifecycle-EOP5IHJT.js → tempo-lifecycle-FMBCHD2M.js} +8 -8
- package/dist/{tempo-wallet-4A5M3FVO.js → tempo-wallet-U3WBWIIH.js} +7 -7
- package/dist/{wallet-LASVQ72F.js → wallet-Z3FDX43V.js} +7 -7
- package/dist/{x402-MFBRORHG-34VE7EWO.js → x402-ARXZQ5BD-H6PNJYYT.js} +2 -2
- package/package.json +2 -2
- package/skills/dvm/SKILL.md +2 -0
- package/skills/dvm/calling.md +12 -1
- package/skills/dvm/recovery.md +3 -0
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
CONFIG_PINNED_FILE,
|
|
9
9
|
ensureConfigDir,
|
|
10
10
|
require_proper_lockfile
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-YQJRKWNT.js";
|
|
12
12
|
import {
|
|
13
13
|
DvmError
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-57PXJ56K.js";
|
|
15
15
|
import {
|
|
16
16
|
__toESM
|
|
17
17
|
} from "./chunk-IYHTITNZ.js";
|
|
@@ -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-
|
|
6
|
+
} from "./chunk-UCCT5IKU.js";
|
|
7
7
|
import {
|
|
8
8
|
__export
|
|
9
9
|
} from "./chunk-IYHTITNZ.js";
|
|
@@ -3107,7 +3107,7 @@ function buildNoopLoggers() {
|
|
|
3107
3107
|
};
|
|
3108
3108
|
}
|
|
3109
3109
|
|
|
3110
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
3110
|
+
// node_modules/@dvmkit/sdk/dist/chunk-EIL7VIVM.js
|
|
3111
3111
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3112
3112
|
import { createPrivateKey, randomBytes as randomBytes2 } from "crypto";
|
|
3113
3113
|
|
|
@@ -10599,7 +10599,7 @@ var SignJWT = class {
|
|
|
10599
10599
|
}
|
|
10600
10600
|
};
|
|
10601
10601
|
|
|
10602
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
10602
|
+
// node_modules/@dvmkit/sdk/dist/chunk-EIL7VIVM.js
|
|
10603
10603
|
var scopes = new AsyncLocalStorage();
|
|
10604
10604
|
function withPaymentDiagnostics(fn) {
|
|
10605
10605
|
return scopes.run({}, fn);
|
|
@@ -10774,7 +10774,7 @@ function logRejected(stage) {
|
|
|
10774
10774
|
});
|
|
10775
10775
|
}
|
|
10776
10776
|
|
|
10777
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
10777
|
+
// node_modules/@dvmkit/sdk/dist/chunk-E4EXYTEO.js
|
|
10778
10778
|
async function verifyX402Payment(paymentHeader, config, requiredUsdcMicro, resource, btcUsdRate, exactVersions = { v1: true, v2: true }) {
|
|
10779
10779
|
return callerLoggers.x402.span(
|
|
10780
10780
|
"x402.verify_payment",
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
isSignableExactRequirement,
|
|
13
13
|
maxAdvertisedMicro,
|
|
14
14
|
withinAdvertisedTolerance
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-YQJRKWNT.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-
|
|
33
|
+
} from "./chunk-57PXJ56K.js";
|
|
34
34
|
|
|
35
35
|
// src/lib/x402/client.ts
|
|
36
36
|
import { randomBytes } from "crypto";
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
} from "./chunk-R2DSAZBO.js";
|
|
7
7
|
import {
|
|
8
8
|
diagnosticConsole
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-UCCT5IKU.js";
|
|
10
10
|
|
|
11
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
11
|
+
// node_modules/@dvmkit/sdk/dist/chunk-PDWVERRC.js
|
|
12
12
|
import { createHash, randomUUID } from "crypto";
|
|
13
13
|
async function x402EarnedCeiling(channel, earnedNative) {
|
|
14
14
|
let earned;
|
|
@@ -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-
|
|
6
|
+
} from "./chunk-HJ2JYBTT.js";
|
|
7
7
|
import {
|
|
8
8
|
costAnchor,
|
|
9
9
|
formatAmount,
|
|
@@ -15,15 +15,15 @@ import {
|
|
|
15
15
|
resolveBtcUsdRate,
|
|
16
16
|
tryResolveBtcUsdRate,
|
|
17
17
|
tryX402Payment
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-CO2TD5RO.js";
|
|
19
19
|
import {
|
|
20
20
|
loadX402Wallet,
|
|
21
21
|
x402NetworkLabel
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-UWVMG4VG.js";
|
|
23
23
|
import {
|
|
24
24
|
isCreditPosture,
|
|
25
25
|
loadConfig
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-2MCZ4QOK.js";
|
|
27
27
|
import {
|
|
28
28
|
BUDGET_FILE,
|
|
29
29
|
CONFIG_DIR,
|
|
@@ -75,6 +75,7 @@ import {
|
|
|
75
75
|
ensureConfigSubdir,
|
|
76
76
|
entryKind,
|
|
77
77
|
findX402Channel,
|
|
78
|
+
formatFiat,
|
|
78
79
|
formatUsd,
|
|
79
80
|
fundingModeForTempoIntent,
|
|
80
81
|
fundingModeForX402Flavour,
|
|
@@ -178,7 +179,7 @@ import {
|
|
|
178
179
|
x402PendingUnsettled,
|
|
179
180
|
x402RequiredFromError,
|
|
180
181
|
x402VoucherPendingState
|
|
181
|
-
} from "./chunk-
|
|
182
|
+
} from "./chunk-YQJRKWNT.js";
|
|
182
183
|
import {
|
|
183
184
|
Challenge_exports,
|
|
184
185
|
Credential_exports
|
|
@@ -197,7 +198,7 @@ import {
|
|
|
197
198
|
redactUrlsInText,
|
|
198
199
|
usdToMsats,
|
|
199
200
|
x402NetworkToCaip2
|
|
200
|
-
} from "./chunk-
|
|
201
|
+
} from "./chunk-57PXJ56K.js";
|
|
201
202
|
import {
|
|
202
203
|
privateKeyToAccount
|
|
203
204
|
} from "./chunk-EVQERRCP.js";
|
|
@@ -2471,8 +2472,17 @@ function loadAnsweredYieldSeqs(jobId) {
|
|
|
2471
2472
|
const job = loadJob(jobId);
|
|
2472
2473
|
for (const seq of job?.paidPaymentRequestSeqs ?? []) answered.add(seq);
|
|
2473
2474
|
for (const payment of job?.bookedCreditPayments ?? []) answered.add(payment.authorization.request_seq);
|
|
2475
|
+
if (job?.callerDeclined) for (const seq of declinedYieldSeqs(loadMessages(jobId))) answered.add(seq);
|
|
2474
2476
|
return answered;
|
|
2475
2477
|
}
|
|
2478
|
+
function declinedYieldSeqs(messages) {
|
|
2479
|
+
const sorted = [...messages].sort((a, b) => a.seq - b.seq);
|
|
2480
|
+
const decline = sorted.findLast((message) => message.from === "requester" && message.type === "decline");
|
|
2481
|
+
if (!decline) return [];
|
|
2482
|
+
const before = sorted.filter((message) => message.from === "provider" && message.seq < decline.seq);
|
|
2483
|
+
const ask = before.findLast((message) => message.type === "payment-request");
|
|
2484
|
+
return [...ask ? [ask.seq] : [], ...before.filter((message) => message.type === "prompt").map((message) => message.seq)];
|
|
2485
|
+
}
|
|
2476
2486
|
async function reconcileInFlightPaymentRequest(jobId, requestSeq, transport, provider, options) {
|
|
2477
2487
|
const boundedOptions = { ...options, timeoutMs: options.timeoutMs ?? JOB_READ_TIMEOUT_MS };
|
|
2478
2488
|
const history = await boundedPaymentRead(jobId, () => transport.getMessages(jobId, 0, provider, boundedOptions), boundedOptions.timeoutMs);
|
|
@@ -2593,17 +2603,24 @@ function computeNextAction(jobId, messages, nowMs = Date.now(), context) {
|
|
|
2593
2603
|
const expired = expiresAtMs !== void 0 && expiresAtMs <= nowMs;
|
|
2594
2604
|
const policy = context?.policy;
|
|
2595
2605
|
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.` : "";
|
|
2606
|
+
const stopping = declineTerms(c);
|
|
2607
|
+
const providerFields2 = [];
|
|
2608
|
+
if (c.fiat_amount && c.fiat_amount.amount > 0) providerFields2.push("fiat_amount");
|
|
2609
|
+
if (stopping?.credit) providerFields2.push("credit");
|
|
2610
|
+
if (stopping) providerFields2.push("charged_if_declined_micro");
|
|
2611
|
+
const declineHint = stopping ? ` If your human does not approve, run \`dvm decline ${guidanceJobArg(jobId)}\`: ${stopping.clause} Letting the deadline pass also ends the job.` : "";
|
|
2596
2612
|
return {
|
|
2597
2613
|
type: "pay",
|
|
2598
2614
|
job_id: jobId,
|
|
2599
2615
|
amount_msats: c.amount_msats,
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
...
|
|
2616
|
+
...c.fiat_amount && c.fiat_amount.amount > 0 ? { fiat_amount: c.fiat_amount } : {},
|
|
2617
|
+
...stopping?.credit ? { credit: stopping.credit } : {},
|
|
2618
|
+
...stopping ? { charged_if_declined_micro: stopping.micro } : {},
|
|
2619
|
+
...providerFields2.length ? { _provider_fields: providerFields2 } : {},
|
|
2603
2620
|
...expiresAtMs !== void 0 ? { expires_at_ms: expiresAtMs } : {},
|
|
2604
|
-
display: withDeadline(display, deadline),
|
|
2621
|
+
display: withDeadline(stopping ? `${withPeriod(display)} ${stopping.clause}` : display, deadline),
|
|
2605
2622
|
reason: asProviderText(c.reason),
|
|
2606
|
-
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
|
|
2623
|
+
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
|
|
2607
2624
|
};
|
|
2608
2625
|
}
|
|
2609
2626
|
case "working": {
|
|
@@ -2619,6 +2636,18 @@ function computeNextAction(jobId, messages, nowMs = Date.now(), context) {
|
|
|
2619
2636
|
}
|
|
2620
2637
|
return null;
|
|
2621
2638
|
}
|
|
2639
|
+
function declineTerms(ask) {
|
|
2640
|
+
const micro = ask.charged_if_declined_micro;
|
|
2641
|
+
if (typeof micro !== "number" || !Number.isSafeInteger(micro) || micro < 0) return void 0;
|
|
2642
|
+
const price = ask.credit;
|
|
2643
|
+
const credit = price && Number.isSafeInteger(price.amount_micro) && price.amount_micro >= 0 && typeof price.currency === "string" ? { amount_micro: price.amount_micro, currency: price.currency } : void 0;
|
|
2644
|
+
const amount = credit && /^[A-Z]{3}$/i.test(credit.currency) ? formatFiat(micro / 1e6, credit.currency) : void 0;
|
|
2645
|
+
const clause = micro === 0 ? "Declining ends the job with no charge for finished work." : amount ? `Declining ends the job and charges ${amount} for the work already finished.` : "Declining ends the job and charges for the work already finished (next_action.charged_if_declined_micro).";
|
|
2646
|
+
return { micro, ...credit ? { credit } : {}, clause };
|
|
2647
|
+
}
|
|
2648
|
+
function withPeriod(text) {
|
|
2649
|
+
return /[.!?]$/.test(text) ? text : `${text}.`;
|
|
2650
|
+
}
|
|
2622
2651
|
function pendingDeadline(messages, answered) {
|
|
2623
2652
|
const prompts = /* @__PURE__ */ new Map();
|
|
2624
2653
|
let payment;
|
|
@@ -2656,6 +2685,133 @@ function deadlineClause(action, expiresAtMs, nowMs, jobId) {
|
|
|
2656
2685
|
return `${action} by ${deadline} (in ${remaining}), or the provider cancels the job.`;
|
|
2657
2686
|
}
|
|
2658
2687
|
|
|
2688
|
+
// src/lib/piece-settlement.ts
|
|
2689
|
+
function pieceSettlement(receipt, context = {}) {
|
|
2690
|
+
const settlement = receipt.settlement;
|
|
2691
|
+
if (!isSettlement(settlement)) return void 0;
|
|
2692
|
+
const job = context.job ?? void 0;
|
|
2693
|
+
const messages = [...context.messages ?? []].sort((a, b) => a.seq - b.seq);
|
|
2694
|
+
const currency = settlementCurrency(receipt, job, messages, context.currency);
|
|
2695
|
+
const stopped = settlement.pieces.filter((piece) => piece.state === "stopped").reduce((sum, piece) => sum + piece.charged, 0);
|
|
2696
|
+
const callerStop = receipt.outcome === "cancelled" && !job?.callerDeclined && (job?.callerCancelled === true || receipt.ended_by === "caller");
|
|
2697
|
+
const ending = receipt.outcome === "completed" ? "finish" : callerStop ? "stop" : "release";
|
|
2698
|
+
const paid = currency && job && context.messages !== void 0 && settlement.pieces.length > 0 ? paidCeiling(job, messages, settlement, currency, ending) : void 0;
|
|
2699
|
+
const listed = settlement.pieces.length > 0 ? settlement.pieces.filter((piece) => piece.state === "finished" || piece.state === "stopped").reduce((sum, piece) => sum + Math.min(piece.charged, piece.amount), 0) : void 0;
|
|
2700
|
+
const declined = ending === "release" && job ? declineCap(job, messages) : void 0;
|
|
2701
|
+
const bounds = [["payments", paid], ["declined_ask", declined], ["receipt_pieces", listed]].filter((entry) => entry[1] !== void 0);
|
|
2702
|
+
const lowest = bounds.reduce(
|
|
2703
|
+
(best, entry) => best === void 0 || entry[1] < best[1] ? entry : best,
|
|
2704
|
+
void 0
|
|
2705
|
+
);
|
|
2706
|
+
const basis = lowest?.[0];
|
|
2707
|
+
const ceiling = lowest?.[1];
|
|
2708
|
+
const overcharged = ceiling !== void 0 && settlement.charged > ceiling;
|
|
2709
|
+
const money = (micro) => formatMicro(micro, currency);
|
|
2710
|
+
let display = `Charged ${money(settlement.charged)} of ${money(settlement.held)} held, ${money(settlement.released)} released.`;
|
|
2711
|
+
if (overcharged) display += ` ${overchargeClause(basis, money(ceiling))}`;
|
|
2712
|
+
return {
|
|
2713
|
+
held_micro: settlement.held,
|
|
2714
|
+
charged_micro: settlement.charged,
|
|
2715
|
+
released_micro: settlement.released,
|
|
2716
|
+
stopped_micro: stopped,
|
|
2717
|
+
currency,
|
|
2718
|
+
...ceiling !== void 0 ? { ceiling_micro: ceiling, ceiling_basis: basis } : {},
|
|
2719
|
+
overcharged,
|
|
2720
|
+
display
|
|
2721
|
+
};
|
|
2722
|
+
}
|
|
2723
|
+
function overchargeClause(basis, ceiling) {
|
|
2724
|
+
return basis === "payments" ? `This charge exceeds the finished pieces this CLI paid for (at most ${ceiling}).` : basis === "declined_ask" ? `This charge exceeds what the job's last ask said stopping would cost (at most ${ceiling}).` : `This charge exceeds what the receipt's own pieces add up to (${ceiling}).`;
|
|
2725
|
+
}
|
|
2726
|
+
function formatMicro(micro, currency) {
|
|
2727
|
+
return currency ? formatFiat(micro / 1e6, currency) : `${micro.toLocaleString("en-US")} micro-units`;
|
|
2728
|
+
}
|
|
2729
|
+
function paidCeiling(job, messages, settlement, currency, ending) {
|
|
2730
|
+
let upfront = 0;
|
|
2731
|
+
if (job.upfrontPayment?.amount_micro !== void 0) {
|
|
2732
|
+
if (!sameCurrency(job.upfrontPayment.currency, currency)) return void 0;
|
|
2733
|
+
upfront = job.upfrontPayment.amount_micro;
|
|
2734
|
+
} else if (job.upfrontPayment || settlement.pieces.some((piece) => piece.paid_seq === 0)) {
|
|
2735
|
+
return void 0;
|
|
2736
|
+
}
|
|
2737
|
+
const logged = new Set(messages.filter((message) => message.from === "requester" && message.type === "payment").map((message) => message.seq));
|
|
2738
|
+
if (!wholeThroughEnd(messages) && settlement.pieces.some((piece) => piece.paid_seq !== 0 && !logged.has(piece.paid_seq))) return void 0;
|
|
2739
|
+
let paid = upfront;
|
|
2740
|
+
let finished;
|
|
2741
|
+
let afterAsk = upfront;
|
|
2742
|
+
const asks = /* @__PURE__ */ new Map();
|
|
2743
|
+
let latestAsk;
|
|
2744
|
+
for (const message of messages) {
|
|
2745
|
+
if (message.from === "provider" && message.type === "payment-request") {
|
|
2746
|
+
asks.set(message.seq, message.content);
|
|
2747
|
+
latestAsk = message.seq;
|
|
2748
|
+
const declined = message.content.charged_if_declined_micro;
|
|
2749
|
+
if (validMicro(declined) && sameCurrency(message.content.credit?.currency, currency)) {
|
|
2750
|
+
finished = declined;
|
|
2751
|
+
afterAsk = 0;
|
|
2752
|
+
}
|
|
2753
|
+
} else if (message.from === "requester" && message.type === "payment") {
|
|
2754
|
+
const credit = message.content.credit;
|
|
2755
|
+
const ask = asks.get(credit?.request_seq ?? latestAsk ?? -1)?.credit;
|
|
2756
|
+
const price = credit ? credit : ask;
|
|
2757
|
+
if (!price || !validMicro(price.amount_micro) || !sameCurrency(price.currency, currency)) return void 0;
|
|
2758
|
+
paid += price.amount_micro;
|
|
2759
|
+
afterAsk += price.amount_micro;
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
if (ending !== "release") return paid;
|
|
2763
|
+
return wholeThroughEnd(messages) ? finished ?? 0 : (finished ?? 0) + afterAsk;
|
|
2764
|
+
}
|
|
2765
|
+
function declineCap(job, messages) {
|
|
2766
|
+
const ask = messages.findLast((message) => message.from === "provider" && message.type === "payment-request");
|
|
2767
|
+
if (!ask || !validMicro(ask.content.charged_if_declined_micro)) return void 0;
|
|
2768
|
+
const recorded = [
|
|
2769
|
+
...job.paidPaymentRequestSeqs ?? [],
|
|
2770
|
+
...job.inFlightPaymentRequestSeqs ?? [],
|
|
2771
|
+
...(job.bookedCreditPayments ?? []).map((payment) => payment.authorization.request_seq)
|
|
2772
|
+
];
|
|
2773
|
+
if (recorded.some((seq) => seq > ask.seq)) return void 0;
|
|
2774
|
+
const paidAsk = answeredYieldSeqs(messages).has(ask.seq) || recorded.includes(ask.seq);
|
|
2775
|
+
if (!paidAsk) return ask.content.charged_if_declined_micro;
|
|
2776
|
+
const price = ask.content.credit?.amount_micro;
|
|
2777
|
+
return validMicro(price) ? ask.content.charged_if_declined_micro + price : void 0;
|
|
2778
|
+
}
|
|
2779
|
+
function wholeThroughEnd(messages) {
|
|
2780
|
+
if (messages.length === 0 || messages[0].seq > 1) return false;
|
|
2781
|
+
if (!messages.every((message, index) => index === 0 || message.seq === messages[index - 1].seq + 1)) return false;
|
|
2782
|
+
return messages.some((message) => message.type === "complete" || message.type === "cancel" || message.type === "decline");
|
|
2783
|
+
}
|
|
2784
|
+
function settlementCurrency(receipt, job, messages, hint) {
|
|
2785
|
+
const candidates = [job?.upfrontPayment?.currency];
|
|
2786
|
+
for (const message of [...messages].reverse()) {
|
|
2787
|
+
if (message.type === "payment-request" && message.from === "provider") candidates.push(message.content.credit?.currency);
|
|
2788
|
+
if (message.type === "payment" && message.from === "requester") candidates.push(message.content.credit?.currency);
|
|
2789
|
+
}
|
|
2790
|
+
candidates.push(hint);
|
|
2791
|
+
const creditId = receipt.credit?.credit_id;
|
|
2792
|
+
if (creditId) candidates.push(safeCredits().find((credit) => credit.creditId === creditId)?.currency);
|
|
2793
|
+
const found = candidates.find((currency) => typeof currency === "string" && currency.length > 0);
|
|
2794
|
+
return found && /^[a-z]{3}$/i.test(found) ? found.toLowerCase() : null;
|
|
2795
|
+
}
|
|
2796
|
+
function safeCredits() {
|
|
2797
|
+
try {
|
|
2798
|
+
return listCredits();
|
|
2799
|
+
} catch {
|
|
2800
|
+
return [];
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
function sameCurrency(a, b) {
|
|
2804
|
+
return typeof a === "string" && a.toLowerCase() === b;
|
|
2805
|
+
}
|
|
2806
|
+
function validMicro(value) {
|
|
2807
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
2808
|
+
}
|
|
2809
|
+
function isSettlement(value) {
|
|
2810
|
+
if (!value || typeof value !== "object") return false;
|
|
2811
|
+
const s = value;
|
|
2812
|
+
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");
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2659
2815
|
// src/lib/job-settlement.ts
|
|
2660
2816
|
function amountDisplay(msats, rail, rate) {
|
|
2661
2817
|
const amount = rate === void 0 ? formatPaymentAmount(msats, void 0, { anchor: false }) : rate > 0 ? formatAmount(msats, rate, { anchor: false }) : formatSats(msats);
|
|
@@ -2671,9 +2827,29 @@ function unknownSettlement(rail) {
|
|
|
2671
2827
|
display: "Settlement unknown; recorded payments do not prove a final charge or return."
|
|
2672
2828
|
};
|
|
2673
2829
|
}
|
|
2674
|
-
function receiptSettlement(receipt, verification, rate) {
|
|
2830
|
+
function receiptSettlement(receipt, verification, rate, context) {
|
|
2675
2831
|
const rail = receipt.paid.rail;
|
|
2676
2832
|
if (verification !== "verified" && verification !== "verified_unattested") return unknownSettlement(rail);
|
|
2833
|
+
const pieces = pieceSettlement(receipt, context);
|
|
2834
|
+
if (pieces && !(receipt.outcome === "completed" && receipt.paid.msats === 0 && pieces.held_micro === 0)) {
|
|
2835
|
+
const whole = receipt.outcome === "completed" && pieces.released_micro === 0;
|
|
2836
|
+
return {
|
|
2837
|
+
status: pieces.charged_micro === 0 ? "released" : "settled",
|
|
2838
|
+
settled_msats: whole ? receipt.paid.msats : pieces.charged_micro === 0 ? 0 : null,
|
|
2839
|
+
...pieces.charged_micro === 0 ? { released_msats: receipt.paid.msats } : {},
|
|
2840
|
+
refunded_msats: 0,
|
|
2841
|
+
rail,
|
|
2842
|
+
evidence: "receipt",
|
|
2843
|
+
held_micro: pieces.held_micro,
|
|
2844
|
+
charged_micro: pieces.charged_micro,
|
|
2845
|
+
released_micro: pieces.released_micro,
|
|
2846
|
+
stopped_micro: pieces.stopped_micro,
|
|
2847
|
+
currency: pieces.currency,
|
|
2848
|
+
...pieces.ceiling_micro !== void 0 ? { ceiling_micro: pieces.ceiling_micro, ceiling_basis: pieces.ceiling_basis } : {},
|
|
2849
|
+
overcharged: pieces.overcharged,
|
|
2850
|
+
display: pieces.display
|
|
2851
|
+
};
|
|
2852
|
+
}
|
|
2677
2853
|
const amount = amountDisplay(receipt.paid.msats, rail, rate);
|
|
2678
2854
|
if (receipt.outcome === "completed") {
|
|
2679
2855
|
return {
|
|
@@ -2713,7 +2889,7 @@ function jobSettlement(job, offeredReceipt) {
|
|
|
2713
2889
|
else pending = true;
|
|
2714
2890
|
}
|
|
2715
2891
|
const verified = receipt ? verifyJobReceipt({ receipt, expectedJobId: job.id, builder: job.builderAnchor }) : void 0;
|
|
2716
|
-
const summary = receipt && verified ? receiptSettlement(receipt, verified.status) : void 0;
|
|
2892
|
+
const summary = receipt && verified ? receiptSettlement(receipt, verified.status, void 0, { job, messages: log }) : void 0;
|
|
2717
2893
|
const matching = receipt?.outcome === job.status;
|
|
2718
2894
|
if (!isTerminalJobStatus(job.status)) {
|
|
2719
2895
|
return {
|
|
@@ -2764,7 +2940,12 @@ function terminalSettlementFields(jobId, options = {}) {
|
|
|
2764
2940
|
const status = options.status ?? stored?.status ?? options.receipt?.outcome;
|
|
2765
2941
|
if (!status || !isTerminalJobStatus(status)) return {};
|
|
2766
2942
|
const job = stored ? { ...stored, status } : { id: jobId, endpoint: "", submittedAt: 0, status };
|
|
2767
|
-
return { settlement: options.persistLocalState === false ? options.receipt && options.receipt.outcome === status ? receiptSettlement(
|
|
2943
|
+
return { settlement: options.persistLocalState === false ? options.receipt && options.receipt.outcome === status ? receiptSettlement(
|
|
2944
|
+
options.receipt,
|
|
2945
|
+
verifyJobReceipt({ receipt: options.receipt, expectedJobId: jobId }).status,
|
|
2946
|
+
void 0,
|
|
2947
|
+
{ currency: options.currency }
|
|
2948
|
+
) : unknownSettlement(null) : jobSettlement(job, options.receipt) };
|
|
2768
2949
|
}
|
|
2769
2950
|
|
|
2770
2951
|
// src/lib/receipt-verify.ts
|
|
@@ -2793,11 +2974,11 @@ function drainReceiptsHint(status) {
|
|
|
2793
2974
|
return "This DVM countersigned nothing, so the only artifact behind this reclaim is the drain request the caller signed. Weaker evidence than a countersigned drain, and worth weighing before funding here again.";
|
|
2794
2975
|
}
|
|
2795
2976
|
}
|
|
2796
|
-
function receiptDisplay(receipt, status, rate = 0) {
|
|
2977
|
+
function receiptDisplay(receipt, status, rate = 0, currency) {
|
|
2797
2978
|
const what = `${receipt.dvm}/${receipt.capability} (DVM ID ${receipt.dvm_id})`;
|
|
2798
2979
|
const when = receiptIssuedAtIso(receipt)?.slice(0, 10);
|
|
2799
|
-
const settlement = receiptSettlement(receipt, status, rate);
|
|
2800
|
-
const payment = settlement.status === "settled" ? `Settled ${formatPaid(receipt.paid.msats, rate)}` : settlement.status === "free" ? "free job" : settlement.display.replace(/\.$/, "");
|
|
2980
|
+
const settlement = receiptSettlement(receipt, status, rate, { job: loadJob(receipt.job_id), currency });
|
|
2981
|
+
const payment = settlement.charged_micro !== void 0 ? `Charged ${formatMicro(settlement.charged_micro, settlement.currency ?? null)}` : settlement.status === "settled" ? `Settled ${formatPaid(receipt.paid.msats, rate)}` : settlement.status === "free" ? "free job" : settlement.display.replace(/\.$/, "");
|
|
2801
2982
|
return `${VERDICT_PREFIX[status]}: ${payment} for ${what}, ${receipt.outcome}${when ? ` ${when}` : ""}.`;
|
|
2802
2983
|
}
|
|
2803
2984
|
function receiptIssuedAtIso(receipt) {
|
|
@@ -3653,8 +3834,8 @@ function completionFromMessages(messages) {
|
|
|
3653
3834
|
payloadIn: artifactCount > 0 ? "messages" : "summary"
|
|
3654
3835
|
};
|
|
3655
3836
|
if (summary !== void 0) out.summary = summary;
|
|
3656
|
-
const terminal = messages.findLast((m) => m.type === "complete" || m.type === "cancel");
|
|
3657
|
-
if (terminal?.type === "cancel" && terminal.content.reason !== void 0)
|
|
3837
|
+
const terminal = messages.findLast((m) => m.type === "complete" || m.type === "cancel" || m.type === "decline");
|
|
3838
|
+
if ((terminal?.type === "cancel" || terminal?.type === "decline") && terminal.content.reason !== void 0)
|
|
3658
3839
|
out.message = terminal.content.reason;
|
|
3659
3840
|
if (artifactCount > 0) out.artifactCount = artifactCount;
|
|
3660
3841
|
return out;
|
|
@@ -3740,9 +3921,20 @@ function captureJobReceipt(jobId, receipt, parseError) {
|
|
|
3740
3921
|
info(
|
|
3741
3922
|
`Warning: this job's receipt did not verify. ${receiptFailureDetail(result.reason ?? "signature_invalid")}`
|
|
3742
3923
|
);
|
|
3924
|
+
} else if (result.reason !== "job_id_mismatch") {
|
|
3925
|
+
warnPieceOvercharge(jobId, receipt, job);
|
|
3743
3926
|
}
|
|
3744
3927
|
return toCapture(receipt, result);
|
|
3745
3928
|
}
|
|
3929
|
+
function warnPieceOvercharge(jobId, receipt, job) {
|
|
3930
|
+
const pieces = pieceSettlement(receipt, { job, messages: loadMessages(jobId) });
|
|
3931
|
+
if (!pieces?.overcharged || pieces.ceiling_micro === void 0) return;
|
|
3932
|
+
const ceiling = formatMicro(pieces.ceiling_micro, pieces.currency);
|
|
3933
|
+
const basis = pieces.ceiling_basis === "payments" ? `the ${ceiling} of finished pieces this CLI paid for` : pieces.ceiling_basis === "declined_ask" ? `the ${ceiling} the job's last ask said stopping would cost` : `the ${ceiling} its own pieces add up to`;
|
|
3934
|
+
info(
|
|
3935
|
+
`Warning: the signed receipt for job ${jobId} charges ${formatMicro(pieces.charged_micro, pieces.currency)}, more than ${basis}. Keep the receipt as evidence ('dvm receipts show ${jobId}') and raise it with the provider.`
|
|
3936
|
+
);
|
|
3937
|
+
}
|
|
3746
3938
|
function captureTransportReceipt(jobId, response) {
|
|
3747
3939
|
captureDrawFundingReceipts(jobId, response.drawFundingReceipts);
|
|
3748
3940
|
if (response.drawFundingReceiptParseError) info("Warning: mid-job funding evidence has an invalid shape.");
|
|
@@ -3768,9 +3960,9 @@ function renderReceiptHuman(capture, jobId) {
|
|
|
3768
3960
|
if (capture.status === "absent") return;
|
|
3769
3961
|
info(`\u{1F9FE} ${capture.display}`);
|
|
3770
3962
|
}
|
|
3771
|
-
function observedSettlementFields(jobId, response, persistLocalState = true) {
|
|
3963
|
+
function observedSettlementFields(jobId, response, persistLocalState = true, currency) {
|
|
3772
3964
|
if (persistLocalState && response?.status && isTerminalJobStatus(response.status) && (response.receipt || response.receiptParseError)) captureTransportReceipt(jobId, response);
|
|
3773
|
-
return terminalSettlementFields(jobId, { status: response?.status, receipt: response?.receipt, persistLocalState });
|
|
3965
|
+
return terminalSettlementFields(jobId, { status: response?.status, receipt: response?.receipt, persistLocalState, currency });
|
|
3774
3966
|
}
|
|
3775
3967
|
function receiptTrustFields(provider) {
|
|
3776
3968
|
return {
|
|
@@ -8267,6 +8459,7 @@ export {
|
|
|
8267
8459
|
parseStatedBudget,
|
|
8268
8460
|
floatBudgetJson,
|
|
8269
8461
|
toFloatError,
|
|
8462
|
+
formatMicro,
|
|
8270
8463
|
receiptSettlement,
|
|
8271
8464
|
jobSettlement,
|
|
8272
8465
|
terminalSettlementFields,
|
|
@@ -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-
|
|
6
|
+
} from "./chunk-HJ2JYBTT.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-
|
|
16
|
+
} from "./chunk-YQJRKWNT.js";
|
|
17
17
|
import {
|
|
18
18
|
DvmError
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-57PXJ56K.js";
|
|
20
20
|
|
|
21
21
|
// src/lib/cli-identity-resolve.ts
|
|
22
22
|
function resolveSigningIdentity(opts) {
|
|
@@ -4,14 +4,14 @@ const require = __dvmCreateRequire(import.meta.url);
|
|
|
4
4
|
import {
|
|
5
5
|
loadConfig,
|
|
6
6
|
updateConfig
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-2MCZ4QOK.js";
|
|
8
8
|
import {
|
|
9
9
|
tempoAccountFromConfig,
|
|
10
10
|
tryResolveTempoAsset
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-YQJRKWNT.js";
|
|
12
12
|
import {
|
|
13
13
|
DvmError
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-57PXJ56K.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-
|
|
49
|
+
const { assertTempoWalletIdle } = await import("./tempo-lifecycle-FMBCHD2M.js");
|
|
50
50
|
await assertTempoWalletIdle("replace");
|
|
51
51
|
}
|
|
52
52
|
const { privateKeyToAccount, generatePrivateKey } = await import("./accounts-2WZE4N5F.js");
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
} from "./chunk-R2DSAZBO.js";
|
|
7
7
|
import {
|
|
8
8
|
diagnosticConsole
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-UCCT5IKU.js";
|
|
10
10
|
|
|
11
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
11
|
+
// node_modules/@dvmkit/sdk/dist/chunk-PGQID4PR.js
|
|
12
12
|
import { randomUUID } from "crypto";
|
|
13
13
|
var ENDPOINTS = {
|
|
14
14
|
job_terminal: "/_internal/job-terminal",
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
formatUsdcMicrounits,
|
|
6
6
|
listX402Channels,
|
|
7
7
|
readX402ChannelGuardFacts
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YQJRKWNT.js";
|
|
9
9
|
import {
|
|
10
10
|
DvmError
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-57PXJ56K.js";
|
|
12
12
|
|
|
13
13
|
// src/lib/x402/lifecycle.ts
|
|
14
14
|
async function assertX402WalletIdle(wallet, intent) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createRequire as __dvmCreateRequire } from "node:module";
|
|
3
3
|
const require = __dvmCreateRequire(import.meta.url);
|
|
4
4
|
|
|
5
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
5
|
+
// node_modules/@dvmkit/sdk/dist/chunk-3UACKFEK.js
|
|
6
6
|
import { isIP } from "net";
|
|
7
7
|
var diagnostic_catalogue_v1_default = {
|
|
8
8
|
version: 1,
|
|
@@ -101,6 +101,8 @@ var diagnostic_catalogue_v1_default = {
|
|
|
101
101
|
"credit_resolve_failed",
|
|
102
102
|
"credit_resolve_state_mismatch",
|
|
103
103
|
"credit_topup_over_ask",
|
|
104
|
+
"credit_topup_redirected",
|
|
105
|
+
"credit_topup_refused",
|
|
104
106
|
"credit_topup_skipped",
|
|
105
107
|
"credit_topup_stale_rate",
|
|
106
108
|
"credit_topup_unbound",
|
|
@@ -206,6 +208,7 @@ var diagnostic_catalogue_v1_default = {
|
|
|
206
208
|
"job_heartbeat_failed",
|
|
207
209
|
"job_id",
|
|
208
210
|
"job_message_append_failed",
|
|
211
|
+
"piece_settlement_exceeds_hold",
|
|
209
212
|
"step_persist_failed",
|
|
210
213
|
"job_messages_listen_connect_failed",
|
|
211
214
|
"job_messages_listen_lost",
|
|
@@ -782,6 +785,8 @@ var diagnostic_catalogue_v1_default = {
|
|
|
782
785
|
"amount_too_large",
|
|
783
786
|
"api_error",
|
|
784
787
|
"app_shell_detected",
|
|
788
|
+
"ask_already_open",
|
|
789
|
+
"ask_expired",
|
|
785
790
|
"audio_source_required",
|
|
786
791
|
"auth_error",
|
|
787
792
|
"auth_required",
|
|
@@ -801,6 +806,7 @@ var diagnostic_catalogue_v1_default = {
|
|
|
801
806
|
"cover_invalid",
|
|
802
807
|
"credit_fund_failed",
|
|
803
808
|
"css_selector_for_requested_content",
|
|
809
|
+
"decline_unavailable",
|
|
804
810
|
"decoder_failed",
|
|
805
811
|
"decoder_unavailable",
|
|
806
812
|
"diarise_failed",
|
|
@@ -849,6 +855,7 @@ var diagnostic_catalogue_v1_default = {
|
|
|
849
855
|
"milliseconds",
|
|
850
856
|
"network_error",
|
|
851
857
|
"no_diariser",
|
|
858
|
+
"no_open_ask",
|
|
852
859
|
"no_premium_substrate",
|
|
853
860
|
"none",
|
|
854
861
|
"not_found",
|
|
@@ -1073,6 +1080,7 @@ var diagnostic_catalogue_v1_default = {
|
|
|
1073
1080
|
],
|
|
1074
1081
|
paymentSkipReasons: [
|
|
1075
1082
|
"credit_or_draw_missing",
|
|
1083
|
+
"credit_not_active",
|
|
1076
1084
|
"draw_not_pending",
|
|
1077
1085
|
"draw_job_mismatch",
|
|
1078
1086
|
"rail_mismatch",
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
authorizeProtectedRemoval,
|
|
6
6
|
loadConfig,
|
|
7
7
|
updateConfig
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-2MCZ4QOK.js";
|
|
9
9
|
import {
|
|
10
10
|
withX402ChannelLock,
|
|
11
11
|
x402WalletFromConfig
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-YQJRKWNT.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-
|
|
20
|
+
} from "./chunk-57PXJ56K.js";
|
|
21
21
|
|
|
22
22
|
// src/lib/x402/networks.ts
|
|
23
23
|
function x402NetworkLabel(network) {
|