@dvmkit/sdk 0.9.0 → 0.10.1

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.
Files changed (52) hide show
  1. package/dist/{chunk-GODOH2AF.js → chunk-2OGBZPPJ.js} +43 -21
  2. package/dist/{chunk-4VV7WACY.js → chunk-2XQLL6N6.js} +1 -1
  3. package/dist/{chunk-LCCG5HQM.js → chunk-3Q6FTZDB.js} +2 -2
  4. package/dist/{chunk-TRY7BJA4.js → chunk-3R7NQA3Z.js} +1 -1
  5. package/dist/{chunk-KGL3YMZA.js → chunk-AJ6UHXUA.js} +1 -1
  6. package/dist/{chunk-BAQRUYRL.js → chunk-EWZFANHJ.js} +1 -1
  7. package/dist/{chunk-K2MSIKMM.js → chunk-FFXXGCVG.js} +1 -1
  8. package/dist/{chunk-WLPLHXNP.js → chunk-JNECYURT.js} +1 -1
  9. package/dist/{chunk-TFDR2YP2.js → chunk-KFCEXCZM.js} +1 -1
  10. package/dist/{chunk-IYQQXEHV.js → chunk-LDIPVPKI.js} +1 -1
  11. package/dist/{chunk-QSZW2I5Y.js → chunk-M3T5JYDJ.js} +15 -8
  12. package/dist/{chunk-Q3VYRU5R.js → chunk-MB6R4XPZ.js} +1 -1
  13. package/dist/{chunk-IBX2ORBV.js → chunk-MMGSYMIC.js} +1 -1
  14. package/dist/{chunk-LFVIZH2G.js → chunk-MU3IE434.js} +278 -152
  15. package/dist/{chunk-OIP44KBB.js → chunk-QGNXYVBO.js} +47 -12
  16. package/dist/{chunk-YYRY32NR.js → chunk-STJBBVNL.js} +2 -2
  17. package/dist/{chunk-73C4JN2E.js → chunk-SYBFMHXQ.js} +381 -87
  18. package/dist/{chunk-WB3E7KE7.js → chunk-VMHYGKWT.js} +1 -1
  19. package/dist/{chunk-GAZBBMAA.js → chunk-VTHYQCDB.js} +1 -1
  20. package/dist/{chunk-LW7KZQHG.js → chunk-VUGEEMLT.js} +1 -1
  21. package/dist/{chunk-HC4I7LAV.js → chunk-W3VGCNG6.js} +1 -1
  22. package/dist/{chunk-ZBQKXAYK.js → chunk-YOSZIWC3.js} +1 -1
  23. package/dist/{content-retention-CVBYehRS.d.ts → content-retention-CrILCNxk.d.ts} +1 -1
  24. package/dist/{credit-ledger-CZQ56DYI.js → credit-ledger-4PZNAMDT.js} +3 -3
  25. package/dist/{credit-menu-QntEhZJS.d.ts → credit-menu-BWsVqMh-.d.ts} +6 -4
  26. package/dist/{fx-CMyNFenZ.d.ts → fx-BM5h4o5S.d.ts} +1 -1
  27. package/dist/index.d.ts +5 -5
  28. package/dist/index.js +4 -4
  29. package/dist/internal/caller.d.ts +7 -7
  30. package/dist/internal/caller.js +7 -7
  31. package/dist/internal/server.d.ts +7 -7
  32. package/dist/internal/server.js +20 -20
  33. package/dist/{job-store-qOD-FrQF.d.ts → job-store-92v8e1LQ.d.ts} +1 -1
  34. package/dist/{lightning-backend-DtdG6UT5.d.ts → lightning-backend-9oky_wJi.d.ts} +1 -1
  35. package/dist/{memory-credit-ledger-EMN7G3MO.js → memory-credit-ledger-RP7DT5IY.js} +4 -4
  36. package/dist/{mpp-setup-VW53KFPO.js → mpp-setup-FURD45LI.js} +3 -3
  37. package/dist/{payout-reporter-TZX2S7KG.js → payout-reporter-HVJ6WUF3.js} +2 -2
  38. package/dist/{postgres-consumed-credential-store-V464OAJB.js → postgres-consumed-credential-store-WO6OCFXZ.js} +1 -1
  39. package/dist/{postgres-job-store-27VOCSPO.js → postgres-job-store-H45PRBLA.js} +2 -2
  40. package/dist/{postgres-replay-store-7GJFAQXY.js → postgres-replay-store-XXJSA457.js} +2 -2
  41. package/dist/{pricing-NNMBNP7N.js → pricing-X4XU5HXY.js} +3 -3
  42. package/dist/{revenue-reporter-4EAVPWXS.js → revenue-reporter-EV3K5L6B.js} +2 -2
  43. package/dist/server/index.d.ts +75 -11
  44. package/dist/server/index.js +65 -27
  45. package/dist/{step-cache-B7svmPz3.d.ts → step-cache--7yA5Ihr.d.ts} +48 -6
  46. package/dist/{tempo-charge-store-2RPOJBM2.js → tempo-charge-store-5JOIYUIH.js} +2 -2
  47. package/dist/{tempo-session-store-LI3Q3A3U.js → tempo-session-store-S6QMLQUA.js} +3 -3
  48. package/dist/testing/index.d.ts +3 -3
  49. package/dist/testing/index.js +6 -6
  50. package/dist/{usd-D3izFz71.d.ts → usd-C7lvLvLk.d.ts} +1 -1
  51. package/dist/{x402-SL36LSOD.js → x402-EN5LSOVM.js} +3 -3
  52. package/package.json +1 -1
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-COYKJRMM.js";
8
8
  import {
9
9
  diagnosticConsole
10
- } from "./chunk-OIP44KBB.js";
10
+ } from "./chunk-QGNXYVBO.js";
11
11
 
