@geminilight/mindos 0.5.9 → 0.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/app/api/settings/test-key/route.ts +111 -0
- package/app/app/api/skills/route.ts +1 -1
- package/app/app/api/sync/route.ts +16 -31
- package/app/app/globals.css +10 -2
- package/app/app/login/page.tsx +1 -1
- package/app/app/view/[...path]/ViewPageClient.tsx +6 -1
- package/app/app/view/[...path]/not-found.tsx +1 -1
- package/app/components/AskModal.tsx +4 -4
- package/app/components/Breadcrumb.tsx +2 -2
- package/app/components/DirView.tsx +6 -6
- package/app/components/FileTree.tsx +2 -2
- package/app/components/HomeContent.tsx +7 -7
- package/app/components/OnboardingView.tsx +1 -1
- package/app/components/SearchModal.tsx +1 -1
- package/app/components/SettingsModal.tsx +2 -2
- package/app/components/SetupWizard.tsx +1 -1400
- package/app/components/Sidebar.tsx +4 -4
- package/app/components/SidebarLayout.tsx +9 -0
- package/app/components/SyncStatusBar.tsx +3 -3
- package/app/components/TableOfContents.tsx +1 -1
- package/app/components/UpdateBanner.tsx +1 -1
- package/app/components/ask/FileChip.tsx +1 -1
- package/app/components/ask/MentionPopover.tsx +4 -4
- package/app/components/ask/MessageList.tsx +1 -1
- package/app/components/ask/SessionHistory.tsx +2 -2
- package/app/components/renderers/config/ConfigRenderer.tsx +1 -1
- package/app/components/renderers/csv/BoardView.tsx +2 -2
- package/app/components/renderers/csv/ConfigPanel.tsx +5 -5
- package/app/components/renderers/csv/GalleryView.tsx +1 -1
- package/app/components/renderers/graph/GraphRenderer.tsx +1 -1
- package/app/components/renderers/summary/SummaryRenderer.tsx +1 -1
- package/app/components/renderers/workflow/WorkflowRenderer.tsx +2 -2
- package/app/components/settings/AiTab.tsx +120 -2
- package/app/components/settings/KnowledgeTab.tsx +1 -1
- package/app/components/settings/McpTab.tsx +27 -23
- package/app/components/settings/PluginsTab.tsx +4 -4
- package/app/components/settings/Primitives.tsx +1 -1
- package/app/components/settings/SyncTab.tsx +8 -8
- package/app/components/setup/StepAI.tsx +67 -0
- package/app/components/setup/StepAgents.tsx +237 -0
- package/app/components/setup/StepDots.tsx +39 -0
- package/app/components/setup/StepKB.tsx +237 -0
- package/app/components/setup/StepPorts.tsx +121 -0
- package/app/components/setup/StepReview.tsx +211 -0
- package/app/components/setup/StepSecurity.tsx +78 -0
- package/app/components/setup/constants.tsx +13 -0
- package/app/components/setup/index.tsx +464 -0
- package/app/components/setup/types.ts +53 -0
- package/app/instrumentation.ts +19 -0
- package/app/lib/i18n.ts +22 -4
- package/app/next.config.ts +1 -1
- package/bin/cli.js +8 -1
- package/bin/lib/sync.js +61 -11
- package/package.json +4 -2
- package/skills/project-wiki/SKILL.md +92 -63
- package/assets/images/demo-flow-dark.png +0 -0
- package/assets/images/demo-flow-light.png +0 -0
- package/assets/images/demo-flow-zh-dark.png +0 -0
- package/assets/images/demo-flow-zh-light.png +0 -0
- package/assets/images/gui-sync-cv.png +0 -0
- package/assets/images/wechat-qr.png +0 -0
- package/mcp/package-lock.json +0 -1717
|
@@ -121,7 +121,7 @@ export default function Sidebar({ fileTree, collapsed = false, onCollapse, onExp
|
|
|
121
121
|
|
|
122
122
|
{/* Mobile navbar */}
|
|
123
123
|
<header className="md:hidden fixed top-0 left-0 right-0 z-30 bg-card border-b border-border flex items-center justify-between px-3 py-2" style={{ paddingTop: 'env(safe-area-inset-top, 0px)' }}>
|
|
124
|
-
<button onClick={() => setMobileOpen(true)} className="p-
|
|
124
|
+
<button onClick={() => setMobileOpen(true)} className="p-3 -ml-1 rounded-lg hover:bg-muted text-muted-foreground hover:text-foreground transition-colors active:bg-accent" aria-label="Open menu">
|
|
125
125
|
<Menu size={20} />
|
|
126
126
|
</button>
|
|
127
127
|
<Link href="/" className="flex items-center gap-2 hover:opacity-80 transition-opacity">
|
|
@@ -132,15 +132,15 @@ export default function Sidebar({ fileTree, collapsed = false, onCollapse, onExp
|
|
|
132
132
|
{/* #8 — Mobile sync dot: visible when there's a problem */}
|
|
133
133
|
<button
|
|
134
134
|
onClick={openSyncSettings}
|
|
135
|
-
className="p-
|
|
135
|
+
className="p-3 rounded-lg hover:bg-muted text-muted-foreground hover:text-foreground transition-colors active:bg-accent flex items-center justify-center"
|
|
136
136
|
aria-label="Sync status"
|
|
137
137
|
>
|
|
138
138
|
<MobileSyncDot status={syncStatus} />
|
|
139
139
|
</button>
|
|
140
|
-
<button onClick={() => setSearchOpen(true)} className="p-
|
|
140
|
+
<button onClick={() => setSearchOpen(true)} className="p-3 rounded-lg hover:bg-muted text-muted-foreground hover:text-foreground transition-colors active:bg-accent" aria-label={t.sidebar.searchTitle}>
|
|
141
141
|
<Search size={20} />
|
|
142
142
|
</button>
|
|
143
|
-
<button onClick={() => setSettingsOpen(true)} className="p-
|
|
143
|
+
<button onClick={() => setSettingsOpen(true)} className="p-3 -mr-1 rounded-lg hover:bg-muted text-muted-foreground hover:text-foreground transition-colors active:bg-accent" aria-label={t.sidebar.settingsTitle}>
|
|
144
144
|
<Settings size={20} />
|
|
145
145
|
</button>
|
|
146
146
|
</div>
|
|
@@ -15,6 +15,14 @@ export default function SidebarLayout({ fileTree, children }: SidebarLayoutProps
|
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
17
|
<>
|
|
18
|
+
{/* Skip to main content — accessibility for keyboard users */}
|
|
19
|
+
<a
|
|
20
|
+
href="#main-content"
|
|
21
|
+
className="sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:z-[60] focus:px-4 focus:py-2 focus:rounded-lg focus:text-sm focus:font-medium focus:font-display"
|
|
22
|
+
style={{ background: 'var(--amber)', color: 'var(--amber-foreground)' }}
|
|
23
|
+
>
|
|
24
|
+
Skip to main content
|
|
25
|
+
</a>
|
|
18
26
|
<Sidebar
|
|
19
27
|
fileTree={fileTree}
|
|
20
28
|
collapsed={collapsed}
|
|
@@ -22,6 +30,7 @@ export default function SidebarLayout({ fileTree, children }: SidebarLayoutProps
|
|
|
22
30
|
onExpand={() => setCollapsed(false)}
|
|
23
31
|
/>
|
|
24
32
|
<main
|
|
33
|
+
id="main-content"
|
|
25
34
|
className={`min-h-screen transition-all duration-300 pt-[52px] md:pt-0 ${
|
|
26
35
|
collapsed ? 'md:pl-0' : 'md:pl-[280px]'
|
|
27
36
|
}`}
|
|
@@ -20,7 +20,7 @@ export function getStatusLevel(status: SyncStatus | null, syncing: boolean): Sta
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export const DOT_COLORS: Record<StatusLevel, string> = {
|
|
23
|
-
synced: 'bg-
|
|
23
|
+
synced: 'bg-success',
|
|
24
24
|
unpushed: 'bg-yellow-500',
|
|
25
25
|
conflicts: 'bg-error', // #6 — conflicts more prominent than unpushed
|
|
26
26
|
error: 'bg-error',
|
|
@@ -173,7 +173,7 @@ export default function SyncStatusBar({ collapsed, onOpenSyncSettings }: SyncSta
|
|
|
173
173
|
className="p-1 rounded hover:bg-muted hover:text-foreground transition-colors shrink-0 ml-2 text-muted-foreground/50 hover:text-muted-foreground"
|
|
174
174
|
title="Dismiss"
|
|
175
175
|
>
|
|
176
|
-
<span className="text-
|
|
176
|
+
<span className="text-2xs">✕</span>
|
|
177
177
|
</button>
|
|
178
178
|
</div>
|
|
179
179
|
);
|
|
@@ -231,7 +231,7 @@ export default function SyncStatusBar({ collapsed, onOpenSyncSettings }: SyncSta
|
|
|
231
231
|
</button>
|
|
232
232
|
<div className="flex items-center gap-1 shrink-0 ml-2">
|
|
233
233
|
{/* #2 — sync result flash */}
|
|
234
|
-
{(syncResult === 'success' || toast) && <CheckCircle2 size={12} className="text-
|
|
234
|
+
{(syncResult === 'success' || toast) && <CheckCircle2 size={12} className="text-success animate-in fade-in duration-200" />}
|
|
235
235
|
{syncResult === 'error' && <XCircle size={12} className="text-error animate-in fade-in duration-200" />}
|
|
236
236
|
<button
|
|
237
237
|
onClick={handleSyncNow}
|
|
@@ -111,7 +111,7 @@ export default function TableOfContents({ content }: TableOfContentsProps) {
|
|
|
111
111
|
style={{ background: 'var(--background)' }}
|
|
112
112
|
>
|
|
113
113
|
<p
|
|
114
|
-
className="text-
|
|
114
|
+
className="text-2xs font-semibold uppercase tracking-wider px-2 mb-1"
|
|
115
115
|
style={{ color: 'var(--muted-foreground)', opacity: 0.5 }}
|
|
116
116
|
>
|
|
117
117
|
On this page
|
|
@@ -60,7 +60,7 @@ export default function UpdateBanner() {
|
|
|
60
60
|
</span>
|
|
61
61
|
<span className="text-muted-foreground">
|
|
62
62
|
{updateT?.runUpdate ?? 'Run'}{' '}
|
|
63
|
-
<code className="px-1 py-0.5 rounded bg-muted font-mono text-
|
|
63
|
+
<code className="px-1 py-0.5 rounded bg-muted font-mono text-xs">mindos update</code>
|
|
64
64
|
{updateT?.orSee ? (
|
|
65
65
|
<>
|
|
66
66
|
{' '}{updateT.orSee}{' '}
|
|
@@ -12,7 +12,7 @@ export default function FileChip({ path, onRemove, variant = 'kb' }: FileChipPro
|
|
|
12
12
|
const name = path.split('/').pop() ?? path;
|
|
13
13
|
const isCsv = name.endsWith('.csv');
|
|
14
14
|
const Icon = variant === 'upload' ? Paperclip : isCsv ? Table : FileText;
|
|
15
|
-
const iconClass = variant === 'upload' ? 'text-
|
|
15
|
+
const iconClass = variant === 'upload' ? 'text-muted-foreground' : isCsv ? 'text-success' : 'text-muted-foreground';
|
|
16
16
|
|
|
17
17
|
return (
|
|
18
18
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs border border-border bg-muted text-foreground max-w-[220px]">
|
|
@@ -31,18 +31,18 @@ export default function MentionPopover({ results, selectedIndex, onSelect }: Men
|
|
|
31
31
|
}`}
|
|
32
32
|
>
|
|
33
33
|
{isCsv ? (
|
|
34
|
-
<Table size={13} className="text-
|
|
34
|
+
<Table size={13} className="text-success shrink-0" />
|
|
35
35
|
) : (
|
|
36
|
-
<FileText size={13} className="text-
|
|
36
|
+
<FileText size={13} className="text-muted-foreground shrink-0" />
|
|
37
37
|
)}
|
|
38
38
|
<span className="truncate flex-1">{name}</span>
|
|
39
|
-
<span className="text-
|
|
39
|
+
<span className="text-2xs text-muted-foreground/50 truncate max-w-[140px] shrink-0">
|
|
40
40
|
{f.split('/').slice(0, -1).join('/')}
|
|
41
41
|
</span>
|
|
42
42
|
</button>
|
|
43
43
|
);
|
|
44
44
|
})}
|
|
45
|
-
<div className="px-3 py-1.5 border-t border-border flex gap-3 text-
|
|
45
|
+
<div className="px-3 py-1.5 border-t border-border flex gap-3 text-2xs text-muted-foreground/50">
|
|
46
46
|
<span>↑↓ navigate</span>
|
|
47
47
|
<span>↵ select</span>
|
|
48
48
|
<span>ESC dismiss</span>
|
|
@@ -89,7 +89,7 @@ export default function MessageList({
|
|
|
89
89
|
{m.role === 'user' ? (
|
|
90
90
|
<div
|
|
91
91
|
className="max-w-[85%] px-3 py-2 rounded-xl rounded-br-sm text-sm leading-relaxed whitespace-pre-wrap"
|
|
92
|
-
style={{ background: 'var(--amber)', color: '
|
|
92
|
+
style={{ background: 'var(--amber)', color: 'var(--amber-foreground)' }}
|
|
93
93
|
>
|
|
94
94
|
{m.content}
|
|
95
95
|
</div>
|
|
@@ -14,7 +14,7 @@ interface SessionHistoryProps {
|
|
|
14
14
|
export default function SessionHistory({ sessions, activeSessionId, onLoad, onDelete }: SessionHistoryProps) {
|
|
15
15
|
return (
|
|
16
16
|
<div className="border-b border-border px-4 py-2.5 max-h-[190px] overflow-y-auto">
|
|
17
|
-
<div className="text-
|
|
17
|
+
<div className="text-xs text-muted-foreground mb-2">Session History</div>
|
|
18
18
|
<div className="flex flex-col gap-1.5">
|
|
19
19
|
{sessions.length === 0 && (
|
|
20
20
|
<div className="text-xs text-muted-foreground/70">No saved sessions.</div>
|
|
@@ -31,7 +31,7 @@ export default function SessionHistory({ sessions, activeSessionId, onLoad, onDe
|
|
|
31
31
|
}`}
|
|
32
32
|
>
|
|
33
33
|
<div className="truncate">{sessionTitle(s)}</div>
|
|
34
|
-
<div className="text-
|
|
34
|
+
<div className="text-2xs opacity-60">{new Date(s.updatedAt).toLocaleString()}</div>
|
|
35
35
|
</button>
|
|
36
36
|
<button
|
|
37
37
|
type="button"
|
|
@@ -144,7 +144,7 @@ export function ConfigRenderer({ content, saveAction }: RendererContext) {
|
|
|
144
144
|
className="px-2.5 py-1 rounded-md text-xs font-medium"
|
|
145
145
|
style={{
|
|
146
146
|
background: value ? 'var(--amber)' : 'var(--muted)',
|
|
147
|
-
color: value ? '
|
|
147
|
+
color: value ? 'var(--amber-foreground)' : 'var(--muted-foreground)',
|
|
148
148
|
}}
|
|
149
149
|
>
|
|
150
150
|
{value ? 'ON' : 'OFF'}
|
|
@@ -80,7 +80,7 @@ export function BoardView({ headers, rows, cfg, saveAction }: {
|
|
|
80
80
|
{headers.map((h, ci) => {
|
|
81
81
|
if (ci === groupIdx || ci === titleIdx || ci === descIdx) return null;
|
|
82
82
|
const v = row[ci]; if (!v) return null;
|
|
83
|
-
return <span key={ci} className="text-
|
|
83
|
+
return <span key={ci} className="text-2xs px-1.5 py-0.5 rounded font-display"
|
|
84
84
|
style={{ background: 'var(--muted)', color: 'var(--muted-foreground)' }}
|
|
85
85
|
>{h}: {v}</span>;
|
|
86
86
|
})}
|
|
@@ -124,7 +124,7 @@ export function BoardView({ headers, rows, cfg, saveAction }: {
|
|
|
124
124
|
setShowNewCol(false);
|
|
125
125
|
}}
|
|
126
126
|
className="text-xs px-2 py-1 rounded font-display"
|
|
127
|
-
style={{ background: 'var(--amber)', color: '
|
|
127
|
+
style={{ background: 'var(--amber)', color: 'var(--amber-foreground)' }}
|
|
128
128
|
>Create</button>
|
|
129
129
|
<button onClick={() => { setNewColInput(''); setShowNewCol(false); }}
|
|
130
130
|
className="text-xs px-2 py-1 rounded font-display"
|
|
@@ -39,7 +39,7 @@ export function ConfigPanel({ headers, cfg, view, onClose, onChange }: {
|
|
|
39
39
|
{view === 'table' && (
|
|
40
40
|
<>
|
|
41
41
|
<div className="h-px" style={{ background: 'var(--border)' }} />
|
|
42
|
-
<p className="text-
|
|
42
|
+
<p className="text-xs font-semibold uppercase tracking-wider" style={labelStyle}>Sort</p>
|
|
43
43
|
<FieldSelect label="Sort by" value={cfg.table.sortField}
|
|
44
44
|
onChange={v => onChange({ ...cfg, table: { ...cfg.table, sortField: v } })} />
|
|
45
45
|
<div className="flex items-center justify-between gap-2">
|
|
@@ -51,7 +51,7 @@ export function ConfigPanel({ headers, cfg, view, onClose, onChange }: {
|
|
|
51
51
|
style={{
|
|
52
52
|
fontSize: '0.72rem',
|
|
53
53
|
background: cfg.table.sortDir === d ? 'var(--amber)' : 'var(--background)',
|
|
54
|
-
color: cfg.table.sortDir === d ? '
|
|
54
|
+
color: cfg.table.sortDir === d ? 'var(--amber-foreground)' : 'var(--muted-foreground)',
|
|
55
55
|
}}
|
|
56
56
|
>{d}</button>
|
|
57
57
|
))}
|
|
@@ -59,12 +59,12 @@ export function ConfigPanel({ headers, cfg, view, onClose, onChange }: {
|
|
|
59
59
|
</div>
|
|
60
60
|
|
|
61
61
|
<div className="h-px" style={{ background: 'var(--border)' }} />
|
|
62
|
-
<p className="text-
|
|
62
|
+
<p className="text-xs font-semibold uppercase tracking-wider" style={labelStyle}>Group</p>
|
|
63
63
|
<FieldSelect label="Group by" value={cfg.table.groupField}
|
|
64
64
|
onChange={v => onChange({ ...cfg, table: { ...cfg.table, groupField: v } })} />
|
|
65
65
|
|
|
66
66
|
<div className="h-px" style={{ background: 'var(--border)' }} />
|
|
67
|
-
<p className="text-
|
|
67
|
+
<p className="text-xs font-semibold uppercase tracking-wider" style={labelStyle}>Columns</p>
|
|
68
68
|
<div className="flex flex-col gap-1.5">
|
|
69
69
|
{headers.map(h => {
|
|
70
70
|
const hidden = cfg.table.hiddenFields.includes(h);
|
|
@@ -77,7 +77,7 @@ export function ConfigPanel({ headers, cfg, view, onClose, onChange }: {
|
|
|
77
77
|
: [...cfg.table.hiddenFields, h];
|
|
78
78
|
onChange({ ...cfg, table: { ...cfg.table, hiddenFields: next } });
|
|
79
79
|
}}
|
|
80
|
-
className="text-
|
|
80
|
+
className="text-xs px-2 py-0.5 rounded transition-colors font-display"
|
|
81
81
|
style={{
|
|
82
82
|
background: hidden ? 'var(--muted)' : 'var(--amber-dim)',
|
|
83
83
|
color: hidden ? 'var(--muted-foreground)' : 'var(--amber)',
|
|
@@ -18,7 +18,7 @@ export function GalleryView({ headers, rows, cfg }: { headers: string[]; rows: s
|
|
|
18
18
|
<div key={i} className="rounded-xl border p-4 flex flex-col gap-2 hover:bg-muted/50 transition-colors"
|
|
19
19
|
style={{ borderColor: 'var(--border)', background: 'var(--card)' }}
|
|
20
20
|
>
|
|
21
|
-
{tag && tc && <span className="self-start text-
|
|
21
|
+
{tag && tc && <span className="self-start text-xs px-2 py-0.5 rounded-full font-medium"
|
|
22
22
|
style={{ background: tc.bg, color: tc.text }}>{tag}</span>}
|
|
23
23
|
<p className="text-sm font-semibold leading-snug" style={{ color: 'var(--foreground)' }}>{title}</p>
|
|
24
24
|
{desc && <p className="text-xs leading-relaxed line-clamp-3" style={{ color: 'var(--muted-foreground)' }}>{desc}</p>}
|
|
@@ -149,7 +149,7 @@ const WikiNode = memo(function WikiNode({ data }: NodeProps) {
|
|
|
149
149
|
textOverflow: 'ellipsis',
|
|
150
150
|
opacity: isOrphan ? 0.4 : 1,
|
|
151
151
|
background: isCurrent ? 'var(--amber)' : 'var(--card)',
|
|
152
|
-
color: isCurrent ? '
|
|
152
|
+
color: isCurrent ? 'var(--amber-foreground)' : 'var(--foreground)',
|
|
153
153
|
border: `1.5px solid ${isCurrent ? 'var(--amber)' : 'var(--border)'}`,
|
|
154
154
|
boxShadow: isCurrent
|
|
155
155
|
? '0 0 20px var(--amber-dim), 0 0 0 2px var(--amber-dim)'
|
|
@@ -155,7 +155,7 @@ Be specific. Reference actual content from the files. Keep the total response un
|
|
|
155
155
|
cursor: streaming || recentFiles.length === 0 ? 'not-allowed' : 'pointer',
|
|
156
156
|
border: 'none',
|
|
157
157
|
background: streaming ? 'var(--muted)' : 'var(--amber)',
|
|
158
|
-
color: streaming ? 'var(--muted-foreground)' : '
|
|
158
|
+
color: streaming ? 'var(--muted-foreground)' : 'var(--amber-foreground)',
|
|
159
159
|
opacity: recentFiles.length === 0 ? 0.5 : 1,
|
|
160
160
|
transition: 'opacity .15s',
|
|
161
161
|
}}
|
|
@@ -206,7 +206,7 @@ function StepCard({
|
|
|
206
206
|
padding: '3px 10px', borderRadius: 6, fontSize: '0.72rem',
|
|
207
207
|
cursor: canRun ? 'pointer' : 'not-allowed',
|
|
208
208
|
border: 'none', background: canRun ? 'var(--amber)' : 'var(--muted)',
|
|
209
|
-
color: canRun ? '
|
|
209
|
+
color: canRun ? 'var(--amber-foreground)' : 'var(--muted-foreground)',
|
|
210
210
|
opacity: canRun ? 1 : 0.5,
|
|
211
211
|
}}
|
|
212
212
|
>
|
|
@@ -362,7 +362,7 @@ export function WorkflowRenderer({ filePath, content }: RendererContext) {
|
|
|
362
362
|
padding: '4px 12px', borderRadius: 7, fontSize: '0.75rem',
|
|
363
363
|
cursor: running ? 'not-allowed' : 'pointer',
|
|
364
364
|
border: 'none', background: running ? 'var(--muted)' : 'var(--amber)',
|
|
365
|
-
color: running ? 'var(--muted-foreground)' : '
|
|
365
|
+
color: running ? 'var(--muted-foreground)' : 'var(--amber-foreground)',
|
|
366
366
|
opacity: running ? 0.7 : 1,
|
|
367
367
|
}}
|
|
368
368
|
>
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
4
|
+
import { AlertCircle, Loader2 } from 'lucide-react';
|
|
4
5
|
import type { AiSettings, ProviderConfig, SettingsData } from './types';
|
|
5
6
|
import { Field, Select, Input, EnvBadge, ApiKeyInput } from './Primitives';
|
|
6
7
|
|
|
8
|
+
type TestState = 'idle' | 'testing' | 'ok' | 'error';
|
|
9
|
+
type ErrorCode = 'auth_error' | 'model_not_found' | 'rate_limited' | 'network_error' | 'unknown';
|
|
10
|
+
|
|
11
|
+
interface TestResult {
|
|
12
|
+
state: TestState;
|
|
13
|
+
latency?: number;
|
|
14
|
+
error?: string;
|
|
15
|
+
code?: ErrorCode;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function errorMessage(t: any, code?: ErrorCode): string {
|
|
19
|
+
switch (code) {
|
|
20
|
+
case 'auth_error': return t.settings.ai.testKeyAuthError;
|
|
21
|
+
case 'model_not_found': return t.settings.ai.testKeyModelNotFound;
|
|
22
|
+
case 'rate_limited': return t.settings.ai.testKeyRateLimited;
|
|
23
|
+
case 'network_error': return t.settings.ai.testKeyNetworkError;
|
|
24
|
+
default: return t.settings.ai.testKeyUnknown;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
7
28
|
interface AiTabProps {
|
|
8
29
|
data: SettingsData;
|
|
9
30
|
updateAi: (patch: Partial<AiSettings>) => void;
|
|
@@ -15,13 +36,76 @@ export function AiTab({ data, updateAi, t }: AiTabProps) {
|
|
|
15
36
|
const envVal = data.envValues ?? {};
|
|
16
37
|
const provider = data.ai.provider;
|
|
17
38
|
|
|
18
|
-
|
|
39
|
+
// --- Test key state ---
|
|
40
|
+
const [testResult, setTestResult] = useState<Record<string, TestResult>>({});
|
|
41
|
+
const okTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
|
|
42
|
+
const prevProviderRef = useRef(provider);
|
|
43
|
+
|
|
44
|
+
// Reset test result when provider changes
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (prevProviderRef.current !== provider) {
|
|
47
|
+
prevProviderRef.current = provider;
|
|
48
|
+
setTestResult({});
|
|
49
|
+
if (okTimerRef.current) { clearTimeout(okTimerRef.current); okTimerRef.current = undefined; }
|
|
50
|
+
}
|
|
51
|
+
}, [provider]);
|
|
52
|
+
|
|
53
|
+
// Cleanup ok timer
|
|
54
|
+
useEffect(() => () => { if (okTimerRef.current) clearTimeout(okTimerRef.current); }, []);
|
|
55
|
+
|
|
56
|
+
const handleTestKey = useCallback(async (providerName: 'anthropic' | 'openai') => {
|
|
57
|
+
const prov = data.ai.providers?.[providerName] ?? {} as ProviderConfig;
|
|
58
|
+
setTestResult(prev => ({ ...prev, [providerName]: { state: 'testing' } }));
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const body: Record<string, string> = { provider: providerName };
|
|
62
|
+
if (prov.apiKey) body.apiKey = prov.apiKey;
|
|
63
|
+
if (prov.model) body.model = prov.model;
|
|
64
|
+
if (providerName === 'openai' && prov.baseUrl) body.baseUrl = prov.baseUrl;
|
|
65
|
+
|
|
66
|
+
const res = await fetch('/api/settings/test-key', {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: { 'Content-Type': 'application/json' },
|
|
69
|
+
body: JSON.stringify(body),
|
|
70
|
+
});
|
|
71
|
+
const json = await res.json();
|
|
72
|
+
|
|
73
|
+
if (json.ok) {
|
|
74
|
+
setTestResult(prev => ({ ...prev, [providerName]: { state: 'ok', latency: json.latency } }));
|
|
75
|
+
// Auto-clear after 5s
|
|
76
|
+
if (okTimerRef.current) clearTimeout(okTimerRef.current);
|
|
77
|
+
okTimerRef.current = setTimeout(() => {
|
|
78
|
+
setTestResult(prev => ({ ...prev, [providerName]: { state: 'idle' } }));
|
|
79
|
+
}, 5000);
|
|
80
|
+
} else {
|
|
81
|
+
setTestResult(prev => ({
|
|
82
|
+
...prev,
|
|
83
|
+
[providerName]: { state: 'error', error: json.error, code: json.code },
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
} catch {
|
|
87
|
+
setTestResult(prev => ({
|
|
88
|
+
...prev,
|
|
89
|
+
[providerName]: { state: 'error', code: 'network_error', error: 'Network error' },
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
}, [data.ai.providers]);
|
|
93
|
+
|
|
94
|
+
// Reset test result when key changes
|
|
95
|
+
const patchProviderWithReset = useCallback((name: 'anthropic' | 'openai', patch: Partial<ProviderConfig>) => {
|
|
96
|
+
if ('apiKey' in patch) {
|
|
97
|
+
setTestResult(prev => ({ ...prev, [name]: { state: 'idle' } }));
|
|
98
|
+
}
|
|
19
99
|
updateAi({
|
|
20
100
|
providers: {
|
|
21
101
|
...data.ai.providers,
|
|
22
102
|
[name]: { ...data.ai.providers?.[name], ...patch },
|
|
23
103
|
},
|
|
24
104
|
});
|
|
105
|
+
}, [data.ai.providers, updateAi]);
|
|
106
|
+
|
|
107
|
+
function patchProvider(name: 'anthropic' | 'openai', patch: Partial<ProviderConfig>) {
|
|
108
|
+
patchProviderWithReset(name, patch);
|
|
25
109
|
}
|
|
26
110
|
|
|
27
111
|
const anthropic = data.ai.providers?.anthropic ?? { apiKey: '', model: '' };
|
|
@@ -31,6 +115,38 @@ export function AiTab({ data, updateAi, t }: AiTabProps) {
|
|
|
31
115
|
const activeEnvKey = provider === 'anthropic' ? env.ANTHROPIC_API_KEY : env.OPENAI_API_KEY;
|
|
32
116
|
const missingApiKey = !activeApiKey && !activeEnvKey;
|
|
33
117
|
|
|
118
|
+
// Test button helper
|
|
119
|
+
const renderTestButton = (providerName: 'anthropic' | 'openai', hasKey: boolean, hasEnv: boolean) => {
|
|
120
|
+
const result = testResult[providerName] ?? { state: 'idle' as TestState };
|
|
121
|
+
const disabled = result.state === 'testing' || (!hasKey && !hasEnv);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<div className="flex items-center gap-2 mt-1.5">
|
|
125
|
+
<button
|
|
126
|
+
type="button"
|
|
127
|
+
disabled={disabled}
|
|
128
|
+
onClick={() => handleTestKey(providerName)}
|
|
129
|
+
className="inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:border-foreground/20 transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
|
|
130
|
+
>
|
|
131
|
+
{result.state === 'testing' ? (
|
|
132
|
+
<>
|
|
133
|
+
<Loader2 size={12} className="animate-spin" />
|
|
134
|
+
{t.settings.ai.testKeyTesting}
|
|
135
|
+
</>
|
|
136
|
+
) : (
|
|
137
|
+
t.settings.ai.testKey
|
|
138
|
+
)}
|
|
139
|
+
</button>
|
|
140
|
+
{result.state === 'ok' && result.latency != null && (
|
|
141
|
+
<span className="text-xs text-success">{t.settings.ai.testKeyOk(result.latency)}</span>
|
|
142
|
+
)}
|
|
143
|
+
{result.state === 'error' && (
|
|
144
|
+
<span className="text-xs text-error">✗ {errorMessage(t, result.code)}</span>
|
|
145
|
+
)}
|
|
146
|
+
</div>
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
|
|
34
150
|
return (
|
|
35
151
|
<div className="space-y-5">
|
|
36
152
|
<Field label={<>{t.settings.ai.provider} <EnvBadge overridden={env.AI_PROVIDER} /></>}>
|
|
@@ -60,6 +176,7 @@ export function AiTab({ data, updateAi, t }: AiTabProps) {
|
|
|
60
176
|
value={anthropic.apiKey}
|
|
61
177
|
onChange={v => patchProvider('anthropic', { apiKey: v })}
|
|
62
178
|
/>
|
|
179
|
+
{renderTestButton('anthropic', !!anthropic.apiKey, !!env.ANTHROPIC_API_KEY)}
|
|
63
180
|
</Field>
|
|
64
181
|
</>
|
|
65
182
|
) : (
|
|
@@ -79,6 +196,7 @@ export function AiTab({ data, updateAi, t }: AiTabProps) {
|
|
|
79
196
|
value={openai.apiKey}
|
|
80
197
|
onChange={v => patchProvider('openai', { apiKey: v })}
|
|
81
198
|
/>
|
|
199
|
+
{renderTestButton('openai', !!openai.apiKey, !!env.OPENAI_API_KEY)}
|
|
82
200
|
</Field>
|
|
83
201
|
<Field
|
|
84
202
|
label={<>{t.settings.ai.baseUrl} <EnvBadge overridden={env.OPENAI_BASE_URL} /></>}
|
|
@@ -114,7 +114,7 @@ export function KnowledgeTab({ data, setData, t }: KnowledgeTabProps) {
|
|
|
114
114
|
className="shrink-0 p-1 rounded text-muted-foreground hover:text-foreground transition-colors"
|
|
115
115
|
title={k.authTokenCopy}
|
|
116
116
|
>
|
|
117
|
-
{copied ? <Check size={13} className="text-
|
|
117
|
+
{copied ? <Check size={13} className="text-success" /> : <Copy size={13} />}
|
|
118
118
|
</button>
|
|
119
119
|
)}
|
|
120
120
|
</div>
|