Refactor API key handling in AssistantPage and ComponentsModelsPage
- Update AssistantPage to use a stored value mask for API keys, improving security and user experience. - Modify ComponentsModelsPage to display the current API key contextually, enhancing clarity for users. - Adjust related components to ensure consistent handling of API key visibility and management.
This commit is contained in:
@@ -584,9 +584,10 @@ export function AssistantPage() {
|
|||||||
type: typeToLabel[a.type],
|
type: typeToLabel[a.type],
|
||||||
updatedAt: formatTimestamp(a.updatedAt),
|
updatedAt: formatTimestamp(a.updatedAt),
|
||||||
}));
|
}));
|
||||||
const hasStoredApiKey = Boolean(
|
const storedApiKeyMask =
|
||||||
editingId && assistants.find((assistant) => assistant.id === editingId)?.apiKey,
|
(editingId &&
|
||||||
);
|
assistants.find((assistant) => assistant.id === editingId)?.apiKey) ||
|
||||||
|
"";
|
||||||
|
|
||||||
const filteredAssistants = listItems.filter((assistant) => {
|
const filteredAssistants = listItems.filter((assistant) => {
|
||||||
if (typeFilter !== "全部" && assistant.type !== typeFilter) {
|
if (typeFilter !== "全部" && assistant.type !== typeFilter) {
|
||||||
@@ -1135,7 +1136,7 @@ export function AssistantPage() {
|
|||||||
value={difyForm.apiKey}
|
value={difyForm.apiKey}
|
||||||
onChange={(value) => updateDifyForm("apiKey", value)}
|
onChange={(value) => updateDifyForm("apiKey", value)}
|
||||||
placeholder="请输入 Dify API Key"
|
placeholder="请输入 Dify API Key"
|
||||||
hasStoredValue={hasStoredApiKey}
|
storedValueMask={storedApiKeyMask}
|
||||||
/>
|
/>
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
|
|
||||||
@@ -1239,7 +1240,7 @@ export function AssistantPage() {
|
|||||||
value={fastGptForm.apiKey}
|
value={fastGptForm.apiKey}
|
||||||
onChange={(value) => updateFastGptForm("apiKey", value)}
|
onChange={(value) => updateFastGptForm("apiKey", value)}
|
||||||
placeholder="请输入 FastGPT API Key"
|
placeholder="请输入 FastGPT API Key"
|
||||||
hasStoredValue={hasStoredApiKey}
|
storedValueMask={storedApiKeyMask}
|
||||||
/>
|
/>
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
|
|
||||||
@@ -1324,7 +1325,7 @@ export function AssistantPage() {
|
|||||||
value={openCodeForm.apiKey}
|
value={openCodeForm.apiKey}
|
||||||
onChange={(value) => updateOpenCodeForm("apiKey", value)}
|
onChange={(value) => updateOpenCodeForm("apiKey", value)}
|
||||||
placeholder="请输入 OpenCode API Key"
|
placeholder="请输入 OpenCode API Key"
|
||||||
hasStoredValue={false}
|
storedValueMask=""
|
||||||
/>
|
/>
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
|
|
||||||
@@ -1908,22 +1909,31 @@ function SecretInputField({
|
|||||||
label,
|
label,
|
||||||
value,
|
value,
|
||||||
placeholder,
|
placeholder,
|
||||||
hasStoredValue,
|
storedValueMask,
|
||||||
onChange,
|
onChange,
|
||||||
}: {
|
}: {
|
||||||
label?: string;
|
label?: string;
|
||||||
value: string;
|
value: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
hasStoredValue: boolean;
|
storedValueMask: string;
|
||||||
onChange: (value: string) => void;
|
onChange: (value: string) => void;
|
||||||
}) {
|
}) {
|
||||||
const [showValue, setShowValue] = useState(false);
|
const [showValue, setShowValue] = useState(false);
|
||||||
|
const hasStoredValue = Boolean(storedValueMask);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label className="block">
|
<label className="block">
|
||||||
{label && (
|
{label && (
|
||||||
<div className="mb-2 text-sm font-medium text-foreground">{label}</div>
|
<div className="mb-2 text-sm font-medium text-foreground">{label}</div>
|
||||||
)}
|
)}
|
||||||
|
{hasStoredValue && (
|
||||||
|
<div className="mb-2 flex items-center gap-2 text-xs text-muted-foreground">
|
||||||
|
<span>当前密钥</span>
|
||||||
|
<code className="rounded-md bg-surface-strong px-2 py-1 font-mono text-foreground">
|
||||||
|
{storedValueMask}
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Input
|
<Input
|
||||||
value={value}
|
value={value}
|
||||||
@@ -1951,7 +1961,7 @@ function SecretInputField({
|
|||||||
</div>
|
</div>
|
||||||
{hasStoredValue && (
|
{hasStoredValue && (
|
||||||
<p className="mt-2 text-xs leading-5 text-muted-foreground">
|
<p className="mt-2 text-xs leading-5 text-muted-foreground">
|
||||||
已有密钥不会返回浏览器。留空可保持原密钥,输入新值将覆盖原密钥。
|
仅显示当前密钥首尾用于识别。留空可保持原密钥,输入新值将覆盖原密钥。
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@@ -696,6 +696,14 @@ export function ComponentsModelsPage() {
|
|||||||
>
|
>
|
||||||
API Key
|
API Key
|
||||||
</FieldLabel>
|
</FieldLabel>
|
||||||
|
{hasStoredApiKey && (
|
||||||
|
<div className="mb-2 flex items-center gap-2 text-xs text-muted-foreground">
|
||||||
|
<span>当前密钥</span>
|
||||||
|
<code className="rounded-md bg-surface-strong px-2 py-1 font-mono text-foreground">
|
||||||
|
{editingModel?.apiKey}
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Input
|
<Input
|
||||||
id="model-api-key"
|
id="model-api-key"
|
||||||
@@ -722,7 +730,7 @@ export function ComponentsModelsPage() {
|
|||||||
</div>
|
</div>
|
||||||
{hasStoredApiKey && (
|
{hasStoredApiKey && (
|
||||||
<p className="mt-2 text-xs leading-5 text-muted-foreground">
|
<p className="mt-2 text-xs leading-5 text-muted-foreground">
|
||||||
已有密钥不会返回浏览器。留空可保持原密钥,输入新值将覆盖原密钥。
|
仅显示当前密钥首尾用于识别。留空可保持原密钥,输入新值将覆盖原密钥。
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user