Skip to content

refactor(providers): share google and xai provider helpers#60722

Merged
vincentkoc merged 10 commits into
mainfrom
refactor/google-oauth-helper-dedupe
Apr 4, 2026
Merged

refactor(providers): share google and xai provider helpers#60722
vincentkoc merged 10 commits into
mainfrom
refactor/google-oauth-helper-dedupe

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

  • share Google OAuth token and Generative AI HTTP request helpers across provider entrypoints
  • share xAI tool auth, config, fallback auth, and Responses request helpers across plugin/tool surfaces
  • reduce provider-local duplicate parsing and request-body construction without changing provider behavior

Verification

  • pnpm exec oxlint extensions/google/api.ts extensions/google/api.test.ts extensions/google/gemini-cli-provider.ts extensions/google/index.ts extensions/google/image-generation-provider.ts extensions/google/media-understanding-provider.ts extensions/google/oauth-token-shared.ts extensions/google/oauth-token-shared.test.ts extensions/google/runtime-api.ts extensions/xai/code-execution.ts extensions/xai/index.ts extensions/xai/src/code-execution-shared.ts extensions/xai/src/responses-tool-shared.ts extensions/xai/src/responses-tool-shared.test.ts extensions/xai/src/tool-auth-shared.ts extensions/xai/src/tool-auth-shared.test.ts extensions/xai/src/tool-config-shared.ts extensions/xai/src/tool-config-shared.test.ts extensions/xai/src/web-search-shared.ts extensions/xai/src/x-search-shared.ts extensions/xai/x-search.ts
  • pnpm exec vitest run --config vitest.config.ts extensions/google/api.test.ts extensions/google/oauth-token-shared.test.ts extensions/xai/src/tool-auth-shared.test.ts extensions/xai/src/tool-config-shared.test.ts extensions/xai/src/responses-tool-shared.test.ts
  • pnpm build

Notes

  • pnpm build ran through the expected build chain in this worktree, but the local session wrapper did not emit a final clean exit after subprocess completion. No build subprocesses were left running after the run.

