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/cli.js
CHANGED
|
@@ -10117,9 +10117,9 @@ var init_call = __esm({
|
|
|
10117
10117
|
});
|
|
10118
10118
|
|
|
10119
10119
|
// ../cli/src/cli.ts
|
|
10120
|
-
import { spawn as
|
|
10120
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
10121
10121
|
import { stat as stat16 } from "node:fs/promises";
|
|
10122
|
-
import { join as
|
|
10122
|
+
import { join as join29 } from "node:path";
|
|
10123
10123
|
import { createInterface as createInterface3 } from "node:readline/promises";
|
|
10124
10124
|
|
|
10125
10125
|
// ../../node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/external.js
|
|
@@ -70104,13 +70104,13 @@ async function withAccountMovementLocks(home, accounts, timeoutMs, operation) {
|
|
|
70104
70104
|
);
|
|
70105
70105
|
}
|
|
70106
70106
|
async function acquireAccountMovementLocks(home, accounts, timeoutMs, operation) {
|
|
70107
|
-
const [account, ...
|
|
70107
|
+
const [account, ...remaining2] = accounts;
|
|
70108
70108
|
if (account === void 0) return await operation();
|
|
70109
70109
|
return await withAccountMovementLock(
|
|
70110
70110
|
home,
|
|
70111
70111
|
account,
|
|
70112
70112
|
timeoutMs,
|
|
70113
|
-
async () => acquireAccountMovementLocks(home,
|
|
70113
|
+
async () => acquireAccountMovementLocks(home, remaining2, timeoutMs, operation)
|
|
70114
70114
|
);
|
|
70115
70115
|
}
|
|
70116
70116
|
async function removeStaleLock2(path) {
|
|
@@ -70183,7 +70183,7 @@ var POWERSHELL_MISSING = [
|
|
|
70183
70183
|
].join(" ");
|
|
70184
70184
|
function secretStore(options = {}) {
|
|
70185
70185
|
const platform2 = options.platform ?? process.platform;
|
|
70186
|
-
const run = options.run ?? spawnRunner;
|
|
70186
|
+
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
70187
70187
|
const env = options.env ?? process.env;
|
|
70188
70188
|
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
70189
70189
|
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
@@ -70377,6 +70377,7 @@ function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
|
70377
70377
|
].join("\n");
|
|
70378
70378
|
const execute = async (script2) => {
|
|
70379
70379
|
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
70380
|
+
|
|
70380
70381
|
`);
|
|
70381
70382
|
requirePowerShell(result);
|
|
70382
70383
|
return result;
|
|
@@ -70549,7 +70550,7 @@ function requireSuccess(result, what) {
|
|
|
70549
70550
|
function withoutTrailingNewline(value) {
|
|
70550
70551
|
return value.replace(/\r?\n$/u, "");
|
|
70551
70552
|
}
|
|
70552
|
-
var spawnRunner = async (file2, args, input2) => await new Promise((resolve3) => {
|
|
70553
|
+
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve3) => {
|
|
70553
70554
|
let stdout = "";
|
|
70554
70555
|
let stderr2 = "";
|
|
70555
70556
|
let settled = false;
|
|
@@ -70559,7 +70560,7 @@ var spawnRunner = async (file2, args, input2) => await new Promise((resolve3) =>
|
|
|
70559
70560
|
resolve3(outcome);
|
|
70560
70561
|
};
|
|
70561
70562
|
const child = spawn(file2, [...args], {
|
|
70562
|
-
detached:
|
|
70563
|
+
detached: platform2 !== "win32",
|
|
70563
70564
|
stdio: ["pipe", "pipe", "pipe"],
|
|
70564
70565
|
windowsHide: true
|
|
70565
70566
|
});
|
|
@@ -72175,6 +72176,17 @@ var WalletStore = class _WalletStore {
|
|
|
72175
72176
|
);
|
|
72176
72177
|
return account?.address ?? (await readKeystoreSummary(this.pathFor(target))).address;
|
|
72177
72178
|
}
|
|
72179
|
+
/**
|
|
72180
|
+
* Creates the vault without deriving an account, for apps that create every
|
|
72181
|
+
* account by name. Refuses when a vault already exists in this home.
|
|
72182
|
+
*/
|
|
72183
|
+
async createEmptyVault() {
|
|
72184
|
+
if (await this.readVaultUnlocked() !== void 0) {
|
|
72185
|
+
throw new KeystoreError("A vault already exists in this home.");
|
|
72186
|
+
}
|
|
72187
|
+
await this.openVault({ create: true });
|
|
72188
|
+
this.dropVaultCache();
|
|
72189
|
+
}
|
|
72178
72190
|
async create(name, passphrase, options = {}) {
|
|
72179
72191
|
void passphrase;
|
|
72180
72192
|
void options.enableSolana;
|
|
@@ -73055,11 +73067,11 @@ function accountChangeBusyError(account, command) {
|
|
|
73055
73067
|
);
|
|
73056
73068
|
}
|
|
73057
73069
|
async function withAccountMutationLocks(home, accounts, command, operation) {
|
|
73058
|
-
const [account, ...
|
|
73070
|
+
const [account, ...remaining2] = [...new Set(accounts)].sort();
|
|
73059
73071
|
if (account === void 0) return await operation();
|
|
73060
73072
|
return await withFileLock(
|
|
73061
73073
|
join8(home, `.account-${account}.lock`),
|
|
73062
|
-
async () => await withAccountMutationLocks(home,
|
|
73074
|
+
async () => await withAccountMutationLocks(home, remaining2, command, operation),
|
|
73063
73075
|
{
|
|
73064
73076
|
lockedMessage: `Account ${account} is busy with another account change. Wait for it to finish, then retry ${command}.`
|
|
73065
73077
|
}
|
|
@@ -73867,8 +73879,8 @@ async function escrowFundingDayRemainingAtomic(input2) {
|
|
|
73867
73879
|
const rows = await readStoredSpendLedgerRows(input2.ledgerPath, input2.now);
|
|
73868
73880
|
const row = rows.find((candidate) => candidate.wallet === input2.wallet);
|
|
73869
73881
|
const reserved = input2.reservationId ? row?.reservations?.find((candidate) => candidate.id === input2.reservationId) : void 0;
|
|
73870
|
-
const
|
|
73871
|
-
return
|
|
73882
|
+
const remaining2 = perDayAtomic - BigInt(row?.spentAtomic ?? "0") + BigInt(reserved?.amountAtomic ?? "0");
|
|
73883
|
+
return remaining2 > 0n ? remaining2 : 0n;
|
|
73872
73884
|
}
|
|
73873
73885
|
async function taskReservedAtomic(input2) {
|
|
73874
73886
|
const rows = await readStoredSpendLedgerRows(input2.ledgerPath, input2.now, true);
|
|
@@ -75208,13 +75220,13 @@ function splitMovementPlanAtRelayLimit(plan) {
|
|
|
75208
75220
|
const legs = plan.legs.flatMap((leg) => {
|
|
75209
75221
|
const purpose = leg.purpose ?? "send";
|
|
75210
75222
|
const split2 = purpose === "sweep" || plan.reason === "send" && plan.treasury !== void 0 && leg.to === plan.treasury;
|
|
75211
|
-
let
|
|
75212
|
-
if (!split2 ||
|
|
75223
|
+
let remaining2 = parseUsdCents(leg.amountUsd);
|
|
75224
|
+
if (!split2 || remaining2 <= maximumCents) return [leg];
|
|
75213
75225
|
const parts = [];
|
|
75214
|
-
while (
|
|
75215
|
-
const cents =
|
|
75226
|
+
while (remaining2 > 0n) {
|
|
75227
|
+
const cents = remaining2 > maximumCents ? maximumCents : remaining2;
|
|
75216
75228
|
parts.push({ ...leg, amountUsd: formatUsdCents(cents) });
|
|
75217
|
-
|
|
75229
|
+
remaining2 -= cents;
|
|
75218
75230
|
}
|
|
75219
75231
|
return parts;
|
|
75220
75232
|
});
|
|
@@ -76090,13 +76102,13 @@ async function withMovementLock(home, from16, timeoutMs, operation) {
|
|
|
76090
76102
|
}
|
|
76091
76103
|
}
|
|
76092
76104
|
async function withMovementLocks(home, senders, timeoutMs, operation) {
|
|
76093
|
-
const [sender, ...
|
|
76105
|
+
const [sender, ...remaining2] = senders;
|
|
76094
76106
|
if (sender === void 0) return await operation();
|
|
76095
76107
|
return await withMovementLock(
|
|
76096
76108
|
home,
|
|
76097
76109
|
sender,
|
|
76098
76110
|
timeoutMs,
|
|
76099
|
-
async () => withMovementLocks(home,
|
|
76111
|
+
async () => withMovementLocks(home, remaining2, timeoutMs, operation)
|
|
76100
76112
|
);
|
|
76101
76113
|
}
|
|
76102
76114
|
async function assertNoPendingCeilingSweep(deps, senders) {
|
|
@@ -76903,11 +76915,11 @@ function planTargets(input2) {
|
|
|
76903
76915
|
function splitCandidateAtRelayMaximum(candidate, relayMaxAtomic) {
|
|
76904
76916
|
const maximumCents = relayMaxAtomic / 10000n;
|
|
76905
76917
|
const legs = [];
|
|
76906
|
-
let
|
|
76907
|
-
while (
|
|
76908
|
-
const cents =
|
|
76918
|
+
let remaining2 = candidate.cents;
|
|
76919
|
+
while (remaining2 > 0n) {
|
|
76920
|
+
const cents = remaining2 > maximumCents ? maximumCents : remaining2;
|
|
76909
76921
|
legs.push(allocationLeg(candidate.from, candidate.to, cents, candidate.purpose));
|
|
76910
|
-
|
|
76922
|
+
remaining2 -= cents;
|
|
76911
76923
|
}
|
|
76912
76924
|
return legs;
|
|
76913
76925
|
}
|
|
@@ -77742,7 +77754,7 @@ function createRunBudget(args) {
|
|
|
77742
77754
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
77743
77755
|
import { arch, platform, release } from "node:os";
|
|
77744
77756
|
import { join as join13 } from "node:path";
|
|
77745
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
77757
|
+
var VAPI_CLIENT_VERSION = "0.12.0";
|
|
77746
77758
|
async function createSupportReport(options) {
|
|
77747
77759
|
const message = options.message.trim();
|
|
77748
77760
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
@@ -79134,8 +79146,15 @@ async function ownerStake(deps) {
|
|
|
79134
79146
|
stakeUrl: parsed.data.stakeUrl
|
|
79135
79147
|
};
|
|
79136
79148
|
}
|
|
79137
|
-
async function routerCredentials(deps) {
|
|
79138
|
-
const
|
|
79149
|
+
async function routerCredentials(deps, options = {}) {
|
|
79150
|
+
const credentials = options.funding === "balance" ? await routerBalanceCredentialSnapshot(deps) : await routerCredentialSnapshot(deps);
|
|
79151
|
+
if (credentials === void 0) {
|
|
79152
|
+
throw new RouterClientError(
|
|
79153
|
+
"no_router_key",
|
|
79154
|
+
"No Router balance key is stored for this wallet."
|
|
79155
|
+
);
|
|
79156
|
+
}
|
|
79157
|
+
const { routerBaseUrl, routerKey } = credentials;
|
|
79139
79158
|
return { baseURL: `${routerBaseUrl}/v1`, apiKey: routerKey };
|
|
79140
79159
|
}
|
|
79141
79160
|
async function routerCredentialSnapshot(deps) {
|
|
@@ -82359,10 +82378,10 @@ async function waitForMilestone(client, input2) {
|
|
|
82359
82378
|
return { reached, milestone, polls, elapsedMs: now().getTime() - started };
|
|
82360
82379
|
}
|
|
82361
82380
|
for (; ; ) {
|
|
82362
|
-
const
|
|
82363
|
-
if (
|
|
82381
|
+
const remaining2 = deadline - now().getTime();
|
|
82382
|
+
if (remaining2 <= 0) return result(false);
|
|
82364
82383
|
const controller = new AbortController();
|
|
82365
|
-
const timer = setTimeout(() => controller.abort(),
|
|
82384
|
+
const timer = setTimeout(() => controller.abort(), remaining2);
|
|
82366
82385
|
let response;
|
|
82367
82386
|
polls++;
|
|
82368
82387
|
try {
|
|
@@ -83026,7 +83045,7 @@ async function feeTask(input2, action) {
|
|
|
83026
83045
|
);
|
|
83027
83046
|
let approvalGranted = input2.approval !== void 0 && "granted" in input2.approval && input2.approval.granted;
|
|
83028
83047
|
const checkPolicy = async (reservationId) => {
|
|
83029
|
-
const
|
|
83048
|
+
const remaining2 = await escrowFundingDayRemainingAtomic({
|
|
83030
83049
|
caps: input2.caps,
|
|
83031
83050
|
ledgerPath: input2.ledgerPath,
|
|
83032
83051
|
wallet: input2.wallet,
|
|
@@ -83043,13 +83062,13 @@ async function feeTask(input2, action) {
|
|
|
83043
83062
|
const maxPerTaskAtomic = policyAtomic(input2.policy.maxPerTaskUsd);
|
|
83044
83063
|
if (feeAtomic > maxPerTaskAtomic || taskReserved + feeAtomic > maxPerTaskAtomic)
|
|
83045
83064
|
return { outcome: "refused", reason: "policy.perTask", money: money2, disputeFee: fee };
|
|
83046
|
-
if (feeAtomic >
|
|
83065
|
+
if (feeAtomic > remaining2)
|
|
83047
83066
|
return { outcome: "refused", reason: "policy.perDay", money: money2, disputeFee: fee };
|
|
83048
83067
|
if (feeAtomic > policyAtomic(input2.policy.approveAboveUsd) && !approvalGranted) {
|
|
83049
83068
|
if (input2.approval && "ask" in input2.approval) {
|
|
83050
83069
|
approvalGranted = await input2.approval.ask({
|
|
83051
83070
|
money: money2,
|
|
83052
|
-
dayRemainingUsd: Number(formatBaseUnitsUsd(
|
|
83071
|
+
dayRemainingUsd: Number(formatBaseUnitsUsd(remaining2))
|
|
83053
83072
|
});
|
|
83054
83073
|
if (!approvalGranted) return { outcome: "declined", money: money2, disputeFee: fee };
|
|
83055
83074
|
} else return { outcome: "approval_needed", money: money2, disputeFee: fee };
|
|
@@ -91565,8 +91584,8 @@ async function memberBudgetAtomic(account, configured, deps) {
|
|
|
91565
91584
|
deps.now?.() ?? /* @__PURE__ */ new Date(),
|
|
91566
91585
|
account
|
|
91567
91586
|
);
|
|
91568
|
-
const
|
|
91569
|
-
return
|
|
91587
|
+
const remaining2 = BigInt(caps.perDayAtomic) - BigInt(ledger.spentAtomic);
|
|
91588
|
+
return remaining2 < 0n ? 0n : remaining2;
|
|
91570
91589
|
}
|
|
91571
91590
|
function withoutTreasuryGrants(profile) {
|
|
91572
91591
|
return {
|
|
@@ -93561,9 +93580,9 @@ async function watchEvents(ctx, input2, now, sleep, deadline, signal, progress)
|
|
|
93561
93580
|
const reached = input2.until !== void 0 && next.events.some((event) => taskStateMatches(input2.until, taskEventState(event)));
|
|
93562
93581
|
if (next.events.length || reached)
|
|
93563
93582
|
return { ...next, ...reached ? { reached: input2.until } : {}, timedOut: false };
|
|
93564
|
-
const
|
|
93565
|
-
if (
|
|
93566
|
-
await sleep(Math.min(TASK_LIMITS.watchIntervalMinMs,
|
|
93583
|
+
const remaining2 = deadline - now().getTime();
|
|
93584
|
+
if (remaining2 <= 0) return { ...next, timedOut: true };
|
|
93585
|
+
await sleep(Math.min(TASK_LIMITS.watchIntervalMinMs, remaining2), signal);
|
|
93567
93586
|
if (now().getTime() >= deadline)
|
|
93568
93587
|
return { events: [], nextCursor: progress.cursor, timedOut: true };
|
|
93569
93588
|
}
|
|
@@ -94606,9 +94625,15 @@ var VapiMcpServer = class {
|
|
|
94606
94625
|
return tool.deprecatedReplacement ? withDeprecation(result, tool.deprecatedReplacement) : result;
|
|
94607
94626
|
}
|
|
94608
94627
|
}
|
|
94609
|
-
|
|
94628
|
+
#output = process.stdout;
|
|
94629
|
+
/**
|
|
94630
|
+
* Serves JSON-RPC lines from `input` and answers on `output`. The desktop
|
|
94631
|
+
* app hands in a socket; the CLI hands in stdio through connectStdio().
|
|
94632
|
+
*/
|
|
94633
|
+
connect(input2, output4) {
|
|
94610
94634
|
if (this.#stdio) return;
|
|
94611
|
-
this.#
|
|
94635
|
+
this.#output = output4;
|
|
94636
|
+
this.#stdio = createInterface({ input: input2, crlfDelay: Infinity });
|
|
94612
94637
|
this.#stdio.on("line", (line) => {
|
|
94613
94638
|
void this.#handleLine(line);
|
|
94614
94639
|
});
|
|
@@ -94617,6 +94642,9 @@ var VapiMcpServer = class {
|
|
|
94617
94642
|
this.#onClose?.();
|
|
94618
94643
|
});
|
|
94619
94644
|
}
|
|
94645
|
+
connectStdio() {
|
|
94646
|
+
this.connect(process.stdin, process.stdout);
|
|
94647
|
+
}
|
|
94620
94648
|
async close() {
|
|
94621
94649
|
this.#stdio?.close();
|
|
94622
94650
|
this.#stdio = void 0;
|
|
@@ -94697,7 +94725,7 @@ var VapiMcpServer = class {
|
|
|
94697
94725
|
}
|
|
94698
94726
|
}
|
|
94699
94727
|
#write(message) {
|
|
94700
|
-
|
|
94728
|
+
this.#output.write(`${JSON.stringify(message)}
|
|
94701
94729
|
`);
|
|
94702
94730
|
}
|
|
94703
94731
|
};
|
|
@@ -98279,10 +98307,10 @@ async function awaitRelay(options) {
|
|
|
98279
98307
|
if (!Number.isFinite(deadline)) throw new CloudBackupError("relay_expired");
|
|
98280
98308
|
while (true) {
|
|
98281
98309
|
if (isAborted(options.signal)) throw new CloudBackupError("relay_aborted");
|
|
98282
|
-
const
|
|
98283
|
-
if (
|
|
98310
|
+
const remaining2 = deadline - readNow(now).getTime();
|
|
98311
|
+
if (remaining2 <= 0) throw new CloudBackupError("relay_expired");
|
|
98284
98312
|
let response;
|
|
98285
|
-
const requestDeadline = AbortSignal.timeout(Math.max(1,
|
|
98313
|
+
const requestDeadline = AbortSignal.timeout(Math.max(1, remaining2));
|
|
98286
98314
|
const requestSignal = options.signal === void 0 ? requestDeadline : AbortSignal.any([options.signal, requestDeadline]);
|
|
98287
98315
|
try {
|
|
98288
98316
|
response = await (options.fetchImpl ?? publicFetch5)(
|
|
@@ -98301,7 +98329,7 @@ async function awaitRelay(options) {
|
|
|
98301
98329
|
return await readRelayResult(response, options);
|
|
98302
98330
|
}
|
|
98303
98331
|
try {
|
|
98304
|
-
await sleep(Math.min(Math.max(0, pollMs),
|
|
98332
|
+
await sleep(Math.min(Math.max(0, pollMs), remaining2), options.signal);
|
|
98305
98333
|
} catch {
|
|
98306
98334
|
if (isAborted(options.signal)) throw new CloudBackupError("relay_aborted");
|
|
98307
98335
|
}
|
|
@@ -99091,7 +99119,7 @@ async function readProcessStdin() {
|
|
|
99091
99119
|
}
|
|
99092
99120
|
|
|
99093
99121
|
// ../cli/src/version.ts
|
|
99094
|
-
var CLI_VERSION = "0.
|
|
99122
|
+
var CLI_VERSION = "0.12.0";
|
|
99095
99123
|
|
|
99096
99124
|
// ../cli/src/status.ts
|
|
99097
99125
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -102316,9 +102344,9 @@ async function reserveRemoteAllowance(args) {
|
|
|
102316
102344
|
const perDayAtomic = BigInt(args.caps.perDayAtomic);
|
|
102317
102345
|
const ledgerPath = getVapiPaths(args.home).ledger;
|
|
102318
102346
|
const spent = BigInt((await readSpendLedger(ledgerPath, args.now, args.account)).spentAtomic);
|
|
102319
|
-
const
|
|
102320
|
-
const requested = args.run.budgetUsd === void 0 ?
|
|
102321
|
-
const reserved = requested <
|
|
102347
|
+
const remaining2 = spent >= perDayAtomic ? 0n : perDayAtomic - spent;
|
|
102348
|
+
const requested = args.run.budgetUsd === void 0 ? remaining2 : usdToAtomic(args.run.budgetUsd);
|
|
102349
|
+
const reserved = requested < remaining2 ? requested : remaining2;
|
|
102322
102350
|
if (reserved === 0n) {
|
|
102323
102351
|
throw new RemoteKeyRefusedError(
|
|
102324
102352
|
"no_daily_allowance",
|
|
@@ -102600,12 +102628,12 @@ function createLocalRuntime(options) {
|
|
|
102600
102628
|
const { home } = options;
|
|
102601
102629
|
const entry = options.entry ?? realpathSync(process.argv[1]);
|
|
102602
102630
|
const execPath = options.execPath ?? process.execPath;
|
|
102603
|
-
const
|
|
102631
|
+
const spawn6 = options.spawn ?? nodeSpawn;
|
|
102604
102632
|
const kill = options.kill ?? ((pid, signal) => process.kill(pid, signal));
|
|
102605
102633
|
const processCommand = options.processCommand ?? defaultProcessCommand;
|
|
102606
102634
|
const ownsProcess = (handle, pid) => processCommand(pid)?.includes(runResultPath(home, handle.runId)) === true;
|
|
102607
102635
|
const closeFd = options.closeFd ?? closeSync2;
|
|
102608
|
-
const
|
|
102636
|
+
const readFile32 = options.readFile ?? nodeReadFile;
|
|
102609
102637
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
102610
102638
|
const openLog = options.openLog ?? ((path) => {
|
|
102611
102639
|
mkdirSync2(runsDirectory(home), { recursive: true, mode: 448 });
|
|
@@ -102623,7 +102651,7 @@ function createLocalRuntime(options) {
|
|
|
102623
102651
|
const logFd = openLog(logPath);
|
|
102624
102652
|
let child;
|
|
102625
102653
|
try {
|
|
102626
|
-
child =
|
|
102654
|
+
child = spawn6(execPath, [entry, ...args, "--json", "--result-file", resultPath], {
|
|
102627
102655
|
detached: true,
|
|
102628
102656
|
stdio: ["ignore", logFd, logFd],
|
|
102629
102657
|
env: {
|
|
@@ -102660,7 +102688,7 @@ function createLocalRuntime(options) {
|
|
|
102660
102688
|
return handle;
|
|
102661
102689
|
},
|
|
102662
102690
|
async status(handle) {
|
|
102663
|
-
const result = await readResultFile(
|
|
102691
|
+
const result = await readResultFile(readFile32, runResultPath(home, handle.runId));
|
|
102664
102692
|
if (result !== void 0) return result;
|
|
102665
102693
|
const pid = localPid(handle);
|
|
102666
102694
|
if (pid === void 0 || handle.kind !== "local") {
|
|
@@ -102763,10 +102791,10 @@ function childArguments(member, run) {
|
|
|
102763
102791
|
...run.drawUsd ? ["--draw", run.drawUsd] : []
|
|
102764
102792
|
];
|
|
102765
102793
|
}
|
|
102766
|
-
async function readResultFile(
|
|
102794
|
+
async function readResultFile(readFile32, path) {
|
|
102767
102795
|
let text;
|
|
102768
102796
|
try {
|
|
102769
|
-
text = await
|
|
102797
|
+
text = await readFile32(path, "utf8");
|
|
102770
102798
|
} catch (error61) {
|
|
102771
102799
|
if (hasCode3(error61, "ENOENT")) return void 0;
|
|
102772
102800
|
return { state: "failed", detail: "unreadable result file" };
|
|
@@ -103541,6 +103569,80 @@ import { spawn as spawn3 } from "node:child_process";
|
|
|
103541
103569
|
import { mkdir as mkdir20, readFile as readFile27, writeFile as writeFile11 } from "node:fs/promises";
|
|
103542
103570
|
import { homedir as systemHomedir } from "node:os";
|
|
103543
103571
|
import { dirname as dirname14, posix, win32 as win322 } from "node:path";
|
|
103572
|
+
|
|
103573
|
+
// ../cli/src/toml-config.ts
|
|
103574
|
+
function removeTomlTables(contents, isTarget) {
|
|
103575
|
+
let removing = false;
|
|
103576
|
+
let retained = "";
|
|
103577
|
+
for (const { line, table } of tomlLines(contents)) {
|
|
103578
|
+
if (table !== void 0) removing = isTarget(tomlKeyPath(table));
|
|
103579
|
+
if (!removing) retained += line;
|
|
103580
|
+
}
|
|
103581
|
+
return retained;
|
|
103582
|
+
}
|
|
103583
|
+
function* tomlLines(contents) {
|
|
103584
|
+
let multiline;
|
|
103585
|
+
for (const line of contents.match(/[^\n]*\n|[^\n]+$/g) ?? []) {
|
|
103586
|
+
yield { line, table: multiline === void 0 ? tomlTableName(line) : void 0 };
|
|
103587
|
+
for (let index2 = 0; index2 < line.length; index2 += 1) {
|
|
103588
|
+
const char = line[index2];
|
|
103589
|
+
if (multiline !== void 0) {
|
|
103590
|
+
if (multiline === '"""' && char === "\\") {
|
|
103591
|
+
index2 += 1;
|
|
103592
|
+
continue;
|
|
103593
|
+
}
|
|
103594
|
+
if (line.startsWith(multiline, index2)) {
|
|
103595
|
+
index2 += 2;
|
|
103596
|
+
multiline = void 0;
|
|
103597
|
+
}
|
|
103598
|
+
} else {
|
|
103599
|
+
if (char === "#") break;
|
|
103600
|
+
if (char !== "'" && char !== '"') continue;
|
|
103601
|
+
const delimiter2 = char.repeat(3);
|
|
103602
|
+
if (line.startsWith(delimiter2, index2)) {
|
|
103603
|
+
multiline = delimiter2;
|
|
103604
|
+
index2 += 2;
|
|
103605
|
+
} else {
|
|
103606
|
+
for (index2 += 1; index2 < line.length; index2 += 1) {
|
|
103607
|
+
if (char === '"' && line[index2] === "\\") index2 += 1;
|
|
103608
|
+
else if (line[index2] === char) break;
|
|
103609
|
+
}
|
|
103610
|
+
}
|
|
103611
|
+
}
|
|
103612
|
+
}
|
|
103613
|
+
}
|
|
103614
|
+
}
|
|
103615
|
+
function tomlKeyPath(table) {
|
|
103616
|
+
const key2 = String.raw`(?:[A-Za-z0-9_-]+|"(?:[^"\\]|\\.)*"|'[^']*')`;
|
|
103617
|
+
const pattern = new RegExp(`^\\s*(${key2})(?:\\s*\\.\\s*(${key2}))*\\s*$`);
|
|
103618
|
+
if (!pattern.test(table)) return [];
|
|
103619
|
+
return [...table.matchAll(new RegExp(key2, "g"))].map(([part]) => unquoteTomlKey(part));
|
|
103620
|
+
}
|
|
103621
|
+
function tomlTableName(line) {
|
|
103622
|
+
const header = line.replace(/\r?\n$/, "");
|
|
103623
|
+
const match = /^\s*(?:\[\[\s*(.*?)\s*\]\]|\[\s*(.*?)\s*\])\s*(?:#.*)?$/.exec(header);
|
|
103624
|
+
return match?.[1] ?? match?.[2];
|
|
103625
|
+
}
|
|
103626
|
+
function unquoteTomlKey(key2) {
|
|
103627
|
+
if (key2.startsWith("'") && key2.endsWith("'")) return key2.slice(1, -1);
|
|
103628
|
+
if (key2.startsWith('"') && key2.endsWith('"')) {
|
|
103629
|
+
try {
|
|
103630
|
+
return JSON.parse(key2);
|
|
103631
|
+
} catch {
|
|
103632
|
+
return key2;
|
|
103633
|
+
}
|
|
103634
|
+
}
|
|
103635
|
+
return key2;
|
|
103636
|
+
}
|
|
103637
|
+
function tomlSeparator(contents) {
|
|
103638
|
+
if (contents.length === 0 || /(?:\r?\n)[ \t]*(?:\r?\n)$/.test(contents)) return "";
|
|
103639
|
+
return /\r?\n$/.test(contents) ? "\n" : "\n\n";
|
|
103640
|
+
}
|
|
103641
|
+
function escapeToml(value) {
|
|
103642
|
+
return JSON.stringify(value).slice(1, -1);
|
|
103643
|
+
}
|
|
103644
|
+
|
|
103645
|
+
// ../cli/src/mcp-install.ts
|
|
103544
103646
|
var MCP_INSTALL_USAGE = "Usage: vapi mcp install <claude-code|claude-desktop|cursor|codex> [--home <dir>] [--registry <url>] [--no-link] [--json]";
|
|
103545
103647
|
var APPS = /* @__PURE__ */ new Set(["claude-code", "claude-desktop", "cursor", "codex"]);
|
|
103546
103648
|
var CLAUDE_ALIAS_NOTICE = "vapi mcp install claude installs into Claude Desktop; for the Claude Code CLI use: vapi mcp install claude-code";
|
|
@@ -103826,7 +103928,10 @@ function jsonConfig(path, existing, entry) {
|
|
|
103826
103928
|
`;
|
|
103827
103929
|
}
|
|
103828
103930
|
function tomlConfig(existing, entry) {
|
|
103829
|
-
const retained =
|
|
103931
|
+
const retained = removeTomlTables(
|
|
103932
|
+
existing,
|
|
103933
|
+
([root, name]) => root === "mcp_servers" && name === "vapi"
|
|
103934
|
+
);
|
|
103830
103935
|
const block = [
|
|
103831
103936
|
"[mcp_servers.vapi]",
|
|
103832
103937
|
'command = "npx"',
|
|
@@ -103836,46 +103941,6 @@ function tomlConfig(existing, entry) {
|
|
|
103836
103941
|
].join("\n");
|
|
103837
103942
|
return `${retained}${tomlSeparator(retained)}${block}`;
|
|
103838
103943
|
}
|
|
103839
|
-
function removeVapiTomlTables(contents) {
|
|
103840
|
-
const lines = contents.match(/[^\n]*\n|[^\n]+$/g) ?? [];
|
|
103841
|
-
let removing = false;
|
|
103842
|
-
let retained = "";
|
|
103843
|
-
for (const line of lines) {
|
|
103844
|
-
const table = tomlTableName(line);
|
|
103845
|
-
if (table !== void 0) removing = isVapiTomlTable(table);
|
|
103846
|
-
if (!removing) retained += line;
|
|
103847
|
-
}
|
|
103848
|
-
return retained;
|
|
103849
|
-
}
|
|
103850
|
-
function tomlTableName(line) {
|
|
103851
|
-
const header = line.replace(/\r?\n$/, "");
|
|
103852
|
-
const match = /^\s*(?:\[\[\s*(.*?)\s*\]\]|\[\s*(.*?)\s*\])\s*(?:#.*)?$/.exec(header);
|
|
103853
|
-
return match?.[1] ?? match?.[2];
|
|
103854
|
-
}
|
|
103855
|
-
function isVapiTomlTable(table) {
|
|
103856
|
-
const key2 = String.raw`(?:[A-Za-z0-9_-]+|"(?:[^"\\]|\\.)*"|'[^']*')`;
|
|
103857
|
-
const match = new RegExp(`^\\s*(${key2})\\s*\\.\\s*(${key2})(?:\\s*\\.|\\s*$)`).exec(table);
|
|
103858
|
-
if (match === null) return false;
|
|
103859
|
-
return unquoteTomlKey(match[1]) === "mcp_servers" && unquoteTomlKey(match[2]) === "vapi";
|
|
103860
|
-
}
|
|
103861
|
-
function unquoteTomlKey(key2) {
|
|
103862
|
-
if (key2.startsWith("'") && key2.endsWith("'")) return key2.slice(1, -1);
|
|
103863
|
-
if (key2.startsWith('"') && key2.endsWith('"')) {
|
|
103864
|
-
try {
|
|
103865
|
-
return JSON.parse(key2);
|
|
103866
|
-
} catch {
|
|
103867
|
-
return key2;
|
|
103868
|
-
}
|
|
103869
|
-
}
|
|
103870
|
-
return key2;
|
|
103871
|
-
}
|
|
103872
|
-
function tomlSeparator(contents) {
|
|
103873
|
-
if (contents.length === 0 || /(?:\r?\n)[ \t]*(?:\r?\n)$/.test(contents)) return "";
|
|
103874
|
-
return /\r?\n$/.test(contents) ? "\n" : "\n\n";
|
|
103875
|
-
}
|
|
103876
|
-
function escapeToml(value) {
|
|
103877
|
-
return value.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
|
103878
|
-
}
|
|
103879
103944
|
function isRecord12(value) {
|
|
103880
103945
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
103881
103946
|
}
|
|
@@ -103897,6 +103962,546 @@ async function pathExists5(path) {
|
|
|
103897
103962
|
}
|
|
103898
103963
|
}
|
|
103899
103964
|
|
|
103965
|
+
// ../cli/src/code.ts
|
|
103966
|
+
import { constants as constants2 } from "node:fs";
|
|
103967
|
+
import { access, mkdir as mkdir21, readFile as readFile28, realpath, unlink as unlink13, writeFile as writeFile12 } from "node:fs/promises";
|
|
103968
|
+
import { homedir as homedir3 } from "node:os";
|
|
103969
|
+
import { basename as basename5, dirname as dirname15, join as join26, posix as posix2, win32 as win323 } from "node:path";
|
|
103970
|
+
var VAPI_CODEX_PROVIDER = "vapi";
|
|
103971
|
+
var VAPI_CODEX_PROFILE = "vapi";
|
|
103972
|
+
var VAPI_CODEX_DEFAULT_MODEL = "venice/openai-gpt-61-sol";
|
|
103973
|
+
var VAPI_ROUTER_KEY_ENV = "VAPI_ROUTER_KEY";
|
|
103974
|
+
function codexConfigPath(env, home) {
|
|
103975
|
+
return join26(env.CODEX_HOME || join26(home, ".codex"), "config.toml");
|
|
103976
|
+
}
|
|
103977
|
+
function hasVapiCodexProfile(contents) {
|
|
103978
|
+
const roots = new Set(
|
|
103979
|
+
[...tomlLines(contents)].flatMap(({ table }) => {
|
|
103980
|
+
const path = table === void 0 ? [] : tomlKeyPath(table);
|
|
103981
|
+
return path.length === 2 && path[1] === "vapi" ? [path[0]] : [];
|
|
103982
|
+
})
|
|
103983
|
+
);
|
|
103984
|
+
return roots.has("model_providers") && roots.has("profiles");
|
|
103985
|
+
}
|
|
103986
|
+
async function resolveBinary(name, options) {
|
|
103987
|
+
const windows = (options.platform ?? process.platform) === "win32";
|
|
103988
|
+
const path = options.env.PATH ?? (windows ? Object.entries(options.env).find(([key2]) => key2.toLowerCase() === "path")?.[1] : void 0);
|
|
103989
|
+
if (path === void 0) return void 0;
|
|
103990
|
+
const paths = windows ? win323 : posix2;
|
|
103991
|
+
const canonical = options.realpath ?? realpath;
|
|
103992
|
+
const executable = options.isExecutable ?? (async (candidate) => {
|
|
103993
|
+
try {
|
|
103994
|
+
await access(candidate, constants2.X_OK);
|
|
103995
|
+
return true;
|
|
103996
|
+
} catch (error61) {
|
|
103997
|
+
if (isMissingFile(error61) || error61.code === "EACCES")
|
|
103998
|
+
return false;
|
|
103999
|
+
throw error61;
|
|
104000
|
+
}
|
|
104001
|
+
});
|
|
104002
|
+
const self = options.selfPath ?? process.argv[1];
|
|
104003
|
+
const selfReal = self === void 0 ? void 0 : await canonical(self);
|
|
104004
|
+
const extensions = windows ? ["", ...(options.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";")] : [""];
|
|
104005
|
+
for (const directory of path.split(windows ? ";" : ":")) {
|
|
104006
|
+
for (const extension of extensions) {
|
|
104007
|
+
const candidate = paths.resolve(directory.replace(/^"|"$/gu, ""), `${name}${extension}`);
|
|
104008
|
+
if (!await executable(candidate)) continue;
|
|
104009
|
+
const resolved = await canonical(candidate);
|
|
104010
|
+
if (selfReal !== void 0 && (windows ? resolved.toLowerCase() === selfReal.toLowerCase() : resolved === selfReal))
|
|
104011
|
+
continue;
|
|
104012
|
+
return candidate;
|
|
104013
|
+
}
|
|
104014
|
+
}
|
|
104015
|
+
return void 0;
|
|
104016
|
+
}
|
|
104017
|
+
var RC_START = "# >>> vapi code >>>";
|
|
104018
|
+
var RC_END = "# <<< vapi code <<<";
|
|
104019
|
+
var CONFIG_END = "# <<< vapi code config <<<\n";
|
|
104020
|
+
var isCodeTable = ([root, name]) => name === "vapi" && (root === "model_providers" || root === "profiles");
|
|
104021
|
+
function cleanConfig(contents) {
|
|
104022
|
+
let created = false;
|
|
104023
|
+
const cleaned = contents.replace(
|
|
104024
|
+
/(\n?)\[model_providers\.vapi\]\n# >>> vapi code config (created|existing) (0|1) >>>\n([\s\S]*?)# <<< vapi code config <<<\n/gu,
|
|
104025
|
+
(_, prefix, kind, separator, body) => {
|
|
104026
|
+
created ||= kind === "created";
|
|
104027
|
+
return (separator === "1" ? "" : prefix) + removeTomlTables(`[model_providers.vapi]
|
|
104028
|
+
${body}`, isCodeTable);
|
|
104029
|
+
}
|
|
104030
|
+
);
|
|
104031
|
+
return { contents: removeTomlTables(cleaned, isCodeTable), created };
|
|
104032
|
+
}
|
|
104033
|
+
function configContents(existing, baseURL) {
|
|
104034
|
+
const clean2 = cleanConfig(existing ?? "");
|
|
104035
|
+
const retained = clean2.contents;
|
|
104036
|
+
const separator = retained.length > 0 && !retained.endsWith("\n") ? "\n" : "";
|
|
104037
|
+
return `${retained}${separator}[model_providers.vapi]
|
|
104038
|
+
# >>> vapi code config ${existing === void 0 || clean2.created ? "created" : "existing"} ${separator.length} >>>
|
|
104039
|
+
` + [
|
|
104040
|
+
'name = "vAPI Router"',
|
|
104041
|
+
`base_url = "${escapeToml(baseURL)}"`,
|
|
104042
|
+
`env_key = "${VAPI_ROUTER_KEY_ENV}"`,
|
|
104043
|
+
'wire_api = "responses"',
|
|
104044
|
+
"",
|
|
104045
|
+
"[profiles.vapi]",
|
|
104046
|
+
`model_provider = "${VAPI_CODEX_PROVIDER}"`,
|
|
104047
|
+
`model = "${VAPI_CODEX_DEFAULT_MODEL}"`,
|
|
104048
|
+
""
|
|
104049
|
+
].join("\n") + CONFIG_END;
|
|
104050
|
+
}
|
|
104051
|
+
function removeAliases(contents) {
|
|
104052
|
+
return contents.replace(
|
|
104053
|
+
/(^|\n)# >>> vapi code >>>\r?\n[\s\S]*?^# <<< vapi code <<<(\r?\n|$)/gmu,
|
|
104054
|
+
(_, prefix, suffix) => suffix === "" ? "" : prefix
|
|
104055
|
+
);
|
|
104056
|
+
}
|
|
104057
|
+
function aliasContents(original, tools) {
|
|
104058
|
+
const existing = original ?? "";
|
|
104059
|
+
const block = [RC_START, ...tools.map((tool) => `alias ${tool}="vapi ${tool}"`), RC_END].join(
|
|
104060
|
+
"\n"
|
|
104061
|
+
);
|
|
104062
|
+
const match = /^# >>> vapi code >>>\r?\n[\s\S]*?^# <<< vapi code <<</gmu;
|
|
104063
|
+
if (match.test(existing)) return existing.replace(match, block);
|
|
104064
|
+
const separator = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
104065
|
+
return `${existing}${separator}${block}${original === "" || existing.endsWith("\n") ? "\n" : ""}`;
|
|
104066
|
+
}
|
|
104067
|
+
async function readOptional(path) {
|
|
104068
|
+
try {
|
|
104069
|
+
return await readFile28(path, "utf8");
|
|
104070
|
+
} catch (error61) {
|
|
104071
|
+
if (isMissingFile(error61)) return void 0;
|
|
104072
|
+
throw error61;
|
|
104073
|
+
}
|
|
104074
|
+
}
|
|
104075
|
+
async function writeConfig(path, contents) {
|
|
104076
|
+
await mkdir21(dirname15(path), { recursive: true });
|
|
104077
|
+
await writeFile12(path, contents);
|
|
104078
|
+
}
|
|
104079
|
+
async function codeCommand(argv, json2, io, dependencies) {
|
|
104080
|
+
const command = argv[0];
|
|
104081
|
+
if (command !== "install" && command !== "uninstall")
|
|
104082
|
+
throw new UsageError("Usage: vapi code <install|uninstall>.");
|
|
104083
|
+
const parsed = parseArguments(argv.slice(1), {
|
|
104084
|
+
valueOptions: new Set(command === "install" ? ["--wallet"] : []),
|
|
104085
|
+
booleanOptions: new Set(command === "install" ? ["--yes", "--no-alias"] : []),
|
|
104086
|
+
maximumPositionals: 0
|
|
104087
|
+
});
|
|
104088
|
+
const env = getEnvironment(dependencies);
|
|
104089
|
+
const home = dependencies.code?.homedir ?? homedir3();
|
|
104090
|
+
const config2 = codexConfigPath(env, home);
|
|
104091
|
+
const rcPaths = [join26(home, ".zshrc"), join26(home, ".bashrc")];
|
|
104092
|
+
if (command === "uninstall") {
|
|
104093
|
+
const removed = [];
|
|
104094
|
+
const previous = await readOptional(config2);
|
|
104095
|
+
if (previous !== void 0) {
|
|
104096
|
+
const clean2 = cleanConfig(previous);
|
|
104097
|
+
if (clean2.contents !== previous) {
|
|
104098
|
+
if (clean2.contents === "" && clean2.created) await unlink13(config2);
|
|
104099
|
+
else await writeFile12(config2, clean2.contents);
|
|
104100
|
+
removed.push(config2);
|
|
104101
|
+
}
|
|
104102
|
+
}
|
|
104103
|
+
for (const path of rcPaths) {
|
|
104104
|
+
const previous2 = await readOptional(path);
|
|
104105
|
+
if (previous2 === void 0) continue;
|
|
104106
|
+
const clean2 = removeAliases(previous2);
|
|
104107
|
+
if (clean2 !== previous2) {
|
|
104108
|
+
if (clean2 === "" && previous2.startsWith(RC_START) && !previous2.endsWith("\n"))
|
|
104109
|
+
await unlink13(path);
|
|
104110
|
+
else await writeFile12(path, clean2);
|
|
104111
|
+
removed.push(path);
|
|
104112
|
+
}
|
|
104113
|
+
}
|
|
104114
|
+
io.stdout(
|
|
104115
|
+
json2 ? JSON.stringify({ command: "code uninstall", removed }) : removed.length === 0 ? "Nothing to remove." : `Removed vAPI code settings from: ${removed.join(", ")}`
|
|
104116
|
+
);
|
|
104117
|
+
return 0;
|
|
104118
|
+
}
|
|
104119
|
+
const tools = [];
|
|
104120
|
+
const skipped2 = [];
|
|
104121
|
+
for (const name of ["claude", "codex"]) {
|
|
104122
|
+
const binary = await resolveBinary(name, { ...dependencies.code, env });
|
|
104123
|
+
if (binary === void 0)
|
|
104124
|
+
skipped2.push(
|
|
104125
|
+
`Skipped ${name === "claude" ? "Claude Code" : "Codex"}: \`${name}\` is not on PATH.`
|
|
104126
|
+
);
|
|
104127
|
+
else tools.push(name);
|
|
104128
|
+
}
|
|
104129
|
+
if (tools.length === 0) {
|
|
104130
|
+
const message = "Neither claude nor codex is on PATH; nothing was installed.";
|
|
104131
|
+
if (json2) io.stdout(JSON.stringify({ installed: [], skipped: skipped2, error: message }));
|
|
104132
|
+
else {
|
|
104133
|
+
skipped2.forEach(io.stderr);
|
|
104134
|
+
io.stderr(message);
|
|
104135
|
+
}
|
|
104136
|
+
return 1;
|
|
104137
|
+
}
|
|
104138
|
+
let target = await targetWallet(parsed, dependencies);
|
|
104139
|
+
const credentials = dependencies.router?.routerCredentials ?? routerCredentials;
|
|
104140
|
+
let linked = false;
|
|
104141
|
+
let rotated = false;
|
|
104142
|
+
let result;
|
|
104143
|
+
for (; ; ) {
|
|
104144
|
+
try {
|
|
104145
|
+
result = await credentials(routerDeps2(target, dependencies));
|
|
104146
|
+
break;
|
|
104147
|
+
} catch (error61) {
|
|
104148
|
+
if (error61 instanceof RouterClientError && error61.code === "not_linked" && !linked) {
|
|
104149
|
+
linked = true;
|
|
104150
|
+
const account = parsed.one("--wallet");
|
|
104151
|
+
await (dependencies.code?.login ?? runLoginFlow)(
|
|
104152
|
+
account === void 0 ? [] : ["--account", account],
|
|
104153
|
+
json2,
|
|
104154
|
+
{ ...io, stdout: io.stderr },
|
|
104155
|
+
json2 ? { ...dependencies, interactive: false, stdinIsTTY: false } : dependencies
|
|
104156
|
+
);
|
|
104157
|
+
target = await targetWallet(parsed, dependencies);
|
|
104158
|
+
} else if (error61 instanceof RouterClientError && error61.code === "no_router_key" && !rotated) {
|
|
104159
|
+
rotated = true;
|
|
104160
|
+
await (dependencies.router?.rotateRouterKey ?? rotateRouterKey)(
|
|
104161
|
+
routerDeps2(target, dependencies)
|
|
104162
|
+
);
|
|
104163
|
+
} else throw error61;
|
|
104164
|
+
}
|
|
104165
|
+
}
|
|
104166
|
+
const installed = [];
|
|
104167
|
+
if (tools.includes("claude")) installed.push("Claude Code: ready, launch with `vapi claude`");
|
|
104168
|
+
if (tools.includes("codex")) {
|
|
104169
|
+
await writeConfig(config2, configContents(await readOptional(config2), result.baseURL));
|
|
104170
|
+
installed.push(`Codex: installed ${config2}`);
|
|
104171
|
+
}
|
|
104172
|
+
let alias = "Aliases: skipped.";
|
|
104173
|
+
if (!parsed.has("--no-alias")) {
|
|
104174
|
+
if ((dependencies.code?.platform ?? process.platform) === "win32")
|
|
104175
|
+
alias = "Aliases: skipped on Windows.";
|
|
104176
|
+
else {
|
|
104177
|
+
const yes = parsed.has("--yes") || !json2 && isInteractive(dependencies) && isStdinInteractive(dependencies) && /^y(?:es)?$/iu.test(
|
|
104178
|
+
(await getLinePrompt(dependencies)(
|
|
104179
|
+
"Make `claude` and `codex` use your vAPI Compute first from now on? [y/N] "
|
|
104180
|
+
)).trim()
|
|
104181
|
+
);
|
|
104182
|
+
if (yes) {
|
|
104183
|
+
const shell = basename5(env.SHELL ?? "");
|
|
104184
|
+
const rc = shell === "zsh" ? rcPaths[0] : shell === "bash" ? rcPaths[1] : await readOptional(rcPaths[0]) !== void 0 ? rcPaths[0] : rcPaths[1];
|
|
104185
|
+
await writeConfig(rc, aliasContents(await readOptional(rc), tools));
|
|
104186
|
+
alias = `Aliases: installed in ${rc}. Open a new terminal or run: source ${rc}`;
|
|
104187
|
+
}
|
|
104188
|
+
}
|
|
104189
|
+
}
|
|
104190
|
+
let compute;
|
|
104191
|
+
try {
|
|
104192
|
+
const usage = await (dependencies.router?.routerUsage ?? routerUsage)(
|
|
104193
|
+
routerDeps2(target, dependencies)
|
|
104194
|
+
);
|
|
104195
|
+
const reset = new Date(usage.compute.resetsAt);
|
|
104196
|
+
if (!Number.isFinite(reset.getTime())) throw new Error("invalid reset time");
|
|
104197
|
+
compute = `$${usage.compute.remainingTodayUsd.toFixed(2)} left today (resets ${reset.toISOString().slice(11, 16)} UTC)`;
|
|
104198
|
+
} catch (error61) {
|
|
104199
|
+
compute = `Compute today: unavailable (${error61 instanceof RouterClientError ? error61.code : "request failed"})`;
|
|
104200
|
+
}
|
|
104201
|
+
const start = `Start with \`vapi ${tools.includes("claude") ? "claude" : "codex"}\``;
|
|
104202
|
+
if (json2)
|
|
104203
|
+
io.stdout(
|
|
104204
|
+
JSON.stringify({ command: "code install", installed, skipped: skipped2, alias, compute, start })
|
|
104205
|
+
);
|
|
104206
|
+
else {
|
|
104207
|
+
skipped2.forEach(io.stderr);
|
|
104208
|
+
[...installed, alias, compute, start].forEach(io.stdout);
|
|
104209
|
+
}
|
|
104210
|
+
return 0;
|
|
104211
|
+
}
|
|
104212
|
+
|
|
104213
|
+
// ../cli/src/code-launch.ts
|
|
104214
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
104215
|
+
import { readFile as readFile29 } from "node:fs/promises";
|
|
104216
|
+
import { constants as constants3, homedir as homedir4 } from "node:os";
|
|
104217
|
+
var CLAUDE_MODELS = {
|
|
104218
|
+
sonnet: "venice/claude-sonnet-5-5",
|
|
104219
|
+
opus: "venice/claude-opus-5-5",
|
|
104220
|
+
haiku: "venice/claude-haiku-5-5"
|
|
104221
|
+
};
|
|
104222
|
+
async function claudeCommand(argv, json2, io, dependencies) {
|
|
104223
|
+
return await launch("claude", argv, json2, io, dependencies);
|
|
104224
|
+
}
|
|
104225
|
+
async function codexCommand(argv, json2, io, dependencies) {
|
|
104226
|
+
return await launch("codex", argv, json2, io, dependencies);
|
|
104227
|
+
}
|
|
104228
|
+
function parseLaunch(argv) {
|
|
104229
|
+
const result = { own: false, vapi: false, balance: false, forwarded: [] };
|
|
104230
|
+
for (let index2 = 0; index2 < argv.length; index2 += 1) {
|
|
104231
|
+
const arg = argv[index2];
|
|
104232
|
+
if (arg === "--") {
|
|
104233
|
+
result.forwarded.push(...argv.slice(index2 + 1));
|
|
104234
|
+
break;
|
|
104235
|
+
}
|
|
104236
|
+
if (arg === "--own") result.own = true;
|
|
104237
|
+
else if (arg === "--vapi") result.vapi = true;
|
|
104238
|
+
else if (arg === "--use-balance") result.balance = true;
|
|
104239
|
+
else if (arg === "--model" || arg === "--account") {
|
|
104240
|
+
const value = argv[++index2];
|
|
104241
|
+
if (!value || value.startsWith("--")) throw new UsageError(`Expected ${arg} <value>.`);
|
|
104242
|
+
if (arg === "--model") result.model = value;
|
|
104243
|
+
else result.account = value;
|
|
104244
|
+
} else result.forwarded.push(arg);
|
|
104245
|
+
}
|
|
104246
|
+
if (result.own && result.vapi) throw new UsageError("--vapi and --own cannot be used together.");
|
|
104247
|
+
return result;
|
|
104248
|
+
}
|
|
104249
|
+
var LaunchTimeout = class extends Error {
|
|
104250
|
+
constructor() {
|
|
104251
|
+
super("timed out");
|
|
104252
|
+
}
|
|
104253
|
+
};
|
|
104254
|
+
async function bounded(operation, milliseconds) {
|
|
104255
|
+
const controller = new AbortController();
|
|
104256
|
+
let timer;
|
|
104257
|
+
try {
|
|
104258
|
+
return await Promise.race([
|
|
104259
|
+
new Promise((_resolve, reject) => {
|
|
104260
|
+
timer = setTimeout(() => {
|
|
104261
|
+
const error61 = new LaunchTimeout();
|
|
104262
|
+
controller.abort(error61);
|
|
104263
|
+
reject(error61);
|
|
104264
|
+
}, milliseconds);
|
|
104265
|
+
}),
|
|
104266
|
+
operation(controller.signal)
|
|
104267
|
+
]);
|
|
104268
|
+
} finally {
|
|
104269
|
+
clearTimeout(timer);
|
|
104270
|
+
controller.abort();
|
|
104271
|
+
}
|
|
104272
|
+
}
|
|
104273
|
+
function abortableDeps(deps, signal) {
|
|
104274
|
+
const fetchImpl = deps.fetchImpl ?? createPublicFetch({ allowPrivateNetwork: false });
|
|
104275
|
+
return {
|
|
104276
|
+
...deps,
|
|
104277
|
+
fetchImpl: (input2, init) => fetchImpl(input2, {
|
|
104278
|
+
...init,
|
|
104279
|
+
signal: init?.signal ? AbortSignal.any([signal, init.signal]) : signal
|
|
104280
|
+
})
|
|
104281
|
+
};
|
|
104282
|
+
}
|
|
104283
|
+
function shortReason(error61, env, credentials) {
|
|
104284
|
+
if (error61 instanceof RouterClientError) {
|
|
104285
|
+
if (error61.code === "not_linked") return "not linked, run vapi code install";
|
|
104286
|
+
if (error61.code === "no_router_key") return "no Router key, run vapi code install";
|
|
104287
|
+
}
|
|
104288
|
+
let message = error61 instanceof Error ? error61.message : String(error61);
|
|
104289
|
+
for (const secret of [
|
|
104290
|
+
credentials?.apiKey,
|
|
104291
|
+
env.ANTHROPIC_API_KEY,
|
|
104292
|
+
env.ANTHROPIC_AUTH_TOKEN,
|
|
104293
|
+
env[VAPI_ROUTER_KEY_ENV]
|
|
104294
|
+
]) {
|
|
104295
|
+
if (secret) message = message.replaceAll(secret, "[redacted]");
|
|
104296
|
+
}
|
|
104297
|
+
return message.replace(/\s+/gu, " ").trim().slice(0, 160) || "request failed";
|
|
104298
|
+
}
|
|
104299
|
+
async function chooseRoute(options, env, dependencies) {
|
|
104300
|
+
if (options.own) return { kind: "own" };
|
|
104301
|
+
const timeout = dependencies.code?.usageTimeoutMs ?? 4e3;
|
|
104302
|
+
let credentials;
|
|
104303
|
+
let deps;
|
|
104304
|
+
let balanceKeyRequired = false;
|
|
104305
|
+
try {
|
|
104306
|
+
credentials = await bounded(async (signal) => {
|
|
104307
|
+
const target = await targetWallet(
|
|
104308
|
+
{ one: (name) => name === "--wallet" ? options.account : void 0 },
|
|
104309
|
+
dependencies,
|
|
104310
|
+
env.VAPI_HOME
|
|
104311
|
+
);
|
|
104312
|
+
signal.throwIfAborted();
|
|
104313
|
+
deps = routerDeps2(target, dependencies);
|
|
104314
|
+
return await (dependencies.router?.routerCredentials ?? routerCredentials)(
|
|
104315
|
+
abortableDeps(deps, signal)
|
|
104316
|
+
);
|
|
104317
|
+
}, timeout);
|
|
104318
|
+
let usage;
|
|
104319
|
+
try {
|
|
104320
|
+
usage = await bounded(
|
|
104321
|
+
(signal) => (dependencies.router?.routerUsage ?? routerUsage)(abortableDeps(deps, signal)),
|
|
104322
|
+
timeout
|
|
104323
|
+
);
|
|
104324
|
+
if (!Number.isFinite(new Date(usage.compute.resetsAt).getTime()))
|
|
104325
|
+
throw new Error("invalid Compute reset time");
|
|
104326
|
+
} catch (error61) {
|
|
104327
|
+
if (options.vapi) return { kind: "vapi", credentials };
|
|
104328
|
+
throw error61;
|
|
104329
|
+
}
|
|
104330
|
+
if (options.vapi || remaining(usage, options.balance) >= 0.5) {
|
|
104331
|
+
if (options.balance && usage.compute.remainingTodayUsd < 0.5 && (usage.balance?.remainingUsd ?? 0) > 0) {
|
|
104332
|
+
balanceKeyRequired = true;
|
|
104333
|
+
credentials = await bounded(
|
|
104334
|
+
(signal) => (dependencies.router?.routerCredentials ?? routerCredentials)(
|
|
104335
|
+
abortableDeps(deps, signal),
|
|
104336
|
+
{ funding: "balance" }
|
|
104337
|
+
),
|
|
104338
|
+
timeout
|
|
104339
|
+
);
|
|
104340
|
+
}
|
|
104341
|
+
return { kind: "vapi", credentials, usage };
|
|
104342
|
+
}
|
|
104343
|
+
return { kind: "own", exhausted: true };
|
|
104344
|
+
} catch (error61) {
|
|
104345
|
+
const reason = balanceKeyRequired && error61 instanceof RouterClientError && error61.code === "no_router_key" ? "no Router balance key is stored" : shortReason(error61, env, credentials);
|
|
104346
|
+
if (options.vapi) return { kind: "unavailable", reason };
|
|
104347
|
+
return { kind: "own", reason };
|
|
104348
|
+
}
|
|
104349
|
+
}
|
|
104350
|
+
function remaining(usage, useBalance) {
|
|
104351
|
+
return usage.compute.remainingTodayUsd + (useBalance ? usage.balance?.remainingUsd ?? 0 : 0);
|
|
104352
|
+
}
|
|
104353
|
+
async function launch(tool, argv, json2, io, dependencies) {
|
|
104354
|
+
if (json2) throw new UsageError(`vapi ${tool} is interactive and does not support --json.`);
|
|
104355
|
+
const options = parseLaunch(argv);
|
|
104356
|
+
const env = getEnvironment(dependencies);
|
|
104357
|
+
let binary;
|
|
104358
|
+
try {
|
|
104359
|
+
binary = await resolveBinary(tool, { ...dependencies.code, env });
|
|
104360
|
+
} catch (error61) {
|
|
104361
|
+
io.stderr(shortReason(error61, env));
|
|
104362
|
+
return 127;
|
|
104363
|
+
}
|
|
104364
|
+
if (binary === void 0) {
|
|
104365
|
+
io.stderr(
|
|
104366
|
+
`\`${tool}\` is not on PATH. Install ${tool === "claude" ? "Claude Code" : "Codex"} first.`
|
|
104367
|
+
);
|
|
104368
|
+
return 127;
|
|
104369
|
+
}
|
|
104370
|
+
const route = await chooseRoute(options, env, dependencies);
|
|
104371
|
+
if (route.kind === "unavailable") {
|
|
104372
|
+
io.stderr(route.reason);
|
|
104373
|
+
return 1;
|
|
104374
|
+
}
|
|
104375
|
+
let args = options.forwarded;
|
|
104376
|
+
let childEnv = env;
|
|
104377
|
+
const own2 = tool === "claude" ? "your own Claude subscription" : "your own Codex/ChatGPT login";
|
|
104378
|
+
if (route.kind === "own") {
|
|
104379
|
+
if (route.exhausted) io.stderr(`\u25CF Compute used up today \u2192 ${own2}`);
|
|
104380
|
+
else if (route.reason !== void 0) io.stderr(`\u25CF vAPI unreachable (${route.reason}) \u2192 ${own2}`);
|
|
104381
|
+
if (options.model !== void 0)
|
|
104382
|
+
args = [tool === "claude" ? "--model" : "-m", options.model, ...args];
|
|
104383
|
+
} else {
|
|
104384
|
+
const { credentials, usage } = route;
|
|
104385
|
+
const model = tool === "claude" ? claudeModel(options.model) : options.model ?? VAPI_CODEX_DEFAULT_MODEL;
|
|
104386
|
+
let status = "\u25CF vAPI Compute";
|
|
104387
|
+
if (usage !== void 0)
|
|
104388
|
+
status += ` \u2014 $${remaining(usage, options.balance).toFixed(2)} left today (resets ${new Date(usage.compute.resetsAt).toISOString().slice(11, 16)} UTC)`;
|
|
104389
|
+
io.stderr(`${status} \xB7 model ${model.slice(model.lastIndexOf("/") + 1)}`);
|
|
104390
|
+
io.stderr(
|
|
104391
|
+
tool === "claude" ? " Compute runs out mid-session? /exit, then: vapi claude --continue" : " Compute runs out mid-session? /quit, then: vapi codex resume --last"
|
|
104392
|
+
);
|
|
104393
|
+
if (tool === "claude") {
|
|
104394
|
+
childEnv = {
|
|
104395
|
+
...env,
|
|
104396
|
+
ANTHROPIC_BASE_URL: credentials.baseURL.replace(/\/v1\/?$/u, ""),
|
|
104397
|
+
ANTHROPIC_AUTH_TOKEN: credentials.apiKey
|
|
104398
|
+
};
|
|
104399
|
+
delete childEnv.ANTHROPIC_API_KEY;
|
|
104400
|
+
if (args.some((arg) => arg === "--settings" || arg.startsWith("--settings=")))
|
|
104401
|
+
io.stderr("\u25CF Your --settings is passed as is; vAPI model settings were not added.");
|
|
104402
|
+
else
|
|
104403
|
+
args = [
|
|
104404
|
+
"--settings",
|
|
104405
|
+
JSON.stringify({
|
|
104406
|
+
env: {
|
|
104407
|
+
ANTHROPIC_MODEL: model,
|
|
104408
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: CLAUDE_MODELS.sonnet,
|
|
104409
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: CLAUDE_MODELS.opus,
|
|
104410
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: CLAUDE_MODELS.haiku,
|
|
104411
|
+
CLAUDE_CODE_MAX_RETRIES: "2"
|
|
104412
|
+
}
|
|
104413
|
+
}),
|
|
104414
|
+
...args
|
|
104415
|
+
];
|
|
104416
|
+
} else {
|
|
104417
|
+
childEnv = { ...env, [VAPI_ROUTER_KEY_ENV]: credentials.apiKey };
|
|
104418
|
+
args = [...await codexArgs(env, credentials.baseURL, options.model, dependencies), ...args];
|
|
104419
|
+
}
|
|
104420
|
+
}
|
|
104421
|
+
return await runChild(binary, args, childEnv, io, dependencies);
|
|
104422
|
+
}
|
|
104423
|
+
function claudeModel(model) {
|
|
104424
|
+
return model === void 0 ? CLAUDE_MODELS.sonnet : Object.hasOwn(CLAUDE_MODELS, model) ? CLAUDE_MODELS[model] : model;
|
|
104425
|
+
}
|
|
104426
|
+
async function codexArgs(env, baseURL, model, dependencies) {
|
|
104427
|
+
let contents = "";
|
|
104428
|
+
try {
|
|
104429
|
+
contents = await readFile29(
|
|
104430
|
+
codexConfigPath(env, dependencies.code?.homedir ?? homedir4()),
|
|
104431
|
+
"utf8"
|
|
104432
|
+
);
|
|
104433
|
+
} catch (error61) {
|
|
104434
|
+
if (!isMissingFile(error61)) throw error61;
|
|
104435
|
+
}
|
|
104436
|
+
const providerArgs = [
|
|
104437
|
+
"-c",
|
|
104438
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.name="vAPI Router"`,
|
|
104439
|
+
"-c",
|
|
104440
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.base_url=${JSON.stringify(baseURL)}`,
|
|
104441
|
+
"-c",
|
|
104442
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.env_key="${VAPI_ROUTER_KEY_ENV}"`,
|
|
104443
|
+
"-c",
|
|
104444
|
+
`model_providers.${VAPI_CODEX_PROVIDER}.wire_api="responses"`,
|
|
104445
|
+
"-c",
|
|
104446
|
+
`model_provider="${VAPI_CODEX_PROVIDER}"`
|
|
104447
|
+
];
|
|
104448
|
+
if (hasVapiCodexProfile(contents))
|
|
104449
|
+
return [
|
|
104450
|
+
"--profile",
|
|
104451
|
+
VAPI_CODEX_PROFILE,
|
|
104452
|
+
...providerArgs,
|
|
104453
|
+
...model === void 0 ? [] : ["-m", model]
|
|
104454
|
+
];
|
|
104455
|
+
return [...providerArgs, "-m", model ?? VAPI_CODEX_DEFAULT_MODEL];
|
|
104456
|
+
}
|
|
104457
|
+
async function runChild(binary, args, env, io, dependencies) {
|
|
104458
|
+
const signals = dependencies.code?.processSignals ?? process;
|
|
104459
|
+
let child;
|
|
104460
|
+
const ignore = () => {
|
|
104461
|
+
};
|
|
104462
|
+
const forward = (signal) => () => {
|
|
104463
|
+
try {
|
|
104464
|
+
child?.kill(signal);
|
|
104465
|
+
} catch (error61) {
|
|
104466
|
+
io.stderr(shortReason(error61, env));
|
|
104467
|
+
}
|
|
104468
|
+
};
|
|
104469
|
+
const listeners = [
|
|
104470
|
+
["SIGINT", ignore],
|
|
104471
|
+
["SIGQUIT", ignore],
|
|
104472
|
+
["SIGTERM", forward("SIGTERM")],
|
|
104473
|
+
["SIGHUP", forward("SIGHUP")]
|
|
104474
|
+
];
|
|
104475
|
+
try {
|
|
104476
|
+
for (const [signal, listener] of listeners) signals.on(signal, listener);
|
|
104477
|
+
return await new Promise((resolve3) => {
|
|
104478
|
+
let settled = false;
|
|
104479
|
+
const finish = (code) => {
|
|
104480
|
+
if (!settled) {
|
|
104481
|
+
settled = true;
|
|
104482
|
+
resolve3(code);
|
|
104483
|
+
}
|
|
104484
|
+
};
|
|
104485
|
+
try {
|
|
104486
|
+
child = (dependencies.code?.spawn ?? spawn4)(binary, args, { env, stdio: "inherit" });
|
|
104487
|
+
child.once("error", (error61) => {
|
|
104488
|
+
if (!settled) io.stderr(shortReason(error61, env));
|
|
104489
|
+
finish(127);
|
|
104490
|
+
});
|
|
104491
|
+
child.once(
|
|
104492
|
+
"exit",
|
|
104493
|
+
(code, signal) => finish(code ?? (signal === null ? 1 : 128 + (constants3.signals[signal] ?? 0)))
|
|
104494
|
+
);
|
|
104495
|
+
} catch (error61) {
|
|
104496
|
+
io.stderr(shortReason(error61, env));
|
|
104497
|
+
finish(127);
|
|
104498
|
+
}
|
|
104499
|
+
});
|
|
104500
|
+
} finally {
|
|
104501
|
+
for (const [signal, listener] of listeners) signals.removeListener(signal, listener);
|
|
104502
|
+
}
|
|
104503
|
+
}
|
|
104504
|
+
|
|
103900
104505
|
// ../cli/src/send.ts
|
|
103901
104506
|
var SEND_USAGE = "Usage: vapi send <amount> --from <account> --to <account|owner|0x\u2026> [--network base|arc] [--resume <nonce>] [--json]";
|
|
103902
104507
|
async function sendCommand(argv, json2, io, dependencies) {
|
|
@@ -103996,7 +104601,7 @@ async function sendConfig(dependencies) {
|
|
|
103996
104601
|
|
|
103997
104602
|
// ../cli/src/setup.ts
|
|
103998
104603
|
import { rm as rm5 } from "node:fs/promises";
|
|
103999
|
-
import { join as
|
|
104604
|
+
import { join as join27 } from "node:path";
|
|
104000
104605
|
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.`;
|
|
104001
104606
|
var VAULT_CHOICE = "Create a new vault, or restore one from a recovery phrase? [new/restore] ";
|
|
104002
104607
|
async function setupCommand(argv, json2, io, dependencies) {
|
|
@@ -104026,7 +104631,7 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
104026
104631
|
let changedAccount = false;
|
|
104027
104632
|
let changedLink = false;
|
|
104028
104633
|
let scannedAddresses;
|
|
104029
|
-
if (!await fileExists2(
|
|
104634
|
+
if (!await fileExists2(join27(paths.directory, "vault.json"))) {
|
|
104030
104635
|
const choice = await vaultChoice(dependencies);
|
|
104031
104636
|
if (choice === "restore") {
|
|
104032
104637
|
if (!isInteractive(dependencies)) {
|
|
@@ -104114,7 +104719,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
104114
104719
|
let scannedAddresses = 0;
|
|
104115
104720
|
try {
|
|
104116
104721
|
const restored = await restoreVault({
|
|
104117
|
-
path:
|
|
104722
|
+
path: join27(paths.directory, "vault.json"),
|
|
104118
104723
|
key: key2,
|
|
104119
104724
|
phrase: validatedPhrase,
|
|
104120
104725
|
probe: async (address4) => await readBalance3(address4) > 0n,
|
|
@@ -104125,7 +104730,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
104125
104730
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
104126
104731
|
});
|
|
104127
104732
|
names = restored.accounts().map((account) => account.name);
|
|
104128
|
-
await rm5(
|
|
104733
|
+
await rm5(join27(paths.directory, "wallets.json"), { force: true });
|
|
104129
104734
|
} finally {
|
|
104130
104735
|
key2.fill(0);
|
|
104131
104736
|
}
|
|
@@ -104243,7 +104848,7 @@ async function withRouterError2(operation) {
|
|
|
104243
104848
|
|
|
104244
104849
|
// ../cli/src/task.ts
|
|
104245
104850
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
104246
|
-
import { readFile as
|
|
104851
|
+
import { readFile as readFile30 } from "node:fs/promises";
|
|
104247
104852
|
var TASK_HELP = `Usage:
|
|
104248
104853
|
vapi task search [--open] [--min <usd>] [--tab trending|new|closing|paid] [--limit <n>] [--json]
|
|
104249
104854
|
vapi task show <id> [--account <name>] [--json]
|
|
@@ -104579,7 +105184,7 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
104579
105184
|
if (maxAwards !== void 0 && maxAwards > TASK_LIMITS.maxAwardsMax)
|
|
104580
105185
|
throw new UsageError("--max-awards must be between 1 and 50.");
|
|
104581
105186
|
if (parsed.one("--webhook") !== void 0) httpsUrl2(parsed.one("--webhook"), "--webhook");
|
|
104582
|
-
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await
|
|
105187
|
+
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await readFile30(briefPath, "utf8");
|
|
104583
105188
|
const input2 = {
|
|
104584
105189
|
title: title.trim(),
|
|
104585
105190
|
description: brief.trim(),
|
|
@@ -105165,13 +105770,13 @@ async function watchTask(id2, parsed, json2, io, dependencies, now) {
|
|
|
105165
105770
|
}
|
|
105166
105771
|
}
|
|
105167
105772
|
cursor2 = Math.max(cursor2, page.nextAfter, ...events.map((event) => event.sequence));
|
|
105168
|
-
const
|
|
105169
|
-
if (
|
|
105773
|
+
const remaining2 = deadline - clock().getTime();
|
|
105774
|
+
if (remaining2 <= 0)
|
|
105170
105775
|
throw new TaskCommandError(
|
|
105171
105776
|
"timeout",
|
|
105172
105777
|
`Task watch timed out after ${parsed.one("--timeout") ?? "7d"}.`
|
|
105173
105778
|
);
|
|
105174
|
-
await context.sleep(Math.min(interval,
|
|
105779
|
+
await context.sleep(Math.min(interval, remaining2));
|
|
105175
105780
|
}
|
|
105176
105781
|
}
|
|
105177
105782
|
function expandDeliveryFiles(argv) {
|
|
@@ -106257,7 +106862,7 @@ async function referencedSleep(milliseconds, signal) {
|
|
|
106257
106862
|
}
|
|
106258
106863
|
|
|
106259
106864
|
// ../cli/src/vault.ts
|
|
106260
|
-
import { join as
|
|
106865
|
+
import { join as join28 } from "node:path";
|
|
106261
106866
|
var VAULT_USAGE = "Usage: vapi vault protect|unprotect|lock|unlock|status [--json]";
|
|
106262
106867
|
var RESTORE_USAGE = "Usage: vapi restore [--accounts <n> | --from-owner [--owner <0x\u2026>]] [--json]";
|
|
106263
106868
|
var LEGACY_PASSWORD_NOTICE = "VAPI_KEYSTORE_PASSWORD is deprecated for vault passwords; use VAPI_VAULT_PASSWORD instead.";
|
|
@@ -106301,7 +106906,7 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
106301
106906
|
}
|
|
106302
106907
|
const accountCount = parseRestoreAccountCount(parsed.one("--accounts"));
|
|
106303
106908
|
const paths = getVapiPaths();
|
|
106304
|
-
const path =
|
|
106909
|
+
const path = join28(paths.directory, "vault.json");
|
|
106305
106910
|
if (await fileExists2(path)) {
|
|
106306
106911
|
throw new Error(
|
|
106307
106912
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
@@ -106458,7 +107063,7 @@ function requireNoArguments(argv) {
|
|
|
106458
107063
|
parseArguments(argv, { valueOptions: /* @__PURE__ */ new Set(), maximumPositionals: 0 });
|
|
106459
107064
|
}
|
|
106460
107065
|
function vaultPath() {
|
|
106461
|
-
return
|
|
107066
|
+
return join28(getVapiPaths().directory, "vault.json");
|
|
106462
107067
|
}
|
|
106463
107068
|
function quietIo(io) {
|
|
106464
107069
|
return { stdout: () => void 0, stderr: io.stderr };
|
|
@@ -106526,6 +107131,10 @@ Usage:
|
|
|
106526
107131
|
vapi login [--account <name>] [--label <name>] [--publish] [--no-browser] [--json]
|
|
106527
107132
|
vapi logout [--account <name>] [--json]
|
|
106528
107133
|
vapi whoami [--account <name>] [--json]
|
|
107134
|
+
vapi claude [--vapi|--own] [--model <m>] [--use-balance] [--account <name>] [<claude args>...]
|
|
107135
|
+
vapi codex [--vapi|--own] [--model <id>] [--use-balance] [--account <name>] [<codex args>...]
|
|
107136
|
+
vapi code install [--yes] [--no-alias] [--account <name>] [--json]
|
|
107137
|
+
vapi code uninstall [--json]
|
|
106529
107138
|
vapi router models [--account <name>] [--json]
|
|
106530
107139
|
vapi router usage [--account <name>] [--json]
|
|
106531
107140
|
vapi router chat --model <id> [--system <text>] [--max-tokens <n>] "<prompt>" [--account <name>] [--json]
|
|
@@ -106745,6 +107354,8 @@ async function confirmWalletName(name, prompt, refusal, dependencies) {
|
|
|
106745
107354
|
if (typed.trim() !== name) throw new KeystoreError(refusal);
|
|
106746
107355
|
}
|
|
106747
107356
|
async function runCli(argv = process.argv.slice(2), io = processIo, dependencies = {}) {
|
|
107357
|
+
const firstArgument = argv.find((argument) => argument !== "--json");
|
|
107358
|
+
const codeLaunch = firstArgument === "claude" || firstArgument === "codex";
|
|
106748
107359
|
let json2 = argv.includes("--json");
|
|
106749
107360
|
const taskInvocation = argv.find((argument) => argument !== "--json") === "task";
|
|
106750
107361
|
const resultFile = runResultFile(argv);
|
|
@@ -106753,15 +107364,15 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
106753
107364
|
stderr: (message) => io.stderr(redactDetachedRunText(message, getEnvironment(dependencies)))
|
|
106754
107365
|
};
|
|
106755
107366
|
try {
|
|
106756
|
-
const parsedInvocation = removeJsonFlag(argv);
|
|
107367
|
+
const parsedInvocation = removeJsonFlag(argv, codeLaunch);
|
|
106757
107368
|
json2 = parsedInvocation.json;
|
|
106758
|
-
const hasWalletOption = parsedInvocation.args.includes(WALLET_OPTION5);
|
|
107369
|
+
const hasWalletOption = !codeLaunch && parsedInvocation.args.includes(WALLET_OPTION5);
|
|
106759
107370
|
const hasAccountOption = parsedInvocation.args.includes(ACCOUNT_OPTION2);
|
|
106760
107371
|
if (hasWalletOption && hasAccountOption) {
|
|
106761
107372
|
throw new UsageError("--wallet and --account cannot be used together.");
|
|
106762
107373
|
}
|
|
106763
107374
|
if (hasWalletOption) io.stderr(WALLET_OPTION_DEPRECATION);
|
|
106764
|
-
const args = parsedInvocation.args.map(
|
|
107375
|
+
const args = codeLaunch ? parsedInvocation.args : parsedInvocation.args.map(
|
|
106765
107376
|
(argument) => argument === WALLET_OPTION5 ? ACCOUNT_OPTION2 : argument
|
|
106766
107377
|
);
|
|
106767
107378
|
const command = args[0];
|
|
@@ -106857,6 +107468,15 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
106857
107468
|
await whoamiCommand(args.slice(1), json2, io, dependencies);
|
|
106858
107469
|
exitCode = 0;
|
|
106859
107470
|
break;
|
|
107471
|
+
case "claude":
|
|
107472
|
+
exitCode = await claudeCommand(args.slice(1), json2, io, dependencies);
|
|
107473
|
+
break;
|
|
107474
|
+
case "codex":
|
|
107475
|
+
exitCode = await codexCommand(args.slice(1), json2, io, dependencies);
|
|
107476
|
+
break;
|
|
107477
|
+
case "code":
|
|
107478
|
+
exitCode = await codeCommand(args.slice(1), json2, io, dependencies);
|
|
107479
|
+
break;
|
|
106860
107480
|
case "router":
|
|
106861
107481
|
await routerCommand(args.slice(1), json2, io, dependencies);
|
|
106862
107482
|
exitCode = 0;
|
|
@@ -106894,7 +107514,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
106894
107514
|
break;
|
|
106895
107515
|
case "unlock":
|
|
106896
107516
|
io.stderr("vapi unlock is now vapi vault unlock; the old name works for one release.");
|
|
106897
|
-
if (await fileExists2(
|
|
107517
|
+
if (await fileExists2(join29(getVapiPaths().directory, "vault.json"))) {
|
|
106898
107518
|
parseArguments(args.slice(1), {
|
|
106899
107519
|
valueOptions: /* @__PURE__ */ new Set([WALLET_OPTION5]),
|
|
106900
107520
|
maximumPositionals: 0
|
|
@@ -107100,7 +107720,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
107100
107720
|
address: account.address,
|
|
107101
107721
|
accounts,
|
|
107102
107722
|
config: paths.config,
|
|
107103
|
-
vault:
|
|
107723
|
+
vault: join29(paths.directory, "vault.json"),
|
|
107104
107724
|
...configRewrites.length > 0 ? { configRewrites } : {},
|
|
107105
107725
|
custody: "self",
|
|
107106
107726
|
warning: CUSTODY_NOTICE,
|
|
@@ -107239,7 +107859,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
107239
107859
|
const result = {
|
|
107240
107860
|
address: account.address,
|
|
107241
107861
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
107242
|
-
vault:
|
|
107862
|
+
vault: join29(paths.directory, "vault.json"),
|
|
107243
107863
|
...label === void 0 ? {} : { label },
|
|
107244
107864
|
spendCaps: created.entry.spendCaps,
|
|
107245
107865
|
isDefault,
|
|
@@ -107279,7 +107899,7 @@ function formatCaps2(caps) {
|
|
|
107279
107899
|
function walletListResult(store, wallets, unlocked) {
|
|
107280
107900
|
return {
|
|
107281
107901
|
default: store.defaultName ?? null,
|
|
107282
|
-
vault:
|
|
107902
|
+
vault: join29(store.home, "vault.json"),
|
|
107283
107903
|
wallets: wallets.map((wallet) => ({
|
|
107284
107904
|
name: wallet.name,
|
|
107285
107905
|
...wallet.address === void 0 ? {} : { address: wallet.address },
|
|
@@ -108552,7 +109172,7 @@ function formatClaimed(origin, claimed) {
|
|
|
108552
109172
|
}
|
|
108553
109173
|
var EXPORT_KEY_WARNING = "Anyone with this key can spend the wallet. Never paste it into a website or chat.";
|
|
108554
109174
|
async function deviceVaultKey2(store, dependencies) {
|
|
108555
|
-
const path =
|
|
109175
|
+
const path = join29(store.home, "vault.json");
|
|
108556
109176
|
const metadata = await readVaultFileUnlocked(path);
|
|
108557
109177
|
const secrets = getSecretStore(dependencies);
|
|
108558
109178
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
@@ -108645,7 +109265,7 @@ async function backupCommand(argv, json2, io, dependencies) {
|
|
|
108645
109265
|
const target = await targetWallet(parsed, dependencies);
|
|
108646
109266
|
const vaultAccount = await target.store.hasVaultAccount(target.name);
|
|
108647
109267
|
if (vaultAccount) {
|
|
108648
|
-
const vault = await readVaultFileUnlocked(
|
|
109268
|
+
const vault = await readVaultFileUnlocked(join29(target.store.home, "vault.json"));
|
|
108649
109269
|
if (vault.accounts.some((account) => account.name === target.name && account.kind === "imported")) {
|
|
108650
109270
|
throw new KeystoreError(
|
|
108651
109271
|
`Account ${target.name} was imported and is not recoverable from the vault phrase. Back it up with vapi export-key --account ${target.name}.`
|
|
@@ -108722,7 +109342,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
108722
109342
|
const existed = store.has(name);
|
|
108723
109343
|
if (existed && !parsed.has("--replace")) {
|
|
108724
109344
|
const address4 = await store.readAddress(name);
|
|
108725
|
-
const location = await store.hasVaultAccount(name) ?
|
|
109345
|
+
const location = await store.hasVaultAccount(name) ? join29(store.home, "vault.json") : store.pathFor(name);
|
|
108726
109346
|
throw new Error(
|
|
108727
109347
|
[
|
|
108728
109348
|
`Wallet ${name} already exists at ${location}.`,
|
|
@@ -108758,7 +109378,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
108758
109378
|
const result = {
|
|
108759
109379
|
address: account.address,
|
|
108760
109380
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
108761
|
-
vault:
|
|
109381
|
+
vault: join29(paths.directory, "vault.json"),
|
|
108762
109382
|
...previousKeystore ? { previousKeystore } : {},
|
|
108763
109383
|
message: "Wallet imported. Its encrypted key stays on this machine."
|
|
108764
109384
|
};
|
|
@@ -109091,7 +109711,7 @@ function formatFund(address4, url2, opened) {
|
|
|
109091
109711
|
function openInBrowser(url2) {
|
|
109092
109712
|
const opener = process.platform === "darwin" ? { command: "open", args: [url2] } : process.platform === "win32" ? { command: "cmd", args: ["/c", "start", "", url2] } : { command: "xdg-open", args: [url2] };
|
|
109093
109713
|
try {
|
|
109094
|
-
const child =
|
|
109714
|
+
const child = spawn5(opener.command, opener.args, { stdio: "ignore", detached: true });
|
|
109095
109715
|
child.on("error", () => void 0);
|
|
109096
109716
|
child.unref();
|
|
109097
109717
|
return true;
|
|
@@ -109283,11 +109903,13 @@ function parseArguments(argv, spec) {
|
|
|
109283
109903
|
has: (name) => flags.has(name)
|
|
109284
109904
|
};
|
|
109285
109905
|
}
|
|
109286
|
-
function removeJsonFlag(argv) {
|
|
109906
|
+
function removeJsonFlag(argv, preserveForwarded = false) {
|
|
109287
109907
|
let json2 = false;
|
|
109288
109908
|
const args = [];
|
|
109909
|
+
let forwarding = false;
|
|
109289
109910
|
for (const argument of argv) {
|
|
109290
|
-
if (argument
|
|
109911
|
+
if (preserveForwarded && argument === "--") forwarding = true;
|
|
109912
|
+
if (argument !== "--json" || forwarding) {
|
|
109291
109913
|
args.push(argument);
|
|
109292
109914
|
continue;
|
|
109293
109915
|
}
|
|
@@ -109388,7 +110010,7 @@ function parseInitNetworks(value) {
|
|
|
109388
110010
|
|
|
109389
110011
|
// ../cli/src/update-check.ts
|
|
109390
110012
|
import { lookup } from "node:dns/promises";
|
|
109391
|
-
import { mkdir as
|
|
110013
|
+
import { mkdir as mkdir22, readFile as readFile31, writeFile as writeFile13 } from "node:fs/promises";
|
|
109392
110014
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
109393
110015
|
var CHECK_TIMEOUT_MS = 1500;
|
|
109394
110016
|
var LATEST_URL = "https://registry.npmjs.org/vapi-network/latest";
|
|
@@ -109405,7 +110027,7 @@ async function runCliWithUpdateCheck(argv = process.argv.slice(2), io = {
|
|
|
109405
110027
|
async function checkForUpdate(options = {}) {
|
|
109406
110028
|
const env = options.env ?? process.env;
|
|
109407
110029
|
const argv = options.argv ?? process.argv.slice(2);
|
|
109408
|
-
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) {
|
|
110030
|
+
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) {
|
|
109409
110031
|
return void 0;
|
|
109410
110032
|
}
|
|
109411
110033
|
const controller = new AbortController();
|
|
@@ -109432,7 +110054,7 @@ async function latestNotice(options, env, signal) {
|
|
|
109432
110054
|
const now = (options.nowMs ?? Date.now)();
|
|
109433
110055
|
let cached2;
|
|
109434
110056
|
try {
|
|
109435
|
-
const value = JSON.parse(await
|
|
110057
|
+
const value = JSON.parse(await readFile31(paths.updateCheck, "utf8"));
|
|
109436
110058
|
if (isRecord13(value) && typeof value.checkedAt === "number" && Number.isFinite(value.checkedAt) && typeof value.latest === "string" && parseVersion(value.latest)) {
|
|
109437
110059
|
cached2 = { checkedAt: value.checkedAt, latest: value.latest };
|
|
109438
110060
|
}
|
|
@@ -109441,9 +110063,9 @@ async function latestNotice(options, env, signal) {
|
|
|
109441
110063
|
signal.throwIfAborted();
|
|
109442
110064
|
let latest = cached2?.latest ?? CLI_VERSION;
|
|
109443
110065
|
if (cached2 === void 0 || now - cached2.checkedAt >= CHECK_INTERVAL_MS || now < cached2.checkedAt) {
|
|
109444
|
-
await
|
|
110066
|
+
await mkdir22(paths.directory, { recursive: true });
|
|
109445
110067
|
signal.throwIfAborted();
|
|
109446
|
-
await
|
|
110068
|
+
await writeFile13(paths.updateCheck, JSON.stringify({ checkedAt: now, latest }), { mode: 384 });
|
|
109447
110069
|
signal.throwIfAborted();
|
|
109448
110070
|
const fetchImpl = options.fetchImpl ?? createPublicFetch({
|
|
109449
110071
|
allowPrivateNetwork: false,
|
|
@@ -109470,7 +110092,7 @@ async function latestNotice(options, env, signal) {
|
|
|
109470
110092
|
return void 0;
|
|
109471
110093
|
}
|
|
109472
110094
|
latest = body.version;
|
|
109473
|
-
await
|
|
110095
|
+
await writeFile13(paths.updateCheck, JSON.stringify({ checkedAt: now, latest }), { mode: 384 });
|
|
109474
110096
|
}
|
|
109475
110097
|
signal.throwIfAborted();
|
|
109476
110098
|
return isNewerVersion(latest, CLI_VERSION) ? `vapi-network ${latest} is available (you have ${CLI_VERSION}). Update: npm i -g vapi-network@latest` : void 0;
|