vana-cli 0.28.2 → 0.29.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/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +146 -58
- package/dist/cli/index.js.map +1 -1
- package/dist/personal-server/index.d.ts +4 -0
- package/dist/personal-server/index.d.ts.map +1 -1
- package/dist/personal-server/index.js +7 -0
- package/dist/personal-server/index.js.map +1 -1
- package/dist/personal-server/registered.d.ts +10 -0
- package/dist/personal-server/registered.d.ts.map +1 -1
- package/dist/personal-server/registered.js +24 -0
- package/dist/personal-server/registered.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAQL,YAAY,EAIb,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAQL,YAAY,EAIb,MAAM,kBAAkB,CAAC;AAgB1B,OAAO,KAAK,EACV,UAAU,EAEV,gBAAgB,EAEhB,SAAS,EACT,YAAY,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAwKjE,UAAU,cAAc;IACtB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AAED,UAAU,iBAAiB;IACzB,CAAC,MAAM,EAAE,MAAM,GAAG;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ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MAAM,EAAE,CAAA;CAAE,GAAG,IAAI,CAAC,CAOrC;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B;IAAE,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,IAAI,CAoD5B;AA6BD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUrD;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE;IACJ,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB,EACD,KAAK,EAAE;IACL,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB,GACA,MAAM,CAaR;AAsBD,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,YAAY,CAAC,WAAW,CAAC,GAAG,IAAI,GAAG,SAAS,GACtD,OAAO,CAOT;AAqMD,qBAAa,2BAA4B,SAAQ,KAAK;CAAG;AAEzD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,GAAE,gBAAwC,EACvD,QAAQ,SAAmB,EAC3B,WAAW,SAAkB,GAC5B,MAAM,EAAE,CAkBV;AAgDD,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EAAE,EACrB,eAAe,EAAE,MAAM,GACtB,MAAM,CA+BR"}
|
package/dist/cli/index.js
CHANGED
|
@@ -29,17 +29,19 @@ const vanaPromptTheme = {
|
|
|
29
29
|
};
|
|
30
30
|
import { createConnectRenderer, createHumanRenderer, createLoginRenderer, formatDisplayPath, formatRelativeTime, } from "./render/index.js";
|
|
31
31
|
import { CliOutcomeStatus, migrateLegacyDataHome, getBrowserProfilesDir, getConnectorCacheDir, getLogsDir, getSessionsDir, getSourceResultPath, readCliState, readCliConfig, updateCliConfig, updateSourceState, } from "../core/index.js";
|
|
32
|
+
import { getVanaHome } from "../core/paths.js";
|
|
32
33
|
import { UnknownNetworkError, VANA_NETWORKS, isVanaNetworkName, resolveNetwork, } from "../core/network.js";
|
|
33
34
|
import { CliExitCode } from "../core/exit-codes.js";
|
|
34
35
|
import { registerAppCommands } from "./app/index.js";
|
|
35
|
-
import { lookupRegisteredServers } from "../personal-server/registered.js";
|
|
36
|
+
import { checkRegisteredServers, lookupRegisteredServers, } from "../personal-server/registered.js";
|
|
36
37
|
import { fetchConnectorToCache, listAvailableSources, readCachedConnectorMetadata, } from "../connectors/registry.js";
|
|
37
|
-
import { detectPersonalServerTarget, ingestResult, personalServerOwnerMismatch, resolvePersonalServerAuthConfig, } from "../personal-server/index.js";
|
|
38
|
+
import { detectPersonalServerTarget, ingestResult, personalServerOwnerMismatch, urlsMatch, resolvePersonalServerAuthConfig, } from "../personal-server/index.js";
|
|
38
39
|
import { findDataConnectorsDir, ManagedPlaywrightRuntime, } from "../runtime/index.js";
|
|
39
40
|
import { getPdppProfileRoot } from "../pdpp/host.js";
|
|
40
41
|
import { runServerStart } from "./server-start.js";
|
|
41
42
|
import { findRunningServers } from "../personal-server/local/server.js";
|
|
42
|
-
import { stopLocalServer } from "../personal-server/local/detach.js";
|
|
43
|
+
import { runningServerPid, stopLocalServer, } from "../personal-server/local/detach.js";
|
|
44
|
+
import { localServerDataDir } from "../personal-server/local/config.js";
|
|
43
45
|
import { isPdppSource, PdppRuntime } from "../pdpp/runtime.js";
|
|
44
46
|
import { listAvailableSkills, installSkill, readInstalledSkills, } from "../skills/index.js";
|
|
45
47
|
import { queryStatus, querySources, queryDataList, queryDataShow, queryDoctor, } from "./queries.js";
|
|
@@ -424,10 +426,11 @@ Examples:
|
|
|
424
426
|
});
|
|
425
427
|
server
|
|
426
428
|
.command("status")
|
|
427
|
-
.description("
|
|
429
|
+
.description("Where your data is served from, where it is stored, and old registrations")
|
|
430
|
+
.option("--all", "List every old registration, not just the count")
|
|
428
431
|
.option("--json", "Output machine-readable JSON")
|
|
429
|
-
.action(async () => {
|
|
430
|
-
process.exitCode = await runCommandWithTelemetry({ ...telemetryBaseContext, command: "server", subcommand: "status" }, async () => runServerStatus(parsedOptions));
|
|
432
|
+
.action(async (statusOptions) => {
|
|
433
|
+
process.exitCode = await runCommandWithTelemetry({ ...telemetryBaseContext, command: "server", subcommand: "status" }, async () => runServerStatus(parsedOptions, statusOptions));
|
|
431
434
|
});
|
|
432
435
|
server
|
|
433
436
|
.command("set-url <url>")
|
|
@@ -2021,14 +2024,48 @@ async function runDoctor(options) {
|
|
|
2021
2024
|
}
|
|
2022
2025
|
return 0;
|
|
2023
2026
|
}
|
|
2024
|
-
|
|
2027
|
+
/** Which network a server serves, from the gateway it reports. */
|
|
2028
|
+
function networkOfGateway(gatewayUrl) {
|
|
2029
|
+
if (typeof gatewayUrl !== "string")
|
|
2030
|
+
return null;
|
|
2031
|
+
return /dp-rpc\.vana\.org/.test(gatewayUrl) ? "mainnet" : "moksha";
|
|
2032
|
+
}
|
|
2033
|
+
/** Where the running server keeps its data on this machine, when known. */
|
|
2034
|
+
function localDataDir(target, network) {
|
|
2035
|
+
if (!target.url || !network)
|
|
2036
|
+
return null;
|
|
2037
|
+
const saved = loadCredentials()?.personal_server;
|
|
2038
|
+
if (saved?.started_by === "vana-server-start" &&
|
|
2039
|
+
urlsMatch(saved.url, target.url) &&
|
|
2040
|
+
runningServerPid(network)) {
|
|
2041
|
+
return { path: localServerDataDir(network), runBy: "cli" };
|
|
2042
|
+
}
|
|
2043
|
+
const desktop = path.join(getVanaHome(), "desktop", "personal-server");
|
|
2044
|
+
const perNetwork = path.join(desktop, network);
|
|
2045
|
+
if (fs.existsSync(perNetwork))
|
|
2046
|
+
return { path: perNetwork, runBy: "desktop" };
|
|
2047
|
+
if (fs.existsSync(desktop))
|
|
2048
|
+
return { path: desktop, runBy: "desktop" };
|
|
2049
|
+
return null;
|
|
2050
|
+
}
|
|
2051
|
+
async function runServerStatus(options, statusOptions = {}) {
|
|
2025
2052
|
const emit = createEmitter(options);
|
|
2026
2053
|
const target = await detectPersonalServerTarget();
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2054
|
+
const account = loadCredentials()?.account.address;
|
|
2055
|
+
const owner = target.health?.owner ?? (account && account !== "env" ? account : null);
|
|
2056
|
+
// Every registration this owner has, checked from outside: the live one is
|
|
2057
|
+
// where apps actually reach the data; the rest are old server identities.
|
|
2058
|
+
const registrations = owner
|
|
2059
|
+
? await checkRegisteredServers(await lookupRegisteredServers(owner), owner)
|
|
2031
2060
|
: [];
|
|
2061
|
+
const localIdentity = target.health?.identity?.toLowerCase();
|
|
2062
|
+
const live = registrations.find((server) => server.reachable &&
|
|
2063
|
+
server.serverAddress.toLowerCase() === localIdentity) ??
|
|
2064
|
+
registrations.find((server) => server.reachable) ??
|
|
2065
|
+
null;
|
|
2066
|
+
const stale = registrations.filter((server) => !server.reachable);
|
|
2067
|
+
const network = networkOfGateway(target.health?.gatewayUrl) ?? live?.network ?? null;
|
|
2068
|
+
const dataDir = localDataDir(target, network);
|
|
2032
2069
|
const state = await readCliState();
|
|
2033
2070
|
// Count scopes from state
|
|
2034
2071
|
let totalScopeCount = 0;
|
|
@@ -2042,7 +2079,12 @@ async function runServerStatus(options) {
|
|
|
2042
2079
|
state: target.state,
|
|
2043
2080
|
url: target.url,
|
|
2044
2081
|
source: target.source,
|
|
2045
|
-
|
|
2082
|
+
owner,
|
|
2083
|
+
publicUrl: live?.url ?? null,
|
|
2084
|
+
publicNetwork: live?.network ?? null,
|
|
2085
|
+
dataDir: dataDir?.path ?? null,
|
|
2086
|
+
runBy: dataDir?.runBy ?? null,
|
|
2087
|
+
registeredServers: registrations,
|
|
2046
2088
|
health: target.health,
|
|
2047
2089
|
scopeCount: totalScopeCount,
|
|
2048
2090
|
})}\n`);
|
|
@@ -2050,50 +2092,58 @@ async function runServerStatus(options) {
|
|
|
2050
2092
|
}
|
|
2051
2093
|
emit.title("Personal Server");
|
|
2052
2094
|
emit.blank();
|
|
2095
|
+
if (live) {
|
|
2096
|
+
emit.keyValue("Public URL", `${live.url} (${live.network}, reachable)`, "success");
|
|
2097
|
+
}
|
|
2098
|
+
else if (target.state === "available") {
|
|
2099
|
+
emit.keyValue("Public URL", "none: apps cannot reach your data", "warning");
|
|
2100
|
+
}
|
|
2101
|
+
else {
|
|
2102
|
+
emit.keyValue("Public URL", "none: no server of yours is answering", "warning");
|
|
2103
|
+
}
|
|
2053
2104
|
if (target.url) {
|
|
2054
|
-
const
|
|
2055
|
-
? "
|
|
2056
|
-
:
|
|
2057
|
-
? "
|
|
2058
|
-
: target.source === "
|
|
2059
|
-
? "
|
|
2105
|
+
const runBy = dataDir?.runBy === "cli"
|
|
2106
|
+
? "vana server start"
|
|
2107
|
+
: dataDir?.runBy === "desktop"
|
|
2108
|
+
? "Vana Desktop"
|
|
2109
|
+
: target.source === "scan"
|
|
2110
|
+
? "found running"
|
|
2060
2111
|
: target.source === "env"
|
|
2061
|
-
? "
|
|
2062
|
-
:
|
|
2063
|
-
emit.keyValue("URL", `${target.url} ${
|
|
2112
|
+
? "from VANA_PERSONAL_SERVER_URL"
|
|
2113
|
+
: "saved";
|
|
2114
|
+
emit.keyValue("Local URL", `${target.url} (${runBy})`, "muted");
|
|
2115
|
+
}
|
|
2116
|
+
else {
|
|
2117
|
+
emit.keyValue("Local URL", "no server running on this machine", "muted");
|
|
2064
2118
|
}
|
|
2065
|
-
|
|
2066
|
-
emit.keyValue("
|
|
2119
|
+
if (dataDir) {
|
|
2120
|
+
emit.keyValue("Data on disk", formatDisplayPath(dataDir.path), "muted");
|
|
2121
|
+
}
|
|
2122
|
+
if (live) {
|
|
2123
|
+
emit.keyValue("Backup", "encrypted in Vana storage, follows your account", "muted");
|
|
2067
2124
|
}
|
|
2068
|
-
const stateLabel = target.state === "available" ? "healthy" : "Not connected";
|
|
2069
|
-
emit.keyValue("Status", stateLabel, target.state === "available" ? "success" : "warning");
|
|
2070
2125
|
if (target.health) {
|
|
2071
2126
|
emit.keyValue("Version", target.health.version, "muted");
|
|
2127
|
+
emit.keyValue("Uptime", formatUptime(target.health.uptime), "muted");
|
|
2072
2128
|
}
|
|
2129
|
+
if (owner)
|
|
2130
|
+
emit.keyValue("Owner", owner, "muted");
|
|
2073
2131
|
if (totalScopeCount > 0) {
|
|
2074
2132
|
emit.keyValue("Scopes", `${totalScopeCount} stored`, "muted");
|
|
2075
2133
|
}
|
|
2076
|
-
if (
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
}
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
if (target.health) {
|
|
2085
|
-
emit.keyValue("Uptime", formatUptime(target.health.uptime), "muted");
|
|
2086
|
-
if (target.health.owner) {
|
|
2087
|
-
emit.keyValue("Owner", target.health.owner, "muted");
|
|
2134
|
+
if (stale.length > 0) {
|
|
2135
|
+
if (statusOptions.all) {
|
|
2136
|
+
for (const server of stale) {
|
|
2137
|
+
emit.keyValue("Old server", `${server.url} (${server.network}, not answering)`, "muted");
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
else {
|
|
2141
|
+
emit.keyValue("Old servers", `${stale.length} not answering (${emit.code("vana server status --all")})`, "muted");
|
|
2088
2142
|
}
|
|
2089
|
-
}
|
|
2090
|
-
if (target.source === "scan" && target.url) {
|
|
2091
|
-
emit.blank();
|
|
2092
|
-
emit.detail(`Save with ${emit.code(`vana server set-url ${target.url}`)}.`);
|
|
2093
2143
|
}
|
|
2094
2144
|
if (target.state !== "available") {
|
|
2095
2145
|
emit.blank();
|
|
2096
|
-
emit.next("vana server
|
|
2146
|
+
emit.next("vana server start --detach");
|
|
2097
2147
|
}
|
|
2098
2148
|
emit.blank();
|
|
2099
2149
|
emit.detail(`More: ${emit.code("vana server sync")} | ${emit.code("vana server data")} | ${emit.code("vana server --help")}`);
|
|
@@ -5100,15 +5150,6 @@ async function runLogin(options, serverUrl, clientId) {
|
|
|
5100
5150
|
const emit = createEmitter(options);
|
|
5101
5151
|
emit.success(`Already logged in as ${formatAddress(existing.account.address)}`);
|
|
5102
5152
|
const server = await describeLoginPersonalServer(existing.personal_server);
|
|
5103
|
-
// A live account session says nothing about the Personal Server, and a
|
|
5104
|
-
// server with no session is exactly what `connect` fails to sync to.
|
|
5105
|
-
// Finish that job here rather than printing this same command back.
|
|
5106
|
-
if (server &&
|
|
5107
|
-
!server.authenticated &&
|
|
5108
|
-
!options.noInput &&
|
|
5109
|
-
getAuthTarget(server.url) === "self-hosted") {
|
|
5110
|
-
return loginToPersonalServer(server.url, options);
|
|
5111
|
-
}
|
|
5112
5153
|
if (server) {
|
|
5113
5154
|
emit.keyValue("Personal Server", server.authenticated
|
|
5114
5155
|
? server.url
|
|
@@ -5117,7 +5158,7 @@ async function runLogin(options, serverUrl, clientId) {
|
|
|
5117
5158
|
emit.info(` Auth expires in ${formatExpiresIn(existing.account.expires_at)}`);
|
|
5118
5159
|
emit.blank();
|
|
5119
5160
|
emit.info(" Run `vana logout` to sign in as someone else.");
|
|
5120
|
-
await
|
|
5161
|
+
return (await finishServerSetup(existing.account.address, options)) ?? 0;
|
|
5121
5162
|
}
|
|
5122
5163
|
return 0;
|
|
5123
5164
|
}
|
|
@@ -5219,9 +5260,15 @@ async function runLogin(options, serverUrl, clientId) {
|
|
|
5219
5260
|
renderer.detail(`Personal Server: ${authedCreds.personal_server.url}`);
|
|
5220
5261
|
}
|
|
5221
5262
|
else {
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5263
|
+
const running = await findOwnRunningServer(authedCreds.account.address);
|
|
5264
|
+
if (running) {
|
|
5265
|
+
renderer.detail(`Personal Server: ${running} (running)`);
|
|
5266
|
+
}
|
|
5267
|
+
else {
|
|
5268
|
+
renderer.detail("No Personal Server found for this account yet.");
|
|
5269
|
+
renderer.next("vana server start --detach");
|
|
5270
|
+
renderer.detail("Or point at one you already run: vana server set-url <url>");
|
|
5271
|
+
}
|
|
5225
5272
|
}
|
|
5226
5273
|
renderer.detail("Credentials saved to ~/.vana/auth.json");
|
|
5227
5274
|
},
|
|
@@ -5239,9 +5286,9 @@ async function runLogin(options, serverUrl, clientId) {
|
|
|
5239
5286
|
openBrowser: Boolean(process.stdout.isTTY) && !options.noInput,
|
|
5240
5287
|
});
|
|
5241
5288
|
renderer.cleanup();
|
|
5242
|
-
if (creds)
|
|
5243
|
-
|
|
5244
|
-
return creds
|
|
5289
|
+
if (!creds)
|
|
5290
|
+
return 1;
|
|
5291
|
+
return (await finishServerSetup(creds.account.address, options)) ?? 0;
|
|
5245
5292
|
}
|
|
5246
5293
|
function serverStartIo(options) {
|
|
5247
5294
|
return {
|
|
@@ -5256,6 +5303,47 @@ function serverStartIo(options) {
|
|
|
5256
5303
|
confirm: (message) => confirm({ message, default: true, ...vanaPromptTheme }),
|
|
5257
5304
|
};
|
|
5258
5305
|
}
|
|
5306
|
+
/** The URL of a running Personal Server this account owns, if any. */
|
|
5307
|
+
async function findOwnRunningServer(address) {
|
|
5308
|
+
try {
|
|
5309
|
+
const target = await detectPersonalServerTarget();
|
|
5310
|
+
return target.state === "available" &&
|
|
5311
|
+
target.url &&
|
|
5312
|
+
target.health?.owner &&
|
|
5313
|
+
!personalServerOwnerMismatch(target.health.owner, address)
|
|
5314
|
+
? target.url
|
|
5315
|
+
: null;
|
|
5316
|
+
}
|
|
5317
|
+
catch {
|
|
5318
|
+
return null;
|
|
5319
|
+
}
|
|
5320
|
+
}
|
|
5321
|
+
/**
|
|
5322
|
+
* The last step of a login at a terminal: make this account's Personal
|
|
5323
|
+
* Server ready to take `connect` writes. A running server of this account
|
|
5324
|
+
* that has not approved the CLI yet (Vana Desktop's, typically) gets that
|
|
5325
|
+
* one-time approval now; with none running, offer to start one. Returns an
|
|
5326
|
+
* exit code when it ran the server approval, else null.
|
|
5327
|
+
*/
|
|
5328
|
+
async function finishServerSetup(address, options) {
|
|
5329
|
+
if (options.json ||
|
|
5330
|
+
options.noInput ||
|
|
5331
|
+
!process.stdin.isTTY ||
|
|
5332
|
+
!process.stdout.isTTY) {
|
|
5333
|
+
return null;
|
|
5334
|
+
}
|
|
5335
|
+
const running = await findOwnRunningServer(address);
|
|
5336
|
+
if (running) {
|
|
5337
|
+
const saved = loadCredentials()?.personal_server;
|
|
5338
|
+
const approved = Boolean(saved?.session_token && urlsMatch(saved.url, running));
|
|
5339
|
+
if (approved || getAuthTarget(running) !== "self-hosted")
|
|
5340
|
+
return null;
|
|
5341
|
+
process.stderr.write(`\n Your Personal Server at ${running} needs to approve this CLI once.\n`);
|
|
5342
|
+
return loginToPersonalServer(running, options);
|
|
5343
|
+
}
|
|
5344
|
+
await offerServerStart(address, options);
|
|
5345
|
+
return null;
|
|
5346
|
+
}
|
|
5259
5347
|
/**
|
|
5260
5348
|
* After a login at a terminal: offer to start this account's Personal Server
|
|
5261
5349
|
* in the background when none of its servers is running. Asked, never done
|