@tetrascience-npm/tetrascience-react-ui 0.5.0-beta.40.1 → 0.5.0-beta.41.1
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/dist/components/ai/attachments.cjs +2 -0
- package/dist/components/ai/attachments.cjs.map +1 -0
- package/dist/components/ai/attachments.js +224 -0
- package/dist/components/ai/attachments.js.map +1 -0
- package/dist/components/ai/chain-of-thought.cjs +2 -0
- package/dist/components/ai/chain-of-thought.cjs.map +1 -0
- package/dist/components/ai/chain-of-thought.js +145 -0
- package/dist/components/ai/chain-of-thought.js.map +1 -0
- package/dist/components/ai/confirmation.cjs +2 -0
- package/dist/components/ai/confirmation.cjs.map +1 -0
- package/dist/components/ai/confirmation.js +109 -0
- package/dist/components/ai/confirmation.js.map +1 -0
- package/dist/components/ai/context.cjs +2 -0
- package/dist/components/ai/context.cjs.map +1 -0
- package/dist/components/ai/context.js +266 -0
- package/dist/components/ai/context.js.map +1 -0
- package/dist/components/ai/conversation.cjs +4 -0
- package/dist/components/ai/conversation.cjs.map +1 -0
- package/dist/components/ai/conversation.js +108 -0
- package/dist/components/ai/conversation.js.map +1 -0
- package/dist/components/ai/inline-citation.cjs +2 -0
- package/dist/components/ai/inline-citation.cjs.map +1 -0
- package/dist/components/ai/inline-citation.js +182 -0
- package/dist/components/ai/inline-citation.js.map +1 -0
- package/dist/components/ai/message.cjs +2 -0
- package/dist/components/ai/message.cjs.map +1 -0
- package/dist/components/ai/message.js +237 -0
- package/dist/components/ai/message.js.map +1 -0
- package/dist/components/ai/model-selector.cjs +2 -0
- package/dist/components/ai/model-selector.cjs.map +1 -0
- package/dist/components/ai/model-selector.js +77 -0
- package/dist/components/ai/model-selector.js.map +1 -0
- package/dist/components/ai/prompt-input.cjs +2 -0
- package/dist/components/ai/prompt-input.cjs.map +1 -0
- package/dist/components/ai/prompt-input.js +774 -0
- package/dist/components/ai/prompt-input.js.map +1 -0
- package/dist/components/ai/queue.cjs +2 -0
- package/dist/components/ai/queue.cjs.map +1 -0
- package/dist/components/ai/queue.js +209 -0
- package/dist/components/ai/queue.js.map +1 -0
- package/dist/components/ai/reasoning.cjs +2 -0
- package/dist/components/ai/reasoning.cjs.map +1 -0
- package/dist/components/ai/reasoning.js +129 -0
- package/dist/components/ai/reasoning.js.map +1 -0
- package/dist/components/ai/shimmer.cjs +2 -0
- package/dist/components/ai/shimmer.cjs.map +1 -0
- package/dist/components/ai/shimmer.js +49 -0
- package/dist/components/ai/shimmer.js.map +1 -0
- package/dist/components/ai/sources.cjs +2 -0
- package/dist/components/ai/sources.cjs.map +1 -0
- package/dist/components/ai/sources.js +54 -0
- package/dist/components/ai/sources.js.map +1 -0
- package/dist/components/ai/speech-input.cjs +2 -0
- package/dist/components/ai/speech-input.cjs.map +1 -0
- package/dist/components/ai/speech-input.js +123 -0
- package/dist/components/ai/speech-input.js.map +1 -0
- package/dist/components/ai/stream-status.cjs +2 -0
- package/dist/components/ai/stream-status.cjs.map +1 -0
- package/dist/components/ai/stream-status.js +106 -0
- package/dist/components/ai/stream-status.js.map +1 -0
- package/dist/components/ai/suggestion.cjs +2 -0
- package/dist/components/ai/suggestion.cjs.map +1 -0
- package/dist/components/ai/suggestion.js +38 -0
- package/dist/components/ai/suggestion.js.map +1 -0
- package/dist/components/ai/task.cjs +2 -0
- package/dist/components/ai/task.cjs.map +1 -0
- package/dist/components/ai/task.js +94 -0
- package/dist/components/ai/task.js.map +1 -0
- package/dist/components/ai/tool.cjs +2 -0
- package/dist/components/ai/tool.cjs.map +1 -0
- package/dist/components/ai/tool.js +143 -0
- package/dist/components/ai/tool.js.map +1 -0
- package/dist/components/composed/Chat/Chat.cjs +2 -0
- package/dist/components/composed/Chat/Chat.cjs.map +1 -0
- package/dist/components/composed/Chat/Chat.js +167 -0
- package/dist/components/composed/Chat/Chat.js.map +1 -0
- package/dist/components/ui/code-block.cjs +4 -0
- package/dist/components/ui/code-block.cjs.map +1 -0
- package/dist/components/ui/code-block.js +306 -0
- package/dist/components/ui/code-block.js.map +1 -0
- package/dist/components/ui/progress.cjs +2 -0
- package/dist/components/ui/progress.cjs.map +1 -0
- package/dist/components/ui/progress.js +32 -0
- package/dist/components/ui/progress.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1145 -0
- package/dist/index.js +574 -372
- package/dist/index.js.map +1 -1
- package/dist/index.tailwind.css +1 -1
- package/package.json +12 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation.js","sources":["../../../src/components/ai/conversation.tsx"],"sourcesContent":["import { ArrowDownIcon, DownloadIcon } from \"lucide-react\";\nimport { useCallback } from \"react\";\nimport { StickToBottom, useStickToBottomContext } from \"use-stick-to-bottom\";\n\nimport type { UIMessage } from \"ai\";\nimport type { ComponentProps } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ConversationProps = ComponentProps<typeof StickToBottom>;\n\nexport const Conversation = ({ className, ...props }: ConversationProps) => (\n <StickToBottom\n className={cn(\"relative flex-1 overflow-y-hidden\", className)}\n initial=\"smooth\"\n resize=\"smooth\"\n role=\"log\"\n {...props}\n />\n);\n\nexport type ConversationContentProps = ComponentProps<\n typeof StickToBottom.Content\n>;\n\nexport const ConversationContent = ({\n className,\n ...props\n}: ConversationContentProps) => (\n <StickToBottom.Content\n className={cn(\"flex flex-col gap-8 p-4\", className)}\n {...props}\n />\n);\n\nexport type ConversationEmptyStateProps = ComponentProps<\"div\"> & {\n title?: string;\n description?: string;\n icon?: React.ReactNode;\n};\n\nexport const ConversationEmptyState = ({\n className,\n title = \"No messages yet\",\n description = \"Start a conversation to see messages here\",\n icon,\n children,\n ...props\n}: ConversationEmptyStateProps) => (\n <div\n className={cn(\n \"flex size-full flex-col items-center justify-center gap-3 p-8 text-center\",\n className\n )}\n {...props}\n >\n {children ?? (\n <>\n {icon && <div className=\"text-muted-foreground\">{icon}</div>}\n <div className=\"space-y-1\">\n <h3 className=\"font-medium text-sm\">{title}</h3>\n {description && (\n <p className=\"text-muted-foreground text-sm\">{description}</p>\n )}\n </div>\n </>\n )}\n </div>\n);\n\nexport type ConversationScrollButtonProps = ComponentProps<typeof Button>;\n\nexport const ConversationScrollButton = ({\n className,\n ...props\n}: ConversationScrollButtonProps) => {\n const { isAtBottom, scrollToBottom } = useStickToBottomContext();\n\n const handleScrollToBottom = useCallback(() => {\n scrollToBottom();\n }, [scrollToBottom]);\n\n return (\n !isAtBottom && (\n <Button\n className={cn(\n \"absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full dark:bg-background dark:hover:bg-muted\",\n className\n )}\n onClick={handleScrollToBottom}\n size=\"icon\"\n type=\"button\"\n variant=\"outline\"\n {...props}\n >\n <ArrowDownIcon className=\"size-4\" />\n </Button>\n )\n );\n};\n\nconst getMessageText = (message: UIMessage): string =>\n message.parts\n .filter((part) => part.type === \"text\")\n .map((part) => part.text)\n .join(\"\");\n\nexport type ConversationDownloadProps = Omit<\n ComponentProps<typeof Button>,\n \"onClick\"\n> & {\n messages: UIMessage[];\n filename?: string;\n formatMessage?: (message: UIMessage, index: number) => string;\n};\n\nconst defaultFormatMessage = (message: UIMessage): string => {\n const roleLabel =\n message.role.charAt(0).toUpperCase() + message.role.slice(1);\n return `**${roleLabel}:** ${getMessageText(message)}`;\n};\n\nexport const messagesToMarkdown = (\n messages: UIMessage[],\n formatMessage: (\n message: UIMessage,\n index: number\n ) => string = defaultFormatMessage\n): string => messages.map((msg, i) => formatMessage(msg, i)).join(\"\\n\\n\");\n\nexport const ConversationDownload = ({\n messages,\n filename = \"conversation.md\",\n formatMessage = defaultFormatMessage,\n className,\n children,\n ...props\n}: ConversationDownloadProps) => {\n const handleDownload = useCallback(() => {\n const markdown = messagesToMarkdown(messages, formatMessage);\n const blob = new Blob([markdown], { type: \"text/markdown\" });\n const url = URL.createObjectURL(blob);\n const link = document.createElement(\"a\");\n link.href = url;\n link.download = filename;\n document.body.append(link);\n link.click();\n link.remove();\n URL.revokeObjectURL(url);\n }, [messages, filename, formatMessage]);\n\n return (\n <Button\n className={cn(\n \"absolute top-4 right-4 rounded-full dark:bg-background dark:hover:bg-muted\",\n className\n )}\n onClick={handleDownload}\n size=\"icon\"\n type=\"button\"\n variant=\"outline\"\n {...props}\n >\n {children ?? <DownloadIcon className=\"size-4\" />}\n </Button>\n );\n};\n"],"names":["Conversation","className","props","jsx","StickToBottom","cn","ConversationContent","ConversationEmptyState","title","description","icon","children","jsxs","Fragment","ConversationScrollButton","isAtBottom","scrollToBottom","useStickToBottomContext","handleScrollToBottom","useCallback","Button","ArrowDownIcon","getMessageText","message","part","defaultFormatMessage","messagesToMarkdown","messages","formatMessage","msg","i","ConversationDownload","filename","handleDownload","markdown","blob","url","link","DownloadIcon"],"mappings":";;;;;;AAYO,MAAMA,IAAe,CAAC,EAAE,WAAAC,GAAW,GAAGC,QAC3C,gBAAAC;AAAA,EAACC;AAAA,EAAA;AAAA,IACC,WAAWC,EAAG,qCAAqCJ,CAAS;AAAA,IAC5D,SAAQ;AAAA,IACR,QAAO;AAAA,IACP,MAAK;AAAA,IACJ,GAAGC;AAAA,EAAA;AACN,GAOWI,IAAsB,CAAC;AAAA,EAClC,WAAAL;AAAA,EACA,GAAGC;AACL,MACE,gBAAAC;AAAA,EAACC,EAAc;AAAA,EAAd;AAAA,IACC,WAAWC,EAAG,2BAA2BJ,CAAS;AAAA,IACjD,GAAGC;AAAA,EAAA;AACN,GASWK,IAAyB,CAAC;AAAA,EACrC,WAAAN;AAAA,EACA,OAAAO,IAAQ;AAAA,EACR,aAAAC,IAAc;AAAA,EACd,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,GAAGT;AACL,MACE,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,WAAWE;AAAA,MACT;AAAA,MACAJ;AAAA,IAAA;AAAA,IAED,GAAGC;AAAA,IAEH,eACC,gBAAAU,EAAAC,GAAA,EACG,UAAA;AAAA,MAAAH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AA,CAAM,GAE3DC,IAAuB,CAAC;AAAA,EACnC,UAAAJ;AAAA,EACA,UAAAK,IAAW;AAAA,EACX,eAAAJ,IAAgBH;AAAA,EAChB,WAAAxB;AAAA,EACA,UAAAU;AAAA,EACA,GAAGT;AACL,MAAiC;AAC/B,QAAM+B,IAAiBd,EAAY,MAAM;AACvC,UAAMe,IAAWR,EAAmBC,GAAUC,CAAa,GACrDO,IAAO,IAAI,KAAK,CAACD,CAAQ,GAAG,EAAE,MAAM,iBAAiB,GACrDE,IAAM,IAAI,gBAAgBD,CAAI,GAC9BE,IAAO,SAAS,cAAc,GAAG;AACvC,IAAAA,EAAK,OAAOD,GACZC,EAAK,WAAWL,GAChB,SAAS,KAAK,OAAOK,CAAI,GACzBA,EAAK,MAAA,GACLA,EAAK,OAAA,GACL,IAAI,gBAAgBD,CAAG;AAAA,EACzB,GAAG,CAACT,GAAUK,GAAUJ,CAAa,CAAC;AAEtC,SACE,gBAAAzB;AAAA,IAACiB;AAAA,IAAA;AAAA,MACC,WAAWf;AAAA,QACT;AAAA,QACAJ;AAAA,MAAA;AAAA,MAEF,SAASgC;AAAA,MACT,MAAK;AAAA,MACL,MAAK;AAAA,MACL,SAAQ;AAAA,MACP,GAAG/B;AAAA,MAEH,UAAAS,KAAY,gBAAAR,EAACmC,GAAA,EAAa,WAAU,SAAA,CAAS;AAAA,IAAA;AAAA,EAAA;AAGpD;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),x=require("lucide-react"),o=require("react"),p=require("../ui/badge.cjs"),u=require("../ui/carousel.cjs"),C=require("../ui/hover-card.cjs"),s=require("../../lib/utils.cjs"),h=({className:e,...t})=>n.jsx("span",{className:s.cn("group inline items-center gap-1",e),...t}),j=({className:e,...t})=>n.jsx("span",{className:s.cn("transition-colors group-hover:bg-accent",e),...t}),f=e=>{try{return new URL(e).hostname}catch{return e}},N=e=>n.jsx(C.HoverCard,{closeDelay:0,openDelay:0,...e}),b=({sources:e,className:t,...i})=>n.jsx(C.HoverCardTrigger,{asChild:!0,children:n.jsx(p.Badge,{className:s.cn("ml-1 rounded-full",t),variant:"secondary",...i,children:e[0]?n.jsxs(n.Fragment,{children:[f(e[0])," ",e.length>1&&`+${e.length-1}`]}):"unknown"})}),v=({className:e,...t})=>n.jsx(C.HoverCardContent,{className:s.cn("relative w-80 p-0",e),...t}),m=o.createContext(void 0),d=()=>o.useContext(m),y=({className:e,children:t,...i})=>{const[a,r]=o.useState();return n.jsx(m.Provider,{value:a,children:n.jsx(u.Carousel,{className:s.cn("w-full",e),setApi:r,...i,children:t})})},k=e=>n.jsx(u.CarouselContent,{...e}),S=({className:e,...t})=>n.jsx(u.CarouselItem,{className:s.cn("w-full space-y-2 p-4 pl-8",e),...t}),q=({className:e,...t})=>n.jsx("div",{className:s.cn("flex items-center justify-between gap-2 rounded-t-md bg-secondary p-2",e),...t}),w=({children:e,className:t,...i})=>{const a=d(),[r,c]=o.useState(0),[I,g]=o.useState(0),l=o.useCallback(()=>{a&&(g(a.scrollSnapList().length),c(a.selectedScrollSnap()+1))},[a]);return o.useEffect(()=>{if(a)return l(),a.on("select",l),()=>{a.off("select",l)}},[a,l]),n.jsx("div",{className:s.cn("flex flex-1 items-center justify-end px-3 py-1 text-muted-foreground text-xs",t),...i,children:e??`${r}/${I}`})},H=({className:e,...t})=>{const i=d(),a=o.useCallback(()=>{i&&i.scrollPrev()},[i]);return n.jsx("button",{"aria-label":"Previous",className:s.cn("shrink-0",e),onClick:a,type:"button",...t,children:n.jsx(x.ArrowLeftIcon,{className:"size-4 text-muted-foreground"})})},P=({className:e,...t})=>{const i=d(),a=o.useCallback(()=>{i&&i.scrollNext()},[i]);return n.jsx("button",{"aria-label":"Next",className:s.cn("shrink-0",e),onClick:a,type:"button",...t,children:n.jsx(x.ArrowRightIcon,{className:"size-4 text-muted-foreground"})})},T=({title:e,url:t,description:i,className:a,children:r,...c})=>n.jsxs("div",{className:s.cn("space-y-1",a),...c,children:[e&&n.jsx("h4",{className:"truncate font-medium text-sm leading-tight",children:e}),t&&n.jsx("p",{className:"truncate break-all text-muted-foreground text-xs",children:t}),i&&n.jsx("p",{className:"line-clamp-3 text-muted-foreground text-sm leading-relaxed",children:i}),r]}),A=({children:e,className:t,...i})=>n.jsx("blockquote",{className:s.cn("border-muted border-l-2 pl-3 text-muted-foreground text-sm italic",t),...i,children:e});exports.InlineCitation=h;exports.InlineCitationCard=N;exports.InlineCitationCardBody=v;exports.InlineCitationCardTrigger=b;exports.InlineCitationCarousel=y;exports.InlineCitationCarouselContent=k;exports.InlineCitationCarouselHeader=q;exports.InlineCitationCarouselIndex=w;exports.InlineCitationCarouselItem=S;exports.InlineCitationCarouselNext=P;exports.InlineCitationCarouselPrev=H;exports.InlineCitationQuote=A;exports.InlineCitationSource=T;exports.InlineCitationText=j;
|
|
2
|
+
//# sourceMappingURL=inline-citation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-citation.cjs","sources":["../../../src/components/ai/inline-citation.tsx"],"sourcesContent":["import { ArrowLeftIcon, ArrowRightIcon } from \"lucide-react\";\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\n\nimport type { CarouselApi } from \"@/components/ui/carousel\";\nimport type { ComponentProps } from \"react\";\n\nimport { Badge } from \"@/components/ui/badge\";\nimport {\n Carousel,\n CarouselContent,\n CarouselItem,\n} from \"@/components/ui/carousel\";\nimport {\n HoverCard,\n HoverCardContent,\n HoverCardTrigger,\n} from \"@/components/ui/hover-card\";\nimport { cn } from \"@/lib/utils\";\n\n\n\n\nexport type InlineCitationProps = ComponentProps<\"span\">;\n\nexport const InlineCitation = ({\n className,\n ...props\n}: InlineCitationProps) => (\n <span\n className={cn(\"group inline items-center gap-1\", className)}\n {...props}\n />\n);\n\nexport type InlineCitationTextProps = ComponentProps<\"span\">;\n\nexport const InlineCitationText = ({\n className,\n ...props\n}: InlineCitationTextProps) => (\n <span\n className={cn(\"transition-colors group-hover:bg-accent\", className)}\n {...props}\n />\n);\n\nconst getHostname = (source: string) => {\n try {\n return new URL(source).hostname;\n } catch {\n return source;\n }\n};\n\nexport type InlineCitationCardProps = ComponentProps<typeof HoverCard>;\n\nexport const InlineCitationCard = (props: InlineCitationCardProps) => (\n <HoverCard closeDelay={0} openDelay={0} {...props} />\n);\n\nexport type InlineCitationCardTriggerProps = ComponentProps<typeof Badge> & {\n sources: string[];\n};\n\nexport const InlineCitationCardTrigger = ({\n sources,\n className,\n ...props\n}: InlineCitationCardTriggerProps) => (\n <HoverCardTrigger asChild>\n <Badge\n className={cn(\"ml-1 rounded-full\", className)}\n variant=\"secondary\"\n {...props}\n >\n {sources[0] ? (\n <>\n {getHostname(sources[0])}{\" \"}\n {sources.length > 1 && `+${sources.length - 1}`}\n </>\n ) : (\n \"unknown\"\n )}\n </Badge>\n </HoverCardTrigger>\n);\n\nexport type InlineCitationCardBodyProps = ComponentProps<\"div\">;\n\nexport const InlineCitationCardBody = ({\n className,\n ...props\n}: InlineCitationCardBodyProps) => (\n <HoverCardContent className={cn(\"relative w-80 p-0\", className)} {...props} />\n);\n\nconst CarouselApiContext = createContext<CarouselApi | undefined>(undefined);\n\nconst useCarouselApi = () => {\n return useContext(CarouselApiContext);\n};\n\nexport type InlineCitationCarouselProps = ComponentProps<typeof Carousel>;\n\nexport const InlineCitationCarousel = ({\n className,\n children,\n ...props\n}: InlineCitationCarouselProps) => {\n const [api, setApi] = useState<CarouselApi>();\n\n return (\n <CarouselApiContext.Provider value={api}>\n <Carousel className={cn(\"w-full\", className)} setApi={setApi} {...props}>\n {children}\n </Carousel>\n </CarouselApiContext.Provider>\n );\n};\n\nexport type InlineCitationCarouselContentProps = ComponentProps<\"div\">;\n\nexport const InlineCitationCarouselContent = (\n props: InlineCitationCarouselContentProps\n) => <CarouselContent {...props} />;\n\nexport type InlineCitationCarouselItemProps = ComponentProps<\"div\">;\n\nexport const InlineCitationCarouselItem = ({\n className,\n ...props\n}: InlineCitationCarouselItemProps) => (\n <CarouselItem\n className={cn(\"w-full space-y-2 p-4 pl-8\", className)}\n {...props}\n />\n);\n\nexport type InlineCitationCarouselHeaderProps = ComponentProps<\"div\">;\n\nexport const InlineCitationCarouselHeader = ({\n className,\n ...props\n}: InlineCitationCarouselHeaderProps) => (\n <div\n className={cn(\n \"flex items-center justify-between gap-2 rounded-t-md bg-secondary p-2\",\n className\n )}\n {...props}\n />\n);\n\nexport type InlineCitationCarouselIndexProps = ComponentProps<\"div\">;\n\nexport const InlineCitationCarouselIndex = ({\n children,\n className,\n ...props\n}: InlineCitationCarouselIndexProps) => {\n const api = useCarouselApi();\n const [current, setCurrent] = useState(0);\n const [count, setCount] = useState(0);\n\n const syncState = useCallback(() => {\n if (!api) {\n return;\n }\n setCount(api.scrollSnapList().length);\n setCurrent(api.selectedScrollSnap() + 1);\n }, [api]);\n\n useEffect(() => {\n if (!api) {\n return;\n }\n\n syncState();\n\n api.on(\"select\", syncState);\n\n return () => {\n api.off(\"select\", syncState);\n };\n }, [api, syncState]);\n\n return (\n <div\n className={cn(\n \"flex flex-1 items-center justify-end px-3 py-1 text-muted-foreground text-xs\",\n className\n )}\n {...props}\n >\n {children ?? `${current}/${count}`}\n </div>\n );\n};\n\nexport type InlineCitationCarouselPrevProps = ComponentProps<\"button\">;\n\nexport const InlineCitationCarouselPrev = ({\n className,\n ...props\n}: InlineCitationCarouselPrevProps) => {\n const api = useCarouselApi();\n\n const handleClick = useCallback(() => {\n if (api) {\n api.scrollPrev();\n }\n }, [api]);\n\n return (\n <button\n aria-label=\"Previous\"\n className={cn(\"shrink-0\", className)}\n onClick={handleClick}\n type=\"button\"\n {...props}\n >\n <ArrowLeftIcon className=\"size-4 text-muted-foreground\" />\n </button>\n );\n};\n\nexport type InlineCitationCarouselNextProps = ComponentProps<\"button\">;\n\nexport const InlineCitationCarouselNext = ({\n className,\n ...props\n}: InlineCitationCarouselNextProps) => {\n const api = useCarouselApi();\n\n const handleClick = useCallback(() => {\n if (api) {\n api.scrollNext();\n }\n }, [api]);\n\n return (\n <button\n aria-label=\"Next\"\n className={cn(\"shrink-0\", className)}\n onClick={handleClick}\n type=\"button\"\n {...props}\n >\n <ArrowRightIcon className=\"size-4 text-muted-foreground\" />\n </button>\n );\n};\n\nexport type InlineCitationSourceProps = ComponentProps<\"div\"> & {\n title?: string;\n url?: string;\n description?: string;\n};\n\nexport const InlineCitationSource = ({\n title,\n url,\n description,\n className,\n children,\n ...props\n}: InlineCitationSourceProps) => (\n <div className={cn(\"space-y-1\", className)} {...props}>\n {title && (\n <h4 className=\"truncate font-medium text-sm leading-tight\">{title}</h4>\n )}\n {url && (\n <p className=\"truncate break-all text-muted-foreground text-xs\">{url}</p>\n )}\n {description && (\n <p className=\"line-clamp-3 text-muted-foreground text-sm leading-relaxed\">\n {description}\n </p>\n )}\n {children}\n </div>\n);\n\nexport type InlineCitationQuoteProps = ComponentProps<\"blockquote\">;\n\nexport const InlineCitationQuote = ({\n children,\n className,\n ...props\n}: InlineCitationQuoteProps) => (\n <blockquote\n className={cn(\n \"border-muted border-l-2 pl-3 text-muted-foreground text-sm italic\",\n className\n )}\n {...props}\n >\n {children}\n </blockquote>\n);\n"],"names":["InlineCitation","className","props","jsx","cn","InlineCitationText","getHostname","source","InlineCitationCard","HoverCard","InlineCitationCardTrigger","sources","HoverCardTrigger","Badge","jsxs","Fragment","InlineCitationCardBody","HoverCardContent","CarouselApiContext","createContext","useCarouselApi","useContext","InlineCitationCarousel","children","api","setApi","useState","Carousel","InlineCitationCarouselContent","CarouselContent","InlineCitationCarouselItem","CarouselItem","InlineCitationCarouselHeader","InlineCitationCarouselIndex","current","setCurrent","count","setCount","syncState","useCallback","useEffect","InlineCitationCarouselPrev","handleClick","ArrowLeftIcon","InlineCitationCarouselNext","ArrowRightIcon","InlineCitationSource","title","url","description","InlineCitationQuote"],"mappings":"kSA8BaA,EAAiB,CAAC,CAC7B,UAAAC,E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AtB,EACA,GAAGC,CACL,IACEC,EAAAA,IAAC,aAAA,CACC,UAAWC,EAAAA,GACT,oEACAH,CAAA,EAED,GAAGC,EAEH,SAAAqB,CAAA,CACH"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { jsx as n, jsxs as m, Fragment as x } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowRightIcon as g, ArrowLeftIcon as h } from "lucide-react";
|
|
3
|
+
import { createContext as N, useState as c, useCallback as u, useEffect as I, useContext as v } from "react";
|
|
4
|
+
import { Badge as b } from "../ui/badge.js";
|
|
5
|
+
import { Carousel as y, CarouselContent as k, CarouselItem as w } from "../ui/carousel.js";
|
|
6
|
+
import { HoverCard as S, HoverCardContent as A, HoverCardTrigger as H } from "../ui/hover-card.js";
|
|
7
|
+
import { cn as a } from "../../lib/utils.js";
|
|
8
|
+
const R = ({
|
|
9
|
+
className: e,
|
|
10
|
+
...t
|
|
11
|
+
}) => /* @__PURE__ */ n(
|
|
12
|
+
"span",
|
|
13
|
+
{
|
|
14
|
+
className: a("group inline items-center gap-1", e),
|
|
15
|
+
...t
|
|
16
|
+
}
|
|
17
|
+
), q = ({
|
|
18
|
+
className: e,
|
|
19
|
+
...t
|
|
20
|
+
}) => /* @__PURE__ */ n(
|
|
21
|
+
"span",
|
|
22
|
+
{
|
|
23
|
+
className: a("transition-colors group-hover:bg-accent", e),
|
|
24
|
+
...t
|
|
25
|
+
}
|
|
26
|
+
), j = (e) => {
|
|
27
|
+
try {
|
|
28
|
+
return new URL(e).hostname;
|
|
29
|
+
} catch {
|
|
30
|
+
return e;
|
|
31
|
+
}
|
|
32
|
+
}, E = (e) => /* @__PURE__ */ n(S, { closeDelay: 0, openDelay: 0, ...e }), F = ({
|
|
33
|
+
sources: e,
|
|
34
|
+
className: t,
|
|
35
|
+
...o
|
|
36
|
+
}) => /* @__PURE__ */ n(H, { asChild: !0, children: /* @__PURE__ */ n(
|
|
37
|
+
b,
|
|
38
|
+
{
|
|
39
|
+
className: a("ml-1 rounded-full", t),
|
|
40
|
+
variant: "secondary",
|
|
41
|
+
...o,
|
|
42
|
+
children: e[0] ? /* @__PURE__ */ m(x, { children: [
|
|
43
|
+
j(e[0]),
|
|
44
|
+
" ",
|
|
45
|
+
e.length > 1 && `+${e.length - 1}`
|
|
46
|
+
] }) : "unknown"
|
|
47
|
+
}
|
|
48
|
+
) }), Q = ({
|
|
49
|
+
className: e,
|
|
50
|
+
...t
|
|
51
|
+
}) => /* @__PURE__ */ n(A, { className: a("relative w-80 p-0", e), ...t }), C = N(void 0), d = () => v(C), U = ({
|
|
52
|
+
className: e,
|
|
53
|
+
children: t,
|
|
54
|
+
...o
|
|
55
|
+
}) => {
|
|
56
|
+
const [r, s] = c();
|
|
57
|
+
return /* @__PURE__ */ n(C.Provider, { value: r, children: /* @__PURE__ */ n(y, { className: a("w-full", e), setApi: s, ...o, children: t }) });
|
|
58
|
+
}, G = (e) => /* @__PURE__ */ n(k, { ...e }), J = ({
|
|
59
|
+
className: e,
|
|
60
|
+
...t
|
|
61
|
+
}) => /* @__PURE__ */ n(
|
|
62
|
+
w,
|
|
63
|
+
{
|
|
64
|
+
className: a("w-full space-y-2 p-4 pl-8", e),
|
|
65
|
+
...t
|
|
66
|
+
}
|
|
67
|
+
), K = ({
|
|
68
|
+
className: e,
|
|
69
|
+
...t
|
|
70
|
+
}) => /* @__PURE__ */ n(
|
|
71
|
+
"div",
|
|
72
|
+
{
|
|
73
|
+
className: a(
|
|
74
|
+
"flex items-center justify-between gap-2 rounded-t-md bg-secondary p-2",
|
|
75
|
+
e
|
|
76
|
+
),
|
|
77
|
+
...t
|
|
78
|
+
}
|
|
79
|
+
), M = ({
|
|
80
|
+
children: e,
|
|
81
|
+
className: t,
|
|
82
|
+
...o
|
|
83
|
+
}) => {
|
|
84
|
+
const r = d(), [s, i] = c(0), [p, f] = c(0), l = u(() => {
|
|
85
|
+
r && (f(r.scrollSnapList().length), i(r.selectedScrollSnap() + 1));
|
|
86
|
+
}, [r]);
|
|
87
|
+
return I(() => {
|
|
88
|
+
if (r)
|
|
89
|
+
return l(), r.on("select", l), () => {
|
|
90
|
+
r.off("select", l);
|
|
91
|
+
};
|
|
92
|
+
}, [r, l]), /* @__PURE__ */ n(
|
|
93
|
+
"div",
|
|
94
|
+
{
|
|
95
|
+
className: a(
|
|
96
|
+
"flex flex-1 items-center justify-end px-3 py-1 text-muted-foreground text-xs",
|
|
97
|
+
t
|
|
98
|
+
),
|
|
99
|
+
...o,
|
|
100
|
+
children: e ?? `${s}/${p}`
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
}, O = ({
|
|
104
|
+
className: e,
|
|
105
|
+
...t
|
|
106
|
+
}) => {
|
|
107
|
+
const o = d(), r = u(() => {
|
|
108
|
+
o && o.scrollPrev();
|
|
109
|
+
}, [o]);
|
|
110
|
+
return /* @__PURE__ */ n(
|
|
111
|
+
"button",
|
|
112
|
+
{
|
|
113
|
+
"aria-label": "Previous",
|
|
114
|
+
className: a("shrink-0", e),
|
|
115
|
+
onClick: r,
|
|
116
|
+
type: "button",
|
|
117
|
+
...t,
|
|
118
|
+
children: /* @__PURE__ */ n(h, { className: "size-4 text-muted-foreground" })
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
}, V = ({
|
|
122
|
+
className: e,
|
|
123
|
+
...t
|
|
124
|
+
}) => {
|
|
125
|
+
const o = d(), r = u(() => {
|
|
126
|
+
o && o.scrollNext();
|
|
127
|
+
}, [o]);
|
|
128
|
+
return /* @__PURE__ */ n(
|
|
129
|
+
"button",
|
|
130
|
+
{
|
|
131
|
+
"aria-label": "Next",
|
|
132
|
+
className: a("shrink-0", e),
|
|
133
|
+
onClick: r,
|
|
134
|
+
type: "button",
|
|
135
|
+
...t,
|
|
136
|
+
children: /* @__PURE__ */ n(g, { className: "size-4 text-muted-foreground" })
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}, W = ({
|
|
140
|
+
title: e,
|
|
141
|
+
url: t,
|
|
142
|
+
description: o,
|
|
143
|
+
className: r,
|
|
144
|
+
children: s,
|
|
145
|
+
...i
|
|
146
|
+
}) => /* @__PURE__ */ m("div", { className: a("space-y-1", r), ...i, children: [
|
|
147
|
+
e && /* @__PURE__ */ n("h4", { className: "truncate font-medium text-sm leading-tight", children: e }),
|
|
148
|
+
t && /* @__PURE__ */ n("p", { className: "truncate break-all text-muted-foreground text-xs", children: t }),
|
|
149
|
+
o && /* @__PURE__ */ n("p", { className: "line-clamp-3 text-muted-foreground text-sm leading-relaxed", children: o }),
|
|
150
|
+
s
|
|
151
|
+
] }), X = ({
|
|
152
|
+
children: e,
|
|
153
|
+
className: t,
|
|
154
|
+
...o
|
|
155
|
+
}) => /* @__PURE__ */ n(
|
|
156
|
+
"blockquote",
|
|
157
|
+
{
|
|
158
|
+
className: a(
|
|
159
|
+
"border-muted border-l-2 pl-3 text-muted-foreground text-sm italic",
|
|
160
|
+
t
|
|
161
|
+
),
|
|
162
|
+
...o,
|
|
163
|
+
children: e
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
export {
|
|
167
|
+
R as InlineCitation,
|
|
168
|
+
E as InlineCitationCard,
|
|
169
|
+
Q as InlineCitationCardBody,
|
|
170
|
+
F as InlineCitationCardTrigger,
|
|
171
|
+
U as InlineCitationCarousel,
|
|
172
|
+
G as InlineCitationCarouselContent,
|
|
173
|
+
K as InlineCitationCarouselHeader,
|
|
174
|
+
M as InlineCitationCarouselIndex,
|
|
175
|
+
J as InlineCitationCarouselItem,
|
|
176
|
+
V as InlineCitationCarouselNext,
|
|
177
|
+
O as InlineCitationCarouselPrev,
|
|
178
|
+
X as InlineCitationQuote,
|
|
179
|
+
W as InlineCitationSource,
|
|
180
|
+
q as InlineCitationText
|
|
181
|
+
};
|
|
182
|
+
//# sourceMappingURL=inline-citation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-citation.js","sources":["../../../src/components/ai/inline-citation.tsx"],"sourcesContent":["import { ArrowLeftIcon, ArrowRightIcon } from \"lucide-react\";\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\n\nimport type { CarouselApi } from \"@/components/ui/carousel\";\nimport type { ComponentProps } from \"react\";\n\nimport { Badge } from \"@/components/ui/badge\";\nimport {\n Carousel,\n CarouselContent,\n CarouselItem,\n} from \"@/components/ui/carousel\";\nimport {\n HoverCard,\n HoverCardContent,\n HoverCardTrigger,\n} from \"@/components/ui/hover-card\";\nimport { cn } from \"@/lib/utils\";\n\n\n\n\nexport type InlineCitationProps = ComponentProps<\"span\">;\n\nexport const InlineCitation = ({\n className,\n ...props\n}: InlineCitationProps) => (\n <span\n className={cn(\"group inline items-center gap-1\", className)}\n {...props}\n />\n);\n\nexport type InlineCitationTextProps = ComponentProps<\"span\">;\n\nexport const InlineCitationText = ({\n className,\n ...props\n}: InlineCitationTextProps) => (\n <span\n className={cn(\"transition-colors group-hover:bg-accent\", className)}\n {...props}\n />\n);\n\nconst getHostname = (source: string) => {\n try {\n return new URL(source).hostname;\n } catch {\n return source;\n }\n};\n\nexport type InlineCitationCardProps = ComponentProps<typeof HoverCard>;\n\nexport const InlineCitationCard = (props: InlineCitationCardProps) => (\n <HoverCard closeDelay={0} openDelay={0} {...props} />\n);\n\nexport type InlineCitationCardTriggerProps = ComponentProps<typeof Badge> & {\n sources: string[];\n};\n\nexport const InlineCitationCardTrigger = ({\n sources,\n className,\n ...props\n}: InlineCitationCardTriggerProps) => (\n <HoverCardTrigger asChild>\n <Badge\n className={cn(\"ml-1 rounded-full\", className)}\n variant=\"secondary\"\n {...props}\n >\n {sources[0] ? (\n <>\n {getHostname(sources[0])}{\" \"}\n {sources.length > 1 && `+${sources.length - 1}`}\n </>\n ) : (\n \"unknown\"\n )}\n </Badge>\n </HoverCardTrigger>\n);\n\nexport type InlineCitationCardBodyProps = ComponentProps<\"div\">;\n\nexport const InlineCitationCardBody = ({\n className,\n ...props\n}: InlineCitationCardBodyProps) => (\n <HoverCardContent className={cn(\"relative w-80 p-0\", className)} {...props} />\n);\n\nconst CarouselApiContext = createContext<CarouselApi | undefined>(undefined);\n\nconst useCarouselApi = () => {\n return useContext(CarouselApiContext);\n};\n\nexport type InlineCitationCarouselProps = ComponentProps<typeof Carousel>;\n\nexport const InlineCitationCarousel = ({\n className,\n children,\n ...props\n}: InlineCitationCarouselProps) => {\n const [api, setApi] = useState<CarouselApi>();\n\n return (\n <CarouselApiContext.Provider value={api}>\n <Carousel className={cn(\"w-full\", className)} setApi={setApi} {...props}>\n {children}\n </Carousel>\n </CarouselApiContext.Provider>\n );\n};\n\nexport type InlineCitationCarouselContentProps = ComponentProps<\"div\">;\n\nexport const InlineCitationCarouselContent = (\n props: InlineCitationCarouselContentProps\n) => <CarouselContent {...props} />;\n\nexport type InlineCitationCarouselItemProps = ComponentProps<\"div\">;\n\nexport const InlineCitationCarouselItem = ({\n className,\n ...props\n}: InlineCitationCarouselItemProps) => (\n <CarouselItem\n className={cn(\"w-full space-y-2 p-4 pl-8\", className)}\n {...props}\n />\n);\n\nexport type InlineCitationCarouselHeaderProps = ComponentProps<\"div\">;\n\nexport const InlineCitationCarouselHeader = ({\n className,\n ...props\n}: InlineCitationCarouselHeaderProps) => (\n <div\n className={cn(\n \"flex items-center justify-between gap-2 rounded-t-md bg-secondary p-2\",\n className\n )}\n {...props}\n />\n);\n\nexport type InlineCitationCarouselIndexProps = ComponentProps<\"div\">;\n\nexport const InlineCitationCarouselIndex = ({\n children,\n className,\n ...props\n}: InlineCitationCarouselIndexProps) => {\n const api = useCarouselApi();\n const [current, setCurrent] = useState(0);\n const [count, setCount] = useState(0);\n\n const syncState = useCallback(() => {\n if (!api) {\n return;\n }\n setCount(api.scrollSnapList().length);\n setCurrent(api.selectedScrollSnap() + 1);\n }, [api]);\n\n useEffect(() => {\n if (!api) {\n return;\n }\n\n syncState();\n\n api.on(\"select\", syncState);\n\n return () => {\n api.off(\"select\", syncState);\n };\n }, [api, syncState]);\n\n return (\n <div\n className={cn(\n \"flex flex-1 items-center justify-end px-3 py-1 text-muted-foreground text-xs\",\n className\n )}\n {...props}\n >\n {children ?? `${current}/${count}`}\n </div>\n );\n};\n\nexport type InlineCitationCarouselPrevProps = ComponentProps<\"button\">;\n\nexport const InlineCitationCarouselPrev = ({\n className,\n ...props\n}: InlineCitationCarouselPrevProps) => {\n const api = useCarouselApi();\n\n const handleClick = useCallback(() => {\n if (api) {\n api.scrollPrev();\n }\n }, [api]);\n\n return (\n <button\n aria-label=\"Previous\"\n className={cn(\"shrink-0\", className)}\n onClick={handleClick}\n type=\"button\"\n {...props}\n >\n <ArrowLeftIcon className=\"size-4 text-muted-foreground\" />\n </button>\n );\n};\n\nexport type InlineCitationCarouselNextProps = ComponentProps<\"button\">;\n\nexport const InlineCitationCarouselNext = ({\n className,\n ...props\n}: InlineCitationCarouselNextProps) => {\n const api = useCarouselApi();\n\n const handleClick = useCallback(() => {\n if (api) {\n api.scrollNext();\n }\n }, [api]);\n\n return (\n <button\n aria-label=\"Next\"\n className={cn(\"shrink-0\", className)}\n onClick={handleClick}\n type=\"button\"\n {...props}\n >\n <ArrowRightIcon className=\"size-4 text-muted-foreground\" />\n </button>\n );\n};\n\nexport type InlineCitationSourceProps = ComponentProps<\"div\"> & {\n title?: string;\n url?: string;\n description?: string;\n};\n\nexport const InlineCitationSource = ({\n title,\n url,\n description,\n className,\n children,\n ...props\n}: InlineCitationSourceProps) => (\n <div className={cn(\"space-y-1\", className)} {...props}>\n {title && (\n <h4 className=\"truncate font-medium text-sm leading-tight\">{title}</h4>\n )}\n {url && (\n <p className=\"truncate break-all text-muted-foreground text-xs\">{url}</p>\n )}\n {description && (\n <p className=\"line-clamp-3 text-muted-foreground text-sm leading-relaxed\">\n {description}\n </p>\n )}\n {children}\n </div>\n);\n\nexport type InlineCitationQuoteProps = ComponentProps<\"blockquote\">;\n\nexport const InlineCitationQuote = ({\n children,\n className,\n ...props\n}: InlineCitationQuoteProps) => (\n <blockquote\n className={cn(\n \"border-muted border-l-2 pl-3 text-muted-foreground text-sm italic\",\n className\n )}\n {...props}\n >\n {children}\n </blockquote>\n);\n"],"names":["InlineCitation","className","props","jsx","cn","InlineCitationText","getHostname","source","InlineCitationCard","HoverCard","InlineCitationCardTrigger","sources","HoverCardTrigger","Badge","jsxs","Fragment","InlineCitationCardBody","HoverCardContent","CarouselApiContext","createContext","useCarouselApi","useContext","InlineCitationCarousel","children","api","setApi","useState","Carousel","InlineCitationCarouselContent","CarouselContent","InlineCitationCarouselItem","CarouselItem","InlineCitationCarouselHeader","InlineCitationCarouselIndex","current","setCurrent","count","setCount","syncState","useCallback","useEffect","InlineCitationCarouselPrev","handleClick","ArrowLeftIcon","InlineCitationCarouselNext","ArrowRightIcon","InlineCitationSource","title","url","description","InlineCitationQuote"],"mappings":";;;;;;;AA8BO,MAAMA,IAAiB,CAAC;AAAA,EAC7B,WAAAC;AAAA,EACA,GAAGC;AACL,MACE,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,WAAWC,EAAG,mCAAmCH,CAAS;AAAA,IACzD,GAAGC;AAAA,EAAA;AACN,GAKWG,IAAqB,CAAC;AAAA,EACjC,WAAAJ;AAAA,EACA,GAAGC;AACL,MACE,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,WAAWC,EAAG,2CAA2CH,CAAS;AAAA,IACjE,GAAGC;AAAA,EAAA;AACN,GAGII,IAAc,CAACC,MAAmB;AACtC,MAAI;AACF,WAAO,IAAI,IAAIA,CAAM,EAAE;AAAA,EACzB,QAAQ;AACN,WAAOA;AAAA,EACT;AACF,GAIaC,IAAqB,CAACN,MACjC,gBAAAC,EAACM,GAAA,EAAU,YAAY,GAAG,WAAW,GAAI,GAAGP,EAAA,CAAO,GAOxCQ,IAA4B,CAAC;AAAA,EACxC,SAAAC;AAAA,EACA,WAAAV;AAAA,EACA,GAAGC;AACL,MACE,gBAAAC,EAACS,GAAA,EAAiB,SAAO,IACvB,UAAA,gBAAAT;AAAA,EAACU;AAAA,EAA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Property(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),w=require("@streamdown/cjk"),C=require("@streamdown/code"),N=require("@streamdown/math"),y=require("@streamdown/mermaid"),M=require("lucide-react"),c=require("react"),T=require("streamdown"),x=require("../ui/button.cjs"),f=require("../ui/button-group.cjs"),d=require("../ui/tooltip.cjs"),i=require("../../lib/utils.cjs"),q=({className:e,from:s,...t})=>n.jsx("div",{className:i.cn("group flex w-full max-w-[95%] flex-col gap-2",s==="user"?"is-user ml-auto justify-end":"is-assistant",e),...t}),k=({children:e,className:s,...t})=>n.jsx("div",{className:i.cn("is-user:dark flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",s),...t,children:e}),A=({className:e,children:s,...t})=>n.jsx("div",{className:i.cn("flex items-center gap-1",e),...t,children:s}),P=({tooltip:e,children:s,label:t,variant:a="ghost",size:r="icon-sm",...l})=>{const o=n.jsxs(x.Button,{size:r,type:"button",variant:a,...l,children:[s,n.jsx("span",{className:"sr-only",children:t||e})]});return e?n.jsx(d.TooltipProvider,{children:n.jsxs(d.Tooltip,{children:[n.jsx(d.TooltipTrigger,{asChild:!0,children:o}),n.jsx(d.TooltipContent,{children:n.jsx("p",{children:e})})]})}):o},b=c.createContext(null),g=()=>{const e=c.useContext(b);if(!e)throw new Error("MessageBranch components must be used within MessageBranch");return e},R=({defaultBranch:e=0,onBranchChange:s,className:t,...a})=>{const[r,l]=c.useState(e),[o,m]=c.useState([]),h=c.useCallback(u=>{l(u),s?.(u)},[s]),p=c.useCallback(()=>{const u=r>0?r-1:o.length-1;h(u)},[r,o.length,h]),B=c.useCallback(()=>{const u=r<o.length-1?r+1:0;h(u)},[r,o.length,h]),v=c.useMemo(()=>({branches:o,currentBranch:r,goToNext:B,goToPrevious:p,setBranches:m,totalBranches:o.length}),[o,r,B,p]);return n.jsx(b.Provider,{value:v,children:n.jsx("div",{className:i.cn("grid w-full gap-2 [&>div]:pb-0",t),...a})})},S=({children:e,...s})=>{const{currentBranch:t,setBranches:a,branches:r}=g(),l=c.useMemo(()=>Array.isArray(e)?e:[e],[e]);return c.useEffect(()=>{r.length!==l.length&&a(l)},[l,r,a]),l.map((o,m)=>n.jsx("div",{className:i.cn("grid gap-2 overflow-hidden [&>div]:pb-0",m===t?"block":"hidden"),...s,children:o},o.key))},z=({className:e,...s})=>{const{totalBranches:t}=g();return t<=1?null:n.jsx(f.ButtonGroup,{className:i.cn("[&>*:not(:first-child)]:rounded-l-md [&>*:not(:last-child)]:rounded-r-md",e),orientation:"horizontal",...s})},G=({children:e,...s})=>{const{goToPrevious:t,totalBranches:a}=g();return n.jsx(x.Button,{"aria-label":"Previous branch",disabled:a<=1,onClick:t,size:"icon-sm",type:"button",variant:"ghost",...s,children:e??n.jsx(M.ChevronLeftIcon,{size:14})})},E=({children:e,...s})=>{const{goToNext:t,totalBranches:a}=g();return n.jsx(x.Button,{"aria-label":"Next branch",disabled:a<=1,onClick:t,size:"icon-sm",type:"button",variant:"ghost",...s,children:e??n.jsx(M.ChevronRightIcon,{size:14})})},I=({className:e,...s})=>{const{currentBranch:t,totalBranches:a}=g();return n.jsx(f.ButtonGroupText,{className:i.cn("border-none bg-transparent text-muted-foreground shadow-none",e),...s,children:`${t+1} of ${a}`})},L={cjk:w.cjk,code:C.code,math:N.math,mermaid:y.mermaid},j=c.memo(({className:e,...s})=>n.jsx(T.Streamdown,{className:i.cn("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),plugins:L,...s}),(e,s)=>e.children===s.children&&s.isAnimating===e.isAnimating);j.displayName="MessageResponse";const O=({className:e,children:s,...t})=>n.jsx("div",{className:i.cn("mt-4 flex w-full items-center justify-between gap-4",e),...t,children:s});exports.Message=q;exports.MessageAction=P;exports.MessageActions=A;exports.MessageBranch=R;exports.MessageBranchContent=S;exports.MessageBranchNext=E;exports.MessageBranchPage=I;exports.MessageBranchPrevious=G;exports.MessageBranchSelector=z;exports.MessageContent=k;exports.MessageResponse=j;exports.MessageToolbar=O;
|
|
2
|
+
//# sourceMappingURL=message.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.cjs","sources":["../../../src/components/ai/message.tsx"],"sourcesContent":["import { cjk } from \"@streamdown/cjk\";\nimport { code } from \"@streamdown/code\";\nimport { math } from \"@streamdown/math\";\nimport { mermaid } from \"@streamdown/mermaid\";\nimport { ChevronLeftIcon, ChevronRightIcon } from \"lucide-react\";\nimport {\n createContext,\n memo,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { Streamdown } from \"streamdown\";\n\nimport type { UIMessage } from \"ai\";\nimport type { ComponentProps, HTMLAttributes, ReactElement } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n ButtonGroup,\n ButtonGroupText,\n} from \"@/components/ui/button-group\";\nimport {\n Tooltip,\n TooltipContent,\n TooltipProvider,\n TooltipTrigger,\n} from \"@/components/ui/tooltip\";\nimport { cn } from \"@/lib/utils\";\n\nexport type MessageProps = HTMLAttributes<HTMLDivElement> & {\n from: UIMessage[\"role\"];\n};\n\nexport const Message = ({ className, from, ...props }: MessageProps) => (\n <div\n className={cn(\n \"group flex w-full max-w-[95%] flex-col gap-2\",\n from === \"user\" ? \"is-user ml-auto justify-end\" : \"is-assistant\",\n className\n )}\n {...props}\n />\n);\n\nexport type MessageContentProps = HTMLAttributes<HTMLDivElement>;\n\nexport const MessageContent = ({\n children,\n className,\n ...props\n}: MessageContentProps) => (\n <div\n className={cn(\n \"is-user:dark flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm\",\n \"group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground\",\n \"group-[.is-assistant]:text-foreground\",\n className\n )}\n {...props}\n >\n {children}\n </div>\n);\n\nexport type MessageActionsProps = ComponentProps<\"div\">;\n\nexport const MessageActions = ({\n className,\n children,\n ...props\n}: MessageActionsProps) => (\n <div className={cn(\"flex items-center gap-1\", className)} {...props}>\n {children}\n </div>\n);\n\nexport type MessageActionProps = ComponentProps<typeof Button> & {\n tooltip?: string;\n label?: string;\n};\n\nexport const MessageAction = ({\n tooltip,\n children,\n label,\n variant = \"ghost\",\n size = \"icon-sm\",\n ...props\n}: MessageActionProps) => {\n const button = (\n <Button size={size} type=\"button\" variant={variant} {...props}>\n {children}\n <span className=\"sr-only\">{label || tooltip}</span>\n </Button>\n );\n\n if (tooltip) {\n return (\n <TooltipProvider>\n <Tooltip>\n <TooltipTrigger asChild>{button}</TooltipTrigger>\n <TooltipContent>\n <p>{tooltip}</p>\n </TooltipContent>\n </Tooltip>\n </TooltipProvider>\n );\n }\n\n return button;\n};\n\ninterface MessageBranchContextType {\n currentBranch: number;\n totalBranches: number;\n goToPrevious: () => void;\n goToNext: () => void;\n branches: ReactElement[];\n setBranches: (branches: ReactElement[]) => void;\n}\n\nconst MessageBranchContext = createContext<MessageBranchContextType | null>(\n null\n);\n\nconst useMessageBranch = () => {\n const context = useContext(MessageBranchContext);\n\n if (!context) {\n throw new Error(\n \"MessageBranch components must be used within MessageBranch\"\n );\n }\n\n return context;\n};\n\nexport type MessageBranchProps = HTMLAttributes<HTMLDivElement> & {\n defaultBranch?: number;\n onBranchChange?: (branchIndex: number) => void;\n};\n\nexport const MessageBranch = ({\n defaultBranch = 0,\n onBranchChange,\n className,\n ...props\n}: MessageBranchProps) => {\n const [currentBranch, setCurrentBranch] = useState(defaultBranch);\n const [branches, setBranches] = useState<ReactElement[]>([]);\n\n const handleBranchChange = useCallback(\n (newBranch: number) => {\n setCurrentBranch(newBranch);\n onBranchChange?.(newBranch);\n },\n [onBranchChange]\n );\n\n const goToPrevious = useCallback(() => {\n const newBranch =\n currentBranch > 0 ? currentBranch - 1 : branches.length - 1;\n handleBranchChange(newBranch);\n }, [currentBranch, branches.length, handleBranchChange]);\n\n const goToNext = useCallback(() => {\n const newBranch =\n currentBranch < branches.length - 1 ? currentBranch + 1 : 0;\n handleBranchChange(newBranch);\n }, [currentBranch, branches.length, handleBranchChange]);\n\n const contextValue = useMemo<MessageBranchContextType>(\n () => ({\n branches,\n currentBranch,\n goToNext,\n goToPrevious,\n setBranches,\n totalBranches: branches.length,\n }),\n [branches, currentBranch, goToNext, goToPrevious]\n );\n\n return (\n <MessageBranchContext.Provider value={contextValue}>\n <div\n className={cn(\"grid w-full gap-2 [&>div]:pb-0\", className)}\n {...props}\n />\n </MessageBranchContext.Provider>\n );\n};\n\nexport type MessageBranchContentProps = HTMLAttributes<HTMLDivElement>;\n\nexport const MessageBranchContent = ({\n children,\n ...props\n}: MessageBranchContentProps) => {\n const { currentBranch, setBranches, branches } = useMessageBranch();\n const childrenArray = useMemo(\n () => (Array.isArray(children) ? children : [children]),\n [children]\n );\n\n // Use useEffect to update branches when they change\n useEffect(() => {\n if (branches.length !== childrenArray.length) {\n setBranches(childrenArray);\n }\n }, [childrenArray, branches, setBranches]);\n\n return childrenArray.map((branch, index) => (\n <div\n className={cn(\n \"grid gap-2 overflow-hidden [&>div]:pb-0\",\n index === currentBranch ? \"block\" : \"hidden\"\n )}\n key={branch.key}\n {...props}\n >\n {branch}\n </div>\n ));\n};\n\nexport type MessageBranchSelectorProps = ComponentProps<typeof ButtonGroup>;\n\nexport const MessageBranchSelector = ({\n className,\n ...props\n}: MessageBranchSelectorProps) => {\n const { totalBranches } = useMessageBranch();\n\n // Don't render if there's only one branch\n if (totalBranches <= 1) {\n return null;\n }\n\n return (\n <ButtonGroup\n className={cn(\n \"[&>*:not(:first-child)]:rounded-l-md [&>*:not(:last-child)]:rounded-r-md\",\n className\n )}\n orientation=\"horizontal\"\n {...props}\n />\n );\n};\n\nexport type MessageBranchPreviousProps = ComponentProps<typeof Button>;\n\nexport const MessageBranchPrevious = ({\n children,\n ...props\n}: MessageBranchPreviousProps) => {\n const { goToPrevious, totalBranches } = useMessageBranch();\n\n return (\n <Button\n aria-label=\"Previous branch\"\n disabled={totalBranches <= 1}\n onClick={goToPrevious}\n size=\"icon-sm\"\n type=\"button\"\n variant=\"ghost\"\n {...props}\n >\n {children ?? <ChevronLeftIcon size={14} />}\n </Button>\n );\n};\n\nexport type MessageBranchNextProps = ComponentProps<typeof Button>;\n\nexport const MessageBranchNext = ({\n children,\n ...props\n}: MessageBranchNextProps) => {\n const { goToNext, totalBranches } = useMessageBranch();\n\n return (\n <Button\n aria-label=\"Next branch\"\n disabled={totalBranches <= 1}\n onClick={goToNext}\n size=\"icon-sm\"\n type=\"button\"\n variant=\"ghost\"\n {...props}\n >\n {children ?? <ChevronRightIcon size={14} />}\n </Button>\n );\n};\n\nexport type MessageBranchPageProps = HTMLAttributes<HTMLSpanElement>;\n\nexport const MessageBranchPage = ({\n className,\n ...props\n}: MessageBranchPageProps) => {\n const { currentBranch, totalBranches } = useMessageBranch();\n\n return (\n <ButtonGroupText\n className={cn(\n \"border-none bg-transparent text-muted-foreground shadow-none\",\n className\n )}\n {...props}\n >\n {`${currentBranch + 1} of ${totalBranches}`}\n </ButtonGroupText>\n );\n};\n\nexport type MessageResponseProps = ComponentProps<typeof Streamdown>;\n\nconst streamdownPlugins = { cjk, code, math, mermaid };\n\nexport const MessageResponse = memo(\n ({ className, ...props }: MessageResponseProps) => (\n <Streamdown\n className={cn(\n \"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0\",\n className\n )}\n plugins={streamdownPlugins}\n {...props}\n />\n ),\n (prevProps, nextProps) =>\n prevProps.children === nextProps.children &&\n nextProps.isAnimating === prevProps.isAnimating\n);\n\nMessageResponse.displayName = \"MessageResponse\";\n\nexport type MessageToolbarProps = ComponentProps<\"div\">;\n\nexport const MessageToolbar = ({\n className,\n children,\n ...props\n}: MessageToolbarProps) => (\n <div\n className={cn(\n \"mt-4 flex w-full items-center justify-between gap-4\",\n className\n )}\n {...props}\n >\n {children}\n </div>\n);\n"],"names":["Message","className","from","props","jsx","cn","MessageContent","children","MessageActions","MessageAction","tooltip","label","variant","size","button","Button","TooltipProvider","jsxs","Tooltip","TooltipTrigger","TooltipContent","MessageBranchContext","createContext","useMessageBranch","context","useContext","MessageBranch","defaultBranch","onBranchChange","currentBranch","setCurrentBranch","useState","branches","setBranches","handleBranchChange","useCallback","newBranch","goToPrevious","goToNext","contextValue","useMemo","MessageBranchContent","childrenArray","useEffect","branch","index","MessageBranchSelector","totalBranches","ButtonGroup","MessageBranchPrevious","ChevronLeftIcon","MessageBranchNext","ChevronRightIcon","MessageBranchPage","ButtonGroupText","streamdownPlugins","cjk","code","math","mermaid","MessageResponse","memo","Streamdown","prevProps","nextProps","MessageToolbar"],"mappings":"sbAoCaA,EAAU,CAAC,CAAE,UAAAC,EAAW,KAAAC,EAAM,GAAGC,KAC5CC,EAAAA,IAAC,MAAA,CACC,UAAWC,EAAAA,GACT,+CACAH,IAAS,OAAS,8BAAgC,eAClDD,CAAA,EAED,GAAGE,CAAA,CACN,EAKWG,EAAiB,CAAC,CAC7B,SAAAC,EACA,UAAAN,EACA,GAAGE,CACL,IACEC,EAAAA,IAAC,MAAA,CACC,UAAWC,EAAAA,GACT,oFACA,kKACA,wCACAJ,CAAA,EAED,GAAGE,EAEH,SAAAI,CAAA,CACH,EAKWC,EAAiB,CAAC,CAC7B,UAAAP,EACA,SAAAM,EACA,GAAGJ,CACL,IACEC,EAAAA,IAAC,OAAI,UAAWC,EAAAA,GAAG,0BAA2BJ,CAAS,EAAI,GAAGE,EAC3D,SAAAI,CAAA,CACH,EAQWE,EAAgB,CAAC,CAAA,QAC5BC,EACA,SAAAH,EACA,MAAAI,EACA,QAAAC,EAAU,QACV,KAAAC,EAAO,UACP,GAAGV,CACL,IAA0B,CACxB,MAAMW,SACHC,EAAAA,OAAA,CAAO,KAAAF,EAAY,KAAK,SAAS,QAAAD,EAAmB,GAAGT,EACrD,SAAA,C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AgB,YAAc,kBAIvB,MAAMK,EAAiB,CAAC,CAC7B,UAAAhE,EACA,SAAAM,EACA,GAAGJ,CACL,IACEC,EAAAA,IAAC,MAAA,CACC,UAAWC,EAAAA,GACT,sDACAJ,CAAA,EAED,GAAGE,EAEH,SAAAI,CAAA,CACH"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { jsx as n, jsxs as x } from "react/jsx-runtime";
|
|
2
|
+
import { cjk as w } from "@streamdown/cjk";
|
|
3
|
+
import { code as N } from "@streamdown/code";
|
|
4
|
+
import { math as y } from "@streamdown/math";
|
|
5
|
+
import { mermaid as C } from "@streamdown/mermaid";
|
|
6
|
+
import { ChevronRightIcon as T, ChevronLeftIcon as k } from "lucide-react";
|
|
7
|
+
import { createContext as A, memo as z, useState as B, useCallback as d, useMemo as b, useEffect as P, useContext as j } from "react";
|
|
8
|
+
import { Streamdown as R } from "streamdown";
|
|
9
|
+
import { Button as g } from "../ui/button.js";
|
|
10
|
+
import { ButtonGroupText as S, ButtonGroup as E } from "../ui/button-group.js";
|
|
11
|
+
import { TooltipProvider as G, Tooltip as I, TooltipTrigger as $, TooltipContent as L } from "../ui/tooltip.js";
|
|
12
|
+
import { cn as c } from "../../lib/utils.js";
|
|
13
|
+
const _ = ({ className: e, from: s, ...t }) => /* @__PURE__ */ n(
|
|
14
|
+
"div",
|
|
15
|
+
{
|
|
16
|
+
className: c(
|
|
17
|
+
"group flex w-full max-w-[95%] flex-col gap-2",
|
|
18
|
+
s === "user" ? "is-user ml-auto justify-end" : "is-assistant",
|
|
19
|
+
e
|
|
20
|
+
),
|
|
21
|
+
...t
|
|
22
|
+
}
|
|
23
|
+
), ee = ({
|
|
24
|
+
children: e,
|
|
25
|
+
className: s,
|
|
26
|
+
...t
|
|
27
|
+
}) => /* @__PURE__ */ n(
|
|
28
|
+
"div",
|
|
29
|
+
{
|
|
30
|
+
className: c(
|
|
31
|
+
"is-user:dark flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm",
|
|
32
|
+
"group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground",
|
|
33
|
+
"group-[.is-assistant]:text-foreground",
|
|
34
|
+
s
|
|
35
|
+
),
|
|
36
|
+
...t,
|
|
37
|
+
children: e
|
|
38
|
+
}
|
|
39
|
+
), se = ({
|
|
40
|
+
className: e,
|
|
41
|
+
children: s,
|
|
42
|
+
...t
|
|
43
|
+
}) => /* @__PURE__ */ n("div", { className: c("flex items-center gap-1", e), ...t, children: s }), te = ({
|
|
44
|
+
tooltip: e,
|
|
45
|
+
children: s,
|
|
46
|
+
label: t,
|
|
47
|
+
variant: a = "ghost",
|
|
48
|
+
size: r = "icon-sm",
|
|
49
|
+
...i
|
|
50
|
+
}) => {
|
|
51
|
+
const o = /* @__PURE__ */ x(g, { size: r, type: "button", variant: a, ...i, children: [
|
|
52
|
+
s,
|
|
53
|
+
/* @__PURE__ */ n("span", { className: "sr-only", children: t || e })
|
|
54
|
+
] });
|
|
55
|
+
return e ? /* @__PURE__ */ n(G, { children: /* @__PURE__ */ x(I, { children: [
|
|
56
|
+
/* @__PURE__ */ n($, { asChild: !0, children: o }),
|
|
57
|
+
/* @__PURE__ */ n(L, { children: /* @__PURE__ */ n("p", { children: e }) })
|
|
58
|
+
] }) }) : o;
|
|
59
|
+
}, v = A(
|
|
60
|
+
null
|
|
61
|
+
), u = () => {
|
|
62
|
+
const e = j(v);
|
|
63
|
+
if (!e)
|
|
64
|
+
throw new Error(
|
|
65
|
+
"MessageBranch components must be used within MessageBranch"
|
|
66
|
+
);
|
|
67
|
+
return e;
|
|
68
|
+
}, ne = ({
|
|
69
|
+
defaultBranch: e = 0,
|
|
70
|
+
onBranchChange: s,
|
|
71
|
+
className: t,
|
|
72
|
+
...a
|
|
73
|
+
}) => {
|
|
74
|
+
const [r, i] = B(e), [o, h] = B([]), m = d(
|
|
75
|
+
(l) => {
|
|
76
|
+
i(l), s?.(l);
|
|
77
|
+
},
|
|
78
|
+
[s]
|
|
79
|
+
), p = d(() => {
|
|
80
|
+
const l = r > 0 ? r - 1 : o.length - 1;
|
|
81
|
+
m(l);
|
|
82
|
+
}, [r, o.length, m]), f = d(() => {
|
|
83
|
+
const l = r < o.length - 1 ? r + 1 : 0;
|
|
84
|
+
m(l);
|
|
85
|
+
}, [r, o.length, m]), M = b(
|
|
86
|
+
() => ({
|
|
87
|
+
branches: o,
|
|
88
|
+
currentBranch: r,
|
|
89
|
+
goToNext: f,
|
|
90
|
+
goToPrevious: p,
|
|
91
|
+
setBranches: h,
|
|
92
|
+
totalBranches: o.length
|
|
93
|
+
}),
|
|
94
|
+
[o, r, f, p]
|
|
95
|
+
);
|
|
96
|
+
return /* @__PURE__ */ n(v.Provider, { value: M, children: /* @__PURE__ */ n(
|
|
97
|
+
"div",
|
|
98
|
+
{
|
|
99
|
+
className: c("grid w-full gap-2 [&>div]:pb-0", t),
|
|
100
|
+
...a
|
|
101
|
+
}
|
|
102
|
+
) });
|
|
103
|
+
}, re = ({
|
|
104
|
+
children: e,
|
|
105
|
+
...s
|
|
106
|
+
}) => {
|
|
107
|
+
const { currentBranch: t, setBranches: a, branches: r } = u(), i = b(
|
|
108
|
+
() => Array.isArray(e) ? e : [e],
|
|
109
|
+
[e]
|
|
110
|
+
);
|
|
111
|
+
return P(() => {
|
|
112
|
+
r.length !== i.length && a(i);
|
|
113
|
+
}, [i, r, a]), i.map((o, h) => /* @__PURE__ */ n(
|
|
114
|
+
"div",
|
|
115
|
+
{
|
|
116
|
+
className: c(
|
|
117
|
+
"grid gap-2 overflow-hidden [&>div]:pb-0",
|
|
118
|
+
h === t ? "block" : "hidden"
|
|
119
|
+
),
|
|
120
|
+
...s,
|
|
121
|
+
children: o
|
|
122
|
+
},
|
|
123
|
+
o.key
|
|
124
|
+
));
|
|
125
|
+
}, oe = ({
|
|
126
|
+
className: e,
|
|
127
|
+
...s
|
|
128
|
+
}) => {
|
|
129
|
+
const { totalBranches: t } = u();
|
|
130
|
+
return t <= 1 ? null : /* @__PURE__ */ n(
|
|
131
|
+
E,
|
|
132
|
+
{
|
|
133
|
+
className: c(
|
|
134
|
+
"[&>*:not(:first-child)]:rounded-l-md [&>*:not(:last-child)]:rounded-r-md",
|
|
135
|
+
e
|
|
136
|
+
),
|
|
137
|
+
orientation: "horizontal",
|
|
138
|
+
...s
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
}, ae = ({
|
|
142
|
+
children: e,
|
|
143
|
+
...s
|
|
144
|
+
}) => {
|
|
145
|
+
const { goToPrevious: t, totalBranches: a } = u();
|
|
146
|
+
return /* @__PURE__ */ n(
|
|
147
|
+
g,
|
|
148
|
+
{
|
|
149
|
+
"aria-label": "Previous branch",
|
|
150
|
+
disabled: a <= 1,
|
|
151
|
+
onClick: t,
|
|
152
|
+
size: "icon-sm",
|
|
153
|
+
type: "button",
|
|
154
|
+
variant: "ghost",
|
|
155
|
+
...s,
|
|
156
|
+
children: e ?? /* @__PURE__ */ n(k, { size: 14 })
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
}, ce = ({
|
|
160
|
+
children: e,
|
|
161
|
+
...s
|
|
162
|
+
}) => {
|
|
163
|
+
const { goToNext: t, totalBranches: a } = u();
|
|
164
|
+
return /* @__PURE__ */ n(
|
|
165
|
+
g,
|
|
166
|
+
{
|
|
167
|
+
"aria-label": "Next branch",
|
|
168
|
+
disabled: a <= 1,
|
|
169
|
+
onClick: t,
|
|
170
|
+
size: "icon-sm",
|
|
171
|
+
type: "button",
|
|
172
|
+
variant: "ghost",
|
|
173
|
+
...s,
|
|
174
|
+
children: e ?? /* @__PURE__ */ n(T, { size: 14 })
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
}, ie = ({
|
|
178
|
+
className: e,
|
|
179
|
+
...s
|
|
180
|
+
}) => {
|
|
181
|
+
const { currentBranch: t, totalBranches: a } = u();
|
|
182
|
+
return /* @__PURE__ */ n(
|
|
183
|
+
S,
|
|
184
|
+
{
|
|
185
|
+
className: c(
|
|
186
|
+
"border-none bg-transparent text-muted-foreground shadow-none",
|
|
187
|
+
e
|
|
188
|
+
),
|
|
189
|
+
...s,
|
|
190
|
+
children: `${t + 1} of ${a}`
|
|
191
|
+
}
|
|
192
|
+
);
|
|
193
|
+
}, V = { cjk: w, code: N, math: y, mermaid: C }, q = z(
|
|
194
|
+
({ className: e, ...s }) => /* @__PURE__ */ n(
|
|
195
|
+
R,
|
|
196
|
+
{
|
|
197
|
+
className: c(
|
|
198
|
+
"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",
|
|
199
|
+
e
|
|
200
|
+
),
|
|
201
|
+
plugins: V,
|
|
202
|
+
...s
|
|
203
|
+
}
|
|
204
|
+
),
|
|
205
|
+
(e, s) => e.children === s.children && s.isAnimating === e.isAnimating
|
|
206
|
+
);
|
|
207
|
+
q.displayName = "MessageResponse";
|
|
208
|
+
const le = ({
|
|
209
|
+
className: e,
|
|
210
|
+
children: s,
|
|
211
|
+
...t
|
|
212
|
+
}) => /* @__PURE__ */ n(
|
|
213
|
+
"div",
|
|
214
|
+
{
|
|
215
|
+
className: c(
|
|
216
|
+
"mt-4 flex w-full items-center justify-between gap-4",
|
|
217
|
+
e
|
|
218
|
+
),
|
|
219
|
+
...t,
|
|
220
|
+
children: s
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
export {
|
|
224
|
+
_ as Message,
|
|
225
|
+
te as MessageAction,
|
|
226
|
+
se as MessageActions,
|
|
227
|
+
ne as MessageBranch,
|
|
228
|
+
re as MessageBranchContent,
|
|
229
|
+
ce as MessageBranchNext,
|
|
230
|
+
ie as MessageBranchPage,
|
|
231
|
+
ae as MessageBranchPrevious,
|
|
232
|
+
oe as MessageBranchSelector,
|
|
233
|
+
ee as MessageContent,
|
|
234
|
+
q as MessageResponse,
|
|
235
|
+
le as MessageToolbar
|
|
236
|
+
};
|
|
237
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sources":["../../../src/components/ai/message.tsx"],"sourcesContent":["import { cjk } from \"@streamdown/cjk\";\nimport { code } from \"@streamdown/code\";\nimport { math } from \"@streamdown/math\";\nimport { mermaid } from \"@streamdown/mermaid\";\nimport { ChevronLeftIcon, ChevronRightIcon } from \"lucide-react\";\nimport {\n createContext,\n memo,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { Streamdown } from \"streamdown\";\n\nimport type { UIMessage } from \"ai\";\nimport type { ComponentProps, HTMLAttributes, ReactElement } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n ButtonGroup,\n ButtonGroupText,\n} from \"@/components/ui/button-group\";\nimport {\n Tooltip,\n TooltipContent,\n TooltipProvider,\n TooltipTrigger,\n} from \"@/components/ui/tooltip\";\nimport { cn } from \"@/lib/utils\";\n\nexport type MessageProps = HTMLAttributes<HTMLDivElement> & {\n from: UIMessage[\"role\"];\n};\n\nexport const Message = ({ className, from, ...props }: MessageProps) => (\n <div\n className={cn(\n \"group flex w-full max-w-[95%] flex-col gap-2\",\n from === \"user\" ? \"is-user ml-auto justify-end\" : \"is-assistant\",\n className\n )}\n {...props}\n />\n);\n\nexport type MessageContentProps = HTMLAttributes<HTMLDivElement>;\n\nexport const MessageContent = ({\n children,\n className,\n ...props\n}: MessageContentProps) => (\n <div\n className={cn(\n \"is-user:dark flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm\",\n \"group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground\",\n \"group-[.is-assistant]:text-foreground\",\n className\n )}\n {...props}\n >\n {children}\n </div>\n);\n\nexport type MessageActionsProps = ComponentProps<\"div\">;\n\nexport const MessageActions = ({\n className,\n children,\n ...props\n}: MessageActionsProps) => (\n <div className={cn(\"flex items-center gap-1\", className)} {...props}>\n {children}\n </div>\n);\n\nexport type MessageActionProps = ComponentProps<typeof Button> & {\n tooltip?: string;\n label?: string;\n};\n\nexport const MessageAction = ({\n tooltip,\n children,\n label,\n variant = \"ghost\",\n size = \"icon-sm\",\n ...props\n}: MessageActionProps) => {\n const button = (\n <Button size={size} type=\"button\" variant={variant} {...props}>\n {children}\n <span className=\"sr-only\">{label || tooltip}</span>\n </Button>\n );\n\n if (tooltip) {\n return (\n <TooltipProvider>\n <Tooltip>\n <TooltipTrigger asChild>{button}</TooltipTrigger>\n <TooltipContent>\n <p>{tooltip}</p>\n </TooltipContent>\n </Tooltip>\n </TooltipProvider>\n );\n }\n\n return button;\n};\n\ninterface MessageBranchContextType {\n currentBranch: number;\n totalBranches: number;\n goToPrevious: () => void;\n goToNext: () => void;\n branches: ReactElement[];\n setBranches: (branches: ReactElement[]) => void;\n}\n\nconst MessageBranchContext = createContext<MessageBranchContextType | null>(\n null\n);\n\nconst useMessageBranch = () => {\n const context = useContext(MessageBranchContext);\n\n if (!context) {\n throw new Error(\n \"MessageBranch components must be used within MessageBranch\"\n );\n }\n\n return context;\n};\n\nexport type MessageBranchProps = HTMLAttributes<HTMLDivElement> & {\n defaultBranch?: number;\n onBranchChange?: (branchIndex: number) => void;\n};\n\nexport const MessageBranch = ({\n defaultBranch = 0,\n onBranchChange,\n className,\n ...props\n}: MessageBranchProps) => {\n const [currentBranch, setCurrentBranch] = useState(defaultBranch);\n const [branches, setBranches] = useState<ReactElement[]>([]);\n\n const handleBranchChange = useCallback(\n (newBranch: number) => {\n setCurrentBranch(newBranch);\n onBranchChange?.(newBranch);\n },\n [onBranchChange]\n );\n\n const goToPrevious = useCallback(() => {\n const newBranch =\n currentBranch > 0 ? currentBranch - 1 : branches.length - 1;\n handleBranchChange(newBranch);\n }, [currentBranch, branches.length, handleBranchChange]);\n\n const goToNext = useCallback(() => {\n const newBranch =\n currentBranch < branches.length - 1 ? currentBranch + 1 : 0;\n handleBranchChange(newBranch);\n }, [currentBranch, branches.length, handleBranchChange]);\n\n const contextValue = useMemo<MessageBranchContextType>(\n () => ({\n branches,\n currentBranch,\n goToNext,\n goToPrevious,\n setBranches,\n totalBranches: branches.length,\n }),\n [branches, currentBranch, goToNext, goToPrevious]\n );\n\n return (\n <MessageBranchContext.Provider value={contextValue}>\n <div\n className={cn(\"grid w-full gap-2 [&>div]:pb-0\", className)}\n {...props}\n />\n </MessageBranchContext.Provider>\n );\n};\n\nexport type MessageBranchContentProps = HTMLAttributes<HTMLDivElement>;\n\nexport const MessageBranchContent = ({\n children,\n ...props\n}: MessageBranchContentProps) => {\n const { currentBranch, setBranches, branches } = useMessageBranch();\n const childrenArray = useMemo(\n () => (Array.isArray(children) ? children : [children]),\n [children]\n );\n\n // Use useEffect to update branches when they change\n useEffect(() => {\n if (branches.length !== childrenArray.length) {\n setBranches(childrenArray);\n }\n }, [childrenArray, branches, setBranches]);\n\n return childrenArray.map((branch, index) => (\n <div\n className={cn(\n \"grid gap-2 overflow-hidden [&>div]:pb-0\",\n index === currentBranch ? \"block\" : \"hidden\"\n )}\n key={branch.key}\n {...props}\n >\n {branch}\n </div>\n ));\n};\n\nexport type MessageBranchSelectorProps = ComponentProps<typeof ButtonGroup>;\n\nexport const MessageBranchSelector = ({\n className,\n ...props\n}: MessageBranchSelectorProps) => {\n const { totalBranches } = useMessageBranch();\n\n // Don't render if there's only one branch\n if (totalBranches <= 1) {\n return null;\n }\n\n return (\n <ButtonGroup\n className={cn(\n \"[&>*:not(:first-child)]:rounded-l-md [&>*:not(:last-child)]:rounded-r-md\",\n className\n )}\n orientation=\"horizontal\"\n {...props}\n />\n );\n};\n\nexport type MessageBranchPreviousProps = ComponentProps<typeof Button>;\n\nexport const MessageBranchPrevious = ({\n children,\n ...props\n}: MessageBranchPreviousProps) => {\n const { goToPrevious, totalBranches } = useMessageBranch();\n\n return (\n <Button\n aria-label=\"Previous branch\"\n disabled={totalBranches <= 1}\n onClick={goToPrevious}\n size=\"icon-sm\"\n type=\"button\"\n variant=\"ghost\"\n {...props}\n >\n {children ?? <ChevronLeftIcon size={14} />}\n </Button>\n );\n};\n\nexport type MessageBranchNextProps = ComponentProps<typeof Button>;\n\nexport const MessageBranchNext = ({\n children,\n ...props\n}: MessageBranchNextProps) => {\n const { goToNext, totalBranches } = useMessageBranch();\n\n return (\n <Button\n aria-label=\"Next branch\"\n disabled={totalBranches <= 1}\n onClick={goToNext}\n size=\"icon-sm\"\n type=\"button\"\n variant=\"ghost\"\n {...props}\n >\n {children ?? <ChevronRightIcon size={14} />}\n </Button>\n );\n};\n\nexport type MessageBranchPageProps = HTMLAttributes<HTMLSpanElement>;\n\nexport const MessageBranchPage = ({\n className,\n ...props\n}: MessageBranchPageProps) => {\n const { currentBranch, totalBranches } = useMessageBranch();\n\n return (\n <ButtonGroupText\n className={cn(\n \"border-none bg-transparent text-muted-foreground shadow-none\",\n className\n )}\n {...props}\n >\n {`${currentBranch + 1} of ${totalBranches}`}\n </ButtonGroupText>\n );\n};\n\nexport type MessageResponseProps = ComponentProps<typeof Streamdown>;\n\nconst streamdownPlugins = { cjk, code, math, mermaid };\n\nexport const MessageResponse = memo(\n ({ className, ...props }: MessageResponseProps) => (\n <Streamdown\n className={cn(\n \"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0\",\n className\n )}\n plugins={streamdownPlugins}\n {...props}\n />\n ),\n (prevProps, nextProps) =>\n prevProps.children === nextProps.children &&\n nextProps.isAnimating === prevProps.isAnimating\n);\n\nMessageResponse.displayName = \"MessageResponse\";\n\nexport type MessageToolbarProps = ComponentProps<\"div\">;\n\nexport const MessageToolbar = ({\n className,\n children,\n ...props\n}: MessageToolbarProps) => (\n <div\n className={cn(\n \"mt-4 flex w-full items-center justify-between gap-4\",\n className\n )}\n {...props}\n >\n {children}\n </div>\n);\n"],"names":["Message","className","from","props","jsx","cn","MessageContent","children","MessageActions","MessageAction","tooltip","label","variant","size","button","Button","TooltipProvider","jsxs","Tooltip","TooltipTrigger","TooltipContent","MessageBranchContext","createContext","useMessageBranch","context","useContext","MessageBranch","defaultBranch","onBranchChange","currentBranch","setCurrentBranch","useState","branches","setBranches","handleBranchChange","useCallback","newBranch","goToPrevious","goToNext","contextValue","useMemo","MessageBranchContent","childrenArray","useEffect","branch","index","MessageBranchSelector","totalBranches","ButtonGroup","MessageBranchPrevious","ChevronLeftIcon","MessageBranchNext","ChevronRightIcon","MessageBranchPage","ButtonGroupText","streamdownPlugins","cjk","code","math","mermaid","MessageResponse","memo","Streamdown","prevProps","nextProps","MessageToolbar"],"mappings":";;;;;;;;;;;;AAoCO,MAAMA,IAAU,CAAC,EAAE,WAAAC,GAAW,MAAAC,GAAM,GAAGC,QAC5C,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,WAAWC;AAAA,MACT;AAAA,MACAH,MAAS,SAAS,gCAAgC;AAAA,MAClDD;AAAA,IAAA;AAAA,IAED,GAAGE;AAAA,EAAA;AACN,GAKWG,KAAiB,CAAC;AAAA,EAC7B,UAAAC;AAAA,EACA,WAAAN;AAAA,EACA,GAAGE;AACL,MACE,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,WAAWC;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACAJ;AAAA,IAAA;AAAA,IAED,GAAGE;AAAA,IAEH,UAAAI;AAAA,EAAA;AACH,GAKWC,KAAiB,CAAC;AAAA,EAC7B,WAAAP;AAAA,EACA,UAAAM;AAAA,EACA,GAAGJ;AACL,MACE,gBAAAC,EAAC,SAAI,WAAWC,EAAG,2BAA2BJ,CAAS,GAAI,GAAGE,GAC3D,UAAAI,EAAA,CACH,GAQWE,KAAgB,CAAC;AAAA,EAC5B,SAAAC;AAAA,EACA,UAAAH;AAAA,EACA,OAAAI;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,MAAAC,IAAO;AAAA,EACP,GAAGV;AACL,MAA0B;AACxB,QAAMW,sBACHC,GAAA,EAAO,MAAAF,GAAY,MAAK,UAAS,SAAAD,GAAmB,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AAAA,QACT;AAAA,QACAJ;AAAA,MAAA;AAAA,MAED,GAAGE;AAAA,MAEH,UAAA,GAAG0B,IAAgB,CAAC,OAAOkB,CAAa;AAAA,IAAA;AAAA,EAAA;AAG/C,GAIMQ,IAAoB,EAAE,KAAAC,GAAK,MAAAC,GAAM,MAAAC,GAAM,SAAAC,EAAA,GAEhCC,IAAkBC;AAAA,EAC7B,CAAC,EAAE,WAAA5D,GAAW,GAAGE,QACf,gBAAAC;AAAA,IAAC0D;AAAA,IAAA;AAAA,MACC,WAAWzD;AAAA,QACT;AAAA,QACAJ;AAAA,MAAA;AAAA,MAEF,SAASsD;AAAA,MACR,GAAGpD;AAAA,IAAA;AAAA,EAAA;AAAA,EAGR,CAAC4D,GAAWC,MACVD,EAAU,aAAaC,EAAU,YACjCA,EAAU,gBAAgBD,EAAU;AACxC;AAEAH,EAAgB,cAAc;AAIvB,MAAMK,KAAiB,CAAC;AAAA,EAC7B,WAAAhE;AAAA,EACA,UAAAM;AAAA,EACA,GAAGJ;AACL,MACE,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,WAAWC;AAAA,MACT;AAAA,MACAJ;AAAA,IAAA;AAAA,IAED,GAAGE;AAAA,IAEH,UAAAI;AAAA,EAAA;AACH;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),l=require("../ui/command.cjs"),c=require("../ui/dialog.cjs"),d=require("../ui/kbd.cjs"),r=require("../../lib/utils.cjs"),a=e=>o.jsx(c.Dialog,{...e}),i=e=>o.jsx(c.DialogTrigger,{...e}),m=({className:e,children:t,title:s="Model Selector",...n})=>o.jsxs(c.DialogContent,{"aria-describedby":void 0,className:r.cn("outline! border-none! p-0 outline-border! outline-solid!",e),...n,children:[o.jsx(c.DialogTitle,{className:"sr-only",children:s}),o.jsx(l.Command,{className:"**:data-[slot=command-input-wrapper]:h-auto",children:t})]}),S=e=>o.jsx(l.CommandDialog,{...e}),g=({className:e,...t})=>o.jsx(l.CommandInput,{className:r.cn("h-auto py-3.5",e),...t}),u=e=>o.jsx(l.CommandList,{...e}),M=e=>o.jsx(l.CommandEmpty,{...e}),p=e=>o.jsx(l.CommandGroup,{...e}),x=e=>o.jsx(l.CommandItem,{...e}),j=({className:e,...t})=>o.jsx(d.Kbd,{className:r.cn("ml-auto",e),...t}),b=e=>o.jsx(l.CommandSeparator,{...e}),h=({provider:e,className:t,...s})=>o.jsx("img",{...s,alt:`${e} logo`,className:r.cn("size-3 dark:invert",t),height:12,src:`https://models.dev/logos/${e}.svg`,width:12}),C=({className:e,...t})=>o.jsx("div",{className:r.cn("flex shrink-0 items-center -space-x-1 [&>img]:rounded-full [&>img]:bg-background [&>img]:p-px [&>img]:ring-1 dark:[&>img]:bg-foreground",e),...t}),N=({className:e,...t})=>o.jsx("span",{className:r.cn("flex-1 truncate text-left",e),...t});exports.ModelSelector=a;exports.ModelSelectorContent=m;exports.ModelSelectorDialog=S;exports.ModelSelectorEmpty=M;exports.ModelSelectorGroup=p;exports.ModelSelectorInput=g;exports.ModelSelectorItem=x;exports.ModelSelectorList=u;exports.ModelSelectorLogo=h;exports.ModelSelectorLogoGroup=C;exports.ModelSelectorName=N;exports.ModelSelectorSeparator=b;exports.ModelSelectorShortcut=j;exports.ModelSelectorTrigger=i;
|
|
2
|
+
//# sourceMappingURL=model-selector.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-selector.cjs","sources":["../../../src/components/ai/model-selector.tsx"],"sourcesContent":["import type { ComponentProps, ReactNode } from \"react\";\n\nimport {\n Command,\n CommandDialog,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n CommandSeparator,\n} from \"@/components/ui/command\";\nimport {\n Dialog,\n DialogContent,\n DialogTitle,\n DialogTrigger,\n} from \"@/components/ui/dialog\";\nimport { Kbd } from \"@/components/ui/kbd\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ModelSelectorProps = ComponentProps<typeof Dialog>;\n\nexport const ModelSelector = (props: ModelSelectorProps) => (\n <Dialog {...props} />\n);\n\nexport type ModelSelectorTriggerProps = ComponentProps<typeof DialogTrigger>;\n\nexport const ModelSelectorTrigger = (props: ModelSelectorTriggerProps) => (\n <DialogTrigger {...props} />\n);\n\nexport type ModelSelectorContentProps = ComponentProps<typeof DialogContent> & {\n title?: ReactNode;\n};\n\nexport const ModelSelectorContent = ({\n className,\n children,\n title = \"Model Selector\",\n ...props\n}: ModelSelectorContentProps) => (\n <DialogContent\n aria-describedby={undefined}\n className={cn(\n \"outline! border-none! p-0 outline-border! outline-solid!\",\n className\n )}\n {...props}\n >\n <DialogTitle className=\"sr-only\">{title}</DialogTitle>\n <Command className=\"**:data-[slot=command-input-wrapper]:h-auto\">\n {children}\n </Command>\n </DialogContent>\n);\n\nexport type ModelSelectorDialogProps = ComponentProps<typeof CommandDialog>;\n\nexport const ModelSelectorDialog = (props: ModelSelectorDialogProps) => (\n <CommandDialog {...props} />\n);\n\nexport type ModelSelectorInputProps = ComponentProps<typeof CommandInput>;\n\nexport const ModelSelectorInput = ({\n className,\n ...props\n}: ModelSelectorInputProps) => (\n <CommandInput className={cn(\"h-auto py-3.5\", className)} {...props} />\n);\n\nexport type ModelSelectorListProps = ComponentProps<typeof CommandList>;\n\nexport const ModelSelectorList = (props: ModelSelectorListProps) => (\n <CommandList {...props} />\n);\n\nexport type ModelSelectorEmptyProps = ComponentProps<typeof CommandEmpty>;\n\nexport const ModelSelectorEmpty = (props: ModelSelectorEmptyProps) => (\n <CommandEmpty {...props} />\n);\n\nexport type ModelSelectorGroupProps = ComponentProps<typeof CommandGroup>;\n\nexport const ModelSelectorGroup = (props: ModelSelectorGroupProps) => (\n <CommandGroup {...props} />\n);\n\nexport type ModelSelectorItemProps = ComponentProps<typeof CommandItem>;\n\nexport const ModelSelectorItem = (props: ModelSelectorItemProps) => (\n <CommandItem {...props} />\n);\n\nexport type ModelSelectorShortcutProps = ComponentProps<typeof Kbd>;\n\nexport const ModelSelectorShortcut = ({\n className,\n ...props\n}: ModelSelectorShortcutProps) => (\n <Kbd className={cn(\"ml-auto\", className)} {...props} />\n);\n\nexport type ModelSelectorSeparatorProps = ComponentProps<\n typeof CommandSeparator\n>;\n\nexport const ModelSelectorSeparator = (props: ModelSelectorSeparatorProps) => (\n <CommandSeparator {...props} />\n);\n\nexport type ModelSelectorLogoProps = Omit<\n ComponentProps<\"img\">,\n \"src\" | \"alt\"\n> & {\n provider:\n | \"moonshotai-cn\"\n | \"lucidquery\"\n | \"moonshotai\"\n | \"zai-coding-plan\"\n | \"alibaba\"\n | \"xai\"\n | \"vultr\"\n | \"nvidia\"\n | \"upstage\"\n | \"groq\"\n | \"github-copilot\"\n | \"mistral\"\n | \"vercel\"\n | \"nebius\"\n | \"deepseek\"\n | \"alibaba-cn\"\n | \"google-vertex-anthropic\"\n | \"venice\"\n | \"chutes\"\n | \"cortecs\"\n | \"github-models\"\n | \"togetherai\"\n | \"azure\"\n | \"baseten\"\n | \"huggingface\"\n | \"opencode\"\n | \"fastrouter\"\n | \"google\"\n | \"google-vertex\"\n | \"cloudflare-workers-ai\"\n | \"inception\"\n | \"wandb\"\n | \"openai\"\n | \"zhipuai-coding-plan\"\n | \"perplexity\"\n | \"openrouter\"\n | \"zenmux\"\n | \"v0\"\n | \"iflowcn\"\n | \"synthetic\"\n | \"deepinfra\"\n | \"zhipuai\"\n | \"submodel\"\n | \"zai\"\n | \"inference\"\n | \"requesty\"\n | \"morph\"\n | \"lmstudio\"\n | \"anthropic\"\n | \"aihubmix\"\n | \"fireworks-ai\"\n | \"modelscope\"\n | \"llama\"\n | \"scaleway\"\n | \"amazon-bedrock\"\n | \"cerebras\"\n // oxlint-disable-next-line typescript-eslint(ban-types) -- intentional pattern for autocomplete-friendly string union\n | (string & {});\n};\n\nexport const ModelSelectorLogo = ({\n provider,\n className,\n ...props\n}: ModelSelectorLogoProps) => (\n <img\n {...props}\n alt={`${provider} logo`}\n className={cn(\"size-3 dark:invert\", className)}\n height={12}\n src={`https://models.dev/logos/${provider}.svg`}\n width={12}\n />\n);\n\nexport type ModelSelectorLogoGroupProps = ComponentProps<\"div\">;\n\nexport const ModelSelectorLogoGroup = ({\n className,\n ...props\n}: ModelSelectorLogoGroupProps) => (\n <div\n className={cn(\n \"flex shrink-0 items-center -space-x-1 [&>img]:rounded-full [&>img]:bg-background [&>img]:p-px [&>img]:ring-1 dark:[&>img]:bg-foreground\",\n className\n )}\n {...props}\n />\n);\n\nexport type ModelSelectorNameProps = ComponentProps<\"span\">;\n\nexport const ModelSelectorName = ({\n className,\n ...props\n}: ModelSelectorNameProps) => (\n <span className={cn(\"flex-1 truncate text-left\", className)} {...props} />\n);\n"],"names":["ModelSelector","props","jsx","Dialog","ModelSelectorTrigger","DialogTrigger","ModelSelectorContent","className","children","title","jsxs","DialogContent","cn","DialogTitle","Command","ModelSelectorDialog","CommandDialog","ModelSelectorInput","CommandInput","ModelSelectorList","CommandList","ModelSelectorEmpty","CommandEmpty","ModelSelectorGroup","CommandGroup","ModelSelectorItem","CommandItem","ModelSelectorShortcut","Kbd","ModelSelectorSeparator","CommandSeparator","ModelSelectorLogo","provider","ModelSelectorLogoGroup","ModelSelectorName"],"mappings":"8OAuBaA,EAAiBC,GAC5BC,EAAAA,IAACC,EAAAA,OAAA,CAAQ,GAAGF,CAAA,CAAO,EAKRG,EAAwBH,GACnCC,EAAAA,IAACG,EAAAA,cAAA,CAAe,GAAGJ,CAAA,CAAO,EAOfK,EAAuB,CAAC,CACnC,UAAAC,EACA,SAAAC,EACA,MAAAC,EAAQ,iBACR,GAAGR,CACL,IACES,EAAAA,KAACC,EAAAA,cAAA,CACC,mBAAkB,OAClB,UAAWC,EAAAA,GACT,2DACAL,CAAA,EAED,GAAGN,EAEJ,SAAA,CAAAC,EAAAA,IAACW,EAAAA,YAAA,CAAY,UAAU,UAAW,SAAAJ,EAAM,EACxCP,EAAAA,IAACY,EAAAA,Q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