mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 18:30:22 +00:00
refactor: pluginize litellm auth onboarding
This commit is contained in:
41
extensions/litellm/index.ts
Normal file
41
extensions/litellm/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { defineSingleProviderPluginEntry } from "openclaw/plugin-sdk/provider-entry";
|
||||
import { applyLitellmConfig, LITELLM_DEFAULT_MODEL_REF } from "./onboard.js";
|
||||
import { buildLitellmProvider } from "./provider-catalog.js";
|
||||
|
||||
const PROVIDER_ID = "litellm";
|
||||
|
||||
export default defineSingleProviderPluginEntry({
|
||||
id: PROVIDER_ID,
|
||||
name: "LiteLLM Provider",
|
||||
description: "Bundled LiteLLM provider plugin",
|
||||
provider: {
|
||||
label: "LiteLLM",
|
||||
docsPath: "/providers/litellm",
|
||||
auth: [
|
||||
{
|
||||
methodId: "api-key",
|
||||
label: "LiteLLM API key",
|
||||
hint: "Unified gateway for 100+ LLM providers",
|
||||
optionKey: "litellmApiKey",
|
||||
flagName: "--litellm-api-key",
|
||||
envVar: "LITELLM_API_KEY",
|
||||
promptMessage: "Enter LiteLLM API key",
|
||||
defaultModel: LITELLM_DEFAULT_MODEL_REF,
|
||||
applyConfig: (cfg) => applyLitellmConfig(cfg),
|
||||
noteTitle: "LiteLLM",
|
||||
noteMessage: [
|
||||
"LiteLLM provides a unified API to 100+ LLM providers.",
|
||||
"Get your API key from your LiteLLM proxy or https://litellm.ai",
|
||||
"Default proxy runs on http://localhost:4000",
|
||||
].join("\n"),
|
||||
wizard: {
|
||||
groupHint: "Unified LLM gateway (100+ providers)",
|
||||
},
|
||||
},
|
||||
],
|
||||
catalog: {
|
||||
buildProvider: buildLitellmProvider,
|
||||
allowExplicitBaseUrl: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
55
extensions/litellm/onboard.ts
Normal file
55
extensions/litellm/onboard.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
createDefaultModelPresetAppliers,
|
||||
type ModelDefinitionConfig,
|
||||
type OpenClawConfig,
|
||||
} from "openclaw/plugin-sdk/provider-onboard";
|
||||
|
||||
export const LITELLM_BASE_URL = "http://localhost:4000";
|
||||
export const LITELLM_DEFAULT_MODEL_ID = "claude-opus-4-6";
|
||||
export const LITELLM_DEFAULT_MODEL_REF = `litellm/${LITELLM_DEFAULT_MODEL_ID}`;
|
||||
const LITELLM_DEFAULT_CONTEXT_WINDOW = 128_000;
|
||||
const LITELLM_DEFAULT_MAX_TOKENS = 8_192;
|
||||
const LITELLM_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
export function buildLitellmModelDefinition(): ModelDefinitionConfig {
|
||||
return {
|
||||
id: LITELLM_DEFAULT_MODEL_ID,
|
||||
name: "Claude Opus 4.6",
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
cost: LITELLM_DEFAULT_COST,
|
||||
contextWindow: LITELLM_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: LITELLM_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
|
||||
const litellmPresetAppliers = createDefaultModelPresetAppliers({
|
||||
primaryModelRef: LITELLM_DEFAULT_MODEL_REF,
|
||||
resolveParams: (cfg: OpenClawConfig) => {
|
||||
const existingProvider = cfg.models?.providers?.litellm as { baseUrl?: unknown } | undefined;
|
||||
const resolvedBaseUrl =
|
||||
typeof existingProvider?.baseUrl === "string" ? existingProvider.baseUrl.trim() : "";
|
||||
|
||||
return {
|
||||
providerId: "litellm",
|
||||
api: "openai-completions" as const,
|
||||
baseUrl: resolvedBaseUrl || LITELLM_BASE_URL,
|
||||
defaultModel: buildLitellmModelDefinition(),
|
||||
defaultModelId: LITELLM_DEFAULT_MODEL_ID,
|
||||
aliases: [{ modelRef: LITELLM_DEFAULT_MODEL_REF, alias: "LiteLLM" }],
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export function applyLitellmProviderConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
return litellmPresetAppliers.applyProviderConfig(cfg);
|
||||
}
|
||||
|
||||
export function applyLitellmConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
return litellmPresetAppliers.applyConfig(cfg);
|
||||
}
|
||||
28
extensions/litellm/openclaw.plugin.json
Normal file
28
extensions/litellm/openclaw.plugin.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"id": "litellm",
|
||||
"providers": ["litellm"],
|
||||
"providerAuthEnvVars": {
|
||||
"litellm": ["LITELLM_API_KEY"]
|
||||
},
|
||||
"providerAuthChoices": [
|
||||
{
|
||||
"provider": "litellm",
|
||||
"method": "api-key",
|
||||
"choiceId": "litellm-api-key",
|
||||
"choiceLabel": "LiteLLM API key",
|
||||
"choiceHint": "Unified gateway for 100+ LLM providers",
|
||||
"groupId": "litellm",
|
||||
"groupLabel": "LiteLLM",
|
||||
"groupHint": "Unified LLM gateway (100+ providers)",
|
||||
"optionKey": "litellmApiKey",
|
||||
"cliFlag": "--litellm-api-key",
|
||||
"cliOption": "--litellm-api-key <key>",
|
||||
"cliDescription": "LiteLLM API key"
|
||||
}
|
||||
],
|
||||
"configSchema": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {}
|
||||
}
|
||||
}
|
||||
12
extensions/litellm/package.json
Normal file
12
extensions/litellm/package.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "@openclaw/litellm-provider",
|
||||
"version": "2026.3.26",
|
||||
"private": true,
|
||||
"description": "OpenClaw LiteLLM provider plugin",
|
||||
"type": "module",
|
||||
"openclaw": {
|
||||
"extensions": [
|
||||
"./index.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
10
extensions/litellm/provider-catalog.ts
Normal file
10
extensions/litellm/provider-catalog.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { ModelProviderConfig } from "openclaw/plugin-sdk/provider-models";
|
||||
import { buildLitellmModelDefinition, LITELLM_BASE_URL } from "./onboard.js";
|
||||
|
||||
export function buildLitellmProvider(): ModelProviderConfig {
|
||||
return {
|
||||
baseUrl: LITELLM_BASE_URL,
|
||||
api: "openai-completions",
|
||||
models: [buildLitellmModelDefinition()],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user