rivet-design 0.11.0 → 0.11.2
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.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -9
- package/dist/index.js.map +1 -1
- package/dist/mcp/agent-variants/areNaSourceContext.d.ts +21 -0
- package/dist/mcp/agent-variants/areNaSourceContext.d.ts.map +1 -0
- package/dist/mcp/agent-variants/areNaSourceContext.js +127 -0
- package/dist/mcp/agent-variants/areNaSourceContext.js.map +1 -0
- package/dist/mcp/agent-variants/createZeroToOneTool.d.ts.map +1 -1
- package/dist/mcp/agent-variants/createZeroToOneTool.js +43 -4
- package/dist/mcp/agent-variants/createZeroToOneTool.js.map +1 -1
- package/dist/mcp/agent-variants/pinterestSourceContext.d.ts +4 -0
- package/dist/mcp/agent-variants/pinterestSourceContext.d.ts.map +1 -1
- package/dist/mcp/agent-variants/pinterestSourceContext.js +7 -0
- package/dist/mcp/agent-variants/pinterestSourceContext.js.map +1 -1
- package/dist/mcp/agent-variants/tools.d.ts +6 -1
- package/dist/mcp/agent-variants/tools.d.ts.map +1 -1
- package/dist/mcp/agent-variants/tools.js.map +1 -1
- package/dist/mcp/auth/httpOAuthProvider.d.ts +12 -12
- package/dist/mcp/auth/httpOAuthProvider.d.ts.map +1 -1
- package/dist/mcp/auth/httpOAuthProvider.js +348 -67
- package/dist/mcp/auth/httpOAuthProvider.js.map +1 -1
- package/dist/mcp/auth/tools.d.ts +1 -0
- package/dist/mcp/auth/tools.d.ts.map +1 -1
- package/dist/mcp/auth/tools.js +31 -10
- package/dist/mcp/auth/tools.js.map +1 -1
- package/dist/mcp/hostedServer.d.ts +13 -0
- package/dist/mcp/hostedServer.d.ts.map +1 -0
- package/dist/mcp/hostedServer.js +46 -0
- package/dist/mcp/hostedServer.js.map +1 -0
- package/dist/mcp/httpServer.d.ts +23 -3
- package/dist/mcp/httpServer.d.ts.map +1 -1
- package/dist/mcp/httpServer.js +320 -56
- package/dist/mcp/httpServer.js.map +1 -1
- package/dist/mcp/integrations/tools.d.ts +6 -5
- package/dist/mcp/integrations/tools.d.ts.map +1 -1
- package/dist/mcp/integrations/tools.js +39 -5
- package/dist/mcp/integrations/tools.js.map +1 -1
- package/dist/mcp/server.d.ts +4 -8
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +56 -35
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/types.d.ts +7 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +3 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/services/AuthService.d.ts +15 -1
- package/dist/services/AuthService.d.ts.map +1 -1
- package/dist/services/AuthService.js +176 -8
- package/dist/services/AuthService.js.map +1 -1
- package/dist/services/ConfigManager.d.ts +2 -0
- package/dist/services/ConfigManager.d.ts.map +1 -1
- package/dist/services/ConfigManager.js +21 -7
- package/dist/services/ConfigManager.js.map +1 -1
- package/dist/services/IntegrationsClient.d.ts +53 -0
- package/dist/services/IntegrationsClient.d.ts.map +1 -1
- package/dist/services/IntegrationsClient.js +51 -4
- package/dist/services/IntegrationsClient.js.map +1 -1
- package/dist/services/RequestAuthContext.d.ts +1 -0
- package/dist/services/RequestAuthContext.d.ts.map +1 -1
- package/dist/services/RequestAuthContext.js.map +1 -1
- package/package.json +1 -1
- package/src/ui/dist/assets/{main-Cw6Pd8ye.js → main-4_VncEaM.js} +2 -2
- package/src/ui/dist/index.html +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntegrationsClient.js","sourceRoot":"","sources":["../../src/services/IntegrationsClient.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAC/C,mDAAmD;AACnD,+CAA4C;AAC5C,6DAAkE;
|
|
1
|
+
{"version":3,"file":"IntegrationsClient.js","sourceRoot":"","sources":["../../src/services/IntegrationsClient.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAC/C,mDAAmD;AACnD,+CAA4C;AAC5C,6DAAkE;AAClE,6DAG8B;AAE9B,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,oBAAoB,CAAC,CAAC;AA+F/C;;;;GAIG;AACH,MAAa,kBAAkB;IACZ,QAAQ,CAAS;IACjB,aAAa,GAAG,IAAA,gCAAgB,GAAE,CAAC;IACnC,WAAW,CAAc;IAE1C,YAAY,OAA0D;QACpE,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;QACtE,IAAI,CAAC,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,IAAI,yBAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5E,CAAC;IAEO,KAAK,CAAC,cAAc;QAC1B,MAAM,cAAc,GAAG,IAAA,0CAAqB,GAAE,CAAC;QAC/C,IAAI,KAAK,GAAG,cAAc,EAAE,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;QACvE,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACf,CAAC;QAED,yEAAyE;QACzE,+DAA+D;QAC/D,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,mBAAmB,EAAE,CAAC;QAC7D,KAAK,GAAG,IAAA,0CAAqB,GAAE,EAAE,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;QAC5E,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAC7B,OAA8C;QAE9C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC1C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,MAAM,cAAc,GAAG,IAAA,0CAAqB,GAAE,CAAC;QAC/C,MAAM,YAAY,GAChB,cAAc,EAAE,YAAY,IAAI,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,CAAC;QACvE,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,IAAA,+CAA0B,EAAC;YACjD,YAAY;YACZ,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,IAAI,cAAc,EAAE,CAAC;YACnB,IAAA,6CAAwB,EAAC;gBACvB,KAAK,EAAE,SAAS,CAAC,KAAK;gBACtB,YAAY,EAAE,SAAS,CAAC,YAAY;aACrC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,aAAa,CAAC,OAAO,CACxB,SAAS,CAAC,KAAK,EACf,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,EACnC,SAAS,CAAC,YAAY,CACvB,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,cAAc,CAAC,GAAW;QAC9B,MAAM,IAAI,GAAG,KAAK,EAAE,MAAc,EAAqB,EAAE,CACvD,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,mCAAmC,EAAE;YACzD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,MAAM,EAAE;aAClC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;SAC9B,CAAC,CAAC;QAEL,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACpD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC;YAC3D,CAAC;YAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;gBACnD,OAAO;oBACL,MAAM,EAAE,OAAO;oBACf,OAAO,EAAE,2BAA2B,QAAQ,CAAC,MAAM,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;iBAC9E,CAAC;YACJ,CAAC;YAED,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAyB,CAAC;QACzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,IAAI,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;YAC1C,OAAO;gBACL,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAClE,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,MAAM,IAAI,GAAG,KAAK,EAAE,MAAc,EAAqB,EAAE,CACvD,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,+BAA+B,EAAE;YACrD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,MAAM,EAAE;aAClC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;SAC9B,CAAC,CAAC;QAEL,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACpD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC;YAC3D,CAAC;YAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;gBACnD,OAAO;oBACL,MAAM,EAAE,OAAO;oBACf,OAAO,EAAE,wBAAwB,QAAQ,CAAC,MAAM,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;iBAC3E,CAAC;YACJ,CAAC;YAED,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAqB,CAAC;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;YACvC,OAAO;gBACL,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAClE,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,gBAAgB;QACpB,MAAM,GAAG,GAAG,KAAK,EAAE,MAAc,EAAqB,EAAE,CACtD,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,mBAAmB,EAAE;YACzC,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,MAAM,EAAE,EAAE;SAC/C,CAAC,CAAC;QAEL,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;YACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC;YAC3D,CAAC;YAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;gBACnD,OAAO;oBACL,MAAM,EAAE,OAAO;oBACf,OAAO,EAAE,8BAA8B,QAAQ,CAAC,MAAM,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;iBACjF,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAElC,CAAC;YACF,OAAO;gBACL,MAAM,EAAE,IAAI;gBACZ,YAAY,EAAE,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;oBAC5D,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,IAAI,EAAE,CAAC;oBAC5C,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,IAAI,EAAE,CAAC;oBACxC,gBAAgB,EACd,OAAO,WAAW,CAAC,gBAAgB,KAAK,QAAQ;wBAC9C,CAAC,CAAC,WAAW,CAAC,gBAAgB;wBAC9B,CAAC,CAAC,IAAI;oBACV,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,WAAW,IAAI,EAAE,CAAC;iBACnD,CAAC,CAAC;aACJ,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,IAAI,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;YAC7C,OAAO;gBACL,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAClE,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAtMD,gDAsMC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestAuthContext.d.ts","sourceRoot":"","sources":["../../src/services/RequestAuthContext.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAIF;;GAEG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,EACzC,OAAO,uBAAuB,EAC9B,UAAU,MAAM,CAAC,KAChB,CAEF,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,wBAAwB,GACnC,OAAO,OAAO,CAAC,uBAAuB,CAAC,KACtC,IAMF,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,qBAAqB,QAAO,uBAAuB,GAAG,IAElE,CAAC"}
|
|
1
|
+
{"version":3,"file":"RequestAuthContext.d.ts","sourceRoot":"","sources":["../../src/services/RequestAuthContext.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAIF;;GAEG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,EACzC,OAAO,uBAAuB,EAC9B,UAAU,MAAM,CAAC,KAChB,CAEF,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,wBAAwB,GACnC,OAAO,OAAO,CAAC,uBAAuB,CAAC,KACtC,IAMF,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,qBAAqB,QAAO,uBAAuB,GAAG,IAElE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestAuthContext.js","sourceRoot":"","sources":["../../src/services/RequestAuthContext.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;
|
|
1
|
+
{"version":3,"file":"RequestAuthContext.js","sourceRoot":"","sources":["../../src/services/RequestAuthContext.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAUrD,MAAM,kBAAkB,GAAG,IAAI,oCAAiB,EAA2B,CAAC;AAE5E;;GAEG;AACI,MAAM,yBAAyB,GAAG,CACvC,KAA8B,EAC9B,QAAiB,EACd,EAAE;IACL,OAAO,kBAAkB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACjD,CAAC,CAAC;AALW,QAAA,yBAAyB,6BAKpC;AAEF,sEAAsE;AAC/D,MAAM,wBAAwB,GAAG,CACtC,KAAuC,EACjC,EAAE;IACR,MAAM,OAAO,GAAG,kBAAkB,CAAC,QAAQ,EAAE,CAAC;IAC9C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;IACT,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAChC,CAAC,CAAC;AARW,QAAA,wBAAwB,4BAQnC;AAEF,sEAAsE;AAC/D,MAAM,qBAAqB,GAAG,GAAmC,EAAE;IACxE,OAAO,kBAAkB,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC;AAC/C,CAAC,CAAC;AAFW,QAAA,qBAAqB,yBAEhC"}
|
package/package.json
CHANGED
|
@@ -507,7 +507,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
507
507
|
|
|
508
508
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
509
509
|
|
|
510
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return h.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},_2e="DialogDescriptionWarning",A2e=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${DV(_2e).contentName}}.`;return h.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Dv=kV,Nv=SV,Lv=_V,jv=AV,lp=PV,Ak=RV;const Nm=Mt("useCommit"),T2e=()=>{const[e,t]=h.useState(!1),[n,r]=h.useState(!1),i=h.useCallback(async()=>{r(!0);try{const o=await fetch("/api/git/generate-commit-message");if(!o.ok){const c=await o.json();throw new Error(c.error||`HTTP ${o.status}`)}return(await o.json()).message}catch(o){return Nm.warn("Failed to generate commit message:",o),null}finally{r(!1)}},[]);return{commit:h.useCallback(async(o,a=!1)=>{t(!0);try{const c=await fetch("/api/git/commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:o,push:a})}),u=await c.json();if(!c.ok&&u.sha)return Nm.warn("Commit succeeded but push failed:",u.details),{sha:u.sha,pushed:!1,pushError:u.details||u.error};if(!c.ok)throw new Error(u.details||u.error||`HTTP ${c.status}`);return Nm.info("Committed successfully:",u.sha),{sha:u.sha,pushed:!!u.pushed}}catch(c){throw Nm.warn("Failed to commit:",c),c}finally{t(!1)}},[]),generateMessage:i,isCommitting:e,isGenerating:n}},P2e=Mt("CommitModal"),I2e=({isOpen:e,onClose:t,onCommitted:n})=>{const r=bs(),{commit:i,generateMessage:s,isCommitting:o,isGenerating:a}=T2e(),[c,u]=h.useState(""),[f,p]=h.useState(null);h.useEffect(()=>{e&&(u(""),s().then(b=>{b&&u(b)}))},[e,s]);const m=h.useCallback(async(b=!1)=>{if(c.trim()){p(b?"push":"commit");try{const x=await i(c.trim(),b);r==null||r.capture("git_commit",{has_push:b,is_pushed:x.pushed,has_push_error:!!x.pushError,message_length:c.trim().length}),n(),t(),x.pushError&&ct.error("Commit succeeded but push failed",{description:x.pushError})}catch(x){r==null||r.capture("git_commit_failed",{has_push:b,error:x instanceof Error?x.message:"unknown"}),P2e.error("Commit failed:",x),ct.error("Commit failed",{description:x instanceof Error?x.message:"Failed to commit"})}finally{p(null)}}},[i,c,n,t,r]),g=h.useCallback(b=>{b.key==="Enter"&&b.metaKey&&(b.preventDefault(),m(!b.shiftKey))},[m]);return y.jsx(Dv,{open:e,onOpenChange:b=>!b&&t(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[420px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Commit Changes"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsxs("div",{className:"relative",children:[y.jsx("textarea",{value:c,onChange:b=>u(b.target.value),onKeyDown:g,placeholder:a?"Generating message...":"Enter commit message",disabled:a,rows:3,className:"w-full resize-none rounded-md bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),a?y.jsx("div",{className:"absolute right-3 top-2.5",children:y.jsx(Ua,{className:"h-4 w-4 animate-spin text-content-subtle",weight:"bold"})}):null]}),y.jsxs("div",{className:"flex gap-2",children:[y.jsx("button",{onClick:()=>m(!1),disabled:o||a||!c.trim(),className:"flex flex-1 items-center justify-center gap-1.5 rounded-md border border-divider px-3 py-2 text-xs text-white transition-colors hover:bg-main-hover disabled:opacity-50",children:f==="commit"?"Committing...":"Commit"}),y.jsx("button",{onClick:()=>m(!0),disabled:o||a||!c.trim(),className:"flex flex-1 items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:f==="push"?"Committing...":"Commit & Push"})]})]})})]})})},LP=Mt("CreateBranchModal"),M2e=({isOpen:e,onClose:t,onCreated:n})=>{const r=bs(),[i,s]=h.useState(""),[o,a]=h.useState(!1),[c,u]=h.useState(!1);h.useEffect(()=>{e&&(s(""),a(!0),fetch("/api/git/generate-branch-name").then(m=>{if(!m.ok)throw new Error(`HTTP ${m.status}`);return m.json()}).then(m=>{s(m.branchName)}).catch(m=>{LP.error("Failed to generate branch name:",m),s("rivet/")}).finally(()=>{a(!1)}))},[e]);const f=h.useCallback(async()=>{if(!i.trim()||c||o)return;u(!0);const m=i.trim();try{const g=await fetch("/api/git/create-branch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branchName:m})});if(!g.ok){const b=await g.json();throw new Error(b.details||b.error||`HTTP ${g.status}`)}n(m),t()}catch(g){const b=g instanceof Error?g.message:"Failed to create branch";r==null||r.capture("git_branch_create_failed",{branch:m,error:b}),ct.error("Failed to create branch",{description:b}),LP.error("Failed to create branch:",g)}finally{u(!1)}},[i,c,o,n,t,r]),p=h.useCallback(m=>{m.key==="Enter"&&(m.preventDefault(),f())},[f]);return y.jsx(Dv,{open:e,onOpenChange:m=>!m&&t(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[420px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Create Branch"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsxs("div",{className:"relative",children:[y.jsx("input",{type:"text",value:i,onChange:m=>s(m.target.value),onKeyDown:p,placeholder:o?"Generating name...":"Enter branch name",disabled:o,className:"w-full rounded-md bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),o?y.jsx("div",{className:"absolute right-3 top-2.5",children:y.jsx(Ua,{className:"h-4 w-4 animate-spin text-content-subtle",weight:"bold"})}):null]}),y.jsx("button",{onClick:f,disabled:c||o||!i.trim(),className:"flex w-full items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:c?"Creating...":"Create"})]})})]})})},R2e=({prUrl:e,branchName:t,isOpen:n,isLoading:r=!1,onClose:i})=>{const s=bs(),o=h.useCallback(a=>{a.key!=="Enter"||a.repeat||r||(a.preventDefault(),e&&(s==null||s.capture("git_pr_link_clicked",{branch:t,pr_url:e,source:"keyboard"}),window.open(e,"_blank","noopener,noreferrer")))},[r,e,s,t]);return h.useEffect(()=>{if(n)return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n,o]),y.jsx(Dv,{open:n,onOpenChange:a=>!a&&i(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsxs(jv,{className:"fixed left-1/2 top-1/2 z-max w-[380px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:[r?y.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[y.jsx(Ua,{className:"h-6 w-6 animate-spin text-primary",weight:"bold"}),y.jsx(lp,{className:"text-sm font-medium text-content",children:"Creating pull request..."})]}):null,r?null:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between gap-3",children:[y.jsx(lp,{className:"whitespace-nowrap text-sm font-semibold text-content",children:"Created Pull Request"}),t?y.jsxs("span",{className:"inline-flex max-w-[180px] shrink-0 items-center gap-1 rounded-md bg-main-input px-2 py-0.5 text-xs text-content-muted",children:[y.jsx(vh,{className:"h-3 w-3 shrink-0",weight:"bold"}),y.jsx("span",{className:"truncate",children:t})]}):null]}),y.jsxs("a",{href:e??"#",target:"_blank",rel:"noopener noreferrer",onClick:()=>{s==null||s.capture("git_pr_link_clicked",{branch:t,pr_url:e,source:"button"})},className:"flex w-full items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover",children:["View PR",y.jsx(r8,{className:"h-3 w-3",weight:"bold"})]})]})]})]})})},NV=({primaryLabel:e,primaryIcon:t,primaryAction:n,isDisabled:r=!1,isLoading:i=!1,loadingLabel:s,dropdownItems:o})=>{const[a,c]=h.useState(!1),u=i?s??e:e;return y.jsxs("div",{className:"flex items-stretch",children:[y.jsxs("button",{onClick:n,disabled:r||i,className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-l-md bg-main-hover px-3 text-xs font-medium text-white transition-colors hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[t?y.jsx(t,{className:"h-3.5 w-3.5",weight:"bold"}):null,u]}),y.jsxs(Fo,{open:a,onOpenChange:c,children:[y.jsx(al,{asChild:!0,children:y.jsx("button",{disabled:i,className:"h-7 flex-shrink-0 rounded-r-md border-l border-white/20 bg-main-hover px-1.5 text-white transition-colors hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:y.jsx(Ba,{className:"h-3.5 w-3.5",weight:"bold"})})}),y.jsx(Oo,{children:y.jsx(Vo,{className:"z-[60] min-w-[140px] rounded-lg border border-divider bg-main p-1 shadow-lg",sideOffset:5,align:"end",children:o.map(f=>{const p=f.icon;return y.jsxs("button",{onClick:()=>{f.isDisabled||(f.onClick(),c(!1))},disabled:f.isDisabled,className:"flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[p?y.jsx(p,{className:"h-3.5 w-3.5",weight:"bold"}):null,f.label]},f.label)})})})]})]})},$2e=h.createContext(null);function D2e(e){switch(e){case"top":return{y:4};case"bottom":return{y:-4};case"left":return{x:4};case"right":return{x:-4}}}function Tk({content:e,children:t,side:n="top",sideOffset:r=8,delayDuration:i=200,className:s,forceOpen:o,onOpenChange:a}){const[c,u]=h.useState(!1),f=o!==void 0?o:c,[p,m]=h.useState(!1),g=Mp(),b=h.useContext($2e);h.useEffect(()=>{f&&m(!0)},[f]);const x=()=>{f||m(!1)},C=D2e(n);return y.jsx(bV,{delayDuration:i,children:y.jsxs(xk,{open:f,onOpenChange:w=>{u(w),a==null||a(w)},children:[y.jsx(wk,{asChild:!0,children:t}),p&&y.jsx(kk,{forceMount:!0,container:b??void 0,children:y.jsx(Ck,{side:n,sideOffset:r,forceMount:!0,className:"z-tooltip",children:y.jsx(mn.div,{className:fr("bg-neutral-900 text-white text-[12px] px-2 py-1 border border-white/10 shadow-lg",g.bg,s),style:{fontVariationSettings:_h.medium},initial:{opacity:0,scale:.8,...C},animate:{opacity:f?1:0,scale:f?1:.9,x:0,y:0},transition:f?{type:"spring",duration:.34,bounce:.55}:{duration:.1},onAnimationComplete:x,children:e})})})]})})}const Fi=({label:e,children:t,side:n="top",sideOffset:r=8,delayDuration:i=300,disabled:s=!1})=>s?y.jsx(y.Fragment,{children:t}):y.jsx(Tk,{content:e,side:n,sideOffset:r,delayDuration:i,children:t}),vx=Mt("GitHome"),N2e=({onClose:e})=>e?y.jsx("div",{className:"z-10 flex h-10 flex-shrink-0 items-center border-b border-main-border bg-main-light px-3",children:y.jsx(Fi,{label:"Close chat",side:"bottom",children:y.jsx("button",{onClick:e,className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})})}):null,L2e=({onUndo:e,isUndoing:t=!1,onClose:n})=>{const r=bs(),s=ke(Qs).branchDiff.isEnabled,{status:o,fetchStatus:a}=q1(),{stats:c}=cV(),{publishChanges:u,isPublishing:f}=Kye(),{pushCommits:p,isPushing:m}=Yye(),[g,b]=h.useState(!1),[x,C]=h.useState(!1),[w,E]=h.useState(!1),[A,T]=h.useState(null),[M,I]=h.useState(null),P=(o==null?void 0:o.branchName)??null,S=(o==null?void 0:o.hasUncommittedChanges)??!1,D=c.totalInsertions>0||c.totalDeletions>0,R=(o==null?void 0:o.canUndo)??!1,L=(o==null?void 0:o.prUrl)??null,j=h.useCallback((Fe,Te,je,nt)=>{Fe==="success"?ct.success(Te,{description:je,action:nt?{label:nt.label,onClick:nt.onClick}:void 0}):Fe==="info"?ct.info(Te,{description:je}):(je&&vx.error(`${Te}:`,je),ct.error(Te))},[]),O=h.useCallback(async()=>{r==null||r.capture("git_pr_create_started",{branch:P}),E(!0),T(null);let Fe=!1;const je=await u((nt,yt,et)=>{nt==="error"&&(Fe=!0,r==null||r.capture("git_pr_create_failed",{branch:P,error:et??yt}),vx.error("Failed to create PR:",et??yt),E(!1),ct.error("Failed to create PR",{description:et??yt}))});je!=null&&je.prUrl?(r==null||r.capture("git_pr_created",{branch:je.branchName,pr_url:je.prUrl}),T(je.prUrl),I(je.branchName),a()):Fe||(r==null||r.capture("git_pr_create_failed",{branch:P,error:"unknown"}),vx.error("Failed to create PR: unknown error"),E(!1),ct.error("Failed to create PR",{description:"Something went wrong creating the pull request."}))},[u,a,r,P]),H=h.useCallback(async()=>{r==null||r.capture("git_push_started",{branch:P});const{success:Fe,error:Te}=await p();Fe?(r==null||r.capture("git_push_succeeded",{branch:P}),j("success","Changes pushed to GitHub")):(r==null||r.capture("git_push_failed",{branch:P,error:Te}),j("error","Failed to push",Te??void 0))},[p,j,r,P]),B=h.useCallback(()=>{L&&(r==null||r.capture("git_pr_opened",{branch:P,pr_url:L}),window.open(L,"_blank","noopener,noreferrer"))},[L,r,P]),Z=h.useCallback(()=>{a(),ct.success("Changes committed")},[a]),K=h.useCallback(Fe=>{r==null||r.capture("git_branch_created",{branch:Fe,from_branch:P}),a(),ct.success("Branch created")},[a,r,P]),q=h.useCallback(()=>{r==null||r.capture("git_commit_modal_opened",{branch:P}),b(!0)},[r,P]),Q=h.useCallback(()=>{r==null||r.capture("git_create_branch_modal_opened",{branch:P}),C(!0)},[r,P]),F=h.useCallback(()=>{r==null||r.capture("git_undo_commit",{branch:P}),e==null||e(j)},[r,P,e,j]),V=S,W=!!L,N=P==="main"&&!V&&!W,z=W?"Go to PR":"Create PR",ee=W?r8:C5,te=W?B:O,re=!W&&!D;let G=V?"Commit":z,X=V?k5:ee,de=V?q:te,ve=V?!1:re;N&&(G="New Branch",X=vh,de=Q,ve=!1);const we=V?[{label:"Undo Commit",icon:Fh,onClick:F,isDisabled:t||!R},{label:"Push Commits",icon:w5,onClick:H,isDisabled:m||!D},{label:z,icon:ee,onClick:te,isDisabled:f||re},{label:"Create New Branch",icon:vh,onClick:Q}]:[{label:"Undo Commit",icon:Fh,onClick:F,isDisabled:t||!R},{label:"Push Commits",icon:w5,onClick:H,isDisabled:m||!D},...N?[{label:"Create PR",icon:C5,onClick:O,isDisabled:!0}]:[{label:"Commit",icon:k5,onClick:q,isDisabled:!S},{label:"Create Branch",icon:vh,onClick:Q}]];return P?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"z-10 flex h-10 flex-shrink-0 items-center justify-between border-b border-main-border bg-main-light px-3",children:[n&&y.jsxs(y.Fragment,{children:[y.jsx("button",{onClick:n,title:"Close panel",className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})}),y.jsx("div",{className:"mx-1 h-4 w-[1px] flex-shrink-0 bg-divider/20"})]}),y.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 pr-2",children:[y.jsx(g2e,{currentBranch:P,onSwitch:()=>{a()}}),s&&D&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"h-4 w-[1px] flex-shrink-0 bg-divider/20"}),y.jsx(Qye,{})]})]}),y.jsx(NV,{primaryLabel:G,primaryIcon:X,primaryAction:de,isDisabled:ve,isLoading:!1,loadingLabel:"Creating PR...",dropdownItems:we})]}),y.jsx(I2e,{isOpen:g,onClose:()=>b(!1),onCommitted:Z}),y.jsx(M2e,{isOpen:x,onClose:()=>C(!1),onCreated:K}),y.jsx(R2e,{prUrl:A,branchName:M??void 0,isOpen:w,isLoading:f,onClose:()=>E(!1)})]}):n?y.jsx("div",{className:"z-10 flex h-10 flex-shrink-0 items-center border-b border-main-border bg-main-light px-3",children:y.jsx("button",{onClick:n,title:"Close panel",className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})}):null},j2e=e=>{const t=ke(x$),r=ke(Qs).gitUi.isEnabled;return!t||!r?y.jsx(N2e,{onClose:e.onClose}):y.jsx(L2e,{...e})},F2e=Mt("SupportTicketModal"),jP=5e3,yx="feedback",O2e=e=>{var r;if(!e)return null;const t=(r=e.formErrors)==null?void 0:r[0];if(t)return t;const n=e.fieldErrors??{};for(const i of Object.values(n)){const s=i==null?void 0:i[0];if(s)return s}return null},V2e=async e=>{let t;try{t=await e.json()}catch{t=void 0}if(e.status===400){if(typeof(t==null?void 0:t.details)=="string"&&t.details.trim())return t.details;if(typeof(t==null?void 0:t.details)=="object"&&t.details!==null){const n=O2e(t.details);if(n)return n}return"Please check your feedback and try again."}return e.status>=500?typeof(t==null?void 0:t.details)=="string"&&t.details.trim()?t.details:"Could not send feedback right now. Please try again later.":typeof(t==null?void 0:t.error)=="string"&&t.error.trim()?t.error:`HTTP ${e.status}`},H2e=({isOpen:e,onClose:t,contactEmail:n})=>{const r=bs(),[i,s]=h.useState(""),[o,a]=h.useState(!1),c=h.useCallback(()=>{s("")},[]),u=h.useCallback(()=>{o||(c(),t())},[o,t,c]),f=h.useCallback(async()=>{const b=i.trim();if(!(!b||o)){a(!0);try{const x=typeof(r==null?void 0:r.get_session_id)=="function"?r.get_session_id():void 0,C=typeof(r==null?void 0:r.get_distinct_id)=="function"?r.get_distinct_id():void 0,w=n==null?void 0:n.trim(),E=await fetch("/api/support/tickets",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:yx,message:b,contactEmail:w||void 0,metadata:{posthogSessionId:x??void 0,posthogDistinctId:C??void 0,appVersion:"0.11.0",appEnvironment:"production",pageUrl:window.location.href,userAgent:navigator.userAgent,submittedAt:new Date().toISOString()}})});if(!E.ok){const A=await V2e(E);throw new Error(A)}r==null||r.capture("support_ticket_submitted",{ticket_type:yx,has_posthog_session_id:!!x}),ct.success("Feedback sent",{description:"Thanks for sharing this."}),c(),t()}catch(x){const C=x instanceof Error?x.message:"Failed to send message";r==null||r.capture("support_ticket_submit_failed",{ticket_type:yx,error:C}),F2e.error("Failed to submit support ticket:",C),ct.error("Could not send feedback",{description:C})}finally{a(!1)}}},[n,o,i,t,r,c]),p=h.useCallback(b=>{b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),f())},[f]),m=jP-i.length,g=o||i.trim().length===0;return y.jsx(Dv,{open:e,onOpenChange:b=>!b&&u(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[480px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Send feedback"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",disabled:o,children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsx("p",{className:"text-sm text-content-subtle",children:"Tell us what happened or what we can improve."}),y.jsxs("div",{className:"space-y-2",children:[y.jsx("label",{htmlFor:"support-ticket-message",className:"text-xs font-medium text-content-muted",children:"Your feedback"}),y.jsx("textarea",{id:"support-ticket-message",value:i,onChange:b=>s(b.target.value),onKeyDown:p,maxLength:jP,rows:7,disabled:o,placeholder:"What happened?",className:"w-full resize-none rounded-md border border-divider bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),y.jsxs("div",{className:"flex justify-between text-xs text-content-subtle",children:[y.jsx("span",{children:"Context details are included automatically."}),y.jsx("span",{children:m})]})]}),y.jsx("button",{onClick:f,disabled:g,className:"flex w-full items-center justify-center gap-2 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:o?y.jsxs(y.Fragment,{children:[y.jsx(Ua,{className:"h-4 w-4 animate-spin",weight:"bold"}),y.jsx("span",{children:"Sending..."})]}):y.jsx("span",{children:"Send feedback"})})]})})]})})},B2e=Mt("ProfileAvatar"),z2e=(e,t)=>{const n=(e??"").trim();if(n){const i=n.split(/\s+/).filter(Boolean);return i.length>=2?(i[0][0]+i[i.length-1][0]).toUpperCase():i[0].slice(0,2).toUpperCase()}const r=(t??"").split("@")[0]??"";if(r){const i=r.split(/[._\-+]/).filter(Boolean);return i.length>=2?(i[0][0]+i[1][0]).toUpperCase():r.slice(0,2).toUpperCase()}return""},U2e=({className:e=""})=>{const{name:t,email:n}=ke(p$),[r,i]=h.useState(!1),[s,o]=h.useState(!1),[a,c]=h.useState(!1),u=z2e(t,n);if(!u)return null;const f=(t==null?void 0:t.trim())||null,p=(n==null?void 0:n.trim())||null,m=async()=>{c(!0);try{const g=await fetch("/api/auth/logout",{method:"POST",credentials:"same-origin"});if(!g.ok)throw new Error(`Logout failed: ${g.status}`)}catch(g){B2e.warn("Logout request failed",g),ct.error("Could not log out. Please try again."),c(!1);return}window.location.reload()};return y.jsxs(y.Fragment,{children:[y.jsxs(Fo,{open:r,onOpenChange:i,children:[y.jsx(al,{asChild:!0,children:y.jsx("button",{type:"button","aria-label":"Account",className:`flex h-6 w-6 shrink-0 select-none items-center justify-center rounded-full border border-main-border bg-main-input text-[10px] font-semibold leading-none text-content-muted transition-colors hover:text-content ${e}`,children:u})}),y.jsx(Oo,{children:y.jsxs(Vo,{className:"z-[60] min-w-[180px] rounded-lg border border-divider bg-main p-1 shadow-lg",sideOffset:6,align:"end",children:[f||p?y.jsxs("div",{className:"border-b border-main-border px-3 py-2",children:[f?y.jsx("div",{className:"truncate text-xs font-medium text-content",children:f}):null,p?y.jsx("div",{className:"truncate text-[11px] text-content-muted",children:p}):null]}):null,y.jsxs("button",{type:"button",onClick:()=>{i(!1),o(!0)},className:"mt-1 flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input",children:[y.jsx(LI,{className:"h-3.5 w-3.5",weight:"bold"}),"Support & feedback"]}),y.jsxs("button",{type:"button",onClick:m,disabled:a,className:"mt-1 flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[y.jsx(yG,{className:"h-3.5 w-3.5",weight:"bold"}),a?"Logging out…":"Log out"]})]})})]}),y.jsx(H2e,{isOpen:s,onClose:()=>o(!1),contactEmail:n??void 0})]})},Ut=Mt("ElementInspector"),Z2e=({chatMessages:e,setChatMessages:t,onClose:n})=>{const[r,i]=Vn(Ui),s=ke(Ad),[o]=Vn(U1),{undoLastChange:a,isUndoing:c}=Qie(),{status:u,fetchStatus:f}=q1(),m=ke(Qs).gitUi.isEnabled,g=m?(u==null?void 0:u.canUndo)??!1:!1,b=h.useCallback(async()=>{if(!s||!r)return;await new Promise(E=>requestAnimationFrame(E)),Ut.debug("Refreshing element styles for:",r.tagName);const w=await s.reSelectElement(ND(r));if(w){s.setCurrentElement(w);const E=s.getComputedStyles();s.showSelectionOverlay(w),VD("style_refresh"),i({...r,computedStyles:E})}else Ut.warn("Could not find element for refresh:",r.xpath)},[s,r,i]),x=h.useCallback(async()=>{if(!(o!=null&&o.canUndo()))return!1;const w=await o.undo();return w.ok?(await b(),!0):(Ut.error("Failed to undo:",w.error.message),!1)},[o,b]),C=h.useCallback(async w=>{var A;if(!m||!g||!await a((T,M,I)=>{w?w(T,M,I):T==="success"?ct.success(M,{description:I}):T==="info"?ct.message(M,{description:I}):(I&&Ut.error(`${M}:`,I),ct.error(M))}))return!1;if(await f(),(s==null?void 0:s.type)==="iframe"&&"forceReload"in s){Ut.info("Force reloading iframe after git undo");try{await((A=s.forceReload)==null?void 0:A.call(s))}catch(T){return Ut.error("Iframe reload failed, but git undo succeeded:",T),w==null||w("info","Changes reverted successfully","Please refresh the page to see the updated preview"),!0}}return await b(),!0},[b,g,m,a,f,s]);return y.jsxs("div",{className:"relative flex h-full w-96 cursor-auto flex-col overflow-hidden bg-main font-main shadow-2xl scrollbar-hide","data-cy":"element-inspector",children:[y.jsx(U2e,{className:"absolute right-3 top-2 z-20"}),y.jsx(j2e,{onUndo:C,isUndoing:c,onClose:n}),y.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:y.jsx(W2e,{chatMessages:e,setChatMessages:t,handleUndo:x,refreshElementStyles:b,fetchStatus:f})})]})},W2e=({chatMessages:e,setChatMessages:t,handleUndo:n,refreshElementStyles:r,fetchStatus:i})=>{const s=bs(),[o,a]=Vn(Ui),c=ke(Ad),[u,f]=Vn(ji),p=bc(),m=ke(xp),g=ke(hs),b=ke(wc),x=ke(eo),C=h.useRef(x);C.current=x;const w=h.useMemo(()=>Fie(u,g),[u,g]),E=h.useMemo(()=>{if(!rh(g))return null;const{sessionId:Se,variantId:He}=g;for(const dt of[b==null?void 0:b.left,b==null?void 0:b.right])if(dt&&dt.sessionId===Se&&dt.variantId===He)return dt.label;if(x.active){const dt=x.variants.find(Ze=>Ze.workItemId===He);if(dt)return dt.label}return"Direction"},[g,b,x]),A=ke(F8),[T,M]=Vn(U1);h.useEffect(()=>{if(!c)return;T&&T.destroy();const Se=new zJ(c,A);return M(Se),window.manipulationService=Se,()=>{Se.destroy(),M(null),delete window.manipulationService}},[c,A,M]);const[I,P]=h.useState(null),[S,D]=h.useState(0),R=Be(m$),L=Array.from(u.values()).filter(Se=>Se.status==="pending").length,[j,O]=Vn(ree),[H,B]=h.useState({}),[Z,K]=h.useState(0),q=h.useRef(null),Q=h.useRef(null),F=h.useRef(null),[V,W]=h.useState(0),N=h.useRef({}),z=h.useRef(!1),ee=h.useCallback(Se=>{const He=C.current;He.active&&He.sessionId===Se.sessionId&&$A(Se,He.variants,N.current),z.current=!1,F.current=Se,W(dt=>dt+1)},[]),te=h.useCallback(()=>{F.current!==null&&(F.current=null,W(Se=>Se+1))},[]),re=h.useCallback(Se=>{Q.current=Se,K(He=>He+1)},[]),G=h.useCallback(()=>{const Se=Q.current;Q.current=null,te(),K(He=>He+1),Se&&(Se.changeIds.length>0&&T&&Se.changeIds.forEach(He=>{T.removeTrackedChangeById(He)}),Se.commentIds.length>0&&f(He=>{if(He.size===0)return He;const dt=(m==null?void 0:m.current)??null;if(dt){const Kt=Se.commentIds.map(St=>He.get(St)).filter(St=>St!=null);Vu(dt,Kt)}const Ze=new Map(He);return Se.commentIds.forEach(Kt=>{Ze.delete(Kt)}),Ze}))},[T,f,m,te]),X=h.useCallback(()=>{Q.current=null,te(),K(Se=>Se+1)},[te]),{modifyWithAgent:de,cancelModification:ve,isModifying:we}=pte(),Fe=ke(w$),Te=ke(wp),je=ke(W1),nt=ke(z8),{sendChanges:yt,sendChatMessage:et}=Q$(),{status:ye,resetStatus:Ye}=Gie(),$t=h.useMemo(()=>Tie(ye),[ye]),Tt=ke(B8),{onRoundStarted:Nt,onProgressSteps:yn,onAssistantChunk:nn,onRoundCompleted:he,onRoundFailed:be,onRoundCanceled:We,getActiveAssistantMessageId:ot,getCancellationMessage:lt,setPhase:Vt}=Xie({setChatMessages:t,isMCPSession:Te}),Gt=ke(Js),J=Gt==="comment",Y=ke(Qs).generativeControls.isEnabled,se=ke(Iv),ce=ke(sV),le=Be(lV),ge=Be(aV),Ce=h.useMemo(()=>wie(se,ce),[se,ce]),$e=Be(j8),ut=ke(uc),it=ke(hd),{startRound:Zt,resetPhase:De}=Zie({mcpStatus:ye,isPublishing:j,isMCPSession:Te,setIsPublishing:O,fetchStatus:i,refreshElementStyles:r,getActiveAssistantMessageId:ot,onProgressSteps:yn,onRoundCompleted:he,setSessionUxPhase:Vt,clearQueuedPendingSnapshot:G});h.useEffect(()=>{if(!Te||!j)return;const Se=F.current;if(!Se)return;if(x.active&&x.sessionId===Se.sessionId)z.current=!0;else{if(!z.current)return;X(),O(!1),De(),Vt("idle");const rn=ot();rn&&be({assistantMessageId:rn,error:"Static preview variant refinement was interrupted."});return}const dt=N.current,Ze=Oie(Se,x.variants,dt);if(Ze.status==="pending")return;$A(Se,x.variants,dt);const Kt=Se.variantIds.length>1,St=ot();if(Ze.status==="succeeded"){G(),O(!1),De(),Vt("idle"),St&&he({assistantMessageId:St,finalMessage:Kt?"Static preview variants refined.":"Static preview variant refined."});return}if(X(),O(!1),De(),Vt("idle"),St){let rn;Ze.status==="cancelled"?rn="Static preview variant refinement was cancelled.":Ze.errorCode?rn=`Static preview variant refinement failed (${Ze.errorCode}).`:rn="Static preview variant refinement failed.",be({assistantMessageId:St,error:rn})}},[G,X,ot,Te,j,he,be,De,O,Vt,V,x]),h.useEffect(()=>{o&&(Te||(q.current=null))},[o==null?void 0:o.xpath,Te]);const at=we||j,Ne=Fe,Rt=$ie((o==null?void 0:o.computedStyles)||{});h.useEffect(()=>{var Kt,St;if(!o||!c||c.type!=="iframe")return;let Se=!1;const He=ND(o),dt=((St=(Kt=o.filePaths)==null?void 0:Kt[0])==null?void 0:St.filePath)||void 0;return(async()=>{const rn=await c.reSelectElement(He);if(Se||!rn)return;const wn=Ga();c.injectRivetId(rn,wn);const Un=c.createElementIdentifier(rn);Un.rivetId=wn,Un.filePath=dt,P(Un)})(),()=>{Se=!0}},[o,c]);const bn=ke(z1);h.useEffect(()=>{if(!T)return;const Se=A.getChangeCount();return D(Se),R(Se),A.onChange(()=>{const dt=A.getChangeCount();D(dt),R(dt)})},[A,T,R]);const en=!!o&&!J;h.useEffect(()=>{var dt;const Se=Ze=>{if(!((Ze.metaKey||Ze.ctrlKey)&&Ze.key.toLowerCase()==="z"&&!Ze.shiftKey)||bn.isEditing)return;const St=document.activeElement;St&&(St.tagName==="INPUT"||St.tagName==="TEXTAREA"||St.tagName==="SELECT"||St.getAttribute("contenteditable")==="true")&&!en||(Ze.preventDefault(),Ut.debug("Undo shortcut triggered"),s==null||s.capture("undo"),n())},He=(dt=m==null?void 0:m.current)==null?void 0:dt.contentDocument;return window.addEventListener("keydown",Se),He==null||He.addEventListener("keydown",Se),()=>{window.removeEventListener("keydown",Se),He==null||He.removeEventListener("keydown",Se)}},[en,n,bn.isEditing,m]);const qt=Se=>{Se!==Gt&&(s==null||s.capture("inspector_tab_changed",{from_tab:Gt,to_tab:Se})),$e(Se)};X8({shortcuts:[{key:"1",handler:()=>{Ut.debug("Switching to Styles tab (1)"),qt("edit")},description:"Switch to Styles tab"},{key:"2",handler:()=>{Ut.debug("Switching to Chat tab (2)"),qt("comment")},description:"Switch to Chat tab"},{key:"1",metaKey:!0,handler:()=>{Ut.debug("Switching to Styles tab (Cmd+1)"),qt("edit")},description:"Switch to Styles tab"},{key:"1",ctrlKey:!0,handler:()=>{Ut.debug("Switching to Styles tab (Ctrl+1)"),qt("edit")},description:"Switch to Styles tab"},{key:"2",metaKey:!0,handler:()=>{Ut.debug("Switching to Chat tab (Cmd+2)"),qt("comment")},description:"Switch to Chat tab"},{key:"2",ctrlKey:!0,handler:()=>{Ut.debug("Switching to Chat tab (Ctrl+2)"),qt("comment")},description:"Switch to Chat tab"}]});const pr=h.useCallback(async()=>{var He;if(at)return;zte(),Vu((m==null?void 0:m.current)??null,u.values());const Se=p.get(qa);Se&&(await a1(Se.diff),p.set(qa,null));for(const dt of u.values()){const Ze=(He=dt.finalizedVariant)==null?void 0:He.codeDiff;Ze&&await a1(Ze)}T==null||T.clear(),f(new Map),le()},[at,T,f,m,u,p,le]),Mn=h.useCallback(async()=>{const He=Hie(Te?u:w,T,Ce);if(!He)return;X();const{pendingComments:dt,styleChanges:Ze,textChanges:Kt,pendingSnapshot:St,applyPointers:rn,hasComments:wn,hasDesignChanges:Un,hasInterfaceChanges:bt}=He;if(s==null||s.capture("apply",{comment_count:dt.length,design_edit_count:Ze.length+Kt.length,interface_change_count:He.interfaceChanges.length,has_comments:wn,has_design_changes:Un,has_interface_changes:bt}),Te){$e("comment"),Ye(),O(!0),Zt();const Yt=$b(rn),{assistantMessageId:on}=Nt({userMessage:Yt,startPhase:"starting"});if(Ut.debug("[MCP] new apply round — asstMsgId:",on),re(St),!wn&&!Un&&bt){const Si=await et(Iw(Ce));if(Si.cancelled)return;Si.success||(X(),ct.error(Si.error||"Failed to send changes"),be({assistantMessageId:on,error:Si.error||"Failed to send changes"}),O(!1),De());return}const Bn=await yt();if(Bn.cancelled)return;if(!Bn.success){X(),ct.error(Bn.error||"Failed to send changes"),be({assistantMessageId:on,error:Bn.error||"Failed to send changes"}),O(!1),De();return}bt&&await et(Iw(Ce)),(Bn.changeIdsToClear||Bn.commentIdsToClear)&&re({...St,commentIds:Bn.commentIdsToClear??St.commentIds,changeIds:Bn.changeIdsToClear??St.changeIds}),Bn.staticPreviewVariantIds&&Bn.staticPreviewVariantIds.length>0&&Bn.staticPreviewSessionId&&ee({sessionId:Bn.staticPreviewSessionId,variantIds:Bn.staticPreviewVariantIds});return}$e("comment"),O(!0);const Rn=Bie(He),Lt=zie(He),sr=$b(rn),{assistantMessageId:Xn}=Nt({userMessage:sr,startPhase:"applying"});re(St);const Tc=dt.flatMap(Yt=>Yt.images??[]),Gi=Uie();Ut.debug("Calling modifyWithAgent");let _s=!1;try{await de({instruction:Rn,elements:Array.from(Lt.values()),images:Tc.length>0?Tc:void 0,sessionId:q.current??void 0},{onProgress:Yt=>{if(Gi.recordActivity(),!Yt.startsWith("Agent:")){const on=Yt.match(/^\[([^\]]+)\]/);on&&Gi.recordToolStart(on[1])}},onChunk:Yt=>{Gi.recordActivity(),Gi.recordReasoningChunk(),nn({content:Yt,assistantMessageId:Xn})},onComplete:async Yt=>{var Fp;_s=!0;const on=Gi.finalize();Ut.debug(`modifyWithAgent completed in ${on.agentExecutionDuration}ms`);const Bn=DA(Yt.changes,Yt.filesModified);if(he({assistantMessageId:Xn,finalMessage:Bn}),Yt.sessionId&&(q.current=Yt.sessionId),G(),Un){Ut.debug("Refreshing styles and status");try{await r(),await i()}catch(io){Ut.warn("Style/status refresh failed:",io)}}wn&&Ut.debug("Sent pending comments were cleared after completion."),bt&&le();const Si=Date.now();if((c==null?void 0:c.type)==="iframe"&&"forceReload"in c){Ut.debug("Force reloading iframe");try{await((Fp=c.forceReload)==null?void 0:Fp.call(c))}catch(io){Ut.warn("Iframe reload failed:",io)}}const Wv=Date.now();s==null||s.capture("code_modification",{success:!0,source:"apply",instruction_length:Rn.length,element_count:Lt.size,modification_time_ms:on.agentExecutionDuration}),s==null||s.capture("agent_apply_session",{success:!0,env:"production",total_duration_ms:Gi.elapsed(),agent_execution_duration_ms:on.agentExecutionDuration,tool_execution_duration_ms:on.totalToolDuration,model_reasoning_duration_ms:on.agentExecutionDuration-on.totalToolDuration,time_to_first_message_ms:on.timeToFirstMessage,post_processing_duration_ms:Si-on.agentEndTime,iframe_reload_duration_ms:Wv-Si,model:Yt.model,tool_counts:on.toolCounts,total_tool_calls:Object.values(on.toolCounts).reduce((io,Op)=>io+Op,0),reasoning_chunk_count:on.reasoningChunkCount,element_count:Lt.size,comment_count:dt.length,design_edit_count:S,instruction_length:Rn.length,session_id:Yt.sessionId,server_ttfm_ms:Yt.ttfmMs}),O(!1),De()},onError:async Yt=>{if(_s=!0,Ut.error("Error in modifyWithAgent:",Yt),be({assistantMessageId:Xn,error:Yt}),X(),s==null||s.capture("code_modification",{success:!1,source:"apply",instruction_length:Rn.length,element_count:Lt.size,error_message:Yt}),s==null||s.capture("agent_apply_session",{success:!1,env:"production",total_duration_ms:Gi.elapsed(),error_message:Yt,element_count:Lt.size,instruction_length:Rn.length}),Un)try{await(T==null?void 0:T.clearInlineChanges())}catch(on){Ut.warn("Failed to clear inline changes:",on)}gm(Yt)?vm(Yt):ct.error("Failed to apply changes"),O(!1),De()},onCanceled:()=>{_s=!0,O(!1),De(),X()}})}catch(Yt){_s=!0,Ut.error("Unexpected error in handleApplyAll:",Yt),X();const on=Yt instanceof Error?Yt.message:"An unexpected error occurred";be({assistantMessageId:Xn,error:on}),gm(on)?vm(on):ct.error("Failed to apply changes"),O(!1),De()}finally{_s||(Ut.warn("modifyWithAgent returned without triggering onComplete or onError"),X(),be({assistantMessageId:Xn,error:"Agent request failed to initialize or timed out without feedback."}),ct.error("Failed to apply changes"),O(!1),De())}},[w,u,T,c,de,r,i,S,s,Te,yt,et,Ye,Nt,nn,he,be,$e,Zt,De,O,re,G,X,Ce,le,ee]);h.useEffect(()=>{const Se=He=>{(He.metaKey||He.ctrlKey)&&He.key==="Enter"&&(ut||(L>0||S>0||Ce.length>0)&&!j&&!at&&(He.preventDefault(),Ut.debug("Apply all shortcut triggered (Cmd/Ctrl+Enter)"),Mn()))};return window.addEventListener("keydown",Se),()=>window.removeEventListener("keydown",Se)},[L,S,Ce,j,at,ut,Mn]);const ir=h.useCallback(async(Se,He)=>{var Kt;if(!T||!I||!c||c.type!=="iframe")return;const Ze=((Kt=Rt[Se])==null?void 0:Kt.type)==="range"?(parseFloat(He)/100).toString():He;await T.previewStyleChange(I,Se,Ze)},[T,I,c,Rt]),cn=h.useCallback(async(Se,He,dt)=>{var wn;const Ze=He;if(!Ze||!T||!I||!o||!c||c.type!=="iframe")return;const St=((wn=Rt[Se])==null?void 0:wn.type)==="range"?(parseFloat(Ze)/100).toString():Ze,rn=await T.applyStyleChange(I,o,Se,St,dt);if(rn.ok){const Un=await c.getComputedStylesForElement(I);Un.ok&&a({...o,computedStyles:Un.value}),B(Rn=>{const Lt={...Rn};return delete Lt[Se],Lt});const bt=Mw.find(Rn=>Rn.properties.some(Lt=>Lt.key===Se));s==null||s.capture("design_property_changed",{property:Se,category:bt==null?void 0:bt.value})}else Ut.error("Failed to apply style:",rn.error.message),ct.error("Failed to apply style")},[T,I,o,c,Rt,B,a,s]),Hn=h.useCallback(async Se=>{T&&await T.transaction(Se)},[T]),Ss=(Se,He)=>{B(dt=>({...dt,[Se]:He}))},Hd=(Se,He)=>{const dt=He.replace("%","").trim();if(dt===""){B(St=>({...St,[Se]:""}));return}const Ze=parseFloat(dt);if(Number.isNaN(Ze))return;const Kt=Math.max(0,Math.min(100,Ze));B(St=>({...St,[Se]:Kt.toString()}))},Bv=Se=>{B(He=>{const dt={...He};return delete dt[Se],dt})},zv=h.useCallback(async()=>{if(!T)return;const Se=await T.redo();Se.ok?await r():Ut.error("Failed to redo:",Se.error.message)},[T,r]),Uv=h.useCallback(()=>{const Se=lt();Te&&je==="embedded"&&fetch("/api/agent/stop",{method:"POST",headers:nt?{"x-rivet-queue-token":nt}:void 0}).catch(He=>{Ut.warn("Failed to stop embedded agent run:",He)}),ve(),O(!1),De(),X(),We({cancellationMessage:Se})},[ve,O,De,X,We,lt,Te,je,nt]),ro=h.useCallback(async(Se,He)=>{Ye();const dt=Date.now();X();const Ze=Array.from(u.values()).filter(Lt=>Lt.status==="pending"),Kt=Ze.length>0,St=Ze.map(Lt=>({id:Lt.id,instruction:Lt.instruction})),rn=jD({pendingComments:St,styleChanges:[],textChanges:[],includeComments:Kt,includeChanges:!1});s==null||s.capture("chat",{message_length:Se.length,has_images:!!(He!=null&&He.length),image_count:(He==null?void 0:He.length)??0,has_pending_comments:Kt,pending_comment_count:Ze.length,has_selected_element:!!o});const wn=Kt?FD(Ze):Se,Un=Kt?LD(Ze,[],[]):[],bt=Kt&&Un.length>0?$b(Un):Se,{assistantMessageId:Rn}=Nt({userMessage:bt,images:He,startPhase:Te?"starting":"applying"});rn.commentIds.length>0&&re(rn);try{if(Te){Ye(),O(!0),Zt();const Lt=await et(wn,He);if(Lt.cancelled)return;Lt.success||(X(),be({assistantMessageId:Rn,error:Lt.error||"Failed to send to Claude Code"}),O(!1),De())}else if(Ne){const Lt=o?[o]:[];await de({instruction:wn,elements:Lt,images:He,sessionId:q.current??void 0},{onProgress:()=>{},onChunk:sr=>{nn({content:sr,assistantMessageId:Rn})},onComplete:async({sessionId:sr,changes:Xn,filesModified:Tc})=>{var _s;const Gi=DA(Xn,Tc);if(he({assistantMessageId:Rn,finalMessage:Gi}),G(),s==null||s.capture("code_modification",{success:!0,source:"chat",instruction_length:wn.length,element_count:Lt.length,modification_time_ms:Date.now()-dt}),sr&&(q.current=sr),Kt&&Ut.debug("Sent pending comments were cleared after completion."),(c==null?void 0:c.type)==="iframe"&&"forceReload"in c)try{await((_s=c.forceReload)==null?void 0:_s.call(c))}catch(Yt){Ut.warn("Iframe reload after agent modification failed:",Yt)}r()},onError:sr=>{X(),be({assistantMessageId:Rn,error:sr}),s==null||s.capture("code_modification",{success:!1,source:"chat",instruction_length:wn.length,element_count:Lt.length,error_message:sr,modification_time_ms:Date.now()-dt}),Ut.error("Code modification error details:",sr),gm(sr)?vm(sr):ct.error("Code Modification Error")},onCanceled:()=>{O(!1),De(),X()}})}else Ut.error("Chat mode not supported"),ct.error("Chat mode not supported")}catch(Lt){Ut.error("Error with streaming request:",Lt);const sr=Lt instanceof Error?Lt.message:"An unexpected error occurred.";X(),O(!1),De(),be({assistantMessageId:Rn,error:sr}),gm(sr)?vm(sr):ct.error("Failed to generate AI response")}},[Ye,u,T,s,o,Te,et,Ne,de,c,r,Nt,nn,he,be,Zt,De,O,re,G,X]),Wi=h.useMemo(()=>{const Se=Array.from(w.values()).filter(bt=>bt.status==="pending"),He=(T==null?void 0:T.getStyleChanges())??[],dt=(T==null?void 0:T.getTextChanges())??[],Ze=He.map(bt=>({id:bt.id,key:rc(bt),property:String(bt.property),newValue:bt.newValue,timestamp:bt.timestamp})),Kt=dt.map(bt=>({id:bt.id,key:rc(bt),oldText:bt.oldText,newText:bt.newText,timestamp:bt.timestamp})),St=jie(Se.map(bt=>({id:bt.id,instruction:bt.instruction,finalizedVariant:bt.finalizedVariant,styleVariants:bt.styleVariants,selectedVariantIndex:bt.selectedVariantIndex,variantGenerationStatus:bt.variantGenerationStatus,requestedVariantCount:bt.requestedVariantCount})),Ze,Kt);for(const bt of Ce)St.push({id:bt.id,kind:"interface",detail:DD(bt)});const rn=Q.current;if(!at||!rn)return St;const wn=new Set(rn.commentIds),Un=new Map;return Ze.forEach(bt=>{Un.set(bt.id,bt.key)}),Kt.forEach(bt=>{Un.set(bt.id,bt.key)}),rn.changeIds.forEach(bt=>{const Rn=Un.get(bt);Rn&&wn.add(Rn)}),St.filter(bt=>!wn.has(bt.id))},[w,S,T,at,Z,Ce]),Ac=h.useCallback(async Se=>{if(Se.kind==="interface"){ge({controlId:Se.id,value:void 0});return}if(Se.kind==="comment"){f(Kt=>{const St=Kt.get(Se.id),rn=(m==null?void 0:m.current)??null;rn&&(St==null?void 0:St.previewBaselineStyle)!==void 0&&Vu(rn,[St]);const wn=new Map(Kt);return wn.delete(Se.id),wn});return}if(!T)return;const dt=T.getChanges().find(Kt=>rc(Kt)===Se.id);if(!dt){Ut.warn("No tracked change for pending row",Se.id);return}const Ze=await T.revertSpecificChange(dt);if(!Ze.ok){Ut.error("revertSpecificChange failed:",Ze.error.message),ct.error("Could not revert change");return}await r()},[T,f,r,m,ge]),Uo=Te?$t||(j&&(ye==null?void 0:ye.status)!=="APPLYING"?Eie:j?Cie:null):null,Lp=y.jsx(J0e,{chatMessages:e,statusHint:Uo,handleChatSend:ro,handleStop:Uv,isProcessing:at,pendingChangeRows:Wi,onRemovePendingChange:Ac,onApplyPendingChanges:Mn,onClearPendingChanges:pr,disableInputWhileProcessing:je!=="embedded",showModelPicker:je!=="embedded"}),jp=y.jsxs("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center px-6 text-center",children:[y.jsx("p",{className:"text-sm text-content-subtle",children:"Select an element to edit, or leave a comment on the page."}),Uo&&y.jsx("p",{className:"mt-2 text-xs text-content-subtle",children:Uo})]});return(()=>{const Se=_ie({isMCPSession:Te,isChatOpen:J,hasSelectedElement:!!o,isVariantsPanelOpen:it,hasPendingChanges:Wi.length>0,changeCount:S,isPublishing:j,isProcessing:at,hasStatusHint:!!Uo,shouldUseAgentChat:je==="embedded"}),He=o?y.jsx(fye,{propertyCategories:Mw,formattedComputedStyles:Rt,pendingChanges:H,handlePendingCssChange:Ss,handlePendingPercentageChange:Hd,applyPropertyChange:cn,previewPropertyChange:ir,performTransaction:Hn,handleBlur:Bv},o.xpath):null,dt=Y&&Gt==="edit"?y.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col",children:[y.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto scrollbar-hide",children:[y.jsx(Vye,{}),Se.showDesignPanel?He:null]}),Wi.length>0?y.jsx("div",{className:"flex-shrink-0 border-t border-main-border px-3 py-2",children:y.jsx(t6,{tags:Wi,onRemoveTag:Ac,onClearAll:pr,canClear:!j&&!at})}):null,y.jsx(Wye,{})]}):Gt==="edit"&&Se.showDesignPanel&&He?He:it?y.jsx(Qee,{}):Se.showChatPanel?Lp:Se.showDesignPanel?He:Se.showMCPEmptyState?jp:null,Ze=Wi.length;return y.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col",children:[E&&!it?y.jsx("div",{className:"flex flex-shrink-0 items-center border-b border-main-border bg-main-light px-4 py-1.5 text-xs text-content-subtle",children:y.jsxs("span",{className:"truncate",children:["Editing"," ",y.jsx("span",{className:"font-medium text-content",children:E})]})}):null,dt,Se.showExternalPendingChanges&&y.jsx("div",{className:"flex-shrink-0 border-t border-main-border px-4 py-2",children:y.jsx(t6,{tags:Wi,onRemoveTag:Ac,onClearAll:pr,canClear:!j&&!at})}),Se.showExternalStatusHint&&Uo&&y.jsx("div",{className:`flex-shrink-0 px-4 py-2 ${Wi.length===0?"border-t border-main-border":""}`,children:y.jsx("p",{className:"text-center text-xs text-content-subtle",children:Uo})}),(Se.showActionBar||Y&&Gt==="edit"&&Wi.length>0)&&y.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-t border-main-border bg-main-light px-4 py-3",children:[y.jsxs("div",{className:"flex gap-2",children:[y.jsx("button",{onClick:n,disabled:!(T!=null&&T.canUndo()),className:"rounded p-1.5 text-content transition-colors hover:bg-main-hover disabled:cursor-not-allowed disabled:opacity-30",title:"Undo (Cmd+Z)",children:y.jsx(Fh,{className:"h-4 w-4"})}),y.jsx("button",{onClick:zv,disabled:!(T!=null&&T.canRedo()),className:"rounded p-1.5 text-content transition-colors hover:bg-main-hover disabled:cursor-not-allowed disabled:opacity-30",title:"Redo (Cmd+Shift+Z)",children:y.jsx(uG,{className:"h-4 w-4"})})]}),y.jsx("button",{onClick:Mn,disabled:j||at,className:"rounded border border-primary px-3 py-1 text-xs font-medium text-gray-300 hover:bg-primary-hover disabled:cursor-not-allowed disabled:opacity-30",title:Te?`Send ${Ze||"pending"} changes to ${Tt||"Claude Code"}`:"Apply all pending changes (⌘↵)","data-cy":"inspector-apply-button",children:Aie({isMCPSession:Te,isApplying:j||at,pendingChangeCount:Ze})})]})]})})()},G2e=Mt("useServerConfig"),q2e=()=>{const[e,t]=h.useState(null),[n,r]=h.useState(!0),[i,s]=h.useState(null),o=h.useCallback(async()=>{var a;try{r(!0),s(null);const c=await fetch("/api/health");if(!c.ok)throw new Error(`Failed to fetch config: ${c.status}`);const u=await c.json();if(!u.framework)throw new Error("Server did not return framework information");const f={userPort:((a=u.ports)==null?void 0:a.userDevServer)||3e3,framework:u.framework};return t(f),f}catch(c){const u=c instanceof Error?c.message:"Failed to fetch server config";throw s(u),G2e.warn("Error fetching server config:",c),c}finally{r(!1)}},[]);return{config:e,fetchConfig:o,isLoading:n,error:i}},K2e="data:image/svg+xml,%3csvg%20width='453'%20height='416'%20viewBox='0%200%20453%20416'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20clip-path='url(%23clip0_1326_108)'%3e%3cpath%20d='M186.07%2025.5539C186.07%2011.4409%20197.511%200%20211.624%200H335.5C400.393%200%20453%2052.6065%20453%20117.5C453%20182.393%20400.393%20235%20335.5%20235H216.639C199.756%20235%20186.07%20221.314%20186.07%20204.431C186.07%20186.743%20198.071%20169.863%20215.299%20165.853C225.291%20163.528%20238.671%20160.53%20256.58%20156.667C258.587%20156.234%20260.54%20155.796%20262.442%20155.354C307.627%20144.861%20299.146%20103.217%20256.58%2084.7815C234.082%2075.0381%20218.731%2068.1115%20208.265%2063.1881C194.851%2056.8779%20186.07%2040.378%20186.07%2025.5539Z'%20fill='white'/%3e%3cpath%20d='M381.709%20415.715C329.789%20415.715%20287.699%20373.625%20287.699%20321.705V314.306C287.699%20288.346%20308.744%20267.301%20334.704%20267.301C386.624%20267.301%20428.714%20309.391%20428.714%20361.311V368.71C428.714%20394.67%20407.669%20415.715%20381.709%20415.715Z'%20fill='white'/%3e%3cpath%20d='M0%2073.5927C0%2033.1632%2032.7745%200.388672%2073.2039%200.388672C113.633%200.388672%20146.408%2033.1632%20146.408%2073.5926V338.795C146.408%20379.225%20113.633%20411.999%2073.2039%20411.999C32.7745%20411.999%200%20379.225%200%20338.795V73.5927Z'%20fill='white'/%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='clip0_1326_108'%3e%3crect%20width='453'%20height='416'%20fill='white'/%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",Lm=(e,t)=>y.jsxs("div",{className:"flex flex-row items-center gap-2",children:[y.jsx("span",{children:e}),t?y.jsx("span",{className:"rounded bg-white/15 px-1.5 py-0.5 text-[10px] leading-none font-bold",children:t}):null]}),Y2e={type:"spring",duration:.3,bounce:0},X2e=({mode:e,onModeChange:t,isLoading:n=!1,disabled:r=!1})=>{const[i,s]=h.useState(!1),o=ke(ji),a=ke(m$),[c,u]=Vn(bp);ke(Ui);const f=Be(Ui),p=Be(Js),m=Be(E$),g=ke(hd),b=Be(hd),x=ke(eo),C=e!=="view"||i||g,E=Array.from(o.values()).filter(P=>P.status==="pending").length+a,A=()=>{c?u(!1):(u(!0),g||(f(null),p("comment"),m(P=>P+1)))},T=()=>{g||(b(!0),u(!0),p("comment"),vt.capture("variants_panel.opened",{source:"control_bar",hasActiveSession:x.active}))},M=c?"Close panel":"Open panel",I=(P,S,D,R,L)=>{const j=r?"Disconnected":S,O=e===P&&!g;return y.jsx(Fi,{label:Lm(j,r?void 0:D),disabled:!C,children:y.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),b(!1),u(!0),t(P)},disabled:r,className:`rounded-md p-2 transition-colors ${O?"bg-primary/20 text-primary":"text-content hover:bg-main-input"} ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":L,children:R})})};return y.jsxs(mn.div,{className:"z-ui-primary absolute right-6 bottom-6",initial:{y:100,opacity:0},animate:{y:n?100:0,opacity:n?0:1},transition:{duration:.6,ease:"easeOut",delay:n?0:.3},children:[E>0&&!C&&!g&&y.jsx(mn.span,{className:"bg-primary pointer-events-none absolute -top-1 -right-1 z-10 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[9px] leading-none font-bold text-white",animate:{opacity:1},transition:{duration:.15,delay:.2},children:E>9?"9+":E}),y.jsxs(mn.div,{layout:!0,className:`border-primary/30 bg-main overflow-hidden border shadow-lg ${C?"":"cursor-pointer"}`,style:{borderRadius:C?10:9999},transition:Y2e,onClick:C?void 0:()=>t("comment"),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[y.jsx(mn.div,{className:"absolute flex items-center justify-center",style:{width:40,height:40,top:0,left:0},animate:{opacity:C?0:1},transition:C?{duration:0}:{duration:0,delay:.2},"aria-hidden":C,children:y.jsx("img",{src:K2e,alt:"Rivet",style:{width:16,height:16}})}),!C&&y.jsx("div",{style:{width:40,height:40}}),y.jsxs(mn.div,{className:"flex items-center gap-1 p-2",style:{position:C?"relative":"absolute",inset:0,pointerEvents:C?"auto":"none"},animate:{opacity:C?1:0},transition:C?{duration:0,delay:.22}:{duration:0},children:[y.jsx(Fi,{label:Lm(r?"Disconnected":"Explore",r?void 0:"E"),disabled:!C,children:y.jsxs("button",{type:"button",onClick:P=>{P.stopPropagation(),T()},disabled:r,className:`relative rounded-md p-2 transition-colors ${g?"bg-primary/20 text-primary":"text-content hover:bg-main-input"} ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"open-variants",children:[y.jsx(s8,{className:"h-5 w-5",weight:"bold"}),x.active&&!g&&y.jsx("span",{className:"bg-primary absolute -top-0.5 -right-0.5 h-2 w-2 rounded-full","aria-label":"Active explore session"})]})}),I("edit","Refine","R",y.jsx(xG,{className:"h-5 w-5"}),"mode-design"),y.jsx("div",{className:"bg-primary/20 mx-1 h-4 w-px"}),y.jsx(Fi,{label:Lm(r?"Disconnected":M,r?void 0:"P"),disabled:!C,children:y.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),A()},disabled:r,className:`text-content hover:bg-main-input relative rounded-md p-2 transition-colors ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"open-panel",children:y.jsx(Oh,{className:"h-5 w-5",weight:"bold",style:c?{transform:"scaleX(-1)"}:void 0})})}),y.jsx(Fi,{label:Lm(r?"Disconnected":"Collapse",r?void 0:"X"),disabled:!C,children:y.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),t("view"),b(!1),u(!1),s(!1)},disabled:r,"aria-label":"Collapse",className:`text-content hover:bg-main-input rounded-md p-2 transition-colors ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"mode-view",children:y.jsx(Ho,{className:"h-5 w-5",weight:"bold"})})})]})]})]})},Q2e=async()=>{let e;try{e=await fetch("/api/mcp/status")}catch{return{isOk:!1,unavailableReason:"rivet_unreachable"}}if(e.status===404||!(e.headers.get("content-type")??"").toLowerCase().includes("application/json"))return jm();if(!e.ok)return{isOk:!1,unavailableReason:"rivet_unreachable"};let n;try{n=await e.json()}catch{return jm()}const r=n.devServerHealth;return r?r.ownership==="none"?{isOk:!1,unavailableReason:"upstream_unreachable"}:r.isReachable===!0?{isOk:!0,unavailableReason:"upstream_unreachable"}:{isOk:!1,unavailableReason:r.reason==="rivet_unreachable"?"rivet_unreachable":"upstream_unreachable"}:jm()},jm=async()=>{try{const e=await fetch("/");return{isOk:e.status!==502&&e.status!==503,unavailableReason:"upstream_unreachable"}}catch{return{isOk:!1,unavailableReason:"rivet_unreachable"}}},FP=Mt("usePreviewUpstreamHealth"),J2e=500,ebe=4e3,tbe=15e3,nbe=(e,t={})=>{const n=h.useRef(null),r=h.useRef(null),i=t.probeMsWhileDown??J2e,s=t.probeMsWhileUp??ebe,o=t.firstUnreachableCaptureAfterMs??tbe,a=t.rerunProbeImmediatelyOnVersion,c=t.skip??!1,[u,f]=h.useState(e==="static"),[p,m]=h.useState(0),[g,b]=h.useState(null),[x,C]=h.useState(0),[w,E]=h.useState(!1),[A,T]=h.useState(!1),[M,I]=h.useState(e==="static"?null:"upstream_unreachable");return h.useEffect(()=>{if(e==="static"){f(!0),b(null),C(0),E(!1),T(!0),I(null);return}if(c){f(!1),b(null),C(0),E(!1),T(!0),I("upstream_unreachable"),n.current=null;return}let P=!0;const S=Date.now();b(S),C(0),E(!1),f(!1),T(!1),I("upstream_unreachable");const D={current:!1},R={current:!1},L={current:!1},j={current:null},O={current:!1};let H=null;const B=()=>{L.current||(L.current=!0,P&&T(!0))},Z=()=>{H!==null&&(clearTimeout(H),H=null)},K=(Q,F)=>{Z(),H=setTimeout(F,Q)},q=async()=>{if(!P)return;C(N=>N+1);const{isOk:Q,unavailableReason:F}=await Q2e();if(!P)return;if(B(),Q){const N=!O.current;O.current=!0,f(!0),I(null),j.current=null,R.current=!1,E(!1),D.current?N&&(vt==null||vt.capture("preview_upstream_restored",{framework:e})):(D.current=!0,vt==null||vt.capture("preview_dev_server_ready",{framework:e,ready_after_ms:Date.now()-S})),K(s,q);return}const V=O.current;O.current=!1,f(!1),I(F),j.current===null&&(j.current=Date.now(),R.current=!1,E(!1)),V&&(vt==null||vt.capture("preview_upstream_lost",{framework:e}),m(N=>N+1),FP.warn("Preview upstream became unavailable after it was ready"));const W=Date.now()-j.current;W>=o&&!R.current&&(R.current=!0,E(!0),vt==null||vt.capture("preview_dev_server_unreachable",{framework:e,elapsed_ms:W}),FP.warn("Dev server did not become ready within timeout window")),K(i,q)};return n.current=()=>K(0,q),K(0,q),()=>{P=!1,n.current=null,Z()}},[e,i,s,o,c]),h.useEffect(()=>{var S;if(e==="static"||a===void 0)return;const P=r.current;r.current=a,P!==null&&P!==a&&((S=n.current)==null||S.call(n))},[e,a]),{isUpstreamReady:u,iframeRemountKey:p,probeStartedAt:g,probeAttemptCount:x,isFirstUnreachableWindowExceeded:w,initialProbeComplete:A,unavailableReason:M}};function rbe(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const n=document.implementation.createHTMLDocument(),r=n.createElement("base"),i=n.createElement("a");return n.head.appendChild(r),n.body.appendChild(i),t&&(r.href=t),i.href=e,i.href}const ibe=(()=>{let e=0;const t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function Va(e){const t=[];for(let n=0,r=e.length;n<r;n++)t.push(e[n]);return t}let mu=null;function LV(e={}){return mu||(e.includeStyleProperties?(mu=e.includeStyleProperties,mu):(mu=Va(window.getComputedStyle(document.documentElement)),mu))}function T1(e,t){const r=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return r?parseFloat(r.replace("px","")):0}function sbe(e){const t=T1(e,"border-left-width"),n=T1(e,"border-right-width");return e.clientWidth+t+n}function obe(e){const t=T1(e,"border-top-width"),n=T1(e,"border-bottom-width");return e.clientHeight+t+n}function jV(e,t={}){const n=t.width||sbe(e),r=t.height||obe(e);return{width:n,height:r}}function abe(){let e,t;try{t=process}catch{}const n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}const hi=16384;function lbe(e){(e.width>hi||e.height>hi)&&(e.width>hi&&e.height>hi?e.width>e.height?(e.height*=hi/e.width,e.width=hi):(e.width*=hi/e.height,e.height=hi):e.width>hi?(e.height*=hi/e.width,e.width=hi):(e.width*=hi/e.height,e.height=hi))}function P1(e){return new Promise((t,n)=>{const r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=n,r.crossOrigin="anonymous",r.decoding="async",r.src=e})}async function cbe(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function ube(e,t,n){const r="http://www.w3.org/2000/svg",i=document.createElementNS(r,"svg"),s=document.createElementNS(r,"foreignObject");return i.setAttribute("width",`${t}`),i.setAttribute("height",`${n}`),i.setAttribute("viewBox",`0 0 ${t} ${n}`),s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("externalResourcesRequired","true"),i.appendChild(s),s.appendChild(e),cbe(i)}const si=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||si(n,t)};function dbe(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function fbe(e,t){return LV(t).map(n=>{const r=e.getPropertyValue(n),i=e.getPropertyPriority(n);return`${n}: ${r}${i?" !important":""};`}).join(" ")}function hbe(e,t,n,r){const i=`.${e}:${t}`,s=n.cssText?dbe(n):fbe(n,r);return document.createTextNode(`${i}{${s}}`)}function OP(e,t,n,r){const i=window.getComputedStyle(e,n),s=i.getPropertyValue("content");if(s===""||s==="none")return;const o=ibe();try{t.className=`${t.className} ${o}`}catch{return}const a=document.createElement("style");a.appendChild(hbe(o,n,i,r)),t.appendChild(a)}function pbe(e,t,n){OP(e,t,":before",n),OP(e,t,":after",n)}const VP="application/font-woff",HP="image/jpeg",mbe={woff:VP,woff2:VP,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:HP,jpeg:HP,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function gbe(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function Pk(e){const t=gbe(e).toLowerCase();return mbe[t]||""}function vbe(e){return e.split(/,/)[1]}function E6(e){return e.search(/^(data:)/)!==-1}function ybe(e,t){return`data:${t};base64,${e}`}async function FV(e,t,n){const r=await fetch(e,t);if(r.status===404)throw new Error(`Resource "${r.url}" not found`);const i=await r.blob();return new Promise((s,o)=>{const a=new FileReader;a.onerror=o,a.onloadend=()=>{try{s(n({res:r,result:a.result}))}catch(c){o(c)}},a.readAsDataURL(i)})}const bx={};function bbe(e,t,n){let r=e.replace(/\?.*/,"");return n&&(r=e),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),t?`[${t}]${r}`:r}async function Ik(e,t,n){const r=bbe(e,t,n.includeQueryParams);if(bx[r]!=null)return bx[r];n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let i;try{const s=await FV(e,n.fetchRequestInit,({res:o,result:a})=>(t||(t=o.headers.get("Content-Type")||""),vbe(a)));i=ybe(s,t)}catch(s){i=n.imagePlaceholder||"";let o=`Failed to fetch resource: ${e}`;s&&(o=typeof s=="string"?s:s.message),o&&console.warn(o)}return bx[r]=i,i}async function xbe(e){const t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):P1(t)}async function wbe(e,t){if(e.currentSrc){const s=document.createElement("canvas"),o=s.getContext("2d");s.width=e.clientWidth,s.height=e.clientHeight,o==null||o.drawImage(e,0,0,s.width,s.height);const a=s.toDataURL();return P1(a)}const n=e.poster,r=Pk(n),i=await Ik(n,r,t);return P1(i)}async function kbe(e,t){var n;try{if(!((n=e==null?void 0:e.contentDocument)===null||n===void 0)&&n.body)return await Fv(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function Cbe(e,t){return si(e,HTMLCanvasElement)?xbe(e):si(e,HTMLVideoElement)?wbe(e,t):si(e,HTMLIFrameElement)?kbe(e,t):e.cloneNode(OV(e))}const Ebe=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",OV=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function Sbe(e,t,n){var r,i;if(OV(t))return t;let s=[];return Ebe(e)&&e.assignedNodes?s=Va(e.assignedNodes()):si(e,HTMLIFrameElement)&&(!((r=e.contentDocument)===null||r===void 0)&&r.body)?s=Va(e.contentDocument.body.childNodes):s=Va(((i=e.shadowRoot)!==null&&i!==void 0?i:e).childNodes),s.length===0||si(e,HTMLVideoElement)||await s.reduce((o,a)=>o.then(()=>Fv(a,n)).then(c=>{c&&t.appendChild(c)}),Promise.resolve()),t}function _be(e,t,n){const r=t.style;if(!r)return;const i=window.getComputedStyle(e);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):LV(n).forEach(s=>{let o=i.getPropertyValue(s);s==="font-size"&&o.endsWith("px")&&(o=`${Math.floor(parseFloat(o.substring(0,o.length-2)))-.1}px`),si(e,HTMLIFrameElement)&&s==="display"&&o==="inline"&&(o="block"),s==="d"&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),r.setProperty(s,o,i.getPropertyPriority(s))})}function Abe(e,t){si(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),si(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function Tbe(e,t){if(si(e,HTMLSelectElement)){const r=Array.from(t.children).find(i=>e.value===i.getAttribute("value"));r&&r.setAttribute("selected","")}}function Pbe(e,t,n){return si(t,Element)&&(_be(e,t,n),pbe(e,t,n),Abe(e,t),Tbe(e,t)),t}async function Ibe(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(n.length===0)return e;const r={};for(let s=0;s<n.length;s++){const a=n[s].getAttribute("xlink:href");if(a){const c=e.querySelector(a),u=document.querySelector(a);!c&&u&&!r[a]&&(r[a]=await Fv(u,t,!0))}}const i=Object.values(r);if(i.length){const s="http://www.w3.org/1999/xhtml",o=document.createElementNS(s,"svg");o.setAttribute("xmlns",s),o.style.position="absolute",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.display="none";const a=document.createElementNS(s,"defs");o.appendChild(a);for(let c=0;c<i.length;c++)a.appendChild(i[c]);e.appendChild(o)}return e}async function Fv(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(r=>Cbe(r,t)).then(r=>Sbe(e,r,t)).then(r=>Pbe(e,r,t)).then(r=>Ibe(r,t))}const VV=/url\((['"]?)([^'"]+?)\1\)/g,Mbe=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Rbe=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function $be(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function Dbe(e){const t=[];return e.replace(VV,(n,r,i)=>(t.push(i),n)),t.filter(n=>!E6(n))}async function Nbe(e,t,n,r,i){try{const s=n?rbe(t,n):t,o=Pk(t);let a;return i||(a=await Ik(s,o,r)),e.replace($be(t),`$1${a}$3`)}catch{}return e}function Lbe(e,{preferredFontFormat:t}){return t?e.replace(Rbe,n=>{for(;;){const[r,,i]=Mbe.exec(n)||[];if(!i)return"";if(i===t)return`src: ${r};`}}):e}function HV(e){return e.search(VV)!==-1}async function BV(e,t,n){if(!HV(e))return e;const r=Lbe(e,n);return Dbe(r).reduce((s,o)=>s.then(a=>Nbe(a,o,t,n)),Promise.resolve(r))}async function gu(e,t,n){var r;const i=(r=t.style)===null||r===void 0?void 0:r.getPropertyValue(e);if(i){const s=await BV(i,null,n);return t.style.setProperty(e,s,t.style.getPropertyPriority(e)),!0}return!1}async function jbe(e,t){await gu("background",e,t)||await gu("background-image",e,t),await gu("mask",e,t)||await gu("-webkit-mask",e,t)||await gu("mask-image",e,t)||await gu("-webkit-mask-image",e,t)}async function Fbe(e,t){const n=si(e,HTMLImageElement);if(!(n&&!E6(e.src))&&!(si(e,SVGImageElement)&&!E6(e.href.baseVal)))return;const r=n?e.src:e.href.baseVal,i=await Ik(r,Pk(r),t);await new Promise((s,o)=>{e.onload=s,e.onerror=t.onImageErrorHandler?(...c)=>{try{s(t.onImageErrorHandler(...c))}catch(u){o(u)}}:o;const a=e;a.decode&&(a.decode=s),a.loading==="lazy"&&(a.loading="eager"),n?(e.srcset="",e.src=i):e.href.baseVal=i})}async function Obe(e,t){const r=Va(e.childNodes).map(i=>zV(i,t));await Promise.all(r).then(()=>e)}async function zV(e,t){si(e,Element)&&(await jbe(e,t),await Fbe(e,t),await Obe(e,t))}function Vbe(e,t){const{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);const r=t.style;return r!=null&&Object.keys(r).forEach(i=>{n[i]=r[i]}),e}const BP={};async function zP(e){let t=BP[e];if(t!=null)return t;const r=await(await fetch(e)).text();return t={url:e,cssText:r},BP[e]=t,t}async function UP(e,t){let n=e.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,s=(n.match(/url\([^)]+\)/g)||[]).map(async o=>{let a=o.replace(r,"$1");return a.startsWith("https://")||(a=new URL(a,e.url).href),FV(a,t.fetchRequestInit,({result:c})=>(n=n.replace(o,`url(${c})`),[o,c]))});return Promise.all(s).then(()=>n)}function ZP(e){if(e==null)return[];const t=[],n=/(\/\*[\s\S]*?\*\/)/gi;let r=e.replace(n,"");const i=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const c=i.exec(r);if(c===null)break;t.push(c[0])}r=r.replace(i,"");const s=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,o="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",a=new RegExp(o,"gi");for(;;){let c=s.exec(r);if(c===null){if(c=a.exec(r),c===null)break;s.lastIndex=a.lastIndex}else a.lastIndex=s.lastIndex;t.push(c[0])}return t}async function Hbe(e,t){const n=[],r=[];return e.forEach(i=>{if("cssRules"in i)try{Va(i.cssRules||[]).forEach((s,o)=>{if(s.type===CSSRule.IMPORT_RULE){let a=o+1;const c=s.href,u=zP(c).then(f=>UP(f,t)).then(f=>ZP(f).forEach(p=>{try{i.insertRule(p,p.startsWith("@import")?a+=1:i.cssRules.length)}catch(m){console.error("Error inserting rule from remote css",{rule:p,error:m})}})).catch(f=>{console.error("Error loading remote css",f.toString())});r.push(u)}})}catch(s){const o=e.find(a=>a.href==null)||document.styleSheets[0];i.href!=null&&r.push(zP(i.href).then(a=>UP(a,t)).then(a=>ZP(a).forEach(c=>{o.insertRule(c,o.cssRules.length)})).catch(a=>{console.error("Error loading remote stylesheet",a)})),console.error("Error inlining remote css file",s)}}),Promise.all(r).then(()=>(e.forEach(i=>{if("cssRules"in i)try{Va(i.cssRules||[]).forEach(s=>{n.push(s)})}catch(s){console.error(`Error while reading CSS rules from ${i.href}`,s)}}),n))}function Bbe(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>HV(t.style.getPropertyValue("src")))}async function zbe(e,t){if(e.ownerDocument==null)throw new Error("Provided element is not within a Document");const n=Va(e.ownerDocument.styleSheets),r=await Hbe(n,t);return Bbe(r)}function UV(e){return e.trim().replace(/["']/g,"")}function Ube(e){const t=new Set;function n(r){(r.style.fontFamily||getComputedStyle(r).fontFamily).split(",").forEach(s=>{t.add(UV(s))}),Array.from(r.children).forEach(s=>{s instanceof HTMLElement&&n(s)})}return n(e),t}async function Zbe(e,t){const n=await zbe(e,t),r=Ube(e);return(await Promise.all(n.filter(s=>r.has(UV(s.style.fontFamily))).map(s=>{const o=s.parentStyleSheet?s.parentStyleSheet.href:null;return BV(s.cssText,o,t)}))).join(`
|
|
510
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return h.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},_2e="DialogDescriptionWarning",A2e=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${DV(_2e).contentName}}.`;return h.useEffect(()=>{var s;const i=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Dv=kV,Nv=SV,Lv=_V,jv=AV,lp=PV,Ak=RV;const Nm=Mt("useCommit"),T2e=()=>{const[e,t]=h.useState(!1),[n,r]=h.useState(!1),i=h.useCallback(async()=>{r(!0);try{const o=await fetch("/api/git/generate-commit-message");if(!o.ok){const c=await o.json();throw new Error(c.error||`HTTP ${o.status}`)}return(await o.json()).message}catch(o){return Nm.warn("Failed to generate commit message:",o),null}finally{r(!1)}},[]);return{commit:h.useCallback(async(o,a=!1)=>{t(!0);try{const c=await fetch("/api/git/commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:o,push:a})}),u=await c.json();if(!c.ok&&u.sha)return Nm.warn("Commit succeeded but push failed:",u.details),{sha:u.sha,pushed:!1,pushError:u.details||u.error};if(!c.ok)throw new Error(u.details||u.error||`HTTP ${c.status}`);return Nm.info("Committed successfully:",u.sha),{sha:u.sha,pushed:!!u.pushed}}catch(c){throw Nm.warn("Failed to commit:",c),c}finally{t(!1)}},[]),generateMessage:i,isCommitting:e,isGenerating:n}},P2e=Mt("CommitModal"),I2e=({isOpen:e,onClose:t,onCommitted:n})=>{const r=bs(),{commit:i,generateMessage:s,isCommitting:o,isGenerating:a}=T2e(),[c,u]=h.useState(""),[f,p]=h.useState(null);h.useEffect(()=>{e&&(u(""),s().then(b=>{b&&u(b)}))},[e,s]);const m=h.useCallback(async(b=!1)=>{if(c.trim()){p(b?"push":"commit");try{const x=await i(c.trim(),b);r==null||r.capture("git_commit",{has_push:b,is_pushed:x.pushed,has_push_error:!!x.pushError,message_length:c.trim().length}),n(),t(),x.pushError&&ct.error("Commit succeeded but push failed",{description:x.pushError})}catch(x){r==null||r.capture("git_commit_failed",{has_push:b,error:x instanceof Error?x.message:"unknown"}),P2e.error("Commit failed:",x),ct.error("Commit failed",{description:x instanceof Error?x.message:"Failed to commit"})}finally{p(null)}}},[i,c,n,t,r]),g=h.useCallback(b=>{b.key==="Enter"&&b.metaKey&&(b.preventDefault(),m(!b.shiftKey))},[m]);return y.jsx(Dv,{open:e,onOpenChange:b=>!b&&t(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[420px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Commit Changes"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsxs("div",{className:"relative",children:[y.jsx("textarea",{value:c,onChange:b=>u(b.target.value),onKeyDown:g,placeholder:a?"Generating message...":"Enter commit message",disabled:a,rows:3,className:"w-full resize-none rounded-md bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),a?y.jsx("div",{className:"absolute right-3 top-2.5",children:y.jsx(Ua,{className:"h-4 w-4 animate-spin text-content-subtle",weight:"bold"})}):null]}),y.jsxs("div",{className:"flex gap-2",children:[y.jsx("button",{onClick:()=>m(!1),disabled:o||a||!c.trim(),className:"flex flex-1 items-center justify-center gap-1.5 rounded-md border border-divider px-3 py-2 text-xs text-white transition-colors hover:bg-main-hover disabled:opacity-50",children:f==="commit"?"Committing...":"Commit"}),y.jsx("button",{onClick:()=>m(!0),disabled:o||a||!c.trim(),className:"flex flex-1 items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:f==="push"?"Committing...":"Commit & Push"})]})]})})]})})},LP=Mt("CreateBranchModal"),M2e=({isOpen:e,onClose:t,onCreated:n})=>{const r=bs(),[i,s]=h.useState(""),[o,a]=h.useState(!1),[c,u]=h.useState(!1);h.useEffect(()=>{e&&(s(""),a(!0),fetch("/api/git/generate-branch-name").then(m=>{if(!m.ok)throw new Error(`HTTP ${m.status}`);return m.json()}).then(m=>{s(m.branchName)}).catch(m=>{LP.error("Failed to generate branch name:",m),s("rivet/")}).finally(()=>{a(!1)}))},[e]);const f=h.useCallback(async()=>{if(!i.trim()||c||o)return;u(!0);const m=i.trim();try{const g=await fetch("/api/git/create-branch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branchName:m})});if(!g.ok){const b=await g.json();throw new Error(b.details||b.error||`HTTP ${g.status}`)}n(m),t()}catch(g){const b=g instanceof Error?g.message:"Failed to create branch";r==null||r.capture("git_branch_create_failed",{branch:m,error:b}),ct.error("Failed to create branch",{description:b}),LP.error("Failed to create branch:",g)}finally{u(!1)}},[i,c,o,n,t,r]),p=h.useCallback(m=>{m.key==="Enter"&&(m.preventDefault(),f())},[f]);return y.jsx(Dv,{open:e,onOpenChange:m=>!m&&t(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[420px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Create Branch"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsxs("div",{className:"relative",children:[y.jsx("input",{type:"text",value:i,onChange:m=>s(m.target.value),onKeyDown:p,placeholder:o?"Generating name...":"Enter branch name",disabled:o,className:"w-full rounded-md bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),o?y.jsx("div",{className:"absolute right-3 top-2.5",children:y.jsx(Ua,{className:"h-4 w-4 animate-spin text-content-subtle",weight:"bold"})}):null]}),y.jsx("button",{onClick:f,disabled:c||o||!i.trim(),className:"flex w-full items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:c?"Creating...":"Create"})]})})]})})},R2e=({prUrl:e,branchName:t,isOpen:n,isLoading:r=!1,onClose:i})=>{const s=bs(),o=h.useCallback(a=>{a.key!=="Enter"||a.repeat||r||(a.preventDefault(),e&&(s==null||s.capture("git_pr_link_clicked",{branch:t,pr_url:e,source:"keyboard"}),window.open(e,"_blank","noopener,noreferrer")))},[r,e,s,t]);return h.useEffect(()=>{if(n)return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n,o]),y.jsx(Dv,{open:n,onOpenChange:a=>!a&&i(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsxs(jv,{className:"fixed left-1/2 top-1/2 z-max w-[380px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:[r?y.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[y.jsx(Ua,{className:"h-6 w-6 animate-spin text-primary",weight:"bold"}),y.jsx(lp,{className:"text-sm font-medium text-content",children:"Creating pull request..."})]}):null,r?null:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between gap-3",children:[y.jsx(lp,{className:"whitespace-nowrap text-sm font-semibold text-content",children:"Created Pull Request"}),t?y.jsxs("span",{className:"inline-flex max-w-[180px] shrink-0 items-center gap-1 rounded-md bg-main-input px-2 py-0.5 text-xs text-content-muted",children:[y.jsx(vh,{className:"h-3 w-3 shrink-0",weight:"bold"}),y.jsx("span",{className:"truncate",children:t})]}):null]}),y.jsxs("a",{href:e??"#",target:"_blank",rel:"noopener noreferrer",onClick:()=>{s==null||s.capture("git_pr_link_clicked",{branch:t,pr_url:e,source:"button"})},className:"flex w-full items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover",children:["View PR",y.jsx(r8,{className:"h-3 w-3",weight:"bold"})]})]})]})]})})},NV=({primaryLabel:e,primaryIcon:t,primaryAction:n,isDisabled:r=!1,isLoading:i=!1,loadingLabel:s,dropdownItems:o})=>{const[a,c]=h.useState(!1),u=i?s??e:e;return y.jsxs("div",{className:"flex items-stretch",children:[y.jsxs("button",{onClick:n,disabled:r||i,className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-l-md bg-main-hover px-3 text-xs font-medium text-white transition-colors hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[t?y.jsx(t,{className:"h-3.5 w-3.5",weight:"bold"}):null,u]}),y.jsxs(Fo,{open:a,onOpenChange:c,children:[y.jsx(al,{asChild:!0,children:y.jsx("button",{disabled:i,className:"h-7 flex-shrink-0 rounded-r-md border-l border-white/20 bg-main-hover px-1.5 text-white transition-colors hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:y.jsx(Ba,{className:"h-3.5 w-3.5",weight:"bold"})})}),y.jsx(Oo,{children:y.jsx(Vo,{className:"z-[60] min-w-[140px] rounded-lg border border-divider bg-main p-1 shadow-lg",sideOffset:5,align:"end",children:o.map(f=>{const p=f.icon;return y.jsxs("button",{onClick:()=>{f.isDisabled||(f.onClick(),c(!1))},disabled:f.isDisabled,className:"flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[p?y.jsx(p,{className:"h-3.5 w-3.5",weight:"bold"}):null,f.label]},f.label)})})})]})]})},$2e=h.createContext(null);function D2e(e){switch(e){case"top":return{y:4};case"bottom":return{y:-4};case"left":return{x:4};case"right":return{x:-4}}}function Tk({content:e,children:t,side:n="top",sideOffset:r=8,delayDuration:i=200,className:s,forceOpen:o,onOpenChange:a}){const[c,u]=h.useState(!1),f=o!==void 0?o:c,[p,m]=h.useState(!1),g=Mp(),b=h.useContext($2e);h.useEffect(()=>{f&&m(!0)},[f]);const x=()=>{f||m(!1)},C=D2e(n);return y.jsx(bV,{delayDuration:i,children:y.jsxs(xk,{open:f,onOpenChange:w=>{u(w),a==null||a(w)},children:[y.jsx(wk,{asChild:!0,children:t}),p&&y.jsx(kk,{forceMount:!0,container:b??void 0,children:y.jsx(Ck,{side:n,sideOffset:r,forceMount:!0,className:"z-tooltip",children:y.jsx(mn.div,{className:fr("bg-neutral-900 text-white text-[12px] px-2 py-1 border border-white/10 shadow-lg",g.bg,s),style:{fontVariationSettings:_h.medium},initial:{opacity:0,scale:.8,...C},animate:{opacity:f?1:0,scale:f?1:.9,x:0,y:0},transition:f?{type:"spring",duration:.34,bounce:.55}:{duration:.1},onAnimationComplete:x,children:e})})})]})})}const Fi=({label:e,children:t,side:n="top",sideOffset:r=8,delayDuration:i=300,disabled:s=!1})=>s?y.jsx(y.Fragment,{children:t}):y.jsx(Tk,{content:e,side:n,sideOffset:r,delayDuration:i,children:t}),vx=Mt("GitHome"),N2e=({onClose:e})=>e?y.jsx("div",{className:"z-10 flex h-10 flex-shrink-0 items-center border-b border-main-border bg-main-light px-3",children:y.jsx(Fi,{label:"Close chat",side:"bottom",children:y.jsx("button",{onClick:e,className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})})}):null,L2e=({onUndo:e,isUndoing:t=!1,onClose:n})=>{const r=bs(),s=ke(Qs).branchDiff.isEnabled,{status:o,fetchStatus:a}=q1(),{stats:c}=cV(),{publishChanges:u,isPublishing:f}=Kye(),{pushCommits:p,isPushing:m}=Yye(),[g,b]=h.useState(!1),[x,C]=h.useState(!1),[w,E]=h.useState(!1),[A,T]=h.useState(null),[M,I]=h.useState(null),P=(o==null?void 0:o.branchName)??null,S=(o==null?void 0:o.hasUncommittedChanges)??!1,D=c.totalInsertions>0||c.totalDeletions>0,R=(o==null?void 0:o.canUndo)??!1,L=(o==null?void 0:o.prUrl)??null,j=h.useCallback((Fe,Te,je,nt)=>{Fe==="success"?ct.success(Te,{description:je,action:nt?{label:nt.label,onClick:nt.onClick}:void 0}):Fe==="info"?ct.info(Te,{description:je}):(je&&vx.error(`${Te}:`,je),ct.error(Te))},[]),O=h.useCallback(async()=>{r==null||r.capture("git_pr_create_started",{branch:P}),E(!0),T(null);let Fe=!1;const je=await u((nt,yt,et)=>{nt==="error"&&(Fe=!0,r==null||r.capture("git_pr_create_failed",{branch:P,error:et??yt}),vx.error("Failed to create PR:",et??yt),E(!1),ct.error("Failed to create PR",{description:et??yt}))});je!=null&&je.prUrl?(r==null||r.capture("git_pr_created",{branch:je.branchName,pr_url:je.prUrl}),T(je.prUrl),I(je.branchName),a()):Fe||(r==null||r.capture("git_pr_create_failed",{branch:P,error:"unknown"}),vx.error("Failed to create PR: unknown error"),E(!1),ct.error("Failed to create PR",{description:"Something went wrong creating the pull request."}))},[u,a,r,P]),H=h.useCallback(async()=>{r==null||r.capture("git_push_started",{branch:P});const{success:Fe,error:Te}=await p();Fe?(r==null||r.capture("git_push_succeeded",{branch:P}),j("success","Changes pushed to GitHub")):(r==null||r.capture("git_push_failed",{branch:P,error:Te}),j("error","Failed to push",Te??void 0))},[p,j,r,P]),B=h.useCallback(()=>{L&&(r==null||r.capture("git_pr_opened",{branch:P,pr_url:L}),window.open(L,"_blank","noopener,noreferrer"))},[L,r,P]),Z=h.useCallback(()=>{a(),ct.success("Changes committed")},[a]),K=h.useCallback(Fe=>{r==null||r.capture("git_branch_created",{branch:Fe,from_branch:P}),a(),ct.success("Branch created")},[a,r,P]),q=h.useCallback(()=>{r==null||r.capture("git_commit_modal_opened",{branch:P}),b(!0)},[r,P]),Q=h.useCallback(()=>{r==null||r.capture("git_create_branch_modal_opened",{branch:P}),C(!0)},[r,P]),F=h.useCallback(()=>{r==null||r.capture("git_undo_commit",{branch:P}),e==null||e(j)},[r,P,e,j]),V=S,W=!!L,N=P==="main"&&!V&&!W,z=W?"Go to PR":"Create PR",ee=W?r8:C5,te=W?B:O,re=!W&&!D;let G=V?"Commit":z,X=V?k5:ee,de=V?q:te,ve=V?!1:re;N&&(G="New Branch",X=vh,de=Q,ve=!1);const we=V?[{label:"Undo Commit",icon:Fh,onClick:F,isDisabled:t||!R},{label:"Push Commits",icon:w5,onClick:H,isDisabled:m||!D},{label:z,icon:ee,onClick:te,isDisabled:f||re},{label:"Create New Branch",icon:vh,onClick:Q}]:[{label:"Undo Commit",icon:Fh,onClick:F,isDisabled:t||!R},{label:"Push Commits",icon:w5,onClick:H,isDisabled:m||!D},...N?[{label:"Create PR",icon:C5,onClick:O,isDisabled:!0}]:[{label:"Commit",icon:k5,onClick:q,isDisabled:!S},{label:"Create Branch",icon:vh,onClick:Q}]];return P?y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"z-10 flex h-10 flex-shrink-0 items-center justify-between border-b border-main-border bg-main-light px-3",children:[n&&y.jsxs(y.Fragment,{children:[y.jsx("button",{onClick:n,title:"Close panel",className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})}),y.jsx("div",{className:"mx-1 h-4 w-[1px] flex-shrink-0 bg-divider/20"})]}),y.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 pr-2",children:[y.jsx(g2e,{currentBranch:P,onSwitch:()=>{a()}}),s&&D&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"h-4 w-[1px] flex-shrink-0 bg-divider/20"}),y.jsx(Qye,{})]})]}),y.jsx(NV,{primaryLabel:G,primaryIcon:X,primaryAction:de,isDisabled:ve,isLoading:!1,loadingLabel:"Creating PR...",dropdownItems:we})]}),y.jsx(I2e,{isOpen:g,onClose:()=>b(!1),onCommitted:Z}),y.jsx(M2e,{isOpen:x,onClose:()=>C(!1),onCreated:K}),y.jsx(R2e,{prUrl:A,branchName:M??void 0,isOpen:w,isLoading:f,onClose:()=>E(!1)})]}):n?y.jsx("div",{className:"z-10 flex h-10 flex-shrink-0 items-center border-b border-main-border bg-main-light px-3",children:y.jsx("button",{onClick:n,title:"Close panel",className:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded p-1 text-content-subtle transition-colors hover:bg-main-input hover:text-content",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})}):null},j2e=e=>{const t=ke(x$),r=ke(Qs).gitUi.isEnabled;return!t||!r?y.jsx(N2e,{onClose:e.onClose}):y.jsx(L2e,{...e})},F2e=Mt("SupportTicketModal"),jP=5e3,yx="feedback",O2e=e=>{var r;if(!e)return null;const t=(r=e.formErrors)==null?void 0:r[0];if(t)return t;const n=e.fieldErrors??{};for(const i of Object.values(n)){const s=i==null?void 0:i[0];if(s)return s}return null},V2e=async e=>{let t;try{t=await e.json()}catch{t=void 0}if(e.status===400){if(typeof(t==null?void 0:t.details)=="string"&&t.details.trim())return t.details;if(typeof(t==null?void 0:t.details)=="object"&&t.details!==null){const n=O2e(t.details);if(n)return n}return"Please check your feedback and try again."}return e.status>=500?typeof(t==null?void 0:t.details)=="string"&&t.details.trim()?t.details:"Could not send feedback right now. Please try again later.":typeof(t==null?void 0:t.error)=="string"&&t.error.trim()?t.error:`HTTP ${e.status}`},H2e=({isOpen:e,onClose:t,contactEmail:n})=>{const r=bs(),[i,s]=h.useState(""),[o,a]=h.useState(!1),c=h.useCallback(()=>{s("")},[]),u=h.useCallback(()=>{o||(c(),t())},[o,t,c]),f=h.useCallback(async()=>{const b=i.trim();if(!(!b||o)){a(!0);try{const x=typeof(r==null?void 0:r.get_session_id)=="function"?r.get_session_id():void 0,C=typeof(r==null?void 0:r.get_distinct_id)=="function"?r.get_distinct_id():void 0,w=n==null?void 0:n.trim(),E=await fetch("/api/support/tickets",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:yx,message:b,contactEmail:w||void 0,metadata:{posthogSessionId:x??void 0,posthogDistinctId:C??void 0,appVersion:"0.11.2",appEnvironment:"production",pageUrl:window.location.href,userAgent:navigator.userAgent,submittedAt:new Date().toISOString()}})});if(!E.ok){const A=await V2e(E);throw new Error(A)}r==null||r.capture("support_ticket_submitted",{ticket_type:yx,has_posthog_session_id:!!x}),ct.success("Feedback sent",{description:"Thanks for sharing this."}),c(),t()}catch(x){const C=x instanceof Error?x.message:"Failed to send message";r==null||r.capture("support_ticket_submit_failed",{ticket_type:yx,error:C}),F2e.error("Failed to submit support ticket:",C),ct.error("Could not send feedback",{description:C})}finally{a(!1)}}},[n,o,i,t,r,c]),p=h.useCallback(b=>{b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),f())},[f]),m=jP-i.length,g=o||i.trim().length===0;return y.jsx(Dv,{open:e,onOpenChange:b=>!b&&u(),children:y.jsxs(Nv,{children:[y.jsx(Lv,{className:"fixed inset-0 z-max bg-black/40"}),y.jsx(jv,{className:"fixed left-1/2 top-1/2 z-max w-[480px] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-divider bg-main p-6 shadow-xl outline-none",children:y.jsxs("div",{className:"flex flex-col gap-4",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx(lp,{className:"text-lg font-semibold text-content",children:"Send feedback"}),y.jsx(Ak,{asChild:!0,children:y.jsx("button",{className:"rounded p-1 text-content-subtle transition-colors hover:text-content",disabled:o,children:y.jsx(Ho,{className:"h-4 w-4",weight:"bold"})})})]}),y.jsx("p",{className:"text-sm text-content-subtle",children:"Tell us what happened or what we can improve."}),y.jsxs("div",{className:"space-y-2",children:[y.jsx("label",{htmlFor:"support-ticket-message",className:"text-xs font-medium text-content-muted",children:"Your feedback"}),y.jsx("textarea",{id:"support-ticket-message",value:i,onChange:b=>s(b.target.value),onKeyDown:p,maxLength:jP,rows:7,disabled:o,placeholder:"What happened?",className:"w-full resize-none rounded-md border border-divider bg-main-input px-3 py-2 text-sm text-content outline-none placeholder:text-content-subtle disabled:opacity-50"}),y.jsxs("div",{className:"flex justify-between text-xs text-content-subtle",children:[y.jsx("span",{children:"Context details are included automatically."}),y.jsx("span",{children:m})]})]}),y.jsx("button",{onClick:f,disabled:g,className:"flex w-full items-center justify-center gap-2 rounded-md bg-primary px-3 py-2 text-xs text-white transition-colors hover:bg-primary-hover disabled:opacity-50",children:o?y.jsxs(y.Fragment,{children:[y.jsx(Ua,{className:"h-4 w-4 animate-spin",weight:"bold"}),y.jsx("span",{children:"Sending..."})]}):y.jsx("span",{children:"Send feedback"})})]})})]})})},B2e=Mt("ProfileAvatar"),z2e=(e,t)=>{const n=(e??"").trim();if(n){const i=n.split(/\s+/).filter(Boolean);return i.length>=2?(i[0][0]+i[i.length-1][0]).toUpperCase():i[0].slice(0,2).toUpperCase()}const r=(t??"").split("@")[0]??"";if(r){const i=r.split(/[._\-+]/).filter(Boolean);return i.length>=2?(i[0][0]+i[1][0]).toUpperCase():r.slice(0,2).toUpperCase()}return""},U2e=({className:e=""})=>{const{name:t,email:n}=ke(p$),[r,i]=h.useState(!1),[s,o]=h.useState(!1),[a,c]=h.useState(!1),u=z2e(t,n);if(!u)return null;const f=(t==null?void 0:t.trim())||null,p=(n==null?void 0:n.trim())||null,m=async()=>{c(!0);try{const g=await fetch("/api/auth/logout",{method:"POST",credentials:"same-origin"});if(!g.ok)throw new Error(`Logout failed: ${g.status}`)}catch(g){B2e.warn("Logout request failed",g),ct.error("Could not log out. Please try again."),c(!1);return}window.location.reload()};return y.jsxs(y.Fragment,{children:[y.jsxs(Fo,{open:r,onOpenChange:i,children:[y.jsx(al,{asChild:!0,children:y.jsx("button",{type:"button","aria-label":"Account",className:`flex h-6 w-6 shrink-0 select-none items-center justify-center rounded-full border border-main-border bg-main-input text-[10px] font-semibold leading-none text-content-muted transition-colors hover:text-content ${e}`,children:u})}),y.jsx(Oo,{children:y.jsxs(Vo,{className:"z-[60] min-w-[180px] rounded-lg border border-divider bg-main p-1 shadow-lg",sideOffset:6,align:"end",children:[f||p?y.jsxs("div",{className:"border-b border-main-border px-3 py-2",children:[f?y.jsx("div",{className:"truncate text-xs font-medium text-content",children:f}):null,p?y.jsx("div",{className:"truncate text-[11px] text-content-muted",children:p}):null]}):null,y.jsxs("button",{type:"button",onClick:()=>{i(!1),o(!0)},className:"mt-1 flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input",children:[y.jsx(LI,{className:"h-3.5 w-3.5",weight:"bold"}),"Support & feedback"]}),y.jsxs("button",{type:"button",onClick:m,disabled:a,className:"mt-1 flex w-full items-center gap-2 rounded border border-transparent px-3 py-1.5 text-xs text-content transition-colors hover:border-primary-border hover:bg-main-input disabled:cursor-not-allowed disabled:opacity-50",children:[y.jsx(yG,{className:"h-3.5 w-3.5",weight:"bold"}),a?"Logging out…":"Log out"]})]})})]}),y.jsx(H2e,{isOpen:s,onClose:()=>o(!1),contactEmail:n??void 0})]})},Ut=Mt("ElementInspector"),Z2e=({chatMessages:e,setChatMessages:t,onClose:n})=>{const[r,i]=Vn(Ui),s=ke(Ad),[o]=Vn(U1),{undoLastChange:a,isUndoing:c}=Qie(),{status:u,fetchStatus:f}=q1(),m=ke(Qs).gitUi.isEnabled,g=m?(u==null?void 0:u.canUndo)??!1:!1,b=h.useCallback(async()=>{if(!s||!r)return;await new Promise(E=>requestAnimationFrame(E)),Ut.debug("Refreshing element styles for:",r.tagName);const w=await s.reSelectElement(ND(r));if(w){s.setCurrentElement(w);const E=s.getComputedStyles();s.showSelectionOverlay(w),VD("style_refresh"),i({...r,computedStyles:E})}else Ut.warn("Could not find element for refresh:",r.xpath)},[s,r,i]),x=h.useCallback(async()=>{if(!(o!=null&&o.canUndo()))return!1;const w=await o.undo();return w.ok?(await b(),!0):(Ut.error("Failed to undo:",w.error.message),!1)},[o,b]),C=h.useCallback(async w=>{var A;if(!m||!g||!await a((T,M,I)=>{w?w(T,M,I):T==="success"?ct.success(M,{description:I}):T==="info"?ct.message(M,{description:I}):(I&&Ut.error(`${M}:`,I),ct.error(M))}))return!1;if(await f(),(s==null?void 0:s.type)==="iframe"&&"forceReload"in s){Ut.info("Force reloading iframe after git undo");try{await((A=s.forceReload)==null?void 0:A.call(s))}catch(T){return Ut.error("Iframe reload failed, but git undo succeeded:",T),w==null||w("info","Changes reverted successfully","Please refresh the page to see the updated preview"),!0}}return await b(),!0},[b,g,m,a,f,s]);return y.jsxs("div",{className:"relative flex h-full w-96 cursor-auto flex-col overflow-hidden bg-main font-main shadow-2xl scrollbar-hide","data-cy":"element-inspector",children:[y.jsx(U2e,{className:"absolute right-3 top-2 z-20"}),y.jsx(j2e,{onUndo:C,isUndoing:c,onClose:n}),y.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:y.jsx(W2e,{chatMessages:e,setChatMessages:t,handleUndo:x,refreshElementStyles:b,fetchStatus:f})})]})},W2e=({chatMessages:e,setChatMessages:t,handleUndo:n,refreshElementStyles:r,fetchStatus:i})=>{const s=bs(),[o,a]=Vn(Ui),c=ke(Ad),[u,f]=Vn(ji),p=bc(),m=ke(xp),g=ke(hs),b=ke(wc),x=ke(eo),C=h.useRef(x);C.current=x;const w=h.useMemo(()=>Fie(u,g),[u,g]),E=h.useMemo(()=>{if(!rh(g))return null;const{sessionId:Se,variantId:He}=g;for(const dt of[b==null?void 0:b.left,b==null?void 0:b.right])if(dt&&dt.sessionId===Se&&dt.variantId===He)return dt.label;if(x.active){const dt=x.variants.find(Ze=>Ze.workItemId===He);if(dt)return dt.label}return"Direction"},[g,b,x]),A=ke(F8),[T,M]=Vn(U1);h.useEffect(()=>{if(!c)return;T&&T.destroy();const Se=new zJ(c,A);return M(Se),window.manipulationService=Se,()=>{Se.destroy(),M(null),delete window.manipulationService}},[c,A,M]);const[I,P]=h.useState(null),[S,D]=h.useState(0),R=Be(m$),L=Array.from(u.values()).filter(Se=>Se.status==="pending").length,[j,O]=Vn(ree),[H,B]=h.useState({}),[Z,K]=h.useState(0),q=h.useRef(null),Q=h.useRef(null),F=h.useRef(null),[V,W]=h.useState(0),N=h.useRef({}),z=h.useRef(!1),ee=h.useCallback(Se=>{const He=C.current;He.active&&He.sessionId===Se.sessionId&&$A(Se,He.variants,N.current),z.current=!1,F.current=Se,W(dt=>dt+1)},[]),te=h.useCallback(()=>{F.current!==null&&(F.current=null,W(Se=>Se+1))},[]),re=h.useCallback(Se=>{Q.current=Se,K(He=>He+1)},[]),G=h.useCallback(()=>{const Se=Q.current;Q.current=null,te(),K(He=>He+1),Se&&(Se.changeIds.length>0&&T&&Se.changeIds.forEach(He=>{T.removeTrackedChangeById(He)}),Se.commentIds.length>0&&f(He=>{if(He.size===0)return He;const dt=(m==null?void 0:m.current)??null;if(dt){const Kt=Se.commentIds.map(St=>He.get(St)).filter(St=>St!=null);Vu(dt,Kt)}const Ze=new Map(He);return Se.commentIds.forEach(Kt=>{Ze.delete(Kt)}),Ze}))},[T,f,m,te]),X=h.useCallback(()=>{Q.current=null,te(),K(Se=>Se+1)},[te]),{modifyWithAgent:de,cancelModification:ve,isModifying:we}=pte(),Fe=ke(w$),Te=ke(wp),je=ke(W1),nt=ke(z8),{sendChanges:yt,sendChatMessage:et}=Q$(),{status:ye,resetStatus:Ye}=Gie(),$t=h.useMemo(()=>Tie(ye),[ye]),Tt=ke(B8),{onRoundStarted:Nt,onProgressSteps:yn,onAssistantChunk:nn,onRoundCompleted:he,onRoundFailed:be,onRoundCanceled:We,getActiveAssistantMessageId:ot,getCancellationMessage:lt,setPhase:Vt}=Xie({setChatMessages:t,isMCPSession:Te}),Gt=ke(Js),J=Gt==="comment",Y=ke(Qs).generativeControls.isEnabled,se=ke(Iv),ce=ke(sV),le=Be(lV),ge=Be(aV),Ce=h.useMemo(()=>wie(se,ce),[se,ce]),$e=Be(j8),ut=ke(uc),it=ke(hd),{startRound:Zt,resetPhase:De}=Zie({mcpStatus:ye,isPublishing:j,isMCPSession:Te,setIsPublishing:O,fetchStatus:i,refreshElementStyles:r,getActiveAssistantMessageId:ot,onProgressSteps:yn,onRoundCompleted:he,setSessionUxPhase:Vt,clearQueuedPendingSnapshot:G});h.useEffect(()=>{if(!Te||!j)return;const Se=F.current;if(!Se)return;if(x.active&&x.sessionId===Se.sessionId)z.current=!0;else{if(!z.current)return;X(),O(!1),De(),Vt("idle");const rn=ot();rn&&be({assistantMessageId:rn,error:"Static preview variant refinement was interrupted."});return}const dt=N.current,Ze=Oie(Se,x.variants,dt);if(Ze.status==="pending")return;$A(Se,x.variants,dt);const Kt=Se.variantIds.length>1,St=ot();if(Ze.status==="succeeded"){G(),O(!1),De(),Vt("idle"),St&&he({assistantMessageId:St,finalMessage:Kt?"Static preview variants refined.":"Static preview variant refined."});return}if(X(),O(!1),De(),Vt("idle"),St){let rn;Ze.status==="cancelled"?rn="Static preview variant refinement was cancelled.":Ze.errorCode?rn=`Static preview variant refinement failed (${Ze.errorCode}).`:rn="Static preview variant refinement failed.",be({assistantMessageId:St,error:rn})}},[G,X,ot,Te,j,he,be,De,O,Vt,V,x]),h.useEffect(()=>{o&&(Te||(q.current=null))},[o==null?void 0:o.xpath,Te]);const at=we||j,Ne=Fe,Rt=$ie((o==null?void 0:o.computedStyles)||{});h.useEffect(()=>{var Kt,St;if(!o||!c||c.type!=="iframe")return;let Se=!1;const He=ND(o),dt=((St=(Kt=o.filePaths)==null?void 0:Kt[0])==null?void 0:St.filePath)||void 0;return(async()=>{const rn=await c.reSelectElement(He);if(Se||!rn)return;const wn=Ga();c.injectRivetId(rn,wn);const Un=c.createElementIdentifier(rn);Un.rivetId=wn,Un.filePath=dt,P(Un)})(),()=>{Se=!0}},[o,c]);const bn=ke(z1);h.useEffect(()=>{if(!T)return;const Se=A.getChangeCount();return D(Se),R(Se),A.onChange(()=>{const dt=A.getChangeCount();D(dt),R(dt)})},[A,T,R]);const en=!!o&&!J;h.useEffect(()=>{var dt;const Se=Ze=>{if(!((Ze.metaKey||Ze.ctrlKey)&&Ze.key.toLowerCase()==="z"&&!Ze.shiftKey)||bn.isEditing)return;const St=document.activeElement;St&&(St.tagName==="INPUT"||St.tagName==="TEXTAREA"||St.tagName==="SELECT"||St.getAttribute("contenteditable")==="true")&&!en||(Ze.preventDefault(),Ut.debug("Undo shortcut triggered"),s==null||s.capture("undo"),n())},He=(dt=m==null?void 0:m.current)==null?void 0:dt.contentDocument;return window.addEventListener("keydown",Se),He==null||He.addEventListener("keydown",Se),()=>{window.removeEventListener("keydown",Se),He==null||He.removeEventListener("keydown",Se)}},[en,n,bn.isEditing,m]);const qt=Se=>{Se!==Gt&&(s==null||s.capture("inspector_tab_changed",{from_tab:Gt,to_tab:Se})),$e(Se)};X8({shortcuts:[{key:"1",handler:()=>{Ut.debug("Switching to Styles tab (1)"),qt("edit")},description:"Switch to Styles tab"},{key:"2",handler:()=>{Ut.debug("Switching to Chat tab (2)"),qt("comment")},description:"Switch to Chat tab"},{key:"1",metaKey:!0,handler:()=>{Ut.debug("Switching to Styles tab (Cmd+1)"),qt("edit")},description:"Switch to Styles tab"},{key:"1",ctrlKey:!0,handler:()=>{Ut.debug("Switching to Styles tab (Ctrl+1)"),qt("edit")},description:"Switch to Styles tab"},{key:"2",metaKey:!0,handler:()=>{Ut.debug("Switching to Chat tab (Cmd+2)"),qt("comment")},description:"Switch to Chat tab"},{key:"2",ctrlKey:!0,handler:()=>{Ut.debug("Switching to Chat tab (Ctrl+2)"),qt("comment")},description:"Switch to Chat tab"}]});const pr=h.useCallback(async()=>{var He;if(at)return;zte(),Vu((m==null?void 0:m.current)??null,u.values());const Se=p.get(qa);Se&&(await a1(Se.diff),p.set(qa,null));for(const dt of u.values()){const Ze=(He=dt.finalizedVariant)==null?void 0:He.codeDiff;Ze&&await a1(Ze)}T==null||T.clear(),f(new Map),le()},[at,T,f,m,u,p,le]),Mn=h.useCallback(async()=>{const He=Hie(Te?u:w,T,Ce);if(!He)return;X();const{pendingComments:dt,styleChanges:Ze,textChanges:Kt,pendingSnapshot:St,applyPointers:rn,hasComments:wn,hasDesignChanges:Un,hasInterfaceChanges:bt}=He;if(s==null||s.capture("apply",{comment_count:dt.length,design_edit_count:Ze.length+Kt.length,interface_change_count:He.interfaceChanges.length,has_comments:wn,has_design_changes:Un,has_interface_changes:bt}),Te){$e("comment"),Ye(),O(!0),Zt();const Yt=$b(rn),{assistantMessageId:on}=Nt({userMessage:Yt,startPhase:"starting"});if(Ut.debug("[MCP] new apply round — asstMsgId:",on),re(St),!wn&&!Un&&bt){const Si=await et(Iw(Ce));if(Si.cancelled)return;Si.success||(X(),ct.error(Si.error||"Failed to send changes"),be({assistantMessageId:on,error:Si.error||"Failed to send changes"}),O(!1),De());return}const Bn=await yt();if(Bn.cancelled)return;if(!Bn.success){X(),ct.error(Bn.error||"Failed to send changes"),be({assistantMessageId:on,error:Bn.error||"Failed to send changes"}),O(!1),De();return}bt&&await et(Iw(Ce)),(Bn.changeIdsToClear||Bn.commentIdsToClear)&&re({...St,commentIds:Bn.commentIdsToClear??St.commentIds,changeIds:Bn.changeIdsToClear??St.changeIds}),Bn.staticPreviewVariantIds&&Bn.staticPreviewVariantIds.length>0&&Bn.staticPreviewSessionId&&ee({sessionId:Bn.staticPreviewSessionId,variantIds:Bn.staticPreviewVariantIds});return}$e("comment"),O(!0);const Rn=Bie(He),Lt=zie(He),sr=$b(rn),{assistantMessageId:Xn}=Nt({userMessage:sr,startPhase:"applying"});re(St);const Tc=dt.flatMap(Yt=>Yt.images??[]),Gi=Uie();Ut.debug("Calling modifyWithAgent");let _s=!1;try{await de({instruction:Rn,elements:Array.from(Lt.values()),images:Tc.length>0?Tc:void 0,sessionId:q.current??void 0},{onProgress:Yt=>{if(Gi.recordActivity(),!Yt.startsWith("Agent:")){const on=Yt.match(/^\[([^\]]+)\]/);on&&Gi.recordToolStart(on[1])}},onChunk:Yt=>{Gi.recordActivity(),Gi.recordReasoningChunk(),nn({content:Yt,assistantMessageId:Xn})},onComplete:async Yt=>{var Fp;_s=!0;const on=Gi.finalize();Ut.debug(`modifyWithAgent completed in ${on.agentExecutionDuration}ms`);const Bn=DA(Yt.changes,Yt.filesModified);if(he({assistantMessageId:Xn,finalMessage:Bn}),Yt.sessionId&&(q.current=Yt.sessionId),G(),Un){Ut.debug("Refreshing styles and status");try{await r(),await i()}catch(io){Ut.warn("Style/status refresh failed:",io)}}wn&&Ut.debug("Sent pending comments were cleared after completion."),bt&&le();const Si=Date.now();if((c==null?void 0:c.type)==="iframe"&&"forceReload"in c){Ut.debug("Force reloading iframe");try{await((Fp=c.forceReload)==null?void 0:Fp.call(c))}catch(io){Ut.warn("Iframe reload failed:",io)}}const Wv=Date.now();s==null||s.capture("code_modification",{success:!0,source:"apply",instruction_length:Rn.length,element_count:Lt.size,modification_time_ms:on.agentExecutionDuration}),s==null||s.capture("agent_apply_session",{success:!0,env:"production",total_duration_ms:Gi.elapsed(),agent_execution_duration_ms:on.agentExecutionDuration,tool_execution_duration_ms:on.totalToolDuration,model_reasoning_duration_ms:on.agentExecutionDuration-on.totalToolDuration,time_to_first_message_ms:on.timeToFirstMessage,post_processing_duration_ms:Si-on.agentEndTime,iframe_reload_duration_ms:Wv-Si,model:Yt.model,tool_counts:on.toolCounts,total_tool_calls:Object.values(on.toolCounts).reduce((io,Op)=>io+Op,0),reasoning_chunk_count:on.reasoningChunkCount,element_count:Lt.size,comment_count:dt.length,design_edit_count:S,instruction_length:Rn.length,session_id:Yt.sessionId,server_ttfm_ms:Yt.ttfmMs}),O(!1),De()},onError:async Yt=>{if(_s=!0,Ut.error("Error in modifyWithAgent:",Yt),be({assistantMessageId:Xn,error:Yt}),X(),s==null||s.capture("code_modification",{success:!1,source:"apply",instruction_length:Rn.length,element_count:Lt.size,error_message:Yt}),s==null||s.capture("agent_apply_session",{success:!1,env:"production",total_duration_ms:Gi.elapsed(),error_message:Yt,element_count:Lt.size,instruction_length:Rn.length}),Un)try{await(T==null?void 0:T.clearInlineChanges())}catch(on){Ut.warn("Failed to clear inline changes:",on)}gm(Yt)?vm(Yt):ct.error("Failed to apply changes"),O(!1),De()},onCanceled:()=>{_s=!0,O(!1),De(),X()}})}catch(Yt){_s=!0,Ut.error("Unexpected error in handleApplyAll:",Yt),X();const on=Yt instanceof Error?Yt.message:"An unexpected error occurred";be({assistantMessageId:Xn,error:on}),gm(on)?vm(on):ct.error("Failed to apply changes"),O(!1),De()}finally{_s||(Ut.warn("modifyWithAgent returned without triggering onComplete or onError"),X(),be({assistantMessageId:Xn,error:"Agent request failed to initialize or timed out without feedback."}),ct.error("Failed to apply changes"),O(!1),De())}},[w,u,T,c,de,r,i,S,s,Te,yt,et,Ye,Nt,nn,he,be,$e,Zt,De,O,re,G,X,Ce,le,ee]);h.useEffect(()=>{const Se=He=>{(He.metaKey||He.ctrlKey)&&He.key==="Enter"&&(ut||(L>0||S>0||Ce.length>0)&&!j&&!at&&(He.preventDefault(),Ut.debug("Apply all shortcut triggered (Cmd/Ctrl+Enter)"),Mn()))};return window.addEventListener("keydown",Se),()=>window.removeEventListener("keydown",Se)},[L,S,Ce,j,at,ut,Mn]);const ir=h.useCallback(async(Se,He)=>{var Kt;if(!T||!I||!c||c.type!=="iframe")return;const Ze=((Kt=Rt[Se])==null?void 0:Kt.type)==="range"?(parseFloat(He)/100).toString():He;await T.previewStyleChange(I,Se,Ze)},[T,I,c,Rt]),cn=h.useCallback(async(Se,He,dt)=>{var wn;const Ze=He;if(!Ze||!T||!I||!o||!c||c.type!=="iframe")return;const St=((wn=Rt[Se])==null?void 0:wn.type)==="range"?(parseFloat(Ze)/100).toString():Ze,rn=await T.applyStyleChange(I,o,Se,St,dt);if(rn.ok){const Un=await c.getComputedStylesForElement(I);Un.ok&&a({...o,computedStyles:Un.value}),B(Rn=>{const Lt={...Rn};return delete Lt[Se],Lt});const bt=Mw.find(Rn=>Rn.properties.some(Lt=>Lt.key===Se));s==null||s.capture("design_property_changed",{property:Se,category:bt==null?void 0:bt.value})}else Ut.error("Failed to apply style:",rn.error.message),ct.error("Failed to apply style")},[T,I,o,c,Rt,B,a,s]),Hn=h.useCallback(async Se=>{T&&await T.transaction(Se)},[T]),Ss=(Se,He)=>{B(dt=>({...dt,[Se]:He}))},Hd=(Se,He)=>{const dt=He.replace("%","").trim();if(dt===""){B(St=>({...St,[Se]:""}));return}const Ze=parseFloat(dt);if(Number.isNaN(Ze))return;const Kt=Math.max(0,Math.min(100,Ze));B(St=>({...St,[Se]:Kt.toString()}))},Bv=Se=>{B(He=>{const dt={...He};return delete dt[Se],dt})},zv=h.useCallback(async()=>{if(!T)return;const Se=await T.redo();Se.ok?await r():Ut.error("Failed to redo:",Se.error.message)},[T,r]),Uv=h.useCallback(()=>{const Se=lt();Te&&je==="embedded"&&fetch("/api/agent/stop",{method:"POST",headers:nt?{"x-rivet-queue-token":nt}:void 0}).catch(He=>{Ut.warn("Failed to stop embedded agent run:",He)}),ve(),O(!1),De(),X(),We({cancellationMessage:Se})},[ve,O,De,X,We,lt,Te,je,nt]),ro=h.useCallback(async(Se,He)=>{Ye();const dt=Date.now();X();const Ze=Array.from(u.values()).filter(Lt=>Lt.status==="pending"),Kt=Ze.length>0,St=Ze.map(Lt=>({id:Lt.id,instruction:Lt.instruction})),rn=jD({pendingComments:St,styleChanges:[],textChanges:[],includeComments:Kt,includeChanges:!1});s==null||s.capture("chat",{message_length:Se.length,has_images:!!(He!=null&&He.length),image_count:(He==null?void 0:He.length)??0,has_pending_comments:Kt,pending_comment_count:Ze.length,has_selected_element:!!o});const wn=Kt?FD(Ze):Se,Un=Kt?LD(Ze,[],[]):[],bt=Kt&&Un.length>0?$b(Un):Se,{assistantMessageId:Rn}=Nt({userMessage:bt,images:He,startPhase:Te?"starting":"applying"});rn.commentIds.length>0&&re(rn);try{if(Te){Ye(),O(!0),Zt();const Lt=await et(wn,He);if(Lt.cancelled)return;Lt.success||(X(),be({assistantMessageId:Rn,error:Lt.error||"Failed to send to Claude Code"}),O(!1),De())}else if(Ne){const Lt=o?[o]:[];await de({instruction:wn,elements:Lt,images:He,sessionId:q.current??void 0},{onProgress:()=>{},onChunk:sr=>{nn({content:sr,assistantMessageId:Rn})},onComplete:async({sessionId:sr,changes:Xn,filesModified:Tc})=>{var _s;const Gi=DA(Xn,Tc);if(he({assistantMessageId:Rn,finalMessage:Gi}),G(),s==null||s.capture("code_modification",{success:!0,source:"chat",instruction_length:wn.length,element_count:Lt.length,modification_time_ms:Date.now()-dt}),sr&&(q.current=sr),Kt&&Ut.debug("Sent pending comments were cleared after completion."),(c==null?void 0:c.type)==="iframe"&&"forceReload"in c)try{await((_s=c.forceReload)==null?void 0:_s.call(c))}catch(Yt){Ut.warn("Iframe reload after agent modification failed:",Yt)}r()},onError:sr=>{X(),be({assistantMessageId:Rn,error:sr}),s==null||s.capture("code_modification",{success:!1,source:"chat",instruction_length:wn.length,element_count:Lt.length,error_message:sr,modification_time_ms:Date.now()-dt}),Ut.error("Code modification error details:",sr),gm(sr)?vm(sr):ct.error("Code Modification Error")},onCanceled:()=>{O(!1),De(),X()}})}else Ut.error("Chat mode not supported"),ct.error("Chat mode not supported")}catch(Lt){Ut.error("Error with streaming request:",Lt);const sr=Lt instanceof Error?Lt.message:"An unexpected error occurred.";X(),O(!1),De(),be({assistantMessageId:Rn,error:sr}),gm(sr)?vm(sr):ct.error("Failed to generate AI response")}},[Ye,u,T,s,o,Te,et,Ne,de,c,r,Nt,nn,he,be,Zt,De,O,re,G,X]),Wi=h.useMemo(()=>{const Se=Array.from(w.values()).filter(bt=>bt.status==="pending"),He=(T==null?void 0:T.getStyleChanges())??[],dt=(T==null?void 0:T.getTextChanges())??[],Ze=He.map(bt=>({id:bt.id,key:rc(bt),property:String(bt.property),newValue:bt.newValue,timestamp:bt.timestamp})),Kt=dt.map(bt=>({id:bt.id,key:rc(bt),oldText:bt.oldText,newText:bt.newText,timestamp:bt.timestamp})),St=jie(Se.map(bt=>({id:bt.id,instruction:bt.instruction,finalizedVariant:bt.finalizedVariant,styleVariants:bt.styleVariants,selectedVariantIndex:bt.selectedVariantIndex,variantGenerationStatus:bt.variantGenerationStatus,requestedVariantCount:bt.requestedVariantCount})),Ze,Kt);for(const bt of Ce)St.push({id:bt.id,kind:"interface",detail:DD(bt)});const rn=Q.current;if(!at||!rn)return St;const wn=new Set(rn.commentIds),Un=new Map;return Ze.forEach(bt=>{Un.set(bt.id,bt.key)}),Kt.forEach(bt=>{Un.set(bt.id,bt.key)}),rn.changeIds.forEach(bt=>{const Rn=Un.get(bt);Rn&&wn.add(Rn)}),St.filter(bt=>!wn.has(bt.id))},[w,S,T,at,Z,Ce]),Ac=h.useCallback(async Se=>{if(Se.kind==="interface"){ge({controlId:Se.id,value:void 0});return}if(Se.kind==="comment"){f(Kt=>{const St=Kt.get(Se.id),rn=(m==null?void 0:m.current)??null;rn&&(St==null?void 0:St.previewBaselineStyle)!==void 0&&Vu(rn,[St]);const wn=new Map(Kt);return wn.delete(Se.id),wn});return}if(!T)return;const dt=T.getChanges().find(Kt=>rc(Kt)===Se.id);if(!dt){Ut.warn("No tracked change for pending row",Se.id);return}const Ze=await T.revertSpecificChange(dt);if(!Ze.ok){Ut.error("revertSpecificChange failed:",Ze.error.message),ct.error("Could not revert change");return}await r()},[T,f,r,m,ge]),Uo=Te?$t||(j&&(ye==null?void 0:ye.status)!=="APPLYING"?Eie:j?Cie:null):null,Lp=y.jsx(J0e,{chatMessages:e,statusHint:Uo,handleChatSend:ro,handleStop:Uv,isProcessing:at,pendingChangeRows:Wi,onRemovePendingChange:Ac,onApplyPendingChanges:Mn,onClearPendingChanges:pr,disableInputWhileProcessing:je!=="embedded",showModelPicker:je!=="embedded"}),jp=y.jsxs("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center px-6 text-center",children:[y.jsx("p",{className:"text-sm text-content-subtle",children:"Select an element to edit, or leave a comment on the page."}),Uo&&y.jsx("p",{className:"mt-2 text-xs text-content-subtle",children:Uo})]});return(()=>{const Se=_ie({isMCPSession:Te,isChatOpen:J,hasSelectedElement:!!o,isVariantsPanelOpen:it,hasPendingChanges:Wi.length>0,changeCount:S,isPublishing:j,isProcessing:at,hasStatusHint:!!Uo,shouldUseAgentChat:je==="embedded"}),He=o?y.jsx(fye,{propertyCategories:Mw,formattedComputedStyles:Rt,pendingChanges:H,handlePendingCssChange:Ss,handlePendingPercentageChange:Hd,applyPropertyChange:cn,previewPropertyChange:ir,performTransaction:Hn,handleBlur:Bv},o.xpath):null,dt=Y&&Gt==="edit"?y.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col",children:[y.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto scrollbar-hide",children:[y.jsx(Vye,{}),Se.showDesignPanel?He:null]}),Wi.length>0?y.jsx("div",{className:"flex-shrink-0 border-t border-main-border px-3 py-2",children:y.jsx(t6,{tags:Wi,onRemoveTag:Ac,onClearAll:pr,canClear:!j&&!at})}):null,y.jsx(Wye,{})]}):Gt==="edit"&&Se.showDesignPanel&&He?He:it?y.jsx(Qee,{}):Se.showChatPanel?Lp:Se.showDesignPanel?He:Se.showMCPEmptyState?jp:null,Ze=Wi.length;return y.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col",children:[E&&!it?y.jsx("div",{className:"flex flex-shrink-0 items-center border-b border-main-border bg-main-light px-4 py-1.5 text-xs text-content-subtle",children:y.jsxs("span",{className:"truncate",children:["Editing"," ",y.jsx("span",{className:"font-medium text-content",children:E})]})}):null,dt,Se.showExternalPendingChanges&&y.jsx("div",{className:"flex-shrink-0 border-t border-main-border px-4 py-2",children:y.jsx(t6,{tags:Wi,onRemoveTag:Ac,onClearAll:pr,canClear:!j&&!at})}),Se.showExternalStatusHint&&Uo&&y.jsx("div",{className:`flex-shrink-0 px-4 py-2 ${Wi.length===0?"border-t border-main-border":""}`,children:y.jsx("p",{className:"text-center text-xs text-content-subtle",children:Uo})}),(Se.showActionBar||Y&&Gt==="edit"&&Wi.length>0)&&y.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-t border-main-border bg-main-light px-4 py-3",children:[y.jsxs("div",{className:"flex gap-2",children:[y.jsx("button",{onClick:n,disabled:!(T!=null&&T.canUndo()),className:"rounded p-1.5 text-content transition-colors hover:bg-main-hover disabled:cursor-not-allowed disabled:opacity-30",title:"Undo (Cmd+Z)",children:y.jsx(Fh,{className:"h-4 w-4"})}),y.jsx("button",{onClick:zv,disabled:!(T!=null&&T.canRedo()),className:"rounded p-1.5 text-content transition-colors hover:bg-main-hover disabled:cursor-not-allowed disabled:opacity-30",title:"Redo (Cmd+Shift+Z)",children:y.jsx(uG,{className:"h-4 w-4"})})]}),y.jsx("button",{onClick:Mn,disabled:j||at,className:"rounded border border-primary px-3 py-1 text-xs font-medium text-gray-300 hover:bg-primary-hover disabled:cursor-not-allowed disabled:opacity-30",title:Te?`Send ${Ze||"pending"} changes to ${Tt||"Claude Code"}`:"Apply all pending changes (⌘↵)","data-cy":"inspector-apply-button",children:Aie({isMCPSession:Te,isApplying:j||at,pendingChangeCount:Ze})})]})]})})()},G2e=Mt("useServerConfig"),q2e=()=>{const[e,t]=h.useState(null),[n,r]=h.useState(!0),[i,s]=h.useState(null),o=h.useCallback(async()=>{var a;try{r(!0),s(null);const c=await fetch("/api/health");if(!c.ok)throw new Error(`Failed to fetch config: ${c.status}`);const u=await c.json();if(!u.framework)throw new Error("Server did not return framework information");const f={userPort:((a=u.ports)==null?void 0:a.userDevServer)||3e3,framework:u.framework};return t(f),f}catch(c){const u=c instanceof Error?c.message:"Failed to fetch server config";throw s(u),G2e.warn("Error fetching server config:",c),c}finally{r(!1)}},[]);return{config:e,fetchConfig:o,isLoading:n,error:i}},K2e="data:image/svg+xml,%3csvg%20width='453'%20height='416'%20viewBox='0%200%20453%20416'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20clip-path='url(%23clip0_1326_108)'%3e%3cpath%20d='M186.07%2025.5539C186.07%2011.4409%20197.511%200%20211.624%200H335.5C400.393%200%20453%2052.6065%20453%20117.5C453%20182.393%20400.393%20235%20335.5%20235H216.639C199.756%20235%20186.07%20221.314%20186.07%20204.431C186.07%20186.743%20198.071%20169.863%20215.299%20165.853C225.291%20163.528%20238.671%20160.53%20256.58%20156.667C258.587%20156.234%20260.54%20155.796%20262.442%20155.354C307.627%20144.861%20299.146%20103.217%20256.58%2084.7815C234.082%2075.0381%20218.731%2068.1115%20208.265%2063.1881C194.851%2056.8779%20186.07%2040.378%20186.07%2025.5539Z'%20fill='white'/%3e%3cpath%20d='M381.709%20415.715C329.789%20415.715%20287.699%20373.625%20287.699%20321.705V314.306C287.699%20288.346%20308.744%20267.301%20334.704%20267.301C386.624%20267.301%20428.714%20309.391%20428.714%20361.311V368.71C428.714%20394.67%20407.669%20415.715%20381.709%20415.715Z'%20fill='white'/%3e%3cpath%20d='M0%2073.5927C0%2033.1632%2032.7745%200.388672%2073.2039%200.388672C113.633%200.388672%20146.408%2033.1632%20146.408%2073.5926V338.795C146.408%20379.225%20113.633%20411.999%2073.2039%20411.999C32.7745%20411.999%200%20379.225%200%20338.795V73.5927Z'%20fill='white'/%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='clip0_1326_108'%3e%3crect%20width='453'%20height='416'%20fill='white'/%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",Lm=(e,t)=>y.jsxs("div",{className:"flex flex-row items-center gap-2",children:[y.jsx("span",{children:e}),t?y.jsx("span",{className:"rounded bg-white/15 px-1.5 py-0.5 text-[10px] leading-none font-bold",children:t}):null]}),Y2e={type:"spring",duration:.3,bounce:0},X2e=({mode:e,onModeChange:t,isLoading:n=!1,disabled:r=!1})=>{const[i,s]=h.useState(!1),o=ke(ji),a=ke(m$),[c,u]=Vn(bp);ke(Ui);const f=Be(Ui),p=Be(Js),m=Be(E$),g=ke(hd),b=Be(hd),x=ke(eo),C=e!=="view"||i||g,E=Array.from(o.values()).filter(P=>P.status==="pending").length+a,A=()=>{c?u(!1):(u(!0),g||(f(null),p("comment"),m(P=>P+1)))},T=()=>{g||(b(!0),u(!0),p("comment"),vt.capture("variants_panel.opened",{source:"control_bar",hasActiveSession:x.active}))},M=c?"Close panel":"Open panel",I=(P,S,D,R,L)=>{const j=r?"Disconnected":S,O=e===P&&!g;return y.jsx(Fi,{label:Lm(j,r?void 0:D),disabled:!C,children:y.jsx("button",{type:"button",onClick:H=>{H.stopPropagation(),b(!1),u(!0),t(P)},disabled:r,className:`rounded-md p-2 transition-colors ${O?"bg-primary/20 text-primary":"text-content hover:bg-main-input"} ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":L,children:R})})};return y.jsxs(mn.div,{className:"z-ui-primary absolute right-6 bottom-6",initial:{y:100,opacity:0},animate:{y:n?100:0,opacity:n?0:1},transition:{duration:.6,ease:"easeOut",delay:n?0:.3},children:[E>0&&!C&&!g&&y.jsx(mn.span,{className:"bg-primary pointer-events-none absolute -top-1 -right-1 z-10 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[9px] leading-none font-bold text-white",animate:{opacity:1},transition:{duration:.15,delay:.2},children:E>9?"9+":E}),y.jsxs(mn.div,{layout:!0,className:`border-primary/30 bg-main overflow-hidden border shadow-lg ${C?"":"cursor-pointer"}`,style:{borderRadius:C?10:9999},transition:Y2e,onClick:C?void 0:()=>t("comment"),onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[y.jsx(mn.div,{className:"absolute flex items-center justify-center",style:{width:40,height:40,top:0,left:0},animate:{opacity:C?0:1},transition:C?{duration:0}:{duration:0,delay:.2},"aria-hidden":C,children:y.jsx("img",{src:K2e,alt:"Rivet",style:{width:16,height:16}})}),!C&&y.jsx("div",{style:{width:40,height:40}}),y.jsxs(mn.div,{className:"flex items-center gap-1 p-2",style:{position:C?"relative":"absolute",inset:0,pointerEvents:C?"auto":"none"},animate:{opacity:C?1:0},transition:C?{duration:0,delay:.22}:{duration:0},children:[y.jsx(Fi,{label:Lm(r?"Disconnected":"Explore",r?void 0:"E"),disabled:!C,children:y.jsxs("button",{type:"button",onClick:P=>{P.stopPropagation(),T()},disabled:r,className:`relative rounded-md p-2 transition-colors ${g?"bg-primary/20 text-primary":"text-content hover:bg-main-input"} ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"open-variants",children:[y.jsx(s8,{className:"h-5 w-5",weight:"bold"}),x.active&&!g&&y.jsx("span",{className:"bg-primary absolute -top-0.5 -right-0.5 h-2 w-2 rounded-full","aria-label":"Active explore session"})]})}),I("edit","Refine","R",y.jsx(xG,{className:"h-5 w-5"}),"mode-design"),y.jsx("div",{className:"bg-primary/20 mx-1 h-4 w-px"}),y.jsx(Fi,{label:Lm(r?"Disconnected":M,r?void 0:"P"),disabled:!C,children:y.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),A()},disabled:r,className:`text-content hover:bg-main-input relative rounded-md p-2 transition-colors ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"open-panel",children:y.jsx(Oh,{className:"h-5 w-5",weight:"bold",style:c?{transform:"scaleX(-1)"}:void 0})})}),y.jsx(Fi,{label:Lm(r?"Disconnected":"Collapse",r?void 0:"X"),disabled:!C,children:y.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),t("view"),b(!1),u(!1),s(!1)},disabled:r,"aria-label":"Collapse",className:`text-content hover:bg-main-input rounded-md p-2 transition-colors ${r?"cursor-not-allowed opacity-50":""}`,"data-cy":"mode-view",children:y.jsx(Ho,{className:"h-5 w-5",weight:"bold"})})})]})]})]})},Q2e=async()=>{let e;try{e=await fetch("/api/mcp/status")}catch{return{isOk:!1,unavailableReason:"rivet_unreachable"}}if(e.status===404||!(e.headers.get("content-type")??"").toLowerCase().includes("application/json"))return jm();if(!e.ok)return{isOk:!1,unavailableReason:"rivet_unreachable"};let n;try{n=await e.json()}catch{return jm()}const r=n.devServerHealth;return r?r.ownership==="none"?{isOk:!1,unavailableReason:"upstream_unreachable"}:r.isReachable===!0?{isOk:!0,unavailableReason:"upstream_unreachable"}:{isOk:!1,unavailableReason:r.reason==="rivet_unreachable"?"rivet_unreachable":"upstream_unreachable"}:jm()},jm=async()=>{try{const e=await fetch("/");return{isOk:e.status!==502&&e.status!==503,unavailableReason:"upstream_unreachable"}}catch{return{isOk:!1,unavailableReason:"rivet_unreachable"}}},FP=Mt("usePreviewUpstreamHealth"),J2e=500,ebe=4e3,tbe=15e3,nbe=(e,t={})=>{const n=h.useRef(null),r=h.useRef(null),i=t.probeMsWhileDown??J2e,s=t.probeMsWhileUp??ebe,o=t.firstUnreachableCaptureAfterMs??tbe,a=t.rerunProbeImmediatelyOnVersion,c=t.skip??!1,[u,f]=h.useState(e==="static"),[p,m]=h.useState(0),[g,b]=h.useState(null),[x,C]=h.useState(0),[w,E]=h.useState(!1),[A,T]=h.useState(!1),[M,I]=h.useState(e==="static"?null:"upstream_unreachable");return h.useEffect(()=>{if(e==="static"){f(!0),b(null),C(0),E(!1),T(!0),I(null);return}if(c){f(!1),b(null),C(0),E(!1),T(!0),I("upstream_unreachable"),n.current=null;return}let P=!0;const S=Date.now();b(S),C(0),E(!1),f(!1),T(!1),I("upstream_unreachable");const D={current:!1},R={current:!1},L={current:!1},j={current:null},O={current:!1};let H=null;const B=()=>{L.current||(L.current=!0,P&&T(!0))},Z=()=>{H!==null&&(clearTimeout(H),H=null)},K=(Q,F)=>{Z(),H=setTimeout(F,Q)},q=async()=>{if(!P)return;C(N=>N+1);const{isOk:Q,unavailableReason:F}=await Q2e();if(!P)return;if(B(),Q){const N=!O.current;O.current=!0,f(!0),I(null),j.current=null,R.current=!1,E(!1),D.current?N&&(vt==null||vt.capture("preview_upstream_restored",{framework:e})):(D.current=!0,vt==null||vt.capture("preview_dev_server_ready",{framework:e,ready_after_ms:Date.now()-S})),K(s,q);return}const V=O.current;O.current=!1,f(!1),I(F),j.current===null&&(j.current=Date.now(),R.current=!1,E(!1)),V&&(vt==null||vt.capture("preview_upstream_lost",{framework:e}),m(N=>N+1),FP.warn("Preview upstream became unavailable after it was ready"));const W=Date.now()-j.current;W>=o&&!R.current&&(R.current=!0,E(!0),vt==null||vt.capture("preview_dev_server_unreachable",{framework:e,elapsed_ms:W}),FP.warn("Dev server did not become ready within timeout window")),K(i,q)};return n.current=()=>K(0,q),K(0,q),()=>{P=!1,n.current=null,Z()}},[e,i,s,o,c]),h.useEffect(()=>{var S;if(e==="static"||a===void 0)return;const P=r.current;r.current=a,P!==null&&P!==a&&((S=n.current)==null||S.call(n))},[e,a]),{isUpstreamReady:u,iframeRemountKey:p,probeStartedAt:g,probeAttemptCount:x,isFirstUnreachableWindowExceeded:w,initialProbeComplete:A,unavailableReason:M}};function rbe(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const n=document.implementation.createHTMLDocument(),r=n.createElement("base"),i=n.createElement("a");return n.head.appendChild(r),n.body.appendChild(i),t&&(r.href=t),i.href=e,i.href}const ibe=(()=>{let e=0;const t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function Va(e){const t=[];for(let n=0,r=e.length;n<r;n++)t.push(e[n]);return t}let mu=null;function LV(e={}){return mu||(e.includeStyleProperties?(mu=e.includeStyleProperties,mu):(mu=Va(window.getComputedStyle(document.documentElement)),mu))}function T1(e,t){const r=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return r?parseFloat(r.replace("px","")):0}function sbe(e){const t=T1(e,"border-left-width"),n=T1(e,"border-right-width");return e.clientWidth+t+n}function obe(e){const t=T1(e,"border-top-width"),n=T1(e,"border-bottom-width");return e.clientHeight+t+n}function jV(e,t={}){const n=t.width||sbe(e),r=t.height||obe(e);return{width:n,height:r}}function abe(){let e,t;try{t=process}catch{}const n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}const hi=16384;function lbe(e){(e.width>hi||e.height>hi)&&(e.width>hi&&e.height>hi?e.width>e.height?(e.height*=hi/e.width,e.width=hi):(e.width*=hi/e.height,e.height=hi):e.width>hi?(e.height*=hi/e.width,e.width=hi):(e.width*=hi/e.height,e.height=hi))}function P1(e){return new Promise((t,n)=>{const r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=n,r.crossOrigin="anonymous",r.decoding="async",r.src=e})}async function cbe(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function ube(e,t,n){const r="http://www.w3.org/2000/svg",i=document.createElementNS(r,"svg"),s=document.createElementNS(r,"foreignObject");return i.setAttribute("width",`${t}`),i.setAttribute("height",`${n}`),i.setAttribute("viewBox",`0 0 ${t} ${n}`),s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("externalResourcesRequired","true"),i.appendChild(s),s.appendChild(e),cbe(i)}const si=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||si(n,t)};function dbe(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function fbe(e,t){return LV(t).map(n=>{const r=e.getPropertyValue(n),i=e.getPropertyPriority(n);return`${n}: ${r}${i?" !important":""};`}).join(" ")}function hbe(e,t,n,r){const i=`.${e}:${t}`,s=n.cssText?dbe(n):fbe(n,r);return document.createTextNode(`${i}{${s}}`)}function OP(e,t,n,r){const i=window.getComputedStyle(e,n),s=i.getPropertyValue("content");if(s===""||s==="none")return;const o=ibe();try{t.className=`${t.className} ${o}`}catch{return}const a=document.createElement("style");a.appendChild(hbe(o,n,i,r)),t.appendChild(a)}function pbe(e,t,n){OP(e,t,":before",n),OP(e,t,":after",n)}const VP="application/font-woff",HP="image/jpeg",mbe={woff:VP,woff2:VP,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:HP,jpeg:HP,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function gbe(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function Pk(e){const t=gbe(e).toLowerCase();return mbe[t]||""}function vbe(e){return e.split(/,/)[1]}function E6(e){return e.search(/^(data:)/)!==-1}function ybe(e,t){return`data:${t};base64,${e}`}async function FV(e,t,n){const r=await fetch(e,t);if(r.status===404)throw new Error(`Resource "${r.url}" not found`);const i=await r.blob();return new Promise((s,o)=>{const a=new FileReader;a.onerror=o,a.onloadend=()=>{try{s(n({res:r,result:a.result}))}catch(c){o(c)}},a.readAsDataURL(i)})}const bx={};function bbe(e,t,n){let r=e.replace(/\?.*/,"");return n&&(r=e),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),t?`[${t}]${r}`:r}async function Ik(e,t,n){const r=bbe(e,t,n.includeQueryParams);if(bx[r]!=null)return bx[r];n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let i;try{const s=await FV(e,n.fetchRequestInit,({res:o,result:a})=>(t||(t=o.headers.get("Content-Type")||""),vbe(a)));i=ybe(s,t)}catch(s){i=n.imagePlaceholder||"";let o=`Failed to fetch resource: ${e}`;s&&(o=typeof s=="string"?s:s.message),o&&console.warn(o)}return bx[r]=i,i}async function xbe(e){const t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):P1(t)}async function wbe(e,t){if(e.currentSrc){const s=document.createElement("canvas"),o=s.getContext("2d");s.width=e.clientWidth,s.height=e.clientHeight,o==null||o.drawImage(e,0,0,s.width,s.height);const a=s.toDataURL();return P1(a)}const n=e.poster,r=Pk(n),i=await Ik(n,r,t);return P1(i)}async function kbe(e,t){var n;try{if(!((n=e==null?void 0:e.contentDocument)===null||n===void 0)&&n.body)return await Fv(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function Cbe(e,t){return si(e,HTMLCanvasElement)?xbe(e):si(e,HTMLVideoElement)?wbe(e,t):si(e,HTMLIFrameElement)?kbe(e,t):e.cloneNode(OV(e))}const Ebe=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",OV=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function Sbe(e,t,n){var r,i;if(OV(t))return t;let s=[];return Ebe(e)&&e.assignedNodes?s=Va(e.assignedNodes()):si(e,HTMLIFrameElement)&&(!((r=e.contentDocument)===null||r===void 0)&&r.body)?s=Va(e.contentDocument.body.childNodes):s=Va(((i=e.shadowRoot)!==null&&i!==void 0?i:e).childNodes),s.length===0||si(e,HTMLVideoElement)||await s.reduce((o,a)=>o.then(()=>Fv(a,n)).then(c=>{c&&t.appendChild(c)}),Promise.resolve()),t}function _be(e,t,n){const r=t.style;if(!r)return;const i=window.getComputedStyle(e);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):LV(n).forEach(s=>{let o=i.getPropertyValue(s);s==="font-size"&&o.endsWith("px")&&(o=`${Math.floor(parseFloat(o.substring(0,o.length-2)))-.1}px`),si(e,HTMLIFrameElement)&&s==="display"&&o==="inline"&&(o="block"),s==="d"&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),r.setProperty(s,o,i.getPropertyPriority(s))})}function Abe(e,t){si(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),si(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function Tbe(e,t){if(si(e,HTMLSelectElement)){const r=Array.from(t.children).find(i=>e.value===i.getAttribute("value"));r&&r.setAttribute("selected","")}}function Pbe(e,t,n){return si(t,Element)&&(_be(e,t,n),pbe(e,t,n),Abe(e,t),Tbe(e,t)),t}async function Ibe(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(n.length===0)return e;const r={};for(let s=0;s<n.length;s++){const a=n[s].getAttribute("xlink:href");if(a){const c=e.querySelector(a),u=document.querySelector(a);!c&&u&&!r[a]&&(r[a]=await Fv(u,t,!0))}}const i=Object.values(r);if(i.length){const s="http://www.w3.org/1999/xhtml",o=document.createElementNS(s,"svg");o.setAttribute("xmlns",s),o.style.position="absolute",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.display="none";const a=document.createElementNS(s,"defs");o.appendChild(a);for(let c=0;c<i.length;c++)a.appendChild(i[c]);e.appendChild(o)}return e}async function Fv(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(r=>Cbe(r,t)).then(r=>Sbe(e,r,t)).then(r=>Pbe(e,r,t)).then(r=>Ibe(r,t))}const VV=/url\((['"]?)([^'"]+?)\1\)/g,Mbe=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Rbe=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function $be(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function Dbe(e){const t=[];return e.replace(VV,(n,r,i)=>(t.push(i),n)),t.filter(n=>!E6(n))}async function Nbe(e,t,n,r,i){try{const s=n?rbe(t,n):t,o=Pk(t);let a;return i||(a=await Ik(s,o,r)),e.replace($be(t),`$1${a}$3`)}catch{}return e}function Lbe(e,{preferredFontFormat:t}){return t?e.replace(Rbe,n=>{for(;;){const[r,,i]=Mbe.exec(n)||[];if(!i)return"";if(i===t)return`src: ${r};`}}):e}function HV(e){return e.search(VV)!==-1}async function BV(e,t,n){if(!HV(e))return e;const r=Lbe(e,n);return Dbe(r).reduce((s,o)=>s.then(a=>Nbe(a,o,t,n)),Promise.resolve(r))}async function gu(e,t,n){var r;const i=(r=t.style)===null||r===void 0?void 0:r.getPropertyValue(e);if(i){const s=await BV(i,null,n);return t.style.setProperty(e,s,t.style.getPropertyPriority(e)),!0}return!1}async function jbe(e,t){await gu("background",e,t)||await gu("background-image",e,t),await gu("mask",e,t)||await gu("-webkit-mask",e,t)||await gu("mask-image",e,t)||await gu("-webkit-mask-image",e,t)}async function Fbe(e,t){const n=si(e,HTMLImageElement);if(!(n&&!E6(e.src))&&!(si(e,SVGImageElement)&&!E6(e.href.baseVal)))return;const r=n?e.src:e.href.baseVal,i=await Ik(r,Pk(r),t);await new Promise((s,o)=>{e.onload=s,e.onerror=t.onImageErrorHandler?(...c)=>{try{s(t.onImageErrorHandler(...c))}catch(u){o(u)}}:o;const a=e;a.decode&&(a.decode=s),a.loading==="lazy"&&(a.loading="eager"),n?(e.srcset="",e.src=i):e.href.baseVal=i})}async function Obe(e,t){const r=Va(e.childNodes).map(i=>zV(i,t));await Promise.all(r).then(()=>e)}async function zV(e,t){si(e,Element)&&(await jbe(e,t),await Fbe(e,t),await Obe(e,t))}function Vbe(e,t){const{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);const r=t.style;return r!=null&&Object.keys(r).forEach(i=>{n[i]=r[i]}),e}const BP={};async function zP(e){let t=BP[e];if(t!=null)return t;const r=await(await fetch(e)).text();return t={url:e,cssText:r},BP[e]=t,t}async function UP(e,t){let n=e.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,s=(n.match(/url\([^)]+\)/g)||[]).map(async o=>{let a=o.replace(r,"$1");return a.startsWith("https://")||(a=new URL(a,e.url).href),FV(a,t.fetchRequestInit,({result:c})=>(n=n.replace(o,`url(${c})`),[o,c]))});return Promise.all(s).then(()=>n)}function ZP(e){if(e==null)return[];const t=[],n=/(\/\*[\s\S]*?\*\/)/gi;let r=e.replace(n,"");const i=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const c=i.exec(r);if(c===null)break;t.push(c[0])}r=r.replace(i,"");const s=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,o="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",a=new RegExp(o,"gi");for(;;){let c=s.exec(r);if(c===null){if(c=a.exec(r),c===null)break;s.lastIndex=a.lastIndex}else a.lastIndex=s.lastIndex;t.push(c[0])}return t}async function Hbe(e,t){const n=[],r=[];return e.forEach(i=>{if("cssRules"in i)try{Va(i.cssRules||[]).forEach((s,o)=>{if(s.type===CSSRule.IMPORT_RULE){let a=o+1;const c=s.href,u=zP(c).then(f=>UP(f,t)).then(f=>ZP(f).forEach(p=>{try{i.insertRule(p,p.startsWith("@import")?a+=1:i.cssRules.length)}catch(m){console.error("Error inserting rule from remote css",{rule:p,error:m})}})).catch(f=>{console.error("Error loading remote css",f.toString())});r.push(u)}})}catch(s){const o=e.find(a=>a.href==null)||document.styleSheets[0];i.href!=null&&r.push(zP(i.href).then(a=>UP(a,t)).then(a=>ZP(a).forEach(c=>{o.insertRule(c,o.cssRules.length)})).catch(a=>{console.error("Error loading remote stylesheet",a)})),console.error("Error inlining remote css file",s)}}),Promise.all(r).then(()=>(e.forEach(i=>{if("cssRules"in i)try{Va(i.cssRules||[]).forEach(s=>{n.push(s)})}catch(s){console.error(`Error while reading CSS rules from ${i.href}`,s)}}),n))}function Bbe(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>HV(t.style.getPropertyValue("src")))}async function zbe(e,t){if(e.ownerDocument==null)throw new Error("Provided element is not within a Document");const n=Va(e.ownerDocument.styleSheets),r=await Hbe(n,t);return Bbe(r)}function UV(e){return e.trim().replace(/["']/g,"")}function Ube(e){const t=new Set;function n(r){(r.style.fontFamily||getComputedStyle(r).fontFamily).split(",").forEach(s=>{t.add(UV(s))}),Array.from(r.children).forEach(s=>{s instanceof HTMLElement&&n(s)})}return n(e),t}async function Zbe(e,t){const n=await zbe(e,t),r=Ube(e);return(await Promise.all(n.filter(s=>r.has(UV(s.style.fontFamily))).map(s=>{const o=s.parentStyleSheet?s.parentStyleSheet.href:null;return BV(s.cssText,o,t)}))).join(`
|
|
511
511
|
`)}async function Wbe(e,t){const n=t.fontEmbedCSS!=null?t.fontEmbedCSS:t.skipFonts?null:await Zbe(e,t);if(n){const r=document.createElement("style"),i=document.createTextNode(n);r.appendChild(i),e.firstChild?e.insertBefore(r,e.firstChild):e.appendChild(r)}}async function Gbe(e,t={}){const{width:n,height:r}=jV(e,t),i=await Fv(e,t,!0);return await Wbe(i,t),await zV(i,t),Vbe(i,t),await ube(i,n,r)}async function qbe(e,t={}){const{width:n,height:r}=jV(e,t),i=await Gbe(e,t),s=await P1(i),o=document.createElement("canvas"),a=o.getContext("2d"),c=t.pixelRatio||abe(),u=t.canvasWidth||n,f=t.canvasHeight||r;return o.width=u*c,o.height=f*c,t.skipAutoScale||lbe(o),o.style.width=`${u}`,o.style.height=`${f}`,t.backgroundColor&&(a.fillStyle=t.backgroundColor,a.fillRect(0,0,o.width,o.height)),a.drawImage(s,0,0,o.width,o.height),o}async function Kbe(e,t={}){return(await qbe(e,t)).toDataURL()}const Ybe=e=>{var n;const t=(n=e.ownerDocument)==null?void 0:n.defaultView;return t?e instanceof t.HTMLElement:e instanceof HTMLElement},zf=async e=>{if(!Ybe(e))return null;try{return await Kbe(e,{cacheBust:!0,filter:n=>!(n.id??"").startsWith("rivet-")})}catch{return null}},Fm=Mt("component-search-api"),Xbe=e=>e instanceof Error&&e.name==="AbortError",Qbe=async(e,{signal:t}={})=>{var n;Fm.debug("Searching component for element:",e.tagName);try{const r=await fetch("/api/search-components",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify([e]),signal:t});if(!r.ok)return Fm.error(`Component search failed: HTTP ${r.status}`),e;const s=(n=(await r.json()).elements)==null?void 0:n[0];return s||(Fm.debug(`No component file found for <${e.tagName}>${e.className?` class="${e.className}"`:""}${e.id?` id="${e.id}"`:""}`),e)}catch(r){if(Xbe(r))throw r;return Fm.error("Component search error:",r),e}},Om=.8,Jbe=.5,I1=()=>{let e=null,t=null,n=null,r=null;const i=o=>{r&&(r.style.left=`${o.left}px`,r.style.top=`${o.top}px`,r.style.width=`${o.width}px`,r.style.height=`${o.height}px`)},s=()=>{if(!e||!t||!r)return;e.left+=(t.left-e.left)*Om,e.top+=(t.top-e.top)*Om,e.width+=(t.width-e.width)*Om,e.height+=(t.height-e.height)*Om,i(e),Math.max(Math.abs(t.left-e.left),Math.abs(t.top-e.top),Math.abs(t.width-e.width),Math.abs(t.height-e.height))>Jbe?n=requestAnimationFrame(s):(e={...t},i(t),n=null)};return{animateTo:(o,a,c=!1)=>{if(r=o,t={...a},c||!e){e={...a},i(a),n&&(cancelAnimationFrame(n),n=null);return}n||(n=requestAnimationFrame(s))},stop:()=>{n&&(cancelAnimationFrame(n),n=null)},reset:()=>{e=null,t=null,n&&(cancelAnimationFrame(n),n=null)}}},exe=32,txe=24,WP=(e,t)=>{const n=t-e;if(n<=0)return[];const r=Math.min(txe,Math.max(2,Math.ceil(n/exe)+1));return Array.from({length:r},(i,s)=>{const o=s/(r-1);return e+n*o})},nxe=(e,t,n)=>{if(typeof e.elementsFromPoint=="function")return e.elementsFromPoint(t,n);if(typeof e.elementFromPoint!="function")return[];const r=e.elementFromPoint(t,n);return r?[r]:[]},rxe=(e,t)=>{const n=new Set,r=WP(t.left,t.right),i=WP(t.top,t.bottom);return r.forEach(s=>{i.forEach(o=>{nxe(e,s,o).forEach(a=>{let c=a;for(;c;)n.add(c),c=c.parentElement})})}),Array.from(n).sort((s,o)=>{var u;if(s===o)return 0;const a=((u=e.defaultView)==null?void 0:u.Node)??Node;return s.compareDocumentPosition(o)&a.DOCUMENT_POSITION_PRECEDING?1:-1})},ZV=(e,t)=>rxe(e,t).filter(r=>{const i=r.getBoundingClientRect();return i.left<t.right&&i.right>t.left&&i.top<t.bottom&&i.bottom>t.top&&i.width>0&&i.height>0}),xx=new WeakMap,ixe=e=>{let t=null;return{schedule:()=>{t===null&&(t=window.requestAnimationFrame(()=>{t=null,e()}))},cancel:()=>{t!==null&&(window.cancelAnimationFrame(t),t=null)}}},sxe=e=>{var u;const t=xx.get(e);if(t)return t;const n=new Set,r=()=>{n.forEach(f=>f.handleChange())},i=()=>{n.forEach(f=>f.handleScroll())},s=new MutationObserver(r),o=e.body,a=((u=e.defaultView)==null?void 0:u.Node)??Node;if(o instanceof a)try{s.observe(o,{childList:!0,subtree:!0,attributes:!0})}catch{}e.addEventListener("scroll",i,!0);const c={subscribers:n,disconnect:()=>{s.disconnect(),e.removeEventListener("scroll",i,!0),xx.delete(e)}};return xx.set(e,c),c},oxe=(e,t)=>{const n=sxe(e);return n.subscribers.add(t),()=>{n.subscribers.delete(t),n.subscribers.size===0&&n.disconnect()}},WV=({iframe:e,onChange:t,onScroll:n})=>{const r=ixe(t);let i=null,s=null;const o=()=>{r.schedule()},a=()=>{n==null||n(),r.schedule()},c=()=>{s==null||s(),s=null},u=p=>{c(),s=oxe(p,{handleChange:o,handleScroll:a}),r.schedule()},f=()=>{const p=e==null?void 0:e.contentDocument;p&&u(p)};return e&&(i=new ResizeObserver(o),i.observe(e),e.contentDocument&&u(e.contentDocument),e.addEventListener("load",f)),()=>{e==null||e.removeEventListener("load",f),i==null||i.disconnect(),c(),r.cancel()}},dl={theme:{extend:{fontFamily:{main:["Satoshi","Inter","system-ui","-apple-system","Segoe UI","sans-serif"]},zIndex:{"resize-handle":"36","capture-overlay":"35","selection-overlay":"34","hover-overlay":"30","element-overlay":"25"},colors:{primary:{DEFAULT:"#FF3300",border:"#ff6b35"}}}}},Ov=dl.theme.extend.zIndex,Vv=dl.theme.extend.colors,axe=e=>Array.from(e.childNodes).filter(n=>n.nodeType===Node.TEXT_NODE).map(n=>{var r;return((r=n.textContent)==null?void 0:r.trim())||""}).join("").length>0,lxe=e=>{const t=e.tagName.toLowerCase();return!!(["path","g","circle","rect","line","polygon"].includes(t)||t==="i"&&e.className&&/\b(fa|icon|material)\b/.test(e.className))},cxe=(e,t,n=6)=>{const i=e.map(o=>{const a=o.getBoundingClientRect(),u=a.width*a.height/t,f=o.tagName.toLowerCase();let p=u>=.2&&u<=3?100:20;return["button","a","input","select","textarea"].includes(f)&&(p+=50),(u<.05||u>10)&&(p-=50),{element:o,score:p,ratio:u}}).filter(o=>o.score>30).filter(o=>!lxe(o.element)).sort((o,a)=>a.score-o.score),s=[];for(const o of i)s.some(c=>c.element.contains(o.element))||s.push(o);return s.slice(0,n).map(o=>o.element)},uxe=(e,t,n=6)=>e.map(i=>{const s=i.boundingRect,a=s.width*s.height/t,c=i.tagName.toLowerCase();let u=a>=.2&&a<=3?100:20;return["button","a","input","select","textarea"].includes(c)&&(u+=50),(a<.05||a>10)&&(u-=50),{element:i,score:u,ratio:a}}).filter(({element:i,score:s})=>{const o=i.tagName.toLowerCase();return s>30&&!["path","g","circle","rect","line","polygon"].includes(o)}).sort((i,s)=>s.score-i.score).slice(0,n).map(({element:i})=>i),wx=!1,dxe=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H8.5L4 20V6a2 2 0 0 1 2-2z' fill='%23FF3300' stroke='white' stroke-width='1.5'/%3E%3Cpath d='M9 9h6M9 12h4' stroke='white' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") 4 20, auto`,GV="opacity 0.15s ease-out",kx=8,Mk=e=>`rivet-hover-overlay--${e}`,Rk=e=>`rivet-selection-overlay--${e}`,qV=e=>`rivet-box-selection-overlay--${e}`,KV=e=>`rivet-mouse-capture--${e}`,S6="rivet-selection-overlay--",fxe="rivet-hover-overlay--",YV='[data-rivet-variant-root="true"]',hxe=`${YV} button[data-action]`,Vm=e=>e.closest(YV)!=null,pxe=(e,t,n)=>{const r=Br(e);if(!r)return null;const i=e.getBoundingClientRect(),s=t-i.left,o=n-i.top,a=Array.from(r.querySelectorAll(hxe));for(const c of a){const u=c.getBoundingClientRect();if(s>=u.left&&s<=u.right&&o>=u.top&&o<=u.bottom)return c}return null},mxe=e=>{const t=Mk(e);let n=document.getElementById(t);return n||(n=document.createElement("div"),n.id=t,n.style.cssText=`
|
|
512
512
|
position: fixed;
|
|
513
513
|
pointer-events: none;
|
|
@@ -642,4 +642,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
642
642
|
<body>
|
|
643
643
|
<div class="panel">${I9}</div>
|
|
644
644
|
</body>
|
|
645
|
-
</html>`,mwe="Too many people are trying Rivet right now. Please try again in a few minutes.",TH="Failed to start an isolated demo session.",gwe=async e=>{if(e.status===429)return mwe;try{const t=await e.json();if(t.error)return t.error;if(t.message)return t.message}catch{}return TH},vwe=({projectPath:e,activeDemoSessionId:t=null,showLoginGate:n=!1,onStartLogin:r,isStartingLogin:i=!1,loginError:s=null,fullPageHostedLoginProgressMessage:o=null,holdHostedTryoutPreviewNavigation:a=!1,hostedTryoutPreviewHoldMessage:c=null,deferInspectorUntilPreviewReady:u=!1})=>{const[f,p]=Vn(Ui),m=Be(Td),g=Be(O8),b=Be(j8),[x,C]=Vn(qJ),w=ke(Js),E=ke(h$)>0,[A,T]=Vn(bp),[M,I]=Vn(hd),P=ke(eo),[S,D]=Vn(ji),R=ke(uc),L=Be(C$),j=Be(Qg),O=Be(V8),H=Be(uc),B=m4e();g4e();const Z=B.isProcessing?"Completing authentication...":o,K=Z!==null,q=h.useRef((f==null?void 0:f.xpath)??null),Q=h.useRef(!1),F=h.useRef(!1),V=Be(Z1),W=q4e();h.useEffect(()=>{V(e??null)},[e,V]),h.useEffect(()=>{if(!e||Q.current)return;Q.current=!0;const re=Y4e(e);re.size>0&&(F.current=!0,D(re));const G=G4e(e);G&&W(G)},[e,D,W]),h.useEffect(()=>{if(!(!e||!Q.current)){if(F.current){F.current=!1;return}K4e(S,e)}},[S,e]),h.useEffect(()=>{(async()=>{try{const G=await fetch("/api/tokens");if(G.ok){const X=await G.json();m(X),X.framework&&br.info(`Loaded ${X.framework} design tokens`)}}catch(G){br.error("Failed to fetch design tokens:",G)}})()},[m]);const N=()=>{w==="edit"||R||(j(null),O(null),H(!1),Mx())},z=h.useCallback(()=>{I(!1),T(!1),b("view"),Mx(),p(null),g(null)},[b,g,T,I,p]);h.useEffect(()=>{n&&(b("view"),Mx(),p(null),g(null),document.body.style.cursor="auto")},[n,b,g,p]);const ee=h.useMemo(()=>[{key:"Escape",allowInTextField:!0,handler:re=>{const G=re.target,X=G.tagName.toLowerCase();if(!((X==="input"||X==="textarea"||X==="select"||G.getAttribute("contenteditable")==="true")&&w!=="comment")){if(G.closest("[data-radix-popper-content-wrapper]")){br.debug("Escape key pressed inside popover - letting Radix handle it");return}if(R){br.debug("Escape key pressed with dirty draft comment - closing draft"),j(null),O(null),H(!1);return}if(M){br.debug("Escape key pressed in variants mode - hiding panel"),I(!1),T(!1);return}br.debug("Escape key pressed - switching to view mode"),z()}},description:"Close inspector"},{key:"x",metaKey:!1,ctrlKey:!1,handler:()=>{if(R){br.debug("X key pressed with dirty draft comment - closing draft"),j(null),O(null),H(!1);return}br.debug("X key pressed - collapsing editor chrome"),z()},description:"Collapse editor chrome"},{key:"n",metaKey:!1,ctrlKey:!1,handler:()=>{if(R){br.debug("N key pressed with dirty draft comment - blocking mode switch"),L(re=>re+1);return}br.debug("N key pressed - switching to navigate mode"),z()},description:"Switch to navigate mode"},{key:"c",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("C key pressed - switching to comment mode"),b("comment")},description:"Switch to comment mode"},{key:"r",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("R key pressed - switching to refine mode"),I(!1),T(!0),b("edit")},description:"Switch to refine mode"},{key:"e",metaKey:!1,ctrlKey:!1,handler:()=>{M||(br.debug("E key pressed - opening variants panel"),I(!0),T(!0),b("comment"),vt.capture("variants_panel.opened",{source:"keyboard_shortcut",hasActiveSession:P.active}))},description:"Open explore panel"},{key:"p",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("P key pressed - toggling panel"),A?T(!1):(T(!0),w==="view"&&!M&&b("comment"))},description:"Toggle panel"}],[w,R,b,L,j,O,H,M,I,A,T,z,P]);X8({shortcuts:ee}),h.useEffect(()=>{const re=()=>{VD("window_resize")};return window.addEventListener("resize",re),()=>window.removeEventListener("resize",re)},[]),h.useEffect(()=>{const re=(f==null?void 0:f.xpath)??null,G=q.current;re&&re!==G&&(q.current=re)},[f==null?void 0:f.xpath]);const te=Array.from(S.values()).some(re=>re.status==="pending");return h.useEffect(()=>{const re=dwe(w,M,te);re!==null&&T(re)},[w,T,M,te]),y.jsxs(mn.div,{className:"relative flex h-screen overflow-hidden",initial:!1,animate:{opacity:1},transition:{duration:.5,ease:"easeOut"},"data-cy":"rivet-app",children:[Z!==null?y.jsx("div",{className:"absolute inset-0 z-50",children:y.jsx(c4e,{message:Z})}):null,n&&!K?y.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-black/45 backdrop-blur-[2px]",children:y.jsx(aH,{isSigningIn:i,onStartSignIn:()=>{r==null||r()},errorMessage:s,displayMode:"modal"})}):null,y.jsxs("div",{className:`relative flex min-w-0 flex-1 flex-col ${n?"pointer-events-none select-none":""}`,children:[y.jsx(a4e,{holdHostedTryoutPreviewNavigation:a,isInteractionDisabled:n,activeDemoSessionId:t}),a&&c?y.jsx("div",{className:"bg-main absolute inset-0 z-30 flex items-center justify-center",children:y.jsx("div",{className:"border-divider bg-main-light rounded-lg border p-6 shadow-lg",children:y.jsx(sH,{message:c})})}):null]}),n?null:y.jsx(y.Fragment,{children:!u&&!E?y.jsxs(y.Fragment,{children:[y.jsx(mn.div,{className:"h-full flex-shrink-0",initial:!1,animate:{width:A?"auto":0,opacity:A?1:0},transition:{ease:[.19,1,.22,1],duration:.45},style:{overflow:"hidden",willChange:"width"},onClickCapture:N,children:y.jsx(Z2e,{chatMessages:x,setChatMessages:C,onClose:()=>T(!1)})}),y.jsx(us,{children:!A&&y.jsx(Fi,{label:"Open chat",side:"left",children:y.jsx(mn.button,{initial:{opacity:0,x:8},animate:{opacity:1,x:0},exit:{opacity:0,x:8},transition:{duration:.15},onClick:()=>T(!0),className:"border-primary/30 bg-main text-content absolute top-4 right-0 z-50 rounded-l-lg border border-r-0 p-2 shadow-lg transition-colors","data-cy":"reopen-panel",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})})})]}):null}),y.jsx(i$,{duration:5e3,richColors:!0,toastOptions:{style:{maxHeight:"150px",overflow:"hidden"}}})]})},ywe=()=>{const[e,t]=h.useState(window.location.hash),[n,r]=h.useState(0),{config:i,refetchConfig:s,loading:o,error:a}=h4e(),c=Be(uc),[u,f]=h.useState(!1),[p,m]=h.useState(null),[g,b]=h.useState(!1),[x,C]=h.useState(!1),[w,E]=h.useState(null),[A,T]=h.useState(!1),M=h.useRef(!1),I=h.useRef(!1),P=cwe(window.location.pathname),S=(i==null?void 0:i.activeDemoSessionId)??null,D=P??w??S,R=h.useMemo(()=>swe(i==null?void 0:i.demoMode,i==null?void 0:i.agentModeAvailable,D),[i==null?void 0:i.demoMode,i==null?void 0:i.agentModeAvailable,D]),L=h.useMemo(()=>iwe({configLoading:o,hasConfig:i!==null,demoMode:i==null?void 0:i.demoMode,agentModeAvailable:i==null?void 0:i.agentModeAvailable,pathnameDemoSessionId:P,activeDemoSessionId:w,configuredDemoSessionId:S}),[i,o,P,w,S]);h.useLayoutEffect(()=>{if(!L){T(!1);return}T(!0)},[L]);const j=A,O=h.useMemo(()=>owe(j),[j]),H=(i==null?void 0:i.demoMode)===!0&&j,B=h.useRef(null);B.current=D;const Z=h.useCallback(async()=>{if(!M.current)return;E(null);const te=await s();if((te==null?void 0:te.demoMode)===!0&&te.agentModeAvailable!==!0){C(!1);return}(te==null?void 0:te.demoMode)===!0&&C(!0)},[s]);h.useEffect(()=>{if((i==null?void 0:i.demoMode)===!0)return ewe(()=>{Z()})},[i==null?void 0:i.demoMode,Z]),h.useEffect(()=>{if(M.current=(i==null?void 0:i.demoMode)===!0,(i==null?void 0:i.demoMode)!==!0)return;const te=window.fetch.bind(window);return rwe({nativeFetch:te,pageOrigin:window.location.origin,getShouldIntercept:()=>M.current})},[i==null?void 0:i.demoMode]),h.useEffect(()=>{(i==null?void 0:i.agentModeAvailable)===!0&&C(!1)},[i==null?void 0:i.agentModeAvailable]);const K=h.useCallback(async te=>{const re=B.current;if(!(te!=null&&te.forceRefresh)&&re)return re;if(I.current)return"";I.current=!0;try{const G=await fetch("/api/demo/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});if(!G.ok){const de=await gwe(G);throw new Error(de)}const X=await G.json();if(!X.sessionId)throw new Error("Demo session response missing session id.");return E(X.sessionId),X.sessionId}finally{I.current=!1}},[]);h.useEffect(()=>{S&&E(S)},[S]),h.useEffect(()=>{i!=null&&i.userId?(vt.identify(i.userId,{...i.email?{email:i.email}:{}}),i.email&&vt.alias(i.email,i.userId)):i!=null&&i.email&&vt.identify(i.email,{email:i.email})},[i==null?void 0:i.userId,i==null?void 0:i.email]),h.useEffect(()=>{if(!i)return;const te=!!i.demoMode,re=te?D:null;vt.register({source:te?"tryout":"core",demo_mode:te,...re?{demo_session_id:re}:{}})},[i,D]);const q=h.useCallback(async()=>{var re;f(!0),m(null);let te=null;try{if(te=window.open("","_blank"),!te)throw new Error("Pop-up blocked. Please allow pop-ups and try again.");try{te.document.open(),te.document.write(pwe),te.document.close()}catch(de){br.warn("Failed to render loading state in auth popup:",de)}const G=await fetch(`${M9}/api/auth/google/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"desktop"})}),X=await G.json();if(!G.ok||!X.success||!X.authUrl||!X.sessionId||!X.pollSecret)throw new Error(X.error||X.message||"Failed to start Google login");if(te.closed)throw new Error("Sign-in window was closed before Google login started.");te.location.href=X.authUrl;for(let de=0;de<hwe;de+=1){if(te.closed)throw new Error("Sign-in window was closed before authentication completed.");const we=await(await fetch(`${M9}/api/auth/google/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session:X.sessionId,pollSecret:X.pollSecret})})).json();if(we.success&&we.token&&((re=we.user)!=null&&re.email)){if(!(await fetch("/api/auth/store",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:we.user.email,token:we.token,refreshToken:we.refreshToken,userId:we.user.id})})).ok)throw new Error("Signed in, but failed to store session locally.");if(te.close(),(i==null?void 0:i.demoMode)===!0){await K({forceRefresh:!0}),window.location.reload();return}window.location.reload();return}if(we.error&&we.error!=="Pending")throw new Error(we.error||"Google login failed");await new Promise(Fe=>setTimeout(Fe,fwe))}throw new Error("Authentication timed out. Please try again.")}catch(G){te&&!te.closed&&te.close();const X=G instanceof Error?G.message:"Failed to start login flow";br.warn("Hosted login failed:",X),m(X),f(!1)}},[i==null?void 0:i.demoMode,K]),Q=(i==null?void 0:i.demoMode)===!0&&((i==null?void 0:i.agentModeAvailable)!==!0||x||u),F=i!=null&&i.demoMode!==!0&&i.agentModeAvailable!==!0,V=M6(e),W=h.useCallback(async()=>{b(!0);try{await s()}finally{b(!1)}},[s]);if(h.useEffect(()=>{if(!L)return;let te=!1;return K({forceRefresh:!0}).catch(re=>{const G=re instanceof Error?re.message:TH;br.warn("Hosted session bootstrap failed:",G),m(G),ct.error(G)}).finally(()=>{te||T(!1)}),()=>{te=!0}},[L,K]),h.useEffect(()=>{const te=()=>{const re=window.location.hash;c(!1),t(G=>(uwe(G,re)&&r(X=>X+1),re))};return window.addEventListener("hashchange",te),()=>window.removeEventListener("hashchange",te)},[c]),V==="tokens")return y.jsx(O4e,{});if(V==="design-system")return y.jsx(Z4e,{});const N={pathname:window.location.pathname,configLoading:o,hasConfig:i!==null,isRetryingConfig:g},z=awe(N),ee=lwe(N);if(z)return y.jsx("div",{className:"h-screen w-full",children:y.jsx(rH,{})});if(ee){const te=a||"Could not load Rivet configuration.";return y.jsx("div",{className:"bg-main flex h-screen items-center justify-center px-6",children:y.jsxs("div",{className:"border-divider bg-main w-full max-w-md rounded-lg border p-6 text-center shadow-lg",children:[y.jsx("p",{className:"text-content text-sm font-medium",children:"We could not start Rivet yet."}),y.jsx("p",{className:"text-content-dim mt-2 text-xs",children:te}),y.jsx("button",{type:"button",className:"border-divider text-content hover:bg-main/80 mt-4 rounded-md border px-3 py-1.5 text-xs",onClick:()=>{W()},children:"Retry"})]})})}return F?y.jsx(aH,{isSigningIn:u,onStartSignIn:()=>{q()},errorMessage:p,displayMode:"full"}):y.jsx(vwe,{projectPath:i==null?void 0:i.projectPath,activeDemoSessionId:R,showLoginGate:Q,onStartLogin:q,isStartingLogin:u,loginError:p,fullPageHostedLoginProgressMessage:(i==null?void 0:i.demoMode)===!0&&u?"Completing sign-in...":null,holdHostedTryoutPreviewNavigation:j,hostedTryoutPreviewHoldMessage:O,deferInspectorUntilPreviewReady:H},n)},bwe="phc_Ntj9tXHbS64XgYxlTfhglRmFivFsfm0AERph4ZlnNH",xwe=new Oz,wwe=()=>y.jsx("div",{style:{display:"flex",height:"100vh",alignItems:"center",justifyContent:"center"},children:y.jsx("p",{style:{fontSize:"14px",color:"#6b7280"},children:"Something went wrong. Please reload the page."})});kW.createRoot(document.getElementById("root")).render(y.jsx(xe.StrictMode,{children:y.jsx(fW,{apiKey:bwe,options:{api_host:"https://us.i.posthog.com",ui_host:"https://us.posthog.com",person_profiles:"always",capture_exceptions:!0,autocapture:!0,capture_pageview:!0,capture_performance:!0,persistence:"localStorage",session_recording:{maskAllInputs:!1,maskInputOptions:{password:!0},maskTextSelector:null},mask_all_text:!1,mask_all_element_attributes:!1,loaded:e=>{e.register({source:"core",rivet_version:"0.11.0",env:"production"})}},children:y.jsx(gW,{fallback:y.jsx(wwe,{}),children:y.jsx(Hz,{client:xwe,children:y.jsx(f1e,{defaultShape:"rounded",children:y.jsx(u1e,{defaultLibrary:"lucide",children:y.jsx(ywe,{})})})})})})}));
|
|
645
|
+
</html>`,mwe="Too many people are trying Rivet right now. Please try again in a few minutes.",TH="Failed to start an isolated demo session.",gwe=async e=>{if(e.status===429)return mwe;try{const t=await e.json();if(t.error)return t.error;if(t.message)return t.message}catch{}return TH},vwe=({projectPath:e,activeDemoSessionId:t=null,showLoginGate:n=!1,onStartLogin:r,isStartingLogin:i=!1,loginError:s=null,fullPageHostedLoginProgressMessage:o=null,holdHostedTryoutPreviewNavigation:a=!1,hostedTryoutPreviewHoldMessage:c=null,deferInspectorUntilPreviewReady:u=!1})=>{const[f,p]=Vn(Ui),m=Be(Td),g=Be(O8),b=Be(j8),[x,C]=Vn(qJ),w=ke(Js),E=ke(h$)>0,[A,T]=Vn(bp),[M,I]=Vn(hd),P=ke(eo),[S,D]=Vn(ji),R=ke(uc),L=Be(C$),j=Be(Qg),O=Be(V8),H=Be(uc),B=m4e();g4e();const Z=B.isProcessing?"Completing authentication...":o,K=Z!==null,q=h.useRef((f==null?void 0:f.xpath)??null),Q=h.useRef(!1),F=h.useRef(!1),V=Be(Z1),W=q4e();h.useEffect(()=>{V(e??null)},[e,V]),h.useEffect(()=>{if(!e||Q.current)return;Q.current=!0;const re=Y4e(e);re.size>0&&(F.current=!0,D(re));const G=G4e(e);G&&W(G)},[e,D,W]),h.useEffect(()=>{if(!(!e||!Q.current)){if(F.current){F.current=!1;return}K4e(S,e)}},[S,e]),h.useEffect(()=>{(async()=>{try{const G=await fetch("/api/tokens");if(G.ok){const X=await G.json();m(X),X.framework&&br.info(`Loaded ${X.framework} design tokens`)}}catch(G){br.error("Failed to fetch design tokens:",G)}})()},[m]);const N=()=>{w==="edit"||R||(j(null),O(null),H(!1),Mx())},z=h.useCallback(()=>{I(!1),T(!1),b("view"),Mx(),p(null),g(null)},[b,g,T,I,p]);h.useEffect(()=>{n&&(b("view"),Mx(),p(null),g(null),document.body.style.cursor="auto")},[n,b,g,p]);const ee=h.useMemo(()=>[{key:"Escape",allowInTextField:!0,handler:re=>{const G=re.target,X=G.tagName.toLowerCase();if(!((X==="input"||X==="textarea"||X==="select"||G.getAttribute("contenteditable")==="true")&&w!=="comment")){if(G.closest("[data-radix-popper-content-wrapper]")){br.debug("Escape key pressed inside popover - letting Radix handle it");return}if(R){br.debug("Escape key pressed with dirty draft comment - closing draft"),j(null),O(null),H(!1);return}if(M){br.debug("Escape key pressed in variants mode - hiding panel"),I(!1),T(!1);return}br.debug("Escape key pressed - switching to view mode"),z()}},description:"Close inspector"},{key:"x",metaKey:!1,ctrlKey:!1,handler:()=>{if(R){br.debug("X key pressed with dirty draft comment - closing draft"),j(null),O(null),H(!1);return}br.debug("X key pressed - collapsing editor chrome"),z()},description:"Collapse editor chrome"},{key:"n",metaKey:!1,ctrlKey:!1,handler:()=>{if(R){br.debug("N key pressed with dirty draft comment - blocking mode switch"),L(re=>re+1);return}br.debug("N key pressed - switching to navigate mode"),z()},description:"Switch to navigate mode"},{key:"c",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("C key pressed - switching to comment mode"),b("comment")},description:"Switch to comment mode"},{key:"r",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("R key pressed - switching to refine mode"),I(!1),T(!0),b("edit")},description:"Switch to refine mode"},{key:"e",metaKey:!1,ctrlKey:!1,handler:()=>{M||(br.debug("E key pressed - opening variants panel"),I(!0),T(!0),b("comment"),vt.capture("variants_panel.opened",{source:"keyboard_shortcut",hasActiveSession:P.active}))},description:"Open explore panel"},{key:"p",metaKey:!1,ctrlKey:!1,handler:()=>{br.debug("P key pressed - toggling panel"),A?T(!1):(T(!0),w==="view"&&!M&&b("comment"))},description:"Toggle panel"}],[w,R,b,L,j,O,H,M,I,A,T,z,P]);X8({shortcuts:ee}),h.useEffect(()=>{const re=()=>{VD("window_resize")};return window.addEventListener("resize",re),()=>window.removeEventListener("resize",re)},[]),h.useEffect(()=>{const re=(f==null?void 0:f.xpath)??null,G=q.current;re&&re!==G&&(q.current=re)},[f==null?void 0:f.xpath]);const te=Array.from(S.values()).some(re=>re.status==="pending");return h.useEffect(()=>{const re=dwe(w,M,te);re!==null&&T(re)},[w,T,M,te]),y.jsxs(mn.div,{className:"relative flex h-screen overflow-hidden",initial:!1,animate:{opacity:1},transition:{duration:.5,ease:"easeOut"},"data-cy":"rivet-app",children:[Z!==null?y.jsx("div",{className:"absolute inset-0 z-50",children:y.jsx(c4e,{message:Z})}):null,n&&!K?y.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-black/45 backdrop-blur-[2px]",children:y.jsx(aH,{isSigningIn:i,onStartSignIn:()=>{r==null||r()},errorMessage:s,displayMode:"modal"})}):null,y.jsxs("div",{className:`relative flex min-w-0 flex-1 flex-col ${n?"pointer-events-none select-none":""}`,children:[y.jsx(a4e,{holdHostedTryoutPreviewNavigation:a,isInteractionDisabled:n,activeDemoSessionId:t}),a&&c?y.jsx("div",{className:"bg-main absolute inset-0 z-30 flex items-center justify-center",children:y.jsx("div",{className:"border-divider bg-main-light rounded-lg border p-6 shadow-lg",children:y.jsx(sH,{message:c})})}):null]}),n?null:y.jsx(y.Fragment,{children:!u&&!E?y.jsxs(y.Fragment,{children:[y.jsx(mn.div,{className:"h-full flex-shrink-0",initial:!1,animate:{width:A?"auto":0,opacity:A?1:0},transition:{ease:[.19,1,.22,1],duration:.45},style:{overflow:"hidden",willChange:"width"},onClickCapture:N,children:y.jsx(Z2e,{chatMessages:x,setChatMessages:C,onClose:()=>T(!1)})}),y.jsx(us,{children:!A&&y.jsx(Fi,{label:"Open chat",side:"left",children:y.jsx(mn.button,{initial:{opacity:0,x:8},animate:{opacity:1,x:0},exit:{opacity:0,x:8},transition:{duration:.15},onClick:()=>T(!0),className:"border-primary/30 bg-main text-content absolute top-4 right-0 z-50 rounded-l-lg border border-r-0 p-2 shadow-lg transition-colors","data-cy":"reopen-panel",children:y.jsx(Oh,{className:"h-4 w-4",weight:"bold"})})})})]}):null}),y.jsx(i$,{duration:5e3,richColors:!0,toastOptions:{style:{maxHeight:"150px",overflow:"hidden"}}})]})},ywe=()=>{const[e,t]=h.useState(window.location.hash),[n,r]=h.useState(0),{config:i,refetchConfig:s,loading:o,error:a}=h4e(),c=Be(uc),[u,f]=h.useState(!1),[p,m]=h.useState(null),[g,b]=h.useState(!1),[x,C]=h.useState(!1),[w,E]=h.useState(null),[A,T]=h.useState(!1),M=h.useRef(!1),I=h.useRef(!1),P=cwe(window.location.pathname),S=(i==null?void 0:i.activeDemoSessionId)??null,D=P??w??S,R=h.useMemo(()=>swe(i==null?void 0:i.demoMode,i==null?void 0:i.agentModeAvailable,D),[i==null?void 0:i.demoMode,i==null?void 0:i.agentModeAvailable,D]),L=h.useMemo(()=>iwe({configLoading:o,hasConfig:i!==null,demoMode:i==null?void 0:i.demoMode,agentModeAvailable:i==null?void 0:i.agentModeAvailable,pathnameDemoSessionId:P,activeDemoSessionId:w,configuredDemoSessionId:S}),[i,o,P,w,S]);h.useLayoutEffect(()=>{if(!L){T(!1);return}T(!0)},[L]);const j=A,O=h.useMemo(()=>owe(j),[j]),H=(i==null?void 0:i.demoMode)===!0&&j,B=h.useRef(null);B.current=D;const Z=h.useCallback(async()=>{if(!M.current)return;E(null);const te=await s();if((te==null?void 0:te.demoMode)===!0&&te.agentModeAvailable!==!0){C(!1);return}(te==null?void 0:te.demoMode)===!0&&C(!0)},[s]);h.useEffect(()=>{if((i==null?void 0:i.demoMode)===!0)return ewe(()=>{Z()})},[i==null?void 0:i.demoMode,Z]),h.useEffect(()=>{if(M.current=(i==null?void 0:i.demoMode)===!0,(i==null?void 0:i.demoMode)!==!0)return;const te=window.fetch.bind(window);return rwe({nativeFetch:te,pageOrigin:window.location.origin,getShouldIntercept:()=>M.current})},[i==null?void 0:i.demoMode]),h.useEffect(()=>{(i==null?void 0:i.agentModeAvailable)===!0&&C(!1)},[i==null?void 0:i.agentModeAvailable]);const K=h.useCallback(async te=>{const re=B.current;if(!(te!=null&&te.forceRefresh)&&re)return re;if(I.current)return"";I.current=!0;try{const G=await fetch("/api/demo/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});if(!G.ok){const de=await gwe(G);throw new Error(de)}const X=await G.json();if(!X.sessionId)throw new Error("Demo session response missing session id.");return E(X.sessionId),X.sessionId}finally{I.current=!1}},[]);h.useEffect(()=>{S&&E(S)},[S]),h.useEffect(()=>{i!=null&&i.userId?(vt.identify(i.userId,{...i.email?{email:i.email}:{}}),i.email&&vt.alias(i.email,i.userId)):i!=null&&i.email&&vt.identify(i.email,{email:i.email})},[i==null?void 0:i.userId,i==null?void 0:i.email]),h.useEffect(()=>{if(!i)return;const te=!!i.demoMode,re=te?D:null;vt.register({source:te?"tryout":"core",demo_mode:te,...re?{demo_session_id:re}:{}})},[i,D]);const q=h.useCallback(async()=>{var re;f(!0),m(null);let te=null;try{if(te=window.open("","_blank"),!te)throw new Error("Pop-up blocked. Please allow pop-ups and try again.");try{te.document.open(),te.document.write(pwe),te.document.close()}catch(de){br.warn("Failed to render loading state in auth popup:",de)}const G=await fetch(`${M9}/api/auth/google/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"desktop"})}),X=await G.json();if(!G.ok||!X.success||!X.authUrl||!X.sessionId||!X.pollSecret)throw new Error(X.error||X.message||"Failed to start Google login");if(te.closed)throw new Error("Sign-in window was closed before Google login started.");te.location.href=X.authUrl;for(let de=0;de<hwe;de+=1){if(te.closed)throw new Error("Sign-in window was closed before authentication completed.");const we=await(await fetch(`${M9}/api/auth/google/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session:X.sessionId,pollSecret:X.pollSecret})})).json();if(we.success&&we.token&&((re=we.user)!=null&&re.email)){if(!(await fetch("/api/auth/store",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:we.user.email,token:we.token,refreshToken:we.refreshToken,userId:we.user.id})})).ok)throw new Error("Signed in, but failed to store session locally.");if(te.close(),(i==null?void 0:i.demoMode)===!0){await K({forceRefresh:!0}),window.location.reload();return}window.location.reload();return}if(we.error&&we.error!=="Pending")throw new Error(we.error||"Google login failed");await new Promise(Fe=>setTimeout(Fe,fwe))}throw new Error("Authentication timed out. Please try again.")}catch(G){te&&!te.closed&&te.close();const X=G instanceof Error?G.message:"Failed to start login flow";br.warn("Hosted login failed:",X),m(X),f(!1)}},[i==null?void 0:i.demoMode,K]),Q=(i==null?void 0:i.demoMode)===!0&&((i==null?void 0:i.agentModeAvailable)!==!0||x||u),F=i!=null&&i.demoMode!==!0&&i.agentModeAvailable!==!0,V=M6(e),W=h.useCallback(async()=>{b(!0);try{await s()}finally{b(!1)}},[s]);if(h.useEffect(()=>{if(!L)return;let te=!1;return K({forceRefresh:!0}).catch(re=>{const G=re instanceof Error?re.message:TH;br.warn("Hosted session bootstrap failed:",G),m(G),ct.error(G)}).finally(()=>{te||T(!1)}),()=>{te=!0}},[L,K]),h.useEffect(()=>{const te=()=>{const re=window.location.hash;c(!1),t(G=>(uwe(G,re)&&r(X=>X+1),re))};return window.addEventListener("hashchange",te),()=>window.removeEventListener("hashchange",te)},[c]),V==="tokens")return y.jsx(O4e,{});if(V==="design-system")return y.jsx(Z4e,{});const N={pathname:window.location.pathname,configLoading:o,hasConfig:i!==null,isRetryingConfig:g},z=awe(N),ee=lwe(N);if(z)return y.jsx("div",{className:"h-screen w-full",children:y.jsx(rH,{})});if(ee){const te=a||"Could not load Rivet configuration.";return y.jsx("div",{className:"bg-main flex h-screen items-center justify-center px-6",children:y.jsxs("div",{className:"border-divider bg-main w-full max-w-md rounded-lg border p-6 text-center shadow-lg",children:[y.jsx("p",{className:"text-content text-sm font-medium",children:"We could not start Rivet yet."}),y.jsx("p",{className:"text-content-dim mt-2 text-xs",children:te}),y.jsx("button",{type:"button",className:"border-divider text-content hover:bg-main/80 mt-4 rounded-md border px-3 py-1.5 text-xs",onClick:()=>{W()},children:"Retry"})]})})}return F?y.jsx(aH,{isSigningIn:u,onStartSignIn:()=>{q()},errorMessage:p,displayMode:"full"}):y.jsx(vwe,{projectPath:i==null?void 0:i.projectPath,activeDemoSessionId:R,showLoginGate:Q,onStartLogin:q,isStartingLogin:u,loginError:p,fullPageHostedLoginProgressMessage:(i==null?void 0:i.demoMode)===!0&&u?"Completing sign-in...":null,holdHostedTryoutPreviewNavigation:j,hostedTryoutPreviewHoldMessage:O,deferInspectorUntilPreviewReady:H},n)},bwe="phc_Ntj9tXHbS64XgYxlTfhglRmFivFsfm0AERph4ZlnNH",xwe=new Oz,wwe=()=>y.jsx("div",{style:{display:"flex",height:"100vh",alignItems:"center",justifyContent:"center"},children:y.jsx("p",{style:{fontSize:"14px",color:"#6b7280"},children:"Something went wrong. Please reload the page."})});kW.createRoot(document.getElementById("root")).render(y.jsx(xe.StrictMode,{children:y.jsx(fW,{apiKey:bwe,options:{api_host:"https://us.i.posthog.com",ui_host:"https://us.posthog.com",person_profiles:"always",capture_exceptions:!0,autocapture:!0,capture_pageview:!0,capture_performance:!0,persistence:"localStorage",session_recording:{maskAllInputs:!1,maskInputOptions:{password:!0},maskTextSelector:null},mask_all_text:!1,mask_all_element_attributes:!1,loaded:e=>{e.register({source:"core",rivet_version:"0.11.2",env:"production"})}},children:y.jsx(gW,{fallback:y.jsx(wwe,{}),children:y.jsx(Hz,{client:xwe,children:y.jsx(f1e,{defaultShape:"rounded",children:y.jsx(u1e,{defaultLibrary:"lucide",children:y.jsx(ywe,{})})})})})})}));
|
package/src/ui/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Rivet - The visual editor for design</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/main-
|
|
8
|
+
<script type="module" crossorigin src="/assets/main-4_VncEaM.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/main-DkCj7b2K.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|