Skip to content

Self-improving AI Employees for everyone

feat(ui): Phase 5 (start) - drop antd Form from credential panel state

trohitgccf9bd5bd486
diff --git a/client/package.json b/client/package.json
index 04dacd19..9be2a3b8 100644
--- a/client/package.json
+++ b/client/package.json
@@ -13,6 +13,7 @@
"@ant-design/icons": "^6.0.2",
"@eslint/js": "^9.33.0",
"@fontsource-variable/geist": "^5.2.8",
+ "@hookform/resolvers": "^5.2.2",
"@lobehub/icons": "^2.45.0",
"@radix-ui/react-collapsible": "^1.1.12",
"@radix-ui/react-dialog": "^1.1.15",
@@ -46,7 +47,7 @@
"radix-ui": "^1.4.3",
"react": "^19.1.1",
"react-dom": "^19.1.1",
- "react-hook-form": "^7",
+ "react-hook-form": "^7.72.1",
"react-js-cron": "^5.2.0",
"react-markdown": "^10.1.0",
"react-simple-code-editor": "^0.14.1",
@@ -62,6 +63,7 @@
"tw-animate-css": "^1.4.0",
"typescript": "^5.9.2",
"vite": "^7.1.2",
+ "zod": "^4.3.6",
"zustand": "^5.0.8"
},
"overrides": {
diff --git a/client/src/components/credentials/panels/QrPairingPanel.tsx b/client/src/components/credentials/panels/QrPairingPanel.tsx
index 2097bd2a..89150e10 100644
--- a/client/src/components/credentials/panels/QrPairingPanel.tsx
+++ b/client/src/components/credentials/panels/QrPairingPanel.tsx
@@ -58,7 +58,7 @@ const QrPairingPanel: React.FC<{ config: ProviderConfig; visible: boolean }> = (
{field && <ApiKeyInput
value={panel.form.getFieldValue(field.key) || ''}
onChange={(v: string) => panel.form.setFieldValue(field.key, v)}
- onSave={() => panel.actions.save(field.key, panel.form.getFieldValue(field.key)?.trim()).then(() => panel.setStored(true))}
+ onSave={() => panel.actions.save(field.key, (panel.form.getFieldValue(field.key) ?? '').trim()).then(() => panel.setStored(true))}
onDelete={() => panel.actions.remove(field.key)}
placeholder={field.placeholder} loading={panel.loading === 'save'} isStored={panel.stored}
/>}
diff --git a/client/src/components/credentials/primitives/FieldRenderer.tsx b/client/src/components/credentials/primitives/FieldRenderer.tsx
index e11220fa..0385c86f 100644
--- a/client/src/components/credentials/primitives/FieldRenderer.tsx
+++ b/client/src/components/credentials/primitives/FieldRenderer.tsx
@@ -1,51 +1,73 @@
/**
* FieldRenderer — generic schema-driven field renderer (n8n CredentialInputs pattern).
- * Takes a FieldDef[] array + antd Form instance, renders the right control per field.
- * Replaces all manual Input/Input.Password/label blocks across panels.
+ * Takes a FieldDef[] array + the form shim from useCredentialPanel.
*/
-import React from 'react';
-import { Form, Input } from 'antd';
-import { useAppTheme } from '../../../hooks/useAppTheme';
+import React, { useState } from 'react';
+import { Eye, EyeOff } from 'lucide-react';
+
+import { Input } from '@/components/ui/input';
+import { Label } from '@/components/ui/label';
import type { FieldDef } from '../types';
-import type { FormInstance } from 'antd';
+
+interface CredentialFormShim {
+ getFieldValue: (key: string) => string | undefined;
+ setFieldValue: (key: string, value: string) => void;
+}
interface Props {
fields: FieldDef[];
- form: FormInstance;
+ form: CredentialFormShim;
}
const FieldRenderer: React.FC<Props> = ({ fields, form }) => {
- const theme = useAppTheme();
- const inputStyle: React.CSSProperties = {
- fontFamily: theme.fontFamily?.mono || 'monospace',
- fontSize: theme.fontSize.sm,
- };
-
return (
- <div className="flex w-full flex-col gap-2">
- {fields.map(f => (
- <Form.Item key={f.key} label={f.label} required={f.required}
- style={{ marginBottom: theme.spacing.xs }}>
- {f.secret ? (
- <Input.Password
- value={form.getFieldValue(f.key) || ''}
- onChange={e => form.setFieldValue(f.key, e.target.value)}
- placeholder={f.placeholder}
- style={inputStyle}
- />
- ) : (
- <Input
- value={form.getFieldValue(f.key) || ''}
- onChange={e => form.setFieldValue(f.key, e.target.value)}
- placeholder={f.placeholder}
- style={inputStyle}
- />
- )}
- </Form.Item>
+ <div className="flex w-full flex-col gap-3">
+ {fields.map((f) => (
+ <FieldRow key={f.key} field={f} form={form} />
))}
</div>
);
};
+interface FieldRowProps {
+ field: FieldDef;
+ form: CredentialFormShim;
+}
+
+const FieldRow: React.FC<FieldRowProps> = ({ field, form }) => {
+ const [revealed, setRevealed] = useState(false);
+ const value = form.getFieldValue(field.key) ?? '';
+ const isSecret = !!field.secret;
+
+ return (
+ <div className="grid gap-1.5">
+ <Label htmlFor={`field-${field.key}`} className="text-xs">
+ {field.label}
+ {field.required && <span className="ml-1 text-destructive">*</span>}
+ </Label>
+ <div className="relative">
+ <Input
+ id={`field-${field.key}`}
+ type={isSecret && !revealed ? 'password' : 'text'}
+ value={value}
+ onChange={(e) => form.setFieldValue(field.key, e.target.value)}
+ placeholder={field.placeholder}
+ className={isSecret ? 'font-mono pr-9' : 'font-mono'}
+ />
+ {isSecret && (
+ <button
+ type="button"
+ onClick={() => setRevealed((r) => !r)}
+ className="absolute top-1/2 right-2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
+ aria-label={revealed ? 'Hide value' : 'Show value'}
+ >
+ {revealed ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
+ </button>
+ )}
+ </div>
+ </div>
+ );
+};
+
export default FieldRenderer;
diff --git a/client/src/components/credentials/primitives/OAuthConnect.tsx b/client/src/components/credentials/primitives/OAuthConnect.tsx
index 4ae12a09..2941f4ca 100644
--- a/client/src/components/credentials/primitives/OAuthConnect.tsx
+++ b/client/src/components/credentials/primitives/OAuthConnect.tsx
@@ -13,11 +13,15 @@ import FieldRenderer from './FieldRenderer';
import ActionBar, { type ActionDef } from './ActionBar';
import StatusCard from './StatusCard';
import type { ProviderConfig, StatusRowDef } from '../types';
-import type { FormInstance } from 'antd';
+
+interface CredentialFormShim {
+ getFieldValue: (key: string) => string | undefined;
+ setFieldValue: (key: string, value: string) => void;
+}
interface Props {
config: ProviderConfig;
- form: FormInstance;
+ form: CredentialFormShim;
connected: boolean;
stored: boolean;
loading: string | null;
diff --git a/client/src/components/credentials/useCredentialPanel.ts b/client/src/components/credentials/useCredentialPanel.ts
index 4d87e4c3..ead7c8cd 100644
--- a/client/src/components/credentials/useCredentialPanel.ts
+++ b/client/src/components/credentials/useCredentialPanel.ts
@@ -1,19 +1,25 @@
/**
- * useCredentialPanel — single hook replacing 20 useState calls + 19 handlers.
+ * useCredentialPanel — single hook for credential panel state.
*
- * Uses antd Form.useForm() for field state management.
- * Provides a generic `execute(key, fn)` that handles try/catch/loading/error
- * identically to every handleTwitterSave, handleGmailLogin, etc.
+ * Plain React state (no antd Form, no react-hook-form). The credential
+ * panels save fields individually via `actions.save(key, value)` rather
+ * than submitting a single form, so a form library is overkill — the
+ * field values are just a key-value bag with stored/loading/error state
+ * around them.
+ *
+ * Provides a generic `execute(key, fn)` that handles try/catch/loading/
+ * error identically to every handleTwitterSave, handleGmailLogin, etc.
*/
-import { useState, useEffect, useCallback } from 'react';
-import { Form } from 'antd';
+import { useCallback, useEffect, useRef, useState } from 'react';
import { useApiKeys } from '../../hooks/useApiKeys';
import { useWebSocket } from '../../contexts/WebSocketContext';
import type { ProviderConfig } from './types';
+export type CredentialFormValues = Record<string, string>;
+
export function useCredentialPanel(config: ProviderConfig, visible: boolean) {
- const [form] = Form.useForm();
+ const [values, setValues] = useState<CredentialFormValues>({});
const [loading, setLoading] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
const [stored, setStored] = useState(false);
@@ -24,22 +30,43 @@ export function useCredentialPanel(config: ProviderConfig, visible: boolean) {
isConnected } = useApiKeys();
const { sendRequest } = useWebSocket();
+ // Imperative form-like API for compat with existing callers. Stable across
+ // renders so memoized children don't re-render.
+ const valuesRef = useRef(values);
+ valuesRef.current = values;
+
+ const form = useRef({
+ getFieldValue: (key: string): string | undefined => valuesRef.current[key],
+ getFieldsValue: (): CredentialFormValues => ({ ...valuesRef.current }),
+ setFieldValue: (key: string, value: string) => {
+ setValues((prev) => ({ ...prev, [key]: value }));
+ },
+ setFieldsValue: (next: CredentialFormValues) => {
+ setValues((prev) => ({ ...prev, ...next }));
+ },
+ resetFields: () => setValues({}),
+ }).current;
+
// Load stored values into form when panel becomes visible
useEffect(() => {
if (!visible || !isConnected || !config.fields) return;
let cancelled = false;
(async () => {
- const values: Record<string, string> = {};
+ const next: CredentialFormValues = {};
let anyStored = false;
for (const field of config.fields!) {
- const has = await hasStoredKey(field.key === 'apiKey' ? config.id : field.key);
+ const storeKey = field.key === 'apiKey' ? config.id : field.key;
+ const has = await hasStoredKey(storeKey);
if (has) {
- const val = await getStoredApiKey(field.key === 'apiKey' ? config.id : field.key);
- if (val && !cancelled) { values[field.key] = val; anyStored = true; }
+ const val = await getStoredApiKey(storeKey);
+ if (val && !cancelled) {
+ next[field.key] = val;
+ anyStored = true;
+ }
}
}
if (!cancelled) {
- form.setFieldsValue(values);
+ setValues(next);
setStored(anyStored);
setError(null);
}
@@ -47,7 +74,7 @@ export function useCredentialPanel(config: ProviderConfig, visible: boolean) {
return () => { cancelled = true; };
}, [config.id, visible, isConnected]);
- // Generic action executor — replaces all 19 duplicate handler functions
+ // Generic action executor — replaces 19 duplicate handler functions.
const execute = useCallback(async (key: string, fn: () => Promise<any>) => {
setLoading(key);
setError(null);
@@ -65,7 +92,7 @@ export function useCredentialPanel(config: ProviderConfig, visible: boolean) {
}
}, []);
- // Pre-built actions that panels call directly
+ // Pre-built actions that panels call directly.
const actions = {
validate: (id: string, key: string) => execute('validate', async () => {
if (config.validateAs === 'google_maps') return validateGoogleMapsKey(key);
@@ -73,7 +100,11 @@ export function useCredentialPanel(config: ProviderConfig, visible: boolean) {
return validateApiKey(id, key);
}),
save: (key: string, value: string) => execute('save', () => saveApiKey(key, value)),
- remove: (key: string) => execute('remove', async () => { await removeApiKey(key); setStored(false); form.resetFields(); }),
+ remove: (key: string) => execute('remove', async () => {
+ await removeApiKey(key);
+ setStored(false);
+ setValues({});
+ }),
oauthLogin: () => execute('login', async () => {
const res = await sendRequest(config.ws!.login, {});
if (res.success && res.url) window.open(res.url, '_blank');
@@ -85,9 +116,8 @@ export function useCredentialPanel(config: ProviderConfig, visible: boolean) {
};
return {
- form, loading, error, stored, setStored, setError,
+ form, values, loading, error, stored, setStored, setError,
execute, actions, isConnected,
- // Pass through API methods panels need
getProviderDefaults, saveProviderDefaults,
getProviderUsageSummary, getAPIUsageSummary,
getStoredModels, getModelConstraints,
diff --git a/client/src/components/ui/form.tsx b/client/src/components/ui/form.tsx
new file mode 100644
index 00000000..f371fea1
--- /dev/null
+++ b/client/src/components/ui/form.tsx
@@ -0,0 +1,167 @@
+"use client"
+
+import * as React from "react"
+import type { Label as LabelPrimitive } from "radix-ui"
+import { Slot } from "radix-ui"
+import {
+ Controller,
+ FormProvider,
+ useFormContext,
+ useFormState,
+ type ControllerProps,
+ type FieldPath,
+ type FieldValues,
+} from "react-hook-form"
+
+import { cn } from "@/lib/utils"
+import { Label } from "@/components/ui/label"
+
+const Form = FormProvider
+
+type FormFieldContextValue<
+ TFieldValues extends FieldValues = FieldValues,
+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
+> = {
+ name: TName
+}
+
+const FormFieldContext = React.createContext<FormFieldContextValue>(
+ {} as FormFieldContextValue
+)
+
+const FormField = <
+ TFieldValues extends FieldValues = FieldValues,
+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
+>({
+ ...props
+}: ControllerProps<TFieldValues, TName>) => {
+ return (
+ <FormFieldContext.Provider value={{ name: props.name }}>
+ <Controller {...props} />
+ </FormFieldContext.Provider>
+ )
+}
+
+const useFormField = () => {
+ const fieldContext = React.useContext(FormFieldContext)
+ const itemContext = React.useContext(FormItemContext)
+ const { getFieldState } = useFormContext()
+ const formState = useFormState({ name: fieldContext.name })
+ const fieldState = getFieldState(fieldContext.name, formState)
+
+ if (!fieldContext) {
+ throw new Error("useFormField should be used within <FormField>")
+ }
+
+ const { id } = itemContext
+
+ return {
+ id,
+ name: fieldContext.name,
+ formItemId: `${id}-form-item`,
+ formDescriptionId: `${id}-form-item-description`,
+ formMessageId: `${id}-form-item-message`,
+ ...fieldState,
+ }
+}
+
+type FormItemContextValue = {
+ id: string
+}
+
+const FormItemContext = React.createContext<FormItemContextValue>(
+ {} as FormItemContextValue
+)
+
+function FormItem({ className, ...props }: React.ComponentProps<"div">) {
+ const id = React.useId()
+
+ return (
+ <FormItemContext.Provider value={{ id }}>
+ <div
+ data-slot="form-item"
+ className={cn("grid gap-2", className)}
+ {...props}
+ />
+ </FormItemContext.Provider>
+ )
+}
+
+function FormLabel({
+ className,
+ ...props
+}: React.ComponentProps<typeof LabelPrimitive.Root>) {
+ const { error, formItemId } = useFormField()
+
+ return (
+ <Label
+ data-slot="form-label"
+ data-error={!!error}
+ className={cn("data-[error=true]:text-destructive", className)}
+ htmlFor={formItemId}
+ {...props}
+ />
+ )
+}
+
+function FormControl({ ...props }: React.ComponentProps<typeof Slot.Root>) {
+ const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
+
+ return (
+ <Slot.Root
+ data-slot="form-control"
+ id={formItemId}
+ aria-describedby={
+ !error
+ ? `${formDescriptionId}`
+ : `${formDescriptionId} ${formMessageId}`
+ }
+ aria-invalid={!!error}
+ {...props}
+ />
+ )
+}
+
+function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
+ const { formDescriptionId } = useFormField()
+
+ return (
+ <p
+ data-slot="form-description"
+ id={formDescriptionId}
+ className={cn("text-sm text-muted-foreground", className)}
+ {...props}
+ />
+ )
+}
+
+function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
+ const { error, formMessageId } = useFormField()
+ const body = error ? String(error?.message ?? "") : props.children
+
+ if (!body) {
+ return null
+ }
+
+ return (
+ <p
+ data-slot="form-message"
+ id={formMessageId}
+ className={cn("text-sm text-destructive", className)}
+ {...props}
+ >
+ {body}
+ </p>
+ )
+}
+
+export {
+ useFormField,
+ Form,
+ FormItem,
+ FormLabel,
+ FormControl,
+ FormDescription,
+ FormMessage,
+ FormField,
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f276f120..61b43f90 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -38,6 +38,9 @@ importers:
'@fontsource-variable/geist':
specifier: ^5.2.8
version: 5.2.8
+ '@hookform/resolvers':
+ specifier: ^5.2.2
'@lobehub/icons':
specifier: ^2.45.0
@@ -138,7 +141,7 @@ importers:
specifier: ^19.1.1
version: 19.2.1([email protected])
react-hook-form:
- specifier: ^7
+ specifier: ^7.72.1
version: 7.72.1([email protected])
react-js-cron:
specifier: ^5.2.0
@@ -185,6 +188,9 @@ importers:
vite:
specifier: ^7.1.2
+ zod:
+ specifier: ^4.3.6
+ version: 4.3.6
zustand:
specifier: ^5.0.8
@@ -982,6 +988,11 @@ packages:
peerDependencies:
hono: ^4
+ '@hookform/[email protected]':
+ resolution: {integrity: sha512-A/IxlMLShx3KjV/HeTcTfaMxdwy690+L/ZADoeaTltLx+CVuzkeVIPuybK3jrRfw7YZnmdKsVVHAlEPIAEUNlA==}
+ peerDependencies:
+ react-hook-form: ^7.55.0
+
'@humanfs/[email protected]':
resolution: {integrity: sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==}
engines: {node: '>=18.18.0'}
@@ -2099,6 +2110,9 @@ packages:
'@splinetool/[email protected]':
resolution: {integrity: sha512-qznHbXA5aKwDbCgESAothCNm1IeEZcmNWG145p5aXj4w5uoqR1TZ9qkTHTKLTsUbHeitCwdhzmRqan1kxboLgQ==}
+ '@standard-schema/[email protected]':
+ resolution: {integrity: sha512-e7Mew686owMaPJVNNLs55PUvgz371nKgwsc4vxE49zsODpJEnxgxRo2y/OKrqueavXgZNMDVj3DdHFlaSAeU8g==}
+
'@stitches/[email protected]':
resolution: {integrity: sha512-9g9dWI4gsSVe8bNLlb+lMkBYsnIKCZTmvqvDG+Avnn69XfmHZKiaMrx7cgTaddq7aTPPmXiTsbFcUy0xgI4+wA==}
peerDependencies:
@@ -6081,6 +6095,9 @@ packages:
resolution: {integrity: sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==}
+ resolution: {integrity: sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==}
+
resolution: {integrity: sha512-PIJDIZKtokhof+9+60cpockVOq05sJzHCriyvaLBmEJixseQ1a5Kdov6fWZfWOu5SK9c+FhH1jU0tntLxRJYMA==}
engines: {node: '>=12.7.0'}
@@ -6877,6 +6894,11 @@ snapshots:
dependencies:
hono: 4.12.12
+ dependencies:
+ '@standard-schema/utils': 0.3.0
+ react-hook-form: 7.72.1([email protected])
+
'@humanfs/[email protected]': {}
'@humanfs/[email protected]':
@@ -8207,6 +8229,8 @@ snapshots:
on-change: 4.0.2
semver-compare: 1.0.0
+ '@standard-schema/[email protected]': {}
+
dependencies:
react: 19.2.1
@@ -9581,8 +9605,8 @@ snapshots:
'@babel/parser': 7.28.5
eslint: 9.39.1([email protected])
hermes-parser: 0.25.1
- zod: 3.25.76
- zod-validation-error: 4.0.2([email protected])
+ zod: 4.3.6
+ zod-validation-error: 4.0.2([email protected])
transitivePeerDependencies:
- supports-color
@@ -12988,12 +13012,14 @@ snapshots:
dependencies:
zod: 3.25.76
dependencies:
- zod: 3.25.76
+ zod: 4.3.6
+
optionalDependencies:
react: 19.2.1