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,121 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { execSync } from 'child_process';
|
|
5
|
+
import { tmpdir } from 'os';
|
|
6
|
+
import { createTicket, createAuditLog } from '@/lib/db';
|
|
7
|
+
|
|
8
|
+
export async function POST(
|
|
9
|
+
request: NextRequest,
|
|
10
|
+
{ params }: { params: Promise<{ name: string }> }
|
|
11
|
+
) {
|
|
12
|
+
try {
|
|
13
|
+
const { name } = await params;
|
|
14
|
+
const body = await request.json();
|
|
15
|
+
const { scriptName, params: scriptParams } = body;
|
|
16
|
+
|
|
17
|
+
if (!scriptName) {
|
|
18
|
+
return NextResponse.json({ error: 'scriptName is required' }, { status: 400 });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const skillPath = join(process.cwd(), '.pi', 'skills', name);
|
|
22
|
+
const scriptPath = join(skillPath, 'scripts', scriptName);
|
|
23
|
+
|
|
24
|
+
if (!existsSync(scriptPath)) {
|
|
25
|
+
return NextResponse.json({ error: 'Script not found' }, { status: 404 });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let scriptContent;
|
|
29
|
+
try {
|
|
30
|
+
scriptContent = readFileSync(scriptPath, 'utf-8');
|
|
31
|
+
} catch {
|
|
32
|
+
return NextResponse.json({ error: 'Failed to read script' }, { status: 500 });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isModify = scriptContent.includes('分类: 修改操作') ||
|
|
36
|
+
scriptContent.includes('modify');
|
|
37
|
+
|
|
38
|
+
if (isModify) {
|
|
39
|
+
const ticket = await createTicket({
|
|
40
|
+
type: 'skill-script',
|
|
41
|
+
title: `执行 Skill 脚本: ${name}/${scriptName}`,
|
|
42
|
+
description: `修改操作需要审批\n\n脚本内容:\n\`\`\`bash\n${scriptContent.slice(0, 500)}\n\`\`\``,
|
|
43
|
+
status: 'pending',
|
|
44
|
+
priority: 'medium',
|
|
45
|
+
skillName: name,
|
|
46
|
+
scriptContent,
|
|
47
|
+
scriptPath: `scripts/${scriptName}`,
|
|
48
|
+
riskLevel: 'medium',
|
|
49
|
+
approvals: [],
|
|
50
|
+
createdBy: 'system',
|
|
51
|
+
aiSessionId: undefined,
|
|
52
|
+
aiGenerated: true,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await createAuditLog({
|
|
56
|
+
action: 'skill_script_execute_requested',
|
|
57
|
+
userId: 'system',
|
|
58
|
+
ticketId: ticket.id,
|
|
59
|
+
details: { skillName: name, scriptName, operationType: 'modify' },
|
|
60
|
+
status: 'success',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return NextResponse.json({
|
|
64
|
+
success: true,
|
|
65
|
+
requiresApproval: true,
|
|
66
|
+
ticketId: ticket.id,
|
|
67
|
+
message: '修改操作需要审批,已创建工单',
|
|
68
|
+
ticketUrl: `/tickets/${ticket.id}`,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const tempDir = join(tmpdir(), `skill-exec-${Date.now()}`);
|
|
73
|
+
mkdirSync(tempDir, { recursive: true });
|
|
74
|
+
const tempScriptPath = join(tempDir, scriptName);
|
|
75
|
+
|
|
76
|
+
writeFileSync(tempScriptPath, scriptContent);
|
|
77
|
+
execSync(`chmod +x "${tempScriptPath}"`);
|
|
78
|
+
|
|
79
|
+
let output = '';
|
|
80
|
+
let error = '';
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
output = execSync(`"${tempScriptPath}"`, {
|
|
84
|
+
encoding: 'utf-8',
|
|
85
|
+
timeout: 30000,
|
|
86
|
+
env: {
|
|
87
|
+
...process.env,
|
|
88
|
+
TOKEN: scriptParams?.token || '',
|
|
89
|
+
},
|
|
90
|
+
}).toString();
|
|
91
|
+
} catch (err: unknown) {
|
|
92
|
+
const execError = err as { stdout?: string; stderr?: string; message?: string };
|
|
93
|
+
error = execError?.stderr || execError?.message || String(err);
|
|
94
|
+
} finally {
|
|
95
|
+
rmSync(tempDir, { recursive: true });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
await createAuditLog({
|
|
99
|
+
action: 'skill_script_executed',
|
|
100
|
+
userId: 'system',
|
|
101
|
+
details: {
|
|
102
|
+
skillName: name,
|
|
103
|
+
scriptName,
|
|
104
|
+
operationType: 'read_only',
|
|
105
|
+
outputLength: output.length,
|
|
106
|
+
hasError: !!error,
|
|
107
|
+
},
|
|
108
|
+
status: error ? 'failure' : 'success',
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return NextResponse.json({
|
|
112
|
+
success: true,
|
|
113
|
+
requiresApproval: false,
|
|
114
|
+
output: output || error,
|
|
115
|
+
hasError: !!error,
|
|
116
|
+
});
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error('Error executing script:', error);
|
|
119
|
+
return NextResponse.json({ error: 'Failed to execute script' }, { status: 500 });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { existsSync, readFileSync, rmSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
5
|
+
export async function GET(
|
|
6
|
+
request: NextRequest,
|
|
7
|
+
{ params }: { params: Promise<{ name: string }> }
|
|
8
|
+
) {
|
|
9
|
+
try {
|
|
10
|
+
const { name } = await params;
|
|
11
|
+
const searchParams = request.nextUrl.searchParams;
|
|
12
|
+
const userId = searchParams.get('userId');
|
|
13
|
+
|
|
14
|
+
let skillPath = join(process.cwd(), '.pi', 'skills', name);
|
|
15
|
+
|
|
16
|
+
// 如果提供了 userId,先检查用户目录
|
|
17
|
+
if (userId) {
|
|
18
|
+
const userSkillPath = join(process.cwd(), 'data', 'skills', 'users', userId, name);
|
|
19
|
+
if (existsSync(userSkillPath)) {
|
|
20
|
+
skillPath = userSkillPath;
|
|
21
|
+
}
|
|
22
|
+
} else if (!existsSync(skillPath)) {
|
|
23
|
+
// 如果没有提供 userId 且系统目录没有,则返回 404
|
|
24
|
+
return NextResponse.json({ error: 'Skill not found' }, { status: 404 });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const jsonPath = join(skillPath, 'SKILL.json');
|
|
28
|
+
const mdPath = join(skillPath, 'SKILL.md');
|
|
29
|
+
const configPath = join(skillPath, 'config.yaml');
|
|
30
|
+
const scriptsDir = join(skillPath, 'scripts');
|
|
31
|
+
|
|
32
|
+
if (!existsSync(skillPath)) {
|
|
33
|
+
return NextResponse.json({ error: 'Skill not found' }, { status: 404 });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let metadata: Record<string, unknown> = {};
|
|
37
|
+
let readme = '';
|
|
38
|
+
let config: string | Record<string, unknown> = {};
|
|
39
|
+
const scripts: Array<{
|
|
40
|
+
name: string;
|
|
41
|
+
type: 'read_only' | 'modify';
|
|
42
|
+
description: string;
|
|
43
|
+
method: string;
|
|
44
|
+
path: string;
|
|
45
|
+
}> = [];
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const jsonContent = readFileSync(jsonPath, 'utf-8');
|
|
49
|
+
metadata = JSON.parse(jsonContent);
|
|
50
|
+
} catch {}
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
readme = readFileSync(mdPath, 'utf-8');
|
|
54
|
+
} catch {}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const yamlContent = readFileSync(configPath, 'utf-8');
|
|
58
|
+
try {
|
|
59
|
+
config = JSON.parse(yamlContent);
|
|
60
|
+
} catch {
|
|
61
|
+
config = yamlContent;
|
|
62
|
+
}
|
|
63
|
+
} catch {}
|
|
64
|
+
|
|
65
|
+
if (existsSync(scriptsDir)) {
|
|
66
|
+
const { readdirSync, statSync } = require('fs');
|
|
67
|
+
const files = readdirSync(scriptsDir).filter((f: string) => {
|
|
68
|
+
const fullPath = join(scriptsDir, f);
|
|
69
|
+
return statSync(fullPath).isFile() && !f.startsWith('.') && !f.endsWith('.sh');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
scripts.push(...files.map((file: string) => {
|
|
73
|
+
let type: 'read_only' | 'modify' = 'read_only';
|
|
74
|
+
let description = '';
|
|
75
|
+
let method = 'GET';
|
|
76
|
+
let path = '/';
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const content = readFileSync(join(scriptsDir, file), 'utf-8');
|
|
80
|
+
const lines = content.split('\n').slice(0, 10);
|
|
81
|
+
|
|
82
|
+
for (const line of lines) {
|
|
83
|
+
if (line.includes('分类:')) {
|
|
84
|
+
type = line.includes('只读操作') ? 'read_only' : 'modify';
|
|
85
|
+
}
|
|
86
|
+
if (line.includes('# ')) {
|
|
87
|
+
description = line.replace('# ', '').trim();
|
|
88
|
+
}
|
|
89
|
+
if (line.includes('API:')) {
|
|
90
|
+
const match = line.match(/(\w+)\s+(.*)/);
|
|
91
|
+
if (match) {
|
|
92
|
+
method = match[1];
|
|
93
|
+
path = match[2];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} catch {}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
name: file,
|
|
101
|
+
type,
|
|
102
|
+
description,
|
|
103
|
+
method,
|
|
104
|
+
path,
|
|
105
|
+
};
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const isBuiltIn = name === 'generate-api-system';
|
|
110
|
+
|
|
111
|
+
const isUserSkill = skillPath.includes('data/users');
|
|
112
|
+
const resultPath = isUserSkill
|
|
113
|
+
? skillPath.replace(process.cwd() + '/', '')
|
|
114
|
+
: `.pi/skills/${name}`;
|
|
115
|
+
|
|
116
|
+
return NextResponse.json({
|
|
117
|
+
...metadata,
|
|
118
|
+
readme,
|
|
119
|
+
config,
|
|
120
|
+
scripts,
|
|
121
|
+
isBuiltIn,
|
|
122
|
+
skillPath: resultPath,
|
|
123
|
+
});
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error('Error getting skill:', error);
|
|
126
|
+
return NextResponse.json({ error: 'Failed to get skill' }, { status: 500 });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function DELETE(
|
|
131
|
+
request: NextRequest,
|
|
132
|
+
{ params }: { params: Promise<{ name: string }> }
|
|
133
|
+
) {
|
|
134
|
+
try {
|
|
135
|
+
const { name } = await params;
|
|
136
|
+
const searchParams = request.nextUrl.searchParams;
|
|
137
|
+
const userId = searchParams.get('userId');
|
|
138
|
+
|
|
139
|
+
if (name === 'generate-api-system') {
|
|
140
|
+
return NextResponse.json({ error: 'Cannot delete built-in skill' }, { status: 403 });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 先检查内置技能目录
|
|
144
|
+
let skillPath = join(process.cwd(), '.pi', 'skills', name);
|
|
145
|
+
let isUserSkill = false;
|
|
146
|
+
|
|
147
|
+
// 如果内置技能不存在,或者提供了 userId,则检查用户私有技能目录
|
|
148
|
+
if (!existsSync(skillPath) || userId) {
|
|
149
|
+
const userSkillPath = join(process.cwd(), 'data', 'users', userId || '', 'skills', name);
|
|
150
|
+
if (existsSync(userSkillPath)) {
|
|
151
|
+
skillPath = userSkillPath;
|
|
152
|
+
isUserSkill = true;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!existsSync(skillPath)) {
|
|
157
|
+
return NextResponse.json({ error: 'Skill not found' }, { status: 404 });
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
rmSync(skillPath, { recursive: true });
|
|
161
|
+
|
|
162
|
+
return NextResponse.json({ success: true, message: `Skill '${name}' has been deleted` });
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error('Error deleting skill:', error);
|
|
165
|
+
return NextResponse.json({ error: 'Failed to delete skill' }, { status: 500 });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通用Skill创建API
|
|
3
|
+
*
|
|
4
|
+
* POST /api/skills/create
|
|
5
|
+
*
|
|
6
|
+
* 用于通过API创建通用skill(非Swagger生成)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
10
|
+
import { createSkill, detectSkillType } from '../../../../lib/skill-generator';
|
|
11
|
+
import type { CreateSkillRequest } from '../../../../lib/skill-types';
|
|
12
|
+
|
|
13
|
+
export async function POST(request: NextRequest) {
|
|
14
|
+
try {
|
|
15
|
+
const body = await request.json();
|
|
16
|
+
|
|
17
|
+
// 验证必填字段
|
|
18
|
+
if (!body.name) {
|
|
19
|
+
return NextResponse.json({
|
|
20
|
+
error: 'name is required'
|
|
21
|
+
}, { status: 400 });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!body.description) {
|
|
25
|
+
return NextResponse.json({
|
|
26
|
+
error: 'description is required'
|
|
27
|
+
}, { status: 400 });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 构建请求
|
|
31
|
+
const skillRequest: CreateSkillRequest = {
|
|
32
|
+
name: body.name,
|
|
33
|
+
displayName: body.displayName || body.name,
|
|
34
|
+
description: body.description,
|
|
35
|
+
type: body.type,
|
|
36
|
+
knowledge: body.knowledge,
|
|
37
|
+
commandPatterns: body.commandPatterns,
|
|
38
|
+
riskConfig: body.riskConfig,
|
|
39
|
+
examples: body.examples,
|
|
40
|
+
author: body.author,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// 创建skill
|
|
44
|
+
const result = await createSkill(skillRequest);
|
|
45
|
+
|
|
46
|
+
if (!result.success) {
|
|
47
|
+
return NextResponse.json({
|
|
48
|
+
error: result.error
|
|
49
|
+
}, { status: 409 }); // 409 Conflict - resource already exists
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return NextResponse.json({
|
|
53
|
+
success: true,
|
|
54
|
+
skillName: result.skillName,
|
|
55
|
+
type: result.type,
|
|
56
|
+
path: result.skillPath,
|
|
57
|
+
files: result.files,
|
|
58
|
+
});
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error('Error creating skill:', error);
|
|
61
|
+
return NextResponse.json({
|
|
62
|
+
error: 'Failed to create skill'
|
|
63
|
+
}, { status: 500 });
|
|
64
|
+
}
|
|
65
|
+
}
|