@flexkit/studio 0.0.32 → 0.0.34
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/{chunk-QSROLDUU.js → chunk-JH4MVD36.js} +2 -2
- package/dist/{chunk-QSROLDUU.js.map → chunk-JH4MVD36.js.map} +1 -1
- package/dist/chunk-LIV5RBWJ.js +2 -0
- package/dist/chunk-LIV5RBWJ.js.map +1 -0
- package/dist/{chunk-LKBCPAXQ.js → chunk-WJ4ORIXF.js} +2 -2
- package/dist/{chunk-LKBCPAXQ.js.map → chunk-WJ4ORIXF.js.map} +1 -1
- package/dist/index.css +0 -3
- package/dist/index.d.ts +10 -6
- package/dist/index.js +92 -86
- package/dist/index.js.map +1 -1
- package/dist/{search-X5V3YOTZ.js → search-KIII5N7I.js} +2 -2
- package/dist/{search-X5V3YOTZ.js.map → search-KIII5N7I.js.map} +1 -1
- package/dist/{types.d-710RgZFw.d.ts → types.d-9Gbw_A9L.d.ts} +33 -29
- package/dist/ui.d.ts +3 -3
- package/dist/ui.js +1 -1
- package/dist/ui.js.map +1 -1
- package/dist/{user-nav-XVY7JTX6.js → user-nav-6UKDSUF3.js} +2 -2
- package/dist/{user-nav-XVY7JTX6.js.map → user-nav-6UKDSUF3.js.map} +1 -1
- package/package.json +3 -1
- package/dist/chunk-5FHCSAK2.js +0 -2
- package/dist/chunk-5FHCSAK2.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import'./index.css';import {f}from'./chunk-
|
|
2
|
-
//# sourceMappingURL=search-
|
|
1
|
+
import'./index.css';import {f}from'./chunk-JH4MVD36.js';import {b}from'./chunk-XFY7MZJN.js';import {n,w,r,q,s,u,b as b$2}from'./chunk-KHPTVIYT.js';import {a,d,c,e,g}from'./chunk-XU2JGXYC.js';import'./chunk-LIV5RBWJ.js';import'./chunk-WDRCARCP.js';import {b as b$1}from'./chunk-EYGOJ2ZN.js';import'./chunk-WIUPQHZ5.js';import {a as a$1}from'./chunk-O2QMYUPS.js';import {useState,useMemo,useRef}from'react';import {LoaderCircle,Search,X}from'lucide-react';import {Command}from'cmdk';import {useNavigate}from'react-router-dom';import {jsxs,jsx}from'react/jsx-runtime';var i="all";function ee(r){let n=r.replace(/([A-Z])/g," $1");return n.charAt(0).toUpperCase()+n.slice(1).trim()}function te(r){return r.filter(n=>n.attributes.some(a=>a.searchable))}function re(r,n){return n===i?r.map(a=>a.plural):r.filter(a=>a.plural===n).map(a=>a.plural)}function ne(r,n){return n===i?i:r.some(a=>a.plural===n)?n:i}function ae(r,n){return {searchRequests:{searches:r.map(a=>({collection:a}))},commonParams:{q:n}}}function oe(r){return r.menu?.label??ee(r.plural)}function be({onSelect:r$1,searchPlaceholder:n$1="Search...",noResultsMsg:a$2="Nothing found",className:V,onSearchChange:y,projectId:D,schema:v}){let[G,l]=useState(false),[s$1,S]=useState(""),[M,X$1]=useState(i),f$1=useMemo(()=>te(v),[v]),m=ne(f$1,M),C=useMemo(()=>re(f$1,m),[f$1,m]),j=useMemo(()=>ae(C,s$1),[C,s$1]),u$1=useRef(null),{results:k,isLoading:d$1}=f(D,j),z=G&&(k.length>0||!d$1),F=useNavigate();function J(e){S(e),e.length>0&&l(true),e.length===0&&l(false),y&&y(e);}function U(e){X$1(e),s$1.length>0&&l(true);}function q$1(){S(""),l(false),u$1.current&&(u$1.current.value="");let e=new URL(window.location.href);e.searchParams.has("id")&&(e.searchParams.delete("id"),F(e.pathname+e.search));}return jsxs(b,{children:[jsxs(a,{onValueChange:U,value:m,children:[jsx(d,{"aria-label":"Filter search by entity",className:"fk:w-36 fk:h-9 fk:py-1 fk:rounded-r-none fk:border-border fk:shadow-none",children:jsx(c,{})}),jsxs(e,{children:[jsx(g,{value:i,children:"All"}),f$1.map(e=>jsx(g,{value:e.plural,children:oe(e)},e.plural))]})]}),jsxs(n,{className:"fk:relative fk:overflow-visible fk:h-auto fk:justify-center fk:rounded-none fk:bg-transparent",onBlur:()=>{setTimeout(()=>{l(false);},300);},onKeyDown:e=>{e.key==="Escape"&&(e.preventDefault(),l(false));},shouldFilter:false,children:[jsxs("div",{className:a$1("fk:flex fk:items-center fk:border-y fk:border-r fk:border-border fk:rounded-r-md fk:bg-background fk:pl-3 fk:pr-2 fk:h-9 fk:md:w-25 fk:lg:w-75","fk:outline-none fk:transition-[color,box-shadow] fk:has-[input:focus-visible]:border-ring fk:has-[input:focus-visible]:ring-[3px] fk:has-[input:focus-visible]:ring-ring/50"),children:[d$1?jsx(LoaderCircle,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(Command.Input,{className:a$1("fk:flex fk:h-9 fk:w-full fk:rounded-none fk:bg-transparent fk:py-1 fk:text-sm fk:outline-hidden fk:placeholder:text-muted-foreground fk:disabled:cursor-not-allowed fk:disabled:opacity-50",V),placeholder:n$1,onMouseDown:()=>{(u$1.current?.value.length??0)>0&&l(true);},onValueChange:J,ref:u$1,value:s$1}),s$1&&jsx(b$1,{"aria-label":"Clear search",className:"fk:flex fk:items-center fk:justify-center fk:ml-2 fk:h-6 fk:w-6 fk:text-muted-foreground fk:hover:text-foreground fk:hover:bg-foreground/10 fk:cursor-pointer fk:rounded-full fk:bg-transparent",onClick:q$1,type:"button",children:jsx(X,{className:"fk:h-4 fk:w-4"})})]}),jsx("div",{className:"fk:relative fk:max-w-150",children:jsx("div",{className:a$1("fk:mt-1 fk:animate-in fk:fade-in-0 fk:zoom-in-95 fk:absolute fk:top-0 fk:z-50 fk:w-full fk:rounded-md fk:bg-popover fk:outline-hidden fk:drop-shadow-md fk:border fk:border-border",z?"fk:block":"fk:hidden"),children:jsxs(w,{className:"fk:max-h-55 fk:overflow-auto",children:[!d$1&&jsx(r,{children:a$2}),jsx(q,{children:jsxs(s,{children:[k.length>0&&jsx(u,{"aria-hidden":"true",className:"fk:hidden!",value:"-"}),k.map(e=>jsxs(u,{className:"fk:flex",value:e._id,onSelect:H=>{r$1({entityName:e._entityName,entityNamePlural:e._entityNamePlural,entityId:H});},children:[jsx("span",{className:"fk:basis-full",children:e[Object.keys(e)[3]]}),jsx(b$2,{className:"fk:py-px fk:text-[0.6875rem] fk:leading-3 fk:bg-teal-400",children:e._entityName})]},e._id))]})})]})})})]})]})}export{be as Search};//# sourceMappingURL=search-KIII5N7I.js.map
|
|
2
|
+
//# sourceMappingURL=search-KIII5N7I.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ui/components/search.tsx"],"names":["ALL_COLLECTIONS","capitalize","str","withSpaces","getSearchableEntities","schema","entity","attr","getCollections","entities","selectedCollection","resolveCollection","buildSearchRequest","collections","q","collection","entityLabel","Search","onSelect","searchPlaceholder","noResultsMsg","className","onSearchChange","projectId","isOpen","setIsOpen","useState","inputValue","setInputValue","setSelectedCollection","searchableEntities","useMemo","resolvedCollection","searchQuery","inputRef","useRef","results","isLoading","useSearch","showDropdown","navigate","useNavigate","handleOnSearchChange","handleEntityChange","value","handleClear","url","jsxs","ButtonGroup","Select","jsx","SelectTrigger","SelectValue","SelectContent","SelectItem","Command","cn","LoaderCircle","SearchIcon","CommandPrimitive","Button","XIcon","ScrollArea","CommandEmpty","CommandList","CommandGroup","CommandItem","item","entityId","Badge"],"mappings":"qjBAwCA,IAAMA,CAAAA,CAAkB,KAAA,CAExB,SAASC,EAAAA,CAAWC,EAAqB,CACvC,IAAMC,CAAAA,CAAaD,CAAAA,CAAI,OAAA,CAAQ,UAAA,CAAY,KAAK,CAAA,CAEhD,OAAOC,CAAAA,CAAW,MAAA,CAAO,CAAC,CAAA,CAAE,aAAY,CAAIA,CAAAA,CAAW,KAAA,CAAM,CAAC,EAAE,IAAA,EAClE,CAEA,SAASC,GAAsBC,CAAAA,CAA4B,CACzD,OAAOA,CAAAA,CAAO,OAAQC,CAAAA,EAAWA,CAAAA,CAAO,UAAA,CAAW,IAAA,CAAM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A,CAAA3C,IAAa,CAAA,CAC3C8B,GAAAA,CAACc,CAAAA,CAAA,CACC,SAAAjB,IAAAA,CAACkB,CAAAA,CAAA,CACE,QAAA,CAAA,CAAA7B,CAAAA,CAAQ,MAAA,CAAS,CAAA,EAAKc,GAAAA,CAACgB,EAAA,CAAY,aAAA,CAAY,MAAA,CAAO,SAAA,CAAU,aAAa,KAAA,CAAM,GAAA,CAAI,CAAA,CACvF9B,CAAAA,CAAQ,IAAK+B,CAAAA,EACZpB,IAAAA,CAACmB,CAAAA,CAAA,CACC,UAAU,SAAA,CAEV,KAAA,CAAOC,CAAAA,CAAK,GAAA,CACZ,SAAWC,CAAAA,EAAa,CACtBlD,GAAAA,CAAS,CAAE,WAAYiD,CAAAA,CAAK,WAAA,CAAa,gBAAA,CAAkBA,CAAAA,CAAK,kBAAmB,QAAA,CAAAC,CAAS,CAAC,EAC/F,CAAA,CAEA,QAAA,CAAA,CAAAlB,GAAAA,CAAC,MAAA,CAAA,CAAK,UAAU,eAAA,CAAiB,QAAA,CAAAiB,CAAAA,CAAK,MAAA,CAAO,KAAKA,CAAI,CAAA,CAAE,CAAC,CAAC,EAAE,CAAA,CAC5DjB,GAAAA,CAACmB,GAAAA,CAAA,CAAM,UAAU,0DAAA,CACd,QAAA,CAAAF,CAAAA,CAAK,WAAA,CACR,IATKA,CAAAA,CAAK,GAUZ,CACD,CAAA,CAAA,CACH,EACF,CAAA,CAAA,CACF,CAAA,CACF,CAAA,CACF,CAAA,CAAA,CACF,GACF,CAEJ","file":"search-X5V3YOTZ.js","sourcesContent":["'use client';\n\nimport { useRef, useState, useMemo } from 'react';\nimport type { JSX } from 'react';\nimport { LoaderCircle, Search as SearchIcon, X as XIcon } from 'lucide-react';\nimport { Command as CommandPrimitive } from 'cmdk';\nimport { useNavigate } from 'react-router-dom';\nimport { useSearch } from '../../core/use-search';\nimport { cn } from '../lib/utils';\nimport { Badge } from '../primitives/badge';\nimport { Button } from '../primitives/button';\nimport { ButtonGroup } from '../primitives/button-group';\nimport { Command, CommandEmpty, CommandGroup, CommandItem, CommandList } from '../primitives/command';\nimport { ScrollArea } from '../primitives/scroll-area';\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../primitives/select';\nimport type { Entity, SearchRequestProps } from '../../core/types';\n\nexport type ComboBoxItemType = {\n value: string;\n label: string;\n};\n\nexport interface SearchProps {\n onSelect: ({\n entityName,\n entityNamePlural,\n entityId,\n }: {\n entityName: string;\n entityNamePlural: string;\n entityId: string;\n }) => void;\n searchPlaceholder?: string;\n noResultsMsg?: string;\n className?: string;\n onSearchChange?: (e: string) => void;\n projectId: string;\n schema: Entity[];\n}\n\nconst ALL_COLLECTIONS = 'all';\n\nfunction capitalize(str: string): string {\n const withSpaces = str.replace(/([A-Z])/g, ' $1');\n\n return withSpaces.charAt(0).toUpperCase() + withSpaces.slice(1).trim();\n}\n\nfunction getSearchableEntities(schema: Entity[]): Entity[] {\n return schema.filter((entity) => entity.attributes.some((attr) => attr.searchable));\n}\n\nfunction getCollections(entities: Entity[], selectedCollection: string): string[] {\n if (selectedCollection === ALL_COLLECTIONS) {\n return entities.map((entity) => entity.plural);\n }\n\n return entities.filter((entity) => entity.plural === selectedCollection).map((entity) => entity.plural);\n}\n\nfunction resolveCollection(entities: Entity[], selectedCollection: string): string {\n if (selectedCollection === ALL_COLLECTIONS) {\n return ALL_COLLECTIONS;\n }\n\n if (entities.some((entity) => entity.plural === selectedCollection)) {\n return selectedCollection;\n }\n\n return ALL_COLLECTIONS;\n}\n\nfunction buildSearchRequest(collections: string[], q: string): SearchRequestProps {\n return {\n searchRequests: {\n searches: collections.map((collection) => ({\n collection,\n })),\n },\n commonParams: {\n q,\n },\n };\n}\n\nfunction entityLabel(entity: Entity): string {\n return entity.menu?.label ?? capitalize(entity.plural);\n}\n\nexport function Search({\n onSelect,\n searchPlaceholder = 'Search...',\n noResultsMsg = 'Nothing found',\n className,\n onSearchChange,\n projectId,\n schema,\n}: SearchProps): JSX.Element {\n const [isOpen, setIsOpen] = useState(false);\n const [inputValue, setInputValue] = useState('');\n const [selectedCollection, setSelectedCollection] = useState(ALL_COLLECTIONS);\n const searchableEntities = useMemo(() => getSearchableEntities(schema), [schema]);\n const resolvedCollection = resolveCollection(searchableEntities, selectedCollection);\n const collections = useMemo(\n () => getCollections(searchableEntities, resolvedCollection),\n [searchableEntities, resolvedCollection]\n );\n const searchQuery = useMemo(() => buildSearchRequest(collections, inputValue), [collections, inputValue]);\n const inputRef = useRef<HTMLInputElement>(null);\n const { results, isLoading } = useSearch(projectId, searchQuery);\n const showDropdown = isOpen && (results.length > 0 || !isLoading);\n const navigate = useNavigate();\n\n function handleOnSearchChange(q: string): void {\n setInputValue(q);\n // TODO: Add debounce\n if (q.length > 0) {\n setIsOpen(true);\n }\n\n if (q.length === 0) {\n setIsOpen(false);\n }\n\n if (onSearchChange) {\n onSearchChange(q);\n }\n }\n\n function handleEntityChange(value: string): void {\n setSelectedCollection(value);\n\n if (inputValue.length > 0) {\n setIsOpen(true);\n }\n }\n\n function handleClear(): void {\n setInputValue('');\n setIsOpen(false);\n\n if (inputRef.current) {\n inputRef.current.value = '';\n }\n\n // Remove id from URL if present\n const url = new URL(window.location.href);\n\n if (url.searchParams.has('id')) {\n url.searchParams.delete('id');\n navigate(url.pathname + url.search);\n }\n }\n\n // TODO: handle error\n\n return (\n <ButtonGroup>\n <Select onValueChange={handleEntityChange} value={resolvedCollection}>\n <SelectTrigger\n aria-label=\"Filter search by entity\"\n className=\"fk:w-36 fk:h-9 fk:py-1 fk:rounded-r-none fk:border-border fk:shadow-none\"\n >\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n <SelectItem value={ALL_COLLECTIONS}>All</SelectItem>\n {searchableEntities.map((entity) => (\n <SelectItem key={entity.plural} value={entity.plural}>\n {entityLabel(entity)}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n <Command\n className=\"fk:relative fk:overflow-visible fk:h-auto fk:justify-center fk:rounded-none fk:bg-transparent\"\n onBlur={() => {\n // close after a delay to allow any click event from the results list to be handled\n setTimeout(() => {\n setIsOpen(false);\n }, 300);\n }}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n setIsOpen(false);\n }\n }}\n shouldFilter={false}\n >\n <div\n className={cn(\n 'fk:flex fk:items-center fk:border-y fk:border-r fk:border-border fk:rounded-r-md fk:bg-background fk:pl-3 fk:pr-2 fk:h-9 fk:md:w-25 fk:lg:w-75',\n 'fk:outline-none fk:transition-[color,box-shadow] fk:has-[input:focus-visible]:border-ring fk:has-[input:focus-visible]:ring-[3px] fk:has-[input:focus-visible]:ring-ring/50'\n )}\n >\n {isLoading ? (\n <LoaderCircle className=\"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin\" />\n ) : (\n <SearchIcon className=\"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50\" />\n )}\n <CommandPrimitive.Input\n className={cn(\n 'fk:flex fk:h-9 fk:w-full fk:rounded-none fk:bg-transparent fk:py-1 fk:text-sm fk:outline-hidden fk:placeholder:text-muted-foreground fk:disabled:cursor-not-allowed fk:disabled:opacity-50',\n className\n )}\n placeholder={searchPlaceholder}\n onMouseDown={() => {\n if ((inputRef.current?.value.length ?? 0) > 0) setIsOpen(true);\n }}\n onValueChange={handleOnSearchChange}\n ref={inputRef}\n value={inputValue}\n />\n {inputValue && (\n <Button\n aria-label=\"Clear search\"\n className=\"fk:flex fk:items-center fk:justify-center fk:ml-2 fk:h-6 fk:w-6 fk:text-muted-foreground fk:hover:text-foreground fk:hover:bg-foreground/10 fk:cursor-pointer fk:rounded-full fk:bg-transparent\"\n onClick={handleClear}\n type=\"button\"\n >\n <XIcon className=\"fk:h-4 fk:w-4\" />\n </Button>\n )}\n </div>\n <div className=\"fk:relative fk:max-w-150\">\n <div\n className={cn(\n 'fk:mt-1 fk:animate-in fk:fade-in-0 fk:zoom-in-95 fk:absolute fk:top-0 fk:z-50 fk:w-full fk:rounded-md fk:bg-popover fk:outline-hidden fk:drop-shadow-md fk:border fk:border-border',\n showDropdown ? 'fk:block' : 'fk:hidden'\n )}\n >\n <ScrollArea className=\"fk:max-h-55 fk:overflow-auto\">\n {!isLoading && <CommandEmpty>{noResultsMsg}</CommandEmpty>}\n <CommandList>\n <CommandGroup>\n {results.length > 0 && <CommandItem aria-hidden=\"true\" className=\"fk:hidden!\" value=\"-\" />}\n {results.map((item) => (\n <CommandItem\n className=\"fk:flex\"\n key={item._id}\n value={item._id}\n onSelect={(entityId) => {\n onSelect({ entityName: item._entityName, entityNamePlural: item._entityNamePlural, entityId });\n }}\n >\n <span className=\"fk:basis-full\">{item[Object.keys(item)[3]]}</span>\n <Badge className=\"fk:py-px fk:text-[0.6875rem] fk:leading-3 fk:bg-teal-400\">\n {item._entityName}\n </Badge>\n </CommandItem>\n ))}\n </CommandGroup>\n </CommandList>\n </ScrollArea>\n </div>\n </div>\n </Command>\n </ButtonGroup>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ui/components/search.tsx"],"names":["ALL_COLLECTIONS","capitalize","str","withSpaces","getSearchableEntities","schema","entity","attr","getCollections","entities","selectedCollection","resolveCollection","buildSearchRequest","collections","q","collection","entityLabel","Search","onSelect","searchPlaceholder","noResultsMsg","className","onSearchChange","projectId","isOpen","setIsOpen","useState","inputValue","setInputValue","setSelectedCollection","searchableEntities","useMemo","resolvedCollection","searchQuery","inputRef","useRef","results","isLoading","useSearch","showDropdown","navigate","useNavigate","handleOnSearchChange","handleEntityChange","value","handleClear","url","jsxs","ButtonGroup","Select","jsx","SelectTrigger","SelectValue","SelectContent","SelectItem","Command","cn","LoaderCircle","SearchIcon","CommandPrimitive","Button","XIcon","ScrollArea","CommandEmpty","CommandList","CommandGroup","CommandItem","item","entityId","Badge"],"mappings":"qjBAwCA,IAAMA,CAAAA,CAAkB,KAAA,CAExB,SAASC,EAAAA,CAAWC,EAAqB,CACvC,IAAMC,CAAAA,CAAaD,CAAAA,CAAI,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.js","sourcesContent":["'use client';\n\nimport { useRef, useState, useMemo } from 'react';\nimport type { JSX } from 'react';\nimport { LoaderCircle, Search as SearchIcon, X as XIcon } from 'lucide-react';\nimport { Command as CommandPrimitive } from 'cmdk';\nimport { useNavigate } from 'react-router-dom';\nimport { useSearch } from '../../core/use-search';\nimport { cn } from '../lib/utils';\nimport { Badge } from '../primitives/badge';\nimport { Button } from '../primitives/button';\nimport { ButtonGroup } from '../primitives/button-group';\nimport { Command, CommandEmpty, CommandGroup, CommandItem, CommandList } from '../primitives/command';\nimport { ScrollArea } from '../primitives/scroll-area';\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../primitives/select';\nimport type { Entity, SearchRequestProps } from '../../core/types';\n\nexport type ComboBoxItemType = {\n value: string;\n label: string;\n};\n\nexport interface SearchProps {\n onSelect: ({\n entityName,\n entityNamePlural,\n entityId,\n }: {\n entityName: string;\n entityNamePlural: string;\n entityId: string;\n }) => void;\n searchPlaceholder?: string;\n noResultsMsg?: string;\n className?: string;\n onSearchChange?: (e: string) => void;\n projectId: string;\n schema: Entity[];\n}\n\nconst ALL_COLLECTIONS = 'all';\n\nfunction capitalize(str: string): string {\n const withSpaces = str.replace(/([A-Z])/g, ' $1');\n\n return withSpaces.charAt(0).toUpperCase() + withSpaces.slice(1).trim();\n}\n\nfunction getSearchableEntities(schema: Entity[]): Entity[] {\n return schema.filter((entity) => entity.attributes.some((attr) => attr.searchable));\n}\n\nfunction getCollections(entities: Entity[], selectedCollection: string): string[] {\n if (selectedCollection === ALL_COLLECTIONS) {\n return entities.map((entity) => entity.plural);\n }\n\n return entities.filter((entity) => entity.plural === selectedCollection).map((entity) => entity.plural);\n}\n\nfunction resolveCollection(entities: Entity[], selectedCollection: string): string {\n if (selectedCollection === ALL_COLLECTIONS) {\n return ALL_COLLECTIONS;\n }\n\n if (entities.some((entity) => entity.plural === selectedCollection)) {\n return selectedCollection;\n }\n\n return ALL_COLLECTIONS;\n}\n\nfunction buildSearchRequest(collections: string[], q: string): SearchRequestProps {\n return {\n searchRequests: {\n searches: collections.map((collection) => ({\n collection,\n })),\n },\n commonParams: {\n q,\n },\n };\n}\n\nfunction entityLabel(entity: Entity): string {\n return entity.menu?.label ?? capitalize(entity.plural);\n}\n\nexport function Search({\n onSelect,\n searchPlaceholder = 'Search...',\n noResultsMsg = 'Nothing found',\n className,\n onSearchChange,\n projectId,\n schema,\n}: SearchProps): JSX.Element {\n const [isOpen, setIsOpen] = useState(false);\n const [inputValue, setInputValue] = useState('');\n const [selectedCollection, setSelectedCollection] = useState(ALL_COLLECTIONS);\n const searchableEntities = useMemo(() => getSearchableEntities(schema), [schema]);\n const resolvedCollection = resolveCollection(searchableEntities, selectedCollection);\n const collections = useMemo(\n () => getCollections(searchableEntities, resolvedCollection),\n [searchableEntities, resolvedCollection]\n );\n const searchQuery = useMemo(() => buildSearchRequest(collections, inputValue), [collections, inputValue]);\n const inputRef = useRef<HTMLInputElement>(null);\n const { results, isLoading } = useSearch(projectId, searchQuery);\n const showDropdown = isOpen && (results.length > 0 || !isLoading);\n const navigate = useNavigate();\n\n function handleOnSearchChange(q: string): void {\n setInputValue(q);\n // TODO: Add debounce\n if (q.length > 0) {\n setIsOpen(true);\n }\n\n if (q.length === 0) {\n setIsOpen(false);\n }\n\n if (onSearchChange) {\n onSearchChange(q);\n }\n }\n\n function handleEntityChange(value: string): void {\n setSelectedCollection(value);\n\n if (inputValue.length > 0) {\n setIsOpen(true);\n }\n }\n\n function handleClear(): void {\n setInputValue('');\n setIsOpen(false);\n\n if (inputRef.current) {\n inputRef.current.value = '';\n }\n\n // Remove id from URL if present\n const url = new URL(window.location.href);\n\n if (url.searchParams.has('id')) {\n url.searchParams.delete('id');\n navigate(url.pathname + url.search);\n }\n }\n\n // TODO: handle error\n\n return (\n <ButtonGroup>\n <Select onValueChange={handleEntityChange} value={resolvedCollection}>\n <SelectTrigger\n aria-label=\"Filter search by entity\"\n className=\"fk:w-36 fk:h-9 fk:py-1 fk:rounded-r-none fk:border-border fk:shadow-none\"\n >\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n <SelectItem value={ALL_COLLECTIONS}>All</SelectItem>\n {searchableEntities.map((entity) => (\n <SelectItem key={entity.plural} value={entity.plural}>\n {entityLabel(entity)}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n <Command\n className=\"fk:relative fk:overflow-visible fk:h-auto fk:justify-center fk:rounded-none fk:bg-transparent\"\n onBlur={() => {\n // close after a delay to allow any click event from the results list to be handled\n setTimeout(() => {\n setIsOpen(false);\n }, 300);\n }}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n setIsOpen(false);\n }\n }}\n shouldFilter={false}\n >\n <div\n className={cn(\n 'fk:flex fk:items-center fk:border-y fk:border-r fk:border-border fk:rounded-r-md fk:bg-background fk:pl-3 fk:pr-2 fk:h-9 fk:md:w-25 fk:lg:w-75',\n 'fk:outline-none fk:transition-[color,box-shadow] fk:has-[input:focus-visible]:border-ring fk:has-[input:focus-visible]:ring-[3px] fk:has-[input:focus-visible]:ring-ring/50'\n )}\n >\n {isLoading ? (\n <LoaderCircle className=\"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin\" />\n ) : (\n <SearchIcon className=\"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50\" />\n )}\n <CommandPrimitive.Input\n className={cn(\n 'fk:flex fk:h-9 fk:w-full fk:rounded-none fk:bg-transparent fk:py-1 fk:text-sm fk:outline-hidden fk:placeholder:text-muted-foreground fk:disabled:cursor-not-allowed fk:disabled:opacity-50',\n className\n )}\n placeholder={searchPlaceholder}\n onMouseDown={() => {\n if ((inputRef.current?.value.length ?? 0) > 0) setIsOpen(true);\n }}\n onValueChange={handleOnSearchChange}\n ref={inputRef}\n value={inputValue}\n />\n {inputValue && (\n <Button\n aria-label=\"Clear search\"\n className=\"fk:flex fk:items-center fk:justify-center fk:ml-2 fk:h-6 fk:w-6 fk:text-muted-foreground fk:hover:text-foreground fk:hover:bg-foreground/10 fk:cursor-pointer fk:rounded-full fk:bg-transparent\"\n onClick={handleClear}\n type=\"button\"\n >\n <XIcon className=\"fk:h-4 fk:w-4\" />\n </Button>\n )}\n </div>\n <div className=\"fk:relative fk:max-w-150\">\n <div\n className={cn(\n 'fk:mt-1 fk:animate-in fk:fade-in-0 fk:zoom-in-95 fk:absolute fk:top-0 fk:z-50 fk:w-full fk:rounded-md fk:bg-popover fk:outline-hidden fk:drop-shadow-md fk:border fk:border-border',\n showDropdown ? 'fk:block' : 'fk:hidden'\n )}\n >\n <ScrollArea className=\"fk:max-h-55 fk:overflow-auto\">\n {!isLoading && <CommandEmpty>{noResultsMsg}</CommandEmpty>}\n <CommandList>\n <CommandGroup>\n {results.length > 0 && <CommandItem aria-hidden=\"true\" className=\"fk:hidden!\" value=\"-\" />}\n {results.map((item) => (\n <CommandItem\n className=\"fk:flex\"\n key={item._id}\n value={item._id}\n onSelect={(entityId) => {\n onSelect({ entityName: item._entityName, entityNamePlural: item._entityNamePlural, entityId });\n }}\n >\n <span className=\"fk:basis-full\">{item[Object.keys(item)[3]]}</span>\n <Badge className=\"fk:py-px fk:text-[0.6875rem] fk:leading-3 fk:bg-teal-400\">\n {item._entityName}\n </Badge>\n </CommandItem>\n ))}\n </CommandGroup>\n </CommandList>\n </ScrollArea>\n </div>\n </div>\n </Command>\n </ButtonGroup>\n );\n}\n"]}
|
|
@@ -38,6 +38,7 @@ type MappedEntityItem = {
|
|
|
38
38
|
type ImageValue = {
|
|
39
39
|
_id: string;
|
|
40
40
|
path: string;
|
|
41
|
+
url?: string;
|
|
41
42
|
size: number;
|
|
42
43
|
mimeType: string;
|
|
43
44
|
originalFilename: string;
|
|
@@ -386,37 +387,40 @@ interface AppRoute {
|
|
|
386
387
|
children?: AppRoute[];
|
|
387
388
|
}
|
|
388
389
|
|
|
389
|
-
interface
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
390
|
+
interface StudioExtension {
|
|
391
|
+
/** Stable machine-readable identity, independent of the optional display label. */
|
|
392
|
+
id: string;
|
|
393
|
+
name?: string;
|
|
394
|
+
contributes: StudioContributions;
|
|
395
|
+
extensions?: StudioExtension[];
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
interface StudioContributions {
|
|
399
|
+
apps?: AppOptions[];
|
|
400
|
+
formFields?: {
|
|
401
|
+
[key: string]: {
|
|
402
|
+
component: (Props: FormFieldProps) => JSX.Element;
|
|
403
|
+
description?: string;
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
previewFields?: {
|
|
407
|
+
[key: string]: {
|
|
408
|
+
component: ({ value }: { value: string | boolean | number | null | Date | Image }) => JSX.Element | null;
|
|
409
|
+
description?: string;
|
|
410
|
+
};
|
|
411
|
+
};
|
|
412
|
+
commands?: CommandOptions[];
|
|
413
|
+
navbar?: {
|
|
414
|
+
logo?: {
|
|
415
|
+
component: (Props: LogoProps) => JSX.Element;
|
|
399
416
|
};
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
component: ({ value }: { value: string | boolean | number | null | Date | Image }) => JSX.Element | null;
|
|
403
|
-
description?: string;
|
|
404
|
-
};
|
|
417
|
+
projectSelector?: {
|
|
418
|
+
component: (Props: ProjectSelectorProps) => JSX.Element;
|
|
405
419
|
};
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
logo?: {
|
|
409
|
-
component: (Props: LogoProps) => JSX.Element;
|
|
410
|
-
};
|
|
411
|
-
projectSelector?: {
|
|
412
|
-
component: (Props: ProjectSelectorProps) => JSX.Element;
|
|
413
|
-
};
|
|
414
|
-
search?: {
|
|
415
|
-
component: (Props: SearchProps) => JSX.Element;
|
|
416
|
-
};
|
|
420
|
+
search?: {
|
|
421
|
+
component: (Props: SearchProps) => JSX.Element;
|
|
417
422
|
};
|
|
418
423
|
};
|
|
419
|
-
plugins?: PluginOptions[];
|
|
420
424
|
}
|
|
421
425
|
|
|
422
426
|
interface ProjectOptions {
|
|
@@ -428,7 +432,7 @@ interface ProjectOptions {
|
|
|
428
432
|
title: string;
|
|
429
433
|
name: string;
|
|
430
434
|
}[];
|
|
431
|
-
|
|
435
|
+
extensions?: StudioExtension[];
|
|
432
436
|
scopes?: Scopes;
|
|
433
437
|
/**
|
|
434
438
|
* Permission spaces for this project. Spaces scope access to entities,
|
|
@@ -448,4 +452,4 @@ type SingleProject = Omit<ProjectOptions, 'basePath'> & {
|
|
|
448
452
|
|
|
449
453
|
type Config = SingleProject | ProjectOptions[];
|
|
450
454
|
|
|
451
|
-
export type { AppContextType as A, Config as C, DataType as D, Entity as E, FieldGroup as F, ImageValue as I, LogoProps as L, MappedEntityItem as M, OrderedAssetValue as O,
|
|
455
|
+
export type { AppContextType as A, Config as C, DataType as D, Entity as E, FieldGroup as F, ImageValue as I, LogoProps as L, MappedEntityItem as M, OrderedAssetValue as O, ProjectOptions as P, StudioContributions as S, UseEntityQueryParams as U, ActionSetRelationship as a, ActionSetScope as b, AppOptions as c, StudioExtension as d, SearchRequestProps as e, SearchResultItem as f, Attribute as g, AuthService as h, FormEntityItem as i, Schema as j, User as k, AttributeValue as l, MultipleRelationshipConnection as m, SingleRelationshipConnection as n, ConditionalFieldContext as o, ConditionalFlag as p, DefaultValue as q, DefaultValueByDataType as r, EntityData as s, FormFieldParams as t, FormFieldProps as u, FormFieldValue as v, ScopeType as w, SingleProject as x };
|
package/dist/ui.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { FieldValues, FieldPath, ControllerProps } from 'react-hook-form';
|
|
|
9
9
|
import { Command as Command$1 } from 'cmdk';
|
|
10
10
|
import * as ResizablePrimitive from 'react-resizable-panels';
|
|
11
11
|
export { PanelImperativeHandle } from 'react-resizable-panels';
|
|
12
|
-
import {
|
|
12
|
+
import { x as SingleProject } from './types.d-9Gbw_A9L.js';
|
|
13
13
|
import { ToasterProps } from 'sonner';
|
|
14
14
|
export { toast } from 'sonner';
|
|
15
15
|
import { FileUIPart, SourceDocumentUIPart, UIMessage, ChatStatus, ToolUIPart, DynamicToolUIPart } from 'ai';
|
|
@@ -535,7 +535,7 @@ declare const usePromptInputReferencedSources: () => ReferencedSourcesContext;
|
|
|
535
535
|
type PromptInputActionAddAttachmentsProps = ComponentProps<typeof DropdownMenuItem> & {
|
|
536
536
|
label?: string;
|
|
537
537
|
};
|
|
538
|
-
declare const PromptInputActionAddAttachments: ({ label, ...props }: PromptInputActionAddAttachmentsProps) => react_jsx_runtime.JSX.Element;
|
|
538
|
+
declare const PromptInputActionAddAttachments: ({ label, onSelect, ...props }: PromptInputActionAddAttachmentsProps) => react_jsx_runtime.JSX.Element;
|
|
539
539
|
type PromptInputActionAddScreenshotProps = ComponentProps<typeof DropdownMenuItem> & {
|
|
540
540
|
label?: string;
|
|
541
541
|
};
|
|
@@ -582,7 +582,7 @@ declare const PromptInputActionMenu: (props: PromptInputActionMenuProps) => reac
|
|
|
582
582
|
type PromptInputActionMenuTriggerProps = PromptInputButtonProps;
|
|
583
583
|
declare const PromptInputActionMenuTrigger: ({ className, children, ...props }: PromptInputActionMenuTriggerProps) => react_jsx_runtime.JSX.Element;
|
|
584
584
|
type PromptInputActionMenuContentProps = ComponentProps<typeof DropdownMenuContent>;
|
|
585
|
-
declare const PromptInputActionMenuContent: ({ className, ...props }: PromptInputActionMenuContentProps) => react_jsx_runtime.JSX.Element;
|
|
585
|
+
declare const PromptInputActionMenuContent: ({ className, onCloseAutoFocus, ...props }: PromptInputActionMenuContentProps) => react_jsx_runtime.JSX.Element;
|
|
586
586
|
type PromptInputActionMenuItemProps = ComponentProps<typeof DropdownMenuItem>;
|
|
587
587
|
declare const PromptInputActionMenuItem: ({ className, ...props }: PromptInputActionMenuItemProps) => react_jsx_runtime.JSX.Element;
|
|
588
588
|
type PromptInputSubmitProps = ComponentProps<typeof InputGroupButton> & {
|
package/dist/ui.js
CHANGED
|
@@ -2,6 +2,6 @@ import'./index.css';import {l,m,n}from'./chunk-PXB5QSHN.js';export{g as DrawerMo
|
|
|
2
2
|
`:e.tokens.map(({token:o,key:r})=>jsx(ca,{token:o},r))}),wo=createContext({code:""}),Co=new Map,Po=new Map,ue=new Map,ma=(e,t)=>{let o=e.slice(0,100),r=e.length>100?e.slice(-100):"";return `${t}:${e.length}:${o}:${r}`},ka=e=>{let t=Co.get(e);if(t)return t;let o=createHighlighter({langs:[e],themes:["github-light","github-dark"]});return Co.set(e,o),o},ga=e=>({bg:"transparent",fg:"inherit",tokens:e.split(`
|
|
3
3
|
`).map(t=>t===""?[]:[{color:"inherit",content:t}])}),yo=(e,t,o)=>{let r=ma(e,t),a=Po.get(r);return a||(o&&(ue.has(r)||ue.set(r,new Set),ue.get(r)?.add(o)),ka(t).then(i=>{let p=i.getLoadedLanguages().includes(t)?t:"text",l=i.codeToTokens(e,{lang:p,themes:{dark:"github-dark",light:"github-light"}}),f={bg:l.bg??"transparent",fg:l.fg??"inherit",tokens:l.tokens};Po.set(r,f);let m=ue.get(r);if(m){for(let k of m)k(f);ue.delete(r);}}).catch(i=>{console.error("Failed to highlight code:",i),ue.delete(r);}),null)},Mo=memo(({tokenized:e,showLineNumbers:t,className:o})=>{let r=useMemo(()=>({backgroundColor:e.bg,color:e.fg}),[e.bg,e.fg]),a$1=useMemo(()=>fa(e.tokens),[e.tokens]);return jsx("pre",{className:a("fk:dark:bg-(--shiki-dark-bg)! fk:dark:text-(--shiki-dark)! fk:m-0 fk:p-4 fk:text-sm",o),style:r,children:jsx("code",{className:a("fk:font-mono fk:text-sm",t&&"fk:[counter-increment:line_0] fk:[counter-reset:line]"),children:a$1.map(i=>jsx(ua,{keyedLine:i,showLineNumbers:t},i.key))})})},(e,t)=>e.tokenized===t.tokenized&&e.showLineNumbers===t.showLineNumbers&&e.className===t.className);Mo.displayName="CodeBlockBody";var ba=({className:e,language:t,style:o,...r})=>jsx("div",{className:a("fk:group fk:relative fk:w-full fk:overflow-hidden fk:rounded-md fk:border fk:bg-background fk:text-foreground",e),"data-language":t,style:{containIntrinsicSize:"auto 200px",contentVisibility:"auto",...o},...r}),ap=({children:e,className:t,...o})=>jsx("div",{className:a("fk:flex fk:items-center fk:justify-between fk:border-b fk:bg-muted/80 fk:px-3 fk:py-2 fk:text-muted-foreground fk:text-xs",t),...o,children:e}),sp=({children:e,className:t,...o})=>jsx("div",{className:a("fk:flex fk:items-center fk:gap-2",t),...o,children:e}),ip=({children:e,className:t,...o})=>jsx("span",{className:a("fk:font-mono",t),...o,children:e}),pp=({children:e,className:t,...o})=>jsx("div",{className:a("fk:-my-1 fk:-mr-1 fk:flex fk:items-center fk:gap-2",t),...o,children:e}),ha=({code:e,language:t,showLineNumbers:o=false})=>{let r=useMemo(()=>ga(e),[e]),a=useMemo(()=>yo(e,t)??r,[e,t,r]),[i,s]=useState(null),p=useRef({code:e,language:t});return (p.current.code!==e||p.current.language!==t)&&(p.current={code:e,language:t},s(null)),useEffect(()=>{let f=false;return yo(e,t,m=>{f||s(m);}),()=>{f=true;}},[e,t]),jsx("div",{className:"fk:relative fk:overflow-auto",children:jsx(Mo,{showLineNumbers:o,tokenized:i??a})})},pt=({code:e,language:t,showLineNumbers:o=false,className:r,children:a,...i})=>{let s=useMemo(()=>({code:e}),[e]);return jsx(wo.Provider,{value:s,children:jsxs(ba,{className:r,language:t,...i,children:[a,jsx(ha,{code:e,language:t,showLineNumbers:o})]})})},lp=({onCopy:e,onError:t,timeout:o=2e3,children:r,className:a$1,...i})=>{let[s,p]=useState(false),l=useRef(0),{code:f}=useContext(wo),m=useCallback(async()=>{if(typeof window>"u"||!navigator?.clipboard?.writeText){t?.(new Error("Clipboard API not available"));return}try{s||(await navigator.clipboard.writeText(f),p(!0),e?.(),l.current=window.setTimeout(()=>p(!1),o));}catch(g){t?.(g);}},[f,e,t,o,s]);useEffect(()=>()=>{window.clearTimeout(l.current);},[]);let k=s?CheckIcon:CopyIcon;return jsx(b,{className:a("fk:shrink-0",a$1),onClick:m,size:"icon",variant:"ghost",...i,children:r??jsx(k,{size:14})})},fp=e=>jsx(a$4,{...e}),cp=({className:e,...t})=>jsx(d,{className:a("fk:h-7 fk:border-none fk:bg-transparent fk:px-2 fk:text-xs fk:shadow-none",e),size:"sm",...t}),dp=e=>jsx(c$1,{...e}),up=({align:e="end",...t})=>jsx(e$1,{align:e,...t}),mp=e=>jsx(g,{...e});var Pp=({className:e,...t})=>jsx(StickToBottom,{className:a("fk:relative fk:flex-1 fk:overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),yp=({className:e,...t})=>jsx(StickToBottom.Content,{className:a("fk:flex fk:flex-col fk:gap-8 fk:p-4",e),...t}),Sp=({className:e,title:t="No messages yet",description:o="Start a conversation to see messages here",icon:r,children:a$1,...i})=>jsx("div",{className:a("fk:flex fk:size-full fk:flex-col fk:items-center fk:justify-center fk:gap-3 fk:p-8 fk:text-center",e),...i,children:a$1??jsxs(Fragment,{children:[r&&jsx("div",{className:"fk:text-muted-foreground",children:r}),jsxs("div",{className:"fk:space-y-1",children:[jsx("h3",{className:"fk:font-medium fk:text-sm",children:t}),o&&jsx("p",{className:"fk:text-muted-foreground fk:text-sm",children:o})]})]})}),Tp=({className:e,...t})=>{let{isAtBottom:o,scrollToBottom:r}=useStickToBottomContext(),a$1=useCallback(()=>{r();},[r]);return !o&&jsx(b,{className:a("fk:absolute fk:bottom-4 fk:left-[50%] fk:translate-x-[-50%] fk:rounded-full fk:dark:bg-background fk:dark:hover:bg-muted",e),onClick:a$1,size:"icon",type:"button",variant:"outline",...t,children:jsx(ArrowDownIcon,{className:"fk:size-4"})})},ya=e=>e.parts.filter(t=>t.type==="text").map(t=>t.text).join(""),Lo=e=>`**${e.role.charAt(0).toUpperCase()+e.role.slice(1)}:** ${ya(e)}`,Sa=(e,t=Lo)=>e.map((o,r)=>t(o,r)).join(`
|
|
4
4
|
|
|
5
|
-
`),Ip=({messages:e,filename:t="conversation.md",formatMessage:o=Lo,className:r,children:a$1,...i})=>{let s=useCallback(()=>{let p=Sa(e,o),l=new Blob([p],{type:"text/markdown"}),f=URL.createObjectURL(l),m=document.createElement("a");m.href=f,m.download=t,document.body.append(m),m.click(),m.remove(),URL.revokeObjectURL(f);},[e,t,o]);return jsx(b,{className:a("fk:absolute fk:top-4 fk:right-4 fk:rounded-full fk:dark:bg-background fk:dark:hover:bg-muted",r),onClick:s,size:"icon",type:"button",variant:"outline",...i,children:a$1??jsx(DownloadIcon,{className:"fk:size-4"})})};var Up=({className:e,from:t,...o})=>jsx("div",{className:a("fk:group fk:flex fk:w-full fk:max-w-[95%] fk:flex-col fk:gap-2",t==="user"?"fk:is-user fk:ml-auto fk:justify-end":"fk:is-assistant",e),...o}),Fp=({children:e,className:t,...o})=>jsx("div",{className:a("fk:is-user:dark fk:flex fk:w-fit fk:min-w-0 fk:max-w-full fk:flex-col fk:gap-2 fk:overflow-hidden fk:text-sm","fk:group-[.is-user]:ml-auto fk:group-[.is-user]:rounded-lg fk:group-[.is-user]:bg-secondary fk:group-[.is-user]:px-4 fk:group-[.is-user]:py-3 fk:group-[.is-user]:text-foreground","fk:group-[.is-assistant]:text-foreground",t),...o,children:e}),_p=({className:e,children:t,...o})=>jsx("div",{className:a("fk:flex fk:items-center fk:gap-1",e),...o,children:t}),Vp=({tooltip:e$1,children:t,label:o,variant:r="ghost",size:a="icon-sm",...i})=>{let s=jsxs(b,{size:a,type:"button",variant:r,...i,children:[t,jsx("span",{className:"fk:sr-only",children:o||e$1})]});return e$1?jsx(a$1,{children:jsxs(b$1,{children:[jsx(c,{asChild:true,children:s}),jsx(e,{children:jsx("p",{children:e$1})})]})}):s},Eo=createContext(null),je=()=>{let e=useContext(Eo);if(!e)throw new Error("MessageBranch components must be used within MessageBranch");return e},jp=({defaultBranch:e=0,onBranchChange:t,className:o,...r})=>{let[a$1,i]=useState(e),[s,p]=useState([]),l=useCallback(g=>{i(g),t?.(g);},[t]),f=useCallback(()=>{let g=a$1>0?a$1-1:s.length-1;l(g);},[a$1,s.length,l]),m=useCallback(()=>{let g=a$1<s.length-1?a$1+1:0;l(g);},[a$1,s.length,l]),k=useMemo(()=>({branches:s,currentBranch:a$1,goToNext:m,goToPrevious:f,setBranches:p,totalBranches:s.length}),[s,a$1,m,f]);return jsx(Eo.Provider,{value:k,children:jsx("div",{className:a("fk:grid fk:w-full fk:gap-2 fk:[&>div]:pb-0",o),...r})})},Wp=({children:e,...t})=>{let{currentBranch:o,setBranches:r,branches:a$1}=je(),i=useMemo(()=>Array.isArray(e)?e:[e],[e]);return useEffect(()=>{a$1.length!==i.length&&r(i);},[i,a$1,r]),i.map((s,p)=>jsx("div",{className:a("fk:grid fk:gap-2 fk:overflow-hidden fk:[&>div]:pb-0",p===o?"fk:block":"fk:hidden"),...t,children:s},s.key))},$p=({className:e,...t})=>{let{totalBranches:o}=je();return o<=1?null:jsx(b$2,{className:a("fk:[&>*:not(:first-child)]:rounded-l-md fk:[&>*:not(:last-child)]:rounded-r-md",e),orientation:"horizontal",...t})},Kp=({children:e,...t})=>{let{goToPrevious:o,totalBranches:r}=je();return jsx(b,{"aria-label":"Previous branch",disabled:r<=1,onClick:o,size:"icon-sm",type:"button",variant:"ghost",...t,children:e??jsx(ChevronLeftIcon,{size:14})})},qp=({children:e,...t})=>{let{goToNext:o,totalBranches:r}=je();return jsx(b,{"aria-label":"Next branch",disabled:r<=1,onClick:o,size:"icon-sm",type:"button",variant:"ghost",...t,children:e??jsx(ChevronRightIcon,{size:14})})},Xp=({className:e,...t})=>{let{currentBranch:o,totalBranches:r}=je();return jsxs(c$2,{className:a("fk:border-none fk:bg-transparent fk:text-muted-foreground fk:shadow-none",e),...t,children:[o+1," of ",r]})},Ha={cjk:cjk,code:code,math:math,mermaid:mermaid},Ga=memo(({className:e,...t})=>jsx(Streamdown,{className:a("fk:size-full fk:[&>*:first-child]:mt-0 fk:[&>*:last-child]:mb-0",e),plugins:Ha,prefix:"fk",...t}),(e,t)=>e.children===t.children&&t.isAnimating===e.isAnimating);Ga.displayName="MessageResponse";var Jp=({className:e,children:t,...o})=>jsx("div",{className:a("fk:mt-4 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-4",e),...o,children:t});var ol=e=>jsx(d$1,{...e}),rl=e=>jsx(e$2,{...e}),nl=({className:e,children:t,title:o="Model Selector",...r})=>jsxs(i,{"aria-describedby":void 0,className:a("fk:outline! fk:border-none! fk:p-0 fk:outline-border! fk:outline-solid!",e),...r,children:[jsx(l$1,{className:"fk:sr-only",children:o}),jsx(n$1,{className:"fk:**:data-[slot=command-input-wrapper]:h-auto",children:t})]}),al=e=>jsx(o,{...e}),sl=({className:e,...t})=>jsx(p,{className:a("fk:h-auto fk:py-3.5",e),...t}),il=e=>jsx(q,{...e}),pl=e=>jsx(r,{...e}),ll=e=>jsx(s,{...e}),fl=e=>jsx(u,{...e}),cl=e=>jsx(v,{...e}),dl=e=>jsx(t,{...e}),ul=({provider:e,className:t,...o})=>jsx("img",{...o,alt:`${e} logo`,className:a("fk:size-3 fk:dark:invert",t),height:12,src:`https://models.dev/logos/${e}.svg`,width:12}),ml=({className:e,...t})=>jsx("div",{className:a("fk:flex fk:shrink-0 fk:items-center fk:-space-x-1 fk:[&>img]:rounded-full fk:[&>img]:bg-background fk:[&>img]:p-px fk:[&>img]:ring-1 fk:dark:[&>img]:bg-foreground",e),...t}),kl=({className:e,...t})=>jsx("span",{className:a("fk:flex-1 fk:truncate fk:text-left",e),...t});var Ka=async e=>{try{let o=await(await fetch(e)).blob();return new Promise(r=>{let a=new FileReader;a.onloadend=()=>r(a.result),a.onerror=()=>r(null),a.readAsDataURL(o);})}catch{return null}},qa=async()=>{if(typeof navigator>"u"||!navigator.mediaDevices?.getDisplayMedia)return null;let e=null,t=document.createElement("video");t.muted=true,t.playsInline=true;try{e=await navigator.mediaDevices.getDisplayMedia({audio:!1,video:!0}),t.srcObject=e,await new Promise((l,f)=>{t.onloadedmetadata=()=>l(),t.onerror=()=>f(new Error("Failed to load screen stream"));}),await t.play();let o=t.videoWidth,r=t.videoHeight;if(!o||!r)return null;let a=document.createElement("canvas");a.width=o,a.height=r;let i=a.getContext("2d");if(!i)return null;i.drawImage(t,0,0,o,r);let s=await new Promise(l=>{a.toBlob(l,"image/png");});if(!s)return null;let p=new Date().toISOString().replaceAll(/[:.]/g,"-").replace("T","_").replace("Z","");return new File([s],`screenshot-${p}.png`,{lastModified:Date.now(),type:"image/png"})}finally{if(e)for(let o of e.getTracks())o.stop();t.pause(),t.srcObject=null;}},$t=createContext(null),Kt=createContext(null),Nl=()=>{let e=useContext($t);if(!e)throw new Error("Wrap your component inside <PromptInputProvider> to use usePromptInputController().");return e},zo=()=>useContext($t),Rl=()=>{let e=useContext(Kt);if(!e)throw new Error("Wrap your component inside <PromptInputProvider> to use useProviderAttachments().");return e},Xa=()=>useContext(Kt),Bl=({initialInput:e="",children:t})=>{let[o,r]=useState(e),a=useCallback(()=>r(""),[]),[i,s]=useState([]),p=useRef(null),l=useRef(()=>{}),f=useCallback(c=>{let x=Array.from(c);x.length!==0&&s(z=>[...z,...x.map(R=>({filename:R.name,id:nanoid(),mediaType:R.type,type:"file",url:URL.createObjectURL(R)}))]);},[]),m=useCallback(c=>{s(x=>{let z=x.find(R=>R.id===c);return z?.url&&URL.revokeObjectURL(z.url),x.filter(R=>R.id!==c)});},[]),k=useCallback(()=>{s(c=>{for(let x of c)x.url&&URL.revokeObjectURL(x.url);return []});},[]),g=useRef(i);useEffect(()=>{g.current=i;},[i]),useEffect(()=>()=>{for(let c of g.current)c.url&&URL.revokeObjectURL(c.url);},[]);let T=useCallback(()=>{l.current?.();},[]),b=useMemo(()=>({add:f,clear:k,fileInputRef:p,files:i,openFileDialog:T,remove:m}),[i,f,m,k,T]),C=useCallback((c,x)=>{p.current=c.current,l.current=x;},[]),N=useMemo(()=>({__registerFileInput:C,attachments:b,textInput:{clear:a,setInput:r,value:o}}),[o,a,b,C]);return jsx($t.Provider,{value:N,children:jsx(Kt.Provider,{value:b,children:t})})},Ho=createContext(null),qt=()=>{let e=Xa(),o=useContext(Ho)??e;if(!o)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return o},Go=createContext(null),Ll=()=>{let e=useContext(Go);if(!e)throw new Error("usePromptInputReferencedSources must be used within a LocalReferencedSourcesContext.Provider");return e},Al=({label:e="Add photos or files",...t})=>{let o=qt(),r=useCallback(a=>{a.preventDefault(),o.openFileDialog();},[o]);return jsxs(h,{...t,onSelect:r,children:[jsx(ImageIcon,{className:"fk:mr-2 fk:size-4"})," ",e]})},Dl=({label:e="Take screenshot",onSelect:t,...o})=>{let r=qt(),a=useCallback(async i=>{if(t?.(i),!i.defaultPrevented)try{let s=await qa();s&&r.add([s]);}catch(s){if(s instanceof DOMException&&(s.name==="NotAllowedError"||s.name==="AbortError"))return;throw s}},[t,r]);return jsxs(h,{...o,onSelect:a,children:[jsx(Monitor,{className:"fk:mr-2 fk:size-4"}),e]})},El=({className:e,accept:t,multiple:o,globalDrop:r,syncHiddenInput:a$1,maxFiles:i,maxFileSize:s,onError:p,onSubmit:l,children:f,...m})=>{let k=zo(),g=!!k,T=useRef(null),b=useRef(null),[C,N]=useState([]),c=g?k.attachments.files:C,[x,z]=useState([]),R=useRef(c);useEffect(()=>{R.current=c;},[c]);let he=useCallback(()=>{T.current?.click();},[]),_=useCallback(u=>!t||t.trim()===""?true:t.split(",").map(h=>h.trim()).filter(Boolean).some(h=>{if(h.endsWith("/*")){let y=h.slice(0,-1);return u.type.startsWith(y)}return u.type===h}),[t]),Ke=useCallback(u=>{let v=Array.from(u),h=v.filter(X=>_(X));if(v.length&&h.length===0){p?.({code:"accept",message:"No files match the accepted types."});return}let y=X=>s?X.size<=s:true,O=h.filter(y);if(h.length>0&&O.length===0){p?.({code:"max_file_size",message:"All files exceed the maximum size."});return}N(X=>{let D=typeof i=="number"?Math.max(0,i-X.length):void 0,se=typeof D=="number"?O.slice(0,D):O;typeof D=="number"&&O.length>D&&p?.({code:"max_files",message:"Too many files. Some were not added."});let ie=[];for(let ct of se)ie.push({filename:ct.name,id:nanoid(),mediaType:ct.type,type:"file",url:URL.createObjectURL(ct)});return [...X,...ie]});},[_,i,s,p]),te=useCallback(u=>N(v=>{let h=v.find(y=>y.id===u);return h?.url&&URL.revokeObjectURL(h.url),v.filter(y=>y.id!==u)}),[]),W=useCallback(u=>{let v=Array.from(u),h=v.filter(ie=>_(ie));if(v.length&&h.length===0){p?.({code:"accept",message:"No files match the accepted types."});return}let y=ie=>s?ie.size<=s:true,O=h.filter(y);if(h.length>0&&O.length===0){p?.({code:"max_file_size",message:"All files exceed the maximum size."});return}let X=c.length,D=typeof i=="number"?Math.max(0,i-X):void 0,se=typeof D=="number"?O.slice(0,D):O;typeof D=="number"&&O.length>D&&p?.({code:"max_files",message:"Too many files. Some were not added."}),se.length>0&&k?.attachments.add(se);},[_,s,i,p,c.length,k]),$=useCallback(()=>g?k?.attachments.clear():N(u=>{for(let v of u)v.url&&URL.revokeObjectURL(v.url);return []}),[g,k]),K=useCallback(()=>z([]),[]),G=g?W:Ke,xe=g?k.attachments.remove:te,qe=g?k.attachments.openFileDialog:he,ve=useCallback(()=>{$(),K();},[$,K]);useEffect(()=>{g&&k.__registerFileInput(T,()=>T.current?.click());},[g,k]),useEffect(()=>{a$1&&T.current&&c.length===0&&(T.current.value="");},[c,a$1]),useEffect(()=>{let u=b.current;if(!u||r)return;let v=y=>{y.dataTransfer?.types?.includes("Files")&&y.preventDefault();},h=y=>{y.dataTransfer?.types?.includes("Files")&&y.preventDefault(),y.dataTransfer?.files&&y.dataTransfer.files.length>0&&G(y.dataTransfer.files);};return u.addEventListener("dragover",v),u.addEventListener("drop",h),()=>{u.removeEventListener("dragover",v),u.removeEventListener("drop",h);}},[G,r]),useEffect(()=>{if(!r)return;let u=h=>{h.dataTransfer?.types?.includes("Files")&&h.preventDefault();},v=h=>{h.dataTransfer?.types?.includes("Files")&&h.preventDefault(),h.dataTransfer?.files&&h.dataTransfer.files.length>0&&G(h.dataTransfer.files);};return document.addEventListener("dragover",u),document.addEventListener("drop",v),()=>{document.removeEventListener("dragover",u),document.removeEventListener("drop",v);}},[G,r]),useEffect(()=>()=>{if(!g)for(let u of R.current)u.url&&URL.revokeObjectURL(u.url);},[g]);let Xe=useCallback(u=>{u.currentTarget.files&&G(u.currentTarget.files),u.currentTarget.value="";},[G]),A=useMemo(()=>({add:G,clear:$,fileInputRef:T,files:c.map(u=>({...u,id:u.id})),openFileDialog:qe,remove:xe}),[c,G,xe,$,qe]),Je=useMemo(()=>({add:u=>{let v=Array.isArray(u)?u:[u];z(h=>[...h,...v.map(y=>({...y,id:nanoid()}))]);},clear:K,remove:u=>{z(v=>v.filter(h=>h.id!==u));},sources:x}),[x,K]),oe=useCallback(async u=>{u.preventDefault();let v=u.currentTarget,h=g?k.textInput.value:new FormData(v).get("message")||"";g||v.reset();try{let y=await Promise.all(c.map(async({id:X,...D})=>{if(D.url?.startsWith("blob:")){let se=await Ka(D.url);return {...D,url:se??D.url}}return D})),O=l({files:y,text:h},u);if(O instanceof Promise)try{await O,ve(),g&&k.textInput.clear();}catch{}else ve(),g&&k.textInput.clear();}catch{}},[g,k,c,l,ve]),q=jsxs(Fragment,{children:[jsx("input",{accept:t,"aria-label":"Upload files",className:"fk:hidden",multiple:o,onChange:Xe,ref:T,title:"Upload files",type:"file"}),jsx("form",{className:a("fk:w-full",e),onSubmit:oe,ref:b,...m,children:jsx(Ut,{className:"fk:overflow-hidden",children:f})})]}),Ce=jsx(Go.Provider,{value:Je,children:q});return jsx(Ho.Provider,{value:A,children:Ce})},zl=({className:e,...t})=>jsx("div",{className:a("fk:contents",e),...t}),Hl=({onChange:e,onKeyDown:t,className:o,placeholder:r="What would you like to know?",...a$1})=>{let i=zo(),s=qt(),[p,l]=useState(false),f=useCallback(b=>{if(t?.(b),!b.defaultPrevented){if(b.key==="Enter"){if(p||b.nativeEvent.isComposing||b.shiftKey)return;b.preventDefault();let{form:C}=b.currentTarget;if(C?.querySelector('button[type="submit"]')?.disabled)return;C?.requestSubmit();}if(b.key==="Backspace"&&b.currentTarget.value===""&&s.files.length>0){b.preventDefault();let C=s.files[s.files.length-1];C&&s.remove(C.id);}}},[t,p,s]),m=useCallback(b=>{let C=b.clipboardData?.items;if(!C)return;let N=[];for(let c of Array.from(C))if(c.kind==="file"){let x=c.getAsFile();x&&N.push(x);}N.length>0&&(b.preventDefault(),s.add(N));},[s]),k=useCallback(()=>l(false),[]),g=useCallback(()=>l(true),[]),T=i?{onChange:b=>{i.textInput.setInput(b.currentTarget.value),e?.(b);},value:i.textInput.value}:{onChange:e};return jsx(Ft,{className:a("fk:field-sizing-content fk:max-h-48 fk:min-h-16",o),name:"message",onCompositionEnd:k,onCompositionStart:g,onKeyDown:f,onPaste:m,placeholder:r,...a$1,...T})},Gl=({className:e,...t})=>jsx(st,{align:"block-end",className:a("fk:order-first fk:flex-wrap fk:gap-1",e),...t}),Ol=({className:e,...t})=>jsx(st,{align:"block-end",className:a("fk:justify-between fk:gap-1",e),...t}),Ul=({className:e,...t})=>jsx("div",{className:a("fk:flex fk:min-w-0 fk:items-center fk:gap-1",e),...t}),Ja=({variant:e$1="ghost",className:t,size:o,tooltip:r,...a$1})=>{let i=o??(Children.count(a$1.children)>1?"sm":"icon-sm"),s=jsx(it,{className:a(t),size:i,type:"button",variant:e$1,...a$1});if(!r)return s;let p=typeof r=="string"?r:r.content,l=typeof r=="string"?void 0:r.shortcut,f=typeof r=="string"?"top":r.side??"top";return jsxs(b$1,{children:[jsx(c,{asChild:true,children:s}),jsxs(e,{side:f,children:[p,l&&jsx("span",{className:"fk:ml-2 fk:text-muted-foreground",children:l})]})]})},Fl=e=>jsx(c$3,{...e}),_l=({className:e,children:t,...o})=>jsx(e$3,{asChild:true,children:jsx(Ja,{className:e,...o,children:t??jsx(PlusIcon,{className:"fk:size-4"})})}),Vl=({className:e,...t})=>jsx(f,{align:"start",className:a(e),...t}),jl=({className:e,...t})=>jsx(h,{className:a(e),...t}),Wl=({className:e,variant:t="default",size:o="icon-sm",status:r,onStop:a$1,onClick:i,children:s,...p})=>{let l=r==="submitted"||r==="streaming",f=jsx(CornerDownLeftIcon,{className:"fk:size-4"});r==="submitted"?f=jsx(Ot,{}):r==="streaming"?f=jsx(SquareIcon,{className:"fk:size-4"}):r==="error"&&(f=jsx(XIcon,{className:"fk:size-4"}));let m=useCallback(k=>{if(l&&a$1){k.preventDefault(),a$1();return}i?.(k);},[l,a$1,i]);return jsx(it,{"aria-label":l?"Stop":"Submit",className:a(e),onClick:m,size:o,type:l&&a$1?"button":"submit",variant:t,...p,children:s??f})},$l=e=>jsx(a$4,{...e}),Kl=({className:e,...t})=>jsx(d,{className:a("fk:border-none fk:bg-transparent fk:font-medium fk:text-muted-foreground fk:shadow-none fk:transition-colors","fk:hover:bg-accent fk:hover:text-foreground fk:aria-expanded:bg-accent fk:aria-expanded:text-foreground",e),...t}),ql=({className:e,...t})=>jsx(e$1,{className:a(e),...t}),Xl=({className:e,...t})=>jsx(g,{className:a(e),...t}),Jl=({className:e,...t})=>jsx(c$1,{className:a(e),...t}),Yl=({openDelay:e=0,closeDelay:t=0,...o})=>jsx(Ue,{closeDelay:t,openDelay:e,...o}),Zl=e=>jsx(Fe,{...e}),Ql=({align:e="start",...t})=>jsx(_e,{align:e,...t}),ef=({className:e,...t})=>jsx("div",{className:a(e),...t}),tf=({className:e,...t})=>jsx("div",{className:a(e),...t}),of=({className:e,...t})=>jsx("h3",{className:a("fk:mb-2 fk:px-3 fk:font-medium fk:text-muted-foreground fk:text-xs",e),...t}),rf=({className:e,...t})=>jsx("div",{className:a("fk:space-y-1",e),...t}),nf=({className:e,...t})=>jsx("div",{className:a("fk:flex fk:items-center fk:gap-2 fk:px-3 fk:py-2 fk:text-xs fk:hover:bg-accent",e),...t}),af=({className:e,...t})=>jsx(n$1,{className:a(e),...t}),sf=({className:e,...t})=>jsx(p,{className:a(e),...t}),pf=({className:e,...t})=>jsx(q,{className:a(e),...t}),lf=({className:e,...t})=>jsx(r,{className:a(e),...t}),ff=({className:e,...t})=>jsx(s,{className:a(e),...t}),cf=({className:e,...t})=>jsx(u,{className:a(e),...t}),df=({className:e,...t$1})=>jsx(t,{className:a(e),...t$1});var Oo=new Map,ts=e=>{let t=Oo.get(e);return t||(t=motion.create(e),Oo.set(e,t)),t},os=({children:e,as:t="p",className:o,duration:r=2,spread:a$1=2})=>{let i=ts(t),s=useMemo(()=>(e?.length??0)*a$1,[e,a$1]);return jsx(i,{animate:{backgroundPosition:"0% center"},className:a("fk:relative fk:inline-block fk:bg-[length:250%_100%,auto] fk:bg-clip-text fk:text-transparent","fk:[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] fk:[background-repeat:no-repeat,padding-box]",o),initial:{backgroundPosition:"100% center"},style:{"--spread":`${s}px`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},transition:{duration:r,ease:"linear",repeat:Number.POSITIVE_INFINITY},children:e})},Xt=memo(os);var _o=createContext(null),gs=()=>{let e=useContext(_o);if(!e)throw new Error("Reasoning components must be used within Reasoning");return e},bs=1e3,hs=1e3,xs=memo(({className:e,isStreaming:t=false,open:o,defaultOpen:r,onOpenChange:a$1,duration:i,children:s,...p})=>{let l$1=r??t,f=r===false,[m,k]=useControllableState({defaultProp:l$1,onChange:a$1,prop:o}),[g,T]=useControllableState({defaultProp:void 0,prop:i}),b=useRef(t),[C,N]=useState(false),c=useRef(null);useEffect(()=>{t?(b.current=true,c.current===null&&(c.current=Date.now())):c.current!==null&&(T(Math.ceil((Date.now()-c.current)/hs)),c.current=null);},[t,T]),useEffect(()=>{t&&!m&&!f&&k(true);},[t,m,k,f]),useEffect(()=>{if(b.current&&!t&&m&&!C){let R=setTimeout(()=>{k(false),N(true);},bs);return ()=>clearTimeout(R)}},[t,m,k,C]);let x=useCallback(R=>{k(R);},[k]),z=useMemo(()=>({duration:g,isOpen:m,isStreaming:t,setIsOpen:k}),[g,m,t,k]);return jsx(_o.Provider,{value:z,children:jsx(l,{className:a("fk:not-prose fk:mb-4",e),onOpenChange:x,open:m,...p,children:s})})}),vs=(e,t)=>e||t===0?jsx(Xt,{duration:1,children:"Thinking..."}):t===void 0?jsx("p",{children:"Thought for a few seconds"}):jsxs("p",{children:["Thought for ",t," seconds"]}),Cs=memo(({className:e,children:t,getThinkingMessage:o=vs,...r})=>{let{isStreaming:a$1,isOpen:i,duration:s}=gs();return jsx(m,{className:a("fk:flex fk:w-full fk:items-center fk:gap-2 fk:text-muted-foreground fk:text-sm fk:transition-colors fk:hover:text-foreground",e),...r,children:t??jsxs(Fragment,{children:[jsx(BrainIcon,{className:"fk:size-4"}),o(a$1,s),jsx(ChevronDownIcon,{className:a("fk:size-4 fk:transition-transform",i?"fk:rotate-180":"fk:rotate-0")})]})})}),Ps={cjk:cjk,code:code,math:math,mermaid:mermaid},ys=memo(({className:e,children:t,...o})=>jsx(n,{className:a("fk:mt-4 fk:text-sm","fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:slide-out-to-top-2 fk:data-[state=open]:slide-in-from-top-2 fk:text-muted-foreground fk:outline-none fk:data-[state=closed]:animate-out fk:data-[state=open]:animate-in",e),...o,children:jsx(Streamdown,{plugins:Ps,children:t})}));xs.displayName="Reasoning";Cs.displayName="ReasoningTrigger";ys.displayName="ReasoningContent";var zf=({className:e,...t})=>jsx(l,{className:a("fk:not-prose fk:mb-4 fk:text-primary fk:text-xs",e),...t}),Hf=({className:e,count:t,children:o,...r})=>jsx(m,{className:a("fk:flex fk:items-center fk:gap-2",e),...r,children:o??jsxs(Fragment,{children:[jsxs("p",{className:"fk:font-medium",children:["Used ",t," sources"]}),jsx(ChevronDownIcon,{className:"fk:h-4 fk:w-4"})]})}),Gf=({className:e,...t})=>jsx(n,{className:a("fk:mt-3 fk:flex fk:w-fit fk:flex-col fk:gap-2","fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:slide-out-to-top-2 fk:data-[state=open]:slide-in-from-top-2 fk:outline-none fk:data-[state=closed]:animate-out fk:data-[state=open]:animate-in",e),...t}),Of=({href:e,title:t,children:o,...r})=>jsx("a",{className:"fk:flex fk:items-center fk:gap-2",href:e,rel:"noreferrer",target:"_blank",...r,children:o??jsxs(Fragment,{children:[jsx(BookIcon,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:block fk:font-medium",children:t})]})});var Rs=6e4;function Bs(){return typeof window<"u"&&"MediaRecorder"in window&&typeof navigator<"u"&&"mediaDevices"in navigator&&typeof navigator.mediaDevices.getUserMedia=="function"}function Ls(){return ["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(t=>MediaRecorder.isTypeSupported(t))}function Wo(e,t){return e instanceof DOMException&&(e.name==="NotAllowedError"||e.name==="PermissionDeniedError")?new Error("Microphone permission was denied. Enable the microphone to dictate."):e instanceof DOMException&&e.name==="NotFoundError"?new Error("No microphone was found."):e instanceof Error?e:new Error(t)}function As(e){return e instanceof Error&&e.name==="AbortError"}function Ds(e,t,o){return e?o?"Cancel transcription":t?"Stop recording":"Dictate":"Dictation is not available in this browser."}var Kf=({className:e$1,disabled:t,onAudioRecorded:o,onError:r,onTranscriptionChange:a$1,size:i="icon-sm",variant:s="ghost",...p})=>{let[l,f]=useState(false),[m,k]=useState(false),[g,T]=useState(false),b$2=useRef(null),C=useRef(null),N=useRef([]),c$1=useRef(null),x=useRef(null),z=useRef(false),R=useRef(!!t),he=useRef(o),_=useRef(r),Ke=useRef(a$1);R.current=!!t,he.current=o,_.current=r,Ke.current=a$1,useEffect(()=>{T(Bs());},[]);let te=useCallback(()=>{if(C.current){for(let A of C.current.getTracks())A.stop();C.current=null;}},[]),W=useCallback(()=>{c$1.current!==null&&(window.clearTimeout(c$1.current),c$1.current=null);},[]),$=useCallback(()=>{W(),b$2.current?.state==="recording"&&b$2.current.stop(),f(false);},[W]),K=useCallback(()=>{x.current?.abort(),x.current=null,k(false);},[]),G=useCallback(()=>{K(),W();let A=b$2.current;A?.state==="recording"&&(z.current=true,A.stop()),f(false),te();},[K,W,te]),xe=useCallback(async()=>{if(!R.current){if(!he.current){_.current?.(new Error("Dictation is not configured."));return}try{let A=await navigator.mediaDevices.getUserMedia({audio:!0});if(R.current){for(let q of A.getTracks())q.stop();return}C.current=A;let Je=Ls(),oe=Je?new MediaRecorder(A,{mimeType:Je}):new MediaRecorder(A);N.current=[],oe.ondataavailable=q=>{q.data.size>0&&N.current.push(q.data);},oe.onstop=async()=>{if(te(),W(),f(!1),z.current){z.current=!1,N.current=[];return}let q=new Blob(N.current,{type:oe.mimeType||"audio/webm"});if(q.size===0)return;let Ce=new AbortController;x.current=Ce,k(!0);try{let u=he.current;if(!u)return;let v=await u(q,Ce.signal);v&&Ke.current?.(v);}catch(u){if(As(u))return;_.current?.(Wo(u,"Transcription failed."));}finally{x.current===Ce&&(x.current=null,k(!1));}},oe.onerror=()=>{f(!1),te(),W(),_.current?.(new Error("Recording failed. Try again."));},b$2.current=oe,oe.start(250),f(!0),c$1.current=window.setTimeout(()=>{$();},Rs);}catch(A){f(false),te(),_.current?.(Wo(A,"Could not start the microphone."));}}},[W,te,$]);useEffect(()=>{t&&G();},[G,t]),useEffect(()=>()=>{G();},[G]);let qe=useCallback(()=>{if(m){K();return}if(l){$();return}xe();},[K,l,m,xe,$]),ve=t||!g||!o,Xe=Ds(g&&!!o,l,m);return jsxs(b$1,{children:[jsx(c,{asChild:true,children:jsxs("span",{className:"fk:relative fk:inline-flex fk:items-center fk:justify-center",children:[l?[0,1,2].map(A=>jsx("span",{className:"fk:absolute fk:inset-0 fk:animate-ping fk:rounded-full fk:border-2 fk:border-red-400/30",style:{animationDelay:`${String(A*.3)}s`,animationDuration:"2s"}},A)):null,jsxs(b,{"aria-label":Xe,"aria-pressed":l,size:i,variant:l?"destructive":s,...p,className:a("fk:relative fk:z-10 fk:rounded-full fk:dark:hover:bg-accent",e$1),disabled:ve,onClick:qe,type:"button",children:[m?jsx(LoaderIcon,{className:"fk:size-4 fk:animate-spin"}):null,!m&&l?jsx(SquareIcon,{className:"fk:size-4"}):null,m||l?null:jsx(MicIcon,{className:"fk:size-5"})]})]})}),jsx(e,{children:Xe})]})};var ec=({className:e,children:t,...o})=>jsxs(w,{className:"fk:w-full fk:overflow-x-auto fk:whitespace-nowrap",...o,children:[jsx("div",{className:a("fk:flex fk:w-max fk:flex-nowrap fk:items-center fk:gap-2",e),children:t}),jsx(x,{className:"fk:hidden",orientation:"horizontal"})]}),tc=({suggestion:e,onClick:t,className:o,variant:r="outline",size:a$1="sm",children:i,...s})=>{let p=useCallback(()=>{t?.(e);},[t,e]);return jsx(b,{className:a("fk:cursor-pointer fk:rounded-full fk:px-4",o),onClick:p,size:a$1,type:"button",variant:r,...s,children:i||e})};var fc=({className:e,...t})=>jsx(l,{className:a("fk:group fk:not-prose fk:mb-4 fk:w-full fk:rounded-md fk:border",e),...t}),Fs={"approval-requested":"Awaiting Approval","approval-responded":"Responded","input-available":"Running","input-streaming":"Pending","output-available":"Completed","output-denied":"Denied","output-error":"Error"},_s={"approval-requested":jsx(ClockIcon,{className:"fk:size-4 fk:text-yellow-600"}),"approval-responded":jsx(CheckCircleIcon,{className:"fk:size-4 fk:text-blue-600"}),"input-available":jsx(ClockIcon,{className:"fk:size-4 fk:animate-pulse"}),"input-streaming":jsx(CircleIcon,{className:"fk:size-4"}),"output-available":jsx(CheckCircleIcon,{className:"fk:size-4 fk:text-green-600"}),"output-denied":jsx(XCircleIcon,{className:"fk:size-4 fk:text-orange-600"}),"output-error":jsx(XCircleIcon,{className:"fk:size-4 fk:text-red-600"})},Vs=e=>jsxs(b$3,{className:"fk:gap-1.5 fk:py-px fk:rounded-full fk:text-xs",variant:"secondary",children:[_s[e],Fs[e]]}),cc=({className:e,title:t,type:o,state:r,toolName:a$1,...i})=>{let s=o==="dynamic-tool"?a$1:o.split("-").slice(1).join("-");return jsxs(m,{className:a("fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-4 fk:px-3 fk:py-2",e),...i,children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(WrenchIcon,{className:"fk:size-4 fk:text-muted-foreground"}),jsx("span",{className:"fk:font-medium fk:text-sm",children:t??s}),Vs(r)]}),jsx(ChevronDownIcon,{className:"fk:size-4 fk:text-muted-foreground fk:transition-transform fk:group-data-[state=open]:rotate-180"})]})},dc=({className:e,...t})=>jsx(n,{className:a("fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:slide-out-to-top-2 fk:data-[state=open]:slide-in-from-top-2 fk:space-y-4 fk:p-4 fk:text-popover-foreground fk:outline-none fk:data-[state=closed]:animate-out fk:data-[state=open]:animate-in",e),...t}),uc=({className:e,input:t,...o})=>jsxs("div",{className:a("fk:space-y-2 fk:overflow-hidden",e),...o,children:[jsx("h4",{className:"fk:font-medium fk:text-muted-foreground fk:text-xs fk:uppercase fk:tracking-wide",children:"Parameters"}),jsx("div",{className:"fk:rounded-md fk:bg-muted/50",children:jsx(pt,{code:JSON.stringify(t,null,2),language:"json"})})]}),mc=({className:e,output:t,errorText:o,...r})=>{if(!(t||o))return null;let a$1=jsx("div",{children:t});return typeof t=="object"&&!isValidElement(t)?a$1=jsx(pt,{code:JSON.stringify(t,null,2),language:"json"}):typeof t=="string"&&(a$1=jsx(pt,{code:t,language:"json"})),jsxs("div",{className:a("fk:space-y-2",e),...r,children:[jsx("h4",{className:"fk:font-medium fk:text-muted-foreground fk:text-xs fk:uppercase fk:tracking-wide",children:o?"Error":"Result"}),jsxs("div",{className:a("fk:overflow-x-auto fk:rounded-md fk:text-xs fk:[&_table]:w-full",o?"fk:bg-destructive/10 fk:text-destructive":"fk:bg-muted/50 fk:text-foreground"),children:[o&&jsx("div",{children:o}),a$1]})]})};
|
|
5
|
+
`),Ip=({messages:e,filename:t="conversation.md",formatMessage:o=Lo,className:r,children:a$1,...i})=>{let s=useCallback(()=>{let p=Sa(e,o),l=new Blob([p],{type:"text/markdown"}),f=URL.createObjectURL(l),m=document.createElement("a");m.href=f,m.download=t,document.body.append(m),m.click(),m.remove(),URL.revokeObjectURL(f);},[e,t,o]);return jsx(b,{className:a("fk:absolute fk:top-4 fk:right-4 fk:rounded-full fk:dark:bg-background fk:dark:hover:bg-muted",r),onClick:s,size:"icon",type:"button",variant:"outline",...i,children:a$1??jsx(DownloadIcon,{className:"fk:size-4"})})};var Up=({className:e,from:t,...o})=>jsx("div",{className:a("fk:group fk:flex fk:w-full fk:max-w-[95%] fk:flex-col fk:gap-2",t==="user"?"fk:is-user fk:ml-auto fk:justify-end":"fk:is-assistant",e),...o}),Fp=({children:e,className:t,...o})=>jsx("div",{className:a("fk:is-user:dark fk:flex fk:w-fit fk:min-w-0 fk:max-w-full fk:flex-col fk:gap-2 fk:overflow-hidden fk:text-sm","fk:group-[.is-user]:ml-auto fk:group-[.is-user]:rounded-lg fk:group-[.is-user]:bg-secondary fk:group-[.is-user]:px-4 fk:group-[.is-user]:py-3 fk:group-[.is-user]:text-foreground","fk:group-[.is-assistant]:text-foreground",t),...o,children:e}),_p=({className:e,children:t,...o})=>jsx("div",{className:a("fk:flex fk:items-center fk:gap-1",e),...o,children:t}),Vp=({tooltip:e$1,children:t,label:o,variant:r="ghost",size:a="icon-sm",...i})=>{let s=jsxs(b,{size:a,type:"button",variant:r,...i,children:[t,jsx("span",{className:"fk:sr-only",children:o||e$1})]});return e$1?jsx(a$1,{children:jsxs(b$1,{children:[jsx(c,{asChild:true,children:s}),jsx(e,{children:jsx("p",{children:e$1})})]})}):s},Eo=createContext(null),je=()=>{let e=useContext(Eo);if(!e)throw new Error("MessageBranch components must be used within MessageBranch");return e},jp=({defaultBranch:e=0,onBranchChange:t,className:o,...r})=>{let[a$1,i]=useState(e),[s,p]=useState([]),l=useCallback(g=>{i(g),t?.(g);},[t]),f=useCallback(()=>{let g=a$1>0?a$1-1:s.length-1;l(g);},[a$1,s.length,l]),m=useCallback(()=>{let g=a$1<s.length-1?a$1+1:0;l(g);},[a$1,s.length,l]),k=useMemo(()=>({branches:s,currentBranch:a$1,goToNext:m,goToPrevious:f,setBranches:p,totalBranches:s.length}),[s,a$1,m,f]);return jsx(Eo.Provider,{value:k,children:jsx("div",{className:a("fk:grid fk:w-full fk:gap-2 fk:[&>div]:pb-0",o),...r})})},Wp=({children:e,...t})=>{let{currentBranch:o,setBranches:r,branches:a$1}=je(),i=useMemo(()=>Array.isArray(e)?e:[e],[e]);return useEffect(()=>{a$1.length!==i.length&&r(i);},[i,a$1,r]),i.map((s,p)=>jsx("div",{className:a("fk:grid fk:gap-2 fk:overflow-hidden fk:[&>div]:pb-0",p===o?"fk:block":"fk:hidden"),...t,children:s},s.key))},$p=({className:e,...t})=>{let{totalBranches:o}=je();return o<=1?null:jsx(b$2,{className:a("fk:[&>*:not(:first-child)]:rounded-l-md fk:[&>*:not(:last-child)]:rounded-r-md",e),orientation:"horizontal",...t})},Kp=({children:e,...t})=>{let{goToPrevious:o,totalBranches:r}=je();return jsx(b,{"aria-label":"Previous branch",disabled:r<=1,onClick:o,size:"icon-sm",type:"button",variant:"ghost",...t,children:e??jsx(ChevronLeftIcon,{size:14})})},qp=({children:e,...t})=>{let{goToNext:o,totalBranches:r}=je();return jsx(b,{"aria-label":"Next branch",disabled:r<=1,onClick:o,size:"icon-sm",type:"button",variant:"ghost",...t,children:e??jsx(ChevronRightIcon,{size:14})})},Xp=({className:e,...t})=>{let{currentBranch:o,totalBranches:r}=je();return jsxs(c$2,{className:a("fk:border-none fk:bg-transparent fk:text-muted-foreground fk:shadow-none",e),...t,children:[o+1," of ",r]})},Ha={cjk:cjk,code:code,math:math,mermaid:mermaid},Ga=memo(({className:e,...t})=>jsx(Streamdown,{className:a("fk:size-full fk:[&>*:first-child]:mt-0 fk:[&>*:last-child]:mb-0",e),plugins:Ha,prefix:"fk",...t}),(e,t)=>e.children===t.children&&t.isAnimating===e.isAnimating);Ga.displayName="MessageResponse";var Jp=({className:e,children:t,...o})=>jsx("div",{className:a("fk:mt-4 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-4",e),...o,children:t});var ol=e=>jsx(d$1,{...e}),rl=e=>jsx(e$2,{...e}),nl=({className:e,children:t,title:o="Model Selector",...r})=>jsxs(i,{"aria-describedby":void 0,className:a("fk:outline! fk:border-none! fk:p-0 fk:outline-border! fk:outline-solid!",e),...r,children:[jsx(l$1,{className:"fk:sr-only",children:o}),jsx(n$1,{className:"fk:**:data-[slot=command-input-wrapper]:h-auto",children:t})]}),al=e=>jsx(o,{...e}),sl=({className:e,...t})=>jsx(p,{className:a("fk:h-auto fk:py-3.5",e),...t}),il=e=>jsx(q,{...e}),pl=e=>jsx(r,{...e}),ll=e=>jsx(s,{...e}),fl=e=>jsx(u,{...e}),cl=e=>jsx(v,{...e}),dl=e=>jsx(t,{...e}),ul=({provider:e,className:t,...o})=>jsx("img",{...o,alt:`${e} logo`,className:a("fk:size-3 fk:dark:invert",t),height:12,src:`https://models.dev/logos/${e}.svg`,width:12}),ml=({className:e,...t})=>jsx("div",{className:a("fk:flex fk:shrink-0 fk:items-center fk:-space-x-1 fk:[&>img]:rounded-full fk:[&>img]:bg-background fk:[&>img]:p-px fk:[&>img]:ring-1 fk:dark:[&>img]:bg-foreground",e),...t}),kl=({className:e,...t})=>jsx("span",{className:a("fk:flex-1 fk:truncate fk:text-left",e),...t});var Ka=async e=>{try{let o=await(await fetch(e)).blob();return new Promise(r=>{let a=new FileReader;a.onloadend=()=>r(a.result),a.onerror=()=>r(null),a.readAsDataURL(o);})}catch{return null}},qa=async()=>{if(typeof navigator>"u"||!navigator.mediaDevices?.getDisplayMedia)return null;let e=null,t=document.createElement("video");t.muted=true,t.playsInline=true;try{e=await navigator.mediaDevices.getDisplayMedia({audio:!1,video:!0}),t.srcObject=e,await new Promise((l,f)=>{t.onloadedmetadata=()=>l(),t.onerror=()=>f(new Error("Failed to load screen stream"));}),await t.play();let o=t.videoWidth,r=t.videoHeight;if(!o||!r)return null;let a=document.createElement("canvas");a.width=o,a.height=r;let i=a.getContext("2d");if(!i)return null;i.drawImage(t,0,0,o,r);let s=await new Promise(l=>{a.toBlob(l,"image/png");});if(!s)return null;let p=new Date().toISOString().replaceAll(/[:.]/g,"-").replace("T","_").replace("Z","");return new File([s],`screenshot-${p}.png`,{lastModified:Date.now(),type:"image/png"})}finally{if(e)for(let o of e.getTracks())o.stop();t.pause(),t.srcObject=null;}},$t=createContext(null),Kt=createContext(null),Nl=()=>{let e=useContext($t);if(!e)throw new Error("Wrap your component inside <PromptInputProvider> to use usePromptInputController().");return e},zo=()=>useContext($t),Rl=()=>{let e=useContext(Kt);if(!e)throw new Error("Wrap your component inside <PromptInputProvider> to use useProviderAttachments().");return e},Xa=()=>useContext(Kt),Bl=({initialInput:e="",children:t})=>{let[o,r]=useState(e),a=useCallback(()=>r(""),[]),[i,s]=useState([]),p=useRef(null),l=useRef(()=>{}),f=useCallback(c=>{let x=Array.from(c);x.length!==0&&s(z=>[...z,...x.map(R=>({filename:R.name,id:nanoid(),mediaType:R.type,type:"file",url:URL.createObjectURL(R)}))]);},[]),m=useCallback(c=>{s(x=>{let z=x.find(R=>R.id===c);return z?.url&&URL.revokeObjectURL(z.url),x.filter(R=>R.id!==c)});},[]),k=useCallback(()=>{s(c=>{for(let x of c)x.url&&URL.revokeObjectURL(x.url);return []});},[]),g=useRef(i);useEffect(()=>{g.current=i;},[i]),useEffect(()=>()=>{for(let c of g.current)c.url&&URL.revokeObjectURL(c.url);},[]);let T=useCallback(()=>{l.current?.();},[]),b=useMemo(()=>({add:f,clear:k,fileInputRef:p,files:i,openFileDialog:T,remove:m}),[i,f,m,k,T]),C=useCallback((c,x)=>{p.current=c.current,l.current=x;},[]),N=useMemo(()=>({__registerFileInput:C,attachments:b,textInput:{clear:a,setInput:r,value:o}}),[o,a,b,C]);return jsx($t.Provider,{value:N,children:jsx(Kt.Provider,{value:b,children:t})})},Ho=createContext(null),qt=()=>{let e=Xa(),o=useContext(Ho)??e;if(!o)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return o},Go=createContext(null),Ll=()=>{let e=useContext(Go);if(!e)throw new Error("usePromptInputReferencedSources must be used within a LocalReferencedSourcesContext.Provider");return e},Al=({label:e="Add photos or files",onSelect:t,...o})=>{let r=qt(),a=useCallback(i=>{t?.(i),!i.defaultPrevented&&r.openFileDialog();},[r,t]);return jsxs(h,{...o,onSelect:a,children:[jsx(ImageIcon,{className:"fk:mr-2 fk:size-4"})," ",e]})},Dl=({label:e="Take screenshot",onSelect:t,...o})=>{let r=qt(),a=useCallback(async i=>{if(t?.(i),!i.defaultPrevented)try{let s=await qa();s&&r.add([s]);}catch(s){if(s instanceof DOMException&&(s.name==="NotAllowedError"||s.name==="AbortError"))return;throw s}},[t,r]);return jsxs(h,{...o,onSelect:a,children:[jsx(Monitor,{className:"fk:mr-2 fk:size-4"}),e]})},El=({className:e,accept:t,multiple:o,globalDrop:r,syncHiddenInput:a$1,maxFiles:i,maxFileSize:s,onError:p,onSubmit:l,children:f,...m})=>{let k=zo(),g=!!k,T=useRef(null),b=useRef(null),[C,N]=useState([]),c=g?k.attachments.files:C,[x,z]=useState([]),R=useRef(c);useEffect(()=>{R.current=c;},[c]);let he=useCallback(()=>{T.current?.click();},[]),_=useCallback(u=>!t||t.trim()===""?true:t.split(",").map(h=>h.trim()).filter(Boolean).some(h=>{if(h.startsWith("."))return u.name.toLowerCase().endsWith(h.toLowerCase());if(h.endsWith("/*")){let y=h.slice(0,-1);return u.type.startsWith(y)}return u.type===h}),[t]),Ke=useCallback(u=>{let v=Array.from(u),h=v.filter(X=>_(X));if(v.length&&h.length===0){p?.({code:"accept",message:"No files match the accepted types."});return}let y=X=>s?X.size<=s:true,O=h.filter(y);if(h.length>0&&O.length===0){p?.({code:"max_file_size",message:"All files exceed the maximum size."});return}N(X=>{let D=typeof i=="number"?Math.max(0,i-X.length):void 0,se=typeof D=="number"?O.slice(0,D):O;typeof D=="number"&&O.length>D&&p?.({code:"max_files",message:"Too many files. Some were not added."});let ie=[];for(let ct of se)ie.push({filename:ct.name,id:nanoid(),mediaType:ct.type,type:"file",url:URL.createObjectURL(ct)});return [...X,...ie]});},[_,i,s,p]),te=useCallback(u=>N(v=>{let h=v.find(y=>y.id===u);return h?.url&&URL.revokeObjectURL(h.url),v.filter(y=>y.id!==u)}),[]),W=useCallback(u=>{let v=Array.from(u),h=v.filter(ie=>_(ie));if(v.length&&h.length===0){p?.({code:"accept",message:"No files match the accepted types."});return}let y=ie=>s?ie.size<=s:true,O=h.filter(y);if(h.length>0&&O.length===0){p?.({code:"max_file_size",message:"All files exceed the maximum size."});return}let X=c.length,D=typeof i=="number"?Math.max(0,i-X):void 0,se=typeof D=="number"?O.slice(0,D):O;typeof D=="number"&&O.length>D&&p?.({code:"max_files",message:"Too many files. Some were not added."}),se.length>0&&k?.attachments.add(se);},[_,s,i,p,c.length,k]),$=useCallback(()=>g?k?.attachments.clear():N(u=>{for(let v of u)v.url&&URL.revokeObjectURL(v.url);return []}),[g,k]),K=useCallback(()=>z([]),[]),G=g?W:Ke,xe=g?k.attachments.remove:te,qe=g?k.attachments.openFileDialog:he,ve=useCallback(()=>{$(),K();},[$,K]);useEffect(()=>{g&&k.__registerFileInput(T,()=>T.current?.click());},[g,k]),useEffect(()=>{a$1&&T.current&&c.length===0&&(T.current.value="");},[c,a$1]),useEffect(()=>{let u=b.current;if(!u||r)return;let v=y=>{y.dataTransfer?.types?.includes("Files")&&y.preventDefault();},h=y=>{y.dataTransfer?.types?.includes("Files")&&y.preventDefault(),y.dataTransfer?.files&&y.dataTransfer.files.length>0&&G(y.dataTransfer.files);};return u.addEventListener("dragover",v),u.addEventListener("drop",h),()=>{u.removeEventListener("dragover",v),u.removeEventListener("drop",h);}},[G,r]),useEffect(()=>{if(!r)return;let u=h=>{h.dataTransfer?.types?.includes("Files")&&h.preventDefault();},v=h=>{h.dataTransfer?.types?.includes("Files")&&h.preventDefault(),h.dataTransfer?.files&&h.dataTransfer.files.length>0&&G(h.dataTransfer.files);};return document.addEventListener("dragover",u),document.addEventListener("drop",v),()=>{document.removeEventListener("dragover",u),document.removeEventListener("drop",v);}},[G,r]),useEffect(()=>()=>{if(!g)for(let u of R.current)u.url&&URL.revokeObjectURL(u.url);},[g]);let Xe=useCallback(u=>{u.currentTarget.files&&G(u.currentTarget.files),u.currentTarget.value="";},[G]),A=useMemo(()=>({add:G,clear:$,fileInputRef:T,files:c.map(u=>({...u,id:u.id})),openFileDialog:qe,remove:xe}),[c,G,xe,$,qe]),Je=useMemo(()=>({add:u=>{let v=Array.isArray(u)?u:[u];z(h=>[...h,...v.map(y=>({...y,id:nanoid()}))]);},clear:K,remove:u=>{z(v=>v.filter(h=>h.id!==u));},sources:x}),[x,K]),oe=useCallback(async u=>{u.preventDefault();let v=u.currentTarget,h=g?k.textInput.value:new FormData(v).get("message")||"";g||v.reset();try{let y=await Promise.all(c.map(async({id:X,...D})=>{if(D.url?.startsWith("blob:")){let se=await Ka(D.url);return {...D,url:se??D.url}}return D})),O=l({files:y,text:h},u);if(O instanceof Promise)try{await O,ve(),g&&k.textInput.clear();}catch{}else ve(),g&&k.textInput.clear();}catch{}},[g,k,c,l,ve]),q=jsxs(Fragment,{children:[jsx("input",{accept:t,"aria-label":"Upload files",className:"fk:hidden",multiple:o,onChange:Xe,ref:T,title:"Upload files",type:"file"}),jsx("form",{className:a("fk:w-full",e),onSubmit:oe,ref:b,...m,children:jsx(Ut,{className:"fk:overflow-hidden",children:f})})]}),Ce=jsx(Go.Provider,{value:Je,children:q});return jsx(Ho.Provider,{value:A,children:Ce})},zl=({className:e,...t})=>jsx("div",{className:a("fk:contents",e),...t}),Hl=({onChange:e,onKeyDown:t,className:o,placeholder:r="What would you like to know?",...a$1})=>{let i=zo(),s=qt(),[p,l]=useState(false),f=useCallback(b=>{if(t?.(b),!b.defaultPrevented){if(b.key==="Enter"){if(p||b.nativeEvent.isComposing||b.shiftKey)return;b.preventDefault();let{form:C}=b.currentTarget;if(C?.querySelector('button[type="submit"]')?.disabled)return;C?.requestSubmit();}if(b.key==="Backspace"&&b.currentTarget.value===""&&s.files.length>0){b.preventDefault();let C=s.files[s.files.length-1];C&&s.remove(C.id);}}},[t,p,s]),m=useCallback(b=>{let C=b.clipboardData?.items;if(!C)return;let N=[];for(let c of Array.from(C))if(c.kind==="file"){let x=c.getAsFile();x&&N.push(x);}N.length>0&&(b.preventDefault(),s.add(N));},[s]),k=useCallback(()=>l(false),[]),g=useCallback(()=>l(true),[]),T=i?{onChange:b=>{i.textInput.setInput(b.currentTarget.value),e?.(b);},value:i.textInput.value}:{onChange:e};return jsx(Ft,{className:a("fk:field-sizing-content fk:max-h-48 fk:min-h-16",o),name:"message",onCompositionEnd:k,onCompositionStart:g,onKeyDown:f,onPaste:m,placeholder:r,...a$1,...T})},Gl=({className:e,...t})=>jsx(st,{align:"block-end",className:a("fk:order-first fk:flex-wrap fk:gap-1",e),...t}),Ol=({className:e,...t})=>jsx(st,{align:"block-end",className:a("fk:justify-between fk:gap-1",e),...t}),Ul=({className:e,...t})=>jsx("div",{className:a("fk:flex fk:min-w-0 fk:items-center fk:gap-1",e),...t}),Ja=({variant:e$1="ghost",className:t,size:o,tooltip:r,...a$1})=>{let i=o??(Children.count(a$1.children)>1?"sm":"icon-sm"),s=jsx(it,{className:a(t),size:i,type:"button",variant:e$1,...a$1});if(!r)return s;let p=typeof r=="string"?r:r.content,l=typeof r=="string"?void 0:r.shortcut,f=typeof r=="string"?"top":r.side??"top";return jsxs(b$1,{children:[jsx(c,{asChild:true,children:s}),jsxs(e,{side:f,children:[p,l&&jsx("span",{className:"fk:ml-2 fk:text-muted-foreground",children:l})]})]})},Fl=e=>jsx(c$3,{...e}),_l=({className:e,children:t,...o})=>jsx(e$3,{asChild:true,children:jsx(Ja,{className:e,...o,children:t??jsx(PlusIcon,{className:"fk:size-4"})})}),Vl=({className:e,onCloseAutoFocus:t,...o})=>jsx(f,{align:"start",className:a(e),onCloseAutoFocus:r=>{t?.(r),!r.defaultPrevented&&r.preventDefault();},...o}),jl=({className:e,...t})=>jsx(h,{className:a(e),...t}),Wl=({className:e,variant:t="default",size:o="icon-sm",status:r,onStop:a$1,onClick:i,children:s,...p})=>{let l=r==="submitted"||r==="streaming",f=jsx(CornerDownLeftIcon,{className:"fk:size-4"});r==="submitted"?f=jsx(Ot,{}):r==="streaming"?f=jsx(SquareIcon,{className:"fk:size-4"}):r==="error"&&(f=jsx(XIcon,{className:"fk:size-4"}));let m=useCallback(k=>{if(l&&a$1){k.preventDefault(),a$1();return}i?.(k);},[l,a$1,i]);return jsx(it,{"aria-label":l?"Stop":"Submit",className:a(e),onClick:m,size:o,type:l&&a$1?"button":"submit",variant:t,...p,children:s??f})},$l=e=>jsx(a$4,{...e}),Kl=({className:e,...t})=>jsx(d,{className:a("fk:border-none fk:bg-transparent fk:font-medium fk:text-muted-foreground fk:shadow-none fk:transition-colors","fk:hover:bg-accent fk:hover:text-foreground fk:aria-expanded:bg-accent fk:aria-expanded:text-foreground",e),...t}),ql=({className:e,...t})=>jsx(e$1,{className:a(e),...t}),Xl=({className:e,...t})=>jsx(g,{className:a(e),...t}),Jl=({className:e,...t})=>jsx(c$1,{className:a(e),...t}),Yl=({openDelay:e=0,closeDelay:t=0,...o})=>jsx(Ue,{closeDelay:t,openDelay:e,...o}),Zl=e=>jsx(Fe,{...e}),Ql=({align:e="start",...t})=>jsx(_e,{align:e,...t}),ef=({className:e,...t})=>jsx("div",{className:a(e),...t}),tf=({className:e,...t})=>jsx("div",{className:a(e),...t}),of=({className:e,...t})=>jsx("h3",{className:a("fk:mb-2 fk:px-3 fk:font-medium fk:text-muted-foreground fk:text-xs",e),...t}),rf=({className:e,...t})=>jsx("div",{className:a("fk:space-y-1",e),...t}),nf=({className:e,...t})=>jsx("div",{className:a("fk:flex fk:items-center fk:gap-2 fk:px-3 fk:py-2 fk:text-xs fk:hover:bg-accent",e),...t}),af=({className:e,...t})=>jsx(n$1,{className:a(e),...t}),sf=({className:e,...t})=>jsx(p,{className:a(e),...t}),pf=({className:e,...t})=>jsx(q,{className:a(e),...t}),lf=({className:e,...t})=>jsx(r,{className:a(e),...t}),ff=({className:e,...t})=>jsx(s,{className:a(e),...t}),cf=({className:e,...t})=>jsx(u,{className:a(e),...t}),df=({className:e,...t$1})=>jsx(t,{className:a(e),...t$1});var Oo=new Map,ts=e=>{let t=Oo.get(e);return t||(t=motion.create(e),Oo.set(e,t)),t},os=({children:e,as:t="p",className:o,duration:r=2,spread:a$1=2})=>{let i=ts(t),s=useMemo(()=>(e?.length??0)*a$1,[e,a$1]);return jsx(i,{animate:{backgroundPosition:"0% center"},className:a("fk:relative fk:inline-block fk:bg-[length:250%_100%,auto] fk:bg-clip-text fk:text-transparent","fk:[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] fk:[background-repeat:no-repeat,padding-box]",o),initial:{backgroundPosition:"100% center"},style:{"--spread":`${s}px`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},transition:{duration:r,ease:"linear",repeat:Number.POSITIVE_INFINITY},children:e})},Xt=memo(os);var _o=createContext(null),gs=()=>{let e=useContext(_o);if(!e)throw new Error("Reasoning components must be used within Reasoning");return e},bs=1e3,hs=1e3,xs=memo(({className:e,isStreaming:t=false,open:o,defaultOpen:r,onOpenChange:a$1,duration:i,children:s,...p})=>{let l$1=r??t,f=r===false,[m,k]=useControllableState({defaultProp:l$1,onChange:a$1,prop:o}),[g,T]=useControllableState({defaultProp:void 0,prop:i}),b=useRef(t),[C,N]=useState(false),c=useRef(null);useEffect(()=>{t?(b.current=true,c.current===null&&(c.current=Date.now())):c.current!==null&&(T(Math.ceil((Date.now()-c.current)/hs)),c.current=null);},[t,T]),useEffect(()=>{t&&!m&&!f&&k(true);},[t,m,k,f]),useEffect(()=>{if(b.current&&!t&&m&&!C){let R=setTimeout(()=>{k(false),N(true);},bs);return ()=>clearTimeout(R)}},[t,m,k,C]);let x=useCallback(R=>{k(R);},[k]),z=useMemo(()=>({duration:g,isOpen:m,isStreaming:t,setIsOpen:k}),[g,m,t,k]);return jsx(_o.Provider,{value:z,children:jsx(l,{className:a("fk:not-prose fk:mb-4",e),onOpenChange:x,open:m,...p,children:s})})}),vs=(e,t)=>e||t===0?jsx(Xt,{duration:1,children:"Thinking..."}):t===void 0?jsx("p",{children:"Thought for a few seconds"}):jsxs("p",{children:["Thought for ",t," seconds"]}),Cs=memo(({className:e,children:t,getThinkingMessage:o=vs,...r})=>{let{isStreaming:a$1,isOpen:i,duration:s}=gs();return jsx(m,{className:a("fk:flex fk:w-full fk:items-center fk:gap-2 fk:text-muted-foreground fk:text-sm fk:transition-colors fk:hover:text-foreground",e),...r,children:t??jsxs(Fragment,{children:[jsx(BrainIcon,{className:"fk:size-4"}),o(a$1,s),jsx(ChevronDownIcon,{className:a("fk:size-4 fk:transition-transform",i?"fk:rotate-180":"fk:rotate-0")})]})})}),Ps={cjk:cjk,code:code,math:math,mermaid:mermaid},ys=memo(({className:e,children:t,...o})=>jsx(n,{className:a("fk:mt-4 fk:text-sm","fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:slide-out-to-top-2 fk:data-[state=open]:slide-in-from-top-2 fk:text-muted-foreground fk:outline-none fk:data-[state=closed]:animate-out fk:data-[state=open]:animate-in",e),...o,children:jsx(Streamdown,{plugins:Ps,children:t})}));xs.displayName="Reasoning";Cs.displayName="ReasoningTrigger";ys.displayName="ReasoningContent";var zf=({className:e,...t})=>jsx(l,{className:a("fk:not-prose fk:mb-4 fk:text-primary fk:text-xs",e),...t}),Hf=({className:e,count:t,children:o,...r})=>jsx(m,{className:a("fk:flex fk:items-center fk:gap-2",e),...r,children:o??jsxs(Fragment,{children:[jsxs("p",{className:"fk:font-medium",children:["Used ",t," sources"]}),jsx(ChevronDownIcon,{className:"fk:h-4 fk:w-4"})]})}),Gf=({className:e,...t})=>jsx(n,{className:a("fk:mt-3 fk:flex fk:w-fit fk:flex-col fk:gap-2","fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:slide-out-to-top-2 fk:data-[state=open]:slide-in-from-top-2 fk:outline-none fk:data-[state=closed]:animate-out fk:data-[state=open]:animate-in",e),...t}),Of=({href:e,title:t,children:o,...r})=>jsx("a",{className:"fk:flex fk:items-center fk:gap-2",href:e,rel:"noreferrer",target:"_blank",...r,children:o??jsxs(Fragment,{children:[jsx(BookIcon,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:block fk:font-medium",children:t})]})});var Rs=6e4;function Bs(){return typeof window<"u"&&"MediaRecorder"in window&&typeof navigator<"u"&&"mediaDevices"in navigator&&typeof navigator.mediaDevices.getUserMedia=="function"}function Ls(){return ["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(t=>MediaRecorder.isTypeSupported(t))}function Wo(e,t){return e instanceof DOMException&&(e.name==="NotAllowedError"||e.name==="PermissionDeniedError")?new Error("Microphone permission was denied. Enable the microphone to dictate."):e instanceof DOMException&&e.name==="NotFoundError"?new Error("No microphone was found."):e instanceof Error?e:new Error(t)}function As(e){return e instanceof Error&&e.name==="AbortError"}function Ds(e,t,o){return e?o?"Cancel transcription":t?"Stop recording":"Dictate":"Dictation is not available in this browser."}var Kf=({className:e$1,disabled:t,onAudioRecorded:o,onError:r,onTranscriptionChange:a$1,size:i="icon-sm",variant:s="ghost",...p})=>{let[l,f]=useState(false),[m,k]=useState(false),[g,T]=useState(false),b$2=useRef(null),C=useRef(null),N=useRef([]),c$1=useRef(null),x=useRef(null),z=useRef(false),R=useRef(!!t),he=useRef(o),_=useRef(r),Ke=useRef(a$1);R.current=!!t,he.current=o,_.current=r,Ke.current=a$1,useEffect(()=>{T(Bs());},[]);let te=useCallback(()=>{if(C.current){for(let A of C.current.getTracks())A.stop();C.current=null;}},[]),W=useCallback(()=>{c$1.current!==null&&(window.clearTimeout(c$1.current),c$1.current=null);},[]),$=useCallback(()=>{W(),b$2.current?.state==="recording"&&b$2.current.stop(),f(false);},[W]),K=useCallback(()=>{x.current?.abort(),x.current=null,k(false);},[]),G=useCallback(()=>{K(),W();let A=b$2.current;A?.state==="recording"&&(z.current=true,A.stop()),f(false),te();},[K,W,te]),xe=useCallback(async()=>{if(!R.current){if(!he.current){_.current?.(new Error("Dictation is not configured."));return}try{let A=await navigator.mediaDevices.getUserMedia({audio:!0});if(R.current){for(let q of A.getTracks())q.stop();return}C.current=A;let Je=Ls(),oe=Je?new MediaRecorder(A,{mimeType:Je}):new MediaRecorder(A);N.current=[],oe.ondataavailable=q=>{q.data.size>0&&N.current.push(q.data);},oe.onstop=async()=>{if(te(),W(),f(!1),z.current){z.current=!1,N.current=[];return}let q=new Blob(N.current,{type:oe.mimeType||"audio/webm"});if(q.size===0)return;let Ce=new AbortController;x.current=Ce,k(!0);try{let u=he.current;if(!u)return;let v=await u(q,Ce.signal);v&&Ke.current?.(v);}catch(u){if(As(u))return;_.current?.(Wo(u,"Transcription failed."));}finally{x.current===Ce&&(x.current=null,k(!1));}},oe.onerror=()=>{f(!1),te(),W(),_.current?.(new Error("Recording failed. Try again."));},b$2.current=oe,oe.start(250),f(!0),c$1.current=window.setTimeout(()=>{$();},Rs);}catch(A){f(false),te(),_.current?.(Wo(A,"Could not start the microphone."));}}},[W,te,$]);useEffect(()=>{t&&G();},[G,t]),useEffect(()=>()=>{G();},[G]);let qe=useCallback(()=>{if(m){K();return}if(l){$();return}xe();},[K,l,m,xe,$]),ve=t||!g||!o,Xe=Ds(g&&!!o,l,m);return jsxs(b$1,{children:[jsx(c,{asChild:true,children:jsxs("span",{className:"fk:relative fk:inline-flex fk:items-center fk:justify-center",children:[l?[0,1,2].map(A=>jsx("span",{className:"fk:absolute fk:inset-0 fk:animate-ping fk:rounded-full fk:border-2 fk:border-red-400/30",style:{animationDelay:`${String(A*.3)}s`,animationDuration:"2s"}},A)):null,jsxs(b,{"aria-label":Xe,"aria-pressed":l,size:i,variant:l?"destructive":s,...p,className:a("fk:relative fk:z-10 fk:rounded-full fk:dark:hover:bg-accent",e$1),disabled:ve,onClick:qe,type:"button",children:[m?jsx(LoaderIcon,{className:"fk:size-4 fk:animate-spin"}):null,!m&&l?jsx(SquareIcon,{className:"fk:size-4"}):null,m||l?null:jsx(MicIcon,{className:"fk:size-5"})]})]})}),jsx(e,{children:Xe})]})};var ec=({className:e,children:t,...o})=>jsxs(w,{className:"fk:w-full fk:overflow-x-auto fk:whitespace-nowrap",...o,children:[jsx("div",{className:a("fk:flex fk:w-max fk:flex-nowrap fk:items-center fk:gap-2",e),children:t}),jsx(x,{className:"fk:hidden",orientation:"horizontal"})]}),tc=({suggestion:e,onClick:t,className:o,variant:r="outline",size:a$1="sm",children:i,...s})=>{let p=useCallback(()=>{t?.(e);},[t,e]);return jsx(b,{className:a("fk:cursor-pointer fk:rounded-full fk:px-4",o),onClick:p,size:a$1,type:"button",variant:r,...s,children:i||e})};var fc=({className:e,...t})=>jsx(l,{className:a("fk:group fk:not-prose fk:mb-4 fk:w-full fk:rounded-md fk:border",e),...t}),Fs={"approval-requested":"Awaiting Approval","approval-responded":"Responded","input-available":"Running","input-streaming":"Pending","output-available":"Completed","output-denied":"Denied","output-error":"Error"},_s={"approval-requested":jsx(ClockIcon,{className:"fk:size-4 fk:text-yellow-600"}),"approval-responded":jsx(CheckCircleIcon,{className:"fk:size-4 fk:text-blue-600"}),"input-available":jsx(ClockIcon,{className:"fk:size-4 fk:animate-pulse"}),"input-streaming":jsx(CircleIcon,{className:"fk:size-4"}),"output-available":jsx(CheckCircleIcon,{className:"fk:size-4 fk:text-green-600"}),"output-denied":jsx(XCircleIcon,{className:"fk:size-4 fk:text-orange-600"}),"output-error":jsx(XCircleIcon,{className:"fk:size-4 fk:text-red-600"})},Vs=e=>jsxs(b$3,{className:"fk:gap-1.5 fk:py-px fk:rounded-full fk:text-xs",variant:"secondary",children:[_s[e],Fs[e]]}),cc=({className:e,title:t,type:o,state:r,toolName:a$1,...i})=>{let s=o==="dynamic-tool"?a$1:o.split("-").slice(1).join("-");return jsxs(m,{className:a("fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-4 fk:px-3 fk:py-2",e),...i,children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(WrenchIcon,{className:"fk:size-4 fk:text-muted-foreground"}),jsx("span",{className:"fk:font-medium fk:text-sm",children:t??s}),Vs(r)]}),jsx(ChevronDownIcon,{className:"fk:size-4 fk:text-muted-foreground fk:transition-transform fk:group-data-[state=open]:rotate-180"})]})},dc=({className:e,...t})=>jsx(n,{className:a("fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:slide-out-to-top-2 fk:data-[state=open]:slide-in-from-top-2 fk:space-y-4 fk:p-4 fk:text-popover-foreground fk:outline-none fk:data-[state=closed]:animate-out fk:data-[state=open]:animate-in",e),...t}),uc=({className:e,input:t,...o})=>jsxs("div",{className:a("fk:space-y-2 fk:overflow-hidden",e),...o,children:[jsx("h4",{className:"fk:font-medium fk:text-muted-foreground fk:text-xs fk:uppercase fk:tracking-wide",children:"Parameters"}),jsx("div",{className:"fk:rounded-md fk:bg-muted/50",children:jsx(pt,{code:JSON.stringify(t,null,2),language:"json"})})]}),mc=({className:e,output:t,errorText:o,...r})=>{if(!(t||o))return null;let a$1=jsx("div",{children:t});return typeof t=="object"&&!isValidElement(t)?a$1=jsx(pt,{code:JSON.stringify(t,null,2),language:"json"}):typeof t=="string"&&(a$1=jsx(pt,{code:t,language:"json"})),jsxs("div",{className:a("fk:space-y-2",e),...r,children:[jsx("h4",{className:"fk:font-medium fk:text-muted-foreground fk:text-xs fk:uppercase fk:tracking-wide",children:o?"Error":"Result"}),jsxs("div",{className:a("fk:overflow-x-auto fk:rounded-md fk:text-xs fk:[&_table]:w-full",o?"fk:bg-destructive/10 fk:text-destructive":"fk:bg-muted/50 fk:text-foreground"),children:[o&&jsx("div",{children:o}),a$1]})]})};
|
|
6
6
|
export{Vi as Attachment,Ji as AttachmentEmpty,Ki as AttachmentHoverCard,Xi as AttachmentHoverCardContent,qi as AttachmentHoverCardTrigger,Wi as AttachmentInfo,ji as AttachmentPreview,$i as AttachmentRemove,_i as Attachments,pt as CodeBlock,pp as CodeBlockActions,ba as CodeBlockContainer,ha as CodeBlockContent,lp as CodeBlockCopyButton,ip as CodeBlockFilename,ap as CodeBlockHeader,fp as CodeBlockLanguageSelector,up as CodeBlockLanguageSelectorContent,mp as CodeBlockLanguageSelectorItem,cp as CodeBlockLanguageSelectorTrigger,dp as CodeBlockLanguageSelectorValue,sp as CodeBlockTitle,Pp as Conversation,yp as ConversationContent,Ip as ConversationDownload,Sp as ConversationEmptyState,Tp as ConversationScrollButton,sn as ExternalLink,Ue as HoverCard,_e as HoverCardContent,Fe as HoverCardTrigger,Ut as InputGroup,st as InputGroupAddon,it as InputGroupButton,Fn as InputGroupInput,Un as InputGroupText,Ft as InputGroupTextarea,Go as LocalReferencedSourcesContext,Up as Message,Vp as MessageAction,_p as MessageActions,jp as MessageBranch,Wp as MessageBranchContent,qp as MessageBranchNext,Xp as MessageBranchPage,Kp as MessageBranchPrevious,$p as MessageBranchSelector,Fp as MessageContent,Ga as MessageResponse,Jp as MessageToolbar,ol as ModelSelector,nl as ModelSelectorContent,al as ModelSelectorDialog,pl as ModelSelectorEmpty,ll as ModelSelectorGroup,sl as ModelSelectorInput,fl as ModelSelectorItem,il as ModelSelectorList,ul as ModelSelectorLogo,ml as ModelSelectorLogoGroup,kl as ModelSelectorName,dl as ModelSelectorSeparator,cl as ModelSelectorShortcut,rl as ModelSelectorTrigger,El as PromptInput,Al as PromptInputActionAddAttachments,Dl as PromptInputActionAddScreenshot,Fl as PromptInputActionMenu,Vl as PromptInputActionMenuContent,jl as PromptInputActionMenuItem,_l as PromptInputActionMenuTrigger,zl as PromptInputBody,Ja as PromptInputButton,af as PromptInputCommand,lf as PromptInputCommandEmpty,ff as PromptInputCommandGroup,sf as PromptInputCommandInput,cf as PromptInputCommandItem,pf as PromptInputCommandList,df as PromptInputCommandSeparator,Ol as PromptInputFooter,Gl as PromptInputHeader,Yl as PromptInputHoverCard,Ql as PromptInputHoverCardContent,Zl as PromptInputHoverCardTrigger,Bl as PromptInputProvider,$l as PromptInputSelect,ql as PromptInputSelectContent,Xl as PromptInputSelectItem,Kl as PromptInputSelectTrigger,Jl as PromptInputSelectValue,Wl as PromptInputSubmit,tf as PromptInputTab,rf as PromptInputTabBody,nf as PromptInputTabItem,of as PromptInputTabLabel,ef as PromptInputTabsList,Hl as PromptInputTextarea,Ul as PromptInputTools,xs as Reasoning,ys as ReasoningContent,Cs as ReasoningTrigger,dn as ResizableHandle,cn as ResizablePanel,fn as ResizablePanelGroup,Nt as Sheet,kn as SheetClose,Rt as SheetContent,At as SheetDescription,gn as SheetFooter,Bt as SheetHeader,ao as SheetOverlay,no as SheetPortal,Lt as SheetTitle,mn as SheetTrigger,Xt as Shimmer,En as Sidebar,Ht as SidebarContent,Ze as SidebarGroup,Mn as SidebarGroupContent,Gt as SidebarGroupLabel,wn as SidebarInset,Qe as SidebarMenu,tt as SidebarMenuButton,et as SidebarMenuItem,Et as SidebarPanel,Tn as SidebarProvider,zt as SidebarRail,In as SidebarTrigger,Of as Source,zf as Sources,Gf as SourcesContent,Hf as SourcesTrigger,Kf as SpeechInput,Ot as Spinner,tc as Suggestion,ec as Suggestions,fc as Tool,dc as ToolContent,cc as ToolHeader,uc as ToolInput,mc as ToolOutput,Yn as getAttachmentLabel,bo as getMediaCategory,Vs as getStatusBadge,yo as highlightCode,Sa as messagesToMarkdown,_t as useAttachmentContext,Qn as useAttachmentsContext,qt as usePromptInputAttachments,Nl as usePromptInputController,Ll as usePromptInputReferencedSources,Rl as useProviderAttachments,gs as useReasoning,Ge as useSidebar};//# sourceMappingURL=ui.js.map
|
|
7
7
|
//# sourceMappingURL=ui.js.map
|