fix(opencode): handle removed OpenAI OAuth auth
This commit is contained in:
parent
1882c33827
commit
3a0e9efe7d
2 changed files with 35 additions and 4 deletions
|
|
@ -340,6 +340,10 @@ export async function CodexAuthPlugin(input: PluginInput, options: CodexAuthPlug
|
||||||
return {
|
return {
|
||||||
apiKey: OAUTH_DUMMY_KEY,
|
apiKey: OAUTH_DUMMY_KEY,
|
||||||
async fetch(requestInput: RequestInfo | URL, init?: RequestInit) {
|
async fetch(requestInput: RequestInfo | URL, init?: RequestInit) {
|
||||||
|
const currentAuth = await getAuth()
|
||||||
|
if (currentAuth?.type !== "oauth")
|
||||||
|
return websocketFetch ? websocketFetch(requestInput, init) : fetch(requestInput, init)
|
||||||
|
|
||||||
if (init?.headers) {
|
if (init?.headers) {
|
||||||
if (init.headers instanceof Headers) {
|
if (init.headers instanceof Headers) {
|
||||||
init.headers.delete("authorization")
|
init.headers.delete("authorization")
|
||||||
|
|
@ -352,10 +356,6 @@ export async function CodexAuthPlugin(input: PluginInput, options: CodexAuthPlug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentAuth = await getAuth()
|
|
||||||
if (currentAuth.type !== "oauth")
|
|
||||||
return websocketFetch ? websocketFetch(requestInput, init) : fetch(requestInput, init)
|
|
||||||
|
|
||||||
const authWithAccount = currentAuth as typeof currentAuth & { accountId?: string }
|
const authWithAccount = currentAuth as typeof currentAuth & { accountId?: string }
|
||||||
|
|
||||||
if (!currentAuth.access || currentAuth.expires < Date.now()) {
|
if (!currentAuth.access || currentAuth.expires < Date.now()) {
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,37 @@ describe("plugin.codex", () => {
|
||||||
await enabled.dispose?.()
|
await enabled.dispose?.()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("passes requests through when OAuth auth is removed after loading", async () => {
|
||||||
|
let auth:
|
||||||
|
| {
|
||||||
|
type: "oauth"
|
||||||
|
refresh: string
|
||||||
|
access: string
|
||||||
|
expires: number
|
||||||
|
}
|
||||||
|
| undefined = {
|
||||||
|
type: "oauth",
|
||||||
|
refresh: "refresh",
|
||||||
|
access: "access",
|
||||||
|
expires: Date.now() + 60_000,
|
||||||
|
}
|
||||||
|
using server = Bun.serve({
|
||||||
|
port: 0,
|
||||||
|
fetch(request) {
|
||||||
|
return Response.json({ authorization: request.headers.get("authorization") })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const hooks = await CodexAuthPlugin({} as never)
|
||||||
|
const loaded = await hooks.auth!.loader!(async () => auth as never, {} as never)
|
||||||
|
auth = undefined
|
||||||
|
|
||||||
|
const response = await loaded.fetch!(server.url, {
|
||||||
|
headers: { authorization: "Bearer current" },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(await response.json()).toEqual({ authorization: "Bearer current" })
|
||||||
|
})
|
||||||
|
|
||||||
test("filters unsupported modes and uses Codex context limits for OAuth GPT models", async () => {
|
test("filters unsupported modes and uses Codex context limits for OAuth GPT models", async () => {
|
||||||
const hooks = await CodexAuthPlugin({} as never)
|
const hooks = await CodexAuthPlugin({} as never)
|
||||||
const limit = { context: 1_050_000, input: 922_000, output: 128_000 }
|
const limit = { context: 1_050_000, input: 922_000, output: 128_000 }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue