ai-design-system 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.
Files changed (290) hide show
  1. package/README.md +307 -0
  2. package/components/ai-elements/actions.tsx +65 -0
  3. package/components/ai-elements/artifact.tsx +147 -0
  4. package/components/ai-elements/branch.tsx +212 -0
  5. package/components/ai-elements/canvas.tsx +24 -0
  6. package/components/ai-elements/chain-of-thought.tsx +228 -0
  7. package/components/ai-elements/code-block.tsx +179 -0
  8. package/components/ai-elements/confirmation.tsx +169 -0
  9. package/components/ai-elements/connection.tsx +28 -0
  10. package/components/ai-elements/context.tsx +408 -0
  11. package/components/ai-elements/controls.tsx +18 -0
  12. package/components/ai-elements/conversation.tsx +97 -0
  13. package/components/ai-elements/edge.tsx +140 -0
  14. package/components/ai-elements/image.tsx +24 -0
  15. package/components/ai-elements/inline-citation.tsx +287 -0
  16. package/components/ai-elements/loader.tsx +96 -0
  17. package/components/ai-elements/message.tsx +80 -0
  18. package/components/ai-elements/node.tsx +71 -0
  19. package/components/ai-elements/open-in-chat.tsx +363 -0
  20. package/components/ai-elements/panel.tsx +15 -0
  21. package/components/ai-elements/plan.tsx +142 -0
  22. package/components/ai-elements/prompt-input.tsx +1352 -0
  23. package/components/ai-elements/queue.tsx +274 -0
  24. package/components/ai-elements/reasoning.tsx +178 -0
  25. package/components/ai-elements/response.tsx +22 -0
  26. package/components/ai-elements/shimmer.tsx +64 -0
  27. package/components/ai-elements/sources.tsx +77 -0
  28. package/components/ai-elements/suggestion.tsx +56 -0
  29. package/components/ai-elements/task.tsx +87 -0
  30. package/components/ai-elements/tool.tsx +179 -0
  31. package/components/ai-elements/toolbar.tsx +16 -0
  32. package/components/ai-elements/web-preview.tsx +263 -0
  33. package/components/blocks/AIConversation/AIConversation.stories.tsx +164 -0
  34. package/components/blocks/AIConversation/AIConversation.tsx +186 -0
  35. package/components/blocks/AIConversation/index.ts +8 -0
  36. package/components/blocks/AppSidebar/AppSidebar.stories.tsx +63 -0
  37. package/components/blocks/AppSidebar/AppSidebar.tsx +87 -0
  38. package/components/blocks/AppSidebar/index.ts +2 -0
  39. package/components/blocks/DocumentEditorWithComments/DocumentEditorWithComments.stories.tsx +341 -0
  40. package/components/blocks/DocumentEditorWithComments/DocumentEditorWithComments.tsx +255 -0
  41. package/components/blocks/DocumentEditorWithComments/index.ts +9 -0
  42. package/components/blocks/FileChangeQueue/FileChangeQueue.stories.tsx +207 -0
  43. package/components/blocks/FileChangeQueue/FileChangeQueue.tsx +143 -0
  44. package/components/blocks/FileChangeQueue/index.ts +7 -0
  45. package/components/blocks/LayoutProvider/LayoutProvider.tsx +34 -0
  46. package/components/blocks/LayoutProvider/index.ts +1 -0
  47. package/components/blocks/index.ts +2 -0
  48. package/components/composites/AgentIndicator/AgentIndicator.stories.tsx +154 -0
  49. package/components/composites/AgentIndicator/AgentIndicator.tsx +102 -0
  50. package/components/composites/AgentIndicator/index.ts +8 -0
  51. package/components/composites/AppHeader/AppHeader.stories.tsx +46 -0
  52. package/components/composites/AppHeader/AppHeader.tsx +24 -0
  53. package/components/composites/AppHeader/index.ts +2 -0
  54. package/components/composites/CommentBox/CommentBox.stories.tsx +192 -0
  55. package/components/composites/CommentBox/CommentBox.tsx +364 -0
  56. package/components/composites/CommentBox/index.ts +8 -0
  57. package/components/composites/Confirmation/Confirmation.stories.tsx +151 -0
  58. package/components/composites/Confirmation/Confirmation.tsx +93 -0
  59. package/components/composites/Confirmation/index.ts +7 -0
  60. package/components/composites/DataTable/DataTable.stories.tsx +35 -0
  61. package/components/composites/DataTable/DataTable.tsx +95 -0
  62. package/components/composites/DataTable/index.ts +2 -0
  63. package/components/composites/DocumentEditor/DocumentEditor.css +106 -0
  64. package/components/composites/DocumentEditor/DocumentEditor.stories.tsx +927 -0
  65. package/components/composites/DocumentEditor/DocumentEditor.tsx +279 -0
  66. package/components/composites/DocumentEditor/index.ts +8 -0
  67. package/components/composites/FileQueue/FileQueue.stories.tsx +175 -0
  68. package/components/composites/FileQueue/FileQueue.tsx +161 -0
  69. package/components/composites/FileQueue/FileStatusBadge.tsx +74 -0
  70. package/components/composites/FileQueue/index.ts +24 -0
  71. package/components/composites/InteractiveChart/InteractiveChart.stories.tsx +49 -0
  72. package/components/composites/InteractiveChart/InteractiveChart.tsx +69 -0
  73. package/components/composites/InteractiveChart/index.ts +2 -0
  74. package/components/composites/ModeToggle/ModeToggle.stories.tsx +212 -0
  75. package/components/composites/ModeToggle/ModeToggle.tsx +100 -0
  76. package/components/composites/ModeToggle/index.ts +7 -0
  77. package/components/composites/NavUser/NavUser.stories.tsx +50 -0
  78. package/components/composites/NavUser/NavUser.tsx +60 -0
  79. package/components/composites/NavUser/index.ts +2 -0
  80. package/components/composites/NavigationList/NavigationList.stories.tsx +46 -0
  81. package/components/composites/NavigationList/NavigationList.tsx +46 -0
  82. package/components/composites/NavigationList/index.ts +2 -0
  83. package/components/composites/OrchestratorMessage/OrchestratorMessage.stories.tsx +188 -0
  84. package/components/composites/OrchestratorMessage/OrchestratorMessage.tsx +72 -0
  85. package/components/composites/OrchestratorMessage/index.ts +8 -0
  86. package/components/composites/PageContainer/PageContainer.stories.tsx +41 -0
  87. package/components/composites/PageContainer/PageContainer.tsx +24 -0
  88. package/components/composites/PageContainer/index.ts +2 -0
  89. package/components/composites/PromptInput/PromptInput.stories.tsx +200 -0
  90. package/components/composites/PromptInput/PromptInput.tsx +129 -0
  91. package/components/composites/PromptInput/index.ts +8 -0
  92. package/components/composites/SpecialistMessage/SpecialistMessage.stories.tsx +286 -0
  93. package/components/composites/SpecialistMessage/SpecialistMessage.tsx +107 -0
  94. package/components/composites/SpecialistMessage/index.ts +8 -0
  95. package/components/composites/StatsCard/StatsCard.stories.tsx +76 -0
  96. package/components/composites/StatsCard/StatsCard.tsx +81 -0
  97. package/components/composites/StatsCard/index.ts +2 -0
  98. package/components/composites/TablePagination/TablePagination.stories.tsx +38 -0
  99. package/components/composites/TablePagination/TablePagination.tsx +119 -0
  100. package/components/composites/TablePagination/index.ts +2 -0
  101. package/components/composites/TableToolbar/TableToolbar.stories.tsx +60 -0
  102. package/components/composites/TableToolbar/TableToolbar.tsx +66 -0
  103. package/components/composites/TableToolbar/index.ts +2 -0
  104. package/components/composites/ThemeSelector/ThemeSelector.stories.tsx +48 -0
  105. package/components/composites/ThemeSelector/ThemeSelector.tsx +79 -0
  106. package/components/composites/ThemeSelector/index.ts +2 -0
  107. package/components/composites/ToolCallDisplay/ToolCallDisplay.stories.tsx +49 -0
  108. package/components/composites/ToolCallDisplay/ToolCallDisplay.tsx +108 -0
  109. package/components/composites/ToolCallDisplay/index.ts +8 -0
  110. package/components/composites/UserMessage/UserMessage.stories.tsx +59 -0
  111. package/components/composites/UserMessage/UserMessage.tsx +52 -0
  112. package/components/composites/UserMessage/index.ts +8 -0
  113. package/components/composites/index.ts +90 -0
  114. package/components/features/AIDocEditor/AIDocEditor.behaviors.stories.tsx +451 -0
  115. package/components/features/AIDocEditor/AIDocEditor.mocks.ts +96 -0
  116. package/components/features/AIDocEditor/AIDocEditor.stories.tsx +140 -0
  117. package/components/features/AIDocEditor/AIDocEditor.tsx +130 -0
  118. package/components/features/AIDocEditor/index.ts +8 -0
  119. package/components/features/AIDocEditor/useAIDocEditor.d.ts +97 -0
  120. package/components/features/AIDocEditor/useAIDocEditor.mock.ts +83 -0
  121. package/components/features/PageLayout/PageLayout.behaviors.stories.tsx +119 -0
  122. package/components/features/PageLayout/PageLayout.mocks.ts +27 -0
  123. package/components/features/PageLayout/PageLayout.stories.tsx +142 -0
  124. package/components/features/PageLayout/PageLayout.tsx +94 -0
  125. package/components/features/PageLayout/index.ts +4 -0
  126. package/components/features/PageLayout/usePageLayout.d.ts +24 -0
  127. package/components/features/PageLayout/usePageLayout.mock.ts +19 -0
  128. package/components/features/RefinementPanel/README.md +189 -0
  129. package/components/features/RefinementPanel/RefinementPanel.behaviors.stories.tsx +475 -0
  130. package/components/features/RefinementPanel/RefinementPanel.mocks.ts +131 -0
  131. package/components/features/RefinementPanel/RefinementPanel.stories.tsx +141 -0
  132. package/components/features/RefinementPanel/RefinementPanel.tsx +160 -0
  133. package/components/features/RefinementPanel/index.ts +25 -0
  134. package/components/features/RefinementPanel/useRefinementPanel.d.ts +74 -0
  135. package/components/features/RefinementPanel/useRefinementPanel.mock.ts +121 -0
  136. package/components/features/SpecNavigator/SpecNavigator.behaviors.stories.tsx +379 -0
  137. package/components/features/SpecNavigator/SpecNavigator.mocks.ts +131 -0
  138. package/components/features/SpecNavigator/SpecNavigator.stories.tsx +122 -0
  139. package/components/features/SpecNavigator/SpecNavigator.tsx +43 -0
  140. package/components/features/SpecNavigator/index.ts +2 -0
  141. package/components/features/SpecNavigator/useSpecNavigator.d.ts +122 -0
  142. package/components/features/SpecNavigator/useSpecNavigator.mock.ts +93 -0
  143. package/components/features/index.ts +18 -0
  144. package/components/index.ts +14 -0
  145. package/components/primitives/Accordion/Accordion.stories.tsx +87 -0
  146. package/components/primitives/Accordion/Accordion.tsx +66 -0
  147. package/components/primitives/Accordion/index.ts +13 -0
  148. package/components/primitives/Alert/Alert.stories.tsx +422 -0
  149. package/components/primitives/Alert/Alert.tsx +61 -0
  150. package/components/primitives/Alert/index.ts +8 -0
  151. package/components/primitives/AlertDialog/AlertDialog.stories.tsx +367 -0
  152. package/components/primitives/AlertDialog/AlertDialog.tsx +182 -0
  153. package/components/primitives/AlertDialog/index.ts +25 -0
  154. package/components/primitives/Avatar/Avatar.stories.tsx +321 -0
  155. package/components/primitives/Avatar/Avatar.tsx +63 -0
  156. package/components/primitives/Avatar/index.ts +8 -0
  157. package/components/primitives/Badge/Badge.stories.tsx +74 -0
  158. package/components/primitives/Badge/Badge.tsx +49 -0
  159. package/components/primitives/Badge/index.ts +2 -0
  160. package/components/primitives/Button/Button.stories.tsx +445 -0
  161. package/components/primitives/Button/Button.tsx +89 -0
  162. package/components/primitives/Button/index.ts +7 -0
  163. package/components/primitives/Card/Card.stories.tsx +831 -0
  164. package/components/primitives/Card/Card.tsx +242 -0
  165. package/components/primitives/Card/index.ts +30 -0
  166. package/components/primitives/Carousel/Carousel.stories.tsx +32 -0
  167. package/components/primitives/Carousel/Carousel.tsx +63 -0
  168. package/components/primitives/Carousel/index.ts +13 -0
  169. package/components/primitives/Chart/Chart.stories.tsx +346 -0
  170. package/components/primitives/Chart/Chart.tsx +117 -0
  171. package/components/primitives/Chart/index.ts +20 -0
  172. package/components/primitives/Checkbox/Checkbox.stories.tsx +87 -0
  173. package/components/primitives/Checkbox/Checkbox.tsx +38 -0
  174. package/components/primitives/Checkbox/index.ts +2 -0
  175. package/components/primitives/Collapsible/Collapsible.stories.tsx +38 -0
  176. package/components/primitives/Collapsible/Collapsible.tsx +39 -0
  177. package/components/primitives/Collapsible/index.ts +8 -0
  178. package/components/primitives/Command/Command.stories.tsx +150 -0
  179. package/components/primitives/Command/Command.tsx +147 -0
  180. package/components/primitives/Command/index.ts +20 -0
  181. package/components/primitives/Dialog/Dialog.stories.tsx +390 -0
  182. package/components/primitives/Dialog/Dialog.tsx +140 -0
  183. package/components/primitives/Dialog/index.ts +22 -0
  184. package/components/primitives/Drawer/Drawer.stories.tsx +327 -0
  185. package/components/primitives/Drawer/Drawer.tsx +208 -0
  186. package/components/primitives/Drawer/index.ts +27 -0
  187. package/components/primitives/DropdownMenu/DropdownMenu.stories.tsx +150 -0
  188. package/components/primitives/DropdownMenu/DropdownMenu.tsx +73 -0
  189. package/components/primitives/DropdownMenu/index.ts +1 -0
  190. package/components/primitives/HoverCard/HoverCard.stories.tsx +26 -0
  191. package/components/primitives/HoverCard/HoverCard.tsx +39 -0
  192. package/components/primitives/HoverCard/index.ts +8 -0
  193. package/components/primitives/Icon/Icon.stories.tsx +281 -0
  194. package/components/primitives/Icon/Icon.tsx +87 -0
  195. package/components/primitives/Icon/index.ts +8 -0
  196. package/components/primitives/Input/Input.stories.tsx +370 -0
  197. package/components/primitives/Input/Input.tsx +88 -0
  198. package/components/primitives/Input/index.ts +7 -0
  199. package/components/primitives/InputGroup/InputGroup.stories.tsx +40 -0
  200. package/components/primitives/InputGroup/InputGroup.tsx +72 -0
  201. package/components/primitives/InputGroup/index.ts +14 -0
  202. package/components/primitives/Label/Label.stories.tsx +227 -0
  203. package/components/primitives/Label/Label.tsx +53 -0
  204. package/components/primitives/Label/index.ts +7 -0
  205. package/components/primitives/Popover/Popover.stories.tsx +42 -0
  206. package/components/primitives/Popover/Popover.tsx +107 -0
  207. package/components/primitives/Popover/index.ts +2 -0
  208. package/components/primitives/Progress/Progress.stories.tsx +340 -0
  209. package/components/primitives/Progress/Progress.tsx +31 -0
  210. package/components/primitives/Progress/index.ts +1 -0
  211. package/components/primitives/ScrollArea/ScrollArea.stories.tsx +26 -0
  212. package/components/primitives/ScrollArea/ScrollArea.tsx +28 -0
  213. package/components/primitives/ScrollArea/index.ts +6 -0
  214. package/components/primitives/Select/Select.stories.tsx +288 -0
  215. package/components/primitives/Select/Select.tsx +162 -0
  216. package/components/primitives/Select/index.ts +22 -0
  217. package/components/primitives/Separator/Separator.stories.tsx +264 -0
  218. package/components/primitives/Separator/Separator.tsx +48 -0
  219. package/components/primitives/Separator/index.ts +7 -0
  220. package/components/primitives/Sidebar/Sidebar.stories.tsx +358 -0
  221. package/components/primitives/Sidebar/Sidebar.tsx +317 -0
  222. package/components/primitives/Sidebar/index.ts +41 -0
  223. package/components/primitives/Table/Table.stories.tsx +389 -0
  224. package/components/primitives/Table/Table.tsx +191 -0
  225. package/components/primitives/Table/index.ts +26 -0
  226. package/components/primitives/Tabs/Tabs.stories.tsx +129 -0
  227. package/components/primitives/Tabs/Tabs.tsx +70 -0
  228. package/components/primitives/Tabs/index.ts +13 -0
  229. package/components/primitives/Textarea/Textarea.stories.tsx +358 -0
  230. package/components/primitives/Textarea/Textarea.tsx +91 -0
  231. package/components/primitives/Textarea/index.ts +7 -0
  232. package/components/primitives/ToggleGroup/ToggleGroup.stories.tsx +87 -0
  233. package/components/primitives/ToggleGroup/ToggleGroup.tsx +52 -0
  234. package/components/primitives/ToggleGroup/index.ts +6 -0
  235. package/components/primitives/Tooltip/Tooltip.stories.tsx +336 -0
  236. package/components/primitives/Tooltip/Tooltip.tsx +78 -0
  237. package/components/primitives/Tooltip/index.ts +10 -0
  238. package/components/primitives/index.ts +34 -0
  239. package/components/ui/accordion.tsx +66 -0
  240. package/components/ui/alert-dialog.tsx +157 -0
  241. package/components/ui/alert.tsx +66 -0
  242. package/components/ui/avatar.tsx +53 -0
  243. package/components/ui/badge.tsx +46 -0
  244. package/components/ui/button.tsx +60 -0
  245. package/components/ui/card.tsx +117 -0
  246. package/components/ui/carousel.tsx +241 -0
  247. package/components/ui/chart.tsx +334 -0
  248. package/components/ui/checkbox.tsx +32 -0
  249. package/components/ui/collapsible.tsx +33 -0
  250. package/components/ui/command.tsx +184 -0
  251. package/components/ui/dialog.tsx +143 -0
  252. package/components/ui/drawer.tsx +118 -0
  253. package/components/ui/dropdown-menu.tsx +257 -0
  254. package/components/ui/hover-card.tsx +44 -0
  255. package/components/ui/input-group.tsx +170 -0
  256. package/components/ui/input.tsx +48 -0
  257. package/components/ui/label.tsx +26 -0
  258. package/components/ui/popover.tsx +33 -0
  259. package/components/ui/progress.tsx +31 -0
  260. package/components/ui/scroll-area.tsx +58 -0
  261. package/components/ui/select.tsx +187 -0
  262. package/components/ui/separator.tsx +31 -0
  263. package/components/ui/sidebar.tsx +577 -0
  264. package/components/ui/table.tsx +120 -0
  265. package/components/ui/tabs.tsx +66 -0
  266. package/components/ui/textarea.tsx +46 -0
  267. package/components/ui/toggle-group.tsx +83 -0
  268. package/components/ui/toggle.tsx +47 -0
  269. package/components/ui/tooltip.tsx +61 -0
  270. package/dist/index.cjs +7389 -0
  271. package/dist/index.cjs.map +1 -0
  272. package/dist/index.css +75 -0
  273. package/dist/index.css.map +1 -0
  274. package/dist/index.js +7160 -0
  275. package/dist/index.js.map +1 -0
  276. package/hooks/useAIDocReviewer.d.ts +0 -0
  277. package/lib/utils.ts +6 -0
  278. package/package.json +140 -0
  279. package/tokens/color/base.json +14 -0
  280. package/tokens/color/dark.json +40 -0
  281. package/tokens/color/green.json +21 -0
  282. package/tokens/color/light.json +52 -0
  283. package/tokens/color/neutral.json +20 -0
  284. package/tokens/color/violet.json +21 -0
  285. package/tokens/spacing.json +22 -0
  286. package/utils/ai-editor/format-date.ts +41 -0
  287. package/utils/ai-editor/index.ts +22 -0
  288. package/utils/ai-editor/type-guards.ts +72 -0
  289. package/utils/ai-editor/validation.ts +130 -0
  290. package/utils/editor-annotations.ts +122 -0
