@dvmkit/dvm-cli 0.7.0-rc.2 → 0.7.0-rc.3
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-6QHVPJNX.js → chunk-2I5XAIQ4.js} +3 -3
- package/dist/{chunk-RQYMWLX4.js → chunk-3PV36227.js} +2 -2
- package/dist/{chunk-7UAQTHNP.js → chunk-5QO3MGMH.js} +4 -4
- package/dist/{chunk-PG7MEKJI.js → chunk-5VOAE2CL.js} +2 -2
- package/dist/{chunk-JTMBSEZO.js → chunk-6JP6ZBWW.js} +4 -4
- package/dist/{chunk-ZXVOMXT4.js → chunk-7OA2XUM4.js} +2 -2
- package/dist/{chunk-VLZ2K7JL.js → chunk-BHJLMVO2.js} +27 -6
- package/dist/{chunk-FPWP4S5S.js → chunk-C5XIOTRP.js} +36 -5
- package/dist/{chunk-IQV4KG63.js → chunk-EQXNDN5I.js} +2 -2
- package/dist/{chunk-U3YRNLZ5.js → chunk-IERBEO4C.js} +3 -3
- package/dist/{chunk-VIYUB3XT.js → chunk-LIITTIEN.js} +347 -85
- package/dist/{chunk-WN5R367B.js → chunk-ZM5QFHEY.js} +30 -2
- package/dist/{client-IDO4IAXG.js → client-PGOH2ION.js} +6 -6
- package/dist/dvm.js +1779 -620
- package/dist/{internal-7FXJTFBU.js → internal-VIAWW5ED.js} +13 -5
- package/dist/{lifecycle-LRS3IBQL.js → lifecycle-VHGTNHHE.js} +6 -6
- package/dist/{payout-reporter-WT7XYW42-U2QPDIYC.js → payout-reporter-3UVWPGMO-WWZWXWCG.js} +6 -4
- package/dist/{pocket-refill-J5OWRBXH.js → pocket-refill-BHNKMENF.js} +10 -10
- package/dist/{revenue-reporter-7UR3W2SD-C5OMRGK3.js → revenue-reporter-E56J3NZK-NZ5H27ZI.js} +2 -2
- package/dist/{tempo-lifecycle-HS2NIFKT.js → tempo-lifecycle-NDBO3V3A.js} +8 -8
- package/dist/{tempo-wallet-BA2LKR45.js → tempo-wallet-BAU7ASWF.js} +7 -7
- package/dist/{wallet-RPPUCQUR.js → wallet-RB2RPWIN.js} +7 -7
- package/dist/{x402-ZU4GML7Z-RYEACIIT.js → x402-BN26TQZ6-4MWLNZGT.js} +2 -2
- package/package.json +2 -2
package/dist/dvm.js
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
assertTempoWalletIdle,
|
|
6
6
|
findSigningIdentityByPubkey,
|
|
7
7
|
resolveSigningIdentity
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-IERBEO4C.js";
|
|
9
9
|
import {
|
|
10
10
|
assertX402WalletIdle
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-5VOAE2CL.js";
|
|
12
12
|
import {
|
|
13
13
|
DEFAULT_CREDIT_POSTURE,
|
|
14
14
|
DEFAULT_RESERVE_LOCKTIME_SECONDS,
|
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
loadJob,
|
|
48
48
|
loadLedger,
|
|
49
49
|
markJobTerminal,
|
|
50
|
+
markPendingSubmissionUnresolved,
|
|
50
51
|
markProofsInFlight,
|
|
51
52
|
meltInFlightTimeoutSeconds,
|
|
52
53
|
needsTopup,
|
|
@@ -69,6 +70,7 @@ import {
|
|
|
69
70
|
receiptTrustFields,
|
|
70
71
|
recordFloatSpend,
|
|
71
72
|
recordSpend,
|
|
73
|
+
recordSpendOnce,
|
|
72
74
|
renderReceiptHuman,
|
|
73
75
|
replayStoredReceipt,
|
|
74
76
|
reservedForMarker,
|
|
@@ -84,8 +86,9 @@ import {
|
|
|
84
86
|
trustLadderFor,
|
|
85
87
|
trustOverrideCapMicro,
|
|
86
88
|
unrecordedFloatBudgetWarning,
|
|
87
|
-
updateJob
|
|
88
|
-
|
|
89
|
+
updateJob,
|
|
90
|
+
withAcceptedUnresolved
|
|
91
|
+
} from "./chunk-BHJLMVO2.js";
|
|
89
92
|
import {
|
|
90
93
|
assertSupportedX402Network,
|
|
91
94
|
connectedX402Payer,
|
|
@@ -94,7 +97,7 @@ import {
|
|
|
94
97
|
repinX402WalletNetwork,
|
|
95
98
|
saveX402Wallet,
|
|
96
99
|
x402NetworkLabel
|
|
97
|
-
} from "./chunk-
|
|
100
|
+
} from "./chunk-2I5XAIQ4.js";
|
|
98
101
|
import {
|
|
99
102
|
assertValidBudget,
|
|
100
103
|
costAnchor,
|
|
@@ -106,19 +109,20 @@ import {
|
|
|
106
109
|
json,
|
|
107
110
|
monetaryJson,
|
|
108
111
|
parseBudget,
|
|
112
|
+
progress,
|
|
109
113
|
raw,
|
|
110
114
|
resolveBtcUsdRate,
|
|
111
115
|
setOutputTraceId,
|
|
112
116
|
staleRateNotice,
|
|
113
117
|
tryResolveBtcUsdRate,
|
|
114
118
|
tryX402Payment
|
|
115
|
-
} from "./chunk-
|
|
119
|
+
} from "./chunk-3PV36227.js";
|
|
116
120
|
import {
|
|
117
121
|
connectedTempoAccount,
|
|
118
122
|
generateTempoKey,
|
|
119
123
|
tempoBalanceCheckHint,
|
|
120
124
|
tempoWrongAssetHint
|
|
121
|
-
} from "./chunk-
|
|
125
|
+
} from "./chunk-5QO3MGMH.js";
|
|
122
126
|
import {
|
|
123
127
|
CREDIT_POSTURES,
|
|
124
128
|
FEEDBACK_POSTURES,
|
|
@@ -135,7 +139,7 @@ import {
|
|
|
135
139
|
retireConfigBackup,
|
|
136
140
|
rollbackConfig,
|
|
137
141
|
updateConfig
|
|
138
|
-
} from "./chunk-
|
|
142
|
+
} from "./chunk-7OA2XUM4.js";
|
|
139
143
|
import {
|
|
140
144
|
A,
|
|
141
145
|
AGENT_MNEMONIC_FILE,
|
|
@@ -160,6 +164,7 @@ import {
|
|
|
160
164
|
IDENTITIES_FILE,
|
|
161
165
|
IDENTITIES_VERSION,
|
|
162
166
|
JOBS_FILE,
|
|
167
|
+
JOB_IDENTITY_HEADER,
|
|
163
168
|
MESSAGES_DIR,
|
|
164
169
|
PAIRINGS_DIR,
|
|
165
170
|
PRIVKEY_HEX_RE,
|
|
@@ -261,6 +266,7 @@ import {
|
|
|
261
266
|
isPublicRequestId,
|
|
262
267
|
isSignedJobReceipt,
|
|
263
268
|
isStablecoinFundRail,
|
|
269
|
+
isStorableJobId,
|
|
264
270
|
ki,
|
|
265
271
|
la,
|
|
266
272
|
listCredits,
|
|
@@ -299,6 +305,7 @@ import {
|
|
|
299
305
|
offersX402CreditFunding,
|
|
300
306
|
parseCreditMenu,
|
|
301
307
|
parseCreditTerms,
|
|
308
|
+
parseJobIdentityHeader,
|
|
302
309
|
parseNwcUri,
|
|
303
310
|
parseTraceparent,
|
|
304
311
|
pendingDrainById,
|
|
@@ -376,7 +383,7 @@ import {
|
|
|
376
383
|
x402PendingUnsettled,
|
|
377
384
|
x402RequiredFromError,
|
|
378
385
|
x402ReservationRelease
|
|
379
|
-
} from "./chunk-
|
|
386
|
+
} from "./chunk-LIITTIEN.js";
|
|
380
387
|
import "./chunk-JBU7RKQ3.js";
|
|
381
388
|
import "./chunk-KDNFUDOG.js";
|
|
382
389
|
import "./chunk-IUTVV6N5.js";
|
|
@@ -417,11 +424,11 @@ import {
|
|
|
417
424
|
usdToMsats,
|
|
418
425
|
usdcToMsats,
|
|
419
426
|
x402NetworkByCaip2
|
|
420
|
-
} from "./chunk-
|
|
421
|
-
import "./chunk-
|
|
422
|
-
import "./chunk-
|
|
427
|
+
} from "./chunk-6JP6ZBWW.js";
|
|
428
|
+
import "./chunk-EQXNDN5I.js";
|
|
429
|
+
import "./chunk-C5XIOTRP.js";
|
|
423
430
|
import "./chunk-R2DSAZBO.js";
|
|
424
|
-
import "./chunk-
|
|
431
|
+
import "./chunk-ZM5QFHEY.js";
|
|
425
432
|
import {
|
|
426
433
|
privateKeyToAccount
|
|
427
434
|
} from "./chunk-EVQERRCP.js";
|
|
@@ -9018,6 +9025,724 @@ async function readBoundedBody(response, limit) {
|
|
|
9018
9025
|
}
|
|
9019
9026
|
var MAX_COMPATIBILITY_BODY_BYTES = 16384;
|
|
9020
9027
|
|
|
9028
|
+
// src/lib/favorites.ts
|
|
9029
|
+
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
9030
|
+
import {
|
|
9031
|
+
closeSync as closeSync2,
|
|
9032
|
+
fchmodSync,
|
|
9033
|
+
fsyncSync,
|
|
9034
|
+
openSync as openSync2,
|
|
9035
|
+
readFileSync as readFileSync3,
|
|
9036
|
+
renameSync,
|
|
9037
|
+
statSync as statSync2,
|
|
9038
|
+
unlinkSync,
|
|
9039
|
+
writeFileSync
|
|
9040
|
+
} from "fs";
|
|
9041
|
+
import { dirname as dirname2 } from "path";
|
|
9042
|
+
var DEFAULT_FILE_MODE = 384;
|
|
9043
|
+
function loadFavorites() {
|
|
9044
|
+
let raw2;
|
|
9045
|
+
try {
|
|
9046
|
+
raw2 = readFileSync3(FAVORITES_FILE, "utf8");
|
|
9047
|
+
} catch (error) {
|
|
9048
|
+
if (nodeErrorCode(error) === "ENOENT") return {};
|
|
9049
|
+
throw unreadableFavorites(error);
|
|
9050
|
+
}
|
|
9051
|
+
try {
|
|
9052
|
+
const parsed = JSON.parse(raw2);
|
|
9053
|
+
if (!isFavoritesMap(parsed)) throw new Error("invalid favorites shape");
|
|
9054
|
+
return parsed;
|
|
9055
|
+
} catch (error) {
|
|
9056
|
+
throw unreadableFavorites(error);
|
|
9057
|
+
}
|
|
9058
|
+
}
|
|
9059
|
+
async function saveFavorite(alias, fav) {
|
|
9060
|
+
return withFavoritesLock(() => {
|
|
9061
|
+
const favs = loadFavorites();
|
|
9062
|
+
const existed = Object.hasOwn(favs, alias);
|
|
9063
|
+
favs[alias] = fav;
|
|
9064
|
+
writeFavorites(favs);
|
|
9065
|
+
return existed;
|
|
9066
|
+
});
|
|
9067
|
+
}
|
|
9068
|
+
async function removeFavorite(alias) {
|
|
9069
|
+
return withFavoritesLock(() => {
|
|
9070
|
+
const favs = loadFavorites();
|
|
9071
|
+
if (!Object.hasOwn(favs, alias)) return false;
|
|
9072
|
+
const { [alias]: _, ...rest } = favs;
|
|
9073
|
+
writeFavorites(rest);
|
|
9074
|
+
return true;
|
|
9075
|
+
});
|
|
9076
|
+
}
|
|
9077
|
+
function resolveEndpoint(input) {
|
|
9078
|
+
if (!input.startsWith("@")) return input;
|
|
9079
|
+
const alias = input.slice(1);
|
|
9080
|
+
const favs = loadFavorites();
|
|
9081
|
+
const fav = Object.hasOwn(favs, alias) ? favs[alias] : void 0;
|
|
9082
|
+
if (!fav) {
|
|
9083
|
+
throw new DvmError(
|
|
9084
|
+
"unknown_favorite",
|
|
9085
|
+
`No favorite named "${alias}".`,
|
|
9086
|
+
"Run 'dvm fav list' to see saved favorites, or 'dvm fav add <endpoint>' to save one."
|
|
9087
|
+
);
|
|
9088
|
+
}
|
|
9089
|
+
return fav.endpoint;
|
|
9090
|
+
}
|
|
9091
|
+
function deriveAlias(endpoint) {
|
|
9092
|
+
try {
|
|
9093
|
+
const hostname2 = new URL(endpoint).hostname;
|
|
9094
|
+
if (hostname2.endsWith(".dvmkit.ai")) {
|
|
9095
|
+
const prefix = hostname2.replace(".dvmkit.ai", "");
|
|
9096
|
+
const dashIdx = prefix.indexOf("--");
|
|
9097
|
+
if (dashIdx !== -1) return prefix.slice(dashIdx + 2);
|
|
9098
|
+
return prefix;
|
|
9099
|
+
}
|
|
9100
|
+
return hostname2.replace(/\.[^.]+$/, "").replace(/\./g, "-");
|
|
9101
|
+
} catch {
|
|
9102
|
+
return endpoint.replace(/[^a-z0-9-]/gi, "-").toLowerCase();
|
|
9103
|
+
}
|
|
9104
|
+
}
|
|
9105
|
+
async function withFavoritesLock(fn) {
|
|
9106
|
+
ensureConfigDir();
|
|
9107
|
+
let release;
|
|
9108
|
+
try {
|
|
9109
|
+
release = await import_proper_lockfile.default.lock(FAVORITES_FILE, {
|
|
9110
|
+
lockfilePath: `${FAVORITES_FILE}.lock`,
|
|
9111
|
+
realpath: false,
|
|
9112
|
+
stale: 3e4,
|
|
9113
|
+
retries: { retries: 10, factor: 1, minTimeout: 100, maxTimeout: 100 }
|
|
9114
|
+
});
|
|
9115
|
+
} catch {
|
|
9116
|
+
throw new DvmError(
|
|
9117
|
+
"favorites_locked",
|
|
9118
|
+
"Another dvm process is updating saved favorites.",
|
|
9119
|
+
"Wait a moment and retry."
|
|
9120
|
+
);
|
|
9121
|
+
}
|
|
9122
|
+
try {
|
|
9123
|
+
return await fn();
|
|
9124
|
+
} finally {
|
|
9125
|
+
await release().catch(() => void 0);
|
|
9126
|
+
}
|
|
9127
|
+
}
|
|
9128
|
+
function writeFavorites(favorites) {
|
|
9129
|
+
const mode = favoritesFileMode();
|
|
9130
|
+
const temporary = `${FAVORITES_FILE}.${String(process.pid)}.${randomSuffix()}.tmp`;
|
|
9131
|
+
const contents = JSON.stringify(favorites, null, 2) + "\n";
|
|
9132
|
+
let fd;
|
|
9133
|
+
try {
|
|
9134
|
+
fd = openSync2(temporary, "wx", mode);
|
|
9135
|
+
fchmodSync(fd, mode);
|
|
9136
|
+
writeFileSync(fd, contents);
|
|
9137
|
+
fsyncSync(fd);
|
|
9138
|
+
closeSync2(fd);
|
|
9139
|
+
fd = void 0;
|
|
9140
|
+
renameSync(temporary, FAVORITES_FILE);
|
|
9141
|
+
fsyncDirectory(dirname2(FAVORITES_FILE));
|
|
9142
|
+
} catch (error) {
|
|
9143
|
+
if (fd !== void 0) {
|
|
9144
|
+
try {
|
|
9145
|
+
closeSync2(fd);
|
|
9146
|
+
} catch {
|
|
9147
|
+
}
|
|
9148
|
+
}
|
|
9149
|
+
try {
|
|
9150
|
+
unlinkSync(temporary);
|
|
9151
|
+
} catch {
|
|
9152
|
+
}
|
|
9153
|
+
throw error;
|
|
9154
|
+
}
|
|
9155
|
+
}
|
|
9156
|
+
function favoritesFileMode() {
|
|
9157
|
+
try {
|
|
9158
|
+
return statSync2(FAVORITES_FILE).mode & 511;
|
|
9159
|
+
} catch (error) {
|
|
9160
|
+
if (nodeErrorCode(error) === "ENOENT") return DEFAULT_FILE_MODE;
|
|
9161
|
+
throw error;
|
|
9162
|
+
}
|
|
9163
|
+
}
|
|
9164
|
+
function fsyncDirectory(path) {
|
|
9165
|
+
const fd = openSync2(path, "r");
|
|
9166
|
+
try {
|
|
9167
|
+
fsyncSync(fd);
|
|
9168
|
+
} finally {
|
|
9169
|
+
closeSync2(fd);
|
|
9170
|
+
}
|
|
9171
|
+
}
|
|
9172
|
+
function randomSuffix() {
|
|
9173
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
9174
|
+
}
|
|
9175
|
+
function unreadableFavorites(error) {
|
|
9176
|
+
return new DvmError(
|
|
9177
|
+
"favorites_unreadable",
|
|
9178
|
+
"Saved favorites are corrupt or unreadable.",
|
|
9179
|
+
`The original file at ${FAVORITES_FILE} was left unchanged. Restore it from a backup, or move it aside before rebuilding favorites.`,
|
|
9180
|
+
{
|
|
9181
|
+
path: FAVORITES_FILE,
|
|
9182
|
+
...nodeErrorCode(error) ? { error_code: nodeErrorCode(error) } : {}
|
|
9183
|
+
}
|
|
9184
|
+
);
|
|
9185
|
+
}
|
|
9186
|
+
function nodeErrorCode(error) {
|
|
9187
|
+
if (!(error instanceof Error) || !("code" in error)) return void 0;
|
|
9188
|
+
const code = error.code;
|
|
9189
|
+
return typeof code === "string" && /^E[A-Z0-9_]{1,63}$/.test(code) ? code : void 0;
|
|
9190
|
+
}
|
|
9191
|
+
function isFavoritesMap(value) {
|
|
9192
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
9193
|
+
return Object.values(value).every(isFavorite);
|
|
9194
|
+
}
|
|
9195
|
+
function isFavorite(value) {
|
|
9196
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
9197
|
+
const candidate = value;
|
|
9198
|
+
return typeof candidate.endpoint === "string" && typeof candidate.addedAt === "number" && Number.isFinite(candidate.addedAt) && (candidate.name === void 0 || typeof candidate.name === "string");
|
|
9199
|
+
}
|
|
9200
|
+
|
|
9201
|
+
// src/lib/submission-evidence.ts
|
|
9202
|
+
import { createHash, randomUUID } from "crypto";
|
|
9203
|
+
import {
|
|
9204
|
+
closeSync as closeSync3,
|
|
9205
|
+
existsSync as existsSync3,
|
|
9206
|
+
fsyncSync as fsyncSync2,
|
|
9207
|
+
linkSync,
|
|
9208
|
+
openSync as openSync3,
|
|
9209
|
+
readdirSync,
|
|
9210
|
+
readFileSync as readFileSync4,
|
|
9211
|
+
unlinkSync as unlinkSync2,
|
|
9212
|
+
writeFileSync as writeFileSync2
|
|
9213
|
+
} from "fs";
|
|
9214
|
+
import { join as join3 } from "path";
|
|
9215
|
+
|
|
9216
|
+
// src/lib/job-identity.ts
|
|
9217
|
+
var IDENTITY_FAILURE_CODES = {
|
|
9218
|
+
identity_mismatch: "provider_identity_mismatch",
|
|
9219
|
+
body_unreadable: "provider_body_unreadable",
|
|
9220
|
+
router_identity_conflict: "hosting_job_identity_conflict"
|
|
9221
|
+
};
|
|
9222
|
+
var ProviderIdentityError = class extends DvmError {
|
|
9223
|
+
observation;
|
|
9224
|
+
constructor(observation, message2, hint, data, proseSources) {
|
|
9225
|
+
super(IDENTITY_FAILURE_CODES[observation.kind], message2, hint, data, void 0, proseSources);
|
|
9226
|
+
this.observation = observation;
|
|
9227
|
+
}
|
|
9228
|
+
};
|
|
9229
|
+
function isIdentityFailure(err) {
|
|
9230
|
+
return err instanceof ProviderIdentityError;
|
|
9231
|
+
}
|
|
9232
|
+
function isParseableBodyJobId(value) {
|
|
9233
|
+
return typeof value === "string" && value.trim().length > 0 && value.length <= 512 && !hasAsciiControl(value);
|
|
9234
|
+
}
|
|
9235
|
+
function isOpaqueJobToken(value) {
|
|
9236
|
+
return typeof value === "string" && value.length > 0 && value.length <= 4096 && value.trim() === value && !hasAsciiControl(value);
|
|
9237
|
+
}
|
|
9238
|
+
function observedJobId(value) {
|
|
9239
|
+
return isStorableJobId(value) ? value : void 0;
|
|
9240
|
+
}
|
|
9241
|
+
function observeJobId(value) {
|
|
9242
|
+
if (value === void 0) return {};
|
|
9243
|
+
if (isStorableJobId(value)) return { stored: value };
|
|
9244
|
+
return { escaped: escapeObservedValue(value) };
|
|
9245
|
+
}
|
|
9246
|
+
var ESCAPED_OBSERVED_VALUE_SOURCE_LIMIT = 1024;
|
|
9247
|
+
function escapeObservedValue(value) {
|
|
9248
|
+
const source = typeof value === "string" ? value : JSON.stringify(value) ?? String(value);
|
|
9249
|
+
const truncated = source.length > ESCAPED_OBSERVED_VALUE_SOURCE_LIMIT;
|
|
9250
|
+
const quoted = JSON.stringify(
|
|
9251
|
+
truncated ? source.slice(0, ESCAPED_OBSERVED_VALUE_SOURCE_LIMIT) : source
|
|
9252
|
+
).replace(
|
|
9253
|
+
/[\u007f-\u009f]/gu,
|
|
9254
|
+
(character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`
|
|
9255
|
+
);
|
|
9256
|
+
return truncated ? `${quoted} [truncated from ${String(source.length)} characters]` : quoted;
|
|
9257
|
+
}
|
|
9258
|
+
function settleJobIdentity(headerValue, body) {
|
|
9259
|
+
const header = parseJobIdentityHeader(headerValue);
|
|
9260
|
+
const headerJobId = header.kind === "valid" ? header.jobId : void 0;
|
|
9261
|
+
const rawBodyJobId = body?.job_id;
|
|
9262
|
+
const jobToken = isOpaqueJobToken(body?.job_token) ? body.job_token : void 0;
|
|
9263
|
+
const observed = (kind) => {
|
|
9264
|
+
const bodyJob = observeJobId(rawBodyJobId);
|
|
9265
|
+
return {
|
|
9266
|
+
kind: "unresolved",
|
|
9267
|
+
observation: {
|
|
9268
|
+
kind,
|
|
9269
|
+
...headerJobId ? { headerJobId } : {},
|
|
9270
|
+
...optionalField("bodyJobId", bodyJob.stored),
|
|
9271
|
+
...bodyJob.escaped ? { unstorable: { body_job_id: bodyJob.escaped } } : {},
|
|
9272
|
+
...jobToken ? { jobToken } : {}
|
|
9273
|
+
}
|
|
9274
|
+
};
|
|
9275
|
+
};
|
|
9276
|
+
if (!isParseableBodyJobId(rawBodyJobId)) return observed("body_unreadable");
|
|
9277
|
+
if (headerJobId !== void 0 && headerJobId !== rawBodyJobId) {
|
|
9278
|
+
return observed("identity_mismatch");
|
|
9279
|
+
}
|
|
9280
|
+
return {
|
|
9281
|
+
kind: "settled",
|
|
9282
|
+
jobId: rawBodyJobId,
|
|
9283
|
+
claimAllowed: header.kind !== "invalid",
|
|
9284
|
+
headerInvalid: header.kind === "invalid"
|
|
9285
|
+
};
|
|
9286
|
+
}
|
|
9287
|
+
function routerConflictObservation(status2, body) {
|
|
9288
|
+
if (status2 !== 409 || !body) return void 0;
|
|
9289
|
+
const error = body.error;
|
|
9290
|
+
if (!error || typeof error !== "object" || Array.isArray(error)) return void 0;
|
|
9291
|
+
const envelope = error;
|
|
9292
|
+
if (envelope.code !== IDENTITY_FAILURE_CODES.router_identity_conflict) return void 0;
|
|
9293
|
+
const accepted = observeJobId(envelope.accepted_job_id);
|
|
9294
|
+
return {
|
|
9295
|
+
kind: "router_identity_conflict",
|
|
9296
|
+
...optionalField("acceptedJobId", accepted.stored),
|
|
9297
|
+
...accepted.escaped ? { unstorable: { accepted_job_id: accepted.escaped } } : {}
|
|
9298
|
+
};
|
|
9299
|
+
}
|
|
9300
|
+
function jobIdentityHeaderValue(headers) {
|
|
9301
|
+
return headers.get(JOB_IDENTITY_HEADER);
|
|
9302
|
+
}
|
|
9303
|
+
function identityError(observation, providerProse) {
|
|
9304
|
+
const { message: message2, display } = describeIdentityFailure(observation);
|
|
9305
|
+
return new ProviderIdentityError(
|
|
9306
|
+
observation,
|
|
9307
|
+
message2,
|
|
9308
|
+
"Do not pay for this request again. Run 'dvm wallet submissions' to see what was recorded.",
|
|
9309
|
+
{
|
|
9310
|
+
identity_kind: observation.kind,
|
|
9311
|
+
...identityDataFields(observation),
|
|
9312
|
+
display: providerProse?.display ?? display
|
|
9313
|
+
},
|
|
9314
|
+
providerProse?.proseSources
|
|
9315
|
+
);
|
|
9316
|
+
}
|
|
9317
|
+
function withIdentityRecovery(err, ctx) {
|
|
9318
|
+
const hint = ctx.publicRequestId ? `Run 'dvm request-result ${ctx.publicRequestId}' to read the accepted job. Do not pay for this request again; 'dvm wallet submissions' shows the recorded evidence (${ctx.ambiguityId}).` : `Run 'dvm wallet submissions' to see the recorded evidence (${ctx.ambiguityId}) and how to read each job it names. Do not pay for this request again.`;
|
|
9319
|
+
return new ProviderIdentityError(
|
|
9320
|
+
err.observation,
|
|
9321
|
+
err.message,
|
|
9322
|
+
hint,
|
|
9323
|
+
{
|
|
9324
|
+
...err.data,
|
|
9325
|
+
ambiguity_id: ctx.ambiguityId,
|
|
9326
|
+
...ctx.publicRequestId ? { request_id: ctx.publicRequestId } : {},
|
|
9327
|
+
...ctx.cashuRequestId ? { cashu_request_id: ctx.cashuRequestId } : {},
|
|
9328
|
+
claim_stored: false
|
|
9329
|
+
},
|
|
9330
|
+
err.proseSources
|
|
9331
|
+
);
|
|
9332
|
+
}
|
|
9333
|
+
function withRequestResultRecovery(err, ctx) {
|
|
9334
|
+
const jobId = err.observation.acceptedJobId;
|
|
9335
|
+
const read = `dvm status ${jobId ? shellQuoteArg(jobId) : "<accepted_job_id>"} --endpoint ${shellQuoteArg(ctx.endpoint)} --job-token <job_token_bearer_secret>`;
|
|
9336
|
+
const hint = `Do not pay again. Running request-result again meets the same refusal while the provider keeps answering with a different job. Read ${jobId ? `job ${jobId}` : "the accepted job"} directly with '${read}', taking the job token from a row for request ${ctx.requestId} in 'dvm wallet submissions' (this refusal is recorded as ${ctx.ambiguityId}). If no row for it holds a job token, this caller never received one for that job.`;
|
|
9337
|
+
return new ProviderIdentityError(
|
|
9338
|
+
err.observation,
|
|
9339
|
+
err.message,
|
|
9340
|
+
hint,
|
|
9341
|
+
{ ...err.data, ambiguity_id: ctx.ambiguityId, request_id: ctx.requestId, claim_stored: false },
|
|
9342
|
+
err.proseSources
|
|
9343
|
+
);
|
|
9344
|
+
}
|
|
9345
|
+
function identityDataFields(observation) {
|
|
9346
|
+
return {
|
|
9347
|
+
...optionalField("header_job_id", observation.headerJobId),
|
|
9348
|
+
...optionalField("body_job_id", observation.bodyJobId),
|
|
9349
|
+
...optionalField("body_job_id_escaped", observation.unstorable?.body_job_id),
|
|
9350
|
+
...optionalField("accepted_job_id", observation.acceptedJobId),
|
|
9351
|
+
...optionalField("accepted_job_id_escaped", observation.unstorable?.accepted_job_id)
|
|
9352
|
+
};
|
|
9353
|
+
}
|
|
9354
|
+
function warnInvalidJobIdentityHeader() {
|
|
9355
|
+
const display = "The provider sent a malformed job identity header, so it was ignored and the job ID was taken from the response body.";
|
|
9356
|
+
if (process.stderr.isTTY === true) {
|
|
9357
|
+
info(`Warning: ${display}`);
|
|
9358
|
+
return;
|
|
9359
|
+
}
|
|
9360
|
+
progress({ event: "warning", code: "job_identity_header_invalid", display });
|
|
9361
|
+
}
|
|
9362
|
+
function describeIdentityFailure(observation) {
|
|
9363
|
+
switch (observation.kind) {
|
|
9364
|
+
case "identity_mismatch":
|
|
9365
|
+
return {
|
|
9366
|
+
message: `The provider accepted the request but named job ${observation.headerJobId ?? "(unknown)"} in its response header and job ${observation.bodyJobId ?? "(unrepresentable)"} in its body.`,
|
|
9367
|
+
display: "The provider took this request but gave two different job IDs for it, so it is unclear which job is yours. Do not pay for it again."
|
|
9368
|
+
};
|
|
9369
|
+
case "body_unreadable":
|
|
9370
|
+
return {
|
|
9371
|
+
message: observation.headerJobId ? `The provider accepted the request as job ${observation.headerJobId}, but its response body could not be read.` : "The provider accepted the request, but its response did not state a readable job ID.",
|
|
9372
|
+
display: "The provider took this request but its reply could not be read, so it is unclear which job is yours. Do not pay for it again."
|
|
9373
|
+
};
|
|
9374
|
+
case "router_identity_conflict":
|
|
9375
|
+
return {
|
|
9376
|
+
message: `The router had already accepted job ${observation.acceptedJobId ?? "(unknown)"} for this request, and the provider answered with a different job.`,
|
|
9377
|
+
display: "This request was already accepted as a different job. Do not pay for it again."
|
|
9378
|
+
};
|
|
9379
|
+
}
|
|
9380
|
+
}
|
|
9381
|
+
function hasAsciiControl(value) {
|
|
9382
|
+
for (const character of value) {
|
|
9383
|
+
const code = character.charCodeAt(0);
|
|
9384
|
+
if (code <= 31 || code === 127) return true;
|
|
9385
|
+
}
|
|
9386
|
+
return false;
|
|
9387
|
+
}
|
|
9388
|
+
function optionalField(key, value) {
|
|
9389
|
+
return value === void 0 ? {} : { [key]: value };
|
|
9390
|
+
}
|
|
9391
|
+
|
|
9392
|
+
// src/lib/submission-evidence.ts
|
|
9393
|
+
var SUBMISSION_EVIDENCE_DIR = join3(CONFIG_DIR, "submission-evidence");
|
|
9394
|
+
function submissionEvidenceKey(args) {
|
|
9395
|
+
return args.cashuRequestId ?? args.publicRequestId ?? randomUUID();
|
|
9396
|
+
}
|
|
9397
|
+
function recordSubmissionEvidence(input) {
|
|
9398
|
+
const ambiguityId = submissionEvidenceKey(input);
|
|
9399
|
+
const existing = loadSubmissionEvidence(ambiguityId);
|
|
9400
|
+
if (existing) return existing;
|
|
9401
|
+
const { observation } = input;
|
|
9402
|
+
const jobToken = isOpaqueJobToken(observation.jobToken) ? observation.jobToken : void 0;
|
|
9403
|
+
const record = {
|
|
9404
|
+
v: 1,
|
|
9405
|
+
ambiguity_id: ambiguityId,
|
|
9406
|
+
kind: observation.kind,
|
|
9407
|
+
observed_at: new Date((input.now ?? Date.now)()).toISOString(),
|
|
9408
|
+
endpoint: input.endpoint,
|
|
9409
|
+
...input.dvmId ? { dvm_id: input.dvmId } : {},
|
|
9410
|
+
...input.capability ? { capability: input.capability } : {},
|
|
9411
|
+
...input.publicRequestId ? { request_id: input.publicRequestId } : {},
|
|
9412
|
+
...input.cashuRequestId ? { cashu_request_id: input.cashuRequestId } : {},
|
|
9413
|
+
rail: input.rail,
|
|
9414
|
+
...input.railCorrelation && Object.keys(input.railCorrelation).length > 0 ? { rail_correlation: input.railCorrelation } : {},
|
|
9415
|
+
...jobToken ? { job_token: jobToken } : {},
|
|
9416
|
+
...boundedIds(observation),
|
|
9417
|
+
...observation.unstorable && Object.keys(observation.unstorable).length > 0 ? { unstorable_job_ids: observation.unstorable } : {},
|
|
9418
|
+
claim_stored: false
|
|
9419
|
+
};
|
|
9420
|
+
return publishOnce(record);
|
|
9421
|
+
}
|
|
9422
|
+
function recordLocalJobCollision(input) {
|
|
9423
|
+
const ambiguityId = `${input.publicRequestId}#local-job-collision`;
|
|
9424
|
+
const existing = loadSubmissionEvidence(ambiguityId);
|
|
9425
|
+
if (existing) return existing;
|
|
9426
|
+
const jobToken = isOpaqueJobToken(input.jobToken) ? input.jobToken : void 0;
|
|
9427
|
+
return publishOnce({
|
|
9428
|
+
v: 1,
|
|
9429
|
+
ambiguity_id: ambiguityId,
|
|
9430
|
+
kind: "local_job_collision",
|
|
9431
|
+
observed_at: new Date((input.now ?? Date.now)()).toISOString(),
|
|
9432
|
+
endpoint: input.endpoint,
|
|
9433
|
+
...input.dvmId ? { dvm_id: input.dvmId } : {},
|
|
9434
|
+
...input.capability ? { capability: input.capability } : {},
|
|
9435
|
+
request_id: input.publicRequestId,
|
|
9436
|
+
...input.cashuRequestId ? { cashu_request_id: input.cashuRequestId } : {},
|
|
9437
|
+
rail: input.rail,
|
|
9438
|
+
...input.railCorrelation && Object.keys(input.railCorrelation).length > 0 ? { rail_correlation: input.railCorrelation } : {},
|
|
9439
|
+
...jobToken ? { job_token: jobToken } : {},
|
|
9440
|
+
...boundedIds({ acceptedJobId: input.jobId }),
|
|
9441
|
+
claim_stored: false
|
|
9442
|
+
});
|
|
9443
|
+
}
|
|
9444
|
+
function recordIdentityFailure(err, input) {
|
|
9445
|
+
if (identityFailureRecorded(err)) return { error: err, record: null };
|
|
9446
|
+
const record = recordSubmissionEvidence({ ...input, observation: err.observation });
|
|
9447
|
+
return {
|
|
9448
|
+
error: withIdentityRecovery(err, {
|
|
9449
|
+
ambiguityId: record.ambiguity_id,
|
|
9450
|
+
...input.publicRequestId ? { publicRequestId: input.publicRequestId } : {},
|
|
9451
|
+
...input.cashuRequestId ? { cashuRequestId: input.cashuRequestId } : {}
|
|
9452
|
+
}),
|
|
9453
|
+
record
|
|
9454
|
+
};
|
|
9455
|
+
}
|
|
9456
|
+
function identityFailureRecorded(err) {
|
|
9457
|
+
return typeof err.data?.ambiguity_id === "string";
|
|
9458
|
+
}
|
|
9459
|
+
function loadSubmissionEvidence(ambiguityId) {
|
|
9460
|
+
const path = evidencePath(ambiguityId);
|
|
9461
|
+
if (!existsSync3(path)) return null;
|
|
9462
|
+
const record = readRecord(path);
|
|
9463
|
+
if (record.ambiguity_id !== ambiguityId) throw unreadable(path, "key mismatch");
|
|
9464
|
+
return record;
|
|
9465
|
+
}
|
|
9466
|
+
function listSubmissionEvidence() {
|
|
9467
|
+
if (!existsSync3(SUBMISSION_EVIDENCE_DIR)) return { records: [], unreadable: [] };
|
|
9468
|
+
const records = [];
|
|
9469
|
+
const unreadable2 = [];
|
|
9470
|
+
for (const name of readdirSync(SUBMISSION_EVIDENCE_DIR).filter((n) => n.endsWith(".json"))) {
|
|
9471
|
+
const path = join3(SUBMISSION_EVIDENCE_DIR, name);
|
|
9472
|
+
try {
|
|
9473
|
+
records.push(readRecord(path));
|
|
9474
|
+
} catch (error) {
|
|
9475
|
+
const cause = error instanceof DvmError ? error.data?.cause : void 0;
|
|
9476
|
+
unreadable2.push({ path, cause: typeof cause === "string" ? cause : "unreadable" });
|
|
9477
|
+
}
|
|
9478
|
+
}
|
|
9479
|
+
records.sort((a, b) => a.observed_at.localeCompare(b.observed_at));
|
|
9480
|
+
return { records, unreadable: unreadable2 };
|
|
9481
|
+
}
|
|
9482
|
+
function journalMarkerFor(record) {
|
|
9483
|
+
const kind = record.kind;
|
|
9484
|
+
if (kind === "local_job_collision") {
|
|
9485
|
+
throw unreadable(evidencePath(record.ambiguity_id), "not an identity failure");
|
|
9486
|
+
}
|
|
9487
|
+
return {
|
|
9488
|
+
kind,
|
|
9489
|
+
observed_at: record.observed_at,
|
|
9490
|
+
...boundedMarkerIds(record),
|
|
9491
|
+
ambiguity_id: record.ambiguity_id
|
|
9492
|
+
};
|
|
9493
|
+
}
|
|
9494
|
+
function publishOnce(record) {
|
|
9495
|
+
const ambiguityId = record.ambiguity_id;
|
|
9496
|
+
ensureConfigSubdir(SUBMISSION_EVIDENCE_DIR);
|
|
9497
|
+
const target = evidencePath(ambiguityId);
|
|
9498
|
+
const temp = `${target}.${String(process.pid)}.${randomUUID()}.tmp`;
|
|
9499
|
+
const fd = openSync3(temp, "wx", 384);
|
|
9500
|
+
try {
|
|
9501
|
+
writeFileSync2(fd, JSON.stringify(record, null, 2) + "\n");
|
|
9502
|
+
fsyncSync2(fd);
|
|
9503
|
+
} finally {
|
|
9504
|
+
closeSync3(fd);
|
|
9505
|
+
}
|
|
9506
|
+
try {
|
|
9507
|
+
linkSync(temp, target);
|
|
9508
|
+
} catch (error) {
|
|
9509
|
+
if (error.code !== "EEXIST") throw error;
|
|
9510
|
+
} finally {
|
|
9511
|
+
unlinkSync2(temp);
|
|
9512
|
+
}
|
|
9513
|
+
fsyncDirectory2(SUBMISSION_EVIDENCE_DIR);
|
|
9514
|
+
return loadSubmissionEvidence(ambiguityId) ?? record;
|
|
9515
|
+
}
|
|
9516
|
+
function boundedIds(observation) {
|
|
9517
|
+
const header = observedJobId(observation.headerJobId);
|
|
9518
|
+
const body = observedJobId(observation.bodyJobId);
|
|
9519
|
+
const accepted = observedJobId(observation.acceptedJobId);
|
|
9520
|
+
return {
|
|
9521
|
+
...header !== void 0 ? { header_job_id: header } : {},
|
|
9522
|
+
...body !== void 0 ? { body_job_id: body } : {},
|
|
9523
|
+
...accepted !== void 0 ? { accepted_job_id: accepted } : {}
|
|
9524
|
+
};
|
|
9525
|
+
}
|
|
9526
|
+
function boundedMarkerIds(record) {
|
|
9527
|
+
return boundedIds({
|
|
9528
|
+
headerJobId: record.header_job_id,
|
|
9529
|
+
bodyJobId: record.body_job_id,
|
|
9530
|
+
acceptedJobId: record.accepted_job_id
|
|
9531
|
+
});
|
|
9532
|
+
}
|
|
9533
|
+
function evidencePath(ambiguityId) {
|
|
9534
|
+
const name = createHash("sha256").update(ambiguityId).digest("hex");
|
|
9535
|
+
return join3(SUBMISSION_EVIDENCE_DIR, `${name}.json`);
|
|
9536
|
+
}
|
|
9537
|
+
function readRecord(path) {
|
|
9538
|
+
let parsed;
|
|
9539
|
+
try {
|
|
9540
|
+
parsed = JSON.parse(readFileSync4(path, "utf8"));
|
|
9541
|
+
} catch (error) {
|
|
9542
|
+
throw unreadable(path, error instanceof Error ? error.message : String(error));
|
|
9543
|
+
}
|
|
9544
|
+
if (!isEvidenceRecord(parsed)) throw unreadable(path, "invalid shape");
|
|
9545
|
+
return parsed;
|
|
9546
|
+
}
|
|
9547
|
+
function unreadable(path, cause) {
|
|
9548
|
+
return new DvmError(
|
|
9549
|
+
"submission_evidence_unreadable",
|
|
9550
|
+
`A submission evidence record at ${path} is unreadable.`,
|
|
9551
|
+
"Restore it from a backup. Do not pay again for any request it may describe; automatic retries stay off until it reads.",
|
|
9552
|
+
{ cause }
|
|
9553
|
+
);
|
|
9554
|
+
}
|
|
9555
|
+
var KINDS = /* @__PURE__ */ new Set([
|
|
9556
|
+
"identity_mismatch",
|
|
9557
|
+
"body_unreadable",
|
|
9558
|
+
"router_identity_conflict",
|
|
9559
|
+
"local_job_collision"
|
|
9560
|
+
]);
|
|
9561
|
+
var RAILS = /* @__PURE__ */ new Set(["cashu", "x402", "tempo", "credit", "none"]);
|
|
9562
|
+
function isEvidenceRecord(value) {
|
|
9563
|
+
if (!isPlainObject(value)) return false;
|
|
9564
|
+
const record = value;
|
|
9565
|
+
const optionalString = (key) => record[key] === void 0 || typeof record[key] === "string";
|
|
9566
|
+
return record.v === 1 && typeof record.ambiguity_id === "string" && KINDS.has(record.kind) && typeof record.observed_at === "string" && typeof record.endpoint === "string" && RAILS.has(record.rail) && record.claim_stored === false && isOptionalStringRecord(record.unstorable_job_ids) && (record.rail_correlation === void 0 || isPlainObject(record.rail_correlation)) && [
|
|
9567
|
+
"dvm_id",
|
|
9568
|
+
"capability",
|
|
9569
|
+
"request_id",
|
|
9570
|
+
"cashu_request_id",
|
|
9571
|
+
"job_token",
|
|
9572
|
+
"header_job_id",
|
|
9573
|
+
"body_job_id",
|
|
9574
|
+
"accepted_job_id"
|
|
9575
|
+
].every(optionalString);
|
|
9576
|
+
}
|
|
9577
|
+
function isPlainObject(value) {
|
|
9578
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9579
|
+
}
|
|
9580
|
+
function isOptionalStringRecord(value) {
|
|
9581
|
+
return value === void 0 || isPlainObject(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
9582
|
+
}
|
|
9583
|
+
function fsyncDirectory2(path) {
|
|
9584
|
+
let fd;
|
|
9585
|
+
try {
|
|
9586
|
+
fd = openSync3(path, "r");
|
|
9587
|
+
fsyncSync2(fd);
|
|
9588
|
+
} finally {
|
|
9589
|
+
if (fd !== void 0) closeSync3(fd);
|
|
9590
|
+
}
|
|
9591
|
+
}
|
|
9592
|
+
|
|
9593
|
+
// src/lib/job-access.ts
|
|
9594
|
+
function resolveJobAccess(jobId, opts) {
|
|
9595
|
+
const stored = loadJob(jobId);
|
|
9596
|
+
return resolveJobAccessWithRecord(jobId, opts, stored);
|
|
9597
|
+
}
|
|
9598
|
+
function resolveJobAccessWithRecord(jobId, opts, record) {
|
|
9599
|
+
const endpointOverride = opts.endpoint ?? process.env.DVM_JOB_ENDPOINT;
|
|
9600
|
+
const tokenOverride = opts.jobToken ?? process.env.DVM_JOB_TOKEN;
|
|
9601
|
+
const endpointOverridden = endpointOverride !== void 0;
|
|
9602
|
+
const tokenOverridden = tokenOverride !== void 0;
|
|
9603
|
+
const foreign = record !== null && endpointOverride !== void 0 && !sameEndpoint(resolveEndpoint(endpointOverride), record.endpoint);
|
|
9604
|
+
const stored = foreign ? null : record;
|
|
9605
|
+
const rawEndpoint = endpointOverride ?? stored?.endpoint;
|
|
9606
|
+
const jobToken = tokenOverride ?? stored?.jobToken;
|
|
9607
|
+
if (!stored && rawEndpoint === void 0 && jobToken === void 0) {
|
|
9608
|
+
throw new DvmError(
|
|
9609
|
+
"job_access_required",
|
|
9610
|
+
`Job ${jobId} is not in the local store, and no portable job access was supplied.`,
|
|
9611
|
+
"Pass --endpoint <url> and --job-token <hex>, or set DVM_JOB_ENDPOINT and DVM_JOB_TOKEN."
|
|
9612
|
+
);
|
|
9613
|
+
}
|
|
9614
|
+
if (rawEndpoint === void 0) {
|
|
9615
|
+
throw new DvmError(
|
|
9616
|
+
"job_endpoint_required",
|
|
9617
|
+
`No provider endpoint is available for job ${jobId}.`,
|
|
9618
|
+
"Pass --endpoint <url> or set DVM_JOB_ENDPOINT."
|
|
9619
|
+
);
|
|
9620
|
+
}
|
|
9621
|
+
if (foreign && jobToken === void 0) {
|
|
9622
|
+
throw foreignJobTokenRequired(jobId, record.endpoint, resolveEndpoint(endpointOverride));
|
|
9623
|
+
}
|
|
9624
|
+
if (!stored && jobToken === void 0) {
|
|
9625
|
+
throw new DvmError(
|
|
9626
|
+
"job_token_required",
|
|
9627
|
+
`No job token is available for job ${jobId}.`,
|
|
9628
|
+
"Pass --job-token <hex> or set DVM_JOB_TOKEN."
|
|
9629
|
+
);
|
|
9630
|
+
}
|
|
9631
|
+
if (tokenOverridden && !isJobToken(jobToken)) {
|
|
9632
|
+
throw new DvmError(
|
|
9633
|
+
"invalid_job_token",
|
|
9634
|
+
"The supplied job token is not a 64-character hexadecimal value.",
|
|
9635
|
+
"Copy the job_token returned when the job was submitted; the value is never printed by this command."
|
|
9636
|
+
);
|
|
9637
|
+
}
|
|
9638
|
+
return {
|
|
9639
|
+
stored,
|
|
9640
|
+
ref: { endpoint: validateProviderEndpoint(resolveEndpoint(rawEndpoint)) },
|
|
9641
|
+
...jobToken !== void 0 ? { jobToken } : {},
|
|
9642
|
+
overridden: endpointOverridden || tokenOverridden,
|
|
9643
|
+
endpointOverridden
|
|
9644
|
+
};
|
|
9645
|
+
}
|
|
9646
|
+
function resolveStoredJobAccess(jobId, opts) {
|
|
9647
|
+
const stored = loadJob(jobId);
|
|
9648
|
+
if (!stored) {
|
|
9649
|
+
throw new DvmError(
|
|
9650
|
+
"job_payment_state_required",
|
|
9651
|
+
`Cannot pay job ${jobId} without its local payment state.`,
|
|
9652
|
+
"Run 'dvm pay' where the job record and message history are available (normally the submitting machine). An endpoint and job token cannot reconstruct its pending request and spending policy."
|
|
9653
|
+
);
|
|
9654
|
+
}
|
|
9655
|
+
return { ...resolveJobAccessWithRecord(jobId, opts, stored), stored };
|
|
9656
|
+
}
|
|
9657
|
+
async function withJobTokenRedaction(jobToken, action) {
|
|
9658
|
+
try {
|
|
9659
|
+
return await action();
|
|
9660
|
+
} catch (err) {
|
|
9661
|
+
throw redactJobTokenFromError(err, jobToken);
|
|
9662
|
+
}
|
|
9663
|
+
}
|
|
9664
|
+
function redactJobTokenFromError(err, jobToken) {
|
|
9665
|
+
if (!jobToken || !(err instanceof DvmError)) return err;
|
|
9666
|
+
const redact = (value) => value.replaceAll(jobToken, "[REDACTED]");
|
|
9667
|
+
return new DvmError(
|
|
9668
|
+
err.code,
|
|
9669
|
+
redact(err.message),
|
|
9670
|
+
err.hint === void 0 ? void 0 : redact(err.hint),
|
|
9671
|
+
err.data === void 0 ? void 0 : redactRecord(err.data, redact),
|
|
9672
|
+
err.display === void 0 ? void 0 : redact(err.display),
|
|
9673
|
+
err.proseSources
|
|
9674
|
+
);
|
|
9675
|
+
}
|
|
9676
|
+
function sameEndpoint(a, b) {
|
|
9677
|
+
const normalize = (value) => {
|
|
9678
|
+
try {
|
|
9679
|
+
const url = new URL(value);
|
|
9680
|
+
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
9681
|
+
} catch {
|
|
9682
|
+
return value.replace(/\/+$/, "");
|
|
9683
|
+
}
|
|
9684
|
+
};
|
|
9685
|
+
return normalize(a) === normalize(b);
|
|
9686
|
+
}
|
|
9687
|
+
function foreignJobTokenRequired(jobId, localEndpoint, endpoint) {
|
|
9688
|
+
const row = evidenceRowWithToken(jobId, endpoint);
|
|
9689
|
+
return new DvmError(
|
|
9690
|
+
"job_token_required",
|
|
9691
|
+
`Local job ${jobId} belongs to ${localEndpoint}. Its job token was issued there and is not sent to ${endpoint}.`,
|
|
9692
|
+
row ? `The job token for ${jobId} at ${endpoint} is job_token_bearer_secret on evidence row ${row} in 'dvm wallet submissions'. Pass it with --job-token or DVM_JOB_TOKEN.` : `Pass the job token ${endpoint} issued for ${jobId} with --job-token or DVM_JOB_TOKEN. No evidence row in 'dvm wallet submissions' holds one for it.`,
|
|
9693
|
+
{
|
|
9694
|
+
job_id: jobId,
|
|
9695
|
+
local_endpoint: localEndpoint,
|
|
9696
|
+
endpoint,
|
|
9697
|
+
...row ? { ambiguity_id: row } : {}
|
|
9698
|
+
}
|
|
9699
|
+
);
|
|
9700
|
+
}
|
|
9701
|
+
function evidenceRowWithToken(jobId, endpoint) {
|
|
9702
|
+
let records;
|
|
9703
|
+
try {
|
|
9704
|
+
({ records } = listSubmissionEvidence());
|
|
9705
|
+
} catch {
|
|
9706
|
+
return void 0;
|
|
9707
|
+
}
|
|
9708
|
+
return records.filter(
|
|
9709
|
+
(record) => record.job_token !== void 0 && sameEndpoint(record.endpoint, endpoint) && [record.header_job_id, record.body_job_id, record.accepted_job_id].includes(jobId)
|
|
9710
|
+
).at(-1)?.ambiguity_id;
|
|
9711
|
+
}
|
|
9712
|
+
function isJobToken(value) {
|
|
9713
|
+
return value !== void 0 && /^[0-9a-fA-F]{64}$/.test(value);
|
|
9714
|
+
}
|
|
9715
|
+
function validateProviderEndpoint(value) {
|
|
9716
|
+
try {
|
|
9717
|
+
const url = new URL(value);
|
|
9718
|
+
if ((url.protocol === "http:" || url.protocol === "https:") && url.hostname) return value;
|
|
9719
|
+
} catch {
|
|
9720
|
+
}
|
|
9721
|
+
throw new DvmError(
|
|
9722
|
+
"invalid_endpoint",
|
|
9723
|
+
"The supplied job endpoint is not a valid HTTP(S) provider URL.",
|
|
9724
|
+
"Pass a full URL such as https://provider.example, or a favorite alias such as @provider."
|
|
9725
|
+
);
|
|
9726
|
+
}
|
|
9727
|
+
function redactRecord(record, redact) {
|
|
9728
|
+
return Object.fromEntries(
|
|
9729
|
+
Object.entries(record).map(([key, value]) => [key, redactValue(value, redact)])
|
|
9730
|
+
);
|
|
9731
|
+
}
|
|
9732
|
+
function redactValue(value, redact) {
|
|
9733
|
+
if (typeof value === "string") return redact(value);
|
|
9734
|
+
if (Array.isArray(value)) return value.map((entry) => redactValue(entry, redact));
|
|
9735
|
+
if (value && typeof value === "object") {
|
|
9736
|
+
return redactRecord(value, redact);
|
|
9737
|
+
}
|
|
9738
|
+
return value;
|
|
9739
|
+
}
|
|
9740
|
+
|
|
9741
|
+
// src/lib/request-recovery-path.ts
|
|
9742
|
+
function requestRecoveryPath(route, requestId) {
|
|
9743
|
+
return `v1/${route}/${encodeURIComponent(requestId)}`;
|
|
9744
|
+
}
|
|
9745
|
+
|
|
9021
9746
|
// src/lib/wallet-agent/recovery-submissions.ts
|
|
9022
9747
|
var RESUME_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
9023
9748
|
var RESUME_MAX_ATTEMPTS = 5;
|
|
@@ -9030,12 +9755,18 @@ async function sweepPendingSubmissions(opts = {}) {
|
|
|
9030
9755
|
httpPost: opts.httpPost ?? createDefaultHttpPost(opts.fetchImpl ?? dvmFetch),
|
|
9031
9756
|
getWalletForMint: opts.getWalletForMint ?? getWallet,
|
|
9032
9757
|
readMnemonic: opts.readMnemonic ?? readAgentMnemonic,
|
|
9033
|
-
lockPubkey: wallet.lock_pubkey
|
|
9758
|
+
lockPubkey: wallet.lock_pubkey,
|
|
9759
|
+
persistUnresolved: async (entry, observation) => {
|
|
9760
|
+
const marker = journalMarkerFor(recordSubmissionEvidence(evidenceInput(entry, observation)));
|
|
9761
|
+
await markPendingSubmissionUnresolved({ requestId: entry.request_id, marker });
|
|
9762
|
+
return marker;
|
|
9763
|
+
}
|
|
9034
9764
|
};
|
|
9035
9765
|
const now = opts.now ?? (() => Date.now());
|
|
9766
|
+
const { entries, unreadable: unreadable2 } = await reconcileEvidenceMarkers(wallet);
|
|
9036
9767
|
const outcomes = [];
|
|
9037
|
-
for (const entry of
|
|
9038
|
-
outcomes.push(await resolveEntry(entry, deps, now()));
|
|
9768
|
+
for (const entry of entries) {
|
|
9769
|
+
outcomes.push(await resolveEntry(entry, deps, now(), unreadable2.has(entry.request_id)));
|
|
9039
9770
|
}
|
|
9040
9771
|
if (outcomes.some(mutatesWallet)) {
|
|
9041
9772
|
await withWalletLock(() => {
|
|
@@ -9079,6 +9810,19 @@ async function recoverPendingSubmission(opts) {
|
|
|
9079
9810
|
"The saved submission does not match the approved strict request binding.",
|
|
9080
9811
|
"Do not recover by endpoint, mint, or amount. Rebuild evidence for the exact saved request."
|
|
9081
9812
|
);
|
|
9813
|
+
const evidence = entry.accepted_unresolved ? null : loadSubmissionEvidence(entry.request_id);
|
|
9814
|
+
if (evidence)
|
|
9815
|
+
saveAgentWallet(withAcceptedUnresolved(wallet, entry.request_id, journalMarkerFor(evidence)));
|
|
9816
|
+
if (entry.accepted_unresolved || evidence)
|
|
9817
|
+
throw new DvmError(
|
|
9818
|
+
"submission_accepted_unresolved",
|
|
9819
|
+
"The provider already accepted this submission without stating a settled job identity.",
|
|
9820
|
+
"Do not pay for or resubmit this request. Run 'dvm wallet submissions' to see the recorded evidence and how to read the job.",
|
|
9821
|
+
{
|
|
9822
|
+
request_id: entry.request_id,
|
|
9823
|
+
ambiguity_id: entry.accepted_unresolved?.ambiguity_id ?? entry.request_id
|
|
9824
|
+
}
|
|
9825
|
+
);
|
|
9082
9826
|
if (entry.output_proofs.length === 0 || entry.swapping)
|
|
9083
9827
|
throw new DvmError(
|
|
9084
9828
|
"submission_not_ready",
|
|
@@ -9105,8 +9849,25 @@ async function recoverPendingSubmission(opts) {
|
|
|
9105
9849
|
});
|
|
9106
9850
|
const outcome = await shipEntry(
|
|
9107
9851
|
attempted,
|
|
9108
|
-
opts.httpPost ?? createDefaultHttpPost(opts.fetchImpl ?? dvmFetch)
|
|
9852
|
+
opts.httpPost ?? createDefaultHttpPost(opts.fetchImpl ?? dvmFetch),
|
|
9853
|
+
// This function already holds the wallet lock, which is not reentrant.
|
|
9854
|
+
async (target, observation) => {
|
|
9855
|
+
const marker = journalMarkerFor(
|
|
9856
|
+
recordSubmissionEvidence(evidenceInput(target, observation))
|
|
9857
|
+
);
|
|
9858
|
+
const current = loadAgentWallet() ?? wallet;
|
|
9859
|
+
saveAgentWallet(withAcceptedUnresolved(current, target.request_id, marker));
|
|
9860
|
+
return marker;
|
|
9861
|
+
}
|
|
9109
9862
|
);
|
|
9863
|
+
if (outcome.kind === "accepted_unresolved") {
|
|
9864
|
+
const observation = outcome.observation ?? { kind: outcome.marker.kind };
|
|
9865
|
+
throw withIdentityRecovery(identityError(observation), {
|
|
9866
|
+
ambiguityId: outcome.marker.ambiguity_id,
|
|
9867
|
+
cashuRequestId: entry.request_id,
|
|
9868
|
+
...publicRequestIdField(entry)
|
|
9869
|
+
});
|
|
9870
|
+
}
|
|
9110
9871
|
if (outcome.kind === "shipped" || outcome.kind === "already_accepted") {
|
|
9111
9872
|
const current = loadAgentWallet() ?? wallet;
|
|
9112
9873
|
saveAgentWallet(applyOutcome(current, outcome, now));
|
|
@@ -9120,6 +9881,25 @@ async function recoverPendingSubmission(opts) {
|
|
|
9120
9881
|
return { requestId: opts.requestId, outcome: "pending", jobId: null, attemptCount: 1 };
|
|
9121
9882
|
});
|
|
9122
9883
|
}
|
|
9884
|
+
async function bookRecoveredSubmissions(args) {
|
|
9885
|
+
const matches = (wallet) => (wallet?.pending_submissions ?? []).filter(
|
|
9886
|
+
(entry) => entry.output_proofs.length > 0 && publicRequestIdOf(entry) === args.publicRequestId && sameEndpoint(entry.endpoint, args.endpoint)
|
|
9887
|
+
);
|
|
9888
|
+
if (matches(loadAgentWallet()).length === 0) return [];
|
|
9889
|
+
const now = args.now ?? (() => Date.now());
|
|
9890
|
+
return withWalletLock(() => {
|
|
9891
|
+
const fresh = loadAgentWallet();
|
|
9892
|
+
const booked = matches(fresh);
|
|
9893
|
+
if (!fresh || booked.length === 0) return [];
|
|
9894
|
+
saveAgentWallet(
|
|
9895
|
+
booked.reduce(
|
|
9896
|
+
(acc, entry) => applyOutcome(acc, { kind: "shipped", entry, jobId: args.jobId }, now),
|
|
9897
|
+
fresh
|
|
9898
|
+
)
|
|
9899
|
+
);
|
|
9900
|
+
return booked.map((entry) => entry.request_id);
|
|
9901
|
+
});
|
|
9902
|
+
}
|
|
9123
9903
|
function isResumable(entry) {
|
|
9124
9904
|
return resumeBody(entry) !== null;
|
|
9125
9905
|
}
|
|
@@ -9128,7 +9908,7 @@ function reclaimAtMs(entry) {
|
|
|
9128
9908
|
if (!entry.canonical_id || typeof entry.t_expire !== "number") return null;
|
|
9129
9909
|
return entry.t_expire;
|
|
9130
9910
|
}
|
|
9131
|
-
async function resolveEntry(entry, deps, nowMs) {
|
|
9911
|
+
async function resolveEntry(entry, deps, nowMs, evidenceUnreadable) {
|
|
9132
9912
|
if (entry.output_proofs.length === 0) {
|
|
9133
9913
|
const inFlightWindowMs = inFlightTimeoutSeconds() * 1e3;
|
|
9134
9914
|
if (entry.swapping) {
|
|
@@ -9140,6 +9920,15 @@ async function resolveEntry(entry, deps, nowMs) {
|
|
|
9140
9920
|
if (reclaimAt !== null && nowMs >= reclaimAt) {
|
|
9141
9921
|
return reclaimEntry(entry, deps);
|
|
9142
9922
|
}
|
|
9923
|
+
if (entry.accepted_unresolved) {
|
|
9924
|
+
return {
|
|
9925
|
+
kind: "accepted_unresolved",
|
|
9926
|
+
entry,
|
|
9927
|
+
marker: entry.accepted_unresolved,
|
|
9928
|
+
evidence: evidenceState(entry.accepted_unresolved.ambiguity_id)
|
|
9929
|
+
};
|
|
9930
|
+
}
|
|
9931
|
+
if (evidenceUnreadable) return { kind: "evidence_unreadable", entry };
|
|
9143
9932
|
if (!isResumable(entry)) {
|
|
9144
9933
|
return { kind: "unresumable", entry };
|
|
9145
9934
|
}
|
|
@@ -9149,7 +9938,7 @@ async function resolveEntry(entry, deps, nowMs) {
|
|
|
9149
9938
|
if ((entry.attempts ?? 0) >= RESUME_MAX_ATTEMPTS) {
|
|
9150
9939
|
return { kind: "stale", entry, reason: `no response after ${RESUME_MAX_ATTEMPTS} attempts` };
|
|
9151
9940
|
}
|
|
9152
|
-
return shipEntry(entry, deps.httpPost);
|
|
9941
|
+
return shipEntry(entry, deps.httpPost, deps.persistUnresolved);
|
|
9153
9942
|
}
|
|
9154
9943
|
async function recoverPreparedSwap(entry, deps) {
|
|
9155
9944
|
const swapping = entry.swapping;
|
|
@@ -9372,7 +10161,14 @@ function isNonNegativeSafeInteger(value) {
|
|
|
9372
10161
|
}
|
|
9373
10162
|
var UUID_V4_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
9374
10163
|
var SHA256_RE = /^[a-f0-9]{64}$/;
|
|
9375
|
-
async function shipEntry(entry, httpPost) {
|
|
10164
|
+
async function shipEntry(entry, httpPost, persistUnresolved) {
|
|
10165
|
+
const unresolved = async (observation) => ({
|
|
10166
|
+
kind: "accepted_unresolved",
|
|
10167
|
+
entry,
|
|
10168
|
+
marker: await persistUnresolved(entry, observation),
|
|
10169
|
+
evidence: "recorded",
|
|
10170
|
+
observation
|
|
10171
|
+
});
|
|
9376
10172
|
const token = { mint: entry.mint, proofs: toCashuProofs(entry.output_proofs) };
|
|
9377
10173
|
const cashuToken = entry.cashu_token ?? ki(token);
|
|
9378
10174
|
const headers = {
|
|
@@ -9381,6 +10177,11 @@ async function shipEntry(entry, httpPost) {
|
|
|
9381
10177
|
"X-Cashu-Request-Id": entry.request_id
|
|
9382
10178
|
};
|
|
9383
10179
|
const route = entry.context?.route === "credit" ? "/v1/credit" : "/v1/job";
|
|
10180
|
+
const { publicRequestId } = publicRequestIdField(entry);
|
|
10181
|
+
if (publicRequestId && route === "/v1/job") {
|
|
10182
|
+
const readBack = await readBackByRequestId(entry, publicRequestId, httpPost, unresolved);
|
|
10183
|
+
if (readBack) return readBack;
|
|
10184
|
+
}
|
|
9384
10185
|
let active2 = entry;
|
|
9385
10186
|
let correctedOnce = false;
|
|
9386
10187
|
for (; ; ) {
|
|
@@ -9405,12 +10206,28 @@ async function shipEntry(entry, httpPost) {
|
|
|
9405
10206
|
applyResumedCreditFund(entry, response.body);
|
|
9406
10207
|
return { kind: "shipped", entry };
|
|
9407
10208
|
}
|
|
9408
|
-
const
|
|
9409
|
-
if (
|
|
9410
|
-
|
|
10209
|
+
const identity = settleJobIdentity(response.jobIdentity ?? null, response.body);
|
|
10210
|
+
if (identity.kind === "unresolved") return unresolved(identity.observation);
|
|
10211
|
+
if (entry.context) {
|
|
10212
|
+
saveJob(
|
|
10213
|
+
jobRecordFromEntry(
|
|
10214
|
+
entry,
|
|
10215
|
+
identity.jobId,
|
|
10216
|
+
response.body,
|
|
10217
|
+
identity.claimAllowed ? response.feedbackClaim : void 0
|
|
10218
|
+
)
|
|
10219
|
+
);
|
|
9411
10220
|
}
|
|
9412
10221
|
await reconcileResumedJobCredit(active2, response.body, httpPost);
|
|
9413
|
-
return { kind: "shipped", entry, jobId };
|
|
10222
|
+
return { kind: "shipped", entry, jobId: identity.jobId };
|
|
10223
|
+
}
|
|
10224
|
+
const conflict = routerConflictObservation(response.status, response.body);
|
|
10225
|
+
if (conflict) return unresolved(conflict);
|
|
10226
|
+
if (response.status === 409) {
|
|
10227
|
+
if (!errorCodeOf(response.body)) return unresolved({ kind: "body_unreadable" });
|
|
10228
|
+
if (publicRequestId) {
|
|
10229
|
+
return { kind: "still_pending", entry, reason: errorCodeOf(response.body) ?? "http 409" };
|
|
10230
|
+
}
|
|
9414
10231
|
}
|
|
9415
10232
|
if (response.status === 409 || response.body?.error === "replay_rejected") {
|
|
9416
10233
|
await reconcileResumedJobCredit(active2, response.body, httpPost);
|
|
@@ -9443,6 +10260,94 @@ async function shipEntry(entry, httpPost) {
|
|
|
9443
10260
|
};
|
|
9444
10261
|
}
|
|
9445
10262
|
}
|
|
10263
|
+
async function readBackByRequestId(entry, requestId, httpPost, unresolved) {
|
|
10264
|
+
const body = requestResultBody(entry, requestId);
|
|
10265
|
+
if (!body) return null;
|
|
10266
|
+
let response;
|
|
10267
|
+
try {
|
|
10268
|
+
response = await httpPost({
|
|
10269
|
+
url: `${entry.endpoint}/${requestRecoveryPath("request-result", requestId)}`,
|
|
10270
|
+
headers: { "Content-Type": "application/json" },
|
|
10271
|
+
body: JSON.stringify(body)
|
|
10272
|
+
});
|
|
10273
|
+
} catch (err) {
|
|
10274
|
+
return { kind: "still_pending", entry, reason: `network error: ${errorText(err)}` };
|
|
10275
|
+
}
|
|
10276
|
+
if (response.status === 404 && errorCodeOf(response.body) === "request_not_found") return null;
|
|
10277
|
+
if (response.status >= 200 && response.status < 300) {
|
|
10278
|
+
if (response.body && response.body.request_id !== requestId) {
|
|
10279
|
+
return unresolved({ kind: "body_unreadable" });
|
|
10280
|
+
}
|
|
10281
|
+
const identity = settleJobIdentity(response.jobIdentity ?? null, response.body);
|
|
10282
|
+
if (identity.kind === "unresolved") return unresolved(identity.observation);
|
|
10283
|
+
const saved = saveRecoveredJob(entry, identity.jobId, response.body, requestId);
|
|
10284
|
+
if (saved !== "saved") {
|
|
10285
|
+
const kept = saved === "foreign_endpoint" ? recordLocalJobCollision({
|
|
10286
|
+
...entryEvidenceContext(entry),
|
|
10287
|
+
publicRequestId: requestId,
|
|
10288
|
+
jobId: identity.jobId,
|
|
10289
|
+
jobToken: response.body?.job_token
|
|
10290
|
+
}) : null;
|
|
10291
|
+
return {
|
|
10292
|
+
kind: "still_pending",
|
|
10293
|
+
entry,
|
|
10294
|
+
reason: `request_result_conflict: job ${identity.jobId} is already a different local job${kept ? `; the recovered job is kept as evidence ${kept.ambiguity_id}` : ""}`
|
|
10295
|
+
};
|
|
10296
|
+
}
|
|
10297
|
+
await reconcileResumedJobCredit(entry, response.body, httpPost);
|
|
10298
|
+
return { kind: "shipped", entry, jobId: identity.jobId };
|
|
10299
|
+
}
|
|
10300
|
+
const conflict = routerConflictObservation(response.status, response.body);
|
|
10301
|
+
if (conflict) return unresolved(conflict);
|
|
10302
|
+
return {
|
|
10303
|
+
kind: "still_pending",
|
|
10304
|
+
entry,
|
|
10305
|
+
reason: `request-result: ${errorCodeOf(response.body) ?? `http ${response.status}`}`
|
|
10306
|
+
};
|
|
10307
|
+
}
|
|
10308
|
+
function requestResultBody(entry, requestId) {
|
|
10309
|
+
const ctx = entry.context;
|
|
10310
|
+
if (!ctx || ctx.route === "credit" || !ctx.signing_pubkey || !ctx.auth_domain) return null;
|
|
10311
|
+
const signer = findSigningIdentityByPubkey(ctx.signing_pubkey);
|
|
10312
|
+
if (!signer) return null;
|
|
10313
|
+
const unsigned = ctx.submit_body.data ?? {};
|
|
10314
|
+
const path = canonicalRequestPath(
|
|
10315
|
+
new URL(
|
|
10316
|
+
requestRecoveryPath("request-result", requestId),
|
|
10317
|
+
`${entry.endpoint.replace(/\/$/, "")}/`
|
|
10318
|
+
).href
|
|
10319
|
+
);
|
|
10320
|
+
return {
|
|
10321
|
+
...ctx.submit_body,
|
|
10322
|
+
data: signDvmRequestData(signer.privkey, unsigned, { ...ctx.auth_domain, path })
|
|
10323
|
+
};
|
|
10324
|
+
}
|
|
10325
|
+
function saveRecoveredJob(entry, jobId, body, requestId) {
|
|
10326
|
+
const token = body?.job_token;
|
|
10327
|
+
const jobToken = isOpaqueJobToken(token) ? token : void 0;
|
|
10328
|
+
const existing = loadJob(jobId);
|
|
10329
|
+
if (existing) {
|
|
10330
|
+
if (!sameEndpoint(existing.endpoint, entry.endpoint)) return "foreign_endpoint";
|
|
10331
|
+
if (existing.requestId !== void 0 && existing.requestId !== requestId) return "other_request";
|
|
10332
|
+
updateJob(jobId, {
|
|
10333
|
+
requestId,
|
|
10334
|
+
...jobToken && !existing.jobToken ? { jobToken } : {}
|
|
10335
|
+
});
|
|
10336
|
+
return "saved";
|
|
10337
|
+
}
|
|
10338
|
+
const { jobToken: _unchecked, ...record } = jobRecordFromEntry(entry, jobId, body, void 0);
|
|
10339
|
+
saveJob({ ...record, requestId, ...jobToken ? { jobToken } : {} });
|
|
10340
|
+
return "saved";
|
|
10341
|
+
}
|
|
10342
|
+
function errorCodeOf(body) {
|
|
10343
|
+
const error = body?.error;
|
|
10344
|
+
if (typeof error === "string") return error;
|
|
10345
|
+
if (error && typeof error === "object" && !Array.isArray(error)) {
|
|
10346
|
+
const code = error.code;
|
|
10347
|
+
if (typeof code === "string") return code;
|
|
10348
|
+
}
|
|
10349
|
+
return null;
|
|
10350
|
+
}
|
|
9446
10351
|
async function correctFundAmount(entry, body) {
|
|
9447
10352
|
const ctx = entry.context;
|
|
9448
10353
|
if (!ctx || ctx.route === "credit") return { kind: "permanent" };
|
|
@@ -9602,9 +10507,11 @@ function isCreditWire(value) {
|
|
|
9602
10507
|
}
|
|
9603
10508
|
function jobRecordFromEntry(entry, jobId, body, feedbackClaim) {
|
|
9604
10509
|
const ctx = entry.context;
|
|
10510
|
+
const { publicRequestId } = publicRequestIdField(entry);
|
|
9605
10511
|
return {
|
|
9606
10512
|
id: jobId,
|
|
9607
10513
|
endpoint: entry.endpoint,
|
|
10514
|
+
...publicRequestId ? { requestId: publicRequestId } : {},
|
|
9608
10515
|
...ctx?.dvm_id ? { dvmId: ctx.dvm_id } : {},
|
|
9609
10516
|
...feedbackClaim ? { feedbackClaim } : {},
|
|
9610
10517
|
...ctx?.capability ? { capability: ctx.capability } : {},
|
|
@@ -9754,16 +10661,76 @@ function createDefaultHttpPost(fetchImpl) {
|
|
|
9754
10661
|
"Retry once the DVM is reachable again."
|
|
9755
10662
|
);
|
|
9756
10663
|
}
|
|
10664
|
+
const jobIdentity = jobIdentityHeaderValue(res.headers);
|
|
9757
10665
|
let body;
|
|
9758
10666
|
try {
|
|
9759
|
-
|
|
10667
|
+
const parsed = await res.json();
|
|
10668
|
+
body = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
9760
10669
|
} catch {
|
|
9761
10670
|
body = null;
|
|
9762
10671
|
}
|
|
9763
10672
|
const feedbackClaim = res.headers.get(ROUTER_FEEDBACK_CLAIM_HEADER) ?? void 0;
|
|
9764
|
-
return {
|
|
10673
|
+
return {
|
|
10674
|
+
status: res.status,
|
|
10675
|
+
body,
|
|
10676
|
+
jobIdentity,
|
|
10677
|
+
...feedbackClaim ? { feedbackClaim } : {}
|
|
10678
|
+
};
|
|
10679
|
+
};
|
|
10680
|
+
}
|
|
10681
|
+
async function reconcileEvidenceMarkers(wallet) {
|
|
10682
|
+
const unreadable2 = /* @__PURE__ */ new Set();
|
|
10683
|
+
const orphaned = wallet.pending_submissions.flatMap((entry) => {
|
|
10684
|
+
if (entry.accepted_unresolved) return [];
|
|
10685
|
+
try {
|
|
10686
|
+
const record = loadSubmissionEvidence(entry.request_id);
|
|
10687
|
+
return record ? [{ requestId: entry.request_id, marker: journalMarkerFor(record) }] : [];
|
|
10688
|
+
} catch {
|
|
10689
|
+
unreadable2.add(entry.request_id);
|
|
10690
|
+
return [];
|
|
10691
|
+
}
|
|
10692
|
+
});
|
|
10693
|
+
if (orphaned.length === 0) return { entries: wallet.pending_submissions, unreadable: unreadable2 };
|
|
10694
|
+
return withWalletLock(() => {
|
|
10695
|
+
const fresh = loadAgentWallet() ?? wallet;
|
|
10696
|
+
const next = orphaned.reduce(
|
|
10697
|
+
(acc, { requestId, marker }) => withAcceptedUnresolved(acc, requestId, marker),
|
|
10698
|
+
fresh
|
|
10699
|
+
);
|
|
10700
|
+
saveAgentWallet(next);
|
|
10701
|
+
return { entries: next.pending_submissions, unreadable: unreadable2 };
|
|
10702
|
+
});
|
|
10703
|
+
}
|
|
10704
|
+
function evidenceState(ambiguityId) {
|
|
10705
|
+
try {
|
|
10706
|
+
return loadSubmissionEvidence(ambiguityId) ? "recorded" : "missing";
|
|
10707
|
+
} catch {
|
|
10708
|
+
return "unreadable";
|
|
10709
|
+
}
|
|
10710
|
+
}
|
|
10711
|
+
function evidenceInput(entry, observation) {
|
|
10712
|
+
return { ...entryEvidenceContext(entry), observation, ...publicRequestIdField(entry) };
|
|
10713
|
+
}
|
|
10714
|
+
function entryEvidenceContext(entry) {
|
|
10715
|
+
const ctx = entry.context;
|
|
10716
|
+
return {
|
|
10717
|
+
endpoint: entry.endpoint,
|
|
10718
|
+
...ctx?.dvm_id ? { dvmId: ctx.dvm_id } : {},
|
|
10719
|
+
...ctx?.capability ? { capability: ctx.capability } : {},
|
|
10720
|
+
cashuRequestId: entry.request_id,
|
|
10721
|
+
rail: "cashu",
|
|
10722
|
+
railCorrelation: { mint: entry.mint, amount_sats: entry.amount_sats }
|
|
9765
10723
|
};
|
|
9766
10724
|
}
|
|
10725
|
+
function publicRequestIdOf(entry) {
|
|
10726
|
+
const data = entry.context?.submit_body.data;
|
|
10727
|
+
const requestId = data && typeof data === "object" && !Array.isArray(data) ? data.request_id : void 0;
|
|
10728
|
+
return isPublicRequestId(requestId) ? requestId : void 0;
|
|
10729
|
+
}
|
|
10730
|
+
function publicRequestIdField(entry) {
|
|
10731
|
+
const publicRequestId = publicRequestIdOf(entry);
|
|
10732
|
+
return publicRequestId ? { publicRequestId } : {};
|
|
10733
|
+
}
|
|
9767
10734
|
|
|
9768
10735
|
// src/lib/agent-wallet-retry.ts
|
|
9769
10736
|
var TRANSIENT_PAYMENT_BACKOFF_MS = [250, 500, 1e3, 2e3, 4e3];
|
|
@@ -10005,8 +10972,8 @@ async function handlePaymentRequest(jobId, request2, policy, transport, provider
|
|
|
10005
10972
|
}
|
|
10006
10973
|
}
|
|
10007
10974
|
if ((opts?.rail === void 0 || opts.rail === "x402") && request2.x402) {
|
|
10008
|
-
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-
|
|
10009
|
-
const { tryX402Payment: tryX402Payment2 } = await import("./client-
|
|
10975
|
+
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-RB2RPWIN.js");
|
|
10976
|
+
const { tryX402Payment: tryX402Payment2 } = await import("./client-PGOH2ION.js");
|
|
10010
10977
|
const wallet = loadX402Wallet2();
|
|
10011
10978
|
if (wallet) {
|
|
10012
10979
|
let proof;
|
|
@@ -10547,179 +11514,6 @@ async function runDiscoveryLifecycle(options) {
|
|
|
10547
11514
|
return { ...summary ? { summary } : {}, messages: messages2, nextAction: result.nextAction };
|
|
10548
11515
|
}
|
|
10549
11516
|
|
|
10550
|
-
// src/lib/favorites.ts
|
|
10551
|
-
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
10552
|
-
import {
|
|
10553
|
-
closeSync as closeSync2,
|
|
10554
|
-
fchmodSync,
|
|
10555
|
-
fsyncSync,
|
|
10556
|
-
openSync as openSync2,
|
|
10557
|
-
readFileSync as readFileSync3,
|
|
10558
|
-
renameSync,
|
|
10559
|
-
statSync as statSync2,
|
|
10560
|
-
unlinkSync,
|
|
10561
|
-
writeFileSync
|
|
10562
|
-
} from "fs";
|
|
10563
|
-
import { dirname as dirname2 } from "path";
|
|
10564
|
-
var DEFAULT_FILE_MODE = 384;
|
|
10565
|
-
function loadFavorites() {
|
|
10566
|
-
let raw2;
|
|
10567
|
-
try {
|
|
10568
|
-
raw2 = readFileSync3(FAVORITES_FILE, "utf8");
|
|
10569
|
-
} catch (error) {
|
|
10570
|
-
if (nodeErrorCode(error) === "ENOENT") return {};
|
|
10571
|
-
throw unreadableFavorites(error);
|
|
10572
|
-
}
|
|
10573
|
-
try {
|
|
10574
|
-
const parsed = JSON.parse(raw2);
|
|
10575
|
-
if (!isFavoritesMap(parsed)) throw new Error("invalid favorites shape");
|
|
10576
|
-
return parsed;
|
|
10577
|
-
} catch (error) {
|
|
10578
|
-
throw unreadableFavorites(error);
|
|
10579
|
-
}
|
|
10580
|
-
}
|
|
10581
|
-
async function saveFavorite(alias, fav) {
|
|
10582
|
-
return withFavoritesLock(() => {
|
|
10583
|
-
const favs = loadFavorites();
|
|
10584
|
-
const existed = Object.hasOwn(favs, alias);
|
|
10585
|
-
favs[alias] = fav;
|
|
10586
|
-
writeFavorites(favs);
|
|
10587
|
-
return existed;
|
|
10588
|
-
});
|
|
10589
|
-
}
|
|
10590
|
-
async function removeFavorite(alias) {
|
|
10591
|
-
return withFavoritesLock(() => {
|
|
10592
|
-
const favs = loadFavorites();
|
|
10593
|
-
if (!Object.hasOwn(favs, alias)) return false;
|
|
10594
|
-
const { [alias]: _, ...rest } = favs;
|
|
10595
|
-
writeFavorites(rest);
|
|
10596
|
-
return true;
|
|
10597
|
-
});
|
|
10598
|
-
}
|
|
10599
|
-
function resolveEndpoint(input) {
|
|
10600
|
-
if (!input.startsWith("@")) return input;
|
|
10601
|
-
const alias = input.slice(1);
|
|
10602
|
-
const favs = loadFavorites();
|
|
10603
|
-
const fav = Object.hasOwn(favs, alias) ? favs[alias] : void 0;
|
|
10604
|
-
if (!fav) {
|
|
10605
|
-
throw new DvmError(
|
|
10606
|
-
"unknown_favorite",
|
|
10607
|
-
`No favorite named "${alias}".`,
|
|
10608
|
-
"Run 'dvm fav list' to see saved favorites, or 'dvm fav add <endpoint>' to save one."
|
|
10609
|
-
);
|
|
10610
|
-
}
|
|
10611
|
-
return fav.endpoint;
|
|
10612
|
-
}
|
|
10613
|
-
function deriveAlias(endpoint) {
|
|
10614
|
-
try {
|
|
10615
|
-
const hostname2 = new URL(endpoint).hostname;
|
|
10616
|
-
if (hostname2.endsWith(".dvmkit.ai")) {
|
|
10617
|
-
const prefix = hostname2.replace(".dvmkit.ai", "");
|
|
10618
|
-
const dashIdx = prefix.indexOf("--");
|
|
10619
|
-
if (dashIdx !== -1) return prefix.slice(dashIdx + 2);
|
|
10620
|
-
return prefix;
|
|
10621
|
-
}
|
|
10622
|
-
return hostname2.replace(/\.[^.]+$/, "").replace(/\./g, "-");
|
|
10623
|
-
} catch {
|
|
10624
|
-
return endpoint.replace(/[^a-z0-9-]/gi, "-").toLowerCase();
|
|
10625
|
-
}
|
|
10626
|
-
}
|
|
10627
|
-
async function withFavoritesLock(fn) {
|
|
10628
|
-
ensureConfigDir();
|
|
10629
|
-
let release;
|
|
10630
|
-
try {
|
|
10631
|
-
release = await import_proper_lockfile.default.lock(FAVORITES_FILE, {
|
|
10632
|
-
lockfilePath: `${FAVORITES_FILE}.lock`,
|
|
10633
|
-
realpath: false,
|
|
10634
|
-
stale: 3e4,
|
|
10635
|
-
retries: { retries: 10, factor: 1, minTimeout: 100, maxTimeout: 100 }
|
|
10636
|
-
});
|
|
10637
|
-
} catch {
|
|
10638
|
-
throw new DvmError(
|
|
10639
|
-
"favorites_locked",
|
|
10640
|
-
"Another dvm process is updating saved favorites.",
|
|
10641
|
-
"Wait a moment and retry."
|
|
10642
|
-
);
|
|
10643
|
-
}
|
|
10644
|
-
try {
|
|
10645
|
-
return await fn();
|
|
10646
|
-
} finally {
|
|
10647
|
-
await release().catch(() => void 0);
|
|
10648
|
-
}
|
|
10649
|
-
}
|
|
10650
|
-
function writeFavorites(favorites) {
|
|
10651
|
-
const mode = favoritesFileMode();
|
|
10652
|
-
const temporary = `${FAVORITES_FILE}.${String(process.pid)}.${randomSuffix()}.tmp`;
|
|
10653
|
-
const contents = JSON.stringify(favorites, null, 2) + "\n";
|
|
10654
|
-
let fd;
|
|
10655
|
-
try {
|
|
10656
|
-
fd = openSync2(temporary, "wx", mode);
|
|
10657
|
-
fchmodSync(fd, mode);
|
|
10658
|
-
writeFileSync(fd, contents);
|
|
10659
|
-
fsyncSync(fd);
|
|
10660
|
-
closeSync2(fd);
|
|
10661
|
-
fd = void 0;
|
|
10662
|
-
renameSync(temporary, FAVORITES_FILE);
|
|
10663
|
-
fsyncDirectory(dirname2(FAVORITES_FILE));
|
|
10664
|
-
} catch (error) {
|
|
10665
|
-
if (fd !== void 0) {
|
|
10666
|
-
try {
|
|
10667
|
-
closeSync2(fd);
|
|
10668
|
-
} catch {
|
|
10669
|
-
}
|
|
10670
|
-
}
|
|
10671
|
-
try {
|
|
10672
|
-
unlinkSync(temporary);
|
|
10673
|
-
} catch {
|
|
10674
|
-
}
|
|
10675
|
-
throw error;
|
|
10676
|
-
}
|
|
10677
|
-
}
|
|
10678
|
-
function favoritesFileMode() {
|
|
10679
|
-
try {
|
|
10680
|
-
return statSync2(FAVORITES_FILE).mode & 511;
|
|
10681
|
-
} catch (error) {
|
|
10682
|
-
if (nodeErrorCode(error) === "ENOENT") return DEFAULT_FILE_MODE;
|
|
10683
|
-
throw error;
|
|
10684
|
-
}
|
|
10685
|
-
}
|
|
10686
|
-
function fsyncDirectory(path) {
|
|
10687
|
-
const fd = openSync2(path, "r");
|
|
10688
|
-
try {
|
|
10689
|
-
fsyncSync(fd);
|
|
10690
|
-
} finally {
|
|
10691
|
-
closeSync2(fd);
|
|
10692
|
-
}
|
|
10693
|
-
}
|
|
10694
|
-
function randomSuffix() {
|
|
10695
|
-
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
10696
|
-
}
|
|
10697
|
-
function unreadableFavorites(error) {
|
|
10698
|
-
return new DvmError(
|
|
10699
|
-
"favorites_unreadable",
|
|
10700
|
-
"Saved favorites are corrupt or unreadable.",
|
|
10701
|
-
`The original file at ${FAVORITES_FILE} was left unchanged. Restore it from a backup, or move it aside before rebuilding favorites.`,
|
|
10702
|
-
{
|
|
10703
|
-
path: FAVORITES_FILE,
|
|
10704
|
-
...nodeErrorCode(error) ? { error_code: nodeErrorCode(error) } : {}
|
|
10705
|
-
}
|
|
10706
|
-
);
|
|
10707
|
-
}
|
|
10708
|
-
function nodeErrorCode(error) {
|
|
10709
|
-
if (!(error instanceof Error) || !("code" in error)) return void 0;
|
|
10710
|
-
const code = error.code;
|
|
10711
|
-
return typeof code === "string" && /^E[A-Z0-9_]{1,63}$/.test(code) ? code : void 0;
|
|
10712
|
-
}
|
|
10713
|
-
function isFavoritesMap(value) {
|
|
10714
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
10715
|
-
return Object.values(value).every(isFavorite);
|
|
10716
|
-
}
|
|
10717
|
-
function isFavorite(value) {
|
|
10718
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
10719
|
-
const candidate = value;
|
|
10720
|
-
return typeof candidate.endpoint === "string" && typeof candidate.addedAt === "number" && Number.isFinite(candidate.addedAt) && (candidate.name === void 0 || typeof candidate.name === "string");
|
|
10721
|
-
}
|
|
10722
|
-
|
|
10723
11517
|
// src/lib/discovery-options.ts
|
|
10724
11518
|
var MAX_TIMER_MS = 2147483647;
|
|
10725
11519
|
var DECIMAL = /^(?:\d+(?:\.\d*)?|\.\d+)$/;
|
|
@@ -11055,20 +11849,59 @@ var HttpsTransport = class {
|
|
|
11055
11849
|
throw withCreditErrorContext(buildPaymentError(errorBody), errorBody);
|
|
11056
11850
|
}
|
|
11057
11851
|
if (!res.ok && res.status !== 202) {
|
|
11058
|
-
|
|
11059
|
-
|
|
11852
|
+
let text;
|
|
11853
|
+
try {
|
|
11854
|
+
text = await res.text();
|
|
11855
|
+
} catch {
|
|
11856
|
+
text = null;
|
|
11857
|
+
}
|
|
11858
|
+
const structured = text === null ? null : parseStructuredError(text);
|
|
11859
|
+
if (res.status === 409 && payment !== void 0 && structured === null) {
|
|
11860
|
+
throw identityError({
|
|
11861
|
+
kind: "body_unreadable",
|
|
11862
|
+
...tempoTransactionHash ? { transactionHash: tempoTransactionHash } : {}
|
|
11863
|
+
});
|
|
11864
|
+
}
|
|
11865
|
+
if (text === null) {
|
|
11866
|
+
throw providerResponseError(
|
|
11867
|
+
"provider_error",
|
|
11868
|
+
`Job submission failed (${res.status}); the response body could not be read.`
|
|
11869
|
+
);
|
|
11870
|
+
}
|
|
11871
|
+
const conflict = routerConflictObservation(res.status, parseJsonObject(text));
|
|
11872
|
+
if (conflict) {
|
|
11873
|
+
throw identityError(
|
|
11874
|
+
{ ...conflict, ...tempoTransactionHash ? { transactionHash: tempoTransactionHash } : {} },
|
|
11875
|
+
structured ? routerProse(structured) : void 0
|
|
11876
|
+
);
|
|
11877
|
+
}
|
|
11060
11878
|
if (structured) throw structured;
|
|
11061
11879
|
throw providerResponseError(
|
|
11062
11880
|
"provider_error",
|
|
11063
11881
|
`Job submission failed (${res.status}): ${text}`
|
|
11064
11882
|
);
|
|
11065
11883
|
}
|
|
11066
|
-
const
|
|
11067
|
-
|
|
11884
|
+
const identityHeader = jobIdentityHeaderValue(res.headers);
|
|
11885
|
+
let parsedBody;
|
|
11886
|
+
try {
|
|
11887
|
+
parsedBody = parseJsonObject(await res.text());
|
|
11888
|
+
} catch {
|
|
11889
|
+
parsedBody = null;
|
|
11890
|
+
}
|
|
11891
|
+
const identity = settleJobIdentity(identityHeader, parsedBody);
|
|
11892
|
+
if (identity.kind === "unresolved") {
|
|
11893
|
+
throw identityError({
|
|
11894
|
+
...identity.observation,
|
|
11895
|
+
...tempoTransactionHash ? { transactionHash: tempoTransactionHash } : {}
|
|
11896
|
+
});
|
|
11897
|
+
}
|
|
11898
|
+
if (identity.headerInvalid) warnInvalidJobIdentityHeader();
|
|
11899
|
+
const data = parsedBody;
|
|
11900
|
+
const feedbackClaim = identity.claimAllowed ? res.headers.get(ROUTER_FEEDBACK_CLAIM_HEADER) ?? void 0 : void 0;
|
|
11068
11901
|
const jobToken = data.job_token;
|
|
11069
11902
|
if (res.status === 202) {
|
|
11070
11903
|
return {
|
|
11071
|
-
jobId:
|
|
11904
|
+
jobId: identity.jobId,
|
|
11072
11905
|
status: data.status === "awaiting-input" ? "awaiting-input" : "processing",
|
|
11073
11906
|
estimatedSeconds: data.estimated_seconds,
|
|
11074
11907
|
jobToken,
|
|
@@ -11078,7 +11911,7 @@ var HttpsTransport = class {
|
|
|
11078
11911
|
};
|
|
11079
11912
|
}
|
|
11080
11913
|
return {
|
|
11081
|
-
jobId:
|
|
11914
|
+
jobId: identity.jobId,
|
|
11082
11915
|
status: "completed",
|
|
11083
11916
|
summary: data.summary,
|
|
11084
11917
|
hasArtifacts: data.has_artifacts,
|
|
@@ -11093,7 +11926,7 @@ var HttpsTransport = class {
|
|
|
11093
11926
|
};
|
|
11094
11927
|
}
|
|
11095
11928
|
async requestResult(provider, requestId, signedJob) {
|
|
11096
|
-
const url = `${provider.endpoint}
|
|
11929
|
+
const url = `${provider.endpoint}/${requestRecoveryPath("request-result", requestId)}`;
|
|
11097
11930
|
const res = await dvmFetch(url, {
|
|
11098
11931
|
method: "POST",
|
|
11099
11932
|
headers: { "Content-Type": "application/json" },
|
|
@@ -11103,22 +11936,32 @@ var HttpsTransport = class {
|
|
|
11103
11936
|
if (!res.ok && res.status !== 202) {
|
|
11104
11937
|
const text = await res.text();
|
|
11105
11938
|
const structured = parseStructuredError(text);
|
|
11939
|
+
const conflict = routerConflictObservation(res.status, parseJsonObject(text));
|
|
11940
|
+
if (conflict) {
|
|
11941
|
+
throw identityError(conflict, structured ? routerProse(structured) : void 0);
|
|
11942
|
+
}
|
|
11106
11943
|
if (structured) throw structured;
|
|
11107
11944
|
throw providerResponseError(
|
|
11108
11945
|
"provider_error",
|
|
11109
11946
|
`Request lookup failed (${res.status}): ${text}`
|
|
11110
11947
|
);
|
|
11111
11948
|
}
|
|
11949
|
+
const identityHeader = parseJobIdentityHeader(jobIdentityHeaderValue(res.headers));
|
|
11112
11950
|
let data;
|
|
11113
11951
|
try {
|
|
11114
11952
|
data = await res.json();
|
|
11115
11953
|
} catch {
|
|
11116
11954
|
throw malformedRequestResult(requestId, "response_not_json");
|
|
11117
11955
|
}
|
|
11118
|
-
|
|
11956
|
+
const receipt = parseRequestResultResponse(data, requestId, res.status);
|
|
11957
|
+
if (identityHeader.kind === "valid" && identityHeader.jobId !== receipt.jobId) {
|
|
11958
|
+
throw malformedRequestResult(requestId, "job_identity_mismatch");
|
|
11959
|
+
}
|
|
11960
|
+
if (identityHeader.kind === "invalid") warnInvalidJobIdentityHeader();
|
|
11961
|
+
return receipt;
|
|
11119
11962
|
}
|
|
11120
11963
|
async requestResume(provider, requestId, signedJob, options) {
|
|
11121
|
-
const url = `${provider.endpoint}
|
|
11964
|
+
const url = `${provider.endpoint}/${requestRecoveryPath("request-resume", requestId)}`;
|
|
11122
11965
|
const signal = options?.timeoutMs && options.timeoutMs > 0 ? AbortSignal.timeout(options.timeoutMs) : void 0;
|
|
11123
11966
|
let res;
|
|
11124
11967
|
try {
|
|
@@ -11483,7 +12326,7 @@ function parseRequestResultResponse(value, requestId, httpStatus) {
|
|
|
11483
12326
|
if (data.request_id !== requestId) {
|
|
11484
12327
|
throw malformedRequestResult(requestId, "request_id_mismatch");
|
|
11485
12328
|
}
|
|
11486
|
-
if (
|
|
12329
|
+
if (!isParseableBodyJobId(data.job_id)) {
|
|
11487
12330
|
throw malformedRequestResult(requestId, "job_id_invalid");
|
|
11488
12331
|
}
|
|
11489
12332
|
const allowedStatuses = /* @__PURE__ */ new Set([
|
|
@@ -11539,16 +12382,6 @@ function parseRequestResultResponse(value, requestId, httpStatus) {
|
|
|
11539
12382
|
...parseFundingResponse(data)
|
|
11540
12383
|
};
|
|
11541
12384
|
}
|
|
11542
|
-
function isOpaqueJobToken(value) {
|
|
11543
|
-
return typeof value === "string" && value.length > 0 && value.length <= 4096 && value.trim() === value && !hasAsciiControl(value);
|
|
11544
|
-
}
|
|
11545
|
-
function hasAsciiControl(value) {
|
|
11546
|
-
for (const character of value) {
|
|
11547
|
-
const code = character.charCodeAt(0);
|
|
11548
|
-
if (code <= 31 || code === 127) return true;
|
|
11549
|
-
}
|
|
11550
|
-
return false;
|
|
11551
|
-
}
|
|
11552
12385
|
function malformedRequestResult(requestId, reason) {
|
|
11553
12386
|
return new DvmError(
|
|
11554
12387
|
"request_outcome_unknown",
|
|
@@ -11683,6 +12516,10 @@ function buildStructuredError(code, fields) {
|
|
|
11683
12516
|
function providerResponseError(code, message2) {
|
|
11684
12517
|
return new DvmError(code, message2, void 0, void 0, void 0, { message: "provider" });
|
|
11685
12518
|
}
|
|
12519
|
+
function routerProse(structured) {
|
|
12520
|
+
const display = typeof structured.data?.display === "string" ? structured.data.display : void 0;
|
|
12521
|
+
return display !== void 0 ? { display, proseSources: { display: "provider" } } : {};
|
|
12522
|
+
}
|
|
11686
12523
|
function parseJsonObject(body) {
|
|
11687
12524
|
try {
|
|
11688
12525
|
const parsed = JSON.parse(body);
|
|
@@ -12242,113 +13079,6 @@ function resolveCapability(info2, requested, dvmId) {
|
|
|
12242
13079
|
);
|
|
12243
13080
|
}
|
|
12244
13081
|
|
|
12245
|
-
// src/lib/job-access.ts
|
|
12246
|
-
function resolveJobAccess(jobId, opts) {
|
|
12247
|
-
const stored = loadJob(jobId);
|
|
12248
|
-
return resolveJobAccessWithRecord(jobId, opts, stored);
|
|
12249
|
-
}
|
|
12250
|
-
function resolveJobAccessWithRecord(jobId, opts, stored) {
|
|
12251
|
-
const endpointOverride = opts.endpoint ?? process.env.DVM_JOB_ENDPOINT;
|
|
12252
|
-
const tokenOverride = opts.jobToken ?? process.env.DVM_JOB_TOKEN;
|
|
12253
|
-
const endpointOverridden = endpointOverride !== void 0;
|
|
12254
|
-
const tokenOverridden = tokenOverride !== void 0;
|
|
12255
|
-
const rawEndpoint = endpointOverride ?? stored?.endpoint;
|
|
12256
|
-
const jobToken = tokenOverride ?? stored?.jobToken;
|
|
12257
|
-
if (!stored && rawEndpoint === void 0 && jobToken === void 0) {
|
|
12258
|
-
throw new DvmError(
|
|
12259
|
-
"job_access_required",
|
|
12260
|
-
`Job ${jobId} is not in the local store, and no portable job access was supplied.`,
|
|
12261
|
-
"Pass --endpoint <url> and --job-token <hex>, or set DVM_JOB_ENDPOINT and DVM_JOB_TOKEN."
|
|
12262
|
-
);
|
|
12263
|
-
}
|
|
12264
|
-
if (rawEndpoint === void 0) {
|
|
12265
|
-
throw new DvmError(
|
|
12266
|
-
"job_endpoint_required",
|
|
12267
|
-
`No provider endpoint is available for job ${jobId}.`,
|
|
12268
|
-
"Pass --endpoint <url> or set DVM_JOB_ENDPOINT."
|
|
12269
|
-
);
|
|
12270
|
-
}
|
|
12271
|
-
if (!stored && jobToken === void 0) {
|
|
12272
|
-
throw new DvmError(
|
|
12273
|
-
"job_token_required",
|
|
12274
|
-
`No job token is available for job ${jobId}.`,
|
|
12275
|
-
"Pass --job-token <hex> or set DVM_JOB_TOKEN."
|
|
12276
|
-
);
|
|
12277
|
-
}
|
|
12278
|
-
if (tokenOverridden && !isJobToken(jobToken)) {
|
|
12279
|
-
throw new DvmError(
|
|
12280
|
-
"invalid_job_token",
|
|
12281
|
-
"The supplied job token is not a 64-character hexadecimal value.",
|
|
12282
|
-
"Copy the job_token returned when the job was submitted; the value is never printed by this command."
|
|
12283
|
-
);
|
|
12284
|
-
}
|
|
12285
|
-
return {
|
|
12286
|
-
stored,
|
|
12287
|
-
ref: { endpoint: validateProviderEndpoint(resolveEndpoint(rawEndpoint)) },
|
|
12288
|
-
...jobToken !== void 0 ? { jobToken } : {},
|
|
12289
|
-
overridden: endpointOverridden || tokenOverridden,
|
|
12290
|
-
endpointOverridden
|
|
12291
|
-
};
|
|
12292
|
-
}
|
|
12293
|
-
function resolveStoredJobAccess(jobId, opts) {
|
|
12294
|
-
const stored = loadJob(jobId);
|
|
12295
|
-
if (!stored) {
|
|
12296
|
-
throw new DvmError(
|
|
12297
|
-
"job_payment_state_required",
|
|
12298
|
-
`Cannot pay job ${jobId} without its local payment state.`,
|
|
12299
|
-
"Run 'dvm pay' where the job record and message history are available (normally the submitting machine). An endpoint and job token cannot reconstruct its pending request and spending policy."
|
|
12300
|
-
);
|
|
12301
|
-
}
|
|
12302
|
-
return { ...resolveJobAccessWithRecord(jobId, opts, stored), stored };
|
|
12303
|
-
}
|
|
12304
|
-
async function withJobTokenRedaction(jobToken, action) {
|
|
12305
|
-
try {
|
|
12306
|
-
return await action();
|
|
12307
|
-
} catch (err) {
|
|
12308
|
-
throw redactJobTokenFromError(err, jobToken);
|
|
12309
|
-
}
|
|
12310
|
-
}
|
|
12311
|
-
function redactJobTokenFromError(err, jobToken) {
|
|
12312
|
-
if (!jobToken || !(err instanceof DvmError)) return err;
|
|
12313
|
-
const redact = (value) => value.replaceAll(jobToken, "[REDACTED]");
|
|
12314
|
-
return new DvmError(
|
|
12315
|
-
err.code,
|
|
12316
|
-
redact(err.message),
|
|
12317
|
-
err.hint === void 0 ? void 0 : redact(err.hint),
|
|
12318
|
-
err.data === void 0 ? void 0 : redactRecord(err.data, redact),
|
|
12319
|
-
err.display === void 0 ? void 0 : redact(err.display),
|
|
12320
|
-
err.proseSources
|
|
12321
|
-
);
|
|
12322
|
-
}
|
|
12323
|
-
function isJobToken(value) {
|
|
12324
|
-
return value !== void 0 && /^[0-9a-fA-F]{64}$/.test(value);
|
|
12325
|
-
}
|
|
12326
|
-
function validateProviderEndpoint(value) {
|
|
12327
|
-
try {
|
|
12328
|
-
const url = new URL(value);
|
|
12329
|
-
if ((url.protocol === "http:" || url.protocol === "https:") && url.hostname) return value;
|
|
12330
|
-
} catch {
|
|
12331
|
-
}
|
|
12332
|
-
throw new DvmError(
|
|
12333
|
-
"invalid_endpoint",
|
|
12334
|
-
"The supplied job endpoint is not a valid HTTP(S) provider URL.",
|
|
12335
|
-
"Pass a full URL such as https://provider.example, or a favorite alias such as @provider."
|
|
12336
|
-
);
|
|
12337
|
-
}
|
|
12338
|
-
function redactRecord(record, redact) {
|
|
12339
|
-
return Object.fromEntries(
|
|
12340
|
-
Object.entries(record).map(([key, value]) => [key, redactValue(value, redact)])
|
|
12341
|
-
);
|
|
12342
|
-
}
|
|
12343
|
-
function redactValue(value, redact) {
|
|
12344
|
-
if (typeof value === "string") return redact(value);
|
|
12345
|
-
if (Array.isArray(value)) return value.map((entry) => redactValue(entry, redact));
|
|
12346
|
-
if (value && typeof value === "object") {
|
|
12347
|
-
return redactRecord(value, redact);
|
|
12348
|
-
}
|
|
12349
|
-
return value;
|
|
12350
|
-
}
|
|
12351
|
-
|
|
12352
13082
|
// src/commands/dvm-identity.ts
|
|
12353
13083
|
function dvmIdentity(dvmId, capability) {
|
|
12354
13084
|
const out = {};
|
|
@@ -12587,14 +13317,14 @@ async function confirmRollback(stored, preview, opts) {
|
|
|
12587
13317
|
async function withStrandingChecked(removing, commit) {
|
|
12588
13318
|
const leaving = new Set(removing.map((target) => target.split(".")[0]));
|
|
12589
13319
|
if (leaving.has("tempo")) {
|
|
12590
|
-
const { assertTempoWalletIdle: assertTempoWalletIdle2 } = await import("./tempo-lifecycle-
|
|
13320
|
+
const { assertTempoWalletIdle: assertTempoWalletIdle2 } = await import("./tempo-lifecycle-NDBO3V3A.js");
|
|
12591
13321
|
await assertTempoWalletIdle2("disconnect");
|
|
12592
13322
|
}
|
|
12593
13323
|
if (!leaving.has("x402")) return commit();
|
|
12594
|
-
const { withX402ChannelLock: withX402ChannelLock2, listPendingX402Fundings: listPendingX402Fundings2, x402PendingUnsettled: x402PendingUnsettled2 } = await import("./internal-
|
|
12595
|
-
const { assertX402WalletIdle: assertX402WalletIdle2 } = await import("./lifecycle-
|
|
12596
|
-
const { ensureAddress: ensureAddress2 } = await import("./internal-
|
|
12597
|
-
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-
|
|
13324
|
+
const { withX402ChannelLock: withX402ChannelLock2, listPendingX402Fundings: listPendingX402Fundings2, x402PendingUnsettled: x402PendingUnsettled2 } = await import("./internal-VIAWW5ED.js");
|
|
13325
|
+
const { assertX402WalletIdle: assertX402WalletIdle2 } = await import("./lifecycle-VHGTNHHE.js");
|
|
13326
|
+
const { ensureAddress: ensureAddress2 } = await import("./internal-VIAWW5ED.js");
|
|
13327
|
+
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-RB2RPWIN.js");
|
|
12598
13328
|
return withX402ChannelLock2(async () => {
|
|
12599
13329
|
const unsettled = listPendingX402Fundings2().filter((entry) => x402PendingUnsettled2(entry));
|
|
12600
13330
|
if (unsettled.length > 0) {
|
|
@@ -13457,7 +14187,7 @@ function creditDrainCommand(handle, creditId) {
|
|
|
13457
14187
|
}
|
|
13458
14188
|
|
|
13459
14189
|
// src/commands/wallet-history.ts
|
|
13460
|
-
import { createHash } from "crypto";
|
|
14190
|
+
import { createHash as createHash2 } from "crypto";
|
|
13461
14191
|
|
|
13462
14192
|
// src/lib/completed-credit-history.ts
|
|
13463
14193
|
function completedCreditHistory(query = {}) {
|
|
@@ -13602,7 +14332,7 @@ function walletHistory(opts, now = /* @__PURE__ */ new Date()) {
|
|
|
13602
14332
|
const windowed = (sinceMs === null ? all : all.filter((e) => e.timestamp >= sinceMs)).slice().sort(
|
|
13603
14333
|
(a, b) => b.timestamp - a.timestamp || (a.id < b.id ? 1 : a.id > b.id ? -1 : 0)
|
|
13604
14334
|
);
|
|
13605
|
-
const fingerprint =
|
|
14335
|
+
const fingerprint = createHash2("sha256").update(JSON.stringify(windowed)).digest("hex");
|
|
13606
14336
|
if (continuation && continuation.fingerprint !== fingerprint) {
|
|
13607
14337
|
throw invalidHistoryCursor();
|
|
13608
14338
|
}
|
|
@@ -14626,7 +15356,7 @@ function wireCreditCurrencyTotals(rows) {
|
|
|
14626
15356
|
|
|
14627
15357
|
// src/lib/credit/drain.ts
|
|
14628
15358
|
import {
|
|
14629
|
-
randomUUID
|
|
15359
|
+
randomUUID as randomUUID2
|
|
14630
15360
|
} from "crypto";
|
|
14631
15361
|
async function runCreditDrain(dvm, opts) {
|
|
14632
15362
|
const endpoint = resolveCreditEndpoint(dvm);
|
|
@@ -14758,7 +15488,7 @@ async function runCreditDrain(dvm, opts) {
|
|
|
14758
15488
|
const payout = await drainPayout(method, opts, channelBacked, dvm);
|
|
14759
15489
|
const mintedThisRun = !pending4;
|
|
14760
15490
|
let drain = pending4 ? reusableDrain(pending4, method, payout) : {
|
|
14761
|
-
drainId: opts.drainId ??
|
|
15491
|
+
drainId: opts.drainId ?? randomUUID2(),
|
|
14762
15492
|
creditId,
|
|
14763
15493
|
method,
|
|
14764
15494
|
payout,
|
|
@@ -15593,7 +16323,7 @@ function refundAddress(address) {
|
|
|
15593
16323
|
|
|
15594
16324
|
// src/lib/credit/funding.ts
|
|
15595
16325
|
import {
|
|
15596
|
-
randomUUID as
|
|
16326
|
+
randomUUID as randomUUID3
|
|
15597
16327
|
} from "crypto";
|
|
15598
16328
|
async function runCreditFund(dvm, opts) {
|
|
15599
16329
|
const endpoint = resolveCreditEndpoint(dvm);
|
|
@@ -15697,7 +16427,7 @@ async function runCreditFund(dvm, opts) {
|
|
|
15697
16427
|
transport,
|
|
15698
16428
|
ref: { endpoint },
|
|
15699
16429
|
signing: signer,
|
|
15700
|
-
creditId: pending4?.creditId ?? opts.creditId ?? (canRefillStoredCredit(stored) ? stored.creditId : signedPending?.creditId ??
|
|
16430
|
+
creditId: pending4?.creditId ?? opts.creditId ?? (canRefillStoredCredit(stored) ? stored.creditId : signedPending?.creditId ?? randomUUID3()),
|
|
15701
16431
|
amountMicro: fundMicro,
|
|
15702
16432
|
human: opts.human,
|
|
15703
16433
|
providerInfo,
|
|
@@ -17426,8 +18156,8 @@ async function probeX402(x402, timeoutMs) {
|
|
|
17426
18156
|
let network;
|
|
17427
18157
|
let address;
|
|
17428
18158
|
try {
|
|
17429
|
-
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-
|
|
17430
|
-
const { getX402Balance, ensureAddress: ensureAddress2, usdcContractByCaip2 } = await import("./internal-
|
|
18159
|
+
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-RB2RPWIN.js");
|
|
18160
|
+
const { getX402Balance, ensureAddress: ensureAddress2, usdcContractByCaip2 } = await import("./internal-VIAWW5ED.js");
|
|
17431
18161
|
const wallet = loadX402Wallet2();
|
|
17432
18162
|
if (!wallet) {
|
|
17433
18163
|
const storedKey = x402.privateKey;
|
|
@@ -17479,8 +18209,8 @@ async function probeMpp(mpp, timeoutMs) {
|
|
|
17479
18209
|
if (!mpp) return null;
|
|
17480
18210
|
if (mpp.method === "tempo") {
|
|
17481
18211
|
try {
|
|
17482
|
-
const { connectedTempoAccount: connectedTempoAccount2 } = await import("./tempo-wallet-
|
|
17483
|
-
const { getTempoUsdcBalance: getTempoUsdcBalance3, resolveTempoNetwork: resolveTempoNetwork2 } = await import("./internal-
|
|
18212
|
+
const { connectedTempoAccount: connectedTempoAccount2 } = await import("./tempo-wallet-BAU7ASWF.js");
|
|
18213
|
+
const { getTempoUsdcBalance: getTempoUsdcBalance3, resolveTempoNetwork: resolveTempoNetwork2 } = await import("./internal-VIAWW5ED.js");
|
|
17484
18214
|
const account = await connectedTempoAccount2();
|
|
17485
18215
|
if (!account) {
|
|
17486
18216
|
return {
|
|
@@ -17574,8 +18304,8 @@ function x402WrongAssetHint(asset) {
|
|
|
17574
18304
|
}
|
|
17575
18305
|
|
|
17576
18306
|
// src/lib/build-freshness.ts
|
|
17577
|
-
import { existsSync as
|
|
17578
|
-
import { dirname as dirname3, join as
|
|
18307
|
+
import { existsSync as existsSync4, readdirSync as readdirSync2, statSync as statSync3 } from "fs";
|
|
18308
|
+
import { dirname as dirname3, join as join4 } from "path";
|
|
17579
18309
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
17580
18310
|
var EXTRA_SOURCES = ["package.json", "tsup.config.ts"];
|
|
17581
18311
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "__snapshots__"]);
|
|
@@ -17594,21 +18324,21 @@ function checkBuildFreshness(opts) {
|
|
|
17594
18324
|
skipReason
|
|
17595
18325
|
});
|
|
17596
18326
|
if (root === null) return skipped("running_from_source");
|
|
17597
|
-
const bundlePath =
|
|
17598
|
-
if (dirname3(moduleDir) !== root || !
|
|
18327
|
+
const bundlePath = join4(root, "dist", "dvm.js");
|
|
18328
|
+
if (dirname3(moduleDir) !== root || !existsSync4(bundlePath)) {
|
|
17599
18329
|
return skipped("running_from_source");
|
|
17600
18330
|
}
|
|
17601
|
-
const srcDir =
|
|
17602
|
-
if (!
|
|
18331
|
+
const srcDir = join4(root, "src");
|
|
18332
|
+
if (!existsSync4(srcDir)) return skipped("no_source_tree");
|
|
17603
18333
|
const builtAtMs = statSync3(bundlePath).mtimeMs;
|
|
17604
18334
|
const newer = [];
|
|
17605
18335
|
let newestMs = 0;
|
|
17606
18336
|
const visit = (dir, rel, budget2) => {
|
|
17607
18337
|
if (budget2.left <= 0) return;
|
|
17608
|
-
for (const entry of
|
|
18338
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
17609
18339
|
if (budget2.left-- <= 0) return;
|
|
17610
18340
|
if (entry.name.startsWith(".") || SKIP_DIRS.has(entry.name)) continue;
|
|
17611
|
-
const abs =
|
|
18341
|
+
const abs = join4(dir, entry.name);
|
|
17612
18342
|
const relPath = rel ? `${rel}/${entry.name}` : entry.name;
|
|
17613
18343
|
if (entry.isDirectory()) {
|
|
17614
18344
|
visit(abs, relPath, budget2);
|
|
@@ -17623,8 +18353,8 @@ function checkBuildFreshness(opts) {
|
|
|
17623
18353
|
const budget = { left: MAX_ENTRIES };
|
|
17624
18354
|
visit(srcDir, "src", budget);
|
|
17625
18355
|
for (const name of EXTRA_SOURCES) {
|
|
17626
|
-
const abs =
|
|
17627
|
-
if (!
|
|
18356
|
+
const abs = join4(root, name);
|
|
18357
|
+
if (!existsSync4(abs)) continue;
|
|
17628
18358
|
const mtimeMs = statSync3(abs).mtimeMs;
|
|
17629
18359
|
if (mtimeMs > newestMs) newestMs = mtimeMs;
|
|
17630
18360
|
if (mtimeMs > builtAtMs) newer.push({ path: name, mtimeMs });
|
|
@@ -17642,7 +18372,7 @@ function checkBuildFreshness(opts) {
|
|
|
17642
18372
|
function findPackageRoot(start) {
|
|
17643
18373
|
let dir = start;
|
|
17644
18374
|
for (; ; ) {
|
|
17645
|
-
if (
|
|
18375
|
+
if (existsSync4(join4(dir, "package.json"))) return dir;
|
|
17646
18376
|
const parent = dirname3(dir);
|
|
17647
18377
|
if (parent === dir) return null;
|
|
17648
18378
|
dir = parent;
|
|
@@ -17650,18 +18380,18 @@ function findPackageRoot(start) {
|
|
|
17650
18380
|
}
|
|
17651
18381
|
|
|
17652
18382
|
// src/lib/caller-state.ts
|
|
17653
|
-
import { existsSync as
|
|
17654
|
-
import { basename, join as
|
|
18383
|
+
import { existsSync as existsSync5, readdirSync as readdirSync3, readFileSync as readFileSync5, statSync as statSync4 } from "fs";
|
|
18384
|
+
import { basename, join as join5 } from "path";
|
|
17655
18385
|
function detectSetupState() {
|
|
17656
18386
|
return {
|
|
17657
18387
|
existingState: {
|
|
17658
|
-
jobs:
|
|
17659
|
-
messages:
|
|
18388
|
+
jobs: existsSync5(JOBS_FILE),
|
|
18389
|
+
messages: existsSync5(MESSAGES_DIR)
|
|
17660
18390
|
},
|
|
17661
18391
|
missing: {
|
|
17662
|
-
config: !
|
|
17663
|
-
identity: !
|
|
17664
|
-
wallet: !
|
|
18392
|
+
config: !existsSync5(CONFIG_FILE),
|
|
18393
|
+
identity: !existsSync5(IDENTITIES_FILE),
|
|
18394
|
+
wallet: !existsSync5(WALLET_FILE)
|
|
17665
18395
|
}
|
|
17666
18396
|
};
|
|
17667
18397
|
}
|
|
@@ -17757,6 +18487,16 @@ var FILE_SPECS = [
|
|
|
17757
18487
|
directory: true
|
|
17758
18488
|
},
|
|
17759
18489
|
{ name: "messages", path: MESSAGES_DIR, json: false, secret: false, directory: true },
|
|
18490
|
+
// Evidence of paid calls accepted without a settled job identity. Each file
|
|
18491
|
+
// is 0600 because a record can hold an anonymous job's access token, so
|
|
18492
|
+
// every file in the directory is checked.
|
|
18493
|
+
{
|
|
18494
|
+
name: "submission_evidence",
|
|
18495
|
+
path: SUBMISSION_EVIDENCE_DIR,
|
|
18496
|
+
json: false,
|
|
18497
|
+
secret: true,
|
|
18498
|
+
directory: true
|
|
18499
|
+
},
|
|
17760
18500
|
// JSONL, not JSON — `json: false` because a whole-file `JSON.parse` would
|
|
17761
18501
|
// report the healthy multi-line form as corrupt. `dvm receipts list` already
|
|
17762
18502
|
// skips malformed lines individually.
|
|
@@ -17770,31 +18510,33 @@ function findQuarantinedCreditStores() {
|
|
|
17770
18510
|
const prefix = `${basename(CREDITS_FILE)}.corrupt-`;
|
|
17771
18511
|
let entries;
|
|
17772
18512
|
try {
|
|
17773
|
-
entries =
|
|
18513
|
+
entries = readdirSync3(CONFIG_DIR);
|
|
17774
18514
|
} catch {
|
|
17775
18515
|
return [];
|
|
17776
18516
|
}
|
|
17777
|
-
return entries.filter((name) => name.startsWith(prefix)).sort((a, b) => a < b ? 1 : a > b ? -1 : 0).map((name) => ({ path:
|
|
18517
|
+
return entries.filter((name) => name.startsWith(prefix)).sort((a, b) => a < b ? 1 : a > b ? -1 : 0).map((name) => ({ path: join5(CONFIG_DIR, name), name }));
|
|
17778
18518
|
}
|
|
17779
18519
|
function checkOne(spec) {
|
|
17780
|
-
const exists =
|
|
18520
|
+
const exists = existsSync5(spec.path);
|
|
17781
18521
|
if (!exists) {
|
|
17782
18522
|
return { name: spec.name, path: spec.path, exists: false };
|
|
17783
18523
|
}
|
|
17784
18524
|
const row = { name: spec.name, path: spec.path, exists: true };
|
|
17785
18525
|
if (spec.json) {
|
|
17786
18526
|
try {
|
|
17787
|
-
JSON.parse(
|
|
18527
|
+
JSON.parse(readFileSync5(spec.path, "utf-8"));
|
|
17788
18528
|
row.parseable = true;
|
|
17789
18529
|
} catch (err) {
|
|
17790
18530
|
row.parseable = false;
|
|
17791
18531
|
row.error = err instanceof Error ? err.message : String(err);
|
|
17792
18532
|
}
|
|
17793
18533
|
}
|
|
17794
|
-
if (spec.secret) {
|
|
18534
|
+
if (spec.secret && spec.directory) {
|
|
18535
|
+
checkSecretDirectory(spec.path, row);
|
|
18536
|
+
} else if (spec.secret) {
|
|
17795
18537
|
try {
|
|
17796
18538
|
const mode = statSync4(spec.path).mode & 511;
|
|
17797
|
-
const modeOctal =
|
|
18539
|
+
const modeOctal = octalMode(mode);
|
|
17798
18540
|
row.modeOk = mode === 384;
|
|
17799
18541
|
row.modeOctal = modeOctal;
|
|
17800
18542
|
if (!row.modeOk && !row.error) {
|
|
@@ -17807,10 +18549,34 @@ function checkOne(spec) {
|
|
|
17807
18549
|
}
|
|
17808
18550
|
return row;
|
|
17809
18551
|
}
|
|
18552
|
+
function checkSecretDirectory(dir, row) {
|
|
18553
|
+
try {
|
|
18554
|
+
const offenders = [];
|
|
18555
|
+
for (const name of readdirSync3(dir)) {
|
|
18556
|
+
const path = join5(dir, name);
|
|
18557
|
+
const stat = statSync4(path);
|
|
18558
|
+
if (!stat.isFile()) continue;
|
|
18559
|
+
const mode = stat.mode & 511;
|
|
18560
|
+
if (mode !== 384) offenders.push({ path, modeOctal: octalMode(mode) });
|
|
18561
|
+
}
|
|
18562
|
+
row.modeOk = offenders.length === 0;
|
|
18563
|
+
if (offenders.length > 0) {
|
|
18564
|
+
row.modeOctal = offenders[0].modeOctal;
|
|
18565
|
+
row.offendingPaths = offenders.map((o) => o.path);
|
|
18566
|
+
row.error = `expected mode 0600, found ${row.modeOctal} on ${String(offenders.length)} file(s)`;
|
|
18567
|
+
}
|
|
18568
|
+
} catch (err) {
|
|
18569
|
+
row.modeOk = false;
|
|
18570
|
+
row.error = err instanceof Error ? err.message : String(err);
|
|
18571
|
+
}
|
|
18572
|
+
}
|
|
18573
|
+
function octalMode(mode) {
|
|
18574
|
+
return "0" + mode.toString(8).padStart(3, "0");
|
|
18575
|
+
}
|
|
17810
18576
|
function readBtcRateCacheAge(now = Date.now()) {
|
|
17811
|
-
if (!
|
|
18577
|
+
if (!existsSync5(BTC_RATE_FILE)) return null;
|
|
17812
18578
|
try {
|
|
17813
|
-
const data = JSON.parse(
|
|
18579
|
+
const data = JSON.parse(readFileSync5(BTC_RATE_FILE, "utf-8"));
|
|
17814
18580
|
if (typeof data.timestamp !== "number") return null;
|
|
17815
18581
|
return { ageMs: now - data.timestamp };
|
|
17816
18582
|
} catch {
|
|
@@ -17819,20 +18585,20 @@ function readBtcRateCacheAge(now = Date.now()) {
|
|
|
17819
18585
|
}
|
|
17820
18586
|
|
|
17821
18587
|
// src/lib/mnemonic-backups.ts
|
|
17822
|
-
import { readdirSync as
|
|
17823
|
-
import { basename as basename2, dirname as dirname4, join as
|
|
18588
|
+
import { readdirSync as readdirSync4, statSync as statSync5 } from "fs";
|
|
18589
|
+
import { basename as basename2, dirname as dirname4, join as join6 } from "path";
|
|
17824
18590
|
function findMnemonicBackups(mnemonicFile, nowMs = Date.now()) {
|
|
17825
18591
|
const dir = dirname4(mnemonicFile);
|
|
17826
18592
|
const prefix = `${basename2(mnemonicFile)}.`;
|
|
17827
18593
|
let names;
|
|
17828
18594
|
try {
|
|
17829
|
-
names =
|
|
18595
|
+
names = readdirSync4(dir);
|
|
17830
18596
|
} catch (err) {
|
|
17831
18597
|
if (err.code === "ENOENT") return [];
|
|
17832
18598
|
throw err;
|
|
17833
18599
|
}
|
|
17834
18600
|
return names.filter((name) => name.startsWith(prefix) && name.endsWith(".bak")).map((name) => {
|
|
17835
|
-
const path =
|
|
18601
|
+
const path = join6(dir, name);
|
|
17836
18602
|
const stat = statSync5(path);
|
|
17837
18603
|
if (!stat.isFile()) return null;
|
|
17838
18604
|
const ageMs2 = Math.max(0, nowMs - stat.mtimeMs);
|
|
@@ -17881,39 +18647,80 @@ function describePendingSubmissions(wallet, nowMs = Date.now()) {
|
|
|
17881
18647
|
(e) => e.state === "stale" || e.state === "unresumable" || e.state === "unreclaimable"
|
|
17882
18648
|
).length,
|
|
17883
18649
|
reclaimable_count: entries.filter((e) => e.state === "reclaimable").length,
|
|
17884
|
-
reclaim_failed_count: entries.filter((e) => e.state === "reclaim_failed").length
|
|
18650
|
+
reclaim_failed_count: entries.filter((e) => e.state === "reclaim_failed").length,
|
|
18651
|
+
accepted_unresolved_count: entries.filter((e) => e.state === "accepted_unresolved").length
|
|
17885
18652
|
};
|
|
17886
18653
|
}
|
|
17887
18654
|
function formatPendingSubmission(view) {
|
|
17888
18655
|
const reqShort = `${view.request_id.slice(0, 8)}\u2026${view.request_id.slice(-4)}`;
|
|
17889
18656
|
const age = view.age_seconds === null ? "age unknown" : `${formatAge(view.age_seconds)} old`;
|
|
17890
18657
|
const why = view.reclaim_error ? `: ${view.reclaim_error}` : "";
|
|
17891
|
-
|
|
18658
|
+
const readBack = view.public_request_id ? `; dvm request-result ${view.public_request_id}` : "";
|
|
18659
|
+
return `${view.amount_sats} sats ${view.endpoint} (req ${reqShort}, ${age}, ${view.state}${why}${readBack})`;
|
|
17892
18660
|
}
|
|
17893
18661
|
function describeResumedSubmissions(outcomes) {
|
|
17894
18662
|
const views = [];
|
|
17895
18663
|
for (const outcome of outcomes) {
|
|
18664
|
+
const publicRequestId = publicRequestIdOf(outcome.entry);
|
|
18665
|
+
const locate = locateAdvice(outcome.entry, publicRequestId);
|
|
17896
18666
|
if (outcome.kind === "shipped") {
|
|
17897
18667
|
const jobId = outcome.jobId ?? null;
|
|
17898
18668
|
views.push({
|
|
17899
18669
|
request_id: outcome.entry.request_id,
|
|
18670
|
+
...publicRequestId ? { public_request_id: publicRequestId } : {},
|
|
17900
18671
|
endpoint: outcome.entry.endpoint,
|
|
17901
18672
|
amount_sats: outcome.entry.amount_sats,
|
|
17902
18673
|
job_id: jobId,
|
|
17903
|
-
display: jobId ? `${outcome.entry.amount_sats} sats paid to ${outcome.entry.endpoint} was reconciled \u2014 the job resumed as ${jobId}. Look it up with \`dvm status ${jobId}\`.` : `${outcome.entry.amount_sats} sats paid to ${outcome.entry.endpoint} was reconciled, but the provider returned no job id.
|
|
18674
|
+
display: jobId ? `${outcome.entry.amount_sats} sats paid to ${outcome.entry.endpoint} was reconciled \u2014 the job resumed as ${jobId}. Look it up with \`dvm status ${jobId}\`.` : `${outcome.entry.amount_sats} sats paid to ${outcome.entry.endpoint} was reconciled, but the provider returned no job id. ${locate}`
|
|
17904
18675
|
});
|
|
17905
18676
|
} else if (outcome.kind === "already_accepted") {
|
|
17906
18677
|
views.push({
|
|
17907
18678
|
request_id: outcome.entry.request_id,
|
|
18679
|
+
...publicRequestId ? { public_request_id: publicRequestId } : {},
|
|
17908
18680
|
endpoint: outcome.entry.endpoint,
|
|
17909
18681
|
amount_sats: outcome.entry.amount_sats,
|
|
17910
18682
|
job_id: null,
|
|
17911
|
-
display: `${outcome.entry.amount_sats} sats paid to ${outcome.entry.endpoint} was already confirmed by the provider, which returned no job id.
|
|
18683
|
+
display: `${outcome.entry.amount_sats} sats paid to ${outcome.entry.endpoint} was already confirmed by the provider, which returned no job id. ${locate}`
|
|
17912
18684
|
});
|
|
17913
18685
|
}
|
|
17914
18686
|
}
|
|
17915
18687
|
return views;
|
|
17916
18688
|
}
|
|
18689
|
+
function describeUnresolvedSubmissions(outcomes) {
|
|
18690
|
+
const views = [];
|
|
18691
|
+
for (const outcome of outcomes) {
|
|
18692
|
+
if (outcome.kind === "evidence_unreadable") {
|
|
18693
|
+
const { entry: entry2 } = outcome;
|
|
18694
|
+
const publicRequestId2 = publicRequestIdOf(entry2);
|
|
18695
|
+
views.push({
|
|
18696
|
+
request_id: entry2.request_id,
|
|
18697
|
+
...publicRequestId2 ? { public_request_id: publicRequestId2 } : {},
|
|
18698
|
+
endpoint: entry2.endpoint,
|
|
18699
|
+
amount_sats: entry2.amount_sats,
|
|
18700
|
+
ambiguity_id: entry2.request_id,
|
|
18701
|
+
evidence: "unreadable",
|
|
18702
|
+
display: `${entry2.amount_sats} sats paid to ${entry2.endpoint} has an evidence record that cannot be read, so the payment is held and not sent again until the file under ${entry2.request_id} in \`dvm wallet submissions\` is restored. ${locateAdvice(entry2, publicRequestId2)}`
|
|
18703
|
+
});
|
|
18704
|
+
continue;
|
|
18705
|
+
}
|
|
18706
|
+
if (outcome.kind !== "accepted_unresolved") continue;
|
|
18707
|
+
if (outcome.evidence === "recorded" && !outcome.observation) continue;
|
|
18708
|
+
const { entry, marker } = outcome;
|
|
18709
|
+
const publicRequestId = publicRequestIdOf(entry);
|
|
18710
|
+
const readBack = publicRequestId ? ` Read the job back with \`dvm request-result ${publicRequestId}\`, which never pays.` : "";
|
|
18711
|
+
views.push({
|
|
18712
|
+
request_id: entry.request_id,
|
|
18713
|
+
...publicRequestId ? { public_request_id: publicRequestId } : {},
|
|
18714
|
+
endpoint: entry.endpoint,
|
|
18715
|
+
amount_sats: entry.amount_sats,
|
|
18716
|
+
kind: marker.kind,
|
|
18717
|
+
ambiguity_id: marker.ambiguity_id,
|
|
18718
|
+
evidence: outcome.evidence,
|
|
18719
|
+
display: outcome.evidence === "recorded" ? `${entry.amount_sats} sats paid to ${entry.endpoint} was accepted on retry, but the provider did not say clearly which job it started. It will not be paid for or sent again; \`dvm wallet submissions\` shows the evidence (${marker.ambiguity_id}).${readBack}` : `${entry.amount_sats} sats paid to ${entry.endpoint} was accepted without a clear job ID, and the evidence record ${marker.ambiguity_id} is ${outcome.evidence === "missing" ? "missing from this machine" : "damaged"}. The payment is still never sent again. ${locateAdvice(entry, publicRequestId)}`
|
|
18720
|
+
});
|
|
18721
|
+
}
|
|
18722
|
+
return views;
|
|
18723
|
+
}
|
|
17917
18724
|
function describeReclaimedSubmissions(outcomes) {
|
|
17918
18725
|
const views = [];
|
|
17919
18726
|
for (const outcome of outcomes) {
|
|
@@ -17947,6 +18754,34 @@ function describeSkippedReclaims(outcomes) {
|
|
|
17947
18754
|
}
|
|
17948
18755
|
return views;
|
|
17949
18756
|
}
|
|
18757
|
+
function describeSubmissionEvidence(records) {
|
|
18758
|
+
return records.map((record) => {
|
|
18759
|
+
const { v: _v, job_token: jobToken, ...fields } = record;
|
|
18760
|
+
const jobIds = [
|
|
18761
|
+
...new Set(
|
|
18762
|
+
[record.header_job_id, record.body_job_id, record.accepted_job_id].filter(
|
|
18763
|
+
(id) => id !== void 0
|
|
18764
|
+
)
|
|
18765
|
+
)
|
|
18766
|
+
];
|
|
18767
|
+
const collision = record.kind === "local_job_collision";
|
|
18768
|
+
const readJob = [
|
|
18769
|
+
...record.request_id && !collision ? [`dvm request-result ${record.request_id}`] : [],
|
|
18770
|
+
...jobToken ? jobIds.map(
|
|
18771
|
+
(jobId) => `DVM_JOB_TOKEN=<job_token_bearer_secret> dvm status ${shellQuoteArg(jobId)} --endpoint ${shellQuoteArg(record.endpoint)}`
|
|
18772
|
+
) : []
|
|
18773
|
+
];
|
|
18774
|
+
const what = collision ? `its job${record.accepted_job_id ? ` ${record.accepted_job_id}` : ""} shares its ID with a local job from another provider, so it is kept here rather than in the local job list` : record.kind === "router_identity_conflict" ? "this request had already been accepted as a different job" : record.kind === "identity_mismatch" ? "the provider named two different jobs for it" : "the provider's reply did not state a readable job";
|
|
18775
|
+
const lookup = readJob.length > 0 ? ` Find the job with one of read_job; those lookups never pay.` : jobIds.length > 0 ? ` No job token was received for ${jobIds.join(", ")}, so quote the request to the provider operator.` : " No job ID was observed, so quote the request to the provider operator.";
|
|
18776
|
+
const secret = jobToken ? " job_token_bearer_secret is a bearer secret: treat it like a password and do not share it." : "";
|
|
18777
|
+
return {
|
|
18778
|
+
...fields,
|
|
18779
|
+
...jobToken ? { job_token_bearer_secret: jobToken } : {},
|
|
18780
|
+
read_job: readJob,
|
|
18781
|
+
display: `A paid call to ${record.endpoint} was accepted, but ${what}. It was not paid for again.${lookup}${secret}`
|
|
18782
|
+
};
|
|
18783
|
+
});
|
|
18784
|
+
}
|
|
17950
18785
|
function toView(entry, nowMs) {
|
|
17951
18786
|
const createdMs = Date.parse(entry.created_at);
|
|
17952
18787
|
const ageMs2 = Number.isNaN(createdMs) ? Number.POSITIVE_INFINITY : nowMs - createdMs;
|
|
@@ -17964,13 +18799,22 @@ function toView(entry, nowMs) {
|
|
|
17964
18799
|
at_risk: state !== "awaiting_swap",
|
|
17965
18800
|
reclaim_at: reclaimAt === null ? null : new Date(reclaimAt).toISOString(),
|
|
17966
18801
|
reclaim_error: state === "reclaim_failed" || state === "unreclaimable" ? entry.reclaim_error ?? null : null,
|
|
18802
|
+
...entry.accepted_unresolved ? { accepted_unresolved: entry.accepted_unresolved } : {},
|
|
18803
|
+
...publicRequestIdOf(entry) ? { public_request_id: publicRequestIdOf(entry) } : {},
|
|
17967
18804
|
display: describe2(entry, state, reclaimAt, nowMs)
|
|
17968
18805
|
};
|
|
17969
18806
|
}
|
|
18807
|
+
function locateAdvice(entry, publicRequestId = publicRequestIdOf(entry)) {
|
|
18808
|
+
return publicRequestId ? `Read the job back with \`dvm request-result ${publicRequestId}\`, which never pays.` : `Quote request ${entry.request_id} to the provider to locate the result.`;
|
|
18809
|
+
}
|
|
17970
18810
|
function deriveState(entry, ageMs2, attempts, reclaimAt) {
|
|
17971
18811
|
if (entry.output_proofs.length === 0) {
|
|
17972
18812
|
return entry.swapping ? "recovering_swap" : "awaiting_swap";
|
|
17973
18813
|
}
|
|
18814
|
+
if (entry.accepted_unresolved) {
|
|
18815
|
+
if (reclaimAt === null || !entry.reclaim_error) return "accepted_unresolved";
|
|
18816
|
+
return entry.reclaim_terminal ? "unreclaimable" : "reclaim_failed";
|
|
18817
|
+
}
|
|
17974
18818
|
const resumeOver = !isResumable(entry) || ageMs2 > RESUME_MAX_AGE_MS || attempts >= RESUME_MAX_ATTEMPTS;
|
|
17975
18819
|
if (resumeOver && reclaimAt !== null) {
|
|
17976
18820
|
if (!entry.reclaim_error) return "reclaimable";
|
|
@@ -17988,7 +18832,7 @@ function describe2(entry, state, reclaimAt, nowMs) {
|
|
|
17988
18832
|
case "recovering_swap":
|
|
17989
18833
|
return `${sats} is tied to a mint swap whose response was interrupted. The wallet is restoring the signed payment or proving the original inputs remain spendable; do not retry or forget request ${entry.request_id}.`;
|
|
17990
18834
|
case "resumable":
|
|
17991
|
-
return `${sats} was paid to ${entry.endpoint} but the provider never confirmed. The next call to any DVM retries it automatically.`;
|
|
18835
|
+
return publicRequestIdOf(entry) ? `${sats} was paid to ${entry.endpoint} but the provider never confirmed. The next call to any DVM reads request ${publicRequestIdOf(entry)} back from the provider, and re-sends the same payment only if the provider never received it.` : `${sats} was paid to ${entry.endpoint} but the provider never confirmed. The next call to any DVM retries it automatically.`;
|
|
17992
18836
|
case "reclaimable":
|
|
17993
18837
|
return reclaimAt !== null && reclaimAt > nowMs ? `${sats} was paid to ${entry.endpoint} and the provider never confirmed it. Retries have stopped, but the payment has an expiry: if the provider still hasn't taken it by ${new Date(reclaimAt).toISOString()}, the wallet returns it to your balance on its own. Nothing to do.` : `${sats} was paid to ${entry.endpoint} and the provider never confirmed it. The payment has expired, so the wallet can take it back \u2014 it returns to your balance on the next call or \`dvm wallet show\`.`;
|
|
17994
18838
|
case "reclaim_failed":
|
|
@@ -17996,9 +18840,14 @@ function describe2(entry, state, reclaimAt, nowMs) {
|
|
|
17996
18840
|
case "unreclaimable":
|
|
17997
18841
|
return entry.reclaim_error?.startsWith("worth ") ? `${sats} was paid to ${entry.endpoint}, the provider never took it, and the payment has expired \u2014 but it is too small to be worth taking back: ${entry.reclaim_error}. Retrying will not change that, so treat these sats as spent; \`dvm wallet submissions --forget ${entry.request_id}\` clears the entry once you have stopped caring about it.` : `${sats} was paid to ${entry.endpoint}, the provider never took it, and automatic recovery cannot succeed: ${entry.reclaim_error ?? "the mint rejected the recovery permanently"} Do not delete the entry until the mint operator has reviewed request ${entry.request_id}.`;
|
|
17998
18842
|
case "stale":
|
|
17999
|
-
return `${sats} was paid to ${entry.endpoint} and the provider never confirmed it. Retries have stopped. If the job never ran, ask the provider to look up request ${entry.request_id}.`;
|
|
18843
|
+
return publicRequestIdOf(entry) ? `${sats} was paid to ${entry.endpoint} and the provider never confirmed it. Retries have stopped. ${locateAdvice(entry)}` : `${sats} was paid to ${entry.endpoint} and the provider never confirmed it. Retries have stopped. If the job never ran, ask the provider to look up request ${entry.request_id}.`;
|
|
18844
|
+
case "accepted_unresolved": {
|
|
18845
|
+
const reclaim = reclaimAt === null ? "" : ` If the provider never redeems the payment, the wallet takes it back after ${new Date(reclaimAt).toISOString()}.`;
|
|
18846
|
+
const readBack = publicRequestIdOf(entry) ? ` ${locateAdvice(entry)}` : "";
|
|
18847
|
+
return `${sats} was paid to ${entry.endpoint} and the provider accepted the call, but did not say clearly which job it started. Automatic retries are off for it so it is never paid twice.${reclaim} The recorded evidence is under ${entry.accepted_unresolved?.ambiguity_id ?? entry.request_id} in \`dvm wallet submissions\`.${readBack}`;
|
|
18848
|
+
}
|
|
18000
18849
|
case "unresumable":
|
|
18001
|
-
return entry.context?.signing_pubkey ? `${sats} was paid to ${entry.endpoint} and the provider never confirmed it. The caller identity that signed the call (${entry.context.signing_pubkey.slice(0, 8)}\u2026) is no longer configured, so it cannot be retried. Quote request ${entry.request_id} to the provider.` : `${sats} was paid to ${entry.endpoint} and the provider never confirmed it. This payment cannot be retried automatically. Quote request ${entry.request_id} to the provider.`;
|
|
18850
|
+
return entry.context?.signing_pubkey ? `${sats} was paid to ${entry.endpoint} and the provider never confirmed it. The caller identity that signed the call (${entry.context.signing_pubkey.slice(0, 8)}\u2026) is no longer configured, so it cannot be retried. Quote request ${publicRequestIdOf(entry) ?? entry.request_id} to the provider.` : `${sats} was paid to ${entry.endpoint} and the provider never confirmed it. This payment cannot be retried automatically. Quote request ${entry.request_id} to the provider.`;
|
|
18002
18851
|
}
|
|
18003
18852
|
}
|
|
18004
18853
|
function formatAge(seconds) {
|
|
@@ -18369,13 +19218,18 @@ function fileRowToCheck(row) {
|
|
|
18369
19218
|
};
|
|
18370
19219
|
}
|
|
18371
19220
|
if (row.modeOk === false) {
|
|
19221
|
+
const offending = row.offendingPaths;
|
|
18372
19222
|
return {
|
|
18373
19223
|
name: `file_${row.name}`,
|
|
18374
19224
|
group: "files",
|
|
18375
19225
|
status: "warn",
|
|
18376
|
-
display: `${row.name} has permissions ${row.modeOctal ?? "?"} (expected 0600).`,
|
|
18377
|
-
hint: `Tighten permissions: chmod 600 ${row.path}`,
|
|
18378
|
-
details: {
|
|
19226
|
+
display: offending ? `${row.name} holds ${String(offending.length)} file(s) with permissions other than 0600 (first: ${row.modeOctal ?? "?"}).` : `${row.name} has permissions ${row.modeOctal ?? "?"} (expected 0600).`,
|
|
19227
|
+
hint: `Tighten permissions: chmod 600 ${offending ? offending.map(shellQuoteArg).join(" ") : row.path}`,
|
|
19228
|
+
details: {
|
|
19229
|
+
path: row.path,
|
|
19230
|
+
modeOctal: row.modeOctal,
|
|
19231
|
+
...offending ? { offending_paths: offending } : {}
|
|
19232
|
+
}
|
|
18379
19233
|
};
|
|
18380
19234
|
}
|
|
18381
19235
|
return {
|
|
@@ -19635,11 +20489,11 @@ async function favRm(name, opts) {
|
|
|
19635
20489
|
}
|
|
19636
20490
|
|
|
19637
20491
|
// src/lib/byte-source.ts
|
|
19638
|
-
import { readFileSync as
|
|
20492
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
19639
20493
|
import { resolve } from "path";
|
|
19640
20494
|
var STDIN_TIMEOUT_MS = 1e4;
|
|
19641
20495
|
function readFileText(path) {
|
|
19642
|
-
return
|
|
20496
|
+
return readFileSync6(resolve(path), "utf-8");
|
|
19643
20497
|
}
|
|
19644
20498
|
var StdinTimeoutError = class extends Error {
|
|
19645
20499
|
constructor(timeoutMs) {
|
|
@@ -19803,7 +20657,7 @@ function callerPlatformResponseError(code, remote, fallbackMessage) {
|
|
|
19803
20657
|
}
|
|
19804
20658
|
|
|
19805
20659
|
// src/lib/feedback-nudges.ts
|
|
19806
|
-
import { existsSync as
|
|
20660
|
+
import { existsSync as existsSync6, readFileSync as readFileSync7, renameSync as renameSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
19807
20661
|
|
|
19808
20662
|
// src/lib/feedback-notice.ts
|
|
19809
20663
|
function buildFeedbackNudge(args) {
|
|
@@ -19855,10 +20709,10 @@ function effectiveFeedbackPosture(config) {
|
|
|
19855
20709
|
return { posture: DEFAULT_FEEDBACK_POSTURE, source: "default" };
|
|
19856
20710
|
}
|
|
19857
20711
|
function loadFeedbackNudgeState() {
|
|
19858
|
-
if (!
|
|
20712
|
+
if (!existsSync6(FEEDBACK_NUDGES_FILE)) return { perDvm: {} };
|
|
19859
20713
|
try {
|
|
19860
20714
|
const parsed = JSON.parse(
|
|
19861
|
-
|
|
20715
|
+
readFileSync7(FEEDBACK_NUDGES_FILE, "utf-8")
|
|
19862
20716
|
);
|
|
19863
20717
|
return {
|
|
19864
20718
|
...typeof parsed.introShownAt === "string" ? { introShownAt: parsed.introShownAt } : {},
|
|
@@ -19947,12 +20801,12 @@ function coercePerDvm(perDvm) {
|
|
|
19947
20801
|
function saveState(state) {
|
|
19948
20802
|
ensureConfigDir();
|
|
19949
20803
|
const tmp = `${FEEDBACK_NUDGES_FILE}.${process.pid}.tmp`;
|
|
19950
|
-
|
|
20804
|
+
writeFileSync3(tmp, JSON.stringify(state, null, 2) + "\n", { mode: 384 });
|
|
19951
20805
|
try {
|
|
19952
20806
|
renameSync2(tmp, FEEDBACK_NUDGES_FILE);
|
|
19953
20807
|
} catch (err) {
|
|
19954
20808
|
try {
|
|
19955
|
-
|
|
20809
|
+
unlinkSync3(tmp);
|
|
19956
20810
|
} catch {
|
|
19957
20811
|
}
|
|
19958
20812
|
throw err;
|
|
@@ -19961,9 +20815,9 @@ function saveState(state) {
|
|
|
19961
20815
|
var nudgedThisInvocation = false;
|
|
19962
20816
|
|
|
19963
20817
|
// src/lib/platform.ts
|
|
19964
|
-
import { existsSync as
|
|
20818
|
+
import { existsSync as existsSync7, mkdirSync, readFileSync as readFileSync8, writeFileSync as writeFileSync4 } from "fs";
|
|
19965
20819
|
import { homedir } from "os";
|
|
19966
|
-
import { join as
|
|
20820
|
+
import { join as join7 } from "path";
|
|
19967
20821
|
function getPlatformUrl() {
|
|
19968
20822
|
return process.env.DVMKIT_PLATFORM_URL ?? "https://api.dvmkit.dev";
|
|
19969
20823
|
}
|
|
@@ -20532,16 +21386,16 @@ function finalizeProgressLine() {
|
|
|
20532
21386
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
20533
21387
|
import {
|
|
20534
21388
|
chmodSync,
|
|
20535
|
-
closeSync as
|
|
21389
|
+
closeSync as closeSync4,
|
|
20536
21390
|
mkdtempSync,
|
|
20537
|
-
openSync as
|
|
20538
|
-
readdirSync as
|
|
21391
|
+
openSync as openSync4,
|
|
21392
|
+
readdirSync as readdirSync5,
|
|
20539
21393
|
rmdirSync,
|
|
20540
|
-
unlinkSync as
|
|
20541
|
-
writeFileSync as
|
|
21394
|
+
unlinkSync as unlinkSync4,
|
|
21395
|
+
writeFileSync as writeFileSync5
|
|
20542
21396
|
} from "fs";
|
|
20543
21397
|
import { tmpdir } from "os";
|
|
20544
|
-
import { join as
|
|
21398
|
+
import { join as join8 } from "path";
|
|
20545
21399
|
|
|
20546
21400
|
// src/lib/mime-ext.ts
|
|
20547
21401
|
var MIME_TO_EXT = {
|
|
@@ -20597,11 +21451,11 @@ var ArtifactSaveSession = class {
|
|
|
20597
21451
|
let created = false;
|
|
20598
21452
|
try {
|
|
20599
21453
|
const directory = this.ensureDirectory();
|
|
20600
|
-
path =
|
|
20601
|
-
fd =
|
|
21454
|
+
path = join8(directory, `artifact-${randomBytes2(16).toString("hex")}.${ext}`);
|
|
21455
|
+
fd = openSync4(path, "wx", FILE_MODE);
|
|
20602
21456
|
created = true;
|
|
20603
|
-
|
|
20604
|
-
|
|
21457
|
+
writeFileSync5(fd, buf);
|
|
21458
|
+
closeSync4(fd);
|
|
20605
21459
|
fd = void 0;
|
|
20606
21460
|
chmodSync(path, FILE_MODE);
|
|
20607
21461
|
this.successfulWrites += 1;
|
|
@@ -20609,13 +21463,13 @@ var ArtifactSaveSession = class {
|
|
|
20609
21463
|
} catch (err) {
|
|
20610
21464
|
if (fd !== void 0) {
|
|
20611
21465
|
try {
|
|
20612
|
-
|
|
21466
|
+
closeSync4(fd);
|
|
20613
21467
|
} catch {
|
|
20614
21468
|
}
|
|
20615
21469
|
}
|
|
20616
21470
|
if (created && path) {
|
|
20617
21471
|
try {
|
|
20618
|
-
|
|
21472
|
+
unlinkSync4(path);
|
|
20619
21473
|
} catch {
|
|
20620
21474
|
}
|
|
20621
21475
|
}
|
|
@@ -20626,7 +21480,7 @@ var ArtifactSaveSession = class {
|
|
|
20626
21480
|
}
|
|
20627
21481
|
ensureDirectory() {
|
|
20628
21482
|
if (this.directory) return this.directory;
|
|
20629
|
-
const directory = mkdtempSync(
|
|
21483
|
+
const directory = mkdtempSync(join8(tmpdir(), "dvm-artifacts-"));
|
|
20630
21484
|
try {
|
|
20631
21485
|
chmodSync(directory, DIRECTORY_MODE);
|
|
20632
21486
|
} catch (err) {
|
|
@@ -20642,7 +21496,7 @@ var ArtifactSaveSession = class {
|
|
|
20642
21496
|
removeEmptyUnreportedDirectory() {
|
|
20643
21497
|
if (!this.directory || this.successfulWrites > 0) return;
|
|
20644
21498
|
try {
|
|
20645
|
-
if (
|
|
21499
|
+
if (readdirSync5(this.directory).length === 0) {
|
|
20646
21500
|
rmdirSync(this.directory);
|
|
20647
21501
|
this.directory = void 0;
|
|
20648
21502
|
}
|
|
@@ -21407,7 +22261,7 @@ function jsonParseErrorLine(jsonText, err) {
|
|
|
21407
22261
|
// src/lib/structured-input-hint.ts
|
|
21408
22262
|
function expectedFieldsFromSchema(schema) {
|
|
21409
22263
|
const props = schema.properties;
|
|
21410
|
-
if (!
|
|
22264
|
+
if (!isPlainObject2(props)) return [];
|
|
21411
22265
|
const requiredList = Array.isArray(schema.required) ? schema.required.filter((x) => typeof x === "string") : [];
|
|
21412
22266
|
const required = new Set(requiredList);
|
|
21413
22267
|
const out = [];
|
|
@@ -21448,11 +22302,11 @@ function buildStructuredInputHint(opts) {
|
|
|
21448
22302
|
if (nextAction) data.next_action = nextAction;
|
|
21449
22303
|
return { message: message2, hint, data };
|
|
21450
22304
|
}
|
|
21451
|
-
function
|
|
22305
|
+
function isPlainObject2(value) {
|
|
21452
22306
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21453
22307
|
}
|
|
21454
22308
|
function jsonSchemaType(node) {
|
|
21455
|
-
if (!
|
|
22309
|
+
if (!isPlainObject2(node)) return "unknown";
|
|
21456
22310
|
const t = node.type;
|
|
21457
22311
|
if (typeof t === "string") return t;
|
|
21458
22312
|
if (Array.isArray(t)) return t.filter((x) => typeof x === "string").join("|") || "unknown";
|
|
@@ -21530,16 +22384,16 @@ function findInputSchema(info2, capability) {
|
|
|
21530
22384
|
if (capability) {
|
|
21531
22385
|
const cap2 = info2.capabilities?.[capability];
|
|
21532
22386
|
if (cap2) {
|
|
21533
|
-
if (
|
|
21534
|
-
const quote2 =
|
|
21535
|
-
if (
|
|
22387
|
+
if (isPlainObject3(cap2.input_schema)) return cap2.input_schema;
|
|
22388
|
+
const quote2 = isPlainObject3(cap2.pricing) ? cap2.pricing.quote : void 0;
|
|
22389
|
+
if (isPlainObject3(quote2) && isPlainObject3(quote2.schema)) return quote2.schema;
|
|
21536
22390
|
}
|
|
21537
22391
|
}
|
|
21538
|
-
if (
|
|
21539
|
-
if (info2.quote &&
|
|
22392
|
+
if (isPlainObject3(info2.inputSchema)) return info2.inputSchema;
|
|
22393
|
+
if (info2.quote && isPlainObject3(info2.quote.schema)) return info2.quote.schema;
|
|
21540
22394
|
return void 0;
|
|
21541
22395
|
}
|
|
21542
|
-
function
|
|
22396
|
+
function isPlainObject3(value) {
|
|
21543
22397
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21544
22398
|
}
|
|
21545
22399
|
|
|
@@ -22088,7 +22942,7 @@ function buildPolicy(opts, btcRate) {
|
|
|
22088
22942
|
}
|
|
22089
22943
|
|
|
22090
22944
|
// src/commands/request.ts
|
|
22091
|
-
import { createHash as
|
|
22945
|
+
import { createHash as createHash3, randomUUID as randomUUID4 } from "crypto";
|
|
22092
22946
|
|
|
22093
22947
|
// src/lib/credit-defer.ts
|
|
22094
22948
|
function noteDeferredFunding(funding) {
|
|
@@ -22121,7 +22975,7 @@ async function settleCreditAfterJob(args) {
|
|
|
22121
22975
|
}
|
|
22122
22976
|
}
|
|
22123
22977
|
if (args.allowTopup !== false) {
|
|
22124
|
-
const refill = args.refillPocket ?? (await import("./pocket-refill-
|
|
22978
|
+
const refill = args.refillPocket ?? (await import("./pocket-refill-BHNKMENF.js")).refillPocketIfLow;
|
|
22125
22979
|
await refill({ human: args.human }).catch(() => void 0);
|
|
22126
22980
|
}
|
|
22127
22981
|
}
|
|
@@ -22602,16 +23456,16 @@ function dollarLimitMicro(declaredLimit) {
|
|
|
22602
23456
|
|
|
22603
23457
|
// src/lib/request-intent-store.ts
|
|
22604
23458
|
import {
|
|
22605
|
-
closeSync as
|
|
22606
|
-
existsSync as
|
|
22607
|
-
fsyncSync as
|
|
23459
|
+
closeSync as closeSync5,
|
|
23460
|
+
existsSync as existsSync8,
|
|
23461
|
+
fsyncSync as fsyncSync3,
|
|
22608
23462
|
mkdirSync as mkdirSync2,
|
|
22609
|
-
openSync as
|
|
22610
|
-
readFileSync as
|
|
23463
|
+
openSync as openSync5,
|
|
23464
|
+
readFileSync as readFileSync9,
|
|
22611
23465
|
renameSync as renameSync3,
|
|
22612
|
-
writeFileSync as
|
|
23466
|
+
writeFileSync as writeFileSync6
|
|
22613
23467
|
} from "fs";
|
|
22614
|
-
import { join as
|
|
23468
|
+
import { join as join9 } from "path";
|
|
22615
23469
|
function saveRequestIntent(intent) {
|
|
22616
23470
|
assertRequestId(intent.requestId);
|
|
22617
23471
|
assertNoPaymentOrAuthSecrets(intent.body);
|
|
@@ -22623,27 +23477,27 @@ function saveRequestIntent(intent) {
|
|
|
22623
23477
|
if (error.code === "EEXIST") return false;
|
|
22624
23478
|
throw error;
|
|
22625
23479
|
}
|
|
22626
|
-
|
|
22627
|
-
const temp =
|
|
22628
|
-
const target =
|
|
22629
|
-
const fd =
|
|
23480
|
+
fsyncDirectory3(REQUEST_INTENTS_DIR);
|
|
23481
|
+
const temp = join9(dir, `intent.${String(process.pid)}.tmp`);
|
|
23482
|
+
const target = join9(dir, "intent.json");
|
|
23483
|
+
const fd = openSync5(temp, "wx", 384);
|
|
22630
23484
|
try {
|
|
22631
|
-
|
|
22632
|
-
|
|
23485
|
+
writeFileSync6(fd, JSON.stringify(intent, null, 2) + "\n");
|
|
23486
|
+
fsyncSync3(fd);
|
|
22633
23487
|
} finally {
|
|
22634
|
-
|
|
23488
|
+
closeSync5(fd);
|
|
22635
23489
|
}
|
|
22636
23490
|
renameSync3(temp, target);
|
|
22637
|
-
|
|
23491
|
+
fsyncDirectory3(dir);
|
|
22638
23492
|
return true;
|
|
22639
23493
|
}
|
|
22640
23494
|
function loadRequestIntent(requestId) {
|
|
22641
23495
|
assertRequestId(requestId);
|
|
22642
23496
|
const dir = intentDirectory(requestId);
|
|
22643
|
-
if (!
|
|
22644
|
-
const path =
|
|
23497
|
+
if (!existsSync8(dir)) return null;
|
|
23498
|
+
const path = join9(dir, "intent.json");
|
|
22645
23499
|
try {
|
|
22646
|
-
const parsed = JSON.parse(
|
|
23500
|
+
const parsed = JSON.parse(readFileSync9(path, "utf8"));
|
|
22647
23501
|
if (!isRequestIntent(parsed) || parsed.requestId !== requestId)
|
|
22648
23502
|
throw new Error("invalid shape");
|
|
22649
23503
|
return parsed;
|
|
@@ -22693,15 +23547,15 @@ function assertRequestId(requestId) {
|
|
|
22693
23547
|
);
|
|
22694
23548
|
}
|
|
22695
23549
|
function intentDirectory(requestId) {
|
|
22696
|
-
return
|
|
23550
|
+
return join9(REQUEST_INTENTS_DIR, requestId);
|
|
22697
23551
|
}
|
|
22698
|
-
function
|
|
23552
|
+
function fsyncDirectory3(path) {
|
|
22699
23553
|
let fd;
|
|
22700
23554
|
try {
|
|
22701
|
-
fd =
|
|
22702
|
-
|
|
23555
|
+
fd = openSync5(path, "r");
|
|
23556
|
+
fsyncSync3(fd);
|
|
22703
23557
|
} finally {
|
|
22704
|
-
if (fd !== void 0)
|
|
23558
|
+
if (fd !== void 0) closeSync5(fd);
|
|
22705
23559
|
}
|
|
22706
23560
|
}
|
|
22707
23561
|
function isRequestIntent(value) {
|
|
@@ -23248,77 +24102,56 @@ async function request(opts) {
|
|
|
23248
24102
|
bidMsats: budgetMsats
|
|
23249
24103
|
});
|
|
23250
24104
|
if (opts.requestId) {
|
|
23251
|
-
|
|
23252
|
-
if (!signing || unsigned?.pubkey !== signing.pubkey) {
|
|
23253
|
-
transport.close();
|
|
23254
|
-
throw new DvmError(
|
|
23255
|
-
"request_intent_invalid",
|
|
23256
|
-
"Could not persist an authenticated recovery intent.",
|
|
23257
|
-
"No payment was attempted. Check the selected caller identity and retry with a fresh request id."
|
|
23258
|
-
);
|
|
23259
|
-
}
|
|
23260
|
-
const body = envelopeToPayload(envelope);
|
|
23261
|
-
body.data = unsigned.body;
|
|
23262
|
-
const saved = saveRequestIntent({
|
|
23263
|
-
v: 2,
|
|
24105
|
+
persistRequestIntent({
|
|
23264
24106
|
requestId: opts.requestId,
|
|
24107
|
+
transport,
|
|
24108
|
+
envelope,
|
|
24109
|
+
signing,
|
|
23265
24110
|
endpoint,
|
|
23266
|
-
|
|
23267
|
-
capability,
|
|
23268
|
-
body,
|
|
23269
|
-
callerPubkey: signing.pubkey,
|
|
24111
|
+
identity,
|
|
23270
24112
|
policy,
|
|
23271
|
-
|
|
23272
|
-
|
|
23273
|
-
...requestedMaxCashuFeeSats !== void 0 ? { maxCashuFeeSats: requestedMaxCashuFeeSats } : {},
|
|
23274
|
-
...receiptTrustFields(providerInfo),
|
|
23275
|
-
authAudience: signing.domain.audience,
|
|
23276
|
-
createdAt: Date.now()
|
|
24113
|
+
opts,
|
|
24114
|
+
providerInfo
|
|
23277
24115
|
});
|
|
23278
|
-
if (!saved) {
|
|
23279
|
-
transport.close();
|
|
23280
|
-
throw new DvmError(
|
|
23281
|
-
"request_id_exists",
|
|
23282
|
-
`Request id ${opts.requestId} already has a local intent.`,
|
|
23283
|
-
`Run 'dvm request-result ${opts.requestId}'. Never submit or pay for a replacement under the same id.`,
|
|
23284
|
-
{ request_id: opts.requestId, status: "unknown" }
|
|
23285
|
-
);
|
|
23286
|
-
}
|
|
23287
24116
|
}
|
|
23288
24117
|
progressNotice("Publishing job request...", opts.human);
|
|
23289
24118
|
const usedPrimitiveInput = !!opts.input && !opts.data && !hasParams;
|
|
23290
|
-
const submitProbe = (env) =>
|
|
23291
|
-
|
|
23292
|
-
|
|
23293
|
-
|
|
23294
|
-
|
|
23295
|
-
|
|
23296
|
-
|
|
23297
|
-
|
|
23298
|
-
|
|
23299
|
-
|
|
23300
|
-
|
|
23301
|
-
|
|
23302
|
-
|
|
23303
|
-
|
|
23304
|
-
|
|
23305
|
-
|
|
24119
|
+
const submitProbe = async (env) => {
|
|
24120
|
+
try {
|
|
24121
|
+
return await withInputSchemaHint(
|
|
24122
|
+
transport,
|
|
24123
|
+
ref,
|
|
24124
|
+
{
|
|
24125
|
+
capability,
|
|
24126
|
+
identifier,
|
|
24127
|
+
command: "request",
|
|
24128
|
+
usedPrimitiveInput,
|
|
24129
|
+
primitiveInput: opts.input,
|
|
24130
|
+
callerRef,
|
|
24131
|
+
callerFlag: opts.dvm ? "dvm" : "endpoint"
|
|
24132
|
+
},
|
|
24133
|
+
() => transport.submit(ref, env, void 0, {
|
|
24134
|
+
timeoutMs: noStream ? 0 : timeout
|
|
24135
|
+
})
|
|
24136
|
+
);
|
|
24137
|
+
} catch (err) {
|
|
24138
|
+
if (!isIdentityFailure(err)) throw err;
|
|
24139
|
+
throw recordIdentityFailure(err, {
|
|
24140
|
+
endpoint,
|
|
24141
|
+
...dvmId ? { dvmId } : {},
|
|
24142
|
+
capability,
|
|
24143
|
+
...opts.requestId ? { publicRequestId: opts.requestId } : {},
|
|
24144
|
+
...probeRailEvidence(env)
|
|
24145
|
+
}).error;
|
|
24146
|
+
}
|
|
24147
|
+
};
|
|
23306
24148
|
let receipt;
|
|
23307
24149
|
try {
|
|
23308
24150
|
receipt = await submitProbe(envelope);
|
|
23309
24151
|
} catch (err) {
|
|
23310
24152
|
if (opts.requestId) {
|
|
23311
24153
|
transport.close();
|
|
23312
|
-
throw
|
|
23313
|
-
"request_outcome_unknown",
|
|
23314
|
-
`The provider did not return a definitive result for request ${opts.requestId}.`,
|
|
23315
|
-
`Run 'dvm request-result ${opts.requestId}'. This lookup cannot submit a job or repeat a payment.`,
|
|
23316
|
-
{
|
|
23317
|
-
request_id: opts.requestId,
|
|
23318
|
-
status: "unknown",
|
|
23319
|
-
cause: err instanceof Error ? err.message : String(err)
|
|
23320
|
-
}
|
|
23321
|
-
);
|
|
24154
|
+
throw requestOutcomeUnknown(opts.requestId, err);
|
|
23322
24155
|
}
|
|
23323
24156
|
if (opts.creditOnly) throw err;
|
|
23324
24157
|
if (probePlan.mode !== "draw" || !signing || !(err instanceof DvmError)) throw err;
|
|
@@ -23629,7 +24462,7 @@ function identityArgs(identity) {
|
|
|
23629
24462
|
return identity ? { identity } : {};
|
|
23630
24463
|
}
|
|
23631
24464
|
function sha256Hex(value) {
|
|
23632
|
-
return
|
|
24465
|
+
return createHash3("sha256").update(value, "utf8").digest("hex");
|
|
23633
24466
|
}
|
|
23634
24467
|
async function fetchServerPriceMicro(transport, ref, envelope) {
|
|
23635
24468
|
try {
|
|
@@ -23782,7 +24615,7 @@ async function recoverDrawProbe(err, args) {
|
|
|
23782
24615
|
const plan = {
|
|
23783
24616
|
mode: "draw",
|
|
23784
24617
|
creditId: args.probePlan.creditId,
|
|
23785
|
-
drawId:
|
|
24618
|
+
drawId: randomUUID4(),
|
|
23786
24619
|
...args.probePlan.source ? { source: args.probePlan.source } : {}
|
|
23787
24620
|
};
|
|
23788
24621
|
const env = reSign({ credit_id: plan.creditId, draw_id: plan.drawId });
|
|
@@ -24062,62 +24895,96 @@ async function handleAutoPayQuotes(transport, ref, envelope, jobId, deadlineMs,
|
|
|
24062
24895
|
info("Credit funding is Cashu-only for now \u2014 paying per-call on the selected rail.");
|
|
24063
24896
|
plan = { mode: "none" };
|
|
24064
24897
|
}
|
|
24898
|
+
let railEnvelope = plainEnvelope;
|
|
24899
|
+
let railOpts = opts;
|
|
24900
|
+
let railSigning = creditCtx?.signing;
|
|
24901
|
+
let generatedRequestId;
|
|
24902
|
+
if (railSigning && perCallSubmitCanCarryRecoveryRequestId({ plan, opts, providerInfo, signing: railSigning })) {
|
|
24903
|
+
generatedRequestId = randomUUID4();
|
|
24904
|
+
railSigning = {
|
|
24905
|
+
...railSigning,
|
|
24906
|
+
unsignedData: { ...railSigning.unsignedData, request_id: generatedRequestId }
|
|
24907
|
+
};
|
|
24908
|
+
railEnvelope = {
|
|
24909
|
+
...plainEnvelope,
|
|
24910
|
+
data: signDvmRequestData(railSigning.privkey, railSigning.unsignedData, railSigning.domain)
|
|
24911
|
+
};
|
|
24912
|
+
railOpts = { ...opts, requestId: generatedRequestId };
|
|
24913
|
+
persistRequestIntent({
|
|
24914
|
+
requestId: generatedRequestId,
|
|
24915
|
+
transport,
|
|
24916
|
+
envelope: railEnvelope,
|
|
24917
|
+
signing: railSigning,
|
|
24918
|
+
endpoint: ref.endpoint,
|
|
24919
|
+
identity,
|
|
24920
|
+
policy,
|
|
24921
|
+
opts: railOpts,
|
|
24922
|
+
providerInfo
|
|
24923
|
+
});
|
|
24924
|
+
}
|
|
24065
24925
|
let cashuFellThroughCode;
|
|
24066
|
-
|
|
24067
|
-
|
|
24068
|
-
|
|
24069
|
-
|
|
24070
|
-
|
|
24071
|
-
|
|
24072
|
-
|
|
24073
|
-
|
|
24074
|
-
|
|
24075
|
-
|
|
24076
|
-
|
|
24077
|
-
|
|
24078
|
-
|
|
24079
|
-
|
|
24080
|
-
|
|
24081
|
-
|
|
24082
|
-
|
|
24083
|
-
|
|
24084
|
-
|
|
24085
|
-
|
|
24086
|
-
|
|
24087
|
-
|
|
24088
|
-
|
|
24089
|
-
|
|
24090
|
-
|
|
24091
|
-
|
|
24092
|
-
|
|
24093
|
-
|
|
24094
|
-
|
|
24095
|
-
|
|
24096
|
-
|
|
24097
|
-
|
|
24098
|
-
|
|
24099
|
-
|
|
24100
|
-
|
|
24101
|
-
|
|
24102
|
-
|
|
24103
|
-
|
|
24104
|
-
|
|
24105
|
-
|
|
24106
|
-
|
|
24107
|
-
|
|
24108
|
-
|
|
24109
|
-
|
|
24110
|
-
|
|
24111
|
-
|
|
24112
|
-
|
|
24113
|
-
|
|
24114
|
-
|
|
24115
|
-
|
|
24116
|
-
|
|
24117
|
-
|
|
24118
|
-
|
|
24119
|
-
|
|
24926
|
+
try {
|
|
24927
|
+
for (const rail of selection.rails) {
|
|
24928
|
+
if (rail === "cashu_p2pk") {
|
|
24929
|
+
const outcome = await tryAgentWalletPayment(
|
|
24930
|
+
transport,
|
|
24931
|
+
ref,
|
|
24932
|
+
railEnvelope,
|
|
24933
|
+
jobId,
|
|
24934
|
+
deadlineMs,
|
|
24935
|
+
chosen,
|
|
24936
|
+
railOpts,
|
|
24937
|
+
identity,
|
|
24938
|
+
policy,
|
|
24939
|
+
upfrontBtcRate,
|
|
24940
|
+
providerInfo,
|
|
24941
|
+
plan,
|
|
24942
|
+
railSigning
|
|
24943
|
+
);
|
|
24944
|
+
if (outcome.handled) return;
|
|
24945
|
+
cashuFellThroughCode = outcome.fellThroughCode ?? cashuFellThroughCode;
|
|
24946
|
+
} else if (rail === "tempo" && tempoAccount) {
|
|
24947
|
+
const handled = await tryTempoPayment({
|
|
24948
|
+
transport,
|
|
24949
|
+
ref,
|
|
24950
|
+
envelope: railEnvelope,
|
|
24951
|
+
jobId,
|
|
24952
|
+
deadlineMs,
|
|
24953
|
+
chosen,
|
|
24954
|
+
quotes,
|
|
24955
|
+
opts: railOpts,
|
|
24956
|
+
identity,
|
|
24957
|
+
policy,
|
|
24958
|
+
btcRate: upfrontBtcRate,
|
|
24959
|
+
account: tempoAccount,
|
|
24960
|
+
providerInfo,
|
|
24961
|
+
signing: railSigning
|
|
24962
|
+
});
|
|
24963
|
+
if (handled) return;
|
|
24964
|
+
} else if (rail === "x402" && x402Wallet) {
|
|
24965
|
+
const handled = await tryX402UpfrontPayment({
|
|
24966
|
+
transport,
|
|
24967
|
+
ref,
|
|
24968
|
+
envelope: railEnvelope,
|
|
24969
|
+
jobId,
|
|
24970
|
+
deadlineMs,
|
|
24971
|
+
chosen,
|
|
24972
|
+
opts: railOpts,
|
|
24973
|
+
identity,
|
|
24974
|
+
policy,
|
|
24975
|
+
btcRate: upfrontBtcRate,
|
|
24976
|
+
wallet: x402Wallet,
|
|
24977
|
+
providerInfo,
|
|
24978
|
+
signing: railSigning
|
|
24979
|
+
});
|
|
24980
|
+
if (handled) return;
|
|
24981
|
+
}
|
|
24982
|
+
}
|
|
24983
|
+
} catch (error) {
|
|
24984
|
+
if (generatedRequestId && leavesOutcomeUnknown(error)) {
|
|
24985
|
+
throw requestOutcomeUnknown(generatedRequestId, error);
|
|
24120
24986
|
}
|
|
24987
|
+
throw error;
|
|
24121
24988
|
}
|
|
24122
24989
|
transport.close?.();
|
|
24123
24990
|
if (cashuFellThroughCode && agentWallet) {
|
|
@@ -24284,12 +25151,44 @@ async function payWithTempo(args, credential) {
|
|
|
24284
25151
|
display: `Paying ${priceLabel} via Tempo (account ${accountShort}).`
|
|
24285
25152
|
});
|
|
24286
25153
|
}
|
|
24287
|
-
|
|
24288
|
-
|
|
24289
|
-
|
|
24290
|
-
|
|
24291
|
-
|
|
24292
|
-
|
|
25154
|
+
let receipt;
|
|
25155
|
+
try {
|
|
25156
|
+
receipt = await transport.submit(
|
|
25157
|
+
ref,
|
|
25158
|
+
envelope,
|
|
25159
|
+
{ mppCredential: credential },
|
|
25160
|
+
{ timeoutMs: paidSubmitTimeoutMs(args.deadlineMs) }
|
|
25161
|
+
);
|
|
25162
|
+
} catch (err) {
|
|
25163
|
+
const unconfirmed = (key) => recordUnconfirmedSpend({
|
|
25164
|
+
msats: paidMsats,
|
|
25165
|
+
btcRate,
|
|
25166
|
+
key,
|
|
25167
|
+
endpoint: ref.endpoint,
|
|
25168
|
+
capability: identity.capability
|
|
25169
|
+
});
|
|
25170
|
+
if (!isIdentityFailure(err)) {
|
|
25171
|
+
if (leavesOutcomeUnknown(raisedAfterPayment(err))) {
|
|
25172
|
+
unconfirmed(unconfirmedSpendKey(opts, err));
|
|
25173
|
+
}
|
|
25174
|
+
throw err;
|
|
25175
|
+
}
|
|
25176
|
+
transport.close?.();
|
|
25177
|
+
const { error } = recordIdentityFailure(err, {
|
|
25178
|
+
endpoint: ref.endpoint,
|
|
25179
|
+
...identity.dvmId ? { dvmId: identity.dvmId } : {},
|
|
25180
|
+
capability: identity.capability,
|
|
25181
|
+
...opts.requestId ? { publicRequestId: opts.requestId } : {},
|
|
25182
|
+
rail: "tempo",
|
|
25183
|
+
railCorrelation: {
|
|
25184
|
+
account: account.address,
|
|
25185
|
+
amount_usdc_micro: usdcMicroUnits,
|
|
25186
|
+
...err.observation.transactionHash ? { transaction_hash: err.observation.transactionHash } : {}
|
|
25187
|
+
}
|
|
25188
|
+
});
|
|
25189
|
+
unconfirmed(unconfirmedSpendKey(opts, error));
|
|
25190
|
+
throw error;
|
|
25191
|
+
}
|
|
24293
25192
|
const effectiveJobId = args.jobId || receipt.jobId;
|
|
24294
25193
|
if (!args.jobId && receipt.jobId) {
|
|
24295
25194
|
saveJob({
|
|
@@ -24419,6 +25318,82 @@ function transactionOutputFields(receipt) {
|
|
|
24419
25318
|
...receipt.transactionHash ? { transaction_hash: receipt.transactionHash } : {}
|
|
24420
25319
|
};
|
|
24421
25320
|
}
|
|
25321
|
+
function persistRequestIntent(args) {
|
|
25322
|
+
const { requestId, transport, signing, opts } = args;
|
|
25323
|
+
const unsigned = unsignRequestData(args.envelope.data);
|
|
25324
|
+
if (!signing || unsigned?.pubkey !== signing.pubkey) {
|
|
25325
|
+
transport.close?.();
|
|
25326
|
+
throw new DvmError(
|
|
25327
|
+
"request_intent_invalid",
|
|
25328
|
+
"Could not persist an authenticated recovery intent.",
|
|
25329
|
+
"No payment was attempted. Check the selected caller identity and retry with a fresh request id."
|
|
25330
|
+
);
|
|
25331
|
+
}
|
|
25332
|
+
const body = envelopeToPayload(args.envelope);
|
|
25333
|
+
body.data = unsigned.body;
|
|
25334
|
+
const maxCashuFeeSats = parseMaxCashuFeeSats(opts.maxCashuFeeSats);
|
|
25335
|
+
const saved = saveRequestIntent({
|
|
25336
|
+
v: 2,
|
|
25337
|
+
requestId,
|
|
25338
|
+
endpoint: args.endpoint,
|
|
25339
|
+
...args.identity.dvmId ? { dvmId: args.identity.dvmId } : {},
|
|
25340
|
+
capability: args.identity.capability,
|
|
25341
|
+
body,
|
|
25342
|
+
callerPubkey: signing.pubkey,
|
|
25343
|
+
policy: args.policy,
|
|
25344
|
+
...opts.mint ? { pinnedMint: opts.mint } : {},
|
|
25345
|
+
...opts.strictPerCall ? { strictPerCall: true } : {},
|
|
25346
|
+
...maxCashuFeeSats !== void 0 ? { maxCashuFeeSats } : {},
|
|
25347
|
+
...receiptTrustFields(args.providerInfo),
|
|
25348
|
+
authAudience: signing.domain.audience,
|
|
25349
|
+
createdAt: Date.now()
|
|
25350
|
+
});
|
|
25351
|
+
if (!saved) {
|
|
25352
|
+
transport.close?.();
|
|
25353
|
+
throw new DvmError(
|
|
25354
|
+
"request_id_exists",
|
|
25355
|
+
`Request id ${requestId} already has a local intent.`,
|
|
25356
|
+
`Run 'dvm request-result ${requestId}'. Never submit or pay for a replacement under the same id.`,
|
|
25357
|
+
{ request_id: requestId, status: "unknown" }
|
|
25358
|
+
);
|
|
25359
|
+
}
|
|
25360
|
+
}
|
|
25361
|
+
function perCallSubmitCanCarryRecoveryRequestId(args) {
|
|
25362
|
+
return args.plan.mode === "none" && args.opts.requestId === void 0 && args.opts.creditOnly === void 0 && args.providerInfo.requestRecovery === true && args.providerInfo.auth?.includes(SIGNED_REQUEST_AUTH_ID) === true && args.signing !== void 0;
|
|
25363
|
+
}
|
|
25364
|
+
function leavesOutcomeUnknown(err) {
|
|
25365
|
+
if (isIdentityFailure(err)) return true;
|
|
25366
|
+
return err instanceof DvmError && postPaymentErrors.has(err) && POST_PAYMENT_UNKNOWN_CODES.has(err.code);
|
|
25367
|
+
}
|
|
25368
|
+
var POST_PAYMENT_UNKNOWN_CODES = /* @__PURE__ */ new Set(["timeout", "provider_unreachable", "request_id_exists"]);
|
|
25369
|
+
var postPaymentErrors = /* @__PURE__ */ new WeakSet();
|
|
25370
|
+
function raisedAfterPayment(err) {
|
|
25371
|
+
if (err !== null && typeof err === "object") postPaymentErrors.add(err);
|
|
25372
|
+
return err;
|
|
25373
|
+
}
|
|
25374
|
+
function recordUnconfirmedSpend(args) {
|
|
25375
|
+
recordSpendOnce({
|
|
25376
|
+
msats: args.msats,
|
|
25377
|
+
btcRate: args.btcRate,
|
|
25378
|
+
jobId: args.key ?? `unconfirmed-${randomUUID4()}`,
|
|
25379
|
+
providerEndpoint: args.endpoint,
|
|
25380
|
+
label: `unconfirmed \xB7 ${args.capability}`
|
|
25381
|
+
});
|
|
25382
|
+
}
|
|
25383
|
+
function unconfirmedSpendKey(opts, err) {
|
|
25384
|
+
if (opts.requestId) return opts.requestId;
|
|
25385
|
+
return typeof err.data?.ambiguity_id === "string" ? err.data.ambiguity_id : void 0;
|
|
25386
|
+
}
|
|
25387
|
+
function probeRailEvidence(env) {
|
|
25388
|
+
const body = unsignRequestData(env.data)?.body;
|
|
25389
|
+
const creditId = typeof body?.credit_id === "string" ? body.credit_id : void 0;
|
|
25390
|
+
const drawId = typeof body?.draw_id === "string" ? body.draw_id : void 0;
|
|
25391
|
+
if (!creditId) return { rail: "none" };
|
|
25392
|
+
return {
|
|
25393
|
+
rail: "credit",
|
|
25394
|
+
railCorrelation: { credit_id: creditId, ...drawId ? { draw_id: drawId } : {} }
|
|
25395
|
+
};
|
|
25396
|
+
}
|
|
24422
25397
|
function requestIdOutputFields(opts) {
|
|
24423
25398
|
return opts.requestId ? { request_id: opts.requestId } : {};
|
|
24424
25399
|
}
|
|
@@ -24426,14 +25401,33 @@ function normalizedLocalCorrelationId(opts) {
|
|
|
24426
25401
|
return opts.localCorrelationId === void 0 ? void 0 : normalizeLocalCorrelationId(opts.localCorrelationId);
|
|
24427
25402
|
}
|
|
24428
25403
|
function requestOutcomeUnknown(requestId, cause) {
|
|
25404
|
+
const ambiguityId = isIdentityFailure(cause) && typeof cause.data?.ambiguity_id === "string" ? cause.data.ambiguity_id : void 0;
|
|
24429
25405
|
return new DvmError(
|
|
24430
25406
|
"request_outcome_unknown",
|
|
24431
25407
|
`The provider did not return a definitive result for request ${requestId}.`,
|
|
24432
|
-
`Run 'dvm request-result ${requestId}'. This lookup cannot submit a job or repeat a payment
|
|
25408
|
+
`Run 'dvm request-result ${requestId}'. This lookup cannot submit a job or repeat a payment.${ambiguityId ? ` Do not pay for this request again; 'dvm wallet submissions' shows the recorded evidence (${ambiguityId}).` : ""}`,
|
|
24433
25409
|
{
|
|
24434
25410
|
request_id: requestId,
|
|
24435
25411
|
status: "unknown",
|
|
24436
|
-
cause: cause instanceof Error ? cause.message : String(cause)
|
|
25412
|
+
cause: cause instanceof Error ? cause.message : String(cause),
|
|
25413
|
+
...cause instanceof DvmError ? { inner_code: cause.code } : {},
|
|
25414
|
+
...isIdentityFailure(cause) ? {
|
|
25415
|
+
identity_kind: cause.observation.kind,
|
|
25416
|
+
...identityDataFields(cause.observation),
|
|
25417
|
+
...ambiguityId ? { ambiguity_id: ambiguityId } : {},
|
|
25418
|
+
...typeof cause.data?.cashu_request_id === "string" ? { cashu_request_id: cause.data.cashu_request_id } : {},
|
|
25419
|
+
claim_stored: false
|
|
25420
|
+
} : {},
|
|
25421
|
+
// A Cashu payment already sent is held in the wallet journal under its
|
|
25422
|
+
// own request ID; keep that context rather than letting the public ID
|
|
25423
|
+
// replace it.
|
|
25424
|
+
...cause instanceof DvmError && cause.data?.spend_committed === true ? {
|
|
25425
|
+
spend_committed: true,
|
|
25426
|
+
...typeof cause.data.cashu_request_id === "string" ? { cashu_request_id: cause.data.cashu_request_id } : {},
|
|
25427
|
+
...typeof cause.data.mint === "string" ? { mint: cause.data.mint } : {},
|
|
25428
|
+
...typeof cause.data.amount_sats === "number" ? { amount_sats: cause.data.amount_sats } : {},
|
|
25429
|
+
...typeof cause.data.display === "string" ? { display: cause.data.display } : {}
|
|
25430
|
+
} : {}
|
|
24437
25431
|
}
|
|
24438
25432
|
);
|
|
24439
25433
|
}
|
|
@@ -24624,28 +25618,32 @@ function resumableSubmitBody(envelope, providerInfo) {
|
|
|
24624
25618
|
if (!signed) return { submit_body: payload };
|
|
24625
25619
|
return { submit_body: { ...payload, data: signed.body }, signing_pubkey: signed.pubkey };
|
|
24626
25620
|
}
|
|
24627
|
-
function withSpentSpendContext(err, prepared) {
|
|
25621
|
+
function withSpentSpendContext(err, prepared, publicRequestId) {
|
|
24628
25622
|
if (!(err instanceof DvmError) || err.code === "payment_invalid") return err;
|
|
24629
25623
|
const held = `${prepared.totalSats} sats`;
|
|
24630
25624
|
const proseSources = {
|
|
24631
25625
|
...err.proseSources?.message === "provider" ? { message: "provider" } : {},
|
|
24632
25626
|
...err.proseSources?.hint === "provider" ? { hint: "provider" } : {}
|
|
24633
25627
|
};
|
|
24634
|
-
|
|
24635
|
-
|
|
24636
|
-
|
|
24637
|
-
|
|
24638
|
-
|
|
24639
|
-
|
|
24640
|
-
|
|
24641
|
-
|
|
24642
|
-
|
|
24643
|
-
|
|
24644
|
-
|
|
24645
|
-
|
|
24646
|
-
|
|
24647
|
-
|
|
24648
|
-
|
|
25628
|
+
const requestId = publicRequestId ?? prepared.requestId;
|
|
25629
|
+
return raisedAfterPayment(
|
|
25630
|
+
new DvmError(
|
|
25631
|
+
err.code,
|
|
25632
|
+
`${err.message} The ${held} payment was already sent \u2014 it is held against request ${requestId}, not lost.`,
|
|
25633
|
+
err.hint,
|
|
25634
|
+
{
|
|
25635
|
+
...err.data,
|
|
25636
|
+
spend_committed: true,
|
|
25637
|
+
request_id: requestId,
|
|
25638
|
+
cashu_request_id: prepared.requestId,
|
|
25639
|
+
endpoint: prepared.endpoint,
|
|
25640
|
+
mint: prepared.mint,
|
|
25641
|
+
amount_sats: prepared.totalSats,
|
|
25642
|
+
display: publicRequestId ? `Your wallet paid ${held} but the provider never confirmed. Your next call reads request ${publicRequestId} back from the provider without paying again \u2014 check 'dvm wallet show'.` : `Your wallet paid ${held} but the provider never confirmed. The payment is held against this request and will be retried automatically on your next call \u2014 check 'dvm wallet show'.`
|
|
25643
|
+
},
|
|
25644
|
+
void 0,
|
|
25645
|
+
Object.keys(proseSources).length > 0 ? proseSources : void 0
|
|
25646
|
+
)
|
|
24649
25647
|
);
|
|
24650
25648
|
}
|
|
24651
25649
|
function expectedFundMicro(err) {
|
|
@@ -24696,6 +25694,29 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
|
|
|
24696
25694
|
);
|
|
24697
25695
|
break;
|
|
24698
25696
|
} catch (err) {
|
|
25697
|
+
if (isIdentityFailure(err)) {
|
|
25698
|
+
transport.close?.();
|
|
25699
|
+
const { error, record } = recordIdentityFailure(err, {
|
|
25700
|
+
endpoint: ref.endpoint,
|
|
25701
|
+
...identity.dvmId ? { dvmId: identity.dvmId } : {},
|
|
25702
|
+
capability: identity.capability,
|
|
25703
|
+
...opts.requestId ? { publicRequestId: opts.requestId } : {},
|
|
25704
|
+
cashuRequestId: prepared.requestId,
|
|
25705
|
+
rail: "cashu",
|
|
25706
|
+
railCorrelation: {
|
|
25707
|
+
mint: prepared.mint,
|
|
25708
|
+
amount_sats: prepared.totalSats,
|
|
25709
|
+
...fundPlan ? { credit_id: fundPlan.creditId, draw_id: fundPlan.drawId } : {}
|
|
25710
|
+
}
|
|
25711
|
+
});
|
|
25712
|
+
if (record) {
|
|
25713
|
+
await markPendingSubmissionUnresolved({
|
|
25714
|
+
requestId: prepared.requestId,
|
|
25715
|
+
marker: journalMarkerFor(record)
|
|
25716
|
+
});
|
|
25717
|
+
}
|
|
25718
|
+
throw error;
|
|
25719
|
+
}
|
|
24699
25720
|
const signedMicro = fundPlan ? fundPlan.wireAmountMicro ?? fundPlan.fundMicro : void 0;
|
|
24700
25721
|
const expected = !correctedOnce && fundPlan && signing ? expectedFundMicro(err) : void 0;
|
|
24701
25722
|
if (expected !== void 0 && expected !== signedMicro && fundPlan && signing) {
|
|
@@ -24726,7 +25747,7 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
|
|
|
24726
25747
|
await abandonPendingSubmission({ requestId: prepared.requestId });
|
|
24727
25748
|
}
|
|
24728
25749
|
transport.close?.();
|
|
24729
|
-
throw withSpentSpendContext(err, prepared);
|
|
25750
|
+
throw withSpentSpendContext(err, prepared, opts.requestId);
|
|
24730
25751
|
}
|
|
24731
25752
|
}
|
|
24732
25753
|
if (receipt.status === "payment-required") {
|
|
@@ -24949,12 +25970,43 @@ async function payWithX402(args, proof) {
|
|
|
24949
25970
|
display: `Paying ${priceLabel} via x402 (account ${addressShort}).`
|
|
24950
25971
|
});
|
|
24951
25972
|
}
|
|
24952
|
-
|
|
24953
|
-
|
|
24954
|
-
|
|
24955
|
-
|
|
24956
|
-
|
|
24957
|
-
|
|
25973
|
+
let receipt;
|
|
25974
|
+
try {
|
|
25975
|
+
receipt = await transport.submit(
|
|
25976
|
+
ref,
|
|
25977
|
+
envelope,
|
|
25978
|
+
{ x402Payment: proof.paymentHeader, x402Version: proof.x402Version },
|
|
25979
|
+
{ timeoutMs: paidSubmitTimeoutMs(args.deadlineMs) }
|
|
25980
|
+
);
|
|
25981
|
+
} catch (err) {
|
|
25982
|
+
const unconfirmed = (key) => recordUnconfirmedSpend({
|
|
25983
|
+
msats: proof.amountMsats,
|
|
25984
|
+
btcRate: proof.btcRate,
|
|
25985
|
+
key,
|
|
25986
|
+
endpoint: ref.endpoint,
|
|
25987
|
+
capability: identity.capability
|
|
25988
|
+
});
|
|
25989
|
+
if (!isIdentityFailure(err)) {
|
|
25990
|
+
if (leavesOutcomeUnknown(raisedAfterPayment(err))) {
|
|
25991
|
+
unconfirmed(unconfirmedSpendKey(opts, err));
|
|
25992
|
+
}
|
|
25993
|
+
throw err;
|
|
25994
|
+
}
|
|
25995
|
+
transport.close?.();
|
|
25996
|
+
const { error } = recordIdentityFailure(err, {
|
|
25997
|
+
endpoint: ref.endpoint,
|
|
25998
|
+
...identity.dvmId ? { dvmId: identity.dvmId } : {},
|
|
25999
|
+
capability: identity.capability,
|
|
26000
|
+
...opts.requestId ? { publicRequestId: opts.requestId } : {},
|
|
26001
|
+
rail: "x402",
|
|
26002
|
+
railCorrelation: {
|
|
26003
|
+
...wallet.address ? { account: wallet.address } : {},
|
|
26004
|
+
amount_usdc_micro: usdcMicroUnits
|
|
26005
|
+
}
|
|
26006
|
+
});
|
|
26007
|
+
unconfirmed(unconfirmedSpendKey(opts, error));
|
|
26008
|
+
throw error;
|
|
26009
|
+
}
|
|
24958
26010
|
const effectiveJobId = args.jobId || receipt.jobId;
|
|
24959
26011
|
if (!args.jobId && receipt.jobId) {
|
|
24960
26012
|
saveJob({
|
|
@@ -25379,10 +26431,17 @@ async function requestResult(requestId, opts = {}) {
|
|
|
25379
26431
|
);
|
|
25380
26432
|
}
|
|
25381
26433
|
const transport = createDvmTransport();
|
|
25382
|
-
const envelope = signedIntentEnvelope(
|
|
26434
|
+
const envelope = signedIntentEnvelope(
|
|
26435
|
+
intent,
|
|
26436
|
+
signer.privkey,
|
|
26437
|
+
requestRecoveryPath("request-result", requestId)
|
|
26438
|
+
);
|
|
25383
26439
|
let receipt;
|
|
25384
26440
|
try {
|
|
25385
26441
|
receipt = await transport.requestResult({ endpoint: intent.endpoint }, requestId, envelope);
|
|
26442
|
+
} catch (err) {
|
|
26443
|
+
if (isIdentityFailure(err)) throw recordRequestResultIdentityFailure(err, intent);
|
|
26444
|
+
throw err;
|
|
25386
26445
|
} finally {
|
|
25387
26446
|
transport.close();
|
|
25388
26447
|
}
|
|
@@ -25398,6 +26457,30 @@ async function requestResult(requestId, opts = {}) {
|
|
|
25398
26457
|
);
|
|
25399
26458
|
}
|
|
25400
26459
|
const existing = loadJob(receipt.jobId);
|
|
26460
|
+
if (existing && !sameEndpoint(existing.endpoint, intent.endpoint)) {
|
|
26461
|
+
const kept = recordLocalJobCollision({
|
|
26462
|
+
publicRequestId: requestId,
|
|
26463
|
+
endpoint: intent.endpoint,
|
|
26464
|
+
jobId: receipt.jobId,
|
|
26465
|
+
jobToken: receipt.jobToken,
|
|
26466
|
+
...intent.dvmId ? { dvmId: intent.dvmId } : {},
|
|
26467
|
+
capability: intent.capability,
|
|
26468
|
+
rail: "none"
|
|
26469
|
+
});
|
|
26470
|
+
const read = `DVM_JOB_TOKEN=<job_token_bearer_secret> dvm status ${shellQuoteArg(receipt.jobId)} --endpoint ${shellQuoteArg(intent.endpoint)}`;
|
|
26471
|
+
throw new DvmError(
|
|
26472
|
+
"request_result_conflict",
|
|
26473
|
+
`Job ${receipt.jobId} is already a local job from another provider, so the recovered job was not added to the local job list.`,
|
|
26474
|
+
kept.job_token ? `Do not overwrite the local record. Read the recovered job with '${read}', taking job_token_bearer_secret from evidence row ${kept.ambiguity_id} in 'dvm wallet submissions'.` : `Do not overwrite the local record. The provider sent no job token for job ${receipt.jobId}, so this caller cannot read it directly; evidence row ${kept.ambiguity_id} in 'dvm wallet submissions' records the request.`,
|
|
26475
|
+
{
|
|
26476
|
+
request_id: requestId,
|
|
26477
|
+
local_job_id: existing.id,
|
|
26478
|
+
local_endpoint: existing.endpoint,
|
|
26479
|
+
server_job_id: receipt.jobId,
|
|
26480
|
+
ambiguity_id: kept.ambiguity_id
|
|
26481
|
+
}
|
|
26482
|
+
);
|
|
26483
|
+
}
|
|
25401
26484
|
const restored = {
|
|
25402
26485
|
requestId,
|
|
25403
26486
|
transactionHash: receipt.transactionHash,
|
|
@@ -25441,8 +26524,16 @@ async function requestResult(requestId, opts = {}) {
|
|
|
25441
26524
|
});
|
|
25442
26525
|
}
|
|
25443
26526
|
const captured = captureTransportReceipt(receipt.jobId, receipt);
|
|
26527
|
+
const confirmed = await bookRecoveredSubmissions({
|
|
26528
|
+
publicRequestId: requestId,
|
|
26529
|
+
endpoint: intent.endpoint,
|
|
26530
|
+
jobId: receipt.jobId
|
|
26531
|
+
});
|
|
25444
26532
|
if (opts.human) {
|
|
25445
26533
|
info(`Recovered request ${requestId} as job ${receipt.jobId} (${receipt.status}).`);
|
|
26534
|
+
if (confirmed.length > 0) {
|
|
26535
|
+
info(`The wallet payment held for this request is now confirmed as spent on that job.`);
|
|
26536
|
+
}
|
|
25446
26537
|
renderReceiptHuman(captured);
|
|
25447
26538
|
return;
|
|
25448
26539
|
}
|
|
@@ -25453,6 +26544,7 @@ async function requestResult(requestId, opts = {}) {
|
|
|
25453
26544
|
...receipt.transactionHash ? { transaction_hash: receipt.transactionHash } : {},
|
|
25454
26545
|
...dvmIdentity(intent.dvmId, intent.capability),
|
|
25455
26546
|
...receipt.summary !== void 0 ? { summary: receipt.summary } : {},
|
|
26547
|
+
...confirmed.length > 0 ? { confirmed_pending_submissions: confirmed } : {},
|
|
25456
26548
|
...receiptJsonFields(captured),
|
|
25457
26549
|
next_action: receipt.status === "completed" || receipt.status === "failed" || receipt.status === "cancelled" ? null : {
|
|
25458
26550
|
type: "poll",
|
|
@@ -25481,6 +26573,21 @@ function signedIntentEnvelope(intent, privkey, route) {
|
|
|
25481
26573
|
bidMsats: typeof body.bid_msats === "number" ? body.bid_msats : void 0
|
|
25482
26574
|
};
|
|
25483
26575
|
}
|
|
26576
|
+
function recordRequestResultIdentityFailure(err, intent) {
|
|
26577
|
+
const record = recordSubmissionEvidence({
|
|
26578
|
+
observation: err.observation,
|
|
26579
|
+
endpoint: intent.endpoint,
|
|
26580
|
+
...intent.dvmId ? { dvmId: intent.dvmId } : {},
|
|
26581
|
+
capability: intent.capability,
|
|
26582
|
+
publicRequestId: intent.requestId,
|
|
26583
|
+
rail: "none"
|
|
26584
|
+
});
|
|
26585
|
+
return withRequestResultRecovery(err, {
|
|
26586
|
+
ambiguityId: record.ambiguity_id,
|
|
26587
|
+
requestId: intent.requestId,
|
|
26588
|
+
endpoint: intent.endpoint
|
|
26589
|
+
});
|
|
26590
|
+
}
|
|
25484
26591
|
function paymentMethod(receipt) {
|
|
25485
26592
|
if (receipt.receipt?.credit) return "credit";
|
|
25486
26593
|
const rail = receipt.receipt?.paid.rail;
|
|
@@ -25525,7 +26632,7 @@ async function requestResume(requestId, opts = {}) {
|
|
|
25525
26632
|
await transport.requestResume(
|
|
25526
26633
|
{ endpoint: intent.endpoint },
|
|
25527
26634
|
requestId,
|
|
25528
|
-
signedIntentEnvelope(intent, signer.privkey,
|
|
26635
|
+
signedIntentEnvelope(intent, signer.privkey, requestRecoveryPath("request-resume", requestId)),
|
|
25529
26636
|
timeoutMs === void 0 ? void 0 : { timeoutMs }
|
|
25530
26637
|
);
|
|
25531
26638
|
} catch (error) {
|
|
@@ -25886,14 +26993,14 @@ async function resolveNextAction(jobId, status2, fetched, transport, ref, opts)
|
|
|
25886
26993
|
import { statSync as statSync6 } from "fs";
|
|
25887
26994
|
|
|
25888
26995
|
// src/lib/upload-stream.ts
|
|
25889
|
-
import { createHash as
|
|
26996
|
+
import { createHash as createHash4 } from "crypto";
|
|
25890
26997
|
import { createReadStream } from "fs";
|
|
25891
26998
|
import * as http2 from "http";
|
|
25892
26999
|
import * as https from "https";
|
|
25893
27000
|
var UPLOAD_RESPONSE_MAX_BYTES = 64 * 1024;
|
|
25894
27001
|
function hashFile(filePath) {
|
|
25895
27002
|
return new Promise((resolve3, reject) => {
|
|
25896
|
-
const hasher =
|
|
27003
|
+
const hasher = createHash4("sha256");
|
|
25897
27004
|
let sizeBytes = 0;
|
|
25898
27005
|
const stream = createReadStream(filePath);
|
|
25899
27006
|
stream.on("data", (chunk) => {
|
|
@@ -26368,7 +27475,7 @@ function getRailOnramp(rail) {
|
|
|
26368
27475
|
}
|
|
26369
27476
|
|
|
26370
27477
|
// src/lib/secret-input.ts
|
|
26371
|
-
import { fstatSync, readFileSync as
|
|
27478
|
+
import { fstatSync, readFileSync as readFileSync10, realpathSync } from "fs";
|
|
26372
27479
|
import { homedir as homedir2 } from "os";
|
|
26373
27480
|
import { resolve as resolve2, sep } from "path";
|
|
26374
27481
|
var BLOCKED_SECRET_PATHS = [
|
|
@@ -26448,7 +27555,7 @@ function readSecretFile(path, config) {
|
|
|
26448
27555
|
throw err;
|
|
26449
27556
|
}
|
|
26450
27557
|
assertSafeFilePath(real);
|
|
26451
|
-
return
|
|
27558
|
+
return readFileSync10(real, "utf-8").trim();
|
|
26452
27559
|
}
|
|
26453
27560
|
function readSecretStdin(config) {
|
|
26454
27561
|
return new Promise((resolveStdin, reject) => {
|
|
@@ -28144,7 +29251,7 @@ function mnemonicValidationError(result) {
|
|
|
28144
29251
|
var import_qrcode = __toESM(require_lib(), 1);
|
|
28145
29252
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
28146
29253
|
import { tmpdir as tmpdir2 } from "os";
|
|
28147
|
-
import { join as
|
|
29254
|
+
import { join as join10 } from "path";
|
|
28148
29255
|
async function renderQrTerminal(payload) {
|
|
28149
29256
|
return (0, import_qrcode.toString)(payload, { type: "terminal", small: true });
|
|
28150
29257
|
}
|
|
@@ -28157,7 +29264,7 @@ async function renderQrPng(payload, outPath) {
|
|
|
28157
29264
|
});
|
|
28158
29265
|
}
|
|
28159
29266
|
function defaultQrImagePath(prefix = "dvm-wallet-fund") {
|
|
28160
|
-
return
|
|
29267
|
+
return join10(tmpdir2(), `${prefix}-${randomBytes3(8).toString("hex")}.png`);
|
|
28161
29268
|
}
|
|
28162
29269
|
|
|
28163
29270
|
// src/lib/funding-handoff.ts
|
|
@@ -29427,6 +30534,7 @@ async function walletShow(opts) {
|
|
|
29427
30534
|
const resumedViews = describeResumedSubmissions(submissionSweep.outcomes);
|
|
29428
30535
|
const reclaimedViews = describeReclaimedSubmissions(submissionSweep.outcomes);
|
|
29429
30536
|
const skippedReclaimViews = describeSkippedReclaims(submissionSweep.outcomes);
|
|
30537
|
+
const unresolvedViews = describeUnresolvedSubmissions(submissionSweep.outcomes);
|
|
29430
30538
|
const post = loadAgentWallet() ?? wallet;
|
|
29431
30539
|
const submissions = describePendingSubmissions(post);
|
|
29432
30540
|
const lockedToProviderSubmissions = submissions.entries.filter(
|
|
@@ -29491,6 +30599,7 @@ async function walletShow(opts) {
|
|
|
29491
30599
|
`Reconciled a ${outcome.entry.amount_sats} sat payment to ${outcome.entry.endpoint}${jobSuffix}.`
|
|
29492
30600
|
);
|
|
29493
30601
|
}
|
|
30602
|
+
for (const view of unresolvedViews) info(view.display);
|
|
29494
30603
|
for (const view of reclaimedViews) {
|
|
29495
30604
|
info(
|
|
29496
30605
|
`A ${view.amount_sats} sat payment to ${view.endpoint} expired unclaimed \u2014 ${view.reclaimed_sats} sats are back in your balance.`
|
|
@@ -29591,6 +30700,7 @@ async function walletShow(opts) {
|
|
|
29591
30700
|
const uncheckedHint = sweep.unchecked.length > 0 ? `${sweep.unchecked.length} pending mint(s) could not be checked against their mint on this call \u2014 see sweep.unchecked for the cause and how long to wait. They keep their pending state; don't fund the same invoice again.` : null;
|
|
29592
30701
|
const stuckReclaims = skippedReclaimViews.filter((v) => !v.terminal);
|
|
29593
30702
|
const deadReclaims = skippedReclaimViews.filter((v) => v.terminal);
|
|
30703
|
+
const unresolvedHint = unresolvedViews.length > 0 ? `${unresolvedViews.length} paid call(s) need attention: the provider accepted them without a clear job ID \u2014 see accepted_unresolved. Do not pay for them again.` : null;
|
|
29594
30704
|
const resumedHint = stuckReclaims.length > 0 ? `${stuckReclaims.reduce((sum, v) => sum + v.amount_sats, 0)} sats from ${stuckReclaims.length} expired payment(s) could not be taken back on this call \u2014 see reclaim_skipped for why. The sats are still recoverable.` : resumedViews.length > 0 ? `Reconciled ${resumedViews.length} unconfirmed payment(s) on this call \u2014 see resumed for the job id(s).` : reclaimedViews.length > 0 ? `${reclaimedViews.reduce((sum, v) => sum + v.reclaimed_sats, 0)} sats came back from ${reclaimedViews.length} expired payment(s) the provider never took \u2014 see reclaimed.` : deadReclaims.length > 0 ? `${deadReclaims.reduce((sum, v) => sum + v.amount_sats, 0)} sats from ${deadReclaims.length} expired payment(s) are too small to be worth taking back \u2014 see reclaim_skipped. Retrying will not change that; treat them as spent.` : null;
|
|
29595
30705
|
json({
|
|
29596
30706
|
status: "ok",
|
|
@@ -29624,10 +30734,13 @@ async function walletShow(opts) {
|
|
|
29624
30734
|
// with the reason. Empty is the normal case; a repeating entry here means
|
|
29625
30735
|
// the self-heal needs a human.
|
|
29626
30736
|
reclaim_skipped: skippedReclaimViews,
|
|
30737
|
+
// paid calls the provider accepted without a settled job identity,
|
|
30738
|
+
// detected on this call or missing their evidence record.
|
|
30739
|
+
accepted_unresolved: unresolvedViews,
|
|
29627
30740
|
sweep: summarizeSweep(sweep),
|
|
29628
30741
|
melt_sweep: summarizeMeltSweep(meltSweep),
|
|
29629
30742
|
display: railsSnapshot.length === 0 ? "Agent wallet is empty." : `${railsSnapshot.map((r) => r.json.display).join(" \u2014 ")} (~$${totalUsd.toFixed(2)} total)`,
|
|
29630
|
-
hint: [uncheckedHint, resumedHint, baseHint].filter(Boolean).join(" ")
|
|
30743
|
+
hint: [uncheckedHint, unresolvedHint, resumedHint, baseHint].filter(Boolean).join(" ")
|
|
29631
30744
|
});
|
|
29632
30745
|
}
|
|
29633
30746
|
}
|
|
@@ -31707,7 +32820,7 @@ function resolveMppEndpoint(identifier) {
|
|
|
31707
32820
|
}
|
|
31708
32821
|
|
|
31709
32822
|
// src/commands/wallet-pair.ts
|
|
31710
|
-
import { createHash as
|
|
32823
|
+
import { createHash as createHash5, randomBytes as randomBytes5 } from "crypto";
|
|
31711
32824
|
import { hostname } from "os";
|
|
31712
32825
|
|
|
31713
32826
|
// node_modules/@noble/ciphers/_arx.js
|
|
@@ -32529,14 +33642,14 @@ function hexToBytes2(hex) {
|
|
|
32529
33642
|
var import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
|
|
32530
33643
|
import {
|
|
32531
33644
|
chmodSync as chmodSync2,
|
|
32532
|
-
existsSync as
|
|
32533
|
-
readdirSync as
|
|
32534
|
-
readFileSync as
|
|
33645
|
+
existsSync as existsSync9,
|
|
33646
|
+
readdirSync as readdirSync6,
|
|
33647
|
+
readFileSync as readFileSync11,
|
|
32535
33648
|
renameSync as renameSync4,
|
|
32536
|
-
unlinkSync as
|
|
32537
|
-
writeFileSync as
|
|
33649
|
+
unlinkSync as unlinkSync5,
|
|
33650
|
+
writeFileSync as writeFileSync7
|
|
32538
33651
|
} from "fs";
|
|
32539
|
-
import { join as
|
|
33652
|
+
import { join as join11 } from "path";
|
|
32540
33653
|
var pairingIdPattern = /^[0-9a-f]{64}$/;
|
|
32541
33654
|
var stateSchema = external_exports.object({
|
|
32542
33655
|
version: external_exports.literal(1),
|
|
@@ -32558,12 +33671,12 @@ var stateSchema = external_exports.object({
|
|
|
32558
33671
|
function createWalletPairingState(state) {
|
|
32559
33672
|
ensurePairingsDirectory();
|
|
32560
33673
|
const path = pairingPath(state.pairing_id);
|
|
32561
|
-
|
|
33674
|
+
writeFileSync7(path, JSON.stringify(state, null, 2) + "\n", { mode: 384, flag: "wx" });
|
|
32562
33675
|
chmodSync2(path, 384);
|
|
32563
33676
|
}
|
|
32564
33677
|
function loadWalletPairingState(pairingId) {
|
|
32565
33678
|
const path = pairingPath(pairingId);
|
|
32566
|
-
if (!
|
|
33679
|
+
if (!existsSync9(path)) {
|
|
32567
33680
|
throw new DvmError(
|
|
32568
33681
|
"wallet_pairing_not_found",
|
|
32569
33682
|
"No local state exists for that wallet pairing.",
|
|
@@ -32571,7 +33684,7 @@ function loadWalletPairingState(pairingId) {
|
|
|
32571
33684
|
);
|
|
32572
33685
|
}
|
|
32573
33686
|
try {
|
|
32574
|
-
return stateSchema.parse(JSON.parse(
|
|
33687
|
+
return stateSchema.parse(JSON.parse(readFileSync11(path, "utf8")));
|
|
32575
33688
|
} catch {
|
|
32576
33689
|
throw new DvmError(
|
|
32577
33690
|
"wallet_pairing_state_invalid",
|
|
@@ -32585,13 +33698,13 @@ function saveWalletPairingState(state) {
|
|
|
32585
33698
|
ensurePairingsDirectory();
|
|
32586
33699
|
const path = pairingPath(state.pairing_id);
|
|
32587
33700
|
const tmp = `${path}.tmp`;
|
|
32588
|
-
|
|
33701
|
+
writeFileSync7(tmp, JSON.stringify(state, null, 2) + "\n", { mode: 384 });
|
|
32589
33702
|
try {
|
|
32590
33703
|
renameSync4(tmp, path);
|
|
32591
33704
|
chmodSync2(path, 384);
|
|
32592
33705
|
} catch (err) {
|
|
32593
33706
|
try {
|
|
32594
|
-
|
|
33707
|
+
unlinkSync5(tmp);
|
|
32595
33708
|
} catch {
|
|
32596
33709
|
}
|
|
32597
33710
|
throw err;
|
|
@@ -32600,21 +33713,21 @@ function saveWalletPairingState(state) {
|
|
|
32600
33713
|
function deleteWalletPairingState(pairingId) {
|
|
32601
33714
|
const path = pairingPath(pairingId);
|
|
32602
33715
|
try {
|
|
32603
|
-
|
|
33716
|
+
unlinkSync5(path);
|
|
32604
33717
|
} catch (err) {
|
|
32605
33718
|
if (err.code !== "ENOENT") throw err;
|
|
32606
33719
|
}
|
|
32607
33720
|
}
|
|
32608
33721
|
function cleanupExpiredWalletPairingStates(nowSeconds = Math.floor(Date.now() / 1e3)) {
|
|
32609
|
-
if (!
|
|
33722
|
+
if (!existsSync9(PAIRINGS_DIR)) return 0;
|
|
32610
33723
|
let removed = 0;
|
|
32611
|
-
for (const name of
|
|
33724
|
+
for (const name of readdirSync6(PAIRINGS_DIR)) {
|
|
32612
33725
|
if (!/^[0-9a-f]{64}\.json$/.test(name)) continue;
|
|
32613
|
-
const path =
|
|
33726
|
+
const path = join11(PAIRINGS_DIR, name);
|
|
32614
33727
|
try {
|
|
32615
|
-
const state = stateSchema.parse(JSON.parse(
|
|
33728
|
+
const state = stateSchema.parse(JSON.parse(readFileSync11(path, "utf8")));
|
|
32616
33729
|
if (state.manifest.expires_at <= nowSeconds) {
|
|
32617
|
-
|
|
33730
|
+
unlinkSync5(path);
|
|
32618
33731
|
removed += 1;
|
|
32619
33732
|
}
|
|
32620
33733
|
} catch {
|
|
@@ -32624,7 +33737,7 @@ function cleanupExpiredWalletPairingStates(nowSeconds = Math.floor(Date.now() /
|
|
|
32624
33737
|
}
|
|
32625
33738
|
async function withWalletPairingLock(pairingId, fn) {
|
|
32626
33739
|
const path = pairingPath(pairingId);
|
|
32627
|
-
if (!
|
|
33740
|
+
if (!existsSync9(path)) return fn();
|
|
32628
33741
|
let release;
|
|
32629
33742
|
try {
|
|
32630
33743
|
release = await import_proper_lockfile2.default.lock(path, {
|
|
@@ -32654,7 +33767,7 @@ function pairingPath(pairingId) {
|
|
|
32654
33767
|
"Wallet pairing id must be 64 lowercase hexadecimal characters."
|
|
32655
33768
|
);
|
|
32656
33769
|
}
|
|
32657
|
-
return
|
|
33770
|
+
return join11(PAIRINGS_DIR, `${pairingId}.json`);
|
|
32658
33771
|
}
|
|
32659
33772
|
function ensurePairingsDirectory() {
|
|
32660
33773
|
ensureConfigSubdir(PAIRINGS_DIR);
|
|
@@ -33079,7 +34192,7 @@ function walletFingerprint(uri) {
|
|
|
33079
34192
|
return uri ? sha2562(uri) : null;
|
|
33080
34193
|
}
|
|
33081
34194
|
function sha2562(value) {
|
|
33082
|
-
return
|
|
34195
|
+
return createHash5("sha256").update(value).digest("hex");
|
|
33083
34196
|
}
|
|
33084
34197
|
function relayHost2(relay) {
|
|
33085
34198
|
try {
|
|
@@ -33205,9 +34318,16 @@ async function walletSubmissions(opts) {
|
|
|
33205
34318
|
listSubmissions(opts);
|
|
33206
34319
|
}
|
|
33207
34320
|
function listSubmissions(opts) {
|
|
33208
|
-
const
|
|
33209
|
-
const
|
|
34321
|
+
const listed = listSubmissionEvidence();
|
|
34322
|
+
const evidence = describeSubmissionEvidence(listed.records);
|
|
34323
|
+
const unreadable2 = listed.unreadable;
|
|
34324
|
+
const wallet = evidence.length > 0 || unreadable2.length > 0 ? loadAgentWallet() : loadWalletOrThrow();
|
|
34325
|
+
const summary = wallet ? describePendingSubmissions(wallet) : EMPTY_SUMMARY;
|
|
33210
34326
|
if (opts.human) {
|
|
34327
|
+
printEvidenceHuman(evidence);
|
|
34328
|
+
for (const file of unreadable2) {
|
|
34329
|
+
info(`Unreadable evidence record (${file.cause}): ${file.path}. Restore it from a backup; do not pay again for any request it may describe.`);
|
|
34330
|
+
}
|
|
33211
34331
|
if (summary.entries.length === 0) {
|
|
33212
34332
|
info("No unconfirmed payments \u2014 every spend has been acknowledged by its provider.");
|
|
33213
34333
|
return;
|
|
@@ -33236,6 +34356,12 @@ function listSubmissions(opts) {
|
|
|
33236
34356
|
` ${summary.reclaim_failed_count} of these have expired but the wallet keeps failing to take the sats back \u2014 the reason is on each line above. Fix the cause and the next call retries; the sats are still recoverable.`
|
|
33237
34357
|
);
|
|
33238
34358
|
}
|
|
34359
|
+
if (summary.accepted_unresolved_count > 0) {
|
|
34360
|
+
info("");
|
|
34361
|
+
info(
|
|
34362
|
+
` ${summary.accepted_unresolved_count} of these were accepted by the provider without a clear job ID. They are never paid for or sent again; the evidence above says how to find each job.`
|
|
34363
|
+
);
|
|
34364
|
+
}
|
|
33239
34365
|
return;
|
|
33240
34366
|
}
|
|
33241
34367
|
json({
|
|
@@ -33251,11 +34377,21 @@ function listSubmissions(opts) {
|
|
|
33251
34377
|
// not stranded — the sats are recoverable once the cause is fixed — but
|
|
33252
34378
|
// unlike `reclaimable` this one needs someone to act.
|
|
33253
34379
|
reclaim_failed_count: summary.reclaim_failed_count,
|
|
33254
|
-
|
|
34380
|
+
// Accepted without a settled job identity: held so nothing pays twice.
|
|
34381
|
+
accepted_unresolved_count: summary.accepted_unresolved_count,
|
|
34382
|
+
submission_evidence: evidence,
|
|
34383
|
+
...unreadable2.length > 0 ? { submission_evidence_unreadable: unreadable2 } : {},
|
|
34384
|
+
display: [
|
|
34385
|
+
summary.entries.length === 0 ? "No unconfirmed payments." : `${summary.entries.length} unconfirmed payment(s), ${summary.at_risk_sats} sats spent but not yet confirmed by a provider.`,
|
|
34386
|
+
evidence.length > 0 ? `${evidence.length} paid call(s) were accepted without a clear job ID; see submission_evidence. None was paid for again.` : null,
|
|
34387
|
+
unreadable2.length > 0 ? `${unreadable2.length} evidence record(s) cannot be read; see submission_evidence_unreadable. The payments they may describe are held and not sent again.` : null
|
|
34388
|
+
].filter(Boolean).join(" "),
|
|
33255
34389
|
hint: [
|
|
33256
34390
|
summary.stranded_count > 0 ? "Entries in state stale/unresumable/unreclaimable will not retry and their sats are not coming back. Close one out with: dvm wallet submissions --forget <request_id> (abandons its sats)." : null,
|
|
33257
34391
|
summary.reclaimable_count > 0 ? "Entries in state reclaimable need no action \u2014 the wallet takes those sats back after reclaim_at." : null,
|
|
33258
34392
|
summary.reclaim_failed_count > 0 ? "Entries in state reclaim_failed have expired but could not be taken back \u2014 see each entry's reclaim_error. The sats are recoverable once that is fixed." : null,
|
|
34393
|
+
unreadable2.length > 0 ? "Restore each file in submission_evidence_unreadable from a backup. Do not pay again for any request it may describe." : null,
|
|
34394
|
+
evidence.length > 0 ? "Do not pay for a request listed in submission_evidence again. Each row's read_job lists lookups that never pay; job_token_bearer_secret, where present, is a bearer secret: treat it like a password and do not share it." : null,
|
|
33259
34395
|
"Resumable entries retry on the next paid call or `dvm wallet show`."
|
|
33260
34396
|
].filter(Boolean).join(" ")
|
|
33261
34397
|
});
|
|
@@ -33285,7 +34421,7 @@ async function forgetSubmission(requestId, opts) {
|
|
|
33285
34421
|
request_id: requestId,
|
|
33286
34422
|
endpoint: view.endpoint,
|
|
33287
34423
|
abandoned_sats: abandoned,
|
|
33288
|
-
display: !view.at_risk ? `Forgot request ${requestId}. No sats were spent, so nothing was abandoned.` : view.state === "reclaimable" || view.state === "reclaim_failed" ? `Forgot the unconfirmed payment for request ${requestId}. ${abandoned} sats paid to ${view.endpoint} are abandoned \u2014 and this one was still recoverable: the wallet would have returned it to your balance by itself${view.reclaim_at ? ` after ${view.reclaim_at}` : ""}.` : view.state === "unreclaimable" ? `Forgot the unconfirmed payment for request ${requestId}. ${abandoned} sats paid to ${view.endpoint} are abandoned \u2014 nothing was given up by forgetting it, since ${view.reclaim_error ?? "the mint's fee exceeds the value"}.` : `Forgot the unconfirmed payment for request ${requestId}. ${abandoned} sats paid to ${view.endpoint} are abandoned \u2014 the proofs were locked to the provider with no refund.`,
|
|
34424
|
+
display: !view.at_risk ? `Forgot request ${requestId}. No sats were spent, so nothing was abandoned.` : view.state === "reclaimable" || view.state === "reclaim_failed" ? `Forgot the unconfirmed payment for request ${requestId}. ${abandoned} sats paid to ${view.endpoint} are abandoned \u2014 and this one was still recoverable: the wallet would have returned it to your balance by itself${view.reclaim_at ? ` after ${view.reclaim_at}` : ""}.` : view.state === "accepted_unresolved" ? `Forgot the journal entry for request ${requestId}. ${abandoned} sats paid to ${view.endpoint} are no longer tracked; the provider accepted that call, and its evidence stays under submission_evidence.` : view.state === "unreclaimable" ? `Forgot the unconfirmed payment for request ${requestId}. ${abandoned} sats paid to ${view.endpoint} are abandoned \u2014 nothing was given up by forgetting it, since ${view.reclaim_error ?? "the mint's fee exceeds the value"}.` : `Forgot the unconfirmed payment for request ${requestId}. ${abandoned} sats paid to ${view.endpoint} are abandoned \u2014 the proofs were locked to the provider with no refund.`,
|
|
33289
34425
|
hint: "The entry is gone from the journal. This cannot be undone."
|
|
33290
34426
|
});
|
|
33291
34427
|
}
|
|
@@ -33306,7 +34442,7 @@ async function confirmForget(view, opts) {
|
|
|
33306
34442
|
// caller money they were otherwise getting back. Reaching
|
|
33307
34443
|
// here at all means they already passed --force.
|
|
33308
34444
|
`throws away ${view.amount_sats} sats paid to ${view.endpoint} that the wallet can still reclaim by itself, so this cannot be undone`
|
|
33309
|
-
) : view.state === "unreclaimable" ? `clears ${view.amount_sats} sats paid to ${view.endpoint} that are too small to be worth taking back, so nothing recoverable is lost \u2014 but this cannot be undone` : `abandons ${view.amount_sats} sats paid to ${view.endpoint} \u2014 the proofs are locked to the provider with no refund, so this cannot be undone`;
|
|
34445
|
+
) : view.state === "accepted_unresolved" ? `stops tracking ${view.amount_sats} sats paid to ${view.endpoint} for a call the provider accepted without a clear job ID${view.reclaim_at ? `, including the wallet's claim to take them back after ${view.reclaim_at} if the provider never redeems them` : ""}; the recorded evidence is kept, but this cannot be undone` : view.state === "unreclaimable" ? `clears ${view.amount_sats} sats paid to ${view.endpoint} that are too small to be worth taking back, so nothing recoverable is lost \u2014 but this cannot be undone` : `abandons ${view.amount_sats} sats paid to ${view.endpoint} \u2014 the proofs are locked to the provider with no refund, so this cannot be undone`;
|
|
33310
34446
|
if (opts.human && process.stdin.isTTY) {
|
|
33311
34447
|
const rl = createInterface4({ input: process.stdin, output: process.stderr });
|
|
33312
34448
|
const answer = await new Promise((resolve3) => {
|
|
@@ -33329,6 +34465,29 @@ async function confirmForget(view, opts) {
|
|
|
33329
34465
|
`This ${consequence}. Use: dvm wallet submissions --forget ${view.request_id} --yes`
|
|
33330
34466
|
);
|
|
33331
34467
|
}
|
|
34468
|
+
var EMPTY_SUMMARY = {
|
|
34469
|
+
entries: [],
|
|
34470
|
+
at_risk_sats: 0,
|
|
34471
|
+
stranded_count: 0,
|
|
34472
|
+
reclaimable_count: 0,
|
|
34473
|
+
reclaim_failed_count: 0,
|
|
34474
|
+
accepted_unresolved_count: 0
|
|
34475
|
+
};
|
|
34476
|
+
function printEvidenceHuman(evidence) {
|
|
34477
|
+
if (evidence.length === 0) return;
|
|
34478
|
+
info(`Accepted without a clear job ID: ${evidence.length} (never paid for again)`);
|
|
34479
|
+
for (const row of evidence) {
|
|
34480
|
+
info(` ${row.ambiguity_id} ${row.endpoint} (${row.kind}, ${row.observed_at})`);
|
|
34481
|
+
info(` ${row.display}`);
|
|
34482
|
+
for (const command of row.read_job) info(` read: ${command}`);
|
|
34483
|
+
if (row.job_token_bearer_secret) {
|
|
34484
|
+
info(
|
|
34485
|
+
` job_token_bearer_secret (treat like a password; do not share): ${row.job_token_bearer_secret}`
|
|
34486
|
+
);
|
|
34487
|
+
}
|
|
34488
|
+
}
|
|
34489
|
+
info("");
|
|
34490
|
+
}
|
|
33332
34491
|
function loadWalletOrThrow() {
|
|
33333
34492
|
const wallet = loadAgentWallet();
|
|
33334
34493
|
if (!wallet) {
|