remove stale web access override

This commit is contained in:
Advait Paliwal
2026-04-10 10:20:31 -07:00
parent 5b9362918e
commit 4137a29507
13 changed files with 115 additions and 3627 deletions

View File

@@ -28,7 +28,8 @@ import {
printModelList,
setDefaultModelSpec,
} from "./model/commands.js";
import { printSearchStatus } from "./search/commands.js";
import { clearSearchConfig, printSearchStatus, setSearchProvider } from "./search/commands.js";
import type { PiWebSearchProvider } from "./pi/web-access.js";
import { runDoctor, runStatus } from "./setup/doctor.js";
import { setupPreviewDependencies } from "./setup/preview.js";
import { runSetup } from "./setup/setup.js";
@@ -269,12 +270,27 @@ async function handlePackagesCommand(subcommand: string | undefined, args: strin
console.log("Optional packages installed.");
}
function handleSearchCommand(subcommand: string | undefined): void {
function handleSearchCommand(subcommand: string | undefined, args: string[]): void {
if (!subcommand || subcommand === "status") {
printSearchStatus();
return;
}
if (subcommand === "set") {
const provider = args[0] as PiWebSearchProvider | undefined;
const validProviders: PiWebSearchProvider[] = ["auto", "perplexity", "exa", "gemini"];
if (!provider || !validProviders.includes(provider)) {
throw new Error("Usage: feynman search set <auto|perplexity|exa|gemini> [api-key]");
}
setSearchProvider(provider, args[1]);
return;
}
if (subcommand === "clear") {
clearSearchConfig();
return;
}
throw new Error(`Unknown search command: ${subcommand}`);
}
@@ -442,7 +458,7 @@ export async function main(): Promise<void> {
}
if (command === "search") {
handleSearchCommand(rest[0]);
handleSearchCommand(rest[0], rest.slice(1));
return;
}

View File

@@ -1,6 +1,5 @@
import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";
import { resolve } from "node:path";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { getFeynmanHome } from "../config/paths.js";
export type PiWebSearchProvider = "auto" | "perplexity" | "exa" | "gemini";
@@ -53,6 +52,23 @@ export function loadPiWebAccessConfig(configPath = getPiWebSearchConfigPath()):
}
}
export function savePiWebAccessConfig(
updates: Partial<Record<keyof PiWebAccessConfig, unknown>>,
configPath = getPiWebSearchConfigPath(),
): void {
const merged: Record<string, unknown> = { ...loadPiWebAccessConfig(configPath) };
for (const [key, value] of Object.entries(updates)) {
if (value === undefined) {
delete merged[key];
} else {
merged[key] = value;
}
}
mkdirSync(dirname(configPath), { recursive: true });
writeFileSync(configPath, JSON.stringify(merged, null, 2) + "\n", "utf8");
}
function formatRouteLabel(provider: PiWebSearchProvider): string {
switch (provider) {
case "perplexity":

View File

@@ -1,6 +1,18 @@
import { getPiWebAccessStatus } from "../pi/web-access.js";
import {
getPiWebAccessStatus,
savePiWebAccessConfig,
type PiWebAccessConfig,
type PiWebSearchProvider,
} from "../pi/web-access.js";
import { printInfo } from "../ui/terminal.js";
const SEARCH_PROVIDERS: PiWebSearchProvider[] = ["auto", "perplexity", "exa", "gemini"];
const PROVIDER_API_KEY_FIELDS: Partial<Record<PiWebSearchProvider, keyof PiWebAccessConfig>> = {
perplexity: "perplexityApiKey",
exa: "exaApiKey",
gemini: "geminiApiKey",
};
export function printSearchStatus(): void {
const status = getPiWebAccessStatus();
printInfo("Managed by: pi-web-access");
@@ -12,3 +24,35 @@ export function printSearchStatus(): void {
printInfo(`Browser profile: ${status.chromeProfile ?? "default Chromium profile"}`);
printInfo(`Config path: ${status.configPath}`);
}
export function setSearchProvider(provider: PiWebSearchProvider, apiKey?: string): void {
if (!SEARCH_PROVIDERS.includes(provider)) {
throw new Error(`Usage: feynman search set <${SEARCH_PROVIDERS.join("|")}> [api-key]`);
}
if (apiKey !== undefined && provider === "auto") {
throw new Error("The auto provider does not use an API key. Usage: feynman search set auto");
}
const updates: Partial<Record<keyof PiWebAccessConfig, unknown>> = {
provider,
searchProvider: provider,
route: undefined,
};
const apiKeyField = PROVIDER_API_KEY_FIELDS[provider];
if (apiKeyField && apiKey !== undefined) {
updates[apiKeyField] = apiKey;
}
savePiWebAccessConfig(updates);
const status = getPiWebAccessStatus();
console.log(`Web search provider set to ${status.routeLabel}.`);
console.log(`Config path: ${status.configPath}`);
}
export function clearSearchConfig(): void {
savePiWebAccessConfig({ provider: undefined, searchProvider: undefined, route: undefined });
const status = getPiWebAccessStatus();
console.log(`Web search provider reset to ${status.routeLabel}.`);
console.log(`Config path: ${status.configPath}`);
}