@@ -0,0 +1,169 @@
1
+ "use client";
2
+
3
+ import { Alert, AlertDescription } from "@/components/ui/alert";
4
+ import { Button } from "@/components/ui/button";
5
+ import { cn } from "@/lib/utils";
6
+ // Define our own types since ToolUIPart doesn't exist in current AI SDK
7
+ type ToolUIState =
8
+ | "input-streaming"
9
+ | "input-available"
10
+ | "approval-requested"
11
+ | "approval-responded"
12
+ | "output-denied"
13
+ | "output-available"
14
+ | "output-error";
15
+
16
+ type ToolApproval = {
17
+ approved?: boolean;
18
+ };
19
+
20
+ type ToolUIPart = {
21
+ type: `tool-${string}`;
22
+ state: ToolUIState;
23
+ approval?: ToolApproval;
24
+ input?: any;
25
+ output?: any;
26
+ errorText?: string;
27
+ };
28
+ import {
29
+ type ComponentProps,
30
+ createContext,
31
+ type ReactNode,
32
+ useContext,
33
+ } from "react";
34
+
35
+ type ConfirmationContextValue = {
36
+ approval: ToolUIPart["approval"];
37
+ state: ToolUIPart["state"];
38
+ };
39
+
40
+ const ConfirmationContext = createContext<ConfirmationContextValue | null>(
41
+ null
42
+ );
43
+
44
+ const useConfirmation = () => {
45
+ const context = useContext(ConfirmationContext);
46
+
47
+ if (!context) {
48
+ throw new Error("Confirmation components must be used within Confirmation");
49
+ }
50
+
51
+ return context;
52
+ };
53
+
54
+ export type ConfirmationProps = ComponentProps<typeof Alert> & {
55
+ approval?: ToolUIPart["approval"];
56
+ state: ToolUIPart["state"];
57
+ };
58
+
59
+ export const Confirmation = ({
60
+ className,
61
+ approval,
62
+ state,
63
+ ...props
64
+ }: ConfirmationProps) => {
65
+ if (!approval || state === "input-streaming" || state === "input-available") {
66
+ return null;
67
+ }
68
+
69
+ return (
70
+ <ConfirmationContext.Provider value={{ approval, state }}>
71
+ <Alert className={cn("flex flex-col gap-2", className)} {...props} />
72
+ </ConfirmationContext.Provider>
73
+ );
74
+ };
75
+
76
+ export type ConfirmationTitleProps = ComponentProps<typeof AlertDescription>;
77
+
78
+ export const ConfirmationTitle = ({
79
+ className,
80
+ ...props
81
+ }: ConfirmationTitleProps) => (
82
+ <AlertDescription className={cn("inline", className)} {...props} />
83
+ );
84
+
85
+ export type ConfirmationRequestProps = {
86
+ children?: ReactNode;
87
+ };
88
+
89
+ export const ConfirmationRequest = ({ children }: ConfirmationRequestProps) => {
90
+ const { state } = useConfirmation();
91
+
92
+ // Only show when approval is requested
93
+ if (state !== "approval-requested") {
94
+ return null;
95
+ }
96
+
97
+ return children;
98
+ };
99
+
100
+ export type ConfirmationAcceptedProps = {
101
+ children?: ReactNode;
102
+ };
103
+
104
+ export const ConfirmationAccepted = ({
105
+ children,
106
+ }: ConfirmationAcceptedProps) => {
107
+ const { approval, state } = useConfirmation();
108
+
109
+ // Only show when approved and in response states
110
+ if (
111
+ !approval?.approved ||
112
+ (state !== "approval-responded" &&
113
+ state !== "output-denied" &&
114
+ state !== "output-available")
115
+ ) {
116
+ return null;
117
+ }
118
+
119
+ return children;
120
+ };
121
+
122
+ export type ConfirmationRejectedProps = {
123
+ children?: ReactNode;
124
+ };
125
+
126
+ export const ConfirmationRejected = ({
127
+ children,
128
+ }: ConfirmationRejectedProps) => {
129
+ const { approval, state } = useConfirmation();
130
+
131
+ // Only show when rejected and in response states
132
+ if (
133
+ approval?.approved !== false ||
134
+ (state !== "approval-responded" &&
135
+ state !== "output-denied" &&
136
+ state !== "output-available")
137
+ ) {
138
+ return null;
139
+ }
140
+
141
+ return children;
142
+ };
143
+
144
+ export type ConfirmationActionsProps = ComponentProps<"div">;
145
+
146
+ export const ConfirmationActions = ({
147
+ className,
148
+ ...props
149
+ }: ConfirmationActionsProps) => {
150
+ const { state } = useConfirmation();
151
+
152
+ // Only show when approval is requested
153
+ if (state !== "approval-requested") {
154
+ return null;
155
+ }
156
+
157
+ return (
158
+ <div
159
+ className={cn("flex items-center justify-end gap-2 self-end", className)}
160
+ {...props}
161
+ />
162
+ );
163
+ };
164
+
165
+ export type ConfirmationActionProps = ComponentProps<typeof Button>;
166
+
167
+ export const ConfirmationAction = (props: ConfirmationActionProps) => (
168
+ <Button className="h-8 px-3 text-sm" type="button" {...props} />
169
+ );
@@ -0,0 +1,28 @@
1
+ import type { ConnectionLineComponent } from "@xyflow/react";
2
+
3
+ const HALF = 0.5;
4
+
5
+ export const Connection: ConnectionLineComponent = ({
6
+ fromX,
7
+ fromY,
8
+ toX,
9
+ toY,
10
+ }) => (
11
+ <g>
12
+ <path
13
+ className="animated"
14
+ d={`M${fromX},${fromY} C ${fromX + (toX - fromX) * HALF},${fromY} ${fromX + (toX - fromX) * HALF},${toY} ${toX},${toY}`}
15
+ fill="none"
16
+ stroke="var(--color-ring)"
17
+ strokeWidth={1}
18
+ />
19
+ <circle
20
+ cx={toX}
21
+ cy={toY}
22
+ fill="var(--background)"
23
+ r={3}
24
+ stroke="var(--color-ring)"
25
+ strokeWidth={1}
26
+ />
27
+ </g>
28
+ );
@@ -0,0 +1,408 @@
1
+ "use client";
2
+
3
+ import { Button } from "@/components/ui/button";
4
+ import {
5
+ HoverCard,
6
+ HoverCardContent,
7
+ HoverCardTrigger,
8
+ } from "@/components/ui/hover-card";
9
+ import { Progress } from "@/components/ui/progress";
10
+ import { cn } from "@/lib/utils";
11
+ import type { LanguageModelUsage } from "ai";
12
+ import { type ComponentProps, createContext, useContext } from "react";
13
+ import { getUsage } from "tokenlens";
14
+
15
+ const PERCENT_MAX = 100;
16
+ const ICON_RADIUS = 10;
17
+ const ICON_VIEWBOX = 24;
18
+ const ICON_CENTER = 12;
19
+ const ICON_STROKE_WIDTH = 2;
20
+
21
+ type ModelId = string;
22
+
23
+ type ContextSchema = {
24
+ usedTokens: number;
25
+ maxTokens: number;
26
+ usage?: LanguageModelUsage;
27
+ modelId?: ModelId;
28
+ };
29
+
30
+ const ContextContext = createContext<ContextSchema | null>(null);
31
+
32
+ const useContextValue = () => {
33
+ const context = useContext(ContextContext);
34
+
35
+ if (!context) {
36
+ throw new Error("Context components must be used within Context");
37
+ }
38
+
39
+ return context;
40
+ };
41
+
42
+ export type ContextProps = ComponentProps<typeof HoverCard> & ContextSchema;
43
+
44
+ export const Context = ({
45
+ usedTokens,
46
+ maxTokens,
47
+ usage,
48
+ modelId,
49
+ ...props
50
+ }: ContextProps) => (
51
+ <ContextContext.Provider
52
+ value={{
53
+ usedTokens,
54
+ maxTokens,
55
+ usage,
56
+ modelId,
57
+ }}
58
+ >
59
+ <HoverCard closeDelay={0} openDelay={0} {...props} />
60
+ </ContextContext.Provider>
61
+ );
62
+
63
+ const ContextIcon = () => {
64
+ const { usedTokens, maxTokens } = useContextValue();
65
+ const circumference = 2 * Math.PI * ICON_RADIUS;
66
+ const usedPercent = usedTokens / maxTokens;
67
+ const dashOffset = circumference * (1 - usedPercent);
68
+
69
+ return (
70
+ <svg
71
+ aria-label="Model context usage"
72
+ height="20"
73
+ role="img"
74
+ style={{ color: "currentcolor" }}
75
+ viewBox={`0 0 ${ICON_VIEWBOX} ${ICON_VIEWBOX}`}
76
+ width="20"
77
+ >
78
+ <circle
79
+ cx={ICON_CENTER}
80
+ cy={ICON_CENTER}
81
+ fill="none"
82
+ opacity="0.25"
83
+ r={ICON_RADIUS}
84
+ stroke="currentColor"
85
+ strokeWidth={ICON_STROKE_WIDTH}
86
+ />
87
+ <circle
88
+ cx={ICON_CENTER}
89
+ cy={ICON_CENTER}
90
+ fill="none"
91
+ opacity="0.7"
92
+ r={ICON_RADIUS}
93
+ stroke="currentColor"
94
+ strokeDasharray={`${circumference} ${circumference}`}
95
+ strokeDashoffset={dashOffset}
96
+ strokeLinecap="round"
97
+ strokeWidth={ICON_STROKE_WIDTH}
98
+ style={{ transformOrigin: "center", transform: "rotate(-90deg)" }}
99
+ />
100
+ </svg>
101
+ );
102
+ };
103
+
104
+ export type ContextTriggerProps = ComponentProps<typeof Button>;
105
+
106
+ export const ContextTrigger = ({ children, ...props }: ContextTriggerProps) => {
107
+ const { usedTokens, maxTokens } = useContextValue();
108
+ const usedPercent = usedTokens / maxTokens;
109
+ const renderedPercent = new Intl.NumberFormat("en-US", {
110
+ style: "percent",
111
+ maximumFractionDigits: 1,
112
+ }).format(usedPercent);
113
+
114
+ return (
115
+ <HoverCardTrigger asChild>
116
+ {children ?? (
117
+ <Button type="button" variant="ghost" {...props}>
118
+ <span className="font-medium text-muted-foreground">
119
+ {renderedPercent}
120
+ </span>
121
+ <ContextIcon />
122
+ </Button>
123
+ )}
124
+ </HoverCardTrigger>
125
+ );
126
+ };
127
+
128
+ export type ContextContentProps = ComponentProps<typeof HoverCardContent>;
129
+
130
+ export const ContextContent = ({
131
+ className,
132
+ ...props
133
+ }: ContextContentProps) => (
134
+ <HoverCardContent
135
+ className={cn("min-w-60 divide-y overflow-hidden p-0", className)}
136
+ {...props}
137
+ />
138
+ );
139
+
140
+ export type ContextContentHeaderProps = ComponentProps<"div">;
141
+
142
+ export const ContextContentHeader = ({
143
+ children,
144
+ className,
145
+ ...props
146
+ }: ContextContentHeaderProps) => {
147
+ const { usedTokens, maxTokens } = useContextValue();
148
+ const usedPercent = usedTokens / maxTokens;
149
+ const displayPct = new Intl.NumberFormat("en-US", {
150
+ style: "percent",
151
+ maximumFractionDigits: 1,
152
+ }).format(usedPercent);
153
+ const used = new Intl.NumberFormat("en-US", {
154
+ notation: "compact",
155
+ }).format(usedTokens);
156
+ const total = new Intl.NumberFormat("en-US", {
157
+ notation: "compact",
158
+ }).format(maxTokens);
159
+
160
+ return (
161
+ <div className={cn("w-full space-y-2 p-3", className)} {...props}>
162
+ {children ?? (
163
+ <>
164
+ <div className="flex items-center justify-between gap-3 text-xs">
165
+ <p>{displayPct}</p>
166
+ <p className="font-mono text-muted-foreground">
167
+ {used} / {total}
168
+ </p>
169
+ </div>
170
+ <div className="space-y-2">
171
+ <Progress className="bg-muted" value={usedPercent * PERCENT_MAX} />
172
+ </div>
173
+ </>
174
+ )}
175
+ </div>
176
+ );
177
+ };
178
+
179
+ export type ContextContentBodyProps = ComponentProps<"div">;
180
+
181
+ export const ContextContentBody = ({
182
+ children,
183
+ className,
184
+ ...props
185
+ }: ContextContentBodyProps) => (
186
+ <div className={cn("w-full p-3", className)} {...props}>
187
+ {children}
188
+ </div>
189
+ );
190
+
191
+ export type ContextContentFooterProps = ComponentProps<"div">;
192
+
193
+ export const ContextContentFooter = ({
194
+ children,
195
+ className,
196
+ ...props
197
+ }: ContextContentFooterProps) => {
198
+ const { modelId, usage } = useContextValue();
199
+ const costUSD = modelId
200
+ ? getUsage({
201
+ modelId,
202
+ usage: {
203
+ input: usage?.inputTokens ?? 0,
204
+ output: usage?.outputTokens ?? 0,
205
+ },
206
+ }).costUSD?.totalUSD
207
+ : undefined;
208
+ const totalCost = new Intl.NumberFormat("en-US", {
209
+ style: "currency",
210
+ currency: "USD",
211
+ }).format(costUSD ?? 0);
212
+
213
+ return (
214
+ <div
215
+ className={cn(
216
+ "flex w-full items-center justify-between gap-3 bg-secondary p-3 text-xs",
217
+ className
218
+ )}
219
+ {...props}
220
+ >
221
+ {children ?? (
222
+ <>
223
+ <span className="text-muted-foreground">Total cost</span>
224
+ <span>{totalCost}</span>
225
+ </>
226
+ )}
227
+ </div>
228
+ );
229
+ };
230
+
231
+ export type ContextInputUsageProps = ComponentProps<"div">;
232
+
233
+ export const ContextInputUsage = ({
234
+ className,
235
+ children,
236
+ ...props
237
+ }: ContextInputUsageProps) => {
238
+ const { usage, modelId } = useContextValue();
239
+ const inputTokens = usage?.inputTokens ?? 0;
240
+
241
+ if (children) {
242
+ return children;
243
+ }
244
+
245
+ if (!inputTokens) {
246
+ return null;
247
+ }
248
+
249
+ const inputCost = modelId
250
+ ? getUsage({
251
+ modelId,
252
+ usage: { input: inputTokens, output: 0 },
253
+ }).costUSD?.totalUSD
254
+ : undefined;
255
+ const inputCostText = new Intl.NumberFormat("en-US", {
256
+ style: "currency",
257
+ currency: "USD",
258
+ }).format(inputCost ?? 0);
259
+
260
+ return (
261
+ <div
262
+ className={cn("flex items-center justify-between text-xs", className)}
263
+ {...props}
264
+ >
265
+ <span className="text-muted-foreground">Input</span>
266
+ <TokensWithCost costText={inputCostText} tokens={inputTokens} />
267
+ </div>
268
+ );
269
+ };
270
+
271
+ export type ContextOutputUsageProps = ComponentProps<"div">;
272
+
273
+ export const ContextOutputUsage = ({
274
+ className,
275
+ children,
276
+ ...props
277
+ }: ContextOutputUsageProps) => {
278
+ const { usage, modelId } = useContextValue();
279
+ const outputTokens = usage?.outputTokens ?? 0;
280
+
281
+ if (children) {
282
+ return children;
283
+ }
284
+
285
+ if (!outputTokens) {
286
+ return null;
287
+ }
288
+
289
+ const outputCost = modelId
290
+ ? getUsage({
291
+ modelId,
292
+ usage: { input: 0, output: outputTokens },
293
+ }).costUSD?.totalUSD
294
+ : undefined;
295
+ const outputCostText = new Intl.NumberFormat("en-US", {
296
+ style: "currency",
297
+ currency: "USD",
298
+ }).format(outputCost ?? 0);
299
+
300
+ return (
301
+ <div
302
+ className={cn("flex items-center justify-between text-xs", className)}
303
+ {...props}
304
+ >
305
+ <span className="text-muted-foreground">Output</span>
306
+ <TokensWithCost costText={outputCostText} tokens={outputTokens} />
307
+ </div>
308
+ );
309
+ };
310
+
311
+ export type ContextReasoningUsageProps = ComponentProps<"div">;
312
+
313
+ export const ContextReasoningUsage = ({
314
+ className,
315
+ children,
316
+ ...props
317
+ }: ContextReasoningUsageProps) => {
318
+ const { usage, modelId } = useContextValue();
319
+ const reasoningTokens = usage?.reasoningTokens ?? 0;
320
+
321
+ if (children) {
322
+ return children;
323
+ }
324
+
325
+ if (!reasoningTokens) {
326
+ return null;
327
+ }
328
+
329
+ const reasoningCost = modelId
330
+ ? getUsage({
331
+ modelId,
332
+ usage: { reasoningTokens },
333
+ }).costUSD?.totalUSD
334
+ : undefined;
335
+ const reasoningCostText = new Intl.NumberFormat("en-US", {
336
+ style: "currency",
337
+ currency: "USD",
338
+ }).format(reasoningCost ?? 0);
339
+
340
+ return (
341
+ <div
342
+ className={cn("flex items-center justify-between text-xs", className)}
343
+ {...props}
344
+ >
345
+ <span className="text-muted-foreground">Reasoning</span>
346
+ <TokensWithCost costText={reasoningCostText} tokens={reasoningTokens} />
347
+ </div>
348
+ );
349
+ };
350
+
351
+ export type ContextCacheUsageProps = ComponentProps<"div">;
352
+
353
+ export const ContextCacheUsage = ({
354
+ className,
355
+ children,
356
+ ...props
357
+ }: ContextCacheUsageProps) => {
358
+ const { usage, modelId } = useContextValue();
359
+ const cacheTokens = usage?.cachedInputTokens ?? 0;
360
+
361
+ if (children) {
362
+ return children;
363
+ }
364
+
365
+ if (!cacheTokens) {
366
+ return null;
367
+ }
368
+
369
+ const cacheCost = modelId
370
+ ? getUsage({
371
+ modelId,
372
+ usage: { cacheReads: cacheTokens, input: 0, output: 0 },
373
+ }).costUSD?.totalUSD
374
+ : undefined;
375
+ const cacheCostText = new Intl.NumberFormat("en-US", {
376
+ style: "currency",
377
+ currency: "USD",
378
+ }).format(cacheCost ?? 0);
379
+
380
+ return (
381
+ <div
382
+ className={cn("flex items-center justify-between text-xs", className)}
383
+ {...props}
384
+ >
385
+ <span className="text-muted-foreground">Cache</span>
386
+ <TokensWithCost costText={cacheCostText} tokens={cacheTokens} />
387
+ </div>
388
+ );
389
+ };
390
+
391
+ const TokensWithCost = ({
392
+ tokens,
393
+ costText,
394
+ }: {
395
+ tokens?: number;
396
+ costText?: string;
397
+ }) => (
398
+ <span>
399
+ {tokens === undefined
400
+ ? "—"
401
+ : new Intl.NumberFormat("en-US", {
402
+ notation: "compact",
403
+ }).format(tokens)}
404
+ {costText ? (
405
+ <span className="ml-2 text-muted-foreground">• {costText}</span>
406
+ ) : null}
407
+ </span>
408
+ );
@@ -0,0 +1,18 @@
1
+ "use client";
2
+
3
+ import { cn } from "@/lib/utils";
4
+ import { Controls as ControlsPrimitive } from "@xyflow/react";
5
+ import type { ComponentProps } from "react";
6
+
7
+ export type ControlsProps = ComponentProps<typeof ControlsPrimitive>;
8
+
9
+ export const Controls = ({ className, ...props }: ControlsProps) => (
10
+ <ControlsPrimitive
11
+ className={cn(
12
+ "gap-px overflow-hidden rounded-md border bg-card p-1 shadow-none!",
13
+ "[&>button]:rounded-md [&>button]:border-none! [&>button]:bg-transparent! [&>button]:hover:bg-secondary!",
14
+ className
15
+ )}
16
+ {...props}
17
+ />
18
+ );
@@ -0,0 +1,97 @@
1
+ "use client";
2
+
3
+ import { Button } from "@/components/ui/button";
4
+ import { cn } from "@/lib/utils";
5
+ import { ArrowDownIcon } from "lucide-react";
6
+ import type { ComponentProps } from "react";
7
+ import { useCallback } from "react";
8
+ import { StickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
9
+
10
+ export type ConversationProps = ComponentProps<typeof StickToBottom>;
11
+
12
+ export const Conversation = ({ className, ...props }: ConversationProps) => (
13
+ <StickToBottom
14
+ className={cn("relative flex-1 overflow-y-auto", className)}
15
+ initial="smooth"
16
+ resize="smooth"
17
+ role="log"
18
+ {...props}
19
+ />
20
+ );
21
+
22
+ export type ConversationContentProps = ComponentProps<
23
+ typeof StickToBottom.Content
24
+ >;
25
+
26
+ export const ConversationContent = ({
27
+ className,
28
+ ...props
29
+ }: ConversationContentProps) => (
30
+ <StickToBottom.Content className={cn("p-4", className)} {...props} />
31
+ );
32
+
33
+ export type ConversationEmptyStateProps = ComponentProps<"div"> & {
34
+ title?: string;
35
+ description?: string;
36
+ icon?: React.ReactNode;
37
+ };
38
+
39
+ export const ConversationEmptyState = ({
40
+ className,
41
+ title = "No messages yet",
42
+ description = "Start a conversation to see messages here",
43
+ icon,
44
+ children,
45
+ ...props
46
+ }: ConversationEmptyStateProps) => (
47
+ <div
48
+ className={cn(
49
+ "flex size-full flex-col items-center justify-center gap-3 p-8 text-center",
50
+ className
51
+ )}
52
+ {...props}
53
+ >
54
+ {children ?? (
55
+ <>
56
+ {icon && <div className="text-muted-foreground">{icon}</div>}
57
+ <div className="space-y-1">
58
+ <h3 className="font-medium text-sm">{title}</h3>
59
+ {description && (
60
+ <p className="text-muted-foreground text-sm">{description}</p>
61
+ )}
62
+ </div>
63
+ </>
64
+ )}
65
+ </div>
66
+ );
67
+
68
+ export type ConversationScrollButtonProps = ComponentProps<typeof Button>;
69
+
70
+ export const ConversationScrollButton = ({
71
+ className,
72
+ ...props
73
+ }: ConversationScrollButtonProps) => {
74
+ const { isAtBottom, scrollToBottom } = useStickToBottomContext();
75
+
76
+ const handleScrollToBottom = useCallback(() => {
77
+ scrollToBottom();
78
+ }, [scrollToBottom]);
79
+
80
+ return (
81
+ !isAtBottom && (
82
+ <Button
83
+ className={cn(
84
+ "absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",
85
+ className
86
+ )}
87
+ onClick={handleScrollToBottom}
88
+ size="icon"
89
+ type="button"
90
+ variant="outline"
91
+ {...props}
92
+ >
93
+ <ArrowDownIcon className="size-4" />
94
+ </Button>
95
+ )
96
+ );
97
+ };