javascript:(async()=>{var Z="MESSAGE_VISIBILITY_EXTERNAL",St=t=>/client|rider|eater/i.test(t.userType??""),_t=t=>/driver|partner|courier/i.test(t.userType??""),It=t=>/voice|call|phone/i.test(t.modality??""),At=t=>/solved|closed|resolved|archived/i.test(t.status??""),kt=t=>t.messages.some(e=>e.initiatorType==="INITIATOR_TYPE_USER"&&e.visibility===Z),Mt=t=>t.messages.some(e=>e.initiatorType==="INITIATOR_TYPE_AGENT"&&e.visibility===Z),Q=t=>It(t)&&t.hasSuccess;function tt(t){let e=[];if(t.length){let o=t.every(At);e.push(o?{label:"Investigation Closed",tone:"ok",title:"Every selected contact is closed."}:{label:"Investigation Ongoing",tone:"warn",title:"At least one selected contact is not closed."})}let n=t.filter(St);if(n.length){let o=n.some(kt)||n.some(Q);e.push(o?{label:"Rider inbound made",tone:"ok",title:"The rider wrote in or a successful call to the rider was found."}:{label:"No rider inbound",tone:"warn",title:"The rider never wrote in and no successful call to the rider was found."})}let r=t.filter(_t);if(r.length){let o=r.some(Mt)||r.some(Q);e.push(o?{label:"Driver outreach made",tone:"ok",title:"We sent the driver an external message or a successful call to the driver was found."}:{label:"No driver outreach",tone:"warn",title:"We never sent the driver an external message and no successful call to the driver was found."})}return e}var Ut="__AUTO_DRAFTER_URL__";function Gt(t){let e=new TextEncoder().encode(t),n="";for(let r=0;r"']+/g;var Nt="https://blissnxt.uberinternal.com/hydrator/graphql";async function D(t,e,n={}){let o=await(n.fetch??globalThis.fetch)(`${Nt}?opName=${t.opName}`,{method:"POST",credentials:"include",signal:n.signal,headers:{"content-type":"application/json","x-csrf-token":"x","rpc-procedure":t.rpcProcedure,...n.headers},body:JSON.stringify({operationName:t.opName,variables:e,query:t.query})});if(!o.ok)throw new Error(`Bliss ${t.opName} HTTP ${o.status} ${o.statusText}`);let s=await o.json();if(!s.data){if(s.errors?.length){let l=s.errors.map(x=>x.message).join("; ");throw new Error(`Bliss ${t.opName} GraphQL error: ${l}`)}throw new Error(`Bliss ${t.opName} returned no data`)}return s.data}var nt=`query getContactContext($contactId: String) {%0A hydrationGetContactContext(%0A in: {%0A contactCustomRequest: {%0A contactId: {value: $contactId}%0A includeInlineAttachmentUrl: true%0A }%0A contactNestedParams: {%0A requesterRequest: {%0A fieldsToSelectV2: {%0A fieldMask: {%0A paths: [%0A "id.uuid.value",%0A "user_info.name.first_name.value",%0A "user_info.name.last_name.value",%0A "user_info.role",%0A "user_info.signup_info.city_id.value",%0A "user_info.signup_info.country_id.value"%0A ]%0A }%0A }%0A }%0A tripRequest: {options: {includeAgora: true, includePaymentProfile: true}}%0A territoryRequest: {request: {options: {includeCountry: true}}}%0A }%0A }%0A ) {%0A contact {%0A id { value }%0A userType%0A modality%0A status%0A cityId%0A countryId { value }%0A territory {%0A name%0A country { name }%0A }%0A requester {%0A id { uuid { value } }%0A userInfo {%0A name { firstName lastName }%0A role%0A signupInfo { cityId countryId }%0A }%0A }%0A trip {%0A uuid { value }%0A driverUuid { value }%0A clientUuid { value }%0A partnerUuid { value }%0A cityId%0A countryId%0A }%0A actions {%0A actions {%0A id { value }%0A actionType%0A arguments { arguments { name value } }%0A message {%0A source%0A visibility%0A text%0A createdAt { value }%0A }%0A }%0A }%0A events {%0A events {%0A base { time { value } initiatorType }%0A outcome%0A actionId { value }%0A creatorUser { userInfo { name { firstName lastName } } }%0A creatorAgent { firstName lastName }%0A }%0A }%0A }%0A }%0A}%0A`;var O={opName:"getContactContext",rpcProcedure:"bliss_hydrator.get_contact_context.__no_postfix__",query:nt};var ot=`query getUserContext($requesterID: String!) {%0A hydrationGetUserContext(%0A in: {%0A userCustomRequest: {%0A criteria: {userId: {uuid: {value: $requesterID}}}%0A fieldsToSelectV2: {%0A fieldMask: {%0A paths: [%0A "user_info.name.first_name.value",%0A "user_info.name.last_name.value",%0A "user_info.role",%0A "user_info.user_types",%0A "user_info.signup_info.city_id.value",%0A "user_info.signup_info.country_id.value",%0A "user_info.signup_info.country_iso2_code.value",%0A "extensions[driver].proto.onboarding.city_id",%0A "extensions[driver].proto.onboarding.driver_business_city_id",%0A "extensions[driver].proto.onboarding.current_status",%0A "extensions[driver].proto.onboarding.flow_type"%0A ]%0A }%0A }%0A }%0A }%0A ) {%0A user {%0A id { uuid { value } }%0A userInfo {%0A name { firstName lastName }%0A role%0A signupInfo {%0A cityId%0A countryId%0A countryIso2Code%0A territory {%0A name%0A slug%0A country { name }%0A }%0A }%0A userTypes%0A }%0A driverInfo {%0A onboarding {%0A driverBusinessCityId%0A cityId%0A currentStatus%0A flowType%0A territory {%0A name%0A country { name }%0A }%0A }%0A }%0A }%0A }%0A}%0A`;var st={opName:"getUserContext",rpcProcedure:"bliss_hydrator.get_user_context.__no_postfix__",query:ot};var it=45e3,K=8,W=120,Dt=new Set(["recordAgentViewStartV1","recordAgentViewEndV1"]),L=null;function T(t,...e){Bt(t)}function Lt(){T("Reading Bliss auth info...");let t=document.getElementById("__AUTH_INFO__");if(!t?.content)throw new Error("Could not find __AUTH_INFO__ meta tag on the page");let e=JSON.parse(`"${t.content.replace(/"/g,'%5C%5C"')}"`),n=JSON.parse(e),r=n.uuid,o=n.agentInfo?.agentId;if(!r)throw new Error("uuid missing from __AUTH_INFO__");if(!o)throw new Error("agentInfo.agentId missing from __AUTH_INFO__");return T("Found Bliss auth info",{uuidPrefix:r.slice(0,8),agentId:o}),{uuid:r,agentId:o}}function qt(){let e=[...(new URL(location.href).searchParams.get("tabs")??"").matchAll(R)].map(n=>n[1].toLowerCase());return T("Read contact tabs from Bliss URL",e),e}function Pt(t){return`https://blissnxt.uberinternal.com/tabs?tabs=${t.map(n=>`contact:${n}`).join(",")}`}function Ot(){if(L&&document.body.contains(L))return L;let t=document.createElement("div");return t.id="launch-autodrafter-overlay",t.style.cssText=["position:fixed","top:12px","right:12px","z-index:2147483647","background:%23111827","color:%23fff","font-family:system-ui,sans-serif","font-size:12px","padding:8px 12px","border-radius:6px","box-shadow:0 4px 12px rgba(0,0,0,0.3)","max-width:340px","line-height:1.4"].join(";"),document.body.appendChild(t),L=t,t}function Bt(t){Ot().textContent=t}function at(){L?.remove(),L=null}function lt(t,e){let n=new AbortController,r=setTimeout(()=>n.abort(),it);return t(n.signal).catch(o=>{throw o instanceof DOMException&&o.name==="AbortError"?new Error(`${e} timed out after ${it}ms`):o}).finally(()=>clearTimeout(r))}async function Ht(t){return T(`Fetching contact ${t.slice(0,8)}...`,{contactId:t}),lt(e=>D(O,{contactId:t},{signal:e}),`getContactContext(${t})`)}async function zt(t){return T(`Fetching user ${t.slice(0,8)}...`,{requesterID:t}),lt(e=>D(st,{requesterID:t},{signal:e}),`getUserContext(${t})`)}function Vt(t){return[t?.firstName,t?.lastName].filter(Boolean).join(" ")||null}function B(t){let e=t.hydrationGetContactContext?.contact;if(!e)throw new Error("GraphQL response did not include contact data");return e}function jt(t){let n=B(t).requester,r=n?.userInfo?.name;return{id:n?.id?.uuid?.value??null,name:Vt(r),firstName:r?.firstName??null,lastName:r?.lastName??null}}function Ft(t){return B(t).userType??null}function Kt(t){let e=B(t).trip;return e?{uuid:e.uuid?.value??null,driverUuid:e.driverUuid?.value??null,clientUuid:e.clientUuid?.value??null,partnerUuid:e.partnerUuid?.value??null,cityId:e.cityId??null,countryId:e.countryId??null}:null}function Wt(t){let e=B(t),n=e.actions?.actions??[],r=e.events?.events??[],o=new Map(r.map(s=>[s.actionId?.value,s]));return n.filter(s=>!Dt.has(s.actionType??"")).map(s=>{let l=s.message,x=o.get(s.id?.value),d={};for(let c of s.arguments?.arguments??[])d[c.name]=c.value;return{text:l?.text??"",createdAt:new Date(l?.createdAt?.value??x?.base?.time?.value??0),source:l?.source??"",visibility:l?.visibility??"",actionType:s.actionType??"",arguments:d}}).sort((s,l)=>s.createdAt.getTime()-l.createdAt.getTime())}function Xt(t){let e=new Set;for(let n of t)for(let r of n.text.match(P)??[])for(let[,o]of r.matchAll(R))e.add(o.toLowerCase());return[...e]}function Yt(t){return!t||t.name==null&&t.country?.name==null?null:{name:t.name??null,country:t.country?.name??null}}function Jt(t,e){let r=e.hydrationGetUserContext?.user?.driverInfo?.onboarding;return{uuid:t,driverTerritory:Yt(r?.territory),driverCityId:r?.driverBusinessCityId??r?.cityId??null}}async function Qt(t){let e=await Promise.allSettled(t.map(Ht)),n=[],r=[];for(let o=0;oa.createdAt.getTime()),d=Xt(l),c=jt(s.value),p=Ft(s.value),i=Kt(s.value);T(`Parsed contact ${t[o].slice(0,8)}`,{uuid:t[o],messages:l.length,mentionedUuids:d,requester:c,userType:p,tripDriverUuid:i?.driverUuid??null}),n.push({uuid:t[o],messages:l,firstAt:x.length?Math.min(...x):1/0,mentionedUuids:d,requester:c,userType:p,trip:i})}return{results:n,errors:r}}async function Zt(t){let e=await Promise.allSettled(t.map(zt)),n=[],r=[];for(let o=0;o&view=0 first.`),null;let e=new Map,n=new Map,r=[],o=[...new Set(t)],s=0;for(;o.length;){if(s++,s>K){r.push(...o.map(f=>({uuid:f,reason:`Stopped at max sweep depth ${K}`}))),T("Stopped recursive fetch at max depth",{maxDepth:K,skipped:o});break}T(s===1?`Fetching ${o.length} tab contact(s)...`:`Depth ${s}: fetching ${o.length} linked contact(s)...`,{pending:o,depth:s});let{results:a,errors:m}=await Qt(o);r.push(...m);for(let f of a)e.set(f.uuid,f),n.set(f.uuid,f.mentionedUuids);let y=new Set(e.keys()),b=new Set;o=a.flatMap(f=>f.mentionedUuids.filter(v=>y.has(v)||b.has(v)||e.size+b.size>=W?!1:(b.add(v),!0))),e.size>=W&&(T("Stopped recursive fetch at max contact count",{maxContacts:W,fetched:e.size}),o=[]),T(`Depth ${s} complete`,{totalFetched:e.size,nextPending:o,errors:r.length})}let l=te(e.values());T(`Hydrating ${l.length} unique person(s)...`,{personUuids:l});let{users:x,errors:d}=l.length?await Zt(l):{users:[],errors:[]};r.push(...d);let c=[...e.values()].sort((a,m)=>a.firstAt-m.firstAt),p=c.map(a=>a.uuid),i={sortedUuids:p,combinedUrl:Pt(p),contacts:Object.fromEntries(c.map(a=>[a.uuid,{uuid:a.uuid,firstAt:a.firstAt===1/0?null:a.firstAt,messages:a.messages,requester:a.requester,userType:a.userType,trip:a.trip}])),users:Object.fromEntries(x.map(a=>[a.uuid,a])),errors:r.map(a=>({uuid:a.uuid,reason:a.reason instanceof Error?a.reason.message:String(a.reason)}))};return T("Sweep complete",{contacts:p.length,users:Object.keys(i.users).length,messages:Object.values(i.contacts).reduce((a,m)=>a+m.messages.length,0),errors:i.errors,payloadBytes:JSON.stringify(i).length}),i}var ut="blissnxt.uberinternal.com";function ee(t){return t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"&%2339;")}function ne(t){t.document.open(),t.document.write(`%0A%0A %0A Launch Auto Drafter%0A %0A %0A
%0A

Preparing Auto Drafter

%0A

Gathering the selected Bliss contacts. This tab will open Auto Drafter automatically.

%0A
%0A %0A`),t.document.close()}function re(t,e){t.document.open(),t.document.write(`%0A%0A %0A Auto Drafter needs attention%0A %0A %0A
%0A

Auto Drafter could not start

%0A

${ee(e)}

%0A
%0A %0A`),t.document.close()}async function dt(){if(location.hostname!==ut){alert(`Launch Auto Drafter must be clicked from a Bliss page on ${ut}.`);return}let t=`launch-autodrafter-${Date.now()}`,e=window.open("about:blank",t);e&&ne(e);try{let n=await ct();n&&(et(n,e?t:"_blank",e),window.location.href=n.combinedUrl)}catch(n){let r=n instanceof Error?n.message:String(n);e&&!e.closed&&re(e,r),at(),alert(`Auto Drafter failed: ${r}`)}}function pt(t,e){return t.reduce((n,r,o)=>n+r+(e[o]??""),"").replace(/>%5Cs+<").replace(/%5Cs+/g," ").trim()}var H=(t,...e)=>pt(t,e),M=(t,...e)=>pt(t,e);var oe="http://www.w3.org/2000/svg",U=760,k=460,q=16,z=28,gt=["%232563eb","%23dc2626","%2316a34a","%23d97706","%237c3aed","%230891b2","%23db2777","%2365a30d","%23ea580c","%234f46e5","%230d9488","%23b45309"],ft="%2394a3b8",V={mention:"%23475569",related:"%23f97316"};function F(t){return t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"&%2339;")}function S(t,e){let n=document.createElementNS(oe,t);for(let r in e)n.setAttribute(r,String(e[r]));return n}function se(t){if(t.recipientName){let e=t.recipientName.trim().split(/%5Cs+/);return(e[0][0]+(e[1]?.[0]??"")).toUpperCase()}return t.uuid.slice(0,2).toUpperCase()}function j(t){return t.recipientId??`contact:${t.uuid}`}function ie(t){let e=new Map,n=0;for(let r of t){let o=j(r);e.has(o)||e.set(o,r.recipientId?gt[n++%25gt.length]:ft)}return e}function mt(t,e=1){return`https://blissnxt.uberinternal.com/tabs?tabs=${t.map(r=>`contact:${r}`).join(",")}&view=${e}`}function ae(t,e,n){document.getElementById("bg-context-menu")?.remove();let r=document.createElement("div");r.id="bg-context-menu",r.style.cssText=M`%0A position: fixed;%0A z-index: 2147483647;%0A background: %23fff;%0A border: 1px solid %23e2e8f0;%0A border-radius: 8px;%0A box-shadow: 0 12px 32px rgba(15, 23, 42, 0.25);%0A padding: 4px;%0A min-width: 210px;%0A font-family: system-ui, sans-serif;%0A `;for(let d of n){let c=document.createElement("button");c.textContent=d.label,c.style.cssText=M`%0A display: block;%0A width: 100%25;%0A text-align: left;%0A border: none;%0A background: none;%0A padding: 8px 12px;%0A font-size: 13px;%0A color: %230f172a;%0A cursor: pointer;%0A border-radius: 6px;%0A `,c.addEventListener("mouseenter",()=>c.style.background="%23f1f5f9"),c.addEventListener("mouseleave",()=>c.style.background="none"),c.addEventListener("click",()=>{r.remove(),d.onClick()}),r.appendChild(c)}document.body.appendChild(r);let o=r.getBoundingClientRect(),s=Math.min(t,window.innerWidth-o.width-8),l=Math.min(e,window.innerHeight-o.height-8);r.style.left=`${Math.max(8,s)}px`,r.style.top=`${Math.max(8,l)}px`;let x=d=>{r.contains(d.target)||(r.remove(),document.removeEventListener("mousedown",x))};setTimeout(()=>document.addEventListener("mousedown",x),0)}function le(t,e){let n=t.length,r=t.map((d,c)=>{let p=2*Math.PI*c/Math.max(n,1);return{uuid:d.uuid,x:U/2+Math.cos(p)*(U/4),y:k/2+Math.sin(p)*(k/4)}}),o=new Map(r.map((d,c)=>[d.uuid,c])),s=e.map(d=>[o.get(d.from),o.get(d.to)]).filter(d=>d[0]!=null&&d[1]!=null),l=Math.sqrt(U*k/Math.max(n,1))*.55,x=320;for(let d=0;d({x:0,y:0}));for(let i=0;i[d.uuid,d]))}function ce(t,e,n){let r=e.x-t.x,o=e.y-t.y,s=Math.hypot(r,o)||.01,l=r/s,x=o/s,d=t.x+l*q,c=t.y+x*q,p=e.x-l*(q+8),i=e.y-x*(q+8),a=(d+p)/2+-x*n,m=(c+i)/2+l*n;return`M${d},${c} Q${a},${m} ${p},${i}`}function ue(t){let e=tt(t);return e.length?e.map(n=>{let r=n.tone==="ok"?"background:%23dcfce7;color:%23166534;border:1px solid %23bbf7d0":"background:%23fef2f2;color:%23991b1b;border:1px solid %23fecaca";return H`%0A %0A ${F(n.label)}%0A %0A `}).join(""):'No rider or driver contacts selected.'}function yt(t){document.getElementById("bliss-graph-overlay")?.remove(),document.getElementById("bliss-graph-restore")?.remove();let{contacts:e,edges:n}=t,r=ie(e),o=le(e,n),s=new Set(e.map(u=>u.uuid)),l=document.createElement("div");l.id="bliss-graph-overlay",l.style.cssText=M`%0A position: fixed;%0A inset: 0;%0A z-index: 2147483647;%0A background: rgba(15, 23, 42, 0.55);%0A display: flex;%0A align-items: center;%0A justify-content: center;%0A font-family: system-ui, sans-serif;%0A `;let x=[...r.entries()].map(([u,g])=>{let C=e.find(G=>j(G)===u),h=C?.recipientName??"Unknown recipient",_=C?.userType?` (${C.userType})`:"";return H`%0A %0A %0A ${F(h+_)}%0A %0A `}).join("");l.innerHTML=H`%0A %0A
%0A

Bliss contact graph

%0A
%0A %0A %0A %0A
%0A
%0A

%0A ${e.length} contacts${t.errors.length?` %5CxB7 ${t.errors.length} fetch error(s)`:""}. Click a node (or legend recipient) to include/exclude it; right-click a node for more.%0A

%0A
%0A %0A mention%0A %0A %0A related contact%0A %0A ${x}%0A
%0A
%0A
%0A %0A `,document.body.appendChild(l);let d=S("svg",{viewBox:`0 0 ${U} ${k}`,width:"100%25",style:"display:block"});d.setAttribute("height",String(k));let c=S("defs",{});for(let u of["mention","related"]){let g=S("marker",{id:`bg-arrow-${u}`,viewBox:"0 0 10 10",refX:"8",refY:"5",markerWidth:"7",markerHeight:"7",orient:"auto-start-reverse"});g.appendChild(S("path",{d:"M0,0 L10,5 L0,10 z",fill:V[u]})),c.appendChild(g)}d.appendChild(c);let p=new Map,i=n.map(u=>{let g=o.get(u.from),C=o.get(u.to);if(!g||!C)return null;let h=`${u.from}>${u.to}`,_=p.get(h)??0;p.set(h,_+1);let G=22+_*16,N=ce(g,C,G),$=S("path",{d:N,fill:"none",stroke:"transparent","stroke-width":"14"});if(u.note){let J=S("title",{});J.textContent=u.note,$.appendChild(J)}d.appendChild($);let Y=S("path",{d:N,fill:"none",stroke:V[u.kind],"stroke-width":"1.8","marker-end":`url(%23bg-arrow-${u.kind})`,style:"pointer-events:none"});return d.appendChild(Y),{el:Y,edge:u}}).filter(u=>u!=null),a=new Map;for(let u of e){let g=o.get(u.uuid),C=r.get(j(u))??ft,h=S("g",{style:"cursor:pointer"}),_=S("title",{});_.textContent=`${u.recipientName??"Unknown"} %5CxB7 ${u.userType??"?"}%0A${u.uuid}`,h.appendChild(_);let G=S("circle",{cx:g.x,cy:g.y,r:q,fill:C,stroke:"%230f172a","stroke-width":"2"}),N=S("text",{x:g.x,y:g.y+4,"text-anchor":"middle","font-size":"11","font-weight":"700",fill:"%23fff",style:"pointer-events:none;user-select:none"});N.textContent=se(u),h.appendChild(G),h.appendChild(N),h.addEventListener("click",()=>w(u.uuid)),h.addEventListener("contextmenu",$=>{$.preventDefault(),ae($.clientX,$.clientY,[{label:s.has(u.uuid)?"De-select contact":"Select contact",onClick:()=>w(u.uuid)},{label:"Open contact in new tab",onClick:()=>A(u.uuid)}])}),d.appendChild(h),a.set(u.uuid,{circle:G,label:N})}l.querySelector("%23bg-graph").appendChild(d);let m=l.querySelector("%23bg-link"),y=l.querySelector("%23bg-badges"),b=[...l.querySelectorAll(".bg-recipient")];function f(u){return e.filter(g=>j(g)===u).map(g=>g.uuid)}function v(){let u=e.filter(g=>s.has(g.uuid)).map(g=>g.uuid);u.length?(m.href=mt(u),m.textContent=`Open ${u.length}-in-1 Bliss`,m.style.pointerEvents="auto",m.style.opacity="1"):(m.removeAttribute("href"),m.textContent="Select at least one contact",m.style.pointerEvents="none",m.style.opacity="0.5"),y.innerHTML=ue(e.filter(g=>s.has(g.uuid)));for(let[g,C]of a){let h=s.has(g);C.circle.setAttribute("opacity",h?"1":"0.25"),C.circle.setAttribute("stroke-dasharray",h?"0":"4 3"),C.label.setAttribute("opacity",h?"1":"0.4")}for(let{el:g,edge:C}of i){let h=s.has(C.from)&&s.has(C.to);g.setAttribute("opacity",h?"1":"0.12")}for(let g of b){let C=g.dataset.recipientKey??"",h=f(C).some(_=>s.has(_));g.style.opacity=h?"1":"0.4"}}function w(u){s.has(u)?s.delete(u):s.add(u),v()}function A(u){let g=e.filter(h=>s.has(h.uuid)||h.uuid===u).map(h=>h.uuid),C=Math.max(0,g.indexOf(u));window.open(mt(g,C),"_blank")}for(let u of b)u.addEventListener("click",()=>{let g=f(u.dataset.recipientKey??""),C=g.some(h=>s.has(h));for(let h of g)C?s.delete(h):s.add(h);v()});let E=document.createElement("button");E.id="bliss-graph-restore",E.textContent="Show contact graph",E.style.cssText=M`%0A position: fixed;%0A bottom: 16px;%0A right: 16px;%0A z-index: 2147483647;%0A display: none;%0A cursor: pointer;%0A border: none;%0A background: %230f172a;%0A color: %23fff;%0A border-radius: 999px;%0A padding: 10px 16px;%0A font-family: system-ui, sans-serif;%0A font-size: 13px;%0A box-shadow: 0 8px 24px rgba(15, 23, 42, 0.35);%0A `,E.addEventListener("click",()=>{l.style.display="flex",E.style.display="none"}),document.body.appendChild(E),l.querySelector("%23bg-hide").addEventListener("click",()=>{l.style.display="none",E.style.display="block"}),l.querySelector("%23bg-autodrafter").addEventListener("click",()=>{dt()}),l.addEventListener("click",u=>{u.target===l&&(l.style.display="none",E.style.display="block")}),v()}var ht=`query getRelatedContacts($contactId: String!, $tenancy: String!) {%0A hydrationGetContactContext(%0A in: {contactCustomRequest: {contactId: {value: $contactId}}, contactDownstreamHeaders: {entries: [{key: "x-uber-tenancy", value: $tenancy}]}}%0A ) {%0A relatedContacts {%0A isSafetyContact%0A relatedContacts {%0A contactId%0A isContactOfRecord%0A }%0A }%0A }%0A}%0A`;var xt={opName:"getRelatedContacts",rpcProcedure:"bliss_hydrator.get_related_contacts.__no_postfix__",query:ht};var bt=45e3,vt=8,Ct=120,pe="uber/production";function wt(t,e){let n=new AbortController,r=setTimeout(()=>n.abort(),bt);return t(n.signal).catch(o=>{throw o instanceof DOMException&&o.name==="AbortError"?new Error(`${e} timed out after ${bt}ms`):o}).finally(()=>clearTimeout(r))}function ge(){return[...(new URL(location.href).searchParams.get("tabs")??"").matchAll(R)].map(e=>e[1].toLowerCase())}function me(t){return[t?.firstName,t?.lastName].filter(Boolean).join(" ")||null}function fe(t){let e=t.hydrationGetContactContext?.contact;if(!e)throw new Error("GraphQL response did not include contact data");return e}function X(t){return t instanceof Error?t.message:String(t)}function ye(t){let e=document.createElement("div");e.innerHTML=t;let n=(e.textContent??"").replace(/%5Cs+/g," ").trim();return n.length>280?`${n.slice(0,279)}%5Cu2026`:n}function he(t,e){let n=fe(e),r=n.actions?.actions??[],o=n.events?.events??[],s=new Map(o.map(p=>[p.actionId?.value,p])),l=r.map(p=>{let i=p.message,a=s.get(p.id?.value),m=new Date(i?.createdAt?.value??a?.base?.time?.value??0).getTime();return{text:i?.text??"",createdAt:m,source:i?.source??"",visibility:i?.visibility??"",initiatorType:a?.base?.initiatorType??"",actionType:p.actionType??""}});l.sort((p,i)=>p.createdAt-i.createdAt);let x=new Map;for(let p of l)for(let i of p.text.match(P)??[])for(let[,a]of i.matchAll(R)){let m=a.toLowerCase();m!==t&&!x.has(m)&&x.set(m,ye(p.text))}let d=n.requester,c=l.map(p=>p.createdAt).filter(p=>Number.isFinite(p)&&p>0);return{contact:{uuid:t,recipientId:d?.id?.uuid?.value??null,recipientName:me(d?.userInfo?.name),userType:n.userType??null,modality:n.modality??null,status:n.status??null,messages:l,hasSuccess:o.some(p=>p.outcome==="ACTION_OUTCOME_TYPE_SUCCEEDED")},firstAt:c.length?Math.min(...c):1/0,mentions:[...x].map(([p,i])=>({uuid:p,note:i}))}}async function xe(t,e){return((await wt(o=>D(xt,{contactId:t,tenancy:e},{signal:o}),`getRelatedContacts(${t})`)).hydrationGetContactContext?.relatedContacts?.relatedContacts??[]).map(o=>o.contactId?.toLowerCase()).filter(o=>!!o&&o!==t)}async function be(t){return wt(e=>D(O,{contactId:t},{signal:e}),`getContactContext(${t})`)}async function Tt(t=()=>{}){let e=[...new Set(ge())];if(!e.length)return alert(`Bliss Graph: no contact tabs found in the current URL.%0AOpen a Bliss page like /tabs?tabs=contact: first.`),null;let n=[],r=new Set,o=[],s=(y,b,f,v)=>{if(y===b)return;let w=`${y}|${b}|${f}`;r.has(w)||(r.add(w),o.push({from:y,to:b,kind:f,...v?{note:v}:{}}))};t(`Finding related contacts for ${e.length} tab(s)...`);let l=await Promise.allSettled(e.map(y=>xe(y,pe))),x=new Set(e);l.forEach((y,b)=>{if(y.status==="rejected"){n.push({uuid:e[b],reason:X(y.reason)});return}for(let f of y.value)s(e[b],f,"related"),x.add(f)});let d=new Map,c=[...x],p=0;for(;c.length;){if(p++,p>vt){n.push(...c.map(v=>({uuid:v,reason:`Stopped at max sweep depth ${vt}`})));break}t(p===1?`Fetching ${c.length} contact(s)...`:`Depth ${p}: fetching ${c.length} linked contact(s)...`);let y=await Promise.allSettled(c.map(be)),b=[];y.forEach((v,w)=>{let A=c[w];if(v.status==="rejected"){n.push({uuid:A,reason:X(v.reason)});return}try{let E=he(A,v.value);d.set(A,E),b.push(E)}catch(E){n.push({uuid:A,reason:X(E)})}});let f=new Set;c=b.flatMap(v=>v.mentions.flatMap(({uuid:w,note:A})=>(s(v.contact.uuid,w,"mention",A),d.has(w)||f.has(w)?[]:d.size+f.size>=Ct?[]:(f.add(w),[w])))),d.size>=Ct&&(c=[])}let i=[...d.values()].sort((y,b)=>y.firstAt-b.firstAt).map(y=>y.contact),a=new Set(i.map(y=>y.uuid)),m=o.filter(y=>a.has(y.from)&&a.has(y.to));return t(`Sweep complete: ${i.length} contact(s).`),{contacts:i,edges:m,errors:n}}var Et="blissnxt.uberinternal.com",I=null;function ve(t){I||(I=document.createElement("div"),I.style.cssText=M` position: fixed; top: 12px; right: 12px; z-index: 2147483647; background: %23111827; color: %23fff; font-family: system-ui, sans-serif; font-size: 12px; padding: 8px 12px; border-radius: 6px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); max-width: 340px; line-height: 1.4; `,document.body.appendChild(I)),I.textContent=t}async function Ce(){if(location.hostname!==Et){alert(`Bliss Graph must be clicked from a Bliss page on ${Et}.`);return}let t=await Tt(ve);I?.remove(),I=null,t&&yt(t)}Ce().catch(t=>{I?.remove(),I=null;let e=t instanceof Error?t.message:String(t);alert(`Bliss Graph failed: ${e}`)});})()