-
Notifications
You must be signed in to change notification settings - Fork 737
feat(settings): auto-detect running CLIProxyAPI and show import banner #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
92ba9a6
d397564
b5dbf88
8a73158
8f7fe77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@open-codesign/desktop': patch | ||
| '@open-codesign/i18n': patch | ||
| --- | ||
|
|
||
| feat(settings): auto-detect running CLIProxyAPI and show import banner | ||
|
|
||
| When the Models tab mounts, probes `http://127.0.0.1:8317/v1/models` via the existing `testEndpoint` IPC bridge. If CLIProxyAPI is running and no provider is already configured at that address, displays a `LocalCpaImportCard` banner above the provider list offering one-click import into `AddCustomProviderModal`. The banner is dismissible and the preference persists to `localStorage` via key `cpa-detection-dismissed-v1`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import { | |
| RotateCcw, | ||
| Sliders, | ||
| Trash2, | ||
| Zap, | ||
| } from 'lucide-react'; | ||
| import { useEffect, useMemo, useRef, useState } from 'react'; | ||
| import type { AppPaths, Preferences, ProviderRow, StorageKind } from '../../../preload/index'; | ||
|
|
@@ -856,6 +857,47 @@ function WarningsList({ warnings }: { warnings: string[] }) { | |
| ); | ||
| } | ||
|
|
||
| const CPA_DETECTION_DISMISSED_KEY = 'cpa-detection-dismissed-v1'; | ||
|
|
||
| function LocalCpaImportCard({ | ||
| onImport, | ||
| onDismiss, | ||
| }: { | ||
| onImport: () => void; | ||
| onDismiss: () => void; | ||
| }) { | ||
| const t = useT(); | ||
| return ( | ||
| <div className="rounded-[var(--radius-md)] border border-[var(--color-accent)] bg-[var(--color-accent-tint)] px-[var(--space-3)] py-[var(--space-2_5)] flex items-start gap-[var(--space-3)]"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Major] This new card introduces raw numeric utilities ( |
||
| <Zap className="w-4 h-4 mt-0.5 shrink-0 text-[var(--color-accent)]" aria-hidden="true" /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Major] New UI uses raw numeric utilities ( |
||
| <div className="flex-1 min-w-0"> | ||
| <p className="text-[var(--text-sm)] font-medium text-[var(--color-text-primary)] leading-snug"> | ||
| {t('settings.providers.cpaDetection.title')} | ||
| </p> | ||
| <p className="text-[var(--text-xs)] text-[var(--color-text-secondary)] mt-0.5 leading-[var(--leading-body)]"> | ||
| {t('settings.providers.cpaDetection.body')} | ||
| </p> | ||
| </div> | ||
| <div className="flex items-center gap-[var(--space-1_5)] shrink-0"> | ||
| <button | ||
| type="button" | ||
| onClick={onImport} | ||
| className="h-7 px-[var(--space-2_5)] rounded-[var(--radius-sm)] text-[var(--text-xs)] text-[var(--color-on-accent)] bg-[var(--color-accent)] hover:opacity-90 transition-opacity whitespace-nowrap" | ||
| > | ||
| {t('settings.providers.cpaDetection.importAction')} | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={onDismiss} | ||
| className="h-7 px-[var(--space-2)] rounded-[var(--radius-sm)] text-[var(--text-xs)] text-[var(--color-text-secondary)] hover:bg-[var(--color-surface-hover)] transition-colors whitespace-nowrap" | ||
| > | ||
| {t('settings.providers.cpaDetection.dismissAction')} | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function ModelsTab() { | ||
| const t = useT(); | ||
| const config = useCodesignStore((s) => s.config); | ||
|
|
@@ -866,6 +908,9 @@ function ModelsTab() { | |
| const [loading, setLoading] = useState(true); | ||
| const [showAddCustom, setShowAddCustom] = useState(false); | ||
| const [showAddMenu, setShowAddMenu] = useState(false); | ||
| const [cpaDetection, setCpaDetection] = useState< | ||
| 'idle' | 'detecting' | 'available' | 'unavailable' | ||
| >('idle'); | ||
| const [externalConfigs, setExternalConfigs] = useState<{ | ||
| codex?: { count: number } | undefined; | ||
| claudeCode?: | ||
|
|
@@ -994,6 +1039,44 @@ function ModelsTab() { | |
| }); | ||
| }, [pushToast, t]); | ||
|
|
||
| useEffect(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: this new detection effect adds multiple branches (dismissed, already-configured, probe success/failure) but there is no new/updated Vitest in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Minor] New CPA detection flow (detect/success/failure/dismiss/import) lacks Vitest coverage in this PR. Please add at least one focused test for the branch logic and dismissal persistence. |
||
| if (!window.codesign?.config?.testEndpoint) return; | ||
| // Only probe once — once we've reached a terminal state, skip. | ||
| if (cpaDetection !== 'idle') return; | ||
| // Skip if user already dismissed this banner for this install. | ||
| try { | ||
| if (window.localStorage.getItem(CPA_DETECTION_DISMISSED_KEY) === '1') return; | ||
| } catch { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Blocker] This catch silently ignores localStorage read failures. Project constraint requires surfacing errors with context instead of silent fallback. |
||
| // localStorage unavailable — proceed with detection | ||
| } | ||
| // Skip detection if a provider is already pointing at the CPA port. | ||
| // We wait for the rows load to settle before probing so we don't flash | ||
| // the banner and immediately hide it on the next render tick. | ||
| if (loading) return; | ||
| const alreadyConfigured = rows.some((r) => | ||
| /^https?:\/\/(localhost|127\.0\.0\.1):8317/.test(r.baseUrl ?? ''), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Minor] Regex is not bounded after
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Minor] Regex is not bounded after |
||
| ); | ||
| if (alreadyConfigured) return; | ||
|
|
||
| setCpaDetection('detecting'); | ||
| void window.codesign.config | ||
| .testEndpoint({ wire: 'anthropic', baseUrl: 'http://127.0.0.1:8317', apiKey: '' }) | ||
| .then((res) => { | ||
| setCpaDetection(res.ok ? 'available' : 'unavailable'); | ||
| }) | ||
| .catch((err) => { | ||
| reportableErrorToast({ | ||
| code: 'CPA_DETECTION_FAILED', | ||
| scope: 'settings', | ||
| title: t('settings.imageGen.toast.loadFailed', { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Major] This error path is for CPA detection, but the toast title uses
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Major] This CPA-detection error path uses |
||
| defaultValue: 'Image generation settings failed to load', | ||
| }), | ||
| description: cleanIpcError(err) || t('settings.common.unknownError'), | ||
| }); | ||
| setCpaDetection('unavailable'); | ||
| }); | ||
| }, [cpaDetection, loading, rows, pushToast, reportableErrorToast, t]); | ||
|
|
||
| async function reloadRows() { | ||
| if (!window.codesign) return; | ||
| const [nextRows, state] = await Promise.all([ | ||
|
|
@@ -1313,6 +1396,28 @@ function ModelsTab() { | |
|
|
||
| <div className="space-y-[var(--space-3)]"> | ||
| <ChatgptLoginCard onStatusChange={reloadRows} /> | ||
| {cpaDetection === 'available' && ( | ||
| <LocalCpaImportCard | ||
| onImport={() => { | ||
| setCustomProviderPreset({ | ||
| name: 'CLIProxyAPI', | ||
| baseUrl: 'http://127.0.0.1:8317', | ||
| wire: 'anthropic', | ||
| defaultModel: '', | ||
| }); | ||
| setShowAddCustom(true); | ||
| setCpaDetection('unavailable'); | ||
| }} | ||
| onDismiss={() => { | ||
| try { | ||
| window.localStorage.setItem(CPA_DETECTION_DISMISSED_KEY, '1'); | ||
| } catch { | ||
| // non-fatal | ||
| } | ||
| setCpaDetection('unavailable'); | ||
| }} | ||
| /> | ||
| )} | ||
| {externalConfigs !== null && | ||
| (externalConfigs.codex !== undefined || | ||
| externalConfigs.claudeCode !== undefined || | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Minor] These tests validate a local regex constant, not the
ModelsTabdetection effect/interaction path. Please add behavior tests around render + probe + dismiss/import.