@flexkit/studio 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/astro.js +1 -1
  2. package/dist/chat-page-ZFPMTRLD.js +2 -0
  3. package/dist/chat-page-ZFPMTRLD.js.map +1 -0
  4. package/dist/chunk-BKJ2DBRK.js +2 -0
  5. package/dist/{chunk-QQUNCDUB.js.map → chunk-BKJ2DBRK.js.map} +1 -1
  6. package/dist/chunk-DPCMOWK4.js +3 -0
  7. package/dist/chunk-DPCMOWK4.js.map +1 -0
  8. package/dist/chunk-DQ6Z333C.js +4 -0
  9. package/dist/{chunk-YINI2YKQ.js.map → chunk-DQ6Z333C.js.map} +1 -1
  10. package/dist/{chunk-OUSEULBR.js → chunk-LMVJWCOM.js} +4 -4
  11. package/dist/{chunk-OUSEULBR.js.map → chunk-LMVJWCOM.js.map} +1 -1
  12. package/dist/{chunk-7PDYCDX6.js → chunk-LX7Q56OS.js} +2 -2
  13. package/dist/{chunk-7PDYCDX6.js.map → chunk-LX7Q56OS.js.map} +1 -1
  14. package/dist/chunk-MKEIZ5ZQ.js +5 -0
  15. package/dist/chunk-MKEIZ5ZQ.js.map +1 -0
  16. package/dist/chunk-QJWY4XIM.js +2 -0
  17. package/dist/{chunk-GZIMMYLK.js.map → chunk-QJWY4XIM.js.map} +1 -1
  18. package/dist/{chunk-C2BPRGGQ.js → chunk-TXK4OFAG.js} +25 -18
  19. package/dist/{chunk-3CPWATOI.js → chunk-WBZKCRQK.js} +2 -2
  20. package/dist/{chunk-3CPWATOI.js.map → chunk-WBZKCRQK.js.map} +1 -1
  21. package/dist/index.css +6 -0
  22. package/dist/index.js +4 -4
  23. package/dist/list-GALFFS5F.js +2 -0
  24. package/dist/{list-SQCN7HA3.js.map → list-GALFFS5F.js.map} +1 -1
  25. package/dist/nextjs.js +1 -1
  26. package/dist/pages-IA7GOMMS.js +3 -0
  27. package/dist/pages-IA7GOMMS.js.map +1 -0
  28. package/dist/{plugin-pages-AHOA6YJE.js → plugin-pages-Q63UBSKH.js} +2 -2
  29. package/dist/{plugin-pages-AHOA6YJE.js.map → plugin-pages-Q63UBSKH.js.map} +1 -1
  30. package/dist/root-5TCUJI6Q.js +23 -0
  31. package/dist/{root-4FGNRGCD.js.map → root-5TCUJI6Q.js.map} +1 -1
  32. package/dist/{root-IIILTOJI.js → root-SMHRBFGW.js} +3 -3
  33. package/dist/{root-IIILTOJI.js.map → root-SMHRBFGW.js.map} +1 -1
  34. package/dist/root-VSTE2THV.js +2 -0
  35. package/dist/{root-5ZW536V7.js.map → root-VSTE2THV.js.map} +1 -1
  36. package/dist/{root-QPQQ3DFJ.js → root-VYZYDWIB.js} +2 -2
  37. package/dist/{root-QPQQ3DFJ.js.map → root-VYZYDWIB.js.map} +1 -1
  38. package/dist/{search-2K2BU4UU.js → search-K75Q65A6.js} +2 -2
  39. package/dist/{search-2K2BU4UU.js.map → search-K75Q65A6.js.map} +1 -1
  40. package/dist/{skills-pages-PSBRTFGK.js → skills-pages-KDG2NOQJ.js} +2 -2
  41. package/dist/{skills-pages-PSBRTFGK.js.map → skills-pages-KDG2NOQJ.js.map} +1 -1
  42. package/dist/tanstack-start.js +1 -1
  43. package/package.json +4 -4
  44. package/dist/chat-page-NWMI4XOE.js +0 -2
  45. package/dist/chat-page-NWMI4XOE.js.map +0 -1
  46. package/dist/chunk-GZIMMYLK.js +0 -2
  47. package/dist/chunk-NSYO57O3.js +0 -5
  48. package/dist/chunk-NSYO57O3.js.map +0 -1
  49. package/dist/chunk-QQUNCDUB.js +0 -2
  50. package/dist/chunk-W2EBZZAY.js +0 -3
  51. package/dist/chunk-W2EBZZAY.js.map +0 -1
  52. package/dist/chunk-YINI2YKQ.js +0 -4
  53. package/dist/list-SQCN7HA3.js +0 -2
  54. package/dist/pages-OIAPASPF.js +0 -3
  55. package/dist/pages-OIAPASPF.js.map +0 -1
  56. package/dist/root-4FGNRGCD.js +0 -23
  57. package/dist/root-5ZW536V7.js +0 -2
