2025-10-17 18:38:49 +08:00
|
|
|
import React from "react";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
2025-11-01 21:05:01 +08:00
|
|
|
import { Wand2 } from "lucide-react";
|
|
|
|
|
import { toast } from "sonner";
|
|
|
|
|
import { formatJSON } from "@/utils/formatters";
|
2025-10-17 18:38:49 +08:00
|
|
|
|
|
|
|
|
interface CodexAuthSectionProps {
|
|
|
|
|
value: string;
|
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
|
onBlur?: () => void;
|
|
|
|
|
error?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CodexAuthSection - Auth JSON editor section
|
|
|
|
|
*/
|
|
|
|
|
export const CodexAuthSection: React.FC<CodexAuthSectionProps> = ({
|
|
|
|
|
value,
|
|
|
|
|
onChange,
|
|
|
|
|
onBlur,
|
|
|
|
|
error,
|
|
|
|
|
}) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2025-11-01 21:05:01 +08:00
|
|
|
const handleFormat = () => {
|
|
|
|
|
if (!value.trim()) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const formatted = formatJSON(value);
|
|
|
|
|
onChange(formatted);
|
|
|
|
|
toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" }));
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const errorMessage =
|
|
|
|
|
error instanceof Error ? error.message : String(error);
|
|
|
|
|
toast.error(
|
|
|
|
|
t("common.formatError", {
|
|
|
|
|
defaultValue: "格式化失败:{{error}}",
|
|
|
|
|
error: errorMessage,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-17 18:38:49 +08:00
|
|
|
return (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label
|
|
|
|
|
htmlFor="codexAuth"
|
|
|
|
|
className="block text-sm font-medium text-gray-900 dark:text-gray-100"
|
|
|
|
|
>
|
|
|
|
|
{t("codexConfig.authJson")}
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<textarea
|
|
|
|
|
id="codexAuth"
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={(e) => onChange(e.target.value)}
|
|
|
|
|
onBlur={onBlur}
|
|
|
|
|
placeholder={t("codexConfig.authJsonPlaceholder")}
|
|
|
|
|
rows={6}
|
2025-10-22 13:31:17 +08:00
|
|
|
className="w-full px-3 py-2 border border-border-default dark:bg-gray-800 dark:text-gray-100 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20 transition-colors resize-y min-h-[8rem]"
|
2025-10-17 18:38:49 +08:00
|
|
|
autoComplete="off"
|
|
|
|
|
autoCorrect="off"
|
|
|
|
|
autoCapitalize="none"
|
|
|
|
|
spellCheck={false}
|
|
|
|
|
lang="en"
|
|
|
|
|
inputMode="text"
|
|
|
|
|
data-gramm="false"
|
|
|
|
|
data-gramm_editor="false"
|
|
|
|
|
data-enable-grammarly="false"
|
|
|
|
|
/>
|
|
|
|
|
|
2025-11-01 21:05:01 +08:00
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={handleFormat}
|
|
|
|
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<Wand2 className="w-3.5 h-3.5" />
|
|
|
|
|
{t("common.format", { defaultValue: "格式化" })}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{error && (
|
|
|
|
|
<p className="text-xs text-red-500 dark:text-red-400">{error}</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2025-10-17 18:38:49 +08:00
|
|
|
|
2025-11-01 21:05:01 +08:00
|
|
|
{!error && (
|
|
|
|
|
<p className="text-xs text-gray-500 dark:text-gray-400">
|
|
|
|
|
{t("codexConfig.authJsonHint")}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
2025-10-17 18:38:49 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface CodexConfigSectionProps {
|
|
|
|
|
value: string;
|
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
|
useCommonConfig: boolean;
|
|
|
|
|
onCommonConfigToggle: (checked: boolean) => void;
|
|
|
|
|
onEditCommonConfig: () => void;
|
|
|
|
|
commonConfigError?: string;
|
|
|
|
|
configError?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CodexConfigSection - Config TOML editor section
|
|
|
|
|
*/
|
|
|
|
|
export const CodexConfigSection: React.FC<CodexConfigSectionProps> = ({
|
|
|
|
|
value,
|
|
|
|
|
onChange,
|
|
|
|
|
useCommonConfig,
|
|
|
|
|
onCommonConfigToggle,
|
|
|
|
|
onEditCommonConfig,
|
|
|
|
|
commonConfigError,
|
|
|
|
|
configError,
|
|
|
|
|
}) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<label
|
|
|
|
|
htmlFor="codexConfig"
|
|
|
|
|
className="block text-sm font-medium text-gray-900 dark:text-gray-100"
|
|
|
|
|
>
|
|
|
|
|
{t("codexConfig.configToml")}
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<label className="inline-flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400 cursor-pointer">
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
checked={useCommonConfig}
|
|
|
|
|
onChange={(e) => onCommonConfigToggle(e.target.checked)}
|
refactor: implement unified border design system
- Define custom border utilities in @layer utilities for consistent theming
- Add border-default (1px gray), border-active (2px primary), border-hover (40% primary), and border-dragging (60% primary) classes
- Update all UI components (Input, Select, TextArea, Button, Dialog, Dropdown) to use unified border classes
- Replace hardcoded border colors (gray-200/300/600/700) with theme-responsive border-border-default
- Update provider cards, MCP components, settings, and forms with new border system
- Remove dark mode border overrides to simplify CSS and improve maintainability
- Ensure all borders automatically adapt to light/dark themes via CSS variables
2025-10-20 23:44:06 +08:00
|
|
|
className="w-4 h-4 text-blue-500 bg-white dark:bg-gray-800 border-border-default rounded focus:ring-blue-500 dark:focus:ring-blue-400 focus:ring-2"
|
2025-10-17 18:38:49 +08:00
|
|
|
/>
|
|
|
|
|
{t("codexConfig.writeCommonConfig")}
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center justify-end">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={onEditCommonConfig}
|
|
|
|
|
className="text-xs text-blue-500 dark:text-blue-400 hover:underline"
|
|
|
|
|
>
|
|
|
|
|
{t("codexConfig.editCommonConfig")}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{commonConfigError && (
|
|
|
|
|
<p className="text-xs text-red-500 dark:text-red-400 text-right">
|
|
|
|
|
{commonConfigError}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<textarea
|
|
|
|
|
id="codexConfig"
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={(e) => onChange(e.target.value)}
|
|
|
|
|
placeholder=""
|
|
|
|
|
rows={8}
|
2025-10-22 13:31:17 +08:00
|
|
|
className="w-full px-3 py-2 border border-border-default dark:bg-gray-800 dark:text-gray-100 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20 transition-colors resize-y min-h-[10rem]"
|
2025-10-17 18:38:49 +08:00
|
|
|
autoComplete="off"
|
|
|
|
|
autoCorrect="off"
|
|
|
|
|
autoCapitalize="none"
|
|
|
|
|
spellCheck={false}
|
|
|
|
|
lang="en"
|
|
|
|
|
inputMode="text"
|
|
|
|
|
data-gramm="false"
|
|
|
|
|
data-gramm_editor="false"
|
|
|
|
|
data-enable-grammarly="false"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{configError && (
|
|
|
|
|
<p className="text-xs text-red-500 dark:text-red-400">{configError}</p>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-11-01 21:05:01 +08:00
|
|
|
{!configError && (
|
|
|
|
|
<p className="text-xs text-gray-500 dark:text-gray-400">
|
|
|
|
|
{t("codexConfig.configTomlHint")}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
2025-10-17 18:38:49 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|