@vellumai/web 0.10.3-staging.1 → 0.10.3-staging.2

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.
Files changed (74) hide show
  1. package/dist/assets/{account-page-BB5Phl5s.js → account-page-CCYCSy2-.js} +1 -1
  2. package/dist/assets/{advanced-page-CMAf1fno.js → advanced-page-CVnT0zH-.js} +1 -1
  3. package/dist/assets/{ai-page-DcOYf6ki.js → ai-page-kEbHR7cH.js} +1 -1
  4. package/dist/assets/{api-key-screen-A7FySG-O.js → api-key-screen-DGVn66y4.js} +1 -1
  5. package/dist/assets/{archive-page-m3yQFOvD.js → archive-page-Dl6HLIJt.js} +1 -1
  6. package/dist/assets/{billing-page-C-JoA25u.js → billing-page-Cq_yLwUC.js} +1 -1
  7. package/dist/assets/{bookmarks-page-Cl2O0te-.js → bookmarks-page-CANlE7hP.js} +1 -1
  8. package/dist/assets/{command-palette-AdQxXi8M.js → command-palette-GZu_zgQg.js} +1 -1
  9. package/dist/assets/{command-palette-window-page-9TqGuzVu.js → command-palette-window-page-CzWu42Ee.js} +1 -1
  10. package/dist/assets/{community-page-DPCIsZX3.js → community-page-Dhgypa-h.js} +1 -1
  11. package/dist/assets/{contacts-page-route-BvCp-gAp.js → contacts-page-route-C3QiOxjO.js} +1 -1
  12. package/dist/assets/{debug-page-CTD3JrfL.js → debug-page-CBozmAQQ.js} +1 -1
  13. package/dist/assets/{deploy-dialogs-C0aZYWkv.js → deploy-dialogs-jf5VL1UP.js} +1 -1
  14. package/dist/assets/{developer-page-Dx6SbGPL.js → developer-page-iEL4eJ8x.js} +1 -1
  15. package/dist/assets/{devices-page-DtqksGFR.js → devices-page-RMaPGcXe.js} +1 -1
  16. package/dist/assets/{dictation-overlay-page-B9zcq9IK.js → dictation-overlay-page-BxQCzLMY.js} +1 -1
  17. package/dist/assets/{document-viewer-page-oeRhq2Yx.js → document-viewer-page-57OuXxYw.js} +1 -1
  18. package/dist/assets/{earn-credits-modal-3vmD9Fug.js → earn-credits-modal-Nm1VymMp.js} +1 -1
  19. package/dist/assets/{emails-page-C_RKF4jL.js → emails-page-0gRZqa6y.js} +1 -1
  20. package/dist/assets/{file-editor-wIYQnMM_.js → file-editor-BNkJJbUv.js} +1 -1
  21. package/dist/assets/{general-page-Bjr3EfG_.js → general-page-aZxTpnpI.js} +1 -1
  22. package/dist/assets/{hatching-screen-OMSxOyvX.js → hatching-screen-KPinlCES.js} +1 -1
  23. package/dist/assets/{home-page-route-BDyODWxN.js → home-page-route-CudtBGg1.js} +1 -1
  24. package/dist/assets/{hosting-screen-dwUA84uS.js → hosting-screen-C14KAJ6m.js} +1 -1
  25. package/dist/assets/{identity-page-route-Ds4SXg6o.js → identity-page-route-C0BFcTAF.js} +1 -1
  26. package/dist/assets/{index-BIDC22lX.js → index-PRnvH2Y1.js} +7 -7
  27. package/dist/assets/{inspect-page-CpIdOQCU.js → inspect-page-CWasyuSO.js} +1 -1
  28. package/dist/assets/{install-b0ONV1om.js → install-C3xe8ARr.js} +1 -1
  29. package/dist/assets/{integrations-page-Dw3rJqPE.js → integrations-page-WhBpTYP2.js} +1 -1
  30. package/dist/assets/{intelligence-layout-DovsSaK4.js → intelligence-layout-CvTumtjv.js} +1 -1
  31. package/dist/assets/{keyboard-shortcuts-page-B2rDCmXw.js → keyboard-shortcuts-page-kiOEZKzE.js} +1 -1
  32. package/dist/assets/{library-detail-page-BfwLhTzc.js → library-detail-page-rPvN9G1a.js} +1 -1
  33. package/dist/assets/{library-page-CKwzimBZ.js → library-page-BHejhapZ.js} +1 -1
  34. package/dist/assets/{login-page-aWGeNMsB.js → login-page-BGLVK82t.js} +1 -1
  35. package/dist/assets/{logout-page-BgczaAe_.js → logout-page-Bl6AD21S.js} +1 -1
  36. package/dist/assets/{logs-layout-Bb4h3S2N.js → logs-layout-C9eUE1Pt.js} +1 -1
  37. package/dist/assets/{memory-router-playground-page-gcwT23uj.js → memory-router-playground-page-Dhi3uqxr.js} +1 -1
  38. package/dist/assets/{mobile-sidebar-drawer-wA5GnkLS.js → mobile-sidebar-drawer-DqXFL0Ke.js} +1 -1
  39. package/dist/assets/{notifications-page-BilxDebz.js → notifications-page-pHiDPA0p.js} +1 -1
  40. package/dist/assets/{oauth-complete-page-CzAcy6Qj.js → oauth-complete-page-DiGMWbOb.js} +1 -1
  41. package/dist/assets/{oauth-popup-complete-page-CvE_74ec.js → oauth-popup-complete-page-CwoZnzdc.js} +1 -1
  42. package/dist/assets/{pairing-page-ddUW7kSm.js → pairing-page-clFaUgzL.js} +1 -1
  43. package/dist/assets/{plugin-detail-page-B-d90SJ8.js → plugin-detail-page-IRPeI4lP.js} +1 -1
  44. package/dist/assets/{plugins-page-tUsEY9_b.js → plugins-page-BaYp2QOe.js} +1 -1
  45. package/dist/assets/{prechat-route-in5c2S6S.js → prechat-route-BaMWiiaf.js} +1 -1
  46. package/dist/assets/{privacy-page-CpYx1RMr.js → privacy-page-BUhxrIRn.js} +1 -1
  47. package/dist/assets/{privacy-screen-Cd4yErpJ.js → privacy-screen-BaHYtKEt.js} +1 -1
  48. package/dist/assets/{provider-callback-page-BCXiAoax.js → provider-callback-page-CxFC4PH1.js} +1 -1
  49. package/dist/assets/{research-mock-page-DfC4Xf4z.js → research-mock-page-ttrrPwo3.js} +1 -1
  50. package/dist/assets/{research-onboarding-route-QentSADF.js → research-onboarding-route-Cxai0fux.js} +1 -1
  51. package/dist/assets/{review-terms-screen-kUBWOFsV.js → review-terms-screen-DEiifDmK.js} +1 -1
  52. package/dist/assets/{select-assistant-screen-DDdKrCaI.js → select-assistant-screen-UoixBMN2.js} +1 -1
  53. package/dist/assets/{settings-layout-CIAca9J9.js → settings-layout-CQ3Z9Raj.js} +1 -1
  54. package/dist/assets/{share-feedback-modal-sqz1cvkl.js → share-feedback-modal-CTwByE7B.js} +1 -1
  55. package/dist/assets/{sidebar-tree-BNLVikyu.js → sidebar-tree-BJkXpCut.js} +1 -1
  56. package/dist/assets/{signup-page-DOYf5rnz.js → signup-page-CKDYl9Wb.js} +1 -1
  57. package/dist/assets/{skills-page-pXRiOYxp.js → skills-page-DVjqqfMw.js} +1 -1
  58. package/dist/assets/{sounds-page-DZjipsnL.js → sounds-page-mens6EAJ.js} +1 -1
  59. package/dist/assets/{step-indicator-dots-D1EQV6VE.js → step-indicator-dots-CEVbsP8r.js} +1 -1
  60. package/dist/assets/{subagent-detail-panel-BhMGv4KW.js → subagent-detail-panel-DVQAkMjF.js} +1 -1
  61. package/dist/assets/{system-events-page-8chSE8WO.js → system-events-page-Dro8iNrx.js} +1 -1
  62. package/dist/assets/{tiptap-document-editor-BIYDH0gu.js → tiptap-document-editor-D2t4qYzv.js} +1 -1
  63. package/dist/assets/{tool-detail-panel-CltEAL4k.js → tool-detail-panel-DRD2DIMF.js} +1 -1
  64. package/dist/assets/{trace-page-Ceqkb39z.js → trace-page-DRWPaAuQ.js} +1 -1
  65. package/dist/assets/{upgrade-cancel-page-BLYBOQhL.js → upgrade-cancel-page-Cwv5eMh9.js} +1 -1
  66. package/dist/assets/{upgrade-success-page-Besx7BnU.js → upgrade-success-page-DnJ8Kyyj.js} +1 -1
  67. package/dist/assets/{usage-page-UvJrF1jZ.js → usage-page-DJHRS0lZ.js} +1 -1
  68. package/dist/assets/{voice-page-B6ocZCAN.js → voice-page-kQZ2ya5j.js} +1 -1
  69. package/dist/assets/{weather-forecast-display-JXZ2NoLx.js → weather-forecast-display-Cu3W6OZF.js} +1 -1
  70. package/dist/assets/{welcome-screen-4_W-iOJc.js → welcome-screen-Bd7PCfAf.js} +1 -1
  71. package/dist/assets/{workflow-detail-panel-BYvRNK8S.js → workflow-detail-panel-CMmPPsuL.js} +1 -1
  72. package/dist/assets/{workspace-page-D6Ak7heg.js → workspace-page-BR4pOxs5.js} +1 -1
  73. package/dist/index.html +1 -1
  74. package/package.json +1 -1
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{r as t,s as n}from"./local-settings-lVNyIOJ_.js";import{t as r}from"./capture-error-Hr1Yo2kx.js";import{t as i}from"./react-DJZBPgpf.js";import{t as a}from"./button-D7s2Q_uG.js";import{d as o,h as s}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{N as c,O as l,S as u,T as d,c as f,n as p}from"./QueryClientProvider-DKhXIxGb.js";import{a as m,c as h,d as g,i as _,l as v,o as y,r as b,s as x,t as S,u as C}from"./useQuery-B45lW1Kk.js";import{t as w}from"./jsx-runtime-CVSDxk6A.js";import{t as T}from"./card-BibIM9x3.js";import{n as E,t as D}from"./panel-item-nGTDevWP.js";import{t as O}from"./confirm-dialog-CfOXCE1N.js";import{t as k}from"./notice-CqRgVmeL.js";import{t as A}from"./popover-CL-JL6vG.js";import{t as j}from"./input-C8kfrq9r.js";import{t as M}from"./toggle-X_kQW5my.js";import{n as N,t as P}from"./list-row-Cw9JYESP.js";import{t as F}from"./modal-D0Q3UWD0.js";import{n as I}from"./toast-2TW5tj1Y.js";import{t as L}from"./createLucideIcon-BlMXrA59.js";import{t as ee}from"./check-D6WkI0gF.js";import{t as R}from"./chevron-right-B6vEpVY0.js";import{t as z}from"./circle-alert-DvNg50UK.js";import{t as B}from"./circle-check-DzlJxj_M.js";import{t as V}from"./external-link-DPAtkBJ2.js";import{t as H}from"./loader-circle-IIzBGiwm.js";import{t as U}from"./log-in-2iOsufxq.js";import{t as W}from"./pencil-DbB9rxpY.js";import{t as te}from"./refresh-cw-Bf6LV0kG.js";import{t as ne}from"./sparkles-BICoewVE.js";import{t as re}from"./x-KVxA2ZL0.js";import{hr as G}from"./sdk.gen-1aYqVbMj.js";import{Bt as ie,J as ae,K as oe,Rt as se,Vt as ce,X as le,Y as ue,Z as de,q as fe,zt as pe}from"./react-query.gen-CQLyoqYk.js";import{r as me}from"./api-errors-CveHbhgb.js";import{L as he,M as ge}from"./auth-store-Kfxhs2oI.js";import{r as _e}from"./api-2kc3MHRz.js";import{a as ve}from"./routes-DVqkwUEe.js";import{n as ye}from"./use-is-mobile-Cy10kl9u.js";import{t as be}from"./assistant-feature-flag-store-Dl92XRsM.js";import{S as xe,b as K,vt as Se,x as Ce,yt as we}from"./react-query.gen-rp6Krcco.js";import{n as Te,t as Ee}from"./browser-CKX_K5ev.js";import{$i as q,Ct as De,Dt as Oe,Et as ke,Ht as Ae,Ir as J,Jr as je,Li as Me,Ot as Ne,St as Pe,Y,an as Fe,bt as Ie,ei as Le,mi as Re,qi as ze,rn as Be,ti as X,wt as Ve,x as He,xi as Ue,xt as We}from"./index-BIDC22lX.js";import{t as Ge}from"./use-active-assistant-id-C-RHQ9f6.js";function Ke(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}function qe(e,t,n){let r=e.slice(0);return r[t]=n,r}var Je=class extends c{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=[];constructor(e,t,n){super(),this.#e=e,this.#r=n,this.#n=[],this.#i=[],this.#t=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#i.forEach(e=>{e.subscribe(t=>{this.#p(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#i.forEach(e=>{e.destroy()})}setQueries(e,t){this.#n=e,this.#r=t,f.batch(()=>{let e=this.#i,t=this.#f(this.#n);t.forEach(e=>e.observer.setOptions(e.defaultedQueryOptions));let n=t.map(e=>e.observer),r=n.map(e=>e.getCurrentResult()),i=e.length!==n.length,a=n.some((t,n)=>t!==e[n]),o=i||a,s=o?!0:r.some((e,t)=>{let n=this.#t[t];return!n||!l(e,n)});!o&&!s||(o&&(this.#l=t,this.#i=n),this.#t=r,this.hasListeners()&&(o&&(Ke(e,n).forEach(e=>{e.destroy()}),Ke(n,e).forEach(e=>{e.subscribe(t=>{this.#p(e,t)})})),this.#m()))})}getCurrentResult(){return this.#t}getQueries(){return this.#i.map(e=>e.getCurrentQuery())}getObservers(){return this.#i}getOptimisticResult(e,t){let n=this.#f(e),r=n.map(e=>e.observer.getOptimisticResult(e.defaultedQueryOptions)),i=n.map(e=>e.defaultedQueryOptions.queryHash);return[r,e=>this.#d(e??r,t,i),()=>this.#u(r,n)]}#u(e,t){return t.map((n,r)=>{let i=e[r];return n.defaultedQueryOptions.notifyOnChangeProps?i:n.observer.trackResult(i,e=>{t.forEach(t=>{t.observer.trackProp(e)})})})}#d(e,t,n){if(t){let r=this.#c,i=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((e,t)=>e!==r[t]));return(!this.#a||this.#t!==this.#s||i||t!==this.#o)&&(this.#o=t,this.#s=this.#t,n!==void 0&&(this.#c=n),this.#a=d(this.#a,t(e))),this.#a}return e}#f(e){let t=new Map;this.#i.forEach(e=>{let n=e.options.queryHash;if(!n)return;let r=t.get(n);r?r.push(e):t.set(n,[e])});let n=[];return e.forEach(e=>{let r=this.#e.defaultQueryOptions(e),i=t.get(r.queryHash)?.shift()??new g(this.#e,r);n.push({defaultedQueryOptions:r,observer:i})}),n}#p(e,t){let n=this.#i.indexOf(e);n!==-1&&(this.#t=qe(this.#t,n,t),this.#m())}#m(){if(this.hasListeners()){let e=this.#a,t=this.#u(this.#t,this.#l);e!==this.#d(t,this.#r?.combine)&&f.batch(()=>{this.listeners.forEach(e=>{e(this.#t)})})}}},Z=e(i(),1);function Ye({queries:e,...t},n){let r=p(n),i=C(),a=v(),o=Z.useMemo(()=>e.map(e=>{let t=r.defaultQueryOptions(e);return t._optimisticResults=i?`isRestoring`:`optimistic`,t}),[e,r,i]);o.forEach(e=>{b(e),y(e,a,r.getQueryCache().get(e.queryHash))}),h(a);let[s]=Z.useState(()=>new Je(r,o,t)),[c,l,d]=s.getOptimisticResult(o,t.combine),S=!i&&t.subscribed!==!1;Z.useSyncExternalStore(Z.useCallback(e=>S?s.subscribe(f.batchCalls(e)):u,[s,S]),()=>s.getCurrentResult(),()=>s.getCurrentResult()),Z.useEffect(()=>{s.setQueries(o,t)},[o,t,s]);let w=c.some((e,t)=>m(o[t],e))?c.flatMap((e,t)=>{let n=o[t];return n&&m(n,e)?_(n,new g(r,n),a):[]}):[];if(w.length>0)throw Promise.all(w);let T=c.find((e,t)=>{let n=o[t];return n&&x({result:e,errorResetBoundary:a,throwOnError:n.throwOnError,query:r.getQueryCache().get(n.queryHash),suspense:n.suspense})});if(T?.error)throw T.error;return l(d())}var Xe=L(`cable`,[[`path`,{d:`M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z`,key:`trhst0`}],[`path`,{d:`M17 21v-2`,key:`ds4u3f`}],[`path`,{d:`M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10`,key:`1mo9zo`}],[`path`,{d:`M21 21v-2`,key:`eo0ou`}],[`path`,{d:`M3 5V3`,key:`1k5hjh`}],[`path`,{d:`M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z`,key:`1dd30t`}],[`path`,{d:`M7 5V3`,key:`1t1388`}]]),Ze=L(`calendar-plus`,[[`path`,{d:`M16 19h6`,key:`xwg31i`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M19 16v6`,key:`tddt3s`}],[`path`,{d:`M21 12.598V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8.5`,key:`1glfrc`}],[`path`,{d:`M3 10h18`,key:`8toen8`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}]]);function Qe({assistantId:e,providerKey:t,displayName:n,managedAvailable:r,connectionsQueryKey:i,allConnections:a}){let o=p(),s=ge(),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),[f,m]=(0,Z.useState)(!1),h=()=>{l.current=null,m(!1)},g=()=>{c.current&&!c.current.closed&&c.current.close(),c.current=null,u.current&&=(clearInterval(u.current),null),d.current&&=(clearTimeout(d.current),null)},_=(0,Z.useCallback)(e=>{if(e.type!==`vellum:oauth-complete`||!l.current||e.requestId!==l.current.requestId)return;let{oauthStatus:t,oauthCode:r}=e;if(g(),h(),t===`connected`)I.success(`${n} account connected.`),o.invalidateQueries({queryKey:i});else{let e=r?`Error: ${r}`:`Authorization failed`;I.error(`${n} ${e}`)}},[i,n,o]),v=(0,Z.useCallback)(async(e,n)=>{if(!r)return!1;for(let r=0;r<8;r+=1){r>0&&await Pe(750);try{if(o.invalidateQueries({queryKey:i}),We(await o.fetchQuery({...K({path:{assistant_id:e}}),staleTime:0}),t,n))return!0}catch{}}return!1},[i,r,t,o]);(0,Z.useEffect)(()=>{let e=e=>{let t=l.current;if(!t)return;let n=De(e,window.location.origin,t.requestId);n&&_(n)},t=e=>{let t=l.current;if(!t)return;let n=Ve(e,t.requestId);n&&(_(n),window.localStorage.removeItem(ke(t.requestId)))};return window.addEventListener(`message`,e),window.addEventListener(`storage`,t),()=>{window.removeEventListener(`message`,e),window.removeEventListener(`storage`,t)}},[_]),Ne((0,Z.useCallback)(e=>{let t=l.current;t&&e.requestId===t.requestId&&_({type:`vellum:oauth-complete`,requestId:e.requestId,oauthStatus:e.oauthStatus,oauthProvider:e.oauthProvider,oauthCode:e.oauthCode})},[_])),(0,Z.useEffect)(()=>Te(()=>{let e=l.current;e&&(async()=>{let t=await v(e.platformAssistantId,e.baselineConnectionSignatures);l.current&&(h(),t&&I.success(`${n} account connected.`))})()}),[v,n]),(0,Z.useEffect)(()=>()=>{u.current&&clearInterval(u.current),d.current&&clearTimeout(d.current),c.current&&!c.current.closed&&c.current.close()},[]);let y=we();return{handleConnect:(i=[])=>{if(!r)return;let f=crypto.randomUUID();m(!0);let p=async r=>{let c;try{c=await he(e)}catch(e){g(),h(),I.error(e instanceof Error?e.message:`Failed to start ${n} authorization.`);return}let u=Ie(await o.fetchQuery({...K({path:{assistant_id:c}}),staleTime:0}).catch(()=>c===e?a??[]:[]),t);l.current={requestId:f,provider:t,platformAssistantId:c,baselineConnectionSignatures:u},y.mutate({path:{assistant_id:c,provider:t},body:{requested_scopes:i,redirect_after_connect:`${ve.account.oauth.popupComplete}?requestId=${f}${s?`&native=1`:``}`}},{onSuccess(e){if(s){Ee(e.connect_url);return}r&&!r.closed?r.location.href=e.connect_url:l.current&&(g(),h(),I.error(`${n} connection failed: popup closed.`))},onError(e){g(),h();let t=me(e,void 0,`Failed to start ${n} authorization.`);I.error(t)}})};if(s){p(null);return}let b=window.open(``,`_blank`,`width=500,height=600`);if(b===null){h(),I.error(`Popup blocked. Please enable popups and try again.`);return}c.current=b,u.current=setInterval(()=>{c.current&&c.current.closed&&l.current&&!d.current&&(d.current=setTimeout(async()=>{d.current=null;let e=l.current;if(!e)return;let t=window.localStorage.getItem(ke(e.requestId));if(t){let n=Oe(t);if(n&&n.requestId===e.requestId){_(n),window.localStorage.removeItem(ke(e.requestId));return}}let r=await v(e.platformAssistantId,e.baselineConnectionSignatures);if(l.current){if(r){g(),h(),I.success(`${n} account connected.`);return}g(),h(),I.error(`${n} connection failed: authorization popup closed.`)}},1e3))},100),p(b)},oauthInProgress:f,startOAuthPending:y.isPending}}var Q=w();function $e({displayName:e,providerKey:t,logoUrl:n,connections:r,connectionsLoading:i,startPending:o,oauthInProgress:s,disconnectingId:c,onConnect:l,onDisconnect:u,connectPresets:d=[]}){let f=o||s;return i?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,Q.jsx)(H,{className:`h-5 w-5 animate-spin text-[var(--content-disabled)]`})}):r.length===0?o||s?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-10`,children:[(0,Q.jsx)(Y,{providerKey:t,displayName:e,logoUrl:n,size:48}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,Q.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}),`Waiting for authorization...`]})]}):(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-10`,children:[(0,Q.jsx)(Y,{providerKey:t,displayName:e,logoUrl:n,size:48}),(0,Q.jsx)(`p`,{className:`text-body-medium-default text-[var(--content-secondary)]`,children:`Connect Account to continue`}),(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,Q.jsx)(a,{variant:`primary`,size:`compact`,leftIcon:(0,Q.jsx)(X,{}),onClick:()=>l(),disabled:f,children:`Connect Account`}),d.map(e=>(0,Q.jsx)(a,{variant:`outlined`,size:`compact`,leftIcon:(0,Q.jsx)(Ze,{}),onClick:()=>l(e.scopes),disabled:f,children:e.label},e.id))]})]}):(0,Q.jsxs)(`div`,{className:`rounded-lg border border-[var(--border-base)]`,children:[(0,Q.jsx)(`ul`,{className:`divide-y divide-[var(--border-base)]`,children:r.map(r=>{let i=c===r.id;return(0,Q.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,Q.jsx)(Y,{providerKey:t,displayName:e,logoUrl:n,size:20}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-body-medium-default text-[var(--content-default)]`,children:r.account_label??`${e} Account`}),(0,Q.jsx)(a,{variant:`dangerOutline`,size:`compact`,iconOnly:i?(0,Q.jsx)(H,{className:`animate-spin`}):(0,Q.jsx)(J,{}),onClick:()=>u(r),disabled:i,"aria-label":`Disconnect ${r.account_label??`${e} account`}`})]},r.id)})}),(0,Q.jsx)(`div`,{className:`border-t border-[var(--border-base)] px-4 py-3 dark:border-[var(--border-base)]`,children:f?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,Q.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}),`Waiting for authorization...`]}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(a,{variant:`primary`,size:`compact`,leftIcon:(0,Q.jsx)(V,{}),onClick:()=>l(),disabled:f,children:`Connect account`}),d.map(e=>(0,Q.jsx)(a,{variant:`outlined`,size:`compact`,leftIcon:(0,Q.jsx)(Ze,{}),onClick:()=>l(e.scopes),disabled:f,children:e.label},e.id))]})})]})}function et(e){return e.length>16?`${e.slice(0,12)}…${e.slice(-4)}`:e.length>8?`${e.slice(0,8)}…`:e}function tt(e){try{return new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}catch{return``}}function nt({assistantId:e,providerKey:t,displayName:n,logoUrl:r}){let i=p(),o=S({...ae({path:{assistant_id:e},query:{provider_key:t}}),select:e=>e.apps}),s=S({...le({path:{assistant_id:e,providerKey:t}}),select:e=>e.oauth_callback_url}),c=o.data??[],l=s.data??null,u=Ye({queries:c.map(t=>({...oe({path:{assistant_id:e,appId:t.id}}),select:e=>e.connections}))}),d={};c.forEach((e,t)=>{d[e.id]=u[t]?.data??[]});let f=ue({path:{assistant_id:e},query:{provider_key:t}}),m=ie({onSuccess:()=>{i.invalidateQueries({queryKey:f}),x(``),w(``),y(!1),I.success(`${n} OAuth app added.`)},onError:e=>{I.error(e.message||`Failed to create OAuth app`)}}),h=pe({onSuccess:()=>{i.invalidateQueries({queryKey:f}),I.success(`OAuth app deleted.`)},onError:e=>{I.error(e.message||`Failed to delete OAuth app`)}}),g=se({onSuccess:e=>{`auth_url`in e&&(window.location.href=e.auth_url)},onError:e=>{I.error(e.message||`Failed to start OAuth flow`)}}),_=ce(),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(``),[C,w]=(0,Z.useState)(``),[E,D]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(null),[M,N]=(0,Z.useState)(null),P=m.isPending,F=h.isPending?h.variables?.path?.id??null:null,L=g.isPending?g.variables?.path?.appId??null:null,R=_.isPending?_.variables?.path?.id??null:null,z=()=>{let n=b.trim(),r=C.trim();!n||!r||m.mutate({path:{assistant_id:e},body:{provider_key:t,client_id:n,client_secret:r}})},B=()=>{let t=k;A(null),t&&h.mutate({path:{assistant_id:e,id:t.id}})},U=t=>{g.mutate({path:{assistant_id:e,appId:t.id},body:{callback_transport:`gateway`,scopes:[]}})};return o.isLoading?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,Q.jsx)(H,{className:`h-5 w-5 animate-spin text-[var(--content-disabled)]`})}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[c.length===0||v?(0,Q.jsx)(T.Root,{children:(0,Q.jsxs)(T.Body,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-body-medium-default text-[var(--content-default)]`,children:c.length===0?`Add your own ${n} OAuth app`:`Add another ${n} OAuth app`}),(0,Q.jsx)(`p`,{className:`text-body-small-default leading-relaxed text-[var(--content-tertiary)]`,children:`Credentials are stored encrypted on the assistant and are never sent to Vellum.`})]}),l?(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-body-small-default text-[var(--content-secondary)]`,children:`Redirect URL`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(j,{type:`text`,value:l,readOnly:!0,fullWidth:!0}),(0,Q.jsx)(a,{type:`button`,variant:`outlined`,size:`compact`,onClick:()=>{navigator.clipboard.writeText(l).then(()=>{D(!0),I.success(`Copied to clipboard!`),setTimeout(()=>D(!1),2e3)})},"aria-label":E?`Copied`:`Copy redirect URL`,iconOnly:E?(0,Q.jsx)(ee,{"aria-hidden":!0}):(0,Q.jsx)(Me,{"aria-hidden":!0})})]}),(0,Q.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`Add this URL to your OAuth app's redirect settings.`})]}):null,(0,Q.jsx)(j,{label:`Client ID`,type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:`Enter your client ID`,fullWidth:!0}),(0,Q.jsx)(j,{label:`Client Secret`,type:`password`,value:C,onChange:e=>w(e.target.value),placeholder:`Enter your client secret`,fullWidth:!0}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c.length>0?(0,Q.jsx)(a,{type:`button`,variant:`outlined`,size:`compact`,onClick:()=>{y(!1),x(``),w(``)},disabled:P,children:`Cancel`}):null,(0,Q.jsx)(a,{type:`button`,size:`compact`,onClick:z,disabled:P||!b.trim()||!C.trim(),leftIcon:P?(0,Q.jsx)(H,{className:`animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(X,{"aria-hidden":!0}),children:`Add App`})]})]})}):null,c.map(e=>{let i=d[e.id]??[],o=F===e.id,s=L===e.id;return(0,Q.jsx)(T.Root,{children:(0,Q.jsxs)(T.Body,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,Q.jsx)(`p`,{className:`truncate text-body-medium-default text-[var(--content-default)]`,children:et(e.client_id)}),(0,Q.jsxs)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:[`Added `,tt(e.created_at)]})]}),(0,Q.jsx)(a,{type:`button`,variant:`dangerOutline`,size:`compact`,onClick:()=>A(e),disabled:o,"aria-label":`Delete OAuth app ${et(e.client_id)}`,iconOnly:o?(0,Q.jsx)(H,{className:`animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(J,{"aria-hidden":!0})})]}),i.length>0?(0,Q.jsx)(`ul`,{className:`divide-y divide-[var(--border-base)] overflow-hidden rounded-md border border-[var(--border-base)] dark:divide-[var(--border-base)] dark:border-[var(--border-base)]`,children:i.map(i=>{let o=R===i.id;return(0,Q.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,Q.jsx)(Y,{providerKey:t,displayName:n,logoUrl:r,size:18}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-body-medium-lighter text-[var(--content-default)]`,children:i.account_info??`${n} Account`}),(0,Q.jsx)(a,{type:`button`,variant:`dangerOutline`,size:`compact`,onClick:()=>N({appId:e.id,connection:i}),disabled:o,"aria-label":`Disconnect ${i.account_info??`${n} account`}`,iconOnly:o?(0,Q.jsx)(H,{className:`animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(J,{"aria-hidden":!0})})]},i.id)})}):null,(0,Q.jsx)(a,{type:`button`,size:`compact`,onClick:()=>U(e),disabled:s,className:`w-full`,leftIcon:s?(0,Q.jsx)(H,{className:`animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(V,{"aria-hidden":!0}),children:s?`Waiting for authorization...`:`Connect account`})]})},e.id)}),c.length>0&&!v?(0,Q.jsx)(a,{type:`button`,variant:`outlined`,size:`compact`,onClick:()=>y(!0),className:`w-full border-dashed`,leftIcon:(0,Q.jsx)(X,{"aria-hidden":!0}),children:`Add Another App`}):null,(0,Q.jsx)(O,{open:k!==null,title:`Delete OAuth app`,message:k?`Delete OAuth app '${et(k.client_id)}'? This will disconnect all linked accounts.`:``,confirmLabel:`Delete`,destructive:!0,onConfirm:B,onCancel:()=>A(null)}),(0,Q.jsx)(O,{open:M!==null,title:`Disconnect ${n}?`,message:M?`Disconnect ${M.connection.account_info??`${n} Account`}? You can reconnect later.`:``,confirmLabel:`Disconnect`,destructive:!0,onConfirm:()=>{let t=M;N(null),t&&_.mutate({path:{assistant_id:e,id:t.connection.id}},{onSuccess:()=>{let r=fe({path:{assistant_id:e,appId:t.appId}});i.invalidateQueries({queryKey:r}),i.invalidateQueries({queryKey:f}),I.success(`${n} account disconnected.`)},onError:e=>{I.error(e.message||`Failed to disconnect account`)}})},onCancel:()=>N(null)})]})}var rt={};function it(e){return rt[e]??[]}function at({assistantId:e,platformAssistantId:t,providerKey:n,displayName:r,description:i,logoUrl:o,platformGate:s,onClose:c}){let l=p(),u=s===`full`,d=!Be(),[f,m]=(0,Z.useState)(s===`gated`&&d?`your-own`:`managed`);(0,Z.useEffect)(()=>{!d&&f===`your-own`&&m(`managed`)},[d,f]);let[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),y=Ce({path:{assistant_id:t}}),{data:b,isLoading:x}=S({...K({path:{assistant_id:t}}),enabled:u}),C=(b??[]).filter(e=>e.provider===n&&e.connected),{handleConnect:w,oauthInProgress:T,startOAuthPending:E}=Qe({assistantId:e,providerKey:n,displayName:r,managedAvailable:u,connectionsQueryKey:y,allConnections:b}),D={path:{assistant_id:t}},k=Se({onSuccess(e,t){I.success(`${r} account disconnected.`);let n=t.path.connection_id;xe(l,D,e=>e?.filter(e=>e.id!==n)),l.invalidateQueries({queryKey:y}),g(null)},onError(e){let t=me(e,void 0,`Failed to disconnect ${r} account.`);I.error(t),g(null)}});(0,Z.useEffect)(()=>{let e=e=>{e.key===`Escape`&&c()};document.addEventListener(`keydown`,e);let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=t}},[c]);let A=e=>{v(e)},j=()=>{let e=_;v(null),e&&(g(e.id),k.mutate({path:{assistant_id:t,connection_id:e.id}}))},M=i?`Configure ${r} OAuth for ${i}`:`Configure ${r} OAuth`;return(0,Q.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:[(0,Q.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`integration-modal-title`,className:`flex w-full max-w-[520px] flex-col overflow-hidden rounded-xl bg-white shadow-xl dark:bg-[var(--surface-lift)]`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-[var(--border-base)] px-5 py-4 dark:border-[var(--border-base)]`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(Y,{providerKey:n,displayName:r,logoUrl:o,size:32}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`h2`,{id:`integration-modal-title`,className:`text-title-small text-[var(--content-default)]`,children:[r,` OAuth`]}),(0,Q.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:M})]})]}),(0,Q.jsx)(a,{variant:`ghost`,size:`compact`,iconOnly:(0,Q.jsx)(re,{}),"aria-label":`Close`,onClick:c})]}),(0,Q.jsxs)(`div`,{className:`space-y-4 px-5 py-4`,children:[s!==`gated`&&d&&(0,Q.jsxs)(`div`,{role:`tablist`,"aria-label":`OAuth mode`,className:`flex w-full rounded-md border border-[var(--border-base)] bg-[var(--surface-base)] p-0.5 dark:border-[var(--border-base)] dark:bg-[var(--surface-base)]/40`,children:[(0,Q.jsx)(ot,{active:f===`managed`,onClick:()=>m(`managed`),children:`Managed`}),(0,Q.jsx)(ot,{active:f===`your-own`,onClick:()=>m(`your-own`),children:`Your Own`})]}),f===`managed`&&s!==`gated`?s===`disabled`?(0,Q.jsx)(He,{children:`Log in to the Vellum platform to manage OAuth connections.`}):(0,Q.jsx)($e,{displayName:r,providerKey:n,logoUrl:o,connections:C,connectionsLoading:x,startPending:E,oauthInProgress:T,disconnectingId:k.isPending?h:null,onConnect:w,onDisconnect:A,connectPresets:it(n)}):d?(0,Q.jsx)(nt,{assistantId:e,providerKey:n,displayName:r,logoUrl:o}):null]}),(0,Q.jsx)(`div`,{className:`flex justify-end border-t border-[var(--border-base)] px-5 py-3 dark:border-[var(--border-base)]`,children:(0,Q.jsx)(a,{variant:`outlined`,size:`compact`,onClick:c,children:`Confirm`})})]}),(0,Q.jsx)(O,{open:_!==null,title:`Disconnect ${r}?`,message:_?`Disconnect ${_.account_label??`${r} Account`}? You can reconnect later.`:``,confirmLabel:`Disconnect`,destructive:!0,onConfirm:j,onCancel:()=>v(null)})]})}function ot({active:e,onClick:t,children:n}){return(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e,onClick:t,className:`flex-1 cursor-pointer rounded-[5px] px-3 py-1.5 text-body-medium-default transition-colors ${e?`bg-white text-[var(--content-default)] shadow-sm dark:bg-[var(--surface-lift)] dark:text-[var(--content-default)]`:`text-[var(--content-secondary)] hover:text-[var(--content-default)] dark:text-[var(--content-disabled)] dark:hover:text-[var(--content-default)]`}`,children:n})}function st({platformAssistantId:e,providerKey:t,displayName:n,description:r,logoUrl:i,connection:o,platformGate:s,onConfigure:c}){let l=p(),u=!!o?.connected,[d,f]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(!1),g=ye(),_=Ce({path:{assistant_id:e}}),v={path:{assistant_id:e}},y=Se({onSuccess(e,t){I.success(`${n} account disconnected.`);let r=t.path.connection_id;xe(l,v,e=>e?.filter(e=>e.id!==r)),l.invalidateQueries({queryKey:_})},onError(e){let t=me(e,void 0,`Failed to disconnect ${n} account.`);I.error(t)}}),b=()=>{o?.id&&h(!0)};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(T.Root,{children:(0,Q.jsxs)(T.Body,{padding:`sm`,className:`flex items-center gap-4 px-4`,children:[(0,Q.jsx)(Y,{providerKey:t,displayName:n,logoUrl:i,size:32}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`truncate text-title-small text-[var(--content-default)]`,children:n}),r&&(0,Q.jsx)(`p`,{className:`truncate text-body-medium-lighter text-[var(--content-tertiary)]`,children:r})]}),u&&s===`full`?(0,Q.jsx)(`div`,{className:`shrink-0`,children:(0,Q.jsx)(ct,{displayName:n,open:d,onOpenChange:f,onEditConnections:()=>{f(!1),c()},onDisable:()=>{f(!1),b()},disablePending:y.isPending,isMobile:g})}):(0,Q.jsx)(a,{variant:`primary`,onClick:c,className:`shrink-0`,children:`Enable`})]})}),(0,Q.jsx)(O,{open:m,title:`Disconnect ${n}?`,message:`Disconnect your ${n} account? You can reconnect it later.`,confirmLabel:`Disconnect`,destructive:!0,onConfirm:()=>{h(!1),o?.id&&y.mutate({path:{assistant_id:e,connection_id:o.id}})},onCancel:()=>h(!1)})]})}function ct({displayName:e,open:t,onOpenChange:n,onEditConnections:r,onDisable:i,disablePending:o,isMobile:s}){return s?(0,Q.jsxs)(E.Root,{open:t,onOpenChange:n,children:[(0,Q.jsx)(E.Trigger,{asChild:!0,children:(0,Q.jsx)(a,{variant:`outlined`,rightIcon:(0,Q.jsx)(q,{}),"aria-haspopup":`menu`,"aria-expanded":t,children:`Configure`})}),(0,Q.jsxs)(E.Content,{children:[(0,Q.jsx)(E.Header,{children:(0,Q.jsx)(E.Title,{children:e})}),(0,Q.jsxs)(E.Body,{children:[(0,Q.jsx)(D,{icon:W,label:`Edit connections`,onSelect:r}),(0,Q.jsx)(D,{icon:o?H:ze,label:`Disable`,onSelect:()=>{o||i()}})]})]})]}):(0,Q.jsxs)(A.Root,{open:t,onOpenChange:n,children:[(0,Q.jsx)(A.Trigger,{asChild:!0,children:(0,Q.jsx)(a,{variant:`outlined`,rightIcon:(0,Q.jsx)(q,{}),"aria-haspopup":`menu`,"aria-expanded":t,children:`Configure`})}),(0,Q.jsxs)(A.Content,{align:`end`,sideOffset:4,role:`menu`,className:`w-56 overflow-hidden p-0`,children:[(0,Q.jsx)(a,{type:`button`,role:`menuitem`,variant:`ghost`,onClick:r,className:`w-full justify-start rounded-none`,leftIcon:(0,Q.jsx)(W,{"aria-hidden":!0}),children:`Edit connections`}),(0,Q.jsx)(a,{type:`button`,role:`menuitem`,variant:`dangerGhost`,onClick:i,disabled:o,className:`w-full justify-start rounded-none`,leftIcon:o?(0,Q.jsx)(H,{className:`animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(ze,{"aria-hidden":!0}),children:`Disable`})]})]})}var lt=[{value:`none`,label:`None`},{value:`oauth`,label:`OAuth`},{value:`bearer`,label:`Bearer Token`},{value:`api-key`,label:`API Key`}],ut=[{value:`sse`,label:`SSE`},{value:`streamable-http`,label:`Streamable HTTP`},{value:`stdio`,label:`Stdio (command)`}];function dt({open:e,onClose:t,onAdd:n,isPending:r}){let[i,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(`sse`),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(`none`),[_,v]=(0,Z.useState)(``),[y,b]=(0,Z.useState)(`X-API-Key`),[x,S]=(0,Z.useState)(``),C=(0,Z.useCallback)(()=>{o(``),c(`sse`),u(``),f(``),m(``),g(`none`),v(``),b(`X-API-Key`),S(``)},[]),w=(0,Z.useCallback)(()=>{r||(C(),t())},[r,C,t]),T=(0,Z.useCallback)(()=>{let e=i.trim();if(!e)return;let t={name:e,transportType:s};if(s===`stdio`){let e=d.trim();if(!e)return;t.command=e;let n=p.trim();n&&(t.args=n.split(/\s+/))}else{let e=l.trim();if(!e)return;t.url=e,h===`bearer`&&_.trim()?t.headers={Authorization:`Bearer ${_.trim()}`}:h===`api-key`&&y.trim()&&x.trim()?t.headers={[y.trim()]:x.trim()}:h===`oauth`&&(t.autoAuth=!0)}n(t)},[i,s,l,d,p,h,_,y,x,n]),E=s===`stdio`,D=i.trim()&&(E?d.trim():l.trim());return(0,Q.jsx)(F.Root,{open:e,onOpenChange:e=>{e||w()},children:(0,Q.jsxs)(F.Content,{size:`md`,children:[(0,Q.jsxs)(F.Header,{children:[(0,Q.jsx)(F.Title,{icon:Xe,children:`Add MCP Server`}),(0,Q.jsx)(F.Description,{children:`Connect to a Model Context Protocol server to extend available tools.`})]}),(0,Q.jsx)(F.Body,{children:(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-name`,children:`Server name`}),(0,Q.jsx)(j,{id:`mcp-name`,type:`text`,value:i,onChange:e=>o(e.target.value),placeholder:`my-server`,fullWidth:!0,autoFocus:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-transport`,children:`Transport`}),(0,Q.jsx)(`select`,{id:`mcp-transport`,value:s,onChange:e=>c(e.target.value),className:`w-full rounded-md border border-[var(--border-element)] bg-[var(--surface-lift)] px-3 py-1.5 text-body-medium-default text-[var(--content-default)] outline-none focus:ring-2 focus:ring-[var(--ring)]`,children:ut.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),E?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-command`,children:`Command`}),(0,Q.jsx)(j,{id:`mcp-command`,type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`npx -y @modelcontextprotocol/server-example`,fullWidth:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-args`,children:`Arguments (space-separated)`}),(0,Q.jsx)(j,{id:`mcp-args`,type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`--port 3000`,fullWidth:!0})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-url`,children:`Server URL`}),(0,Q.jsx)(j,{id:`mcp-url`,type:`url`,value:l,onChange:e=>u(e.target.value),placeholder:`https://example.com/mcp`,fullWidth:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-auth`,children:`Authentication`}),(0,Q.jsx)(`select`,{id:`mcp-auth`,value:h,onChange:e=>g(e.target.value),className:`w-full rounded-md border border-[var(--border-element)] bg-[var(--surface-lift)] px-3 py-1.5 text-body-medium-default text-[var(--content-default)] outline-none focus:ring-2 focus:ring-[var(--ring)]`,children:lt.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),h===`oauth`?(0,Q.jsx)(`p`,{className:`rounded-md border border-[var(--border-element)] bg-[var(--surface-base)] px-3 py-2 text-body-small-default text-[var(--content-tertiary)]`,children:`OAuth credentials will be configured through a browser-based authorization flow after the server is added.`}):null,h===`bearer`?(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-bearer`,children:`Bearer token`}),(0,Q.jsx)(j,{id:`mcp-bearer`,type:`password`,value:_,onChange:e=>v(e.target.value),placeholder:`tok_...`,fullWidth:!0})]}):null,h===`api-key`?(0,Q.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-apikey-header`,children:`Header name`}),(0,Q.jsx)(j,{id:`mcp-apikey-header`,type:`text`,value:y,onChange:e=>b(e.target.value),placeholder:`X-API-Key`,fullWidth:!0})]}),(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-apikey-value`,children:`API key`}),(0,Q.jsx)(j,{id:`mcp-apikey-value`,type:`password`,value:x,onChange:e=>S(e.target.value),placeholder:`sk_...`,fullWidth:!0})]})]}):null]})]})}),(0,Q.jsxs)(F.Footer,{children:[(0,Q.jsx)(a,{variant:`ghost`,onClick:w,disabled:r,children:`Cancel`}),(0,Q.jsx)(a,{variant:`primary`,onClick:T,disabled:!D||r,children:r?`Adding...`:`Add Server`})]})]})})}async function ft(e){let{data:t,response:n}=await G.get({url:`/v1/assistants/{assistant_id}/internal/mcp/list`,path:{assistant_id:e}});if(!n?.ok)throw Error(`Failed to fetch MCP servers: ${n?.status}`);return t}async function pt(e){let{data:t,response:n}=await G.get({url:`/v1/assistants/{assistant_id}/internal/mcp/tools-summary`,path:{assistant_id:e}});if(!n?.ok)throw Error(`Failed to fetch MCP tools summary: ${n?.status}`);return t}async function mt(e,t){let{response:n}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/update`,path:{assistant_id:e},body:t});if(!n?.ok)throw Error(`Failed to update MCP server: ${n?.status}`)}async function ht(e,t){let{response:n}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/add`,path:{assistant_id:e},body:t});if(!n?.ok)throw Error(`Failed to add MCP server: ${n?.status}`)}async function gt(e,t){let{response:n}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/remove`,path:{assistant_id:e},body:{name:t}});if(!n?.ok)throw Error(`Failed to remove MCP server: ${n?.status}`)}async function _t(e,t){let{data:n,response:r}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/auth/start`,path:{assistant_id:e},body:{serverId:t}});if(!r?.ok)throw Error(`Failed to start MCP auth: ${r?.status}`);return n}async function vt(e,t){let{data:n,response:r}=await G.get({url:`/v1/assistants/{assistant_id}/internal/mcp/auth/status/${encodeURIComponent(t)}`,path:{assistant_id:e}});if(!r?.ok)throw Error(`Failed to poll MCP auth status: ${r?.status}`);return n}async function yt(e,t){let{response:n}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/auth/revoke`,path:{assistant_id:e},body:{serverId:t}});if(!n?.ok)throw Error(`Failed to revoke OAuth for ${t}: ${n?.status}`)}async function bt(e){let{response:t}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/reload`,path:{assistant_id:e},body:{}});if(!t?.ok)throw Error(`Failed to reload MCP servers: ${t?.status}`)}var xt={connected:{icon:B,label:`Connected`,className:`text-[var(--system-positive-strong)]`},"needs-auth":{icon:Ue,label:`Needs Auth`,className:`text-[var(--system-warning-strong)]`},disabled:{icon:Le,label:`Disabled`,className:`text-[var(--content-tertiary)]`}},St={icon:z,label:`Error`,className:`text-[var(--system-negative-strong)]`};function Ct({server:e,toolsSummary:t,onToggleEnabled:n,onRemove:r,onConfigure:i,onAuthenticate:o,onRevokeOAuth:s,isUpdating:c,isAuthenticating:l,isRevoking:u}){let[d,f]=(0,Z.useState)(!1),p=xt[e.status]??St,m=p.icon,h=(0,Z.useCallback)(t=>n(e.id,t),[n,e.id]),g=(0,Z.useCallback)(()=>r(e.id),[r,e.id]),_=(0,Z.useCallback)(()=>i(e.id),[i,e.id]),v=(0,Z.useCallback)(()=>o(e.id),[o,e.id]),y=(0,Z.useCallback)(()=>s(e.id),[s,e.id]),b=(0,Z.useCallback)(()=>f(e=>!e),[]);return(0,Q.jsx)(T.Root,{children:(0,Q.jsxs)(T.Body,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-body-medium-default text-[var(--content-default)]`,children:e.id}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-label-medium-default ${p.className}`,children:[(0,Q.jsx)(m,{className:`h-3.5 w-3.5`}),p.label]}),e.hasOAuth?(0,Q.jsx)(`span`,{className:`rounded-full bg-[var(--surface-lift)] px-2 py-0.5 text-label-small-default text-[var(--content-secondary)]`,children:`OAuth`}):null]}),(0,Q.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-body-small-default text-[var(--content-tertiary)]`,children:[(0,Q.jsx)(`span`,{children:e.transport.type}),t?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,Q.jsxs)(`span`,{children:[t.toolCount,` `,t.toolCount===1?`tool`:`tools`]}),(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,Q.jsxs)(`span`,{children:[`~`,t.estimatedTokens.toLocaleString(),` tokens`]})]}):null]})]})}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[c||l?(0,Q.jsx)(H,{className:`h-4 w-4 animate-spin text-[var(--content-tertiary)]`}):null,e.status===`needs-auth`&&e.transport.type!==`stdio`&&!e.hasOAuth?(0,Q.jsx)(a,{variant:`ghost`,size:`compact`,leftIcon:(0,Q.jsx)(U,{}),onClick:v,disabled:l,children:l?`Authenticating...`:`Authenticate`}):null,e.hasOAuth?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(a,{variant:`ghost`,size:`compact`,leftIcon:(0,Q.jsx)(te,{}),onClick:v,disabled:l,tooltip:`Re-authenticate OAuth`,children:`Re-auth`}),(0,Q.jsx)(a,{variant:`dangerGhost`,size:`compact`,leftIcon:(0,Q.jsx)(Re,{}),onClick:y,disabled:u,tooltip:`Revoke OAuth credentials`,children:u?`Revoking...`:`Revoke`})]}):null,(0,Q.jsx)(M,{checked:e.enabled,onChange:h,disabled:c,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.id}`}),(0,Q.jsx)(a,{variant:`ghost`,size:`compact`,onClick:_,tooltip:`Configure`,children:`Configure`}),(0,Q.jsx)(a,{variant:`dangerGhost`,size:`compact`,iconOnly:(0,Q.jsx)(J,{}),onClick:g,tooltip:`Remove server`,"aria-label":`Remove ${e.id}`})]})]}),t&&t.tools.length>0?(0,Q.jsxs)(`div`,{className:`mt-3 border-t border-[var(--border-base)] pt-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:b,className:`flex w-full cursor-pointer items-center gap-1 text-body-small-default text-[var(--content-secondary)] hover:text-[var(--content-default)]`,children:[d?(0,Q.jsx)(q,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(R,{className:`h-3.5 w-3.5`}),t.toolCount,` registered `,t.toolCount===1?`tool`:`tools`]}),d?(0,Q.jsx)(`div`,{className:`mt-2 max-h-60 overflow-y-auto`,children:t.tools.map(e=>(0,Q.jsx)(P,{title:e.name,subtitle:e.description||void 0,trailing:(0,Q.jsxs)(`span`,{className:`whitespace-nowrap text-body-small-default text-[var(--content-secondary)]`,children:[`~`,e.estimatedTokens.toLocaleString(),` tok`]})},e.name))}):null]}):null]})})}var wt=[{value:`none`,label:`None`},{value:`bearer`,label:`Bearer Token`},{value:`api-key`,label:`API Key`}],Tt=[`low`,`medium`,`high`];function Et({server:e,toolsSummary:t,onClose:n,onSave:r,isPending:i}){let[o,s]=(0,Z.useState)(`medium`),[c,l]=(0,Z.useState)(`none`),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(`X-API-Key`),[m,h]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{e&&(s(e.defaultRiskLevel),l(e.authType),d(``),p(e.authHeaderName??`X-API-Key`),h(``))},[e]);let g=(0,Z.useCallback)(()=>{if(!e)return;let t=c!==e.authType,n=c===`bearer`&&u.trim()!==``,i=c===`api-key`&&f.trim()!==``&&m.trim()!==``,a=t||n||i,s;s=a?c===`none`?null:c===`bearer`&&u.trim()?{Authorization:`Bearer ${u.trim()}`}:c===`api-key`&&f.trim()&&m.trim()?{[f.trim()]:m.trim()}:void 0:void 0,r(e.id,{name:e.id,defaultRiskLevel:o,...s===void 0?{}:{headers:s}})},[e,o,c,u,f,m,r]),_=(0,Z.useCallback)(()=>{i||n()},[i,n]);return e?(0,Q.jsx)(F.Root,{open:!!e,onOpenChange:e=>{e||_()},children:(0,Q.jsxs)(F.Content,{size:`lg`,children:[(0,Q.jsxs)(F.Header,{children:[(0,Q.jsx)(F.Title,{icon:Xe,children:e.id}),(0,Q.jsxs)(F.Description,{children:[e.transport.type,` transport · `,e.status]})]}),(0,Q.jsx)(F.Body,{children:(0,Q.jsxs)(`div`,{className:`space-y-5`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-risk`,children:`Default risk level`}),(0,Q.jsx)(`select`,{id:`mcp-risk`,value:o,onChange:e=>s(e.target.value),className:`w-full rounded-md border border-[var(--border-element)] bg-[var(--surface-lift)] px-3 py-1.5 text-body-medium-default text-[var(--content-default)] outline-none focus:ring-2 focus:ring-[var(--ring)]`,children:Tt.map(e=>(0,Q.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),e.transport.type===`stdio`?null:(0,Q.jsxs)(Q.Fragment,{children:[e.hasOAuth?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-[var(--border-element)] bg-[var(--surface-base)] px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`text-body-small-default text-[var(--content-secondary)]`,children:`Authentication`}),(0,Q.jsx)(`span`,{className:`rounded-full bg-[var(--surface-lift)] px-2 py-0.5 text-label-small-default text-[var(--content-default)]`,children:`OAuth`}),(0,Q.jsx)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`— managed via OAuth flow`})]}):null,e.hasOAuth?null:(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-detail-auth`,children:`Authentication`}),(0,Q.jsx)(`select`,{id:`mcp-detail-auth`,value:c,onChange:e=>l(e.target.value),className:`w-full rounded-md border border-[var(--border-element)] bg-[var(--surface-lift)] px-3 py-1.5 text-body-medium-default text-[var(--content-default)] outline-none focus:ring-2 focus:ring-[var(--ring)]`,children:wt.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),c===`bearer`&&!e.hasOAuth?(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-detail-bearer`,children:`Bearer token`}),(0,Q.jsx)(j,{id:`mcp-detail-bearer`,type:`password`,value:u,onChange:e=>d(e.target.value),placeholder:e.hasStaticAuth&&e.authType===`bearer`?`•••••••• (leave blank to keep current)`:`tok_...`,fullWidth:!0})]}):null,c===`api-key`&&!e.hasOAuth?(0,Q.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-detail-apikey-header`,children:`Header name`}),(0,Q.jsx)(j,{id:`mcp-detail-apikey-header`,type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`X-API-Key`,fullWidth:!0})]}),(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-detail-apikey-value`,children:`API key`}),(0,Q.jsx)(j,{id:`mcp-detail-apikey-value`,type:`password`,value:m,onChange:e=>h(e.target.value),placeholder:e.hasStaticAuth&&e.authType===`api-key`?`•••••••• (leave blank to keep current)`:`sk_...`,fullWidth:!0})]})]}):null]}),t&&t.tools.length>0?(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`h3`,{className:`text-body-medium-default text-[var(--content-default)]`,children:[`Registered tools (`,t.toolCount,`)`]}),(0,Q.jsxs)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:[`Total estimated token overhead: ~`,t.estimatedTokens.toLocaleString(),` tokens`]}),(0,Q.jsx)(`div`,{className:`max-h-64 overflow-y-auto rounded-lg border border-[var(--border-base)]`,children:(0,Q.jsxs)(`table`,{className:`w-full text-body-small-default`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`border-b border-[var(--border-base)] bg-[var(--surface-base)]`,children:[(0,Q.jsx)(`th`,{className:`px-3 py-2 text-left font-medium text-[var(--content-secondary)]`,children:`Tool`}),(0,Q.jsx)(`th`,{className:`px-3 py-2 text-left font-medium text-[var(--content-secondary)]`,children:`Description`}),(0,Q.jsx)(`th`,{className:`px-3 py-2 text-right font-medium text-[var(--content-secondary)]`,children:`Tokens`})]})}),(0,Q.jsx)(`tbody`,{children:t.tools.map(e=>(0,Q.jsxs)(`tr`,{className:`border-b border-[var(--border-base)] last:border-b-0`,children:[(0,Q.jsx)(`td`,{className:`px-3 py-2 font-medium text-[var(--content-default)]`,children:e.name}),(0,Q.jsx)(`td`,{className:`max-w-xs truncate px-3 py-2 text-[var(--content-tertiary)]`,children:e.description||`—`}),(0,Q.jsxs)(`td`,{className:`px-3 py-2 text-right text-[var(--content-tertiary)]`,children:[`~`,e.estimatedTokens.toLocaleString()]})]},e.name))})]})})]}):null]})}),(0,Q.jsxs)(F.Footer,{children:[(0,Q.jsx)(a,{variant:`ghost`,onClick:_,disabled:i,children:`Cancel`}),(0,Q.jsx)(a,{variant:`primary`,onClick:g,disabled:i,children:i?`Saving...`:`Save`})]})]})}):null}var Dt=`mcp-servers`,Ot=`mcp-tools-summary`,kt=`Help me set up an MCP server to extend you with external tools.`;function At(){let e=Ge(),t=p(),n=o(),r=be.use.mcpAddServer(),i=be.use.hasHydrated(),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(new Set),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(null),[D,k]=(0,Z.useState)(null),{data:A,isLoading:j,isError:M}=S({queryKey:[Dt,e],queryFn:()=>ft(e)}),{data:N}=S({queryKey:[Ot,e],queryFn:()=>pt(e)}),P=(0,Z.useCallback)(()=>{t.invalidateQueries({queryKey:[Dt,e]}),t.invalidateQueries({queryKey:[Ot,e]})},[t,e]),F=(0,Z.useMemo)(()=>{let e=new Map;if(N)for(let t of N.servers)e.set(t.serverId,t);return e},[N]),L=(0,Z.useMemo)(()=>!l||!A?null:A.servers.find(e=>e.id===l)??null,[l,A]),ee=(0,Z.useCallback)(async(t,n)=>{h(e=>new Set(e).add(t));try{await mt(e,{name:t,enabled:n}),P()}catch{I.error(`Failed to ${n?`enable`:`disable`} ${t}`)}finally{h(e=>{let n=new Set(e);return n.delete(t),n})}},[e,P]),R=(0,Z.useCallback)(async()=>{if(d){y(!0);try{await gt(e,d),P(),I.success(`Removed ${d}`),f(null)}catch{I.error(`Failed to remove ${d}`)}finally{y(!1)}}},[d,e,P]),z=(0,Z.useCallback)(async t=>{E(t);let n;try{n=await _t(e,t)}catch{I.error(`Failed to start authentication for ${t}`),E(null);return}try{if(n.already_authenticated){I.success(`${t} is already authenticated`),P();return}window.open(n.auth_url,`_blank`,`noopener,noreferrer`);for(let n=0;n<60;n++){await new Promise(e=>setTimeout(e,3e3));let n=await vt(e,t);if(n.status===`complete`){I.success(`${t} authenticated successfully`),P();return}if(n.status===`error`){I.error(n.error??`Authentication failed for ${t}`);return}}I.error(`Authentication timed out for ${t}`)}catch{I.error(`Authentication polling failed for ${t}`)}finally{E(null),P()}},[e,P]),B=(0,Z.useCallback)(async t=>{k(t);try{await yt(e,t),P(),I.success(`OAuth credentials revoked for ${t}`)}catch{I.error(`Failed to revoke OAuth for ${t}`)}finally{k(null)}},[e,P]),V=(0,Z.useCallback)(async t=>{let n=t.autoAuth?window.open(`about:blank`,`_blank`,`noopener`):null;_(!0);try{await ht(e,t),P(),I.success(`Added ${t.name}`),c(!1)}catch{I.error(`Failed to add ${t.name}`),n?.close(),_(!1);return}if(_(!1),t.autoAuth){E(t.name);try{let r=await _t(e,t.name);if(r.already_authenticated){n?.close(),I.success(`${t.name} is already authenticated`),P();return}n?n.location.href=r.auth_url:window.open(r.auth_url,`_blank`,`noopener,noreferrer`);for(let n=0;n<60;n++){await new Promise(e=>setTimeout(e,3e3));let n=await vt(e,t.name);if(n.status===`complete`){I.success(`${t.name} authenticated successfully`),P();return}if(n.status===`error`){I.error(n.error??`Authentication failed for ${t.name}`);return}}I.error(`Authentication timed out for ${t.name}`)}catch{n?.close(),I.error(`Failed to start authentication for ${t.name}`)}finally{E(null),P()}}},[e,P]),U=(0,Z.useCallback)(async(t,n)=>{x(!0);try{await mt(e,n),P(),I.success(`Updated ${t}`),u(null)}catch{I.error(`Failed to update ${t}`)}finally{x(!1)}},[e,P]),W=(0,Z.useCallback)(async()=>{w(!0);try{await bt(e),P(),I.success(`MCP servers reloaded`)}catch{I.error(`Failed to reload MCP servers`)}finally{w(!1)}},[e,P]),ne=(0,Z.useCallback)(()=>{r?c(!0):Ae(n,{prompt:kt})},[r,n]),re=A?.servers??[];return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-title-small text-[var(--content-default)]`,children:`MCP Servers`}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-body-small-default text-[var(--content-tertiary)]`,children:`Manage Model Context Protocol server connections and their registered tools.`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(a,{variant:`ghost`,size:`compact`,iconOnly:(0,Q.jsx)(te,{className:C?`animate-spin`:``}),onClick:W,disabled:C,tooltip:`Reload all servers`,"aria-label":`Reload MCP servers`}),r?(0,Q.jsx)(a,{variant:`primary`,size:`compact`,leftIcon:(0,Q.jsx)(X,{}),onClick:()=>c(!0),children:`Add Server`}):null]})]}),N?(0,Q.jsxs)(`div`,{className:`flex gap-4 text-body-small-default text-[var(--content-tertiary)]`,children:[(0,Q.jsxs)(`span`,{children:[N.totalToolCount,` total `,N.totalToolCount===1?`tool`:`tools`]}),(0,Q.jsxs)(`span`,{children:[`~`,N.totalEstimatedTokens.toLocaleString(),` total tokens`]})]}):null,j?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,Q.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,Q.jsx)(`span`,{children:`Loading MCP servers...`})]}):M?(0,Q.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Failed to load MCP servers. Check that an assistant is running.`}):re.length===0?(0,Q.jsxs)(`button`,{type:`button`,onClick:ne,disabled:!i,className:`flex w-full flex-col items-center gap-2 rounded-lg border border-dashed border-[var(--border-element)] px-4 py-12 text-center transition-colors hover:border-[var(--border-active)] hover:bg-[var(--surface-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)] disabled:pointer-events-none`,children:[(0,Q.jsx)(Xe,{className:`h-6 w-6 text-[var(--content-disabled)]`}),(0,Q.jsx)(`p`,{className:`text-body-medium-default text-[var(--content-default)]`,children:`No MCP Servers`}),(0,Q.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:r?`Add an MCP server to extend your assistant with external tools.`:`Chat with your assistant to set up an MCP server.`})]}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:re.map(e=>(0,Q.jsx)(Ct,{server:e,toolsSummary:F.get(e.id),onToggleEnabled:ee,onRemove:f,onConfigure:u,onAuthenticate:z,onRevokeOAuth:B,isUpdating:m.has(e.id),isAuthenticating:T===e.id,isRevoking:D===e.id},e.id))}),r?(0,Q.jsx)(dt,{open:s,onClose:()=>c(!1),onAdd:V,isPending:g}):null,(0,Q.jsx)(Et,{server:L,toolsSummary:l?F.get(l):void 0,onClose:()=>u(null),onSave:U,isPending:b}),(0,Q.jsx)(O,{open:!!d,title:`Remove MCP Server`,message:`Are you sure you want to remove "${d}"? This will disconnect all tools provided by this server.`,confirmLabel:`Remove`,destructive:!0,isPending:v,onConfirm:R,onCancel:()=>f(null)})]})}function jt(){return(0,Q.jsx)(At,{})}function Mt(e,t){let[n,r]=(0,Z.useState)({platformAssistantId:null,isLoading:!1,error:null});return(0,Z.useEffect)(()=>{if(!t||!e){r({platformAssistantId:null,isLoading:!1,error:null});return}let n=!0;return r({platformAssistantId:null,isLoading:!0,error:null}),he(e).then(e=>{n&&r({platformAssistantId:e,isLoading:!1,error:null})}).catch(e=>{n&&r({platformAssistantId:null,isLoading:!1,error:e instanceof Error?e:Error(String(e))})}),()=>{n=!1}},[e,t]),n}var Nt=`vellum:integrations:bannerDismissed`,Pt=[{value:`all`,label:`All`},{value:`enabled`,label:`Enabled`},{value:`not-enabled`,label:`Not Enabled`}];function $(e,t){return e?.find(e=>e.provider===t)??null}function Ft(e){return e===`mcp`?`mcp`:`oauth`}function It(){let[e]=s(),i=o(),a=Fe(),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!0),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(`all`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!0),[b,x]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{y(t(Nt,`false`)===`true`)},[]);let C=()=>{y(!0),n(Nt,`true`)};(0,Z.useEffect)(()=>{let e=!0;return(async()=>{try{let t=await _e();e&&t.ok&&l(t.data)}catch(e){r(e,{context:`integrations.getAssistant`})}finally{e&&d(!1)}})(),()=>{e=!1}},[]);let{platformAssistantId:w,isLoading:T}=Mt(c?.id,a===`full`),{data:E,isLoading:D,isError:O}=S({...de({path:{assistant_id:c?.id??``}}),select:e=>e.providers,enabled:!!c}),{data:M,isLoading:N}=S({...K({path:{assistant_id:w??``}}),enabled:!!w&&a===`full`});(0,Z.useEffect)(()=>{let t=e.get(`oauth_status`);if(!t)return;let n=e.get(`oauth_provider`),r=n?n.charAt(0).toUpperCase()+n.slice(1):null;if(t===`connected`)I.success(r?`${r} account connected successfully.`:`Account connected successfully.`);else if(t===`error`){let t=e.get(`oauth_code`)??`unknown`;I.error({denied:`Authorization was denied. Please try again.`,state_invalid:`Authorization state was invalid. Please try again.`,state_expired:`Authorization expired. Please try again.`,exchange_failed:`Failed to complete authorization. Please try again.`,identity_failed:`Failed to verify account identity. Please try again.`}[t]??(r?`Failed to connect ${r}.`:`Failed to connect. Please try again.`))}i(ve.settings.integrations,{replace:!0})},[e,i]);let P=(0,Z.useMemo)(()=>E?.filter(e=>e.supports_managed_mode)??[],[E]),F=(0,Z.useMemo)(()=>{let e=f.trim().toLowerCase(),t=P.filter(t=>{if(!e)return!0;let n=(t.display_name??t.provider_key).toLowerCase(),r=(t.description??``).toLowerCase();return n.includes(e)||r.includes(e)});return m!==`all`&&(t=t.filter(e=>{let t=!!$(M,e.provider_key)?.connected;return m===`enabled`?t:!t})),[...t].sort((e,t)=>{let n=!!$(M,e.provider_key)?.connected;if(n!==!!$(M,t.provider_key)?.connected)return n?-1:1;let r=(e.display_name??e.provider_key).toLowerCase(),i=(t.display_name??t.provider_key).toLowerCase();return r.localeCompare(i)})},[P,M,f,m]),L=u||D||N||T,ee=Pt.find(e=>e.value===m)?.label??`All`,R=(()=>{if(f.trim())return`No integrations matched`;switch(m){case`enabled`:return`No Enabled Integrations`;case`not-enabled`:return`All Integrations Are Enabled`;default:return`No Integrations Available`}})(),z=(()=>{if(f.trim())return`No integrations matched "${f.trim()}"`;switch(m){case`enabled`:return`Connect an integration to get started.`;case`not-enabled`:return`All available integrations have been connected.`;default:return`Check your connection and try again.`}})(),B=(0,Z.useMemo)(()=>b?P.find(e=>e.provider_key===b)??null:null,[P,b]);return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[!v&&(0,Q.jsxs)(k,{tone:`info`,icon:(0,Q.jsx)(ne,{className:`h-3.5 w-3.5`}),onDismiss:C,children:[(0,Q.jsx)(`span`,{className:`text-body-medium-default`,children:`Tip:`}),` You can enable integrations by mentioning them in chat.`]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(j,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`Search Integrations`,"aria-label":`Search integrations`,leftIcon:(0,Q.jsx)(je,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),fullWidth:!0,wrapperClassName:`flex-1`}),(0,Q.jsxs)(A.Root,{open:g,onOpenChange:_,children:[(0,Q.jsx)(A.Trigger,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,"aria-haspopup":`listbox`,"aria-expanded":g,className:`flex w-36 cursor-pointer items-center justify-between gap-2 rounded-md border border-[var(--border-element)] bg-[var(--surface-lift)] px-3 py-1.5 text-body-medium-lighter text-[var(--content-default)] transition-colors hover:bg-[var(--ghost-hover)]`,children:[(0,Q.jsx)(`span`,{children:ee}),(0,Q.jsx)(q,{className:`h-3.5 w-3.5`})]})}),(0,Q.jsx)(A.Content,{align:`end`,sideOffset:4,className:`w-36 overflow-hidden p-0`,children:(0,Q.jsx)(`div`,{role:`listbox`,children:Pt.map(e=>{let t=e.value===m;return(0,Q.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":t,onClick:()=>{h(e.value),_(!1)},className:`flex w-full cursor-pointer items-center px-3 py-1.5 text-left hover:bg-[var(--ghost-hover)] ${t?`text-body-medium-default text-[var(--content-default)]`:`text-body-medium-lighter text-[var(--content-default)]`}`,children:e.label},e.value)})})})]})]}),(0,Q.jsx)(`div`,{children:L?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,Q.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,Q.jsx)(`span`,{children:`Loading...`})]}):O?(0,Q.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Failed to load integrations. Please try again.`}):c?F.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-[var(--border-element)] px-4 py-12 text-center`,children:[(0,Q.jsx)(je,{className:`h-6 w-6 text-[var(--content-disabled)]`}),(0,Q.jsx)(`p`,{className:`text-body-medium-default text-[var(--content-default)]`,children:R}),(0,Q.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:z})]}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:F.map(e=>(0,Q.jsx)(st,{platformAssistantId:w??c.id,providerKey:e.provider_key,displayName:e.display_name??e.provider_key,description:e.description,logoUrl:e.logo_url,connection:$(M,e.provider_key),platformGate:a,onConfigure:()=>x(e.provider_key)},e.provider_key))}):(0,Q.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`No assistant found. Hatch an assistant to connect integrations.`})}),B&&c&&(0,Q.jsx)(at,{assistantId:c.id,platformAssistantId:w??c.id,providerKey:B.provider_key,displayName:B.display_name??B.provider_key,description:B.description,logoUrl:B.logo_url,platformGate:a,onClose:()=>x(null)})]})}function Lt(){let[e,t]=s(),n=Ft(e.get(`tab`));return(0,Q.jsx)(`div`,{className:`space-y-6`,children:(0,Q.jsxs)(N.Root,{value:n,onValueChange:n=>{let r=Ft(n),i=new URLSearchParams(e);r===`mcp`?i.set(`tab`,`mcp`):i.delete(`tab`),t(i,{replace:!0})},children:[(0,Q.jsxs)(N.List,{children:[(0,Q.jsx)(N.Trigger,{value:`oauth`,children:`OAuth`}),(0,Q.jsx)(N.Trigger,{value:`mcp`,children:`MCP`})]}),(0,Q.jsx)(N.Panel,{value:`oauth`,className:`pt-4`,children:(0,Q.jsx)(Z.Suspense,{children:(0,Q.jsx)(It,{})})}),(0,Q.jsx)(N.Panel,{value:`mcp`,className:`pt-4`,children:(0,Q.jsx)(jt,{})})]})})}export{Lt as IntegrationsPage};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{r as t,s as n}from"./local-settings-lVNyIOJ_.js";import{t as r}from"./capture-error-Hr1Yo2kx.js";import{t as i}from"./react-DJZBPgpf.js";import{t as a}from"./button-D7s2Q_uG.js";import{d as o,h as s}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{N as c,O as l,S as u,T as d,c as f,n as p}from"./QueryClientProvider-DKhXIxGb.js";import{a as m,c as h,d as g,i as _,l as v,o as y,r as b,s as x,t as S,u as C}from"./useQuery-B45lW1Kk.js";import{t as w}from"./jsx-runtime-CVSDxk6A.js";import{t as T}from"./card-BibIM9x3.js";import{n as E,t as D}from"./panel-item-nGTDevWP.js";import{t as O}from"./confirm-dialog-CfOXCE1N.js";import{t as k}from"./notice-CqRgVmeL.js";import{t as A}from"./popover-CL-JL6vG.js";import{t as j}from"./input-C8kfrq9r.js";import{t as M}from"./toggle-X_kQW5my.js";import{n as N,t as P}from"./list-row-Cw9JYESP.js";import{t as F}from"./modal-D0Q3UWD0.js";import{n as I}from"./toast-2TW5tj1Y.js";import{t as L}from"./createLucideIcon-BlMXrA59.js";import{t as ee}from"./check-D6WkI0gF.js";import{t as R}from"./chevron-right-B6vEpVY0.js";import{t as z}from"./circle-alert-DvNg50UK.js";import{t as B}from"./circle-check-DzlJxj_M.js";import{t as V}from"./external-link-DPAtkBJ2.js";import{t as H}from"./loader-circle-IIzBGiwm.js";import{t as U}from"./log-in-2iOsufxq.js";import{t as W}from"./pencil-DbB9rxpY.js";import{t as te}from"./refresh-cw-Bf6LV0kG.js";import{t as ne}from"./sparkles-BICoewVE.js";import{t as re}from"./x-KVxA2ZL0.js";import{hr as G}from"./sdk.gen-1aYqVbMj.js";import{Bt as ie,J as ae,K as oe,Rt as se,Vt as ce,X as le,Y as ue,Z as de,q as fe,zt as pe}from"./react-query.gen-CQLyoqYk.js";import{r as me}from"./api-errors-CveHbhgb.js";import{L as he,M as ge}from"./auth-store-Kfxhs2oI.js";import{r as _e}from"./api-2kc3MHRz.js";import{a as ve}from"./routes-DVqkwUEe.js";import{n as ye}from"./use-is-mobile-Cy10kl9u.js";import{t as be}from"./assistant-feature-flag-store-Dl92XRsM.js";import{S as xe,b as K,vt as Se,x as Ce,yt as we}from"./react-query.gen-rp6Krcco.js";import{n as Te,t as Ee}from"./browser-CKX_K5ev.js";import{$i as q,Ct as De,Dt as Oe,Et as ke,Ht as Ae,Ir as J,Jr as je,Li as Me,Ot as Ne,St as Pe,Y,an as Fe,bt as Ie,ei as Le,mi as Re,qi as ze,rn as Be,ti as X,wt as Ve,x as He,xi as Ue,xt as We}from"./index-PRnvH2Y1.js";import{t as Ge}from"./use-active-assistant-id-C-RHQ9f6.js";function Ke(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}function qe(e,t,n){let r=e.slice(0);return r[t]=n,r}var Je=class extends c{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=[];constructor(e,t,n){super(),this.#e=e,this.#r=n,this.#n=[],this.#i=[],this.#t=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#i.forEach(e=>{e.subscribe(t=>{this.#p(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#i.forEach(e=>{e.destroy()})}setQueries(e,t){this.#n=e,this.#r=t,f.batch(()=>{let e=this.#i,t=this.#f(this.#n);t.forEach(e=>e.observer.setOptions(e.defaultedQueryOptions));let n=t.map(e=>e.observer),r=n.map(e=>e.getCurrentResult()),i=e.length!==n.length,a=n.some((t,n)=>t!==e[n]),o=i||a,s=o?!0:r.some((e,t)=>{let n=this.#t[t];return!n||!l(e,n)});!o&&!s||(o&&(this.#l=t,this.#i=n),this.#t=r,this.hasListeners()&&(o&&(Ke(e,n).forEach(e=>{e.destroy()}),Ke(n,e).forEach(e=>{e.subscribe(t=>{this.#p(e,t)})})),this.#m()))})}getCurrentResult(){return this.#t}getQueries(){return this.#i.map(e=>e.getCurrentQuery())}getObservers(){return this.#i}getOptimisticResult(e,t){let n=this.#f(e),r=n.map(e=>e.observer.getOptimisticResult(e.defaultedQueryOptions)),i=n.map(e=>e.defaultedQueryOptions.queryHash);return[r,e=>this.#d(e??r,t,i),()=>this.#u(r,n)]}#u(e,t){return t.map((n,r)=>{let i=e[r];return n.defaultedQueryOptions.notifyOnChangeProps?i:n.observer.trackResult(i,e=>{t.forEach(t=>{t.observer.trackProp(e)})})})}#d(e,t,n){if(t){let r=this.#c,i=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((e,t)=>e!==r[t]));return(!this.#a||this.#t!==this.#s||i||t!==this.#o)&&(this.#o=t,this.#s=this.#t,n!==void 0&&(this.#c=n),this.#a=d(this.#a,t(e))),this.#a}return e}#f(e){let t=new Map;this.#i.forEach(e=>{let n=e.options.queryHash;if(!n)return;let r=t.get(n);r?r.push(e):t.set(n,[e])});let n=[];return e.forEach(e=>{let r=this.#e.defaultQueryOptions(e),i=t.get(r.queryHash)?.shift()??new g(this.#e,r);n.push({defaultedQueryOptions:r,observer:i})}),n}#p(e,t){let n=this.#i.indexOf(e);n!==-1&&(this.#t=qe(this.#t,n,t),this.#m())}#m(){if(this.hasListeners()){let e=this.#a,t=this.#u(this.#t,this.#l);e!==this.#d(t,this.#r?.combine)&&f.batch(()=>{this.listeners.forEach(e=>{e(this.#t)})})}}},Z=e(i(),1);function Ye({queries:e,...t},n){let r=p(n),i=C(),a=v(),o=Z.useMemo(()=>e.map(e=>{let t=r.defaultQueryOptions(e);return t._optimisticResults=i?`isRestoring`:`optimistic`,t}),[e,r,i]);o.forEach(e=>{b(e),y(e,a,r.getQueryCache().get(e.queryHash))}),h(a);let[s]=Z.useState(()=>new Je(r,o,t)),[c,l,d]=s.getOptimisticResult(o,t.combine),S=!i&&t.subscribed!==!1;Z.useSyncExternalStore(Z.useCallback(e=>S?s.subscribe(f.batchCalls(e)):u,[s,S]),()=>s.getCurrentResult(),()=>s.getCurrentResult()),Z.useEffect(()=>{s.setQueries(o,t)},[o,t,s]);let w=c.some((e,t)=>m(o[t],e))?c.flatMap((e,t)=>{let n=o[t];return n&&m(n,e)?_(n,new g(r,n),a):[]}):[];if(w.length>0)throw Promise.all(w);let T=c.find((e,t)=>{let n=o[t];return n&&x({result:e,errorResetBoundary:a,throwOnError:n.throwOnError,query:r.getQueryCache().get(n.queryHash),suspense:n.suspense})});if(T?.error)throw T.error;return l(d())}var Xe=L(`cable`,[[`path`,{d:`M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z`,key:`trhst0`}],[`path`,{d:`M17 21v-2`,key:`ds4u3f`}],[`path`,{d:`M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10`,key:`1mo9zo`}],[`path`,{d:`M21 21v-2`,key:`eo0ou`}],[`path`,{d:`M3 5V3`,key:`1k5hjh`}],[`path`,{d:`M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z`,key:`1dd30t`}],[`path`,{d:`M7 5V3`,key:`1t1388`}]]),Ze=L(`calendar-plus`,[[`path`,{d:`M16 19h6`,key:`xwg31i`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M19 16v6`,key:`tddt3s`}],[`path`,{d:`M21 12.598V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8.5`,key:`1glfrc`}],[`path`,{d:`M3 10h18`,key:`8toen8`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}]]);function Qe({assistantId:e,providerKey:t,displayName:n,managedAvailable:r,connectionsQueryKey:i,allConnections:a}){let o=p(),s=ge(),c=(0,Z.useRef)(null),l=(0,Z.useRef)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),[f,m]=(0,Z.useState)(!1),h=()=>{l.current=null,m(!1)},g=()=>{c.current&&!c.current.closed&&c.current.close(),c.current=null,u.current&&=(clearInterval(u.current),null),d.current&&=(clearTimeout(d.current),null)},_=(0,Z.useCallback)(e=>{if(e.type!==`vellum:oauth-complete`||!l.current||e.requestId!==l.current.requestId)return;let{oauthStatus:t,oauthCode:r}=e;if(g(),h(),t===`connected`)I.success(`${n} account connected.`),o.invalidateQueries({queryKey:i});else{let e=r?`Error: ${r}`:`Authorization failed`;I.error(`${n} ${e}`)}},[i,n,o]),v=(0,Z.useCallback)(async(e,n)=>{if(!r)return!1;for(let r=0;r<8;r+=1){r>0&&await Pe(750);try{if(o.invalidateQueries({queryKey:i}),We(await o.fetchQuery({...K({path:{assistant_id:e}}),staleTime:0}),t,n))return!0}catch{}}return!1},[i,r,t,o]);(0,Z.useEffect)(()=>{let e=e=>{let t=l.current;if(!t)return;let n=De(e,window.location.origin,t.requestId);n&&_(n)},t=e=>{let t=l.current;if(!t)return;let n=Ve(e,t.requestId);n&&(_(n),window.localStorage.removeItem(ke(t.requestId)))};return window.addEventListener(`message`,e),window.addEventListener(`storage`,t),()=>{window.removeEventListener(`message`,e),window.removeEventListener(`storage`,t)}},[_]),Ne((0,Z.useCallback)(e=>{let t=l.current;t&&e.requestId===t.requestId&&_({type:`vellum:oauth-complete`,requestId:e.requestId,oauthStatus:e.oauthStatus,oauthProvider:e.oauthProvider,oauthCode:e.oauthCode})},[_])),(0,Z.useEffect)(()=>Te(()=>{let e=l.current;e&&(async()=>{let t=await v(e.platformAssistantId,e.baselineConnectionSignatures);l.current&&(h(),t&&I.success(`${n} account connected.`))})()}),[v,n]),(0,Z.useEffect)(()=>()=>{u.current&&clearInterval(u.current),d.current&&clearTimeout(d.current),c.current&&!c.current.closed&&c.current.close()},[]);let y=we();return{handleConnect:(i=[])=>{if(!r)return;let f=crypto.randomUUID();m(!0);let p=async r=>{let c;try{c=await he(e)}catch(e){g(),h(),I.error(e instanceof Error?e.message:`Failed to start ${n} authorization.`);return}let u=Ie(await o.fetchQuery({...K({path:{assistant_id:c}}),staleTime:0}).catch(()=>c===e?a??[]:[]),t);l.current={requestId:f,provider:t,platformAssistantId:c,baselineConnectionSignatures:u},y.mutate({path:{assistant_id:c,provider:t},body:{requested_scopes:i,redirect_after_connect:`${ve.account.oauth.popupComplete}?requestId=${f}${s?`&native=1`:``}`}},{onSuccess(e){if(s){Ee(e.connect_url);return}r&&!r.closed?r.location.href=e.connect_url:l.current&&(g(),h(),I.error(`${n} connection failed: popup closed.`))},onError(e){g(),h();let t=me(e,void 0,`Failed to start ${n} authorization.`);I.error(t)}})};if(s){p(null);return}let b=window.open(``,`_blank`,`width=500,height=600`);if(b===null){h(),I.error(`Popup blocked. Please enable popups and try again.`);return}c.current=b,u.current=setInterval(()=>{c.current&&c.current.closed&&l.current&&!d.current&&(d.current=setTimeout(async()=>{d.current=null;let e=l.current;if(!e)return;let t=window.localStorage.getItem(ke(e.requestId));if(t){let n=Oe(t);if(n&&n.requestId===e.requestId){_(n),window.localStorage.removeItem(ke(e.requestId));return}}let r=await v(e.platformAssistantId,e.baselineConnectionSignatures);if(l.current){if(r){g(),h(),I.success(`${n} account connected.`);return}g(),h(),I.error(`${n} connection failed: authorization popup closed.`)}},1e3))},100),p(b)},oauthInProgress:f,startOAuthPending:y.isPending}}var Q=w();function $e({displayName:e,providerKey:t,logoUrl:n,connections:r,connectionsLoading:i,startPending:o,oauthInProgress:s,disconnectingId:c,onConnect:l,onDisconnect:u,connectPresets:d=[]}){let f=o||s;return i?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,Q.jsx)(H,{className:`h-5 w-5 animate-spin text-[var(--content-disabled)]`})}):r.length===0?o||s?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-10`,children:[(0,Q.jsx)(Y,{providerKey:t,displayName:e,logoUrl:n,size:48}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,Q.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}),`Waiting for authorization...`]})]}):(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-10`,children:[(0,Q.jsx)(Y,{providerKey:t,displayName:e,logoUrl:n,size:48}),(0,Q.jsx)(`p`,{className:`text-body-medium-default text-[var(--content-secondary)]`,children:`Connect Account to continue`}),(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,Q.jsx)(a,{variant:`primary`,size:`compact`,leftIcon:(0,Q.jsx)(X,{}),onClick:()=>l(),disabled:f,children:`Connect Account`}),d.map(e=>(0,Q.jsx)(a,{variant:`outlined`,size:`compact`,leftIcon:(0,Q.jsx)(Ze,{}),onClick:()=>l(e.scopes),disabled:f,children:e.label},e.id))]})]}):(0,Q.jsxs)(`div`,{className:`rounded-lg border border-[var(--border-base)]`,children:[(0,Q.jsx)(`ul`,{className:`divide-y divide-[var(--border-base)]`,children:r.map(r=>{let i=c===r.id;return(0,Q.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,Q.jsx)(Y,{providerKey:t,displayName:e,logoUrl:n,size:20}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-body-medium-default text-[var(--content-default)]`,children:r.account_label??`${e} Account`}),(0,Q.jsx)(a,{variant:`dangerOutline`,size:`compact`,iconOnly:i?(0,Q.jsx)(H,{className:`animate-spin`}):(0,Q.jsx)(J,{}),onClick:()=>u(r),disabled:i,"aria-label":`Disconnect ${r.account_label??`${e} account`}`})]},r.id)})}),(0,Q.jsx)(`div`,{className:`border-t border-[var(--border-base)] px-4 py-3 dark:border-[var(--border-base)]`,children:f?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,Q.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}),`Waiting for authorization...`]}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(a,{variant:`primary`,size:`compact`,leftIcon:(0,Q.jsx)(V,{}),onClick:()=>l(),disabled:f,children:`Connect account`}),d.map(e=>(0,Q.jsx)(a,{variant:`outlined`,size:`compact`,leftIcon:(0,Q.jsx)(Ze,{}),onClick:()=>l(e.scopes),disabled:f,children:e.label},e.id))]})})]})}function et(e){return e.length>16?`${e.slice(0,12)}…${e.slice(-4)}`:e.length>8?`${e.slice(0,8)}…`:e}function tt(e){try{return new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}catch{return``}}function nt({assistantId:e,providerKey:t,displayName:n,logoUrl:r}){let i=p(),o=S({...ae({path:{assistant_id:e},query:{provider_key:t}}),select:e=>e.apps}),s=S({...le({path:{assistant_id:e,providerKey:t}}),select:e=>e.oauth_callback_url}),c=o.data??[],l=s.data??null,u=Ye({queries:c.map(t=>({...oe({path:{assistant_id:e,appId:t.id}}),select:e=>e.connections}))}),d={};c.forEach((e,t)=>{d[e.id]=u[t]?.data??[]});let f=ue({path:{assistant_id:e},query:{provider_key:t}}),m=ie({onSuccess:()=>{i.invalidateQueries({queryKey:f}),x(``),w(``),y(!1),I.success(`${n} OAuth app added.`)},onError:e=>{I.error(e.message||`Failed to create OAuth app`)}}),h=pe({onSuccess:()=>{i.invalidateQueries({queryKey:f}),I.success(`OAuth app deleted.`)},onError:e=>{I.error(e.message||`Failed to delete OAuth app`)}}),g=se({onSuccess:e=>{`auth_url`in e&&(window.location.href=e.auth_url)},onError:e=>{I.error(e.message||`Failed to start OAuth flow`)}}),_=ce(),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(``),[C,w]=(0,Z.useState)(``),[E,D]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(null),[M,N]=(0,Z.useState)(null),P=m.isPending,F=h.isPending?h.variables?.path?.id??null:null,L=g.isPending?g.variables?.path?.appId??null:null,R=_.isPending?_.variables?.path?.id??null:null,z=()=>{let n=b.trim(),r=C.trim();!n||!r||m.mutate({path:{assistant_id:e},body:{provider_key:t,client_id:n,client_secret:r}})},B=()=>{let t=k;A(null),t&&h.mutate({path:{assistant_id:e,id:t.id}})},U=t=>{g.mutate({path:{assistant_id:e,appId:t.id},body:{callback_transport:`gateway`,scopes:[]}})};return o.isLoading?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,Q.jsx)(H,{className:`h-5 w-5 animate-spin text-[var(--content-disabled)]`})}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[c.length===0||v?(0,Q.jsx)(T.Root,{children:(0,Q.jsxs)(T.Body,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-body-medium-default text-[var(--content-default)]`,children:c.length===0?`Add your own ${n} OAuth app`:`Add another ${n} OAuth app`}),(0,Q.jsx)(`p`,{className:`text-body-small-default leading-relaxed text-[var(--content-tertiary)]`,children:`Credentials are stored encrypted on the assistant and are never sent to Vellum.`})]}),l?(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-body-small-default text-[var(--content-secondary)]`,children:`Redirect URL`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(j,{type:`text`,value:l,readOnly:!0,fullWidth:!0}),(0,Q.jsx)(a,{type:`button`,variant:`outlined`,size:`compact`,onClick:()=>{navigator.clipboard.writeText(l).then(()=>{D(!0),I.success(`Copied to clipboard!`),setTimeout(()=>D(!1),2e3)})},"aria-label":E?`Copied`:`Copy redirect URL`,iconOnly:E?(0,Q.jsx)(ee,{"aria-hidden":!0}):(0,Q.jsx)(Me,{"aria-hidden":!0})})]}),(0,Q.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`Add this URL to your OAuth app's redirect settings.`})]}):null,(0,Q.jsx)(j,{label:`Client ID`,type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:`Enter your client ID`,fullWidth:!0}),(0,Q.jsx)(j,{label:`Client Secret`,type:`password`,value:C,onChange:e=>w(e.target.value),placeholder:`Enter your client secret`,fullWidth:!0}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c.length>0?(0,Q.jsx)(a,{type:`button`,variant:`outlined`,size:`compact`,onClick:()=>{y(!1),x(``),w(``)},disabled:P,children:`Cancel`}):null,(0,Q.jsx)(a,{type:`button`,size:`compact`,onClick:z,disabled:P||!b.trim()||!C.trim(),leftIcon:P?(0,Q.jsx)(H,{className:`animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(X,{"aria-hidden":!0}),children:`Add App`})]})]})}):null,c.map(e=>{let i=d[e.id]??[],o=F===e.id,s=L===e.id;return(0,Q.jsx)(T.Root,{children:(0,Q.jsxs)(T.Body,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,Q.jsx)(`p`,{className:`truncate text-body-medium-default text-[var(--content-default)]`,children:et(e.client_id)}),(0,Q.jsxs)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:[`Added `,tt(e.created_at)]})]}),(0,Q.jsx)(a,{type:`button`,variant:`dangerOutline`,size:`compact`,onClick:()=>A(e),disabled:o,"aria-label":`Delete OAuth app ${et(e.client_id)}`,iconOnly:o?(0,Q.jsx)(H,{className:`animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(J,{"aria-hidden":!0})})]}),i.length>0?(0,Q.jsx)(`ul`,{className:`divide-y divide-[var(--border-base)] overflow-hidden rounded-md border border-[var(--border-base)] dark:divide-[var(--border-base)] dark:border-[var(--border-base)]`,children:i.map(i=>{let o=R===i.id;return(0,Q.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,Q.jsx)(Y,{providerKey:t,displayName:n,logoUrl:r,size:18}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-body-medium-lighter text-[var(--content-default)]`,children:i.account_info??`${n} Account`}),(0,Q.jsx)(a,{type:`button`,variant:`dangerOutline`,size:`compact`,onClick:()=>N({appId:e.id,connection:i}),disabled:o,"aria-label":`Disconnect ${i.account_info??`${n} account`}`,iconOnly:o?(0,Q.jsx)(H,{className:`animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(J,{"aria-hidden":!0})})]},i.id)})}):null,(0,Q.jsx)(a,{type:`button`,size:`compact`,onClick:()=>U(e),disabled:s,className:`w-full`,leftIcon:s?(0,Q.jsx)(H,{className:`animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(V,{"aria-hidden":!0}),children:s?`Waiting for authorization...`:`Connect account`})]})},e.id)}),c.length>0&&!v?(0,Q.jsx)(a,{type:`button`,variant:`outlined`,size:`compact`,onClick:()=>y(!0),className:`w-full border-dashed`,leftIcon:(0,Q.jsx)(X,{"aria-hidden":!0}),children:`Add Another App`}):null,(0,Q.jsx)(O,{open:k!==null,title:`Delete OAuth app`,message:k?`Delete OAuth app '${et(k.client_id)}'? This will disconnect all linked accounts.`:``,confirmLabel:`Delete`,destructive:!0,onConfirm:B,onCancel:()=>A(null)}),(0,Q.jsx)(O,{open:M!==null,title:`Disconnect ${n}?`,message:M?`Disconnect ${M.connection.account_info??`${n} Account`}? You can reconnect later.`:``,confirmLabel:`Disconnect`,destructive:!0,onConfirm:()=>{let t=M;N(null),t&&_.mutate({path:{assistant_id:e,id:t.connection.id}},{onSuccess:()=>{let r=fe({path:{assistant_id:e,appId:t.appId}});i.invalidateQueries({queryKey:r}),i.invalidateQueries({queryKey:f}),I.success(`${n} account disconnected.`)},onError:e=>{I.error(e.message||`Failed to disconnect account`)}})},onCancel:()=>N(null)})]})}var rt={};function it(e){return rt[e]??[]}function at({assistantId:e,platformAssistantId:t,providerKey:n,displayName:r,description:i,logoUrl:o,platformGate:s,onClose:c}){let l=p(),u=s===`full`,d=!Be(),[f,m]=(0,Z.useState)(s===`gated`&&d?`your-own`:`managed`);(0,Z.useEffect)(()=>{!d&&f===`your-own`&&m(`managed`)},[d,f]);let[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),y=Ce({path:{assistant_id:t}}),{data:b,isLoading:x}=S({...K({path:{assistant_id:t}}),enabled:u}),C=(b??[]).filter(e=>e.provider===n&&e.connected),{handleConnect:w,oauthInProgress:T,startOAuthPending:E}=Qe({assistantId:e,providerKey:n,displayName:r,managedAvailable:u,connectionsQueryKey:y,allConnections:b}),D={path:{assistant_id:t}},k=Se({onSuccess(e,t){I.success(`${r} account disconnected.`);let n=t.path.connection_id;xe(l,D,e=>e?.filter(e=>e.id!==n)),l.invalidateQueries({queryKey:y}),g(null)},onError(e){let t=me(e,void 0,`Failed to disconnect ${r} account.`);I.error(t),g(null)}});(0,Z.useEffect)(()=>{let e=e=>{e.key===`Escape`&&c()};document.addEventListener(`keydown`,e);let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=t}},[c]);let A=e=>{v(e)},j=()=>{let e=_;v(null),e&&(g(e.id),k.mutate({path:{assistant_id:t,connection_id:e.id}}))},M=i?`Configure ${r} OAuth for ${i}`:`Configure ${r} OAuth`;return(0,Q.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:[(0,Q.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`integration-modal-title`,className:`flex w-full max-w-[520px] flex-col overflow-hidden rounded-xl bg-white shadow-xl dark:bg-[var(--surface-lift)]`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-[var(--border-base)] px-5 py-4 dark:border-[var(--border-base)]`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(Y,{providerKey:n,displayName:r,logoUrl:o,size:32}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`h2`,{id:`integration-modal-title`,className:`text-title-small text-[var(--content-default)]`,children:[r,` OAuth`]}),(0,Q.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:M})]})]}),(0,Q.jsx)(a,{variant:`ghost`,size:`compact`,iconOnly:(0,Q.jsx)(re,{}),"aria-label":`Close`,onClick:c})]}),(0,Q.jsxs)(`div`,{className:`space-y-4 px-5 py-4`,children:[s!==`gated`&&d&&(0,Q.jsxs)(`div`,{role:`tablist`,"aria-label":`OAuth mode`,className:`flex w-full rounded-md border border-[var(--border-base)] bg-[var(--surface-base)] p-0.5 dark:border-[var(--border-base)] dark:bg-[var(--surface-base)]/40`,children:[(0,Q.jsx)(ot,{active:f===`managed`,onClick:()=>m(`managed`),children:`Managed`}),(0,Q.jsx)(ot,{active:f===`your-own`,onClick:()=>m(`your-own`),children:`Your Own`})]}),f===`managed`&&s!==`gated`?s===`disabled`?(0,Q.jsx)(He,{children:`Log in to the Vellum platform to manage OAuth connections.`}):(0,Q.jsx)($e,{displayName:r,providerKey:n,logoUrl:o,connections:C,connectionsLoading:x,startPending:E,oauthInProgress:T,disconnectingId:k.isPending?h:null,onConnect:w,onDisconnect:A,connectPresets:it(n)}):d?(0,Q.jsx)(nt,{assistantId:e,providerKey:n,displayName:r,logoUrl:o}):null]}),(0,Q.jsx)(`div`,{className:`flex justify-end border-t border-[var(--border-base)] px-5 py-3 dark:border-[var(--border-base)]`,children:(0,Q.jsx)(a,{variant:`outlined`,size:`compact`,onClick:c,children:`Confirm`})})]}),(0,Q.jsx)(O,{open:_!==null,title:`Disconnect ${r}?`,message:_?`Disconnect ${_.account_label??`${r} Account`}? You can reconnect later.`:``,confirmLabel:`Disconnect`,destructive:!0,onConfirm:j,onCancel:()=>v(null)})]})}function ot({active:e,onClick:t,children:n}){return(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e,onClick:t,className:`flex-1 cursor-pointer rounded-[5px] px-3 py-1.5 text-body-medium-default transition-colors ${e?`bg-white text-[var(--content-default)] shadow-sm dark:bg-[var(--surface-lift)] dark:text-[var(--content-default)]`:`text-[var(--content-secondary)] hover:text-[var(--content-default)] dark:text-[var(--content-disabled)] dark:hover:text-[var(--content-default)]`}`,children:n})}function st({platformAssistantId:e,providerKey:t,displayName:n,description:r,logoUrl:i,connection:o,platformGate:s,onConfigure:c}){let l=p(),u=!!o?.connected,[d,f]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(!1),g=ye(),_=Ce({path:{assistant_id:e}}),v={path:{assistant_id:e}},y=Se({onSuccess(e,t){I.success(`${n} account disconnected.`);let r=t.path.connection_id;xe(l,v,e=>e?.filter(e=>e.id!==r)),l.invalidateQueries({queryKey:_})},onError(e){let t=me(e,void 0,`Failed to disconnect ${n} account.`);I.error(t)}}),b=()=>{o?.id&&h(!0)};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(T.Root,{children:(0,Q.jsxs)(T.Body,{padding:`sm`,className:`flex items-center gap-4 px-4`,children:[(0,Q.jsx)(Y,{providerKey:t,displayName:n,logoUrl:i,size:32}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`truncate text-title-small text-[var(--content-default)]`,children:n}),r&&(0,Q.jsx)(`p`,{className:`truncate text-body-medium-lighter text-[var(--content-tertiary)]`,children:r})]}),u&&s===`full`?(0,Q.jsx)(`div`,{className:`shrink-0`,children:(0,Q.jsx)(ct,{displayName:n,open:d,onOpenChange:f,onEditConnections:()=>{f(!1),c()},onDisable:()=>{f(!1),b()},disablePending:y.isPending,isMobile:g})}):(0,Q.jsx)(a,{variant:`primary`,onClick:c,className:`shrink-0`,children:`Enable`})]})}),(0,Q.jsx)(O,{open:m,title:`Disconnect ${n}?`,message:`Disconnect your ${n} account? You can reconnect it later.`,confirmLabel:`Disconnect`,destructive:!0,onConfirm:()=>{h(!1),o?.id&&y.mutate({path:{assistant_id:e,connection_id:o.id}})},onCancel:()=>h(!1)})]})}function ct({displayName:e,open:t,onOpenChange:n,onEditConnections:r,onDisable:i,disablePending:o,isMobile:s}){return s?(0,Q.jsxs)(E.Root,{open:t,onOpenChange:n,children:[(0,Q.jsx)(E.Trigger,{asChild:!0,children:(0,Q.jsx)(a,{variant:`outlined`,rightIcon:(0,Q.jsx)(q,{}),"aria-haspopup":`menu`,"aria-expanded":t,children:`Configure`})}),(0,Q.jsxs)(E.Content,{children:[(0,Q.jsx)(E.Header,{children:(0,Q.jsx)(E.Title,{children:e})}),(0,Q.jsxs)(E.Body,{children:[(0,Q.jsx)(D,{icon:W,label:`Edit connections`,onSelect:r}),(0,Q.jsx)(D,{icon:o?H:ze,label:`Disable`,onSelect:()=>{o||i()}})]})]})]}):(0,Q.jsxs)(A.Root,{open:t,onOpenChange:n,children:[(0,Q.jsx)(A.Trigger,{asChild:!0,children:(0,Q.jsx)(a,{variant:`outlined`,rightIcon:(0,Q.jsx)(q,{}),"aria-haspopup":`menu`,"aria-expanded":t,children:`Configure`})}),(0,Q.jsxs)(A.Content,{align:`end`,sideOffset:4,role:`menu`,className:`w-56 overflow-hidden p-0`,children:[(0,Q.jsx)(a,{type:`button`,role:`menuitem`,variant:`ghost`,onClick:r,className:`w-full justify-start rounded-none`,leftIcon:(0,Q.jsx)(W,{"aria-hidden":!0}),children:`Edit connections`}),(0,Q.jsx)(a,{type:`button`,role:`menuitem`,variant:`dangerGhost`,onClick:i,disabled:o,className:`w-full justify-start rounded-none`,leftIcon:o?(0,Q.jsx)(H,{className:`animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(ze,{"aria-hidden":!0}),children:`Disable`})]})]})}var lt=[{value:`none`,label:`None`},{value:`oauth`,label:`OAuth`},{value:`bearer`,label:`Bearer Token`},{value:`api-key`,label:`API Key`}],ut=[{value:`sse`,label:`SSE`},{value:`streamable-http`,label:`Streamable HTTP`},{value:`stdio`,label:`Stdio (command)`}];function dt({open:e,onClose:t,onAdd:n,isPending:r}){let[i,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(`sse`),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(`none`),[_,v]=(0,Z.useState)(``),[y,b]=(0,Z.useState)(`X-API-Key`),[x,S]=(0,Z.useState)(``),C=(0,Z.useCallback)(()=>{o(``),c(`sse`),u(``),f(``),m(``),g(`none`),v(``),b(`X-API-Key`),S(``)},[]),w=(0,Z.useCallback)(()=>{r||(C(),t())},[r,C,t]),T=(0,Z.useCallback)(()=>{let e=i.trim();if(!e)return;let t={name:e,transportType:s};if(s===`stdio`){let e=d.trim();if(!e)return;t.command=e;let n=p.trim();n&&(t.args=n.split(/\s+/))}else{let e=l.trim();if(!e)return;t.url=e,h===`bearer`&&_.trim()?t.headers={Authorization:`Bearer ${_.trim()}`}:h===`api-key`&&y.trim()&&x.trim()?t.headers={[y.trim()]:x.trim()}:h===`oauth`&&(t.autoAuth=!0)}n(t)},[i,s,l,d,p,h,_,y,x,n]),E=s===`stdio`,D=i.trim()&&(E?d.trim():l.trim());return(0,Q.jsx)(F.Root,{open:e,onOpenChange:e=>{e||w()},children:(0,Q.jsxs)(F.Content,{size:`md`,children:[(0,Q.jsxs)(F.Header,{children:[(0,Q.jsx)(F.Title,{icon:Xe,children:`Add MCP Server`}),(0,Q.jsx)(F.Description,{children:`Connect to a Model Context Protocol server to extend available tools.`})]}),(0,Q.jsx)(F.Body,{children:(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-name`,children:`Server name`}),(0,Q.jsx)(j,{id:`mcp-name`,type:`text`,value:i,onChange:e=>o(e.target.value),placeholder:`my-server`,fullWidth:!0,autoFocus:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-transport`,children:`Transport`}),(0,Q.jsx)(`select`,{id:`mcp-transport`,value:s,onChange:e=>c(e.target.value),className:`w-full rounded-md border border-[var(--border-element)] bg-[var(--surface-lift)] px-3 py-1.5 text-body-medium-default text-[var(--content-default)] outline-none focus:ring-2 focus:ring-[var(--ring)]`,children:ut.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),E?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-command`,children:`Command`}),(0,Q.jsx)(j,{id:`mcp-command`,type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`npx -y @modelcontextprotocol/server-example`,fullWidth:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-args`,children:`Arguments (space-separated)`}),(0,Q.jsx)(j,{id:`mcp-args`,type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`--port 3000`,fullWidth:!0})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-url`,children:`Server URL`}),(0,Q.jsx)(j,{id:`mcp-url`,type:`url`,value:l,onChange:e=>u(e.target.value),placeholder:`https://example.com/mcp`,fullWidth:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-auth`,children:`Authentication`}),(0,Q.jsx)(`select`,{id:`mcp-auth`,value:h,onChange:e=>g(e.target.value),className:`w-full rounded-md border border-[var(--border-element)] bg-[var(--surface-lift)] px-3 py-1.5 text-body-medium-default text-[var(--content-default)] outline-none focus:ring-2 focus:ring-[var(--ring)]`,children:lt.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),h===`oauth`?(0,Q.jsx)(`p`,{className:`rounded-md border border-[var(--border-element)] bg-[var(--surface-base)] px-3 py-2 text-body-small-default text-[var(--content-tertiary)]`,children:`OAuth credentials will be configured through a browser-based authorization flow after the server is added.`}):null,h===`bearer`?(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-bearer`,children:`Bearer token`}),(0,Q.jsx)(j,{id:`mcp-bearer`,type:`password`,value:_,onChange:e=>v(e.target.value),placeholder:`tok_...`,fullWidth:!0})]}):null,h===`api-key`?(0,Q.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-apikey-header`,children:`Header name`}),(0,Q.jsx)(j,{id:`mcp-apikey-header`,type:`text`,value:y,onChange:e=>b(e.target.value),placeholder:`X-API-Key`,fullWidth:!0})]}),(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-apikey-value`,children:`API key`}),(0,Q.jsx)(j,{id:`mcp-apikey-value`,type:`password`,value:x,onChange:e=>S(e.target.value),placeholder:`sk_...`,fullWidth:!0})]})]}):null]})]})}),(0,Q.jsxs)(F.Footer,{children:[(0,Q.jsx)(a,{variant:`ghost`,onClick:w,disabled:r,children:`Cancel`}),(0,Q.jsx)(a,{variant:`primary`,onClick:T,disabled:!D||r,children:r?`Adding...`:`Add Server`})]})]})})}async function ft(e){let{data:t,response:n}=await G.get({url:`/v1/assistants/{assistant_id}/internal/mcp/list`,path:{assistant_id:e}});if(!n?.ok)throw Error(`Failed to fetch MCP servers: ${n?.status}`);return t}async function pt(e){let{data:t,response:n}=await G.get({url:`/v1/assistants/{assistant_id}/internal/mcp/tools-summary`,path:{assistant_id:e}});if(!n?.ok)throw Error(`Failed to fetch MCP tools summary: ${n?.status}`);return t}async function mt(e,t){let{response:n}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/update`,path:{assistant_id:e},body:t});if(!n?.ok)throw Error(`Failed to update MCP server: ${n?.status}`)}async function ht(e,t){let{response:n}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/add`,path:{assistant_id:e},body:t});if(!n?.ok)throw Error(`Failed to add MCP server: ${n?.status}`)}async function gt(e,t){let{response:n}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/remove`,path:{assistant_id:e},body:{name:t}});if(!n?.ok)throw Error(`Failed to remove MCP server: ${n?.status}`)}async function _t(e,t){let{data:n,response:r}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/auth/start`,path:{assistant_id:e},body:{serverId:t}});if(!r?.ok)throw Error(`Failed to start MCP auth: ${r?.status}`);return n}async function vt(e,t){let{data:n,response:r}=await G.get({url:`/v1/assistants/{assistant_id}/internal/mcp/auth/status/${encodeURIComponent(t)}`,path:{assistant_id:e}});if(!r?.ok)throw Error(`Failed to poll MCP auth status: ${r?.status}`);return n}async function yt(e,t){let{response:n}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/auth/revoke`,path:{assistant_id:e},body:{serverId:t}});if(!n?.ok)throw Error(`Failed to revoke OAuth for ${t}: ${n?.status}`)}async function bt(e){let{response:t}=await G.post({url:`/v1/assistants/{assistant_id}/internal/mcp/reload`,path:{assistant_id:e},body:{}});if(!t?.ok)throw Error(`Failed to reload MCP servers: ${t?.status}`)}var xt={connected:{icon:B,label:`Connected`,className:`text-[var(--system-positive-strong)]`},"needs-auth":{icon:Ue,label:`Needs Auth`,className:`text-[var(--system-warning-strong)]`},disabled:{icon:Le,label:`Disabled`,className:`text-[var(--content-tertiary)]`}},St={icon:z,label:`Error`,className:`text-[var(--system-negative-strong)]`};function Ct({server:e,toolsSummary:t,onToggleEnabled:n,onRemove:r,onConfigure:i,onAuthenticate:o,onRevokeOAuth:s,isUpdating:c,isAuthenticating:l,isRevoking:u}){let[d,f]=(0,Z.useState)(!1),p=xt[e.status]??St,m=p.icon,h=(0,Z.useCallback)(t=>n(e.id,t),[n,e.id]),g=(0,Z.useCallback)(()=>r(e.id),[r,e.id]),_=(0,Z.useCallback)(()=>i(e.id),[i,e.id]),v=(0,Z.useCallback)(()=>o(e.id),[o,e.id]),y=(0,Z.useCallback)(()=>s(e.id),[s,e.id]),b=(0,Z.useCallback)(()=>f(e=>!e),[]);return(0,Q.jsx)(T.Root,{children:(0,Q.jsxs)(T.Body,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-body-medium-default text-[var(--content-default)]`,children:e.id}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-label-medium-default ${p.className}`,children:[(0,Q.jsx)(m,{className:`h-3.5 w-3.5`}),p.label]}),e.hasOAuth?(0,Q.jsx)(`span`,{className:`rounded-full bg-[var(--surface-lift)] px-2 py-0.5 text-label-small-default text-[var(--content-secondary)]`,children:`OAuth`}):null]}),(0,Q.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-body-small-default text-[var(--content-tertiary)]`,children:[(0,Q.jsx)(`span`,{children:e.transport.type}),t?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,Q.jsxs)(`span`,{children:[t.toolCount,` `,t.toolCount===1?`tool`:`tools`]}),(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,Q.jsxs)(`span`,{children:[`~`,t.estimatedTokens.toLocaleString(),` tokens`]})]}):null]})]})}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[c||l?(0,Q.jsx)(H,{className:`h-4 w-4 animate-spin text-[var(--content-tertiary)]`}):null,e.status===`needs-auth`&&e.transport.type!==`stdio`&&!e.hasOAuth?(0,Q.jsx)(a,{variant:`ghost`,size:`compact`,leftIcon:(0,Q.jsx)(U,{}),onClick:v,disabled:l,children:l?`Authenticating...`:`Authenticate`}):null,e.hasOAuth?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(a,{variant:`ghost`,size:`compact`,leftIcon:(0,Q.jsx)(te,{}),onClick:v,disabled:l,tooltip:`Re-authenticate OAuth`,children:`Re-auth`}),(0,Q.jsx)(a,{variant:`dangerGhost`,size:`compact`,leftIcon:(0,Q.jsx)(Re,{}),onClick:y,disabled:u,tooltip:`Revoke OAuth credentials`,children:u?`Revoking...`:`Revoke`})]}):null,(0,Q.jsx)(M,{checked:e.enabled,onChange:h,disabled:c,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.id}`}),(0,Q.jsx)(a,{variant:`ghost`,size:`compact`,onClick:_,tooltip:`Configure`,children:`Configure`}),(0,Q.jsx)(a,{variant:`dangerGhost`,size:`compact`,iconOnly:(0,Q.jsx)(J,{}),onClick:g,tooltip:`Remove server`,"aria-label":`Remove ${e.id}`})]})]}),t&&t.tools.length>0?(0,Q.jsxs)(`div`,{className:`mt-3 border-t border-[var(--border-base)] pt-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:b,className:`flex w-full cursor-pointer items-center gap-1 text-body-small-default text-[var(--content-secondary)] hover:text-[var(--content-default)]`,children:[d?(0,Q.jsx)(q,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(R,{className:`h-3.5 w-3.5`}),t.toolCount,` registered `,t.toolCount===1?`tool`:`tools`]}),d?(0,Q.jsx)(`div`,{className:`mt-2 max-h-60 overflow-y-auto`,children:t.tools.map(e=>(0,Q.jsx)(P,{title:e.name,subtitle:e.description||void 0,trailing:(0,Q.jsxs)(`span`,{className:`whitespace-nowrap text-body-small-default text-[var(--content-secondary)]`,children:[`~`,e.estimatedTokens.toLocaleString(),` tok`]})},e.name))}):null]}):null]})})}var wt=[{value:`none`,label:`None`},{value:`bearer`,label:`Bearer Token`},{value:`api-key`,label:`API Key`}],Tt=[`low`,`medium`,`high`];function Et({server:e,toolsSummary:t,onClose:n,onSave:r,isPending:i}){let[o,s]=(0,Z.useState)(`medium`),[c,l]=(0,Z.useState)(`none`),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(`X-API-Key`),[m,h]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{e&&(s(e.defaultRiskLevel),l(e.authType),d(``),p(e.authHeaderName??`X-API-Key`),h(``))},[e]);let g=(0,Z.useCallback)(()=>{if(!e)return;let t=c!==e.authType,n=c===`bearer`&&u.trim()!==``,i=c===`api-key`&&f.trim()!==``&&m.trim()!==``,a=t||n||i,s;s=a?c===`none`?null:c===`bearer`&&u.trim()?{Authorization:`Bearer ${u.trim()}`}:c===`api-key`&&f.trim()&&m.trim()?{[f.trim()]:m.trim()}:void 0:void 0,r(e.id,{name:e.id,defaultRiskLevel:o,...s===void 0?{}:{headers:s}})},[e,o,c,u,f,m,r]),_=(0,Z.useCallback)(()=>{i||n()},[i,n]);return e?(0,Q.jsx)(F.Root,{open:!!e,onOpenChange:e=>{e||_()},children:(0,Q.jsxs)(F.Content,{size:`lg`,children:[(0,Q.jsxs)(F.Header,{children:[(0,Q.jsx)(F.Title,{icon:Xe,children:e.id}),(0,Q.jsxs)(F.Description,{children:[e.transport.type,` transport · `,e.status]})]}),(0,Q.jsx)(F.Body,{children:(0,Q.jsxs)(`div`,{className:`space-y-5`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-risk`,children:`Default risk level`}),(0,Q.jsx)(`select`,{id:`mcp-risk`,value:o,onChange:e=>s(e.target.value),className:`w-full rounded-md border border-[var(--border-element)] bg-[var(--surface-lift)] px-3 py-1.5 text-body-medium-default text-[var(--content-default)] outline-none focus:ring-2 focus:ring-[var(--ring)]`,children:Tt.map(e=>(0,Q.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),e.transport.type===`stdio`?null:(0,Q.jsxs)(Q.Fragment,{children:[e.hasOAuth?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-[var(--border-element)] bg-[var(--surface-base)] px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`text-body-small-default text-[var(--content-secondary)]`,children:`Authentication`}),(0,Q.jsx)(`span`,{className:`rounded-full bg-[var(--surface-lift)] px-2 py-0.5 text-label-small-default text-[var(--content-default)]`,children:`OAuth`}),(0,Q.jsx)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`— managed via OAuth flow`})]}):null,e.hasOAuth?null:(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-detail-auth`,children:`Authentication`}),(0,Q.jsx)(`select`,{id:`mcp-detail-auth`,value:c,onChange:e=>l(e.target.value),className:`w-full rounded-md border border-[var(--border-element)] bg-[var(--surface-lift)] px-3 py-1.5 text-body-medium-default text-[var(--content-default)] outline-none focus:ring-2 focus:ring-[var(--ring)]`,children:wt.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),c===`bearer`&&!e.hasOAuth?(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-detail-bearer`,children:`Bearer token`}),(0,Q.jsx)(j,{id:`mcp-detail-bearer`,type:`password`,value:u,onChange:e=>d(e.target.value),placeholder:e.hasStaticAuth&&e.authType===`bearer`?`•••••••• (leave blank to keep current)`:`tok_...`,fullWidth:!0})]}):null,c===`api-key`&&!e.hasOAuth?(0,Q.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-detail-apikey-header`,children:`Header name`}),(0,Q.jsx)(j,{id:`mcp-detail-apikey-header`,type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`X-API-Key`,fullWidth:!0})]}),(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-body-small-default text-[var(--content-secondary)]`,htmlFor:`mcp-detail-apikey-value`,children:`API key`}),(0,Q.jsx)(j,{id:`mcp-detail-apikey-value`,type:`password`,value:m,onChange:e=>h(e.target.value),placeholder:e.hasStaticAuth&&e.authType===`api-key`?`•••••••• (leave blank to keep current)`:`sk_...`,fullWidth:!0})]})]}):null]}),t&&t.tools.length>0?(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`h3`,{className:`text-body-medium-default text-[var(--content-default)]`,children:[`Registered tools (`,t.toolCount,`)`]}),(0,Q.jsxs)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:[`Total estimated token overhead: ~`,t.estimatedTokens.toLocaleString(),` tokens`]}),(0,Q.jsx)(`div`,{className:`max-h-64 overflow-y-auto rounded-lg border border-[var(--border-base)]`,children:(0,Q.jsxs)(`table`,{className:`w-full text-body-small-default`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`border-b border-[var(--border-base)] bg-[var(--surface-base)]`,children:[(0,Q.jsx)(`th`,{className:`px-3 py-2 text-left font-medium text-[var(--content-secondary)]`,children:`Tool`}),(0,Q.jsx)(`th`,{className:`px-3 py-2 text-left font-medium text-[var(--content-secondary)]`,children:`Description`}),(0,Q.jsx)(`th`,{className:`px-3 py-2 text-right font-medium text-[var(--content-secondary)]`,children:`Tokens`})]})}),(0,Q.jsx)(`tbody`,{children:t.tools.map(e=>(0,Q.jsxs)(`tr`,{className:`border-b border-[var(--border-base)] last:border-b-0`,children:[(0,Q.jsx)(`td`,{className:`px-3 py-2 font-medium text-[var(--content-default)]`,children:e.name}),(0,Q.jsx)(`td`,{className:`max-w-xs truncate px-3 py-2 text-[var(--content-tertiary)]`,children:e.description||`—`}),(0,Q.jsxs)(`td`,{className:`px-3 py-2 text-right text-[var(--content-tertiary)]`,children:[`~`,e.estimatedTokens.toLocaleString()]})]},e.name))})]})})]}):null]})}),(0,Q.jsxs)(F.Footer,{children:[(0,Q.jsx)(a,{variant:`ghost`,onClick:_,disabled:i,children:`Cancel`}),(0,Q.jsx)(a,{variant:`primary`,onClick:g,disabled:i,children:i?`Saving...`:`Save`})]})]})}):null}var Dt=`mcp-servers`,Ot=`mcp-tools-summary`,kt=`Help me set up an MCP server to extend you with external tools.`;function At(){let e=Ge(),t=p(),n=o(),r=be.use.mcpAddServer(),i=be.use.hasHydrated(),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(new Set),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(null),[D,k]=(0,Z.useState)(null),{data:A,isLoading:j,isError:M}=S({queryKey:[Dt,e],queryFn:()=>ft(e)}),{data:N}=S({queryKey:[Ot,e],queryFn:()=>pt(e)}),P=(0,Z.useCallback)(()=>{t.invalidateQueries({queryKey:[Dt,e]}),t.invalidateQueries({queryKey:[Ot,e]})},[t,e]),F=(0,Z.useMemo)(()=>{let e=new Map;if(N)for(let t of N.servers)e.set(t.serverId,t);return e},[N]),L=(0,Z.useMemo)(()=>!l||!A?null:A.servers.find(e=>e.id===l)??null,[l,A]),ee=(0,Z.useCallback)(async(t,n)=>{h(e=>new Set(e).add(t));try{await mt(e,{name:t,enabled:n}),P()}catch{I.error(`Failed to ${n?`enable`:`disable`} ${t}`)}finally{h(e=>{let n=new Set(e);return n.delete(t),n})}},[e,P]),R=(0,Z.useCallback)(async()=>{if(d){y(!0);try{await gt(e,d),P(),I.success(`Removed ${d}`),f(null)}catch{I.error(`Failed to remove ${d}`)}finally{y(!1)}}},[d,e,P]),z=(0,Z.useCallback)(async t=>{E(t);let n;try{n=await _t(e,t)}catch{I.error(`Failed to start authentication for ${t}`),E(null);return}try{if(n.already_authenticated){I.success(`${t} is already authenticated`),P();return}window.open(n.auth_url,`_blank`,`noopener,noreferrer`);for(let n=0;n<60;n++){await new Promise(e=>setTimeout(e,3e3));let n=await vt(e,t);if(n.status===`complete`){I.success(`${t} authenticated successfully`),P();return}if(n.status===`error`){I.error(n.error??`Authentication failed for ${t}`);return}}I.error(`Authentication timed out for ${t}`)}catch{I.error(`Authentication polling failed for ${t}`)}finally{E(null),P()}},[e,P]),B=(0,Z.useCallback)(async t=>{k(t);try{await yt(e,t),P(),I.success(`OAuth credentials revoked for ${t}`)}catch{I.error(`Failed to revoke OAuth for ${t}`)}finally{k(null)}},[e,P]),V=(0,Z.useCallback)(async t=>{let n=t.autoAuth?window.open(`about:blank`,`_blank`,`noopener`):null;_(!0);try{await ht(e,t),P(),I.success(`Added ${t.name}`),c(!1)}catch{I.error(`Failed to add ${t.name}`),n?.close(),_(!1);return}if(_(!1),t.autoAuth){E(t.name);try{let r=await _t(e,t.name);if(r.already_authenticated){n?.close(),I.success(`${t.name} is already authenticated`),P();return}n?n.location.href=r.auth_url:window.open(r.auth_url,`_blank`,`noopener,noreferrer`);for(let n=0;n<60;n++){await new Promise(e=>setTimeout(e,3e3));let n=await vt(e,t.name);if(n.status===`complete`){I.success(`${t.name} authenticated successfully`),P();return}if(n.status===`error`){I.error(n.error??`Authentication failed for ${t.name}`);return}}I.error(`Authentication timed out for ${t.name}`)}catch{n?.close(),I.error(`Failed to start authentication for ${t.name}`)}finally{E(null),P()}}},[e,P]),U=(0,Z.useCallback)(async(t,n)=>{x(!0);try{await mt(e,n),P(),I.success(`Updated ${t}`),u(null)}catch{I.error(`Failed to update ${t}`)}finally{x(!1)}},[e,P]),W=(0,Z.useCallback)(async()=>{w(!0);try{await bt(e),P(),I.success(`MCP servers reloaded`)}catch{I.error(`Failed to reload MCP servers`)}finally{w(!1)}},[e,P]),ne=(0,Z.useCallback)(()=>{r?c(!0):Ae(n,{prompt:kt})},[r,n]),re=A?.servers??[];return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-title-small text-[var(--content-default)]`,children:`MCP Servers`}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-body-small-default text-[var(--content-tertiary)]`,children:`Manage Model Context Protocol server connections and their registered tools.`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(a,{variant:`ghost`,size:`compact`,iconOnly:(0,Q.jsx)(te,{className:C?`animate-spin`:``}),onClick:W,disabled:C,tooltip:`Reload all servers`,"aria-label":`Reload MCP servers`}),r?(0,Q.jsx)(a,{variant:`primary`,size:`compact`,leftIcon:(0,Q.jsx)(X,{}),onClick:()=>c(!0),children:`Add Server`}):null]})]}),N?(0,Q.jsxs)(`div`,{className:`flex gap-4 text-body-small-default text-[var(--content-tertiary)]`,children:[(0,Q.jsxs)(`span`,{children:[N.totalToolCount,` total `,N.totalToolCount===1?`tool`:`tools`]}),(0,Q.jsxs)(`span`,{children:[`~`,N.totalEstimatedTokens.toLocaleString(),` total tokens`]})]}):null,j?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,Q.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,Q.jsx)(`span`,{children:`Loading MCP servers...`})]}):M?(0,Q.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Failed to load MCP servers. Check that an assistant is running.`}):re.length===0?(0,Q.jsxs)(`button`,{type:`button`,onClick:ne,disabled:!i,className:`flex w-full flex-col items-center gap-2 rounded-lg border border-dashed border-[var(--border-element)] px-4 py-12 text-center transition-colors hover:border-[var(--border-active)] hover:bg-[var(--surface-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)] disabled:pointer-events-none`,children:[(0,Q.jsx)(Xe,{className:`h-6 w-6 text-[var(--content-disabled)]`}),(0,Q.jsx)(`p`,{className:`text-body-medium-default text-[var(--content-default)]`,children:`No MCP Servers`}),(0,Q.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:r?`Add an MCP server to extend your assistant with external tools.`:`Chat with your assistant to set up an MCP server.`})]}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:re.map(e=>(0,Q.jsx)(Ct,{server:e,toolsSummary:F.get(e.id),onToggleEnabled:ee,onRemove:f,onConfigure:u,onAuthenticate:z,onRevokeOAuth:B,isUpdating:m.has(e.id),isAuthenticating:T===e.id,isRevoking:D===e.id},e.id))}),r?(0,Q.jsx)(dt,{open:s,onClose:()=>c(!1),onAdd:V,isPending:g}):null,(0,Q.jsx)(Et,{server:L,toolsSummary:l?F.get(l):void 0,onClose:()=>u(null),onSave:U,isPending:b}),(0,Q.jsx)(O,{open:!!d,title:`Remove MCP Server`,message:`Are you sure you want to remove "${d}"? This will disconnect all tools provided by this server.`,confirmLabel:`Remove`,destructive:!0,isPending:v,onConfirm:R,onCancel:()=>f(null)})]})}function jt(){return(0,Q.jsx)(At,{})}function Mt(e,t){let[n,r]=(0,Z.useState)({platformAssistantId:null,isLoading:!1,error:null});return(0,Z.useEffect)(()=>{if(!t||!e){r({platformAssistantId:null,isLoading:!1,error:null});return}let n=!0;return r({platformAssistantId:null,isLoading:!0,error:null}),he(e).then(e=>{n&&r({platformAssistantId:e,isLoading:!1,error:null})}).catch(e=>{n&&r({platformAssistantId:null,isLoading:!1,error:e instanceof Error?e:Error(String(e))})}),()=>{n=!1}},[e,t]),n}var Nt=`vellum:integrations:bannerDismissed`,Pt=[{value:`all`,label:`All`},{value:`enabled`,label:`Enabled`},{value:`not-enabled`,label:`Not Enabled`}];function $(e,t){return e?.find(e=>e.provider===t)??null}function Ft(e){return e===`mcp`?`mcp`:`oauth`}function It(){let[e]=s(),i=o(),a=Fe(),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!0),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(`all`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!0),[b,x]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{y(t(Nt,`false`)===`true`)},[]);let C=()=>{y(!0),n(Nt,`true`)};(0,Z.useEffect)(()=>{let e=!0;return(async()=>{try{let t=await _e();e&&t.ok&&l(t.data)}catch(e){r(e,{context:`integrations.getAssistant`})}finally{e&&d(!1)}})(),()=>{e=!1}},[]);let{platformAssistantId:w,isLoading:T}=Mt(c?.id,a===`full`),{data:E,isLoading:D,isError:O}=S({...de({path:{assistant_id:c?.id??``}}),select:e=>e.providers,enabled:!!c}),{data:M,isLoading:N}=S({...K({path:{assistant_id:w??``}}),enabled:!!w&&a===`full`});(0,Z.useEffect)(()=>{let t=e.get(`oauth_status`);if(!t)return;let n=e.get(`oauth_provider`),r=n?n.charAt(0).toUpperCase()+n.slice(1):null;if(t===`connected`)I.success(r?`${r} account connected successfully.`:`Account connected successfully.`);else if(t===`error`){let t=e.get(`oauth_code`)??`unknown`;I.error({denied:`Authorization was denied. Please try again.`,state_invalid:`Authorization state was invalid. Please try again.`,state_expired:`Authorization expired. Please try again.`,exchange_failed:`Failed to complete authorization. Please try again.`,identity_failed:`Failed to verify account identity. Please try again.`}[t]??(r?`Failed to connect ${r}.`:`Failed to connect. Please try again.`))}i(ve.settings.integrations,{replace:!0})},[e,i]);let P=(0,Z.useMemo)(()=>E?.filter(e=>e.supports_managed_mode)??[],[E]),F=(0,Z.useMemo)(()=>{let e=f.trim().toLowerCase(),t=P.filter(t=>{if(!e)return!0;let n=(t.display_name??t.provider_key).toLowerCase(),r=(t.description??``).toLowerCase();return n.includes(e)||r.includes(e)});return m!==`all`&&(t=t.filter(e=>{let t=!!$(M,e.provider_key)?.connected;return m===`enabled`?t:!t})),[...t].sort((e,t)=>{let n=!!$(M,e.provider_key)?.connected;if(n!==!!$(M,t.provider_key)?.connected)return n?-1:1;let r=(e.display_name??e.provider_key).toLowerCase(),i=(t.display_name??t.provider_key).toLowerCase();return r.localeCompare(i)})},[P,M,f,m]),L=u||D||N||T,ee=Pt.find(e=>e.value===m)?.label??`All`,R=(()=>{if(f.trim())return`No integrations matched`;switch(m){case`enabled`:return`No Enabled Integrations`;case`not-enabled`:return`All Integrations Are Enabled`;default:return`No Integrations Available`}})(),z=(()=>{if(f.trim())return`No integrations matched "${f.trim()}"`;switch(m){case`enabled`:return`Connect an integration to get started.`;case`not-enabled`:return`All available integrations have been connected.`;default:return`Check your connection and try again.`}})(),B=(0,Z.useMemo)(()=>b?P.find(e=>e.provider_key===b)??null:null,[P,b]);return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[!v&&(0,Q.jsxs)(k,{tone:`info`,icon:(0,Q.jsx)(ne,{className:`h-3.5 w-3.5`}),onDismiss:C,children:[(0,Q.jsx)(`span`,{className:`text-body-medium-default`,children:`Tip:`}),` You can enable integrations by mentioning them in chat.`]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(j,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`Search Integrations`,"aria-label":`Search integrations`,leftIcon:(0,Q.jsx)(je,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),fullWidth:!0,wrapperClassName:`flex-1`}),(0,Q.jsxs)(A.Root,{open:g,onOpenChange:_,children:[(0,Q.jsx)(A.Trigger,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,"aria-haspopup":`listbox`,"aria-expanded":g,className:`flex w-36 cursor-pointer items-center justify-between gap-2 rounded-md border border-[var(--border-element)] bg-[var(--surface-lift)] px-3 py-1.5 text-body-medium-lighter text-[var(--content-default)] transition-colors hover:bg-[var(--ghost-hover)]`,children:[(0,Q.jsx)(`span`,{children:ee}),(0,Q.jsx)(q,{className:`h-3.5 w-3.5`})]})}),(0,Q.jsx)(A.Content,{align:`end`,sideOffset:4,className:`w-36 overflow-hidden p-0`,children:(0,Q.jsx)(`div`,{role:`listbox`,children:Pt.map(e=>{let t=e.value===m;return(0,Q.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":t,onClick:()=>{h(e.value),_(!1)},className:`flex w-full cursor-pointer items-center px-3 py-1.5 text-left hover:bg-[var(--ghost-hover)] ${t?`text-body-medium-default text-[var(--content-default)]`:`text-body-medium-lighter text-[var(--content-default)]`}`,children:e.label},e.value)})})})]})]}),(0,Q.jsx)(`div`,{children:L?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,Q.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,Q.jsx)(`span`,{children:`Loading...`})]}):O?(0,Q.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Failed to load integrations. Please try again.`}):c?F.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-[var(--border-element)] px-4 py-12 text-center`,children:[(0,Q.jsx)(je,{className:`h-6 w-6 text-[var(--content-disabled)]`}),(0,Q.jsx)(`p`,{className:`text-body-medium-default text-[var(--content-default)]`,children:R}),(0,Q.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:z})]}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:F.map(e=>(0,Q.jsx)(st,{platformAssistantId:w??c.id,providerKey:e.provider_key,displayName:e.display_name??e.provider_key,description:e.description,logoUrl:e.logo_url,connection:$(M,e.provider_key),platformGate:a,onConfigure:()=>x(e.provider_key)},e.provider_key))}):(0,Q.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`No assistant found. Hatch an assistant to connect integrations.`})}),B&&c&&(0,Q.jsx)(at,{assistantId:c.id,platformAssistantId:w??c.id,providerKey:B.provider_key,displayName:B.display_name??B.provider_key,description:B.description,logoUrl:B.logo_url,platformGate:a,onClose:()=>x(null)})]})}function Lt(){let[e,t]=s(),n=Ft(e.get(`tab`));return(0,Q.jsx)(`div`,{className:`space-y-6`,children:(0,Q.jsxs)(N.Root,{value:n,onValueChange:n=>{let r=Ft(n),i=new URLSearchParams(e);r===`mcp`?i.set(`tab`,`mcp`):i.delete(`tab`),t(i,{replace:!0})},children:[(0,Q.jsxs)(N.List,{children:[(0,Q.jsx)(N.Trigger,{value:`oauth`,children:`OAuth`}),(0,Q.jsx)(N.Trigger,{value:`mcp`,children:`MCP`})]}),(0,Q.jsx)(N.Panel,{value:`oauth`,className:`pt-4`,children:(0,Q.jsx)(Z.Suspense,{children:(0,Q.jsx)(It,{})})}),(0,Q.jsx)(N.Panel,{value:`mcp`,className:`pt-4`,children:(0,Q.jsx)(jt,{})})]})})}export{Lt as IntegrationsPage};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{i as n,n as r,u as i}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as a}from"./jsx-runtime-CVSDxk6A.js";import{t as o}from"./cn-DvW5mxZR.js";import{t as s}from"./typography-BscuIPxA.js";import"./src-CK6bncSg.js";import{a as c}from"./routes-DVqkwUEe.js";import{n as l}from"./use-is-mobile-Cy10kl9u.js";import{t as u}from"./assistant-identity-store-CKjnoLSp.js";import{t as d}from"./assistant-feature-flag-store-Dl92XRsM.js";import{Qt as f}from"./index-BIDC22lX.js";import{t as p}from"./page-shell-cEGpH3P5.js";var m=e(t(),1),h=a(),g=[{label:`Identity`,to:c.identity},{label:`Skills`,to:c.skills},{label:`Workspace`,to:c.workspace},{label:`Contacts`,to:c.contacts.root}],_={label:`Plugins`,to:c.plugins};function v(){let e=u.use.name(),t=d.use.hasHydrated(),a=d.use.externalPlugins(),{pathname:c}=i(),v=l(),y=f.use.setTopBarCenter();(0,m.useEffect)(()=>(y(v?(0,h.jsxs)(s,{variant:`body-medium-default`,className:`truncate text-[var(--content-secondary)]`,children:[`About `,e||`Assistant`]}):null),()=>{y(null)}),[v,e,y]);let b=t&&a?[g[0],_,...g.slice(1)]:g;return(0,h.jsxs)(p,{children:[(0,h.jsxs)(`h1`,{className:`mb-4 shrink-0 text-title-large text-[var(--content-default)] max-md:hidden`,children:[`About `,e||`Assistant`]}),(0,h.jsx)(`nav`,{className:`mb-4 flex shrink-0 items-center overflow-x-auto border-b border-[var(--border-base)]`,style:{scrollbarWidth:`none`,WebkitOverflowScrolling:`touch`},"aria-label":`About assistant sections`,children:b.map(({label:e,to:t})=>{let n=c===t||c.startsWith(t+`/`);return(0,h.jsx)(r,{to:t,className:o(`relative -mb-px inline-flex cursor-pointer items-center gap-1.5 border-b-2 border-transparent bg-transparent px-2.5 py-[7px]`,`text-body-medium-default whitespace-nowrap`,`text-[var(--content-secondary)] transition-colors`,`outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)] focus-visible:ring-offset-0`,`hover:bg-[var(--surface-hover)] hover:text-[var(--content-default)]`,n&&`border-[var(--border-active)] text-[var(--primary-active)]`,n&&`hover:bg-transparent`),children:e},t)})}),(0,h.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:(0,h.jsx)(n,{})})]})}export{v as IntelligenceLayout};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{i as n,n as r,u as i}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as a}from"./jsx-runtime-CVSDxk6A.js";import{t as o}from"./cn-DvW5mxZR.js";import{t as s}from"./typography-BscuIPxA.js";import"./src-CK6bncSg.js";import{a as c}from"./routes-DVqkwUEe.js";import{n as l}from"./use-is-mobile-Cy10kl9u.js";import{t as u}from"./assistant-identity-store-CKjnoLSp.js";import{t as d}from"./assistant-feature-flag-store-Dl92XRsM.js";import{Qt as f}from"./index-PRnvH2Y1.js";import{t as p}from"./page-shell-cEGpH3P5.js";var m=e(t(),1),h=a(),g=[{label:`Identity`,to:c.identity},{label:`Skills`,to:c.skills},{label:`Workspace`,to:c.workspace},{label:`Contacts`,to:c.contacts.root}],_={label:`Plugins`,to:c.plugins};function v(){let e=u.use.name(),t=d.use.hasHydrated(),a=d.use.externalPlugins(),{pathname:c}=i(),v=l(),y=f.use.setTopBarCenter();(0,m.useEffect)(()=>(y(v?(0,h.jsxs)(s,{variant:`body-medium-default`,className:`truncate text-[var(--content-secondary)]`,children:[`About `,e||`Assistant`]}):null),()=>{y(null)}),[v,e,y]);let b=t&&a?[g[0],_,...g.slice(1)]:g;return(0,h.jsxs)(p,{children:[(0,h.jsxs)(`h1`,{className:`mb-4 shrink-0 text-title-large text-[var(--content-default)] max-md:hidden`,children:[`About `,e||`Assistant`]}),(0,h.jsx)(`nav`,{className:`mb-4 flex shrink-0 items-center overflow-x-auto border-b border-[var(--border-base)]`,style:{scrollbarWidth:`none`,WebkitOverflowScrolling:`touch`},"aria-label":`About assistant sections`,children:b.map(({label:e,to:t})=>{let n=c===t||c.startsWith(t+`/`);return(0,h.jsx)(r,{to:t,className:o(`relative -mb-px inline-flex cursor-pointer items-center gap-1.5 border-b-2 border-transparent bg-transparent px-2.5 py-[7px]`,`text-body-medium-default whitespace-nowrap`,`text-[var(--content-secondary)] transition-colors`,`outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)] focus-visible:ring-offset-0`,`hover:bg-[var(--surface-hover)] hover:text-[var(--content-default)]`,n&&`border-[var(--border-active)] text-[var(--primary-active)]`,n&&`hover:bg-transparent`),children:e},t)})}),(0,h.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:(0,h.jsx)(n,{})})]})}export{v as IntelligenceLayout};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{t as n}from"./button-D7s2Q_uG.js";import{r}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as i}from"./jsx-runtime-CVSDxk6A.js";import{t as a}from"./card-BibIM9x3.js";import{t as o}from"./notice-CqRgVmeL.js";import{t as s}from"./shortcut-keys-vM6sNj7W.js";import{t as c}from"./is-electron-C_ZTVhv8.js";import{t as l}from"./x-KVxA2ZL0.js";import{a as u}from"./routes-DVqkwUEe.js";import{Zr as d}from"./index-BIDC22lX.js";var f=e(t(),1);async function p(){if(!c())return[];let e=window.vellum;return e?.hotkeys?e.hotkeys.get():[]}async function m(e,t){if(!c())return;let n=window.vellum;n?.hotkeys&&await n.hotkeys.set(e,t)}function h(e){if(!c())return()=>{};let t=window.vellum;return t?.hotkeys?t.hotkeys.onChange(e):()=>{}}var g={ArrowUp:`Up`,ArrowDown:`Down`,ArrowLeft:`Left`,ArrowRight:`Right`,Enter:`Return`,NumpadEnter:`Return`,Space:`Space`,Tab:`Tab`,Escape:`Escape`,Backspace:`Backspace`,Delete:`Delete`,Insert:`Insert`,Home:`Home`,End:`End`,PageUp:`PageUp`,PageDown:`PageDown`,Minus:`-`,Equal:`=`,BracketLeft:`[`,BracketRight:`]`,Backslash:`\\`,Semicolon:`;`,Quote:`'`,Backquote:"`",Comma:`,`,Period:`.`,Slash:`/`},_=new Set([`MetaLeft`,`MetaRight`,`ControlLeft`,`ControlRight`,`AltLeft`,`AltRight`,`ShiftLeft`,`ShiftRight`]),v=e=>{let t=e.code;return _.has(t)?null:/^Key[A-Z]$/.test(t)?t.slice(3):/^Digit[0-9]$/.test(t)?t.slice(5):/^Numpad[0-9]$/.test(t)?`num${t.slice(6)}`:/^F[0-9]{1,2}$/.test(t)?t:g[t]??null},y=e=>{let t=v(e);if(t===null)return null;let n=[];return e.metaKey&&n.push(`CmdOrCtrl`),e.ctrlKey&&n.push(`Control`),e.altKey&&n.push(`Alt`),e.shiftKey&&n.push(`Shift`),[...n,t].join(`+`)},b=(e,t,n)=>n===``?null:e.find(e=>e.key!==t&&e.accelerator===n)??null,x=i(),S=[{scope:`global`,title:`Global shortcuts`,description:`Work anywhere, even when Vellum is in the background.`},{scope:`menu`,title:`App shortcuts`,description:`Work while a Vellum window is focused.`}];function C({hotkey:e,recording:t,conflictLabel:r,onStartRecording:i,onCancelRecording:a,onReset:o,onRemove:c}){let u=e.accelerator===``,f=e.override!==null;return(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-2`,children:[(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`div`,{className:`truncate text-body-medium-lighter text-[var(--content-default)]`,children:e.label}),r!==null&&(0,x.jsxs)(`div`,{className:`text-body-small-default text-[var(--system-negative-strong)]`,children:[`Already used by `,r]})]}),(0,x.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[t?(0,x.jsx)(`span`,{className:`text-body-small-default text-[var(--content-secondary)]`,children:`Recording… press a shortcut, or Esc to cancel`}):u?(0,x.jsx)(`span`,{className:`text-body-small-default italic text-[var(--content-disabled)]`,children:`Disabled`}):(0,x.jsx)(s,{accelerator:e.accelerator}),t?(0,x.jsx)(n,{variant:`ghost`,size:`compact`,onClick:a,children:`Cancel`}):(0,x.jsx)(n,{variant:`outlined`,size:`compact`,onClick:i,"aria-label":`Record shortcut for ${e.label}`,children:`Record`}),(0,x.jsx)(n,{variant:`ghost`,size:`compact`,disabled:!f,leftIcon:(0,x.jsx)(d,{className:`h-3.5 w-3.5`}),onClick:o,"aria-label":`Reset ${e.label} to default`}),(0,x.jsx)(n,{variant:`ghost`,size:`compact`,disabled:u,leftIcon:(0,x.jsx)(l,{className:`h-3.5 w-3.5`}),onClick:c,"aria-label":`Remove ${e.label} binding`})]})]})}function w(){let[e,t]=(0,f.useState)([]),[n,i]=(0,f.useState)(null),[s,l]=(0,f.useState)(null),d=(0,f.useCallback)(()=>{p().then(t)},[]);(0,f.useEffect)(()=>(d(),h(t)),[d]);let g=(0,f.useCallback)(()=>{i(null),l(null)},[]);(0,f.useEffect)(()=>{if(n===null)return;let t=t=>{if(t.preventDefault(),t.stopPropagation(),t.code===`Escape`){g();return}let r=y(t);if(r===null)return;let i=b(e,n,r);if(i!==null){l({key:n,label:i.label});return}m(n,r).then(d),g()};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[n,e,d,g]);let _=(0,f.useCallback)(e=>{l(null),i(e)},[]),v=(0,f.useCallback)(t=>{let n=b(e,t,e.find(e=>e.key===t)?.defaultAccelerator??``);if(n!==null){i(null),l({key:t,label:n.label});return}g(),m(t,null).then(d)},[e,d,g]),w=(0,f.useCallback)(e=>{g(),m(e,``).then(d)},[d,g]),T=(0,f.useMemo)(()=>S.map(t=>({...t,commands:e.filter(e=>e.rebindable&&e.scope===t.scope)})).filter(e=>e.commands.length>0),[e]);return c()?(0,x.jsxs)(`div`,{className:`space-y-4`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h2`,{className:`text-title-medium text-[var(--content-default)]`,children:`Keyboard Shortcuts`}),(0,x.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-secondary)]`,children:`Customize the shortcuts for Vellum's commands.`})]}),s!==null&&(0,x.jsxs)(o,{tone:`warning`,children:[`That shortcut is already used by `,s.label,`.`,` `,n===null?`Remove or change that binding before resetting.`:`Pick a different combination, or press Esc to cancel.`]}),T.map(e=>(0,x.jsxs)(a,{bordered:!0,children:[(0,x.jsxs)(`div`,{className:`mb-2`,children:[(0,x.jsx)(`div`,{className:`text-body-medium-emphasised text-[var(--content-default)]`,children:e.title}),(0,x.jsx)(`div`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:e.description})]}),(0,x.jsx)(`div`,{className:`divide-y divide-[var(--border-base)]`,children:e.commands.map(e=>(0,x.jsx)(C,{hotkey:e,recording:n===e.key,conflictLabel:s!==null&&s.key===e.key?s.label:null,onStartRecording:()=>_(e.key),onCancelRecording:g,onReset:()=>v(e.key),onRemove:()=>w(e.key)},e.key))})]},e.scope))]}):(0,x.jsx)(r,{replace:!0,to:u.settings.general})}export{w as KeyboardShortcutsPage};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{t as n}from"./button-D7s2Q_uG.js";import{r}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as i}from"./jsx-runtime-CVSDxk6A.js";import{t as a}from"./card-BibIM9x3.js";import{t as o}from"./notice-CqRgVmeL.js";import{t as s}from"./shortcut-keys-vM6sNj7W.js";import{t as c}from"./is-electron-C_ZTVhv8.js";import{t as l}from"./x-KVxA2ZL0.js";import{a as u}from"./routes-DVqkwUEe.js";import{Zr as d}from"./index-PRnvH2Y1.js";var f=e(t(),1);async function p(){if(!c())return[];let e=window.vellum;return e?.hotkeys?e.hotkeys.get():[]}async function m(e,t){if(!c())return;let n=window.vellum;n?.hotkeys&&await n.hotkeys.set(e,t)}function h(e){if(!c())return()=>{};let t=window.vellum;return t?.hotkeys?t.hotkeys.onChange(e):()=>{}}var g={ArrowUp:`Up`,ArrowDown:`Down`,ArrowLeft:`Left`,ArrowRight:`Right`,Enter:`Return`,NumpadEnter:`Return`,Space:`Space`,Tab:`Tab`,Escape:`Escape`,Backspace:`Backspace`,Delete:`Delete`,Insert:`Insert`,Home:`Home`,End:`End`,PageUp:`PageUp`,PageDown:`PageDown`,Minus:`-`,Equal:`=`,BracketLeft:`[`,BracketRight:`]`,Backslash:`\\`,Semicolon:`;`,Quote:`'`,Backquote:"`",Comma:`,`,Period:`.`,Slash:`/`},_=new Set([`MetaLeft`,`MetaRight`,`ControlLeft`,`ControlRight`,`AltLeft`,`AltRight`,`ShiftLeft`,`ShiftRight`]),v=e=>{let t=e.code;return _.has(t)?null:/^Key[A-Z]$/.test(t)?t.slice(3):/^Digit[0-9]$/.test(t)?t.slice(5):/^Numpad[0-9]$/.test(t)?`num${t.slice(6)}`:/^F[0-9]{1,2}$/.test(t)?t:g[t]??null},y=e=>{let t=v(e);if(t===null)return null;let n=[];return e.metaKey&&n.push(`CmdOrCtrl`),e.ctrlKey&&n.push(`Control`),e.altKey&&n.push(`Alt`),e.shiftKey&&n.push(`Shift`),[...n,t].join(`+`)},b=(e,t,n)=>n===``?null:e.find(e=>e.key!==t&&e.accelerator===n)??null,x=i(),S=[{scope:`global`,title:`Global shortcuts`,description:`Work anywhere, even when Vellum is in the background.`},{scope:`menu`,title:`App shortcuts`,description:`Work while a Vellum window is focused.`}];function C({hotkey:e,recording:t,conflictLabel:r,onStartRecording:i,onCancelRecording:a,onReset:o,onRemove:c}){let u=e.accelerator===``,f=e.override!==null;return(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-2`,children:[(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`div`,{className:`truncate text-body-medium-lighter text-[var(--content-default)]`,children:e.label}),r!==null&&(0,x.jsxs)(`div`,{className:`text-body-small-default text-[var(--system-negative-strong)]`,children:[`Already used by `,r]})]}),(0,x.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[t?(0,x.jsx)(`span`,{className:`text-body-small-default text-[var(--content-secondary)]`,children:`Recording… press a shortcut, or Esc to cancel`}):u?(0,x.jsx)(`span`,{className:`text-body-small-default italic text-[var(--content-disabled)]`,children:`Disabled`}):(0,x.jsx)(s,{accelerator:e.accelerator}),t?(0,x.jsx)(n,{variant:`ghost`,size:`compact`,onClick:a,children:`Cancel`}):(0,x.jsx)(n,{variant:`outlined`,size:`compact`,onClick:i,"aria-label":`Record shortcut for ${e.label}`,children:`Record`}),(0,x.jsx)(n,{variant:`ghost`,size:`compact`,disabled:!f,leftIcon:(0,x.jsx)(d,{className:`h-3.5 w-3.5`}),onClick:o,"aria-label":`Reset ${e.label} to default`}),(0,x.jsx)(n,{variant:`ghost`,size:`compact`,disabled:u,leftIcon:(0,x.jsx)(l,{className:`h-3.5 w-3.5`}),onClick:c,"aria-label":`Remove ${e.label} binding`})]})]})}function w(){let[e,t]=(0,f.useState)([]),[n,i]=(0,f.useState)(null),[s,l]=(0,f.useState)(null),d=(0,f.useCallback)(()=>{p().then(t)},[]);(0,f.useEffect)(()=>(d(),h(t)),[d]);let g=(0,f.useCallback)(()=>{i(null),l(null)},[]);(0,f.useEffect)(()=>{if(n===null)return;let t=t=>{if(t.preventDefault(),t.stopPropagation(),t.code===`Escape`){g();return}let r=y(t);if(r===null)return;let i=b(e,n,r);if(i!==null){l({key:n,label:i.label});return}m(n,r).then(d),g()};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[n,e,d,g]);let _=(0,f.useCallback)(e=>{l(null),i(e)},[]),v=(0,f.useCallback)(t=>{let n=b(e,t,e.find(e=>e.key===t)?.defaultAccelerator??``);if(n!==null){i(null),l({key:t,label:n.label});return}g(),m(t,null).then(d)},[e,d,g]),w=(0,f.useCallback)(e=>{g(),m(e,``).then(d)},[d,g]),T=(0,f.useMemo)(()=>S.map(t=>({...t,commands:e.filter(e=>e.rebindable&&e.scope===t.scope)})).filter(e=>e.commands.length>0),[e]);return c()?(0,x.jsxs)(`div`,{className:`space-y-4`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h2`,{className:`text-title-medium text-[var(--content-default)]`,children:`Keyboard Shortcuts`}),(0,x.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-secondary)]`,children:`Customize the shortcuts for Vellum's commands.`})]}),s!==null&&(0,x.jsxs)(o,{tone:`warning`,children:[`That shortcut is already used by `,s.label,`.`,` `,n===null?`Remove or change that binding before resetting.`:`Pick a different combination, or press Esc to cancel.`]}),T.map(e=>(0,x.jsxs)(a,{bordered:!0,children:[(0,x.jsxs)(`div`,{className:`mb-2`,children:[(0,x.jsx)(`div`,{className:`text-body-medium-emphasised text-[var(--content-default)]`,children:e.title}),(0,x.jsx)(`div`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:e.description})]}),(0,x.jsx)(`div`,{className:`divide-y divide-[var(--border-base)]`,children:e.commands.map(e=>(0,x.jsx)(C,{hotkey:e,recording:n===e.key,conflictLabel:s!==null&&s.key===e.key?s.label:null,onStartRecording:()=>_(e.key),onCancelRecording:g,onReset:()=>v(e.key),onRemove:()=>w(e.key)},e.key))})]},e.scope))]}):(0,x.jsx)(r,{replace:!0,to:u.settings.general})}export{w as KeyboardShortcutsPage};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{d as n,p as r}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as i}from"./jsx-runtime-CVSDxk6A.js";import"./src-CK6bncSg.js";import{n as a}from"./toast-2TW5tj1Y.js";import{t as o}from"./loader-circle-IIzBGiwm.js";import{n as s}from"./sdk.gen-1aYqVbMj.js";import{a as c}from"./routes-DVqkwUEe.js";import{a as l}from"./viewer-store-Dead64xY.js";import{_t as u,dt as d,r as f}from"./index-BIDC22lX.js";import{t as p}from"./use-active-assistant-id-C-RHQ9f6.js";var m=e(t(),1),h=i();function g(){let{appId:e}=r(),t=p(),i=n(),[g,_]=(0,m.useState)(null),[v,y]=(0,m.useState)(null),[b,x]=(0,m.useState)(!1),S=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(e)return S.current=e,_(null),y(null),s({path:{assistant_id:t,id:e},throwOnError:!0}).then(({data:n})=>{S.current===e&&(l(t,n.appId,n.html),_({appId:n.appId,dirName:n.dirName,name:n.name,html:n.html}))}).catch(t=>{S.current===e&&y(t instanceof Error?t.message:`Failed to open app`)}),()=>{S.current=null}},[t,e]);let C=(0,m.useCallback)(()=>{i(c.library.root)},[i]),w=f(),T=(0,m.useCallback)(()=>{g&&w(g)},[g,w]),E=(0,m.useCallback)(async()=>{if(!(!g||b)){x(!0);try{await u(t,g.appId,g.name),a.success(`App exported`,{description:`${g.name}.vellum`})}catch(e){a.error(`Failed to share app`,{description:e instanceof Error?e.message:void 0})}finally{x(!1)}}},[t,g,b]);return e?v?(0,h.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-4`,children:[(0,h.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:v}),(0,h.jsx)(`button`,{type:`button`,onClick:C,className:`text-body-medium-default text-[var(--primary-base)] underline`,children:`Back to Library`})]}):g?(0,h.jsx)(d,{appId:g.appId,appName:g.name,html:g.html,assistantId:t,onClose:C,onEdit:T,onShare:E,isSharing:b,enableFullscreen:!0}):(0,h.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,h.jsx)(o,{className:`h-6 w-6 animate-spin text-[var(--content-tertiary)]`})}):null}export{g as LibraryDetailPage};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{d as n,p as r}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as i}from"./jsx-runtime-CVSDxk6A.js";import"./src-CK6bncSg.js";import{n as a}from"./toast-2TW5tj1Y.js";import{t as o}from"./loader-circle-IIzBGiwm.js";import{n as s}from"./sdk.gen-1aYqVbMj.js";import{a as c}from"./routes-DVqkwUEe.js";import{a as l}from"./viewer-store-Dead64xY.js";import{_t as u,dt as d,r as f}from"./index-PRnvH2Y1.js";import{t as p}from"./use-active-assistant-id-C-RHQ9f6.js";var m=e(t(),1),h=i();function g(){let{appId:e}=r(),t=p(),i=n(),[g,_]=(0,m.useState)(null),[v,y]=(0,m.useState)(null),[b,x]=(0,m.useState)(!1),S=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(e)return S.current=e,_(null),y(null),s({path:{assistant_id:t,id:e},throwOnError:!0}).then(({data:n})=>{S.current===e&&(l(t,n.appId,n.html),_({appId:n.appId,dirName:n.dirName,name:n.name,html:n.html}))}).catch(t=>{S.current===e&&y(t instanceof Error?t.message:`Failed to open app`)}),()=>{S.current=null}},[t,e]);let C=(0,m.useCallback)(()=>{i(c.library.root)},[i]),w=f(),T=(0,m.useCallback)(()=>{g&&w(g)},[g,w]),E=(0,m.useCallback)(async()=>{if(!(!g||b)){x(!0);try{await u(t,g.appId,g.name),a.success(`App exported`,{description:`${g.name}.vellum`})}catch(e){a.error(`Failed to share app`,{description:e instanceof Error?e.message:void 0})}finally{x(!1)}}},[t,g,b]);return e?v?(0,h.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-4`,children:[(0,h.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:v}),(0,h.jsx)(`button`,{type:`button`,onClick:C,className:`text-body-medium-default text-[var(--primary-base)] underline`,children:`Back to Library`})]}):g?(0,h.jsx)(d,{appId:g.appId,appName:g.name,html:g.html,assistantId:t,onClose:C,onEdit:T,onShare:E,isSharing:b,enableFullscreen:!0}):(0,h.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,h.jsx)(o,{className:`h-6 w-6 animate-spin text-[var(--content-tertiary)]`})}):null}export{g as LibraryDetailPage};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{t as n}from"./button-D7s2Q_uG.js";import{d as r}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{n as i}from"./QueryClientProvider-DKhXIxGb.js";import{t as a}from"./useQuery-B45lW1Kk.js";import{t as o}from"./jsx-runtime-CVSDxk6A.js";import{n as s,t as c}from"./panel-item-nGTDevWP.js";import{t as l}from"./menu-C_97pis4.js";import"./src-CK6bncSg.js";import{t as u}from"./confirm-dialog-CfOXCE1N.js";import{t as d}from"./input-C8kfrq9r.js";import{n as f}from"./toast-2TW5tj1Y.js";import{t as p}from"./arrow-up-nBfZxfhi.js";import{t as m}from"./file-text-CmK9LY1p.js";import{t as h}from"./globe-DYF_lSGm.js";import{s as g,t as _}from"./sdk.gen-1aYqVbMj.js";import{C as v,n as y,t as b}from"./react-query.gen-CQLyoqYk.js";import{a as x}from"./routes-DVqkwUEe.js";import{n as S}from"./use-is-mobile-Cy10kl9u.js";import{i as C,r as w}from"./viewer-store-Dead64xY.js";import{t as T}from"./misc-BN2o2MEB.js";import{Fr as E,Ft as D,Ht as O,Ir as k,Jr as A,Ni as j,Z as M,_t as N,gt as P,ii as F,ri as I,yi as L}from"./index-BIDC22lX.js";import{t as R}from"./deploy-dialogs-C0aZYWkv.js";import{t as z}from"./use-active-assistant-id-C-RHQ9f6.js";import{t as B}from"./page-shell-cEGpH3P5.js";import{t as V}from"./format-date-CLlHK5gl.js";var H=e(t(),1),U=o();function W({app:e,isDeleting:t,onConfirm:n,onCancel:r}){return(0,U.jsx)(u,{open:e!==null,title:`Delete app`,message:e?`"${e.name}" will be permanently removed.`:``,confirmLabel:t?`Deleting…`:`Delete`,destructive:!0,onConfirm:n,onCancel:r})}function G(e){return e===1?`1 word`:`${e} words`}function K({document:e,onOpen:t}){return(0,U.jsxs)(`div`,{className:`group relative flex flex-col gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(e.surfaceId),className:T(`relative flex w-full cursor-pointer flex-col items-center justify-center gap-2 overflow-hidden rounded-xl border border-[var(--border-base)] bg-[var(--surface-base)]`,`aspect-[16/10]`,`outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)]`),children:[(0,U.jsx)(m,{size:34,className:`text-[var(--content-tertiary)]`}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:G(e.wordCount)})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(e.surfaceId),className:`flex cursor-pointer flex-col gap-0.5 px-0.5 text-left outline-none`,children:[(0,U.jsx)(`span`,{className:`truncate text-body-large-default text-[color:var(--content-emphasised)]`,children:e.title}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[color:var(--content-tertiary)]`,children:V(new Date(e.updatedAt))})]})]})}function q({fileInputRef:e,isImporting:t,onImportBundle:r,onNewConversation:i}){return(0,U.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-4 px-4 py-24`,children:[(0,U.jsx)(`input`,{ref:e,type:`file`,accept:`.vellum`,className:`hidden`,onChange:r}),(0,U.jsx)(`div`,{className:`flex h-16 w-16 items-center justify-center rounded-xl bg-[var(--surface-base)]`,children:(0,U.jsx)(L,{size:32,className:`text-[var(--content-tertiary)]`})}),(0,U.jsx)(`h2`,{className:`text-title-medium text-[var(--content-default)]`,children:`Your library is empty`}),(0,U.jsx)(`p`,{className:`max-w-md text-center text-body-medium-lighter text-[color:var(--content-tertiary)]`,children:`Ask your assistant to build something, or import a shared app`}),(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[i?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(n,{variant:`primary`,size:`regular`,onClick:i,children:`New Conversation`}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[color:var(--content-tertiary)]`,children:`or`})]}):null,(0,U.jsxs)(n,{variant:`outlined`,size:`regular`,onClick:()=>e.current?.click(),disabled:t,children:[t?(0,U.jsx)(`div`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent`}):(0,U.jsx)(E,{size:14}),(0,U.jsx)(`span`,{className:`ml-1.5`,children:`Import .vellum File`})]})]})]})}function J({app:e,assistantId:t,isPinned:n,onOpen:r,onPin:i,onDelete:a,onDeploy:o,justImported:s,onAnimationEnd:c}){let[l,u]=(0,H.useState)(!1),d=(0,H.useCallback)(()=>C(t,e.id),[t,e.id]),p=(0,H.useCallback)(async()=>{if(!l){u(!0);try{await N(t,e.id,e.name),f.success(`App exported`,{description:`${e.name}.vellum`})}catch(e){f.error(`Failed to share app`,{description:e instanceof Error?e.message:void 0})}finally{u(!1)}}},[t,e.id,e.name,l]),[m,h]=(0,H.useState)(!1),g=S();return(0,U.jsxs)(`div`,{className:T(`group relative flex flex-col gap-2`,s&&`animate-[card-entrance_400ms_ease-out]`),onAnimationEnd:s?c:void 0,children:[(0,U.jsx)(`button`,{type:`button`,onClick:()=>r(e.id),className:T(`relative w-full cursor-pointer overflow-hidden rounded-xl`,`outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)]`),children:(0,U.jsx)(M,{name:e.name,icon:e.icon,loadHtml:d})}),(0,U.jsx)(`div`,{className:T(`absolute right-2 top-2 z-20 transition-opacity`,`max-md:opacity-100`,`md:group-hover:opacity-100 md:group-focus-within:opacity-100`,m?`opacity-100`:`md:opacity-0`),children:(0,U.jsx)(Y,{appName:e.name,isPinned:n,open:m,onOpenChange:h,onPin:()=>i(e),onDelete:a?()=>a(e):void 0,onShare:p,onDeploy:o,isMobile:g})}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:`flex cursor-pointer flex-col gap-0.5 px-0.5 text-left outline-none`,children:[(0,U.jsx)(`span`,{className:`truncate text-body-large-default text-[color:var(--content-emphasised)]`,children:e.name}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[color:var(--content-tertiary)]`,children:V(new Date(e.createdAt))})]})]})}function Y({appName:e,isPinned:t,open:r,onOpenChange:i,onPin:a,onDelete:o,onShare:u,onDeploy:d,isMobile:f}){return f?(0,U.jsxs)(s.Root,{open:r,onOpenChange:i,children:[(0,U.jsx)(s.Trigger,{asChild:!0,children:(0,U.jsx)(n,{variant:`primary`,size:`compact`,iconOnly:(0,U.jsx)(j,{}),"aria-label":`App actions`,onClick:e=>e.stopPropagation()})}),(0,U.jsxs)(s.Content,{children:[(0,U.jsx)(s.Header,{className:`sr-only`,children:(0,U.jsx)(s.Title,{children:e})}),(0,U.jsxs)(s.Body,{className:`pt-0`,children:[(0,U.jsx)(c,{icon:t?F:I,label:t?`Unpin`:`Pin`,onSelect:()=>{i(!1),a()}}),u?(0,U.jsx)(c,{icon:p,label:(0,U.jsxs)(`span`,{className:`flex flex-col gap-0.5 overflow-visible whitespace-normal`,children:[(0,U.jsx)(`span`,{children:`Share`}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`Export as .vellum file`})]}),onSelect:()=>{i(!1),u()}}):null,d?(0,U.jsx)(c,{icon:h,label:(0,U.jsxs)(`span`,{className:`flex flex-col gap-0.5 overflow-visible whitespace-normal`,children:[(0,U.jsx)(`span`,{children:`Deploy to Vercel`}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`Publish as a static page`})]}),onSelect:()=>{i(!1),d()}}):null,o?(0,U.jsx)(c,{icon:k,label:`Delete`,onSelect:()=>{i(!1),o()}}):null]})]})]}):(0,U.jsxs)(l.Root,{open:r,onOpenChange:i,children:[(0,U.jsx)(l.Trigger,{asChild:!0,children:(0,U.jsx)(n,{variant:`primary`,size:`compact`,iconOnly:(0,U.jsx)(j,{}),"aria-label":`App actions`,onClick:e=>e.stopPropagation()})}),(0,U.jsxs)(l.Content,{align:`end`,sideOffset:4,children:[(0,U.jsx)(l.Item,{leftIcon:t?(0,U.jsx)(F,{size:14}):(0,U.jsx)(I,{size:14}),onSelect:()=>a(),className:`whitespace-nowrap`,children:t?`Unpin`:`Pin`}),u?(0,U.jsx)(l.Item,{leftIcon:(0,U.jsx)(p,{size:14}),onSelect:()=>u(),className:`whitespace-nowrap`,children:`Share`}):null,d?(0,U.jsx)(l.Item,{leftIcon:(0,U.jsx)(h,{size:14}),onSelect:()=>d(),className:`whitespace-nowrap`,children:`Deploy to Vercel`}):null,o?(0,U.jsx)(l.Item,{leftIcon:(0,U.jsx)(k,{size:14,className:`text-red-600`}),onSelect:()=>o(),className:`whitespace-nowrap text-red-600 data-[highlighted]:text-red-700`,children:`Delete`}):null]})]})}function X({title:e,apps:t,assistantId:n,pinnedAppIds:r,lastImportedAppId:i,onOpen:a,onPin:o,onDelete:s,onDeploy:c,onAnimationEnd:l}){return t.length===0?null:(0,U.jsxs)(`section`,{children:[(0,U.jsx)(`h2`,{className:`mb-4 text-body-small-emphasised text-[color:var(--content-secondary)]`,children:e}),(0,U.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(max(220px,calc((100%-6rem)/5)),1fr))] gap-6`,children:t.map(e=>(0,U.jsx)(J,{app:e,assistantId:n,isPinned:r.has(e.id),onOpen:a,onPin:o,onDelete:s,justImported:e.id===i,onAnimationEnd:l,onDeploy:c?()=>c(e.id):void 0},e.id))})]})}var Z=(e,t)=>t.updatedAt-e.updatedAt||t.createdAt-e.createdAt;function Q(e){let t=D.use.pinnedAppIds(),{data:n=[],isLoading:r,error:i}=a({...b({path:{assistant_id:e}}),select:e=>e.apps}),{data:o=[],isLoading:s,error:c}=a({...v({path:{assistant_id:e}}),select:e=>e.documents}),l=r||s,u=i&&c?i instanceof Error?i.message:`Failed to load library`:null,[d,f]=(0,H.useState)(``),p=(0,H.useMemo)(()=>{if(!d.trim())return n;let e=d.toLowerCase();return n.filter(t=>t.name.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[n,d]);return{apps:n,documents:o,filteredApps:p,pinnedApps:(0,H.useMemo)(()=>p.filter(e=>t.has(e.id)).sort(Z),[p,t]),recentApps:(0,H.useMemo)(()=>p.filter(e=>!t.has(e.id)).sort(Z),[p,t]),filteredDocuments:(0,H.useMemo)(()=>{if(!d.trim())return o;let e=d.toLowerCase();return o.filter(t=>t.title.toLowerCase().includes(e))},[o,d]),searchText:d,setSearchText:f,loading:l,error:u}}async function $(e,t){let{data:n,error:r,response:i}=await g({path:{assistant_id:e},body:t,bodySerializer:e=>e,headers:{"Content-Type":`application/octet-stream`},throwOnError:!1});if(!i||!i.ok){let e=(r&&typeof r==`object`&&`message`in r?r.message:null)??`Failed to import app.`;throw Error(e)}return n}function ee({assistantId:e,assistantName:t,title:r,onNewConversation:a,onOpenDocument:o,onOpenApp:s}){let c=i(),l=D.use.togglePin(),u=D.use.pinnedAppIds(),p=P.use.isDeploying(),{apps:m,documents:h,filteredApps:g,pinnedApps:v,recentApps:b,filteredDocuments:x,searchText:S,setSearchText:T,loading:O,error:k}=Q(e),[j,M]=(0,H.useState)(null),[N,F]=(0,H.useState)(!1),I=(0,H.useCallback)(async()=>{let t=j;if(!(!t||N)){F(!0);try{await _({path:{assistant_id:e,id:t.id},throwOnError:!0}),w(e,t.id),c.invalidateQueries({queryKey:y({path:{assistant_id:e}})}),u.has(t.id)&&l(t),M(null)}catch(e){f.error(e instanceof Error?e.message:`Failed to delete app`)}finally{F(!1)}}},[j,N,e,u,l,c]),L=(0,H.useCallback)(()=>{N||M(null)},[N]),z=(0,H.useRef)(null),[B,V]=(0,H.useState)(!1),G=(0,H.useCallback)(async t=>{let n=t.target.files?.[0];if(!(!n||B)){V(!0);try{let t=await $(e,n);await c.invalidateQueries({queryKey:y({path:{assistant_id:e}})}),f.success(t.name+` imported`),s(t.appId)}catch(e){f.error(e instanceof Error?e.message:`Failed to import app`)}finally{V(!1),z.current&&(z.current.value=``)}}},[e,B,c,s]),J=(0,H.useCallback)(async t=>{if(p)return;let n=m.find(e=>e.id===t)?.name??`this app`;try{let r=await C(e,t);P.getState().deployApp(e,t,n,r)}catch{P.getState().deployApp(e,t,n,``)}},[e,p,m]),Y=(0,H.useCallback)(e=>l(e),[l]);return O?(0,U.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,U.jsx)(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-[var(--border-base)] border-t-[var(--primary-base)]`,role:`status`,"aria-label":`Loading apps`})}):k?(0,U.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-4 px-4`,children:[(0,U.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:k}),(0,U.jsx)(`button`,{type:`button`,className:`rounded-lg bg-[var(--primary-base)] px-4 py-2 text-body-medium-default text-[var(--content-inset)] transition-colors hover:bg-[var(--primary-hover)]`,onClick:()=>window.location.reload(),children:`Retry`})]}):m.length===0&&h.length===0?(0,U.jsx)(q,{fileInputRef:z,isImporting:B,onImportBundle:G,onNewConversation:a?()=>a():void 0}):(0,U.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[(0,U.jsxs)(`div`,{className:`mb-4 flex shrink-0 items-center justify-between gap-4`,children:[r?(0,U.jsx)(`h1`,{className:`text-title-large text-[var(--content-default)]`,children:r}):(0,U.jsx)(`span`,{}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`input`,{ref:z,type:`file`,accept:`.vellum`,className:`hidden`,onChange:G}),(0,U.jsxs)(n,{variant:`outlined`,size:`regular`,onClick:()=>z.current?.click(),disabled:B,children:[B?(0,U.jsx)(`div`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent`}):(0,U.jsx)(E,{size:14}),(0,U.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})]})]}),(0,U.jsx)(`div`,{className:`mb-6 shrink-0`,children:(0,U.jsx)(d,{fullWidth:!0,type:`text`,placeholder:`Search your library`,value:S,onChange:e=>T(e.target.value),leftIcon:(0,U.jsx)(A,{size:16})})}),(0,U.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:g.length===0&&x.length===0?(0,U.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16`,children:[(0,U.jsx)(A,{size:32,className:`mb-4 text-[var(--content-tertiary)]`}),(0,U.jsxs)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:[`No apps or documents matched “`,S,`”`]})]}):(0,U.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,U.jsx)(X,{title:`Pinned`,apps:v,assistantId:e,pinnedAppIds:u,onOpen:s,onPin:Y,onDelete:M,onDeploy:J}),(0,U.jsx)(X,{title:`Recents`,apps:b,assistantId:e,pinnedAppIds:u,onOpen:s,onPin:Y,onDelete:M,onDeploy:J}),x.length>0?(0,U.jsxs)(`section`,{children:[(0,U.jsx)(`h2`,{className:`mb-4 text-body-small-emphasised text-[color:var(--content-secondary)]`,children:`Documents`}),(0,U.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(max(220px,calc((100%-6rem)/5)),1fr))] gap-6`,children:x.map(e=>(0,U.jsx)(K,{document:e,onOpen:e=>{o&&o(e)}},e.surfaceId))})]}):null]})}),(0,U.jsx)(R,{assistantId:e,assistantName:t,onStartConversation:a}),(0,U.jsx)(W,{app:j,isDeleting:N,onConfirm:I,onCancel:L})]})}function te(){let e=z(),t=r();return(0,U.jsx)(B,{children:(0,U.jsx)(ee,{assistantId:e,title:`Library`,onNewConversation:(0,H.useCallback)(e=>{O(t,{prompt:e})},[t]),onOpenDocument:(0,H.useCallback)(e=>{t(x.document(e))},[t]),onOpenApp:(0,H.useCallback)(e=>{t(x.library.app(e))},[t])})})}export{te as LibraryPage};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{t as n}from"./button-D7s2Q_uG.js";import{d as r}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{n as i}from"./QueryClientProvider-DKhXIxGb.js";import{t as a}from"./useQuery-B45lW1Kk.js";import{t as o}from"./jsx-runtime-CVSDxk6A.js";import{n as s,t as c}from"./panel-item-nGTDevWP.js";import{t as l}from"./menu-C_97pis4.js";import"./src-CK6bncSg.js";import{t as u}from"./confirm-dialog-CfOXCE1N.js";import{t as d}from"./input-C8kfrq9r.js";import{n as f}from"./toast-2TW5tj1Y.js";import{t as p}from"./arrow-up-nBfZxfhi.js";import{t as m}from"./file-text-CmK9LY1p.js";import{t as h}from"./globe-DYF_lSGm.js";import{s as g,t as _}from"./sdk.gen-1aYqVbMj.js";import{C as v,n as y,t as b}from"./react-query.gen-CQLyoqYk.js";import{a as x}from"./routes-DVqkwUEe.js";import{n as S}from"./use-is-mobile-Cy10kl9u.js";import{i as C,r as w}from"./viewer-store-Dead64xY.js";import{t as T}from"./misc-BN2o2MEB.js";import{Fr as E,Ft as D,Ht as O,Ir as k,Jr as A,Ni as j,Z as M,_t as N,gt as P,ii as F,ri as I,yi as L}from"./index-PRnvH2Y1.js";import{t as R}from"./deploy-dialogs-jf5VL1UP.js";import{t as z}from"./use-active-assistant-id-C-RHQ9f6.js";import{t as B}from"./page-shell-cEGpH3P5.js";import{t as V}from"./format-date-CLlHK5gl.js";var H=e(t(),1),U=o();function W({app:e,isDeleting:t,onConfirm:n,onCancel:r}){return(0,U.jsx)(u,{open:e!==null,title:`Delete app`,message:e?`"${e.name}" will be permanently removed.`:``,confirmLabel:t?`Deleting…`:`Delete`,destructive:!0,onConfirm:n,onCancel:r})}function G(e){return e===1?`1 word`:`${e} words`}function K({document:e,onOpen:t}){return(0,U.jsxs)(`div`,{className:`group relative flex flex-col gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(e.surfaceId),className:T(`relative flex w-full cursor-pointer flex-col items-center justify-center gap-2 overflow-hidden rounded-xl border border-[var(--border-base)] bg-[var(--surface-base)]`,`aspect-[16/10]`,`outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)]`),children:[(0,U.jsx)(m,{size:34,className:`text-[var(--content-tertiary)]`}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:G(e.wordCount)})]}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(e.surfaceId),className:`flex cursor-pointer flex-col gap-0.5 px-0.5 text-left outline-none`,children:[(0,U.jsx)(`span`,{className:`truncate text-body-large-default text-[color:var(--content-emphasised)]`,children:e.title}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[color:var(--content-tertiary)]`,children:V(new Date(e.updatedAt))})]})]})}function q({fileInputRef:e,isImporting:t,onImportBundle:r,onNewConversation:i}){return(0,U.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-4 px-4 py-24`,children:[(0,U.jsx)(`input`,{ref:e,type:`file`,accept:`.vellum`,className:`hidden`,onChange:r}),(0,U.jsx)(`div`,{className:`flex h-16 w-16 items-center justify-center rounded-xl bg-[var(--surface-base)]`,children:(0,U.jsx)(L,{size:32,className:`text-[var(--content-tertiary)]`})}),(0,U.jsx)(`h2`,{className:`text-title-medium text-[var(--content-default)]`,children:`Your library is empty`}),(0,U.jsx)(`p`,{className:`max-w-md text-center text-body-medium-lighter text-[color:var(--content-tertiary)]`,children:`Ask your assistant to build something, or import a shared app`}),(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[i?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(n,{variant:`primary`,size:`regular`,onClick:i,children:`New Conversation`}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[color:var(--content-tertiary)]`,children:`or`})]}):null,(0,U.jsxs)(n,{variant:`outlined`,size:`regular`,onClick:()=>e.current?.click(),disabled:t,children:[t?(0,U.jsx)(`div`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent`}):(0,U.jsx)(E,{size:14}),(0,U.jsx)(`span`,{className:`ml-1.5`,children:`Import .vellum File`})]})]})]})}function J({app:e,assistantId:t,isPinned:n,onOpen:r,onPin:i,onDelete:a,onDeploy:o,justImported:s,onAnimationEnd:c}){let[l,u]=(0,H.useState)(!1),d=(0,H.useCallback)(()=>C(t,e.id),[t,e.id]),p=(0,H.useCallback)(async()=>{if(!l){u(!0);try{await N(t,e.id,e.name),f.success(`App exported`,{description:`${e.name}.vellum`})}catch(e){f.error(`Failed to share app`,{description:e instanceof Error?e.message:void 0})}finally{u(!1)}}},[t,e.id,e.name,l]),[m,h]=(0,H.useState)(!1),g=S();return(0,U.jsxs)(`div`,{className:T(`group relative flex flex-col gap-2`,s&&`animate-[card-entrance_400ms_ease-out]`),onAnimationEnd:s?c:void 0,children:[(0,U.jsx)(`button`,{type:`button`,onClick:()=>r(e.id),className:T(`relative w-full cursor-pointer overflow-hidden rounded-xl`,`outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)]`),children:(0,U.jsx)(M,{name:e.name,icon:e.icon,loadHtml:d})}),(0,U.jsx)(`div`,{className:T(`absolute right-2 top-2 z-20 transition-opacity`,`max-md:opacity-100`,`md:group-hover:opacity-100 md:group-focus-within:opacity-100`,m?`opacity-100`:`md:opacity-0`),children:(0,U.jsx)(Y,{appName:e.name,isPinned:n,open:m,onOpenChange:h,onPin:()=>i(e),onDelete:a?()=>a(e):void 0,onShare:p,onDeploy:o,isMobile:g})}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:`flex cursor-pointer flex-col gap-0.5 px-0.5 text-left outline-none`,children:[(0,U.jsx)(`span`,{className:`truncate text-body-large-default text-[color:var(--content-emphasised)]`,children:e.name}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[color:var(--content-tertiary)]`,children:V(new Date(e.createdAt))})]})]})}function Y({appName:e,isPinned:t,open:r,onOpenChange:i,onPin:a,onDelete:o,onShare:u,onDeploy:d,isMobile:f}){return f?(0,U.jsxs)(s.Root,{open:r,onOpenChange:i,children:[(0,U.jsx)(s.Trigger,{asChild:!0,children:(0,U.jsx)(n,{variant:`primary`,size:`compact`,iconOnly:(0,U.jsx)(j,{}),"aria-label":`App actions`,onClick:e=>e.stopPropagation()})}),(0,U.jsxs)(s.Content,{children:[(0,U.jsx)(s.Header,{className:`sr-only`,children:(0,U.jsx)(s.Title,{children:e})}),(0,U.jsxs)(s.Body,{className:`pt-0`,children:[(0,U.jsx)(c,{icon:t?F:I,label:t?`Unpin`:`Pin`,onSelect:()=>{i(!1),a()}}),u?(0,U.jsx)(c,{icon:p,label:(0,U.jsxs)(`span`,{className:`flex flex-col gap-0.5 overflow-visible whitespace-normal`,children:[(0,U.jsx)(`span`,{children:`Share`}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`Export as .vellum file`})]}),onSelect:()=>{i(!1),u()}}):null,d?(0,U.jsx)(c,{icon:h,label:(0,U.jsxs)(`span`,{className:`flex flex-col gap-0.5 overflow-visible whitespace-normal`,children:[(0,U.jsx)(`span`,{children:`Deploy to Vercel`}),(0,U.jsx)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`Publish as a static page`})]}),onSelect:()=>{i(!1),d()}}):null,o?(0,U.jsx)(c,{icon:k,label:`Delete`,onSelect:()=>{i(!1),o()}}):null]})]})]}):(0,U.jsxs)(l.Root,{open:r,onOpenChange:i,children:[(0,U.jsx)(l.Trigger,{asChild:!0,children:(0,U.jsx)(n,{variant:`primary`,size:`compact`,iconOnly:(0,U.jsx)(j,{}),"aria-label":`App actions`,onClick:e=>e.stopPropagation()})}),(0,U.jsxs)(l.Content,{align:`end`,sideOffset:4,children:[(0,U.jsx)(l.Item,{leftIcon:t?(0,U.jsx)(F,{size:14}):(0,U.jsx)(I,{size:14}),onSelect:()=>a(),className:`whitespace-nowrap`,children:t?`Unpin`:`Pin`}),u?(0,U.jsx)(l.Item,{leftIcon:(0,U.jsx)(p,{size:14}),onSelect:()=>u(),className:`whitespace-nowrap`,children:`Share`}):null,d?(0,U.jsx)(l.Item,{leftIcon:(0,U.jsx)(h,{size:14}),onSelect:()=>d(),className:`whitespace-nowrap`,children:`Deploy to Vercel`}):null,o?(0,U.jsx)(l.Item,{leftIcon:(0,U.jsx)(k,{size:14,className:`text-red-600`}),onSelect:()=>o(),className:`whitespace-nowrap text-red-600 data-[highlighted]:text-red-700`,children:`Delete`}):null]})]})}function X({title:e,apps:t,assistantId:n,pinnedAppIds:r,lastImportedAppId:i,onOpen:a,onPin:o,onDelete:s,onDeploy:c,onAnimationEnd:l}){return t.length===0?null:(0,U.jsxs)(`section`,{children:[(0,U.jsx)(`h2`,{className:`mb-4 text-body-small-emphasised text-[color:var(--content-secondary)]`,children:e}),(0,U.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(max(220px,calc((100%-6rem)/5)),1fr))] gap-6`,children:t.map(e=>(0,U.jsx)(J,{app:e,assistantId:n,isPinned:r.has(e.id),onOpen:a,onPin:o,onDelete:s,justImported:e.id===i,onAnimationEnd:l,onDeploy:c?()=>c(e.id):void 0},e.id))})]})}var Z=(e,t)=>t.updatedAt-e.updatedAt||t.createdAt-e.createdAt;function Q(e){let t=D.use.pinnedAppIds(),{data:n=[],isLoading:r,error:i}=a({...b({path:{assistant_id:e}}),select:e=>e.apps}),{data:o=[],isLoading:s,error:c}=a({...v({path:{assistant_id:e}}),select:e=>e.documents}),l=r||s,u=i&&c?i instanceof Error?i.message:`Failed to load library`:null,[d,f]=(0,H.useState)(``),p=(0,H.useMemo)(()=>{if(!d.trim())return n;let e=d.toLowerCase();return n.filter(t=>t.name.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[n,d]);return{apps:n,documents:o,filteredApps:p,pinnedApps:(0,H.useMemo)(()=>p.filter(e=>t.has(e.id)).sort(Z),[p,t]),recentApps:(0,H.useMemo)(()=>p.filter(e=>!t.has(e.id)).sort(Z),[p,t]),filteredDocuments:(0,H.useMemo)(()=>{if(!d.trim())return o;let e=d.toLowerCase();return o.filter(t=>t.title.toLowerCase().includes(e))},[o,d]),searchText:d,setSearchText:f,loading:l,error:u}}async function $(e,t){let{data:n,error:r,response:i}=await g({path:{assistant_id:e},body:t,bodySerializer:e=>e,headers:{"Content-Type":`application/octet-stream`},throwOnError:!1});if(!i||!i.ok){let e=(r&&typeof r==`object`&&`message`in r?r.message:null)??`Failed to import app.`;throw Error(e)}return n}function ee({assistantId:e,assistantName:t,title:r,onNewConversation:a,onOpenDocument:o,onOpenApp:s}){let c=i(),l=D.use.togglePin(),u=D.use.pinnedAppIds(),p=P.use.isDeploying(),{apps:m,documents:h,filteredApps:g,pinnedApps:v,recentApps:b,filteredDocuments:x,searchText:S,setSearchText:T,loading:O,error:k}=Q(e),[j,M]=(0,H.useState)(null),[N,F]=(0,H.useState)(!1),I=(0,H.useCallback)(async()=>{let t=j;if(!(!t||N)){F(!0);try{await _({path:{assistant_id:e,id:t.id},throwOnError:!0}),w(e,t.id),c.invalidateQueries({queryKey:y({path:{assistant_id:e}})}),u.has(t.id)&&l(t),M(null)}catch(e){f.error(e instanceof Error?e.message:`Failed to delete app`)}finally{F(!1)}}},[j,N,e,u,l,c]),L=(0,H.useCallback)(()=>{N||M(null)},[N]),z=(0,H.useRef)(null),[B,V]=(0,H.useState)(!1),G=(0,H.useCallback)(async t=>{let n=t.target.files?.[0];if(!(!n||B)){V(!0);try{let t=await $(e,n);await c.invalidateQueries({queryKey:y({path:{assistant_id:e}})}),f.success(t.name+` imported`),s(t.appId)}catch(e){f.error(e instanceof Error?e.message:`Failed to import app`)}finally{V(!1),z.current&&(z.current.value=``)}}},[e,B,c,s]),J=(0,H.useCallback)(async t=>{if(p)return;let n=m.find(e=>e.id===t)?.name??`this app`;try{let r=await C(e,t);P.getState().deployApp(e,t,n,r)}catch{P.getState().deployApp(e,t,n,``)}},[e,p,m]),Y=(0,H.useCallback)(e=>l(e),[l]);return O?(0,U.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,U.jsx)(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-[var(--border-base)] border-t-[var(--primary-base)]`,role:`status`,"aria-label":`Loading apps`})}):k?(0,U.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-4 px-4`,children:[(0,U.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:k}),(0,U.jsx)(`button`,{type:`button`,className:`rounded-lg bg-[var(--primary-base)] px-4 py-2 text-body-medium-default text-[var(--content-inset)] transition-colors hover:bg-[var(--primary-hover)]`,onClick:()=>window.location.reload(),children:`Retry`})]}):m.length===0&&h.length===0?(0,U.jsx)(q,{fileInputRef:z,isImporting:B,onImportBundle:G,onNewConversation:a?()=>a():void 0}):(0,U.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[(0,U.jsxs)(`div`,{className:`mb-4 flex shrink-0 items-center justify-between gap-4`,children:[r?(0,U.jsx)(`h1`,{className:`text-title-large text-[var(--content-default)]`,children:r}):(0,U.jsx)(`span`,{}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`input`,{ref:z,type:`file`,accept:`.vellum`,className:`hidden`,onChange:G}),(0,U.jsxs)(n,{variant:`outlined`,size:`regular`,onClick:()=>z.current?.click(),disabled:B,children:[B?(0,U.jsx)(`div`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent`}):(0,U.jsx)(E,{size:14}),(0,U.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})]})]}),(0,U.jsx)(`div`,{className:`mb-6 shrink-0`,children:(0,U.jsx)(d,{fullWidth:!0,type:`text`,placeholder:`Search your library`,value:S,onChange:e=>T(e.target.value),leftIcon:(0,U.jsx)(A,{size:16})})}),(0,U.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:g.length===0&&x.length===0?(0,U.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16`,children:[(0,U.jsx)(A,{size:32,className:`mb-4 text-[var(--content-tertiary)]`}),(0,U.jsxs)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:[`No apps or documents matched “`,S,`”`]})]}):(0,U.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,U.jsx)(X,{title:`Pinned`,apps:v,assistantId:e,pinnedAppIds:u,onOpen:s,onPin:Y,onDelete:M,onDeploy:J}),(0,U.jsx)(X,{title:`Recents`,apps:b,assistantId:e,pinnedAppIds:u,onOpen:s,onPin:Y,onDelete:M,onDeploy:J}),x.length>0?(0,U.jsxs)(`section`,{children:[(0,U.jsx)(`h2`,{className:`mb-4 text-body-small-emphasised text-[color:var(--content-secondary)]`,children:`Documents`}),(0,U.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(max(220px,calc((100%-6rem)/5)),1fr))] gap-6`,children:x.map(e=>(0,U.jsx)(K,{document:e,onOpen:e=>{o&&o(e)}},e.surfaceId))})]}):null]})}),(0,U.jsx)(R,{assistantId:e,assistantName:t,onStartConversation:a}),(0,U.jsx)(W,{app:j,isDeleting:N,onConfirm:I,onCancel:L})]})}function te(){let e=z(),t=r();return(0,U.jsx)(B,{children:(0,U.jsx)(ee,{assistantId:e,title:`Library`,onNewConversation:(0,H.useCallback)(e=>{O(t,{prompt:e})},[t]),onOpenDocument:(0,H.useCallback)(e=>{t(x.document(e))},[t]),onOpenApp:(0,H.useCallback)(e=>{t(x.library.app(e))},[t])})})}export{te as LibraryPage};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{t as n}from"./button-D7s2Q_uG.js";import{h as r,t as i}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as a}from"./jsx-runtime-CVSDxk6A.js";import{t as o}from"./cn-DvW5mxZR.js";import"./src-CK6bncSg.js";import{A as s,M as c,j as l}from"./auth-store-Kfxhs2oI.js";import{a as u}from"./routes-DVqkwUEe.js";import{n as d,r as f}from"./login-flow-DPi11n3h.js";import{t as p}from"./public-asset-Fx_laYnf.js";import{X as m,at as h,pi as g}from"./index-BIDC22lX.js";var _=e(t(),1),v=a();function y({children:e}){return(0,v.jsxs)(`div`,{className:`fixed inset-0 z-50 flex flex-col items-center justify-center bg-[var(--surface-base)] text-[var(--content-default)]`,children:[(0,v.jsx)(`img`,{src:p(`/vellum-logo.svg`),alt:`Vellum`,width:220,height:66,className:`block dark:hidden`}),(0,v.jsx)(`img`,{src:p(`/vellum-logo-white.svg`),alt:`Vellum`,width:220,height:66,className:`hidden dark:block`}),e,(0,v.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute left-1/2 w-full max-w-[900px] -translate-x-1/2`,style:{bottom:0},children:(0,v.jsx)(`img`,{src:p(`/login-background-characters.svg`),alt:``,width:880,height:182,className:`h-auto w-full`})})]})}function b(){return(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{className:`pointer-events-none absolute top-[120px] left-1/2 z-0 -translate-x-1/2`,children:(0,v.jsx)(`img`,{src:p(`/vellum-logo-white.svg`),alt:`Vellum`,width:92,height:28})}),(0,v.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute right-0 bottom-0 left-1/2 z-0 w-full max-w-[1100px] -translate-x-1/2`,children:(0,v.jsx)(`img`,{src:p(`/login-background-characters.svg`),alt:``,width:880,height:182,className:`h-auto w-full`})})]})}var x=`flex w-full max-w-[448px] flex-col gap-6 rounded-lg border border-[var(--border-disabled)] bg-[var(--surface-lift)] p-6`;function S({children:e}){return(0,v.jsx)(`div`,{className:x,children:e})}function C({children:e}){return(0,v.jsx)(`h1`,{className:`text-title-large text-center text-[var(--content-emphasised)]`,children:e})}function w({children:e,className:t}){return(0,v.jsx)(`p`,{className:o(`text-body-small-default text-center text-[var(--system-negative-strong)]`,t),children:e})}function T({children:e}){return(0,v.jsx)(`div`,{className:`dark`,children:(0,v.jsxs)(`div`,{className:`relative min-h-screen overflow-x-hidden bg-[var(--surface-base)] text-[var(--content-default)]`,children:[(0,v.jsx)(b,{}),(0,v.jsx)(`div`,{className:`relative z-10 flex min-h-screen flex-col items-center justify-center px-4`,children:e})]})})}function E({signUpHref:e}){return(0,v.jsxs)(`p`,{className:`text-body-small-default flex justify-center gap-1`,children:[(0,v.jsx)(`span`,{className:`text-[var(--content-secondary)]`,children:`Don't have an account?`}),(0,v.jsx)(i,{to:e,className:`font-medium text-[var(--content-emphasised)] hover:underline`,children:`Sign up`})]})}function D({returnTo:e,loading:t,errorMessage:r,onProviderClick:i}){let a=e?`${u.account.signup}?returnTo=${encodeURIComponent(e)}`:u.account.signup;return(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(C,{children:`Sign in to Vellum`}),r&&(0,v.jsx)(w,{children:r}),(0,v.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,v.jsx)(n,{type:`button`,variant:`outlined`,fullWidth:!0,onClick:()=>i(`AppleOAuth`),disabled:t,leftIcon:(0,v.jsx)(h,{}),className:`max-w-[300px] gap-3`,children:`Continue with Apple`}),(0,v.jsx)(n,{type:`button`,variant:`outlined`,fullWidth:!0,onClick:()=>i(`GoogleOAuth`),disabled:t,leftIcon:(0,v.jsx)(m,{}),className:`max-w-[300px] gap-3`,children:`Continue with Google`}),(0,v.jsx)(n,{type:`button`,variant:`outlined`,fullWidth:!0,onClick:()=>i(),disabled:t,leftIcon:(0,v.jsx)(g,{}),className:`max-w-[300px] gap-3`,children:`Continue with Email`})]}),(0,v.jsx)(E,{signUpHref:a})]})}var O={signup_closed:`Sign-ups are currently closed. Visit vellum.ai/community to request access.`};function k({returnTo:e}){let[t,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),o=async()=>{r(null),a(!0);try{await l({returnTo:e??null})}catch(e){let t=e&&typeof e==`object`&&`code`in e?e.code:void 0;if(t===`USER_CANCELLED`){a(!1);return}if(t===`AUTH_ERROR`){let t=e&&typeof e==`object`&&`data`in e&&e.data&&typeof e.data==`object`&&`authError`in e.data&&typeof e.data.authError==`string`?e.data.authError:void 0;r((t&&O[t])??`Something went wrong. Please try again.`)}else console.error(`[native-auth] auth flow failed:`,e),r(`Something went wrong. Please try again.`);a(!1)}};return(0,v.jsx)(y,{children:(0,v.jsxs)(`div`,{className:`z-10 mt-8 flex w-full max-w-[320px] flex-col items-center gap-3`,children:[t&&(0,v.jsx)(w,{className:`max-w-[280px]`,children:t}),(0,v.jsx)(n,{type:`button`,variant:`primary`,fullWidth:!0,onClick:()=>{o()},disabled:i,className:`max-w-[300px]`,children:`Sign in`})]})})}function A({returnTo:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!1),a=f(e),o=async t=>{n(null),i(!0);try{await s(d,a,{...t?{providerHint:t}:{},returnTo:e})}catch(e){console.error(`[web-login] auth flow failed:`,e),n(`Something went wrong. Please try again.`),i(!1)}};return(0,v.jsx)(T,{children:(0,v.jsx)(S,{children:(0,v.jsx)(D,{returnTo:e,loading:r,errorMessage:t,onProviderClick:e=>{o(e)}})})})}function j(){let[e]=r(),t=c(),n=e.get(`returnTo`);return t?(0,v.jsx)(k,{returnTo:n}):(0,v.jsx)(A,{returnTo:n})}export{j as LoginPage};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{t as n}from"./button-D7s2Q_uG.js";import{h as r,t as i}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as a}from"./jsx-runtime-CVSDxk6A.js";import{t as o}from"./cn-DvW5mxZR.js";import"./src-CK6bncSg.js";import{A as s,M as c,j as l}from"./auth-store-Kfxhs2oI.js";import{a as u}from"./routes-DVqkwUEe.js";import{n as d,r as f}from"./login-flow-DPi11n3h.js";import{t as p}from"./public-asset-Fx_laYnf.js";import{X as m,at as h,pi as g}from"./index-PRnvH2Y1.js";var _=e(t(),1),v=a();function y({children:e}){return(0,v.jsxs)(`div`,{className:`fixed inset-0 z-50 flex flex-col items-center justify-center bg-[var(--surface-base)] text-[var(--content-default)]`,children:[(0,v.jsx)(`img`,{src:p(`/vellum-logo.svg`),alt:`Vellum`,width:220,height:66,className:`block dark:hidden`}),(0,v.jsx)(`img`,{src:p(`/vellum-logo-white.svg`),alt:`Vellum`,width:220,height:66,className:`hidden dark:block`}),e,(0,v.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute left-1/2 w-full max-w-[900px] -translate-x-1/2`,style:{bottom:0},children:(0,v.jsx)(`img`,{src:p(`/login-background-characters.svg`),alt:``,width:880,height:182,className:`h-auto w-full`})})]})}function b(){return(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{className:`pointer-events-none absolute top-[120px] left-1/2 z-0 -translate-x-1/2`,children:(0,v.jsx)(`img`,{src:p(`/vellum-logo-white.svg`),alt:`Vellum`,width:92,height:28})}),(0,v.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute right-0 bottom-0 left-1/2 z-0 w-full max-w-[1100px] -translate-x-1/2`,children:(0,v.jsx)(`img`,{src:p(`/login-background-characters.svg`),alt:``,width:880,height:182,className:`h-auto w-full`})})]})}var x=`flex w-full max-w-[448px] flex-col gap-6 rounded-lg border border-[var(--border-disabled)] bg-[var(--surface-lift)] p-6`;function S({children:e}){return(0,v.jsx)(`div`,{className:x,children:e})}function C({children:e}){return(0,v.jsx)(`h1`,{className:`text-title-large text-center text-[var(--content-emphasised)]`,children:e})}function w({children:e,className:t}){return(0,v.jsx)(`p`,{className:o(`text-body-small-default text-center text-[var(--system-negative-strong)]`,t),children:e})}function T({children:e}){return(0,v.jsx)(`div`,{className:`dark`,children:(0,v.jsxs)(`div`,{className:`relative min-h-screen overflow-x-hidden bg-[var(--surface-base)] text-[var(--content-default)]`,children:[(0,v.jsx)(b,{}),(0,v.jsx)(`div`,{className:`relative z-10 flex min-h-screen flex-col items-center justify-center px-4`,children:e})]})})}function E({signUpHref:e}){return(0,v.jsxs)(`p`,{className:`text-body-small-default flex justify-center gap-1`,children:[(0,v.jsx)(`span`,{className:`text-[var(--content-secondary)]`,children:`Don't have an account?`}),(0,v.jsx)(i,{to:e,className:`font-medium text-[var(--content-emphasised)] hover:underline`,children:`Sign up`})]})}function D({returnTo:e,loading:t,errorMessage:r,onProviderClick:i}){let a=e?`${u.account.signup}?returnTo=${encodeURIComponent(e)}`:u.account.signup;return(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(C,{children:`Sign in to Vellum`}),r&&(0,v.jsx)(w,{children:r}),(0,v.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,v.jsx)(n,{type:`button`,variant:`outlined`,fullWidth:!0,onClick:()=>i(`AppleOAuth`),disabled:t,leftIcon:(0,v.jsx)(h,{}),className:`max-w-[300px] gap-3`,children:`Continue with Apple`}),(0,v.jsx)(n,{type:`button`,variant:`outlined`,fullWidth:!0,onClick:()=>i(`GoogleOAuth`),disabled:t,leftIcon:(0,v.jsx)(m,{}),className:`max-w-[300px] gap-3`,children:`Continue with Google`}),(0,v.jsx)(n,{type:`button`,variant:`outlined`,fullWidth:!0,onClick:()=>i(),disabled:t,leftIcon:(0,v.jsx)(g,{}),className:`max-w-[300px] gap-3`,children:`Continue with Email`})]}),(0,v.jsx)(E,{signUpHref:a})]})}var O={signup_closed:`Sign-ups are currently closed. Visit vellum.ai/community to request access.`};function k({returnTo:e}){let[t,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),o=async()=>{r(null),a(!0);try{await l({returnTo:e??null})}catch(e){let t=e&&typeof e==`object`&&`code`in e?e.code:void 0;if(t===`USER_CANCELLED`){a(!1);return}if(t===`AUTH_ERROR`){let t=e&&typeof e==`object`&&`data`in e&&e.data&&typeof e.data==`object`&&`authError`in e.data&&typeof e.data.authError==`string`?e.data.authError:void 0;r((t&&O[t])??`Something went wrong. Please try again.`)}else console.error(`[native-auth] auth flow failed:`,e),r(`Something went wrong. Please try again.`);a(!1)}};return(0,v.jsx)(y,{children:(0,v.jsxs)(`div`,{className:`z-10 mt-8 flex w-full max-w-[320px] flex-col items-center gap-3`,children:[t&&(0,v.jsx)(w,{className:`max-w-[280px]`,children:t}),(0,v.jsx)(n,{type:`button`,variant:`primary`,fullWidth:!0,onClick:()=>{o()},disabled:i,className:`max-w-[300px]`,children:`Sign in`})]})})}function A({returnTo:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!1),a=f(e),o=async t=>{n(null),i(!0);try{await s(d,a,{...t?{providerHint:t}:{},returnTo:e})}catch(e){console.error(`[web-login] auth flow failed:`,e),n(`Something went wrong. Please try again.`),i(!1)}};return(0,v.jsx)(T,{children:(0,v.jsx)(S,{children:(0,v.jsx)(D,{returnTo:e,loading:r,errorMessage:t,onProviderClick:e=>{o(e)}})})})}function j(){let[e]=r(),t=c(),n=e.get(`returnTo`);return t?(0,v.jsx)(k,{returnTo:n}):(0,v.jsx)(A,{returnTo:n})}export{j as LoginPage};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{h as n}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as r}from"./jsx-runtime-CVSDxk6A.js";import{n as i}from"./auth-store-Kfxhs2oI.js";import{t as a}from"./return-to-ByvaXBKr.js";import{a as o}from"./routes-DVqkwUEe.js";import{Rn as s}from"./index-BIDC22lX.js";import{r as c,t as l}from"./account-shell-b6GjlQ0u.js";var u=e(t(),1),d=r();function f(){let[e]=n(),t=i.use.logout(),r=(0,u.useRef)(!1);return(0,u.useEffect)(()=>{if(r.current)return;r.current=!0;let n=a(e.get(`returnTo`),o.account.login),i=n.startsWith(`http`)||n===o.account.login?n:`${o.account.login}?returnTo=${encodeURIComponent(n)}`,c=!1;return t().then(()=>{c||s(i)},()=>{c||s(i)}),()=>{c=!0}},[t,e]),(0,d.jsx)(l,{children:(0,d.jsx)(c,{title:`Signing out...`})})}export{f as LogoutPage};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{h as n}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as r}from"./jsx-runtime-CVSDxk6A.js";import{n as i}from"./auth-store-Kfxhs2oI.js";import{t as a}from"./return-to-ByvaXBKr.js";import{a as o}from"./routes-DVqkwUEe.js";import{Rn as s}from"./index-PRnvH2Y1.js";import{r as c,t as l}from"./account-shell-b6GjlQ0u.js";var u=e(t(),1),d=r();function f(){let[e]=n(),t=i.use.logout(),r=(0,u.useRef)(!1);return(0,u.useEffect)(()=>{if(r.current)return;r.current=!0;let n=a(e.get(`returnTo`),o.account.login),i=n.startsWith(`http`)||n===o.account.login?n:`${o.account.login}?returnTo=${encodeURIComponent(n)}`,c=!1;return t().then(()=>{c||s(i)},()=>{c||s(i)}),()=>{c=!0}},[t,e]),(0,d.jsx)(l,{children:(0,d.jsx)(c,{title:`Signing out...`})})}export{f as LogoutPage};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{i as n,u as r}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as i}from"./jsx-runtime-CVSDxk6A.js";import{t as a}from"./createLucideIcon-BlMXrA59.js";import{a as o}from"./routes-DVqkwUEe.js";import{Yr as s,an as c,ea as l,pi as u}from"./index-BIDC22lX.js";import{n as d,t as f}from"./sidebar-tree-BNLVikyu.js";var p=a(`monitor-cog`,[[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`m14.305 7.53.923-.382`,key:`1mlnsw`}],[`path`,{d:`m15.228 4.852-.923-.383`,key:`82mpwg`}],[`path`,{d:`m16.852 3.228-.383-.924`,key:`ln4sir`}],[`path`,{d:`m16.852 8.772-.383.923`,key:`1dejw0`}],[`path`,{d:`m19.148 3.228.383-.924`,key:`192kgf`}],[`path`,{d:`m19.53 9.696-.382-.924`,key:`fiavlr`}],[`path`,{d:`m20.772 4.852.924-.383`,key:`1j8mgp`}],[`path`,{d:`m20.772 7.148.924.383`,key:`zix9be`}],[`path`,{d:`M22 13v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7`,key:`1tnzv8`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}]]),m=e(t(),1),h=[{id:`usage`,label:`Usage`,href:o.logs.usage,icon:l},{id:`logs`,label:`Logs`,href:o.logs.trace,icon:s},{id:`emails`,label:`Emails`,href:o.logs.emails,icon:u},{id:`system-events`,label:`System Events`,href:o.logs.systemEvents,icon:p}],g=i();function _(){let e=c({platformHostedOnly:!0}),t=c(),{pathname:i}=r(),a=(0,m.useMemo)(()=>h.filter(n=>!(n.id===`system-events`&&e===`gated`||n.id===`emails`&&t===`gated`)),[e,t]),s=(0,m.useMemo)(()=>{let e=h.find(e=>i===e.href||i.startsWith(e.href+`/`));return e?e.label:i===o.logs.root?h[0]?.label??`Logs & Usage`:`Logs & Usage`},[i]);return(0,g.jsx)(d,{backHref:o.assistant,sidebar:(0,g.jsx)(f,{items:a,indexPath:o.logs.root}),title:s,menuRoute:o.logs.root,children:(0,g.jsx)(n,{})})}export{_ as LogsLayout};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{i as n,u as r}from"./chunk-5KNZJZUH-DdS6bb-3.js";import{t as i}from"./jsx-runtime-CVSDxk6A.js";import{t as a}from"./createLucideIcon-BlMXrA59.js";import{a as o}from"./routes-DVqkwUEe.js";import{Yr as s,an as c,ea as l,pi as u}from"./index-PRnvH2Y1.js";import{n as d,t as f}from"./sidebar-tree-BJkXpCut.js";var p=a(`monitor-cog`,[[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`m14.305 7.53.923-.382`,key:`1mlnsw`}],[`path`,{d:`m15.228 4.852-.923-.383`,key:`82mpwg`}],[`path`,{d:`m16.852 3.228-.383-.924`,key:`ln4sir`}],[`path`,{d:`m16.852 8.772-.383.923`,key:`1dejw0`}],[`path`,{d:`m19.148 3.228.383-.924`,key:`192kgf`}],[`path`,{d:`m19.53 9.696-.382-.924`,key:`fiavlr`}],[`path`,{d:`m20.772 4.852.924-.383`,key:`1j8mgp`}],[`path`,{d:`m20.772 7.148.924.383`,key:`zix9be`}],[`path`,{d:`M22 13v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7`,key:`1tnzv8`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}]]),m=e(t(),1),h=[{id:`usage`,label:`Usage`,href:o.logs.usage,icon:l},{id:`logs`,label:`Logs`,href:o.logs.trace,icon:s},{id:`emails`,label:`Emails`,href:o.logs.emails,icon:u},{id:`system-events`,label:`System Events`,href:o.logs.systemEvents,icon:p}],g=i();function _(){let e=c({platformHostedOnly:!0}),t=c(),{pathname:i}=r(),a=(0,m.useMemo)(()=>h.filter(n=>!(n.id===`system-events`&&e===`gated`||n.id===`emails`&&t===`gated`)),[e,t]),s=(0,m.useMemo)(()=>{let e=h.find(e=>i===e.href||i.startsWith(e.href+`/`));return e?e.label:i===o.logs.root?h[0]?.label??`Logs & Usage`:`Logs & Usage`},[i]);return(0,g.jsx)(d,{backHref:o.assistant,sidebar:(0,g.jsx)(f,{items:a,indexPath:o.logs.root}),title:s,menuRoute:o.logs.root,children:(0,g.jsx)(n,{})})}export{_ as LogsLayout};
@@ -1,3 +1,3 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{t as n}from"./useQuery-B45lW1Kk.js";import{t as r}from"./useMutation-Lj4VunQV.js";import{t as i}from"./jsx-runtime-CVSDxk6A.js";import{t as a}from"./card-BibIM9x3.js";import"./src-CK6bncSg.js";import{Qt as o}from"./sdk.gen-1aYqVbMj.js";import{G as s,W as c,f as l}from"./react-query.gen-CQLyoqYk.js";import{o as u}from"./auth-store-Kfxhs2oI.js";import{t as d}from"./client-feature-flag-store-C1kdd1EO.js";import{Ut as f}from"./index-BIDC22lX.js";import{t as p}from"./use-active-assistant-id-C-RHQ9f6.js";var m=e(t(),1),h=class extends Error{status;constructor(e,t){super(t),this.name=`SimulateMemoryRouterError`,this.status=e}};async function g(e,t,n){let{data:r,response:i}=await o({path:{assistant_id:e},body:t,signal:n,throwOnError:!1}),a=i?await i.clone().text().catch(()=>``):``;if(!i||!i.ok)throw new h(i?.status??0,a||i?.statusText||`Failed to simulate memory router`);if(!r)throw new h(i.status,`Empty response from memory router simulator endpoint`);return{response:r,rawRequest:JSON.stringify(t,null,2),rawResponse:_(a)}}function _(e){if(e.length===0)return e;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function v(e){return r({mutationFn:async t=>{if(!e)throw new h(0,`Missing assistantId`);return g(e,t)}})}function y(e){return n({...l({path:{assistant_id:e}}),enabled:!!e,staleTime:6e4})}function b(e){return n({...s({path:{assistant_id:e}}),enabled:!!e,staleTime:1440*60*1e3})}function x(e){return n({...c({path:{assistant_id:e}}),enabled:!!e,staleTime:1/0})}var S=i();function C(){let e=f(),t=u(),n=d.use.memoryRouterPlayground();return t?(0,S.jsx)($,{children:`Loading…`}):!e||!n?(0,S.jsx)($,{children:`Memory router playground is not available.`}):(0,S.jsx)(T,{})}var w={tier1:``,tier2:``,batch:``,profile:``,customPrompt:``};function T(){let e=p(),t=v(e),n=v(e),r=y(e),i=b(e),a=x(e),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)([{assistantMessage:``,userMessage:``}]),[u,d]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(u)return;let e=a.data?.nowText;typeof e==`string`&&o===``&&s(e)},[a.data?.nowText,o,u]);let[f,h]=(0,m.useState)(w),[g,_]=(0,m.useState)(w),[C,T]=(0,m.useState)(null),[D,k]=(0,m.useState)(null),j=c[c.length-1].userMessage,M=e=>{let r=e===`A`?f:g,i=e===`A`?T:k,a=e===`A`?t:n;i(null);let s;try{s=E(r)}catch(e){i(e instanceof Error?e.message:`Invalid override input`);return}let l=r.profile.trim().length>0?r.profile:void 0,u=r.customPrompt.trim().length>0?r.customPrompt:void 0,d=c.map((e,t)=>t===c.length-1?{...e,userMessage:e.userMessage.trim()}:e);a.mutate({recentTurnPairs:d,nowText:o,...s?{configOverrides:s}:{},...l===void 0?{}:{profileOverride:l},...u===void 0?{}:{routerPromptOverride:u}})},N=()=>{M(`A`),M(`B`)},P=j.trim().length>0,I=P&&!t.isPending,L=P&&!n.isPending;return(0,S.jsx)(`div`,{className:`flex h-full min-h-0 flex-col overflow-y-auto`,children:(0,S.jsxs)(`div`,{className:`mx-auto flex w-full max-w-[1280px] flex-col gap-6 p-6`,children:[(0,S.jsx)(ee,{}),(0,S.jsx)(O,{nowText:o,onNowTextChange:e=>{d(!0),s(e)},onReloadNowText:()=>{let e=a.data?.nowText;typeof e==`string`&&(s(e),d(!1))},nowTextLoading:a.isLoading,pairs:c,onPairsChange:l}),(0,S.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,S.jsx)(A,{paneId:`A`,overrides:f,onChange:h,onRun:()=>M(`A`),canRun:I,isRunning:t.isPending,profiles:r.data?.profiles??[],activeProfile:r.data?.activeProfile??null,defaultPromptTemplate:i.data?.template??``}),(0,S.jsx)(A,{paneId:`B`,overrides:g,onChange:_,onRun:()=>M(`B`),canRun:L,isRunning:n.isPending,profiles:r.data?.profiles??[],activeProfile:r.data?.activeProfile??null,defaultPromptTemplate:i.data?.template??``})]}),(0,S.jsx)(`div`,{className:`flex justify-end`,children:(0,S.jsx)(te,{onClick:N,disabled:!P||t.isPending||n.isPending,isRunning:t.isPending||n.isPending})}),(0,S.jsx)(ne,{visible:t.data!==void 0&&n.data!==void 0}),(0,S.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,S.jsx)(F,{paneId:`A`,userMessage:j,mutation:t,otherResult:n.data?.response,validation:C}),(0,S.jsx)(F,{paneId:`B`,userMessage:j,mutation:n,otherResult:t.data?.response,validation:D})]})]})})}function E(e){let t={...D(`tier1_size`,e.tier1),...D(`tier2_size`,e.tier2),...D(`batch_size`,e.batch)};return Object.keys(t).length===0?void 0:t}function D(e,t){let n=t.trim();if(n===``)return{};if(n===`null`)return{[e]:null};let r=Number(n);if(!Number.isInteger(r)||r<1)throw Error(`${e} must be a positive integer or 'null' (got "${n}")`);return{[e]:r}}function ee(){return(0,S.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,S.jsx)(`h1`,{className:`text-body-large-default`,style:{color:`var(--content-default)`},children:`Memory Router Playground`}),(0,S.jsxs)(`p`,{className:`text-body-medium-lighter`,style:{color:`var(--content-secondary)`},children:[`Dry-run the v4 router with custom tier/batch overrides. Read-only — no rows are written to `,(0,S.jsx)(`code`,{children:`memory_v2_injection_events`}),` or`,` `,(0,S.jsx)(`code`,{children:`memory_v2_activation_logs`}),`, and no activation state is mutated. Leave an override blank to inherit the live config value; enter`,` `,(0,S.jsx)(`code`,{children:`null`}),` to explicitly disable a tier.`]})]})}function O({nowText:e,onNowTextChange:t,onReloadNowText:n,nowTextLoading:r,pairs:i,onPairsChange:o}){let s=(e,t)=>{o(i.map((n,r)=>r===e?{...n,...t}:n))},c=()=>{o([{assistantMessage:``,userMessage:``},...i])},l=e=>{e!==i.length-1&&o(i.filter((t,n)=>n!==e))};return(0,S.jsx)(a,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,S.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:`Conversational context (shared by both panes)`}),(0,S.jsx)(k,{id:`memory-router-playground-now`,label:`<now> block`,value:e,onChange:t,rows:6,monospace:!0,placeholder:r?`Loading current NOW.md…`:`Pre-filled with the live NOW.md. Edit to test alternate states.`,trailing:(0,S.jsx)(`button`,{type:`button`,onClick:n,disabled:r,className:`rounded px-2 py-1 text-label-default`,style:{background:`var(--surface-overlay)`,color:`var(--content-secondary)`,border:`none`,cursor:r?`not-allowed`:`pointer`},children:`Reload live NOW.md`})}),(0,S.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,S.jsx)(`span`,{className:`text-label-default`,style:{color:`var(--content-secondary)`},children:`Recent (assistant, user) pairs · oldest first`}),(0,S.jsx)(`button`,{type:`button`,onClick:c,className:`rounded px-2 py-1 text-label-default`,style:{background:`var(--surface-overlay)`,color:`var(--content-secondary)`,border:`none`,cursor:`pointer`},children:`+ Add older pair`})]}),i.map((e,t)=>{let n=t===i.length-1;return(0,S.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border p-3`,style:{borderColor:`var(--border-base)`,background:`var(--surface-base)`},children:[(0,S.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,S.jsxs)(`span`,{className:`text-label-default`,style:{color:`var(--content-secondary)`},children:[`Pair `,t+1,` of `,i.length,n?` · most recent`:``]}),!n&&(0,S.jsx)(`button`,{type:`button`,onClick:()=>l(t),className:`rounded px-2 py-1 text-label-default`,style:{background:`transparent`,color:`var(--system-negative-strong)`,border:`none`,cursor:`pointer`},children:`Remove`})]}),(0,S.jsx)(k,{id:`memory-router-playground-pair-${t}-assistant`,label:`[assistant]: reply`,value:e.assistantMessage,onChange:e=>s(t,{assistantMessage:e}),rows:3,placeholder:t===0&&i.length===1?`Leave blank for a first-turn scenario.`:`Assistant's reply that came before the user message below.`}),(0,S.jsx)(k,{id:`memory-router-playground-pair-${t}-user`,label:n?`Just-arrived [user]: message`:`[user]: message`,value:e.userMessage,onChange:e=>s(t,{userMessage:e}),rows:3,placeholder:n?`e.g. what should we ship next`:`User's message.`,required:n})]},t)})]})})}function k({id:e,label:t,value:n,onChange:r,rows:i,placeholder:a,monospace:o,trailing:s,required:c}){return(0,S.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,S.jsxs)(`label`,{htmlFor:e,className:`text-label-default`,style:{color:`var(--content-secondary)`},children:[t,c?` *`:``]}),s]}),(0,S.jsx)(`textarea`,{id:e,value:n,onChange:e=>r(e.target.value),rows:i,placeholder:a,className:`rounded-md border px-3 py-2 text-body-medium-default`,style:{borderColor:`var(--border-base)`,background:`var(--surface-base)`,color:`var(--content-default)`,resize:`vertical`,...o?{fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace`}:{}}})]})}function A({paneId:e,overrides:t,onChange:n,onRun:r,canRun:i,isRunning:o,profiles:s,activeProfile:c,defaultPromptTemplate:l}){return(0,S.jsx)(a,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,S.jsxs)(`div`,{className:`text-body-medium-default`,style:{color:q(e)},children:[`Config `,e]}),(0,S.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,S.jsx)(N,{paneId:e,label:`tier1_size`,value:t.tier1,onChange:e=>n({...t,tier1:e})}),(0,S.jsx)(N,{paneId:e,label:`tier2_size`,value:t.tier2,onChange:e=>n({...t,tier2:e})}),(0,S.jsx)(N,{paneId:e,label:`batch_size`,value:t.batch,onChange:e=>n({...t,batch:e})})]}),(0,S.jsx)(M,{paneId:e,value:t.profile,onChange:e=>n({...t,profile:e}),profiles:s,activeProfile:c}),(0,S.jsx)(j,{paneId:e,value:t.customPrompt,onChange:e=>n({...t,customPrompt:e}),defaultTemplate:l}),(0,S.jsx)(`div`,{className:`flex justify-end`,children:(0,S.jsx)(`button`,{type:`button`,onClick:r,disabled:!i,className:`rounded-md px-4 py-2 text-body-medium-default transition-colors`,style:{background:i?`var(--system-positive-strong)`:`var(--surface-overlay)`,color:i?`var(--content-on-positive)`:`var(--content-disabled)`,border:`none`,cursor:i?`pointer`:`not-allowed`},children:o?`Running…`:`Run ${e}`})})]})})}function j({paneId:e,value:t,onChange:n,defaultTemplate:r}){let[i,a]=(0,m.useState)(!1),o=`memory-router-playground-${e}-prompt`,s=t.trim().length>0;return(0,S.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,S.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`text-label-default`,style:{color:`var(--content-secondary)`,background:`transparent`,border:`none`,padding:0,cursor:`pointer`,textAlign:`left`},children:[i?`▾`:`▸`,` System prompt`,` `,(0,S.jsxs)(`span`,{style:{color:`var(--content-tertiary)`},children:[`(`,s?`custom`:`bundled`,`)`]})]}),i&&(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>n(r),disabled:r.length===0,className:`rounded px-2 py-1 text-label-default`,style:{background:`var(--surface-overlay)`,color:`var(--content-secondary)`,border:`none`,cursor:r.length===0?`not-allowed`:`pointer`},children:`Load default`}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>n(``),disabled:!s,className:`rounded px-2 py-1 text-label-default`,style:{background:`var(--surface-overlay)`,color:`var(--content-secondary)`,border:`none`,cursor:s?`pointer`:`not-allowed`},children:`Reset`})]})]}),i&&(0,S.jsx)(`textarea`,{id:o,value:t,onChange:e=>n(e.target.value),rows:12,placeholder:`Custom router system prompt. Available placeholders:
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{t as n}from"./useQuery-B45lW1Kk.js";import{t as r}from"./useMutation-Lj4VunQV.js";import{t as i}from"./jsx-runtime-CVSDxk6A.js";import{t as a}from"./card-BibIM9x3.js";import"./src-CK6bncSg.js";import{Qt as o}from"./sdk.gen-1aYqVbMj.js";import{G as s,W as c,f as l}from"./react-query.gen-CQLyoqYk.js";import{o as u}from"./auth-store-Kfxhs2oI.js";import{t as d}from"./client-feature-flag-store-C1kdd1EO.js";import{Ut as f}from"./index-PRnvH2Y1.js";import{t as p}from"./use-active-assistant-id-C-RHQ9f6.js";var m=e(t(),1),h=class extends Error{status;constructor(e,t){super(t),this.name=`SimulateMemoryRouterError`,this.status=e}};async function g(e,t,n){let{data:r,response:i}=await o({path:{assistant_id:e},body:t,signal:n,throwOnError:!1}),a=i?await i.clone().text().catch(()=>``):``;if(!i||!i.ok)throw new h(i?.status??0,a||i?.statusText||`Failed to simulate memory router`);if(!r)throw new h(i.status,`Empty response from memory router simulator endpoint`);return{response:r,rawRequest:JSON.stringify(t,null,2),rawResponse:_(a)}}function _(e){if(e.length===0)return e;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function v(e){return r({mutationFn:async t=>{if(!e)throw new h(0,`Missing assistantId`);return g(e,t)}})}function y(e){return n({...l({path:{assistant_id:e}}),enabled:!!e,staleTime:6e4})}function b(e){return n({...s({path:{assistant_id:e}}),enabled:!!e,staleTime:1440*60*1e3})}function x(e){return n({...c({path:{assistant_id:e}}),enabled:!!e,staleTime:1/0})}var S=i();function C(){let e=f(),t=u(),n=d.use.memoryRouterPlayground();return t?(0,S.jsx)($,{children:`Loading…`}):!e||!n?(0,S.jsx)($,{children:`Memory router playground is not available.`}):(0,S.jsx)(T,{})}var w={tier1:``,tier2:``,batch:``,profile:``,customPrompt:``};function T(){let e=p(),t=v(e),n=v(e),r=y(e),i=b(e),a=x(e),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)([{assistantMessage:``,userMessage:``}]),[u,d]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(u)return;let e=a.data?.nowText;typeof e==`string`&&o===``&&s(e)},[a.data?.nowText,o,u]);let[f,h]=(0,m.useState)(w),[g,_]=(0,m.useState)(w),[C,T]=(0,m.useState)(null),[D,k]=(0,m.useState)(null),j=c[c.length-1].userMessage,M=e=>{let r=e===`A`?f:g,i=e===`A`?T:k,a=e===`A`?t:n;i(null);let s;try{s=E(r)}catch(e){i(e instanceof Error?e.message:`Invalid override input`);return}let l=r.profile.trim().length>0?r.profile:void 0,u=r.customPrompt.trim().length>0?r.customPrompt:void 0,d=c.map((e,t)=>t===c.length-1?{...e,userMessage:e.userMessage.trim()}:e);a.mutate({recentTurnPairs:d,nowText:o,...s?{configOverrides:s}:{},...l===void 0?{}:{profileOverride:l},...u===void 0?{}:{routerPromptOverride:u}})},N=()=>{M(`A`),M(`B`)},P=j.trim().length>0,I=P&&!t.isPending,L=P&&!n.isPending;return(0,S.jsx)(`div`,{className:`flex h-full min-h-0 flex-col overflow-y-auto`,children:(0,S.jsxs)(`div`,{className:`mx-auto flex w-full max-w-[1280px] flex-col gap-6 p-6`,children:[(0,S.jsx)(ee,{}),(0,S.jsx)(O,{nowText:o,onNowTextChange:e=>{d(!0),s(e)},onReloadNowText:()=>{let e=a.data?.nowText;typeof e==`string`&&(s(e),d(!1))},nowTextLoading:a.isLoading,pairs:c,onPairsChange:l}),(0,S.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,S.jsx)(A,{paneId:`A`,overrides:f,onChange:h,onRun:()=>M(`A`),canRun:I,isRunning:t.isPending,profiles:r.data?.profiles??[],activeProfile:r.data?.activeProfile??null,defaultPromptTemplate:i.data?.template??``}),(0,S.jsx)(A,{paneId:`B`,overrides:g,onChange:_,onRun:()=>M(`B`),canRun:L,isRunning:n.isPending,profiles:r.data?.profiles??[],activeProfile:r.data?.activeProfile??null,defaultPromptTemplate:i.data?.template??``})]}),(0,S.jsx)(`div`,{className:`flex justify-end`,children:(0,S.jsx)(te,{onClick:N,disabled:!P||t.isPending||n.isPending,isRunning:t.isPending||n.isPending})}),(0,S.jsx)(ne,{visible:t.data!==void 0&&n.data!==void 0}),(0,S.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,S.jsx)(F,{paneId:`A`,userMessage:j,mutation:t,otherResult:n.data?.response,validation:C}),(0,S.jsx)(F,{paneId:`B`,userMessage:j,mutation:n,otherResult:t.data?.response,validation:D})]})]})})}function E(e){let t={...D(`tier1_size`,e.tier1),...D(`tier2_size`,e.tier2),...D(`batch_size`,e.batch)};return Object.keys(t).length===0?void 0:t}function D(e,t){let n=t.trim();if(n===``)return{};if(n===`null`)return{[e]:null};let r=Number(n);if(!Number.isInteger(r)||r<1)throw Error(`${e} must be a positive integer or 'null' (got "${n}")`);return{[e]:r}}function ee(){return(0,S.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,S.jsx)(`h1`,{className:`text-body-large-default`,style:{color:`var(--content-default)`},children:`Memory Router Playground`}),(0,S.jsxs)(`p`,{className:`text-body-medium-lighter`,style:{color:`var(--content-secondary)`},children:[`Dry-run the v4 router with custom tier/batch overrides. Read-only — no rows are written to `,(0,S.jsx)(`code`,{children:`memory_v2_injection_events`}),` or`,` `,(0,S.jsx)(`code`,{children:`memory_v2_activation_logs`}),`, and no activation state is mutated. Leave an override blank to inherit the live config value; enter`,` `,(0,S.jsx)(`code`,{children:`null`}),` to explicitly disable a tier.`]})]})}function O({nowText:e,onNowTextChange:t,onReloadNowText:n,nowTextLoading:r,pairs:i,onPairsChange:o}){let s=(e,t)=>{o(i.map((n,r)=>r===e?{...n,...t}:n))},c=()=>{o([{assistantMessage:``,userMessage:``},...i])},l=e=>{e!==i.length-1&&o(i.filter((t,n)=>n!==e))};return(0,S.jsx)(a,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,S.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:`Conversational context (shared by both panes)`}),(0,S.jsx)(k,{id:`memory-router-playground-now`,label:`<now> block`,value:e,onChange:t,rows:6,monospace:!0,placeholder:r?`Loading current NOW.md…`:`Pre-filled with the live NOW.md. Edit to test alternate states.`,trailing:(0,S.jsx)(`button`,{type:`button`,onClick:n,disabled:r,className:`rounded px-2 py-1 text-label-default`,style:{background:`var(--surface-overlay)`,color:`var(--content-secondary)`,border:`none`,cursor:r?`not-allowed`:`pointer`},children:`Reload live NOW.md`})}),(0,S.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,S.jsx)(`span`,{className:`text-label-default`,style:{color:`var(--content-secondary)`},children:`Recent (assistant, user) pairs · oldest first`}),(0,S.jsx)(`button`,{type:`button`,onClick:c,className:`rounded px-2 py-1 text-label-default`,style:{background:`var(--surface-overlay)`,color:`var(--content-secondary)`,border:`none`,cursor:`pointer`},children:`+ Add older pair`})]}),i.map((e,t)=>{let n=t===i.length-1;return(0,S.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border p-3`,style:{borderColor:`var(--border-base)`,background:`var(--surface-base)`},children:[(0,S.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,S.jsxs)(`span`,{className:`text-label-default`,style:{color:`var(--content-secondary)`},children:[`Pair `,t+1,` of `,i.length,n?` · most recent`:``]}),!n&&(0,S.jsx)(`button`,{type:`button`,onClick:()=>l(t),className:`rounded px-2 py-1 text-label-default`,style:{background:`transparent`,color:`var(--system-negative-strong)`,border:`none`,cursor:`pointer`},children:`Remove`})]}),(0,S.jsx)(k,{id:`memory-router-playground-pair-${t}-assistant`,label:`[assistant]: reply`,value:e.assistantMessage,onChange:e=>s(t,{assistantMessage:e}),rows:3,placeholder:t===0&&i.length===1?`Leave blank for a first-turn scenario.`:`Assistant's reply that came before the user message below.`}),(0,S.jsx)(k,{id:`memory-router-playground-pair-${t}-user`,label:n?`Just-arrived [user]: message`:`[user]: message`,value:e.userMessage,onChange:e=>s(t,{userMessage:e}),rows:3,placeholder:n?`e.g. what should we ship next`:`User's message.`,required:n})]},t)})]})})}function k({id:e,label:t,value:n,onChange:r,rows:i,placeholder:a,monospace:o,trailing:s,required:c}){return(0,S.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,S.jsxs)(`label`,{htmlFor:e,className:`text-label-default`,style:{color:`var(--content-secondary)`},children:[t,c?` *`:``]}),s]}),(0,S.jsx)(`textarea`,{id:e,value:n,onChange:e=>r(e.target.value),rows:i,placeholder:a,className:`rounded-md border px-3 py-2 text-body-medium-default`,style:{borderColor:`var(--border-base)`,background:`var(--surface-base)`,color:`var(--content-default)`,resize:`vertical`,...o?{fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace`}:{}}})]})}function A({paneId:e,overrides:t,onChange:n,onRun:r,canRun:i,isRunning:o,profiles:s,activeProfile:c,defaultPromptTemplate:l}){return(0,S.jsx)(a,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,S.jsxs)(`div`,{className:`text-body-medium-default`,style:{color:q(e)},children:[`Config `,e]}),(0,S.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,S.jsx)(N,{paneId:e,label:`tier1_size`,value:t.tier1,onChange:e=>n({...t,tier1:e})}),(0,S.jsx)(N,{paneId:e,label:`tier2_size`,value:t.tier2,onChange:e=>n({...t,tier2:e})}),(0,S.jsx)(N,{paneId:e,label:`batch_size`,value:t.batch,onChange:e=>n({...t,batch:e})})]}),(0,S.jsx)(M,{paneId:e,value:t.profile,onChange:e=>n({...t,profile:e}),profiles:s,activeProfile:c}),(0,S.jsx)(j,{paneId:e,value:t.customPrompt,onChange:e=>n({...t,customPrompt:e}),defaultTemplate:l}),(0,S.jsx)(`div`,{className:`flex justify-end`,children:(0,S.jsx)(`button`,{type:`button`,onClick:r,disabled:!i,className:`rounded-md px-4 py-2 text-body-medium-default transition-colors`,style:{background:i?`var(--system-positive-strong)`:`var(--surface-overlay)`,color:i?`var(--content-on-positive)`:`var(--content-disabled)`,border:`none`,cursor:i?`pointer`:`not-allowed`},children:o?`Running…`:`Run ${e}`})})]})})}function j({paneId:e,value:t,onChange:n,defaultTemplate:r}){let[i,a]=(0,m.useState)(!1),o=`memory-router-playground-${e}-prompt`,s=t.trim().length>0;return(0,S.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,S.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`text-label-default`,style:{color:`var(--content-secondary)`,background:`transparent`,border:`none`,padding:0,cursor:`pointer`,textAlign:`left`},children:[i?`▾`:`▸`,` System prompt`,` `,(0,S.jsxs)(`span`,{style:{color:`var(--content-tertiary)`},children:[`(`,s?`custom`:`bundled`,`)`]})]}),i&&(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>n(r),disabled:r.length===0,className:`rounded px-2 py-1 text-label-default`,style:{background:`var(--surface-overlay)`,color:`var(--content-secondary)`,border:`none`,cursor:r.length===0?`not-allowed`:`pointer`},children:`Load default`}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>n(``),disabled:!s,className:`rounded px-2 py-1 text-label-default`,style:{background:`var(--surface-overlay)`,color:`var(--content-secondary)`,border:`none`,cursor:s?`pointer`:`not-allowed`},children:`Reset`})]})]}),i&&(0,S.jsx)(`textarea`,{id:o,value:t,onChange:e=>n(e.target.value),rows:12,placeholder:`Custom router system prompt. Available placeholders:
2
2
  {{ASSISTANT_NAME}}, {{USER_NAME}}, {{PAGE_INDEX}}
3
3
  Leave blank to use the bundled template. "Load default" seeds the textarea with the bundled body for editing.`,className:`rounded-md border px-3 py-2 text-body-small-default`,style:{borderColor:`var(--border-base)`,background:`var(--surface-base)`,color:`var(--content-default)`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace`,resize:`vertical`,minHeight:`120px`}})]})}function M({paneId:e,value:t,onChange:n,profiles:r,activeProfile:i}){let a=`memory-router-playground-${e}-profile`,o=i!==null&&i.length>0?`inherit active (${i})`:`inherit active`;return(0,S.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,S.jsx)(`label`,{htmlFor:a,className:`text-label-default`,style:{color:`var(--content-secondary)`},children:`llm.profiles override`}),(0,S.jsxs)(`select`,{id:a,value:t,onChange:e=>n(e.target.value),className:`rounded-md border px-3 py-2 text-body-medium-default`,style:{borderColor:`var(--border-base)`,background:`var(--surface-base)`,color:`var(--content-default)`},children:[(0,S.jsx)(`option`,{value:``,children:o}),r.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))]})]})}function N({paneId:e,label:t,value:n,onChange:r}){let i=`memory-router-playground-${e}-${t}`;return(0,S.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,S.jsx)(`label`,{htmlFor:i,className:`text-label-default`,style:{color:`var(--content-secondary)`},children:t}),(0,S.jsx)(`input`,{id:i,value:n,onChange:e=>r(e.target.value),placeholder:`inherit`,className:`rounded-md border px-3 py-2 text-body-medium-default`,style:{borderColor:`var(--border-base)`,background:`var(--surface-base)`,color:`var(--content-default)`}})]})}function te({onClick:e,disabled:t,isRunning:n}){return(0,S.jsx)(`button`,{type:`button`,onClick:e,disabled:t,className:`rounded-md px-4 py-2 text-body-medium-default transition-colors`,style:{background:t?`var(--surface-overlay)`:`var(--primary-base)`,color:t?`var(--content-disabled)`:`var(--content-on-primary)`,border:`none`,cursor:t?`not-allowed`:`pointer`},children:n?`Running…`:`Run both`})}function ne({visible:e}){return e?(0,S.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 rounded-md px-4 py-2 text-label-default`,style:{background:`var(--surface-overlay)`,color:`var(--content-secondary)`},children:[(0,S.jsx)(P,{marker:`●`,markerColor:`var(--content-default)`,label:`in both`}),(0,S.jsx)(P,{marker:`◆`,markerColor:q(`A`),label:`A only`}),(0,S.jsx)(P,{marker:`◇`,markerColor:q(`B`),label:`B only`})]}):null}function P({marker:e,markerColor:t,label:n}){return(0,S.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,S.jsx)(`span`,{style:{color:t},children:e}),(0,S.jsx)(`span`,{children:n})]})}function F({paneId:e,userMessage:t,mutation:n,otherResult:r,validation:i}){let a=n.data;return(0,S.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,S.jsx)(R,{paneId:e}),i!==null&&(0,S.jsx)(Q,{message:i}),n.isError&&(0,S.jsx)(Q,{message:n.error instanceof Error?n.error.message:`Failed to run simulation`}),a!==void 0&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(z,{paneId:e,userMessage:t,result:a.response,otherResult:r}),(0,S.jsx)(I,{paneId:e,rawRequest:a.rawRequest,rawResponse:a.rawResponse})]})]})}function I({paneId:e,rawRequest:t,rawResponse:n}){let[r,i]=(0,m.useState)(!1);return(0,S.jsx)(a,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-2 p-4`,children:[(0,S.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`text-label-default`,style:{color:`var(--content-secondary)`,background:`transparent`,border:`none`,padding:0,cursor:`pointer`,textAlign:`left`},children:[r?`▾`:`▸`,` Raw API exchange`]}),r&&(0,S.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,S.jsx)(L,{label:`Request (Pane ${e})`,body:t}),(0,S.jsx)(L,{label:`Response (Pane ${e})`,body:n})]})]})})}function L({label:e,body:t}){return(0,S.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,S.jsx)(`span`,{className:`text-label-default`,style:{color:`var(--content-secondary)`},children:e}),(0,S.jsx)(`pre`,{className:`overflow-auto rounded-md border px-3 py-2 text-body-small-default`,style:{borderColor:`var(--border-base)`,background:`var(--surface-base)`,color:`var(--content-default)`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace`,maxHeight:`320px`,whiteSpace:`pre`},children:t.length===0?`(empty)`:t})]})}function R({paneId:e}){return(0,S.jsxs)(`div`,{className:`text-body-medium-default`,style:{color:q(e)},children:[`Pane `,e]})}function z({paneId:e,userMessage:t,result:n,otherResult:r}){let i=(0,m.useMemo)(()=>B(n,r),[n,r]),a=(0,m.useMemo)(()=>W(n),[n]);return(0,S.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,S.jsx)(H,{result:n,userMessage:t,otherResult:r,counts:(0,m.useMemo)(()=>V(i),[i])}),(0,S.jsx)(U,{result:n}),n.failureReason!==null&&(0,S.jsx)(Q,{message:`Router failure: ${n.failureReason}`}),a.length===0?(0,S.jsx)(X,{}):a.map(t=>(0,S.jsx)(Y,{paneId:e,source:t.source,slugs:t.slugs,scores:n.scores,diff:i},t.source))]})}function B(e,t){let n=new Map;if(t===void 0){for(let t of e.selectedSlugs)n.set(t,`both`);return n}let r=new Set(t.selectedSlugs);for(let t of e.selectedSlugs)n.set(t,r.has(t)?`both`:`only-here`);return n}function V(e){let t=0,n=0;for(let r of e.values())r===`both`?t++:n++;return{total:e.size,shared:t,unique:n}}function H({result:e,userMessage:t,otherResult:n,counts:r}){let i=[{label:`User message`,value:t},{label:`Total candidate pages`,value:e.totalCandidatePages.toLocaleString()},{label:`Selected`,value:`${e.selectedSlugs.length} (live max_page_ids: ${e.effectiveConfig.max_page_ids})`}];return n!==void 0&&i.push({label:`Diff`,value:`${r.shared} shared · ${r.unique} unique to this pane`}),(0,S.jsx)(a,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,S.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:`Summary`}),(0,S.jsx)(Z,{rows:i})]})})}function U({result:e}){let t=[`tier1_size`,`tier2_size`,`batch_size`,`max_page_ids`].map(t=>{let n=e.effectiveConfig[t],r=e.overrides[t];return{label:t,value:`${n===null?`null`:String(n)}${r===void 0?``:` (override)`}`}});return t.push({label:`llm.profiles override`,value:e.profileOverride===null?`inherit active`:`${e.profileOverride} (override)`}),t.push({label:`system prompt`,value:e.routerPromptOverridden?`custom`:`bundled`}),(0,S.jsx)(a,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,S.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:`Effective config`}),(0,S.jsx)(Z,{rows:t})]})})}function W(e){let t=new Map;for(let n of e.selectedSlugs){let r=e.sourceBySlug[n];if(r===void 0)continue;let i=t.get(r)??[];i.push(n),t.set(r,i)}return[...t.keys()].sort((e,t)=>G(e)-G(t)).map(e=>({source:e,slugs:t.get(e)}))}function G(e){return e===`tier1`?0:e===`tier2`?1:e.startsWith(`tier3:`)?2+Number(e.slice(6)):2**53-1}function K(e){return e===`tier1`?`tier 1`:e===`tier2`?`tier 2`:e.startsWith(`tier3:`)?`tier 3 · b${e.slice(6)}`:e}function q(e){return e===`A`?`var(--system-mid-strong)`:`var(--primary-base)`}function J(e,t){return t===`both`?{color:`var(--content-default)`,marker:`●`}:{color:q(e),marker:e===`A`?`◆`:`◇`}}function Y({paneId:e,source:t,slugs:n,scores:r,diff:i}){return(0,S.jsx)(a,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,S.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,S.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:K(t)}),(0,S.jsxs)(`span`,{className:`text-label-default`,style:{color:`var(--content-secondary)`},children:[n.length,` `,n.length===1?`page`:`pages`]})]}),(0,S.jsx)(`ul`,{className:`flex flex-col gap-1`,children:n.map(n=>{let{color:a,marker:o}=J(e,i.get(n)??`only-here`);return(0,S.jsxs)(`li`,{className:`flex items-baseline justify-between gap-3`,children:[(0,S.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,S.jsx)(`span`,{style:{color:a},children:o}),(0,S.jsx)(`code`,{className:`text-body-medium-default`,style:{color:a},children:n})]}),t===`tier2`&&(0,S.jsxs)(`span`,{className:`tabular-nums text-label-default`,style:{color:`var(--content-secondary)`},children:[`EMA `,(r[n]??0).toFixed(3)]})]},n)})})]})})}function X(){return(0,S.jsx)(a,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-2 p-4`,children:[(0,S.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:`No pages selected`}),(0,S.jsx)(`span`,{className:`text-label-default`,style:{color:`var(--content-secondary)`},children:`The router returned an empty selection. Try a more specific query, or relax the override values.`})]})})}function Z({rows:e}){return(0,S.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map(({label:e,value:t})=>(0,S.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,S.jsx)(`span`,{className:`shrink-0 text-label-default`,style:{color:`var(--content-secondary)`},children:e}),(0,S.jsx)(`span`,{className:`text-right text-body-medium-lighter`,style:{color:`var(--content-default)`},children:t})]},e))})}function Q({message:e}){return(0,S.jsx)(`div`,{className:`rounded-md px-4 py-3 text-body-medium-default`,style:{background:`var(--surface-overlay)`,color:`var(--system-negative-strong)`},children:e})}function $({children:e}){return(0,S.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8 text-label-default`,style:{color:`var(--content-tertiary)`},children:e})}export{C as MemoryRouterPlaygroundPage};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{t as n}from"./button-D7s2Q_uG.js";import{t as r}from"./jsx-runtime-CVSDxk6A.js";import"./src-CK6bncSg.js";import{t as i}from"./x-KVxA2ZL0.js";import{fi as a}from"./index-BIDC22lX.js";var o=e(t(),1),s=r(),c=`(min-width: 640px)`,l=[`a[href]`,`button:not([disabled])`,`input:not([disabled])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`);function u({open:e,onClose:t,children:r,title:a}){let u=(0,o.useRef)(null),d=(0,o.useRef)(null),f=(0,o.useRef)(t);return(0,o.useEffect)(()=>{f.current=t}),(0,o.useEffect)(()=>{if(!e)return;d.current?.focus();let t=document.body.style.overflow;document.body.style.overflow=`hidden`;let n=window.matchMedia(c),r=e=>{e.matches&&f.current()};n.addEventListener(`change`,r);let i=e=>{if(e.key===`Escape`){f.current();return}if(e.key!==`Tab`||!u.current)return;let t=u.current.querySelectorAll(l),n=t[0],r=t[t.length-1];if(!n||!r){e.preventDefault();return}let i=document.activeElement,a=u.current.contains(i);e.shiftKey?(!a||i===n)&&(e.preventDefault(),r.focus()):(!a||i===r)&&(e.preventDefault(),n.focus())};return document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`keydown`,i),n.removeEventListener(`change`,r),document.body.style.overflow=t}},[e]),e?(0,s.jsxs)(`div`,{ref:u,className:`fixed inset-0 sm:hidden`,style:{zIndex:40},role:`dialog`,"aria-modal":`true`,"aria-label":a,children:[(0,s.jsx)(`button`,{type:`button`,"aria-label":`Close sidebar`,className:`absolute inset-0 h-full w-full cursor-default`,style:{background:`rgba(0, 0, 0, 0.4)`,zIndex:40},onClick:t}),(0,s.jsxs)(`aside`,{className:`relative flex h-full w-[80vw] max-w-xs flex-col shadow-xl`,style:{background:`var(--surface-lift)`,borderRight:`1px solid var(--border-base)`,zIndex:50,paddingTop:`var(--safe-area-inset-top, env(safe-area-inset-top, 0px))`,paddingBottom:`var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))`,paddingLeft:`var(--safe-area-inset-left, env(safe-area-inset-left, 0px))`},children:[(0,s.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b px-4 py-3`,style:{borderColor:`var(--border-base)`},children:[(0,s.jsx)(`span`,{className:`text-title-small`,style:{color:`var(--content-default)`},children:a}),(0,s.jsx)(n,{ref:d,type:`button`,variant:`ghost`,size:`compact`,iconOnly:(0,s.jsx)(i,{"aria-hidden":!0}),onClick:t,"aria-label":`Close`,tintColor:`var(--content-tertiary)`})]}),(0,s.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:r})]})]}):null}function d({onClick:e}){return(0,s.jsx)(n,{type:`button`,variant:`ghost`,iconOnly:(0,s.jsx)(a,{"aria-hidden":!0}),onClick:e,"aria-label":`Open sidebar`,tintColor:`var(--content-secondary)`,className:`sm:hidden`})}export{d as n,u as t};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-DJZBPgpf.js";import{t as n}from"./button-D7s2Q_uG.js";import{t as r}from"./jsx-runtime-CVSDxk6A.js";import"./src-CK6bncSg.js";import{t as i}from"./x-KVxA2ZL0.js";import{fi as a}from"./index-PRnvH2Y1.js";var o=e(t(),1),s=r(),c=`(min-width: 640px)`,l=[`a[href]`,`button:not([disabled])`,`input:not([disabled])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`);function u({open:e,onClose:t,children:r,title:a}){let u=(0,o.useRef)(null),d=(0,o.useRef)(null),f=(0,o.useRef)(t);return(0,o.useEffect)(()=>{f.current=t}),(0,o.useEffect)(()=>{if(!e)return;d.current?.focus();let t=document.body.style.overflow;document.body.style.overflow=`hidden`;let n=window.matchMedia(c),r=e=>{e.matches&&f.current()};n.addEventListener(`change`,r);let i=e=>{if(e.key===`Escape`){f.current();return}if(e.key!==`Tab`||!u.current)return;let t=u.current.querySelectorAll(l),n=t[0],r=t[t.length-1];if(!n||!r){e.preventDefault();return}let i=document.activeElement,a=u.current.contains(i);e.shiftKey?(!a||i===n)&&(e.preventDefault(),r.focus()):(!a||i===r)&&(e.preventDefault(),n.focus())};return document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`keydown`,i),n.removeEventListener(`change`,r),document.body.style.overflow=t}},[e]),e?(0,s.jsxs)(`div`,{ref:u,className:`fixed inset-0 sm:hidden`,style:{zIndex:40},role:`dialog`,"aria-modal":`true`,"aria-label":a,children:[(0,s.jsx)(`button`,{type:`button`,"aria-label":`Close sidebar`,className:`absolute inset-0 h-full w-full cursor-default`,style:{background:`rgba(0, 0, 0, 0.4)`,zIndex:40},onClick:t}),(0,s.jsxs)(`aside`,{className:`relative flex h-full w-[80vw] max-w-xs flex-col shadow-xl`,style:{background:`var(--surface-lift)`,borderRight:`1px solid var(--border-base)`,zIndex:50,paddingTop:`var(--safe-area-inset-top, env(safe-area-inset-top, 0px))`,paddingBottom:`var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))`,paddingLeft:`var(--safe-area-inset-left, env(safe-area-inset-left, 0px))`},children:[(0,s.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b px-4 py-3`,style:{borderColor:`var(--border-base)`},children:[(0,s.jsx)(`span`,{className:`text-title-small`,style:{color:`var(--content-default)`},children:a}),(0,s.jsx)(n,{ref:d,type:`button`,variant:`ghost`,size:`compact`,iconOnly:(0,s.jsx)(i,{"aria-hidden":!0}),onClick:t,"aria-label":`Close`,tintColor:`var(--content-tertiary)`})]}),(0,s.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:r})]})]}):null}function d({onClick:e}){return(0,s.jsx)(n,{type:`button`,variant:`ghost`,iconOnly:(0,s.jsx)(a,{"aria-hidden":!0}),onClick:e,"aria-label":`Open sidebar`,tintColor:`var(--content-secondary)`,className:`sm:hidden`})}export{d as n,u as t};