feat: add MCP service tag filtering, transaction record viewing, and various optimizations

This commit is contained in:
lcx committed 2025-12-30 18:28:25 +08:00
1 parent 276817e624
commit d6dea1f1e8
29 files changed
+1367 -87

No files matched your search

+23 -7
View File
@@ -1,6 +1,6 @@
"use client";
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import {
Navbar,
NavbarContent,
@@ -15,6 +15,7 @@ import { useAuth } from "@/shared/lib/useAuth";
import { ArrowRightIcon } from "lucide-react";
import { DynamicLogo } from "@/shared/components/DynamicLogo";
import Link from "next/link";
import { useSharedStore } from "../store/share";
export type NavigationItem = {
label: string;
href: string;
@@ -45,6 +46,13 @@ function NavigationClient({
const { t } = useTranslation();
const { handleLogin } = useAuth();
const [userToken, setUserToken] = useState<string | null>(null);
useEffect(() => {
const userToken = useSharedStore?.getState?.().user_token
setUserToken(userToken);
}, []);
return (
<>
{/* Main Navigation */}
@@ -97,9 +105,17 @@ function NavigationClient({
{langNode ? (
langNode
) : (
<Button onPress={handleLogin} variant="light">
<b className="text-md"> {t("Sign In")}</b>
</Button>
<>
{
!userToken && (
<>
<Button onPress={handleLogin} variant="light">
<b className="text-md"> {t("Sign In")}</b>
</Button>
</>
)
}
</>
)}
{/* Desktop Auth Button */}
@@ -110,7 +126,7 @@ function NavigationClient({
radius="full"
onPress={onLogin || handleLogin}
>
<b className="text-md"> {t(signinText)}</b>
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</b>
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
<ArrowRightIcon
size={16}
@@ -128,7 +144,7 @@ function NavigationClient({
onPress={onLogin || handleLogin}
size="sm"
>
<b className="text-md"> {t(signinText)}</b>
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</b>
</Button>
</div>
)}
@@ -156,7 +172,7 @@ function NavigationClient({
radius="full"
onPress={onLogin || handleLogin}
>
<b className="text-md"> {t(signinText)}</b>
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</b>
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
<ArrowRightIcon
size={16}
@@ -9,6 +9,7 @@ import {
interface HeroSectionProps {
searchQuery: string;
isTagBarDisplay: boolean;
onSearchChange: (value: string) => void;
onSearch?: () => void;
searchSuggestions?: string[];
@@ -16,6 +17,7 @@ interface HeroSectionProps {
export const HeroSection: React.FC<HeroSectionProps> = ({
searchQuery,
isTagBarDisplay,
onSearchChange,
onSearch,
searchSuggestions = [],
@@ -77,7 +79,7 @@ export const HeroSection: React.FC<HeroSectionProps> = ({
};
return (
<div className="relative overflow-hidden mx-auto p-6 py-24 max-w-7xl">
<div className={`relative overflow-hidden mx-auto p-6 ${isTagBarDisplay ? 'py-12' : 'py-24'} max-w-7xl`}>
<div className="text-center mb-12">
<h1 className="text-5xl lg:text-6xl font-bold mb-6 leading-tight">
{t(
@@ -1,6 +1,6 @@
"use client";
import React, { useState } from "react";
import React, { useCallback, useEffect, useState } from "react";
import { Card, Chip, Button, Select, SelectItem } from "@nextui-org/react";
import { FlipButton } from "@/shared/components/FlipButton";
import { useAuth } from "@/shared/lib/useAuth";
@@ -9,7 +9,16 @@ import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
import { Copy } from "lucide-react";
import { copyToClipboard } from "@/shared/utils/clipboard";
import toast from "react-hot-toast";
import { useSharedStore } from "@/shared/store/share";
import { fetchAPI } from "@/shared/rpc/common-function";
import i18n from "@/shared/lib/i18n";
type apiKeyList = {
name: string;
apikey: string;
create_time: string;
apikey_id: number;
}
interface ServerConfigProps {
mcpName?: string;
url?: string;
@@ -20,6 +29,18 @@ interface ServerConfigProps {
type McpType = "sse" | "streamable-http";
// 辅助函数:将 API Key 掩码显示,只保留前2位和后4位
const maskApiKey = (apiKey: string): string => {
if (!apiKey || apiKey.length <= 6) {
return apiKey; // 如果太短就直接返回
}
const prefix = apiKey.slice(0, 2);
const suffix = apiKey.slice(-4);
const maskedLength = apiKey.length - 6;
const masked = '*'.repeat(maskedLength);
return `${prefix}${masked}${suffix}`;
};
export const ServerConfig: React.FC<ServerConfigProps> = ({
mcpName,
url = process.env.NEXT_PUBLIC_MCP_URL,
@@ -31,6 +52,48 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
const { handleLogin } = useAuth();
const { platformConfig } = usePlatformConfig();
const [mcpType, setMcpType] = useState<McpType>("sse");
// API Key List
const [apiKeys, setApiKeys] = useState<{ key: string, label: string }[]>([]);
// Selected API Key
const [selectedApiKey, setSelectedApiKey] = useState<string | null>(null);
// User Token
const [userToken, setUserToken] = useState<string | null>(null);
useEffect(() => {
const fetchData = async () => {
const userToken = useSharedStore?.getState?.().user_token
setUserToken(userToken);
if (userToken) {
const data = await fetchApiKeys()
if (data.length > 0) {
setApiKeys(data.map((item) => ({
key: item.apikey,
label: item.name,
})));
}
}
}
fetchData();
}, []);
const fetchApiKeys = useCallback(
async (
): Promise<apiKeyList[]> => {
try {
const response = await fetchAPI<apiKeyList[]>('/api/apikey/list');
if (!response.success) {
toast.error(response.error_message || i18n.t("Failed to load api keys"));
return []
}
return response.data || []
} catch (error) {
console.error("Error fetching api keys:", error);
return []
}
},
[]
);
const mcpTypeOptions = [
{ key: "sse", label: "SSE (Server-Sent Events)" },
@@ -40,8 +103,8 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
const getCodeContent = () => {
const serverUrl =
mcpType === "streamable-http"
? `${url}/streamable-http?authkey={Your-${platformConfig?.name}-Auth-Key}`
: `${url}?authkey={Your-${platformConfig?.name}-Auth-Key}`;
? `${url}/streamable-http?authkey=${selectedApiKey ? selectedApiKey : `{Your-${platformConfig?.name}-Auth-Key}`}`
: `${url}?authkey=${selectedApiKey ? selectedApiKey : `{Your-${platformConfig?.name}-Auth-Key}`}`;
return `{
"mcpServers": {
@@ -63,16 +126,62 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
}
};
const handleCreateNewAuthorization = () => {
sessionStorage.setItem('create_new_authorization', 'true');
handleLogin()
}
return (
<div className={`min-w-full ${className} flex-shrink-0`}>
<div className="mb-2 mt-1">
{
visitor || can_invoke ? <>
<FlipButton
className="w-full rounded-md"
text={t("Sign up to get the auth key")}
onPress={handleLogin}
/>
{
!userToken ? <>
<FlipButton
className="w-full rounded-md"
text={t("Sign up to get the auth key")}
onPress={handleLogin}
/>
</> : <>
{
apiKeys.length ?
<>
<Select
label={t("Auth Key")}
placeholder={t("Auth Key Name")}
selectedKeys={selectedApiKey ? [selectedApiKey] : []}
onSelectionChange={(keys) => {
const selectedKey = Array.from(keys)[0] as string;
setSelectedApiKey(selectedKey);
}}
className="w-full"
size="sm"
classNames={{
trigger: " bg-black text-white data-[hover=true]:bg-dark-200",
label: "!text-default-200",
value: "!text-white",
popoverContent: "bg-black text-white",
}}
>
{apiKeys.map((option) => (
<SelectItem key={option.key} value={option.key}>
{option.label}
</SelectItem>
))}
</Select>
</>
:
<>
<FlipButton
className="w-full rounded-md"
text={t("Create New Authorization")}
onPress={handleCreateNewAuthorization}
/>
</>
}
</>
}
</> : <>
<div className="w-full rounded-lg bg-[#F3126033] md:pr-2 h-[40px] md:h-[50px] shadow-lg flex items-center justify-center">
<p className="text-[#C20E4D] text-center font-bold text-lg leading-none">
@@ -140,7 +249,7 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
{mcpType === "streamable-http"
? `${url}/streamable-http?authkey=`
: `${url}?authkey=`}
<span className="text-success">{`{Your-${platformConfig?.name}-Auth-Key}`}</span>
<span className="text-success">{selectedApiKey ? maskApiKey(selectedApiKey) : `{Your-${platformConfig?.name}-Auth-Key}`}</span>
{`"
}
}
@@ -0,0 +1,309 @@
"use client";
import React, { useState, useEffect, useRef } from "react";
import {
Modal,
ModalContent,
ModalHeader,
ModalBody,
ModalFooter,
Button,
} from "@nextui-org/react";
import { Theme, ThemeType } from "@/shared/types/system";
import { useTranslation } from "react-i18next";
interface TagFilterProps {
tags: string[];
theme: ThemeType;
selectedTag: string;
onTagChange: (tag: string) => void;
maxWidthPercent?: number; // 最大宽度百分比,默认80%
}
export const TagFilter: React.FC<TagFilterProps> = ({
tags,
theme,
selectedTag,
onTagChange,
maxWidthPercent = 80,
}) => {
const { t } = useTranslation();
// 是否打开标签筛选弹窗
const [isModalOpen, setIsModalOpen] = useState(false);
// 临时选中的标签
const [tempSelectedTag, setTempSelectedTag] = useState<string | null>(null);
// 可见的标签
const [visibleTags, setVisibleTags] = useState<string[]>(["ALL", ...tags]);
// 是否显示更多按钮
const [showMore, setShowMore] = useState(false);
// 从弹窗选择的额外标签
const [extraTag, setExtraTag] = useState<string | null>(null);
// 容器引用
const containerRef = useRef<HTMLDivElement>(null);
// 标签容器引用
const tagsContainerRef = useRef<HTMLDivElement>(null);
// 根据主题获取颜色配置
const getThemeColors = () => {
switch (theme) {
case Theme.DEFAULT:
case Theme.MODERN:
return {
selected: "bg-[#C8DCFF] text-[#1E40AF]",
unselected: "text-gray-700 hover:bg-gray-200",
shadow: "shadow-lg shadow-[#C8DCFF]/50",
};
case Theme.CLASSIC:
return {
selected: "bg-[#475569] text-white",
unselected: "text-gray-700 hover:bg-gray-200",
shadow: "shadow-lg shadow-[#475569]/50",
};
case Theme.TEMU:
return {
selected: "bg-[#F97316] text-white",
unselected: "text-gray-700 hover:bg-gray-200",
shadow: "shadow-lg shadow-[#F97316]/50",
};
case Theme.CREATIVE:
return {
selected: "to-orange-500 via-red-500 from-pink-500 bg-gradient-to-r text-white",
unselected: "text-gray-700 hover:bg-gray-200",
shadow: "shadow-lg shadow-[#EF5082]/50",
};
default:
return {
selected: "bg-[#C8DCFF] text-[#1E40AF]",
unselected: "text-gray-700 hover:bg-gray-200",
shadow: "shadow-lg shadow-[#C8DCFF]/50",
};
}
};
const themeColors = getThemeColors();
// 计算哪些标签可以显示
useEffect(() => {
const calculateVisibleTags = () => {
if (!containerRef.current) return;
const containerWidth = containerRef.current.offsetWidth;
const maxWidth = (containerWidth * maxWidthPercent) / 100;
// More按钮的宽度(估算)
const moreButtonWidth = 80;
// 创建临时元素来测量标签宽度
const tempDiv = document.createElement("div");
tempDiv.style.position = "absolute";
tempDiv.style.visibility = "hidden";
tempDiv.style.whiteSpace = "nowrap";
tempDiv.className = "px-6 py-2 rounded-full text-sm font-medium";
document.body.appendChild(tempDiv);
let currentWidth = 0;
const visible: string[] = ["ALL"];
let needsMore = false;
// 先计算常规标签
for (const tag of tags) {
if (tag === extraTag) continue; // 跳过额外标签,稍后处理
tempDiv.textContent = tag;
const tagWidth = tempDiv.offsetWidth; // 不加间距
if (currentWidth + tagWidth + moreButtonWidth > maxWidth) {
needsMore = true;
break;
}
currentWidth += tagWidth;
visible.push(tag);
}
// 处理额外标签或当前选中的标签
// 如果当前选中的标签不在可见列表中(除了ALL),需要作为额外标签显示
const tagToShow = extraTag || (selectedTag !== "ALL" && !visible.includes(selectedTag) ? selectedTag : null);
if (tagToShow && tagToShow !== "ALL" && !visible.includes(tagToShow)) {
tempDiv.textContent = tagToShow;
const tagWidth = tempDiv.offsetWidth; // 不加间距
// 检查是否还有空间显示额外标签
if (currentWidth + tagWidth + moreButtonWidth <= maxWidth) {
// 空间足够,直接添加
currentWidth += tagWidth;
visible.push(tagToShow);
} else {
// 空间不够,替换掉最后一个常规标签(保留 ALL)
if (visible.length > 1) {
visible.pop(); // 移除最后一个标签
visible.push(tagToShow); // 添加额外标签
needsMore = true; // 确保显示 More 按钮
}
}
}
document.body.removeChild(tempDiv);
setVisibleTags(visible);
setShowMore(needsMore);
};
// 延迟执行以确保DOM已渲染
setTimeout(calculateVisibleTags, 0);
// 监听窗口大小变化
window.addEventListener("resize", calculateVisibleTags);
return () => window.removeEventListener("resize", calculateVisibleTags);
}, [tags, extraTag, selectedTag, maxWidthPercent]);
const handleTagClick = (tag: string) => {
// 如果点击的是额外标签以外的标签,清除额外标签
if (extraTag && tag !== extraTag) {
setExtraTag(null);
}
onTagChange(tag);
};
const handleModalOpen = () => {
// 打开弹窗时,初始化临时选中的标签为当前选中的标签
setTempSelectedTag(selectedTag);
setIsModalOpen(true);
};
const handleModalConfirm = () => {
if (tempSelectedTag) {
// 如果选择的是 ALL 或者已经在可见标签中的标签,不设置为额外标签
if (tempSelectedTag === "ALL" || visibleTags.includes(tempSelectedTag)) {
setExtraTag(null);
} else {
// 否则设置为额外标签
setExtraTag(tempSelectedTag);
}
onTagChange(tempSelectedTag);
}
setIsModalOpen(false);
};
const handleModalCancel = () => {
setTempSelectedTag(null);
setIsModalOpen(false);
};
const handleModalTagClick = (tag: string) => {
setTempSelectedTag(tag);
};
return (
<>
<div ref={containerRef} className="w-full px-6 py-6">
<div className="mx-auto max-w-7xl text-center">
<div
ref={tagsContainerRef}
className="inline-flex items-center border-1 bg-[#fff] rounded-full transition-all duration-300"
>
{visibleTags.map((tag) => {
const isSelected = selectedTag === tag;
return (
<button
key={tag}
onClick={() => handleTagClick(tag)}
className={`
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
whitespace-nowrap
${
isSelected
? `${themeColors.selected} ${themeColors.shadow}`
: themeColors.unselected
}
`}
>
{tag}
</button>
);
})}
{showMore && (
<button
onClick={handleModalOpen}
className="px-4 py-2 text-sm font-medium text-blue-500 hover:text-blue-600 transition-colors whitespace-nowrap"
>
More
</button>
)}
</div>
</div>
</div>
{/* More Modal */}
<Modal
isOpen={isModalOpen}
onClose={handleModalCancel}
size="2xl"
scrollBehavior="inside"
>
<ModalContent>
<ModalHeader className="flex flex-col gap-1">
Tag Filter
</ModalHeader>
<ModalBody>
<div className="flex flex-wrap gap-3 py-4">
<button
onClick={() => handleModalTagClick("ALL")}
className={`
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
${
tempSelectedTag === "ALL"
? "bg-blue-500 text-white shadow-lg shadow-blue-500/50"
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
}
`}
>
ALL
</button>
{tags.map((tag) => {
const isSelected = tempSelectedTag === tag;
return (
<button
key={tag}
onClick={() => handleModalTagClick(tag)}
className={`
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
${
isSelected
? "bg-blue-500 text-white shadow-lg shadow-blue-500/50"
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
}
`}
>
{tag}
</button>
);
})}
</div>
</ModalBody>
<ModalFooter>
<Button
color="default"
variant="light"
onPress={handleModalCancel}
>
{t("Cancel")}
</Button>
<Button
color="primary"
onPress={handleModalConfirm}
isDisabled={!tempSelectedTag}
>
{t("Confirm")}
</Button>
</ModalFooter>
</ModalContent>
</Modal>
</>
);
};