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,280 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { RiveParameters } from "@rive-app/react-webgl2";
|
|
4
|
+
import type { FC, ReactNode } from "react";
|
|
5
|
+
|
|
6
|
+
import { cn } from "@/lib/utils";
|
|
7
|
+
import {
|
|
8
|
+
useRive,
|
|
9
|
+
useStateMachineInput,
|
|
10
|
+
useViewModel,
|
|
11
|
+
useViewModelInstance,
|
|
12
|
+
useViewModelInstanceColor,
|
|
13
|
+
} from "@rive-app/react-webgl2";
|
|
14
|
+
import { memo, useEffect, useMemo, useRef, useState } from "react";
|
|
15
|
+
|
|
16
|
+
export type PersonaState =
|
|
17
|
+
| "idle"
|
|
18
|
+
| "listening"
|
|
19
|
+
| "thinking"
|
|
20
|
+
| "speaking"
|
|
21
|
+
| "asleep";
|
|
22
|
+
|
|
23
|
+
interface PersonaProps {
|
|
24
|
+
state: PersonaState;
|
|
25
|
+
onLoad?: RiveParameters["onLoad"];
|
|
26
|
+
onLoadError?: RiveParameters["onLoadError"];
|
|
27
|
+
onReady?: () => void;
|
|
28
|
+
onPause?: RiveParameters["onPause"];
|
|
29
|
+
onPlay?: RiveParameters["onPlay"];
|
|
30
|
+
onStop?: RiveParameters["onStop"];
|
|
31
|
+
className?: string;
|
|
32
|
+
variant?: keyof typeof sources;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The state machine name is always 'default' for Elements AI visuals
|
|
36
|
+
const stateMachine = "default";
|
|
37
|
+
|
|
38
|
+
const sources = {
|
|
39
|
+
command: {
|
|
40
|
+
dynamicColor: true,
|
|
41
|
+
hasModel: true,
|
|
42
|
+
source:
|
|
43
|
+
"https://ejiidnob33g9ap1r.public.blob.vercel-storage.com/command-2.0.riv",
|
|
44
|
+
},
|
|
45
|
+
glint: {
|
|
46
|
+
dynamicColor: true,
|
|
47
|
+
hasModel: true,
|
|
48
|
+
source:
|
|
49
|
+
"https://ejiidnob33g9ap1r.public.blob.vercel-storage.com/glint-2.0.riv",
|
|
50
|
+
},
|
|
51
|
+
halo: {
|
|
52
|
+
dynamicColor: true,
|
|
53
|
+
hasModel: true,
|
|
54
|
+
source:
|
|
55
|
+
"https://ejiidnob33g9ap1r.public.blob.vercel-storage.com/halo-2.0.riv",
|
|
56
|
+
},
|
|
57
|
+
mana: {
|
|
58
|
+
dynamicColor: false,
|
|
59
|
+
hasModel: true,
|
|
60
|
+
source:
|
|
61
|
+
"https://ejiidnob33g9ap1r.public.blob.vercel-storage.com/mana-2.0.riv",
|
|
62
|
+
},
|
|
63
|
+
obsidian: {
|
|
64
|
+
dynamicColor: true,
|
|
65
|
+
hasModel: true,
|
|
66
|
+
source:
|
|
67
|
+
"https://ejiidnob33g9ap1r.public.blob.vercel-storage.com/obsidian-2.0.riv",
|
|
68
|
+
},
|
|
69
|
+
opal: {
|
|
70
|
+
dynamicColor: false,
|
|
71
|
+
hasModel: false,
|
|
72
|
+
source:
|
|
73
|
+
"https://ejiidnob33g9ap1r.public.blob.vercel-storage.com/orb-1.2.riv",
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const getCurrentTheme = (): "light" | "dark" => {
|
|
78
|
+
if (typeof window !== "undefined") {
|
|
79
|
+
if (document.documentElement.classList.contains("dark")) {
|
|
80
|
+
return "dark";
|
|
81
|
+
}
|
|
82
|
+
if (window.matchMedia?.("(prefers-color-scheme: dark)").matches) {
|
|
83
|
+
return "dark";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return "light";
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const useTheme = (enabled: boolean) => {
|
|
90
|
+
const [theme, setTheme] = useState<"light" | "dark">(getCurrentTheme);
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
// Skip if not enabled (avoids unnecessary observers for non-dynamic-color variants)
|
|
94
|
+
if (!enabled) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Watch for classList changes
|
|
99
|
+
const observer = new MutationObserver(() => {
|
|
100
|
+
setTheme(getCurrentTheme());
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
observer.observe(document.documentElement, {
|
|
104
|
+
attributeFilter: ["class"],
|
|
105
|
+
attributes: true,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Watch for OS-level theme changes
|
|
109
|
+
let mql: MediaQueryList | null = null;
|
|
110
|
+
const handleMediaChange = () => {
|
|
111
|
+
setTheme(getCurrentTheme());
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
if (window.matchMedia) {
|
|
115
|
+
mql = window.matchMedia("(prefers-color-scheme: dark)");
|
|
116
|
+
mql.addEventListener("change", handleMediaChange);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return () => {
|
|
120
|
+
observer.disconnect();
|
|
121
|
+
if (mql) {
|
|
122
|
+
mql.removeEventListener("change", handleMediaChange);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}, [enabled]);
|
|
126
|
+
|
|
127
|
+
return theme;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
interface PersonaWithModelProps {
|
|
131
|
+
rive: ReturnType<typeof useRive>["rive"];
|
|
132
|
+
source: (typeof sources)[keyof typeof sources];
|
|
133
|
+
children: React.ReactNode;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const PersonaWithModel = memo(
|
|
137
|
+
({ rive, source, children }: PersonaWithModelProps) => {
|
|
138
|
+
const theme = useTheme(source.dynamicColor);
|
|
139
|
+
const viewModel = useViewModel(rive, { useDefault: true });
|
|
140
|
+
const viewModelInstance = useViewModelInstance(viewModel, {
|
|
141
|
+
rive,
|
|
142
|
+
useDefault: true,
|
|
143
|
+
});
|
|
144
|
+
const viewModelInstanceColor = useViewModelInstanceColor(
|
|
145
|
+
"color",
|
|
146
|
+
viewModelInstance
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (!(viewModelInstanceColor && source.dynamicColor)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const [r, g, b] = theme === "dark" ? [255, 255, 255] : [0, 0, 0];
|
|
155
|
+
viewModelInstanceColor.setRgb(r, g, b);
|
|
156
|
+
}, [viewModelInstanceColor, theme, source.dynamicColor]);
|
|
157
|
+
|
|
158
|
+
return children;
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
PersonaWithModel.displayName = "PersonaWithModel";
|
|
163
|
+
|
|
164
|
+
interface PersonaWithoutModelProps {
|
|
165
|
+
children: ReactNode;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const PersonaWithoutModel = memo(
|
|
169
|
+
({ children }: PersonaWithoutModelProps) => children
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
PersonaWithoutModel.displayName = "PersonaWithoutModel";
|
|
173
|
+
|
|
174
|
+
export const Persona: FC<PersonaProps> = memo(
|
|
175
|
+
({
|
|
176
|
+
variant = "obsidian",
|
|
177
|
+
state = "idle",
|
|
178
|
+
onLoad,
|
|
179
|
+
onLoadError,
|
|
180
|
+
onReady,
|
|
181
|
+
onPause,
|
|
182
|
+
onPlay,
|
|
183
|
+
onStop,
|
|
184
|
+
className,
|
|
185
|
+
}) => {
|
|
186
|
+
const source = sources[variant];
|
|
187
|
+
|
|
188
|
+
if (!source) {
|
|
189
|
+
throw new Error(`Invalid variant: ${variant}`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Stabilize callbacks to prevent useRive from reinitializing
|
|
193
|
+
const callbacksRef = useRef({
|
|
194
|
+
onLoad,
|
|
195
|
+
onLoadError,
|
|
196
|
+
onPause,
|
|
197
|
+
onPlay,
|
|
198
|
+
onReady,
|
|
199
|
+
onStop,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
callbacksRef.current = {
|
|
204
|
+
onLoad,
|
|
205
|
+
onLoadError,
|
|
206
|
+
onPause,
|
|
207
|
+
onPlay,
|
|
208
|
+
onReady,
|
|
209
|
+
onStop,
|
|
210
|
+
};
|
|
211
|
+
}, [onLoad, onLoadError, onPause, onPlay, onReady, onStop]);
|
|
212
|
+
|
|
213
|
+
const stableCallbacks = useMemo(
|
|
214
|
+
() => ({
|
|
215
|
+
onLoad: ((loadedRive) =>
|
|
216
|
+
callbacksRef.current.onLoad?.(
|
|
217
|
+
loadedRive
|
|
218
|
+
)) as RiveParameters["onLoad"],
|
|
219
|
+
onLoadError: ((err) =>
|
|
220
|
+
callbacksRef.current.onLoadError?.(
|
|
221
|
+
err
|
|
222
|
+
)) as RiveParameters["onLoadError"],
|
|
223
|
+
onPause: ((event) =>
|
|
224
|
+
callbacksRef.current.onPause?.(event)) as RiveParameters["onPause"],
|
|
225
|
+
onPlay: ((event) =>
|
|
226
|
+
callbacksRef.current.onPlay?.(event)) as RiveParameters["onPlay"],
|
|
227
|
+
onReady: () => callbacksRef.current.onReady?.(),
|
|
228
|
+
onStop: ((event) =>
|
|
229
|
+
callbacksRef.current.onStop?.(event)) as RiveParameters["onStop"],
|
|
230
|
+
}),
|
|
231
|
+
[]
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const { rive, RiveComponent } = useRive({
|
|
235
|
+
autoplay: true,
|
|
236
|
+
onLoad: stableCallbacks.onLoad,
|
|
237
|
+
onLoadError: stableCallbacks.onLoadError,
|
|
238
|
+
onPause: stableCallbacks.onPause,
|
|
239
|
+
onPlay: stableCallbacks.onPlay,
|
|
240
|
+
onRiveReady: stableCallbacks.onReady,
|
|
241
|
+
onStop: stableCallbacks.onStop,
|
|
242
|
+
src: source.source,
|
|
243
|
+
stateMachines: stateMachine,
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const listeningInput = useStateMachineInput(
|
|
247
|
+
rive,
|
|
248
|
+
stateMachine,
|
|
249
|
+
"listening"
|
|
250
|
+
);
|
|
251
|
+
const thinkingInput = useStateMachineInput(rive, stateMachine, "thinking");
|
|
252
|
+
const speakingInput = useStateMachineInput(rive, stateMachine, "speaking");
|
|
253
|
+
const asleepInput = useStateMachineInput(rive, stateMachine, "asleep");
|
|
254
|
+
|
|
255
|
+
useEffect(() => {
|
|
256
|
+
if (listeningInput) {
|
|
257
|
+
listeningInput.value = state === "listening";
|
|
258
|
+
}
|
|
259
|
+
if (thinkingInput) {
|
|
260
|
+
thinkingInput.value = state === "thinking";
|
|
261
|
+
}
|
|
262
|
+
if (speakingInput) {
|
|
263
|
+
speakingInput.value = state === "speaking";
|
|
264
|
+
}
|
|
265
|
+
if (asleepInput) {
|
|
266
|
+
asleepInput.value = state === "asleep";
|
|
267
|
+
}
|
|
268
|
+
}, [state, listeningInput, thinkingInput, speakingInput, asleepInput]);
|
|
269
|
+
|
|
270
|
+
const Component = source.hasModel ? PersonaWithModel : PersonaWithoutModel;
|
|
271
|
+
|
|
272
|
+
return (
|
|
273
|
+
<Component rive={rive} source={source}>
|
|
274
|
+
<RiveComponent className={cn("size-16 shrink-0", className)} />
|
|
275
|
+
</Component>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
Persona.displayName = "Persona";
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps } from "react";
|
|
4
|
+
|
|
5
|
+
import { Button } from "@/components/ui/button";
|
|
6
|
+
import {
|
|
7
|
+
Card,
|
|
8
|
+
CardAction,
|
|
9
|
+
CardContent,
|
|
10
|
+
CardDescription,
|
|
11
|
+
CardFooter,
|
|
12
|
+
CardHeader,
|
|
13
|
+
CardTitle,
|
|
14
|
+
} from "@/components/ui/card";
|
|
15
|
+
import {
|
|
16
|
+
Collapsible,
|
|
17
|
+
CollapsibleContent,
|
|
18
|
+
CollapsibleTrigger,
|
|
19
|
+
} from "@/components/ui/collapsible";
|
|
20
|
+
import { cn } from "@/lib/utils";
|
|
21
|
+
import { ChevronsUpDownIcon } from "lucide-react";
|
|
22
|
+
import { createContext, useContext } from "react";
|
|
23
|
+
|
|
24
|
+
import { Shimmer } from "./shimmer";
|
|
25
|
+
|
|
26
|
+
interface PlanContextValue {
|
|
27
|
+
isStreaming: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const PlanContext = createContext<PlanContextValue | null>(null);
|
|
31
|
+
|
|
32
|
+
const usePlan = () => {
|
|
33
|
+
const context = useContext(PlanContext);
|
|
34
|
+
if (!context) {
|
|
35
|
+
throw new Error("Plan components must be used within Plan");
|
|
36
|
+
}
|
|
37
|
+
return context;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type PlanProps = ComponentProps<typeof Collapsible> & {
|
|
41
|
+
isStreaming?: boolean;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const Plan = ({
|
|
45
|
+
className,
|
|
46
|
+
isStreaming = false,
|
|
47
|
+
children,
|
|
48
|
+
...props
|
|
49
|
+
}: PlanProps) => (
|
|
50
|
+
<PlanContext.Provider value={{ isStreaming }}>
|
|
51
|
+
<Collapsible asChild data-slot="plan" {...props}>
|
|
52
|
+
<Card className={cn("shadow-none", className)}>{children}</Card>
|
|
53
|
+
</Collapsible>
|
|
54
|
+
</PlanContext.Provider>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export type PlanHeaderProps = ComponentProps<typeof CardHeader>;
|
|
58
|
+
|
|
59
|
+
export const PlanHeader = ({ className, ...props }: PlanHeaderProps) => (
|
|
60
|
+
<CardHeader
|
|
61
|
+
className={cn("flex items-start justify-between", className)}
|
|
62
|
+
data-slot="plan-header"
|
|
63
|
+
{...props}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
export type PlanTitleProps = Omit<
|
|
68
|
+
ComponentProps<typeof CardTitle>,
|
|
69
|
+
"children"
|
|
70
|
+
> & {
|
|
71
|
+
children: string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const PlanTitle = ({ children, ...props }: PlanTitleProps) => {
|
|
75
|
+
const { isStreaming } = usePlan();
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<CardTitle data-slot="plan-title" {...props}>
|
|
79
|
+
{isStreaming ? <Shimmer>{children}</Shimmer> : children}
|
|
80
|
+
</CardTitle>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type PlanDescriptionProps = Omit<
|
|
85
|
+
ComponentProps<typeof CardDescription>,
|
|
86
|
+
"children"
|
|
87
|
+
> & {
|
|
88
|
+
children: string;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const PlanDescription = ({
|
|
92
|
+
className,
|
|
93
|
+
children,
|
|
94
|
+
...props
|
|
95
|
+
}: PlanDescriptionProps) => {
|
|
96
|
+
const { isStreaming } = usePlan();
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<CardDescription
|
|
100
|
+
className={cn("text-balance", className)}
|
|
101
|
+
data-slot="plan-description"
|
|
102
|
+
{...props}
|
|
103
|
+
>
|
|
104
|
+
{isStreaming ? <Shimmer>{children}</Shimmer> : children}
|
|
105
|
+
</CardDescription>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type PlanActionProps = ComponentProps<typeof CardAction>;
|
|
110
|
+
|
|
111
|
+
export const PlanAction = (props: PlanActionProps) => (
|
|
112
|
+
<CardAction data-slot="plan-action" {...props} />
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
export type PlanContentProps = ComponentProps<typeof CardContent>;
|
|
116
|
+
|
|
117
|
+
export const PlanContent = (props: PlanContentProps) => (
|
|
118
|
+
<CollapsibleContent asChild>
|
|
119
|
+
<CardContent data-slot="plan-content" {...props} />
|
|
120
|
+
</CollapsibleContent>
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
export type PlanFooterProps = ComponentProps<"div">;
|
|
124
|
+
|
|
125
|
+
export const PlanFooter = (props: PlanFooterProps) => (
|
|
126
|
+
<CardFooter data-slot="plan-footer" {...props} />
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
export type PlanTriggerProps = ComponentProps<typeof CollapsibleTrigger>;
|
|
130
|
+
|
|
131
|
+
export const PlanTrigger = ({ className, ...props }: PlanTriggerProps) => (
|
|
132
|
+
<CollapsibleTrigger asChild>
|
|
133
|
+
<Button
|
|
134
|
+
className={cn("size-8", className)}
|
|
135
|
+
data-slot="plan-trigger"
|
|
136
|
+
size="icon"
|
|
137
|
+
variant="ghost"
|
|
138
|
+
{...props}
|
|
139
|
+
>
|
|
140
|
+
<ChevronsUpDownIcon className="size-4" />
|
|
141
|
+
<span className="sr-only">Toggle plan</span>
|
|
142
|
+
</Button>
|
|
143
|
+
</CollapsibleTrigger>
|
|
144
|
+
);
|