mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 20:51:10 +00:00
refactor(plugins): move auth and model policy to providers
This commit is contained in:
@@ -17,10 +17,14 @@ import {
|
||||
buildProviderMissingAuthMessageWithPlugin,
|
||||
prepareProviderExtraParams,
|
||||
resolveProviderCacheTtlEligibility,
|
||||
resolveProviderBinaryThinking,
|
||||
resolveProviderBuiltInModelSuppression,
|
||||
resolveProviderDefaultThinkingLevel,
|
||||
resolveProviderModernModelRef,
|
||||
resolveProviderUsageSnapshotWithPlugin,
|
||||
resolveProviderCapabilitiesWithPlugin,
|
||||
resolveProviderUsageAuthWithPlugin,
|
||||
resolveProviderXHighThinking,
|
||||
normalizeProviderResolvedModelWithPlugin,
|
||||
prepareProviderDynamicModel,
|
||||
prepareProviderRuntimeAuth,
|
||||
@@ -143,6 +147,10 @@ describe("provider-runtime", () => {
|
||||
resolveUsageAuth,
|
||||
fetchUsageSnapshot,
|
||||
isCacheTtlEligible: ({ modelId }) => modelId.startsWith("anthropic/"),
|
||||
isBinaryThinking: () => true,
|
||||
supportsXHighThinking: ({ modelId }) => modelId === "gpt-5.4",
|
||||
resolveDefaultThinkingLevel: ({ reasoning }) => (reasoning ? "low" : "off"),
|
||||
isModernModelRef: ({ modelId }) => modelId.startsWith("gpt-5"),
|
||||
},
|
||||
];
|
||||
});
|
||||
@@ -278,6 +286,47 @@ describe("provider-runtime", () => {
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
resolveProviderBinaryThinking({
|
||||
provider: "demo",
|
||||
context: {
|
||||
provider: "demo",
|
||||
modelId: "glm-5",
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
resolveProviderXHighThinking({
|
||||
provider: "demo",
|
||||
context: {
|
||||
provider: "demo",
|
||||
modelId: "gpt-5.4",
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
resolveProviderDefaultThinkingLevel({
|
||||
provider: "demo",
|
||||
context: {
|
||||
provider: "demo",
|
||||
modelId: "gpt-5.4",
|
||||
reasoning: true,
|
||||
},
|
||||
}),
|
||||
).toBe("low");
|
||||
|
||||
expect(
|
||||
resolveProviderModernModelRef({
|
||||
provider: "demo",
|
||||
context: {
|
||||
provider: "demo",
|
||||
modelId: "gpt-5.4",
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
buildProviderMissingAuthMessageWithPlugin({
|
||||
provider: "openai",
|
||||
|
||||
@@ -6,7 +6,9 @@ import type {
|
||||
ProviderBuildMissingAuthMessageContext,
|
||||
ProviderBuiltInModelSuppressionContext,
|
||||
ProviderCacheTtlEligibilityContext,
|
||||
ProviderDefaultThinkingPolicyContext,
|
||||
ProviderFetchUsageSnapshotContext,
|
||||
ProviderModernModelPolicyContext,
|
||||
ProviderPrepareExtraParamsContext,
|
||||
ProviderPrepareDynamicModelContext,
|
||||
ProviderPrepareRuntimeAuthContext,
|
||||
@@ -14,6 +16,7 @@ import type {
|
||||
ProviderPlugin,
|
||||
ProviderResolveDynamicModelContext,
|
||||
ProviderRuntimeModel,
|
||||
ProviderThinkingPolicyContext,
|
||||
ProviderWrapStreamFnContext,
|
||||
} from "./types.js";
|
||||
|
||||
@@ -179,6 +182,46 @@ export function resolveProviderCacheTtlEligibility(params: {
|
||||
return resolveProviderRuntimePlugin(params)?.isCacheTtlEligible?.(params.context);
|
||||
}
|
||||
|
||||
export function resolveProviderBinaryThinking(params: {
|
||||
provider: string;
|
||||
config?: OpenClawConfig;
|
||||
workspaceDir?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
context: ProviderThinkingPolicyContext;
|
||||
}) {
|
||||
return resolveProviderRuntimePlugin(params)?.isBinaryThinking?.(params.context);
|
||||
}
|
||||
|
||||
export function resolveProviderXHighThinking(params: {
|
||||
provider: string;
|
||||
config?: OpenClawConfig;
|
||||
workspaceDir?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
context: ProviderThinkingPolicyContext;
|
||||
}) {
|
||||
return resolveProviderRuntimePlugin(params)?.supportsXHighThinking?.(params.context);
|
||||
}
|
||||
|
||||
export function resolveProviderDefaultThinkingLevel(params: {
|
||||
provider: string;
|
||||
config?: OpenClawConfig;
|
||||
workspaceDir?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
context: ProviderDefaultThinkingPolicyContext;
|
||||
}) {
|
||||
return resolveProviderRuntimePlugin(params)?.resolveDefaultThinkingLevel?.(params.context);
|
||||
}
|
||||
|
||||
export function resolveProviderModernModelRef(params: {
|
||||
provider: string;
|
||||
config?: OpenClawConfig;
|
||||
workspaceDir?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
context: ProviderModernModelPolicyContext;
|
||||
}) {
|
||||
return resolveProviderRuntimePlugin(params)?.isModernModelRef?.(params.context);
|
||||
}
|
||||
|
||||
export function buildProviderMissingAuthMessageWithPlugin(params: {
|
||||
provider: string;
|
||||
config?: OpenClawConfig;
|
||||
|
||||
@@ -426,6 +426,40 @@ export type ProviderBuiltInModelSuppressionResult = {
|
||||
errorMessage?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provider-owned thinking policy input.
|
||||
*
|
||||
* Used by shared `/think`, ACP controls, and directive parsing to ask a
|
||||
* provider whether a model supports special reasoning UX such as xhigh or a
|
||||
* binary on/off toggle.
|
||||
*/
|
||||
export type ProviderThinkingPolicyContext = {
|
||||
provider: string;
|
||||
modelId: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provider-owned default thinking policy input.
|
||||
*
|
||||
* `reasoning` is the merged catalog hint for the selected model when one is
|
||||
* available. Providers can use it to keep "reasoning model => low" behavior
|
||||
* without re-reading the catalog themselves.
|
||||
*/
|
||||
export type ProviderDefaultThinkingPolicyContext = ProviderThinkingPolicyContext & {
|
||||
reasoning?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provider-owned "modern model" policy input.
|
||||
*
|
||||
* Live smoke/model-profile selection uses this to keep provider-specific
|
||||
* inclusion/exclusion rules out of core.
|
||||
*/
|
||||
export type ProviderModernModelPolicyContext = {
|
||||
provider: string;
|
||||
modelId: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Final catalog augmentation hook.
|
||||
*
|
||||
@@ -651,6 +685,35 @@ export type ProviderPlugin = {
|
||||
| Promise<Array<ModelCatalogEntry> | ReadonlyArray<ModelCatalogEntry> | null | undefined>
|
||||
| null
|
||||
| undefined;
|
||||
/**
|
||||
* Provider-owned binary thinking toggle.
|
||||
*
|
||||
* Return true when the provider exposes a coarse on/off reasoning control
|
||||
* instead of the normal multi-level ladder shown by `/think`.
|
||||
*/
|
||||
isBinaryThinking?: (ctx: ProviderThinkingPolicyContext) => boolean | undefined;
|
||||
/**
|
||||
* Provider-owned xhigh reasoning support.
|
||||
*
|
||||
* Return true only for models that should expose the `xhigh` thinking level.
|
||||
*/
|
||||
supportsXHighThinking?: (ctx: ProviderThinkingPolicyContext) => boolean | undefined;
|
||||
/**
|
||||
* Provider-owned default thinking level.
|
||||
*
|
||||
* Use this to keep model-family defaults (for example Claude 4.6 =>
|
||||
* adaptive) out of core command logic.
|
||||
*/
|
||||
resolveDefaultThinkingLevel?: (
|
||||
ctx: ProviderDefaultThinkingPolicyContext,
|
||||
) => "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "adaptive" | null | undefined;
|
||||
/**
|
||||
* Provider-owned "modern model" matcher used by live profile/smoke filters.
|
||||
*
|
||||
* Return true when the given provider/model ref should be treated as a
|
||||
* preferred modern model candidate.
|
||||
*/
|
||||
isModernModelRef?: (ctx: ProviderModernModelPolicyContext) => boolean | undefined;
|
||||
wizard?: ProviderPluginWizard;
|
||||
formatApiKey?: (cred: AuthProfileCredential) => string;
|
||||
refreshOAuth?: (cred: OAuthCredential) => Promise<OAuthCredential>;
|
||||
|
||||
Reference in New Issue
Block a user