mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-28 09:33:06 +00:00
refactor: share self hosted provider plugin helpers
This commit is contained in:
@@ -2,6 +2,7 @@ import { upsertAuthProfileWithLock } from "../agents/auth-profiles.js";
|
||||
import type { ApiKeyCredential, AuthProfileCredential } from "../agents/auth-profiles/types.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type {
|
||||
ProviderDiscoveryContext,
|
||||
ProviderAuthResult,
|
||||
ProviderAuthMethodNonInteractiveContext,
|
||||
ProviderNonInteractiveApiKeyResult,
|
||||
@@ -181,6 +182,28 @@ export async function promptAndConfigureOpenAICompatibleSelfHostedProviderAuth(
|
||||
return buildSelfHostedProviderAuthResult(result);
|
||||
}
|
||||
|
||||
export async function discoverOpenAICompatibleSelfHostedProvider<
|
||||
T extends Record<string, unknown>,
|
||||
>(params: {
|
||||
ctx: ProviderDiscoveryContext;
|
||||
providerId: string;
|
||||
buildProvider: (params: { apiKey?: string }) => Promise<T>;
|
||||
}): Promise<{ provider: T & { apiKey: string } } | null> {
|
||||
if (params.ctx.config.models?.providers?.[params.providerId]) {
|
||||
return null;
|
||||
}
|
||||
const { apiKey, discoveryApiKey } = params.ctx.resolveProviderApiKey(params.providerId);
|
||||
if (!apiKey) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
provider: {
|
||||
...(await params.buildProvider({ apiKey: discoveryApiKey })),
|
||||
apiKey,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function buildMissingNonInteractiveModelIdMessage(params: {
|
||||
authChoice: string;
|
||||
providerLabel: string;
|
||||
|
||||
@@ -17,7 +17,9 @@ export { buildOauthProviderAuthResult } from "./provider-auth-result.js";
|
||||
export {
|
||||
applyProviderDefaultModel,
|
||||
configureOpenAICompatibleSelfHostedProviderNonInteractive,
|
||||
discoverOpenAICompatibleSelfHostedProvider,
|
||||
promptAndConfigureOpenAICompatibleSelfHostedProvider,
|
||||
promptAndConfigureOpenAICompatibleSelfHostedProviderAuth,
|
||||
SELF_HOSTED_DEFAULT_CONTEXT_WINDOW,
|
||||
SELF_HOSTED_DEFAULT_COST,
|
||||
SELF_HOSTED_DEFAULT_MAX_TOKENS,
|
||||
|
||||
Reference in New Issue
Block a user