@vellumai/web 0.10.12-dev.202607242227.e52a30c → 0.10.12-dev.202607242326.75b9ec6

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.
@@ -1,4 +1,4 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./button-Dy5001j6.js";import{m as r,t as i,u as a}from"./chunk-5KNZJZUH-Bsoom5--.js";import{n as o}from"./QueryClientProvider-CMu7CkQU.js";import{t as s}from"./useQuery-Bz-fbQ-m.js";import{t as c}from"./useMutation-CXGTrp4W.js";import{t as l}from"./jsx-runtime-D3ZM-ToX.js";import{t as u}from"./cn-CJf7MmLX.js";import{t as d}from"./typography-DEI9Ra9z.js";import{t as f}from"./card-DRIctGVs.js";import{b as p,c as m,d as h,g,h as _,l as v,o as y}from"./use-save-twilio-credentials-CUQ6gdIj.js";import{t as b}from"./chevron-down-B5A-0g8A.js";import{t as x}from"./circle-check-big-DSsDH5_6.js";import{t as S}from"./list-row-B1wPb2Au.js";import{o as C,r as w,t as T,u as E}from"./threshold-presets-BO8En2q0.js";import{t as D}from"./message-square-CQGiY4zk.js";import{t as O}from"./search-BVW-n8to.js";import{t as ee}from"./notice-BMK7xqUw.js";import{M as k,N as A,a as j,i as M}from"./src-D89CNeuT.js";import{t as N}from"./tag-NXcyiTkK.js";import{t as P}from"./input-hw3el2GJ.js";import{t as te}from"./panel-item-CrtoJCrd.js";import{t as F}from"./confirm-dialog-UYFm4osC.js";import{t as I}from"./dropdown-BCfnSdIZ.js";import{n as ne,t as re}from"./create-selectors-Qo7kcikX.js";import{t as ie}from"./assistant-identity-store-DIyVo8LV.js";import{r as ae}from"./utils-CnB60ZJN.js";import{u as oe}from"./routes-vE-2hncW.js";import{n as se}from"./conversation-navigation-nuG3yn67.js";import{i as L,o as ce,r as R}from"./sdk.gen-DPKrJeho.js";import{t as le}from"./assistant-feature-flag-store-fyKSDJNN.js";import{t as z}from"./public-asset-CbDDcomC.js";import{t as ue}from"./use-active-assistant-id-CXhDyK7y.js";import{t as de}from"./slack-setup-wizard-Dbiw6QLI.js";import{c as fe,i as pe,l as B,n as me,o as he,r as ge,s as _e,t as ve}from"./use-invite-link-dialog-sv9yVxhE.js";import{t as ye}from"./detail-card-BMRGmkia.js";import{n as be,t as xe}from"./mobile-sidebar-drawer-hLKPbhQ-.js";import{t as V}from"./mutation-error-zQ6oi-va.js";var H=e(t(),1),U=re(ne()(e=>({selectedAdapter:`slack`,selectAdapter:t=>e({selectedAdapter:t})}))),W={slack:{label:`Slack`,disconnectMessage:`This clears the stored Slack bot and app tokens for this assistant. You can reconnect later.`,hasTrustFloorControl:!1},telegram:{label:`Telegram`,disconnectMessage:`This clears the stored Telegram bot token for this assistant. You can reconnect later.`,hasTrustFloorControl:!0,disconnectedPitch:e=>`Connect a Telegram bot so ${e} can send and receive messages on Telegram.`},phone:{label:`Phone Calling`,disconnectMessage:`This clears the stored Twilio credentials for this assistant. You can reconnect later.`,hasTrustFloorControl:!0,disconnectedPitch:e=>`Connect your Twilio account so ${e} can make and answer phone calls.`}},G=l();function K({channels:e,selectedKey:t,onSelect:n}){return(0,G.jsx)(f.Root,{className:`flex h-full flex-col overflow-hidden`,children:(0,G.jsxs)(f.Body,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-4`,children:[(0,G.jsx)(`h2`,{className:`text-title-medium`,style:{color:`var(--content-default)`},children:`Channels`}),(0,G.jsx)(`div`,{className:`flex flex-col gap-1`,children:e.map(e=>(0,G.jsx)(Se,{channel:e,selected:e.key===t,onClick:()=>n(e.key)},e.key))})]})})}function Se({channel:e,selected:t,onClick:n}){let r=e.status===`ready`,i=h(e.key),a=r?`Connected`:`Not connected`;return(0,G.jsx)(te,{asChild:!0,active:t,label:`${i}, ${a}`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:n,className:`flex h-auto w-full items-center gap-2 rounded-[6px] px-[8px] py-2 text-left`,children:[(0,G.jsx)(v,{channelId:e.key,className:`h-4 w-4 shrink-0 text-[color:var(--content-secondary)]`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-body-medium-default`,children:i}),(0,G.jsx)(`span`,{className:`flex shrink-0 items-center`,children:(0,G.jsx)(N,{tone:r?`positive`:`neutral`,children:a})})]})})}function q({icon:e,title:t,description:n,action:r,className:i}){return(0,G.jsxs)(`div`,{className:u(`flex flex-col items-center justify-center gap-3 px-4 py-12 text-center`,i),children:[e?(0,G.jsx)(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-xl bg-[var(--surface-sunken)] text-[var(--content-tertiary)]`,children:e}):null,(0,G.jsx)(`h3`,{className:`text-title-small text-[var(--content-default)]`,children:t}),n?(0,G.jsx)(`p`,{className:`max-w-md text-body-medium-lighter text-[color:var(--content-tertiary)]`,children:n}):null,r?(0,G.jsx)(`div`,{className:`mt-1`,children:r}):null]})}function Ce({assistantDisplayName:e,policy:t,saving:n=!1,loading:r=!1,error:i=!1,onChange:a}){let o=t??`trusted_contacts`,s=fe(e),c=he.map(e=>({value:e,label:_e[e],tooltip:s[e]}));return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsxs)(d,{as:`span`,variant:`body-small-emphasised`,className:`text-[color:var(--content-secondary)]`,children:[`Who can message `,e]}),r?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:`Loading…`}):i?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-negative)]`,children:`Couldn’t load this setting. Try reopening this page.`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{style:{maxWidth:280},children:(0,G.jsx)(I,{value:o,onChange:a,options:c,disabled:n,"aria-label":`Who can message ${e}`})}),(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:s[o]}),o===`trusted_contacts`?(0,G.jsxs)(ee,{tone:`info`,className:`max-w-lg`,children:[`People you haven’t verified yet — even teammates in the same channel — can’t get through: `,e,` lets them know they need to be verified and notifies you. You can verify people ahead of time in Contacts.`]}):null]})]})}function we({address:e,pending:t,onDisconnect:r}){return(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(N,{tone:`positive`,leftIcon:(0,G.jsx)(x,{}),children:`Connected`}),e?(0,G.jsx)(`span`,{className:`text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:e}):null,(0,G.jsx)(`div`,{className:`ml-auto`,children:(0,G.jsx)(n,{type:`button`,variant:`danger`,onClick:r,disabled:!r||t,children:t?`Disconnecting…`:`Disconnect`})})]})}function Te({children:e}){return(0,G.jsxs)(f.Root,{children:[(0,G.jsx)(f.Header,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`img`,{src:z(`/images/integrations/slack.svg`),alt:``,className:`size-8 rounded-lg bg-[var(--surface-sunken)] p-1`}),(0,G.jsx)(d,{as:`span`,variant:`body-medium-default`,children:`Slack setup`})]})}),(0,G.jsx)(f.Body,{children:e})]})}var J=T.map(e=>e.riskThreshold),Y={none:{label:w(`none`).label,sublabel:`asks every time`,tone:`negative`,dotColor:`var(--system-negative-strong)`},low:{label:w(`low`).label,sublabel:`safe lookups`,tone:`warning`,dotColor:`var(--system-mid-strong)`},medium:{label:w(`medium`).label,sublabel:`broader lookups`,tone:`info`,dotColor:`var(--system-info-strong)`},high:{label:w(`high`).label,sublabel:`any lookup`,tone:`positive`,dotColor:`var(--system-positive-strong)`}},X=[`trusted_contact`,`unverified_contact`,`unknown`];function Ee(e,t){let n={};for(let r of e){if(r.selector.scope!==`channel`||r.selector.adapter!==t)continue;let e=r.selector.channelExternalId;e&&(r.contactType===`trusted_contact`||!(e in n))&&(n[e]=r.threshold)}return n}function Z(e,t,n){return n===`channels`?e.selector.scope===`adapter`&&e.selector.adapter===t:e.selector.scope===`channel_type`&&e.selector.adapter===t&&e.selector.channelType===`dm`}function Q(e,t,n){let r;for(let i of e)Z(i,t,n)&&(i.contactType===`trusted_contact`||r===void 0)&&(r=i.threshold);return r}function De({color:e}){return(0,G.jsx)(`span`,{"aria-hidden":`true`,className:`h-1.5 w-1.5 shrink-0 rounded-full`,style:{backgroundColor:e}})}function Oe({tier:e,defaultTier:t,disabled:n,onTierChange:r,onReset:i,"aria-label":a}){let o=e??t,s=J.map(e=>({value:e,label:Y[e].label,icon:(0,G.jsx)(De,{color:Y[e].dotColor}),suffix:e===t?(0,G.jsx)(`span`,{className:`text-[color:var(--content-tertiary)]`,children:`default`}):void 0,tooltip:Y[e].sublabel}));return(0,G.jsx)(I,{value:o??``,onChange:e=>{e===t?i():r(e)},options:s,placeholder:`Default`,disabled:n,size:`compact`,menuAlign:`end`,"aria-label":a})}function $(e){return e.type===`dm`?`dm`:e.isPrivate?`private`:`public`}function ke(e){return e.filter(e=>$(e)!==`dm`)}function Ae(e,t,n){let r=t.trim().toLowerCase();return e.filter(e=>(n===null||$(e)===n)&&(r===``||e.name.toLowerCase().includes(r))).sort((e,t)=>e.name.localeCompare(t.name))}function je(e){let t={public:0,private:0,dm:0};for(let n of e)t[$(n)]+=1;return t}function Me(e){return e.memberCount==null?null:e.memberCount===1?`1 member`:`${e.memberCount} members`}var Ne=[{value:null,label:`All`},{value:`public`,label:`Public`},{value:`private`,label:`Private`}],Pe={public:p,private:E},Fe=100,Ie=new Set;function Le({assistantDisplayName:e,slackHandle:t,channels:n,loading:r=!1,error:i=!1,tierOverrides:a,defaultTier:o=null,accessControlsSupported:s=!0,tierOverridesLoading:c=!1,tierOverridesError:l=!1,pendingChannelIds:f=Ie,onTierChange:m,onTierReset:h}){let[g,_]=(0,H.useState)(``),[v,y]=(0,H.useState)(null),b=(0,H.useMemo)(()=>ke(n??[]),[n]),x=(0,H.useMemo)(()=>Ae(b,g,v),[b,g,v]),S=(0,H.useMemo)(()=>je(b),[b]),C=t??`@${e}`;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,G.jsx)(d,{as:`p`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:(0,G.jsxs)(G.Fragment,{children:[`Add with`,` `,(0,G.jsxs)(`code`,{className:`text-[color:var(--content-secondary)]`,children:[`/invite `,C]}),` `,`or remove with`,` `,(0,G.jsxs)(`code`,{className:`text-[color:var(--content-secondary)]`,children:[`/remove `,C]}),` `,`in that Slack channel. Only channels `,e,` is in appear here.`]})}),r?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:`Loading…`}):i?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-negative)]`,children:`Couldn’t load channels. Try reopening this page.`}):b.length===0?(0,G.jsx)(q,{icon:(0,G.jsx)(p,{className:`h-6 w-6`}),title:`No channels yet`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`min-w-56 flex-1`,children:(0,G.jsx)(P,{type:`search`,value:g,onChange:e=>_(e.target.value),placeholder:`Search channels`,"aria-label":`Search channels`,leftIcon:(0,G.jsx)(O,{className:`h-4 w-4`}),fullWidth:!0})}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,role:`group`,"aria-label":`Filter channels by type`,children:Ne.map(({value:e,label:t})=>{let n=v===e,r=e===null?b.length:S[e];return(0,G.jsxs)(`button`,{type:`button`,"aria-pressed":n,onClick:()=>y(e),className:u(`inline-flex h-6 items-center rounded-full px-2.5 text-body-small-emphasised leading-none transition-colors`,n?`bg-[var(--content-default)] text-[var(--surface-base)]`:`bg-[var(--tag-bg-neutral)] text-[color:var(--content-secondary)] hover:text-[color:var(--content-default)]`),children:[t,` `,r]},e??`all`)})})]}),x.length===0?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`py-4 text-center text-[color:var(--content-tertiary)]`,children:`No channels match.`}):x.length>Fe?(0,G.jsx)(`div`,{className:`h-96`,children:(0,G.jsx)(j,{items:x,computeItemKey:(e,t)=>t.id,itemContent:(e,t)=>(0,G.jsx)(Re,{channel:t,pending:f.has(t.id),overridesLoading:c,overridesError:l,defaultTier:o,accessControls:s,tierOverride:a?.[t.id],onTierChange:e=>m?.(t.id,e),onReset:()=>h?.(t.id)}),className:`h-full`})}):(0,G.jsx)(`div`,{className:`max-h-96 overflow-y-auto`,children:x.map(e=>(0,G.jsx)(Re,{channel:e,pending:f.has(e.id),overridesLoading:c,overridesError:l,defaultTier:o,accessControls:s,tierOverride:a?.[e.id],onTierChange:t=>m?.(e.id,t),onReset:()=>h?.(e.id)},e.id))})]})]})}function Re({channel:e,pending:t,overridesLoading:n,overridesError:r,defaultTier:i,accessControls:a,tierOverride:o,onTierChange:s,onReset:c}){let l=$(e);if(l===`dm`)return null;let u=Pe[l],d=Me(e),f=`[&+&]:border-t [&+&]:border-[var(--border-base)]`;return a?(0,G.jsx)(S,{className:f,leading:(0,G.jsx)(u,{className:`h-4 w-4 text-[var(--content-tertiary)]`}),title:e.name,subtitle:d??void 0,trailing:(0,G.jsx)(`div`,{className:`w-40 sm:w-48`,children:(0,G.jsx)(Oe,{tier:o,defaultTier:i,disabled:t||n||r,onTierChange:s,onReset:c,"aria-label":`Assistant Access in ${e.name}`})})}):(0,G.jsx)(S,{className:f,leading:(0,G.jsx)(u,{className:`h-4 w-4 text-[var(--content-tertiary)]`}),title:e.name,trailing:d==null?void 0:(0,G.jsx)(`span`,{className:`text-body-small-default text-[color:var(--content-tertiary)]`,children:d})})}function ze(e,t){switch(e){case`none`:return`${t} replies, but asks you before looking anything up — even a web search.`;case`low`:return`Low-risk lookups run on their own: web searches, reading files in ${t}'s own workspace.`;case`medium`:return`Also allows medium-risk lookups to run on their own.`;case`high`:return`Any lookup runs on its own, including reads of sensitive local files.`}}function Be({assistantName:e,defaultTier:t}){return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,G.jsx)(d,{as:`span`,variant:`body-small-emphasised`,children:`Assistant Access levels`}),(0,G.jsxs)(d,{as:`p`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:[`Applies to other people in the channel — your own requests use your global Assistant Access. The levels only cover how much `,e,` `,`looks up on its own before answering; writing, sending, and spending always come to you first, at every level. Your`,` `,(0,G.jsx)(i,{to:oe.settings.privacy,className:`text-[var(--content-link)] underline hover:text-[var(--content-link-hover)]`,children:`Trust Rules`}),` `,`fine-tune when it asks.`]}),(0,G.jsx)(`ul`,{className:`grid gap-x-6 gap-y-3 sm:grid-cols-2`,children:J.map(n=>{let r=Y[n];return(0,G.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(De,{color:r.dotColor}),(0,G.jsx)(d,{as:`span`,variant:`body-small-emphasised`,children:r.label}),n===t?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:`· default`}):null]}),(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:ze(n,e)})]},n)})})]})}var Ve=[{bucket:`channels`,icon:p,title:`Channels`,description:`Public and private channels`},{bucket:`dm`,icon:D,title:`Direct messages`,description:`One-on-one DMs`}];function He({assistantName:e,globalDefaultTier:t,bucketTiers:n,loading:r,error:i,pendingBuckets:a,onBucketChange:o,onBucketReset:s}){return(0,G.jsxs)(f.Root,{children:[(0,G.jsx)(f.Header,{children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[`Default access`,(0,G.jsxs)(d,{as:`p`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:[`How much `,e,` does on its own, by conversation type. Individual channels can override this below.`]})]})}),(0,G.jsx)(f.Body,{className:`py-1`,children:Ve.map(({bucket:e,icon:c,title:l,description:u})=>{let d=e===`dm`?n?.channels??t:t;return(0,G.jsx)(S,{className:`[&+&]:border-t [&+&]:border-[var(--border-base)]`,leading:(0,G.jsx)(c,{className:`h-4 w-4 text-[var(--content-tertiary)]`}),title:l,subtitle:u,trailing:(0,G.jsx)(`div`,{className:`w-40 sm:w-48`,children:(0,G.jsx)(Oe,{tier:n?.[e],defaultTier:d,disabled:r||i||a.has(e),onTierChange:t=>o(e,t),onReset:()=>s(e),"aria-label":`Default Assistant Access for ${l}`})})},e)})}),(0,G.jsx)(f.Footer,{className:`p-0`,children:(0,G.jsx)(Be,{assistantName:e,defaultTier:t})})]})}var Ue=`0.10.8`;function We(){return ae(Ue)}function Ge(e,t,n){return X.map(r=>({selector:{scope:`channel`,adapter:e,channelExternalId:t},contactType:r,threshold:n}))}function Ke(e,t,n){return e.selector.scope===`channel`&&e.selector.adapter===t&&e.selector.channelExternalId===n}function qe(e,t){return t===`channels`?{scope:`adapter`,adapter:e}:{scope:`channel_type`,adapter:e,channelType:`dm`}}function Je(e,t,n){let r=qe(e,t);return X.map(e=>({selector:r,contactType:e,threshold:n}))}function Ye({assistantId:e,adapter:t}){let n=o(),r=We()&&!!e,i=(0,H.useMemo)(()=>({path:{assistant_id:e}}),[e]),a=(0,H.useMemo)(()=>g(i),[i]),l=(0,H.useMemo)(()=>[`channel-permission-resolve`,e,t],[e,t]),u=s({..._(i),enabled:r}),d=u.data?.cells,f=(0,H.useMemo)(()=>d?Ee(d,t):void 0,[d,t]),p=(0,H.useMemo)(()=>d?{channels:Q(d,t,`channels`),dm:Q(d,t,`dm`)}:void 0,[d,t]),m=s({queryKey:l,queryFn:async()=>{let{data:e}=await ce({...i,body:{adapter:t,contactType:`trusted_contact`},throwOnError:!0});return e.resolved?.threshold??null},enabled:r,retry:!1,staleTime:3e4}),h=(e,t)=>{let r=n.getQueryData(a),i=Date.now();return n.setQueryData(a,n=>({cells:[...(n?.cells??[]).filter(t=>!e(t)),...t.map(e=>({...e,updatedAt:i}))]})),{previous:r}},v=c({mutationFn:async({channelExternalId:e,tier:n})=>{await Promise.all(Ge(t,e,n).map(e=>L({...i,body:e,throwOnError:!0})))},onMutate:({channelExternalId:e,tier:n})=>h(n=>Ke(n,t,e),Ge(t,e,n)),onError:(e,t,r)=>{n.setQueryData(a,r?.previous),V(`Failed to save channel settings`)(e)},onSettled:()=>n.invalidateQueries({queryKey:a})}),y=c({mutationFn:async({channelExternalId:e})=>{await Promise.all(X.map(n=>R({...i,body:{selector:{scope:`channel`,adapter:t,channelExternalId:e},contactType:n},throwOnError:!0})))},onMutate:({channelExternalId:e})=>h(n=>Ke(n,t,e),[]),onError:(e,t,r)=>{n.setQueryData(a,r?.previous),V(`Failed to reset channel settings`)(e)},onSettled:()=>n.invalidateQueries({queryKey:a})}),b=c({mutationFn:async({bucket:e,tier:n})=>{await Promise.all(Je(t,e,n).map(e=>L({...i,body:e,throwOnError:!0})))},onMutate:({bucket:e,tier:n})=>h(n=>Z(n,t,e),Je(t,e,n)),onError:(e,t,r)=>{n.setQueryData(a,r?.previous),V(`Failed to save the default`)(e)},onSettled:(e,t,{bucket:r})=>{n.invalidateQueries({queryKey:a}),r===`channels`&&n.invalidateQueries({queryKey:l})}}),x=c({mutationFn:async({bucket:e})=>{let n=qe(t,e);await Promise.all(X.map(e=>R({...i,body:{selector:n,contactType:e},throwOnError:!0})))},onMutate:({bucket:e})=>h(n=>Z(n,t,e),[]),onError:(e,t,r)=>{n.setQueryData(a,r?.previous),V(`Failed to reset the default`)(e)},onSettled:(e,t,{bucket:r})=>{n.invalidateQueries({queryKey:a}),r===`channels`&&n.invalidateQueries({queryKey:l})}}),S=(0,H.useMemo)(()=>{let e=new Set;return v.isPending&&v.variables&&e.add(v.variables.channelExternalId),y.isPending&&y.variables&&e.add(y.variables.channelExternalId),e},[v.isPending,v.variables,y.isPending,y.variables]),C=(0,H.useMemo)(()=>{let e=new Set;return b.isPending&&b.variables&&e.add(b.variables.bucket),x.isPending&&x.variables&&e.add(x.variables.bucket),e},[b.isPending,b.variables,x.isPending,x.variables]);return!r||u.isError?{supported:!1,tierOverrides:void 0,defaultCellTier:void 0,bucketTiers:void 0,pendingChannelIds:new Set,pendingBuckets:new Set,isLoading:!1,isError:!1,onTierChange:void 0,onTierReset:void 0,onBucketChange:void 0,onBucketReset:void 0}:{supported:!0,tierOverrides:f,defaultCellTier:m.data,bucketTiers:p,pendingChannelIds:S,pendingBuckets:C,isLoading:u.isPending,isError:u.isError,onTierChange:(e,t)=>v.mutate({channelExternalId:e,tier:t}),onTierReset:e=>{f?.[e]!==void 0&&y.mutate({channelExternalId:e})},onBucketChange:(e,t)=>b.mutate({bucket:e,tier:t}),onBucketReset:e=>{p?.[e]!==void 0&&x.mutate({bucket:e})}}}function Xe({assistantId:e,assistantDisplayName:t,slackHandle:n}){let r=s({...y(e),enabled:!!e,select:e=>e.channels}),i=Ye({assistantId:e,adapter:`slack`}),a=s({queryKey:[`thresholds`,e],queryFn:()=>C(e),enabled:i.supported&&!!e,staleTime:3e4}).data?.interactive??null,o=i.defaultCellTier===void 0?null:i.defaultCellTier??a,c=(0,G.jsx)(Le,{assistantDisplayName:t,slackHandle:n,accessControlsSupported:i.supported,defaultTier:o,channels:r.data,loading:r.isPending,error:r.isError,tierOverrides:i.tierOverrides,tierOverridesLoading:i.isLoading,tierOverridesError:i.isError,pendingChannelIds:i.pendingChannelIds,onTierChange:i.onTierChange,onTierReset:i.onTierReset});return!i.supported||!i.onBucketChange||!i.onBucketReset?(0,G.jsx)(f.Root,{noPadding:!0,clipContents:!0,children:c}):(0,G.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,G.jsx)(He,{assistantName:t,globalDefaultTier:a,bucketTiers:i.bucketTiers,loading:i.isLoading,error:i.isError,pendingBuckets:i.pendingBuckets,onBucketChange:i.onBucketChange,onBucketReset:i.onBucketReset}),(0,G.jsx)(f.Root,{noPadding:!0,clipContents:!0,children:(0,G.jsx)(M.Root,{type:`single`,collapsible:!0,children:(0,G.jsxs)(M.Item,{value:`per-channel-overrides`,children:[(0,G.jsxs)(M.Trigger,{className:`group justify-between gap-2 px-4 py-3`,children:[(0,G.jsx)(d,{as:`span`,variant:`body-small-emphasised`,children:`Per-channel overrides`}),(0,G.jsx)(b,{"aria-hidden":`true`,className:`h-4 w-4 shrink-0 text-[var(--content-tertiary)] transition-transform group-data-[state=open]:rotate-180`})]}),(0,G.jsx)(M.Content,{className:`border-[var(--border-base)] data-[state=open]:border-t`,children:c})]})})})]})}function Ze({slackHandle:e,disconnectPending:t=!1,onDisconnect:r,children:i}){return(0,G.jsxs)(f.Root,{children:[(0,G.jsx)(f.Header,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`img`,{src:z(`/images/integrations/slack.svg`),alt:``,className:`size-8 rounded-lg bg-[var(--surface-sunken)] p-1`}),e?(0,G.jsx)(d,{as:`span`,variant:`body-medium-default`,children:e}):null,(0,G.jsx)(N,{tone:`positive`,leftIcon:(0,G.jsx)(x,{}),children:`Connected`}),(0,G.jsx)(`div`,{className:`ml-auto`,children:(0,G.jsx)(n,{type:`button`,variant:`ghost`,onClick:r,disabled:!r||t,children:t?`Disconnecting…`:`Disconnect`})})]})}),(0,G.jsx)(f.Body,{children:i})]})}function Qe({threadMode:e,threadModePending:t=!1,onThreadModeChange:n}){return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(d,{as:`span`,variant:`body-small-emphasised`,className:`text-[color:var(--content-secondary)]`,children:`Thread Behavior`}),(0,G.jsxs)(A,{value:e??`mention_then_thread`,onValueChange:e=>n?.(e),disabled:t||!n,"aria-label":`Slack thread behavior`,children:[(0,G.jsx)(k,{value:`mention_only`,label:`Mentions only`,helperText:`Bot only responds when @mentioned.`}),(0,G.jsx)(k,{value:`mention_then_thread`,label:`Follow threads after first mention`,helperText:`After an @mention in a thread, bot listens to all subsequent replies.`})]})]})}function $e({onSave:e}){let[t,r]=(0,H.useState)(``),[i,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(null),c=t.trim().length>0&&!i;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(P,{label:`Bot Token`,type:`password`,value:t,onChange:e=>r(e.target.value),placeholder:`Paste your Telegram bot token`,disabled:i,fullWidth:!0}),o?(0,G.jsx)(`p`,{className:`text-label-small`,style:{color:`var(--content-negative)`},children:o}):null,(0,G.jsx)(`div`,{children:(0,G.jsx)(n,{type:`button`,onClick:async()=>{if(!(!e||!c)){a(!0),s(null);try{await e(t.trim()),r(``)}catch(e){s(e instanceof Error?e.message:`Failed to save`)}finally{a(!1)}}},disabled:!c,children:i?`Saving…`:`Save`})})]})}function et({onSave:e}){let[t,r]=(0,H.useState)(``),[i,a]=(0,H.useState)(``),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(null),u=t.trim().length>0&&i.trim().length>0&&!o;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(P,{label:`Account SID`,type:`text`,value:t,onChange:e=>r(e.target.value),placeholder:`ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`,disabled:o,fullWidth:!0}),(0,G.jsx)(P,{label:`Auth Token`,type:`password`,value:i,onChange:e=>a(e.target.value),placeholder:`Twilio auth token`,disabled:o,fullWidth:!0}),c?(0,G.jsx)(`p`,{className:`text-label-small`,style:{color:`var(--content-negative)`},children:c}):null,(0,G.jsx)(`div`,{children:(0,G.jsx)(n,{type:`button`,onClick:async()=>{if(!(!e||!u)){s(!0),l(null);try{await e(t.trim(),i.trim()),r(``),a(``)}catch(e){l(e instanceof Error?e.message:`Failed to save`)}finally{s(!1)}}},disabled:!u,children:o?`Saving…`:`Save`})})]})}function tt({channel:e,assistantId:t,assistantName:r,assistantDisplayName:i,pending:a,initialManualEntry:o=!1,onSetup:s,onDisconnect:c,onSaveTelegramToken:l,onSaveSlackConfig:u,slackSaveStatus:d,slackSaveError:f,slackThreadMode:p,slackThreadModePending:m=!1,onSlackThreadModeChange:g,onSaveTwilioCredentials:_,policy:y,policySaving:b=!1,policyLoading:x=!1,policyError:S=!1,onPolicyChange:C}){let w=e.status===`ready`,[T,E]=(0,H.useState)(o);if(e.key===`slack`)return(0,G.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[w?(0,G.jsx)(Ze,{slackHandle:e.address,disconnectPending:a,onDisconnect:c,children:(0,G.jsx)(Qe,{threadMode:p,threadModePending:m,onThreadModeChange:g})}):(0,G.jsx)(Te,{children:(0,G.jsx)(de,{assistantName:r,onSave:u,saveStatus:d,saveError:f})}),w?(0,G.jsx)(Xe,{assistantId:t,assistantDisplayName:i,slackHandle:e.address}):null]});let D=W[e.key];return(0,G.jsx)(`div`,{className:`flex flex-col gap-4`,children:w?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(we,{address:e.address,pending:a,onDisconnect:c}),D.hasTrustFloorControl&&C?(0,G.jsx)(Ce,{assistantDisplayName:i,policy:y,saving:b,loading:x,error:S,onChange:C}):null]}):T?e.key===`telegram`?(0,G.jsx)($e,{onSave:l}):(0,G.jsx)(et,{onSave:_}):(0,G.jsx)(q,{icon:(0,G.jsx)(v,{channelId:e.key,className:`h-6 w-6`}),title:`${h(e.key)} isn't connected`,description:D.disconnectedPitch?.(i),action:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,G.jsx)(n,{type:`button`,variant:`outlined`,onClick:s,disabled:!s||a,children:a?`Opening…`:`Set up`}),(0,G.jsx)(n,{type:`button`,variant:`link`,onClick:()=>E(!0),children:`or connect manually`})]})})})}var nt={no_one:{title:`Block all messages?`,message:`Setting this channel to “No one” hard-denies every inbound message — including messages from you.
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./button-Dy5001j6.js";import{m as r,t as i,u as a}from"./chunk-5KNZJZUH-Bsoom5--.js";import{n as o}from"./QueryClientProvider-CMu7CkQU.js";import{t as s}from"./useQuery-Bz-fbQ-m.js";import{t as c}from"./useMutation-CXGTrp4W.js";import{t as l}from"./jsx-runtime-D3ZM-ToX.js";import{t as u}from"./cn-CJf7MmLX.js";import{t as d}from"./typography-DEI9Ra9z.js";import{t as f}from"./card-DRIctGVs.js";import{b as p,c as m,d as h,g,h as _,l as v,o as y}from"./use-save-twilio-credentials-dUedxPbM.js";import{t as b}from"./chevron-down-B5A-0g8A.js";import{t as x}from"./circle-check-big-DSsDH5_6.js";import{t as S}from"./list-row-B1wPb2Au.js";import{o as C,r as w,t as T,u as E}from"./threshold-presets-BO8En2q0.js";import{t as D}from"./message-square-CQGiY4zk.js";import{t as O}from"./search-BVW-n8to.js";import{t as ee}from"./notice-BMK7xqUw.js";import{M as k,N as A,a as j,i as M}from"./src-D89CNeuT.js";import{t as N}from"./tag-NXcyiTkK.js";import{t as P}from"./input-hw3el2GJ.js";import{t as te}from"./panel-item-CrtoJCrd.js";import{t as F}from"./confirm-dialog-UYFm4osC.js";import{t as I}from"./dropdown-BCfnSdIZ.js";import{n as ne,t as re}from"./create-selectors-Qo7kcikX.js";import{t as ie}from"./assistant-identity-store-DIyVo8LV.js";import{r as ae}from"./utils-CnB60ZJN.js";import{u as oe}from"./routes-vE-2hncW.js";import{n as se}from"./conversation-navigation-nuG3yn67.js";import{i as L,o as ce,r as R}from"./sdk.gen-DPKrJeho.js";import{t as le}from"./assistant-feature-flag-store-fyKSDJNN.js";import{t as z}from"./public-asset-CbDDcomC.js";import{t as ue}from"./use-active-assistant-id-CXhDyK7y.js";import{t as de}from"./slack-setup-wizard-CAVg-F3_.js";import{c as fe,i as pe,l as B,n as me,o as he,r as ge,s as _e,t as ve}from"./use-invite-link-dialog-Cvvpn0Hm.js";import{t as ye}from"./detail-card-BMRGmkia.js";import{n as be,t as xe}from"./mobile-sidebar-drawer-hLKPbhQ-.js";import{t as V}from"./mutation-error-zQ6oi-va.js";var H=e(t(),1),U=re(ne()(e=>({selectedAdapter:`slack`,selectAdapter:t=>e({selectedAdapter:t})}))),W={slack:{label:`Slack`,disconnectMessage:`This clears the stored Slack bot and app tokens for this assistant. You can reconnect later.`,hasTrustFloorControl:!1},telegram:{label:`Telegram`,disconnectMessage:`This clears the stored Telegram bot token for this assistant. You can reconnect later.`,hasTrustFloorControl:!0,disconnectedPitch:e=>`Connect a Telegram bot so ${e} can send and receive messages on Telegram.`},phone:{label:`Phone Calling`,disconnectMessage:`This clears the stored Twilio credentials for this assistant. You can reconnect later.`,hasTrustFloorControl:!0,disconnectedPitch:e=>`Connect your Twilio account so ${e} can make and answer phone calls.`}},G=l();function K({channels:e,selectedKey:t,onSelect:n}){return(0,G.jsx)(f.Root,{className:`flex h-full flex-col overflow-hidden`,children:(0,G.jsxs)(f.Body,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-4`,children:[(0,G.jsx)(`h2`,{className:`text-title-medium`,style:{color:`var(--content-default)`},children:`Channels`}),(0,G.jsx)(`div`,{className:`flex flex-col gap-1`,children:e.map(e=>(0,G.jsx)(Se,{channel:e,selected:e.key===t,onClick:()=>n(e.key)},e.key))})]})})}function Se({channel:e,selected:t,onClick:n}){let r=e.status===`ready`,i=h(e.key),a=r?`Connected`:`Not connected`;return(0,G.jsx)(te,{asChild:!0,active:t,label:`${i}, ${a}`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:n,className:`flex h-auto w-full items-center gap-2 rounded-[6px] px-[8px] py-2 text-left`,children:[(0,G.jsx)(v,{channelId:e.key,className:`h-4 w-4 shrink-0 text-[color:var(--content-secondary)]`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-body-medium-default`,children:i}),(0,G.jsx)(`span`,{className:`flex shrink-0 items-center`,children:(0,G.jsx)(N,{tone:r?`positive`:`neutral`,children:a})})]})})}function q({icon:e,title:t,description:n,action:r,className:i}){return(0,G.jsxs)(`div`,{className:u(`flex flex-col items-center justify-center gap-3 px-4 py-12 text-center`,i),children:[e?(0,G.jsx)(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-xl bg-[var(--surface-sunken)] text-[var(--content-tertiary)]`,children:e}):null,(0,G.jsx)(`h3`,{className:`text-title-small text-[var(--content-default)]`,children:t}),n?(0,G.jsx)(`p`,{className:`max-w-md text-body-medium-lighter text-[color:var(--content-tertiary)]`,children:n}):null,r?(0,G.jsx)(`div`,{className:`mt-1`,children:r}):null]})}function Ce({assistantDisplayName:e,policy:t,saving:n=!1,loading:r=!1,error:i=!1,onChange:a}){let o=t??`trusted_contacts`,s=fe(e),c=he.map(e=>({value:e,label:_e[e],tooltip:s[e]}));return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsxs)(d,{as:`span`,variant:`body-small-emphasised`,className:`text-[color:var(--content-secondary)]`,children:[`Who can message `,e]}),r?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:`Loading…`}):i?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-negative)]`,children:`Couldn’t load this setting. Try reopening this page.`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{style:{maxWidth:280},children:(0,G.jsx)(I,{value:o,onChange:a,options:c,disabled:n,"aria-label":`Who can message ${e}`})}),(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:s[o]}),o===`trusted_contacts`?(0,G.jsxs)(ee,{tone:`info`,className:`max-w-lg`,children:[`People you haven’t verified yet — even teammates in the same channel — can’t get through: `,e,` lets them know they need to be verified and notifies you. You can verify people ahead of time in Contacts.`]}):null]})]})}function we({address:e,pending:t,onDisconnect:r}){return(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(N,{tone:`positive`,leftIcon:(0,G.jsx)(x,{}),children:`Connected`}),e?(0,G.jsx)(`span`,{className:`text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:e}):null,(0,G.jsx)(`div`,{className:`ml-auto`,children:(0,G.jsx)(n,{type:`button`,variant:`danger`,onClick:r,disabled:!r||t,children:t?`Disconnecting…`:`Disconnect`})})]})}function Te({children:e}){return(0,G.jsxs)(f.Root,{children:[(0,G.jsx)(f.Header,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`img`,{src:z(`/images/integrations/slack.svg`),alt:``,className:`size-8 rounded-lg bg-[var(--surface-sunken)] p-1`}),(0,G.jsx)(d,{as:`span`,variant:`body-medium-default`,children:`Slack setup`})]})}),(0,G.jsx)(f.Body,{children:e})]})}var J=T.map(e=>e.riskThreshold),Y={none:{label:w(`none`).label,sublabel:`asks every time`,tone:`negative`,dotColor:`var(--system-negative-strong)`},low:{label:w(`low`).label,sublabel:`safe lookups`,tone:`warning`,dotColor:`var(--system-mid-strong)`},medium:{label:w(`medium`).label,sublabel:`broader lookups`,tone:`info`,dotColor:`var(--system-info-strong)`},high:{label:w(`high`).label,sublabel:`any lookup`,tone:`positive`,dotColor:`var(--system-positive-strong)`}},X=[`trusted_contact`,`unverified_contact`,`unknown`];function Ee(e,t){let n={};for(let r of e){if(r.selector.scope!==`channel`||r.selector.adapter!==t)continue;let e=r.selector.channelExternalId;e&&(r.contactType===`trusted_contact`||!(e in n))&&(n[e]=r.threshold)}return n}function Z(e,t,n){return n===`channels`?e.selector.scope===`adapter`&&e.selector.adapter===t:e.selector.scope===`channel_type`&&e.selector.adapter===t&&e.selector.channelType===`dm`}function Q(e,t,n){let r;for(let i of e)Z(i,t,n)&&(i.contactType===`trusted_contact`||r===void 0)&&(r=i.threshold);return r}function De({color:e}){return(0,G.jsx)(`span`,{"aria-hidden":`true`,className:`h-1.5 w-1.5 shrink-0 rounded-full`,style:{backgroundColor:e}})}function Oe({tier:e,defaultTier:t,disabled:n,onTierChange:r,onReset:i,"aria-label":a}){let o=e??t,s=J.map(e=>({value:e,label:Y[e].label,icon:(0,G.jsx)(De,{color:Y[e].dotColor}),suffix:e===t?(0,G.jsx)(`span`,{className:`text-[color:var(--content-tertiary)]`,children:`default`}):void 0,tooltip:Y[e].sublabel}));return(0,G.jsx)(I,{value:o??``,onChange:e=>{e===t?i():r(e)},options:s,placeholder:`Default`,disabled:n,size:`compact`,menuAlign:`end`,"aria-label":a})}function $(e){return e.type===`dm`?`dm`:e.isPrivate?`private`:`public`}function ke(e){return e.filter(e=>$(e)!==`dm`)}function Ae(e,t,n){let r=t.trim().toLowerCase();return e.filter(e=>(n===null||$(e)===n)&&(r===``||e.name.toLowerCase().includes(r))).sort((e,t)=>e.name.localeCompare(t.name))}function je(e){let t={public:0,private:0,dm:0};for(let n of e)t[$(n)]+=1;return t}function Me(e){return e.memberCount==null?null:e.memberCount===1?`1 member`:`${e.memberCount} members`}var Ne=[{value:null,label:`All`},{value:`public`,label:`Public`},{value:`private`,label:`Private`}],Pe={public:p,private:E},Fe=100,Ie=new Set;function Le({assistantDisplayName:e,slackHandle:t,channels:n,loading:r=!1,error:i=!1,tierOverrides:a,defaultTier:o=null,accessControlsSupported:s=!0,tierOverridesLoading:c=!1,tierOverridesError:l=!1,pendingChannelIds:f=Ie,onTierChange:m,onTierReset:h}){let[g,_]=(0,H.useState)(``),[v,y]=(0,H.useState)(null),b=(0,H.useMemo)(()=>ke(n??[]),[n]),x=(0,H.useMemo)(()=>Ae(b,g,v),[b,g,v]),S=(0,H.useMemo)(()=>je(b),[b]),C=t??`@${e}`;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,G.jsx)(d,{as:`p`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:(0,G.jsxs)(G.Fragment,{children:[`Add with`,` `,(0,G.jsxs)(`code`,{className:`text-[color:var(--content-secondary)]`,children:[`/invite `,C]}),` `,`or remove with`,` `,(0,G.jsxs)(`code`,{className:`text-[color:var(--content-secondary)]`,children:[`/remove `,C]}),` `,`in that Slack channel. Only channels `,e,` is in appear here.`]})}),r?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:`Loading…`}):i?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-negative)]`,children:`Couldn’t load channels. Try reopening this page.`}):b.length===0?(0,G.jsx)(q,{icon:(0,G.jsx)(p,{className:`h-6 w-6`}),title:`No channels yet`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`min-w-56 flex-1`,children:(0,G.jsx)(P,{type:`search`,value:g,onChange:e=>_(e.target.value),placeholder:`Search channels`,"aria-label":`Search channels`,leftIcon:(0,G.jsx)(O,{className:`h-4 w-4`}),fullWidth:!0})}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,role:`group`,"aria-label":`Filter channels by type`,children:Ne.map(({value:e,label:t})=>{let n=v===e,r=e===null?b.length:S[e];return(0,G.jsxs)(`button`,{type:`button`,"aria-pressed":n,onClick:()=>y(e),className:u(`inline-flex h-6 items-center rounded-full px-2.5 text-body-small-emphasised leading-none transition-colors`,n?`bg-[var(--content-default)] text-[var(--surface-base)]`:`bg-[var(--tag-bg-neutral)] text-[color:var(--content-secondary)] hover:text-[color:var(--content-default)]`),children:[t,` `,r]},e??`all`)})})]}),x.length===0?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`py-4 text-center text-[color:var(--content-tertiary)]`,children:`No channels match.`}):x.length>Fe?(0,G.jsx)(`div`,{className:`h-96`,children:(0,G.jsx)(j,{items:x,computeItemKey:(e,t)=>t.id,itemContent:(e,t)=>(0,G.jsx)(Re,{channel:t,pending:f.has(t.id),overridesLoading:c,overridesError:l,defaultTier:o,accessControls:s,tierOverride:a?.[t.id],onTierChange:e=>m?.(t.id,e),onReset:()=>h?.(t.id)}),className:`h-full`})}):(0,G.jsx)(`div`,{className:`max-h-96 overflow-y-auto`,children:x.map(e=>(0,G.jsx)(Re,{channel:e,pending:f.has(e.id),overridesLoading:c,overridesError:l,defaultTier:o,accessControls:s,tierOverride:a?.[e.id],onTierChange:t=>m?.(e.id,t),onReset:()=>h?.(e.id)},e.id))})]})]})}function Re({channel:e,pending:t,overridesLoading:n,overridesError:r,defaultTier:i,accessControls:a,tierOverride:o,onTierChange:s,onReset:c}){let l=$(e);if(l===`dm`)return null;let u=Pe[l],d=Me(e),f=`[&+&]:border-t [&+&]:border-[var(--border-base)]`;return a?(0,G.jsx)(S,{className:f,leading:(0,G.jsx)(u,{className:`h-4 w-4 text-[var(--content-tertiary)]`}),title:e.name,subtitle:d??void 0,trailing:(0,G.jsx)(`div`,{className:`w-40 sm:w-48`,children:(0,G.jsx)(Oe,{tier:o,defaultTier:i,disabled:t||n||r,onTierChange:s,onReset:c,"aria-label":`Assistant Access in ${e.name}`})})}):(0,G.jsx)(S,{className:f,leading:(0,G.jsx)(u,{className:`h-4 w-4 text-[var(--content-tertiary)]`}),title:e.name,trailing:d==null?void 0:(0,G.jsx)(`span`,{className:`text-body-small-default text-[color:var(--content-tertiary)]`,children:d})})}function ze(e,t){switch(e){case`none`:return`${t} replies, but asks you before looking anything up — even a web search.`;case`low`:return`Low-risk lookups run on their own: web searches, reading files in ${t}'s own workspace.`;case`medium`:return`Also allows medium-risk lookups to run on their own.`;case`high`:return`Any lookup runs on its own, including reads of sensitive local files.`}}function Be({assistantName:e,defaultTier:t}){return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,G.jsx)(d,{as:`span`,variant:`body-small-emphasised`,children:`Assistant Access levels`}),(0,G.jsxs)(d,{as:`p`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:[`Applies to other people in the channel — your own requests use your global Assistant Access. The levels only cover how much `,e,` `,`looks up on its own before answering; writing, sending, and spending always come to you first, at every level. Your`,` `,(0,G.jsx)(i,{to:oe.settings.privacy,className:`text-[var(--content-link)] underline hover:text-[var(--content-link-hover)]`,children:`Trust Rules`}),` `,`fine-tune when it asks.`]}),(0,G.jsx)(`ul`,{className:`grid gap-x-6 gap-y-3 sm:grid-cols-2`,children:J.map(n=>{let r=Y[n];return(0,G.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(De,{color:r.dotColor}),(0,G.jsx)(d,{as:`span`,variant:`body-small-emphasised`,children:r.label}),n===t?(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:`· default`}):null]}),(0,G.jsx)(d,{as:`span`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:ze(n,e)})]},n)})})]})}var Ve=[{bucket:`channels`,icon:p,title:`Channels`,description:`Public and private channels`},{bucket:`dm`,icon:D,title:`Direct messages`,description:`One-on-one DMs`}];function He({assistantName:e,globalDefaultTier:t,bucketTiers:n,loading:r,error:i,pendingBuckets:a,onBucketChange:o,onBucketReset:s}){return(0,G.jsxs)(f.Root,{children:[(0,G.jsx)(f.Header,{children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[`Default access`,(0,G.jsxs)(d,{as:`p`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:[`How much `,e,` does on its own, by conversation type. Individual channels can override this below.`]})]})}),(0,G.jsx)(f.Body,{className:`py-1`,children:Ve.map(({bucket:e,icon:c,title:l,description:u})=>{let d=e===`dm`?n?.channels??t:t;return(0,G.jsx)(S,{className:`[&+&]:border-t [&+&]:border-[var(--border-base)]`,leading:(0,G.jsx)(c,{className:`h-4 w-4 text-[var(--content-tertiary)]`}),title:l,subtitle:u,trailing:(0,G.jsx)(`div`,{className:`w-40 sm:w-48`,children:(0,G.jsx)(Oe,{tier:n?.[e],defaultTier:d,disabled:r||i||a.has(e),onTierChange:t=>o(e,t),onReset:()=>s(e),"aria-label":`Default Assistant Access for ${l}`})})},e)})}),(0,G.jsx)(f.Footer,{className:`p-0`,children:(0,G.jsx)(Be,{assistantName:e,defaultTier:t})})]})}var Ue=`0.10.8`;function We(){return ae(Ue)}function Ge(e,t,n){return X.map(r=>({selector:{scope:`channel`,adapter:e,channelExternalId:t},contactType:r,threshold:n}))}function Ke(e,t,n){return e.selector.scope===`channel`&&e.selector.adapter===t&&e.selector.channelExternalId===n}function qe(e,t){return t===`channels`?{scope:`adapter`,adapter:e}:{scope:`channel_type`,adapter:e,channelType:`dm`}}function Je(e,t,n){let r=qe(e,t);return X.map(e=>({selector:r,contactType:e,threshold:n}))}function Ye({assistantId:e,adapter:t}){let n=o(),r=We()&&!!e,i=(0,H.useMemo)(()=>({path:{assistant_id:e}}),[e]),a=(0,H.useMemo)(()=>g(i),[i]),l=(0,H.useMemo)(()=>[`channel-permission-resolve`,e,t],[e,t]),u=s({..._(i),enabled:r}),d=u.data?.cells,f=(0,H.useMemo)(()=>d?Ee(d,t):void 0,[d,t]),p=(0,H.useMemo)(()=>d?{channels:Q(d,t,`channels`),dm:Q(d,t,`dm`)}:void 0,[d,t]),m=s({queryKey:l,queryFn:async()=>{let{data:e}=await ce({...i,body:{adapter:t,contactType:`trusted_contact`},throwOnError:!0});return e.resolved?.threshold??null},enabled:r,retry:!1,staleTime:3e4}),h=(e,t)=>{let r=n.getQueryData(a),i=Date.now();return n.setQueryData(a,n=>({cells:[...(n?.cells??[]).filter(t=>!e(t)),...t.map(e=>({...e,updatedAt:i}))]})),{previous:r}},v=c({mutationFn:async({channelExternalId:e,tier:n})=>{await Promise.all(Ge(t,e,n).map(e=>L({...i,body:e,throwOnError:!0})))},onMutate:({channelExternalId:e,tier:n})=>h(n=>Ke(n,t,e),Ge(t,e,n)),onError:(e,t,r)=>{n.setQueryData(a,r?.previous),V(`Failed to save channel settings`)(e)},onSettled:()=>n.invalidateQueries({queryKey:a})}),y=c({mutationFn:async({channelExternalId:e})=>{await Promise.all(X.map(n=>R({...i,body:{selector:{scope:`channel`,adapter:t,channelExternalId:e},contactType:n},throwOnError:!0})))},onMutate:({channelExternalId:e})=>h(n=>Ke(n,t,e),[]),onError:(e,t,r)=>{n.setQueryData(a,r?.previous),V(`Failed to reset channel settings`)(e)},onSettled:()=>n.invalidateQueries({queryKey:a})}),b=c({mutationFn:async({bucket:e,tier:n})=>{await Promise.all(Je(t,e,n).map(e=>L({...i,body:e,throwOnError:!0})))},onMutate:({bucket:e,tier:n})=>h(n=>Z(n,t,e),Je(t,e,n)),onError:(e,t,r)=>{n.setQueryData(a,r?.previous),V(`Failed to save the default`)(e)},onSettled:(e,t,{bucket:r})=>{n.invalidateQueries({queryKey:a}),r===`channels`&&n.invalidateQueries({queryKey:l})}}),x=c({mutationFn:async({bucket:e})=>{let n=qe(t,e);await Promise.all(X.map(e=>R({...i,body:{selector:n,contactType:e},throwOnError:!0})))},onMutate:({bucket:e})=>h(n=>Z(n,t,e),[]),onError:(e,t,r)=>{n.setQueryData(a,r?.previous),V(`Failed to reset the default`)(e)},onSettled:(e,t,{bucket:r})=>{n.invalidateQueries({queryKey:a}),r===`channels`&&n.invalidateQueries({queryKey:l})}}),S=(0,H.useMemo)(()=>{let e=new Set;return v.isPending&&v.variables&&e.add(v.variables.channelExternalId),y.isPending&&y.variables&&e.add(y.variables.channelExternalId),e},[v.isPending,v.variables,y.isPending,y.variables]),C=(0,H.useMemo)(()=>{let e=new Set;return b.isPending&&b.variables&&e.add(b.variables.bucket),x.isPending&&x.variables&&e.add(x.variables.bucket),e},[b.isPending,b.variables,x.isPending,x.variables]);return!r||u.isError?{supported:!1,tierOverrides:void 0,defaultCellTier:void 0,bucketTiers:void 0,pendingChannelIds:new Set,pendingBuckets:new Set,isLoading:!1,isError:!1,onTierChange:void 0,onTierReset:void 0,onBucketChange:void 0,onBucketReset:void 0}:{supported:!0,tierOverrides:f,defaultCellTier:m.data,bucketTiers:p,pendingChannelIds:S,pendingBuckets:C,isLoading:u.isPending,isError:u.isError,onTierChange:(e,t)=>v.mutate({channelExternalId:e,tier:t}),onTierReset:e=>{f?.[e]!==void 0&&y.mutate({channelExternalId:e})},onBucketChange:(e,t)=>b.mutate({bucket:e,tier:t}),onBucketReset:e=>{p?.[e]!==void 0&&x.mutate({bucket:e})}}}function Xe({assistantId:e,assistantDisplayName:t,slackHandle:n}){let r=s({...y(e),enabled:!!e,select:e=>e.channels}),i=Ye({assistantId:e,adapter:`slack`}),a=s({queryKey:[`thresholds`,e],queryFn:()=>C(e),enabled:i.supported&&!!e,staleTime:3e4}).data?.interactive??null,o=i.defaultCellTier===void 0?null:i.defaultCellTier??a,c=(0,G.jsx)(Le,{assistantDisplayName:t,slackHandle:n,accessControlsSupported:i.supported,defaultTier:o,channels:r.data,loading:r.isPending,error:r.isError,tierOverrides:i.tierOverrides,tierOverridesLoading:i.isLoading,tierOverridesError:i.isError,pendingChannelIds:i.pendingChannelIds,onTierChange:i.onTierChange,onTierReset:i.onTierReset});return!i.supported||!i.onBucketChange||!i.onBucketReset?(0,G.jsx)(f.Root,{noPadding:!0,clipContents:!0,children:c}):(0,G.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,G.jsx)(He,{assistantName:t,globalDefaultTier:a,bucketTiers:i.bucketTiers,loading:i.isLoading,error:i.isError,pendingBuckets:i.pendingBuckets,onBucketChange:i.onBucketChange,onBucketReset:i.onBucketReset}),(0,G.jsx)(f.Root,{noPadding:!0,clipContents:!0,children:(0,G.jsx)(M.Root,{type:`single`,collapsible:!0,children:(0,G.jsxs)(M.Item,{value:`per-channel-overrides`,children:[(0,G.jsxs)(M.Trigger,{className:`group justify-between gap-2 px-4 py-3`,children:[(0,G.jsx)(d,{as:`span`,variant:`body-small-emphasised`,children:`Per-channel overrides`}),(0,G.jsx)(b,{"aria-hidden":`true`,className:`h-4 w-4 shrink-0 text-[var(--content-tertiary)] transition-transform group-data-[state=open]:rotate-180`})]}),(0,G.jsx)(M.Content,{className:`border-[var(--border-base)] data-[state=open]:border-t`,children:c})]})})})]})}function Ze({slackHandle:e,disconnectPending:t=!1,onDisconnect:r,children:i}){return(0,G.jsxs)(f.Root,{children:[(0,G.jsx)(f.Header,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`img`,{src:z(`/images/integrations/slack.svg`),alt:``,className:`size-8 rounded-lg bg-[var(--surface-sunken)] p-1`}),e?(0,G.jsx)(d,{as:`span`,variant:`body-medium-default`,children:e}):null,(0,G.jsx)(N,{tone:`positive`,leftIcon:(0,G.jsx)(x,{}),children:`Connected`}),(0,G.jsx)(`div`,{className:`ml-auto`,children:(0,G.jsx)(n,{type:`button`,variant:`ghost`,onClick:r,disabled:!r||t,children:t?`Disconnecting…`:`Disconnect`})})]})}),(0,G.jsx)(f.Body,{children:i})]})}function Qe({threadMode:e,threadModePending:t=!1,onThreadModeChange:n}){return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(d,{as:`span`,variant:`body-small-emphasised`,className:`text-[color:var(--content-secondary)]`,children:`Thread Behavior`}),(0,G.jsxs)(A,{value:e??`mention_then_thread`,onValueChange:e=>n?.(e),disabled:t||!n,"aria-label":`Slack thread behavior`,children:[(0,G.jsx)(k,{value:`mention_only`,label:`Mentions only`,helperText:`Bot only responds when @mentioned.`}),(0,G.jsx)(k,{value:`mention_then_thread`,label:`Follow threads after first mention`,helperText:`After an @mention in a thread, bot listens to all subsequent replies.`})]})]})}function $e({onSave:e}){let[t,r]=(0,H.useState)(``),[i,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(null),c=t.trim().length>0&&!i;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(P,{label:`Bot Token`,type:`password`,value:t,onChange:e=>r(e.target.value),placeholder:`Paste your Telegram bot token`,disabled:i,fullWidth:!0}),o?(0,G.jsx)(`p`,{className:`text-label-small`,style:{color:`var(--content-negative)`},children:o}):null,(0,G.jsx)(`div`,{children:(0,G.jsx)(n,{type:`button`,onClick:async()=>{if(!(!e||!c)){a(!0),s(null);try{await e(t.trim()),r(``)}catch(e){s(e instanceof Error?e.message:`Failed to save`)}finally{a(!1)}}},disabled:!c,children:i?`Saving…`:`Save`})})]})}function et({onSave:e}){let[t,r]=(0,H.useState)(``),[i,a]=(0,H.useState)(``),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(null),u=t.trim().length>0&&i.trim().length>0&&!o;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(P,{label:`Account SID`,type:`text`,value:t,onChange:e=>r(e.target.value),placeholder:`ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`,disabled:o,fullWidth:!0}),(0,G.jsx)(P,{label:`Auth Token`,type:`password`,value:i,onChange:e=>a(e.target.value),placeholder:`Twilio auth token`,disabled:o,fullWidth:!0}),c?(0,G.jsx)(`p`,{className:`text-label-small`,style:{color:`var(--content-negative)`},children:c}):null,(0,G.jsx)(`div`,{children:(0,G.jsx)(n,{type:`button`,onClick:async()=>{if(!(!e||!u)){s(!0),l(null);try{await e(t.trim(),i.trim()),r(``),a(``)}catch(e){l(e instanceof Error?e.message:`Failed to save`)}finally{s(!1)}}},disabled:!u,children:o?`Saving…`:`Save`})})]})}function tt({channel:e,assistantId:t,assistantName:r,assistantDisplayName:i,pending:a,initialManualEntry:o=!1,onSetup:s,onDisconnect:c,onSaveTelegramToken:l,onSaveSlackConfig:u,slackSaveStatus:d,slackSaveError:f,slackThreadMode:p,slackThreadModePending:m=!1,onSlackThreadModeChange:g,onSaveTwilioCredentials:_,policy:y,policySaving:b=!1,policyLoading:x=!1,policyError:S=!1,onPolicyChange:C}){let w=e.status===`ready`,[T,E]=(0,H.useState)(o);if(e.key===`slack`)return(0,G.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[w?(0,G.jsx)(Ze,{slackHandle:e.address,disconnectPending:a,onDisconnect:c,children:(0,G.jsx)(Qe,{threadMode:p,threadModePending:m,onThreadModeChange:g})}):(0,G.jsx)(Te,{children:(0,G.jsx)(de,{assistantName:r,onSave:u,saveStatus:d,saveError:f})}),w?(0,G.jsx)(Xe,{assistantId:t,assistantDisplayName:i,slackHandle:e.address}):null]});let D=W[e.key];return(0,G.jsx)(`div`,{className:`flex flex-col gap-4`,children:w?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(we,{address:e.address,pending:a,onDisconnect:c}),D.hasTrustFloorControl&&C?(0,G.jsx)(Ce,{assistantDisplayName:i,policy:y,saving:b,loading:x,error:S,onChange:C}):null]}):T?e.key===`telegram`?(0,G.jsx)($e,{onSave:l}):(0,G.jsx)(et,{onSave:_}):(0,G.jsx)(q,{icon:(0,G.jsx)(v,{channelId:e.key,className:`h-6 w-6`}),title:`${h(e.key)} isn't connected`,description:D.disconnectedPitch?.(i),action:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,G.jsx)(n,{type:`button`,variant:`outlined`,onClick:s,disabled:!s||a,children:a?`Opening…`:`Set up`}),(0,G.jsx)(n,{type:`button`,variant:`link`,onClick:()=>E(!0),children:`or connect manually`})]})})})}var nt={no_one:{title:`Block all messages?`,message:`Setting this channel to “No one” hard-denies every inbound message — including messages from you.
2
2
 
