@dvmkit/dvm-cli 0.2.0 → 0.3.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/README.md +7 -1
- package/dist/{chunk-OWJZYYMG.js → chunk-24VB7FR7.js} +44 -14
- package/dist/{chunk-G5C6E6PJ.js → chunk-R4MSO2GX.js} +8198 -8191
- package/dist/{chunk-EGY4KDBW.js → chunk-SKKZ4OAA.js} +9 -2
- package/dist/{chunk-4JXFXP4Y.js → chunk-V2BE4E5V.js} +5 -2
- package/dist/{chunk-6CC6JGEU.js → chunk-VY277ROG.js} +1 -1
- package/dist/{chunk-ZJYO7OLO.js → chunk-XN4YSEO6.js} +89 -11
- package/dist/{chunk-ECK465AY.js → chunk-YLWATJ7F.js} +9 -9
- package/dist/{chunk-N7MGIK2U.js → chunk-Z75N4GTG.js} +58390 -54920
- package/dist/dvm.js +4642 -28934
- package/dist/{internal-JDG52DJH.js → internal-OBEYRHMV.js} +31 -23
- package/dist/{payout-reporter-3UB5WRCV-XTVZFIAO.js → payout-reporter-RG6XNGPI-KNY74HLM.js} +1 -1
- package/dist/{pocket-refill-QJMMD6QN.js → pocket-refill-NXTJIVB5.js} +8 -8
- package/dist/{revenue-reporter-JIKUPXOK-TYUBTF4P.js → revenue-reporter-ASZ7SHHH-ISAMJDZQ.js} +1 -1
- package/dist/{tempo-lifecycle-SQL3KLEZ-AATA2SKI.js → tempo-lifecycle-DFIXQ54Q-LNXPKWK5.js} +4 -4
- package/dist/{tempo-wallet-QOLEIPCV-SWCXRBDS.js → tempo-wallet-4QKSV65O-J6ZZQAD7.js} +10 -2
- package/dist/{x402-FTG2GRAQ-UGAUMUL6.js → x402-5H27DCBE-UEQQQ5UY.js} +5 -5
- package/package.json +5 -6
- package/skills/dvm/SKILL.md +4 -2
|
@@ -4279,7 +4279,7 @@ var schnorr = /* @__PURE__ */ (() => {
|
|
|
4279
4279
|
};
|
|
4280
4280
|
})();
|
|
4281
4281
|
|
|
4282
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
4282
|
+
// node_modules/@dvmkit/sdk/dist/chunk-CGKZDODG.js
|
|
4283
4283
|
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
4284
4284
|
import {
|
|
4285
4285
|
appendFileSync,
|
|
@@ -4450,6 +4450,13 @@ function assertValidConfig(config, fields) {
|
|
|
4450
4450
|
const value = owner[leaf];
|
|
4451
4451
|
if (value === void 0 || !matchesKind(value, kind)) throw invalidFieldError(path, kind);
|
|
4452
4452
|
}
|
|
4453
|
+
if ((!scope || scope.has("tempo")) && isPlainObject(record.tempo) && record.tempo.network !== void 0 && record.tempo.network !== "mainnet" && record.tempo.network !== "moderato") {
|
|
4454
|
+
throw new DvmError(
|
|
4455
|
+
"config_invalid",
|
|
4456
|
+
`The caller configuration field 'tempo.network' must be 'mainnet' or 'moderato'.`,
|
|
4457
|
+
`Correct tempo.network in ${CONFIG_FILE}.${rollbackSuffix()}`
|
|
4458
|
+
);
|
|
4459
|
+
}
|
|
4453
4460
|
}
|
|
4454
4461
|
function readRawConfig() {
|
|
4455
4462
|
if (!existsSync(CONFIG_FILE)) return null;
|
|
@@ -4577,7 +4584,7 @@ var PROTECTED_FIELDS = {
|
|
|
4577
4584
|
var CONFIG_PATH_SHAPE = {
|
|
4578
4585
|
float: { statedBudget: {}, connectedAt: {}, alias: {}, methods: {} },
|
|
4579
4586
|
x402: { privateKey: {}, network: {} },
|
|
4580
|
-
tempo: { method: {}, accountId: {}, apiKey: {} },
|
|
4587
|
+
tempo: { method: {}, accountId: {}, apiKey: {}, network: {} },
|
|
4581
4588
|
credit: {
|
|
4582
4589
|
targetJobs: {},
|
|
4583
4590
|
posture: {},
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
withSdkInitLock
|
|
6
6
|
} from "./chunk-3SWX5BQP.js";
|
|
7
7
|
|
|
8
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
8
|
+
// node_modules/@dvmkit/sdk/dist/chunk-6BQM7TOW.js
|
|
9
9
|
import { createHash, randomUUID } from "crypto";
|
|
10
10
|
var MemoryX402BatchStore = class {
|
|
11
11
|
batches = /* @__PURE__ */ new Map();
|
|
@@ -143,6 +143,7 @@ var PayoutReporter = class {
|
|
|
143
143
|
ownsBatchStore;
|
|
144
144
|
intervalMs;
|
|
145
145
|
now;
|
|
146
|
+
lastX402SnapshotAt = 0;
|
|
146
147
|
x402;
|
|
147
148
|
tempo;
|
|
148
149
|
timer = null;
|
|
@@ -575,6 +576,8 @@ var PayoutReporter = class {
|
|
|
575
576
|
async snapshotX402() {
|
|
576
577
|
const ctx = this.x402;
|
|
577
578
|
if (!ctx) return;
|
|
579
|
+
const snapshotAt = Math.max(this.now(), this.lastX402SnapshotAt + 1);
|
|
580
|
+
this.lastX402SnapshotAt = snapshotAt;
|
|
578
581
|
try {
|
|
579
582
|
const pools = [];
|
|
580
583
|
const wedged = [];
|
|
@@ -630,7 +633,7 @@ var PayoutReporter = class {
|
|
|
630
633
|
items: pools.length,
|
|
631
634
|
pools,
|
|
632
635
|
wedged,
|
|
633
|
-
snapshotAt
|
|
636
|
+
snapshotAt
|
|
634
637
|
});
|
|
635
638
|
} catch (err) {
|
|
636
639
|
warn("payout_pending_snapshot_failed", { rail: "x402", error: message(err) });
|
|
@@ -5,16 +5,36 @@ import {
|
|
|
5
5
|
withSdkInitLock
|
|
6
6
|
} from "./chunk-3SWX5BQP.js";
|
|
7
7
|
|
|
8
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
8
|
+
// node_modules/@dvmkit/sdk/dist/chunk-EVBK675R.js
|
|
9
9
|
import { randomUUID } from "crypto";
|
|
10
10
|
var ENDPOINTS = {
|
|
11
11
|
revenue: "/_internal/job-revenue",
|
|
12
|
+
cost: "/_internal/job-cost",
|
|
12
13
|
deposit: "/_internal/credit-deposit",
|
|
13
14
|
release: "/_internal/credit-draw-release",
|
|
14
15
|
drain: "/_internal/credit-drain",
|
|
15
16
|
payout: "/_internal/payout",
|
|
16
17
|
expiry_release: "/_internal/credit-expiry-release"
|
|
17
18
|
};
|
|
19
|
+
var PENDING_DVM_REPORTS_TABLE = "pending_dvm_reports";
|
|
20
|
+
var LEGACY_PENDING_REPORTS_TABLE = "pending_revenue_reports";
|
|
21
|
+
var SDK_REPORT_TABLE_BASE_COLUMNS = [
|
|
22
|
+
"id",
|
|
23
|
+
"payload",
|
|
24
|
+
"retry_count",
|
|
25
|
+
"next_retry_at",
|
|
26
|
+
"stale",
|
|
27
|
+
"created_at"
|
|
28
|
+
];
|
|
29
|
+
var PLATFORM_REPORT_TABLE_COLUMNS = [
|
|
30
|
+
"id",
|
|
31
|
+
"payload",
|
|
32
|
+
"source",
|
|
33
|
+
"retry_count",
|
|
34
|
+
"next_retry_at",
|
|
35
|
+
"last_error",
|
|
36
|
+
"created_at"
|
|
37
|
+
];
|
|
18
38
|
var RevenueReporter = class _RevenueReporter {
|
|
19
39
|
// 24h of failed retries
|
|
20
40
|
constructor(db, platformUrl, platformToken) {
|
|
@@ -30,14 +50,14 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
30
50
|
static MAX_BACKOFF_MS = 3e5;
|
|
31
51
|
// 5 min
|
|
32
52
|
static ABANDON_AFTER_MS = 24 * 60 * 60 * 1e3;
|
|
33
|
-
/** Create the pending-reports table (idempotent). */
|
|
53
|
+
/** Create the pending-reports table and migrate the legacy SDK outbox (idempotent). */
|
|
34
54
|
async init() {
|
|
35
55
|
await withSdkInitLock(this.db, () => this.createTables());
|
|
36
56
|
}
|
|
37
57
|
/** The boot DDL itself — always runs under {@link withSdkInitLock} (internal-review). */
|
|
38
58
|
async createTables() {
|
|
39
59
|
await this.db.query(`
|
|
40
|
-
CREATE TABLE IF NOT EXISTS
|
|
60
|
+
CREATE TABLE IF NOT EXISTS ${PENDING_DVM_REPORTS_TABLE} (
|
|
41
61
|
id TEXT PRIMARY KEY,
|
|
42
62
|
payload JSONB NOT NULL,
|
|
43
63
|
retry_count INTEGER NOT NULL DEFAULT 0,
|
|
@@ -48,17 +68,75 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
48
68
|
kind TEXT NOT NULL DEFAULT 'revenue'
|
|
49
69
|
)
|
|
50
70
|
`);
|
|
71
|
+
await this.assertSdkTableShape(PENDING_DVM_REPORTS_TABLE);
|
|
51
72
|
await this.db.query(
|
|
52
|
-
|
|
73
|
+
`ALTER TABLE ${PENDING_DVM_REPORTS_TABLE} ADD COLUMN IF NOT EXISTS stale_reason TEXT`
|
|
53
74
|
);
|
|
54
75
|
await this.db.query(
|
|
55
|
-
|
|
76
|
+
`ALTER TABLE ${PENDING_DVM_REPORTS_TABLE} ADD COLUMN IF NOT EXISTS kind TEXT NOT NULL DEFAULT 'revenue'`
|
|
56
77
|
);
|
|
78
|
+
await this.migrateLegacySdkOutbox();
|
|
79
|
+
}
|
|
80
|
+
/** Copy rows from the old SDK-owned table without touching the platform's table of that name. */
|
|
81
|
+
async migrateLegacySdkOutbox() {
|
|
82
|
+
const columns = await this.tableColumns(LEGACY_PENDING_REPORTS_TABLE);
|
|
83
|
+
if (columns.size === 0) return;
|
|
84
|
+
if (PLATFORM_REPORT_TABLE_COLUMNS.every((column) => columns.has(column))) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.assertSdkColumns(LEGACY_PENDING_REPORTS_TABLE, columns);
|
|
88
|
+
await this.db.query(
|
|
89
|
+
`ALTER TABLE ${LEGACY_PENDING_REPORTS_TABLE} ADD COLUMN IF NOT EXISTS stale_reason TEXT`
|
|
90
|
+
);
|
|
91
|
+
await this.db.query(
|
|
92
|
+
`ALTER TABLE ${LEGACY_PENDING_REPORTS_TABLE} ADD COLUMN IF NOT EXISTS kind TEXT NOT NULL DEFAULT 'revenue'`
|
|
93
|
+
);
|
|
94
|
+
await this.db.query(`
|
|
95
|
+
WITH copied AS (
|
|
96
|
+
INSERT INTO ${PENDING_DVM_REPORTS_TABLE}
|
|
97
|
+
(id, payload, retry_count, next_retry_at, stale, stale_reason, created_at, kind)
|
|
98
|
+
SELECT id, payload, retry_count, next_retry_at, stale, stale_reason, created_at, kind
|
|
99
|
+
FROM ${LEGACY_PENDING_REPORTS_TABLE}
|
|
100
|
+
ON CONFLICT (id) DO NOTHING
|
|
101
|
+
RETURNING id
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
DELETE FROM ${LEGACY_PENDING_REPORTS_TABLE} AS legacy
|
|
105
|
+
WHERE EXISTS (SELECT 1 FROM copied WHERE copied.id = legacy.id)
|
|
106
|
+
OR EXISTS (
|
|
107
|
+
SELECT 1 FROM ${PENDING_DVM_REPORTS_TABLE} AS migrated
|
|
108
|
+
WHERE migrated.id = legacy.id
|
|
109
|
+
)
|
|
110
|
+
`);
|
|
111
|
+
}
|
|
112
|
+
/** Refuse a pre-existing relation whose columns cannot safely serve as the SDK outbox. */
|
|
113
|
+
async assertSdkTableShape(tableName) {
|
|
114
|
+
this.assertSdkColumns(tableName, await this.tableColumns(tableName));
|
|
115
|
+
}
|
|
116
|
+
assertSdkColumns(tableName, columns) {
|
|
117
|
+
const matchesSdk = SDK_REPORT_TABLE_BASE_COLUMNS.every((column) => columns.has(column)) && !columns.has("source");
|
|
118
|
+
if (matchesSdk) return;
|
|
119
|
+
throw new Error(
|
|
120
|
+
`RevenueReporter.init(): table "${tableName}" is not the SDK revenue outbox shape. The SDK owns "${PENDING_DVM_REPORTS_TABLE}"; the platform owns "${LEGACY_PENDING_REPORTS_TABLE}". Refusing to boot before credit funding can reach a mismatched outbox. Found columns: ${[...columns].sort().join(", ") || "none"}.`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
async tableColumns(tableName) {
|
|
124
|
+
const { rows } = await this.db.query(
|
|
125
|
+
`SELECT column_name
|
|
126
|
+
FROM information_schema.columns
|
|
127
|
+
WHERE table_schema = current_schema() AND table_name = $1`,
|
|
128
|
+
[tableName]
|
|
129
|
+
);
|
|
130
|
+
return new Set(rows.map((row) => row.column_name));
|
|
57
131
|
}
|
|
58
132
|
/** Persist a revenue report and attempt immediate delivery. */
|
|
59
133
|
async report(payload) {
|
|
60
134
|
return this.enqueue("revenue", payload, payload.jobId);
|
|
61
135
|
}
|
|
136
|
+
/** Persist a zero-revenue job cost and attempt immediate delivery. */
|
|
137
|
+
async reportCost(payload) {
|
|
138
|
+
return this.enqueue("cost", payload, payload.jobId);
|
|
139
|
+
}
|
|
62
140
|
/**
|
|
63
141
|
* Join a credit deposit to the caller-owned rail transaction.
|
|
64
142
|
*
|
|
@@ -370,7 +448,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
370
448
|
async getQueueStats() {
|
|
371
449
|
const { rows } = await this.db.query(
|
|
372
450
|
`SELECT stale, stale_reason, COUNT(*)::int AS count
|
|
373
|
-
FROM
|
|
451
|
+
FROM ${PENDING_DVM_REPORTS_TABLE}
|
|
374
452
|
GROUP BY stale, stale_reason`
|
|
375
453
|
);
|
|
376
454
|
let liveRetry = 0;
|
|
@@ -397,7 +475,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
397
475
|
async drainPending() {
|
|
398
476
|
try {
|
|
399
477
|
const { rows } = await this.db.query(
|
|
400
|
-
`SELECT id, payload, retry_count, created_at, kind FROM
|
|
478
|
+
`SELECT id, payload, retry_count, created_at, kind FROM ${PENDING_DVM_REPORTS_TABLE}
|
|
401
479
|
WHERE stale = false AND next_retry_at <= $1
|
|
402
480
|
ORDER BY created_at LIMIT 10`,
|
|
403
481
|
[Date.now()]
|
|
@@ -431,7 +509,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
431
509
|
_RevenueReporter.MAX_BACKOFF_MS
|
|
432
510
|
);
|
|
433
511
|
await this.db.query(
|
|
434
|
-
`UPDATE
|
|
512
|
+
`UPDATE ${PENDING_DVM_REPORTS_TABLE}
|
|
435
513
|
SET retry_count = $1, next_retry_at = $2
|
|
436
514
|
WHERE id = $3`,
|
|
437
515
|
[retryCount, Date.now() + backoff, row.id]
|
|
@@ -452,7 +530,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
452
530
|
async insertPending(q, kind, payload) {
|
|
453
531
|
const id = randomUUID();
|
|
454
532
|
await q.query(
|
|
455
|
-
`INSERT INTO
|
|
533
|
+
`INSERT INTO ${PENDING_DVM_REPORTS_TABLE} (id, payload, created_at, kind)
|
|
456
534
|
VALUES ($1, $2, $3, $4)`,
|
|
457
535
|
[id, JSON.stringify(payload), Date.now(), kind]
|
|
458
536
|
);
|
|
@@ -479,7 +557,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
479
557
|
throw err;
|
|
480
558
|
}
|
|
481
559
|
if (res.ok) {
|
|
482
|
-
await this.db.query(
|
|
560
|
+
await this.db.query(`DELETE FROM ${PENDING_DVM_REPORTS_TABLE} WHERE id = $1`, [id]);
|
|
483
561
|
console.log(`[revenue-reporter] reported ${kind} ${label}`);
|
|
484
562
|
return;
|
|
485
563
|
}
|
|
@@ -503,7 +581,7 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
503
581
|
/** Mark a pending row terminal (stale) with a classification reason. */
|
|
504
582
|
async markStale(id, reason) {
|
|
505
583
|
await this.db.query(
|
|
506
|
-
|
|
584
|
+
`UPDATE ${PENDING_DVM_REPORTS_TABLE} SET stale = true, stale_reason = $1 WHERE id = $2`,
|
|
507
585
|
[reason, id]
|
|
508
586
|
);
|
|
509
587
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __dvmCreateRequire } from "node:module";
|
|
3
3
|
const require = __dvmCreateRequire(import.meta.url);
|
|
4
|
-
import {
|
|
5
|
-
connectedTempoAccount,
|
|
6
|
-
tempoBalanceCheckHint,
|
|
7
|
-
tempoTokenReference
|
|
8
|
-
} from "./chunk-OWJZYYMG.js";
|
|
9
4
|
import {
|
|
10
5
|
from as from2,
|
|
11
6
|
from2 as from3,
|
|
@@ -122,7 +117,12 @@ import {
|
|
|
122
117
|
maxAdvertisedMicro,
|
|
123
118
|
normalizeCreditEndpoint,
|
|
124
119
|
withinAdvertisedTolerance
|
|
125
|
-
} from "./chunk-
|
|
120
|
+
} from "./chunk-VY277ROG.js";
|
|
121
|
+
import {
|
|
122
|
+
connectedTempoAccount,
|
|
123
|
+
tempoBalanceCheckHint,
|
|
124
|
+
tempoTokenReference
|
|
125
|
+
} from "./chunk-24VB7FR7.js";
|
|
126
126
|
import {
|
|
127
127
|
DvmError,
|
|
128
128
|
IDENTITIES_FILE,
|
|
@@ -134,7 +134,7 @@ import {
|
|
|
134
134
|
resolveRpcHttpTransportOptions,
|
|
135
135
|
resolveRpcOverride,
|
|
136
136
|
schnorr
|
|
137
|
-
} from "./chunk-
|
|
137
|
+
} from "./chunk-SKKZ4OAA.js";
|
|
138
138
|
import {
|
|
139
139
|
privateKeyToAccount
|
|
140
140
|
} from "./chunk-EVQERRCP.js";
|
|
@@ -169,7 +169,7 @@ import {
|
|
|
169
169
|
__toESM
|
|
170
170
|
} from "./chunk-IYHTITNZ.js";
|
|
171
171
|
|
|
172
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
172
|
+
// node_modules/@dvmkit/sdk/dist/chunk-TQWGQCNV.js
|
|
173
173
|
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
174
174
|
import { existsSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "fs";
|
|
175
175
|
import { AsyncLocalStorage } from "async_hooks";
|
|
@@ -4010,7 +4010,7 @@ async function charge3(store, channelId, amount) {
|
|
|
4010
4010
|
return chargeSessionChannel({ store, channelId, amount });
|
|
4011
4011
|
}
|
|
4012
4012
|
|
|
4013
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
4013
|
+
// node_modules/@dvmkit/sdk/dist/chunk-TQWGQCNV.js
|
|
4014
4014
|
var import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
|
|
4015
4015
|
var DEFAULT_LOCK_STALE_MS = 3e4;
|
|
4016
4016
|
var DEFAULT_LOCK_RETRIES = 30;
|