@dvmkit/sdk 0.14.2 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-IVW5UMD3.js → chunk-2UZOJRRS.js} +1 -1
- package/dist/{chunk-G47UY3BK.js → chunk-4IFZHJQK.js} +1 -1
- package/dist/{chunk-BAHZK334.js → chunk-5U2RG3ZW.js} +6 -2
- package/dist/{chunk-GB2N4NG5.js → chunk-7N5VDCG3.js} +2 -2
- package/dist/{chunk-CVT5LTAK.js → chunk-7QGS27UT.js} +1 -1
- package/dist/{chunk-FOXGN4KQ.js → chunk-ELNWQS24.js} +1 -1
- package/dist/{chunk-I2H2XYQV.js → chunk-F2LNWZCV.js} +1 -1
- package/dist/{chunk-RQK7OFJO.js → chunk-FRGKANTZ.js} +1 -1
- package/dist/{chunk-2I6NXIPG.js → chunk-ICHC4VDZ.js} +1 -1
- package/dist/{chunk-LM6E4YHQ.js → chunk-K4ZQE7IB.js} +2 -2
- package/dist/{chunk-FL6Q3JNJ.js → chunk-KVKJ7R5V.js} +56 -2
- package/dist/{chunk-P5KQKLWL.js → chunk-MD34LE6M.js} +1 -1
- package/dist/{chunk-PJAKJD2U.js → chunk-N4SBDUVD.js} +31 -9
- package/dist/{chunk-IUODXRQN.js → chunk-OYBSDJR6.js} +2 -2
- package/dist/{chunk-CRH6BMMG.js → chunk-PBT3H2LZ.js} +1 -1
- package/dist/{chunk-33J3NQDZ.js → chunk-PP5WHB6T.js} +1 -1
- package/dist/{chunk-VG74TVFF.js → chunk-SGSHDMHP.js} +114 -41
- package/dist/{chunk-R7FH7SHX.js → chunk-TN6MWTZI.js} +2 -2
- package/dist/{chunk-R3FSW66G.js → chunk-V4CBI5HB.js} +39 -13
- package/dist/{chunk-ZO2ZAPG3.js → chunk-V73WRF46.js} +1 -1
- package/dist/{chunk-7NZRJPEP.js → chunk-VQHBJXBL.js} +1 -1
- package/dist/{chunk-LZFZGY7L.js → chunk-XBQTFOIT.js} +1 -1
- package/dist/{chunk-QRYGBKCR.js → chunk-XSF5YTEY.js} +1 -1
- package/dist/{content-retention-DA2mlW31.d.ts → content-retention-BASsjgKw.d.ts} +1 -1
- package/dist/{credit-ledger-EZDZYLSK.js → credit-ledger-VWZ5NP7V.js} +3 -3
- package/dist/{credit-menu-BXHL3jHA.d.ts → credit-menu-B239nIY5.d.ts} +13 -6
- package/dist/{fx-UnO-P6Cj.d.ts → fx-BmvWGISH.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -4
- package/dist/internal/caller.d.ts +11 -7
- package/dist/internal/caller.js +7 -7
- package/dist/internal/server.d.ts +7 -7
- package/dist/internal/server.js +21 -21
- package/dist/{job-store-AxjHh5Gp.d.ts → job-store-CA7u1nHV.d.ts} +11 -3
- package/dist/{lightning-backend-C5_GKiKR.d.ts → lightning-backend-BOcopzXk.d.ts} +1 -1
- package/dist/{memory-credit-ledger-REZGHPJP.js → memory-credit-ledger-DZWRQGSF.js} +4 -4
- package/dist/{mpp-setup-RG5JDMIO.js → mpp-setup-3NJY354I.js} +3 -3
- package/dist/{payout-reporter-DDQ7FGRC.js → payout-reporter-P3652TLG.js} +2 -2
- package/dist/{postgres-consumed-credential-store-I4WTNVQZ.js → postgres-consumed-credential-store-S2CBQ4NO.js} +1 -1
- package/dist/{postgres-job-store-VDSDXCHR.js → postgres-job-store-JRSG54VJ.js} +3 -3
- package/dist/{postgres-replay-store-3F5FCUXN.js → postgres-replay-store-ZPILIJIW.js} +2 -2
- package/dist/{pricing-HLYEGPXD.js → pricing-3P7KAONY.js} +3 -3
- package/dist/{revenue-reporter-RIEHBKRA.js → revenue-reporter-2P3PWJJM.js} +2 -2
- package/dist/server/index.d.ts +14 -12
- package/dist/server/index.js +28 -28
- package/dist/{step-cache-MA3hpa7F.d.ts → step-cache-BCRHimiY.d.ts} +23 -1
- package/dist/{tempo-charge-store-B5SYDCBK.js → tempo-charge-store-2LK6IDLS.js} +2 -2
- package/dist/{tempo-session-store-FHW7N22I.js → tempo-session-store-5MHCH3YW.js} +3 -3
- package/dist/testing/index.d.ts +7 -4
- package/dist/testing/index.js +7 -7
- package/dist/{usd-CLGrKw9p.d.ts → usd-B8_WMfHT.d.ts} +1 -1
- package/dist/{x402-AY6P5KV4.js → x402-6T73AZQ6.js} +3 -3
- package/package.json +1 -1
|
@@ -1024,7 +1024,8 @@ var diagnostic_catalogue_v1_default = {
|
|
|
1024
1024
|
identityFields: [
|
|
1025
1025
|
"dvm_id",
|
|
1026
1026
|
"dvm_slug",
|
|
1027
|
-
"builder_id"
|
|
1027
|
+
"builder_id",
|
|
1028
|
+
"dvm_resolution"
|
|
1028
1029
|
],
|
|
1029
1030
|
capabilityFields: [
|
|
1030
1031
|
"capability"
|
|
@@ -1445,11 +1446,14 @@ function projectHost(value) {
|
|
|
1445
1446
|
}
|
|
1446
1447
|
function validateIdentity(key, value) {
|
|
1447
1448
|
if (typeof value !== "string") return void 0;
|
|
1449
|
+
if (key === "dvm_resolution") return value === "none" ? value : void 0;
|
|
1448
1450
|
if (key === "dvm_slug") return SLUG_RE.test(value) ? value : void 0;
|
|
1449
1451
|
return value.length <= 36 && UUID_RE.test(value) ? value : void 0;
|
|
1450
1452
|
}
|
|
1451
1453
|
function projectIdentity(key, authority) {
|
|
1452
|
-
|
|
1454
|
+
const identities = authority && AUTHORITY_IDENTITIES.get(authority);
|
|
1455
|
+
if (key === "dvm_resolution" && identities?.dvm_id) return void 0;
|
|
1456
|
+
return identities?.[key];
|
|
1453
1457
|
}
|
|
1454
1458
|
function projectCapability(value, authority) {
|
|
1455
1459
|
if (typeof value !== "string" || !CAPABILITY_RE.test(value)) return void 0;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loggers
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TN6MWTZI.js";
|
|
4
4
|
import {
|
|
5
5
|
diagnosticConsole
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5U2RG3ZW.js";
|
|
7
7
|
|
|
8
8
|
// src/sdk/server/mpp-setup.ts
|
|
9
9
|
import { createHash, randomUUID } from "crypto";
|
|
@@ -10,13 +10,13 @@ import {
|
|
|
10
10
|
} from "./chunk-5UC7TOQC.js";
|
|
11
11
|
import {
|
|
12
12
|
applyRetryToPool
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-ELNWQS24.js";
|
|
14
14
|
import {
|
|
15
15
|
x402NetworkByCaip2
|
|
16
16
|
} from "./chunk-BPYMEMQX.js";
|
|
17
17
|
import {
|
|
18
18
|
diagnosticConsole
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-5U2RG3ZW.js";
|
|
20
20
|
|
|
21
21
|
// src/sdk/server/credit-ledger.ts
|
|
22
22
|
import { randomUUID } from "crypto";
|
|
@@ -26,6 +26,7 @@ function toJobRecord(job) {
|
|
|
26
26
|
awaitingInputAtMs: job.awaitingInputAtMs,
|
|
27
27
|
messages: job.messages,
|
|
28
28
|
seq: job.seq,
|
|
29
|
+
upfrontPayment: job.upfrontPayment,
|
|
29
30
|
paidMsats: job.paidMsats,
|
|
30
31
|
paymentMint: job.paymentMint,
|
|
31
32
|
paymentRail: job.paymentRail,
|
|
@@ -77,6 +78,7 @@ function fromJobRecord(record) {
|
|
|
77
78
|
awaitingInputAtMs: record.awaitingInputAtMs,
|
|
78
79
|
messages: [...record.messages],
|
|
79
80
|
seq: record.seq,
|
|
81
|
+
upfrontPayment: record.upfrontPayment,
|
|
80
82
|
paidMsats: record.paidMsats,
|
|
81
83
|
paymentMint: record.paymentMint,
|
|
82
84
|
paymentRail: record.paymentRail,
|
|
@@ -163,7 +165,51 @@ function providerMessage(job, type, content) {
|
|
|
163
165
|
}
|
|
164
166
|
job.messageAppender?.(msg, type === "prompt" ? { awaitingInput: job.status === "awaiting-input" } : void 0);
|
|
165
167
|
}
|
|
168
|
+
var historyHolds = /* @__PURE__ */ new WeakMap();
|
|
169
|
+
var heldNotifications = /* @__PURE__ */ new WeakMap();
|
|
170
|
+
function holdJobHistory(job, seq) {
|
|
171
|
+
let holds = historyHolds.get(job);
|
|
172
|
+
if (!holds) {
|
|
173
|
+
holds = /* @__PURE__ */ new Set();
|
|
174
|
+
historyHolds.set(job, holds);
|
|
175
|
+
}
|
|
176
|
+
holds.add(seq);
|
|
177
|
+
}
|
|
178
|
+
function visibleJobMessages(job) {
|
|
179
|
+
const holds = historyHolds.get(job);
|
|
180
|
+
if (!holds?.size) return job.messages;
|
|
181
|
+
const boundary = Math.min(...holds);
|
|
182
|
+
return job.messages.filter((message) => message.seq < boundary);
|
|
183
|
+
}
|
|
184
|
+
function releaseJobHistory(job, seq, accepted) {
|
|
185
|
+
const holds = historyHolds.get(job);
|
|
186
|
+
const wasPending = holds?.delete(seq);
|
|
187
|
+
if (accepted && wasPending) {
|
|
188
|
+
const next = job.messages.findIndex((existing) => existing.seq > accepted.seq);
|
|
189
|
+
job.messages.splice(next < 0 ? job.messages.length : next, 0, accepted);
|
|
190
|
+
const queued = heldNotifications.get(job) ?? [];
|
|
191
|
+
queued.push(accepted);
|
|
192
|
+
heldNotifications.set(job, queued);
|
|
193
|
+
}
|
|
194
|
+
flushJobHistory(job);
|
|
195
|
+
}
|
|
196
|
+
function flushJobHistory(job) {
|
|
197
|
+
const holds = historyHolds.get(job);
|
|
198
|
+
const boundary = holds?.size ? Math.min(...holds) : Infinity;
|
|
199
|
+
const queued = heldNotifications.get(job) ?? [];
|
|
200
|
+
queued.sort((a, b) => a.seq - b.seq);
|
|
201
|
+
heldNotifications.set(job, queued.filter((message) => message.seq >= boundary));
|
|
202
|
+
for (const message of queued) {
|
|
203
|
+
if (message.seq < boundary) {
|
|
204
|
+
for (const listener of job.listeners) listener(message);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
166
208
|
function localMessage(job, from, type, content) {
|
|
209
|
+
if (type === "cancel" || type === "complete") {
|
|
210
|
+
historyHolds.get(job)?.clear();
|
|
211
|
+
flushJobHistory(job);
|
|
212
|
+
}
|
|
167
213
|
job.seq++;
|
|
168
214
|
const msg = {
|
|
169
215
|
seq: job.seq,
|
|
@@ -173,8 +219,13 @@ function localMessage(job, from, type, content) {
|
|
|
173
219
|
content
|
|
174
220
|
};
|
|
175
221
|
job.messages.push(msg);
|
|
176
|
-
|
|
177
|
-
|
|
222
|
+
const holds = historyHolds.get(job);
|
|
223
|
+
if (holds?.size && msg.seq >= Math.min(...holds)) {
|
|
224
|
+
const queued = heldNotifications.get(job) ?? [];
|
|
225
|
+
queued.push(msg);
|
|
226
|
+
heldNotifications.set(job, queued);
|
|
227
|
+
} else {
|
|
228
|
+
for (const listener of job.listeners) listener(msg);
|
|
178
229
|
}
|
|
179
230
|
return msg;
|
|
180
231
|
}
|
|
@@ -270,6 +321,9 @@ export {
|
|
|
270
321
|
abortJob,
|
|
271
322
|
JobCancelledError,
|
|
272
323
|
providerMessage,
|
|
324
|
+
holdJobHistory,
|
|
325
|
+
visibleJobMessages,
|
|
326
|
+
releaseJobHistory,
|
|
273
327
|
localMessage,
|
|
274
328
|
isTerminal,
|
|
275
329
|
isYieldMessage,
|
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
applyContentHoldMutation,
|
|
4
4
|
callerDeadline,
|
|
5
5
|
hasCallerDeadline
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-KVKJ7R5V.js";
|
|
7
7
|
import {
|
|
8
8
|
withSdkInitLock
|
|
9
9
|
} from "./chunk-COYKJRMM.js";
|
|
10
10
|
import {
|
|
11
11
|
diagnosticConsole
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-5U2RG3ZW.js";
|
|
13
13
|
|
|
14
14
|
// src/sdk/server/postgres-job-store.ts
|
|
15
15
|
import { createHash } from "crypto";
|
|
@@ -263,6 +263,7 @@ var PostgresJobStore = class {
|
|
|
263
263
|
-- with a fund-and-draw response. INSERT-only for replay stability.
|
|
264
264
|
ALTER TABLE jobs ADD COLUMN IF NOT EXISTS funding_receipt JSONB;
|
|
265
265
|
ALTER TABLE jobs ADD COLUMN IF NOT EXISTS funding_credit JSONB;
|
|
266
|
+
ALTER TABLE jobs ADD COLUMN IF NOT EXISTS upfront_payment JSONB;
|
|
266
267
|
-- the outstanding mid-job ask, denominated in fiat micro at the
|
|
267
268
|
-- instant it was emitted. The top-up's ledger leg funds and grows the
|
|
268
269
|
-- draw in this figure, so it must not move with the BTC/USD rate between
|
|
@@ -550,8 +551,8 @@ var PostgresJobStore = class {
|
|
|
550
551
|
last_activity_at, next_seq, requester_token_hash, requester_token,
|
|
551
552
|
request_fingerprint, requester_pubkey, request_id, credit_id, draw_id,
|
|
552
553
|
pending_payment_fiat_micro, pending_payment_fiat_currency, auth_request_path,
|
|
553
|
-
funding_receipt, funding_credit, dvm_id, terminal_at_ms, caller_wait_ms, awaiting_input_at_ms, ended_by, timing_known
|
|
554
|
-
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$51)
|
|
554
|
+
funding_receipt, funding_credit, dvm_id, terminal_at_ms, caller_wait_ms, awaiting_input_at_ms, ended_by, timing_known, upfront_payment
|
|
555
|
+
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$51,$52)
|
|
555
556
|
ON CONFLICT (id) DO UPDATE SET
|
|
556
557
|
terminal_at_ms = COALESCE(jobs.terminal_at_ms, EXCLUDED.terminal_at_ms),
|
|
557
558
|
ended_by = CASE WHEN jobs.status IN ('completed', 'failed', 'cancelled') THEN jobs.ended_by ELSE EXCLUDED.ended_by END,
|
|
@@ -690,7 +691,8 @@ var PostgresJobStore = class {
|
|
|
690
691
|
record.status === "awaiting-input" ? record.awaitingInputAtMs ?? now : null,
|
|
691
692
|
isTerminalStatus(record.status) && record.status !== "completed" ? record.endedBy ?? "provider" : null,
|
|
692
693
|
now,
|
|
693
|
-
record.timingKnown ?? true
|
|
694
|
+
record.timingKnown ?? true,
|
|
695
|
+
record.upfrontPayment ? JSON.stringify(record.upfrontPayment) : null
|
|
694
696
|
]
|
|
695
697
|
);
|
|
696
698
|
let rowCount;
|
|
@@ -729,6 +731,7 @@ var PostgresJobStore = class {
|
|
|
729
731
|
return;
|
|
730
732
|
}
|
|
731
733
|
if (record.status === "completed" || record.status === "failed" || record.status === "cancelled") {
|
|
734
|
+
await this.pool.query("SELECT pg_notify('job_messages', $1)", [record.id]).catch(() => void 0);
|
|
732
735
|
await this.deleteResolvedMessages(record.id).catch(() => void 0);
|
|
733
736
|
}
|
|
734
737
|
}
|
|
@@ -1197,7 +1200,11 @@ var PostgresJobStore = class {
|
|
|
1197
1200
|
}
|
|
1198
1201
|
async markInboundFailed(jobId, seq, _reason) {
|
|
1199
1202
|
await this.pool.query(
|
|
1200
|
-
|
|
1203
|
+
`WITH failed AS (
|
|
1204
|
+
UPDATE job_messages SET status='failed-verify'
|
|
1205
|
+
WHERE job_id = $1 AND seq = $2 AND status = 'pending-verification'
|
|
1206
|
+
RETURNING job_id
|
|
1207
|
+
) SELECT pg_notify('job_messages', job_id) FROM failed`,
|
|
1201
1208
|
[jobId, seq]
|
|
1202
1209
|
);
|
|
1203
1210
|
}
|
|
@@ -1316,10 +1323,24 @@ var PostgresJobStore = class {
|
|
|
1316
1323
|
if (subSet.size === 0) this.notifySubscribers.delete(jobId);
|
|
1317
1324
|
});
|
|
1318
1325
|
}
|
|
1319
|
-
async getMessages(jobId, afterSeq) {
|
|
1326
|
+
async getMessages(jobId, afterSeq, options) {
|
|
1320
1327
|
const { rows } = await this.pool.query(
|
|
1321
|
-
|
|
1322
|
-
|
|
1328
|
+
`WITH terminal AS (
|
|
1329
|
+
SELECT messages FROM jobs WHERE id = $1 AND status IN ('completed', 'failed', 'cancelled')
|
|
1330
|
+
), history AS (
|
|
1331
|
+
SELECT seq, data, 0 AS origin FROM job_messages
|
|
1332
|
+
WHERE job_id = $1 AND seq > $2 AND status = 'verified'
|
|
1333
|
+
AND ($3::boolean OR EXISTS (SELECT 1 FROM terminal)
|
|
1334
|
+
OR EXISTS (SELECT 1 FROM job_messages WHERE job_id = $1 AND status = 'verified'
|
|
1335
|
+
AND data->>'from' = 'provider' AND data->>'type' IN ('complete', 'cancel'))
|
|
1336
|
+
OR seq < COALESCE((SELECT MIN(seq) FROM job_messages
|
|
1337
|
+
WHERE job_id = $1 AND status = 'pending-verification' AND data->>'type' = 'payment'), 9223372036854775807))
|
|
1338
|
+
UNION ALL
|
|
1339
|
+
SELECT (message->>'seq')::bigint, message, 1 AS origin
|
|
1340
|
+
FROM terminal CROSS JOIN LATERAL jsonb_array_elements(terminal.messages) AS snapshot(message)
|
|
1341
|
+
WHERE (message->>'seq')::bigint > $2
|
|
1342
|
+
) SELECT DISTINCT ON (seq) data FROM history ORDER BY seq, origin`,
|
|
1343
|
+
[jobId, afterSeq, options?.includeHeld ?? false]
|
|
1323
1344
|
);
|
|
1324
1345
|
return rows.map((r) => typeof r.data === "string" ? JSON.parse(r.data) : r.data);
|
|
1325
1346
|
}
|
|
@@ -1547,6 +1568,7 @@ function rowToRecord(row) {
|
|
|
1547
1568
|
summary: row.summary,
|
|
1548
1569
|
messages: row.messages,
|
|
1549
1570
|
seq: row.seq,
|
|
1571
|
+
upfrontPayment: row.upfront_payment ?? void 0,
|
|
1550
1572
|
paidMsats: Number(row.paid_msats),
|
|
1551
1573
|
paymentMint: row.payment_mint,
|
|
1552
1574
|
paymentRail: row.payment_rail ?? void 0,
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
createX402FacilitatorAuthHeaders,
|
|
3
3
|
settleWithFacilitator,
|
|
4
4
|
verifyWithFacilitator
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-F2LNWZCV.js";
|
|
6
6
|
import {
|
|
7
7
|
buildPaymentRequirements,
|
|
8
8
|
decodePayment,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from "./chunk-66HGCPBU.js";
|
|
16
16
|
import {
|
|
17
17
|
diagnosticConsole
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-5U2RG3ZW.js";
|
|
19
19
|
|
|
20
20
|
// src/lib/x402/verify.ts
|
|
21
21
|
async function verifyX402Payment(paymentHeader, config, requiredUsdcMicro, resource, btcUsdRate, exactVersions = { v1: true, v2: true }) {
|