diff --git a/extensions/google/gemini-cli-provider.ts b/extensions/google/gemini-cli-provider.ts index 28dc355e142..3da20eed293 100644 --- a/extensions/google/gemini-cli-provider.ts +++ b/extensions/google/gemini-cli-provider.ts @@ -4,11 +4,10 @@ import type { ProviderFetchUsageSnapshotContext, } from "openclaw/plugin-sdk/plugin-entry"; import { buildOauthProviderAuthResult } from "openclaw/plugin-sdk/provider-auth-result"; -import { buildProviderReplayFamilyHooks } from "openclaw/plugin-sdk/provider-model-shared"; -import { buildProviderStreamFamilyHooks } from "openclaw/plugin-sdk/provider-stream-family"; import { buildProviderToolCompatFamilyHooks } from "openclaw/plugin-sdk/provider-tools"; import { fetchGeminiUsage } from "openclaw/plugin-sdk/provider-usage"; import { formatGoogleOauthApiKey, parseGoogleUsageToken } from "./oauth-token-shared.js"; +import { GOOGLE_GEMINI_PROVIDER_HOOKS } from "./provider-hooks.js"; import { isModernGoogleModel, resolveGoogleGeminiForwardCompatModel } from "./provider-models.js"; const PROVIDER_ID = "google-gemini-cli"; @@ -22,8 +21,7 @@ const ENV_VARS = [ ] as const; const GOOGLE_GEMINI_CLI_PROVIDER_HOOKS = { - ...buildProviderReplayFamilyHooks({ family: "google-gemini" }), - ...buildProviderStreamFamilyHooks("google-thinking"), + ...GOOGLE_GEMINI_PROVIDER_HOOKS, ...buildProviderToolCompatFamilyHooks("gemini"), }; diff --git a/extensions/google/index.test.ts b/extensions/google/index.test.ts index df967852a4f..2f0024a81e4 100644 --- a/extensions/google/index.test.ts +++ b/extensions/google/index.test.ts @@ -188,4 +188,17 @@ describe("google provider plugin hooks", () => { runCase(googleProvider, "google"); runCase(cliProvider, "google-gemini-cli"); }); + + it("shares Gemini replay and stream hooks across Google provider variants", async () => { + const { providers } = await registerProviderPlugin({ + plugin: googleProviderPlugin, + id: "google", + name: "Google Provider", + }); + const googleProvider = requireRegisteredProvider(providers, "google"); + const cliProvider = requireRegisteredProvider(providers, "google-gemini-cli"); + + expect(googleProvider.buildReplayPolicy).toBe(cliProvider.buildReplayPolicy); + expect(googleProvider.wrapStreamFn).toBe(cliProvider.wrapStreamFn); + }); }); diff --git a/extensions/google/provider-hooks.ts b/extensions/google/provider-hooks.ts new file mode 100644 index 00000000000..a72f2bcd762 --- /dev/null +++ b/extensions/google/provider-hooks.ts @@ -0,0 +1,9 @@ +import { buildProviderReplayFamilyHooks } from "openclaw/plugin-sdk/provider-model-shared"; +import { buildProviderStreamFamilyHooks } from "openclaw/plugin-sdk/provider-stream-family"; + +export const GOOGLE_GEMINI_PROVIDER_HOOKS = { + ...buildProviderReplayFamilyHooks({ + family: "google-gemini", + }), + ...buildProviderStreamFamilyHooks("google-thinking"), +}; diff --git a/extensions/google/provider-registration.ts b/extensions/google/provider-registration.ts index 13b8ad37032..1883a961cf1 100644 --- a/extensions/google/provider-registration.ts +++ b/extensions/google/provider-registration.ts @@ -1,7 +1,5 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry"; import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key"; -import { buildProviderReplayFamilyHooks } from "openclaw/plugin-sdk/provider-model-shared"; -import { buildProviderStreamFamilyHooks } from "openclaw/plugin-sdk/provider-stream-family"; import { GOOGLE_GEMINI_DEFAULT_MODEL, applyGoogleGeminiModelDefault, @@ -9,15 +7,9 @@ import { normalizeGoogleModelId, resolveGoogleGenerativeAiTransport, } from "./api.js"; +import { GOOGLE_GEMINI_PROVIDER_HOOKS } from "./provider-hooks.js"; import { isModernGoogleModel, resolveGoogleGeminiForwardCompatModel } from "./provider-models.js"; -const GOOGLE_GEMINI_PROVIDER_HOOKS = { - ...buildProviderReplayFamilyHooks({ - family: "google-gemini", - }), - ...buildProviderStreamFamilyHooks("google-thinking"), -}; - export function registerGoogleProvider(api: OpenClawPluginApi) { api.registerProvider({ id: "google",