mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:24:31 +00:00
refactor: harden kilocode auth ordering and dedupe provider wiring
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
||||
} from "../agents/venice-models.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { ModelApi } from "../config/types.models.js";
|
||||
import { KILOCODE_BASE_URL } from "../providers/kilocode-shared.js";
|
||||
import {
|
||||
HUGGINGFACE_DEFAULT_MODEL_REF,
|
||||
KILOCODE_DEFAULT_MODEL_REF,
|
||||
@@ -433,7 +434,7 @@ export function applyMistralConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
return applyAgentDefaultModelPrimary(next, MISTRAL_DEFAULT_MODEL_REF);
|
||||
}
|
||||
|
||||
export const KILOCODE_BASE_URL = "https://api.kilo.ai/api/gateway/";
|
||||
export { KILOCODE_BASE_URL };
|
||||
|
||||
/**
|
||||
* Apply Kilo Gateway provider configuration without changing the default model.
|
||||
@@ -477,6 +478,7 @@ export function applyAuthProfileConfig(
|
||||
preferProfileFirst?: boolean;
|
||||
},
|
||||
): OpenClawConfig {
|
||||
const normalizedProvider = params.provider.toLowerCase();
|
||||
const profiles = {
|
||||
...cfg.auth?.profiles,
|
||||
[params.profileId]: {
|
||||
@@ -486,8 +488,13 @@ export function applyAuthProfileConfig(
|
||||
},
|
||||
};
|
||||
|
||||
// Only maintain `auth.order` when the user explicitly configured it.
|
||||
// Default behavior: no explicit order -> resolveAuthProfileOrder can round-robin by lastUsed.
|
||||
const configuredProviderProfiles = Object.entries(cfg.auth?.profiles ?? {})
|
||||
.filter(([, profile]) => profile.provider.toLowerCase() === normalizedProvider)
|
||||
.map(([profileId, profile]) => ({ profileId, mode: profile.mode }));
|
||||
|
||||
// Maintain `auth.order` when it already exists. Additionally, if we detect
|
||||
// mixed auth modes for the same provider (e.g. legacy oauth + newly selected
|
||||
// api_key), create an explicit order to keep the newly selected profile first.
|
||||
const existingProviderOrder = cfg.auth?.order?.[params.provider];
|
||||
const preferProfileFirst = params.preferProfileFirst ?? true;
|
||||
const reorderedProviderOrder =
|
||||
@@ -497,6 +504,18 @@ export function applyAuthProfileConfig(
|
||||
...existingProviderOrder.filter((profileId) => profileId !== params.profileId),
|
||||
]
|
||||
: existingProviderOrder;
|
||||
const hasMixedConfiguredModes = configuredProviderProfiles.some(
|
||||
({ profileId, mode }) => profileId !== params.profileId && mode !== params.mode,
|
||||
);
|
||||
const derivedProviderOrder =
|
||||
existingProviderOrder === undefined && preferProfileFirst && hasMixedConfiguredModes
|
||||
? [
|
||||
params.profileId,
|
||||
...configuredProviderProfiles
|
||||
.map(({ profileId }) => profileId)
|
||||
.filter((profileId) => profileId !== params.profileId),
|
||||
]
|
||||
: undefined;
|
||||
const order =
|
||||
existingProviderOrder !== undefined
|
||||
? {
|
||||
@@ -505,7 +524,12 @@ export function applyAuthProfileConfig(
|
||||
? reorderedProviderOrder
|
||||
: [...(reorderedProviderOrder ?? []), params.profileId],
|
||||
}
|
||||
: cfg.auth?.order;
|
||||
: derivedProviderOrder
|
||||
? {
|
||||
...cfg.auth?.order,
|
||||
[params.provider]: derivedProviderOrder,
|
||||
}
|
||||
: cfg.auth?.order;
|
||||
return {
|
||||
...cfg,
|
||||
auth: {
|
||||
|
||||
Reference in New Issue
Block a user