@dvmkit/dvm-cli 0.20.0 → 0.21.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-MSQJWCPT.js → chunk-7UGJALAX.js} +3 -3
- package/dist/{chunk-EEQPFGPM.js → chunk-BU5E7IDF.js} +2 -2
- package/dist/{chunk-4RINUKY4.js → chunk-CMIEPFKP.js} +8326 -27312
- package/dist/{chunk-ZZCYSYXR.js → chunk-EA6RU4OR.js} +10 -10
- package/dist/{chunk-WCX4PNEF.js → chunk-GEG2YAIB.js} +19 -1
- package/dist/{chunk-4S6TNP4N.js → chunk-GWISSHP6.js} +221 -24
- package/dist/{chunk-2B2MCZ2I.js → chunk-L3PHIA5L.js} +4 -4
- package/dist/{chunk-2YPUKPJN.js → chunk-M4Q3DBQO.js} +3 -3
- package/dist/chunk-MP63OWTD.js +27343 -0
- package/dist/{chunk-W4ADV3HW.js → chunk-NSHMTEFJ.js} +27 -17
- package/dist/{chunk-DOAMK5C6.js → chunk-QVX7KPLS.js} +2 -2
- package/dist/{chunk-QXXPXQLM.js → chunk-YRLRHJ6O.js} +2 -2
- package/dist/{client-FKYQXFBN.js → client-MJZL7XTD.js} +6 -6
- package/dist/dvm.js +5441 -473
- package/dist/{internal-EQJXMIR2.js → internal-TUEXUURQ.js} +5 -5
- package/dist/{lifecycle-3IBVUCTB.js → lifecycle-7PSR5CYB.js} +6 -6
- package/dist/{payout-reporter-5PH53T44-7IA4NGIN.js → payout-reporter-O4OLJXKQ-7N2HPPPY.js} +2 -2
- package/dist/{pocket-refill-M65PPCN3.js → pocket-refill-OX3WXUZ4.js} +10 -10
- package/dist/{revenue-reporter-4XV3OO5O-RYHS3M34.js → revenue-reporter-RMK4HFEW-7HGJQOXL.js} +2 -2
- package/dist/{tempo-lifecycle-Q3N5GGIQ.js → tempo-lifecycle-BOW6OFSI.js} +8 -8
- package/dist/{tempo-wallet-AY6R3E4Z.js → tempo-wallet-D424H37T.js} +7 -7
- package/dist/{wallet-J7JCMFZ2.js → wallet-CZV4TOJ3.js} +7 -7
- package/dist/{x402-FHHB3V4V-CM6OMLHE.js → x402-JCKCGEM3-NFTGP54F.js} +2 -2
- package/package.json +2 -2
- package/skills/dvm/SKILL.md +1 -1
- package/skills/dvm/calling.md +21 -3
- package/dist/chunk-DF2OWCRY.js +0 -11127
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
} from "./chunk-R2DSAZBO.js";
|
|
7
7
|
import {
|
|
8
8
|
diagnosticConsole
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-GEG2YAIB.js";
|
|
10
10
|
|
|
11
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
11
|
+
// node_modules/@dvmkit/sdk/dist/chunk-TFMY2QUI.js
|
|
12
12
|
import { randomUUID } from "crypto";
|
|
13
13
|
var ENDPOINTS = {
|
|
14
14
|
job_terminal: "/_internal/job-terminal",
|
|
@@ -579,7 +579,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
579
579
|
await q.query(
|
|
580
580
|
`INSERT INTO ${PENDING_DVM_REPORTS_TABLE} (id, payload, created_at, kind)
|
|
581
581
|
VALUES ($1, $2, $3, $4)`,
|
|
582
|
-
[id, JSON.stringify(payload), Date.now(), kind]
|
|
582
|
+
[id, JSON.stringify(withoutSentinelCaller(payload)), Date.now(), kind]
|
|
583
583
|
);
|
|
584
584
|
return id;
|
|
585
585
|
}
|
|
@@ -596,7 +596,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
596
596
|
"Content-Type": "application/json",
|
|
597
597
|
Authorization: `Bearer ${this.platformToken}`
|
|
598
598
|
},
|
|
599
|
-
body: JSON.stringify(payload),
|
|
599
|
+
body: JSON.stringify(withoutSentinelCaller(payload)),
|
|
600
600
|
signal: AbortSignal.timeout(1e4)
|
|
601
601
|
});
|
|
602
602
|
} catch (err) {
|
|
@@ -633,16 +633,12 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
633
633
|
}
|
|
634
634
|
if (res.status === 401) {
|
|
635
635
|
await this.markStale(id, "token_rotated");
|
|
636
|
-
diagnosticConsole.warn(
|
|
637
|
-
`[revenue-reporter] Report ${id} got 401 \u2014 marking stale (token likely rotated)`
|
|
638
|
-
);
|
|
636
|
+
diagnosticConsole.warn({ event: "platform_report_rejected", report_kind: kind, status_code: res.status });
|
|
639
637
|
return;
|
|
640
638
|
}
|
|
641
639
|
if (res.status >= 400 && res.status < 500) {
|
|
642
640
|
await this.markStale(id, `client_error:${res.status}`);
|
|
643
|
-
diagnosticConsole.warn(
|
|
644
|
-
`[revenue-reporter] Report ${id} got HTTP ${res.status} \u2014 marking stale (permanent client error, will not retry)`
|
|
645
|
-
);
|
|
641
|
+
diagnosticConsole.warn({ event: "platform_report_rejected", report_kind: kind, status_code: res.status });
|
|
646
642
|
return;
|
|
647
643
|
}
|
|
648
644
|
diagnosticConsole.warn(`[revenue-reporter] delivery failed for ${id}: HTTP ${res.status} \u2014 will retry`);
|
|
@@ -655,6 +651,10 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
655
651
|
);
|
|
656
652
|
}
|
|
657
653
|
};
|
|
654
|
+
function withoutSentinelCaller(payload) {
|
|
655
|
+
const caller = payload.callerPubkey;
|
|
656
|
+
return caller === "anonymous" || caller === "dev-anonymous" ? { ...payload, callerPubkey: null } : payload;
|
|
657
|
+
}
|
|
658
658
|
|
|
659
659
|
export {
|
|
660
660
|
RevenueReporter
|
|
@@ -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-UAHC43ZB.js
|
|
6
6
|
import { isIP } from "net";
|
|
7
7
|
var diagnostic_catalogue_v1_default = {
|
|
8
8
|
version: 1,
|
|
@@ -257,6 +257,9 @@ var diagnostic_catalogue_v1_default = {
|
|
|
257
257
|
"lightning_settlement_check_failed",
|
|
258
258
|
"lock_pubkey_grace_seconds_invalid",
|
|
259
259
|
"log",
|
|
260
|
+
"mandate_ask_resume_failed",
|
|
261
|
+
"mandate_ask_sweep_failed",
|
|
262
|
+
"mandate_payment_skipped",
|
|
260
263
|
"melter_previous_run_read_failed",
|
|
261
264
|
"melter_report_unconfigured",
|
|
262
265
|
"melter_run_report",
|
|
@@ -326,6 +329,7 @@ var diagnostic_catalogue_v1_default = {
|
|
|
326
329
|
"platform_db_health_endpoint_failed",
|
|
327
330
|
"platform_db_health_recovery_failed",
|
|
328
331
|
"platform_hosted_test_mint_allowed",
|
|
332
|
+
"platform_report_rejected",
|
|
329
333
|
"postgres_client_error",
|
|
330
334
|
"postgres_pool_error",
|
|
331
335
|
"postgres_transport_recovery",
|
|
@@ -494,6 +498,8 @@ var diagnostic_catalogue_v1_default = {
|
|
|
494
498
|
"x402.verify_payment.result",
|
|
495
499
|
"x402.verify_with_facilitator",
|
|
496
500
|
"x402.verify_with_facilitator.result",
|
|
501
|
+
"x402_channel_lock_in_process",
|
|
502
|
+
"x402_channel_lock_release_failed",
|
|
497
503
|
"x402_claim_ceiling_unbound",
|
|
498
504
|
"x402_claim_ceiling_unresolved",
|
|
499
505
|
"x402_credential_rejected",
|
|
@@ -908,6 +914,7 @@ var diagnostic_catalogue_v1_default = {
|
|
|
908
914
|
"insecure_scheme",
|
|
909
915
|
"internal_error",
|
|
910
916
|
"invalid_input",
|
|
917
|
+
"invalid_mandate",
|
|
911
918
|
"invalid_menu",
|
|
912
919
|
"invalid_payment",
|
|
913
920
|
"invalid_quote_data",
|
|
@@ -1166,6 +1173,14 @@ var diagnostic_catalogue_v1_default = {
|
|
|
1166
1173
|
"denomination_unavailable",
|
|
1167
1174
|
"topup_cap_unavailable",
|
|
1168
1175
|
"topup_cap_currency_mismatch",
|
|
1176
|
+
"mandate_expired",
|
|
1177
|
+
"mandate_ask_cap",
|
|
1178
|
+
"mandate_total_cap",
|
|
1179
|
+
"mandate_balance",
|
|
1180
|
+
"mandate_currency",
|
|
1181
|
+
"mandate_draw_owned_elsewhere",
|
|
1182
|
+
"mandate_ask_unpriced",
|
|
1183
|
+
"mandate_credit_unavailable",
|
|
1169
1184
|
"unknown"
|
|
1170
1185
|
],
|
|
1171
1186
|
denominationCauses: [
|
|
@@ -1495,6 +1510,9 @@ function projectFields(input, dataset, authority, identityAuthority, eventName)
|
|
|
1495
1510
|
return output;
|
|
1496
1511
|
}
|
|
1497
1512
|
function projectField(key, value, dataset, authority, identityAuthority, eventName) {
|
|
1513
|
+
if (eventName === "platform_report_rejected" && key === "report_kind") {
|
|
1514
|
+
return typeof value === "string" && ["job_terminal", "revenue", "cost", "deposit", "refund", "release", "drain", "payout", "expiry_release"].includes(value) ? value : void 0;
|
|
1515
|
+
}
|
|
1498
1516
|
if (eventName === "x402_shutdown_claim_incomplete") {
|
|
1499
1517
|
if (key === "unclaimed_channels") return value === null || isNonnegativeSafeInteger(value) ? value : void 0;
|
|
1500
1518
|
if (key === "unclaimed_amount_native") return value === null || typeof value === "string" && DECIMAL_RE.test(value) ? value : void 0;
|
|
@@ -3,15 +3,15 @@ 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-L3PHIA5L.js";
|
|
7
7
|
import {
|
|
8
8
|
loadX402Wallet,
|
|
9
9
|
x402NetworkLabel
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-M4Q3DBQO.js";
|
|
11
11
|
import {
|
|
12
12
|
isCreditPosture,
|
|
13
13
|
loadConfig
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-BU5E7IDF.js";
|
|
15
15
|
import {
|
|
16
16
|
addOutputWarnings,
|
|
17
17
|
costAnchor,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
resolveBtcUsdRate,
|
|
28
28
|
tryResolveBtcUsdRate,
|
|
29
29
|
tryX402Payment
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-YRLRHJ6O.js";
|
|
31
31
|
import {
|
|
32
32
|
A,
|
|
33
33
|
BUDGET_FILE,
|
|
@@ -185,7 +185,7 @@ import {
|
|
|
185
185
|
x402PendingUnsettled,
|
|
186
186
|
x402RequiredFromError,
|
|
187
187
|
x402VoucherPendingState
|
|
188
|
-
} from "./chunk-
|
|
188
|
+
} from "./chunk-CMIEPFKP.js";
|
|
189
189
|
import {
|
|
190
190
|
Challenge_exports,
|
|
191
191
|
Credential_exports
|
|
@@ -206,7 +206,7 @@ import {
|
|
|
206
206
|
redactUrlsInText,
|
|
207
207
|
usdToMsats,
|
|
208
208
|
x402NetworkToCaip2
|
|
209
|
-
} from "./chunk-
|
|
209
|
+
} from "./chunk-MP63OWTD.js";
|
|
210
210
|
import {
|
|
211
211
|
privateKeyToAccount
|
|
212
212
|
} from "./chunk-EVQERRCP.js";
|
|
@@ -3113,13 +3113,19 @@ function hasUnknownUpfrontRail(job) {
|
|
|
3113
3113
|
function updateJob(id, update) {
|
|
3114
3114
|
mutateJobs((jobs) => {
|
|
3115
3115
|
const idx = jobs.findIndex((j) => j.id === id);
|
|
3116
|
-
if (idx !== -1)
|
|
3116
|
+
if (idx !== -1) {
|
|
3117
|
+
jobs[idx] = { ...jobs[idx], ...update };
|
|
3118
|
+
if (update.status && ["completed", "failed", "cancelled"].includes(update.status)) clearPaymentCreditRefusals(jobs[idx]);
|
|
3119
|
+
}
|
|
3117
3120
|
});
|
|
3118
3121
|
}
|
|
3119
3122
|
function updateObservedJob(id, update) {
|
|
3120
3123
|
mutateJobs((jobs) => {
|
|
3121
3124
|
const idx = jobs.findIndex((j) => j.id === id);
|
|
3122
|
-
if (idx !== -1)
|
|
3125
|
+
if (idx !== -1) {
|
|
3126
|
+
jobs[idx] = { ...jobs[idx], ...update };
|
|
3127
|
+
if (update.status && ["completed", "failed", "cancelled"].includes(update.status)) clearPaymentCreditRefusals(jobs[idx]);
|
|
3128
|
+
}
|
|
3123
3129
|
}, true);
|
|
3124
3130
|
}
|
|
3125
3131
|
function recordCallerMessageHash(jobId, endpoint, hash) {
|
|
@@ -3176,6 +3182,18 @@ function recordBudgetRefusal(jobId, requestSeq, overrun) {
|
|
|
3176
3182
|
if (job) (job.budgetRefusals ??= {})[String(requestSeq)] = overrun;
|
|
3177
3183
|
}, true);
|
|
3178
3184
|
}
|
|
3185
|
+
function recordPaymentCreditLanding(jobId, requestSeq, credit) {
|
|
3186
|
+
mutateCreditPayment(jobId, (job) => {
|
|
3187
|
+
const landings = job.paymentCreditLandings ??= {};
|
|
3188
|
+
const existing = Object.keys(landings).find((key) => landings[key].fund_id === credit.fund_id);
|
|
3189
|
+
landings[existing ?? (landings[requestSeq] ? credit.fund_id : String(requestSeq))] = credit;
|
|
3190
|
+
if (existing !== void 0) return;
|
|
3191
|
+
clearUnconfirmedSubmission(job, requestSeq);
|
|
3192
|
+
job.inFlightPaymentRequestSeqs = job.inFlightPaymentRequestSeqs?.filter((seq) => seq !== requestSeq);
|
|
3193
|
+
if (!job.inFlightPaymentRequestSeqs?.length) delete job.inFlightPaymentRequestSeqs;
|
|
3194
|
+
clearPaymentRequestStartTime(job, requestSeq);
|
|
3195
|
+
}, true);
|
|
3196
|
+
}
|
|
3179
3197
|
function markPaymentRequestInFlight(jobId, requestSeq, submission) {
|
|
3180
3198
|
mutateJobs((jobs) => {
|
|
3181
3199
|
const job = jobs.find((entry) => entry.id === jobId);
|
|
@@ -3207,6 +3225,7 @@ function markPaymentRequestPaid(jobId, requestSeq) {
|
|
|
3207
3225
|
const booked2 = mutateJobs((jobs) => {
|
|
3208
3226
|
const job = jobs.find((entry) => entry.id === jobId);
|
|
3209
3227
|
if (!job) return void 0;
|
|
3228
|
+
clearPaymentCreditRefusals(job, requestSeq);
|
|
3210
3229
|
if (!job.paidPaymentRequestSeqs?.includes(requestSeq))
|
|
3211
3230
|
(job.paidPaymentRequestSeqs ??= []).push(requestSeq);
|
|
3212
3231
|
if (job.inFlightPaymentRequestSeqs) {
|
|
@@ -3235,10 +3254,16 @@ function markPaymentRequestPaid(jobId, requestSeq) {
|
|
|
3235
3254
|
});
|
|
3236
3255
|
return booked2;
|
|
3237
3256
|
}
|
|
3257
|
+
function clearPaymentCreditRefusals(job, requestSeq) {
|
|
3258
|
+
for (const landing of Object.values(job.paymentCreditLandings ?? {})) {
|
|
3259
|
+
if (requestSeq === void 0 || landing.request_seq === requestSeq) delete landing.credit_payment_unavailable;
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3238
3262
|
function markPaymentRequestAnswered(jobId, requestSeq) {
|
|
3239
3263
|
mutateJobs((jobs) => {
|
|
3240
3264
|
const job = jobs.find((entry) => entry.id === jobId);
|
|
3241
3265
|
if (!job) return;
|
|
3266
|
+
clearPaymentCreditRefusals(job, requestSeq);
|
|
3242
3267
|
if (!job.paidPaymentRequestSeqs?.includes(requestSeq))
|
|
3243
3268
|
(job.paidPaymentRequestSeqs ??= []).push(requestSeq);
|
|
3244
3269
|
job.inFlightPaymentRequestSeqs = job.inFlightPaymentRequestSeqs?.filter((seq) => seq !== requestSeq);
|
|
@@ -3466,6 +3491,7 @@ function mutateCreditPayment(jobId, change, observed = false) {
|
|
|
3466
3491
|
}
|
|
3467
3492
|
function bookCreditPayment(jobId, intent) {
|
|
3468
3493
|
const booked2 = mutateCreditPayment(jobId, (job) => {
|
|
3494
|
+
clearPaymentCreditRefusals(job, intent.authorization.request_seq);
|
|
3469
3495
|
let booked3 = false;
|
|
3470
3496
|
if (!job.bookedCreditPayments?.some((entry) => entry.authorization.payment_id === intent.authorization.payment_id)) {
|
|
3471
3497
|
booked3 = true;
|
|
@@ -4094,6 +4120,149 @@ function providerJobJson(data, providerJob = true) {
|
|
|
4094
4120
|
}, [...providerJob ? ["jobId"] : [], "capability", "identifier"]));
|
|
4095
4121
|
}
|
|
4096
4122
|
|
|
4123
|
+
// src/lib/mandate-payments.ts
|
|
4124
|
+
function mandateCredit(message) {
|
|
4125
|
+
if (message.from !== "requester" || message.type !== "payment") return void 0;
|
|
4126
|
+
const credit = message.content.credit;
|
|
4127
|
+
return credit?.mandate === true ? credit : void 0;
|
|
4128
|
+
}
|
|
4129
|
+
function validMicro2(value) {
|
|
4130
|
+
return Number.isSafeInteger(value) && value >= 0;
|
|
4131
|
+
}
|
|
4132
|
+
function safeCurrency(value) {
|
|
4133
|
+
return typeof value === "string" && /^[a-z]{3}$/i.test(value) ? value.toLowerCase() : null;
|
|
4134
|
+
}
|
|
4135
|
+
function money(micro, currency) {
|
|
4136
|
+
if (!validMicro2(micro)) return "an unrecorded amount";
|
|
4137
|
+
return currency ? formatFiat(micro / 1e6, currency) : `${(micro / 1e6).toLocaleString("en-US", { maximumFractionDigits: 6 })} (currency not recorded)`;
|
|
4138
|
+
}
|
|
4139
|
+
function mandateDrawTotal(job, history) {
|
|
4140
|
+
const mandate = job.mandate;
|
|
4141
|
+
if (!mandate) return 0;
|
|
4142
|
+
const bound = (credit) => credit?.credit_id === mandate.credit_id && credit.draw_id === mandate.draw_id && credit.currency === mandate.currency && validMicro2(credit.amount_micro) ? credit.amount_micro : 0;
|
|
4143
|
+
let total = bound(job.upfrontPayment);
|
|
4144
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4145
|
+
for (const message of history) {
|
|
4146
|
+
if (seen.has(message.seq)) continue;
|
|
4147
|
+
seen.add(message.seq);
|
|
4148
|
+
if (message.from === "requester" && message.type === "payment") total += bound(message.content.credit);
|
|
4149
|
+
}
|
|
4150
|
+
return total;
|
|
4151
|
+
}
|
|
4152
|
+
function mandatePaymentReports(job, history) {
|
|
4153
|
+
const mandate = job?.mandate;
|
|
4154
|
+
const currency = safeCurrency(mandate?.currency);
|
|
4155
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4156
|
+
const paidAsks = /* @__PURE__ */ new Set();
|
|
4157
|
+
const reports = [];
|
|
4158
|
+
const asks = /* @__PURE__ */ new Map();
|
|
4159
|
+
const prefix = [];
|
|
4160
|
+
for (const message of [...history].sort((a, b) => a.seq - b.seq)) {
|
|
4161
|
+
if (seen.has(message.seq)) continue;
|
|
4162
|
+
seen.add(message.seq);
|
|
4163
|
+
prefix.push(message);
|
|
4164
|
+
if (message.from === "provider" && message.type === "payment-request") asks.set(message.seq, message);
|
|
4165
|
+
const paid = mandateCredit(message);
|
|
4166
|
+
if (!paid) {
|
|
4167
|
+
if (message.from === "requester" && message.type === "payment") {
|
|
4168
|
+
const seq = message.content.credit?.request_seq ?? [...asks.keys()].at(-1);
|
|
4169
|
+
if (seq !== void 0) paidAsks.add(seq);
|
|
4170
|
+
}
|
|
4171
|
+
continue;
|
|
4172
|
+
}
|
|
4173
|
+
const total = job ? mandateDrawTotal(job, prefix) : 0;
|
|
4174
|
+
const ask = asks.get(paid.request_seq);
|
|
4175
|
+
const violations = [];
|
|
4176
|
+
const reasons = [];
|
|
4177
|
+
const breach = (field, reason) => {
|
|
4178
|
+
violations.push(field);
|
|
4179
|
+
reasons.push(reason);
|
|
4180
|
+
};
|
|
4181
|
+
if (!validMicro2(paid.amount_micro) || paid.amount_micro === 0) breach("amount_micro", "an invalid payment amount");
|
|
4182
|
+
if (!ask) breach("request_seq", "a payment for a charge missing from the job's requests");
|
|
4183
|
+
else if (!ask.content.credit) breach("ask_unpriced", "a payment for a charge with no credit price");
|
|
4184
|
+
else {
|
|
4185
|
+
if (paid.amount_micro > ask.content.credit.amount_micro)
|
|
4186
|
+
breach("ask_amount_micro", `more than the provider requested for this charge (${money(ask.content.credit.amount_micro, currency)})`);
|
|
4187
|
+
if (paid.currency !== ask.content.credit.currency)
|
|
4188
|
+
breach("ask_currency", "a payment in a different currency from the requested charge");
|
|
4189
|
+
}
|
|
4190
|
+
if (paidAsks.has(paid.request_seq)) breach("duplicate_request_seq", "more than one payment for the same charge");
|
|
4191
|
+
paidAsks.add(paid.request_seq);
|
|
4192
|
+
if (mandate) {
|
|
4193
|
+
if (paid.amount_micro > mandate.max_ask_micro)
|
|
4194
|
+
breach("max_ask_micro", `more than your per-charge limit of ${money(mandate.max_ask_micro, currency)}`);
|
|
4195
|
+
if (total > mandate.max_total_micro)
|
|
4196
|
+
breach("max_total_micro", `more than your standing credit budget of ${money(mandate.max_total_micro, currency)}`);
|
|
4197
|
+
if (message.timestamp * 1e3 >= mandate.expires_at_ms)
|
|
4198
|
+
breach("expires_at_ms", `a payment after your standing limit ended on ${new Date(mandate.expires_at_ms).toISOString()}`);
|
|
4199
|
+
if (paid.credit_id !== mandate.credit_id) breach("credit_id", "a different prepaid credit than you authorised");
|
|
4200
|
+
if (paid.draw_id !== mandate.draw_id) breach("draw_id", "a different job credit reservation than you authorised");
|
|
4201
|
+
if (paid.currency !== mandate.currency) breach("currency", "a different currency than you authorised");
|
|
4202
|
+
}
|
|
4203
|
+
const paidCurrency = mandate ? paid.currency === mandate.currency ? currency : null : safeCurrency(paid.currency);
|
|
4204
|
+
const amount = { amount_micro: paid.amount_micro, currency: paid.currency, display: money(paid.amount_micro, paidCurrency) };
|
|
4205
|
+
const overchargeDisplay = reasons.length ? `Provider overcharge: ${reasons.join("; ")}.` : void 0;
|
|
4206
|
+
const display = `${amount.display} paid from your credit under your standing limit. ` + (mandate ? `Running credit total ${money(total, currency)} of ${money(mandate.max_total_micro, currency)} budget.` : "The signed standing limit is not available locally, so its limits could not be checked.") + (overchargeDisplay ? ` ${overchargeDisplay}` : "");
|
|
4207
|
+
reports.push({
|
|
4208
|
+
amount_msats: ask?.content.amount_msats ?? 0,
|
|
4209
|
+
seq: message.seq,
|
|
4210
|
+
request_seq: paid.request_seq,
|
|
4211
|
+
mandate: true,
|
|
4212
|
+
amount,
|
|
4213
|
+
limits_checked: !!mandate,
|
|
4214
|
+
total_micro: total,
|
|
4215
|
+
budget_micro: mandate?.max_total_micro,
|
|
4216
|
+
currency,
|
|
4217
|
+
overcharged: violations.length > 0,
|
|
4218
|
+
violated_limits: violations,
|
|
4219
|
+
overcharge_display: overchargeDisplay,
|
|
4220
|
+
display
|
|
4221
|
+
});
|
|
4222
|
+
}
|
|
4223
|
+
return reports;
|
|
4224
|
+
}
|
|
4225
|
+
function mandatePaymentSummary(job, messages) {
|
|
4226
|
+
const payments = mandatePaymentReports(job, messages);
|
|
4227
|
+
if (!payments.length) return {};
|
|
4228
|
+
const violated = [...new Set(payments.flatMap((payment) => payment.violated_limits))];
|
|
4229
|
+
return { mandate_payments: payments, ...violated.length ? {
|
|
4230
|
+
overcharged: true,
|
|
4231
|
+
violated_limits: violated,
|
|
4232
|
+
display: [...new Set(payments.map((payment) => payment.overcharge_display).filter(Boolean))].join(" ")
|
|
4233
|
+
} : {} };
|
|
4234
|
+
}
|
|
4235
|
+
function recordMandatePayments(jobId, history) {
|
|
4236
|
+
if (!loadJob(jobId)?.mandate || !history.some(mandateCredit)) return;
|
|
4237
|
+
mutateCreditPayment(jobId, (job) => {
|
|
4238
|
+
for (const message of history) {
|
|
4239
|
+
const credit = mandateCredit(message);
|
|
4240
|
+
if (!credit) continue;
|
|
4241
|
+
if (job.pendingCreditPayment?.authorization.request_seq === credit.request_seq)
|
|
4242
|
+
delete job.pendingCreditPayment;
|
|
4243
|
+
const booked2 = job.mandatePaymentSeqs?.includes(message.seq) === true;
|
|
4244
|
+
const ask = history.find((entry) => entry.seq === credit.request_seq && entry.type === "payment-request");
|
|
4245
|
+
const msats = ask?.type === "payment-request" ? ask.content.amount_msats : 0;
|
|
4246
|
+
const valuations = job.mandatePaymentMsats ??= {};
|
|
4247
|
+
const previous = valuations[message.seq] ?? 0;
|
|
4248
|
+
if (!booked2 || previous === 0 && msats > 0) {
|
|
4249
|
+
valuations[message.seq] = msats;
|
|
4250
|
+
job.totalPaidMsats = (job.totalPaidMsats ?? 0) + msats - previous;
|
|
4251
|
+
if (credit.currency === "usd") job.paidUsdMsats = (job.paidUsdMsats ?? 0) + msats - previous;
|
|
4252
|
+
}
|
|
4253
|
+
if (!booked2) {
|
|
4254
|
+
(job.mandatePaymentSeqs ??= []).push(message.seq);
|
|
4255
|
+
job.paymentsHonoured = (job.paymentsHonoured ?? 0) + 1;
|
|
4256
|
+
if (credit.currency === "usd") job.paidUsdMicro = (job.paidUsdMicro ?? 0) + credit.amount_micro;
|
|
4257
|
+
(job.paymentApprovals ??= []).push({ requestSeq: credit.request_seq, approval: "auto" });
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4260
|
+
}, true);
|
|
4261
|
+
}
|
|
4262
|
+
function storedMandateSummary(jobId) {
|
|
4263
|
+
return mandatePaymentSummary(loadJob(jobId), loadMessages(jobId));
|
|
4264
|
+
}
|
|
4265
|
+
|
|
4097
4266
|
// src/lib/wallet-agent/journal-file.ts
|
|
4098
4267
|
var import_proper_lockfile4 = __toESM(require_proper_lockfile(), 1);
|
|
4099
4268
|
import { closeSync as closeSync6, existsSync as existsSync5, fsyncSync as fsyncSync5, openSync as openSync6, readFileSync as readFileSync6, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "fs";
|
|
@@ -5202,6 +5371,8 @@ function loadAnsweredYieldSeqs(jobId) {
|
|
|
5202
5371
|
const answered = answeredYieldSeqs(loadMessages(jobId));
|
|
5203
5372
|
const job = loadJob(jobId);
|
|
5204
5373
|
for (const seq of job?.paidPaymentRequestSeqs ?? []) answered.add(seq);
|
|
5374
|
+
for (const landing of Object.values(job?.paymentCreditLandings ?? {}))
|
|
5375
|
+
if (landing.ask_answered && landing.request_seq !== void 0) answered.add(landing.request_seq);
|
|
5205
5376
|
for (const payment of job?.bookedCreditPayments ?? []) answered.add(payment.authorization.request_seq);
|
|
5206
5377
|
for (const seq of declinedAskSeqs(jobId)) answered.add(seq);
|
|
5207
5378
|
return answered;
|
|
@@ -5253,6 +5424,14 @@ async function reconcilePaymentRequestHistory(jobId, requestSeq, history, status
|
|
|
5253
5424
|
async function settleRecordedPayments(jobId) {
|
|
5254
5425
|
await applySubmissionVerdicts().catch(() => void 0);
|
|
5255
5426
|
const job = loadJob(jobId);
|
|
5427
|
+
const recorded = job?.mandate || job?.pendingCreditPayment ? loadMessages(jobId) : [];
|
|
5428
|
+
if (job?.mandate) recordMandatePayments(jobId, recorded);
|
|
5429
|
+
const pending = loadJob(jobId)?.pendingCreditPayment;
|
|
5430
|
+
if (pending && recorded.some((message) => {
|
|
5431
|
+
const credit = message.type === "payment" && message.from === "requester" ? message.content.credit : void 0;
|
|
5432
|
+
const expected = pending.authorization;
|
|
5433
|
+
return credit && credit.payment_id === expected.payment_id && credit.request_seq === expected.request_seq && credit.credit_id === expected.credit_id && credit.draw_id === expected.draw_id && credit.amount_micro === expected.amount_micro && credit.currency === expected.currency;
|
|
5434
|
+
})) bookCreditPayment(jobId, pending);
|
|
5256
5435
|
const held = /* @__PURE__ */ new Set([
|
|
5257
5436
|
...job?.inFlightPaymentRequestSeqs ?? [],
|
|
5258
5437
|
...Object.keys(job?.unconfirmedPaymentSubmissions ?? {}).map(Number)
|
|
@@ -5383,8 +5562,8 @@ function computeNextAction(jobId, messages, nowMs = Date.now(), context) {
|
|
|
5383
5562
|
case "payment-request": {
|
|
5384
5563
|
const c = msg.content;
|
|
5385
5564
|
const display = formatPaymentAmount(c.amount_msats, c.fiat_amount);
|
|
5386
|
-
const
|
|
5387
|
-
const priceGuidance =
|
|
5565
|
+
const safeCurrency2 = !c.fiat_amount || c.fiat_amount.amount <= 0 || c.fiat_amount.currency.length === 3 && /^[A-Z]{3}$/i.test(c.fiat_amount.currency);
|
|
5566
|
+
const priceGuidance = safeCurrency2 ? display : "see the provider price in next_action.fiat_amount";
|
|
5388
5567
|
const deadline = deadlineClause(expiresAtMs === validDeadline(c.expires_at_ms) ? "Pay" : "Reply", expiresAtMs, nowMs, jobId);
|
|
5389
5568
|
const expired = expiresAtMs !== void 0 && expiresAtMs <= nowMs;
|
|
5390
5569
|
const policy = context?.policy;
|
|
@@ -5558,12 +5737,12 @@ async function stablecoinRemaining(rail) {
|
|
|
5558
5737
|
const balance = await Promise.race([
|
|
5559
5738
|
(async () => {
|
|
5560
5739
|
if (rail === "x402") {
|
|
5561
|
-
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-
|
|
5740
|
+
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-CZV4TOJ3.js");
|
|
5562
5741
|
const wallet = loadX402Wallet2();
|
|
5563
5742
|
if (!wallet) return;
|
|
5564
5743
|
return (await getX402Balance(await ensureAddress(wallet))).usdc;
|
|
5565
5744
|
}
|
|
5566
|
-
const { connectedTempoAccount: connectedTempoAccount2 } = await import("./tempo-wallet-
|
|
5745
|
+
const { connectedTempoAccount: connectedTempoAccount2 } = await import("./tempo-wallet-D424H37T.js");
|
|
5567
5746
|
const account = await connectedTempoAccount2();
|
|
5568
5747
|
if (account) return (await getTempoUsdcBalance(account)).usdc;
|
|
5569
5748
|
})(),
|
|
@@ -5605,10 +5784,12 @@ function pieceSettlement(receipt, context = {}) {
|
|
|
5605
5784
|
);
|
|
5606
5785
|
const basis = lowest?.[0];
|
|
5607
5786
|
const ceiling = lowest?.[1];
|
|
5608
|
-
const
|
|
5609
|
-
const
|
|
5610
|
-
|
|
5611
|
-
|
|
5787
|
+
const mandateCheck = mandatePaymentSummary(job, messages);
|
|
5788
|
+
const overcharged = mandateCheck.overcharged === true || ceiling !== void 0 && settlement.charged > ceiling;
|
|
5789
|
+
const money2 = (micro) => formatMicro(micro, currency);
|
|
5790
|
+
let display = `Charged ${money2(settlement.charged)} of ${money2(settlement.held)} held, ${money2(settlement.released)} released.`;
|
|
5791
|
+
if (mandateCheck.overcharged) display += ` ${mandateCheck.display}`;
|
|
5792
|
+
if (ceiling !== void 0 && settlement.charged > ceiling) display += ` ${overchargeClause(basis, money2(ceiling))}`;
|
|
5612
5793
|
return {
|
|
5613
5794
|
held_micro: settlement.held,
|
|
5614
5795
|
charged_micro: settlement.charged,
|
|
@@ -5616,6 +5797,7 @@ function pieceSettlement(receipt, context = {}) {
|
|
|
5616
5797
|
stopped_micro: stopped,
|
|
5617
5798
|
currency,
|
|
5618
5799
|
...ceiling !== void 0 ? { ceiling_micro: ceiling, ceiling_basis: basis } : {},
|
|
5800
|
+
...mandateCheck.violated_limits ? { violated_limits: mandateCheck.violated_limits } : {},
|
|
5619
5801
|
overcharged,
|
|
5620
5802
|
display
|
|
5621
5803
|
};
|
|
@@ -5656,7 +5838,7 @@ function paidCeiling(job, messages, settlement, currency, ending) {
|
|
|
5656
5838
|
asks.set(message.seq, message.content);
|
|
5657
5839
|
latestAsk = message.seq;
|
|
5658
5840
|
const declined = message.content.charged_if_declined_micro;
|
|
5659
|
-
if (
|
|
5841
|
+
if (validMicro3(declined) && sameCurrency(message.content.credit?.currency, currency)) {
|
|
5660
5842
|
finished = declined;
|
|
5661
5843
|
afterAsk = 0;
|
|
5662
5844
|
}
|
|
@@ -5664,7 +5846,7 @@ function paidCeiling(job, messages, settlement, currency, ending) {
|
|
|
5664
5846
|
const credit = message.content.credit;
|
|
5665
5847
|
const ask = asks.get(credit?.request_seq ?? latestAsk ?? -1)?.credit;
|
|
5666
5848
|
const price = credit ? credit : ask;
|
|
5667
|
-
if (!price || !
|
|
5849
|
+
if (!price || !validMicro3(price.amount_micro) || !sameCurrency(price.currency, currency)) return void 0;
|
|
5668
5850
|
paid += price.amount_micro;
|
|
5669
5851
|
afterAsk += price.amount_micro;
|
|
5670
5852
|
}
|
|
@@ -5674,7 +5856,7 @@ function paidCeiling(job, messages, settlement, currency, ending) {
|
|
|
5674
5856
|
}
|
|
5675
5857
|
function declineCap(job, messages) {
|
|
5676
5858
|
const ask = messages.findLast((message) => message.from === "provider" && message.type === "payment-request");
|
|
5677
|
-
if (!ask || !
|
|
5859
|
+
if (!ask || !validMicro3(ask.content.charged_if_declined_micro)) return void 0;
|
|
5678
5860
|
const recorded = [
|
|
5679
5861
|
...job.paidPaymentRequestSeqs ?? [],
|
|
5680
5862
|
...job.inFlightPaymentRequestSeqs ?? [],
|
|
@@ -5684,7 +5866,7 @@ function declineCap(job, messages) {
|
|
|
5684
5866
|
const paidAsk = answeredYieldSeqs(messages).has(ask.seq) || recorded.includes(ask.seq);
|
|
5685
5867
|
if (!paidAsk) return ask.content.charged_if_declined_micro;
|
|
5686
5868
|
const price = ask.content.credit?.amount_micro;
|
|
5687
|
-
return
|
|
5869
|
+
return validMicro3(price) ? ask.content.charged_if_declined_micro + price : void 0;
|
|
5688
5870
|
}
|
|
5689
5871
|
function wholeThroughEnd(messages) {
|
|
5690
5872
|
if (messages.length === 0 || messages[0].seq > 1) return false;
|
|
@@ -5701,7 +5883,7 @@ function settlementCurrency(receipt, job, messages, hint) {
|
|
|
5701
5883
|
const creditId = receipt.credit?.credit_id;
|
|
5702
5884
|
if (creditId) candidates.push(safeCredits().find((credit) => credit.creditId === creditId)?.currency);
|
|
5703
5885
|
const railUsd = typeof job?.upfrontRailPayment === "object" ? job.upfrontRailPayment?.usdMicro : void 0;
|
|
5704
|
-
if (!job?.upfrontRailConflict &&
|
|
5886
|
+
if (!job?.upfrontRailConflict && validMicro3(railUsd) && railUsd === receipt.settlement?.held) candidates.push("usd");
|
|
5705
5887
|
const found = candidates.find((currency) => typeof currency === "string" && /^[a-z]{3}$/i.test(currency));
|
|
5706
5888
|
return found ? found.toLowerCase() : null;
|
|
5707
5889
|
}
|
|
@@ -5715,13 +5897,13 @@ function safeCredits() {
|
|
|
5715
5897
|
function sameCurrency(a, b) {
|
|
5716
5898
|
return typeof a === "string" && a.toLowerCase() === b;
|
|
5717
5899
|
}
|
|
5718
|
-
function
|
|
5900
|
+
function validMicro3(value) {
|
|
5719
5901
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
5720
5902
|
}
|
|
5721
5903
|
function isSettlement(value) {
|
|
5722
5904
|
if (!value || typeof value !== "object") return false;
|
|
5723
5905
|
const s = value;
|
|
5724
|
-
return
|
|
5906
|
+
return validMicro3(s.held) && validMicro3(s.charged) && validMicro3(s.released) && Array.isArray(s.pieces) && s.pieces.every((piece) => piece && typeof piece === "object" && validMicro3(piece.amount) && validMicro3(piece.charged) && typeof piece.state === "string");
|
|
5725
5907
|
}
|
|
5726
5908
|
|
|
5727
5909
|
// src/lib/job-settlement.ts
|
|
@@ -5759,6 +5941,7 @@ function receiptSettlement(receipt, verification, rate, context) {
|
|
|
5759
5941
|
currency: pieces.currency,
|
|
5760
5942
|
...pieces.ceiling_micro !== void 0 ? { ceiling_micro: pieces.ceiling_micro, ceiling_basis: pieces.ceiling_basis } : {},
|
|
5761
5943
|
overcharged: pieces.overcharged,
|
|
5944
|
+
...pieces.violated_limits ? { violated_limits: pieces.violated_limits } : {},
|
|
5762
5945
|
display: pieces.display
|
|
5763
5946
|
};
|
|
5764
5947
|
}
|
|
@@ -6110,7 +6293,12 @@ function captureJobReceipt(jobId, receipt, parseError) {
|
|
|
6110
6293
|
}
|
|
6111
6294
|
function warnPieceOvercharge(jobId, receipt, job) {
|
|
6112
6295
|
const pieces = pieceSettlement(receipt, { job, messages: loadMessages(jobId) });
|
|
6113
|
-
if (!pieces?.overcharged
|
|
6296
|
+
if (!pieces?.overcharged) return;
|
|
6297
|
+
if (pieces.violated_limits?.length) {
|
|
6298
|
+
info(`Warning: ${pieces.display} Keep the receipt for job ${jobId} as evidence.`);
|
|
6299
|
+
return;
|
|
6300
|
+
}
|
|
6301
|
+
if (pieces.ceiling_micro === void 0) return;
|
|
6114
6302
|
const ceiling = formatMicro(pieces.ceiling_micro, pieces.currency);
|
|
6115
6303
|
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`;
|
|
6116
6304
|
info(
|
|
@@ -7281,6 +7469,7 @@ async function fundOverX402(args, fundId, resumed, corrected = false, locked = f
|
|
|
7281
7469
|
await processX402BatchResponseForWallet({
|
|
7282
7470
|
wallet,
|
|
7283
7471
|
depositMicro: pending.targetMicro,
|
|
7472
|
+
paymentHeader: pending.paymentHeader,
|
|
7284
7473
|
paymentResponse: result.x402PaymentResponse,
|
|
7285
7474
|
channelId: pending.channelId
|
|
7286
7475
|
});
|
|
@@ -9992,6 +10181,7 @@ export {
|
|
|
9992
10181
|
loadAllJobs,
|
|
9993
10182
|
addPayment,
|
|
9994
10183
|
recordBudgetRefusal,
|
|
10184
|
+
recordPaymentCreditLanding,
|
|
9995
10185
|
markPaymentRequestInFlight,
|
|
9996
10186
|
clearPaymentRequestInFlight,
|
|
9997
10187
|
markPaymentRequestPaid,
|
|
@@ -10020,6 +10210,12 @@ export {
|
|
|
10020
10210
|
recordSpendOnce,
|
|
10021
10211
|
enforceGlobalBudget,
|
|
10022
10212
|
statusSnapshot,
|
|
10213
|
+
mandateCredit,
|
|
10214
|
+
mandateDrawTotal,
|
|
10215
|
+
mandatePaymentReports,
|
|
10216
|
+
mandatePaymentSummary,
|
|
10217
|
+
recordMandatePayments,
|
|
10218
|
+
storedMandateSummary,
|
|
10023
10219
|
journalFile,
|
|
10024
10220
|
extractBuilderHandle,
|
|
10025
10221
|
reservedForMarker,
|
|
@@ -10038,6 +10234,7 @@ export {
|
|
|
10038
10234
|
formatLocktime,
|
|
10039
10235
|
prepareAgentSpend,
|
|
10040
10236
|
commitAgentSpend,
|
|
10237
|
+
commitHeldSubmission,
|
|
10041
10238
|
correctPendingFundAmount,
|
|
10042
10239
|
abandonPendingSubmission,
|
|
10043
10240
|
abandonSubmissionInWallet,
|
|
@@ -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-BU5E7IDF.js";
|
|
8
8
|
import {
|
|
9
9
|
tempoAccountFromConfig,
|
|
10
10
|
tryResolveTempoAsset
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-CMIEPFKP.js";
|
|
12
12
|
import {
|
|
13
13
|
DvmError
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-MP63OWTD.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-BOW6OFSI.js");
|
|
50
50
|
await assertTempoWalletIdle("replace");
|
|
51
51
|
}
|
|
52
52
|
const { privateKeyToAccount, generatePrivateKey } = await import("./accounts-2WZE4N5F.js");
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
authorizeProtectedRemoval,
|
|
6
6
|
loadConfig,
|
|
7
7
|
updateConfig
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-BU5E7IDF.js";
|
|
9
9
|
import {
|
|
10
10
|
withX402ChannelLock,
|
|
11
11
|
x402WalletFromConfig
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-CMIEPFKP.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-MP63OWTD.js";
|
|
21
21
|
|
|
22
22
|
// src/lib/x402/networks.ts
|
|
23
23
|
function x402NetworkLabel(network) {
|