@flexkit/studio 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/activity-nav-button-SIJTREEC.js +2 -0
  2. package/dist/{activity-nav-button-AESIPODJ.js.map → activity-nav-button-SIJTREEC.js.map} +1 -1
  3. package/dist/astro.js +1 -1
  4. package/dist/chat-page-YALTEYVY.js +4 -0
  5. package/dist/chat-page-YALTEYVY.js.map +1 -0
  6. package/dist/{chunk-TXK4OFAG.js → chunk-2AVINVYN.js} +4 -0
  7. package/dist/chunk-3GUFJ6KL.js +2 -0
  8. package/dist/chunk-3GUFJ6KL.js.map +1 -0
  9. package/dist/{chunk-J2G4C6I5.js → chunk-52DYWQBF.js} +2 -2
  10. package/dist/{chunk-J2G4C6I5.js.map → chunk-52DYWQBF.js.map} +1 -1
  11. package/dist/{chunk-6RDPFMLK.js → chunk-5C2GT7MI.js} +2 -2
  12. package/dist/{chunk-6RDPFMLK.js.map → chunk-5C2GT7MI.js.map} +1 -1
  13. package/dist/{chunk-LN55VJ35.js → chunk-7KCER62Q.js} +3 -3
  14. package/dist/{chunk-LN55VJ35.js.map → chunk-7KCER62Q.js.map} +1 -1
  15. package/dist/{chunk-NOFQHWES.js → chunk-7UZJLTR2.js} +2 -2
  16. package/dist/{chunk-NOFQHWES.js.map → chunk-7UZJLTR2.js.map} +1 -1
  17. package/dist/{chunk-2AHDTE5T.js → chunk-DTO6OBC7.js} +2 -2
  18. package/dist/{chunk-2AHDTE5T.js.map → chunk-DTO6OBC7.js.map} +1 -1
  19. package/dist/{chunk-NYKATVPZ.js → chunk-GJQQZFER.js} +3 -3
  20. package/dist/{chunk-NYKATVPZ.js.map → chunk-GJQQZFER.js.map} +1 -1
  21. package/dist/chunk-JK3IOLJZ.js +3 -0
  22. package/dist/chunk-JK3IOLJZ.js.map +1 -0
  23. package/dist/{chunk-KWS3NAYS.js → chunk-MYUV2B6S.js} +3 -3
  24. package/dist/{chunk-KWS3NAYS.js.map → chunk-MYUV2B6S.js.map} +1 -1
  25. package/dist/chunk-TYDYAOQ7.js +3 -0
  26. package/dist/chunk-TYDYAOQ7.js.map +1 -0
  27. package/dist/{chunk-7SK5YPHT.js → chunk-V64P56OA.js} +2 -2
  28. package/dist/{chunk-7SK5YPHT.js.map → chunk-V64P56OA.js.map} +1 -1
  29. package/dist/chunk-W2SMMUXR.js +8 -0
  30. package/dist/chunk-W2SMMUXR.js.map +1 -0
  31. package/dist/{chunk-PWQPA2QL.js → chunk-XAGCVHPZ.js} +2 -2
  32. package/dist/{chunk-PWQPA2QL.js.map → chunk-XAGCVHPZ.js.map} +1 -1
  33. package/dist/index.css +6 -0
  34. package/dist/index.d.ts +3 -1
  35. package/dist/index.js +8 -8
  36. package/dist/index.js.map +1 -1
  37. package/dist/{list-PNKQAYUK.js → list-CLP77KU3.js} +2 -2
  38. package/dist/{list-PNKQAYUK.js.map → list-CLP77KU3.js.map} +1 -1
  39. package/dist/nextjs.js +1 -1
  40. package/dist/pages-4NDELS2U.js +3 -0
  41. package/dist/pages-4NDELS2U.js.map +1 -0
  42. package/dist/{plugin-pages-SE52XFFW.js → plugin-pages-IHHXP7QL.js} +2 -2
  43. package/dist/{plugin-pages-SE52XFFW.js.map → plugin-pages-IHHXP7QL.js.map} +1 -1
  44. package/dist/{root-44ZJLA4E.js → root-4IOF2PC6.js} +2 -2
  45. package/dist/{root-44ZJLA4E.js.map → root-4IOF2PC6.js.map} +1 -1
  46. package/dist/{root-X5NDURAN.js → root-ALGRTN7S.js} +3 -3
  47. package/dist/{root-X5NDURAN.js.map → root-ALGRTN7S.js.map} +1 -1
  48. package/dist/{root-LFQA2VSE.js → root-N45KARKK.js} +2 -2
  49. package/dist/{root-LFQA2VSE.js.map → root-N45KARKK.js.map} +1 -1
  50. package/dist/{root-BH3PQS2H.js → root-SG2H2IAC.js} +3 -3
  51. package/dist/{root-BH3PQS2H.js.map → root-SG2H2IAC.js.map} +1 -1
  52. package/dist/{search-Q65IC67C.js → search-2WY6JMGS.js} +2 -2
  53. package/dist/{search-Q65IC67C.js.map → search-2WY6JMGS.js.map} +1 -1
  54. package/dist/{skills-pages-TWOIIU5J.js → skills-pages-ANAOWXPJ.js} +2 -2
  55. package/dist/{skills-pages-TWOIIU5J.js.map → skills-pages-ANAOWXPJ.js.map} +1 -1
  56. package/dist/tanstack-start.js +1 -1
  57. package/dist/{user-nav-QZTYBG45.js → user-nav-DCAHVWN7.js} +2 -2
  58. package/dist/{user-nav-QZTYBG45.js.map → user-nav-DCAHVWN7.js.map} +1 -1
  59. package/package.json +3 -3
  60. package/dist/activity-nav-button-AESIPODJ.js +0 -2
  61. package/dist/chat-page-S2YGOKO5.js +0 -4
  62. package/dist/chat-page-S2YGOKO5.js.map +0 -1
  63. package/dist/chunk-3TGCCDOR.js +0 -2
  64. package/dist/chunk-3TGCCDOR.js.map +0 -1
  65. package/dist/chunk-CKNFYN3O.js +0 -3
  66. package/dist/chunk-CKNFYN3O.js.map +0 -1
  67. package/dist/chunk-NNA4MLFC.js +0 -3
  68. package/dist/chunk-NNA4MLFC.js.map +0 -1
  69. package/dist/chunk-SVZY7ZZD.js +0 -8
  70. package/dist/chunk-SVZY7ZZD.js.map +0 -1
  71. package/dist/pages-KHFSZ3PH.js +0 -3
  72. package/dist/pages-KHFSZ3PH.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import'./index.css';import {c as c$2,a}from'./chunk-NYKATVPZ.js';import {s,m as m$1,J,d,u,v,w,x}from'./chunk-KWS3NAYS.js';import {c}from'./chunk-P6BZ4QP7.js';import'./chunk-7SK5YPHT.js';import'./chunk-2DXR5NJV.js';import {f}from'./chunk-LN55VJ35.js';import'./chunk-NNA4MLFC.js';import {N}from'./chunk-YCCFUGWJ.js';import {v as v$1}from'./chunk-32ZU4MLE.js';import'./chunk-HDOIOXMP.js';import {t}from'./chunk-SZEGGBOC.js';import'./chunk-U45E5X3H.js';import {b,c as c$1,e}from'./chunk-USNXQOMJ.js';import'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {useState,useMemo,useCallback}from'react';import {useParams,useLocation,Outlet}from'react-router-dom';import {jsx,jsxs}from'react/jsx-runtime';var m=36,ct=[{_updatedAt:"DESC"},{_id:"DESC"}];function vt(){let{entity:t}=useParams(),{search:a}=useLocation(),g=new URLSearchParams(a).get("id"),{scope:j}=c(),{schemaErrorMessage:G}=s(),{currentProject:Q}=f(),h=Q?.schema??[],n=m$1(h,t??""),[r,S]=useState([]),[W,B]=useState(0),[O,F]=useState(t);t!==O&&(F(t),S([]));let k=J({attributesSchema:n?.attributes??[],actionsComponent:o=>ut({entityName:n?.name??"",entityNamePlural:t??"",row:o}),checkboxSelect:"multiple",enableColumnSorting:true}),f$1=useMemo(()=>{if(r.length===0)return ct;let o=r.map(({id:u,desc:it})=>({[u]:it?"DESC":"ASC"}));return o.some(u=>"_id"in u)?o:[...o,{_id:"DESC"}]},[r]),y=useMemo(()=>{if(r.length!==0)return d(f$1,n)},[n,f$1,r.length]),H=g?{where:{_id:{eq:g}}}:{offset:0,limit:m,sort:f$1,...y?{where:y}:{}},{isLoading:Y,isLoadingMore:Z,fetchMore:b$1,reload:C,count:i,data:l,isProjectDisabled:$}=u({entityNamePlural:t??"",schema:h,scope:j,variables:H,selection:"list"});function tt(o){S(o);}let N$1=l?.length??0,et=i>0&&N$1>0&&N$1<i,ot=useCallback(()=>{b$1({variables:{offset:0,limit:m}});},[b$1]),nt=useCallback(()=>{B(o=>o+1),C();},[C]),rt=Array(m).fill({}),at=pt(k),s$1=Y&&(l==null||l.length===0);return $?jsx("div",{className:"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3",children:jsx(v,{})}):jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3",children:[jsx(w,{}),jsxs("div",{className:"fk:flex fk:items-center fk:mb-4 fk:gap-2",children:[jsxs(b,{children:[jsx(c$1,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:w-4 fk:h-4"})}),jsx(e,{children:"Toggle Sidebar"})]}),jsx(v$1,{orientation:"vertical",className:"fk:h-4"}),jsx("h2",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:ft(n?.menu?.label??n?.plural??"")}),s$1?null:jsxs("span",{className:"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground",children:[i.toLocaleString()," ",i===1?"record":"records"]})]}),G?null:jsx(x,{columns:s$1?at:k,data:s$1?rt:l??[],entityName:n?.name??"",hasMore:et,isLoadingMore:Z,pageSize:m,scrollToTopKey:W,sorting:r,onLoadMore:ot,onSortingChange:tt,toolbarComponent:o=>jsx(c$2,{entityName:n?.name??"",isReloading:s$1,onReload:nt,table:o})}),jsx(Outlet,{})]})}function ft(t){return t.charAt(0).toUpperCase()+t.slice(1)}function ut({entityName:t,entityNamePlural:a$1,row:d}){return jsx(a,{entityName:t,entityNamePlural:a$1,row:d})}function pt(t$1){return t$1.map(a=>({...a,cell:()=>jsx(t,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}export{vt as List};//# sourceMappingURL=list-PNKQAYUK.js.map
