@sightspool/sdk 0.2.1 → 0.3.0

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.
@@ -1,4 +1,4 @@
1
- var Sightspool=(function(exports){'use strict';var mt=Object.defineProperty;var H=(t,e)=>()=>(t&&(e=t(t=0)),e);var F=(t,e)=>{for(var n in e)mt(t,n,{get:e[n],enumerable:true});};function U(t){if(!t)return "";try{return String(t).replace(gt,"\u2039email\u203A").replace(ht,"\u2039num\u203A").replace(/\s+/g," ").trim().slice(0,280)}catch(e){return ""}}function O(t,e){try{return typeof t.closest=="function"&&t.closest(e)!=null}catch(n){return false}}function I(t,e=[]){if(!t||typeof t.closest!="function")return false;if(O(t,`[${yt}]`))return true;for(let n of e)if(n&&O(t,n))return true;return false}function A(t,e=[]){if(!t||typeof t.closest!="function")return false;for(let n of e)if(n&&O(t,n))return true;return false}var gt,ht,z,B,yt,R=H(()=>{gt=/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g,ht=/\d{6,}/g;z="Session and account attached automatically.",B="\u2039redacted\u203A",yt="data-sightspool-ignore";});var nt={};F(nt,{showPrompt:()=>Rt});function Rt(t){return new Promise(e=>{if(typeof document=="undefined"){e({answer:"dismissed"});return}let n=false,o=document.createElement("div"),r=o.attachShadow({mode:"open"});function s(l){if(!n){n=true;try{o.remove();}catch(m){}e(l);}}let f=document.createElement("style");f.textContent=At,r.appendChild(f);let a=document.createElement("div");a.className="wrap",r.appendChild(a);function d(l){a.innerHTML="";let m=document.createElement("div");m.className="card",m.style.position="relative";let i=document.createElement("button");i.className="x",i.textContent="\xD7",i.setAttribute("aria-label","Dismiss"),i.onclick=()=>s({answer:"dismissed"}),m.appendChild(i),m.appendChild(l);let u=document.createElement("p");u.className="disc",u.textContent=z,m.appendChild(u),a.appendChild(m);}function p(){let l=document.createElement("div"),m=document.createElement("p");m.className="q",m.textContent="Were you able to do what you came here to do today?",l.appendChild(m);let i=document.createElement("div");i.className="row";let u=document.createElement("button");u.className="primary",u.textContent="Yes",u.onclick=()=>s({answer:"yes"});let g=document.createElement("button");g.textContent="Not really",g.onclick=()=>v(),i.append(u,g),l.appendChild(i),d(l);}function v(){let l=document.createElement("div"),m=document.createElement("p");m.className="q",m.textContent="What were you trying to do?",l.appendChild(m);for(let u of t.candidates.slice(0,4)){let g=document.createElement("button");g.className="cand",g.textContent=u,g.onclick=()=>s({answer:"not_really",intent:u}),l.appendChild(g);}let i=document.createElement("button");i.className="cand",i.textContent="Something else\u2026",i.onclick=()=>y(),l.appendChild(i),d(l);}function y(){let l=document.createElement("div"),m=document.createElement("p");m.className="q",m.textContent="What were you trying to do?",l.appendChild(m);let i=document.createElement("input");i.type="text",i.placeholder="In your own words\u2026",l.appendChild(i);let u=document.createElement("div");u.className="row";let g=document.createElement("button");g.className="primary",g.textContent="Send",g.onclick=()=>s({answer:"not_really",verbatim:i.value.trim()||void 0}),u.appendChild(g),l.appendChild(u),d(l);try{i.focus();}catch(C){}}try{document.body.appendChild(o),p();}catch(l){s({answer:"dismissed"});}})}var At,ot=H(()=>{R();At=`
1
+ var Sightspool=(function(exports){'use strict';var ge=Object.defineProperty;var I=(e,t)=>()=>(e&&(t=e(e=0)),t);var H=(e,t)=>{for(var n in t)ge(e,n,{get:t[n],enumerable:true});};function U(e){if(!e)return "";try{return String(e).replace(ye,"\u2039email\u203A").replace(be,"\u2039num\u203A").replace(/\s+/g," ").trim().slice(0,280)}catch(t){return ""}}function O(e,t){try{return typeof e.closest=="function"&&e.closest(t)!=null}catch(n){return false}}function A(e,t=[]){if(!e||typeof e.closest!="function")return false;if(O(e,`[${xe}]`))return true;for(let n of t)if(n&&O(e,n))return true;return false}function L(e,t=[]){if(!e||typeof e.closest!="function")return false;for(let n of t)if(n&&O(e,n))return true;return false}var ye,be,B,K,xe,R=I(()=>{ye=/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g,be=/\d{6,}/g;B="Session and account attached automatically.",K="\u2039redacted\u203A",xe="data-sightspool-ignore";});var ne={};H(ne,{showPrompt:()=>Ne});function Ne(e){return new Promise(t=>{if(typeof document=="undefined"){t({answer:"dismissed"});return}let n=false,o=document.createElement("div"),r=o.attachShadow({mode:"open"});function c(f){if(!n){n=true;try{o.remove();}catch(y){}t(f);}}let l=document.createElement("style");l.textContent=Re,r.appendChild(l);let s=document.createElement("div");s.className="wrap",r.appendChild(s);function u(f){s.innerHTML="";let y=document.createElement("div");y.className="card",y.style.position="relative";let i=document.createElement("button");i.className="x",i.textContent="\xD7",i.setAttribute("aria-label","Dismiss"),i.onclick=()=>c({answer:"dismissed"}),y.appendChild(i),y.appendChild(f);let a=document.createElement("p");a.className="disc",a.textContent=B,y.appendChild(a),s.appendChild(y);}function p(){let f=document.createElement("div"),y=document.createElement("p");y.className="q",y.textContent="Were you able to do what you came here to do today?",f.appendChild(y);let i=document.createElement("div");i.className="row";let a=document.createElement("button");a.className="primary",a.textContent="Yes",a.onclick=()=>c({answer:"yes"});let m=document.createElement("button");m.textContent="Not really",m.onclick=()=>h(),i.append(a,m),f.appendChild(i),u(f);}function h(){let f=document.createElement("div"),y=document.createElement("p");y.className="q",y.textContent="What were you trying to do?",f.appendChild(y);for(let a of e.candidates.slice(0,4)){let m=document.createElement("button");m.className="cand",m.textContent=a,m.onclick=()=>c({answer:"not_really",intent:a}),f.appendChild(m);}let i=document.createElement("button");i.className="cand",i.textContent="Something else\u2026",i.onclick=()=>g(),f.appendChild(i),u(f);}function g(){let f=document.createElement("div"),y=document.createElement("p");y.className="q",y.textContent="What were you trying to do?",f.appendChild(y);let i=document.createElement("input");i.type="text",i.placeholder="In your own words\u2026",f.appendChild(i);let a=document.createElement("div");a.className="row";let m=document.createElement("button");m.className="primary",m.textContent="Send",m.onclick=()=>c({answer:"not_really",verbatim:i.value.trim()||void 0}),a.appendChild(m),f.appendChild(a),u(f);try{i.focus();}catch(C){}}try{document.body.appendChild(o),p();}catch(f){c({answer:"dismissed"});}})}var Re,oe=I(()=>{R();Re=`
2
2
  :host { all: initial; }
3
3
  .wrap { position: fixed; bottom: 20px; right: 20px; z-index: 2147483000;
4
4
  width: 320px; max-width: calc(100vw - 32px); font-family: system-ui, -apple-system, sans-serif; }
@@ -16,7 +16,28 @@ button.primary { background: #18181b; color: #fff; border-color: #18181b; }
16
16
  color: #a1a1aa; padding: 2px 6px; }
17
17
  input { font: inherit; font-size: 13px; width: 100%; box-sizing: border-box; padding: 8px 10px;
18
18
  border: 1px solid #e4e4e7; border-radius: 8px; margin-bottom: 8px; }
19
- `;});var rt={};F(rt,{showSurvey:()=>Nt});function Nt(t){return new Promise(e=>{if(typeof document=="undefined"){e({dismissed:true});return}let n=false,o=document.createElement("div"),r=o.attachShadow({mode:"open"});function s(){try{o.remove();}catch(i){}}function f(i,u){n||(n=true,e(i),u?(m(),setTimeout(s,1100)):s());}let a=document.createElement("style");a.textContent=Lt,r.appendChild(a);let d=document.createElement("div");d.className="wrap",r.appendChild(d);function p(){d.innerHTML="";let i=document.createElement("div");return i.className="card",d.appendChild(i),i}function v(i){let u=document.createElement("button");u.className="x",u.textContent="\xD7",u.setAttribute("aria-label","Dismiss"),u.onclick=()=>f({dismissed:true},false),i.appendChild(u);}function y(){var g,C,E;let i=p();v(i);let u=document.createElement("p");u.className="q",u.textContent=t.question,i.appendChild(u);for(let w of ((g=t.options)!=null?g:[]).slice(0,6)){let c=document.createElement("button");c.className="opt",c.textContent=w,c.onclick=()=>f({choice:w},true),i.appendChild(c);}if(t.allow_text){let w=document.createElement("button");w.className="opt",w.textContent=((E=(C=t.options)==null?void 0:C.length)!=null?E:0)>0?"Something else\u2026":"Answer\u2026",w.onclick=l,i.appendChild(w);}}function l(){let i=p();v(i);let u=document.createElement("p");u.className="q",u.textContent=t.question,i.appendChild(u);let g=document.createElement("input");g.type="text",g.placeholder="In your own words\u2026",i.appendChild(g);let C=document.createElement("div");C.className="row";let E=document.createElement("button");E.className="primary",E.textContent="Send";let w=()=>{let c=g.value.trim();if(!c){f({dismissed:true},false);return}f({text:c},true);};E.onclick=w,g.onkeydown=c=>{c.key==="Enter"&&w();},C.appendChild(E),i.appendChild(C);try{g.focus();}catch(c){}}function m(){let i=p(),u=document.createElement("p");u.className="done",u.textContent="Thanks \u2014 that helps.",i.appendChild(u);}try{document.body.appendChild(o),y();}catch(i){f({dismissed:true},false);}})}var Lt,it=H(()=>{Lt=`
19
+ `;});var re={};H(re,{showProbe:()=>Me});function Oe(e){try{return document.querySelector(`[data-sightspool-slot="${e}"]`)}catch(t){return null}}function Me(e){return new Promise(t=>{if(typeof document=="undefined"){t({dismissed:true,mounted:false});return}let n=e.slot?Oe(e.slot):null;if(e.slot&&!n){t({mounted:false});return}let o=false,r=!!n,c=document.createElement(r?"span":"div"),l=c.attachShadow({mode:"open"});function s(){try{c.remove();}catch(i){}}function u(i,a){o||(o=true,t(i),a?(y(),setTimeout(s,3200)):s());}let p=document.createElement("style");p.textContent=r?He:Pe,l.appendChild(p);let h=document.createElement(r?"span":"div");r||(h.className="wrap"),l.appendChild(h);function g(){if(h.innerHTML="",r)return h;let i=document.createElement("div");return i.className="card",h.appendChild(i),i}function f(){let i=g();if(!r){let m=document.createElement("button");m.className="x",m.textContent="\xD7",m.setAttribute("aria-label","Dismiss"),m.onclick=()=>u({dismissed:true,mounted:true},false),i.appendChild(m);}let a=document.createElement("button");a.className="probe",a.textContent=e.label,a.onclick=()=>u({voted:true,mounted:true},true),i.appendChild(a);}function y(){let i=g(),a=document.createElement("p");a.className="done",a.textContent=e.disclosure,i.appendChild(a);}try{(n!=null?n:document.body).appendChild(c),f();}catch(i){u({dismissed:true,mounted:false},false);}})}var Pe,He,ie=I(()=>{Pe=`
20
+ :host { all: initial; }
21
+ .wrap { position: fixed; bottom: 20px; right: 20px; z-index: 2147483000;
22
+ width: 340px; max-width: calc(100vw - 32px); font-family: system-ui, -apple-system, sans-serif; }
23
+ .card { position: relative; background: #fff; color: #18181b; border: 1px solid #e4e4e7;
24
+ border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.12); padding: 16px; }
25
+ .probe { font: inherit; font-size: 13px; cursor: pointer; display: block; width: 100%;
26
+ text-align: left; border: 1px dashed #a1a1aa; border-radius: 8px; padding: 10px 12px;
27
+ background: #fafafa; color: #3f3f46; }
28
+ .probe:hover { border-color: #18181b; color: #18181b; }
29
+ .x { position: absolute; top: 8px; right: 10px; border: none; background: none; font-size: 16px;
30
+ color: #a1a1aa; padding: 2px 6px; cursor: pointer; }
31
+ .done { font-size: 13px; color: #18181b; margin: 0; line-height: 1.4; }
32
+ `,He=`
33
+ :host { all: initial; display: inline-block; max-width: 100%; }
34
+ .probe { font: inherit; font-family: system-ui, -apple-system, sans-serif; font-size: 13px;
35
+ cursor: pointer; display: inline-block; text-align: left; border: 1px dashed #a1a1aa;
36
+ border-radius: 8px; padding: 8px 12px; background: transparent; color: #52525b; }
37
+ .probe:hover { border-color: #18181b; color: #18181b; }
38
+ .done { font-family: system-ui, -apple-system, sans-serif; font-size: 13px; color: #52525b;
39
+ margin: 0; line-height: 1.4; border: 1px dashed #d4d4d8; border-radius: 8px; padding: 8px 12px; }
40
+ `;});var se={};H(se,{showSurvey:()=>qe});function qe(e){return new Promise(t=>{if(typeof document=="undefined"){t({dismissed:true});return}let n=false,o=document.createElement("div"),r=o.attachShadow({mode:"open"});function c(){try{o.remove();}catch(i){}}function l(i,a){n||(n=true,t(i),a?(y(),setTimeout(c,1100)):c());}let s=document.createElement("style");s.textContent=De,r.appendChild(s);let u=document.createElement("div");u.className="wrap",r.appendChild(u);function p(){u.innerHTML="";let i=document.createElement("div");return i.className="card",u.appendChild(i),i}function h(i){let a=document.createElement("button");a.className="x",a.textContent="\xD7",a.setAttribute("aria-label","Dismiss"),a.onclick=()=>l({dismissed:true},false),i.appendChild(a);}function g(){var m,C,S;let i=p();h(i);let a=document.createElement("p");a.className="q",a.textContent=e.question,i.appendChild(a);for(let w of ((m=e.options)!=null?m:[]).slice(0,6)){let d=document.createElement("button");d.className="opt",d.textContent=w,d.onclick=()=>l({choice:w},true),i.appendChild(d);}if(e.allow_text){let w=document.createElement("button");w.className="opt",w.textContent=((S=(C=e.options)==null?void 0:C.length)!=null?S:0)>0?"Something else\u2026":"Answer\u2026",w.onclick=f,i.appendChild(w);}}function f(){let i=p();h(i);let a=document.createElement("p");a.className="q",a.textContent=e.question,i.appendChild(a);let m=document.createElement("input");m.type="text",m.placeholder="In your own words\u2026",i.appendChild(m);let C=document.createElement("div");C.className="row";let S=document.createElement("button");S.className="primary",S.textContent="Send";let w=()=>{let d=m.value.trim();if(!d){l({dismissed:true},false);return}l({text:d},true);};S.onclick=w,m.onkeydown=d=>{d.key==="Enter"&&w();},C.appendChild(S),i.appendChild(C);try{m.focus();}catch(d){}}function y(){let i=p(),a=document.createElement("p");a.className="done",a.textContent="Thanks \u2014 that helps.",i.appendChild(a);}try{document.body.appendChild(o),g();}catch(i){l({dismissed:true},false);}})}var De,ae=I(()=>{De=`
20
41
  :host { all: initial; }
21
42
  .wrap { position: fixed; bottom: 20px; right: 20px; z-index: 2147483000;
22
43
  width: 340px; max-width: calc(100vw - 32px); font-family: system-ui, -apple-system, sans-serif; }
@@ -34,6 +55,6 @@ button.primary { background: #18181b; color: #fff; border-color: #18181b; }
34
55
  .done { font-size: 13px; color: #18181b; margin: 0; }
35
56
  input { font: inherit; font-size: 13px; width: 100%; box-sizing: border-box; padding: 8px 10px;
36
57
  border: 1px solid #e4e4e7; border-radius: 8px; margin-bottom: 8px; }
37
- `;});R();var K=30,bt=700,vt=1e3,xt=3;function wt(){return typeof window!="undefined"&&typeof document!="undefined"}function W(t){var E,w;let e=(E=t.redact)!=null?E:[],n=(w=t.block)!=null?w:[],o=[],r,s=false,f=[],a=[],d=[];function p(){for(let c of f)try{c();}catch(b){}}function v(c,b){try{o.push({t:Date.now(),type:c,label:b?U(b):void 0}),o.length>K&&(o=o.slice(-K)),t.debug&&console.debug("[sightspool] event",c,b),p();}catch(h){}}function y(){try{return location.pathname+location.search}catch(c){return ""}}function l(){try{return document.title||""}catch(c){return ""}}function m(c){var b;try{let h=c.target;if(I(h,n))return;let T=h&&(((b=h.getAttribute)==null?void 0:b.call(h,"aria-label"))||h.textContent)||"",k=A(h,e)?B:T.trim().slice(0,60),D=Date.now();d=d.filter(N=>D-N<=vt),d.push(D);let pt=d.length>=xt;v(pt?"rage_click":"click",k);let ft=y(),q=!1,_=null;try{_=new MutationObserver(()=>{q=!0;}),_.observe(document.body,{childList:!0,subtree:!0,attributes:!0});}catch(N){}window.setTimeout(()=>{try{_==null||_.disconnect(),!q&&y()===ft&&k&&v("dead_click",k);}catch(N){}},bt);}catch(h){}}function i(c){try{r=String(c.message||"error"),v("error",r);}catch(b){}}function u(c){try{let b=c.reason;r=b instanceof Error?b.message:String(b),v("error",r);}catch(b){}}function g(){try{let c=()=>v("route",y()),b=history.pushState,h=history.replaceState;history.pushState=function(...T){let k=b.apply(this,T);return c(),k},history.replaceState=function(...T){let k=h.apply(this,T);return c(),k},window.addEventListener("popstate",c),a.push(()=>{history.pushState=b,history.replaceState=h,window.removeEventListener("popstate",c);}),v("route",y());}catch(c){}}function C(){try{if(typeof window.fetch!="function")return;let c=window.fetch.bind(window);window.fetch=async(...b)=>{try{let h=await c(...b);return h.ok||v("request_error",`HTTP ${h.status}`),h}catch(h){throw v("request_error",h instanceof Error?h.message:"network error"),h}},a.push(()=>{window.fetch=c;});}catch(c){}}return {start(){if(!(s||!wt())){s=true;try{document.addEventListener("click",m,!0),window.addEventListener("error",i),window.addEventListener("unhandledrejection",u),a.push(()=>{document.removeEventListener("click",m,!0),window.removeEventListener("error",i),window.removeEventListener("unhandledrejection",u);}),g(),C();}catch(c){}}},stop(){s=false;for(let c of a.splice(0))try{c();}catch(b){}},trail(){return o.slice()},route:y,label:l,error(){return r},onEvent(c){f.push(c);},recordSearch(c,b){let h=c.trim();h&&v(b?"zero_result":"search",h);}}}R();var Et=/search|filter|find|query|command|lookup/i,St=800;function Ct(t){try{let e=t;if(e.type==="search")return !0;let n=t.getAttribute("role")||"";if(n==="searchbox"||n==="combobox")return !0;let o=[e.name,e.placeholder,t.getAttribute("aria-label"),t.id,t.className].filter(Boolean).join(" ");return Et.test(o)}catch(e){return false}}function j(t,e){var d,p;let n,o=null,r=false,s=(d=e.redact)!=null?d:[],f=(p=e.block)!=null?p:[];function a(v){try{let y=v.target;if(!y||y.tagName!=="INPUT"&&y.tagName!=="TEXTAREA"||!Ct(y)||I(y,f)||A(y,s))return;let l=(y.value||"").trim();if(l.length<2)return;o!==null&&window.clearTimeout(o),o=window.setTimeout(()=>{n=l,t.recordSearch(l),e.debug&&console.debug("[sightspool] harvested intent",l);},St);}catch(y){}}return {start(){if(!(r||typeof document=="undefined")){r=true;try{document.addEventListener("input",a,!0);}catch(v){}}},stop(){r=false;try{document.removeEventListener("input",a,!0),o!==null&&window.clearTimeout(o);}catch(v){}},lastIntentHint(){return n}}}function G(t){let e=[],n,o=null,r=false,s=`${t.endpoint.replace(/\/+$/,"")}/api/sdk/ingest`;function f(p){if(p.length===0)return;let v={key:t.key,identity:n,signals:p},y=JSON.stringify(v);try{if(typeof navigator!="undefined"&&typeof navigator.sendBeacon=="function"){let l=new Blob([y],{type:"text/plain"});if(navigator.sendBeacon(s,l)){t.debug&&console.debug("[sightspool] beacon",p.length);return}}fetch(s,{method:"POST",headers:{"Content-Type":"text/plain"},body:y,keepalive:!0,mode:"cors",credentials:"omit"}).catch(()=>{});}catch(l){}}function a(){try{document.visibilityState==="hidden"&&d();}catch(p){}}function d(){if(e.length===0)return;let p=e;e=[],f(p);}return {start(){if(!(r||typeof window=="undefined")){r=true;try{document.addEventListener("visibilitychange",a),window.addEventListener("pagehide",d),o=window.setInterval(d,15e3);}catch(p){}}},stop(){r=false;try{document.removeEventListener("visibilitychange",a),window.removeEventListener("pagehide",d),o!==null&&window.clearInterval(o);}catch(p){}d();},enqueue(p){e.push(p),e.length>=10&&d();},flush:d,setIdentity(p){n=p;}}}function $(t,e,n=8e3){var f;let o=t.filter(a=>e-a.t<=n);if(o.some(a=>a.type==="error"||a.type==="request_error"))return "error";let r=o.filter(a=>a.type==="click"||a.type==="rage_click");for(let a=0;a<r.length;a++)if(r.filter(p=>p.t>=r[a].t&&p.t-r[a].t<=1e3).length>=3)return "rage";if(o.some(a=>a.type==="dead_click"))return "dead_end";let s=new Map;for(let a of r){if(!a.label)continue;let d=((f=s.get(a.label))!=null?f:0)+1;if(s.set(a.label,d),d>=3)return "retry"}return null}var L={maxPromptsPerSession:1,cooldownMs:5*6e4};function Y(t,e,n=L){return !(t.promptsShown>=n.maxPromptsPerSession||t.lastPromptAt!==null&&e-t.lastPromptAt<n.cooldownMs)}var kt=new Set(["survey"]);function S(t,e){if(typeof t!="string")return;let n=t.trim();return n?n.slice(0,e):void 0}function X(t,e){let n={},o=S(t,500);o&&(n.route=o);let r=S(e==null?void 0:e.account,200);r&&(n.account=r);let s=S(e==null?void 0:e.plan,80);return s&&(n.plan=s),n}function Tt(t){if(!t||typeof t!="object")return null;let e=t,n=S(e.id,64),o=S(e.type,40);if(!n||!o||!kt.has(o))return null;let r=e.config&&typeof e.config=="object"?e.config:{},s=S(r.question,500);if(!s)return null;let f=Array.isArray(r.options)?r.options.map(d=>S(d,200)).filter(d=>!!d).slice(0,6):void 0,a={question:s,...f&&f.length?{options:f}:{},allow_text:r.allow_text===true};return {id:n,type:o,config:a}}function _t(t,e,n){let o=S(t,200);if(o)return o;let r=S(e,200);return r||n}var V="sightspool_rk";function J(t,e){let n=S(t==null?void 0:t.userId,200);if(n)return n;try{let o=localStorage.getItem(V);return o||(o="anon-"+Math.random().toString(36).slice(2)+Date.now().toString(36),localStorage.setItem(V,o)),_t(void 0,o,e)}catch(o){return e}}function Z(t,e){return `${t.replace(/\/+$/,"")}/api/sdk/${e}`}async function Q(t){var e;try{if(typeof fetch!="function")return null;let n=await fetch(Z(t.endpoint,"serve"),{method:"POST",headers:{"Content-Type":"text/plain"},body:JSON.stringify({key:t.key,context:t.ctx,respondent_key:t.respondentKey}),mode:"cors",credentials:"omit"});if(!n.ok)return null;let o=await n.json(),r=Tt(o==null?void 0:o.intervention);return t.debug&&console.debug("[sightspool] serve",(e=r==null?void 0:r.id)!=null?e:"(none)"),r}catch(n){return null}}function tt(t){try{let e=Z(t.endpoint,"respond"),n=JSON.stringify({key:t.key,intervention_id:t.interventionId,response:t.response,respondent_key:t.respondentKey});if(typeof navigator!="undefined"&&typeof navigator.sendBeacon=="function"){let o=new Blob([n],{type:"text/plain"});if(navigator.sendBeacon(e,o))return}typeof fetch=="function"&&fetch(e,{method:"POST",headers:{"Content-Type":"text/plain"},body:n,keepalive:!0,mode:"cors",credentials:"omit"}).catch(()=>{});}catch(e){}}var It=new Set(["localhost","127.0.0.1","0.0.0.0","::1",""]);function et(t){let e=(t!=null?t:"").trim().toLowerCase();return It.has(e)?true:e.endsWith(".local")||e.endsWith(".localhost")}var Ht="https://www.sightspool.com",Ot=3e4,Pt=600,Mt=2500,Dt=1;function qt(){try{return typeof location!="undefined"?location.hostname:""}catch(t){return ""}}var x=null;function Ft(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}return "s-"+Math.random().toString(36).slice(2)+Date.now().toString(36)}function Ut(t){let e=[],n=t.harvest.lastIntentHint();n&&e.push(`Searching for \u201C${n}\u201D`);let o=t.capture.label();return o&&e.push(`Something on \u201C${o.slice(0,40)}\u201D`),e}function P(t,e,n={}){let o=t.capture.error();return {captured_at:new Date().toISOString(),route:t.capture.route(),client_label:t.capture.label(),trail:t.capture.trail(),session_ref:t.sessionRef,trigger:e,intent_hint:t.harvest.lastIntentHint(),error:o,outcome:o||e==="friction"?"failed":"unknown",...n}}async function at(t,e){var o;let n=Date.now();if(Y(t.fatigue,n,L)){t.fatigue.promptsShown+=1,t.fatigue.lastPromptAt=n;try{let{showPrompt:r}=await Promise.resolve().then(()=>(ot(),nt)),s=await r({candidates:Ut(t)});t.egress.enqueue(P(t,e,{answer:s.answer,verbatim:s.verbatim,intent_hint:(o=s.intent)!=null?o:t.harvest.lastIntentHint(),outcome:s.answer==="yes"?"achieved":"failed"}));}catch(r){t.egress.enqueue(P(t,e));}}else t.egress.enqueue(P(t,e));}async function ct(t){if(!t.running||!t.interventionsEnabled||t.suppressed||t.surveyOnScreen||t.interventionsShown>=Dt)return;let e=Date.now();if(t.fatigue.lastPromptAt!==null&&e-t.fatigue.lastPromptAt<L.cooldownMs)return;let n=J(t.identity,t.sessionRef),o=await Q({endpoint:t.config.endpoint,key:t.config.key,ctx:X(t.capture.route(),t.identity),respondentKey:n,debug:t.config.debug});if(!(!o||!t.running)){t.surveyOnScreen=true,t.interventionsShown+=1,t.fatigue.lastPromptAt=Date.now();try{let{showSurvey:r}=await Promise.resolve().then(()=>(it(),rt)),s=await r(o.config);!s.dismissed&&(s.choice||s.text)&&tt({endpoint:t.config.endpoint,key:t.config.key,interventionId:o.id,response:{choice:s.choice,text:s.text},respondentKey:n});}catch(r){}finally{t.surveyOnScreen=false;}}}function zt(){let t=x;if(!(!t||!t.running)){try{let e=t.capture.route();e&&e!==t.lastServeRoute&&(t.lastServeRoute=e,ct(t));}catch(e){}t.eventTimer===null&&(t.eventTimer=(typeof window!="undefined"?window.setTimeout:setTimeout)(()=>{t.eventTimer=null;try{let e=Date.now();if(e-t.lastFrictionEmitAt<Ot||!$(t.capture.trail(),e))return;t.lastFrictionEmitAt=e,at(t,"friction");}catch(e){}},Pt));}}function ut(t){let e=x;if(!(!e||!e.running||!e.config.boundaryAsk))try{t.clientY<=0&&at(e,"boundary");}catch(n){}}function M(t){if(!t.running){if(t.suppressed){t.config.debug&&console.debug("[sightspool] capture suppressed on localhost (set captureOnLocalhost:true to override)");return}t.running=true,t.capture.start(),t.harvest.start(),t.egress.start(),t.capture.onEvent(zt);try{document.addEventListener("mouseout",ut);}catch(e){}t.interventionsEnabled&&(t.lastServeRoute=(()=>{try{return t.capture.route()}catch(e){return null}})(),(typeof window!="undefined"?window.setTimeout:setTimeout)(()=>{ct(t);},Mt)),t.config.debug&&console.debug("[sightspool] started",t.sessionRef);}}function dt(t){try{if(!t||!t.key){console.warn("[sightspool] init: a `key` is required");return}if(x)return;let e=t.endpoint||Ht,n={redact:t.redact,block:t.block},o=W({debug:!!t.debug,...n}),r=j(o,{debug:!!t.debug,...n}),s=G({key:t.key,endpoint:e,debug:!!t.debug});x={config:{...t,key:t.key,endpoint:e,boundaryAsk:t.boundaryAsk!==!1,debug:!!t.debug},capture:o,harvest:r,egress:s,identity:{},sessionRef:Ft(),fatigue:{promptsShown:0,lastPromptAt:null},lastFrictionEmitAt:0,eventTimer:null,running:!1,suppressed:et(qt())&&t.captureOnLocalhost!==!0,interventionsEnabled:t.interventions!==!1,lastServeRoute:null,surveyOnScreen:!1,interventionsShown:0},t.consent!==!1&&M(x);}catch(e){try{console.warn("[sightspool] init failed",e);}catch(n){}}}function Bt(t,e){try{if(!x)return;x.identity={userId:t,account:e==null?void 0:e.account,plan:e==null?void 0:e.plan},x.egress.setIdentity(x.identity);}catch(n){}}function Kt(){try{x&&M(x);}catch(t){}}function Wt(t){try{if(!x)return;t?M(x):lt();}catch(e){}}function lt(){try{if(!x)return;x.running=!1,x.capture.stop(),x.harvest.stop(),x.egress.stop();try{document.removeEventListener("mouseout",ut);}catch(t){}}catch(t){}}var jt={init:dt,identify:Bt,start:Kt,stop:lt,consent:Wt},ue=jt,st;try{if(typeof document!="undefined"){let t=(st=document.currentScript)!=null?st:document.querySelector("script[data-sightspool-key]"),e=t==null?void 0:t.getAttribute("data-sightspool-key");if(e){let n=(t==null?void 0:t.getAttribute("data-sightspool-endpoint"))||void 0;if(!n&&(t!=null&&t.src))try{n=new URL(t.src).origin;}catch(r){}let o=r=>{let s=t==null?void 0:t.getAttribute(r);if(!s)return;let f=s.split(",").map(a=>a.trim()).filter(Boolean);return f.length?f:void 0};dt({key:e,endpoint:n,redact:o("data-sightspool-redact"),block:o("data-sightspool-block"),captureOnLocalhost:(t==null?void 0:t.hasAttribute("data-sightspool-capture-localhost"))||void 0,interventions:t!=null&&t.hasAttribute("data-sightspool-no-interventions")?!1:void 0,debug:(t==null?void 0:t.hasAttribute("data-sightspool-debug"))||void 0});}}}catch(t){}
38
- exports.consent=Wt;exports.default=ue;exports.identify=Bt;exports.init=dt;exports.start=Kt;exports.stop=lt;Object.defineProperty(exports,'__esModule',{value:true});return exports;})({});//# sourceMappingURL=sdk.global.js.map
58
+ `;});R();var W=30,ve=700,we=1e3,Ee=3;function Se(){return typeof window!="undefined"&&typeof document!="undefined"}function G(e){var S,w;let t=(S=e.redact)!=null?S:[],n=(w=e.block)!=null?w:[],o=[],r,c=false,l=[],s=[],u=[];function p(){for(let d of l)try{d();}catch(x){}}function h(d,x){try{o.push({t:Date.now(),type:d,label:x?U(x):void 0}),o.length>W&&(o=o.slice(-W)),e.debug&&console.debug("[sightspool] event",d,x),p();}catch(b){}}function g(){try{return location.pathname+location.search}catch(d){return ""}}function f(){try{return document.title||""}catch(d){return ""}}function y(d){var x;try{let b=d.target;if(A(b,n))return;let _=b&&(((x=b.getAttribute)==null?void 0:x.call(b,"aria-label"))||b.textContent)||"",k=L(b,t)?K:_.trim().slice(0,60),F=Date.now();u=u.filter(P=>F-P<=we),u.push(F);let me=u.length>=Ee;h(me?"rage_click":"click",k);let he=g(),z=!1,T=null;try{T=new MutationObserver(()=>{z=!0;}),T.observe(document.body,{childList:!0,subtree:!0,attributes:!0});}catch(P){}window.setTimeout(()=>{try{T==null||T.disconnect(),!z&&g()===he&&k&&h("dead_click",k);}catch(P){}},ve);}catch(b){}}function i(d){try{r=String(d.message||"error"),h("error",r);}catch(x){}}function a(d){try{let x=d.reason;r=x instanceof Error?x.message:String(x),h("error",r);}catch(x){}}function m(){try{let d=()=>h("route",g()),x=history.pushState,b=history.replaceState;history.pushState=function(..._){let k=x.apply(this,_);return d(),k},history.replaceState=function(..._){let k=b.apply(this,_);return d(),k},window.addEventListener("popstate",d),s.push(()=>{history.pushState=x,history.replaceState=b,window.removeEventListener("popstate",d);}),h("route",g());}catch(d){}}function C(){try{if(typeof window.fetch!="function")return;let d=window.fetch.bind(window);window.fetch=async(...x)=>{try{let b=await d(...x);return b.ok||h("request_error",`HTTP ${b.status}`),b}catch(b){throw h("request_error",b instanceof Error?b.message:"network error"),b}},s.push(()=>{window.fetch=d;});}catch(d){}}return {start(){if(!(c||!Se())){c=true;try{document.addEventListener("click",y,!0),window.addEventListener("error",i),window.addEventListener("unhandledrejection",a),s.push(()=>{document.removeEventListener("click",y,!0),window.removeEventListener("error",i),window.removeEventListener("unhandledrejection",a);}),m(),C();}catch(d){}}},stop(){c=false;for(let d of s.splice(0))try{d();}catch(x){}},trail(){return o.slice()},route:g,label:f,error(){return r},onEvent(d){l.push(d);},recordSearch(d,x){let b=d.trim();b&&h(x?"zero_result":"search",b);}}}R();var Ce=/search|filter|find|query|command|lookup/i,ke=800;function _e(e){try{let t=e;if(t.type==="search")return !0;let n=e.getAttribute("role")||"";if(n==="searchbox"||n==="combobox")return !0;let o=[t.name,t.placeholder,e.getAttribute("aria-label"),e.id,e.className].filter(Boolean).join(" ");return Ce.test(o)}catch(t){return false}}function $(e,t){var u,p;let n,o=null,r=false,c=(u=t.redact)!=null?u:[],l=(p=t.block)!=null?p:[];function s(h){try{let g=h.target;if(!g||g.tagName!=="INPUT"&&g.tagName!=="TEXTAREA"||!_e(g)||A(g,l)||L(g,c))return;let f=(g.value||"").trim();if(f.length<2)return;o!==null&&window.clearTimeout(o),o=window.setTimeout(()=>{n=f,e.recordSearch(f),t.debug&&console.debug("[sightspool] harvested intent",f);},ke);}catch(g){}}return {start(){if(!(r||typeof document=="undefined")){r=true;try{document.addEventListener("input",s,!0);}catch(h){}}},stop(){r=false;try{document.removeEventListener("input",s,!0),o!==null&&window.clearTimeout(o);}catch(h){}},lastIntentHint(){return n}}}function j(e){let t=[],n,o=null,r=false,c=`${e.endpoint.replace(/\/+$/,"")}/api/sdk/ingest`;function l(p){if(p.length===0)return;let h={key:e.key,identity:n,signals:p},g=JSON.stringify(h);try{if(typeof navigator!="undefined"&&typeof navigator.sendBeacon=="function"){let f=new Blob([g],{type:"text/plain"});if(navigator.sendBeacon(c,f)){e.debug&&console.debug("[sightspool] beacon",p.length);return}}fetch(c,{method:"POST",headers:{"Content-Type":"text/plain"},body:g,keepalive:!0,mode:"cors",credentials:"omit"}).catch(()=>{});}catch(f){}}function s(){try{document.visibilityState==="hidden"&&u();}catch(p){}}function u(){if(t.length===0)return;let p=t;t=[],l(p);}return {start(){if(!(r||typeof window=="undefined")){r=true;try{document.addEventListener("visibilitychange",s),window.addEventListener("pagehide",u),o=window.setInterval(u,15e3);}catch(p){}}},stop(){r=false;try{document.removeEventListener("visibilitychange",s),window.removeEventListener("pagehide",u),o!==null&&window.clearInterval(o);}catch(p){}u();},enqueue(p){t.push(p),t.length>=10&&u();},flush:u,setIdentity(p){n=p;}}}function Y(e,t,n=8e3){var l;let o=e.filter(s=>t-s.t<=n);if(o.some(s=>s.type==="error"||s.type==="request_error"))return "error";let r=o.filter(s=>s.type==="click"||s.type==="rage_click");for(let s=0;s<r.length;s++)if(r.filter(p=>p.t>=r[s].t&&p.t-r[s].t<=1e3).length>=3)return "rage";if(o.some(s=>s.type==="dead_click"))return "dead_end";let c=new Map;for(let s of r){if(!s.label)continue;let u=((l=c.get(s.label))!=null?l:0)+1;if(c.set(s.label,u),u>=3)return "retry"}return null}var N={maxPromptsPerSession:1,cooldownMs:5*6e4};function V(e,t,n=N){return !(e.promptsShown>=n.maxPromptsPerSession||e.lastPromptAt!==null&&t-e.lastPromptAt<n.cooldownMs)}var Te=new Set(["survey","demand_probe"]);function E(e,t){if(typeof e!="string")return;let n=e.trim();return n?n.slice(0,t):void 0}function J(e,t){let n={},o=E(e,500);o&&(n.route=o);let r=E(t==null?void 0:t.account,200);r&&(n.account=r);let c=E(t==null?void 0:t.plan,80);return c&&(n.plan=c),n}function Ie(e){if(!e||typeof e!="object")return null;let t=e,n=E(t.id,64),o=E(t.type,40);if(!n||!o||!Te.has(o))return null;let r=t.config&&typeof t.config=="object"?t.config:{};if(o==="demand_probe"){let u=E(r.label,200),p=E(r.disclosure,300);if(!u||!p)return null;let h=E(r.slot,64),g=h&&/^[a-z0-9][a-z0-9_-]*$/i.test(h)?h:void 0;return {id:n,type:o,config:{label:u,disclosure:p,...g?{slot:g}:{}}}}let c=E(r.question,500);if(!c)return null;let l=Array.isArray(r.options)?r.options.map(u=>E(u,200)).filter(u=>!!u).slice(0,6):void 0,s={question:c,...l&&l.length?{options:l}:{},allow_text:r.allow_text===true};return {id:n,type:"survey",config:s}}function Ae(e,t,n){let o=E(e,200);if(o)return o;let r=E(t,200);return r||n}var X="sightspool_rk";function Z(e,t){let n=E(e==null?void 0:e.userId,200);if(n)return n;try{let o=localStorage.getItem(X);return o||(o="anon-"+Math.random().toString(36).slice(2)+Date.now().toString(36),localStorage.setItem(X,o)),Ae(void 0,o,t)}catch(o){return t}}function Q(e,t){return `${e.replace(/\/+$/,"")}/api/sdk/${t}`}async function ee(e){var t;try{if(typeof fetch!="function")return null;let n=await fetch(Q(e.endpoint,"serve"),{method:"POST",headers:{"Content-Type":"text/plain"},body:JSON.stringify({key:e.key,context:e.ctx,respondent_key:e.respondentKey}),mode:"cors",credentials:"omit"});if(!n.ok)return null;let o=await n.json(),r=Ie(o==null?void 0:o.intervention);return e.debug&&console.debug("[sightspool] serve",(t=r==null?void 0:r.id)!=null?t:"(none)"),r}catch(n){return null}}function M(e){try{let t=Q(e.endpoint,"respond"),n=JSON.stringify({key:e.key,intervention_id:e.interventionId,response:e.response,respondent_key:e.respondentKey});if(typeof navigator!="undefined"&&typeof navigator.sendBeacon=="function"){let o=new Blob([n],{type:"text/plain"});if(navigator.sendBeacon(t,o))return}typeof fetch=="function"&&fetch(t,{method:"POST",headers:{"Content-Type":"text/plain"},body:n,keepalive:!0,mode:"cors",credentials:"omit"}).catch(()=>{});}catch(t){}}var Le=new Set(["localhost","127.0.0.1","0.0.0.0","::1",""]);function te(e){let t=(e!=null?e:"").trim().toLowerCase();return Le.has(t)?true:t.endsWith(".local")||t.endsWith(".localhost")}var Fe="https://www.sightspool.com",ze=3e4,Ue=600,Be=2500,Ke=1;function We(){try{return typeof location!="undefined"?location.hostname:""}catch(e){return ""}}var v=null;function Ge(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}return "s-"+Math.random().toString(36).slice(2)+Date.now().toString(36)}function $e(e){let t=[],n=e.harvest.lastIntentHint();n&&t.push(`Searching for \u201C${n}\u201D`);let o=e.capture.label();return o&&t.push(`Something on \u201C${o.slice(0,40)}\u201D`),t}function D(e,t,n={}){let o=e.capture.error();return {captured_at:new Date().toISOString(),route:e.capture.route(),client_label:e.capture.label(),trail:e.capture.trail(),session_ref:e.sessionRef,trigger:t,intent_hint:e.harvest.lastIntentHint(),error:o,outcome:o||t==="friction"?"failed":"unknown",...n}}async function de(e,t){var o;let n=Date.now();if(V(e.fatigue,n,N)){e.fatigue.promptsShown+=1,e.fatigue.lastPromptAt=n;try{let{showPrompt:r}=await Promise.resolve().then(()=>(oe(),ne)),c=await r({candidates:$e(e)});e.egress.enqueue(D(e,t,{answer:c.answer,verbatim:c.verbatim,intent_hint:(o=c.intent)!=null?o:e.harvest.lastIntentHint(),outcome:c.answer==="yes"?"achieved":"failed"}));}catch(r){e.egress.enqueue(D(e,t));}}else e.egress.enqueue(D(e,t));}async function ue(e){if(!e.running||!e.interventionsEnabled||e.suppressed||e.surveyOnScreen||e.interventionsShown>=Ke)return;let t=Date.now();if(e.fatigue.lastPromptAt!==null&&t-e.fatigue.lastPromptAt<N.cooldownMs)return;let n=Z(e.identity,e.sessionRef),o=await ee({endpoint:e.config.endpoint,key:e.config.key,ctx:J(e.capture.route(),e.identity),respondentKey:n,debug:e.config.debug});if(!o||!e.running)return;let r=e.interventionsShown,c=e.fatigue.lastPromptAt;e.surveyOnScreen=true,e.interventionsShown+=1,e.fatigue.lastPromptAt=Date.now();try{if(o.type==="demand_probe"){let{showProbe:l}=await Promise.resolve().then(()=>(ie(),re)),s=await l(o.config);s.mounted?s.voted&&M({endpoint:e.config.endpoint,key:e.config.key,interventionId:o.id,response:{choice:"vote"},respondentKey:n}):(e.interventionsShown=r,e.fatigue.lastPromptAt=c);}else {let{showSurvey:l}=await Promise.resolve().then(()=>(ae(),se)),s=await l(o.config);!s.dismissed&&(s.choice||s.text)&&M({endpoint:e.config.endpoint,key:e.config.key,interventionId:o.id,response:{choice:s.choice,text:s.text},respondentKey:n});}}catch(l){}finally{e.surveyOnScreen=false;}}function je(){let e=v;if(!(!e||!e.running)){try{let t=e.capture.route();t&&t!==e.lastServeRoute&&(e.lastServeRoute=t,ue(e));}catch(t){}e.eventTimer===null&&(e.eventTimer=(typeof window!="undefined"?window.setTimeout:setTimeout)(()=>{e.eventTimer=null;try{let t=Date.now();if(t-e.lastFrictionEmitAt<ze||!Y(e.capture.trail(),t))return;e.lastFrictionEmitAt=t,de(e,"friction");}catch(t){}},Ue));}}function le(e){let t=v;if(!(!t||!t.running||!t.config.boundaryAsk))try{e.clientY<=0&&de(t,"boundary");}catch(n){}}function q(e){if(!e.running){if(e.suppressed){e.config.debug&&console.debug("[sightspool] capture suppressed on localhost (set captureOnLocalhost:true to override)");return}e.running=true,e.capture.start(),e.harvest.start(),e.egress.start(),e.capture.onEvent(je);try{document.addEventListener("mouseout",le);}catch(t){}e.interventionsEnabled&&(e.lastServeRoute=(()=>{try{return e.capture.route()}catch(t){return null}})(),(typeof window!="undefined"?window.setTimeout:setTimeout)(()=>{ue(e);},Be)),e.config.debug&&console.debug("[sightspool] started",e.sessionRef);}}function pe(e){try{if(!e||!e.key){console.warn("[sightspool] init: a `key` is required");return}if(v)return;let t=e.endpoint||Fe,n={redact:e.redact,block:e.block},o=G({debug:!!e.debug,...n}),r=$(o,{debug:!!e.debug,...n}),c=j({key:e.key,endpoint:t,debug:!!e.debug});v={config:{...e,key:e.key,endpoint:t,boundaryAsk:e.boundaryAsk!==!1,debug:!!e.debug},capture:o,harvest:r,egress:c,identity:{},sessionRef:Ge(),fatigue:{promptsShown:0,lastPromptAt:null},lastFrictionEmitAt:0,eventTimer:null,running:!1,suppressed:te(We())&&e.captureOnLocalhost!==!0,interventionsEnabled:e.interventions!==!1,lastServeRoute:null,surveyOnScreen:!1,interventionsShown:0},e.consent!==!1&&q(v);}catch(t){try{console.warn("[sightspool] init failed",t);}catch(n){}}}function Ye(e,t){try{if(!v)return;v.identity={userId:e,account:t==null?void 0:t.account,plan:t==null?void 0:t.plan},v.egress.setIdentity(v.identity);}catch(n){}}function Ve(){try{v&&q(v);}catch(e){}}function Xe(e){try{if(!v)return;e?q(v):fe();}catch(t){}}function fe(){try{if(!v)return;v.running=!1,v.capture.stop(),v.harvest.stop(),v.egress.stop();try{document.removeEventListener("mouseout",le);}catch(e){}}catch(e){}}var Je={init:pe,identify:Ye,start:Ve,stop:fe,consent:Xe},ht=Je,ce;try{if(typeof document!="undefined"){let e=(ce=document.currentScript)!=null?ce:document.querySelector("script[data-sightspool-key]"),t=e==null?void 0:e.getAttribute("data-sightspool-key");if(t){let n=(e==null?void 0:e.getAttribute("data-sightspool-endpoint"))||void 0;if(!n&&(e!=null&&e.src))try{n=new URL(e.src).origin;}catch(r){}let o=r=>{let c=e==null?void 0:e.getAttribute(r);if(!c)return;let l=c.split(",").map(s=>s.trim()).filter(Boolean);return l.length?l:void 0};pe({key:t,endpoint:n,redact:o("data-sightspool-redact"),block:o("data-sightspool-block"),captureOnLocalhost:(e==null?void 0:e.hasAttribute("data-sightspool-capture-localhost"))||void 0,interventions:e!=null&&e.hasAttribute("data-sightspool-no-interventions")?!1:void 0,debug:(e==null?void 0:e.hasAttribute("data-sightspool-debug"))||void 0});}}}catch(e){}
59
+ exports.consent=Xe;exports.default=ht;exports.identify=Ye;exports.init=pe;exports.start=Ve;exports.stop=fe;Object.defineProperty(exports,'__esModule',{value:true});return exports;})({});//# sourceMappingURL=sdk.global.js.map
39
60
  //# sourceMappingURL=sdk.global.js.map