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,144 @@
|
|
|
1
|
+
import type { EdgeProps, InternalNode, Node } from "@xyflow/react";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BaseEdge,
|
|
5
|
+
getBezierPath,
|
|
6
|
+
getSimpleBezierPath,
|
|
7
|
+
Position,
|
|
8
|
+
useInternalNode,
|
|
9
|
+
} from "@xyflow/react";
|
|
10
|
+
|
|
11
|
+
const Temporary = ({
|
|
12
|
+
id,
|
|
13
|
+
sourceX,
|
|
14
|
+
sourceY,
|
|
15
|
+
targetX,
|
|
16
|
+
targetY,
|
|
17
|
+
sourcePosition,
|
|
18
|
+
targetPosition,
|
|
19
|
+
}: EdgeProps) => {
|
|
20
|
+
const [edgePath] = getSimpleBezierPath({
|
|
21
|
+
sourcePosition,
|
|
22
|
+
sourceX,
|
|
23
|
+
sourceY,
|
|
24
|
+
targetPosition,
|
|
25
|
+
targetX,
|
|
26
|
+
targetY,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<BaseEdge
|
|
31
|
+
className="stroke-1 stroke-ring"
|
|
32
|
+
id={id}
|
|
33
|
+
path={edgePath}
|
|
34
|
+
style={{
|
|
35
|
+
strokeDasharray: "5, 5",
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getHandleCoordsByPosition = (
|
|
42
|
+
node: InternalNode<Node>,
|
|
43
|
+
handlePosition: Position
|
|
44
|
+
) => {
|
|
45
|
+
// Choose the handle type based on position - Left is for target, Right is for source
|
|
46
|
+
const handleType = handlePosition === Position.Left ? "target" : "source";
|
|
47
|
+
|
|
48
|
+
const handle = node.internals.handleBounds?.[handleType]?.find(
|
|
49
|
+
(h) => h.position === handlePosition
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (!handle) {
|
|
53
|
+
return [0, 0] as const;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let offsetX = handle.width / 2;
|
|
57
|
+
let offsetY = handle.height / 2;
|
|
58
|
+
|
|
59
|
+
// this is a tiny detail to make the markerEnd of an edge visible.
|
|
60
|
+
// The handle position that gets calculated has the origin top-left, so depending which side we are using, we add a little offset
|
|
61
|
+
// when the handlePosition is Position.Right for example, we need to add an offset as big as the handle itself in order to get the correct position
|
|
62
|
+
switch (handlePosition) {
|
|
63
|
+
case Position.Left: {
|
|
64
|
+
offsetX = 0;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case Position.Right: {
|
|
68
|
+
offsetX = handle.width;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case Position.Top: {
|
|
72
|
+
offsetY = 0;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case Position.Bottom: {
|
|
76
|
+
offsetY = handle.height;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
default: {
|
|
80
|
+
throw new Error(`Invalid handle position: ${handlePosition}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const x = node.internals.positionAbsolute.x + handle.x + offsetX;
|
|
85
|
+
const y = node.internals.positionAbsolute.y + handle.y + offsetY;
|
|
86
|
+
|
|
87
|
+
return [x, y] as const;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const getEdgeParams = (
|
|
91
|
+
source: InternalNode<Node>,
|
|
92
|
+
target: InternalNode<Node>
|
|
93
|
+
) => {
|
|
94
|
+
const sourcePos = Position.Right;
|
|
95
|
+
const [sx, sy] = getHandleCoordsByPosition(source, sourcePos);
|
|
96
|
+
const targetPos = Position.Left;
|
|
97
|
+
const [tx, ty] = getHandleCoordsByPosition(target, targetPos);
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
sourcePos,
|
|
101
|
+
sx,
|
|
102
|
+
sy,
|
|
103
|
+
targetPos,
|
|
104
|
+
tx,
|
|
105
|
+
ty,
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const Animated = ({ id, source, target, markerEnd, style }: EdgeProps) => {
|
|
110
|
+
const sourceNode = useInternalNode(source);
|
|
111
|
+
const targetNode = useInternalNode(target);
|
|
112
|
+
|
|
113
|
+
if (!(sourceNode && targetNode)) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const { sx, sy, tx, ty, sourcePos, targetPos } = getEdgeParams(
|
|
118
|
+
sourceNode,
|
|
119
|
+
targetNode
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const [edgePath] = getBezierPath({
|
|
123
|
+
sourcePosition: sourcePos,
|
|
124
|
+
sourceX: sx,
|
|
125
|
+
sourceY: sy,
|
|
126
|
+
targetPosition: targetPos,
|
|
127
|
+
targetX: tx,
|
|
128
|
+
targetY: ty,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<>
|
|
133
|
+
<BaseEdge id={id} markerEnd={markerEnd} path={edgePath} style={style} />
|
|
134
|
+
<circle fill="var(--primary)" r="4">
|
|
135
|
+
<animateMotion dur="2s" path={edgePath} repeatCount="indefinite" />
|
|
136
|
+
</circle>
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const Edge = {
|
|
142
|
+
Animated,
|
|
143
|
+
Temporary,
|
|
144
|
+
};
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps, HTMLAttributes } from "react";
|
|
4
|
+
|
|
5
|
+
import { Badge } from "@/components/ui/badge";
|
|
6
|
+
import { Button } from "@/components/ui/button";
|
|
7
|
+
import { Switch } from "@/components/ui/switch";
|
|
8
|
+
import { cn } from "@/lib/utils";
|
|
9
|
+
import { CheckIcon, CopyIcon, EyeIcon, EyeOffIcon } from "lucide-react";
|
|
10
|
+
import {
|
|
11
|
+
createContext,
|
|
12
|
+
useCallback,
|
|
13
|
+
useContext,
|
|
14
|
+
useEffect,
|
|
15
|
+
useMemo,
|
|
16
|
+
useRef,
|
|
17
|
+
useState,
|
|
18
|
+
} from "react";
|
|
19
|
+
|
|
20
|
+
interface EnvironmentVariablesContextType {
|
|
21
|
+
showValues: boolean;
|
|
22
|
+
setShowValues: (show: boolean) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Default noop for context default value
|
|
26
|
+
// oxlint-disable-next-line eslint(no-empty-function)
|
|
27
|
+
const noop = () => {};
|
|
28
|
+
|
|
29
|
+
const EnvironmentVariablesContext =
|
|
30
|
+
createContext<EnvironmentVariablesContextType>({
|
|
31
|
+
setShowValues: noop,
|
|
32
|
+
showValues: false,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export type EnvironmentVariablesProps = HTMLAttributes<HTMLDivElement> & {
|
|
36
|
+
showValues?: boolean;
|
|
37
|
+
defaultShowValues?: boolean;
|
|
38
|
+
onShowValuesChange?: (show: boolean) => void;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const EnvironmentVariables = ({
|
|
42
|
+
showValues: controlledShowValues,
|
|
43
|
+
defaultShowValues = false,
|
|
44
|
+
onShowValuesChange,
|
|
45
|
+
className,
|
|
46
|
+
children,
|
|
47
|
+
...props
|
|
48
|
+
}: EnvironmentVariablesProps) => {
|
|
49
|
+
const [internalShowValues, setInternalShowValues] =
|
|
50
|
+
useState(defaultShowValues);
|
|
51
|
+
const showValues = controlledShowValues ?? internalShowValues;
|
|
52
|
+
|
|
53
|
+
const setShowValues = useCallback(
|
|
54
|
+
(show: boolean) => {
|
|
55
|
+
setInternalShowValues(show);
|
|
56
|
+
onShowValuesChange?.(show);
|
|
57
|
+
},
|
|
58
|
+
[onShowValuesChange]
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const contextValue = useMemo(
|
|
62
|
+
() => ({ setShowValues, showValues }),
|
|
63
|
+
[setShowValues, showValues]
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<EnvironmentVariablesContext.Provider value={contextValue}>
|
|
68
|
+
<div
|
|
69
|
+
className={cn("rounded-lg border bg-background", className)}
|
|
70
|
+
{...props}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</div>
|
|
74
|
+
</EnvironmentVariablesContext.Provider>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type EnvironmentVariablesHeaderProps = HTMLAttributes<HTMLDivElement>;
|
|
79
|
+
|
|
80
|
+
export const EnvironmentVariablesHeader = ({
|
|
81
|
+
className,
|
|
82
|
+
children,
|
|
83
|
+
...props
|
|
84
|
+
}: EnvironmentVariablesHeaderProps) => (
|
|
85
|
+
<div
|
|
86
|
+
className={cn(
|
|
87
|
+
"flex items-center justify-between border-b px-4 py-3",
|
|
88
|
+
className
|
|
89
|
+
)}
|
|
90
|
+
{...props}
|
|
91
|
+
>
|
|
92
|
+
{children}
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
export type EnvironmentVariablesTitleProps = HTMLAttributes<HTMLHeadingElement>;
|
|
97
|
+
|
|
98
|
+
export const EnvironmentVariablesTitle = ({
|
|
99
|
+
className,
|
|
100
|
+
children,
|
|
101
|
+
...props
|
|
102
|
+
}: EnvironmentVariablesTitleProps) => (
|
|
103
|
+
<h3 className={cn("font-medium text-sm", className)} {...props}>
|
|
104
|
+
{children ?? "Environment Variables"}
|
|
105
|
+
</h3>
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
export type EnvironmentVariablesToggleProps = ComponentProps<typeof Switch>;
|
|
109
|
+
|
|
110
|
+
export const EnvironmentVariablesToggle = ({
|
|
111
|
+
className,
|
|
112
|
+
...props
|
|
113
|
+
}: EnvironmentVariablesToggleProps) => {
|
|
114
|
+
const { showValues, setShowValues } = useContext(EnvironmentVariablesContext);
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<div className={cn("flex items-center gap-2", className)}>
|
|
118
|
+
<span className="text-muted-foreground text-xs">
|
|
119
|
+
{showValues ? <EyeIcon size={14} /> : <EyeOffIcon size={14} />}
|
|
120
|
+
</span>
|
|
121
|
+
<Switch
|
|
122
|
+
aria-label="Toggle value visibility"
|
|
123
|
+
checked={showValues}
|
|
124
|
+
onCheckedChange={setShowValues}
|
|
125
|
+
{...props}
|
|
126
|
+
/>
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export type EnvironmentVariablesContentProps = HTMLAttributes<HTMLDivElement>;
|
|
132
|
+
|
|
133
|
+
export const EnvironmentVariablesContent = ({
|
|
134
|
+
className,
|
|
135
|
+
children,
|
|
136
|
+
...props
|
|
137
|
+
}: EnvironmentVariablesContentProps) => (
|
|
138
|
+
<div className={cn("divide-y", className)} {...props}>
|
|
139
|
+
{children}
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
interface EnvironmentVariableContextType {
|
|
144
|
+
name: string;
|
|
145
|
+
value: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const EnvironmentVariableContext =
|
|
149
|
+
createContext<EnvironmentVariableContextType>({
|
|
150
|
+
name: "",
|
|
151
|
+
value: "",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export type EnvironmentVariableProps = HTMLAttributes<HTMLDivElement> & {
|
|
155
|
+
name: string;
|
|
156
|
+
value: string;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const EnvironmentVariable = ({
|
|
160
|
+
name,
|
|
161
|
+
value,
|
|
162
|
+
className,
|
|
163
|
+
children,
|
|
164
|
+
...props
|
|
165
|
+
}: EnvironmentVariableProps) => {
|
|
166
|
+
const envVarContextValue = useMemo(() => ({ name, value }), [name, value]);
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<EnvironmentVariableContext.Provider value={envVarContextValue}>
|
|
170
|
+
<div
|
|
171
|
+
className={cn(
|
|
172
|
+
"flex items-center justify-between gap-4 px-4 py-3",
|
|
173
|
+
className
|
|
174
|
+
)}
|
|
175
|
+
{...props}
|
|
176
|
+
>
|
|
177
|
+
{children ?? (
|
|
178
|
+
<>
|
|
179
|
+
<div className="flex items-center gap-2">
|
|
180
|
+
<EnvironmentVariableName />
|
|
181
|
+
</div>
|
|
182
|
+
<EnvironmentVariableValue />
|
|
183
|
+
</>
|
|
184
|
+
)}
|
|
185
|
+
</div>
|
|
186
|
+
</EnvironmentVariableContext.Provider>
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export type EnvironmentVariableGroupProps = HTMLAttributes<HTMLDivElement>;
|
|
191
|
+
|
|
192
|
+
export const EnvironmentVariableGroup = ({
|
|
193
|
+
className,
|
|
194
|
+
children,
|
|
195
|
+
...props
|
|
196
|
+
}: EnvironmentVariableGroupProps) => (
|
|
197
|
+
<div className={cn("flex items-center gap-2", className)} {...props}>
|
|
198
|
+
{children}
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
export type EnvironmentVariableNameProps = HTMLAttributes<HTMLSpanElement>;
|
|
203
|
+
|
|
204
|
+
export const EnvironmentVariableName = ({
|
|
205
|
+
className,
|
|
206
|
+
children,
|
|
207
|
+
...props
|
|
208
|
+
}: EnvironmentVariableNameProps) => {
|
|
209
|
+
const { name } = useContext(EnvironmentVariableContext);
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<span className={cn("font-mono text-sm", className)} {...props}>
|
|
213
|
+
{children ?? name}
|
|
214
|
+
</span>
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export type EnvironmentVariableValueProps = HTMLAttributes<HTMLSpanElement>;
|
|
219
|
+
|
|
220
|
+
export const EnvironmentVariableValue = ({
|
|
221
|
+
className,
|
|
222
|
+
children,
|
|
223
|
+
...props
|
|
224
|
+
}: EnvironmentVariableValueProps) => {
|
|
225
|
+
const { value } = useContext(EnvironmentVariableContext);
|
|
226
|
+
const { showValues } = useContext(EnvironmentVariablesContext);
|
|
227
|
+
|
|
228
|
+
const displayValue = showValues
|
|
229
|
+
? value
|
|
230
|
+
: "•".repeat(Math.min(value.length, 20));
|
|
231
|
+
|
|
232
|
+
return (
|
|
233
|
+
<span
|
|
234
|
+
className={cn(
|
|
235
|
+
"font-mono text-muted-foreground text-sm",
|
|
236
|
+
!showValues && "select-none",
|
|
237
|
+
className
|
|
238
|
+
)}
|
|
239
|
+
{...props}
|
|
240
|
+
>
|
|
241
|
+
{children ?? displayValue}
|
|
242
|
+
</span>
|
|
243
|
+
);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export type EnvironmentVariableCopyButtonProps = ComponentProps<
|
|
247
|
+
typeof Button
|
|
248
|
+
> & {
|
|
249
|
+
onCopy?: () => void;
|
|
250
|
+
onError?: (error: Error) => void;
|
|
251
|
+
timeout?: number;
|
|
252
|
+
copyFormat?: "name" | "value" | "export";
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
export const EnvironmentVariableCopyButton = ({
|
|
256
|
+
onCopy,
|
|
257
|
+
onError,
|
|
258
|
+
timeout = 2000,
|
|
259
|
+
copyFormat = "value",
|
|
260
|
+
children,
|
|
261
|
+
className,
|
|
262
|
+
...props
|
|
263
|
+
}: EnvironmentVariableCopyButtonProps) => {
|
|
264
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
265
|
+
const timeoutRef = useRef<number>(0);
|
|
266
|
+
const { name, value } = useContext(EnvironmentVariableContext);
|
|
267
|
+
|
|
268
|
+
const getTextToCopy = useCallback((): string => {
|
|
269
|
+
const formatMap = {
|
|
270
|
+
export: () => `export ${name}="${value}"`,
|
|
271
|
+
name: () => name,
|
|
272
|
+
value: () => value,
|
|
273
|
+
};
|
|
274
|
+
return formatMap[copyFormat]();
|
|
275
|
+
}, [name, value, copyFormat]);
|
|
276
|
+
|
|
277
|
+
const copyToClipboard = useCallback(async () => {
|
|
278
|
+
if (typeof window === "undefined" || !navigator?.clipboard?.writeText) {
|
|
279
|
+
onError?.(new Error("Clipboard API not available"));
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
try {
|
|
284
|
+
await navigator.clipboard.writeText(getTextToCopy());
|
|
285
|
+
setIsCopied(true);
|
|
286
|
+
onCopy?.();
|
|
287
|
+
timeoutRef.current = window.setTimeout(() => setIsCopied(false), timeout);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
onError?.(error as Error);
|
|
290
|
+
}
|
|
291
|
+
}, [getTextToCopy, onCopy, onError, timeout]);
|
|
292
|
+
|
|
293
|
+
useEffect(
|
|
294
|
+
() => () => {
|
|
295
|
+
window.clearTimeout(timeoutRef.current);
|
|
296
|
+
},
|
|
297
|
+
[]
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
const Icon = isCopied ? CheckIcon : CopyIcon;
|
|
301
|
+
|
|
302
|
+
return (
|
|
303
|
+
<Button
|
|
304
|
+
className={cn("size-6 shrink-0", className)}
|
|
305
|
+
onClick={copyToClipboard}
|
|
306
|
+
size="icon"
|
|
307
|
+
variant="ghost"
|
|
308
|
+
{...props}
|
|
309
|
+
>
|
|
310
|
+
{children ?? <Icon size={12} />}
|
|
311
|
+
</Button>
|
|
312
|
+
);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
export type EnvironmentVariableRequiredProps = ComponentProps<typeof Badge>;
|
|
316
|
+
|
|
317
|
+
export const EnvironmentVariableRequired = ({
|
|
318
|
+
className,
|
|
319
|
+
children,
|
|
320
|
+
...props
|
|
321
|
+
}: EnvironmentVariableRequiredProps) => (
|
|
322
|
+
<Badge className={cn("text-xs", className)} variant="secondary" {...props}>
|
|
323
|
+
{children ?? "Required"}
|
|
324
|
+
</Badge>
|
|
325
|
+
);
|