@flexkit/studio 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat-page-ZFPMTRLD.js +2 -0
- package/dist/chat-page-ZFPMTRLD.js.map +1 -0
- package/dist/chunk-BKJ2DBRK.js +2 -0
- package/dist/{chunk-QQUNCDUB.js.map → chunk-BKJ2DBRK.js.map} +1 -1
- package/dist/chunk-DPCMOWK4.js +3 -0
- package/dist/chunk-DPCMOWK4.js.map +1 -0
- package/dist/chunk-DQ6Z333C.js +4 -0
- package/dist/{chunk-YINI2YKQ.js.map → chunk-DQ6Z333C.js.map} +1 -1
- package/dist/{chunk-OUSEULBR.js → chunk-LMVJWCOM.js} +4 -4
- package/dist/{chunk-OUSEULBR.js.map → chunk-LMVJWCOM.js.map} +1 -1
- package/dist/{chunk-7PDYCDX6.js → chunk-LX7Q56OS.js} +2 -2
- package/dist/{chunk-7PDYCDX6.js.map → chunk-LX7Q56OS.js.map} +1 -1
- package/dist/chunk-MKEIZ5ZQ.js +5 -0
- package/dist/chunk-MKEIZ5ZQ.js.map +1 -0
- package/dist/chunk-QJWY4XIM.js +2 -0
- package/dist/{chunk-GZIMMYLK.js.map → chunk-QJWY4XIM.js.map} +1 -1
- package/dist/{chunk-3CPWATOI.js → chunk-WBZKCRQK.js} +2 -2
- package/dist/{chunk-3CPWATOI.js.map → chunk-WBZKCRQK.js.map} +1 -1
- package/dist/index.css +6 -0
- package/dist/index.js +4 -4
- package/dist/list-GALFFS5F.js +2 -0
- package/dist/{list-SQCN7HA3.js.map → list-GALFFS5F.js.map} +1 -1
- package/dist/pages-IA7GOMMS.js +3 -0
- package/dist/pages-IA7GOMMS.js.map +1 -0
- package/dist/{plugin-pages-AHOA6YJE.js → plugin-pages-Q63UBSKH.js} +2 -2
- package/dist/{plugin-pages-AHOA6YJE.js.map → plugin-pages-Q63UBSKH.js.map} +1 -1
- package/dist/root-5TCUJI6Q.js +23 -0
- package/dist/{root-4FGNRGCD.js.map → root-5TCUJI6Q.js.map} +1 -1
- package/dist/{root-IIILTOJI.js → root-SMHRBFGW.js} +3 -3
- package/dist/{root-IIILTOJI.js.map → root-SMHRBFGW.js.map} +1 -1
- package/dist/root-VSTE2THV.js +2 -0
- package/dist/{root-5ZW536V7.js.map → root-VSTE2THV.js.map} +1 -1
- package/dist/{root-QPQQ3DFJ.js → root-VYZYDWIB.js} +2 -2
- package/dist/{root-QPQQ3DFJ.js.map → root-VYZYDWIB.js.map} +1 -1
- package/dist/{search-2K2BU4UU.js → search-K75Q65A6.js} +2 -2
- package/dist/{search-2K2BU4UU.js.map → search-K75Q65A6.js.map} +1 -1
- package/dist/{skills-pages-PSBRTFGK.js → skills-pages-KDG2NOQJ.js} +2 -2
- package/dist/{skills-pages-PSBRTFGK.js.map → skills-pages-KDG2NOQJ.js.map} +1 -1
- package/package.json +4 -4
- package/dist/chat-page-NWMI4XOE.js +0 -2
- package/dist/chat-page-NWMI4XOE.js.map +0 -1
- package/dist/chunk-GZIMMYLK.js +0 -2
- package/dist/chunk-NSYO57O3.js +0 -5
- package/dist/chunk-NSYO57O3.js.map +0 -1
- package/dist/chunk-QQUNCDUB.js +0 -2
- package/dist/chunk-W2EBZZAY.js +0 -3
- package/dist/chunk-W2EBZZAY.js.map +0 -1
- package/dist/chunk-YINI2YKQ.js +0 -4
- package/dist/list-SQCN7HA3.js +0 -2
- package/dist/pages-OIAPASPF.js +0 -3
- package/dist/pages-OIAPASPF.js.map +0 -1
- package/dist/root-4FGNRGCD.js +0 -23
- package/dist/root-5ZW536V7.js +0 -2
|
@@ -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":"mhBAwCA,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,CAAMC,GAASA,CAAAA,CAAK,UAAU,CAAC,CACpF,CAEA,SAASC,EAAAA,CAAeC,CAAAA,CAAoBC,CAAAA,CAAsC,CAChF,OAAIA,CAAAA,GAAuBV,CAAAA,CAClBS,EAAS,GAAA,CAAKH,CAAAA,EAAWA,CAAAA,CAAO,MAAM,EAGxCG,CAAAA,CAAS,MAAA,CAAQH,CAAAA,EAAWA,CAAAA,CAAO,SAAWI,CAAkB,CAAA,CAAE,GAAA,CAAKJ,CAAAA,EAAWA,CAAAA,CAAO,MAAM,CACxG,CAEA,SAASK,EAAAA,CAAkBF,CAAAA,CAAoBC,CAAAA,CAAoC,CACjF,OAAIA,CAAAA,GAAuBV,CAAAA,CAClBA,CAAAA,CAGLS,CAAAA,CAAS,KAAMH,CAAAA,EAAWA,CAAAA,CAAO,MAAA,GAAWI,CAAkB,CAAA,CACzDA,CAAAA,CAGFV,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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,CAAAA,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-2K2BU4UU.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 fk:corner-squircle\"\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 fk:corner-squircle\"\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 fk:corner-squircle',\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 fk:corner-squircle',\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 fk:corner-squircle\"\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 fk:corner-squircle',\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":"mhBAwCA,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,CAAMC,GAASA,CAAAA,CAAK,UAAU,CAAC,CACpF,CAEA,SAASC,EAAAA,CAAeC,CAAAA,CAAoBC,CAAAA,CAAsC,CAChF,OAAIA,CAAAA,GAAuBV,CAAAA,CAClBS,EAAS,GAAA,CAAKH,CAAAA,EAAWA,CAAAA,CAAO,MAAM,EAGxCG,CAA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AAA,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,CAAAA,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-K75Q65A6.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 fk:corner-squircle\"\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 fk:corner-squircle\"\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 fk:corner-squircle',\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 fk:corner-squircle',\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 fk:corner-squircle\"\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 fk:corner-squircle',\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,2 +1,2 @@
|
|
|
1
|
-
import'./index.css';import {c}from'./chunk-7PDYCDX6.js';import {f,g,d as d$2}from'./chunk-HROHAMPM.js';import {b}from'./chunk-7SK5YPHT.js';import {f as f$1}from'./chunk-W2EBZZAY.js';import {h}from'./chunk-NNA4MLFC.js';import {Oc,Qc,s,ra,ta,L,M,S,O,e as e$1,la,ma,na}from'./chunk-6LYEDKFY.js';import {t}from'./chunk-SZEGGBOC.js';import {v,w,b as b$1}from'./chunk-ODORXGGY.js';import {d}from'./chunk-5DHOBLAE.js';import {a,d as d$1,c as c$1,e,g as g$1}from'./chunk-HDOIOXMP.js';import'./chunk-O2QMYUPS.js';import {useState,useRef,useMemo,useEffect}from'react';import {Plus,LoaderCircle,Trash2,GraduationCapIcon,ArrowLeft,Info,PenLine,Eye}from'lucide-react';import Pt from'react-markdown';import {useNavigate,Link,useParams}from'react-router-dom';import ve from'swr';import At from'swr/infinite';import {history,defaultKeymap,historyKeymap,indentWithTab}from'@codemirror/commands';import {markdown}from'@codemirror/lang-markdown';import {languages}from'@codemirror/language-data';import {foldGutter,indentOnInput,bracketMatching,foldKeymap}from'@codemirror/language';import {highlightSelectionMatches,searchKeymap}from'@codemirror/search';import {Compartment,EditorState,Prec}from'@codemirror/state';import {EditorView,lineNumbers,highlightActiveLineGutter,highlightSpecialChars,drawSelection,dropCursor,highlightActiveLine,keymap,placeholder}from'@codemirror/view';import {tags}from'@lezer/highlight';import {createTheme}from'@uiw/codemirror-themes';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var je="var(--font-geist-mono), ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",Q="#212121",Y="#fafafa";function ze(t,i,o){return [t,EditorView.theme({"&":{backgroundColor:i},".cm-scroller":{backgroundColor:i},".cm-gutters":{backgroundColor:o}})]}var ce=ze(createTheme({settings:{background:Q,caret:"#f8f8f0",fontFamily:je,foreground:"#f8f8f2",gutterBackground:Q,gutterBorder:"transparent",gutterForeground:"#6d8a88",lineHighlight:"rgba(255, 255, 255, 0.1)",selection:"rgba(255, 255, 255, 0.1)",selectionMatch:"rgba(255, 255, 255, 0.2)"},styles:[{color:"#6272a4",tag:[tags.comment,tags.quote,tags.strikethrough]},{color:"#6272a4",tag:[tags.meta,tags.processingInstruction]},{color:"#f1fa8c",tag:tags.string},{color:"#f91f6f",tag:[tags.atom,tags.bool,tags.number,tags.heading]},{color:"#ff79c6",tag:[tags.keyword,tags.operator,tags.tagName]},{color:"#8be9fd",tag:[tags.typeName,tags.link,tags.url]},{color:"#009fb8",tag:[tags.className,tags.attributeName,tags.monospace]},{color:"#66d9ef",tag:[tags.propertyName,tags.function(tags.propertyName)]},{color:"#009fb8",tag:[tags.definition(tags.variableName),tags.function(tags.variableName)]},{color:"#0072f5",tag:[tags.strong,tags.emphasis]},{color:"#ff5555",tag:tags.invalid}],theme:"dark"}),Q,Q),de=ze(createTheme({settings:{background:Y,caret:"#526fff",fontFamily:je,foreground:"#383a42",gutterBackground:Y,gutterBorder:"transparent",gutterForeground:"#9d9d9f",lineHighlight:"#383a420c",selection:"#e5e5e6",selectionMatch:"#e5e5e6"},styles:[{color:"#a0a1a7",tag:[tags.comment,tags.quote,tags.strikethrough]},{color:"#a0a1a7",tag:[tags.meta,tags.processingInstruction]},{color:"#50a14f",tag:tags.string},{color:"#986801",tag:[tags.attributeName]},{color:"#a626a4",tag:tags.keyword},{color:"#0072f5",tag:[tags.operator,tags.strong,tags.emphasis]},{color:"#f91f6f",tag:[tags.atom,tags.bool,tags.number,tags.heading]},{color:"#c18401",tag:[tags.typeName,tags.className]},{color:"#009fb8",tag:[tags.tagName,tags.propertyName,tags.monospace]},{color:"#4078f2",tag:[tags.link,tags.url,tags.function(tags.variableName),tags.definition(tags.variableName)]},{color:"#f91f6f",tag:tags.invalid}],theme:"light"}),Y,Y);function me(){let t=document.documentElement;return t.getAttribute("data-theme")==="dark"||t.classList.contains("dark")||t.style.colorScheme==="dark"}var xt=EditorView.theme({"&":{fontSize:"13px",height:"100%",maxHeight:"100%",maxWidth:"100%",minHeight:"0",minWidth:"0",width:"100%"},"&.cm-focused":{outline:"none"},".cm-scroller":{height:"100%",lineHeight:"1.6",minHeight:"0",minWidth:"0",overflow:"auto",width:"100%"},".cm-content":{fontSize:"13px",fontStyle:"normal",fontWeight:"400",minWidth:"0 !important",padding:"12px 0"},".cm-line, .cm-line span":{fontSize:"inherit",fontStyle:"inherit",fontWeight:"inherit",lineHeight:"inherit"},".cm-gutters":{borderRight:"1px solid transparent"},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none"}});function ue(t){return [t?ce:de,xt]}function He(t){return [EditorState.readOnly.of(t),EditorView.editable.of(!t)]}function Oe(t){let i={"aria-multiline":"true",role:"textbox"};return t.ariaLabel&&(i["aria-label"]=t.ariaLabel),t.ariaLabelledBy&&(i["aria-labelledby"]=t.ariaLabelledBy),t.ariaDescribedBy&&(i["aria-describedby"]=t.ariaDescribedBy),t.ariaInvalid&&(i["aria-invalid"]="true"),t.readOnly&&(i["aria-readonly"]="true"),i}function Xe({ariaDescribedBy:t,ariaInvalid:i,ariaLabel:o,ariaLabelledBy:l,className:f,onBlur:d,onChange:k,onSave:u,placeholder:m,readOnly:c=false,value:p}){let h=useRef(null),y=useRef(null),L=useRef(new Compartment),P=useRef(new Compartment),N=useRef(new Compartment),C=useRef(d),w=useRef(k),I=useRef(u),v=useRef(p);return C.current=d,w.current=k,I.current=u,v.current=p,useEffect(()=>{let s=h.current;if(!s)return;let g=new EditorView({parent:s,state:EditorState.create({doc:v.current,extensions:[lineNumbers(),highlightActiveLineGutter(),highlightSpecialChars(),history(),foldGutter(),drawSelection(),dropCursor(),EditorState.allowMultipleSelections.of(true),indentOnInput(),bracketMatching(),highlightActiveLine(),highlightSelectionMatches(),EditorView.lineWrapping,markdown({codeLanguages:languages}),keymap.of([...defaultKeymap,...historyKeymap,...searchKeymap,...foldKeymap,indentWithTab]),Prec.highest(keymap.of([{key:"Mod-s",run:()=>(I.current?.(),true)}])),EditorView.updateListener.of(B=>{B.docChanged&&w.current?.(B.state.doc.toString()),B.focusChanged&&!B.view.hasFocus&&C.current?.();}),L.current.of(ue(me())),P.current.of(He(c)),N.current.of(EditorView.contentAttributes.of(Oe({ariaDescribedBy:t,ariaInvalid:i,ariaLabel:o,ariaLabelledBy:l,readOnly:c}))),...m?[placeholder(m)]:[]]})});y.current=g;let K=new ResizeObserver(()=>{g.requestMeasure();});K.observe(s);let G=new MutationObserver(()=>{g.dispatch({effects:L.current.reconfigure(ue(me()))});});return G.observe(document.documentElement,{attributeFilter:["class","data-theme","style"],attributes:true}),()=>{K.disconnect(),G.disconnect(),g.destroy(),y.current=null;}},[]),useEffect(()=>{let s=y.current;s&&s.dispatch({effects:L.current.reconfigure(ue(me()))});},[de,ce]),useEffect(()=>{let s=y.current;if(!s)return;let g=s.state.doc.toString();g!==p&&s.dispatch({changes:{from:0,to:g.length,insert:p}});},[p]),useEffect(()=>{let s=y.current;s&&s.dispatch({effects:[P.current.reconfigure(He(c)),N.current.reconfigure(EditorView.contentAttributes.of(Oe({ariaDescribedBy:t,ariaInvalid:i,ariaLabel:o,ariaLabelledBy:l,readOnly:c})))]});},[t,i,o,l,c]),jsx("div",{className:f??"fk:h-full fk:min-h-0 fk:min-w-0 fk:w-full fk:overflow-hidden",ref:h})}var Je=25,Bt=[{descriptionWidth:"fk:w-44",id:"skill-a",nameWidth:"fk:w-28"},{descriptionWidth:"fk:w-52",id:"skill-b",nameWidth:"fk:w-20"},{descriptionWidth:"fk:w-40",id:"skill-c",nameWidth:"fk:w-36"},{descriptionWidth:"fk:w-48",id:"skill-d",nameWidth:"fk:w-24"},{descriptionWidth:"fk:w-36",id:"skill-e",nameWidth:"fk:w-32"},{descriptionWidth:"fk:w-56",id:"skill-f",nameWidth:"fk:w-16"}];function Wt(){return jsxs("div",{"aria-busy":"true",className:"fk:grid fk:grid-cols-1 fk:gap-x-16 fk:gap-y-1 fk:lg:grid-cols-2",children:[jsx("span",{className:"fk:sr-only",children:"Loading skills"}),Bt.map(t$1=>jsxs("div",{className:"fk:-mx-3 fk:flex fk:min-w-0 fk:items-center fk:gap-3 fk:px-3 fk:py-2",children:[jsx(t,{className:"fk:size-10 fk:shrink-0 fk:rounded-lg"}),jsxs("span",{className:"fk:flex fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-1.5",children:[jsx(t,{className:`fk:h-4 ${t$1.nameWidth}`}),jsx(t,{className:`fk:h-4 ${t$1.descriptionWidth}`})]})]},t$1.id))]})}var Rt={code({children:t,className:i,node:o,...l}){return typeof i=="string"&&i.split(" ").some(d=>d.startsWith("language-"))?jsx("code",{className:i,...l,children:t}):jsx("code",{className:"fk:rounded fk:bg-muted fk:px-1.5 fk:py-0.5 fk:font-mono fk:text-[0.875em] fk:font-medium fk:before:content-none fk:after:content-none fk:corner-squircle",...l,children:t})}};function be(){let{currentProjectId:t}=f$1();return {api:useMemo(()=>t?d$2(t):null,[t]),projectId:t}}function ie({children:t}){return jsx("div",{className:"fk:rounded-md fk:border fk:border-dashed fk:p-8 fk:text-center fk:text-sm fk:text-muted-foreground fk:corner-squircle",children:t})}function jt({onVisible:t}){let i=useRef(null),o=useRef(t);return o.current=t,useEffect(()=>{let l=i.current;if(!l)return;let f=new IntersectionObserver(d=>{d.some(k=>k.isIntersecting)&&o.current();});return f.observe(l),()=>{f.disconnect();}},[]),jsx("div",{"aria-hidden":true,className:"fk:h-px",ref:i})}function zt(t,i){return t.visibility==="space"?(t.spaceId?i.get(t.spaceId):void 0)??"Space":t.visibility==="personal"?"Personal":"Project"}function Dt({skill:t}){return t.logoUrl?jsx("img",{alt:"",className:"fk:size-10 fk:shrink-0 fk:rounded-lg fk:corner-squircle",src:t.logoUrl}):jsx("span",{className:"fk:flex fk:size-10 fk:shrink-0 fk:items-center fk:justify-center fk:rounded-lg fk:bg-muted fk:text-muted-foreground fk:corner-squircle",children:jsx(GraduationCapIcon,{className:"fk:size-5"})})}function hi(){let{api:t,projectId:i}=be(),o=useNavigate(),[l,f$1]=useState(""),d$1=b(),k=l.trim().length>0,u=(s,g$1)=>!i||g$1&&!g$1.hasMore?null:g(i).skills({limit:Je,offset:s*Je,search:l.trim()||void 0}),{data:m,isLoading:c$1,setSize:p,size:h}=At(u,f),y=m?.flatMap(s=>s.skills)??[],P=m?.[m.length-1]?.hasMore??false,N=m!==void 0&&h>m.length,C=c$1&&y.length===0;if(!i||!t)return jsx(ie,{children:"Select a project to view skills."});function w(){p(s=>s+1);}let I="No skills yet.";k&&(I="No skills match your search.");let v=jsx("div",{className:"fk:grid fk:grid-cols-1 fk:gap-x-16 fk:gap-y-1 fk:lg:grid-cols-2",children:y.map(s=>jsxs("button",{type:"button",onClick:()=>o(s.id),className:"fk:-mx-3 fk:flex fk:min-w-0 fk:items-center fk:gap-3 fk:rounded-lg fk:px-3 fk:py-2 fk:text-left fk:transition-colors fk:hover:bg-accent fk:focus-visible:bg-accent fk:focus-visible:outline-none fk:corner-squircle",children:[jsx(Dt,{skill:s}),jsxs("span",{className:"fk:min-w-0 fk:flex-1",children:[jsx("span",{className:"fk:block fk:truncate fk:text-sm fk:font-medium",children:s.name}),jsx("span",{className:"fk:block fk:truncate fk:text-sm fk:text-muted-foreground",children:s.description})]})]},s.id))});return C?v=jsx(Wt,{}):y.length===0&&(v=jsx(Oc,{children:jsx(Qc,{children:I})})),jsxs("main",{className:"fk:flex fk:min-h-0 fk:flex-1 fk:flex-col",children:[jsx(c,{}),jsx("div",{className:"fk:min-h-0 fk:flex-1 fk:overflow-auto",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:w-full fk:max-w-4xl fk:flex-col fk:gap-8 fk:py-6 fk:pl-4 fk:pr-6",children:[jsxs("div",{children:[jsx("h2",{className:"fk:text-2xl fk:font-semibold",children:"Skills for your agents"}),jsx("p",{className:"fk:mt-2 fk:text-muted-foreground",children:"Reusable Markdown instructions that agents load when relevant, or always when attached to an automation."})]}),jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-3",children:[jsx(s,{"aria-label":"Search skills",className:"fk:w-full fk:max-w-xs",placeholder:"Search skills\u2026",value:l,onChange:s=>{p(1),f$1(s.target.value);}}),d$1?jsx(d,{asChild:true,className:"fk:ml-auto",size:"sm",children:jsxs(Link,{to:"new",children:[jsx(Plus,{}),"New Skill"]})}):jsx(ra,{disabled:true,children:jsxs(d,{className:"fk:ml-auto",disabled:true,size:"sm",children:[jsx(Plus,{}),"New Skill"]})})]}),v,P&&!N?jsx(jt,{onVisible:w}):null,N?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more skills..."})]}):null]})})]})}function te({className:t,id:i,message:o}){return jsx("p",{className:`fk:text-sm fk:text-destructive ${t??""}`,id:i,children:o})}function D({children:t,hint:i,htmlFor:o,id:l}){return jsxs("div",{className:"fk:mb-1.5 fk:pl-2.5 fk:flex fk:items-center fk:gap-1",children:[jsx(e$1,{htmlFor:o,id:l,children:t}),jsxs(L,{children:[jsx(M,{asChild:true,children:jsx("button",{"aria-label":`About ${t.toLowerCase()}`,className:"fk:rounded-sm fk:text-muted-foreground hover:fk:text-foreground fk:corner-squircle",type:"button",children:jsx(Info,{className:"fk:size-3.5"})})}),jsx(O,{className:"fk:max-w-xs",children:i})]})]})}function Se({actions:t,title:i}){return jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:gap-2 fk:pr-4",children:[jsxs(L,{children:[jsx(M,{asChild:true,children:jsx(S,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(O,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:h-4"}),jsx("h1",{className:"fk:min-w-0 fk:flex-1 fk:truncate fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:i}),t]}),jsx(d,{asChild:true,className:"fk:shrink-0 fk:w-fit",size:"sm",variant:"ghost",children:jsxs(Link,{relative:"path",to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Skills"]})})]})}function Ht(){return jsxs("div",{"aria-busy":"true",className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-3 fk:overflow-hidden fk:pb-3",children:[jsx("span",{className:"fk:sr-only",children:"Loading skill"}),jsx(Se,{actions:jsx(t,{className:"fk:h-8 fk:w-24"}),title:jsx(t,{className:"fk:h-5 fk:w-40"})}),jsxs("div",{className:"fk:m-auto fk:flex fk:min-h-0 fk:w-full fk:max-w-6xl fk:flex-1 fk:flex-col fk:gap-8 fk:px-6",children:[jsxs("div",{className:"fk:grid fk:shrink-0 fk:gap-3 fk:lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)_auto]",children:[["name","description"].map(t$1=>jsxs("div",{className:"fk:flex fk:flex-col fk:gap-2",children:[jsx(t,{className:"fk:h-4 fk:w-20"}),jsx(t,{className:"fk:h-9 fk:w-full"})]},t$1)),jsxs("div",{className:"fk:flex fk:flex-col fk:gap-2",children:[jsx(t,{className:"fk:h-4 fk:w-20"}),jsx(t,{className:"fk:h-9 fk:w-32"})]})]}),jsxs("div",{className:"fk:flex fk:min-h-0 fk:flex-1 fk:flex-col fk:gap-1.5",children:[jsx(t,{className:"fk:h-4 fk:w-16"}),jsx(t,{className:"fk:min-h-48 fk:flex-1 fk:rounded-md"})]})]})]})}function Ke({content:t,onBlur:i,onChange:o,onSave:l,readOnly:f=false,showContentError:d,validationMessage:k}){let[u,m]=useState("write"),c=t.length>5e4,p;return t.trim()?p=jsx(Pt,{components:Rt,children:t}):p=jsx("p",{className:"fk:text-muted-foreground",children:"Nothing to preview."}),jsxs("div",{className:"fk:flex fk:min-h-0 fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-1.5",children:[jsxs("div",{className:"fk:pl-3.25 fk:flex fk:shrink-0 fk:items-center fk:gap-1",children:[jsx(e$1,{htmlFor:"skill-content",id:"skill-content-label",children:"Content"}),jsxs(L,{children:[jsx(M,{asChild:true,children:jsx("button",{"aria-label":"About skill content",className:"fk:rounded-sm fk:text-muted-foreground hover:fk:text-foreground fk:corner-squircle",type:"button",children:jsx(Info,{className:"fk:size-3.5"})})}),jsx(O,{className:"fk:max-w-sm",children:"The skill itself, in Markdown. Write it like instructions for a capable colleague: procedures, rules, examples, and edge cases. Attached skills are always loaded; other visible skills are loaded on demand."})]})]}),jsxs("div",{className:`fk:flex fk:min-h-0 fk:min-w-0 fk:flex-1 fk:flex-col fk:ml-0.75 fk:overflow-hidden fk:rounded-md fk:border ${d?"fk:border-destructive":""} fk:corner-squircle`,children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:justify-between fk:gap-2 fk:border-b fk:px-2.5 fk:py-1",children:[jsx(la,{value:u,onValueChange:h=>{m(h==="preview"?"preview":"write");},children:jsxs(ma,{children:[jsxs(L,{children:[jsx(M,{asChild:true,children:jsx("span",{className:"fk:inline-flex",children:jsx(na,{"aria-label":"Write",className:"fk:px-2.5",value:"write",children:jsx(PenLine,{className:"fk:size-3.5"})})})}),jsx(O,{children:"Write"})]}),jsxs(L,{children:[jsx(M,{asChild:true,children:jsx("span",{className:"fk:inline-flex",children:jsx(na,{"aria-label":"Preview",className:"fk:px-2.5",value:"preview",children:jsx(Eye,{className:"fk:size-3.5"})})})}),jsx(O,{children:"Preview"})]})]})}),jsxs("span",{className:c?"fk:text-xs fk:text-destructive":"fk:text-xs fk:text-muted-foreground",children:[t.length.toLocaleString()," / ",5e4.toLocaleString()]})]}),jsx("div",{className:"fk:min-h-0 fk:min-w-0 fk:flex-1 fk:overflow-hidden",hidden:u!=="write",children:jsx(Xe,{ariaDescribedBy:d?"skill-content-error":void 0,ariaInvalid:d,ariaLabelledBy:"skill-content-label",className:"fk:h-full fk:min-h-0 fk:min-w-0 fk:w-full fk:overflow-hidden",readOnly:f,value:t,onBlur:i,onChange:o,onSave:l})}),u==="preview"?jsx(w,{className:"fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:prose fk:prose-sm fk:dark:prose-invert fk:max-w-none fk:px-4 fk:py-3",children:p})}):null,d&&k?jsx(te,{className:"fk:border-t fk:px-3 fk:py-2",id:"skill-content-error",message:k}):null]})]})}function Ge({api:t,mode:i,onSaved:o,projectId:l,skill:f$1}){let[d$2,k]=useState(f$1?.name??""),[u,m]=useState(f$1?.description??""),[c,p]=useState(f$1?.content??""),[h$1,y]=useState(f$1?.visibility??"project"),[L,P]=useState(f$1?.spaceId??null),[N,C]=useState(false),w=useRef(false),[I,v]=useState(""),[s$1,g$2]=useState({content:false,description:false,name:false}),K=useNavigate(),{data:G}=ve(g(l).spaces,f),[,B]=h(),H=b(),$e=B.user?.spaces??[],xe=(G?.spaces??[]).filter(a=>$e.includes(a.code)),ne="";c.trim()?c.length>5e4&&(ne=`Content must be at most ${String(5e4)} characters`):ne="Content is required";let b$1={content:ne,description:u.trim()?"":"Description is required",name:d$2.trim()?"":"Name is required",space:h$1==="space"&&!L?"Select a space":""},ae=!b$1.content&&!b$1.description&&!b$1.name&&!b$1.space,$=s$1.name&&!!b$1.name,U=s$1.description&&!!b$1.description,Ue=s$1.content&&!!b$1.content,Ze=i==="create"?"New Skill":f$1?.name??"Skill",se="Update skill";N?se="Saving...":i==="create"&&(se="Create skill");async function ye(){if(!H||w.current)return;if(!ae){g$2({content:true,description:true,name:true});return}w.current=true,C(true),v("");let a={content:c,description:u,name:d$2,spaceId:h$1==="space"?L:null,visibility:h$1};try{let M=i==="create"||!f$1?await t.createSkill(a):await t.updateSkill(f$1.id,a);if(!M.success){v(Array.isArray(M.errorMessage)?M.errorMessage.join(", "):M.errorMessage);return}ta.success(i==="create"||!f$1?"Skill created.":"Skill saved."),o(M.skill);}catch(M){v(M instanceof Error?M.message:"Failed to save skill.");}finally{w.current=false,C(false);}}async function Qe(a){a.preventDefault(),await ye();}async function Ye(){if(!(!f$1||!H||w.current)){w.current=true,C(true),v("");try{let a=await t.deleteSkill(f$1.id);if(!a.success){v(Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage);return}K("..",{relative:"path"});}catch(a){v(a instanceof Error?a.message:"Failed to delete skill.");}finally{w.current=false,C(false);}}}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-3 fk:pb-3",children:[jsx(Se,{actions:jsxs("div",{className:"fk:flex fk:items-center fk:gap-3",children:[ae?null:jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Complete the required fields to save"}),i==="edit"&&f$1?jsxs(d,{disabled:N||!H,size:"sm",type:"button",variant:"outline",onClick:()=>{Ye();},children:[jsx(Trash2,{}),"Delete"]}):null,jsx(ra,{disabled:!H,children:jsx(d,{disabled:N||!ae||!H,form:"skill-editor-form",size:"sm",type:"submit",children:se})})]}),title:Ze}),I?jsx("div",{className:"fk:shrink-0 fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-3 fk:text-sm fk:text-destructive fk:corner-squircle",children:I}):null,jsxs("form",{className:"fk:flex fk:min-h-0 fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-6 fk:w-full fk:max-w-6xl fk:m-auto fk:gap-8 fk:px-4",id:"skill-editor-form",onSubmit:a=>{Qe(a);},children:[jsxs("div",{className:"fk:grid fk:min-w-0 fk:shrink-0 fk:gap-3 fk:px-0.75 fk:lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)_auto]",children:[jsxs("div",{children:[jsx(D,{hint:"Identifying label for this skill",htmlFor:"skill-name",children:"Name"}),jsx(s,{"aria-describedby":$?"skill-name-error":void 0,"aria-invalid":$,className:$?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"skill-name",value:d$2,onBlur:()=>g$2(a=>({...a,name:true})),onChange:a=>k(a.target.value)}),$?jsx(te,{id:"skill-name-error",message:b$1.name}):null]}),jsxs("div",{children:[jsx(D,{hint:"One or two sentences describing when to use this skill. Agents rely on it to decide whether the skill applies to their current task.",htmlFor:"skill-description",children:"Description"}),jsx(s,{"aria-describedby":U?"skill-description-error":void 0,"aria-invalid":U,className:U?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"skill-description",placeholder:"e.g. Rules for writing product descriptions in our brand voice",value:u,onBlur:()=>g$2(a=>({...a,description:true})),onChange:a=>m(a.target.value)}),U?jsx(te,{id:"skill-description-error",message:b$1.description}):null]}),jsxs("div",{children:[jsx(D,{hint:"Who can see and use this skill. Space skills are only visible to members of the selected space and only usable by automations in that space; personal skills are private to you.",htmlFor:"skill-visibility",children:"Visibility"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsxs(a,{value:h$1,onValueChange:a=>{y(a==="space"||a==="personal"?a:"project"),a!=="space"&&P(null);},children:[jsx(d$1,{"aria-label":"Visibility",className:"fk:w-fit fk:min-w-26",id:"skill-visibility",children:jsx(c$1,{})}),jsxs(e,{align:"start",children:[jsx(g$1,{value:"project",children:"Project"}),jsx(g$1,{disabled:xe.length===0,value:"space",children:"Space"}),jsx(g$1,{value:"personal",children:"Personal"})]})]}),h$1==="space"?jsxs(a,{value:L??"",onValueChange:a=>{P(a||null);},children:[jsx(d$1,{"aria-label":"Space",className:"fk:w-fit fk:min-w-34",children:jsx(c$1,{placeholder:"Select a space"})}),jsx(e,{align:"start",children:xe.map(a=>jsx(g$1,{value:a.id,children:a.label},a.id))})]}):null]}),h$1==="space"&&b$1.space?jsx(te,{message:b$1.space}):null]})]}),jsx(Ke,{content:c,showContentError:Ue,validationMessage:b$1.content,onBlur:()=>g$2(a=>({...a,content:true})),onChange:p,onSave:()=>{ye();}})]})]})}function Ot({projectId:t,skill:i,spaceLabelById:o}){let l=b(),f=useNavigate(),[d$2,k]=useState(false),[u,m]=useState("");async function c(){k(true),m("");let p;try{p=await fetch(`/api/flexkit/${t}/skills/${i.id}/fork`,{method:"POST",credentials:"include"});}catch{m("Unable to create a copy. Try again."),k(false);return}if(k(false),!p.ok){m("Unable to create a copy. Check your permissions.");return}f("..",{relative:"path"});}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-3 fk:pb-3",children:[jsx(Se,{actions:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(b$1,{variant:"secondary",children:i.source==="plugin"?"Plugin":"Code"}),i.source==="plugin"&&jsx(d,{type:"button",disabled:d$2||!l,onClick:()=>{c();},size:"sm",children:"Edit a copy"})]}),title:i.name}),jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:px-4 fk:gap-3 fk:max-w-6xl fk:m-auto",children:[jsxs("div",{className:"fk:shrink-0 fk:rounded-md fk:border fk:bg-muted/30 fk:px-3 fk:py-2 fk:corner-squircle",children:[jsx("p",{className:"fk:text-sm fk:font-medium",children:"Version-controlled skill"}),jsx("p",{className:"fk:text-sm fk:text-muted-foreground",children:i.source==="plugin"?"This skill is managed by its plugin. Edit a copy to create a personal Studio skill.":"Edit this skill in your repository and re-sync it from the Custom Tools settings."})]}),jsxs("div",{className:"fk:grid fk:min-w-0 fk:shrink-0 fk:gap-3 fk:lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)_auto]",children:[jsxs("div",{children:[jsx(D,{hint:"Identifying label for this skill",htmlFor:"skill-name",children:"Name"}),jsx(s,{className:"fk:opacity-100!",disabled:true,id:"skill-name",value:i.name})]}),jsxs("div",{children:[jsx(D,{hint:"One or two sentences describing when to use this skill. Agents rely on it to decide whether the skill applies to their current task.",htmlFor:"skill-description",children:"Description"}),jsx(s,{className:"fk:opacity-100!",disabled:true,id:"skill-description",placeholder:"e.g. Rules for writing product descriptions in our brand voice",value:i.description})]}),jsxs("div",{children:[jsx(D,{hint:"Who can see and use this skill. Space skills are only visible to members of the selected space and only usable by automations in that space; personal skills are private to you.",htmlFor:"skill-visibility",children:"Visibility"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsxs(a,{disabled:true,value:i.visibility,children:[jsx(d$1,{"aria-label":"Visibility",className:"fk:w-fit fk:min-w-26 fk:opacity-100!",id:"skill-visibility",children:jsx(c$1,{})}),jsxs(e,{align:"start",children:[jsx(g$1,{value:"project",children:"Project"}),jsx(g$1,{disabled:!i.spaceId,value:"space",children:"Space"}),jsx(g$1,{value:"personal",children:"Personal"})]})]}),i.visibility==="space"?jsxs(a,{disabled:true,value:i.spaceId??"",children:[jsx(d$1,{"aria-label":"Space",className:"fk:w-fit fk:min-w-34 fk:opacity-100!",children:jsx(c$1,{placeholder:"Select a space"})}),jsx(e,{align:"start",children:jsx(g$1,{value:i.spaceId??"",children:zt(i,o)})})]}):null]})]})]}),u&&jsx("p",{role:"alert",children:u}),jsx(Ke,{content:i.content,readOnly:true})]})]})}function vi(){let{api:t,projectId:i}=be(),o=useNavigate();return !i||!t?jsx(ie,{children:"Select a project to create skills."}):jsx(Ge,{api:t,mode:"create",projectId:i,onSaved:()=>o("..",{relative:"path"})})}function bi(){let{api:t,projectId:i}=be(),{skillId:o}=useParams(),{data:l,error:f$1,isLoading:d,mutate:k}=ve(i&&o?g(i).skill(o):null,f),{data:u}=ve(i?g(i).spaces:null,f);if(!i||!t||!o)return jsx(ie,{children:"Select a skill."});if(f$1)return jsx(ie,{children:"Failed to load skill."});if(d||!l?.skill)return jsx(Ht,{});let m=new Map((u?.spaces??[]).map(c=>[c.id,c.label]));return l.skill.source!=="studio"?jsx(Ot,{projectId:i,skill:l.skill,spaceLabelById:m}):jsx(Ge,{api:t,mode:"edit",projectId:i,skill:l.skill,onSaved:c=>{c?k({skill:c},{revalidate:false}):k();}})}export{vi as CreateSkillPage,bi as SkillDetailPage,Ge as SkillForm,hi as SkillsPage};//# sourceMappingURL=skills-pages-PSBRTFGK.js.map
|
|
2
|
-
//# sourceMappingURL=skills-pages-
|
|
1
|
+
import'./index.css';import {c}from'./chunk-LX7Q56OS.js';import {f,g,d as d$2}from'./chunk-HROHAMPM.js';import {b}from'./chunk-7SK5YPHT.js';import {g as g$2}from'./chunk-DPCMOWK4.js';import {h}from'./chunk-NNA4MLFC.js';import {Oc,Qc,s,ra,ta,L,M,S,O,e as e$1,la,ma,na}from'./chunk-6LYEDKFY.js';import {t}from'./chunk-SZEGGBOC.js';import {v,w,b as b$1}from'./chunk-ODORXGGY.js';import {d}from'./chunk-5DHOBLAE.js';import {a,d as d$1,c as c$1,e,g as g$1}from'./chunk-HDOIOXMP.js';import'./chunk-O2QMYUPS.js';import {useState,useRef,useMemo,useEffect}from'react';import {Plus,LoaderCircle,Trash2,GraduationCapIcon,ArrowLeft,Info,PenLine,Eye}from'lucide-react';import Pt from'react-markdown';import {useNavigate,Link,useParams}from'react-router-dom';import ve from'swr';import At from'swr/infinite';import {history,defaultKeymap,historyKeymap,indentWithTab}from'@codemirror/commands';import {markdown}from'@codemirror/lang-markdown';import {languages}from'@codemirror/language-data';import {foldGutter,indentOnInput,bracketMatching,foldKeymap}from'@codemirror/language';import {highlightSelectionMatches,searchKeymap}from'@codemirror/search';import {Compartment,EditorState,Prec}from'@codemirror/state';import {EditorView,lineNumbers,highlightActiveLineGutter,highlightSpecialChars,drawSelection,dropCursor,highlightActiveLine,keymap,placeholder}from'@codemirror/view';import {tags}from'@lezer/highlight';import {createTheme}from'@uiw/codemirror-themes';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var je="var(--font-geist-mono), ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",Q="#212121",Y="#fafafa";function ze(t,i,o){return [t,EditorView.theme({"&":{backgroundColor:i},".cm-scroller":{backgroundColor:i},".cm-gutters":{backgroundColor:o}})]}var ce=ze(createTheme({settings:{background:Q,caret:"#f8f8f0",fontFamily:je,foreground:"#f8f8f2",gutterBackground:Q,gutterBorder:"transparent",gutterForeground:"#6d8a88",lineHighlight:"rgba(255, 255, 255, 0.1)",selection:"rgba(255, 255, 255, 0.1)",selectionMatch:"rgba(255, 255, 255, 0.2)"},styles:[{color:"#6272a4",tag:[tags.comment,tags.quote,tags.strikethrough]},{color:"#6272a4",tag:[tags.meta,tags.processingInstruction]},{color:"#f1fa8c",tag:tags.string},{color:"#f91f6f",tag:[tags.atom,tags.bool,tags.number,tags.heading]},{color:"#ff79c6",tag:[tags.keyword,tags.operator,tags.tagName]},{color:"#8be9fd",tag:[tags.typeName,tags.link,tags.url]},{color:"#009fb8",tag:[tags.className,tags.attributeName,tags.monospace]},{color:"#66d9ef",tag:[tags.propertyName,tags.function(tags.propertyName)]},{color:"#009fb8",tag:[tags.definition(tags.variableName),tags.function(tags.variableName)]},{color:"#0072f5",tag:[tags.strong,tags.emphasis]},{color:"#ff5555",tag:tags.invalid}],theme:"dark"}),Q,Q),de=ze(createTheme({settings:{background:Y,caret:"#526fff",fontFamily:je,foreground:"#383a42",gutterBackground:Y,gutterBorder:"transparent",gutterForeground:"#9d9d9f",lineHighlight:"#383a420c",selection:"#e5e5e6",selectionMatch:"#e5e5e6"},styles:[{color:"#a0a1a7",tag:[tags.comment,tags.quote,tags.strikethrough]},{color:"#a0a1a7",tag:[tags.meta,tags.processingInstruction]},{color:"#50a14f",tag:tags.string},{color:"#986801",tag:[tags.attributeName]},{color:"#a626a4",tag:tags.keyword},{color:"#0072f5",tag:[tags.operator,tags.strong,tags.emphasis]},{color:"#f91f6f",tag:[tags.atom,tags.bool,tags.number,tags.heading]},{color:"#c18401",tag:[tags.typeName,tags.className]},{color:"#009fb8",tag:[tags.tagName,tags.propertyName,tags.monospace]},{color:"#4078f2",tag:[tags.link,tags.url,tags.function(tags.variableName),tags.definition(tags.variableName)]},{color:"#f91f6f",tag:tags.invalid}],theme:"light"}),Y,Y);function me(){let t=document.documentElement;return t.getAttribute("data-theme")==="dark"||t.classList.contains("dark")||t.style.colorScheme==="dark"}var xt=EditorView.theme({"&":{fontSize:"13px",height:"100%",maxHeight:"100%",maxWidth:"100%",minHeight:"0",minWidth:"0",width:"100%"},"&.cm-focused":{outline:"none"},".cm-scroller":{height:"100%",lineHeight:"1.6",minHeight:"0",minWidth:"0",overflow:"auto",width:"100%"},".cm-content":{fontSize:"13px",fontStyle:"normal",fontWeight:"400",minWidth:"0 !important",padding:"12px 0"},".cm-line, .cm-line span":{fontSize:"inherit",fontStyle:"inherit",fontWeight:"inherit",lineHeight:"inherit"},".cm-gutters":{borderRight:"1px solid transparent"},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none"}});function ue(t){return [t?ce:de,xt]}function He(t){return [EditorState.readOnly.of(t),EditorView.editable.of(!t)]}function Oe(t){let i={"aria-multiline":"true",role:"textbox"};return t.ariaLabel&&(i["aria-label"]=t.ariaLabel),t.ariaLabelledBy&&(i["aria-labelledby"]=t.ariaLabelledBy),t.ariaDescribedBy&&(i["aria-describedby"]=t.ariaDescribedBy),t.ariaInvalid&&(i["aria-invalid"]="true"),t.readOnly&&(i["aria-readonly"]="true"),i}function Xe({ariaDescribedBy:t,ariaInvalid:i,ariaLabel:o,ariaLabelledBy:l,className:f,onBlur:d,onChange:k,onSave:u,placeholder:m,readOnly:c=false,value:p}){let h=useRef(null),y=useRef(null),L=useRef(new Compartment),P=useRef(new Compartment),N=useRef(new Compartment),C=useRef(d),w=useRef(k),I=useRef(u),v=useRef(p);return C.current=d,w.current=k,I.current=u,v.current=p,useEffect(()=>{let s=h.current;if(!s)return;let g=new EditorView({parent:s,state:EditorState.create({doc:v.current,extensions:[lineNumbers(),highlightActiveLineGutter(),highlightSpecialChars(),history(),foldGutter(),drawSelection(),dropCursor(),EditorState.allowMultipleSelections.of(true),indentOnInput(),bracketMatching(),highlightActiveLine(),highlightSelectionMatches(),EditorView.lineWrapping,markdown({codeLanguages:languages}),keymap.of([...defaultKeymap,...historyKeymap,...searchKeymap,...foldKeymap,indentWithTab]),Prec.highest(keymap.of([{key:"Mod-s",run:()=>(I.current?.(),true)}])),EditorView.updateListener.of(B=>{B.docChanged&&w.current?.(B.state.doc.toString()),B.focusChanged&&!B.view.hasFocus&&C.current?.();}),L.current.of(ue(me())),P.current.of(He(c)),N.current.of(EditorView.contentAttributes.of(Oe({ariaDescribedBy:t,ariaInvalid:i,ariaLabel:o,ariaLabelledBy:l,readOnly:c}))),...m?[placeholder(m)]:[]]})});y.current=g;let K=new ResizeObserver(()=>{g.requestMeasure();});K.observe(s);let G=new MutationObserver(()=>{g.dispatch({effects:L.current.reconfigure(ue(me()))});});return G.observe(document.documentElement,{attributeFilter:["class","data-theme","style"],attributes:true}),()=>{K.disconnect(),G.disconnect(),g.destroy(),y.current=null;}},[]),useEffect(()=>{let s=y.current;s&&s.dispatch({effects:L.current.reconfigure(ue(me()))});},[de,ce]),useEffect(()=>{let s=y.current;if(!s)return;let g=s.state.doc.toString();g!==p&&s.dispatch({changes:{from:0,to:g.length,insert:p}});},[p]),useEffect(()=>{let s=y.current;s&&s.dispatch({effects:[P.current.reconfigure(He(c)),N.current.reconfigure(EditorView.contentAttributes.of(Oe({ariaDescribedBy:t,ariaInvalid:i,ariaLabel:o,ariaLabelledBy:l,readOnly:c})))]});},[t,i,o,l,c]),jsx("div",{className:f??"fk:h-full fk:min-h-0 fk:min-w-0 fk:w-full fk:overflow-hidden",ref:h})}var Je=25,Bt=[{descriptionWidth:"fk:w-44",id:"skill-a",nameWidth:"fk:w-28"},{descriptionWidth:"fk:w-52",id:"skill-b",nameWidth:"fk:w-20"},{descriptionWidth:"fk:w-40",id:"skill-c",nameWidth:"fk:w-36"},{descriptionWidth:"fk:w-48",id:"skill-d",nameWidth:"fk:w-24"},{descriptionWidth:"fk:w-36",id:"skill-e",nameWidth:"fk:w-32"},{descriptionWidth:"fk:w-56",id:"skill-f",nameWidth:"fk:w-16"}];function Wt(){return jsxs("div",{"aria-busy":"true",className:"fk:grid fk:grid-cols-1 fk:gap-x-16 fk:gap-y-1 fk:lg:grid-cols-2",children:[jsx("span",{className:"fk:sr-only",children:"Loading skills"}),Bt.map(t$1=>jsxs("div",{className:"fk:-mx-3 fk:flex fk:min-w-0 fk:items-center fk:gap-3 fk:px-3 fk:py-2",children:[jsx(t,{className:"fk:size-10 fk:shrink-0 fk:rounded-lg"}),jsxs("span",{className:"fk:flex fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-1.5",children:[jsx(t,{className:`fk:h-4 ${t$1.nameWidth}`}),jsx(t,{className:`fk:h-4 ${t$1.descriptionWidth}`})]})]},t$1.id))]})}var Rt={code({children:t,className:i,node:o,...l}){return typeof i=="string"&&i.split(" ").some(d=>d.startsWith("language-"))?jsx("code",{className:i,...l,children:t}):jsx("code",{className:"fk:rounded fk:bg-muted fk:px-1.5 fk:py-0.5 fk:font-mono fk:text-[0.875em] fk:font-medium fk:before:content-none fk:after:content-none fk:corner-squircle",...l,children:t})}};function be(){let{currentProjectId:t}=g$2();return {api:useMemo(()=>t?d$2(t):null,[t]),projectId:t}}function ie({children:t}){return jsx("div",{className:"fk:rounded-md fk:border fk:border-dashed fk:p-8 fk:text-center fk:text-sm fk:text-muted-foreground fk:corner-squircle",children:t})}function jt({onVisible:t}){let i=useRef(null),o=useRef(t);return o.current=t,useEffect(()=>{let l=i.current;if(!l)return;let f=new IntersectionObserver(d=>{d.some(k=>k.isIntersecting)&&o.current();});return f.observe(l),()=>{f.disconnect();}},[]),jsx("div",{"aria-hidden":true,className:"fk:h-px",ref:i})}function zt(t,i){return t.visibility==="space"?(t.spaceId?i.get(t.spaceId):void 0)??"Space":t.visibility==="personal"?"Personal":"Project"}function Dt({skill:t}){return t.logoUrl?jsx("img",{alt:"",className:"fk:size-10 fk:shrink-0 fk:rounded-lg fk:corner-squircle",src:t.logoUrl}):jsx("span",{className:"fk:flex fk:size-10 fk:shrink-0 fk:items-center fk:justify-center fk:rounded-lg fk:bg-muted fk:text-muted-foreground fk:corner-squircle",children:jsx(GraduationCapIcon,{className:"fk:size-5"})})}function hi(){let{api:t,projectId:i}=be(),o=useNavigate(),[l,f$1]=useState(""),d$1=b(),k=l.trim().length>0,u=(s,g$1)=>!i||g$1&&!g$1.hasMore?null:g(i).skills({limit:Je,offset:s*Je,search:l.trim()||void 0}),{data:m,isLoading:c$1,setSize:p,size:h}=At(u,f),y=m?.flatMap(s=>s.skills)??[],P=m?.[m.length-1]?.hasMore??false,N=m!==void 0&&h>m.length,C=c$1&&y.length===0;if(!i||!t)return jsx(ie,{children:"Select a project to view skills."});function w(){p(s=>s+1);}let I="No skills yet.";k&&(I="No skills match your search.");let v=jsx("div",{className:"fk:grid fk:grid-cols-1 fk:gap-x-16 fk:gap-y-1 fk:lg:grid-cols-2",children:y.map(s=>jsxs("button",{type:"button",onClick:()=>o(s.id),className:"fk:-mx-3 fk:flex fk:min-w-0 fk:items-center fk:gap-3 fk:rounded-lg fk:px-3 fk:py-2 fk:text-left fk:transition-colors fk:hover:bg-accent fk:focus-visible:bg-accent fk:focus-visible:outline-none fk:corner-squircle",children:[jsx(Dt,{skill:s}),jsxs("span",{className:"fk:min-w-0 fk:flex-1",children:[jsx("span",{className:"fk:block fk:truncate fk:text-sm fk:font-medium",children:s.name}),jsx("span",{className:"fk:block fk:truncate fk:text-sm fk:text-muted-foreground",children:s.description})]})]},s.id))});return C?v=jsx(Wt,{}):y.length===0&&(v=jsx(Oc,{children:jsx(Qc,{children:I})})),jsxs("main",{className:"fk:flex fk:min-h-0 fk:flex-1 fk:flex-col",children:[jsx(c,{}),jsx("div",{className:"fk:min-h-0 fk:flex-1 fk:overflow-auto",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:w-full fk:max-w-4xl fk:flex-col fk:gap-8 fk:py-6 fk:pl-4 fk:pr-6",children:[jsxs("div",{children:[jsx("h2",{className:"fk:text-2xl fk:font-semibold",children:"Skills for your agents"}),jsx("p",{className:"fk:mt-2 fk:text-muted-foreground",children:"Reusable Markdown instructions that agents load when relevant, or always when attached to an automation."})]}),jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-3",children:[jsx(s,{"aria-label":"Search skills",className:"fk:w-full fk:max-w-xs",placeholder:"Search skills\u2026",value:l,onChange:s=>{p(1),f$1(s.target.value);}}),d$1?jsx(d,{asChild:true,className:"fk:ml-auto",size:"sm",children:jsxs(Link,{to:"new",children:[jsx(Plus,{}),"New Skill"]})}):jsx(ra,{disabled:true,children:jsxs(d,{className:"fk:ml-auto",disabled:true,size:"sm",children:[jsx(Plus,{}),"New Skill"]})})]}),v,P&&!N?jsx(jt,{onVisible:w}):null,N?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more skills..."})]}):null]})})]})}function te({className:t,id:i,message:o}){return jsx("p",{className:`fk:text-sm fk:text-destructive ${t??""}`,id:i,children:o})}function D({children:t,hint:i,htmlFor:o,id:l}){return jsxs("div",{className:"fk:mb-1.5 fk:pl-2.5 fk:flex fk:items-center fk:gap-1",children:[jsx(e$1,{htmlFor:o,id:l,children:t}),jsxs(L,{children:[jsx(M,{asChild:true,children:jsx("button",{"aria-label":`About ${t.toLowerCase()}`,className:"fk:rounded-sm fk:text-muted-foreground hover:fk:text-foreground fk:corner-squircle",type:"button",children:jsx(Info,{className:"fk:size-3.5"})})}),jsx(O,{className:"fk:max-w-xs",children:i})]})]})}function Se({actions:t,title:i}){return jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:gap-2 fk:pr-4",children:[jsxs(L,{children:[jsx(M,{asChild:true,children:jsx(S,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(O,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:h-4"}),jsx("h1",{className:"fk:min-w-0 fk:flex-1 fk:truncate fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:i}),t]}),jsx(d,{asChild:true,className:"fk:shrink-0 fk:w-fit",size:"sm",variant:"ghost",children:jsxs(Link,{relative:"path",to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Skills"]})})]})}function Ht(){return jsxs("div",{"aria-busy":"true",className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-3 fk:overflow-hidden fk:pb-3",children:[jsx("span",{className:"fk:sr-only",children:"Loading skill"}),jsx(Se,{actions:jsx(t,{className:"fk:h-8 fk:w-24"}),title:jsx(t,{className:"fk:h-5 fk:w-40"})}),jsxs("div",{className:"fk:m-auto fk:flex fk:min-h-0 fk:w-full fk:max-w-6xl fk:flex-1 fk:flex-col fk:gap-8 fk:px-6",children:[jsxs("div",{className:"fk:grid fk:shrink-0 fk:gap-3 fk:lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)_auto]",children:[["name","description"].map(t$1=>jsxs("div",{className:"fk:flex fk:flex-col fk:gap-2",children:[jsx(t,{className:"fk:h-4 fk:w-20"}),jsx(t,{className:"fk:h-9 fk:w-full"})]},t$1)),jsxs("div",{className:"fk:flex fk:flex-col fk:gap-2",children:[jsx(t,{className:"fk:h-4 fk:w-20"}),jsx(t,{className:"fk:h-9 fk:w-32"})]})]}),jsxs("div",{className:"fk:flex fk:min-h-0 fk:flex-1 fk:flex-col fk:gap-1.5",children:[jsx(t,{className:"fk:h-4 fk:w-16"}),jsx(t,{className:"fk:min-h-48 fk:flex-1 fk:rounded-md"})]})]})]})}function Ke({content:t,onBlur:i,onChange:o,onSave:l,readOnly:f=false,showContentError:d,validationMessage:k}){let[u,m]=useState("write"),c=t.length>5e4,p;return t.trim()?p=jsx(Pt,{components:Rt,children:t}):p=jsx("p",{className:"fk:text-muted-foreground",children:"Nothing to preview."}),jsxs("div",{className:"fk:flex fk:min-h-0 fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-1.5",children:[jsxs("div",{className:"fk:pl-3.25 fk:flex fk:shrink-0 fk:items-center fk:gap-1",children:[jsx(e$1,{htmlFor:"skill-content",id:"skill-content-label",children:"Content"}),jsxs(L,{children:[jsx(M,{asChild:true,children:jsx("button",{"aria-label":"About skill content",className:"fk:rounded-sm fk:text-muted-foreground hover:fk:text-foreground fk:corner-squircle",type:"button",children:jsx(Info,{className:"fk:size-3.5"})})}),jsx(O,{className:"fk:max-w-sm",children:"The skill itself, in Markdown. Write it like instructions for a capable colleague: procedures, rules, examples, and edge cases. Attached skills are always loaded; other visible skills are loaded on demand."})]})]}),jsxs("div",{className:`fk:flex fk:min-h-0 fk:min-w-0 fk:flex-1 fk:flex-col fk:ml-0.75 fk:overflow-hidden fk:rounded-md fk:border ${d?"fk:border-destructive":""} fk:corner-squircle`,children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:justify-between fk:gap-2 fk:border-b fk:px-2.5 fk:py-1",children:[jsx(la,{value:u,onValueChange:h=>{m(h==="preview"?"preview":"write");},children:jsxs(ma,{children:[jsxs(L,{children:[jsx(M,{asChild:true,children:jsx("span",{className:"fk:inline-flex",children:jsx(na,{"aria-label":"Write",className:"fk:px-2.5",value:"write",children:jsx(PenLine,{className:"fk:size-3.5"})})})}),jsx(O,{children:"Write"})]}),jsxs(L,{children:[jsx(M,{asChild:true,children:jsx("span",{className:"fk:inline-flex",children:jsx(na,{"aria-label":"Preview",className:"fk:px-2.5",value:"preview",children:jsx(Eye,{className:"fk:size-3.5"})})})}),jsx(O,{children:"Preview"})]})]})}),jsxs("span",{className:c?"fk:text-xs fk:text-destructive":"fk:text-xs fk:text-muted-foreground",children:[t.length.toLocaleString()," / ",5e4.toLocaleString()]})]}),jsx("div",{className:"fk:min-h-0 fk:min-w-0 fk:flex-1 fk:overflow-hidden",hidden:u!=="write",children:jsx(Xe,{ariaDescribedBy:d?"skill-content-error":void 0,ariaInvalid:d,ariaLabelledBy:"skill-content-label",className:"fk:h-full fk:min-h-0 fk:min-w-0 fk:w-full fk:overflow-hidden",readOnly:f,value:t,onBlur:i,onChange:o,onSave:l})}),u==="preview"?jsx(w,{className:"fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:prose fk:prose-sm fk:dark:prose-invert fk:max-w-none fk:px-4 fk:py-3",children:p})}):null,d&&k?jsx(te,{className:"fk:border-t fk:px-3 fk:py-2",id:"skill-content-error",message:k}):null]})]})}function Ge({api:t,mode:i,onSaved:o,projectId:l,skill:f$1}){let[d$2,k]=useState(f$1?.name??""),[u,m]=useState(f$1?.description??""),[c,p]=useState(f$1?.content??""),[h$1,y]=useState(f$1?.visibility??"project"),[L,P]=useState(f$1?.spaceId??null),[N,C]=useState(false),w=useRef(false),[I,v]=useState(""),[s$1,g$2]=useState({content:false,description:false,name:false}),K=useNavigate(),{data:G}=ve(g(l).spaces,f),[,B]=h(),H=b(),$e=B.user?.spaces??[],xe=(G?.spaces??[]).filter(a=>$e.includes(a.code)),ne="";c.trim()?c.length>5e4&&(ne=`Content must be at most ${String(5e4)} characters`):ne="Content is required";let b$1={content:ne,description:u.trim()?"":"Description is required",name:d$2.trim()?"":"Name is required",space:h$1==="space"&&!L?"Select a space":""},ae=!b$1.content&&!b$1.description&&!b$1.name&&!b$1.space,$=s$1.name&&!!b$1.name,U=s$1.description&&!!b$1.description,Ue=s$1.content&&!!b$1.content,Ze=i==="create"?"New Skill":f$1?.name??"Skill",se="Update skill";N?se="Saving...":i==="create"&&(se="Create skill");async function ye(){if(!H||w.current)return;if(!ae){g$2({content:true,description:true,name:true});return}w.current=true,C(true),v("");let a={content:c,description:u,name:d$2,spaceId:h$1==="space"?L:null,visibility:h$1};try{let M=i==="create"||!f$1?await t.createSkill(a):await t.updateSkill(f$1.id,a);if(!M.success){v(Array.isArray(M.errorMessage)?M.errorMessage.join(", "):M.errorMessage);return}ta.success(i==="create"||!f$1?"Skill created.":"Skill saved."),o(M.skill);}catch(M){v(M instanceof Error?M.message:"Failed to save skill.");}finally{w.current=false,C(false);}}async function Qe(a){a.preventDefault(),await ye();}async function Ye(){if(!(!f$1||!H||w.current)){w.current=true,C(true),v("");try{let a=await t.deleteSkill(f$1.id);if(!a.success){v(Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage);return}K("..",{relative:"path"});}catch(a){v(a instanceof Error?a.message:"Failed to delete skill.");}finally{w.current=false,C(false);}}}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-3 fk:pb-3",children:[jsx(Se,{actions:jsxs("div",{className:"fk:flex fk:items-center fk:gap-3",children:[ae?null:jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Complete the required fields to save"}),i==="edit"&&f$1?jsxs(d,{disabled:N||!H,size:"sm",type:"button",variant:"outline",onClick:()=>{Ye();},children:[jsx(Trash2,{}),"Delete"]}):null,jsx(ra,{disabled:!H,children:jsx(d,{disabled:N||!ae||!H,form:"skill-editor-form",size:"sm",type:"submit",children:se})})]}),title:Ze}),I?jsx("div",{className:"fk:shrink-0 fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-3 fk:text-sm fk:text-destructive fk:corner-squircle",children:I}):null,jsxs("form",{className:"fk:flex fk:min-h-0 fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-6 fk:w-full fk:max-w-6xl fk:m-auto fk:gap-8 fk:px-4",id:"skill-editor-form",onSubmit:a=>{Qe(a);},children:[jsxs("div",{className:"fk:grid fk:min-w-0 fk:shrink-0 fk:gap-3 fk:px-0.75 fk:lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)_auto]",children:[jsxs("div",{children:[jsx(D,{hint:"Identifying label for this skill",htmlFor:"skill-name",children:"Name"}),jsx(s,{"aria-describedby":$?"skill-name-error":void 0,"aria-invalid":$,className:$?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"skill-name",value:d$2,onBlur:()=>g$2(a=>({...a,name:true})),onChange:a=>k(a.target.value)}),$?jsx(te,{id:"skill-name-error",message:b$1.name}):null]}),jsxs("div",{children:[jsx(D,{hint:"One or two sentences describing when to use this skill. Agents rely on it to decide whether the skill applies to their current task.",htmlFor:"skill-description",children:"Description"}),jsx(s,{"aria-describedby":U?"skill-description-error":void 0,"aria-invalid":U,className:U?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"skill-description",placeholder:"e.g. Rules for writing product descriptions in our brand voice",value:u,onBlur:()=>g$2(a=>({...a,description:true})),onChange:a=>m(a.target.value)}),U?jsx(te,{id:"skill-description-error",message:b$1.description}):null]}),jsxs("div",{children:[jsx(D,{hint:"Who can see and use this skill. Space skills are only visible to members of the selected space and only usable by automations in that space; personal skills are private to you.",htmlFor:"skill-visibility",children:"Visibility"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsxs(a,{value:h$1,onValueChange:a=>{y(a==="space"||a==="personal"?a:"project"),a!=="space"&&P(null);},children:[jsx(d$1,{"aria-label":"Visibility",className:"fk:w-fit fk:min-w-26",id:"skill-visibility",children:jsx(c$1,{})}),jsxs(e,{align:"start",children:[jsx(g$1,{value:"project",children:"Project"}),jsx(g$1,{disabled:xe.length===0,value:"space",children:"Space"}),jsx(g$1,{value:"personal",children:"Personal"})]})]}),h$1==="space"?jsxs(a,{value:L??"",onValueChange:a=>{P(a||null);},children:[jsx(d$1,{"aria-label":"Space",className:"fk:w-fit fk:min-w-34",children:jsx(c$1,{placeholder:"Select a space"})}),jsx(e,{align:"start",children:xe.map(a=>jsx(g$1,{value:a.id,children:a.label},a.id))})]}):null]}),h$1==="space"&&b$1.space?jsx(te,{message:b$1.space}):null]})]}),jsx(Ke,{content:c,showContentError:Ue,validationMessage:b$1.content,onBlur:()=>g$2(a=>({...a,content:true})),onChange:p,onSave:()=>{ye();}})]})]})}function Ot({projectId:t,skill:i,spaceLabelById:o}){let l=b(),f=useNavigate(),[d$2,k]=useState(false),[u,m]=useState("");async function c(){k(true),m("");let p;try{p=await fetch(`/api/flexkit/${t}/skills/${i.id}/fork`,{method:"POST",credentials:"include"});}catch{m("Unable to create a copy. Try again."),k(false);return}if(k(false),!p.ok){m("Unable to create a copy. Check your permissions.");return}f("..",{relative:"path"});}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-3 fk:pb-3",children:[jsx(Se,{actions:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(b$1,{variant:"secondary",children:i.source==="plugin"?"Plugin":"Code"}),i.source==="plugin"&&jsx(d,{type:"button",disabled:d$2||!l,onClick:()=>{c();},size:"sm",children:"Edit a copy"})]}),title:i.name}),jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:px-4 fk:gap-3 fk:max-w-6xl fk:m-auto",children:[jsxs("div",{className:"fk:shrink-0 fk:rounded-md fk:border fk:bg-muted/30 fk:px-3 fk:py-2 fk:corner-squircle",children:[jsx("p",{className:"fk:text-sm fk:font-medium",children:"Version-controlled skill"}),jsx("p",{className:"fk:text-sm fk:text-muted-foreground",children:i.source==="plugin"?"This skill is managed by its plugin. Edit a copy to create a personal Studio skill.":"Edit this skill in your repository and re-sync it from the Custom Tools settings."})]}),jsxs("div",{className:"fk:grid fk:min-w-0 fk:shrink-0 fk:gap-3 fk:lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)_auto]",children:[jsxs("div",{children:[jsx(D,{hint:"Identifying label for this skill",htmlFor:"skill-name",children:"Name"}),jsx(s,{className:"fk:opacity-100!",disabled:true,id:"skill-name",value:i.name})]}),jsxs("div",{children:[jsx(D,{hint:"One or two sentences describing when to use this skill. Agents rely on it to decide whether the skill applies to their current task.",htmlFor:"skill-description",children:"Description"}),jsx(s,{className:"fk:opacity-100!",disabled:true,id:"skill-description",placeholder:"e.g. Rules for writing product descriptions in our brand voice",value:i.description})]}),jsxs("div",{children:[jsx(D,{hint:"Who can see and use this skill. Space skills are only visible to members of the selected space and only usable by automations in that space; personal skills are private to you.",htmlFor:"skill-visibility",children:"Visibility"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsxs(a,{disabled:true,value:i.visibility,children:[jsx(d$1,{"aria-label":"Visibility",className:"fk:w-fit fk:min-w-26 fk:opacity-100!",id:"skill-visibility",children:jsx(c$1,{})}),jsxs(e,{align:"start",children:[jsx(g$1,{value:"project",children:"Project"}),jsx(g$1,{disabled:!i.spaceId,value:"space",children:"Space"}),jsx(g$1,{value:"personal",children:"Personal"})]})]}),i.visibility==="space"?jsxs(a,{disabled:true,value:i.spaceId??"",children:[jsx(d$1,{"aria-label":"Space",className:"fk:w-fit fk:min-w-34 fk:opacity-100!",children:jsx(c$1,{placeholder:"Select a space"})}),jsx(e,{align:"start",children:jsx(g$1,{value:i.spaceId??"",children:zt(i,o)})})]}):null]})]})]}),u&&jsx("p",{role:"alert",children:u}),jsx(Ke,{content:i.content,readOnly:true})]})]})}function vi(){let{api:t,projectId:i}=be(),o=useNavigate();return !i||!t?jsx(ie,{children:"Select a project to create skills."}):jsx(Ge,{api:t,mode:"create",projectId:i,onSaved:()=>o("..",{relative:"path"})})}function bi(){let{api:t,projectId:i}=be(),{skillId:o}=useParams(),{data:l,error:f$1,isLoading:d,mutate:k}=ve(i&&o?g(i).skill(o):null,f),{data:u}=ve(i?g(i).spaces:null,f);if(!i||!t||!o)return jsx(ie,{children:"Select a skill."});if(f$1)return jsx(ie,{children:"Failed to load skill."});if(d||!l?.skill)return jsx(Ht,{});let m=new Map((u?.spaces??[]).map(c=>[c.id,c.label]));return l.skill.source!=="studio"?jsx(Ot,{projectId:i,skill:l.skill,spaceLabelById:m}):jsx(Ge,{api:t,mode:"edit",projectId:i,skill:l.skill,onSaved:c=>{c?k({skill:c},{revalidate:false}):k();}})}export{vi as CreateSkillPage,bi as SkillDetailPage,Ge as SkillForm,hi as SkillsPage};//# sourceMappingURL=skills-pages-KDG2NOQJ.js.map
|
|
2
|
+
//# sourceMappingURL=skills-pages-KDG2NOQJ.js.map
|