@vincentkoc vincentkoc self-assigned this Apr 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Apr 4, 2026
@vincentkoc vincentkoc marked this pull request as ready for review April 4, 2026 06:28

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e9fdf28dd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +55 to +57
resolveGoogleGenerativeAiHttpRequestConfig({
apiKey: params.apiKey,
baseUrl: params.baseUrl ?? params.defaultBaseUrl,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep private-network disabled for default media endpoint

This call now passes params.baseUrl ?? params.defaultBaseUrl into resolveGoogleGenerativeAiHttpRequestConfig, but that helper sets allowPrivateNetwork from whether baseUrl is non-empty. Since defaultBaseUrl is always set, audio/video requests now enable private-network access even when the user did not configure a custom base URL. Previously this path only enabled private-network when params.baseUrl was explicitly provided, so this change silently weakens the network guard for the default Google endpoint.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR is a focused refactoring that extracts duplicated provider helpers into shared modules for both the Google and xAI extensions, without changing any observable provider behavior.

Google changes:

  • oauth-token-shared.ts (new): centralises parseGoogleOauthApiKey, formatGoogleOauthApiKey, and parseGoogleUsageToken, consumed by gemini-cli-provider.ts and index.ts.
  • api.ts gains resolveGoogleGenerativeAiHttpRequestConfig, a single shared HTTP request config builder now used by both image-generation-provider.ts and media-understanding-provider.ts.
  • runtime-api.ts re-exports the new helper so the existing import surface of that barrel is preserved.

xAI changes:

  • src/tool-auth-shared.ts (new): shared xAI API key resolution (plugin config → legacy grok → env var) with source metadata.
  • src/tool-config-shared.ts (new): shared model/config normalization helpers (coerceXaiToolConfig, resolveNormalizedXaiToolModel, resolvePositiveIntegerToolConfig).
  • src/responses-tool-shared.ts (new): shared Responses API body builder and citation extractor, used by web-search-shared.ts, x-search-shared.ts, and code-execution-shared.ts.
  • src/code-execution-shared.ts (new): code execution tool helper wrapping the shared Responses API primitives.

One issue found:

  • extractXaiWebSearchContent is imported in extensions/xai/src/x-search-shared.ts:12 and extensions/xai/src/code-execution-shared.ts:12 but is unused in both files — it belongs only to web-search-shared.ts where it is correctly re-exported. These dead imports should be removed.

Confidence Score: 4/5

Safe to merge after removing two unused imports; no behavioral changes introduced.

The refactoring is well-scoped, all shared helpers have accompanying unit tests, and the extraction follows existing extension patterns. The only issue is two unused extractXaiWebSearchContent imports in x-search-shared.ts and code-execution-shared.ts that were likely left over from an intermediate draft — they are dead code but do not affect runtime behavior.

extensions/xai/src/x-search-shared.ts and extensions/xai/src/code-execution-shared.ts — both carry an unused import of extractXaiWebSearchContent that should be removed.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/xai/src/x-search-shared.ts
Line: 12

Comment:
**Unused import introduced by this refactor**

`extractXaiWebSearchContent` is imported here but is never used anywhere in this module — it does not appear in `resolveXaiXSearchConfig`, `resolveXaiXSearchModel`, `requestXaiXSearch`, `buildXaiXSearchPayload`, or the `__testing` export. The same pattern appears in `extensions/xai/src/code-execution-shared.ts:12`. Both were likely copied from an earlier draft before the function was moved to live exclusively in `web-search-shared.ts`.

Remove the dead binding from both import statements:

```suggestion
import { type XaiWebSearchResponse } from "./web-search-shared.js";
```

And in `extensions/xai/src/code-execution-shared.ts` line 12:
```ts
import { type XaiWebSearchResponse } from "./web-search-shared.js";
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(xai): re-export shared web search ex..." | Re-trigger Greptile

Comment thread extensions/xai/src/x-search-shared.ts Outdated
resolveNormalizedXaiToolModel,
resolvePositiveIntegerToolConfig,
} from "./tool-config-shared.js";
import { extractXaiWebSearchContent, type XaiWebSearchResponse } from "./web-search-shared.js";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unused import introduced by this refactor

extractXaiWebSearchContent is imported here but is never used anywhere in this module — it does not appear in resolveXaiXSearchConfig, resolveXaiXSearchModel, requestXaiXSearch, buildXaiXSearchPayload, or the __testing export. The same pattern appears in extensions/xai/src/code-execution-shared.ts:12. Both were likely copied from an earlier draft before the function was moved to live exclusively in web-search-shared.ts.

Remove the dead binding from both import statements:

Suggested change
import { extractXaiWebSearchContent, type XaiWebSearchResponse } from "./web-search-shared.js";
import { type XaiWebSearchResponse } from "./web-search-shared.js";

And in extensions/xai/src/code-execution-shared.ts line 12:

import { type XaiWebSearchResponse } from "./web-search-shared.js";
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/xai/src/x-search-shared.ts
Line: 12

Comment:
**Unused import introduced by this refactor**

`extractXaiWebSearchContent` is imported here but is never used anywhere in this module — it does not appear in `resolveXaiXSearchConfig`, `resolveXaiXSearchModel`, `requestXaiXSearch`, `buildXaiXSearchPayload`, or the `__testing` export. The same pattern appears in `extensions/xai/src/code-execution-shared.ts:12`. Both were likely copied from an earlier draft before the function was moved to live exclusively in `web-search-shared.ts`.

Remove the dead binding from both import statements:

```suggestion
import { type XaiWebSearchResponse } from "./web-search-shared.js";
```

And in `extensions/xai/src/code-execution-shared.ts` line 12:
```ts
import { type XaiWebSearchResponse } from "./web-search-shared.js";
```

How can I resolve this? If you propose a fix, please make it concise.

@vincentkoc vincentkoc merged commit 65842aa into main Apr 4, 2026
8 of 9 checks passed
@vincentkoc vincentkoc deleted the refactor/google-oauth-helper-dedupe branch April 4, 2026 07:14
KimGLee pushed a commit to KimGLee/openclaw that referenced this pull request Apr 4, 2026
…60722)

* refactor(google): share oauth token helpers

* refactor(xai): share tool auth fallback helpers

* refactor(xai): share tool auth resolution

* refactor(xai): share tool config helpers

* refactor(xai): share fallback auth helpers

* refactor(xai): share responses tool helpers

* refactor(google): share http request config helper

* fix(xai): re-export shared web search extractor

* fix(xai): import plugin config type

* fix(providers): preserve default google network guard
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…60722)

* refactor(google): share oauth token helpers

* refactor(xai): share tool auth fallback helpers

* refactor(xai): share tool auth resolution

* refactor(xai): share tool config helpers

* refactor(xai): share fallback auth helpers

* refactor(xai): share responses tool helpers

* refactor(google): share http request config helper

* fix(xai): re-export shared web search extractor

* fix(xai): import plugin config type

* fix(providers): preserve default google network guard
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…60722)

* refactor(google): share oauth token helpers

* refactor(xai): share tool auth fallback helpers

* refactor(xai): share tool auth resolution

* refactor(xai): share tool config helpers

* refactor(xai): share fallback auth helpers

* refactor(xai): share responses tool helpers

* refactor(google): share http request config helper

* fix(xai): re-export shared web search extractor

* fix(xai): import plugin config type

* fix(providers): preserve default google network guard
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…60722)

* refactor(google): share oauth token helpers

* refactor(xai): share tool auth fallback helpers

* refactor(xai): share tool auth resolution

* refactor(xai): share tool config helpers

* refactor(xai): share fallback auth helpers

* refactor(xai): share responses tool helpers

* refactor(google): share http request config helper

* fix(xai): re-export shared web search extractor

* fix(xai): import plugin config type

* fix(providers): preserve default google network guard
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…60722)

* refactor(google): share oauth token helpers

* refactor(xai): share tool auth fallback helpers

* refactor(xai): share tool auth resolution

* refactor(xai): share tool config helpers

* refactor(xai): share fallback auth helpers

* refactor(xai): share responses tool helpers

* refactor(google): share http request config helper

* fix(xai): re-export shared web search extractor

* fix(xai): import plugin config type

* fix(providers): preserve default google network guard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant