2025-10-16 10:00:22 +08:00
|
|
|
import { invoke } from "@tauri-apps/api/core";
|
|
|
|
|
import type { CustomEndpoint } from "@/types";
|
2025-10-30 14:59:15 +08:00
|
|
|
import type { AppId } from "./types";
|
2025-10-16 10:00:22 +08:00
|
|
|
|
|
|
|
|
export interface EndpointLatencyResult {
|
|
|
|
|
url: string;
|
|
|
|
|
latency: number | null;
|
|
|
|
|
status?: number;
|
|
|
|
|
error?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const vscodeApi = {
|
2025-10-30 14:59:15 +08:00
|
|
|
async getLiveProviderSettings(appId: AppId) {
|
|
|
|
|
return await invoke("read_live_provider_settings", { app: appId });
|
2025-10-16 10:00:22 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async testApiEndpoints(
|
|
|
|
|
urls: string[],
|
2025-10-16 12:13:51 +08:00
|
|
|
options?: { timeoutSecs?: number },
|
2025-10-16 10:00:22 +08:00
|
|
|
): Promise<EndpointLatencyResult[]> {
|
|
|
|
|
return await invoke("test_api_endpoints", {
|
|
|
|
|
urls,
|
refactor: migrate all Tauri commands to camelCase parameters
This commit addresses parameter naming inconsistencies caused by Tauri v2's
requirement for camelCase parameter names in IPC commands.
Backend changes (Rust):
- Updated all command parameters from snake_case to camelCase
- Commands affected:
* provider.rs: providerId (×4), timeoutSecs
* import_export.rs: filePath (×2), defaultName
* config.rs: defaultPath
- Added #[allow(non_snake_case)] attributes for camelCase parameters
- Removed unused QueryUsageParams struct
Frontend changes (TypeScript):
- Removed redundant snake_case parameters from all invoke() calls
- Updated API files:
* usage.ts: removed debug logs, unified to providerId
* vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
* settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
- Ensured all parameters now use camelCase exclusively
Test updates:
- Updated MSW handlers to accept both old and new parameter formats during transition
- Added i18n mock compatibility for tests
Root cause:
The issue stemmed from Tauri v2 strictly requiring camelCase for command
parameters, while the codebase was using snake_case. This caused parameters
like 'provider_id' to not be recognized by the backend, resulting in
"missing providerId parameter" errors.
BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
Any external tools or scripts calling these commands must be updated accordingly.
Fixes: Usage query always failing with "missing providerId" error
Fixes: Custom endpoint management not receiving provider ID
Fixes: Import/export dialogs not respecting default paths
2025-11-03 16:50:23 +08:00
|
|
|
timeoutSecs: options?.timeoutSecs,
|
2025-10-16 10:00:22 +08:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async getCustomEndpoints(
|
2025-10-30 14:59:15 +08:00
|
|
|
appId: AppId,
|
2025-10-16 12:13:51 +08:00
|
|
|
providerId: string,
|
2025-10-16 10:00:22 +08:00
|
|
|
): Promise<CustomEndpoint[]> {
|
|
|
|
|
return await invoke("get_custom_endpoints", {
|
2025-10-30 14:59:15 +08:00
|
|
|
app: appId,
|
refactor: migrate all Tauri commands to camelCase parameters
This commit addresses parameter naming inconsistencies caused by Tauri v2's
requirement for camelCase parameter names in IPC commands.
Backend changes (Rust):
- Updated all command parameters from snake_case to camelCase
- Commands affected:
* provider.rs: providerId (×4), timeoutSecs
* import_export.rs: filePath (×2), defaultName
* config.rs: defaultPath
- Added #[allow(non_snake_case)] attributes for camelCase parameters
- Removed unused QueryUsageParams struct
Frontend changes (TypeScript):
- Removed redundant snake_case parameters from all invoke() calls
- Updated API files:
* usage.ts: removed debug logs, unified to providerId
* vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
* settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
- Ensured all parameters now use camelCase exclusively
Test updates:
- Updated MSW handlers to accept both old and new parameter formats during transition
- Added i18n mock compatibility for tests
Root cause:
The issue stemmed from Tauri v2 strictly requiring camelCase for command
parameters, while the codebase was using snake_case. This caused parameters
like 'provider_id' to not be recognized by the backend, resulting in
"missing providerId parameter" errors.
BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
Any external tools or scripts calling these commands must be updated accordingly.
Fixes: Usage query always failing with "missing providerId" error
Fixes: Custom endpoint management not receiving provider ID
Fixes: Import/export dialogs not respecting default paths
2025-11-03 16:50:23 +08:00
|
|
|
providerId: providerId,
|
2025-10-16 10:00:22 +08:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async addCustomEndpoint(
|
2025-10-30 14:59:15 +08:00
|
|
|
appId: AppId,
|
2025-10-16 10:00:22 +08:00
|
|
|
providerId: string,
|
2025-10-16 12:13:51 +08:00
|
|
|
url: string,
|
2025-10-16 10:00:22 +08:00
|
|
|
): Promise<void> {
|
|
|
|
|
await invoke("add_custom_endpoint", {
|
2025-10-30 14:59:15 +08:00
|
|
|
app: appId,
|
refactor: migrate all Tauri commands to camelCase parameters
This commit addresses parameter naming inconsistencies caused by Tauri v2's
requirement for camelCase parameter names in IPC commands.
Backend changes (Rust):
- Updated all command parameters from snake_case to camelCase
- Commands affected:
* provider.rs: providerId (×4), timeoutSecs
* import_export.rs: filePath (×2), defaultName
* config.rs: defaultPath
- Added #[allow(non_snake_case)] attributes for camelCase parameters
- Removed unused QueryUsageParams struct
Frontend changes (TypeScript):
- Removed redundant snake_case parameters from all invoke() calls
- Updated API files:
* usage.ts: removed debug logs, unified to providerId
* vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
* settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
- Ensured all parameters now use camelCase exclusively
Test updates:
- Updated MSW handlers to accept both old and new parameter formats during transition
- Added i18n mock compatibility for tests
Root cause:
The issue stemmed from Tauri v2 strictly requiring camelCase for command
parameters, while the codebase was using snake_case. This caused parameters
like 'provider_id' to not be recognized by the backend, resulting in
"missing providerId parameter" errors.
BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
Any external tools or scripts calling these commands must be updated accordingly.
Fixes: Usage query always failing with "missing providerId" error
Fixes: Custom endpoint management not receiving provider ID
Fixes: Import/export dialogs not respecting default paths
2025-11-03 16:50:23 +08:00
|
|
|
providerId: providerId,
|
2025-10-16 10:00:22 +08:00
|
|
|
url,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async removeCustomEndpoint(
|
2025-10-30 14:59:15 +08:00
|
|
|
appId: AppId,
|
2025-10-16 10:00:22 +08:00
|
|
|
providerId: string,
|
2025-10-16 12:13:51 +08:00
|
|
|
url: string,
|
2025-10-16 10:00:22 +08:00
|
|
|
): Promise<void> {
|
|
|
|
|
await invoke("remove_custom_endpoint", {
|
2025-10-30 14:59:15 +08:00
|
|
|
app: appId,
|
refactor: migrate all Tauri commands to camelCase parameters
This commit addresses parameter naming inconsistencies caused by Tauri v2's
requirement for camelCase parameter names in IPC commands.
Backend changes (Rust):
- Updated all command parameters from snake_case to camelCase
- Commands affected:
* provider.rs: providerId (×4), timeoutSecs
* import_export.rs: filePath (×2), defaultName
* config.rs: defaultPath
- Added #[allow(non_snake_case)] attributes for camelCase parameters
- Removed unused QueryUsageParams struct
Frontend changes (TypeScript):
- Removed redundant snake_case parameters from all invoke() calls
- Updated API files:
* usage.ts: removed debug logs, unified to providerId
* vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
* settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
- Ensured all parameters now use camelCase exclusively
Test updates:
- Updated MSW handlers to accept both old and new parameter formats during transition
- Added i18n mock compatibility for tests
Root cause:
The issue stemmed from Tauri v2 strictly requiring camelCase for command
parameters, while the codebase was using snake_case. This caused parameters
like 'provider_id' to not be recognized by the backend, resulting in
"missing providerId parameter" errors.
BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
Any external tools or scripts calling these commands must be updated accordingly.
Fixes: Usage query always failing with "missing providerId" error
Fixes: Custom endpoint management not receiving provider ID
Fixes: Import/export dialogs not respecting default paths
2025-11-03 16:50:23 +08:00
|
|
|
providerId: providerId,
|
2025-10-16 10:00:22 +08:00
|
|
|
url,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async updateEndpointLastUsed(
|
2025-10-30 14:59:15 +08:00
|
|
|
appId: AppId,
|
2025-10-16 10:00:22 +08:00
|
|
|
providerId: string,
|
2025-10-16 12:13:51 +08:00
|
|
|
url: string,
|
2025-10-16 10:00:22 +08:00
|
|
|
): Promise<void> {
|
|
|
|
|
await invoke("update_endpoint_last_used", {
|
2025-10-30 14:59:15 +08:00
|
|
|
app: appId,
|
refactor: migrate all Tauri commands to camelCase parameters
This commit addresses parameter naming inconsistencies caused by Tauri v2's
requirement for camelCase parameter names in IPC commands.
Backend changes (Rust):
- Updated all command parameters from snake_case to camelCase
- Commands affected:
* provider.rs: providerId (×4), timeoutSecs
* import_export.rs: filePath (×2), defaultName
* config.rs: defaultPath
- Added #[allow(non_snake_case)] attributes for camelCase parameters
- Removed unused QueryUsageParams struct
Frontend changes (TypeScript):
- Removed redundant snake_case parameters from all invoke() calls
- Updated API files:
* usage.ts: removed debug logs, unified to providerId
* vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
* settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
- Ensured all parameters now use camelCase exclusively
Test updates:
- Updated MSW handlers to accept both old and new parameter formats during transition
- Added i18n mock compatibility for tests
Root cause:
The issue stemmed from Tauri v2 strictly requiring camelCase for command
parameters, while the codebase was using snake_case. This caused parameters
like 'provider_id' to not be recognized by the backend, resulting in
"missing providerId parameter" errors.
BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
Any external tools or scripts calling these commands must be updated accordingly.
Fixes: Usage query always failing with "missing providerId" error
Fixes: Custom endpoint management not receiving provider ID
Fixes: Import/export dialogs not respecting default paths
2025-11-03 16:50:23 +08:00
|
|
|
providerId: providerId,
|
2025-10-16 10:00:22 +08:00
|
|
|
url,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async exportConfigToFile(filePath: string) {
|
|
|
|
|
return await invoke("export_config_to_file", {
|
|
|
|
|
filePath,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async importConfigFromFile(filePath: string) {
|
|
|
|
|
return await invoke("import_config_from_file", {
|
|
|
|
|
filePath,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async saveFileDialog(defaultName: string): Promise<string | null> {
|
|
|
|
|
return await invoke("save_file_dialog", {
|
|
|
|
|
defaultName,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async openFileDialog(): Promise<string | null> {
|
|
|
|
|
return await invoke("open_file_dialog");
|
|
|
|
|
},
|
|
|
|
|
};
|