From c974adf10d9f325dad175955094089e9d3e5efb2 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 17 Mar 2026 05:44:51 +0000 Subject: [PATCH] refactor(providers): reuse simple api-key catalog helper --- extensions/modelstudio/index.ts | 24 ++++++++---------------- extensions/moonshot/index.ts | 24 ++++++++---------------- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/extensions/modelstudio/index.ts b/extensions/modelstudio/index.ts index ad5c1852b59..20318b2a022 100644 --- a/extensions/modelstudio/index.ts +++ b/extensions/modelstudio/index.ts @@ -1,5 +1,6 @@ import { emptyPluginConfigSchema, type OpenClawPluginApi } from "openclaw/plugin-sdk/core"; import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth"; +import { buildSingleProviderApiKeyCatalog } from "openclaw/plugin-sdk/provider-catalog"; import { applyModelStudioConfig, applyModelStudioConfigCn, @@ -78,22 +79,13 @@ const modelStudioPlugin = { ], catalog: { order: "simple", - run: async (ctx) => { - const apiKey = ctx.resolveProviderApiKey(PROVIDER_ID).apiKey; - if (!apiKey) { - return null; - } - const explicitProvider = ctx.config.models?.providers?.[PROVIDER_ID]; - const explicitBaseUrl = - typeof explicitProvider?.baseUrl === "string" ? explicitProvider.baseUrl.trim() : ""; - return { - provider: { - ...buildModelStudioProvider(), - ...(explicitBaseUrl ? { baseUrl: explicitBaseUrl } : {}), - apiKey, - }, - }; - }, + run: (ctx) => + buildSingleProviderApiKeyCatalog({ + ctx, + providerId: PROVIDER_ID, + buildProvider: buildModelStudioProvider, + allowExplicitBaseUrl: true, + }), }, }); }, diff --git a/extensions/moonshot/index.ts b/extensions/moonshot/index.ts index 80bd7af6763..c47c4a92d41 100644 --- a/extensions/moonshot/index.ts +++ b/extensions/moonshot/index.ts @@ -1,5 +1,6 @@ import { emptyPluginConfigSchema, type OpenClawPluginApi } from "openclaw/plugin-sdk/core"; import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth"; +import { buildSingleProviderApiKeyCatalog } from "openclaw/plugin-sdk/provider-catalog"; import { createMoonshotThinkingWrapper, resolveMoonshotThinkingType, @@ -74,22 +75,13 @@ const moonshotPlugin = { ], catalog: { order: "simple", - run: async (ctx) => { - const apiKey = ctx.resolveProviderApiKey(PROVIDER_ID).apiKey; - if (!apiKey) { - return null; - } - const explicitProvider = ctx.config.models?.providers?.[PROVIDER_ID]; - const explicitBaseUrl = - typeof explicitProvider?.baseUrl === "string" ? explicitProvider.baseUrl.trim() : ""; - return { - provider: { - ...buildMoonshotProvider(), - ...(explicitBaseUrl ? { baseUrl: explicitBaseUrl } : {}), - apiKey, - }, - }; - }, + run: (ctx) => + buildSingleProviderApiKeyCatalog({ + ctx, + providerId: PROVIDER_ID, + buildProvider: buildMoonshotProvider, + allowExplicitBaseUrl: true, + }), }, wrapStreamFn: (ctx) => { const thinkingType = resolveMoonshotThinkingType({