refactor(core): simplify ChatGPT connection state
This commit is contained in:
parent
aef37e4514
commit
88ccd16a0c
1 changed files with 4 additions and 3 deletions
|
|
@ -164,14 +164,16 @@ export const OpenAIPlugin = define({
|
|||
effect: Effect.fn(function* (ctx) {
|
||||
const bus = yield* Bus.Service
|
||||
const loading = Semaphore.makeUnsafe(1)
|
||||
let chatgpt: Credential.OAuth | undefined
|
||||
let chatgpt = false
|
||||
let account: string | undefined
|
||||
|
||||
const load = Effect.fn("OpenAIPlugin.load")(function* () {
|
||||
const connection = yield* ctx.integration.connection.active("openai")
|
||||
const credential = connection
|
||||
? yield* ctx.integration.connection.resolve(connection).pipe(Effect.catch(() => Effect.succeed(undefined)))
|
||||
: undefined
|
||||
chatgpt = credential?.type === "oauth" && OpenAICodex.isChatGPT(credential) ? credential : undefined
|
||||
chatgpt = OpenAICodex.isChatGPT(credential)
|
||||
account = OpenAICodex.accountID(credential)
|
||||
})
|
||||
|
||||
yield* ctx.integration.transform((draft) => {
|
||||
|
|
@ -194,7 +196,6 @@ export const OpenAIPlugin = define({
|
|||
const item = evt.provider.get(Provider.ID.openai)
|
||||
if (!item) return
|
||||
item.provider.settings = Provider.mergeOverlay(item.provider.settings, { baseURL: OpenAICodex.baseURL })
|
||||
const account = OpenAICodex.accountID(chatgpt)
|
||||
item.provider.headers = Provider.mergeHeaders(
|
||||
item.provider.headers,
|
||||
account === undefined ? undefined : { "chatgpt-account-id": account },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue