MCPcopy Create free account
hub / github.com/anomalyco/opencode / authFetch

Function authFetch

packages/core/src/plugin/provider/google-vertex.ts:41–55  ·  view source on GitHub ↗
(fetchWithRuntimeOptions?: unknown)

Source from the content-addressed store, hash-verified

39}
40
41function authFetch(fetchWithRuntimeOptions?: unknown) {
42 // Native Vertex SDKs handle ADC internally. OpenAI-compatible Vertex endpoints
43 // do not, so inject a Google access token into their fetch path.
44 return async (input: Parameters<typeof fetch>[0], init?: RequestInit) => {
45 const { GoogleAuth } = await import("google-auth-library")
46 const auth = new GoogleAuth({ scopes: ["https://www.googleapis.com/auth/cloud-platform"] })
47 const client = await auth.getClient()
48 const token = await client.getAccessToken()
49 const headers = new Headers(init?.headers)
50 headers.set("Authorization", `Bearer ${token.token}`)
51 return typeof fetchWithRuntimeOptions === "function"
52 ? fetchWithRuntimeOptions(input, { ...init, headers })
53 : fetch(input, { ...init, headers })
54 }
55}
56
57export const GoogleVertexPlugin = define({
58 id: "google-vertex",

Callers 1

google-vertex.tsFile · 0.85

Calls 4

getClientMethod · 0.80
getAccessTokenMethod · 0.80
fetchFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected