slopus--happy
98e40dac97
CLI Smoke Test / smoke-test-linux (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-linux (24) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (24) (push) Has been cancelled
Expo App TypeScript typecheck / typecheck (push) Has been cancelled
67 行
2.2 KiB
TypeScript
67 行
2.2 KiB
TypeScript
import type {
|
|
AuthState,
|
|
Capability,
|
|
Plugin,
|
|
PluginContext,
|
|
} from '../types'
|
|
|
|
/**
|
|
* Codex plugin — auth-only for now. The agent worker is built on Claude
|
|
* Agent SDK, which only speaks Anthropic. Once an OpenAI-compatible path
|
|
* lands, this plugin can declare its own llm-inference capability.
|
|
*/
|
|
class CodexPlugin implements Plugin {
|
|
id = 'codex'
|
|
name = 'Codex'
|
|
description = 'Sign in with your ChatGPT account. (Inference via Codex coming soon — currently auth-only.)'
|
|
vendor = 'OpenAI'
|
|
category = 'inference' as const
|
|
accent = '#10a37f'
|
|
|
|
private auth: AuthState = { status: 'unconfigured' }
|
|
private capabilities: Capability[] = []
|
|
|
|
async activate(_ctx: PluginContext) {
|
|
try {
|
|
const snap = await window.codexAuth.status()
|
|
if (snap.status === 'connected') {
|
|
this.auth = { status: 'connected', account: snap.email }
|
|
}
|
|
} catch {
|
|
/* codexAuth IPC not available — leave unconfigured. */
|
|
}
|
|
}
|
|
|
|
async connect(_credential: string, ctx: PluginContext): Promise<AuthState> {
|
|
try {
|
|
this.auth = { status: 'connecting' }
|
|
ctx.onAuthChanged()
|
|
const snap = await window.codexAuth.login()
|
|
if (snap.status !== 'connected') {
|
|
this.auth = { status: 'error', message: 'Login finished but no tokens were written.' }
|
|
ctx.onAuthChanged()
|
|
return this.auth
|
|
}
|
|
this.auth = { status: 'connected', account: snap.email }
|
|
ctx.onAuthChanged()
|
|
return this.auth
|
|
} catch (err) {
|
|
const msg = err instanceof Error ? err.message : String(err)
|
|
this.auth = { status: 'error', message: msg }
|
|
ctx.onAuthChanged()
|
|
return this.auth
|
|
}
|
|
}
|
|
|
|
async disconnect(ctx: PluginContext) {
|
|
try { await window.codexAuth.logout() } catch {}
|
|
this.auth = { status: 'unconfigured' }
|
|
ctx.onAuthChanged()
|
|
}
|
|
|
|
getAuthState(): AuthState { return this.auth }
|
|
getCapabilities(): readonly Capability[] { return this.capabilities }
|
|
}
|
|
|
|
export const codexPlugin: Plugin = new CodexPlugin()
|