From c03f97f954112bb1ae52a3e886d651feb231ad79 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 17 Apr 2026 14:25:11 -0700 Subject: [PATCH] test(plugins): break google contract helper cycles --- extensions/google/api.ts | 29 +------------------- extensions/google/onboard.ts | 28 +++++++++++++++++++ extensions/google/provider-registration.ts | 13 ++++----- src/plugins/contracts/registry.retry.test.ts | 18 ++++++++++-- 4 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 extensions/google/onboard.ts diff --git a/extensions/google/api.ts b/extensions/google/api.ts index fb96d515e70..86987cb070a 100644 --- a/extensions/google/api.ts +++ b/extensions/google/api.ts @@ -2,11 +2,8 @@ import { resolveProviderHttpRequestConfig, type ProviderRequestTransportOverrides, } from "openclaw/plugin-sdk/provider-http"; -import { - applyAgentDefaultModelPrimary, - type OpenClawConfig, -} from "openclaw/plugin-sdk/provider-onboard"; import { parseGoogleOauthApiKey } from "./oauth-token-shared.js"; +export { applyGoogleGeminiModelDefault, GOOGLE_GEMINI_DEFAULT_MODEL } from "./onboard.js"; import { DEFAULT_GOOGLE_API_BASE_URL, normalizeGoogleApiBaseUrl, @@ -90,27 +87,3 @@ export function resolveGoogleGenerativeAiHttpRequestConfig(params: { transport: params.transport, }); } - -export const GOOGLE_GEMINI_DEFAULT_MODEL = "google/gemini-3.1-pro-preview"; - -export function applyGoogleGeminiModelDefault(cfg: OpenClawConfig): { - next: OpenClawConfig; - changed: boolean; -} { - const current = cfg.agents?.defaults?.model as unknown; - const currentPrimary = - typeof current === "string" - ? current.trim() || undefined - : current && - typeof current === "object" && - typeof (current as { primary?: unknown }).primary === "string" - ? ((current as { primary: string }).primary || "").trim() || undefined - : undefined; - if (currentPrimary === GOOGLE_GEMINI_DEFAULT_MODEL) { - return { next: cfg, changed: false }; - } - return { - next: applyAgentDefaultModelPrimary(cfg, GOOGLE_GEMINI_DEFAULT_MODEL), - changed: true, - }; -} diff --git a/extensions/google/onboard.ts b/extensions/google/onboard.ts new file mode 100644 index 00000000000..5c6dd39d73f --- /dev/null +++ b/extensions/google/onboard.ts @@ -0,0 +1,28 @@ +import { + applyAgentDefaultModelPrimary, + type OpenClawConfig, +} from "openclaw/plugin-sdk/provider-onboard"; + +export const GOOGLE_GEMINI_DEFAULT_MODEL = "google/gemini-3.1-pro-preview"; + +export function applyGoogleGeminiModelDefault(cfg: OpenClawConfig): { + next: OpenClawConfig; + changed: boolean; +} { + const current = cfg.agents?.defaults?.model as unknown; + const currentPrimary = + typeof current === "string" + ? current.trim() || undefined + : current && + typeof current === "object" && + typeof (current as { primary?: unknown }).primary === "string" + ? ((current as { primary: string }).primary || "").trim() || undefined + : undefined; + if (currentPrimary === GOOGLE_GEMINI_DEFAULT_MODEL) { + return { next: cfg, changed: false }; + } + return { + next: applyAgentDefaultModelPrimary(cfg, GOOGLE_GEMINI_DEFAULT_MODEL), + changed: true, + }; +} diff --git a/extensions/google/provider-registration.ts b/extensions/google/provider-registration.ts index f33d15b7c74..f5b480854ec 100644 --- a/extensions/google/provider-registration.ts +++ b/extensions/google/provider-registration.ts @@ -1,15 +1,14 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry"; import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key"; import type { ProviderPlugin } from "openclaw/plugin-sdk/provider-model-shared"; -import { - GOOGLE_GEMINI_DEFAULT_MODEL, - applyGoogleGeminiModelDefault, - normalizeGoogleProviderConfig, - normalizeGoogleModelId, - resolveGoogleGenerativeAiTransport, -} from "./api.js"; +import { normalizeGoogleModelId } from "./model-id.js"; +import { GOOGLE_GEMINI_DEFAULT_MODEL, applyGoogleGeminiModelDefault } from "./onboard.js"; import { GOOGLE_GEMINI_PROVIDER_HOOKS } from "./provider-hooks.js"; import { isModernGoogleModel, resolveGoogleGeminiForwardCompatModel } from "./provider-models.js"; +import { + normalizeGoogleProviderConfig, + resolveGoogleGenerativeAiTransport, +} from "./provider-policy.js"; export function buildGoogleProvider(): ProviderPlugin { return { diff --git a/src/plugins/contracts/registry.retry.test.ts b/src/plugins/contracts/registry.retry.test.ts index 2461a7151f6..3421aedda94 100644 --- a/src/plugins/contracts/registry.retry.test.ts +++ b/src/plugins/contracts/registry.retry.test.ts @@ -198,7 +198,14 @@ describe("plugin contract registry scoped retries", () => { id: "openai", label: "OpenAI", docsPath: "/providers/openai", - auth: [{ id: "api-key", label: "API key", run: async () => ({ profiles: [] }) }], + auth: [ + { + id: "api-key", + label: "API key", + kind: "api_key", + run: async () => ({ profiles: [] }), + }, + ], } as ProviderPlugin, }, { @@ -207,7 +214,14 @@ describe("plugin contract registry scoped retries", () => { id: "openai-codex", label: "OpenAI Codex", docsPath: "/providers/openai", - auth: [{ id: "oauth", label: "OAuth", run: async () => ({ profiles: [] }) }], + auth: [ + { + id: "oauth", + label: "OAuth", + kind: "oauth", + run: async () => ({ profiles: [] }), + }, + ], } as ProviderPlugin, }, ]);