vapi-network 0.11.0 → 0.12.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.
- package/README.md +259 -126
- package/SKILL.md +25 -20
- package/dist/cli.js +773 -132
- package/dist/cli.js.map +3 -3
- package/dist/index.js +953 -191
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10128,9 +10128,9 @@ __export(src_exports4, {
|
|
|
10128
10128
|
});
|
|
10129
10129
|
|
|
10130
10130
|
// ../cli/src/cli.ts
|
|
10131
|
-
import { spawn as
|
|
10131
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
10132
10132
|
import { stat as stat16 } from "node:fs/promises";
|
|
10133
|
-
import { join as
|
|
10133
|
+
import { join as join30 } from "node:path";
|
|
10134
10134
|
import { createInterface as createInterface3 } from "node:readline/promises";
|
|
10135
10135
|
|
|
10136
10136
|
// ../core/src/index.ts
|
|
@@ -10198,6 +10198,7 @@ __export(src_exports, {
|
|
|
10198
10198
|
RESTORE_GAP_LIMIT: () => RESTORE_GAP_LIMIT,
|
|
10199
10199
|
ROUTER_TOPUP_TIERS: () => ROUTER_TOPUP_TIERS,
|
|
10200
10200
|
RUN_ID_PATTERN: () => RUN_ID_PATTERN,
|
|
10201
|
+
RemoteAccountError: () => RemoteAccountError,
|
|
10201
10202
|
RunBudgetError: () => RunBudgetError,
|
|
10202
10203
|
SECRET_STORE_SERVICE: () => SECRET_STORE_SERVICE,
|
|
10203
10204
|
SIBLINGS_DEFAULT_TIMEOUT_MS: () => SIBLINGS_DEFAULT_TIMEOUT_MS,
|
|
@@ -10284,6 +10285,7 @@ __export(src_exports, {
|
|
|
10284
10285
|
createRunId: () => createRunId,
|
|
10285
10286
|
createSIWxMessage: () => createSIWxMessage,
|
|
10286
10287
|
createSupportReport: () => createSupportReport,
|
|
10288
|
+
createVault: () => createVault2,
|
|
10287
10289
|
decideFunding: () => decideFunding,
|
|
10288
10290
|
decideRelease: () => decideRelease,
|
|
10289
10291
|
decodePaymentRequiredHeader: () => decodePaymentRequiredHeader,
|
|
@@ -10345,6 +10347,7 @@ __export(src_exports, {
|
|
|
10345
10347
|
isWalletName: () => isWalletName,
|
|
10346
10348
|
leaveSwarm: () => leaveSwarm,
|
|
10347
10349
|
linkRouterAllowanceUsd: () => linkRouterAllowanceUsd,
|
|
10350
|
+
linkStates: () => linkStates,
|
|
10348
10351
|
listAccounts: () => listAccounts,
|
|
10349
10352
|
listAgentProfiles: () => listAgentProfiles,
|
|
10350
10353
|
listServicesResponseSchema: () => listServicesResponseSchema,
|
|
@@ -10421,6 +10424,7 @@ __export(src_exports, {
|
|
|
10421
10424
|
receiptWallet: () => receiptWallet,
|
|
10422
10425
|
receiptsToCsv: () => receiptsToCsv,
|
|
10423
10426
|
releaseSpend: () => releaseSpend,
|
|
10427
|
+
remotePaymentAccount: () => remotePaymentAccount,
|
|
10424
10428
|
removeAgentProfile: () => removeAgentProfile,
|
|
10425
10429
|
renameReceiptWallet: () => renameReceiptWallet,
|
|
10426
10430
|
requireRpcUrl: () => requireRpcUrl,
|
|
@@ -70653,13 +70657,13 @@ async function withAccountMovementLocks(home, accounts, timeoutMs, operation) {
|
|
|
70653
70657
|
);
|
|
70654
70658
|
}
|
|
70655
70659
|
async function acquireAccountMovementLocks(home, accounts, timeoutMs, operation) {
|
|
70656
|
-
const [account, ...
|
|
70660
|
+
const [account, ...remaining2] = accounts;
|
|
70657
70661
|
if (account === void 0) return await operation();
|
|
70658
70662
|
return await withAccountMovementLock(
|
|
70659
70663
|
home,
|
|
70660
70664
|
account,
|
|
70661
70665
|
timeoutMs,
|
|
70662
|
-
async () => acquireAccountMovementLocks(home,
|
|
70666
|
+
async () => acquireAccountMovementLocks(home, remaining2, timeoutMs, operation)
|
|
70663
70667
|
);
|
|
70664
70668
|
}
|
|
70665
70669
|
async function removeStaleLock2(path) {
|
|
@@ -70732,7 +70736,7 @@ var POWERSHELL_MISSING = [
|
|
|
70732
70736
|
].join(" ");
|
|
70733
70737
|
function secretStore(options = {}) {
|
|
70734
70738
|
const platform2 = options.platform ?? process.platform;
|
|
70735
|
-
const run = options.run ?? spawnRunner;
|
|
70739
|
+
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
70736
70740
|
const env = options.env ?? process.env;
|
|
70737
70741
|
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
70738
70742
|
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
@@ -70926,6 +70930,7 @@ function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
|
70926
70930
|
].join("\n");
|
|
70927
70931
|
const execute = async (script2) => {
|
|
70928
70932
|
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
70933
|
+
|
|
70929
70934
|
`);
|
|
70930
70935
|
requirePowerShell(result);
|
|
70931
70936
|
return result;
|
|
@@ -71088,17 +71093,25 @@ function binaryInstalled(file2, env) {
|
|
|
71088
71093
|
if (isAbsolute(file2) || win32.isAbsolute(file2)) return existsSync(file2);
|
|
71089
71094
|
return (env.PATH ?? "").split(delimiter).some((directory) => existsSync(join6(directory, file2)));
|
|
71090
71095
|
}
|
|
71096
|
+
var SAFE_FAILURE_DETAILS = [
|
|
71097
|
+
"Cannot autolaunch D-Bus without X11 $DISPLAY",
|
|
71098
|
+
"Cannot autolaunch D-Bus",
|
|
71099
|
+
"The name org.freedesktop.secrets was not provided by any .service files",
|
|
71100
|
+
"Cannot create an item in a locked collection",
|
|
71101
|
+
"User interaction is not allowed.",
|
|
71102
|
+
"Access to the path is denied."
|
|
71103
|
+
];
|
|
71091
71104
|
function requireSuccess(result, what) {
|
|
71092
71105
|
if (result.code === 0) return;
|
|
71093
|
-
const detail =
|
|
71106
|
+
const detail = SAFE_FAILURE_DETAILS.find((reason) => result.stderr.includes(reason));
|
|
71094
71107
|
throw new KeystoreError(
|
|
71095
|
-
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail
|
|
71108
|
+
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail === void 0 ? "" : ` ${detail}`}`
|
|
71096
71109
|
);
|
|
71097
71110
|
}
|
|
71098
71111
|
function withoutTrailingNewline(value) {
|
|
71099
71112
|
return value.replace(/\r?\n$/u, "");
|
|
71100
71113
|
}
|
|
71101
|
-
var spawnRunner = async (file2, args, input2) => await new Promise((resolve4) => {
|
|
71114
|
+
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve4) => {
|
|
71102
71115
|
let stdout = "";
|
|
71103
71116
|
let stderr2 = "";
|
|
71104
71117
|
let settled = false;
|
|
@@ -71108,7 +71121,7 @@ var spawnRunner = async (file2, args, input2) => await new Promise((resolve4) =>
|
|
|
71108
71121
|
resolve4(outcome);
|
|
71109
71122
|
};
|
|
71110
71123
|
const child = spawn(file2, [...args], {
|
|
71111
|
-
detached:
|
|
71124
|
+
detached: platform2 !== "win32",
|
|
71112
71125
|
stdio: ["pipe", "pipe", "pipe"],
|
|
71113
71126
|
windowsHide: true
|
|
71114
71127
|
});
|
|
@@ -72121,7 +72134,7 @@ async function loadOrCreateDeviceKey(args) {
|
|
|
72121
72134
|
await args.secrets.set(VAULT_KEY_ACCOUNT, key2.toString("base64"));
|
|
72122
72135
|
return key2;
|
|
72123
72136
|
} catch (error61) {
|
|
72124
|
-
throw asVaultError2(error61,
|
|
72137
|
+
throw asVaultError2(error61, deviceKeyFailureMessage(error61, args.secrets.platform));
|
|
72125
72138
|
}
|
|
72126
72139
|
});
|
|
72127
72140
|
}
|
|
@@ -72379,6 +72392,12 @@ function parseJson(value) {
|
|
|
72379
72392
|
function asVaultError2(error61, message) {
|
|
72380
72393
|
return error61 instanceof VaultError ? error61 : new VaultError("corrupt", message, { cause: error61 });
|
|
72381
72394
|
}
|
|
72395
|
+
var HEADLESS_LINUX_HINT = "A server, container or GitHub Codespace usually has no keyring. Run vapi on your own computer, or connect Claude from https://api.vapinetwork.ai/connect.";
|
|
72396
|
+
function deviceKeyFailureMessage(error61, platform2) {
|
|
72397
|
+
if (!(error61 instanceof KeystoreError)) return "Unable to load or create the device vault key.";
|
|
72398
|
+
const detail = `Unable to load or create the device vault key: ${error61.message.replace(/\.$/u, "")}.`;
|
|
72399
|
+
return platform2 === "linux" ? `${detail} ${HEADLESS_LINUX_HINT}` : detail;
|
|
72400
|
+
}
|
|
72382
72401
|
|
|
72383
72402
|
// ../core/src/vault-migrate.ts
|
|
72384
72403
|
import {
|
|
@@ -72727,6 +72746,17 @@ var WalletStore = class _WalletStore {
|
|
|
72727
72746
|
);
|
|
72728
72747
|
return account?.address ?? (await readKeystoreSummary(this.pathFor(target))).address;
|
|
72729
72748
|
}
|
|
72749
|
+
/**
|
|
72750
|
+
* Creates the vault without deriving an account, for apps that create every
|
|
72751
|
+
* account by name. Refuses when a vault already exists in this home.
|
|
72752
|
+
*/
|
|
72753
|
+
async createEmptyVault() {
|
|
72754
|
+
if (await this.readVaultUnlocked() !== void 0) {
|
|
72755
|
+
throw new KeystoreError("A vault already exists in this home.");
|
|
72756
|
+
}
|
|
72757
|
+
await this.openVault({ create: true });
|
|
72758
|
+
this.dropVaultCache();
|
|
72759
|
+
}
|
|
72730
72760
|
async create(name, passphrase, options = {}) {
|
|
72731
72761
|
void passphrase;
|
|
72732
72762
|
void options.enableSolana;
|
|
@@ -73607,11 +73637,11 @@ function accountChangeBusyError(account, command) {
|
|
|
73607
73637
|
);
|
|
73608
73638
|
}
|
|
73609
73639
|
async function withAccountMutationLocks(home, accounts, command, operation) {
|
|
73610
|
-
const [account, ...
|
|
73640
|
+
const [account, ...remaining2] = [...new Set(accounts)].sort();
|
|
73611
73641
|
if (account === void 0) return await operation();
|
|
73612
73642
|
return await withFileLock(
|
|
73613
73643
|
join8(home, `.account-${account}.lock`),
|
|
73614
|
-
async () => await withAccountMutationLocks(home,
|
|
73644
|
+
async () => await withAccountMutationLocks(home, remaining2, command, operation),
|
|
73615
73645
|
{
|
|
73616
73646
|
lockedMessage: `Account ${account} is busy with another account change. Wait for it to finish, then retry ${command}.`
|
|
73617
73647
|
}
|
|
@@ -74419,8 +74449,8 @@ async function escrowFundingDayRemainingAtomic(input2) {
|
|
|
74419
74449
|
const rows = await readStoredSpendLedgerRows(input2.ledgerPath, input2.now);
|
|
74420
74450
|
const row = rows.find((candidate) => candidate.wallet === input2.wallet);
|
|
74421
74451
|
const reserved = input2.reservationId ? row?.reservations?.find((candidate) => candidate.id === input2.reservationId) : void 0;
|
|
74422
|
-
const
|
|
74423
|
-
return
|
|
74452
|
+
const remaining2 = perDayAtomic - BigInt(row?.spentAtomic ?? "0") + BigInt(reserved?.amountAtomic ?? "0");
|
|
74453
|
+
return remaining2 > 0n ? remaining2 : 0n;
|
|
74424
74454
|
}
|
|
74425
74455
|
async function taskReservedAtomic(input2) {
|
|
74426
74456
|
const rows = await readStoredSpendLedgerRows(input2.ledgerPath, input2.now, true);
|
|
@@ -75760,13 +75790,13 @@ function splitMovementPlanAtRelayLimit(plan) {
|
|
|
75760
75790
|
const legs = plan.legs.flatMap((leg) => {
|
|
75761
75791
|
const purpose = leg.purpose ?? "send";
|
|
75762
75792
|
const split2 = purpose === "sweep" || plan.reason === "send" && plan.treasury !== void 0 && leg.to === plan.treasury;
|
|
75763
|
-
let
|
|
75764
|
-
if (!split2 ||
|
|
75793
|
+
let remaining2 = parseUsdCents(leg.amountUsd);
|
|
75794
|
+
if (!split2 || remaining2 <= maximumCents) return [leg];
|
|
75765
75795
|
const parts = [];
|
|
75766
|
-
while (
|
|
75767
|
-
const cents =
|
|
75796
|
+
while (remaining2 > 0n) {
|
|
75797
|
+
const cents = remaining2 > maximumCents ? maximumCents : remaining2;
|
|
75768
75798
|
parts.push({ ...leg, amountUsd: formatUsdCents(cents) });
|
|
75769
|
-
|
|
75799
|
+
remaining2 -= cents;
|
|
75770
75800
|
}
|
|
75771
75801
|
return parts;
|
|
75772
75802
|
});
|
|
@@ -76642,13 +76672,13 @@ async function withMovementLock(home, from16, timeoutMs, operation) {
|
|
|
76642
76672
|
}
|
|
76643
76673
|
}
|
|
76644
76674
|
async function withMovementLocks(home, senders, timeoutMs, operation) {
|
|
76645
|
-
const [sender, ...
|
|
76675
|
+
const [sender, ...remaining2] = senders;
|
|
76646
76676
|
if (sender === void 0) return await operation();
|
|
76647
76677
|
return await withMovementLock(
|
|
76648
76678
|
home,
|
|
76649
76679
|
sender,
|
|
76650
76680
|
timeoutMs,
|
|
76651
|
-
async () => withMovementLocks(home,
|
|
76681
|
+
async () => withMovementLocks(home, remaining2, timeoutMs, operation)
|
|
76652
76682
|
);
|
|
76653
76683
|
}
|
|
76654
76684
|
async function assertNoPendingCeilingSweep(deps, senders) {
|
|
@@ -77455,11 +77485,11 @@ function planTargets(input2) {
|
|
|
77455
77485
|
function splitCandidateAtRelayMaximum(candidate, relayMaxAtomic) {
|
|
77456
77486
|
const maximumCents = relayMaxAtomic / 10000n;
|
|
77457
77487
|
const legs = [];
|
|
77458
|
-
let
|
|
77459
|
-
while (
|
|
77460
|
-
const cents =
|
|
77488
|
+
let remaining2 = candidate.cents;
|
|
77489
|
+
while (remaining2 > 0n) {
|
|
77490
|
+
const cents = remaining2 > maximumCents ? maximumCents : remaining2;
|
|
77461
77491
|
legs.push(allocationLeg(candidate.from, candidate.to, cents, candidate.purpose));
|
|
77462
|
-
|
|
77492
|
+
remaining2 -= cents;
|
|
77463
77493
|
}
|
|
77464
77494
|
return legs;
|
|
77465
77495
|
}
|
|
@@ -78294,7 +78324,7 @@ function createRunBudget(args) {
|
|
|
78294
78324
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
78295
78325
|
import { arch, platform, release } from "node:os";
|
|
78296
78326
|
import { join as join13 } from "node:path";
|
|
78297
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
78327
|
+
var VAPI_CLIENT_VERSION = "0.12.1";
|
|
78298
78328
|
async function createSupportReport(options) {
|
|
78299
78329
|
const message = options.message.trim();
|
|
78300
78330
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
@@ -79686,8 +79716,15 @@ async function ownerStake(deps) {
|
|
|
79686
79716
|
stakeUrl: parsed.data.stakeUrl
|
|
79687
79717
|
};
|
|
79688
79718
|
}
|
|
79689
|
-
async function routerCredentials(deps) {
|
|
79690
|
-
const
|
|
79719
|
+
async function routerCredentials(deps, options = {}) {
|
|
79720
|
+
const credentials = options.funding === "balance" ? await routerBalanceCredentialSnapshot(deps) : await routerCredentialSnapshot(deps);
|
|
79721
|
+
if (credentials === void 0) {
|
|
79722
|
+
throw new RouterClientError(
|
|
79723
|
+
"no_router_key",
|
|
79724
|
+
"No Router balance key is stored for this wallet."
|
|
79725
|
+
);
|
|
79726
|
+
}
|
|
79727
|
+
const { routerBaseUrl, routerKey } = credentials;
|
|
79691
79728
|
return { baseURL: `${routerBaseUrl}/v1`, apiKey: routerKey };
|
|
79692
79729
|
}
|
|
79693
79730
|
async function routerCredentialSnapshot(deps) {
|
|
@@ -82911,10 +82948,10 @@ async function waitForMilestone(client, input2) {
|
|
|
82911
82948
|
return { reached, milestone, polls, elapsedMs: now().getTime() - started };
|
|
82912
82949
|
}
|
|
82913
82950
|
for (; ; ) {
|
|
82914
|
-
const
|
|
82915
|
-
if (
|
|
82951
|
+
const remaining2 = deadline - now().getTime();
|
|
82952
|
+
if (remaining2 <= 0) return result(false);
|
|
82916
82953
|
const controller = new AbortController();
|
|
82917
|
-
const timer = setTimeout(() => controller.abort(),
|
|
82954
|
+
const timer = setTimeout(() => controller.abort(), remaining2);
|
|
82918
82955
|
let response;
|
|
82919
82956
|
polls++;
|
|
82920
82957
|
try {
|
|
@@ -83578,7 +83615,7 @@ async function feeTask(input2, action) {
|
|
|
83578
83615
|
);
|
|
83579
83616
|
let approvalGranted = input2.approval !== void 0 && "granted" in input2.approval && input2.approval.granted;
|
|
83580
83617
|
const checkPolicy = async (reservationId) => {
|
|
83581
|
-
const
|
|
83618
|
+
const remaining2 = await escrowFundingDayRemainingAtomic({
|
|
83582
83619
|
caps: input2.caps,
|
|
83583
83620
|
ledgerPath: input2.ledgerPath,
|
|
83584
83621
|
wallet: input2.wallet,
|
|
@@ -83595,13 +83632,13 @@ async function feeTask(input2, action) {
|
|
|
83595
83632
|
const maxPerTaskAtomic = policyAtomic(input2.policy.maxPerTaskUsd);
|
|
83596
83633
|
if (feeAtomic > maxPerTaskAtomic || taskReserved + feeAtomic > maxPerTaskAtomic)
|
|
83597
83634
|
return { outcome: "refused", reason: "policy.perTask", money: money2, disputeFee: fee };
|
|
83598
|
-
if (feeAtomic >
|
|
83635
|
+
if (feeAtomic > remaining2)
|
|
83599
83636
|
return { outcome: "refused", reason: "policy.perDay", money: money2, disputeFee: fee };
|
|
83600
83637
|
if (feeAtomic > policyAtomic(input2.policy.approveAboveUsd) && !approvalGranted) {
|
|
83601
83638
|
if (input2.approval && "ask" in input2.approval) {
|
|
83602
83639
|
approvalGranted = await input2.approval.ask({
|
|
83603
83640
|
money: money2,
|
|
83604
|
-
dayRemainingUsd: Number(formatBaseUnitsUsd(
|
|
83641
|
+
dayRemainingUsd: Number(formatBaseUnitsUsd(remaining2))
|
|
83605
83642
|
});
|
|
83606
83643
|
if (!approvalGranted) return { outcome: "declined", money: money2, disputeFee: fee };
|
|
83607
83644
|
} else return { outcome: "approval_needed", money: money2, disputeFee: fee };
|
|
@@ -85826,6 +85863,54 @@ var SpendPolicy = class {
|
|
|
85826
85863
|
}
|
|
85827
85864
|
};
|
|
85828
85865
|
|
|
85866
|
+
// ../core/src/link-state.ts
|
|
85867
|
+
async function linkStates(args) {
|
|
85868
|
+
const origin = new URL(args.apiBase).origin;
|
|
85869
|
+
await args.store.reload();
|
|
85870
|
+
const states = /* @__PURE__ */ new Map();
|
|
85871
|
+
const candidates = [];
|
|
85872
|
+
for (const name of args.store.names()) {
|
|
85873
|
+
const link3 = args.store.entry(name)?.link;
|
|
85874
|
+
const address4 = await args.store.readAddress(name);
|
|
85875
|
+
const hasTokens = args.secrets.available && await args.secrets.has(agentSecretAccounts(name).tokens).catch(() => false);
|
|
85876
|
+
if (link3 === void 0 || new URL(link3.apiBase).origin !== origin || address4 === void 0 || !hasTokens) {
|
|
85877
|
+
states.set(name, "not_linked");
|
|
85878
|
+
continue;
|
|
85879
|
+
}
|
|
85880
|
+
states.set(name, "linked");
|
|
85881
|
+
candidates.push({ name, owner: getAddress(link3.owner), address: getAddress(address4) });
|
|
85882
|
+
}
|
|
85883
|
+
for (const source of candidates) {
|
|
85884
|
+
let result;
|
|
85885
|
+
try {
|
|
85886
|
+
result = await fetchSiblings({
|
|
85887
|
+
apiBase: args.apiBase,
|
|
85888
|
+
account: source.name,
|
|
85889
|
+
secrets: args.secrets,
|
|
85890
|
+
wallets: args.store,
|
|
85891
|
+
...args.fetchImpl === void 0 ? {} : { fetchImpl: args.fetchImpl },
|
|
85892
|
+
...args.now === void 0 ? {} : { now: args.now }
|
|
85893
|
+
});
|
|
85894
|
+
} catch (error61) {
|
|
85895
|
+
if (error61 instanceof SiblingsError && error61.code === "not_linked") {
|
|
85896
|
+
states.set(source.name, "revoked");
|
|
85897
|
+
continue;
|
|
85898
|
+
}
|
|
85899
|
+
return states;
|
|
85900
|
+
}
|
|
85901
|
+
const owner = result.owner === null ? source.owner : getAddress(result.owner);
|
|
85902
|
+
for (const candidate of candidates) {
|
|
85903
|
+
if (candidate.owner !== owner) continue;
|
|
85904
|
+
const sibling = result.siblings.find(
|
|
85905
|
+
(entry) => getAddress(entry.address) === candidate.address
|
|
85906
|
+
);
|
|
85907
|
+
states.set(candidate.name, sibling?.status === "active" ? "linked" : "revoked");
|
|
85908
|
+
}
|
|
85909
|
+
return states;
|
|
85910
|
+
}
|
|
85911
|
+
return states;
|
|
85912
|
+
}
|
|
85913
|
+
|
|
85829
85914
|
// ../core/src/stats.ts
|
|
85830
85915
|
var STATS_RANGES = ["24h", "7d", "30d"];
|
|
85831
85916
|
var OUTCOMES = [
|
|
@@ -88145,6 +88230,37 @@ function isRecord4(value) {
|
|
|
88145
88230
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
88146
88231
|
}
|
|
88147
88232
|
|
|
88233
|
+
// ../core/src/vault-setup.ts
|
|
88234
|
+
import { rm as rm2 } from "node:fs/promises";
|
|
88235
|
+
import { join as join18 } from "node:path";
|
|
88236
|
+
async function createVault2(home, options) {
|
|
88237
|
+
if (options.password === "") {
|
|
88238
|
+
throw new KeystoreError("A password cannot be empty.");
|
|
88239
|
+
}
|
|
88240
|
+
const store = await WalletStore.open(home, {
|
|
88241
|
+
secrets: options.secrets,
|
|
88242
|
+
...options.now === void 0 ? {} : { now: options.now }
|
|
88243
|
+
});
|
|
88244
|
+
const hadDeviceKey = options.password !== void 0 && await options.secrets.has(VAULT_KEY_ACCOUNT);
|
|
88245
|
+
await store.createEmptyVault();
|
|
88246
|
+
if (options.password !== void 0) {
|
|
88247
|
+
const path = join18(home, "vault.json");
|
|
88248
|
+
try {
|
|
88249
|
+
await protectVault({
|
|
88250
|
+
path,
|
|
88251
|
+
secrets: options.secrets,
|
|
88252
|
+
password: options.password
|
|
88253
|
+
});
|
|
88254
|
+
} catch (error61) {
|
|
88255
|
+
await Promise.allSettled([
|
|
88256
|
+
rm2(path, { force: true }),
|
|
88257
|
+
...hadDeviceKey ? [] : [options.secrets.remove(VAULT_KEY_ACCOUNT)]
|
|
88258
|
+
]);
|
|
88259
|
+
throw error61;
|
|
88260
|
+
}
|
|
88261
|
+
}
|
|
88262
|
+
}
|
|
88263
|
+
|
|
88148
88264
|
// ../core/src/wallet.ts
|
|
88149
88265
|
var LocalWallet = class {
|
|
88150
88266
|
constructor(account, policy) {
|
|
@@ -88172,6 +88288,44 @@ var LocalWallet = class {
|
|
|
88172
88288
|
}
|
|
88173
88289
|
};
|
|
88174
88290
|
|
|
88291
|
+
// ../core/src/remote-account.ts
|
|
88292
|
+
var RemoteAccountError = class extends Error {
|
|
88293
|
+
constructor(code, message) {
|
|
88294
|
+
super(message);
|
|
88295
|
+
this.code = code;
|
|
88296
|
+
this.name = "RemoteAccountError";
|
|
88297
|
+
}
|
|
88298
|
+
code;
|
|
88299
|
+
};
|
|
88300
|
+
var notPermitted = (what) => new RemoteAccountError("not_permitted", `${what} is not permitted through vAPI Desktop.`);
|
|
88301
|
+
function remotePaymentAccount(args) {
|
|
88302
|
+
const base = toAccount({
|
|
88303
|
+
address: args.address,
|
|
88304
|
+
async signMessage({ message }) {
|
|
88305
|
+
const text = typeof message === "string" ? message : JSON.stringify(message);
|
|
88306
|
+
return await args.request({ kind: "message", wallet: args.wallet, message: text });
|
|
88307
|
+
},
|
|
88308
|
+
async signTransaction() {
|
|
88309
|
+
throw notPermitted("Raw transaction signing");
|
|
88310
|
+
},
|
|
88311
|
+
async signTypedData(typedData) {
|
|
88312
|
+
return await args.request({ kind: "typedData", wallet: args.wallet, typedData });
|
|
88313
|
+
}
|
|
88314
|
+
});
|
|
88315
|
+
const account = {
|
|
88316
|
+
...base,
|
|
88317
|
+
publicKey: args.publicKey,
|
|
88318
|
+
source: "privateKey",
|
|
88319
|
+
async sign() {
|
|
88320
|
+
throw notPermitted("Hash signing");
|
|
88321
|
+
},
|
|
88322
|
+
async signAuthorization() {
|
|
88323
|
+
throw notPermitted("EIP-7702 authorization");
|
|
88324
|
+
}
|
|
88325
|
+
};
|
|
88326
|
+
return account;
|
|
88327
|
+
}
|
|
88328
|
+
|
|
88175
88329
|
// ../core/src/member-bundle.ts
|
|
88176
88330
|
var MEMBER_BUNDLE_MAX_BYTES = 32 * 1024;
|
|
88177
88331
|
var REMOTE_BLOCKED_GRANTS = /* @__PURE__ */ new Set([
|
|
@@ -91733,8 +91887,8 @@ function exactPriceFact(value) {
|
|
|
91733
91887
|
}
|
|
91734
91888
|
|
|
91735
91889
|
// ../mcp/src/agent/runtime.ts
|
|
91736
|
-
import { mkdir as mkdir18, readFile as readFile23, readdir as readdir7, rm as
|
|
91737
|
-
import { join as
|
|
91890
|
+
import { mkdir as mkdir18, readFile as readFile23, readdir as readdir7, rm as rm3 } from "node:fs/promises";
|
|
91891
|
+
import { join as join19 } from "node:path";
|
|
91738
91892
|
|
|
91739
91893
|
// ../mcp/src/agent/run.ts
|
|
91740
91894
|
var loopSearchResultSchema = external_exports.array(
|
|
@@ -92820,8 +92974,8 @@ async function memberBudgetAtomic(account, configured, deps) {
|
|
|
92820
92974
|
deps.now?.() ?? /* @__PURE__ */ new Date(),
|
|
92821
92975
|
account
|
|
92822
92976
|
);
|
|
92823
|
-
const
|
|
92824
|
-
return
|
|
92977
|
+
const remaining2 = BigInt(caps.perDayAtomic) - BigInt(ledger.spentAtomic);
|
|
92978
|
+
return remaining2 < 0n ? 0n : remaining2;
|
|
92825
92979
|
}
|
|
92826
92980
|
function withoutTreasuryGrants(profile) {
|
|
92827
92981
|
return {
|
|
@@ -93035,19 +93189,19 @@ var runRecordSchema = external_exports.strictObject({
|
|
|
93035
93189
|
detail: external_exports.string().optional()
|
|
93036
93190
|
});
|
|
93037
93191
|
function runsDirectory(home) {
|
|
93038
|
-
return
|
|
93192
|
+
return join19(home, "runs");
|
|
93039
93193
|
}
|
|
93040
93194
|
function runRecordPath(home, runId) {
|
|
93041
93195
|
assertRunId(runId);
|
|
93042
|
-
return
|
|
93196
|
+
return join19(runsDirectory(home), `${runId}.json`);
|
|
93043
93197
|
}
|
|
93044
93198
|
function runLogPath(home, runId) {
|
|
93045
93199
|
assertRunId(runId);
|
|
93046
|
-
return
|
|
93200
|
+
return join19(runsDirectory(home), `${runId}.log`);
|
|
93047
93201
|
}
|
|
93048
93202
|
function runResultPath(home, runId) {
|
|
93049
93203
|
assertRunId(runId);
|
|
93050
|
-
return
|
|
93204
|
+
return join19(runsDirectory(home), `${runId}.result.json`);
|
|
93051
93205
|
}
|
|
93052
93206
|
async function writeRunRecord(home, record2) {
|
|
93053
93207
|
const path = runRecordPath(home, record2.runId);
|
|
@@ -93078,7 +93232,7 @@ async function listRunRecords(home, filter = {}) {
|
|
|
93078
93232
|
if (match === null) continue;
|
|
93079
93233
|
try {
|
|
93080
93234
|
const record2 = runRecordSchema.parse(
|
|
93081
|
-
JSON.parse(await readFile23(
|
|
93235
|
+
JSON.parse(await readFile23(join19(runsDirectory(home), file2), "utf8"))
|
|
93082
93236
|
);
|
|
93083
93237
|
if (record2.runId !== match[1]) continue;
|
|
93084
93238
|
if (filter.swarm !== void 0 && record2.member.swarm !== filter.swarm) continue;
|
|
@@ -93215,7 +93369,7 @@ async function startDetachedRun(args) {
|
|
|
93215
93369
|
await writeRunRecord(args.home, reservation);
|
|
93216
93370
|
});
|
|
93217
93371
|
} catch (error61) {
|
|
93218
|
-
await
|
|
93372
|
+
await rm3(runRecordPath(args.home, args.run.runId), { force: true }).catch(
|
|
93219
93373
|
() => void 0
|
|
93220
93374
|
);
|
|
93221
93375
|
throw error61;
|
|
@@ -93234,7 +93388,7 @@ async function startDetachedRun(args) {
|
|
|
93234
93388
|
() => false
|
|
93235
93389
|
);
|
|
93236
93390
|
if (stopped) {
|
|
93237
|
-
await
|
|
93391
|
+
await rm3(runRecordPath(args.home, args.run.runId), { force: true }).catch(
|
|
93238
93392
|
() => void 0
|
|
93239
93393
|
);
|
|
93240
93394
|
}
|
|
@@ -93355,7 +93509,7 @@ async function stopRun(args) {
|
|
|
93355
93509
|
}
|
|
93356
93510
|
}
|
|
93357
93511
|
function memberRunLockPath(home, account) {
|
|
93358
|
-
return
|
|
93512
|
+
return join19(runsDirectory(home), `.member-${account}.lock`);
|
|
93359
93513
|
}
|
|
93360
93514
|
function summarizeRunRecord(record2) {
|
|
93361
93515
|
return {
|
|
@@ -94816,9 +94970,9 @@ async function watchEvents(ctx, input2, now, sleep, deadline, signal, progress)
|
|
|
94816
94970
|
const reached = input2.until !== void 0 && next.events.some((event) => taskStateMatches(input2.until, taskEventState(event)));
|
|
94817
94971
|
if (next.events.length || reached)
|
|
94818
94972
|
return { ...next, ...reached ? { reached: input2.until } : {}, timedOut: false };
|
|
94819
|
-
const
|
|
94820
|
-
if (
|
|
94821
|
-
await sleep(Math.min(TASK_LIMITS.watchIntervalMinMs,
|
|
94973
|
+
const remaining2 = deadline - now().getTime();
|
|
94974
|
+
if (remaining2 <= 0) return { ...next, timedOut: true };
|
|
94975
|
+
await sleep(Math.min(TASK_LIMITS.watchIntervalMinMs, remaining2), signal);
|
|
94822
94976
|
if (now().getTime() >= deadline)
|
|
94823
94977
|
return { events: [], nextCursor: progress.cursor, timedOut: true };
|
|
94824
94978
|
}
|
|
@@ -95861,9 +96015,15 @@ var VapiMcpServer = class {
|
|
|
95861
96015
|
return tool.deprecatedReplacement ? withDeprecation(result, tool.deprecatedReplacement) : result;
|
|
95862
96016
|
}
|
|
95863
96017
|
}
|
|
95864
|
-
|
|
96018
|
+
#output = process.stdout;
|
|
96019
|
+
/**
|
|
96020
|
+
* Serves JSON-RPC lines from `input` and answers on `output`. The desktop
|
|
96021
|
+
* app hands in a socket; the CLI hands in stdio through connectStdio().
|
|
96022
|
+
*/
|
|
96023
|
+
connect(input2, output4) {
|
|
95865
96024
|
if (this.#stdio) return;
|
|
95866
|
-
this.#
|
|
96025
|
+
this.#output = output4;
|
|
96026
|
+
this.#stdio = createInterface({ input: input2, crlfDelay: Infinity });
|
|
95867
96027
|
this.#stdio.on("line", (line) => {
|
|
95868
96028
|
void this.#handleLine(line);
|
|
95869
96029
|
});
|
|
@@ -95872,6 +96032,9 @@ var VapiMcpServer = class {
|
|
|
95872
96032
|
this.#onClose?.();
|
|
95873
96033
|
});
|
|
95874
96034
|
}
|
|
96035
|
+
connectStdio() {
|
|
96036
|
+
this.connect(process.stdin, process.stdout);
|
|
96037
|
+
}
|
|
95875
96038
|
async close() {
|
|
95876
96039
|
this.#stdio?.close();
|
|
95877
96040
|
this.#stdio = void 0;
|
|
@@ -95952,7 +96115,7 @@ var VapiMcpServer = class {
|
|
|
95952
96115
|
}
|
|
95953
96116
|
}
|
|
95954
96117
|
#write(message) {
|
|
95955
|
-
|
|
96118
|
+
this.#output.write(`${JSON.stringify(message)}
|
|
95956
96119
|
`);
|
|
95957
96120
|
}
|
|
95958
96121
|
};
|
|
@@ -96954,7 +97117,7 @@ function rgbToAnsi256(red, green, blue) {
|
|
|
96954
97117
|
|
|
96955
97118
|
// ../cli/src/accounts.ts
|
|
96956
97119
|
import { readFile as readFile25, stat as stat14 } from "node:fs/promises";
|
|
96957
|
-
import { join as
|
|
97120
|
+
import { join as join22 } from "node:path";
|
|
96958
97121
|
|
|
96959
97122
|
// ../cli/src/dashboard.ts
|
|
96960
97123
|
import { resolve as resolve3 } from "node:path";
|
|
@@ -96965,7 +97128,12 @@ var PROBE_MODES = ["origin", "endpoint", "openapi"];
|
|
|
96965
97128
|
var PAYOUT_CHAIN_ID = "eip155:8453";
|
|
96966
97129
|
var PAYOUT_STATEMENT = "Confirm this wallet receives vAPI Call payouts";
|
|
96967
97130
|
var CLAIM_STATEMENT_PREFIX = "Claim the vAPI Call listings served from";
|
|
96968
|
-
|
|
97131
|
+
function apiKeyConsoleUrl(baseUrl) {
|
|
97132
|
+
const url2 = listingsUrl(baseUrl, "/connect");
|
|
97133
|
+
url2.search = "advanced=keys";
|
|
97134
|
+
url2.hash = "api-keys";
|
|
97135
|
+
return url2;
|
|
97136
|
+
}
|
|
96969
97137
|
var RegistryApiError = class extends Error {
|
|
96970
97138
|
constructor(status, message, body) {
|
|
96971
97139
|
super(message);
|
|
@@ -97125,7 +97293,7 @@ async function registryError(response, baseUrl) {
|
|
|
97125
97293
|
[
|
|
97126
97294
|
"The vAPI API key was rejected.",
|
|
97127
97295
|
detail,
|
|
97128
|
-
`Create a key in the console at ${
|
|
97296
|
+
`Create a key in the console at ${apiKeyConsoleUrl(baseUrl).href} and store it with vapi auth set-key.`
|
|
97129
97297
|
].filter(Boolean).join(" "),
|
|
97130
97298
|
body
|
|
97131
97299
|
);
|
|
@@ -97631,7 +97799,7 @@ import { homedir as homedir2 } from "node:os";
|
|
|
97631
97799
|
import { sep } from "node:path";
|
|
97632
97800
|
|
|
97633
97801
|
// ../core/src/cloud-backup.ts
|
|
97634
|
-
import { join as
|
|
97802
|
+
import { join as join21 } from "node:path";
|
|
97635
97803
|
|
|
97636
97804
|
// ../core/src/backup.ts
|
|
97637
97805
|
import {
|
|
@@ -97656,9 +97824,9 @@ import {
|
|
|
97656
97824
|
open as openFile,
|
|
97657
97825
|
readFile as readFile24,
|
|
97658
97826
|
readdir as readdir8,
|
|
97659
|
-
rm as
|
|
97827
|
+
rm as rm4
|
|
97660
97828
|
} from "node:fs/promises";
|
|
97661
|
-
import { dirname as dirname12, join as
|
|
97829
|
+
import { dirname as dirname12, join as join20 } from "node:path";
|
|
97662
97830
|
var ERROR_MESSAGES = {
|
|
97663
97831
|
backup_too_large: "Backup envelope exceeds 65,536 bytes.",
|
|
97664
97832
|
backup_open_failed: "Unable to open backup.",
|
|
@@ -98136,7 +98304,7 @@ async function exportBackupSource(options) {
|
|
|
98136
98304
|
var BackupSnapshotChangedError = class extends Error {
|
|
98137
98305
|
};
|
|
98138
98306
|
async function exportBackupSourceAttempt(options, networks) {
|
|
98139
|
-
const path =
|
|
98307
|
+
const path = join20(options.store.home, "vault.json");
|
|
98140
98308
|
const { phrase, file: file2, accounts } = await withVaultLock(path, async () => {
|
|
98141
98309
|
const [phrase2, vault, file3] = await Promise.all([
|
|
98142
98310
|
exportVaultPhrase({ path, key: options.vaultKey }),
|
|
@@ -98272,16 +98440,16 @@ async function restoreBackupPlaintext(options) {
|
|
|
98272
98440
|
} catch {
|
|
98273
98441
|
throw new BackupError("backup_invalid_input");
|
|
98274
98442
|
}
|
|
98275
|
-
const vaultPath2 =
|
|
98276
|
-
const registryPath =
|
|
98443
|
+
const vaultPath2 = join20(options.home, "vault.json");
|
|
98444
|
+
const registryPath = join20(options.home, "wallets.json");
|
|
98277
98445
|
let stagingHome;
|
|
98278
98446
|
let beforePublishError;
|
|
98279
98447
|
let afterPublishError;
|
|
98280
98448
|
try {
|
|
98281
98449
|
await mkdir19(options.home, { recursive: true, mode: 448 });
|
|
98282
|
-
stagingHome = await mkdtemp(
|
|
98283
|
-
const stagedVaultPath =
|
|
98284
|
-
const stagedRegistryPath =
|
|
98450
|
+
stagingHome = await mkdtemp(join20(options.home, ".backup-restore-"));
|
|
98451
|
+
const stagedVaultPath = join20(stagingHome, "vault.json");
|
|
98452
|
+
const stagedRegistryPath = join20(stagingHome, "wallets.json");
|
|
98285
98453
|
await createVault({
|
|
98286
98454
|
path: stagedVaultPath,
|
|
98287
98455
|
key: options.vaultKey,
|
|
@@ -98340,7 +98508,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
98340
98508
|
protected: plaintext.protected,
|
|
98341
98509
|
networks: [...plaintext.registry.networks]
|
|
98342
98510
|
};
|
|
98343
|
-
const markerPath =
|
|
98511
|
+
const markerPath = join20(options.home, RESTORE_MARKER_FILE);
|
|
98344
98512
|
const fingerprint = restoreFingerprint(
|
|
98345
98513
|
plaintext,
|
|
98346
98514
|
stagedV2?.restoreDevice ?? options.device,
|
|
@@ -98405,7 +98573,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
98405
98573
|
await link2(stagedVaultPath, vaultPath2);
|
|
98406
98574
|
publishedVault = true;
|
|
98407
98575
|
} catch (error61) {
|
|
98408
|
-
await
|
|
98576
|
+
await rm4(markerPath, { force: true }).catch(() => void 0);
|
|
98409
98577
|
throw error61;
|
|
98410
98578
|
}
|
|
98411
98579
|
await notifyRestorePublish(options.afterPublish, { kind: "vault" }, (error61) => {
|
|
@@ -98416,8 +98584,8 @@ async function restoreBackupPlaintext(options) {
|
|
|
98416
98584
|
try {
|
|
98417
98585
|
await link2(stagedRegistryPath, registryPath);
|
|
98418
98586
|
} catch (error61) {
|
|
98419
|
-
if (publishedVault) await
|
|
98420
|
-
await
|
|
98587
|
+
if (publishedVault) await rm4(vaultPath2, { force: true }).catch(() => void 0);
|
|
98588
|
+
await rm4(markerPath, { force: true }).catch(() => void 0);
|
|
98421
98589
|
throw error61;
|
|
98422
98590
|
}
|
|
98423
98591
|
await notifyRestorePublish(options.afterPublish, { kind: "registry" }, (error61) => {
|
|
@@ -98431,7 +98599,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
98431
98599
|
});
|
|
98432
98600
|
});
|
|
98433
98601
|
}
|
|
98434
|
-
await
|
|
98602
|
+
await rm4(markerPath, { force: true });
|
|
98435
98603
|
});
|
|
98436
98604
|
if (stagedV2 === void 0) return baseResult;
|
|
98437
98605
|
return {
|
|
@@ -98452,7 +98620,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
98452
98620
|
throw new BackupError("backup_invalid_input");
|
|
98453
98621
|
} finally {
|
|
98454
98622
|
if (stagingHome !== void 0) {
|
|
98455
|
-
await
|
|
98623
|
+
await rm4(stagingHome, { recursive: true, force: true }).catch(() => void 0);
|
|
98456
98624
|
}
|
|
98457
98625
|
}
|
|
98458
98626
|
}
|
|
@@ -98551,13 +98719,13 @@ async function stageV2Restore(options) {
|
|
|
98551
98719
|
}
|
|
98552
98720
|
const agents = [];
|
|
98553
98721
|
for (const profile of validAgents) {
|
|
98554
|
-
const stagedPath =
|
|
98722
|
+
const stagedPath = join20(options.stagingHome, "agents", `${profile.name}.json`);
|
|
98555
98723
|
if (await stageRestoreBytes(stagedPath, prettyJson(profile))) {
|
|
98556
98724
|
agents.push({
|
|
98557
98725
|
kind: "agent",
|
|
98558
98726
|
name: profile.name,
|
|
98559
98727
|
stagedPath,
|
|
98560
|
-
targetPath:
|
|
98728
|
+
targetPath: join20(options.home, "agents", `${profile.name}.json`)
|
|
98561
98729
|
});
|
|
98562
98730
|
} else {
|
|
98563
98731
|
skipped2.push({ kind: "agent", name: profile.name, reason: "write_failed" });
|
|
@@ -98577,13 +98745,13 @@ async function stageV2Restore(options) {
|
|
|
98577
98745
|
if (restoreDevice !== void 0) {
|
|
98578
98746
|
for (const value of validSwarms) {
|
|
98579
98747
|
const swarm = swarmFileSchema.parse({ ...value, device: restoreDevice });
|
|
98580
|
-
const stagedPath =
|
|
98748
|
+
const stagedPath = join20(options.stagingHome, "swarms", `${swarm.name}.json`);
|
|
98581
98749
|
if (await stageRestoreBytes(stagedPath, prettyJson(swarm))) {
|
|
98582
98750
|
swarms.push({
|
|
98583
98751
|
kind: "swarm",
|
|
98584
98752
|
name: swarm.name,
|
|
98585
98753
|
stagedPath,
|
|
98586
|
-
targetPath:
|
|
98754
|
+
targetPath: join20(options.home, "swarms", `${swarm.name}.json`)
|
|
98587
98755
|
});
|
|
98588
98756
|
} else {
|
|
98589
98757
|
skipped2.push({ kind: "swarm", name: swarm.name, reason: "write_failed" });
|
|
@@ -98593,13 +98761,13 @@ async function stageV2Restore(options) {
|
|
|
98593
98761
|
const movements = [];
|
|
98594
98762
|
for (const movement of validMovements) {
|
|
98595
98763
|
const restored = reconcileRestoredMovement(movement, assumedReceiptKeys);
|
|
98596
|
-
const stagedPath =
|
|
98764
|
+
const stagedPath = join20(options.stagingHome, "movements", `${restored.id}.json`);
|
|
98597
98765
|
if (await stageRestoreBytes(stagedPath, serializeMovement(restored))) {
|
|
98598
98766
|
movements.push({
|
|
98599
98767
|
kind: "movement",
|
|
98600
98768
|
name: restored.id,
|
|
98601
98769
|
stagedPath,
|
|
98602
|
-
targetPath:
|
|
98770
|
+
targetPath: join20(options.home, "movements", `${restored.id}.json`),
|
|
98603
98771
|
movement: restored
|
|
98604
98772
|
});
|
|
98605
98773
|
} else {
|
|
@@ -98758,7 +98926,7 @@ async function reconcilePublishedMovements(staged, home, requireDurableSafety =
|
|
|
98758
98926
|
const unjournaledKeys = new Set([...signedKeys].filter((key2) => !journaledKeys.has(key2)));
|
|
98759
98927
|
let files;
|
|
98760
98928
|
try {
|
|
98761
|
-
files = await readdir8(
|
|
98929
|
+
files = await readdir8(join20(home, "movements"));
|
|
98762
98930
|
} catch (error61) {
|
|
98763
98931
|
if (isMissingFile4(error61)) return;
|
|
98764
98932
|
if (requireDurableSafety && unjournaledKeys.size > 0) throw error61;
|
|
@@ -99537,10 +99705,10 @@ async function awaitRelay(options) {
|
|
|
99537
99705
|
if (!Number.isFinite(deadline)) throw new CloudBackupError("relay_expired");
|
|
99538
99706
|
while (true) {
|
|
99539
99707
|
if (isAborted(options.signal)) throw new CloudBackupError("relay_aborted");
|
|
99540
|
-
const
|
|
99541
|
-
if (
|
|
99708
|
+
const remaining2 = deadline - readNow(now).getTime();
|
|
99709
|
+
if (remaining2 <= 0) throw new CloudBackupError("relay_expired");
|
|
99542
99710
|
let response;
|
|
99543
|
-
const requestDeadline = AbortSignal.timeout(Math.max(1,
|
|
99711
|
+
const requestDeadline = AbortSignal.timeout(Math.max(1, remaining2));
|
|
99544
99712
|
const requestSignal = options.signal === void 0 ? requestDeadline : AbortSignal.any([options.signal, requestDeadline]);
|
|
99545
99713
|
try {
|
|
99546
99714
|
response = await (options.fetchImpl ?? publicFetch5)(
|
|
@@ -99559,7 +99727,7 @@ async function awaitRelay(options) {
|
|
|
99559
99727
|
return await readRelayResult(response, options);
|
|
99560
99728
|
}
|
|
99561
99729
|
try {
|
|
99562
|
-
await sleep(Math.min(Math.max(0, pollMs),
|
|
99730
|
+
await sleep(Math.min(Math.max(0, pollMs), remaining2), options.signal);
|
|
99563
99731
|
} catch {
|
|
99564
99732
|
if (isAborted(options.signal)) throw new CloudBackupError("relay_aborted");
|
|
99565
99733
|
}
|
|
@@ -99667,7 +99835,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
99667
99835
|
try {
|
|
99668
99836
|
let vaultFile;
|
|
99669
99837
|
try {
|
|
99670
|
-
vaultFile = await readVaultFileUnlocked(
|
|
99838
|
+
vaultFile = await readVaultFileUnlocked(join21(options.store.home, "vault.json"));
|
|
99671
99839
|
} catch (error61) {
|
|
99672
99840
|
if (error61 instanceof VaultError && error61.code === "not_found") {
|
|
99673
99841
|
return { status: "skipped", reason: "no_vault" };
|
|
@@ -99676,7 +99844,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
99676
99844
|
}
|
|
99677
99845
|
try {
|
|
99678
99846
|
vaultKey = vaultFile.protected ? await unlockProtectedVault({
|
|
99679
|
-
path:
|
|
99847
|
+
path: join21(options.store.home, "vault.json"),
|
|
99680
99848
|
secrets: options.secrets,
|
|
99681
99849
|
env: options.env,
|
|
99682
99850
|
...options.now === void 0 ? {} : { now: options.now }
|
|
@@ -100349,7 +100517,7 @@ async function readProcessStdin() {
|
|
|
100349
100517
|
}
|
|
100350
100518
|
|
|
100351
100519
|
// ../cli/src/version.ts
|
|
100352
|
-
var CLI_VERSION = "0.
|
|
100520
|
+
var CLI_VERSION = "0.12.1";
|
|
100353
100521
|
|
|
100354
100522
|
// ../cli/src/status.ts
|
|
100355
100523
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -100851,10 +101019,10 @@ async function accountsRenameCommand(argv, json2, io, dependencies) {
|
|
|
100851
101019
|
{
|
|
100852
101020
|
previous: from16,
|
|
100853
101021
|
...address4 === void 0 ? {} : { address: address4 },
|
|
100854
|
-
vault:
|
|
101022
|
+
vault: join22(store.home, "vault.json"),
|
|
100855
101023
|
message: `Wallet ${from16} is now ${renamed.name}.`
|
|
100856
101024
|
},
|
|
100857
|
-
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${
|
|
101025
|
+
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${join22(store.home, "vault.json")}`].join(
|
|
100858
101026
|
"\n"
|
|
100859
101027
|
)
|
|
100860
101028
|
);
|
|
@@ -100963,13 +101131,13 @@ async function accountsRestoreCommand(argv, json2, io, dependencies) {
|
|
|
100963
101131
|
{ name: restored.name, ...address4 === void 0 ? {} : { address: address4 } },
|
|
100964
101132
|
{
|
|
100965
101133
|
...address4 === void 0 ? {} : { address: address4 },
|
|
100966
|
-
vault:
|
|
101134
|
+
vault: join22(store.home, "vault.json"),
|
|
100967
101135
|
spendCaps: restored.entry.spendCaps,
|
|
100968
101136
|
message: `Wallet ${restored.name} restored to the device vault.`
|
|
100969
101137
|
},
|
|
100970
101138
|
[
|
|
100971
101139
|
`Wallet ${restored.name} restored to the device vault.`,
|
|
100972
|
-
`Vault: ${
|
|
101140
|
+
`Vault: ${join22(store.home, "vault.json")}`
|
|
100973
101141
|
].join("\n")
|
|
100974
101142
|
);
|
|
100975
101143
|
}
|
|
@@ -101299,7 +101467,7 @@ function formatNetworkAccounts(accounts) {
|
|
|
101299
101467
|
}
|
|
101300
101468
|
|
|
101301
101469
|
// ../cli/src/cloud-backup.ts
|
|
101302
|
-
import { join as
|
|
101470
|
+
import { join as join23 } from "node:path";
|
|
101303
101471
|
var CLOUD_BACKUP_USAGE = "Usage: vapi backup --cloud [off] [--json]";
|
|
101304
101472
|
var OWNER_RESTORE_USAGE = "Usage: vapi restore --from-owner [--owner <0x\u2026>] [--json]";
|
|
101305
101473
|
var OWNER_PATTERN2 = /^0x[0-9a-fA-F]{40}$/u;
|
|
@@ -101322,7 +101490,7 @@ async function cloudBackupCommand(argv, json2, io, dependencies) {
|
|
|
101322
101490
|
}
|
|
101323
101491
|
async function enrollCloudBackup(json2, io, dependencies) {
|
|
101324
101492
|
const paths = getVapiPaths();
|
|
101325
|
-
if (!await fileExists2(
|
|
101493
|
+
if (!await fileExists2(join23(paths.directory, "vault.json"))) {
|
|
101326
101494
|
throw new Error("No vault on this device. Run vapi setup first.");
|
|
101327
101495
|
}
|
|
101328
101496
|
const context = await cloudContext(io, dependencies);
|
|
@@ -101434,7 +101602,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
101434
101602
|
}
|
|
101435
101603
|
const expectedOwner = ownerValue?.toLowerCase();
|
|
101436
101604
|
const paths = getVapiPaths();
|
|
101437
|
-
if (await fileExists2(
|
|
101605
|
+
if (await fileExists2(join23(paths.directory, "vault.json")) && !await fileExists2(join23(paths.directory, ".backup-restore.json"))) {
|
|
101438
101606
|
throw new Error(
|
|
101439
101607
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
101440
101608
|
);
|
|
@@ -102532,21 +102700,21 @@ function shortExcerpt(value) {
|
|
|
102532
102700
|
|
|
102533
102701
|
// ../cli/src/agent.ts
|
|
102534
102702
|
import { readFile as readFile27, stat as stat15 } from "node:fs/promises";
|
|
102535
|
-
import { join as
|
|
102703
|
+
import { join as join26 } from "node:path";
|
|
102536
102704
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
102537
102705
|
|
|
102538
102706
|
// ../cli/src/headless.ts
|
|
102539
|
-
import { chmod as chmod7, mkdtemp as mkdtemp2, rm as
|
|
102707
|
+
import { chmod as chmod7, mkdtemp as mkdtemp2, rm as rm5, writeFile as writeFile10 } from "node:fs/promises";
|
|
102540
102708
|
import { rmSync } from "node:fs";
|
|
102541
102709
|
import { tmpdir as osTmpdir } from "node:os";
|
|
102542
|
-
import { join as
|
|
102710
|
+
import { join as join24 } from "node:path";
|
|
102543
102711
|
var BUNDLE_VARIABLE_PATTERN = /^[A-Z_][A-Z0-9_]*$/u;
|
|
102544
102712
|
var REMOTE_BLOCKED_GRANTS2 = /* @__PURE__ */ new Set(["delegate", "allocate"]);
|
|
102545
102713
|
var agentProfileOptions = { schema: registeredAgentProfileSchema };
|
|
102546
102714
|
async function createHeadlessHome(bundle, options = {}) {
|
|
102547
|
-
const home = await mkdtemp2(
|
|
102715
|
+
const home = await mkdtemp2(join24(options.tmpdir ?? osTmpdir(), "vapi-headless-"));
|
|
102548
102716
|
const cleanup = async () => {
|
|
102549
|
-
await
|
|
102717
|
+
await rm5(home, { recursive: true, force: true });
|
|
102550
102718
|
};
|
|
102551
102719
|
try {
|
|
102552
102720
|
await chmod7(home, 448);
|
|
@@ -102693,7 +102861,7 @@ async function runHeadlessAgent(input2) {
|
|
|
102693
102861
|
} finally {
|
|
102694
102862
|
if (previousHome === void 0) delete process.env.VAPI_HOME;
|
|
102695
102863
|
else process.env.VAPI_HOME = previousHome;
|
|
102696
|
-
if (home !== void 0) await
|
|
102864
|
+
if (home !== void 0) await rm5(home, { recursive: true, force: true });
|
|
102697
102865
|
removeSignalHandlers();
|
|
102698
102866
|
}
|
|
102699
102867
|
}
|
|
@@ -102755,7 +102923,7 @@ import {
|
|
|
102755
102923
|
writeFile as nodeWriteFile
|
|
102756
102924
|
} from "node:fs/promises";
|
|
102757
102925
|
import { tmpdir as osTmpdir2 } from "node:os";
|
|
102758
|
-
import { basename as basename4, dirname as dirname13, join as
|
|
102926
|
+
import { basename as basename4, dirname as dirname13, join as join25 } from "node:path";
|
|
102759
102927
|
var RAILWAY_CLI = {
|
|
102760
102928
|
binary: "railway",
|
|
102761
102929
|
create: (options) => [
|
|
@@ -102927,7 +103095,7 @@ async function assertRemoteSafeMember(args) {
|
|
|
102927
103095
|
}
|
|
102928
103096
|
function railwaySidecarPath(home, runId) {
|
|
102929
103097
|
if (!isRunId(runId)) throw new RuntimeError("invalid_run_id", `Invalid run id: ${runId}.`);
|
|
102930
|
-
return
|
|
103098
|
+
return join25(runsDirectory(home), `${runId}.railway.json`);
|
|
102931
103099
|
}
|
|
102932
103100
|
function createRailwayRuntime(options) {
|
|
102933
103101
|
const { home } = options;
|
|
@@ -103252,10 +103420,10 @@ function createRailwayRuntime(options) {
|
|
|
103252
103420
|
let createError;
|
|
103253
103421
|
let cleanupError;
|
|
103254
103422
|
try {
|
|
103255
|
-
directory = await fs.mkdtemp(
|
|
103423
|
+
directory = await fs.mkdtemp(join25(options.tmpdir ?? osTmpdir2(), "vapi-railway-"));
|
|
103256
103424
|
assertNotInterrupted();
|
|
103257
103425
|
await assertMode(fs, directory, 448, "env-file directory");
|
|
103258
|
-
envFile =
|
|
103426
|
+
envFile = join25(directory, "member.env");
|
|
103259
103427
|
await fs.writeFile(envFile, `${RAILWAY_CLI.bundleVariable}=${bundle}
|
|
103260
103428
|
`, {
|
|
103261
103429
|
encoding: "utf8",
|
|
@@ -103574,9 +103742,9 @@ async function reserveRemoteAllowance(args) {
|
|
|
103574
103742
|
const perDayAtomic = BigInt(args.caps.perDayAtomic);
|
|
103575
103743
|
const ledgerPath = getVapiPaths(args.home).ledger;
|
|
103576
103744
|
const spent = BigInt((await readSpendLedger(ledgerPath, args.now, args.account)).spentAtomic);
|
|
103577
|
-
const
|
|
103578
|
-
const requested = args.run.budgetUsd === void 0 ?
|
|
103579
|
-
const reserved = requested <
|
|
103745
|
+
const remaining2 = spent >= perDayAtomic ? 0n : perDayAtomic - spent;
|
|
103746
|
+
const requested = args.run.budgetUsd === void 0 ? remaining2 : usdToAtomic(args.run.budgetUsd);
|
|
103747
|
+
const reserved = requested < remaining2 ? requested : remaining2;
|
|
103580
103748
|
if (reserved === 0n) {
|
|
103581
103749
|
throw new RemoteKeyRefusedError(
|
|
103582
103750
|
"no_daily_allowance",
|
|
@@ -103710,7 +103878,7 @@ async function writeSidecar(home, runId, sidecar) {
|
|
|
103710
103878
|
function writeSidecarSync(path, sidecar) {
|
|
103711
103879
|
const directory = dirname13(path);
|
|
103712
103880
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
103713
|
-
const temporary =
|
|
103881
|
+
const temporary = join25(
|
|
103714
103882
|
directory,
|
|
103715
103883
|
`.${basename4(path)}.${process.pid}.${randomBytes16(6).toString("hex")}.tmp`
|
|
103716
103884
|
);
|
|
@@ -103808,7 +103976,7 @@ async function assertMode(fs, path, mode, what) {
|
|
|
103808
103976
|
}
|
|
103809
103977
|
}
|
|
103810
103978
|
async function deviceVaultKey(home, secrets, now) {
|
|
103811
|
-
const path =
|
|
103979
|
+
const path = join25(home, "vault.json");
|
|
103812
103980
|
const metadata = await readVaultFileUnlocked(path);
|
|
103813
103981
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
103814
103982
|
path,
|
|
@@ -103858,12 +104026,12 @@ function createLocalRuntime(options) {
|
|
|
103858
104026
|
const { home } = options;
|
|
103859
104027
|
const entry = options.entry ?? realpathSync(process.argv[1]);
|
|
103860
104028
|
const execPath = options.execPath ?? process.execPath;
|
|
103861
|
-
const
|
|
104029
|
+
const spawn6 = options.spawn ?? nodeSpawn;
|
|
103862
104030
|
const kill = options.kill ?? ((pid, signal) => process.kill(pid, signal));
|
|
103863
104031
|
const processCommand = options.processCommand ?? defaultProcessCommand;
|
|
103864
104032
|
const ownsProcess = (handle, pid) => processCommand(pid)?.includes(runResultPath(home, handle.runId)) === true;
|
|
103865
104033
|
const closeFd = options.closeFd ?? closeSync2;
|
|
103866
|
-
const
|
|
104034
|
+
const readFile33 = options.readFile ?? nodeReadFile;
|
|
103867
104035
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
103868
104036
|
const openLog = options.openLog ?? ((path) => {
|
|
103869
104037
|
mkdirSync2(runsDirectory(home), { recursive: true, mode: 448 });
|
|
@@ -103881,7 +104049,7 @@ function createLocalRuntime(options) {
|
|
|
103881
104049
|
const logFd = openLog(logPath);
|
|
103882
104050
|
let child;
|
|
103883
104051
|
try {
|
|
103884
|
-
child =
|
|
104052
|
+
child = spawn6(execPath, [entry, ...args, "--json", "--result-file", resultPath], {
|
|
103885
104053
|
detached: true,
|
|
103886
104054
|
stdio: ["ignore", logFd, logFd],
|
|
103887
104055
|
env: {
|
|
@@ -103918,7 +104086,7 @@ function createLocalRuntime(options) {
|
|
|
103918
104086
|
return handle;
|
|
103919
104087
|
},
|
|
103920
104088
|
async status(handle) {
|
|
103921
|
-
const result = await readResultFile(
|
|
104089
|
+
const result = await readResultFile(readFile33, runResultPath(home, handle.runId));
|
|
103922
104090
|
if (result !== void 0) return result;
|
|
103923
104091
|
const pid = localPid(handle);
|
|
103924
104092
|
if (pid === void 0 || handle.kind !== "local") {
|
|
@@ -104021,10 +104189,10 @@ function childArguments(member, run) {
|
|
|
104021
104189
|
...run.drawUsd ? ["--draw", run.drawUsd] : []
|
|
104022
104190
|
];
|
|
104023
104191
|
}
|
|
104024
|
-
async function readResultFile(
|
|
104192
|
+
async function readResultFile(readFile33, path) {
|
|
104025
104193
|
let text;
|
|
104026
104194
|
try {
|
|
104027
|
-
text = await
|
|
104195
|
+
text = await readFile33(path, "utf8");
|
|
104028
104196
|
} catch (error61) {
|
|
104029
104197
|
if (hasCode3(error61, "ENOENT")) return void 0;
|
|
104030
104198
|
return { state: "failed", detail: "unreadable result file" };
|
|
@@ -104735,7 +104903,7 @@ function explicitWallet(name) {
|
|
|
104735
104903
|
}
|
|
104736
104904
|
async function profileFileExists(directory, name) {
|
|
104737
104905
|
try {
|
|
104738
|
-
await stat15(
|
|
104906
|
+
await stat15(join26(directory, `${name}.json`));
|
|
104739
104907
|
return true;
|
|
104740
104908
|
} catch (error61) {
|
|
104741
104909
|
if (isMissingFile(error61)) return false;
|
|
@@ -104799,6 +104967,80 @@ import { spawn as spawn3 } from "node:child_process";
|
|
|
104799
104967
|
import { mkdir as mkdir20, readFile as readFile28, writeFile as writeFile11 } from "node:fs/promises";
|
|
104800
104968
|
import { homedir as systemHomedir } from "node:os";
|
|
104801
104969
|
import { dirname as dirname14, posix, win32 as win322 } from "node:path";
|
|
104970
|
+
|
|
104971
|
+
// ../cli/src/toml-config.ts
|
|
104972
|
+
function removeTomlTables(contents, isTarget) {
|
|
104973
|
+
let removing = false;
|
|
104974
|
+
let retained = "";
|
|
104975
|
+
for (const { line, table } of tomlLines(contents)) {
|
|
104976
|
+
if (table !== void 0) removing = isTarget(tomlKeyPath(table));
|
|
104977
|
+
if (!removing) retained += line;
|
|
104978
|
+
}
|
|
104979
|
+
return retained;
|
|
104980
|
+
}
|
|
104981
|
+
function* tomlLines(contents) {
|
|
104982
|
+
let multiline;
|
|
104983
|
+
for (const line of contents.match(/[^\n]*\n|[^\n]+$/g) ?? []) {
|
|
104984
|
+
yield { line, table: multiline === void 0 ? tomlTableName(line) : void 0 };
|
|
104985
|
+
for (let index2 = 0; index2 < line.length; index2 += 1) {
|
|
104986
|
+
const char = line[index2];
|
|
104987
|
+
if (multiline !== void 0) {
|
|
104988
|
+
if (multiline === '"""' && char === "\\") {
|
|
104989
|
+
index2 += 1;
|
|
104990
|
+
continue;
|
|
104991
|
+
}
|
|
104992
|
+
if (line.startsWith(multiline, index2)) {
|
|
104993
|
+
index2 += 2;
|
|
104994
|
+
multiline = void 0;
|
|
104995
|
+
}
|
|
104996
|
+
} else {
|
|
104997
|
+
if (char === "#") break;
|
|
104998
|
+
if (char !== "'" && char !== '"') continue;
|
|
104999
|
+
const delimiter2 = char.repeat(3);
|
|
105000
|
+
if (line.startsWith(delimiter2, index2)) {
|
|
105001
|
+
multiline = delimiter2;
|
|
105002
|
+
index2 += 2;
|
|
105003
|
+
} else {
|
|
105004
|
+
for (index2 += 1; index2 < line.length; index2 += 1) {
|
|
105005
|
+
if (char === '"' && line[index2] === "\\") index2 += 1;
|
|
105006
|
+
else if (line[index2] === char) break;
|
|
105007
|
+
}
|
|
105008
|
+
}
|
|
105009
|
+
}
|
|
105010
|
+
}
|
|
105011
|
+
}
|
|
105012
|
+
}
|
|
105013
|
+
function tomlKeyPath(table) {
|
|
105014
|
+
const key2 = String.raw`(?:[A-Za-z0-9_-]+|"(?:[^"\\]|\\.)*"|'[^']*')`;
|
|
105015
|
+
const pattern = new RegExp(`^\\s*(${key2})(?:\\s*\\.\\s*(${key2}))*\\s*$`);
|
|
105016
|
+
if (!pattern.test(table)) return [];
|
|
105017
|
+
return [...table.matchAll(new RegExp(key2, "g"))].map(([part]) => unquoteTomlKey(part));
|
|
105018
|
+
}
|
|
105019
|
+
function tomlTableName(line) {
|
|
105020
|
+
const header = line.replace(/\r?\n$/, "");
|
|
105021
|
+
const match = /^\s*(?:\[\[\s*(.*?)\s*\]\]|\[\s*(.*?)\s*\])\s*(?:#.*)?$/.exec(header);
|
|
105022
|
+
return match?.[1] ?? match?.[2];
|
|
105023
|
+
}
|
|
105024
|
+
function unquoteTomlKey(key2) {
|
|
105025
|
+
if (key2.startsWith("'") && key2.endsWith("'")) return key2.slice(1, -1);
|
|
105026
|
+
if (key2.startsWith('"') && key2.endsWith('"')) {
|
|
105027
|
+
try {
|
|
105028
|
+
return JSON.parse(key2);
|
|
105029
|
+
} catch {
|
|
105030
|
+
return key2;
|
|
105031
|
+
}
|
|
105032
|
+
}
|
|
105033
|
+
return key2;
|
|
105034
|
+
}
|
|
105035
|
+
function tomlSeparator(contents) {
|
|
105036
|
+
if (contents.length === 0 || /(?:\r?\n)[ \t]*(?:\r?\n)$/.test(contents)) return "";
|
|
105037
|
+
return /\r?\n$/.test(contents) ? "\n" : "\n\n";
|
|
105038
|
+
}
|
|
105039
|
+
function escapeToml(value) {
|
|
105040
|
+
return JSON.stringify(value).slice(1, -1);
|
|
105041
|
+
}
|
|
105042
|
+
|
|
105043
|
+
// ../cli/src/mcp-install.ts
|
|
104802
105044
|
var MCP_INSTALL_USAGE = "Usage: vapi mcp install <claude-code|claude-desktop|cursor|codex> [--home <dir>] [--registry <url>] [--no-link] [--json]";
|
|
104803
105045
|
var APPS = /* @__PURE__ */ new Set(["claude-code", "claude-desktop", "cursor", "codex"]);
|
|
104804
105046
|
var CLAUDE_ALIAS_NOTICE = "vapi mcp install claude installs into Claude Desktop; for the Claude Code CLI use: vapi mcp install claude-code";
|
|
@@ -105084,7 +105326,10 @@ function jsonConfig(path, existing, entry) {
|
|
|
105084
105326
|
`;
|
|
105085
105327
|
}
|
|
105086
105328
|
function tomlConfig(existing, entry) {
|
|
105087
|
-
const retained =
|
|
105329
|
+
const retained = removeTomlTables(
|
|
105330
|
+
existing,
|
|
105331
|
+
([root, name]) => root === "mcp_servers" && name === "vapi"
|
|
105332
|
+
);
|
|
105088
105333
|
const block = [
|
|
105089
105334
|
"[mcp_servers.vapi]",
|
|
105090
105335
|
'command = "npx"',
|
|
@@ -105094,46 +105339,6 @@ function tomlConfig(existing, entry) {
|
|
|
105094
105339
|
].join("\n");
|
|
105095
105340
|
return `${retained}${tomlSeparator(retained)}${block}`;
|
|
105096
105341
|
}
|
|
105097
|
-
function removeVapiTomlTables(contents) {
|
|
105098
|
-
const lines = contents.match(/[^\n]*\n|[^\n]+$/g) ?? [];
|
|
105099
|
-
let removing = false;
|
|
105100
|
-
let retained = "";
|
|
105101
|
-
for (const line of lines) {
|
|
105102
|
-
const table = tomlTableName(line);
|
|
105103
|
-
if (table !== void 0) removing = isVapiTomlTable(table);
|
|
105104
|
-
if (!removing) retained += line;
|
|
105105
|
-
}
|
|
105106
|
-
return retained;
|
|
105107
|
-
}
|
|
105108
|
-
function tomlTableName(line) {
|
|
105109
|
-
const header = line.replace(/\r?\n$/, "");
|
|
105110
|
-
const match = /^\s*(?:\[\[\s*(.*?)\s*\]\]|\[\s*(.*?)\s*\])\s*(?:#.*)?$/.exec(header);
|
|
105111
|
-
return match?.[1] ?? match?.[2];
|
|
105112
|
-
}
|
|
105113
|
-
function isVapiTomlTable(table) {
|
|
105114
|
-
const key2 = String.raw`(?:[A-Za-z0-9_-]+|"(?:[^"\\]|\\.)*"|'[^']*')`;
|
|
105115
|
-
const match = new RegExp(`^\\s*(${key2})\\s*\\.\\s*(${key2})(?:\\s*\\.|\\s*$)`).exec(table);
|
|
105116
|
-
if (match === null) return false;
|
|
105117
|
-
return unquoteTomlKey(match[1]) === "mcp_servers" && unquoteTomlKey(match[2]) === "vapi";
|
|
105118
|
-
}
|
|
105119
|
-
function unquoteTomlKey(key2) {
|
|
105120
|
-
if (key2.startsWith("'") && key2.endsWith("'")) return key2.slice(1, -1);
|
|
105121
|
-
if (key2.startsWith('"') && key2.endsWith('"')) {
|
|
105122
|
-
try {
|
|
105123
|
-
return JSON.parse(key2);
|
|
105124
|
-
} catch {
|
|
105125
|
-
return key2;
|
|
105126
|
-
}
|
|
105127
|
-
}
|
|
105128
|
-
return key2;
|
|
105129
|
-
}
|
|
105130
|
-
function tomlSeparator(contents) {
|
|
105131
|
-
if (contents.length === 0 || /(?:\r?\n)[ \t]*(?:\r?\n)$/.test(contents)) return "";
|
|
105132
|
-
return /\r?\n$/.test(contents) ? "\n" : "\n\n";
|
|
105133
|
-
}
|
|
105134
|
-
function escapeToml(value) {
|
|
105135
|
-
return value.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
|
105136
|
-
}
|
|
105137
105342
|
function isRecord12(value) {
|
|
105138
105343
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
105139
105344
|
}
|
|
@@ -105155,6 +105360,546 @@ async function pathExists5(path) {
|
|
|
105155
105360
|
}
|
|
105156
105361
|
}
|
|
105157
105362
|
|
|
105363
|
+
// ../cli/src/code.ts
|
|
105364
|
+
import { constants as constants2 } from "node:fs";
|
|
105365
|
+
import { access, mkdir as mkdir21, readFile as readFile29, realpath, unlink as unlink13, writeFile as writeFile12 } from "node:fs/promises";
|
|
105366
|
+
import { homedir as homedir3 } from "node:os";
|
|
105367
|
+
import { basename as basename5, dirname as dirname15, join as join27, posix as posix2, win32 as win323 } from "node:path";
|
|
105368
|
+
var VAPI_CODEX_PROVIDER = "vapi";
|
|
105369
|
+
var VAPI_CODEX_PROFILE = "vapi";
|
|
105370
|
+
var VAPI_CODEX_DEFAULT_MODEL = "venice/openai-gpt-61-sol";
|
|
105371
|
+
var VAPI_ROUTER_KEY_ENV = "VAPI_ROUTER_KEY";
|
|
105372
|
+
function codexConfigPath(env, home) {
|
|
105373
|
+
return join27(env.CODEX_HOME || join27(home, ".codex"), "config.toml");
|
|
105374
|
+
}
|
|
105375
|
+
function hasVapiCodexProfile(contents) {
|
|
105376
|
+
const roots = new Set(
|
|
105377
|
+
[...tomlLines(contents)].flatMap(({ table }) => {
|
|
105378
|
+
const path = table === void 0 ? [] : tomlKeyPath(table);
|
|
105379
|
+
return path.length === 2 && path[1] === "vapi" ? [path[0]] : [];
|
|
105380
|
+
})
|
|
105381
|
+
);
|
|
105382
|
+
return roots.has("model_providers") && roots.has("profiles");
|
|
105383
|
+
}
|
|
105384
|
+
async function resolveBinary(name, options) {
|
|
105385
|
+
const windows = (options.platform ?? process.platform) === "win32";
|
|
105386
|
+
const path = options.env.PATH ?? (windows ? Object.entries(options.env).find(([key2]) => key2.toLowerCase() === "path")?.[1] : void 0);
|
|
105387
|
+
if (path === void 0) return void 0;
|
|
105388
|
+
const paths = windows ? win323 : posix2;
|
|
105389
|
+
const canonical = options.realpath ?? realpath;
|
|
105390
|
+
const executable = options.isExecutable ?? (async (candidate) => {
|
|
105391
|
+
try {
|
|
105392
|
+
await access(candidate, constants2.X_OK);
|
|
105393
|
+
return true;
|
|
105394
|
+
} catch (error61) {
|
|
105395
|
+
if (isMissingFile(error61) || error61.code === "EACCES")
|
|
105396
|
+
return false;
|
|
105397
|
+
throw error61;
|
|
105398
|
+
}
|
|
105399
|
+
});
|
|
105400
|
+
const self = options.selfPath ?? process.argv[1];
|
|
105401
|
+
const selfReal = self === void 0 ? void 0 : await canonical(self);
|
|
105402
|
+
const extensions = windows ? ["", ...(options.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";")] : [""];
|
|
105403
|
+
for (const directory of path.split(windows ? ";" : ":")) {
|
|
105404
|
+
for (const extension of extensions) {
|
|
105405
|
+
const candidate = paths.resolve(directory.replace(/^"|"$/gu, ""), `${name}${extension}`);
|
|
105406
|
+
if (!await executable(candidate)) continue;
|
|
105407
|
+
const resolved = await canonical(candidate);
|
|
105408
|
+
if (selfReal !== void 0 && (windows ? resolved.toLowerCase() === selfReal.toLowerCase() : resolved === selfReal))
|
|
105409
|
+
continue;
|
|
105410
|
+
return candidate;
|
|
105411
|
+
}
|
|
105412
|
+
}
|
|
105413
|
+
return void 0;
|
|
105414
|
+
}
|
|
105415
|
+
var RC_START = "# >>> vapi code >>>";
|
|
105416
|
+
var RC_END = "# <<< vapi code <<<";
|
|
105417
|
+
var CONFIG_END = "# <<< vapi code config <<<\n";
|
|
105418
|
+
var isCodeTable = ([root, name]) => name === "vapi" && (root === "model_providers" || root === "profiles");
|
|
105419
|
+
function cleanConfig(contents) {
|
|
105420
|
+
let created = false;
|
|
105421
|
+
const cleaned = contents.replace(
|
|
105422
|
+
/(\n?)\[model_providers\.vapi\]\n# >>> vapi code config (created|existing) (0|1) >>>\n([\s\S]*?)# <<< vapi code config <<<\n/gu,
|
|
105423
|
+
(_, prefix, kind, separator, body) => {
|
|
105424
|
+
created ||= kind === "created";
|
|
105425
|
+
return (separator === "1" ? "" : prefix) + removeTomlTables(`[model_providers.vapi]
|
|
105426
|
+
${body}`, isCodeTable);
|
|
105427
|
+
}
|
|
105428
|
+
);
|
|
105429
|
+
return { contents: removeTomlTables(cleaned, isCodeTable), created };
|
|
105430
|
+
}
|
|
105431
|
+
function configContents(existing, baseURL) {
|
|
105432
|
+
const clean2 = cleanConfig(existing ?? "");
|
|
105433
|
+
const retained = clean2.contents;
|
|
105434
|
+
const separator = retained.length > 0 && !retained.endsWith("\n") ? "\n" : "";
|
|
105435
|
+
return `${retained}${separator}[model_providers.vapi]
|
|
105436
|
+
# >>> vapi code config ${existing === void 0 || clean2.created ? "created" : "existing"} ${separator.length} >>>
|
|
105437
|
+
` + [
|
|
105438
|
+
'name = "vAPI Router"',
|
|
105439
|
+
`base_url = "${escapeToml(baseURL)}"`,
|
|
105440
|
+
`env_key = "${VAPI_ROUTER_KEY_ENV}"`,
|
|
105441
|
+
'wire_api = "responses"',
|
|
105442
|
+
"",
|
|
105443
|
+
"[profiles.vapi]",
|
|
105444
|
+
`model_provider = "${VAPI_CODEX_PROVIDER}"`,
|
|
105445
|
+
`model = "${VAPI_CODEX_DEFAULT_MODEL}"`,
|
|
105446
|
+
""
|
|
105447
|
+
].join("\n") + CONFIG_END;
|
|
105448
|
+
}
|
|
105449
|
+
function removeAliases(contents) {
|
|
105450
|
+
return contents.replace(
|
|
105451
|
+
/(^|\n)# >>> vapi code >>>\r?\n[\s\S]*?^# <<< vapi code <<<(\r?\n|$)/gmu,
|
|
105452
|
+
(_, prefix, suffix) => suffix === "" ? "" : prefix
|
|
105453
|
+
);
|
|
105454
|
+
}
|
|
105455
|
+
function aliasContents(original, tools) {
|
|
105456
|
+
const existing = original ?? "";
|
|
105457
|
+
const block = [RC_START, ...tools.map((tool) => `alias ${tool}="vapi ${tool}"`), RC_END].join(
|
|
105458
|
+
"\n"
|
|
105459
|
+
);
|
|
105460
|
+
const match = /^# >>> vapi code >>>\r?\n[\s\S]*?^# <<< vapi code <<</gmu;
|
|
105461
|
+
if (match.test(existing)) return existing.replace(match, block);
|
|
105462
|
+
const separator = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
105463
|
+
return `${existing}${separator}${block}${original === "" || existing.endsWith("\n") ? "\n" : ""}`;
|
|
105464
|
+
}
|
|
105465
|
+
async function readOptional(path) {
|
|
105466
|
+
try {
|
|
105467
|
+
return await readFile29(path, "utf8");
|
|
105468
|
+
} catch (error61) {
|
|
105469
|
+
if (isMissingFile(error61)) return void 0;
|
|
105470
|
+
throw error61;
|
|
105471
|
+
}
|
|
105472
|
+
}
|
|
105473
|
+
async function writeConfig(path, contents) {
|
|
105474
|
+
await mkdir21(dirname15(path), { recursive: true });
|
|
105475
|
+
await writeFile12(path, contents);
|
|
105476
|
+
}
|
|
105477
|
+
async function codeCommand(argv, json2, io, dependencies) {
|
|
105478
|
+
const command = argv[0];
|
|
105479
|
+
if (command !== "install" && command !== "uninstall")
|
|
105480
|
+
throw new UsageError("Usage: vapi code <install|uninstall>.");
|
|
105481
|
+
const parsed = parseArguments(argv.slice(1), {
|
|
105482
|
+
valueOptions: new Set(command === "install" ? ["--wallet"] : []),
|
|
105483
|
+
booleanOptions: new Set(command === "install" ? ["--yes", "--no-alias"] : []),
|
|
105484
|
+
maximumPositionals: 0
|
|
105485
|
+
});
|
|
105486
|
+
const env = getEnvironment(dependencies);
|
|
105487
|
+
const home = dependencies.code?.homedir ?? homedir3();
|
|
105488
|
+
const config2 = codexConfigPath(env, home);
|
|
105489
|
+
const rcPaths = [join27(home, ".zshrc"), join27(home, ".bashrc")];
|
|
105490
|
+
if (command === "uninstall") {
|
|
105491
|
+
const removed = [];
|
|
105492
|
+
const previous = await readOptional(config2);
|
|
105493
|
+
if (previous !== void 0) {
|
|
105494
|
+
const clean2 = cleanConfig(previous);
|
|
105495
|
+
if (clean2.contents !== previous) {
|
|
105496
|
+
if (clean2.contents === "" && clean2.created) await unlink13(config2);
|
|
105497
|
+
else await writeFile12(config2, clean2.contents);
|
|
105498
|
+
removed.push(config2);
|
|
105499
|
+
}
|
|
105500
|
+
}
|
|
105501
|
+
for (const path of rcPaths) {
|
|
105502
|
+
const previous2 = await readOptional(path);
|
|
105503
|
+
if (previous2 === void 0) continue;
|
|
105504
|
+
const clean2 = removeAliases(previous2);
|
|
105505
|
+
if (clean2 !== previous2) {
|
|
105506
|
+
if (clean2 === "" && previous2.startsWith(RC_START) && !previous2.endsWith("\n"))
|
|
105507
|
+
await unlink13(path);
|
|
105508
|
+
else await writeFile12(path, clean2);
|
|
105509
|
+
removed.push(path);
|
|
105510
|
+
}
|
|
105511
|
+
}
|
|
105512
|
+
io.stdout(
|
|
105513
|
+
json2 ? JSON.stringify({ command: "code uninstall", removed }) : removed.length === 0 ? "Nothing to remove." : `Removed vAPI code settings from: ${removed.join(", ")}`
|
|
105514
|
+
);
|
|
105515
|
+
return 0;
|
|
105516
|
+
}
|
|
105517
|
+
const tools = [];
|
|
105518
|
+
const skipped2 = [];
|
|
105519
|
+
for (const name of ["claude", "codex"]) {
|
|
105520
|
+
const binary = await resolveBinary(name, { ...dependencies.code, env });
|
|
105521
|
+
if (binary === void 0)
|
|
105522
|
+
skipped2.push(
|
|
105523
|
+
`Skipped ${name === "claude" ? "Claude Code" : "Codex"}: \`${name}\` is not on PATH.`
|
|
105524
|
+
);
|
|
105525
|
+
else tools.push(name);
|
|
105526
|
+
}
|
|
105527
|
+
if (tools.length === 0) {
|
|
105528
|
+
const message = "Neither claude nor codex is on PATH; nothing was installed.";
|
|
105529
|
+
if (json2) io.stdout(JSON.stringify({ installed: [], skipped: skipped2, error: message }));
|
|
105530
|
+
else {
|
|
105531
|
+
skipped2.forEach(io.stderr);
|
|
105532
|
+
io.stderr(message);
|
|
105533
|
+
}
|
|
105534
|
+
return 1;
|
|
105535
|
+
}
|
|
105536
|
+
let target = await targetWallet(parsed, dependencies);
|
|
105537
|
+
const credentials = dependencies.router?.routerCredentials ?? routerCredentials;
|
|
105538
|
+
let linked = false;
|
|
105539
|
+
let rotated = false;
|
|
105540
|
+
let result;
|
|
105541
|
+
for (; ; ) {
|
|
105542
|
+
try {
|
|
105543
|
+
result = await credentials(routerDeps2(target, dependencies));
|
|
105544
|
+
break;
|
|
105545
|
+
} catch (error61) {
|
|
105546
|
+
if (error61 instanceof RouterClientError && error61.code === "not_linked" && !linked) {
|
|
105547
|
+
linked = true;
|
|
105548
|
+
const account = parsed.one("--wallet");
|
|
105549
|
+
await (dependencies.code?.login ?? runLoginFlow)(
|
|
105550
|
+
account === void 0 ? [] : ["--account", account],
|
|
105551
|
+
json2,
|
|
105552
|
+
{ ...io, stdout: io.stderr },
|
|
105553
|
+
json2 ? { ...dependencies, interactive: false, stdinIsTTY: false } : dependencies
|
|
105554
|
+
);
|
|
105555
|
+
target = await targetWallet(parsed, dependencies);
|
|
105556
|
+
} else if (error61 instanceof RouterClientError && error61.code === "no_router_key" && !rotated) {
|
|
105557
|
+
rotated = true;
|
|
105558
|
+
await (dependencies.router?.rotateRouterKey ?? rotateRouterKey)(
|
|
105559
|
+
routerDeps2(target, dependencies)
|
|
105560
|
+
);
|
|
105561
|
+
} else throw error61;
|
|
105562
|
+
}
|
|
105563
|
+
}
|
|
105564
|
+
const installed = [];
|
|
105565
|
+
if (tools.includes("claude")) installed.push("Claude Code: ready, launch with `vapi claude`");
|
|
105566
|
+
if (tools.includes("codex")) {
|
|
105567
|
+
await writeConfig(config2, configContents(await readOptional(config2), result.baseURL));
|
|
105568
|
+
installed.push(`Codex: installed ${config2}`);
|
|
105569
|
+
}
|
|
105570
|
+
let alias = "Aliases: skipped.";
|
|
105571
|
+
if (!parsed.has("--no-alias")) {
|
|
105572
|
+
if ((dependencies.code?.platform ?? process.platform) === "win32")
|
|
105573
|
+
alias = "Aliases: skipped on Windows.";
|
|
105574
|
+
else {
|
|
105575
|
+
const yes = parsed.has("--yes") || !json2 && isInteractive(dependencies) && isStdinInteractive(dependencies) && /^y(?:es)?$/iu.test(
|
|
105576
|
+
(await getLinePrompt(dependencies)(
|
|
105577
|
+
"Make `claude` and `codex` use your vAPI Compute first from now on? [y/N] "
|
|
105578
|
+
)).trim()
|
|
105579
|
+
);
|
|
105580
|
+
if (yes) {
|
|
105581
|
+
const shell = basename5(env.SHELL ?? "");
|
|
105582
|
+
const rc = shell === "zsh" ? rcPaths[0] : shell === "bash" ? rcPaths[1] : await readOptional(rcPaths[0]) !== void 0 ? rcPaths[0] : rcPaths[1];
|
|
105583
|
+
await writeConfig(rc, aliasContents(await readOptional(rc), tools));
|
|
105584
|
+
alias = `Aliases: installed in ${rc}. Open a new terminal or run: source ${rc}`;
|
|
105585
|
+
}
|
|
105586
|
+
}
|
|
105587
|
+
}
|
|
105588
|
+
let compute;
|
|
105589
|
+
try {
|
|
105590
|
+
const usage = await (dependencies.router?.routerUsage ?? routerUsage)(
|
|
105591
|
+
routerDeps2(target, dependencies)
|
|
105592
|
+
);
|
|
105593
|
+
const reset = new Date(usage.compute.resetsAt);
|
|
105594
|
+
if (!Number.isFinite(reset.getTime())) throw new Error("invalid reset time");
|
|
105595
|
+
compute = `$${usage.compute.remainingTodayUsd.toFixed(2)} left today (resets ${reset.toISOString().slice(11, 16)} UTC)`;
|
|
105596
|
+
} catch (error61) {
|
|
105597
|
+
compute = `Compute today: unavailable (${error61 instanceof RouterClientError ? error61.code : "request failed"})`;
|
|
105598
|
+
}
|
|
105599
|
+
const start = `Start with \`vapi ${tools.includes("claude") ? "claude" : "codex"}\``;
|
|
105600
|
+
if (json2)
|
|
105601
|
+
io.stdout(
|
|
105602
|
+
JSON.stringify({ command: "code install", installed, skipped: skipped2, alias, compute, start })
|
|
105603
|
+
);
|
|
105604
|
+
else {
|
|
105605
|
+
skipped2.forEach(io.stderr);
|
|
105606
|
+
[...installed, alias, compute, start].forEach(io.stdout);
|
|
105607
|
+
}
|
|
105608
|
+
return 0;
|
|
105609
|
+
}
|
|
105610
|
+
|
|
105611
|
+
// ../cli/src/code-launch.ts
|
|
105612
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
105613
|
+
import { readFile as readFile30 } from "node:fs/promises";
|
|
105614
|
+
import { constants as constants3, homedir as homedir4 } from "node:os";
|
|
105615
|
+
var CLAUDE_MODELS = {
|
|
105616
|
+
sonnet: "venice/claude-sonnet-5-5",
|
|
105617
|
+
opus: "venice/claude-opus-5-5",
|
|
105618
|
+
haiku: "venice/claude-haiku-5-5"
|
|
105619
|
+
};
|
|
105620
|
+
async function claudeCommand(argv, json2, io, dependencies) {
|
|
105621
|
+
return await launch("claude", argv, json2, io, dependencies);
|
|
105622
|
+
}
|
|
105623
|
+
async function codexCommand(argv, json2, io, dependencies) {
|
|
105624
|
+
return await launch("codex", argv, json2, io, dependencies);
|
|
105625
|
+
}
|
|
105626
|
+
function parseLaunch(argv) {
|
|
105627
|
+
const result = { own: false, vapi: false, balance: false, forwarded: [] };
|
|
105628
|
+
for (let index2 = 0; index2 < argv.length; index2 += 1) {
|
|
105629
|
+
const arg = argv[index2];
|
|
105630
|
+
if (arg === "--") {
|
|
105631
|
+
result.forwarded.push(...argv.slice(index2 + 1));
|
|
105632
|
+
break;
|
|
105633
|
+
}
|
|
105634
|
+
if (arg === "--own") result.own = true;
|
|
105635
|
+
else if (arg === "--vapi") result.vapi = true;
|
|
105636
|
+
else if (arg === "--use-balance") result.balance = true;
|
|
105637
|
+
else if (arg === "--model" || arg === "--account") {
|
|
105638
|
+
const value = argv[++index2];
|
|
105639
|
+
if (!value || value.startsWith("--")) throw new UsageError(`Expected ${arg} <value>.`);
|
|
105640
|
+
if (arg === "--model") result.model = value;
|
|
105641
|
+
else result.account = value;
|
|
105642
|
+
} else result.forwarded.push(arg);
|
|
105643
|
+
}
|
|
105644
|
+
if (result.own && result.vapi) throw new UsageError("--vapi and --own cannot be used together.");
|
|
105645
|
+
return result;
|
|
105646
|
+
}
|
|
105647
|
+
var LaunchTimeout = class extends Error {
|
|
105648
|
+
constructor() {
|
|
105649
|
+
super("timed out");
|
|
105650
|
+
}
|
|
105651
|
+
};
|
|
105652
|
+
async function bounded(operation, milliseconds) {
|
|
105653
|
+
const controller = new AbortController();
|
|
105654
|
+
let timer;
|
|
105655
|
+
try {
|
|
105656
|
+
return await Promise.race([
|
|
105657
|
+
new Promise((_resolve, reject) => {
|
|
105658
|
+
timer = setTimeout(() => {
|
|
105659
|
+
const error61 = new LaunchTimeout();
|
|
105660
|
+
controller.abort(error61);
|
|
105661
|
+
reject(error61);
|
|
105662
|
+
}, milliseconds);
|
|
105663
|
+
}),
|
|
105664
|
+
operation(controller.signal)
|
|
105665
|
+
]);
|
|
105666
|
+
} finally {
|
|
105667
|
+
clearTimeout(timer);
|
|
105668
|
+
controller.abort();
|
|
105669
|
+
}
|
|
105670
|
+
}
|
|
105671
|
+
function abortableDeps(deps, signal) {
|
|
105672
|
+
const fetchImpl = deps.fetchImpl ?? createPublicFetch({ allowPrivateNetwork: false });
|
|
105673
|
+
return {
|
|
105674
|
+
...deps,
|
|
105675
|
+
fetchImpl: (input2, init) => fetchImpl(input2, {
|
|
105676
|
+
...init,
|
|
105677
|
+
signal: init?.signal ? AbortSignal.any([signal, init.signal]) : signal
|
|
105678
|
+
})
|
|
105679
|
+
};
|
|
105680
|
+
}
|
|
105681
|
+
function shortReason(error61, env, credentials) {
|
|
105682
|
+
if (error61 instanceof RouterClientError) {
|
|
105683
|
+
if (error61.code === "not_linked") return "not linked, run vapi code install";
|
|
105684
|
+
if (error61.code === "no_router_key") return "no Router key, run vapi code install";
|
|
105685
|
+
}
|
|
105686
|
+
let message = error61 instanceof Error ? error61.message : String(error61);
|
|
105687
|
+
for (const secret of [
|
|
105688
|
+
credentials?.apiKey,
|
|
105689
|
+
env.ANTHROPIC_API_KEY,
|
|
105690
|
+
env.ANTHROPIC_AUTH_TOKEN,
|
|
105691
|
+
env[VAPI_ROUTER_KEY_ENV]
|
|
105692
|
+
]) {
|
|
105693
|
+
if (secret) message = message.replaceAll(secret, "[redacted]");
|
|
105694
|
+
}
|
|
105695
|
+
return message.replace(/\s+/gu, " ").trim().slice(0, 160) || "request failed";
|
|
105696
|
+
}
|
|
105697
|
+
async function chooseRoute(options, env, dependencies) {
|
|
105698
|
+
if (options.own) return { kind: "own" };
|
|
105699
|
+
const timeout = dependencies.code?.usageTimeoutMs ?? 4e3;
|
|
105700
|
+
let credentials;
|
|
105701
|
+
let deps;
|
|
105702
|
+
let balanceKeyRequired = false;
|
|
105703
|
+
try {
|
|
105704
|
+
credentials = await bounded(async (signal) => {
|
|
105705
|
+
const target = await targetWallet(
|
|
105706
|
+
{ one: (name) => name === "--wallet" ? options.account : void 0 },
|
|
105707
|
+
dependencies,
|
|
105708
|
+
env.VAPI_HOME
|
|
105709
|
+
);
|
|
105710
|
+
signal.throwIfAborted();
|
|
105711
|
+
deps = routerDeps2(target, dependencies);
|
|
105712
|
+
return await (dependencies.router?.routerCredentials ?? routerCredentials)(
|
|
105713
|
+
abortableDeps(deps, signal)
|
|
105714
|
+
);
|
|
105715
|
+
}, timeout);
|
|
105716
|
+
let usage;
|
|
105717
|
+
try {
|
|
105718
|
+
usage = await bounded(
|
|
105719
|
+
(signal) => (dependencies.router?.routerUsage ?? routerUsage)(abortableDeps(deps, signal)),
|
|
105720
|
+
timeout
|
|
105721
|
+
);
|
|
105722
|
+
if (!Number.isFinite(new Date(usage.compute.resetsAt).getTime()))
|
|
105723
|
+
throw new Error("invalid Compute reset time");
|
|
105724
|
+
} catch (error61) {
|
|
105725
|
+
if (options.vapi) return { kind: "vapi", credentials };
|
|
105726
|
+
throw error61;
|
|
105727
|
+
}
|
|
105728
|
+
if (options.vapi || remaining(usage, options.balance) >= 0.5) {
|
|
105729
|
+
if (options.balance && usage.compute.remainingTodayUsd < 0.5 && (usage.balance?.remainingUsd ?? 0) > 0) {
|
|
105730
|
+
balanceKeyRequired = true;
|
|
105731
|
+
credentials = await bounded(
|
|
105732
|
+
(signal) => (dependencies.router?.routerCredentials ?? routerCredentials)(
|
|
105733
|
+
abortableDeps(deps, signal),
|
|
105734
|
+
{ funding: "balance" }
|
|
105735
|
+
),
|
|
105736
|
+
timeout
|
|
105737
|
+
);
|
|
105738
|
+
}
|
|
105739
|
+
return { kind: "vapi", credentials, usage };
|
|
105740
|
+
}
|
|
105741
|
+
return { kind: "own", exhausted: true };
|
|
105742
|
+
} catch (error61) {
|
|
105743
|
+
const reason = balanceKeyRequired && error61 instanceof RouterClientError && error61.code === "no_router_key" ? "no Router balance key is stored" : shortReason(error61, env, credentials);
|
|
105744
|
+
if (options.vapi) return { kind: "unavailable", reason };
|
|
105745
|
+
return { kind: "own", reason };
|
|
105746
|
+
}
|
|
105747
|
+
}
|
|
105748
|
+
function remaining(usage, useBalance) {
|
|
105749
|
+
return usage.compute.remainingTodayUsd + (useBalance ? usage.balance?.remainingUsd ?? 0 : 0);
|
|
105750
|
+
}
|
|
105751
|
+
async function launch(tool, argv, json2, io, dependencies) {
|
|
105752
|
+
if (json2) throw new UsageError(`vapi ${tool} is interactive and does not support --json.`);
|
|
105753
|
+
const options = parseLaunch(argv);
|
|
105754
|
+
const env = getEnvironment(dependencies);
|
|
105755
|
+
let binary;
|
|
105756
|
+
try {
|
|
105757
|
+
binary = await resolveBinary(tool, { ...dependencies.code, env });
|
|
105758
|
+
} catch (error61) {
|
|
105759
|
+
io.stderr(shortReason(error61, env));
|
|
105760
|
+
return 127;
|
|
105761
|
+
}
|
|
105762
|
+
if (binary === void 0) {
|
|
105763
|
+
io.stderr(
|
|
105764
|
+
`\`${tool}\` is not on PATH. Install ${tool === "claude" ? "Claude Code" : "Codex"} first.`
|
|
105765
|
+
);
|
|
105766
|
+
return 127;
|
|
105767
|
+
}
|
|
105768
|
+
const route = await chooseRoute(options, env, dependencies);
|
|
105769
|
+
if (route.kind === "unavailable") {
|
|
105770
|
+
io.stderr(route.reason);
|
|
105771
|
+
return 1;
|
|
105772
|
+
}
|
|
105773
|
+
let args = options.forwarded;
|
|
105774
|
+
let childEnv = env;
|
|
105775
|
+
const own2 = tool === "claude" ? "your own Claude subscription" : "your own Codex/ChatGPT login";
|
|
105776
|
+
if (route.kind === "own") {
|
|
105777
|
+
if (route.exhausted) io.stderr(`\u25CF Compute used up today \u2192 ${own2}`);
|
|
105778
|
+
else if (route.reason !== void 0) io.stderr(`\u25CF vAPI unreachable (${route.reason}) \u2192 ${own2}`);
|
|
105779
|
+
if (options.model !== void 0)
|
|
105780
|
+
args = [tool === "claude" ? "--model" : "-m", options.model, ...args];
|
|
105781
|
+
} else {
|
|
105782
|
+
const { credentials, usage } = route;
|
|
105783
|
+
const model = tool === "claude" ? claudeModel(options.model) : options.model ?? VAPI_CODEX_DEFAULT_MODEL;
|
|
105784
|
+
let status = "\u25CF vAPI Compute";
|
|
105785
|
+
if (usage !== void 0)
|
|
105786
|
+
status += ` \u2014 $${remaining(usage, options.balance).toFixed(2)} left today (resets ${new Date(usage.compute.resetsAt).toISOString().slice(11, 16)} UTC)`;
|
|
105787
|
+
io.stderr(`${status} \xB7 model ${model.slice(model.lastIndexOf("/") + 1)}`);
|
|
105788
|
+
io.stderr(
|
|
105789
|
+
tool === "claude" ? " Compute runs out mid-session? /exit, then: vapi claude --continue" : " Compute runs out mid-session? /quit, then: vapi codex resume --last"
|
|
105790
|
+
);
|
|
105791
|
+
if (tool === "claude") {
|
|
105792
|
+
childEnv = {
|
|
105793
|
+
...env,
|
|
105794
|
+
ANTHROPIC_BASE_URL: credentials.baseURL.replace(/\/v1\/?$/u, ""),
|
|
105795
|
+
ANTHROPIC_AUTH_TOKEN: credentials.apiKey
|
|
105796
|
+
};
|
|
105797
|
+
delete childEnv.ANTHROPIC_API_KEY;
|
|
105798
|
+
if (args.some((arg) => arg === "--settings" || arg.startsWith("--settings=")))
|
|
105799
|
+
io.stderr("\u25CF Your --settings is passed as is; vAPI model settings were not added.");
|
|
105800
|
+
else
|
|
105801
|
+
args = [
|
|
105802
|
+
"--settings",
|
|
105803
|
+
JSON.stringify({
|
|
105804
|
+
env: {
|
|
105805
|
+
ANTHROPIC_MODEL: model,
|
|
105806
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: CLAUDE_MODELS.sonnet,
|
|
105807
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: CLAUDE_MODELS.opus,
|
|
105808
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: CLAUDE_MODELS.haiku,
|
|
105809
|
+
CLAUDE_CODE_MAX_RETRIES: "2"
|
|
105810
|
+
}
|
|
105811
|
+
}),
|
|
105812
|
+
...args
|
|
105813
|
+
];
|
|
105814
|
+
} else {
|
|
105815
|
+
childEnv = { ...env, [VAPI_ROUTER_KEY_ENV]: credentials.apiKey };
|
|
105816
|
+
args = [...await codexArgs(env, credentials.baseURL, options.model, dependencies), ...args];
|
|
105817
|
+
}
|
|
105818
|
+
}
|
|
105819
|
+
return await runChild(binary, args, childEnv, io, dependencies);
|
|
105820
|
+
}
|
|
105821
|
+
function claudeModel(model) {
|
|
105822
|
+
return model === void 0 ? CLAUDE_MODELS.sonnet : Object.hasOwn(CLAUDE_MODELS, model) ? CLAUDE_MODELS[model] : model;
|
|
105823
|
+
}
|
|
105824
|
+
async function codexArgs(env, baseURL, model, dependencies) {
|
|
105825
|
+
let contents = "";
|
|
105826
|
+
try {
|
|
105827
|
+
contents = await readFile30(
|
|
105828
|
+
codexConfigPath(env, dependencies.code?.homedir ?? homedir4()),
|
|
105829
|
+
"utf8"
|
|
105830
|
+
);
|
|
105831
|
+
} catch (error61) {
|
|
105832
|
+
if (!isMissingFile(error61)) throw error61;
|
|
105833
|
+
}
|
|
105834
|
+
const providerArgs = [
|
|
105835
|
+
"-c",
|
|
105836
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.name="vAPI Router"`,
|
|
105837
|
+
"-c",
|
|
105838
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.base_url=${JSON.stringify(baseURL)}`,
|
|
105839
|
+
"-c",
|
|
105840
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.env_key="${VAPI_ROUTER_KEY_ENV}"`,
|
|
105841
|
+
"-c",
|
|
105842
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.wire_api="responses"`,
|
|
105843
|
+
"-c",
|
|
105844
|
+
`model_provider="${VAPI_CODEX_PROVIDER}"`
|
|
105845
|
+
];
|
|
105846
|
+
if (hasVapiCodexProfile(contents))
|
|
105847
|
+
return [
|
|
105848
|
+
"--profile",
|
|
105849
|
+
VAPI_CODEX_PROFILE,
|
|
105850
|
+
...providerArgs,
|
|
105851
|
+
...model === void 0 ? [] : ["-m", model]
|
|
105852
|
+
];
|
|
105853
|
+
return [...providerArgs, "-m", model ?? VAPI_CODEX_DEFAULT_MODEL];
|
|
105854
|
+
}
|
|
105855
|
+
async function runChild(binary, args, env, io, dependencies) {
|
|
105856
|
+
const signals = dependencies.code?.processSignals ?? process;
|
|
105857
|
+
let child;
|
|
105858
|
+
const ignore = () => {
|
|
105859
|
+
};
|
|
105860
|
+
const forward = (signal) => () => {
|
|
105861
|
+
try {
|
|
105862
|
+
child?.kill(signal);
|
|
105863
|
+
} catch (error61) {
|
|
105864
|
+
io.stderr(shortReason(error61, env));
|
|
105865
|
+
}
|
|
105866
|
+
};
|
|
105867
|
+
const listeners = [
|
|
105868
|
+
["SIGINT", ignore],
|
|
105869
|
+
["SIGQUIT", ignore],
|
|
105870
|
+
["SIGTERM", forward("SIGTERM")],
|
|
105871
|
+
["SIGHUP", forward("SIGHUP")]
|
|
105872
|
+
];
|
|
105873
|
+
try {
|
|
105874
|
+
for (const [signal, listener] of listeners) signals.on(signal, listener);
|
|
105875
|
+
return await new Promise((resolve4) => {
|
|
105876
|
+
let settled = false;
|
|
105877
|
+
const finish = (code) => {
|
|
105878
|
+
if (!settled) {
|
|
105879
|
+
settled = true;
|
|
105880
|
+
resolve4(code);
|
|
105881
|
+
}
|
|
105882
|
+
};
|
|
105883
|
+
try {
|
|
105884
|
+
child = (dependencies.code?.spawn ?? spawn4)(binary, args, { env, stdio: "inherit" });
|
|
105885
|
+
child.once("error", (error61) => {
|
|
105886
|
+
if (!settled) io.stderr(shortReason(error61, env));
|
|
105887
|
+
finish(127);
|
|
105888
|
+
});
|
|
105889
|
+
child.once(
|
|
105890
|
+
"exit",
|
|
105891
|
+
(code, signal) => finish(code ?? (signal === null ? 1 : 128 + (constants3.signals[signal] ?? 0)))
|
|
105892
|
+
);
|
|
105893
|
+
} catch (error61) {
|
|
105894
|
+
io.stderr(shortReason(error61, env));
|
|
105895
|
+
finish(127);
|
|
105896
|
+
}
|
|
105897
|
+
});
|
|
105898
|
+
} finally {
|
|
105899
|
+
for (const [signal, listener] of listeners) signals.removeListener(signal, listener);
|
|
105900
|
+
}
|
|
105901
|
+
}
|
|
105902
|
+
|
|
105158
105903
|
// ../cli/src/send.ts
|
|
105159
105904
|
var SEND_USAGE = "Usage: vapi send <amount> --from <account> --to <account|owner|0x\u2026> [--network base|arc] [--resume <nonce>] [--json]";
|
|
105160
105905
|
async function sendCommand(argv, json2, io, dependencies) {
|
|
@@ -105253,8 +105998,8 @@ async function sendConfig(dependencies) {
|
|
|
105253
105998
|
}
|
|
105254
105999
|
|
|
105255
106000
|
// ../cli/src/setup.ts
|
|
105256
|
-
import { rm as
|
|
105257
|
-
import { join as
|
|
106001
|
+
import { rm as rm6 } from "node:fs/promises";
|
|
106002
|
+
import { join as join28 } from "node:path";
|
|
105258
106003
|
var SETUP_ARGUMENT_ERROR = `vapi setup accepts only --no-cloud-backup and --accounts <n> (1-${MAX_RESTORE_ACCOUNTS}); a recovery phrase is typed at the prompt, never passed on the command line.`;
|
|
105259
106004
|
var VAULT_CHOICE = "Create a new vault, or restore one from a recovery phrase? [new/restore] ";
|
|
105260
106005
|
async function setupCommand(argv, json2, io, dependencies) {
|
|
@@ -105284,7 +106029,7 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
105284
106029
|
let changedAccount = false;
|
|
105285
106030
|
let changedLink = false;
|
|
105286
106031
|
let scannedAddresses;
|
|
105287
|
-
if (!await fileExists2(
|
|
106032
|
+
if (!await fileExists2(join28(paths.directory, "vault.json"))) {
|
|
105288
106033
|
const choice = await vaultChoice(dependencies);
|
|
105289
106034
|
if (choice === "restore") {
|
|
105290
106035
|
if (!isInteractive(dependencies)) {
|
|
@@ -105372,7 +106117,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
105372
106117
|
let scannedAddresses = 0;
|
|
105373
106118
|
try {
|
|
105374
106119
|
const restored = await restoreVault({
|
|
105375
|
-
path:
|
|
106120
|
+
path: join28(paths.directory, "vault.json"),
|
|
105376
106121
|
key: key2,
|
|
105377
106122
|
phrase: validatedPhrase,
|
|
105378
106123
|
probe: async (address4) => await readBalance3(address4) > 0n,
|
|
@@ -105383,7 +106128,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
105383
106128
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
105384
106129
|
});
|
|
105385
106130
|
names = restored.accounts().map((account) => account.name);
|
|
105386
|
-
await
|
|
106131
|
+
await rm6(join28(paths.directory, "wallets.json"), { force: true });
|
|
105387
106132
|
} finally {
|
|
105388
106133
|
key2.fill(0);
|
|
105389
106134
|
}
|
|
@@ -105501,7 +106246,7 @@ async function withRouterError2(operation) {
|
|
|
105501
106246
|
|
|
105502
106247
|
// ../cli/src/task.ts
|
|
105503
106248
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
105504
|
-
import { readFile as
|
|
106249
|
+
import { readFile as readFile31 } from "node:fs/promises";
|
|
105505
106250
|
var TASK_HELP = `Usage:
|
|
105506
106251
|
vapi task search [--open] [--min <usd>] [--tab trending|new|closing|paid] [--limit <n>] [--json]
|
|
105507
106252
|
vapi task show <id> [--account <name>] [--json]
|
|
@@ -105837,7 +106582,7 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
105837
106582
|
if (maxAwards !== void 0 && maxAwards > TASK_LIMITS.maxAwardsMax)
|
|
105838
106583
|
throw new UsageError("--max-awards must be between 1 and 50.");
|
|
105839
106584
|
if (parsed.one("--webhook") !== void 0) httpsUrl2(parsed.one("--webhook"), "--webhook");
|
|
105840
|
-
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await
|
|
106585
|
+
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await readFile31(briefPath, "utf8");
|
|
105841
106586
|
const input2 = {
|
|
105842
106587
|
title: title.trim(),
|
|
105843
106588
|
description: brief.trim(),
|
|
@@ -106423,13 +107168,13 @@ async function watchTask(id2, parsed, json2, io, dependencies, now) {
|
|
|
106423
107168
|
}
|
|
106424
107169
|
}
|
|
106425
107170
|
cursor2 = Math.max(cursor2, page.nextAfter, ...events.map((event) => event.sequence));
|
|
106426
|
-
const
|
|
106427
|
-
if (
|
|
107171
|
+
const remaining2 = deadline - clock().getTime();
|
|
107172
|
+
if (remaining2 <= 0)
|
|
106428
107173
|
throw new TaskCommandError(
|
|
106429
107174
|
"timeout",
|
|
106430
107175
|
`Task watch timed out after ${parsed.one("--timeout") ?? "7d"}.`
|
|
106431
107176
|
);
|
|
106432
|
-
await context.sleep(Math.min(interval,
|
|
107177
|
+
await context.sleep(Math.min(interval, remaining2));
|
|
106433
107178
|
}
|
|
106434
107179
|
}
|
|
106435
107180
|
function expandDeliveryFiles(argv) {
|
|
@@ -107515,7 +108260,7 @@ async function referencedSleep(milliseconds, signal) {
|
|
|
107515
108260
|
}
|
|
107516
108261
|
|
|
107517
108262
|
// ../cli/src/vault.ts
|
|
107518
|
-
import { join as
|
|
108263
|
+
import { join as join29 } from "node:path";
|
|
107519
108264
|
var VAULT_USAGE = "Usage: vapi vault protect|unprotect|lock|unlock|status [--json]";
|
|
107520
108265
|
var RESTORE_USAGE = "Usage: vapi restore [--accounts <n> | --from-owner [--owner <0x\u2026>]] [--json]";
|
|
107521
108266
|
var LEGACY_PASSWORD_NOTICE = "VAPI_KEYSTORE_PASSWORD is deprecated for vault passwords; use VAPI_VAULT_PASSWORD instead.";
|
|
@@ -107559,7 +108304,7 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
107559
108304
|
}
|
|
107560
108305
|
const accountCount = parseRestoreAccountCount(parsed.one("--accounts"));
|
|
107561
108306
|
const paths = getVapiPaths();
|
|
107562
|
-
const path =
|
|
108307
|
+
const path = join29(paths.directory, "vault.json");
|
|
107563
108308
|
if (await fileExists2(path)) {
|
|
107564
108309
|
throw new Error(
|
|
107565
108310
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
@@ -107716,7 +108461,7 @@ function requireNoArguments(argv) {
|
|
|
107716
108461
|
parseArguments(argv, { valueOptions: /* @__PURE__ */ new Set(), maximumPositionals: 0 });
|
|
107717
108462
|
}
|
|
107718
108463
|
function vaultPath() {
|
|
107719
|
-
return
|
|
108464
|
+
return join29(getVapiPaths().directory, "vault.json");
|
|
107720
108465
|
}
|
|
107721
108466
|
function quietIo(io) {
|
|
107722
108467
|
return { stdout: () => void 0, stderr: io.stderr };
|
|
@@ -107784,6 +108529,10 @@ Usage:
|
|
|
107784
108529
|
vapi login [--account <name>] [--label <name>] [--publish] [--no-browser] [--json]
|
|
107785
108530
|
vapi logout [--account <name>] [--json]
|
|
107786
108531
|
vapi whoami [--account <name>] [--json]
|
|
108532
|
+
vapi claude [--vapi|--own] [--model <m>] [--use-balance] [--account <name>] [<claude args>...]
|
|
108533
|
+
vapi codex [--vapi|--own] [--model <id>] [--use-balance] [--account <name>] [<codex args>...]
|
|
108534
|
+
vapi code install [--yes] [--no-alias] [--account <name>] [--json]
|
|
108535
|
+
vapi code uninstall [--json]
|
|
107787
108536
|
vapi router models [--account <name>] [--json]
|
|
107788
108537
|
vapi router usage [--account <name>] [--json]
|
|
107789
108538
|
vapi router chat --model <id> [--system <text>] [--max-tokens <n>] "<prompt>" [--account <name>] [--json]
|
|
@@ -108003,6 +108752,8 @@ async function confirmWalletName(name, prompt, refusal, dependencies) {
|
|
|
108003
108752
|
if (typed.trim() !== name) throw new KeystoreError(refusal);
|
|
108004
108753
|
}
|
|
108005
108754
|
async function runCli(argv = process.argv.slice(2), io = processIo, dependencies = {}) {
|
|
108755
|
+
const firstArgument = argv.find((argument) => argument !== "--json");
|
|
108756
|
+
const codeLaunch = firstArgument === "claude" || firstArgument === "codex";
|
|
108006
108757
|
let json2 = argv.includes("--json");
|
|
108007
108758
|
const taskInvocation = argv.find((argument) => argument !== "--json") === "task";
|
|
108008
108759
|
const resultFile = runResultFile(argv);
|
|
@@ -108011,15 +108762,15 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
108011
108762
|
stderr: (message) => io.stderr(redactDetachedRunText(message, getEnvironment(dependencies)))
|
|
108012
108763
|
};
|
|
108013
108764
|
try {
|
|
108014
|
-
const parsedInvocation = removeJsonFlag(argv);
|
|
108765
|
+
const parsedInvocation = removeJsonFlag(argv, codeLaunch);
|
|
108015
108766
|
json2 = parsedInvocation.json;
|
|
108016
|
-
const hasWalletOption = parsedInvocation.args.includes(WALLET_OPTION5);
|
|
108767
|
+
const hasWalletOption = !codeLaunch && parsedInvocation.args.includes(WALLET_OPTION5);
|
|
108017
108768
|
const hasAccountOption = parsedInvocation.args.includes(ACCOUNT_OPTION2);
|
|
108018
108769
|
if (hasWalletOption && hasAccountOption) {
|
|
108019
108770
|
throw new UsageError("--wallet and --account cannot be used together.");
|
|
108020
108771
|
}
|
|
108021
108772
|
if (hasWalletOption) io.stderr(WALLET_OPTION_DEPRECATION);
|
|
108022
|
-
const args = parsedInvocation.args.map(
|
|
108773
|
+
const args = codeLaunch ? parsedInvocation.args : parsedInvocation.args.map(
|
|
108023
108774
|
(argument) => argument === WALLET_OPTION5 ? ACCOUNT_OPTION2 : argument
|
|
108024
108775
|
);
|
|
108025
108776
|
const command = args[0];
|
|
@@ -108115,6 +108866,15 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
108115
108866
|
await whoamiCommand(args.slice(1), json2, io, dependencies);
|
|
108116
108867
|
exitCode = 0;
|
|
108117
108868
|
break;
|
|
108869
|
+
case "claude":
|
|
108870
|
+
exitCode = await claudeCommand(args.slice(1), json2, io, dependencies);
|
|
108871
|
+
break;
|
|
108872
|
+
case "codex":
|
|
108873
|
+
exitCode = await codexCommand(args.slice(1), json2, io, dependencies);
|
|
108874
|
+
break;
|
|
108875
|
+
case "code":
|
|
108876
|
+
exitCode = await codeCommand(args.slice(1), json2, io, dependencies);
|
|
108877
|
+
break;
|
|
108118
108878
|
case "router":
|
|
108119
108879
|
await routerCommand(args.slice(1), json2, io, dependencies);
|
|
108120
108880
|
exitCode = 0;
|
|
@@ -108152,7 +108912,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
108152
108912
|
break;
|
|
108153
108913
|
case "unlock":
|
|
108154
108914
|
io.stderr("vapi unlock is now vapi vault unlock; the old name works for one release.");
|
|
108155
|
-
if (await fileExists2(
|
|
108915
|
+
if (await fileExists2(join30(getVapiPaths().directory, "vault.json"))) {
|
|
108156
108916
|
parseArguments(args.slice(1), {
|
|
108157
108917
|
valueOptions: /* @__PURE__ */ new Set([WALLET_OPTION5]),
|
|
108158
108918
|
maximumPositionals: 0
|
|
@@ -108358,7 +109118,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
108358
109118
|
address: account.address,
|
|
108359
109119
|
accounts,
|
|
108360
109120
|
config: paths.config,
|
|
108361
|
-
vault:
|
|
109121
|
+
vault: join30(paths.directory, "vault.json"),
|
|
108362
109122
|
...configRewrites.length > 0 ? { configRewrites } : {},
|
|
108363
109123
|
custody: "self",
|
|
108364
109124
|
warning: CUSTODY_NOTICE,
|
|
@@ -108497,7 +109257,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
108497
109257
|
const result = {
|
|
108498
109258
|
address: account.address,
|
|
108499
109259
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
108500
|
-
vault:
|
|
109260
|
+
vault: join30(paths.directory, "vault.json"),
|
|
108501
109261
|
...label === void 0 ? {} : { label },
|
|
108502
109262
|
spendCaps: created.entry.spendCaps,
|
|
108503
109263
|
isDefault,
|
|
@@ -108537,7 +109297,7 @@ function formatCaps2(caps) {
|
|
|
108537
109297
|
function walletListResult(store, wallets, unlocked) {
|
|
108538
109298
|
return {
|
|
108539
109299
|
default: store.defaultName ?? null,
|
|
108540
|
-
vault:
|
|
109300
|
+
vault: join30(store.home, "vault.json"),
|
|
108541
109301
|
wallets: wallets.map((wallet) => ({
|
|
108542
109302
|
name: wallet.name,
|
|
108543
109303
|
...wallet.address === void 0 ? {} : { address: wallet.address },
|
|
@@ -109553,7 +110313,7 @@ function sameOrigin2(left, right) {
|
|
|
109553
110313
|
function noApiKeyMessage(baseUrl) {
|
|
109554
110314
|
return [
|
|
109555
110315
|
"No vAPI API key on this machine.",
|
|
109556
|
-
`Create one in the console at ${
|
|
110316
|
+
`Create one in the console at ${apiKeyConsoleUrl(baseUrl).href}, then store it with vapi auth set-key.`,
|
|
109557
110317
|
`In CI, set ${API_KEY_ENV} instead.`
|
|
109558
110318
|
].join("\n");
|
|
109559
110319
|
}
|
|
@@ -109810,7 +110570,7 @@ function formatClaimed(origin, claimed) {
|
|
|
109810
110570
|
}
|
|
109811
110571
|
var EXPORT_KEY_WARNING = "Anyone with this key can spend the wallet. Never paste it into a website or chat.";
|
|
109812
110572
|
async function deviceVaultKey2(store, dependencies) {
|
|
109813
|
-
const path =
|
|
110573
|
+
const path = join30(store.home, "vault.json");
|
|
109814
110574
|
const metadata = await readVaultFileUnlocked(path);
|
|
109815
110575
|
const secrets = getSecretStore(dependencies);
|
|
109816
110576
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
@@ -109903,7 +110663,7 @@ async function backupCommand(argv, json2, io, dependencies) {
|
|
|
109903
110663
|
const target = await targetWallet(parsed, dependencies);
|
|
109904
110664
|
const vaultAccount = await target.store.hasVaultAccount(target.name);
|
|
109905
110665
|
if (vaultAccount) {
|
|
109906
|
-
const vault = await readVaultFileUnlocked(
|
|
110666
|
+
const vault = await readVaultFileUnlocked(join30(target.store.home, "vault.json"));
|
|
109907
110667
|
if (vault.accounts.some((account) => account.name === target.name && account.kind === "imported")) {
|
|
109908
110668
|
throw new KeystoreError(
|
|
109909
110669
|
`Account ${target.name} was imported and is not recoverable from the vault phrase. Back it up with vapi export-key --account ${target.name}.`
|
|
@@ -109980,7 +110740,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109980
110740
|
const existed = store.has(name);
|
|
109981
110741
|
if (existed && !parsed.has("--replace")) {
|
|
109982
110742
|
const address4 = await store.readAddress(name);
|
|
109983
|
-
const location = await store.hasVaultAccount(name) ?
|
|
110743
|
+
const location = await store.hasVaultAccount(name) ? join30(store.home, "vault.json") : store.pathFor(name);
|
|
109984
110744
|
throw new Error(
|
|
109985
110745
|
[
|
|
109986
110746
|
`Wallet ${name} already exists at ${location}.`,
|
|
@@ -110016,7 +110776,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
110016
110776
|
const result = {
|
|
110017
110777
|
address: account.address,
|
|
110018
110778
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
110019
|
-
vault:
|
|
110779
|
+
vault: join30(paths.directory, "vault.json"),
|
|
110020
110780
|
...previousKeystore ? { previousKeystore } : {},
|
|
110021
110781
|
message: "Wallet imported. Its encrypted key stays on this machine."
|
|
110022
110782
|
};
|
|
@@ -110349,7 +111109,7 @@ function formatFund(address4, url2, opened) {
|
|
|
110349
111109
|
function openInBrowser(url2) {
|
|
110350
111110
|
const opener = process.platform === "darwin" ? { command: "open", args: [url2] } : process.platform === "win32" ? { command: "cmd", args: ["/c", "start", "", url2] } : { command: "xdg-open", args: [url2] };
|
|
110351
111111
|
try {
|
|
110352
|
-
const child =
|
|
111112
|
+
const child = spawn5(opener.command, opener.args, { stdio: "ignore", detached: true });
|
|
110353
111113
|
child.on("error", () => void 0);
|
|
110354
111114
|
child.unref();
|
|
110355
111115
|
return true;
|
|
@@ -110541,11 +111301,13 @@ function parseArguments(argv, spec) {
|
|
|
110541
111301
|
has: (name) => flags.has(name)
|
|
110542
111302
|
};
|
|
110543
111303
|
}
|
|
110544
|
-
function removeJsonFlag(argv) {
|
|
111304
|
+
function removeJsonFlag(argv, preserveForwarded = false) {
|
|
110545
111305
|
let json2 = false;
|
|
110546
111306
|
const args = [];
|
|
111307
|
+
let forwarding = false;
|
|
110547
111308
|
for (const argument of argv) {
|
|
110548
|
-
if (argument
|
|
111309
|
+
if (preserveForwarded && argument === "--") forwarding = true;
|
|
111310
|
+
if (argument !== "--json" || forwarding) {
|
|
110549
111311
|
args.push(argument);
|
|
110550
111312
|
continue;
|
|
110551
111313
|
}
|
|
@@ -110646,7 +111408,7 @@ function parseInitNetworks(value) {
|
|
|
110646
111408
|
|
|
110647
111409
|
// ../cli/src/update-check.ts
|
|
110648
111410
|
import { lookup } from "node:dns/promises";
|
|
110649
|
-
import { mkdir as
|
|
111411
|
+
import { mkdir as mkdir22, readFile as readFile32, writeFile as writeFile13 } from "node:fs/promises";
|
|
110650
111412
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
110651
111413
|
var CHECK_TIMEOUT_MS = 1500;
|
|
110652
111414
|
var LATEST_URL = "https://registry.npmjs.org/vapi-network/latest";
|
|
@@ -110663,7 +111425,7 @@ async function runCliWithUpdateCheck(argv = process.argv.slice(2), io = {
|
|
|
110663
111425
|
async function checkForUpdate(options = {}) {
|
|
110664
111426
|
const env = options.env ?? process.env;
|
|
110665
111427
|
const argv = options.argv ?? process.argv.slice(2);
|
|
110666
|
-
if (!(options.stderrIsTTY ?? process.stderr.isTTY) || argv.includes("--json") || argv[0] === "mcp" && argv[1] !== "install" || env.VAPI_NO_UPDATE_CHECK === "1" || env.CI !== void 0) {
|
|
111428
|
+
if (!(options.stderrIsTTY ?? process.stderr.isTTY) || argv.includes("--json") || argv[0] === "claude" || argv[0] === "codex" || argv[0] === "mcp" && argv[1] !== "install" || env.VAPI_NO_UPDATE_CHECK === "1" || env.CI !== void 0) {
|
|
110667
111429
|
return void 0;
|
|
110668
111430
|
}
|
|
110669
111431
|
const controller = new AbortController();
|
|
@@ -110690,7 +111452,7 @@ async function latestNotice(options, env, signal) {
|
|
|
110690
111452
|
const now = (options.nowMs ?? Date.now)();
|
|
110691
111453
|
let cached2;
|
|
110692
111454
|
try {
|
|
110693
|
-
const value = JSON.parse(await
|
|
111455
|
+
const value = JSON.parse(await readFile32(paths.updateCheck, "utf8"));
|
|
110694
111456
|
if (isRecord13(value) && typeof value.checkedAt === "number" && Number.isFinite(value.checkedAt) && typeof value.latest === "string" && parseVersion(value.latest)) {
|
|
110695
111457
|
cached2 = { checkedAt: value.checkedAt, latest: value.latest };
|
|
110696
111458
|
}
|
|
@@ -110699,9 +111461,9 @@ async function latestNotice(options, env, signal) {
|
|
|
110699
111461
|
signal.throwIfAborted();
|
|
110700
111462
|
let latest = cached2?.latest ?? CLI_VERSION;
|
|
110701
111463
|
if (cached2 === void 0 || now - cached2.checkedAt >= CHECK_INTERVAL_MS || now < cached2.checkedAt) {
|
|
110702
|
-
await
|
|
111464
|
+
await mkdir22(paths.directory, { recursive: true });
|
|
110703
111465
|
signal.throwIfAborted();
|
|
110704
|
-
await
|
|
111466
|
+
await writeFile13(paths.updateCheck, JSON.stringify({ checkedAt: now, latest }), { mode: 384 });
|
|
110705
111467
|
signal.throwIfAborted();
|
|
110706
111468
|
const fetchImpl = options.fetchImpl ?? createPublicFetch({
|
|
110707
111469
|
allowPrivateNetwork: false,
|
|
@@ -110728,7 +111490,7 @@ async function latestNotice(options, env, signal) {
|
|
|
110728
111490
|
return void 0;
|
|
110729
111491
|
}
|
|
110730
111492
|
latest = body.version;
|
|
110731
|
-
await
|
|
111493
|
+
await writeFile13(paths.updateCheck, JSON.stringify({ checkedAt: now, latest }), { mode: 384 });
|
|
110732
111494
|
}
|
|
110733
111495
|
signal.throwIfAborted();
|
|
110734
111496
|
return isNewerVersion(latest, CLI_VERSION) ? `vapi-network ${latest} is available (you have ${CLI_VERSION}). Update: npm i -g vapi-network@latest` : void 0;
|
|
@@ -110771,15 +111533,15 @@ function isNewerVersion(latest, current) {
|
|
|
110771
111533
|
}
|
|
110772
111534
|
|
|
110773
111535
|
// src/client.ts
|
|
110774
|
-
import { homedir as
|
|
110775
|
-
import { join as
|
|
111536
|
+
import { homedir as homedir5 } from "node:os";
|
|
111537
|
+
import { join as join31 } from "node:path";
|
|
110776
111538
|
var ACCOUNT_NOT_LINKED = "Not linked. Run vapi login on this machine, or set VAPI_HOME to a linked home.";
|
|
110777
111539
|
var DISCOVERY_PATH2 = "/api/call/discovery";
|
|
110778
111540
|
var warnedWalletOption = false;
|
|
110779
111541
|
async function createVapiClient(options = {}) {
|
|
110780
111542
|
if (options.wallet !== void 0) warnWalletOption();
|
|
110781
111543
|
const env = options.env ?? process.env;
|
|
110782
|
-
const home = options.home ?? (env.VAPI_HOME?.trim() ||
|
|
111544
|
+
const home = options.home ?? (env.VAPI_HOME?.trim() || join31(homedir5(), ".vapi"));
|
|
110783
111545
|
const paths = getVapiPaths(home);
|
|
110784
111546
|
const requestedName = typeof options.account === "string" ? options.account : options.wallet;
|
|
110785
111547
|
const injected = typeof options.account === "object" ? options.account : void 0;
|