12
12
  // src/sdk/server/postgres-job-store.ts
13
13
  import { createHash } from "crypto";
@@ -483,7 +483,16 @@ var PostgresJobStore = class {
483
483
  held.client.release();
484
484
  }
485
485
  async save(record) {
486
- await this.saveRecord(record, record[JOB_DVM_ID]);
486
+ const dvmId = record[JOB_DVM_ID];
487
+ for (let attempt = 0; ; attempt++) {
488
+ try {
489
+ await this.saveRecord(record, dvmId);
490
+ return;
491
+ } catch (error) {
492
+ if (attempt >= 7 || !await this.canRetrySnapshot(error, record)) throw error;
493
+ await new Promise((resolve) => setTimeout(resolve, 5 * (attempt + 1)));
494
+ }
495
+ }
487
496
  }
488
497
  /** Persist a job while retaining its mount identity for cost-report recovery. */
489
498
  async saveForDvm(record, dvmId) {
@@ -495,6 +504,17 @@ var PostgresJobStore = class {
495
504
  delete scoped[JOB_DVM_ID];
496
505
  }
497
506
  }
507
+ async canRetrySnapshot(error, record) {
508
+ if (error === null || typeof error !== "object") return false;
509
+ const { code, constraint } = error;
510
+ if (code === "40P01") return true;
511
+ if (code !== "23505" || constraint !== "idx_jobs_request_id_caller") return false;
512
+ const { rows } = await this.pool.query(
513
+ "SELECT id FROM jobs WHERE requester_pubkey=$1 AND request_id=$2",
514
+ [record.requesterPubkey, record.requestId]
515
+ );
516
+ return rows[0]?.id === record.id;
517
+ }
498
518
  async saveRecord(record, dvmId) {
499
519
  const now = Date.now();
500
520
  const write = (q) => q.query(
@@ -642,14 +662,14 @@ var PostgresJobStore = class {
642
662
  ]
643
663
  );
644
664
  let rowCount;
645
- if (this.hostingCleanupFence) {
646
- const tx = await this.pool.connect();
647
- try {
648
- await tx.query("BEGIN");
649
- const existing = await tx.query(
650
- "SELECT dvm_id FROM jobs WHERE id=$1 FOR UPDATE",
651
- [record.id]
652
- );
665
+ const tx = await this.pool.connect();
666
+ try {
667
+ await tx.query("BEGIN");
668
+ const existing = await tx.query(
669
+ "SELECT dvm_id FROM jobs WHERE id=$1 FOR UPDATE",
670
+ [record.id]
671
+ );
672
+ if (this.hostingCleanupFence) {
653
673
  if (existing.rows[0]) {
654
674
  if (existing.rows[0].dvm_id !== null && existing.rows[0].dvm_id !== this.hostingCleanupFence.dvmId) {
655
675
  throw new Error("Hosted job belongs to another DVM");
@@ -657,16 +677,14 @@ var PostgresJobStore = class {
657
677
  } else {
658
678
  await this.hostingCleanupFence.assertNewIntent(tx, { jobId: record.id });
659
679
  }
660
- ({ rowCount } = await write(tx));
661
- await tx.query("COMMIT");
662
- } catch (error) {
663
- await tx.query("ROLLBACK").catch(() => void 0);
664
- throw error;
665
- } finally {
666
- tx.release();
667
680
  }
668
- } else {
669
- ({ rowCount } = await write(this.pool));
681
+ ({ rowCount } = await write(tx));
682
+ await tx.query("COMMIT");
683
+ } catch (error) {
684
+ await tx.query("ROLLBACK").catch(() => void 0);
685
+ throw error;
686
+ } finally {
687
+ tx.release();
670
688
  }
671
689
  if (rowCount === 0) {
672
690
  diagnosticConsole.warn(
@@ -1393,8 +1411,12 @@ var PostgresJobStore = class {
1393
1411
  return true;
1394
1412
  }
1395
1413
  async deleteResolvedMessages(jobId) {
1396
- await this.pool.query(this.hostingCleanupFence ? `DELETE FROM job_messages WHERE job_id=$1 AND NOT (
1397
- data->>'type'='payment' AND status IN ('pending-verification','failed-verify'))` : "DELETE FROM job_messages WHERE job_id=$1", [jobId]);
1414
+ await this.pool.query(
1415
+ `DELETE FROM job_messages WHERE job_id=$1 AND NOT (
1416
+ data->>'type'='payment' AND (status='pending-verification'
1417
+ OR ($2::boolean AND status='failed-verify')))`,
1418
+ [jobId, !!this.hostingCleanupFence]
1419
+ );
1398
1420
  }
1399
1421
  async fetchCountersTx(client, jobId) {
1400
1422
  const { rows } = await client.query(
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-UKD3R2KU.js";
8
8
  import {
9
9
  diagnosticConsole
10
- } from "./chunk-OIP44KBB.js";
10
+ } from "./chunk-QGNXYVBO.js";
11
11
 
12
12
  // src/sdk/server/zod-error.ts
13
13
  function humanizeZodError(err, opts) {
@@ -2,7 +2,7 @@ import {
2
2
  createX402FacilitatorAuthHeaders,
3
3
  settleWithFacilitator,
4
4
  verifyWithFacilitator
5
- } from "./chunk-GAZBBMAA.js";
5
+ } from "./chunk-VTHYQCDB.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-OIP44KBB.js";
18
+ } from "./chunk-QGNXYVBO.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 }) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  emitDiagnostic,
3
3
  projectDiagnosticFields
4
- } from "./chunk-OIP44KBB.js";
4
+ } from "./chunk-QGNXYVBO.js";
5
5
 
6
6
  // src/sdk/logger.ts
7
7
  function createConsoleLogger(_jobId) {
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  diagnosticConsole,
6
6
  projectSpanRow
7
- } from "./chunk-OIP44KBB.js";
7
+ } from "./chunk-QGNXYVBO.js";
8
8
 
9
9
  // src/lib/x402/env.ts
10
10
  import { isAddress } from "viem";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-COYKJRMM.js";
4
4
  import {
5
5
  diagnosticConsole
6
- } from "./chunk-OIP44KBB.js";
6
+ } from "./chunk-QGNXYVBO.js";
7
7
 
8
8
  // src/sdk/server/postgres-replay-store.ts
9
9
  var DEFAULT_TABLE_NAME = "signed_request_replays";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-COYKJRMM.js";
4
4
  import {
5
5
  diagnosticConsole
6
- } from "./chunk-OIP44KBB.js";
6
+ } from "./chunk-QGNXYVBO.js";
7
7
 
8
8
  // src/sdk/server/payout-reporter.ts
9
9
  import { createHash, randomUUID } from "crypto";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  validateCurrency
3
- } from "./chunk-HC4I7LAV.js";
3
+ } from "./chunk-W3VGCNG6.js";
4
4
 
