@flexkit/studio 0.2.17 → 0.2.19
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/activity-nav-button-V5DFHADL.js +2 -0
- package/dist/{activity-nav-button-7SVTTHBQ.js.map → activity-nav-button-V5DFHADL.js.map} +1 -1
- package/dist/chat-page-LAK4TFN4.js +4 -0
- package/dist/chat-page-LAK4TFN4.js.map +1 -0
- package/dist/chunk-2NXQF2F7.js +2 -0
- package/dist/chunk-2NXQF2F7.js.map +1 -0
- package/dist/chunk-4IEOAKKK.js +2 -0
- package/dist/chunk-4IEOAKKK.js.map +1 -0
- package/dist/{chunk-3C2EG3SI.js → chunk-54AXLGAK.js} +2 -2
- package/dist/{chunk-3C2EG3SI.js.map → chunk-54AXLGAK.js.map} +1 -1
- package/dist/chunk-6RRB47OZ.js +8 -0
- package/dist/chunk-6RRB47OZ.js.map +1 -0
- package/dist/chunk-A7XHA2P6.js +3 -0
- package/dist/chunk-A7XHA2P6.js.map +1 -0
- package/dist/chunk-BMO7JFAX.js +2 -0
- package/dist/chunk-BMO7JFAX.js.map +1 -0
- package/dist/{chunk-U5D3EDCY.js → chunk-BMX4URYN.js} +2 -2
- package/dist/{chunk-U5D3EDCY.js.map → chunk-BMX4URYN.js.map} +1 -1
- package/dist/chunk-CLCIE5RF.js +2 -0
- package/dist/chunk-CLCIE5RF.js.map +1 -0
- package/dist/{chunk-RYKUNA7Z.js → chunk-DFLAX7EE.js} +2 -2
- package/dist/{chunk-RYKUNA7Z.js.map → chunk-DFLAX7EE.js.map} +1 -1
- package/dist/chunk-DGIY4SKN.js +7 -0
- package/dist/chunk-DGIY4SKN.js.map +1 -0
- package/dist/chunk-DHVKE36X.js +3 -0
- package/dist/chunk-DHVKE36X.js.map +1 -0
- package/dist/chunk-EMFHKTAV.js +2 -0
- package/dist/chunk-EMFHKTAV.js.map +1 -0
- package/dist/chunk-ERDARDGB.js +2 -0
- package/dist/chunk-ERDARDGB.js.map +1 -0
- package/dist/chunk-H2RWSC56.js +3 -0
- package/dist/chunk-H2RWSC56.js.map +1 -0
- package/dist/{chunk-FDN23BPI.js → chunk-HCJAM5LG.js} +2 -2
- package/dist/{chunk-FDN23BPI.js.map → chunk-HCJAM5LG.js.map} +1 -1
- package/dist/chunk-ME55YNBF.js +30 -0
- package/dist/chunk-ME55YNBF.js.map +1 -0
- package/dist/chunk-OOYCTZ3C.js +379 -0
- package/dist/chunk-OOYCTZ3C.js.map +1 -0
- package/dist/chunk-QWQHXMXW.js +2 -0
- package/dist/{chunk-FNWEP2NM.js.map → chunk-QWQHXMXW.js.map} +1 -1
- package/dist/{chunk-ALCK2BJY.js → chunk-UOR437J2.js} +2 -2
- package/dist/{chunk-ALCK2BJY.js.map → chunk-UOR437J2.js.map} +1 -1
- package/dist/{chunk-3KMR2CXS.js → chunk-V6RB45UU.js} +2 -2
- package/dist/{chunk-3KMR2CXS.js.map → chunk-V6RB45UU.js.map} +1 -1
- package/dist/chunk-VMWUMFUL.js +4 -0
- package/dist/chunk-VMWUMFUL.js.map +1 -0
- package/dist/chunk-XMOSCJOI.js +2 -0
- package/dist/chunk-XMOSCJOI.js.map +1 -0
- package/dist/chunk-XNHSHVG2.js +7 -0
- package/dist/chunk-XNHSHVG2.js.map +1 -0
- package/dist/chunk-YDVO6XWD.js +2 -0
- package/dist/chunk-YDVO6XWD.js.map +1 -0
- package/dist/chunk-ZKA2HKNI.js +2 -0
- package/dist/chunk-ZKA2HKNI.js.map +1 -0
- package/dist/entry-3JSFO4OU.js +2 -0
- package/dist/entry-3JSFO4OU.js.map +1 -0
- package/dist/index.css +712 -246
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/list-SY3L2ACH.js +3 -0
- package/dist/list-SY3L2ACH.js.map +1 -0
- package/dist/list-Z2C74QDN.js +2 -0
- package/dist/{list-EXNTXASK.js.map → list-Z2C74QDN.js.map} +1 -1
- package/dist/pages-INCA54HE.js +5 -0
- package/dist/{pages-NWZLOKQM.js.map → pages-INCA54HE.js.map} +1 -1
- package/dist/plugin-pages-WO3MCJKC.js +2 -0
- package/dist/{plugin-pages-2KMZFNFB.js.map → plugin-pages-WO3MCJKC.js.map} +1 -1
- package/dist/record-links-CTB4SC4J.js +2 -0
- package/dist/record-links-CTB4SC4J.js.map +1 -0
- package/dist/root-6MSWGFZX.js +2 -0
- package/dist/root-6MSWGFZX.js.map +1 -0
- package/dist/root-B4D3C37Q.js +2 -0
- package/dist/root-B4D3C37Q.js.map +1 -0
- package/dist/root-DOOWSYWY.js +23 -0
- package/dist/root-DOOWSYWY.js.map +1 -0
- package/dist/root-JA2LFGNX.js +2 -0
- package/dist/root-JA2LFGNX.js.map +1 -0
- package/dist/root-OGX4DUTM.js +2 -0
- package/dist/root-OGX4DUTM.js.map +1 -0
- package/dist/{root-BRCN3D2D.js → root-XHXX3SZG.js} +3 -3
- package/dist/{root-BRCN3D2D.js.map → root-XHXX3SZG.js.map} +1 -1
- package/dist/search-Z4M4R4NJ.js +2 -0
- package/dist/{search-7IJJYUSR.js.map → search-Z4M4R4NJ.js.map} +1 -1
- package/dist/skills-pages-TP2XQPCQ.js +2 -0
- package/dist/{skills-pages-4ELHNJVY.js.map → skills-pages-TP2XQPCQ.js.map} +1 -1
- package/dist/source-5J56KIFA.js +2 -0
- package/dist/source-5J56KIFA.js.map +1 -0
- package/dist/spec-renderer-3GAVSV52.js +2 -0
- package/dist/{spec-renderer-EX7SCFWH.js.map → spec-renderer-3GAVSV52.js.map} +1 -1
- package/dist/ui.d.ts +15 -5
- package/dist/ui.js +1 -1
- package/package.json +13 -5
- package/dist/activity-nav-button-7SVTTHBQ.js +0 -2
- package/dist/chat-page-X3MIN6YC.js +0 -4
- package/dist/chat-page-X3MIN6YC.js.map +0 -1
- package/dist/chunk-7ZFUS62K.js +0 -3
- package/dist/chunk-7ZFUS62K.js.map +0 -1
- package/dist/chunk-D6H64Z37.js +0 -8
- package/dist/chunk-D6H64Z37.js.map +0 -1
- package/dist/chunk-FNWEP2NM.js +0 -2
- package/dist/chunk-NLRSLQUT.js +0 -3
- package/dist/chunk-NLRSLQUT.js.map +0 -1
- package/dist/chunk-P6BZ4QP7.js +0 -2
- package/dist/chunk-P6BZ4QP7.js.map +0 -1
- package/dist/chunk-PKAWL5W4.js +0 -4
- package/dist/chunk-PKAWL5W4.js.map +0 -1
- package/dist/chunk-RNMAR527.js +0 -384
- package/dist/chunk-RNMAR527.js.map +0 -1
- package/dist/chunk-YCCFUGWJ.js +0 -7
- package/dist/chunk-YCCFUGWJ.js.map +0 -1
- package/dist/list-EXNTXASK.js +0 -2
- package/dist/pages-NWZLOKQM.js +0 -5
- package/dist/plugin-pages-2KMZFNFB.js +0 -2
- package/dist/root-A6FK3OR6.js +0 -2
- package/dist/root-A6FK3OR6.js.map +0 -1
- package/dist/root-CUNQWMK4.js +0 -23
- package/dist/root-CUNQWMK4.js.map +0 -1
- package/dist/root-SCCUPXFD.js +0 -2
- package/dist/root-SCCUPXFD.js.map +0 -1
- package/dist/search-7IJJYUSR.js +0 -2
- package/dist/skills-pages-4ELHNJVY.js +0 -2
- package/dist/spec-renderer-EX7SCFWH.js +0 -2
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import'./index.css';import {a as a$1}from'./chunk-CLCIE5RF.js';import {a}from'./chunk-EMFHKTAV.js';import {e,b as b$1,j,n,c as c$2,i as i$1,h as h$1,l as l$2,o,k as k$2}from'./chunk-4IEOAKKK.js';import'./chunk-2NXQF2F7.js';import {c}from'./chunk-CAZ6EUR2.js';import {b}from'./chunk-ZZRA4567.js';import {x,k,e as e$1,y,d as d$1,b as b$4,f,l as l$1,j as j$2,g,h as h$2}from'./chunk-A7XHA2P6.js';import'./chunk-H2RWSC56.js';import'./chunk-2HYQVMP3.js';import'./chunk-5CVDMZUI.js';import {Tc,Vc,s,c as c$1,d,na,$,aa,da,ea,ba,O,e as e$3,qa,fa}from'./chunk-DGIY4SKN.js';import {t}from'./chunk-SZEGGBOC.js';import {v,c as c$4,h,i,k as k$1,l,j as j$1,b as b$5}from'./chunk-32ZU4MLE.js';import'./chunk-U45E5X3H.js';import'./chunk-HDOIOXMP.js';import {b as b$3,c as c$3,e as e$2}from'./chunk-USNXQOMJ.js';import {b as b$2}from'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {useState,useRef,useMemo,useEffect}from'react';import {formatDistance,format}from'date-fns';import {SearchIcon,XIcon,ListIcon,LayoutGridIcon,LinkIcon,UploadIcon,LoaderCircle}from'lucide-react';import {useNavigate,Link}from'react-router-dom';import st from'swr/infinite';import {jsx,jsxs}from'react/jsx-runtime';var He=25,it=3e3,rt=250;function ft(t,a){let[o,s]=useState(t);return useEffect(()=>{let r=setTimeout(()=>s(t),a);return ()=>clearTimeout(r)},[a,t]),o}var dt={failed:"No document failed to index.",processing:"No document is being indexed right now.",ready:"No document is ready yet."};function ct({viewMode:t$1}){let a=["a","b","c","d","e","f"];return t$1==="grid"?jsxs("div",{"aria-busy":"true",className:Oe,children:[jsx("span",{className:"fk:sr-only",children:"Loading documents"}),a.map(o=>jsxs("div",{className:"fk:flex fk:flex-col fk:gap-3 fk:rounded-xl fk:border fk:p-3 fk:corner-squircle",children:[jsxs("span",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(t,{className:"fk:size-6 fk:rounded-md"}),jsx(t,{className:"fk:h-4 fk:flex-1"})]}),jsx(t,{className:"fk:aspect-[4/3] fk:w-full fk:rounded-lg"})]},o))]}):jsxs("div",{"aria-busy":"true",className:"fk:flex fk:flex-col",children:[jsx("span",{className:"fk:sr-only",children:"Loading documents"}),a.map(o=>jsxs("div",{className:"fk:flex fk:h-12 fk:items-center fk:gap-3 fk:border-b fk:px-3",children:[jsx(t,{className:"fk:size-6 fk:shrink-0 fk:rounded-md"}),jsx(t,{className:"fk:h-4 fk:w-1/3"}),jsx(t,{className:"fk:ml-auto fk:h-4 fk:w-16"}),jsx(t,{className:"fk:hidden fk:h-4 fk:w-24 fk:md:block"})]},o))]})}function kt(t,a){let[o,s]=useState([]),r=useRef(Promise.resolve());function m(p){if(t)for(let f$1 of p){let u=f(f$1);if(u){qa.error(u);continue}let d={id:`${f$1.name}-${String(Date.now())}-${String(Math.random())}`,name:f$1.name};s(i=>[...i,d]),r.current=r.current.then(async()=>{try{let i=await t.addFile(f$1);i$1(i,f$1.name),a();}catch(i){qa.error(h$1(i,`${f$1.name} could not be added.`));}finally{s(i=>i.filter(w=>w.id!==d.id));}}).catch(()=>{});}}return {addFiles:m,pending:o}}function ut({api:t,onOpenChange:a,onRegistered:o,open:s$1}){let[r,m]=useState(""),[p,f]=useState(""),[u,d]=useState(""),[i$2,w]=useState(false);function N(){a(false),m(""),f(""),d("");}async function K(c){c.preventDefault();let x=h$2(r);if("error"in x){d(x.error);return}w(true),d("");try{let E=await t.addUrl({title:p.trim()||void 0,url:x.url});i$1(E,x.url),o(),N();}catch(E){d(h$1(E,"The page could not be added."));}finally{w(false);}}return jsx(c$4,{open:s$1,onOpenChange:c=>c?a(true):N(),children:jsx(h,{children:jsxs("form",{className:"fk:flex fk:flex-col fk:gap-4",onSubmit:c=>{K(c);},children:[jsxs(i,{children:[jsx(k$1,{children:"Add a web page"}),jsx(l,{children:"The page is fetched and indexed now, and again whenever you re-index it. Only public pages work."})]}),jsxs("div",{className:"fk:flex fk:flex-col fk:gap-1.5",children:[jsx(e$3,{htmlFor:"knowledge-url",children:"Address"}),jsx(s,{autoFocus:true,id:"knowledge-url",inputMode:"url",placeholder:"https://example.com/help/returns",value:r,onChange:c=>{m(c.target.value),d("");}})]}),jsxs("div",{className:"fk:flex fk:flex-col fk:gap-1.5",children:[jsx(e$3,{htmlFor:"knowledge-url-title",children:"Title (optional)"}),jsx(s,{id:"knowledge-url-title",maxLength:b$4,placeholder:"Defaults to the page address",value:p,onChange:c=>f(c.target.value)})]}),u?jsx("p",{className:"fk:text-sm fk:text-destructive",children:u}):null,jsxs(j$1,{children:[jsx(b$2,{disabled:i$2,size:"sm",type:"button",variant:"outline",onClick:N,children:"Cancel"}),jsxs(b$2,{disabled:i$2||!r.trim(),size:"sm",type:"submit",children:[i$2?jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}):jsx(LinkIcon,{className:"fk:size-4"}),"Add page"]})]})]})})})}var Oe="fk:grid fk:grid-cols-[repeat(auto-fill,minmax(14rem,1fr))] fk:gap-4";function mt(t){return format(new Date(t),"MMM d, yyyy")}function Ue(){return jsx(b$5,{className:"fk:shrink-0 fk:corner-squircle",variant:"outline",children:"Hidden from agent"})}function Ge(){return jsx(b$5,{className:"fk:shrink-0 fk:corner-squircle","data-knowledge-content-match":true,variant:"secondary",children:"In content"})}function pt(t,a){let o=t.target;t.defaultPrevented||t.button!==0||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||!t.currentTarget.contains(o)||o.closest("a, button")||a();}function gt({source:t,...a}){let o$1=l$1(t),s=o$1.tone==="ready"?"fk:hidden fk:xl:inline":"fk:hidden fk:md:inline";return jsxs(da,{className:"fk:h-12 fk:cursor-pointer","data-knowledge-row":true,onClick:r=>pt(r,()=>a.onOpen(t)),children:[jsx(fa,{className:"fk:max-w-0 fk:w-full",children:jsxs("span",{className:"fk:flex fk:min-w-0 fk:items-center fk:gap-3",children:[jsx(l$2,{source:t}),jsx(Link,{className:"fk:truncate fk:text-sm fk:font-medium fk:hover:underline fk:underline-offset-2 fk:focus-visible:outline-none fk:focus-visible:underline",to:t.id,children:t.title}),t.matchedIn==="content"?jsx(Ge,{}):null,t.agentVisible?null:jsx(Ue,{})]})}),jsx(fa,{className:"fk:whitespace-nowrap",children:jsxs("span",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(k$2,{label:o$1.label,tone:o$1.tone}),jsx("span",{className:`${s} fk:max-w-64 fk:truncate fk:text-xs fk:text-muted-foreground`,title:o$1.detail,children:o$1.detail})]})}),jsx(fa,{className:"fk:hidden fk:whitespace-nowrap fk:text-muted-foreground fk:md:table-cell",children:j$2(t)}),jsx(fa,{className:"fk:hidden fk:whitespace-nowrap fk:text-right fk:tabular-nums fk:text-muted-foreground fk:md:table-cell",children:t.size===null?"\u2014":g(t.size)}),jsx(fa,{className:"fk:hidden fk:whitespace-nowrap fk:text-muted-foreground fk:sm:table-cell",children:jsxs(b$3,{children:[jsx(c$3,{asChild:true,children:jsx("span",{children:mt(t.createdAt)})}),jsxs(e$2,{children:["Updated ",formatDistance(new Date(t.updatedAt),new Date,{addSuffix:true})]})]})}),jsx(fa,{className:"fk:w-12 fk:pr-2 fk:text-right",children:jsx(o,{source:t,onOpen:()=>a.onOpen(t),onRemoved:()=>a.onRemoved(t)})})]})}function ht({sources:t,...a}){return jsxs($,{"data-knowledge-list":true,children:[jsx(aa,{children:jsxs(da,{className:"fk:hover:bg-transparent",children:[jsx(ea,{children:"Name"}),jsx(ea,{children:"Status"}),jsx(ea,{className:"fk:hidden fk:md:table-cell",children:"Type"}),jsx(ea,{className:"fk:hidden fk:text-right fk:md:table-cell",children:"Size"}),jsx(ea,{className:"fk:hidden fk:sm:table-cell",children:"Added"}),jsx(ea,{className:"fk:w-12",children:jsx("span",{className:"fk:sr-only",children:"Actions"})})]})}),jsx(ba,{children:t.map(o=>jsx(gt,{source:o,...a},o.id))})]})}function bt({source:t}){let a=t.preview?.trim();return jsx("div",{className:"fk:relative fk:aspect-[4/3] fk:overflow-hidden fk:rounded-lg fk:bg-muted fk:corner-squircle",children:a?jsxs("div",{"aria-hidden":true,className:"fk:absolute fk:inset-x-4 fk:top-3 fk:bottom-0 fk:overflow-hidden fk:rounded-t-sm fk:bg-background fk:px-3 fk:pt-3 fk:shadow-sm",children:[jsx("p",{className:"fk:whitespace-pre-line fk:text-[9px] fk:leading-[1.45] fk:text-foreground/80 fk:select-none",children:a}),jsx("span",{className:"fk:pointer-events-none fk:absolute fk:inset-x-0 fk:bottom-0 fk:h-10 fk:bg-gradient-to-t fk:from-background fk:to-transparent"})]}):jsx("div",{className:"fk:flex fk:h-full fk:items-center fk:justify-center",children:jsx(l$2,{size:56,source:t})})})}function vt({source:t,...a}){let o$1=l$1(t),s=[j$2(t)];return t.size!==null&&s.push(g(t.size)),s.push(o$1.detail),jsxs("div",{className:"fk:relative fk:flex fk:min-w-0 fk:flex-col fk:gap-3 fk:rounded-xl fk:border fk:bg-card fk:p-3 fk:transition-colors fk:hover:bg-accent/60 fk:has-[>a:focus-visible]:ring-2 fk:has-[>a:focus-visible]:ring-ring fk:corner-squircle","data-knowledge-card":true,title:t.title,children:[jsx(Link,{"aria-label":`Open ${t.title}`,className:"fk:absolute fk:inset-0 fk:rounded-xl fk:focus-visible:outline-none fk:corner-squircle",to:t.id}),jsxs("span",{className:"fk:pointer-events-none fk:relative fk:flex fk:min-w-0 fk:items-center fk:gap-2",children:[jsx(l$2,{source:t}),jsx("span",{className:"fk:min-w-0 fk:flex-1 fk:truncate fk:text-sm fk:font-medium",children:t.title}),jsx("span",{className:"fk:pointer-events-auto fk:-my-1 fk:-mr-1.5",children:jsx(o,{source:t,onOpen:()=>a.onOpen(t),onRemoved:()=>a.onRemoved(t)})})]}),jsx("span",{className:"fk:pointer-events-none fk:relative",children:jsx(bt,{source:t})}),jsxs("span",{className:"fk:pointer-events-none fk:relative fk:flex fk:min-w-0 fk:items-center fk:gap-2",children:[jsx(k$2,{label:o$1.label,tone:o$1.tone}),jsx("span",{className:"fk:min-w-0 fk:flex-1 fk:truncate fk:text-xs fk:text-muted-foreground",children:s.join(" \xB7 ")}),t.matchedIn==="content"?jsx(Ge,{}):null,t.agentVisible?null:jsx(Ue,{})]})]})}function wt({sources:t,...a}){return jsx("div",{className:Oe,"data-knowledge-grid":true,children:t.map(o=>jsx(vt,{source:o,...a},o.id))})}function Nt(){return jsxs("div",{className:"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2 fk:pr-4",children:[jsxs(b$3,{children:[jsx(c$3,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$2,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:h-4"}),jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:"Knowledge"})]})}function Pt(){let{api:t,projectId:a$2}=e(),o=useNavigate(),s$1=b(),r=c(),m=a(),[p,f]=useState(""),u=ft(p.trim(),rt),[d$2,i]=useState(()=>x()),[w,N]=useState(false),K=useRef(null),c$3=useRef(null),[x$1,E]=useState(false),Ve=(l,T)=>!a$2||T&&!T.hasMore?null:c$2(a$2).sources({limit:He,offset:l*He,search:u||void 0,status:m}),{data:h,isLoading:Xe,mutate:L,setSize:A,size:Je}=st(Ve,b$1,{refreshInterval:r&&x$1?it:0}),S=useMemo(()=>h?.flatMap(l=>l.sources)??[],[h]),z=h?.[0]?.count??0,qe=h?.[h.length-1]?.hasMore??false,te=h!==void 0&&Je>h.length,$e=Xe&&S.length===0,{addFiles:ne,pending:ae}=kt(t,()=>{L();}),oe=useRef(L);oe.current=L,useEffect(()=>{oe.current();},[]),useEffect(()=>{E(S.some(l=>k(l)));},[S]);let le=useRef(A);if(le.current=A,useEffect(()=>{le.current(1);},[u]),!a$2||!t)return jsx(j,{children:"Select a project to manage its knowledge."});function je(l){let T=Array.from(l.target.files??[]);l.target.value="",ne(T);}let P=`No documents yet. Upload ${e$1} files, or add a public web page, and the agent will search and cite them.`;u?P="No document title or content matches your search.":m&&(P=dt[m]);let se={onOpen:l=>{o(l.id);},onRemoved:l=>{L(T=>T?.map(F=>({...F,count:Math.max(0,F.count-1),sources:F.sources.filter(We=>We.id!==l.id)})),{revalidate:true});}},R=d$2==="grid"?jsx(wt,{sources:S,...se}):jsx(ht,{sources:S,...se});return $e?R=jsx(ct,{viewMode:d$2}):S.length===0&&(R=jsx(Tc,{children:jsx(Vc,{children:P})})),jsxs("main",{className:"fk:flex fk:min-h-0 fk:flex-1 fk:flex-col",children:[jsx(Nt,{}),jsx(a$1,{disabled:!s$1,onDropFiles:ne,children:jsx("div",{className:"fk:min-h-0 fk:flex-1 fk:overflow-auto",children:jsxs("div",{className:"fk:flex fk:w-full fk:flex-col fk:gap-5 fk:py-4 fk:pl-4 fk:pr-6",children:[jsxs("div",{children:[jsx("h2",{className:"fk:text-2xl fk:font-semibold",children:"Documents"}),jsx("p",{className:"fk:mt-1 fk:text-sm fk:text-muted-foreground",children:"Policies, manuals, specs and other reference material for your team and agents. The agent searches them when a question needs them and cites the passage it used."})]}),jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-3",children:[jsxs("div",{className:"fk:relative fk:w-full fk:max-w-sm",children:[jsx(SearchIcon,{className:"fk:pointer-events-none fk:absolute fk:left-2.5 fk:top-1/2 fk:size-4 fk:-translate-y-1/2 fk:text-muted-foreground"}),jsx(s,{"aria-label":"Search documents",className:"fk:pl-8 fk:pr-9",placeholder:"Search by title or content\u2026",ref:c$3,value:p,onChange:l=>f(l.target.value)}),p?jsx(b$2,{"aria-label":"Clear search",className:"fk:absolute fk:right-1.5 fk:top-1/2 fk:flex fk:size-6 fk:-translate-y-1/2 fk:items-center fk:justify-center fk:rounded-full fk:bg-transparent fk:text-muted-foreground fk:hover:bg-foreground/10 fk:hover:text-foreground fk:corner-squircle","data-knowledge-clear-search":true,type:"button",onClick:()=>{f(""),c$3.current?.focus();},children:jsx(XIcon,{className:"fk:size-4"})}):null]}),z>0?jsxs("span",{className:"fk:text-sm fk:text-muted-foreground",children:[z.toLocaleString()," ",z===1?"document":"documents"]}):null,jsxs("div",{className:"fk:ml-auto fk:flex fk:items-center fk:gap-2",children:[jsxs(c$1,{"aria-label":"Layout",size:"sm",type:"single",value:d$2,variant:"outline",onValueChange:l=>{(l==="list"||l==="grid")&&(i(l),y(l));},children:[jsx(d,{"aria-label":"List layout",value:"list",children:jsx(ListIcon,{className:"fk:size-4"})}),jsx(d,{"aria-label":"Grid layout",value:"grid",children:jsx(LayoutGridIcon,{className:"fk:size-4"})})]}),jsx(na,{disabled:!s$1,children:jsxs(b$2,{disabled:!s$1,size:"sm",variant:"outline",onClick:()=>N(true),children:[jsx(LinkIcon,{}),"Add web page"]})}),jsx(na,{disabled:!s$1,children:jsxs(b$2,{disabled:!s$1,size:"sm",onClick:()=>K.current?.click(),children:[jsx(UploadIcon,{}),"Upload documents"]})}),jsx("input",{accept:d$1,className:"fk:hidden",multiple:true,ref:K,type:"file",onChange:je})]})]}),ae.length>0?jsx("div",{className:"fk:flex fk:flex-col fk:gap-1 fk:text-sm fk:text-muted-foreground",children:ae.map(l=>jsxs("span",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),"Uploading ",l.name,"\u2026"]},l.id))}):null,R,qe&&!te?jsx(n,{onVisible:()=>{A(l=>l+1);}}):null,te?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 documents..."})]}):null]})})}),jsx(ut,{api:t,open:w,onOpenChange:N,onRegistered:()=>{L();}})]})}
|
|
2
|
+
export{Pt as List};//# sourceMappingURL=list-SY3L2ACH.js.map
|
|
3
|
+
//# sourceMappingURL=list-SY3L2ACH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/apps/knowledge/list.tsx"],"names":["KNOWLEDGE_PAGE_SIZE","LIST_POLL_INTERVAL_MS","SEARCH_DEBOUNCE_MS","useDebouncedValue","value","delayMs","debounced","setDebounced","useState","useEffect","timer","EMPTY_BY_FILTER","KnowledgeListSkeleton","viewMode","ids","jsxs","GRID_CLASSES","jsx","id","Skeleton","useKnowledgeUploads","api","onRegistered","pending","setPending","queueRef","useRef","addFiles","files","file","problem","getKnowledgeFileProblem","toast","upload","current","result","announceRegistered","error","describeApiError","entry","AddUrlDialog","onOpenChange","open","setValue","title","setTitle","setError","isSubmitting","setIsSubmitting","close","handleSubmit","event","parsed","parseKnowledgeUrl","submitError","Dialog","next","DialogContent","DialogHeader","DialogTitle","DialogDescription","Label","Input","KNOWLEDGE_MAX_TITLE_LENGTH","DialogFooter","Button","LoaderCircle","LinkIcon","formatAdded","iso","format","HiddenBadge","Badge","ContentMatchBadge","handleRowClick","target","SourceListRow","source","actions","status","summarizeKnowledgeStatus","detailClass","TableRow","TableCell","KnowledgeTypeIcon","Link","StatusBadge","getKnowledgeKindLabel","formatFileSize","Tooltip","TooltipTrigger","TooltipContent","formatDistance","SourceActionsMenu","SourceTable","sources","Table","TableHeader","TableHead","TableBody","SourcePreview","preview","SourceCard","meta","SourceGrid","ListHeader","SidebarTrigger","Separator","List","projectId","useProjectKnowledge","navigate","useNavigate","canMutate","useCanMutate","isViewing","useIsViewing","useKnowledgeStatusFilter","search","setSearch","query","setViewMode","getStoredKnowledgeViewMode","isUrlDialogOpen","setIsUrlDialogOpen","fileInputRef","searchInputRef","isBusy","setIsBusy","getSourcesKey","pageIndex","previousPage","knowledgePaths","pages","isLoading","mutate","setSize","size","useSWRInfinite","fetcher","useMemo","page","total","hasMore","isLoadingMore","isInitialLoading","mutateRef","isKnowledgeSourceBusy","setSizeRef","PageMessage","handleFilesPicked","emptyMessage","KNOWLEDGE_FORMATS_LABEL","removed","content","Alert","AlertDescription","AssetDropZone","SearchIcon","XIcon","ToggleGroup","setStoredKnowledgeViewMode","ToggleGroupItem","ListIcon","LayoutGridIcon","PermissionTooltip","UploadIcon","KNOWLEDGE_ACCEPT","InfiniteScrollSentinel"],"mappings":"gqCAoEA,IAAMA,EAAAA,CAAsB,EAAA,CACtBC,EAAAA,CAAwB,GAAA,CAExBC,EAAAA,CAAqB,GAAA,CAE3B,SAASC,EAAAA,CAAqBC,CAAAA,CAAUC,CAAAA,CAAoB,CAC1D,GAAM,CAACC,CAAAA,CAAWC,CAAY,CAAA,CAAIC,QAAAA,CAASJ,CAAK,CAAA,CAEhD,OAAAK,SAAAA,CAAU,IAAM,CACd,IAAMC,CAAAA,CAAQ,UAAA,CAAW,IAAMH,CAAAA,CAAaH,CAAK,CAAA,CAAGC,CAAO,CA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AQhC,CAAAA,CAAStG,CAAAA,EAAYA,CAAAA,CAAU,CAAC,EAAA,CAAA,CAAG,CAAA,CAC/E,IAAA,CACH8G,EAAAA,CACCjI,IAAAA,CAAC,KAAA,CAAA,CAAI,SAAA,CAAU,gGAAA,CACb,QAAA,CAAA,CAAAE,GAAAA,CAACiD,YAAAA,CAAA,CAAa,SAAA,CAAU,2BAAA,CAA4B,CAAA,CACpDjD,GAAAA,CAAC,MAAA,CAAA,CAAK,QAAA,CAAA,2BAAA,CAAyB,CAAA,CAAA,CACjC,CAAA,CACE,IAAA,CAAA,CACN,CAAA,CACF,CAAA,CACF,CAAA,CACAA,GAAAA,CAACuB,EAAAA,CAAA,CACC,GAAA,CAAKnB,CAAAA,CACL,IAAA,CAAMsG,CAAAA,CACN,YAAA,CAAcC,CAAAA,CACd,YAAA,CAAc,IAAG,CAAQW,CAAAA,GAAO,CAAA,CAClC,GACF,CAEJ","file":"list-SY3L2ACH.js","sourcesContent":["import type { ChangeEvent, FormEvent, JSX, MouseEvent } from 'react';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { format, formatDistance } from 'date-fns';\nimport { LayoutGridIcon, LinkIcon, ListIcon, LoaderCircle, SearchIcon, UploadIcon, XIcon } from 'lucide-react';\nimport { Link, useNavigate } from 'react-router-dom';\nimport useSWRInfinite from 'swr/infinite';\nimport { useIsViewing } from '../../core/apps/app-active';\nimport { useCanMutate } from '../../core/permissions';\nimport {\n Alert,\n AlertDescription,\n Badge,\n Button,\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeader,\n TableRow,\n ToggleGroup,\n ToggleGroupItem,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n Input,\n Label,\n PermissionTooltip,\n Separator,\n SidebarTrigger,\n Skeleton,\n toast,\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from '../../ui';\nimport { AssetDropZone } from '../asset-manager/data-grid/asset-drop-zone';\nimport { fetcher, knowledgePaths, type KnowledgeApi } from './api';\nimport {\n formatFileSize,\n getKnowledgeFileProblem,\n getKnowledgeKindLabel,\n getStoredKnowledgeViewMode,\n isKnowledgeSourceBusy,\n KNOWLEDGE_ACCEPT,\n KNOWLEDGE_FORMATS_LABEL,\n KNOWLEDGE_MAX_TITLE_LENGTH,\n parseKnowledgeUrl,\n setStoredKnowledgeViewMode,\n summarizeKnowledgeStatus,\n type KnowledgeSource,\n type KnowledgeSourcesList,\n type KnowledgeViewMode,\n} from './knowledge';\nimport {\n announceRegistered,\n describeApiError,\n InfiniteScrollSentinel,\n KnowledgeTypeIcon,\n PageMessage,\n SourceActionsMenu,\n StatusBadge,\n useProjectKnowledge,\n} from './shared';\nimport { useKnowledgeStatusFilter } from './sidebar';\n\nconst KNOWLEDGE_PAGE_SIZE = 25;\nconst LIST_POLL_INTERVAL_MS = 3_000;\n/** Typing pauses this long before the list asks the platform; each ask now searches the documents' text too. */\nconst SEARCH_DEBOUNCE_MS = 250;\n\nfunction useDebouncedValue<T>(value: T, delayMs: number): T {\n const [debounced, setDebounced] = useState(value);\n\n useEffect(() => {\n const timer = setTimeout(() => setDebounced(value), delayMs);\n\n return () => clearTimeout(timer);\n }, [delayMs, value]);\n\n return debounced;\n}\n\nconst EMPTY_BY_FILTER = {\n failed: 'No document failed to index.',\n processing: 'No document is being indexed right now.',\n ready: 'No document is ready yet.',\n};\n\nfunction KnowledgeListSkeleton({ viewMode }: { viewMode: KnowledgeViewMode }): JSX.Element {\n const ids = ['a', 'b', 'c', 'd', 'e', 'f'];\n\n if (viewMode === 'grid') {\n return (\n <div aria-busy=\"true\" className={GRID_CLASSES}>\n <span className=\"fk:sr-only\">Loading documents</span>\n {ids.map((id) => (\n <div className=\"fk:flex fk:flex-col fk:gap-3 fk:rounded-xl fk:border fk:p-3 fk:corner-squircle\" key={id}>\n <span className=\"fk:flex fk:items-center fk:gap-2\">\n <Skeleton className=\"fk:size-6 fk:rounded-md\" />\n <Skeleton className=\"fk:h-4 fk:flex-1\" />\n </span>\n <Skeleton className=\"fk:aspect-[4/3] fk:w-full fk:rounded-lg\" />\n </div>\n ))}\n </div>\n );\n }\n\n return (\n <div aria-busy=\"true\" className=\"fk:flex fk:flex-col\">\n <span className=\"fk:sr-only\">Loading documents</span>\n {ids.map((id) => (\n <div className=\"fk:flex fk:h-12 fk:items-center fk:gap-3 fk:border-b fk:px-3\" key={id}>\n <Skeleton className=\"fk:size-6 fk:shrink-0 fk:rounded-md\" />\n <Skeleton className=\"fk:h-4 fk:w-1/3\" />\n <Skeleton className=\"fk:ml-auto fk:h-4 fk:w-16\" />\n <Skeleton className=\"fk:hidden fk:h-4 fk:w-24 fk:md:block\" />\n </div>\n ))}\n </div>\n );\n}\n\ninterface PendingUpload {\n id: string;\n name: string;\n}\n\n/** Runs file uploads one after another and reports each outcome; the list revalidates after every registration. */\nfunction useKnowledgeUploads(\n api: KnowledgeApi | null,\n onRegistered: () => void\n): {\n addFiles: (_files: File[]) => void;\n pending: PendingUpload[];\n} {\n const [pending, setPending] = useState<PendingUpload[]>([]);\n const queueRef = useRef<Promise<void>>(Promise.resolve());\n\n function addFiles(files: File[]): void {\n if (!api) {\n return;\n }\n\n for (const file of files) {\n const problem = getKnowledgeFileProblem(file);\n\n if (problem) {\n toast.error(problem);\n\n continue;\n }\n\n const upload: PendingUpload = {\n id: `${file.name}-${String(Date.now())}-${String(Math.random())}`,\n name: file.name,\n };\n\n setPending((current) => [...current, upload]);\n queueRef.current = queueRef.current\n .then(async () => {\n try {\n const result = await api.addFile(file);\n\n announceRegistered(result, file.name);\n onRegistered();\n } catch (error) {\n toast.error(describeApiError(error, `${file.name} could not be added.`));\n } finally {\n setPending((current) => current.filter((entry) => entry.id !== upload.id));\n }\n })\n .catch(() => undefined);\n }\n }\n\n return { addFiles, pending };\n}\n\nfunction AddUrlDialog({\n api,\n onOpenChange,\n onRegistered,\n open,\n}: {\n api: KnowledgeApi;\n onOpenChange: (_open: boolean) => void;\n onRegistered: () => void;\n open: boolean;\n}): JSX.Element {\n const [value, setValue] = useState('');\n const [title, setTitle] = useState('');\n const [error, setError] = useState('');\n const [isSubmitting, setIsSubmitting] = useState(false);\n\n function close(): void {\n onOpenChange(false);\n setValue('');\n setTitle('');\n setError('');\n }\n\n async function handleSubmit(event: FormEvent<HTMLFormElement>): Promise<void> {\n event.preventDefault();\n\n const parsed = parseKnowledgeUrl(value);\n\n if ('error' in parsed) {\n setError(parsed.error);\n\n return;\n }\n\n setIsSubmitting(true);\n setError('');\n\n try {\n const result = await api.addUrl({ title: title.trim() || undefined, url: parsed.url });\n\n announceRegistered(result, parsed.url);\n onRegistered();\n close();\n } catch (submitError) {\n setError(describeApiError(submitError, 'The page could not be added.'));\n } finally {\n setIsSubmitting(false);\n }\n }\n\n return (\n <Dialog open={open} onOpenChange={(next) => (next ? onOpenChange(true) : close())}>\n <DialogContent>\n <form className=\"fk:flex fk:flex-col fk:gap-4\" onSubmit={(event) => void handleSubmit(event)}>\n <DialogHeader>\n <DialogTitle>Add a web page</DialogTitle>\n <DialogDescription>\n The page is fetched and indexed now, and again whenever you re-index it. Only public pages work.\n </DialogDescription>\n </DialogHeader>\n <div className=\"fk:flex fk:flex-col fk:gap-1.5\">\n <Label htmlFor=\"knowledge-url\">Address</Label>\n <Input\n autoFocus\n id=\"knowledge-url\"\n inputMode=\"url\"\n placeholder=\"https://example.com/help/returns\"\n value={value}\n onChange={(event) => {\n setValue(event.target.value);\n setError('');\n }}\n />\n </div>\n <div className=\"fk:flex fk:flex-col fk:gap-1.5\">\n <Label htmlFor=\"knowledge-url-title\">Title (optional)</Label>\n <Input\n id=\"knowledge-url-title\"\n maxLength={KNOWLEDGE_MAX_TITLE_LENGTH}\n placeholder=\"Defaults to the page address\"\n value={title}\n onChange={(event) => setTitle(event.target.value)}\n />\n </div>\n {error ? <p className=\"fk:text-sm fk:text-destructive\">{error}</p> : null}\n <DialogFooter>\n <Button disabled={isSubmitting} size=\"sm\" type=\"button\" variant=\"outline\" onClick={close}>\n Cancel\n </Button>\n <Button disabled={isSubmitting || !value.trim()} size=\"sm\" type=\"submit\">\n {isSubmitting ? (\n <LoaderCircle className=\"fk:size-4 fk:animate-spin\" />\n ) : (\n <LinkIcon className=\"fk:size-4\" />\n )}\n Add page\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n );\n}\n\nconst GRID_CLASSES = 'fk:grid fk:grid-cols-[repeat(auto-fill,minmax(14rem,1fr))] fk:gap-4';\n\nfunction formatAdded(iso: string): string {\n return format(new Date(iso), 'MMM d, yyyy');\n}\n\nfunction HiddenBadge(): JSX.Element {\n return (\n <Badge className=\"fk:shrink-0 fk:corner-squircle\" variant=\"outline\">\n Hidden from agent\n </Badge>\n );\n}\n\n/** A search hit whose title does not carry the words: the text inside does. */\nfunction ContentMatchBadge(): JSX.Element {\n return (\n <Badge className=\"fk:shrink-0 fk:corner-squircle\" data-knowledge-content-match variant=\"secondary\">\n In content\n </Badge>\n );\n}\n\ninterface SourceActions {\n onOpen: (_source: KnowledgeSource) => void;\n onRemoved: (_source: KnowledgeSource) => void;\n}\n\ntype SourceItemProps = SourceActions & { source: KnowledgeSource };\n\n/**\n * A plain click on the row opens the document. Clicks that bubbled up from\n * a portal (the menu, the removal dialog), modified clicks (the title link\n * handles new tabs itself) and clicks on the row's own controls are not.\n */\nfunction handleRowClick(event: MouseEvent<HTMLElement>, open: () => void): void {\n const target = event.target as Node;\n\n if (\n event.defaultPrevented ||\n event.button !== 0 ||\n event.metaKey ||\n event.ctrlKey ||\n event.shiftKey ||\n event.altKey ||\n !event.currentTarget.contains(target) ||\n (target as Element).closest('a, button')\n ) {\n return;\n }\n\n open();\n}\n\n/**\n * One line of the list: the type mark, the title as a real link (so it can\n * be opened in a new tab), then the status and facts in columns, like a file\n * manager. The whole row is clickable for the mouse; the link carries the\n * keyboard and assistive tech.\n */\nfunction SourceListRow({ source, ...actions }: SourceItemProps): JSX.Element {\n const status = summarizeKnowledgeStatus(source);\n // What went wrong, or what is happening, matters at every width; the passage count can wait for a wide one.\n const detailClass = status.tone === 'ready' ? 'fk:hidden fk:xl:inline' : 'fk:hidden fk:md:inline';\n\n return (\n <TableRow\n className=\"fk:h-12 fk:cursor-pointer\"\n data-knowledge-row\n onClick={(event) => handleRowClick(event, () => actions.onOpen(source))}\n >\n <TableCell className=\"fk:max-w-0 fk:w-full\">\n <span className=\"fk:flex fk:min-w-0 fk:items-center fk:gap-3\">\n <KnowledgeTypeIcon source={source} />\n <Link\n className=\"fk:truncate fk:text-sm fk:font-medium fk:hover:underline fk:underline-offset-2 fk:focus-visible:outline-none fk:focus-visible:underline\"\n to={source.id}\n >\n {source.title}\n </Link>\n {source.matchedIn === 'content' ? <ContentMatchBadge /> : null}\n {!source.agentVisible ? <HiddenBadge /> : null}\n </span>\n </TableCell>\n <TableCell className=\"fk:whitespace-nowrap\">\n <span className=\"fk:flex fk:items-center fk:gap-2\">\n <StatusBadge label={status.label} tone={status.tone} />\n <span\n className={`${detailClass} fk:max-w-64 fk:truncate fk:text-xs fk:text-muted-foreground`}\n title={status.detail}\n >\n {status.detail}\n </span>\n </span>\n </TableCell>\n <TableCell className=\"fk:hidden fk:whitespace-nowrap fk:text-muted-foreground fk:md:table-cell\">\n {getKnowledgeKindLabel(source)}\n </TableCell>\n <TableCell className=\"fk:hidden fk:whitespace-nowrap fk:text-right fk:tabular-nums fk:text-muted-foreground fk:md:table-cell\">\n {source.size === null ? '—' : formatFileSize(source.size)}\n </TableCell>\n <TableCell className=\"fk:hidden fk:whitespace-nowrap fk:text-muted-foreground fk:sm:table-cell\">\n <Tooltip>\n <TooltipTrigger asChild>\n <span>{formatAdded(source.createdAt)}</span>\n </TooltipTrigger>\n <TooltipContent>\n Updated {formatDistance(new Date(source.updatedAt), new Date(), { addSuffix: true })}\n </TooltipContent>\n </Tooltip>\n </TableCell>\n <TableCell className=\"fk:w-12 fk:pr-2 fk:text-right\">\n <SourceActionsMenu\n source={source}\n onOpen={() => actions.onOpen(source)}\n onRemoved={() => actions.onRemoved(source)}\n />\n </TableCell>\n </TableRow>\n );\n}\n\nfunction SourceTable({ sources, ...actions }: SourceActions & { sources: KnowledgeSource[] }): JSX.Element {\n return (\n <Table data-knowledge-list>\n <TableHeader>\n <TableRow className=\"fk:hover:bg-transparent\">\n <TableHead>Name</TableHead>\n <TableHead>Status</TableHead>\n <TableHead className=\"fk:hidden fk:md:table-cell\">Type</TableHead>\n <TableHead className=\"fk:hidden fk:text-right fk:md:table-cell\">Size</TableHead>\n <TableHead className=\"fk:hidden fk:sm:table-cell\">Added</TableHead>\n <TableHead className=\"fk:w-12\">\n <span className=\"fk:sr-only\">Actions</span>\n </TableHead>\n </TableRow>\n </TableHeader>\n <TableBody>\n {sources.map((source) => (\n <SourceListRow key={source.id} source={source} {...actions} />\n ))}\n </TableBody>\n </Table>\n );\n}\n\n/**\n * The card's thumbnail: the opening text of the document laid out like a\n * small page, the way a file manager shows the first page. Documents still\n * indexing, or without text, show their type mark instead.\n */\nfunction SourcePreview({ source }: { source: KnowledgeSource }): JSX.Element {\n const preview = source.preview?.trim();\n\n return (\n <div className=\"fk:relative fk:aspect-[4/3] fk:overflow-hidden fk:rounded-lg fk:bg-muted fk:corner-squircle\">\n {preview ? (\n <div\n aria-hidden\n className=\"fk:absolute fk:inset-x-4 fk:top-3 fk:bottom-0 fk:overflow-hidden fk:rounded-t-sm fk:bg-background fk:px-3 fk:pt-3 fk:shadow-sm\"\n >\n <p className=\"fk:whitespace-pre-line fk:text-[9px] fk:leading-[1.45] fk:text-foreground/80 fk:select-none\">\n {preview}\n </p>\n <span className=\"fk:pointer-events-none fk:absolute fk:inset-x-0 fk:bottom-0 fk:h-10 fk:bg-gradient-to-t fk:from-background fk:to-transparent\" />\n </div>\n ) : (\n <div className=\"fk:flex fk:h-full fk:items-center fk:justify-center\">\n <KnowledgeTypeIcon size={56} source={source} />\n </div>\n )}\n </div>\n );\n}\n\nfunction SourceCard({ source, ...actions }: SourceItemProps): JSX.Element {\n const status = summarizeKnowledgeStatus(source);\n const meta = [getKnowledgeKindLabel(source)];\n\n if (source.size !== null) {\n meta.push(formatFileSize(source.size));\n }\n\n meta.push(status.detail);\n\n // A link laid over the card opens the document (so it can be opened in a\n // new tab too); the menu button sits above it. The title tooltip lives on\n // the card itself, which does receive the pointer.\n return (\n <div\n className=\"fk:relative fk:flex fk:min-w-0 fk:flex-col fk:gap-3 fk:rounded-xl fk:border fk:bg-card fk:p-3 fk:transition-colors fk:hover:bg-accent/60 fk:has-[>a:focus-visible]:ring-2 fk:has-[>a:focus-visible]:ring-ring fk:corner-squircle\"\n data-knowledge-card\n title={source.title}\n >\n <Link\n aria-label={`Open ${source.title}`}\n className=\"fk:absolute fk:inset-0 fk:rounded-xl fk:focus-visible:outline-none fk:corner-squircle\"\n to={source.id}\n />\n <span className=\"fk:pointer-events-none fk:relative fk:flex fk:min-w-0 fk:items-center fk:gap-2\">\n <KnowledgeTypeIcon source={source} />\n <span className=\"fk:min-w-0 fk:flex-1 fk:truncate fk:text-sm fk:font-medium\">{source.title}</span>\n <span className=\"fk:pointer-events-auto fk:-my-1 fk:-mr-1.5\">\n <SourceActionsMenu\n source={source}\n onOpen={() => actions.onOpen(source)}\n onRemoved={() => actions.onRemoved(source)}\n />\n </span>\n </span>\n <span className=\"fk:pointer-events-none fk:relative\">\n <SourcePreview source={source} />\n </span>\n <span className=\"fk:pointer-events-none fk:relative fk:flex fk:min-w-0 fk:items-center fk:gap-2\">\n <StatusBadge label={status.label} tone={status.tone} />\n <span className=\"fk:min-w-0 fk:flex-1 fk:truncate fk:text-xs fk:text-muted-foreground\">{meta.join(' · ')}</span>\n {source.matchedIn === 'content' ? <ContentMatchBadge /> : null}\n {!source.agentVisible ? <HiddenBadge /> : null}\n </span>\n </div>\n );\n}\n\nfunction SourceGrid({ sources, ...actions }: SourceActions & { sources: KnowledgeSource[] }): JSX.Element {\n return (\n <div className={GRID_CLASSES} data-knowledge-grid>\n {sources.map((source) => (\n <SourceCard key={source.id} source={source} {...actions} />\n ))}\n </div>\n );\n}\n\nfunction ListHeader(): JSX.Element {\n return (\n <div className=\"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2 fk:pr-4\">\n <Tooltip>\n <TooltipTrigger asChild>\n <SidebarTrigger className=\"fk:-ml-1 fk:h-4 fk:w-4\" />\n </TooltipTrigger>\n <TooltipContent>Toggle Sidebar</TooltipContent>\n </Tooltip>\n <Separator orientation=\"vertical\" className=\"fk:h-4\" />\n <h1 className=\"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight\">Knowledge</h1>\n </div>\n );\n}\n\nexport function List(): JSX.Element {\n const { api, projectId } = useProjectKnowledge();\n const navigate = useNavigate();\n const canMutate = useCanMutate();\n const isViewing = useIsViewing();\n const status = useKnowledgeStatusFilter();\n const [search, setSearch] = useState('');\n const query = useDebouncedValue(search.trim(), SEARCH_DEBOUNCE_MS);\n const [viewMode, setViewMode] = useState<KnowledgeViewMode>(() => getStoredKnowledgeViewMode());\n const [isUrlDialogOpen, setIsUrlDialogOpen] = useState(false);\n const fileInputRef = useRef<HTMLInputElement>(null);\n const searchInputRef = useRef<HTMLInputElement>(null);\n const [isBusy, setIsBusy] = useState(false);\n const getSourcesKey = (pageIndex: number, previousPage: KnowledgeSourcesList | null): string | null => {\n if (!projectId || (previousPage && !previousPage.hasMore)) {\n return null;\n }\n\n return knowledgePaths(projectId).sources({\n limit: KNOWLEDGE_PAGE_SIZE,\n offset: pageIndex * KNOWLEDGE_PAGE_SIZE,\n search: query || undefined,\n status,\n });\n };\n const {\n data: pages,\n isLoading,\n mutate,\n setSize,\n size,\n } = useSWRInfinite<KnowledgeSourcesList>(getSourcesKey, fetcher, {\n // Rows that are still indexing change on their own; poll while one is in flight and the tab is in front.\n refreshInterval: isViewing && isBusy ? LIST_POLL_INTERVAL_MS : 0,\n });\n const sources = useMemo(() => pages?.flatMap((page) => page.sources) ?? [], [pages]);\n const total = pages?.[0]?.count ?? 0;\n const hasMore = pages?.[pages.length - 1]?.hasMore ?? false;\n const isLoadingMore = pages !== undefined && size > pages.length;\n const isInitialLoading = isLoading && sources.length === 0;\n const { addFiles, pending } = useKnowledgeUploads(api, () => void mutate());\n const mutateRef = useRef(mutate);\n\n mutateRef.current = mutate;\n\n // Coming back from a document page must show what changed there. The\n // infinite hook keeps serving its cached pages otherwise, whatever the\n // mount options.\n useEffect(() => {\n void mutateRef.current();\n }, []);\n\n useEffect(() => {\n setIsBusy(sources.some((source) => isKnowledgeSourceBusy(source)));\n }, [sources]);\n\n // A new search starts from its first page.\n const setSizeRef = useRef(setSize);\n\n setSizeRef.current = setSize;\n\n useEffect(() => {\n void setSizeRef.current(1);\n }, [query]);\n\n if (!projectId || !api) {\n return <PageMessage>Select a project to manage its knowledge.</PageMessage>;\n }\n\n function handleFilesPicked(event: ChangeEvent<HTMLInputElement>): void {\n const files = Array.from(event.target.files ?? []);\n\n event.target.value = '';\n addFiles(files);\n }\n\n let emptyMessage = `No documents yet. Upload ${KNOWLEDGE_FORMATS_LABEL} files, or add a public web page, and the agent will search and cite them.`;\n\n if (query) {\n emptyMessage = 'No document title or content matches your search.';\n } else if (status) {\n emptyMessage = EMPTY_BY_FILTER[status];\n }\n\n const actions: SourceActions = {\n onOpen: (source) => void navigate(source.id),\n // Drop the row at once, then let this hook refetch its pages: the global\n // list invalidation clears other caches but never revalidates an infinite hook.\n onRemoved: (removed) =>\n void mutate(\n (current) =>\n current?.map((page) => ({\n ...page,\n count: Math.max(0, page.count - 1),\n sources: page.sources.filter((entry) => entry.id !== removed.id),\n })),\n { revalidate: true }\n ),\n };\n let content: JSX.Element =\n viewMode === 'grid' ? (\n <SourceGrid sources={sources} {...actions} />\n ) : (\n <SourceTable sources={sources} {...actions} />\n );\n\n if (isInitialLoading) {\n content = <KnowledgeListSkeleton viewMode={viewMode} />;\n } else if (sources.length === 0) {\n content = (\n <Alert>\n <AlertDescription>{emptyMessage}</AlertDescription>\n </Alert>\n );\n }\n\n return (\n <main className=\"fk:flex fk:min-h-0 fk:flex-1 fk:flex-col\">\n <ListHeader />\n <AssetDropZone disabled={!canMutate} onDropFiles={addFiles}>\n <div className=\"fk:min-h-0 fk:flex-1 fk:overflow-auto\">\n <div className=\"fk:flex fk:w-full fk:flex-col fk:gap-5 fk:py-4 fk:pl-4 fk:pr-6\">\n <div>\n <h2 className=\"fk:text-2xl fk:font-semibold\">Documents</h2>\n <p className=\"fk:mt-1 fk:text-sm fk:text-muted-foreground\">\n Policies, manuals, specs and other reference material for your team and agents. The agent searches them\n when a question needs them and cites the passage it used.\n </p>\n </div>\n <div className=\"fk:flex fk:flex-wrap fk:items-center fk:gap-3\">\n <div className=\"fk:relative fk:w-full fk:max-w-sm\">\n <SearchIcon className=\"fk:pointer-events-none fk:absolute fk:left-2.5 fk:top-1/2 fk:size-4 fk:-translate-y-1/2 fk:text-muted-foreground\" />\n <Input\n aria-label=\"Search documents\"\n className=\"fk:pl-8 fk:pr-9\"\n placeholder=\"Search by title or content…\"\n ref={searchInputRef}\n value={search}\n onChange={(event) => setSearch(event.target.value)}\n />\n {search ? (\n <Button\n aria-label=\"Clear search\"\n className=\"fk:absolute fk:right-1.5 fk:top-1/2 fk:flex fk:size-6 fk:-translate-y-1/2 fk:items-center fk:justify-center fk:rounded-full fk:bg-transparent fk:text-muted-foreground fk:hover:bg-foreground/10 fk:hover:text-foreground fk:corner-squircle\"\n data-knowledge-clear-search\n type=\"button\"\n onClick={() => {\n setSearch('');\n searchInputRef.current?.focus();\n }}\n >\n <XIcon className=\"fk:size-4\" />\n </Button>\n ) : null}\n </div>\n {total > 0 ? (\n <span className=\"fk:text-sm fk:text-muted-foreground\">\n {total.toLocaleString()} {total === 1 ? 'document' : 'documents'}\n </span>\n ) : null}\n <div className=\"fk:ml-auto fk:flex fk:items-center fk:gap-2\">\n <ToggleGroup\n aria-label=\"Layout\"\n size=\"sm\"\n type=\"single\"\n value={viewMode}\n variant=\"outline\"\n onValueChange={(value) => {\n if (value === 'list' || value === 'grid') {\n setViewMode(value);\n setStoredKnowledgeViewMode(value);\n }\n }}\n >\n <ToggleGroupItem aria-label=\"List layout\" value=\"list\">\n <ListIcon className=\"fk:size-4\" />\n </ToggleGroupItem>\n <ToggleGroupItem aria-label=\"Grid layout\" value=\"grid\">\n <LayoutGridIcon className=\"fk:size-4\" />\n </ToggleGroupItem>\n </ToggleGroup>\n <PermissionTooltip disabled={!canMutate}>\n <Button disabled={!canMutate} size=\"sm\" variant=\"outline\" onClick={() => setIsUrlDialogOpen(true)}>\n <LinkIcon />\n Add web page\n </Button>\n </PermissionTooltip>\n <PermissionTooltip disabled={!canMutate}>\n <Button disabled={!canMutate} size=\"sm\" onClick={() => fileInputRef.current?.click()}>\n <UploadIcon />\n Upload documents\n </Button>\n </PermissionTooltip>\n <input\n accept={KNOWLEDGE_ACCEPT}\n className=\"fk:hidden\"\n multiple\n ref={fileInputRef}\n type=\"file\"\n onChange={handleFilesPicked}\n />\n </div>\n </div>\n {pending.length > 0 ? (\n <div className=\"fk:flex fk:flex-col fk:gap-1 fk:text-sm fk:text-muted-foreground\">\n {pending.map((upload) => (\n <span className=\"fk:flex fk:items-center fk:gap-2\" key={upload.id}>\n <LoaderCircle className=\"fk:size-4 fk:animate-spin\" />\n Uploading {upload.name}…\n </span>\n ))}\n </div>\n ) : null}\n {content}\n {hasMore && !isLoadingMore ? (\n <InfiniteScrollSentinel onVisible={() => void setSize((current) => current + 1)} />\n ) : null}\n {isLoadingMore ? (\n <div className=\"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground\">\n <LoaderCircle className=\"fk:size-4 fk:animate-spin\" />\n <span>Loading more documents...</span>\n </div>\n ) : null}\n </div>\n </div>\n </AssetDropZone>\n <AddUrlDialog\n api={api}\n open={isUrlDialogOpen}\n onOpenChange={setIsUrlDialogOpen}\n onRegistered={() => void mutate()}\n />\n </main>\n );\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import'./index.css';import {c as c$2,a as a$1}from'./chunk-VMWUMFUL.js';import {m as m$2,a,b,d as d$1}from'./chunk-XNHSHVG2.js';import'./chunk-CAZ6EUR2.js';import'./chunk-2DXR5NJV.js';import {u,m as m$1,d,w}from'./chunk-OOYCTZ3C.js';import'./chunk-ZZRA4567.js';import'./chunk-BMO7JFAX.js';import {c}from'./chunk-XMOSCJOI.js';import'./chunk-A7XHA2P6.js';import'./chunk-YDVO6XWD.js';import'./chunk-ERDARDGB.js';import {f}from'./chunk-H2RWSC56.js';import'./chunk-2HYQVMP3.js';import'./chunk-5CVDMZUI.js';import {O}from'./chunk-DGIY4SKN.js';import {t}from'./chunk-SZEGGBOC.js';import {v}from'./chunk-32ZU4MLE.js';import'./chunk-U45E5X3H.js';import'./chunk-HDOIOXMP.js';import {b as b$1,c as c$1,e}from'./chunk-USNXQOMJ.js';import'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {useState,useMemo,useCallback}from'react';import {useParams,useLocation,Outlet}from'react-router-dom';import {jsx,jsxs}from'react/jsx-runtime';var m=36,ct=[{_updatedAt:"DESC"},{_id:"DESC"}];function vt(){let{entity:t}=useParams(),{search:a$1}=useLocation(),g=new URLSearchParams(a$1).get("id"),{scope:j}=c(),{schemaErrorMessage:G}=u(),{currentProject:Q}=f(),h=Q?.schema??[],n=m$1(h,t??""),[r,S]=useState([]),[W,B]=useState(0),[O$1,F]=useState(t);t!==O$1&&(F(t),S([]));let k=m$2({attributesSchema:n?.attributes??[],actionsComponent:o=>ut({entityName:n?.name??"",entityNamePlural:t??"",row:o}),checkboxSelect:"multiple",enableColumnSorting:true}),f$1=useMemo(()=>{if(r.length===0)return ct;let o=r.map(({id:u,desc:it})=>({[u]:it?"DESC":"ASC"}));return o.some(u=>"_id"in u)?o:[...o,{_id:"DESC"}]},[r]),y=useMemo(()=>{if(r.length!==0)return d(f$1,n)},[n,f$1,r.length]),H=g?{where:{_id:{eq:g}}}:{offset:0,limit:m,sort:f$1,...y?{where:y}:{}},{isLoading:Y,isLoadingMore:Z,fetchMore:b$2,reload:C,count:i,data:l,isProjectDisabled:$}=w({entityNamePlural:t??"",schema:h,scope:j,variables:H,selection:"list"});function tt(o){S(o);}let N=l?.length??0,et=i>0&&N>0&&N<i,ot=useCallback(()=>{b$2({variables:{offset:0,limit:m}});},[b$2]),nt=useCallback(()=>{B(o=>o+1),C();},[C]),rt=Array(m).fill({}),at=pt(k),s=Y&&(l==null||l.length===0);return $?jsx("div",{className:"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3",children:jsx(a,{})}):jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3",children:[jsx(b,{}),jsxs("div",{className:"fk:flex fk:items-center fk:mb-4 fk:gap-2",children:[jsxs(b$1,{children:[jsx(c$1,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:w-4 fk:h-4"})}),jsx(e,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:h-4"}),jsx("h2",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:ft(n?.menu?.label??n?.plural??"")}),s?null:jsxs("span",{className:"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground",children:[i.toLocaleString()," ",i===1?"record":"records"]})]}),G?null:jsx(d$1,{columns:s?at:k,data:s?rt:l??[],entityName:n?.name??"",hasMore:et,isLoadingMore:Z,pageSize:m,scrollToTopKey:W,sorting:r,onLoadMore:ot,onSortingChange:tt,toolbarComponent:o=>jsx(c$2,{entityName:n?.name??"",isReloading:s,onReload:nt,table:o})}),jsx(Outlet,{})]})}function ft(t){return t.charAt(0).toUpperCase()+t.slice(1)}function ut({entityName:t,entityNamePlural:a,row:d}){return jsx(a$1,{entityName:t,entityNamePlural:a,row:d})}function pt(t$1){return t$1.map(a=>({...a,cell:()=>jsx(t,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}export{vt as List};//# sourceMappingURL=list-Z2C74QDN.js.map
|
|
2
|
+
//# sourceMappingURL=list-Z2C74QDN.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/apps/desk/list.tsx"],"names":["pageSize","defaultSort","List","entityName","useParams","search","useLocation","entityId","scope","useAppContext","schemaErrorMessage","useGraphQLError","currentProject","useConfig","schema","entitySchema","getEntitySchema","sorting","setSorting","useState","scrollToTopKey","setScrollToTopKey","sortedEntityName","setSortedEntityName","columnsDefinition","useGridColumnsDefinition","row","dataRowActions","graphqlSort","useMemo","primarySort","id","desc","entry","sortNotNullWhere","getSortNotNullWhere","variables","isLoading","isLoadingMore","fetchMore","reload","count","data","isProjectDisabled","useEntityQuery","handleSortingChange","updater","rowsCount","hasMore","handleLoadMore","useCallback","handleReload","key","loadingData","loadingColumns","getLoadingColumns","isInitialLoading","jsx","ProjectDisabled","jsxs","SchemaError","Tooltip","TooltipTrigger","SidebarTrigger","TooltipContent","Separator","capitalize","DataTable","table","DataTableToolbar","Outlet","str","entityNamePlural","DataTableRowActions","columns","column","Skeleton"],"mappings":"svBAiBA,IAAMA,EAAW,EAAA,CACXC,EAAAA,CAAc,CAAC,CAAE,UAAA,CAAY,MAAO,CAAA,CAAG,CAAE,IAAK,MAAO,CAAC,CAAA,CAErD,SAASC,EAAAA,EAAoB,CAClC,GAAM,CAAE,OAAQC,CAAW,CAAA,CAAIC,SAAAA,EAAU,CACnC,CAAE,MAAA,CAAAC,CAAO,CAAA,CAAIC,aAAY,CAEzBC,CAAAA,CADQ,IAAI,eAAA,CAAgBF,CAAM,CAAA,CACjB,GAAA,CAAI,IAAI,EACzB,CAAE,KAAA,CAAAG,CAAM,CAAA,CAAIC,CAAAA,EAAc,CAC1B,CAAE,kBAAA,CAAAC,CAAmB,CAAA,CAAIC,CAAAA,EAAgB,CACzC,CAAE,cAAA,CAAAC,CAAe,CAAA,CAAIC,CAAAA,EAAU,CAC/BC,CAAAA,CAASF,CAAAA,EAAgB,MAAA,EAAU,EAAC,CACpCG,CAAAA,CAAeC,GAAAA,CAAgBF,EAAQX,CAAAA,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CAAkBmB,GAAAA,CAAqF,CAC9G,OAAOA,GAAAA,CAAQ,GAAA,CAAKC,CAAAA,GAAY,CAC9B,GAAGA,CAAAA,CACH,IAAA,CAAM,IAAMlB,GAAAA,CAACmB,CAAAA,CAAA,CAAS,SAAA,CAAU,mBAAmB,KAAA,CAAO,CAAE,SAAA,CAAW,KAAA,CAAO,YAAA,CAAc,KAAM,CAAA,CAAG,CACvG,EAAE,CACJ","file":"list-EXNTXASK.js","sourcesContent":["import { JSX, useCallback, useMemo, useState } from 'react';\nimport { useLocation, useParams, Outlet } from 'react-router-dom';\nimport type { ColumnDef, Row, SortingState, Updater } from '@tanstack/react-table';\nimport { getEntitySchema, getSortNotNullWhere } from '../../graphql-client/queries';\nimport { useAppContext } from '../../core/app-context';\nimport { useConfig } from '../../core/config/config-context';\nimport { useEntityQuery } from '../../graphql-client/use-entity-query';\nimport { useGraphQLError } from '../../graphql-client/graphql-context';\nimport { ProjectDisabled } from '../../core/error/project-disabled';\nimport { SchemaError } from '../../core/error/schema-error';\nimport { DataTable } from '../../data-grid/data-table';\nimport { DataTableRowActions } from '../../data-grid/data-table-row-actions';\nimport { DataTableToolbar } from '../../data-grid/data-table-toolbar';\nimport { useGridColumnsDefinition } from '../../data-grid/columns';\nimport type { AttributeValue } from '../../graphql-client/types';\nimport { Skeleton, SidebarTrigger, Separator, Tooltip, TooltipContent, TooltipTrigger } from '../../ui';\n\nconst pageSize = 36;\nconst defaultSort = [{ _updatedAt: 'DESC' }, { _id: 'DESC' }];\n\nexport function List(): JSX.Element {\n const { entity: entityName } = useParams();\n const { search } = useLocation();\n const query = new URLSearchParams(search);\n const entityId = query.get('id');\n const { scope } = useAppContext();\n const { schemaErrorMessage } = useGraphQLError();\n const { currentProject } = useConfig();\n const schema = currentProject?.schema ?? [];\n const entitySchema = getEntitySchema(schema, entityName ?? '');\n const [sorting, setSorting] = useState<SortingState>([]);\n const [scrollToTopKey, setScrollToTopKey] = useState(0);\n const [sortedEntityName, setSortedEntityName] = useState(entityName);\n\n if (entityName !== sortedEntityName) {\n setSortedEntityName(entityName);\n setSorting([]);\n }\n\n const columnsDefinition = useGridColumnsDefinition<AttributeValue, unknown>({\n attributesSchema: entitySchema?.attributes ?? [],\n actionsComponent: (row) =>\n dataRowActions({ entityName: entitySchema?.name ?? '', entityNamePlural: entityName ?? '', row }),\n checkboxSelect: 'multiple',\n enableColumnSorting: true,\n });\n\n const graphqlSort = useMemo(() => {\n if (sorting.length === 0) {\n return defaultSort;\n }\n\n const primarySort = sorting.map(({ id, desc }) => ({ [id]: desc ? 'DESC' : 'ASC' }));\n const hasIdSort = primarySort.some((entry) => '_id' in entry);\n\n if (hasIdSort) {\n return primarySort;\n }\n\n // Tie-break so offset pages stay stable when sort values collide.\n return [...primarySort, { _id: 'DESC' }];\n }, [sorting]);\n const sortNotNullWhere = useMemo(() => {\n if (sorting.length === 0) {\n return undefined;\n }\n\n return getSortNotNullWhere(graphqlSort, entitySchema);\n }, [entitySchema, graphqlSort, sorting.length]);\n\n const variables = entityId\n ? { where: { _id: { eq: entityId } } }\n : {\n offset: 0,\n limit: pageSize,\n sort: graphqlSort,\n ...(sortNotNullWhere ? { where: sortNotNullWhere } : {}),\n };\n\n const { isLoading, isLoadingMore, fetchMore, reload, count, data, isProjectDisabled } = useEntityQuery({\n entityNamePlural: entityName ?? '',\n schema,\n scope,\n variables,\n selection: 'list',\n });\n\n function handleSortingChange(updater: Updater<SortingState>): void {\n setSorting(updater);\n }\n\n const rowsCount = data?.length ?? 0;\n const hasMore = count > 0 && rowsCount > 0 && rowsCount < count;\n\n const handleLoadMore = useCallback(() => {\n fetchMore({\n variables: {\n // Offset is tracked inside useEntityQuery from page windows; value here is ignored.\n offset: 0,\n limit: pageSize,\n },\n });\n }, [fetchMore]);\n\n const handleReload = useCallback(() => {\n setScrollToTopKey((key) => key + 1);\n reload();\n }, [reload]);\n\n const loadingData = Array(pageSize).fill({});\n const loadingColumns = getLoadingColumns(columnsDefinition);\n const isInitialLoading = isLoading && (data == null || data.length === 0);\n\n if (isProjectDisabled) {\n return (\n <div className=\"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3\">\n <ProjectDisabled />\n </div>\n );\n }\n\n return (\n <div className=\"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3\">\n <SchemaError />\n <div className=\"fk:flex fk:items-center fk:mb-4 fk:gap-2\">\n <Tooltip>\n <TooltipTrigger asChild>\n <SidebarTrigger className=\"fk:-ml-1 fk:w-4 fk:h-4\" />\n </TooltipTrigger>\n <TooltipContent>Toggle Sidebar</TooltipContent>\n </Tooltip>\n <Separator orientation=\"vertical\" className=\"fk:h-4\" />\n <h2 className=\"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight\">\n {capitalize(entitySchema?.menu?.label ?? entitySchema?.plural ?? '')}\n </h2>\n {!isInitialLoading ? (\n <span className=\"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground\">\n {count.toLocaleString()} {count === 1 ? 'record' : 'records'}\n </span>\n ) : null}\n </div>\n {!schemaErrorMessage ? (\n <DataTable\n columns={isInitialLoading ? loadingColumns : columnsDefinition}\n data={isInitialLoading ? loadingData : (data ?? [])}\n entityName={entitySchema?.name ?? ''}\n hasMore={hasMore}\n isLoadingMore={isLoadingMore}\n pageSize={pageSize}\n scrollToTopKey={scrollToTopKey}\n sorting={sorting}\n onLoadMore={handleLoadMore}\n onSortingChange={handleSortingChange}\n toolbarComponent={(table) => (\n <DataTableToolbar\n entityName={entitySchema?.name ?? ''}\n isReloading={isInitialLoading}\n onReload={handleReload}\n table={table}\n />\n )}\n />\n ) : null}\n <Outlet />\n </div>\n );\n}\n\nfunction capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\ntype DataRowActions = {\n entityName: string;\n entityNamePlural: string;\n row: Row<AttributeValue>;\n};\n\nfunction dataRowActions({ entityName, entityNamePlural, row }: DataRowActions): JSX.Element {\n return <DataTableRowActions entityName={entityName} entityNamePlural={entityNamePlural} row={row} />;\n}\n\nfunction getLoadingColumns(columns: ColumnDef<AttributeValue, unknown>[]): ColumnDef<AttributeValue, unknown>[] {\n return columns.map((column) => ({\n ...column,\n cell: () => <Skeleton className=\"fk:h-4 fk:w-full\" style={{ marginTop: '7px', marginBottom: '6px' }} />,\n }));\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/apps/desk/list.tsx"],"names":["pageSize","defaultSort","List","entityName","useParams","search","useLocation","entityId","scope","useAppContext","schemaErrorMessage","useGraphQLError","currentProject","useConfig","schema","entitySchema","getEntitySchema","sorting","setSorting","useState","scrollToTopKey","setScrollToTopKey","sortedEntityName","setSortedEntityName","columnsDefinition","useGridColumnsDefinition","row","dataRowActions","graphqlSort","useMemo","primarySort","id","desc","entry","sortNotNullWhere","getSortNotNullWhere","variables","isLoading","isLoadingMore","fetchMore","reload","count","data","isProjectDisabled","useEntityQuery","handleSortingChange","updater","rowsCount","hasMore","handleLoadMore","useCallback","handleReload","key","loadingData","loadingColumns","getLoadingColumns","isInitialLoading","jsx","ProjectDisabled","jsxs","SchemaError","Tooltip","TooltipTrigger","SidebarTrigger","TooltipContent","Separator","capitalize","DataTable","table","DataTableToolbar","Outlet","str","entityNamePlural","DataTableRowActions","columns","column","Skeleton"],"mappings":"65BAiBA,IAAMA,EAAW,EAAA,CACXC,EAAAA,CAAc,CAAC,CAAE,UAAA,CAAY,MAAO,CAAA,CAAG,CAAE,IAAK,MAAO,CAAC,CAAA,CAErD,SAASC,EAAAA,EAAoB,CAClC,GAAM,CAAE,OAAQC,CAAW,CAAA,CAAIC,SAAAA,EAAU,CACnC,CAAE,MAAA,CAAAC,GAAO,CAAA,CAAIC,aAAY,CAEzBC,CAAAA,CADQ,IAAI,eAAA,CAAgBF,GAAM,CAAA,CACjB,GAAA,CAAI,IAAI,EACzB,CAAE,KAAA,CAAAG,CAAM,CAAA,CAAIC,CAAAA,EAAc,CAC1B,CAAE,kBAAA,CAAAC,CAAmB,CAAA,CAAIC,CAAAA,EAAg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,CAAgC,CAC1F,OAAO+B,GAAAA,CAACgB,IAAA,CAAoB,UAAA,CAAYtE,CAAAA,CAAY,gBAAA,CAAkBqE,CAAAA,CAAkB,GAAA,CAAK9C,CAAAA,CAAK,CACpG,CAEA,SAAS6B,EAAAA,CAAkBmB,GAAAA,CAAqF,CAC9G,OAAOA,GAAAA,CAAQ,GAAA,CAAKC,CAAAA,GAAY,CAC9B,GAAGA,CAAAA,CACH,IAAA,CAAM,IAAMlB,GAAAA,CAACmB,CAAAA,CAAA,CAAS,SAAA,CAAU,mBAAmB,KAAA,CAAO,CAAE,SAAA,CAAW,KAAA,CAAO,YAAA,CAAc,KAAM,CAAA,CAAG,CACvG,EAAE,CACJ","file":"list-Z2C74QDN.js","sourcesContent":["import { JSX, useCallback, useMemo, useState } from 'react';\nimport { useLocation, useParams, Outlet } from 'react-router-dom';\nimport type { ColumnDef, Row, SortingState, Updater } from '@tanstack/react-table';\nimport { getEntitySchema, getSortNotNullWhere } from '../../graphql-client/queries';\nimport { useAppContext } from '../../core/app-context';\nimport { useConfig } from '../../core/config/config-context';\nimport { useEntityQuery } from '../../graphql-client/use-entity-query';\nimport { useGraphQLError } from '../../graphql-client/graphql-context';\nimport { ProjectDisabled } from '../../core/error/project-disabled';\nimport { SchemaError } from '../../core/error/schema-error';\nimport { DataTable } from '../../data-grid/data-table';\nimport { DataTableRowActions } from '../../data-grid/data-table-row-actions';\nimport { DataTableToolbar } from '../../data-grid/data-table-toolbar';\nimport { useGridColumnsDefinition } from '../../data-grid/columns';\nimport type { AttributeValue } from '../../graphql-client/types';\nimport { Skeleton, SidebarTrigger, Separator, Tooltip, TooltipContent, TooltipTrigger } from '../../ui';\n\nconst pageSize = 36;\nconst defaultSort = [{ _updatedAt: 'DESC' }, { _id: 'DESC' }];\n\nexport function List(): JSX.Element {\n const { entity: entityName } = useParams();\n const { search } = useLocation();\n const query = new URLSearchParams(search);\n const entityId = query.get('id');\n const { scope } = useAppContext();\n const { schemaErrorMessage } = useGraphQLError();\n const { currentProject } = useConfig();\n const schema = currentProject?.schema ?? [];\n const entitySchema = getEntitySchema(schema, entityName ?? '');\n const [sorting, setSorting] = useState<SortingState>([]);\n const [scrollToTopKey, setScrollToTopKey] = useState(0);\n const [sortedEntityName, setSortedEntityName] = useState(entityName);\n\n if (entityName !== sortedEntityName) {\n setSortedEntityName(entityName);\n setSorting([]);\n }\n\n const columnsDefinition = useGridColumnsDefinition<AttributeValue, unknown>({\n attributesSchema: entitySchema?.attributes ?? [],\n actionsComponent: (row) =>\n dataRowActions({ entityName: entitySchema?.name ?? '', entityNamePlural: entityName ?? '', row }),\n checkboxSelect: 'multiple',\n enableColumnSorting: true,\n });\n\n const graphqlSort = useMemo(() => {\n if (sorting.length === 0) {\n return defaultSort;\n }\n\n const primarySort = sorting.map(({ id, desc }) => ({ [id]: desc ? 'DESC' : 'ASC' }));\n const hasIdSort = primarySort.some((entry) => '_id' in entry);\n\n if (hasIdSort) {\n return primarySort;\n }\n\n // Tie-break so offset pages stay stable when sort values collide.\n return [...primarySort, { _id: 'DESC' }];\n }, [sorting]);\n const sortNotNullWhere = useMemo(() => {\n if (sorting.length === 0) {\n return undefined;\n }\n\n return getSortNotNullWhere(graphqlSort, entitySchema);\n }, [entitySchema, graphqlSort, sorting.length]);\n\n const variables = entityId\n ? { where: { _id: { eq: entityId } } }\n : {\n offset: 0,\n limit: pageSize,\n sort: graphqlSort,\n ...(sortNotNullWhere ? { where: sortNotNullWhere } : {}),\n };\n\n const { isLoading, isLoadingMore, fetchMore, reload, count, data, isProjectDisabled } = useEntityQuery({\n entityNamePlural: entityName ?? '',\n schema,\n scope,\n variables,\n selection: 'list',\n });\n\n function handleSortingChange(updater: Updater<SortingState>): void {\n setSorting(updater);\n }\n\n const rowsCount = data?.length ?? 0;\n const hasMore = count > 0 && rowsCount > 0 && rowsCount < count;\n\n const handleLoadMore = useCallback(() => {\n fetchMore({\n variables: {\n // Offset is tracked inside useEntityQuery from page windows; value here is ignored.\n offset: 0,\n limit: pageSize,\n },\n });\n }, [fetchMore]);\n\n const handleReload = useCallback(() => {\n setScrollToTopKey((key) => key + 1);\n reload();\n }, [reload]);\n\n const loadingData = Array(pageSize).fill({});\n const loadingColumns = getLoadingColumns(columnsDefinition);\n const isInitialLoading = isLoading && (data == null || data.length === 0);\n\n if (isProjectDisabled) {\n return (\n <div className=\"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3\">\n <ProjectDisabled />\n </div>\n );\n }\n\n return (\n <div className=\"fk:flex fk:flex-col fk:h-full fk:px-4 fk:pt-3\">\n <SchemaError />\n <div className=\"fk:flex fk:items-center fk:mb-4 fk:gap-2\">\n <Tooltip>\n <TooltipTrigger asChild>\n <SidebarTrigger className=\"fk:-ml-1 fk:w-4 fk:h-4\" />\n </TooltipTrigger>\n <TooltipContent>Toggle Sidebar</TooltipContent>\n </Tooltip>\n <Separator orientation=\"vertical\" className=\"fk:h-4\" />\n <h2 className=\"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight\">\n {capitalize(entitySchema?.menu?.label ?? entitySchema?.plural ?? '')}\n </h2>\n {!isInitialLoading ? (\n <span className=\"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground\">\n {count.toLocaleString()} {count === 1 ? 'record' : 'records'}\n </span>\n ) : null}\n </div>\n {!schemaErrorMessage ? (\n <DataTable\n columns={isInitialLoading ? loadingColumns : columnsDefinition}\n data={isInitialLoading ? loadingData : (data ?? [])}\n entityName={entitySchema?.name ?? ''}\n hasMore={hasMore}\n isLoadingMore={isLoadingMore}\n pageSize={pageSize}\n scrollToTopKey={scrollToTopKey}\n sorting={sorting}\n onLoadMore={handleLoadMore}\n onSortingChange={handleSortingChange}\n toolbarComponent={(table) => (\n <DataTableToolbar\n entityName={entitySchema?.name ?? ''}\n isReloading={isInitialLoading}\n onReload={handleReload}\n table={table}\n />\n )}\n />\n ) : null}\n <Outlet />\n </div>\n );\n}\n\nfunction capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\ntype DataRowActions = {\n entityName: string;\n entityNamePlural: string;\n row: Row<AttributeValue>;\n};\n\nfunction dataRowActions({ entityName, entityNamePlural, row }: DataRowActions): JSX.Element {\n return <DataTableRowActions entityName={entityName} entityNamePlural={entityNamePlural} row={row} />;\n}\n\nfunction getLoadingColumns(columns: ColumnDef<AttributeValue, unknown>[]): ColumnDef<AttributeValue, unknown>[] {\n return columns.map((column) => ({\n ...column,\n cell: () => <Skeleton className=\"fk:h-4 fk:w-full\" style={{ marginTop: '7px', marginBottom: '6px' }} />,\n }));\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import'./index.css';import {f as f$3,b as b$6,c as c$4,d as d$2,e as e$4,g as g$4}from'./chunk-CSUHZFEP.js';import {x,a,b as b$4,d,c as c$3,y,C,D,B,g as g$2,h as h$1,i,f as f$2,z,I,E,H,e as e$3,F}from'./chunk-6RRB47OZ.js';import {a as a$4}from'./chunk-HCJAM5LG.js';import {b as b$7}from'./chunk-UOR437J2.js';import {c as c$2,a as a$1,b as b$5,e as e$2,d as d$1,g as g$6,i as i$1,h as h$2}from'./chunk-D5WYD5M4.js';import {a as a$2}from'./chunk-54AXLGAK.js';import {f,g,e as e$7,c as c$6,d as d$4}from'./chunk-DHVKE36X.js';import'./chunk-4IEOAKKK.js';import'./chunk-2NXQF2F7.js';import {c as c$1}from'./chunk-CAZ6EUR2.js';import {b}from'./chunk-ZZRA4567.js';import'./chunk-A7XHA2P6.js';import {f as f$4}from'./chunk-H2RWSC56.js';import {g as g$3}from'./chunk-2HYQVMP3.js';import'./chunk-5CVDMZUI.js';import {$,aa as aa$1,da as da$1,ea as ea$1,ba as ba$1,fa,O,f as f$1,na as na$1,ha,ia,ja,ab,bb,db,qa as qa$1,s,e as e$5,_,la,t as t$1,u,v as v$1}from'./chunk-DGIY4SKN.js';import {e,g as g$1,h,j,o,t,q,r,s as s$1,k}from'./chunk-SZEGGBOC.js';import {b as b$1,v,w,x as x$1,m,o as o$1,p,q as q$1,r as r$1,t as t$2}from'./chunk-32ZU4MLE.js';import'./chunk-U45E5X3H.js';import {a as a$3,d as d$3,c as c$5,e as e$6,g as g$5}from'./chunk-HDOIOXMP.js';import {b as b$3,c,e as e$1}from'./chunk-USNXQOMJ.js';import {b as b$2}from'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {useState,useRef,useMemo,useCallback,useEffect,useTransition,Fragment as Fragment$1,useId}from'react';import {formatDistance,format}from'date-fns';import {Ellipsis,Pencil,Trash2,Plus,ArrowLeft,LoaderCircle,Play,XIcon,TriangleAlertIcon,ZapIcon,BotIcon,Search,X,CoinsIcon,BrainIcon,Trash2Icon,LoaderCircleIcon,GraduationCapIcon,WrenchIcon,Settings2Icon,BellIcon,ClockIcon,WebhookIcon,DatabaseZapIcon,CircleCheckBigIcon,RefreshCwIcon,PlusIcon,ChevronDownIcon,LockIcon,CheckIcon,ChevronsUpDownIcon,CopyIcon,KeyRoundIcon}from'lucide-react';import {useNavigate,Link,useParams}from'react-router-dom';import {useReactTable,getCoreRowModel}from'@tanstack/react-table';import De,{useSWRConfig}from'swr';import It from'swr/infinite';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {CronExpressionParser}from'cron-parser';var qa=[{kind:"approval_request",label:"Approval requests"},{kind:"automation_failure",label:"Automation failures"},{kind:"automation_result",label:"Automation results"},{kind:"monitor_event",label:"Chat monitors"},{kind:"question",label:"Agent questions"}];function Bo({checked:t,disabled:n,label:o,onCheckedChange:i}){let l=useId();return jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsx("label",{className:"fk:text-sm",htmlFor:l,children:o}),jsx(_,{checked:t,disabled:n,id:l,onCheckedChange:i})]})}function jo(){let{mode:t}=f$4(),{isLoaded:n,mutate:o,preferences:i}=g$6(),[l,k]=useState(false);async function f(c){k(true);try{await o(h$2(c),{optimisticData:{preferences:c},rollbackOnError:!0});}catch{qa$1.error("Unable to save your notification settings.");}finally{k(false);}}function g(c,p){let d=new Set(i.desktopMutedKinds);p?d.delete(c):d.add(c),f({...i,desktopMutedKinds:[...d]});}return jsxs(t$1,{children:[jsx(u,{asChild:true,children:jsx(b$2,{"aria-label":"Notification settings",className:"fk:ml-auto",size:"icon",variant:"ghost",children:jsx(Settings2Icon,{className:"fk:size-4"})})}),jsxs(v$1,{align:"end",className:"fk:w-80 fk:space-y-4",children:[jsxs("div",{className:"fk:space-y-2",children:[jsx("p",{className:"fk:text-sm fk:font-medium",children:"Desktop notifications"}),jsxs("p",{className:"fk:text-xs fk:text-muted-foreground",children:[t==="hosted"?"Shown while Studio is in the background, and while your browser runs with no Studio tab open.":"Shown while Studio is open in the background."," ","Activity always keeps every item."]}),qa.map(({kind:c,label:p})=>jsx(Bo,{checked:!i.desktopMutedKinds.includes(c),disabled:l||!n,label:p,onCheckedChange:d=>g(c,d)},c))]}),jsxs("div",{className:"fk:space-y-2",children:[jsx("p",{className:"fk:text-sm fk:font-medium",children:"Email"}),jsx(Bo,{checked:i.approvalEmail,disabled:l||!n,label:"Approval requests I haven\u2019t read",onCheckedChange:c=>{f({...i,approvalEmail:c});}})]}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"These settings apply to every project you open."})]})]})}var Wa=[{label:"Enabled",value:"enabled"},{label:"Disabled",value:"disabled"}],Ga=[{label:"Project",value:"project"},{label:"Space",value:"space"},{label:"Personal",value:"personal"}];function Za(t,n=300){let o,i=function(...l){o!==void 0&&clearTimeout(o),o=setTimeout(()=>{o=void 0,t.apply(this,l);},n);};return i.cancel=()=>{o!==void 0&&(clearTimeout(o),o=void 0);},i}function Oo({actions:t,isSearchLoading:n=false,onSearchChange:o,search:i,searchPlaceholder:l="Search automations...",table:k}){let f=k.getState().columnFilters.length>0||i.trim().length>0,g=k.getAllColumns().find(P=>P.id==="status"),c=k.getAllColumns().find(P=>P.id==="visibility"),[p,d]=useState(i),v=p.trim(),C=i.trim(),T=v.length>0&&(n||v!==C),j=useRef(o);j.current=o;let A=useMemo(()=>Za(P=>{j.current(P);},300),[]);useEffect(()=>{d(i);},[i]),useEffect(()=>()=>{A.cancel();},[A]);function x(){A.cancel(),d(""),o("");}function b(){k.resetColumnFilters(),x();}return jsx("div",{className:"fk:flex fk:w-full fk:min-w-0",children:jsxs(w,{className:"fk:w-0 fk:min-w-0 fk:flex-1 fk:whitespace-nowrap fk:-ml-0.75",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-3 fk:p-0.75 fk:pb-2.5",children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs("div",{className:"fk:relative",children:[T?jsx(LoaderCircle,{className:"fk:absolute fk:left-2 fk:top-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-2 fk:top-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(s,{className:"fk:h-8 fk:w-37.5 fk:lg:w-70 fk:px-7 fk:text-sm",name:"search-automations",placeholder:l,value:p,onChange:P=>{let{value:F}=P.target;if(d(F),F.trim().length===0){A.cancel(),o("");return}A(F.trim());}}),p?jsx(b$2,{"aria-label":"Clear search",className:"fk:absolute fk:right-1 fk:top-1 fk:h-6 fk:w-6 fk:text-muted-foreground fk:hover:text-foreground fk:hover:bg-foreground/10 fk:cursor-pointer fk:rounded-full fk:bg-transparent fk:corner-squircle",onClick:x,type:"button",children:jsx(X,{className:"fk:h-4 fk:w-4"})}):null]}),g?jsx(a$2,{column:g,options:Wa,title:"Status"}):null,c?jsx(a$2,{column:c,options:Ga,title:"Visibility"}):null,f?jsxs(b$2,{className:"fk:h-8 fk:px-2 fk:lg:px-3",onClick:b,variant:"ghost",children:["Reset",jsx(X,{className:"fk:ml-2 fk:h-4 fk:w-4"})]}):null]}),t?jsx("div",{className:"fk:ml-auto fk:flex fk:shrink-0 fk:items-center fk:gap-3",children:t}):null]}),jsx(x$1,{orientation:"horizontal"})]})})}function Sn(t,n,o){return (o??[]).some(i=>i.toLowerCase().includes(n.trim().toLowerCase()))?1:0}function Kt({disabled:t,emptyText:n,footer:o,items:i,searchPlaceholder:l,triggerLabel:k="Attach",onToggle:f}){let[g,c]=useState(false),p$1=useRef(null);return jsxs(t$1,{open:g,onOpenChange:c,children:[jsx(u,{asChild:true,children:jsxs(b$2,{disabled:t,size:"sm",type:"button",variant:"outline",children:[k,jsx(ChevronDownIcon,{className:"fk:ml-1 fk:size-4"})]})}),jsx(v$1,{align:"end",className:"fk:w-72 fk:p-0",onOpenAutoFocus:d=>{d.preventDefault(),p$1.current?.focus({preventScroll:true});},children:jsxs(m,{filter:Sn,children:[jsx(o$1,{placeholder:l,ref:p$1}),jsxs(p,{className:"fk:max-h-72",children:[jsx(q$1,{children:n}),jsx(r$1,{children:i.map(d=>jsxs(t$2,{disabled:!!d.lockedHint,title:d.lockedHint,value:d.id,keywords:[d.label],onSelect:()=>f(d.id,!d.attached),children:[d.lockedHint?jsx(LockIcon,{className:"fk:size-4"}):jsx(CheckIcon,{className:d.attached?"fk:size-4":"fk:size-4 fk:opacity-0"}),jsx("span",{className:"fk:truncate",children:d.label}),d.badge?jsx(b$1,{className:"fk:ml-auto fk:py-0 fk:text-[10px]",variant:"secondary",children:d.badge}):null]},d.id))})]}),o]})})]})}function Jo(t){return t==="project"?"Project":"Personal"}function Tt(t,n){return t.connections.filter(o=>o.scope===n&&o.status==="connected")}function In(t,n){if(!n)return null;let o=Tt(t,n.connectionMode);return n.connectionId?o.find(i=>i.id===n.connectionId)??null:o.find(i=>i.isPrimary)??null}function Nt(t){return t?t.connectionId?`account:${t.connectionId}`:`primary:${t.connectionMode}`:""}function Pn({ariaLabel:t,disabled:n,plugin:o,scopes:i,value:l,onChange:k}){let f=[];for(let c of i){let p=Tt(o,c),d=p.find(C=>C.isPrimary),[v]=p;if(p.length===1&&v){let C=l?.connectionMode===c&&l.connectionId===v.id;f.push({choice:{connectionMode:c,connectionId:C||!v.isPrimary?v.id:null},label:`${Jo(c)} \xB7 ${v.displayName}`});continue}d&&f.push({choice:{connectionMode:c,connectionId:null},label:`Primary ${c} account (${d.displayName})`});for(let C of p)f.push({choice:{connectionMode:c,connectionId:C.id},label:`${Jo(c)} \xB7 ${C.displayName}`});}let g=Nt(l);return jsxs(a$3,{disabled:n,value:f.some(c=>Nt(c.choice)===g)?g:"",onValueChange:c=>{let p=f.find(d=>Nt(d.choice)===c);p&&k(p.choice);},children:[jsx(d$3,{"aria-label":t,className:"fk:w-fit fk:max-w-full",size:"sm",children:jsx(c$5,{placeholder:"Select account"})}),jsx(e$6,{children:f.map(c=>jsx(g$5,{value:Nt(c.choice),children:c.label},Nt(c.choice)))})]})}var wn=2;function Xo(t){return t.scopes.filter(n=>n==="project"||t.allowPersonal)}function rs(t){let n=Xo(t),o=n.includes("personal")&&(!n.includes("project")||Tt(t,"project").length===0&&Tt(t,"personal").length>0);return {pluginId:t.id,enabled:true,connectionMode:o?"personal":"project",connectionId:null,allTools:true,selectedTools:[],deliveryEnabled:false,channels:[]}}function cs(t,n){return `${encodeURIComponent(t)}:${encodeURIComponent(n)}`}function fs(t){return decodeURIComponent(t.slice(t.indexOf(":")+1))}function us(t){let n=t.map(fs),o=n.slice(0,wn).join(", ");return n.length>wn?`${o} +${n.length-wn} more`:o}function ds({canManage:t,disabled:n,plugin:o$1,projectId:i,usage:l,onChange:k,onRemove:f$1}){let g=Xo(o$1),c=g.some(w=>Tt(o$1,w).length>0),p=g.includes(l.connectionMode)?{connectionMode:l.connectionMode,connectionId:l.connectionId}:null,d=In(o$1,p),{data:v$1,error:C}=De(d?`/api/flexkit/${i}/plugin-connections/${d.id}/tools`:null,f),T=(v$1?.servers??[]).flatMap(w=>w.tools.map(H=>({key:cs(w.name,H.name),entry:H}))),j$1=(v$1?.servers??[]).flatMap(w=>w.error?[w.error]:[]),A=l.allTools!==false,x=n||!o$1.enabled,b=w=>k({...l,allTools:false,selectedTools:w,enabled:w.length>0}),P=()=>k({...l,allTools:true,selectedTools:[],enabled:true}),F=w=>({...l,connectionMode:w.connectionMode,connectionId:w.connectionId,selectedTools:[],enabled:A}),{mutate:S}=useSWRConfig(),[_,M]=useState(false),B=async w=>{M(true);try{await b$7(d$4(i),o$1.id,w),await S(`/api/flexkit/${i}/plugins`),k(F({connectionMode:w,connectionId:null}));}catch(H){qa$1.error(H instanceof Error?H.message:`Unable to connect ${o$1.name}.`);}finally{M(false);}},U=null;return o$1.enabled?c?p?d?C||j$1.length?U={text:j$1[0]??"Unable to load tools. Reconnect or try again.",tone:"warning"}:A?U={text:"All tools",tone:"muted"}:l.selectedTools.length===0?U={text:"No tools selected, so the agent cannot use this plugin yet.",tone:"warning"}:U={text:us(l.selectedTools),tone:"muted"}:U={text:p.connectionId?"The selected account is no longer connected.":`The primary ${p.connectionMode} account needs reconnecting.`,tone:"warning"}:U={text:"Select an account.",tone:"warning"}:U={text:`Connect ${o$1.name} to use its tools.`,tone:"warning"}:U={text:"Disabled by project policy.",tone:"warning"},jsxs(Fragment,{children:[jsxs("div",{className:"fk:m-1.5 fk:flex fk:flex-wrap fk:items-center fk:justify-between fk:gap-x-3 fk:gap-y-2 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:min-w-0 fk:flex-1 fk:items-center fk:gap-2.5",children:[jsx("img",{src:o$1.logoUrl,alt:"",className:"fk:size-5 fk:shrink-0 fk:rounded fk:corner-squircle fk:self-start"}),jsxs("div",{className:"fk:min-w-0",children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:o$1.name}),jsx("p",{className:U.tone==="warning"?"fk:truncate fk:text-xs fk:text-warning":"fk:truncate fk:text-xs fk:text-muted-foreground",children:U.text}),l.connectionMode==="personal"&&l.enabled?jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Using your account makes this automation personal."}):null]})]}),jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-1.5",children:[c?jsxs(Fragment,{children:[jsx(Pn,{ariaLabel:`${o$1.name} account`,disabled:x,plugin:o$1,scopes:g,value:p,onChange:w=>{w.connectionMode===l.connectionMode&&w.connectionId===l.connectionId||k(F(w));}}),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(b$2,{disabled:x||!d||!v$1,size:"sm",type:"button",variant:"outline",children:[A?"All tools":l.selectedTools.length?`Tools (${l.selectedTools.length})`:"Select tools",jsx(ChevronDownIcon,{className:"fk:ml-1 fk:size-4"})]})}),jsxs(h,{align:"end",className:"fk:max-h-80 fk:w-80 fk:overflow-y-auto",children:[jsxs(j,{className:"fk:items-start",onSelect:w=>{w.preventDefault(),A?b(T.map(H=>H.key)):P();},children:[jsx(CheckIcon,{className:A?"fk:mt-0.5 fk:size-4":"fk:mt-0.5 fk:size-4 fk:opacity-0"}),jsxs("span",{className:"fk:min-w-0",children:[jsx("span",{className:"fk:block",children:"All tools (recommended)"}),jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Includes tools added later. Uncheck to pick specific ones."})]})]}),jsx(o,{}),T.map(({key:w,entry:H})=>{let $=A||l.selectedTools.includes(w);return jsxs(j,{className:"fk:items-start",onSelect:he=>{he.preventDefault();let q=A?T.map(be=>be.key):l.selectedTools;b($?q.filter(be=>be!==w):[...q,w]);},children:[jsx(CheckIcon,{className:$?"fk:mt-0.5 fk:size-4":"fk:mt-0.5 fk:size-4 fk:opacity-0"}),jsxs("span",{className:"fk:min-w-0",children:[jsx("span",{className:"fk:block",children:H.name}),H.description?jsx("span",{className:"fk:line-clamp-2 fk:text-xs fk:text-muted-foreground",children:H.description}):null]})]},w)}),v$1&&T.length===0?jsx(j,{disabled:true,children:"This account exposes no tools."}):null]})]})]}):jsx(a$4,{busy:_||n,canManage:t,plugin:o$1,onConnect:w=>{B(w);}}),jsx(b$2,{"aria-label":`Remove ${o$1.name} from automation`,disabled:n,size:"icon",type:"button",variant:"ghost",onClick:f$1,children:jsx(Trash2Icon,{className:"fk:size-4"})})]})]}),jsx(v,{})]})}function ms({disabled:t,plugins:n,onAdd:o}){let[i,l]=useState(false),k=useRef(null);return jsxs(t$1,{open:i,onOpenChange:l,children:[jsx(u,{asChild:true,children:jsxs("button",{className:"fk:m-1.5 fk:flex fk:w-[calc(100%-0.75rem)] fk:cursor-pointer fk:items-center fk:gap-2.5 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:text-left fk:text-sm fk:text-muted-foreground fk:hover:bg-muted fk:hover:text-foreground disabled:fk:cursor-not-allowed disabled:fk:opacity-50 fk:corner-squircle",disabled:t||n.length===0,type:"button",children:[jsx(PlusIcon,{className:"fk:size-5"}),"Plugin tools"]})}),jsx(v$1,{align:"start",className:"fk:w-72 fk:p-0",onOpenAutoFocus:f=>{f.preventDefault(),k.current?.focus({preventScroll:true});},children:jsxs(m,{filter:Sn,children:[jsx(o$1,{placeholder:"Search plugins\u2026",ref:k}),jsxs(p,{children:[jsx(q$1,{children:"No plugins found."}),jsx(r$1,{children:n.map(f=>jsxs(t$2,{value:f.id,keywords:[f.name],onSelect:()=>{o(f),l(false);},children:[jsx("img",{src:f.logoUrl,alt:"",className:"fk:size-5 fk:shrink-0 fk:rounded fk:corner-squircle"}),jsx("span",{className:"fk:truncate",children:f.name}),f.connections.some(g=>g.status==="connected")?null:jsx("span",{className:"fk:ml-auto fk:text-xs fk:text-muted-foreground",children:"Not connected"})]},f.id))})]})]})})]})}function Ko({projectId:t,value:n,disabled:o,onChange:i}){let{data:l,error:k}=De(`/api/flexkit/${t}/plugins`,f),f$1=(l?.plugins??[]).filter(p=>p.capabilities.agentTools),g=new Map(f$1.map(p=>[p.id,p])),c=f$1.filter(p=>p.enabled&&!n.some(d=>d.pluginId===p.id));return jsxs(Fragment,{children:[n.map(p=>{let d=g.get(p.pluginId);return d?jsx(ds,{disabled:o,canManage:l?.canManage??false,plugin:d,projectId:t,usage:p,onChange:v=>i(n.map(C=>C.pluginId===d.id?v:C)),onRemove:()=>i(n.filter(v=>v.pluginId!==d.id))},p.pluginId):null}),k?jsx("p",{className:"fk:mx-3 fk:text-xs fk:text-warning",role:"alert",children:"Unable to load plugins. Your existing selections are preserved."}):null,jsx(ms,{disabled:o||!l,plugins:c,onAdd:p=>i([...n,rs(p)])})]})}var Wt=["slack","teams"],ea=["create","update","delete"],da="0 * * * *",Ts="0 9 * * *",Cs="0 9 * * 1",Ss="0 9 1 * *",ws=[{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}],As=Array.from({length:24},(t,n)=>({label:`${n.toString().padStart(2,"0")}:00`,value:n})),ta={automation_run:"a run of",bulk_action:"a bulk action of",schema_deploy:"a schema deployment"},na={any:"finishes",failed:"fails",succeeded:"succeeds"},Is=[{label:"=",value:"eq"},{label:"\u2260",value:"neq"},{label:">",value:"gt"},{label:"\u2265",value:"gte"},{label:"<",value:"lt"},{label:"\u2264",value:"lte"},{label:"contains",value:"contains"},{label:"exists",value:"exists"}],Ln=5,Dn=1440,Ps=15,Mn="__any__";function Ms(t){return !t.instructions&&!t.model&&!t.name&&!t.plugins&&!t.space&&Object.keys(t.toolErrors).length===0&&Object.keys(t.triggerErrors).length===0}function oa(t){return t.some(n=>n.enabled&&n.connectionMode==="personal")}function Xe({id:t,message:n}){return n?jsxs("p",{className:"fk:flex fk:items-start fk:text-sm fk:text-warning fk:gap-1",id:t,role:"alert",children:[jsx(TriangleAlertIcon,{className:"fk:size-4 fk:shrink-0 fk:mt-0.5"}),n]}):null}function ft(){return crypto.randomUUID()}function Rs(t){return (t?.triggers??[]).map(n=>({...n,key:n.id??ft()}))}function Es(t){return t.connected&&t.connectionLabel?`While your local runtime (${t.connectionLabel}) is connected, manually running this automation uses its custom tools so you can test them.`:t.connected?"While `flexkit dev` is connected, manually running this automation uses the custom tools from your local runtime so you can test them.":t.origin?`Using ${t.origin}`:t.tools.length===0?"":"Registered in this project"}function Ls(){return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}function Ds(){let t=crypto.getRandomValues(new Uint8Array(24));return Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}function zs(t){if(t===da)return {kind:"hourly"};let n=/^0 (\d{1,2}) \* \* \*$/.exec(t);if(n)return {hour:Number(n[1]),kind:"daily"};let o=/^0 (\d{1,2}) \* \* ([0-6])$/.exec(t);return o?{day:Number(o[2]),hour:Number(o[1]),kind:"weekly"}:{kind:"custom"}}function ma(t,n,o){try{let i=CronExpressionParser.parse(t,{tz:n});return Array.from({length:o},()=>i.next().toDate())}catch{return []}}function ka(t,n){return new Intl.DateTimeFormat("en-US",{day:"numeric",hour:"numeric",minute:"2-digit",month:"short",timeZone:n,weekday:"short"}).format(t)}function pa(t,n){let o=t.trim();if(!o)return "Cron expression is required";let i=o.split(/\s+/).length;if(i<5||i>6)return `Expected 5 fields (min hour day month weekday), got ${i.toString()}`;try{return CronExpressionParser.parse(o,{tz:n}),null}catch{return "Invalid cron expression"}}function Fs(t,n,o){let i=t.filter(k=>!k.deprecated);if(n!=="edit"||!o)return i;let l=c$4(t,o);return l?.deprecated?[l,...i.filter(k=>b$6(k)!==o)]:l?i:[{deprecated:true,effort:null,efforts:[],id:o,kind:"model",name:o},...i]}function zn(t){return `${t.teamId??""}:${t.id}`}function _s(t,n){let o={};for(let i of [...t,...n])o[zn(i)]=i;return Object.values(o)}function aa(t,n){return {...t,availableChannels:t.channels,channelsLoaded:!t.connected,enabled:t.connected&&n==="edit"&&t.enabled,loadingChannels:false}}function Bs(t,n){return {slack:aa(t.providers.slack,n),teams:aa(t.providers.teams,n)}}function js({channels:t,disabled:n,loading:o,onChange:i,onRefresh:l,provider:k,value:f}){let[g,c]=useState(false),[p,d]=useState(""),v=useRef(null),C=new Set(f.map(b=>b.id)),T=k==="slack"?"Slack":"Teams",j=t.filter(b=>b.name.toLowerCase().includes(p.toLowerCase()));useEffect(()=>{if(!g)return;function b(F){let{target:S}=F;!(S instanceof Node)||v.current?.contains(S)||c(false);}function P(F){F.key==="Escape"&&c(false);}return document.addEventListener("pointerdown",b),document.addEventListener("keydown",P),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("keydown",P);}},[g]);function A(b){if(C.has(b.id)){i(f.filter(P=>P.id!==b.id));return}i([...f,b]);}function x(b){i(f.filter(P=>P.id!==b));}return jsxs("div",{className:"fk:relative",ref:v,children:[jsxs(b$2,{"aria-expanded":g,className:"fk:h-auto fk:min-h-8 fk:w-full fk:max-w-100 fk:justify-between fk:bg-muted/60 fk:px-3 fk:py-1 hover:fk:border-secondary fk:dark:bg-muted/30",disabled:n,role:"combobox",type:"button",variant:"outline",onClick:()=>c(b=>!b),children:[jsx("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:gap-1",children:f.length===0?jsx("span",{className:"fk:text-muted-foreground",children:o?`Loading ${T} channels...`:`Select ${T} channels`}):f.map(b=>jsxs(b$1,{className:"fk:rounded-sm fk:bg-accent fk:text-xs fk:corner-squircle",variant:"secondary",onClick:P=>{P.stopPropagation(),x(b.id);},children:[b.name,jsx(XIcon,{className:"fk:ml-1 fk:size-3 fk:cursor-pointer"})]},zn(b)))}),jsx(ChevronsUpDownIcon,{className:"fk:size-4 fk:shrink-0 fk:opacity-50"})]}),g?jsxs("div",{className:"fk:absolute fk:z-50 fk:mt-1 fk:w-full fk:max-w-100 fk:rounded-md fk:border fk:bg-popover fk:p-0 fk:text-popover-foreground fk:shadow-md fk:corner-squircle",children:[jsx("div",{className:"fk:border-b fk:p-2",children:jsx(s,{className:"fk:h-8",placeholder:`Search ${T} channels...`,value:p,onChange:b=>d(b.target.value)})}),jsx("div",{className:"fk:max-h-56 fk:overflow-auto fk:p-1",children:j.length>0?j.map(b=>jsxs(b$2,{className:"fk:h-auto fk:w-full fk:justify-start fk:rounded-sm fk:px-2 fk:py-1.5 fk:font-normal fk:corner-squircle",type:"button",variant:"ghost",onClick:()=>A(b),children:[jsx(CheckIcon,{className:`fk:mr-2 fk:size-4 ${C.has(b.id)?"fk:opacity-100":"fk:opacity-0"}`}),b.name]},zn(b))):jsx("div",{className:"fk:px-2 fk:py-6 fk:text-center fk:text-sm fk:text-muted-foreground",children:o?"Loading channels...":"No channels found."})}),jsx("div",{className:"fk:border-t fk:border-border fk:p-2",children:jsx(b$2,{className:"fk:h-8 fk:w-full fk:justify-start fk:text-xs",disabled:o,type:"button",variant:"ghost",onClick:l,children:o?jsxs(Fragment,{children:[jsx(LoaderCircleIcon,{className:"fk:mr-2 fk:size-3 fk:animate-spin"}),"Refreshing channels..."]}):jsxs(Fragment,{children:[jsx(RefreshCwIcon,{className:"fk:mr-2 fk:size-3"}),"Refresh channels"]})})})]}):null]})}function Gt({cron:t,timezone:n}){let[o]=ma(t,n,1);return o?jsxs("span",{className:"fk:text-sm fk:text-muted-foreground",children:["Next run ",ka(o,n)]}):null}function sa({onChange:t,value:n}){return jsxs(a$3,{value:n.toString(),onValueChange:o=>t(Number(o)),children:[jsx(d$3,{"aria-label":"Hour",className:"fk:h-7 fk:w-fit fk:gap-1 fk:border-transparent fk:bg-background/90 fk:px-2 fk:py-0 fk:text-sm fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$5,{})}),jsx(e$6,{children:As.map(o=>jsx(g$5,{value:o.value.toString(),children:o.label},o.value))})]})}function $s({onChange:t,value:n}){return jsxs(a$3,{value:n.toString(),onValueChange:o=>t(Number(o)),children:[jsx(d$3,{"aria-label":"Day of week",className:"fk:h-7 fk:w-fit fk:gap-1 fk:border-transparent fk:bg-background/90 fk:px-2 fk:py-0 fk:text-sm fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$5,{})}),jsx(e$6,{children:ws.map(o=>jsx(g$5,{value:o.value.toString(),children:o.label},o.value))})]})}function Vs({onChange:t,timezone:n,value:o}){let[i,l]=useState(false),k=useRef(null),f=pa(o,n),g=f?[]:ma(o,n,3);return useEffect(()=>{if(!i)return;function c(d){let{target:v}=d;!(v instanceof Node)||k.current?.contains(v)||l(false);}function p(d){d.key==="Escape"&&l(false);}return document.addEventListener("pointerdown",c),document.addEventListener("keydown",p),()=>{document.removeEventListener("pointerdown",c),document.removeEventListener("keydown",p);}},[i]),jsxs("div",{className:"fk:relative",ref:k,children:[jsxs(b$2,{className:"fk:h-auto fk:gap-1.5 fk:bg-background/90 fk:px-2 fk:py-1 fk:font-mono fk:font-normal fk:shadow-sm hover:fk:bg-accent",type:"button",variant:"ghost",onClick:()=>l(c=>!c),children:[o||"Set cron",jsx(ChevronDownIcon,{className:"fk:size-3.5 fk:opacity-50"})]}),i?jsxs("div",{className:"fk:absolute fk:z-50 fk:mt-1 fk:w-72 fk:rounded-md fk:border fk:bg-popover fk:p-3 fk:text-popover-foreground fk:shadow-md fk:corner-squircle",children:[jsxs("div",{className:"fk:mb-2 fk:text-xs fk:text-muted-foreground",children:["Cron expression (",n,")"]}),jsx(s,{className:`fk:h-8 fk:font-mono ${f?"fk:border-destructive focus-visible:fk:ring-destructive":""}`,value:o,onChange:c=>t(c.target.value)}),f?jsx("p",{className:"fk:mt-2 fk:text-xs fk:text-destructive",children:f}):jsxs("div",{className:"fk:mt-2 fk:space-y-0.5 fk:text-xs fk:text-muted-foreground",children:[jsx("p",{className:"fk:mb-1",children:"5 fields: min hour day month weekday"}),g.map(c=>jsx("p",{children:ka(c,n)},c.toISOString()))]})]}):null]})}function Os({onChange:t,trigger:n}){let o=zs(n.cron);return o.kind==="hourly"?jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Every hour"}),jsx(Gt,{cron:n.cron,timezone:n.timezone})]}):o.kind==="daily"?jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Every day at"}),jsx(sa,{value:o.hour,onChange:i=>t({...n,cron:`0 ${i.toString()} * * *`})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(Gt,{cron:n.cron,timezone:n.timezone})]}):o.kind==="weekly"?jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Every week on"}),jsx($s,{value:o.day,onChange:i=>t({...n,cron:`0 ${o.hour.toString()} * * ${i.toString()}`})}),jsx("span",{children:"at"}),jsx(sa,{value:o.hour,onChange:i=>t({...n,cron:`0 ${i.toString()} * * ${o.day.toString()}`})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(Gt,{cron:n.cron,timezone:n.timezone})]}):jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Custom schedule"}),jsx(Vs,{timezone:n.timezone,value:n.cron,onChange:i=>t({...n,cron:i})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(Gt,{cron:n.cron,timezone:n.timezone})]})}function qs({onChange:t,projectId:n,trigger:o}){let[i,l]=useState(false),[k,f]=useState(false),g=o.url??c$6(n,o.token);function c$1(p,d){navigator.clipboard.writeText(p).then(()=>{d(true),window.setTimeout(()=>d(false),1500);});}return jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Webhook triggered"}),jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsxs(b$2,{className:"fk:h-auto fk:min-w-0 fk:max-w-60 fk:gap-1.5 fk:bg-background/90 fk:px-2 fk:py-1 fk:text-xs fk:font-normal fk:shadow-sm hover:fk:bg-accent",type:"button",variant:"ghost",onClick:()=>c$1(g,l),children:[jsx("span",{className:"fk:truncate",children:g}),i?jsx(CheckIcon,{className:"fk:size-3.5 fk:shrink-0"}):jsx(CopyIcon,{className:"fk:size-3.5 fk:shrink-0 fk:opacity-60"})]})}),jsx(e$1,{className:"fk:max-w-96 fk:break-all",children:g})]}),o.secret?jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>c$1(`Bearer ${o.secret??""}`,f),children:[k?jsx(CheckIcon,{className:"fk:size-3.5"}):jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Copy auth header"]}):jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>t({...o,secret:Ds()}),children:[jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Generate auth header"]})]})}function Js({entities:t,onChange:n,trigger:o}){function i(f){let g=o.events.includes(f)?o.events.filter(c=>c!==f):[...o.events,f];n({...o,events:ea.filter(c=>g.includes(c))});}function l(f){let g=o.entities.includes(f)?o.entities.filter(c=>c!==f):[...o.entities,f];n({...o,entities:g});}let k$1=o.entities.length>0?o.entities.join(", "):"All entities";return jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"On"}),jsx("div",{className:"fk:flex fk:items-center fk:gap-1",children:ea.map(f=>jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs fk:capitalize",size:"sm",type:"button",variant:o.events.includes(f)?"secondary":"ghost",onClick:()=>i(f),children:[o.events.includes(f)?jsx(CheckIcon,{className:"fk:size-3"}):null,f]},f))}),jsx("span",{children:"of"}),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(b$2,{className:"fk:h-7 fk:max-w-60 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",children:[jsx("span",{className:"fk:truncate",children:k$1}),jsx(ChevronDownIcon,{className:"fk:size-3.5 fk:opacity-50"})]})}),jsx(h,{align:"start",className:"fk:max-h-64 fk:w-56 fk:overflow-auto",children:t.length===0?jsx(j,{disabled:true,children:"No entities found in the project schema"}):t.map(f=>jsx(k,{checked:o.entities.includes(f),onCheckedChange:()=>l(f),onSelect:g=>g.preventDefault(),children:f},f))})]})]})}function Us({automationId:t,onChange:n,projectId:o,trigger:i}){let{data:l}=De(i.job==="schema_deploy"?null:g(o).automations({limit:100}),f),k=(l?.automations??[]).filter(f=>f.id!==t);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:"When"}),jsxs(a$3,{value:i.job,onValueChange:f=>n({...i,automationId:f==="schema_deploy"?null:i.automationId,job:f}),children:[jsx(d$3,{className:"fk:h-7 fk:w-auto fk:text-xs",children:jsx(c$5,{})}),jsx(e$6,{children:Object.keys(ta).map(f=>jsx(g$5,{value:f,children:ta[f]},f))})]}),i.job==="schema_deploy"?null:jsxs(a$3,{value:i.automationId??(i.job==="bulk_action"?Mn:""),onValueChange:f=>n({...i,automationId:f===Mn?null:f}),children:[jsx(d$3,{className:"fk:h-7 fk:w-auto fk:max-w-60 fk:text-xs",children:jsx(c$5,{placeholder:"Choose an automation"})}),jsxs(e$6,{children:[i.job==="bulk_action"?jsx(g$5,{value:Mn,children:"any automation"}):null,k.map(f=>jsx(g$5,{value:f.id,children:f.name},f.id))]})]}),jsxs(a$3,{value:i.outcome,onValueChange:f=>n({...i,outcome:f}),children:[jsx(d$3,{className:"fk:h-7 fk:w-auto fk:text-xs",children:jsx(c$5,{})}),jsx(e$6,{children:Object.keys(na).map(f=>jsx(g$5,{value:f,children:na[f]},f))})]})]})}function Hs(t){let n=t.trim();return n==="true"||n==="false"?n==="true":n==="null"?null:n!==""&&Number.isFinite(Number(n))?Number(n):t}function Xs(t){return t===void 0?"":String(t)}function Ks({onChange:t,value:n}){let[o,i]=useState(()=>Xs(n));return jsx(s,{"aria-label":"Value",className:"fk:h-7 fk:w-32 fk:text-xs",placeholder:"10",value:o,onChange:l=>{i(l.target.value),t(Hs(l.target.value));}})}function Ws({onChange:t,trigger:n}){let o=useId(),{condition:i}=n;return jsxs("div",{className:"fk:flex fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-2 fk:text-sm",children:[jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-2",children:[jsx("span",{children:"Every"}),jsx(s,{"aria-label":"Minutes between checks",className:"fk:h-7 fk:w-16 fk:text-xs",max:Dn,min:Ln,type:"number",value:Number.isFinite(n.intervalMinutes)?n.intervalMinutes:"",onChange:l=>t({...n,intervalMinutes:Number.parseInt(l.target.value,10)})}),jsx("span",{children:"minutes, run when"}),jsxs(a$3,{value:i?"condition":"changed",onValueChange:l=>t({...n,condition:l==="changed"?null:{op:"gte",path:"",value:""}}),children:[jsx(d$3,{className:"fk:h-7 fk:w-auto fk:text-xs",children:jsx(c$5,{})}),jsxs(e$6,{children:[jsx(g$5,{value:"condition",children:"a value meets a condition"}),jsx(g$5,{value:"changed",children:"the result changes"})]})]})]}),i?jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-2",children:[jsx(s,{"aria-label":"Path in the result",className:"fk:h-7 fk:w-78 fk:font-mono fk:text-xs",placeholder:"data.ordersConnection.totalCount",value:i.path,onChange:l=>t({...n,condition:{...i,path:l.target.value}})}),jsxs(a$3,{value:i.op,onValueChange:l=>t({...n,condition:l==="exists"?{op:"exists",path:i.path}:{...i,op:l}}),children:[jsx(d$3,{className:"fk:h-7 fk:w-auto fk:text-xs",children:jsx(c$5,{})}),jsx(e$6,{children:Is.map(l=>jsx(g$5,{value:l.value,children:l.label},l.value))})]}),i.op==="exists"?null:jsx(Ks,{value:i.value,onChange:l=>t({...n,condition:{...i,value:l}})})]}):null,jsx(e$5,{className:"fk:sr-only",htmlFor:o,children:"Read-only GraphQL query"}),jsx(la,{className:"fk:min-h-20 fk:font-mono fk:text-xs",id:o,placeholder:`query {
|
|
2
|
+
ordersConnection(where: { status: { eq: "pending" } }) { totalCount }
|
|
3
|
+
}`,value:n.query,onChange:l=>t({...n,query:l.target.value})})]})}function Gs({automationId:t,entities:n,errors:o,onChange:i,projectId:l,triggers:k}){let f=k.some(v=>v.type==="webhook");function g(v){i([...k,v]);}function c(v){g({cron:v,key:ft(),timezone:Ls(),type:"schedule"});}function p(v){i(k.map(C=>C.key===v.key?v:C));}function d(v){i(k.filter(C=>C.key!==v));}return jsxs("div",{className:"fk:rounded-lg fk:border fk:bg-muted/60 fk:dark:bg-muted/30 fk:corner-squircle",children:[k.map(v$1=>jsxs(Fragment$1,{children:[jsxs("div",{className:"fk:group fk:rounded-md fk:m-1.5 fk:p-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-3",children:[v$1.type==="schedule"?jsx(ClockIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,v$1.type==="webhook"?jsx(WebhookIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,v$1.type==="entity"?jsx(DatabaseZapIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,v$1.type==="job"?jsx(CircleCheckBigIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,v$1.type==="poll"?jsx(RefreshCwIcon,{className:"fk:size-4 fk:shrink-0 fk:self-start fk:mt-2.5 fk:text-muted-foreground"}):null,v$1.type==="schedule"?jsx(Os,{trigger:v$1,onChange:p}):null,v$1.type==="webhook"?jsx(qs,{projectId:l,trigger:v$1,onChange:p}):null,v$1.type==="entity"?jsx(Js,{entities:n,trigger:v$1,onChange:p}):null,v$1.type==="job"?jsx(Us,{automationId:t,projectId:l,trigger:v$1,onChange:p}):null,v$1.type==="poll"?jsx(Ws,{trigger:v$1,onChange:p}):null,jsx(b$2,{"aria-label":"Remove trigger",className:"fk:opacity-0 fk:group-hover:opacity-100",size:"icon",type:"button",variant:"ghost",onClick:()=>d(v$1.key),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})})]}),o[v$1.key]?jsx("div",{className:"fk:mt-1 fk:pl-7",children:jsx(Xe,{message:o[v$1.key]})}):null]},v$1.key),jsx(v,{className:"fk:h-4"})]},v$1.key)),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(b$2,{className:`fk:h-auto fk:w-full fk:justify-start fk:gap-3 fk:px-3 fk:py-3 fk:text-muted-foreground hover:fk:bg-muted hover:fk:text-foreground ${k.length===0?"fk:rounded-lg fk:corner-squircle":"fk:rounded-none fk:rounded-b-lg fk:corner-squircle"}`,type:"button",variant:"ghost",children:[jsx(PlusIcon,{className:"fk:size-4"}),"Add Trigger"]})}),jsxs(h,{align:"start",className:"fk:w-56",children:[jsxs(q,{children:[jsxs(r,{children:[jsx(ClockIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Scheduled"]}),jsxs(s$1,{children:[jsx(j,{onClick:()=>c(da),children:"Hourly"}),jsx(j,{onClick:()=>c(Ts),children:"Daily"}),jsx(j,{onClick:()=>c(Cs),children:"Weekly"}),jsx(j,{onClick:()=>c(Ss),children:"Custom (cron)"})]})]}),jsxs(j,{disabled:f,onClick:()=>g({key:ft(),secret:null,token:crypto.randomUUID(),type:"webhook"}),children:[jsx(WebhookIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Webhook Triggered"]}),jsxs(j,{onClick:()=>g({entities:[],events:["create"],key:ft(),type:"entity"}),children:[jsx(DatabaseZapIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Entity Events"]}),jsxs(j,{onClick:()=>g({automationId:null,job:"schema_deploy",key:ft(),outcome:"succeeded",type:"job"}),children:[jsx(CircleCheckBigIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Job Finished"]}),jsxs(j,{onClick:()=>g({condition:{op:"gte",path:"",value:""},intervalMinutes:Ps,key:ft(),query:"",type:"poll",variables:null}),children:[jsx(RefreshCwIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Poll Condition"]})]})]})]})}function Zs(){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 Ys(){return jsxs("svg",{"aria-label":"Microsoft Teams",className:"fk:mt-1 fk:size-3.5 fk:text-muted-foreground",fill:"currentColor",role:"img",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{clipRule:"evenodd",d:"M15.5 5A3 3 0 0 1 14 7.599V7.5a2 2 0 0 0-2-2H9.541A3 3 0 1 1 15.5 5Zm6.25 1a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm-3.294 11.732A3.25 3.25 0 0 0 23 14.75v-4.361a.889.889 0 0 0-.889-.889h-3.879c.17.294.268.636.268 1V17c0 .248-.015.492-.044.732ZM8.169 19.5A5 5 0 0 0 17.5 17v-6.5a1 1 0 0 0-1-1H14v8a2 2 0 0 1-2 2H8.169Z",fillRule:"evenodd"}),jsx("path",{clipRule:"evenodd",d:"M1 17.5v-10a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1Zm6.75-6.75H9.5v-1.5h-5v1.5h1.75v4.75h1.5v-4.75Z",fillRule:"evenodd"})]})}function Yt(t,n,o){return t.visibility==="space"?n==="space"&&o!==null&&t.spaceId===o:t.visibility==="personal"?n==="personal":true}function Qs(t,n,o){return t.visibility==="space"&&!Yt(t,n,o)}function ei(t,n){let o=t.spaceId?n[t.spaceId]:void 0;return o?`Only available on ${o} automations`:"Only available on space automations"}async function ti(t,n){try{return (await f(g(t).skill(n))).skill}catch(o){if(o instanceof e$7&&o.status===404)return null;throw o}}var ga=[{label:"Results that need attention (recommended)",value:"when_flagged"},{label:"Every finished run",value:"always"},{label:"Failures only",value:"failures"},{label:"Never",value:"never"}];function ni(t){return ga.some(n=>n.value===t)}function Fn({api:t,automation:n,mode:o,onSaved:i,projectId:l}){let[k,f$1]=useState((n?.toolConfigs??[]).filter(s=>!["slack","teams"].includes(s.pluginId))),[g$1,c]=useState(n?.name??""),[p,d]=useState(n?.instructions??""),[v$1,C]=useState(n?.enabled??false),[T,j]=useState(null),[A,x]=useState(null),[b$3,P]=useState(n?.mutationPolicy??"require_approval"),[F,S]=useState(n?.toolAllowRules),[_$1,M]=useState(n?.notifyRule??"when_flagged"),[B,U]=useState(n?.notifyCreator??true),[w,H]=useState(n?.subscriberIds??[]),[$,he]=useState(n?.visibility??"project"),[q,be]=useState(n?.spaceId??null),[ye,Be]=useState(n?.skillIds??[]),[me,dt]=useState(n?.customToolNames??[]),[Ce,ze]=useState(()=>Rs(n)),[je,We]=useState(false),[Ge,$e]=useState(""),[R,N]=useState({instructions:false,name:false}),[E,ke]=useState(null),[Pt,mt]=useState(null),{mutate:$n}=useSWRConfig(),[kt,Vn]=useState(()=>({slack:n?.toolConfigs?.find(s=>s.pluginId==="slack")?.connectionId??null,teams:n?.toolConfigs?.find(s=>s.pluginId==="teams")?.connectionId??null})),Mt=useRef({}),On=useRef(null),{data:Ze,error:Ia}=De(`/api/flexkit/${l}/plugins`,f),qn=!!(Ze||Ia),Pa=g(l).tools(n?.id),{data:Ve,error:Ma}=De(Pa,f),{data:Ra}=De(g(l).entities,f),{data:sn}=De(g(l).spaces,f),{data:Rt}=De($==="personal"?null:g(l).members($==="space"?q:null),f),{data:oe}=De(g(l).skills({limit:100}),f),[,Ea]=g$3(),ae=b(),La=Ea.user?.spaces??[],Jn=(sn?.spaces??[]).filter(s=>La.includes(s.code)),Et=Ve?.tools.models,Un=useMemo(()=>{let s=n?.modelId??"";return s?f$3(s,Et??[])??{effort:null,modelKey:s}:null},[n?.modelId,Et]),ln=T??Un?.modelKey??"",pt=useMemo(()=>Fs(Et??[],o,ln),[o,Et,ln]),Lt=ln||(pt[0]?b$6(pt[0]):""),Hn=c$4(pt,Lt),rn=d$2(Hn,A??(T===null?Un?.effort??null:null)),Xn=e$4(Hn),cn=Lt?g$4({effort:rn,modelKey:Lt},pt):"",Kn=useMemo(()=>new Set((oe?.skills??[]).map(s=>s.id)),[oe?.skills]),Ye=useMemo(()=>oe?ye.filter(s=>!Kn.has(s)).sort():[],[Kn,ye,oe]),Da=Ye.length>0?[l,"attached-skills",...Ye]:null,{data:Dt}=De(Da,()=>Promise.all(Ye.map(s=>ti(l,s)))),Qe=useMemo(()=>{let s={};for(let h of oe?.skills??[])s[h.id]=h;for(let h of Dt??[])h&&(s[h.id]=h);return s},[Dt,oe?.skills]),fn=useMemo(()=>{let s=(oe?.skills??[]).filter(y=>Yt(y,$,q)),h=new Set(s.map(y=>y.id));return [...ye.map(y=>Qe[y]).filter(y=>!y||h.has(y.id)?false:Yt(y,$,q)),...s]},[ye,Qe,oe?.skills,q,$]),za=useMemo(()=>{let s={};for(let h of sn?.spaces??[])s[h.id]=h.label;return s},[sn?.spaces]),un=useMemo(()=>(oe?.skills??[]).filter(s=>Qs(s,$,q)),[oe?.skills,q,$]),Fe=Ve?.tools.customTools,dn=useMemo(()=>{let s={};for(let h of Fe?.tools??[])s[h.name]=h;return s},[Fe?.tools]),mn=useMemo(()=>{let s=Fe?.tools??[],h=new Set(s.map(y=>y.name));return [...me.filter(y=>!h.has(y)).map(y=>dn[y]??{description:"",name:y}),...s]},[me,dn,Fe?.tools]),Wn=Fe?Es(Fe):"";useEffect(()=>{if(!oe)return;let s=Ye.length>0&&Dt===void 0,h=new Set(s?[]:Ye.filter(m=>!Qe[m]));Be(m=>{let y=m.filter(D=>{if(h.has(D))return false;let Me=Qe[D];return Me?Yt(Me,$,q):true});return y.length===m.length?m:y});},[Dt,Qe,oe,q,Ye,$]);let et=oa(k),le=useMemo(()=>{let s={};for(let m of Ce){if(m.type==="schedule"){let y=pa(m.cron,m.timezone);y&&(s[m.key]=y);}m.type==="entity"&&m.events.length===0&&(s[m.key]="Select at least one event (create, update or delete)"),m.type==="job"&&m.job==="automation_run"&&!m.automationId&&(s[m.key]="Choose the automation whose runs start this one"),m.type==="poll"&&(!Number.isInteger(m.intervalMinutes)||m.intervalMinutes<Ln||m.intervalMinutes>Dn?s[m.key]=`Check every ${Ln.toString()} to ${Dn.toString()} minutes`:m.query.trim()?m.condition&&!m.condition.path.trim()&&(s[m.key]="Enter the path of the value to compare, e.g. data.ordersConnection.totalCount"):s[m.key]="Enter the read-only GraphQL query to check");}let h={};for(let m of Wt){let y=E?.[m];y?.enabled&&y.channels.length===0&&(h[m]=`Select at least one ${m==="slack"?"Slack":"Teams"} channel or remove the tool`);}return {instructions:p.trim()?"":"Instructions are required",model:cn?"":"Select a model",name:g$1.trim()?"":"Name is required",plugins:et&&$!=="personal"?"Personal plugin connections can only be used by a personal automation.":"",space:$==="space"&&!q?"Select a space":"",toolErrors:h,triggerErrors:s}},[cn,p,g$1,et,q,E,Ce,$]),kn=Ms(le),zt=R.name&&!!le.name,gt=R.instructions&&!!le.instructions;useEffect(()=>{let s=`${n?.id??""}:${o}`;!Ve?.tools||On.current===s||(On.current=s,ke(Bs(Ve.tools,o)));},[n?.id,o,Ve?.tools]);let Ft=useMemo(()=>({slack:Ze?.plugins.find(s=>s.id==="slack")??null,teams:Ze?.plugins.find(s=>s.id==="teams")??null}),[Ze]),pn=useMemo(()=>{let s=h=>{let m=Ft[h];return m?In(m,{connectionMode:"project",connectionId:kt[h]})?.id??null:null};return {slack:s("slack"),teams:s("teams")}},[kt,Ft]),gn=useCallback(async(s,h)=>{Mt.current[s]=h,ke(m=>m&&{...m,[s]:{...m[s],channelsLoadError:void 0,loadingChannels:true}});try{let m=await t.listChannels(s,h);if(Mt.current[s]!==h)return;let y=m.success?void 0:m.errorMessage??`Failed to load ${s==="slack"?"Slack":"Teams"} channels.`;ke(D=>D&&{...D,[s]:{...D[s],availableChannels:_s(D[s].channels,m.channels),channelsLoadError:y,channelsLoaded:!0,loadingChannels:!1}});}catch(m){if(Mt.current[s]!==h)return;let y=m instanceof Error?m.message:"Failed to load integration channels.";ke(D=>D&&{...D,[s]:{...D[s],channelsLoadError:y,channelsLoaded:true,loadingChannels:false}});}},[t]);useEffect(()=>{if(!(!E||!ae||!qn))for(let s of Wt){let h=E[s];h.connected&&!h.channelsLoaded&&!h.loadingChannels&&gn(s,pn[s]);}},[ae,gn,qn,pn,E]);async function Fa(s){let h=Ft[s];if(h){mt(s);try{await b$7(t,h.id,"project");let y=(await $n(`/api/flexkit/${l}/plugins`))?.plugins.find(D=>D.id===h.id)?.connections.find(D=>D.scope==="project"&&D.isPrimary&&D.status==="connected");Vn(D=>({...D,[s]:null})),Gn(s,{connected:!0,enabled:!0,workspaceName:y?.displayName??null});}catch(m){qa$1.error(m instanceof Error?m.message:`Unable to connect ${h.name}.`);}finally{mt(null);}}}function _t(s,h){ke(m=>m&&{...m,[s]:{...m[s],...h}});}function _a(s,h){kt[s]!==h&&(Vn(m=>({...m,[s]:h})),Gn(s));}function Gn(s,h={}){Mt.current[s]=void 0,_t(s,{...h,availableChannels:[],channels:[],channelsLoaded:false,channelsLoadError:void 0,loadingChannels:false});}function Ba(s){_t(s,{channels:[],enabled:false});}function Zn(s,h){Be(m=>h?m.includes(s)?m:[...m,s]:m.filter(y=>y!==s));}function Yn(s,h){dt(m=>h?m.includes(s)?m:[...m,s]:m.filter(y=>y!==s));}async function ja(s){if(s.preventDefault(),!ae)return;if(!kn){N({instructions:true,name:true});return}We(true),$e("");let h=Wt.map(y=>{let D=E?.[y]??Ve?.tools.providers[y];return {channels:D?.channels??[],enabled:D?.enabled??false,pluginId:y,connectionMode:"project",connectionId:kt[y],selectedTools:[],deliveryEnabled:D?.enabled??false}}),m={customToolNames:me,enabled:v$1,instructions:p,modelId:cn,mutationPolicy:b$3,name:g$1,notifyCreator:B,notifyRule:_$1,skillIds:ye,subscriberIds:$==="personal"?[]:w,...F!==void 0?{toolAllowRules:F}:{},spaceId:$==="space"?q:null,toolConfigs:[...h,...k],triggers:Ce.map(({key:y,...D})=>D),visibility:$};try{let y=o==="create"||!n?await t.createAutomation(m):await t.updateAutomation(n.id,m);if(!y.success){$e(Array.isArray(y.errorMessage)?y.errorMessage.join(", "):y.errorMessage);return}qa$1.success(o==="create"||!n?"Automation created.":"Automation saved."),i(y.automation);}catch(y){$e(y instanceof Error?y.message:"Failed to save automation.");}finally{We(false);}}return jsxs("form",{className:"fk:max-w-4xl fk:space-y-8 fk:px-1 fk:mx-auto",onSubmit:s=>{ja(s);},children:[Ge?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-3 fk:text-sm fk:text-destructive fk:corner-squircle",children:Ge}):null,jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",children:"Status"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-1",children:"Disabling an automation stops its schedules and ignores webhook calls and entity events"}),jsxs("div",{className:"fk:flex fk:h-10 fk:items-center fk:gap-2",children:[jsx(_,{checked:v$1,id:"automation-enabled",onCheckedChange:C}),jsx(e$5,{className:"fk:font-normal",htmlFor:"automation-enabled",children:v$1?"Active":"Inactive"})]})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-name",children:"Name"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Identifying label for this automation"}),jsx(s,{"aria-describedby":zt?"automation-name-error":void 0,"aria-invalid":zt,className:zt?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"automation-name",value:g$1,onBlur:()=>N(s=>({...s,name:true})),onChange:s=>c(s.target.value)}),zt?jsx(Xe,{id:"automation-name-error",message:le.name}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-visibility",children:"Visibility"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Who can see and manage this automation. Space automations are only visible to members of the selected space; personal automations are private to you."}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsxs(a$3,{value:$,onValueChange:s=>{et&&s!=="personal"||(he(s==="space"||s==="personal"?s:"project"),s!=="space"&&be(null));},children:[jsx(d$3,{"aria-label":"Visibility",className:"fk:w-fit",id:"automation-visibility",children:jsx(c$5,{})}),jsxs(e$6,{align:"start",children:[jsx(g$5,{disabled:et,value:"project",children:"Project"}),jsx(g$5,{disabled:et||Jn.length===0,value:"space",children:"Space"}),jsx(g$5,{value:"personal",children:"Personal"})]})]}),$==="space"?jsxs(a$3,{value:q??"",onValueChange:s=>{be(s||null);},children:[jsx(d$3,{"aria-label":"Space",className:"fk:w-fit",children:jsx(c$5,{placeholder:"Select a space"})}),jsx(e$6,{align:"start",children:Jn.map(s=>jsx(g$5,{value:s.id,children:s.label},s.id))})]}):null]}),et?jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"This automation uses a personal plugin connection, so project and space visibility are unavailable."}):null,le.plugins?jsx(Xe,{message:le.plugins}):null,$==="space"&&le.space?jsx(Xe,{message:le.space}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",children:"Triggers"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"When this automation should run. Schedules run in your timezone; webhooks run when their URL is called."}),jsx(Gs,{automationId:n?.id,entities:Ra?.entities??[],errors:le.triggerErrors,projectId:l,triggers:Ce,onChange:ze})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-instructions",children:"Agent instructions"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Natural-language instructions the agent follows on every run. Be specific about entities, conditions, and the expected outcome."}),jsxs("div",{children:[jsx("div",{className:`fk:rounded-t-md fk:border-x fk:border-t fk:bg-muted/60 fk:ring-offset-background focus-within:fk:ring-2 focus-within:fk:ring-ring focus-within:fk:ring-offset-2 fk:dark:bg-muted/30 ${gt?"fk:border-destructive":"fk:border-input"} fk:corner-squircle`,children:jsx(la,{"aria-describedby":gt?"automation-instructions-error":void 0,"aria-invalid":gt,className:"fk:flex fk:min-h-[160px] fk:max-h-[320px] fk:w-full fk:rounded-none fk:border-0 fk:bg-transparent fk:dark:bg-transparent fk:pb-11 fk:shadow-none focus-visible:fk:ring-0 focus-visible:fk:ring-offset-0 fk:mask-[linear-gradient(to_bottom,black_calc(100%-2.75rem),#0009_calc(100%-1.25rem),#0003_calc(100%-0.5rem),transparent)] fk:corner-squircle",id:"automation-instructions",placeholder:"Describe what the agent should do on each run, e.g. 'When a new Review is created, translate the text to English, run a sentiment analysis and store the result in the sentiment attribute...'",rows:8,value:p,onBlur:()=>N(s=>({...s,instructions:true})),onChange:s=>d(s.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 ${gt?"fk:border-destructive":"fk:border-input"} fk:corner-squircle`,children:jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-2",children:[jsxs(a$3,{value:Lt,onValueChange:s=>{j(s),x(null);},children:[jsx(d$3,{"aria-label":"Model",className:"fk:w-fit fk:border-transparent fk:bg-background/90 fk:px-2.5 fk:py-0 fk:text-xs fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$5,{placeholder:"Select a model"})}),jsx(e$6,{align:"start",children:pt.map(s=>jsxs(g$5,{value:b$6(s),children:[s.name,s.deprecated?" (Legacy)":""]},b$6(s)))})]}),Xn.length>1&&rn?jsxs(a$3,{value:rn,onValueChange:x,children:[jsx(d$3,{"aria-label":"Reasoning effort",className:"fk:w-fit fk:border-transparent fk:bg-background/90 fk:px-2.5 fk:py-0 fk:text-xs fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$5,{placeholder:"Effort"})}),jsx(e$6,{align:"start",children:Xn.map(s=>jsx(g$5,{value:s.value,children:s.label},s.value))})]}):null]})})]}),gt?jsx(Xe,{id:"automation-instructions-error",message:le.instructions}):null,Ve&&le.model?jsx(Xe,{message:le.model}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-mutation-policy",children:"Mutations"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"How data changes proposed by the agent are handled. With approval required, runs pause until a project member reviews a before/after preview in the Approvals inbox."}),jsxs(a$3,{value:b$3,onValueChange:s=>{P(s==="auto_approve"?"auto_approve":"require_approval");},children:[jsx(d$3,{"aria-label":"Mutation policy",className:"fk:w-fit",id:"automation-mutation-policy",children:jsx(c$5,{})}),jsxs(e$6,{align:"start",children:[jsx(g$5,{value:"require_approval",children:"Require approval (recommended)"}),jsx(g$5,{value:"auto_approve",children:"Auto-approve"})]})]}),b$3==="auto_approve"&&k.some(s=>s.enabled)?jsxs("p",{className:"fk:flex fk:items-start fk:gap-1 fk:text-xs fk:text-warning",role:"status",children:[jsx(TriangleAlertIcon,{className:"fk:mt-px fk:size-3.5 fk:shrink-0"}),"Plugin tools will run without review. Content the agent reads, such as emails or documents, could lead it to act on your connected accounts."]}):null,b$3==="require_approval"&&F&&F.length>0?jsxs("div",{className:"fk:space-y-2",children:[jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Always allowed plugin tools (approved with \u201Calways allow\u201D from the Approvals inbox):"}),jsx("ul",{className:"fk:space-y-1",children:F.map(s=>jsxs("li",{className:"fk:flex fk:items-center fk:justify-between fk:gap-2 fk:rounded-md fk:border fk:border-border fk:px-2.5 fk:py-1.5 fk:text-xs fk:corner-squircle",children:[jsxs("code",{children:[s.pluginId,": ",s.tool]}),jsx(b$2,{"aria-label":`Remove allow rule for ${s.pluginId} ${s.tool}`,size:"sm",type:"button",variant:"ghost",onClick:()=>S(h=>(h??[]).filter(m=>m!==s)),children:"Remove"})]},`${s.pluginId}/${s.server}/${s.tool}`))})]}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-notify-rule",children:"Notifications"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Approval requests and run results appear in Activity in Studio. Failures are always reported unless set to Never."}),jsxs(a$3,{value:_$1,onValueChange:s=>{ni(s)&&M(s);},children:[jsx(d$3,{"aria-label":"Notify about runs",className:"fk:w-fit",id:"automation-notify-rule",children:jsx(c$5,{})}),jsx(e$6,{align:"start",children:ga.map(s=>jsx(g$5,{value:s.value,children:s.label},s.value))})]}),jsxs("div",{className:"fk:flex fk:h-8 fk:items-center fk:gap-2",children:[jsx(_,{checked:B,id:"automation-notify-creator",onCheckedChange:U}),jsx(e$5,{className:"fk:font-normal",htmlFor:"automation-notify-creator",children:"Notify the creator"})]}),$==="personal"?null:jsxs("div",{className:"fk:space-y-2",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-2",children:[jsxs("div",{children:[jsx("p",{className:"fk:text-sm",children:"Subscribers"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Members who also get its notifications. Only owners and developers receive approval requests."})]}),jsx(Kt,{disabled:!ae||!Rt,emptyText:"No members match.",items:(Rt?.members??[]).map(s=>({attached:w.includes(s.id),id:s.id,label:s.displayName})),searchPlaceholder:"Search members\u2026",triggerLabel:"Add",onToggle:(s,h)=>H(m=>h?[...new Set([...m,s])]:m.filter(y=>y!==s))})]}),w.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5",children:w.map(s=>{let m=Rt?.members.find(y=>y.id===s)?.displayName??(Rt?"No longer has access":"Loading\u2026");return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[m,jsx("button",{"aria-label":`Remove subscriber ${m}`,className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!ae,type:"button",onClick:()=>H(y=>y.filter(D=>D!==s)),children:jsx(XIcon,{className:"fk:size-3"})})]},s)})}):null]})]}),jsxs("div",{className:"fk:space-y-4",children:[jsxs("div",{children:[jsx(e$5,{className:"fk:text-sm fk:font-medium",children:"Tools"}),jsx("p",{className:"fk:mb-3 fk:text-xs fk:text-muted-foreground",children:"Configure additional destinations and built-in capabilities for this automation."})]}),jsxs("div",{className:"fk:rounded-lg fk:border fk:bg-muted/60 fk:dark:bg-muted/30 fk:corner-squircle",children:[jsx("div",{className:"fk:rounded-t-lg fk:corner-squircle",children:jsxs("div",{className:"fk:m-1.5 fk:flex fk:items-start fk:justify-between fk:gap-3 fk:rounded-md fk:p-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:gap-3 fk:pb-0.5",children:[jsx(BrainIcon,{className:"fk:mt-1 fk:size-3.5 fk:text-muted-foreground"}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:"Memories"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Builds memory across runs to make automations smarter over time"})]})]}),jsx(b$1,{className:"fk:mt-1.5 fk:py-0 fk:text-[10px] fk:font-light fk:tracking-wide",variant:"secondary",children:"Always on"})]})}),jsx(v,{}),E?Wt.map(s=>{let h=E[s],m=s==="slack"?"Send to Slack":"Send to Microsoft Teams",y=s==="slack"?Zs:Ys,D=Ft[s];return jsxs(Fragment$1,{children:[jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:p-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsxs("div",{className:"fk:flex fk:gap-3",children:[jsx(y,{}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:m}),h.connected&&h.workspaceName?jsxs("p",{className:"fk:text-xs fk:text-muted-foreground",children:["Connected to ",h.workspaceName]}):null,h.connected?null:jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:Ze?.canManage===false?"Not connected. Ask a project owner or developer to connect it.":"Not connected"})]})]}),h.connected?h.enabled?jsx(b$2,{"aria-label":`Remove ${s==="slack"?"Slack":"Microsoft Teams"} from automation`,size:"icon",type:"button",variant:"ghost",onClick:()=>Ba(s),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})}):jsx(b$2,{size:"sm",type:"button",variant:"outline",onClick:()=>_t(s,{enabled:true}),children:"Add"}):jsx(b$2,{disabled:!ae||!D?.enabled||!Ze?.canManage||Pt!==null,size:"sm",type:"button",variant:"outline",onClick:()=>{Fa(s);},children:Pt===s?"Connecting\u2026":"Connect"})]}),h.connected&&h.enabled?jsxs("div",{className:"fk:space-y-2 fk:pl-7",children:[D&&D.connections.filter(Me=>Me.scope==="project"&&Me.status==="connected").length>1?jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-3",children:[jsx(e$5,{className:"fk:text-xs fk:font-medium",children:"Workspace"}),jsx(Pn,{ariaLabel:`${s==="slack"?"Slack":"Microsoft Teams"} workspace`,disabled:!ae,plugin:D,scopes:["project"],value:{connectionMode:"project",connectionId:kt[s]},onChange:Me=>_a(s,Me.connectionId)})]}):null,jsx(e$5,{className:"fk:mr-3 fk:text-xs fk:font-medium",children:"Channels"}),jsx(js,{channels:h.availableChannels,disabled:h.loadingChannels||!ae,loading:h.loadingChannels,provider:s,value:h.channels,onChange:Me=>_t(s,{channels:Me}),onRefresh:()=>{gn(s,pn[s]);}}),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&&le.toolErrors[s]?jsx(Xe,{message:le.toolErrors[s]}):null]}):null]}),jsx(v,{})]},s)}):Ma?jsx("p",{className:"fk:m-1.5 fk:p-1.5 fk:text-xs fk:text-warning",role:"alert",children:"Unable to load Slack and Microsoft Teams delivery. Reload the page to try again."}):jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:p-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircleIcon,{className:"fk:size-4 fk:animate-spin"}),"Loading tools..."]}),jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsxs("div",{className:"fk:flex fk:gap-2.5",children:[jsx(GraduationCapIcon,{className:"fk:mt-px fk:size-5 fk:text-muted-foreground"}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:"Skills"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Attached skills are always loaded into the agent context. All other skills you can see stay discoverable by the agent when relevant."})]})]}),jsx(Kt,{disabled:!ae||fn.length===0&&un.length===0,emptyText:"No skills match.",items:[...fn.map(s=>({id:s.id,label:s.name,attached:ye.includes(s.id),badge:s.source==="code"?"Code":void 0})),...un.map(s=>({id:s.id,label:s.name,attached:false,badge:s.source==="code"?"Code":void 0,lockedHint:ei(s,za)}))],searchPlaceholder:"Search skills\u2026",onToggle:Zn})]}),oe&&fn.length===0&&un.length===0?jsx("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:"No attachable skills yet. Create them on the Skills tab."}):null,oe?.hasMore?jsxs("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:["Showing the ",oe.skills.length," most recently updated skills. Attached skills outside this list are kept when you save."]}):null,ye.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5 fk:pl-7",children:ye.map(s=>{let h=Qe[s],m=h?.name??"Loading skill\u2026";return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[m,h?.source==="code"?jsx("span",{className:"fk:text-[10px] fk:uppercase",children:"Code"}):null,jsx("button",{"aria-label":h?`Detach ${h.name}`:"Detach skill",className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!ae,type:"button",onClick:()=>Zn(s,false),children:jsx(XIcon,{className:"fk:size-3"})})]},s)})}):null]}),jsx(v,{}),jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsxs("div",{className:"fk:flex fk:gap-2.5",children:[jsx(WrenchIcon,{className:"fk:mt-px fk:size-5 fk:text-muted-foreground"}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:"Custom tools"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Attached custom tools can be called during a run. Tools you do not attach stay unavailable to this automation."}),Wn?jsx("p",{className:Fe?.connected?"fk:mt-1 fk:text-xs fk:text-warning":"fk:mt-1 fk:text-xs fk:text-muted-foreground",children:Wn}):null]})]}),jsx(Kt,{disabled:!ae||mn.length===0,emptyText:"No custom tools match.",items:mn.map(s=>({id:s.name,label:s.name,attached:me.includes(s.name)})),searchPlaceholder:"Search custom tools\u2026",onToggle:Yn})]}),Fe&&mn.length===0?jsx("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:"No custom tools registered yet. Define them in flexkit.tools.ts, run `flexkit dev` or sync them from the Dashboard, then attach the ones this automation needs."}):null,me.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5 fk:pl-7",children:me.map(s=>{let m=dn[s]?.name??s;return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[m,jsx("button",{"aria-label":`Detach ${m}`,className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!ae,type:"button",onClick:()=>Yn(s,false),children:jsx(XIcon,{className:"fk:size-3"})})]},s)})}):null]}),jsx(v,{}),jsx(Ko,{projectId:l,value:k,disabled:!ae,onChange:s=>{f$1(s),oa(s)&&(he("personal"),be(null));}})]})]}),jsxs("div",{className:"fk:flex fk:items-center fk:justify-end fk:gap-3",children:[kn?null:jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Complete the required fields to save"}),jsx(na$1,{disabled:!ae,children:jsx(b$2,{disabled:je||!kn||!ae,type:"submit",children:je?"Saving...":o==="create"?"Create automation":"Update automation"})})]})]})}var ba=25;function pi(t){return Math.max(600,t)}function gi(t){return t==="mine"||t==="team"}function Z({children:t}){return jsx("div",{className:"fk:rounded-md fk:border fk:border-dashed fk:p-8 fk:text-center fk:text-sm fk:text-muted-foreground fk:corner-squircle",children:t})}function vi(t){return t==="success"?"fk:bg-success/20 fk:text-success":t==="awaiting_approval"?"fk:bg-amber-500/20 fk:text-amber-600":t==="skipped"?"fk:bg-orange-500/20 fk:text-orange-700":"fk:bg-secondary fk:text-secondary-foreground"}function Ca({status:t}){return jsx(b$1,{className:`fk:border-none fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide ${vi(t)}`,variant:t==="success"?"default":"secondary",children:t==="awaiting_approval"?"awaiting approval":t})}function hi(t){if(t==="0 * * * *")return "Every hour";let n=/^0 (\d{1,2}) \* \* \*$/.exec(t);if(n)return `Every day at ${n[1].padStart(2,"0")}:00`;let o=/^0 (\d{1,2}) \* \* ([0-6])$/.exec(t);return o?`Every ${["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][Number(o[2])]??"week"} at ${o[1].padStart(2,"0")}:00`:t}function bi(t){let n=t.triggers.map(o=>{if(o.type==="schedule")return hi(o.cron);if(o.type==="webhook")return "Webhook";if(o.type==="job")return o.job==="schema_deploy"?"After a deployment":o.job==="automation_run"?"After another automation":"After a bulk action";if(o.type==="poll")return `Poll every ${o.intervalMinutes.toString()} min`;let i=o.entities.length>0?o.entities.join(", "):"all entities";return `On ${o.events.join("/")} of ${i}`});return n.length===0?"Manual only":n.join(" \xB7 ")}function Sa(t){return t?!!(t.name.trim()&&t.instructions.trim()&&t.modelId.trim()):false}function yi({projectId:t}){let{data:n}=De(g(t).creditBalance,f),o=n?.creditBalance;return o?jsx(b$2,{asChild:true,size:"sm",variant:"secondary",children:jsxs("a",{href:o.billingUrl,rel:"noopener noreferrer",target:"_blank",children:[jsx(CoinsIcon,{className:"fk:mr-2 fk:size-4"}),o.display," Credit"]})}):null}function xi(t,n){let o=t.visibility??"project";return o==="space"?(t.spaceId?n.get(t.spaceId):void 0)??"Space":o==="personal"?"Personal":"Project"}var wa="fk:sticky fk:top-0 fk:z-10 fk:[&_th]:sticky fk:[&_th]:top-0 fk:[&_th]:bg-muted";function Ni(){return jsxs($,{children:[jsx(aa$1,{className:wa,children:jsxs(da$1,{children:[jsx(ea$1,{children:"Automation"}),jsx(ea$1,{children:"Triggers"}),jsx(ea$1,{children:"Last run"}),jsx(ea$1,{className:"fk:text-center",children:"Runs"}),jsx(ea$1,{children:"Visibility"}),jsx(ea$1,{className:"fk:text-center",children:"Status"}),jsx(ea$1,{})]})}),jsx(ba$1,{children:Array.from({length:5},(t$1,n)=>jsxs(da$1,{children:[jsx(fa,{children:jsx(t,{className:"fk:h-4 fk:w-36"})}),jsx(fa,{children:jsx(t,{className:"fk:h-4 fk:w-48"})}),jsx(fa,{children:jsx(t,{className:"fk:h-4 fk:w-24"})}),jsx(fa,{className:"fk:text-center",children:jsx(t,{className:"fk:mx-auto fk:h-4 fk:w-8"})}),jsx(fa,{children:jsx(t,{className:"fk:h-4.75 fk:w-16"})}),jsx(fa,{className:"fk:text-center",children:jsx(t,{className:"fk:mx-auto fk:h-4.75 fk:w-16"})}),jsx(fa,{className:"fk:text-right",children:jsx(t,{className:"fk:ml-auto fk:size-8"})})]},n))})]})}function ya(t,n){let i=t.find(l=>l.id===n)?.value;return Array.isArray(i)?i.filter(l=>typeof l=="string"):[]}function Ti(t){if(t.length===0)return;let n=t.map(o=>o==="enabled"?true:o==="disabled"?false:null).filter(o=>o!==null);if(n.length!==0)return n}function Ci(t){if(t.length===0)return;let n=t.filter(o=>o==="project"||o==="space"||o==="personal");if(n.length!==0)return n}function Vl(){let{api:t,projectId:n}=x(),o$1=useNavigate(),[i,l]=useState([]),[k,f$2]=useState(""),[g$2,c$1]=useState(""),p=b(),d=useRef(null),v$1=ya(i,"status"),C=ya(i,"visibility"),T=Ti(v$1),j$1=Ci(C),A=i.length>0||k.trim().length>0,x$1=JSON.stringify({enabledFilter:T,search:k,visibilityFilter:j$1}),b$4=(N,E)=>!n||E&&E.hasMore===false?null:g(n).automations({enabled:T,limit:ba,offset:N*ba,search:k.trim()||void 0,visibility:j$1}),{data:P,isLoading:F,mutate:S,setSize:_,size:M}=It(b$4,f),{data:B}=De(n?g(n).spaces:null,f),U=useMemo(()=>new Map((B?.spaces??[]).map(N=>[N.id,N.label])),[B?.spaces]),w=P?.flatMap(N=>N.automations)??[],$$1=P?.[P.length-1]?.hasMore??false,he=P!==void 0&&M>P.length,q=P?.[0]?.count,be=F&&w.length===0,ye=useMemo(()=>[{id:"status",accessorKey:"enabled"},{id:"visibility",accessorKey:"visibility"}],[]),Be=useReactTable({columns:ye,data:w,getCoreRowModel:getCoreRowModel(),manualFiltering:true,onColumnFiltersChange:N=>{_(1),l(N);},state:{columnFilters:i}}),me=useRef(()=>{_(N=>N+1);}),dt=useRef($$1),Ce=useRef(he);me.current=()=>{_(N=>N+1);},dt.current=$$1,Ce.current=he;let ze=useCallback(N=>{if(!me.current||!dt.current||Ce.current)return;let E=N??d.current;if(!E)return;let{scrollHeight:ke,scrollTop:Pt,clientHeight:mt}=E;ke-Pt-mt>=pi(mt)||(Ce.current=true,me.current());},[]);useEffect(()=>{ze();},[ze,w.length,$$1,he,x$1]),useEffect(()=>{d.current?.scrollTo({top:0});},[x$1]);let je=useRef(k);je.current=k;let We=useCallback(N=>{N!==je.current&&(_(1),f$2(N));},[_]);if(!n||!t)return jsx(Z,{children:"Select a project to view automations."});async function Ge(N){if(c$1(""),!t)return;let E=await t.deleteAutomation(N.id);if(!E.success){c$1(Array.isArray(E.errorMessage)?E.errorMessage.join(", "):E.errorMessage);return}await S();}function $e(N){ze(N.currentTarget);}let R;return F&&w.length===0?R=jsx(Ni,{}):w.length===0?R=jsx(Z,{children:A?"No results.":"No automations yet."}):R=jsxs($,{children:[jsx(aa$1,{className:wa,children:jsxs(da$1,{children:[jsx(ea$1,{children:"Automation"}),jsx(ea$1,{children:"Triggers"}),jsx(ea$1,{children:"Last run"}),jsx(ea$1,{className:"fk:text-center",children:"Runs"}),jsx(ea$1,{children:"Visibility"}),jsx(ea$1,{className:"fk:text-center",children:"Status"}),jsx(ea$1,{})]})}),jsx(ba$1,{children:w.map(N=>jsxs(da$1,{className:"fk:cursor-pointer",onClick:()=>o$1(N.id),children:[jsx(fa,{children:jsx("span",{className:"fk:font-medium",children:N.name})}),jsx(fa,{className:"fk:text-muted-foreground",children:bi(N)}),jsx(fa,{children:N.lastRunAt?formatDistance(new Date(N.lastRunAt),new Date,{addSuffix:true}):"Never"}),jsx(fa,{className:"fk:text-center",children:N.totalRuns}),jsx(fa,{children:jsx(b$1,{className:"fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide",variant:N.visibility==="personal"?"secondary":"outline",children:xi(N,U)})}),jsx(fa,{className:"fk:text-center",children:jsx(b$1,{className:`fk:border-none fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide ${N.enabled?"fk:bg-success/20 fk:text-success":"fk:bg-secondary fk:text-secondary-foreground"}`,variant:N.enabled?"default":"secondary",children:N.enabled?"Enabled":"Disabled"})}),jsx(fa,{className:"fk:text-right",children:jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsx(b$2,{"aria-label":`Actions for ${N.name}`,size:"icon",type:"button",variant:"ghost",onClick:E=>{E.stopPropagation();},children:jsx(Ellipsis,{className:"fk:size-4"})})}),jsxs(h,{align:"end",className:"fk:w-40",children:[jsxs(j,{onClick:E=>{E.stopPropagation(),o$1(N.id);},children:[jsx(Pencil,{}),"Edit"]}),jsx(o,{}),jsxs(j,{disabled:!p,variant:"destructive",onClick:E=>{E.stopPropagation(),Ge(N);},children:[jsx(Trash2,{}),"Delete"]})]})]})})]},N.id))})]}),jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-4 fk:pr-4",children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsxs("div",{className:"fk:min-w-0 fk:flex-1",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:"Automations"}),!be&&q!==void 0?jsxs("span",{className:"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground",children:[q.toLocaleString()," ",q===1?"automation":"automations"]}):null]}),jsxs("p",{className:"fk:mt-1 fk:text-sm fk:text-muted-foreground",children:["Agent-powered tasks that run on a schedule or when your data changes.",jsx(f$1,{href:"https://flexkit.io/docs/automations",children:"Learn more"})]})]})]}),g$2?jsx("div",{className:"fk:text-sm fk:text-destructive",children:g$2}):null,jsx(Oo,{actions:jsxs(Fragment,{children:[jsx(yi,{projectId:n}),p?jsx(b$2,{asChild:true,className:"fk:h-8",size:"sm",children:jsxs(Link,{to:"new",children:[jsx(Plus,{className:"fk:mr-2 fk:size-4"}),"New Automation"]})}):jsx(na$1,{disabled:true,children:jsxs(b$2,{className:"fk:h-8",disabled:true,size:"sm",children:[jsx(Plus,{className:"fk:mr-2 fk:size-4"}),"New Automation"]})})]}),isSearchLoading:F&&k.trim().length>0,search:k,table:Be,onSearchChange:We}),jsxs("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1",children:[he?jsx("div",{"aria-hidden":true,className:"fk:pointer-events-none fk:absolute fk:top-0 fk:right-px fk:left-px fk:z-20 fk:h-0.5 fk:overflow-hidden fk:opacity-40",children:jsx("div",{className:"fk:animate-progress fk:h-full fk:w-full fk:bg-foreground"})}):null,jsx("div",{className:"fk:h-full fk:overflow-auto",onScroll:$e,ref:d,children:R})]})]})}function Ol(){let{api:t,projectId:n}=x(),o=useNavigate();return !n||!t?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(b$3,{children:[jsx(c,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:"New Automation"})})]}),jsx(b$2,{asChild:true,className:"fk:shrink-0 fk:w-fit",size:"sm",variant:"ghost",children:jsxs(Link,{relative:"path",to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:jsx(Fn,{api:t,mode:"create",projectId:n,onSaved:()=>o("..",{relative:"path"})})})})]})}function ql(){let{api:t,projectId:n}=x(),{automationId:o}=useParams(),i=useNavigate(),[l,k]=useTransition(),f$1=b(),{data:g$1,mutate:c$1}=De(n&&o?g(n).automation(o):null,f);if(!n||!t||!o)return jsx(Z,{children:"Select an automation."});if(!g$1?.automation)return jsx(Z,{children:"Loading automation..."});let p=t,d=Sa(g$1.automation)&&f$1,v$1=o;function C(){d&&k(async()=>{let T=await p.runAutomation(v$1);if(T.success&&T.runId){i(`runs/${T.runId}`);return}await c$1();});}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:g$1.automation.name})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-center fk:justify-between fk:gap-3 fk:pr-4",children:[jsx(b$2,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"../automations",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(ha,{value:"settings",children:jsxs(ia,{children:[jsx(ja,{className:"text-xs",value:"settings",children:"Settings"}),jsx(ja,{className:"text-xs",value:"runs",children:jsx(Link,{to:"runs",children:"Runs"})})]})}),jsx(na$1,{disabled:!f$1,children:jsxs(b$2,{disabled:l||!d,size:"sm",onClick:C,children:[l?jsx(LoaderCircle,{className:"fk:mr-2 fk:size-4 fk:animate-spin"}):jsx(Play,{className:"fk:mr-2 fk:size-4"}),"Run now"]})})]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:jsx(Fn,{api:t,automation:g$1.automation,mode:"edit",projectId:n,onSaved:T=>{T?c$1({automation:T},{revalidate:false}):c$1();}})})})]})}var nn=25;function Jl(){let{api:t,projectId:n}=x(),{automationId:o}=useParams(),i=useNavigate(),[l,k]=useTransition(),{data:f$1}=De(n&&o?g(n).automation(o):null,f),g$1=(B,U)=>!n||!o||U&&U.hasMore===false?null:g(n).automationRuns(o,B*nn,nn),{data:c$1,isLoading:p,mutate:d,setSize:v$1,size:C}=It(g$1,f),T=b();if(!n||!t||!o)return jsx(Z,{children:"Select an automation to view runs."});let j=t,A=Sa(f$1?.automation)&&T,x$1=o;function b$1(){A&&k(async()=>{let B=await j.runAutomation(x$1);if(B.success&&B.runId){i(B.runId);return}await d();});}let P=c$1?.flatMap(B=>B.runs)??[],S=c$1?.[c$1.length-1]?.hasMore??false,_=c$1!==void 0&&C>c$1.length;function M(){v$1(B=>B+1);}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:f$1?.automation.name??"Automation"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-center fk:justify-between fk:gap-3 fk:pr-4",children:[jsx(b$2,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"../automations",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(ha,{value:"runs",children:jsxs(ia,{children:[jsx(ja,{className:"text-xs",value:"settings",children:jsx(Link,{relative:"path",to:"..",children:"Settings"})}),jsx(ja,{className:"text-xs",value:"runs",children:"Runs"})]})}),jsx(na$1,{disabled:!T,children:jsxs(b$2,{disabled:l||!A,size:"sm",onClick:b$1,children:[l?jsx(LoaderCircle,{className:"fk:mr-2 fk:size-4 fk:animate-spin"}):jsx(Play,{className:"fk:mr-2 fk:size-4"}),"Run now"]})})]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[jsx(Aa,{basePath:".",isLoading:p,runs:P}),S&&!_?jsx(an,{onVisible:M}):null,_?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more runs..."})]}):null]})})]})}function an({onVisible:t}){let n=useRef(null),o=useRef(t);return o.current=t,useEffect(()=>{let i=n.current;if(!i)return;let l=new IntersectionObserver(k=>{k.some(f=>f.isIntersecting)&&o.current();});return l.observe(i),()=>{l.disconnect();}},[]),jsx("div",{className:"fk:h-px",ref:n})}function jn(){return jsx($,{children:jsx(ba$1,{children:Array.from({length:5},(t$1,n)=>jsxs(da$1,{children:[jsx(fa,{className:"fk:py-2",children:jsx(t,{className:"fk:h-4 fk:w-28"})}),jsx(fa,{children:jsx(t,{className:"fk:h-4 fk:w-20"})}),jsx(fa,{children:jsx(t,{className:"fk:h-4.75 fk:w-16"})}),jsx(fa,{children:jsx(t,{className:"fk:h-4 fk:w-full fk:max-w-md"})})]},n))})})}function Aa({basePath:t,isLoading:n=false,runs:o}){return n?jsx(jn,{}):o.length===0?jsx(Z,{children:"No runs found."}):jsx($,{children:jsx(ba$1,{children:o.map(i=>jsxs(da$1,{children:[jsx(fa,{className:"fk:py-2",children:jsx(Link,{className:"fk:font-medium hover:fk:underline",to:`${t}/${i.id}`,children:formatDistance(new Date(i.startedAt),new Date,{addSuffix:true})})}),jsx(fa,{className:"fk:text-muted-foreground",children:i.triggerType}),jsx(fa,{children:jsx(Ca,{status:i.status})}),jsx(fa,{className:"fk:max-w-md fk:truncate fk:text-muted-foreground",children:i.summary??""})]},i.id))})})}function Ul(){let{projectId:t$1}=x(),[n,o]=useState("team"),i=(x,b)=>!t$1||b&&!b.history.hasMore?null:g(t$1).runHistory(n,x*nn,nn),{data:l,isLoading:k,setSize:f$1,size:g$1}=It(i,f),c$1=l?.[0]?.history.metrics,p=l?.flatMap(x=>x.history.runs)??[],v=l?.[l.length-1]?.history.hasMore??false,C=l!==void 0&&g$1>l.length;if(!t$1)return jsx(Z,{children:"Select a project to view run history."});function T(){f$1(x=>x+1);}function j(x){!gi(x)||x===n||o(x);}let A=null;return k?A=jsx("div",{className:"fk:mb-6 fk:grid fk:shrink-0 fk:gap-3 fk:grid-cols-4 fk:pr-4",children:Array.from({length:4},(x,b)=>jsxs("div",{className:"fk:rounded-md fk:bg-muted/60 fk:p-4 fk:corner-squircle",children:[jsx(t,{className:"fk:h-4 fk:w-24"}),jsx(t,{className:"fk:mt-2 fk:h-8 fk:w-12"})]},b))}):c$1&&(A=jsxs("div",{className:"fk:mb-6 fk:grid fk:shrink-0 fk:gap-3 fk:grid-cols-4 fk:pr-4",children:[jsx(tn,{title:"Successful 24h",value:c$1.successful24h}),jsx(tn,{title:"Failed 24h",value:c$1.failed24h}),jsx(tn,{title:"Successful 7d",value:c$1.successful7d}),jsx(tn,{title:"Failed 7d",value:c$1.failed7d})]})),jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col",children:[jsxs("div",{className:"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(ha,{value:n,onValueChange:j,children:jsxs(ia,{children:[jsx(ja,{value:"team",children:"Team"}),jsx(ja,{value:"mine",children:"Mine"})]})})]}),A,jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[jsx(Aa,{basePath:"../automations",isLoading:k,runs:p.map(x=>({...x,id:`${x.automationId}/runs/${x.id}`}))}),v&&!C?jsx(an,{onVisible:T}):null,C?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more runs..."})]}):null]})})]})}var xa=25;function Si(t){return t==="pending"||t==="all"}function Hl(){let{api:t,projectId:n}=x(),[o,i]=useState("pending"),[l,k]=useState(null),f$1=(M,B)=>!n||B&&!B.hasMore?null:g(n).approvals({limit:xa,offset:M*xa,status:o==="pending"?"pending":void 0}),{data:g$1,isLoading:c$1,mutate:p,setSize:d$1,size:v}=It(f$1,f,{refreshInterval:3e4}),C=g$1?.flatMap(M=>M.approvals)??[],T=g$1?.[0]?.pendingCount??0,j=g$1?.[0],A=a();useEffect(()=>{j&&A(j);},[j,A]);let b=g$1?.[g$1.length-1]?.hasMore??false,P=g$1!==void 0&&v>g$1.length,F=C.find(M=>M.id===l)??null;if(useEffect(()=>{l===null||F!==null||c$1||g$1===void 0||k(null);},[g$1,c$1,F,l]),!n||!t)return jsx(Z,{children:"Select a project to view approvals."});function S(){d$1(M=>M+1);}function _(M){!Si(M)||M===o||(d$1(1),i(M));}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col",children:[jsxs("div",{className:"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(ha,{value:o,onValueChange:_,children:jsxs(ia,{children:[jsxs(ja,{value:"pending",children:["Pending",T>0?` (${T.toString()})`:""]}),jsx(ja,{value:"all",children:"All"})]})})]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[c$1?jsx(jn,{}):C.length===0?jsx(Z,{children:o==="pending"?"No proposals are waiting for approval.":"No approvals found."}):jsx($,{children:jsx(ba$1,{children:C.map(M=>jsxs(da$1,{className:"fk:cursor-pointer",onClick:()=>k(M.id),children:[jsx(fa,{children:jsx(b$4,{status:M.status})}),jsx(fa,{className:"fk:font-medium",children:M.operationsSummary}),jsx(fa,{className:"fk:text-muted-foreground",children:M.automationName}),jsx(fa,{className:"fk:text-muted-foreground",children:formatDistance(new Date(M.requestedAt),new Date,{addSuffix:true})}),jsx(fa,{onClick:B=>B.stopPropagation(),children:M.chatId?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../agent/chats/${M.chatId}`,children:"View chat"}):M.automationId&&M.runId?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../automations/${M.automationId}/runs/${M.runId}`,children:"View run"}):null})]},M.id))})}),b&&!P?jsx(an,{onVisible:S}):null,P?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more approvals..."})]}):null]})}),F?jsx(d,{api:t,approval:F,onClose:()=>k(null),onDecided:()=>{p();}},`${F.id}-${F.status}`):null]})}var Na=25,wi={attention:"fk:border-none fk:bg-amber-500/20 fk:text-amber-600 fk:corner-squircle",failure:"fk:border-none fk:bg-destructive/15 fk:text-destructive fk:corner-squircle",neutral:"fk:corner-squircle"};function Ai(t){return t==="needs_action"||t==="all"}function Ii(){let{mode:t}=f$4(),[n,o]=useState(()=>typeof Notification>"u"?"unsupported":Notification.permission);return n!=="default"?null:jsxs("div",{className:"fk:mb-3 fk:flex fk:items-center fk:gap-3 fk:rounded-md fk:border fk:p-3 fk:text-sm fk:corner-squircle",children:[jsx(BellIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}),jsx("span",{className:"fk:flex-1",children:"Get a desktop notification when something needs you while Studio is in the background."}),jsx(b$2,{size:"sm",variant:"outline",onClick:()=>{Notification.requestPermission().then(i=>{o(i),i==="granted"&&t==="hosted"&&i$1().catch(()=>{});});},children:"Turn on"})]})}function Xl(){let{api:t,projectId:n}=x(),o=useNavigate(),i=c$1(),[l,k]=useState("needs_action"),[f$1,g$1]=useState(()=>new Set),c$3=a(),p=(S,_)=>!n||_&&!_.hasMore?null:g(n).activity({filter:l,limit:Na,offset:S*Na}),{data:d,isLoading:v,mutate:C,setSize:T,size:j}=It(p,f,{refreshInterval:3e4}),A=useMemo(()=>d?.flatMap(S=>S.items)??[],[d]),x$1=d?.[d.length-1]?.hasMore??false,b=d!==void 0&&j>d.length;if(useEffect(()=>{let S=A.filter(_=>_.state==="unread").map(_=>_.id);!t||!i||S.length===0||(g$1(_=>new Set([..._,...S])),t.markActivityRead(S).then(()=>c$3()));},[t,i,A,c$3]),!n||!t)return jsx(Z,{children:"Select a project to view activity."});function P(S){!Ai(S)||S===l||(T(1),k(S));}function F(S){t&&t.setActivityItemState(S.id,"dismissed").catch(_=>{qa$1.error(_ instanceof Error?_.message:"Unable to dismiss this item.");}).finally(()=>{C();});}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col",children:[jsxs("div",{className:"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(ha,{value:l,onValueChange:P,children:jsxs(ia,{children:[jsx(ja,{value:"needs_action",children:"Needs attention"}),jsx(ja,{value:"all",children:"All"})]})}),jsx(jo,{})]}),jsx(Ii,{}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[v?jsx(jn,{}):A.length===0?jsx(Z,{children:l==="needs_action"?"Nothing needs your attention.":"No activity yet."}):jsx($,{children:jsx(ba$1,{children:A.map(S=>{let _=c$2(S),M=a$1(S),B=b$5(S),U=e$2(S),w=d$1(S);return jsxs(da$1,{className:"fk:cursor-pointer",onClick:()=>o(S.id),children:[jsx(fa,{className:"fk:w-4 fk:pr-0",children:f$1.has(S.id)||S.state==="unread"?jsx("span",{"aria-label":"Unread",className:"fk:block fk:size-2 fk:rounded-full fk:bg-primary"}):null}),jsxs(fa,{children:[jsx("div",{className:"fk:font-medium",children:S.title}),S.body?jsx("div",{className:"fk:text-xs fk:text-muted-foreground",children:S.body}):null]}),jsx(fa,{children:_?jsx(b$1,{className:wi[w],variant:w==="neutral"?"outline":"default",children:_}):null}),jsx(fa,{className:"fk:whitespace-nowrap fk:text-muted-foreground",children:formatDistance(new Date(S.createdAt),new Date,{addSuffix:true})}),jsx(fa,{className:"fk:whitespace-nowrap",onClick:H=>H.stopPropagation(),children:M&&B?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../${M}`,children:B}):null}),jsx(fa,{className:"fk:w-8",onClick:H=>H.stopPropagation(),children:U?null:jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(b$2,{"aria-label":"Dismiss",size:"icon",variant:"ghost",onClick:()=>F(S),children:jsx(XIcon,{className:"fk:size-4"})})}),jsx(e$1,{children:"Dismiss"})]})})]},S.id)})})}),x$1&&!b?jsx(an,{onVisible:()=>{T(S=>S+1);}}):null,b?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more activity..."})]}):null]})})]})}function Kl(){let{api:t$1,projectId:n}=x(),{itemId:o=""}=useParams(),i=a(),{data:l,error:k,isLoading:f$1,mutate:g$1}=De(n&&o?g(n).activityItem(o):null,f),c$2=l?.item,p=c$2?.approvalId??null,{data:d,mutate:v$1}=De(n&&p?g(n).approval(p):null,f),C=c$2?.state==="unread",T=c$1();if(useEffect(()=>{!t$1||!C||!T||t$1.markActivityRead([o]).then(()=>{g$1(),i();});},[t$1,C,T,o,g$1,i]),!n||!t$1)return jsx(Z,{children:"Select a project to view activity."});let j=c$2?a$1(c$2):null,A=c$2?b$5(c$2):null,x$1;return k?x$1=jsx(Z,{children:"This activity item no longer exists."}):f$1||!c$2?x$1=jsxs("div",{className:"fk:flex fk:flex-col fk:gap-3",children:[jsx(t,{className:"fk:h-4 fk:w-64"}),jsx(t,{className:"fk:h-32 fk:w-full"})]}):x$1=jsxs("div",{className:"fk:flex fk:flex-col fk:gap-6",children:[jsxs("div",{className:"fk:text-sm fk:text-muted-foreground",children:[c$2.body?`${c$2.body} \xB7 `:"",formatDistance(new Date(c$2.createdAt),new Date,{addSuffix:true})]}),d?jsx(c$3,{api:t$1,approval:d.approval,chat:d.approval.chatId!==null,onDecided:()=>{g$1(),v$1(),i();}},`${d.approval.id}-${d.approval.status}`):p?jsx(t,{className:"fk:h-32 fk:w-full"}):null]}),jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:c$2?.title??"Activity"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:justify-between fk:gap-3 fk:pr-4",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(b$2,{asChild:true,"aria-label":"Back to Activity",size:"icon",variant:"ghost",children:jsx(Link,{relative:"path",to:"..",children:jsx(ArrowLeft,{className:"fk:size-4"})})})}),jsx(e$1,{children:"Back to Activity"})]}),j&&A?jsx(b$2,{asChild:true,size:"sm",variant:"outline",children:jsx(Link,{to:`../${j}`,children:A})}):null]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:x$1})})]})}function tn({title:t,value:n}){return jsxs("div",{className:"fk:rounded-md fk:bg-muted/60 fk:p-4 fk:corner-squircle",children:[jsx("div",{className:"fk:text-sm fk:text-muted-foreground",children:t}),jsx("div",{className:"fk:mt-1 fk:text-2xl fk:font-medium",children:n.toLocaleString()})]})}function Wl(){let{api:t,projectId:n}=x(),{automationId:o,runId:i}=useParams(),{data:l,mutate:k}=De(n&&i?g(n).run(i):null,f,{refreshInterval:P=>!P?.run||C(P.run.status)?0:y}),{data:f$1}=De(n&&o?g(n).automation(o):null,f),[g$1,c$1]=useTransition(),[p,d]=useState(false);if(useEffect(()=>{d(false);},[i]),!n||!t||!o||!i)return jsx(Z,{children:"Select a run."});let v$1=t,C$1=i,T=l?.run,j=T?.status==="running"&&!p;function A(){c$1(async()=>{await v$1.cancelRun(C$1),await k();});}function x$1(){d(true),k();}function b(){k();}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(O,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:f$1?.automation.name??"Automation"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-start fk:justify-between fk:gap-3 fk:pr-4",children:[jsxs("div",{children:[jsx(b$2,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{relative:"path",to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Runs"]})}),jsxs("div",{className:"fk:mt-4 fk:flex fk:flex-wrap fk:items-center fk:gap-2",children:[jsx("h2",{className:"fk:text-sm fk:font-medium",children:T?`Run from ${format(new Date(T.startedAt),"PPpp")}`:"Loading run..."}),T?jsx(Ca,{status:T.status}):null]})]}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[T&&C(T.status)?jsx(b$2,{asChild:true,size:"sm",variant:"outline",children:jsx("a",{href:v$1.getTranscriptUrl(C$1),rel:"noreferrer",target:"_blank",children:"Transcript"})}):null,j?jsx(b$2,{disabled:g$1,size:"sm",variant:"destructive",onClick:A,children:g$1?"Cancelling...":"Cancel run"}):null]})]}),jsxs(ab,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:[jsx(bb,{className:"fk:gap-0 fk:p-0",children:jsx("div",{className:"fk:mx-auto fk:w-full fk:max-w-5xl fk:pb-6 fk:pr-4",children:T?jsx(Mi,{api:t,run:T,onRunUpdated:b,onStreamFinished:x$1}):jsx(Z,{children:"Loading run..."})})}),jsx(db,{})]})]})}function Pi(t){return t==="unavailable"?"No replay events were recorded.":t==="error"?"Unable to load run replay.":"Loading run replay..."}function Mi({api:t,onRunUpdated:n,onStreamFinished:o,run:i$1}){let{projectId:l}=x(),{workflowRunId:k}=i$1,f$1=k?t.getStreamUrl(k):"",[g$1,c]=useState(0),[p,d]=useState(false),[v,C$1]=useState([]),[T,j]=useState({}),A=useRef(null),{message:x$1,status:b}=D(f$1,{decidedApprovals:T,recordStatus:i$1.status,resumeToken:g$1,suppressApprovalPause:p}),P=useMemo(()=>x$1?[x$1]:[],[x$1]),F=B(P),S=useRef(n);S.current=n;let _=useRef(o);_.current=o;let M=useMemo(()=>({onApprovalDecided:(R,N)=>{R&&N&&N!=="pending"&&j(E=>({...E,[R]:N})),!(R&&A.current===R)&&(R&&(A.current=R),d(true),c(E=>E+1),S.current?.());}}),[]),B$1=!p&&i$1.status!=="running"&&!C(i$1.status)&&(b==="paused"||i$1.status==="awaiting_approval"||g$2(x$1)),U=a(),w=C(i$1.status);useEffect(()=>{(B$1||w)&&U();},[B$1,U,w]);let H$1=g$2(x$1),$=B$1&&!H$1&&l!=null,{data:he}=De($&&l?g(l).approvals({limit:25,offset:0,runId:i$1.id,status:"pending"}):null,f,{refreshInterval:y}),q=useMemo(()=>new Set(h$1(x$1)),[x$1]),be=v.filter(R=>!q.has(R.id)),Be=!C(i$1.status)&&(b==="streaming"||b==="paused"),me=F.length>0||be.length>0||Be;if(useEffect(()=>{c(0),d(false),A.current=null,C$1([]),j({});},[i$1.id]),useEffect(()=>{let R=he?.approvals;R?.length&&C$1(N=>{let E=new Map(N.map(ke=>[ke.id,ke]));for(let ke of R)E.set(ke.id,ke);return [...E.values()]});},[he]),useEffect(()=>{C$1(R=>{if(R.length===0)return R;let N=R.filter(E=>!q.has(E.id));return N.length===R.length?R:N});},[q]),useEffect(()=>{if(!p)return;if(i$1.status==="running"){d(false);return}if(i$1.status!=="awaiting_approval")return;let R=i(x$1),N=A.current;R.length===0||N===null||R.every(E=>E!==N)&&d(false);},[x$1,i$1.status,p]),useEffect(()=>{b==="finished"&&_.current?.();},[b]),useEffect(()=>{b==="paused"&&S.current?.();},[b]),useEffect(()=>{if(i$1.status!=="awaiting_approval")return;let R=window.setInterval(()=>{S.current?.();},y);return ()=>{window.clearInterval(R);}},[i$1.status]),!k)return jsx(Z,{children:"The run has not started streaming yet."});let Ce=Be||B$1&&b!=="finished"&&b!=="error",ze=x$1?.parts[x$1.parts.length-1],je=ze?.type==="text"&&ze.state==="streaming",We=B$1?"Awaiting approval":f$2(x$1)??"Thinking",Ge=B$1||!je,$e=Pi(b);return jsx(z.Provider,{value:M,children:jsxs("div",{className:"fk:space-y-4",children:[i$1.status==="failed"&&i$1.error?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-4 fk:text-sm fk:corner-squircle",children:i$1.summary??i$1.error}):null,b==="unavailable"?jsx("div",{className:"fk:rounded-md fk:border fk:border-amber-500/30 fk:bg-amber-500/5 fk:p-4 fk:text-sm fk:corner-squircle",children:"The workflow replay is no longer available. Generated artifacts may still be available below."}):null,b==="error"&&!me?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-4 fk:text-sm fk:corner-squircle",children:"Failed to load the run stream. Try reloading the page."}):null,me?jsxs("div",{className:"fk:space-y-5 fk:rounded-md fk:bg-background fk:corner-squircle",children:[F.map(R=>jsx(Ri,{api:t,message:R},R.id)),be.map(R=>jsx(I,{api:t,message:E(R)},R.id)),Ce?jsx(H,{label:We,visible:Ge}):null]}):jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:rounded-md fk:border fk:border-dashed fk:p-8 fk:font-mono fk:text-sm fk:text-muted-foreground fk:corner-squircle",children:[b==="unavailable"||b==="error"?jsx(TriangleAlertIcon,{className:"fk:size-4"}):jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:$e})]})]})})}function Ri({api:t,message:n}){let o=n.role==="user",i=n.parts.filter(l=>!e$3(l));return i.length===0?null:jsxs("div",{className:o?"fk:ml-auto fk:w-full fk:max-w-[70%]":"fk:w-full fk:min-w-0",children:[jsx("div",{className:"fk:mb-2 fk:flex fk:items-center fk:gap-2 fk:font-mono fk:text-sm fk:font-medium fk:text-primary",children:o?jsxs(Fragment,{children:[jsx(ZapIcon,{className:"fk:ml-auto fk:size-4"}),jsx("span",{children:"Trigger"})]}):jsxs(Fragment,{children:[jsx(BotIcon,{className:"fk:size-4"}),jsxs("span",{children:["Agent",n.metadata?.model?` (${n.metadata.model})`:""]})]})}),jsx("div",{className:"fk:space-y-8 fk:min-w-0",children:i.map((l,k)=>jsx(F,{api:t,part:l,partIndex:k,parts:i},k))})]})}
|
|
4
|
+
export{Kl as ActivityItemPage,Xl as ActivityPage,Hl as ApprovalsPage,ql as AutomationDetailPage,Vl as AutomationsPage,Ol as CreateAutomationPage,Wl as RunDetailPage,Ul as RunHistoryPage,Jl as RunsPage};//# sourceMappingURL=pages-INCA54HE.js.map
|
|
5
|
+
//# sourceMappingURL=pages-INCA54HE.js.map
|