@flexkit/automations 0.0.24 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +281 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import'./index.css';import {Bot,Plus,Ellipsis,Pencil,Trash2,LoaderCircle,ArrowLeft,Play,CoinsIcon,BrainIcon,Trash2Icon,TriangleAlertIcon,LoaderCircleIcon,BotIcon,HistoryIcon,ClockIcon,WebhookIcon,DatabaseZapIcon,PlusIcon,XIcon,ChevronsUpDownIcon,CheckIcon,RefreshCwIcon,ZapIcon,CopyIcon,KeyRoundIcon,ChevronDownIcon,TerminalIcon,SearchIcon,CheckCircle2Icon,CloudUploadIcon,FileTextIcon,DownloadIcon,MessageSquareIcon,SendIcon,CircleSlashIcon,XCircleIcon}from'lucide-react';import {useConfig,Outlet}from'@flexkit/studio';import {Tooltip,TooltipTrigger,SidebarTrigger,TooltipContent,Separator,ExternalLink,Button,Table,TableHeader,TableRow,TableHead,TableBody,TableCell,Badge,DropdownMenu,DropdownMenuTrigger,DropdownMenuContent,DropdownMenuItem,DropdownMenuSeparator,ScrollArea,Tabs,TabsList,TabsTrigger,SidebarProvider,SidebarInset,Label,Switch,Input,Textarea,Select,SelectTrigger,SelectValue,SelectContent,SelectItem,SidebarPanel,SidebarContent,SidebarGroup,SidebarMenu,SidebarMenuItem,SidebarMenuButton,SidebarRail,DropdownMenuSub,DropdownMenuSubTrigger,DropdownMenuSubContent,toast,DropdownMenuCheckboxItem}from'@flexkit/studio/ui';import {useNavigate,Link,useParams,useLocation,NavLink}from'react-router-dom';import {jsx,jsxs,Fragment as Fragment$1}from'react/jsx-runtime';import {useState,useTransition,useMemo,useRef,useEffect,useCallback,Fragment}from'react';import {parseJsonEventStream,uiMessageChunkSchema,readUIMessageStream}from'ai';import {formatDistance,format}from'date-fns';import Y from'swr';import zt from'swr/infinite';import {CronExpressionParser}from'cron-parser';var Xe=NavLink;function Oe(){let t=useLocation().pathname.endsWith("/automations/runs");return jsxs(SidebarPanel,{collapsible:"icon",variant:"inset",children:[jsx(SidebarContent,{children:jsx(SidebarGroup,{children:jsxs(SidebarMenu,{children:[jsx(SidebarMenuItem,{children:jsx(SidebarMenuButton,{asChild:true,isActive:!t,tooltip:"Automations",children:jsxs(Xe,{to:".",children:[jsx(BotIcon,{className:"fk:h-4 fk:w-4",strokeWidth:2}),jsx("span",{children:"Automations"})]})})}),jsx(SidebarMenuItem,{children:jsx(SidebarMenuButton,{asChild:true,isActive:t,tooltip:"Run History",children:jsxs(Xe,{to:"runs",children:[jsx(HistoryIcon,{className:"fk:h-4 fk:w-4",strokeWidth:2}),jsx("span",{children:"Run History"})]})})})]})})}),jsx(SidebarRail,{})]})}var ln="flexkit:sidebar:state";function qe(){let{currentProjectId:e}=useConfig(),t=document.cookie.split("; ").find(a=>a.startsWith(`${ln}=`))?.split("=")[1]!=="false";return e?jsxs(SidebarProvider,{className:"fk:h-full",defaultOpen:t,children:[jsx(Oe,{}),jsx(SidebarInset,{children:jsx("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:overflow-hidden fk:px-4 fk:pt-3",children:jsx("div",{className:"fk:flex fk:min-h-0 fk:flex-1 fk:flex-col",children:jsx(Outlet,{})})})})]}):jsx("main",{className:"fk:flex fk:h-full fk:flex-1 fk:items-center fk:justify-center fk:p-8 fk:text-sm fk:text-muted-foreground",children:"Select a project to manage automations."})}function un(){if(typeof window>"u")return "https://flexkit.io";let{hostname:e,protocol:t}=window.location;return e==="localhost"||e==="127.0.0.1"?"https://flexkit.test":e==="flexkit.test"||e.endsWith(".flexkit.test")?`${t}//flexkit.test`:"https://flexkit.io"}function dn(){if(typeof window>"u")return "flexkit.io";let{hostname:e}=window.location;return e==="localhost"||e==="127.0.0.1"||e==="flexkit.test"||e.endsWith(".flexkit.test")?"flexkit.test":"flexkit.io"}function We(e,t){return `https://${e}.api.${dn()}/automations/webhook/${encodeURIComponent(t)}`}function Ve(e){let t=`/api/flexkit/${e}`,a=`${t}/automations`;async function s(o,f){let i=await fetch(o,{credentials:"include",headers:{"Content-Type":"application/json",...f?.headers??{}},...f}),c=await i.json();if(!i.ok){let k=c&&typeof c=="object"&&"error"in c?String(c.error):"Request failed";throw new Error(k)}return c}return {cancelRun:async o=>s(`${a}/runs/${encodeURIComponent(o)}/cancel`,{method:"POST"}),createAutomation:async o=>s(a,{body:JSON.stringify(o),method:"POST"}),deleteAutomation:async o=>s(`${a}/${encodeURIComponent(o)}`,{method:"DELETE"}),getArtifactUrl:(o,f)=>{let i=f?.download?"?download=1":"";return `${a}/artifacts/${encodeURIComponent(o)}/content${i}`},getIntegrationManageUrl:o=>`${un()}/dashboard/${o}/${e}/integrations`,getRunArtifacts:async o=>s(`${a}/runs/${encodeURIComponent(o)}/artifacts`).then(f=>f.artifacts),getStreamUrl:o=>`${a}/runs/${encodeURIComponent(o)}/stream`,listChannels:async o=>{let f=await fetch(`${t}/integrations/${o}/channels`,{credentials:"include",headers:{"Content-Type":"application/json"}}),i=await f.json();if(f.ok)return {channels:i.channels??[],errorMessage:i.errorMessage,success:i.success??true};if(i.success===false)return {channels:i.channels??[],errorMessage:i.errorMessage??`Failed to load ${o==="slack"?"Slack":"Teams"} channels.`,success:false};let c=i.error?String(i.error):"Request failed";throw new Error(c)},runAutomation:async o=>s(`${a}/${encodeURIComponent(o)}/runs`,{method:"POST"}),updateAutomation:async(o,f)=>s(`${a}/${encodeURIComponent(o)}`,{body:JSON.stringify(f),method:"PATCH"})}}var I=async e=>{let t=await fetch(e,{credentials:"include"});if(!t.ok)throw new Error("Request failed");return await t.json()};function M(e){let t=`/api/flexkit/${e}/automations`;return {automation:a=>`${t}/${encodeURIComponent(a)}`,automationRuns:(a,s=0,o=25)=>`${t}/${encodeURIComponent(a)}/runs?offset=${s.toString()}&limit=${o.toString()}`,automations:t,creditBalance:`${t}/credits`,entities:`${t}/entities`,run:a=>`${t}/runs/${encodeURIComponent(a)}`,runHistory:(a,s=0,o=25)=>`${t}/runs?scope=${a}&offset=${s.toString()}&limit=${o.toString()}`,tools:a=>a?`${t}/${encodeURIComponent(a)}/tools`:`${t}/tools`}}var ce=["slack","teams"],tt=["create","update","delete"],pt="0 * * * *",En="0 9 * * *",Pn="0 9 * * 1",Dn="0 9 1 * *",zn=[{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}],$n=Array.from({length:24},(e,t)=>({label:`${t.toString().padStart(2,"0")}:00`,value:t}));function Ln(e){return !e.instructions&&!e.model&&!e.name&&Object.keys(e.toolErrors).length===0&&Object.keys(e.triggerErrors).length===0}function ne({id:e,message:t}){return t?jsxs("p",{className:"fk:flex fk:items-start fk:text-sm fk:text-warning fk:gap-1",id:e,role:"alert",children:[jsx(TriangleAlertIcon,{className:"fk:size-4 fk:shrink-0 fk:mt-0.5"}),t]}):null}function ke(){return crypto.randomUUID()}function Fn(e){return (e?.triggers??[]).map(t=>({...t,key:t.id??ke()}))}function Bn(){return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}function Un(){let e=crypto.getRandomValues(new Uint8Array(24));return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function _n(e){if(e===pt)return {kind:"hourly"};let t=/^0 (\d{1,2}) \* \* \*$/.exec(e);if(t)return {hour:Number(t[1]),kind:"daily"};let a=/^0 (\d{1,2}) \* \* ([0-6])$/.exec(e);return a?{day:Number(a[2]),hour:Number(a[1]),kind:"weekly"}:{kind:"custom"}}function gt(e,t,a){try{let s=CronExpressionParser.parse(e,{tz:t});return Array.from({length:a},()=>s.next().toDate())}catch{return []}}function ht(e,t){return new Intl.DateTimeFormat("en-US",{day:"numeric",hour:"numeric",minute:"2-digit",month:"short",timeZone:t,weekday:"short"}).format(e)}function vt(e,t){let a=e.trim();if(!a)return "Cron expression is required";let s=a.split(/\s+/).length;if(s<5||s>6)return `Expected 5 fields (min hour day month weekday), got ${s.toString()}`;try{return CronExpressionParser.parse(a,{tz:t}),null}catch{return "Invalid cron expression"}}function Hn(e,t,a){let s=e.filter(f=>!f.deprecated);if(t!=="edit"||!a)return s;let o=e.find(f=>f.id===a);return o?.deprecated?[o,...s.filter(f=>f.id!==a)]:!o&&!s.some(f=>f.id===a)?[{deprecated:true,effort:null,id:a,name:a},...s]:s}function Ce(e){return `${e.teamId??""}:${e.id}`}function jn(e,t){let a={};for(let s of [...e,...t])a[Ce(s)]=s;return Object.values(a)}function nt(e,t){return {...e,availableChannels:e.channels,channelsLoaded:!e.connected,enabled:e.connected&&t==="edit"&&e.enabled,loadingChannels:false}}function Jn(e,t){return {slack:nt(e.providers.slack,t),teams:nt(e.providers.teams,t)}}function Xn({channels:e,disabled:t,loading:a,onChange:s,onRefresh:o,provider:f,value:i}){let[c,k]=useState(false),[p,u]=useState(""),g=useRef(null),N=new Set(i.map(b=>b.id)),x=f==="slack"?"Slack":"Teams",E=e.filter(b=>b.name.toLowerCase().includes(p.toLowerCase()));useEffect(()=>{if(!c)return;function b(F){let{target:j}=F;!(j instanceof Node)||g.current?.contains(j)||k(false);}function S(F){F.key==="Escape"&&k(false);}return document.addEventListener("pointerdown",b),document.addEventListener("keydown",S),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("keydown",S);}},[c]);function w(b){if(N.has(b.id)){s(i.filter(S=>S.id!==b.id));return}s([...i,b]);}function H(b){s(i.filter(S=>S.id!==b));}return jsxs("div",{className:"fk:relative",ref:g,children:[jsxs(Button,{"aria-expanded":c,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:t,role:"combobox",type:"button",variant:"outline",onClick:()=>k(b=>!b),children:[jsx("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:gap-1",children:i.length===0?jsx("span",{className:"fk:text-muted-foreground",children:a?`Loading ${x} channels...`:`Select ${x} channels`}):i.map(b=>jsxs(Badge,{className:"fk:rounded-sm fk:bg-accent fk:text-xs",variant:"secondary",onClick:S=>{S.stopPropagation(),H(b.id);},children:[b.name,jsx(XIcon,{className:"fk:ml-1 fk:size-3 fk:cursor-pointer"})]},Ce(b)))}),jsx(ChevronsUpDownIcon,{className:"fk:size-4 fk:shrink-0 fk:opacity-50"})]}),c?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",children:[jsx("div",{className:"fk:border-b fk:p-2",children:jsx(Input,{className:"fk:h-8",placeholder:`Search ${x} channels...`,value:p,onChange:b=>u(b.target.value)})}),jsx("div",{className:"fk:max-h-56 fk:overflow-auto fk:p-1",children:E.length>0?E.map(b=>jsxs("button",{className:"fk:flex fk:w-full fk:items-center fk:rounded-sm fk:px-2 fk:py-1.5 fk:text-left fk:text-sm hover:fk:bg-accent",type:"button",onClick:()=>w(b),children:[jsx(CheckIcon,{className:`fk:mr-2 fk:size-4 ${N.has(b.id)?"fk:opacity-100":"fk:opacity-0"}`}),b.name]},Ce(b))):jsx("div",{className:"fk:px-2 fk:py-6 fk:text-center fk:text-sm fk:text-muted-foreground",children:a?"Loading channels...":"No channels found."})}),jsx("div",{className:"fk:border-t fk:border-border fk:p-2",children:jsx(Button,{className:"fk:h-8 fk:w-full fk:justify-start fk:text-xs",disabled:a,type:"button",variant:"ghost",onClick:o,children:a?jsxs(Fragment$1,{children:[jsx(LoaderCircleIcon,{className:"fk:mr-2 fk:size-3 fk:animate-spin"}),"Refreshing channels..."]}):jsxs(Fragment$1,{children:[jsx(RefreshCwIcon,{className:"fk:mr-2 fk:size-3"}),"Refresh channels"]})})})]}):null]})}function me({cron:e,timezone:t}){let[a]=gt(e,t,1);return a?jsxs("span",{className:"fk:text-sm fk:text-muted-foreground",children:["Next run ",ht(a,t)]}):null}function at({onChange:e,value:t}){return jsxs(Select,{value:t.toString(),onValueChange:a=>e(Number(a)),children:[jsx(SelectTrigger,{"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(SelectValue,{})}),jsx(SelectContent,{children:$n.map(a=>jsx(SelectItem,{value:a.value.toString(),children:a.label},a.value))})]})}function On({onChange:e,value:t}){return jsxs(Select,{value:t.toString(),onValueChange:a=>e(Number(a)),children:[jsx(SelectTrigger,{"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(SelectValue,{})}),jsx(SelectContent,{children:zn.map(a=>jsx(SelectItem,{value:a.value.toString(),children:a.label},a.value))})]})}function qn({onChange:e,timezone:t,value:a}){let[s,o]=useState(false),f=useRef(null),i=vt(a,t),c=i?[]:gt(a,t,3);return useEffect(()=>{if(!s)return;function k(u){let{target:g}=u;!(g instanceof Node)||f.current?.contains(g)||o(false);}function p(u){u.key==="Escape"&&o(false);}return document.addEventListener("pointerdown",k),document.addEventListener("keydown",p),()=>{document.removeEventListener("pointerdown",k),document.removeEventListener("keydown",p);}},[s]),jsxs("div",{className:"fk:relative",ref:f,children:[jsxs("button",{className:"fk:flex fk:items-center fk:gap-1.5 fk:rounded-md fk:bg-background/90 fk:px-2 fk:py-1 fk:font-mono fk:text-sm fk:shadow-sm hover:fk:bg-accent",type:"button",onClick:()=>o(k=>!k),children:[a||"Set cron",jsx(ChevronDownIcon,{className:"fk:size-3.5 fk:opacity-50"})]}),s?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",children:[jsxs("div",{className:"fk:mb-2 fk:text-xs fk:text-muted-foreground",children:["Cron expression (",t,")"]}),jsx(Input,{className:`fk:h-8 fk:font-mono ${i?"fk:border-destructive focus-visible:fk:ring-destructive":""}`,value:a,onChange:k=>e(k.target.value)}),i?jsx("p",{className:"fk:mt-2 fk:text-xs fk:text-destructive",children:i}):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"}),c.map(k=>jsx("p",{children:ht(k,t)},k.toISOString()))]})]}):null]})}function Wn({onChange:e,trigger:t}){let a=_n(t.cron);return a.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(me,{cron:t.cron,timezone:t.timezone})]}):a.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(at,{value:a.hour,onChange:s=>e({...t,cron:`0 ${s.toString()} * * *`})}),jsx("span",{className:"fk:text-muted-foreground",children:t.timezone}),jsx(me,{cron:t.cron,timezone:t.timezone})]}):a.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(On,{value:a.day,onChange:s=>e({...t,cron:`0 ${a.hour.toString()} * * ${s.toString()}`})}),jsx("span",{children:"at"}),jsx(at,{value:a.hour,onChange:s=>e({...t,cron:`0 ${s.toString()} * * ${a.day.toString()}`})}),jsx("span",{className:"fk:text-muted-foreground",children:t.timezone}),jsx(me,{cron:t.cron,timezone:t.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(qn,{timezone:t.timezone,value:t.cron,onChange:s=>e({...t,cron:s})}),jsx("span",{className:"fk:text-muted-foreground",children:t.timezone}),jsx(me,{cron:t.cron,timezone:t.timezone})]})}function Vn({onChange:e,projectId:t,trigger:a}){let[s,o]=useState(false),[f,i]=useState(false),c=a.url??We(t,a.token);function k(p,u){navigator.clipboard.writeText(p).then(()=>{u(true),window.setTimeout(()=>u(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(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsxs("button",{className:"fk:flex fk:min-w-0 fk:max-w-60 fk:items-center fk:gap-1.5 fk:rounded-md fk:bg-background/90 fk:px-2 fk:py-1 fk:text-xs fk:shadow-sm hover:fk:bg-accent",type:"button",onClick:()=>k(c,o),children:[jsx("span",{className:"fk:truncate",children:c}),s?jsx(CheckIcon,{className:"fk:size-3.5 fk:shrink-0"}):jsx(CopyIcon,{className:"fk:size-3.5 fk:shrink-0 fk:opacity-60"})]})}),jsx(TooltipContent,{className:"fk:max-w-96 fk:break-all",children:c})]}),a.secret?jsxs(Button,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>k(`Bearer ${a.secret??""}`,i),children:[f?jsx(CheckIcon,{className:"fk:size-3.5"}):jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Copy auth header"]}):jsxs(Button,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>e({...a,secret:Un()}),children:[jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Generate auth header"]})]})}function Kn({entities:e,onChange:t,trigger:a}){function s(i){let c=a.events.includes(i)?a.events.filter(k=>k!==i):[...a.events,i];t({...a,events:tt.filter(k=>c.includes(k))});}function o(i){let c=a.entities.includes(i)?a.entities.filter(k=>k!==i):[...a.entities,i];t({...a,entities:c});}let f=a.entities.length>0?a.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:tt.map(i=>jsxs(Button,{className:"fk:h-7 fk:px-2.5 fk:text-xs fk:capitalize",size:"sm",type:"button",variant:a.events.includes(i)?"secondary":"ghost",onClick:()=>s(i),children:[a.events.includes(i)?jsx(CheckIcon,{className:"fk:size-3"}):null,i]},i))}),jsx("span",{children:"of"}),jsxs(DropdownMenu,{children:[jsx(DropdownMenuTrigger,{asChild:true,children:jsxs(Button,{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:f}),jsx(ChevronDownIcon,{className:"fk:size-3.5 fk:opacity-50"})]})}),jsx(DropdownMenuContent,{align:"start",className:"fk:max-h-64 fk:w-56 fk:overflow-auto",children:e.length===0?jsx(DropdownMenuItem,{disabled:true,children:"No entities found in the project schema"}):e.map(i=>jsx(DropdownMenuCheckboxItem,{checked:a.entities.includes(i),onCheckedChange:()=>o(i),onSelect:c=>c.preventDefault(),children:i},i))})]})]})}function Gn({entities:e,errors:t,onChange:a,projectId:s,triggers:o}){let f=o.some(u=>u.type==="webhook");function i(u){a([...o,u]);}function c(u){i({cron:u,key:ke(),timezone:Bn(),type:"schedule"});}function k(u){a(o.map(g=>g.key===u.key?u:g));}function p(u){a(o.filter(g=>g.key!==u));}return jsxs("div",{className:"fk:rounded-lg fk:border fk:bg-muted/60 fk:dark:bg-muted/30",children:[o.map(u=>jsxs(Fragment,{children:[jsxs("div",{className:"fk:group fk:rounded-md fk:m-1.5 fk:p-1.5 fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-3",children:[u.type==="schedule"?jsx(ClockIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,u.type==="webhook"?jsx(WebhookIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,u.type==="entity"?jsx(DatabaseZapIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,u.type==="schedule"?jsx(Wn,{trigger:u,onChange:k}):null,u.type==="webhook"?jsx(Vn,{projectId:s,trigger:u,onChange:k}):null,u.type==="entity"?jsx(Kn,{entities:e,trigger:u,onChange:k}):null,jsx(Button,{"aria-label":"Remove trigger",className:"fk:opacity-0 fk:group-hover:opacity-100",size:"icon",type:"button",variant:"ghost",onClick:()=>p(u.key),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})})]}),t[u.key]?jsx("div",{className:"fk:mt-1 fk:pl-7",children:jsx(ne,{message:t[u.key]})}):null]},u.key),jsx(Separator,{className:"fk:h-4"})]},u.key)),jsxs(DropdownMenu,{children:[jsx(DropdownMenuTrigger,{asChild:true,children:jsxs("button",{className:"fk:flex fk:w-full fk:items-center fk:gap-3 fk:rounded-b-lg fk:px-3 fk:py-3 fk:text-sm fk:text-muted-foreground hover:fk:bg-muted hover:fk:text-foreground",type:"button",children:[jsx(PlusIcon,{className:"fk:size-4"}),"Add Trigger"]})}),jsxs(DropdownMenuContent,{align:"start",className:"fk:w-56",children:[jsxs(DropdownMenuSub,{children:[jsxs(DropdownMenuSubTrigger,{children:[jsx(ClockIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Scheduled"]}),jsxs(DropdownMenuSubContent,{children:[jsx(DropdownMenuItem,{onClick:()=>c(pt),children:"Hourly"}),jsx(DropdownMenuItem,{onClick:()=>c(En),children:"Daily"}),jsx(DropdownMenuItem,{onClick:()=>c(Pn),children:"Weekly"}),jsx(DropdownMenuItem,{onClick:()=>c(Dn),children:"Custom (cron)"})]})]}),jsxs(DropdownMenuItem,{disabled:f,onClick:()=>i({key:ke(),secret:null,token:crypto.randomUUID(),type:"webhook"}),children:[jsx(WebhookIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Webhook Triggered"]}),jsxs(DropdownMenuItem,{onClick:()=>i({entities:[],events:["create"],key:ke(),type:"entity"}),children:[jsx(DatabaseZapIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Entity Events"]})]})]})]})}function Zn(){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 Qn(){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 ze({api:e,automation:t,mode:a,onSaved:s,projectId:o}){let[f,i]=useState(t?.name??""),[c,k]=useState(t?.instructions??""),[p,u]=useState(t?.enabled??false),[g,N]=useState(t?.modelId??""),[x,E]=useState(()=>Fn(t)),[w,H]=useState(false),[b,S]=useState(""),[F,j]=useState({instructions:false,name:false}),[T,J]=useState(null),Xt=M(o).tools(t?.id),{data:B}=Y(Xt,I),{data:Ot}=Y(M(o).entities,I),He=useMemo(()=>Hn(B?.tools.models??[],a,g||t?.modelId||""),[t?.modelId,a,g,B?.tools.models]),fe=g||He[0]?.id||"",$=useMemo(()=>{let m={};for(let y of x){if(y.type==="schedule"){let v=vt(y.cron,y.timezone);v&&(m[y.key]=v);}y.type==="entity"&&y.events.length===0&&(m[y.key]="Select at least one event (create, update or delete)");}let h={};for(let y of ce){let v=T?.[y];v?.enabled&&v.channels.length===0&&(h[y]=`Select at least one ${y==="slack"?"Slack":"Teams"} channel or remove the tool`);}return {instructions:c.trim()?"":"Instructions are required",model:fe?"":"Select a model",name:f.trim()?"":"Name is required",toolErrors:h,triggerErrors:m}},[fe,c,f,T,x]),we=Ln($),ue=F.name&&!!$.name,te=F.instructions&&!!$.instructions;useEffect(()=>{B?.tools&&J(Jn(B.tools,a));},[t?.id,a,B?.tools]);let Se=useCallback(async m=>{J(h=>h&&{...h,[m]:{...h[m],channelsLoadError:void 0,loadingChannels:true}});try{let h=await e.listChannels(m),y=h.success?void 0:h.errorMessage??`Failed to load ${m==="slack"?"Slack":"Teams"} channels.`;J(v=>v&&{...v,[m]:{...v[m],availableChannels:jn(v[m].channels,h.channels),channelsLoadError:y,channelsLoaded:!0,loadingChannels:!1}});}catch(h){let y=h instanceof Error?h.message:"Failed to load integration channels.";J(v=>v&&{...v,[m]:{...v[m],channelsLoadError:y,channelsLoaded:true,loadingChannels:false}});}},[e]);useEffect(()=>{if(T)for(let m of ce){let h=T[m];h.connected&&!h.channelsLoaded&&!h.loadingChannels&&Se(m);}},[Se,T]);function Re(m,h){J(y=>y&&{...y,[m]:{...y[m],...h}});}function qt(m){Re(m,{channels:[],enabled:false});}async function Wt(m){if(m.preventDefault(),!we){j({instructions:true,name:true});return}H(true),S("");let h=ce.map(v=>{let U=T?.[v]??B?.tools.providers[v];return {channels:U?.channels??[],enabled:U?.enabled??false,provider:v}}),y={enabled:p,instructions:c,modelId:fe,name:f,toolConfigs:h,triggers:x.map(({key:v,...U})=>U)};try{let v=a==="create"||!t?await e.createAutomation(y):await e.updateAutomation(t.id,y);if(!v.success){S(Array.isArray(v.errorMessage)?v.errorMessage.join(", "):v.errorMessage);return}toast.success(a==="create"||!t?"Automation created.":"Automation saved."),s(v.automation);}catch(v){S(v instanceof Error?v.message:"Failed to save automation.");}finally{H(false);}}return jsxs("form",{className:"fk:max-w-3xl fk:space-y-8 fk:px-1 fk:mx-auto",onSubmit:m=>{Wt(m);},children:[b?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",children:b}):null,jsxs("div",{className:"fk:space-y-3",children:[jsx(Label,{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(Switch,{checked:p,id:"automation-enabled",onCheckedChange:u}),jsx(Label,{className:"fk:font-normal",htmlFor:"automation-enabled",children:p?"Active":"Inactive"})]})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(Label,{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(Input,{"aria-describedby":ue?"automation-name-error":void 0,"aria-invalid":ue,className:ue?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"automation-name",value:f,onBlur:()=>j(m=>({...m,name:true})),onChange:m=>i(m.target.value)}),ue?jsx(ne,{id:"automation-name-error",message:$.name}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(Label,{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(Gn,{entities:Ot?.entities??[],errors:$.triggerErrors,projectId:o,triggers:x,onChange:E})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(Label,{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 ${te?"fk:border-destructive":"fk:border-input"}`,children:jsx(Textarea,{"aria-describedby":te?"automation-instructions-error":void 0,"aria-invalid":te,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)]",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:c,onBlur:()=>j(m=>({...m,instructions:true})),onChange:m=>k(m.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 ${te?"fk:border-destructive":"fk:border-input"}`,children:jsxs(Select,{value:fe,onValueChange:N,children:[jsx(SelectTrigger,{"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(SelectValue,{placeholder:"Select a model"})}),jsx(SelectContent,{align:"start",children:He.map(m=>jsxs(SelectItem,{value:m.id,children:[m.name,m.deprecated?" (Legacy)":""]},m.id))})]})})]}),te?jsx(ne,{id:"automation-instructions-error",message:$.instructions}):null,B&&$.model?jsx(ne,{message:$.model}):null]}),jsxs("div",{className:"fk:space-y-4",children:[jsxs("div",{children:[jsx(Label,{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",children:[jsx("div",{className:"fk:rounded-t-lg",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",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(Badge,{className:"fk:mt-1.5 fk:py-0 fk:text-[10px] fk:font-light fk:tracking-wide",variant:"secondary",children:"Always on"})]})}),T?ce.map(m=>{let h=T[m];return jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:p-1.5 fk:hover:bg-muted",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(m==="slack"?Zn:Qn,{}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:m==="slack"?"Send to Slack":"Send to Microsoft Teams"}),h.workspaceName?jsxs("p",{className:"fk:text-xs fk:text-muted-foreground",children:["Connected to ",h.workspaceName]}):null]})]}),h.connected?h.enabled?jsx(Button,{"aria-label":`Remove ${m==="slack"?"Slack":"Microsoft Teams"} from automation`,size:"icon",type:"button",variant:"ghost",onClick:()=>qt(m),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})}):jsx(Button,{size:"sm",type:"button",variant:"outline",onClick:()=>Re(m,{enabled:true}),children:"Add"}):jsx(Button,{disabled:!B?.tools.teamId,size:"sm",type:"button",variant:"outline",onClick:()=>{let U=B?.tools.teamId;U&&window.open(e.getIntegrationManageUrl(U),"_blank","noopener,noreferrer");},children:"Manage"})]}),h.connected?null:jsxs("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:["Connect ",m==="slack"?"Slack":"Microsoft Teams"," in Project Integrations before using it in an automation."]}),h.connected&&h.enabled?jsxs("div",{className:"fk:space-y-2 fk:pl-7",children:[jsx(Label,{className:"fk:mr-3 fk:text-xs fk:font-medium",children:"Channels"}),jsx(Xn,{channels:h.availableChannels,disabled:h.loadingChannels,loading:h.loadingChannels,provider:m,value:h.channels,onChange:U=>Re(m,{channels:U}),onRefresh:()=>{Se(m);}}),h.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"}),h.channelsLoadError]}):null,!h.channelsLoadError&&$.toolErrors[m]?jsx(ne,{message:$.toolErrors[m]}):null]}):null]},m)}):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:flex fk:items-center fk:justify-end fk:gap-3",children:[we?null:jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Complete the required fields to save"}),jsx(Button,{disabled:w||!we,type:"submit",children:w?"Saving...":a==="create"?"Create automation":"Update automation"})]})]})}function ee(){let{currentProjectId:e}=useConfig();return {api:useMemo(()=>e?Ve(e):null,[e]),projectId:e}}function z({children:e}){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",children:e})}function Ra({status:e}){return jsx(Badge,{className:`fk:border-none fk:h-[19px] fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide ${e==="success"?"fk:bg-success/20 fk:text-success":"fk:bg-secondary fk:text-secondary-foreground"}`,variant:e==="success"?"default":"secondary",children:e})}function Ca(e){if(e==="0 * * * *")return "Every hour";let t=/^0 (\d{1,2}) \* \* \*$/.exec(e);if(t)return `Every day at ${t[1].padStart(2,"0")}:00`;let a=/^0 (\d{1,2}) \* \* ([0-6])$/.exec(e);return a?`Every ${["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][Number(a[2])]??"week"} at ${a[1].padStart(2,"0")}:00`:e}function Aa(e){let t=e.triggers.map(a=>{if(a.type==="schedule")return Ca(a.cron);if(a.type==="webhook")return "Webhook";let s=a.entities.length>0?a.entities.join(", "):"all entities";return `On ${a.events.join("/")} of ${s}`});return t.length===0?"Manual only":t.join(" \xB7 ")}function $t(e){return e?!!(e.name.trim()&&e.instructions.trim()&&e.modelId.trim()):false}function Ia({projectId:e}){let{data:t}=Y(M(e).creditBalance,I),a=t?.creditBalance;return a?jsx(Button,{asChild:true,size:"sm",variant:"secondary",children:jsxs("a",{href:a.billingUrl,rel:"noopener noreferrer",target:"_blank",children:[jsx(CoinsIcon,{className:"fk:mr-2 fk:size-4"}),a.display," Credit"]})}):null}function Lt(){let{api:e,projectId:t}=ee(),a=useNavigate(),{data:s,mutate:o}=Y(t?M(t).automations:null,I),[f,i]=useState("");if(!t||!e)return jsx(z,{children:"Select a project to view automations."});let c=[...s?.automations??[]].sort((p,u)=>{let g=p.lastRunAt?new Date(p.lastRunAt).getTime():0;return (u.lastRunAt?new Date(u.lastRunAt).getTime():0)-g});async function k(p){if(i(""),!e)return;let u=await e.deleteAutomation(p.id);if(!u.success){i(Array.isArray(u.errorMessage)?u.errorMessage.join(", "):u.errorMessage);return}await o();}return jsxs("div",{className:"fk:space-y-6 fk:h-full",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(SidebarTrigger,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(TooltipContent,{children:"Toggle Sidebar"})]}),jsx(Separator,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsxs("div",{className:"fk:flex-1",children:[jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:"Automations"}),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(ExternalLink,{href:"https://flexkit.io/docs/automations",children:"Learn more"})]})]}),jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:justify-end fk:gap-3",children:[jsx(Ia,{projectId:t}),jsx(Button,{asChild:true,size:"sm",children:jsxs(Link,{to:"new",children:[jsx(Plus,{className:"fk:mr-2 fk:size-4"}),"New Automation"]})})]})]}),f?jsx("div",{className:"fk:text-sm fk:text-destructive",children:f}):null,c.length===0?jsx(z,{children:"No automations yet."}):jsxs(Table,{children:[jsx(TableHeader,{children:jsxs(TableRow,{children:[jsx(TableHead,{children:"Automation"}),jsx(TableHead,{children:"Triggers"}),jsx(TableHead,{children:"Last run"}),jsx(TableHead,{className:"fk:text-center",children:"Runs"}),jsx(TableHead,{className:"fk:text-center",children:"Status"}),jsx(TableHead,{})]})}),jsx(TableBody,{children:c.map(p=>jsxs(TableRow,{className:"fk:cursor-pointer",onClick:()=>a(p.id),children:[jsx(TableCell,{children:jsx("div",{className:"fk:font-medium",children:p.name})}),jsx(TableCell,{className:"fk:text-muted-foreground",children:Aa(p)}),jsx(TableCell,{children:p.lastRunAt?formatDistance(new Date(p.lastRunAt),new Date,{addSuffix:true}):"Never"}),jsx(TableCell,{className:"fk:text-center",children:p.totalRuns}),jsx(TableCell,{className:"fk:text-center",children:jsx(Badge,{className:`fk:border-none fk:h-[19px] fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide ${p.enabled?"fk:bg-success/20 fk:text-success":"fk:bg-secondary fk:text-secondary-foreground"}`,variant:p.enabled?"default":"secondary",children:p.enabled?"Enabled":"Disabled"})}),jsx(TableCell,{className:"fk:text-right",children:jsxs(DropdownMenu,{children:[jsx(DropdownMenuTrigger,{asChild:true,children:jsx(Button,{"aria-label":`Actions for ${p.name}`,size:"icon",type:"button",variant:"ghost",onClick:u=>{u.stopPropagation();},children:jsx(Ellipsis,{className:"fk:size-4"})})}),jsxs(DropdownMenuContent,{align:"end",className:"fk:w-40",children:[jsxs(DropdownMenuItem,{onClick:u=>{u.stopPropagation(),a(p.id);},children:[jsx(Pencil,{}),"Edit"]}),jsx(DropdownMenuSeparator,{}),jsxs(DropdownMenuItem,{variant:"destructive",onClick:u=>{u.stopPropagation(),k(p);},children:[jsx(Trash2,{}),"Delete"]})]})]})})]},p.id))})]})]})}function Ft(){let{api:e,projectId:t}=ee(),a=useNavigate();return !t||!e?jsx(z,{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(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(SidebarTrigger,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(TooltipContent,{children:"Toggle Sidebar"})]}),jsx(Separator,{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(Button,{asChild:true,className:"fk:shrink-0 fk:w-fit",size:"sm",variant:"ghost",children:jsxs(Link,{to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(ScrollArea,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:jsx(ze,{api:e,mode:"create",projectId:t,onSaved:()=>a("..")})})})]})}function Bt(){let{api:e,projectId:t}=ee(),{automationId:a}=useParams(),s=useNavigate(),[o,f]=useTransition(),{data:i,mutate:c}=Y(t&&a?M(t).automation(a):null,I);if(!t||!e||!a)return jsx(z,{children:"Select an automation."});if(!i?.automation)return jsx(z,{children:"Loading automation..."});let k=e,p=$t(i.automation),u=a;function g(){p&&f(async()=>{let N=await k.runAutomation(u);if(N.success&&N.runId){s(`runs/${N.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(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(SidebarTrigger,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(TooltipContent,{children:"Toggle Sidebar"})]}),jsx(Separator,{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:i.automation.name})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-center fk:justify-between fk:gap-3",children:[jsx(Button,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(Tabs,{value:"settings",children:jsxs(TabsList,{children:[jsx(TabsTrigger,{className:"text-xs",value:"settings",children:"Settings"}),jsx(TabsTrigger,{className:"text-xs",value:"runs",children:jsx(Link,{to:"runs",children:"Runs"})})]})}),jsxs(Button,{disabled:o||!p,size:"sm",onClick:g,children:[o?jsx(LoaderCircle,{className:"fk:mr-2 fk:size-4 fk:animate-spin"}):jsx(Play,{className:"fk:mr-2 fk:size-4"}),"Run now"]})]}),jsx(ScrollArea,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:jsx(ze,{api:e,automation:i.automation,mode:"edit",projectId:t,onSaved:N=>{N?c({automation:N},{revalidate:false}):c();}})})})]})}var xe=25;function Ut(){let{api:e,projectId:t}=ee(),{automationId:a}=useParams(),s=useNavigate(),[o,f]=useTransition(),{data:i}=Y(t&&a?M(t).automation(a):null,I),c=(T,J)=>!t||!a||J&&J.hasMore===false?null:M(t).automationRuns(a,T*xe,xe),{data:k,mutate:p,setSize:u,size:g}=zt(c,I);if(!t||!e||!a)return jsx(z,{children:"Select an automation to view runs."});let N=e,x=$t(i?.automation),E=a;function w(){x&&f(async()=>{let T=await N.runAutomation(E);if(T.success&&T.runId){s(T.runId);return}await p();});}let H=k?.flatMap(T=>T.runs)??[],S=k?.[k.length-1]?.hasMore??false,F=k!==void 0&&g>k.length;function j(){u(T=>T+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(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(SidebarTrigger,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(TooltipContent,{children:"Toggle Sidebar"})]}),jsx(Separator,{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:i?.automation.name??"Automation"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-center fk:justify-between fk:gap-3",children:[jsx(Button,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(Tabs,{value:"runs",children:jsxs(TabsList,{children:[jsx(TabsTrigger,{className:"text-xs",value:"settings",children:jsx(Link,{relative:"path",to:"..",children:"Settings"})}),jsx(TabsTrigger,{className:"text-xs",value:"runs",children:"Runs"})]})}),jsxs(Button,{disabled:o||!x,size:"sm",onClick:w,children:[o?jsx(LoaderCircle,{className:"fk:mr-2 fk:size-4 fk:animate-spin"}):jsx(Play,{className:"fk:mr-2 fk:size-4"}),"Run now"]})]}),jsx(ScrollArea,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[jsx(Ht,{basePath:".",runs:H}),S&&!F?jsx(_t,{onVisible:j}):null,F?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 _t({onVisible:e}){let t=useRef(null),a=useRef(e);return a.current=e,useEffect(()=>{let s=t.current;if(!s)return;let o=new IntersectionObserver(f=>{f.some(i=>i.isIntersecting)&&a.current();});return o.observe(s),()=>{o.disconnect();}},[]),jsx("div",{className:"fk:h-px",ref:t})}function Ht({basePath:e,runs:t}){return t.length===0?jsx(z,{children:"No runs found."}):jsx(Table,{children:jsx(TableBody,{children:t.map(a=>jsxs(TableRow,{children:[jsx(TableCell,{className:"fk:py-2",children:jsx(Link,{className:"fk:font-medium hover:fk:underline",to:`${e}/${a.id}`,children:formatDistance(new Date(a.startedAt),new Date,{addSuffix:true})})}),jsx(TableCell,{className:"fk:text-muted-foreground",children:a.triggerType}),jsx(TableCell,{children:jsx(Ra,{status:a.status})}),jsx(TableCell,{className:"fk:max-w-md fk:truncate fk:text-muted-foreground",children:a.summary??""})]},a.id))})})}function jt(){let{projectId:e}=ee(),[t,a]=useState("team"),s=(x,E)=>!e||E&&!E.history.hasMore?null:M(e).runHistory(t,x*xe,xe),{data:o,setSize:f,size:i}=zt(s,I),c=o?.[0]?.history.metrics,k=o?.flatMap(x=>x.history.runs)??[],u=o?.[o.length-1]?.history.hasMore??false,g=o!==void 0&&i>o.length;if(!e)return jsx(z,{children:"Select a project to view run history."});function N(){f(x=>x+1);}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-6",children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:gap-2",children:[jsx(Button,{size:"sm",variant:t==="team"?"default":"outline",onClick:()=>a("team"),children:"Team"}),jsx(Button,{size:"sm",variant:t==="mine"?"default":"outline",onClick:()=>a("mine"),children:"Mine"})]}),c?jsxs("div",{className:"fk:grid fk:shrink-0 fk:gap-3 fk:md:grid-cols-4",children:[jsx(he,{title:"Successful 24h",value:c.successful24h}),jsx(he,{title:"Failed 24h",value:c.failed24h}),jsx(he,{title:"Successful 7d",value:c.successful7d}),jsx(he,{title:"Failed 7d",value:c.failed7d})]}):null,jsx(ScrollArea,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[jsx(Ht,{basePath:"..",runs:k.map(x=>({...x,id:`${x.automationId}/runs/${x.id}`}))}),u&&!g?jsx(_t,{onVisible:N}):null,g?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 he({title:e,value:t}){return jsxs("div",{className:"fk:rounded-md fk:bg-muted/60 fk:p-4",children:[jsx("div",{className:"fk:text-sm fk:text-muted-foreground",children:e}),jsx("div",{className:"fk:mt-1 fk:text-2xl fk:font-medium",children:t.toLocaleString()})]})}var Ma=5,Ea=2e3,Tt="data-spec";function Pa(e){return new Promise(t=>window.setTimeout(t,e))}function Da(e){return e instanceof Error?e.name==="AbortError"||e.message.toLowerCase().includes("aborted"):false}function za(e){return e.some(t=>t.type!=="step-start")}function $a(e){let t=new Set;for(let a of e)for(let s of a.parts)s.type==="data-user-message"&&s.id&&t.add(s.id);return t}function La(e){let t=$a(e),a=[];for(let s of e){if(s.role==="user"){t.has(s.id)||a.push(s);continue}if(s.role!=="assistant"){a.push(s);continue}let o=[],f=0,i=()=>{za(o)&&a.push({...s,id:`${s.id}-${f.toString()}`,parts:o}),f++,o=[];};for(let c of s.parts){if(c.type==="data-user-message"){let k=A(c);i(),a.push({id:c.id??crypto.randomUUID(),parts:k.parts,role:"user"});continue}o.push(c);}i();}return a}function Fa(e){return useMemo(()=>La(e),[e])}function A(e){return e.data}function Ba(e,t){let[a,s]=useState(),[o,f]=useState("streaming");return useEffect(()=>{if(!e){s(void 0),f("unavailable");return}let i=new AbortController,c=async()=>{let u=await fetch(`${e}?startIndex=0`,{credentials:"include",signal:i.signal});if(u.status===404)return "unavailable";if(!u.ok||!u.body)throw new Error(`Failed to fetch the run stream (status ${u.status.toString()})`);let g=false,x=parseJsonEventStream({schema:uiMessageChunkSchema,stream:u.body}).pipeThrough(new TransformStream({transform:(w,H)=>{if(!w.success)throw w.error;w.value.type==="finish"&&(g=true),H.enqueue(w.value);}})),E=readUIMessageStream({onError:w=>{console.error("Automation run stream chunk error",w);},stream:x});for await(let w of E){if(i.signal.aborted)break;s({...w});}return g?"finished":"incomplete"},k=async()=>{for(let u=0;u<Ma;u++){u>0&&(await Pa(Ea),s(void 0));try{let g=await c();if(i.signal.aborted)return;if(g==="unavailable"){f("unavailable");return}if(g==="finished"){f("finished");return}}catch(g){if(i.signal.aborted||Da(g))return;console.error("Automation run stream error",g);}}f(t?.recordStatus==="running"?"streaming":"error");},p=window.setTimeout(()=>{k();},0);return ()=>{window.clearTimeout(p),i.abort("Run replay unmounted");}},[t?.recordStatus,e]),{message:a,status:o}}function Jt(){let{api:e,projectId:t}=ee(),{automationId:a,runId:s}=useParams(),{data:o,mutate:f}=Y(t&&s?M(t).run(s):null,I),{data:i}=Y(t&&a?M(t).automation(a):null,I),[c,k]=useTransition();if(!t||!e||!a||!s)return jsx(z,{children:"Select a run."});let p=e,u=s,g=o?.run;function N(){k(async()=>{await p.cancelRun(u),await f();});}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(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(SidebarTrigger,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(TooltipContent,{children:"Toggle Sidebar"})]}),jsx(Separator,{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:i?.automation.name??"Automation"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-start fk:justify-between fk:gap-3",children:[jsxs("div",{children:[jsx(Button,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{relative:"path",to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Runs"]})}),jsx("h2",{className:"fk:mt-4 fk:text-lg fk:font-medium",children:g?`Run from ${format(new Date(g.startedAt),"PPpp")}`:"Loading run..."})]}),g?.status==="running"?jsx(Button,{disabled:c,size:"sm",variant:"destructive",onClick:N,children:c?"Cancelling...":"Cancel run"}):null]}),jsx(ScrollArea,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4 fk:max-w-5xl fk:mx-auto",children:g?jsx(Ua,{api:e,run:g}):jsx(z,{children:"Loading run..."})})})]})}function Ua({api:e,run:t}){let{workflowRunId:a}=t,s=a?e.getStreamUrl(a):"",{message:o,status:f}=Ba(s,{recordStatus:t.status}),i=useMemo(()=>o?[o]:[],[o]),c=Fa(i);return a?jsxs("div",{className:"fk:space-y-4",children:[t.status==="failed"&&t.error?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-4 fk:text-sm",children:t.summary??t.error}):null,f==="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",children:"The workflow replay is no longer available. Generated artifacts may still be available below."}):null,f==="error"&&c.length===0?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-4 fk:text-sm",children:"Failed to load the run stream. Try reloading the page."}):null,c.length>0?jsxs("div",{className:"fk:space-y-5 fk:rounded-md fk:bg-background",children:[c.map(k=>jsx(_a,{api:e,message:k},k.id)),f==="streaming"?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:font-mono fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Running..."})]}):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",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:f==="unavailable"?"No replay events were recorded.":"Loading run replay..."})]})]}):jsx(z,{children:"The run has not started streaming yet."})}function _a({api:e,message:t}){let a=t.role==="user";return jsxs("div",{className:a?"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:a?jsxs(Fragment$1,{children:[jsx(ZapIcon,{className:"fk:ml-auto fk:size-4"}),jsx("span",{children:"Trigger"})]}):jsxs(Fragment$1,{children:[jsx(BotIcon,{className:"fk:size-4"}),jsxs("span",{children:["Agent",t.metadata?.model?` (${t.metadata.model})`:""]})]})}),jsx("div",{className:"fk:space-y-3 fk:min-w-0",children:t.parts.map((s,o)=>jsx(Ha,{api:e,part:s,partIndex:o,parts:t.parts},o))})]})}function Ha({api:e,part:t,partIndex:a,parts:s}){if(t.type==="step-start")return null;if(t.type==="text")return jsx(ja,{part:t});if(t.type==="reasoning")return jsx(Ja,{text:t.text});if(t.type==="data-generating-files")return jsx(Xa,{message:A(t)});if(t.type==="data-run-artifact")return jsx(Oa,{api:e,message:A(t)});if(t.type==="data-tool-delivery")return jsx(qa,{message:A(t)});if(t.type==="data-run-summary")return jsx(Wa,{message:A(t)});if(t.type==="data-run-command"){let o=A(t);return jsx(_,{error:o.error?.message,icon:jsx(TerminalIcon,{className:"fk:size-3.5"}),loading:["executing","running","waiting"].includes(o.status),message:o.status==="error"?o.error?.message??`Command failed: ${o.command}`:`${o.status==="done"?"Ran":"Running"} ${o.command} ${o.args.join(" ")}`,title:"Run command"})}if(t.type==="data-search-schema"){let o=A(t);return jsx(_,{error:o.error?.message,icon:jsx(SearchIcon,{className:"fk:size-3.5"}),loading:o.status==="loading",message:o.status==="error"?o.error?.message??"Failed to search schema":`${o.status==="done"?"Searched":"Searching"}${o.query?` "${o.query}"`:" schema"}`,title:"Search schema"})}if(t.type==="data-web-search"){let o=A(t);return jsx(_,{error:o.error?.message,icon:jsx(SearchIcon,{className:"fk:size-3.5"}),loading:o.status==="loading",message:o.status==="error"?o.error?.message??"Failed to search the web":`${o.status==="done"?"Searched":"Searching"} "${o.query}"`,title:"Web search"})}if(t.type==="data-validate-graphql"){let o=A(t);return jsx(_,{error:o.error?.message,icon:jsx(DatabaseZapIcon,{className:"fk:size-3.5"}),loading:o.status==="loading",message:Ga(o),title:"Validate GraphQL"})}if(t.type==="data-execute-graphql"){let o=A(t),f=o.operationType==="mutation"?"mutation":"query";return jsx(_,{error:o.error?.message,icon:jsx(DatabaseZapIcon,{className:"fk:size-3.5"}),loading:o.status==="loading",message:o.status==="error"?o.error?.message??`Failed to execute ${f}`:`${o.status==="done"?"Executed":"Executing"} ${f}`,title:"Execute GraphQL"})}if(t.type==="data-bulk-graphql-action")return jsx(Va,{message:A(t)});if(t.type==="data-update-memory"){let o=A(t);return jsx(_,{error:o.error?.message,icon:jsx(CheckCircle2Icon,{className:"fk:size-3.5"}),loading:o.status==="loading",message:o.status==="error"?o.error?.message??"Failed to update memory":o.status==="done"?"Updated automation memory":"Updating automation memory",title:"Update memory"})}if(t.type==="data-create-sandbox"){let o=A(t);return jsx(_,{error:o.error?.message,icon:jsx(TerminalIcon,{className:"fk:size-3.5"}),loading:o.status==="loading",message:o.status==="error"?o.error?.message??"Failed to create sandbox":o.status==="done"?"Created sandbox":"Creating sandbox",title:"Create sandbox"})}return t.type===Tt?s.slice(a+1).find(f=>f.type===Tt)?null:jsxs(K,{children:[jsxs(G,{children:[jsx(CheckCircle2Icon,{className:"fk:size-3.5"}),"Generated visual spec"]}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"A structured json-render response was generated for this run."})]}):t.type.startsWith("data-")?jsx(Ka,{part:t}):null}function ja({part:e}){return jsx("div",{className:"fk:min-w-0 fk:max-w-full fk:overflow-x-auto fk:whitespace-pre-wrap fk:rounded-xl fk:bg-muted fk:px-4 fk:py-3 fk:text-sm fk:font-light fk:leading-relaxed fk:text-secondary-foreground",children:e.text})}function Ja({text:e}){return jsxs(K,{className:"fk:bg-muted/30",children:[jsxs(G,{children:[jsx(BrainIcon,{className:"fk:size-3.5"}),"Reasoning"]}),jsx("p",{className:"fk:mt-2 fk:whitespace-pre-wrap fk:text-xs fk:text-muted-foreground",children:e})]})}function K({children:e,className:t=""}){return jsx("div",{className:`fk:min-w-0 fk:max-w-full fk:overflow-x-auto fk:rounded-xl fk:border fk:border-border fk:bg-background fk:px-3.5 fk:py-3 fk:text-sm ${t}`,children:e})}function G({children:e}){return jsx("div",{className:"fk:flex fk:items-center fk:gap-2 fk:font-medium fk:text-muted-foreground",children:e})}function _e({isError:e,loading:t}){return t?jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}):e?jsx(XIcon,{className:"fk:size-4 fk:text-red-700"}):jsx(CheckIcon,{className:"fk:size-4"})}function _({error:e,icon:t,loading:a,message:s,title:o}){return jsxs(K,{children:[jsxs(G,{children:[t,o]}),jsxs("div",{className:"fk:relative fk:min-h-5 fk:pl-6",children:[jsx("span",{className:"fk:absolute fk:left-0 fk:top-0",children:jsx(_e,{isError:!!e,loading:a})}),jsx("span",{className:"fk:text-xs",children:s})]})]})}function Xa({message:e}){let t=["error","uploading","generating"].includes(e.status),a=t?e.paths.slice(0,e.paths.length-1):e.paths,s=t?e.paths[e.paths.length-1]??"":null;return jsxs(K,{children:[jsxs(G,{children:[jsx(CloudUploadIcon,{className:"fk:size-3.5"}),jsx("span",{children:e.status==="done"?"Uploaded files":"Generating files"})]}),jsxs("div",{className:"fk:space-y-1 fk:text-sm",children:[a.map((o,f)=>jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(CheckIcon,{className:"fk:size-4"}),jsx("span",{className:"fk:whitespace-pre-wrap",children:o})]},`${o}-${f.toString()}`)),typeof s=="string"?jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(_e,{isError:e.status==="error",loading:e.status!=="error"}),jsx("span",{children:e.status==="error"?e.error?.message??s:s})]}):null]})]})}function Oa({api:e,message:t}){let a=t.status==="done"&&t.artifactId,s=a?e.getArtifactUrl(t.artifactId??""):"",o=a?e.getArtifactUrl(t.artifactId??"",{download:true}):"",f=Za(t.sizeBytes);return jsxs(K,{children:[jsxs(G,{children:[jsx(FileTextIcon,{className:"fk:size-3.5"}),t.status==="done"?"Published artifact":"Publishing artifact"]}),jsxs("div",{className:"fk:relative fk:min-h-5 fk:pl-6",children:[jsx("span",{className:"fk:absolute fk:left-0 fk:top-0",children:jsx(_e,{isError:t.status==="error",loading:t.status==="uploading"})}),jsxs("div",{className:"fk:min-w-0 fk:space-y-2",children:[jsxs("div",{className:"fk:min-w-0",children:[jsx("div",{className:"fk:truncate fk:font-medium",children:t.filename}),jsxs("div",{className:"fk:text-xs fk:text-muted-foreground",children:[t.status==="uploading"&&"Uploading to artifacts",t.status==="done"&&[Qa(t),f].filter(Boolean).join(" \xB7 "),t.status==="error"&&(t.error?.message??"Failed to publish artifact")]})]}),a?jsxs("div",{className:"fk:flex fk:flex-wrap fk:gap-2",children:[jsx(Button,{asChild:true,size:"sm",variant:"outline",children:jsx("a",{href:s,rel:"noreferrer",target:"_blank",children:"Preview"})}),jsx(Button,{asChild:true,size:"sm",variant:"outline",children:jsxs("a",{href:o,children:[jsx(DownloadIcon,{className:"fk:size-3"}),"Download"]})})]}):null]})]})]})}function qa({message:e}){let t=e.provider==="slack"?"Slack":"Microsoft Teams",a=e.provider==="slack"?jsx(MessageSquareIcon,{className:"fk:size-3.5"}):jsx(SendIcon,{className:"fk:size-3.5"});return jsx(_,{error:e.error?.message,icon:a,loading:e.status==="loading",message:e.status==="error"?e.error?.message??`Failed to send result to ${e.channelName}`:`${e.status==="done"?"Sent":"Sending"} result to ${e.channelName}`,title:`${t} Delivery`})}function Wa({message:e}){let t=e.status==="success"?jsx(CheckCircle2Icon,{className:"fk:size-3.5 fk:text-green-700"}):e.status==="skipped"?jsx(CircleSlashIcon,{className:"fk:size-3.5"}):jsx(XCircleIcon,{className:"fk:size-3.5 fk:text-red-700"}),a=e.status==="success"?"Run completed":e.status==="skipped"?"Run skipped":"Run failed";return jsxs(K,{className:e.status==="failed"?"fk:border-red-700/40":"fk:border-green-700/40",children:[jsxs(G,{children:[t,jsx("span",{children:a})]}),e.status==="failed"?jsx("p",{className:"fk:whitespace-pre-wrap fk:text-xs",children:e.summary}):null]})}function Va({message:e}){let t=[typeof e.processedItems=="number"?`${e.processedItems.toString()} processed`:"",typeof e.changedItems=="number"?`${e.changedItems.toString()} changed`:"",typeof e.failedItems=="number"?`${e.failedItems.toString()} failed`:"",typeof e.totalItems=="number"?`${e.totalItems.toString()} total`:""].filter(Boolean);return jsx(_,{error:e.error?.message,icon:jsx(DatabaseZapIcon,{className:"fk:size-3.5"}),loading:e.status==="loading"||e.status==="running",message:e.status==="error"?e.error?.message??`Failed bulk ${e.operationName}`:`${e.status==="done"?"Completed":"Running"} ${e.operationName}${t.length>0?` (${t.join(", ")})`:""}`,title:"Bulk GraphQL action"})}function Ka({part:e}){return jsxs(K,{className:"fk:bg-muted/30",children:[jsxs(G,{children:[jsx(CheckCircle2Icon,{className:"fk:size-3.5"}),e.type.replace(/^data-/,"").replaceAll("-"," ")]}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"This run emitted a structured event that is not yet rendered by Studio."})]})}function Ga(e){if(e.status==="error")return e.error?.message??"Failed to validate GraphQL";if(e.status==="invalid"){let t=e.errorCount??0;return `Validation failed with ${t.toString()} ${t===1?"error":"errors"}`}return e.status==="valid"?"GraphQL operation is valid":"Validating GraphQL"}function Za(e){if(typeof e!="number")return "";if(e<1024)return `${e.toString()} B`;let t=e/1024;return t<1024?`${t.toFixed(1)} KB`:`${(t/1024).toFixed(1)} MB`}function Qa(e){return e.kind==="pdf"?"PDF artifact":e.kind==="html"?"HTML artifact":"Artifact"}function Ho(){return {name:"flexkit.automations",contributes:{apps:[{component:jsx(qe,{}),icon:jsx(Bot,{strokeWidth:1.5}),name:"automations",routes:[{component:jsx(Lt,{}),path:""},{component:jsx(jt,{}),path:"runs"},{component:jsx(Ft,{}),path:"new"},{component:jsx(Bt,{}),path:":automationId"},{component:jsx(Ut,{}),path:":automationId/runs"},{component:jsx(Jt,{}),path:":automationId/runs/:runId"}],title:"Automations"}]}}}
|
|
2
|
-
export{
|
|
1
|
+
import'./index.css';import {Bot,Plus,Ellipsis,Pencil,Trash2,LoaderCircle,ArrowLeft,Play,CoinsIcon,BrainIcon,Trash2Icon,TriangleAlertIcon,LoaderCircleIcon,BotIcon,HistoryIcon,ClockIcon,WebhookIcon,DatabaseZapIcon,PlusIcon,XIcon,ChevronsUpDownIcon,CheckIcon,RefreshCwIcon,ZapIcon,CopyIcon,KeyRoundIcon,ChevronDownIcon,TerminalIcon,SearchIcon,CheckCircle2Icon,CloudUploadIcon,FileTextIcon,DownloadIcon,MessageSquareIcon,SendIcon,CircleSlashIcon,XCircleIcon,TrendingUpIcon,TrendingDownIcon,MinusIcon,InfoIcon,OctagonAlertIcon,AlertTriangleIcon,LightbulbIcon}from'lucide-react';import {useConfig,Outlet}from'@flexkit/studio';import {Tooltip,TooltipTrigger,SidebarTrigger,TooltipContent,Separator,ExternalLink,Button,Table,TableHeader,TableRow,TableHead,TableBody,TableCell,Badge,DropdownMenu,DropdownMenuTrigger,DropdownMenuContent,DropdownMenuItem,DropdownMenuSeparator,ScrollArea,Tabs,TabsList,TabsTrigger,SidebarProvider,SidebarInset,Label,Switch,Input,Textarea,Select,SelectTrigger,SelectValue,SelectContent,SelectItem,SidebarPanel,SidebarContent,SidebarGroup,SidebarMenu,SidebarMenuItem,SidebarMenuButton,SidebarRail,DropdownMenuSub,DropdownMenuSubTrigger,DropdownMenuSubContent,toast,DropdownMenuCheckboxItem,TableCaption,TabsContent,Skeleton}from'@flexkit/studio/ui';import {useNavigate,Link,useParams,useLocation,NavLink}from'react-router-dom';import {jsx,jsxs,Fragment as Fragment$1}from'react/jsx-runtime';import {useState,useTransition,useMemo,useRef,useEffect,useCallback,Fragment,useId}from'react';import {parseJsonEventStream,uiMessageChunkSchema,readUIMessageStream}from'ai';import {formatDistance,format}from'date-fns';import Q from'swr';import Qt from'swr/infinite';import {CronExpressionParser}from'cron-parser';import {buildSpecFromParts,StateProvider,VisibilityProvider,ActionProvider,Renderer}from'@json-render/react';import {PieChart,Tooltip as Tooltip$1,Pie,Cell,LineChart,CartesianGrid,XAxis,YAxis,Line,BarChart,Bar,ResponsiveContainer}from'recharts';var Ye=NavLink;function Qe(){let t=useLocation().pathname.endsWith("/automations/runs");return jsxs(SidebarPanel,{collapsible:"icon",variant:"inset",children:[jsx(SidebarContent,{children:jsx(SidebarGroup,{children:jsxs(SidebarMenu,{children:[jsx(SidebarMenuItem,{children:jsx(SidebarMenuButton,{asChild:true,isActive:!t,tooltip:"Automations",children:jsxs(Ye,{to:".",children:[jsx(BotIcon,{className:"fk:h-4 fk:w-4",strokeWidth:2}),jsx("span",{children:"Automations"})]})})}),jsx(SidebarMenuItem,{children:jsx(SidebarMenuButton,{asChild:true,isActive:t,tooltip:"Run History",children:jsxs(Ye,{to:"runs",children:[jsx(HistoryIcon,{className:"fk:h-4 fk:w-4",strokeWidth:2}),jsx("span",{children:"Run History"})]})})})]})})}),jsx(SidebarRail,{})]})}var Rn="flexkit:sidebar:state";function et(){let{currentProjectId:e}=useConfig(),t=document.cookie.split("; ").find(n=>n.startsWith(`${Rn}=`))?.split("=")[1]!=="false";return e?jsxs(SidebarProvider,{className:"fk:h-full",defaultOpen:t,children:[jsx(Qe,{}),jsx(SidebarInset,{children:jsx("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:overflow-hidden fk:px-4 fk:pt-3",children:jsx("div",{className:"fk:flex fk:min-h-0 fk:flex-1 fk:flex-col",children:jsx(Outlet,{})})})})]}):jsx("main",{className:"fk:flex fk:h-full fk:flex-1 fk:items-center fk:justify-center fk:p-8 fk:text-sm fk:text-muted-foreground",children:"Select a project to manage automations."})}function Pn(){if(typeof window>"u")return "https://flexkit.io";let{hostname:e,protocol:t}=window.location;return e==="localhost"||e==="127.0.0.1"?"https://flexkit.test":e==="flexkit.test"||e.endsWith(".flexkit.test")?`${t}//flexkit.test`:"https://flexkit.io"}function In(){if(typeof window>"u")return "flexkit.io";let{hostname:e}=window.location;return e==="localhost"||e==="127.0.0.1"||e==="flexkit.test"||e.endsWith(".flexkit.test")?"flexkit.test":"flexkit.io"}function tt(e,t){return `https://${e}.api.${In()}/automations/webhook/${encodeURIComponent(t)}`}function nt(e){let t=`/api/flexkit/${e}`,n=`${t}/automations`;async function o(r,l){let i=await fetch(r,{credentials:"include",headers:{"Content-Type":"application/json",...l?.headers??{}},...l}),c=await i.json();if(!i.ok){let k=c&&typeof c=="object"&&"error"in c?String(c.error):"Request failed";throw new Error(k)}return c}return {cancelRun:async r=>o(`${n}/runs/${encodeURIComponent(r)}/cancel`,{method:"POST"}),createAutomation:async r=>o(n,{body:JSON.stringify(r),method:"POST"}),deleteAutomation:async r=>o(`${n}/${encodeURIComponent(r)}`,{method:"DELETE"}),getArtifactUrl:(r,l)=>{let i=l?.download?"?download=1":"";return `${n}/artifacts/${encodeURIComponent(r)}/content${i}`},getIntegrationManageUrl:r=>`${Pn()}/dashboard/${r}/${e}/integrations`,getRunArtifacts:async r=>o(`${n}/runs/${encodeURIComponent(r)}/artifacts`).then(l=>l.artifacts),getStreamUrl:r=>`${n}/runs/${encodeURIComponent(r)}/stream`,listChannels:async r=>{let l=await fetch(`${t}/integrations/${r}/channels`,{credentials:"include",headers:{"Content-Type":"application/json"}}),i=await l.json();if(l.ok)return {channels:i.channels??[],errorMessage:i.errorMessage,success:i.success??true};if(i.success===false)return {channels:i.channels??[],errorMessage:i.errorMessage??`Failed to load ${r==="slack"?"Slack":"Teams"} channels.`,success:false};let c=i.error?String(i.error):"Request failed";throw new Error(c)},runAutomation:async r=>o(`${n}/${encodeURIComponent(r)}/runs`,{method:"POST"}),updateAutomation:async(r,l)=>o(`${n}/${encodeURIComponent(r)}`,{body:JSON.stringify(l),method:"PATCH"})}}var M=async e=>{let t=await fetch(e,{credentials:"include"});if(!t.ok)throw new Error("Request failed");return await t.json()};function E(e){let t=`/api/flexkit/${e}/automations`;return {automation:n=>`${t}/${encodeURIComponent(n)}`,automationRuns:(n,o=0,r=25)=>`${t}/${encodeURIComponent(n)}/runs?offset=${o.toString()}&limit=${r.toString()}`,automations:t,creditBalance:`${t}/credits`,entities:`${t}/entities`,run:n=>`${t}/runs/${encodeURIComponent(n)}`,runHistory:(n,o=0,r=25)=>`${t}/runs?scope=${n}&offset=${o.toString()}&limit=${r.toString()}`,tools:n=>n?`${t}/${encodeURIComponent(n)}/tools`:`${t}/tools`}}var ke=["slack","teams"],ft=["create","update","delete"],wt="0 * * * *",Gn="0 9 * * *",Zn="0 9 * * 1",Yn="0 9 1 * *",Qn=[{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}],ea=Array.from({length:24},(e,t)=>({label:`${t.toString().padStart(2,"0")}:00`,value:t}));function ta(e){return !e.instructions&&!e.model&&!e.name&&Object.keys(e.toolErrors).length===0&&Object.keys(e.triggerErrors).length===0}function re({id:e,message:t}){return t?jsxs("p",{className:"fk:flex fk:items-start fk:text-sm fk:text-warning fk:gap-1",id:e,role:"alert",children:[jsx(TriangleAlertIcon,{className:"fk:size-4 fk:shrink-0 fk:mt-0.5"}),t]}):null}function ge(){return crypto.randomUUID()}function na(e){return (e?.triggers??[]).map(t=>({...t,key:t.id??ge()}))}function aa(){return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}function ra(){let e=crypto.getRandomValues(new Uint8Array(24));return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function oa(e){if(e===wt)return {kind:"hourly"};let t=/^0 (\d{1,2}) \* \* \*$/.exec(e);if(t)return {hour:Number(t[1]),kind:"daily"};let n=/^0 (\d{1,2}) \* \* ([0-6])$/.exec(e);return n?{day:Number(n[2]),hour:Number(n[1]),kind:"weekly"}:{kind:"custom"}}function Tt(e,t,n){try{let o=CronExpressionParser.parse(e,{tz:t});return Array.from({length:n},()=>o.next().toDate())}catch{return []}}function Ct(e,t){return new Intl.DateTimeFormat("en-US",{day:"numeric",hour:"numeric",minute:"2-digit",month:"short",timeZone:t,weekday:"short"}).format(e)}function St(e,t){let n=e.trim();if(!n)return "Cron expression is required";let o=n.split(/\s+/).length;if(o<5||o>6)return `Expected 5 fields (min hour day month weekday), got ${o.toString()}`;try{return CronExpressionParser.parse(n,{tz:t}),null}catch{return "Invalid cron expression"}}function sa(e,t,n){let o=e.filter(l=>!l.deprecated);if(t!=="edit"||!n)return o;let r=e.find(l=>l.id===n);return r?.deprecated?[r,...o.filter(l=>l.id!==n)]:!r&&!o.some(l=>l.id===n)?[{deprecated:true,effort:null,id:n,name:n},...o]:o}function Ie(e){return `${e.teamId??""}:${e.id}`}function ia(e,t){let n={};for(let o of [...e,...t])n[Ie(o)]=o;return Object.values(n)}function dt(e,t){return {...e,availableChannels:e.channels,channelsLoaded:!e.connected,enabled:e.connected&&t==="edit"&&e.enabled,loadingChannels:false}}function la(e,t){return {slack:dt(e.providers.slack,t),teams:dt(e.providers.teams,t)}}function fa({channels:e,disabled:t,loading:n,onChange:o,onRefresh:r,provider:l,value:i}){let[c,k]=useState(false),[g,u]=useState(""),h=useRef(null),T=new Set(i.map(y=>y.id)),N=l==="slack"?"Slack":"Teams",z=e.filter(y=>y.name.toLowerCase().includes(g.toLowerCase()));useEffect(()=>{if(!c)return;function y(H){let{target:X}=H;!(X instanceof Node)||h.current?.contains(X)||k(false);}function R(H){H.key==="Escape"&&k(false);}return document.addEventListener("pointerdown",y),document.addEventListener("keydown",R),()=>{document.removeEventListener("pointerdown",y),document.removeEventListener("keydown",R);}},[c]);function S(y){if(T.has(y.id)){o(i.filter(R=>R.id!==y.id));return}o([...i,y]);}function J(y){o(i.filter(R=>R.id!==y));}return jsxs("div",{className:"fk:relative",ref:h,children:[jsxs(Button,{"aria-expanded":c,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:t,role:"combobox",type:"button",variant:"outline",onClick:()=>k(y=>!y),children:[jsx("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:gap-1",children:i.length===0?jsx("span",{className:"fk:text-muted-foreground",children:n?`Loading ${N} channels...`:`Select ${N} channels`}):i.map(y=>jsxs(Badge,{className:"fk:rounded-sm fk:bg-accent fk:text-xs",variant:"secondary",onClick:R=>{R.stopPropagation(),J(y.id);},children:[y.name,jsx(XIcon,{className:"fk:ml-1 fk:size-3 fk:cursor-pointer"})]},Ie(y)))}),jsx(ChevronsUpDownIcon,{className:"fk:size-4 fk:shrink-0 fk:opacity-50"})]}),c?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",children:[jsx("div",{className:"fk:border-b fk:p-2",children:jsx(Input,{className:"fk:h-8",placeholder:`Search ${N} channels...`,value:g,onChange:y=>u(y.target.value)})}),jsx("div",{className:"fk:max-h-56 fk:overflow-auto fk:p-1",children:z.length>0?z.map(y=>jsxs("button",{className:"fk:flex fk:w-full fk:items-center fk:rounded-sm fk:px-2 fk:py-1.5 fk:text-left fk:text-sm hover:fk:bg-accent",type:"button",onClick:()=>S(y),children:[jsx(CheckIcon,{className:`fk:mr-2 fk:size-4 ${T.has(y.id)?"fk:opacity-100":"fk:opacity-0"}`}),y.name]},Ie(y))):jsx("div",{className:"fk:px-2 fk:py-6 fk:text-center fk:text-sm fk:text-muted-foreground",children:n?"Loading channels...":"No channels found."})}),jsx("div",{className:"fk:border-t fk:border-border fk:p-2",children:jsx(Button,{className:"fk:h-8 fk:w-full fk:justify-start fk:text-xs",disabled:n,type:"button",variant:"ghost",onClick:r,children:n?jsxs(Fragment$1,{children:[jsx(LoaderCircleIcon,{className:"fk:mr-2 fk:size-3 fk:animate-spin"}),"Refreshing channels..."]}):jsxs(Fragment$1,{children:[jsx(RefreshCwIcon,{className:"fk:mr-2 fk:size-3"}),"Refresh channels"]})})})]}):null]})}function pe({cron:e,timezone:t}){let[n]=Tt(e,t,1);return n?jsxs("span",{className:"fk:text-sm fk:text-muted-foreground",children:["Next run ",Ct(n,t)]}):null}function ut({onChange:e,value:t}){return jsxs(Select,{value:t.toString(),onValueChange:n=>e(Number(n)),children:[jsx(SelectTrigger,{"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(SelectValue,{})}),jsx(SelectContent,{children:ea.map(n=>jsx(SelectItem,{value:n.value.toString(),children:n.label},n.value))})]})}function da({onChange:e,value:t}){return jsxs(Select,{value:t.toString(),onValueChange:n=>e(Number(n)),children:[jsx(SelectTrigger,{"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(SelectValue,{})}),jsx(SelectContent,{children:Qn.map(n=>jsx(SelectItem,{value:n.value.toString(),children:n.label},n.value))})]})}function ua({onChange:e,timezone:t,value:n}){let[o,r]=useState(false),l=useRef(null),i=St(n,t),c=i?[]:Tt(n,t,3);return useEffect(()=>{if(!o)return;function k(u){let{target:h}=u;!(h instanceof Node)||l.current?.contains(h)||r(false);}function g(u){u.key==="Escape"&&r(false);}return document.addEventListener("pointerdown",k),document.addEventListener("keydown",g),()=>{document.removeEventListener("pointerdown",k),document.removeEventListener("keydown",g);}},[o]),jsxs("div",{className:"fk:relative",ref:l,children:[jsxs("button",{className:"fk:flex fk:items-center fk:gap-1.5 fk:rounded-md fk:bg-background/90 fk:px-2 fk:py-1 fk:font-mono fk:text-sm fk:shadow-sm hover:fk:bg-accent",type:"button",onClick:()=>r(k=>!k),children:[n||"Set cron",jsx(ChevronDownIcon,{className:"fk:size-3.5 fk:opacity-50"})]}),o?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",children:[jsxs("div",{className:"fk:mb-2 fk:text-xs fk:text-muted-foreground",children:["Cron expression (",t,")"]}),jsx(Input,{className:`fk:h-8 fk:font-mono ${i?"fk:border-destructive focus-visible:fk:ring-destructive":""}`,value:n,onChange:k=>e(k.target.value)}),i?jsx("p",{className:"fk:mt-2 fk:text-xs fk:text-destructive",children:i}):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"}),c.map(k=>jsx("p",{children:Ct(k,t)},k.toISOString()))]})]}):null]})}function ca({onChange:e,trigger:t}){let n=oa(t.cron);return n.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(pe,{cron:t.cron,timezone:t.timezone})]}):n.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(ut,{value:n.hour,onChange:o=>e({...t,cron:`0 ${o.toString()} * * *`})}),jsx("span",{className:"fk:text-muted-foreground",children:t.timezone}),jsx(pe,{cron:t.cron,timezone:t.timezone})]}):n.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(da,{value:n.day,onChange:o=>e({...t,cron:`0 ${n.hour.toString()} * * ${o.toString()}`})}),jsx("span",{children:"at"}),jsx(ut,{value:n.hour,onChange:o=>e({...t,cron:`0 ${o.toString()} * * ${n.day.toString()}`})}),jsx("span",{className:"fk:text-muted-foreground",children:t.timezone}),jsx(pe,{cron:t.cron,timezone:t.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(ua,{timezone:t.timezone,value:t.cron,onChange:o=>e({...t,cron:o})}),jsx("span",{className:"fk:text-muted-foreground",children:t.timezone}),jsx(pe,{cron:t.cron,timezone:t.timezone})]})}function ma({onChange:e,projectId:t,trigger:n}){let[o,r]=useState(false),[l,i]=useState(false),c=n.url??tt(t,n.token);function k(g,u){navigator.clipboard.writeText(g).then(()=>{u(true),window.setTimeout(()=>u(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(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsxs("button",{className:"fk:flex fk:min-w-0 fk:max-w-60 fk:items-center fk:gap-1.5 fk:rounded-md fk:bg-background/90 fk:px-2 fk:py-1 fk:text-xs fk:shadow-sm hover:fk:bg-accent",type:"button",onClick:()=>k(c,r),children:[jsx("span",{className:"fk:truncate",children:c}),o?jsx(CheckIcon,{className:"fk:size-3.5 fk:shrink-0"}):jsx(CopyIcon,{className:"fk:size-3.5 fk:shrink-0 fk:opacity-60"})]})}),jsx(TooltipContent,{className:"fk:max-w-96 fk:break-all",children:c})]}),n.secret?jsxs(Button,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>k(`Bearer ${n.secret??""}`,i),children:[l?jsx(CheckIcon,{className:"fk:size-3.5"}):jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Copy auth header"]}):jsxs(Button,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>e({...n,secret:ra()}),children:[jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Generate auth header"]})]})}function ka({entities:e,onChange:t,trigger:n}){function o(i){let c=n.events.includes(i)?n.events.filter(k=>k!==i):[...n.events,i];t({...n,events:ft.filter(k=>c.includes(k))});}function r(i){let c=n.entities.includes(i)?n.entities.filter(k=>k!==i):[...n.entities,i];t({...n,entities:c});}let l=n.entities.length>0?n.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:ft.map(i=>jsxs(Button,{className:"fk:h-7 fk:px-2.5 fk:text-xs fk:capitalize",size:"sm",type:"button",variant:n.events.includes(i)?"secondary":"ghost",onClick:()=>o(i),children:[n.events.includes(i)?jsx(CheckIcon,{className:"fk:size-3"}):null,i]},i))}),jsx("span",{children:"of"}),jsxs(DropdownMenu,{children:[jsx(DropdownMenuTrigger,{asChild:true,children:jsxs(Button,{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:l}),jsx(ChevronDownIcon,{className:"fk:size-3.5 fk:opacity-50"})]})}),jsx(DropdownMenuContent,{align:"start",className:"fk:max-h-64 fk:w-56 fk:overflow-auto",children:e.length===0?jsx(DropdownMenuItem,{disabled:true,children:"No entities found in the project schema"}):e.map(i=>jsx(DropdownMenuCheckboxItem,{checked:n.entities.includes(i),onCheckedChange:()=>r(i),onSelect:c=>c.preventDefault(),children:i},i))})]})]})}function pa({entities:e,errors:t,onChange:n,projectId:o,triggers:r}){let l=r.some(u=>u.type==="webhook");function i(u){n([...r,u]);}function c(u){i({cron:u,key:ge(),timezone:aa(),type:"schedule"});}function k(u){n(r.map(h=>h.key===u.key?u:h));}function g(u){n(r.filter(h=>h.key!==u));}return jsxs("div",{className:"fk:rounded-lg fk:border fk:bg-muted/60 fk:dark:bg-muted/30",children:[r.map(u=>jsxs(Fragment,{children:[jsxs("div",{className:"fk:group fk:rounded-md fk:m-1.5 fk:p-1.5 fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-3",children:[u.type==="schedule"?jsx(ClockIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,u.type==="webhook"?jsx(WebhookIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,u.type==="entity"?jsx(DatabaseZapIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,u.type==="schedule"?jsx(ca,{trigger:u,onChange:k}):null,u.type==="webhook"?jsx(ma,{projectId:o,trigger:u,onChange:k}):null,u.type==="entity"?jsx(ka,{entities:e,trigger:u,onChange:k}):null,jsx(Button,{"aria-label":"Remove trigger",className:"fk:opacity-0 fk:group-hover:opacity-100",size:"icon",type:"button",variant:"ghost",onClick:()=>g(u.key),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})})]}),t[u.key]?jsx("div",{className:"fk:mt-1 fk:pl-7",children:jsx(re,{message:t[u.key]})}):null]},u.key),jsx(Separator,{className:"fk:h-4"})]},u.key)),jsxs(DropdownMenu,{children:[jsx(DropdownMenuTrigger,{asChild:true,children:jsxs("button",{className:"fk:flex fk:w-full fk:items-center fk:gap-3 fk:rounded-b-lg fk:px-3 fk:py-3 fk:text-sm fk:text-muted-foreground hover:fk:bg-muted hover:fk:text-foreground",type:"button",children:[jsx(PlusIcon,{className:"fk:size-4"}),"Add Trigger"]})}),jsxs(DropdownMenuContent,{align:"start",className:"fk:w-56",children:[jsxs(DropdownMenuSub,{children:[jsxs(DropdownMenuSubTrigger,{children:[jsx(ClockIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Scheduled"]}),jsxs(DropdownMenuSubContent,{children:[jsx(DropdownMenuItem,{onClick:()=>c(wt),children:"Hourly"}),jsx(DropdownMenuItem,{onClick:()=>c(Gn),children:"Daily"}),jsx(DropdownMenuItem,{onClick:()=>c(Zn),children:"Weekly"}),jsx(DropdownMenuItem,{onClick:()=>c(Yn),children:"Custom (cron)"})]})]}),jsxs(DropdownMenuItem,{disabled:l,onClick:()=>i({key:ge(),secret:null,token:crypto.randomUUID(),type:"webhook"}),children:[jsx(WebhookIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Webhook Triggered"]}),jsxs(DropdownMenuItem,{onClick:()=>i({entities:[],events:["create"],key:ge(),type:"entity"}),children:[jsx(DatabaseZapIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Entity Events"]})]})]})]})}function ga(){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 ha(){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 Be({api:e,automation:t,mode:n,onSaved:o,projectId:r}){let[l,i]=useState(t?.name??""),[c,k]=useState(t?.instructions??""),[g,u]=useState(t?.enabled??false),[h,T]=useState(t?.modelId??""),[N,z]=useState(()=>na(t)),[S,J]=useState(false),[y,R]=useState(""),[H,X]=useState({instructions:false,name:false}),[C,O]=useState(null),dn=E(r).tools(t?.id),{data:_}=Q(dn,M),{data:un}=Q(E(r).entities,M),Ve=useMemo(()=>sa(_?.tools.models??[],n,h||t?.modelId||""),[t?.modelId,n,h,_?.tools.models]),ue=h||Ve[0]?.id||"",B=useMemo(()=>{let p={};for(let x of N){if(x.type==="schedule"){let b=St(x.cron,x.timezone);b&&(p[x.key]=b);}x.type==="entity"&&x.events.length===0&&(p[x.key]="Select at least one event (create, update or delete)");}let v={};for(let x of ke){let b=C?.[x];b?.enabled&&b.channels.length===0&&(v[x]=`Select at least one ${x==="slack"?"Slack":"Teams"} channel or remove the tool`);}return {instructions:c.trim()?"":"Instructions are required",model:ue?"":"Select a model",name:l.trim()?"":"Name is required",toolErrors:v,triggerErrors:p}},[ue,c,l,C,N]),Re=ta(B),ce=H.name&&!!B.name,ae=H.instructions&&!!B.instructions;useEffect(()=>{_?.tools&&O(la(_.tools,n));},[t?.id,n,_?.tools]);let Ae=useCallback(async p=>{O(v=>v&&{...v,[p]:{...v[p],channelsLoadError:void 0,loadingChannels:true}});try{let v=await e.listChannels(p),x=v.success?void 0:v.errorMessage??`Failed to load ${p==="slack"?"Slack":"Teams"} channels.`;O(b=>b&&{...b,[p]:{...b[p],availableChannels:ia(b[p].channels,v.channels),channelsLoadError:x,channelsLoaded:!0,loadingChannels:!1}});}catch(v){let x=v instanceof Error?v.message:"Failed to load integration channels.";O(b=>b&&{...b,[p]:{...b[p],channelsLoadError:x,channelsLoaded:true,loadingChannels:false}});}},[e]);useEffect(()=>{if(C)for(let p of ke){let v=C[p];v.connected&&!v.channelsLoaded&&!v.loadingChannels&&Ae(p);}},[Ae,C]);function Pe(p,v){O(x=>x&&{...x,[p]:{...x[p],...v}});}function cn(p){Pe(p,{channels:[],enabled:false});}async function mn(p){if(p.preventDefault(),!Re){X({instructions:true,name:true});return}J(true),R("");let v=ke.map(b=>{let U=C?.[b]??_?.tools.providers[b];return {channels:U?.channels??[],enabled:U?.enabled??false,provider:b}}),x={enabled:g,instructions:c,modelId:ue,name:l,toolConfigs:v,triggers:N.map(({key:b,...U})=>U)};try{let b=n==="create"||!t?await e.createAutomation(x):await e.updateAutomation(t.id,x);if(!b.success){R(Array.isArray(b.errorMessage)?b.errorMessage.join(", "):b.errorMessage);return}toast.success(n==="create"||!t?"Automation created.":"Automation saved."),o(b.automation);}catch(b){R(b instanceof Error?b.message:"Failed to save automation.");}finally{J(false);}}return jsxs("form",{className:"fk:max-w-3xl fk:space-y-8 fk:px-1 fk:mx-auto",onSubmit:p=>{mn(p);},children:[y?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",children:y}):null,jsxs("div",{className:"fk:space-y-3",children:[jsx(Label,{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(Switch,{checked:g,id:"automation-enabled",onCheckedChange:u}),jsx(Label,{className:"fk:font-normal",htmlFor:"automation-enabled",children:g?"Active":"Inactive"})]})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(Label,{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(Input,{"aria-describedby":ce?"automation-name-error":void 0,"aria-invalid":ce,className:ce?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"automation-name",value:l,onBlur:()=>X(p=>({...p,name:true})),onChange:p=>i(p.target.value)}),ce?jsx(re,{id:"automation-name-error",message:B.name}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(Label,{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(pa,{entities:un?.entities??[],errors:B.triggerErrors,projectId:r,triggers:N,onChange:z})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(Label,{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 ${ae?"fk:border-destructive":"fk:border-input"}`,children:jsx(Textarea,{"aria-describedby":ae?"automation-instructions-error":void 0,"aria-invalid":ae,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)]",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:c,onBlur:()=>X(p=>({...p,instructions:true})),onChange:p=>k(p.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 ${ae?"fk:border-destructive":"fk:border-input"}`,children:jsxs(Select,{value:ue,onValueChange:T,children:[jsx(SelectTrigger,{"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(SelectValue,{placeholder:"Select a model"})}),jsx(SelectContent,{align:"start",children:Ve.map(p=>jsxs(SelectItem,{value:p.id,children:[p.name,p.deprecated?" (Legacy)":""]},p.id))})]})})]}),ae?jsx(re,{id:"automation-instructions-error",message:B.instructions}):null,_&&B.model?jsx(re,{message:B.model}):null]}),jsxs("div",{className:"fk:space-y-4",children:[jsxs("div",{children:[jsx(Label,{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",children:[jsx("div",{className:"fk:rounded-t-lg",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",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(Badge,{className:"fk:mt-1.5 fk:py-0 fk:text-[10px] fk:font-light fk:tracking-wide",variant:"secondary",children:"Always on"})]})}),C?ke.map(p=>{let v=C[p];return jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:p-1.5 fk:hover:bg-muted",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(p==="slack"?ga:ha,{}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:p==="slack"?"Send to Slack":"Send to Microsoft Teams"}),v.workspaceName?jsxs("p",{className:"fk:text-xs fk:text-muted-foreground",children:["Connected to ",v.workspaceName]}):null]})]}),v.connected?v.enabled?jsx(Button,{"aria-label":`Remove ${p==="slack"?"Slack":"Microsoft Teams"} from automation`,size:"icon",type:"button",variant:"ghost",onClick:()=>cn(p),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})}):jsx(Button,{size:"sm",type:"button",variant:"outline",onClick:()=>Pe(p,{enabled:true}),children:"Add"}):jsx(Button,{disabled:!_?.tools.teamId,size:"sm",type:"button",variant:"outline",onClick:()=>{let U=_?.tools.teamId;U&&window.open(e.getIntegrationManageUrl(U),"_blank","noopener,noreferrer");},children:"Manage"})]}),v.connected?null:jsxs("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:["Connect ",p==="slack"?"Slack":"Microsoft Teams"," in Project Integrations before using it in an automation."]}),v.connected&&v.enabled?jsxs("div",{className:"fk:space-y-2 fk:pl-7",children:[jsx(Label,{className:"fk:mr-3 fk:text-xs fk:font-medium",children:"Channels"}),jsx(fa,{channels:v.availableChannels,disabled:v.loadingChannels,loading:v.loadingChannels,provider:p,value:v.channels,onChange:U=>Pe(p,{channels:U}),onRefresh:()=>{Ae(p);}}),v.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"}),v.channelsLoadError]}):null,!v.channelsLoadError&&B.toolErrors[p]?jsx(re,{message:B.toolErrors[p]}):null]}):null]},p)}):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:flex fk:items-center fk:justify-end fk:gap-3",children:[Re?null:jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Complete the required fields to save"}),jsx(Button,{disabled:S||!Re,type:"submit",children:S?"Saving...":n==="create"?"Create automation":"Update automation"})]})]})}var Qa={sm:"fk:max-w-sm",md:"fk:max-w-md",lg:"fk:max-w-lg",full:"fk:max-w-full"},er=({children:e,element:t})=>{let{props:n}=t,o=n.maxWidth?Qa[n.maxWidth]:"",r=n.centered?"fk:mx-auto":"";return jsxs("div",{className:`fk:w-full fk:rounded-lg fk:border fk:border-border fk:bg-card fk:p-4 ${o} ${r} ${n.className??""}`,children:[n.title&&jsx("div",{className:"fk:text-sm fk:font-medium",children:n.title}),n.description&&jsx("div",{className:"fk:mt-0.5 fk:text-xs fk:text-muted-foreground",children:n.description}),(n.title??n.description)&&e?jsx("div",{className:"fk:mt-3"}):null,e]})},tr={none:"fk:gap-0",sm:"fk:gap-2",md:"fk:gap-3",lg:"fk:gap-4",xl:"fk:gap-6"},nr={start:"fk:items-start",center:"fk:items-center",end:"fk:items-end",stretch:"fk:items-stretch"},ar={start:"fk:justify-start",center:"fk:justify-center",end:"fk:justify-end",between:"fk:justify-between",around:"fk:justify-around"},rr=({children:e,element:t})=>{let{props:n}=t,o=n.direction==="horizontal"?"fk:flex-row fk:flex-wrap":"fk:flex-col",r=tr[n.gap??"md"],l=n.align?nr[n.align]:"",i=n.justify?ar[n.justify]:"";return jsx("div",{className:`fk:flex fk:w-full ${o} ${r} ${l} ${i} ${n.className??""}`,children:e})},or={1:"fk:grid-cols-1",2:"fk:grid-cols-2",3:"fk:grid-cols-3",4:"fk:grid-cols-4",5:"fk:grid-cols-5",6:"fk:grid-cols-6"},sr={sm:"fk:gap-2",md:"fk:gap-3",lg:"fk:gap-4",xl:"fk:gap-6"},ir=({children:e,element:t})=>{let{props:n}=t,o=or[n.columns??1]??"fk:grid-cols-1",r=sr[n.gap??"md"];return jsx("div",{className:`fk:grid fk:w-full ${o} ${r} ${n.className??""}`,children:e})},lr=({element:e})=>jsx(Separator,{orientation:e.props.orientation??"horizontal"}),fr={h1:"fk:text-xl fk:font-semibold fk:tracking-tight",h2:"fk:text-lg fk:font-semibold fk:tracking-tight",h3:"fk:text-base fk:font-medium",h4:"fk:text-sm fk:font-medium"},dr=({element:e})=>{let t=e.props.level??"h2";return jsx(t,{className:fr[t],children:e.props.text})},ur={body:"fk:text-sm",muted:"fk:text-sm fk:text-muted-foreground",caption:"fk:text-xs fk:text-muted-foreground",lead:"fk:text-base",code:"fk:rounded fk:bg-muted fk:px-1 fk:py-0.5 fk:font-mono fk:text-xs"},cr=({element:e})=>jsx("p",{className:ur[e.props.variant??"body"],children:e.props.text}),mr=({element:e})=>jsx(Badge,{variant:e.props.variant??"default",children:e.props.text});function kr({type:e}){switch(e){case "success":return jsx(CheckCircle2Icon,{className:"fk:size-4 fk:translate-y-0.5"});case "warning":return jsx(AlertTriangleIcon,{className:"fk:size-4 fk:translate-y-0.5"});case "error":return jsx(XCircleIcon,{className:"fk:size-4 fk:translate-y-0.5"});default:return jsx(InfoIcon,{className:"fk:size-4 fk:translate-y-0.5"})}}var pr=({element:e})=>{let{props:t}=e,n=t.type==="error"?"fk:border-destructive/50 fk:text-destructive":"fk:text-foreground";return jsxs("div",{className:`fk:flex fk:w-full fk:gap-3 fk:rounded-lg fk:border fk:bg-card fk:px-4 fk:py-3 fk:text-sm ${n}`,role:"alert",children:[jsx(kr,{type:t.type}),jsxs("div",{className:"fk:min-w-0",children:[jsx("div",{className:"fk:font-medium",children:t.title}),t.message&&jsx("div",{className:"fk:text-muted-foreground",children:t.message})]})]})},gr=({element:e})=>{let t=e.props.columns??[],n=(e.props.rows??[]).map(o=>o.map(String));return jsx("div",{className:"fk:w-full fk:overflow-hidden fk:rounded-md fk:border fk:border-border fk:mt-2",children:jsxs(Table,{children:[e.props.caption&&jsx(TableCaption,{children:e.props.caption}),jsx(TableHeader,{children:jsx(TableRow,{children:t.map(o=>jsx(TableHead,{children:o},o))})}),jsx(TableBody,{children:n.map((o,r)=>jsx(TableRow,{children:o.map((l,i)=>jsx(TableCell,{children:l},i))},r))})]})})},hr=({element:e})=>{let{props:t}=e,n=t.max??100,o=n>0?Math.min(100,Math.max(0,t.value/n*100)):0;return jsxs("div",{className:"fk:w-full",children:[t.label&&jsxs("div",{className:"fk:mb-1 fk:flex fk:items-center fk:justify-between fk:text-xs fk:text-muted-foreground",children:[jsx("span",{children:t.label}),jsxs("span",{className:"fk:tabular-nums",children:[Math.round(o),"%"]})]}),jsx("div",{className:"fk:h-2 fk:w-full fk:overflow-hidden fk:rounded-full fk:bg-secondary",children:jsx("div",{className:"fk:h-full fk:rounded-full fk:bg-primary",style:{width:`${o.toString()}%`}})})]})},vr=({element:e})=>jsx(Skeleton,{className:e.props.rounded?"fk:rounded-full":"",style:{height:e.props.height??"1rem",width:e.props.width??"100%"}}),br=({element:e})=>jsx(ExternalLink,{href:e.props.href,children:e.props.label}),yr=({element:e})=>e.props.src?jsx("img",{alt:e.props.alt,className:"fk:max-w-full fk:rounded-md",height:e.props.height??void 0,src:e.props.src,width:e.props.width??void 0}):null,xr=({element:e})=>jsx("div",{className:"fk:w-full fk:divide-y fk:divide-border fk:rounded-md fk:border fk:border-border",children:(e.props.items??[]).map((t,n)=>jsxs("details",{className:"fk:group fk:px-4 fk:py-3",children:[jsx("summary",{className:"fk:cursor-pointer fk:list-none fk:text-sm fk:font-medium",children:t.title}),jsx("p",{className:"fk:mt-2 fk:text-sm fk:text-muted-foreground",children:t.content})]},n))}),Nr=({children:e,element:t})=>{let n=t.props.tabs??[];return jsxs(Tabs,{defaultValue:t.props.value??t.props.defaultValue??n[0]?.value,children:[jsx(TabsList,{children:n.map(o=>jsx(TabsTrigger,{value:o.value,children:o.label},o.value))}),e]})},wr=({children:e,element:t})=>jsx(TabsContent,{value:t.props.value,children:e}),Tr={up:"fk:text-success",down:"fk:text-destructive",neutral:"fk:text-muted-foreground"};function Cr({trend:e}){return e==="up"?jsx(TrendingUpIcon,{className:"fk:size-4"}):e==="down"?jsx(TrendingDownIcon,{className:"fk:size-4"}):jsx(MinusIcon,{className:"fk:size-4"})}var Sr=({element:e})=>{let{props:t}=e;return jsxs("div",{className:"fk:w-full fk:rounded-lg fk:border fk:border-border fk:bg-card fk:p-4",children:[jsx("div",{className:"fk:text-xs fk:font-medium fk:text-muted-foreground",children:t.label}),jsxs("div",{className:"fk:mt-1 fk:flex fk:items-center fk:gap-2",children:[jsx("span",{className:"fk:text-2xl fk:font-semibold fk:tabular-nums fk:tracking-tight",children:t.value}),t.trend&&jsx("span",{className:Tr[t.trend],children:jsx(Cr,{trend:t.trend})})]}),t.detail&&jsx("div",{className:"fk:mt-1 fk:text-xs fk:text-muted-foreground",children:t.detail})]})},Rr={info:"fk:border-blue-500/30 fk:bg-blue-500/5 fk:text-blue-700 fk:dark:text-blue-400",tip:"fk:border-emerald-500/30 fk:bg-emerald-500/5 fk:text-emerald-700 fk:dark:text-emerald-400",warning:"fk:border-amber-500/30 fk:bg-amber-500/5 fk:text-amber-700 fk:dark:text-amber-400",important:"fk:border-red-500/30 fk:bg-red-500/5 fk:text-red-700 fk:dark:text-red-400"};function Ar({type:e}){switch(e){case "tip":return jsx(LightbulbIcon,{className:"fk:size-4 fk:shrink-0 fk:translate-y-0.5"});case "warning":return jsx(AlertTriangleIcon,{className:"fk:size-4 fk:shrink-0 fk:translate-y-0.5"});case "important":return jsx(OctagonAlertIcon,{className:"fk:size-4 fk:shrink-0 fk:translate-y-0.5"});default:return jsx(InfoIcon,{className:"fk:size-4 fk:shrink-0 fk:translate-y-0.5"})}}var Pr=({element:e})=>{let{props:t}=e,n=t.type??"info";return jsxs("div",{className:`fk:flex fk:w-full fk:gap-3 fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:text-sm ${Rr[n]}`,children:[jsx(Ar,{type:n}),jsxs("div",{className:"fk:min-w-0",children:[t.title&&jsx("div",{className:"fk:font-medium",children:t.title}),jsx("div",{className:"fk:text-foreground",children:t.content})]})]})},Ir={completed:"fk:border-success fk:bg-success",current:"fk:border-primary fk:bg-primary",upcoming:"fk:border-border fk:bg-background"},Mr=({element:e})=>jsx("div",{className:"fk:w-full",children:(e.props.items??[]).map((t,n,o)=>jsxs("div",{className:"fk:relative fk:flex fk:gap-3 fk:pb-4 fk:last:pb-0",children:[n<o.length-1&&jsx("div",{className:"fk:absolute fk:left-[5px] fk:top-4 fk:h-full fk:w-px fk:bg-border"}),jsx("div",{className:`fk:mt-1 fk:size-[11px] fk:shrink-0 fk:rounded-full fk:border-2 ${Ir[t.status??"upcoming"]}`}),jsxs("div",{className:"fk:min-w-0",children:[jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-baseline fk:gap-x-2",children:[jsx("span",{className:"fk:text-sm fk:font-medium",children:t.title}),t.date&&jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:t.date})]}),t.description&&jsx("div",{className:"fk:text-sm fk:text-muted-foreground",children:t.description})]})]},n))}),be=["#6366f1","#10b981","#f59e0b","#ef4444","#06b6d4"],_e={background:"hsl(var(--background))",border:"1px solid hsl(var(--border))",borderRadius:6,fontSize:12},ye={fill:"hsl(var(--muted-foreground))",fontSize:11};function Fe(e){let t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:0}function Lt(e){let t=e.data??[];if(!e.aggregate)return t.map(o=>({x:String(o[e.xKey]??""),y:Fe(o[e.yKey])}));let n=new Map;for(let o of t){let r=String(o[e.xKey]??""),l=n.get(r)??{count:0,sum:0};l.count+=1,l.sum+=Fe(o[e.yKey]),n.set(r,l);}return Array.from(n.entries()).map(([o,r])=>e.aggregate==="count"?{x:o,y:r.count}:e.aggregate==="avg"?{x:o,y:r.count===0?0:r.sum/r.count}:{x:o,y:r.sum})}function Ue({children:e,height:t,title:n}){return jsxs("div",{className:"fk:w-full",children:[n&&jsx("div",{className:"fk:mb-2 fk:text-sm fk:font-medium",children:n}),jsx("div",{style:{height:t??256},children:jsx(ResponsiveContainer,{height:"100%",width:"100%",children:e})})]})}var Er=({element:e})=>{let t=Lt(e.props),n=e.props.color??be[0];return jsx(Ue,{height:e.props.height,title:e.props.title,children:jsxs(BarChart,{data:t,children:[jsx(CartesianGrid,{stroke:"hsl(var(--border))",vertical:false}),jsx(XAxis,{axisLine:false,dataKey:"x",tick:ye,tickLine:false,tickMargin:8}),jsx(YAxis,{axisLine:false,tick:ye,tickLine:false,width:40}),jsx(Tooltip$1,{contentStyle:_e,cursor:{fill:"hsl(var(--muted))"}}),jsx(Bar,{dataKey:"y",fill:n,name:e.props.yKey,radius:4})]})})},zr=({element:e})=>{let t=Lt(e.props),n=e.props.color??be[0];return jsx(Ue,{height:e.props.height,title:e.props.title,children:jsxs(LineChart,{data:t,children:[jsx(CartesianGrid,{stroke:"hsl(var(--border))",vertical:false}),jsx(XAxis,{axisLine:false,dataKey:"x",tick:ye,tickLine:false,tickMargin:8}),jsx(YAxis,{axisLine:false,tick:ye,tickLine:false,width:40}),jsx(Tooltip$1,{contentStyle:_e}),jsx(Line,{dataKey:"y",dot:false,name:e.props.yKey,stroke:n,strokeWidth:2,type:"monotone"})]})})},$r=({element:e})=>{let t=(e.props.data??[]).map(n=>({name:String(n[e.props.nameKey]??""),value:Fe(n[e.props.valueKey])}));return jsx(Ue,{height:e.props.height,title:e.props.title,children:jsxs(PieChart,{children:[jsx(Tooltip$1,{contentStyle:_e}),jsx(Pie,{data:t,dataKey:"value",innerRadius:"45%",nameKey:"name",children:t.map((n,o)=>jsx(Cell,{fill:be[o%be.length]},`${n.name}-${o.toString()}`))})]})})},Dr=({element:e})=>{let{chart:t,title:n}=e.props,o=useId().replace(/[^a-zA-Z0-9]/g,""),[r,l]=useState(null),[i,c]=useState(null);return useEffect(()=>{let k=false;return (async()=>{try{let{default:u}=await import('mermaid'),h=document.documentElement.classList.contains("dark");u.initialize({securityLevel:"strict",startOnLoad:!1,theme:h?"dark":"default"});let T=await u.render(`fk-mermaid-${o}`,t);k||(l(T.svg),c(null));}catch(u){k||c(u instanceof Error?u.message:"Failed to render the diagram.");}})(),()=>{k=true;}},[t,o]),jsxs("div",{className:"fk:w-full fk:rounded-lg fk:border fk:border-border fk:bg-card fk:p-4",children:[n&&jsx("div",{className:"fk:mb-2 fk:text-sm fk:font-medium",children:n}),i?jsx("pre",{className:"fk:overflow-x-auto fk:whitespace-pre-wrap fk:text-xs fk:text-muted-foreground",children:t}):null,!i&&r?jsx("div",{className:"fk:flex fk:justify-center fk:overflow-x-auto",dangerouslySetInnerHTML:{__html:r}}):null,!i&&!r?jsx(Skeleton,{className:"fk:h-40 fk:w-full"}):null]})},Lr={Accordion:xr,Alert:pr,Badge:mr,BarChart:Er,Callout:Pr,Card:er,Grid:ir,Heading:dr,Image:yr,LineChart:zr,Link:br,Mermaid:Dr,Metric:Sr,PieChart:$r,Progress:hr,Separator:lr,Skeleton:vr,Stack:rr,TabContent:wr,Table:gr,Tabs:Nr,Text:cr,Timeline:Mr},Br=({element:e})=>jsxs("div",{className:"fk:rounded-md fk:border fk:border-dashed fk:border-border fk:p-3 fk:text-sm fk:text-muted-foreground",children:["Unsupported component: ",e.type]});function Fr(e){if(!e.elements[e.root])return null;let t=false,n={};for(let o of Object.keys(e.elements)){let r=e.elements[o];if(!r)continue;let l=r.children??[],i=l.filter(c=>!!e.elements[c]);i.length!==l.length&&(t=true),n[o]=i.length===l.length?r:{...r,children:i};}return t?{...e,elements:n}:e}function Bt({parts:e}){let t=useMemo(()=>{let o=buildSpecFromParts(e);return o?Fr(o):null},[e]),n=useMemo(()=>JSON.stringify(t?.state??{}),[t]);return t?jsx(StateProvider,{initialState:t.state,children:jsx(VisibilityProvider,{children:jsx(ActionProvider,{children:jsx(Renderer,{fallback:Br,registry:Lr,spec:t})})})},n):null}function ee(){let{currentProjectId:e}=useConfig();return {api:useMemo(()=>e?nt(e):null,[e]),projectId:e}}function L({children:e}){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",children:e})}function mo({status:e}){return jsx(Badge,{className:`fk:border-none fk:h-[19px] fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide ${e==="success"?"fk:bg-success/20 fk:text-success":"fk:bg-secondary fk:text-secondary-foreground"}`,variant:e==="success"?"default":"secondary",children:e})}function ko(e){if(e==="0 * * * *")return "Every hour";let t=/^0 (\d{1,2}) \* \* \*$/.exec(e);if(t)return `Every day at ${t[1].padStart(2,"0")}:00`;let n=/^0 (\d{1,2}) \* \* ([0-6])$/.exec(e);return n?`Every ${["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][Number(n[2])]??"week"} at ${n[1].padStart(2,"0")}:00`:e}function po(e){let t=e.triggers.map(n=>{if(n.type==="schedule")return ko(n.cron);if(n.type==="webhook")return "Webhook";let o=n.entities.length>0?n.entities.join(", "):"all entities";return `On ${n.events.join("/")} of ${o}`});return t.length===0?"Manual only":t.join(" \xB7 ")}function en(e){return e?!!(e.name.trim()&&e.instructions.trim()&&e.modelId.trim()):false}function go({projectId:e}){let{data:t}=Q(E(e).creditBalance,M),n=t?.creditBalance;return n?jsx(Button,{asChild:true,size:"sm",variant:"secondary",children:jsxs("a",{href:n.billingUrl,rel:"noopener noreferrer",target:"_blank",children:[jsx(CoinsIcon,{className:"fk:mr-2 fk:size-4"}),n.display," Credit"]})}):null}function tn(){let{api:e,projectId:t}=ee(),n=useNavigate(),{data:o,mutate:r}=Q(t?E(t).automations:null,M),[l,i]=useState("");if(!t||!e)return jsx(L,{children:"Select a project to view automations."});let c=[...o?.automations??[]].sort((g,u)=>{let h=g.lastRunAt?new Date(g.lastRunAt).getTime():0;return (u.lastRunAt?new Date(u.lastRunAt).getTime():0)-h});async function k(g){if(i(""),!e)return;let u=await e.deleteAutomation(g.id);if(!u.success){i(Array.isArray(u.errorMessage)?u.errorMessage.join(", "):u.errorMessage);return}await r();}return jsxs("div",{className:"fk:space-y-6 fk:h-full",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(SidebarTrigger,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(TooltipContent,{children:"Toggle Sidebar"})]}),jsx(Separator,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsxs("div",{className:"fk:flex-1",children:[jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:"Automations"}),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(ExternalLink,{href:"https://flexkit.io/docs/automations",children:"Learn more"})]})]}),jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:justify-end fk:gap-3",children:[jsx(go,{projectId:t}),jsx(Button,{asChild:true,size:"sm",children:jsxs(Link,{to:"new",children:[jsx(Plus,{className:"fk:mr-2 fk:size-4"}),"New Automation"]})})]})]}),l?jsx("div",{className:"fk:text-sm fk:text-destructive",children:l}):null,c.length===0?jsx(L,{children:"No automations yet."}):jsxs(Table,{children:[jsx(TableHeader,{children:jsxs(TableRow,{children:[jsx(TableHead,{children:"Automation"}),jsx(TableHead,{children:"Triggers"}),jsx(TableHead,{children:"Last run"}),jsx(TableHead,{className:"fk:text-center",children:"Runs"}),jsx(TableHead,{className:"fk:text-center",children:"Status"}),jsx(TableHead,{})]})}),jsx(TableBody,{children:c.map(g=>jsxs(TableRow,{className:"fk:cursor-pointer",onClick:()=>n(g.id),children:[jsx(TableCell,{children:jsx("div",{className:"fk:font-medium",children:g.name})}),jsx(TableCell,{className:"fk:text-muted-foreground",children:po(g)}),jsx(TableCell,{children:g.lastRunAt?formatDistance(new Date(g.lastRunAt),new Date,{addSuffix:true}):"Never"}),jsx(TableCell,{className:"fk:text-center",children:g.totalRuns}),jsx(TableCell,{className:"fk:text-center",children:jsx(Badge,{className:`fk:border-none fk:h-[19px] fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide ${g.enabled?"fk:bg-success/20 fk:text-success":"fk:bg-secondary fk:text-secondary-foreground"}`,variant:g.enabled?"default":"secondary",children:g.enabled?"Enabled":"Disabled"})}),jsx(TableCell,{className:"fk:text-right",children:jsxs(DropdownMenu,{children:[jsx(DropdownMenuTrigger,{asChild:true,children:jsx(Button,{"aria-label":`Actions for ${g.name}`,size:"icon",type:"button",variant:"ghost",onClick:u=>{u.stopPropagation();},children:jsx(Ellipsis,{className:"fk:size-4"})})}),jsxs(DropdownMenuContent,{align:"end",className:"fk:w-40",children:[jsxs(DropdownMenuItem,{onClick:u=>{u.stopPropagation(),n(g.id);},children:[jsx(Pencil,{}),"Edit"]}),jsx(DropdownMenuSeparator,{}),jsxs(DropdownMenuItem,{variant:"destructive",onClick:u=>{u.stopPropagation(),k(g);},children:[jsx(Trash2,{}),"Delete"]})]})]})})]},g.id))})]})]})}function nn(){let{api:e,projectId:t}=ee(),n=useNavigate();return !t||!e?jsx(L,{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(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(SidebarTrigger,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(TooltipContent,{children:"Toggle Sidebar"})]}),jsx(Separator,{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(Button,{asChild:true,className:"fk:shrink-0 fk:w-fit",size:"sm",variant:"ghost",children:jsxs(Link,{to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(ScrollArea,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:jsx(Be,{api:e,mode:"create",projectId:t,onSaved:()=>n("..")})})})]})}function an(){let{api:e,projectId:t}=ee(),{automationId:n}=useParams(),o=useNavigate(),[r,l]=useTransition(),{data:i,mutate:c}=Q(t&&n?E(t).automation(n):null,M);if(!t||!e||!n)return jsx(L,{children:"Select an automation."});if(!i?.automation)return jsx(L,{children:"Loading automation..."});let k=e,g=en(i.automation),u=n;function h(){g&&l(async()=>{let T=await k.runAutomation(u);if(T.success&&T.runId){o(`runs/${T.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(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(SidebarTrigger,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(TooltipContent,{children:"Toggle Sidebar"})]}),jsx(Separator,{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:i.automation.name})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-center fk:justify-between fk:gap-3",children:[jsx(Button,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(Tabs,{value:"settings",children:jsxs(TabsList,{children:[jsx(TabsTrigger,{className:"text-xs",value:"settings",children:"Settings"}),jsx(TabsTrigger,{className:"text-xs",value:"runs",children:jsx(Link,{to:"runs",children:"Runs"})})]})}),jsxs(Button,{disabled:r||!g,size:"sm",onClick:h,children:[r?jsx(LoaderCircle,{className:"fk:mr-2 fk:size-4 fk:animate-spin"}):jsx(Play,{className:"fk:mr-2 fk:size-4"}),"Run now"]})]}),jsx(ScrollArea,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:jsx(Be,{api:e,automation:i.automation,mode:"edit",projectId:t,onSaved:T=>{T?c({automation:T},{revalidate:false}):c();}})})})]})}var Te=25;function rn(){let{api:e,projectId:t}=ee(),{automationId:n}=useParams(),o=useNavigate(),[r,l]=useTransition(),{data:i}=Q(t&&n?E(t).automation(n):null,M),c=(C,O)=>!t||!n||O&&O.hasMore===false?null:E(t).automationRuns(n,C*Te,Te),{data:k,mutate:g,setSize:u,size:h}=Qt(c,M);if(!t||!e||!n)return jsx(L,{children:"Select an automation to view runs."});let T=e,N=en(i?.automation),z=n;function S(){N&&l(async()=>{let C=await T.runAutomation(z);if(C.success&&C.runId){o(C.runId);return}await g();});}let J=k?.flatMap(C=>C.runs)??[],R=k?.[k.length-1]?.hasMore??false,H=k!==void 0&&h>k.length;function X(){u(C=>C+1);}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(SidebarTrigger,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(TooltipContent,{children:"Toggle Sidebar"})]}),jsx(Separator,{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:i?.automation.name??"Automation"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-center fk:justify-between fk:gap-3",children:[jsx(Button,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(Tabs,{value:"runs",children:jsxs(TabsList,{children:[jsx(TabsTrigger,{className:"text-xs",value:"settings",children:jsx(Link,{relative:"path",to:"..",children:"Settings"})}),jsx(TabsTrigger,{className:"text-xs",value:"runs",children:"Runs"})]})}),jsxs(Button,{disabled:r||!N,size:"sm",onClick:S,children:[r?jsx(LoaderCircle,{className:"fk:mr-2 fk:size-4 fk:animate-spin"}):jsx(Play,{className:"fk:mr-2 fk:size-4"}),"Run now"]})]}),jsx(ScrollArea,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[jsx(sn,{basePath:".",runs:J}),R&&!H?jsx(on,{onVisible:X}):null,H?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more runs..."})]}):null]})})]})}function on({onVisible:e}){let t=useRef(null),n=useRef(e);return n.current=e,useEffect(()=>{let o=t.current;if(!o)return;let r=new IntersectionObserver(l=>{l.some(i=>i.isIntersecting)&&n.current();});return r.observe(o),()=>{r.disconnect();}},[]),jsx("div",{className:"fk:h-px",ref:t})}function sn({basePath:e,runs:t}){return t.length===0?jsx(L,{children:"No runs found."}):jsx(Table,{children:jsx(TableBody,{children:t.map(n=>jsxs(TableRow,{children:[jsx(TableCell,{className:"fk:py-2",children:jsx(Link,{className:"fk:font-medium hover:fk:underline",to:`${e}/${n.id}`,children:formatDistance(new Date(n.startedAt),new Date,{addSuffix:true})})}),jsx(TableCell,{className:"fk:text-muted-foreground",children:n.triggerType}),jsx(TableCell,{children:jsx(mo,{status:n.status})}),jsx(TableCell,{className:"fk:max-w-md fk:truncate fk:text-muted-foreground",children:n.summary??""})]},n.id))})})}function ln(){let{projectId:e}=ee(),[t,n]=useState("team"),o=(N,z)=>!e||z&&!z.history.hasMore?null:E(e).runHistory(t,N*Te,Te),{data:r,setSize:l,size:i}=Qt(o,M),c=r?.[0]?.history.metrics,k=r?.flatMap(N=>N.history.runs)??[],u=r?.[r.length-1]?.history.hasMore??false,h=r!==void 0&&i>r.length;if(!e)return jsx(L,{children:"Select a project to view run history."});function T(){l(N=>N+1);}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-6",children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:gap-2",children:[jsx(Button,{size:"sm",variant:t==="team"?"default":"outline",onClick:()=>n("team"),children:"Team"}),jsx(Button,{size:"sm",variant:t==="mine"?"default":"outline",onClick:()=>n("mine"),children:"Mine"})]}),c?jsxs("div",{className:"fk:grid fk:shrink-0 fk:gap-3 fk:md:grid-cols-4",children:[jsx(xe,{title:"Successful 24h",value:c.successful24h}),jsx(xe,{title:"Failed 24h",value:c.failed24h}),jsx(xe,{title:"Successful 7d",value:c.successful7d}),jsx(xe,{title:"Failed 7d",value:c.failed7d})]}):null,jsx(ScrollArea,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[jsx(sn,{basePath:"..",runs:k.map(N=>({...N,id:`${N.automationId}/runs/${N.id}`}))}),u&&!h?jsx(on,{onVisible:T}):null,h?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more runs..."})]}):null]})})]})}function xe({title:e,value:t}){return jsxs("div",{className:"fk:rounded-md fk:bg-muted/60 fk:p-4",children:[jsx("div",{className:"fk:text-sm fk:text-muted-foreground",children:e}),jsx("div",{className:"fk:mt-1 fk:text-2xl fk:font-medium",children:t.toLocaleString()})]})}var ho=5,vo=2e3,jt="data-spec";function bo(e){return new Promise(t=>window.setTimeout(t,e))}function yo(e){return e instanceof Error?e.name==="AbortError"||e.message.toLowerCase().includes("aborted"):false}function xo(e){return e.some(t=>t.type!=="step-start")}function No(e){let t=new Set;for(let n of e)for(let o of n.parts)o.type==="data-user-message"&&o.id&&t.add(o.id);return t}function wo(e){let t=No(e),n=[];for(let o of e){if(o.role==="user"){t.has(o.id)||n.push(o);continue}if(o.role!=="assistant"){n.push(o);continue}let r=[],l=0,i=()=>{xo(r)&&n.push({...o,id:`${o.id}-${l.toString()}`,parts:r}),l++,r=[];};for(let c of o.parts){if(c.type==="data-user-message"){let k=I(c);i(),n.push({id:c.id??crypto.randomUUID(),parts:k.parts,role:"user"});continue}r.push(c);}i();}return n}function To(e){return useMemo(()=>wo(e),[e])}function I(e){return e.data}function Co(e,t){let[n,o]=useState(),[r,l]=useState("streaming");return useEffect(()=>{if(!e){o(void 0),l("unavailable");return}let i=new AbortController,c=async()=>{let u=await fetch(`${e}?startIndex=0`,{credentials:"include",signal:i.signal});if(u.status===404)return "unavailable";if(!u.ok||!u.body)throw new Error(`Failed to fetch the run stream (status ${u.status.toString()})`);let h=false,N=parseJsonEventStream({schema:uiMessageChunkSchema,stream:u.body}).pipeThrough(new TransformStream({transform:(S,J)=>{if(!S.success)throw S.error;S.value.type==="finish"&&(h=true),J.enqueue(S.value);}})),z=readUIMessageStream({onError:S=>{console.error("Automation run stream chunk error",S);},stream:N});for await(let S of z){if(i.signal.aborted)break;o({...S});}return h?"finished":"incomplete"},k=async()=>{for(let u=0;u<ho;u++){u>0&&(await bo(vo),o(void 0));try{let h=await c();if(i.signal.aborted)return;if(h==="unavailable"){l("unavailable");return}if(h==="finished"){l("finished");return}}catch(h){if(i.signal.aborted||yo(h))return;console.error("Automation run stream error",h);}}l(t?.recordStatus==="running"?"streaming":"error");},g=window.setTimeout(()=>{k();},0);return ()=>{window.clearTimeout(g),i.abort("Run replay unmounted");}},[t?.recordStatus,e]),{message:n,status:r}}function fn(){let{api:e,projectId:t}=ee(),{automationId:n,runId:o}=useParams(),{data:r,mutate:l}=Q(t&&o?E(t).run(o):null,M),{data:i}=Q(t&&n?E(t).automation(n):null,M),[c,k]=useTransition();if(!t||!e||!n||!o)return jsx(L,{children:"Select a run."});let g=e,u=o,h=r?.run;function T(){k(async()=>{await g.cancelRun(u),await l();});}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(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(SidebarTrigger,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(TooltipContent,{children:"Toggle Sidebar"})]}),jsx(Separator,{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:i?.automation.name??"Automation"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-start fk:justify-between fk:gap-3",children:[jsxs("div",{children:[jsx(Button,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{relative:"path",to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Runs"]})}),jsx("h2",{className:"fk:mt-4 fk:text-lg fk:font-medium",children:h?`Run from ${format(new Date(h.startedAt),"PPpp")}`:"Loading run..."})]}),h?.status==="running"?jsx(Button,{disabled:c,size:"sm",variant:"destructive",onClick:T,children:c?"Cancelling...":"Cancel run"}):null]}),jsx(ScrollArea,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4 fk:max-w-5xl fk:mx-auto",children:h?jsx(So,{api:e,run:h}):jsx(L,{children:"Loading run..."})})})]})}function So({api:e,run:t}){let{workflowRunId:n}=t,o=n?e.getStreamUrl(n):"",{message:r,status:l}=Co(o,{recordStatus:t.status}),i=useMemo(()=>r?[r]:[],[r]),c=To(i);return n?jsxs("div",{className:"fk:space-y-4",children:[t.status==="failed"&&t.error?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-4 fk:text-sm",children:t.summary??t.error}):null,l==="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",children:"The workflow replay is no longer available. Generated artifacts may still be available below."}):null,l==="error"&&c.length===0?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-4 fk:text-sm",children:"Failed to load the run stream. Try reloading the page."}):null,c.length>0?jsxs("div",{className:"fk:space-y-5 fk:rounded-md fk:bg-background",children:[c.map(k=>jsx(Ro,{api:e,message:k},k.id)),l==="streaming"?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:font-mono fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Running..."})]}):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",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:l==="unavailable"?"No replay events were recorded.":"Loading run replay..."})]})]}):jsx(L,{children:"The run has not started streaming yet."})}function Ro({api:e,message:t}){let n=t.role==="user";return jsxs("div",{className:n?"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:n?jsxs(Fragment$1,{children:[jsx(ZapIcon,{className:"fk:ml-auto fk:size-4"}),jsx("span",{children:"Trigger"})]}):jsxs(Fragment$1,{children:[jsx(BotIcon,{className:"fk:size-4"}),jsxs("span",{children:["Agent",t.metadata?.model?` (${t.metadata.model})`:""]})]})}),jsx("div",{className:"fk:space-y-3 fk:min-w-0",children:t.parts.map((o,r)=>jsx(Ao,{api:e,part:o,partIndex:r,parts:t.parts},r))})]})}function Ao({api:e,part:t,partIndex:n,parts:o}){if(t.type==="step-start")return null;if(t.type==="text")return jsx(Po,{part:t});if(t.type==="reasoning")return jsx(Io,{text:t.text});if(t.type==="data-generating-files")return jsx(Mo,{message:I(t)});if(t.type==="data-run-artifact")return jsx(Eo,{api:e,message:I(t)});if(t.type==="data-tool-delivery")return jsx(zo,{message:I(t)});if(t.type==="data-run-summary")return jsx($o,{message:I(t)});if(t.type==="data-run-command"){let r=I(t);return jsx(j,{error:r.error?.message,icon:jsx(TerminalIcon,{className:"fk:size-3.5"}),loading:["executing","running","waiting"].includes(r.status),message:r.status==="error"?r.error?.message??`Command failed: ${r.command}`:`${r.status==="done"?"Ran":"Running"} ${r.command} ${r.args.join(" ")}`,title:"Run command"})}if(t.type==="data-search-schema"){let r=I(t);return jsx(j,{error:r.error?.message,icon:jsx(SearchIcon,{className:"fk:size-3.5"}),loading:r.status==="loading",message:r.status==="error"?r.error?.message??"Failed to search schema":`${r.status==="done"?"Searched":"Searching"}${r.query?` "${r.query}"`:" schema"}`,title:"Search schema"})}if(t.type==="data-web-search"){let r=I(t);return jsx(j,{error:r.error?.message,icon:jsx(SearchIcon,{className:"fk:size-3.5"}),loading:r.status==="loading",message:r.status==="error"?r.error?.message??"Failed to search the web":`${r.status==="done"?"Searched":"Searching"} "${r.query}"`,title:"Web search"})}if(t.type==="data-validate-graphql"){let r=I(t);return jsx(j,{error:r.error?.message,icon:jsx(DatabaseZapIcon,{className:"fk:size-3.5"}),loading:r.status==="loading",message:Bo(r),title:"Validate GraphQL"})}if(t.type==="data-execute-graphql"){let r=I(t),l=r.operationType==="mutation"?"mutation":"query";return jsx(j,{error:r.error?.message,icon:jsx(DatabaseZapIcon,{className:"fk:size-3.5"}),loading:r.status==="loading",message:r.status==="error"?r.error?.message??`Failed to execute ${l}`:`${r.status==="done"?"Executed":"Executing"} ${l}`,title:"Execute GraphQL"})}if(t.type==="data-bulk-graphql-action")return jsx(Do,{message:I(t)});if(t.type==="data-update-memory"){let r=I(t);return jsx(j,{error:r.error?.message,icon:jsx(CheckCircle2Icon,{className:"fk:size-3.5"}),loading:r.status==="loading",message:r.status==="error"?r.error?.message??"Failed to update memory":r.status==="done"?"Updated automation memory":"Updating automation memory",title:"Update memory"})}if(t.type==="data-create-sandbox"){let r=I(t);return jsx(j,{error:r.error?.message,icon:jsx(TerminalIcon,{className:"fk:size-3.5"}),loading:r.status==="loading",message:r.status==="error"?r.error?.message??"Failed to create sandbox":r.status==="done"?"Created sandbox":"Creating sandbox",title:"Create sandbox"})}return t.type===jt?o.slice(n+1).find(l=>l.type===jt)?null:jsx(Bt,{parts:o}):t.type.startsWith("data-")?jsx(Lo,{part:t}):null}function Po({part:e}){return jsx("div",{className:"fk:min-w-0 fk:max-w-full fk:overflow-x-auto fk:whitespace-pre-wrap fk:rounded-xl fk:bg-muted fk:px-4 fk:py-3 fk:text-sm fk:font-light fk:leading-relaxed fk:text-secondary-foreground",children:e.text})}function Io({text:e}){return jsxs(te,{className:"fk:bg-muted/30",children:[jsxs(ne,{children:[jsx(BrainIcon,{className:"fk:size-3.5"}),"Reasoning"]}),jsx("p",{className:"fk:mt-2 fk:whitespace-pre-wrap fk:text-xs fk:text-muted-foreground",children:e})]})}function te({children:e,className:t=""}){return jsx("div",{className:`fk:min-w-0 fk:max-w-full fk:overflow-x-auto fk:rounded-xl fk:border fk:border-border fk:bg-background fk:px-3.5 fk:py-3 fk:text-sm ${t}`,children:e})}function ne({children:e}){return jsx("div",{className:"fk:flex fk:items-center fk:gap-2 fk:font-medium fk:text-muted-foreground",children:e})}function qe({isError:e,loading:t}){return t?jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}):e?jsx(XIcon,{className:"fk:size-4 fk:text-red-700"}):jsx(CheckIcon,{className:"fk:size-4"})}function j({error:e,icon:t,loading:n,message:o,title:r}){return jsxs(te,{children:[jsxs(ne,{children:[t,r]}),jsxs("div",{className:"fk:relative fk:min-h-5 fk:pl-6",children:[jsx("span",{className:"fk:absolute fk:left-0 fk:top-0",children:jsx(qe,{isError:!!e,loading:n})}),jsx("span",{className:"fk:text-xs",children:o})]})]})}function Mo({message:e}){let t=["error","uploading","generating"].includes(e.status),n=t?e.paths.slice(0,e.paths.length-1):e.paths,o=t?e.paths[e.paths.length-1]??"":null;return jsxs(te,{children:[jsxs(ne,{children:[jsx(CloudUploadIcon,{className:"fk:size-3.5"}),jsx("span",{children:e.status==="done"?"Uploaded files":"Generating files"})]}),jsxs("div",{className:"fk:space-y-1 fk:text-sm",children:[n.map((r,l)=>jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(CheckIcon,{className:"fk:size-4"}),jsx("span",{className:"fk:whitespace-pre-wrap",children:r})]},`${r}-${l.toString()}`)),typeof o=="string"?jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(qe,{isError:e.status==="error",loading:e.status!=="error"}),jsx("span",{children:e.status==="error"?e.error?.message??o:o})]}):null]})]})}function Eo({api:e,message:t}){let n=t.status==="done"&&t.artifactId,o=n?e.getArtifactUrl(t.artifactId??""):"",r=n?e.getArtifactUrl(t.artifactId??"",{download:true}):"",l=Fo(t.sizeBytes);return jsxs(te,{children:[jsxs(ne,{children:[jsx(FileTextIcon,{className:"fk:size-3.5"}),t.status==="done"?"Published artifact":"Publishing artifact"]}),jsxs("div",{className:"fk:relative fk:min-h-5 fk:pl-6",children:[jsx("span",{className:"fk:absolute fk:left-0 fk:top-0",children:jsx(qe,{isError:t.status==="error",loading:t.status==="uploading"})}),jsxs("div",{className:"fk:min-w-0 fk:space-y-2",children:[jsxs("div",{className:"fk:min-w-0",children:[jsx("div",{className:"fk:truncate fk:font-medium",children:t.filename}),jsxs("div",{className:"fk:text-xs fk:text-muted-foreground",children:[t.status==="uploading"&&"Uploading to artifacts",t.status==="done"&&[Ho(t),l].filter(Boolean).join(" \xB7 "),t.status==="error"&&(t.error?.message??"Failed to publish artifact")]})]}),n?jsxs("div",{className:"fk:flex fk:flex-wrap fk:gap-2",children:[jsx(Button,{asChild:true,size:"sm",variant:"outline",children:jsx("a",{href:o,rel:"noreferrer",target:"_blank",children:"Preview"})}),jsx(Button,{asChild:true,size:"sm",variant:"outline",children:jsxs("a",{href:r,children:[jsx(DownloadIcon,{className:"fk:size-3"}),"Download"]})})]}):null]})]})]})}function zo({message:e}){let t=e.provider==="slack"?"Slack":"Microsoft Teams",n=e.provider==="slack"?jsx(MessageSquareIcon,{className:"fk:size-3.5"}):jsx(SendIcon,{className:"fk:size-3.5"});return jsx(j,{error:e.error?.message,icon:n,loading:e.status==="loading",message:e.status==="error"?e.error?.message??`Failed to send result to ${e.channelName}`:`${e.status==="done"?"Sent":"Sending"} result to ${e.channelName}`,title:`${t} Delivery`})}function $o({message:e}){let t=e.status==="success"?jsx(CheckCircle2Icon,{className:"fk:size-3.5 fk:text-green-700"}):e.status==="skipped"?jsx(CircleSlashIcon,{className:"fk:size-3.5"}):jsx(XCircleIcon,{className:"fk:size-3.5 fk:text-red-700"}),n=e.status==="success"?"Run completed":e.status==="skipped"?"Run skipped":"Run failed";return jsxs(te,{className:e.status==="failed"?"fk:border-red-700/40":"fk:border-green-700/40",children:[jsxs(ne,{children:[t,jsx("span",{children:n})]}),e.status==="failed"?jsx("p",{className:"fk:whitespace-pre-wrap fk:text-xs",children:e.summary}):null]})}function Do({message:e}){let t=[typeof e.processedItems=="number"?`${e.processedItems.toString()} processed`:"",typeof e.changedItems=="number"?`${e.changedItems.toString()} changed`:"",typeof e.failedItems=="number"?`${e.failedItems.toString()} failed`:"",typeof e.totalItems=="number"?`${e.totalItems.toString()} total`:""].filter(Boolean);return jsx(j,{error:e.error?.message,icon:jsx(DatabaseZapIcon,{className:"fk:size-3.5"}),loading:e.status==="loading"||e.status==="running",message:e.status==="error"?e.error?.message??`Failed bulk ${e.operationName}`:`${e.status==="done"?"Completed":"Running"} ${e.operationName}${t.length>0?` (${t.join(", ")})`:""}`,title:"Bulk GraphQL action"})}function Lo({part:e}){return jsxs(te,{className:"fk:bg-muted/30",children:[jsxs(ne,{children:[jsx(CheckCircle2Icon,{className:"fk:size-3.5"}),e.type.replace(/^data-/,"").replaceAll("-"," ")]}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"This run emitted a structured event that is not yet rendered by Studio."})]})}function Bo(e){if(e.status==="error")return e.error?.message??"Failed to validate GraphQL";if(e.status==="invalid"){let t=e.errorCount??0;return `Validation failed with ${t.toString()} ${t===1?"error":"errors"}`}return e.status==="valid"?"GraphQL operation is valid":"Validating GraphQL"}function Fo(e){if(typeof e!="number")return "";if(e<1024)return `${e.toString()} B`;let t=e/1024;return t<1024?`${t.toFixed(1)} KB`:`${(t/1024).toFixed(1)} MB`}function Ho(e){return e.kind==="pdf"?"PDF artifact":e.kind==="html"?"HTML artifact":"Artifact"}function Ds(){return {name:"flexkit.automations",contributes:{apps:[{component:jsx(et,{}),icon:jsx(Bot,{strokeWidth:1.5}),name:"automations",routes:[{component:jsx(tn,{}),path:""},{component:jsx(ln,{}),path:"runs"},{component:jsx(nn,{}),path:"new"},{component:jsx(an,{}),path:":automationId"},{component:jsx(rn,{}),path:":automationId/runs"},{component:jsx(fn,{}),path:":automationId/runs/:runId"}],title:"Automations"}]}}}
|
|
2
|
+
export{Ds as Automations};//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|