5
5
  // src/sdk/pricing/upfront.ts
6
6
  function buildUpfront(input) {
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-FUJ36YDV.js";
9
9
  import {
10
10
  loggers
11
- } from "./chunk-QSZW2I5Y.js";
11
+ } from "./chunk-M3T5JYDJ.js";
12
12
 
13
13
  // src/sdk/server/job-store.ts
14
14
  function accumulateAskedTopUp(prior, ask) {
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-COYKJRMM.js";
8
8
  import {
9
9
  diagnosticConsole
10
- } from "./chunk-OIP44KBB.js";
10
+ } from "./chunk-QGNXYVBO.js";
11
11
 
12
12
  // src/sdk/server/tempo-charge-store.ts
13
13
  import { Credential } from "mppx";
@@ -7,7 +7,7 @@ import {
7
7
  extendDiagnosticIdentityAuthority,
8
8
  projectDiagnosticFields,
9
9
  projectSpanRow
10
- } from "./chunk-OIP44KBB.js";
10
+ } from "./chunk-QGNXYVBO.js";
11
11
 
12
12
  // src/observability/context.ts
13
13
  import { AsyncLocalStorage } from "async_hooks";
@@ -163,7 +163,8 @@ async function withSpan(opts, fn) {
163
163
  attributeInput,
164
164
  opts.dataset,
165
165
  authority,
166
- identityAuthority
166
+ identityAuthority,
167
+ opts.name
167
168
  );
