Compare commits
5 Commits
3edd6b2a69
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e19b1811d8 | ||
|
|
3269b2eef3 | ||
| 52fa9c5b42 | |||
| 08294e0c7f | |||
| cf2baecb3c |
33
package.json
33
package.json
@@ -14,43 +14,44 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@base-ui/react": "^1.2.0",
|
||||
"@kevisual/router": "0.0.84",
|
||||
"@tanstack/react-router": "^1.163.2",
|
||||
"@kevisual/router": "0.1.1",
|
||||
"@tanstack/react-router": "^1.166.7",
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
"@uiw/react-codemirror": "^4.25.5",
|
||||
"@uiw/react-codemirror": "^4.25.8",
|
||||
"@uiw/react-md-editor": "^4.0.11",
|
||||
"antd": "^6.3.1",
|
||||
"antd": "^6.3.2",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "^1.1.1",
|
||||
"dayjs": "^1.11.19",
|
||||
"eruda": "^3.4.3",
|
||||
"es-toolkit": "^1.44.0",
|
||||
"es-toolkit": "^1.45.1",
|
||||
"fuse.js": "^7.1.0",
|
||||
"idb-keyval": "^6.2.2",
|
||||
"lucide-react": "^0.575.0",
|
||||
"lucide-react": "^0.577.0",
|
||||
"nanoid": "^5.1.6",
|
||||
"next-themes": "^0.4.6",
|
||||
"react": "19.2.4",
|
||||
"react-dom": "19.2.4",
|
||||
"react-hook-form": "^7.71.2",
|
||||
"react-resizable-panels": "^4.6.5",
|
||||
"react-resizable-panels": "^4.7.2",
|
||||
"sonner": "^2.0.7",
|
||||
"valtio": "^2.3.0",
|
||||
"valtio": "^2.3.1",
|
||||
"zod": "^4.3.6",
|
||||
"zustand": "^5.0.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kevisual/api": "^0.0.60",
|
||||
"@kevisual/ai": "^0.0.28",
|
||||
"@kevisual/api": "^0.0.62",
|
||||
"@kevisual/context": "^0.0.8",
|
||||
"@kevisual/js-filter": "^0.0.5",
|
||||
"@kevisual/kv-login": "^0.1.15",
|
||||
"@kevisual/query": "^0.0.52",
|
||||
"@kevisual/js-filter": "^0.0.6",
|
||||
"@kevisual/kv-login": "^0.1.17",
|
||||
"@kevisual/query": "^0.0.53",
|
||||
"@kevisual/types": "^0.0.12",
|
||||
"@tailwindcss/vite": "^4.2.1",
|
||||
"@tanstack/react-router-devtools": "^1.163.2",
|
||||
"@tanstack/router-plugin": "^1.163.2",
|
||||
"@types/node": "^25.3.0",
|
||||
"@tanstack/react-router-devtools": "^1.166.7",
|
||||
"@tanstack/router-plugin": "^1.166.7",
|
||||
"@types/node": "^25.4.0",
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^5.1.4",
|
||||
@@ -59,6 +60,6 @@
|
||||
"tailwindcss": "^4.2.1",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "v8.0.0-beta.15"
|
||||
"vite": "v8.0.0-beta.16"
|
||||
}
|
||||
}
|
||||
|
||||
553
pnpm-lock.yaml
generated
553
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -19,8 +19,14 @@ export const Chat = () => {
|
||||
setIsLoading(true);
|
||||
const { routes } = studioStore;
|
||||
let callPrompts = '';
|
||||
const toolsList = routes.map((r, index) =>
|
||||
`${index + 1}. 工具名称: ${r.id}\n 描述: ${r.description}`
|
||||
const toolsList = routes.map((r, index) => {
|
||||
const args = r.metadata?.args || {};
|
||||
let argsDescription = '';
|
||||
if (Object.keys(args).length > 0) {
|
||||
argsDescription = ',参数: ' + JSON.stringify(args);
|
||||
}
|
||||
return `${index + 1}. 工具名称: path: ${r.path} key: ${r.key}\n 描述: ${r.description}${argsDescription}`;
|
||||
}
|
||||
).join('\n\n');
|
||||
|
||||
callPrompts = `你是一个 AI 助手,你可以使用以下工具来帮助用户完成任务:
|
||||
@@ -34,7 +40,8 @@ ${toolsList}
|
||||
## JSON 数据格式
|
||||
\`\`\`json
|
||||
{
|
||||
"id": "工具的id",
|
||||
"path": "工具的path",
|
||||
"key": "工具的key",
|
||||
"payload": {
|
||||
// 工具所需的参数(如果需要)
|
||||
// 例如: "id": "xxx", "name": "xxx"
|
||||
@@ -45,7 +52,7 @@ ${toolsList}
|
||||
注意:
|
||||
- payload 中包含工具执行所需的所有参数
|
||||
- 如果工具不需要参数,payload 可以为空对象 {}
|
||||
- 确保返回的 id 与上述工具列表中的工具名称完全匹配`
|
||||
- 确保返回的 path 和 key 与上述工具列表中的工具名称完全匹配`
|
||||
|
||||
const res = await query.post({
|
||||
path: 'ai',
|
||||
@@ -69,7 +76,7 @@ ${toolsList}
|
||||
// 处理返回结果
|
||||
const payload = res.data?.action;
|
||||
if (payload) {
|
||||
const route = routes.find(r => r.id === payload.id);
|
||||
const route = routes.find(r => r.path === payload.path && r.key === payload.key);
|
||||
const { path, key } = route || {};
|
||||
const { id, ...otherParams } = payload.payload || {};
|
||||
const action = { path, key, ...otherParams }
|
||||
@@ -101,7 +108,7 @@ ${toolsList}
|
||||
}
|
||||
return <div className="h-full flex flex-col border-l border-gray-300 bg-white">
|
||||
<div style={{ height: '3rem' }} className="flex items-center justify-between px-4 border-b border-gray-300 bg-gray-50">
|
||||
<div className="text-sm text-gray-600">智能体</div>
|
||||
<div className="text-sm text-gray-600">执行体</div>
|
||||
</div>
|
||||
<div style={{ height: 'calc(100% - 3rem)' }} className="overflow-auto">
|
||||
<QueryViewMessages type="component" />
|
||||
|
||||
@@ -539,12 +539,12 @@ export const DetailsDialog = () => {
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<Dialog open={queryViewStore.showDetailsDialog} onOpenChange={queryViewStore.setShowDetailsDialog}>
|
||||
<DialogContent className={`max-h-[80vh] overflow-hidden ${isFullscreen ? 'w-screen! h-screen! max-w-screen! max-h-screen! ' : 'max-w-3xl! '}`}>
|
||||
<DialogHeader>
|
||||
<DialogContent className={`flex flex-col max-h-[85vh] ${isFullscreen ? 'w-screen! h-screen! max-w-screen! max-h-screen! ' : 'max-w-4xl! '}`}>
|
||||
<DialogHeader className="flex-shrink-0">
|
||||
<DialogTitle>详情信息</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex gap-2 border-b border-gray-200">
|
||||
<div className="flex gap-2 border-b border-gray-200 flex-shrink-0">
|
||||
{queryViewStore.allDetailsTabs.map((tab) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
@@ -559,7 +559,7 @@ export const DetailsDialog = () => {
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-4 h-[calc(80vh-200px)] overflow-auto scrollbar px-2">
|
||||
<div className="flex-1 overflow-auto scrollbar px-2 min-h-0">
|
||||
{/* 第一个标签页:详情信息 */}
|
||||
{queryViewStore.detailsActiveTab === 'details' && (
|
||||
<DetailsInfoPanel detailsData={queryViewStore.detailsData} />
|
||||
@@ -575,9 +575,9 @@ export const DetailsDialog = () => {
|
||||
<RouterInfoPanel routeInfo={routeInfo} />
|
||||
)}
|
||||
|
||||
{/* 第三个标签页:响应 */}
|
||||
{/* 第四个标签页:响应 */}
|
||||
{queryViewStore.detailsActiveTab === 'response' && (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-4 h-full">
|
||||
<QueryView viewData={queryViewStore.detailsData} type={'message'} setIsFullscreen={setIsFullscreen} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -67,7 +67,7 @@ export const QueryView = (props: Props) => {
|
||||
setIsList(true);
|
||||
}
|
||||
setData(response.data.list)
|
||||
const [_, firstItem] = response.data.list || []
|
||||
const [firstItem] = response.data.list || []
|
||||
if (firstItem) {
|
||||
const cols: ColumnDef<any>[] = Object.keys(firstItem).map(key => ({
|
||||
accessorKey: key,
|
||||
|
||||
135
src/pages/studio/components/ProxyStatusDialog.tsx
Normal file
135
src/pages/studio/components/ProxyStatusDialog.tsx
Normal file
@@ -0,0 +1,135 @@
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { useStudioStore } from '../store';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { Activity, RefreshCw, CheckCircle, XCircle } from 'lucide-react';
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { cloneDeep } from 'es-toolkit';
|
||||
import { RouterViewItem } from '@kevisual/api/proxy';
|
||||
|
||||
export const ProxyStatusDialog = () => {
|
||||
const { showProxyStatus, setShowProxyStatus, getQueryProxyStatus } = useStudioStore(
|
||||
useShallow((state) => ({
|
||||
showProxyStatus: state.showProxyStatus,
|
||||
setShowProxyStatus: state.setShowProxyStatus,
|
||||
getQueryProxyStatus: state.getQueryProxyStatus,
|
||||
}))
|
||||
);
|
||||
|
||||
const [statusList, setStatusList] = useState<RouterViewItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
|
||||
const loadStatus = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const status = await getQueryProxyStatus();
|
||||
console.log('Loaded proxy status:', status);
|
||||
setStatusList(cloneDeep(status));
|
||||
} catch (error) {
|
||||
console.error('Failed to load proxy status:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (showProxyStatus) {
|
||||
loadStatus();
|
||||
// 每5秒刷新一次
|
||||
intervalRef.current = setInterval(loadStatus, 5000);
|
||||
} else {
|
||||
// 关闭弹窗时清除定时器
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
intervalRef.current = null;
|
||||
}
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
intervalRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [showProxyStatus]);
|
||||
|
||||
const getStatusStyle = (status?: string) => {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
return {
|
||||
icon: <CheckCircle size={14} />,
|
||||
className: 'bg-green-100 text-green-700 border-green-200',
|
||||
};
|
||||
case 'error':
|
||||
return {
|
||||
icon: <XCircle size={14} />,
|
||||
className: 'bg-red-100 text-red-700 border-red-200',
|
||||
};
|
||||
default:
|
||||
return {
|
||||
icon: null,
|
||||
className: 'bg-gray-100 text-gray-700 border-gray-200',
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={showProxyStatus} onOpenChange={setShowProxyStatus}>
|
||||
<DialogContent className="max-w-2xl! max-h-[80vh] overflow-hidden flex flex-col">
|
||||
<DialogHeader className="flex flex-row items-center justify-between">
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<Activity size={20} />
|
||||
Proxy Router 状态
|
||||
<button
|
||||
className="p-1 rounded-md text-gray-500 hover:text-gray-700 hover:bg-gray-200 transition-colors"
|
||||
title="刷新"
|
||||
onClick={loadStatus}
|
||||
disabled={loading}
|
||||
>
|
||||
<RefreshCw size={16} className={loading ? 'animate-spin' : ''} />
|
||||
</button>
|
||||
</DialogTitle>
|
||||
|
||||
</DialogHeader>
|
||||
<div className="flex-1 overflow-auto">
|
||||
{loading ? (
|
||||
<div className="text-center text-gray-500 py-8">加载中...</div>
|
||||
) : statusList.length === 0 ? (
|
||||
<div className="text-center text-gray-500 py-8">暂无数据</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{statusList.map((item) => {
|
||||
const statusStyle = getStatusStyle(item.routerStatus);
|
||||
return (
|
||||
<div
|
||||
key={item.id}
|
||||
className="p-3 border border-gray-200 rounded-md hover:bg-gray-50 transition-colors"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-medium text-gray-900">{item.title}</span>
|
||||
<span className="text-xs text-gray-500">{item.id}</span>
|
||||
</div>
|
||||
{item.type === 'api' && item.api?.url && (
|
||||
<div className="mt-2">
|
||||
<span className="text-xs text-gray-500">URL: </span>
|
||||
<span className="text-xs font-mono text-gray-700">{item.api?.url}</span>
|
||||
</div>
|
||||
)}
|
||||
{item.routerStatus && (
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
<span className={`inline-flex items-center gap-1 px-2 py-1 rounded text-xs border ${statusStyle.className}`}>
|
||||
{statusStyle.icon}
|
||||
{item.routerStatus}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
196
src/pages/studio/components/RouterGroupDialog.tsx
Normal file
196
src/pages/studio/components/RouterGroupDialog.tsx
Normal file
@@ -0,0 +1,196 @@
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { useStudioStore } from '../store';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
import { FolderClosed, FolderOpen, Search, List } from 'lucide-react';
|
||||
import { useState, useMemo, useEffect } from 'react';
|
||||
|
||||
interface RouteItem {
|
||||
id: string;
|
||||
path?: string;
|
||||
key?: string;
|
||||
description?: string;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
interface GroupedRoutes {
|
||||
[group: string]: RouteItem[];
|
||||
}
|
||||
|
||||
type TabType = 'grouped' | 'all';
|
||||
|
||||
export const RouterGroupDialog = () => {
|
||||
const { showRouterGroup, setShowRouterGroup, routes, allRoutes, searchRoutes, setShowFilter, getAllRoutes } = useStudioStore(
|
||||
useShallow((state) => ({
|
||||
showRouterGroup: state.showRouterGroup,
|
||||
setShowRouterGroup: state.setShowRouterGroup,
|
||||
routes: state.routes,
|
||||
allRoutes: state.allRoutes,
|
||||
searchRoutes: state.searchRoutes,
|
||||
setShowFilter: state.setShowFilter,
|
||||
getAllRoutes: state.getAllRoutes,
|
||||
}))
|
||||
);
|
||||
|
||||
const [expandedGroups, setExpandedGroups] = useState<Set<string>>(new Set());
|
||||
const [activeTab, setActiveTab] = useState<TabType>('grouped');
|
||||
|
||||
useEffect(() => {
|
||||
if (showRouterGroup && activeTab === 'all') {
|
||||
getAllRoutes();
|
||||
}
|
||||
}, [showRouterGroup, activeTab, getAllRoutes]);
|
||||
|
||||
const displayRoutes = activeTab === 'grouped' ? routes : allRoutes;
|
||||
|
||||
// 按 path 分组
|
||||
const groupedRoutes = useMemo(() => {
|
||||
const groups: GroupedRoutes = {};
|
||||
displayRoutes.forEach((route: RouteItem) => {
|
||||
if (!route.path) return;
|
||||
// 获取第一级路径作为分组
|
||||
const firstSegment = route.path.split('/').filter(Boolean)[0] || 'root';
|
||||
if (!groups[firstSegment]) {
|
||||
groups[firstSegment] = [];
|
||||
}
|
||||
groups[firstSegment].push(route);
|
||||
});
|
||||
return groups;
|
||||
}, [displayRoutes]);
|
||||
|
||||
const toggleGroup = (group: string) => {
|
||||
const newExpanded = new Set(expandedGroups);
|
||||
if (newExpanded.has(group)) {
|
||||
newExpanded.delete(group);
|
||||
} else {
|
||||
newExpanded.add(group);
|
||||
}
|
||||
setExpandedGroups(newExpanded);
|
||||
};
|
||||
|
||||
const handleSearchByPath = (e: React.MouseEvent, path: string) => {
|
||||
e.stopPropagation();
|
||||
const keyword = `WHERE path='${path}'`;
|
||||
searchRoutes(keyword);
|
||||
setShowFilter(true);
|
||||
setShowRouterGroup(false);
|
||||
};
|
||||
|
||||
const handleSearchByKey = (e: React.MouseEvent, path: string, key: string) => {
|
||||
e.stopPropagation();
|
||||
const keyword = `WHERE path='${path}' AND key='${key}'`;
|
||||
searchRoutes(keyword);
|
||||
setShowFilter(true);
|
||||
setShowRouterGroup(false);
|
||||
};
|
||||
|
||||
const sortedGroups = Object.keys(groupedRoutes).sort();
|
||||
|
||||
const renderRouteItem = (route: RouteItem) => (
|
||||
<div
|
||||
key={route.id}
|
||||
className="px-4 py-2 hover:bg-gray-50 transition-colors flex items-center justify-between"
|
||||
>
|
||||
<div className="flex items-center gap-2 flex-1 min-w-0">
|
||||
<span className="font-mono text-sm text-gray-800 truncate">{route.path}</span>
|
||||
{route.key && (
|
||||
<>
|
||||
<span className="text-xs text-gray-500">/</span>
|
||||
<span className="text-sm text-gray-600 truncate">{route.key}</span>
|
||||
<button
|
||||
className="p-1 rounded text-gray-400 hover:text-gray-700 hover:bg-gray-200 transition-colors shrink-0"
|
||||
title="搜索此路径和key"
|
||||
onClick={(e) => handleSearchByKey(e, route.path!, route.key!)}
|
||||
>
|
||||
<Search size={14} />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{route.description && (
|
||||
<span className="text-xs text-gray-500 truncate max-w-xs ml-2 shrink-0">
|
||||
{route.description}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
const renderGroup = (group: string) => {
|
||||
const isExpanded = expandedGroups.has(group);
|
||||
const groupRoutes = groupedRoutes[group];
|
||||
// 使用分组的第一个路由的完整 path 作为搜索关键词
|
||||
const searchPath = groupRoutes[0]?.path || `/${group}`;
|
||||
|
||||
return (
|
||||
<div key={group} className="border border-gray-200 rounded-md overflow-hidden">
|
||||
<div
|
||||
className="flex items-center gap-2 px-3 py-2 bg-gray-50 cursor-pointer hover:bg-gray-100 transition-colors"
|
||||
onClick={() => toggleGroup(group)}
|
||||
>
|
||||
{isExpanded ? (
|
||||
<FolderOpen size={18} className="text-gray-600" />
|
||||
) : (
|
||||
<FolderClosed size={18} className="text-gray-600" />
|
||||
)}
|
||||
<span className="font-medium text-gray-900">/{group}</span>
|
||||
<span className="text-xs text-gray-500">({groupRoutes.length} 个路由)</span>
|
||||
<button
|
||||
className="ml-auto p-1 rounded text-gray-400 hover:text-gray-700 hover:bg-gray-200 transition-colors"
|
||||
title="搜索此路径"
|
||||
onClick={(e) => handleSearchByPath(e, searchPath)}
|
||||
>
|
||||
<Search size={14} />
|
||||
</button>
|
||||
</div>
|
||||
{isExpanded && (
|
||||
<div className="divide-y divide-gray-100">
|
||||
{groupRoutes.map(renderRouteItem)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={showRouterGroup} onOpenChange={setShowRouterGroup}>
|
||||
<DialogContent className="max-w-3xl! max-h-[80vh] overflow-hidden flex flex-col">
|
||||
<DialogHeader>
|
||||
<DialogTitle>路由分组</DialogTitle>
|
||||
</DialogHeader>
|
||||
{/* Tabs */}
|
||||
<div className="flex border-b border-gray-200">
|
||||
<button
|
||||
className={`flex items-center gap-2 px-4 py-2 text-sm font-medium transition-colors ${
|
||||
activeTab === 'grouped'
|
||||
? 'text-gray-900 border-b-2 border-gray-900'
|
||||
: 'text-gray-500 hover:text-gray-700'
|
||||
}`}
|
||||
onClick={() => setActiveTab('grouped')}
|
||||
>
|
||||
<FolderClosed size={16} />
|
||||
当前分组
|
||||
</button>
|
||||
<button
|
||||
className={`flex items-center gap-2 px-4 py-2 text-sm font-medium transition-colors ${
|
||||
activeTab === 'all'
|
||||
? 'text-gray-900 border-b-2 border-gray-900'
|
||||
: 'text-gray-500 hover:text-gray-700'
|
||||
}`}
|
||||
onClick={() => setActiveTab('all')}
|
||||
>
|
||||
<List size={16} />
|
||||
全部路由 ({allRoutes.length})
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex-1 overflow-auto space-y-2 p-2">
|
||||
{sortedGroups.length === 0 ? (
|
||||
<div className="text-center text-gray-500 py-8">
|
||||
{activeTab === 'all' && allRoutes.length === 0 ? '加载中...' : '暂无路由数据'}
|
||||
</div>
|
||||
) : (
|
||||
sortedGroups.map(renderGroup)
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import { filterRouteInfo, useStudioStore } from './store.ts';
|
||||
import { use, useEffect, useState } from 'react';
|
||||
import { MonitorPlay, Play, PanelLeft, PanelLeftClose, PanelRight, PanelRightClose, PanelTop, PanelTopClose, Filter, FilterX, Search, X, MoreHorizontal, Info, Code, RotateCcw, Book } from 'lucide-react';
|
||||
import { MonitorPlay, Play, PanelLeft, PanelLeftClose, PanelRight, PanelRightClose, PanelTop, PanelTopClose, Filter, FilterX, Search, X, MoreHorizontal, Info, Code, RotateCcw, Book, FolderClosed, Activity } from 'lucide-react';
|
||||
import { Panel, Group } from 'react-resizable-panels'
|
||||
import { ViewList } from '../view/list.tsx';
|
||||
import { useShallow } from 'zustand/shallow';
|
||||
@@ -9,6 +9,8 @@ import { Input } from '@/components/ui/input.tsx';
|
||||
import { Button } from '@/components/ui/button.tsx';
|
||||
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from '@/components/ui/dropdown-menu.tsx';
|
||||
import { ExportDialog } from './components/ExportDialog';
|
||||
import { RouterGroupDialog } from './components/RouterGroupDialog';
|
||||
import { ProxyStatusDialog } from './components/ProxyStatusDialog';
|
||||
import { useQueryViewStore } from '../query-view/store/index.ts';
|
||||
import { toast } from 'sonner';
|
||||
import { DetailsDialog } from '../query-view/components/DetailsDialog.tsx';
|
||||
@@ -115,6 +117,8 @@ export const App = () => {
|
||||
setShowFilter: state.setShowFilter,
|
||||
setShowExportDialog: state.setShowExportDialog,
|
||||
setExportRoutes: state.setExportRoutes,
|
||||
setShowRouterGroup: state.setShowRouterGroup,
|
||||
setShowProxyStatus: state.setShowProxyStatus,
|
||||
})));
|
||||
const queryViewStore = useQueryViewStore(useShallow((state) => ({
|
||||
setShowDetailsDialog: state.setShowDetailsDialog,
|
||||
@@ -188,6 +192,8 @@ export const App = () => {
|
||||
return (
|
||||
<div className="max-w-5xl mx-auto p-6 h-full overflow-hidden flex flex-col relative">
|
||||
<ExportDialog />
|
||||
<RouterGroupDialog />
|
||||
<ProxyStatusDialog />
|
||||
{loading && <div className="text-center text-gray-500 mb-4">加载中...</div>}
|
||||
{store.showFilter && (
|
||||
<div className="mb-3 animate-in fade-in slide-in-from-top-2 duration-300">
|
||||
@@ -363,7 +369,27 @@ export const App = () => {
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className='h-12 absolute bottom-0 left-0 right-0 bg-white border-t border-gray-200 flex items-center justify-end px-4'>
|
||||
<div className='h-12 absolute bottom-0 left-0 right-0 bg-white border-t border-gray-200 flex items-center justify-end px-4 gap-2'>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
store.setShowProxyStatus(true);
|
||||
}}
|
||||
className="gap-2"
|
||||
title="Proxy 状态"
|
||||
>
|
||||
<Activity size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
store.setShowRouterGroup(true);
|
||||
}}
|
||||
className="gap-2"
|
||||
title="路由分组"
|
||||
>
|
||||
<FolderClosed size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
@@ -377,4 +403,4 @@ export const App = () => {
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ import { use } from '@kevisual/context'
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { app } from '@/agents'
|
||||
import { cloneDeep } from 'es-toolkit'
|
||||
import { nanoid } from 'nanoid';
|
||||
import { nanoid, customAlphabet } from 'nanoid';
|
||||
import { Result } from '@kevisual/query';
|
||||
const letterAndNumber = 'abcdefghijklmnopqrstuvwxy';
|
||||
const nanoid8 = customAlphabet(letterAndNumber, 8);
|
||||
const historyReplace = (url: string) => {
|
||||
if (window.history.replaceState) {
|
||||
window.history.replaceState(null, '', url);
|
||||
@@ -42,6 +44,8 @@ interface StudioState {
|
||||
setLoading: (loading: boolean) => void;
|
||||
routes: Array<RouteItem>;
|
||||
searchRoutes: (keyword: string) => Promise<void>;
|
||||
allRoutes: Array<RouteItem>;
|
||||
getAllRoutes: () => Promise<void>;
|
||||
run: (route: RouteItem, type?: 'normal' | 'custom') => Promise<void>;
|
||||
queryProxy?: QueryProxy;
|
||||
init: (force?: boolean) => Promise<{ queryProxy: QueryProxy }>;
|
||||
@@ -72,6 +76,11 @@ interface StudioState {
|
||||
setExportRoutes: (routes?: RouteItem[]) => void;
|
||||
showApiDocs: boolean;
|
||||
setShowApiDocs: (show: boolean) => void;
|
||||
showRouterGroup: boolean;
|
||||
setShowRouterGroup: (show: boolean) => void;
|
||||
showProxyStatus: boolean;
|
||||
setShowProxyStatus: (show: boolean) => void;
|
||||
getQueryProxyStatus: () => Promise<RouterViewItem[]>;
|
||||
}
|
||||
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
export const filterRouteInfo = (viewData: RouterViewItem) => {
|
||||
@@ -108,6 +117,12 @@ export const useStudioStore = create<StudioState>()(
|
||||
const routes: any[] = await queryProxy.listRoutes(() => true, { query: keyword });
|
||||
set({ routes, searchKeyword: keyword });
|
||||
},
|
||||
allRoutes: [],
|
||||
getAllRoutes: async () => {
|
||||
let queryProxy = get().queryProxy!;
|
||||
const routes: any[] = await queryProxy.listRoutes(() => true);
|
||||
set({ allRoutes: routes });
|
||||
},
|
||||
searchKeyword: '',
|
||||
setSearchKeyword: (keyword: string) => set({ searchKeyword: keyword }),
|
||||
currentView: undefined,
|
||||
@@ -337,6 +352,20 @@ export const useStudioStore = create<StudioState>()(
|
||||
setExportRoutes: (routes?: RouteItem[]) => set({ exportRoutes: routes }),
|
||||
showApiDocs: false,
|
||||
setShowApiDocs: (show: boolean) => set({ showApiDocs: show }),
|
||||
showRouterGroup: false,
|
||||
setShowRouterGroup: (show: boolean) => set({ showRouterGroup: show }),
|
||||
showProxyStatus: false,
|
||||
setShowProxyStatus: (show: boolean) => set({ showProxyStatus: show }),
|
||||
getQueryProxyStatus: async () => {
|
||||
let queryProxy = get().queryProxy!;
|
||||
const status = queryProxy.routerViewItems.map(item => {
|
||||
return {
|
||||
id: item.id || nanoid8(),
|
||||
...item,
|
||||
}
|
||||
})
|
||||
return status;
|
||||
}
|
||||
}),
|
||||
{
|
||||
name: 'studio-storage',
|
||||
|
||||
@@ -206,8 +206,8 @@ export const ViewList = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full h-full max-w-4xl p-4 border border-gray-200 rounded-md shadow-sm">
|
||||
<div className="flex items-center space-x-2 mb-4">
|
||||
<div className="w-full h-full max-w-4xl py-4 border border-gray-200 rounded-md shadow-sm overflow-hidden">
|
||||
<div className="flex items-center px-4 space-x-2 mb-4">
|
||||
<Button onClick={() => store.setShowApiDocs(true)} title='文档' variant="outline" size="icon" className="h-8 w-8 cursor-pointer border-gray-300">
|
||||
<Book size={16} />
|
||||
</Button>
|
||||
@@ -228,7 +228,7 @@ export const ViewList = () => {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col">
|
||||
<div className="flex flex-col px-4 overscroll-auto scrollbar" style={{ height: 'calc(100% - 32px)' }}>
|
||||
{filteredViews.length === 0 ? (
|
||||
<div className="text-center py-4 text-gray-500">
|
||||
{searchTerm ? '未找到匹配的视图' : '暂无视图'}
|
||||
|
||||
Reference in New Issue
Block a user