fix: restore provider and config compatibility checks

This commit is contained in:
Peter Steinberger
2026-04-05 03:47:57 +01:00
parent 22175faaec
commit fb580b551e
21 changed files with 330 additions and 153 deletions

View File

@@ -1,5 +1,7 @@
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key";
import { normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared";
import type { SecretInput } from "openclaw/plugin-sdk/secret-input";
import { applyKimiCodeConfig, KIMI_CODING_MODEL_REF } from "./onboard.js";
import { buildKimiCodingProvider } from "./provider-catalog.js";
import { KIMI_REPLAY_POLICY } from "./replay-policy.js";
@@ -12,6 +14,25 @@ function isRecord(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
}
function findExplicitProviderConfig(
providers: Record<string, unknown> | undefined,
providerId: string,
): Record<string, unknown> | undefined {
if (!providers) {
return undefined;
}
const normalizedProviderId = normalizeProviderId(providerId);
const match = Object.entries(providers).find(
([configuredProviderId]) => normalizeProviderId(configuredProviderId) === normalizedProviderId,
);
return isRecord(match?.[1]) ? match[1] : undefined;
}
function buildKimiReplayPolicy() {
return {
preserveSignatures: false,
};
}
export default definePluginEntry({
id: PLUGIN_ID,
name: "Kimi Provider",
@@ -57,12 +78,15 @@ export default definePluginEntry({
if (!apiKey) {
return null;
}
const explicitProvider = ctx.config.models?.providers?.[PROVIDER_ID];
const explicitProvider = findExplicitProviderConfig(
ctx.config.models?.providers as Record<string, unknown> | undefined,
PROVIDER_ID,
);
const builtInProvider = buildKimiCodingProvider();
const explicitBaseUrl =
typeof explicitProvider?.baseUrl === "string" ? explicitProvider.baseUrl.trim() : "";
const explicitHeaders = isRecord(explicitProvider?.headers)
? explicitProvider.headers
? (explicitProvider.headers as Record<string, SecretInput>)
: undefined;
return {
provider: {