@@ -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":"ynBAiBA,IAAMA,EAAW,EAAA,CACXC,EAAAA,CAAc,CAAC,CAAE,UAAA,CAAY,MAAO,CAAA,CAAG,CAAE,IAAK,MAAO,CAAC,CAAA,CAErD,SAASC,EAAAA,EAAoB,CAClC,GAAM,CAAE,OAAQC,CAAW,CAAA,CAAIC,SAAAA,EAAU,CACnC,CAAE,MAAA,CAAAC,CAAO,CAAA,CAAIC,aAAY,CAEzBC,CAAAA,CADQ,IAAI,eAAA,CAAgBF,CAAM,CAAA,CACjB,GAAA,CAAI,IAAI,EACzB,CAAE,KAAA,CAAAG,CAAM,CAAA,CAAIC,CAAAA,EAAc,CAC1B,CAAE,kBAAA,CAAAC,CAAmB,CAAA,CAAIC,CAAAA,EAAgB,CACzC,CAAE,cAAA,CAAAC,CAAe,CAAA,CAAIC,CAAAA,EAAU,CAC/BC,CAAAA,CAASF,CAAAA,EAAgB,MAAA,EAAU,EAAC,CACpCG,CAAAA,CAAeC,GAAAA,CAAgBF,EA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S6B,EAAAA,CAAkBmB,GAAAA,CAAqF,CAC9G,OAAOA,GAAAA,CAAQ,GAAA,CAAKC,CAAAA,GAAY,CAC9B,GAAGA,CAAAA,CACH,IAAA,CAAM,IAAMlB,GAAAA,CAACmB,CAAAA,CAAA,CAAS,SAAA,CAAU,mBAAmB,KAAA,CAAO,CAAE,SAAA,CAAW,KAAA,CAAO,YAAA,CAAc,KAAM,CAAA,CAAG,CACvG,EAAE,CACJ","file":"list-SQCN7HA3.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":"ynBAiBA,IAAMA,EAAW,EAAA,CACXC,EAAAA,CAAc,CAAC,CAAE,UAAA,CAAY,MAAO,CAAA,CAAG,CAAE,IAAK,MAAO,CAAC,CAAA,CAErD,SAASC,EAAAA,EAAoB,CAClC,GAAM,CAAE,OAAQC,CAAW,CAAA,CAAIC,SAAAA,EAAU,CACnC,CAAE,MAAA,CAAAC,CAAO,CAAA,CAAIC,aAAY,CAEzBC,GAAAA,CADQ,IAAI,eAAA,CAAgBF,CAAM,CAAA,CACjB,GAAA,CAAI,IAAI,EACzB,CAAE,KAAA,CAAAG,CAAM,CAAA,CAAIC,CAAAA,EAAc,CAC1B,CAAE,kBAAA,CAAAC,CAAmB,CAAA,CAAIC,CAAA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I,CAAA,CAAgC,CAC1F,OAAO+B,GAAAA,CAACgB,EAAA,CAAoB,UAAA,CAAYtE,CAAAA,CAAY,gBAAA,CAAkBqE,GAAAA,CAAkB,GAAA,CAAK9C,CAAAA,CAAK,CACpG,CAEA,SAAS6B,EAAAA,CAAkBmB,GAAAA,CAAqF,CAC9G,OAAOA,GAAAA,CAAQ,GAAA,CAAKC,CAAAA,GAAY,CAC9B,GAAGA,CAAAA,CACH,IAAA,CAAM,IAAMlB,GAAAA,CAACmB,CAAAA,CAAA,CAAS,SAAA,CAAU,mBAAmB,KAAA,CAAO,CAAE,SAAA,CAAW,KAAA,CAAO,YAAA,CAAc,KAAM,CAAA,CAAG,CACvG,EAAE,CACJ","file":"list-GALFFS5F.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-C2BPRGGQ.js";
3
+ } from "./chunk-TXK4OFAG.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$3,b as b$3,c as c$1,d as d$2,e as e$2,g as g$3}from'./chunk-CSUHZFEP.js';import {i,a,b as b$2,c,j as j$1,n,o as o$1,m,f as f$2,g as g$2,h as h$1,e as e$1,k,t as t$1,p,s,d as d$1,q}from'./chunk-MKEIZ5ZQ.js';import {a as a$3,b as b$4}from'./chunk-LX7Q56OS.js';import {f,g,e as e$5,c as c$3,d as d$4}from'./chunk-HROHAMPM.js';import {a as a$1}from'./chunk-G4PYYHI3.js';import {b}from'./chunk-7SK5YPHT.js';import'./chunk-DPCMOWK4.js';import {h as h$2}from'./chunk-NNA4MLFC.js';import {da,ea,ha,ia,fa,ja,L,M,S,O,f as f$1,ra,la,ma,na,eb,fb,hb,s as s$1,e as e$3,ca,pa as pa$1,ta,t as t$2,u,v as v$1}from'./chunk-6LYEDKFY.js';import {e,g as g$1,h,j,o,t,q as q$1,r,s as s$2,k as k$1}from'./chunk-SZEGGBOC.js';import {b as b$1,v,w,x,m as m$1,o as o$2,p as p$1,q as q$2,r as r$1,t as t$3}from'./chunk-ODORXGGY.js';import {d}from'./chunk-5DHOBLAE.js';import {a as a$2,d as d$3,c as c$2,e as e$4,g as g$4}from'./chunk-HDOIOXMP.js';import'./chunk-O2QMYUPS.js';import {useState,useRef,useMemo,useCallback,useEffect,useTransition,Fragment as Fragment$1}from'react';import {formatDistance,format}from'date-fns';import {Ellipsis,Pencil,Trash2,Plus,ArrowLeft,LoaderCircle,Play,TriangleAlertIcon,ZapIcon,BotIcon,Search,X,CoinsIcon,BrainIcon,Trash2Icon,LoaderCircleIcon,GraduationCapIcon,XIcon,WrenchIcon,ClockIcon,WebhookIcon,DatabaseZapIcon,PlusIcon,ChevronsUpDownIcon,CheckIcon,RefreshCwIcon,ChevronDownIcon,LockIcon,CopyIcon,KeyRoundIcon}from'lucide-react';import {useNavigate,Link,useParams}from'react-router-dom';import {useReactTable,getCoreRowModel}from'@tanstack/react-table';import Ve,{useSWRConfig}from'swr';import qt from'swr/infinite';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {CronExpressionParser}from'cron-parser';var ka=[{label:"Enabled",value:"enabled"},{label:"Disabled",value:"disabled"}],pa=[{label:"Project",value:"project"},{label:"Space",value:"space"},{label:"Personal",value:"personal"}];function ga(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 go({actions:t,isSearchLoading:n=false,onSearchChange:o,search:i,searchPlaceholder:l="Search automations...",table:p}){let f=p.getState().columnFilters.length>0||i.trim().length>0,g=p.getAllColumns().find(I=>I.id==="status"),c=p.getAllColumns().find(I=>I.id==="visibility"),[u,d$1]=useState(i),N=u.trim(),w$1=i.trim(),C=N.length>0&&(n||N!==w$1),$=useRef(o);$.current=o;let P=useMemo(()=>ga(I=>{$.current(I);},300),[]);useEffect(()=>{d$1(i);},[i]),useEffect(()=>()=>{P.cancel();},[P]);function T(){P.cancel(),d$1(""),o("");}function v(){p.resetColumnFilters(),T();}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:[C?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$1,{className:"fk:h-8 fk:w-37.5 fk:lg:w-70 fk:px-7 fk:text-sm",name:"search-automations",placeholder:l,value:u,onChange:I=>{let{value:L}=I.target;if(d$1(L),L.trim().length===0){P.cancel(),o("");return}P(L.trim());}}),u?jsx(d,{"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:T,type:"button",children:jsx(X,{className:"fk:h-4 fk:w-4"})}):null]}),g?jsx(a$1,{column:g,options:ka,title:"Status"}):null,c?jsx(a$1,{column:c,options:pa,title:"Visibility"}):null,f?jsxs(d,{className:"fk:h-8 fk:px-2 fk:lg:px-3",onClick:v,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,{orientation:"horizontal"})]})})}function rn(t,n,o){return (o??[]).some(i=>i.toLowerCase().includes(n.trim().toLowerCase()))?1:0}function cn({disabled:t,emptyText:n,footer:o,items:i,searchPlaceholder:l,onToggle:p}){let[f,g]=useState(false),c=useRef(null);return jsxs(t$2,{open:f,onOpenChange:g,children:[jsx(u,{asChild:true,children:jsxs(d,{disabled:t,size:"sm",type:"button",variant:"outline",children:["Attach",jsx(ChevronDownIcon,{className:"fk:ml-1 fk:size-4"})]})}),jsx(v$1,{align:"end",className:"fk:w-72 fk:p-0",onOpenAutoFocus:u=>{u.preventDefault(),c.current?.focus({preventScroll:true});},children:jsxs(m$1,{filter:rn,children:[jsx(o$2,{placeholder:l,ref:c}),jsxs(p$1,{className:"fk:max-h-72",children:[jsx(q$2,{children:n}),jsx(r$1,{children:i.map(u=>jsxs(t$3,{disabled:!!u.lockedHint,title:u.lockedHint,value:u.id,keywords:[u.label],onSelect:()=>p(u.id,!u.attached),children:[u.lockedHint?jsx(LockIcon,{className:"fk:size-4"}):jsx(CheckIcon,{className:u.attached?"fk:size-4":"fk:size-4 fk:opacity-0"}),jsx("span",{className:"fk:truncate",children:u.label}),u.badge?jsx(b$1,{className:"fk:ml-auto fk:py-0 fk:text-[10px]",variant:"secondary",children:u.badge}):null]},u.id))})]}),o]})})]})}function vo(t){return t==="project"?"Project":"Personal"}function dt(t,n){return t.connections.filter(o=>o.scope===n&&o.status==="connected")}function dn(t,n){if(!n)return null;let o=dt(t,n.connectionMode);return n.connectionId?o.find(i=>i.id===n.connectionId)??null:o.find(i=>i.isPrimary)??null}function ut(t){return t?t.connectionId?`account:${t.connectionId}`:`primary:${t.connectionMode}`:""}function mn({ariaLabel:t,disabled:n,plugin:o,scopes:i,value:l,onChange:p}){let f=[];for(let c of i){let u=dt(o,c),d=u.find(w=>w.isPrimary),[N]=u;if(u.length===1&&N){let w=l?.connectionMode===c&&l.connectionId===N.id;f.push({choice:{connectionMode:c,connectionId:w||!N.isPrimary?N.id:null},label:`${vo(c)} \xB7 ${N.displayName}`});continue}d&&f.push({choice:{connectionMode:c,connectionId:null},label:`Primary ${c} account (${d.displayName})`});for(let w of u)f.push({choice:{connectionMode:c,connectionId:w.id},label:`${vo(c)} \xB7 ${w.displayName}`});}let g=ut(l);return jsxs(a$2,{disabled:n,value:f.some(c=>ut(c.choice)===g)?g:"",onValueChange:c=>{let u=f.find(d=>ut(d.choice)===c);u&&p(u.choice);},children:[jsx(d$3,{"aria-label":t,className:"fk:w-fit fk:max-w-full",size:"sm",children:jsx(c$2,{placeholder:"Select account"})}),jsx(e$4,{children:f.map(c=>jsx(g$4,{value:ut(c.choice),children:c.label},ut(c.choice)))})]})}var fn=2;function xo(t){return t.scopes.filter(n=>n==="project"||t.allowPersonal)}function Aa(t){let n=xo(t),o=n.includes("personal")&&(!n.includes("project")||dt(t,"project").length===0&&dt(t,"personal").length>0);return {pluginId:t.id,enabled:true,connectionMode:o?"personal":"project",connectionId:null,allTools:true,selectedTools:[],deliveryEnabled:false,channels:[]}}function Ia(t,n){return `${encodeURIComponent(t)}:${encodeURIComponent(n)}`}function Pa(t){return decodeURIComponent(t.slice(t.indexOf(":")+1))}function Ma(t){let n=t.map(Pa),o=n.slice(0,fn).join(", ");return n.length>fn?`${o} +${n.length-fn} more`:o}function Ra({canManage:t,disabled:n,plugin:o$1,projectId:i,usage:l,onChange:p,onRemove:f$1}){let g=xo(o$1),c=g.some(x=>dt(o$1,x).length>0),u=g.includes(l.connectionMode)?{connectionMode:l.connectionMode,connectionId:l.connectionId}:null,d$1=dn(o$1,u),{data:N,error:w}=Ve(d$1?`/api/flexkit/${i}/plugin-connections/${d$1.id}/tools`:null,f),C=(N?.servers??[]).flatMap(x=>x.tools.map(O=>({key:Ia(x.name,O.name),entry:O}))),$=(N?.servers??[]).flatMap(x=>x.error?[x.error]:[]),P=l.allTools!==false,T=n||!o$1.enabled,v$1=x=>p({...l,allTools:false,selectedTools:x,enabled:x.length>0}),I=()=>p({...l,allTools:true,selectedTools:[],enabled:true}),L=x=>({...l,connectionMode:x.connectionMode,connectionId:x.connectionId,selectedTools:[],enabled:P}),{mutate:q}=useSWRConfig(),[z,M]=useState(false),S=async x=>{M(true);try{await a$3(d$4(i),o$1.id,x),await q(`/api/flexkit/${i}/plugins`),p(L({connectionMode:x,connectionId:null}));}catch(O){ta.error(O instanceof Error?O.message:`Unable to connect ${o$1.name}.`);}finally{M(false);}},_=null;return o$1.enabled?c?u?d$1?w||$.length?_={text:$[0]??"Unable to load tools. Reconnect or try again.",tone:"warning"}:P?_={text:"All tools",tone:"muted"}:l.selectedTools.length===0?_={text:"No tools selected, so the agent cannot use this plugin yet.",tone:"warning"}:_={text:Ma(l.selectedTools),tone:"muted"}:_={text:u.connectionId?"The selected account is no longer connected.":`The primary ${u.connectionMode} account needs reconnecting.`,tone:"warning"}:_={text:"Select an account.",tone:"warning"}:_={text:`Connect ${o$1.name} to use its tools.`,tone:"warning"}:_={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:_.tone==="warning"?"fk:truncate fk:text-xs fk:text-warning":"fk:truncate fk:text-xs fk:text-muted-foreground",children:_.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(mn,{ariaLabel:`${o$1.name} account`,disabled:T,plugin:o$1,scopes:g,value:u,onChange:x=>{x.connectionMode===l.connectionMode&&x.connectionId===l.connectionId||p(L(x));}}),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(d,{disabled:T||!d$1||!N,size:"sm",type:"button",variant:"outline",children:[P?"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:x=>{x.preventDefault(),P?v$1(C.map(O=>O.key)):I();},children:[jsx(CheckIcon,{className:P?"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,{}),C.map(({key:x,entry:O})=>{let X=P||l.selectedTools.includes(x);return jsxs(j,{className:"fk:items-start",onSelect:le=>{le.preventDefault();let J=P?C.map(de=>de.key):l.selectedTools;v$1(X?J.filter(de=>de!==x):[...J,x]);},children:[jsx(CheckIcon,{className:X?"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:O.name}),O.description?jsx("span",{className:"fk:line-clamp-2 fk:text-xs fk:text-muted-foreground",children:O.description}):null]})]},x)}),N&&C.length===0?jsx(j,{disabled:true,children:"This account exposes no tools."}):null]})]})]}):jsx(b$4,{busy:z||n,canManage:t,plugin:o$1,onConnect:x=>{S(x);}}),jsx(d,{"aria-label":`Remove ${o$1.name} from automation`,disabled:n,size:"icon",type:"button",variant:"ghost",onClick:f$1,children:jsx(Trash2Icon,{className:"fk:size-4"})})]})]}),jsx(v,{})]})}function Ea({disabled:t,plugins:n,onAdd:o}){let[i,l]=useState(false),p=useRef(null);return jsxs(t$2,{open:i,onOpenChange:l,children:[jsx(u,{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$1,{align:"start",className:"fk:w-72 fk:p-0",onOpenAutoFocus:f=>{f.preventDefault(),p.current?.focus({preventScroll:true});},children:jsxs(m$1,{filter:rn,children:[jsx(o$2,{placeholder:"Search plugins\u2026",ref:p}),jsxs(p$1,{children:[jsx(q$2,{children:"No plugins found."}),jsx(r$1,{children:n.map(f=>jsxs(t$3,{value:f.id,keywords:[f.name],onSelect:()=>{o(f),l(false);},children:[jsx("img",{src:f.logoUrl,alt:"",className:"fk:size-5 fk:shrink-0 fk:rounded fk:corner-squircle"}),jsx("span",{className:"fk:truncate",children:f.name}),f.connections.some(g=>g.status==="connected")?null:jsx("span",{className:"fk:ml-auto fk:text-xs fk:text-muted-foreground",children:"Not connected"})]},f.id))})]})]})})]})}function No({projectId:t,value:n,disabled:o,onChange:i}){let{data:l,error:p}=Ve(`/api/flexkit/${t}/plugins`,f),f$1=(l?.plugins??[]).filter(u=>u.capabilities.agentTools),g=new Map(f$1.map(u=>[u.id,u])),c=f$1.filter(u=>u.enabled&&!n.some(d=>d.pluginId===u.id));return jsxs(Fragment,{children:[n.map(u=>{let d=g.get(u.pluginId);return d?jsx(Ra,{disabled:o,canManage:l?.canManage??false,plugin:d,projectId:t,usage:u,onChange:N=>i(n.map(w=>w.pluginId===d.id?N:w)),onRemove:()=>i(n.filter(N=>N.pluginId!==d.id))},u.pluginId):null}),p?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(Ea,{disabled:o||!l,plugins:c,onAdd:u=>i([...n,Aa(u)])})]})}var Lt=["slack","teams"],Ao=["create","update","delete"],Bo="0 * * * *",Va="0 9 * * *",Ua="0 9 * * 1",qa="0 9 1 * *",Oa=[{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}],Xa=Array.from({length:24},(t,n)=>({label:`${n.toString().padStart(2,"0")}:00`,value:n}));function Ja(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 Io(t){return t.some(n=>n.enabled&&n.connectionMode==="personal")}function He({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 Ft(){return crypto.randomUUID()}function Ka(t){return (t?.triggers??[]).map(n=>({...n,key:n.id??Ft()}))}function Wa(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 Za(){return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}function Ga(){let t=crypto.getRandomValues(new Uint8Array(24));return Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}function Ya(t){if(t===Bo)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 $o(t,n,o){try{let i=CronExpressionParser.parse(t,{tz:n});return Array.from({length:o},()=>i.next().toDate())}catch{return []}}function jo(t,n){return new Intl.DateTimeFormat("en-US",{day:"numeric",hour:"numeric",minute:"2-digit",month:"short",timeZone:n,weekday:"short"}).format(t)}function _o(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 Qa(t,n,o){let i=t.filter(p=>!p.deprecated);if(n!=="edit"||!o)return i;let l=c$1(t,o);return l?.deprecated?[l,...i.filter(p=>b$3(p)!==o)]:l?i:[{deprecated:true,effort:null,efforts:[],id:o,kind:"model",name:o},...i]}function gn(t){return `${t.teamId??""}:${t.id}`}function es(t,n){let o={};for(let i of [...t,...n])o[gn(i)]=i;return Object.values(o)}function Po(t,n){return {...t,availableChannels:t.channels,channelsLoaded:!t.connected,enabled:t.connected&&n==="edit"&&t.enabled,loadingChannels:false}}function ts(t,n){return {slack:Po(t.providers.slack,n),teams:Po(t.providers.teams,n)}}function ns({channels:t,disabled:n,loading:o,onChange:i,onRefresh:l,provider:p,value:f}){let[g,c]=useState(false),[u,d$1]=useState(""),N=useRef(null),w=new Set(f.map(v=>v.id)),C=p==="slack"?"Slack":"Teams",$=t.filter(v=>v.name.toLowerCase().includes(u.toLowerCase()));useEffect(()=>{if(!g)return;function v(L){let{target:q}=L;!(q instanceof Node)||N.current?.contains(q)||c(false);}function I(L){L.key==="Escape"&&c(false);}return document.addEventListener("pointerdown",v),document.addEventListener("keydown",I),()=>{document.removeEventListener("pointerdown",v),document.removeEventListener("keydown",I);}},[g]);function P(v){if(w.has(v.id)){i(f.filter(I=>I.id!==v.id));return}i([...f,v]);}function T(v){i(f.filter(I=>I.id!==v));}return jsxs("div",{className:"fk:relative",ref:N,children:[jsxs(d,{"aria-expanded":g,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(v=>!v),children:[jsx("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:gap-1",children:f.length===0?jsx("span",{className:"fk:text-muted-foreground",children:o?`Loading ${C} channels...`:`Select ${C} channels`}):f.map(v=>jsxs(b$1,{className:"fk:rounded-sm fk:bg-accent fk:text-xs fk:corner-squircle",variant:"secondary",onClick:I=>{I.stopPropagation(),T(v.id);},children:[v.name,jsx(XIcon,{className:"fk:ml-1 fk:size-3 fk:cursor-pointer"})]},gn(v)))}),jsx(ChevronsUpDownIcon,{className:"fk:size-4 fk:shrink-0 fk:opacity-50"})]}),g?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$1,{className:"fk:h-8",placeholder:`Search ${C} channels...`,value:u,onChange:v=>d$1(v.target.value)})}),jsx("div",{className:"fk:max-h-56 fk:overflow-auto fk:p-1",children:$.length>0?$.map(v=>jsxs(d,{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:()=>P(v),children:[jsx(CheckIcon,{className:`fk:mr-2 fk:size-4 ${w.has(v.id)?"fk:opacity-100":"fk:opacity-0"}`}),v.name]},gn(v))):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(d,{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 zt({cron:t,timezone:n}){let[o]=$o(t,n,1);return o?jsxs("span",{className:"fk:text-sm fk:text-muted-foreground",children:["Next run ",jo(o,n)]}):null}function Mo({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$2,{})}),jsx(e$4,{children:Xa.map(o=>jsx(g$4,{value:o.value.toString(),children:o.label},o.value))})]})}function os({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$2,{})}),jsx(e$4,{children:Oa.map(o=>jsx(g$4,{value:o.value.toString(),children:o.label},o.value))})]})}function as({onChange:t,timezone:n,value:o}){let[i,l]=useState(false),p=useRef(null),f=_o(o,n),g=f?[]:$o(o,n,3);return useEffect(()=>{if(!i)return;function c(d){let{target:N}=d;!(N instanceof Node)||p.current?.contains(N)||l(false);}function u(d){d.key==="Escape"&&l(false);}return document.addEventListener("pointerdown",c),document.addEventListener("keydown",u),()=>{document.removeEventListener("pointerdown",c),document.removeEventListener("keydown",u);}},[i]),jsxs("div",{className:"fk:relative",ref:p,children:[jsxs(d,{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$1,{className:`fk:h-8 fk:font-mono ${f?"fk:border-destructive focus-visible:fk:ring-destructive":""}`,value:o,onChange:c=>t(c.target.value)}),f?jsx("p",{className:"fk:mt-2 fk:text-xs fk:text-destructive",children:f}):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"}),g.map(c=>jsx("p",{children:jo(c,n)},c.toISOString()))]})]}):null]})}function ss({onChange:t,trigger:n}){let o=Ya(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(zt,{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(Mo,{value:o.hour,onChange:i=>t({...n,cron:`0 ${i.toString()} * * *`})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(zt,{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(os,{value:o.day,onChange:i=>t({...n,cron:`0 ${o.hour.toString()} * * ${i.toString()}`})}),jsx("span",{children:"at"}),jsx(Mo,{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(zt,{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(as,{timezone:n.timezone,value:n.cron,onChange:i=>t({...n,cron:i})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(zt,{cron:n.cron,timezone:n.timezone})]})}function is({onChange:t,projectId:n,trigger:o}){let[i,l]=useState(false),[p,f]=useState(false),g=o.url??c$3(n,o.token);function c(u,d){navigator.clipboard.writeText(u).then(()=>{d(true),window.setTimeout(()=>d(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(L,{children:[jsx(M,{asChild:true,children:jsxs(d,{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(g,l),children:[jsx("span",{className:"fk:truncate",children:g}),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(O,{className:"fk:max-w-96 fk:break-all",children:g})]}),o.secret?jsxs(d,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>c(`Bearer ${o.secret??""}`,f),children:[p?jsx(CheckIcon,{className:"fk:size-3.5"}):jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Copy auth header"]}):jsxs(d,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>t({...o,secret:Ga()}),children:[jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Generate auth header"]})]})}function ls({entities:t,onChange:n,trigger:o}){function i(f){let g=o.events.includes(f)?o.events.filter(c=>c!==f):[...o.events,f];n({...o,events:Ao.filter(c=>g.includes(c))});}function l(f){let g=o.entities.includes(f)?o.entities.filter(c=>c!==f):[...o.entities,f];n({...o,entities:g});}let p=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:Ao.map(f=>jsxs(d,{className:"fk:h-7 fk:px-2.5 fk:text-xs fk:capitalize",size:"sm",type:"button",variant:o.events.includes(f)?"secondary":"ghost",onClick:()=>i(f),children:[o.events.includes(f)?jsx(CheckIcon,{className:"fk:size-3"}):null,f]},f))}),jsx("span",{children:"of"}),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(d,{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:p}),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(f=>jsx(k$1,{checked:o.entities.includes(f),onCheckedChange:()=>l(f),onSelect:g=>g.preventDefault(),children:f},f))})]})]})}function rs({entities:t,errors:n,onChange:o,projectId:i,triggers:l}){let p=l.some(d=>d.type==="webhook");function f(d){o([...l,d]);}function g(d){f({cron:d,key:Ft(),timezone:Za(),type:"schedule"});}function c(d){o(l.map(N=>N.key===d.key?d:N));}function u(d){o(l.filter(N=>N.key!==d));}return jsxs("div",{className:"fk:rounded-lg fk:border fk:bg-muted/60 fk:dark:bg-muted/30 fk:corner-squircle",children:[l.map(d$1=>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:[d$1.type==="schedule"?jsx(ClockIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,d$1.type==="webhook"?jsx(WebhookIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,d$1.type==="entity"?jsx(DatabaseZapIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,d$1.type==="schedule"?jsx(ss,{trigger:d$1,onChange:c}):null,d$1.type==="webhook"?jsx(is,{projectId:i,trigger:d$1,onChange:c}):null,d$1.type==="entity"?jsx(ls,{entities:t,trigger:d$1,onChange:c}):null,jsx(d,{"aria-label":"Remove trigger",className:"fk:opacity-0 fk:group-hover:opacity-100",size:"icon",type:"button",variant:"ghost",onClick:()=>u(d$1.key),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})})]}),n[d$1.key]?jsx("div",{className:"fk:mt-1 fk:pl-7",children:jsx(He,{message:n[d$1.key]})}):null]},d$1.key),jsx(v,{className:"fk:h-4"})]},d$1.key)),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(d,{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$1,{children:[jsxs(r,{children:[jsx(ClockIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Scheduled"]}),jsxs(s$2,{children:[jsx(j,{onClick:()=>g(Bo),children:"Hourly"}),jsx(j,{onClick:()=>g(Va),children:"Daily"}),jsx(j,{onClick:()=>g(Ua),children:"Weekly"}),jsx(j,{onClick:()=>g(qa),children:"Custom (cron)"})]})]}),jsxs(j,{disabled:p,onClick:()=>f({key:Ft(),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:()=>f({entities:[],events:["create"],key:Ft(),type:"entity"}),children:[jsx(DatabaseZapIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Entity Events"]})]})]})]})}function cs(){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 fs(){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 Bt(t,n,o){return t.visibility==="space"?n==="space"&&o!==null&&t.spaceId===o:t.visibility==="personal"?n==="personal":true}function us(t,n,o){return t.visibility==="space"&&!Bt(t,n,o)}function ds(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 ms(t,n){try{return (await f(g(t).skill(n))).skill}catch(o){if(o instanceof e$5&&o.status===404)return null;throw o}}function hn({api:t,automation:n,mode:o,onSaved:i,projectId:l}){let[p,f$1]=useState((n?.toolConfigs??[]).filter(a=>!["slack","teams"].includes(a.pluginId))),[g$1,c]=useState(n?.name??""),[u,d$1]=useState(n?.instructions??""),[N,w]=useState(n?.enabled??false),[C,$]=useState(null),[P,T]=useState(null),[v$1,I]=useState(n?.mutationPolicy??"require_approval"),[L,q]=useState(n?.toolAllowRules),[z,M]=useState(n?.visibility??"project"),[S,_]=useState(n?.spaceId??null),[x,O]=useState(n?.skillIds??[]),[X,le]=useState(n?.customToolNames??[]),[J,de]=useState(()=>Ka(n)),[nt,ze]=useState(false),[Ce,Fe]=useState(""),[Me,me]=useState({instructions:false,name:false}),[te,we]=useState(null),[Ue,qe]=useState(null),{mutate:R}=useSWRConfig(),[b$2,F]=useState(()=>({slack:n?.toolConfigs?.find(a=>a.pluginId==="slack")?.connectionId??null,teams:n?.toolConfigs?.find(a=>a.pluginId==="teams")?.connectionId??null})),ie=useRef({}),pt=useRef(null),{data:Se,error:Tn}=Ve(`/api/flexkit/${l}/plugins`,f),Cn=!!(Se||Tn),Yo=g(l).tools(n?.id),{data:Be,error:Qo}=Ve(Yo,f),{data:ea}=Ve(g(l).entities,f),{data:Ot}=Ve(g(l).spaces,f),{data:K}=Ve(g(l).skills({limit:100}),f),[,ta$1]=h$2(),ne=b(),na=ta$1.user?.spaces??[],wn=(Ot?.spaces??[]).filter(a=>na.includes(a.code)),gt=Be?.tools.models,Sn=useMemo(()=>{let a=n?.modelId??"";return a?f$3(a,gt??[])??{effort:null,modelKey:a}:null},[n?.modelId,gt]),Xt=C??Sn?.modelKey??"",ot=useMemo(()=>Qa(gt??[],o,Xt),[o,gt,Xt]),ht=Xt||(ot[0]?b$3(ot[0]):""),An=c$1(ot,ht),Jt=d$2(An,P??(C===null?Sn?.effort??null:null)),In=e$2(An),Kt=ht?g$3({effort:Jt,modelKey:ht},ot):"",Pn=useMemo(()=>new Set((K?.skills??[]).map(a=>a.id)),[K?.skills]),Oe=useMemo(()=>K?x.filter(a=>!Pn.has(a)).sort():[],[Pn,x,K]),oa=Oe.length>0?[l,"attached-skills",...Oe]:null,{data:vt}=Ve(oa,()=>Promise.all(Oe.map(a=>ms(l,a)))),Xe=useMemo(()=>{let a={};for(let k of K?.skills??[])a[k.id]=k;for(let k of vt??[])k&&(a[k.id]=k);return a},[vt,K?.skills]),Wt=useMemo(()=>{let a=(K?.skills??[]).filter(y=>Bt(y,z,S)),k=new Set(a.map(y=>y.id));return [...x.map(y=>Xe[y]).filter(y=>!y||k.has(y.id)?false:Bt(y,z,S)),...a]},[x,Xe,K?.skills,S,z]),aa=useMemo(()=>{let a={};for(let k of Ot?.spaces??[])a[k.id]=k.label;return a},[Ot?.spaces]),Zt=useMemo(()=>(K?.skills??[]).filter(a=>us(a,z,S)),[K?.skills,S,z]),Re=Be?.tools.customTools,Gt=useMemo(()=>{let a={};for(let k of Re?.tools??[])a[k.name]=k;return a},[Re?.tools]),Yt=useMemo(()=>{let a=Re?.tools??[],k=new Set(a.map(y=>y.name));return [...X.filter(y=>!k.has(y)).map(y=>Gt[y]??{description:"",name:y}),...a]},[X,Gt,Re?.tools]),Mn=Re?Wa(Re):"";useEffect(()=>{if(!K)return;let a=Oe.length>0&&vt===void 0,k=new Set(a?[]:Oe.filter(h=>!Xe[h]));O(h=>{let y=h.filter(D=>{if(k.has(D))return false;let Ae=Xe[D];return Ae?Bt(Ae,z,S):true});return y.length===h.length?h:y});},[vt,Xe,K,S,Oe,z]);let Je=Io(p),G=useMemo(()=>{let a={};for(let h of J){if(h.type==="schedule"){let y=_o(h.cron,h.timezone);y&&(a[h.key]=y);}h.type==="entity"&&h.events.length===0&&(a[h.key]="Select at least one event (create, update or delete)");}let k={};for(let h of Lt){let y=te?.[h];y?.enabled&&y.channels.length===0&&(k[h]=`Select at least one ${h==="slack"?"Slack":"Teams"} channel or remove the tool`);}return {instructions:u.trim()?"":"Instructions are required",model:Kt?"":"Select a model",name:g$1.trim()?"":"Name is required",plugins:Je&&z!=="personal"?"Personal plugin connections can only be used by a personal automation.":"",space:z==="space"&&!S?"Select a space":"",toolErrors:k,triggerErrors:a}},[Kt,u,g$1,Je,S,te,J,z]),Qt=Ja(G),bt=Me.name&&!!G.name,at=Me.instructions&&!!G.instructions;useEffect(()=>{let a=`${n?.id??""}:${o}`;!Be?.tools||pt.current===a||(pt.current=a,we(ts(Be.tools,o)));},[n?.id,o,Be?.tools]);let yt=useMemo(()=>({slack:Se?.plugins.find(a=>a.id==="slack")??null,teams:Se?.plugins.find(a=>a.id==="teams")??null}),[Se]),en=useMemo(()=>{let a=k=>{let h=yt[k];return h?dn(h,{connectionMode:"project",connectionId:b$2[k]})?.id??null:null};return {slack:a("slack"),teams:a("teams")}},[b$2,yt]),tn=useCallback(async(a,k)=>{ie.current[a]=k,we(h=>h&&{...h,[a]:{...h[a],channelsLoadError:void 0,loadingChannels:true}});try{let h=await t.listChannels(a,k);if(ie.current[a]!==k)return;let y=h.success?void 0:h.errorMessage??`Failed to load ${a==="slack"?"Slack":"Teams"} channels.`;we(D=>D&&{...D,[a]:{...D[a],availableChannels:es(D[a].channels,h.channels),channelsLoadError:y,channelsLoaded:!0,loadingChannels:!1}});}catch(h){if(ie.current[a]!==k)return;let y=h instanceof Error?h.message:"Failed to load integration channels.";we(D=>D&&{...D,[a]:{...D[a],channelsLoadError:y,channelsLoaded:true,loadingChannels:false}});}},[t]);useEffect(()=>{if(!(!te||!ne||!Cn))for(let a of Lt){let k=te[a];k.connected&&!k.channelsLoaded&&!k.loadingChannels&&tn(a,en[a]);}},[ne,tn,Cn,en,te]);async function sa(a){let k=yt[a];if(k){qe(a);try{await a$3(t,k.id,"project");let y=(await R(`/api/flexkit/${l}/plugins`))?.plugins.find(D=>D.id===k.id)?.connections.find(D=>D.scope==="project"&&D.isPrimary&&D.status==="connected");F(D=>({...D,[a]:null})),Rn(a,{connected:!0,enabled:!0,workspaceName:y?.displayName??null});}catch(h){ta.error(h instanceof Error?h.message:`Unable to connect ${k.name}.`);}finally{qe(null);}}}function xt(a,k){we(h=>h&&{...h,[a]:{...h[a],...k}});}function ia(a,k){b$2[a]!==k&&(F(h=>({...h,[a]:k})),Rn(a));}function Rn(a,k={}){ie.current[a]=void 0,xt(a,{...k,availableChannels:[],channels:[],channelsLoaded:false,channelsLoadError:void 0,loadingChannels:false});}function la(a){xt(a,{channels:[],enabled:false});}function En(a,k){O(h=>k?h.includes(a)?h:[...h,a]:h.filter(y=>y!==a));}function Dn(a,k){le(h=>k?h.includes(a)?h:[...h,a]:h.filter(y=>y!==a));}async function ra$1(a){if(a.preventDefault(),!ne)return;if(!Qt){me({instructions:true,name:true});return}ze(true),Fe("");let k=Lt.map(y=>{let D=te?.[y]??Be?.tools.providers[y];return {channels:D?.channels??[],enabled:D?.enabled??false,pluginId:y,connectionMode:"project",connectionId:b$2[y],selectedTools:[],deliveryEnabled:D?.enabled??false}}),h={customToolNames:X,enabled:N,instructions:u,modelId:Kt,mutationPolicy:v$1,name:g$1,skillIds:x,...L!==void 0?{toolAllowRules:L}:{},spaceId:z==="space"?S:null,toolConfigs:[...k,...p],triggers:J.map(({key:y,...D})=>D),visibility:z};try{let y=o==="create"||!n?await t.createAutomation(h):await t.updateAutomation(n.id,h);if(!y.success){Fe(Array.isArray(y.errorMessage)?y.errorMessage.join(", "):y.errorMessage);return}ta.success(o==="create"||!n?"Automation created.":"Automation saved."),i(y.automation);}catch(y){Fe(y instanceof Error?y.message:"Failed to save automation.");}finally{ze(false);}}return jsxs("form",{className:"fk:max-w-4xl fk:space-y-8 fk:px-1 fk:mx-auto",onSubmit:a=>{ra$1(a);},children:[Ce?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:Ce}):null,jsxs("div",{className:"fk:space-y-3",children:[jsx(e$3,{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(ca,{checked:N,id:"automation-enabled",onCheckedChange:w}),jsx(e$3,{className:"fk:font-normal",htmlFor:"automation-enabled",children:N?"Active":"Inactive"})]})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$3,{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$1,{"aria-describedby":bt?"automation-name-error":void 0,"aria-invalid":bt,className:bt?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"automation-name",value:g$1,onBlur:()=>me(a=>({...a,name:true})),onChange:a=>c(a.target.value)}),bt?jsx(He,{id:"automation-name-error",message:G.name}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$3,{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:z,onValueChange:a=>{Je&&a!=="personal"||(M(a==="space"||a==="personal"?a:"project"),a!=="space"&&_(null));},children:[jsx(d$3,{"aria-label":"Visibility",className:"fk:w-fit",id:"automation-visibility",children:jsx(c$2,{})}),jsxs(e$4,{align:"start",children:[jsx(g$4,{disabled:Je,value:"project",children:"Project"}),jsx(g$4,{disabled:Je||wn.length===0,value:"space",children:"Space"}),jsx(g$4,{value:"personal",children:"Personal"})]})]}),z==="space"?jsxs(a$2,{value:S??"",onValueChange:a=>{_(a||null);},children:[jsx(d$3,{"aria-label":"Space",className:"fk:w-fit",children:jsx(c$2,{placeholder:"Select a space"})}),jsx(e$4,{align:"start",children:wn.map(a=>jsx(g$4,{value:a.id,children:a.label},a.id))})]}):null]}),Je?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,G.plugins?jsx(He,{message:G.plugins}):null,z==="space"&&G.space?jsx(He,{message:G.space}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$3,{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(rs,{entities:ea?.entities??[],errors:G.triggerErrors,projectId:l,triggers:J,onChange:de})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$3,{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 ${at?"fk:border-destructive":"fk:border-input"} fk:corner-squircle`,children:jsx(pa$1,{"aria-describedby":at?"automation-instructions-error":void 0,"aria-invalid":at,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:u,onBlur:()=>me(a=>({...a,instructions:true})),onChange:a=>d$1(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 ${at?"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:ht,onValueChange:a=>{$(a),T(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$2,{placeholder:"Select a model"})}),jsx(e$4,{align:"start",children:ot.map(a=>jsxs(g$4,{value:b$3(a),children:[a.name,a.deprecated?" (Legacy)":""]},b$3(a)))})]}),In.length>1&&Jt?jsxs(a$2,{value:Jt,onValueChange:T,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$2,{placeholder:"Effort"})}),jsx(e$4,{align:"start",children:In.map(a=>jsx(g$4,{value:a.value,children:a.label},a.value))})]}):null]})})]}),at?jsx(He,{id:"automation-instructions-error",message:G.instructions}):null,Be&&G.model?jsx(He,{message:G.model}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$3,{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:v$1,onValueChange:a=>{I(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$2,{})}),jsxs(e$4,{align:"start",children:[jsx(g$4,{value:"require_approval",children:"Require approval (recommended)"}),jsx(g$4,{value:"auto_approve",children:"Auto-approve"})]})]}),v$1==="auto_approve"&&p.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,v$1==="require_approval"&&L&&L.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:L.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(d,{"aria-label":`Remove allow rule for ${a.pluginId} ${a.tool}`,size:"sm",type:"button",variant:"ghost",onClick:()=>q(k=>(k??[]).filter(h=>h!==a)),children:"Remove"})]},`${a.pluginId}/${a.server}/${a.tool}`))})]}):null]}),jsxs("div",{className:"fk:space-y-4",children:[jsxs("div",{children:[jsx(e$3,{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,{}),te?Lt.map(a=>{let k=te[a],h=a==="slack"?"Send to Slack":"Send to Microsoft Teams",y=a==="slack"?cs:fs,D=yt[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(y,{}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:h}),k.connected&&k.workspaceName?jsxs("p",{className:"fk:text-xs fk:text-muted-foreground",children:["Connected to ",k.workspaceName]}):null,k.connected?null:jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:Se?.canManage===false?"Not connected. Ask a project owner or developer to connect it.":"Not connected"})]})]}),k.connected?k.enabled?jsx(d,{"aria-label":`Remove ${a==="slack"?"Slack":"Microsoft Teams"} from automation`,size:"icon",type:"button",variant:"ghost",onClick:()=>la(a),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})}):jsx(d,{size:"sm",type:"button",variant:"outline",onClick:()=>xt(a,{enabled:true}),children:"Add"}):jsx(d,{disabled:!ne||!D?.enabled||!Se?.canManage||Ue!==null,size:"sm",type:"button",variant:"outline",onClick:()=>{sa(a);},children:Ue===a?"Connecting\u2026":"Connect"})]}),k.connected&&k.enabled?jsxs("div",{className:"fk:space-y-2 fk:pl-7",children:[D&&D.connections.filter(Ae=>Ae.scope==="project"&&Ae.status==="connected").length>1?jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-3",children:[jsx(e$3,{className:"fk:text-xs fk:font-medium",children:"Workspace"}),jsx(mn,{ariaLabel:`${a==="slack"?"Slack":"Microsoft Teams"} workspace`,disabled:!ne,plugin:D,scopes:["project"],value:{connectionMode:"project",connectionId:b$2[a]},onChange:Ae=>ia(a,Ae.connectionId)})]}):null,jsx(e$3,{className:"fk:mr-3 fk:text-xs fk:font-medium",children:"Channels"}),jsx(ns,{channels:k.availableChannels,disabled:k.loadingChannels||!ne,loading:k.loadingChannels,provider:a,value:k.channels,onChange:Ae=>xt(a,{channels:Ae}),onRefresh:()=>{tn(a,en[a]);}}),k.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"}),k.channelsLoadError]}):null,!k.channelsLoadError&&G.toolErrors[a]?jsx(He,{message:G.toolErrors[a]}):null]}):null]}),jsx(v,{})]},a)}):Qo?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(cn,{disabled:!ne||Wt.length===0&&Zt.length===0,emptyText:"No skills match.",items:[...Wt.map(a=>({id:a.id,label:a.name,attached:x.includes(a.id),badge:a.source==="code"?"Code":void 0})),...Zt.map(a=>({id:a.id,label:a.name,attached:false,badge:a.source==="code"?"Code":void 0,lockedHint:ds(a,aa)}))],searchPlaceholder:"Search skills\u2026",onToggle:En})]}),K&&Wt.length===0&&Zt.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,K?.hasMore?jsxs("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:["Showing the ",K.skills.length," most recently updated skills. Attached skills outside this list are kept when you save."]}):null,x.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5 fk:pl-7",children:x.map(a=>{let k=Xe[a],h=k?.name??"Loading skill\u2026";return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[h,k?.source==="code"?jsx("span",{className:"fk:text-[10px] fk:uppercase",children:"Code"}):null,jsx("button",{"aria-label":k?`Detach ${k.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:!ne,type:"button",onClick:()=>En(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."}),Mn?jsx("p",{className:Re?.connected?"fk:mt-1 fk:text-xs fk:text-warning":"fk:mt-1 fk:text-xs fk:text-muted-foreground",children:Mn}):null]})]}),jsx(cn,{disabled:!ne||Yt.length===0,emptyText:"No custom tools match.",items:Yt.map(a=>({id:a.name,label:a.name,attached:X.includes(a.name)})),searchPlaceholder:"Search custom tools\u2026",onToggle:Dn})]}),Re&&Yt.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,X.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5 fk:pl-7",children:X.map(a=>{let h=Gt[a]?.name??a;return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[h,jsx("button",{"aria-label":`Detach ${h}`,className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!ne,type:"button",onClick:()=>Dn(a,false),children:jsx(XIcon,{className:"fk:size-3"})})]},a)})}):null]}),jsx(v,{}),jsx(No,{projectId:l,value:p,disabled:!ne,onChange:a=>{f$1(a),Io(a)&&(M("personal"),_(null));}})]})]}),jsxs("div",{className:"fk:flex fk:items-center fk:justify-end fk:gap-3",children:[Qt?null:jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Complete the required fields to save"}),jsx(ra,{disabled:!ne,children:jsx(d,{disabled:nt||!Qt||!ne,type:"submit",children:nt?"Saving...":o==="create"?"Create automation":"Update automation"})})]})]})}var Uo=25;function Cs(t){return Math.max(600,t)}function ws(t){return t==="mine"||t==="team"}function se({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 Ss(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 Jo({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 ${Ss(t)}`,variant:t==="success"?"default":"secondary",children:t==="awaiting_approval"?"awaiting approval":t})}function As(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 Is(t){let n=t.triggers.map(o=>{if(o.type==="schedule")return As(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 Ko(t){return t?!!(t.name.trim()&&t.instructions.trim()&&t.modelId.trim()):false}function Ps({projectId:t}){let{data:n}=Ve(g(t).creditBalance,f),o=n?.creditBalance;return o?jsx(d,{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 Ms(t,n){let o=t.visibility??"project";return o==="space"?(t.spaceId?n.get(t.spaceId):void 0)??"Space":o==="personal"?"Personal":"Project"}var Wo="fk:sticky fk:top-0 fk:z-10 fk:[&_th]:sticky fk:[&_th]:top-0 fk:[&_th]:bg-muted";function Rs(){return jsxs(da,{children:[jsx(ea,{className:Wo,children:jsxs(ha,{children:[jsx(ia,{children:"Automation"}),jsx(ia,{children:"Triggers"}),jsx(ia,{children:"Last run"}),jsx(ia,{className:"fk:text-center",children:"Runs"}),jsx(ia,{children:"Visibility"}),jsx(ia,{className:"fk:text-center",children:"Status"}),jsx(ia,{})]})}),jsx(fa,{children:Array.from({length:5},(t$1,n)=>jsxs(ha,{children:[jsx(ja,{children:jsx(t,{className:"fk:h-4 fk:w-36"})}),jsx(ja,{children:jsx(t,{className:"fk:h-4 fk:w-48"})}),jsx(ja,{children:jsx(t,{className:"fk:h-4 fk:w-24"})}),jsx(ja,{className:"fk:text-center",children:jsx(t,{className:"fk:mx-auto fk:h-4 fk:w-8"})}),jsx(ja,{children:jsx(t,{className:"fk:h-4.75 fk:w-16"})}),jsx(ja,{className:"fk:text-center",children:jsx(t,{className:"fk:mx-auto fk:h-4.75 fk:w-16"})}),jsx(ja,{className:"fk:text-right",children:jsx(t,{className:"fk:ml-auto fk:size-8"})})]},n))})]})}function qo(t,n){let i=t.find(l=>l.id===n)?.value;return Array.isArray(i)?i.filter(l=>typeof l=="string"):[]}function Es(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 Ds(t){if(t.length===0)return;let n=t.filter(o=>o==="project"||o==="space"||o==="personal");if(n.length!==0)return n}function zi(){let{api:t,projectId:n}=i(),o$1=useNavigate(),[i$1,l]=useState([]),[p,f$2]=useState(""),[g$2,c]=useState(""),u=b(),d$1=useRef(null),N=qo(i$1,"status"),w=qo(i$1,"visibility"),C=Es(N),$=Ds(w),P=i$1.length>0||p.trim().length>0,T=JSON.stringify({enabledFilter:C,search:p,visibilityFilter:$}),v$1=(b,F)=>!n||F&&F.hasMore===false?null:g(n).automations({enabled:C,limit:Uo,offset:b*Uo,search:p.trim()||void 0,visibility:$}),{data:I,isLoading:L$1,mutate:q,setSize:z,size:M$1}=qt(v$1,f),{data:S$1}=Ve(n?g(n).spaces:null,f),_=useMemo(()=>new Map((S$1?.spaces??[]).map(b=>[b.id,b.label])),[S$1?.spaces]),x=I?.flatMap(b=>b.automations)??[],X=I?.[I.length-1]?.hasMore??false,le=I!==void 0&&M$1>I.length,J=I?.[0]?.count,de=L$1&&x.length===0,nt=useMemo(()=>[{id:"status",accessorKey:"enabled"},{id:"visibility",accessorKey:"visibility"}],[]),ze=useReactTable({columns:nt,data:x,getCoreRowModel:getCoreRowModel(),manualFiltering:true,onColumnFiltersChange:b=>{z(1),l(b);},state:{columnFilters:i$1}}),Ce=useRef(()=>{z(b=>b+1);}),Fe=useRef(X),Me=useRef(le);Ce.current=()=>{z(b=>b+1);},Fe.current=X,Me.current=le;let me=useCallback(b=>{if(!Ce.current||!Fe.current||Me.current)return;let F=b??d$1.current;if(!F)return;let{scrollHeight:ie,scrollTop:pt,clientHeight:Se}=F;ie-pt-Se>=Cs(Se)||(Me.current=true,Ce.current());},[]);useEffect(()=>{me();},[me,x.length,X,le,T]),useEffect(()=>{d$1.current?.scrollTo({top:0});},[T]);let te=useRef(p);te.current=p;let we=useCallback(b=>{b!==te.current&&(z(1),f$2(b));},[z]);if(!n||!t)return jsx(se,{children:"Select a project to view automations."});async function Ue(b){if(c(""),!t)return;let F=await t.deleteAutomation(b.id);if(!F.success){c(Array.isArray(F.errorMessage)?F.errorMessage.join(", "):F.errorMessage);return}await q();}function qe(b){me(b.currentTarget);}let R;return L$1&&x.length===0?R=jsx(Rs,{}):x.length===0?R=jsx(se,{children:P?"No results.":"No automations yet."}):R=jsxs(da,{children:[jsx(ea,{className:Wo,children:jsxs(ha,{children:[jsx(ia,{children:"Automation"}),jsx(ia,{children:"Triggers"}),jsx(ia,{children:"Last run"}),jsx(ia,{className:"fk:text-center",children:"Runs"}),jsx(ia,{children:"Visibility"}),jsx(ia,{className:"fk:text-center",children:"Status"}),jsx(ia,{})]})}),jsx(fa,{children:x.map(b=>jsxs(ha,{className:"fk:cursor-pointer",onClick:()=>o$1(b.id),children:[jsx(ja,{children:jsx("span",{className:"fk:font-medium",children:b.name})}),jsx(ja,{className:"fk:text-muted-foreground",children:Is(b)}),jsx(ja,{children:b.lastRunAt?formatDistance(new Date(b.lastRunAt),new Date,{addSuffix:true}):"Never"}),jsx(ja,{className:"fk:text-center",children:b.totalRuns}),jsx(ja,{children:jsx(b$1,{className:"fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide",variant:b.visibility==="personal"?"secondary":"outline",children:Ms(b,_)})}),jsx(ja,{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 ${b.enabled?"fk:bg-success/20 fk:text-success":"fk:bg-secondary fk:text-secondary-foreground"}`,variant:b.enabled?"default":"secondary",children:b.enabled?"Enabled":"Disabled"})}),jsx(ja,{className:"fk:text-right",children:jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsx(d,{"aria-label":`Actions for ${b.name}`,size:"icon",type:"button",variant:"ghost",onClick:F=>{F.stopPropagation();},children:jsx(Ellipsis,{className:"fk:size-4"})})}),jsxs(h,{align:"end",className:"fk:w-40",children:[jsxs(j,{onClick:F=>{F.stopPropagation(),o$1(b.id);},children:[jsx(Pencil,{}),"Edit"]}),jsx(o,{}),jsxs(j,{disabled:!u,variant:"destructive",onClick:F=>{F.stopPropagation(),Ue(b);},children:[jsx(Trash2,{}),"Delete"]})]})]})})]},b.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(L,{children:[jsx(M,{asChild:true,children:jsx(S,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(O,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk: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"}),!de&&J!==void 0?jsxs("span",{className:"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground",children:[J.toLocaleString()," ",J===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"})]})]})]}),g$2?jsx("div",{className:"fk:text-sm fk:text-destructive",children:g$2}):null,jsx(go,{actions:jsxs(Fragment,{children:[jsx(Ps,{projectId:n}),u?jsx(d,{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(ra,{disabled:true,children:jsxs(d,{className:"fk:h-8",disabled:true,size:"sm",children:[jsx(Plus,{className:"fk:mr-2 fk:size-4"}),"New Automation"]})})]}),isSearchLoading:L$1&&p.trim().length>0,search:p,table:ze,onSearchChange:we}),jsxs("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1",children:[le?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:qe,ref:d$1,children:R})]})]})}function Fi(){let{api:t,projectId:n}=i(),o=useNavigate();return !n||!t?jsx(se,{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(L,{children:[jsx(M,{asChild:true,children:jsx(S,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(O,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk: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(d,{asChild:true,className:"fk:shrink-0 fk:w-fit",size:"sm",variant:"ghost",children:jsxs(Link,{relative:"path",to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"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(hn,{api:t,mode:"create",projectId:n,onSaved:()=>o("..",{relative:"path"})})})})]})}function Bi(){let{api:t,projectId:n}=i(),{automationId:o}=useParams(),i$1=useNavigate(),[l,p]=useTransition(),f$1=b(),{data:g$1,mutate:c}=Ve(n&&o?g(n).automation(o):null,f);if(!n||!t||!o)return jsx(se,{children:"Select an automation."});if(!g$1?.automation)return jsx(se,{children:"Loading automation..."});let u=t,d$1=Ko(g$1.automation)&&f$1,N=o;function w$1(){d$1&&p(async()=>{let C=await u.runAutomation(N);if(C.success&&C.runId){i$1(`runs/${C.runId}`);return}await c();});}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(L,{children:[jsx(M,{asChild:true,children:jsx(S,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(O,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk: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:g$1.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(d,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"../automations",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(la,{value:"settings",children:jsxs(ma,{children:[jsx(na,{className:"text-xs",value:"settings",children:"Settings"}),jsx(na,{className:"text-xs",value:"runs",children:jsx(Link,{to:"runs",children:"Runs"})})]})}),jsx(ra,{disabled:!f$1,children:jsxs(d,{disabled:l||!d$1,size:"sm",onClick:w$1,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(hn,{api:t,automation:g$1.automation,mode:"edit",projectId:n,onSaved:C=>{C?c({automation:C},{revalidate:false}):c();}})})})]})}var Ht=25;function $i(){let{api:t,projectId:n}=i(),{automationId:o}=useParams(),i$1=useNavigate(),[l,p]=useTransition(),{data:f$1}=Ve(n&&o?g(n).automation(o):null,f),g$1=(S,_)=>!n||!o||_&&_.hasMore===false?null:g(n).automationRuns(o,S*Ht,Ht),{data:c,isLoading:u,mutate:d$1,setSize:N,size:w$1}=qt(g$1,f),C=b();if(!n||!t||!o)return jsx(se,{children:"Select an automation to view runs."});let $=t,P=Ko(f$1?.automation)&&C,T=o;function v$1(){P&&p(async()=>{let S=await $.runAutomation(T);if(S.success&&S.runId){i$1(S.runId);return}await d$1();});}let I=c?.flatMap(S=>S.runs)??[],q=c?.[c.length-1]?.hasMore??false,z=c!==void 0&&w$1>c.length;function M$1(){N(S=>S+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(L,{children:[jsx(M,{asChild:true,children:jsx(S,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(O,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk: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:f$1?.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(d,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"../automations",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(la,{value:"runs",children:jsxs(ma,{children:[jsx(na,{className:"text-xs",value:"settings",children:jsx(Link,{relative:"path",to:"..",children:"Settings"})}),jsx(na,{className:"text-xs",value:"runs",children:"Runs"})]})}),jsx(ra,{disabled:!C,children:jsxs(d,{disabled:l||!P,size:"sm",onClick:v$1,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(Go,{basePath:".",isLoading:u,runs:I}),q&&!z?jsx(Nn,{onVisible:M$1}):null,z?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 Nn({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(p=>{p.some(f=>f.isIntersecting)&&o.current();});return l.observe(i),()=>{l.disconnect();}},[]),jsx("div",{className:"fk:h-px",ref:n})}function Zo(){return jsx(da,{children:jsx(fa,{children:Array.from({length:5},(t$1,n)=>jsxs(ha,{children:[jsx(ja,{className:"fk:py-2",children:jsx(t,{className:"fk:h-4 fk:w-28"})}),jsx(ja,{children:jsx(t,{className:"fk:h-4 fk:w-20"})}),jsx(ja,{children:jsx(t,{className:"fk:h-4.75 fk:w-16"})}),jsx(ja,{children:jsx(t,{className:"fk:h-4 fk:w-full fk:max-w-md"})})]},n))})})}function Go({basePath:t,isLoading:n=false,runs:o}){return n?jsx(Zo,{}):o.length===0?jsx(se,{children:"No runs found."}):jsx(da,{children:jsx(fa,{children:o.map(i=>jsxs(ha,{children:[jsx(ja,{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(ja,{className:"fk:text-muted-foreground",children:i.triggerType}),jsx(ja,{children:jsx(Jo,{status:i.status})}),jsx(ja,{className:"fk:max-w-md fk:truncate fk:text-muted-foreground",children:i.summary??""})]},i.id))})})}function ji(){let{projectId:t$1}=i(),[n,o]=useState("team"),i$1=(T,v)=>!t$1||v&&!v.history.hasMore?null:g(t$1).runHistory(n,T*Ht,Ht),{data:l,isLoading:p,setSize:f$1,size:g$1}=qt(i$1,f),c=l?.[0]?.history.metrics,u=l?.flatMap(T=>T.history.runs)??[],N=l?.[l.length-1]?.history.hasMore??false,w$1=l!==void 0&&g$1>l.length;if(!t$1)return jsx(se,{children:"Select a project to view run history."});function C(){f$1(T=>T+1);}function $(T){!ws(T)||T===n||o(T);}let P=null;return p?P=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},(T,v)=>jsxs("div",{className:"fk:rounded-md fk:bg-muted/60 fk:p-4 fk:corner-squircle",children:[jsx(t,{className:"fk:h-4 fk:w-24"}),jsx(t,{className:"fk:mt-2 fk:h-8 fk:w-12"})]},v))}):c&&(P=jsxs("div",{className:"fk:mb-6 fk:grid fk:shrink-0 fk:gap-3 fk:grid-cols-4 fk:pr-4",children:[jsx(_t,{title:"Successful 24h",value:c.successful24h}),jsx(_t,{title:"Failed 24h",value:c.failed24h}),jsx(_t,{title:"Successful 7d",value:c.successful7d}),jsx(_t,{title:"Failed 7d",value:c.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(L,{children:[jsx(M,{asChild:true,children:jsx(S,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(O,{children:"Toggle Sidebar"})]}),jsx(la,{value:n,onValueChange:$,children:jsxs(ma,{children:[jsx(na,{value:"team",children:"Team"}),jsx(na,{value:"mine",children:"Mine"})]})})]}),P,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(Go,{basePath:"../automations",isLoading:p,runs:u.map(T=>({...T,id:`${T.automationId}/runs/${T.id}`}))}),N&&!w$1?jsx(Nn,{onVisible:C}):null,w$1?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 Oo=25;function Ls(t){return t==="pending"||t==="all"}function _i(){let{api:t,projectId:n}=i(),[o,i$1]=useState("pending"),[l,p]=useState(null),f$1=(M,S)=>!n||S&&!S.hasMore?null:g(n).approvals({limit:Oo,offset:M*Oo,status:o==="pending"?"pending":void 0}),{data:g$1,isLoading:c$1,mutate:u,setSize:d,size:N}=qt(f$1,f,{refreshInterval:3e4}),w$1=g$1?.flatMap(M=>M.approvals)??[],C=g$1?.[0]?.pendingCount??0,$=g$1?.[0],P=a();useEffect(()=>{$&&P($);},[$,P]);let v=g$1?.[g$1.length-1]?.hasMore??false,I=g$1!==void 0&&N>g$1.length,L$1=w$1.find(M=>M.id===l)??null;if(useEffect(()=>{l===null||L$1!==null||c$1||g$1===void 0||p(null);},[g$1,c$1,L$1,l]),!n||!t)return jsx(se,{children:"Select a project to view approvals."});function q(){d(M=>M+1);}function z(M){!Ls(M)||M===o||(d(1),i$1(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(L,{children:[jsx(M,{asChild:true,children:jsx(S,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(O,{children:"Toggle Sidebar"})]}),jsx(la,{value:o,onValueChange:z,children:jsxs(ma,{children:[jsxs(na,{value:"pending",children:["Pending",C>0?` (${C.toString()})`:""]}),jsx(na,{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(Zo,{}):w$1.length===0?jsx(se,{children:o==="pending"?"No proposals are waiting for approval.":"No approvals found."}):jsx(da,{children:jsx(fa,{children:w$1.map(M=>jsxs(ha,{className:"fk:cursor-pointer",onClick:()=>p(M.id),children:[jsx(ja,{children:jsx(b$2,{status:M.status})}),jsx(ja,{className:"fk:font-medium",children:M.operationsSummary}),jsx(ja,{className:"fk:text-muted-foreground",children:M.automationName}),jsx(ja,{className:"fk:text-muted-foreground",children:formatDistance(new Date(M.requestedAt),new Date,{addSuffix:true})}),jsx(ja,{onClick:S=>S.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))})}),v&&!I?jsx(Nn,{onVisible:q}):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 approvals..."})]}):null]})}),L$1?jsx(c,{api:t,approval:L$1,onClose:()=>p(null),onDecided:()=>{u();}},`${L$1.id}-${L$1.status}`):null]})}function _t({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 Hi(){let{api:t,projectId:n$1}=i(),{automationId:o,runId:i$1}=useParams(),{data:l,mutate:p}=Ve(n$1&&i$1?g(n$1).run(i$1):null,f,{refreshInterval:I=>!I?.run||n(I.run.status)?0:j$1}),{data:f$1}=Ve(n$1&&o?g(n$1).automation(o):null,f),[g$1,c]=useTransition(),[u,d$1]=useState(false);if(useEffect(()=>{d$1(false);},[i$1]),!n$1||!t||!o||!i$1)return jsx(se,{children:"Select a run."});let N=t,w=i$1,C=l?.run,$=C?.status==="running"&&!u;function P(){c(async()=>{await N.cancelRun(w),await p();});}function T(){d$1(true),p();}function v$1(){p();}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(L,{children:[jsx(M,{asChild:true,children:jsx(S,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(O,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk: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:f$1?.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(d,{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:C?`Run from ${format(new Date(C.startedAt),"PPpp")}`:"Loading run..."}),C?jsx(Jo,{status:C.status}):null]})]}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[C&&n(C.status)?jsx(d,{asChild:true,size:"sm",variant:"outline",children:jsx("a",{href:N.getTranscriptUrl(w),rel:"noreferrer",target:"_blank",children:"Transcript"})}):null,$?jsx(d,{disabled:g$1,size:"sm",variant:"destructive",onClick:P,children:g$1?"Cancelling...":"Cancel run"}):null]})]}),jsxs(eb,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:[jsx(fb,{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:C?jsx(Fs,{api:t,run:C,onRunUpdated:v$1,onStreamFinished:T}):jsx(se,{children:"Loading run..."})})}),jsx(hb,{})]})]})}function zs(t){return t==="unavailable"?"No replay events were recorded.":t==="error"?"Unable to load run replay.":"Loading run replay..."}function Fs({api:t,onRunUpdated:n$1,onStreamFinished:o,run:i$1}){let{projectId:l}=i(),{workflowRunId:p$1}=i$1,f$1=p$1?t.getStreamUrl(p$1):"",[g$1,c]=useState(0),[u,d]=useState(false),[N,w]=useState([]),[C,$]=useState({}),P=useRef(null),{message:T,status:v}=o$1(f$1,{decidedApprovals:C,recordStatus:i$1.status,resumeToken:g$1,suppressApprovalPause:u}),I=useMemo(()=>T?[T]:[],[T]),L=m(I),q=useRef(n$1);q.current=n$1;let z=useRef(o);z.current=o;let M=useMemo(()=>({onApprovalDecided:(R,b)=>{R&&b&&b!=="pending"&&$(F=>({...F,[R]:b})),!(R&&P.current===R)&&(R&&(P.current=R),d(true),c(F=>F+1),q.current?.());}}),[]),S=!u&&i$1.status!=="running"&&!n(i$1.status)&&(v==="paused"||i$1.status==="awaiting_approval"||f$2(T)),_=a(),x=n(i$1.status);useEffect(()=>{(S||x)&&_();},[S,_,x]);let O=f$2(T),X=S&&!O&&l!=null,{data:le}=Ve(X&&l?g(l).approvals({limit:25,offset:0,runId:i$1.id,status:"pending"}):null,f,{refreshInterval:j$1}),J=useMemo(()=>new Set(g$2(T)),[T]),de=N.filter(R=>!J.has(R.id)),ze=!n(i$1.status)&&(v==="streaming"||v==="paused"),Ce=L.length>0||de.length>0||ze;if(useEffect(()=>{c(0),d(false),P.current=null,w([]),$({});},[i$1.id]),useEffect(()=>{let R=le?.approvals;R?.length&&w(b=>{let F=new Map(b.map(ie=>[ie.id,ie]));for(let ie of R)F.set(ie.id,ie);return [...F.values()]});},[le]),useEffect(()=>{w(R=>{if(R.length===0)return R;let b=R.filter(F=>!J.has(F.id));return b.length===R.length?R:b});},[J]),useEffect(()=>{if(!u)return;if(i$1.status==="running"){d(false);return}if(i$1.status!=="awaiting_approval")return;let R=h$1(T),b=P.current;R.length===0||b===null||R.every(F=>F!==b)&&d(false);},[T,i$1.status,u]),useEffect(()=>{v==="finished"&&z.current?.();},[v]),useEffect(()=>{v==="paused"&&q.current?.();},[v]),useEffect(()=>{if(i$1.status!=="awaiting_approval")return;let R=window.setInterval(()=>{q.current?.();},j$1);return ()=>{window.clearInterval(R);}},[i$1.status]),!p$1)return jsx(se,{children:"The run has not started streaming yet."});let Me=ze||S&&v!=="finished"&&v!=="error",me=T?.parts[T.parts.length-1],te=me?.type==="text"&&me.state==="streaming",we=S?"Awaiting approval":e$1(T)??"Thinking",Ue=S||!te,qe=zs(v);return jsx(k.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,v==="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,v==="error"&&!Ce?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,Ce?jsxs("div",{className:"fk:space-y-5 fk:rounded-md fk:bg-background fk:corner-squircle",children:[L.map(R=>jsx(Bs,{api:t,message:R},R.id)),de.map(R=>jsx(t$1,{api:t,message:p(R)},R.id)),Me?jsx(s,{label:we,visible:Ue}):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:[v==="unavailable"||v==="error"?jsx(TriangleAlertIcon,{className:"fk:size-4"}):jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:qe})]})]})})}function Bs({api:t,message:n}){let o=n.role==="user",i=n.parts.filter(l=>!d$1(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,p)=>jsx(q,{api:t,part:l,partIndex:p,parts:i},p))})]})}
2
+ export{_i as ApprovalsPage,Bi as AutomationDetailPage,zi as AutomationsPage,Fi as CreateAutomationPage,Hi as RunDetailPage,ji as RunHistoryPage,$i as RunsPage};//# sourceMappingURL=pages-IA7GOMMS.js.map
3
+ //# sourceMappingURL=pages-IA7GOMMS.js.map