feat(settings): Codex Bağlama, on by default
Settings → Codex Bağlama runs the bundled bridge for an OpenAI Codex install on the same computer: the IDE's models and combos appear in Codex and switching models keeps the conversation. The IDE points Codex's openai_base_url at the bridge only after the bridge answers, keeps it running across logins, and removes every trace when the setting is turned off. A Codex that already uses another base URL is left untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HRDGW1LiKcDUZYUdKBoWYW
This commit is contained in:
1 parent
1ce5ab82cf
commit
dea67fc153
16 files changed
+2317
-2
No files matched your search
@@ -0,0 +1,193 @@
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { I18nProvider } from '@/i18n/context'
|
||||
|
||||
import type { CodexLinkStatus } from '../../../electron/codex-link-types'
|
||||
|
||||
import { CodexLinkSettings } from './codex-link-settings'
|
||||
|
||||
const notifyError = vi.hoisted(() => vi.fn())
|
||||
vi.mock('@/store/notifications', () => ({ notifyError }))
|
||||
|
||||
const RUNNING: CodexLinkStatus = {
|
||||
enabled: true,
|
||||
codexFound: true,
|
||||
venvReady: true,
|
||||
foreign: false,
|
||||
bridgeRunning: true,
|
||||
ideDurum: 'tamam',
|
||||
ideModel: 12,
|
||||
ozet: true,
|
||||
lastError: null
|
||||
}
|
||||
|
||||
const get = vi.fn<() => Promise<CodexLinkStatus>>()
|
||||
const set = vi.fn<(patch: { enabled?: boolean; sync?: boolean }) => Promise<CodexLinkStatus>>()
|
||||
|
||||
function renderPage(locale: 'en' | 'tr' = 'tr') {
|
||||
return render(
|
||||
<I18nProvider configClient={null} initialLocale={locale}>
|
||||
<CodexLinkSettings />
|
||||
</I18nProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function statusTexts() {
|
||||
return screen.getAllByRole('listitem').map(item => item.textContent)
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
;(window as unknown as { hermesDesktop: unknown }).hermesDesktop = { codexLink: { get, set } }
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.resetAllMocks()
|
||||
delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
|
||||
})
|
||||
|
||||
describe('Codex Link settings', () => {
|
||||
it('explains the feature and shows a healthy link in Turkish', async () => {
|
||||
get.mockResolvedValue(RUNNING)
|
||||
renderPage()
|
||||
|
||||
expect(await screen.findByText('Köprü çalışıyor.')).toBeTruthy()
|
||||
expect(statusTexts()).toEqual(['Bu bilgisayarda Codex bulundu.', 'Köprü çalışıyor.', "Codex'e 12 model eklendi."])
|
||||
expect(
|
||||
screen.getByText(
|
||||
"AITURK IDE'deki modelleri ve comboları bu bilgisayardaki Codex'e ekler; modeller arasında geçerken sohbet bağlamını korur."
|
||||
)
|
||||
).toBeTruthy()
|
||||
expect(screen.getByText("Codex'te yeni modelleri görmek için Codex'i yeniden açın.")).toBeTruthy()
|
||||
expect(screen.getByRole('switch', { name: 'Codex Bağlama' }).getAttribute('aria-checked')).toBe('true')
|
||||
expect(set).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders in English for other locales', async () => {
|
||||
get.mockResolvedValue(RUNNING)
|
||||
renderPage('en')
|
||||
|
||||
expect(await screen.findByText('The bridge is running.')).toBeTruthy()
|
||||
expect(statusTexts()).toEqual([
|
||||
'Codex was found on this computer.',
|
||||
'The bridge is running.',
|
||||
'12 models added to Codex.'
|
||||
])
|
||||
expect(screen.getByRole('button', { name: 'Sync now' })).toBeTruthy()
|
||||
})
|
||||
|
||||
it('says only that Codex is missing when it is not installed', async () => {
|
||||
get.mockResolvedValue({ ...RUNNING, codexFound: false, bridgeRunning: false, ideDurum: null, ideModel: null })
|
||||
renderPage()
|
||||
|
||||
expect(await screen.findByText('Bu bilgisayarda Codex bulunamadı.')).toBeTruthy()
|
||||
expect(statusTexts()).toEqual(['Bu bilgisayarda Codex bulunamadı.'])
|
||||
})
|
||||
|
||||
it('says another bridge is in charge and does not claim ours is running', async () => {
|
||||
get.mockResolvedValue({ ...RUNNING, foreign: true })
|
||||
renderPage()
|
||||
|
||||
expect(await screen.findByText(/başka bir köprü kullanıyor/)).toBeTruthy()
|
||||
expect(statusTexts()).toEqual([
|
||||
'Bu bilgisayarda Codex bulundu.',
|
||||
'Bu bilgisayarda Codex başka bir köprü kullanıyor; ayarına dokunulmadı.'
|
||||
])
|
||||
})
|
||||
|
||||
it('says it is waiting for the IDE setup', async () => {
|
||||
get.mockResolvedValue({ ...RUNNING, venvReady: false, bridgeRunning: false, ideDurum: null, ideModel: null })
|
||||
renderPage()
|
||||
|
||||
expect(await screen.findByText('IDE kurulumu tamamlanınca etkinleşecek.')).toBeTruthy()
|
||||
expect(screen.queryByText('Köprü çalışmıyor.')).toBeNull()
|
||||
})
|
||||
|
||||
it('asks for a sign-in when the bridge has no IDE session', async () => {
|
||||
get.mockResolvedValue({ ...RUNNING, ideDurum: 'anahtar-yok', ideModel: 0 })
|
||||
renderPage()
|
||||
|
||||
expect(await screen.findByText('IDE oturumu bulunamadı, giriş yapın.')).toBeTruthy()
|
||||
expect(screen.queryByText(/model eklendi/)).toBeNull()
|
||||
})
|
||||
|
||||
it('shows a stopped bridge together with the last error', async () => {
|
||||
get.mockResolvedValue({
|
||||
...RUNNING,
|
||||
bridgeRunning: false,
|
||||
ideDurum: null,
|
||||
ideModel: null,
|
||||
lastError: 'bridge-start-failed'
|
||||
})
|
||||
renderPage()
|
||||
|
||||
expect(await screen.findByText('Köprü çalışmıyor.')).toBeTruthy()
|
||||
expect(screen.getByText('Köprü başlatılamadı; Codex ayarına dokunulmadı.')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('turns the link off through the bridge and adopts the reply', async () => {
|
||||
get.mockResolvedValue(RUNNING)
|
||||
set.mockResolvedValue({ ...RUNNING, enabled: false, bridgeRunning: false, ideDurum: null, ideModel: null })
|
||||
renderPage()
|
||||
|
||||
await screen.findByText('Köprü çalışıyor.')
|
||||
fireEvent.click(screen.getByRole('switch', { name: 'Codex Bağlama' }))
|
||||
|
||||
expect(set).toHaveBeenCalledWith({ enabled: false })
|
||||
expect(await screen.findByText('Codex Bağlama kapalı. Codex kendi ayarlarıyla çalışıyor.')).toBeTruthy()
|
||||
expect(screen.getByRole('switch', { name: 'Codex Bağlama' }).getAttribute('aria-checked')).toBe('false')
|
||||
})
|
||||
|
||||
it('rolls the switch back and reports when the change fails', async () => {
|
||||
get.mockResolvedValue(RUNNING)
|
||||
set.mockRejectedValue(new Error('codex-link:unavailable'))
|
||||
renderPage()
|
||||
|
||||
await screen.findByText('Köprü çalışıyor.')
|
||||
fireEvent.click(screen.getByRole('switch', { name: 'Codex Bağlama' }))
|
||||
|
||||
await waitFor(() => expect(notifyError).toHaveBeenCalledWith(expect.any(Error), 'Codex Bağlama değiştirilemedi.'))
|
||||
expect(screen.getByRole('switch', { name: 'Codex Bağlama' }).getAttribute('aria-checked')).toBe('true')
|
||||
expect(screen.getByText('Köprü çalışıyor.')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('syncs on demand and keeps the button disabled while it runs', async () => {
|
||||
get.mockResolvedValue({ ...RUNNING, bridgeRunning: false, ideDurum: null, ideModel: null })
|
||||
|
||||
let finish: (status: CodexLinkStatus) => void = () => undefined
|
||||
|
||||
set.mockReturnValue(
|
||||
new Promise<CodexLinkStatus>(resolve => {
|
||||
finish = resolve
|
||||
})
|
||||
)
|
||||
renderPage()
|
||||
|
||||
await screen.findByText('Köprü çalışmıyor.')
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Şimdi eşitle' }))
|
||||
|
||||
expect(set).toHaveBeenCalledTimes(1)
|
||||
expect(set).toHaveBeenCalledWith({ sync: true })
|
||||
|
||||
const pending = screen.getByRole('button', { name: 'Eşitleniyor…' }) as HTMLButtonElement
|
||||
|
||||
expect(pending.disabled).toBe(true)
|
||||
fireEvent.click(pending)
|
||||
expect(set).toHaveBeenCalledTimes(1)
|
||||
|
||||
finish(RUNNING)
|
||||
|
||||
expect(await screen.findByText('Köprü çalışıyor.')).toBeTruthy()
|
||||
expect((screen.getByRole('button', { name: 'Şimdi eşitle' }) as HTMLButtonElement).disabled).toBe(false)
|
||||
})
|
||||
|
||||
it('offers nothing to click where the desktop bridge is absent', () => {
|
||||
delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
|
||||
renderPage()
|
||||
|
||||
expect(screen.getByText('Codex Bağlama yalnızca Windows masaüstü uygulamasında kullanılabilir.')).toBeTruthy()
|
||||
expect(screen.queryByRole('switch')).toBeNull()
|
||||
expect(get).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,233 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { type CodexLinkCopy, useCodexLinkCopy } from '@/i18n/codex-link'
|
||||
import { triggerHaptic } from '@/lib/haptics'
|
||||
import { AlertTriangle, Check, CircleIcon, Link, RefreshCw } from '@/lib/icons'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { notifyError } from '@/store/notifications'
|
||||
|
||||
import type { CodexLinkPatch, CodexLinkStatus } from '../../../electron/codex-link-types'
|
||||
|
||||
import { EmptyState, ListRow, ListRowSkeleton, SettingsContent, SettingsSection } from './primitives'
|
||||
|
||||
type Tone = 'muted' | 'ok' | 'warn'
|
||||
|
||||
interface StatusLine {
|
||||
id: string
|
||||
text: string
|
||||
tone: Tone
|
||||
}
|
||||
|
||||
/**
|
||||
* What the user needs to know, top-down, stopping at the first fact that makes
|
||||
* the rest moot (no Codex → nothing else to say; another bridge → ours is not
|
||||
* involved; setup pending → the bridge cannot be running yet).
|
||||
*/
|
||||
export function codexLinkStatusLines(status: CodexLinkStatus, copy: CodexLinkCopy): StatusLine[] {
|
||||
const lines: StatusLine[] = []
|
||||
const error = status.lastError ? [{ id: 'error', text: copy.errors[status.lastError], tone: 'warn' as const }] : []
|
||||
|
||||
if (!status.codexFound) {
|
||||
return [{ id: 'codex', text: copy.codexMissing, tone: 'muted' }, ...error]
|
||||
}
|
||||
|
||||
lines.push({ id: 'codex', text: copy.codexFound, tone: 'ok' })
|
||||
|
||||
if (status.foreign) {
|
||||
return [...lines, { id: 'foreign', text: copy.foreign, tone: 'warn' }, ...error]
|
||||
}
|
||||
|
||||
if (!status.enabled) {
|
||||
return [...lines, { id: 'off', text: copy.off, tone: 'muted' }, ...error]
|
||||
}
|
||||
|
||||
if (!status.venvReady) {
|
||||
return [...lines, { id: 'venv', text: copy.venvPending, tone: 'muted' }, ...error]
|
||||
}
|
||||
|
||||
if (!status.bridgeRunning) {
|
||||
return [...lines, { id: 'bridge', text: copy.bridgeStopped, tone: 'warn' }, ...error]
|
||||
}
|
||||
|
||||
lines.push({ id: 'bridge', text: copy.bridgeRunning, tone: 'ok' })
|
||||
|
||||
if (status.ideDurum === 'anahtar-yok') {
|
||||
lines.push({ id: 'ide', text: copy.signIn, tone: 'warn' })
|
||||
} else if (status.ideDurum === 'tamam' && status.ideModel !== null) {
|
||||
lines.push({ id: 'ide', text: copy.models(status.ideModel), tone: 'ok' })
|
||||
}
|
||||
|
||||
return [...lines, ...error]
|
||||
}
|
||||
|
||||
const TONE_ICON = { muted: CircleIcon, ok: Check, warn: AlertTriangle } as const
|
||||
|
||||
const TONE_CLASS: Record<Tone, string> = {
|
||||
muted: 'text-(--ui-text-tertiary)',
|
||||
ok: 'text-(--ui-text-secondary)',
|
||||
warn: 'text-amber-500/90'
|
||||
}
|
||||
|
||||
// Phone-sized hit area around the compact switch: the visible control keeps the
|
||||
// design-system size, the label that wraps it is the 44px target.
|
||||
const TOUCH_TARGET = 'flex min-h-11 min-w-11 cursor-pointer items-center @2xl:justify-end'
|
||||
|
||||
/**
|
||||
* Settings → Codex Link. Main owns everything real (the preference file, the
|
||||
* bridge, Codex's config, the login item); this page reads the state it reports
|
||||
* and asks for changes, adopting whatever comes back as the truth.
|
||||
*/
|
||||
export function CodexLinkSettings() {
|
||||
const copy = useCodexLinkCopy()
|
||||
const bridge = typeof window === 'undefined' ? undefined : window.hermesDesktop?.codexLink
|
||||
const [status, setStatus] = useState<CodexLinkStatus | null>(null)
|
||||
const [loadFailed, setLoadFailed] = useState(false)
|
||||
const [busy, setBusy] = useState<'sync' | 'toggle' | null>(null)
|
||||
// A slow initial read must not overwrite the answer to a newer change.
|
||||
const generation = useRef(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (!bridge) {
|
||||
return
|
||||
}
|
||||
|
||||
const ticket = generation.current
|
||||
|
||||
bridge.get().then(
|
||||
next => {
|
||||
if (generation.current === ticket) {
|
||||
setStatus(next)
|
||||
}
|
||||
},
|
||||
() => {
|
||||
if (generation.current === ticket) {
|
||||
setLoadFailed(true)
|
||||
}
|
||||
}
|
||||
)
|
||||
}, [bridge])
|
||||
|
||||
const change = useCallback(
|
||||
async (patch: CodexLinkPatch, kind: 'sync' | 'toggle') => {
|
||||
if (!bridge || busy) {
|
||||
return
|
||||
}
|
||||
|
||||
const before = status
|
||||
generation.current += 1
|
||||
setBusy(kind)
|
||||
setLoadFailed(false)
|
||||
|
||||
// The switch moves at once; main's reply (or the rollback) has the last word.
|
||||
if (typeof patch.enabled === 'boolean' && before) {
|
||||
setStatus({ ...before, enabled: patch.enabled })
|
||||
}
|
||||
|
||||
try {
|
||||
setStatus(await bridge.set(patch))
|
||||
} catch (error) {
|
||||
setStatus(before)
|
||||
notifyError(error, copy.saveFailed)
|
||||
} finally {
|
||||
setBusy(null)
|
||||
}
|
||||
},
|
||||
[bridge, busy, copy.saveFailed, status]
|
||||
)
|
||||
|
||||
if (!bridge) {
|
||||
return (
|
||||
<SettingsContent>
|
||||
<EmptyState description={copy.unavailable} title={copy.title} />
|
||||
</SettingsContent>
|
||||
)
|
||||
}
|
||||
|
||||
const lines = status ? codexLinkStatusLines(status, copy) : []
|
||||
|
||||
return (
|
||||
<SettingsContent>
|
||||
<SettingsSection icon={Link} title={copy.title}>
|
||||
<ListRow
|
||||
action={
|
||||
<label className={TOUCH_TARGET}>
|
||||
<Switch
|
||||
aria-label={copy.title}
|
||||
checked={status?.enabled ?? true}
|
||||
disabled={!status || busy !== null}
|
||||
onCheckedChange={enabled => {
|
||||
triggerHaptic('selection')
|
||||
void change({ enabled }, 'toggle')
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
}
|
||||
description={copy.description}
|
||||
title={copy.title}
|
||||
/>
|
||||
|
||||
{!status && !loadFailed && <ListRowSkeleton wide />}
|
||||
|
||||
{loadFailed && !status && (
|
||||
<p className="py-3 text-[length:var(--conversation-caption-font-size)] text-amber-500/90" role="alert">
|
||||
{copy.loadFailed}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{status && (
|
||||
<ListRow
|
||||
below={
|
||||
<ul aria-live="polite" className="mt-1.5 grid gap-1.5">
|
||||
{lines.map(line => {
|
||||
const Icon = TONE_ICON[line.tone]
|
||||
|
||||
return (
|
||||
<li
|
||||
className={cn(
|
||||
'flex min-w-0 items-start gap-2 text-[length:var(--conversation-caption-font-size)] leading-(--conversation-caption-line-height)',
|
||||
TONE_CLASS[line.tone]
|
||||
)}
|
||||
data-tone={line.tone}
|
||||
key={line.id}
|
||||
>
|
||||
<Icon aria-hidden className="mt-0.5 size-3.5 shrink-0" />
|
||||
<span className="min-w-0 break-words">{line.text}</span>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
}
|
||||
title={copy.statusTitle}
|
||||
wide
|
||||
/>
|
||||
)}
|
||||
|
||||
<ListRow
|
||||
action={
|
||||
<Button
|
||||
className="min-h-11 w-full @2xl:w-auto"
|
||||
disabled={!status || busy !== null}
|
||||
onClick={() => {
|
||||
triggerHaptic('open')
|
||||
void change({ sync: true }, 'sync')
|
||||
}}
|
||||
type="button"
|
||||
variant="secondary"
|
||||
>
|
||||
<RefreshCw />
|
||||
{busy === 'sync' ? copy.syncing : copy.sync}
|
||||
</Button>
|
||||
}
|
||||
description={copy.syncDesc}
|
||||
title={copy.syncTitle}
|
||||
/>
|
||||
|
||||
<p className="pt-2 text-[length:var(--conversation-caption-font-size)] leading-(--conversation-caption-line-height) text-(--ui-text-tertiary)">
|
||||
{copy.restartNote}
|
||||
</p>
|
||||
</SettingsSection>
|
||||
</SettingsContent>
|
||||
)
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { Tip } from '@/components/ui/tooltip'
|
||||
import { getHermesConfigDefaults, getHermesConfigRecord, saveHermesConfig } from '@/hermes'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { useAiturkCopy } from '@/i18n/aiturk'
|
||||
import { useCodexLinkCopy } from '@/i18n/codex-link'
|
||||
import { triggerHaptic } from '@/lib/haptics'
|
||||
import {
|
||||
Archive,
|
||||
@@ -20,6 +21,7 @@ import {
|
||||
Info,
|
||||
Keyboard,
|
||||
KeyRound,
|
||||
Link,
|
||||
Package,
|
||||
RefreshCw,
|
||||
Search,
|
||||
@@ -46,6 +48,7 @@ import { SKILLS_ROUTE } from '../routes'
|
||||
import { AboutSettings } from './about-settings'
|
||||
import { AppearanceSettings } from './appearance-settings'
|
||||
import { BillingSettings } from './billing'
|
||||
import { CodexLinkSettings } from './codex-link-settings'
|
||||
import { ConfigSettings } from './config-settings'
|
||||
import { SECTIONS } from './constants'
|
||||
import { GatewaySettings } from './gateway-settings'
|
||||
@@ -68,6 +71,7 @@ const SETTINGS_VIEWS: readonly SettingsViewId[] = [
|
||||
'keys',
|
||||
'notifications',
|
||||
'billing',
|
||||
'codex-link',
|
||||
'plugins',
|
||||
'sessions',
|
||||
'about'
|
||||
@@ -76,6 +80,7 @@ const SETTINGS_VIEWS: readonly SettingsViewId[] = [
|
||||
export function SettingsView({ onClose, onConfigSaved, onMainModelChanged }: SettingsPageProps) {
|
||||
const { t } = useI18n()
|
||||
const aiturkCopy = useAiturkCopy()
|
||||
const codexLinkCopy = useCodexLinkCopy()
|
||||
const navigate = useNavigate()
|
||||
const { hash, pathname, search } = useLocation()
|
||||
|
||||
@@ -267,6 +272,19 @@ export function SettingsView({ onClose, onConfigSaved, onMainModelChanged }: Set
|
||||
}
|
||||
]
|
||||
: []),
|
||||
// "Codex Bağlama": present only where the desktop bridge offers it
|
||||
// (Windows). A stale ?tab=codex-link elsewhere renders its own notice.
|
||||
...(window.hermesDesktop?.codexLink
|
||||
? [
|
||||
{
|
||||
active: activeView === 'codex-link',
|
||||
icon: Link,
|
||||
id: 'codex-link',
|
||||
label: codexLinkCopy.nav,
|
||||
onSelect: () => setActiveView('codex-link')
|
||||
}
|
||||
]
|
||||
: []),
|
||||
{
|
||||
active: activeView === 'keybinds',
|
||||
icon: Keyboard,
|
||||
@@ -320,7 +338,7 @@ export function SettingsView({ onClose, onConfigSaved, onMainModelChanged }: Set
|
||||
onSelect: () => setActiveView('about')
|
||||
}
|
||||
],
|
||||
[activeView, keysView, providerView, t, aiturkCopy, setActiveView, openProviderView, openKeysView]
|
||||
[activeView, keysView, providerView, t, aiturkCopy, codexLinkCopy, setActiveView, openProviderView, openKeysView]
|
||||
)
|
||||
|
||||
// Type-to-search: printable keystrokes on the Settings surface (outside any
|
||||
@@ -439,6 +457,8 @@ export function SettingsView({ onClose, onConfigSaved, onMainModelChanged }: Set
|
||||
<BillingSettings />
|
||||
) : activeView === 'plugins' ? (
|
||||
<PluginsSettings />
|
||||
) : activeView === 'codex-link' ? (
|
||||
<CodexLinkSettings />
|
||||
) : (
|
||||
<SessionsSettings />
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { EnvVarInfo } from '@/types/hermes'
|
||||
export type SettingsView =
|
||||
| 'about'
|
||||
| 'billing'
|
||||
| 'codex-link'
|
||||
| 'connections'
|
||||
| 'gateway'
|
||||
| 'keybinds'
|
||||
|
||||
Reference in new issue
Block a user