3
3
  You can reverse this at any time.`,confirmLabel:`Block all`,destructive:!0},any_contact:{title:`Allow any contact?`,message:`“Any contact” admits every matched contact in this channel — including pending, unverified ones — not just your verified contacts.
4
4
 
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./button-Dy5001j6.js";import{m as r,n as i,u as a}from"./chunk-5KNZJZUH-Bsoom5--.js";import{n as o}from"./QueryClientProvider-CMu7CkQU.js";import{t as s}from"./useQuery-Bz-fbQ-m.js";import{t as c}from"./useMutation-CXGTrp4W.js";import{t as l}from"./jsx-runtime-D3ZM-ToX.js";import{t as u}from"./typography-DEI9Ra9z.js";import{t as d}from"./card-DRIctGVs.js";import{t as f}from"./createLucideIcon-CAM1RhH8.js";import{t as p}from"./arrow-left-C2ylPLHq.js";import{t as m}from"./arrow-right-B-jRJNWP.js";import{a as h,b as g,c as _,d as v,l as y,x as b,y as x}from"./use-save-twilio-credentials-CUQ6gdIj.js";import{t as S}from"./circle-check-big-DSsDH5_6.js";import{t as C}from"./link-2-BKL8QWRX.js";import{t as w}from"./loader-circle-XREx3i4W.js";import{t as T}from"./mail-CMdPNysl.js";import{t as E}from"./message-square-CQGiY4zk.js";import{t as D}from"./pencil-D38YNe2r.js";import{t as O}from"./plus-jH3kAliM.js";import{t as k}from"./search-BVW-n8to.js";import{t as A}from"./send-Q71Exj3z.js";import{t as j}from"./user-plus-oiIr9ey8.js";import{t as M}from"./tag-NXcyiTkK.js";import{t as N}from"./input-hw3el2GJ.js";import{t as P}from"./modal-BR4CUFBd.js";import{t as F}from"./panel-item-CrtoJCrd.js";import{n as ee}from"./toast-LgLp4obE.js";import{t as I}from"./confirm-dialog-UYFm4osC.js";import{C as te}from"./sdk.gen-BVAVE6A_.js";import{Ht as ne,S as L,Ut as re,a as ie,b as ae,x as oe}from"./react-query.gen-r3I6j8-1.js";import{t as se}from"./assistant-identity-store-DIyVo8LV.js";import{u as ce}from"./routes-vE-2hncW.js";import{n as R}from"./conversation-navigation-nuG3yn67.js";import{t as le}from"./assistant-feature-flag-store-fyKSDJNN.js";import{t as z}from"./use-active-assistant-id-CXhDyK7y.js";import{i as ue,l as de,n as fe,r as B,t as pe}from"./use-invite-link-dialog-sv9yVxhE.js";import{t as V}from"./detail-card-BMRGmkia.js";import{n as me,t as he}from"./mobile-sidebar-drawer-hLKPbhQ-.js";import{t as H}from"./mutation-error-zQ6oi-va.js";import{a as ge,i as _e,n as U,t as ve}from"./contacts-gateway-CFNbQjfX.js";var ye=f(`circle-question-mark`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),W=f(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),be=f(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),G=e(t(),1),xe=new Set([`slack`]);function K(e){return e.status===`verified`||e.status===`active`&&e.verifiedAt!=null}var q=l();function Se({channels:e,pendingChannelKey:t=null,onConnect:n,onDisconnect:r}){let[i,a]=(0,G.useState)(null);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`flex flex-col`,children:e.map((e,i)=>(0,q.jsxs)(`div`,{children:[i>0?(0,q.jsx)(`div`,{className:`border-t`,style:{borderColor:`var(--border-base)`}}):null,(0,q.jsx)(J,{channel:e,pending:t===e.key,onConnect:n?()=>n(e.key):void 0,onDisconnect:r?()=>a(e.key):void 0})]},e.key))}),(0,q.jsx)(I,{open:i!==null,title:`Disconnect ${i?v(i):``}?`,message:`This clears the stored credentials for this channel. You can reconnect later.`,confirmLabel:`Disconnect`,destructive:!0,onConfirm:()=>{i&&r&&r(i),a(null)},onCancel:()=>a(null)})]})}function J({channel:e,pending:t,onConnect:r,onDisconnect:i}){let a=e.status===`ready`;return(0,q.jsxs)(`div`,{className:`flex items-center gap-3 py-4`,children:[(0,q.jsx)(y,{channelId:e.key,className:`h-4 w-4 shrink-0 text-[color:var(--content-secondary)]`}),(0,q.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:v(e.key)}),a&&e.address?(0,q.jsx)(`span`,{className:`truncate text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:e.address}):null,(0,q.jsx)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:a?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 h-8 px-2.5 rounded-md whitespace-nowrap select-none text-body-small-emphasised leading-none bg-[var(--content-default)] text-[var(--surface-base)]`,children:[(0,q.jsx)(S,{className:`h-3 w-3`}),`Connected`]}),(0,q.jsx)(n,{variant:`danger`,onClick:i,disabled:!i||t,children:t?`Disconnecting…`:`Disconnect`})]}):(0,q.jsx)(n,{variant:`outlined`,onClick:r,disabled:!r||t,children:`Connect`})})]})}function Y({role:e,contactType:t}){let{label:n,tone:r}=X(e,t);return(0,q.jsx)(M,{tone:r,children:n})}function X(e,t){switch(e){case`guardian`:return{label:`Guardian`,tone:`positive`};case`assistant`:return{label:`Assistant`,tone:`negative`};default:return t===`assistant`?{label:`Assistant`,tone:`negative`}:{label:`Human`,tone:`warning`}}}function Ce({assistantName:e,...t}){let n=de(e);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,q.jsx)(V,{title:`${n} (Your Assistant)`,accessory:(0,q.jsx)(Y,{role:`assistant`}),compactAccessory:!0}),(0,q.jsx)(V,{title:`Channels`,subtitle:`Where ${n} can be reached.`,children:(0,q.jsx)(Se,{...t})})]})}var Z=new Set([`telegram`,`phone`,`vellum`,`whatsapp`,`slack`,`email`,`platform`,`a2a`]);function we(e){return Z.has(e)}function Te(e,t){return e.id===`a2a`?t&&t.status!==`revoked`?{kind:`connected`}:{kind:`setup`}:t!=null&&K(t)?{kind:`verified`}:t?.status===`blocked`?{kind:`none`}:t&&t.status!==`revoked`?{kind:`unverified`}:{kind:`setup`}}function Ee(e,t,n){let r=[],i=new Set;if(e)for(let t of e)t.id===`a2a`&&!n||(r.push(t),i.add(t.id));for(let e of t)e.status===`revoked`||i.has(e.type)||e.type===`a2a`&&!n||we(e.type)&&(r.push({id:e.type,label:e.type.charAt(0).toUpperCase()+e.type.slice(1),subtitle:``,icon:`help-circle`,supportsVerification:!1,setupMessages:{guardian:``,contact:``}}),i.add(e.type));return r}function Q({name:e,className:t,style:n}){switch(e){case`bot`:return(0,q.jsx)(b,{className:t,style:n});case`hash`:return(0,q.jsx)(g,{className:t,style:n});case`send`:return(0,q.jsx)(A,{className:t,style:n});case`phone`:return(0,q.jsx)(x,{className:t,style:n});case`mail`:return(0,q.jsx)(T,{className:t,style:n});case`message-square`:return(0,q.jsx)(E,{className:t,style:n});default:return(0,q.jsx)(ye,{className:t,style:n})}}function $({contactChannels:e,availableChannels:t,a2aEnabled:n,setupLabel:r=`Invite`,verifyLoading:i,verifySubject:a=`self`,onSetupChannel:o,onVerifyChannel:s,onRevokeChannel:c,onLinkAccount:l}){let[u,d]=(0,G.useState)(null),[f,p]=(0,G.useState)(null),m=new Map;for(let t of e)t.status!==`revoked`&&(m.has(t.type)||m.set(t.type,t));return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`flex flex-col`,children:Ee(t,e,n).map((e,t)=>{let n=m.get(e.id);return(0,q.jsxs)(`div`,{children:[t>0&&(0,q.jsx)(`div`,{className:`border-t`,style:{borderColor:`var(--border-base)`}}),(0,q.jsx)(De,{info:e,existing:n,setupLabel:r,verifyLoading:i,onSetup:o?()=>o(e.id):void 0,onVerify:s&&e.supportsVerification?()=>d(e):void 0,onRevoke:c&&n?()=>p({channelId:n.id,channel:e}):void 0,onLinkAccount:l&&xe.has(e.id)?()=>l(e.id):void 0})]},e.id)})}),u&&(0,q.jsx)(I,{open:!0,title:`Verify ${u.label}`,message:a===`contact`?`This will mark this contact's ${u.label} channel as verified. Your assistant will recognize them when they reach out from it.`:`This will mark your ${u.label} channel as verified. Your assistant will recognize you when you reach out from it.`,confirmLabel:`Verify`,onConfirm:()=>{u&&(s?.(u.id),d(null))},onCancel:()=>d(null)}),f&&(0,q.jsx)(I,{open:!0,title:`Revoke ${f.channel.label}`,message:`This will disconnect the verified channel. The contact will need to re-verify to use this channel again.`,confirmLabel:`Revoke`,destructive:!0,onConfirm:()=>{c?.(f.channelId,f.channel.id),p(null)},onCancel:()=>p(null)})]})}function De({info:e,existing:t,setupLabel:r,verifyLoading:i,onSetup:a,onVerify:o,onRevoke:s,onLinkAccount:c}){let l=Te(e,t);return(0,q.jsxs)(`div`,{className:`flex items-center gap-3 py-4`,children:[(0,q.jsx)(Q,{name:e.icon,className:`h-4 w-4 shrink-0`,style:{color:`var(--content-secondary)`}}),(0,q.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:e.label}),t?.address?(0,q.jsx)(`span`,{className:`truncate text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:t.address}):null,(0,q.jsx)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:l.kind===`connected`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 h-8 px-2.5 rounded-md whitespace-nowrap select-none text-body-small-emphasised leading-none bg-[var(--content-default)] text-[var(--surface-base)]`,children:[(0,q.jsx)(S,{className:`h-3 w-3`}),`Connected`]}),s?(0,q.jsx)(n,{variant:`danger`,onClick:s,children:`Revoke`}):null]}):l.kind===`verified`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 h-8 px-2.5 rounded-md whitespace-nowrap select-none text-body-small-emphasised leading-none bg-[var(--content-default)] text-[var(--surface-base)]`,children:[(0,q.jsx)(S,{className:`h-3 w-3`}),`Verified`]}),s?(0,q.jsx)(n,{variant:`danger`,onClick:s,children:`Revoke`}):null]}):l.kind===`unverified`?(0,q.jsx)(n,{variant:`outlined`,onClick:o,disabled:!o||i,children:i?`Verifying…`:`Verify`}):l.kind===`setup`?e.id===`a2a`?null:(0,q.jsxs)(q.Fragment,{children:[c?(0,q.jsxs)(n,{onClick:c,children:[(0,q.jsx)(C,{className:`h-3.5 w-3.5`}),`Link account`]}):null,(0,q.jsx)(n,{variant:`outlined`,onClick:a,disabled:!a,children:r})]}):null})]})}function Oe(e){return(0,q.jsx)(ke,{...e},e.contact.id)}function ke({contact:e,savePending:t,deletePending:r,verifyPending:i,mergePending:a=!1,canMerge:o=!1,availableChannels:s,a2aEnabled:c,onSave:l,onDelete:u,onMerge:d,onSetupChannel:f,onVerifyChannel:p,onRevokeChannel:m,onLinkAccount:h}){let g=e.displayName===`New Contact`,[_,v]=(0,G.useState)(g?``:e.displayName),[y,b]=(0,G.useState)(e.notes??``),[x,S]=(0,G.useState)(!1),C=_.trim(),w=y.trim(),T=g?``:e.displayName,E=e.notes??``,D=C!==T||w!==E,O=C.length>0&&D&&!t&&!r,k=g&&e.channels.length===0&&e.interactionCount===0,A=C||e.displayName,j=`${e.interactionCount} interaction${e.interactionCount===1?``:`s`}`;return(0,q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,q.jsx)(V,{title:A,accessory:(0,q.jsx)(Y,{role:e.role,contactType:e.contactType}),compactAccessory:!0,subtitle:j,children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsx)(N,{label:`Name`,type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`Give this human a name`,autoFocus:g,disabled:t||r,fullWidth:!0}),(0,q.jsx)(N,{label:`Notes`,type:`text`,value:y,onChange:e=>b(e.target.value),placeholder:`Optional notes about the human which AI will take into account`,disabled:t||r,fullWidth:!0}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsx)(n,{type:`button`,onClick:()=>l({displayName:C,notes:w}),disabled:!O,children:t?`Saving…`:`Save`}),d?(0,q.jsx)(n,{type:`button`,variant:`outlined`,onClick:d,disabled:!o||k||D||a||t||r,title:o?k?`Save this contact before merging`:D?`Save your changes before merging`:void 0:`No other contacts available to merge`,children:a?`Merging…`:`Merge…`}):null,(0,q.jsx)(n,{type:`button`,variant:`danger`,onClick:()=>{k?u():S(!0)},disabled:r,children:r?`Deleting…`:`Delete Contact`})]})]})}),(0,q.jsx)(V,{title:`Linked accounts`,subtitle:`Where the assistant recognizes this contact. Link accounts you know, invite the ones you don't.`,children:(0,q.jsx)($,{contactChannels:e.channels,availableChannels:s,a2aEnabled:c,verifyLoading:i,verifySubject:`contact`,onSetupChannel:f,onVerifyChannel:p,onRevokeChannel:m,onLinkAccount:h})}),(0,q.jsx)(I,{open:x,title:`Delete ${e.displayName}?`,message:`This will permanently delete this contact and all their channels. This action cannot be undone.`,confirmLabel:`Delete`,destructive:!0,onConfirm:()=>{S(!1),u()},onCancel:()=>S(!1)})]})}function Ae(e){return(0,q.jsx)(je,{...e},`${e.survivor.id}:${e.open?`open`:`closed`}`)}function je({open:e,survivor:t,candidates:r,pending:i,errorMessage:a,onMerge:o,onClose:s}){let[c,l]=(0,G.useState)(``),[d,f]=(0,G.useState)(null);(0,G.useEffect)(()=>{d&&!r.some(e=>e.id===d)&&f(null)},[r,d]);let m=(0,G.useMemo)(()=>{let e=c.trim().toLowerCase();return e?r.filter(t=>t.displayName.toLowerCase().includes(e)):r},[r,c]),h=d?r.find(e=>e.id===d)??null:null,g=Ie(t);return(0,q.jsx)(P.Root,{open:e,onOpenChange:e=>{!e&&!i&&s()},children:(0,q.jsxs)(P.Content,{size:`md`,children:[(0,q.jsxs)(P.Header,{children:[(0,q.jsx)(P.Title,{icon:be,children:h?`Merge "${h.displayName}" into ${g}?`:`Merge another contact into ${g}`}),(0,q.jsx)(P.Description,{children:h?`Channels and notes from the merged contact will move over. The merged contact will be deleted.`:`The contact you pick will be deleted. Its channels and notes will be added to this one.`})]}),(0,q.jsxs)(P.Body,{className:`flex flex-col gap-3`,children:[h?(0,q.jsx)(Pe,{survivor:t,donor:h}):r.length===0?(0,q.jsx)(Fe,{}):(0,q.jsx)(Me,{search:c,onSearch:l,candidates:m,onPick:f}),a?(0,q.jsx)(u,{as:`p`,variant:`body-small-default`,className:`text-(--system-negative-strong)`,role:`alert`,children:a}):null]}),(0,q.jsx)(P.Footer,{children:h?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(n,{variant:`outlined`,onClick:()=>f(null),disabled:i,leftIcon:(0,q.jsx)(p,{"aria-hidden":!0}),children:`Back`}),(0,q.jsx)(n,{variant:`danger`,onClick:()=>o(h.id),disabled:i,children:i?`Merging…`:`Merge`})]}):(0,q.jsx)(n,{variant:`outlined`,onClick:s,disabled:i,children:`Cancel`})})]})})}function Me({search:e,onSearch:t,candidates:n,onPick:r}){return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(N,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Search contacts`,leftIcon:(0,q.jsx)(k,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),fullWidth:!0}),(0,q.jsx)(`div`,{className:`flex max-h-[320px] min-h-[120px] flex-col gap-1 overflow-y-auto`,role:`listbox`,"aria-label":`Select a contact to merge`,children:n.length===0?(0,q.jsx)(u,{as:`p`,variant:`body-small-default`,className:`px-3 py-4 text-center text-(--content-tertiary)`,children:`No matching contacts`}):n.map(e=>(0,q.jsx)(Ne,{contact:e,onPick:()=>r(e.id)},e.id))})]})}function Ne({contact:e,onPick:t}){let n=Be(e).join(` | `)||void 0;return(0,q.jsx)(F,{asChild:!0,label:``,children:(0,q.jsx)(`button`,{type:`button`,onClick:t,role:`option`,"aria-selected":`false`,className:`flex h-auto w-full items-center gap-2 rounded-[6px] px-[8px] py-2 text-left`,children:(0,q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,q.jsx)(`span`,{className:`truncate text-body-medium-default`,children:e.displayName}),n?(0,q.jsx)(`span`,{className:`truncate text-body-small-default text-(--content-tertiary)`,children:n}):null]})})})}function Pe({survivor:e,donor:t}){let n=Ie(e),{moved:r,duplicates:i}=ze(e,t);return(0,q.jsxs)(`ul`,{className:`flex flex-col gap-2 text-body-medium-lighter text-(--content-secondary)`,children:[(0,q.jsxs)(`li`,{children:[(0,q.jsxs)(`span`,{className:`text-(--content-default)`,children:[`“`,t.displayName,`”`]}),` `,`will be deleted.`]}),(0,q.jsx)(`li`,{children:r.length===0?`No new channels will move to ${n}.`:`${r.length} channel${r.length===1?``:`s`} will move to ${n}: ${r.map(e=>Re(e.type)).join(`, `)}.`}),i.length>0?(0,q.jsxs)(`li`,{className:`text-(--content-tertiary)`,children:[i.length,` duplicate channel`,i.length===1?``:`s`,` already on `,n,` `,`(skipped).`]}):null,t.notes?(0,q.jsx)(`li`,{children:`Notes from the merged contact will be appended.`}):null,(0,q.jsx)(`li`,{className:`text-(--content-tertiary)`,children:`This cannot be undone.`})]})}function Fe(){return(0,q.jsx)(u,{as:`p`,variant:`body-medium-lighter`,className:`px-3 py-6 text-center text-(--content-tertiary)`,children:`No other contacts available to merge.`})}function Ie(e){return e.role===`guardian`?!e.displayName||e.displayName.startsWith(`vellum-principal-`)?`you`:`${e.displayName} (you)`:e.displayName||`this contact`}var Le={slack:`Slack`,telegram:`Telegram`,phone:`Phone`,email:`Email`,whatsapp:`WhatsApp`};function Re(e){return Le[e.toLowerCase()]??e}function ze(e,t){let n=[],r=[];for(let i of t.channels)i.status!==`revoked`&&(e.channels.some(e=>e.type===i.type&&e.address.toLowerCase()===i.address.toLowerCase())?r.push(i):n.push(i));return{moved:n,duplicates:r}}function Be(e){let t=new Set,n=[];for(let r of e.channels){if(r.status===`revoked`)continue;let e=r.type.toLowerCase();t.has(e)||(t.add(e),n.push(Le[e]??r.type))}return n}function Ve({loading:e,guardian:t,assistantName:r,regularContacts:i,selection:a,onSelect:o,onAddContact:s,addingContact:c=!1}){let[l,u]=(0,G.useState)(``),f=l.trim()?i.filter(e=>e.displayName.toLowerCase().includes(l.trim().toLowerCase())):i;return(0,q.jsx)(d.Root,{className:`flex h-full flex-col overflow-hidden`,children:(0,q.jsxs)(d.Body,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`h2`,{className:`text-title-medium`,style:{color:`var(--content-default)`},children:`Entries`}),(0,q.jsx)(n,{type:`button`,variant:`ghost`,iconOnly:c?(0,q.jsx)(w,{className:`animate-spin`,"aria-hidden":!0}):(0,q.jsx)(O,{"aria-hidden":!0}),onClick:s,disabled:c,"aria-label":`Add contact`,tintColor:`var(--content-secondary)`})]}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[t?(0,q.jsx)(He,{name:t.displayName?`${t.displayName} (You)`:`You`,role:t.role,channelTypes:t.channelTypes,selected:a?.kind===`contact`&&a.contactId===t.id,onClick:()=>o({kind:`contact`,contactId:t.id}),trailingIcon:`pencil`}):null,(0,q.jsx)(He,{name:r?.trim()||`Your Assistant`,role:`assistant`,selected:a?.kind===`assistant`,onClick:()=>o({kind:`assistant`}),trailingIcon:`more`})]}),(0,q.jsx)(`div`,{className:`border-t`,style:{borderColor:`var(--border-base)`}}),i.length>0?(0,q.jsx)(N,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search Contacts`,leftIcon:(0,q.jsx)(k,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),fullWidth:!0}):null,i.length>0?(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto flex flex-col gap-1`,children:[f.map(e=>(0,q.jsx)(He,{name:e.displayName,role:e.role,contactType:e.contactType,channelTypes:e.channelTypes,verified:e.verified,selected:a?.kind===`contact`&&a.contactId===e.id,onClick:()=>o({kind:`contact`,contactId:e.id}),trailingIcon:`more`},e.id)),f.length===0?(0,q.jsx)(`p`,{className:`px-3 py-4 text-center text-body-small-default`,style:{color:`var(--content-tertiary)`},children:`No matching contacts`}):null]}):e?null:(0,q.jsx)(n,{type:`button`,variant:`ghost`,onClick:s,disabled:c,tintColor:`var(--primary-base)`,leftIcon:c?(0,q.jsx)(w,{className:`animate-spin`,"aria-hidden":!0}):(0,q.jsx)(j,{"aria-hidden":!0}),children:`Add Contact`})]})})}function He({name:e,role:t,contactType:n,channelTypes:r,selected:i,onClick:a,trailingIcon:o,verified:s}){let c=r&&r.length>0?r.join(` | `):void 0;return(0,q.jsx)(F,{asChild:!0,active:i,label:``,trailingAction:o===`pencil`?(0,q.jsx)(D,{className:`h-3.5 w-3.5`,"aria-hidden":!0}):o===`more`?(0,q.jsx)(W,{className:`h-3.5 w-3.5`,"aria-hidden":!0}):void 0,children:(0,q.jsxs)(`button`,{type:`button`,onClick:a,className:`flex h-auto w-full items-center gap-2 rounded-[6px] px-[8px] py-2 text-left`,children:[(0,q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,q.jsx)(`span`,{className:`truncate text-body-medium-default`,children:e}),c?(0,q.jsx)(`span`,{className:`truncate text-body-small-default`,style:{color:`var(--content-tertiary)`},children:c}):null]}),(0,q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[s===void 0?null:(0,q.jsx)(M,{tone:s?`positive`:`neutral`,children:s?`Verified`:`Unverified`}),(0,q.jsx)(Y,{role:t,contactType:n})]})]})})}function Ue(e){return(0,q.jsx)(We,{...e},e.contact.id)}function We({contact:e,savePending:t,verifyPending:r,mergePending:i=!1,canMerge:a=!1,availableChannels:o,a2aEnabled:s,onSave:c,onMerge:l,onSetupChannel:u,onVerifyChannel:d,onRevokeChannel:f,onGenerateInviteLink:p}){let m=e.displayName.startsWith(`vellum-principal-`),h=m?``:e.displayName,[g,_]=(0,G.useState)(h),[v,y]=(0,G.useState)(e.notes??``),b=g.trim(),x=v.trim(),S=b!==h.trim()||x!==(e.notes??``).trim(),C=S&&!t,w=`${e.interactionCount} interaction${e.interactionCount===1?``:`s`}`;return(0,q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,q.jsx)(V,{title:m?`You`:`${e.displayName} (You)`,accessory:(0,q.jsx)(Y,{role:`guardian`}),compactAccessory:!0,subtitle:w,children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsx)(N,{label:`Name`,type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:`Your name`,disabled:t,fullWidth:!0}),(0,q.jsx)(N,{label:`Notes`,type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:`Notes about yourself which AI will take into account`,disabled:t,fullWidth:!0}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsx)(n,{variant:`primary`,onClick:()=>c({displayName:b||e.displayName,notes:x}),disabled:!C,children:t?`Saving…`:`Save`}),l?(0,q.jsx)(n,{variant:`outlined`,onClick:l,disabled:!a||S||i||t,title:a?S?`Save your changes before merging`:void 0:`No other contacts available to merge`,children:i?`Merging…`:`Merge…`}):null]})]})}),(0,q.jsx)(V,{title:`Channels`,subtitle:`Once verified, your assistant will recognize you when you message from these channels.`,children:(0,q.jsx)($,{contactChannels:e.channels,availableChannels:o,a2aEnabled:s,setupLabel:`Verify me`,verifyLoading:r,onSetupChannel:u,onVerifyChannel:d,onRevokeChannel:f})}),p?(0,q.jsx)(B,{onClick:p}):null]})}function Ge(e,t){let n=t.trim().toLowerCase().replace(/^@/,``);return n===``?e:e.filter(e=>e.displayName.toLowerCase().includes(n)||e.username.toLowerCase().includes(n))}function Ke(e){let t=e.trim().split(/\s+/).filter(Boolean);return`${t[0]?.[0]??`?`}${t.length>1?t[t.length-1]?.[0]??``:``}`.toUpperCase()}function qe({open:e,channelLabel:t,contactName:r,accounts:i,loading:a,errorMessage:o,pendingAccountId:s,onPick:c,onClose:l,onInviteInstead:u}){let[d,f]=(0,G.useState)(``);(0,G.useEffect)(()=>{e&&f(``)},[e]);let p=(0,G.useMemo)(()=>Ge(i??[],d),[i,d]),h=s!=null;return(0,q.jsx)(P.Root,{open:e,onOpenChange:e=>!e&&l(),children:(0,q.jsxs)(P.Content,{size:`sm`,children:[(0,q.jsxs)(P.Header,{children:[(0,q.jsxs)(P.Title,{children:[`Link `,t,` account`]}),(0,q.jsxs)(P.Description,{children:[`Search your `,t,` workspace and pick`,` `,(0,q.jsx)(`span`,{className:`text-[color:var(--content-default)]`,children:r}),`’s account.`]})]}),(0,q.jsxs)(P.Body,{className:`flex flex-col gap-3`,children:[(0,q.jsx)(N,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:`Search by name or @handle`,"aria-label":`Search ${t} workspace accounts`,leftIcon:(0,q.jsx)(k,{className:`h-4 w-4`}),fullWidth:!0}),o?(0,q.jsx)(`p`,{className:`text-body-small-default text-[color:var(--content-negative)]`,children:o}):null,(0,q.jsx)(`div`,{className:`max-h-80 overflow-y-auto`,children:a?(0,q.jsx)(`p`,{className:`py-4 text-center text-body-small-default text-[color:var(--content-tertiary)]`,children:`Loading workspace members…`}):p.length===0?(0,q.jsx)(`p`,{className:`py-4 text-center text-body-small-default text-[color:var(--content-tertiary)]`,children:(i?.length??0)===0?`No workspace members found.`:`No members match.`}):(0,q.jsx)(`ul`,{className:`flex flex-col`,children:p.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>c(e),disabled:h,className:`flex w-full cursor-pointer items-center gap-3 rounded-md px-2 py-2 text-left transition-colors hover:bg-[var(--surface-overlay)] disabled:cursor-not-allowed disabled:opacity-60`,children:[e.imageUrl?(0,q.jsx)(`img`,{src:e.imageUrl,alt:``,className:`h-8 w-8 shrink-0 rounded-full`}):(0,q.jsx)(`span`,{"aria-hidden":`true`,className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-[var(--tag-bg-neutral)] text-body-small-emphasised text-[color:var(--content-secondary)]`,children:Ke(e.displayName)}),(0,q.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,q.jsx)(`span`,{className:`truncate text-body-medium-default text-[color:var(--content-default)]`,children:e.displayName}),(0,q.jsxs)(`span`,{className:`truncate text-body-small-default text-[color:var(--content-tertiary)]`,children:[`@`,e.username]})]}),s===e.id?(0,q.jsx)(`span`,{className:`ml-auto shrink-0 text-body-small-default text-[color:var(--content-tertiary)]`,children:`Linking…`}):null]})},e.id))})})]}),(0,q.jsxs)(P.Footer,{className:`items-center justify-between gap-3 border-t border-[var(--border-base)]`,children:[(0,q.jsxs)(`p`,{className:`text-body-small-default text-[color:var(--content-tertiary)]`,children:[`Picking marks this account as`,` `,(0,q.jsx)(`span`,{className:`text-[color:var(--content-secondary)]`,children:`guardian-linked`}),` `,`— you vouch for the identity, no handshake needed.`]}),u?(0,q.jsxs)(n,{variant:`link`,className:`shrink-0`,onClick:u,disabled:h,children:[`Or send an invite instead`,(0,q.jsx)(m,{className:`h-3.5 w-3.5`})]}):null]})]})})}function Je({assistantId:e,channelType:t,contact:n,onLinked:r}){let[i,a]=(0,G.useState)(!1),o=c({mutationFn:n=>U(e,n.contact,{type:t,address:n.account.id}),onSuccess:(e,t)=>{a(!1),ee.success(`Linked as @${t.account.username}`),r()}}),s=(0,G.useCallback)(()=>{o.reset(),a(!0)},[o]),l=(0,G.useCallback)(()=>{o.isPending||(o.reset(),a(!1))},[o]),u=(0,G.useCallback)(e=>{!n||o.isPending||o.mutate({contact:n,account:e})},[n,o]);return{channelType:t,dialogOpen:i,open:s,close:l,linkErrorMessage:o.error instanceof Error?o.error.message:o.error?`Failed to link account`:null,pendingAccountId:o.isPending?o.variables.account.id:null,pick:u}}var Ye=[{id:`slack`,label:`Slack`,subtitle:`Message your assistant from Slack`,icon:`hash`,supportsVerification:!0,setupMessages:{guardian:`I'd like to verify my identity as your guardian on Slack. Can you help me set that up?`,contact:`I'd like to verify a contact's Slack identity. Can you walk me through it?`}},{id:`telegram`,label:`Telegram`,subtitle:`Message your assistant from Telegram`,icon:`send`,supportsVerification:!0,setupMessages:{guardian:`I'd like to verify my identity as your guardian on Telegram. Can you help me set that up?`,contact:`I'd like to verify a contact's Telegram identity. Can you walk me through it?`}},{id:`phone`,label:`Phone Calling`,subtitle:`Call or text your assistant via phone`,icon:`phone`,supportsVerification:!0,setupMessages:{guardian:`I'd like to verify my identity as your guardian for phone calls. Can you help me set that up?`,contact:`I'd like to verify a contact's phone number. Can you help me set that up?`}}],Xe=[];function Ze({assistantId:e,onStartSetupConversation:t}){let n=le.use.a2aChannel(),a=se.use.name(),l=o(),[u]=r(),d=u.get(`setup`),f=d&&_(d)?d:null,[p,m]=(0,G.useState)({kind:`assistant`}),g=pe(e),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(!1),S=de(a),C=(0,G.useMemo)(()=>({path:{assistant_id:e}}),[e]),w=oe(C),T=s({...ae(C),enabled:!!e,select:e=>e.contacts}),E=fe({assistantId:e,onStartSetupConversation:t}),D=s({...ie({path:{assistant_id:e}}),enabled:!!e,queryFn:async({signal:t})=>{let{data:n,error:r,response:i}=await te({path:{assistant_id:e},signal:t,throwOnError:!1});if(!i||i.status===404)return{channels:Ye};if(!i.ok)throw r??Error(`Failed to fetch channel availability`);return n},select:e=>e.channels}).data??Xe,O=T.data,k=(0,G.useMemo)(()=>O?.find(e=>e.role===`guardian`)??null,[O]),A=(0,G.useMemo)(()=>O?.filter(e=>e.role!==`guardian`)??[],[O]),j=(0,G.useMemo)(()=>p.kind===`contact`?O?.find(e=>e.id===p.contactId)??null:null,[O,p]),M=(0,G.useMemo)(()=>!O||!j?[]:O.filter(e=>e.id!==j.id&&e.role!==`guardian`),[O,j]),N=M.length>0,P=(0,G.useRef)(!!f);(0,G.useEffect)(()=>{P.current||k&&(P.current=!0,m({kind:`contact`,contactId:k.id}))},[k]);let F=(0,G.useCallback)(()=>l.invalidateQueries({queryKey:w}),[l,w]),I=c({mutationFn:()=>_e(e,{displayName:`New Contact`}),onMutate:async()=>{await l.cancelQueries({queryKey:w})},onSuccess:e=>{L(l,C,t=>t?{...t,contacts:[...t.contacts,e]}:void 0),m({kind:`contact`,contactId:e.id})},onError:H(`Failed to create contact`),onSettled:()=>F()}),R=c({mutationFn:t=>ve(e,t),onSuccess:(e,t)=>{L(l,C,e=>e?{...e,contacts:e.contacts.filter(e=>e.id!==t)}:void 0),m({kind:`assistant`})},onError:H(`Failed to delete contact`),onSettled:()=>F()}),z=c({mutationFn:({contactId:t,patch:n})=>_e(e,{id:t,displayName:n.displayName,notes:n.notes}),onSuccess:e=>{L(l,C,t=>t?{...t,contacts:t.contacts.map(t=>t.id===e.id?e:t)}:void 0)},onError:H(`Failed to save contact`),onSettled:()=>F()}),B=re({onMutate:async()=>{await l.cancelQueries({queryKey:w})},onSuccess:(e,t)=>{let n=e.contact,r=t.body.mergeId;n&&(L(l,C,e=>e?{...e,contacts:e.contacts.filter(e=>e.id!==r).map(e=>e.id===n.id?n:e)}:void 0),m({kind:`contact`,contactId:n.id})),x(!1),ee.success(`Contacts merged`)},onSettled:()=>F()}),V=(0,G.useCallback)(e=>{m(e),y(!1),x(!1),B.reset()},[B]),U=(0,G.useCallback)(()=>{B.reset(),x(!0)},[B]),ye=(0,G.useCallback)(()=>{B.isPending||(x(!1),B.reset())},[B]),W=ne({onSuccess:()=>F()}),be=(0,G.useCallback)((t,n)=>{W.mutate({path:{assistant_id:e,contactChannelId:t},body:{status:`revoked`}})},[W,e]),xe=(0,G.useCallback)(()=>{I.isPending||I.mutate()},[I]),K=(0,G.useCallback)(e=>{if(!t)return;let n=D.find(t=>t.id===e)?.setupMessages.contact;n&&t(n)},[D,t]),Se=(0,G.useCallback)(e=>{if(!t)return;let n=D.find(t=>t.id===e)?.setupMessages.guardian;n&&t(n)},[D,t]),J=c({mutationFn:t=>ge(e,t.channelId),onSuccess:()=>F(),onError:H(`Failed to verify channel`)}),Y=(0,G.useCallback)(e=>{if(!j)return;let t=j.channels.find(t=>t.type===e&&t.status!==`revoked`);t&&J.mutate({channelId:t.id})},[j,J]),X=Je({assistantId:e,channelType:`slack`,contact:j?{id:j.id,displayName:j.displayName}:null,onLinked:F}),Z=s({...h(e),enabled:!!e&&X.dialogOpen,select:e=>e.users}),we=E.channels.some(e=>e.key===`slack`&&e.status===`ready`),Te=(0,G.useCallback)(e=>{e===X.channelType&&X.open()},[X]),Ee=R.isPending?R.variables:null,Q=(0,G.useMemo)(()=>j?z.isPending&&z.variables?.contactId===j.id?{...j,displayName:z.variables.patch.displayName,notes:z.variables.patch.notes}:j:null,[j,z.isPending,z.variables]);if(f)return(0,q.jsx)(i,{to:`${ce.channels}?setup=${f}`,replace:!0});let $={loading:T.isLoading,assistantName:S,guardian:k?{id:k.id,displayName:k.displayName.startsWith(`vellum-principal-`)?``:k.displayName,role:k.role,channelTypes:tt(k.channels,n)}:null,regularContacts:A.filter(e=>e.id!==Ee).map(e=>({id:e.id,displayName:e.displayName,role:e.role,contactType:e.contactType,channelTypes:tt(e.channels,n),verified:et(e.channels)})),selection:p,onAddContact:xe,addingContact:I.isPending};return(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden sm:flex-row sm:gap-6`,children:[(0,q.jsx)(`div`,{className:`flex items-center sm:hidden`,children:(0,q.jsx)(me,{onClick:()=>y(!0)})}),(0,q.jsx)(he,{open:v,onClose:()=>y(!1),title:`Contacts`,children:(0,q.jsx)(Ve,{...$,onSelect:V})}),(0,q.jsx)(`aside`,{className:`hidden min-h-0 w-[320px] shrink-0 overflow-y-auto self-stretch sm:block`,children:(0,q.jsx)(Ve,{...$,onSelect:V})}),(0,q.jsx)(`section`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:p.kind===`assistant`||p.kind===`contact`&&p.contactId===Ee?(0,q.jsx)(Ce,{assistantName:S,channels:E.channels,pendingChannelKey:E.pendingChannelKey,onConnect:E.onSetup,onDisconnect:E.onDisconnect}):Q?Q.role===`guardian`?(0,q.jsx)(Ue,{contact:Q,savePending:z.isPending,verifyPending:J.isPending,mergePending:B.isPending,canMerge:N,availableChannels:D,a2aEnabled:n,onSave:e=>{z.mutate({contactId:Q.id,patch:e})},onMerge:U,onSetupChannel:t?Se:void 0,onVerifyChannel:Y,onRevokeChannel:be,onGenerateInviteLink:n?g.open:void 0}):(0,q.jsx)(Oe,{contact:Q,savePending:z.isPending,deletePending:R.isPending,verifyPending:J.isPending,mergePending:B.isPending,canMerge:N,availableChannels:D,a2aEnabled:n,onSave:e=>{z.mutate({contactId:Q.id,patch:e})},onDelete:()=>{R.mutate(Q.id)},onMerge:U,onSetupChannel:t?K:void 0,onVerifyChannel:Y,onRevokeChannel:be,onLinkAccount:we?Te:void 0}):(0,q.jsx)(Qe,{})}),j?(0,q.jsx)(Ae,{open:b,survivor:j,candidates:M,pending:B.isPending,errorMessage:B.error instanceof Error?B.error.message:B.error?`Failed to merge contacts`:null,onMerge:t=>B.mutate({path:{assistant_id:e},body:{keepId:j.id,mergeId:t}}),onClose:ye}):null,(0,q.jsx)(qe,{open:X.dialogOpen,channelLabel:`Slack`,contactName:j?.displayName??``,accounts:Z.data,loading:Z.isLoading,errorMessage:Z.isError?`Couldn’t load the workspace roster. Check the Slack connection and try again.`:X.linkErrorMessage,pendingAccountId:X.pendingAccountId,onPick:X.pick,onClose:X.close,onInviteInstead:t?()=>{X.close(),K(X.channelType)}:void 0}),(0,q.jsx)(ue,{open:g.isOpen,assistantId:e,onClose:g.close})]})}function Qe(){return(0,q.jsx)(`div`,{className:`flex h-full items-center justify-center py-16`,children:(0,q.jsx)(`p`,{className:`text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:`Select a contact`})})}var $e={slack:`Slack`,telegram:`Telegram`,phone:`Phone`,email:`Email`,whatsapp:`WhatsApp`,a2a:`A2A`};function et(e){return e.some(e=>e.status!==`revoked`&&(e.type===`a2a`||K(e)))}function tt(e,t){let n=new Set,r=[];for(let i of e){if(i.status===`revoked`)continue;let e=i.type.toLowerCase();n.has(e)||e===`a2a`&&!t||(n.add(e),r.push($e[e]??i.type))}return r}function nt(){let e=a(),t=z();return(0,q.jsx)(Ze,{assistantId:t,onStartSetupConversation:t=>{R(e,{prompt:t})}},t)}export{nt as ContactsPageRoute};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./button-Dy5001j6.js";import{m as r,n as i,u as a}from"./chunk-5KNZJZUH-Bsoom5--.js";import{n as o}from"./QueryClientProvider-CMu7CkQU.js";import{t as s}from"./useQuery-Bz-fbQ-m.js";import{t as c}from"./useMutation-CXGTrp4W.js";import{t as l}from"./jsx-runtime-D3ZM-ToX.js";import{t as u}from"./typography-DEI9Ra9z.js";import{t as d}from"./card-DRIctGVs.js";import{t as f}from"./createLucideIcon-CAM1RhH8.js";import{t as p}from"./arrow-left-C2ylPLHq.js";import{t as m}from"./arrow-right-B-jRJNWP.js";import{a as h,b as g,c as _,d as v,l as y,x as b,y as x}from"./use-save-twilio-credentials-dUedxPbM.js";import{t as S}from"./circle-check-big-DSsDH5_6.js";import{t as C}from"./link-2-BKL8QWRX.js";import{t as w}from"./loader-circle-XREx3i4W.js";import{t as T}from"./mail-CMdPNysl.js";import{t as E}from"./message-square-CQGiY4zk.js";import{t as D}from"./pencil-D38YNe2r.js";import{t as O}from"./plus-jH3kAliM.js";import{t as k}from"./search-BVW-n8to.js";import{t as A}from"./send-Q71Exj3z.js";import{t as j}from"./user-plus-oiIr9ey8.js";import{t as M}from"./tag-NXcyiTkK.js";import{t as N}from"./input-hw3el2GJ.js";import{t as P}from"./modal-BR4CUFBd.js";import{t as F}from"./panel-item-CrtoJCrd.js";import{n as ee}from"./toast-LgLp4obE.js";import{t as I}from"./confirm-dialog-UYFm4osC.js";import{C as te}from"./sdk.gen-BVAVE6A_.js";import{Ht as ne,S as L,Ut as re,a as ie,b as ae,x as oe}from"./react-query.gen-r3I6j8-1.js";import{t as se}from"./assistant-identity-store-DIyVo8LV.js";import{u as ce}from"./routes-vE-2hncW.js";import{n as R}from"./conversation-navigation-nuG3yn67.js";import{t as le}from"./assistant-feature-flag-store-fyKSDJNN.js";import{t as z}from"./use-active-assistant-id-CXhDyK7y.js";import{i as ue,l as de,n as fe,r as B,t as pe}from"./use-invite-link-dialog-Cvvpn0Hm.js";import{t as V}from"./detail-card-BMRGmkia.js";import{n as me,t as he}from"./mobile-sidebar-drawer-hLKPbhQ-.js";import{t as H}from"./mutation-error-zQ6oi-va.js";import{a as ge,i as _e,n as U,t as ve}from"./contacts-gateway-CFNbQjfX.js";var ye=f(`circle-question-mark`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),W=f(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),be=f(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),G=e(t(),1),xe=new Set([`slack`]);function K(e){return e.status===`verified`||e.status===`active`&&e.verifiedAt!=null}var q=l();function Se({channels:e,pendingChannelKey:t=null,onConnect:n,onDisconnect:r}){let[i,a]=(0,G.useState)(null);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`flex flex-col`,children:e.map((e,i)=>(0,q.jsxs)(`div`,{children:[i>0?(0,q.jsx)(`div`,{className:`border-t`,style:{borderColor:`var(--border-base)`}}):null,(0,q.jsx)(J,{channel:e,pending:t===e.key,onConnect:n?()=>n(e.key):void 0,onDisconnect:r?()=>a(e.key):void 0})]},e.key))}),(0,q.jsx)(I,{open:i!==null,title:`Disconnect ${i?v(i):``}?`,message:`This clears the stored credentials for this channel. You can reconnect later.`,confirmLabel:`Disconnect`,destructive:!0,onConfirm:()=>{i&&r&&r(i),a(null)},onCancel:()=>a(null)})]})}function J({channel:e,pending:t,onConnect:r,onDisconnect:i}){let a=e.status===`ready`;return(0,q.jsxs)(`div`,{className:`flex items-center gap-3 py-4`,children:[(0,q.jsx)(y,{channelId:e.key,className:`h-4 w-4 shrink-0 text-[color:var(--content-secondary)]`}),(0,q.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:v(e.key)}),a&&e.address?(0,q.jsx)(`span`,{className:`truncate text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:e.address}):null,(0,q.jsx)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:a?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 h-8 px-2.5 rounded-md whitespace-nowrap select-none text-body-small-emphasised leading-none bg-[var(--content-default)] text-[var(--surface-base)]`,children:[(0,q.jsx)(S,{className:`h-3 w-3`}),`Connected`]}),(0,q.jsx)(n,{variant:`danger`,onClick:i,disabled:!i||t,children:t?`Disconnecting…`:`Disconnect`})]}):(0,q.jsx)(n,{variant:`outlined`,onClick:r,disabled:!r||t,children:`Connect`})})]})}function Y({role:e,contactType:t}){let{label:n,tone:r}=X(e,t);return(0,q.jsx)(M,{tone:r,children:n})}function X(e,t){switch(e){case`guardian`:return{label:`Guardian`,tone:`positive`};case`assistant`:return{label:`Assistant`,tone:`negative`};default:return t===`assistant`?{label:`Assistant`,tone:`negative`}:{label:`Human`,tone:`warning`}}}function Ce({assistantName:e,...t}){let n=de(e);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,q.jsx)(V,{title:`${n} (Your Assistant)`,accessory:(0,q.jsx)(Y,{role:`assistant`}),compactAccessory:!0}),(0,q.jsx)(V,{title:`Channels`,subtitle:`Where ${n} can be reached.`,children:(0,q.jsx)(Se,{...t})})]})}var Z=new Set([`telegram`,`phone`,`vellum`,`whatsapp`,`slack`,`email`,`platform`,`a2a`]);function we(e){return Z.has(e)}function Te(e,t){return e.id===`a2a`?t&&t.status!==`revoked`?{kind:`connected`}:{kind:`setup`}:t!=null&&K(t)?{kind:`verified`}:t?.status===`blocked`?{kind:`none`}:t&&t.status!==`revoked`?{kind:`unverified`}:{kind:`setup`}}function Ee(e,t,n){let r=[],i=new Set;if(e)for(let t of e)t.id===`a2a`&&!n||(r.push(t),i.add(t.id));for(let e of t)e.status===`revoked`||i.has(e.type)||e.type===`a2a`&&!n||we(e.type)&&(r.push({id:e.type,label:e.type.charAt(0).toUpperCase()+e.type.slice(1),subtitle:``,icon:`help-circle`,supportsVerification:!1,setupMessages:{guardian:``,contact:``}}),i.add(e.type));return r}function Q({name:e,className:t,style:n}){switch(e){case`bot`:return(0,q.jsx)(b,{className:t,style:n});case`hash`:return(0,q.jsx)(g,{className:t,style:n});case`send`:return(0,q.jsx)(A,{className:t,style:n});case`phone`:return(0,q.jsx)(x,{className:t,style:n});case`mail`:return(0,q.jsx)(T,{className:t,style:n});case`message-square`:return(0,q.jsx)(E,{className:t,style:n});default:return(0,q.jsx)(ye,{className:t,style:n})}}function $({contactChannels:e,availableChannels:t,a2aEnabled:n,setupLabel:r=`Invite`,verifyLoading:i,verifySubject:a=`self`,onSetupChannel:o,onVerifyChannel:s,onRevokeChannel:c,onLinkAccount:l}){let[u,d]=(0,G.useState)(null),[f,p]=(0,G.useState)(null),m=new Map;for(let t of e)t.status!==`revoked`&&(m.has(t.type)||m.set(t.type,t));return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`flex flex-col`,children:Ee(t,e,n).map((e,t)=>{let n=m.get(e.id);return(0,q.jsxs)(`div`,{children:[t>0&&(0,q.jsx)(`div`,{className:`border-t`,style:{borderColor:`var(--border-base)`}}),(0,q.jsx)(De,{info:e,existing:n,setupLabel:r,verifyLoading:i,onSetup:o?()=>o(e.id):void 0,onVerify:s&&e.supportsVerification?()=>d(e):void 0,onRevoke:c&&n?()=>p({channelId:n.id,channel:e}):void 0,onLinkAccount:l&&xe.has(e.id)?()=>l(e.id):void 0})]},e.id)})}),u&&(0,q.jsx)(I,{open:!0,title:`Verify ${u.label}`,message:a===`contact`?`This will mark this contact's ${u.label} channel as verified. Your assistant will recognize them when they reach out from it.`:`This will mark your ${u.label} channel as verified. Your assistant will recognize you when you reach out from it.`,confirmLabel:`Verify`,onConfirm:()=>{u&&(s?.(u.id),d(null))},onCancel:()=>d(null)}),f&&(0,q.jsx)(I,{open:!0,title:`Revoke ${f.channel.label}`,message:`This will disconnect the verified channel. The contact will need to re-verify to use this channel again.`,confirmLabel:`Revoke`,destructive:!0,onConfirm:()=>{c?.(f.channelId,f.channel.id),p(null)},onCancel:()=>p(null)})]})}function De({info:e,existing:t,setupLabel:r,verifyLoading:i,onSetup:a,onVerify:o,onRevoke:s,onLinkAccount:c}){let l=Te(e,t);return(0,q.jsxs)(`div`,{className:`flex items-center gap-3 py-4`,children:[(0,q.jsx)(Q,{name:e.icon,className:`h-4 w-4 shrink-0`,style:{color:`var(--content-secondary)`}}),(0,q.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:e.label}),t?.address?(0,q.jsx)(`span`,{className:`truncate text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:t.address}):null,(0,q.jsx)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:l.kind===`connected`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 h-8 px-2.5 rounded-md whitespace-nowrap select-none text-body-small-emphasised leading-none bg-[var(--content-default)] text-[var(--surface-base)]`,children:[(0,q.jsx)(S,{className:`h-3 w-3`}),`Connected`]}),s?(0,q.jsx)(n,{variant:`danger`,onClick:s,children:`Revoke`}):null]}):l.kind===`verified`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 h-8 px-2.5 rounded-md whitespace-nowrap select-none text-body-small-emphasised leading-none bg-[var(--content-default)] text-[var(--surface-base)]`,children:[(0,q.jsx)(S,{className:`h-3 w-3`}),`Verified`]}),s?(0,q.jsx)(n,{variant:`danger`,onClick:s,children:`Revoke`}):null]}):l.kind===`unverified`?(0,q.jsx)(n,{variant:`outlined`,onClick:o,disabled:!o||i,children:i?`Verifying…`:`Verify`}):l.kind===`setup`?e.id===`a2a`?null:(0,q.jsxs)(q.Fragment,{children:[c?(0,q.jsxs)(n,{onClick:c,children:[(0,q.jsx)(C,{className:`h-3.5 w-3.5`}),`Link account`]}):null,(0,q.jsx)(n,{variant:`outlined`,onClick:a,disabled:!a,children:r})]}):null})]})}function Oe(e){return(0,q.jsx)(ke,{...e},e.contact.id)}function ke({contact:e,savePending:t,deletePending:r,verifyPending:i,mergePending:a=!1,canMerge:o=!1,availableChannels:s,a2aEnabled:c,onSave:l,onDelete:u,onMerge:d,onSetupChannel:f,onVerifyChannel:p,onRevokeChannel:m,onLinkAccount:h}){let g=e.displayName===`New Contact`,[_,v]=(0,G.useState)(g?``:e.displayName),[y,b]=(0,G.useState)(e.notes??``),[x,S]=(0,G.useState)(!1),C=_.trim(),w=y.trim(),T=g?``:e.displayName,E=e.notes??``,D=C!==T||w!==E,O=C.length>0&&D&&!t&&!r,k=g&&e.channels.length===0&&e.interactionCount===0,A=C||e.displayName,j=`${e.interactionCount} interaction${e.interactionCount===1?``:`s`}`;return(0,q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,q.jsx)(V,{title:A,accessory:(0,q.jsx)(Y,{role:e.role,contactType:e.contactType}),compactAccessory:!0,subtitle:j,children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsx)(N,{label:`Name`,type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`Give this human a name`,autoFocus:g,disabled:t||r,fullWidth:!0}),(0,q.jsx)(N,{label:`Notes`,type:`text`,value:y,onChange:e=>b(e.target.value),placeholder:`Optional notes about the human which AI will take into account`,disabled:t||r,fullWidth:!0}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsx)(n,{type:`button`,onClick:()=>l({displayName:C,notes:w}),disabled:!O,children:t?`Saving…`:`Save`}),d?(0,q.jsx)(n,{type:`button`,variant:`outlined`,onClick:d,disabled:!o||k||D||a||t||r,title:o?k?`Save this contact before merging`:D?`Save your changes before merging`:void 0:`No other contacts available to merge`,children:a?`Merging…`:`Merge…`}):null,(0,q.jsx)(n,{type:`button`,variant:`danger`,onClick:()=>{k?u():S(!0)},disabled:r,children:r?`Deleting…`:`Delete Contact`})]})]})}),(0,q.jsx)(V,{title:`Linked accounts`,subtitle:`Where the assistant recognizes this contact. Link accounts you know, invite the ones you don't.`,children:(0,q.jsx)($,{contactChannels:e.channels,availableChannels:s,a2aEnabled:c,verifyLoading:i,verifySubject:`contact`,onSetupChannel:f,onVerifyChannel:p,onRevokeChannel:m,onLinkAccount:h})}),(0,q.jsx)(I,{open:x,title:`Delete ${e.displayName}?`,message:`This will permanently delete this contact and all their channels. This action cannot be undone.`,confirmLabel:`Delete`,destructive:!0,onConfirm:()=>{S(!1),u()},onCancel:()=>S(!1)})]})}function Ae(e){return(0,q.jsx)(je,{...e},`${e.survivor.id}:${e.open?`open`:`closed`}`)}function je({open:e,survivor:t,candidates:r,pending:i,errorMessage:a,onMerge:o,onClose:s}){let[c,l]=(0,G.useState)(``),[d,f]=(0,G.useState)(null);(0,G.useEffect)(()=>{d&&!r.some(e=>e.id===d)&&f(null)},[r,d]);let m=(0,G.useMemo)(()=>{let e=c.trim().toLowerCase();return e?r.filter(t=>t.displayName.toLowerCase().includes(e)):r},[r,c]),h=d?r.find(e=>e.id===d)??null:null,g=Ie(t);return(0,q.jsx)(P.Root,{open:e,onOpenChange:e=>{!e&&!i&&s()},children:(0,q.jsxs)(P.Content,{size:`md`,children:[(0,q.jsxs)(P.Header,{children:[(0,q.jsx)(P.Title,{icon:be,children:h?`Merge "${h.displayName}" into ${g}?`:`Merge another contact into ${g}`}),(0,q.jsx)(P.Description,{children:h?`Channels and notes from the merged contact will move over. The merged contact will be deleted.`:`The contact you pick will be deleted. Its channels and notes will be added to this one.`})]}),(0,q.jsxs)(P.Body,{className:`flex flex-col gap-3`,children:[h?(0,q.jsx)(Pe,{survivor:t,donor:h}):r.length===0?(0,q.jsx)(Fe,{}):(0,q.jsx)(Me,{search:c,onSearch:l,candidates:m,onPick:f}),a?(0,q.jsx)(u,{as:`p`,variant:`body-small-default`,className:`text-(--system-negative-strong)`,role:`alert`,children:a}):null]}),(0,q.jsx)(P.Footer,{children:h?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(n,{variant:`outlined`,onClick:()=>f(null),disabled:i,leftIcon:(0,q.jsx)(p,{"aria-hidden":!0}),children:`Back`}),(0,q.jsx)(n,{variant:`danger`,onClick:()=>o(h.id),disabled:i,children:i?`Merging…`:`Merge`})]}):(0,q.jsx)(n,{variant:`outlined`,onClick:s,disabled:i,children:`Cancel`})})]})})}function Me({search:e,onSearch:t,candidates:n,onPick:r}){return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(N,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Search contacts`,leftIcon:(0,q.jsx)(k,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),fullWidth:!0}),(0,q.jsx)(`div`,{className:`flex max-h-[320px] min-h-[120px] flex-col gap-1 overflow-y-auto`,role:`listbox`,"aria-label":`Select a contact to merge`,children:n.length===0?(0,q.jsx)(u,{as:`p`,variant:`body-small-default`,className:`px-3 py-4 text-center text-(--content-tertiary)`,children:`No matching contacts`}):n.map(e=>(0,q.jsx)(Ne,{contact:e,onPick:()=>r(e.id)},e.id))})]})}function Ne({contact:e,onPick:t}){let n=Be(e).join(` | `)||void 0;return(0,q.jsx)(F,{asChild:!0,label:``,children:(0,q.jsx)(`button`,{type:`button`,onClick:t,role:`option`,"aria-selected":`false`,className:`flex h-auto w-full items-center gap-2 rounded-[6px] px-[8px] py-2 text-left`,children:(0,q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,q.jsx)(`span`,{className:`truncate text-body-medium-default`,children:e.displayName}),n?(0,q.jsx)(`span`,{className:`truncate text-body-small-default text-(--content-tertiary)`,children:n}):null]})})})}function Pe({survivor:e,donor:t}){let n=Ie(e),{moved:r,duplicates:i}=ze(e,t);return(0,q.jsxs)(`ul`,{className:`flex flex-col gap-2 text-body-medium-lighter text-(--content-secondary)`,children:[(0,q.jsxs)(`li`,{children:[(0,q.jsxs)(`span`,{className:`text-(--content-default)`,children:[`“`,t.displayName,`”`]}),` `,`will be deleted.`]}),(0,q.jsx)(`li`,{children:r.length===0?`No new channels will move to ${n}.`:`${r.length} channel${r.length===1?``:`s`} will move to ${n}: ${r.map(e=>Re(e.type)).join(`, `)}.`}),i.length>0?(0,q.jsxs)(`li`,{className:`text-(--content-tertiary)`,children:[i.length,` duplicate channel`,i.length===1?``:`s`,` already on `,n,` `,`(skipped).`]}):null,t.notes?(0,q.jsx)(`li`,{children:`Notes from the merged contact will be appended.`}):null,(0,q.jsx)(`li`,{className:`text-(--content-tertiary)`,children:`This cannot be undone.`})]})}function Fe(){return(0,q.jsx)(u,{as:`p`,variant:`body-medium-lighter`,className:`px-3 py-6 text-center text-(--content-tertiary)`,children:`No other contacts available to merge.`})}function Ie(e){return e.role===`guardian`?!e.displayName||e.displayName.startsWith(`vellum-principal-`)?`you`:`${e.displayName} (you)`:e.displayName||`this contact`}var Le={slack:`Slack`,telegram:`Telegram`,phone:`Phone`,email:`Email`,whatsapp:`WhatsApp`};function Re(e){return Le[e.toLowerCase()]??e}function ze(e,t){let n=[],r=[];for(let i of t.channels)i.status!==`revoked`&&(e.channels.some(e=>e.type===i.type&&e.address.toLowerCase()===i.address.toLowerCase())?r.push(i):n.push(i));return{moved:n,duplicates:r}}function Be(e){let t=new Set,n=[];for(let r of e.channels){if(r.status===`revoked`)continue;let e=r.type.toLowerCase();t.has(e)||(t.add(e),n.push(Le[e]??r.type))}return n}function Ve({loading:e,guardian:t,assistantName:r,regularContacts:i,selection:a,onSelect:o,onAddContact:s,addingContact:c=!1}){let[l,u]=(0,G.useState)(``),f=l.trim()?i.filter(e=>e.displayName.toLowerCase().includes(l.trim().toLowerCase())):i;return(0,q.jsx)(d.Root,{className:`flex h-full flex-col overflow-hidden`,children:(0,q.jsxs)(d.Body,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`h2`,{className:`text-title-medium`,style:{color:`var(--content-default)`},children:`Entries`}),(0,q.jsx)(n,{type:`button`,variant:`ghost`,iconOnly:c?(0,q.jsx)(w,{className:`animate-spin`,"aria-hidden":!0}):(0,q.jsx)(O,{"aria-hidden":!0}),onClick:s,disabled:c,"aria-label":`Add contact`,tintColor:`var(--content-secondary)`})]}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[t?(0,q.jsx)(He,{name:t.displayName?`${t.displayName} (You)`:`You`,role:t.role,channelTypes:t.channelTypes,selected:a?.kind===`contact`&&a.contactId===t.id,onClick:()=>o({kind:`contact`,contactId:t.id}),trailingIcon:`pencil`}):null,(0,q.jsx)(He,{name:r?.trim()||`Your Assistant`,role:`assistant`,selected:a?.kind===`assistant`,onClick:()=>o({kind:`assistant`}),trailingIcon:`more`})]}),(0,q.jsx)(`div`,{className:`border-t`,style:{borderColor:`var(--border-base)`}}),i.length>0?(0,q.jsx)(N,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search Contacts`,leftIcon:(0,q.jsx)(k,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),fullWidth:!0}):null,i.length>0?(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto flex flex-col gap-1`,children:[f.map(e=>(0,q.jsx)(He,{name:e.displayName,role:e.role,contactType:e.contactType,channelTypes:e.channelTypes,verified:e.verified,selected:a?.kind===`contact`&&a.contactId===e.id,onClick:()=>o({kind:`contact`,contactId:e.id}),trailingIcon:`more`},e.id)),f.length===0?(0,q.jsx)(`p`,{className:`px-3 py-4 text-center text-body-small-default`,style:{color:`var(--content-tertiary)`},children:`No matching contacts`}):null]}):e?null:(0,q.jsx)(n,{type:`button`,variant:`ghost`,onClick:s,disabled:c,tintColor:`var(--primary-base)`,leftIcon:c?(0,q.jsx)(w,{className:`animate-spin`,"aria-hidden":!0}):(0,q.jsx)(j,{"aria-hidden":!0}),children:`Add Contact`})]})})}function He({name:e,role:t,contactType:n,channelTypes:r,selected:i,onClick:a,trailingIcon:o,verified:s}){let c=r&&r.length>0?r.join(` | `):void 0;return(0,q.jsx)(F,{asChild:!0,active:i,label:``,trailingAction:o===`pencil`?(0,q.jsx)(D,{className:`h-3.5 w-3.5`,"aria-hidden":!0}):o===`more`?(0,q.jsx)(W,{className:`h-3.5 w-3.5`,"aria-hidden":!0}):void 0,children:(0,q.jsxs)(`button`,{type:`button`,onClick:a,className:`flex h-auto w-full items-center gap-2 rounded-[6px] px-[8px] py-2 text-left`,children:[(0,q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,q.jsx)(`span`,{className:`truncate text-body-medium-default`,children:e}),c?(0,q.jsx)(`span`,{className:`truncate text-body-small-default`,style:{color:`var(--content-tertiary)`},children:c}):null]}),(0,q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[s===void 0?null:(0,q.jsx)(M,{tone:s?`positive`:`neutral`,children:s?`Verified`:`Unverified`}),(0,q.jsx)(Y,{role:t,contactType:n})]})]})})}function Ue(e){return(0,q.jsx)(We,{...e},e.contact.id)}function We({contact:e,savePending:t,verifyPending:r,mergePending:i=!1,canMerge:a=!1,availableChannels:o,a2aEnabled:s,onSave:c,onMerge:l,onSetupChannel:u,onVerifyChannel:d,onRevokeChannel:f,onGenerateInviteLink:p}){let m=e.displayName.startsWith(`vellum-principal-`),h=m?``:e.displayName,[g,_]=(0,G.useState)(h),[v,y]=(0,G.useState)(e.notes??``),b=g.trim(),x=v.trim(),S=b!==h.trim()||x!==(e.notes??``).trim(),C=S&&!t,w=`${e.interactionCount} interaction${e.interactionCount===1?``:`s`}`;return(0,q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,q.jsx)(V,{title:m?`You`:`${e.displayName} (You)`,accessory:(0,q.jsx)(Y,{role:`guardian`}),compactAccessory:!0,subtitle:w,children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,q.jsx)(N,{label:`Name`,type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:`Your name`,disabled:t,fullWidth:!0}),(0,q.jsx)(N,{label:`Notes`,type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:`Notes about yourself which AI will take into account`,disabled:t,fullWidth:!0}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,q.jsx)(n,{variant:`primary`,onClick:()=>c({displayName:b||e.displayName,notes:x}),disabled:!C,children:t?`Saving…`:`Save`}),l?(0,q.jsx)(n,{variant:`outlined`,onClick:l,disabled:!a||S||i||t,title:a?S?`Save your changes before merging`:void 0:`No other contacts available to merge`,children:i?`Merging…`:`Merge…`}):null]})]})}),(0,q.jsx)(V,{title:`Channels`,subtitle:`Once verified, your assistant will recognize you when you message from these channels.`,children:(0,q.jsx)($,{contactChannels:e.channels,availableChannels:o,a2aEnabled:s,setupLabel:`Verify me`,verifyLoading:r,onSetupChannel:u,onVerifyChannel:d,onRevokeChannel:f})}),p?(0,q.jsx)(B,{onClick:p}):null]})}function Ge(e,t){let n=t.trim().toLowerCase().replace(/^@/,``);return n===``?e:e.filter(e=>e.displayName.toLowerCase().includes(n)||e.username.toLowerCase().includes(n))}function Ke(e){let t=e.trim().split(/\s+/).filter(Boolean);return`${t[0]?.[0]??`?`}${t.length>1?t[t.length-1]?.[0]??``:``}`.toUpperCase()}function qe({open:e,channelLabel:t,contactName:r,accounts:i,loading:a,errorMessage:o,pendingAccountId:s,onPick:c,onClose:l,onInviteInstead:u}){let[d,f]=(0,G.useState)(``);(0,G.useEffect)(()=>{e&&f(``)},[e]);let p=(0,G.useMemo)(()=>Ge(i??[],d),[i,d]),h=s!=null;return(0,q.jsx)(P.Root,{open:e,onOpenChange:e=>!e&&l(),children:(0,q.jsxs)(P.Content,{size:`sm`,children:[(0,q.jsxs)(P.Header,{children:[(0,q.jsxs)(P.Title,{children:[`Link `,t,` account`]}),(0,q.jsxs)(P.Description,{children:[`Search your `,t,` workspace and pick`,` `,(0,q.jsx)(`span`,{className:`text-[color:var(--content-default)]`,children:r}),`’s account.`]})]}),(0,q.jsxs)(P.Body,{className:`flex flex-col gap-3`,children:[(0,q.jsx)(N,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:`Search by name or @handle`,"aria-label":`Search ${t} workspace accounts`,leftIcon:(0,q.jsx)(k,{className:`h-4 w-4`}),fullWidth:!0}),o?(0,q.jsx)(`p`,{className:`text-body-small-default text-[color:var(--content-negative)]`,children:o}):null,(0,q.jsx)(`div`,{className:`max-h-80 overflow-y-auto`,children:a?(0,q.jsx)(`p`,{className:`py-4 text-center text-body-small-default text-[color:var(--content-tertiary)]`,children:`Loading workspace members…`}):p.length===0?(0,q.jsx)(`p`,{className:`py-4 text-center text-body-small-default text-[color:var(--content-tertiary)]`,children:(i?.length??0)===0?`No workspace members found.`:`No members match.`}):(0,q.jsx)(`ul`,{className:`flex flex-col`,children:p.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>c(e),disabled:h,className:`flex w-full cursor-pointer items-center gap-3 rounded-md px-2 py-2 text-left transition-colors hover:bg-[var(--surface-overlay)] disabled:cursor-not-allowed disabled:opacity-60`,children:[e.imageUrl?(0,q.jsx)(`img`,{src:e.imageUrl,alt:``,className:`h-8 w-8 shrink-0 rounded-full`}):(0,q.jsx)(`span`,{"aria-hidden":`true`,className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-[var(--tag-bg-neutral)] text-body-small-emphasised text-[color:var(--content-secondary)]`,children:Ke(e.displayName)}),(0,q.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,q.jsx)(`span`,{className:`truncate text-body-medium-default text-[color:var(--content-default)]`,children:e.displayName}),(0,q.jsxs)(`span`,{className:`truncate text-body-small-default text-[color:var(--content-tertiary)]`,children:[`@`,e.username]})]}),s===e.id?(0,q.jsx)(`span`,{className:`ml-auto shrink-0 text-body-small-default text-[color:var(--content-tertiary)]`,children:`Linking…`}):null]})},e.id))})})]}),(0,q.jsxs)(P.Footer,{className:`items-center justify-between gap-3 border-t border-[var(--border-base)]`,children:[(0,q.jsxs)(`p`,{className:`text-body-small-default text-[color:var(--content-tertiary)]`,children:[`Picking marks this account as`,` `,(0,q.jsx)(`span`,{className:`text-[color:var(--content-secondary)]`,children:`guardian-linked`}),` `,`— you vouch for the identity, no handshake needed.`]}),u?(0,q.jsxs)(n,{variant:`link`,className:`shrink-0`,onClick:u,disabled:h,children:[`Or send an invite instead`,(0,q.jsx)(m,{className:`h-3.5 w-3.5`})]}):null]})]})})}function Je({assistantId:e,channelType:t,contact:n,onLinked:r}){let[i,a]=(0,G.useState)(!1),o=c({mutationFn:n=>U(e,n.contact,{type:t,address:n.account.id}),onSuccess:(e,t)=>{a(!1),ee.success(`Linked as @${t.account.username}`),r()}}),s=(0,G.useCallback)(()=>{o.reset(),a(!0)},[o]),l=(0,G.useCallback)(()=>{o.isPending||(o.reset(),a(!1))},[o]),u=(0,G.useCallback)(e=>{!n||o.isPending||o.mutate({contact:n,account:e})},[n,o]);return{channelType:t,dialogOpen:i,open:s,close:l,linkErrorMessage:o.error instanceof Error?o.error.message:o.error?`Failed to link account`:null,pendingAccountId:o.isPending?o.variables.account.id:null,pick:u}}var Ye=[{id:`slack`,label:`Slack`,subtitle:`Message your assistant from Slack`,icon:`hash`,supportsVerification:!0,setupMessages:{guardian:`I'd like to verify my identity as your guardian on Slack. Can you help me set that up?`,contact:`I'd like to verify a contact's Slack identity. Can you walk me through it?`}},{id:`telegram`,label:`Telegram`,subtitle:`Message your assistant from Telegram`,icon:`send`,supportsVerification:!0,setupMessages:{guardian:`I'd like to verify my identity as your guardian on Telegram. Can you help me set that up?`,contact:`I'd like to verify a contact's Telegram identity. Can you walk me through it?`}},{id:`phone`,label:`Phone Calling`,subtitle:`Call or text your assistant via phone`,icon:`phone`,supportsVerification:!0,setupMessages:{guardian:`I'd like to verify my identity as your guardian for phone calls. Can you help me set that up?`,contact:`I'd like to verify a contact's phone number. Can you help me set that up?`}}],Xe=[];function Ze({assistantId:e,onStartSetupConversation:t}){let n=le.use.a2aChannel(),a=se.use.name(),l=o(),[u]=r(),d=u.get(`setup`),f=d&&_(d)?d:null,[p,m]=(0,G.useState)({kind:`assistant`}),g=pe(e),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(!1),S=de(a),C=(0,G.useMemo)(()=>({path:{assistant_id:e}}),[e]),w=oe(C),T=s({...ae(C),enabled:!!e,select:e=>e.contacts}),E=fe({assistantId:e,onStartSetupConversation:t}),D=s({...ie({path:{assistant_id:e}}),enabled:!!e,queryFn:async({signal:t})=>{let{data:n,error:r,response:i}=await te({path:{assistant_id:e},signal:t,throwOnError:!1});if(!i||i.status===404)return{channels:Ye};if(!i.ok)throw r??Error(`Failed to fetch channel availability`);return n},select:e=>e.channels}).data??Xe,O=T.data,k=(0,G.useMemo)(()=>O?.find(e=>e.role===`guardian`)??null,[O]),A=(0,G.useMemo)(()=>O?.filter(e=>e.role!==`guardian`)??[],[O]),j=(0,G.useMemo)(()=>p.kind===`contact`?O?.find(e=>e.id===p.contactId)??null:null,[O,p]),M=(0,G.useMemo)(()=>!O||!j?[]:O.filter(e=>e.id!==j.id&&e.role!==`guardian`),[O,j]),N=M.length>0,P=(0,G.useRef)(!!f);(0,G.useEffect)(()=>{P.current||k&&(P.current=!0,m({kind:`contact`,contactId:k.id}))},[k]);let F=(0,G.useCallback)(()=>l.invalidateQueries({queryKey:w}),[l,w]),I=c({mutationFn:()=>_e(e,{displayName:`New Contact`}),onMutate:async()=>{await l.cancelQueries({queryKey:w})},onSuccess:e=>{L(l,C,t=>t?{...t,contacts:[...t.contacts,e]}:void 0),m({kind:`contact`,contactId:e.id})},onError:H(`Failed to create contact`),onSettled:()=>F()}),R=c({mutationFn:t=>ve(e,t),onSuccess:(e,t)=>{L(l,C,e=>e?{...e,contacts:e.contacts.filter(e=>e.id!==t)}:void 0),m({kind:`assistant`})},onError:H(`Failed to delete contact`),onSettled:()=>F()}),z=c({mutationFn:({contactId:t,patch:n})=>_e(e,{id:t,displayName:n.displayName,notes:n.notes}),onSuccess:e=>{L(l,C,t=>t?{...t,contacts:t.contacts.map(t=>t.id===e.id?e:t)}:void 0)},onError:H(`Failed to save contact`),onSettled:()=>F()}),B=re({onMutate:async()=>{await l.cancelQueries({queryKey:w})},onSuccess:(e,t)=>{let n=e.contact,r=t.body.mergeId;n&&(L(l,C,e=>e?{...e,contacts:e.contacts.filter(e=>e.id!==r).map(e=>e.id===n.id?n:e)}:void 0),m({kind:`contact`,contactId:n.id})),x(!1),ee.success(`Contacts merged`)},onSettled:()=>F()}),V=(0,G.useCallback)(e=>{m(e),y(!1),x(!1),B.reset()},[B]),U=(0,G.useCallback)(()=>{B.reset(),x(!0)},[B]),ye=(0,G.useCallback)(()=>{B.isPending||(x(!1),B.reset())},[B]),W=ne({onSuccess:()=>F()}),be=(0,G.useCallback)((t,n)=>{W.mutate({path:{assistant_id:e,contactChannelId:t},body:{status:`revoked`}})},[W,e]),xe=(0,G.useCallback)(()=>{I.isPending||I.mutate()},[I]),K=(0,G.useCallback)(e=>{if(!t)return;let n=D.find(t=>t.id===e)?.setupMessages.contact;n&&t(n)},[D,t]),Se=(0,G.useCallback)(e=>{if(!t)return;let n=D.find(t=>t.id===e)?.setupMessages.guardian;n&&t(n)},[D,t]),J=c({mutationFn:t=>ge(e,t.channelId),onSuccess:()=>F(),onError:H(`Failed to verify channel`)}),Y=(0,G.useCallback)(e=>{if(!j)return;let t=j.channels.find(t=>t.type===e&&t.status!==`revoked`);t&&J.mutate({channelId:t.id})},[j,J]),X=Je({assistantId:e,channelType:`slack`,contact:j?{id:j.id,displayName:j.displayName}:null,onLinked:F}),Z=s({...h(e),enabled:!!e&&X.dialogOpen,select:e=>e.users}),we=E.channels.some(e=>e.key===`slack`&&e.status===`ready`),Te=(0,G.useCallback)(e=>{e===X.channelType&&X.open()},[X]),Ee=R.isPending?R.variables:null,Q=(0,G.useMemo)(()=>j?z.isPending&&z.variables?.contactId===j.id?{...j,displayName:z.variables.patch.displayName,notes:z.variables.patch.notes}:j:null,[j,z.isPending,z.variables]);if(f)return(0,q.jsx)(i,{to:`${ce.channels}?setup=${f}`,replace:!0});let $={loading:T.isLoading,assistantName:S,guardian:k?{id:k.id,displayName:k.displayName.startsWith(`vellum-principal-`)?``:k.displayName,role:k.role,channelTypes:tt(k.channels,n)}:null,regularContacts:A.filter(e=>e.id!==Ee).map(e=>({id:e.id,displayName:e.displayName,role:e.role,contactType:e.contactType,channelTypes:tt(e.channels,n),verified:et(e.channels)})),selection:p,onAddContact:xe,addingContact:I.isPending};return(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden sm:flex-row sm:gap-6`,children:[(0,q.jsx)(`div`,{className:`flex items-center sm:hidden`,children:(0,q.jsx)(me,{onClick:()=>y(!0)})}),(0,q.jsx)(he,{open:v,onClose:()=>y(!1),title:`Contacts`,children:(0,q.jsx)(Ve,{...$,onSelect:V})}),(0,q.jsx)(`aside`,{className:`hidden min-h-0 w-[320px] shrink-0 overflow-y-auto self-stretch sm:block`,children:(0,q.jsx)(Ve,{...$,onSelect:V})}),(0,q.jsx)(`section`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:p.kind===`assistant`||p.kind===`contact`&&p.contactId===Ee?(0,q.jsx)(Ce,{assistantName:S,channels:E.channels,pendingChannelKey:E.pendingChannelKey,onConnect:E.onSetup,onDisconnect:E.onDisconnect}):Q?Q.role===`guardian`?(0,q.jsx)(Ue,{contact:Q,savePending:z.isPending,verifyPending:J.isPending,mergePending:B.isPending,canMerge:N,availableChannels:D,a2aEnabled:n,onSave:e=>{z.mutate({contactId:Q.id,patch:e})},onMerge:U,onSetupChannel:t?Se:void 0,onVerifyChannel:Y,onRevokeChannel:be,onGenerateInviteLink:n?g.open:void 0}):(0,q.jsx)(Oe,{contact:Q,savePending:z.isPending,deletePending:R.isPending,verifyPending:J.isPending,mergePending:B.isPending,canMerge:N,availableChannels:D,a2aEnabled:n,onSave:e=>{z.mutate({contactId:Q.id,patch:e})},onDelete:()=>{R.mutate(Q.id)},onMerge:U,onSetupChannel:t?K:void 0,onVerifyChannel:Y,onRevokeChannel:be,onLinkAccount:we?Te:void 0}):(0,q.jsx)(Qe,{})}),j?(0,q.jsx)(Ae,{open:b,survivor:j,candidates:M,pending:B.isPending,errorMessage:B.error instanceof Error?B.error.message:B.error?`Failed to merge contacts`:null,onMerge:t=>B.mutate({path:{assistant_id:e},body:{keepId:j.id,mergeId:t}}),onClose:ye}):null,(0,q.jsx)(qe,{open:X.dialogOpen,channelLabel:`Slack`,contactName:j?.displayName??``,accounts:Z.data,loading:Z.isLoading,errorMessage:Z.isError?`Couldn’t load the workspace roster. Check the Slack connection and try again.`:X.linkErrorMessage,pendingAccountId:X.pendingAccountId,onPick:X.pick,onClose:X.close,onInviteInstead:t?()=>{X.close(),K(X.channelType)}:void 0}),(0,q.jsx)(ue,{open:g.isOpen,assistantId:e,onClose:g.close})]})}function Qe(){return(0,q.jsx)(`div`,{className:`flex h-full items-center justify-center py-16`,children:(0,q.jsx)(`p`,{className:`text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:`Select a contact`})})}var $e={slack:`Slack`,telegram:`Telegram`,phone:`Phone`,email:`Email`,whatsapp:`WhatsApp`,a2a:`A2A`};function et(e){return e.some(e=>e.status!==`revoked`&&(e.type===`a2a`||K(e)))}function tt(e,t){let n=new Set,r=[];for(let i of e){if(i.status===`revoked`)continue;let e=i.type.toLowerCase();n.has(e)||e===`a2a`&&!t||(n.add(e),r.push($e[e]??i.type))}return r}function nt(){let e=a(),t=z();return(0,q.jsx)(Ze,{assistantId:t,onStartSetupConversation:t=>{R(e,{prompt:t})}},t)}export{nt as ContactsPageRoute};