work-agent 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -0
- package/app/(admin)/approvals/page.tsx +16 -0
- package/app/(admin)/audit/page.tsx +18 -0
- package/app/(admin)/layout.tsx +47 -0
- package/app/(admin)/scheduled-tasks/page.tsx +17 -0
- package/app/(admin)/settings/page.tsx +46 -0
- package/app/(admin)/skills/[name]/page.tsx +378 -0
- package/app/(admin)/skills/page.tsx +406 -0
- package/app/(admin)/statistics/page.tsx +416 -0
- package/app/(admin)/tickets/[id]/page.tsx +348 -0
- package/app/(admin)/tickets/new/page.tsx +309 -0
- package/app/(admin)/tickets/page.tsx +27 -0
- package/app/api/audit/route.ts +30 -0
- package/app/api/auth/feishu/callback/route.ts +72 -0
- package/app/api/auth/feishu/login/route.ts +17 -0
- package/app/api/auth/feishu/sso/route.ts +78 -0
- package/app/api/auth/login/route.ts +85 -0
- package/app/api/auth/oauth/route.ts +168 -0
- package/app/api/config/providers/route.ts +105 -0
- package/app/api/config/route.ts +115 -0
- package/app/api/config/status/route.ts +56 -0
- package/app/api/config/test/route.ts +212 -0
- package/app/api/documents/[id]/route.ts +88 -0
- package/app/api/documents/route.ts +53 -0
- package/app/api/health/route.ts +32 -0
- package/app/api/knowledge/[id]/route.ts +152 -0
- package/app/api/knowledge/from-session/route.ts +27 -0
- package/app/api/knowledge/route.ts +100 -0
- package/app/api/market/knowledge/[id]/route.ts +92 -0
- package/app/api/market/knowledge/route.ts +130 -0
- package/app/api/marketplace/skills/[id]/approve/route.ts +68 -0
- package/app/api/marketplace/skills/[id]/certify/route.ts +54 -0
- package/app/api/marketplace/skills/[id]/install/route.ts +180 -0
- package/app/api/marketplace/skills/[id]/promote-to-system/route.ts +219 -0
- package/app/api/marketplace/skills/[id]/rate/route.ts +90 -0
- package/app/api/marketplace/skills/[id]/ratings/route.ts +55 -0
- package/app/api/marketplace/skills/[id]/reject/route.ts +68 -0
- package/app/api/marketplace/skills/[id]/route.ts +177 -0
- package/app/api/marketplace/skills/route.ts +235 -0
- package/app/api/memory/route.ts +40 -0
- package/app/api/my/files/[id]/route.ts +52 -0
- package/app/api/my/files/route.ts +230 -0
- package/app/api/my/knowledge/route.ts +36 -0
- package/app/api/pi-chat/route.ts +443 -0
- package/app/api/recommend/route.ts +38 -0
- package/app/api/scheduled-tasks/[id]/execute/route.ts +132 -0
- package/app/api/scheduled-tasks/[id]/route.ts +165 -0
- package/app/api/scheduled-tasks/[id]/toggle/route.ts +53 -0
- package/app/api/scheduled-tasks/route.ts +101 -0
- package/app/api/sessions/[id]/messages/route.ts +212 -0
- package/app/api/sessions/route.ts +101 -0
- package/app/api/share/file/[id]/route.ts +37 -0
- package/app/api/skills/[name]/execute/route.ts +121 -0
- package/app/api/skills/[name]/route.ts +167 -0
- package/app/api/skills/create/route.ts +65 -0
- package/app/api/skills/generate/route.ts +405 -0
- package/app/api/skills/installed/route.ts +151 -0
- package/app/api/skills/route.ts +174 -0
- package/app/api/skills/translate/route.ts +40 -0
- package/app/api/skills/user/[name]/route.ts +159 -0
- package/app/api/skills/user/route.ts +90 -0
- package/app/api/statistics/route.ts +94 -0
- package/app/api/task-executions/[id]/route.ts +34 -0
- package/app/api/task-executions/route.ts +29 -0
- package/app/api/tickets/[id]/approve/route.ts +129 -0
- package/app/api/tickets/[id]/execute/route.ts +201 -0
- package/app/api/tickets/[id]/route.ts +127 -0
- package/app/api/tickets/route.ts +103 -0
- package/app/api/user/skills/route.ts +175 -0
- package/app/api/users/route.ts +80 -0
- package/app/chat/page.tsx +5 -0
- package/app/globals.css +84 -0
- package/app/h5/layout.tsx +5 -0
- package/app/h5/mobile-approvals-page.tsx +167 -0
- package/app/h5/mobile-chat-page.tsx +951 -0
- package/app/h5/mobile-profile-page.tsx +147 -0
- package/app/h5/mobile-tickets-page.tsx +121 -0
- package/app/h5/page.tsx +23 -0
- package/app/h5/ticket-action-buttons.tsx +80 -0
- package/app/layout.tsx +26 -0
- package/app/login/page.tsx +318 -0
- package/app/market/knowledge/[id]/page.tsx +77 -0
- package/app/market/knowledge/page.tsx +358 -0
- package/app/market/layout.tsx +29 -0
- package/app/market/page.tsx +18 -0
- package/app/market/skills/page.tsx +397 -0
- package/app/my/files/page.tsx +511 -0
- package/app/my/knowledge/[id]/page.tsx +271 -0
- package/app/my/knowledge/new/page.tsx +234 -0
- package/app/my/knowledge/page.tsx +248 -0
- package/app/my/layout.tsx +32 -0
- package/app/my/memory/page.tsx +164 -0
- package/app/my/page.tsx +18 -0
- package/app/my/scheduled-tasks/[id]/edit/page.tsx +290 -0
- package/app/my/scheduled-tasks/[id]/executions/page.tsx +275 -0
- package/app/my/scheduled-tasks/[id]/page.tsx +284 -0
- package/app/my/scheduled-tasks/new/page.tsx +230 -0
- package/app/my/scheduled-tasks/page.tsx +27 -0
- package/app/my/skills/[name]/page.tsx +320 -0
- package/app/my/skills/new/page.tsx +394 -0
- package/app/my/skills/page.tsx +303 -0
- package/app/page.tsx +2288 -0
- package/app/share/[sessionId]/page.tsx +226 -0
- package/app/share/file/[id]/page.tsx +140 -0
- package/bin/README.md +63 -0
- package/bin/generate-api-system +300 -0
- package/bin/postinstall.js +95 -0
- package/bin/work-agent.js +173 -0
- package/components/ai-elements/agent.tsx +142 -0
- package/components/ai-elements/artifact.tsx +149 -0
- package/components/ai-elements/attachments.tsx +427 -0
- package/components/ai-elements/audio-player.tsx +232 -0
- package/components/ai-elements/canvas.tsx +26 -0
- package/components/ai-elements/chain-of-thought.tsx +223 -0
- package/components/ai-elements/checkpoint.tsx +72 -0
- package/components/ai-elements/code-block.tsx +555 -0
- package/components/ai-elements/commit.tsx +449 -0
- package/components/ai-elements/confirmation.tsx +173 -0
- package/components/ai-elements/connection.tsx +28 -0
- package/components/ai-elements/context.tsx +410 -0
- package/components/ai-elements/controls.tsx +19 -0
- package/components/ai-elements/conversation.tsx +167 -0
- package/components/ai-elements/edge.tsx +144 -0
- package/components/ai-elements/environment-variables.tsx +325 -0
- package/components/ai-elements/file-tree.tsx +298 -0
- package/components/ai-elements/image.tsx +25 -0
- package/components/ai-elements/inline-citation.tsx +294 -0
- package/components/ai-elements/jsx-preview.tsx +250 -0
- package/components/ai-elements/message.tsx +367 -0
- package/components/ai-elements/mic-selector.tsx +372 -0
- package/components/ai-elements/model-selector.tsx +214 -0
- package/components/ai-elements/node.tsx +72 -0
- package/components/ai-elements/open-in-chat.tsx +367 -0
- package/components/ai-elements/package-info.tsx +235 -0
- package/components/ai-elements/panel.tsx +16 -0
- package/components/ai-elements/persona.tsx +280 -0
- package/components/ai-elements/plan.tsx +144 -0
- package/components/ai-elements/prompt-input.tsx +1341 -0
- package/components/ai-elements/queue.tsx +275 -0
- package/components/ai-elements/reasoning.tsx +355 -0
- package/components/ai-elements/sandbox.tsx +133 -0
- package/components/ai-elements/schema-display.tsx +473 -0
- package/components/ai-elements/shimmer.tsx +78 -0
- package/components/ai-elements/snippet.tsx +141 -0
- package/components/ai-elements/sources.tsx +78 -0
- package/components/ai-elements/speech-input.tsx +324 -0
- package/components/ai-elements/stack-trace.tsx +531 -0
- package/components/ai-elements/suggestion.tsx +58 -0
- package/components/ai-elements/task.tsx +88 -0
- package/components/ai-elements/terminal.tsx +277 -0
- package/components/ai-elements/test-results.tsx +497 -0
- package/components/ai-elements/tool.tsx +174 -0
- package/components/ai-elements/toolbar.tsx +17 -0
- package/components/ai-elements/transcription.tsx +126 -0
- package/components/ai-elements/voice-selector.tsx +525 -0
- package/components/ai-elements/web-preview.tsx +282 -0
- package/components/audit-log-list.tsx +114 -0
- package/components/chat/EmptyPreviewState.tsx +12 -0
- package/components/chat/KnowledgePickerDialog.tsx +464 -0
- package/components/chat/KnowledgePreview.tsx +70 -0
- package/components/chat/KnowledgePreviewPanel.tsx +86 -0
- package/components/chat/MentionInput.tsx +309 -0
- package/components/chat/OrganizeDialog.tsx +258 -0
- package/components/chat/RecommendationBanner.tsx +94 -0
- package/components/chat/SaveToKnowledgeDialog.tsx +193 -0
- package/components/chat/SkillSelector.tsx +305 -0
- package/components/chat/SkillSwitcher.tsx +163 -0
- package/components/client-layout.tsx +15 -0
- package/components/knowledge/KnowledgeMetadataPanel.tsx +293 -0
- package/components/layout-wrapper.tsx +18 -0
- package/components/mobile-layout.tsx +62 -0
- package/components/scheduled-task-list.tsx +356 -0
- package/components/setup-guide.tsx +484 -0
- package/components/sub-nav.tsx +54 -0
- package/components/ticket-detail-content.tsx +383 -0
- package/components/ticket-list.tsx +366 -0
- package/components/top-nav.tsx +132 -0
- package/components/ui/accordion.tsx +58 -0
- package/components/ui/alert.tsx +59 -0
- package/components/ui/avatar.tsx +50 -0
- package/components/ui/badge.tsx +36 -0
- package/components/ui/button-group.tsx +83 -0
- package/components/ui/button.tsx +57 -0
- package/components/ui/card.tsx +91 -0
- package/components/ui/carousel.tsx +262 -0
- package/components/ui/collapsible.tsx +11 -0
- package/components/ui/command.tsx +153 -0
- package/components/ui/dialog.tsx +122 -0
- package/components/ui/dropdown-menu.tsx +200 -0
- package/components/ui/hover-card.tsx +29 -0
- package/components/ui/input-group.tsx +170 -0
- package/components/ui/input.tsx +22 -0
- package/components/ui/label.tsx +26 -0
- package/components/ui/popover.tsx +31 -0
- package/components/ui/progress.tsx +28 -0
- package/components/ui/scroll-area.tsx +48 -0
- package/components/ui/select.tsx +174 -0
- package/components/ui/separator.tsx +31 -0
- package/components/ui/spinner.tsx +16 -0
- package/components/ui/switch.tsx +29 -0
- package/components/ui/table.tsx +120 -0
- package/components/ui/tabs.tsx +55 -0
- package/components/ui/textarea.tsx +22 -0
- package/components/ui/tooltip.tsx +30 -0
- package/components/welcome-guide.tsx +182 -0
- package/components.json +24 -0
- package/lib/command-parser.ts +331 -0
- package/lib/dangerous-commands.ts +672 -0
- package/lib/db.ts +2250 -0
- package/lib/feishu-auth.ts +135 -0
- package/lib/file-storage.ts +306 -0
- package/lib/file-tool.ts +583 -0
- package/lib/knowledge-tool.ts +152 -0
- package/lib/knowledge-types.ts +66 -0
- package/lib/market-client.ts +313 -0
- package/lib/market-db.ts +736 -0
- package/lib/market-types.ts +51 -0
- package/lib/memory-tool.ts +211 -0
- package/lib/memory.ts +197 -0
- package/lib/pi-config.ts +436 -0
- package/lib/pi-session.ts +799 -0
- package/lib/pinyin.ts +13 -0
- package/lib/recommendation.ts +227 -0
- package/lib/risk-estimator.ts +350 -0
- package/lib/scheduled-task-tool.ts +184 -0
- package/lib/scheduler-init.ts +43 -0
- package/lib/scheduler.ts +416 -0
- package/lib/secure-bash-tool.ts +413 -0
- package/lib/skill-engine.ts +396 -0
- package/lib/skill-generator.ts +269 -0
- package/lib/skill-loader.ts +234 -0
- package/lib/skill-tool.ts +188 -0
- package/lib/skill-types.ts +82 -0
- package/lib/skills-init.ts +58 -0
- package/lib/ticket-tool.ts +246 -0
- package/lib/user-skill-types.ts +30 -0
- package/lib/user-skills.ts +362 -0
- package/lib/utils.ts +6 -0
- package/lib/workflow.ts +154 -0
- package/lib/zip-tool.ts +191 -0
- package/next.config.js +8 -0
- package/package.json +106 -0
- package/public/.gitkeep +1 -0
- package/public/icon.svg +1 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import Link from 'next/link';
|
|
5
|
+
import { useRouter } from 'next/navigation';
|
|
6
|
+
import {
|
|
7
|
+
Plus,
|
|
8
|
+
Search,
|
|
9
|
+
Star,
|
|
10
|
+
Download,
|
|
11
|
+
ArrowLeft,
|
|
12
|
+
Sparkles,
|
|
13
|
+
Bot,
|
|
14
|
+
Package,
|
|
15
|
+
Rocket,
|
|
16
|
+
Shield,
|
|
17
|
+
Loader2,
|
|
18
|
+
Trash2,
|
|
19
|
+
} from 'lucide-react';
|
|
20
|
+
import { Button } from '@/components/ui/button';
|
|
21
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
22
|
+
import { Badge } from '@/components/ui/badge';
|
|
23
|
+
import { Input } from '@/components/ui/input';
|
|
24
|
+
import { Alert, AlertDescription } from '@/components/ui/alert';
|
|
25
|
+
|
|
26
|
+
interface MarketSkill {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
displayName: string;
|
|
30
|
+
description: string;
|
|
31
|
+
version: string;
|
|
32
|
+
author: string;
|
|
33
|
+
authorName?: string;
|
|
34
|
+
status: 'pending' | 'approved' | 'rejected' | 'archived';
|
|
35
|
+
isOfficial: boolean;
|
|
36
|
+
ratingAvg: number;
|
|
37
|
+
ratingCount: number;
|
|
38
|
+
downloadCount: number;
|
|
39
|
+
reviewedBy?: string;
|
|
40
|
+
reviewedAt?: string;
|
|
41
|
+
reviewComment?: string;
|
|
42
|
+
createdAt: string;
|
|
43
|
+
updatedAt: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default function MarketPage() {
|
|
47
|
+
const router = useRouter();
|
|
48
|
+
const [skills, setSkills] = useState<MarketSkill[]>([]);
|
|
49
|
+
const [loading, setLoading] = useState(true);
|
|
50
|
+
const [search, setSearch] = useState('');
|
|
51
|
+
const [userId, setUserId] = useState<string>('');
|
|
52
|
+
const [userRole, setUserRole] = useState<'admin' | 'guest'>('guest');
|
|
53
|
+
const [installedSkills, setInstalledSkills] = useState<Set<string>>(new Set());
|
|
54
|
+
const [promotingSkillId, setPromotingSkillId] = useState<string | null>(null);
|
|
55
|
+
const [deletingSkillId, setDeletingSkillId] = useState<string | null>(null);
|
|
56
|
+
const [alertMessage, setAlertMessage] = useState<{ type: 'success' | 'error'; message: string } | null>(null);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const uid = localStorage.getItem('userId');
|
|
60
|
+
if (!uid) {
|
|
61
|
+
router.push('/login');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
setUserId(uid);
|
|
65
|
+
|
|
66
|
+
// Get user role from localStorage (stored as separate key by login page)
|
|
67
|
+
const role = localStorage.getItem('role') as 'admin' | 'guest' | null;
|
|
68
|
+
setUserRole(role || 'guest');
|
|
69
|
+
|
|
70
|
+
fetchSkills();
|
|
71
|
+
fetchInstalledSkills(uid);
|
|
72
|
+
}, [router]);
|
|
73
|
+
|
|
74
|
+
const fetchSkills = async () => {
|
|
75
|
+
try {
|
|
76
|
+
// Only show approved skills in the market
|
|
77
|
+
const res = await fetch(`/api/marketplace/skills?status=approved&search=${encodeURIComponent(search)}`);
|
|
78
|
+
if (res.ok) {
|
|
79
|
+
const data = await res.json();
|
|
80
|
+
setSkills(data.skills || []);
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('Failed to fetch skills:', error);
|
|
84
|
+
} finally {
|
|
85
|
+
setLoading(false);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const fetchInstalledSkills = async (uid: string) => {
|
|
90
|
+
try {
|
|
91
|
+
const res = await fetch(`/api/user/skills?userId=${uid}`);
|
|
92
|
+
if (res.ok) {
|
|
93
|
+
const data = await res.json();
|
|
94
|
+
setInstalledSkills(new Set((data.skills || []).map((s: any) => s.skillName)));
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('Failed to fetch installed skills:', error);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const handleSearch = (e: React.FormEvent) => {
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
setLoading(true);
|
|
104
|
+
fetchSkills();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const handleInstall = async (skillName: string) => {
|
|
108
|
+
if (!userId) return;
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const res = await fetch('/api/user/skills', {
|
|
112
|
+
method: 'POST',
|
|
113
|
+
headers: { 'Content-Type': 'application/json' },
|
|
114
|
+
body: JSON.stringify({
|
|
115
|
+
userId,
|
|
116
|
+
action: 'install',
|
|
117
|
+
skillName,
|
|
118
|
+
source: 'market',
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (res.ok) {
|
|
123
|
+
setInstalledSkills(prev => new Set([...prev, skillName]));
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error('Failed to install skill:', error);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const handleUninstall = async (skillName: string) => {
|
|
131
|
+
if (!userId) return;
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const res = await fetch('/api/user/skills', {
|
|
135
|
+
method: 'POST',
|
|
136
|
+
headers: { 'Content-Type': 'application/json' },
|
|
137
|
+
body: JSON.stringify({
|
|
138
|
+
userId,
|
|
139
|
+
action: 'uninstall',
|
|
140
|
+
skillName,
|
|
141
|
+
}),
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
if (res.ok) {
|
|
145
|
+
setInstalledSkills(prev => {
|
|
146
|
+
const next = new Set(prev);
|
|
147
|
+
next.delete(skillName);
|
|
148
|
+
return next;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error('Failed to uninstall skill:', error);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const handlePromoteToSystem = async (skillId: string, skillName: string) => {
|
|
157
|
+
if (!userId || userRole !== 'admin') {
|
|
158
|
+
setAlertMessage({ type: 'error', message: '需要管理员权限' });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
setPromotingSkillId(skillId);
|
|
163
|
+
setAlertMessage(null);
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
const res = await fetch(`/api/marketplace/skills/${skillId}/promote-to-system?userId=${userId}`, {
|
|
167
|
+
method: 'POST',
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (res.ok) {
|
|
171
|
+
const data = await res.json();
|
|
172
|
+
setAlertMessage({ type: 'success', message: data.message || '技能已提升为系统技能' });
|
|
173
|
+
// Refresh the skills list
|
|
174
|
+
fetchSkills();
|
|
175
|
+
} else {
|
|
176
|
+
const data = await res.json();
|
|
177
|
+
setAlertMessage({ type: 'error', message: data.error || '提升技能失败' });
|
|
178
|
+
}
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.error('Failed to promote skill:', error);
|
|
181
|
+
setAlertMessage({ type: 'error', message: '提升技能失败' });
|
|
182
|
+
} finally {
|
|
183
|
+
setPromotingSkillId(null);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const handleDelete = async (skillId: string, skillName: string) => {
|
|
188
|
+
if (!userId || userRole !== 'admin') {
|
|
189
|
+
setAlertMessage({ type: 'error', message: '需要管理员权限' });
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!confirm(`确定要删除技能 "${skillName}" 吗?此操作不可恢复。`)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
setDeletingSkillId(skillId);
|
|
198
|
+
setAlertMessage(null);
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
const res = await fetch(`/api/marketplace/skills/${skillId}?userId=${userId}&role=${userRole}`, {
|
|
202
|
+
method: 'DELETE',
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
if (res.ok) {
|
|
206
|
+
setAlertMessage({ type: 'success', message: '技能已删除' });
|
|
207
|
+
setSkills(prev => prev.filter(s => s.id !== skillId));
|
|
208
|
+
} else {
|
|
209
|
+
const data = await res.json();
|
|
210
|
+
setAlertMessage({ type: 'error', message: data.error || '删除技能失败' });
|
|
211
|
+
}
|
|
212
|
+
} catch (error) {
|
|
213
|
+
console.error('Failed to delete skill:', error);
|
|
214
|
+
setAlertMessage({ type: 'error', message: '删除技能失败' });
|
|
215
|
+
} finally {
|
|
216
|
+
setDeletingSkillId(null);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<div className="p-6">
|
|
222
|
+
<div className="flex items-center justify-between mb-6">
|
|
223
|
+
<div />
|
|
224
|
+
<div className="flex items-center gap-2">
|
|
225
|
+
<Link href="/my/skills">
|
|
226
|
+
<Button variant="outline" size="sm">
|
|
227
|
+
<Bot className="w-4 h-4 mr-2" />
|
|
228
|
+
我的Skill
|
|
229
|
+
</Button>
|
|
230
|
+
</Link>
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
|
|
234
|
+
{/* Alert Message */}
|
|
235
|
+
{alertMessage && (
|
|
236
|
+
<Alert
|
|
237
|
+
variant={alertMessage.type === 'error' ? 'destructive' : 'default'}
|
|
238
|
+
className="mb-4"
|
|
239
|
+
>
|
|
240
|
+
<AlertDescription>{alertMessage.message}</AlertDescription>
|
|
241
|
+
</Alert>
|
|
242
|
+
)}
|
|
243
|
+
|
|
244
|
+
{/* Search */}
|
|
245
|
+
<form onSubmit={handleSearch} className="mb-6">
|
|
246
|
+
<div className="flex gap-2">
|
|
247
|
+
<div className="relative flex-1">
|
|
248
|
+
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400" />
|
|
249
|
+
<Input
|
|
250
|
+
type="text"
|
|
251
|
+
placeholder="搜索Skill..."
|
|
252
|
+
value={search}
|
|
253
|
+
onChange={(e) => setSearch(e.target.value)}
|
|
254
|
+
className="pl-10"
|
|
255
|
+
/>
|
|
256
|
+
</div>
|
|
257
|
+
<Button type="submit">搜索</Button>
|
|
258
|
+
</div>
|
|
259
|
+
</form>
|
|
260
|
+
|
|
261
|
+
{/* Stats */}
|
|
262
|
+
<div className="grid grid-cols-3 gap-4 mb-6">
|
|
263
|
+
<Card>
|
|
264
|
+
<CardContent className="p-4">
|
|
265
|
+
<div className="text-2xl font-bold">{skills.length}</div>
|
|
266
|
+
<div className="text-sm text-gray-500">市场Skill</div>
|
|
267
|
+
</CardContent>
|
|
268
|
+
</Card>
|
|
269
|
+
<Card>
|
|
270
|
+
<CardContent className="p-4">
|
|
271
|
+
<div className="text-2xl font-bold">{installedSkills.size}</div>
|
|
272
|
+
<div className="text-sm text-gray-500">已安装</div>
|
|
273
|
+
</CardContent>
|
|
274
|
+
</Card>
|
|
275
|
+
<Card>
|
|
276
|
+
<CardContent className="p-4">
|
|
277
|
+
<div className="text-2xl font-bold">
|
|
278
|
+
{skills.reduce((sum, s) => sum + s.downloadCount, 0)}
|
|
279
|
+
</div>
|
|
280
|
+
<div className="text-sm text-gray-500">总下载</div>
|
|
281
|
+
</CardContent>
|
|
282
|
+
</Card>
|
|
283
|
+
</div>
|
|
284
|
+
|
|
285
|
+
{/* Skills Grid */}
|
|
286
|
+
{loading ? (
|
|
287
|
+
<div className="text-center py-12 text-gray-500">加载中...</div>
|
|
288
|
+
) : skills.length === 0 ? (
|
|
289
|
+
<div className="text-center py-12">
|
|
290
|
+
<Package className="w-12 h-12 mx-auto text-gray-300 mb-4" />
|
|
291
|
+
<p className="text-gray-500">暂无Skill</p>
|
|
292
|
+
</div>
|
|
293
|
+
) : (
|
|
294
|
+
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
|
295
|
+
{skills.map((skill) => (
|
|
296
|
+
<Card key={skill.id} className="hover:shadow-md transition-shadow">
|
|
297
|
+
<CardHeader className="pb-3">
|
|
298
|
+
<div className="flex items-start justify-between">
|
|
299
|
+
<div>
|
|
300
|
+
<CardTitle className="text-lg">{skill.displayName}</CardTitle>
|
|
301
|
+
<CardDescription className="text-xs mt-1">
|
|
302
|
+
by {skill.authorName || skill.author || '匿名'}
|
|
303
|
+
</CardDescription>
|
|
304
|
+
</div>
|
|
305
|
+
<div className="flex gap-1">
|
|
306
|
+
{skill.isOfficial && (
|
|
307
|
+
<Badge variant="secondary" className="text-xs">
|
|
308
|
+
<Shield className="w-3 h-3 mr-1" />
|
|
309
|
+
官方
|
|
310
|
+
</Badge>
|
|
311
|
+
)}
|
|
312
|
+
{skill.status === 'approved' && userRole === 'admin' && (
|
|
313
|
+
<Badge variant="outline" className="text-xs border-green-500 text-green-600">
|
|
314
|
+
已审核
|
|
315
|
+
</Badge>
|
|
316
|
+
)}
|
|
317
|
+
</div>
|
|
318
|
+
</div>
|
|
319
|
+
</CardHeader>
|
|
320
|
+
<CardContent>
|
|
321
|
+
<p className="text-sm text-gray-600 mb-4 line-clamp-2">
|
|
322
|
+
{skill.description || '暂无描述'}
|
|
323
|
+
</p>
|
|
324
|
+
|
|
325
|
+
<div className="flex items-center justify-between">
|
|
326
|
+
<div className="flex items-center gap-4 text-sm text-gray-500">
|
|
327
|
+
<span className="flex items-center gap-1">
|
|
328
|
+
<Download className="w-4 h-4" />
|
|
329
|
+
{skill.downloadCount}
|
|
330
|
+
</span>
|
|
331
|
+
<span className="flex items-center gap-1">
|
|
332
|
+
<Star className="w-4 h-4 text-yellow-500" />
|
|
333
|
+
{skill.ratingAvg > 0 ? skill.ratingAvg.toFixed(1) : '-'}
|
|
334
|
+
</span>
|
|
335
|
+
</div>
|
|
336
|
+
|
|
337
|
+
<div className="flex gap-2">
|
|
338
|
+
{/* Admin buttons for approved skills */}
|
|
339
|
+
{userRole === 'admin' && skill.status === 'approved' && (
|
|
340
|
+
<>
|
|
341
|
+
<Button
|
|
342
|
+
variant="outline"
|
|
343
|
+
size="sm"
|
|
344
|
+
className="text-purple-600 border-purple-600 hover:bg-purple-50"
|
|
345
|
+
onClick={() => handlePromoteToSystem(skill.id, skill.name)}
|
|
346
|
+
disabled={promotingSkillId === skill.id}
|
|
347
|
+
title="提升为系统技能"
|
|
348
|
+
>
|
|
349
|
+
{promotingSkillId === skill.id ? (
|
|
350
|
+
<Loader2 className="w-4 h-4 animate-spin" />
|
|
351
|
+
) : (
|
|
352
|
+
<Rocket className="w-4 h-4" />
|
|
353
|
+
)}
|
|
354
|
+
</Button>
|
|
355
|
+
<Button
|
|
356
|
+
variant="outline"
|
|
357
|
+
size="sm"
|
|
358
|
+
className="text-red-600 border-red-600 hover:bg-red-50"
|
|
359
|
+
onClick={() => handleDelete(skill.id, skill.name)}
|
|
360
|
+
disabled={deletingSkillId === skill.id}
|
|
361
|
+
title="删除技能"
|
|
362
|
+
>
|
|
363
|
+
{deletingSkillId === skill.id ? (
|
|
364
|
+
<Loader2 className="w-4 h-4 animate-spin" />
|
|
365
|
+
) : (
|
|
366
|
+
<Trash2 className="w-4 h-4" />
|
|
367
|
+
)}
|
|
368
|
+
</Button>
|
|
369
|
+
</>
|
|
370
|
+
)}
|
|
371
|
+
|
|
372
|
+
{installedSkills.has(skill.name) ? (
|
|
373
|
+
<Button
|
|
374
|
+
variant="outline"
|
|
375
|
+
size="sm"
|
|
376
|
+
onClick={() => handleUninstall(skill.name)}
|
|
377
|
+
>
|
|
378
|
+
已安装
|
|
379
|
+
</Button>
|
|
380
|
+
) : (
|
|
381
|
+
<Button
|
|
382
|
+
size="sm"
|
|
383
|
+
onClick={() => handleInstall(skill.name)}
|
|
384
|
+
>
|
|
385
|
+
安装
|
|
386
|
+
</Button>
|
|
387
|
+
)}
|
|
388
|
+
</div>
|
|
389
|
+
</div>
|
|
390
|
+
</CardContent>
|
|
391
|
+
</Card>
|
|
392
|
+
))}
|
|
393
|
+
</div>
|
|
394
|
+
)}
|
|
395
|
+
</div>
|
|
396
|
+
);
|
|
397
|
+
}
|