javascript:(async()=>{var q="__AUTO_DRAFTER_URL__";function L(t){let e=new TextEncoder().encode(t),s="";for(let a=0;a"']+/g;var N="https://blissnxt.uberinternal.com/hydrator/graphql?opName=getContactMessages",_=45e3,b=8,w=120,O=`query getContactMessages($contactID: String) { hydrationGetContactContext( in: {contactCustomRequest: {contactId: {value: $contactID}, includeInlineAttachmentUrl: true}} ) { contact { requester { id { uuid { value } } userInfo { name { firstName lastName } } } userType actions { actions { id { value } actionType arguments { arguments { name value } } message { source visibility text createdAt { value } } } } events { events { base { time { value } } actionId { value } creatorUser { userInfo { name { firstName lastName } } } creatorAgent { firstName lastName } } } } } }`,p=null;function c(t,...e){P(t)}function k(){c("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,'\\"')}"`),s=JSON.parse(e),a=s.uuid,i=s.agentInfo?.agentId;if(!a)throw new Error("uuid missing from __AUTH_INFO__");if(!i)throw new Error("agentInfo.agentId missing from __AUTH_INFO__");return c("Found Bliss auth info",{uuidPrefix:a.slice(0,8),agentId:i}),{uuid:a,agentId:i}}function $(){let e=[...(new URL(location.href).searchParams.get("tabs")??"").matchAll(x)].map(s=>s[1].toLowerCase());return c("Read contact tabs from Bliss URL",e),e}function D(t){return`https://blissnxt.uberinternal.com/tabs?tabs=${t.map(s=>`contact:${s}`).join(",")}`}function H(){if(p&&document.body.contains(p))return p;let t=document.createElement("div");return t.id="launch-autodrafter-overlay",t.style.cssText=["position:fixed","top:12px","right:12px","z-index:2147483647","background:#111827","color:#fff","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),p=t,t}function P(t){H().textContent=t}function R(){p?.remove(),p=null}async function B(t,e){c(`Fetching contact ${t.slice(0,8)}...`,{contactID:t});let s=new AbortController,a=setTimeout(()=>s.abort(),_),i;try{i=await fetch(N,{method:"POST",credentials:"include",signal:s.signal,headers:{accept:"*/*","content-type":"application/json","rpc-procedure":"bliss_hydrator.get_contact_messages.__no_postfix__","x-csrf-token":"x"},body:JSON.stringify({operationName:"getContactMessages",variables:{contactID:t,agentUuid:e.uuid},query:O})})}catch(r){throw r instanceof DOMException&&r.name==="AbortError"?new Error(`GraphQL request timed out after ${_}ms for ${t}`):r}finally{clearTimeout(a)}if(!i.ok)throw new Error(`GraphQL request failed for ${t}: ${i.status} ${i.statusText}`);let n=await i.json();return c(`Fetched contact ${t.slice(0,8)}`,{hasContact:!!n.data?.hydrationGetContactContext?.contact}),n}function v(t){return[t?.firstName,t?.lastName].filter(Boolean).join(" ")||null}function A(t){let e=t.data?.hydrationGetContactContext?.contact;if(!e)throw new Error("GraphQL response did not include contact data");return e}function C(t){let e=A(t).requester;return{id:e?.id?.uuid?.value??null,name:v(e?.userInfo?.name)}}function E(t){return A(t).userType??null}function F(t){let e=A(t),s=e.actions?.actions??[],a=e.events?.events??[],i=new Map(a.map(n=>[n.actionId?.value,n]));return s.map(n=>{let r=n.message,l=i.get(n.id?.value),d={};for(let u of n.arguments?.arguments??[])d[u.name]=u.value;return{text:r?.text??"",createdAt:new Date(r?.createdAt?.value??l?.base?.time?.value??0),source:r?.source??"",visibility:r?.visibility??"",author:v(l?.creatorAgent)??v(l?.creatorUser?.userInfo?.name),actionType:n.actionType??"",arguments:d}}).sort((n,r)=>n.createdAt.getTime()-r.createdAt.getTime())}function j(t){let e=new Set;for(let s of t)for(let a of s.text.match(T)??[])for(let[,i]of a.matchAll(x))e.add(i.toLowerCase());return[...e]}async function z(t,e){let s=await Promise.allSettled(t.map(n=>B(n,e))),a=[],i=[];for(let n=0;no.createdAt.getTime()),u=j(l);c(`Parsed contact ${t[n].slice(0,8)}`,{uuid:t[n],messages:l.length,mentionedUuids:u,requester:C(r.value),userType:E(r.value)}),a.push({uuid:t[n],messages:l,firstAt:d.length?Math.min(...d):1/0,mentionedUuids:u,requester:C(r.value),userType:E(r.value)})}return{results:a,errors:i}}async function U(){c("Starting sweep",{href:location.href});let t=k(),e=$();if(!e.length)return alert(`Auto Drafter: no contact tabs found in the current URL. Open a Bliss page like /tabs?tabs=contact:&view=0 first.`),null;let s=new Map,a=new Map,i=[],n=[...new Set(e)],r=0;for(;n.length;){if(r++,r>b){i.push(...n.map(g=>({uuid:g,reason:`Stopped at max sweep depth ${b}`}))),c("Stopped recursive fetch at max depth",{maxDepth:b,skipped:n});break}c(r===1?`Fetching ${n.length} tab contact(s)...`:`Depth ${r}: fetching ${n.length} linked contact(s)...`,{pending:n,depth:r});let{results:o,errors:m}=await z(n,t);i.push(...m);for(let g of o)s.set(g.uuid,g),a.set(g.uuid,g.mentionedUuids);let I=new Set(s.keys()),h=new Set;n=o.flatMap(g=>g.mentionedUuids.filter(y=>I.has(y)||h.has(y)||s.size+h.size>=w?!1:(h.add(y),!0))),s.size>=w&&(c("Stopped recursive fetch at max contact count",{maxContacts:w,fetched:s.size}),n=[]),c(`Depth ${r} complete`,{totalFetched:s.size,nextPending:n,errors:i.length})}let l=[...s.values()].sort((o,m)=>o.firstAt-m.firstAt),d=l.map(o=>o.uuid),u={sortedUuids:d,combinedUrl:D(d),graph:Object.fromEntries(a.entries()),contacts:Object.fromEntries(l.map(o=>[o.uuid,{uuid:o.uuid,firstAt:o.firstAt===1/0?null:o.firstAt,mentionedUuids:o.mentionedUuids,messages:o.messages,requester:o.requester,userType:o.userType}])),errors:i.map(o=>({uuid:o.uuid,reason:o.reason instanceof Error?o.reason.message:String(o.reason)}))};return c("Sweep complete",{contacts:d.length,messages:Object.values(u.contacts).reduce((o,m)=>o+m.messages.length,0),errors:u.errors,payloadBytes:JSON.stringify(u).length}),u}var M="blissnxt.uberinternal.com",f=null;function G(t){t.document.open(),t.document.write(` Launch Auto Drafter

Preparing Auto Drafter

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

`),t.document.close()}function W(t){return t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function J(t,e){t.document.open(),t.document.write(` Auto Drafter needs attention

Auto Drafter could not start

${W(e)}

`),t.document.close()}async function Q(){if(location.hostname!==M){alert(`Launch Auto Drafter must be clicked from a Bliss page on ${M}.`);return}let t=`launch-autodrafter-${Date.now()}`,e=window.open("about:blank",t);e&&(f=e,G(e));let s=await U();s&&(S(s,e?t:"_blank",e),window.location.href=s.combinedUrl)}Q().catch(t=>{let e=t instanceof Error?t.message:String(t);f&&!f.closed&&J(f,e),R(),alert(`Auto Drafter failed: ${e}`)});})()