@fork-api/chat-sdk 0.1.167 → 0.1.168
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.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
scrollbar-width: thin;
|
|
57
57
|
scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
|
|
58
58
|
}
|
|
59
|
-
`}),go.jsxs("div",{className:"__fork-panel",style:co,children:[go.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid rgba(229, 231, 235, 0.8)",flexShrink:0},children:[go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flex:1},children:[go.jsx("span",{onDoubleClick:async l=>{if(l.stopPropagation(),!G&&confirm("Kill all forks in this container?")){we(true);try{let R=await Fe();`${R?.deleted??0}`,ue([]),le(null),oe(!1),v("");}catch(R){console.error("[Fork] Reset failed:",R);}finally{we(false);}}},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:4,margin:-4,cursor:"pointer",flexShrink:0},children:go.jsx(zt,{style:{width:16,height:16,color:"#1c4587",pointerEvents:"none"}})}),e==="running"?go.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:ao}):ve.length===0&&!rt?go.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:"Fork"}):rt?go.jsxs("div",{ref:Lt,style:{position:"relative",minWidth:0,display:"inline-flex"},children:[go.jsxs("button",{type:"button",onClick:()=>{Je(l=>!l);},onMouseEnter:()=>at(true),onMouseLeave:()=>at(false),"aria-haspopup":"menu","aria-expanded":$e,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 6px",border:"1px solid transparent",borderRadius:6,background:tr||$e?"#f3f4f6":"transparent",fontSize:13,fontWeight:600,color:"#111827",fontFamily:"inherit",cursor:"pointer",maxWidth:180,minWidth:0,transition:"background-color 0.12s"},children:[go.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Xr}),go.jsx(lucideReact.ChevronDown,{style:{width:12,height:12,color:"#6b7280",flexShrink:0,transform:$e?"rotate(180deg)":void 0,transition:"transform 0.15s"}})]}),$e&&go.jsxs("div",{role:"menu",style:{position:"absolute",top:"calc(100% + 4px)",left:0,minWidth:200,maxWidth:260,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06)",padding:4,zIndex:2147483001},children:[ve.map(l=>{let R=l.id===ye,U=Et===l.id,me=re===l.id;return go.jsxs("button",{type:"button",role:"menuitem",onMouseEnter:()=>Ct(l.id),onMouseLeave:()=>Ct(null),onClick:()=>{l.id!==ye&&lo(l.id);},disabled:!!re,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 8px",border:"none",background:U?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:re?"default":"pointer",textAlign:"left",fontWeight:R?600:400,opacity:re&&!me?.55:1},children:[go.jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,color:"#111827",flexShrink:0},children:R&&go.jsx(lucideReact.Check,{style:{width:12,height:12}})}),go.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:me?"Switching...":l.name})]},l.id)}),go.jsx("div",{style:{height:1,background:"#e5e7eb",margin:"4px 0"}}),lt?go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"4px 4px"},children:[go.jsx("input",{ref:ct,type:"text",value:Le,placeholder:"Container name",disabled:re==="__new__",onChange:l=>Ve(l.target.value),onKeyDown:l=>{l.key==="Enter"?(l.preventDefault(),Jr(Le)):l.key==="Escape"&&(l.preventDefault(),l.stopPropagation(),Be(false),Ve(""));},style:{flex:1,minWidth:0,padding:"5px 8px",border:"1px solid #d1d5db",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",background:"#ffffff",outline:"none"},onFocus:l=>{l.currentTarget.style.borderColor="#1c4587",l.currentTarget.style.boxShadow="0 0 0 2px rgba(28,69,135,0.15)";},onBlur:l=>{l.currentTarget.style.borderColor="#d1d5db",l.currentTarget.style.boxShadow="none";}}),go.jsx("button",{type:"button",onClick:()=>{Jr(Le);},disabled:!Le.trim()||re==="__new__",title:"Create",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:!Le.trim()||re==="__new__"?"#e5e7eb":"#1c4587",color:!Le.trim()||re==="__new__"?"#9ca3af":"#ffffff",cursor:!Le.trim()||re==="__new__"?"default":"pointer",flexShrink:0},children:re==="__new__"?go.jsx("span",{style:{width:10,height:10,border:"1.5px solid currentColor",borderTopColor:"transparent",borderRadius:"50%",animation:"__fork-spin 0.7s linear infinite"}}):go.jsx(lucideReact.Check,{style:{width:12,height:12}})})]}):go.jsx("button",{type:"button",role:"menuitem",onMouseEnter:()=>Pe(true),onMouseLeave:()=>Pe(false),onClick:()=>{re||(m(null),Ve(""),Be(true));},disabled:!!re,style:{display:"flex",alignItems:"center",width:"100%",padding:"6px 8px",border:"none",background:$t?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:re?"default":"pointer",textAlign:"left",opacity:re&&re!=="__new__"?.55:1},children:"+ New container"}),b&&go.jsx("div",{style:{padding:"6px 8px",fontSize:11,lineHeight:1.35,color:"#b91c1c"},children:b})]})]}):go.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Xr}),e==="running"&&go.jsx("span",{title:qe?`Estimated ~${qe} min`:"Estimating\u2026",style:{fontSize:10,fontWeight:600,color:qe?"#1c4587":"#9ca3af",backgroundColor:qe?"rgba(28, 69, 135, 0.08)":"rgba(156, 163, 175, 0.12)",padding:"1px 6px",borderRadius:999,flexShrink:0,fontVariantNumeric:"tabular-nums",animation:qe?void 0:"__fork-pulse 1.4s ease-in-out infinite",minWidth:28,textAlign:"center"},children:qe?`~${qe}m`:"~ m"})]}),!I&&go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[Dr&&go.jsx("button",{onClick:xe?so:oo,onMouseEnter:()=>C(true),onMouseLeave:()=>C(false),title:xe?"Redock to sidebar":"Pop out into window",style:{padding:6,borderRadius:6,color:P?"#4b5563":"#9ca3af",backgroundColor:P?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:xe?go.jsx(lucideReact.PictureInPicture,{style:{width:16,height:16}}):go.jsx(lucideReact.PictureInPicture2,{style:{width:16,height:16}})}),go.jsx("button",{onClick:qr,onMouseEnter:()=>F(true),onMouseLeave:()=>F(false),style:{padding:6,borderRadius:6,color:c?"#4b5563":"#9ca3af",backgroundColor:c?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:go.jsx(lucideReact.X,{style:{width:16,height:16}})})]})]}),go.jsxs("div",{ref:fe,style:{flex:1,overflowY:"auto",minHeight:0,display:"flex",flexDirection:"column"},children:[(Z||ce)&&go.jsxs("div",{style:{padding:"10px 12px 6px 12px",display:"flex",alignItems:"center",gap:8,borderBottom:"1px solid #f3f4f6"},children:[go.jsx("button",{onClick:()=>{le(null),oe(false),se.current=false;},style:{fontSize:12,color:"#374151",background:"transparent",border:"none",padding:"2px 4px",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4},title:"Back to all forks",children:"\u2190 All forks"}),(()=>{let R=(Z?ne.find(U=>U.id===Z)?.targetId:null)??nt;return R?go.jsxs("span",{style:{fontSize:11,color:"#9ca3af",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",flex:1},title:`Forking ${R}`,children:["Forking ",go.jsx("span",{style:{color:"#6b7280"},children:R})]}):null})()]}),!Z&&!ce&&go.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[go.jsx("div",{style:{padding:"12px 16px 10px 16px",borderBottom:"1px solid #f3f4f6"},children:go.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#111827"},children:"Forks"})}),ne.length===0&&go.jsx("div",{style:{padding:"24px 20px",textAlign:"center",fontSize:13,color:"#6b7280"},children:"No forks yet. Describe a feature below to start one."}),ne.length>0&&go.jsx("div",{style:{display:"flex",flexDirection:"column"},children:ne.map(l=>{let R=l.summary||"Untitled fork";return go.jsxs("button",{onClick:()=>{oe(false),le(l.id);},style:{textAlign:"left",padding:"10px 16px",background:"#ffffff",border:"none",borderBottom:"1px solid #f3f4f6",cursor:"pointer",display:"flex",flexDirection:"column",gap:2},onMouseEnter:U=>U.currentTarget.style.background="#fafafa",onMouseLeave:U=>U.currentTarget.style.background="#ffffff",children:[go.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[go.jsx("span",{style:{fontSize:13,fontWeight:500,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",flex:1},children:R}),go.jsx("span",{style:{fontSize:11,color:"#9ca3af",flexShrink:0},children:_s(l.updatedAt)})]}),go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:"#6b7280"},children:[go.jsx("span",{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:l.targetId}),go.jsx("span",{style:{color:"#d1d5db"},children:"\xB7"}),go.jsxs("span",{children:[l.promptCount," prompt",l.promptCount===1?"":"s"]}),l.status==="running"||l.status==="building"?go.jsxs(go.Fragment,{children:[go.jsx("span",{style:{color:"#d1d5db"},children:"\xB7"}),go.jsx("span",{style:{color:"#2563eb"},children:"running"})]}):null]})]},l.id)})})]}),Z&&ut.length>0&&go.jsx("div",{style:{padding:"16px 16px 0 16px"},children:ut.map((l,R)=>go.jsx("div",{style:{marginBottom:R<ut.length-1?10:0},children:l.type==="user"?go.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8,flexDirection:"row-reverse"},children:[go.jsx("div",{style:{width:22,height:22,borderRadius:"50%",backgroundColor:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:2},children:go.jsx(lucideReact.User,{style:{width:13,height:13,color:"#6b7280"}})}),go.jsx("div",{style:{backgroundColor:"#f3f4f6",borderRadius:"12px 4px 12px 12px",padding:"8px 12px",fontSize:13,color:"#374151",lineHeight:1.5,maxWidth:"75%"},children:l.text})]}):M==="item"&&R===ut.length-1?go.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:12,borderRadius:8,border:"1px solid #e4e4e7",background:"#ffffff"},children:[go.jsx("div",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,flexShrink:0,borderRadius:6,background:"#f4f4f5",color:"#0a0a0a"},children:go.jsx(lucideReact.BadgeCheck,{style:{width:16,height:16}})}),go.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,flex:1,minWidth:0},children:[go.jsx("div",{style:{fontSize:13,fontWeight:500,color:"#0a0a0a",lineHeight:1.3},children:"Feature applied"}),go.jsx("div",{style:{fontSize:13,color:"#71717a",lineHeight:1.4},children:l.text})]}),k&&e!=="running"&&go.jsx("button",{onClick:U=>{U.stopPropagation(),Vr();},disabled:j,style:{padding:"4px 10px",fontSize:12,fontWeight:500,borderRadius:6,border:"1px solid #e4e4e7",background:"#ffffff",color:"#0a0a0a",cursor:j?"default":"pointer",opacity:j?.4:1,height:28,flexShrink:0},children:"Undo"})]}):go.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[go.jsx("div",{style:{width:22,height:22,borderRadius:"50%",backgroundColor:"#f0fdf4",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:2},children:go.jsx(lucideReact.Check,{style:{width:13,height:13,color:"#9ca3af"}})}),go.jsxs("div",{style:{backgroundColor:"#f9fafb",borderRadius:"4px 12px 12px 12px",padding:"8px 12px",fontSize:13,color:"#6b7280",fontWeight:500,display:"flex",alignItems:"center",gap:6,maxWidth:"75%"},children:[go.jsx("span",{style:{flex:1},children:l.text}),k&&R===ut.length-1&&e!=="running"&&go.jsxs("button",{onClick:U=>{U.stopPropagation(),Vr();},onMouseEnter:()=>K(R),onMouseLeave:()=>K(null),disabled:j,style:{position:"relative",padding:2,borderRadius:4,border:"none",background:de===R?"rgba(0,0,0,0.06)":"transparent",color:de===R?"#6b7280":"#d1d5db",cursor:j?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s, background 0.15s",opacity:j?.4:1,flexShrink:0},children:[go.jsx(lucideReact.Undo2,{style:{width:12,height:12}}),de===R&&go.jsx("span",{style:{position:"absolute",bottom:"calc(100% + 4px)",right:0,fontSize:10,fontWeight:500,color:"#fff",background:"#374151",borderRadius:4,padding:"2px 6px",whiteSpace:"nowrap",pointerEvents:"none",lineHeight:"16px"},children:"Undo"})]})]})]})},R))}),e==="running"&&(Z||ce)&&go.jsx("div",{style:{padding:16},children:go.jsxs("div",{onClick:()=>Q(!V),style:{backgroundColor:"#1a1a2e",borderRadius:12,overflow:"hidden",cursor:"pointer",transition:"all 0.3s cubic-bezier(0.22, 1, 0.36, 1)"},children:[go.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px"},children:[go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[go.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#6b7280",strokeWidth:"2.5",strokeLinecap:"round",style:{animation:"__fork-spin 2s linear infinite",flexShrink:0},children:go.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),go.jsx(Es,{events:r})]}),go.jsx("div",{style:{color:"#6b7280",flexShrink:0,marginLeft:8,transition:"transform 0.2s ease",transform:V?"rotate(180deg)":"rotate(0deg)"},children:go.jsx(lucideReact.ChevronDown,{style:{width:14,height:14}})})]}),go.jsx("div",{style:{maxHeight:V?320:0,opacity:V?1:0,transition:"max-height 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease",overflow:"hidden"},children:go.jsx("div",{style:{borderTop:"1px solid rgba(255,255,255,0.08)",maxHeight:320,overflowY:"auto"},children:go.jsx(Sn,{events:r})})})]})}),e==="error"&&(Z||ce)&&go.jsxs("div",{style:{padding:"20px 16px",textAlign:"center"},children:[go.jsx("div",{style:{width:36,height:36,backgroundColor:"#fef2f2",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 10px auto"},children:go.jsx(lucideReact.X,{style:{width:18,height:18,color:"#ef4444"}})}),go.jsx("p",{style:{fontSize:12,color:"#6b7280",marginBottom:10,maxWidth:260,margin:"0 auto 10px auto"},children:n}),go.jsxs("button",{onClick:()=>{let l=t?.prompt||Tt.current;l&&u(l,nt);},onMouseEnter:()=>z(true),onMouseLeave:()=>z(false),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 12px",borderRadius:8,fontSize:12,fontWeight:500,color:"#4f46e5",backgroundColor:_?"#e0e7ff":"#eef2ff",border:"none",cursor:"pointer",transition:"background-color 0.15s",fontFamily:"inherit"},children:[go.jsx(lucideReact.RotateCcw,{style:{width:12,height:12}})," Try Again"]})]})]}),e!=="running"&&go.jsx("div",{style:{padding:"8px 12px 12px 12px",borderTop:"1px solid rgba(229, 231, 235, 0.6)",flexShrink:0},children:go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,borderRadius:12,padding:"8px 8px 8px 12px",background:"rgba(0, 0, 0, 0.04)",border:"1px solid rgba(0, 0, 0, 0.06)"},children:[go.jsx("textarea",{ref:Se,value:h,onChange:l=>{v(l.target.value),l.target.style.height="auto",l.target.style.height=Math.min(l.target.scrollHeight,160)+"px";},onKeyDown:l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),zr()),l.key==="Escape"&&!I&&qr();},placeholder:Z?"Iterate on this feature...":"Start building a new Fork...",rows:1,style:{flex:1,backgroundColor:"transparent",fontSize:13,color:"#111827",border:"none",outline:"none",padding:"0 4px 0 0",fontFamily:"inherit",resize:"none",lineHeight:1.5,maxHeight:160,overflow:"auto"}}),go.jsx("button",{onClick:zr,disabled:!h.trim(),onMouseEnter:()=>y(true),onMouseLeave:()=>y(false),style:{width:26,height:26,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",color:"#ffffff",opacity:h.trim()?1:.25,transform:x&&h.trim()?"scale(1.1)":"scale(1)",background:h.trim()?"#1c4587":"rgba(0,0,0,0.12)",border:"none",cursor:h.trim()?"pointer":"default",flexShrink:0,transition:"transform 0.15s, opacity 0.15s",padding:0},children:go.jsx(lucideReact.ArrowUp,{style:{width:13,height:13}})})]})})]})]});return I?nr:xe&&J?po.createPortal(nr,J.document.body):go.jsx(Cs,{children:nr})}function En(e){if("target"in e&&e.target)return e.target;if("boundaryId"in e&&e.boundaryId)return {type:"boundary",id:e.boundaryId,title:e.title};if("slotId"in e&&e.slotId)return {type:"slot",id:e.slotId,title:e.title??e.slotLabel};throw new Error("Fork chat target requires either target, slotId, or boundaryId.")}function xr(e){let{apiKey:t,userId:r,userHash:n,baseUrl:o,appId:s,previewSession:i,refreshModuleManifest:a,queueBoundaryAnimation:u,trackForkActivity:k,recordForkActivityEvent:g}=he(),[d,w]=mr.useState("idle"),[A,f]=mr.useState(null),[p,I]=mr.useState([]),[M,h]=mr.useState(null),v=mr.useRef(null),T=mr.useCallback(()=>{w("prompting"),I([]),h(null),f(null);},[]),N=mr.useCallback(()=>{w("idle"),v.current&&(v.current.close(),v.current=null);},[]);mr.useEffect(()=>{i&&i.target.kind==="module"&&i.target.id===e&&w(L=>L==="idle"?"prompting":L);},[i?.preview_session_id,i?.target.id,e]);let D=mr.useCallback(async(L,B,S)=>{try{if(!s)throw new Error("ForkProvider requires appId for module boundary prompts.");w("running"),I([]),h(null),f(null);let c;if(i){let C=S?.forkId??i.fork_id??void 0,x=await fetch(`${o}/api/v1/preview/${encodeURIComponent(i.preview_session_id)}/author`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...te()},body:JSON.stringify({prompt:L,...e?{boundary_id:e}:{},...C&&!S?.forceNew?{fork_id:C}:{},...S?.forceNew?{force_new:!0}:{}})});if(!x.ok){let z=await x.json().catch(()=>({}));throw new Error(z.error||`API error: ${x.status}`)}let y=await x.json();y.container_id&&Ge(y.container_id,y.container_name),dt(y.fork_id),c=await(await fetch(`${o}/api/v1/forks/${y.fork_id}`,{headers:{Authorization:`Bearer ${t}`,...te()}})).json();}else if(S?.forkId){let C={prompt:L};r&&(C.userId=r),n&&(C.userHash=n);let x=await fetch(`${o}/api/v1/forks/${encodeURIComponent(S.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(C)});if(!x.ok){let y=await x.json().catch(()=>({}));throw new Error(y.error||`API error: ${x.status}`)}c=await x.json();}else {let C={userId:r,prompt:L,boundaryId:e,appId:s};B&&(C.containerId=B),n&&(C.userHash=n),S?.forceNew&&(C.force_new=!0);let x=await fetch(`${o}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(C)});if(!x.ok){let y=await x.json().catch(()=>({}));throw new Error(y.error||`API error: ${x.status}`)}c=await x.json();}f(c),k(c,{targetKind:"module",targetId:e});let F=new URLSearchParams({key:t});i?(F.set("previewSessionId",i.preview_session_id),F.set("previewForkId",c.id)):r&&F.set("userId",r),n&&F.set("userHash",n);let P=new EventSource(`${o}/api/v1/forks/${c.id}/events?${F.toString()}`);v.current=P,P.onmessage=C=>{try{let x=JSON.parse(C.data);if(g(c.id,x),I(y=>[...y,x]),x.type==="complete"){let y=x.data;u(e,c.id),a().catch(()=>{}).finally(()=>{let _={...c,status:"complete",moduleUrl:y.moduleUrl,cssUrls:y.cssUrls,summary:y.summary,completedAt:new Date().toISOString()};f(_),w("complete"),P.close();});}else if(x.type==="error"){let y=x.data;h(y.error||"Unknown error"),w("error"),P.close();}}catch{}},P.onerror=()=>{let C={Authorization:`Bearer ${t}`,...te()};!i&&r&&(C["X-Fork-User-Id"]=r),!i&&n&&(C["X-Fork-User-Hash"]=n),fetch(`${o}/api/v1/forks/${c.id}`,{headers:C}).then(x=>x.json()).then(x=>{f(x),x.status==="complete"?(u(e,x.id),a().catch(()=>{}),w("complete")):x.status==="error"&&(h(x.error||"Fork generation failed"),w("error"));}).catch(()=>{h("Connection lost"),w("error");}),P.close();};}catch(c){h(c.message),w("error");}},[t,s,o,e,i,u,a,g,k,n,r]),O=mr.useCallback(async L=>{try{let B={Authorization:`Bearer ${t}`,...te()};!i&&r&&(B["X-Fork-User-Id"]=r),!i&&n&&(B["X-Fork-User-Hash"]=n);let S=await fetch(`${o}/api/v1/forks/${L}`,{headers:B});if(!S.ok)return;let c=await S.json(),F=c.boundaryId??e;if(k(c,{targetKind:"module",targetId:F}),c.status==="complete"){w("complete"),f(c),h(null),I([]);return}if(c.status==="error"){w("error"),f(c),h(c.error||"Fork generation failed"),I([]);return}if(c.status!=="pending"&&c.status!=="running"&&c.status!=="building")return;w("running"),f(c),h(null),I([]);let P=new URLSearchParams({key:t});i?(P.set("previewSessionId",i.preview_session_id),P.set("previewForkId",c.id)):r&&P.set("userId",r),n&&P.set("userHash",n);let C=new EventSource(`${o}/api/v1/forks/${c.id}/events?${P.toString()}`);v.current&&v.current.close(),v.current=C,C.onmessage=x=>{try{let y=JSON.parse(x.data);if(g(c.id,y),I(_=>[..._,y]),y.type==="complete"){let _=y.data;u(e,c.id),a().catch(()=>{}).finally(()=>{let z={...c,status:"complete",moduleUrl:_.moduleUrl,cssUrls:_.cssUrls,summary:_.summary,completedAt:new Date().toISOString()};f(z),w("complete"),C.close();});}else if(y.type==="error"){let _=y.data;h(_.error||"Unknown error"),w("error"),C.close();}}catch{}},C.onerror=()=>{C.close();};}catch{}},[t,o,e,i,u,g,a,k,n,r]),E=mr.useCallback(async()=>{try{if(!s)throw new Error("ForkProvider requires appId for boundary undo.");let L={userId:r,boundaryId:e,appId:s};n&&(L.userHash=n);let B=await fetch(`${o}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(L)});if(!B.ok){let c=await B.json().catch(()=>({}));throw new Error(c.error||`API error: ${B.status}`)}let S=await B.json();return await a().catch(()=>{}),S.removed?(f(null),w("prompting")):S.fork&&(f(S.fork),w("complete")),S}catch(L){throw h(L.message),L}},[t,s,o,e,a,n,r]);return {state:d,fork:A,events:p,error:M,open:T,close:N,startFork:D,undoFork:E,adoptRunningFork:O}}var Ms=0;function Pn(e){let{state:t,fork:r,events:n,error:o,open:s,close:i,startFork:a,undoFork:u,adoptRunningFork:k}=xr(e),[g,d]=mr.useState(false),w=mr.useRef(null),A=mr.useRef(t),f=mr.useCallback(()=>{w.current!==null&&(clearTimeout(w.current),w.current=null);},[]),p=mr.useCallback(()=>{f(),d(true),s();},[f,s]),I=mr.useCallback(()=>{f(),d(false),i();},[f,i]),M=mr.useCallback(async h=>{f(),d(true),await k(h);},[k,f]);return mr.useEffect(()=>{let h=A.current;A.current=t,t==="complete"&&h!=="complete"&&g&&(f(),w.current=setTimeout(()=>{w.current=null,d(false),i();},Ms)),(t==="running"||t==="prompting")&&f();},[t,g,f,i]),mr.useEffect(()=>f,[f]),{state:t,fork:r,events:n,error:o,isOpen:g,open:p,close:I,submit:a,undo:u,adoptRunningFork:M}}function Ar(){let{apiKey:e,userId:t,userHash:r,baseUrl:n,previewSession:o,setSlotFork:s,clearSlotFork:i,skipAnimationForSlot:a,trackForkActivity:u,recordForkActivityEvent:k}=he(),[g,d]=mr.useState("idle"),[w,A]=mr.useState(null),[f,p]=mr.useState([]),[I,M]=mr.useState(null),h=mr.useRef(null),v=mr.useCallback(()=>{d("prompting"),p([]),M(null),A(null);},[]),T=mr.useCallback(()=>{d("idle"),h.current&&(h.current.close(),h.current=null);},[]);mr.useEffect(()=>{o&&o.target.kind==="slot"&&d(E=>E==="idle"?"prompting":E);},[o?.preview_session_id,o?.target.kind]);let N=mr.useCallback(async(E,L,B,S)=>{try{d("running"),p([]),M(null),A(null);let c;if(o){let x=S?.forkId??o.fork_id??void 0,y=await fetch(`${n}/api/v1/preview/${encodeURIComponent(o.preview_session_id)}/author`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...te()},body:JSON.stringify({prompt:E,...L?{slot_id:L}:{},...x&&!S?.forceNew?{fork_id:x}:{},...S?.forceNew?{force_new:!0}:{}})});if(!y.ok){let V=await y.json().catch(()=>({}));throw new Error(V.error||`API error: ${y.status}`)}let _=await y.json();_.container_id&&Ge(_.container_id,_.container_name),dt(_.fork_id),c=await(await fetch(`${n}/api/v1/forks/${_.fork_id}`,{headers:{Authorization:`Bearer ${e}`,...te()}})).json();}else if(S?.forkId){let x={prompt:E};t&&(x.userId=t),r&&(x.userHash=r);let y=await fetch(`${n}/api/v1/forks/${encodeURIComponent(S.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(x)});if(!y.ok){let _=await y.json().catch(()=>({}));throw new Error(_.error||`API error: ${y.status}`)}c=await y.json();}else {let x={userId:t,prompt:E};L&&(x.slotId=L),B&&(x.containerId=B),r&&(x.userHash=r),S?.forceNew&&(x.force_new=!0);let y=await fetch(`${n}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(x)});if(!y.ok){let _=await y.json().catch(()=>({}));throw new Error(_.error||`API error: ${y.status}`)}c=await y.json();}A(c);let F=L??c.slotId;F&&u(c,{targetKind:"slot",targetId:F});let P=new URLSearchParams({key:e});o?(P.set("previewSessionId",o.preview_session_id),P.set("previewForkId",c.id)):t&&P.set("userId",t),r&&P.set("userHash",r);let C=new EventSource(`${n}/api/v1/forks/${c.id}/events?${P.toString()}`);h.current=C,C.onmessage=x=>{try{let y=JSON.parse(x.data);if(k(c.id,y),p(_=>[..._,y]),y.type==="complete"){let _=y.data,z={...c,status:"complete",bundleUrl:_.bundleUrl,summary:_.summary,completedAt:new Date().toISOString()};A(z),d("complete"),L&&_.bundleUrl&&s(L,z),C.close();}else if(y.type==="error"){let _=y.data;M(_.error||"Unknown error"),d("error"),C.close();}}catch{}},C.onerror=()=>{let x={Authorization:`Bearer ${e}`,...te()};!o&&t&&(x["X-Fork-User-Id"]=t),!o&&r&&(x["X-Fork-User-Hash"]=r),fetch(`${n}/api/v1/forks/${c.id}`,{headers:x}).then(y=>y.json()).then(y=>{A(y),y.status==="complete"?(d("complete"),L&&y.bundleUrl&&s(L,y)):y.status==="error"&&(M(y.error||"Fork generation failed"),d("error"));}).catch(()=>{M("Connection lost"),d("error");}),C.close();};}catch(c){M(c.message),d("error");}},[e,n,o,k,s,u,r,t]),D=mr.useCallback(async E=>{try{let L={Authorization:`Bearer ${e}`,...te()};!o&&t&&(L["X-Fork-User-Id"]=t),!o&&r&&(L["X-Fork-User-Hash"]=r);let B=await fetch(`${n}/api/v1/forks/${E}`,{headers:L});if(!B.ok)return;let S=await B.json();if(S.slotId&&u(S,{targetKind:"slot",targetId:S.slotId}),S.status==="complete"){d("complete"),A(S),M(null),p([]);return}if(S.status==="error"){d("error"),A(S),M(S.error||"Fork generation failed"),p([]);return}if(S.status!=="pending"&&S.status!=="running"&&S.status!=="building")return;d("running"),A(S),M(null),p([]);let c=new URLSearchParams({key:e});o?(c.set("previewSessionId",o.preview_session_id),c.set("previewForkId",S.id)):t&&c.set("userId",t),r&&c.set("userHash",r);let F=new EventSource(`${n}/api/v1/forks/${S.id}/events?${c.toString()}`);h.current&&h.current.close(),h.current=F;let P=S.slotId;F.onmessage=C=>{try{let x=JSON.parse(C.data);if(k(S.id,x),p(y=>[...y,x]),x.type==="complete"){let y=x.data,_={...S,status:"complete",bundleUrl:y.bundleUrl,summary:y.summary,completedAt:new Date().toISOString()};A(_),d("complete"),P&&y.bundleUrl&&s(P,_),F.close();}else if(x.type==="error"){let y=x.data;M(y.error||"Unknown error"),d("error"),F.close();}}catch{}},F.onerror=()=>{F.close();};}catch{}},[e,n,o,k,s,u,r,t]),O=mr.useCallback(async E=>{try{let L={userId:t,slotId:E};r&&(L.userHash=r);let B=await fetch(`${n}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(L)});if(!B.ok){let c=await B.json().catch(()=>({}));throw new Error(c.error||`API error: ${B.status}`)}let S=await B.json();return a(E),S.removed?(i(E),A(null),d("prompting")):S.fork&&(s(E,S.fork),A(S.fork)),S}catch(L){throw M(L.message),L}},[e,t,r,n,i,s]);return {state:g,fork:w,events:f,error:I,open:v,close:T,startFork:N,undoFork:O,adoptRunningFork:D}}var Us=0;function Ln(){let{state:e,fork:t,events:r,error:n,open:o,close:s,startFork:i,undoFork:a,adoptRunningFork:u}=Ar(),[k,g]=mr.useState(false),d=mr.useRef(null),w=mr.useRef(e),A=mr.useCallback(()=>{d.current!==null&&(clearTimeout(d.current),d.current=null);},[]),f=mr.useCallback(()=>{A(),g(true),o();},[A,o]),p=mr.useCallback(()=>{A(),g(false),s();},[A,s]),I=mr.useCallback(async M=>{A(),g(true),await u(M);},[u,A]);return mr.useEffect(()=>{let M=w.current;w.current=e,e==="complete"&&M!=="complete"&&k&&(A(),d.current=setTimeout(()=>{d.current=null,g(false),s();},Us)),(e==="running"||e==="prompting")&&A();},[e,k,A,s]),mr.useEffect(()=>A,[A]),{state:e,fork:t,events:r,error:n,isOpen:k,open:f,close:p,submit:i,undo:a,adoptRunningFork:I}}var Ns=new Set(["pending","running","building"]);function _r(e){let t=En(e),r=Ln(),n=Pn(t.type==="boundary"?t.id:""),{baseUrl:o,apiKey:s,userId:i,userHash:a,appId:u,activitySummary:k,forkActivities:g,markForkActivitySeen:d}=he(),w=t.type==="slot"?r:n,A=t.type==="slot"?"slot":"boundary",f=t.id,p=t.title,I=t.type==="slot"?"slot":"module",M=g.find(D=>D.targetKind===I&&D.targetId===t.id&&Ns.has(D.status)),h=g.find(D=>D.targetKind===I&&D.targetId===t.id&&D.status==="complete"&&D.unread),v=mr.useCallback(()=>{d();let D=M??h;if(D){w.adoptRunningFork(D.id);return}w.open();},[w,d,M,h]),T=mr.useCallback((D,O,E,L)=>t.type==="slot"?r.submit(D,O??t.id,E,L):n.submit(D,E,L),[n,r,t]),N=mr.useCallback(D=>t.type==="slot"?r.undo(D??t.id):n.undo(),[n,r,t]);return {...w,open:v,target:t,targetId:f,targetLabel:p,historyMode:A,submit:T,undo:N,buttonProps:{onClick:v,hasNotification:k.unreadCompletedCount>0,activity:k},panelProps:{state:w.state,fork:w.fork,events:w.events,error:w.error,...t.type==="slot"?{slotId:f,targetLabel:p,historyMode:A}:{targetId:f,targetLabel:p,historyMode:A},onSubmit:T,onUndo:N,onClose:w.close,baseUrl:o,apiKey:s,userId:i,userHash:a,appId:u}}}function Ft(e){let{embedded:t,completeVariant:r}=e,n=_r(e);return t?go.jsx(qt,{...n.panelProps,embedded:true,completeVariant:r}):n.isOpen?go.jsx(qt,{...n.panelProps,completeVariant:r}):go.jsx(wr,{...n.buttonProps})}function Bs({boundaryId:e,title:t}){return go.jsx(Ft,{boundaryId:e,title:t})}function Er(e){let t=Array.from(e.children).filter(n=>n instanceof HTMLElement);return t.length===1?t[0]:getComputedStyle(e).display==="contents"?null:e}function Hn(e){let t=e.getBoundingClientRect(),r=e.cloneNode(true);r.setAttribute("data-fork-clone-overlay","true"),r.style.position="fixed",r.style.top=`${t.top}px`,r.style.left=`${t.left}px`,r.style.width=`${t.width}px`,r.style.height=`${t.height}px`,r.style.flex="none",r.style.minHeight="auto",r.style.zIndex="9998",r.style.pointerEvents="none",r.style.overflow="hidden";let n=getComputedStyle(e).backgroundColor;r.style.backgroundColor=n&&n!=="rgba(0, 0, 0, 0)"&&n!=="transparent"?n:getComputedStyle(document.body).backgroundColor||"#ffffff",document.body.appendChild(r);let o=e.querySelectorAll("*"),s=r.querySelectorAll("*");for(let i=0;i<o.length;i+=1)o[i].scrollTop!==0&&(s[i].scrollTop=o[i].scrollTop),o[i].scrollLeft!==0&&(s[i].scrollLeft=o[i].scrollLeft);return r}function Cr(e){let t=[],r=e.querySelectorAll("*");for(let n of r){if(!(n instanceof HTMLElement))continue;let o=n.getBoundingClientRect();if(o.width<10||o.height<10||["SCRIPT","STYLE","META","LINK"].includes(n.tagName))continue;let s=getComputedStyle(n),i=parseFloat(s.borderTopLeftRadius)||0;t.push({tag:n.tagName,className:n.className||"",text:(n.textContent||"").slice(0,50).trim(),rect:o,borderRadius:i});}return t}function On(e,t){let r=[];for(let n of t)if(!(e.find(i=>i.tag===n.tag&&i.className===n.className&&Math.abs(i.rect.top-n.rect.top)<20&&Math.abs(i.rect.left-n.rect.left)<20)||r.some(i=>n.rect.top>=i.rect.top&&n.rect.left>=i.rect.left&&n.rect.right<=i.rect.right&&n.rect.bottom<=i.rect.bottom))){for(let i=r.length-1;i>=0;i-=1){let a=r[i];a.rect.top>=n.rect.top&&a.rect.left>=n.rect.left&&a.rect.right<=n.rect.right&&a.rect.bottom<=n.rect.bottom&&r.splice(i,1);}r.push({rect:n.rect,borderRadius:n.borderRadius});}return r}function Un(e,t){let r=[];for(let n of e)if(!(t.find(i=>i.tag===n.tag&&i.className===n.className&&Math.abs(i.rect.top-n.rect.top)<20&&Math.abs(i.rect.left-n.rect.left)<20)||r.some(i=>n.rect.top>=i.rect.top&&n.rect.left>=i.rect.left&&n.rect.right<=i.rect.right&&n.rect.bottom<=i.rect.bottom))){for(let i=r.length-1;i>=0;i-=1){let a=r[i];a.rect.top>=n.rect.top&&a.rect.left>=n.rect.left&&a.rect.right<=n.rect.right&&a.rect.bottom<=n.rect.bottom&&r.splice(i,1);}r.push({rect:n.rect,borderRadius:n.borderRadius});}return r}function Nn(e,t,r,n,o){let s=Math.max(0,Math.min(o,r/2,n/2));return s===0?`M ${e} ${t} L ${e+r} ${t} L ${e+r} ${t+n} L ${e} ${t+n} Z`:[`M ${e+s} ${t}`,`L ${e+r-s} ${t}`,`A ${s} ${s} 0 0 1 ${e+r} ${t+s}`,`L ${e+r} ${t+n-s}`,`A ${s} ${s} 0 0 1 ${e+r-s} ${t+n}`,`L ${e+s} ${t+n}`,`A ${s} ${s} 0 0 1 ${e} ${t+n-s}`,`L ${e} ${t+s}`,`A ${s} ${s} 0 0 1 ${e+s} ${t}`,"Z"].join(" ")}function $r(e){let t="http://www.w3.org/2000/svg",r=document.createElement("div");r.setAttribute("data-fork-highlights","true"),r.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let n=document.createElementNS(t,"svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs");n.appendChild(o);let s=[];for(let g=0;g<e.length;g+=1){let{rect:d,borderRadius:w}=e[g],A=d.left-.5,f=d.top-.5,p=d.width+1,I=d.height+1,M=Math.min(w+.5,p/2,I/2),h=Nn(A,f,p,I,M),v=`__fork-glow-${g}`,T=document.createElementNS(t,"filter");T.setAttribute("id",v),T.setAttribute("x","-100%"),T.setAttribute("y","-100%"),T.setAttribute("width","300%"),T.setAttribute("height","300%");let N=document.createElementNS(t,"feGaussianBlur");N.setAttribute("in","SourceGraphic"),N.setAttribute("stdDeviation","8"),T.appendChild(N),o.appendChild(T);let D=`__fork-mask-${g}`,O=document.createElementNS(t,"mask");O.setAttribute("id",D),O.setAttribute("maskUnits","userSpaceOnUse"),O.setAttribute("x",String(A-200)),O.setAttribute("y",String(f-200)),O.setAttribute("width",String(p+400)),O.setAttribute("height",String(I+400));let E=document.createElementNS(t,"rect");E.setAttribute("x",String(A-200)),E.setAttribute("y",String(f-200)),E.setAttribute("width",String(p+400)),E.setAttribute("height",String(I+400)),E.setAttribute("fill","white"),O.appendChild(E);let L=document.createElementNS(t,"path");L.setAttribute("d",h),L.setAttribute("fill","black"),O.appendChild(L),o.appendChild(O);let B=document.createElementNS(t,"g");B.setAttribute("mask",`url(#${D})`),B.setAttribute("opacity","0");let S=document.createElementNS(t,"g");S.setAttribute("filter",`url(#${v})`);let c=document.createElementNS(t,"path");c.setAttribute("d",h),c.setAttribute("fill","none"),c.setAttribute("stroke","rgba(150, 185, 220, 0.6)"),c.setAttribute("stroke-width","6"),c.setAttribute("stroke-linecap","round"),S.appendChild(c),B.appendChild(S),n.appendChild(B);let F=document.createElementNS(t,"path");F.setAttribute("d",h),F.setAttribute("fill","none"),F.setAttribute("stroke","rgba(150, 185, 220, 0.35)"),F.setAttribute("stroke-width","2"),F.setAttribute("stroke-linecap","round"),F.setAttribute("opacity","0"),n.appendChild(F),s.push(c,F),c.__group=B;}r.appendChild(n),document.body.appendChild(r);let i=[];for(let g=0;g<s.length;g+=2){let d=s[g],w=s[g+1],A=d.__group;if(!A)continue;let f=w.getTotalLength(),p=d.getTotalLength();if(f<=0)continue;let I=f*.35;w.setAttribute("stroke-dasharray",`${I} ${f-I}`),w.setAttribute("stroke-dashoffset","0"),i.push(w.animate([{strokeDashoffset:0,opacity:0,offset:0},{strokeDashoffset:-0.2*f,opacity:.92,offset:.06},{strokeDashoffset:-2*f,opacity:.92,offset:.92},{strokeDashoffset:-2.25*f,opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));let M=p*.35;d.setAttribute("stroke-dasharray",`${M} ${p-M}`),d.setAttribute("stroke-dashoffset","0"),i.push(d.animate([{strokeDashoffset:0,offset:0},{strokeDashoffset:-0.2*p,offset:.06},{strokeDashoffset:-2*p,offset:.92},{strokeDashoffset:-2.25*p,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"})),i.push(A.animate([{opacity:0,offset:0},{opacity:.92,offset:.06},{opacity:.92,offset:.92},{opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));}let a=false,u=()=>{if(a)return;a=true,clearTimeout(k);for(let d of i)try{d.cancel();}catch{}let g=r.animate([{opacity:1},{opacity:0}],{duration:400,fill:"forwards"});g.onfinish=()=>r.remove(),window.removeEventListener("click",u);},k=setTimeout(u,14500);return setTimeout(()=>{a||window.addEventListener("click",u);},500),u}function Bn(e){let t="http://www.w3.org/2000/svg",r=document.createElement("div");r.setAttribute("data-fork-removed","true"),r.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let n=document.createElementNS(t,"svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs"),s=document.createElementNS(t,"filter");s.setAttribute("id","__fork-removed-shadow"),s.setAttribute("x","-10%"),s.setAttribute("y","-10%"),s.setAttribute("width","120%"),s.setAttribute("height","120%");let i=document.createElementNS(t,"feDropShadow");i.setAttribute("dx","0"),i.setAttribute("dy","1"),i.setAttribute("stdDeviation","2"),i.setAttribute("flood-color","rgba(0,0,0,0.15)"),s.appendChild(i),o.appendChild(s),n.appendChild(o);for(let{rect:a,borderRadius:u}of e){let k=document.createElementNS(t,"path");k.setAttribute("d",Nn(a.left,a.top,a.width,a.height,u)),k.setAttribute("fill","none"),k.setAttribute("stroke","rgba(120, 125, 135, 0.6)"),k.setAttribute("stroke-width","1.5"),k.setAttribute("stroke-dasharray","8 4"),k.setAttribute("stroke-linecap","round"),k.setAttribute("filter","url(#__fork-removed-shadow)"),k.setAttribute("opacity","0"),n.appendChild(k),k.animate([{opacity:0,offset:0},{opacity:.6,offset:.08},{opacity:.05,offset:.45},{opacity:.6,offset:.85},{opacity:.05,offset:1}],{duration:5e3,easing:"ease-in-out",fill:"forwards"});}return r.appendChild(n),document.body.appendChild(r),r}function Kn(e,t){if(js(t.selector))return jn(e,t);let n=jn(e,t);if(n)return n;try{let s=document.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e&&e.contains(s))return s}catch{}if(Dn(t.selector))try{let s=e.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e)return s}catch{}if(t.textHint){let s=t.textHint.trim();if(s){let i=Tr(e,g=>g===s);if(i)return i;let a=s.toLowerCase(),u=Tr(e,g=>g.toLowerCase()===a);if(u)return u;let k=Tr(e,g=>g.toLowerCase().includes(a));if(k)return k}}let o=Ks(t.selector);if(o&&o!==t.selector&&Dn(o))try{let s=e.querySelector(o);if(s instanceof HTMLElement&&s!==e)return s}catch{}return null}function Dn(e){let t=e.split(/\s+|>|~|\+/),r=t[t.length-1]??"";return /[#\[]|:not\(|:nth-/.test(r)}function jn(e,t){let r=Array.from(e.querySelectorAll("[data-fork-new]"));if(r.length===0)return null;let n=Pr(t.label),o=Pr(t.textHint);return r.find(i=>{let a=Pr(i.getAttribute("data-fork-new"));return !!a&&(a===n||a===o)})??null}function js(e){return e.trim()==="[data-fork-new]"}function Pr(e){return e?.trim().replace(/\s+/g," ").toLowerCase()||null}function Ks(e){return e.replace(/\[class[\*~|^$]?=("[^"]*"|'[^']*'|[^\]]+)\]/g,"").replace(/\.[A-Za-z_][\w-]*/g,"").replace(/\s+/g," ").trim()}function Tr(e,t){let r=null,n=1/0,o=e.querySelectorAll("*");for(let s of o){let i=s.textContent?.trim();if(!i||!t(i))continue;let a=s.getBoundingClientRect();if(a.width<4||a.height<4)continue;let u=a.width*a.height;u<n&&(r=s,n=u);}return r}var Mr=2147483600,zs=1600,Ws=3e4,Js=300,Ke=10;function Vs(e){let r=getComputedStyle(e).borderTopLeftRadius;if(!r)return 4;if(r.endsWith("%")){let i=parseFloat(r);if(!Number.isFinite(i)||i<=0)return 4;let a=e.getBoundingClientRect(),u=Math.min(a.width,a.height);return Math.max(4,i/100*u)}let n=parseFloat(r);if(!Number.isFinite(n)||n<=0)return 4;let o=e.getBoundingClientRect(),s=Math.min(o.width,o.height)/2;return n>=s?s:Math.min(n,16)}function qs(e,t,r,n){let s=window.innerWidth,i=window.innerHeight,a=e;a==="top"&&t.top<n+Ke+8?a="bottom":a==="bottom"&&i-t.bottom<n+Ke+8?a="top":a==="left"&&t.left<r+Ke+8?a="right":a==="right"&&s-t.right<r+Ke+8&&(a="left");let u=0,k=0;return a==="top"?(u=t.top-n-Ke,k=t.left+t.width/2-r/2):a==="bottom"?(u=t.bottom+Ke,k=t.left+t.width/2-r/2):a==="left"?(u=t.top+t.height/2-n/2,k=t.left-r-Ke):(u=t.top+t.height/2-n/2,k=t.right+Ke),k=Math.max(8,Math.min(k,s-r-8)),u=Math.max(8,Math.min(u,i-n-8)),{top:u,left:k,placement:a}}function Xs(e){let t=document.createElement("div");t.setAttribute("data-fork-highlight-outline","true"),t.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr}`,"border:1.5px solid rgba(59,130,246,0.85)","box-sizing:border-box","opacity:0","transition:opacity 200ms ease-out"].join(";");let r=document.createElement("div");r.setAttribute("data-fork-highlight-glow","true"),r.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr-1}`,"box-sizing:border-box","border:1px solid rgba(59,130,246,0.36)","box-shadow:0 0 0 4px rgba(59,130,246,0.16), 0 0 18px 2px rgba(59,130,246,0.31)","opacity:0","transition:opacity 200ms ease-out"].join(";");let n=document.createElement("div");return n.setAttribute("data-fork-highlight-tooltip","true"),n.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr+1}`,"padding:6px 10px","font:500 12px/1.2 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif","color:#ffffff","background:linear-gradient(135deg,#64748b,#475569)","border-radius:999px","box-shadow:0 4px 14px rgba(71,85,105,0.31),0 1px 2px rgba(0,0,0,0.1)","white-space:nowrap","opacity:0","transform:translateY(-2px)","transition:opacity 200ms ease-out, transform 200ms ease-out"].join(";"),n.textContent=`New: ${e}`,{outline:t,glow:r,tooltip:n}}function Gs(){if(document.getElementById("__fork-highlight-keyframes"))return;let e=document.createElement("style");e.id="__fork-highlight-keyframes",e.textContent=`
|
|
59
|
+
`}),go.jsxs("div",{className:"__fork-panel",style:co,children:[go.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid rgba(229, 231, 235, 0.8)",flexShrink:0},children:[go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flex:1},children:[go.jsx("span",{onDoubleClick:async l=>{if(l.stopPropagation(),!G&&confirm("Kill all forks in this container?")){we(true);try{let R=await Fe();`${R?.deleted??0}`,ue([]),le(null),oe(!1),v("");}catch(R){console.error("[Fork] Reset failed:",R);}finally{we(false);}}},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:4,margin:-4,cursor:"pointer",flexShrink:0},children:go.jsx(zt,{style:{width:16,height:16,color:"#1c4587",pointerEvents:"none"}})}),e==="running"?go.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:ao}):ve.length===0&&!rt?go.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:"Fork"}):rt?go.jsxs("div",{ref:Lt,style:{position:"relative",minWidth:0,display:"inline-flex"},children:[go.jsxs("button",{type:"button",onClick:()=>{Je(l=>!l);},onMouseEnter:()=>at(true),onMouseLeave:()=>at(false),"aria-haspopup":"menu","aria-expanded":$e,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 6px",border:"1px solid transparent",borderRadius:6,background:tr||$e?"#f3f4f6":"transparent",fontSize:13,fontWeight:600,color:"#111827",fontFamily:"inherit",cursor:"pointer",maxWidth:180,minWidth:0,transition:"background-color 0.12s"},children:[go.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Xr}),go.jsx(lucideReact.ChevronDown,{style:{width:12,height:12,color:"#6b7280",flexShrink:0,transform:$e?"rotate(180deg)":void 0,transition:"transform 0.15s"}})]}),$e&&go.jsxs("div",{role:"menu",style:{position:"absolute",top:"calc(100% + 4px)",left:0,minWidth:200,maxWidth:260,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06)",padding:4,zIndex:2147483001},children:[ve.map(l=>{let R=l.id===ye,U=Et===l.id,me=re===l.id;return go.jsxs("button",{type:"button",role:"menuitem",onMouseEnter:()=>Ct(l.id),onMouseLeave:()=>Ct(null),onClick:()=>{l.id!==ye&&lo(l.id);},disabled:!!re,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 8px",border:"none",background:U?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:re?"default":"pointer",textAlign:"left",fontWeight:R?600:400,opacity:re&&!me?.55:1},children:[go.jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,color:"#111827",flexShrink:0},children:R&&go.jsx(lucideReact.Check,{style:{width:12,height:12}})}),go.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:me?"Switching...":l.name})]},l.id)}),go.jsx("div",{style:{height:1,background:"#e5e7eb",margin:"4px 0"}}),lt?go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"4px 4px"},children:[go.jsx("input",{ref:ct,type:"text",value:Le,placeholder:"Container name",disabled:re==="__new__",onChange:l=>Ve(l.target.value),onKeyDown:l=>{l.key==="Enter"?(l.preventDefault(),Jr(Le)):l.key==="Escape"&&(l.preventDefault(),l.stopPropagation(),Be(false),Ve(""));},style:{flex:1,minWidth:0,padding:"5px 8px",border:"1px solid #d1d5db",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",background:"#ffffff",outline:"none"},onFocus:l=>{l.currentTarget.style.borderColor="#1c4587",l.currentTarget.style.boxShadow="0 0 0 2px rgba(28,69,135,0.15)";},onBlur:l=>{l.currentTarget.style.borderColor="#d1d5db",l.currentTarget.style.boxShadow="none";}}),go.jsx("button",{type:"button",onClick:()=>{Jr(Le);},disabled:!Le.trim()||re==="__new__",title:"Create",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:!Le.trim()||re==="__new__"?"#e5e7eb":"#1c4587",color:!Le.trim()||re==="__new__"?"#9ca3af":"#ffffff",cursor:!Le.trim()||re==="__new__"?"default":"pointer",flexShrink:0},children:re==="__new__"?go.jsx("span",{style:{width:10,height:10,border:"1.5px solid currentColor",borderTopColor:"transparent",borderRadius:"50%",animation:"__fork-spin 0.7s linear infinite"}}):go.jsx(lucideReact.Check,{style:{width:12,height:12}})})]}):go.jsx("button",{type:"button",role:"menuitem",onMouseEnter:()=>Pe(true),onMouseLeave:()=>Pe(false),onClick:()=>{re||(m(null),Ve(""),Be(true));},disabled:!!re,style:{display:"flex",alignItems:"center",width:"100%",padding:"6px 8px",border:"none",background:$t?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:re?"default":"pointer",textAlign:"left",opacity:re&&re!=="__new__"?.55:1},children:"+ New container"}),b&&go.jsx("div",{style:{padding:"6px 8px",fontSize:11,lineHeight:1.35,color:"#b91c1c"},children:b})]})]}):go.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Xr}),e==="running"&&go.jsx("span",{title:qe?`Estimated ~${qe} min`:"Estimating\u2026",style:{fontSize:10,fontWeight:600,color:qe?"#1c4587":"#9ca3af",backgroundColor:qe?"rgba(28, 69, 135, 0.08)":"rgba(156, 163, 175, 0.12)",padding:"1px 6px",borderRadius:999,flexShrink:0,fontVariantNumeric:"tabular-nums",animation:qe?void 0:"__fork-pulse 1.4s ease-in-out infinite",minWidth:28,textAlign:"center"},children:qe?`~${qe}m`:"~ m"})]}),!I&&go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[Dr&&go.jsx("button",{onClick:xe?so:oo,onMouseEnter:()=>C(true),onMouseLeave:()=>C(false),title:xe?"Redock to sidebar":"Pop out into window",style:{padding:6,borderRadius:6,color:P?"#4b5563":"#9ca3af",backgroundColor:P?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:xe?go.jsx(lucideReact.PictureInPicture,{style:{width:16,height:16}}):go.jsx(lucideReact.PictureInPicture2,{style:{width:16,height:16}})}),go.jsx("button",{onClick:qr,onMouseEnter:()=>F(true),onMouseLeave:()=>F(false),style:{padding:6,borderRadius:6,color:c?"#4b5563":"#9ca3af",backgroundColor:c?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:go.jsx(lucideReact.X,{style:{width:16,height:16}})})]})]}),go.jsxs("div",{ref:fe,style:{flex:1,overflowY:"auto",minHeight:0,display:"flex",flexDirection:"column"},children:[(Z||ce)&&go.jsxs("div",{style:{padding:"10px 12px 6px 12px",display:"flex",alignItems:"center",gap:8,borderBottom:"1px solid #f3f4f6"},children:[go.jsx("button",{onClick:()=>{le(null),oe(false),se.current=false;},style:{fontSize:12,color:"#374151",background:"transparent",border:"none",padding:"2px 4px",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4},title:"Back to all forks",children:"\u2190 All forks"}),(()=>{let R=(Z?ne.find(U=>U.id===Z)?.targetId:null)??nt;return R?go.jsxs("span",{style:{fontSize:11,color:"#9ca3af",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",flex:1},title:`Forking ${R}`,children:["Forking ",go.jsx("span",{style:{color:"#6b7280"},children:R})]}):null})()]}),!Z&&!ce&&go.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[go.jsx("div",{style:{padding:"12px 16px 10px 16px",borderBottom:"1px solid #f3f4f6"},children:go.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#111827"},children:"Forks"})}),ne.length===0&&go.jsx("div",{style:{padding:"24px 20px",textAlign:"center",fontSize:13,color:"#6b7280"},children:"No forks yet. Describe a feature below to start one."}),ne.length>0&&go.jsx("div",{style:{display:"flex",flexDirection:"column"},children:ne.map(l=>{let R=l.summary||"Untitled fork";return go.jsxs("button",{onClick:()=>{oe(false),le(l.id);},style:{textAlign:"left",padding:"10px 16px",background:"#ffffff",border:"none",borderBottom:"1px solid #f3f4f6",cursor:"pointer",display:"flex",flexDirection:"column",gap:2},onMouseEnter:U=>U.currentTarget.style.background="#fafafa",onMouseLeave:U=>U.currentTarget.style.background="#ffffff",children:[go.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[go.jsx("span",{style:{fontSize:13,fontWeight:500,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",flex:1},children:R}),go.jsx("span",{style:{fontSize:11,color:"#9ca3af",flexShrink:0},children:_s(l.updatedAt)})]}),go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:"#6b7280"},children:[go.jsx("span",{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:l.targetId}),go.jsx("span",{style:{color:"#d1d5db"},children:"\xB7"}),go.jsxs("span",{children:[l.promptCount," prompt",l.promptCount===1?"":"s"]}),l.status==="running"||l.status==="building"?go.jsxs(go.Fragment,{children:[go.jsx("span",{style:{color:"#d1d5db"},children:"\xB7"}),go.jsx("span",{style:{color:"#2563eb"},children:"running"})]}):null]})]},l.id)})})]}),Z&&ut.length>0&&go.jsx("div",{style:{padding:"16px 16px 0 16px"},children:ut.map((l,R)=>go.jsx("div",{style:{marginBottom:R<ut.length-1?10:0},children:l.type==="user"?go.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8,flexDirection:"row-reverse"},children:[go.jsx("div",{style:{width:22,height:22,borderRadius:"50%",backgroundColor:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:2},children:go.jsx(lucideReact.User,{style:{width:13,height:13,color:"#6b7280"}})}),go.jsx("div",{style:{backgroundColor:"#f3f4f6",borderRadius:"12px 4px 12px 12px",padding:"8px 12px",fontSize:13,color:"#374151",lineHeight:1.5,maxWidth:"75%"},children:l.text})]}):M==="item"&&R===ut.length-1?go.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:12,borderRadius:8,border:"1px solid #e4e4e7",background:"#ffffff"},children:[go.jsx("div",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,flexShrink:0,borderRadius:6,background:"#f4f4f5",color:"#0a0a0a"},children:go.jsx(lucideReact.BadgeCheck,{style:{width:16,height:16}})}),go.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,flex:1,minWidth:0},children:[go.jsx("div",{style:{fontSize:13,fontWeight:500,color:"#0a0a0a",lineHeight:1.3},children:"Feature applied"}),go.jsx("div",{style:{fontSize:13,color:"#71717a",lineHeight:1.4},children:l.text})]}),k&&e!=="running"&&go.jsx("button",{onClick:U=>{U.stopPropagation(),Vr();},disabled:j,style:{padding:"4px 10px",fontSize:12,fontWeight:500,borderRadius:6,border:"1px solid #e4e4e7",background:"#ffffff",color:"#0a0a0a",cursor:j?"default":"pointer",opacity:j?.4:1,height:28,flexShrink:0},children:"Undo"})]}):go.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[go.jsx("div",{style:{width:22,height:22,borderRadius:"50%",backgroundColor:"#f0fdf4",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:2},children:go.jsx(lucideReact.Check,{style:{width:13,height:13,color:"#9ca3af"}})}),go.jsxs("div",{style:{backgroundColor:"#f9fafb",borderRadius:"4px 12px 12px 12px",padding:"8px 12px",fontSize:13,color:"#6b7280",fontWeight:500,display:"flex",alignItems:"center",gap:6,maxWidth:"75%"},children:[go.jsx("span",{style:{flex:1},children:l.text}),k&&R===ut.length-1&&e!=="running"&&go.jsxs("button",{onClick:U=>{U.stopPropagation(),Vr();},onMouseEnter:()=>K(R),onMouseLeave:()=>K(null),disabled:j,style:{position:"relative",padding:2,borderRadius:4,border:"none",background:de===R?"rgba(0,0,0,0.06)":"transparent",color:de===R?"#6b7280":"#d1d5db",cursor:j?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s, background 0.15s",opacity:j?.4:1,flexShrink:0},children:[go.jsx(lucideReact.Undo2,{style:{width:12,height:12}}),de===R&&go.jsx("span",{style:{position:"absolute",bottom:"calc(100% + 4px)",right:0,fontSize:10,fontWeight:500,color:"#fff",background:"#374151",borderRadius:4,padding:"2px 6px",whiteSpace:"nowrap",pointerEvents:"none",lineHeight:"16px"},children:"Undo"})]})]})]})},R))}),e==="running"&&(Z||ce)&&go.jsx("div",{style:{padding:16},children:go.jsxs("div",{onClick:()=>Q(!V),style:{backgroundColor:"#1a1a2e",borderRadius:12,overflow:"hidden",cursor:"pointer",transition:"all 0.3s cubic-bezier(0.22, 1, 0.36, 1)"},children:[go.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px"},children:[go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[go.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#6b7280",strokeWidth:"2.5",strokeLinecap:"round",style:{animation:"__fork-spin 2s linear infinite",flexShrink:0},children:go.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),go.jsx(Es,{events:r})]}),go.jsx("div",{style:{color:"#6b7280",flexShrink:0,marginLeft:8,transition:"transform 0.2s ease",transform:V?"rotate(180deg)":"rotate(0deg)"},children:go.jsx(lucideReact.ChevronDown,{style:{width:14,height:14}})})]}),go.jsx("div",{style:{maxHeight:V?320:0,opacity:V?1:0,transition:"max-height 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease",overflow:"hidden"},children:go.jsx("div",{style:{borderTop:"1px solid rgba(255,255,255,0.08)",maxHeight:320,overflowY:"auto"},children:go.jsx(Sn,{events:r})})})]})}),e==="error"&&(Z||ce)&&go.jsxs("div",{style:{padding:"20px 16px",textAlign:"center"},children:[go.jsx("div",{style:{width:36,height:36,backgroundColor:"#fef2f2",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 10px auto"},children:go.jsx(lucideReact.X,{style:{width:18,height:18,color:"#ef4444"}})}),go.jsx("p",{style:{fontSize:12,color:"#6b7280",marginBottom:10,maxWidth:260,margin:"0 auto 10px auto"},children:n}),go.jsxs("button",{onClick:()=>{let l=t?.prompt||Tt.current;l&&u(l,nt);},onMouseEnter:()=>z(true),onMouseLeave:()=>z(false),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 12px",borderRadius:8,fontSize:12,fontWeight:500,color:"#4f46e5",backgroundColor:_?"#e0e7ff":"#eef2ff",border:"none",cursor:"pointer",transition:"background-color 0.15s",fontFamily:"inherit"},children:[go.jsx(lucideReact.RotateCcw,{style:{width:12,height:12}})," Try Again"]})]})]}),e!=="running"&&go.jsx("div",{style:{padding:"8px 12px 12px 12px",borderTop:"1px solid rgba(229, 231, 235, 0.6)",flexShrink:0},children:go.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,borderRadius:12,padding:"8px 8px 8px 12px",background:"rgba(0, 0, 0, 0.04)",border:"1px solid rgba(0, 0, 0, 0.06)"},children:[go.jsx("textarea",{ref:Se,value:h,onChange:l=>{v(l.target.value),l.target.style.height="auto",l.target.style.height=Math.min(l.target.scrollHeight,160)+"px";},onKeyDown:l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),zr()),l.key==="Escape"&&!I&&qr();},placeholder:Z?"Iterate on this feature...":"Start building a new Fork...",rows:1,style:{flex:1,backgroundColor:"transparent",fontSize:13,color:"#111827",border:"none",outline:"none",padding:"0 4px 0 0",fontFamily:"inherit",resize:"none",lineHeight:1.5,maxHeight:160,overflow:"auto"}}),go.jsx("button",{onClick:zr,disabled:!h.trim(),onMouseEnter:()=>y(true),onMouseLeave:()=>y(false),style:{width:26,height:26,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",color:"#ffffff",opacity:h.trim()?1:.25,transform:x&&h.trim()?"scale(1.1)":"scale(1)",background:h.trim()?"#1c4587":"rgba(0,0,0,0.12)",border:"none",cursor:h.trim()?"pointer":"default",flexShrink:0,transition:"transform 0.15s, opacity 0.15s",padding:0},children:go.jsx(lucideReact.ArrowUp,{style:{width:13,height:13}})})]})})]})]});return I?nr:xe&&J?po.createPortal(nr,J.document.body):go.jsx(Cs,{children:nr})}function En(e){if("target"in e&&e.target)return e.target;if("boundaryId"in e&&e.boundaryId)return {type:"boundary",id:e.boundaryId,title:e.title};if("slotId"in e&&e.slotId)return {type:"slot",id:e.slotId,title:e.title??e.slotLabel};throw new Error("Fork chat target requires either target, slotId, or boundaryId.")}function xr(e){let{apiKey:t,userId:r,userHash:n,baseUrl:o,appId:s,previewSession:i,refreshModuleManifest:a,queueBoundaryAnimation:u,trackForkActivity:k,recordForkActivityEvent:g}=he(),[d,w]=mr.useState("idle"),[A,f]=mr.useState(null),[p,I]=mr.useState([]),[M,h]=mr.useState(null),v=mr.useRef(null),T=mr.useCallback(()=>{w("prompting"),I([]),h(null),f(null);},[]),N=mr.useCallback(()=>{w("idle"),v.current&&(v.current.close(),v.current=null);},[]);mr.useEffect(()=>{i&&i.target.kind==="module"&&i.target.id===e&&w(L=>L==="idle"?"prompting":L);},[i?.preview_session_id,i?.target.id,e]);let D=mr.useCallback(async(L,B,S)=>{try{if(!s)throw new Error("ForkProvider requires appId for module boundary prompts.");w("running"),I([]),h(null),f(null);let c;if(i){let C=S?.forkId??i.fork_id??void 0,x=await fetch(`${o}/api/v1/preview/${encodeURIComponent(i.preview_session_id)}/author`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...te()},body:JSON.stringify({prompt:L,...e?{boundary_id:e}:{},...C&&!S?.forceNew?{fork_id:C}:{},...S?.forceNew?{force_new:!0}:{}})});if(!x.ok){let z=await x.json().catch(()=>({}));throw new Error(z.error||`API error: ${x.status}`)}let y=await x.json();y.container_id&&Ge(y.container_id,y.container_name),dt(y.fork_id),c=await(await fetch(`${o}/api/v1/forks/${y.fork_id}`,{headers:{Authorization:`Bearer ${t}`,...te()}})).json();}else if(S?.forkId){let C={prompt:L};r&&(C.userId=r),n&&(C.userHash=n);let x=await fetch(`${o}/api/v1/forks/${encodeURIComponent(S.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(C)});if(!x.ok){let y=await x.json().catch(()=>({}));throw new Error(y.error||`API error: ${x.status}`)}c=await x.json();}else {let C={userId:r,prompt:L,boundaryId:e,appId:s};B&&(C.containerId=B),n&&(C.userHash=n),S?.forceNew&&(C.force_new=!0);let x=await fetch(`${o}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(C)});if(!x.ok){let y=await x.json().catch(()=>({}));throw new Error(y.error||`API error: ${x.status}`)}c=await x.json();}f(c),k(c,{targetKind:"module",targetId:e});let F=new URLSearchParams({key:t});i?(F.set("previewSessionId",i.preview_session_id),F.set("previewForkId",c.id)):r&&F.set("userId",r),n&&F.set("userHash",n);let P=new EventSource(`${o}/api/v1/forks/${c.id}/events?${F.toString()}`);v.current=P,P.onmessage=C=>{try{let x=JSON.parse(C.data);if(g(c.id,x),I(y=>[...y,x]),x.type==="complete"){let y=x.data;u(e,c.id),a().catch(()=>{}).finally(()=>{let _={...c,status:"complete",moduleUrl:y.moduleUrl,cssUrls:y.cssUrls,summary:y.summary,completedAt:new Date().toISOString()};f(_),w("complete"),P.close();});}else if(x.type==="error"){let y=x.data;h(y.error||"Unknown error"),w("error"),P.close();}}catch{}},P.onerror=()=>{let C={Authorization:`Bearer ${t}`,...te()};!i&&r&&(C["X-Fork-User-Id"]=r),!i&&n&&(C["X-Fork-User-Hash"]=n),fetch(`${o}/api/v1/forks/${c.id}`,{headers:C}).then(x=>x.json()).then(x=>{f(x),x.status==="complete"?(u(e,x.id),a().catch(()=>{}),w("complete")):x.status==="error"&&(h(x.error||"Fork generation failed"),w("error"));}).catch(()=>{h("Connection lost"),w("error");}),P.close();};}catch(c){h(c.message),w("error");}},[t,s,o,e,i,u,a,g,k,n,r]),O=mr.useCallback(async L=>{try{let B={Authorization:`Bearer ${t}`,...te()};!i&&r&&(B["X-Fork-User-Id"]=r),!i&&n&&(B["X-Fork-User-Hash"]=n);let S=await fetch(`${o}/api/v1/forks/${L}`,{headers:B});if(!S.ok)return;let c=await S.json(),F=c.boundaryId??e;if(k(c,{targetKind:"module",targetId:F}),c.status==="complete"){w("complete"),f(c),h(null),I([]);return}if(c.status==="error"){w("error"),f(c),h(c.error||"Fork generation failed"),I([]);return}if(c.status!=="pending"&&c.status!=="running"&&c.status!=="building")return;w("running"),f(c),h(null),I([]);let P=new URLSearchParams({key:t});i?(P.set("previewSessionId",i.preview_session_id),P.set("previewForkId",c.id)):r&&P.set("userId",r),n&&P.set("userHash",n);let C=new EventSource(`${o}/api/v1/forks/${c.id}/events?${P.toString()}`);v.current&&v.current.close(),v.current=C,C.onmessage=x=>{try{let y=JSON.parse(x.data);if(g(c.id,y),I(_=>[..._,y]),y.type==="complete"){let _=y.data;u(e,c.id),a().catch(()=>{}).finally(()=>{let z={...c,status:"complete",moduleUrl:_.moduleUrl,cssUrls:_.cssUrls,summary:_.summary,completedAt:new Date().toISOString()};f(z),w("complete"),C.close();});}else if(y.type==="error"){let _=y.data;h(_.error||"Unknown error"),w("error"),C.close();}}catch{}},C.onerror=()=>{C.close();};}catch{}},[t,o,e,i,u,g,a,k,n,r]),E=mr.useCallback(async()=>{try{if(!s)throw new Error("ForkProvider requires appId for boundary undo.");let L={userId:r,boundaryId:e,appId:s};n&&(L.userHash=n);let B=await fetch(`${o}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(L)});if(!B.ok){let c=await B.json().catch(()=>({}));throw new Error(c.error||`API error: ${B.status}`)}let S=await B.json();return await a().catch(()=>{}),S.removed?(f(null),w("prompting")):S.fork&&(f(S.fork),w("complete")),S}catch(L){throw h(L.message),L}},[t,s,o,e,a,n,r]);return {state:d,fork:A,events:p,error:M,open:T,close:N,startFork:D,undoFork:E,adoptRunningFork:O}}var Ms=0;function Pn(e){let{state:t,fork:r,events:n,error:o,open:s,close:i,startFork:a,undoFork:u,adoptRunningFork:k}=xr(e),[g,d]=mr.useState(false),w=mr.useRef(null),A=mr.useRef(t),f=mr.useCallback(()=>{w.current!==null&&(clearTimeout(w.current),w.current=null);},[]),p=mr.useCallback(()=>{f(),d(true),s();},[f,s]),I=mr.useCallback(()=>{f(),d(false),i();},[f,i]),M=mr.useCallback(async h=>{f(),d(true),await k(h);},[k,f]);return mr.useEffect(()=>{let h=A.current;A.current=t,t==="complete"&&h==="running"&&g&&(f(),w.current=setTimeout(()=>{w.current=null,d(false),i();},Ms)),(t==="running"||t==="prompting")&&f();},[t,g,f,i]),mr.useEffect(()=>f,[f]),{state:t,fork:r,events:n,error:o,isOpen:g,open:p,close:I,submit:a,undo:u,adoptRunningFork:M}}function Ar(){let{apiKey:e,userId:t,userHash:r,baseUrl:n,previewSession:o,setSlotFork:s,clearSlotFork:i,skipAnimationForSlot:a,trackForkActivity:u,recordForkActivityEvent:k}=he(),[g,d]=mr.useState("idle"),[w,A]=mr.useState(null),[f,p]=mr.useState([]),[I,M]=mr.useState(null),h=mr.useRef(null),v=mr.useCallback(()=>{d("prompting"),p([]),M(null),A(null);},[]),T=mr.useCallback(()=>{d("idle"),h.current&&(h.current.close(),h.current=null);},[]);mr.useEffect(()=>{o&&o.target.kind==="slot"&&d(E=>E==="idle"?"prompting":E);},[o?.preview_session_id,o?.target.kind]);let N=mr.useCallback(async(E,L,B,S)=>{try{d("running"),p([]),M(null),A(null);let c;if(o){let x=S?.forkId??o.fork_id??void 0,y=await fetch(`${n}/api/v1/preview/${encodeURIComponent(o.preview_session_id)}/author`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...te()},body:JSON.stringify({prompt:E,...L?{slot_id:L}:{},...x&&!S?.forceNew?{fork_id:x}:{},...S?.forceNew?{force_new:!0}:{}})});if(!y.ok){let V=await y.json().catch(()=>({}));throw new Error(V.error||`API error: ${y.status}`)}let _=await y.json();_.container_id&&Ge(_.container_id,_.container_name),dt(_.fork_id),c=await(await fetch(`${n}/api/v1/forks/${_.fork_id}`,{headers:{Authorization:`Bearer ${e}`,...te()}})).json();}else if(S?.forkId){let x={prompt:E};t&&(x.userId=t),r&&(x.userHash=r);let y=await fetch(`${n}/api/v1/forks/${encodeURIComponent(S.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(x)});if(!y.ok){let _=await y.json().catch(()=>({}));throw new Error(_.error||`API error: ${y.status}`)}c=await y.json();}else {let x={userId:t,prompt:E};L&&(x.slotId=L),B&&(x.containerId=B),r&&(x.userHash=r),S?.forceNew&&(x.force_new=!0);let y=await fetch(`${n}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(x)});if(!y.ok){let _=await y.json().catch(()=>({}));throw new Error(_.error||`API error: ${y.status}`)}c=await y.json();}A(c);let F=L??c.slotId;F&&u(c,{targetKind:"slot",targetId:F});let P=new URLSearchParams({key:e});o?(P.set("previewSessionId",o.preview_session_id),P.set("previewForkId",c.id)):t&&P.set("userId",t),r&&P.set("userHash",r);let C=new EventSource(`${n}/api/v1/forks/${c.id}/events?${P.toString()}`);h.current=C,C.onmessage=x=>{try{let y=JSON.parse(x.data);if(k(c.id,y),p(_=>[..._,y]),y.type==="complete"){let _=y.data,z={...c,status:"complete",bundleUrl:_.bundleUrl,summary:_.summary,completedAt:new Date().toISOString()};A(z),d("complete"),L&&_.bundleUrl&&s(L,z),C.close();}else if(y.type==="error"){let _=y.data;M(_.error||"Unknown error"),d("error"),C.close();}}catch{}},C.onerror=()=>{let x={Authorization:`Bearer ${e}`,...te()};!o&&t&&(x["X-Fork-User-Id"]=t),!o&&r&&(x["X-Fork-User-Hash"]=r),fetch(`${n}/api/v1/forks/${c.id}`,{headers:x}).then(y=>y.json()).then(y=>{A(y),y.status==="complete"?(d("complete"),L&&y.bundleUrl&&s(L,y)):y.status==="error"&&(M(y.error||"Fork generation failed"),d("error"));}).catch(()=>{M("Connection lost"),d("error");}),C.close();};}catch(c){M(c.message),d("error");}},[e,n,o,k,s,u,r,t]),D=mr.useCallback(async E=>{try{let L={Authorization:`Bearer ${e}`,...te()};!o&&t&&(L["X-Fork-User-Id"]=t),!o&&r&&(L["X-Fork-User-Hash"]=r);let B=await fetch(`${n}/api/v1/forks/${E}`,{headers:L});if(!B.ok)return;let S=await B.json();if(S.slotId&&u(S,{targetKind:"slot",targetId:S.slotId}),S.status==="complete"){d("complete"),A(S),M(null),p([]);return}if(S.status==="error"){d("error"),A(S),M(S.error||"Fork generation failed"),p([]);return}if(S.status!=="pending"&&S.status!=="running"&&S.status!=="building")return;d("running"),A(S),M(null),p([]);let c=new URLSearchParams({key:e});o?(c.set("previewSessionId",o.preview_session_id),c.set("previewForkId",S.id)):t&&c.set("userId",t),r&&c.set("userHash",r);let F=new EventSource(`${n}/api/v1/forks/${S.id}/events?${c.toString()}`);h.current&&h.current.close(),h.current=F;let P=S.slotId;F.onmessage=C=>{try{let x=JSON.parse(C.data);if(k(S.id,x),p(y=>[...y,x]),x.type==="complete"){let y=x.data,_={...S,status:"complete",bundleUrl:y.bundleUrl,summary:y.summary,completedAt:new Date().toISOString()};A(_),d("complete"),P&&y.bundleUrl&&s(P,_),F.close();}else if(x.type==="error"){let y=x.data;M(y.error||"Unknown error"),d("error"),F.close();}}catch{}},F.onerror=()=>{F.close();};}catch{}},[e,n,o,k,s,u,r,t]),O=mr.useCallback(async E=>{try{let L={userId:t,slotId:E};r&&(L.userHash=r);let B=await fetch(`${n}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(L)});if(!B.ok){let c=await B.json().catch(()=>({}));throw new Error(c.error||`API error: ${B.status}`)}let S=await B.json();return a(E),S.removed?(i(E),A(null),d("prompting")):S.fork&&(s(E,S.fork),A(S.fork)),S}catch(L){throw M(L.message),L}},[e,t,r,n,i,s]);return {state:g,fork:w,events:f,error:I,open:v,close:T,startFork:N,undoFork:O,adoptRunningFork:D}}var Us=0;function Ln(){let{state:e,fork:t,events:r,error:n,open:o,close:s,startFork:i,undoFork:a,adoptRunningFork:u}=Ar(),[k,g]=mr.useState(false),d=mr.useRef(null),w=mr.useRef(e),A=mr.useCallback(()=>{d.current!==null&&(clearTimeout(d.current),d.current=null);},[]),f=mr.useCallback(()=>{A(),g(true),o();},[A,o]),p=mr.useCallback(()=>{A(),g(false),s();},[A,s]),I=mr.useCallback(async M=>{A(),g(true),await u(M);},[u,A]);return mr.useEffect(()=>{let M=w.current;w.current=e,e==="complete"&&M==="running"&&k&&(A(),d.current=setTimeout(()=>{d.current=null,g(false),s();},Us)),(e==="running"||e==="prompting")&&A();},[e,k,A,s]),mr.useEffect(()=>A,[A]),{state:e,fork:t,events:r,error:n,isOpen:k,open:f,close:p,submit:i,undo:a,adoptRunningFork:I}}var Ns=new Set(["pending","running","building"]);function _r(e){let t=En(e),r=Ln(),n=Pn(t.type==="boundary"?t.id:""),{baseUrl:o,apiKey:s,userId:i,userHash:a,appId:u,activitySummary:k,forkActivities:g,markForkActivitySeen:d}=he(),w=t.type==="slot"?r:n,A=t.type==="slot"?"slot":"boundary",f=t.id,p=t.title,I=t.type==="slot"?"slot":"module",M=g.find(D=>D.targetKind===I&&D.targetId===t.id&&Ns.has(D.status)),h=g.find(D=>D.targetKind===I&&D.targetId===t.id&&D.status==="complete"&&D.unread),v=mr.useCallback(()=>{d();let D=M??h;if(D){w.adoptRunningFork(D.id);return}w.open();},[w,d,M,h]),T=mr.useCallback((D,O,E,L)=>t.type==="slot"?r.submit(D,O??t.id,E,L):n.submit(D,E,L),[n,r,t]),N=mr.useCallback(D=>t.type==="slot"?r.undo(D??t.id):n.undo(),[n,r,t]);return {...w,open:v,target:t,targetId:f,targetLabel:p,historyMode:A,submit:T,undo:N,buttonProps:{onClick:v,hasNotification:k.unreadCompletedCount>0,activity:k},panelProps:{state:w.state,fork:w.fork,events:w.events,error:w.error,...t.type==="slot"?{slotId:f,targetLabel:p,historyMode:A}:{targetId:f,targetLabel:p,historyMode:A},onSubmit:T,onUndo:N,onClose:w.close,baseUrl:o,apiKey:s,userId:i,userHash:a,appId:u}}}function Ft(e){let{embedded:t,completeVariant:r}=e,n=_r(e);return t?go.jsx(qt,{...n.panelProps,embedded:true,completeVariant:r}):n.isOpen?go.jsx(qt,{...n.panelProps,completeVariant:r}):go.jsx(wr,{...n.buttonProps})}function Bs({boundaryId:e,title:t}){return go.jsx(Ft,{boundaryId:e,title:t})}function Er(e){let t=Array.from(e.children).filter(n=>n instanceof HTMLElement);return t.length===1?t[0]:getComputedStyle(e).display==="contents"?null:e}function Hn(e){let t=e.getBoundingClientRect(),r=e.cloneNode(true);r.setAttribute("data-fork-clone-overlay","true"),r.style.position="fixed",r.style.top=`${t.top}px`,r.style.left=`${t.left}px`,r.style.width=`${t.width}px`,r.style.height=`${t.height}px`,r.style.flex="none",r.style.minHeight="auto",r.style.zIndex="9998",r.style.pointerEvents="none",r.style.overflow="hidden";let n=getComputedStyle(e).backgroundColor;r.style.backgroundColor=n&&n!=="rgba(0, 0, 0, 0)"&&n!=="transparent"?n:getComputedStyle(document.body).backgroundColor||"#ffffff",document.body.appendChild(r);let o=e.querySelectorAll("*"),s=r.querySelectorAll("*");for(let i=0;i<o.length;i+=1)o[i].scrollTop!==0&&(s[i].scrollTop=o[i].scrollTop),o[i].scrollLeft!==0&&(s[i].scrollLeft=o[i].scrollLeft);return r}function Cr(e){let t=[],r=e.querySelectorAll("*");for(let n of r){if(!(n instanceof HTMLElement))continue;let o=n.getBoundingClientRect();if(o.width<10||o.height<10||["SCRIPT","STYLE","META","LINK"].includes(n.tagName))continue;let s=getComputedStyle(n),i=parseFloat(s.borderTopLeftRadius)||0;t.push({tag:n.tagName,className:n.className||"",text:(n.textContent||"").slice(0,50).trim(),rect:o,borderRadius:i});}return t}function On(e,t){let r=[];for(let n of t)if(!(e.find(i=>i.tag===n.tag&&i.className===n.className&&Math.abs(i.rect.top-n.rect.top)<20&&Math.abs(i.rect.left-n.rect.left)<20)||r.some(i=>n.rect.top>=i.rect.top&&n.rect.left>=i.rect.left&&n.rect.right<=i.rect.right&&n.rect.bottom<=i.rect.bottom))){for(let i=r.length-1;i>=0;i-=1){let a=r[i];a.rect.top>=n.rect.top&&a.rect.left>=n.rect.left&&a.rect.right<=n.rect.right&&a.rect.bottom<=n.rect.bottom&&r.splice(i,1);}r.push({rect:n.rect,borderRadius:n.borderRadius});}return r}function Un(e,t){let r=[];for(let n of e)if(!(t.find(i=>i.tag===n.tag&&i.className===n.className&&Math.abs(i.rect.top-n.rect.top)<20&&Math.abs(i.rect.left-n.rect.left)<20)||r.some(i=>n.rect.top>=i.rect.top&&n.rect.left>=i.rect.left&&n.rect.right<=i.rect.right&&n.rect.bottom<=i.rect.bottom))){for(let i=r.length-1;i>=0;i-=1){let a=r[i];a.rect.top>=n.rect.top&&a.rect.left>=n.rect.left&&a.rect.right<=n.rect.right&&a.rect.bottom<=n.rect.bottom&&r.splice(i,1);}r.push({rect:n.rect,borderRadius:n.borderRadius});}return r}function Nn(e,t,r,n,o){let s=Math.max(0,Math.min(o,r/2,n/2));return s===0?`M ${e} ${t} L ${e+r} ${t} L ${e+r} ${t+n} L ${e} ${t+n} Z`:[`M ${e+s} ${t}`,`L ${e+r-s} ${t}`,`A ${s} ${s} 0 0 1 ${e+r} ${t+s}`,`L ${e+r} ${t+n-s}`,`A ${s} ${s} 0 0 1 ${e+r-s} ${t+n}`,`L ${e+s} ${t+n}`,`A ${s} ${s} 0 0 1 ${e} ${t+n-s}`,`L ${e} ${t+s}`,`A ${s} ${s} 0 0 1 ${e+s} ${t}`,"Z"].join(" ")}function $r(e){let t="http://www.w3.org/2000/svg",r=document.createElement("div");r.setAttribute("data-fork-highlights","true"),r.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let n=document.createElementNS(t,"svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs");n.appendChild(o);let s=[];for(let g=0;g<e.length;g+=1){let{rect:d,borderRadius:w}=e[g],A=d.left-.5,f=d.top-.5,p=d.width+1,I=d.height+1,M=Math.min(w+.5,p/2,I/2),h=Nn(A,f,p,I,M),v=`__fork-glow-${g}`,T=document.createElementNS(t,"filter");T.setAttribute("id",v),T.setAttribute("x","-100%"),T.setAttribute("y","-100%"),T.setAttribute("width","300%"),T.setAttribute("height","300%");let N=document.createElementNS(t,"feGaussianBlur");N.setAttribute("in","SourceGraphic"),N.setAttribute("stdDeviation","8"),T.appendChild(N),o.appendChild(T);let D=`__fork-mask-${g}`,O=document.createElementNS(t,"mask");O.setAttribute("id",D),O.setAttribute("maskUnits","userSpaceOnUse"),O.setAttribute("x",String(A-200)),O.setAttribute("y",String(f-200)),O.setAttribute("width",String(p+400)),O.setAttribute("height",String(I+400));let E=document.createElementNS(t,"rect");E.setAttribute("x",String(A-200)),E.setAttribute("y",String(f-200)),E.setAttribute("width",String(p+400)),E.setAttribute("height",String(I+400)),E.setAttribute("fill","white"),O.appendChild(E);let L=document.createElementNS(t,"path");L.setAttribute("d",h),L.setAttribute("fill","black"),O.appendChild(L),o.appendChild(O);let B=document.createElementNS(t,"g");B.setAttribute("mask",`url(#${D})`),B.setAttribute("opacity","0");let S=document.createElementNS(t,"g");S.setAttribute("filter",`url(#${v})`);let c=document.createElementNS(t,"path");c.setAttribute("d",h),c.setAttribute("fill","none"),c.setAttribute("stroke","rgba(150, 185, 220, 0.6)"),c.setAttribute("stroke-width","6"),c.setAttribute("stroke-linecap","round"),S.appendChild(c),B.appendChild(S),n.appendChild(B);let F=document.createElementNS(t,"path");F.setAttribute("d",h),F.setAttribute("fill","none"),F.setAttribute("stroke","rgba(150, 185, 220, 0.35)"),F.setAttribute("stroke-width","2"),F.setAttribute("stroke-linecap","round"),F.setAttribute("opacity","0"),n.appendChild(F),s.push(c,F),c.__group=B;}r.appendChild(n),document.body.appendChild(r);let i=[];for(let g=0;g<s.length;g+=2){let d=s[g],w=s[g+1],A=d.__group;if(!A)continue;let f=w.getTotalLength(),p=d.getTotalLength();if(f<=0)continue;let I=f*.35;w.setAttribute("stroke-dasharray",`${I} ${f-I}`),w.setAttribute("stroke-dashoffset","0"),i.push(w.animate([{strokeDashoffset:0,opacity:0,offset:0},{strokeDashoffset:-0.2*f,opacity:.92,offset:.06},{strokeDashoffset:-2*f,opacity:.92,offset:.92},{strokeDashoffset:-2.25*f,opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));let M=p*.35;d.setAttribute("stroke-dasharray",`${M} ${p-M}`),d.setAttribute("stroke-dashoffset","0"),i.push(d.animate([{strokeDashoffset:0,offset:0},{strokeDashoffset:-0.2*p,offset:.06},{strokeDashoffset:-2*p,offset:.92},{strokeDashoffset:-2.25*p,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"})),i.push(A.animate([{opacity:0,offset:0},{opacity:.92,offset:.06},{opacity:.92,offset:.92},{opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));}let a=false,u=()=>{if(a)return;a=true,clearTimeout(k);for(let d of i)try{d.cancel();}catch{}let g=r.animate([{opacity:1},{opacity:0}],{duration:400,fill:"forwards"});g.onfinish=()=>r.remove(),window.removeEventListener("click",u);},k=setTimeout(u,14500);return setTimeout(()=>{a||window.addEventListener("click",u);},500),u}function Bn(e){let t="http://www.w3.org/2000/svg",r=document.createElement("div");r.setAttribute("data-fork-removed","true"),r.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let n=document.createElementNS(t,"svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs"),s=document.createElementNS(t,"filter");s.setAttribute("id","__fork-removed-shadow"),s.setAttribute("x","-10%"),s.setAttribute("y","-10%"),s.setAttribute("width","120%"),s.setAttribute("height","120%");let i=document.createElementNS(t,"feDropShadow");i.setAttribute("dx","0"),i.setAttribute("dy","1"),i.setAttribute("stdDeviation","2"),i.setAttribute("flood-color","rgba(0,0,0,0.15)"),s.appendChild(i),o.appendChild(s),n.appendChild(o);for(let{rect:a,borderRadius:u}of e){let k=document.createElementNS(t,"path");k.setAttribute("d",Nn(a.left,a.top,a.width,a.height,u)),k.setAttribute("fill","none"),k.setAttribute("stroke","rgba(120, 125, 135, 0.6)"),k.setAttribute("stroke-width","1.5"),k.setAttribute("stroke-dasharray","8 4"),k.setAttribute("stroke-linecap","round"),k.setAttribute("filter","url(#__fork-removed-shadow)"),k.setAttribute("opacity","0"),n.appendChild(k),k.animate([{opacity:0,offset:0},{opacity:.6,offset:.08},{opacity:.05,offset:.45},{opacity:.6,offset:.85},{opacity:.05,offset:1}],{duration:5e3,easing:"ease-in-out",fill:"forwards"});}return r.appendChild(n),document.body.appendChild(r),r}function Kn(e,t){if(js(t.selector))return jn(e,t);let n=jn(e,t);if(n)return n;try{let s=document.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e&&e.contains(s))return s}catch{}if(Dn(t.selector))try{let s=e.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e)return s}catch{}if(t.textHint){let s=t.textHint.trim();if(s){let i=Tr(e,g=>g===s);if(i)return i;let a=s.toLowerCase(),u=Tr(e,g=>g.toLowerCase()===a);if(u)return u;let k=Tr(e,g=>g.toLowerCase().includes(a));if(k)return k}}let o=Ks(t.selector);if(o&&o!==t.selector&&Dn(o))try{let s=e.querySelector(o);if(s instanceof HTMLElement&&s!==e)return s}catch{}return null}function Dn(e){let t=e.split(/\s+|>|~|\+/),r=t[t.length-1]??"";return /[#\[]|:not\(|:nth-/.test(r)}function jn(e,t){let r=Array.from(e.querySelectorAll("[data-fork-new]"));if(r.length===0)return null;let n=Pr(t.label),o=Pr(t.textHint);return r.find(i=>{let a=Pr(i.getAttribute("data-fork-new"));return !!a&&(a===n||a===o)})??null}function js(e){return e.trim()==="[data-fork-new]"}function Pr(e){return e?.trim().replace(/\s+/g," ").toLowerCase()||null}function Ks(e){return e.replace(/\[class[\*~|^$]?=("[^"]*"|'[^']*'|[^\]]+)\]/g,"").replace(/\.[A-Za-z_][\w-]*/g,"").replace(/\s+/g," ").trim()}function Tr(e,t){let r=null,n=1/0,o=e.querySelectorAll("*");for(let s of o){let i=s.textContent?.trim();if(!i||!t(i))continue;let a=s.getBoundingClientRect();if(a.width<4||a.height<4)continue;let u=a.width*a.height;u<n&&(r=s,n=u);}return r}var Mr=2147483600,zs=1600,Ws=3e4,Js=300,Ke=10;function Vs(e){let r=getComputedStyle(e).borderTopLeftRadius;if(!r)return 4;if(r.endsWith("%")){let i=parseFloat(r);if(!Number.isFinite(i)||i<=0)return 4;let a=e.getBoundingClientRect(),u=Math.min(a.width,a.height);return Math.max(4,i/100*u)}let n=parseFloat(r);if(!Number.isFinite(n)||n<=0)return 4;let o=e.getBoundingClientRect(),s=Math.min(o.width,o.height)/2;return n>=s?s:Math.min(n,16)}function qs(e,t,r,n){let s=window.innerWidth,i=window.innerHeight,a=e;a==="top"&&t.top<n+Ke+8?a="bottom":a==="bottom"&&i-t.bottom<n+Ke+8?a="top":a==="left"&&t.left<r+Ke+8?a="right":a==="right"&&s-t.right<r+Ke+8&&(a="left");let u=0,k=0;return a==="top"?(u=t.top-n-Ke,k=t.left+t.width/2-r/2):a==="bottom"?(u=t.bottom+Ke,k=t.left+t.width/2-r/2):a==="left"?(u=t.top+t.height/2-n/2,k=t.left-r-Ke):(u=t.top+t.height/2-n/2,k=t.right+Ke),k=Math.max(8,Math.min(k,s-r-8)),u=Math.max(8,Math.min(u,i-n-8)),{top:u,left:k,placement:a}}function Xs(e){let t=document.createElement("div");t.setAttribute("data-fork-highlight-outline","true"),t.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr}`,"border:1.5px solid rgba(59,130,246,0.85)","box-sizing:border-box","opacity:0","transition:opacity 200ms ease-out"].join(";");let r=document.createElement("div");r.setAttribute("data-fork-highlight-glow","true"),r.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr-1}`,"box-sizing:border-box","border:1px solid rgba(59,130,246,0.36)","box-shadow:0 0 0 4px rgba(59,130,246,0.16), 0 0 18px 2px rgba(59,130,246,0.31)","opacity:0","transition:opacity 200ms ease-out"].join(";");let n=document.createElement("div");return n.setAttribute("data-fork-highlight-tooltip","true"),n.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr+1}`,"padding:6px 10px","font:500 12px/1.2 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif","color:#ffffff","background:linear-gradient(135deg,#64748b,#475569)","border-radius:999px","box-shadow:0 4px 14px rgba(71,85,105,0.31),0 1px 2px rgba(0,0,0,0.1)","white-space:nowrap","opacity:0","transform:translateY(-2px)","transition:opacity 200ms ease-out, transform 200ms ease-out"].join(";"),n.textContent=`New: ${e}`,{outline:t,glow:r,tooltip:n}}function Gs(){if(document.getElementById("__fork-highlight-keyframes"))return;let e=document.createElement("style");e.id="__fork-highlight-keyframes",e.textContent=`
|
|
60
60
|
@keyframes __fork-highlight-pulse {
|
|
61
61
|
0%, 100% { box-shadow: 0 0 0 3px rgba(59,130,246,0.11), 0 0 12px 1px rgba(59,130,246,0.22); }
|
|
62
62
|
50% { box-shadow: 0 0 0 6px rgba(59,130,246,0.25), 0 0 22px 4px rgba(59,130,246,0.49); }
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,7 @@ import*as mr from'react';import mr__default,{createContext,useSyncExternalStore,
|
|
|
56
56
|
scrollbar-width: thin;
|
|
57
57
|
scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
|
|
58
58
|
}
|
|
59
|
-
`}),jsxs("div",{className:"__fork-panel",style:co,children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid rgba(229, 231, 235, 0.8)",flexShrink:0},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flex:1},children:[jsx("span",{onDoubleClick:async l=>{if(l.stopPropagation(),!G&&confirm("Kill all forks in this container?")){we(true);try{let R=await Fe();`${R?.deleted??0}`,ue([]),le(null),oe(!1),v("");}catch(R){console.error("[Fork] Reset failed:",R);}finally{we(false);}}},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:4,margin:-4,cursor:"pointer",flexShrink:0},children:jsx(zt,{style:{width:16,height:16,color:"#1c4587",pointerEvents:"none"}})}),e==="running"?jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:ao}):ve.length===0&&!rt?jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:"Fork"}):rt?jsxs("div",{ref:Lt,style:{position:"relative",minWidth:0,display:"inline-flex"},children:[jsxs("button",{type:"button",onClick:()=>{Je(l=>!l);},onMouseEnter:()=>at(true),onMouseLeave:()=>at(false),"aria-haspopup":"menu","aria-expanded":$e,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 6px",border:"1px solid transparent",borderRadius:6,background:tr||$e?"#f3f4f6":"transparent",fontSize:13,fontWeight:600,color:"#111827",fontFamily:"inherit",cursor:"pointer",maxWidth:180,minWidth:0,transition:"background-color 0.12s"},children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Xr}),jsx(ChevronDown,{style:{width:12,height:12,color:"#6b7280",flexShrink:0,transform:$e?"rotate(180deg)":void 0,transition:"transform 0.15s"}})]}),$e&&jsxs("div",{role:"menu",style:{position:"absolute",top:"calc(100% + 4px)",left:0,minWidth:200,maxWidth:260,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06)",padding:4,zIndex:2147483001},children:[ve.map(l=>{let R=l.id===ye,U=Et===l.id,me=re===l.id;return jsxs("button",{type:"button",role:"menuitem",onMouseEnter:()=>Ct(l.id),onMouseLeave:()=>Ct(null),onClick:()=>{l.id!==ye&&lo(l.id);},disabled:!!re,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 8px",border:"none",background:U?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:re?"default":"pointer",textAlign:"left",fontWeight:R?600:400,opacity:re&&!me?.55:1},children:[jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,color:"#111827",flexShrink:0},children:R&&jsx(Check,{style:{width:12,height:12}})}),jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:me?"Switching...":l.name})]},l.id)}),jsx("div",{style:{height:1,background:"#e5e7eb",margin:"4px 0"}}),lt?jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"4px 4px"},children:[jsx("input",{ref:ct,type:"text",value:Le,placeholder:"Container name",disabled:re==="__new__",onChange:l=>Ve(l.target.value),onKeyDown:l=>{l.key==="Enter"?(l.preventDefault(),Jr(Le)):l.key==="Escape"&&(l.preventDefault(),l.stopPropagation(),Be(false),Ve(""));},style:{flex:1,minWidth:0,padding:"5px 8px",border:"1px solid #d1d5db",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",background:"#ffffff",outline:"none"},onFocus:l=>{l.currentTarget.style.borderColor="#1c4587",l.currentTarget.style.boxShadow="0 0 0 2px rgba(28,69,135,0.15)";},onBlur:l=>{l.currentTarget.style.borderColor="#d1d5db",l.currentTarget.style.boxShadow="none";}}),jsx("button",{type:"button",onClick:()=>{Jr(Le);},disabled:!Le.trim()||re==="__new__",title:"Create",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:!Le.trim()||re==="__new__"?"#e5e7eb":"#1c4587",color:!Le.trim()||re==="__new__"?"#9ca3af":"#ffffff",cursor:!Le.trim()||re==="__new__"?"default":"pointer",flexShrink:0},children:re==="__new__"?jsx("span",{style:{width:10,height:10,border:"1.5px solid currentColor",borderTopColor:"transparent",borderRadius:"50%",animation:"__fork-spin 0.7s linear infinite"}}):jsx(Check,{style:{width:12,height:12}})})]}):jsx("button",{type:"button",role:"menuitem",onMouseEnter:()=>Pe(true),onMouseLeave:()=>Pe(false),onClick:()=>{re||(m(null),Ve(""),Be(true));},disabled:!!re,style:{display:"flex",alignItems:"center",width:"100%",padding:"6px 8px",border:"none",background:$t?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:re?"default":"pointer",textAlign:"left",opacity:re&&re!=="__new__"?.55:1},children:"+ New container"}),b&&jsx("div",{style:{padding:"6px 8px",fontSize:11,lineHeight:1.35,color:"#b91c1c"},children:b})]})]}):jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Xr}),e==="running"&&jsx("span",{title:qe?`Estimated ~${qe} min`:"Estimating\u2026",style:{fontSize:10,fontWeight:600,color:qe?"#1c4587":"#9ca3af",backgroundColor:qe?"rgba(28, 69, 135, 0.08)":"rgba(156, 163, 175, 0.12)",padding:"1px 6px",borderRadius:999,flexShrink:0,fontVariantNumeric:"tabular-nums",animation:qe?void 0:"__fork-pulse 1.4s ease-in-out infinite",minWidth:28,textAlign:"center"},children:qe?`~${qe}m`:"~ m"})]}),!I&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[Dr&&jsx("button",{onClick:xe?so:oo,onMouseEnter:()=>C(true),onMouseLeave:()=>C(false),title:xe?"Redock to sidebar":"Pop out into window",style:{padding:6,borderRadius:6,color:P?"#4b5563":"#9ca3af",backgroundColor:P?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:xe?jsx(PictureInPicture,{style:{width:16,height:16}}):jsx(PictureInPicture2,{style:{width:16,height:16}})}),jsx("button",{onClick:qr,onMouseEnter:()=>F(true),onMouseLeave:()=>F(false),style:{padding:6,borderRadius:6,color:c?"#4b5563":"#9ca3af",backgroundColor:c?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:jsx(X,{style:{width:16,height:16}})})]})]}),jsxs("div",{ref:fe,style:{flex:1,overflowY:"auto",minHeight:0,display:"flex",flexDirection:"column"},children:[(Z||ce)&&jsxs("div",{style:{padding:"10px 12px 6px 12px",display:"flex",alignItems:"center",gap:8,borderBottom:"1px solid #f3f4f6"},children:[jsx("button",{onClick:()=>{le(null),oe(false),se.current=false;},style:{fontSize:12,color:"#374151",background:"transparent",border:"none",padding:"2px 4px",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4},title:"Back to all forks",children:"\u2190 All forks"}),(()=>{let R=(Z?ne.find(U=>U.id===Z)?.targetId:null)??nt;return R?jsxs("span",{style:{fontSize:11,color:"#9ca3af",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",flex:1},title:`Forking ${R}`,children:["Forking ",jsx("span",{style:{color:"#6b7280"},children:R})]}):null})()]}),!Z&&!ce&&jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[jsx("div",{style:{padding:"12px 16px 10px 16px",borderBottom:"1px solid #f3f4f6"},children:jsx("span",{style:{fontSize:12,fontWeight:600,color:"#111827"},children:"Forks"})}),ne.length===0&&jsx("div",{style:{padding:"24px 20px",textAlign:"center",fontSize:13,color:"#6b7280"},children:"No forks yet. Describe a feature below to start one."}),ne.length>0&&jsx("div",{style:{display:"flex",flexDirection:"column"},children:ne.map(l=>{let R=l.summary||"Untitled fork";return jsxs("button",{onClick:()=>{oe(false),le(l.id);},style:{textAlign:"left",padding:"10px 16px",background:"#ffffff",border:"none",borderBottom:"1px solid #f3f4f6",cursor:"pointer",display:"flex",flexDirection:"column",gap:2},onMouseEnter:U=>U.currentTarget.style.background="#fafafa",onMouseLeave:U=>U.currentTarget.style.background="#ffffff",children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[jsx("span",{style:{fontSize:13,fontWeight:500,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",flex:1},children:R}),jsx("span",{style:{fontSize:11,color:"#9ca3af",flexShrink:0},children:_s(l.updatedAt)})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:"#6b7280"},children:[jsx("span",{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:l.targetId}),jsx("span",{style:{color:"#d1d5db"},children:"\xB7"}),jsxs("span",{children:[l.promptCount," prompt",l.promptCount===1?"":"s"]}),l.status==="running"||l.status==="building"?jsxs(Fragment,{children:[jsx("span",{style:{color:"#d1d5db"},children:"\xB7"}),jsx("span",{style:{color:"#2563eb"},children:"running"})]}):null]})]},l.id)})})]}),Z&&ut.length>0&&jsx("div",{style:{padding:"16px 16px 0 16px"},children:ut.map((l,R)=>jsx("div",{style:{marginBottom:R<ut.length-1?10:0},children:l.type==="user"?jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8,flexDirection:"row-reverse"},children:[jsx("div",{style:{width:22,height:22,borderRadius:"50%",backgroundColor:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:2},children:jsx(User,{style:{width:13,height:13,color:"#6b7280"}})}),jsx("div",{style:{backgroundColor:"#f3f4f6",borderRadius:"12px 4px 12px 12px",padding:"8px 12px",fontSize:13,color:"#374151",lineHeight:1.5,maxWidth:"75%"},children:l.text})]}):M==="item"&&R===ut.length-1?jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:12,borderRadius:8,border:"1px solid #e4e4e7",background:"#ffffff"},children:[jsx("div",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,flexShrink:0,borderRadius:6,background:"#f4f4f5",color:"#0a0a0a"},children:jsx(BadgeCheck,{style:{width:16,height:16}})}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,flex:1,minWidth:0},children:[jsx("div",{style:{fontSize:13,fontWeight:500,color:"#0a0a0a",lineHeight:1.3},children:"Feature applied"}),jsx("div",{style:{fontSize:13,color:"#71717a",lineHeight:1.4},children:l.text})]}),k&&e!=="running"&&jsx("button",{onClick:U=>{U.stopPropagation(),Vr();},disabled:j,style:{padding:"4px 10px",fontSize:12,fontWeight:500,borderRadius:6,border:"1px solid #e4e4e7",background:"#ffffff",color:"#0a0a0a",cursor:j?"default":"pointer",opacity:j?.4:1,height:28,flexShrink:0},children:"Undo"})]}):jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[jsx("div",{style:{width:22,height:22,borderRadius:"50%",backgroundColor:"#f0fdf4",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:2},children:jsx(Check,{style:{width:13,height:13,color:"#9ca3af"}})}),jsxs("div",{style:{backgroundColor:"#f9fafb",borderRadius:"4px 12px 12px 12px",padding:"8px 12px",fontSize:13,color:"#6b7280",fontWeight:500,display:"flex",alignItems:"center",gap:6,maxWidth:"75%"},children:[jsx("span",{style:{flex:1},children:l.text}),k&&R===ut.length-1&&e!=="running"&&jsxs("button",{onClick:U=>{U.stopPropagation(),Vr();},onMouseEnter:()=>K(R),onMouseLeave:()=>K(null),disabled:j,style:{position:"relative",padding:2,borderRadius:4,border:"none",background:de===R?"rgba(0,0,0,0.06)":"transparent",color:de===R?"#6b7280":"#d1d5db",cursor:j?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s, background 0.15s",opacity:j?.4:1,flexShrink:0},children:[jsx(Undo2,{style:{width:12,height:12}}),de===R&&jsx("span",{style:{position:"absolute",bottom:"calc(100% + 4px)",right:0,fontSize:10,fontWeight:500,color:"#fff",background:"#374151",borderRadius:4,padding:"2px 6px",whiteSpace:"nowrap",pointerEvents:"none",lineHeight:"16px"},children:"Undo"})]})]})]})},R))}),e==="running"&&(Z||ce)&&jsx("div",{style:{padding:16},children:jsxs("div",{onClick:()=>Q(!V),style:{backgroundColor:"#1a1a2e",borderRadius:12,overflow:"hidden",cursor:"pointer",transition:"all 0.3s cubic-bezier(0.22, 1, 0.36, 1)"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#6b7280",strokeWidth:"2.5",strokeLinecap:"round",style:{animation:"__fork-spin 2s linear infinite",flexShrink:0},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsx(Es,{events:r})]}),jsx("div",{style:{color:"#6b7280",flexShrink:0,marginLeft:8,transition:"transform 0.2s ease",transform:V?"rotate(180deg)":"rotate(0deg)"},children:jsx(ChevronDown,{style:{width:14,height:14}})})]}),jsx("div",{style:{maxHeight:V?320:0,opacity:V?1:0,transition:"max-height 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease",overflow:"hidden"},children:jsx("div",{style:{borderTop:"1px solid rgba(255,255,255,0.08)",maxHeight:320,overflowY:"auto"},children:jsx(Sn,{events:r})})})]})}),e==="error"&&(Z||ce)&&jsxs("div",{style:{padding:"20px 16px",textAlign:"center"},children:[jsx("div",{style:{width:36,height:36,backgroundColor:"#fef2f2",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 10px auto"},children:jsx(X,{style:{width:18,height:18,color:"#ef4444"}})}),jsx("p",{style:{fontSize:12,color:"#6b7280",marginBottom:10,maxWidth:260,margin:"0 auto 10px auto"},children:n}),jsxs("button",{onClick:()=>{let l=t?.prompt||Tt.current;l&&u(l,nt);},onMouseEnter:()=>z(true),onMouseLeave:()=>z(false),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 12px",borderRadius:8,fontSize:12,fontWeight:500,color:"#4f46e5",backgroundColor:_?"#e0e7ff":"#eef2ff",border:"none",cursor:"pointer",transition:"background-color 0.15s",fontFamily:"inherit"},children:[jsx(RotateCcw,{style:{width:12,height:12}})," Try Again"]})]})]}),e!=="running"&&jsx("div",{style:{padding:"8px 12px 12px 12px",borderTop:"1px solid rgba(229, 231, 235, 0.6)",flexShrink:0},children:jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,borderRadius:12,padding:"8px 8px 8px 12px",background:"rgba(0, 0, 0, 0.04)",border:"1px solid rgba(0, 0, 0, 0.06)"},children:[jsx("textarea",{ref:Se,value:h,onChange:l=>{v(l.target.value),l.target.style.height="auto",l.target.style.height=Math.min(l.target.scrollHeight,160)+"px";},onKeyDown:l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),zr()),l.key==="Escape"&&!I&&qr();},placeholder:Z?"Iterate on this feature...":"Start building a new Fork...",rows:1,style:{flex:1,backgroundColor:"transparent",fontSize:13,color:"#111827",border:"none",outline:"none",padding:"0 4px 0 0",fontFamily:"inherit",resize:"none",lineHeight:1.5,maxHeight:160,overflow:"auto"}}),jsx("button",{onClick:zr,disabled:!h.trim(),onMouseEnter:()=>y(true),onMouseLeave:()=>y(false),style:{width:26,height:26,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",color:"#ffffff",opacity:h.trim()?1:.25,transform:x&&h.trim()?"scale(1.1)":"scale(1)",background:h.trim()?"#1c4587":"rgba(0,0,0,0.12)",border:"none",cursor:h.trim()?"pointer":"default",flexShrink:0,transition:"transform 0.15s, opacity 0.15s",padding:0},children:jsx(ArrowUp,{style:{width:13,height:13}})})]})})]})]});return I?nr:xe&&J?createPortal(nr,J.document.body):jsx(Cs,{children:nr})}function En(e){if("target"in e&&e.target)return e.target;if("boundaryId"in e&&e.boundaryId)return {type:"boundary",id:e.boundaryId,title:e.title};if("slotId"in e&&e.slotId)return {type:"slot",id:e.slotId,title:e.title??e.slotLabel};throw new Error("Fork chat target requires either target, slotId, or boundaryId.")}function xr(e){let{apiKey:t,userId:r,userHash:n,baseUrl:o,appId:s,previewSession:i,refreshModuleManifest:a,queueBoundaryAnimation:u,trackForkActivity:k,recordForkActivityEvent:g}=he(),[d,w]=useState("idle"),[A,f]=useState(null),[p,I]=useState([]),[M,h]=useState(null),v=useRef(null),T=useCallback(()=>{w("prompting"),I([]),h(null),f(null);},[]),N=useCallback(()=>{w("idle"),v.current&&(v.current.close(),v.current=null);},[]);useEffect(()=>{i&&i.target.kind==="module"&&i.target.id===e&&w(L=>L==="idle"?"prompting":L);},[i?.preview_session_id,i?.target.id,e]);let D=useCallback(async(L,B,S)=>{try{if(!s)throw new Error("ForkProvider requires appId for module boundary prompts.");w("running"),I([]),h(null),f(null);let c;if(i){let C=S?.forkId??i.fork_id??void 0,x=await fetch(`${o}/api/v1/preview/${encodeURIComponent(i.preview_session_id)}/author`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...te()},body:JSON.stringify({prompt:L,...e?{boundary_id:e}:{},...C&&!S?.forceNew?{fork_id:C}:{},...S?.forceNew?{force_new:!0}:{}})});if(!x.ok){let z=await x.json().catch(()=>({}));throw new Error(z.error||`API error: ${x.status}`)}let y=await x.json();y.container_id&&Ge(y.container_id,y.container_name),dt(y.fork_id),c=await(await fetch(`${o}/api/v1/forks/${y.fork_id}`,{headers:{Authorization:`Bearer ${t}`,...te()}})).json();}else if(S?.forkId){let C={prompt:L};r&&(C.userId=r),n&&(C.userHash=n);let x=await fetch(`${o}/api/v1/forks/${encodeURIComponent(S.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(C)});if(!x.ok){let y=await x.json().catch(()=>({}));throw new Error(y.error||`API error: ${x.status}`)}c=await x.json();}else {let C={userId:r,prompt:L,boundaryId:e,appId:s};B&&(C.containerId=B),n&&(C.userHash=n),S?.forceNew&&(C.force_new=!0);let x=await fetch(`${o}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(C)});if(!x.ok){let y=await x.json().catch(()=>({}));throw new Error(y.error||`API error: ${x.status}`)}c=await x.json();}f(c),k(c,{targetKind:"module",targetId:e});let F=new URLSearchParams({key:t});i?(F.set("previewSessionId",i.preview_session_id),F.set("previewForkId",c.id)):r&&F.set("userId",r),n&&F.set("userHash",n);let P=new EventSource(`${o}/api/v1/forks/${c.id}/events?${F.toString()}`);v.current=P,P.onmessage=C=>{try{let x=JSON.parse(C.data);if(g(c.id,x),I(y=>[...y,x]),x.type==="complete"){let y=x.data;u(e,c.id),a().catch(()=>{}).finally(()=>{let _={...c,status:"complete",moduleUrl:y.moduleUrl,cssUrls:y.cssUrls,summary:y.summary,completedAt:new Date().toISOString()};f(_),w("complete"),P.close();});}else if(x.type==="error"){let y=x.data;h(y.error||"Unknown error"),w("error"),P.close();}}catch{}},P.onerror=()=>{let C={Authorization:`Bearer ${t}`,...te()};!i&&r&&(C["X-Fork-User-Id"]=r),!i&&n&&(C["X-Fork-User-Hash"]=n),fetch(`${o}/api/v1/forks/${c.id}`,{headers:C}).then(x=>x.json()).then(x=>{f(x),x.status==="complete"?(u(e,x.id),a().catch(()=>{}),w("complete")):x.status==="error"&&(h(x.error||"Fork generation failed"),w("error"));}).catch(()=>{h("Connection lost"),w("error");}),P.close();};}catch(c){h(c.message),w("error");}},[t,s,o,e,i,u,a,g,k,n,r]),O=useCallback(async L=>{try{let B={Authorization:`Bearer ${t}`,...te()};!i&&r&&(B["X-Fork-User-Id"]=r),!i&&n&&(B["X-Fork-User-Hash"]=n);let S=await fetch(`${o}/api/v1/forks/${L}`,{headers:B});if(!S.ok)return;let c=await S.json(),F=c.boundaryId??e;if(k(c,{targetKind:"module",targetId:F}),c.status==="complete"){w("complete"),f(c),h(null),I([]);return}if(c.status==="error"){w("error"),f(c),h(c.error||"Fork generation failed"),I([]);return}if(c.status!=="pending"&&c.status!=="running"&&c.status!=="building")return;w("running"),f(c),h(null),I([]);let P=new URLSearchParams({key:t});i?(P.set("previewSessionId",i.preview_session_id),P.set("previewForkId",c.id)):r&&P.set("userId",r),n&&P.set("userHash",n);let C=new EventSource(`${o}/api/v1/forks/${c.id}/events?${P.toString()}`);v.current&&v.current.close(),v.current=C,C.onmessage=x=>{try{let y=JSON.parse(x.data);if(g(c.id,y),I(_=>[..._,y]),y.type==="complete"){let _=y.data;u(e,c.id),a().catch(()=>{}).finally(()=>{let z={...c,status:"complete",moduleUrl:_.moduleUrl,cssUrls:_.cssUrls,summary:_.summary,completedAt:new Date().toISOString()};f(z),w("complete"),C.close();});}else if(y.type==="error"){let _=y.data;h(_.error||"Unknown error"),w("error"),C.close();}}catch{}},C.onerror=()=>{C.close();};}catch{}},[t,o,e,i,u,g,a,k,n,r]),E=useCallback(async()=>{try{if(!s)throw new Error("ForkProvider requires appId for boundary undo.");let L={userId:r,boundaryId:e,appId:s};n&&(L.userHash=n);let B=await fetch(`${o}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(L)});if(!B.ok){let c=await B.json().catch(()=>({}));throw new Error(c.error||`API error: ${B.status}`)}let S=await B.json();return await a().catch(()=>{}),S.removed?(f(null),w("prompting")):S.fork&&(f(S.fork),w("complete")),S}catch(L){throw h(L.message),L}},[t,s,o,e,a,n,r]);return {state:d,fork:A,events:p,error:M,open:T,close:N,startFork:D,undoFork:E,adoptRunningFork:O}}var Ms=0;function Pn(e){let{state:t,fork:r,events:n,error:o,open:s,close:i,startFork:a,undoFork:u,adoptRunningFork:k}=xr(e),[g,d]=useState(false),w=useRef(null),A=useRef(t),f=useCallback(()=>{w.current!==null&&(clearTimeout(w.current),w.current=null);},[]),p=useCallback(()=>{f(),d(true),s();},[f,s]),I=useCallback(()=>{f(),d(false),i();},[f,i]),M=useCallback(async h=>{f(),d(true),await k(h);},[k,f]);return useEffect(()=>{let h=A.current;A.current=t,t==="complete"&&h!=="complete"&&g&&(f(),w.current=setTimeout(()=>{w.current=null,d(false),i();},Ms)),(t==="running"||t==="prompting")&&f();},[t,g,f,i]),useEffect(()=>f,[f]),{state:t,fork:r,events:n,error:o,isOpen:g,open:p,close:I,submit:a,undo:u,adoptRunningFork:M}}function Ar(){let{apiKey:e,userId:t,userHash:r,baseUrl:n,previewSession:o,setSlotFork:s,clearSlotFork:i,skipAnimationForSlot:a,trackForkActivity:u,recordForkActivityEvent:k}=he(),[g,d]=useState("idle"),[w,A]=useState(null),[f,p]=useState([]),[I,M]=useState(null),h=useRef(null),v=useCallback(()=>{d("prompting"),p([]),M(null),A(null);},[]),T=useCallback(()=>{d("idle"),h.current&&(h.current.close(),h.current=null);},[]);useEffect(()=>{o&&o.target.kind==="slot"&&d(E=>E==="idle"?"prompting":E);},[o?.preview_session_id,o?.target.kind]);let N=useCallback(async(E,L,B,S)=>{try{d("running"),p([]),M(null),A(null);let c;if(o){let x=S?.forkId??o.fork_id??void 0,y=await fetch(`${n}/api/v1/preview/${encodeURIComponent(o.preview_session_id)}/author`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...te()},body:JSON.stringify({prompt:E,...L?{slot_id:L}:{},...x&&!S?.forceNew?{fork_id:x}:{},...S?.forceNew?{force_new:!0}:{}})});if(!y.ok){let V=await y.json().catch(()=>({}));throw new Error(V.error||`API error: ${y.status}`)}let _=await y.json();_.container_id&&Ge(_.container_id,_.container_name),dt(_.fork_id),c=await(await fetch(`${n}/api/v1/forks/${_.fork_id}`,{headers:{Authorization:`Bearer ${e}`,...te()}})).json();}else if(S?.forkId){let x={prompt:E};t&&(x.userId=t),r&&(x.userHash=r);let y=await fetch(`${n}/api/v1/forks/${encodeURIComponent(S.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(x)});if(!y.ok){let _=await y.json().catch(()=>({}));throw new Error(_.error||`API error: ${y.status}`)}c=await y.json();}else {let x={userId:t,prompt:E};L&&(x.slotId=L),B&&(x.containerId=B),r&&(x.userHash=r),S?.forceNew&&(x.force_new=!0);let y=await fetch(`${n}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(x)});if(!y.ok){let _=await y.json().catch(()=>({}));throw new Error(_.error||`API error: ${y.status}`)}c=await y.json();}A(c);let F=L??c.slotId;F&&u(c,{targetKind:"slot",targetId:F});let P=new URLSearchParams({key:e});o?(P.set("previewSessionId",o.preview_session_id),P.set("previewForkId",c.id)):t&&P.set("userId",t),r&&P.set("userHash",r);let C=new EventSource(`${n}/api/v1/forks/${c.id}/events?${P.toString()}`);h.current=C,C.onmessage=x=>{try{let y=JSON.parse(x.data);if(k(c.id,y),p(_=>[..._,y]),y.type==="complete"){let _=y.data,z={...c,status:"complete",bundleUrl:_.bundleUrl,summary:_.summary,completedAt:new Date().toISOString()};A(z),d("complete"),L&&_.bundleUrl&&s(L,z),C.close();}else if(y.type==="error"){let _=y.data;M(_.error||"Unknown error"),d("error"),C.close();}}catch{}},C.onerror=()=>{let x={Authorization:`Bearer ${e}`,...te()};!o&&t&&(x["X-Fork-User-Id"]=t),!o&&r&&(x["X-Fork-User-Hash"]=r),fetch(`${n}/api/v1/forks/${c.id}`,{headers:x}).then(y=>y.json()).then(y=>{A(y),y.status==="complete"?(d("complete"),L&&y.bundleUrl&&s(L,y)):y.status==="error"&&(M(y.error||"Fork generation failed"),d("error"));}).catch(()=>{M("Connection lost"),d("error");}),C.close();};}catch(c){M(c.message),d("error");}},[e,n,o,k,s,u,r,t]),D=useCallback(async E=>{try{let L={Authorization:`Bearer ${e}`,...te()};!o&&t&&(L["X-Fork-User-Id"]=t),!o&&r&&(L["X-Fork-User-Hash"]=r);let B=await fetch(`${n}/api/v1/forks/${E}`,{headers:L});if(!B.ok)return;let S=await B.json();if(S.slotId&&u(S,{targetKind:"slot",targetId:S.slotId}),S.status==="complete"){d("complete"),A(S),M(null),p([]);return}if(S.status==="error"){d("error"),A(S),M(S.error||"Fork generation failed"),p([]);return}if(S.status!=="pending"&&S.status!=="running"&&S.status!=="building")return;d("running"),A(S),M(null),p([]);let c=new URLSearchParams({key:e});o?(c.set("previewSessionId",o.preview_session_id),c.set("previewForkId",S.id)):t&&c.set("userId",t),r&&c.set("userHash",r);let F=new EventSource(`${n}/api/v1/forks/${S.id}/events?${c.toString()}`);h.current&&h.current.close(),h.current=F;let P=S.slotId;F.onmessage=C=>{try{let x=JSON.parse(C.data);if(k(S.id,x),p(y=>[...y,x]),x.type==="complete"){let y=x.data,_={...S,status:"complete",bundleUrl:y.bundleUrl,summary:y.summary,completedAt:new Date().toISOString()};A(_),d("complete"),P&&y.bundleUrl&&s(P,_),F.close();}else if(x.type==="error"){let y=x.data;M(y.error||"Unknown error"),d("error"),F.close();}}catch{}},F.onerror=()=>{F.close();};}catch{}},[e,n,o,k,s,u,r,t]),O=useCallback(async E=>{try{let L={userId:t,slotId:E};r&&(L.userHash=r);let B=await fetch(`${n}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(L)});if(!B.ok){let c=await B.json().catch(()=>({}));throw new Error(c.error||`API error: ${B.status}`)}let S=await B.json();return a(E),S.removed?(i(E),A(null),d("prompting")):S.fork&&(s(E,S.fork),A(S.fork)),S}catch(L){throw M(L.message),L}},[e,t,r,n,i,s]);return {state:g,fork:w,events:f,error:I,open:v,close:T,startFork:N,undoFork:O,adoptRunningFork:D}}var Us=0;function Ln(){let{state:e,fork:t,events:r,error:n,open:o,close:s,startFork:i,undoFork:a,adoptRunningFork:u}=Ar(),[k,g]=useState(false),d=useRef(null),w=useRef(e),A=useCallback(()=>{d.current!==null&&(clearTimeout(d.current),d.current=null);},[]),f=useCallback(()=>{A(),g(true),o();},[A,o]),p=useCallback(()=>{A(),g(false),s();},[A,s]),I=useCallback(async M=>{A(),g(true),await u(M);},[u,A]);return useEffect(()=>{let M=w.current;w.current=e,e==="complete"&&M!=="complete"&&k&&(A(),d.current=setTimeout(()=>{d.current=null,g(false),s();},Us)),(e==="running"||e==="prompting")&&A();},[e,k,A,s]),useEffect(()=>A,[A]),{state:e,fork:t,events:r,error:n,isOpen:k,open:f,close:p,submit:i,undo:a,adoptRunningFork:I}}var Ns=new Set(["pending","running","building"]);function _r(e){let t=En(e),r=Ln(),n=Pn(t.type==="boundary"?t.id:""),{baseUrl:o,apiKey:s,userId:i,userHash:a,appId:u,activitySummary:k,forkActivities:g,markForkActivitySeen:d}=he(),w=t.type==="slot"?r:n,A=t.type==="slot"?"slot":"boundary",f=t.id,p=t.title,I=t.type==="slot"?"slot":"module",M=g.find(D=>D.targetKind===I&&D.targetId===t.id&&Ns.has(D.status)),h=g.find(D=>D.targetKind===I&&D.targetId===t.id&&D.status==="complete"&&D.unread),v=useCallback(()=>{d();let D=M??h;if(D){w.adoptRunningFork(D.id);return}w.open();},[w,d,M,h]),T=useCallback((D,O,E,L)=>t.type==="slot"?r.submit(D,O??t.id,E,L):n.submit(D,E,L),[n,r,t]),N=useCallback(D=>t.type==="slot"?r.undo(D??t.id):n.undo(),[n,r,t]);return {...w,open:v,target:t,targetId:f,targetLabel:p,historyMode:A,submit:T,undo:N,buttonProps:{onClick:v,hasNotification:k.unreadCompletedCount>0,activity:k},panelProps:{state:w.state,fork:w.fork,events:w.events,error:w.error,...t.type==="slot"?{slotId:f,targetLabel:p,historyMode:A}:{targetId:f,targetLabel:p,historyMode:A},onSubmit:T,onUndo:N,onClose:w.close,baseUrl:o,apiKey:s,userId:i,userHash:a,appId:u}}}function Ft(e){let{embedded:t,completeVariant:r}=e,n=_r(e);return t?jsx(qt,{...n.panelProps,embedded:true,completeVariant:r}):n.isOpen?jsx(qt,{...n.panelProps,completeVariant:r}):jsx(wr,{...n.buttonProps})}function Bs({boundaryId:e,title:t}){return jsx(Ft,{boundaryId:e,title:t})}function Er(e){let t=Array.from(e.children).filter(n=>n instanceof HTMLElement);return t.length===1?t[0]:getComputedStyle(e).display==="contents"?null:e}function Hn(e){let t=e.getBoundingClientRect(),r=e.cloneNode(true);r.setAttribute("data-fork-clone-overlay","true"),r.style.position="fixed",r.style.top=`${t.top}px`,r.style.left=`${t.left}px`,r.style.width=`${t.width}px`,r.style.height=`${t.height}px`,r.style.flex="none",r.style.minHeight="auto",r.style.zIndex="9998",r.style.pointerEvents="none",r.style.overflow="hidden";let n=getComputedStyle(e).backgroundColor;r.style.backgroundColor=n&&n!=="rgba(0, 0, 0, 0)"&&n!=="transparent"?n:getComputedStyle(document.body).backgroundColor||"#ffffff",document.body.appendChild(r);let o=e.querySelectorAll("*"),s=r.querySelectorAll("*");for(let i=0;i<o.length;i+=1)o[i].scrollTop!==0&&(s[i].scrollTop=o[i].scrollTop),o[i].scrollLeft!==0&&(s[i].scrollLeft=o[i].scrollLeft);return r}function Cr(e){let t=[],r=e.querySelectorAll("*");for(let n of r){if(!(n instanceof HTMLElement))continue;let o=n.getBoundingClientRect();if(o.width<10||o.height<10||["SCRIPT","STYLE","META","LINK"].includes(n.tagName))continue;let s=getComputedStyle(n),i=parseFloat(s.borderTopLeftRadius)||0;t.push({tag:n.tagName,className:n.className||"",text:(n.textContent||"").slice(0,50).trim(),rect:o,borderRadius:i});}return t}function On(e,t){let r=[];for(let n of t)if(!(e.find(i=>i.tag===n.tag&&i.className===n.className&&Math.abs(i.rect.top-n.rect.top)<20&&Math.abs(i.rect.left-n.rect.left)<20)||r.some(i=>n.rect.top>=i.rect.top&&n.rect.left>=i.rect.left&&n.rect.right<=i.rect.right&&n.rect.bottom<=i.rect.bottom))){for(let i=r.length-1;i>=0;i-=1){let a=r[i];a.rect.top>=n.rect.top&&a.rect.left>=n.rect.left&&a.rect.right<=n.rect.right&&a.rect.bottom<=n.rect.bottom&&r.splice(i,1);}r.push({rect:n.rect,borderRadius:n.borderRadius});}return r}function Un(e,t){let r=[];for(let n of e)if(!(t.find(i=>i.tag===n.tag&&i.className===n.className&&Math.abs(i.rect.top-n.rect.top)<20&&Math.abs(i.rect.left-n.rect.left)<20)||r.some(i=>n.rect.top>=i.rect.top&&n.rect.left>=i.rect.left&&n.rect.right<=i.rect.right&&n.rect.bottom<=i.rect.bottom))){for(let i=r.length-1;i>=0;i-=1){let a=r[i];a.rect.top>=n.rect.top&&a.rect.left>=n.rect.left&&a.rect.right<=n.rect.right&&a.rect.bottom<=n.rect.bottom&&r.splice(i,1);}r.push({rect:n.rect,borderRadius:n.borderRadius});}return r}function Nn(e,t,r,n,o){let s=Math.max(0,Math.min(o,r/2,n/2));return s===0?`M ${e} ${t} L ${e+r} ${t} L ${e+r} ${t+n} L ${e} ${t+n} Z`:[`M ${e+s} ${t}`,`L ${e+r-s} ${t}`,`A ${s} ${s} 0 0 1 ${e+r} ${t+s}`,`L ${e+r} ${t+n-s}`,`A ${s} ${s} 0 0 1 ${e+r-s} ${t+n}`,`L ${e+s} ${t+n}`,`A ${s} ${s} 0 0 1 ${e} ${t+n-s}`,`L ${e} ${t+s}`,`A ${s} ${s} 0 0 1 ${e+s} ${t}`,"Z"].join(" ")}function $r(e){let t="http://www.w3.org/2000/svg",r=document.createElement("div");r.setAttribute("data-fork-highlights","true"),r.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let n=document.createElementNS(t,"svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs");n.appendChild(o);let s=[];for(let g=0;g<e.length;g+=1){let{rect:d,borderRadius:w}=e[g],A=d.left-.5,f=d.top-.5,p=d.width+1,I=d.height+1,M=Math.min(w+.5,p/2,I/2),h=Nn(A,f,p,I,M),v=`__fork-glow-${g}`,T=document.createElementNS(t,"filter");T.setAttribute("id",v),T.setAttribute("x","-100%"),T.setAttribute("y","-100%"),T.setAttribute("width","300%"),T.setAttribute("height","300%");let N=document.createElementNS(t,"feGaussianBlur");N.setAttribute("in","SourceGraphic"),N.setAttribute("stdDeviation","8"),T.appendChild(N),o.appendChild(T);let D=`__fork-mask-${g}`,O=document.createElementNS(t,"mask");O.setAttribute("id",D),O.setAttribute("maskUnits","userSpaceOnUse"),O.setAttribute("x",String(A-200)),O.setAttribute("y",String(f-200)),O.setAttribute("width",String(p+400)),O.setAttribute("height",String(I+400));let E=document.createElementNS(t,"rect");E.setAttribute("x",String(A-200)),E.setAttribute("y",String(f-200)),E.setAttribute("width",String(p+400)),E.setAttribute("height",String(I+400)),E.setAttribute("fill","white"),O.appendChild(E);let L=document.createElementNS(t,"path");L.setAttribute("d",h),L.setAttribute("fill","black"),O.appendChild(L),o.appendChild(O);let B=document.createElementNS(t,"g");B.setAttribute("mask",`url(#${D})`),B.setAttribute("opacity","0");let S=document.createElementNS(t,"g");S.setAttribute("filter",`url(#${v})`);let c=document.createElementNS(t,"path");c.setAttribute("d",h),c.setAttribute("fill","none"),c.setAttribute("stroke","rgba(150, 185, 220, 0.6)"),c.setAttribute("stroke-width","6"),c.setAttribute("stroke-linecap","round"),S.appendChild(c),B.appendChild(S),n.appendChild(B);let F=document.createElementNS(t,"path");F.setAttribute("d",h),F.setAttribute("fill","none"),F.setAttribute("stroke","rgba(150, 185, 220, 0.35)"),F.setAttribute("stroke-width","2"),F.setAttribute("stroke-linecap","round"),F.setAttribute("opacity","0"),n.appendChild(F),s.push(c,F),c.__group=B;}r.appendChild(n),document.body.appendChild(r);let i=[];for(let g=0;g<s.length;g+=2){let d=s[g],w=s[g+1],A=d.__group;if(!A)continue;let f=w.getTotalLength(),p=d.getTotalLength();if(f<=0)continue;let I=f*.35;w.setAttribute("stroke-dasharray",`${I} ${f-I}`),w.setAttribute("stroke-dashoffset","0"),i.push(w.animate([{strokeDashoffset:0,opacity:0,offset:0},{strokeDashoffset:-0.2*f,opacity:.92,offset:.06},{strokeDashoffset:-2*f,opacity:.92,offset:.92},{strokeDashoffset:-2.25*f,opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));let M=p*.35;d.setAttribute("stroke-dasharray",`${M} ${p-M}`),d.setAttribute("stroke-dashoffset","0"),i.push(d.animate([{strokeDashoffset:0,offset:0},{strokeDashoffset:-0.2*p,offset:.06},{strokeDashoffset:-2*p,offset:.92},{strokeDashoffset:-2.25*p,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"})),i.push(A.animate([{opacity:0,offset:0},{opacity:.92,offset:.06},{opacity:.92,offset:.92},{opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));}let a=false,u=()=>{if(a)return;a=true,clearTimeout(k);for(let d of i)try{d.cancel();}catch{}let g=r.animate([{opacity:1},{opacity:0}],{duration:400,fill:"forwards"});g.onfinish=()=>r.remove(),window.removeEventListener("click",u);},k=setTimeout(u,14500);return setTimeout(()=>{a||window.addEventListener("click",u);},500),u}function Bn(e){let t="http://www.w3.org/2000/svg",r=document.createElement("div");r.setAttribute("data-fork-removed","true"),r.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let n=document.createElementNS(t,"svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs"),s=document.createElementNS(t,"filter");s.setAttribute("id","__fork-removed-shadow"),s.setAttribute("x","-10%"),s.setAttribute("y","-10%"),s.setAttribute("width","120%"),s.setAttribute("height","120%");let i=document.createElementNS(t,"feDropShadow");i.setAttribute("dx","0"),i.setAttribute("dy","1"),i.setAttribute("stdDeviation","2"),i.setAttribute("flood-color","rgba(0,0,0,0.15)"),s.appendChild(i),o.appendChild(s),n.appendChild(o);for(let{rect:a,borderRadius:u}of e){let k=document.createElementNS(t,"path");k.setAttribute("d",Nn(a.left,a.top,a.width,a.height,u)),k.setAttribute("fill","none"),k.setAttribute("stroke","rgba(120, 125, 135, 0.6)"),k.setAttribute("stroke-width","1.5"),k.setAttribute("stroke-dasharray","8 4"),k.setAttribute("stroke-linecap","round"),k.setAttribute("filter","url(#__fork-removed-shadow)"),k.setAttribute("opacity","0"),n.appendChild(k),k.animate([{opacity:0,offset:0},{opacity:.6,offset:.08},{opacity:.05,offset:.45},{opacity:.6,offset:.85},{opacity:.05,offset:1}],{duration:5e3,easing:"ease-in-out",fill:"forwards"});}return r.appendChild(n),document.body.appendChild(r),r}function Kn(e,t){if(js(t.selector))return jn(e,t);let n=jn(e,t);if(n)return n;try{let s=document.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e&&e.contains(s))return s}catch{}if(Dn(t.selector))try{let s=e.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e)return s}catch{}if(t.textHint){let s=t.textHint.trim();if(s){let i=Tr(e,g=>g===s);if(i)return i;let a=s.toLowerCase(),u=Tr(e,g=>g.toLowerCase()===a);if(u)return u;let k=Tr(e,g=>g.toLowerCase().includes(a));if(k)return k}}let o=Ks(t.selector);if(o&&o!==t.selector&&Dn(o))try{let s=e.querySelector(o);if(s instanceof HTMLElement&&s!==e)return s}catch{}return null}function Dn(e){let t=e.split(/\s+|>|~|\+/),r=t[t.length-1]??"";return /[#\[]|:not\(|:nth-/.test(r)}function jn(e,t){let r=Array.from(e.querySelectorAll("[data-fork-new]"));if(r.length===0)return null;let n=Pr(t.label),o=Pr(t.textHint);return r.find(i=>{let a=Pr(i.getAttribute("data-fork-new"));return !!a&&(a===n||a===o)})??null}function js(e){return e.trim()==="[data-fork-new]"}function Pr(e){return e?.trim().replace(/\s+/g," ").toLowerCase()||null}function Ks(e){return e.replace(/\[class[\*~|^$]?=("[^"]*"|'[^']*'|[^\]]+)\]/g,"").replace(/\.[A-Za-z_][\w-]*/g,"").replace(/\s+/g," ").trim()}function Tr(e,t){let r=null,n=1/0,o=e.querySelectorAll("*");for(let s of o){let i=s.textContent?.trim();if(!i||!t(i))continue;let a=s.getBoundingClientRect();if(a.width<4||a.height<4)continue;let u=a.width*a.height;u<n&&(r=s,n=u);}return r}var Mr=2147483600,zs=1600,Ws=3e4,Js=300,Ke=10;function Vs(e){let r=getComputedStyle(e).borderTopLeftRadius;if(!r)return 4;if(r.endsWith("%")){let i=parseFloat(r);if(!Number.isFinite(i)||i<=0)return 4;let a=e.getBoundingClientRect(),u=Math.min(a.width,a.height);return Math.max(4,i/100*u)}let n=parseFloat(r);if(!Number.isFinite(n)||n<=0)return 4;let o=e.getBoundingClientRect(),s=Math.min(o.width,o.height)/2;return n>=s?s:Math.min(n,16)}function qs(e,t,r,n){let s=window.innerWidth,i=window.innerHeight,a=e;a==="top"&&t.top<n+Ke+8?a="bottom":a==="bottom"&&i-t.bottom<n+Ke+8?a="top":a==="left"&&t.left<r+Ke+8?a="right":a==="right"&&s-t.right<r+Ke+8&&(a="left");let u=0,k=0;return a==="top"?(u=t.top-n-Ke,k=t.left+t.width/2-r/2):a==="bottom"?(u=t.bottom+Ke,k=t.left+t.width/2-r/2):a==="left"?(u=t.top+t.height/2-n/2,k=t.left-r-Ke):(u=t.top+t.height/2-n/2,k=t.right+Ke),k=Math.max(8,Math.min(k,s-r-8)),u=Math.max(8,Math.min(u,i-n-8)),{top:u,left:k,placement:a}}function Xs(e){let t=document.createElement("div");t.setAttribute("data-fork-highlight-outline","true"),t.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr}`,"border:1.5px solid rgba(59,130,246,0.85)","box-sizing:border-box","opacity:0","transition:opacity 200ms ease-out"].join(";");let r=document.createElement("div");r.setAttribute("data-fork-highlight-glow","true"),r.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr-1}`,"box-sizing:border-box","border:1px solid rgba(59,130,246,0.36)","box-shadow:0 0 0 4px rgba(59,130,246,0.16), 0 0 18px 2px rgba(59,130,246,0.31)","opacity:0","transition:opacity 200ms ease-out"].join(";");let n=document.createElement("div");return n.setAttribute("data-fork-highlight-tooltip","true"),n.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr+1}`,"padding:6px 10px","font:500 12px/1.2 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif","color:#ffffff","background:linear-gradient(135deg,#64748b,#475569)","border-radius:999px","box-shadow:0 4px 14px rgba(71,85,105,0.31),0 1px 2px rgba(0,0,0,0.1)","white-space:nowrap","opacity:0","transform:translateY(-2px)","transition:opacity 200ms ease-out, transform 200ms ease-out"].join(";"),n.textContent=`New: ${e}`,{outline:t,glow:r,tooltip:n}}function Gs(){if(document.getElementById("__fork-highlight-keyframes"))return;let e=document.createElement("style");e.id="__fork-highlight-keyframes",e.textContent=`
|
|
59
|
+
`}),jsxs("div",{className:"__fork-panel",style:co,children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid rgba(229, 231, 235, 0.8)",flexShrink:0},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flex:1},children:[jsx("span",{onDoubleClick:async l=>{if(l.stopPropagation(),!G&&confirm("Kill all forks in this container?")){we(true);try{let R=await Fe();`${R?.deleted??0}`,ue([]),le(null),oe(!1),v("");}catch(R){console.error("[Fork] Reset failed:",R);}finally{we(false);}}},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:4,margin:-4,cursor:"pointer",flexShrink:0},children:jsx(zt,{style:{width:16,height:16,color:"#1c4587",pointerEvents:"none"}})}),e==="running"?jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:ao}):ve.length===0&&!rt?jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:"Fork"}):rt?jsxs("div",{ref:Lt,style:{position:"relative",minWidth:0,display:"inline-flex"},children:[jsxs("button",{type:"button",onClick:()=>{Je(l=>!l);},onMouseEnter:()=>at(true),onMouseLeave:()=>at(false),"aria-haspopup":"menu","aria-expanded":$e,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 6px",border:"1px solid transparent",borderRadius:6,background:tr||$e?"#f3f4f6":"transparent",fontSize:13,fontWeight:600,color:"#111827",fontFamily:"inherit",cursor:"pointer",maxWidth:180,minWidth:0,transition:"background-color 0.12s"},children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Xr}),jsx(ChevronDown,{style:{width:12,height:12,color:"#6b7280",flexShrink:0,transform:$e?"rotate(180deg)":void 0,transition:"transform 0.15s"}})]}),$e&&jsxs("div",{role:"menu",style:{position:"absolute",top:"calc(100% + 4px)",left:0,minWidth:200,maxWidth:260,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06)",padding:4,zIndex:2147483001},children:[ve.map(l=>{let R=l.id===ye,U=Et===l.id,me=re===l.id;return jsxs("button",{type:"button",role:"menuitem",onMouseEnter:()=>Ct(l.id),onMouseLeave:()=>Ct(null),onClick:()=>{l.id!==ye&&lo(l.id);},disabled:!!re,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 8px",border:"none",background:U?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:re?"default":"pointer",textAlign:"left",fontWeight:R?600:400,opacity:re&&!me?.55:1},children:[jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,color:"#111827",flexShrink:0},children:R&&jsx(Check,{style:{width:12,height:12}})}),jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:me?"Switching...":l.name})]},l.id)}),jsx("div",{style:{height:1,background:"#e5e7eb",margin:"4px 0"}}),lt?jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"4px 4px"},children:[jsx("input",{ref:ct,type:"text",value:Le,placeholder:"Container name",disabled:re==="__new__",onChange:l=>Ve(l.target.value),onKeyDown:l=>{l.key==="Enter"?(l.preventDefault(),Jr(Le)):l.key==="Escape"&&(l.preventDefault(),l.stopPropagation(),Be(false),Ve(""));},style:{flex:1,minWidth:0,padding:"5px 8px",border:"1px solid #d1d5db",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",background:"#ffffff",outline:"none"},onFocus:l=>{l.currentTarget.style.borderColor="#1c4587",l.currentTarget.style.boxShadow="0 0 0 2px rgba(28,69,135,0.15)";},onBlur:l=>{l.currentTarget.style.borderColor="#d1d5db",l.currentTarget.style.boxShadow="none";}}),jsx("button",{type:"button",onClick:()=>{Jr(Le);},disabled:!Le.trim()||re==="__new__",title:"Create",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:!Le.trim()||re==="__new__"?"#e5e7eb":"#1c4587",color:!Le.trim()||re==="__new__"?"#9ca3af":"#ffffff",cursor:!Le.trim()||re==="__new__"?"default":"pointer",flexShrink:0},children:re==="__new__"?jsx("span",{style:{width:10,height:10,border:"1.5px solid currentColor",borderTopColor:"transparent",borderRadius:"50%",animation:"__fork-spin 0.7s linear infinite"}}):jsx(Check,{style:{width:12,height:12}})})]}):jsx("button",{type:"button",role:"menuitem",onMouseEnter:()=>Pe(true),onMouseLeave:()=>Pe(false),onClick:()=>{re||(m(null),Ve(""),Be(true));},disabled:!!re,style:{display:"flex",alignItems:"center",width:"100%",padding:"6px 8px",border:"none",background:$t?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:re?"default":"pointer",textAlign:"left",opacity:re&&re!=="__new__"?.55:1},children:"+ New container"}),b&&jsx("div",{style:{padding:"6px 8px",fontSize:11,lineHeight:1.35,color:"#b91c1c"},children:b})]})]}):jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Xr}),e==="running"&&jsx("span",{title:qe?`Estimated ~${qe} min`:"Estimating\u2026",style:{fontSize:10,fontWeight:600,color:qe?"#1c4587":"#9ca3af",backgroundColor:qe?"rgba(28, 69, 135, 0.08)":"rgba(156, 163, 175, 0.12)",padding:"1px 6px",borderRadius:999,flexShrink:0,fontVariantNumeric:"tabular-nums",animation:qe?void 0:"__fork-pulse 1.4s ease-in-out infinite",minWidth:28,textAlign:"center"},children:qe?`~${qe}m`:"~ m"})]}),!I&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[Dr&&jsx("button",{onClick:xe?so:oo,onMouseEnter:()=>C(true),onMouseLeave:()=>C(false),title:xe?"Redock to sidebar":"Pop out into window",style:{padding:6,borderRadius:6,color:P?"#4b5563":"#9ca3af",backgroundColor:P?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:xe?jsx(PictureInPicture,{style:{width:16,height:16}}):jsx(PictureInPicture2,{style:{width:16,height:16}})}),jsx("button",{onClick:qr,onMouseEnter:()=>F(true),onMouseLeave:()=>F(false),style:{padding:6,borderRadius:6,color:c?"#4b5563":"#9ca3af",backgroundColor:c?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:jsx(X,{style:{width:16,height:16}})})]})]}),jsxs("div",{ref:fe,style:{flex:1,overflowY:"auto",minHeight:0,display:"flex",flexDirection:"column"},children:[(Z||ce)&&jsxs("div",{style:{padding:"10px 12px 6px 12px",display:"flex",alignItems:"center",gap:8,borderBottom:"1px solid #f3f4f6"},children:[jsx("button",{onClick:()=>{le(null),oe(false),se.current=false;},style:{fontSize:12,color:"#374151",background:"transparent",border:"none",padding:"2px 4px",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4},title:"Back to all forks",children:"\u2190 All forks"}),(()=>{let R=(Z?ne.find(U=>U.id===Z)?.targetId:null)??nt;return R?jsxs("span",{style:{fontSize:11,color:"#9ca3af",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",flex:1},title:`Forking ${R}`,children:["Forking ",jsx("span",{style:{color:"#6b7280"},children:R})]}):null})()]}),!Z&&!ce&&jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[jsx("div",{style:{padding:"12px 16px 10px 16px",borderBottom:"1px solid #f3f4f6"},children:jsx("span",{style:{fontSize:12,fontWeight:600,color:"#111827"},children:"Forks"})}),ne.length===0&&jsx("div",{style:{padding:"24px 20px",textAlign:"center",fontSize:13,color:"#6b7280"},children:"No forks yet. Describe a feature below to start one."}),ne.length>0&&jsx("div",{style:{display:"flex",flexDirection:"column"},children:ne.map(l=>{let R=l.summary||"Untitled fork";return jsxs("button",{onClick:()=>{oe(false),le(l.id);},style:{textAlign:"left",padding:"10px 16px",background:"#ffffff",border:"none",borderBottom:"1px solid #f3f4f6",cursor:"pointer",display:"flex",flexDirection:"column",gap:2},onMouseEnter:U=>U.currentTarget.style.background="#fafafa",onMouseLeave:U=>U.currentTarget.style.background="#ffffff",children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[jsx("span",{style:{fontSize:13,fontWeight:500,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",flex:1},children:R}),jsx("span",{style:{fontSize:11,color:"#9ca3af",flexShrink:0},children:_s(l.updatedAt)})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:"#6b7280"},children:[jsx("span",{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:l.targetId}),jsx("span",{style:{color:"#d1d5db"},children:"\xB7"}),jsxs("span",{children:[l.promptCount," prompt",l.promptCount===1?"":"s"]}),l.status==="running"||l.status==="building"?jsxs(Fragment,{children:[jsx("span",{style:{color:"#d1d5db"},children:"\xB7"}),jsx("span",{style:{color:"#2563eb"},children:"running"})]}):null]})]},l.id)})})]}),Z&&ut.length>0&&jsx("div",{style:{padding:"16px 16px 0 16px"},children:ut.map((l,R)=>jsx("div",{style:{marginBottom:R<ut.length-1?10:0},children:l.type==="user"?jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8,flexDirection:"row-reverse"},children:[jsx("div",{style:{width:22,height:22,borderRadius:"50%",backgroundColor:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:2},children:jsx(User,{style:{width:13,height:13,color:"#6b7280"}})}),jsx("div",{style:{backgroundColor:"#f3f4f6",borderRadius:"12px 4px 12px 12px",padding:"8px 12px",fontSize:13,color:"#374151",lineHeight:1.5,maxWidth:"75%"},children:l.text})]}):M==="item"&&R===ut.length-1?jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:12,borderRadius:8,border:"1px solid #e4e4e7",background:"#ffffff"},children:[jsx("div",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,flexShrink:0,borderRadius:6,background:"#f4f4f5",color:"#0a0a0a"},children:jsx(BadgeCheck,{style:{width:16,height:16}})}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,flex:1,minWidth:0},children:[jsx("div",{style:{fontSize:13,fontWeight:500,color:"#0a0a0a",lineHeight:1.3},children:"Feature applied"}),jsx("div",{style:{fontSize:13,color:"#71717a",lineHeight:1.4},children:l.text})]}),k&&e!=="running"&&jsx("button",{onClick:U=>{U.stopPropagation(),Vr();},disabled:j,style:{padding:"4px 10px",fontSize:12,fontWeight:500,borderRadius:6,border:"1px solid #e4e4e7",background:"#ffffff",color:"#0a0a0a",cursor:j?"default":"pointer",opacity:j?.4:1,height:28,flexShrink:0},children:"Undo"})]}):jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[jsx("div",{style:{width:22,height:22,borderRadius:"50%",backgroundColor:"#f0fdf4",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,marginTop:2},children:jsx(Check,{style:{width:13,height:13,color:"#9ca3af"}})}),jsxs("div",{style:{backgroundColor:"#f9fafb",borderRadius:"4px 12px 12px 12px",padding:"8px 12px",fontSize:13,color:"#6b7280",fontWeight:500,display:"flex",alignItems:"center",gap:6,maxWidth:"75%"},children:[jsx("span",{style:{flex:1},children:l.text}),k&&R===ut.length-1&&e!=="running"&&jsxs("button",{onClick:U=>{U.stopPropagation(),Vr();},onMouseEnter:()=>K(R),onMouseLeave:()=>K(null),disabled:j,style:{position:"relative",padding:2,borderRadius:4,border:"none",background:de===R?"rgba(0,0,0,0.06)":"transparent",color:de===R?"#6b7280":"#d1d5db",cursor:j?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s, background 0.15s",opacity:j?.4:1,flexShrink:0},children:[jsx(Undo2,{style:{width:12,height:12}}),de===R&&jsx("span",{style:{position:"absolute",bottom:"calc(100% + 4px)",right:0,fontSize:10,fontWeight:500,color:"#fff",background:"#374151",borderRadius:4,padding:"2px 6px",whiteSpace:"nowrap",pointerEvents:"none",lineHeight:"16px"},children:"Undo"})]})]})]})},R))}),e==="running"&&(Z||ce)&&jsx("div",{style:{padding:16},children:jsxs("div",{onClick:()=>Q(!V),style:{backgroundColor:"#1a1a2e",borderRadius:12,overflow:"hidden",cursor:"pointer",transition:"all 0.3s cubic-bezier(0.22, 1, 0.36, 1)"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#6b7280",strokeWidth:"2.5",strokeLinecap:"round",style:{animation:"__fork-spin 2s linear infinite",flexShrink:0},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsx(Es,{events:r})]}),jsx("div",{style:{color:"#6b7280",flexShrink:0,marginLeft:8,transition:"transform 0.2s ease",transform:V?"rotate(180deg)":"rotate(0deg)"},children:jsx(ChevronDown,{style:{width:14,height:14}})})]}),jsx("div",{style:{maxHeight:V?320:0,opacity:V?1:0,transition:"max-height 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease",overflow:"hidden"},children:jsx("div",{style:{borderTop:"1px solid rgba(255,255,255,0.08)",maxHeight:320,overflowY:"auto"},children:jsx(Sn,{events:r})})})]})}),e==="error"&&(Z||ce)&&jsxs("div",{style:{padding:"20px 16px",textAlign:"center"},children:[jsx("div",{style:{width:36,height:36,backgroundColor:"#fef2f2",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 10px auto"},children:jsx(X,{style:{width:18,height:18,color:"#ef4444"}})}),jsx("p",{style:{fontSize:12,color:"#6b7280",marginBottom:10,maxWidth:260,margin:"0 auto 10px auto"},children:n}),jsxs("button",{onClick:()=>{let l=t?.prompt||Tt.current;l&&u(l,nt);},onMouseEnter:()=>z(true),onMouseLeave:()=>z(false),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 12px",borderRadius:8,fontSize:12,fontWeight:500,color:"#4f46e5",backgroundColor:_?"#e0e7ff":"#eef2ff",border:"none",cursor:"pointer",transition:"background-color 0.15s",fontFamily:"inherit"},children:[jsx(RotateCcw,{style:{width:12,height:12}})," Try Again"]})]})]}),e!=="running"&&jsx("div",{style:{padding:"8px 12px 12px 12px",borderTop:"1px solid rgba(229, 231, 235, 0.6)",flexShrink:0},children:jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,borderRadius:12,padding:"8px 8px 8px 12px",background:"rgba(0, 0, 0, 0.04)",border:"1px solid rgba(0, 0, 0, 0.06)"},children:[jsx("textarea",{ref:Se,value:h,onChange:l=>{v(l.target.value),l.target.style.height="auto",l.target.style.height=Math.min(l.target.scrollHeight,160)+"px";},onKeyDown:l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),zr()),l.key==="Escape"&&!I&&qr();},placeholder:Z?"Iterate on this feature...":"Start building a new Fork...",rows:1,style:{flex:1,backgroundColor:"transparent",fontSize:13,color:"#111827",border:"none",outline:"none",padding:"0 4px 0 0",fontFamily:"inherit",resize:"none",lineHeight:1.5,maxHeight:160,overflow:"auto"}}),jsx("button",{onClick:zr,disabled:!h.trim(),onMouseEnter:()=>y(true),onMouseLeave:()=>y(false),style:{width:26,height:26,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",color:"#ffffff",opacity:h.trim()?1:.25,transform:x&&h.trim()?"scale(1.1)":"scale(1)",background:h.trim()?"#1c4587":"rgba(0,0,0,0.12)",border:"none",cursor:h.trim()?"pointer":"default",flexShrink:0,transition:"transform 0.15s, opacity 0.15s",padding:0},children:jsx(ArrowUp,{style:{width:13,height:13}})})]})})]})]});return I?nr:xe&&J?createPortal(nr,J.document.body):jsx(Cs,{children:nr})}function En(e){if("target"in e&&e.target)return e.target;if("boundaryId"in e&&e.boundaryId)return {type:"boundary",id:e.boundaryId,title:e.title};if("slotId"in e&&e.slotId)return {type:"slot",id:e.slotId,title:e.title??e.slotLabel};throw new Error("Fork chat target requires either target, slotId, or boundaryId.")}function xr(e){let{apiKey:t,userId:r,userHash:n,baseUrl:o,appId:s,previewSession:i,refreshModuleManifest:a,queueBoundaryAnimation:u,trackForkActivity:k,recordForkActivityEvent:g}=he(),[d,w]=useState("idle"),[A,f]=useState(null),[p,I]=useState([]),[M,h]=useState(null),v=useRef(null),T=useCallback(()=>{w("prompting"),I([]),h(null),f(null);},[]),N=useCallback(()=>{w("idle"),v.current&&(v.current.close(),v.current=null);},[]);useEffect(()=>{i&&i.target.kind==="module"&&i.target.id===e&&w(L=>L==="idle"?"prompting":L);},[i?.preview_session_id,i?.target.id,e]);let D=useCallback(async(L,B,S)=>{try{if(!s)throw new Error("ForkProvider requires appId for module boundary prompts.");w("running"),I([]),h(null),f(null);let c;if(i){let C=S?.forkId??i.fork_id??void 0,x=await fetch(`${o}/api/v1/preview/${encodeURIComponent(i.preview_session_id)}/author`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...te()},body:JSON.stringify({prompt:L,...e?{boundary_id:e}:{},...C&&!S?.forceNew?{fork_id:C}:{},...S?.forceNew?{force_new:!0}:{}})});if(!x.ok){let z=await x.json().catch(()=>({}));throw new Error(z.error||`API error: ${x.status}`)}let y=await x.json();y.container_id&&Ge(y.container_id,y.container_name),dt(y.fork_id),c=await(await fetch(`${o}/api/v1/forks/${y.fork_id}`,{headers:{Authorization:`Bearer ${t}`,...te()}})).json();}else if(S?.forkId){let C={prompt:L};r&&(C.userId=r),n&&(C.userHash=n);let x=await fetch(`${o}/api/v1/forks/${encodeURIComponent(S.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(C)});if(!x.ok){let y=await x.json().catch(()=>({}));throw new Error(y.error||`API error: ${x.status}`)}c=await x.json();}else {let C={userId:r,prompt:L,boundaryId:e,appId:s};B&&(C.containerId=B),n&&(C.userHash=n),S?.forceNew&&(C.force_new=!0);let x=await fetch(`${o}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(C)});if(!x.ok){let y=await x.json().catch(()=>({}));throw new Error(y.error||`API error: ${x.status}`)}c=await x.json();}f(c),k(c,{targetKind:"module",targetId:e});let F=new URLSearchParams({key:t});i?(F.set("previewSessionId",i.preview_session_id),F.set("previewForkId",c.id)):r&&F.set("userId",r),n&&F.set("userHash",n);let P=new EventSource(`${o}/api/v1/forks/${c.id}/events?${F.toString()}`);v.current=P,P.onmessage=C=>{try{let x=JSON.parse(C.data);if(g(c.id,x),I(y=>[...y,x]),x.type==="complete"){let y=x.data;u(e,c.id),a().catch(()=>{}).finally(()=>{let _={...c,status:"complete",moduleUrl:y.moduleUrl,cssUrls:y.cssUrls,summary:y.summary,completedAt:new Date().toISOString()};f(_),w("complete"),P.close();});}else if(x.type==="error"){let y=x.data;h(y.error||"Unknown error"),w("error"),P.close();}}catch{}},P.onerror=()=>{let C={Authorization:`Bearer ${t}`,...te()};!i&&r&&(C["X-Fork-User-Id"]=r),!i&&n&&(C["X-Fork-User-Hash"]=n),fetch(`${o}/api/v1/forks/${c.id}`,{headers:C}).then(x=>x.json()).then(x=>{f(x),x.status==="complete"?(u(e,x.id),a().catch(()=>{}),w("complete")):x.status==="error"&&(h(x.error||"Fork generation failed"),w("error"));}).catch(()=>{h("Connection lost"),w("error");}),P.close();};}catch(c){h(c.message),w("error");}},[t,s,o,e,i,u,a,g,k,n,r]),O=useCallback(async L=>{try{let B={Authorization:`Bearer ${t}`,...te()};!i&&r&&(B["X-Fork-User-Id"]=r),!i&&n&&(B["X-Fork-User-Hash"]=n);let S=await fetch(`${o}/api/v1/forks/${L}`,{headers:B});if(!S.ok)return;let c=await S.json(),F=c.boundaryId??e;if(k(c,{targetKind:"module",targetId:F}),c.status==="complete"){w("complete"),f(c),h(null),I([]);return}if(c.status==="error"){w("error"),f(c),h(c.error||"Fork generation failed"),I([]);return}if(c.status!=="pending"&&c.status!=="running"&&c.status!=="building")return;w("running"),f(c),h(null),I([]);let P=new URLSearchParams({key:t});i?(P.set("previewSessionId",i.preview_session_id),P.set("previewForkId",c.id)):r&&P.set("userId",r),n&&P.set("userHash",n);let C=new EventSource(`${o}/api/v1/forks/${c.id}/events?${P.toString()}`);v.current&&v.current.close(),v.current=C,C.onmessage=x=>{try{let y=JSON.parse(x.data);if(g(c.id,y),I(_=>[..._,y]),y.type==="complete"){let _=y.data;u(e,c.id),a().catch(()=>{}).finally(()=>{let z={...c,status:"complete",moduleUrl:_.moduleUrl,cssUrls:_.cssUrls,summary:_.summary,completedAt:new Date().toISOString()};f(z),w("complete"),C.close();});}else if(y.type==="error"){let _=y.data;h(_.error||"Unknown error"),w("error"),C.close();}}catch{}},C.onerror=()=>{C.close();};}catch{}},[t,o,e,i,u,g,a,k,n,r]),E=useCallback(async()=>{try{if(!s)throw new Error("ForkProvider requires appId for boundary undo.");let L={userId:r,boundaryId:e,appId:s};n&&(L.userHash=n);let B=await fetch(`${o}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(L)});if(!B.ok){let c=await B.json().catch(()=>({}));throw new Error(c.error||`API error: ${B.status}`)}let S=await B.json();return await a().catch(()=>{}),S.removed?(f(null),w("prompting")):S.fork&&(f(S.fork),w("complete")),S}catch(L){throw h(L.message),L}},[t,s,o,e,a,n,r]);return {state:d,fork:A,events:p,error:M,open:T,close:N,startFork:D,undoFork:E,adoptRunningFork:O}}var Ms=0;function Pn(e){let{state:t,fork:r,events:n,error:o,open:s,close:i,startFork:a,undoFork:u,adoptRunningFork:k}=xr(e),[g,d]=useState(false),w=useRef(null),A=useRef(t),f=useCallback(()=>{w.current!==null&&(clearTimeout(w.current),w.current=null);},[]),p=useCallback(()=>{f(),d(true),s();},[f,s]),I=useCallback(()=>{f(),d(false),i();},[f,i]),M=useCallback(async h=>{f(),d(true),await k(h);},[k,f]);return useEffect(()=>{let h=A.current;A.current=t,t==="complete"&&h==="running"&&g&&(f(),w.current=setTimeout(()=>{w.current=null,d(false),i();},Ms)),(t==="running"||t==="prompting")&&f();},[t,g,f,i]),useEffect(()=>f,[f]),{state:t,fork:r,events:n,error:o,isOpen:g,open:p,close:I,submit:a,undo:u,adoptRunningFork:M}}function Ar(){let{apiKey:e,userId:t,userHash:r,baseUrl:n,previewSession:o,setSlotFork:s,clearSlotFork:i,skipAnimationForSlot:a,trackForkActivity:u,recordForkActivityEvent:k}=he(),[g,d]=useState("idle"),[w,A]=useState(null),[f,p]=useState([]),[I,M]=useState(null),h=useRef(null),v=useCallback(()=>{d("prompting"),p([]),M(null),A(null);},[]),T=useCallback(()=>{d("idle"),h.current&&(h.current.close(),h.current=null);},[]);useEffect(()=>{o&&o.target.kind==="slot"&&d(E=>E==="idle"?"prompting":E);},[o?.preview_session_id,o?.target.kind]);let N=useCallback(async(E,L,B,S)=>{try{d("running"),p([]),M(null),A(null);let c;if(o){let x=S?.forkId??o.fork_id??void 0,y=await fetch(`${n}/api/v1/preview/${encodeURIComponent(o.preview_session_id)}/author`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...te()},body:JSON.stringify({prompt:E,...L?{slot_id:L}:{},...x&&!S?.forceNew?{fork_id:x}:{},...S?.forceNew?{force_new:!0}:{}})});if(!y.ok){let V=await y.json().catch(()=>({}));throw new Error(V.error||`API error: ${y.status}`)}let _=await y.json();_.container_id&&Ge(_.container_id,_.container_name),dt(_.fork_id),c=await(await fetch(`${n}/api/v1/forks/${_.fork_id}`,{headers:{Authorization:`Bearer ${e}`,...te()}})).json();}else if(S?.forkId){let x={prompt:E};t&&(x.userId=t),r&&(x.userHash=r);let y=await fetch(`${n}/api/v1/forks/${encodeURIComponent(S.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(x)});if(!y.ok){let _=await y.json().catch(()=>({}));throw new Error(_.error||`API error: ${y.status}`)}c=await y.json();}else {let x={userId:t,prompt:E};L&&(x.slotId=L),B&&(x.containerId=B),r&&(x.userHash=r),S?.forceNew&&(x.force_new=!0);let y=await fetch(`${n}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(x)});if(!y.ok){let _=await y.json().catch(()=>({}));throw new Error(_.error||`API error: ${y.status}`)}c=await y.json();}A(c);let F=L??c.slotId;F&&u(c,{targetKind:"slot",targetId:F});let P=new URLSearchParams({key:e});o?(P.set("previewSessionId",o.preview_session_id),P.set("previewForkId",c.id)):t&&P.set("userId",t),r&&P.set("userHash",r);let C=new EventSource(`${n}/api/v1/forks/${c.id}/events?${P.toString()}`);h.current=C,C.onmessage=x=>{try{let y=JSON.parse(x.data);if(k(c.id,y),p(_=>[..._,y]),y.type==="complete"){let _=y.data,z={...c,status:"complete",bundleUrl:_.bundleUrl,summary:_.summary,completedAt:new Date().toISOString()};A(z),d("complete"),L&&_.bundleUrl&&s(L,z),C.close();}else if(y.type==="error"){let _=y.data;M(_.error||"Unknown error"),d("error"),C.close();}}catch{}},C.onerror=()=>{let x={Authorization:`Bearer ${e}`,...te()};!o&&t&&(x["X-Fork-User-Id"]=t),!o&&r&&(x["X-Fork-User-Hash"]=r),fetch(`${n}/api/v1/forks/${c.id}`,{headers:x}).then(y=>y.json()).then(y=>{A(y),y.status==="complete"?(d("complete"),L&&y.bundleUrl&&s(L,y)):y.status==="error"&&(M(y.error||"Fork generation failed"),d("error"));}).catch(()=>{M("Connection lost"),d("error");}),C.close();};}catch(c){M(c.message),d("error");}},[e,n,o,k,s,u,r,t]),D=useCallback(async E=>{try{let L={Authorization:`Bearer ${e}`,...te()};!o&&t&&(L["X-Fork-User-Id"]=t),!o&&r&&(L["X-Fork-User-Hash"]=r);let B=await fetch(`${n}/api/v1/forks/${E}`,{headers:L});if(!B.ok)return;let S=await B.json();if(S.slotId&&u(S,{targetKind:"slot",targetId:S.slotId}),S.status==="complete"){d("complete"),A(S),M(null),p([]);return}if(S.status==="error"){d("error"),A(S),M(S.error||"Fork generation failed"),p([]);return}if(S.status!=="pending"&&S.status!=="running"&&S.status!=="building")return;d("running"),A(S),M(null),p([]);let c=new URLSearchParams({key:e});o?(c.set("previewSessionId",o.preview_session_id),c.set("previewForkId",S.id)):t&&c.set("userId",t),r&&c.set("userHash",r);let F=new EventSource(`${n}/api/v1/forks/${S.id}/events?${c.toString()}`);h.current&&h.current.close(),h.current=F;let P=S.slotId;F.onmessage=C=>{try{let x=JSON.parse(C.data);if(k(S.id,x),p(y=>[...y,x]),x.type==="complete"){let y=x.data,_={...S,status:"complete",bundleUrl:y.bundleUrl,summary:y.summary,completedAt:new Date().toISOString()};A(_),d("complete"),P&&y.bundleUrl&&s(P,_),F.close();}else if(x.type==="error"){let y=x.data;M(y.error||"Unknown error"),d("error"),F.close();}}catch{}},F.onerror=()=>{F.close();};}catch{}},[e,n,o,k,s,u,r,t]),O=useCallback(async E=>{try{let L={userId:t,slotId:E};r&&(L.userHash=r);let B=await fetch(`${n}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(L)});if(!B.ok){let c=await B.json().catch(()=>({}));throw new Error(c.error||`API error: ${B.status}`)}let S=await B.json();return a(E),S.removed?(i(E),A(null),d("prompting")):S.fork&&(s(E,S.fork),A(S.fork)),S}catch(L){throw M(L.message),L}},[e,t,r,n,i,s]);return {state:g,fork:w,events:f,error:I,open:v,close:T,startFork:N,undoFork:O,adoptRunningFork:D}}var Us=0;function Ln(){let{state:e,fork:t,events:r,error:n,open:o,close:s,startFork:i,undoFork:a,adoptRunningFork:u}=Ar(),[k,g]=useState(false),d=useRef(null),w=useRef(e),A=useCallback(()=>{d.current!==null&&(clearTimeout(d.current),d.current=null);},[]),f=useCallback(()=>{A(),g(true),o();},[A,o]),p=useCallback(()=>{A(),g(false),s();},[A,s]),I=useCallback(async M=>{A(),g(true),await u(M);},[u,A]);return useEffect(()=>{let M=w.current;w.current=e,e==="complete"&&M==="running"&&k&&(A(),d.current=setTimeout(()=>{d.current=null,g(false),s();},Us)),(e==="running"||e==="prompting")&&A();},[e,k,A,s]),useEffect(()=>A,[A]),{state:e,fork:t,events:r,error:n,isOpen:k,open:f,close:p,submit:i,undo:a,adoptRunningFork:I}}var Ns=new Set(["pending","running","building"]);function _r(e){let t=En(e),r=Ln(),n=Pn(t.type==="boundary"?t.id:""),{baseUrl:o,apiKey:s,userId:i,userHash:a,appId:u,activitySummary:k,forkActivities:g,markForkActivitySeen:d}=he(),w=t.type==="slot"?r:n,A=t.type==="slot"?"slot":"boundary",f=t.id,p=t.title,I=t.type==="slot"?"slot":"module",M=g.find(D=>D.targetKind===I&&D.targetId===t.id&&Ns.has(D.status)),h=g.find(D=>D.targetKind===I&&D.targetId===t.id&&D.status==="complete"&&D.unread),v=useCallback(()=>{d();let D=M??h;if(D){w.adoptRunningFork(D.id);return}w.open();},[w,d,M,h]),T=useCallback((D,O,E,L)=>t.type==="slot"?r.submit(D,O??t.id,E,L):n.submit(D,E,L),[n,r,t]),N=useCallback(D=>t.type==="slot"?r.undo(D??t.id):n.undo(),[n,r,t]);return {...w,open:v,target:t,targetId:f,targetLabel:p,historyMode:A,submit:T,undo:N,buttonProps:{onClick:v,hasNotification:k.unreadCompletedCount>0,activity:k},panelProps:{state:w.state,fork:w.fork,events:w.events,error:w.error,...t.type==="slot"?{slotId:f,targetLabel:p,historyMode:A}:{targetId:f,targetLabel:p,historyMode:A},onSubmit:T,onUndo:N,onClose:w.close,baseUrl:o,apiKey:s,userId:i,userHash:a,appId:u}}}function Ft(e){let{embedded:t,completeVariant:r}=e,n=_r(e);return t?jsx(qt,{...n.panelProps,embedded:true,completeVariant:r}):n.isOpen?jsx(qt,{...n.panelProps,completeVariant:r}):jsx(wr,{...n.buttonProps})}function Bs({boundaryId:e,title:t}){return jsx(Ft,{boundaryId:e,title:t})}function Er(e){let t=Array.from(e.children).filter(n=>n instanceof HTMLElement);return t.length===1?t[0]:getComputedStyle(e).display==="contents"?null:e}function Hn(e){let t=e.getBoundingClientRect(),r=e.cloneNode(true);r.setAttribute("data-fork-clone-overlay","true"),r.style.position="fixed",r.style.top=`${t.top}px`,r.style.left=`${t.left}px`,r.style.width=`${t.width}px`,r.style.height=`${t.height}px`,r.style.flex="none",r.style.minHeight="auto",r.style.zIndex="9998",r.style.pointerEvents="none",r.style.overflow="hidden";let n=getComputedStyle(e).backgroundColor;r.style.backgroundColor=n&&n!=="rgba(0, 0, 0, 0)"&&n!=="transparent"?n:getComputedStyle(document.body).backgroundColor||"#ffffff",document.body.appendChild(r);let o=e.querySelectorAll("*"),s=r.querySelectorAll("*");for(let i=0;i<o.length;i+=1)o[i].scrollTop!==0&&(s[i].scrollTop=o[i].scrollTop),o[i].scrollLeft!==0&&(s[i].scrollLeft=o[i].scrollLeft);return r}function Cr(e){let t=[],r=e.querySelectorAll("*");for(let n of r){if(!(n instanceof HTMLElement))continue;let o=n.getBoundingClientRect();if(o.width<10||o.height<10||["SCRIPT","STYLE","META","LINK"].includes(n.tagName))continue;let s=getComputedStyle(n),i=parseFloat(s.borderTopLeftRadius)||0;t.push({tag:n.tagName,className:n.className||"",text:(n.textContent||"").slice(0,50).trim(),rect:o,borderRadius:i});}return t}function On(e,t){let r=[];for(let n of t)if(!(e.find(i=>i.tag===n.tag&&i.className===n.className&&Math.abs(i.rect.top-n.rect.top)<20&&Math.abs(i.rect.left-n.rect.left)<20)||r.some(i=>n.rect.top>=i.rect.top&&n.rect.left>=i.rect.left&&n.rect.right<=i.rect.right&&n.rect.bottom<=i.rect.bottom))){for(let i=r.length-1;i>=0;i-=1){let a=r[i];a.rect.top>=n.rect.top&&a.rect.left>=n.rect.left&&a.rect.right<=n.rect.right&&a.rect.bottom<=n.rect.bottom&&r.splice(i,1);}r.push({rect:n.rect,borderRadius:n.borderRadius});}return r}function Un(e,t){let r=[];for(let n of e)if(!(t.find(i=>i.tag===n.tag&&i.className===n.className&&Math.abs(i.rect.top-n.rect.top)<20&&Math.abs(i.rect.left-n.rect.left)<20)||r.some(i=>n.rect.top>=i.rect.top&&n.rect.left>=i.rect.left&&n.rect.right<=i.rect.right&&n.rect.bottom<=i.rect.bottom))){for(let i=r.length-1;i>=0;i-=1){let a=r[i];a.rect.top>=n.rect.top&&a.rect.left>=n.rect.left&&a.rect.right<=n.rect.right&&a.rect.bottom<=n.rect.bottom&&r.splice(i,1);}r.push({rect:n.rect,borderRadius:n.borderRadius});}return r}function Nn(e,t,r,n,o){let s=Math.max(0,Math.min(o,r/2,n/2));return s===0?`M ${e} ${t} L ${e+r} ${t} L ${e+r} ${t+n} L ${e} ${t+n} Z`:[`M ${e+s} ${t}`,`L ${e+r-s} ${t}`,`A ${s} ${s} 0 0 1 ${e+r} ${t+s}`,`L ${e+r} ${t+n-s}`,`A ${s} ${s} 0 0 1 ${e+r-s} ${t+n}`,`L ${e+s} ${t+n}`,`A ${s} ${s} 0 0 1 ${e} ${t+n-s}`,`L ${e} ${t+s}`,`A ${s} ${s} 0 0 1 ${e+s} ${t}`,"Z"].join(" ")}function $r(e){let t="http://www.w3.org/2000/svg",r=document.createElement("div");r.setAttribute("data-fork-highlights","true"),r.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let n=document.createElementNS(t,"svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs");n.appendChild(o);let s=[];for(let g=0;g<e.length;g+=1){let{rect:d,borderRadius:w}=e[g],A=d.left-.5,f=d.top-.5,p=d.width+1,I=d.height+1,M=Math.min(w+.5,p/2,I/2),h=Nn(A,f,p,I,M),v=`__fork-glow-${g}`,T=document.createElementNS(t,"filter");T.setAttribute("id",v),T.setAttribute("x","-100%"),T.setAttribute("y","-100%"),T.setAttribute("width","300%"),T.setAttribute("height","300%");let N=document.createElementNS(t,"feGaussianBlur");N.setAttribute("in","SourceGraphic"),N.setAttribute("stdDeviation","8"),T.appendChild(N),o.appendChild(T);let D=`__fork-mask-${g}`,O=document.createElementNS(t,"mask");O.setAttribute("id",D),O.setAttribute("maskUnits","userSpaceOnUse"),O.setAttribute("x",String(A-200)),O.setAttribute("y",String(f-200)),O.setAttribute("width",String(p+400)),O.setAttribute("height",String(I+400));let E=document.createElementNS(t,"rect");E.setAttribute("x",String(A-200)),E.setAttribute("y",String(f-200)),E.setAttribute("width",String(p+400)),E.setAttribute("height",String(I+400)),E.setAttribute("fill","white"),O.appendChild(E);let L=document.createElementNS(t,"path");L.setAttribute("d",h),L.setAttribute("fill","black"),O.appendChild(L),o.appendChild(O);let B=document.createElementNS(t,"g");B.setAttribute("mask",`url(#${D})`),B.setAttribute("opacity","0");let S=document.createElementNS(t,"g");S.setAttribute("filter",`url(#${v})`);let c=document.createElementNS(t,"path");c.setAttribute("d",h),c.setAttribute("fill","none"),c.setAttribute("stroke","rgba(150, 185, 220, 0.6)"),c.setAttribute("stroke-width","6"),c.setAttribute("stroke-linecap","round"),S.appendChild(c),B.appendChild(S),n.appendChild(B);let F=document.createElementNS(t,"path");F.setAttribute("d",h),F.setAttribute("fill","none"),F.setAttribute("stroke","rgba(150, 185, 220, 0.35)"),F.setAttribute("stroke-width","2"),F.setAttribute("stroke-linecap","round"),F.setAttribute("opacity","0"),n.appendChild(F),s.push(c,F),c.__group=B;}r.appendChild(n),document.body.appendChild(r);let i=[];for(let g=0;g<s.length;g+=2){let d=s[g],w=s[g+1],A=d.__group;if(!A)continue;let f=w.getTotalLength(),p=d.getTotalLength();if(f<=0)continue;let I=f*.35;w.setAttribute("stroke-dasharray",`${I} ${f-I}`),w.setAttribute("stroke-dashoffset","0"),i.push(w.animate([{strokeDashoffset:0,opacity:0,offset:0},{strokeDashoffset:-0.2*f,opacity:.92,offset:.06},{strokeDashoffset:-2*f,opacity:.92,offset:.92},{strokeDashoffset:-2.25*f,opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));let M=p*.35;d.setAttribute("stroke-dasharray",`${M} ${p-M}`),d.setAttribute("stroke-dashoffset","0"),i.push(d.animate([{strokeDashoffset:0,offset:0},{strokeDashoffset:-0.2*p,offset:.06},{strokeDashoffset:-2*p,offset:.92},{strokeDashoffset:-2.25*p,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"})),i.push(A.animate([{opacity:0,offset:0},{opacity:.92,offset:.06},{opacity:.92,offset:.92},{opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));}let a=false,u=()=>{if(a)return;a=true,clearTimeout(k);for(let d of i)try{d.cancel();}catch{}let g=r.animate([{opacity:1},{opacity:0}],{duration:400,fill:"forwards"});g.onfinish=()=>r.remove(),window.removeEventListener("click",u);},k=setTimeout(u,14500);return setTimeout(()=>{a||window.addEventListener("click",u);},500),u}function Bn(e){let t="http://www.w3.org/2000/svg",r=document.createElement("div");r.setAttribute("data-fork-removed","true"),r.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let n=document.createElementNS(t,"svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs"),s=document.createElementNS(t,"filter");s.setAttribute("id","__fork-removed-shadow"),s.setAttribute("x","-10%"),s.setAttribute("y","-10%"),s.setAttribute("width","120%"),s.setAttribute("height","120%");let i=document.createElementNS(t,"feDropShadow");i.setAttribute("dx","0"),i.setAttribute("dy","1"),i.setAttribute("stdDeviation","2"),i.setAttribute("flood-color","rgba(0,0,0,0.15)"),s.appendChild(i),o.appendChild(s),n.appendChild(o);for(let{rect:a,borderRadius:u}of e){let k=document.createElementNS(t,"path");k.setAttribute("d",Nn(a.left,a.top,a.width,a.height,u)),k.setAttribute("fill","none"),k.setAttribute("stroke","rgba(120, 125, 135, 0.6)"),k.setAttribute("stroke-width","1.5"),k.setAttribute("stroke-dasharray","8 4"),k.setAttribute("stroke-linecap","round"),k.setAttribute("filter","url(#__fork-removed-shadow)"),k.setAttribute("opacity","0"),n.appendChild(k),k.animate([{opacity:0,offset:0},{opacity:.6,offset:.08},{opacity:.05,offset:.45},{opacity:.6,offset:.85},{opacity:.05,offset:1}],{duration:5e3,easing:"ease-in-out",fill:"forwards"});}return r.appendChild(n),document.body.appendChild(r),r}function Kn(e,t){if(js(t.selector))return jn(e,t);let n=jn(e,t);if(n)return n;try{let s=document.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e&&e.contains(s))return s}catch{}if(Dn(t.selector))try{let s=e.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e)return s}catch{}if(t.textHint){let s=t.textHint.trim();if(s){let i=Tr(e,g=>g===s);if(i)return i;let a=s.toLowerCase(),u=Tr(e,g=>g.toLowerCase()===a);if(u)return u;let k=Tr(e,g=>g.toLowerCase().includes(a));if(k)return k}}let o=Ks(t.selector);if(o&&o!==t.selector&&Dn(o))try{let s=e.querySelector(o);if(s instanceof HTMLElement&&s!==e)return s}catch{}return null}function Dn(e){let t=e.split(/\s+|>|~|\+/),r=t[t.length-1]??"";return /[#\[]|:not\(|:nth-/.test(r)}function jn(e,t){let r=Array.from(e.querySelectorAll("[data-fork-new]"));if(r.length===0)return null;let n=Pr(t.label),o=Pr(t.textHint);return r.find(i=>{let a=Pr(i.getAttribute("data-fork-new"));return !!a&&(a===n||a===o)})??null}function js(e){return e.trim()==="[data-fork-new]"}function Pr(e){return e?.trim().replace(/\s+/g," ").toLowerCase()||null}function Ks(e){return e.replace(/\[class[\*~|^$]?=("[^"]*"|'[^']*'|[^\]]+)\]/g,"").replace(/\.[A-Za-z_][\w-]*/g,"").replace(/\s+/g," ").trim()}function Tr(e,t){let r=null,n=1/0,o=e.querySelectorAll("*");for(let s of o){let i=s.textContent?.trim();if(!i||!t(i))continue;let a=s.getBoundingClientRect();if(a.width<4||a.height<4)continue;let u=a.width*a.height;u<n&&(r=s,n=u);}return r}var Mr=2147483600,zs=1600,Ws=3e4,Js=300,Ke=10;function Vs(e){let r=getComputedStyle(e).borderTopLeftRadius;if(!r)return 4;if(r.endsWith("%")){let i=parseFloat(r);if(!Number.isFinite(i)||i<=0)return 4;let a=e.getBoundingClientRect(),u=Math.min(a.width,a.height);return Math.max(4,i/100*u)}let n=parseFloat(r);if(!Number.isFinite(n)||n<=0)return 4;let o=e.getBoundingClientRect(),s=Math.min(o.width,o.height)/2;return n>=s?s:Math.min(n,16)}function qs(e,t,r,n){let s=window.innerWidth,i=window.innerHeight,a=e;a==="top"&&t.top<n+Ke+8?a="bottom":a==="bottom"&&i-t.bottom<n+Ke+8?a="top":a==="left"&&t.left<r+Ke+8?a="right":a==="right"&&s-t.right<r+Ke+8&&(a="left");let u=0,k=0;return a==="top"?(u=t.top-n-Ke,k=t.left+t.width/2-r/2):a==="bottom"?(u=t.bottom+Ke,k=t.left+t.width/2-r/2):a==="left"?(u=t.top+t.height/2-n/2,k=t.left-r-Ke):(u=t.top+t.height/2-n/2,k=t.right+Ke),k=Math.max(8,Math.min(k,s-r-8)),u=Math.max(8,Math.min(u,i-n-8)),{top:u,left:k,placement:a}}function Xs(e){let t=document.createElement("div");t.setAttribute("data-fork-highlight-outline","true"),t.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr}`,"border:1.5px solid rgba(59,130,246,0.85)","box-sizing:border-box","opacity:0","transition:opacity 200ms ease-out"].join(";");let r=document.createElement("div");r.setAttribute("data-fork-highlight-glow","true"),r.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr-1}`,"box-sizing:border-box","border:1px solid rgba(59,130,246,0.36)","box-shadow:0 0 0 4px rgba(59,130,246,0.16), 0 0 18px 2px rgba(59,130,246,0.31)","opacity:0","transition:opacity 200ms ease-out"].join(";");let n=document.createElement("div");return n.setAttribute("data-fork-highlight-tooltip","true"),n.style.cssText=["position:fixed","pointer-events:none",`z-index:${Mr+1}`,"padding:6px 10px","font:500 12px/1.2 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif","color:#ffffff","background:linear-gradient(135deg,#64748b,#475569)","border-radius:999px","box-shadow:0 4px 14px rgba(71,85,105,0.31),0 1px 2px rgba(0,0,0,0.1)","white-space:nowrap","opacity:0","transform:translateY(-2px)","transition:opacity 200ms ease-out, transform 200ms ease-out"].join(";"),n.textContent=`New: ${e}`,{outline:t,glow:r,tooltip:n}}function Gs(){if(document.getElementById("__fork-highlight-keyframes"))return;let e=document.createElement("style");e.id="__fork-highlight-keyframes",e.textContent=`
|
|
60
60
|
@keyframes __fork-highlight-pulse {
|
|
61
61
|
0%, 100% { box-shadow: 0 0 0 3px rgba(59,130,246,0.11), 0 0 12px 1px rgba(59,130,246,0.22); }
|
|
62
62
|
50% { box-shadow: 0 0 0 6px rgba(59,130,246,0.25), 0 0 22px 4px rgba(59,130,246,0.49); }
|
package/package.json
CHANGED