2
- //# sourceMappingURL=list-PNKQAYUK.js.map
1
+ import'./index.css';import {c as c$2,a}from'./chunk-GJQQZFER.js';import {s,m as m$1,J,d,u,v,w,x}from'./chunk-MYUV2B6S.js';import {c}from'./chunk-P6BZ4QP7.js';import'./chunk-V64P56OA.js';import'./chunk-2DXR5NJV.js';import {f}from'./chunk-7KCER62Q.js';import'./chunk-TYDYAOQ7.js';import {N}from'./chunk-YCCFUGWJ.js';import {v as v$1}from'./chunk-32ZU4MLE.js';import'./chunk-HDOIOXMP.js';import {t}from'./chunk-SZEGGBOC.js';import'./chunk-U45E5X3H.js';import {b,c as c$1,e}from'./chunk-USNXQOMJ.js';import'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {useState,useMemo,useCallback}from'react';import {useParams,useLocation,Outlet}from'react-router-dom';import {jsx,jsxs}from'react/jsx-runtime';var m=36,ct=[{_updatedAt:"DESC"},{_id:"DESC"}];function vt(){let{entity:t}=useParams(),{search:a}=useLocation(),g=new URLSearchParams(a).get("id"),{scope:j}=c(),{schemaErrorMessage:G}=s(),{currentProject:Q}=f(),h=Q?.schema??[],n=m$1(h,t??""),[r,S]=useState([]),[W,B]=useState(0),[O,F]=useState(t);t!==O&&(F(t),S([]));let k=J({attributesSchema:n?.attributes??[],actionsComponent:o=>ut({entityName:n?.name??"",entityNamePlural:t??"",row:o}),checkboxSelect:"multiple",enableColumnSorting:true}),f$1=useMemo(()=>{if(r.length===0)return ct;let o=r.map(({id:u,desc:it})=>({[u]:it?"DESC":"ASC"}));return o.some(u=>"_id"in u)?o:[...o,{_id:"DESC"}]},[r]),y=useMemo(()=>{if(r.length!==0)return d(f$1,n)},[n,f$1,r.length]),H=g?{where:{_id:{eq:g}}}:{offset:0,limit:m,sort:f$1,...y?{where:y}:{}},{isLoading:Y,isLoadingMore:Z,fetchMore:b$1,reload:C,count:i,data:l,isProjectDisabled:$}=u({entityNamePlural:t??"",schema:h,scope:j,variables:H,selection:"list"});function tt(o){S(o);}let N$1=l?.length??0,et=i>0&&N$1>0&&N$1<i,ot=useCallback(()=>{b$1({variables:{offset:0,limit:m}});},[b$1]),nt=useCallback(()=>{B(o=>o+1),C();},[C]),rt=Array(m).fill({}),at=pt(k),s$1=Y&&(l==null||l.length===0);return $?jsx("div",{className:"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3",children:jsx(v,{})}):jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3",children:[jsx(w,{}),jsxs("div",{className:"fk:flex fk:items-center fk:mb-4 fk:gap-2",children:[jsxs(b,{children:[jsx(c$1,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:w-4 fk:h-4"})}),jsx(e,{children:"Toggle Sidebar"})]}),jsx(v$1,{orientation:"vertical",className:"fk:h-4"}),jsx("h2",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:ft(n?.menu?.label??n?.plural??"")}),s$1?null:jsxs("span",{className:"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground",children:[i.toLocaleString()," ",i===1?"record":"records"]})]}),G?null:jsx(x,{columns:s$1?at:k,data:s$1?rt:l??[],entityName:n?.name??"",hasMore:et,isLoadingMore:Z,pageSize:m,scrollToTopKey:W,sorting:r,onLoadMore:ot,onSortingChange:tt,toolbarComponent:o=>jsx(c$2,{entityName:n?.name??"",isReloading:s$1,onReload:nt,table:o})}),jsx(Outlet,{})]})}function ft(t){return t.charAt(0).toUpperCase()+t.slice(1)}function ut({entityName:t,entityNamePlural:a$1,row:d}){return jsx(a,{entityName:t,entityNamePlural:a$1,row:d})}function pt(t$1){return t$1.map(a=>({...a,cell:()=>jsx(t,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}export{vt as List};//# sourceMappingURL=list-CLP77KU3.js.map
2
+ //# sourceMappingURL=list-CLP77KU3.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/apps/desk/list.tsx"],"names":["pageSize","defaultSort","List","entityName","useParams","search","useLocation","entityId","scope","useAppContext","schemaErrorMessage","useGraphQLError","currentProject","useConfig","schema","entitySchema","getEntitySchema","sorting","setSorting","useState","scrollToTopKey","setScrollToTopKey","sortedEntityName","setSortedEntityName","columnsDefinition","useGridColumnsDefinition","row","dataRowActions","graphqlSort","useMemo","primarySort","id","desc","entry","sortNotNullWhere","getSortNotNullWhere","variables","isLoading","isLoadingMore","fetchMore","reload","count","data","isProjectDisabled","useEntityQuery","handleSortingChange","updater","rowsCount","hasMore","handleLoadMore","useCallback","handleReload","key","loadingData","loadingColumns","getLoadingColumns","isInitialLoading","jsx","ProjectDisabled","jsxs","SchemaError","Tooltip","TooltipTrigger","SidebarTrigger","TooltipContent","Separator","capitalize","DataTable","table","DataTableToolbar","Outlet","str","entityNamePlural","DataTableRowActions","columns","column","Skeleton"],"mappings":"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","file":"list-PNKQAYUK.js","sourcesContent":["import { JSX, useCallback, useMemo, useState } from 'react';\nimport { useLocation, useParams, Outlet } from 'react-router-dom';\nimport type { ColumnDef, Row, SortingState, Updater } from '@tanstack/react-table';\nimport { getEntitySchema, getSortNotNullWhere } from '../../graphql-client/queries';\nimport { useAppContext } from '../../core/app-context';\nimport { useConfig } from '../../core/config/config-context';\nimport { useEntityQuery } from '../../graphql-client/use-entity-query';\nimport { useGraphQLError } from '../../graphql-client/graphql-context';\nimport { ProjectDisabled } from '../../core/error/project-disabled';\nimport { SchemaError } from '../../core/error/schema-error';\nimport { DataTable } from '../../data-grid/data-table';\nimport { DataTableRowActions } from '../../data-grid/data-table-row-actions';\nimport { DataTableToolbar } from '../../data-grid/data-table-toolbar';\nimport { useGridColumnsDefinition } from '../../data-grid/columns';\nimport type { AttributeValue } from '../../graphql-client/types';\nimport { Skeleton, SidebarTrigger, Separator, Tooltip, TooltipContent, TooltipTrigger } from '../../ui';\n\nconst pageSize = 36;\nconst defaultSort = [{ _updatedAt: 'DESC' }, { _id: 'DESC' }];\n\nexport function List(): JSX.Element {\n const { entity: entityName } = useParams();\n const { search } = useLocation();\n const query = new URLSearchParams(search);\n const entityId = query.get('id');\n const { scope } = useAppContext();\n const { schemaErrorMessage } = useGraphQLError();\n const { currentProject } = useConfig();\n const schema = currentProject?.schema ?? [];\n const entitySchema = getEntitySchema(schema, entityName ?? '');\n const [sorting, setSorting] = useState<SortingState>([]);\n const [scrollToTopKey, setScrollToTopKey] = useState(0);\n const [sortedEntityName, setSortedEntityName] = useState(entityName);\n\n if (entityName !== sortedEntityName) {\n setSortedEntityName(entityName);\n setSorting([]);\n }\n\n const columnsDefinition = useGridColumnsDefinition<AttributeValue, unknown>({\n attributesSchema: entitySchema?.attributes ?? [],\n actionsComponent: (row) =>\n dataRowActions({ entityName: entitySchema?.name ?? '', entityNamePlural: entityName ?? '', row }),\n checkboxSelect: 'multiple',\n enableColumnSorting: true,\n });\n\n const graphqlSort = useMemo(() => {\n if (sorting.length === 0) {\n return defaultSort;\n }\n\n const primarySort = sorting.map(({ id, desc }) => ({ [id]: desc ? 'DESC' : 'ASC' }));\n const hasIdSort = primarySort.some((entry) => '_id' in entry);\n\n if (hasIdSort) {\n return primarySort;\n }\n\n // Tie-break so offset pages stay stable when sort values collide.\n return [...primarySort, { _id: 'DESC' }];\n }, [sorting]);\n const sortNotNullWhere = useMemo(() => {\n if (sorting.length === 0) {\n return undefined;\n }\n\n return getSortNotNullWhere(graphqlSort, entitySchema);\n }, [entitySchema, graphqlSort, sorting.length]);\n\n const variables = entityId\n ? { where: { _id: { eq: entityId } } }\n : {\n offset: 0,\n limit: pageSize,\n sort: graphqlSort,\n ...(sortNotNullWhere ? { where: sortNotNullWhere } : {}),\n };\n\n const { isLoading, isLoadingMore, fetchMore, reload, count, data, isProjectDisabled } = useEntityQuery({\n entityNamePlural: entityName ?? '',\n schema,\n scope,\n variables,\n selection: 'list',\n });\n\n function handleSortingChange(updater: Updater<SortingState>): void {\n setSorting(updater);\n }\n\n const rowsCount = data?.length ?? 0;\n const hasMore = count > 0 && rowsCount > 0 && rowsCount < count;\n\n const handleLoadMore = useCallback(() => {\n fetchMore({\n variables: {\n // Offset is tracked inside useEntityQuery from page windows; value here is ignored.\n offset: 0,\n limit: pageSize,\n },\n });\n }, [fetchMore]);\n\n const handleReload = useCallback(() => {\n setScrollToTopKey((key) => key + 1);\n reload();\n }, [reload]);\n\n const loadingData = Array(pageSize).fill({});\n const loadingColumns = getLoadingColumns(columnsDefinition);\n const isInitialLoading = isLoading && (data == null || data.length === 0);\n\n if (isProjectDisabled) {\n return (\n <div className=\"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3\">\n <ProjectDisabled />\n </div>\n );\n }\n\n return (\n <div className=\"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3\">\n <SchemaError />\n <div className=\"fk:flex fk:items-center fk:mb-4 fk:gap-2\">\n <Tooltip>\n <TooltipTrigger asChild>\n <SidebarTrigger className=\"fk:-ml-1 fk:w-4 fk:h-4\" />\n </TooltipTrigger>\n <TooltipContent>Toggle Sidebar</TooltipContent>\n </Tooltip>\n <Separator orientation=\"vertical\" className=\"fk:h-4\" />\n <h2 className=\"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight\">\n {capitalize(entitySchema?.menu?.label ?? entitySchema?.plural ?? '')}\n </h2>\n {!isInitialLoading ? (\n <span className=\"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground\">\n {count.toLocaleString()} {count === 1 ? 'record' : 'records'}\n </span>\n ) : null}\n </div>\n {!schemaErrorMessage ? (\n <DataTable\n columns={isInitialLoading ? loadingColumns : columnsDefinition}\n data={isInitialLoading ? loadingData : (data ?? [])}\n entityName={entitySchema?.name ?? ''}\n hasMore={hasMore}\n isLoadingMore={isLoadingMore}\n pageSize={pageSize}\n scrollToTopKey={scrollToTopKey}\n sorting={sorting}\n onLoadMore={handleLoadMore}\n onSortingChange={handleSortingChange}\n toolbarComponent={(table) => (\n <DataTableToolbar\n entityName={entitySchema?.name ?? ''}\n isReloading={isInitialLoading}\n onReload={handleReload}\n table={table}\n />\n )}\n />\n ) : null}\n <Outlet />\n </div>\n );\n}\n\nfunction capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\ntype DataRowActions = {\n entityName: string;\n entityNamePlural: string;\n row: Row<AttributeValue>;\n};\n\nfunction dataRowActions({ entityName, entityNamePlural, row }: DataRowActions): JSX.Element {\n return <DataTableRowActions entityName={entityName} entityNamePlural={entityNamePlural} row={row} />;\n}\n\nfunction getLoadingColumns(columns: ColumnDef<AttributeValue, unknown>[]): ColumnDef<AttributeValue, unknown>[] {\n return columns.map((column) => ({\n ...column,\n cell: () => <Skeleton className=\"fk:h-4 fk:w-full\" style={{ marginTop: '7px', marginBottom: '6px' }} />,\n }));\n}\n"]}
1
+ {"version":3,"sources":["../src/apps/desk/list.tsx"],"names":["pageSize","defaultSort","List","entityName","useParams","search","useLocation","entityId","scope","useAppContext","schemaErrorMessage","useGraphQLError","currentProject","useConfig","schema","entitySchema","getEntitySchema","sorting","setSorting","useState","scrollToTopKey","setScrollToTopKey","sortedEntityName","setSortedEntityName","columnsDefinition","useGridColumnsDefinition","row","dataRowActions","graphqlSort","useMemo","primarySort","id","desc","entry","sortNotNullWhere","getSortNotNullWhere","variables","isLoading","isLoadingMore","fetchMore","reload","count","data","isProjectDisabled","useEntityQuery","handleSortingChange","updater","rowsCount","hasMore","handleLoadMore","useCallback","handleReload","key","loadingData","loadingColumns","getLoadingColumns","isInitialLoading","jsx","ProjectDisabled","jsxs","SchemaError","Tooltip","TooltipTrigger","SidebarTrigger","TooltipContent","Separator","capitalize","DataTable","table","DataTableToolbar","Outlet","str","entityNamePlural","DataTableRowActions","columns","column","Skeleton"],"mappings":"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","file":"list-CLP77KU3.js","sourcesContent":["import { JSX, useCallback, useMemo, useState } from 'react';\nimport { useLocation, useParams, Outlet } from 'react-router-dom';\nimport type { ColumnDef, Row, SortingState, Updater } from '@tanstack/react-table';\nimport { getEntitySchema, getSortNotNullWhere } from '../../graphql-client/queries';\nimport { useAppContext } from '../../core/app-context';\nimport { useConfig } from '../../core/config/config-context';\nimport { useEntityQuery } from '../../graphql-client/use-entity-query';\nimport { useGraphQLError } from '../../graphql-client/graphql-context';\nimport { ProjectDisabled } from '../../core/error/project-disabled';\nimport { SchemaError } from '../../core/error/schema-error';\nimport { DataTable } from '../../data-grid/data-table';\nimport { DataTableRowActions } from '../../data-grid/data-table-row-actions';\nimport { DataTableToolbar } from '../../data-grid/data-table-toolbar';\nimport { useGridColumnsDefinition } from '../../data-grid/columns';\nimport type { AttributeValue } from '../../graphql-client/types';\nimport { Skeleton, SidebarTrigger, Separator, Tooltip, TooltipContent, TooltipTrigger } from '../../ui';\n\nconst pageSize = 36;\nconst defaultSort = [{ _updatedAt: 'DESC' }, { _id: 'DESC' }];\n\nexport function List(): JSX.Element {\n const { entity: entityName } = useParams();\n const { search } = useLocation();\n const query = new URLSearchParams(search);\n const entityId = query.get('id');\n const { scope } = useAppContext();\n const { schemaErrorMessage } = useGraphQLError();\n const { currentProject } = useConfig();\n const schema = currentProject?.schema ?? [];\n const entitySchema = getEntitySchema(schema, entityName ?? '');\n const [sorting, setSorting] = useState<SortingState>([]);\n const [scrollToTopKey, setScrollToTopKey] = useState(0);\n const [sortedEntityName, setSortedEntityName] = useState(entityName);\n\n if (entityName !== sortedEntityName) {\n setSortedEntityName(entityName);\n setSorting([]);\n }\n\n const columnsDefinition = useGridColumnsDefinition<AttributeValue, unknown>({\n attributesSchema: entitySchema?.attributes ?? [],\n actionsComponent: (row) =>\n dataRowActions({ entityName: entitySchema?.name ?? '', entityNamePlural: entityName ?? '', row }),\n checkboxSelect: 'multiple',\n enableColumnSorting: true,\n });\n\n const graphqlSort = useMemo(() => {\n if (sorting.length === 0) {\n return defaultSort;\n }\n\n const primarySort = sorting.map(({ id, desc }) => ({ [id]: desc ? 'DESC' : 'ASC' }));\n const hasIdSort = primarySort.some((entry) => '_id' in entry);\n\n if (hasIdSort) {\n return primarySort;\n }\n\n // Tie-break so offset pages stay stable when sort values collide.\n return [...primarySort, { _id: 'DESC' }];\n }, [sorting]);\n const sortNotNullWhere = useMemo(() => {\n if (sorting.length === 0) {\n return undefined;\n }\n\n return getSortNotNullWhere(graphqlSort, entitySchema);\n }, [entitySchema, graphqlSort, sorting.length]);\n\n const variables = entityId\n ? { where: { _id: { eq: entityId } } }\n : {\n offset: 0,\n limit: pageSize,\n sort: graphqlSort,\n ...(sortNotNullWhere ? { where: sortNotNullWhere } : {}),\n };\n\n const { isLoading, isLoadingMore, fetchMore, reload, count, data, isProjectDisabled } = useEntityQuery({\n entityNamePlural: entityName ?? '',\n schema,\n scope,\n variables,\n selection: 'list',\n });\n\n function handleSortingChange(updater: Updater<SortingState>): void {\n setSorting(updater);\n }\n\n const rowsCount = data?.length ?? 0;\n const hasMore = count > 0 && rowsCount > 0 && rowsCount < count;\n\n const handleLoadMore = useCallback(() => {\n fetchMore({\n variables: {\n // Offset is tracked inside useEntityQuery from page windows; value here is ignored.\n offset: 0,\n limit: pageSize,\n },\n });\n }, [fetchMore]);\n\n const handleReload = useCallback(() => {\n setScrollToTopKey((key) => key + 1);\n reload();\n }, [reload]);\n\n const loadingData = Array(pageSize).fill({});\n const loadingColumns = getLoadingColumns(columnsDefinition);\n const isInitialLoading = isLoading && (data == null || data.length === 0);\n\n if (isProjectDisabled) {\n return (\n <div className=\"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3\">\n <ProjectDisabled />\n </div>\n );\n }\n\n return (\n <div className=\"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3\">\n <SchemaError />\n <div className=\"fk:flex fk:items-center fk:mb-4 fk:gap-2\">\n <Tooltip>\n <TooltipTrigger asChild>\n <SidebarTrigger className=\"fk:-ml-1 fk:w-4 fk:h-4\" />\n </TooltipTrigger>\n <TooltipContent>Toggle Sidebar</TooltipContent>\n </Tooltip>\n <Separator orientation=\"vertical\" className=\"fk:h-4\" />\n <h2 className=\"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight\">\n {capitalize(entitySchema?.menu?.label ?? entitySchema?.plural ?? '')}\n </h2>\n {!isInitialLoading ? (\n <span className=\"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground\">\n {count.toLocaleString()} {count === 1 ? 'record' : 'records'}\n </span>\n ) : null}\n </div>\n {!schemaErrorMessage ? (\n <DataTable\n columns={isInitialLoading ? loadingColumns : columnsDefinition}\n data={isInitialLoading ? loadingData : (data ?? [])}\n entityName={entitySchema?.name ?? ''}\n hasMore={hasMore}\n isLoadingMore={isLoadingMore}\n pageSize={pageSize}\n scrollToTopKey={scrollToTopKey}\n sorting={sorting}\n onLoadMore={handleLoadMore}\n onSortingChange={handleSortingChange}\n toolbarComponent={(table) => (\n <DataTableToolbar\n entityName={entitySchema?.name ?? ''}\n isReloading={isInitialLoading}\n onReload={handleReload}\n table={table}\n />\n )}\n />\n ) : null}\n <Outlet />\n </div>\n );\n}\n\nfunction capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\ntype DataRowActions = {\n entityName: string;\n entityNamePlural: string;\n row: Row<AttributeValue>;\n};\n\nfunction dataRowActions({ entityName, entityNamePlural, row }: DataRowActions): JSX.Element {\n return <DataTableRowActions entityName={entityName} entityNamePlural={entityNamePlural} row={row} />;\n}\n\nfunction getLoadingColumns(columns: ColumnDef<AttributeValue, unknown>[]): ColumnDef<AttributeValue, unknown>[] {\n return columns.map((column) => ({\n ...column,\n cell: () => <Skeleton className=\"fk:h-4 fk:w-full\" style={{ marginTop: '7px', marginBottom: '6px' }} />,\n }));\n}\n"]}
package/dist/nextjs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  handleFlexkitRequest
3
- } from "./chunk-TXK4OFAG.js";
3
+ } from "./chunk-2AVINVYN.js";
4
4
 
5
5
  // src/auth/nextjs-api.ts
