import { launcherFetch } from "@/api/http" export interface ToolSupportItem { name: string description: string category: string config_key: string status: "enabled" | "disabled" | "blocked" reason_code?: string } interface ToolsResponse { tools: ToolSupportItem[] } interface ToolActionResponse { status: string } export interface WebSearchProviderOption { id: string label: string configured: boolean current: boolean requires_auth: boolean } export interface WebSearchProviderConfig { enabled: boolean max_results: number base_url?: string api_key?: string api_keys?: string[] model?: string api_key_set?: boolean } export interface WebSearchConfigResponse { provider: string current_service: string prefer_native: boolean proxy?: string providers: WebSearchProviderOption[] settings: Record } async function request(path: string, options?: RequestInit): Promise { const res = await launcherFetch(path, options) if (!res.ok) { let message = `API error: ${res.status} ${res.statusText}` try { const body = (await res.json()) as { error?: string errors?: string[] } if (Array.isArray(body.errors) && body.errors.length > 0) { message = body.errors.join("; ") } else if (typeof body.error === "string" && body.error.trim() !== "") { message = body.error } } catch { // ignore invalid body } throw new Error(message) } return res.json() as Promise } export async function getTools(): Promise { return request("/api/tools") } export async function setToolEnabled( name: string, enabled: boolean, ): Promise { return request( `/api/tools/${encodeURIComponent(name)}/state`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ enabled }), }, ) } export async function getWebSearchConfig(): Promise { return request("/api/tools/web-search-config") } export async function updateWebSearchConfig( payload: WebSearchConfigResponse, ): Promise { return request("/api/tools/web-search-config", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }) }