@vellumai/web 0.11.0-dev.202607291248.5e5423d → 0.11.0-dev.202607291450.e26688c

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.
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{a as t,c as n,i as r}from"./local-settings-C-dW2vkq.js";import{r as i,t as a}from"./capture-error-FWzaVb8P.js";import{t as o}from"./react-BFJW0bSv.js";import{t as s}from"./button-Dy5001j6.js";import{m as c,u as l}from"./chunk-5KNZJZUH-Bsoom5--.js";import{n as u}from"./QueryClientProvider-CMu7CkQU.js";import{t as d}from"./useQuery-Bz-fbQ-m.js";import{t as f}from"./useMutation-CXGTrp4W.js";import{t as p}from"./jsx-runtime-D3ZM-ToX.js";import{t as m}from"./cn-CJf7MmLX.js";import{t as h}from"./typography-DEI9Ra9z.js";import{t as g}from"./check-sC49_hjU.js";import{t as _}from"./chevron-down-B5A-0g8A.js";import{t as v}from"./circle-alert-DVCpoZrc.js";import{t as y}from"./circle-check-CjGnAahM.js";import{t as b}from"./menu-CKZtG-s_.js";import{t as x}from"./clock-BYTc0Ds9.js";import{t as S}from"./list-row-BYrmPIC4.js";import{t as C}from"./ellipsis-vertical-nov0xhhF.js";import{t as w}from"./external-link-CAce-RVu.js";import{t as T}from"./info-CYiVdnQV.js";import{t as E}from"./list-CDyb1CGV.js";import{t as D}from"./loader-circle-BzJ2kz3F.js";import{t as O}from"./mail-DABv3_Ue.js";import{t as k}from"./plus-JG7kWjHA.js";import{t as A}from"./search-DA3TmTuR.js";import{t as j}from"./trash-2-De6X8YiM.js";import{t as M}from"./triangle-alert--e3n47gm.js";import{t as N}from"./notice-DCp7WO3L.js";import{M as P}from"./src-CXhyCUAb.js";import{t as F}from"./tag-D8NAGb0r.js";import{t as I}from"./popover-BFL-uOLh.js";import{t as L}from"./input-C-GkeWCw.js";import{t as R}from"./toggle-D776PTw-.js";import{t as z}from"./modal-DwsThLGg.js";import{n as B}from"./toast-DR7D7Uma.js";import{t as ee}from"./confirm-dialog-DZX6LhLy.js";import{t as V}from"./dropdown-Dt0Iof85.js";import{$ as H,B as U,C as W,F as te,G,H as K,I as q,J as ne,K as J,L as re,M as Y,N as ie,P as ae,Q as oe,R as se,S as ce,T as le,U as ue,V as de,W as fe,X as pe,Y as me,Z as he,_ as ge,a as _e,at as ve,c as ye,ct as be,d as xe,dt as Se,et as Ce,f as we,g as Te,h as Ee,i as De,it as Oe,j as ke,l as Ae,lt as je,m as Me,n as Ne,nt as Pe,o as Fe,ot as Ie,p as Le,q as Re,r as ze,rt as Be,s as Ve,st as He,t as Ue,tt as We,u as Ge,ut as Ke,v as qe,w as Je,x as Ye,y as Xe,z as Ze}from"./use-sticky-profiles-DGyk-gqL.js";import{t as Qe}from"./assistant-identity-store-BczULg2T.js";import{i as $e,r as et,t as tt}from"./utils-CIvMYJQ9.js";import{r as nt}from"./api-errors-SZKDzMLE.js";import{Gt as rt,Tn as it,Wt as at,ft as ot,j as st,lt as ct,or as lt}from"./sdk.gen-BpXADDVr.js";import{d as ut}from"./routes-GmNvdtLW.js";import{i as dt}from"./use-platform-gate-tFGgV7DD.js";import{r as ft}from"./use-is-org-ready-BBEFTAYz.js";import{H as pt,Ht as mt,Lt as ht,U as gt,V as _t,W as vt,c as X,d as yt,f as bt,l as xt,m as St,p as Ct,u as wt,yt as Tt}from"./react-query.gen-CHKuXvhB.js";import{n as Et}from"./use-is-mobile-Cx2xnNUx.js";import{c as Dt,d as Ot,f as kt,g as At,h as jt,l as Mt,lt as Nt,m as Pt,o as Ft,p as It,s as Lt,u as Rt,v as zt,y as Bt}from"./react-query.gen-D3PlzpvD.js";import{a as Vt,i as Ht,n as Ut,o as Wt}from"./voice-list-CbCzxcgt.js";import{t as Gt}from"./platform-login-notice-Cexm_R9g.js";import{t as Z}from"./use-active-assistant-id-DDp_V4pO.js";import{t as Kt}from"./detail-shell-BabBuKSF.js";import{t as qt}from"./detail-card-C5IwAWc6.js";import{n as Jt,t as Yt}from"./detail-drawer-hBuwSVX0.js";import{t as Xt}from"./use-platform-assistant-id-D4XJdlKK.js";import{t as Zt}from"./environment-store-CCr1mq7O.js";var Q=e(o(),1),$=p();function Qt({mode:e,onChange:t}){return(0,$.jsx)(`div`,{className:`max-w-[280px]`,children:(0,$.jsx)(P,{ariaLabel:`Service mode`,value:e,onChange:t,items:[{value:`managed`,label:`Managed`},{value:`your-own`,label:`Your Own`}]})})}function $t({id:e,title:t,subtitle:n,mode:r,onModeChange:i,children:a}){return(0,$.jsxs)(qt,{id:e,title:t,subtitle:n,accessory:(0,$.jsx)(Qt,{mode:r,onChange:i}),children:[(0,$.jsx)(`div`,{className:`h-px bg-[var(--surface-active)]`}),(0,$.jsx)(`div`,{className:`mt-4`,children:a})]})}function en({id:e,title:t,subtitle:n,children:r}){return(0,$.jsxs)(qt,{id:e,title:t,subtitle:n,children:[(0,$.jsx)(`div`,{className:`h-px bg-[var(--surface-active)]`}),(0,$.jsx)(`div`,{className:`mt-4`,children:r})]})}function tn(){return(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-[var(--border-base)] bg-[var(--surface-base)] px-4 py-2.5`,children:[(0,$.jsx)(T,{className:`mt-0.5 h-4 w-4 shrink-0 text-[var(--content-tertiary)]`}),(0,$.jsxs)(`p`,{className:`text-body-medium-lighter text-[var(--content-secondary)]`,children:[`Managed services are metered and deducted from your Vellum account balance.`,` `,(0,$.jsxs)(`a`,{href:`https://www.vellum.ai/docs/pricing`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[var(--primary-base)] hover:underline`,children:[`View pricing`,(0,$.jsx)(w,{className:`h-3.5 w-3.5`})]})]})]})}function nn({status:e,message:t,isLoading:n}){return n?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-[var(--tag-bg-neutral)] px-2.5 py-0.5 text-body-small-default text-[var(--content-quiet)]`,children:[(0,$.jsx)(D,{className:`h-3 w-3 animate-spin`}),`Checking domain…`]}):e?e===`verified`?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-[var(--system-positive-weak)] px-2.5 py-0.5 text-body-small-default text-[var(--system-positive-strong)]`,title:`DNS records have been verified. Your domain is ready to send and receive email.`,children:[(0,$.jsx)(g,{className:`h-3 w-3`}),`Domain verified`]}):e===`pending`||e===`not_started`?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-[var(--system-mid-weak)] px-2.5 py-0.5 text-body-small-default text-[var(--system-mid-strong)]`,title:`DNS records have been provisioned. Waiting for the email provider to verify them — this usually takes a few minutes.`,children:[(0,$.jsx)(x,{className:`h-3 w-3`}),`Verifying domain…`]}):(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-[var(--system-negative-weak)] px-2.5 py-0.5 text-body-small-default text-[var(--system-negative-strong)]`,title:`Domain verification failed. DNS records may not have propagated correctly. You could try releasing and re-registering the domain.`,children:[(0,$.jsx)(v,{className:`h-3 w-3`}),`Verification failed`]}):(0,$.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-[var(--tag-bg-neutral)] px-2.5 py-0.5 text-body-small-default text-[var(--content-quiet)]`,title:`Unable to retrieve domain verification status.`,children:`Unknown status`})}function rn({onClick:e,disabled:t}){return(0,$.jsx)(s,{onClick:e,disabled:t,children:`Save`})}function an({onClick:e,filled:t=!1}){return(0,$.jsx)(s,{variant:t?`danger`:`dangerGhost`,onClick:e,children:`Reset`})}function on({guide:e}){return(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-sunken)] p-3 text-body-small-default text-[var(--content-tertiary)]`,children:[(0,$.jsx)(T,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-[var(--system-positive-strong)]`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{children:e.description}),(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[var(--system-positive-strong)] underline hover:opacity-80`,children:[e.linkLabel,(0,$.jsx)(w,{className:`h-3 w-3`})]})]})]})}function sn({subdomain:e,onSubdomainChange:t,domainSuffix:n,subdomainPlaceholder:r=`my-assistant`,disabled:i,autoFocus:a,prefix:o,error:s,locked:c,lockedMessage:l}){return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex h-9 w-full items-center rounded-md border bg-[var(--field-bg)] text-body-medium-lighter transition-[border-color] duration-150 ${s?`border-[var(--system-negative-strong)]`:`border-[var(--field-border)] focus-within:border-[var(--border-active)]`}`,children:[o,(0,$.jsx)(`input`,{value:e,onChange:e=>t(e.target.value.toLowerCase().trim()),disabled:i||c,readOnly:c,autoFocus:a,placeholder:r,"aria-label":`Subdomain`,"aria-invalid":!!s,className:`h-full min-w-0 flex-1 bg-transparent ${o?`pl-1.5`:`pl-3`} pr-1 text-[var(--content-default)] placeholder:text-[var(--content-tertiary)] outline-none disabled:cursor-not-allowed disabled:opacity-60`}),(0,$.jsxs)(`span`,{className:`shrink-0 pr-3 font-mono text-[var(--content-secondary)]`,children:[`.`,n]})]}),s&&(0,$.jsx)(`p`,{className:`mt-1.5 text-body-small-default text-[var(--system-negative-strong)]`,children:s}),c&&l&&(0,$.jsx)(`p`,{className:`mt-1.5 text-body-small-default text-[var(--content-tertiary)]`,children:l})]})}function cn({assistantId:e,assistantHandle:t,emailRootDomain:n}){let r=u(),i=l(),[o,p]=c(),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(!1),[E,k]=(0,Q.useState)(!1),[A,M]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{g||!t||m||(h(t),_(!0))},[t,g,m]);let P=d({...Nt(),enabled:!0}),F=P.data,I=F?.entitlements,L=I?.managed_email===!0,R=!!I&&!L,z=!F&&P.isError&&!P.isFetching,V=d({...Dt({path:{assistant_id:e}}),enabled:!R}),H=d({...It({path:{assistant_id:e}}),enabled:!R}),U=V.data?.results?.[0],W=H.data?.results?.[0],te=U?`${U.subdomain}.${n}`:null,G=d({...jt({path:{assistant_id:e,id:W?.id??``}}),enabled:!!W?.id,refetchOnWindowFocus:!1}),K=d({...Rt({path:{assistant_id:e,id:U?.id??``}}),enabled:!!U?.id,refetchInterval:e=>{let t=e.state.data?.status;return t===`verified`||t===`failed`?!1:1e4},refetchOnWindowFocus:!0});(0,Q.useEffect)(()=>{o.get(`release`)!==`1`||!U||W||(k(!0),p(e=>{let t=new URLSearchParams(e);return t.delete(`release`),t},{replace:!0}))},[W,U,o,p]);let q=f(Ft()),ne=f(Lt()),J=f(Ot()),re=f(kt()),Y=(0,Q.useCallback)(()=>{let t={assistant_id:e};r.invalidateQueries({queryKey:Mt({path:t})}),r.invalidateQueries({queryKey:Pt({path:t})}),W?.id&&r.invalidateQueries({queryKey:At({path:{...t,id:W.id}})}),r.invalidateQueries({queryKey:Bt()})},[W?.id,e,r]),ie=(0,Q.useCallback)(async()=>{let t=m.trim().toLowerCase();if(!t){y(`Enter a subdomain.`);return}T(!1);try{await q.mutateAsync({path:{assistant_id:e},body:{subdomain:t}}),h(``),y(null),Y(),B.success(`Domain ${t}.${n} registered.`)}catch(e){y(nt(e,void 0,`Failed to register domain.`))}},[e,n,Y,q,m]),ae=(0,Q.useCallback)(async()=>{let t=b.trim().toLowerCase();if(!t){C(`Enter an email username.`);return}try{await J.mutateAsync({path:{assistant_id:e},body:{username:t}}),x(``),C(null),Y(),B.success(`Email address created.`)}catch(e){C(nt(e,void 0,`Failed to create email address.`))}},[e,Y,J,b]),oe=(0,Q.useCallback)(async()=>{if(W?.id){M(!1);try{await re.mutateAsync({path:{assistant_id:e,id:W.id}}),Y(),B.success(`Email address removed.`)}catch(e){a(e,{context:`email_address_delete`}),B.error(`Failed to remove email address.`)}}},[W?.id,e,re,Y]),se=(0,Q.useCallback)(async()=>{if(!U?.id)return;if(W){B.error(`Remove the email address first.`);return}k(!1);let t=U.subdomain;try{await ne.mutateAsync({path:{assistant_id:e,id:U.id}}),h(t),Y(),B.success(`Domain released.`)}catch(e){a(e,{context:`email_domain_release`}),B.error(`Failed to release domain.`)}},[W,e,ne,U?.id,U?.subdomain,Y]);if(P.isLoading)return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-body-small-default text-[var(--content-tertiary)]`,children:[(0,$.jsx)(D,{className:`h-4 w-4 animate-spin`}),`Checking subscription…`]});if(R)return(0,$.jsx)(N,{tone:`info`,icon:(0,$.jsx)(O,{className:`h-4 w-4`,"aria-hidden":!0}),title:`Give your assistant its own email address`,actions:(0,$.jsx)(s,{size:`compact`,onClick:()=>i(ut.plans),children:`Upgrade`}),children:`Upgrade to a plan that includes an email address for your assistant. No provider setup required.`});let ce=z?(0,$.jsx)(N,{tone:`warning`,title:`Couldn't verify subscription status`,actions:(0,$.jsx)(s,{size:`compact`,variant:`outlined`,onClick:()=>P.refetch(),children:`Retry`}),children:`We couldn't reach the billing service. The form below assumes managed email is enabled for your org — if it isn't, registering a domain will fail.`}):null;return U?W?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[ce,(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Address`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-mono text-body-small-default text-[var(--content-default)]`,children:W.address}),(0,$.jsx)(nn,{status:K.data?.status,message:K.data?.message,isLoading:K.isLoading}),(0,$.jsx)(s,{variant:`dangerGhost`,size:`compact`,iconOnly:(0,$.jsx)(j,{}),onClick:()=>M(!0),disabled:re.isPending,"aria-label":`Remove email address`})]}),(0,$.jsx)(ee,{open:A,title:`Remove Email Address`,message:(0,$.jsxs)($.Fragment,{children:[`Are you sure you want to remove`,` `,(0,$.jsx)(`code`,{className:`rounded bg-[var(--surface-active)] px-1 py-0.5 font-mono text-[0.9em]`,children:W.address}),`? Your assistant will no longer be able to send or receive email at this address.`]}),confirmLabel:`Remove`,destructive:!0,onConfirm:oe,onCancel:()=>M(!1)})]}),G.data?.usage&&(0,$.jsxs)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:[G.data.usage.sent_today,` /`,` `,G.data.usage.daily_limit,` sent today ·`,` `,G.data.usage.received_today,` received`]})]}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[ce,(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Domain`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`font-mono text-body-small-default text-[var(--content-default)]`,children:[U.subdomain,`.`,n]}),(0,$.jsx)(nn,{status:K.data?.status,message:K.data?.message,isLoading:K.isLoading}),(0,$.jsx)(s,{variant:`dangerGhost`,size:`compact`,iconOnly:(0,$.jsx)(j,{}),onClick:()=>k(!0),disabled:ne.isPending,"aria-label":`Release domain`})]}),(0,$.jsx)(ee,{open:E,title:`Release Domain`,message:(0,$.jsxs)($.Fragment,{children:[`Are you sure you want to release`,` `,(0,$.jsxs)(`code`,{className:`rounded bg-[var(--surface-active)] px-1 py-0.5 font-mono text-[0.9em]`,children:[U.subdomain,`.`,n]}),`? The subdomain will become available for others to claim.`]}),confirmLabel:`Release`,destructive:!0,onConfirm:se,onCancel:()=>k(!1)})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Email address`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex h-9 min-w-0 flex-1 items-center rounded-md border bg-[var(--field-bg)] text-body-medium-lighter transition-[border-color] duration-150 ${S?`border-[var(--system-negative-strong)]`:`border-[var(--field-border)] focus-within:border-[var(--border-active)]`}`,children:[(0,$.jsx)(`input`,{value:b,onChange:e=>{x(e.target.value.toLowerCase()),S&&C(null)},placeholder:`hi`,"aria-label":`Email username`,"aria-invalid":!!S,className:`h-full min-w-0 flex-1 bg-transparent pl-3 pr-1 text-[var(--content-default)] placeholder:text-[var(--content-tertiary)] outline-none`}),(0,$.jsxs)(`span`,{className:`shrink-0 pr-3 font-mono text-[var(--content-secondary)]`,children:[`@`,te]})]}),(0,$.jsx)(s,{onClick:ae,disabled:J.isPending||!b.trim(),children:J.isPending?`Creating…`:`Create`})]}),S&&(0,$.jsx)(`p`,{className:`text-body-small-default text-[var(--system-negative-strong)]`,children:S})]})]}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[ce,(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Subdomain`}),(0,$.jsx)(sn,{subdomain:m,onSubdomainChange:e=>{h(e),v&&y(null)},domainSuffix:n,subdomainPlaceholder:`my-assistant`,error:v}),(0,$.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`Each assistant gets its own subdomain. Lowercase letters, numbers, and hyphens only.`}),(0,$.jsx)(s,{onClick:()=>T(!0),disabled:q.isPending||!m.trim(),children:q.isPending?`Registering…`:`Register`}),(0,$.jsx)(ee,{open:w,title:`Set Subdomain`,message:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`code`,{className:`rounded bg-[var(--surface-active)] px-1 py-0.5 font-mono text-[0.9em]`,children:m.trim().toLowerCase()||`subdomain`}),` `,`will also become your assistant's public handle. You won't be able to change it once set.`]}),confirmLabel:`Confirm`,onConfirm:ie,onCancel:()=>T(!1)})]})}function ln(){let e=Z(),t=ft(),{data:o}=d({...zt(),enabled:t}),s=o?.results?.[0]?.handle,c=Zt.use.emailRootDomain(),l=dt(),[u,f]=(0,Q.useState)(()=>l===`gated`?`your-own`:oe(r(Fe,`managed`),`managed`)),[p,m]=(0,Q.useState)(()=>{let e=r(_e,`resend`);return e===`mailgun`||e===`resend`?e:`resend`}),{platformAssistantId:h,error:g}=Xt(e,l===`full`&&u===`managed`),_=h??(g?e:null),v=d({queryKey:[`byoEmailCredential`,e,p],queryFn:async()=>{let{data:t}=await ct({path:{assistant_id:e},body:{service:p,field:`api_key`},throwOnError:!0});return t},enabled:u===`your-own`||l===`gated`,staleTime:6e4,retry:i,meta:{errorContext:`byo_email_credential_check`}});(0,Q.useEffect)(()=>{v.error&&a(v.error,{context:`byo_email_credential_check`,bestEffort:!0})},[v.error]);let b=v.data?.hasSecret===!0,x=(0,Q.useCallback)(e=>{f(e),n(Fe,e)},[]),S=(0,Q.useCallback)(()=>{n(_e,p),B.success(`Email settings saved.`)},[p]),C=(0,Q.useMemo)(()=>Te.find(e=>e.id===p)??Te[0],[p]),E=(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-sunken)] p-3 text-body-small-default text-[var(--content-tertiary)]`,children:[(0,$.jsx)(T,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-[var(--system-positive-strong)]`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`span`,{children:[`Configure `,C.displayName,` via the assistant CLI: ask the assistant to run the`,` `,(0,$.jsx)(`code`,{className:`rounded bg-[var(--surface-active)] px-1 py-0.5 text-[12px]`,children:C.setupSkill}),` `,`skill. It walks you through storing the API key, detecting the domain, and (optionally) wiring up an inbound webhook.`]}),(0,$.jsxs)(`a`,{href:C.docsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[var(--system-positive-strong)] underline hover:opacity-80`,children:[`Open `,C.displayName,(0,$.jsx)(w,{className:`h-3 w-3`})]})]})]}),O=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,$.jsx)(V,{value:p,onChange:e=>{(e===`mailgun`||e===`resend`)&&m(e)},options:Te.map(e=>({value:e.id,label:e.displayName}))})]}),b?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-[var(--system-positive-subtle)] bg-[var(--surface-sunken)] p-3 text-body-small-default text-[var(--content-default)]`,children:[(0,$.jsx)(y,{className:`h-4 w-4 shrink-0 text-[var(--system-positive-strong)]`}),(0,$.jsxs)(`span`,{children:[C.displayName,` API key configured. To reconfigure, run the`,` `,(0,$.jsx)(`code`,{className:`rounded bg-[var(--surface-active)] px-1 py-0.5 text-[12px]`,children:C.setupSkill}),` `,`skill.`]})]}),(0,$.jsxs)(`a`,{href:C.docsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-body-small-default text-[var(--system-positive-strong)] underline hover:opacity-80`,children:[`Open `,C.displayName,(0,$.jsx)(w,{className:`h-3 w-3`})]})]}):E,(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(rn,{onClick:S,disabled:!1})})]});return l===`gated`?(0,$.jsx)(en,{id:`email`,title:`Email`,subtitle:`Configure how your assistant sends and receives email`,children:O}):(0,$.jsx)($t,{id:`email`,title:`Email`,subtitle:`Configure how your assistant sends and receives email`,mode:u,onModeChange:x,children:u===`managed`?(0,$.jsx)(`div`,{className:`space-y-4`,children:l===`disabled`?(0,$.jsx)(Gt,{children:`Log in to the Vellum platform to manage email settings.`}):_===null?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-body-small-default text-[var(--content-tertiary)]`,children:[(0,$.jsx)(D,{className:`h-4 w-4 animate-spin`}),`Connecting to the Vellum platform…`]}):(0,$.jsx)(cn,{assistantId:_,assistantHandle:s,emailRootDomain:c})}):O})}function un(){let e=Z();return(0,Q.useCallback)(async(t,n)=>{try{let{data:r}=await lt({path:{assistant_id:e},body:{value:n,type:`api_key`,name:t},throwOnError:!0});ne(r)}catch(e){throw e instanceof Error&&e.message===`No assistant found`?B.error(`Assistant not ready. Please try again.`):B.error(`Failed to save ${t} API key. Please try again.`),a(e,{context:`provision_provider_key`}),e}},[e])}function dn(e){let[t,n]=(0,Q.useState)(void 0);return(0,Q.useEffect)(()=>{t!==void 0&&e===t.value&&n(void 0)},[e,t]),[t===void 0?e:t.value,(0,Q.useCallback)(e=>n(e===void 0?void 0:{value:e}),[])]}var fn=`0.11.0`;function pn(){return tt(fn)}var mn=`gemini-3.1-flash-image-preview`;function hn(){let e=Z(),t=u(),i=ft(),{data:o}=d({...X({path:{assistant_id:e}}),enabled:i,staleTime:3e4}),s=mt({onSuccess:n=>{wt(t,{path:{assistant_id:e}},n)}}),c=un(),[l,f]=dn((0,Q.useMemo)(()=>{if(!o)return r(ye,`gemini`);let e=o.services?.[`image-generation`];return e?.mode===`managed`?`vellum`:e?.provider||r(`vellum:ai:imageGenProvider`,`gemini`)},[o])),[p,m]=(0,Q.useState)(()=>r(Ve,mn)),h=W(l),g=h.includes(p)?p:h[0]??mn,[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(!1),x=qe.map(e=>({value:e,label:Xe[e]??e})),S=(0,Q.useMemo)(()=>W(l).map(e=>({value:e,label:ge[e]??e})),[l]),C=l===`gemini`||l===`openai`,{hasStoredCredential:w}=K({assistantId:e,credentialKind:`api_key`,credentialName:l,enabled:C}),T=f,E=(0,Q.useCallback)(async()=>{b(!0);let r=_.trim(),i=C&&r.length>0;try{i&&await c(Je(g),r),await $e();let n=l===`vellum`&&!pn()?{mode:`managed`}:{provider:l,mode:l===`vellum`?`managed`:`your-own`};await s.mutateAsync({path:{assistant_id:e},body:{services:{"image-generation":n}}}).catch(e=>{throw B.error(`Failed to update assistant configuration. Please try again.`),a(e,{context:`patch_daemon_config`}),e});try{await it({path:{assistant_id:e},body:{modelId:g},throwOnError:!0})}catch(e){throw B.error(`Failed to update image generation model. Please try again.`),a(e,{context:`set_image_gen_model`}),e}finally{t.invalidateQueries({queryKey:xt({path:{assistant_id:e}})})}}catch{b(!1);return}b(!1);try{if(n(ye,l),n(Ve,g),i){let n=de(e,`api_key`,l);t.setQueryData(n,!0),t.invalidateQueries({queryKey:n}),v(``)}B.success(`Image generation settings saved.`)}catch(e){a(e,{context:`settings-ai-image-gen-persist-local`}),B.error(`Saved, but local preferences could not be written.`)}},[_,l,C,g,e,s,c,t]),O=(0,Q.useCallback)(()=>{v(``),m(mn),n(Ve,mn)},[]);return(0,$.jsx)(en,{title:`Image Generation`,subtitle:`Configure which model your assistant uses to generate images`,children:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,$.jsx)(V,{"aria-label":`Image generation provider`,value:l,onChange:T,options:x})]}),l===`vellum`&&(0,$.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Image generation runs through your Vellum account.`}),C&&(0,$.jsx)(L,{label:`API Key`,type:`password`,value:_,onChange:e=>v(e.target.value),placeholder:q(l===`openai`?`Enter your OpenAI API key`:`Enter your Gemini API key`,w),fullWidth:!0}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Active Model`}),(0,$.jsx)(V,{"aria-label":`Image generation model`,value:g,onChange:m,options:S})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(rn,{onClick:E,disabled:y}),y&&(0,$.jsx)(D,{className:`h-4 w-4 animate-spin text-[var(--content-disabled)]`}),C&&(0,$.jsx)(an,{onClick:O})]})]})})}function gn({title:e,count:t,action:n,children:r}){return(0,$.jsxs)(`section`,{className:`rounded-xl border border-[var(--border-hover)] bg-[var(--surface-overlay)] px-3 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,$.jsx)(h,{variant:`body-large-default`,as:`h3`,className:`text-[var(--content-secondary)]`,children:e}),t==null?null:(0,$.jsxs)(h,{variant:`body-large-default`,as:`span`,"aria-label":`${t} ${e.toLowerCase()}`,className:`text-[var(--content-disabled)]`,children:[`·`,` `,t]})]}),n]}),r==null?null:(0,$.jsx)(`div`,{className:`mt-4 border-t border-[var(--border-base)]`,children:r})]})}function _n({blocked:e,availableReplacements:t,replacement:n,onReplacementChange:r,error:i,saving:a,onClose:o,onConfirm:c}){let l=``;if(e){let t=e.label||e.name;l=e.isActive&&e.callSiteIds.length>0?`"${t}" is the active profile and is used by ${e.callSiteIds.length} call site(s). Pick a replacement profile.`:e.isActive?`"${t}" is the active profile. Pick a different active profile before deleting, or select a replacement below.`:`"${t}" is used by ${e.callSiteIds.length} call site(s). Select a replacement profile to reassign them before deleting.`}return(0,$.jsx)(z.Root,{open:e!==null,onOpenChange:e=>{e||o()},children:(0,$.jsxs)(z.Content,{size:`sm`,children:[(0,$.jsx)(z.Header,{children:(0,$.jsx)(z.Title,{children:`Can't Delete Profile`})}),(0,$.jsxs)(z.Body,{className:`space-y-4`,children:[(0,$.jsx)(h,{variant:`body-medium-default`,as:`p`,children:l}),e&&e.callSiteIds.length>0&&(0,$.jsx)(`ul`,{className:`space-y-1 pl-1`,children:e.callSiteIds.map(e=>(0,$.jsxs)(`li`,{className:`text-body-small-default text-(--content-secondary)`,children:[`• `,(0,$.jsx)(`code`,{children:e})]},e))}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Replacement profile`}),(0,$.jsx)(V,{"aria-label":`Replacement profile`,value:n,onChange:r,options:[{value:``,label:`Select a replacement…`},...t.map(e=>({value:e.name,label:e.label??e.name}))]})]}),i&&(0,$.jsx)(h,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:i})]}),(0,$.jsxs)(z.Footer,{children:[(0,$.jsx)(s,{variant:`ghost`,size:`compact`,onClick:o,children:`Cancel`}),(0,$.jsx)(s,{variant:`primary`,size:`compact`,disabled:!n||a,onClick:c,children:a?`Saving…`:`Reassign and Delete`})]})]})})}function vn({profile:e,isActiveProfile:t,isAdvisorProfile:n,selected:r,connections:i,onOpen:a,onMakeActive:o,onMakeAdvisor:c,onClearAdvisor:l,onSetStatus:u,onDelete:d}){let f=e.source===`managed`,p=e.status===`disabled`,m=e.label??e.name,h=[];e.model&&h.push(Y(e.provider??void 0,e.model,i)),f&&h.push(`Managed by Vellum`);let g=e.availability,_=g!=null&&g.status!==`ok`?g.message??`This profile's provider is not available.`:null;return(0,$.jsx)(S,{title:(0,$.jsx)(`span`,{className:p?`opacity-55`:void 0,children:m}),subtitle:h.length>0?h.join(` • `):void 0,onClick:a,showChevron:!1,selected:r,contentAriaLabel:`Open profile ${m}`,trailingInteractive:!0,trailing:(0,$.jsxs)($.Fragment,{children:[_==null?null:(0,$.jsx)(`span`,{title:_,className:`inline-flex`,children:(0,$.jsx)(v,{className:`h-4 w-4 text-[var(--system-mid-strong)]`,"aria-label":_,role:`img`})}),p?(0,$.jsx)(F,{tone:`neutral`,children:`Disabled`}):null,t?(0,$.jsx)(F,{tone:`positive`,children:`Default`}):null,n?(0,$.jsx)(F,{tone:`warning`,children:`Advisor`}):null,(0,$.jsxs)(b.Root,{children:[(0,$.jsx)(b.Trigger,{asChild:!0,children:(0,$.jsx)(s,{variant:`ghost`,size:`compact`,iconOnly:(0,$.jsx)(C,{}),"aria-label":`Actions for ${m}`})}),(0,$.jsxs)(b.Content,{align:`end`,sideOffset:4,children:[(0,$.jsx)(b.Item,{onSelect:a,children:f?`View`:`Edit`}),!t&&!p?(0,$.jsx)(b.Item,{onSelect:o,children:`Make Default`}):null,!n&&!p?(0,$.jsx)(b.Item,{onSelect:c,children:`Make Advisor`}):null,n?(0,$.jsx)(b.Item,{onSelect:l,children:`Remove as Advisor`}):null,p?(0,$.jsx)(b.Item,{onSelect:()=>u(!0),children:`Enable`}):f?null:(0,$.jsx)(b.Item,{onSelect:()=>u(!1),children:`Disable`}),f?null:(0,$.jsx)(b.Item,{onSelect:d,className:`text-[var(--system-negative-strong)] data-[highlighted]:text-[var(--system-negative-strong)]`,children:`Delete`})]})]})]})})}var yn=`0.11.0`;function bn(){return et(yn)}function xn(e,t){let n=bn(),{data:r}=d({..._t({path:{assistant_id:e}}),enabled:n,staleTime:3e4}),{profiles:i,profileOrder:a}=Ue(t?.llm,e);return(0,Q.useMemo)(()=>r==null?{entries:me(i,a).map(e=>({name:e.name,label:e.label??null,provider:e.provider??null,model:e.model??null,status:e.status===`disabled`?`disabled`:`active`,source:e.source===`managed`?`managed`:`user`,provider_connection:e.provider_connection,availability:null})),isEffectiveCatalog:!1}:{entries:r.profiles,isEffectiveCatalog:!0},[r,i,a])}function Sn(e){let t=u();return mt({onSuccess:n=>{wt(t,{path:{assistant_id:e}},n),t.invalidateQueries({queryKey:pt({path:{assistant_id:e}})})}})}function Cn(e){let t=Sn(e);async function n(n,r,i){try{await t.mutateAsync({path:{assistant_id:e},body:{llm:n}})}catch(e){throw a(e,{context:r}),B.error(i),e}}return{makeActive:e=>n({activeProfile:e},`settings-ai-profile-make-active`,`Failed to set the active profile. Please try again.`),makeAdvisor:e=>n({advisorProfile:e},`settings-ai-profile-make-advisor`,`Failed to set the advisor profile. Please try again.`),clearAdvisor:()=>n({advisorProfile:null},`settings-ai-profile-clear-advisor`,`Failed to clear the advisor profile. Please try again.`),setStatus:(e,t)=>n({profiles:{[e]:{status:t?`active`:`disabled`}}},`settings-ai-profile-toggle`,`Failed to update the profile. Please try again.`),deleteProfile:(e,t,r)=>n({profiles:{[e]:null},profileOrder:t.filter(t=>t!==e),...r?.isAdvisor?{advisorProfile:null}:{}},`settings-ai-profile-delete`,`Failed to delete the profile. Please try again.`),patchLlm:n,isPending:t.isPending}}function wn(e,t,n){let r=Cn(e),i=t?.llm?.activeProfile??null,a=t?.llm?.advisorProfile??null,o=t?.llm?.callSites??{},s=(0,Q.useMemo)(()=>t?.llm?.profiles??{},[t?.llm?.profiles]),c=(0,Q.useMemo)(()=>t?.llm?.profileOrder??[],[t?.llm?.profileOrder]),l=(0,Q.useMemo)(()=>me(s,c),[s,c]),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(!1);async function v(e){try{await r.deleteProfile(e,c,{isAdvisor:e===a}),n?.onDeleted?.(e)}catch{}}function y(e){if(t==null)return;let n=s[e]?.label??e,r=e===i,a=Object.entries(o).filter(([t,n])=>t!==`mainAgent`&&n?.profile===e).map(([e])=>e);if(r||a.length>0){d({name:e,label:n,isActive:r,callSiteIds:a}),h(``),p(null);return}v(e)}async function b(){if(!u||!m)return;_(!0),p(null);let e={};if(u.isActive&&(e.activeProfile=m),u.callSiteIds.length>0){let t={};for(let e of u.callSiteIds)t[e]={profile:m};e.callSites=t}if(Object.keys(e).length>0)try{await r.patchLlm(e,`settings-ai-profile-reassign-delete`,`Failed to reassign references. Please try again.`)}catch{p(`Failed to reassign references. Please try again.`),_(!1);return}let t=u.name;d(null),_(!1),v(t)}let x=l.filter(e=>e.name!==u?.name&&e.source!==`managed`);return{requestDelete:y,blockedDeleteModalProps:{blocked:u,availableReplacements:x.length>0?x:l.filter(e=>e.name!==u?.name),replacement:m,onReplacementChange:h,error:f,saving:g,onClose:()=>{d(null),p(null)},onConfirm:()=>void b()}}}function Tn({assistantId:e,config:t,connections:n,selectedProfileName:r,onOpenProfile:i,onCreateProfile:a,onProfileDeleted:o}){let{entries:c}=xn(e,t),l=Cn(e),u=wn(e,t,{onDeleted:o}),d=t?.llm?.activeProfile??null,f=t?.llm?.advisorProfile??null;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(gn,{title:`Profiles`,action:(0,$.jsx)(s,{variant:`primary`,size:`compact`,onClick:a,leftIcon:(0,$.jsx)(k,{}),disabled:t==null,children:`Create Profile`}),children:t==null?(0,$.jsx)(h,{variant:`body-medium-lighter`,as:`p`,className:`py-4 text-center text-(--content-tertiary)`,children:`Loading profiles…`}):c.length===0?(0,$.jsx)(h,{variant:`body-medium-lighter`,as:`p`,className:`py-4 text-center text-(--content-tertiary)`,children:`No profiles yet. Create one to get started.`}):c.map(e=>(0,$.jsx)(vn,{profile:e,isActiveProfile:e.name===d,isAdvisorProfile:e.name===f,selected:e.name===r,connections:n,onOpen:()=>i(e.name),onMakeActive:()=>void l.makeActive(e.name),onMakeAdvisor:()=>void l.makeAdvisor(e.name),onClearAdvisor:()=>void l.clearAdvisor(),onSetStatus:t=>void l.setStatus(e.name,t),onDelete:()=>u.requestDelete(e.name)},e.name))}),(0,$.jsx)(_n,{...u.blockedDeleteModalProps})]})}var En={anthropic:!0,openai:!0,gemini:!0,fireworks:!0,openrouter:!0,vellum:!0};function Dn(e){return e in En}function On(e){let t=e.baseUrl??``;try{e.baseUrl&&(t=new URL(e.baseUrl).host)}catch{}let n=[];t&&n.push(t);let r=e.models?.length??0;return r>0&&n.push(`${r} ${r===1?`model`:`models`}`),e.auth.type===`none`&&n.push(`keyless`),n.join(` · `)}function kn(e){switch(e.auth.type){case`api_key`:return`Own API key`;case`oauth_subscription`:return`ChatGPT subscription`;case`none`:return`No API key needed`;default:return null}}function An(e){if(e.provider===`vellum`)return`Included with your plan`;if(e.provider===`openai-compatible`)return On(e);let t=[],n=e.models?.length??Se(e.provider).length;n>0&&t.push(`${n} ${n===1?`model`:`models`}`);let r=kn(e);return r&&t.push(r),t.join(` • `)}function jn({connection:e,isDefault:t,supportsDefaultProvider:n,selected:r,isSettingDefault:i,onOpen:a,onSetDefault:o,onDelete:c}){let l=e.isManaged??!1,u=J(e),d=Dn(e.provider),f=An(e),p=n&&!t&&d,m=!l&&a!=null,h=!l&&!t,g=p||m||h;return(0,$.jsx)(S,{title:u,subtitle:f.length>0?f:void 0,onClick:a,showChevron:!1,selected:r,contentAriaLabel:a?`Open provider ${u}`:void 0,trailingInteractive:!0,trailing:(0,$.jsxs)($.Fragment,{children:[l?(0,$.jsx)(F,{tone:`neutral`,title:`Runs on Vellum's managed credentials.`,children:`Managed`}):null,t?(0,$.jsx)(F,{tone:`info`,title:`Built-in profiles (Balanced, Quality, Speed) use this provider.`,children:`Default`}):null,e.provider===`ollama`?(0,$.jsx)(F,{tone:`neutral`,title:`Runs models on this machine.`,children:`Local`}):null,e.provider===`openai-compatible`?(0,$.jsx)(F,{tone:`neutral`,title:`A provider you created, served by an OpenAI-compatible endpoint.`,children:`Custom`}):null,g?(0,$.jsxs)(b.Root,{children:[(0,$.jsx)(b.Trigger,{asChild:!0,children:(0,$.jsx)(s,{variant:`ghost`,size:`compact`,iconOnly:(0,$.jsx)(C,{}),"aria-label":`Actions for ${u}`})}),(0,$.jsxs)(b.Content,{align:`end`,sideOffset:4,children:[m?(0,$.jsx)(b.Item,{onSelect:a,children:`Edit`}):null,p?(0,$.jsx)(b.Item,{disabled:i,onSelect:o,children:`Set as default`}):null,h?(0,$.jsx)(b.Item,{onSelect:c,className:`text-[var(--system-negative-strong)] data-[highlighted]:text-[var(--system-negative-strong)]`,children:`Delete`}):null]})]}):(0,$.jsx)(`span`,{className:`inline-block w-8`,"aria-hidden":!0})]})})}function Mn(e,t){let n=u(),r={path:{assistant_id:e}},i=f({...St(),onSuccess:()=>{n.invalidateQueries({queryKey:Ct(r)}),n.invalidateQueries({queryKey:xt(r)}),n.invalidateQueries({queryKey:pt(r)})},onError:e=>{a(e,{context:`settings-ai-set-default-provider`}),B.error(`Failed to set the default provider. Please try again.`)}});function o(t){Dn(t.provider)&&i.mutate({path:{assistant_id:e},body:{provider:t.provider,connectionName:t.name}})}function s(e){return i.isPending&&i.variables?.body?.connectionName===e}async function c(i){try{let{response:a}=await at({path:{assistant_id:e,name:i}});a?.ok||a?.status===404?(n.invalidateQueries({queryKey:vt(r)}),t?.onDeleted?.(i)):a?.status===409?B.error(`This provider is in use by a profile or as the default provider. Update those settings before deleting it.`):B.error(`Failed to delete the provider. Please try again.`)}catch(e){a(e,{context:`settings-ai-provider-delete`}),B.error(`Failed to delete the provider. Please try again.`)}}return{setDefault:o,isSettingDefault:s,deleteConnection:c}}var Nn=`0.10.8`;function Pn(){return et(Nn)}function Fn({assistantId:e,selectedConnectionName:t,onOpenConnection:n,onAddProvider:r,onConnectionDeleted:i}){let{data:a,isLoading:o,isError:c}=d(gt({path:{assistant_id:e}})),l=Pn(),{data:u}=d({...bt({path:{assistant_id:e}}),enabled:l}),f=l?u?.resolvedConnectionName??null:null,p=Mn(e,{onDeleted:i}),m=(0,Q.useMemo)(()=>{let e=a?.connections??[];return[...e.filter(e=>e.provider===be),...e.filter(e=>e.provider!==be)]},[a]);return(0,$.jsx)(gn,{title:`Providers`,action:(0,$.jsx)(s,{variant:`outlined`,size:`compact`,onClick:r,leftIcon:(0,$.jsx)(k,{}),children:`Add Provider`}),children:o?(0,$.jsx)(`div`,{className:`space-y-2 py-2`,children:[1,2,3].map(e=>(0,$.jsx)(`div`,{className:`h-10 animate-pulse rounded-lg bg-[var(--surface-active)]`},e))}):c?(0,$.jsx)(h,{variant:`body-medium-default`,as:`p`,className:`py-4 text-center text-(--system-negative-strong)`,children:`Failed to load providers. Please try again.`}):m.length===0?(0,$.jsx)(h,{variant:`body-medium-lighter`,as:`p`,className:`py-4 text-center text-(--content-tertiary)`,children:`No providers yet. Add one to get started.`}):m.map(e=>(0,$.jsx)(jn,{connection:e,isDefault:e.name===f,supportsDefaultProvider:l,selected:e.name===t,isSettingDefault:p.isSettingDefault(e.name),onOpen:e.isManaged??!1?void 0:()=>n(e.name),onSetDefault:()=>p.setDefault(e),onDelete:()=>void p.deleteConnection(e.name)},e.name))})}function In({panel:e,onOpenPanel:t,onClosePanel:n}){let r=Z(),{data:i}=d({...X({path:{assistant_id:r}}),staleTime:3e4}),a=Pn(),{data:o}=d({...bt({path:{assistant_id:r}}),enabled:a}),c=o?.availability,{data:l}=d({...gt({path:{assistant_id:r}})}),u=l?.connections,f=i?.llm?.callSites??{},p=Object.entries(f).filter(([e,t])=>e!==`mainAgent`&&(t?.profile!=null||t?.provider!=null||t?.model!=null)).length;return(0,$.jsx)(en,{title:`Language Model`,subtitle:`Profiles choose which model answers. Providers supply access to it`,children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[c&&c.status!==`ok`&&(0,$.jsx)(N,{tone:c.status===`unknown`?`warning`:`error`,children:c.message??`Your default provider is not available.`}),r&&(0,$.jsx)(Tn,{assistantId:r,config:i,connections:u,selectedProfileName:e?.kind===`profile`?e.name:null,onOpenProfile:e=>t({kind:`profile`,name:e}),onCreateProfile:()=>t({kind:`create-profile`}),onProfileDeleted:t=>{e?.kind===`profile`&&e.name===t&&n()}}),r&&(0,$.jsx)(Fn,{assistantId:r,selectedConnectionName:e?.kind===`provider`?e.name:null,onOpenConnection:e=>t({kind:`provider`,name:e}),onAddProvider:()=>t({kind:`add-provider`}),onConnectionDeleted:t=>{e?.kind===`provider`&&e.name===t&&n()}}),(0,$.jsx)(gn,{title:`Overrides`,count:p,action:(0,$.jsx)(s,{variant:`outlined`,size:`compact`,onClick:()=>t({kind:`overrides`}),children:`Manage`})})]})})}function Ln(e,{onSaved:t}={}){let n=Sn(e),{data:r}=d({...X({path:{assistant_id:e}}),staleTime:3e4}),i=(0,Q.useMemo)(()=>r?.llm?.profiles??{},[r?.llm?.profiles]),o=r?.llm?.profileOrder??[];async function s(r,s,c){let l=c?.mode??`replace`,u=!(r in i);if(l===`merge`&&!u){await n.mutateAsync({path:{assistant_id:e},body:{llm:{profiles:{[r]:s}}}}),t?.();return}let d={profiles:{[r]:s}};if(u&&(d.profileOrder=o.includes(r)?o:[...o,r]),u)await n.mutateAsync({path:{assistant_id:e},body:{llm:d}});else{let t=i[r];await n.mutateAsync({path:{assistant_id:e},body:{llm:{profiles:{[r]:null}}}});try{await n.mutateAsync({path:{assistant_id:e},body:{llm:d}})}catch(i){throw a(i,{context:`settings-ai-profile-edit-recreate`}),t!=null&&await n.mutateAsync({path:{assistant_id:e},body:{llm:{profiles:{[r]:t}}}}).catch(()=>{}),i}}u&&B.success(`Profile "${s.label??r}" created`),t?.()}return{saveProfile:s,isPending:n.isPending}}function Rn({assistantId:e,profileName:t,onClose:n}){let{data:r}=d({...X({path:{assistant_id:e}}),staleTime:3e4}),{data:i}=d({...gt({path:{assistant_id:e}})}),a=i?.connections,o=(0,Q.useMemo)(()=>r?.llm?.profiles??{},[r?.llm?.profiles]),c=Object.keys(o),l=(0,Q.useMemo)(()=>{if(t==null)return;let e=o[t];return e?{name:t,...e}:void 0},[t,o]),u=t==null?`create`:l?.source===`managed`||l?.invariant===!0?`view`:`edit`,{saveProfile:f,isPending:p}=Ln(e,{onSaved:n}),m=ke({mode:u,profileName:t??void 0,initialValues:l,existingNames:c,connections:a,assistantId:e,onSave:f}),h=wn(e,r,{onDeleted:()=>n()}),g=t!=null&&r!=null&&!(t in o);(0,Q.useEffect)(()=>{g&&!m.saving&&!p&&n()},[g,m.saving,p,n]);let _=u===`view`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Kt,{title:m.effectiveMode===`create`?`New Profile`:l?.label??t??`Profile`,closeVariant:`outlined`,onClose:n,headerTrailing:_&&m.effectiveMode!==`create`?(0,$.jsx)(F,{tone:`neutral`,children:`Managed by Vellum`}):null,headerActions:m.effectiveMode!==`create`&&!m.isReadOnly?(0,$.jsx)(s,{variant:`outlined`,size:`compact`,leftIcon:(0,$.jsx)(j,{}),tintColor:`var(--system-negative-strong)`,onClick:()=>{t!=null&&h.requestDelete(t)},disabled:m.saving,children:`Delete`}):null,footer:m.isReadOnly?(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(s,{variant:`outlined`,onClick:m.switchToSaveAsNew,disabled:m.saving,children:`Save As New`}),m.hasViewModeChanges?(0,$.jsx)(s,{variant:`primary`,onClick:()=>void m.handleSave(),disabled:m.saving,children:m.saving?`Saving…`:`Save`}):null]}):(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(s,{variant:`primary`,onClick:()=>void m.handleSave(),disabled:m.isInvalid||m.saving,children:m.saving?`Saving…`:m.effectiveMode===`create`?`Create Profile`:`Save Changes`})}),children:(0,$.jsx)(ie,{editor:m,assistantId:e,connections:a,variant:`panel`})}),(0,$.jsx)(_n,{...h.blockedDeleteModalProps})]})}var zn=`__custom__`;function Bn(e){return e?!!(e.profile||e.provider||e.model):!1}function Vn(e,t){let n=Bn(e);return n===Bn(t)?n?(e?.profile??null)===(t?.profile??null)&&(e?.provider??null)===(t?.provider??null)&&(e?.model??null)===(t?.model??null):!0:!1}function Hn({id:e,displayName:t,description:n,defaultProfileLabel:r,draft:i,profileOptions:a,onDraftChange:o,onToggle:s}){let c=Bn(i),l=!i||!c?``:i.provider||i.model?zn:i.profile??``,u=l===zn,d=ue(),f=d[0]??He[0],p=d.find(e=>e===i?.provider)??f,m=Se(p).map(e=>({value:e.id,label:e.displayName})),h=!!i?.provider&&!i?.model;function g(t){t===`__custom__`?o(e,{profile:null,provider:f,model:Ke(f)??``}):t===``?o(e,null):o(e,{profile:t,provider:null,model:null})}function _(t){let n=Ke(t)??``;o(e,{...i??{},profile:null,provider:t,model:n})}function v(t){o(e,{...i??{},model:t})}return(0,$.jsxs)(`div`,{className:`rounded-lg border border-[var(--border-base)] bg-[var(--surface-base)] p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-body-medium-default font-medium text-[var(--content-default)]`,children:t}),n&&(0,$.jsxs)(`p`,{className:`mt-0.5 text-body-small-default text-[var(--content-tertiary)]`,children:[n,r&&(0,$.jsxs)(`span`,{className:`ml-1.5 text-body-small-default text-[var(--content-tertiary)] opacity-60`,children:[`· Default: `,r]})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[c&&(0,$.jsx)(V,{value:l,onChange:g,options:a,className:`w-44`,menuMinWidth:280,menuAlign:`end`}),(0,$.jsx)(R,{checked:c,onChange:t=>s(e,t),"aria-label":`Override ${t}`})]})]}),c&&u&&(0,$.jsxs)(`div`,{className:`mt-3 space-y-2 border-t border-[var(--border-base)] pt-3`,children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`label`,{className:`mb-1 block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,$.jsx)(V,{value:p??``,onChange:_,options:d.map(e=>({value:e,label:je[e]??e}))})]}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`label`,{className:`mb-1 block text-body-small-default text-[var(--content-tertiary)]`,children:`Model`}),(0,$.jsx)(V,{value:i?.model??``,onChange:v,options:m})]})]}),h&&(0,$.jsx)(`p`,{className:`text-body-small-default text-[var(--system-negative-strong)]`,children:`Pick a model`})]})]})}function Un({assistantId:e,onClose:t}){let n=u(),{data:r}=d({...X({path:{assistant_id:e}}),staleTime:3e4}),i=(0,Q.useMemo)(()=>r?.llm?.profiles??{},[r?.llm?.profiles]),o=(0,Q.useMemo)(()=>r?.llm?.profileOrder??[],[r?.llm?.profileOrder]),c=(0,Q.useMemo)(()=>r?.llm?.callSites??{},[r?.llm?.callSites]),l=(0,Q.useMemo)(()=>me(i,o),[i,o]),f=ue(),p=mt({onSuccess:t=>{wt(n,{path:{assistant_id:e}},t)}}),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)({}),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),{data:w,isLoading:T,isError:E,refetch:O}=d({...yt({path:{assistant_id:e}}),enabled:!!e,staleTime:6e4,refetchOnWindowFocus:!1}),k=(0,Q.useMemo)(()=>(w?.callSites??[]).filter(e=>e.id!==`mainAgent`),[w]),j=!T&&!E&&!!w&&!!r,M=(0,Q.useMemo)(()=>k.map(e=>e.id),[k]),N=(0,Q.useMemo)(()=>{if(!j)return{};let e={};for(let t of M)if(t in v)e[t]=v[t];else{let n=c[t];e[t]=n?{...n}:{}}return e},[j,M,c,v]),P=(0,Q.useMemo)(()=>new Set(M),[M]),F=(0,Q.useMemo)(()=>Object.entries(c).some(([e,t])=>P.has(e)&&(t?.profile!=null||t?.provider!=null||t?.model!=null)),[c,P]),I=(0,Q.useMemo)(()=>{if(!j)return!1;for(let e of Object.keys(N))if(!Vn(N[e],c[e]))return!0;return!1},[j,N,c]),R=(0,Q.useMemo)(()=>Object.values(N).some(e=>Bn(e)&&!!e?.provider&&!e?.model),[N]),z=(0,Q.useMemo)(()=>De(l,[]).map(e=>({value:e.name,label:Ne(e)})),[l]),H=(0,Q.useCallback)(()=>{if(!g)return;let e={};for(let t of M)e[t]={profile:g};y(e)},[g,M]),U=(0,Q.useCallback)(e=>[...De(l,[e]).map(e=>({value:e.name,label:Ne(e)})),{value:zn,label:`Custom`}],[l]),W=(0,Q.useMemo)(()=>{if(!m.trim())return k;let e=m.toLowerCase();return k.filter(t=>(t.displayName??``).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)||(t.domain??``).toLowerCase().includes(e))},[k,m]),te=(0,Q.useMemo)(()=>{if(!w)return[];let e=w.domains.map(e=>e.id),t=new Map(w.domains.map(e=>[e.id,e])),n=[];for(let r of e){let e=W.filter(e=>e.domain===r);e.length>0&&n.push({domain:t.get(r),sites:e})}let r=new Set(e),i=W.filter(e=>!r.has(e.domain));return i.length>0&&n.push({domain:{id:`other`,displayName:`Other`},sites:i}),n},[w,W]),G=(0,Q.useCallback)((e,t)=>{y(n=>({...n,[e]:t}))},[]),K=(0,Q.useCallback)((e,t)=>{if(!t){y(t=>({...t,[e]:null}));return}let n=ze(l,k.find(t=>t.id===e)?.defaultProfile);if(n)y(t=>({...t,[e]:{profile:n}}));else{let t=f[0]??He[0],n=Ke(t)??``;y(r=>({...r,[e]:{provider:t,model:n}}))}},[k,l,f]),q=(0,Q.useCallback)(async()=>{x(!0);try{let n={};for(let e of Object.keys(N)){let t=N[e]??null;n[e]=Bn(t)?{profile:t?.profile??null,provider:t?.provider??null,model:t?.model??null}:null}await p.mutateAsync({path:{assistant_id:e},body:{llm:{callSites:n}}}),t(),B.success(`Overrides saved.`)}catch(e){B.error(`Failed to save overrides. Please try again.`),a(e,{context:`call_site_overrides_save`})}finally{x(!1)}},[N,t,p,e]),ne=(0,Q.useCallback)(async()=>{x(!0);try{let n={};for(let e of Object.keys(N))n[e]=null;await p.mutateAsync({path:{assistant_id:e},body:{llm:{callSites:n}}}),t(),B.success(`Overrides reset.`)}catch(e){B.error(`Failed to reset overrides. Please try again.`),a(e,{context:`call_site_overrides_reset`})}finally{x(!1)}},[N,t,p,e]);return(0,$.jsxs)(Kt,{title:`Action Overrides`,closeVariant:`outlined`,onClose:t,footer:(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[F&&(0,$.jsx)(s,{variant:`outlined`,size:`compact`,onClick:()=>C(!0),disabled:b||!j,tintColor:`var(--system-negative-strong)`,className:`mr-auto`,children:`Reset to Defaults`}),(0,$.jsx)(s,{variant:`primary`,size:`compact`,onClick:()=>void q(),disabled:!I||R||b,children:b?(0,$.jsx)(D,{className:`h-4 w-4 animate-spin`}):`Save`})]}),children:[(0,$.jsx)(`p`,{className:`mb-4 text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Customize which model profile specific actions should use. Uses your default profile if no override is set.`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`mb-4`,children:(0,$.jsx)(L,{type:`search`,value:m,onChange:e=>h(e.target.value),placeholder:`Search actions…`,leftIcon:(0,$.jsx)(A,{className:`h-4 w-4`}),fullWidth:!0})}),z.length>0&&(0,$.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 rounded-lg border border-[var(--border-base)] bg-[var(--surface-base)] p-3`,children:[(0,$.jsx)(`p`,{className:`min-w-0 flex-1 text-body-medium-default text-[var(--content-default)]`,children:`Use one profile for all actions`}),(0,$.jsx)(V,{value:g,onChange:_,options:z,placeholder:`Choose profile…`,className:`w-44`,menuMinWidth:280,menuAlign:`end`}),(0,$.jsx)(s,{variant:`outlined`,size:`compact`,onClick:H,disabled:!g||!j||b,children:`Apply to all`})]}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,$.jsx)(D,{className:`h-6 w-6 animate-spin text-[var(--content-tertiary)]`})}),E&&(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-12 text-center`,children:[(0,$.jsx)(`p`,{className:`text-body-medium-default text-[var(--content-default)]`,children:`Couldn't load actions`}),(0,$.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Make sure your assistant is running`}),(0,$.jsx)(s,{variant:`outlined`,size:`compact`,onClick:()=>void O(),children:`Retry`})]}),!T&&!E&&w&&(0,$.jsx)(`div`,{className:`space-y-4`,children:te.length===0?(0,$.jsx)(`p`,{className:`py-8 text-center text-body-medium-lighter text-[var(--content-tertiary)]`,children:`No actions match your search.`}):te.map(({domain:e,sites:t})=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-body-small-default font-semibold uppercase tracking-wider text-[var(--content-tertiary)]`,children:e.displayName}),(0,$.jsx)(`div`,{className:`space-y-1`,children:t.map(e=>{let t=(()=>{let t=N[e.id]??null;return!t||!Bn(t)?``:t.provider||t.model?`__custom__`:t.profile??``})(),n=e.defaultProfile?l.find(t=>t.name===e.defaultProfile)?.label??e.defaultProfile:null;return(0,$.jsx)(Hn,{id:e.id,displayName:e.displayName,description:e.description,defaultProfileLabel:n,draft:N[e.id]??null,profileOptions:U(t===``||t===`__custom__`?null:t),onDraftChange:G,onToggle:K},e.id)})})]},e.id))})]}),(0,$.jsx)(ee,{open:S,title:`Reset to Defaults`,message:`Every task override will be reset and will follow your active profile. This cannot be undone.`,confirmLabel:`Reset to Defaults`,destructive:!0,onConfirm:()=>{C(!1),ne()},onCancel:()=>C(!1)})]})}function Wn({mode:e,connection:t,assistantId:n,existingNames:r,connections:i,variant:a=`modal`,onSave:o,onCancel:c}){let[l,d]=(0,Q.useState)(t?.label??``),f=t?.name??``,p=t?.provider??`anthropic`,m=t?.auth.type??`api_key`,[g,_]=(0,Q.useState)(()=>t?.auth.type===`api_key`?t.auth.credential:t?``:`credential/anthropic/api_key`),[v,y]=(0,Q.useState)(t?.baseUrl??``),[b,x]=(0,Q.useState)(()=>t?.models?t.models.map(e=>e.id).join(`, `):``),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),E=p===`openai-compatible`,[D,O]=(0,Q.useState)(``),[k,A]=(0,Q.useState)(!1),j=u(),M=(0,Q.useMemo)(()=>G(g),[g]),N=m===`api_key`&&M!==null,{hasStoredCredential:P,isLoading:F}=K({assistantId:n,credentialKind:`credential`,credentialName:M?`${M.service}:${M.field}`:``,enabled:N}),{credentials:I}=te({assistantId:n,enabled:m===`api_key`});(0,Q.useEffect)(()=>{let e=t?.provider??`anthropic`;d(t?.label??``),t?.auth.type===`api_key`?_(t.auth.credential):_(t?``:`credential/${e}/api_key`),T(null),y(t?.baseUrl??``),x(t?.models?t.models.map(e=>e.id).join(`, `):``),O(``),A(!1)},[t]);let R=l.trim()!==(t?.label??``).trim(),B=E&&R?Ze(l,i,t?.name):null,ee=f.trim().length>0&&B===null;async function V(){if(ee){C(!0),T(null);try{let e;if(m===`api_key`){let t=g.trim()||`credential/${p}/api_key`,r=D.trim();if(r){A(!0);try{let e=G(t);await lt({path:{assistant_id:n},body:e?{type:`credential`,name:`${e.service}:${e.field}`,value:r}:{type:`api_key`,name:p,value:r},throwOnError:!0});let i=de(n,`credential`,e?`${e.service}:${e.field}`:``);j.setQueryData(i,!0),j.invalidateQueries({queryKey:Tt({path:{assistant_id:n}})})}catch{T(`Failed to save API key. Please try again.`);return}finally{A(!1)}}e={type:`api_key`,credential:t}}else if(t)e=t.auth;else{T(`Nothing to edit. Close and try again.`);return}let r=l.trim()||null,i={auth:e,label:r,...E&&{base_url:v.trim()||null,models:b.trim()?b.split(`,`).map(e=>({id:e.trim()})).filter(e=>e.id):null}},{data:a,error:s,response:c}=await rt({path:{assistant_id:n,name:t?.name??f.trim()},body:i});if(!c?.ok){T(Re(c?.status,s)??fe(c?.status));return}if(!a){T(`Server returned an empty response. Please try again.`);return}o(a)}catch{T(`Failed to save provider. Please try again.`)}finally{C(!1)}}}let H=I.filter(e=>e.service===p),W=e!==`create`&&t?.auth.type===`api_key`,ne=H.length>0||W,Y=q(`Enter your API key`,P);if(e===`create`)return(0,$.jsx)(ae,{variant:a===`panel`?`inline`:`modal`,assistantId:n,existingNames:r,connections:i,defaultProviderType:p,onCreated:o,onCancel:c});let ie=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:[`Display Name`,` `,(0,$.jsx)(`span`,{className:`text-[var(--content-disabled)]`,children:`(optional)`})]}),(0,$.jsx)(L,{value:l,onChange:e=>d(e.target.value),placeholder:`e.g. My Anthropic Key`,fullWidth:!0}),B?(0,$.jsx)(h,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:se[B]}):null]}),E&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Base URL`}),(0,$.jsx)(L,{value:v,onChange:e=>y(e.target.value),placeholder:`https://api.example.com/v1`,fullWidth:!0})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Models`}),(0,$.jsx)(L,{value:b,onChange:e=>x(e.target.value),placeholder:`model-1, model-2`,fullWidth:!0}),(0,$.jsx)(h,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Comma-separated model identifiers exposed by your endpoint.`})]})]}),m===`api_key`&&(0,$.jsx)(re,{apiKeyValue:D,onApiKeyChange:O,credential:g,onCredentialChange:_,isLoadingCredential:F,apiKeyPlaceholder:Y,provider:p,providerCredentials:H,showAdvancedSection:ne,onError:T}),m===`oauth_subscription`&&(0,$.jsx)(U,{assistantId:n,onConnected:o}),w&&(0,$.jsx)(h,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:w})]}),oe=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(s,{variant:`ghost`,size:`compact`,onClick:c,children:`Cancel`}),(0,$.jsx)(s,{variant:`primary`,size:`compact`,disabled:!ee||S||k,onClick:()=>void V(),children:S?`Saving…`:`Save Changes`})]});return a===`panel`?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[ie,(0,$.jsx)(`div`,{className:`flex justify-end gap-2`,children:oe})]}):(0,$.jsxs)(z.Content,{size:`md`,children:[(0,$.jsxs)(z.Header,{children:[(0,$.jsx)(z.Title,{children:`Edit Provider`}),(0,$.jsx)(z.Description,{children:t?`Editing ${J(t)}.`:`Edit provider settings.`})]}),(0,$.jsx)(z.Body,{children:ie}),(0,$.jsx)(z.Footer,{children:oe})]})}function Gn({assistantId:e,connectionName:t,onClose:n}){let r=u(),{data:i}=d(gt({path:{assistant_id:e}})),a=(0,Q.useMemo)(()=>i?.connections??[],[i]),o=(0,Q.useMemo)(()=>t==null?void 0:a.find(e=>e.name===t),[t,a]),s=t!=null&&i!=null&&o==null;(0,Q.useEffect)(()=>{s&&n()},[s,n]);function c(){r.invalidateQueries({queryKey:vt({path:{assistant_id:e}})}),r.invalidateQueries({queryKey:Ct({path:{assistant_id:e}})}),n()}return(0,$.jsx)(Kt,{title:o?J(o):`Add Provider`,closeVariant:`outlined`,onClose:n,children:t==null||o!=null?(0,$.jsx)(Wn,{mode:o?`edit`:`create`,connection:o,variant:`panel`,assistantId:e,existingNames:a.map(e=>e.name),connections:a,onSave:c,onCancel:n}):null})}var Kn={vellum:{provider:`vellum`},deepgram:{provider:`deepgram`,credentialService:`deepgram`},openai:{provider:`openai-whisper`,credentialService:`openai`}},qn={vellum:`vellum`,deepgram:`deepgram`,"openai-whisper":`openai`},Jn=`deepgram`;function Yn({assistantId:e,hideSaveButton:t=!1,hideCredentialsGuide:i=!1,onSaveStateChange:a}={}){let o=Z(),s=e??o,c=ft(),l=u(),[f]=(0,Q.useState)(()=>Ye.filter(e=>!e.requiresNativeDictation||le())),p=Jn,{data:m}=d({...X({path:{assistant_id:s}}),enabled:c,staleTime:3e4}),h=m?.services?.stt,g=h?.mode===`managed`?`vellum`:h?.provider,_=(0,Q.useMemo)(()=>{let e=g?qn[g]:void 0;if(e&&f.some(t=>t.id===e))return e;let t=r(Ge,p);return f.some(e=>e.id===t)?t:p},[g,f,p]),v=!!g,[y,b]=dn(_),[x,S]=(0,Q.useState)(``),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=r(Ge,p);e===`macos-native`&&!f.some(t=>t.id===e)&&n(Ge,p)},[f,p]);let D=(0,Q.useMemo)(()=>f.find(e=>e.id===y)??f[0],[f,y]),O=D.apiKeyPlaceholder!==void 0;(0,Q.useEffect)(()=>{w(r(Ae+y,``).length>0),S(``)},[y]);let k=(0,Q.useMemo)(()=>{let e=y!==_,t=x.trim().length>0;return e||t},[y,_,x]),A=(0,Q.useCallback)(async()=>{let e=x.trim();n(Ge,y),e.length>0&&n(Ae+y,e);let t=Kn[y];E(!0);try{if(t?.credentialService){let n=e.length>0?e:r(Ae+y,``);if(n.length>0){let{response:e}=await ot({path:{assistant_id:s},body:{service:t.credentialService,field:`api_key`,value:n,label:`${D.displayName} API Key`},throwOnError:!1});if(!e?.ok)throw Error(`Failed to store API key (HTTP ${e?.status??`?`})`)}}if(t&&(y!==_||!v)||g===`vellum`&&y!==`vellum`){let e=t?.provider??Jn,{response:n}=await st({path:{assistant_id:s},body:{services:{stt:{provider:e,mode:e===`vellum`?`managed`:`your-own`}}},throwOnError:!1});if(!n?.ok)throw Error(`Failed to save configuration (HTTP ${n?.status??`?`})`)}return e.length>0&&w(!0),S(``),l.invalidateQueries({queryKey:xt({path:{assistant_id:s}})}),B.success(`Speech-to-text settings saved`),!0}catch(e){return B.error(e instanceof Error?e.message:`Failed to save speech-to-text settings`),!1}finally{E(!1)}},[s,y,x,D,_,v,g,l]);(0,Q.useEffect)(()=>{a?.({hasChanges:k,saving:T,save:A})},[a,k,T,A]);let j=(0,Q.useCallback)(()=>{n(Ae+y,``),w(!1),S(``)},[y]),N=C?`•••••••• (Enter a new key to replace)`:D.apiKeyPlaceholder;return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,$.jsx)(V,{value:y,onChange:b,options:f.map(e=>({value:e.id,label:e.displayName})),"aria-label":`STT provider`})]}),O&&(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`API Key`}),(0,$.jsx)(L,{type:`password`,value:x,onChange:e=>S(e.target.value),placeholder:N,fullWidth:!0})]}),D.setupWarning&&(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-sunken)] p-3 text-body-small-default text-[var(--content-tertiary)]`,children:[(0,$.jsx)(M,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-[var(--system-mid-strong)]`}),(0,$.jsx)(`span`,{children:D.setupWarning})]}),!i&&D.credentialsGuide&&(0,$.jsx)(on,{guide:D.credentialsGuide}),y===`vellum`&&(0,$.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Transcription runs through your Vellum account.`}),(!t||C)&&(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[!t&&(0,$.jsx)(rn,{onClick:A,disabled:!k||T}),C&&(0,$.jsx)(an,{onClick:j})]})]})}function Xn(){return(0,$.jsx)(en,{title:`Speech-to-Text`,subtitle:`Configure how your assistant transcribes speech`,children:(0,$.jsx)(Yn,{})})}async function Zn(e){let{provider:t,apiKey:n,voiceId:r,text:i}=e;if(n.trim().length===0)return{kind:`error`,message:`Save an API key for this provider first.`};try{return t===`elevenlabs`?await Qn(n,r,i):t===`deepgram`?await $n(n,i):t===`fish-audio`?{kind:`unsupported`,message:`Fish Audio TTS is only supported in the desktop app today. Use ElevenLabs or Deepgram to test from the browser.`}:t===`xai`?{kind:`unsupported`,message:`xAI TTS is only supported in the desktop app today. Use ElevenLabs or Deepgram to test from the browser.`}:{kind:`unsupported`,message:`TTS testing for "${t}" is not supported from the browser yet.`}}catch(e){return{kind:`error`,message:e instanceof Error?e.message:`Failed to reach the TTS provider.`}}}async function Qn(e,t,n){let r=t.trim();if(r.length===0)return{kind:`error`,message:`Enter and save a Voice ID before testing ElevenLabs.`};let i=await fetch(`https://api.elevenlabs.io/v1/text-to-speech/${encodeURIComponent(r)}?output_format=mp3_44100_128`,{method:`POST`,headers:{"xi-api-key":e,"Content-Type":`application/json`,Accept:`audio/mpeg`},body:JSON.stringify({text:n,model_id:`eleven_turbo_v2_5`})});return i.ok?{kind:`audio`,blob:await i.blob()}:{kind:`error`,message:await er(i,`ElevenLabs rejected the request.`)}}async function $n(e,t){let n=await fetch(`https://api.deepgram.com/v1/speak?model=aura-2-thalia-en`,{method:`POST`,headers:{Authorization:`Token ${e}`,"Content-Type":`application/json`,Accept:`audio/mpeg`},body:JSON.stringify({text:t})});return n.ok?{kind:`audio`,blob:await n.blob()}:{kind:`error`,message:await er(n,`Deepgram rejected the request.`)}}async function er(e,t){try{let n=await e.text();if(n.length===0)return`${t} (HTTP ${e.status})`;try{let e=JSON.parse(n);if(e&&typeof e==`object`&&`detail`in e&&typeof e.detail==`string`)return e.detail;if(e&&typeof e==`object`&&`message`in e&&typeof e.message==`string`)return e.message}catch{}return n.slice(0,200)}catch{return`${t} (HTTP ${e.status})`}}function tr({assistantId:e,value:t,onChange:n,className:r}){let[i,a]=(0,Q.useState)(!1),{voices:o}=Vt(e);if(o.length===0)return null;let s=o.find(e=>e.model===t)??o[0];return(0,$.jsxs)(I.Root,{open:i,onOpenChange:a,children:[(0,$.jsx)(I.Trigger,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,"aria-label":`Voice`,className:m(`flex h-9 w-full items-center gap-2 rounded-md border border-[var(--field-border)] bg-[var(--field-bg)] px-3 text-left text-body-medium-lighter text-[var(--content-default)] transition-colors focus:outline-none data-[state=open]:border-[var(--border-active)]`,r),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:s?Ht(s.description):`Select a voice`}),(0,$.jsx)(_,{className:`h-3.5 w-3.5 shrink-0 text-[var(--content-tertiary)]`,"aria-hidden":!0})]})}),(0,$.jsx)(I.Content,{side:`bottom`,align:`start`,className:`w-[var(--radix-popover-trigger-width)] p-1`,children:(0,$.jsx)(Ut,{assistantId:e,value:t,onChange:n,onSelect:()=>a(!1),showSource:!0})})]})}var nr={elevenlabs:`voiceId`,"fish-audio":`referenceId`,xai:`voiceId`};function rr({assistantId:e,hideSaveButton:t=!1,hideCredentialsGuide:i=!1,onSaveStateChange:a}={}){let o=Z(),c=e??o,l=Qe.use.name()??`your assistant`,f=ft(),p=u(),{data:m}=d({...ht({path:{assistant_id:c}}),enabled:f,staleTime:1/0}),h=(0,Q.useMemo)(()=>{let e=m?.providers;if(!e)return ce;if(e.some(e=>e.id===`vellum`))return e;let t=ce.find(e=>e.id===`vellum`);return t?[t,...e]:e},[m]),{data:g}=d({...X({path:{assistant_id:c}}),enabled:f,staleTime:3e4}),_=g?.services?.tts,v=_?.mode===`managed`?`vellum`:_?.provider,y=`elevenlabs`,b=(0,Q.useMemo)(()=>v??r(`vellum:voice:ttsProvider`,y),[v,y]),x=!!v,[S,C]=dn(b),[w,T]=(0,Q.useState)(``),[D,O]=(0,Q.useState)(``),[k,A]=(0,Q.useState)(``),[j,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)(!1),{voices:R,defaultModel:z,fetched:ee}=Wt(c,{enabled:S===`vellum`}),H=_?.providers?.vellum?.model??z??``,[U,W]=dn(H),te=R.find(e=>e.model===U)??R[0],[G,K]=(0,Q.useState)(null),q=R.some(e=>e.model===H),ne=G??(ee&&H!==``&&!q),J=(0,Q.useMemo)(()=>h.find(e=>e.id===S)??h[0],[S,h]),re=S===`vellum`&&J.supportsVoiceSelection&&U.trim()!==``&&U.trim()!==H,Y=(0,Q.useCallback)(e=>{let t=r(xe+e,``),n=r(Le+e,``);M(t.length>0),O(n),A(n),T(``)},[]);(0,Q.useEffect)(()=>{Y(S)},[S,Y]);let ie=(0,Q.useMemo)(()=>{let e=S!==b,t=w.trim().length>0,n=D.trim()!==k;return e||t||n||re},[S,b,w,D,k,re]),ae=(0,Q.useCallback)(async()=>{let e=w.trim(),t=D.trim(),i=J.id;n(we,i),e.length>0&&n(xe+i,e),n(Le+i,t);let a=e.length>0?e:r(xe+i,``),o=nr[i];I(!0);try{if(a.length>0){let{response:e}=await ot({path:{assistant_id:c},body:{service:i,field:`api_key`,value:a,label:`${J.displayName} API Key`},throwOnError:!1});if(!e?.ok)throw Error(`Failed to store API key (HTTP ${e?.status??`?`})`)}let e={...S!==b||!x?{provider:i,mode:i===`vellum`?`managed`:`your-own`}:{},...o?{providers:{[i]:{[o]:t}}}:{},...re?{providers:{vellum:{model:U.trim()}}}:{}};if(Object.keys(e).length>0){let{response:t}=await st({path:{assistant_id:c},body:{services:{tts:e}},throwOnError:!1});if(!t?.ok)throw Error(`Failed to save configuration (HTTP ${t?.status??`?`})`)}return M(a.length>0),A(t),T(``),p.invalidateQueries({queryKey:xt({path:{assistant_id:c}})}),B.success(`Text-to-speech settings saved`),!0}catch(e){return B.error(e instanceof Error?e.message:`Failed to save text-to-speech settings`),!1}finally{I(!1)}},[c,S,U,re,w,D,J,b,x,p]);(0,Q.useEffect)(()=>{a?.({hasChanges:ie,saving:F,save:ae})},[a,ie,F,ae]);let oe=(0,Q.useCallback)(()=>{n(xe+S,``),M(!1),T(``)},[S]),se=(0,Q.useCallback)(async()=>{P(!0);try{let e=r(xe+S,``),t=w.trim(),n=t.length>0?t:e;if(n.length===0){B.error(`Save an API key for this provider before testing.`);return}let i=r(Le+S,``),a=D.trim(),o=await Zn({provider:S,apiKey:n,voiceId:a.length>0?a:i,text:`Hey! It's ${l}. How does this sound?`});if(o.kind!==`audio`){B.error(o.message);return}let s=URL.createObjectURL(o.blob);try{let e=new Audio(s);await e.play(),await new Promise(t=>{e.onended=()=>t(),e.onerror=()=>t()})}finally{URL.revokeObjectURL(s)}}finally{P(!1)}},[l,w,S,D]),le=j?`•••••••• (Enter a new key to replace)`:J.apiKeyPlaceholder,ue=S===`vellum`,de=ue&&J.supportsVoiceSelection,fe=(0,$.jsxs)(s,{variant:`link`,size:`compact`,className:`inline-flex h-auto items-center gap-1 px-0 underline [--vbtn-fg:var(--content-tertiary)]`,onClick:()=>{K(!1),R.some(e=>e.model===U)||W(z||R[0]?.model||``)},children:[(0,$.jsx)(E,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`Choose from catalog`]}),pe=de&&ne&&R.length>0?fe:null;return(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,$.jsx)(V,{value:S,onChange:C,options:h.map(e=>({value:e.id,label:e.displayName})),"aria-label":`TTS provider`})]}),!ue&&(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`API Key`}),(0,$.jsx)(L,{type:`password`,value:w,onChange:e=>T(e.target.value),placeholder:le,fullWidth:!0})]}),de&&(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Voice`}),ne?(0,$.jsx)(L,{type:`text`,value:U,onChange:e=>W(e.target.value),placeholder:`Enter a voice ID`,"aria-label":`Custom voice ID`,fullWidth:!0}):te?(0,$.jsx)(tr,{assistantId:c,value:U,onChange:W}):ee&&(0,$.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`No managed voices are currently available.`})]}),J.supportsVoiceSelection&&!ue&&(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Voice ID`}),(0,$.jsx)(L,{type:`text`,value:D,onChange:e=>O(e.target.value),placeholder:`Enter a voice ID`,fullWidth:!0})]}),!i&&!ue&&(0,$.jsx)(on,{guide:J.credentialsGuide}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!ue&&(0,$.jsx)(s,{variant:`outlined`,onClick:se,disabled:N,children:N?`Testing…`:`Test`}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-3`,children:[pe,!t&&(0,$.jsx)(rn,{onClick:ae,disabled:!ie||F}),j&&!ue&&(0,$.jsx)(an,{onClick:oe})]})]})]})}function ir(){return(0,$.jsx)(en,{id:`text-to-speech`,title:`Text-to-Speech`,subtitle:`Configure how your assistant speaks`,children:(0,$.jsx)(rr,{})})}var ar=`default`;function or(){let e=Z(),i=u(),{data:o}=d({...X({path:{assistant_id:e}}),staleTime:3e4}),s=mt({onSuccess:t=>{wt(i,{path:{assistant_id:e}},t)}}),c=un(),l=(0,Q.useMemo)(()=>o?o.services?.[`web-fetch`]?.provider||r(`vellum:ai:webFetchProvider`,ar):r(Me,ar),[o]),[f,p]=(0,Q.useState)(!1),[m,h]=dn(l),[g,_]=(0,Q.useState)(``),v=Be.has(m),{hasStoredCredential:y}=K({assistantId:e,credentialKind:`api_key`,credentialName:m,enabled:v}),b=g.trim().length>0,x=f||v&&!y&&!b||m===l&&!b,S=q(Ie[m]??`Enter your API key`,y),C=(0,Q.useCallback)(async()=>{p(!0);let t=g.trim(),r=v&&t.length>0;try{r&&await c(m,t),await s.mutateAsync({path:{assistant_id:e},body:{services:{"web-fetch":{provider:m}}}}).catch(e=>{throw B.error(`Failed to update assistant configuration. Please try again.`),a(e,{context:`patch_daemon_config`}),e})}catch{p(!1);return}p(!1);try{if(n(Me,m),r){let r=pe(m);r&&n(r,t);let a=de(e,`api_key`,m);i.setQueryData(a,!0),i.invalidateQueries({queryKey:a}),_(``)}B.success(`Web fetch settings saved.`)}catch(e){a(e,{context:`settings-ai-web-fetch-persist-local`}),B.error(`Saved, but local preferences could not be written.`)}},[v,s,c,i,e,g,m]),w=(0,Q.useCallback)(()=>{let e=pe(m);e&&t(e),_(``),h(ar),n(Me,ar)},[m,h]);return(0,$.jsx)(en,{id:`web-fetch`,title:`Web Fetch`,subtitle:`Configure how your assistant reads individual web pages`,children:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,$.jsx)(V,{value:m,onChange:h,options:ve.map(e=>({value:e,label:Oe[e]??e}))})]}),v&&(0,$.jsx)(L,{label:`API Key`,type:`password`,value:g,onChange:e=>_(e.target.value),placeholder:S,fullWidth:!0}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(rn,{onClick:C,disabled:x}),f&&(0,$.jsx)(D,{className:`h-4 w-4 animate-spin text-[var(--content-disabled)]`}),v&&(0,$.jsx)(an,{onClick:w,filled:!0})]})]})})}var sr=`0.10.12`;function cr(){return tt(sr)}function lr(){let e=Z(),i=u(),o=ft(),{data:s}=d({...X({path:{assistant_id:e}}),enabled:o,staleTime:3e4}),c=mt({onSuccess:t=>{wt(i,{path:{assistant_id:e}},t)}}),l=un(),f=(0,Q.useMemo)(()=>{if(!s)return r(Ee,`inference-provider-native`);let e=s.services?.[`web-search`];return(e?.mode===`managed`&&e?.provider!==`inference-provider-native`?`vellum`:e?.provider)||r(`vellum:ai:webSearchProvider`,`inference-provider-native`)},[s]),[p,m]=(0,Q.useState)(!1),[h,g]=dn(f),[_,v]=(0,Q.useState)(``),y=H.has(h),{hasStoredCredential:b}=K({assistantId:e,credentialKind:`api_key`,credentialName:h,enabled:y}),x=_.trim().length>0,S=p||y&&!b&&!x||h===f&&!x,C=q(Pe[h]??`Enter your API key`,b),w=(0,Q.useCallback)(async()=>{m(!0);let t=_.trim(),r=he(h),o=y&&t.length>0;try{o&&await l(h,t),await $e();let n=h===`vellum`?cr()?{provider:`vellum`,mode:`managed`}:{mode:`managed`}:{provider:h,mode:`your-own`};await c.mutateAsync({path:{assistant_id:e},body:{services:{"web-search":n}}}).catch(e=>{throw B.error(`Failed to update assistant configuration. Please try again.`),a(e,{context:`patch_daemon_config`}),e})}catch{m(!1);return}m(!1);try{if(n(Ee,h),o){r&&n(r,t);let a=de(e,`api_key`,h);i.setQueryData(a,!0),i.invalidateQueries({queryKey:a}),v(``)}B.success(`Web search settings saved.`)}catch(e){a(e,{context:`settings-ai-web-search-persist-local`}),B.error(`Saved, but local preferences could not be written.`)}},[y,c,l,i,e,_,h]),T=(0,Q.useCallback)(()=>{let e=he(h);e&&t(e),v(``),g(`inference-provider-native`),n(Ee,`inference-provider-native`)},[h,g]);return(0,$.jsx)(en,{title:`Web Search`,subtitle:`Configure how your assistant should search the web`,children:(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,$.jsx)(V,{"aria-label":`Web search provider`,value:h,onChange:g,options:We.map(e=>({value:e,label:Ce[e]??e}))})]}),h===`vellum`&&(0,$.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Search runs through your Vellum account.`}),y&&(0,$.jsx)(L,{label:`API Key`,type:`password`,value:_,onChange:e=>v(e.target.value),placeholder:C,fullWidth:!0}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(rn,{onClick:w,disabled:S}),p&&(0,$.jsx)(D,{className:`h-4 w-4 animate-spin text-[var(--content-disabled)]`}),y&&(0,$.jsx)(an,{onClick:T,filled:!0})]})]})})}function ur(){let e=Z(),t=Et(),[n,r]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=window.location.hash.slice(1);e&&requestAnimationFrame(()=>{document.getElementById(e)?.scrollIntoView({block:`start`})})},[]);let i=(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-5 overflow-y-auto`,children:[(0,$.jsx)(tn,{}),(0,$.jsx)(In,{panel:n,onOpenPanel:r,onClosePanel:()=>r(null)}),(0,$.jsx)(lr,{}),(0,$.jsx)(or,{}),(0,$.jsx)(ln,{}),(0,$.jsx)(hn,{}),(0,$.jsx)(ir,{}),(0,$.jsx)(Xn,{})]}),a=n?.kind===`profile`?`profile:${n.name}`:n?.kind===`provider`?`provider:${n.name}`:n?.kind??`closed`,o=n?.kind===`provider`||n?.kind===`add-provider`,s=n!=null&&e?n.kind===`overrides`?(0,$.jsx)(Un,{assistantId:e,onClose:()=>r(null)},a):o?(0,$.jsx)(Gn,{assistantId:e,connectionName:n.kind===`provider`?n.name:null,onClose:()=>r(null)},a):(0,$.jsx)(Rn,{assistantId:e,profileName:n.kind===`profile`?n.name:null,onClose:()=>r(null)},a):null;return s&&t?(0,$.jsx)(Jt,{children:s}):s?(0,$.jsx)(Yt,{storageKey:`aiSettingsDetailDrawerWidth`,detailKey:a,section:i,detail:s}):i}export{ur as AiPage};
@@ -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-BsGr-PCx.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-BYrmPIC4.js";import{o as C,r as w,t as T,u as E}from"./threshold-presets-BICi9Dqc.js";import{t as D}from"./message-square-zCNXaHYX.js";import{t as O}from"./search-DA3TmTuR.js";import{t as k}from"./notice-DCp7WO3L.js";import{N as A,P as j,a as M,i as N}from"./src-CXhyCUAb.js";import{t as P}from"./tag-D8NAGb0r.js";import{t as F}from"./input-C-GkeWCw.js";import{t as ee}from"./panel-item-ldBYDDDs.js";import{t as I}from"./confirm-dialog-DZX6LhLy.js";import{t as L}from"./dropdown-Dt0Iof85.js";import{n as te,t as ne}from"./create-selectors-B-P03-8K.js";import{t as re}from"./assistant-identity-store-BczULg2T.js";import{r as ie}from"./utils-CIvMYJQ9.js";import{d as ae}from"./routes-GmNvdtLW.js";import{n as oe}from"./conversation-navigation-DQ1vVewy.js";import{i as se,o as ce,r as R}from"./sdk.gen-BYZJ41ES.js";import{t as le}from"./assistant-feature-flag-store-BcO9bqIV.js";import{t as z}from"./public-asset-CD3ouSWU.js";import{t as ue}from"./use-active-assistant-id-DDp_V4pO.js";import{t as de}from"./slack-setup-wizard-CpORhyCf.js";import{t as fe}from"./index-CNAtypl-.js";import{c as pe,i as me,l as B,n as he,o as ge,r as _e,s as ve,t as ye}from"./use-invite-link-dialog-CjcR6UQy.js";import{t as be}from"./detail-card-C5IwAWc6.js";import{n as xe,t as Se}from"./mobile-sidebar-drawer-D7FGsgGT.js";import{t as V}from"./mutation-error-B6KUpkc8.js";var H=e(t(),1),U=ne(te()(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)(Ce,{channel:e,selected:e.key===t,onClick:()=>n(e.key)},e.key))})]})})}function Ce({channel:e,selected:t,onClick:n}){let r=e.status===`ready`,i=h(e.key),a=r?`Connected`:`Not connected`;return(0,G.jsx)(ee,{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)(P,{tone:r?`positive`:`neutral`,children:a})})]})})}function we({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 Te({assistantDisplayName:e,policy:t,saving:n=!1,loading:r=!1,error:i=!1,onChange:a}){let o=t??`trusted_contacts`,s=pe(e),c=ge.map(e=>({value:e,label:ve[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)(L,{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)(k,{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 Ee({address:e,pending:t,onDisconnect:r}){return(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(P,{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 De({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})]})}T.map(e=>e.riskThreshold);var Oe=[`none`,`low`];function q(e){if(e!==void 0)return e===`none`?`none`:`low`}var J={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)`}},Y=[`trusted_contact`,`unverified_contact`,`unknown`];function ke(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 X(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 Ae(e,t,n){let r;for(let i of e)X(i,t,n)&&(i.contactType===`trusted_contact`||r===void 0)&&(r=i.threshold);return r}var je=`__default__`;function Z({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 Me({tier:e,defaultTier:t,disabled:n,onTierChange:r,onReset:i,"aria-label":a}){let o=q(e??t??void 0),s=q(t??void 0)??null,c=Oe.map(e=>({value:e,label:J[e].label,icon:(0,G.jsx)(Z,{color:J[e].dotColor}),suffix:e===s?(0,G.jsx)(`span`,{className:`text-[color:var(--content-tertiary)]`,children:`default`}):void 0,tooltip:J[e].sublabel}));return s===null&&c.unshift({value:je,label:`Default`,icon:(0,G.jsx)(Z,{color:`transparent`}),tooltip:`follows the default level`}),(0,G.jsx)(L,{value:o??``,onChange:e=>{e===je||e===s?i():r(e)},options:c,placeholder:`Default`,disabled:n,size:`compact`,menuAlign:`end`,"aria-label":a})}function Q(e){return e.type===`dm`?`dm`:e.isPrivate?`private`:`public`}function Ne(e){return e.filter(e=>Q(e)!==`dm`)}function Pe(e,t,n){let r=t.trim().toLowerCase();return e.filter(e=>(n===null||Q(e)===n)&&(r===``||e.name.toLowerCase().includes(r))).sort((e,t)=>e.name.localeCompare(t.name))}function Fe(e){let t={public:0,private:0,dm:0};for(let n of e)t[Q(n)]+=1;return t}function Ie(e){return e.memberCount==null?null:e.memberCount===1?`1 member`:`${e.memberCount} members`}var Le=[{value:null,label:`All`},{value:`public`,label:`Public`},{value:`private`,label:`Private`}],Re={public:p,private:E},ze=100,Be=new Set;function Ve({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=Be,onTierChange:m,onTierReset:h}){let[g,_]=(0,H.useState)(``),[v,y]=(0,H.useState)(null),b=(0,H.useMemo)(()=>Ne(n??[]),[n]),x=(0,H.useMemo)(()=>Pe(b,g,v),[b,g,v]),S=(0,H.useMemo)(()=>Fe(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)(we,{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)(F,{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:Le.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>ze?(0,G.jsx)(`div`,{className:`h-96`,children:(0,G.jsx)(M,{items:x,computeItemKey:(e,t)=>t.id,itemContent:(e,t)=>(0,G.jsx)(He,{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)(He,{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 He({channel:e,pending:t,overridesLoading:n,overridesError:r,defaultTier:i,accessControls:a,tierOverride:o,onTierChange:s,onReset:c}){let l=Q(e);if(l===`dm`)return null;let u=Re[l],d=Ie(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)(Me,{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 Ue(e,t){return e===`none`?`${t} replies, but asks you before doing anything else, even a web search.`:`${t} can look things up and take notes on its own: web searches, public web pages, and reading and writing files in its own workspace.`}function We({assistantName:e,defaultTier:t}){let n=q(t??void 0)??null;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.jsx)(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.`}),(0,G.jsx)(`ul`,{className:`grid gap-x-6 gap-y-3 sm:grid-cols-2`,children:Oe.map(t=>{let r=J[t];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)(Z,{color:r.dotColor}),(0,G.jsx)(d,{as:`span`,variant:`body-small-emphasised`,children:r.label}),t===n?(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:Ue(t,e)})]},t)})}),(0,G.jsxs)(d,{as:`p`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:[`Whatever the level, nothing in this room lets `,e,` run code, change how it works, reach your computer or your connected accounts, or use skills you haven’t vetted. Those always come to you first. Your`,` `,(0,G.jsx)(i,{to:ae.settings.privacy,className:`text-[var(--content-link)] underline hover:text-[var(--content-link-hover)]`,children:`Trust Rules`}),` `,`fine-tune when it asks.`]})]})}var Ge=[{bucket:`channels`,icon:p,title:`Channels`,description:`Public and private channels`},{bucket:`dm`,icon:D,title:`Direct messages`,description:`One-on-one DMs`}];function Ke({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:Ge.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)(Me,{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)(We,{assistantName:e,defaultTier:t})})]})}var qe=`0.11.0`;function Je(){return ie(qe)}var Ye=new Set([404,501]);function Xe(e){let t=fe(e);return t!==void 0&&Ye.has(t)}function Ze(e,t,n){return Y.map(r=>({selector:{scope:`channel`,adapter:e,channelExternalId:t},contactType:r,threshold:n}))}function Qe(e,t,n){return e.selector.scope===`channel`&&e.selector.adapter===t&&e.selector.channelExternalId===n}function $e(e,t){return t===`channels`?{scope:`adapter`,adapter:e}:{scope:`channel_type`,adapter:e,channelType:`dm`}}function et(e,t,n){let r=$e(e,t);return Y.map(e=>({selector:r,contactType:e,threshold:n}))}function tt({assistantId:e,adapter:t}){let n=o(),r=Je()&&!!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?ke(d,t):void 0,[d,t]),p=(0,H.useMemo)(()=>d?{channels:Ae(d,t,`channels`),dm:Ae(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(Ze(t,e,n).map(e=>se({...i,body:e,throwOnError:!0})))},onMutate:({channelExternalId:e,tier:n})=>h(n=>Qe(n,t,e),Ze(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(Y.map(n=>R({...i,body:{selector:{scope:`channel`,adapter:t,channelExternalId:e},contactType:n},throwOnError:!0})))},onMutate:({channelExternalId:e})=>h(n=>Qe(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(et(t,e,n).map(e=>se({...i,body:e,throwOnError:!0})))},onMutate:({bucket:e,tier:n})=>h(n=>X(n,t,e),et(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=$e(t,e);await Promise.all(Y.map(e=>R({...i,body:{selector:n,contactType:e},throwOnError:!0})))},onMutate:({bucket:e})=>h(n=>X(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&&Xe(u.error)?{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 nt({assistantId:e,assistantDisplayName:t,slackHandle:n}){let r=s({...y(e),enabled:!!e,select:e=>e.channels}),i=tt({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)(Ve,{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:[i.isError?(0,G.jsx)(k,{tone:`error`,children:`Couldn’t load access settings. These controls stay disabled until they load. Try reopening this page.`}):null,(0,G.jsx)(Ke,{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)(N.Root,{type:`single`,collapsible:!0,children:(0,G.jsxs)(N.Item,{value:`per-channel-overrides`,children:[(0,G.jsxs)(N.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)(N.Content,{className:`border-[var(--border-base)] data-[state=open]:border-t`,children:c})]})})})]})}function rt({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)(P,{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 it({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)(j,{value:e??`mention_then_thread`,onValueChange:e=>n?.(e),disabled:t||!n,"aria-label":`Slack thread behavior`,children:[(0,G.jsx)(A,{value:`mention_only`,label:`Mentions only`,helperText:`Bot only responds when @mentioned.`}),(0,G.jsx)(A,{value:`mention_then_thread`,label:`Follow threads after first mention`,helperText:`After an @mention in a thread, bot listens to all subsequent replies.`})]})]})}function at({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)(F,{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 ot({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)(F,{label:`Account SID`,type:`text`,value:t,onChange:e=>r(e.target.value),placeholder:`ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`,disabled:o,fullWidth:!0}),(0,G.jsx)(F,{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 st({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)(rt,{slackHandle:e.address,disconnectPending:a,onDisconnect:c,children:(0,G.jsx)(it,{threadMode:p,threadModePending:m,onThreadModeChange:g})}):(0,G.jsx)(De,{children:(0,G.jsx)(de,{assistantName:r,onSave:u,saveStatus:d,saveError:f})}),w?(0,G.jsx)(nt,{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)(Ee,{address:e.address,pending:a,onDisconnect:c}),D.hasTrustFloorControl&&C?(0,G.jsx)(Te,{assistantDisplayName:i,policy:y,saving:b,loading:x,error:S,onChange:C}):null]}):T?e.key===`telegram`?(0,G.jsx)(at,{onSave:l}):(0,G.jsx)(ot,{onSave:_}):(0,G.jsx)(we,{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 $={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-BsGr-PCx.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-BYrmPIC4.js";import{o as C,r as w,t as T,u as E}from"./threshold-presets-BICi9Dqc.js";import{t as D}from"./message-square-zCNXaHYX.js";import{t as O}from"./search-DA3TmTuR.js";import{t as k}from"./notice-DCp7WO3L.js";import{N as A,P as j,a as M,i as N}from"./src-CXhyCUAb.js";import{t as P}from"./tag-D8NAGb0r.js";import{t as F}from"./input-C-GkeWCw.js";import{t as ee}from"./panel-item-ldBYDDDs.js";import{t as I}from"./confirm-dialog-DZX6LhLy.js";import{t as L}from"./dropdown-Dt0Iof85.js";import{n as te,t as ne}from"./create-selectors-B-P03-8K.js";import{t as re}from"./assistant-identity-store-BczULg2T.js";import{r as ie}from"./utils-CIvMYJQ9.js";import{d as ae}from"./routes-GmNvdtLW.js";import{n as oe}from"./conversation-navigation-DQ1vVewy.js";import{i as se,o as ce,r as R}from"./sdk.gen-BYZJ41ES.js";import{t as le}from"./assistant-feature-flag-store-BcO9bqIV.js";import{t as z}from"./public-asset-CD3ouSWU.js";import{t as ue}from"./use-active-assistant-id-DDp_V4pO.js";import{t as de}from"./slack-setup-wizard-CpORhyCf.js";import{t as fe}from"./index-B81A5OyO.js";import{c as pe,i as me,l as B,n as he,o as ge,r as _e,s as ve,t as ye}from"./use-invite-link-dialog-CjcR6UQy.js";import{t as be}from"./detail-card-C5IwAWc6.js";import{n as xe,t as Se}from"./mobile-sidebar-drawer-D7FGsgGT.js";import{t as V}from"./mutation-error-B6KUpkc8.js";var H=e(t(),1),U=ne(te()(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)(Ce,{channel:e,selected:e.key===t,onClick:()=>n(e.key)},e.key))})]})})}function Ce({channel:e,selected:t,onClick:n}){let r=e.status===`ready`,i=h(e.key),a=r?`Connected`:`Not connected`;return(0,G.jsx)(ee,{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)(P,{tone:r?`positive`:`neutral`,children:a})})]})})}function we({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 Te({assistantDisplayName:e,policy:t,saving:n=!1,loading:r=!1,error:i=!1,onChange:a}){let o=t??`trusted_contacts`,s=pe(e),c=ge.map(e=>({value:e,label:ve[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)(L,{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)(k,{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 Ee({address:e,pending:t,onDisconnect:r}){return(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(P,{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 De({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})]})}T.map(e=>e.riskThreshold);var Oe=[`none`,`low`];function q(e){if(e!==void 0)return e===`none`?`none`:`low`}var J={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)`}},Y=[`trusted_contact`,`unverified_contact`,`unknown`];function ke(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 X(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 Ae(e,t,n){let r;for(let i of e)X(i,t,n)&&(i.contactType===`trusted_contact`||r===void 0)&&(r=i.threshold);return r}var je=`__default__`;function Z({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 Me({tier:e,defaultTier:t,disabled:n,onTierChange:r,onReset:i,"aria-label":a}){let o=q(e??t??void 0),s=q(t??void 0)??null,c=Oe.map(e=>({value:e,label:J[e].label,icon:(0,G.jsx)(Z,{color:J[e].dotColor}),suffix:e===s?(0,G.jsx)(`span`,{className:`text-[color:var(--content-tertiary)]`,children:`default`}):void 0,tooltip:J[e].sublabel}));return s===null&&c.unshift({value:je,label:`Default`,icon:(0,G.jsx)(Z,{color:`transparent`}),tooltip:`follows the default level`}),(0,G.jsx)(L,{value:o??``,onChange:e=>{e===je||e===s?i():r(e)},options:c,placeholder:`Default`,disabled:n,size:`compact`,menuAlign:`end`,"aria-label":a})}function Q(e){return e.type===`dm`?`dm`:e.isPrivate?`private`:`public`}function Ne(e){return e.filter(e=>Q(e)!==`dm`)}function Pe(e,t,n){let r=t.trim().toLowerCase();return e.filter(e=>(n===null||Q(e)===n)&&(r===``||e.name.toLowerCase().includes(r))).sort((e,t)=>e.name.localeCompare(t.name))}function Fe(e){let t={public:0,private:0,dm:0};for(let n of e)t[Q(n)]+=1;return t}function Ie(e){return e.memberCount==null?null:e.memberCount===1?`1 member`:`${e.memberCount} members`}var Le=[{value:null,label:`All`},{value:`public`,label:`Public`},{value:`private`,label:`Private`}],Re={public:p,private:E},ze=100,Be=new Set;function Ve({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=Be,onTierChange:m,onTierReset:h}){let[g,_]=(0,H.useState)(``),[v,y]=(0,H.useState)(null),b=(0,H.useMemo)(()=>Ne(n??[]),[n]),x=(0,H.useMemo)(()=>Pe(b,g,v),[b,g,v]),S=(0,H.useMemo)(()=>Fe(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)(we,{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)(F,{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:Le.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>ze?(0,G.jsx)(`div`,{className:`h-96`,children:(0,G.jsx)(M,{items:x,computeItemKey:(e,t)=>t.id,itemContent:(e,t)=>(0,G.jsx)(He,{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)(He,{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 He({channel:e,pending:t,overridesLoading:n,overridesError:r,defaultTier:i,accessControls:a,tierOverride:o,onTierChange:s,onReset:c}){let l=Q(e);if(l===`dm`)return null;let u=Re[l],d=Ie(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)(Me,{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 Ue(e,t){return e===`none`?`${t} replies, but asks you before doing anything else, even a web search.`:`${t} can look things up and take notes on its own: web searches, public web pages, and reading and writing files in its own workspace.`}function We({assistantName:e,defaultTier:t}){let n=q(t??void 0)??null;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.jsx)(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.`}),(0,G.jsx)(`ul`,{className:`grid gap-x-6 gap-y-3 sm:grid-cols-2`,children:Oe.map(t=>{let r=J[t];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)(Z,{color:r.dotColor}),(0,G.jsx)(d,{as:`span`,variant:`body-small-emphasised`,children:r.label}),t===n?(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:Ue(t,e)})]},t)})}),(0,G.jsxs)(d,{as:`p`,variant:`body-small-default`,className:`text-[color:var(--content-tertiary)]`,children:[`Whatever the level, nothing in this room lets `,e,` run code, change how it works, reach your computer or your connected accounts, or use skills you haven’t vetted. Those always come to you first. Your`,` `,(0,G.jsx)(i,{to:ae.settings.privacy,className:`text-[var(--content-link)] underline hover:text-[var(--content-link-hover)]`,children:`Trust Rules`}),` `,`fine-tune when it asks.`]})]})}var Ge=[{bucket:`channels`,icon:p,title:`Channels`,description:`Public and private channels`},{bucket:`dm`,icon:D,title:`Direct messages`,description:`One-on-one DMs`}];function Ke({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:Ge.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)(Me,{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)(We,{assistantName:e,defaultTier:t})})]})}var qe=`0.11.0`;function Je(){return ie(qe)}var Ye=new Set([404,501]);function Xe(e){let t=fe(e);return t!==void 0&&Ye.has(t)}function Ze(e,t,n){return Y.map(r=>({selector:{scope:`channel`,adapter:e,channelExternalId:t},contactType:r,threshold:n}))}function Qe(e,t,n){return e.selector.scope===`channel`&&e.selector.adapter===t&&e.selector.channelExternalId===n}function $e(e,t){return t===`channels`?{scope:`adapter`,adapter:e}:{scope:`channel_type`,adapter:e,channelType:`dm`}}function et(e,t,n){let r=$e(e,t);return Y.map(e=>({selector:r,contactType:e,threshold:n}))}function tt({assistantId:e,adapter:t}){let n=o(),r=Je()&&!!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?ke(d,t):void 0,[d,t]),p=(0,H.useMemo)(()=>d?{channels:Ae(d,t,`channels`),dm:Ae(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(Ze(t,e,n).map(e=>se({...i,body:e,throwOnError:!0})))},onMutate:({channelExternalId:e,tier:n})=>h(n=>Qe(n,t,e),Ze(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(Y.map(n=>R({...i,body:{selector:{scope:`channel`,adapter:t,channelExternalId:e},contactType:n},throwOnError:!0})))},onMutate:({channelExternalId:e})=>h(n=>Qe(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(et(t,e,n).map(e=>se({...i,body:e,throwOnError:!0})))},onMutate:({bucket:e,tier:n})=>h(n=>X(n,t,e),et(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=$e(t,e);await Promise.all(Y.map(e=>R({...i,body:{selector:n,contactType:e},throwOnError:!0})))},onMutate:({bucket:e})=>h(n=>X(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&&Xe(u.error)?{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 nt({assistantId:e,assistantDisplayName:t,slackHandle:n}){let r=s({...y(e),enabled:!!e,select:e=>e.channels}),i=tt({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)(Ve,{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:[i.isError?(0,G.jsx)(k,{tone:`error`,children:`Couldn’t load access settings. These controls stay disabled until they load. Try reopening this page.`}):null,(0,G.jsx)(Ke,{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)(N.Root,{type:`single`,collapsible:!0,children:(0,G.jsxs)(N.Item,{value:`per-channel-overrides`,children:[(0,G.jsxs)(N.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)(N.Content,{className:`border-[var(--border-base)] data-[state=open]:border-t`,children:c})]})})})]})}function rt({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)(P,{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 it({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)(j,{value:e??`mention_then_thread`,onValueChange:e=>n?.(e),disabled:t||!n,"aria-label":`Slack thread behavior`,children:[(0,G.jsx)(A,{value:`mention_only`,label:`Mentions only`,helperText:`Bot only responds when @mentioned.`}),(0,G.jsx)(A,{value:`mention_then_thread`,label:`Follow threads after first mention`,helperText:`After an @mention in a thread, bot listens to all subsequent replies.`})]})]})}function at({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)(F,{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 ot({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)(F,{label:`Account SID`,type:`text`,value:t,onChange:e=>r(e.target.value),placeholder:`ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`,disabled:o,fullWidth:!0}),(0,G.jsx)(F,{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 st({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)(rt,{slackHandle:e.address,disconnectPending:a,onDisconnect:c,children:(0,G.jsx)(it,{threadMode:p,threadModePending:m,onThreadModeChange:g})}):(0,G.jsx)(De,{children:(0,G.jsx)(de,{assistantName:r,onSave:u,saveStatus:d,saveError:f})}),w?(0,G.jsx)(nt,{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)(Ee,{address:e.address,pending:a,onDisconnect:c}),D.hasTrustFloorControl&&C?(0,G.jsx)(Te,{assistantDisplayName:i,policy:y,saving:b,loading:x,error:S,onChange:C}):null]}):T?e.key===`telegram`?(0,G.jsx)(at,{onSave:l}):(0,G.jsx)(ot,{onSave:_}):(0,G.jsx)(we,{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 $={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