mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 00:02:53 +00:00
Route internal model catalog imports to the extracted @openclaw/model-catalog-core package and delete obsolete internal facades. Keep public SDK declarations self-contained by wrapping core helpers at public boundaries instead of leaking private package imports. Verification: - pnpm test src/plugins/contracts/model-catalog-core-imports.test.ts src/plugins/sdk-alias.test.ts packages/model-catalog-core/src/configured-model-refs.test.ts packages/model-catalog-core/src/provider-model-id-normalize.test.ts packages/model-catalog-core/src/provider-model-id-normalization.test.ts src/config/config.model-ref-validation.test.ts src/agents/model-selection.test.ts src/plugin-sdk/provider-model-shared.test.ts -- --reporter=verbose - pnpm check:test-types - pnpm test:extensions:package-boundary:compile - pnpm build - rg "@openclaw/model-catalog-core" dist/plugin-sdk packages/plugin-sdk/dist -n --glob '*.d.ts' || true - git diff --check - autoreview clean after fix CI note: merged with admin override because checks-node-agentic-commands-doctor and checks-node-core-runtime-infra-state failed twice with exit 143/no-output watchdog termination after prior passing test output, while relevant local proof and the rest of CI were green.
97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id";
|
|
import { resolveBundledProviderPolicySurface } from "./provider-public-artifacts.js";
|
|
import type {
|
|
ProviderDefaultThinkingPolicyContext,
|
|
ProviderThinkingProfile,
|
|
ProviderThinkingPolicyContext,
|
|
} from "./provider-thinking.types.js";
|
|
|
|
type ThinkingProviderPlugin = {
|
|
id: string;
|
|
aliases?: string[];
|
|
hookAliases?: string[];
|
|
isBinaryThinking?: (ctx: ProviderThinkingPolicyContext) => boolean | undefined;
|
|
supportsXHighThinking?: (ctx: ProviderThinkingPolicyContext) => boolean | undefined;
|
|
resolveThinkingProfile?: (
|
|
ctx: ProviderDefaultThinkingPolicyContext,
|
|
) => ProviderThinkingProfile | null | undefined;
|
|
resolveDefaultThinkingLevel?: (
|
|
ctx: ProviderDefaultThinkingPolicyContext,
|
|
) => "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "adaptive" | null | undefined;
|
|
};
|
|
|
|
const PLUGIN_REGISTRY_STATE = Symbol.for("openclaw.pluginRegistryState");
|
|
|
|
type ThinkingRegistryState = {
|
|
activeRegistry?: {
|
|
providers?: Array<{
|
|
provider: ThinkingProviderPlugin;
|
|
}>;
|
|
} | null;
|
|
};
|
|
|
|
function matchesProviderId(provider: ThinkingProviderPlugin, providerId: string): boolean {
|
|
const normalized = normalizeProviderId(providerId);
|
|
if (!normalized) {
|
|
return false;
|
|
}
|
|
if (normalizeProviderId(provider.id) === normalized) {
|
|
return true;
|
|
}
|
|
return [...(provider.aliases ?? []), ...(provider.hookAliases ?? [])].some(
|
|
(alias) => normalizeProviderId(alias) === normalized,
|
|
);
|
|
}
|
|
|
|
function resolveActiveThinkingProvider(providerId: string): ThinkingProviderPlugin | undefined {
|
|
const state = (
|
|
globalThis as typeof globalThis & { [PLUGIN_REGISTRY_STATE]?: ThinkingRegistryState }
|
|
)[PLUGIN_REGISTRY_STATE];
|
|
const activeProvider = state?.activeRegistry?.providers?.find((entry) => {
|
|
return matchesProviderId(entry.provider, providerId);
|
|
})?.provider;
|
|
if (activeProvider) {
|
|
return activeProvider;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
type ThinkingHookParams<TContext> = {
|
|
provider: string;
|
|
context: TContext;
|
|
};
|
|
|
|
export function resolveProviderBinaryThinking(
|
|
params: ThinkingHookParams<ProviderThinkingPolicyContext>,
|
|
) {
|
|
return resolveActiveThinkingProvider(params.provider)?.isBinaryThinking?.(params.context);
|
|
}
|
|
|
|
export function resolveProviderXHighThinking(
|
|
params: ThinkingHookParams<ProviderThinkingPolicyContext>,
|
|
) {
|
|
return resolveActiveThinkingProvider(params.provider)?.supportsXHighThinking?.(params.context);
|
|
}
|
|
|
|
export function resolveProviderThinkingProfile(
|
|
params: ThinkingHookParams<ProviderDefaultThinkingPolicyContext>,
|
|
) {
|
|
const activeProfile = resolveActiveThinkingProvider(params.provider)?.resolveThinkingProfile?.(
|
|
params.context,
|
|
);
|
|
if (activeProfile) {
|
|
return activeProfile;
|
|
}
|
|
return resolveBundledProviderPolicySurface(params.provider)?.resolveThinkingProfile?.(
|
|
params.context,
|
|
);
|
|
}
|
|
|
|
export function resolveProviderDefaultThinkingLevel(
|
|
params: ThinkingHookParams<ProviderDefaultThinkingPolicyContext>,
|
|
) {
|
|
return resolveActiveThinkingProvider(params.provider)?.resolveDefaultThinkingLevel?.(
|
|
params.context,
|
|
);
|
|
}
|