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,282 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps, ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
import { Button } from "@/components/ui/button";
|
|
6
|
+
import {
|
|
7
|
+
Collapsible,
|
|
8
|
+
CollapsibleContent,
|
|
9
|
+
CollapsibleTrigger,
|
|
10
|
+
} from "@/components/ui/collapsible";
|
|
11
|
+
import { Input } from "@/components/ui/input";
|
|
12
|
+
import {
|
|
13
|
+
Tooltip,
|
|
14
|
+
TooltipContent,
|
|
15
|
+
TooltipProvider,
|
|
16
|
+
TooltipTrigger,
|
|
17
|
+
} from "@/components/ui/tooltip";
|
|
18
|
+
import { cn } from "@/lib/utils";
|
|
19
|
+
import { ChevronDownIcon } from "lucide-react";
|
|
20
|
+
import {
|
|
21
|
+
createContext,
|
|
22
|
+
useCallback,
|
|
23
|
+
useContext,
|
|
24
|
+
useMemo,
|
|
25
|
+
useState,
|
|
26
|
+
} from "react";
|
|
27
|
+
|
|
28
|
+
export interface WebPreviewContextValue {
|
|
29
|
+
url: string;
|
|
30
|
+
setUrl: (url: string) => void;
|
|
31
|
+
consoleOpen: boolean;
|
|
32
|
+
setConsoleOpen: (open: boolean) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const WebPreviewContext = createContext<WebPreviewContextValue | null>(null);
|
|
36
|
+
|
|
37
|
+
const useWebPreview = () => {
|
|
38
|
+
const context = useContext(WebPreviewContext);
|
|
39
|
+
if (!context) {
|
|
40
|
+
throw new Error("WebPreview components must be used within a WebPreview");
|
|
41
|
+
}
|
|
42
|
+
return context;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type WebPreviewProps = ComponentProps<"div"> & {
|
|
46
|
+
defaultUrl?: string;
|
|
47
|
+
onUrlChange?: (url: string) => void;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const WebPreview = ({
|
|
51
|
+
className,
|
|
52
|
+
children,
|
|
53
|
+
defaultUrl = "",
|
|
54
|
+
onUrlChange,
|
|
55
|
+
...props
|
|
56
|
+
}: WebPreviewProps) => {
|
|
57
|
+
const [url, setUrl] = useState(defaultUrl);
|
|
58
|
+
const [consoleOpen, setConsoleOpen] = useState(false);
|
|
59
|
+
|
|
60
|
+
const handleUrlChange = useCallback(
|
|
61
|
+
(newUrl: string) => {
|
|
62
|
+
setUrl(newUrl);
|
|
63
|
+
onUrlChange?.(newUrl);
|
|
64
|
+
},
|
|
65
|
+
[onUrlChange]
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const contextValue = useMemo<WebPreviewContextValue>(
|
|
69
|
+
() => ({
|
|
70
|
+
consoleOpen,
|
|
71
|
+
setConsoleOpen,
|
|
72
|
+
setUrl: handleUrlChange,
|
|
73
|
+
url,
|
|
74
|
+
}),
|
|
75
|
+
[consoleOpen, handleUrlChange, url]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<WebPreviewContext.Provider value={contextValue}>
|
|
80
|
+
<div
|
|
81
|
+
className={cn(
|
|
82
|
+
"flex size-full flex-col rounded-lg border bg-card",
|
|
83
|
+
className
|
|
84
|
+
)}
|
|
85
|
+
{...props}
|
|
86
|
+
>
|
|
87
|
+
{children}
|
|
88
|
+
</div>
|
|
89
|
+
</WebPreviewContext.Provider>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export type WebPreviewNavigationProps = ComponentProps<"div">;
|
|
94
|
+
|
|
95
|
+
export const WebPreviewNavigation = ({
|
|
96
|
+
className,
|
|
97
|
+
children,
|
|
98
|
+
...props
|
|
99
|
+
}: WebPreviewNavigationProps) => (
|
|
100
|
+
<div
|
|
101
|
+
className={cn("flex items-center gap-1 border-b p-2", className)}
|
|
102
|
+
{...props}
|
|
103
|
+
>
|
|
104
|
+
{children}
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
export type WebPreviewNavigationButtonProps = ComponentProps<typeof Button> & {
|
|
109
|
+
tooltip?: string;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const WebPreviewNavigationButton = ({
|
|
113
|
+
onClick,
|
|
114
|
+
disabled,
|
|
115
|
+
tooltip,
|
|
116
|
+
children,
|
|
117
|
+
...props
|
|
118
|
+
}: WebPreviewNavigationButtonProps) => (
|
|
119
|
+
<TooltipProvider>
|
|
120
|
+
<Tooltip>
|
|
121
|
+
<TooltipTrigger asChild>
|
|
122
|
+
<Button
|
|
123
|
+
className="h-8 w-8 p-0 hover:text-foreground"
|
|
124
|
+
disabled={disabled}
|
|
125
|
+
onClick={onClick}
|
|
126
|
+
size="sm"
|
|
127
|
+
variant="ghost"
|
|
128
|
+
{...props}
|
|
129
|
+
>
|
|
130
|
+
{children}
|
|
131
|
+
</Button>
|
|
132
|
+
</TooltipTrigger>
|
|
133
|
+
<TooltipContent>
|
|
134
|
+
<p>{tooltip}</p>
|
|
135
|
+
</TooltipContent>
|
|
136
|
+
</Tooltip>
|
|
137
|
+
</TooltipProvider>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
export type WebPreviewUrlProps = ComponentProps<typeof Input>;
|
|
141
|
+
|
|
142
|
+
export const WebPreviewUrl = ({
|
|
143
|
+
value,
|
|
144
|
+
onChange,
|
|
145
|
+
onKeyDown,
|
|
146
|
+
...props
|
|
147
|
+
}: WebPreviewUrlProps) => {
|
|
148
|
+
const { url, setUrl } = useWebPreview();
|
|
149
|
+
const [prevUrl, setPrevUrl] = useState(url);
|
|
150
|
+
const [inputValue, setInputValue] = useState(url);
|
|
151
|
+
|
|
152
|
+
// Sync input value with context URL when it changes externally (derived state pattern)
|
|
153
|
+
if (url !== prevUrl) {
|
|
154
|
+
setPrevUrl(url);
|
|
155
|
+
setInputValue(url);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
159
|
+
setInputValue(event.target.value);
|
|
160
|
+
onChange?.(event);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const handleKeyDown = useCallback(
|
|
164
|
+
(event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
165
|
+
if (event.key === "Enter") {
|
|
166
|
+
const target = event.target as HTMLInputElement;
|
|
167
|
+
setUrl(target.value);
|
|
168
|
+
}
|
|
169
|
+
onKeyDown?.(event);
|
|
170
|
+
},
|
|
171
|
+
[setUrl, onKeyDown]
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<Input
|
|
176
|
+
className="h-8 flex-1 text-sm"
|
|
177
|
+
onChange={onChange ?? handleChange}
|
|
178
|
+
onKeyDown={handleKeyDown}
|
|
179
|
+
placeholder="Enter URL..."
|
|
180
|
+
value={value ?? inputValue}
|
|
181
|
+
{...props}
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export type WebPreviewBodyProps = ComponentProps<"iframe"> & {
|
|
187
|
+
loading?: ReactNode;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export const WebPreviewBody = ({
|
|
191
|
+
className,
|
|
192
|
+
loading,
|
|
193
|
+
src,
|
|
194
|
+
...props
|
|
195
|
+
}: WebPreviewBodyProps) => {
|
|
196
|
+
const { url } = useWebPreview();
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<div className="flex-1">
|
|
200
|
+
<iframe
|
|
201
|
+
className={cn("size-full", className)}
|
|
202
|
+
// oxlint-disable-next-line eslint-plugin-react(iframe-missing-sandbox)
|
|
203
|
+
sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-presentation"
|
|
204
|
+
src={(src ?? url) || undefined}
|
|
205
|
+
title="Preview"
|
|
206
|
+
{...props}
|
|
207
|
+
/>
|
|
208
|
+
{loading}
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export type WebPreviewConsoleProps = ComponentProps<"div"> & {
|
|
214
|
+
logs?: {
|
|
215
|
+
level: "log" | "warn" | "error";
|
|
216
|
+
message: string;
|
|
217
|
+
timestamp: Date;
|
|
218
|
+
}[];
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export const WebPreviewConsole = ({
|
|
222
|
+
className,
|
|
223
|
+
logs = [],
|
|
224
|
+
children,
|
|
225
|
+
...props
|
|
226
|
+
}: WebPreviewConsoleProps) => {
|
|
227
|
+
const { consoleOpen, setConsoleOpen } = useWebPreview();
|
|
228
|
+
|
|
229
|
+
return (
|
|
230
|
+
<Collapsible
|
|
231
|
+
className={cn("border-t bg-muted/50 font-mono text-sm", className)}
|
|
232
|
+
onOpenChange={setConsoleOpen}
|
|
233
|
+
open={consoleOpen}
|
|
234
|
+
{...props}
|
|
235
|
+
>
|
|
236
|
+
<CollapsibleTrigger asChild>
|
|
237
|
+
<Button
|
|
238
|
+
className="flex w-full items-center justify-between p-4 text-left font-medium hover:bg-muted/50"
|
|
239
|
+
variant="ghost"
|
|
240
|
+
>
|
|
241
|
+
Console
|
|
242
|
+
<ChevronDownIcon
|
|
243
|
+
className={cn(
|
|
244
|
+
"h-4 w-4 transition-transform duration-200",
|
|
245
|
+
consoleOpen && "rotate-180"
|
|
246
|
+
)}
|
|
247
|
+
/>
|
|
248
|
+
</Button>
|
|
249
|
+
</CollapsibleTrigger>
|
|
250
|
+
<CollapsibleContent
|
|
251
|
+
className={cn(
|
|
252
|
+
"px-4 pb-4",
|
|
253
|
+
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 outline-none data-[state=closed]:animate-out data-[state=open]:animate-in"
|
|
254
|
+
)}
|
|
255
|
+
>
|
|
256
|
+
<div className="max-h-48 space-y-1 overflow-y-auto">
|
|
257
|
+
{logs.length === 0 ? (
|
|
258
|
+
<p className="text-muted-foreground">No console output</p>
|
|
259
|
+
) : (
|
|
260
|
+
logs.map((log, index) => (
|
|
261
|
+
<div
|
|
262
|
+
className={cn(
|
|
263
|
+
"text-xs",
|
|
264
|
+
log.level === "error" && "text-destructive",
|
|
265
|
+
log.level === "warn" && "text-yellow-600",
|
|
266
|
+
log.level === "log" && "text-foreground"
|
|
267
|
+
)}
|
|
268
|
+
key={`${log.timestamp.getTime()}-${index}`}
|
|
269
|
+
>
|
|
270
|
+
<span className="text-muted-foreground">
|
|
271
|
+
{log.timestamp.toLocaleTimeString()}
|
|
272
|
+
</span>{" "}
|
|
273
|
+
{log.message}
|
|
274
|
+
</div>
|
|
275
|
+
))
|
|
276
|
+
)}
|
|
277
|
+
{children}
|
|
278
|
+
</div>
|
|
279
|
+
</CollapsibleContent>
|
|
280
|
+
</Collapsible>
|
|
281
|
+
);
|
|
282
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import { CheckCircle2, XCircle } from 'lucide-react';
|
|
5
|
+
import type { AuditLog } from '@/lib/db';
|
|
6
|
+
import { Badge } from '@/components/ui/badge';
|
|
7
|
+
|
|
8
|
+
export function AuditLogList() {
|
|
9
|
+
const [logs, setLogs] = useState<AuditLog[]>([]);
|
|
10
|
+
const [loading, setLoading] = useState(true);
|
|
11
|
+
const [error, setError] = useState<string | null>(null);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
async function fetchLogs() {
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch('/api/audit?limit=50');
|
|
17
|
+
if (!response.ok) throw new Error('获取审计日志失败');
|
|
18
|
+
|
|
19
|
+
const data = await response.json();
|
|
20
|
+
setLogs(data.logs);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
setError(err instanceof Error ? err.message : '未知错误');
|
|
23
|
+
} finally {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fetchLogs();
|
|
29
|
+
}, []);
|
|
30
|
+
|
|
31
|
+
if (loading) {
|
|
32
|
+
return (
|
|
33
|
+
<div className="flex items-center justify-center py-12">
|
|
34
|
+
<div className="flex flex-col items-center gap-4">
|
|
35
|
+
<div className="w-8 h-8 border-4 border-primary border-t-transparent rounded-full animate-spin"></div>
|
|
36
|
+
<p className="text-muted-foreground">加载中...</p>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (error) {
|
|
43
|
+
return (
|
|
44
|
+
<div className="bg-destructive/10 border border-destructive/20 rounded-lg p-4">
|
|
45
|
+
<p className="text-destructive text-sm">错误: {error}</p>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (logs.length === 0) {
|
|
51
|
+
return (
|
|
52
|
+
<div className="text-center py-12">
|
|
53
|
+
<div className="text-5xl mb-3">📭</div>
|
|
54
|
+
<p className="text-muted-foreground">暂无审计日志</p>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className="divide-y divide-border">
|
|
61
|
+
{logs.map((log) => (
|
|
62
|
+
<div key={log.id} className="p-4 hover:bg-muted/50 transition-colors">
|
|
63
|
+
<div className="flex items-start gap-4">
|
|
64
|
+
<div className="mt-1 flex-shrink-0">
|
|
65
|
+
{log.status === 'success' ? (
|
|
66
|
+
<CheckCircle2 className="h-5 w-5 text-green-600" />
|
|
67
|
+
) : (
|
|
68
|
+
<XCircle className="h-5 w-5 text-destructive" />
|
|
69
|
+
)}
|
|
70
|
+
</div>
|
|
71
|
+
<div className="flex-1 min-w-0">
|
|
72
|
+
<div className="flex items-center gap-3 mb-1 flex-wrap">
|
|
73
|
+
<span className="font-medium">{log.action}</span>
|
|
74
|
+
<span className="text-xs text-muted-foreground">
|
|
75
|
+
{new Date(log.timestamp).toLocaleString('zh-CN')}
|
|
76
|
+
</span>
|
|
77
|
+
<StatusBadge status={log.status} />
|
|
78
|
+
</div>
|
|
79
|
+
<p className="text-sm text-muted-foreground">
|
|
80
|
+
操作人: <span className="font-medium text-foreground">{log.userId}</span>
|
|
81
|
+
{log.ticketId && ` • 工单: ${log.ticketId}`}
|
|
82
|
+
</p>
|
|
83
|
+
{(() => {
|
|
84
|
+
const details = log.details;
|
|
85
|
+
if (details && typeof details === 'object' && Object.keys(details).length > 0) {
|
|
86
|
+
return (
|
|
87
|
+
<details className="mt-2 group">
|
|
88
|
+
<summary className="text-xs text-muted-foreground cursor-pointer hover:text-foreground list-none">
|
|
89
|
+
<span className="inline-flex items-center gap-1">
|
|
90
|
+
<span className="group-hover:underline">详情</span>
|
|
91
|
+
</span>
|
|
92
|
+
</summary>
|
|
93
|
+
<pre className="mt-2 text-xs bg-muted p-3 rounded overflow-x-auto text-foreground">
|
|
94
|
+
{JSON.stringify(details, null, 2)}
|
|
95
|
+
</pre>
|
|
96
|
+
</details>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
})()}
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
))}
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function StatusBadge({ status }: { status: string }) {
|
|
110
|
+
if (status === 'success') {
|
|
111
|
+
return <Badge variant="default" className="bg-green-600 hover:bg-green-700">成功</Badge>;
|
|
112
|
+
}
|
|
113
|
+
return <Badge variant="destructive">失败</Badge>;
|
|
114
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { BookOpen } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
export function EmptyPreviewState() {
|
|
6
|
+
return (
|
|
7
|
+
<div className="h-full flex flex-col items-center justify-center text-gray-400">
|
|
8
|
+
<BookOpen className="w-16 h-16 mb-4" />
|
|
9
|
+
<p className="text-sm">点击左侧知识条目预览内容</p>
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
}
|