@flexkit/automations 0.0.22
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/LICENSE +21 -0
- package/dist/index.css +1008 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { PluginOptions } from '@flexkit/studio';
|
|
2
|
+
|
|
3
|
+
type AutomationRunStatus = 'running' | 'success' | 'skipped' | 'failed' | 'cancelled';
|
|
4
|
+
type AutomationTriggerType = 'entity' | 'manual' | 'schedule' | 'webhook';
|
|
5
|
+
type AutomationTriggerEvent = 'create' | 'update' | 'delete';
|
|
6
|
+
type AutomationToolProvider = 'slack' | 'teams';
|
|
7
|
+
interface AutomationScheduleTrigger {
|
|
8
|
+
cron: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
timezone: string;
|
|
11
|
+
type: 'schedule';
|
|
12
|
+
}
|
|
13
|
+
interface AutomationWebhookTrigger {
|
|
14
|
+
id?: string;
|
|
15
|
+
secret: string | null;
|
|
16
|
+
token: string;
|
|
17
|
+
type: 'webhook';
|
|
18
|
+
url?: string;
|
|
19
|
+
}
|
|
20
|
+
interface AutomationEntityTrigger {
|
|
21
|
+
entities: string[];
|
|
22
|
+
events: AutomationTriggerEvent[];
|
|
23
|
+
id?: string;
|
|
24
|
+
type: 'entity';
|
|
25
|
+
}
|
|
26
|
+
type AutomationTrigger = AutomationScheduleTrigger | AutomationWebhookTrigger | AutomationEntityTrigger;
|
|
27
|
+
interface AutomationToolChannel {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
serviceUrl?: string;
|
|
31
|
+
teamId?: string;
|
|
32
|
+
}
|
|
33
|
+
interface Automation {
|
|
34
|
+
createdAt: string | null;
|
|
35
|
+
enabled: boolean;
|
|
36
|
+
id: string;
|
|
37
|
+
instructions: string;
|
|
38
|
+
lastRunAt: string | null;
|
|
39
|
+
modelId: string;
|
|
40
|
+
name: string;
|
|
41
|
+
projectId: string;
|
|
42
|
+
totalRuns: number;
|
|
43
|
+
triggers: AutomationTrigger[];
|
|
44
|
+
updatedAt: string | null;
|
|
45
|
+
}
|
|
46
|
+
interface AutomationRun {
|
|
47
|
+
automationId: string;
|
|
48
|
+
completedAt: string | null;
|
|
49
|
+
error: string | null;
|
|
50
|
+
id: string;
|
|
51
|
+
projectId: string;
|
|
52
|
+
startedAt: string;
|
|
53
|
+
status: AutomationRunStatus;
|
|
54
|
+
summary: string | null;
|
|
55
|
+
triggerPayload: unknown;
|
|
56
|
+
triggerType: AutomationTriggerType;
|
|
57
|
+
workflowRunId: string | null;
|
|
58
|
+
}
|
|
59
|
+
interface RunHistoryRun extends AutomationRun {
|
|
60
|
+
automationName: string;
|
|
61
|
+
}
|
|
62
|
+
interface RunHistoryMetrics {
|
|
63
|
+
failed24h: number;
|
|
64
|
+
failed7d: number;
|
|
65
|
+
successful24h: number;
|
|
66
|
+
successful7d: number;
|
|
67
|
+
}
|
|
68
|
+
interface RunHistory {
|
|
69
|
+
hasMore: boolean;
|
|
70
|
+
metrics: RunHistoryMetrics;
|
|
71
|
+
runs: RunHistoryRun[];
|
|
72
|
+
}
|
|
73
|
+
interface AutomationCreditBalance {
|
|
74
|
+
availableMicros: number;
|
|
75
|
+
billingUrl: string;
|
|
76
|
+
display: string;
|
|
77
|
+
isLowBalance: boolean;
|
|
78
|
+
teamId: string;
|
|
79
|
+
}
|
|
80
|
+
interface AutomationArtifact {
|
|
81
|
+
artifactId: string;
|
|
82
|
+
contentType: string;
|
|
83
|
+
createdAt: string;
|
|
84
|
+
downloadUrl: string;
|
|
85
|
+
filename: string;
|
|
86
|
+
kind: 'html' | 'pdf';
|
|
87
|
+
previewUrl: string;
|
|
88
|
+
sizeBytes: number;
|
|
89
|
+
}
|
|
90
|
+
interface AutomationToolConfigInput {
|
|
91
|
+
channels: AutomationToolChannel[];
|
|
92
|
+
enabled: boolean;
|
|
93
|
+
provider: AutomationToolProvider;
|
|
94
|
+
}
|
|
95
|
+
interface AutomationInput {
|
|
96
|
+
enabled: boolean;
|
|
97
|
+
instructions: string;
|
|
98
|
+
modelId: string;
|
|
99
|
+
name: string;
|
|
100
|
+
toolConfigs: AutomationToolConfigInput[];
|
|
101
|
+
triggers: AutomationTrigger[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare function Automations(): PluginOptions;
|
|
105
|
+
|
|
106
|
+
export { type Automation, type AutomationArtifact, type AutomationCreditBalance, type AutomationInput, type AutomationRun, type AutomationRunStatus, type AutomationToolChannel, type AutomationToolProvider, Automations, type RunHistory, type RunHistoryRun };
|
package/dist/index.js
ADDED
|
@@ -0,0 +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{Ho as Automations};//# sourceMappingURL=index.js.map
|
|
3
|
+
//# sourceMappingURL=index.js.map
|