try{let e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="36028f45-58a9-4a46-9277-46d43eda529a",e._sentryDebugIdIdentifier="sentry-dbid-36028f45-58a9-4a46-9277-46d43eda529a")}catch(e){}{let e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=Object.assign({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:anthropic-apps":!0})}"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[36016],{0xe0c26d90:(e,t,n)=>{n.d(t,{rs:()=>_,$H:()=>m,b2:()=>k,oZ:()=>q,OV:()=>C,tn:()=>T,nB:()=>L,rW:()=>S,bo:()=>E,Cq:()=>w,b4:()=>A,yL:()=>I,VX:()=>G,ak:()=>x});var a=n(0x12c9046cd),r=n(0x14de19ae8),i=n(0x49fac030),s=n(0xac309a83),c=n(0x1b813d90),u=n(0x1bd175d8c),o=n(0x17e725145),l=n(0x20892a038),d=n(0x1eb4fc9be),h=n(0x4d348f95),g=n(0xfc89b4a4),p=n(0x22be9474c),y=n(0x21fe74567),v=n(0x18175ce17),f=n(0xc6857cab);let b="github_success";function _(e){var t;return null!=(t=null==e?void 0:e.repos.some(e=>{var t;return(null==(t=e.status)?void 0:t.app_installed)===!0}))&&t}function m(e){let{isGithubAuthenticated:t,isListGithubReposLoading:n,githubReposData:a}=e;return!1!==t&&(void 0===t||n?void 0:_(a))}let L=function(){var e;let{callerIdentifier:t,toggleGithubModalOpen:n,fetchImmediately:s=!1,pathname:c,queryString:o,shouldRedirectToDesktopApp:l}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{activeOrganization:d}=(0,r.YL)(),p=null==d?void 0:d.uuid,f=w(),[_,m]=(0,g.useState)(s),L=(e=>{let{shouldFetch:t=!1}=e,{activeOrganization:n}=(0,r.YL)(),s=null==n?void 0:n.uuid,c=w();return(0,a.Sk)("/api/organizations/".concat(s,"/sync/github/auth"),{queryKey:[i.Hv,{orgUuid:s}],enabled:!!(t&&n&&c),meta:{noToast:!0}})})({shouldFetch:_}),S=(0,g.useCallback)(async function(){var e,t;let{forceRefetch:n=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return!_||n?(m(!0),null==(e=(await L.refetch()).data)?void 0:e.is_authenticated):null==(t=L.data)?void 0:t.is_authenticated},[L,_]),{mutate:A}=(0,a.L2)("/api/organizations/".concat(p,"/sync/github/auth/start"),"POST",{enabled:!!(d&&f),onSuccess:e=>{if(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(0===t.length)return!1;try{if(!e.startsWith("http://")&&!e.startsWith("https://"))return!1;let n=new URL(e);return"https:"===n.protocol&&t.some(e=>n.hostname===e||n.hostname.endsWith(".".concat(e)))}catch(e){return!1}}(e.redirect_url,["github.com"]))window.location.href=e.redirect_url;else throw Error("Invalid redirect URL received from auth endpoint")}}),I="".concat(b,"=").concat(t).concat(o?"&".concat(o):"");(0,v.FZ)({callerIdentifier:t,successParam:b,handleOpen:()=>{null==n||n(!0)}});let T=(0,h.useSearchParams)(),E=(0,u.V)(),k=(0,g.useRef)(!1),x=(0,h.usePathname)(),G=(0,y.d)({pathname:c||x,searchParams:T,queryString:I,shouldOpenInClaudeApp:E||!!l});return{checkIsGithubAuthenticated:S,initGithubAuth:()=>{if(f){if(E)return void window.open("/settings/connectors?open_in_browser=1&auth_start=github&origin=".concat(G));k.current||(k.current=!0,A({pre_auth_state:{origin:G}}))}},isGithubAuthenticated:null==(e=L.data)?void 0:e.is_authenticated,isLoading:L.isLoading}},S=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{activeOrganization:t}=(0,r.YL)(),n=null==t?void 0:t.uuid,s=w(),c=(0,o.useQueryClient)();return(0,a.L2)("/api/organizations/".concat(n,"/sync/github/auth"),"DELETE",{enabled:!!(t&&s),...e,onSuccess:function(){for(var t,a=arguments.length,r=Array(a),s=0;s{let{data:e}=(0,v.LN)(),t=(0,r.mV)(),n=!!(Array.isArray(e)&&e.find(e=>e.type===c.v8.GITHUB&&e.enabled));return!!(!f.env.NEXT_PUBLIC_DISABLE_GITHUB_INTEGRATION&&(!t||n))},A=()=>{let{activeOrganization:e}=(0,r.YL)(),t=null==e?void 0:e.uuid,n=w();return(0,a.Sk)("/api/organizations/".concat(t,"/sync/github/repos"),{queryKey:[i.jL,{orgUuid:t}],enabled:!!(e&&n),meta:{noToast:!0}})},I=function(){let{skipStatus:e,enabled:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{activeOrganization:n}=(0,r.YL)(),i=null==n?void 0:n.uuid,c=w(),u=(0,s.fS)("bad_moon_rising_skip_status"),o=null!=e?e:u,l=new URLSearchParams({skip_status:o.toString()}).toString();return(0,a.Sk)("/api/organizations/".concat(i,"/code/repos?").concat(l),{queryKey:["SYNC_GH_REPOS_WITH_STATUS_QUERY_KEY",{orgUuid:i,skipStatus:o}],enabled:!!(n&&i&&c&&t),meta:{noToast:!0}})},T=e=>{var t;let{owner:n,repo:s,branch:c}=e,u=(e=>{let{owner:t,repo:n,branch:s}=e,{activeOrganization:c}=(0,r.YL)(),u=null==c?void 0:c.uuid,o=w(),l=new URLSearchParams({owner:null!=t?t:"",repo:null!=n?n:""}).toString();return(0,a.Sk)("/api/organizations/".concat(u,"/sync/github/repo?").concat(l),{queryKey:[i.yB,{orgUuid:u,owner:t,repo:n}],enabled:!!(t&&n&&!s&&c&&o),meta:{noToast:!0}})})({owner:n,repo:s,branch:c}),o=(e=>{let{owner:t,repo:n,branch:s}=e,{activeOrganization:c}=(0,r.YL)(),u=null==c?void 0:c.uuid,o=w();return(0,a.Sk)("/api/organizations/".concat(u,"/sync/github/repo/").concat(t,"/").concat(n,"/tree/").concat(s),{queryKey:[i.o6,{orgUuid:u,owner:t,repo:n,branch:s}],staleTime:3e5,enabled:!!(t&&n&&s&&c&&o),meta:{noToast:!0}})})({owner:n,repo:s,branch:c||(null==(t=u.data)?void 0:t.default_branch)});return{data:{repo:u.data,tree:o.data},isFetching:u.isFetching||o.isFetching,error:u.error||o.error}},E=e=>{let{repoBranches:t,enabled:n=!0}=e,{activeOrganization:a}=(0,r.YL)(),s=null==a?void 0:a.uuid,c=w(),u=[...t].sort((e,t)=>"".concat(e.repo,":").concat(e.branch).localeCompare("".concat(t.repo,":").concat(t.branch)));return(0,l.useQuery)({queryKey:[i.uh,{orgUuid:s,repoBranches:u}],queryFn:async()=>{let e=await fetch("/api/github/organizations/".concat(s,"/github_batch_branch_status"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({repo_branches:u})});if(!e.ok)throw Error("Failed to fetch branch statuses: ".concat(e.status));return e.json()},enabled:!!(a&&c&&u.length>0&&n),staleTime:5e3,refetchOnWindowFocus:!0,placeholderData:d.rX})},k=()=>{var e;let{activeOrganization:t}=(0,r.YL)(),n=null==t?void 0:t.uuid,{data:s,isLoading:c}=(0,a.Sk)("/api/organizations/".concat(n,"/sync/github/auth"),{queryKey:[i.Hv,{orgUuid:n}],enabled:!!t,meta:{noToast:!0}}),u=null==s?void 0:s.is_authenticated,{data:o,isLoading:l}=(0,a.Sk)("/api/organizations/".concat(n,"/sync/github/repos"),{queryKey:[i.jL,{orgUuid:n}],enabled:!!(t&&u),meta:{noToast:!0}}),{data:d,isLoading:h}=(0,p.Nj)(null==t?void 0:t.uuid),y=(0,g.useMemo)(()=>{var e,t;return new Set((null!=(t=null==d||null==(e=d.settings)?void 0:e.vcs_connections)?t:[]).filter(e=>"github"===e.type).map(e=>e.org_name))},[null==d||null==(e=d.settings)?void 0:e.vcs_connections]);return{data:{orgs:(0,g.useMemo)(()=>{let e=[],t=new Set;if(o)for(let n of o){let a=n.owner;if("Organization"!==a.type)continue;let r=a.login;t.has(r)||(t.add(r),e.push({id:r,login:r,selectedForAnalytics:y.has(r)}))}return e},[o,y])},isLoading:c||h||l,isGithubAuthenticated:u}},x=()=>{var e,t;let{activeOrganization:n}=(0,r.YL)(),a=(0,o.useQueryClient)(),{data:s}=(0,p.Nj)(null==n?void 0:n.uuid),{mutate:c,isPending:u}=(0,p.NE)({onSuccess:e=>{a.setQueryData([i.i5,null==n?void 0:n.uuid],e)}}),l=(0,g.useCallback)(e=>{c({vcs_connections:e})},[c]),d=(0,g.useCallback)((e,t)=>{var n,a;let r=null!=(a=null==s||null==(n=s.settings)?void 0:n.vcs_connections)?a:[];r.some(t=>"github"===t.type&&t.org_name===e)||l([...r,{type:"github",org_name:e,org_id:t}])},[null==s||null==(e=s.settings)?void 0:e.vcs_connections,l]),h=(0,g.useCallback)(e=>{var t,n;l((null!=(n=null==s||null==(t=s.settings)?void 0:t.vcs_connections)?n:[]).filter(t=>"github"!==t.type||t.org_name!==e))},[null==s||null==(t=s.settings)?void 0:t.vcs_connections,l]);return{updateVcsConnections:l,addGithubOrg:d,removeGithubOrg:h,isPending:u}},G=e=>{let t,{repo:n,branch:a,enabled:s=!0}=e,{activeOrganization:c}=(0,r.YL)(),u=null==c?void 0:c.uuid,d=(0,o.useQueryClient)(),h=[i.uh,{orgUuid:u}];for(let[,e]of d.getQueriesData({queryKey:h,exact:!1}))if((null==e?void 0:e.branch_statuses)&&(t=e.branch_statuses.find(e=>e.repo===n&&e.branch===a)))break;let{data:g}=(e=>{let{repo:t,branch:n,enabled:a=!0}=e,{activeOrganization:s}=(0,r.YL)(),c=null==s?void 0:s.uuid,u=w();return(0,l.useQuery)({queryKey:[i.i8,{orgUuid:c,repo:t,branch:n}],queryFn:async()=>{let e=await fetch("/api/github/organizations/".concat(c,"/github_batch_branch_status"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({repo_branches:[{repo:t,branch:n}]})});if(!e.ok)throw Error("Failed to fetch single branch status: ".concat(e.status));return(await e.json()).branch_statuses[0]},enabled:!!(s&&u&&t&&n&&a),staleTime:5e3,refetchOnWindowFocus:!0})})({repo:n,branch:a,enabled:s});return!g&&t?t:g&&!t||g?g:void 0},C=()=>{let{activeOrganization:e}=(0,r.YL)(),t=null==e?void 0:e.uuid;return(0,a.L2)("/api/github/organizations/".concat(t,"/generate_pr_content"),"POST",{enabled:!!e})},q=function(){let{onSuccess:e,onError:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{activeOrganization:n}=(0,r.YL)(),s=null==n?void 0:n.uuid,c=(0,o.useQueryClient)();return(0,a.L2)("/api/github/organizations/".concat(s,"/github_create_pr"),"POST",{enabled:!!n,onSuccess:(t,n)=>{let a={number:t.number,additions:0,deletions:0,commits:0,state:t.state,url:t.html_url};c.setQueryData([i.i8,{orgUuid:s,repo:n.repo,branch:n.head}],e=>e?{...e,pull_request:a}:e);let r=n.head.includes(":")?n.head.split(":")[1]:n.head;c.setQueriesData({queryKey:[i.uh]},e=>e?{...e,branch_statuses:e.branch_statuses.map(e=>e.branch===r?{...e,pull_request:a}:e)}:e),null==e||e(t)},onError:t})}},0x18175ce17:(e,t,n)=>{n.d(t,{Cg:()=>z,Dd:()=>E,FZ:()=>I,Kn:()=>G,LN:()=>S,TI:()=>q,X0:()=>N,Ys:()=>Q,dJ:()=>P,eL:()=>k,fe:()=>V,hm:()=>C,kO:()=>K,ob:()=>O,ph:()=>A,qi:()=>D,tS:()=>L,vm:()=>Y,xc:()=>w,z3:()=>T});var a=n(0x17aa9d8d7),r=n(0x12c9046cd),i=n(0x14de19ae8),s=n(0x139b5e710),c=n(0x1016c6ed2),u=n(0x49fac030),o=n(0xac309a83),l=n(0x1b813d90),d=n(0x1bd175d8c),h=n(0x78b33fbd),g=n(0x17e725145),p=n(0x4d348f95),y=n(0xfc89b4a4),v=n(0x1ab0d1ca1),f=n(0x21fe74567),b=n(0x4d9fc74e),_=n(0xe824fb1c),m=n(0xc6857cab);let L=e=>e.type===l.v8.GITHUB?{sync_source_type:l.v8.GITHUB,sync_source_config:e.config}:e.type===l.v8.GDRIVE?{sync_source_type:l.v8.GDRIVE,sync_source_config:e.config}:null,S=()=>{let{activeOrganization:e}=(0,i.YL)(),t=null==e?void 0:e.uuid;return(0,r.Sk)("/api/organizations/".concat(t,"/sync/settings"),{queryKey:[u._V,{orgUuid:t}],enabled:!!e})},w=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{activeOrganization:t}=(0,i.YL)(),n=null==t?void 0:t.uuid,a=(0,g.useQueryClient)();return(0,r.Qv)("/api/organizations/".concat(n,"/sync/settings"),"PUT",(e,t)=>{let{type:n,enabled:a}=e;t||(t=[]);let r=t.map(e=>e.type===n?{...e,enabled:a}:e);return r.some(e=>e.type===n)?r:[...t,{type:n,enabled:a}]},{queryKey:[u._V,{orgUuid:n}],enabled:!!t,onSuccess:async function(){for(var t,r=arguments.length,i=Array(r),s=0;s0&&void 0!==arguments[0]?arguments[0]:{},{activeOrganization:t}=(0,i.YL)(),n=null==t?void 0:t.uuid,a=(0,g.useQueryClient)(),s=(0,o.fS)("kingfisher_enabled"),c=(0,o.fS)("apps_use_bananagrams"),l=(0,h.useLayer)("trials_freemium").get("free_integrations",!1);return(0,r.Qv)("/api/organizations/".concat(n,"/sync/settings/config"),"POST",(e,t)=>{let{type:n,config:a}=e;return t||(t=[]),t.map(e=>e.type===n?{...e,config:{...e.config,...a}}:e)},{queryKey:[u._V,{orgUuid:n}],enabled:!!(t&&(s||l)&&c),onSuccess:async function(){for(var t,r=arguments.length,i=Array(r),s=0;s{let{callerIdentifier:t,successParam:n,handleOpen:a}=e,r=(0,p.useSearchParams)(),i=(0,y.useRef)(!1);(0,y.useEffect)(()=>{!r.has(n)||i.current||t&&t!==r.get(n)||(i.current=!0,((e,t)=>{let n=new URLSearchParams(Array.from(t.entries()));n.delete(e);let a=n.toString()?"?".concat(n.toString()):"",r=window.location.pathname+a;window.history.replaceState({...window.history.state,as:r,url:r},"",r)})(n,r),a())},[r,t,a,n])},T=e=>{let t;return t=e.status.state,[l.I5.CREATED,l.I5.PENDING,l.I5.UPDATING].includes(t)},E=e=>[l.I5.FAILED,l.I5.UPDATE_FAILED].includes(e.status.state),k=()=>{let{addError:e}=(0,s.Yf)(),t=(0,g.useQueryClient)();return(n,a)=>{(e=>{if(e instanceof c.LG)return e instanceof c.LG&&"access_denied"===e.errorCode})(n)&&(e("Please try again. You may need to reconnect with your ".concat(l.sb[a.sync_source_type]," account."),{error:n}),u.ku.forEach(e=>{t.invalidateQueries({queryKey:[e]})}),t.invalidateQueries({queryKey:[u.GC]}))}},x={[l.v8.GCAL]:"enabled_foccacia",[l.v8.GMAIL]:"enabled_sourdough"},G=()=>(0,h.useLayer)("trials_freemium").get("free_integrations",!1),C=e=>{let t=(0,i.mV)(),{data:n}=S(),a=!!(Array.isArray(n)&&n.find(t=>t.type===e&&t.enabled));return!t||a},q={"https://mcp-server-gcal-586545259222.us-central1.run.app/sse":l.v8.GCAL,"https://mcp-server-gcal-586545259222.us-central1.run.app/mcp":l.v8.GCAL,"https://gcal.mcp.claude.com/mcp":l.v8.GCAL,"https://gcal.mcp.staging.ant.dev/mcp":l.v8.GCAL,"https://mcp-server-gmail-110131437935.us-central1.run.app/sse":l.v8.GMAIL,"https://mcp-server-gmail-110131437935.us-central1.run.app/mcp":l.v8.GMAIL,"https://gmail.mcp.claude.com/mcp":l.v8.GMAIL,"https://gmail.mcp.staging.ant.dev/mcp":l.v8.GMAIL,"https://api.anthropic.com/mcp/gdrive/sse":l.v8.GDRIVE,"https://api.anthropic.com/mcp/gdrive/mcp":l.v8.GDRIVE,"https://api-staging.anthropic.com/mcp/gdrive/sse":l.v8.GDRIVE,"https://api-staging.anthropic.com/mcp/gdrive/mcp":l.v8.GDRIVE},D=e=>{let t;return t=(0,_.Uz)({type:"remote"}),t.find(t=>t.url&&q[t.url]===e)},P=e=>!!D(e),Y=()=>(0,o.fS)("enabled_brioche"),K=()=>(0,o.fS)("mcp_gdrive"),Q=e=>{let t=Y(),n=K(),a=C(e),r=(e=>{let t="cinnabon_enabled";switch(e){case l.v8.GCAL:case l.v8.GMAIL:t="pumpernickel_enabled";break;case l.v8.GDRIVE:t="kingfisher_enabled";break;default:t="cinnabon_enabled"}let n=(0,o.fS)(t),a=G();return!m.env.NEXT_PUBLIC_DISABLE_INTEGRATIONS&&(n||a)})(e),i=P(e),s=e===l.v8.GDRIVE?n:t;return!!(r&&(a||s&&i))},R=e=>"sfdc"===e?"salesforce":"gdrive"===e?"mcp/drive":e,z=e=>{let t=D(e);return t?{isFetched:!0,isAuthenticated:!!t.isConnected,server_uuid:t.uuid}:{isFetched:!1,isAuthenticated:!1,server_uuid:void 0}},O=function(e){let{callerIdentifier:t,handleAuthSuccess:n,pathname:a,queryString:c}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=K(),o=Y(),h=e===l.v8.GDRIVE?u:o,_=((e,t)=>{let{pathname:n,queryString:a,callerIdentifier:r}=t,i=D(e),s=Q(e),c=z(e),u=r?"".concat(e,"_success=").concat(r).concat(a?"&".concat(a):""):a,o=(0,b.QD)({pathname:n,queryString:u});return{isAuthenticated:!!s&&!!i&&c.isAuthenticated,startAuth:()=>{s&&i&&o({uuid:i.uuid,url:i.url})},disconnect:()=>{},isFetched:!!i&&c.isFetched}})(e,{pathname:a,queryString:c,callerIdentifier:t}),{activeOrganization:m}=(0,i.YL)(),L=null==m?void 0:m.uuid,S=(0,p.usePathname)(),w=(0,p.useSearchParams)(),{addSuccess:A}=(0,s.Yf)(),T=(0,v.A)(),E=Q(e),k=(0,g.useQueryClient)(),x=(0,d.V)(),{data:G,isFetched:C}=(0,r.Sk)("/api/organizations/".concat(L,"/sync/").concat(R(e),"/auth"),{queryKey:["sync_".concat(e,"_auth_status"),{orgUuid:L}],enabled:!!(m&&E)}),q=(0,y.useRef)(!1),{mutate:P}=(0,r.L2)("/api/organizations/".concat(L,"/sync/").concat(R(e),"/auth/start"),"POST",{enabled:!!(m&&E)&&!h,onSuccess:e=>{window.location.href=e.redirect_url}});I({callerIdentifier:t,successParam:"".concat(e,"_success"),handleOpen:()=>{A(T.formatMessage({defaultMessage:"Connected to {integrationName}",id:"g0plFfAZAH"},{integrationName:l.sb[e]})),null==n||n(!0)}});let{mutate:O}=(0,r.L2)("/api/organizations/".concat(L,"/sync/").concat(R(e),"/auth"),"DELETE",{enabled:!!(m&&E)&&!h,onSuccess:()=>{k.invalidateQueries({queryKey:["sync_".concat(e,"_auth_status"),{orgUuid:L}]})}});return h&&_.isFetched?{..._,authBreakdown:{mcp:E&&_.isAuthenticated,firstParty:E&&!!(null==G?void 0:G.is_authenticated)},mcpServerGated:h}:{isAuthenticated:E&&!!(null==G?void 0:G.is_authenticated),startAuth:()=>{if(!q.current&&E){let n="".concat(e,"_success=").concat(t).concat(c?"&".concat(c):""),r=(0,f.d)({pathname:a||S,searchParams:w,queryString:n,shouldOpenInClaudeApp:x});if(x){window.location.href="/settings/connectors?open_in_browser=1&auth_start=".concat(e,"&origin=").concat(r);return}q.current=!0,P({pre_auth_state:{origin:r},redirect_uri:new URL("/connect/".concat(R(e),"/callback"),window.location.origin).toString()})}},disconnect:O,isFetched:C,authBreakdown:{mcp:E&&_.isAuthenticated,firstParty:E&&!!(null==G?void 0:G.is_authenticated)},mcpServerGated:h}},N=(e,t)=>{var n,a;let r=Y(),s=K(),c=e===l.v8.GDRIVE?s:r,u=Q(e),{account:o}=(0,i.YL)(),d=x[e];return!d||c?u:u&&(t?!!(null==t||null==(n=t.conversationSettings)?void 0:n[d]):!!(null==o||null==(a=o.settings)?void 0:a[d]))},V=()=>{let{account:e}=(0,i.YL)(),{mutate:t}=(0,a.yJ)();return{toggleIntegrationEnabled:(n,a)=>{if(!e)return;let r=x[n];r&&t({[r]:a})}}}}}]);