refactor: share self hosted provider plugin helpers

This commit is contained in:
Peter Steinberger
2026-03-14 00:40:00 +00:00
parent 66aabf5eaa
commit 81ea997d40
4 changed files with 47 additions and 66 deletions

View File

@@ -1,13 +1,11 @@
import {
buildSglangProvider,
configureOpenAICompatibleSelfHostedProviderNonInteractive,
discoverOpenAICompatibleSelfHostedProvider,
emptyPluginConfigSchema,
promptAndConfigureOpenAICompatibleSelfHostedProvider,
promptAndConfigureOpenAICompatibleSelfHostedProviderAuth,
type OpenClawPluginApi,
type ProviderAuthContext,
type ProviderAuthMethodNonInteractiveContext,
type ProviderAuthResult,
type ProviderDiscoveryContext,
} from "openclaw/plugin-sdk/core";
const PROVIDER_ID = "sglang";
@@ -30,8 +28,8 @@ const sglangPlugin = {
label: "SGLang",
hint: "Fast self-hosted OpenAI-compatible server",
kind: "custom",
run: async (ctx: ProviderAuthContext): Promise<ProviderAuthResult> => {
const result = await promptAndConfigureOpenAICompatibleSelfHostedProvider({
run: async (ctx) =>
promptAndConfigureOpenAICompatibleSelfHostedProviderAuth({
cfg: ctx.config,
prompter: ctx.prompter,
providerId: PROVIDER_ID,
@@ -39,18 +37,7 @@ const sglangPlugin = {
defaultBaseUrl: DEFAULT_BASE_URL,
defaultApiKeyEnvVar: "SGLANG_API_KEY",
modelPlaceholder: "Qwen/Qwen3-8B",
});
return {
profiles: [
{
profileId: result.profileId,
credential: result.credential,
},
],
configPatch: result.config,
defaultModel: result.modelRef,
};
},
}),
runNonInteractive: async (ctx: ProviderAuthMethodNonInteractiveContext) =>
configureOpenAICompatibleSelfHostedProviderNonInteractive({
ctx,
@@ -64,21 +51,12 @@ const sglangPlugin = {
],
discovery: {
order: "late",
run: async (ctx: ProviderDiscoveryContext) => {
if (ctx.config.models?.providers?.sglang) {
return null;
}
const { apiKey, discoveryApiKey } = ctx.resolveProviderApiKey(PROVIDER_ID);
if (!apiKey) {
return null;
}
return {
provider: {
...(await buildSglangProvider({ apiKey: discoveryApiKey })),
apiKey,
},
};
},
run: async (ctx) =>
discoverOpenAICompatibleSelfHostedProvider({
ctx,
providerId: PROVIDER_ID,
buildProvider: buildSglangProvider,
}),
},
wizard: {
onboarding: {

View File

@@ -1,13 +1,11 @@
import {
buildVllmProvider,
configureOpenAICompatibleSelfHostedProviderNonInteractive,
discoverOpenAICompatibleSelfHostedProvider,
emptyPluginConfigSchema,
promptAndConfigureOpenAICompatibleSelfHostedProvider,
promptAndConfigureOpenAICompatibleSelfHostedProviderAuth,
type OpenClawPluginApi,
type ProviderAuthContext,
type ProviderAuthMethodNonInteractiveContext,
type ProviderAuthResult,
type ProviderDiscoveryContext,
} from "openclaw/plugin-sdk/core";
const PROVIDER_ID = "vllm";
@@ -30,8 +28,8 @@ const vllmPlugin = {
label: "vLLM",
hint: "Local/self-hosted OpenAI-compatible server",
kind: "custom",
run: async (ctx: ProviderAuthContext): Promise<ProviderAuthResult> => {
const result = await promptAndConfigureOpenAICompatibleSelfHostedProvider({
run: async (ctx) =>
promptAndConfigureOpenAICompatibleSelfHostedProviderAuth({
cfg: ctx.config,
prompter: ctx.prompter,
providerId: PROVIDER_ID,
@@ -39,18 +37,7 @@ const vllmPlugin = {
defaultBaseUrl: DEFAULT_BASE_URL,
defaultApiKeyEnvVar: "VLLM_API_KEY",
modelPlaceholder: "meta-llama/Meta-Llama-3-8B-Instruct",
});
return {
profiles: [
{
profileId: result.profileId,
credential: result.credential,
},
],
configPatch: result.config,
defaultModel: result.modelRef,
};
},
}),
runNonInteractive: async (ctx: ProviderAuthMethodNonInteractiveContext) =>
configureOpenAICompatibleSelfHostedProviderNonInteractive({
ctx,
@@ -64,21 +51,12 @@ const vllmPlugin = {
],
discovery: {
order: "late",
run: async (ctx: ProviderDiscoveryContext) => {
if (ctx.config.models?.providers?.vllm) {
return null;
}
const { apiKey, discoveryApiKey } = ctx.resolveProviderApiKey(PROVIDER_ID);
if (!apiKey) {
return null;
}
return {
provider: {
...(await buildVllmProvider({ apiKey: discoveryApiKey })),
apiKey,
},
};
},
run: async (ctx) =>
discoverOpenAICompatibleSelfHostedProvider({
ctx,
providerId: PROVIDER_ID,
buildProvider: buildVllmProvider,
}),
},
wizard: {
onboarding: {