PageSourceSearch

https://zandy.ai/assets/composer-bundle-DJeQLkP-.js

js zandy.ai collected 2026-10-05 13:24:04 UTC 70,866 bytes, 1 lines download raw bytes

1var e=Object.defineProperty,s=(s,t,r)=>((s,t,r)=>t in s?e(s,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[t]=r)(s,"symbol"!=typeof t?t+"":t,r);import{j as t,cl as r,aa as a,J as n,o as l,bU as o,bB as i,bE as d,cm as c,bO as m,b9 as x,X as u,n as p,ch as h,cn as g,w as f,aQ as j,a_ as b,av as v,co as y,aY as N,e as w,U as k,b2 as C,bK as _,W as S,cp as T,Q as P,E as M,aV as A,aU as O,a as E,cq as F,z as I,H as L,cr as U}from"./ui-CUzbSzx5.js";import{r as R}from"./vendor-CPzIg6dU.js";import{c as D,u as $,b as z,L as H}from"./router-DEhUawKM.js";import{u as q,a as B,b as V,c as K,g as J,f as Q,C as W,d as Z,V as Y,e as G,h as X,i as ee,j as se,k as te}from"./useComposerVoiceSession-BaRz9wbG.js";import{a as re,b as ae,c as ne,d as le}from"./useComposerThreads-DbLDfAge.js";import{f as oe,T as ie,o as de,p as ce,B as me,q as xe,J as ue,c as pe,u as he,b as ge,A as fe,w as je,x as be,y as ve,z as ye,C as Ne,D as we,E as ke,t as Ce,s as _e}from"./index-Dmu1cEKX.js";import{S as Se,a as Te,b as Pe,c as Me,d as Ae}from"./sheet-C0xCYVtb.js";import{B as Oe}from"./badge-DTxAHISX.js";import{S as Ee}from"./switch-BvbAMTvq.js";import{S as Fe}from"./separator-oQlYjJaq.js";import{D as Ie,a as Le,b as Ue,d as Re}from"./dropdown-menu-hR-pNmva.js";import{I as De}from"./input-D6U5oJf9.js";import{f as $e,F as ze}from"./dates-BJ73i3Cl.js";import{u as He}from"./useMcpServers-BcIXPLLA.js";import{D as qe,a as Be,b as Ve,c as Ke,f as Je,d as Qe}from"./dialog-CaWgGF_c.js";import{L as We}from"./label-DLKSIsWw.js";import{a as Ze,u as Ye,b as Ge}from"./query-DzXmn2oi.js";import{T as Xe}from"./textarea-O_j_WMLn.js";import{S as es,a as ss,b as ts,c as rs,d as as}from"./select-BN8yl-mz.js";import"./supabase-CwQXPgqN.js";import"./ComposerVoiceInput-BWZSkY9_.js";import"./useVoiceCallMode-AoCRQ4VU.js";import"./useCompanySettings-CEMYwrsq.js";import"./useUserProfile-BF29pxaC.js";import"./clerk-DdMheoFF.js";import"./AnimatedNumber-BNWqwN8m.js";import"./motion-DtGpigtx.js";import"./checkbox-_jNau4ze.js";import"./BarChart-BLQx9EoZ.js";import"./tiny-invariant-DDIfS17J.js";import"./string-guOtgHAX.js";import"./linear-ReRuFhd6.js";import"./init-DLRA0X12.js";import"./defaultLocale-Cz8hFv87.js";import"./time-CrrB8Bxw.js";import"./band--TEbrEV-.js";import"./ordinal-B3SZQd5H.js";import"./LineChart-Cr0O449_.js";import"./AreaChart-BZ1bl0I2.js";import"./CartesianGrid-DNsObWnY.js";import"./MarkdownWithMermaid-BMH3YLC2.js";import"./markdown-renderer-CAgDkUdT.js";import"./purify.es-XbFm06Uh.js";import"./prism-markdown-C-n-YvHI.js";import"./InlineMermaidDiagram-hCMqsVhH.js";import"./useMermaidRenderer-00mGG108.js";import"./popover-BKH44zXC.js";import"./index-GH8Z6mWF.js";const ns=({enabled:e,onClick:s})=>{const{isSuperAdmin:a}=oe();return a?t.jsx(ie,{delayDuration:300,children:t.jsxs(de,{children:[t.jsx(ce,{asChild:!0,children:t.jsxs(me,{variant:"ghost",size:"icon",className:"h-7 w-7 relative",onClick:s,"aria-label":"Open Composer debug panel",children:[t.jsx(r,{className:"h-4 w-4 "+(e?"text-amber-600 dark:text-amber-400":"text-muted-foreground")}),e&&t.jsx("span",{className:"absolute top-0.5 right-0.5 h-1.5 w-1.5 rounded-full bg-amber-500 animate-pulse"})]})}),t.jsx(xe,{side:"bottom",className:"text-xs",children:e?"Debug mode on — open panel":"Open Composer debug"})]})}):null},ls={composer:"Composer",crm:"CRM",mcp:"MCP"},os={natural:"Natural completion",cap_count:"Step limit reached",cap_time:"Time limit reached",halted:"Halted for confirmation",error:"Error"},is={natural:"bg-emerald-500/15 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-300",cap_count:"bg-amber-500/15 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300",cap_time:"bg-amber-500/15 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300",halted:"bg-blue-500/15 text-blue-700 dark:bg-blue-500/20 dark:text-blue-300",error:"bg-destructive/15 text-destructive"},ds=e=>null==e?"—":e<1e3?`${e} ms`:`${(e/1e3).toFixed(2)} s`,cs=(e,s=400)=>{let t;try{t="string"==typeof e?e:JSON.stringify(e,null,2)}catch{t=String(e)}return t.length>s?`${t.slice(0,s)}…`:t},ms=({title:e,count:s,defaultOpen:r=!1,children:l})=>
1{const[o,i]=R.useState(r);return t.jsxs("div",{className:"rounded-md border border-border/60 bg-card",children:[t.jsx("button",{type:"button",onClick:()=>i(e=>!e),className:"w-full flex items-center justify-between px-3 py-2 text-sm font-medium hover:bg-muted/50 transition-colors",children:t.jsxs("span",{className:"flex items-center gap-2",children:[o?t.jsx(a,{className:"h-3.5 w-3.5"}):t.jsx(n,{className:"h-3.5 w-3.5"}),e,null!=s&&t.jsxs("span",{className:"text-xs text-muted-foreground font-normal",children:["(",s,")"]})]})}),o&&t.jsx("div",{className:"px-3 pb-3 text-xs",children:l})]})},xs=({value:e,label:s})=>{const[r,a]=R.useState(!1);return t.jsxs(me,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:async()=>{try{await navigator.clipboard.writeText(e),a(!0),ue.success(`${s} copied`),setTimeout(()=>a(!1),1500)}catch{ue.error("Copy failed")}},children:[r?t.jsx(l,{className:"h-3 w-3 mr-1"}):t.jsx(o,{className:"h-3 w-3 mr-1"}),"Copy"]})},us=({step:e,toolResults:s})=>{const r=s.filter(s=>s.step===e.step),a="complete"===e.status?"bg-emerald-500/15 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-300":"running"===e.status?"bg-blue-500/15 text-blue-700 dark:bg-blue-500/20 dark:text-blue-300":"halted_for_confirmation"===e.status||"limit_reached"===e.status?"bg-amber-500/15 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300":"bg-destructive/15 text-destructive";return t.jsxs("div",{className:"rounded-md border border-border/60 bg-card p-3 space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[t.jsxs("span",{className:"font-semibold",children:["Step ",e.step]}),t.jsxs("span",{className:"text-muted-foreground",children:["/ ",e.max]}),t.jsx(Oe,{variant:"outline",className:`text-[10px] py-0 px-1.5 h-4 ${a}`,children:e.status})]}),t.jsx("span",{className:"text-[10px] text-muted-foreground",children:ds(e.elapsedMs)})]}),e.errorMessage&&t.jsx("div",{className:"rounded bg-destructive/10 px-2 py-1 text-[11px] text-destructive",children:e.errorMessage}),r.length>0?t.jsx("div",{className:"space-y-1.5",children:r.map(e=>t.jsxs("div",{className:"rounded bg-muted/50 px-2 py-1.5 text-[11px] space-y-1",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("code",{className:"font-mono text-foreground",children:e.toolName}),t.jsx("span",{className:"text-muted-foreground",children:e.serverName})]}),e.args&&Object.keys(e.args).length>0&&t.jsxs("details",{className:"text-muted-foreground",children:[t.jsx("summary",{className:"cursor-pointer hover:text-foreground",children:"args"}),t.jsx("pre",{className:"mt-1 whitespace-pre-wrap font-mono text-[10px] bg-background/80 p-1.5 rounded overflow-x-auto",children:cs(e.args,1500)})]}),(e.result||e.error)&&t.jsxs("details",{className:"text-muted-foreground",children:[t.jsx("summary",{className:"cursor-pointer hover:text-foreground",children:e.error?"error":"result"}),t.jsx("pre",{className:"mt-1 whitespace-pre-wrap font-mono text-[10px] bg-background/80 p-1.5 rounded overflow-x-auto",children:cs(e.error??e.result??"",2e3)})]})]},e.toolId))}):t.jsx("div",{className:"text-[10px] text-muted-foreground italic",children:"No tool calls in this step."})]})},ps=({open:e,onOpenChange:s,messages:r,debugEnabled:a,onDebugEnabledChange:n})=>{const l=R.useMemo(()=>(e=>{const s=e.filter(e=>"assistant"===e.role);return[...s].reverse().find(e=>e.debug)??s[s.length-1]})(r),[r]),o=null==l?void 0:l.debug,i=(null==l?void 0:l.steps)??[],d=(null==l?void 0:l.toolResults)??[],c=R.useMemo(()=>{var e;const s=(null==o?void 0:o.availableTools)??[],t={composer:[],crm:[],mcp:[]};for(const r of s)(t[e=r.group]??(t[e]=[])).push(r);return t},[null==o?void 0:o.availableTools]);return t.jsx(Se,{open:e,onOpenChange:s,children:t.jsxs(Te,{side:"right",className:"w-full sm:max-w-xl overflow-y-auto",children:[t.jsxs(Pe,{className:"space-y-2",children:[t.jsxs(Me,{className:"flex items-center justify-between",children:[t.jsx("span",{children:"Composer Debug"}),t.jsx(Oe,{variant:"outline",className:"text-[10px] bg-amber-500/15 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300",children:"super-admin"})]}),t.jsx(Ae,{className:"text-xs",children:"Inspect what Zandy actually sees and does on each turn. Toggle off to stop sending the debug flag with future messages."})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between rounded-md border border-border/60 bg-card px-3 py-2",children:[t.jsxs("div",{className:"space-y-0.5",children:[t.jsx("div",{className:"text-sm font-medium",children:"Debug mode"}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:["Sends ",t.jsx("code",{className:"font-mono",children:"debug: true"})," to ",t.jsx("code",{className:"font-mono",children:"chat-with-zandy"}),"."]})]}),t.jsx(Ee,{checked:a,onCheckedChange:n})]}),!o&&t.jsx("div",{className:"mt-4 rounded-md border border-dashed border-border/60 bg-muted/30 p-4 text-center text-xs text-muted-foreground",children:a?"Send a message in Composer to capture a debug trace.":"Turn debug mode on, then send a message in Composer to capture a debug trace."}),o&&t.jsxs("div",{className:"mt-4 space-y-3",children:[t.jsxs("div",{className:"rounded-md border border-border/60 bg-card p-3 text-xs space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-muted-foreground",children:"Model"}),t.jsx("code",{className:"font-mono text-foreground",children:o.modelId??"—"})]}),t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-muted-foreground",children:"Provider"}),t.jsx("code",{className:"font-mono text-foreground",children:o.provider??"—"})]}),t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-muted-foreground",children:"History sent"}),t.jsxs("span",{children:[o.messageCount??0," messages"]})]}),t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-muted-foreground",children:"Caps"}),t.jsxs("span",{children:[o.maxSteps??"?"," steps · ",ds(o.maxTurnMs)]})]}),null!=o.elapsedMs&&t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-muted-foreground",children:"Total elapsed"}),t.jsx("span",{children:ds(o.elapsedMs)})]}),o.exitPath&&t.jsxs("div",{className:"flex items-center justify-between pt-1",children:[t.jsx("span",{className:"text-muted-foreground",children:"Exit"}),t.jsxs(Oe,{variant:"outline",className:`text-[10px] py-0 px-1.5 h-4 ${is[o.exitPath]}`,children:[os[o.exitPath],null!=o.stepsRun&&` · ${o.stepsRun} step${1===o.stepsRun?"":"s"}`]})]})]}),t.jsxs(ms,{title:"System prompt",count:o.systemPromptChars,defaultOpen:!1,children:[t.jsx("div",{className:"flex items-center justify-end mb-1",children:o.systemPrompt&&t.jsx(xs,{value:o.systemPrompt,label:"System prompt"})}),t.jsx("pre",{className:"whitespace-pre-wrap font-mono text-[11px] bg-muted/40 p-2 rounded max-h-[40vh] overflow-y-auto",children:o.systemPrompt??"(no system prompt)"})]}),t.jsxs(ms,{title:"Available tools",count:o.toolCount,defaultOpen:!1,children:[["composer","crm","mcp"].map(e=>{const s=c[e]??[];return 0===s.length?null:t.jsxs("div",{className:"mb-3 last:mb-0",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:ls[e]}),t.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["(",s.length,")"]}),"mcp"===e&&o.mcpServers&&o.mcpServers.length>0&&t.jsxs("span",{className:"text-[10px] text-muted-foreground italic",children:["via ",o.mcpServers.join(", ")
1]})]}),t.jsx("div",{className:"space-y-1",children:s.map(e=>t.jsxs("div",{className:"rounded bg-muted/40 px-2 py-1",children:[t.jsx("div",{className:"font-mono text-[11px] text-foreground",children:e.name}),e.description&&t.jsx("div",{className:"text-[10px] text-muted-foreground mt-0.5 line-clamp-2",children:e.description})]},e.name))})]},e)}),0===(o.toolCount??0)&&t.jsx("div",{className:"text-[11px] text-muted-foreground italic",children:"No tools registered."})]}),t.jsx(Fe,{}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"text-xs font-semibold flex items-center gap-2",children:[t.jsx("span",{children:"Steps"}),t.jsxs("span",{className:"text-muted-foreground font-normal",children:["(",i.length,")"]})]}),0===i.length?t.jsx("div",{className:"text-[11px] text-muted-foreground italic rounded-md border border-dashed border-border/60 p-3 text-center",children:"No tool steps were taken on this turn — the LLM answered directly."}):t.jsx("div",{className:"space-y-2",children:i.map(e=>t.jsx(us,{step:e,toolResults:d},e.step))})]})]})]})})};class hs extends R.Component{constructor(){super(...arguments),s(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("[ComposerChatView] message failed to render:",e)}render(){return this.state.hasError?t.jsx("div",{className:"rounded-lg border border-border/50 bg-muted/30 px-3 py-2 text-xs text-muted-foreground",children:"This message couldn't be displayed. The conversation continues below."}):this.props.children}}class gs extends R.Component{constructor(){super(...arguments),s(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("[ComposerChatView] conversation body failed to render:",e),this.props.onError()}render(){return this.state.hasError?this.props.fallback:this.props.children}}function fs(){const{threadId:e}=D(),s=$(),r=R.useRef(null),a=R.useRef(null),[n,o]=z(),[g]=R.useState(()=>n.get("prompt")??"");R.useEffect(()=>{if(!n.has("prompt")&&!n.has("play_id"))return;const e=new URLSearchParams(n);e.delete("prompt"),e.delete("play_id"),o(e,{replace:!0})},[]);const f=q(),{voiceCall:j,voiceLevelRef:b}=f,{messages:v,isLoading:y,threadTitle:N,sendMessage:w,stopGeneration:k,confirmAction:C,cancelAction:_,submitFormAction:S,retryAction:T}=B(e,f.composerOptions);f.bindActions({sendMessage:w,confirmAction:C,cancelAction:_}),V(f,v);const P=K(),M=J(P),A=re(),O=ae(),E=ne(),{data:F}=le(e),I=Q(),[L,U]=R.useState(!1);R.useEffect(()=>{const e=a.current;e&&e.scrollTo({top:e.scrollHeight,behavior:"smooth"})},[v]);const X=async t=>{if(e)try{const r=await E.mutateAsync({threadId:e,anchorMessageId:t,includeAnchor:!0});ue.success("Forked from message"),s(`/composer/${r}`)}catch(r){console.error("[Composer] fork failed:",r),ue.error("Failed to fork")}},ee=0===v.length;return t.jsxs("div",{"data-composer-capture-skip":!0,className:"flex flex-col flex-1 min-h-0",children:[e?t.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border/50",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[(null==F?void 0:F.parent_thread_id)&&t.jsxs(H,{to:`/composer/${F.parent_thread_id}`,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",title:"Forked from parent thread",children:[t.jsx(i,{className:"h-3 w-3"}),t.jsx("span",{children:"parent"})]}),t.jsx("h2",{className:"text-sm font-medium text-foreground/70 truncate",children:N})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(ns,{enabled:I.enabled,onClick:()=>I.setPanelOpen(!0)}),t.jsxs(Ie,{children:[t.jsx(Le,{asChild:!0,children:t.jsx(me,{variant:"ghost",size:"icon",className:"h-7 w-7",children:t.jsx(d,{className:"h-4 w-4 text-muted-foreground"})})}),t.jsxs(Ue,{align:"end",children:[t.jsxs(Re,{onClick:async()=>{if(!e)return;const s=window.prompt("Rename thread:",N);if(s&&s.trim())try{await O.mutateAsync({threadId:e,title:s.trim()}),ue.success("Thread renamed")}catch{ue.error("Failed to rename thread")}},children:[t.jsx(c,{className:"h-3.5 w-3.5 mr-2"}),"Rename"]}),t.jsxs(Re,{onClick:async()=>
1{if(e)try{await A.mutateAsync(e),s("/composer"),ue.success("Thread deleted")}catch{ue.error("Failed to delete thread")}},className:"text-destructive",children:[t.jsx(m,{className:"h-3.5 w-3.5 mr-2"}),"Delete"]})]})]})]})]}):t.jsx("div",{className:"flex items-center justify-end px-4 py-2",children:t.jsx(ns,{enabled:I.enabled,onClick:()=>I.setPanelOpen(!0)})}),t.jsx(gs,{onError:()=>U(!0),fallback:t.jsx("div",{className:"flex-1 flex items-center justify-center px-4 text-sm text-muted-foreground",children:"This conversation couldn't be displayed. Your input is preserved below."}),children:t.jsx("div",{ref:a,className:"flex-1 overflow-y-auto px-4",children:ee?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full max-w-md mx-auto text-center gap-6",children:[t.jsx(W,{size:80}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-lg font-medium text-foreground/80 mb-1",children:"Ask Zandy to do something"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Create contacts, manage campaigns, check analytics, or navigate anywhere in the app."})]}),t.jsx("div",{className:"flex flex-wrap gap-2 justify-center",children:M.map(e=>t.jsx("button",{disabled:y,onClick:()=>w(e.prompt),className:"px-3 py-1.5 text-xs rounded-full border border-border/50 text-muted-foreground\n                    hover:bg-muted/50 hover:text-foreground transition-colors disabled:opacity-50 disabled:pointer-events-none",children:e.label},e.label))})]}):t.jsxs("div",{className:"max-w-3xl mx-auto pt-8 pb-4 space-y-3",children:[v.map((s,r)=>t.jsx(hs,{children:t.jsx(Z,{message:s,onConfirm:e=>C(e),onCancel:e=>_(e),onSubmitForm:(e,s)=>S(e,s),onRetry:e=>T(e),onCardAction:e=>w(e),isStreaming:y&&r===v.length-1,onFork:e?X:void 0})},s.id)),t.jsx("div",{ref:r})]})})}),j.callActive&&t.jsx(Y,{state:j.voiceState,levelRef:b,errorMessage:j.micError,onRetry:j.retryMic,onEnd:f.endCall}),t.jsx("div",{className:"border-t border-border/50 bg-background px-4 py-3",children:t.jsxs("div",{className:"max-w-3xl mx-auto space-y-2",children:[j.pendingVoice&&t.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-accent/40 bg-accent/5 px-3 py-2",children:[t.jsx(x,{className:"h-4 w-4 text-accent shrink-0"}),t.jsx("p",{className:"text-sm flex-1 min-w-0 truncate",children:j.pendingVoice}),t.jsx(me,{size:"sm",variant:"ghost",className:"h-7 px-2",title:"Send now",onClick:()=>j.confirmPending(j.pendingVoice),children:t.jsx(l,{className:"h-4 w-4"})}),t.jsx(me,{size:"sm",variant:"ghost",className:"h-7 px-2 text-muted-foreground",title:"Discard",onClick:j.cancelPending,children:t.jsx(u,{className:"h-4 w-4"})})]}),t.jsx(G,{onSend:w,onStop:k,isLoading:y,initialValue:g,callActive:j.callActive,degraded:L,onToggleCall:()=>f.toggleCall(v.length>0)}),j.callActive&&t.jsxs("div",{className:"flex items-center justify-between gap-3 pl-1",children:[t.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:["listening"===j.voiceState&&t.jsxs(t.Fragment,{children:[t.jsx(x,{className:"h-3 w-3 text-emerald-500"})," Listening — just talk; talk over me to interrupt"]}),"transcribing"===j.voiceState&&t.jsxs(t.Fragment,{children:[t.jsx(p,{className:"h-3 w-3 animate-spin"})," Transcribing…"]}),"thinking"===j.voiceState&&t.jsxs(t.Fragment,{children:[t.jsx(p,{className:"h-3 w-3 animate-spin"})," Thinking…"]}),"speaking"===j.voiceState&&t.jsxs(t.Fragment,{children:[t.jsx(h,{className:"h-3 w-3 text-accent"})," Speaking…"]}),"off"===j.voiceState&&t.jsxs(t.Fragment,{children:[t.jsx(p,{className:"h-3 w-3 animate-spin"})," Starting mic…"]})]}),t.jsx("select",{value:j.voiceId,onChange:e=>j.changeVoice(e.target.value),title:"Zandy's speaking voice",className:"h-6 text-xs rounded-md border border-border/60 bg-background px-1.5 text-muted-foreground max-w-[180px]",children:j.voices.map(e=>t.jsx("option",{value:e.id,children:e.label},e.id))})]})]})}),t.jsx(gs,{onError:()=>U(!0),fallback:null,children:t.jsx(ps,{open:I.panelOpen,onOpenChange:I.setPanelOpen,messages:v,debugEnabled:I.enabled,onDebugEnabledChange:I.setEnabled})})]})}const js=["crm","voice","leads","cadence","social","sms","email","knowledge","meetings","memory","schedule","job","analytics","nav","system","settings"],bs={crm:"CRM",voice:"Voice",leads:"Leads",social:"Social",sms:"SMS",email:"Email",cadence:"Cadences",knowledge:"Knowledge",meetings:"Meetings",memory:"Memory",schedule:"Schedules",job:"Jobs",analytics:"Analytics",nav:"Navigation",system:"System",settings:"Settings"},vs={none:{label:"auto-execute",classes:"bg-emerald-500/15 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-300 border-emerald-500/30"},preview:{label:"preview",classes:"bg-amber-500/15 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300 border-amber-500/30"},confirm:{label:"confirm",classes:"bg-destructive/10 text-destructive dark:bg-destructive/20 dark:text-destructive border-destructive/30"}};function ys({name:e,className:s}){const r=y[e];return r?t.jsx(r,{className:s}):t.jsx(v,{className:s})}
1function Ns(){const e=$(),[s,r]=R.useState(""),[a,n]=R.useState("all"),[l,o]=R.useState(new Set),i=R.useCallback(e=>{o(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},[]),d=R.useMemo(()=>{const e=s.trim().toLowerCase();return X.filter(s=>{var t,r;return("all"===a||s.tier===a)&&(!(l.size>0&&!l.has(s.domain))&&(!e||(s.name.toLowerCase().includes(e)||s.label.toLowerCase().includes(e)||((null==(t=s.description)?void 0:t.toLowerCase().includes(e))??!1)||((null==(r=s.examplePrompt)?void 0:r.toLowerCase().includes(e))??!1))))})},[s,a,l]),c=R.useMemo(()=>{const e=new Map;for(const s of d){const t=e.get(s.domain)??[];t.push(s),e.set(s.domain,t)}return js.filter(s=>e.has(s)).map(s=>({domain:s,tools:e.get(s)}))},[d]),m=R.useCallback(s=>{if(!s.examplePrompt)return void e("/composer");const t=new URLSearchParams({prompt:s.examplePrompt});e(`/composer?${t.toString()}`)},[e]),x=d.length,p=X.length;return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"border-b border-border/40 bg-background/50 px-4 sm:px-6 py-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx("div",{className:"w-7 h-7 rounded-lg bg-primary/10 flex items-center justify-center",children:t.jsx(g,{className:"h-3.5 w-3.5 text-primary"})}),t.jsx("h1",{className:"text-lg font-semibold text-foreground",children:"Composer Tool Catalog"})]}),t.jsxs("p",{className:"text-[12px] text-muted-foreground/70 ml-9",children:[x," of ",p," tools — search and filter to discover what Composer can do."]})]}),t.jsxs("div",{className:"border-b border-border/30 bg-card/40 px-4 sm:px-6 py-3 space-y-3",children:[t.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[t.jsxs("div",{className:"flex-1 relative",children:[t.jsx(f,{className:"h-3.5 w-3.5 absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground/60"}),t.jsx(De,{type:"text",value:s,onChange:e=>r(e.target.value),placeholder:"Search by name, description, or example prompt…",className:"pl-9 h-9 text-[13px]"}),s&&t.jsx("button",{type:"button",onClick:()=>r(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground/60 hover:text-foreground","aria-label":"Clear search",children:t.jsx(u,{className:"h-3.5 w-3.5"})})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(j,{className:"h-3.5 w-3.5 text-muted-foreground/60"}),t.jsx("div",{className:"flex gap-1",children:["all","none","preview","confirm"].map(e=>t.jsx("button",{type:"button",onClick:()=>n(e),className:pe("px-2.5 py-1 text-[11px] font-medium rounded-full border transition-colors",a===e?"bg-primary text-primary-foreground border-primary":"bg-transparent text-muted-foreground border-border/40 hover:bg-muted/40"),children:"all"===e?"All":"none"===e?"Auto-execute":"preview"===e?"Preview":"Confirm"},e))})]})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[js.map(e=>t.jsx("button",{type:"button",onClick:()=>i(e),className:pe("px-2.5 py-1 text-[11px] font-medium rounded-full border transition-colors",l.has(e)?"bg-primary/10 text-primary border-primary/30":"bg-transparent text-muted-foreground border-border/40 hover:bg-muted/40"),children:bs[e]},e)),l.size>0&&t.jsx("button",{type:"button",onClick:()=>o(new Set),className:"ml-1 px-2.5 py-1 text-[11px] font-medium rounded-full text-muted-foreground hover:text-foreground transition-colors",children:"Clear domains"})]})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-4 sm:px-6 py-4 space-y-6",children:0===c.length?t.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[t.jsx("div",{className:"w-12 h-12 rounded-2xl bg-muted/40 flex items-center justify-center mb-3",children:t.jsx(f,{className:"h-5 w-5 text-muted-foreground/40"})}),t.jsx("p",{className:"text-sm font-medium text-foreground/60 mb-1",children:"No tools match"}),t.jsx("p",{className:"text-xs text-muted-foreground/50 max-w-[300px]",children:"Try a different search term or clear your filters."})]}):c.map(({domain:e,tools:s})=>t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("h2",{className:"text-[13px] font-semibold text-foreground",children:bs[e]}
1),t.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:s.length})]}),t.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2.5",children:s.map(e=>t.jsx(ws,{tool:e,onTryIt:m},e.name))})]},e))})]})}function ws({tool:e,onTryIt:s}){const r=vs[e.tier];return t.jsxs("div",{className:"rounded-xl border border-border/40 bg-card/60 p-3 hover:border-border hover:bg-card transition-colors flex flex-col gap-2",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center flex-shrink-0",children:t.jsx(ys,{name:e.icon,className:"h-4 w-4 text-primary"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h3",{className:"text-[12.5px] font-medium text-foreground leading-tight",children:e.label}),t.jsx("p",{className:"text-[10px] text-muted-foreground/60 font-mono truncate",children:e.name})]}),t.jsx(Oe,{variant:"outline",className:pe("text-[9px] uppercase tracking-wide font-medium",r.classes),children:r.label})]}),e.description&&t.jsx("p",{className:"text-[11.5px] text-muted-foreground/80 leading-relaxed line-clamp-2",children:e.description}),e.examplePrompt?t.jsxs("div",{className:"mt-auto flex items-end gap-2",children:[t.jsxs("p",{className:"flex-1 text-[10.5px] text-muted-foreground/60 italic leading-snug line-clamp-2",children:['"',e.examplePrompt,'"']}),t.jsxs(me,{type:"button",size:"sm",variant:"ghost",onClick:()=>s(e),className:"flex-shrink-0 h-6 px-2 text-[10.5px] gap-1",children:["Try it",t.jsx(b,{className:"h-3 w-3"})]})]}):t.jsx("div",{className:"mt-auto"})]})}function ks(){const e=$(),{activeCompany:s}=he(),{user:r}=ge(),[a,n]=R.useState(""),[o,i]=R.useState(null),[d,x]=R.useState(""),[p,h]=R.useState(null),{data:g=[],isLoading:j}=ee({companyId:null==s?void 0:s.id,userId:null==r?void 0:r.id}),v=se(),y=te(),C=R.useMemo(()=>{if(!a.trim())return g;const e=a.toLowerCase();return g.filter(s=>s.title.toLowerCase().includes(e)||s.prompt_text.toLowerCase().includes(e))},[g,a]),_=R.useCallback(e=>e.user_id===(null==r?void 0:r.id),[null==r?void 0:r.id]),S=R.useCallback(s=>{const t=new URLSearchParams({prompt:s.prompt_text,play_id:s.id});e(`/composer?${t.toString()}`)},[e]),T=R.useCallback(e=>{i(e.id),x(e.title)},[]),P=R.useCallback(async()=>{if(!o||!(null==s?void 0:s.id)||!(null==r?void 0:r.id))return;const e=d.trim();if(e)try{await v.mutateAsync({id:o,companyId:s.id,userId:r.id,patch:{title:e}}),i(null),x("")}catch(t){console.error("[ComposerPlays] rename failed:",t),ue.error("Rename failed.")}else ue.error("Title required.")},[o,d,null==s?void 0:s.id,null==r?void 0:r.id,v]),M=R.useCallback(async e=>{if((null==s?void 0:s.id)&&(null==r?void 0:r.id))if(_(e))try{await v.mutateAsync({id:e.id,companyId:s.id,userId:r.id,patch:{is_shared:!e.is_shared}}),ue.success(e.is_shared?"Made private":"Shared with company")}catch(t){console.error("[ComposerPlays] toggle shared failed:",t),ue.error("Failed to update sharing.")}else ue.error("Only the play owner can change sharing.")},[null==s?void 0:s.id,null==r?void 0:r.id,v,_]),A=R.useCallback(async()=>{if(p&&(null==s?void 0:s.id)&&(null==r?void 0:r.id))try{await y.mutateAsync({id:p,companyId:s.id,userId:r.id}),ue.success("Play deleted.")}catch(e){console.error("[ComposerPlays] delete failed:",e),ue.error("Delete failed.")}finally{h(null)}},[p,null==s?void 0:s.id,null==r?void 0:r.id,y]);return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"border-b border-border/40 bg-background/50 px-4 sm:px-6 py-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx("div",{className:"w-7 h-7 rounded-lg bg-primary/10 flex items-center justify-center",children:t.jsx(N,{className:"h-3.5 w-3.5 text-primary"})}),t.jsx("h1",{className:"text-lg font-semibold text-foreground",children:"Saved Plays"})]}),t.jsx("p",{className:"text-[12px] text-muted-foreground/70 ml-9",children:"Reusable Composer prompts. Run with one click, optionally share with your team."})]}),t.jsx("div",{className:"border-b border-border/30 bg-card/40 px-4 sm:px-6 py-3",children:t.jsxs("div",{className:"relative max-w-md",children:[t.jsx(f,{className:"h-3.5 w-3.5 absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground
1/60"}),t.jsx(De,{type:"text",value:a,onChange:e=>n(e.target.value),placeholder:"Search plays…",className:"pl-9 h-9 text-[13px]"}),a&&t.jsx("button",{type:"button",onClick:()=>n(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground/60 hover:text-foreground","aria-label":"Clear search",children:t.jsx(u,{className:"h-3.5 w-3.5"})})]})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-4 sm:px-6 py-4",children:j?t.jsx("p",{className:"text-center text-sm text-muted-foreground/60 py-12",children:"Loading plays…"}):0===C.length?t.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[t.jsx("div",{className:"w-12 h-12 rounded-2xl bg-muted/40 flex items-center justify-center mb-3",children:t.jsx(N,{className:"h-5 w-5 text-muted-foreground/40"})}),t.jsx("p",{className:"text-sm font-medium text-foreground/60 mb-1",children:0===g.length?"No plays yet":"No plays match"}),t.jsx("p",{className:"text-xs text-muted-foreground/50 max-w-[320px]",children:0===g.length?"Save your favourite Composer prompts from the chat input to re-run them with one click.":"Try a different search term."})]}):t.jsx("div",{className:"overflow-x-auto rounded-xl border border-border/40 bg-card/40",children:t.jsxs("table",{className:"w-full text-[13px]",children:[t.jsx("thead",{className:"border-b border-border/30 bg-muted/20",children:t.jsxs("tr",{className:"text-left text-[11px] uppercase tracking-wider text-muted-foreground/70",children:[t.jsx("th",{className:"px-3 py-2 font-medium",children:"Title"}),t.jsx("th",{className:"px-3 py-2 font-medium",children:"Prompt"}),t.jsx("th",{className:"px-3 py-2 font-medium",children:"Shared"}),t.jsx("th",{className:"px-3 py-2 font-medium text-right",children:"Run count"}),t.jsx("th",{className:"px-3 py-2 font-medium",children:"Last used"}),t.jsx("th",{className:"px-3 py-2 font-medium"})]})}),t.jsx("tbody",{children:C.map(e=>{const s=_(e);return t.jsxs("tr",{className:"border-b border-border/20 hover:bg-muted/20 transition-colors",children:[t.jsx("td",{className:"px-3 py-2.5",children:o===e.id?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(De,{autoFocus:!0,value:d,onChange:e=>x(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),P()),"Escape"===e.key&&(e.preventDefault(),i(null))},className:"h-7 text-[12.5px]"}),t.jsx("button",{type:"button",onClick:P,className:"p-1 rounded hover:bg-emerald-500/10 text-emerald-600","aria-label":"Save rename",children:t.jsx(l,{className:"h-3.5 w-3.5"})}),t.jsx("button",{type:"button",onClick:()=>i(null),className:"p-1 rounded hover:bg-muted text-muted-foreground","aria-label":"Cancel rename",children:t.jsx(u,{className:"h-3.5 w-3.5"})})]}):t.jsxs("div",{className:"flex items-center gap-1.5",children:[s?t.jsx(w,{className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(k,{className:"h-3 w-3 text-emerald-500/80 flex-shrink-0"}),t.jsx("span",{className:"font-medium text-foreground",children:e.title})]})}),t.jsx("td",{className:"px-3 py-2.5 max-w-[320px]",children:t.jsx("p",{className:"text-[11.5px] text-muted-foreground/80 truncate",children:e.prompt_text})}),t.jsx("td",{className:"px-3 py-2.5",children:t.jsx(Ee,{checked:e.is_shared,disabled:!s,onCheckedChange:()=>M(e),"aria-label":"Share with company"})}),t.jsx("td",{className:"px-3 py-2.5 text-right text-muted-foreground/70 tabular-nums",children:e.run_count}),t.jsx("td",{className:"px-3 py-2.5 text-muted-foreground/70",children:e.last_used_at?$e(new Date(e.last_used_at),"MMM d, h:mm a"):"—"}),t.jsx("td",{className:"px-3 py-2.5 text-right",children:t.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[t.jsxs(me,{type:"button",size:"sm",variant:"ghost",onClick:()=>S(e),className:"h-7 px-2 text-[11px] gap-1",children:["Run",t.jsx(b,{className:"h-3 w-3"})]}),s&&o!==e.id&&t.jsx("button",{type:"button",onClick:()=>T(e),className:"p-1.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground","aria-label":"Rename play",children:t.jsx(c,{className:"h-3.5 w-3.5"})}),s&&t.jsx("button",{type:"button",onClick:()=>
1h(e.id),className:pe("p-1.5 rounded text-muted-foreground/70 hover:text-destructive hover:bg-destructive/10"),"aria-label":"Delete play",children:t.jsx(m,{className:"h-3.5 w-3.5"})})]})})]},e.id)})})]})})}),t.jsx(fe,{open:null!==p,onOpenChange:e=>!e&&h(null),children:t.jsxs(je,{children:[t.jsxs(be,{children:[t.jsx(ve,{children:"Delete this play?"}),t.jsx(ye,{children:"This permanently removes the saved prompt. Anyone in your company who had access will no longer see it."})]}),t.jsxs(Ne,{children:[t.jsx(we,{children:"Cancel"}),t.jsx(ke,{onClick:A,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})})]})}const Cs=[{id:"hubspot-mcp",name:"HubSpot",tagline:"Contacts, companies, and deals",description:"Search contacts, push deal updates, log activities, and pull pipeline reports from your HubSpot CRM.",category:"crm",iconName:"Users",accentColor:"#FF7A59",serverUrlTemplate:"https://mcp.hubspot.com/v1/sse",transportType:"http",authType:"bearer",authHelpUrl:"https://developers.hubspot.com/docs/api/private-apps",authPlaceholder:"pat-na1-xxxxx (private app access token)",documentationUrl:"https://developers.hubspot.com/docs/api/overview",isOfficial:!1},{id:"salesforce-mcp",name:"Salesforce",tagline:"Leads, accounts, and opportunities",description:"Query Salesforce records, update fields, and run SOQL from natural language prompts. Bring your CRM into Composer.",category:"crm",iconName:"Cloud",accentColor:"#00A1E0",serverUrlTemplate:"https://{instance}.my.salesforce.com/services/mcp",transportType:"http",authType:"bearer",authHelpUrl:"https://help.salesforce.com/s/articleView?id=sf.connected_app_create.htm",authPlaceholder:"OAuth access token from connected app",documentationUrl:"https://developer.salesforce.com/docs",isOfficial:!1},{id:"apollo-mcp",name:"Apollo.io",tagline:"Lead enrichment and prospecting",description:"Enrich contacts with verified emails and direct dials, search Apollo's 270M+ contact database, and pull company firmographics into Composer.",category:"sales",iconName:"Telescope",accentColor:"#1B2C5C",serverUrlTemplate:"https://mcp.apollo.io/sse",transportType:"http",authType:"api_key",authHelpUrl:"https://docs.apollo.io/reference/authentication",authPlaceholder:"Apollo API key from Settings → API",documentationUrl:"https://docs.apollo.io",isOfficial:!1},{id:"outreach-mcp",name:"Outreach",tagline:"Sequences, prospects, and engagement",description:'Read sequence performance, add prospects to sequences, and pull engagement data from Outreach. Useful for "summarize this rep\'s pipeline activity" prompts.',category:"sales",iconName:"Send",accentColor:"#5951FF",serverUrlTemplate:"https://mcp.outreach.io/sse",transportType:"http",authType:"bearer",authHelpUrl:"https://developers.outreach.io/api/oauth-app/",authPlaceholder:"OAuth access token",documentationUrl:"https://developers.outreach.io",isOfficial:!1},{id:"calendly-mcp",name:"Calendly",tagline:"Booking links and scheduled meetings",description:'Pull upcoming meetings, list available booking links, and check rep availability. Great for "what\'s on my calendar this week" or "send a booking link" prompts.',category:"sales",iconName:"CalendarDays",accentColor:"#006BFF",serverUrlTemplate:"https://mcp.calendly.com/sse",transportType:"http",authType:"bearer",authHelpUrl:"https://developer.calendly.com/api-docs/ZG9jOjI3NjMyOA-personal-access-tokens",authPlaceholder:"Calendly personal access token",documentationUrl:"https://developer.calendly.com",isOfficial:!1},{id:"slack-mcp",name:"Slack",tagline:"Channels, messages, and DMs",description:"Read recent messages, post to channels, search history, and surface @mentions from your Slack workspace.",category:"communication",iconName:"Hash",accentColor:"#4A154B",serverUrlTemplate:"https://slack.com/api/mcp",transportType:"http",authType:"bearer",authHelpUrl:"https://api.slack.com/authentication/token-types#user",authPlaceholder:"xoxp-xxxxxxxxxxxx (user token)",documentationUrl:"https://api.slack.com/docs",isOfficial:!1},{id:"notion-mcp",name:"Notion",tagline:"Pages, databases, and wikis",description:"Search Notion content, create new pages, update database rows, and pull docs into Composer context.",category:"knowledge",iconName:"BookOpen",accentColor:"#000000",serverUrlTemplate:"https://mcp.notion.com/v1/sse",transportType:"http",authType:"bearer",authHelpUrl:"https://developers.notion.com/docs/create-a-notion-integration",authPlaceholder:"secret_xxxxxxxxxxxx (integration token)",documentationUrl:"https://developers.notion.com",isOfficial:!1},{id:"zapier-mcp",name:"Zapier",tagline:"8,000+ app integrations",description:"Run any Zapier action as a tool — bridges Composer to thousands of apps without writing custom integrations.",category:"automation",iconName:"Zap",accentColor:"#FF4A00",serverUrlTemplate:"https://mcp.zapier.com/api/mcp/sse",transportType:"http",authType:"bearer",authHelpUrl:"https://help.zapier.com/hc/en-us/articles/27995540527629",authPlaceholder:"Zapier MCP API key",documentationUrl:"https://zapier.com/mcp",isOfficial:!0},{id:"n8n-mcp",name:"n8n",tagline:"Self-hosted workflow automation",description:"Connect to your n8n instance and trigger workflows as Composer tools. Bring your custom automations into chat.",category:"automation",iconName:"Workflow",accentColor:"#EA4B71",serverUrlTemplate:"https://{workspace}.app.n8n.cloud/mcp-server/http",transportType:"http",authType:"bearer",authHelpUrl:"https://docs.n8n.io/api/authentication/",authPlaceholder:"n8n API key from Settings → API",documentationUrl:"https://docs.n8n.io",isOfficial:!1}],_s=["crm","sales","communication","knowledge","automation"],Ss={crm:"CRM",sales:"Sales Tools",communication:"Communication",knowledge:"Knowledge",automation:"Automation"};function Ts({template:e,open:s,onOpenChange:r,onInstalled:a}){const{addServer:n,discoverTools:l,canManageIntegrations:o}=He(),[i,d]=R.useState(""),[c,m]=R.useState(""),[x,u]=R.useState(!1);R.useEffect(()=>{e&&(d(e.serverUrlTemplate),m(""),u(!1))},[e,s]);const h=R.useMemo(()=>!!e&&/\{[a-z0-9_]+\}/i.test(i),[e,i]),g="none"!==(null==e?void 0:e.authType),f=g&&!c.trim(),j=!(!e||h||f||n.isPending||x);if(!e)return null;const b=n.isPending||x;return o?t.jsx(qe,{open:s,onOpenChange:r,children:t.jsxs(Be,{className:"sm:max-w-[480px]",children:[t.jsx(Ve,{children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center text-white font-semibold text-sm shrink-0",style:{backgroundColor:e.accentColor}
1,"aria-hidden":!0,children:e.name.slice(0,1)}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsxs(Ke,{className:"text-base",children:["Install ",e.name]}),e.isOfficial&&t.jsx(Oe,{variant:"secondary",className:"text-[10px] uppercase tracking-wide",children:"Official"})]}),t.jsx(Je,{className:"text-xs mt-0.5",children:e.tagline})]})]})}),t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"rounded-xl bg-muted/50 border border-border/40 p-3 text-[12px] text-muted-foreground/90 leading-relaxed",children:e.description}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(We,{htmlFor:"mcp-server-url",className:"text-[12px] font-medium",children:"Server URL"}),t.jsx(De,{id:"mcp-server-url",value:i,onChange:e=>d(e.target.value),spellCheck:!1,autoComplete:"off",className:"h-9 font-mono text-[12px]"}),h&&t.jsxs("p",{className:"text-[11px] text-amber-600 dark:text-amber-400",children:["Replace placeholders like ",t.jsx("code",{className:"bg-muted px-1 py-0.5 rounded",children:"{workspace}"})," with the actual value before installing."]})]}),g&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(We,{htmlFor:"mcp-auth-token",className:"text-[12px] font-medium",children:"bearer"===e.authType?"Bearer token":"API key"}),e.authHelpUrl&&t.jsxs("a",{href:e.authHelpUrl,target:"_blank",rel:"noreferrer noopener",className:"text-[11px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1",children:["Where do I find this?",t.jsx(_,{className:"h-3 w-3"})]})]}),t.jsx(De,{id:"mcp-auth-token",type:"password",value:c,onChange:e=>m(e.target.value),placeholder:e.authPlaceholder??"Paste your token…",autoComplete:"off",spellCheck:!1,className:"h-9 font-mono text-[12px]"}),t.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"Your token is encrypted before storage and only used to call this MCP server."})]}),e.documentationUrl&&t.jsxs("a",{href:e.documentationUrl,target:"_blank",rel:"noreferrer noopener",className:"text-[11px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1",children:[t.jsx(_,{className:"h-3 w-3"}),e.name," documentation"]})]}),t.jsxs(Qe,{children:[t.jsx(me,{variant:"ghost",onClick:()=>r(!1),disabled:b,children:"Cancel"}),t.jsx(me,{onClick:async()=>{if(e&&j)try{const t=await n.mutateAsync({name:e.name,server_url:i.trim(),transport_type:e.transportType,auth_type:e.authType,auth_token:g?c.trim():void 0});ue.success(`${e.name} installed`),u(!0);try{const s=await l.mutateAsync(t.id);ue.success(`Discovered ${s.tools_count??0} tools from ${e.name}`)}catch(s){ue.warning("Installed, but tool discovery failed",{description:s instanceof Error?s.message:"Try again from Settings → Integrations."})}finally{u(!1)}null==a||a(t.id),r(!1)}catch(s){ue.error(`Failed to install ${e.name}`,{description:s instanceof Error?s.message:"Unknown error"})}},disabled:!j,children:b?t.jsxs(t.Fragment,{children:[t.jsx(p,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}),x?t.jsxs(t.Fragment,{children:[t.jsx(S,{className:"h-3 w-3 mr-1"}),"Discovering tools…"]}):"Installing…"]}):t.jsxs(t.Fragment,{children:[t.jsx(v,{className:"h-3.5 w-3.5 mr-1.5"}),"Install"]})})]})]})}):t.jsx(qe,{open:s,onOpenChange:r,children:t.jsxs(Be,{className:"sm:max-w-[480px]",children:[t.jsx(Ve,{children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-10 h-10 rounded-xl bg-muted flex items-center justify-center shrink-0",children:t.jsx(C,{className:"h-4 w-4 text-muted-foreground"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx(Ke,{className:"text-base",children:"Admin only"}),t.jsxs(Je,{className:"text-xs mt-0.5",children:["Installing ",e.name," requires owner or admin permissions."]})]})]})}),t.jsxs("div",{className:"rounded-xl bg-muted/40 border border-border/40 p-3 text-[12.5px] text-muted-foreground/90 leading-relaxed",children:["MCP integrations affect everyone in your company — only admins can install them. Ask an admin to enable ",e.name," for your team. Once installed, the ",e.name," tools will be available for you to use in Composer."]}),t.jsx(Qe,{children:t.jsx(me,{variant:"ghost",onClick:()=>r(!1),children:"Close"})})]})})}function Ps({name:e,className:s}){const r=y[e];return r?t.jsx(r,{className:s}):t.jsx(v,{className:s})}function Ms(){const e=$(),{isFeatureEnabled:s}=Ce(),{servers:r,canManageIntegrations:a}
1=He(),[n,l]=R.useState(""),[o,i]=R.useState(new Set),[d,c]=R.useState(null),[m,x]=R.useState(!1),p=R.useMemo(()=>{const e=new Set;for(const s of r??[])e.add(s.name.trim().toLowerCase());return e},[r]),h=s("mcp-servers"),g=R.useMemo(()=>{const e=n.trim().toLowerCase();return Cs.filter(s=>!(o.size>0&&!o.has(s.category))&&(!e||(s.name.toLowerCase().includes(e)||s.tagline.toLowerCase().includes(e)||s.description.toLowerCase().includes(e)||s.category.toLowerCase().includes(e))))},[n,o]),b=R.useMemo(()=>{const e=new Map;for(const s of g){const t=e.get(s.category)??[];t.push(s),e.set(s.category,t)}return _s.filter(s=>e.has(s)).map(s=>({category:s,templates:e.get(s)}))},[g]);return h?t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx("div",{className:"border-b border-border/40 bg-background/50 px-4 sm:px-6 py-4",children:t.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx("div",{className:"w-7 h-7 rounded-lg bg-primary/10 flex items-center justify-center",children:t.jsx(T,{className:"h-3.5 w-3.5 text-primary"})}),t.jsx("h1",{className:"text-lg font-semibold text-foreground",children:"MCP Marketplace"}),t.jsx(Oe,{variant:"outline",className:"text-[10px] uppercase tracking-wide",children:"Preview"})]}),t.jsxs("p",{className:"text-[12px] text-muted-foreground/70 ml-9",children:[g.length," of ",Cs.length," servers — click to install with one form."]})]}),t.jsxs(me,{variant:"outline",size:"sm",className:"rounded-xl",onClick:()=>e("/settings?tab=integrations"),children:[t.jsx(P,{className:"h-3.5 w-3.5 mr-1.5"}),"Manage installed"]})]})}),!a&&t.jsx("div",{className:"border-b border-amber-500/20 bg-amber-500/5 px-4 sm:px-6 py-2.5",children:t.jsxs("div",{className:"flex items-start gap-2 text-[12px] text-amber-700 dark:text-amber-300",children:[t.jsx(C,{className:"h-3.5 w-3.5 mt-0.5 flex-shrink-0"}),t.jsxs("p",{children:[t.jsx("span",{className:"font-medium",children:"Admin only."})," ","Only owners and admins can install MCP integrations. Browse the catalog and ask an admin to enable any servers your team needs — once installed, the tools will be available for everyone to use in Composer."]})]})}),t.jsxs("div",{className:"border-b border-border/30 bg-card/40 px-4 sm:px-6 py-3 space-y-3",children:[t.jsx("div",{className:"flex flex-col sm:flex-row gap-2",children:t.jsxs("div",{className:"flex-1 relative",children:[t.jsx(f,{className:"h-3.5 w-3.5 absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground/60"}),t.jsx(De,{type:"text",value:n,onChange:e=>l(e.target.value),placeholder:"Search servers by name, description, or category…",className:"pl-9 h-9 text-[13px]"}),n&&t.jsx("button",{type:"button",onClick:()=>l(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground/60 hover:text-foreground","aria-label":"Clear search",children:t.jsx(u,{className:"h-3.5 w-3.5"})})]})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.jsx(j,{className:"h-3.5 w-3.5 text-muted-foreground/60 mr-1"}),_s.map(e=>t.jsx("button",{type:"button",onClick:()=>(e=>{i(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})})(e),className:pe("px-2.5 py-1 text-[11px] font-medium rounded-full border transition-colors",o.has(e)?"bg-primary/10 text-primary border-primary/30":"bg-transparent text-muted-foreground border-border/40 hover:bg-muted/40"),children:Ss[e]},e)),o.size>0&&t.jsx("button",{type:"button",onClick:()=>i(new Set),className:"ml-1 px-2.5 py-1 text-[11px] font-medium rounded-full text-muted-foreground hover:text-foreground transition-colors",children:"Clear"})]})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto px-4 sm:px-6 py-4 space-y-6",children:[0===b.length?t.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[t.jsx("div",{className:"w-12 h-12 rounded-2xl bg-muted/40 flex items-center justify-center mb-3",children:t.jsx(f,{className:"h-5 w-5 text-muted-foreground/40"})}
1),t.jsx("p",{className:"text-sm font-medium text-foreground/60 mb-1",children:"No servers match"}),t.jsx("p",{className:"text-xs text-muted-foreground/50 max-w-[300px]",children:"Try a different search term or clear your filters."})]}):b.map(({category:e,templates:s})=>t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("h2",{className:"text-[13px] font-semibold text-foreground",children:Ss[e]}),t.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:s.length})]}),t.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2.5",children:s.map(e=>t.jsx(As,{template:e,isInstalled:p.has(e.name.trim().toLowerCase()),canInstall:a,onInstall:()=>(e=>{c(e),x(!0)})(e)},e.id))})]},e)),t.jsx("div",{className:"pt-4 pb-2 flex items-center justify-center",children:t.jsxs("a",{href:"https://modelcontextprotocol.io/introduction",target:"_blank",rel:"noopener noreferrer",className:"text-[11px] text-muted-foreground/60 hover:text-foreground inline-flex items-center gap-1",children:["Learn more about Model Context Protocol",t.jsx(_,{className:"h-3 w-3"})]})})]}),t.jsx(Ts,{template:d,open:m,onOpenChange:e=>{x(e),e||c(null)}})]}):t.jsxs("div",{className:"flex flex-col items-center justify-center h-full p-8 text-center",children:[t.jsx("div",{className:"w-12 h-12 rounded-2xl bg-muted/40 flex items-center justify-center mb-3",children:t.jsx(T,{className:"h-5 w-5 text-muted-foreground/40"})}),t.jsx("h1",{className:"text-base font-semibold text-foreground/70 mb-1",children:"MCP Marketplace not available"}),t.jsxs("p",{className:"text-xs text-muted-foreground/60 max-w-[320px]",children:["The ",t.jsx("code",{className:"text-[11px] bg-muted px-1 py-0.5 rounded",children:"mcp-servers"})," feature flag is not enabled for this environment."]})]})}function As({template:e,isInstalled:s,canInstall:r,onInstall:a}){return t.jsxs("div",{className:"rounded-xl border border-border/40 bg-card/60 p-3 hover:border-border hover:bg-card transition-colors flex flex-col gap-2",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0",style:{backgroundColor:`${e.accentColor}15`},"aria-hidden":!0,children:t.jsx(Ps,{name:e.iconName,className:"h-4 w-4"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[t.jsx("h3",{className:"text-[12.5px] font-medium text-foreground leading-tight",children:e.name}),e.isOfficial&&t.jsx(Oe,{variant:"secondary",className:"text-[9px] uppercase tracking-wide font-medium px-1.5 py-0",children:"Official"})]}),t.jsx("p",{className:"text-[10px] text-muted-foreground/60 truncate",children:e.tagline})]}),s&&t.jsxs(Oe,{variant:"outline",className:"text-[9px] uppercase tracking-wide font-medium bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-500/30",children:[t.jsx(M,{className:"h-2.5 w-2.5 mr-0.5"}),"Installed"]})]}),t.jsx("p",{className:"text-[11.5px] text-muted-foreground/80 leading-relaxed line-clamp-3",children:e.description}),t.jsx("div",{className:"mt-auto flex items-center justify-end pt-1",children:r?t.jsx(me,{type:"button",size:"sm",variant:s?"ghost":"default",onClick:a,className:"h-6 px-2.5 text-[10.5px] gap-1",children:s?"Reinstall":"Install"}):t.jsxs(me,{type:"button",size:"sm",variant:"outline",disabled:!0,title:"Only owners and admins can install integrations",className:"h-6 px-2.5 text-[10.5px] gap-1 cursor-not-allowed",children:[t.jsx(C,{className:"h-2.5 w-2.5"}),s?"Installed":"Admin only"]})})]})}const Os={preference:"Preference",fact:"Fact",pattern:"Pattern"},Es={preference:"bg-indigo-500/15 text-indigo-700 dark:bg-indigo-500/20 dark:text-indigo-300",fact:"bg-emerald-500/15 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-300",pattern:"bg-amber-500/15 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300"};function Fs(){const{user:e}=ge(),{activeCompany:s}=he(),r=null==s?void 0:s.id,a=null==e?void 0:e.id,n=Ze(),[l,o]=R.useState(!1),[i,d]=R.useState(null),[x,u]=R.useState(""),[p,h]=R.useState("preference"),[g,f]=R.useState("user"),[j,b]=R.useState(null),v=Ye({queryKey:["composer-memory",r,a],queryFn:async()=>{const{data:e,error:s}=await _e.rpc("composer_memory_list",{p_company_id:r,p_user_id:a,p_limit:200});if(s)throw new Error(s.message);return e??[]},enabled:!!r}),y=Ge({mutationFn:async()=>
1{if(!r)throw new Error("No active company");const{error:e}=await _e.rpc("composer_memory_upsert",{p_id:(null==i?void 0:i.id)??null,p_company_id:r,p_user_id:"company"===g?null:a??null,p_kind:p,p_content:x.trim(),p_source_thread_id:(null==i?void 0:i.source_thread_id)??null});if(e)throw new Error(e.message)},onSuccess:()=>{n.invalidateQueries({queryKey:["composer-memory",r,a]}),ue.success(i?"Memory updated":"Memory added"),w()},onError:e=>ue.error(`Save failed: ${e.message}`)}),N=Ge({mutationFn:async e=>{if(!r)throw new Error("No active company");const{error:s}=await _e.rpc("composer_memory_delete",{p_id:e,p_company_id:r});if(s)throw new Error(s.message)},onSuccess:()=>{n.invalidateQueries({queryKey:["composer-memory",r,a]}),ue.success("Forgotten"),b(null)},onError:e=>ue.error(`Delete failed: ${e.message}`)}),w=()=>{o(!1),d(null),u("")},k=v.data??[];return t.jsxs("div",{className:"max-w-4xl mx-auto p-4 sm:p-6 space-y-6",children:[t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"rounded-xl bg-muted p-2 shrink-0",children:t.jsx(A,{className:"h-5 w-5 text-foreground"})}),t.jsxs("div",{children:[t.jsx("h1",{className:"text-xl font-semibold",children:"Composer Memory"}),t.jsx("p",{className:"text-sm text-muted-foreground max-w-2xl",children:"Things Composer remembers about you and your company. These are injected into every Composer prompt so you don't have to repeat yourself."})]})]}),t.jsxs(me,{onClick:()=>{d(null),u(""),h("preference"),f("user"),o(!0)},className:"gap-2 shrink-0",children:[t.jsx(O,{className:"h-4 w-4"}),"Add memory"]})]}),t.jsx("div",{className:"rounded-2xl border border-border overflow-hidden",children:v.isLoading?t.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:"Loading…"}):0===k.length?t.jsxs("div",{className:"p-12 text-center text-sm text-muted-foreground flex flex-col items-center gap-3",children:[t.jsx(A,{className:"h-10 w-10 text-muted-foreground/40",strokeWidth:1.5}),t.jsxs("div",{children:[t.jsx("p",{className:"font-medium",children:"No memories yet."}),t.jsx("p",{className:"text-xs mt-1",children:"Tell Composer something like “remember that our trial is 14 days” — or add one manually."})]})]}):t.jsx("ul",{className:"divide-y divide-border",children:k.map(e=>t.jsxs("li",{className:"flex items-start gap-4 px-4 py-3 hover:bg-accent/40 transition-colors",children:[t.jsx("span",{className:`text-xs font-medium uppercase tracking-wide rounded-full px-2 py-0.5 shrink-0 mt-0.5 ${Es[e.kind]}`,children:Os[e.kind]}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:e.content}),t.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[null===e.user_id?"Company-wide · ":"You only · ",e.last_used_at?`used ${ze(new Date(e.last_used_at),{addSuffix:!0})}`:`added ${ze(new Date(e.created_at),{addSuffix:!0})}`]})]}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx(me,{variant:"ghost",size:"sm",onClick:()=>(e=>{d(e),u(e.content),h(e.kind),f(null===e.user_id?"company":"user"),o(!0)})(e),children:t.jsx(c,{className:"h-4 w-4"})}),t.jsx(me,{variant:"ghost",size:"sm",onClick:()=>b(e),className:"text-destructive hover:text-destructive",children:t.jsx(m,{className:"h-4 w-4"})})]})]},e.id))})}),t.jsx(qe,{open:l,onOpenChange:e=>{e||w()},children:t.jsxs(Be,{className:"max-w-[95vw] sm:max-w-lg",children:[t.jsxs(Ve,{children:[t.jsx(Ke,{children:i?"Edit memory":"Add memory"}),t.jsx(Je,{children:"Phrase it as a standalone sentence. It will be prepended to every Composer prompt."})]}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(We,{htmlFor:"memory-content",children:"Content"}),t.jsx(Xe,{id:"memory-content",rows:4,placeholder:"e.g. Our trial period is 14 days.",value:x,onChange:e=>u(e.target.value),maxLength:2e3}),t.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[x.length," / 2000"]})]}),t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(We,{children:"Kind"}),t.jsxs(es,{value:p,onValueChange:e=>h(e),children:[t.jsx(ss,{children:t.jsx(ts,{})}),t.jsxs(rs,{children:[t.jsx(as,{value:"preference",children:"Preference"}),t.jsx(as,{value:"fact",children:"Fact"}),t.jsx(as,{value:"pattern",children:"Pattern"})]})]})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(We,{children:"Scope"}),t.jsxs(es,{value:g,onValueChange:e=>f(e),children:[t.jsx(ss,{children:t.jsx(ts,{})}),t.jsxs(rs,{children:[t.jsx(as,{value:"user",children:"You only"}),t.jsx(as,{value:"company",children:"Company-wide"})]})]})]})]})]}),t.jsxs(Qe,{children:[t.jsx(me,{variant:"ghost",onClick:w,children:"Cancel"}),t.jsx(me,{onClick:()=>y.mutate(),disabled:!x.trim()||y.isPending,children:y.isPending?"Saving…":i?"Save":"Add"})]})]})}),t.jsx(fe,{open:!!j,onOpenChange:e=>{e||b(null)},children:t.jsxs(je,{children:[t.jsxs(be,{children:[t.jsx(ve,{children:"Forget this memory?"}),t.jsx(ye,{children:"Composer will stop using this in future prompts. You can always add it back later."})]}),t.jsxs(Ne,{children:[t.jsx(we,{children:"Cancel"}),t.jsx(ke,{onClick:()=>j&&N.mutate(j.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Forget"})]})]})})]})}const Is={pending:"bg-amber-500/15 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300",running:"bg-blue-500/15 text-blue-700 dark:bg-blue-500/20 dark:text-blue-300",done:"bg-emerald-500/15 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-300",failed:"bg-red-500/15 text-red-700 dark:bg-red-500/20 dark:text-red-300",cancelled:"bg-muted text-muted-foreground"};function Ls(){const{user:e}=ge(),{activeCompany:s}=he(),r=null==s?void 0:s.id,a=null==e?void 0:e.id,n=Ze(),[l,o]=R.useState("one_shot"),[i,d]=R.useState(null),c=Ye({queryKey:["composer-scheduled-actions",r,a],enabled:!!r,queryFn:async()=>{const{data:e,error:s}=await _e.rpc("composer_scheduled_actions_list",{p_company_id:r,p_user_id:a??null,p_limit:200});if(s)throw new Error(s.message);return e??[]},refetchInterval:15e3,refetchOnMount:"always"}),m=Ge({mutationFn:async e=>{const{data:s,error:t}=await _e.rpc("composer_cancel_scheduled_action",{p_id:e.id,p_company_id:r,p_user_id:a??"system"});if(t)throw new Error(t.message);if(!0!==s)throw new Error("Schedule could not be cancelled (already done/failed?)")},onSuccess:()=>{ue.success("Scheduled action cancelled"),n.invalidateQueries({queryKey:["composer-scheduled-actions"]}),d(null)},onError:e=>{ue.error(e instanceof Error?e.message:"Cancel failed")}});if(!r)return null;
1const x=c.data??[],u=x.filter(e=>"one_shot"===e.kind),p=x.filter(e=>"recurring"===e.kind),h="one_shot"===l?u:p;return t.jsxs("div",{className:"p-6 max-w-3xl mx-auto space-y-6",children:[t.jsxs("header",{className:"space-y-1",children:[t.jsx("h1",{className:"text-2xl font-semibold",children:"Composer Schedules"}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Future tool runs and recurring prompts Composer will fire for you. Create new ones by asking Composer (e.g. ",t.jsx("em",{children:'"send Acme a follow-up SMS at 9am tomorrow"'}),")."]})]}),t.jsxs("div",{className:"flex items-center gap-2 border-b border-border",children:[t.jsx(Us,{active:"one_shot"===l,onClick:()=>o("one_shot"),icon:t.jsx(E,{className:"h-3.5 w-3.5"}),label:`One-shot · ${u.length}`}),t.jsx(Us,{active:"recurring"===l,onClick:()=>o("recurring"),icon:t.jsx(F,{className:"h-3.5 w-3.5"}),label:`Recurring · ${p.length}`})]}),c.isLoading&&t.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading…"}),!c.isLoading&&0===h.length&&t.jsxs("div",{className:"text-sm text-muted-foreground py-8 text-center border border-dashed border-border rounded-lg",children:["No ","one_shot"===l?"one-shot":"recurring"," schedules yet."]}),t.jsx("div",{className:"space-y-3",children:h.map(e=>t.jsx(Rs,{row:e,onCancel:()=>d(e)},e.id))}),t.jsx(fe,{open:null!==i,onOpenChange:e=>!e&&d(null),children:t.jsxs(je,{children:[t.jsxs(be,{children:[t.jsx(ve,{children:"Cancel scheduled action?"}),t.jsxs(ye,{children:["This will mark the action ",t.jsx("strong",{children:(null==i?void 0:i.name)??(null==i?void 0:i.tool_name)??(null==i?void 0:i.id)})," ","as cancelled and prevent it from firing."]})]}),t.jsxs(Ne,{children:[t.jsx(we,{children:"Keep it"}),t.jsx(ke,{onClick:()=>i&&m.mutate(i),disabled:m.isPending,children:m.isPending?"Cancelling…":"Cancel action"})]})]})})]})}function Us({active:e,onClick:s,icon:r,label:a}){return t.jsxs("button",{onClick:s,className:"flex items-center gap-1.5 px-3 py-2 text-sm border-b-2 -mb-px transition-colors "+(e?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:[r,a]})}function Rs({row:e,onCancel:s}){const r="one_shot"===e.kind,a=e.run_at,n=(()=>{try{const e=new Date(a),s=Date.now();return e.getTime()>s?`in ${ze(e)}`:`${ze(e)} ago`}catch{return a}})(),l="pending"===e.status||"running"===e.status;return t.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 space-y-3",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm font-medium text-foreground truncate",children:e.name??(r?e.tool_name:"Recurring prompt")}),t.jsx(Ds,{status:e.status})]}),r?t.jsx("div",{className:"font-mono text-xs text-muted-foreground mt-1 truncate",children:e.tool_name}):t.jsx("div",{className:"font-mono text-xs text-muted-foreground mt-1 truncate",children:e.cron})]}),l&&t.jsxs(me,{variant:"ghost",size:"sm",onClick:s,children:[t.jsx(I,{className:"h-3.5 w-3.5 mr-1"})," Cancel"]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-muted-foreground",children:r?"Fires":"Next run"}),t.jsx("div",{className:"text-foreground",children:n})]}),e.last_run_at&&t.jsxs("div",{children:[t.jsx("div",{className:"text-muted-foreground",children:"Last run"}),t.jsx("div",{className:"text-foreground",children:(()=>{try{return`${ze(new Date(e.last_run_at))} ago`}catch{return e.last_run_at}})()})]})]}),!r&&e.prompt&&t.jsx("div",{className:"text-xs text-muted-foreground bg-muted rounded-md p-2 line-clamp-2",title:e.prompt,children:e.prompt}),e.last_error&&t.jsxs("div",{className:"text-xs text-red-700 dark:text-red-300 bg-red-500/10 rounded-md p-2 flex items-start gap-1.5",children:[t.jsx(L,{className:"h-3.5 w-3.5 flex-shrink-0 mt-0.5"}),t.jsx("span",{className:"break-all",children:e.last_error})]})]})}function Ds({status:e}){const s="done"===e?t.jsx(M,{className:"h-3 w-3"}):"failed"===e?t.jsx(L,{className:"h-3 w-3"}):"cancelled"===e?t.jsx(U,{className:"h-3 w-3"}):null;return t.jsxs("span",{className:`text-[10px] uppercase tracking-wide px-1.5 py-0.5 rounded inline-flex items-center gap-1 ${Is[e]}`,children:[s,e]})}const $s={pending:"bg-amber-500/15 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300",running:"bg-blue-500/15 text-blue-700 dark:bg-blue-500/20 dark:text-blue-300",done:"bg-emerald-500/15 text-emerald-700 dark:bg-emerald-500/20 dark:text-emerald-300",failed:"bg-red-500/15 text-red-700 dark:bg-red-500/20 dark:text-red-300",cancelled:"bg-muted text-muted-foreground"};function zs(){const{user:e}=ge(),{activeCompany:s}=he(),r=null==s?void 0:s.id,a=null==e?void 0:e.id,n=Ze(),[l,o]=R.useState("active"),[i,d]=R.useState(null),c=Ye({queryKey:["composer-jobs",r,a],enabled:!!r,queryFn:async()=>{const{data:e,error:s}=await _e.rpc("composer_jobs_list",{p_company_id:r,p_user_id:a??null,p_status:null,p_limit:200});if(s)throw new Error(s.message);return e??[]},refetchInterval:1e4,refetchOnMount:"always"}),m=Ge({mutationFn:async e=>{const{data:s,error:t}
1=await _e.rpc("composer_cancel_job",{p_id:e.id,p_company_id:r,p_user_id:a??"system"});if(t)throw new Error(t.message);if(!0!==s)throw new Error("Job could not be cancelled (already done/failed?)")},onSuccess:()=>{ue.success("Job cancelled"),n.invalidateQueries({queryKey:["composer-jobs"]}),d(null)},onError:e=>{ue.error(e instanceof Error?e.message:"Cancel failed")}}),x=c.data??[],u=R.useMemo(()=>({active:x.filter(e=>"pending"===e.status||"running"===e.status),completed:x.filter(e=>"done"===e.status),failed:x.filter(e=>"failed"===e.status||"cancelled"===e.status)}),[x]),h=u[l];return r?t.jsxs("div",{className:"p-6 max-w-3xl mx-auto space-y-6",children:[t.jsxs("header",{className:"space-y-1",children:[t.jsx("h1",{className:"text-2xl font-semibold",children:"Composer Jobs"}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Background work Composer is running for you. Start new jobs by asking Composer (e.g. ",t.jsx("em",{children:'"enrich my 50 oldest contacts"'}),")."]})]}),t.jsxs("div",{className:"flex items-center gap-2 border-b border-border",children:[t.jsx(Hs,{active:"active"===l,onClick:()=>o("active"),icon:t.jsx(p,{className:"h-3.5 w-3.5"}),label:`Active · ${u.active.length}`}),t.jsx(Hs,{active:"completed"===l,onClick:()=>o("completed"),icon:t.jsx(M,{className:"h-3.5 w-3.5"}),label:`Completed · ${u.completed.length}`}),t.jsx(Hs,{active:"failed"===l,onClick:()=>o("failed"),icon:t.jsx(L,{className:"h-3.5 w-3.5"}),label:`Failed · ${u.failed.length}`})]}),c.isLoading&&t.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading…"}),!c.isLoading&&0===h.length&&t.jsxs("div",{className:"text-sm text-muted-foreground py-8 text-center border border-dashed border-border rounded-lg",children:["No ",l," jobs."]}),t.jsx("div",{className:"space-y-3",children:h.map(e=>t.jsx(qs,{row:e,onCancel:()=>d(e)},e.id))}),t.jsx(fe,{open:null!==i,onOpenChange:e=>!e&&d(null),children:t.jsxs(je,{children:[t.jsxs(be,{children:[t.jsx(ve,{children:"Cancel job?"}),t.jsxs(ye,{children:["This will stop ",t.jsx("strong",{children:(null==i?void 0:i.name)??(null==i?void 0:i.tool_name)})," ","at the next progress checkpoint. Work already done is kept."]})]}),t.jsxs(Ne,{children:[t.jsx(we,{children:"Keep running"}),t.jsx(ke,{onClick:()=>i&&m.mutate(i),disabled:m.isPending,children:m.isPending?"Cancelling…":"Cancel job"})]})]})})]}):null}function Hs({active:e,onClick:s,icon:r,label:a}){return t.jsxs("button",{onClick:s,className:"flex items-center gap-1.5 px-3 py-2 text-sm border-b-2 -mb-px transition-colors "+(e?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:[r,a]})}function qs({row:e,onCancel:s}){var r,a;const n="pending"===e.status||"running"===e.status,l=Math.max(0,Math.min(100,(null==(r=e.progress)?void 0:r.percent)??0)),o=(()=>{switch(e.status){case"running":return t.jsx(p,{className:"h-3.5 w-3.5 animate-spin"});case"done":return t.jsx(M,{className:"h-3.5 w-3.5 text-emerald-600"});case"failed":return t.jsx(L,{className:"h-3.5 w-3.5 text-red-600"});case"cancelled":return t.jsx(U,{className:"h-3.5 w-3.5 text-muted-foreground"});default:return t.jsx(v,{className:"h-3.5 w-3.5"})}})();return t.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 space-y-3",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[o,t.jsx("span",{className:"text-sm font-medium text-foreground truncate",children:e.name??e.tool_name}),t.jsx("span",{className:`text-[10px] uppercase tracking-wide px-1.5 py-0.5 rounded ${$s[e.status]}`,children:e.status})]}),t.jsx("div",{className:"font-mono text-xs text-muted-foreground mt-1 truncate",children:e.tool_name})]}),n&&t.jsxs(me,{variant:"ghost",size:"sm",onClick:s,children:[t.jsx(I,{className:"h-3.5 w-3.5 mr-1"})," Cancel"]})]}),(n||l>0)&&t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"h-1.5 w-full bg-muted rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-blue-500 transition-all duration-300",style:{width:`${l}%`}})}),t.jsxs("div",{className:"flex items-center justify-between text-[11px] text-muted-foreground",children:[t.jsx("span",{children:(null==(a=e.progress)?void 0:a.message)??("pending"===e.status?"Waiting for worker…":"Working…")}),t.jsxs("span",{children:[l.toFixed(0),"%"]})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs text-muted-foreground",children:[e.started_at&&t.jsxs("div",{children:[t.jsx("div",{children:"Started"}),t.jsx("div",{className:"text-foreground",children:Bs(e.started_at)})]}),e.finished_at&&t.jsxs("div",{children:[t.jsx("div",{children:"Finished"}),t.jsx("div",{className:"text-foreground",children:Bs(e.finished_at)})]})]}),"done"===e.status&&e.result&&t.jsx("div",{className:"text-xs text-foreground
1/80 bg-muted/50 rounded-md p-2",children:"string"==typeof e.result.message?e.result.message:t.jsx("pre",{className:"whitespace-pre-wrap font-mono text-[11px]",children:JSON.stringify(e.result,null,2).slice(0,400)})}),e.error_message&&"done"!==e.status&&t.jsxs("div",{className:"text-xs text-red-700 dark:text-red-300 bg-red-500/10 rounded-md p-2 flex items-start gap-1.5",children:[t.jsx(L,{className:"h-3.5 w-3.5 flex-shrink-0 mt-0.5"}),t.jsx("span",{className:"break-all",children:e.error_message})]})]})}function Bs(e){try{return`${ze(new Date(e))} ago`}catch{return e}}export{fs as ComposerChatView,zs as ComposerJobsSidebar,Ms as ComposerMcpMarketplace,Fs as ComposerMemorySidebar,ks as ComposerPlays,Ls as ComposerSchedulesSidebar,Ns as ComposerTools};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.