new flow for Pi provider/model settings

This commit is contained in:
2026-02-22 20:19:11 +00:00
parent 1372f53782
commit f1e3ce4b76
15 changed files with 249 additions and 460 deletions
+68 -6
View File
@@ -1,10 +1,72 @@
import { mkdirSync } from 'node:fs';
import { DATA_PATH } from './data-path';
import { mkdirSync, existsSync, copyFileSync } from 'node:fs';
import { join } from 'node:path';
import { homedir } from 'node:os';
import { DATA_PATH, PI_CONFIG_DIR } from './data-path';
import { syncLocalProvidersToPiConfig } from './api/server-settings/sync-pi-config';
mkdirSync(DATA_PATH, { recursive: true });
mkdirSync(PI_CONFIG_DIR, { recursive: true });
// Sync local providers to Pi config on startup
syncLocalProvidersToPiConfig().catch(err => {
console.error('Failed to sync local providers to Pi config on startup:', err);
});
async function ensurePiInstalled(): Promise<boolean> {
try {
const proc = Bun.spawn(['pi', '--version'], { stdout: 'pipe', stderr: 'pipe' });
await proc.exited;
return proc.exitCode === 0;
} catch {
return false;
}
}
async function installPi(): Promise<boolean> {
console.log('[bootstrap] Pi not found, installing...');
try {
const proc = Bun.spawn(['npm', 'install', '-g', '@mariozechner/pi-coding-agent'], {
stdout: 'pipe',
stderr: 'pipe',
});
const stderr = await new Response(proc.stderr).text();
await proc.exited;
if (proc.exitCode !== 0) {
console.error('[bootstrap] Pi installation failed:', stderr.trim());
return false;
}
console.log('[bootstrap] Pi installed successfully');
return true;
} catch (err) {
console.error('[bootstrap] Pi installation error:', err);
return false;
}
}
function seedPiConfig(): void {
const hostPiDir = join(homedir(), '.pi', 'agent');
const filesToCopy = ['models.json', 'settings.json'];
for (const file of filesToCopy) {
const target = join(PI_CONFIG_DIR, file);
if (existsSync(target)) continue;
const source = join(hostPiDir, file);
if (existsSync(source)) {
copyFileSync(source, target);
console.log(`[bootstrap] Seeded ${file} from host Pi config`);
}
}
}
(async () => {
const installed = await ensurePiInstalled();
if (!installed) {
const ok = await installPi();
if (!ok) {
console.error('[bootstrap] Could not install Pi — model discovery will not work');
return;
}
}
seedPiConfig();
await syncLocalProvidersToPiConfig().catch(err => {
console.error('[bootstrap] Failed to sync local providers to Pi config:', err);
});
})();