Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: slove the creds detail page cant modify the kv creds (#13473)

LiJianda1bccfd20ba
diff --git a/src/routes/(main)/settings/creds/features/EditCredModal/EditKVForm.tsx b/src/routes/(main)/settings/creds/features/EditCredModal/EditKVForm.tsx
index 39957e23422..59c96b528b5 100644
--- a/src/routes/(main)/settings/creds/features/EditCredModal/EditKVForm.tsx
+++ b/src/routes/(main)/settings/creds/features/EditCredModal/EditKVForm.tsx
@@ -52,7 +52,7 @@ const EditKVForm: FC<EditKVFormProps> = ({ cred, onCancel, onSuccess }) => {
});
// Convert values object to array of key-value pairs
- const values = (result as any).values || {};
+ const values = (result as any).plaintext || {};
const kvPairs = Object.entries(values).map(([key, value]) => ({
key,
value: value as string,
diff --git a/src/routes/(main)/settings/creds/features/ViewCredModal.tsx b/src/routes/(main)/settings/creds/features/ViewCredModal.tsx
index d32f59b47f1..40cc36ad00e 100644
--- a/src/routes/(main)/settings/creds/features/ViewCredModal.tsx
+++ b/src/routes/(main)/settings/creds/features/ViewCredModal.tsx
@@ -1,16 +1,130 @@
'use client';
import { type UserCredSummary } from '@lobechat/types';
-import { CopyButton } from '@lobehub/ui';
+import { CopyButton, Flexbox } from '@lobehub/ui';
import { useQuery } from '@tanstack/react-query';
import { Alert, Descriptions, Modal, Skeleton, Typography } from 'antd';
-import { type FC } from 'react';
+import { createStyles } from 'antd-style';
+import { Eye, EyeOff } from 'lucide-react';
+import { type FC, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { lambdaClient } from '@/libs/trpc/client';
const { Text } = Typography;
+const useStyles = createStyles(({ css, token }) => ({
+ kvKey: css`
+ min-width: 140px;
+ padding-block: 8px;
+ padding-inline: 12px;
+ border-radius: ${token.borderRadius}px 0 0 ${token.borderRadius}px;
+
+ font-family: ${token.fontFamilyCode};
+ font-size: 13px;
+ color: ${token.colorTextSecondary};
+
+ background: ${token.colorFillQuaternary};
+ `,
+ kvRow: css`
+ display: flex;
+ align-items: stretch;
+ border: 1px solid ${token.colorBorderSecondary};
+ border-radius: ${token.borderRadius}px;
+
+ &:not(:last-child) {
+ margin-block-end: 8px;
+ }
+ `,
+ kvValue: css`
+ display: flex;
+ flex: 1;
+ gap: 8px;
+ align-items: center;
+ justify-content: space-between;
+
+ padding-block: 8px;
+ padding-inline: 12px;
+ border-radius: 0 ${token.borderRadius}px ${token.borderRadius}px 0;
+
+ font-family: ${token.fontFamilyCode};
+ font-size: 13px;
+
+ background: ${token.colorBgContainer};
+ `,
+ maskedValue: css`
+ color: ${token.colorTextQuaternary};
+ letter-spacing: 2px;
+ `,
+ toggleBtn: css`
+ cursor: pointer;
+
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ padding: 4px;
+ border-radius: ${token.borderRadiusSM}px;
+
+ color: ${token.colorTextTertiary};
+
+ transition: all 0.2s;
+
+ &:hover {
+ color: ${token.colorText};
+ background: ${token.colorFillSecondary};
+ }
+ `,
+ valuesSection: css`
+ margin-block-start: 16px;
+ `,
+ valuesTitle: css`
+ margin-block-end: 12px;
+ font-weight: 500;
+ `,
+}));
+
+// Mask value like "sk-****xxxx"
+const maskValue = (value: string): string => {
+ if (value.length <= 4) return '••••••••';
+ return '••••••••' + value.slice(-4);
+};
+
+interface KVRowProps {
+ keyName: string;
+ value: string;
+}
+
+const KVRow: FC<KVRowProps> = ({ keyName, value }) => {
+ const { styles, cx } = useStyles();
+ const [visible, setVisible] = useState(false);
+
+ return (
+ <div className={styles.kvRow}>
+ <div className={styles.kvKey}>{keyName}</div>
+ <div className={styles.kvValue}>
+ <Text
+ className={cx(!visible && styles.maskedValue)}
+ style={{
+ flex: 1,
+ fontFamily: 'var(--lobe-font-family-code)',
+ fontSize: 13,
+ wordBreak: 'break-all',
+ }}
+ >
+ {visible ? value : maskValue(value)}
+ </Text>
+ <Flexbox horizontal align="center" gap={4}>
+ <div className={styles.toggleBtn} onClick={() => setVisible(!visible)}>
+ {visible ? <EyeOff size={16} /> : <Eye size={16} />}
+ </div>
+ <CopyButton content={value} size="small" />
+ </Flexbox>
+ </div>
+ </div>
+ );
+};
+
interface ViewCredModalProps {
cred: UserCredSummary | null;
onClose: () => void;
@@ -19,6 +133,7 @@ interface ViewCredModalProps {
const ViewCredModal: FC<ViewCredModalProps> = ({ cred, open, onClose }) => {
const { t } = useTranslation('setting');
+ const { styles } = useStyles();
const { data, isLoading, error } = useQuery({
enabled: open && !!cred,
@@ -30,7 +145,7 @@ const ViewCredModal: FC<ViewCredModalProps> = ({ cred, open, onClose }) => {
queryKey: ['cred-plaintext', cred?.id],
});
- const values = (data as any)?.values || {};
+ const values = (data as any)?.plaintext || {};
const valueEntries = Object.entries(values);
return (
@@ -69,35 +184,12 @@ const ViewCredModal: FC<ViewCredModalProps> = ({ cred, open, onClose }) => {
</Descriptions>
{valueEntries.length > 0 && (
- <Descriptions
- bordered
- column={1}
- size="small"
- style={{ marginTop: 16 }}
- title={t('creds.view.values')}
- >
+ <div className={styles.valuesSection}>
+ <div className={styles.valuesTitle}>{t('creds.view.values')}</div>
{valueEntries.map(([key, value]) => (
- <Descriptions.Item
- contentStyle={{ display: 'flex', alignItems: 'center', gap: 8 }}
- key={key}
- label={key}
- labelStyle={{ width: 120 }}
- >
- <Text
- copyable={false}
- style={{
- flex: 1,
- fontFamily: 'monospace',
- fontSize: 12,
- wordBreak: 'break-all',
- }}
- >
- {String(value)}
- </Text>
- <CopyButton content={String(value)} size="small" />
- </Descriptions.Item>
+ <KVRow key={key} keyName={key} value={String(value)} />
))}
- </Descriptions>
+ </div>
)}
{valueEntries.length === 0 && cred?.type === 'oauth' && (