6
6
  function resultToNextResponse(result, NextResponse) {
@@ -0,0 +1,3 @@
1
+ import'./index.css';import {f as f$4,b as b$6,c as c$3,d as d$2,e as e$4,g as g$4}from'./chunk-CSUHZFEP.js';import {t,a,b as b$4,d,c as c$2,u,y,z,x,g as g$3,h as h$1,i,f as f$3,v as v$1,E,A,D,e as e$3,B}from'./chunk-W2SMMUXR.js';import {a as a$3,b as b$7}from'./chunk-52DYWQBF.js';import {b as b$5,e as e$2,c as c$1,d as d$1,g as g$2,f as f$2,i as i$1,k,j as j$1}from'./chunk-3GUFJ6KL.js';import {f,g,e as e$7,c as c$5,d as d$4}from'./chunk-JK3IOLJZ.js';import {a as a$1}from'./chunk-3C2EG3SI.js';import {b}from'./chunk-V64P56OA.js';import {f as f$5}from'./chunk-7KCER62Q.js';import {h as h$2}from'./chunk-TYDYAOQ7.js';import {_,$,ca as ca$1,da as da$1,aa,ea,N,f as f$1,ma as ma$1,ga,ha as ha$1,ia as ia$1,_a,$a,bb,oa,s,e as e$5,Z,ka as ka$1,t as t$2,u as u$1,v as v$2}from'./chunk-YCCFUGWJ.js';import {b as b$1,v,w,x as x$1,m,o as o$1,p,q as q$1,r as r$1,t as t$3}from'./chunk-32ZU4MLE.js';import {a as a$2,d as d$3,c as c$4,e as e$6,g as g$5}from'./chunk-HDOIOXMP.js';import {e,g as g$1,h,j,o,t as t$1,q,r,s as s$1,k as k$1}from'./chunk-SZEGGBOC.js';import'./chunk-U45E5X3H.js';import {b as b$3,c,e as e$1}from'./chunk-USNXQOMJ.js';import {b as b$2}from'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {useState,useRef,useMemo,useCallback,useEffect,useTransition,Fragment as Fragment$1,useId}from'react';import {formatDistance,format}from'date-fns';import {Ellipsis,Pencil,Trash2,Plus,ArrowLeft,LoaderCircle,Play,XIcon,TriangleAlertIcon,ZapIcon,BotIcon,Search,X,CoinsIcon,BrainIcon,Trash2Icon,LoaderCircleIcon,GraduationCapIcon,WrenchIcon,Settings2Icon,BellIcon,ClockIcon,WebhookIcon,DatabaseZapIcon,PlusIcon,ChevronDownIcon,LockIcon,CheckIcon,ChevronsUpDownIcon,RefreshCwIcon,CopyIcon,KeyRoundIcon}from'lucide-react';import {useNavigate,Link,useParams}from'react-router-dom';import {useReactTable,getCoreRowModel}from'@tanstack/react-table';import De,{useSWRConfig}from'swr';import At from'swr/infinite';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {CronExpressionParser}from'cron-parser';var Fa=[{kind:"approval_request",label:"Approval requests"},{kind:"automation_failure",label:"Automation failures"},{kind:"automation_result",label:"Automation results"},{kind:"monitor_event",label:"Chat monitors"}];function Lo({checked:t,disabled:n,label:o,onCheckedChange:i}){let l=useId();return jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsx("label",{className:"fk:text-sm",htmlFor:l,children:o}),jsx(Z,{checked:t,disabled:n,id:l,onCheckedChange:i})]})}function zo(){let{mode:t}=f$5(),{isLoaded:n,mutate:o,preferences:i}=i$1(),[l,k]=useState(false);async function d(c){k(true);try{await o(j$1(c),{optimisticData:{preferences:c},rollbackOnError:!0});}catch{oa.error("Unable to save your notification settings.");}finally{k(false);}}function p(c,g){let r=new Set(i.desktopMutedKinds);g?r.delete(c):r.add(c),d({...i,desktopMutedKinds:[...r]});}return jsxs(t$2,{children:[jsx(u$1,{asChild:true,children:jsx(b$2,{"aria-label":"Notification settings",className:"fk:ml-auto",size:"icon",variant:"ghost",children:jsx(Settings2Icon,{className:"fk:size-4"})})}),jsxs(v$2,{align:"end",className:"fk:w-80 fk:space-y-4",children:[jsxs("div",{className:"fk:space-y-2",children:[jsx("p",{className:"fk:text-sm fk:font-medium",children:"Desktop notifications"}),jsxs("p",{className:"fk:text-xs fk:text-muted-foreground",children:[t==="hosted"?"Shown while Studio is in the background, and while your browser runs with no Studio tab open.":"Shown while Studio is open in the background."," ","Activity always keeps every item."]}),Fa.map(({kind:c,label:g})=>jsx(Lo,{checked:!i.desktopMutedKinds.includes(c),disabled:l||!n,label:g,onCheckedChange:r=>p(c,r)},c))]}),jsxs("div",{className:"fk:space-y-2",children:[jsx("p",{className:"fk:text-sm fk:font-medium",children:"Email"}),jsx(Lo,{checked:i.approvalEmail,disabled:l||!n,label:"Approval requests I haven\u2019t read",onCheckedChange:c=>{d({...i,approvalEmail:c});}})]}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"These settings apply to every project you open."})]})]})}var Ha=[{label:"Enabled",value:"enabled"},{label:"Disabled",value:"disabled"}],qa=[{label:"Project",value:"project"},{label:"Space",value:"space"},{label:"Personal",value:"personal"}];function Ua(t,n=300){let o,i=function(...l){o!==void 0&&clearTimeout(o),o=setTimeout(()=>{o=void 0,t.apply(this,l);},n);};return i.cancel=()=>{o!==void 0&&(clearTimeout(o),o=void 0);},i}function $o({actions:t,isSearchLoading:n=false,onSearchChange:o,search:i,searchPlaceholder:l="Search automations...",table:k}){let d=k.getState().columnFilters.length>0||i.trim().length>0,p=k.getAllColumns().find(P=>P.id==="status"),c=k.getAllColumns().find(P=>P.id==="visibility"),[g,r]=useState(i),N=g.trim(),I=i.trim(),T=N.length>0&&(n||N!==I),_=useRef(o);_.current=o;let S=useMemo(()=>Ua(P=>{_.current(P);},300),[]);useEffect(()=>{r(i);},[i]),useEffect(()=>()=>{S.cancel();},[S]);function y(){S.cancel(),r(""),o("");}function h(){k.resetColumnFilters(),y();}return jsx("div",{className:"fk:flex fk:w-full fk:min-w-0",children:jsxs(w,{className:"fk:w-0 fk:min-w-0 fk:flex-1 fk:whitespace-nowrap fk:-ml-0.75",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-3 fk:p-0.75 fk:pb-2.5",children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs("div",{className:"fk:relative",children:[T?jsx(LoaderCircle,{className:"fk:absolute fk:left-2 fk:top-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-2 fk:top-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(s,{className:"fk:h-8 fk:w-37.5 fk:lg:w-70 fk:px-7 fk:text-sm",name:"search-automations",placeholder:l,value:g,onChange:P=>{let{value:F}=P.target;if(r(F),F.trim().length===0){S.cancel(),o("");return}S(F.trim());}}),g?jsx(b$2,{"aria-label":"Clear search",className:"fk:absolute fk:right-1 fk:top-1 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",onClick:y,type:"button",children:jsx(X,{className:"fk:h-4 fk:w-4"})}):null]}),p?jsx(a$1,{column:p,options:Ha,title:"Status"}):null,c?jsx(a$1,{column:c,options:qa,title:"Visibility"}):null,d?jsxs(b$2,{className:"fk:h-8 fk:px-2 fk:lg:px-3",onClick:h,variant:"ghost",children:["Reset",jsx(X,{className:"fk:ml-2 fk:h-4 fk:w-4"})]}):null]}),t?jsx("div",{className:"fk:ml-auto fk:flex fk:shrink-0 fk:items-center fk:gap-3",children:t}):null]}),jsx(x$1,{orientation:"horizontal"})]})})}function Cn(t,n,o){return (o??[]).some(i=>i.toLowerCase().includes(n.trim().toLowerCase()))?1:0}function Jt({disabled:t,emptyText:n,footer:o,items:i,searchPlaceholder:l,triggerLabel:k="Attach",onToggle:d}){let[p$1,c]=useState(false),g=useRef(null);return jsxs(t$2,{open:p$1,onOpenChange:c,children:[jsx(u$1,{asChild:true,children:jsxs(b$2,{disabled:t,size:"sm",type:"button",variant:"outline",children:[k,jsx(ChevronDownIcon,{className:"fk:ml-1 fk:size-4"})]})}),jsx(v$2,{align:"end",className:"fk:w-72 fk:p-0",onOpenAutoFocus:r=>{r.preventDefault(),g.current?.focus({preventScroll:true});},children:jsxs(m,{filter:Cn,children:[jsx(o$1,{placeholder:l,ref:g}),jsxs(p,{className:"fk:max-h-72",children:[jsx(q$1,{children:n}),jsx(r$1,{children:i.map(r=>jsxs(t$3,{disabled:!!r.lockedHint,title:r.lockedHint,value:r.id,keywords:[r.label],onSelect:()=>d(r.id,!r.attached),children:[r.lockedHint?jsx(LockIcon,{className:"fk:size-4"}):jsx(CheckIcon,{className:r.attached?"fk:size-4":"fk:size-4 fk:opacity-0"}),jsx("span",{className:"fk:truncate",children:r.label}),r.badge?jsx(b$1,{className:"fk:ml-auto fk:py-0 fk:text-[10px]",variant:"secondary",children:r.badge}):null]},r.id))})]}),o]})})]})}function jo(t){return t==="project"?"Project":"Personal"}function Nt(t,n){return t.connections.filter(o=>o.scope===n&&o.status==="connected")}function An(t,n){if(!n)return null;let o=Nt(t,n.connectionMode);return n.connectionId?o.find(i=>i.id===n.connectionId)??null:o.find(i=>i.isPrimary)??null}function xt(t){return t?t.connectionId?`account:${t.connectionId}`:`primary:${t.connectionMode}`:""}function In({ariaLabel:t,disabled:n,plugin:o,scopes:i,value:l,onChange:k}){let d=[];for(let c of i){let g=Nt(o,c),r=g.find(I=>I.isPrimary),[N]=g;if(g.length===1&&N){let I=l?.connectionMode===c&&l.connectionId===N.id;d.push({choice:{connectionMode:c,connectionId:I||!N.isPrimary?N.id:null},label:`${jo(c)} \xB7 ${N.displayName}`});continue}r&&d.push({choice:{connectionMode:c,connectionId:null},label:`Primary ${c} account (${r.displayName})`});for(let I of g)d.push({choice:{connectionMode:c,connectionId:I.id},label:`${jo(c)} \xB7 ${I.displayName}`});}let p=xt(l);return jsxs(a$2,{disabled:n,value:d.some(c=>xt(c.choice)===p)?p:"",onValueChange:c=>{let g=d.find(r=>xt(r.choice)===c);g&&k(g.choice);},children:[jsx(d$3,{"aria-label":t,className:"fk:w-fit fk:max-w-full",size:"sm",children:jsx(c$4,{placeholder:"Select account"})}),jsx(e$6,{children:d.map(c=>jsx(g$5,{value:xt(c.choice),children:c.label},xt(c.choice)))})]})}var wn=2;function qo(t){return t.scopes.filter(n=>n==="project"||t.allowPersonal)}function ts(t){let n=qo(t),o=n.includes("personal")&&(!n.includes("project")||Nt(t,"project").length===0&&Nt(t,"personal").length>0);return {pluginId:t.id,enabled:true,connectionMode:o?"personal":"project",connectionId:null,allTools:true,selectedTools:[],deliveryEnabled:false,channels:[]}}function ns(t,n){return `${encodeURIComponent(t)}:${encodeURIComponent(n)}`}function os(t){return decodeURIComponent(t.slice(t.indexOf(":")+1))}function as(t){let n=t.map(os),o=n.slice(0,wn).join(", ");return n.length>wn?`${o} +${n.length-wn} more`:o}function ss({canManage:t,disabled:n,plugin:o$1,projectId:i,usage:l,onChange:k,onRemove:d}){let p=qo(o$1),c=p.some(w=>Nt(o$1,w).length>0),g=p.includes(l.connectionMode)?{connectionMode:l.connectionMode,connectionId:l.connectionId}:null,r=An(o$1,g),{data:N,error:I}=De(r?`/api/flexkit/${i}/plugin-connections/${r.id}/tools`:null,f),T=(N?.servers??[]).flatMap(w=>w.tools.map(X=>({key:ns(w.name,X.name),entry:X}))),_=(N?.servers??[]).flatMap(w=>w.error?[w.error]:[]),S=l.allTools!==false,y=n||!o$1.enabled,h$1=w=>k({...l,allTools:false,selectedTools:w,enabled:w.length>0}),P=()=>k({...l,allTools:true,selectedTools:[],enabled:true}),F=w=>({...l,connectionMode:w.connectionMode,connectionId:w.connectionId,selectedTools:[],enabled:S}),{mutate:C}=useSWRConfig(),[B,M]=useState(false),$=async w=>{M(true);try{await a$3(d$4(i),o$1.id,w),await C(`/api/flexkit/${i}/plugins`),k(F({connectionMode:w,connectionId:null}));}catch(X){oa.error(X instanceof Error?X.message:`Unable to connect ${o$1.name}.`);}finally{M(false);}},U=null;return o$1.enabled?c?g?r?I||_.length?U={text:_[0]??"Unable to load tools. Reconnect or try again.",tone:"warning"}:S?U={text:"All tools",tone:"muted"}:l.selectedTools.length===0?U={text:"No tools selected, so the agent cannot use this plugin yet.",tone:"warning"}:U={text:as(l.selectedTools),tone:"muted"}:U={text:g.connectionId?"The selected account is no longer connected.":`The primary ${g.connectionMode} account needs reconnecting.`,tone:"warning"}:U={text:"Select an account.",tone:"warning"}:U={text:`Connect ${o$1.name} to use its tools.`,tone:"warning"}:U={text:"Disabled by project policy.",tone:"warning"},jsxs(Fragment,{children:[jsxs("div",{className:"fk:m-1.5 fk:flex fk:flex-wrap fk:items-center fk:justify-between fk:gap-x-3 fk:gap-y-2 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:min-w-0 fk:flex-1 fk:items-center fk:gap-2.5",children:[jsx("img",{src:o$1.logoUrl,alt:"",className:"fk:size-5 fk:shrink-0 fk:rounded fk:corner-squircle fk:self-start"}),jsxs("div",{className:"fk:min-w-0",children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:o$1.name}),jsx("p",{className:U.tone==="warning"?"fk:truncate fk:text-xs fk:text-warning":"fk:truncate fk:text-xs fk:text-muted-foreground",children:U.text}),l.connectionMode==="personal"&&l.enabled?jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Using your account makes this automation personal."}):null]})]}),jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-1.5",children:[c?jsxs(Fragment,{children:[jsx(In,{ariaLabel:`${o$1.name} account`,disabled:y,plugin:o$1,scopes:p,value:g,onChange:w=>{w.connectionMode===l.connectionMode&&w.connectionId===l.connectionId||k(F(w));}}),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(b$2,{disabled:y||!r||!N,size:"sm",type:"button",variant:"outline",children:[S?"All tools":l.selectedTools.length?`Tools (${l.selectedTools.length})`:"Select tools",jsx(ChevronDownIcon,{className:"fk:ml-1 fk:size-4"})]})}),jsxs(h,{align:"end",className:"fk:max-h-80 fk:w-80 fk:overflow-y-auto",children:[jsxs(j,{className:"fk:items-start",onSelect:w=>{w.preventDefault(),S?h$1(T.map(X=>X.key)):P();},children:[jsx(CheckIcon,{className:S?"fk:mt-0.5 fk:size-4":"fk:mt-0.5 fk:size-4 fk:opacity-0"}),jsxs("span",{className:"fk:min-w-0",children:[jsx("span",{className:"fk:block",children:"All tools (recommended)"}),jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Includes tools added later. Uncheck to pick specific ones."})]})]}),jsx(o,{}),T.map(({key:w,entry:X})=>{let j$1=S||l.selectedTools.includes(w);return jsxs(j,{className:"fk:items-start",onSelect:ke=>{ke.preventDefault();let q=S?T.map(pe=>pe.key):l.selectedTools;h$1(j$1?q.filter(pe=>pe!==w):[...q,w]);},children:[jsx(CheckIcon,{className:j$1?"fk:mt-0.5 fk:size-4":"fk:mt-0.5 fk:size-4 fk:opacity-0"}),jsxs("span",{className:"fk:min-w-0",children:[jsx("span",{className:"fk:block",children:X.name}),X.description?jsx("span",{className:"fk:line-clamp-2 fk:text-xs fk:text-muted-foreground",children:X.description}):null]})]},w)}),N&&T.length===0?jsx(j,{disabled:true,children:"This account exposes no tools."}):null]})]})]}):jsx(b$7,{busy:B||n,canManage:t,plugin:o$1,onConnect:w=>{$(w);}}),jsx(b$2,{"aria-label":`Remove ${o$1.name} from automation`,disabled:n,size:"icon",type:"button",variant:"ghost",onClick:d,children:jsx(Trash2Icon,{className:"fk:size-4"})})]})]}),jsx(v,{})]})}function is({disabled:t,plugins:n,onAdd:o}){let[i,l]=useState(false),k=useRef(null);return jsxs(t$2,{open:i,onOpenChange:l,children:[jsx(u$1,{asChild:true,children:jsxs("button",{className:"fk:m-1.5 fk:flex fk:w-[calc(100%-0.75rem)] fk:cursor-pointer fk:items-center fk:gap-2.5 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:text-left fk:text-sm fk:text-muted-foreground fk:hover:bg-muted fk:hover:text-foreground disabled:fk:cursor-not-allowed disabled:fk:opacity-50 fk:corner-squircle",disabled:t||n.length===0,type:"button",children:[jsx(PlusIcon,{className:"fk:size-5"}),"Plugin tools"]})}),jsx(v$2,{align:"start",className:"fk:w-72 fk:p-0",onOpenAutoFocus:d=>{d.preventDefault(),k.current?.focus({preventScroll:true});},children:jsxs(m,{filter:Cn,children:[jsx(o$1,{placeholder:"Search plugins\u2026",ref:k}),jsxs(p,{children:[jsx(q$1,{children:"No plugins found."}),jsx(r$1,{children:n.map(d=>jsxs(t$3,{value:d.id,keywords:[d.name],onSelect:()=>{o(d),l(false);},children:[jsx("img",{src:d.logoUrl,alt:"",className:"fk:size-5 fk:shrink-0 fk:rounded fk:corner-squircle"}),jsx("span",{className:"fk:truncate",children:d.name}),d.connections.some(p=>p.status==="connected")?null:jsx("span",{className:"fk:ml-auto fk:text-xs fk:text-muted-foreground",children:"Not connected"})]},d.id))})]})]})})]})}function Uo({projectId:t,value:n,disabled:o,onChange:i}){let{data:l,error:k}=De(`/api/flexkit/${t}/plugins`,f),d=(l?.plugins??[]).filter(g=>g.capabilities.agentTools),p=new Map(d.map(g=>[g.id,g])),c=d.filter(g=>g.enabled&&!n.some(r=>r.pluginId===g.id));return jsxs(Fragment,{children:[n.map(g=>{let r=p.get(g.pluginId);return r?jsx(ss,{disabled:o,canManage:l?.canManage??false,plugin:r,projectId:t,usage:g,onChange:N=>i(n.map(I=>I.pluginId===r.id?N:I)),onRemove:()=>i(n.filter(N=>N.pluginId!==r.id))},g.pluginId):null}),k?jsx("p",{className:"fk:mx-3 fk:text-xs fk:text-warning",role:"alert",children:"Unable to load plugins. Your existing selections are preserved."}):null,jsx(is,{disabled:o||!l,plugins:c,onAdd:g=>i([...n,ts(g)])})]})}var Kt=["slack","teams"],Wo=["create","update","delete"],sa="0 * * * *",gs="0 9 * * *",vs="0 9 * * 1",hs="0 9 1 * *",bs=[{label:"Monday",value:1},{label:"Tuesday",value:2},{label:"Wednesday",value:3},{label:"Thursday",value:4},{label:"Friday",value:5},{label:"Saturday",value:6},{label:"Sunday",value:0}],ys=Array.from({length:24},(t,n)=>({label:`${n.toString().padStart(2,"0")}:00`,value:n}));function xs(t){return !t.instructions&&!t.model&&!t.name&&!t.plugins&&!t.space&&Object.keys(t.toolErrors).length===0&&Object.keys(t.triggerErrors).length===0}function Go(t){return t.some(n=>n.enabled&&n.connectionMode==="personal")}function Xe({id:t,message:n}){return n?jsxs("p",{className:"fk:flex fk:items-start fk:text-sm fk:text-warning fk:gap-1",id:t,role:"alert",children:[jsx(TriangleAlertIcon,{className:"fk:size-4 fk:shrink-0 fk:mt-0.5"}),n]}):null}function Zt(){return crypto.randomUUID()}function Ns(t){return (t?.triggers??[]).map(n=>({...n,key:n.id??Zt()}))}function Ts(t){return t.connected&&t.connectionLabel?`While your local runtime (${t.connectionLabel}) is connected, manually running this automation uses its custom tools so you can test them.`:t.connected?"While `flexkit dev` is connected, manually running this automation uses the custom tools from your local runtime so you can test them.":t.origin?`Using ${t.origin}`:t.tools.length===0?"":"Registered in this project"}function Cs(){return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}function ws(){let t=crypto.getRandomValues(new Uint8Array(24));return Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}function Ss(t){if(t===sa)return {kind:"hourly"};let n=/^0 (\d{1,2}) \* \* \*$/.exec(t);if(n)return {hour:Number(n[1]),kind:"daily"};let o=/^0 (\d{1,2}) \* \* ([0-6])$/.exec(t);return o?{day:Number(o[2]),hour:Number(o[1]),kind:"weekly"}:{kind:"custom"}}function ia(t,n,o){try{let i=CronExpressionParser.parse(t,{tz:n});return Array.from({length:o},()=>i.next().toDate())}catch{return []}}function la(t,n){return new Intl.DateTimeFormat("en-US",{day:"numeric",hour:"numeric",minute:"2-digit",month:"short",timeZone:n,weekday:"short"}).format(t)}function ra(t,n){let o=t.trim();if(!o)return "Cron expression is required";let i=o.split(/\s+/).length;if(i<5||i>6)return `Expected 5 fields (min hour day month weekday), got ${i.toString()}`;try{return CronExpressionParser.parse(o,{tz:n}),null}catch{return "Invalid cron expression"}}function As(t,n,o){let i=t.filter(k=>!k.deprecated);if(n!=="edit"||!o)return i;let l=c$3(t,o);return l?.deprecated?[l,...i.filter(k=>b$6(k)!==o)]:l?i:[{deprecated:true,effort:null,efforts:[],id:o,kind:"model",name:o},...i]}function Mn(t){return `${t.teamId??""}:${t.id}`}function Is(t,n){let o={};for(let i of [...t,...n])o[Mn(i)]=i;return Object.values(o)}function Zo(t,n){return {...t,availableChannels:t.channels,channelsLoaded:!t.connected,enabled:t.connected&&n==="edit"&&t.enabled,loadingChannels:false}}function Ps(t,n){return {slack:Zo(t.providers.slack,n),teams:Zo(t.providers.teams,n)}}function Ms({channels:t,disabled:n,loading:o,onChange:i,onRefresh:l,provider:k,value:d}){let[p,c]=useState(false),[g,r]=useState(""),N=useRef(null),I=new Set(d.map(h=>h.id)),T=k==="slack"?"Slack":"Teams",_=t.filter(h=>h.name.toLowerCase().includes(g.toLowerCase()));useEffect(()=>{if(!p)return;function h(F){let{target:C}=F;!(C instanceof Node)||N.current?.contains(C)||c(false);}function P(F){F.key==="Escape"&&c(false);}return document.addEventListener("pointerdown",h),document.addEventListener("keydown",P),()=>{document.removeEventListener("pointerdown",h),document.removeEventListener("keydown",P);}},[p]);function S(h){if(I.has(h.id)){i(d.filter(P=>P.id!==h.id));return}i([...d,h]);}function y(h){i(d.filter(P=>P.id!==h));}return jsxs("div",{className:"fk:relative",ref:N,children:[jsxs(b$2,{"aria-expanded":p,className:"fk:h-auto fk:min-h-8 fk:w-full fk:max-w-100 fk:justify-between fk:bg-muted/60 fk:px-3 fk:py-1 hover:fk:border-secondary fk:dark:bg-muted/30",disabled:n,role:"combobox",type:"button",variant:"outline",onClick:()=>c(h=>!h),children:[jsx("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:gap-1",children:d.length===0?jsx("span",{className:"fk:text-muted-foreground",children:o?`Loading ${T} channels...`:`Select ${T} channels`}):d.map(h=>jsxs(b$1,{className:"fk:rounded-sm fk:bg-accent fk:text-xs fk:corner-squircle",variant:"secondary",onClick:P=>{P.stopPropagation(),y(h.id);},children:[h.name,jsx(XIcon,{className:"fk:ml-1 fk:size-3 fk:cursor-pointer"})]},Mn(h)))}),jsx(ChevronsUpDownIcon,{className:"fk:size-4 fk:shrink-0 fk:opacity-50"})]}),p?jsxs("div",{className:"fk:absolute fk:z-50 fk:mt-1 fk:w-full fk:max-w-100 fk:rounded-md fk:border fk:bg-popover fk:p-0 fk:text-popover-foreground fk:shadow-md fk:corner-squircle",children:[jsx("div",{className:"fk:border-b fk:p-2",children:jsx(s,{className:"fk:h-8",placeholder:`Search ${T} channels...`,value:g,onChange:h=>r(h.target.value)})}),jsx("div",{className:"fk:max-h-56 fk:overflow-auto fk:p-1",children:_.length>0?_.map(h=>jsxs(b$2,{className:"fk:h-auto fk:w-full fk:justify-start fk:rounded-sm fk:px-2 fk:py-1.5 fk:font-normal fk:corner-squircle",type:"button",variant:"ghost",onClick:()=>S(h),children:[jsx(CheckIcon,{className:`fk:mr-2 fk:size-4 ${I.has(h.id)?"fk:opacity-100":"fk:opacity-0"}`}),h.name]},Mn(h))):jsx("div",{className:"fk:px-2 fk:py-6 fk:text-center fk:text-sm fk:text-muted-foreground",children:o?"Loading channels...":"No channels found."})}),jsx("div",{className:"fk:border-t fk:border-border fk:p-2",children:jsx(b$2,{className:"fk:h-8 fk:w-full fk:justify-start fk:text-xs",disabled:o,type:"button",variant:"ghost",onClick:l,children:o?jsxs(Fragment,{children:[jsx(LoaderCircleIcon,{className:"fk:mr-2 fk:size-3 fk:animate-spin"}),"Refreshing channels..."]}):jsxs(Fragment,{children:[jsx(RefreshCwIcon,{className:"fk:mr-2 fk:size-3"}),"Refresh channels"]})})})]}):null]})}function Wt({cron:t,timezone:n}){let[o]=ia(t,n,1);return o?jsxs("span",{className:"fk:text-sm fk:text-muted-foreground",children:["Next run ",la(o,n)]}):null}function Yo({onChange:t,value:n}){return jsxs(a$2,{value:n.toString(),onValueChange:o=>t(Number(o)),children:[jsx(d$3,{"aria-label":"Hour",className:"fk:h-7 fk:w-fit fk:gap-1 fk:border-transparent fk:bg-background/90 fk:px-2 fk:py-0 fk:text-sm fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$4,{})}),jsx(e$6,{children:ys.map(o=>jsx(g$5,{value:o.value.toString(),children:o.label},o.value))})]})}function Rs({onChange:t,value:n}){return jsxs(a$2,{value:n.toString(),onValueChange:o=>t(Number(o)),children:[jsx(d$3,{"aria-label":"Day of week",className:"fk:h-7 fk:w-fit fk:gap-1 fk:border-transparent fk:bg-background/90 fk:px-2 fk:py-0 fk:text-sm fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$4,{})}),jsx(e$6,{children:bs.map(o=>jsx(g$5,{value:o.value.toString(),children:o.label},o.value))})]})}function Es({onChange:t,timezone:n,value:o}){let[i,l]=useState(false),k=useRef(null),d=ra(o,n),p=d?[]:ia(o,n,3);return useEffect(()=>{if(!i)return;function c(r){let{target:N}=r;!(N instanceof Node)||k.current?.contains(N)||l(false);}function g(r){r.key==="Escape"&&l(false);}return document.addEventListener("pointerdown",c),document.addEventListener("keydown",g),()=>{document.removeEventListener("pointerdown",c),document.removeEventListener("keydown",g);}},[i]),jsxs("div",{className:"fk:relative",ref:k,children:[jsxs(b$2,{className:"fk:h-auto fk:gap-1.5 fk:bg-background/90 fk:px-2 fk:py-1 fk:font-mono fk:font-normal fk:shadow-sm hover:fk:bg-accent",type:"button",variant:"ghost",onClick:()=>l(c=>!c),children:[o||"Set cron",jsx(ChevronDownIcon,{className:"fk:size-3.5 fk:opacity-50"})]}),i?jsxs("div",{className:"fk:absolute fk:z-50 fk:mt-1 fk:w-72 fk:rounded-md fk:border fk:bg-popover fk:p-3 fk:text-popover-foreground fk:shadow-md fk:corner-squircle",children:[jsxs("div",{className:"fk:mb-2 fk:text-xs fk:text-muted-foreground",children:["Cron expression (",n,")"]}),jsx(s,{className:`fk:h-8 fk:font-mono ${d?"fk:border-destructive focus-visible:fk:ring-destructive":""}`,value:o,onChange:c=>t(c.target.value)}),d?jsx("p",{className:"fk:mt-2 fk:text-xs fk:text-destructive",children:d}):jsxs("div",{className:"fk:mt-2 fk:space-y-0.5 fk:text-xs fk:text-muted-foreground",children:[jsx("p",{className:"fk:mb-1",children:"5 fields: min hour day month weekday"}),p.map(c=>jsx("p",{children:la(c,n)},c.toISOString()))]})]}):null]})}function Ds({onChange:t,trigger:n}){let o=Ss(n.cron);return o.kind==="hourly"?jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Every hour"}),jsx(Wt,{cron:n.cron,timezone:n.timezone})]}):o.kind==="daily"?jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Every day at"}),jsx(Yo,{value:o.hour,onChange:i=>t({...n,cron:`0 ${i.toString()} * * *`})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(Wt,{cron:n.cron,timezone:n.timezone})]}):o.kind==="weekly"?jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Every week on"}),jsx(Rs,{value:o.day,onChange:i=>t({...n,cron:`0 ${o.hour.toString()} * * ${i.toString()}`})}),jsx("span",{children:"at"}),jsx(Yo,{value:o.hour,onChange:i=>t({...n,cron:`0 ${i.toString()} * * ${o.day.toString()}`})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(Wt,{cron:n.cron,timezone:n.timezone})]}):jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Custom schedule"}),jsx(Es,{timezone:n.timezone,value:n.cron,onChange:i=>t({...n,cron:i})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(Wt,{cron:n.cron,timezone:n.timezone})]})}function Ls({onChange:t,projectId:n,trigger:o}){let[i,l]=useState(false),[k,d]=useState(false),p=o.url??c$5(n,o.token);function c$1(g,r){navigator.clipboard.writeText(g).then(()=>{r(true),window.setTimeout(()=>r(false),1500);});}return jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Webhook triggered"}),jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsxs(b$2,{className:"fk:h-auto fk:min-w-0 fk:max-w-60 fk:gap-1.5 fk:bg-background/90 fk:px-2 fk:py-1 fk:text-xs fk:font-normal fk:shadow-sm hover:fk:bg-accent",type:"button",variant:"ghost",onClick:()=>c$1(p,l),children:[jsx("span",{className:"fk:truncate",children:p}),i?jsx(CheckIcon,{className:"fk:size-3.5 fk:shrink-0"}):jsx(CopyIcon,{className:"fk:size-3.5 fk:shrink-0 fk:opacity-60"})]})}),jsx(e$1,{className:"fk:max-w-96 fk:break-all",children:p})]}),o.secret?jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>c$1(`Bearer ${o.secret??""}`,d),children:[k?jsx(CheckIcon,{className:"fk:size-3.5"}):jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Copy auth header"]}):jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>t({...o,secret:ws()}),children:[jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Generate auth header"]})]})}function zs({entities:t,onChange:n,trigger:o}){function i(d){let p=o.events.includes(d)?o.events.filter(c=>c!==d):[...o.events,d];n({...o,events:Wo.filter(c=>p.includes(c))});}function l(d){let p=o.entities.includes(d)?o.entities.filter(c=>c!==d):[...o.entities,d];n({...o,entities:p});}let k=o.entities.length>0?o.entities.join(", "):"All entities";return jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"On"}),jsx("div",{className:"fk:flex fk:items-center fk:gap-1",children:Wo.map(d=>jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs fk:capitalize",size:"sm",type:"button",variant:o.events.includes(d)?"secondary":"ghost",onClick:()=>i(d),children:[o.events.includes(d)?jsx(CheckIcon,{className:"fk:size-3"}):null,d]},d))}),jsx("span",{children:"of"}),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(b$2,{className:"fk:h-7 fk:max-w-60 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",children:[jsx("span",{className:"fk:truncate",children:k}),jsx(ChevronDownIcon,{className:"fk:size-3.5 fk:opacity-50"})]})}),jsx(h,{align:"start",className:"fk:max-h-64 fk:w-56 fk:overflow-auto",children:t.length===0?jsx(j,{disabled:true,children:"No entities found in the project schema"}):t.map(d=>jsx(k$1,{checked:o.entities.includes(d),onCheckedChange:()=>l(d),onSelect:p=>p.preventDefault(),children:d},d))})]})]})}function Fs({entities:t,errors:n,onChange:o,projectId:i,triggers:l}){let k=l.some(r=>r.type==="webhook");function d(r){o([...l,r]);}function p(r){d({cron:r,key:Zt(),timezone:Cs(),type:"schedule"});}function c(r){o(l.map(N=>N.key===r.key?r:N));}function g(r){o(l.filter(N=>N.key!==r));}return jsxs("div",{className:"fk:rounded-lg fk:border fk:bg-muted/60 fk:dark:bg-muted/30 fk:corner-squircle",children:[l.map(r=>jsxs(Fragment$1,{children:[jsxs("div",{className:"fk:group fk:rounded-md fk:m-1.5 fk:p-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-3",children:[r.type==="schedule"?jsx(ClockIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,r.type==="webhook"?jsx(WebhookIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,r.type==="entity"?jsx(DatabaseZapIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,r.type==="schedule"?jsx(Ds,{trigger:r,onChange:c}):null,r.type==="webhook"?jsx(Ls,{projectId:i,trigger:r,onChange:c}):null,r.type==="entity"?jsx(zs,{entities:t,trigger:r,onChange:c}):null,jsx(b$2,{"aria-label":"Remove trigger",className:"fk:opacity-0 fk:group-hover:opacity-100",size:"icon",type:"button",variant:"ghost",onClick:()=>g(r.key),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})})]}),n[r.key]?jsx("div",{className:"fk:mt-1 fk:pl-7",children:jsx(Xe,{message:n[r.key]})}):null]},r.key),jsx(v,{className:"fk:h-4"})]},r.key)),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(b$2,{className:`fk:h-auto fk:w-full fk:justify-start fk:gap-3 fk:px-3 fk:py-3 fk:text-muted-foreground hover:fk:bg-muted hover:fk:text-foreground ${l.length===0?"fk:rounded-lg fk:corner-squircle":"fk:rounded-none fk:rounded-b-lg fk:corner-squircle"}`,type:"button",variant:"ghost",children:[jsx(PlusIcon,{className:"fk:size-4"}),"Add Trigger"]})}),jsxs(h,{align:"start",className:"fk:w-56",children:[jsxs(q,{children:[jsxs(r,{children:[jsx(ClockIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Scheduled"]}),jsxs(s$1,{children:[jsx(j,{onClick:()=>p(sa),children:"Hourly"}),jsx(j,{onClick:()=>p(gs),children:"Daily"}),jsx(j,{onClick:()=>p(vs),children:"Weekly"}),jsx(j,{onClick:()=>p(hs),children:"Custom (cron)"})]})]}),jsxs(j,{disabled:k,onClick:()=>d({key:Zt(),secret:null,token:crypto.randomUUID(),type:"webhook"}),children:[jsx(WebhookIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Webhook Triggered"]}),jsxs(j,{onClick:()=>d({entities:[],events:["create"],key:Zt(),type:"entity"}),children:[jsx(DatabaseZapIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Entity Events"]})]})]})]})}function Bs(){return jsxs("svg",{"aria-label":"Slack",className:"fk:mt-1 fk:size-3.5 fk:text-muted-foreground",fill:"currentColor",role:"img",viewBox:"0 0 127 127",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M27.2 80c0 7.3-5.9 13.2-13.2 13.2C6.7 93.2.8 87.3.8 80c0-7.3 5.9-13.2 13.2-13.2h13.2V80zm6.6 0c0-7.3 5.9-13.2 13.2-13.2 7.3 0 13.2 5.9 13.2 13.2v33c0 7.3-5.9 13.2-13.2 13.2-7.3 0-13.2-5.9-13.2-13.2V80z"}),jsx("path",{d:"M47 27c-7.3 0-13.2-5.9-13.2-13.2C33.8 6.5 39.7.6 47 .6c7.3 0 13.2 5.9 13.2 13.2V27H47zm0 6.7c7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2H13.9C6.6 60.1.7 54.2.7 46.9c0-7.3 5.9-13.2 13.2-13.2H47z"}),jsx("path",{d:"M99.9 46.9c0-7.3 5.9-13.2 13.2-13.2 7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2H99.9V46.9zm-6.6 0c0 7.3-5.9 13.2-13.2 13.2-7.3 0-13.2-5.9-13.2-13.2V13.8C66.9 6.5 72.8.6 80.1.6c7.3 0 13.2 5.9 13.2 13.2v33.1z"}),jsx("path",{d:"M80.1 99.8c7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2-7.3 0-13.2-5.9-13.2-13.2V99.8h13.2zm0-6.6c-7.3 0-13.2-5.9-13.2-13.2 0-7.3 5.9-13.2 13.2-13.2h33.1c7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2H80.1z"})]})}function $s(){return jsxs("svg",{"aria-label":"Microsoft Teams",className:"fk:mt-1 fk:size-3.5 fk:text-muted-foreground",fill:"currentColor",role:"img",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{clipRule:"evenodd",d:"M15.5 5A3 3 0 0 1 14 7.599V7.5a2 2 0 0 0-2-2H9.541A3 3 0 1 1 15.5 5Zm6.25 1a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm-3.294 11.732A3.25 3.25 0 0 0 23 14.75v-4.361a.889.889 0 0 0-.889-.889h-3.879c.17.294.268.636.268 1V17c0 .248-.015.492-.044.732ZM8.169 19.5A5 5 0 0 0 17.5 17v-6.5a1 1 0 0 0-1-1H14v8a2 2 0 0 1-2 2H8.169Z",fillRule:"evenodd"}),jsx("path",{clipRule:"evenodd",d:"M1 17.5v-10a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1Zm6.75-6.75H9.5v-1.5h-5v1.5h1.75v4.75h1.5v-4.75Z",fillRule:"evenodd"})]})}function Yt(t,n,o){return t.visibility==="space"?n==="space"&&o!==null&&t.spaceId===o:t.visibility==="personal"?n==="personal":true}function _s(t,n,o){return t.visibility==="space"&&!Yt(t,n,o)}function js(t,n){let o=t.spaceId?n[t.spaceId]:void 0;return o?`Only available on ${o} automations`:"Only available on space automations"}async function Vs(t,n){try{return (await f(g(t).skill(n))).skill}catch(o){if(o instanceof e$7&&o.status===404)return null;throw o}}var ca=[{label:"Results that need attention (recommended)",value:"when_flagged"},{label:"Every finished run",value:"always"},{label:"Failures only",value:"failures"},{label:"Never",value:"never"}];function Hs(t){return ca.some(n=>n.value===t)}function Rn({api:t,automation:n,mode:o,onSaved:i,projectId:l}){let[k,d]=useState((n?.toolConfigs??[]).filter(a=>!["slack","teams"].includes(a.pluginId))),[p,c]=useState(n?.name??""),[g$1,r]=useState(n?.instructions??""),[N,I]=useState(n?.enabled??false),[T,_]=useState(null),[S,y]=useState(null),[h,P]=useState(n?.mutationPolicy??"require_approval"),[F,C]=useState(n?.toolAllowRules),[B,M]=useState(n?.notifyRule??"when_flagged"),[$,U]=useState(n?.notifyCreator??true),[w,X]=useState(n?.subscriberIds??[]),[j,ke]=useState(n?.visibility??"project"),[q,pe]=useState(n?.spaceId??null),[ge,Fe]=useState(n?.skillIds??[]),[re,ut]=useState(n?.customToolNames??[]),[Ce,Le]=useState(()=>Ns(n)),[Be,Ke]=useState(false),[We,$e]=useState(""),[R,x]=useState({instructions:false,name:false}),[E,ce]=useState(null),[It,dt]=useState(null),{mutate:zn}=useSWRConfig(),[mt,Fn]=useState(()=>({slack:n?.toolConfigs?.find(a=>a.pluginId==="slack")?.connectionId??null,teams:n?.toolConfigs?.find(a=>a.pluginId==="teams")?.connectionId??null})),Pt=useRef({}),Bn=useRef(null),{data:Ge,error:xa}=De(`/api/flexkit/${l}/plugins`,f),$n=!!(Ge||xa),Na=g(l).tools(n?.id),{data:_e,error:Ta}=De(Na,f),{data:Ca}=De(g(l).entities,f),{data:sn}=De(g(l).spaces,f),{data:Mt}=De(j==="personal"?null:g(l).members(j==="space"?q:null),f),{data:Z$1}=De(g(l).skills({limit:100}),f),[,wa]=h$2(),Y=b(),Sa=wa.user?.spaces??[],_n=(sn?.spaces??[]).filter(a=>Sa.includes(a.code)),Rt=_e?.tools.models,jn=useMemo(()=>{let a=n?.modelId??"";return a?f$4(a,Rt??[])??{effort:null,modelKey:a}:null},[n?.modelId,Rt]),ln=T??jn?.modelKey??"",kt=useMemo(()=>As(Rt??[],o,ln),[o,Rt,ln]),Et=ln||(kt[0]?b$6(kt[0]):""),Vn=c$3(kt,Et),rn=d$2(Vn,S??(T===null?jn?.effort??null:null)),Hn=e$4(Vn),cn=Et?g$4({effort:rn,modelKey:Et},kt):"",qn=useMemo(()=>new Set((Z$1?.skills??[]).map(a=>a.id)),[Z$1?.skills]),Ze=useMemo(()=>Z$1?ge.filter(a=>!qn.has(a)).sort():[],[qn,ge,Z$1]),Aa=Ze.length>0?[l,"attached-skills",...Ze]:null,{data:Dt}=De(Aa,()=>Promise.all(Ze.map(a=>Vs(l,a)))),Ye=useMemo(()=>{let a={};for(let m of Z$1?.skills??[])a[m.id]=m;for(let m of Dt??[])m&&(a[m.id]=m);return a},[Dt,Z$1?.skills]),fn=useMemo(()=>{let a=(Z$1?.skills??[]).filter(b=>Yt(b,j,q)),m=new Set(a.map(b=>b.id));return [...ge.map(b=>Ye[b]).filter(b=>!b||m.has(b.id)?false:Yt(b,j,q)),...a]},[ge,Ye,Z$1?.skills,q,j]),Ia=useMemo(()=>{let a={};for(let m of sn?.spaces??[])a[m.id]=m.label;return a},[sn?.spaces]),un=useMemo(()=>(Z$1?.skills??[]).filter(a=>_s(a,j,q)),[Z$1?.skills,q,j]),ze=_e?.tools.customTools,dn=useMemo(()=>{let a={};for(let m of ze?.tools??[])a[m.name]=m;return a},[ze?.tools]),mn=useMemo(()=>{let a=ze?.tools??[],m=new Set(a.map(b=>b.name));return [...re.filter(b=>!m.has(b)).map(b=>dn[b]??{description:"",name:b}),...a]},[re,dn,ze?.tools]),Un=ze?Ts(ze):"";useEffect(()=>{if(!Z$1)return;let a=Ze.length>0&&Dt===void 0,m=new Set(a?[]:Ze.filter(v=>!Ye[v]));Fe(v=>{let b=v.filter(L=>{if(m.has(L))return false;let Me=Ye[L];return Me?Yt(Me,j,q):true});return b.length===v.length?v:b});},[Dt,Ye,Z$1,q,Ze,j]);let Qe=Go(k),ne=useMemo(()=>{let a={};for(let v of Ce){if(v.type==="schedule"){let b=ra(v.cron,v.timezone);b&&(a[v.key]=b);}v.type==="entity"&&v.events.length===0&&(a[v.key]="Select at least one event (create, update or delete)");}let m={};for(let v of Kt){let b=E?.[v];b?.enabled&&b.channels.length===0&&(m[v]=`Select at least one ${v==="slack"?"Slack":"Teams"} channel or remove the tool`);}return {instructions:g$1.trim()?"":"Instructions are required",model:cn?"":"Select a model",name:p.trim()?"":"Name is required",plugins:Qe&&j!=="personal"?"Personal plugin connections can only be used by a personal automation.":"",space:j==="space"&&!q?"Select a space":"",toolErrors:m,triggerErrors:a}},[cn,g$1,p,Qe,q,E,Ce,j]),kn=xs(ne),Lt=R.name&&!!ne.name,pt=R.instructions&&!!ne.instructions;useEffect(()=>{let a=`${n?.id??""}:${o}`;!_e?.tools||Bn.current===a||(Bn.current=a,ce(Ps(_e.tools,o)));},[n?.id,o,_e?.tools]);let zt=useMemo(()=>({slack:Ge?.plugins.find(a=>a.id==="slack")??null,teams:Ge?.plugins.find(a=>a.id==="teams")??null}),[Ge]),pn=useMemo(()=>{let a=m=>{let v=zt[m];return v?An(v,{connectionMode:"project",connectionId:mt[m]})?.id??null:null};return {slack:a("slack"),teams:a("teams")}},[mt,zt]),gn=useCallback(async(a,m)=>{Pt.current[a]=m,ce(v=>v&&{...v,[a]:{...v[a],channelsLoadError:void 0,loadingChannels:true}});try{let v=await t.listChannels(a,m);if(Pt.current[a]!==m)return;let b=v.success?void 0:v.errorMessage??`Failed to load ${a==="slack"?"Slack":"Teams"} channels.`;ce(L=>L&&{...L,[a]:{...L[a],availableChannels:Is(L[a].channels,v.channels),channelsLoadError:b,channelsLoaded:!0,loadingChannels:!1}});}catch(v){if(Pt.current[a]!==m)return;let b=v instanceof Error?v.message:"Failed to load integration channels.";ce(L=>L&&{...L,[a]:{...L[a],channelsLoadError:b,channelsLoaded:true,loadingChannels:false}});}},[t]);useEffect(()=>{if(!(!E||!Y||!$n))for(let a of Kt){let m=E[a];m.connected&&!m.channelsLoaded&&!m.loadingChannels&&gn(a,pn[a]);}},[Y,gn,$n,pn,E]);async function Pa(a){let m=zt[a];if(m){dt(a);try{await a$3(t,m.id,"project");let b=(await zn(`/api/flexkit/${l}/plugins`))?.plugins.find(L=>L.id===m.id)?.connections.find(L=>L.scope==="project"&&L.isPrimary&&L.status==="connected");Fn(L=>({...L,[a]:null})),On(a,{connected:!0,enabled:!0,workspaceName:b?.displayName??null});}catch(v){oa.error(v instanceof Error?v.message:`Unable to connect ${m.name}.`);}finally{dt(null);}}}function Ft(a,m){ce(v=>v&&{...v,[a]:{...v[a],...m}});}function Ma(a,m){mt[a]!==m&&(Fn(v=>({...v,[a]:m})),On(a));}function On(a,m={}){Pt.current[a]=void 0,Ft(a,{...m,availableChannels:[],channels:[],channelsLoaded:false,channelsLoadError:void 0,loadingChannels:false});}function Ra(a){Ft(a,{channels:[],enabled:false});}function Xn(a,m){Fe(v=>m?v.includes(a)?v:[...v,a]:v.filter(b=>b!==a));}function Jn(a,m){ut(v=>m?v.includes(a)?v:[...v,a]:v.filter(b=>b!==a));}async function Ea(a){if(a.preventDefault(),!Y)return;if(!kn){x({instructions:true,name:true});return}Ke(true),$e("");let m=Kt.map(b=>{let L=E?.[b]??_e?.tools.providers[b];return {channels:L?.channels??[],enabled:L?.enabled??false,pluginId:b,connectionMode:"project",connectionId:mt[b],selectedTools:[],deliveryEnabled:L?.enabled??false}}),v={customToolNames:re,enabled:N,instructions:g$1,modelId:cn,mutationPolicy:h,name:p,notifyCreator:$,notifyRule:B,skillIds:ge,subscriberIds:j==="personal"?[]:w,...F!==void 0?{toolAllowRules:F}:{},spaceId:j==="space"?q:null,toolConfigs:[...m,...k],triggers:Ce.map(({key:b,...L})=>L),visibility:j};try{let b=o==="create"||!n?await t.createAutomation(v):await t.updateAutomation(n.id,v);if(!b.success){$e(Array.isArray(b.errorMessage)?b.errorMessage.join(", "):b.errorMessage);return}oa.success(o==="create"||!n?"Automation created.":"Automation saved."),i(b.automation);}catch(b){$e(b instanceof Error?b.message:"Failed to save automation.");}finally{Ke(false);}}return jsxs("form",{className:"fk:max-w-4xl fk:space-y-8 fk:px-1 fk:mx-auto",onSubmit:a=>{Ea(a);},children:[We?jsx("div",{className:"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:We}):null,jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",children:"Status"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-1",children:"Disabling an automation stops its schedules and ignores webhook calls and entity events"}),jsxs("div",{className:"fk:flex fk:h-10 fk:items-center fk:gap-2",children:[jsx(Z,{checked:N,id:"automation-enabled",onCheckedChange:I}),jsx(e$5,{className:"fk:font-normal",htmlFor:"automation-enabled",children:N?"Active":"Inactive"})]})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-name",children:"Name"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Identifying label for this automation"}),jsx(s,{"aria-describedby":Lt?"automation-name-error":void 0,"aria-invalid":Lt,className:Lt?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"automation-name",value:p,onBlur:()=>x(a=>({...a,name:true})),onChange:a=>c(a.target.value)}),Lt?jsx(Xe,{id:"automation-name-error",message:ne.name}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-visibility",children:"Visibility"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Who can see and manage this automation. Space automations are only visible to members of the selected space; personal automations are private to you."}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsxs(a$2,{value:j,onValueChange:a=>{Qe&&a!=="personal"||(ke(a==="space"||a==="personal"?a:"project"),a!=="space"&&pe(null));},children:[jsx(d$3,{"aria-label":"Visibility",className:"fk:w-fit",id:"automation-visibility",children:jsx(c$4,{})}),jsxs(e$6,{align:"start",children:[jsx(g$5,{disabled:Qe,value:"project",children:"Project"}),jsx(g$5,{disabled:Qe||_n.length===0,value:"space",children:"Space"}),jsx(g$5,{value:"personal",children:"Personal"})]})]}),j==="space"?jsxs(a$2,{value:q??"",onValueChange:a=>{pe(a||null);},children:[jsx(d$3,{"aria-label":"Space",className:"fk:w-fit",children:jsx(c$4,{placeholder:"Select a space"})}),jsx(e$6,{align:"start",children:_n.map(a=>jsx(g$5,{value:a.id,children:a.label},a.id))})]}):null]}),Qe?jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"This automation uses a personal plugin connection, so project and space visibility are unavailable."}):null,ne.plugins?jsx(Xe,{message:ne.plugins}):null,j==="space"&&ne.space?jsx(Xe,{message:ne.space}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",children:"Triggers"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"When this automation should run. Schedules run in your timezone; webhooks run when their URL is called."}),jsx(Fs,{entities:Ca?.entities??[],errors:ne.triggerErrors,projectId:l,triggers:Ce,onChange:Le})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-instructions",children:"Agent instructions"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Natural-language instructions the agent follows on every run. Be specific about entities, conditions, and the expected outcome."}),jsxs("div",{children:[jsx("div",{className:`fk:rounded-t-md fk:border-x fk:border-t fk:bg-muted/60 fk:ring-offset-background focus-within:fk:ring-2 focus-within:fk:ring-ring focus-within:fk:ring-offset-2 fk:dark:bg-muted/30 ${pt?"fk:border-destructive":"fk:border-input"} fk:corner-squircle`,children:jsx(ka$1,{"aria-describedby":pt?"automation-instructions-error":void 0,"aria-invalid":pt,className:"fk:flex fk:min-h-[160px] fk:max-h-[320px] fk:w-full fk:rounded-none fk:border-0 fk:bg-transparent fk:dark:bg-transparent fk:pb-11 fk:shadow-none focus-visible:fk:ring-0 focus-visible:fk:ring-offset-0 fk:mask-[linear-gradient(to_bottom,black_calc(100%-2.75rem),#0009_calc(100%-1.25rem),#0003_calc(100%-0.5rem),transparent)] fk:corner-squircle",id:"automation-instructions",placeholder:"Describe what the agent should do on each run, e.g. 'When a new Review is created, translate the text to English, run a sentiment analysis and store the result in the sentiment attribute...'",rows:8,value:g$1,onBlur:()=>x(a=>({...a,instructions:true})),onChange:a=>r(a.target.value)})}),jsx("div",{className:`fk:rounded-b-md fk:border-x fk:border-b fk:bg-muted/60 fk:dark:bg-muted/30 fk:px-2 fk:py-2 ${pt?"fk:border-destructive":"fk:border-input"} fk:corner-squircle`,children:jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-2",children:[jsxs(a$2,{value:Et,onValueChange:a=>{_(a),y(null);},children:[jsx(d$3,{"aria-label":"Model",className:"fk:w-fit fk:border-transparent fk:bg-background/90 fk:px-2.5 fk:py-0 fk:text-xs fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$4,{placeholder:"Select a model"})}),jsx(e$6,{align:"start",children:kt.map(a=>jsxs(g$5,{value:b$6(a),children:[a.name,a.deprecated?" (Legacy)":""]},b$6(a)))})]}),Hn.length>1&&rn?jsxs(a$2,{value:rn,onValueChange:y,children:[jsx(d$3,{"aria-label":"Reasoning effort",className:"fk:w-fit fk:border-transparent fk:bg-background/90 fk:px-2.5 fk:py-0 fk:text-xs fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$4,{placeholder:"Effort"})}),jsx(e$6,{align:"start",children:Hn.map(a=>jsx(g$5,{value:a.value,children:a.label},a.value))})]}):null]})})]}),pt?jsx(Xe,{id:"automation-instructions-error",message:ne.instructions}):null,_e&&ne.model?jsx(Xe,{message:ne.model}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-mutation-policy",children:"Mutations"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"How data changes proposed by the agent are handled. With approval required, runs pause until a project member reviews a before/after preview in the Approvals inbox."}),jsxs(a$2,{value:h,onValueChange:a=>{P(a==="auto_approve"?"auto_approve":"require_approval");},children:[jsx(d$3,{"aria-label":"Mutation policy",className:"fk:w-fit",id:"automation-mutation-policy",children:jsx(c$4,{})}),jsxs(e$6,{align:"start",children:[jsx(g$5,{value:"require_approval",children:"Require approval (recommended)"}),jsx(g$5,{value:"auto_approve",children:"Auto-approve"})]})]}),h==="auto_approve"&&k.some(a=>a.enabled)?jsxs("p",{className:"fk:flex fk:items-start fk:gap-1 fk:text-xs fk:text-warning",role:"status",children:[jsx(TriangleAlertIcon,{className:"fk:mt-px fk:size-3.5 fk:shrink-0"}),"Plugin tools will run without review. Content the agent reads, such as emails or documents, could lead it to act on your connected accounts."]}):null,h==="require_approval"&&F&&F.length>0?jsxs("div",{className:"fk:space-y-2",children:[jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Always allowed plugin tools (approved with \u201Calways allow\u201D from the Approvals inbox):"}),jsx("ul",{className:"fk:space-y-1",children:F.map(a=>jsxs("li",{className:"fk:flex fk:items-center fk:justify-between fk:gap-2 fk:rounded-md fk:border fk:border-border fk:px-2.5 fk:py-1.5 fk:text-xs fk:corner-squircle",children:[jsxs("code",{children:[a.pluginId,": ",a.tool]}),jsx(b$2,{"aria-label":`Remove allow rule for ${a.pluginId} ${a.tool}`,size:"sm",type:"button",variant:"ghost",onClick:()=>C(m=>(m??[]).filter(v=>v!==a)),children:"Remove"})]},`${a.pluginId}/${a.server}/${a.tool}`))})]}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-notify-rule",children:"Notifications"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Approval requests and run results appear in Activity in Studio. Failures are always reported unless set to Never."}),jsxs(a$2,{value:B,onValueChange:a=>{Hs(a)&&M(a);},children:[jsx(d$3,{"aria-label":"Notify about runs",className:"fk:w-fit",id:"automation-notify-rule",children:jsx(c$4,{})}),jsx(e$6,{align:"start",children:ca.map(a=>jsx(g$5,{value:a.value,children:a.label},a.value))})]}),jsxs("div",{className:"fk:flex fk:h-8 fk:items-center fk:gap-2",children:[jsx(Z,{checked:$,id:"automation-notify-creator",onCheckedChange:U}),jsx(e$5,{className:"fk:font-normal",htmlFor:"automation-notify-creator",children:"Notify the creator"})]}),j==="personal"?null:jsxs("div",{className:"fk:space-y-2",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-2",children:[jsxs("div",{children:[jsx("p",{className:"fk:text-sm",children:"Subscribers"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Members who also get its notifications. Only owners and developers receive approval requests."})]}),jsx(Jt,{disabled:!Y||!Mt,emptyText:"No members match.",items:(Mt?.members??[]).map(a=>({attached:w.includes(a.id),id:a.id,label:a.displayName})),searchPlaceholder:"Search members\u2026",triggerLabel:"Add",onToggle:(a,m)=>X(v=>m?[...new Set([...v,a])]:v.filter(b=>b!==a))})]}),w.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5",children:w.map(a=>{let v=Mt?.members.find(b=>b.id===a)?.displayName??(Mt?"No longer has access":"Loading\u2026");return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[v,jsx("button",{"aria-label":`Remove subscriber ${v}`,className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!Y,type:"button",onClick:()=>X(b=>b.filter(L=>L!==a)),children:jsx(XIcon,{className:"fk:size-3"})})]},a)})}):null]})]}),jsxs("div",{className:"fk:space-y-4",children:[jsxs("div",{children:[jsx(e$5,{className:"fk:text-sm fk:font-medium",children:"Tools"}),jsx("p",{className:"fk:mb-3 fk:text-xs fk:text-muted-foreground",children:"Configure additional destinations and built-in capabilities for this automation."})]}),jsxs("div",{className:"fk:rounded-lg fk:border fk:bg-muted/60 fk:dark:bg-muted/30 fk:corner-squircle",children:[jsx("div",{className:"fk:rounded-t-lg fk:corner-squircle",children:jsxs("div",{className:"fk:m-1.5 fk:flex fk:items-start fk:justify-between fk:gap-3 fk:rounded-md fk:p-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:gap-3 fk:pb-0.5",children:[jsx(BrainIcon,{className:"fk:mt-1 fk:size-3.5 fk:text-muted-foreground"}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:"Memories"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Builds memory across runs to make automations smarter over time"})]})]}),jsx(b$1,{className:"fk:mt-1.5 fk:py-0 fk:text-[10px] fk:font-light fk:tracking-wide",variant:"secondary",children:"Always on"})]})}),jsx(v,{}),E?Kt.map(a=>{let m=E[a],v$1=a==="slack"?"Send to Slack":"Send to Microsoft Teams",b=a==="slack"?Bs:$s,L=zt[a];return jsxs(Fragment$1,{children:[jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:p-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsxs("div",{className:"fk:flex fk:gap-3",children:[jsx(b,{}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:v$1}),m.connected&&m.workspaceName?jsxs("p",{className:"fk:text-xs fk:text-muted-foreground",children:["Connected to ",m.workspaceName]}):null,m.connected?null:jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:Ge?.canManage===false?"Not connected. Ask a project owner or developer to connect it.":"Not connected"})]})]}),m.connected?m.enabled?jsx(b$2,{"aria-label":`Remove ${a==="slack"?"Slack":"Microsoft Teams"} from automation`,size:"icon",type:"button",variant:"ghost",onClick:()=>Ra(a),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})}):jsx(b$2,{size:"sm",type:"button",variant:"outline",onClick:()=>Ft(a,{enabled:true}),children:"Add"}):jsx(b$2,{disabled:!Y||!L?.enabled||!Ge?.canManage||It!==null,size:"sm",type:"button",variant:"outline",onClick:()=>{Pa(a);},children:It===a?"Connecting\u2026":"Connect"})]}),m.connected&&m.enabled?jsxs("div",{className:"fk:space-y-2 fk:pl-7",children:[L&&L.connections.filter(Me=>Me.scope==="project"&&Me.status==="connected").length>1?jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-3",children:[jsx(e$5,{className:"fk:text-xs fk:font-medium",children:"Workspace"}),jsx(In,{ariaLabel:`${a==="slack"?"Slack":"Microsoft Teams"} workspace`,disabled:!Y,plugin:L,scopes:["project"],value:{connectionMode:"project",connectionId:mt[a]},onChange:Me=>Ma(a,Me.connectionId)})]}):null,jsx(e$5,{className:"fk:mr-3 fk:text-xs fk:font-medium",children:"Channels"}),jsx(Ms,{channels:m.availableChannels,disabled:m.loadingChannels||!Y,loading:m.loadingChannels,provider:a,value:m.channels,onChange:Me=>Ft(a,{channels:Me}),onRefresh:()=>{gn(a,pn[a]);}}),m.channelsLoadError?jsxs("p",{className:"fk:flex fk:items-start fk:text-sm fk:text-warning fk:gap-1",children:[jsx(TriangleAlertIcon,{className:"fk:size-4 fk:shrink-0 fk:mt-0.5"}),m.channelsLoadError]}):null,!m.channelsLoadError&&ne.toolErrors[a]?jsx(Xe,{message:ne.toolErrors[a]}):null]}):null]}),jsx(v,{})]},a)}):Ta?jsx("p",{className:"fk:m-1.5 fk:p-1.5 fk:text-xs fk:text-warning",role:"alert",children:"Unable to load Slack and Microsoft Teams delivery. Reload the page to try again."}):jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:p-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircleIcon,{className:"fk:size-4 fk:animate-spin"}),"Loading tools..."]}),jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsxs("div",{className:"fk:flex fk:gap-2.5",children:[jsx(GraduationCapIcon,{className:"fk:mt-px fk:size-5 fk:text-muted-foreground"}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:"Skills"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Attached skills are always loaded into the agent context. All other skills you can see stay discoverable by the agent when relevant."})]})]}),jsx(Jt,{disabled:!Y||fn.length===0&&un.length===0,emptyText:"No skills match.",items:[...fn.map(a=>({id:a.id,label:a.name,attached:ge.includes(a.id),badge:a.source==="code"?"Code":void 0})),...un.map(a=>({id:a.id,label:a.name,attached:false,badge:a.source==="code"?"Code":void 0,lockedHint:js(a,Ia)}))],searchPlaceholder:"Search skills\u2026",onToggle:Xn})]}),Z$1&&fn.length===0&&un.length===0?jsx("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:"No attachable skills yet. Create them on the Skills tab."}):null,Z$1?.hasMore?jsxs("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:["Showing the ",Z$1.skills.length," most recently updated skills. Attached skills outside this list are kept when you save."]}):null,ge.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5 fk:pl-7",children:ge.map(a=>{let m=Ye[a],v=m?.name??"Loading skill\u2026";return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[v,m?.source==="code"?jsx("span",{className:"fk:text-[10px] fk:uppercase",children:"Code"}):null,jsx("button",{"aria-label":m?`Detach ${m.name}`:"Detach skill",className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!Y,type:"button",onClick:()=>Xn(a,false),children:jsx(XIcon,{className:"fk:size-3"})})]},a)})}):null]}),jsx(v,{}),jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsxs("div",{className:"fk:flex fk:gap-2.5",children:[jsx(WrenchIcon,{className:"fk:mt-px fk:size-5 fk:text-muted-foreground"}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:"Custom tools"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Attached custom tools can be called during a run. Tools you do not attach stay unavailable to this automation."}),Un?jsx("p",{className:ze?.connected?"fk:mt-1 fk:text-xs fk:text-warning":"fk:mt-1 fk:text-xs fk:text-muted-foreground",children:Un}):null]})]}),jsx(Jt,{disabled:!Y||mn.length===0,emptyText:"No custom tools match.",items:mn.map(a=>({id:a.name,label:a.name,attached:re.includes(a.name)})),searchPlaceholder:"Search custom tools\u2026",onToggle:Jn})]}),ze&&mn.length===0?jsx("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:"No custom tools registered yet. Define them in flexkit.tools.ts, run `flexkit dev` or sync them from the Dashboard, then attach the ones this automation needs."}):null,re.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5 fk:pl-7",children:re.map(a=>{let v=dn[a]?.name??a;return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[v,jsx("button",{"aria-label":`Detach ${v}`,className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!Y,type:"button",onClick:()=>Jn(a,false),children:jsx(XIcon,{className:"fk:size-3"})})]},a)})}):null]}),jsx(v,{}),jsx(Uo,{projectId:l,value:k,disabled:!Y,onChange:a=>{d(a),Go(a)&&(ke("personal"),pe(null));}})]})]}),jsxs("div",{className:"fk:flex fk:items-center fk:justify-end fk:gap-3",children:[kn?null:jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Complete the required fields to save"}),jsx(ma$1,{disabled:!Y,children:jsx(b$2,{disabled:Be||!kn||!Y,type:"submit",children:Be?"Saving...":o==="create"?"Create automation":"Update automation"})})]})]})}var da=25;function ti(t){return Math.max(600,t)}function ni(t){return t==="mine"||t==="team"}function W({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 oi(t){return t==="success"?"fk:bg-success/20 fk:text-success":t==="awaiting_approval"?"fk:bg-amber-500/20 fk:text-amber-600":t==="skipped"?"fk:bg-orange-500/20 fk:text-orange-700":"fk:bg-secondary fk:text-secondary-foreground"}function va({status:t}){return jsx(b$1,{className:`fk:border-none fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide ${oi(t)}`,variant:t==="success"?"default":"secondary",children:t==="awaiting_approval"?"awaiting approval":t})}function ai(t){if(t==="0 * * * *")return "Every hour";let n=/^0 (\d{1,2}) \* \* \*$/.exec(t);if(n)return `Every day at ${n[1].padStart(2,"0")}:00`;let o=/^0 (\d{1,2}) \* \* ([0-6])$/.exec(t);return o?`Every ${["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][Number(o[2])]??"week"} at ${o[1].padStart(2,"0")}:00`:t}function si(t){let n=t.triggers.map(o=>{if(o.type==="schedule")return ai(o.cron);if(o.type==="webhook")return "Webhook";let i=o.entities.length>0?o.entities.join(", "):"all entities";return `On ${o.events.join("/")} of ${i}`});return n.length===0?"Manual only":n.join(" \xB7 ")}function ha(t){return t?!!(t.name.trim()&&t.instructions.trim()&&t.modelId.trim()):false}function ii({projectId:t}){let{data:n}=De(g(t).creditBalance,f),o=n?.creditBalance;return o?jsx(b$2,{asChild:true,size:"sm",variant:"secondary",children:jsxs("a",{href:o.billingUrl,rel:"noopener noreferrer",target:"_blank",children:[jsx(CoinsIcon,{className:"fk:mr-2 fk:size-4"}),o.display," Credit"]})}):null}function li(t,n){let o=t.visibility??"project";return o==="space"?(t.spaceId?n.get(t.spaceId):void 0)??"Space":o==="personal"?"Personal":"Project"}var ba="fk:sticky fk:top-0 fk:z-10 fk:[&_th]:sticky fk:[&_th]:top-0 fk:[&_th]:bg-muted";function ri(){return jsxs(_,{children:[jsx($,{className:ba,children:jsxs(ca$1,{children:[jsx(da$1,{children:"Automation"}),jsx(da$1,{children:"Triggers"}),jsx(da$1,{children:"Last run"}),jsx(da$1,{className:"fk:text-center",children:"Runs"}),jsx(da$1,{children:"Visibility"}),jsx(da$1,{className:"fk:text-center",children:"Status"}),jsx(da$1,{})]})}),jsx(aa,{children:Array.from({length:5},(t,n)=>jsxs(ca$1,{children:[jsx(ea,{children:jsx(t$1,{className:"fk:h-4 fk:w-36"})}),jsx(ea,{children:jsx(t$1,{className:"fk:h-4 fk:w-48"})}),jsx(ea,{children:jsx(t$1,{className:"fk:h-4 fk:w-24"})}),jsx(ea,{className:"fk:text-center",children:jsx(t$1,{className:"fk:mx-auto fk:h-4 fk:w-8"})}),jsx(ea,{children:jsx(t$1,{className:"fk:h-4.75 fk:w-16"})}),jsx(ea,{className:"fk:text-center",children:jsx(t$1,{className:"fk:mx-auto fk:h-4.75 fk:w-16"})}),jsx(ea,{className:"fk:text-right",children:jsx(t$1,{className:"fk:ml-auto fk:size-8"})})]},n))})]})}function ma(t,n){let i=t.find(l=>l.id===n)?.value;return Array.isArray(i)?i.filter(l=>typeof l=="string"):[]}function ci(t){if(t.length===0)return;let n=t.map(o=>o==="enabled"?true:o==="disabled"?false:null).filter(o=>o!==null);if(n.length!==0)return n}function fi(t){if(t.length===0)return;let n=t.filter(o=>o==="project"||o==="space"||o==="personal");if(n.length!==0)return n}function Al(){let{api:t$1,projectId:n}=t(),o$1=useNavigate(),[i,l]=useState([]),[k,d]=useState(""),[p,c$1]=useState(""),g$2=b(),r=useRef(null),N$1=ma(i,"status"),I=ma(i,"visibility"),T=ci(N$1),_$1=fi(I),S=i.length>0||k.trim().length>0,y=JSON.stringify({enabledFilter:T,search:k,visibilityFilter:_$1}),h$1=(x,E)=>!n||E&&E.hasMore===false?null:g(n).automations({enabled:T,limit:da,offset:x*da,search:k.trim()||void 0,visibility:_$1}),{data:P,isLoading:F,mutate:C,setSize:B,size:M}=At(h$1,f),{data:$$1}=De(n?g(n).spaces:null,f),U=useMemo(()=>new Map(($$1?.spaces??[]).map(x=>[x.id,x.label])),[$$1?.spaces]),w=P?.flatMap(x=>x.automations)??[],j$1=P?.[P.length-1]?.hasMore??false,ke=P!==void 0&&M>P.length,q=P?.[0]?.count,pe=F&&w.length===0,ge=useMemo(()=>[{id:"status",accessorKey:"enabled"},{id:"visibility",accessorKey:"visibility"}],[]),Fe=useReactTable({columns:ge,data:w,getCoreRowModel:getCoreRowModel(),manualFiltering:true,onColumnFiltersChange:x=>{B(1),l(x);},state:{columnFilters:i}}),re=useRef(()=>{B(x=>x+1);}),ut=useRef(j$1),Ce=useRef(ke);re.current=()=>{B(x=>x+1);},ut.current=j$1,Ce.current=ke;let Le=useCallback(x=>{if(!re.current||!ut.current||Ce.current)return;let E=x??r.current;if(!E)return;let{scrollHeight:ce,scrollTop:It,clientHeight:dt}=E;ce-It-dt>=ti(dt)||(Ce.current=true,re.current());},[]);useEffect(()=>{Le();},[Le,w.length,j$1,ke,y]),useEffect(()=>{r.current?.scrollTo({top:0});},[y]);let Be=useRef(k);Be.current=k;let Ke=useCallback(x=>{x!==Be.current&&(B(1),d(x));},[B]);if(!n||!t$1)return jsx(W,{children:"Select a project to view automations."});async function We(x){if(c$1(""),!t$1)return;let E=await t$1.deleteAutomation(x.id);if(!E.success){c$1(Array.isArray(E.errorMessage)?E.errorMessage.join(", "):E.errorMessage);return}await C();}function $e(x){Le(x.currentTarget);}let R;return F&&w.length===0?R=jsx(ri,{}):w.length===0?R=jsx(W,{children:S?"No results.":"No automations yet."}):R=jsxs(_,{children:[jsx($,{className:ba,children:jsxs(ca$1,{children:[jsx(da$1,{children:"Automation"}),jsx(da$1,{children:"Triggers"}),jsx(da$1,{children:"Last run"}),jsx(da$1,{className:"fk:text-center",children:"Runs"}),jsx(da$1,{children:"Visibility"}),jsx(da$1,{className:"fk:text-center",children:"Status"}),jsx(da$1,{})]})}),jsx(aa,{children:w.map(x=>jsxs(ca$1,{className:"fk:cursor-pointer",onClick:()=>o$1(x.id),children:[jsx(ea,{children:jsx("span",{className:"fk:font-medium",children:x.name})}),jsx(ea,{className:"fk:text-muted-foreground",children:si(x)}),jsx(ea,{children:x.lastRunAt?formatDistance(new Date(x.lastRunAt),new Date,{addSuffix:true}):"Never"}),jsx(ea,{className:"fk:text-center",children:x.totalRuns}),jsx(ea,{children:jsx(b$1,{className:"fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide",variant:x.visibility==="personal"?"secondary":"outline",children:li(x,U)})}),jsx(ea,{className:"fk:text-center",children:jsx(b$1,{className:`fk:border-none fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide ${x.enabled?"fk:bg-success/20 fk:text-success":"fk:bg-secondary fk:text-secondary-foreground"}`,variant:x.enabled?"default":"secondary",children:x.enabled?"Enabled":"Disabled"})}),jsx(ea,{className:"fk:text-right",children:jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsx(b$2,{"aria-label":`Actions for ${x.name}`,size:"icon",type:"button",variant:"ghost",onClick:E=>{E.stopPropagation();},children:jsx(Ellipsis,{className:"fk:size-4"})})}),jsxs(h,{align:"end",className:"fk:w-40",children:[jsxs(j,{onClick:E=>{E.stopPropagation(),o$1(x.id);},children:[jsx(Pencil,{}),"Edit"]}),jsx(o,{}),jsxs(j,{disabled:!g$2,variant:"destructive",onClick:E=>{E.stopPropagation(),We(x);},children:[jsx(Trash2,{}),"Delete"]})]})]})})]},x.id))})]}),jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-4 fk:pr-4",children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsxs("div",{className:"fk:min-w-0 fk:flex-1",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:"Automations"}),!pe&&q!==void 0?jsxs("span",{className:"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground",children:[q.toLocaleString()," ",q===1?"automation":"automations"]}):null]}),jsxs("p",{className:"fk:mt-1 fk:text-sm fk:text-muted-foreground",children:["Agent-powered tasks that run on a schedule or when your data changes.",jsx(f$1,{href:"https://flexkit.io/docs/automations",children:"Learn more"})]})]})]}),p?jsx("div",{className:"fk:text-sm fk:text-destructive",children:p}):null,jsx($o,{actions:jsxs(Fragment,{children:[jsx(ii,{projectId:n}),g$2?jsx(b$2,{asChild:true,className:"fk:h-8",size:"sm",children:jsxs(Link,{to:"new",children:[jsx(Plus,{className:"fk:mr-2 fk:size-4"}),"New Automation"]})}):jsx(ma$1,{disabled:true,children:jsxs(b$2,{className:"fk:h-8",disabled:true,size:"sm",children:[jsx(Plus,{className:"fk:mr-2 fk:size-4"}),"New Automation"]})})]}),isSearchLoading:F&&k.trim().length>0,search:k,table:Fe,onSearchChange:Ke}),jsxs("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1",children:[ke?jsx("div",{"aria-hidden":true,className:"fk:pointer-events-none fk:absolute fk:top-0 fk:right-px fk:left-px fk:z-20 fk:h-0.5 fk:overflow-hidden fk:opacity-40",children:jsx("div",{className:"fk:animate-progress fk:h-full fk:w-full fk:bg-foreground"})}):null,jsx("div",{className:"fk:h-full fk:overflow-auto",onScroll:$e,ref:r,children:R})]})]})}function Il(){let{api:t$1,projectId:n}=t(),o=useNavigate();return !n||!t$1?jsx(W,{children:"Select a project to create automations."}):jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:"New Automation"})})]}),jsx(b$2,{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"}),"Automations"]})}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:jsx(Rn,{api:t$1,mode:"create",projectId:n,onSaved:()=>o("..",{relative:"path"})})})})]})}function Pl(){let{api:t$1,projectId:n}=t(),{automationId:o}=useParams(),i=useNavigate(),[l,k]=useTransition(),d=b(),{data:p,mutate:c$1}=De(n&&o?g(n).automation(o):null,f);if(!n||!t$1||!o)return jsx(W,{children:"Select an automation."});if(!p?.automation)return jsx(W,{children:"Loading automation..."});let g$1=t$1,r=ha(p.automation)&&d,N$1=o;function I(){r&&k(async()=>{let T=await g$1.runAutomation(N$1);if(T.success&&T.runId){i(`runs/${T.runId}`);return}await c$1();});}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:p.automation.name})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-center fk:justify-between fk:gap-3 fk:pr-4",children:[jsx(b$2,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"../automations",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(ga,{value:"settings",children:jsxs(ha$1,{children:[jsx(ia$1,{className:"text-xs",value:"settings",children:"Settings"}),jsx(ia$1,{className:"text-xs",value:"runs",children:jsx(Link,{to:"runs",children:"Runs"})})]})}),jsx(ma$1,{disabled:!d,children:jsxs(b$2,{disabled:l||!r,size:"sm",onClick:I,children:[l?jsx(LoaderCircle,{className:"fk:mr-2 fk:size-4 fk:animate-spin"}):jsx(Play,{className:"fk:mr-2 fk:size-4"}),"Run now"]})})]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:jsx(Rn,{api:t$1,automation:p.automation,mode:"edit",projectId:n,onSaved:T=>{T?c$1({automation:T},{revalidate:false}):c$1();}})})})]})}var nn=25;function Ml(){let{api:t$1,projectId:n}=t(),{automationId:o}=useParams(),i=useNavigate(),[l,k]=useTransition(),{data:d}=De(n&&o?g(n).automation(o):null,f),p=($,U)=>!n||!o||U&&U.hasMore===false?null:g(n).automationRuns(o,$*nn,nn),{data:c$1,isLoading:g$1,mutate:r,setSize:N$1,size:I}=At(p,f),T=b();if(!n||!t$1||!o)return jsx(W,{children:"Select an automation to view runs."});let _=t$1,S=ha(d?.automation)&&T,y=o;function h(){S&&k(async()=>{let $=await _.runAutomation(y);if($.success&&$.runId){i($.runId);return}await r();});}let P=c$1?.flatMap($=>$.runs)??[],C=c$1?.[c$1.length-1]?.hasMore??false,B=c$1!==void 0&&I>c$1.length;function M(){N$1($=>$+1);}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:d?.automation.name??"Automation"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-center fk:justify-between fk:gap-3 fk:pr-4",children:[jsx(b$2,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"../automations",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(ga,{value:"runs",children:jsxs(ha$1,{children:[jsx(ia$1,{className:"text-xs",value:"settings",children:jsx(Link,{relative:"path",to:"..",children:"Settings"})}),jsx(ia$1,{className:"text-xs",value:"runs",children:"Runs"})]})}),jsx(ma$1,{disabled:!T,children:jsxs(b$2,{disabled:l||!S,size:"sm",onClick:h,children:[l?jsx(LoaderCircle,{className:"fk:mr-2 fk:size-4 fk:animate-spin"}):jsx(Play,{className:"fk:mr-2 fk:size-4"}),"Run now"]})})]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[jsx(ya,{basePath:".",isLoading:g$1,runs:P}),C&&!B?jsx(an,{onVisible:M}):null,B?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 runs..."})]}):null]})})]})}function an({onVisible:t}){let n=useRef(null),o=useRef(t);return o.current=t,useEffect(()=>{let i=n.current;if(!i)return;let l=new IntersectionObserver(k=>{k.some(d=>d.isIntersecting)&&o.current();});return l.observe(i),()=>{l.disconnect();}},[]),jsx("div",{className:"fk:h-px",ref:n})}function Ln(){return jsx(_,{children:jsx(aa,{children:Array.from({length:5},(t,n)=>jsxs(ca$1,{children:[jsx(ea,{className:"fk:py-2",children:jsx(t$1,{className:"fk:h-4 fk:w-28"})}),jsx(ea,{children:jsx(t$1,{className:"fk:h-4 fk:w-20"})}),jsx(ea,{children:jsx(t$1,{className:"fk:h-4.75 fk:w-16"})}),jsx(ea,{children:jsx(t$1,{className:"fk:h-4 fk:w-full fk:max-w-md"})})]},n))})})}function ya({basePath:t,isLoading:n=false,runs:o}){return n?jsx(Ln,{}):o.length===0?jsx(W,{children:"No runs found."}):jsx(_,{children:jsx(aa,{children:o.map(i=>jsxs(ca$1,{children:[jsx(ea,{className:"fk:py-2",children:jsx(Link,{className:"fk:font-medium hover:fk:underline",to:`${t}/${i.id}`,children:formatDistance(new Date(i.startedAt),new Date,{addSuffix:true})})}),jsx(ea,{className:"fk:text-muted-foreground",children:i.triggerType}),jsx(ea,{children:jsx(va,{status:i.status})}),jsx(ea,{className:"fk:max-w-md fk:truncate fk:text-muted-foreground",children:i.summary??""})]},i.id))})})}function Rl(){let{projectId:t$2}=t(),[n,o]=useState("team"),i=(y,h)=>!t$2||h&&!h.history.hasMore?null:g(t$2).runHistory(n,y*nn,nn),{data:l,isLoading:k,setSize:d,size:p}=At(i,f),c$1=l?.[0]?.history.metrics,g$1=l?.flatMap(y=>y.history.runs)??[],N$1=l?.[l.length-1]?.history.hasMore??false,I=l!==void 0&&p>l.length;if(!t$2)return jsx(W,{children:"Select a project to view run history."});function T(){d(y=>y+1);}function _(y){!ni(y)||y===n||o(y);}let S=null;return k?S=jsx("div",{className:"fk:mb-6 fk:grid fk:shrink-0 fk:gap-3 fk:grid-cols-4 fk:pr-4",children:Array.from({length:4},(y,h)=>jsxs("div",{className:"fk:rounded-md fk:bg-muted/60 fk:p-4 fk:corner-squircle",children:[jsx(t$1,{className:"fk:h-4 fk:w-24"}),jsx(t$1,{className:"fk:mt-2 fk:h-8 fk:w-12"})]},h))}):c$1&&(S=jsxs("div",{className:"fk:mb-6 fk:grid fk:shrink-0 fk:gap-3 fk:grid-cols-4 fk:pr-4",children:[jsx(tn,{title:"Successful 24h",value:c$1.successful24h}),jsx(tn,{title:"Failed 24h",value:c$1.failed24h}),jsx(tn,{title:"Successful 7d",value:c$1.successful7d}),jsx(tn,{title:"Failed 7d",value:c$1.failed7d})]})),jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col",children:[jsxs("div",{className:"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(ga,{value:n,onValueChange:_,children:jsxs(ha$1,{children:[jsx(ia$1,{value:"team",children:"Team"}),jsx(ia$1,{value:"mine",children:"Mine"})]})})]}),S,jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[jsx(ya,{basePath:"../automations",isLoading:k,runs:g$1.map(y=>({...y,id:`${y.automationId}/runs/${y.id}`}))}),N$1&&!I?jsx(an,{onVisible:T}):null,I?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 runs..."})]}):null]})})]})}var ka=25;function ui(t){return t==="pending"||t==="all"}function El(){let{api:t$1,projectId:n}=t(),[o,i]=useState("pending"),[l,k]=useState(null),d$1=(M,$)=>!n||$&&!$.hasMore?null:g(n).approvals({limit:ka,offset:M*ka,status:o==="pending"?"pending":void 0}),{data:p,isLoading:c$1,mutate:g$1,setSize:r,size:N$1}=At(d$1,f,{refreshInterval:3e4}),I=p?.flatMap(M=>M.approvals)??[],T=p?.[0]?.pendingCount??0,_$1=p?.[0],S=a();useEffect(()=>{_$1&&S(_$1);},[_$1,S]);let h=p?.[p.length-1]?.hasMore??false,P=p!==void 0&&N$1>p.length,F=I.find(M=>M.id===l)??null;if(useEffect(()=>{l===null||F!==null||c$1||p===void 0||k(null);},[p,c$1,F,l]),!n||!t$1)return jsx(W,{children:"Select a project to view approvals."});function C(){r(M=>M+1);}function B(M){!ui(M)||M===o||(r(1),i(M));}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col",children:[jsxs("div",{className:"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(ga,{value:o,onValueChange:B,children:jsxs(ha$1,{children:[jsxs(ia$1,{value:"pending",children:["Pending",T>0?` (${T.toString()})`:""]}),jsx(ia$1,{value:"all",children:"All"})]})})]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[c$1?jsx(Ln,{}):I.length===0?jsx(W,{children:o==="pending"?"No proposals are waiting for approval.":"No approvals found."}):jsx(_,{children:jsx(aa,{children:I.map(M=>jsxs(ca$1,{className:"fk:cursor-pointer",onClick:()=>k(M.id),children:[jsx(ea,{children:jsx(b$4,{status:M.status})}),jsx(ea,{className:"fk:font-medium",children:M.operationsSummary}),jsx(ea,{className:"fk:text-muted-foreground",children:M.automationName}),jsx(ea,{className:"fk:text-muted-foreground",children:formatDistance(new Date(M.requestedAt),new Date,{addSuffix:true})}),jsx(ea,{onClick:$=>$.stopPropagation(),children:M.chatId?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../agent/chats/${M.chatId}`,children:"View chat"}):M.automationId&&M.runId?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../automations/${M.automationId}/runs/${M.runId}`,children:"View run"}):null})]},M.id))})}),h&&!P?jsx(an,{onVisible:C}):null,P?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 approvals..."})]}):null]})}),F?jsx(d,{api:t$1,approval:F,onClose:()=>k(null),onDecided:()=>{g$1();}},`${F.id}-${F.status}`):null]})}var pa=25,di={attention:"fk:border-none fk:bg-amber-500/20 fk:text-amber-600 fk:corner-squircle",failure:"fk:border-none fk:bg-destructive/15 fk:text-destructive fk:corner-squircle",neutral:"fk:corner-squircle"};function mi(t){return t==="needs_action"||t==="all"}function ki(){let{mode:t}=f$5(),[n,o]=useState(()=>typeof Notification>"u"?"unsupported":Notification.permission);return n!=="default"?null:jsxs("div",{className:"fk:mb-3 fk:flex fk:items-center fk:gap-3 fk:rounded-md fk:border fk:p-3 fk:text-sm fk:corner-squircle",children:[jsx(BellIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}),jsx("span",{className:"fk:flex-1",children:"Get a desktop notification when something needs you while Studio is in the background."}),jsx(b$2,{size:"sm",variant:"outline",onClick:()=>{Notification.requestPermission().then(i=>{o(i),i==="granted"&&t==="hosted"&&k().catch(()=>{});});},children:"Turn on"})]})}function Dl(){let{api:t$1,projectId:n}=t(),o=useNavigate(),i=b$5(),[l,k]=useState("needs_action"),[d,p]=useState(()=>new Set),c$2=a(),g$1=(C,B)=>!n||B&&!B.hasMore?null:g(n).activity({filter:l,limit:pa,offset:C*pa}),{data:r,isLoading:N$1,mutate:I,setSize:T,size:_$1}=At(g$1,f,{refreshInterval:3e4}),S=useMemo(()=>r?.flatMap(C=>C.items)??[],[r]),y=r?.[r.length-1]?.hasMore??false,h=r!==void 0&&_$1>r.length;if(useEffect(()=>{let C=S.filter(B=>B.state==="unread").map(B=>B.id);!t$1||!i||C.length===0||(p(B=>new Set([...B,...C])),t$1.markActivityRead(C).then(()=>c$2()));},[t$1,i,S,c$2]),!n||!t$1)return jsx(W,{children:"Select a project to view activity."});function P(C){!mi(C)||C===l||(T(1),k(C));}function F(C){t$1&&t$1.setActivityItemState(C.id,"dismissed").catch(B=>{oa.error(B instanceof Error?B.message:"Unable to dismiss this item.");}).finally(()=>{I();});}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col",children:[jsxs("div",{className:"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(ga,{value:l,onValueChange:P,children:jsxs(ha$1,{children:[jsx(ia$1,{value:"needs_action",children:"Needs attention"}),jsx(ia$1,{value:"all",children:"All"})]})}),jsx(zo,{})]}),jsx(ki,{}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[N$1?jsx(Ln,{}):S.length===0?jsx(W,{children:l==="needs_action"?"Nothing needs your attention.":"No activity yet."}):jsx(_,{children:jsx(aa,{children:S.map(C=>{let B=e$2(C),M=c$1(C),$=d$1(C),U=g$2(C),w=f$2(C);return jsxs(ca$1,{className:"fk:cursor-pointer",onClick:()=>o(C.id),children:[jsx(ea,{className:"fk:w-4 fk:pr-0",children:d.has(C.id)||C.state==="unread"?jsx("span",{"aria-label":"Unread",className:"fk:block fk:size-2 fk:rounded-full fk:bg-primary"}):null}),jsxs(ea,{children:[jsx("div",{className:"fk:font-medium",children:C.title}),C.body?jsx("div",{className:"fk:text-xs fk:text-muted-foreground",children:C.body}):null]}),jsx(ea,{children:B?jsx(b$1,{className:di[w],variant:w==="neutral"?"outline":"default",children:B}):null}),jsx(ea,{className:"fk:whitespace-nowrap fk:text-muted-foreground",children:formatDistance(new Date(C.createdAt),new Date,{addSuffix:true})}),jsx(ea,{className:"fk:whitespace-nowrap",onClick:X=>X.stopPropagation(),children:M&&$?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../${M}`,children:$}):null}),jsx(ea,{className:"fk:w-8",onClick:X=>X.stopPropagation(),children:U?null:jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(b$2,{"aria-label":"Dismiss",size:"icon",variant:"ghost",onClick:()=>F(C),children:jsx(XIcon,{className:"fk:size-4"})})}),jsx(e$1,{children:"Dismiss"})]})})]},C.id)})})}),y&&!h?jsx(an,{onVisible:()=>{T(C=>C+1);}}):null,h?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 activity..."})]}):null]})})]})}function Ll(){let{api:t$2,projectId:n}=t(),{itemId:o=""}=useParams(),i=a(),{data:l,error:k,isLoading:d,mutate:p}=De(n&&o?g(n).activityItem(o):null,f),c$3=l?.item,g$1=c$3?.approvalId??null,{data:r,mutate:N$1}=De(n&&g$1?g(n).approval(g$1):null,f),I=c$3?.state==="unread",T=b$5();if(useEffect(()=>{!t$2||!I||!T||t$2.markActivityRead([o]).then(()=>{p(),i();});},[t$2,I,T,o,p,i]),!n||!t$2)return jsx(W,{children:"Select a project to view activity."});let _=c$3?c$1(c$3):null,S=c$3?d$1(c$3):null,y;return k?y=jsx(W,{children:"This activity item no longer exists."}):d||!c$3?y=jsxs("div",{className:"fk:flex fk:flex-col fk:gap-3",children:[jsx(t$1,{className:"fk:h-4 fk:w-64"}),jsx(t$1,{className:"fk:h-32 fk:w-full"})]}):y=jsxs("div",{className:"fk:flex fk:flex-col fk:gap-6",children:[jsxs("div",{className:"fk:text-sm fk:text-muted-foreground",children:[c$3.body?`${c$3.body} \xB7 `:"",formatDistance(new Date(c$3.createdAt),new Date,{addSuffix:true})]}),r?jsx(c$2,{api:t$2,approval:r.approval,chat:r.approval.chatId!==null,onDecided:()=>{p(),N$1(),i();}},`${r.approval.id}-${r.approval.status}`):g$1?jsx(t$1,{className:"fk:h-32 fk:w-full"}):null]}),jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:c$3?.title??"Activity"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:justify-between fk:gap-3 fk:pr-4",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(b$2,{asChild:true,"aria-label":"Back to Activity",size:"icon",variant:"ghost",children:jsx(Link,{relative:"path",to:"..",children:jsx(ArrowLeft,{className:"fk:size-4"})})})}),jsx(e$1,{children:"Back to Activity"})]}),_&&S?jsx(b$2,{asChild:true,size:"sm",variant:"outline",children:jsx(Link,{to:`../${_}`,children:S})}):null]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:y})})]})}function tn({title:t,value:n}){return jsxs("div",{className:"fk:rounded-md fk:bg-muted/60 fk:p-4 fk:corner-squircle",children:[jsx("div",{className:"fk:text-sm fk:text-muted-foreground",children:t}),jsx("div",{className:"fk:mt-1 fk:text-2xl fk:font-medium",children:n.toLocaleString()})]})}function zl(){let{api:t$1,projectId:n}=t(),{automationId:o,runId:i}=useParams(),{data:l,mutate:k}=De(n&&i?g(n).run(i):null,f,{refreshInterval:P=>!P?.run||y(P.run.status)?0:u}),{data:d}=De(n&&o?g(n).automation(o):null,f),[p,c$1]=useTransition(),[g$1,r]=useState(false);if(useEffect(()=>{r(false);},[i]),!n||!t$1||!o||!i)return jsx(W,{children:"Select a run."});let N$1=t$1,I=i,T=l?.run,_=T?.status==="running"&&!g$1;function S(){c$1(async()=>{await N$1.cancelRun(I),await k();});}function y$1(){r(true),k();}function h(){k();}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:d?.automation.name??"Automation"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-start fk:justify-between fk:gap-3 fk:pr-4",children:[jsxs("div",{children:[jsx(b$2,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{relative:"path",to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Runs"]})}),jsxs("div",{className:"fk:mt-4 fk:flex fk:flex-wrap fk:items-center fk:gap-2",children:[jsx("h2",{className:"fk:text-sm fk:font-medium",children:T?`Run from ${format(new Date(T.startedAt),"PPpp")}`:"Loading run..."}),T?jsx(va,{status:T.status}):null]})]}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[T&&y(T.status)?jsx(b$2,{asChild:true,size:"sm",variant:"outline",children:jsx("a",{href:N$1.getTranscriptUrl(I),rel:"noreferrer",target:"_blank",children:"Transcript"})}):null,_?jsx(b$2,{disabled:p,size:"sm",variant:"destructive",onClick:S,children:p?"Cancelling...":"Cancel run"}):null]})]}),jsxs(_a,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:[jsx($a,{className:"fk:gap-0 fk:p-0",children:jsx("div",{className:"fk:mx-auto fk:w-full fk:max-w-5xl fk:pb-6 fk:pr-4",children:T?jsx(gi,{api:t$1,run:T,onRunUpdated:h,onStreamFinished:y$1}):jsx(W,{children:"Loading run..."})})}),jsx(bb,{})]})]})}function pi(t){return t==="unavailable"?"No replay events were recorded.":t==="error"?"Unable to load run replay.":"Loading run replay..."}function gi({api:t$1,onRunUpdated:n,onStreamFinished:o,run:i$1}){let{projectId:l}=t(),{workflowRunId:k}=i$1,d=k?t$1.getStreamUrl(k):"",[p,c]=useState(0),[g$1,r]=useState(false),[N,I]=useState([]),[T,_]=useState({}),S=useRef(null),{message:y$1,status:h}=z(d,{decidedApprovals:T,recordStatus:i$1.status,resumeToken:p,suppressApprovalPause:g$1}),P=useMemo(()=>y$1?[y$1]:[],[y$1]),F=x(P),C=useRef(n);C.current=n;let B=useRef(o);B.current=o;let M=useMemo(()=>({onApprovalDecided:(R,x)=>{R&&x&&x!=="pending"&&_(E=>({...E,[R]:x})),!(R&&S.current===R)&&(R&&(S.current=R),r(true),c(E=>E+1),C.current?.());}}),[]),$=!g$1&&i$1.status!=="running"&&!y(i$1.status)&&(h==="paused"||i$1.status==="awaiting_approval"||g$3(y$1)),U=a(),w=y(i$1.status);useEffect(()=>{($||w)&&U();},[$,U,w]);let X=g$3(y$1),j=$&&!X&&l!=null,{data:ke}=De(j&&l?g(l).approvals({limit:25,offset:0,runId:i$1.id,status:"pending"}):null,f,{refreshInterval:u}),q=useMemo(()=>new Set(h$1(y$1)),[y$1]),pe=N.filter(R=>!q.has(R.id)),Fe=!y(i$1.status)&&(h==="streaming"||h==="paused"),re=F.length>0||pe.length>0||Fe;if(useEffect(()=>{c(0),r(false),S.current=null,I([]),_({});},[i$1.id]),useEffect(()=>{let R=ke?.approvals;R?.length&&I(x=>{let E=new Map(x.map(ce=>[ce.id,ce]));for(let ce of R)E.set(ce.id,ce);return [...E.values()]});},[ke]),useEffect(()=>{I(R=>{if(R.length===0)return R;let x=R.filter(E=>!q.has(E.id));return x.length===R.length?R:x});},[q]),useEffect(()=>{if(!g$1)return;if(i$1.status==="running"){r(false);return}if(i$1.status!=="awaiting_approval")return;let R=i(y$1),x=S.current;R.length===0||x===null||R.every(E=>E!==x)&&r(false);},[y$1,i$1.status,g$1]),useEffect(()=>{h==="finished"&&B.current?.();},[h]),useEffect(()=>{h==="paused"&&C.current?.();},[h]),useEffect(()=>{if(i$1.status!=="awaiting_approval")return;let R=window.setInterval(()=>{C.current?.();},u);return ()=>{window.clearInterval(R);}},[i$1.status]),!k)return jsx(W,{children:"The run has not started streaming yet."});let Ce=Fe||$&&h!=="finished"&&h!=="error",Le=y$1?.parts[y$1.parts.length-1],Be=Le?.type==="text"&&Le.state==="streaming",Ke=$?"Awaiting approval":f$3(y$1)??"Thinking",We=$||!Be,$e=pi(h);return jsx(v$1.Provider,{value:M,children:jsxs("div",{className:"fk:space-y-4",children:[i$1.status==="failed"&&i$1.error?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-4 fk:text-sm fk:corner-squircle",children:i$1.summary??i$1.error}):null,h==="unavailable"?jsx("div",{className:"fk:rounded-md fk:border fk:border-amber-500/30 fk:bg-amber-500/5 fk:p-4 fk:text-sm fk:corner-squircle",children:"The workflow replay is no longer available. Generated artifacts may still be available below."}):null,h==="error"&&!re?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-4 fk:text-sm fk:corner-squircle",children:"Failed to load the run stream. Try reloading the page."}):null,re?jsxs("div",{className:"fk:space-y-5 fk:rounded-md fk:bg-background fk:corner-squircle",children:[F.map(R=>jsx(vi,{api:t$1,message:R},R.id)),pe.map(R=>jsx(E,{api:t$1,message:A(R)},R.id)),Ce?jsx(D,{label:Ke,visible:We}):null]}):jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:rounded-md fk:border fk:border-dashed fk:p-8 fk:font-mono fk:text-sm fk:text-muted-foreground fk:corner-squircle",children:[h==="unavailable"||h==="error"?jsx(TriangleAlertIcon,{className:"fk:size-4"}):jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:$e})]})]})})}function vi({api:t,message:n}){let o=n.role==="user",i=n.parts.filter(l=>!e$3(l));return i.length===0?null:jsxs("div",{className:o?"fk:ml-auto fk:w-full fk:max-w-[70%]":"fk:w-full fk:min-w-0",children:[jsx("div",{className:"fk:mb-2 fk:flex fk:items-center fk:gap-2 fk:font-mono fk:text-sm fk:font-medium fk:text-primary",children:o?jsxs(Fragment,{children:[jsx(ZapIcon,{className:"fk:ml-auto fk:size-4"}),jsx("span",{children:"Trigger"})]}):jsxs(Fragment,{children:[jsx(BotIcon,{className:"fk:size-4"}),jsxs("span",{children:["Agent",n.metadata?.model?` (${n.metadata.model})`:""]})]})}),jsx("div",{className:"fk:space-y-8 fk:min-w-0",children:i.map((l,k)=>jsx(B,{api:t,part:l,partIndex:k,parts:i},k))})]})}
2
+ export{Ll as ActivityItemPage,Dl as ActivityPage,El as ApprovalsPage,Pl as AutomationDetailPage,Al as AutomationsPage,Il as CreateAutomationPage,zl as RunDetailPage,Rl as RunHistoryPage,Ml as RunsPage};//# sourceMappingURL=pages-4NDELS2U.js.map
3
+ //# sourceMappingURL=pages-4NDELS2U.js.map