mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-26 14:35:22 +08:00
931ef7d3dd
Replace the previous dual-parameter approach (app_type/app/appType) with a single required `app: String` parameter across all Tauri commands. This change: - Introduces unified `parse_app()` helper replacing complex `resolve_app_type()` logic - Updates all backend commands in config, mcp, and provider modules - Aligns frontend API calls to use consistent `app` parameter naming - Simplifies MSW test handlers by removing optional parameter handling This improves API clarity and reduces parameter ambiguity while maintaining backward compatibility through error handling.
98 lines
2.1 KiB
TypeScript
98 lines
2.1 KiB
TypeScript
import { invoke } from "@tauri-apps/api/core";
|
|
import type { CustomEndpoint } from "@/types";
|
|
import type { AppType } from "./types";
|
|
|
|
export interface EndpointLatencyResult {
|
|
url: string;
|
|
latency: number | null;
|
|
status?: number;
|
|
error?: string;
|
|
}
|
|
|
|
export const vscodeApi = {
|
|
async getLiveProviderSettings(appType: AppType) {
|
|
return await invoke("read_live_provider_settings", { app: appType });
|
|
},
|
|
|
|
async testApiEndpoints(
|
|
urls: string[],
|
|
options?: { timeoutSecs?: number },
|
|
): Promise<EndpointLatencyResult[]> {
|
|
return await invoke("test_api_endpoints", {
|
|
urls,
|
|
timeout_secs: options?.timeoutSecs,
|
|
});
|
|
},
|
|
|
|
async getCustomEndpoints(
|
|
appType: AppType,
|
|
providerId: string,
|
|
): Promise<CustomEndpoint[]> {
|
|
return await invoke("get_custom_endpoints", {
|
|
app: appType,
|
|
provider_id: providerId,
|
|
});
|
|
},
|
|
|
|
async addCustomEndpoint(
|
|
appType: AppType,
|
|
providerId: string,
|
|
url: string,
|
|
): Promise<void> {
|
|
await invoke("add_custom_endpoint", {
|
|
app: appType,
|
|
provider_id: providerId,
|
|
url,
|
|
});
|
|
},
|
|
|
|
async removeCustomEndpoint(
|
|
appType: AppType,
|
|
providerId: string,
|
|
url: string,
|
|
): Promise<void> {
|
|
await invoke("remove_custom_endpoint", {
|
|
app: appType,
|
|
provider_id: providerId,
|
|
url,
|
|
});
|
|
},
|
|
|
|
async updateEndpointLastUsed(
|
|
appType: AppType,
|
|
providerId: string,
|
|
url: string,
|
|
): Promise<void> {
|
|
await invoke("update_endpoint_last_used", {
|
|
app: appType,
|
|
provider_id: providerId,
|
|
url,
|
|
});
|
|
},
|
|
|
|
async exportConfigToFile(filePath: string) {
|
|
return await invoke("export_config_to_file", {
|
|
file_path: filePath,
|
|
filePath,
|
|
});
|
|
},
|
|
|
|
async importConfigFromFile(filePath: string) {
|
|
return await invoke("import_config_from_file", {
|
|
file_path: filePath,
|
|
filePath,
|
|
});
|
|
},
|
|
|
|
async saveFileDialog(defaultName: string): Promise<string | null> {
|
|
return await invoke("save_file_dialog", {
|
|
default_name: defaultName,
|
|
defaultName,
|
|
});
|
|
},
|
|
|
|
async openFileDialog(): Promise<string | null> {
|
|
return await invoke("open_file_dialog");
|
|
},
|
|
};
|