(input: PluginInput, options: CodexAuthPluginOptions = {})
| 261 | } |
| 262 | |
| 263 | export 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) |
no test coverage detected