(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,895301,e=>{"use strict";var r=e.i(651681);let t={name:"message-circle",size:24,node:[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]]};t.node;let n=(0,r.f)(t);e.s(["f",0,n],895301)},226633,e=>{"use strict";var r=e.i(659350),t=e.i(136562),n=e.i(596376),i=e.i(139697),a=e.i(181870),o=e.i(475615),s=e.i(1423),l=e.i(326e3),c=e.i(647204);e.i(707060);var u=e.i(288265),d=e.i(895301),m=e.i(16043),f=e.i(375702),p=e.i(901869);let h="A shopper filling in a checkout form, as a list of timestamped events in order. Judge the whole session so far.",g="SAVE10",x=["United States","Canada","United Kingdom","Germany","France","Australia","Japan"],y=({instructions:e,yes:r,no:t,line:n,label:i})=>({type:"noul",instructions:e,criteria:{true:r,false:t},line:n,label:i}),v={promo:y({instructions:"Is the user struggling with the promo code?",yes:"A rejected code, retyping or clearing the code, or a long pause on that field.",no:"No promo activity yet, or a code accepted on the first try.",line:.7,label:"Struggling with the promo code"}),quit:y({instructions:"Is the user about to give up?",yes:"Repeated errors, long idles, going back and forth, or stalling with fields still empty.",no:"Steady progress through the form.",line:.7,label:"About to give up"}),fraud:y({instructions:"Does this look like card testing or fraud?",yes:"Several different card numbers, quick retries after rejections, or details that do not fit together.",no:"One card, entered once, at an ordinary pace.",line:.7,label:"Looks like card testing"}),ready:y({instructions:"Is the user ready to pay?",yes:"Every field is filled and accepted and there are no recent errors.",no:"Fields are missing, an error is outstanding, or the user is still editing.",line:.8,label:"Ready to pay"}),shipping:y({instructions:"Is the user unsure about shipping?",yes:"Changed the country more than once, or paused a long time on it.",no:"Chose a country once and moved on.",line:.7,label:"Unsure about shipping"}),help:y({instructions:"Would a live chat offer help right now?",yes:"Stuck on the same problem for a while, or failing repeatedly.",no:"Moving along, or only just started.",line:.7,label:"Would want live chat"}),comparing:y({instructions:"Is the user comparing prices somewhere else?",yes:"Left the tab and came back, or idled a long time right before paying.",no:"Stayed on the page and kept filling in the form.",line:.7,label:"Comparing prices elsewhere"}),returning:y({instructions:"Is this a returning customer?",yes:"Fast, confident entries with no errors.",no:"Slow, exploratory entries, or first attempts that fail.",line:.7,label:"Returning customer"})},k=["promo","quit","fraud","ready","shipping","help","comparing","returning"],j=Object.fromEntries(k.map(e=>[e,{type:"noul",instructions:v[e].instructions,criteria:v[e].criteria}])),b=`${h} Answer every question with true or false. Reply only with JSON.`,w={type:"object",properties:Object.fromEntries(k.map(e=>[e,{type:"boolean"}])),required:k,additionalProperties:!1},N=[{kind:"focus",field:"email"},{kind:"type",field:"email",value:"sam.ortega@example.com"},{kind:"focus",field:"card"},{kind:"type",field:"card",value:"4242 4242 4242 4242"},{kind:"focus",field:"promo"},{kind:"type",field:"promo",value:"SAVE20"},{kind:"apply"},{kind:"wait",ms:2500},{kind:"type",field:"promo",value:""},{kind:"type",field:"promo",value:"SAVE25"},{kind:"apply"},{kind:"focus",field:"country"},{kind:"country",value:"Germany"},{kind:"country",value:"France"},{kind:"focus",field:"promo"},{kind:"wait",ms:6500}],S=`import { OpenRouter } from '@openrouter/sdk'; const openRouter = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY }); // About a second after each event in the form, ask eight questions about the session so far. const questions = { ${k.map(e=>` ${e}: { type: 'noul', instructions: '${v[e].instructions}', criteria: { true: '${v[e].criteria.true}', false: '${v[e].criteria.false}', }, },`).join("\n")} }; const { answers } = await openRouter.alpha.decisions.create({ decisionsRequest: { model: 'typesafe/jev-1.13', state: { description: '${h}', events, // ['0:04 typed in Email', '0:12 promo code rejected: SAVE20', '0:18 idle 6 s on Promo code', …] }, questions, }, }); if (answers.promo.noul > ${v.promo.line}) showPromoHint(); // the form reacts to the number if (answers.help.noul > ${v.help.line}) offerLiveChat();`;var C=e.i(13718);let $={kind:"idle"};function R(e,r){switch(r.type){case"started":return"watching"===e.kind?e:{kind:"watching"};case"sample_started":return"watching"===e.kind?{kind:"playing_sample"}:e;case"sample_ended":return"playing_sample"===e.kind?{kind:"watching"}:e;case"reset":return"idle"===e.kind?e:$;default:return r}}let E={email:"Email",card:"Card number",promo:"Promo code",country:"Country"},T={asked:0,latencies:[],cost:0,agreed:0,compared:0},A=e=>{if(!e.length)return 0;let r=[...e].sort((e,r)=>e-r);return r[Math.floor(r.length/2)]};e.s(["NoticeRecipe",0,function(){let e=(0,u.f)(),[y,P]=(0,m.useReducer)(R,$),F="idle"!==y.kind,M="playing_sample"===y.kind,[B,O]=(0,m.useState)([]),[q,z]=(0,m.useState)({status:"idle",probs:{},checks:0,latencies:[],cost:0}),[_,I]=(0,m.useState)({}),[U,V]=(0,m.useState)(T),[K,J]=(0,m.useState)(""),[L,W]=(0,m.useState)(""),[D,G]=(0,m.useState)(""),[H,X]=(0,m.useState)(""),[Y,Q]=(0,m.useState)("none"),[Z,ee]=(0,m.useState)(!1),[er,et]=(0,m.useState)(!1),en=(0,m.useRef)(null),ei=(0,m.useRef)([]),ea=(0,m.useRef)(null),eo=(0,m.useRef)(null),es=(0,m.useRef)(null),el=(0,m.useRef)({}),ec=(0,m.useRef)(null),eu=(0,m.useRef)(!1),ed=(0,m.useRef)(null),em=(0,m.useRef)(null),ef=(0,m.useRef)(0),ep=(0,m.useRef)(0),eh=(0,m.useRef)(!1),eg=(0,m.useRef)(null),ex=(0,m.useCallback)(()=>{for(let{timer:e}of(eu.current=!1,ef.current+=1,ea.current=null,ec.current?.abort(),em.current=null,eg.current?.(),eg.current=null,eo.current&&(clearTimeout(eo.current),eo.current=null),es.current&&(clearTimeout(es.current),es.current=null),Object.values(el.current)))clearTimeout(e);el.current={}},[]),ey=(0,m.useCallback)(()=>{if(!eu.current||document.hidden)return;ec.current?.abort();let e=new AbortController;ec.current=e;let r=ei.current,t=ep.current,n=ef.current,i=()=>!e.signal.aborted&&eu.current&&ef.current===n&&ep.current===t;z(e=>i()?{...e,status:"sending"}:e);let a=(0,C.A)({state:{description:h,events:r},questions:j},e.signal).then(e=>{if((0,c.V)(e)){if(i()){let r=(0,C.G)(e.error);z(e=>i()?{...e,status:"error",error:r}:e)}return null}let r=e.data,t={};for(let e of k){let n=r.answers[e];n&&"noul"===n.type&&(t[e]=n.noul)}return i()&&(z(e=>i()?{status:"done",probs:t,checks:e.checks+1,latencies:[...e.latencies,r.latencyMs],cost:e.cost+(r.usage.cost??0)}:e),I(e=>{if(!i())return e;let r={...e};for(let e of k)(t[e]??0)>=v[e].line&&(r[e]=!0);return r})),t});if(em.current&&!em.current.signal.aborted)return;em.current=e;let o=performance.now();(0,C.e)({model:"openai/gpt-6-luna",system:b,user:`${k.map(e=>`${e}: ${v[e].instructions} true means: ${v[e].criteria.true} false means: ${v[e].criteria.false}`).join("\n")} Session so far: ${r.join("\n")}`,schema:w},e.signal).then(async e=>{if((0,c.V)(e))return;let r=e.data,t=Math.round(performance.now()-o),n=await a??{},s=k.filter(e=>void 0!==n[e]),l=s.filter(e=>{let t=n[e];return void 0!==t&&!!r.json[e]==t>=.5}).length;i()&&V(e=>i()?{asked:e.asked+1,latencies:[...e.latencies,t],cost:e.cost+(r.usage.cost??0),agreed:e.agreed+l,compared:e.compared+s.length}:e)}).finally(()=>{em.current===e&&(em.current=null)})},[]),ev=(0,m.useCallback)(()=>{if(eo.current&&(clearTimeout(eo.current),eo.current=null),!ea.current||!eu.current)return;let e=ef.current;eo.current=setTimeout(()=>{ea.current&&eu.current&&ef.current===e&&(eo.current=null,ek(`idle 6 s on ${E[ea.current]}`))},6e3)},[]),ek=(0,m.useCallback)(e=>{let r;if(!eu.current)return;let t=`${(r=Math.max(0,Math.round((performance.now()-(en.current??performance.now()))/1e3)),`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`)} ${e}`;ep.current+=1,ei.current=[...ei.current,t],O(ei.current),es.current&&clearTimeout(es.current);let n=ef.current;es.current=setTimeout(()=>{eu.current&&ef.current===n&&ey()},1e3)},[ey]),ej=(0,m.useEffectEvent)(()=>{document.hidden&&eu.current?(ed.current=performance.now(),ex(),P({type:"sample_ended"})):document.hidden||null===ed.current||(eu.current=!0,ek(`came back after ${Math.round((performance.now()-ed.current)/1e3)} s away`),ed.current=null)});(0,m.useEffect)(()=>(document.addEventListener("visibilitychange",ej),()=>{ex(),document.removeEventListener("visibilitychange",ej)}),[ex]);let eb=()=>{ex(),ed.current=null,P({type:"reset"}),en.current=null,ei.current=[],O([]),z({status:"idle",probs:{},checks:0,latencies:[],cost:0}),I({}),V(T),J(""),W(""),G(""),X(""),Q("none"),ee(!1),et(!1)},ew=()=>{eb(),eu.current=!0,P({type:"started"}),en.current=performance.now()},eN=e=>{ea.current!==e&&ek(`focused ${E[e]}`),ea.current=e,ev()},eS=(e,r)=>{"card"===e?ek(`entered a card number ending ${r.replaceAll(/\D/g,"").slice(-4)||"…"}`):"promo"===e?ek(`typed promo code ${r.toUpperCase()}`):ek("typed in Email")},eC=(e,r)=>{ep.current+=1;let t=el.current[e];if(t&&(clearTimeout(t.timer),delete el.current[e]),"email"===e&&J(r),"card"===e&&(W(r),ee(!1)),"promo"===e&&(G(r),Q("none")),!eu.current)return;if(ea.current===e&&ev(),""===r)return void ek(`cleared ${E[e]}`);let n=ef.current;el.current[e]={timer:setTimeout(()=>{eu.current&&ef.current===n&&(delete el.current[e],eS(e,r))},700),value:r}},e$=e=>{if("country"!==e){let r=el.current[e];r&&(clearTimeout(r.timer),delete el.current[e],eu.current&&eS(e,r.value))}ea.current===e&&(ea.current=null,eo.current&&(clearTimeout(eo.current),eo.current=null))},eR=(e=D)=>{let r=e.trim().toUpperCase();if(!r)return;let t=r===g;Q(t?"ok":"bad"),ek(t?`promo code accepted: ${r}`:`promo code rejected: ${r}`)},eE=e=>{X(e),"country"===ea.current&&ev(),ek(`chose country ${e}`)},eT=async()=>{ew(),P({type:"sample_started"});let e=ef.current,r=()=>eu.current&&ef.current===e,t=e=>new Promise(r=>{let t=setTimeout(()=>{eg.current=null,r()},e);eg.current=()=>{clearTimeout(t),r()}}),n="";for(let e of N){if(!r())return;if("focus"===e.kind)eN(e.field);else if("type"===e.kind){"promo"===e.field&&(n=e.value);for(let n=1;n<=e.value.length||1===n;n++)if(!r()||(eC(e.field,e.value.slice(0,n)),await t("promo"===e.field?120:45),!r()))return;if(await t(900),!r())return}else"apply"===e.kind?eR(n):"country"===e.kind&&eE(e.value);if("wait"===e.kind?await t(e.ms):await t(600),!r())return}P({type:"sample_ended"})},eA=q.probs,eP=q.checks>0?e("{count} answers per check",{count:k.length}):void 0;return(0,r.jsx)(p.B,{id:"notice",fill:!0,code:{code:S,filename:"notice.ts"},controls:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,r.jsx)(p.K,{idle:e("Start watching"),again:e("Reset"),running:e("Starting…"),status:F?"done":"idle",onClick:F?eb:ew}),(0,r.jsx)(p.I,{label:e("Play a sample session"),children:(0,r.jsx)(i.Button,{disabled:M,onClick:()=>void eT(),children:M?e("Playing…"):e("Play a sample session")})}),eP&&(0,r.jsx)(p.X,{children:eP})]}),"error"===q.status&&(0,r.jsx)(n.J,{variant:"negative",children:q.error})]}),children:(0,r.jsxs)("div",{className:"grid gap-6 md:min-h-0 md:flex-1 md:grid-cols-3 md:grid-rows-[minmax(0,1fr)]",children:[(0,r.jsxs)("section",{className:"flex min-w-0 flex-col gap-3 md:min-h-0",children:[(0,r.jsx)("h2",{className:"text-size-section font-medium text-foreground",children:e("Checkout")}),(0,r.jsxs)("div",{className:"flex flex-col gap-4 rounded-(--radius-lg) border border-border p-5 md:min-h-0 md:flex-1 md:overflow-y-auto",children:[(0,r.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,r.jsx)(o.f,{htmlFor:"notice-email",children:e("Email")}),(0,r.jsx)(a.f,{id:"notice-email",type:"email",value:K,onFocus:()=>eN("email"),onBlur:()=>e$("email"),onChange:e=>eC("email",e.target.value),placeholder:e("you@company.com")})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,r.jsx)(o.f,{htmlFor:"notice-card",children:e("Card number")}),(0,r.jsx)(a.f,{id:"notice-card",inputMode:"numeric",value:L,onFocus:()=>eN("card"),onBlur:()=>{e$("card"),L&&16!==L.replaceAll(/\D/g,"").length&&(ee(!0),ek("card number rejected: wrong length"))},onChange:e=>eC("card",e.target.value),placeholder:e("4242 4242 4242 4242"),"aria-invalid":Z}),Z&&(0,r.jsx)("p",{className:"text-size-overline text-(--negative-text)",children:e("That number is not 16 digits.")})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,r.jsx)(o.f,{htmlFor:"notice-promo",children:e("Promo code")}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(a.f,{id:"notice-promo",value:D,onFocus:()=>eN("promo"),onBlur:()=>e$("promo"),onChange:e=>eC("promo",e.target.value),onKeyDown:e=>"Enter"===e.key&&eR(),placeholder:e("Code"),className:"uppercase"}),(0,r.jsx)(i.Button,{className:"shrink-0",onClick:()=>eR(),disabled:!D.trim(),children:e("Apply")})]}),"bad"===Y&&(0,r.jsx)("p",{className:"text-size-overline text-(--negative-text)",children:e("That code is not valid.")}),"ok"===Y&&(0,r.jsx)("p",{className:"text-size-overline text-(--positive-text)",children:e("10% off applied.")}),_.promo&&"ok"!==Y&&(0,r.jsx)("div",{className:"mt-1 animate-in fade-in duration-500",children:(0,r.jsx)(n.J,{variant:"info",children:e("Having trouble with the code? {promo} works until Friday.",{promo:g})})})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,r.jsx)(o.f,{htmlFor:"notice-country",children:e("Shipping country")}),(0,r.jsxs)(l.Select,{value:H,onValueChange:eE,onOpenChange:e=>{eh.current=e,e?eN("country"):e$("country")},children:[(0,r.jsx)(l.SelectTrigger,{id:"notice-country",onFocus:()=>eN("country"),onBlur:()=>{eh.current||e$("country")},children:(0,r.jsx)(l.SelectValue,{placeholder:e("Choose a country")})}),(0,r.jsx)(l.SelectContent,{children:x.map(e=>(0,r.jsx)(l.SelectItem,{value:e,children:e},e))})]})]}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3 border-t border-border/50 pt-4",children:[(0,r.jsx)(i.Button,{onClick:()=>{et(!0),ek("pressed Pay")},disabled:_.fraud||er,children:e("Pay $49.00")}),_.help&&(0,r.jsx)("div",{className:"flex animate-in fade-in duration-500",children:(0,r.jsxs)(i.Button,{variant:"ghost",onClick:()=>ek("opened live chat"),children:[(0,r.jsx)(d.f,{className:"size-4"}),e("Chat with us")]})}),(0,r.jsx)("span",{className:"text-size-overline text-muted-foreground",children:function(e){let{gt:r,paid:t,fraud:n}=e;return r(t?"Nothing was charged.":n?"We need a moment to verify this card.":"Nothing is ever charged here.")}({gt:e,paid:er,fraud:_.fraud??!1})})]})]})]}),(0,r.jsxs)("section",{className:"flex min-w-0 flex-col gap-3 md:min-h-0",children:[(0,r.jsx)("h2",{className:"text-size-section font-medium text-foreground",children:e("What the software notices")}),(0,r.jsxs)("div",{className:"flex flex-col gap-3 rounded-(--radius-lg) border border-border p-5 md:min-h-0 md:flex-1 md:overflow-y-auto",children:[(0,r.jsx)("ul",{className:"flex flex-col gap-2.5",children:k.map(n=>{let i=eA[n],a=void 0!==i&&i>=v[n].line;return(0,r.jsxs)("li",{className:"grid grid-cols-[minmax(0,1fr)_3.5rem] items-center gap-x-3 gap-y-1",children:[(0,r.jsx)("span",{className:(0,t.f)("text-body",a?"font-medium text-foreground":"text-muted-foreground"),children:v[n].label}),(0,r.jsx)("span",{className:(0,t.f)("text-right tabular-nums text-body",void 0===i?"text-muted-foreground":(0,t.f)((0,p.q)(a),a&&"font-medium")),children:function(e){let{gt:r,p:t,watching:n}=e;return void 0===t?n?"…":"":r("{percent}%",{percent:Math.round(100*t)})}({gt:e,p:i,watching:F})}),(0,r.jsx)(s.f,{value:(i??0)*100,variant:"neutral",track:"muted",className:"col-span-2 h-1.5",indicatorClassName:a?void 0:"bg-muted-foreground/50"})]},n)})}),!F&&(0,r.jsx)("p",{className:"text-body text-muted-foreground",children:e("Press Start, then use the form.")})]})]}),(0,r.jsxs)("section",{className:"flex min-w-0 flex-col gap-6 md:min-h-0",children:[(0,r.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,r.jsx)("h2",{className:"text-size-section font-medium text-foreground",children:e("Benchmark")}),(0,r.jsx)(f.p,{stack:!0,llmName:"Chat model",labels:{decisions:e("Checks"),agreed:e("Same answer")},jev:q.checks>0?{decisions:String(q.checks),medianMs:A(q.latencies),cost:q.cost}:void 0,llm:q.checks>0?{decisions:`${U.asked} of ${q.checks}`,medianMs:A(U.latencies),cost:U.cost}:void 0,agreement:{same:U.agreed,of:U.compared}})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-3 md:min-h-0 md:flex-1",children:[(0,r.jsx)("h2",{className:"text-size-section font-medium text-foreground",children:e("What it saw")}),(0,r.jsxs)("ol",{className:"max-h-56 overflow-y-auto rounded-(--radius-lg) border border-border p-4 font-mono text-size-overline text-muted-foreground md:max-h-none md:min-h-0 md:flex-1",children:[0===B.length&&(0,r.jsx)("li",{className:"font-sans",children:F?e("Nothing yet."):e("Every click and pause lands here as a line of text.")}),B.map((e,n)=>(0,r.jsx)("li",{className:(0,t.f)(n===B.length-1&&"text-foreground"),children:e},e))]})]})]})]})})}],226633)}]); //# sourceMappingURL=2fwptscnc-owq.js.map