Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

feat(ui): show key checks as pills in the field and flag a provider with no key

Luis Ortizf5301c1b5e3f
diff --git a/apps/desktop/src/renderer/settings/SettingsPanel.tsx b/apps/desktop/src/renderer/settings/SettingsPanel.tsx
index 5ff2066..37d093c 100644
--- a/apps/desktop/src/renderer/settings/SettingsPanel.tsx
+++ b/apps/desktop/src/renderer/settings/SettingsPanel.tsx
@@ -148,7 +148,7 @@ export function SettingsPanel() {
/>
</Row>
- <Row label={i18n.t('desktop_keepClicksBeyondArea')}>
+ <Row label={i18n.t('desktop_keepClicksBeyondArea')} hint={i18n.t('desktop_keepClicksBeyondAreaHint')}>
<Switch
checked={settings.keepClicksBeyondArea}
label={i18n.t('desktop_keepClicksBeyondArea')}
@@ -159,14 +159,14 @@ export function SettingsPanel() {
</Card>
<Card icon={Keyboard} title={i18n.t('desktop_cardKeyboard')} hint={i18n.t('desktop_cardKeyboardHint')}>
- <Row label={i18n.t('desktop_recordTyping')}>
+ <Row label={i18n.t('desktop_recordTyping')} hint={i18n.t('desktop_recordTypingHint')}>
<Switch
checked={settings.recordTyping}
label={i18n.t('desktop_recordTyping')}
onChange={(recordTyping) => save({ recordTyping })}
/>
</Row>
- <Row label={i18n.t('desktop_typingDebounce')}>
+ <Row label={i18n.t('desktop_typingDebounce')} hint={i18n.t('desktop_typingDebounceHint')}>
<Slider
label={i18n.t('desktop_typingDebounce')}
min={200}
diff --git a/packages/ui/src/ai/components/AiSettings.tsx b/packages/ui/src/ai/components/AiSettings.tsx
index 6268235..c7072e0 100644
--- a/packages/ui/src/ai/components/AiSettings.tsx
+++ b/packages/ui/src/ai/components/AiSettings.tsx
@@ -2,7 +2,7 @@ import { SERVER } from '@mimik/core/capture/ai/keys';
import { CUSTOM_MODEL_VALUE } from '@mimik/core/capture/ai/models';
import { AI_LANGUAGES, type AILanguageCode } from '@mimik/core/capture/ai/prompts';
import { i18n } from '@mimik/core/env';
-import { Globe, Sparkles } from 'lucide-react';
+import { Sparkles } from 'lucide-react';
import { SettingsCard } from '../../common/components/SettingsCard';
import { Input } from '../../components/ui/input';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../../components/ui/select';
@@ -28,7 +28,11 @@ export function AiSettings({ keys, onOpenKeys, onChange }: AiSettingsProps) {
: !keys.keys[provider] && i18n.t('settings.aiNoKey');
return (
- <SettingsCard icon={Sparkles} title={i18n.t('settings.aiDescriptions')}>
+ <SettingsCard
+ icon={Sparkles}
+ title={i18n.t('settings.aiDescriptions')}
+ hint={i18n.t('settings.aiDescriptionsHint')}
+ >
<div>
<label className="block text-[11px] font-semibold text-foreground mb-1">{i18n.t('settings.provider')}</label>
<ProviderSelect
@@ -70,10 +74,7 @@ export function AiSettings({ keys, onOpenKeys, onChange }: AiSettingsProps) {
</div>
<div>
- <label className="block text-[11px] font-semibold text-foreground mb-1">
- <Globe size={11} className="inline mr-1 -mt-px" />
- {i18n.t('settings.aiLanguage')}
- </label>
+ <label className="block text-[11px] font-semibold text-foreground mb-1">{i18n.t('settings.aiLanguage')}</label>
<Select value={language} onValueChange={(v) => setLanguage(v as AILanguageCode)}>
<SelectTrigger className="h-8">
<SelectValue />
diff --git a/packages/ui/src/ai/components/KeyStatusIcon.tsx b/packages/ui/src/ai/components/KeyStatusIcon.tsx
deleted file mode 100644
index 3c44027..0000000
--- a/packages/ui/src/ai/components/KeyStatusIcon.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-import { i18n } from '@mimik/core/env';
-import { Check, CircleAlert, Loader2 } from 'lucide-react';
-import type { KeyStatus } from '../types';
-
-export function KeyStatusIcon({ status }: { status: KeyStatus }) {
- if (status === 'checking') {
- return (
- <Loader2 size={14} className="animate-spin text-muted-foreground" aria-label={i18n.t('settings.validatingKey')} />
- );
- }
- if (status === 'valid') {
- return (
- <Check
- size={14}
- strokeWidth={3}
- style={{ color: 'var(--color-success)' }}
- aria-label={i18n.t('settings.keyValid')}
- />
- );
- }
- if (status === null) return null;
- return <CircleAlert size={14} className={status === 'unreachable' ? 'text-muted-foreground' : 'text-destructive'} />;
-}
diff --git a/packages/ui/src/ai/components/KeyStatusNote.tsx b/packages/ui/src/ai/components/KeyStatusNote.tsx
index 569dd76..a023598 100644
--- a/packages/ui/src/ai/components/KeyStatusNote.tsx
+++ b/packages/ui/src/ai/components/KeyStatusNote.tsx
@@ -1,19 +1,7 @@
import { i18n } from '@mimik/core/env';
-import { Check } from 'lucide-react';
import type { KeyStatus } from '../types';
export function KeyStatusNote({ status }: { status: KeyStatus }) {
- if (status === 'checking') {
- return <p className="mt-1 text-[11px] text-muted-foreground">{i18n.t('settings.validatingKey')}</p>;
- }
- if (status === 'valid') {
- return (
- <p className="mt-1 text-[11px] flex items-center gap-1" style={{ color: 'var(--color-success)' }}>
- <Check size={11} />
- {i18n.t('settings.keyValid')}
- </p>
- );
- }
if (status === 'rejected') {
return (
<p className="mt-1 text-[11px] text-destructive" role="alert">
diff --git a/packages/ui/src/ai/components/KeyStatusPill.tsx b/packages/ui/src/ai/components/KeyStatusPill.tsx
new file mode 100644
index 0000000..6b83f77
--- /dev/null
+++ b/packages/ui/src/ai/components/KeyStatusPill.tsx
@@ -0,0 +1,30 @@
+import { i18n } from '@mimik/core/env';
+import { Loader2 } from 'lucide-react';
+import type { KeyStatus } from '../types';
+
+const GOOD = 'bg-[#ECFDF5] text-[#047857]';
+const BAD = 'bg-[#FEF3F2] text-[#B42318]';
+const QUIET = 'bg-secondary text-muted-foreground';
+
+const PILLS: Record<NonNullable<KeyStatus>, { label: string; tone: string }> = {
+ checking: { label: 'settings.keyChecking', tone: QUIET },
+ valid: { label: 'settings.keyVerified', tone: GOOD },
+ rejected: { label: 'settings.keyRejected', tone: BAD },
+ unreachable: { label: 'settings.keyOffline', tone: QUIET },
+ 'model-required': { label: 'settings.keyCheckModel', tone: BAD },
+ 'model-invalid': { label: 'settings.keyCheckModel', tone: BAD },
+};
+
+export function KeyStatusPill({ status }: { status: KeyStatus }) {
+ if (!status) return null;
+ const pill = PILLS[status];
+ return (
+ <span
+ role="status"
+ className={`inline-flex h-[22px] shrink-0 items-center gap-1.5 rounded-full px-2.5 text-[11px] font-semibold ${pill.tone}`}
+ >
+ {status === 'checking' && <Loader2 size={11} className="animate-spin" />}
+ {i18n.t(pill.label)}
+ </span>
+ );
+}
diff --git a/packages/ui/src/ai/components/ProviderKeyRow.tsx b/packages/ui/src/ai/components/ProviderKeyRow.tsx
index 42e19e4..28e082a 100644
--- a/packages/ui/src/ai/components/ProviderKeyRow.tsx
+++ b/packages/ui/src/ai/components/ProviderKeyRow.tsx
@@ -3,8 +3,8 @@ import { i18n } from '@mimik/core/env';
import { useEffect } from 'react';
import { useKeyCheck } from '../hooks/use-key-check';
import type { ValidateKey } from '../types';
-import { KeyStatusIcon } from './KeyStatusIcon';
import { KeyStatusNote } from './KeyStatusNote';
+import { KeyStatusPill } from './KeyStatusPill';
import { KeyWarningNote } from './KeyWarningNote';
import { ProviderLogo } from './ProviderLogo';
import { SecretInput } from './SecretInput';
@@ -33,9 +33,8 @@ export function ProviderKeyRow({ provider, value, onChange, validate, bare = fal
<span className="w-7 h-7 rounded-lg bg-secondary text-foreground flex items-center justify-center shrink-0">
<ProviderLogo provider={provider} />
</span>
- <span className="w-28 shrink-0 flex items-center gap-1.5 text-[13px] font-semibold text-foreground">
+ <span className="w-28 shrink-0 text-[13px] font-semibold text-foreground">
{KEY_PROVIDER_LABELS[provider]}
- <KeyStatusIcon status={keyCheck.status} />
</span>
</>
)}
@@ -49,15 +48,14 @@ export function ProviderKeyRow({ provider, value, onChange, validate, bare = fal
if (value.trim()) void check(provider, value.trim());
}}
placeholder={KEY_PLACEHOLDERS[provider]}
+ status={<KeyStatusPill status={keyCheck.status} />}
aria-label={bare ? i18n.t('settings.apiKey') : undefined}
className={bare ? 'h-11 rounded-xl pl-4 text-sm border-border' : 'h-8 text-[13px] rounded-lg border-border'}
/>
</div>
- {(bare || (keyCheck.status !== 'valid' && keyCheck.status !== 'checking')) && (
- <div className={bare ? '' : 'pl-10'}>
- <KeyStatusNote status={keyCheck.status} />
- </div>
- )}
+ <div className={bare ? '' : 'pl-10'}>
+ <KeyStatusNote status={keyCheck.status} />
+ </div>
<div className={bare ? '' : 'pl-10'}>
<KeyWarningNote warning={keyCheck.warning} />
</div>
diff --git a/packages/ui/src/ai/components/ProviderSelect.tsx b/packages/ui/src/ai/components/ProviderSelect.tsx
index 045fb50..117cb5d 100644
--- a/packages/ui/src/ai/components/ProviderSelect.tsx
+++ b/packages/ui/src/ai/components/ProviderSelect.tsx
@@ -29,11 +29,19 @@ export function ProviderSelect<T extends string>({
triggerClassName,
}: ProviderSelectProps<T>) {
const [open, setOpen] = useState(false);
+ const missingKey = options.find((option) => option.value === value)?.available === false;
return (
<Select open={open} onOpenChange={setOpen} value={value} onValueChange={(next) => onChange(next as T)}>
<SelectTrigger className={triggerClassName ?? 'h-8'}>
- <SelectValue />
+ <span className="flex min-w-0 flex-1 items-center gap-2">
+ <SelectValue />
+ {missingKey && (
+ <span className="ml-auto inline-flex h-[22px] shrink-0 items-center rounded-full bg-[#FEF3F2] px-2.5 text-[11px] font-semibold text-[#B42318]">
+ {i18n.t('settings.noKey')}
+ </span>
+ )}
+ </span>
</SelectTrigger>
<SelectContent>
{options.map((option) => (
@@ -64,11 +72,13 @@ export function ProviderSelect<T extends string>({
) : (
<span className="ml-auto text-[11px]">{i18n.t('settings.noKey')}</span>
))}
- <span className="absolute right-2 flex items-center">
- <SelectPrimitive.ItemIndicator>
- <Check size={13} className="text-accent" />
- </SelectPrimitive.ItemIndicator>
- </span>
+ {option.available && (
+ <span className="absolute right-2 flex items-center">
+ <SelectPrimitive.ItemIndicator>
+ <Check size={13} className="text-accent" />
+ </SelectPrimitive.ItemIndicator>
+ </span>
+ )}
</SelectPrimitive.Item>
))}
</SelectContent>
diff --git a/packages/ui/src/ai/components/SecretInput.tsx b/packages/ui/src/ai/components/SecretInput.tsx
index 3e331ca..c1d08e0 100644
--- a/packages/ui/src/ai/components/SecretInput.tsx
+++ b/packages/ui/src/ai/components/SecretInput.tsx
@@ -1,6 +1,6 @@
import { i18n } from '@mimik/core/env';
import { Eye, EyeOff, X } from 'lucide-react';
-import { useState } from 'react';
+import { type ReactNode, useState } from 'react';
import { Input } from '../../components/ui/input';
export function SecretInput({
@@ -10,6 +10,7 @@ export function SecretInput({
placeholder,
className,
buttonClassName,
+ status,
}: {
value: string;
onChange: (next: string) => void;
@@ -17,6 +18,7 @@ export function SecretInput({
placeholder?: string;
className?: string;
buttonClassName?: string;
+ status?: ReactNode;
}) {
const [revealed, setRevealed] = useState(false);
const Icon = revealed ? EyeOff : Eye;
@@ -29,8 +31,15 @@ export function SecretInput({
onChange={(e) => onChange(e.target.value)}
onBlur={onBlur}
placeholder={placeholder}
- className={`${value ? 'pr-14' : 'pr-8'} ${className ?? ''}`}
+ className={`${status ? 'pr-40' : value ? 'pr-14' : 'pr-8'} ${className ?? ''}`}
/>
+ {status && (
+ <span
+ className={`pointer-events-none absolute top-1/2 flex -translate-y-1/2 ${value ? 'right-14' : 'right-8'}`}
+ >
+ {status}
+ </span>
+ )}
{value && (
<button
type="button"
diff --git a/packages/ui/src/ai/components/ServerSettings.tsx b/packages/ui/src/ai/components/ServerSettings.tsx
index bcff265..6d9bb10 100644
--- a/packages/ui/src/ai/components/ServerSettings.tsx
+++ b/packages/ui/src/ai/components/ServerSettings.tsx
@@ -7,8 +7,9 @@ import { SettingsCard } from '../../common/components/SettingsCard';
import { Input } from '../../components/ui/input';
import { useKeyCheck } from '../hooks/use-key-check';
import type { ValidateKey } from '../types';
-import { KeyStatusIcon } from './KeyStatusIcon';
import { KeyStatusNote } from './KeyStatusNote';
+import { KeyStatusPill } from './KeyStatusPill';
+import { ProviderLogo } from './ProviderLogo';
import { SecretInput } from './SecretInput';
interface ServerSettingsProps {
@@ -45,23 +46,25 @@ export function ServerSettings({ server, onChange, validate }: ServerSettingsPro
<div className="-mt-1 divide-y divide-secondary">
<div className="py-2.5">
<label className="flex items-center gap-3">
- <span className="w-[152px] shrink-0 flex items-center gap-1.5 text-[13px] font-semibold text-foreground">
+ <span className="w-[152px] shrink-0 text-[13px] font-semibold text-foreground">
{i18n.t('settings.baseUrl')}
- <KeyStatusIcon status={keyCheck.status} />
</span>
- <Input
- value={server.url}
- onChange={(e) => change({ url: e.target.value })}
- onBlur={() => probe(server)}
- placeholder="http://localhost:11434/v1"
- className="h-8 flex-1 text-[13px] rounded-lg border-border font-mono"
- />
+ <span className="relative flex min-w-0 flex-1">
+ <Input
+ value={server.url}
+ onChange={(e) => change({ url: e.target.value })}
+ onBlur={() => probe(server)}
+ placeholder="http://localhost:11434/v1"
+ className={`h-8 flex-1 text-[13px] rounded-lg border-border ${keyCheck.status ? 'pr-32' : ''}`}
+ />
+ <span className="pointer-events-none absolute right-2 top-1/2 flex -translate-y-1/2">
+ <KeyStatusPill status={keyCheck.status} />
+ </span>
+ </span>
</label>
- {keyCheck.status !== 'valid' && keyCheck.status !== 'checking' && (
- <div className="pl-[164px]">
- <KeyStatusNote status={keyCheck.status} />
- </div>
- )}
+ <div className="pl-[164px]">
+ <KeyStatusNote status={keyCheck.status} />
+ </div>
</div>
<div className="flex items-center gap-3 py-2.5">
<span className="w-[152px] shrink-0 text-[13px] font-semibold text-foreground">
@@ -83,8 +86,16 @@ export function ServerSettings({ server, onChange, validate }: ServerSettingsPro
label={i18n.t('settings.serverSpeaks')}
value={server.protocol}
options={[
- { value: 'openai' as const, label: i18n.t('settings.protocolOpenai') },
- { value: 'anthropic' as const, label: i18n.t('settings.protocolAnthropic') },
+ {
+ value: 'openai' as const,
+ label: i18n.t('settings.protocolOpenai'),
+ logo: <ProviderLogo provider="openai" />,
+ },
+ {
+ value: 'anthropic' as const,
+ label: i18n.t('settings.protocolAnthropic'),
+ logo: <ProviderLogo provider="anthropic" />,
+ },
]}
onChange={(protocol) => {
change({ protocol });
diff --git a/packages/ui/src/ai/hooks/use-key-check.ts b/packages/ui/src/ai/hooks/use-key-check.ts
index 03caa44..bb8f7e4 100644
--- a/packages/ui/src/ai/hooks/use-key-check.ts
+++ b/packages/ui/src/ai/hooks/use-key-check.ts
@@ -1,17 +1,22 @@
import { useCallback, useRef, useState } from 'react';
-import type { KeyStatus, KeyWarning, ValidateKey } from '../types';
+import type { KeyCheckResult, KeyStatus, KeyWarning, ValidateKey } from '../types';
+
+const verified = new Map<string, KeyCheckResult>();
export function useKeyCheck(validate: ValidateKey) {
const [status, setStatus] = useState<KeyStatus>(null);
const [models, setModels] = useState<string[] | null>(null);
const [warning, setWarning] = useState<KeyWarning | null>(null);
- const validated = useRef('');
const requestId = useRef(0);
const check = useCallback(
async (provider: string, apiKey: string, baseUrl?: string, model?: string) => {
const fingerprint = `${provider}:${apiKey}:${baseUrl ?? ''}:${model ?? ''}`;
- if (validated.current === fingerprint) {
+ const known = verified.get(fingerprint);
+ if (known) {
+ requestId.current += 1;
+ setModels(known.models?.length ? known.models : null);
+ setWarning(known.warning ?? null);
setStatus('valid');
return;
}
@@ -21,7 +26,7 @@ export function useKeyCheck(validate: ValidateKey) {
setWarning(null);
const result = await validate(provider, apiKey, baseUrl, model).catch(() => null);
if (requestId.current !== currentRequestId) return;
- if (result?.valid) validated.current = fingerprint;
+ if (result?.valid) verified.set(fingerprint, result);
setModels(result?.models?.length ? result.models : null);
setWarning(result?.valid && result.warning ? result.warning : null);
setStatus(
@@ -41,7 +46,6 @@ export function useKeyCheck(validate: ValidateKey) {
const reset = useCallback(() => {
requestId.current += 1;
- validated.current = '';
setStatus(null);
setModels(null);
setWarning(null);
diff --git a/packages/ui/src/branding/components/BrandingSettings.tsx b/packages/ui/src/branding/components/BrandingSettings.tsx
index bd92956..41f4e88 100644
--- a/packages/ui/src/branding/components/BrandingSettings.tsx
+++ b/packages/ui/src/branding/components/BrandingSettings.tsx
@@ -52,7 +52,11 @@ export function BrandingSettings({ onChange }: { onChange?: (patch: Record<strin
}
/>
- <SettingsCard icon={ImageIcon} title={i18n.t('settings.branding')}>
+ <SettingsCard
+ icon={ImageIcon}
+ title={i18n.t('settings.logoAndFooter')}
+ hint={i18n.t('settings.logoAndFooterHint')}
+ >
<div>
<label className="block text-[11px] font-semibold text-foreground mb-1">{i18n.t('settings.brandLogo')}</label>
<input
diff --git a/packages/ui/src/common/components/Segmented.tsx b/packages/ui/src/common/components/Segmented.tsx
index aa917c9..f8206b0 100644
--- a/packages/ui/src/common/components/Segmented.tsx
+++ b/packages/ui/src/common/components/Segmented.tsx
@@ -1,35 +1,52 @@
import type { Command } from 'lucide-react';
+import type { ReactNode } from 'react';
+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../components/ui/tooltip';
interface SegmentedProps<T> {
label: string;
value: T;
- options: { value: T; label: string; Icon?: typeof Command }[];
+ options: { value: T; label: string; Icon?: typeof Command; logo?: ReactNode }[];
onChange: (next: T) => void;
}
export function Segmented<T>({ label, value, options, onChange }: SegmentedProps<T>) {
return (
- <fieldset
- aria-label={label}
- className="flex shrink-0 gap-[3px] self-start rounded-[10px] border border-border bg-card p-[3px]"
- >
- {options.map((option) => {
- const active = option.value === value;
- return (
- <button
- key={option.label}
- type="button"
- aria-pressed={active}
- onClick={() => onChange(option.value)}
- className={`flex h-8 items-center gap-1.5 rounded-lg px-3 text-[12.5px] font-semibold transition-colors ${
- active ? 'bg-primary text-primary-foreground' : 'text-foreground hover:bg-secondary'
- }`}
- >
- {option.Icon && <option.Icon size={14} />}
- {option.label}
- </button>
- );
- })}
- </fieldset>
+ <TooltipProvider>
+ <fieldset
+ aria-label={label}
+ className="flex shrink-0 gap-[3px] self-start rounded-[10px] border border-border bg-card p-[3px]"
+ >
+ {options.map((option) => {
+ const active = option.value === value;
+ const button = (
+ <button
+ key={option.label}
+ type="button"
+ aria-pressed={active}
+ aria-label={option.logo ? option.label : undefined}
+ onClick={() => onChange(option.value)}
+ className={`flex h-8 items-center gap-1.5 rounded-lg text-[12.5px] font-semibold transition-colors ${
+ option.logo ? 'w-9 justify-center' : 'px-3'
+ } ${active ? 'bg-primary text-primary-foreground' : 'text-foreground hover:bg-secondary'}`}
+ >
+ {option.logo ?? (
+ <>
+ {option.Icon && <option.Icon size={14} />}
+ {option.label}
+ </>
+ )}
+ </button>
+ );
+ return option.logo ? (
+ <Tooltip key={option.label}>
+ <TooltipTrigger asChild>{button}</TooltipTrigger>
+ <TooltipContent>{option.label}</TooltipContent>
+ </Tooltip>
+ ) : (
+ button
+ );
+ })}
+ </fieldset>
+ </TooltipProvider>
);
}