fix(new-setup): always source ONECLI_URL from installer stdout
Match v1 behavior: drop getApiHost() (which was returning the CLI default https://app.onecli.sh) and always extract the gateway URL from the install script's stdout, then apply it via onecli config set api-host and .env. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -37,20 +37,6 @@ function onecliVersion(): string | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getApiHost(): string | null {
|
|
||||||
try {
|
|
||||||
const out = execFileSync('onecli', ['config', 'get', 'api-host'], {
|
|
||||||
encoding: 'utf-8',
|
|
||||||
env: childEnv(),
|
|
||||||
stdio: ['ignore', 'pipe', 'ignore'],
|
|
||||||
}).trim();
|
|
||||||
const parsed = JSON.parse(out) as { value?: unknown };
|
|
||||||
return typeof parsed.value === 'string' && parsed.value ? parsed.value : null;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function extractUrlFromOutput(output: string): string | null {
|
function extractUrlFromOutput(output: string): string | null {
|
||||||
const match = output.match(/https?:\/\/[\w.\-]+(?::\d+)?/);
|
const match = output.match(/https?:\/\/[\w.\-]+(?::\d+)?/);
|
||||||
return match ? match[0] : null;
|
return match ? match[0] : null;
|
||||||
@@ -123,60 +109,49 @@ async function pollHealth(url: string, timeoutMs: number): Promise<boolean> {
|
|||||||
export async function run(_args: string[]): Promise<void> {
|
export async function run(_args: string[]): Promise<void> {
|
||||||
ensureShellProfilePath();
|
ensureShellProfilePath();
|
||||||
|
|
||||||
let installOutput = '';
|
log.info('Installing OneCLI gateway and CLI');
|
||||||
let present = !!onecliVersion();
|
const res = installOnecli();
|
||||||
if (!present) {
|
if (!res.ok) {
|
||||||
log.info('Installing OneCLI gateway and CLI');
|
emitStatus('ONECLI', {
|
||||||
const res = installOnecli();
|
INSTALLED: false,
|
||||||
installOutput = res.stdout;
|
STATUS: 'failed',
|
||||||
if (!res.ok) {
|
ERROR: 'install_failed',
|
||||||
emitStatus('ONECLI', {
|
LOG: 'logs/setup.log',
|
||||||
INSTALLED: false,
|
});
|
||||||
STATUS: 'failed',
|
process.exit(1);
|
||||||
ERROR: 'install_failed',
|
}
|
||||||
LOG: 'logs/setup.log',
|
if (!onecliVersion()) {
|
||||||
});
|
emitStatus('ONECLI', {
|
||||||
process.exit(1);
|
INSTALLED: false,
|
||||||
}
|
STATUS: 'failed',
|
||||||
present = !!onecliVersion();
|
ERROR: 'onecli_not_on_path_after_install',
|
||||||
if (!present) {
|
HINT: 'Open a new shell or run `export PATH="$HOME/.local/bin:$PATH"` and retry.',
|
||||||
emitStatus('ONECLI', {
|
LOG: 'logs/setup.log',
|
||||||
INSTALLED: false,
|
});
|
||||||
STATUS: 'failed',
|
process.exit(1);
|
||||||
ERROR: 'onecli_not_on_path_after_install',
|
|
||||||
HINT: 'Open a new shell or run `export PATH="$HOME/.local/bin:$PATH"` and retry.',
|
|
||||||
LOG: 'logs/setup.log',
|
|
||||||
});
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let url = getApiHost();
|
|
||||||
if (!url && installOutput) {
|
|
||||||
url = extractUrlFromOutput(installOutput);
|
|
||||||
if (url) {
|
|
||||||
try {
|
|
||||||
execFileSync('onecli', ['config', 'set', 'api-host', url], {
|
|
||||||
stdio: 'ignore',
|
|
||||||
env: childEnv(),
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
log.warn('onecli config set api-host failed', { err });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const url = extractUrlFromOutput(res.stdout);
|
||||||
if (!url) {
|
if (!url) {
|
||||||
emitStatus('ONECLI', {
|
emitStatus('ONECLI', {
|
||||||
INSTALLED: true,
|
INSTALLED: true,
|
||||||
STATUS: 'failed',
|
STATUS: 'failed',
|
||||||
ERROR: 'could_not_resolve_api_host',
|
ERROR: 'could_not_resolve_api_host',
|
||||||
HINT: 'Run `onecli config get api-host` to inspect the gateway URL.',
|
HINT: 'Inspect logs/setup.log for the install output.',
|
||||||
LOG: 'logs/setup.log',
|
LOG: 'logs/setup.log',
|
||||||
});
|
});
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
execFileSync('onecli', ['config', 'set', 'api-host', url], {
|
||||||
|
stdio: 'ignore',
|
||||||
|
env: childEnv(),
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('onecli config set api-host failed', { err });
|
||||||
|
}
|
||||||
|
|
||||||
writeEnvOnecliUrl(url);
|
writeEnvOnecliUrl(url);
|
||||||
log.info('Wrote ONECLI_URL to .env', { url });
|
log.info('Wrote ONECLI_URL to .env', { url });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user