refactor provider 1

This commit is contained in:
paisley
2026-03-07 20:52:12 +08:00
parent 5b7688e4b1
commit 17cee4e053
11 changed files with 904 additions and 192 deletions

View File

@@ -54,6 +54,7 @@ import { deviceOAuthManager, OAuthProviderType } from '../utils/device-oauth';
import { applyProxySettings } from './proxy';
import { proxyAwareFetch } from '../utils/proxy-fetch';
import { getRecentTokenUsageHistory } from '../utils/token-usage';
import { getProviderService } from '../services/providers/provider-service';
/**
* For custom/ollama providers, derive a unique key for OpenClaw config files
@@ -995,6 +996,8 @@ function registerDeviceOAuthHandlers(mainWindow: BrowserWindow): void {
* Provider-related IPC handlers
*/
function registerProviderHandlers(gatewayManager: GatewayManager): void {
const providerService = getProviderService();
// Listen for OAuth success to automatically restart the Gateway with new tokens/configs.
// Use a longer debounce (8s) so that provider:setDefault — which writes the full config
// and then calls debouncedRestart(2s) — has time to fire and coalesce into a single
@@ -1010,6 +1013,19 @@ function registerProviderHandlers(gatewayManager: GatewayManager): void {
return await getAllProvidersWithKeyInfo();
});
// New provider-service endpoints used by the account-based refactor.
ipcMain.handle('provider:listVendors', async () => {
return await providerService.listVendors();
});
ipcMain.handle('provider:listAccounts', async () => {
return await providerService.listAccounts();
});
ipcMain.handle('provider:getAccount', async (_, accountId: string) => {
return await providerService.getAccount(accountId);
});
// Get a specific provider
ipcMain.handle('provider:get', async (_, providerId: string) => {
return await getProvider(providerId);