(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,444660,e=>{"use strict";let t,r,s;var n=e.i(659350),a=e.i(136562),o=e.i(596376),i=e.i(139697),l=e.i(1423),c=e.i(797521),d=e.i(647204);e.i(707060);var u=e.i(288265),m=e.i(852902),h=e.i(16043),f=e.i(375702),p=e.i(901869);let x={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}},g=["up","down","left","right"],b=[{x:1,y:1},{x:4,y:1},{x:2,y:3},{x:3,y:3},{x:1,y:4},{x:4,y:4}],v={runner:{x:5,y:5},chaser:{x:0,y:0}},w=e=>b.some(t=>t.x===e.x&&t.y===e.y),y=e=>e.x>=0&&e.y>=0&&e.x<6&&e.y<6,j=(e,t)=>e.x===t.x&&e.y===t.y,k=(e,t)=>({x:e.x+x[t].x,y:e.y+x[t].y}),N=(e,t)=>y(k(e,t))&&!w(k(e,t));function R(e,t){let r=e=>6*e.y+e.x,s=new Set([r(e)]),n=[e];for(let e=0;n.length;e++){let a=[];for(let o of n){if(j(o,t))return e;for(let e of g){let t=k(o,e);!y(t)||w(t)||s.has(r(t))||(s.add(r(t)),a.push(t))}}n=a}return Math.abs(e.x-t.x)+Math.abs(e.y-t.y)}let M=e=>`column ${e.x+1}, row ${e.y+1}`;function $({runner:e,chaser:t,lastRunnerMove:r}){let s=b.map(M).join("; "),n=r?` and just moved ${r}.`:".";return`A chase on a 6 by 6 grid. The runner is at ${M(e)}${n} The chaser is at ${M(t)}, ${R(t,e)} steps away around the walls. Walls at: ${s}. The chaser wants to catch the runner as fast as possible.`}function A(e,t){let r={};for(let s of g){if(!N(t,s))continue;let n=k(t,s);r[s]=`Chaser moves ${s} to ${M(n)}. The runner is then ${R(n,e)} steps away around the walls.`}return r}let T="Which move brings the chaser closest to the runner?",C=e=>`'${e.replaceAll("'","\\'")}'`,S=(t=v.runner,s=Object.entries(A(t,r=v.chaser)).map(([e,t])=>` ${e}: ${C(t)},`).join("\n"),`import { OpenRouter } from '@openrouter/sdk'; const openRouter = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY }); // Every chaser move is one request. The state and the options are written out // in words, positions and distances included, so Jev reads them rather than counts. const state = ${C($({runner:t,chaser:r}))}; const { answers } = await openRouter.alpha.decisions.create({ decisionsRequest: { model: 'typesafe/jev-1.13', state, questions: { move: { type: 'choice', instructions: ${C(T)}, criteria: { ${s} }, }, }, }, }); answers.move.choice; // 'right' answers.move.probabilities; // { right: 0.6, down: 0.4 } // Apply the move, then ask again. Two to three decisions a second through OpenRouter.`);var E=e.i(60755);let O={kind:"idle"};function z(e,t){switch(t.type){case"started":return"running"===e.kind?e:{kind:"running"};case"stopped":return"running"===e.kind?{kind:"stopped"}:e;case"failed":return"idle"===e.kind?e:{kind:"failed",error:t.error};default:return t}}var B=e.i(13718);let P={decisions:0,latencies:[],cost:0,catches:0,runnerMoves:0,elapsedMs:0},_={asked:0,answered:0,agreed:0,latencies:[],cost:0},q={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right",w:"up",s:"down",a:"left",d:"right"},J=e=>{if(!e.length)return 0;let t=[...e].sort((e,t)=>e-t);return t[Math.floor(t.length/2)]??0},K=e=>g.some(t=>t===e),H=e=>new Promise(t=>{setTimeout(t,e)});e.s(["GameRecipe",0,function(){var e;let t=(0,u.f)(),[r,s]=(0,h.useState)({...v}),[x,b]=(0,h.useState)(P),[y,R]=(0,h.useReducer)(z,O),M="running"===y.kind,C="idle"!==y.kind,L="failed"===y.kind?y.error:null,[U,D]=(0,h.useState)(!1),[I,X]=(0,h.useState)(_),V=(0,h.useRef)({...v}),Y=(0,h.useRef)(!1),F=(0,h.useRef)(null),G=(0,h.useRef)({startedAt:0,banked:0}),W=(0,h.useRef)(null),[Q,Z]=(0,h.useState)(448),ee=j(r.runner,r.chaser);(0,h.useEffect)(()=>{let e=W.current;if(!e)return;let t=new ResizeObserver(()=>Z(Math.max(240,Math.min(448,e.clientHeight-40))));return t.observe(e),()=>t.disconnect()},[]);let et=(0,h.useRef)(null),er=({runner:e,chaser:t,lastRunnerMove:r,jevMove:s,signal:n})=>{if(n.aborted||et.current&&!et.current.aborted)return;et.current=n,X(e=>({...e,asked:e.asked+1}));let a=performance.now();(0,B.e)({model:"openai/gpt-6-luna",system:"Pick the best chaser move. Reply only with JSON.",user:function({runner:e,chaser:t,lastRunnerMove:r}){let s=Object.entries(A(e,t)).map(([e,t])=>`- ${e}: ${t}`).join("\n");return`${$({runner:e,chaser:t,lastRunnerMove:r})} ${T} ${s}`}({runner:e,chaser:t,lastRunnerMove:r}),schema:{type:"object",properties:{move:{type:"string",enum:Object.keys(A(e,t))}},required:["move"],additionalProperties:!1}},n).then(async e=>{if((0,d.V)(e))return;let t=Math.round(performance.now()-a),r=await s;n.aborted||X(s=>({...s,answered:s.answered+1,agreed:s.agreed+ +(null!==r&&e.data.json.move===r),latencies:[...s.latencies,t],cost:s.cost+(e.data.usage.cost??0)}))}).finally(()=>{et.current===n&&(et.current=null)})},es=e=>{V.current=e,s(e)},en=()=>G.current.banked+(Y.current?performance.now()-G.current.startedAt:0),ea=(0,h.useCallback)(()=>{Y.current&&(G.current.banked+=performance.now()-G.current.startedAt,Y.current=!1,F.current?.abort(),R({type:"stopped"}))},[]);(0,h.useEffect)(()=>()=>F.current?.abort(),[]);let eo=async e=>{let t=e.signal;for(;Y.current&&!t.aborted;){let{runner:e,chaser:r,lastRunnerMove:s}=V.current,n=performance.now(),a=(0,B.A)({state:$({runner:e,chaser:r,lastRunnerMove:s}),questions:{move:function(e,t){let r=A(e,t),s={};for(let e of g){let t=r[e];t&&(s[e]=t)}return{type:"choice",instructions:T,criteria:s}}(e,r)}},t);er({runner:e,chaser:r,lastRunnerMove:s,jevMove:a.then(e=>{if((0,d.V)(e))return null;let t=e.data.answers.move,r=t?.type==="choice"?t.choice:"";return K(r)?r:null}),signal:t});let o=await a;if((0,d.V)(o)){if(t.aborted)return;R({type:"failed",error:(0,B.G)(o.error)}),ea();return}let i=o.data;if(!Y.current||t.aborted)return;let l=i.answers.move;if(!l||"choice"!==l.type)continue;let c=Math.round(performance.now()-n);if(!K(l.choice))continue;let u=l.choice,m=V.current,h=N(m.chaser,u)?k(m.chaser,u):m.chaser,f=j(h,m.runner);if(es({...m,chaser:h}),b(e=>({decisions:e.decisions+1,latencies:[...e.latencies,c],cost:e.cost+(i.usage.cost??0),catches:e.catches+ +!!f,runnerMoves:e.runnerMoves,elapsedMs:en(),last:{choice:u,probabilities:l.probabilities??{[u]:1},ms:c}})),f){D(!0),ea(),await H(700),D(!1);return}}},ei=()=>{let e=new AbortController;F.current=e,Y.current=!0,G.current.startedAt=performance.now(),R({type:"started"}),eo(e)},el=(0,h.useCallback)(e=>{if(!Y.current)return;let t=V.current;if(!N(t.runner,e))return;let r=k(t.runner,e);j(r,t.chaser)||(es({...t,runner:r,lastRunnerMove:e}),b(e=>({...e,runnerMoves:e.runnerMoves+1})))},[]);(0,h.useEffect)(()=>{let e=e=>{let t=q[e.key];if(!t||!Y.current)return;let r=e.target instanceof HTMLElement?e.target:null;r&&("INPUT"===r.tagName||"TEXTAREA"===r.tagName)||(e.preventDefault(),el(t))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[el]);let ec=x.elapsedMs/1e3,ed=ec>0?x.decisions/ec:0,eu=(x.decisions?x.cost/x.decisions:0)*ed*3600,em=(0,c.f)(),eh=x.decisions>0?t("{perSecond} decisions a second · about {perHour} an hour at this pace",{perSecond:ed.toFixed(1),perHour:(0,E.x)(em,eu)}):void 0;return(0,n.jsx)(p.B,{id:"game",fill:!0,code:{code:S,filename:"chaser.ts"},controls:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,n.jsx)(p.K,{idle:t("Start"),again:t("Restart"),running:t("Starting…"),status:C?"done":"idle",onClick:C?()=>{ea(),G.current={startedAt:0,banked:0},es({...v}),b(P),X(_),ei()}:ei}),C&&!M&&!ee&&(0,n.jsx)(p.I,{label:t("Resume"),children:(0,n.jsx)(i.Button,{onClick:ei,children:t("Resume")})}),M&&(0,n.jsxs)(i.Button,{onClick:ea,children:[(0,n.jsx)(m.f,{className:"size-3.5"}),t("Stop")]}),eh&&(0,n.jsx)(p.X,{children:eh})]}),L&&(0,n.jsx)(o.J,{variant:"negative",children:L})]}),children:(0,n.jsxs)("div",{ref:W,className:"grid gap-6 md:min-h-0 md:flex-1 md:grid-cols-[auto_minmax(0,1fr)_minmax(0,1.25fr)] md:grid-rows-[minmax(0,1fr)]",style:{"--board":`${Q}px`},children:[(0,n.jsxs)("section",{className:"flex flex-col gap-3 md:min-h-0",children:[(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("h2",{className:"text-size-section font-medium text-foreground",children:t("Board")}),(0,n.jsx)("span",{className:"text-size-overline tabular-nums text-muted-foreground",children:(e={started:C,catches:x.catches,moves:x.runnerMoves}).started?0===e.catches?t("Not caught yet · {moves} runner moves",{moves:e.moves}):t("Caught {catches} {times} · {moves} runner moves",{catches:e.catches,times:t(1===e.catches?"time":"times"),moves:e.moves}):""})]}),(0,n.jsx)("div",{role:"button",tabIndex:M?0:-1,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),el("up"))},className:(0,a.f)("grid w-full max-w-112 grid-cols-(--board-columns) gap-1 rounded-(--radius-lg) border border-border p-2 transition-colors duration-300 md:w-(--board)",M&&"cursor-pointer",U&&"bg-(--warning-bg)"),"data-allow-inline-style":!0,style:{"--board-columns":"repeat(6, minmax(0, 1fr))"},"aria-label":t("Chase board"),onClick:e=>{if(!M)return;let t=e.currentTarget.getBoundingClientRect(),r=e.clientX-(t.left+t.width/2),s=e.clientY-(t.top+t.height/2);el(Math.abs(r)>Math.abs(s)?r>0?"right":"left":s>0?"down":"up")},children:Array.from({length:36},(e,s)=>{let o={x:s%6,y:Math.floor(s/6)},i=j(o,r.runner),l=j(o,r.chaser);return(0,n.jsxs)("div",{className:(0,a.f)("flex aspect-square items-center justify-center rounded-(--radius-sm) border border-border/50",w(o)&&"border-border bg-[repeating-linear-gradient(135deg,hsl(var(--muted-foreground))_0_2px,transparent_2px_7px)]"),children:[i&&(0,n.jsx)("span",{"aria-label":t("Runner"),className:"size-3/5 rounded-(--radius-full) bg-foreground transition-transform"}),l&&!i&&(0,n.jsx)("span",{"aria-label":t("Chaser"),className:"size-3/5 rounded-(--radius-full) border-2 border-foreground"})]},`${o.x}-${o.y}`)})})]}),(0,n.jsxs)("section",{className:"flex flex-col gap-3 md:min-h-0",children:[(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("h2",{className:"text-size-section font-medium text-foreground",children:t("Last decision")}),x.last&&(0,n.jsx)(p.X,{children:t("{ms} ms",{ms:x.last.ms})})]}),(0,n.jsx)("div",{className:"flex flex-col rounded-(--radius-lg) border border-border p-5 md:h-(--board)",children:x.last?(0,n.jsx)("ul",{className:"flex flex-col gap-2",children:g.filter(e=>x.last?.probabilities[e]!==void 0).map(e=>{let r=x.last;if(!r)return null;let s=r.probabilities[e]??0,o=e===r.choice;return(0,n.jsxs)("li",{className:"flex items-center gap-3 text-body",children:[(0,n.jsx)("span",{className:(0,a.f)("w-12 capitalize",o?"font-medium text-foreground":"text-muted-foreground"),children:e}),(0,n.jsx)(l.f,{value:100*s,variant:"neutral",track:"muted",className:"h-1.5 flex-1",indicatorClassName:o?void 0:"bg-muted-foreground/40"}),(0,n.jsx)("span",{className:(0,a.f)("w-10 text-right tabular-nums",o?(0,p.q)(!0):"text-muted-foreground"),children:t("{percent}%",{percent:Math.round(100*s)})})]},e)})}):(0,n.jsx)("p",{className:"text-body text-muted-foreground",children:t("Jev's options and how it weighed them appear here after the first move.")})})]}),(0,n.jsxs)("section",{className:"contents md:flex md:min-h-0 md:min-w-0 md:flex-col md:gap-6 md:overflow-y-auto",children:[(0,n.jsxs)("div",{className:"flex min-w-0 flex-col gap-3",children:[(0,n.jsx)("h2",{className:"text-size-section font-medium text-foreground",children:t("Benchmark")}),(0,n.jsx)(f.p,{stack:!0,llmName:"Chat model",labels:{decisions:t("Moves"),agreed:t("Same move")},jev:x.decisions>0?{decisions:String(x.decisions),medianMs:J(x.latencies),cost:x.cost}:void 0,llm:x.decisions>0?{decisions:t("{asked} of {total}",{asked:I.asked,total:x.decisions}),medianMs:J(I.latencies),cost:I.cost}:void 0,agreement:{same:I.agreed,of:I.answered}})]}),(0,n.jsxs)("div",{className:"order-first flex min-w-0 flex-col gap-3 md:order-none",children:[(0,n.jsx)("h2",{className:"text-size-section font-medium text-foreground",children:t("How it works")}),(0,n.jsxs)("div",{className:"flex flex-col gap-3 rounded-(--radius-lg) border border-border p-5",children:[(0,n.jsx)(p.N,{children:t("You are the solid disc. Arrow keys move you, or a tap on a side of the board. Jev moves the ring.")}),(0,n.jsx)("p",{className:"text-body text-muted-foreground",children:t("Jev is told where both pieces are and how many steps each move would leave to the runner, then picks one.")})]})]})]})]})})}],444660)}]); //# sourceMappingURL=14dhpfksiz_l6.js.map