refactor/channel & ipc (#349)
Co-authored-by: paisley <8197966+su8su@users.noreply.github.com> Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
8b45960662
commit
e28eba01e1
48
electron/main/provider-model-sync.ts
Normal file
48
electron/main/provider-model-sync.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { getProviderConfig } from '../utils/provider-registry';
|
||||
import { getOpenClawProviderKeyForType, isOAuthProviderType } from '../utils/provider-keys';
|
||||
import type { ProviderConfig } from '../utils/secure-storage';
|
||||
|
||||
export interface AgentProviderUpdatePayload {
|
||||
providerKey: string;
|
||||
entry: {
|
||||
baseUrl: string;
|
||||
api: string;
|
||||
apiKey: string | undefined;
|
||||
models: Array<{ id: string; name: string }>;
|
||||
};
|
||||
}
|
||||
|
||||
export function getModelIdFromRef(modelRef: string | undefined, providerKey: string): string | undefined {
|
||||
if (!modelRef) return undefined;
|
||||
if (modelRef.startsWith(`${providerKey}/`)) {
|
||||
return modelRef.slice(providerKey.length + 1);
|
||||
}
|
||||
return modelRef;
|
||||
}
|
||||
|
||||
export function buildNonOAuthAgentProviderUpdate(
|
||||
provider: ProviderConfig,
|
||||
providerId: string,
|
||||
modelRef: string | undefined
|
||||
): AgentProviderUpdatePayload | null {
|
||||
if (provider.type === 'custom' || provider.type === 'ollama' || isOAuthProviderType(provider.type)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const providerKey = getOpenClawProviderKeyForType(provider.type, providerId);
|
||||
const meta = getProviderConfig(provider.type);
|
||||
const baseUrl = provider.baseUrl || meta?.baseUrl;
|
||||
const api = meta?.api;
|
||||
if (!baseUrl || !api) return null;
|
||||
|
||||
const modelId = getModelIdFromRef(modelRef, providerKey);
|
||||
return {
|
||||
providerKey,
|
||||
entry: {
|
||||
baseUrl,
|
||||
api,
|
||||
apiKey: meta?.apiKeyEnv,
|
||||
models: modelId ? [{ id: modelId, name: modelId }] : [],
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user