@vapi-network/core 0.10.0 → 0.12.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 +198 -177
- package/dist/call-contracts-wire.d.ts +30 -0
- package/dist/call-contracts-wire.d.ts.map +1 -1
- package/dist/discovery.d.ts +2 -0
- package/dist/discovery.d.ts.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +399 -21
- package/dist/index.js.map +3 -3
- package/dist/link-state.d.ts +21 -0
- package/dist/link-state.d.ts.map +1 -0
- package/dist/listing-fee.d.ts +4 -0
- package/dist/listing-fee.d.ts.map +1 -0
- package/dist/marketplace-contracts.d.ts +168 -2
- package/dist/marketplace-contracts.d.ts.map +1 -1
- package/dist/remote-account.d.ts +29 -0
- package/dist/remote-account.d.ts.map +1 -0
- package/dist/router-client.d.ts +3 -1
- package/dist/router-client.d.ts.map +1 -1
- package/dist/router-client.js +218 -18
- package/dist/router-client.js.map +3 -3
- package/dist/secret-store.d.ts.map +1 -1
- package/dist/spend-cap-exceeded.d.ts +36 -0
- package/dist/spend-cap-exceeded.d.ts.map +1 -0
- package/dist/spend-policy.d.ts +12 -1
- package/dist/spend-policy.d.ts.map +1 -1
- package/dist/support-report.d.ts +1 -1
- package/dist/tasks.js +7 -3
- package/dist/tasks.js.map +1 -1
- package/dist/vault-setup.d.ts +13 -0
- package/dist/vault-setup.d.ts.map +1 -0
- package/dist/wallet-store.d.ts +5 -0
- package/dist/wallet-store.d.ts.map +1 -1
- package/dist/x402-pay.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38791,6 +38791,32 @@ var listingLivenessSchema = external_exports.looseObject({
|
|
|
38791
38791
|
latencyP95Ms: external_exports.number().nonnegative().nullable(),
|
|
38792
38792
|
checks7d: external_exports.number().int().nonnegative()
|
|
38793
38793
|
});
|
|
38794
|
+
var LISTING_HEALTH_STATES = ["healthy", "degraded", "outage", "unknown"];
|
|
38795
|
+
var listingHealthStateSchema = external_exports.enum(LISTING_HEALTH_STATES).catch("unknown");
|
|
38796
|
+
var listingHealthSchema = external_exports.looseObject({
|
|
38797
|
+
state: listingHealthStateSchema,
|
|
38798
|
+
uptime7d: external_exports.number().min(0).max(1).nullable().catch(null),
|
|
38799
|
+
latencyP50Ms: external_exports.number().nonnegative().nullable().catch(null),
|
|
38800
|
+
latencyP95Ms: external_exports.number().nonnegative().nullable().catch(null),
|
|
38801
|
+
checks7d: external_exports.number().int().nonnegative().catch(0)
|
|
38802
|
+
});
|
|
38803
|
+
var marketplaceAlternativeSchema = external_exports.looseObject({
|
|
38804
|
+
ref: external_exports.string().trim().min(1),
|
|
38805
|
+
reason: external_exports.enum(["cheaper", "healthier"])
|
|
38806
|
+
});
|
|
38807
|
+
var marketplaceAlternativesSchema = external_exports.preprocess((value) => {
|
|
38808
|
+
if (!Array.isArray(value)) return void 0;
|
|
38809
|
+
const alternatives = [];
|
|
38810
|
+
const refs = /* @__PURE__ */ new Set();
|
|
38811
|
+
for (const entry of value) {
|
|
38812
|
+
const parsed = marketplaceAlternativeSchema.safeParse(entry);
|
|
38813
|
+
if (!parsed.success || refs.has(parsed.data.ref)) continue;
|
|
38814
|
+
refs.add(parsed.data.ref);
|
|
38815
|
+
alternatives.push(parsed.data);
|
|
38816
|
+
if (alternatives.length === 2) break;
|
|
38817
|
+
}
|
|
38818
|
+
return alternatives.length > 0 ? alternatives : void 0;
|
|
38819
|
+
}, external_exports.array(marketplaceAlternativeSchema).optional());
|
|
38794
38820
|
var listingConformanceSchema = external_exports.looseObject({
|
|
38795
38821
|
declaredVersion: external_exports.union([external_exports.literal(1), external_exports.literal(2)]).nullable(),
|
|
38796
38822
|
versionConformant: external_exports.boolean(),
|
|
@@ -38822,7 +38848,8 @@ var marketplaceBadgeCodeSchema = external_exports.enum([
|
|
|
38822
38848
|
"vapi_verified",
|
|
38823
38849
|
"external_catalog",
|
|
38824
38850
|
"approved_vendor",
|
|
38825
|
-
"unverified"
|
|
38851
|
+
"unverified",
|
|
38852
|
+
"failed_calls_free"
|
|
38826
38853
|
]);
|
|
38827
38854
|
var marketplaceBadgeSchema = external_exports.looseObject({
|
|
38828
38855
|
code: marketplaceBadgeCodeSchema,
|
|
@@ -38863,6 +38890,8 @@ var firstPartyApiMarketplaceHitSchema = external_exports.looseObject({
|
|
|
38863
38890
|
...marketplaceHitBase,
|
|
38864
38891
|
kind: external_exports.literal("api"),
|
|
38865
38892
|
provenance: firstPartyProvenanceSchema,
|
|
38893
|
+
health: listingHealthSchema.optional().catch(void 0),
|
|
38894
|
+
alternatives: marketplaceAlternativesSchema.optional().catch(void 0),
|
|
38866
38895
|
execution: external_exports.looseObject({
|
|
38867
38896
|
mode: executionModeSchema
|
|
38868
38897
|
}),
|
|
@@ -38872,6 +38901,8 @@ var mirroredApiMarketplaceHitSchema = external_exports.looseObject({
|
|
|
38872
38901
|
...marketplaceHitBase,
|
|
38873
38902
|
kind: external_exports.literal("api"),
|
|
38874
38903
|
provenance: external_exports.literal("indexed"),
|
|
38904
|
+
health: listingHealthSchema.optional().catch(void 0),
|
|
38905
|
+
alternatives: marketplaceAlternativesSchema.optional().catch(void 0),
|
|
38875
38906
|
execution: external_exports.looseObject({
|
|
38876
38907
|
mode: external_exports.literal("direct"),
|
|
38877
38908
|
url: external_exports.url().max(2048).regex(/^https:\/\/(?![^/?#]*@)/),
|
|
@@ -38921,7 +38952,8 @@ var marketplaceDiscoveryInputSchema = external_exports.strictObject({
|
|
|
38921
38952
|
network: external_exports.string().trim().min(1).max(160).optional(),
|
|
38922
38953
|
cursor: external_exports.string().trim().min(1).max(4096).optional(),
|
|
38923
38954
|
limit: external_exports.number().int().min(1).max(50).optional(),
|
|
38924
|
-
includeUnverified: external_exports.boolean().optional()
|
|
38955
|
+
includeUnverified: external_exports.boolean().optional(),
|
|
38956
|
+
includeOutage: external_exports.boolean().optional()
|
|
38925
38957
|
}).superRefine((input2, context) => {
|
|
38926
38958
|
if (input2.kinds && new Set(input2.kinds).size !== input2.kinds.length) {
|
|
38927
38959
|
context.addIssue({
|
|
@@ -38939,7 +38971,14 @@ var marketplaceDiscoveryEnvelopeSchema = external_exports.looseObject({
|
|
|
38939
38971
|
items: external_exports.array(external_exports.unknown()),
|
|
38940
38972
|
nextCursor: external_exports.string().min(1).max(4096).nullable(),
|
|
38941
38973
|
unavailableKinds: external_exports.array(marketplaceKindSchema).max(MARKETPLACE_KINDS.length),
|
|
38942
|
-
|
|
38974
|
+
// The ranking label is informational: pinning it made every installed client
|
|
38975
|
+
// reject the page the day the registry re-ranked, so any label is accepted.
|
|
38976
|
+
rankingVersion: external_exports.string().trim().min(1).max(80),
|
|
38977
|
+
// `hiddenOutage` counts listings in outage the registry left out because
|
|
38978
|
+
// `includeOutage` was not set. Older registries send no totals at all.
|
|
38979
|
+
totals: external_exports.looseObject({
|
|
38980
|
+
hiddenOutage: external_exports.number().int().nonnegative().optional().catch(void 0)
|
|
38981
|
+
}).optional().catch(void 0)
|
|
38943
38982
|
});
|
|
38944
38983
|
var marketplaceDiscoveryPageSchema = marketplaceDiscoveryEnvelopeSchema.extend({
|
|
38945
38984
|
items: external_exports.array(marketplaceHitSchema)
|
|
@@ -45491,6 +45530,11 @@ var discoveryEndpointSchema = external_exports.looseObject({
|
|
|
45491
45530
|
operationId: external_exports.string().trim().min(1).optional(),
|
|
45492
45531
|
requestContentType: external_exports.string().trim().min(1).optional(),
|
|
45493
45532
|
requestSchema: external_exports.json().optional(),
|
|
45533
|
+
responseSchema: external_exports.json().optional().catch(void 0),
|
|
45534
|
+
exampleRequest: external_exports.looseObject({
|
|
45535
|
+
query: external_exports.record(external_exports.string(), external_exports.string()).optional().catch(void 0),
|
|
45536
|
+
body: external_exports.json().optional()
|
|
45537
|
+
}).optional().catch(void 0),
|
|
45494
45538
|
responseContentType: external_exports.string().trim().min(1).optional(),
|
|
45495
45539
|
pathTemplate: external_exports.string().trim().min(1).optional(),
|
|
45496
45540
|
pathParameters: external_exports.array(external_exports.string().trim().min(1)).optional(),
|
|
@@ -69694,7 +69738,7 @@ var POWERSHELL_MISSING = [
|
|
|
69694
69738
|
].join(" ");
|
|
69695
69739
|
function secretStore(options = {}) {
|
|
69696
69740
|
const platform2 = options.platform ?? process.platform;
|
|
69697
|
-
const run = options.run ?? spawnRunner;
|
|
69741
|
+
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
69698
69742
|
const env = options.env ?? process.env;
|
|
69699
69743
|
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
69700
69744
|
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
@@ -69888,6 +69932,7 @@ function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
|
69888
69932
|
].join("\n");
|
|
69889
69933
|
const execute = async (script2) => {
|
|
69890
69934
|
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
69935
|
+
|
|
69891
69936
|
`);
|
|
69892
69937
|
requirePowerShell(result);
|
|
69893
69938
|
return result;
|
|
@@ -70060,7 +70105,7 @@ function requireSuccess(result, what) {
|
|
|
70060
70105
|
function withoutTrailingNewline(value) {
|
|
70061
70106
|
return value.replace(/\r?\n$/u, "");
|
|
70062
70107
|
}
|
|
70063
|
-
var spawnRunner = async (file2, args, input2) => await new Promise((resolve2) => {
|
|
70108
|
+
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve2) => {
|
|
70064
70109
|
let stdout = "";
|
|
70065
70110
|
let stderr2 = "";
|
|
70066
70111
|
let settled = false;
|
|
@@ -70070,7 +70115,7 @@ var spawnRunner = async (file2, args, input2) => await new Promise((resolve2) =>
|
|
|
70070
70115
|
resolve2(outcome);
|
|
70071
70116
|
};
|
|
70072
70117
|
const child = spawn(file2, [...args], {
|
|
70073
|
-
detached:
|
|
70118
|
+
detached: platform2 !== "win32",
|
|
70074
70119
|
stdio: ["pipe", "pipe", "pipe"],
|
|
70075
70120
|
windowsHide: true
|
|
70076
70121
|
});
|
|
@@ -71645,6 +71690,17 @@ var WalletStore = class _WalletStore {
|
|
|
71645
71690
|
);
|
|
71646
71691
|
return account?.address ?? (await readKeystoreSummary(this.pathFor(target))).address;
|
|
71647
71692
|
}
|
|
71693
|
+
/**
|
|
71694
|
+
* Creates the vault without deriving an account, for apps that create every
|
|
71695
|
+
* account by name. Refuses when a vault already exists in this home.
|
|
71696
|
+
*/
|
|
71697
|
+
async createEmptyVault() {
|
|
71698
|
+
if (await this.readVaultUnlocked() !== void 0) {
|
|
71699
|
+
throw new KeystoreError("A vault already exists in this home.");
|
|
71700
|
+
}
|
|
71701
|
+
await this.openVault({ create: true });
|
|
71702
|
+
this.dropVaultCache();
|
|
71703
|
+
}
|
|
71648
71704
|
async create(name, passphrase, options = {}) {
|
|
71649
71705
|
void passphrase;
|
|
71650
71706
|
void options.enableSolana;
|
|
@@ -73315,12 +73371,14 @@ var ledgerFileSchema = external_exports.union([
|
|
|
73315
73371
|
ledgerRowSchema
|
|
73316
73372
|
]);
|
|
73317
73373
|
var SpendCapError = class extends Error {
|
|
73318
|
-
constructor(code, message) {
|
|
73374
|
+
constructor(code, message, details) {
|
|
73319
73375
|
super(message);
|
|
73320
73376
|
this.code = code;
|
|
73377
|
+
this.details = details;
|
|
73321
73378
|
this.name = "SpendCapError";
|
|
73322
73379
|
}
|
|
73323
73380
|
code;
|
|
73381
|
+
details;
|
|
73324
73382
|
};
|
|
73325
73383
|
function utcDateKey(now = /* @__PURE__ */ new Date()) {
|
|
73326
73384
|
return now.toISOString().slice(0, 10);
|
|
@@ -73402,7 +73460,8 @@ async function reserveSpend(amountAtomic, caps, options) {
|
|
|
73402
73460
|
if (amountAtomic > perCallAtomic) {
|
|
73403
73461
|
throw new SpendCapError(
|
|
73404
73462
|
"per_call_cap_exceeded",
|
|
73405
|
-
`Payment quote ${amountAtomic} atomic USDC exceeds the per-call cap ${perCallAtomic}. Refusing to sign
|
|
73463
|
+
`Payment quote ${amountAtomic} atomic USDC exceeds the per-call cap ${perCallAtomic}. Refusing to sign.`,
|
|
73464
|
+
{ amountAtomic, limitAtomic: perCallAtomic, wallet: options?.wallet }
|
|
73406
73465
|
);
|
|
73407
73466
|
}
|
|
73408
73467
|
}
|
|
@@ -73491,7 +73550,8 @@ async function reserveSpend(amountAtomic, caps, options) {
|
|
|
73491
73550
|
if (nextSpent > perDayAtomic) {
|
|
73492
73551
|
throw new SpendCapError(
|
|
73493
73552
|
"per_day_cap_exceeded",
|
|
73494
|
-
`${kind === "escrow-funding" ? "Escrow funding" : "Payment quote"} ${amountAtomic} atomic USDC would raise today's spend to ${nextSpent} for wallet ${wallet}, above the per-day cap ${perDayAtomic}. Refusing to sign
|
|
73553
|
+
`${kind === "escrow-funding" ? "Escrow funding" : "Payment quote"} ${amountAtomic} atomic USDC would raise today's spend to ${nextSpent} for wallet ${wallet}, above the per-day cap ${perDayAtomic}. Refusing to sign.`,
|
|
73554
|
+
{ amountAtomic, limitAtomic: perDayAtomic, spentAtomic: BigInt(spentAtomic), wallet }
|
|
73495
73555
|
);
|
|
73496
73556
|
}
|
|
73497
73557
|
const reservationId = options?.reservationId ?? (options?.taskKey === void 0 ? void 0 : randomBytes10(16).toString("hex"));
|
|
@@ -76350,6 +76410,96 @@ function parseAtomic(value, label) {
|
|
|
76350
76410
|
throw new Error(`Invalid ${label} atomic amount.`);
|
|
76351
76411
|
}
|
|
76352
76412
|
|
|
76413
|
+
// src/spend-cap-exceeded.ts
|
|
76414
|
+
var SpendCapExceededError = class extends Error {
|
|
76415
|
+
name = "SpendCapExceededError";
|
|
76416
|
+
code = "spend_cap_exceeded";
|
|
76417
|
+
retryable = false;
|
|
76418
|
+
cap;
|
|
76419
|
+
amountUsd;
|
|
76420
|
+
limitUsd;
|
|
76421
|
+
spentUsd;
|
|
76422
|
+
wallet;
|
|
76423
|
+
command;
|
|
76424
|
+
constructor(input2) {
|
|
76425
|
+
const amountUsd = normalizeUsd(input2.amountUsd);
|
|
76426
|
+
const limitUsd = normalizeUsd(input2.limitUsd);
|
|
76427
|
+
const spentUsd = input2.spentUsd === void 0 ? void 0 : normalizeUsd(input2.spentUsd);
|
|
76428
|
+
const wallet = input2.wallet?.trim() || void 0;
|
|
76429
|
+
const command = input2.command === void 0 ? spendCapCommand(input2.cap, amountUsd, spentUsd, wallet, input2.perDayLimitUsd) : input2.command;
|
|
76430
|
+
super(
|
|
76431
|
+
input2.message ?? spendCapMessage(input2.cap, amountUsd, limitUsd, spentUsd, wallet, command),
|
|
76432
|
+
input2.cause === void 0 ? void 0 : { cause: input2.cause }
|
|
76433
|
+
);
|
|
76434
|
+
this.cap = input2.cap;
|
|
76435
|
+
this.amountUsd = amountUsd;
|
|
76436
|
+
this.limitUsd = limitUsd;
|
|
76437
|
+
this.spentUsd = spentUsd;
|
|
76438
|
+
this.wallet = wallet;
|
|
76439
|
+
this.command = command;
|
|
76440
|
+
}
|
|
76441
|
+
toJSON() {
|
|
76442
|
+
return {
|
|
76443
|
+
code: this.code,
|
|
76444
|
+
cap: this.cap,
|
|
76445
|
+
amountUsd: this.amountUsd,
|
|
76446
|
+
limitUsd: this.limitUsd,
|
|
76447
|
+
...this.spentUsd === void 0 ? {} : { spentUsd: this.spentUsd },
|
|
76448
|
+
...this.wallet === void 0 ? {} : { wallet: this.wallet },
|
|
76449
|
+
command: this.command,
|
|
76450
|
+
message: this.message
|
|
76451
|
+
};
|
|
76452
|
+
}
|
|
76453
|
+
};
|
|
76454
|
+
function spendCapCommand(cap, amountUsd, spentUsd, wallet, perDayLimitUsd) {
|
|
76455
|
+
const account = wallet ?? "<account>";
|
|
76456
|
+
if (cap === "per_call") {
|
|
76457
|
+
const scale = Math.max(fractionLength(amountUsd), fractionLength(perDayLimitUsd ?? "0"));
|
|
76458
|
+
const raiseDay = perDayLimitUsd !== void 0 && parseDecimal(amountUsd, scale) > parseDecimal(perDayLimitUsd, scale);
|
|
76459
|
+
return `vapi accounts caps ${account} --per-call ${amountUsd}${raiseDay ? ` --per-day ${amountUsd}` : ""}`;
|
|
76460
|
+
}
|
|
76461
|
+
if (cap === "per_day") {
|
|
76462
|
+
return `vapi accounts caps ${account} --per-day ${addUsd(spentUsd ?? "0", amountUsd)}`;
|
|
76463
|
+
}
|
|
76464
|
+
if (cap === "max_price") {
|
|
76465
|
+
return `--max ${amountUsd}`;
|
|
76466
|
+
}
|
|
76467
|
+
if (cap === "run_budget") {
|
|
76468
|
+
const budget = addUsd(spentUsd ?? "0", amountUsd);
|
|
76469
|
+
return `--budget ${budget}`;
|
|
76470
|
+
}
|
|
76471
|
+
return null;
|
|
76472
|
+
}
|
|
76473
|
+
function spendCapMessage(cap, amountUsd, limitUsd, spentUsd, wallet, command) {
|
|
76474
|
+
const capName = cap === "per_call" ? "per-call spend cap" : cap === "per_day" ? "per-day spend cap" : cap === "max_price" ? "maximum price" : cap === "max_amount" ? "maximum amount" : "run budget";
|
|
76475
|
+
const account = cap === "per_call" || cap === "per_day" ? ` of account ${wallet ?? "<account>"}` : "";
|
|
76476
|
+
const payment = cap === "per_day" || cap === "run_budget" ? `this payment of $${amountUsd} would raise ${cap === "per_day" ? "today's spend" : "run spend"} from $${spentUsd ?? "0"} to $${addUsd(spentUsd ?? "0", amountUsd)}, above $${limitUsd}` : `this payment of $${amountUsd} exceeds the limit of $${limitUsd}`;
|
|
76477
|
+
const guidance = cap === "max_price" ? ` MCP call.pay takes maxPriceUsd. Raise the CLI maximum with:` : cap === "run_budget" ? " Raise it on vapi agent run or vapi swarm run with:" : " Raise it with:";
|
|
76478
|
+
const action = command === null ? "" : `${guidance} ${command}`;
|
|
76479
|
+
return `Blocked by the ${capName}${account}: ${payment}. Nothing was signed.${action}`;
|
|
76480
|
+
}
|
|
76481
|
+
function normalizeUsd(value) {
|
|
76482
|
+
const trimmed = value.trim();
|
|
76483
|
+
if (!trimmed.includes(".")) return trimmed;
|
|
76484
|
+
const normalized = trimmed.replace(/0+$/u, "").replace(/\.$/u, "");
|
|
76485
|
+
return normalized || "0";
|
|
76486
|
+
}
|
|
76487
|
+
function addUsd(left, right) {
|
|
76488
|
+
const scale = Math.max(fractionLength(left), fractionLength(right));
|
|
76489
|
+
const factor = 10n ** BigInt(scale);
|
|
76490
|
+
const total = parseDecimal(left, scale) + parseDecimal(right, scale);
|
|
76491
|
+
const whole = total / factor;
|
|
76492
|
+
const fraction = (total % factor).toString().padStart(scale, "0").replace(/0+$/u, "");
|
|
76493
|
+
return fraction ? `${whole}.${fraction}` : whole.toString();
|
|
76494
|
+
}
|
|
76495
|
+
function fractionLength(value) {
|
|
76496
|
+
return value.split(".")[1]?.length ?? 0;
|
|
76497
|
+
}
|
|
76498
|
+
function parseDecimal(value, scale) {
|
|
76499
|
+
const [whole = "0", fraction = ""] = value.split(".");
|
|
76500
|
+
return BigInt(whole) * 10n ** BigInt(scale) + BigInt(fraction.padEnd(scale, "0") || "0");
|
|
76501
|
+
}
|
|
76502
|
+
|
|
76353
76503
|
// src/swarm.ts
|
|
76354
76504
|
import { readdir as readdir6, readFile as readFile15, stat as stat11, unlink as unlink11 } from "node:fs/promises";
|
|
76355
76505
|
import { join as join12 } from "node:path";
|
|
@@ -77021,7 +77171,7 @@ function createRunBudget(args) {
|
|
|
77021
77171
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
77022
77172
|
import { arch, platform, release } from "node:os";
|
|
77023
77173
|
import { join as join13 } from "node:path";
|
|
77024
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
77174
|
+
var VAPI_CLIENT_VERSION = "0.12.0";
|
|
77025
77175
|
async function createSupportReport(options) {
|
|
77026
77176
|
const message = options.message.trim();
|
|
77027
77177
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
@@ -77216,8 +77366,28 @@ async function completeX402Payment(args) {
|
|
|
77216
77366
|
}
|
|
77217
77367
|
args.challenge.request.signal.throwIfAborted();
|
|
77218
77368
|
if (trace) trace.capsApplied = true;
|
|
77219
|
-
|
|
77220
|
-
|
|
77369
|
+
try {
|
|
77370
|
+
assertMaximumAtomic(quote.amountAtomic, args.maxAtomic);
|
|
77371
|
+
} catch (error61) {
|
|
77372
|
+
if (args.maxAtomic !== void 0 && isErrorCode(error61, "max_price_exceeded")) {
|
|
77373
|
+
throw paymentCapError("max_amount", quote.amountAtomic, args.maxAtomic, args, error61);
|
|
77374
|
+
}
|
|
77375
|
+
throw error61;
|
|
77376
|
+
}
|
|
77377
|
+
try {
|
|
77378
|
+
assertMaxPrice(quote.amountAtomic, args.maxPriceUsd);
|
|
77379
|
+
} catch (error61) {
|
|
77380
|
+
if (args.maxPriceUsd !== void 0 && isErrorCode(error61, "max_price_exceeded")) {
|
|
77381
|
+
throw paymentCapError(
|
|
77382
|
+
"max_price",
|
|
77383
|
+
quote.amountAtomic,
|
|
77384
|
+
usdToAtomic(args.maxPriceUsd),
|
|
77385
|
+
args,
|
|
77386
|
+
error61
|
|
77387
|
+
);
|
|
77388
|
+
}
|
|
77389
|
+
throw error61;
|
|
77390
|
+
}
|
|
77221
77391
|
const spendReservation = {
|
|
77222
77392
|
ledgerPath: args.ledgerPath ?? getVapiPaths().ledger,
|
|
77223
77393
|
now: args.now,
|
|
@@ -77226,18 +77396,42 @@ async function completeX402Payment(args) {
|
|
|
77226
77396
|
let reservationId;
|
|
77227
77397
|
let reservedOn;
|
|
77228
77398
|
if (args.runBudget === void 0) {
|
|
77229
|
-
|
|
77399
|
+
try {
|
|
77400
|
+
await reserveSpend(quote.amountAtomic, args.caps, spendReservation);
|
|
77401
|
+
} catch (error61) {
|
|
77402
|
+
throw walletCapError(error61, quote.amountAtomic, args);
|
|
77403
|
+
}
|
|
77230
77404
|
} else {
|
|
77231
77405
|
reservationId = args.paymentId ?? `x402_${randomBytes14(12).toString("hex")}`;
|
|
77232
|
-
|
|
77233
|
-
|
|
77234
|
-
|
|
77235
|
-
|
|
77406
|
+
let reservation;
|
|
77407
|
+
try {
|
|
77408
|
+
reservation = await reserveSpend(quote.amountAtomic, args.caps, {
|
|
77409
|
+
...spendReservation,
|
|
77410
|
+
reservationId
|
|
77411
|
+
});
|
|
77412
|
+
} catch (error61) {
|
|
77413
|
+
throw walletCapError(error61, quote.amountAtomic, args);
|
|
77414
|
+
}
|
|
77236
77415
|
reservedOn = reservation.date;
|
|
77237
77416
|
try {
|
|
77238
77417
|
args.runBudget.reserve(quote.amountAtomic, reservationId);
|
|
77239
77418
|
} catch (error61) {
|
|
77240
|
-
|
|
77419
|
+
let runSpentAtomic;
|
|
77420
|
+
try {
|
|
77421
|
+
runSpentAtomic = args.runBudget.spentAtomic();
|
|
77422
|
+
} finally {
|
|
77423
|
+
await releaseUnsentReservation(args, quote.amountAtomic, reservationId, reservedOn);
|
|
77424
|
+
}
|
|
77425
|
+
if (error61 instanceof RunBudgetError || isErrorCode(error61, "run_budget_exceeded")) {
|
|
77426
|
+
throw new SpendCapExceededError({
|
|
77427
|
+
cap: "run_budget",
|
|
77428
|
+
amountUsd: formatUsdc(quote.amountAtomic),
|
|
77429
|
+
limitUsd: formatUsdc(args.runBudget.limitAtomic),
|
|
77430
|
+
spentUsd: formatUsdc(runSpentAtomic),
|
|
77431
|
+
...args.wallet === void 0 ? {} : { wallet: args.wallet },
|
|
77432
|
+
cause: error61
|
|
77433
|
+
});
|
|
77434
|
+
}
|
|
77241
77435
|
throw error61;
|
|
77242
77436
|
}
|
|
77243
77437
|
}
|
|
@@ -77520,6 +77714,18 @@ function sanitizeThrownError(error61, secrets) {
|
|
|
77520
77714
|
if (!(error61 instanceof Error)) return error61;
|
|
77521
77715
|
const message = redactKnownSecrets(error61.message, secrets);
|
|
77522
77716
|
const cause = error61.cause === void 0 ? void 0 : sanitizeThrownError(error61.cause, secrets);
|
|
77717
|
+
if (error61 instanceof SpendCapExceededError) {
|
|
77718
|
+
return new SpendCapExceededError({
|
|
77719
|
+
cap: error61.cap,
|
|
77720
|
+
amountUsd: error61.amountUsd,
|
|
77721
|
+
limitUsd: error61.limitUsd,
|
|
77722
|
+
...error61.spentUsd === void 0 ? {} : { spentUsd: error61.spentUsd },
|
|
77723
|
+
...error61.wallet === void 0 ? {} : { wallet: error61.wallet },
|
|
77724
|
+
command: error61.command,
|
|
77725
|
+
message,
|
|
77726
|
+
...cause === void 0 ? {} : { cause }
|
|
77727
|
+
});
|
|
77728
|
+
}
|
|
77523
77729
|
if (message === error61.message && cause === error61.cause) return error61;
|
|
77524
77730
|
if (error61 instanceof X402Error) {
|
|
77525
77731
|
return new X402Error(error61.code, message, cause === void 0 ? void 0 : { cause });
|
|
@@ -77621,6 +77827,43 @@ function assertMaximumAtomic(amountAtomic, maxAtomic) {
|
|
|
77621
77827
|
);
|
|
77622
77828
|
}
|
|
77623
77829
|
}
|
|
77830
|
+
function walletCapError(error61, amountAtomic, args) {
|
|
77831
|
+
if (!(error61 instanceof SpendCapError)) return error61;
|
|
77832
|
+
if (error61.code === "per_call_cap_exceeded") {
|
|
77833
|
+
return paymentCapError(
|
|
77834
|
+
"per_call",
|
|
77835
|
+
amountAtomic,
|
|
77836
|
+
error61.details?.limitAtomic ?? BigInt(args.caps.perCallAtomic),
|
|
77837
|
+
args,
|
|
77838
|
+
error61
|
|
77839
|
+
);
|
|
77840
|
+
}
|
|
77841
|
+
if (error61.code === "per_day_cap_exceeded") {
|
|
77842
|
+
return paymentCapError(
|
|
77843
|
+
"per_day",
|
|
77844
|
+
amountAtomic,
|
|
77845
|
+
error61.details?.limitAtomic ?? BigInt(args.caps.perDayAtomic),
|
|
77846
|
+
args,
|
|
77847
|
+
error61,
|
|
77848
|
+
error61.details?.spentAtomic
|
|
77849
|
+
);
|
|
77850
|
+
}
|
|
77851
|
+
return error61;
|
|
77852
|
+
}
|
|
77853
|
+
function paymentCapError(cap, amountAtomic, limitAtomic, args, cause, spentAtomic) {
|
|
77854
|
+
return new SpendCapExceededError({
|
|
77855
|
+
cap,
|
|
77856
|
+
amountUsd: formatUsdc(amountAtomic),
|
|
77857
|
+
limitUsd: formatUsdc(limitAtomic),
|
|
77858
|
+
...cap === "per_call" ? { perDayLimitUsd: formatUsdc(BigInt(args.caps.perDayAtomic)) } : {},
|
|
77859
|
+
...spentAtomic === void 0 ? {} : { spentUsd: formatUsdc(spentAtomic) },
|
|
77860
|
+
...args.wallet === void 0 ? {} : { wallet: args.wallet },
|
|
77861
|
+
cause
|
|
77862
|
+
});
|
|
77863
|
+
}
|
|
77864
|
+
function isErrorCode(error61, code) {
|
|
77865
|
+
return typeof error61 === "object" && error61 !== null && Reflect.get(error61, "code") === code;
|
|
77866
|
+
}
|
|
77624
77867
|
function settlementUnknown(message, quote, payment, payer, receipt, cause) {
|
|
77625
77868
|
return new X402PaymentError(
|
|
77626
77869
|
"settlement_unknown",
|
|
@@ -77696,7 +77939,7 @@ function receiptQuote(quote) {
|
|
|
77696
77939
|
};
|
|
77697
77940
|
}
|
|
77698
77941
|
function paymentErrorOutcome(error61) {
|
|
77699
|
-
if (error61 instanceof SpendCapError || error61 instanceof RunBudgetError || error61 instanceof X402Error && error61.code === "max_price_exceeded") {
|
|
77942
|
+
if (error61 instanceof SpendCapExceededError || error61 instanceof SpendCapError || error61 instanceof RunBudgetError || error61 instanceof X402Error && error61.code === "max_price_exceeded") {
|
|
77700
77943
|
return "declined_policy";
|
|
77701
77944
|
}
|
|
77702
77945
|
if (error61 instanceof X402PaymentError) {
|
|
@@ -77713,7 +77956,7 @@ function errorCode(error61) {
|
|
|
77713
77956
|
return "request_failed";
|
|
77714
77957
|
}
|
|
77715
77958
|
function receiptSafeErrorMessage(error61) {
|
|
77716
|
-
if (error61 instanceof SpendCapError || error61 instanceof RunBudgetError || error61 instanceof X402Error || error61 instanceof X402PaymentError) {
|
|
77959
|
+
if (error61 instanceof SpendCapExceededError || error61 instanceof SpendCapError || error61 instanceof RunBudgetError || error61 instanceof X402Error || error61 instanceof X402PaymentError) {
|
|
77717
77960
|
return error61.message;
|
|
77718
77961
|
}
|
|
77719
77962
|
return "The x402 request failed before it completed.";
|
|
@@ -78263,7 +78506,10 @@ function normalizeResourceUrl(value) {
|
|
|
78263
78506
|
async function discover(sources, query, options = {}) {
|
|
78264
78507
|
const nowMs = options.nowMs ?? (() => performance.now());
|
|
78265
78508
|
const startedAt = options.now ?? /* @__PURE__ */ new Date();
|
|
78266
|
-
const searchOptions =
|
|
78509
|
+
const searchOptions = {
|
|
78510
|
+
...options.includeUnverified === void 0 ? {} : { includeUnverified: options.includeUnverified },
|
|
78511
|
+
...options.includeOutage === void 0 ? {} : { includeOutage: options.includeOutage }
|
|
78512
|
+
};
|
|
78267
78513
|
const settled = await Promise.all(
|
|
78268
78514
|
sources.map(async (source) => {
|
|
78269
78515
|
const started = nowMs();
|
|
@@ -78988,6 +79234,11 @@ function safeOrigin2(value) {
|
|
|
78988
79234
|
}
|
|
78989
79235
|
}
|
|
78990
79236
|
|
|
79237
|
+
// src/listing-fee.ts
|
|
79238
|
+
function formatListingFee(fee) {
|
|
79239
|
+
return fee.bps === 0 ? "No network fee" : `${fee.label} (${fee.bps / 100}%)`;
|
|
79240
|
+
}
|
|
79241
|
+
|
|
78991
79242
|
// src/onramp.ts
|
|
78992
79243
|
var ONRAMP_NETWORK = "base";
|
|
78993
79244
|
var ONRAMP_FALLBACK_INSTRUCTIONS = "Send USDC on Base (eip155:8453) to this address; add a little ETH for gas if you plan to sweep.";
|
|
@@ -79036,6 +79287,54 @@ var SpendPolicy = class {
|
|
|
79036
79287
|
}
|
|
79037
79288
|
};
|
|
79038
79289
|
|
|
79290
|
+
// src/link-state.ts
|
|
79291
|
+
async function linkStates(args) {
|
|
79292
|
+
const origin = new URL(args.apiBase).origin;
|
|
79293
|
+
await args.store.reload();
|
|
79294
|
+
const states = /* @__PURE__ */ new Map();
|
|
79295
|
+
const candidates = [];
|
|
79296
|
+
for (const name of args.store.names()) {
|
|
79297
|
+
const link2 = args.store.entry(name)?.link;
|
|
79298
|
+
const address2 = await args.store.readAddress(name);
|
|
79299
|
+
const hasTokens = args.secrets.available && await args.secrets.has(agentSecretAccounts(name).tokens).catch(() => false);
|
|
79300
|
+
if (link2 === void 0 || new URL(link2.apiBase).origin !== origin || address2 === void 0 || !hasTokens) {
|
|
79301
|
+
states.set(name, "not_linked");
|
|
79302
|
+
continue;
|
|
79303
|
+
}
|
|
79304
|
+
states.set(name, "linked");
|
|
79305
|
+
candidates.push({ name, owner: getAddress(link2.owner), address: getAddress(address2) });
|
|
79306
|
+
}
|
|
79307
|
+
for (const source of candidates) {
|
|
79308
|
+
let result;
|
|
79309
|
+
try {
|
|
79310
|
+
result = await fetchSiblings({
|
|
79311
|
+
apiBase: args.apiBase,
|
|
79312
|
+
account: source.name,
|
|
79313
|
+
secrets: args.secrets,
|
|
79314
|
+
wallets: args.store,
|
|
79315
|
+
...args.fetchImpl === void 0 ? {} : { fetchImpl: args.fetchImpl },
|
|
79316
|
+
...args.now === void 0 ? {} : { now: args.now }
|
|
79317
|
+
});
|
|
79318
|
+
} catch (error61) {
|
|
79319
|
+
if (error61 instanceof SiblingsError && error61.code === "not_linked") {
|
|
79320
|
+
states.set(source.name, "revoked");
|
|
79321
|
+
continue;
|
|
79322
|
+
}
|
|
79323
|
+
return states;
|
|
79324
|
+
}
|
|
79325
|
+
const owner = result.owner === null ? source.owner : getAddress(result.owner);
|
|
79326
|
+
for (const candidate of candidates) {
|
|
79327
|
+
if (candidate.owner !== owner) continue;
|
|
79328
|
+
const sibling = result.siblings.find(
|
|
79329
|
+
(entry) => getAddress(entry.address) === candidate.address
|
|
79330
|
+
);
|
|
79331
|
+
states.set(candidate.name, sibling?.status === "active" ? "linked" : "revoked");
|
|
79332
|
+
}
|
|
79333
|
+
return states;
|
|
79334
|
+
}
|
|
79335
|
+
return states;
|
|
79336
|
+
}
|
|
79337
|
+
|
|
79039
79338
|
// src/stats.ts
|
|
79040
79339
|
var STATS_RANGES = ["24h", "7d", "30d"];
|
|
79041
79340
|
var OUTCOMES = [
|
|
@@ -81355,6 +81654,37 @@ function isRecord4(value) {
|
|
|
81355
81654
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
81356
81655
|
}
|
|
81357
81656
|
|
|
81657
|
+
// src/vault-setup.ts
|
|
81658
|
+
import { rm as rm2 } from "node:fs/promises";
|
|
81659
|
+
import { join as join16 } from "node:path";
|
|
81660
|
+
async function createVault2(home, options) {
|
|
81661
|
+
if (options.password === "") {
|
|
81662
|
+
throw new KeystoreError("A password cannot be empty.");
|
|
81663
|
+
}
|
|
81664
|
+
const store = await WalletStore.open(home, {
|
|
81665
|
+
secrets: options.secrets,
|
|
81666
|
+
...options.now === void 0 ? {} : { now: options.now }
|
|
81667
|
+
});
|
|
81668
|
+
const hadDeviceKey = options.password !== void 0 && await options.secrets.has(VAULT_KEY_ACCOUNT);
|
|
81669
|
+
await store.createEmptyVault();
|
|
81670
|
+
if (options.password !== void 0) {
|
|
81671
|
+
const path = join16(home, "vault.json");
|
|
81672
|
+
try {
|
|
81673
|
+
await protectVault({
|
|
81674
|
+
path,
|
|
81675
|
+
secrets: options.secrets,
|
|
81676
|
+
password: options.password
|
|
81677
|
+
});
|
|
81678
|
+
} catch (error61) {
|
|
81679
|
+
await Promise.allSettled([
|
|
81680
|
+
rm2(path, { force: true }),
|
|
81681
|
+
...hadDeviceKey ? [] : [options.secrets.remove(VAULT_KEY_ACCOUNT)]
|
|
81682
|
+
]);
|
|
81683
|
+
throw error61;
|
|
81684
|
+
}
|
|
81685
|
+
}
|
|
81686
|
+
}
|
|
81687
|
+
|
|
81358
81688
|
// src/wallet.ts
|
|
81359
81689
|
var LocalWallet = class {
|
|
81360
81690
|
constructor(account, policy) {
|
|
@@ -81381,6 +81711,44 @@ var LocalWallet = class {
|
|
|
81381
81711
|
return await readUsdcBalance({ network, configured, address: address2 });
|
|
81382
81712
|
}
|
|
81383
81713
|
};
|
|
81714
|
+
|
|
81715
|
+
// src/remote-account.ts
|
|
81716
|
+
var RemoteAccountError = class extends Error {
|
|
81717
|
+
constructor(code, message) {
|
|
81718
|
+
super(message);
|
|
81719
|
+
this.code = code;
|
|
81720
|
+
this.name = "RemoteAccountError";
|
|
81721
|
+
}
|
|
81722
|
+
code;
|
|
81723
|
+
};
|
|
81724
|
+
var notPermitted = (what) => new RemoteAccountError("not_permitted", `${what} is not permitted through vAPI Desktop.`);
|
|
81725
|
+
function remotePaymentAccount(args) {
|
|
81726
|
+
const base = toAccount({
|
|
81727
|
+
address: args.address,
|
|
81728
|
+
async signMessage({ message }) {
|
|
81729
|
+
const text = typeof message === "string" ? message : JSON.stringify(message);
|
|
81730
|
+
return await args.request({ kind: "message", wallet: args.wallet, message: text });
|
|
81731
|
+
},
|
|
81732
|
+
async signTransaction() {
|
|
81733
|
+
throw notPermitted("Raw transaction signing");
|
|
81734
|
+
},
|
|
81735
|
+
async signTypedData(typedData) {
|
|
81736
|
+
return await args.request({ kind: "typedData", wallet: args.wallet, typedData });
|
|
81737
|
+
}
|
|
81738
|
+
});
|
|
81739
|
+
const account = {
|
|
81740
|
+
...base,
|
|
81741
|
+
publicKey: args.publicKey,
|
|
81742
|
+
source: "privateKey",
|
|
81743
|
+
async sign() {
|
|
81744
|
+
throw notPermitted("Hash signing");
|
|
81745
|
+
},
|
|
81746
|
+
async signAuthorization() {
|
|
81747
|
+
throw notPermitted("EIP-7702 authorization");
|
|
81748
|
+
}
|
|
81749
|
+
};
|
|
81750
|
+
return account;
|
|
81751
|
+
}
|
|
81384
81752
|
export {
|
|
81385
81753
|
AGENT_GRANTS,
|
|
81386
81754
|
AGENT_MARKER_VARIABLES,
|
|
@@ -81426,6 +81794,7 @@ export {
|
|
|
81426
81794
|
FileLockedError,
|
|
81427
81795
|
KeystoreError,
|
|
81428
81796
|
LISTING_GROUPS,
|
|
81797
|
+
LISTING_HEALTH_STATES,
|
|
81429
81798
|
LISTING_VERIFICATIONS,
|
|
81430
81799
|
LocalWallet,
|
|
81431
81800
|
MARKETPLACE_DISCOVERY_PROTOCOL,
|
|
@@ -81443,6 +81812,7 @@ export {
|
|
|
81443
81812
|
RESTORE_GAP_LIMIT,
|
|
81444
81813
|
ROUTER_TOPUP_TIERS,
|
|
81445
81814
|
RUN_ID_PATTERN,
|
|
81815
|
+
RemoteAccountError,
|
|
81446
81816
|
RunBudgetError,
|
|
81447
81817
|
SECRET_STORE_SERVICE,
|
|
81448
81818
|
SIBLINGS_DEFAULT_TIMEOUT_MS,
|
|
@@ -81460,6 +81830,7 @@ export {
|
|
|
81460
81830
|
SWARM_TREASURY_CAPS,
|
|
81461
81831
|
SiblingsError,
|
|
81462
81832
|
SpendCapError,
|
|
81833
|
+
SpendCapExceededError,
|
|
81463
81834
|
SpendPolicy,
|
|
81464
81835
|
SwarmError,
|
|
81465
81836
|
SweepGasError,
|
|
@@ -81528,6 +81899,7 @@ export {
|
|
|
81528
81899
|
createRunId,
|
|
81529
81900
|
createSIWxMessage,
|
|
81530
81901
|
createSupportReport,
|
|
81902
|
+
createVault2 as createVault,
|
|
81531
81903
|
decideFunding,
|
|
81532
81904
|
decideRelease,
|
|
81533
81905
|
decodePaymentRequiredHeader,
|
|
@@ -81561,6 +81933,7 @@ export {
|
|
|
81561
81933
|
firstPartyProvenanceSchema,
|
|
81562
81934
|
formatCeilingUsd,
|
|
81563
81935
|
formatLegacyRegistryRewrites,
|
|
81936
|
+
formatListingFee,
|
|
81564
81937
|
formatUsdAmount,
|
|
81565
81938
|
formatUsdc,
|
|
81566
81939
|
fundSwarm,
|
|
@@ -81588,6 +81961,7 @@ export {
|
|
|
81588
81961
|
isWalletName,
|
|
81589
81962
|
leaveSwarm,
|
|
81590
81963
|
linkRouterAllowanceUsd,
|
|
81964
|
+
linkStates,
|
|
81591
81965
|
listAccounts,
|
|
81592
81966
|
listAgentProfiles,
|
|
81593
81967
|
listServicesResponseSchema,
|
|
@@ -81597,6 +81971,8 @@ export {
|
|
|
81597
81971
|
listingDisclosureShape,
|
|
81598
81972
|
listingFeeSchema,
|
|
81599
81973
|
listingGroupSchema,
|
|
81974
|
+
listingHealthSchema,
|
|
81975
|
+
listingHealthStateSchema,
|
|
81600
81976
|
listingIdentitySchema,
|
|
81601
81977
|
listingLivenessSchema,
|
|
81602
81978
|
listingVerificationFieldSchema,
|
|
@@ -81605,6 +81981,7 @@ export {
|
|
|
81605
81981
|
loadOrCreateDeviceKey,
|
|
81606
81982
|
lockVault,
|
|
81607
81983
|
lowerAccountCaps,
|
|
81984
|
+
marketplaceAlternativeSchema,
|
|
81608
81985
|
marketplaceBadgeCodeSchema,
|
|
81609
81986
|
marketplaceBadgeSchema,
|
|
81610
81987
|
marketplaceDiscoveryEnvelopeSchema,
|
|
@@ -81661,6 +82038,7 @@ export {
|
|
|
81661
82038
|
receiptWallet,
|
|
81662
82039
|
receiptsToCsv,
|
|
81663
82040
|
releaseSpend,
|
|
82041
|
+
remotePaymentAccount,
|
|
81664
82042
|
removeAgentProfile,
|
|
81665
82043
|
renameReceiptWallet,
|
|
81666
82044
|
requireRpcUrl,
|