168
169
  const childDimensions = bindDiagnosticIdentityAuthority(
169
170
  bindDiagnosticCapabilityAuthority(
@@ -172,13 +173,15 @@ async function withSpan(opts, fn) {
172
173
  ctx.dimensions,
173
174
  opts.dataset,
174
175
  authority,
175
- identityAuthority
176
+ identityAuthority,
177
+ opts.name
176
178
  ),
177
179
  ...projectDiagnosticFields(
178
180
  opts.dims,
179
181
  opts.dataset,
180
182
  authority,
181
- identityAuthority
183
+ identityAuthority,
184
+ opts.name
182
185
  )
183
186
  },
184
187
  authority
@@ -203,7 +206,8 @@ async function withSpan(opts, fn) {
203
206
  { ...attributes, ...identityCandidates },
204
207
  opts.dataset,
205
208
  authority,
206
- latestIdentityAuthority()
209
+ latestIdentityAuthority(),
210
+ opts.name
207
211
  );
208
212
  };
209
213
  const emitRow = () => {
@@ -227,7 +231,8 @@ async function withSpan(opts, fn) {
227
231
  childCtx.dimensions,
228
232
  opts.dataset,
229
233
  authority,
230
- activeIdentityAuthority
234
+ activeIdentityAuthority,
235
+ opts.name
231
236
  ),
232
237
  attributes,
233
238
  error_message: null,
@@ -263,7 +268,8 @@ async function withSpan(opts, fn) {
263
268
  overrides,
264
269
  opts.dataset,
265
270
  authority,
266
- latestIdentityAuthority()
271
+ latestIdentityAuthority(),
272
+ opts.name
267
273
  )
268
274
  };
269
275
  }
@@ -284,7 +290,8 @@ async function withSpan(opts, fn) {
284
290
  nextAttributes,
285
291
  opts.dataset,
286
292
  authority,
287
- latestIdentityAuthority()
293
+ latestIdentityAuthority(),
294
+ opts.name
288
295
  );
289
296
  if (nextStatus === "ok" || nextStatus === "error") status = nextStatus;
290
297
  if (nextLevel === "info" || nextLevel === "warn" || nextLevel === "error") {
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-COYKJRMM.js";
8
8
  import {
9
9
  withPostgresTransactionRecovery
10
- } from "./chunk-IBX2ORBV.js";
10
+ } from "./chunk-MMGSYMIC.js";
11
11
 
12
12
  // src/sdk/server/tempo-session-store.ts
13
13
  import { AsyncLocalStorage } from "async_hooks";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  diagnosticConsole
3
- } from "./chunk-OIP44KBB.js";
3
+ } from "./chunk-QGNXYVBO.js";
4
4
 
5
5
  // src/lib/pg-retry.ts
6
6
  import { AsyncLocalStorage } from "async_hooks";