vapi-network 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +259 -126
- package/SKILL.md +25 -20
- package/dist/cli.js +748 -126
- package/dist/cli.js.map +3 -3
- package/dist/index.js +928 -185
- 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;
|
|
@@ -71098,7 +71103,7 @@ function requireSuccess(result, what) {
|
|
|
71098
71103
|
function withoutTrailingNewline(value) {
|
|
71099
71104
|
return value.replace(/\r?\n$/u, "");
|
|
71100
71105
|
}
|
|
71101
|
-
var spawnRunner = async (file2, args, input2) => await new Promise((resolve4) => {
|
|
71106
|
+
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve4) => {
|
|
71102
71107
|
let stdout = "";
|
|
71103
71108
|
let stderr2 = "";
|
|
71104
71109
|
let settled = false;
|
|
@@ -71108,7 +71113,7 @@ var spawnRunner = async (file2, args, input2) => await new Promise((resolve4) =>
|
|
|
71108
71113
|
resolve4(outcome);
|
|
71109
71114
|
};
|
|
71110
71115
|
const child = spawn(file2, [...args], {
|
|
71111
|
-
detached:
|
|
71116
|
+
detached: platform2 !== "win32",
|
|
71112
71117
|
stdio: ["pipe", "pipe", "pipe"],
|
|
71113
71118
|
windowsHide: true
|
|
71114
71119
|
});
|
|
@@ -72727,6 +72732,17 @@ var WalletStore = class _WalletStore {
|
|
|
72727
72732
|
);
|
|
72728
72733
|
return account?.address ?? (await readKeystoreSummary(this.pathFor(target))).address;
|
|
72729
72734
|
}
|
|
72735
|
+
/**
|
|
72736
|
+
* Creates the vault without deriving an account, for apps that create every
|
|
72737
|
+
* account by name. Refuses when a vault already exists in this home.
|
|
72738
|
+
*/
|
|
72739
|
+
async createEmptyVault() {
|
|
72740
|
+
if (await this.readVaultUnlocked() !== void 0) {
|
|
72741
|
+
throw new KeystoreError("A vault already exists in this home.");
|
|
72742
|
+
}
|
|
72743
|
+
await this.openVault({ create: true });
|
|
72744
|
+
this.dropVaultCache();
|
|
72745
|
+
}
|
|
72730
72746
|
async create(name, passphrase, options = {}) {
|
|
72731
72747
|
void passphrase;
|
|
72732
72748
|
void options.enableSolana;
|
|
@@ -73607,11 +73623,11 @@ function accountChangeBusyError(account, command) {
|
|
|
73607
73623
|
);
|
|
73608
73624
|
}
|
|
73609
73625
|
async function withAccountMutationLocks(home, accounts, command, operation) {
|
|
73610
|
-
const [account, ...
|
|
73626
|
+
const [account, ...remaining2] = [...new Set(accounts)].sort();
|
|
73611
73627
|
if (account === void 0) return await operation();
|
|
73612
73628
|
return await withFileLock(
|
|
73613
73629
|
join8(home, `.account-${account}.lock`),
|
|
73614
|
-
async () => await withAccountMutationLocks(home,
|
|
73630
|
+
async () => await withAccountMutationLocks(home, remaining2, command, operation),
|
|
73615
73631
|
{
|
|
73616
73632
|
lockedMessage: `Account ${account} is busy with another account change. Wait for it to finish, then retry ${command}.`
|
|
73617
73633
|
}
|
|
@@ -74419,8 +74435,8 @@ async function escrowFundingDayRemainingAtomic(input2) {
|
|
|
74419
74435
|
const rows = await readStoredSpendLedgerRows(input2.ledgerPath, input2.now);
|
|
74420
74436
|
const row = rows.find((candidate) => candidate.wallet === input2.wallet);
|
|
74421
74437
|
const reserved = input2.reservationId ? row?.reservations?.find((candidate) => candidate.id === input2.reservationId) : void 0;
|
|
74422
|
-
const
|
|
74423
|
-
return
|
|
74438
|
+
const remaining2 = perDayAtomic - BigInt(row?.spentAtomic ?? "0") + BigInt(reserved?.amountAtomic ?? "0");
|
|
74439
|
+
return remaining2 > 0n ? remaining2 : 0n;
|
|
74424
74440
|
}
|
|
74425
74441
|
async function taskReservedAtomic(input2) {
|
|
74426
74442
|
const rows = await readStoredSpendLedgerRows(input2.ledgerPath, input2.now, true);
|
|
@@ -75760,13 +75776,13 @@ function splitMovementPlanAtRelayLimit(plan) {
|
|
|
75760
75776
|
const legs = plan.legs.flatMap((leg) => {
|
|
75761
75777
|
const purpose = leg.purpose ?? "send";
|
|
75762
75778
|
const split2 = purpose === "sweep" || plan.reason === "send" && plan.treasury !== void 0 && leg.to === plan.treasury;
|
|
75763
|
-
let
|
|
75764
|
-
if (!split2 ||
|
|
75779
|
+
let remaining2 = parseUsdCents(leg.amountUsd);
|
|
75780
|
+
if (!split2 || remaining2 <= maximumCents) return [leg];
|
|
75765
75781
|
const parts = [];
|
|
75766
|
-
while (
|
|
75767
|
-
const cents =
|
|
75782
|
+
while (remaining2 > 0n) {
|
|
75783
|
+
const cents = remaining2 > maximumCents ? maximumCents : remaining2;
|
|
75768
75784
|
parts.push({ ...leg, amountUsd: formatUsdCents(cents) });
|
|
75769
|
-
|
|
75785
|
+
remaining2 -= cents;
|
|
75770
75786
|
}
|
|
75771
75787
|
return parts;
|
|
75772
75788
|
});
|
|
@@ -76642,13 +76658,13 @@ async function withMovementLock(home, from16, timeoutMs, operation) {
|
|
|
76642
76658
|
}
|
|
76643
76659
|
}
|
|
76644
76660
|
async function withMovementLocks(home, senders, timeoutMs, operation) {
|
|
76645
|
-
const [sender, ...
|
|
76661
|
+
const [sender, ...remaining2] = senders;
|
|
76646
76662
|
if (sender === void 0) return await operation();
|
|
76647
76663
|
return await withMovementLock(
|
|
76648
76664
|
home,
|
|
76649
76665
|
sender,
|
|
76650
76666
|
timeoutMs,
|
|
76651
|
-
async () => withMovementLocks(home,
|
|
76667
|
+
async () => withMovementLocks(home, remaining2, timeoutMs, operation)
|
|
76652
76668
|
);
|
|
76653
76669
|
}
|
|
76654
76670
|
async function assertNoPendingCeilingSweep(deps, senders) {
|
|
@@ -77455,11 +77471,11 @@ function planTargets(input2) {
|
|
|
77455
77471
|
function splitCandidateAtRelayMaximum(candidate, relayMaxAtomic) {
|
|
77456
77472
|
const maximumCents = relayMaxAtomic / 10000n;
|
|
77457
77473
|
const legs = [];
|
|
77458
|
-
let
|
|
77459
|
-
while (
|
|
77460
|
-
const cents =
|
|
77474
|
+
let remaining2 = candidate.cents;
|
|
77475
|
+
while (remaining2 > 0n) {
|
|
77476
|
+
const cents = remaining2 > maximumCents ? maximumCents : remaining2;
|
|
77461
77477
|
legs.push(allocationLeg(candidate.from, candidate.to, cents, candidate.purpose));
|
|
77462
|
-
|
|
77478
|
+
remaining2 -= cents;
|
|
77463
77479
|
}
|
|
77464
77480
|
return legs;
|
|
77465
77481
|
}
|
|
@@ -78294,7 +78310,7 @@ function createRunBudget(args) {
|
|
|
78294
78310
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
78295
78311
|
import { arch, platform, release } from "node:os";
|
|
78296
78312
|
import { join as join13 } from "node:path";
|
|
78297
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
78313
|
+
var VAPI_CLIENT_VERSION = "0.12.0";
|
|
78298
78314
|
async function createSupportReport(options) {
|
|
78299
78315
|
const message = options.message.trim();
|
|
78300
78316
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
@@ -79686,8 +79702,15 @@ async function ownerStake(deps) {
|
|
|
79686
79702
|
stakeUrl: parsed.data.stakeUrl
|
|
79687
79703
|
};
|
|
79688
79704
|
}
|
|
79689
|
-
async function routerCredentials(deps) {
|
|
79690
|
-
const
|
|
79705
|
+
async function routerCredentials(deps, options = {}) {
|
|
79706
|
+
const credentials = options.funding === "balance" ? await routerBalanceCredentialSnapshot(deps) : await routerCredentialSnapshot(deps);
|
|
79707
|
+
if (credentials === void 0) {
|
|
79708
|
+
throw new RouterClientError(
|
|
79709
|
+
"no_router_key",
|
|
79710
|
+
"No Router balance key is stored for this wallet."
|
|
79711
|
+
);
|
|
79712
|
+
}
|
|
79713
|
+
const { routerBaseUrl, routerKey } = credentials;
|
|
79691
79714
|
return { baseURL: `${routerBaseUrl}/v1`, apiKey: routerKey };
|
|
79692
79715
|
}
|
|
79693
79716
|
async function routerCredentialSnapshot(deps) {
|
|
@@ -82911,10 +82934,10 @@ async function waitForMilestone(client, input2) {
|
|
|
82911
82934
|
return { reached, milestone, polls, elapsedMs: now().getTime() - started };
|
|
82912
82935
|
}
|
|
82913
82936
|
for (; ; ) {
|
|
82914
|
-
const
|
|
82915
|
-
if (
|
|
82937
|
+
const remaining2 = deadline - now().getTime();
|
|
82938
|
+
if (remaining2 <= 0) return result(false);
|
|
82916
82939
|
const controller = new AbortController();
|
|
82917
|
-
const timer = setTimeout(() => controller.abort(),
|
|
82940
|
+
const timer = setTimeout(() => controller.abort(), remaining2);
|
|
82918
82941
|
let response;
|
|
82919
82942
|
polls++;
|
|
82920
82943
|
try {
|
|
@@ -83578,7 +83601,7 @@ async function feeTask(input2, action) {
|
|
|
83578
83601
|
);
|
|
83579
83602
|
let approvalGranted = input2.approval !== void 0 && "granted" in input2.approval && input2.approval.granted;
|
|
83580
83603
|
const checkPolicy = async (reservationId) => {
|
|
83581
|
-
const
|
|
83604
|
+
const remaining2 = await escrowFundingDayRemainingAtomic({
|
|
83582
83605
|
caps: input2.caps,
|
|
83583
83606
|
ledgerPath: input2.ledgerPath,
|
|
83584
83607
|
wallet: input2.wallet,
|
|
@@ -83595,13 +83618,13 @@ async function feeTask(input2, action) {
|
|
|
83595
83618
|
const maxPerTaskAtomic = policyAtomic(input2.policy.maxPerTaskUsd);
|
|
83596
83619
|
if (feeAtomic > maxPerTaskAtomic || taskReserved + feeAtomic > maxPerTaskAtomic)
|
|
83597
83620
|
return { outcome: "refused", reason: "policy.perTask", money: money2, disputeFee: fee };
|
|
83598
|
-
if (feeAtomic >
|
|
83621
|
+
if (feeAtomic > remaining2)
|
|
83599
83622
|
return { outcome: "refused", reason: "policy.perDay", money: money2, disputeFee: fee };
|
|
83600
83623
|
if (feeAtomic > policyAtomic(input2.policy.approveAboveUsd) && !approvalGranted) {
|
|
83601
83624
|
if (input2.approval && "ask" in input2.approval) {
|
|
83602
83625
|
approvalGranted = await input2.approval.ask({
|
|
83603
83626
|
money: money2,
|
|
83604
|
-
dayRemainingUsd: Number(formatBaseUnitsUsd(
|
|
83627
|
+
dayRemainingUsd: Number(formatBaseUnitsUsd(remaining2))
|
|
83605
83628
|
});
|
|
83606
83629
|
if (!approvalGranted) return { outcome: "declined", money: money2, disputeFee: fee };
|
|
83607
83630
|
} else return { outcome: "approval_needed", money: money2, disputeFee: fee };
|
|
@@ -85826,6 +85849,54 @@ var SpendPolicy = class {
|
|
|
85826
85849
|
}
|
|
85827
85850
|
};
|
|
85828
85851
|
|
|
85852
|
+
// ../core/src/link-state.ts
|
|
85853
|
+
async function linkStates(args) {
|
|
85854
|
+
const origin = new URL(args.apiBase).origin;
|
|
85855
|
+
await args.store.reload();
|
|
85856
|
+
const states = /* @__PURE__ */ new Map();
|
|
85857
|
+
const candidates = [];
|
|
85858
|
+
for (const name of args.store.names()) {
|
|
85859
|
+
const link3 = args.store.entry(name)?.link;
|
|
85860
|
+
const address4 = await args.store.readAddress(name);
|
|
85861
|
+
const hasTokens = args.secrets.available && await args.secrets.has(agentSecretAccounts(name).tokens).catch(() => false);
|
|
85862
|
+
if (link3 === void 0 || new URL(link3.apiBase).origin !== origin || address4 === void 0 || !hasTokens) {
|
|
85863
|
+
states.set(name, "not_linked");
|
|
85864
|
+
continue;
|
|
85865
|
+
}
|
|
85866
|
+
states.set(name, "linked");
|
|
85867
|
+
candidates.push({ name, owner: getAddress(link3.owner), address: getAddress(address4) });
|
|
85868
|
+
}
|
|
85869
|
+
for (const source of candidates) {
|
|
85870
|
+
let result;
|
|
85871
|
+
try {
|
|
85872
|
+
result = await fetchSiblings({
|
|
85873
|
+
apiBase: args.apiBase,
|
|
85874
|
+
account: source.name,
|
|
85875
|
+
secrets: args.secrets,
|
|
85876
|
+
wallets: args.store,
|
|
85877
|
+
...args.fetchImpl === void 0 ? {} : { fetchImpl: args.fetchImpl },
|
|
85878
|
+
...args.now === void 0 ? {} : { now: args.now }
|
|
85879
|
+
});
|
|
85880
|
+
} catch (error61) {
|
|
85881
|
+
if (error61 instanceof SiblingsError && error61.code === "not_linked") {
|
|
85882
|
+
states.set(source.name, "revoked");
|
|
85883
|
+
continue;
|
|
85884
|
+
}
|
|
85885
|
+
return states;
|
|
85886
|
+
}
|
|
85887
|
+
const owner = result.owner === null ? source.owner : getAddress(result.owner);
|
|
85888
|
+
for (const candidate of candidates) {
|
|
85889
|
+
if (candidate.owner !== owner) continue;
|
|
85890
|
+
const sibling = result.siblings.find(
|
|
85891
|
+
(entry) => getAddress(entry.address) === candidate.address
|
|
85892
|
+
);
|
|
85893
|
+
states.set(candidate.name, sibling?.status === "active" ? "linked" : "revoked");
|
|
85894
|
+
}
|
|
85895
|
+
return states;
|
|
85896
|
+
}
|
|
85897
|
+
return states;
|
|
85898
|
+
}
|
|
85899
|
+
|
|
85829
85900
|
// ../core/src/stats.ts
|
|
85830
85901
|
var STATS_RANGES = ["24h", "7d", "30d"];
|
|
85831
85902
|
var OUTCOMES = [
|
|
@@ -88145,6 +88216,37 @@ function isRecord4(value) {
|
|
|
88145
88216
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
88146
88217
|
}
|
|
88147
88218
|
|
|
88219
|
+
// ../core/src/vault-setup.ts
|
|
88220
|
+
import { rm as rm2 } from "node:fs/promises";
|
|
88221
|
+
import { join as join18 } from "node:path";
|
|
88222
|
+
async function createVault2(home, options) {
|
|
88223
|
+
if (options.password === "") {
|
|
88224
|
+
throw new KeystoreError("A password cannot be empty.");
|
|
88225
|
+
}
|
|
88226
|
+
const store = await WalletStore.open(home, {
|
|
88227
|
+
secrets: options.secrets,
|
|
88228
|
+
...options.now === void 0 ? {} : { now: options.now }
|
|
88229
|
+
});
|
|
88230
|
+
const hadDeviceKey = options.password !== void 0 && await options.secrets.has(VAULT_KEY_ACCOUNT);
|
|
88231
|
+
await store.createEmptyVault();
|
|
88232
|
+
if (options.password !== void 0) {
|
|
88233
|
+
const path = join18(home, "vault.json");
|
|
88234
|
+
try {
|
|
88235
|
+
await protectVault({
|
|
88236
|
+
path,
|
|
88237
|
+
secrets: options.secrets,
|
|
88238
|
+
password: options.password
|
|
88239
|
+
});
|
|
88240
|
+
} catch (error61) {
|
|
88241
|
+
await Promise.allSettled([
|
|
88242
|
+
rm2(path, { force: true }),
|
|
88243
|
+
...hadDeviceKey ? [] : [options.secrets.remove(VAULT_KEY_ACCOUNT)]
|
|
88244
|
+
]);
|
|
88245
|
+
throw error61;
|
|
88246
|
+
}
|
|
88247
|
+
}
|
|
88248
|
+
}
|
|
88249
|
+
|
|
88148
88250
|
// ../core/src/wallet.ts
|
|
88149
88251
|
var LocalWallet = class {
|
|
88150
88252
|
constructor(account, policy) {
|
|
@@ -88172,6 +88274,44 @@ var LocalWallet = class {
|
|
|
88172
88274
|
}
|
|
88173
88275
|
};
|
|
88174
88276
|
|
|
88277
|
+
// ../core/src/remote-account.ts
|
|
88278
|
+
var RemoteAccountError = class extends Error {
|
|
88279
|
+
constructor(code, message) {
|
|
88280
|
+
super(message);
|
|
88281
|
+
this.code = code;
|
|
88282
|
+
this.name = "RemoteAccountError";
|
|
88283
|
+
}
|
|
88284
|
+
code;
|
|
88285
|
+
};
|
|
88286
|
+
var notPermitted = (what) => new RemoteAccountError("not_permitted", `${what} is not permitted through vAPI Desktop.`);
|
|
88287
|
+
function remotePaymentAccount(args) {
|
|
88288
|
+
const base = toAccount({
|
|
88289
|
+
address: args.address,
|
|
88290
|
+
async signMessage({ message }) {
|
|
88291
|
+
const text = typeof message === "string" ? message : JSON.stringify(message);
|
|
88292
|
+
return await args.request({ kind: "message", wallet: args.wallet, message: text });
|
|
88293
|
+
},
|
|
88294
|
+
async signTransaction() {
|
|
88295
|
+
throw notPermitted("Raw transaction signing");
|
|
88296
|
+
},
|
|
88297
|
+
async signTypedData(typedData) {
|
|
88298
|
+
return await args.request({ kind: "typedData", wallet: args.wallet, typedData });
|
|
88299
|
+
}
|
|
88300
|
+
});
|
|
88301
|
+
const account = {
|
|
88302
|
+
...base,
|
|
88303
|
+
publicKey: args.publicKey,
|
|
88304
|
+
source: "privateKey",
|
|
88305
|
+
async sign() {
|
|
88306
|
+
throw notPermitted("Hash signing");
|
|
88307
|
+
},
|
|
88308
|
+
async signAuthorization() {
|
|
88309
|
+
throw notPermitted("EIP-7702 authorization");
|
|
88310
|
+
}
|
|
88311
|
+
};
|
|
88312
|
+
return account;
|
|
88313
|
+
}
|
|
88314
|
+
|
|
88175
88315
|
// ../core/src/member-bundle.ts
|
|
88176
88316
|
var MEMBER_BUNDLE_MAX_BYTES = 32 * 1024;
|
|
88177
88317
|
var REMOTE_BLOCKED_GRANTS = /* @__PURE__ */ new Set([
|
|
@@ -91733,8 +91873,8 @@ function exactPriceFact(value) {
|
|
|
91733
91873
|
}
|
|
91734
91874
|
|
|
91735
91875
|
// ../mcp/src/agent/runtime.ts
|
|
91736
|
-
import { mkdir as mkdir18, readFile as readFile23, readdir as readdir7, rm as
|
|
91737
|
-
import { join as
|
|
91876
|
+
import { mkdir as mkdir18, readFile as readFile23, readdir as readdir7, rm as rm3 } from "node:fs/promises";
|
|
91877
|
+
import { join as join19 } from "node:path";
|
|
91738
91878
|
|
|
91739
91879
|
// ../mcp/src/agent/run.ts
|
|
91740
91880
|
var loopSearchResultSchema = external_exports.array(
|
|
@@ -92820,8 +92960,8 @@ async function memberBudgetAtomic(account, configured, deps) {
|
|
|
92820
92960
|
deps.now?.() ?? /* @__PURE__ */ new Date(),
|
|
92821
92961
|
account
|
|
92822
92962
|
);
|
|
92823
|
-
const
|
|
92824
|
-
return
|
|
92963
|
+
const remaining2 = BigInt(caps.perDayAtomic) - BigInt(ledger.spentAtomic);
|
|
92964
|
+
return remaining2 < 0n ? 0n : remaining2;
|
|
92825
92965
|
}
|
|
92826
92966
|
function withoutTreasuryGrants(profile) {
|
|
92827
92967
|
return {
|
|
@@ -93035,19 +93175,19 @@ var runRecordSchema = external_exports.strictObject({
|
|
|
93035
93175
|
detail: external_exports.string().optional()
|
|
93036
93176
|
});
|
|
93037
93177
|
function runsDirectory(home) {
|
|
93038
|
-
return
|
|
93178
|
+
return join19(home, "runs");
|
|
93039
93179
|
}
|
|
93040
93180
|
function runRecordPath(home, runId) {
|
|
93041
93181
|
assertRunId(runId);
|
|
93042
|
-
return
|
|
93182
|
+
return join19(runsDirectory(home), `${runId}.json`);
|
|
93043
93183
|
}
|
|
93044
93184
|
function runLogPath(home, runId) {
|
|
93045
93185
|
assertRunId(runId);
|
|
93046
|
-
return
|
|
93186
|
+
return join19(runsDirectory(home), `${runId}.log`);
|
|
93047
93187
|
}
|
|
93048
93188
|
function runResultPath(home, runId) {
|
|
93049
93189
|
assertRunId(runId);
|
|
93050
|
-
return
|
|
93190
|
+
return join19(runsDirectory(home), `${runId}.result.json`);
|
|
93051
93191
|
}
|
|
93052
93192
|
async function writeRunRecord(home, record2) {
|
|
93053
93193
|
const path = runRecordPath(home, record2.runId);
|
|
@@ -93078,7 +93218,7 @@ async function listRunRecords(home, filter = {}) {
|
|
|
93078
93218
|
if (match === null) continue;
|
|
93079
93219
|
try {
|
|
93080
93220
|
const record2 = runRecordSchema.parse(
|
|
93081
|
-
JSON.parse(await readFile23(
|
|
93221
|
+
JSON.parse(await readFile23(join19(runsDirectory(home), file2), "utf8"))
|
|
93082
93222
|
);
|
|
93083
93223
|
if (record2.runId !== match[1]) continue;
|
|
93084
93224
|
if (filter.swarm !== void 0 && record2.member.swarm !== filter.swarm) continue;
|
|
@@ -93215,7 +93355,7 @@ async function startDetachedRun(args) {
|
|
|
93215
93355
|
await writeRunRecord(args.home, reservation);
|
|
93216
93356
|
});
|
|
93217
93357
|
} catch (error61) {
|
|
93218
|
-
await
|
|
93358
|
+
await rm3(runRecordPath(args.home, args.run.runId), { force: true }).catch(
|
|
93219
93359
|
() => void 0
|
|
93220
93360
|
);
|
|
93221
93361
|
throw error61;
|
|
@@ -93234,7 +93374,7 @@ async function startDetachedRun(args) {
|
|
|
93234
93374
|
() => false
|
|
93235
93375
|
);
|
|
93236
93376
|
if (stopped) {
|
|
93237
|
-
await
|
|
93377
|
+
await rm3(runRecordPath(args.home, args.run.runId), { force: true }).catch(
|
|
93238
93378
|
() => void 0
|
|
93239
93379
|
);
|
|
93240
93380
|
}
|
|
@@ -93355,7 +93495,7 @@ async function stopRun(args) {
|
|
|
93355
93495
|
}
|
|
93356
93496
|
}
|
|
93357
93497
|
function memberRunLockPath(home, account) {
|
|
93358
|
-
return
|
|
93498
|
+
return join19(runsDirectory(home), `.member-${account}.lock`);
|
|
93359
93499
|
}
|
|
93360
93500
|
function summarizeRunRecord(record2) {
|
|
93361
93501
|
return {
|
|
@@ -94816,9 +94956,9 @@ async function watchEvents(ctx, input2, now, sleep, deadline, signal, progress)
|
|
|
94816
94956
|
const reached = input2.until !== void 0 && next.events.some((event) => taskStateMatches(input2.until, taskEventState(event)));
|
|
94817
94957
|
if (next.events.length || reached)
|
|
94818
94958
|
return { ...next, ...reached ? { reached: input2.until } : {}, timedOut: false };
|
|
94819
|
-
const
|
|
94820
|
-
if (
|
|
94821
|
-
await sleep(Math.min(TASK_LIMITS.watchIntervalMinMs,
|
|
94959
|
+
const remaining2 = deadline - now().getTime();
|
|
94960
|
+
if (remaining2 <= 0) return { ...next, timedOut: true };
|
|
94961
|
+
await sleep(Math.min(TASK_LIMITS.watchIntervalMinMs, remaining2), signal);
|
|
94822
94962
|
if (now().getTime() >= deadline)
|
|
94823
94963
|
return { events: [], nextCursor: progress.cursor, timedOut: true };
|
|
94824
94964
|
}
|
|
@@ -95861,9 +96001,15 @@ var VapiMcpServer = class {
|
|
|
95861
96001
|
return tool.deprecatedReplacement ? withDeprecation(result, tool.deprecatedReplacement) : result;
|
|
95862
96002
|
}
|
|
95863
96003
|
}
|
|
95864
|
-
|
|
96004
|
+
#output = process.stdout;
|
|
96005
|
+
/**
|
|
96006
|
+
* Serves JSON-RPC lines from `input` and answers on `output`. The desktop
|
|
96007
|
+
* app hands in a socket; the CLI hands in stdio through connectStdio().
|
|
96008
|
+
*/
|
|
96009
|
+
connect(input2, output4) {
|
|
95865
96010
|
if (this.#stdio) return;
|
|
95866
|
-
this.#
|
|
96011
|
+
this.#output = output4;
|
|
96012
|
+
this.#stdio = createInterface({ input: input2, crlfDelay: Infinity });
|
|
95867
96013
|
this.#stdio.on("line", (line) => {
|
|
95868
96014
|
void this.#handleLine(line);
|
|
95869
96015
|
});
|
|
@@ -95872,6 +96018,9 @@ var VapiMcpServer = class {
|
|
|
95872
96018
|
this.#onClose?.();
|
|
95873
96019
|
});
|
|
95874
96020
|
}
|
|
96021
|
+
connectStdio() {
|
|
96022
|
+
this.connect(process.stdin, process.stdout);
|
|
96023
|
+
}
|
|
95875
96024
|
async close() {
|
|
95876
96025
|
this.#stdio?.close();
|
|
95877
96026
|
this.#stdio = void 0;
|
|
@@ -95952,7 +96101,7 @@ var VapiMcpServer = class {
|
|
|
95952
96101
|
}
|
|
95953
96102
|
}
|
|
95954
96103
|
#write(message) {
|
|
95955
|
-
|
|
96104
|
+
this.#output.write(`${JSON.stringify(message)}
|
|
95956
96105
|
`);
|
|
95957
96106
|
}
|
|
95958
96107
|
};
|
|
@@ -96954,7 +97103,7 @@ function rgbToAnsi256(red, green, blue) {
|
|
|
96954
97103
|
|
|
96955
97104
|
// ../cli/src/accounts.ts
|
|
96956
97105
|
import { readFile as readFile25, stat as stat14 } from "node:fs/promises";
|
|
96957
|
-
import { join as
|
|
97106
|
+
import { join as join22 } from "node:path";
|
|
96958
97107
|
|
|
96959
97108
|
// ../cli/src/dashboard.ts
|
|
96960
97109
|
import { resolve as resolve3 } from "node:path";
|
|
@@ -97631,7 +97780,7 @@ import { homedir as homedir2 } from "node:os";
|
|
|
97631
97780
|
import { sep } from "node:path";
|
|
97632
97781
|
|
|
97633
97782
|
// ../core/src/cloud-backup.ts
|
|
97634
|
-
import { join as
|
|
97783
|
+
import { join as join21 } from "node:path";
|
|
97635
97784
|
|
|
97636
97785
|
// ../core/src/backup.ts
|
|
97637
97786
|
import {
|
|
@@ -97656,9 +97805,9 @@ import {
|
|
|
97656
97805
|
open as openFile,
|
|
97657
97806
|
readFile as readFile24,
|
|
97658
97807
|
readdir as readdir8,
|
|
97659
|
-
rm as
|
|
97808
|
+
rm as rm4
|
|
97660
97809
|
} from "node:fs/promises";
|
|
97661
|
-
import { dirname as dirname12, join as
|
|
97810
|
+
import { dirname as dirname12, join as join20 } from "node:path";
|
|
97662
97811
|
var ERROR_MESSAGES = {
|
|
97663
97812
|
backup_too_large: "Backup envelope exceeds 65,536 bytes.",
|
|
97664
97813
|
backup_open_failed: "Unable to open backup.",
|
|
@@ -98136,7 +98285,7 @@ async function exportBackupSource(options) {
|
|
|
98136
98285
|
var BackupSnapshotChangedError = class extends Error {
|
|
98137
98286
|
};
|
|
98138
98287
|
async function exportBackupSourceAttempt(options, networks) {
|
|
98139
|
-
const path =
|
|
98288
|
+
const path = join20(options.store.home, "vault.json");
|
|
98140
98289
|
const { phrase, file: file2, accounts } = await withVaultLock(path, async () => {
|
|
98141
98290
|
const [phrase2, vault, file3] = await Promise.all([
|
|
98142
98291
|
exportVaultPhrase({ path, key: options.vaultKey }),
|
|
@@ -98272,16 +98421,16 @@ async function restoreBackupPlaintext(options) {
|
|
|
98272
98421
|
} catch {
|
|
98273
98422
|
throw new BackupError("backup_invalid_input");
|
|
98274
98423
|
}
|
|
98275
|
-
const vaultPath2 =
|
|
98276
|
-
const registryPath =
|
|
98424
|
+
const vaultPath2 = join20(options.home, "vault.json");
|
|
98425
|
+
const registryPath = join20(options.home, "wallets.json");
|
|
98277
98426
|
let stagingHome;
|
|
98278
98427
|
let beforePublishError;
|
|
98279
98428
|
let afterPublishError;
|
|
98280
98429
|
try {
|
|
98281
98430
|
await mkdir19(options.home, { recursive: true, mode: 448 });
|
|
98282
|
-
stagingHome = await mkdtemp(
|
|
98283
|
-
const stagedVaultPath =
|
|
98284
|
-
const stagedRegistryPath =
|
|
98431
|
+
stagingHome = await mkdtemp(join20(options.home, ".backup-restore-"));
|
|
98432
|
+
const stagedVaultPath = join20(stagingHome, "vault.json");
|
|
98433
|
+
const stagedRegistryPath = join20(stagingHome, "wallets.json");
|
|
98285
98434
|
await createVault({
|
|
98286
98435
|
path: stagedVaultPath,
|
|
98287
98436
|
key: options.vaultKey,
|
|
@@ -98340,7 +98489,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
98340
98489
|
protected: plaintext.protected,
|
|
98341
98490
|
networks: [...plaintext.registry.networks]
|
|
98342
98491
|
};
|
|
98343
|
-
const markerPath =
|
|
98492
|
+
const markerPath = join20(options.home, RESTORE_MARKER_FILE);
|
|
98344
98493
|
const fingerprint = restoreFingerprint(
|
|
98345
98494
|
plaintext,
|
|
98346
98495
|
stagedV2?.restoreDevice ?? options.device,
|
|
@@ -98405,7 +98554,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
98405
98554
|
await link2(stagedVaultPath, vaultPath2);
|
|
98406
98555
|
publishedVault = true;
|
|
98407
98556
|
} catch (error61) {
|
|
98408
|
-
await
|
|
98557
|
+
await rm4(markerPath, { force: true }).catch(() => void 0);
|
|
98409
98558
|
throw error61;
|
|
98410
98559
|
}
|
|
98411
98560
|
await notifyRestorePublish(options.afterPublish, { kind: "vault" }, (error61) => {
|
|
@@ -98416,8 +98565,8 @@ async function restoreBackupPlaintext(options) {
|
|
|
98416
98565
|
try {
|
|
98417
98566
|
await link2(stagedRegistryPath, registryPath);
|
|
98418
98567
|
} catch (error61) {
|
|
98419
|
-
if (publishedVault) await
|
|
98420
|
-
await
|
|
98568
|
+
if (publishedVault) await rm4(vaultPath2, { force: true }).catch(() => void 0);
|
|
98569
|
+
await rm4(markerPath, { force: true }).catch(() => void 0);
|
|
98421
98570
|
throw error61;
|
|
98422
98571
|
}
|
|
98423
98572
|
await notifyRestorePublish(options.afterPublish, { kind: "registry" }, (error61) => {
|
|
@@ -98431,7 +98580,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
98431
98580
|
});
|
|
98432
98581
|
});
|
|
98433
98582
|
}
|
|
98434
|
-
await
|
|
98583
|
+
await rm4(markerPath, { force: true });
|
|
98435
98584
|
});
|
|
98436
98585
|
if (stagedV2 === void 0) return baseResult;
|
|
98437
98586
|
return {
|
|
@@ -98452,7 +98601,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
98452
98601
|
throw new BackupError("backup_invalid_input");
|
|
98453
98602
|
} finally {
|
|
98454
98603
|
if (stagingHome !== void 0) {
|
|
98455
|
-
await
|
|
98604
|
+
await rm4(stagingHome, { recursive: true, force: true }).catch(() => void 0);
|
|
98456
98605
|
}
|
|
98457
98606
|
}
|
|
98458
98607
|
}
|
|
@@ -98551,13 +98700,13 @@ async function stageV2Restore(options) {
|
|
|
98551
98700
|
}
|
|
98552
98701
|
const agents = [];
|
|
98553
98702
|
for (const profile of validAgents) {
|
|
98554
|
-
const stagedPath =
|
|
98703
|
+
const stagedPath = join20(options.stagingHome, "agents", `${profile.name}.json`);
|
|
98555
98704
|
if (await stageRestoreBytes(stagedPath, prettyJson(profile))) {
|
|
98556
98705
|
agents.push({
|
|
98557
98706
|
kind: "agent",
|
|
98558
98707
|
name: profile.name,
|
|
98559
98708
|
stagedPath,
|
|
98560
|
-
targetPath:
|
|
98709
|
+
targetPath: join20(options.home, "agents", `${profile.name}.json`)
|
|
98561
98710
|
});
|
|
98562
98711
|
} else {
|
|
98563
98712
|
skipped2.push({ kind: "agent", name: profile.name, reason: "write_failed" });
|
|
@@ -98577,13 +98726,13 @@ async function stageV2Restore(options) {
|
|
|
98577
98726
|
if (restoreDevice !== void 0) {
|
|
98578
98727
|
for (const value of validSwarms) {
|
|
98579
98728
|
const swarm = swarmFileSchema.parse({ ...value, device: restoreDevice });
|
|
98580
|
-
const stagedPath =
|
|
98729
|
+
const stagedPath = join20(options.stagingHome, "swarms", `${swarm.name}.json`);
|
|
98581
98730
|
if (await stageRestoreBytes(stagedPath, prettyJson(swarm))) {
|
|
98582
98731
|
swarms.push({
|
|
98583
98732
|
kind: "swarm",
|
|
98584
98733
|
name: swarm.name,
|
|
98585
98734
|
stagedPath,
|
|
98586
|
-
targetPath:
|
|
98735
|
+
targetPath: join20(options.home, "swarms", `${swarm.name}.json`)
|
|
98587
98736
|
});
|
|
98588
98737
|
} else {
|
|
98589
98738
|
skipped2.push({ kind: "swarm", name: swarm.name, reason: "write_failed" });
|
|
@@ -98593,13 +98742,13 @@ async function stageV2Restore(options) {
|
|
|
98593
98742
|
const movements = [];
|
|
98594
98743
|
for (const movement of validMovements) {
|
|
98595
98744
|
const restored = reconcileRestoredMovement(movement, assumedReceiptKeys);
|
|
98596
|
-
const stagedPath =
|
|
98745
|
+
const stagedPath = join20(options.stagingHome, "movements", `${restored.id}.json`);
|
|
98597
98746
|
if (await stageRestoreBytes(stagedPath, serializeMovement(restored))) {
|
|
98598
98747
|
movements.push({
|
|
98599
98748
|
kind: "movement",
|
|
98600
98749
|
name: restored.id,
|
|
98601
98750
|
stagedPath,
|
|
98602
|
-
targetPath:
|
|
98751
|
+
targetPath: join20(options.home, "movements", `${restored.id}.json`),
|
|
98603
98752
|
movement: restored
|
|
98604
98753
|
});
|
|
98605
98754
|
} else {
|
|
@@ -98758,7 +98907,7 @@ async function reconcilePublishedMovements(staged, home, requireDurableSafety =
|
|
|
98758
98907
|
const unjournaledKeys = new Set([...signedKeys].filter((key2) => !journaledKeys.has(key2)));
|
|
98759
98908
|
let files;
|
|
98760
98909
|
try {
|
|
98761
|
-
files = await readdir8(
|
|
98910
|
+
files = await readdir8(join20(home, "movements"));
|
|
98762
98911
|
} catch (error61) {
|
|
98763
98912
|
if (isMissingFile4(error61)) return;
|
|
98764
98913
|
if (requireDurableSafety && unjournaledKeys.size > 0) throw error61;
|
|
@@ -99537,10 +99686,10 @@ async function awaitRelay(options) {
|
|
|
99537
99686
|
if (!Number.isFinite(deadline)) throw new CloudBackupError("relay_expired");
|
|
99538
99687
|
while (true) {
|
|
99539
99688
|
if (isAborted(options.signal)) throw new CloudBackupError("relay_aborted");
|
|
99540
|
-
const
|
|
99541
|
-
if (
|
|
99689
|
+
const remaining2 = deadline - readNow(now).getTime();
|
|
99690
|
+
if (remaining2 <= 0) throw new CloudBackupError("relay_expired");
|
|
99542
99691
|
let response;
|
|
99543
|
-
const requestDeadline = AbortSignal.timeout(Math.max(1,
|
|
99692
|
+
const requestDeadline = AbortSignal.timeout(Math.max(1, remaining2));
|
|
99544
99693
|
const requestSignal = options.signal === void 0 ? requestDeadline : AbortSignal.any([options.signal, requestDeadline]);
|
|
99545
99694
|
try {
|
|
99546
99695
|
response = await (options.fetchImpl ?? publicFetch5)(
|
|
@@ -99559,7 +99708,7 @@ async function awaitRelay(options) {
|
|
|
99559
99708
|
return await readRelayResult(response, options);
|
|
99560
99709
|
}
|
|
99561
99710
|
try {
|
|
99562
|
-
await sleep(Math.min(Math.max(0, pollMs),
|
|
99711
|
+
await sleep(Math.min(Math.max(0, pollMs), remaining2), options.signal);
|
|
99563
99712
|
} catch {
|
|
99564
99713
|
if (isAborted(options.signal)) throw new CloudBackupError("relay_aborted");
|
|
99565
99714
|
}
|
|
@@ -99667,7 +99816,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
99667
99816
|
try {
|
|
99668
99817
|
let vaultFile;
|
|
99669
99818
|
try {
|
|
99670
|
-
vaultFile = await readVaultFileUnlocked(
|
|
99819
|
+
vaultFile = await readVaultFileUnlocked(join21(options.store.home, "vault.json"));
|
|
99671
99820
|
} catch (error61) {
|
|
99672
99821
|
if (error61 instanceof VaultError && error61.code === "not_found") {
|
|
99673
99822
|
return { status: "skipped", reason: "no_vault" };
|
|
@@ -99676,7 +99825,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
99676
99825
|
}
|
|
99677
99826
|
try {
|
|
99678
99827
|
vaultKey = vaultFile.protected ? await unlockProtectedVault({
|
|
99679
|
-
path:
|
|
99828
|
+
path: join21(options.store.home, "vault.json"),
|
|
99680
99829
|
secrets: options.secrets,
|
|
99681
99830
|
env: options.env,
|
|
99682
99831
|
...options.now === void 0 ? {} : { now: options.now }
|
|
@@ -100349,7 +100498,7 @@ async function readProcessStdin() {
|
|
|
100349
100498
|
}
|
|
100350
100499
|
|
|
100351
100500
|
// ../cli/src/version.ts
|
|
100352
|
-
var CLI_VERSION = "0.
|
|
100501
|
+
var CLI_VERSION = "0.12.0";
|
|
100353
100502
|
|
|
100354
100503
|
// ../cli/src/status.ts
|
|
100355
100504
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -100851,10 +101000,10 @@ async function accountsRenameCommand(argv, json2, io, dependencies) {
|
|
|
100851
101000
|
{
|
|
100852
101001
|
previous: from16,
|
|
100853
101002
|
...address4 === void 0 ? {} : { address: address4 },
|
|
100854
|
-
vault:
|
|
101003
|
+
vault: join22(store.home, "vault.json"),
|
|
100855
101004
|
message: `Wallet ${from16} is now ${renamed.name}.`
|
|
100856
101005
|
},
|
|
100857
|
-
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${
|
|
101006
|
+
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${join22(store.home, "vault.json")}`].join(
|
|
100858
101007
|
"\n"
|
|
100859
101008
|
)
|
|
100860
101009
|
);
|
|
@@ -100963,13 +101112,13 @@ async function accountsRestoreCommand(argv, json2, io, dependencies) {
|
|
|
100963
101112
|
{ name: restored.name, ...address4 === void 0 ? {} : { address: address4 } },
|
|
100964
101113
|
{
|
|
100965
101114
|
...address4 === void 0 ? {} : { address: address4 },
|
|
100966
|
-
vault:
|
|
101115
|
+
vault: join22(store.home, "vault.json"),
|
|
100967
101116
|
spendCaps: restored.entry.spendCaps,
|
|
100968
101117
|
message: `Wallet ${restored.name} restored to the device vault.`
|
|
100969
101118
|
},
|
|
100970
101119
|
[
|
|
100971
101120
|
`Wallet ${restored.name} restored to the device vault.`,
|
|
100972
|
-
`Vault: ${
|
|
101121
|
+
`Vault: ${join22(store.home, "vault.json")}`
|
|
100973
101122
|
].join("\n")
|
|
100974
101123
|
);
|
|
100975
101124
|
}
|
|
@@ -101299,7 +101448,7 @@ function formatNetworkAccounts(accounts) {
|
|
|
101299
101448
|
}
|
|
101300
101449
|
|
|
101301
101450
|
// ../cli/src/cloud-backup.ts
|
|
101302
|
-
import { join as
|
|
101451
|
+
import { join as join23 } from "node:path";
|
|
101303
101452
|
var CLOUD_BACKUP_USAGE = "Usage: vapi backup --cloud [off] [--json]";
|
|
101304
101453
|
var OWNER_RESTORE_USAGE = "Usage: vapi restore --from-owner [--owner <0x\u2026>] [--json]";
|
|
101305
101454
|
var OWNER_PATTERN2 = /^0x[0-9a-fA-F]{40}$/u;
|
|
@@ -101322,7 +101471,7 @@ async function cloudBackupCommand(argv, json2, io, dependencies) {
|
|
|
101322
101471
|
}
|
|
101323
101472
|
async function enrollCloudBackup(json2, io, dependencies) {
|
|
101324
101473
|
const paths = getVapiPaths();
|
|
101325
|
-
if (!await fileExists2(
|
|
101474
|
+
if (!await fileExists2(join23(paths.directory, "vault.json"))) {
|
|
101326
101475
|
throw new Error("No vault on this device. Run vapi setup first.");
|
|
101327
101476
|
}
|
|
101328
101477
|
const context = await cloudContext(io, dependencies);
|
|
@@ -101434,7 +101583,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
101434
101583
|
}
|
|
101435
101584
|
const expectedOwner = ownerValue?.toLowerCase();
|
|
101436
101585
|
const paths = getVapiPaths();
|
|
101437
|
-
if (await fileExists2(
|
|
101586
|
+
if (await fileExists2(join23(paths.directory, "vault.json")) && !await fileExists2(join23(paths.directory, ".backup-restore.json"))) {
|
|
101438
101587
|
throw new Error(
|
|
101439
101588
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
101440
101589
|
);
|
|
@@ -102532,21 +102681,21 @@ function shortExcerpt(value) {
|
|
|
102532
102681
|
|
|
102533
102682
|
// ../cli/src/agent.ts
|
|
102534
102683
|
import { readFile as readFile27, stat as stat15 } from "node:fs/promises";
|
|
102535
|
-
import { join as
|
|
102684
|
+
import { join as join26 } from "node:path";
|
|
102536
102685
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
102537
102686
|
|
|
102538
102687
|
// ../cli/src/headless.ts
|
|
102539
|
-
import { chmod as chmod7, mkdtemp as mkdtemp2, rm as
|
|
102688
|
+
import { chmod as chmod7, mkdtemp as mkdtemp2, rm as rm5, writeFile as writeFile10 } from "node:fs/promises";
|
|
102540
102689
|
import { rmSync } from "node:fs";
|
|
102541
102690
|
import { tmpdir as osTmpdir } from "node:os";
|
|
102542
|
-
import { join as
|
|
102691
|
+
import { join as join24 } from "node:path";
|
|
102543
102692
|
var BUNDLE_VARIABLE_PATTERN = /^[A-Z_][A-Z0-9_]*$/u;
|
|
102544
102693
|
var REMOTE_BLOCKED_GRANTS2 = /* @__PURE__ */ new Set(["delegate", "allocate"]);
|
|
102545
102694
|
var agentProfileOptions = { schema: registeredAgentProfileSchema };
|
|
102546
102695
|
async function createHeadlessHome(bundle, options = {}) {
|
|
102547
|
-
const home = await mkdtemp2(
|
|
102696
|
+
const home = await mkdtemp2(join24(options.tmpdir ?? osTmpdir(), "vapi-headless-"));
|
|
102548
102697
|
const cleanup = async () => {
|
|
102549
|
-
await
|
|
102698
|
+
await rm5(home, { recursive: true, force: true });
|
|
102550
102699
|
};
|
|
102551
102700
|
try {
|
|
102552
102701
|
await chmod7(home, 448);
|
|
@@ -102693,7 +102842,7 @@ async function runHeadlessAgent(input2) {
|
|
|
102693
102842
|
} finally {
|
|
102694
102843
|
if (previousHome === void 0) delete process.env.VAPI_HOME;
|
|
102695
102844
|
else process.env.VAPI_HOME = previousHome;
|
|
102696
|
-
if (home !== void 0) await
|
|
102845
|
+
if (home !== void 0) await rm5(home, { recursive: true, force: true });
|
|
102697
102846
|
removeSignalHandlers();
|
|
102698
102847
|
}
|
|
102699
102848
|
}
|
|
@@ -102755,7 +102904,7 @@ import {
|
|
|
102755
102904
|
writeFile as nodeWriteFile
|
|
102756
102905
|
} from "node:fs/promises";
|
|
102757
102906
|
import { tmpdir as osTmpdir2 } from "node:os";
|
|
102758
|
-
import { basename as basename4, dirname as dirname13, join as
|
|
102907
|
+
import { basename as basename4, dirname as dirname13, join as join25 } from "node:path";
|
|
102759
102908
|
var RAILWAY_CLI = {
|
|
102760
102909
|
binary: "railway",
|
|
102761
102910
|
create: (options) => [
|
|
@@ -102927,7 +103076,7 @@ async function assertRemoteSafeMember(args) {
|
|
|
102927
103076
|
}
|
|
102928
103077
|
function railwaySidecarPath(home, runId) {
|
|
102929
103078
|
if (!isRunId(runId)) throw new RuntimeError("invalid_run_id", `Invalid run id: ${runId}.`);
|
|
102930
|
-
return
|
|
103079
|
+
return join25(runsDirectory(home), `${runId}.railway.json`);
|
|
102931
103080
|
}
|
|
102932
103081
|
function createRailwayRuntime(options) {
|
|
102933
103082
|
const { home } = options;
|
|
@@ -103252,10 +103401,10 @@ function createRailwayRuntime(options) {
|
|
|
103252
103401
|
let createError;
|
|
103253
103402
|
let cleanupError;
|
|
103254
103403
|
try {
|
|
103255
|
-
directory = await fs.mkdtemp(
|
|
103404
|
+
directory = await fs.mkdtemp(join25(options.tmpdir ?? osTmpdir2(), "vapi-railway-"));
|
|
103256
103405
|
assertNotInterrupted();
|
|
103257
103406
|
await assertMode(fs, directory, 448, "env-file directory");
|
|
103258
|
-
envFile =
|
|
103407
|
+
envFile = join25(directory, "member.env");
|
|
103259
103408
|
await fs.writeFile(envFile, `${RAILWAY_CLI.bundleVariable}=${bundle}
|
|
103260
103409
|
`, {
|
|
103261
103410
|
encoding: "utf8",
|
|
@@ -103574,9 +103723,9 @@ async function reserveRemoteAllowance(args) {
|
|
|
103574
103723
|
const perDayAtomic = BigInt(args.caps.perDayAtomic);
|
|
103575
103724
|
const ledgerPath = getVapiPaths(args.home).ledger;
|
|
103576
103725
|
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 <
|
|
103726
|
+
const remaining2 = spent >= perDayAtomic ? 0n : perDayAtomic - spent;
|
|
103727
|
+
const requested = args.run.budgetUsd === void 0 ? remaining2 : usdToAtomic(args.run.budgetUsd);
|
|
103728
|
+
const reserved = requested < remaining2 ? requested : remaining2;
|
|
103580
103729
|
if (reserved === 0n) {
|
|
103581
103730
|
throw new RemoteKeyRefusedError(
|
|
103582
103731
|
"no_daily_allowance",
|
|
@@ -103710,7 +103859,7 @@ async function writeSidecar(home, runId, sidecar) {
|
|
|
103710
103859
|
function writeSidecarSync(path, sidecar) {
|
|
103711
103860
|
const directory = dirname13(path);
|
|
103712
103861
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
103713
|
-
const temporary =
|
|
103862
|
+
const temporary = join25(
|
|
103714
103863
|
directory,
|
|
103715
103864
|
`.${basename4(path)}.${process.pid}.${randomBytes16(6).toString("hex")}.tmp`
|
|
103716
103865
|
);
|
|
@@ -103808,7 +103957,7 @@ async function assertMode(fs, path, mode, what) {
|
|
|
103808
103957
|
}
|
|
103809
103958
|
}
|
|
103810
103959
|
async function deviceVaultKey(home, secrets, now) {
|
|
103811
|
-
const path =
|
|
103960
|
+
const path = join25(home, "vault.json");
|
|
103812
103961
|
const metadata = await readVaultFileUnlocked(path);
|
|
103813
103962
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
103814
103963
|
path,
|
|
@@ -103858,12 +104007,12 @@ function createLocalRuntime(options) {
|
|
|
103858
104007
|
const { home } = options;
|
|
103859
104008
|
const entry = options.entry ?? realpathSync(process.argv[1]);
|
|
103860
104009
|
const execPath = options.execPath ?? process.execPath;
|
|
103861
|
-
const
|
|
104010
|
+
const spawn6 = options.spawn ?? nodeSpawn;
|
|
103862
104011
|
const kill = options.kill ?? ((pid, signal) => process.kill(pid, signal));
|
|
103863
104012
|
const processCommand = options.processCommand ?? defaultProcessCommand;
|
|
103864
104013
|
const ownsProcess = (handle, pid) => processCommand(pid)?.includes(runResultPath(home, handle.runId)) === true;
|
|
103865
104014
|
const closeFd = options.closeFd ?? closeSync2;
|
|
103866
|
-
const
|
|
104015
|
+
const readFile33 = options.readFile ?? nodeReadFile;
|
|
103867
104016
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
103868
104017
|
const openLog = options.openLog ?? ((path) => {
|
|
103869
104018
|
mkdirSync2(runsDirectory(home), { recursive: true, mode: 448 });
|
|
@@ -103881,7 +104030,7 @@ function createLocalRuntime(options) {
|
|
|
103881
104030
|
const logFd = openLog(logPath);
|
|
103882
104031
|
let child;
|
|
103883
104032
|
try {
|
|
103884
|
-
child =
|
|
104033
|
+
child = spawn6(execPath, [entry, ...args, "--json", "--result-file", resultPath], {
|
|
103885
104034
|
detached: true,
|
|
103886
104035
|
stdio: ["ignore", logFd, logFd],
|
|
103887
104036
|
env: {
|
|
@@ -103918,7 +104067,7 @@ function createLocalRuntime(options) {
|
|
|
103918
104067
|
return handle;
|
|
103919
104068
|
},
|
|
103920
104069
|
async status(handle) {
|
|
103921
|
-
const result = await readResultFile(
|
|
104070
|
+
const result = await readResultFile(readFile33, runResultPath(home, handle.runId));
|
|
103922
104071
|
if (result !== void 0) return result;
|
|
103923
104072
|
const pid = localPid(handle);
|
|
103924
104073
|
if (pid === void 0 || handle.kind !== "local") {
|
|
@@ -104021,10 +104170,10 @@ function childArguments(member, run) {
|
|
|
104021
104170
|
...run.drawUsd ? ["--draw", run.drawUsd] : []
|
|
104022
104171
|
];
|
|
104023
104172
|
}
|
|
104024
|
-
async function readResultFile(
|
|
104173
|
+
async function readResultFile(readFile33, path) {
|
|
104025
104174
|
let text;
|
|
104026
104175
|
try {
|
|
104027
|
-
text = await
|
|
104176
|
+
text = await readFile33(path, "utf8");
|
|
104028
104177
|
} catch (error61) {
|
|
104029
104178
|
if (hasCode3(error61, "ENOENT")) return void 0;
|
|
104030
104179
|
return { state: "failed", detail: "unreadable result file" };
|
|
@@ -104735,7 +104884,7 @@ function explicitWallet(name) {
|
|
|
104735
104884
|
}
|
|
104736
104885
|
async function profileFileExists(directory, name) {
|
|
104737
104886
|
try {
|
|
104738
|
-
await stat15(
|
|
104887
|
+
await stat15(join26(directory, `${name}.json`));
|
|
104739
104888
|
return true;
|
|
104740
104889
|
} catch (error61) {
|
|
104741
104890
|
if (isMissingFile(error61)) return false;
|
|
@@ -104799,6 +104948,80 @@ import { spawn as spawn3 } from "node:child_process";
|
|
|
104799
104948
|
import { mkdir as mkdir20, readFile as readFile28, writeFile as writeFile11 } from "node:fs/promises";
|
|
104800
104949
|
import { homedir as systemHomedir } from "node:os";
|
|
104801
104950
|
import { dirname as dirname14, posix, win32 as win322 } from "node:path";
|
|
104951
|
+
|
|
104952
|
+
// ../cli/src/toml-config.ts
|
|
104953
|
+
function removeTomlTables(contents, isTarget) {
|
|
104954
|
+
let removing = false;
|
|
104955
|
+
let retained = "";
|
|
104956
|
+
for (const { line, table } of tomlLines(contents)) {
|
|
104957
|
+
if (table !== void 0) removing = isTarget(tomlKeyPath(table));
|
|
104958
|
+
if (!removing) retained += line;
|
|
104959
|
+
}
|
|
104960
|
+
return retained;
|
|
104961
|
+
}
|
|
104962
|
+
function* tomlLines(contents) {
|
|
104963
|
+
let multiline;
|
|
104964
|
+
for (const line of contents.match(/[^\n]*\n|[^\n]+$/g) ?? []) {
|
|
104965
|
+
yield { line, table: multiline === void 0 ? tomlTableName(line) : void 0 };
|
|
104966
|
+
for (let index2 = 0; index2 < line.length; index2 += 1) {
|
|
104967
|
+
const char = line[index2];
|
|
104968
|
+
if (multiline !== void 0) {
|
|
104969
|
+
if (multiline === '"""' && char === "\\") {
|
|
104970
|
+
index2 += 1;
|
|
104971
|
+
continue;
|
|
104972
|
+
}
|
|
104973
|
+
if (line.startsWith(multiline, index2)) {
|
|
104974
|
+
index2 += 2;
|
|
104975
|
+
multiline = void 0;
|
|
104976
|
+
}
|
|
104977
|
+
} else {
|
|
104978
|
+
if (char === "#") break;
|
|
104979
|
+
if (char !== "'" && char !== '"') continue;
|
|
104980
|
+
const delimiter2 = char.repeat(3);
|
|
104981
|
+
if (line.startsWith(delimiter2, index2)) {
|
|
104982
|
+
multiline = delimiter2;
|
|
104983
|
+
index2 += 2;
|
|
104984
|
+
} else {
|
|
104985
|
+
for (index2 += 1; index2 < line.length; index2 += 1) {
|
|
104986
|
+
if (char === '"' && line[index2] === "\\") index2 += 1;
|
|
104987
|
+
else if (line[index2] === char) break;
|
|
104988
|
+
}
|
|
104989
|
+
}
|
|
104990
|
+
}
|
|
104991
|
+
}
|
|
104992
|
+
}
|
|
104993
|
+
}
|
|
104994
|
+
function tomlKeyPath(table) {
|
|
104995
|
+
const key2 = String.raw`(?:[A-Za-z0-9_-]+|"(?:[^"\\]|\\.)*"|'[^']*')`;
|
|
104996
|
+
const pattern = new RegExp(`^\\s*(${key2})(?:\\s*\\.\\s*(${key2}))*\\s*$`);
|
|
104997
|
+
if (!pattern.test(table)) return [];
|
|
104998
|
+
return [...table.matchAll(new RegExp(key2, "g"))].map(([part]) => unquoteTomlKey(part));
|
|
104999
|
+
}
|
|
105000
|
+
function tomlTableName(line) {
|
|
105001
|
+
const header = line.replace(/\r?\n$/, "");
|
|
105002
|
+
const match = /^\s*(?:\[\[\s*(.*?)\s*\]\]|\[\s*(.*?)\s*\])\s*(?:#.*)?$/.exec(header);
|
|
105003
|
+
return match?.[1] ?? match?.[2];
|
|
105004
|
+
}
|
|
105005
|
+
function unquoteTomlKey(key2) {
|
|
105006
|
+
if (key2.startsWith("'") && key2.endsWith("'")) return key2.slice(1, -1);
|
|
105007
|
+
if (key2.startsWith('"') && key2.endsWith('"')) {
|
|
105008
|
+
try {
|
|
105009
|
+
return JSON.parse(key2);
|
|
105010
|
+
} catch {
|
|
105011
|
+
return key2;
|
|
105012
|
+
}
|
|
105013
|
+
}
|
|
105014
|
+
return key2;
|
|
105015
|
+
}
|
|
105016
|
+
function tomlSeparator(contents) {
|
|
105017
|
+
if (contents.length === 0 || /(?:\r?\n)[ \t]*(?:\r?\n)$/.test(contents)) return "";
|
|
105018
|
+
return /\r?\n$/.test(contents) ? "\n" : "\n\n";
|
|
105019
|
+
}
|
|
105020
|
+
function escapeToml(value) {
|
|
105021
|
+
return JSON.stringify(value).slice(1, -1);
|
|
105022
|
+
}
|
|
105023
|
+
|
|
105024
|
+
// ../cli/src/mcp-install.ts
|
|
104802
105025
|
var MCP_INSTALL_USAGE = "Usage: vapi mcp install <claude-code|claude-desktop|cursor|codex> [--home <dir>] [--registry <url>] [--no-link] [--json]";
|
|
104803
105026
|
var APPS = /* @__PURE__ */ new Set(["claude-code", "claude-desktop", "cursor", "codex"]);
|
|
104804
105027
|
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 +105307,10 @@ function jsonConfig(path, existing, entry) {
|
|
|
105084
105307
|
`;
|
|
105085
105308
|
}
|
|
105086
105309
|
function tomlConfig(existing, entry) {
|
|
105087
|
-
const retained =
|
|
105310
|
+
const retained = removeTomlTables(
|
|
105311
|
+
existing,
|
|
105312
|
+
([root, name]) => root === "mcp_servers" && name === "vapi"
|
|
105313
|
+
);
|
|
105088
105314
|
const block = [
|
|
105089
105315
|
"[mcp_servers.vapi]",
|
|
105090
105316
|
'command = "npx"',
|
|
@@ -105094,46 +105320,6 @@ function tomlConfig(existing, entry) {
|
|
|
105094
105320
|
].join("\n");
|
|
105095
105321
|
return `${retained}${tomlSeparator(retained)}${block}`;
|
|
105096
105322
|
}
|
|
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
105323
|
function isRecord12(value) {
|
|
105138
105324
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
105139
105325
|
}
|
|
@@ -105155,6 +105341,546 @@ async function pathExists5(path) {
|
|
|
105155
105341
|
}
|
|
105156
105342
|
}
|
|
105157
105343
|
|
|
105344
|
+
// ../cli/src/code.ts
|
|
105345
|
+
import { constants as constants2 } from "node:fs";
|
|
105346
|
+
import { access, mkdir as mkdir21, readFile as readFile29, realpath, unlink as unlink13, writeFile as writeFile12 } from "node:fs/promises";
|
|
105347
|
+
import { homedir as homedir3 } from "node:os";
|
|
105348
|
+
import { basename as basename5, dirname as dirname15, join as join27, posix as posix2, win32 as win323 } from "node:path";
|
|
105349
|
+
var VAPI_CODEX_PROVIDER = "vapi";
|
|
105350
|
+
var VAPI_CODEX_PROFILE = "vapi";
|
|
105351
|
+
var VAPI_CODEX_DEFAULT_MODEL = "venice/openai-gpt-61-sol";
|
|
105352
|
+
var VAPI_ROUTER_KEY_ENV = "VAPI_ROUTER_KEY";
|
|
105353
|
+
function codexConfigPath(env, home) {
|
|
105354
|
+
return join27(env.CODEX_HOME || join27(home, ".codex"), "config.toml");
|
|
105355
|
+
}
|
|
105356
|
+
function hasVapiCodexProfile(contents) {
|
|
105357
|
+
const roots = new Set(
|
|
105358
|
+
[...tomlLines(contents)].flatMap(({ table }) => {
|
|
105359
|
+
const path = table === void 0 ? [] : tomlKeyPath(table);
|
|
105360
|
+
return path.length === 2 && path[1] === "vapi" ? [path[0]] : [];
|
|
105361
|
+
})
|
|
105362
|
+
);
|
|
105363
|
+
return roots.has("model_providers") && roots.has("profiles");
|
|
105364
|
+
}
|
|
105365
|
+
async function resolveBinary(name, options) {
|
|
105366
|
+
const windows = (options.platform ?? process.platform) === "win32";
|
|
105367
|
+
const path = options.env.PATH ?? (windows ? Object.entries(options.env).find(([key2]) => key2.toLowerCase() === "path")?.[1] : void 0);
|
|
105368
|
+
if (path === void 0) return void 0;
|
|
105369
|
+
const paths = windows ? win323 : posix2;
|
|
105370
|
+
const canonical = options.realpath ?? realpath;
|
|
105371
|
+
const executable = options.isExecutable ?? (async (candidate) => {
|
|
105372
|
+
try {
|
|
105373
|
+
await access(candidate, constants2.X_OK);
|
|
105374
|
+
return true;
|
|
105375
|
+
} catch (error61) {
|
|
105376
|
+
if (isMissingFile(error61) || error61.code === "EACCES")
|
|
105377
|
+
return false;
|
|
105378
|
+
throw error61;
|
|
105379
|
+
}
|
|
105380
|
+
});
|
|
105381
|
+
const self = options.selfPath ?? process.argv[1];
|
|
105382
|
+
const selfReal = self === void 0 ? void 0 : await canonical(self);
|
|
105383
|
+
const extensions = windows ? ["", ...(options.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";")] : [""];
|
|
105384
|
+
for (const directory of path.split(windows ? ";" : ":")) {
|
|
105385
|
+
for (const extension of extensions) {
|
|
105386
|
+
const candidate = paths.resolve(directory.replace(/^"|"$/gu, ""), `${name}${extension}`);
|
|
105387
|
+
if (!await executable(candidate)) continue;
|
|
105388
|
+
const resolved = await canonical(candidate);
|
|
105389
|
+
if (selfReal !== void 0 && (windows ? resolved.toLowerCase() === selfReal.toLowerCase() : resolved === selfReal))
|
|
105390
|
+
continue;
|
|
105391
|
+
return candidate;
|
|
105392
|
+
}
|
|
105393
|
+
}
|
|
105394
|
+
return void 0;
|
|
105395
|
+
}
|
|
105396
|
+
var RC_START = "# >>> vapi code >>>";
|
|
105397
|
+
var RC_END = "# <<< vapi code <<<";
|
|
105398
|
+
var CONFIG_END = "# <<< vapi code config <<<\n";
|
|
105399
|
+
var isCodeTable = ([root, name]) => name === "vapi" && (root === "model_providers" || root === "profiles");
|
|
105400
|
+
function cleanConfig(contents) {
|
|
105401
|
+
let created = false;
|
|
105402
|
+
const cleaned = contents.replace(
|
|
105403
|
+
/(\n?)\[model_providers\.vapi\]\n# >>> vapi code config (created|existing) (0|1) >>>\n([\s\S]*?)# <<< vapi code config <<<\n/gu,
|
|
105404
|
+
(_, prefix, kind, separator, body) => {
|
|
105405
|
+
created ||= kind === "created";
|
|
105406
|
+
return (separator === "1" ? "" : prefix) + removeTomlTables(`[model_providers.vapi]
|
|
105407
|
+
${body}`, isCodeTable);
|
|
105408
|
+
}
|
|
105409
|
+
);
|
|
105410
|
+
return { contents: removeTomlTables(cleaned, isCodeTable), created };
|
|
105411
|
+
}
|
|
105412
|
+
function configContents(existing, baseURL) {
|
|
105413
|
+
const clean2 = cleanConfig(existing ?? "");
|
|
105414
|
+
const retained = clean2.contents;
|
|
105415
|
+
const separator = retained.length > 0 && !retained.endsWith("\n") ? "\n" : "";
|
|
105416
|
+
return `${retained}${separator}[model_providers.vapi]
|
|
105417
|
+
# >>> vapi code config ${existing === void 0 || clean2.created ? "created" : "existing"} ${separator.length} >>>
|
|
105418
|
+
` + [
|
|
105419
|
+
'name = "vAPI Router"',
|
|
105420
|
+
`base_url = "${escapeToml(baseURL)}"`,
|
|
105421
|
+
`env_key = "${VAPI_ROUTER_KEY_ENV}"`,
|
|
105422
|
+
'wire_api = "responses"',
|
|
105423
|
+
"",
|
|
105424
|
+
"[profiles.vapi]",
|
|
105425
|
+
`model_provider = "${VAPI_CODEX_PROVIDER}"`,
|
|
105426
|
+
`model = "${VAPI_CODEX_DEFAULT_MODEL}"`,
|
|
105427
|
+
""
|
|
105428
|
+
].join("\n") + CONFIG_END;
|
|
105429
|
+
}
|
|
105430
|
+
function removeAliases(contents) {
|
|
105431
|
+
return contents.replace(
|
|
105432
|
+
/(^|\n)# >>> vapi code >>>\r?\n[\s\S]*?^# <<< vapi code <<<(\r?\n|$)/gmu,
|
|
105433
|
+
(_, prefix, suffix) => suffix === "" ? "" : prefix
|
|
105434
|
+
);
|
|
105435
|
+
}
|
|
105436
|
+
function aliasContents(original, tools) {
|
|
105437
|
+
const existing = original ?? "";
|
|
105438
|
+
const block = [RC_START, ...tools.map((tool) => `alias ${tool}="vapi ${tool}"`), RC_END].join(
|
|
105439
|
+
"\n"
|
|
105440
|
+
);
|
|
105441
|
+
const match = /^# >>> vapi code >>>\r?\n[\s\S]*?^# <<< vapi code <<</gmu;
|
|
105442
|
+
if (match.test(existing)) return existing.replace(match, block);
|
|
105443
|
+
const separator = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
105444
|
+
return `${existing}${separator}${block}${original === "" || existing.endsWith("\n") ? "\n" : ""}`;
|
|
105445
|
+
}
|
|
105446
|
+
async function readOptional(path) {
|
|
105447
|
+
try {
|
|
105448
|
+
return await readFile29(path, "utf8");
|
|
105449
|
+
} catch (error61) {
|
|
105450
|
+
if (isMissingFile(error61)) return void 0;
|
|
105451
|
+
throw error61;
|
|
105452
|
+
}
|
|
105453
|
+
}
|
|
105454
|
+
async function writeConfig(path, contents) {
|
|
105455
|
+
await mkdir21(dirname15(path), { recursive: true });
|
|
105456
|
+
await writeFile12(path, contents);
|
|
105457
|
+
}
|
|
105458
|
+
async function codeCommand(argv, json2, io, dependencies) {
|
|
105459
|
+
const command = argv[0];
|
|
105460
|
+
if (command !== "install" && command !== "uninstall")
|
|
105461
|
+
throw new UsageError("Usage: vapi code <install|uninstall>.");
|
|
105462
|
+
const parsed = parseArguments(argv.slice(1), {
|
|
105463
|
+
valueOptions: new Set(command === "install" ? ["--wallet"] : []),
|
|
105464
|
+
booleanOptions: new Set(command === "install" ? ["--yes", "--no-alias"] : []),
|
|
105465
|
+
maximumPositionals: 0
|
|
105466
|
+
});
|
|
105467
|
+
const env = getEnvironment(dependencies);
|
|
105468
|
+
const home = dependencies.code?.homedir ?? homedir3();
|
|
105469
|
+
const config2 = codexConfigPath(env, home);
|
|
105470
|
+
const rcPaths = [join27(home, ".zshrc"), join27(home, ".bashrc")];
|
|
105471
|
+
if (command === "uninstall") {
|
|
105472
|
+
const removed = [];
|
|
105473
|
+
const previous = await readOptional(config2);
|
|
105474
|
+
if (previous !== void 0) {
|
|
105475
|
+
const clean2 = cleanConfig(previous);
|
|
105476
|
+
if (clean2.contents !== previous) {
|
|
105477
|
+
if (clean2.contents === "" && clean2.created) await unlink13(config2);
|
|
105478
|
+
else await writeFile12(config2, clean2.contents);
|
|
105479
|
+
removed.push(config2);
|
|
105480
|
+
}
|
|
105481
|
+
}
|
|
105482
|
+
for (const path of rcPaths) {
|
|
105483
|
+
const previous2 = await readOptional(path);
|
|
105484
|
+
if (previous2 === void 0) continue;
|
|
105485
|
+
const clean2 = removeAliases(previous2);
|
|
105486
|
+
if (clean2 !== previous2) {
|
|
105487
|
+
if (clean2 === "" && previous2.startsWith(RC_START) && !previous2.endsWith("\n"))
|
|
105488
|
+
await unlink13(path);
|
|
105489
|
+
else await writeFile12(path, clean2);
|
|
105490
|
+
removed.push(path);
|
|
105491
|
+
}
|
|
105492
|
+
}
|
|
105493
|
+
io.stdout(
|
|
105494
|
+
json2 ? JSON.stringify({ command: "code uninstall", removed }) : removed.length === 0 ? "Nothing to remove." : `Removed vAPI code settings from: ${removed.join(", ")}`
|
|
105495
|
+
);
|
|
105496
|
+
return 0;
|
|
105497
|
+
}
|
|
105498
|
+
const tools = [];
|
|
105499
|
+
const skipped2 = [];
|
|
105500
|
+
for (const name of ["claude", "codex"]) {
|
|
105501
|
+
const binary = await resolveBinary(name, { ...dependencies.code, env });
|
|
105502
|
+
if (binary === void 0)
|
|
105503
|
+
skipped2.push(
|
|
105504
|
+
`Skipped ${name === "claude" ? "Claude Code" : "Codex"}: \`${name}\` is not on PATH.`
|
|
105505
|
+
);
|
|
105506
|
+
else tools.push(name);
|
|
105507
|
+
}
|
|
105508
|
+
if (tools.length === 0) {
|
|
105509
|
+
const message = "Neither claude nor codex is on PATH; nothing was installed.";
|
|
105510
|
+
if (json2) io.stdout(JSON.stringify({ installed: [], skipped: skipped2, error: message }));
|
|
105511
|
+
else {
|
|
105512
|
+
skipped2.forEach(io.stderr);
|
|
105513
|
+
io.stderr(message);
|
|
105514
|
+
}
|
|
105515
|
+
return 1;
|
|
105516
|
+
}
|
|
105517
|
+
let target = await targetWallet(parsed, dependencies);
|
|
105518
|
+
const credentials = dependencies.router?.routerCredentials ?? routerCredentials;
|
|
105519
|
+
let linked = false;
|
|
105520
|
+
let rotated = false;
|
|
105521
|
+
let result;
|
|
105522
|
+
for (; ; ) {
|
|
105523
|
+
try {
|
|
105524
|
+
result = await credentials(routerDeps2(target, dependencies));
|
|
105525
|
+
break;
|
|
105526
|
+
} catch (error61) {
|
|
105527
|
+
if (error61 instanceof RouterClientError && error61.code === "not_linked" && !linked) {
|
|
105528
|
+
linked = true;
|
|
105529
|
+
const account = parsed.one("--wallet");
|
|
105530
|
+
await (dependencies.code?.login ?? runLoginFlow)(
|
|
105531
|
+
account === void 0 ? [] : ["--account", account],
|
|
105532
|
+
json2,
|
|
105533
|
+
{ ...io, stdout: io.stderr },
|
|
105534
|
+
json2 ? { ...dependencies, interactive: false, stdinIsTTY: false } : dependencies
|
|
105535
|
+
);
|
|
105536
|
+
target = await targetWallet(parsed, dependencies);
|
|
105537
|
+
} else if (error61 instanceof RouterClientError && error61.code === "no_router_key" && !rotated) {
|
|
105538
|
+
rotated = true;
|
|
105539
|
+
await (dependencies.router?.rotateRouterKey ?? rotateRouterKey)(
|
|
105540
|
+
routerDeps2(target, dependencies)
|
|
105541
|
+
);
|
|
105542
|
+
} else throw error61;
|
|
105543
|
+
}
|
|
105544
|
+
}
|
|
105545
|
+
const installed = [];
|
|
105546
|
+
if (tools.includes("claude")) installed.push("Claude Code: ready, launch with `vapi claude`");
|
|
105547
|
+
if (tools.includes("codex")) {
|
|
105548
|
+
await writeConfig(config2, configContents(await readOptional(config2), result.baseURL));
|
|
105549
|
+
installed.push(`Codex: installed ${config2}`);
|
|
105550
|
+
}
|
|
105551
|
+
let alias = "Aliases: skipped.";
|
|
105552
|
+
if (!parsed.has("--no-alias")) {
|
|
105553
|
+
if ((dependencies.code?.platform ?? process.platform) === "win32")
|
|
105554
|
+
alias = "Aliases: skipped on Windows.";
|
|
105555
|
+
else {
|
|
105556
|
+
const yes = parsed.has("--yes") || !json2 && isInteractive(dependencies) && isStdinInteractive(dependencies) && /^y(?:es)?$/iu.test(
|
|
105557
|
+
(await getLinePrompt(dependencies)(
|
|
105558
|
+
"Make `claude` and `codex` use your vAPI Compute first from now on? [y/N] "
|
|
105559
|
+
)).trim()
|
|
105560
|
+
);
|
|
105561
|
+
if (yes) {
|
|
105562
|
+
const shell = basename5(env.SHELL ?? "");
|
|
105563
|
+
const rc = shell === "zsh" ? rcPaths[0] : shell === "bash" ? rcPaths[1] : await readOptional(rcPaths[0]) !== void 0 ? rcPaths[0] : rcPaths[1];
|
|
105564
|
+
await writeConfig(rc, aliasContents(await readOptional(rc), tools));
|
|
105565
|
+
alias = `Aliases: installed in ${rc}. Open a new terminal or run: source ${rc}`;
|
|
105566
|
+
}
|
|
105567
|
+
}
|
|
105568
|
+
}
|
|
105569
|
+
let compute;
|
|
105570
|
+
try {
|
|
105571
|
+
const usage = await (dependencies.router?.routerUsage ?? routerUsage)(
|
|
105572
|
+
routerDeps2(target, dependencies)
|
|
105573
|
+
);
|
|
105574
|
+
const reset = new Date(usage.compute.resetsAt);
|
|
105575
|
+
if (!Number.isFinite(reset.getTime())) throw new Error("invalid reset time");
|
|
105576
|
+
compute = `$${usage.compute.remainingTodayUsd.toFixed(2)} left today (resets ${reset.toISOString().slice(11, 16)} UTC)`;
|
|
105577
|
+
} catch (error61) {
|
|
105578
|
+
compute = `Compute today: unavailable (${error61 instanceof RouterClientError ? error61.code : "request failed"})`;
|
|
105579
|
+
}
|
|
105580
|
+
const start = `Start with \`vapi ${tools.includes("claude") ? "claude" : "codex"}\``;
|
|
105581
|
+
if (json2)
|
|
105582
|
+
io.stdout(
|
|
105583
|
+
JSON.stringify({ command: "code install", installed, skipped: skipped2, alias, compute, start })
|
|
105584
|
+
);
|
|
105585
|
+
else {
|
|
105586
|
+
skipped2.forEach(io.stderr);
|
|
105587
|
+
[...installed, alias, compute, start].forEach(io.stdout);
|
|
105588
|
+
}
|
|
105589
|
+
return 0;
|
|
105590
|
+
}
|
|
105591
|
+
|
|
105592
|
+
// ../cli/src/code-launch.ts
|
|
105593
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
105594
|
+
import { readFile as readFile30 } from "node:fs/promises";
|
|
105595
|
+
import { constants as constants3, homedir as homedir4 } from "node:os";
|
|
105596
|
+
var CLAUDE_MODELS = {
|
|
105597
|
+
sonnet: "venice/claude-sonnet-5-5",
|
|
105598
|
+
opus: "venice/claude-opus-5-5",
|
|
105599
|
+
haiku: "venice/claude-haiku-5-5"
|
|
105600
|
+
};
|
|
105601
|
+
async function claudeCommand(argv, json2, io, dependencies) {
|
|
105602
|
+
return await launch("claude", argv, json2, io, dependencies);
|
|
105603
|
+
}
|
|
105604
|
+
async function codexCommand(argv, json2, io, dependencies) {
|
|
105605
|
+
return await launch("codex", argv, json2, io, dependencies);
|
|
105606
|
+
}
|
|
105607
|
+
function parseLaunch(argv) {
|
|
105608
|
+
const result = { own: false, vapi: false, balance: false, forwarded: [] };
|
|
105609
|
+
for (let index2 = 0; index2 < argv.length; index2 += 1) {
|
|
105610
|
+
const arg = argv[index2];
|
|
105611
|
+
if (arg === "--") {
|
|
105612
|
+
result.forwarded.push(...argv.slice(index2 + 1));
|
|
105613
|
+
break;
|
|
105614
|
+
}
|
|
105615
|
+
if (arg === "--own") result.own = true;
|
|
105616
|
+
else if (arg === "--vapi") result.vapi = true;
|
|
105617
|
+
else if (arg === "--use-balance") result.balance = true;
|
|
105618
|
+
else if (arg === "--model" || arg === "--account") {
|
|
105619
|
+
const value = argv[++index2];
|
|
105620
|
+
if (!value || value.startsWith("--")) throw new UsageError(`Expected ${arg} <value>.`);
|
|
105621
|
+
if (arg === "--model") result.model = value;
|
|
105622
|
+
else result.account = value;
|
|
105623
|
+
} else result.forwarded.push(arg);
|
|
105624
|
+
}
|
|
105625
|
+
if (result.own && result.vapi) throw new UsageError("--vapi and --own cannot be used together.");
|
|
105626
|
+
return result;
|
|
105627
|
+
}
|
|
105628
|
+
var LaunchTimeout = class extends Error {
|
|
105629
|
+
constructor() {
|
|
105630
|
+
super("timed out");
|
|
105631
|
+
}
|
|
105632
|
+
};
|
|
105633
|
+
async function bounded(operation, milliseconds) {
|
|
105634
|
+
const controller = new AbortController();
|
|
105635
|
+
let timer;
|
|
105636
|
+
try {
|
|
105637
|
+
return await Promise.race([
|
|
105638
|
+
new Promise((_resolve, reject) => {
|
|
105639
|
+
timer = setTimeout(() => {
|
|
105640
|
+
const error61 = new LaunchTimeout();
|
|
105641
|
+
controller.abort(error61);
|
|
105642
|
+
reject(error61);
|
|
105643
|
+
}, milliseconds);
|
|
105644
|
+
}),
|
|
105645
|
+
operation(controller.signal)
|
|
105646
|
+
]);
|
|
105647
|
+
} finally {
|
|
105648
|
+
clearTimeout(timer);
|
|
105649
|
+
controller.abort();
|
|
105650
|
+
}
|
|
105651
|
+
}
|
|
105652
|
+
function abortableDeps(deps, signal) {
|
|
105653
|
+
const fetchImpl = deps.fetchImpl ?? createPublicFetch({ allowPrivateNetwork: false });
|
|
105654
|
+
return {
|
|
105655
|
+
...deps,
|
|
105656
|
+
fetchImpl: (input2, init) => fetchImpl(input2, {
|
|
105657
|
+
...init,
|
|
105658
|
+
signal: init?.signal ? AbortSignal.any([signal, init.signal]) : signal
|
|
105659
|
+
})
|
|
105660
|
+
};
|
|
105661
|
+
}
|
|
105662
|
+
function shortReason(error61, env, credentials) {
|
|
105663
|
+
if (error61 instanceof RouterClientError) {
|
|
105664
|
+
if (error61.code === "not_linked") return "not linked, run vapi code install";
|
|
105665
|
+
if (error61.code === "no_router_key") return "no Router key, run vapi code install";
|
|
105666
|
+
}
|
|
105667
|
+
let message = error61 instanceof Error ? error61.message : String(error61);
|
|
105668
|
+
for (const secret of [
|
|
105669
|
+
credentials?.apiKey,
|
|
105670
|
+
env.ANTHROPIC_API_KEY,
|
|
105671
|
+
env.ANTHROPIC_AUTH_TOKEN,
|
|
105672
|
+
env[VAPI_ROUTER_KEY_ENV]
|
|
105673
|
+
]) {
|
|
105674
|
+
if (secret) message = message.replaceAll(secret, "[redacted]");
|
|
105675
|
+
}
|
|
105676
|
+
return message.replace(/\s+/gu, " ").trim().slice(0, 160) || "request failed";
|
|
105677
|
+
}
|
|
105678
|
+
async function chooseRoute(options, env, dependencies) {
|
|
105679
|
+
if (options.own) return { kind: "own" };
|
|
105680
|
+
const timeout = dependencies.code?.usageTimeoutMs ?? 4e3;
|
|
105681
|
+
let credentials;
|
|
105682
|
+
let deps;
|
|
105683
|
+
let balanceKeyRequired = false;
|
|
105684
|
+
try {
|
|
105685
|
+
credentials = await bounded(async (signal) => {
|
|
105686
|
+
const target = await targetWallet(
|
|
105687
|
+
{ one: (name) => name === "--wallet" ? options.account : void 0 },
|
|
105688
|
+
dependencies,
|
|
105689
|
+
env.VAPI_HOME
|
|
105690
|
+
);
|
|
105691
|
+
signal.throwIfAborted();
|
|
105692
|
+
deps = routerDeps2(target, dependencies);
|
|
105693
|
+
return await (dependencies.router?.routerCredentials ?? routerCredentials)(
|
|
105694
|
+
abortableDeps(deps, signal)
|
|
105695
|
+
);
|
|
105696
|
+
}, timeout);
|
|
105697
|
+
let usage;
|
|
105698
|
+
try {
|
|
105699
|
+
usage = await bounded(
|
|
105700
|
+
(signal) => (dependencies.router?.routerUsage ?? routerUsage)(abortableDeps(deps, signal)),
|
|
105701
|
+
timeout
|
|
105702
|
+
);
|
|
105703
|
+
if (!Number.isFinite(new Date(usage.compute.resetsAt).getTime()))
|
|
105704
|
+
throw new Error("invalid Compute reset time");
|
|
105705
|
+
} catch (error61) {
|
|
105706
|
+
if (options.vapi) return { kind: "vapi", credentials };
|
|
105707
|
+
throw error61;
|
|
105708
|
+
}
|
|
105709
|
+
if (options.vapi || remaining(usage, options.balance) >= 0.5) {
|
|
105710
|
+
if (options.balance && usage.compute.remainingTodayUsd < 0.5 && (usage.balance?.remainingUsd ?? 0) > 0) {
|
|
105711
|
+
balanceKeyRequired = true;
|
|
105712
|
+
credentials = await bounded(
|
|
105713
|
+
(signal) => (dependencies.router?.routerCredentials ?? routerCredentials)(
|
|
105714
|
+
abortableDeps(deps, signal),
|
|
105715
|
+
{ funding: "balance" }
|
|
105716
|
+
),
|
|
105717
|
+
timeout
|
|
105718
|
+
);
|
|
105719
|
+
}
|
|
105720
|
+
return { kind: "vapi", credentials, usage };
|
|
105721
|
+
}
|
|
105722
|
+
return { kind: "own", exhausted: true };
|
|
105723
|
+
} catch (error61) {
|
|
105724
|
+
const reason = balanceKeyRequired && error61 instanceof RouterClientError && error61.code === "no_router_key" ? "no Router balance key is stored" : shortReason(error61, env, credentials);
|
|
105725
|
+
if (options.vapi) return { kind: "unavailable", reason };
|
|
105726
|
+
return { kind: "own", reason };
|
|
105727
|
+
}
|
|
105728
|
+
}
|
|
105729
|
+
function remaining(usage, useBalance) {
|
|
105730
|
+
return usage.compute.remainingTodayUsd + (useBalance ? usage.balance?.remainingUsd ?? 0 : 0);
|
|
105731
|
+
}
|
|
105732
|
+
async function launch(tool, argv, json2, io, dependencies) {
|
|
105733
|
+
if (json2) throw new UsageError(`vapi ${tool} is interactive and does not support --json.`);
|
|
105734
|
+
const options = parseLaunch(argv);
|
|
105735
|
+
const env = getEnvironment(dependencies);
|
|
105736
|
+
let binary;
|
|
105737
|
+
try {
|
|
105738
|
+
binary = await resolveBinary(tool, { ...dependencies.code, env });
|
|
105739
|
+
} catch (error61) {
|
|
105740
|
+
io.stderr(shortReason(error61, env));
|
|
105741
|
+
return 127;
|
|
105742
|
+
}
|
|
105743
|
+
if (binary === void 0) {
|
|
105744
|
+
io.stderr(
|
|
105745
|
+
`\`${tool}\` is not on PATH. Install ${tool === "claude" ? "Claude Code" : "Codex"} first.`
|
|
105746
|
+
);
|
|
105747
|
+
return 127;
|
|
105748
|
+
}
|
|
105749
|
+
const route = await chooseRoute(options, env, dependencies);
|
|
105750
|
+
if (route.kind === "unavailable") {
|
|
105751
|
+
io.stderr(route.reason);
|
|
105752
|
+
return 1;
|
|
105753
|
+
}
|
|
105754
|
+
let args = options.forwarded;
|
|
105755
|
+
let childEnv = env;
|
|
105756
|
+
const own2 = tool === "claude" ? "your own Claude subscription" : "your own Codex/ChatGPT login";
|
|
105757
|
+
if (route.kind === "own") {
|
|
105758
|
+
if (route.exhausted) io.stderr(`\u25CF Compute used up today \u2192 ${own2}`);
|
|
105759
|
+
else if (route.reason !== void 0) io.stderr(`\u25CF vAPI unreachable (${route.reason}) \u2192 ${own2}`);
|
|
105760
|
+
if (options.model !== void 0)
|
|
105761
|
+
args = [tool === "claude" ? "--model" : "-m", options.model, ...args];
|
|
105762
|
+
} else {
|
|
105763
|
+
const { credentials, usage } = route;
|
|
105764
|
+
const model = tool === "claude" ? claudeModel(options.model) : options.model ?? VAPI_CODEX_DEFAULT_MODEL;
|
|
105765
|
+
let status = "\u25CF vAPI Compute";
|
|
105766
|
+
if (usage !== void 0)
|
|
105767
|
+
status += ` \u2014 $${remaining(usage, options.balance).toFixed(2)} left today (resets ${new Date(usage.compute.resetsAt).toISOString().slice(11, 16)} UTC)`;
|
|
105768
|
+
io.stderr(`${status} \xB7 model ${model.slice(model.lastIndexOf("/") + 1)}`);
|
|
105769
|
+
io.stderr(
|
|
105770
|
+
tool === "claude" ? " Compute runs out mid-session? /exit, then: vapi claude --continue" : " Compute runs out mid-session? /quit, then: vapi codex resume --last"
|
|
105771
|
+
);
|
|
105772
|
+
if (tool === "claude") {
|
|
105773
|
+
childEnv = {
|
|
105774
|
+
...env,
|
|
105775
|
+
ANTHROPIC_BASE_URL: credentials.baseURL.replace(/\/v1\/?$/u, ""),
|
|
105776
|
+
ANTHROPIC_AUTH_TOKEN: credentials.apiKey
|
|
105777
|
+
};
|
|
105778
|
+
delete childEnv.ANTHROPIC_API_KEY;
|
|
105779
|
+
if (args.some((arg) => arg === "--settings" || arg.startsWith("--settings=")))
|
|
105780
|
+
io.stderr("\u25CF Your --settings is passed as is; vAPI model settings were not added.");
|
|
105781
|
+
else
|
|
105782
|
+
args = [
|
|
105783
|
+
"--settings",
|
|
105784
|
+
JSON.stringify({
|
|
105785
|
+
env: {
|
|
105786
|
+
ANTHROPIC_MODEL: model,
|
|
105787
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: CLAUDE_MODELS.sonnet,
|
|
105788
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: CLAUDE_MODELS.opus,
|
|
105789
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: CLAUDE_MODELS.haiku,
|
|
105790
|
+
CLAUDE_CODE_MAX_RETRIES: "2"
|
|
105791
|
+
}
|
|
105792
|
+
}),
|
|
105793
|
+
...args
|
|
105794
|
+
];
|
|
105795
|
+
} else {
|
|
105796
|
+
childEnv = { ...env, [VAPI_ROUTER_KEY_ENV]: credentials.apiKey };
|
|
105797
|
+
args = [...await codexArgs(env, credentials.baseURL, options.model, dependencies), ...args];
|
|
105798
|
+
}
|
|
105799
|
+
}
|
|
105800
|
+
return await runChild(binary, args, childEnv, io, dependencies);
|
|
105801
|
+
}
|
|
105802
|
+
function claudeModel(model) {
|
|
105803
|
+
return model === void 0 ? CLAUDE_MODELS.sonnet : Object.hasOwn(CLAUDE_MODELS, model) ? CLAUDE_MODELS[model] : model;
|
|
105804
|
+
}
|
|
105805
|
+
async function codexArgs(env, baseURL, model, dependencies) {
|
|
105806
|
+
let contents = "";
|
|
105807
|
+
try {
|
|
105808
|
+
contents = await readFile30(
|
|
105809
|
+
codexConfigPath(env, dependencies.code?.homedir ?? homedir4()),
|
|
105810
|
+
"utf8"
|
|
105811
|
+
);
|
|
105812
|
+
} catch (error61) {
|
|
105813
|
+
if (!isMissingFile(error61)) throw error61;
|
|
105814
|
+
}
|
|
105815
|
+
const providerArgs = [
|
|
105816
|
+
"-c",
|
|
105817
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.name="vAPI Router"`,
|
|
105818
|
+
"-c",
|
|
105819
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.base_url=${JSON.stringify(baseURL)}`,
|
|
105820
|
+
"-c",
|
|
105821
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.env_key="${VAPI_ROUTER_KEY_ENV}"`,
|
|
105822
|
+
"-c",
|
|
105823
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.wire_api="responses"`,
|
|
105824
|
+
"-c",
|
|
105825
|
+
`model_provider="${VAPI_CODEX_PROVIDER}"`
|
|
105826
|
+
];
|
|
105827
|
+
if (hasVapiCodexProfile(contents))
|
|
105828
|
+
return [
|
|
105829
|
+
"--profile",
|
|
105830
|
+
VAPI_CODEX_PROFILE,
|
|
105831
|
+
...providerArgs,
|
|
105832
|
+
...model === void 0 ? [] : ["-m", model]
|
|
105833
|
+
];
|
|
105834
|
+
return [...providerArgs, "-m", model ?? VAPI_CODEX_DEFAULT_MODEL];
|
|
105835
|
+
}
|
|
105836
|
+
async function runChild(binary, args, env, io, dependencies) {
|
|
105837
|
+
const signals = dependencies.code?.processSignals ?? process;
|
|
105838
|
+
let child;
|
|
105839
|
+
const ignore = () => {
|
|
105840
|
+
};
|
|
105841
|
+
const forward = (signal) => () => {
|
|
105842
|
+
try {
|
|
105843
|
+
child?.kill(signal);
|
|
105844
|
+
} catch (error61) {
|
|
105845
|
+
io.stderr(shortReason(error61, env));
|
|
105846
|
+
}
|
|
105847
|
+
};
|
|
105848
|
+
const listeners = [
|
|
105849
|
+
["SIGINT", ignore],
|
|
105850
|
+
["SIGQUIT", ignore],
|
|
105851
|
+
["SIGTERM", forward("SIGTERM")],
|
|
105852
|
+
["SIGHUP", forward("SIGHUP")]
|
|
105853
|
+
];
|
|
105854
|
+
try {
|
|
105855
|
+
for (const [signal, listener] of listeners) signals.on(signal, listener);
|
|
105856
|
+
return await new Promise((resolve4) => {
|
|
105857
|
+
let settled = false;
|
|
105858
|
+
const finish = (code) => {
|
|
105859
|
+
if (!settled) {
|
|
105860
|
+
settled = true;
|
|
105861
|
+
resolve4(code);
|
|
105862
|
+
}
|
|
105863
|
+
};
|
|
105864
|
+
try {
|
|
105865
|
+
child = (dependencies.code?.spawn ?? spawn4)(binary, args, { env, stdio: "inherit" });
|
|
105866
|
+
child.once("error", (error61) => {
|
|
105867
|
+
if (!settled) io.stderr(shortReason(error61, env));
|
|
105868
|
+
finish(127);
|
|
105869
|
+
});
|
|
105870
|
+
child.once(
|
|
105871
|
+
"exit",
|
|
105872
|
+
(code, signal) => finish(code ?? (signal === null ? 1 : 128 + (constants3.signals[signal] ?? 0)))
|
|
105873
|
+
);
|
|
105874
|
+
} catch (error61) {
|
|
105875
|
+
io.stderr(shortReason(error61, env));
|
|
105876
|
+
finish(127);
|
|
105877
|
+
}
|
|
105878
|
+
});
|
|
105879
|
+
} finally {
|
|
105880
|
+
for (const [signal, listener] of listeners) signals.removeListener(signal, listener);
|
|
105881
|
+
}
|
|
105882
|
+
}
|
|
105883
|
+
|
|
105158
105884
|
// ../cli/src/send.ts
|
|
105159
105885
|
var SEND_USAGE = "Usage: vapi send <amount> --from <account> --to <account|owner|0x\u2026> [--network base|arc] [--resume <nonce>] [--json]";
|
|
105160
105886
|
async function sendCommand(argv, json2, io, dependencies) {
|
|
@@ -105253,8 +105979,8 @@ async function sendConfig(dependencies) {
|
|
|
105253
105979
|
}
|
|
105254
105980
|
|
|
105255
105981
|
// ../cli/src/setup.ts
|
|
105256
|
-
import { rm as
|
|
105257
|
-
import { join as
|
|
105982
|
+
import { rm as rm6 } from "node:fs/promises";
|
|
105983
|
+
import { join as join28 } from "node:path";
|
|
105258
105984
|
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
105985
|
var VAULT_CHOICE = "Create a new vault, or restore one from a recovery phrase? [new/restore] ";
|
|
105260
105986
|
async function setupCommand(argv, json2, io, dependencies) {
|
|
@@ -105284,7 +106010,7 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
105284
106010
|
let changedAccount = false;
|
|
105285
106011
|
let changedLink = false;
|
|
105286
106012
|
let scannedAddresses;
|
|
105287
|
-
if (!await fileExists2(
|
|
106013
|
+
if (!await fileExists2(join28(paths.directory, "vault.json"))) {
|
|
105288
106014
|
const choice = await vaultChoice(dependencies);
|
|
105289
106015
|
if (choice === "restore") {
|
|
105290
106016
|
if (!isInteractive(dependencies)) {
|
|
@@ -105372,7 +106098,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
105372
106098
|
let scannedAddresses = 0;
|
|
105373
106099
|
try {
|
|
105374
106100
|
const restored = await restoreVault({
|
|
105375
|
-
path:
|
|
106101
|
+
path: join28(paths.directory, "vault.json"),
|
|
105376
106102
|
key: key2,
|
|
105377
106103
|
phrase: validatedPhrase,
|
|
105378
106104
|
probe: async (address4) => await readBalance3(address4) > 0n,
|
|
@@ -105383,7 +106109,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
105383
106109
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
105384
106110
|
});
|
|
105385
106111
|
names = restored.accounts().map((account) => account.name);
|
|
105386
|
-
await
|
|
106112
|
+
await rm6(join28(paths.directory, "wallets.json"), { force: true });
|
|
105387
106113
|
} finally {
|
|
105388
106114
|
key2.fill(0);
|
|
105389
106115
|
}
|
|
@@ -105501,7 +106227,7 @@ async function withRouterError2(operation) {
|
|
|
105501
106227
|
|
|
105502
106228
|
// ../cli/src/task.ts
|
|
105503
106229
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
105504
|
-
import { readFile as
|
|
106230
|
+
import { readFile as readFile31 } from "node:fs/promises";
|
|
105505
106231
|
var TASK_HELP = `Usage:
|
|
105506
106232
|
vapi task search [--open] [--min <usd>] [--tab trending|new|closing|paid] [--limit <n>] [--json]
|
|
105507
106233
|
vapi task show <id> [--account <name>] [--json]
|
|
@@ -105837,7 +106563,7 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
105837
106563
|
if (maxAwards !== void 0 && maxAwards > TASK_LIMITS.maxAwardsMax)
|
|
105838
106564
|
throw new UsageError("--max-awards must be between 1 and 50.");
|
|
105839
106565
|
if (parsed.one("--webhook") !== void 0) httpsUrl2(parsed.one("--webhook"), "--webhook");
|
|
105840
|
-
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await
|
|
106566
|
+
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await readFile31(briefPath, "utf8");
|
|
105841
106567
|
const input2 = {
|
|
105842
106568
|
title: title.trim(),
|
|
105843
106569
|
description: brief.trim(),
|
|
@@ -106423,13 +107149,13 @@ async function watchTask(id2, parsed, json2, io, dependencies, now) {
|
|
|
106423
107149
|
}
|
|
106424
107150
|
}
|
|
106425
107151
|
cursor2 = Math.max(cursor2, page.nextAfter, ...events.map((event) => event.sequence));
|
|
106426
|
-
const
|
|
106427
|
-
if (
|
|
107152
|
+
const remaining2 = deadline - clock().getTime();
|
|
107153
|
+
if (remaining2 <= 0)
|
|
106428
107154
|
throw new TaskCommandError(
|
|
106429
107155
|
"timeout",
|
|
106430
107156
|
`Task watch timed out after ${parsed.one("--timeout") ?? "7d"}.`
|
|
106431
107157
|
);
|
|
106432
|
-
await context.sleep(Math.min(interval,
|
|
107158
|
+
await context.sleep(Math.min(interval, remaining2));
|
|
106433
107159
|
}
|
|
106434
107160
|
}
|
|
106435
107161
|
function expandDeliveryFiles(argv) {
|
|
@@ -107515,7 +108241,7 @@ async function referencedSleep(milliseconds, signal) {
|
|
|
107515
108241
|
}
|
|
107516
108242
|
|
|
107517
108243
|
// ../cli/src/vault.ts
|
|
107518
|
-
import { join as
|
|
108244
|
+
import { join as join29 } from "node:path";
|
|
107519
108245
|
var VAULT_USAGE = "Usage: vapi vault protect|unprotect|lock|unlock|status [--json]";
|
|
107520
108246
|
var RESTORE_USAGE = "Usage: vapi restore [--accounts <n> | --from-owner [--owner <0x\u2026>]] [--json]";
|
|
107521
108247
|
var LEGACY_PASSWORD_NOTICE = "VAPI_KEYSTORE_PASSWORD is deprecated for vault passwords; use VAPI_VAULT_PASSWORD instead.";
|
|
@@ -107559,7 +108285,7 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
107559
108285
|
}
|
|
107560
108286
|
const accountCount = parseRestoreAccountCount(parsed.one("--accounts"));
|
|
107561
108287
|
const paths = getVapiPaths();
|
|
107562
|
-
const path =
|
|
108288
|
+
const path = join29(paths.directory, "vault.json");
|
|
107563
108289
|
if (await fileExists2(path)) {
|
|
107564
108290
|
throw new Error(
|
|
107565
108291
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
@@ -107716,7 +108442,7 @@ function requireNoArguments(argv) {
|
|
|
107716
108442
|
parseArguments(argv, { valueOptions: /* @__PURE__ */ new Set(), maximumPositionals: 0 });
|
|
107717
108443
|
}
|
|
107718
108444
|
function vaultPath() {
|
|
107719
|
-
return
|
|
108445
|
+
return join29(getVapiPaths().directory, "vault.json");
|
|
107720
108446
|
}
|
|
107721
108447
|
function quietIo(io) {
|
|
107722
108448
|
return { stdout: () => void 0, stderr: io.stderr };
|
|
@@ -107784,6 +108510,10 @@ Usage:
|
|
|
107784
108510
|
vapi login [--account <name>] [--label <name>] [--publish] [--no-browser] [--json]
|
|
107785
108511
|
vapi logout [--account <name>] [--json]
|
|
107786
108512
|
vapi whoami [--account <name>] [--json]
|
|
108513
|
+
vapi claude [--vapi|--own] [--model <m>] [--use-balance] [--account <name>] [<claude args>...]
|
|
108514
|
+
vapi codex [--vapi|--own] [--model <id>] [--use-balance] [--account <name>] [<codex args>...]
|
|
108515
|
+
vapi code install [--yes] [--no-alias] [--account <name>] [--json]
|
|
108516
|
+
vapi code uninstall [--json]
|
|
107787
108517
|
vapi router models [--account <name>] [--json]
|
|
107788
108518
|
vapi router usage [--account <name>] [--json]
|
|
107789
108519
|
vapi router chat --model <id> [--system <text>] [--max-tokens <n>] "<prompt>" [--account <name>] [--json]
|
|
@@ -108003,6 +108733,8 @@ async function confirmWalletName(name, prompt, refusal, dependencies) {
|
|
|
108003
108733
|
if (typed.trim() !== name) throw new KeystoreError(refusal);
|
|
108004
108734
|
}
|
|
108005
108735
|
async function runCli(argv = process.argv.slice(2), io = processIo, dependencies = {}) {
|
|
108736
|
+
const firstArgument = argv.find((argument) => argument !== "--json");
|
|
108737
|
+
const codeLaunch = firstArgument === "claude" || firstArgument === "codex";
|
|
108006
108738
|
let json2 = argv.includes("--json");
|
|
108007
108739
|
const taskInvocation = argv.find((argument) => argument !== "--json") === "task";
|
|
108008
108740
|
const resultFile = runResultFile(argv);
|
|
@@ -108011,15 +108743,15 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
108011
108743
|
stderr: (message) => io.stderr(redactDetachedRunText(message, getEnvironment(dependencies)))
|
|
108012
108744
|
};
|
|
108013
108745
|
try {
|
|
108014
|
-
const parsedInvocation = removeJsonFlag(argv);
|
|
108746
|
+
const parsedInvocation = removeJsonFlag(argv, codeLaunch);
|
|
108015
108747
|
json2 = parsedInvocation.json;
|
|
108016
|
-
const hasWalletOption = parsedInvocation.args.includes(WALLET_OPTION5);
|
|
108748
|
+
const hasWalletOption = !codeLaunch && parsedInvocation.args.includes(WALLET_OPTION5);
|
|
108017
108749
|
const hasAccountOption = parsedInvocation.args.includes(ACCOUNT_OPTION2);
|
|
108018
108750
|
if (hasWalletOption && hasAccountOption) {
|
|
108019
108751
|
throw new UsageError("--wallet and --account cannot be used together.");
|
|
108020
108752
|
}
|
|
108021
108753
|
if (hasWalletOption) io.stderr(WALLET_OPTION_DEPRECATION);
|
|
108022
|
-
const args = parsedInvocation.args.map(
|
|
108754
|
+
const args = codeLaunch ? parsedInvocation.args : parsedInvocation.args.map(
|
|
108023
108755
|
(argument) => argument === WALLET_OPTION5 ? ACCOUNT_OPTION2 : argument
|
|
108024
108756
|
);
|
|
108025
108757
|
const command = args[0];
|
|
@@ -108115,6 +108847,15 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
108115
108847
|
await whoamiCommand(args.slice(1), json2, io, dependencies);
|
|
108116
108848
|
exitCode = 0;
|
|
108117
108849
|
break;
|
|
108850
|
+
case "claude":
|
|
108851
|
+
exitCode = await claudeCommand(args.slice(1), json2, io, dependencies);
|
|
108852
|
+
break;
|
|
108853
|
+
case "codex":
|
|
108854
|
+
exitCode = await codexCommand(args.slice(1), json2, io, dependencies);
|
|
108855
|
+
break;
|
|
108856
|
+
case "code":
|
|
108857
|
+
exitCode = await codeCommand(args.slice(1), json2, io, dependencies);
|
|
108858
|
+
break;
|
|
108118
108859
|
case "router":
|
|
108119
108860
|
await routerCommand(args.slice(1), json2, io, dependencies);
|
|
108120
108861
|
exitCode = 0;
|
|
@@ -108152,7 +108893,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
108152
108893
|
break;
|
|
108153
108894
|
case "unlock":
|
|
108154
108895
|
io.stderr("vapi unlock is now vapi vault unlock; the old name works for one release.");
|
|
108155
|
-
if (await fileExists2(
|
|
108896
|
+
if (await fileExists2(join30(getVapiPaths().directory, "vault.json"))) {
|
|
108156
108897
|
parseArguments(args.slice(1), {
|
|
108157
108898
|
valueOptions: /* @__PURE__ */ new Set([WALLET_OPTION5]),
|
|
108158
108899
|
maximumPositionals: 0
|
|
@@ -108358,7 +109099,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
108358
109099
|
address: account.address,
|
|
108359
109100
|
accounts,
|
|
108360
109101
|
config: paths.config,
|
|
108361
|
-
vault:
|
|
109102
|
+
vault: join30(paths.directory, "vault.json"),
|
|
108362
109103
|
...configRewrites.length > 0 ? { configRewrites } : {},
|
|
108363
109104
|
custody: "self",
|
|
108364
109105
|
warning: CUSTODY_NOTICE,
|
|
@@ -108497,7 +109238,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
108497
109238
|
const result = {
|
|
108498
109239
|
address: account.address,
|
|
108499
109240
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
108500
|
-
vault:
|
|
109241
|
+
vault: join30(paths.directory, "vault.json"),
|
|
108501
109242
|
...label === void 0 ? {} : { label },
|
|
108502
109243
|
spendCaps: created.entry.spendCaps,
|
|
108503
109244
|
isDefault,
|
|
@@ -108537,7 +109278,7 @@ function formatCaps2(caps) {
|
|
|
108537
109278
|
function walletListResult(store, wallets, unlocked) {
|
|
108538
109279
|
return {
|
|
108539
109280
|
default: store.defaultName ?? null,
|
|
108540
|
-
vault:
|
|
109281
|
+
vault: join30(store.home, "vault.json"),
|
|
108541
109282
|
wallets: wallets.map((wallet) => ({
|
|
108542
109283
|
name: wallet.name,
|
|
108543
109284
|
...wallet.address === void 0 ? {} : { address: wallet.address },
|
|
@@ -109810,7 +110551,7 @@ function formatClaimed(origin, claimed) {
|
|
|
109810
110551
|
}
|
|
109811
110552
|
var EXPORT_KEY_WARNING = "Anyone with this key can spend the wallet. Never paste it into a website or chat.";
|
|
109812
110553
|
async function deviceVaultKey2(store, dependencies) {
|
|
109813
|
-
const path =
|
|
110554
|
+
const path = join30(store.home, "vault.json");
|
|
109814
110555
|
const metadata = await readVaultFileUnlocked(path);
|
|
109815
110556
|
const secrets = getSecretStore(dependencies);
|
|
109816
110557
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
@@ -109903,7 +110644,7 @@ async function backupCommand(argv, json2, io, dependencies) {
|
|
|
109903
110644
|
const target = await targetWallet(parsed, dependencies);
|
|
109904
110645
|
const vaultAccount = await target.store.hasVaultAccount(target.name);
|
|
109905
110646
|
if (vaultAccount) {
|
|
109906
|
-
const vault = await readVaultFileUnlocked(
|
|
110647
|
+
const vault = await readVaultFileUnlocked(join30(target.store.home, "vault.json"));
|
|
109907
110648
|
if (vault.accounts.some((account) => account.name === target.name && account.kind === "imported")) {
|
|
109908
110649
|
throw new KeystoreError(
|
|
109909
110650
|
`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 +110721,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109980
110721
|
const existed = store.has(name);
|
|
109981
110722
|
if (existed && !parsed.has("--replace")) {
|
|
109982
110723
|
const address4 = await store.readAddress(name);
|
|
109983
|
-
const location = await store.hasVaultAccount(name) ?
|
|
110724
|
+
const location = await store.hasVaultAccount(name) ? join30(store.home, "vault.json") : store.pathFor(name);
|
|
109984
110725
|
throw new Error(
|
|
109985
110726
|
[
|
|
109986
110727
|
`Wallet ${name} already exists at ${location}.`,
|
|
@@ -110016,7 +110757,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
110016
110757
|
const result = {
|
|
110017
110758
|
address: account.address,
|
|
110018
110759
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
110019
|
-
vault:
|
|
110760
|
+
vault: join30(paths.directory, "vault.json"),
|
|
110020
110761
|
...previousKeystore ? { previousKeystore } : {},
|
|
110021
110762
|
message: "Wallet imported. Its encrypted key stays on this machine."
|
|
110022
110763
|
};
|
|
@@ -110349,7 +111090,7 @@ function formatFund(address4, url2, opened) {
|
|
|
110349
111090
|
function openInBrowser(url2) {
|
|
110350
111091
|
const opener = process.platform === "darwin" ? { command: "open", args: [url2] } : process.platform === "win32" ? { command: "cmd", args: ["/c", "start", "", url2] } : { command: "xdg-open", args: [url2] };
|
|
110351
111092
|
try {
|
|
110352
|
-
const child =
|
|
111093
|
+
const child = spawn5(opener.command, opener.args, { stdio: "ignore", detached: true });
|
|
110353
111094
|
child.on("error", () => void 0);
|
|
110354
111095
|
child.unref();
|
|
110355
111096
|
return true;
|
|
@@ -110541,11 +111282,13 @@ function parseArguments(argv, spec) {
|
|
|
110541
111282
|
has: (name) => flags.has(name)
|
|
110542
111283
|
};
|
|
110543
111284
|
}
|
|
110544
|
-
function removeJsonFlag(argv) {
|
|
111285
|
+
function removeJsonFlag(argv, preserveForwarded = false) {
|
|
110545
111286
|
let json2 = false;
|
|
110546
111287
|
const args = [];
|
|
111288
|
+
let forwarding = false;
|
|
110547
111289
|
for (const argument of argv) {
|
|
110548
|
-
if (argument
|
|
111290
|
+
if (preserveForwarded && argument === "--") forwarding = true;
|
|
111291
|
+
if (argument !== "--json" || forwarding) {
|
|
110549
111292
|
args.push(argument);
|
|
110550
111293
|
continue;
|
|
110551
111294
|
}
|
|
@@ -110646,7 +111389,7 @@ function parseInitNetworks(value) {
|
|
|
110646
111389
|
|
|
110647
111390
|
// ../cli/src/update-check.ts
|
|
110648
111391
|
import { lookup } from "node:dns/promises";
|
|
110649
|
-
import { mkdir as
|
|
111392
|
+
import { mkdir as mkdir22, readFile as readFile32, writeFile as writeFile13 } from "node:fs/promises";
|
|
110650
111393
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
110651
111394
|
var CHECK_TIMEOUT_MS = 1500;
|
|
110652
111395
|
var LATEST_URL = "https://registry.npmjs.org/vapi-network/latest";
|
|
@@ -110663,7 +111406,7 @@ async function runCliWithUpdateCheck(argv = process.argv.slice(2), io = {
|
|
|
110663
111406
|
async function checkForUpdate(options = {}) {
|
|
110664
111407
|
const env = options.env ?? process.env;
|
|
110665
111408
|
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) {
|
|
111409
|
+
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
111410
|
return void 0;
|
|
110668
111411
|
}
|
|
110669
111412
|
const controller = new AbortController();
|
|
@@ -110690,7 +111433,7 @@ async function latestNotice(options, env, signal) {
|
|
|
110690
111433
|
const now = (options.nowMs ?? Date.now)();
|
|
110691
111434
|
let cached2;
|
|
110692
111435
|
try {
|
|
110693
|
-
const value = JSON.parse(await
|
|
111436
|
+
const value = JSON.parse(await readFile32(paths.updateCheck, "utf8"));
|
|
110694
111437
|
if (isRecord13(value) && typeof value.checkedAt === "number" && Number.isFinite(value.checkedAt) && typeof value.latest === "string" && parseVersion(value.latest)) {
|
|
110695
111438
|
cached2 = { checkedAt: value.checkedAt, latest: value.latest };
|
|
110696
111439
|
}
|
|
@@ -110699,9 +111442,9 @@ async function latestNotice(options, env, signal) {
|
|
|
110699
111442
|
signal.throwIfAborted();
|
|
110700
111443
|
let latest = cached2?.latest ?? CLI_VERSION;
|
|
110701
111444
|
if (cached2 === void 0 || now - cached2.checkedAt >= CHECK_INTERVAL_MS || now < cached2.checkedAt) {
|
|
110702
|
-
await
|
|
111445
|
+
await mkdir22(paths.directory, { recursive: true });
|
|
110703
111446
|
signal.throwIfAborted();
|
|
110704
|
-
await
|
|
111447
|
+
await writeFile13(paths.updateCheck, JSON.stringify({ checkedAt: now, latest }), { mode: 384 });
|
|
110705
111448
|
signal.throwIfAborted();
|
|
110706
111449
|
const fetchImpl = options.fetchImpl ?? createPublicFetch({
|
|
110707
111450
|
allowPrivateNetwork: false,
|
|
@@ -110728,7 +111471,7 @@ async function latestNotice(options, env, signal) {
|
|
|
110728
111471
|
return void 0;
|
|
110729
111472
|
}
|
|
110730
111473
|
latest = body.version;
|
|
110731
|
-
await
|
|
111474
|
+
await writeFile13(paths.updateCheck, JSON.stringify({ checkedAt: now, latest }), { mode: 384 });
|
|
110732
111475
|
}
|
|
110733
111476
|
signal.throwIfAborted();
|
|
110734
111477
|
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 +111514,15 @@ function isNewerVersion(latest, current) {
|
|
|
110771
111514
|
}
|
|
110772
111515
|
|
|
110773
111516
|
// src/client.ts
|
|
110774
|
-
import { homedir as
|
|
110775
|
-
import { join as
|
|
111517
|
+
import { homedir as homedir5 } from "node:os";
|
|
111518
|
+
import { join as join31 } from "node:path";
|
|
110776
111519
|
var ACCOUNT_NOT_LINKED = "Not linked. Run vapi login on this machine, or set VAPI_HOME to a linked home.";
|
|
110777
111520
|
var DISCOVERY_PATH2 = "/api/call/discovery";
|
|
110778
111521
|
var warnedWalletOption = false;
|
|
110779
111522
|
async function createVapiClient(options = {}) {
|
|
110780
111523
|
if (options.wallet !== void 0) warnWalletOption();
|
|
110781
111524
|
const env = options.env ?? process.env;
|
|
110782
|
-
const home = options.home ?? (env.VAPI_HOME?.trim() ||
|
|
111525
|
+
const home = options.home ?? (env.VAPI_HOME?.trim() || join31(homedir5(), ".vapi"));
|
|
110783
111526
|
const paths = getVapiPaths(home);
|
|
110784
111527
|
const requestedName = typeof options.account === "string" ? options.account : options.wallet;
|
|
110785
111528
|
const injected = typeof options.account === "object" ? options.account : void 0;
|