MCPcopy Index your code
hub / github.com/anomalyco/opencode / CodexAuthPlugin

Function CodexAuthPlugin

packages/opencode/src/plugin/openai/codex.ts:263–556  ·  view source on GitHub ↗
(input: PluginInput, options: CodexAuthPluginOptions = {})

Source from the content-addressed store, hash-verified

261}
262
263export async function CodexAuthPlugin(input: PluginInput, options: CodexAuthPluginOptions = {}): Promise<Hooks> {
264 const issuer = options.issuer ?? ISSUER
265 const codexApiEndpoint = options.codexApiEndpoint ?? CODEX_API_ENDPOINT
266 let websocketFetchInstalled = false
267 const websocketFetches: Array<ReturnType<typeof OpenAIWebSocketPool.createWebSocketFetch>> = []
268
269 return {
270 async dispose() {
271 for (const websocketFetch of websocketFetches) websocketFetch.close()
272 websocketFetches.length = 0
273 },
274 async event(input) {
275 if (input.event.type !== "session.deleted") return
276 for (const websocketFetch of websocketFetches) websocketFetch.remove(input.event.properties.info.id)
277 },
278 provider: {
279 id: "openai",
280 async models(provider, ctx) {
281 if (ctx.auth?.type !== "oauth") return provider.models
282
283 return Object.fromEntries(
284 Object.entries(provider.models)
285 .filter(([, model]) => {
286 if (ALLOWED_MODELS.has(model.api.id)) return true
287 if (DISALLOWED_MODELS.has(model.api.id)) return false
288 const match = model.api.id.match(/^gpt-(\d+\.\d+)/)
289 return match ? parseFloat(match[1]) > 5.4 : false
290 })
291 .map(([modelID, model]) => [
292 modelID,
293 {
294 ...model,
295 cost: {
296 input: 0,
297 output: 0,
298 cache: { read: 0, write: 0 },
299 },
300 limit: model.id.includes("gpt-5.5")
301 ? {
302 context: 400_000,
303 input: 272_000,
304 output: 128_000,
305 }
306 : model.limit,
307 },
308 ]),
309 )
310 },
311 },
312 auth: {
313 provider: "openai",
314 async loader(getAuth) {
315 const auth = await getAuth()
316 const websocketFetch = options.experimentalWebSockets
317 ? OpenAIWebSocketPool.createWebSocketFetch({ httpFetch: fetch })
318 : undefined
319 if (websocketFetch) {
320 websocketFetches.push(websocketFetch)

Callers 2

codex.test.tsFile · 0.90
internalPluginsFunction · 0.90

Calls 9

extractAccountIdFunction · 0.85
startOAuthServerFunction · 0.70
generatePKCEFunction · 0.70
base64UrlEncodeFunction · 0.70
buildAuthorizeUrlFunction · 0.70
waitForOAuthCallbackFunction · 0.70
stopOAuthServerFunction · 0.70
fetchFunction · 0.70
jsonMethod · 0.65

Tested by

no test coverage detected