diff options
| author | Kartik <[email protected]> | 2024-06-15 20:36:41 +0530 |
|---|---|---|
| committer | Kartik <[email protected]> | 2024-06-15 20:36:41 +0530 |
| commit | 8ecfc654c77262a40f8458b2b4e44c163ad094bd (patch) | |
| tree | 1c2b3ad23bb55808acf98f0229b13d2f7e8649ef /packages | |
| parent | chore: Remove unused variables and dependencies (diff) | |
| parent | getspaces and other features integrated with the backend (diff) | |
| download | supermemory-8ecfc654c77262a40f8458b2b4e44c163ad094bd.tar.xz supermemory-8ecfc654c77262a40f8458b2b4e44c163ad094bd.zip | |
Merge branch 'codetorso' of https://github.com/Dhravya/supermemory into codetorso
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/shared-types/index.ts | 61 | ||||
| -rw-r--r-- | packages/tailwind-config/globals.css | 123 | ||||
| -rw-r--r-- | packages/tailwind-config/tailwind.config.ts | 6 | ||||
| -rw-r--r-- | packages/ui/shadcn/accordion.tsx | 54 | ||||
| -rw-r--r-- | packages/ui/shadcn/select.tsx | 160 | ||||
| -rw-r--r-- | packages/ui/shadcn/sonner.tsx | 31 |
6 files changed, 427 insertions, 8 deletions
diff --git a/packages/shared-types/index.ts b/packages/shared-types/index.ts index bf4a56da..46e3edba 100644 --- a/packages/shared-types/index.ts +++ b/packages/shared-types/index.ts @@ -1,7 +1,54 @@ -export type ChatHistory = { - question: string; - answer: { - parts: { text: string }[]; - sources: { isNote: boolean; source: string }[]; - }; -}; +import { z } from "zod"; + +export const ChatHistoryZod = z.object({ + question: z.string(), + answer: z.object({ + parts: z.array(z.object({ text: z.string() })), + sources: z.array( + z.object({ + type: z.enum(["note", "page", "tweet"]), + source: z.string(), + title: z.string(), + content: z.string(), + }), + ), + }), +}); + +export type ChatHistory = z.infer<typeof ChatHistoryZod>; + +export const ModelCompatibleChatHistoryZod = z.array( + z.object({ + role: z.union([ + z.literal("user"), + z.literal("assistant"), + z.literal("system"), + ]), + content: z.string(), + }), +); + +export type ModelCompatibleChatHistory = z.infer< + typeof ModelCompatibleChatHistoryZod +>; + +export function convertChatHistoryList( + chatHistoryList: ChatHistory[], +): ModelCompatibleChatHistory { + let convertedChats: ModelCompatibleChatHistory = []; + + chatHistoryList.forEach((chat) => { + convertedChats.push( + { + role: "user", + content: chat.question, + }, + { + role: "assistant", + content: chat.answer.parts.map((part) => part.text).join(" "), + }, + ); + }); + + return convertedChats; +} diff --git a/packages/tailwind-config/globals.css b/packages/tailwind-config/globals.css index 18017f73..d845aca4 100644 --- a/packages/tailwind-config/globals.css +++ b/packages/tailwind-config/globals.css @@ -49,6 +49,42 @@ body { align-items: center; justify-content: center; } + + .markdown table { + --tw-border-spacing-x: 0px; + --tw-border-spacing-y: 0px; + border-collapse: separate; + border-spacing: var(--tw-border-spacing-x) var(--tw-border-spacing-y); + width: 100%; + } + .markdown th { + background-color: rgba(236, 236, 241, 0.2); + border-bottom-width: 1px; + border-left-width: 1px; + border-top-width: 1px; + padding: 0.25rem 0.75rem; + } + .markdown th:first-child { + border-top-left-radius: 0.375rem; + } + .markdown th:last-child { + border-right-width: 1px; + border-top-right-radius: 0.375rem; + } + .markdown td { + border-bottom-width: 1px; + border-left-width: 1px; + padding: 0.25rem 0.75rem; + } + .markdown td:last-child { + border-right-width: 1px; + } + .markdown tbody tr:last-child td:first-child { + border-bottom-left-radius: 0.375rem; + } + .markdown tbody tr:last-child td:last-child { + border-bottom-right-radius: 0.375rem; + } } @layer utilities { @@ -57,6 +93,34 @@ body { } } +@layer components { + .markdown ol, + .markdown ul { + display: flex; + flex-direction: column; + padding-left: 1rem; + } + + .markdown ol li, + .markdown ol li > p, + .markdown ol ol, + .markdown ol ul, + .markdown ul li, + .markdown ul li > p, + .markdown ul ol, + .markdown ul ul { + margin: 0; + } + + .markdown ul li:before { + content: "•"; + font-size: 0.875rem; + line-height: 1.25rem; + margin-left: -1rem; + position: absolute; + } +} + .gradient-background { background: linear-gradient( 150deg, @@ -84,3 +148,62 @@ body { ::-webkit-scrollbar-thumb:hover { background: #22303d; } + +.no-scrollbar { + /* For WebKit (Safari, Chrome, etc.) */ + &::-webkit-scrollbar { + display: none; + } + + /* For Firefox */ + scrollbar-width: none; + + /* For IE and Edge */ + -ms-overflow-style: none; +} + +:not(pre) > code.hljs, +:not(pre) > code[class*="language-"] { + border-radius: 0.3em; + white-space: normal; +} +.hljs-comment { + color: hsla(0, 0%, 100%, 0.5); +} +.hljs-meta { + color: hsla(0, 0%, 100%, 0.6); +} +.hljs-built_in, +.hljs-class .hljs-title { + color: #e9950c; +} +.hljs-doctag, +.hljs-formula, +.hljs-keyword, +.hljs-literal { + color: #2e95d3; +} +.hljs-addition, +.hljs-attribute, +.hljs-meta-string, +.hljs-regexp, +.hljs-string { + color: #00a67d; +} +.hljs-attr, +.hljs-number, +.hljs-selector-attr, +.hljs-selector-class, +.hljs-selector-pseudo, +.hljs-template-variable, +.hljs-type, +.hljs-variable { + color: #df3079; +} +.hljs-bullet, +.hljs-link, +.hljs-selector-id, +.hljs-symbol, +.hljs-title { + color: #f22c3d; +} diff --git a/packages/tailwind-config/tailwind.config.ts b/packages/tailwind-config/tailwind.config.ts index bf36b528..3711bd41 100644 --- a/packages/tailwind-config/tailwind.config.ts +++ b/packages/tailwind-config/tailwind.config.ts @@ -71,7 +71,11 @@ const config = { }, }, }, - plugins: [require("tailwindcss-animate"), require("@tailwindcss/typography")], + plugins: [ + require("tailwindcss-animate"), + require("@tailwindcss/typography"), + require("tailwind-scrollbar"), + ], } satisfies Config; export default config; diff --git a/packages/ui/shadcn/accordion.tsx b/packages/ui/shadcn/accordion.tsx new file mode 100644 index 00000000..a5dedb19 --- /dev/null +++ b/packages/ui/shadcn/accordion.tsx @@ -0,0 +1,54 @@ +"use client"; + +import * as React from "react"; +import * as AccordionPrimitive from "@radix-ui/react-accordion"; +import { ChevronDown } from "lucide-react"; + +import { cn } from "@repo/ui/lib/utils"; + +const Accordion = AccordionPrimitive.Root; + +const AccordionItem = React.forwardRef< + React.ElementRef<typeof AccordionPrimitive.Item>, + React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item> +>(({ className, ...props }, ref) => ( + <AccordionPrimitive.Item ref={ref} className={cn(className)} {...props} /> +)); +AccordionItem.displayName = "AccordionItem"; + +const AccordionTrigger = React.forwardRef< + React.ElementRef<typeof AccordionPrimitive.Trigger>, + React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger> +>(({ className, children, ...props }, ref) => ( + <AccordionPrimitive.Header className="flex"> + <AccordionPrimitive.Trigger + ref={ref} + className={cn( + "flex flex-1 items-center gap-2 py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180", + className, + )} + {...props} + > + {children} + <ChevronDown className="h-4 w-4 shrink-0 transition-transform duration-200" /> + </AccordionPrimitive.Trigger> + </AccordionPrimitive.Header> +)); +AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName; + +const AccordionContent = React.forwardRef< + React.ElementRef<typeof AccordionPrimitive.Content>, + React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content> +>(({ className, children, ...props }, ref) => ( + <AccordionPrimitive.Content + ref={ref} + className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down" + {...props} + > + <div className={cn("pb-4 pt-0", className)}>{children}</div> + </AccordionPrimitive.Content> +)); + +AccordionContent.displayName = AccordionPrimitive.Content.displayName; + +export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }; diff --git a/packages/ui/shadcn/select.tsx b/packages/ui/shadcn/select.tsx new file mode 100644 index 00000000..8abe27c1 --- /dev/null +++ b/packages/ui/shadcn/select.tsx @@ -0,0 +1,160 @@ +"use client"; + +import * as React from "react"; +import * as SelectPrimitive from "@radix-ui/react-select"; +import { Check, ChevronDown, ChevronUp } from "lucide-react"; + +import { cn } from "@repo/ui/lib/utils"; + +const Select = SelectPrimitive.Root; + +const SelectGroup = SelectPrimitive.Group; + +const SelectValue = SelectPrimitive.Value; + +const SelectTrigger = React.forwardRef< + React.ElementRef<typeof SelectPrimitive.Trigger>, + React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> +>(({ className, children, ...props }, ref) => ( + <SelectPrimitive.Trigger + ref={ref} + className={cn( + "flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", + className, + )} + {...props} + > + {children} + <SelectPrimitive.Icon asChild> + <ChevronDown className="h-4 w-4 opacity-50" /> + </SelectPrimitive.Icon> + </SelectPrimitive.Trigger> +)); +SelectTrigger.displayName = SelectPrimitive.Trigger.displayName; + +const SelectScrollUpButton = React.forwardRef< + React.ElementRef<typeof SelectPrimitive.ScrollUpButton>, + React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton> +>(({ className, ...props }, ref) => ( + <SelectPrimitive.ScrollUpButton + ref={ref} + className={cn( + "flex cursor-default items-center justify-center py-1", + className, + )} + {...props} + > + <ChevronUp className="h-4 w-4" /> + </SelectPrimitive.ScrollUpButton> +)); +SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName; + +const SelectScrollDownButton = React.forwardRef< + React.ElementRef<typeof SelectPrimitive.ScrollDownButton>, + React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton> +>(({ className, ...props }, ref) => ( + <SelectPrimitive.ScrollDownButton + ref={ref} + className={cn( + "flex cursor-default items-center justify-center py-1", + className, + )} + {...props} + > + <ChevronDown className="h-4 w-4" /> + </SelectPrimitive.ScrollDownButton> +)); +SelectScrollDownButton.displayName = + SelectPrimitive.ScrollDownButton.displayName; + +const SelectContent = React.forwardRef< + React.ElementRef<typeof SelectPrimitive.Content>, + React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content> +>(({ className, children, position = "popper", ...props }, ref) => ( + <SelectPrimitive.Portal> + <SelectPrimitive.Content + ref={ref} + className={cn( + "relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out 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", + position === "popper" && + "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", + className, + )} + position={position} + {...props} + > + <SelectScrollUpButton /> + <SelectPrimitive.Viewport + className={cn( + "p-1", + position === "popper" && + "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]", + )} + > + {children} + </SelectPrimitive.Viewport> + <SelectScrollDownButton /> + </SelectPrimitive.Content> + </SelectPrimitive.Portal> +)); +SelectContent.displayName = SelectPrimitive.Content.displayName; + +const SelectLabel = React.forwardRef< + React.ElementRef<typeof SelectPrimitive.Label>, + React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label> +>(({ className, ...props }, ref) => ( + <SelectPrimitive.Label + ref={ref} + className={cn("py-1.5 pl-8 pr-2 text-sm font-semibold", className)} + {...props} + /> +)); +SelectLabel.displayName = SelectPrimitive.Label.displayName; + +const SelectItem = React.forwardRef< + React.ElementRef<typeof SelectPrimitive.Item>, + React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item> +>(({ className, children, ...props }, ref) => ( + <SelectPrimitive.Item + ref={ref} + className={cn( + "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-foreground-menu data-[disabled]:pointer-events-none data-[disabled]:opacity-50", + className, + )} + {...props} + > + <span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center"> + <SelectPrimitive.ItemIndicator> + <Check className="h-4 w-4" /> + </SelectPrimitive.ItemIndicator> + </span> + + <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText> + </SelectPrimitive.Item> +)); +SelectItem.displayName = SelectPrimitive.Item.displayName; + +const SelectSeparator = React.forwardRef< + React.ElementRef<typeof SelectPrimitive.Separator>, + React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator> +>(({ className, ...props }, ref) => ( + <SelectPrimitive.Separator + ref={ref} + className={cn("-mx-1 my-1 h-px bg-muted", className)} + {...props} + /> +)); +SelectSeparator.displayName = SelectPrimitive.Separator.displayName; + +export { + Select, + SelectGroup, + SelectValue, + SelectTrigger, + SelectContent, + SelectLabel, + SelectItem, + SelectSeparator, + SelectScrollUpButton, + SelectScrollDownButton, +}; diff --git a/packages/ui/shadcn/sonner.tsx b/packages/ui/shadcn/sonner.tsx new file mode 100644 index 00000000..549cf841 --- /dev/null +++ b/packages/ui/shadcn/sonner.tsx @@ -0,0 +1,31 @@ +"use client"; + +import { useTheme } from "next-themes"; +import { Toaster as Sonner } from "sonner"; + +type ToasterProps = React.ComponentProps<typeof Sonner>; + +const Toaster = ({ ...props }: ToasterProps) => { + const { theme = "system" } = useTheme(); + + return ( + <Sonner + theme={theme as ToasterProps["theme"]} + className="toaster group" + toastOptions={{ + classNames: { + toast: + "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg", + description: "group-[.toast]:text-muted-foreground", + actionButton: + "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground", + cancelButton: + "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground", + }, + }} + {...props} + /> + ); +}; + +export { Toaster }; |