@cmmd-center/forge 0.14.1 → 0.14.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.
Files changed (71) hide show
  1. package/dist/bin.cjs +487 -41
  2. package/dist/bin.mjs +511 -65
  3. package/dist/client/assets/{CanvasPanel-BeSvnc85.js → CanvasPanel-Bk1rL0LG.js} +3 -3
  4. package/dist/client/assets/CompositeItem-D1GrQhpu.js +2 -0
  5. package/dist/client/assets/CompositeList-CEBk8sf_.js +2 -0
  6. package/dist/client/assets/DiffPanel-jC25MVg8.js +64 -0
  7. package/dist/client/assets/{DiffPanel.logic-CAb-hngG.js → DiffPanel.logic-DHo4jHZM.js} +6 -6
  8. package/dist/client/assets/{DiffWorkerPoolProvider-BbyQb-ye.js → DiffWorkerPoolProvider-r1DUfA1d.js} +10 -10
  9. package/dist/client/assets/Effect-CyyMOw4X.js +15 -0
  10. package/dist/client/assets/PullRequestCodePanel-BWuWxI6X.js +5 -0
  11. package/dist/client/assets/Schema-8EGdYSms.js +3 -0
  12. package/dist/client/assets/Stream-Bvl2Z6qI.js +2 -0
  13. package/dist/client/assets/ThemeEditorPanel-BOkxNR3t.js +2 -0
  14. package/dist/client/assets/Virtualizer-DOL71mrP.js +2 -0
  15. package/dist/client/assets/WorkerPoolContext-gI2-7Koc.js +2538 -0
  16. package/dist/client/assets/activeOrganizationId-CySrJzMX.js +2 -0
  17. package/dist/client/assets/atomRegistry-CzI2zp7d.js +3 -0
  18. package/dist/client/assets/{canvasStateStore-DYt9MgFu.js → canvasStateStore-dUmp5NFj.js} +2 -2
  19. package/dist/client/assets/chevron-left-BXpfeqsT.js +2 -0
  20. package/dist/client/assets/chevron-right-B103tjaJ.js +2 -0
  21. package/dist/client/assets/cmmdAuthRedirect-CHlAAdAc.js +3 -0
  22. package/dist/client/assets/cmmdEmbedMode-DhVvltxi.js +2 -0
  23. package/dist/client/assets/currentForgeWorkspaceStore-eKCBxKgv.js +2 -0
  24. package/dist/client/assets/dialog-BfhVD7Kq.js +2 -0
  25. package/dist/client/assets/getPseudoElementBounds-DBf0dPO9.js +2 -0
  26. package/dist/client/assets/index-BS4FABiE.js +301 -0
  27. package/dist/client/assets/minus-CbEeUDFT.js +2 -0
  28. package/dist/client/assets/popover-D8qvi5AD.js +2 -0
  29. package/dist/client/assets/{react-D4GEJ3ir.js → react-A0DLYjwn.js} +2 -2
  30. package/dist/client/assets/scroll-area-BDuz0PnB.js +2 -0
  31. package/dist/client/assets/sidebarV2CustomSnoozeDialog-pxOuwuY2.js +2 -0
  32. package/dist/client/assets/src-7C4X1Oy2.js +2 -0
  33. package/dist/client/assets/switch-BeaQwtm7.js +2 -0
  34. package/dist/client/assets/{themePalette-BWvBK22X.js → themePalette-D4rx0k29.js} +2 -2
  35. package/dist/client/assets/toggle--uJ9LmDV.js +2 -0
  36. package/dist/client/assets/toggle-group-6UcL78FY.js +2 -0
  37. package/dist/client/assets/tooltip-C_eHCky0.js +2 -0
  38. package/dist/client/assets/useOpenInteractionType-BFjAYgzR.js +2 -0
  39. package/dist/client/assets/{workspaceReadinessAtom-D6bgTvKb.js → workspaceReadinessAtom-BIm13kLJ.js} +2 -2
  40. package/dist/client/index.html +33 -31
  41. package/dist/forge-build.json +1 -1
  42. package/dist/{open-yHTUkd2Y.mjs → open-2-reBrpv.mjs} +3 -3
  43. package/package.json +1 -1
  44. package/dist/client/assets/CompositeItem-DTyKsv13.js +0 -2
  45. package/dist/client/assets/CompositeList-Bc8TYCyy.js +0 -2
  46. package/dist/client/assets/DiffPanel-3EEekk0W.js +0 -64
  47. package/dist/client/assets/PullRequestCodePanel--fricLiS.js +0 -5
  48. package/dist/client/assets/Stream-mUTFnSY9.js +0 -15
  49. package/dist/client/assets/ThemeEditorPanel-BCJuZ6ai.js +0 -2
  50. package/dist/client/assets/Virtualizer-DX75f7Mw.js +0 -2
  51. package/dist/client/assets/WorkerPoolContext-D_2lN-9Y.js +0 -1533
  52. package/dist/client/assets/atomRegistry-C1yW8tyM.js +0 -3
  53. package/dist/client/assets/chevron-left-1XbEOuXj.js +0 -2
  54. package/dist/client/assets/chevron-right-DAF000Jz.js +0 -2
  55. package/dist/client/assets/cmmdAuthRedirect-DRkKjx0G.js +0 -3
  56. package/dist/client/assets/cmmdForgeRuntimeListResource-Df9wlF4U.js +0 -1008
  57. package/dist/client/assets/currentForgeWorkspaceStore-CiCPSq18.js +0 -2
  58. package/dist/client/assets/dialog-C0bK23D8.js +0 -2
  59. package/dist/client/assets/getPseudoElementBounds-DJTX-eyW.js +0 -2
  60. package/dist/client/assets/index-BHReJBiJ.js +0 -301
  61. package/dist/client/assets/minus-_j91i8bf.js +0 -2
  62. package/dist/client/assets/popover-ClRgm7hB.js +0 -2
  63. package/dist/client/assets/scroll-area-BHqISEYq.js +0 -2
  64. package/dist/client/assets/sidebarV2CustomSnoozeDialog-lbAJoff_.js +0 -2
  65. package/dist/client/assets/src-B_wrKHuq.js +0 -3
  66. package/dist/client/assets/switch-BWQHMJkU.js +0 -2
  67. package/dist/client/assets/toggle-CORC1vE9.js +0 -2
  68. package/dist/client/assets/toggle-group-C9nAr6VB.js +0 -2
  69. package/dist/client/assets/tooltip-CrS-TEbN.js +0 -2
  70. package/dist/client/assets/useOpenInteractionType-KsRrk6uH.js +0 -2
  71. package/dist/client/assets/utils-xQJ3ak-X.js +0 -2
@@ -0,0 +1,2 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ha as t}from"./Effect-CyyMOw4X.js";import{B as n,P as r,V as i,b as a,d as o,g as s,h as c,n as l,nt as u,t as d,y as f}from"./Schema-8EGdYSms.js";import{t as p}from"./debouncer-BEV7Iuwb.js";var m=e(t(),1);function ee(){let e=new Map;return{clear:()=>e.clear(),getItem:t=>e.get(t)??null,key:t=>Array.from(e.keys()).at(t)??null,get length(){return e.size},removeItem:t=>e.delete(t),setItem:(t,n)=>e.set(t,n)}}var h=typeof window<`u`?window.localStorage:ee(),g=(e,t)=>r(i(e))(t),_=(e,t)=>n(i(e))(t),v=(e,t)=>{let n=h.getItem(e);return n?g(t,n):null},y=(e,t,n)=>{let r=_(n,t);h.setItem(e,r)},b=e=>{h.removeItem(e)},x=`forge:local_storage_change`;function S(e){typeof window>`u`||window.dispatchEvent(new CustomEvent(x,{detail:{key:e}}))}function C(e,t,n){let[r,i]=(0,m.useState)(()=>{try{return v(e,n)??t}catch(e){return console.error(`[LOCALSTORAGE] Error:`,e),t}}),a=(0,m.useCallback)(t=>{i(r=>{try{let i=typeof t==`function`?t(r):t;return i===null?b(e):y(e,i,n),queueMicrotask(()=>S(e)),i}catch(e){return console.error(`[LOCALSTORAGE] Error:`,e),r}})},[e,n]),o=(0,m.useRef)(e);return(0,m.useEffect)(()=>{if(o.current!==e){o.current=e;try{let r=v(e,n);i(r??t)}catch(e){console.error(`[LOCALSTORAGE] Error:`,e)}}},[e,t,n]),(0,m.useEffect)(()=>{let r=()=>{try{let r=v(e,n);i(r??t)}catch(e){console.error(`[LOCALSTORAGE] Error:`,e)}},a=t=>{t.key===e&&r()},o=t=>{t.detail.key===e&&r()};return window.addEventListener(`storage`,a),window.addEventListener(x,o),()=>{window.removeEventListener(`storage`,a),window.removeEventListener(x,o)}},[e,t,n]),[r,a]}var w=`cmmd-runtime:`;function T(e){return`${w}${e}`}function E(){let e=new Map;return{getItem:t=>e.get(t)??null,setItem:(t,n)=>{e.set(t,n)},removeItem:t=>{e.delete(t)}}}function te(e){return e!=null&&typeof e.getItem==`function`&&typeof e.setItem==`function`&&typeof e.removeItem==`function`}function D(e){return te(e)?e:E()}var O=E();function k(){return globalThis.localStorage||globalThis.window?.localStorage}var A={getItem:e=>{try{let t=k()?.getItem(e);if(t!==void 0)return t}catch{}return O.getItem(e)},setItem:(e,t)=>{try{let n=k();if(n){n.setItem(e,t);return}}catch{}O.setItem(e,t)},removeItem:e=>{try{let t=k();if(t){t.removeItem(e);return}}catch{}O.removeItem(e)}};function j(e){let t=A.getItem(e);return typeof t==`string`?t:null}function ne(e,t){A.setItem(e,t)}function re(e){A.removeItem(e)}function ie(e,t=300){let n=D(e),r=new p((e,t)=>{n.setItem(e,t)},{wait:t});return{getItem:e=>n.getItem(e),setItem:(e,t)=>{r.maybeExecute(e,t)},removeItem:e=>{r.cancel(),n.removeItem(e)},flush:()=>{r.flush()}}}var M=`registered`,N={destroyed:`destroyed`,superseded:`destroyed`,error:`error`,failed:`error`,draining:`draining`,recycling:`draining`,stopped:`stopped`,suspended:`suspended`,provisioning:`provisioning`,created:`provisioning`,starting:`starting`,restarting:`starting`};function P(e,t){let n=N[e];if(n!==void 0)return n;if(e!==`running`)return`stopped`;if(t)switch(t){case`app_ready`:case`server_ready`:case`ready`:case`supervisor_up`:return`running`;case`starting`:case`image_pulling`:case`waiting_state`:return`starting`;case`error`:return`error`;default:return`running`}return`running`}function F(e){return e===`destroyed`}function I(e){switch(e){case`running`:case`starting`:case`provisioning`:return!0;case`suspended`:return!0;case`registered`:case`stopped`:case`draining`:case`error`:case`destroyed`:return!1;default:return!1}}function L(e){let t=e.shortName?.trim();if(t)return t;if(e.projectName)return e.projectName;if(e.githubRepoFullName){let t=e.githubRepoFullName.split(`/`),n=t[t.length-1];if(n)return n}return`project ${e.cmmdProjectId}`}var R={state:`unknown`,label:`Unknown`,detail:`Current Environment availability has not been observed.`,tone:`muted`,automaticWakeAllowed:!1,shellConnected:!1,shellMayEstablishReady:!1};function z(e,t,n,r,i,a,o=!1){return{state:e,label:t,detail:n,tone:r,automaticWakeAllowed:i,shellConnected:a,shellMayEstablishReady:o}}function B(e,t){return e.ownerIntent===`paused`?z(`paused`,`Paused`,`Resume before live work can wake this Environment.`,`warning`,!1,t):e.ownerIntent===`deleting`?z(`deleting`,`Deleting`,`This Environment is being removed.`,`muted`,!1,t):null}function V(e,t){return e.executionAdmission.state===`allowed`?null:z(`unavailable`,`Unavailable`,`This Environment is not accepting live work while it drains.`,`warning`,!1,t)}function H(e,t=!1){if(e==null)return R;let n=B(e,t);if(n!==null)return n;if(e.ownerIntent!==`active`)return R;let r=V(e,t);if(r!==null)return r;let{provider:i,guestReadiness:a,activeWork:o}=e;return i.observedAt===null||i.failure!==null||i.state===`absent`||i.state===`unknown`?z(`unknown`,`Unknown`,`Current provider availability has not been observed.`,`muted`,e.automaticWakeAllowed,t):i.state===`sleeping`?z(`sleeping`,`Sleeping`,`Live work wakes this Environment automatically.`,`muted`,e.automaticWakeAllowed,t):a.observedAt===null||a.failure!==null||a.state===`unknown`?z(`unknown`,`Unknown`,`Current guest readiness has not been observed.`,`muted`,e.automaticWakeAllowed,t):a.state===`starting`?z(`starting`,`Starting`,`Preparing live execution.`,`warning`,e.automaticWakeAllowed,t):a.state===`degraded`?z(`degraded`,`Degraded`,`A required service needs attention.`,`warning`,e.automaticWakeAllowed,t):a.state===`failed`?z(`needs-attention`,`Needs attention`,`The readiness check failed.`,`destructive`,e.automaticWakeAllowed,t):t?z(`ready`,`Ready`,null,`success`,e.automaticWakeAllowed,!0):o.state===`active`?z(`ready`,`Ready`,null,`success`,e.automaticWakeAllowed,t):z(`unknown`,`Unknown`,`No current execution proof is available.`,`muted`,e.automaticWakeAllowed,t,!0)}function U(e,t){return!t||!e.shellMayEstablishReady?e:z(`ready`,`Ready`,null,`success`,e.automaticWakeAllowed,!0)}function W(e){return e?P(e.status,e.readinessPhase??void 0):M}function G(e){return e.runtime?.githubRepoFullName??e.githubRepoFullName??null}function K(e,t){return{cmmdOrganizationId:e.organizationId,cmmdProjectId:e.projectId,projectName:L({shortName:e.shortName??null,projectName:e.projectName??null,githubRepoFullName:t,cmmdProjectId:e.projectId}),githubRepoFullName:t,iconUrl:e.iconUrl??null,icon:e.icon??null}}function q(e){return e?{runtimeId:e.runtimeId,workspaceRoot:e.workspaceRoot??null,status:W(e),desiredState:J(e.desiredState),environmentId:T(e.runtimeId),cmmdEnvironmentId:e.environmentId??null,...e.maintenance===void 0?{}:{maintenance:e.maintenance}}:{runtimeId:null,workspaceRoot:null,status:M,desiredState:null,environmentId:null,cmmdEnvironmentId:null}}function J(e){return e===`running`||e===`stopped`||e===`destroyed`?e:null}function Y(e){return{...K(e,G(e)),registeredAt:e.registeredAt??null,...q(e.runtime),removal:e.removal??null,resolvedRef:null}}function ae(e){return e.map(Y)}function oe(e){return e.map(e=>({runtimeId:e.runtime.runtimeId,cmmdOrganizationId:e.organizationId,cmmdUserId:e.userId,displayName:e.displayName??null,userFirstName:e.userFirstName??null,environmentId:T(e.runtime.runtimeId),cmmdEnvironmentId:e.runtime.environmentId??null,status:W(e.runtime),desiredState:J(e.runtime.desiredState),...e.runtime.maintenance===void 0?{}:{maintenance:e.runtime.maintenance},lifecycle:H(e.lifecycle)}))}var X=`forge:cmmd-cloud-project-catalog:v5`,se=a({runtimeId:c(f),cmmdOrganizationId:s,cmmdProjectId:s,cmmdEnvironmentId:c(f),registeredAt:u(c(f)),projectName:f,githubRepoFullName:c(f),workspaceRoot:c(f),iconUrl:u(c(f)),icon:u(c(f)),status:f,desiredState:u(c(f)),environmentId:c(f),removal:u(c(a({operationId:f,deletePlanningProject:l,status:o([`pending`,`running`,`retryable`]),phase:o([`destroy_runtime`,`purge_execution_state`,`delete_planning_project`,`unregister`,`complete`]),lastErrorCode:c(f),lastErrorMessage:c(f),updatedAt:f})))}),Z=a({rows:d(se),environments:d(a({runtimeId:f,cmmdOrganizationId:s,cmmdUserId:s,displayName:u(c(f)),userFirstName:u(c(f)),environmentId:f,cmmdEnvironmentId:c(f),status:f,desiredState:c(f)})),fetchedAt:f});function ce(){b(X)}function le(){try{let e=v(X,Z);return e?{rows:e.rows.map(e=>({runtimeId:e.runtimeId,cmmdOrganizationId:e.cmmdOrganizationId,cmmdProjectId:e.cmmdProjectId,registeredAt:e.registeredAt??null,projectName:e.projectName,githubRepoFullName:e.githubRepoFullName,workspaceRoot:e.workspaceRoot,iconUrl:e.iconUrl??null,icon:e.icon??null,status:e.runtimeId===null?M:P(e.status),desiredState:J(e.desiredState),environmentId:e.runtimeId===null?null:T(e.runtimeId),cmmdEnvironmentId:e.cmmdEnvironmentId,resolvedRef:null,removal:e.removal??null})),environments:e.environments.map(e=>({runtimeId:e.runtimeId,cmmdOrganizationId:e.cmmdOrganizationId,cmmdUserId:e.cmmdUserId,displayName:e.displayName??null,userFirstName:e.userFirstName??null,cmmdEnvironmentId:e.cmmdEnvironmentId,status:P(e.status),desiredState:J(e.desiredState),environmentId:T(e.runtimeId)})),fetchedAt:e.fetchedAt}:null}catch{return null}}function ue(e,t,n){try{y(X,{rows:e.map(e=>({runtimeId:e.runtimeId,cmmdOrganizationId:e.cmmdOrganizationId,cmmdProjectId:e.cmmdProjectId,cmmdEnvironmentId:e.cmmdEnvironmentId,registeredAt:e.registeredAt,projectName:e.projectName,githubRepoFullName:e.githubRepoFullName,workspaceRoot:e.workspaceRoot,iconUrl:e.iconUrl,icon:e.icon,status:e.status,environmentId:e.environmentId,removal:e.removal})),environments:t,fetchedAt:n},Z)}catch{}}var Q=null;function de(e){Q=e}function fe(){Q?.refresh()}function pe(){Q?.clearMemory()}var $=null;function me(){return $}function he(e){$=e}export{w as C,y as D,b as E,C as O,ne as S,v as T,ie as _,de as a,re as b,ue as c,H as d,U as f,A as g,P as h,fe as i,oe as l,F as m,he as n,ce as o,I as p,pe as r,le as s,me as t,ae as u,E as v,T as w,D as x,j as y};
2
+ //# sourceMappingURL=activeOrganizationId-CySrJzMX.js.map
@@ -0,0 +1,3 @@
1
+ import{r as e,t}from"./rolldown-runtime-hePW80VL.js";import{$i as n,$t as r,A as i,Ar as a,Bn as o,Ct as s,D as c,Di as l,Ei as u,Er as d,Fa as f,Fr as p,Ft as m,Ha as h,Hr as g,Ia as ee,K as te,La as _,Lt as v,Na as y,Oi as b,On as x,P as S,Pn as ne,Q as re,Qt as C,R as w,Rr as ie,Si as ae,St as T,Ti as oe,Tr as se,U as ce,Ui as le,Ur as ue,Va as de,W as E,Zt as fe,_ as pe,ai as me,at as he,b as D,bi as ge,bn as _e,c as ve,ca as ye,ci as be,d as xe,da as O,ea as Se,f as Ce,fi as we,fn as Te,ga as Ee,ha as De,ht as Oe,ii as ke,in as Ae,ja as je,jn as k,jr as Me,kn as Ne,ln as Pe,mt as Fe,ni as Ie,on as Le,pa as Re,pi as ze,pt as Be,ri as Ve,rn as He,rt as Ue,s as We,sa as A,sn as Ge,ta as Ke,tn as qe,ua as Je,ut as Ye,v as Xe,vi as Ze,vt as j,wn as Qe,xn as $e,xt as et,za as tt,zr as nt}from"./Effect-CyyMOw4X.js";import{A as rt,D as it,E as at,I as ot,L as st,N as ct,R as lt,S as ut,a as dt,h as ft,k as pt,l as mt,n as ht,o as gt,r as _t,s as vt,t as yt,u as bt,v as xt,x as St,z as Ct}from"./Stream-Bvl2Z6qI.js";var wt=t((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,ee=typeof setTimeout==`function`?setTimeout:null,te=typeof clearTimeout==`function`?clearTimeout:null,_=typeof setImmediate<`u`?setImmediate:null;function v(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function y(e){if(h=!1,v(e),!m)if(n(c)!==null)m=!0,b||(b=!0,w());else{var t=n(l);t!==null&&T(y,t.startTime-e)}}var b=!1,x=-1,S=5,ne=-1;function re(){return g?!0:!(e.unstable_now()-ne<S)}function C(){if(g=!1,b){var t=e.unstable_now();ne=t;var i=!0;try{a:{m=!1,h&&(h=!1,te(x),x=-1),p=!0;var a=f;try{b:{for(v(t),d=n(c);d!==null&&!(d.expirationTime>t&&re());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,v(t),i=!0;break b}d===n(c)&&r(c),v(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&T(y,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}}}finally{i?w():b=!1}}}var w;if(typeof _==`function`)w=function(){_(C)};else if(typeof MessageChannel<`u`){var ie=new MessageChannel,ae=ie.port2;ie.port1.onmessage=C,w=function(){ae.postMessage(null)}}else w=function(){ee(C,0)};function T(t,n){x=ee(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):S=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(te(x),x=-1):h=!0,T(y,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,b||(b=!0,w()))),r},e.unstable_shouldYield=re,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),Tt=t(((e,t)=>{t.exports=wt()})),Et=`~effect/collections/MutableHashMap`,Dt={[Et]:Et,[Symbol.iterator](){return this.backing[Symbol.iterator]()},toString(){return`MutableHashMap(${Ke(Array.from(this))})`},toJSON(){return{_id:`MutableHashMap`,values:Se(Array.from(this))}},[n](){return this.toJSON()},pipe(){return de(this,arguments)}},Ot=()=>{let e=Object.create(Dt);return e.backing=new Map,e.buckets=new Map,e},kt=f(2,(e,t)=>{if(e.backing.has(t))return b(e.backing.get(t));if(N(t))return l();let n=M.get(e);if(n!==void 0)return e.backing.has(n)?b(e.backing.get(n)):l();let r=O(t),i=e.buckets.get(r);return i===void 0?l():At(e,i,t)}),M=new WeakMap,N=e=>typeof e!=`object`&&typeof e!=`function`,At=(e,t,n)=>{for(let r=0,i=t.length;r<i;r++)if(A(n,t[r])){let i=t[r];return M.set(n,i),b(e.backing.get(i))}return l()},jt=f(3,(e,t,n)=>{if(e.backing.has(t)||N(t))return e.backing.set(t,n),e;let r=M.get(e);if(r!==void 0&&e.backing.has(r))return e.backing.set(r,n),e;let i=O(t),a=e.buckets.get(i);return a===void 0?(e.buckets.set(i,[t]),e.backing.set(t,n),e):(r=Mt(a,t),r===void 0&&(a.push(t),r=t),e.backing.set(r,n),e)}),Mt=(e,t)=>{for(let n=0,r=e.length;n<r;n++)if(A(t,e[n]))return M.set(t,e[n]),e[n]},Nt=f(2,(e,t)=>{if(N(t))return e.backing.delete(t),e;let n=M.get(e)??t,r=O(n),i=e.buckets.get(r);if(i===void 0)return e;for(let t=0,r=i.length;t<r;t++){let r=i[t];if(r===n||A(n,r)){e.backing.delete(r),i.splice(t,1);break}}return i.length===0&&e.buckets.delete(r),e}),Pt=`~effect/SubscriptionRef`,P=e=>Ee(e,Pt);({...le});var Ft=e=>gt(e.pubsub),It=e=>T(()=>e.value),Lt=(e,t)=>{e.value=t,rt(e.pubsub,t)},Rt=f(2,(e,t)=>e.semaphore.withPermit(T(()=>Lt(e,t)))),F=class extends Ie()(`effect/reactivity/Reactivity`){},zt=T(()=>{let e=new Map,t=t=>{Gt(t,t=>{let n=e.get(t);n!==void 0&&n.forEach(e=>e())})},n=e=>Ce(n=>{let r=n.mapUnsafe.get(Bt.key);return r?Gt(e,e=>{r.add(e)}):t(e),m}),r=(e,t)=>s(t,n(e)),a=(t,n)=>{let r=[];return Gt(t,t=>{r.push(t);let i=e.get(t);i===void 0&&(i=new Set,e.set(t,i)),i.add(n)}),()=>{for(let t=0;t<r.length;t++){let i=e.get(r[t]);i.delete(n),i.size===0&&e.delete(r[t])}}},o=(e,t)=>i(function*(){let n=yield*xe(),r=me(n,Le),i=yield*it(),o=ee(he(n),st(r)),s=!1,c=!1,l=e=>{e._tag===`Failure`?at(i,e.cause):pt(i,e.value),c?(c=!1,o(t).addObserver(l)):s=!1};function u(){if(s){c=!0;return}s=!0,o(t).addObserver(l)}let d=a(e,u);return yield*Ge(r,T(d)),u(),i});return F.of({mutation:r,query:o,stream:(e,t)=>o(e,t).pipe(w(vt),St),invalidateUnsafe:t,invalidate:n,registerUnsafe:a,withBatch:t=>et(()=>{let n=new Set;return t.pipe(re(Bt,n),te(t=>T(()=>{n.forEach(t=>{let n=e.get(t);n!==void 0&&n.forEach(e=>e())})})))})})}),Bt=class extends Ie()(`effect/reactivity/Reactivity/PendingInvalidation`){},Vt=f(2,(e,t)=>F.use(n=>n.mutation(t,e))),Ht=e=>F.use(t=>t.invalidate(e)),Ut=r(F)(zt);function Wt(e){switch(typeof e){case`string`:case`number`:case`bigint`:case`boolean`:return String(e);default:return O(e)}}var Gt=(e,t)=>{if(Array.isArray(e)){for(let n=0;n<e.length;n++)t(Wt(e[n]));return}for(let n in e){t(n);let r=e[n];for(let e=0;e<r.length;e++)t(`${n}:${Wt(r[e])}`)}},I={"~effect/reactivity/AsyncResult":{E:_,A:_},pipe(){return de(this,arguments)},[ye](e){if(this._tag!==e._tag||this.waiting!==e.waiting)return!1;switch(this._tag){case`Initial`:return!0;case`Success`:return A(this.value,e.value);case`Failure`:return A(this.cause,e.cause)}},[De](){let e=Re(`${this._tag}:${this.waiting}`);return this._tag===`Initial`?e:Je(e)(this._tag===`Success`?O(this.value):O(this.cause))}},Kt=(e,t)=>e._tag===`Success`?z(e.value):B(e.cause,{previous:t}),qt=e=>e._tag===`None`?L(!0):V(e.value),Jt=e=>e._tag!==`Initial`,L=(e=!1)=>{let t=Object.create(I);return t._tag=`Initial`,t.waiting=e,t},R=e=>e._tag===`Success`,z=(e,t)=>{let n=Object.create(I);return n._tag=`Success`,n.value=e,n.waiting=t?.waiting??!1,n.timestamp=t?.timestamp??Date.now(),n},Yt=e=>e._tag===`Failure`,Xt=(e,t)=>{let n=Object.create(I);return n._tag=`Failure`,n.cause=e,n.previousSuccess=t?.previousSuccess??l(),n.waiting=t?.waiting??!1,n},B=(e,t)=>Xt(e,{previousSuccess:we(t.previous,e=>R(e)?b(e):Yt(e)?e.previousSuccess:l()),waiting:t.waiting}),Zt=(e,t)=>B(ne(e),t),V=(e,t)=>{if(e.waiting)return t?.touch?Qt(e):e;let n=Object.assign(Object.create(I),e);return n.waiting=!0,t?.touch&&R(n)&&(n.timestamp=Date.now()),n},Qt=e=>R(e)?z(e.value,{waiting:e.waiting}):e,H=(e,t)=>e._tag===`Failure`?B(e.cause,{previous:t,waiting:e.waiting}):e,$t=e=>e._tag===`Success`?b(e.value):e._tag===`Failure`?oe(e.previousSuccess,e=>e.value):l(),en=e=>Ze($t(e),()=>new k(`AsyncResult.getOrThrow: no value found`)),tn=e=>{switch(e._tag){case`Success`:return x(e.value);case`Failure`:return $e(e.cause);default:return _e(new k)}},U=`~effect/reactivity/AtomRegistry`,nn=e=>new sn(e?.initialValues,e?.scheduleTask,e?.timeoutResolution,e?.defaultIdleTTL),rn=Ie(U),an={immediate:!0},on=e=>{e()},W=`~effect-atom/atom/Atom/Serializable`,G=e=>W in e?e[W].key:e,sn=class{[U];timeoutResolution;defaultIdleTTL;scheduler;schedulerAsync;dispatcher;onNodeAdded;onNodeRemoved;constructor(e,t,n,r){if(this[U]=U,this.scheduler=new se(`sync`,t),this.schedulerAsync=new se(`async`,t),this.dispatcher=this.schedulerAsync.makeDispatcher(),this.defaultIdleTTL=r,this.timeoutResolution=n===void 0&&r!==void 0?Math.round(r/2):n??1e3,e!==void 0)for(let[t,n]of e){let e=t;for(;e.initialValueTarget;)e=e.initialValueTarget;this.ensureNode(e).setInitialValue(n)}}nodes=new Map;preloadedSerializable=new Map;timeoutBuckets=new Map;nodeTimeoutBucket=new Map;disposed=!1;getNodes(){return this.nodes}get(e){return this.ensureNode(e).value()}set(e,t){e.write(this.ensureNode(e).writeContext,t)}setSerializable(e,t){this.preloadedSerializable.set(e,t)}modify(e,t){let n=this.ensureNode(e),r=t(n.value());return e.write(n.writeContext,r[1]),r[0]}update(e,t){let n=this.ensureNode(e);e.write(n.writeContext,t(n.value()))}refresh=e=>{e.refresh===void 0?this.invalidateAtom(e):e.refresh(this.refresh)};subscribe(e,t,n){let r=this.ensureNode(e);n?.immediate&&t(r.value());let i=r.subscribe(function(){t(r._value)});return()=>{i(),r.canBeRemoved&&this.scheduleNodeRemoval(r)}}mount(e){return this.subscribe(e,y,an)}atomHasTtl(e){return!e.keepAlive&&e.idleTTL!==0&&(e.idleTTL!==void 0||this.defaultIdleTTL!==void 0)}ensureNode(e){let t=G(e),n=this.nodes.get(t);if(n===void 0?(n=this.createNode(e),this.nodes.set(t,n),this.onNodeAdded?.(n)):this.atomHasTtl(e)&&this.removeNodeTimeout(n),typeof t==`string`&&this.preloadedSerializable.has(t)){let r=this.preloadedSerializable.get(t);this.preloadedSerializable.delete(t);let i=e[W].decode(r);n.setValue(i)}return n}createNode(e){if(this.disposed)throw Error(`Cannot access Atom ${e}: registry is disposed`);return e.keepAlive||this.scheduleAtomRemoval(e),new cn(this,e)}invalidateAtom=e=>{this.ensureNode(e).invalidate()};scheduleAtomRemoval(e){this.dispatcher.scheduleTask(()=>{let t=this.nodes.get(G(e));t!==void 0&&t.canBeRemoved&&this.removeNode(t)},0)}scheduleNodeRemoval(e){this.dispatcher.scheduleTask(()=>{e.canBeRemoved&&this.removeNode(e)},0)}removeNode(e){this.atomHasTtl(e.atom)?this.setNodeTimeout(e):(this.nodes.delete(G(e.atom)),e.remove(),this.onNodeRemoved?.(e))}setNodeTimeout(e){if(this.nodeTimeoutBucket.has(e))return;let t=e.atom.idleTTL??this.defaultIdleTTL;if(this.#e!==null&&(t-=this.#e,t<=0)){this.nodes.delete(G(e.atom)),e.remove(),this.onNodeRemoved?.(e);return}let n=Math.ceil(t/this.timeoutResolution)*this.timeoutResolution,r=Date.now()+n,i=r-r%this.timeoutResolution+this.timeoutResolution,a=this.timeoutBuckets.get(i);a===void 0&&(a=[new Set,setTimeout(()=>this.sweepBucket(i),i-Date.now())],this.timeoutBuckets.set(i,a)),a[0].add(e),this.nodeTimeoutBucket.set(e,i)}removeNodeTimeout(e){let t=this.nodeTimeoutBucket.get(e);if(t===void 0)return;this.nodeTimeoutBucket.delete(e),this.scheduleNodeRemoval(e);let[n,r]=this.timeoutBuckets.get(t);n.delete(e),n.size===0&&(clearTimeout(r),this.timeoutBuckets.delete(t))}#e=null;sweepBucket(e){let t=this.timeoutBuckets.get(e)[0];this.timeoutBuckets.delete(e),t.forEach(e=>{this.nodeTimeoutBucket.delete(e),e.canBeRemoved&&(this.nodes.delete(G(e.atom)),this.onNodeRemoved?.(e),this.#e=e.atom.idleTTL??this.defaultIdleTTL,e.remove(),this.#e=null)})}reset(){this.timeoutBuckets.forEach(([,e])=>clearTimeout(e)),this.timeoutBuckets.clear(),this.nodeTimeoutBucket.clear(),this.nodes.forEach(e=>{e.remove(),this.onNodeRemoved?.(e)}),this.nodes.clear()}dispose(){this.disposed=!0,this.reset()}},K={alive:1,initialized:2,waitingForValue:4},q={uninitialized:K.alive|K.waitingForValue,stale:K.alive|K.initialized|K.waitingForValue,valid:K.alive|K.initialized,removed:0},cn=class{constructor(e,t){this.registry=e,this.atom=t,this.writeContext=new fn(e,this)}registry;atom;state=q.uninitialized;lifetime;writeContext;preserveInitialValueOnBuild=!1;parents=[];previousParents;children=[];listeners=new Set;skipInvalidation=!1;currentState(){switch(this.state){case q.uninitialized:return`uninitialized`;case q.stale:return`stale`;case q.valid:return`valid`;default:return`removed`}}get canBeRemoved(){return!this.atom.keepAlive&&this.listeners.size===0&&this.children.length===0&&this.state!==0}_value=void 0;value(){if((this.state&K.waitingForValue)!==0){this.lifetime=dn(this);let e=this.atom.read(this.lifetime);if((this.state&K.waitingForValue)!==0&&(this.preserveInitialValueOnBuild?(this.preserveInitialValueOnBuild=!1,this.state=q.valid):this.setValue(e)),this.previousParents){let e=this.previousParents;this.previousParents=void 0;for(let t=0;t<e.length;t++)e[t].removeChild(this),e[t].canBeRemoved&&this.registry.scheduleNodeRemoval(e[t])}}return this._value}valueOption(){return(this.state&K.initialized)===0?l():b(this._value)}setInitialValue(e){if((this.state&K.initialized)===0){this.preserveInitialValueOnBuild=!0,this.state=q.stale,this._value=e,Y.phase===J.collect?Y.notify.add(this):this.notify();return}this.setValue(e)}setValue(e){if((this.state&K.initialized)===0){this.state=q.valid,this._value=e,Y.phase===J.collect?Y.notify.add(this):this.notify();return}this.state=q.valid,!Object.is(this._value,e)&&(this._value=e,this.skipInvalidation?this.skipInvalidation=!1:this.invalidateChildren(),this.listeners.size>0&&(Y.phase===J.collect?Y.notify.add(this):this.notify()))}addParent(e){if(this.parents.push(e),this.previousParents!==void 0){let t=this.previousParents.indexOf(e);t!==-1&&(this.previousParents[t]=this.previousParents[this.previousParents.length-1],this.previousParents.pop()===void 0&&(this.previousParents=void 0))}e.children.indexOf(this)===-1&&(e.children.push(this),e.skipInvalidation&&=!1)}removeChild(e){let t=this.children.indexOf(e);t!==-1&&(this.children[t]=this.children[this.children.length-1],this.children.pop())}invalidate(){this.state===q.valid&&(this.state=q.stale,this.disposeLifetime()),Y.phase===J.collect?Y.stale.push(this):this.atom.lazy&&this.listeners.size===0&&!ln(this.children)?(this.invalidateChildren(),this.skipInvalidation=!0):this.value()}invalidateChildren(){if(this.children.length===0)return;let e=this.children;this.children=[];for(let t=0;t<e.length;t++)e[t].invalidate()}notify(){this.listeners.forEach(on),Y.phase===J.commit&&Y.notify.delete(this)}disposeLifetime(){this.lifetime!==void 0&&(this.lifetime.dispose(),this.lifetime=void 0),this.parents.length!==0&&(this.previousParents=this.parents,this.parents=[])}remove(){if(this.state=q.removed,this.listeners.clear(),this.lifetime===void 0||(this.disposeLifetime(),this.previousParents===void 0))return;let e=this.previousParents;this.previousParents=void 0;for(let t=0;t<e.length;t++)e[t].removeChild(this),e[t].canBeRemoved&&this.registry.removeNode(e[t])}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}};function ln(e){if(e.length===0)return!1;let t=e,n,r=0;for(;t!==void 0;){for(let e=0,r=t.length;e<r;e++){let r=t[e];if(!r.atom.lazy||r.listeners.size>0)return!0;r.children.length>0&&(n===void 0?n=[r.children]:n.push(r.children))}t=n?.[r++]}return!1}var un={get registry(){return this.node.registry},addFinalizer(e){if(this.disposed)return e();this.finalizers??=[],this.finalizers.push(e)},get(e){if(this.disposed)return this.node.registry.get(e);let t=this.node.registry.ensureNode(e);return this.node.addParent(t),t.value()},result(e,t){if(this.disposed||this.isFn)return this.resultOnce(e,t);let n=this.get(e);if(t?.suspendOnWaiting&&n.waiting)return E;switch(n._tag){case`Initial`:return E;case`Failure`:return $e(n.cause);case`Success`:return j(n.value)}},resultOnce(e,t){return We(n=>{let r=this.once(e);if(r._tag!==`Initial`&&!(t?.suspendOnWaiting&&r.waiting))return n(tn(r));let i=this.node.registry.subscribe(e,e=>{e._tag===`Initial`||t?.suspendOnWaiting&&e.waiting||(i(),n(tn(e)))},{immediate:!1});return T(i)})},setResult(e,t){return this.disposed?E:(this.node.registry.set(e,t),this.resultOnce(e,{suspendOnWaiting:!0}))},some(e){if(this.disposed||this.isFn)return this.someOnce(e);let t=this.get(e);return t._tag===`None`?E:j(t.value)},someOnce(e){return We(t=>{let n=this.once(e);if(ae(n))return t(j(n.value));let r=this.node.registry.subscribe(e,e=>{ge(e)||(r(),t(j(e.value)))},{immediate:!1});return T(r)})},once(e){return this.node.registry.get(e)},self(){return this.disposed?l():this.node.valueOption()},refresh(e){this.disposed||this.node.registry.refresh(e)},refreshSelf(){this.disposed||this.node.invalidate()},mount(e){this.disposed||this.addFinalizer(this.node.registry.mount(e))},subscribe(e,t,n){this.disposed||this.addFinalizer(this.node.registry.subscribe(e,t,n))},setSelf(e){this.disposed||this.node.setValue(e)},set(e,t){this.disposed||this.node.registry.set(e,t)},stream(e,t){return this.disposed?ht:yt(n=>T(()=>{this.subscribe(e,e=>pt(n,e),{immediate:!t?.withoutInitialValue})}))},streamResult(e,t){return this.stream(e,t).pipe(dt(Jt),bt(e=>e._tag===`Success`?j(e.value):Xe(e.cause)))},dispose(){if(this.disposed=!0,this.finalizers===void 0)return;let e=this.finalizers;this.finalizers=void 0;for(let t=e.length-1;t>=0;t--)e[t]()}},dn=e=>{function t(n){if(t.disposed||t.isFn)return e.registry.get(n);let r=e.registry.ensureNode(n),i=r.value();return e.addParent(r),i}return Object.setPrototypeOf(t,un),t.isFn=!1,t.disposed=!1,t.finalizers=void 0,t.node=e,t},fn=class{constructor(e,t){this.registry=e,this.node=t}registry;node;get(e){return this.registry.get(e)}set(e,t){return this.registry.set(e,t)}setSelf(e){return this.node.setValue(e)}refreshSelf(){return this.node.invalidate()}},J={disabled:0,collect:1,commit:2},Y={phase:J.disabled,depth:0,stale:[],notify:new Set};function pn(e){Y.phase=J.collect,Y.depth++;try{if(e(),Y.depth===1){for(let e=0;e<Y.stale.length;e++)mn(Y.stale[e]);Y.phase=J.commit;for(let e of Y.notify)e.notify();Y.notify.clear()}}finally{Y.depth--,Y.depth===0&&(Y.phase=J.disabled,Y.stale=[])}}function mn(e){if(e.state!==q.valid){for(let t=0;t<e.parents.length;t++){let n=e.parents[t];n.state!==q.valid&&mn(n)}e.state!==q.valid&&e.value()}}var hn=`~effect/reactivity/Atom`,gn=e=>Ee(e,hn),_n=`~effect/reactivity/Atom/Writable`,X=f(2,(e,t)=>{let n=a(t),r=Me(n);return Object.assign(Object.create(Object.getPrototypeOf(e)),{...e,keepAlive:!r,idleTTL:r?p(n):void 0})})(0),vn={[hn]:hn,...le,toJSON(){return{_id:`Atom`,keepAlive:this.keepAlive,lazy:this.lazy,label:this.label}}},yn={...vn,atom(e,t){let n=Tn(e,t);return Z(e=>{let t=e.self(),r=e(this);return r._tag===`Success`?n(e,r.value):H(r,t)})},fn(e,t){return arguments.length===0?(e,t)=>bn(this,e,t):bn(this,e,t)},pull(e,t){let n=X(On(0));return zn(n,Z(r=>{let i=r.self(),a=r(this);return a._tag===`Success`?$(r,Rn(r,n,e,t),L(!0),a.value):H(a,i)}))},subscriptionRef(e){return Pn(X(Z(t=>{let n=t.self(),r=t(this);if(r._tag!==`Success`)return H(r,n);let i=typeof e==`function`?e(t):e;return P(i)?i:$(t,i,L(!0),r.value)})),(e,t)=>Nn(e,t,en(e(this))))}},bn=(e,t,n)=>{let[r,i,a]=Ln(n?.reactivityKeys?(e,r)=>{let i=t(e,r);return S(i)?Vt(i,n.reactivityKeys):_t(i,Ht(n.reactivityKeys))}:t,n);return Q(t=>{t.get(a);let n=t.self(),i=t.get(e);return i._tag===`Success`?r(t,i.value):H(i,n)},i)},xn={...vn,[_n]:_n},Sn=e=>_n in e,Z=(e,t)=>{let n=Object.create(vn);return n.keepAlive=!1,n.lazy=!0,n.read=e,n.refresh=t,n},Q=(e,t,n)=>{let r=Object.create(xn);return r.keepAlive=!1,r.lazy=!0,r.read=e,r.write=t,r.refresh=n,r};function Cn(e,t){e.setSelf(t)}var wn=(e,t)=>{let n=Tn(e,t);return`~effect/reactivity/Atom`in n?n:Z(n)},Tn=(e,t)=>{if(typeof e==`function`&&!S(e)&&!mt(e)){let n=e;return function(e,r){let i=n(e);switch(typeof i){case`function`:case`object`:return i===null?i:En in i?kn(e,i,t,r):Dn in i?jn(e,i,t,r):i;default:return i}}}return S(e)?function(n,r){return kn(n,e,t,r)}:mt(e)?function(n,r){return jn(n,e,t,r)}:On(e)},En=`~effect/Effect`,Dn=`~effect/Stream`,On=e=>Q(function(t){return e},Cn),kn=(e,t,n,r)=>$(e,t,n?.initialValue===void 0?L():z(n.initialValue),r,n?.uninterruptible);function $(e,t,n,r=ke(),i=!1){let a=e.self(),o=Te();e.addFinalizer(()=>{he(r)(Pe(o,Ne))});let s=new Map(r.mapUnsafe);s.set(Le.key,o),s.set(rn.key,e.registry),s.set(d.key,e.registry.scheduler);let c,l=!1,u=An(be(s),t,function(t){c=Kt(t,a),l&&e.setSelf(c)},i);return l=!0,u!==void 0&&e.addFinalizer(u),c===void 0?a._tag===`Some`?qt(a):V(n):c}function An(e,t,n,r=!1){if(Qe(t)){n(t);return}let i=he(e)(t);i.currentDispatcher?.flush();let a=i.pollUnsafe();if(a){n(a);return}let o=i.addObserver(n);function s(){o(),r||i.interruptUnsafe()}return s}(e=>{let t=Ut;function n(r){let i=Object.create(yn);i.keepAlive=!1,i.lazy=!0,i.refresh=void 0,i.factory=n;let a=Vn(Z(typeof r==`function`?e=>Ae(r(e),t):()=>Ae(r,t)));return i.layer=a,i.read=function(t){let n=t(a);return kn(t,D(Fe,t=>C(n,e.memoMap,t)),{uninterruptible:!0})},i}n.memoMap=e.memoMap,n.addGlobalLayer=e=>{t=Ae(t,He(e,Ut))};let r=X(wn(Ce(t=>C(Ut,e.memoMap,me(t,Le))).pipe(w(me(F)))));return n.withReactivity=e=>t=>Un(t,n=>{let i=en(n(r));return n.addFinalizer(i.registerUnsafe(e,()=>{n.refresh(t)})),n.subscribe(t,e=>n.setSelf(e)),n.once(t)},{initialValueTarget:t}),n})({memoMap:qe()}).withReactivity;var jn=(e,t,n,r)=>Mn(e,t,n?.initialValue===void 0?L():z(n.initialValue),r);function Mn(e,t,n,r=ke()){let i=e.self();r=Ve(r,rn,e.registry);let a=Oe(n=>D(ut(t.channel,n),t=>v({while:je,body:()=>t,step(t){e.setSelf(z(ue(t),{waiting:!0}))}}))).pipe(ve(t=>(fe(t)?tt(e.self(),we($t),u({onNone:()=>e.setSelf(Zt(new k,{previous:e.self()})),onSome:t=>e.setSelf(z(t))})):e.setSelf(B(t,{previous:e.self()})),m))),o=new Map(r.mapUnsafe);o.set(rn.key,e.registry),o.set(d.key,e.registry.scheduler);let s=An(be(o),a,y,!1);return s!==void 0&&e.addFinalizer(s),i._tag===`Some`?qt(i):V(n)}var Nn=(e,t,n=ke())=>P(t)?(e.addFinalizer(Ft(t).pipe(ft(t=>{for(let n=0;n<t.length;n++)e.setSelf(t[n]);return m}),Ue(n))),Be(n)(It(t))):t._tag===`Success`?Mn(e,Ft(t.value),L(!0),n):t,Pn=(e,t)=>{function n(t,n){let r=t.get(e);P(r)?Ye(Rt(r,n)):R(r)&&Ye(Rt(r.value,n))}return Q(n=>{let r=n(e);return P(r)||R(r)?t(n,r):r},n)},Fn=Symbol.for(`effect/reactivity/atom/Atom/Reset`),In=Symbol.for(`effect/reactivity/atom/Atom/Interrupt`);function Ln(e,t){let n=X(On([0,void 0])),r=t?.initialValue===void 0?L():z(t.initialValue),i=t?.concurrent?X(Z(e=>{let t=new Set;return e.addFinalizer(()=>t.forEach(e=>e.interruptUnsafe())),t})):void 0;function a(t,a){let s=i?t(i):void 0;t.isFn=!0;let[l,u]=t.get(n);if(l===0)return r;if(u===In)return B(o(),{previous:t.self()});let d=e(u,t);return En in d?(s&&(d=D(c(d,{startImmediately:!0}),e=>(s.add(e),e.addObserver(()=>s.delete(e)),w(ot(s),e=>e[0])))),$(t,d,r,a,!1)):Mn(t,d,r,a)}function s(e,t){Kn(()=>{t===Fn?e.set(n,[0,void 0]):t===In?e.set(n,[e.get(n)[0]+1,In]):e.set(n,[e.get(n)[0]+1,t]),e.refreshSelf()})}return[a,s,n]}var Rn=(e,t,n,r)=>D(xt(typeof n==`function`?n(e):n),n=>{let i=ct().context,a=nt(),o=ce(n,{onFailure(e){return fe(e)?g(a)?j({done:!0,items:a}):pe(new k(`Atom.pull: no items`)):Xe(e)},onSuccess(e){let t;return r?.disableAccumulation?t=e:(t=ie(a,e),a=t),j({done:!1,items:t})}}),s=new Set;return e.addFinalizer(()=>{for(let e of s)e()}),e.once(t),e.subscribe(t,()=>{e.setSelf(qt(e.self()));let t;t=An(i,o,n=>{t&&s.delete(t);let r=Kt(n,e.self()),i=s.size>0;e.setSelf(i?V(r):r)}),t&&s.add(t)}),o}),zn=(e,t)=>Q(t.read,function(t,n){t.set(e,t.get(e)+1)}),Bn=typeof WeakRef>`u`||typeof FinalizationRegistry>`u`?e=>{let t=Ot();return function(n){let r=kt(t,n);if(r._tag===`Some`)return r.value;let i=e(n);return jt(t,n,i),i}}:e=>{let t=Ot(),n=new FinalizationRegistry(e=>{Nt(t,e)});return function(r){let i=kt(t,r).pipe(ze(e=>e.deref()));if(i._tag===`Some`)return i.value;let a=e(r);return jt(t,r,new WeakRef(a)),n.register(a,r),a}},Vn=e=>Object.assign(Object.create(Object.getPrototypeOf(e)),{...e,keepAlive:!0}),Hn=f(2,(e,t)=>Object.assign(Object.create(Object.getPrototypeOf(e)),{...e,label:[t,Error().stack?.split(`
2
+ `)[5]??``]})),Un=f(e=>gn(e[0]),(e,t,n)=>{let r=X(Sn(e)?Q(n=>t(n,e),function(t,n){t.set(e,n)},e.refresh??function(t){t(e)}):Z(n=>t(n,e),e.refresh??function(t){t(e)}));return n?.initialValueTarget&&(r.initialValueTarget=Wn(n.initialValueTarget)),r}),Wn=e=>{let t=e;for(;t.initialValueTarget;)t=t.initialValueTarget;return t},Gn=f(2,(e,t)=>Un(e,n=>t(n(e)))),Kn=pn,qn=`~effect-atom/atom/Atom/ServerValue`,Jn=f(2,(e,t)=>`~effect-atom/atom/Atom/ServerValue`in e?e[qn](e=>t.get(e)):t.get(e)),Yn=e(h(),1),Xn=e(Tt(),1);function Zn(e){let t=Xn.unstable_scheduleCallback(4,e);return()=>Xn.unstable_cancelCallback(t)}var Qn=Yn.createContext(nn({scheduleTask:Zn,defaultIdleTTL:400})),$n=lt(),er=Ct(),tr=nn();function nr(e){let t=(0,$n.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,er.jsx)(Qn.Provider,{value:tr,children:n}),t[0]=n,t[1]=r),r}export{Jn as a,Gn as c,Bn as i,Hn as l,tr as n,Vn as o,Qn as r,wn as s,nr as t,Tt as u};
3
+ //# sourceMappingURL=atomRegistry-CzI2zp7d.js.map
@@ -1,2 +1,2 @@
1
- import{dn as e}from"./CompositeItem-DTyKsv13.js";import{t}from"./react-D4GEJ3ir.js";var n=e(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),r=e(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),i=e(`chevrons-down`,[[`path`,{d:`m7 6 5 5 5-5`,key:`1lc07p`}],[`path`,{d:`m7 13 5 5 5-5`,key:`1d48rs`}]]),a=e(`chevrons-up`,[[`path`,{d:`m17 11-5-5-5 5`,key:`e8nh98`}],[`path`,{d:`m17 18-5-5-5 5`,key:`2avn1x`}]]),o=e(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),s=e(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),c=e(`eye-off`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),l=e(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),u=e(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),d=e(`mouse-pointer-2`,[[`path`,{d:`M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z`,key:`edeuup`}]]),f=e(`palette`,[[`path`,{d:`M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z`,key:`e79jfc`}],[`circle`,{cx:`13.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`1okk4w`}],[`circle`,{cx:`17.5`,cy:`10.5`,r:`.5`,fill:`currentColor`,key:`f64h9f`}],[`circle`,{cx:`6.5`,cy:`12.5`,r:`.5`,fill:`currentColor`,key:`qy21gx`}],[`circle`,{cx:`8.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`fotxhn`}]]),p=e(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),m=e(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),h=e(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),g={primaryColor:`#6366f1`,secondaryColor:`#8b5cf6`,accentColor:`#f59e0b`,backgroundColor:`#ffffff`,textColor:`#1f2937`,fontFamily:`Inter, sans-serif`,headingFontFamily:`Inter, sans-serif`},_={bold:{bg:`#1f2937`,accent:`#f59e0b`,text:`#ffffff`},minimal:{bg:`#ffffff`,accent:`#6366f1`,text:`#1f2937`},gradient:{bg:`#4f46e5`,accent:`#818cf8`,text:`#ffffff`},split:{bg:`#f8fafc`,accent:`#0ea5e9`,text:`#0f172a`},centered:{bg:`#fef3c7`,accent:`#d97706`,text:`#78350f`}},v=[`bold`,`minimal`,`gradient`,`split`,`centered`];function y(e){let t=e.toLowerCase();return t.includes(`bold`)||t.includes(`sale`)||t.includes(`announcement`)?`bold`:t.includes(`minimal`)||t.includes(`clean`)||t.includes(`simple`)?`minimal`:t.includes(`gradient`)||t.includes(`modern`)||t.includes(`tech`)?`gradient`:t.includes(`split`)||t.includes(`compare`)||t.includes(`versus`)?`split`:t.includes(`warm`)||t.includes(`friendly`)||t.includes(`welcome`)?`centered`:v[Math.floor(Math.random()*v.length)]??`bold`}function b(e){let t=e.replace(/^(create|make|design|generate)\s+(a|an|me)?\s*/i,``).replace(/\s*(instagram|facebook|twitter|linkedin|youtube|social media|post|story|banner|cover|thumbnail)\s*/gi,``).replace(/\s*(about|for|with|featuring)\s*/i,`|`).trim().split(`|`).map(e=>e.trim()).filter(Boolean),n=t[0]??``;if(t.length>=2)return{heading:x(n),subtext:x(t.slice(1).join(` `))};if(n.length>30){let e=n.split(` `),t=Math.ceil(e.length/2);return{heading:x(e.slice(0,t).join(` `)),subtext:x(e.slice(t).join(` `))}}return{heading:n?x(n):`Your Title Here`,subtext:`Add your message`}}function x(e){return e.charAt(0).toUpperCase()+e.slice(1)}function S(e,t,n,r=g){let i=y(e),a=_[i],{heading:o,subtext:s}=b(e),c=t>n;Math.abs(t-n);let l=[];switch(l.push({type:`rect`,left:0,top:0,width:t,height:n,fill:a.bg,selectable:!1,customId:`__bg__`,customName:`Background`}),i){case`bold`:l.push(...C(t,n,a,o,s,r));break;case`minimal`:l.push(...w(t,n,a,o,s,r));break;case`gradient`:l.push(...T(t,n,a,o,s,r));break;case`split`:l.push(...E(t,n,a,o,s,c,r));break;case`centered`:l.push(...D(t,n,a,o,s,r))}return{objects:l}}function C(e,t,n,r,i,a){let o=Math.min(e,t)*.08,s=Math.min(e,t)*.1,c=s*.4;return[{type:`rect`,left:0,top:0,width:e,height:t*.06,fill:n.accent,customName:`Accent Bar`},{type:`textbox`,left:o,top:t*.3,width:e-o*2,text:r.toUpperCase(),fontSize:s,fontFamily:a.headingFontFamily,fontWeight:`900`,fill:n.text,textAlign:`left`,customName:`Heading`},{type:`textbox`,left:o,top:t*.55,width:e-o*2,text:i,fontSize:c,fontFamily:a.fontFamily,fontWeight:`400`,fill:n.accent,textAlign:`left`,customName:`Subtext`},{type:`rect`,left:o,top:t*.85,width:e*.3,height:4,fill:n.accent,customName:`Accent Line`}]}function w(e,t,n,r,i,a){let o=Math.min(e,t)*.08,s=o*.45;return[{type:`rect`,left:e*.04,top:t*.04,width:e*.92,height:t*.92,fill:`transparent`,stroke:n.accent,strokeWidth:2,customName:`Frame`},{type:`textbox`,left:e*.1,top:t*.35,width:e*.8,text:r,fontSize:o,fontFamily:a.headingFontFamily,fontWeight:`600`,fill:n.text,textAlign:`center`,customName:`Heading`},{type:`rect`,left:e*.4,top:t*.52,width:e*.2,height:2,fill:n.accent,customName:`Divider`},{type:`textbox`,left:e*.15,top:t*.58,width:e*.7,text:i,fontSize:s,fontFamily:a.fontFamily,fontWeight:`400`,fill:`#6b7280`,textAlign:`center`,customName:`Subtext`}]}function T(e,t,n,r,i,a){let o=Math.min(e,t)*.09,s=o*.4;return[{type:`rect`,left:0,top:t*.6,width:e,height:t*.4,fill:`rgba(0,0,0,0.3)`,customName:`Overlay`},{type:`ellipse`,left:e*.7,top:-t*.15,rx:e*.25,ry:e*.25,fill:n.accent,opacity:.3,customName:`Deco Circle`},{type:`textbox`,left:e*.08,top:t*.35,width:e*.84,text:r,fontSize:o,fontFamily:a.headingFontFamily,fontWeight:`700`,fill:n.text,textAlign:`center`,customName:`Heading`},{type:`textbox`,left:e*.12,top:t*.65,width:e*.76,text:i,fontSize:s,fontFamily:a.fontFamily,fontWeight:`400`,fill:`rgba(255,255,255,0.85)`,textAlign:`center`,customName:`Subtext`}]}function E(e,t,n,r,i,a,o){let s=Math.min(e,t)*.08,c=s*.45;return a?[{type:`rect`,left:0,top:0,width:e*.45,height:t,fill:n.accent,customName:`Color Panel`},{type:`textbox`,left:e*.52,top:t*.3,width:e*.42,text:r,fontSize:s,fontFamily:o.headingFontFamily,fontWeight:`700`,fill:n.text,textAlign:`left`,customName:`Heading`},{type:`textbox`,left:e*.52,top:t*.55,width:e*.42,text:i,fontSize:c,fontFamily:o.fontFamily,fontWeight:`400`,fill:`#64748b`,textAlign:`left`,customName:`Subtext`}]:[{type:`rect`,left:0,top:0,width:e,height:t*.45,fill:n.accent,customName:`Color Panel`},{type:`textbox`,left:e*.08,top:t*.52,width:e*.84,text:r,fontSize:s,fontFamily:o.headingFontFamily,fontWeight:`700`,fill:n.text,textAlign:`center`,customName:`Heading`},{type:`textbox`,left:e*.12,top:t*.72,width:e*.76,text:i,fontSize:c,fontFamily:o.fontFamily,fontWeight:`400`,fill:`#64748b`,textAlign:`center`,customName:`Subtext`}]}function D(e,t,n,r,i,a){let o=Math.min(e,t)*.09,s=o*.4;return[{type:`rect`,left:e*.1,top:t*.15,width:e*.8,height:t*.7,fill:`rgba(255,255,255,0.7)`,rx:20,ry:20,customName:`Card`},{type:`textbox`,left:e*.15,top:t*.3,width:e*.7,text:r,fontSize:o,fontFamily:a.headingFontFamily,fontWeight:`700`,fill:n.text,textAlign:`center`,customName:`Heading`},{type:`textbox`,left:e*.18,top:t*.55,width:e*.64,text:i,fontSize:s,fontFamily:a.fontFamily,fontWeight:`400`,fill:n.text,textAlign:`center`,opacity:.7,customName:`Subtext`},{type:`rect`,left:e*.3,top:t*.72,width:e*.4,height:Math.min(e,t)*.07,fill:n.accent,rx:8,ry:8,customName:`CTA Button`},{type:`textbox`,left:e*.3,top:t*.725,width:e*.4,text:`Learn More`,fontSize:s*.9,fontFamily:a.fontFamily,fontWeight:`600`,fill:`#ffffff`,textAlign:`center`,customName:`CTA Text`}]}var O=[{id:`ig-post-bold`,name:`Bold Announcement`,category:`social`,presetId:`instagram-post`,style:`bold`,description:`High-impact Instagram post with bold typography`,previewPrompt:`New Product Launch`},{id:`ig-post-minimal`,name:`Clean & Minimal`,category:`social`,presetId:`instagram-post`,style:`minimal`,description:`Minimalist Instagram post with elegant framing`,previewPrompt:`Mindful Living`},{id:`ig-story-gradient`,name:`Gradient Story`,category:`social`,presetId:`instagram-story`,style:`gradient`,description:`Modern gradient Instagram story`,previewPrompt:`Summer Vibes`},{id:`fb-cover-split`,name:`Split Cover`,category:`social`,presetId:`facebook-cover`,style:`split`,description:`Two-tone Facebook cover photo`,previewPrompt:`Welcome to Our Community`},{id:`linkedin-minimal`,name:`Professional Banner`,category:`business`,presetId:`linkedin-banner`,style:`minimal`,description:`Clean LinkedIn banner for professionals`,previewPrompt:`Innovation & Strategy`},{id:`twitter-bold`,name:`Tweet Graphic`,category:`social`,presetId:`twitter-post`,style:`bold`,description:`Eye-catching Twitter/X post graphic`,previewPrompt:`Breaking News`},{id:`yt-gradient`,name:`YouTube Thumbnail`,category:`social`,presetId:`youtube-thumbnail`,style:`gradient`,description:`Vibrant YouTube thumbnail`,previewPrompt:`Top 10 Tips`},{id:`presentation-centered`,name:`Title Slide`,category:`presentation`,presetId:`presentation`,style:`centered`,description:`Warm presentation title slide`,previewPrompt:`Quarterly Review`},{id:`bcard-minimal`,name:`Business Card`,category:`business`,presetId:`business-card`,style:`minimal`,description:`Elegant business card layout`,previewPrompt:`Jane Smith | Designer`},{id:`invoice-split`,name:`Invoice Header`,category:`business`,presetId:`invoice`,style:`split`,description:`Professional invoice header layout`,previewPrompt:`Invoice #1234`},{id:`sale-bold`,name:`Flash Sale`,category:`marketing`,presetId:`instagram-post`,style:`bold`,description:`High-energy sale promotion post`,previewPrompt:`50% Off Everything`},{id:`launch-gradient`,name:`Product Launch`,category:`marketing`,presetId:`instagram-post`,style:`gradient`,description:`Modern product launch announcement`,previewPrompt:`Introducing Our New Product`}];function k(){let e=new Map;for(let t of O){let n=e.get(t.category)??[];n.push(t),e.set(t.category,n)}return e}var A=`forge:canvas-state:v1`;function j(){if(typeof window>`u`)return{};try{let e=localStorage.getItem(A);if(!e)return{};let t=JSON.parse(e),n={savedDesigns:t.savedDesigns??{},artboardPresetId:t.artboardPresetId??null,activeTool:t.activeTool??`select`};return t.brandKit&&(n.brandKit=t.brandKit),n}catch{return{}}}function M(e){if(!(typeof window>`u`))try{let t={savedDesigns:e.savedDesigns,artboardPresetId:e.artboardPresetId,activeTool:e.activeTool,brandKit:e.brandKit};localStorage.setItem(A,JSON.stringify(t))}catch{}}var N=j(),P={activeTool:N.activeTool??`select`,artboardPresetId:N.artboardPresetId??`instagram-post`,artboardWidth:1080,artboardHeight:1080,selectedObjectIds:[],selectedObjectProperties:null,propertiesPanelOpen:!1,historyStack:[],historyIndex:-1,layers:[],zoomLevel:1,savedDesigns:N.savedDesigns??{},brandKit:N.brandKit??g,pendingGeneratePrompt:null},F=t()((e,t)=>({...P,setActiveTool:n=>{e({activeTool:n}),M(t())},setArtboard:(n,r,i)=>{e({artboardPresetId:n,artboardWidth:r,artboardHeight:i}),M(t())},setSelectedObjects:(t,n)=>{e({selectedObjectIds:t,selectedObjectProperties:n,propertiesPanelOpen:t.length>0})},clearSelection:()=>{e({selectedObjectIds:[],selectedObjectProperties:null})},setPropertiesPanelOpen:t=>{e({propertiesPanelOpen:t})},pushHistorySnapshot:t=>{e(e=>{let n=[...e.historyStack.slice(0,e.historyIndex+1),t].slice(-50);return{historyStack:n,historyIndex:n.length-1}})},undo:()=>{let n=t();if(n.historyIndex<=0)return null;let r=n.historyIndex-1;return e({historyIndex:r}),n.historyStack[r]??null},redo:()=>{let n=t();if(n.historyIndex>=n.historyStack.length-1)return null;let r=n.historyIndex+1;return e({historyIndex:r}),n.historyStack[r]??null},setLayers:t=>{e({layers:t})},setZoomLevel:t=>{e({zoomLevel:t})},saveDesign:(n,r,i)=>{e(e=>({savedDesigns:{...e.savedDesigns,[n]:{json:i,name:r,updatedAt:new Date().toISOString()}}})),M(t())},loadDesign:e=>t().savedDesigns[e]?.json??null,deleteDesign:n=>{e(e=>{let{[n]:t,...r}=e.savedDesigns;return{savedDesigns:r}}),M(t())},resetHistory:()=>{e({historyStack:[],historyIndex:-1})},setBrandKit:n=>{e({brandKit:n}),M(t())},updateBrandKit:n=>{e(e=>({brandKit:{...e.brandKit,...n}})),M(t())},requestCanvasGenerate:t=>{e({pendingGeneratePrompt:t})},consumePendingGenerate:()=>{let n=t().pendingGeneratePrompt;return n&&e({pendingGeneratePrompt:null}),n}}));export{i as _,k as a,p as c,u as d,l as f,a as g,o as h,S as i,f as l,s as m,O as n,h as o,c as p,g as r,m as s,F as t,d as u,r as v,n as y};
2
- //# sourceMappingURL=canvasStateStore-DYt9MgFu.js.map
1
+ import{dn as e}from"./CompositeItem-D1GrQhpu.js";import{t}from"./react-A0DLYjwn.js";var n=e(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),r=e(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),i=e(`chevrons-down`,[[`path`,{d:`m7 6 5 5 5-5`,key:`1lc07p`}],[`path`,{d:`m7 13 5 5 5-5`,key:`1d48rs`}]]),a=e(`chevrons-up`,[[`path`,{d:`m17 11-5-5-5 5`,key:`e8nh98`}],[`path`,{d:`m17 18-5-5-5 5`,key:`2avn1x`}]]),o=e(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),s=e(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),c=e(`eye-off`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),l=e(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),u=e(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),d=e(`mouse-pointer-2`,[[`path`,{d:`M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z`,key:`edeuup`}]]),f=e(`palette`,[[`path`,{d:`M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z`,key:`e79jfc`}],[`circle`,{cx:`13.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`1okk4w`}],[`circle`,{cx:`17.5`,cy:`10.5`,r:`.5`,fill:`currentColor`,key:`f64h9f`}],[`circle`,{cx:`6.5`,cy:`12.5`,r:`.5`,fill:`currentColor`,key:`qy21gx`}],[`circle`,{cx:`8.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`fotxhn`}]]),p=e(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),m=e(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),h=e(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),g={primaryColor:`#6366f1`,secondaryColor:`#8b5cf6`,accentColor:`#f59e0b`,backgroundColor:`#ffffff`,textColor:`#1f2937`,fontFamily:`Inter, sans-serif`,headingFontFamily:`Inter, sans-serif`},_={bold:{bg:`#1f2937`,accent:`#f59e0b`,text:`#ffffff`},minimal:{bg:`#ffffff`,accent:`#6366f1`,text:`#1f2937`},gradient:{bg:`#4f46e5`,accent:`#818cf8`,text:`#ffffff`},split:{bg:`#f8fafc`,accent:`#0ea5e9`,text:`#0f172a`},centered:{bg:`#fef3c7`,accent:`#d97706`,text:`#78350f`}},v=[`bold`,`minimal`,`gradient`,`split`,`centered`];function y(e){let t=e.toLowerCase();return t.includes(`bold`)||t.includes(`sale`)||t.includes(`announcement`)?`bold`:t.includes(`minimal`)||t.includes(`clean`)||t.includes(`simple`)?`minimal`:t.includes(`gradient`)||t.includes(`modern`)||t.includes(`tech`)?`gradient`:t.includes(`split`)||t.includes(`compare`)||t.includes(`versus`)?`split`:t.includes(`warm`)||t.includes(`friendly`)||t.includes(`welcome`)?`centered`:v[Math.floor(Math.random()*v.length)]??`bold`}function b(e){let t=e.replace(/^(create|make|design|generate)\s+(a|an|me)?\s*/i,``).replace(/\s*(instagram|facebook|twitter|linkedin|youtube|social media|post|story|banner|cover|thumbnail)\s*/gi,``).replace(/\s*(about|for|with|featuring)\s*/i,`|`).trim().split(`|`).map(e=>e.trim()).filter(Boolean),n=t[0]??``;if(t.length>=2)return{heading:x(n),subtext:x(t.slice(1).join(` `))};if(n.length>30){let e=n.split(` `),t=Math.ceil(e.length/2);return{heading:x(e.slice(0,t).join(` `)),subtext:x(e.slice(t).join(` `))}}return{heading:n?x(n):`Your Title Here`,subtext:`Add your message`}}function x(e){return e.charAt(0).toUpperCase()+e.slice(1)}function S(e,t,n,r=g){let i=y(e),a=_[i],{heading:o,subtext:s}=b(e),c=t>n;Math.abs(t-n);let l=[];switch(l.push({type:`rect`,left:0,top:0,width:t,height:n,fill:a.bg,selectable:!1,customId:`__bg__`,customName:`Background`}),i){case`bold`:l.push(...C(t,n,a,o,s,r));break;case`minimal`:l.push(...w(t,n,a,o,s,r));break;case`gradient`:l.push(...T(t,n,a,o,s,r));break;case`split`:l.push(...E(t,n,a,o,s,c,r));break;case`centered`:l.push(...D(t,n,a,o,s,r))}return{objects:l}}function C(e,t,n,r,i,a){let o=Math.min(e,t)*.08,s=Math.min(e,t)*.1,c=s*.4;return[{type:`rect`,left:0,top:0,width:e,height:t*.06,fill:n.accent,customName:`Accent Bar`},{type:`textbox`,left:o,top:t*.3,width:e-o*2,text:r.toUpperCase(),fontSize:s,fontFamily:a.headingFontFamily,fontWeight:`900`,fill:n.text,textAlign:`left`,customName:`Heading`},{type:`textbox`,left:o,top:t*.55,width:e-o*2,text:i,fontSize:c,fontFamily:a.fontFamily,fontWeight:`400`,fill:n.accent,textAlign:`left`,customName:`Subtext`},{type:`rect`,left:o,top:t*.85,width:e*.3,height:4,fill:n.accent,customName:`Accent Line`}]}function w(e,t,n,r,i,a){let o=Math.min(e,t)*.08,s=o*.45;return[{type:`rect`,left:e*.04,top:t*.04,width:e*.92,height:t*.92,fill:`transparent`,stroke:n.accent,strokeWidth:2,customName:`Frame`},{type:`textbox`,left:e*.1,top:t*.35,width:e*.8,text:r,fontSize:o,fontFamily:a.headingFontFamily,fontWeight:`600`,fill:n.text,textAlign:`center`,customName:`Heading`},{type:`rect`,left:e*.4,top:t*.52,width:e*.2,height:2,fill:n.accent,customName:`Divider`},{type:`textbox`,left:e*.15,top:t*.58,width:e*.7,text:i,fontSize:s,fontFamily:a.fontFamily,fontWeight:`400`,fill:`#6b7280`,textAlign:`center`,customName:`Subtext`}]}function T(e,t,n,r,i,a){let o=Math.min(e,t)*.09,s=o*.4;return[{type:`rect`,left:0,top:t*.6,width:e,height:t*.4,fill:`rgba(0,0,0,0.3)`,customName:`Overlay`},{type:`ellipse`,left:e*.7,top:-t*.15,rx:e*.25,ry:e*.25,fill:n.accent,opacity:.3,customName:`Deco Circle`},{type:`textbox`,left:e*.08,top:t*.35,width:e*.84,text:r,fontSize:o,fontFamily:a.headingFontFamily,fontWeight:`700`,fill:n.text,textAlign:`center`,customName:`Heading`},{type:`textbox`,left:e*.12,top:t*.65,width:e*.76,text:i,fontSize:s,fontFamily:a.fontFamily,fontWeight:`400`,fill:`rgba(255,255,255,0.85)`,textAlign:`center`,customName:`Subtext`}]}function E(e,t,n,r,i,a,o){let s=Math.min(e,t)*.08,c=s*.45;return a?[{type:`rect`,left:0,top:0,width:e*.45,height:t,fill:n.accent,customName:`Color Panel`},{type:`textbox`,left:e*.52,top:t*.3,width:e*.42,text:r,fontSize:s,fontFamily:o.headingFontFamily,fontWeight:`700`,fill:n.text,textAlign:`left`,customName:`Heading`},{type:`textbox`,left:e*.52,top:t*.55,width:e*.42,text:i,fontSize:c,fontFamily:o.fontFamily,fontWeight:`400`,fill:`#64748b`,textAlign:`left`,customName:`Subtext`}]:[{type:`rect`,left:0,top:0,width:e,height:t*.45,fill:n.accent,customName:`Color Panel`},{type:`textbox`,left:e*.08,top:t*.52,width:e*.84,text:r,fontSize:s,fontFamily:o.headingFontFamily,fontWeight:`700`,fill:n.text,textAlign:`center`,customName:`Heading`},{type:`textbox`,left:e*.12,top:t*.72,width:e*.76,text:i,fontSize:c,fontFamily:o.fontFamily,fontWeight:`400`,fill:`#64748b`,textAlign:`center`,customName:`Subtext`}]}function D(e,t,n,r,i,a){let o=Math.min(e,t)*.09,s=o*.4;return[{type:`rect`,left:e*.1,top:t*.15,width:e*.8,height:t*.7,fill:`rgba(255,255,255,0.7)`,rx:20,ry:20,customName:`Card`},{type:`textbox`,left:e*.15,top:t*.3,width:e*.7,text:r,fontSize:o,fontFamily:a.headingFontFamily,fontWeight:`700`,fill:n.text,textAlign:`center`,customName:`Heading`},{type:`textbox`,left:e*.18,top:t*.55,width:e*.64,text:i,fontSize:s,fontFamily:a.fontFamily,fontWeight:`400`,fill:n.text,textAlign:`center`,opacity:.7,customName:`Subtext`},{type:`rect`,left:e*.3,top:t*.72,width:e*.4,height:Math.min(e,t)*.07,fill:n.accent,rx:8,ry:8,customName:`CTA Button`},{type:`textbox`,left:e*.3,top:t*.725,width:e*.4,text:`Learn More`,fontSize:s*.9,fontFamily:a.fontFamily,fontWeight:`600`,fill:`#ffffff`,textAlign:`center`,customName:`CTA Text`}]}var O=[{id:`ig-post-bold`,name:`Bold Announcement`,category:`social`,presetId:`instagram-post`,style:`bold`,description:`High-impact Instagram post with bold typography`,previewPrompt:`New Product Launch`},{id:`ig-post-minimal`,name:`Clean & Minimal`,category:`social`,presetId:`instagram-post`,style:`minimal`,description:`Minimalist Instagram post with elegant framing`,previewPrompt:`Mindful Living`},{id:`ig-story-gradient`,name:`Gradient Story`,category:`social`,presetId:`instagram-story`,style:`gradient`,description:`Modern gradient Instagram story`,previewPrompt:`Summer Vibes`},{id:`fb-cover-split`,name:`Split Cover`,category:`social`,presetId:`facebook-cover`,style:`split`,description:`Two-tone Facebook cover photo`,previewPrompt:`Welcome to Our Community`},{id:`linkedin-minimal`,name:`Professional Banner`,category:`business`,presetId:`linkedin-banner`,style:`minimal`,description:`Clean LinkedIn banner for professionals`,previewPrompt:`Innovation & Strategy`},{id:`twitter-bold`,name:`Tweet Graphic`,category:`social`,presetId:`twitter-post`,style:`bold`,description:`Eye-catching Twitter/X post graphic`,previewPrompt:`Breaking News`},{id:`yt-gradient`,name:`YouTube Thumbnail`,category:`social`,presetId:`youtube-thumbnail`,style:`gradient`,description:`Vibrant YouTube thumbnail`,previewPrompt:`Top 10 Tips`},{id:`presentation-centered`,name:`Title Slide`,category:`presentation`,presetId:`presentation`,style:`centered`,description:`Warm presentation title slide`,previewPrompt:`Quarterly Review`},{id:`bcard-minimal`,name:`Business Card`,category:`business`,presetId:`business-card`,style:`minimal`,description:`Elegant business card layout`,previewPrompt:`Jane Smith | Designer`},{id:`invoice-split`,name:`Invoice Header`,category:`business`,presetId:`invoice`,style:`split`,description:`Professional invoice header layout`,previewPrompt:`Invoice #1234`},{id:`sale-bold`,name:`Flash Sale`,category:`marketing`,presetId:`instagram-post`,style:`bold`,description:`High-energy sale promotion post`,previewPrompt:`50% Off Everything`},{id:`launch-gradient`,name:`Product Launch`,category:`marketing`,presetId:`instagram-post`,style:`gradient`,description:`Modern product launch announcement`,previewPrompt:`Introducing Our New Product`}];function k(){let e=new Map;for(let t of O){let n=e.get(t.category)??[];n.push(t),e.set(t.category,n)}return e}var A=`forge:canvas-state:v1`;function j(){if(typeof window>`u`)return{};try{let e=localStorage.getItem(A);if(!e)return{};let t=JSON.parse(e),n={savedDesigns:t.savedDesigns??{},artboardPresetId:t.artboardPresetId??null,activeTool:t.activeTool??`select`};return t.brandKit&&(n.brandKit=t.brandKit),n}catch{return{}}}function M(e){if(!(typeof window>`u`))try{let t={savedDesigns:e.savedDesigns,artboardPresetId:e.artboardPresetId,activeTool:e.activeTool,brandKit:e.brandKit};localStorage.setItem(A,JSON.stringify(t))}catch{}}var N=j(),P={activeTool:N.activeTool??`select`,artboardPresetId:N.artboardPresetId??`instagram-post`,artboardWidth:1080,artboardHeight:1080,selectedObjectIds:[],selectedObjectProperties:null,propertiesPanelOpen:!1,historyStack:[],historyIndex:-1,layers:[],zoomLevel:1,savedDesigns:N.savedDesigns??{},brandKit:N.brandKit??g,pendingGeneratePrompt:null},F=t()((e,t)=>({...P,setActiveTool:n=>{e({activeTool:n}),M(t())},setArtboard:(n,r,i)=>{e({artboardPresetId:n,artboardWidth:r,artboardHeight:i}),M(t())},setSelectedObjects:(t,n)=>{e({selectedObjectIds:t,selectedObjectProperties:n,propertiesPanelOpen:t.length>0})},clearSelection:()=>{e({selectedObjectIds:[],selectedObjectProperties:null})},setPropertiesPanelOpen:t=>{e({propertiesPanelOpen:t})},pushHistorySnapshot:t=>{e(e=>{let n=[...e.historyStack.slice(0,e.historyIndex+1),t].slice(-50);return{historyStack:n,historyIndex:n.length-1}})},undo:()=>{let n=t();if(n.historyIndex<=0)return null;let r=n.historyIndex-1;return e({historyIndex:r}),n.historyStack[r]??null},redo:()=>{let n=t();if(n.historyIndex>=n.historyStack.length-1)return null;let r=n.historyIndex+1;return e({historyIndex:r}),n.historyStack[r]??null},setLayers:t=>{e({layers:t})},setZoomLevel:t=>{e({zoomLevel:t})},saveDesign:(n,r,i)=>{e(e=>({savedDesigns:{...e.savedDesigns,[n]:{json:i,name:r,updatedAt:new Date().toISOString()}}})),M(t())},loadDesign:e=>t().savedDesigns[e]?.json??null,deleteDesign:n=>{e(e=>{let{[n]:t,...r}=e.savedDesigns;return{savedDesigns:r}}),M(t())},resetHistory:()=>{e({historyStack:[],historyIndex:-1})},setBrandKit:n=>{e({brandKit:n}),M(t())},updateBrandKit:n=>{e(e=>({brandKit:{...e.brandKit,...n}})),M(t())},requestCanvasGenerate:t=>{e({pendingGeneratePrompt:t})},consumePendingGenerate:()=>{let n=t().pendingGeneratePrompt;return n&&e({pendingGeneratePrompt:null}),n}}));export{i as _,k as a,p as c,u as d,l as f,a as g,o as h,S as i,f as l,s as m,O as n,h as o,c as p,g as r,m as s,F as t,d as u,r as v,n as y};
2
+ //# sourceMappingURL=canvasStateStore-dUmp5NFj.js.map
@@ -0,0 +1,2 @@
1
+ import{dn as e}from"./CompositeItem-D1GrQhpu.js";var t=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]);export{t};
2
+ //# sourceMappingURL=chevron-left-BXpfeqsT.js.map
@@ -0,0 +1,2 @@
1
+ import{dn as e}from"./CompositeItem-D1GrQhpu.js";var t=e(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]);export{t};
2
+ //# sourceMappingURL=chevron-right-B103tjaJ.js.map
@@ -0,0 +1,3 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/__vite-browser-external-2W3EstLn.js","assets/rolldown-runtime-hePW80VL.js"])))=>i.map(i=>d[i]);
2
+ import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{$ as n,$t as r,A as i,C as a,Cn as o,Dr as s,E as c,Et as l,Fa as u,Fn as d,Ft as f,G as p,Ha as m,Ht as h,I as g,Ia as ee,In as te,J as _,Jt as ne,K as v,L as y,La as b,Lt as x,M as S,N as C,Na as w,Nr as T,Nt as E,O as D,Or as O,Ot as k,P as A,Pt as j,Q as M,R as N,Rt as P,Si as F,St as re,T as ie,Ti as ae,Tn as oe,U as se,Ui as ce,Ut as le,Vn as ue,Vt as de,W as fe,X as pe,Xr as me,Y as he,Yn as ge,Z as _e,_ as ve,_n as ye,ai as be,an as xe,at as Se,b as Ce,bi as we,bn as Te,c as Ee,cn as De,d as Oe,ei as ke,f as Ae,ga as je,gt as Me,h as Ne,hn as Pe,ht as Fe,ii as Ie,it as Le,j as Re,k as ze,kr as Be,li as Ve,mn as He,n as Ue,ni as We,nn as Ge,oi as Ke,on as qe,p as Je,pn as Ye,q as Xe,qr as Ze,qt as Qe,r as $e,ri as et,rn as tt,s as nt,sn as rt,t as it,ti as at,tt as ot,u as st,vn as ct,vt as lt,wt as ut,xn as dt,xt as ft,yn as pt,zn as mt,zt as ht}from"./Effect-CyyMOw4X.js";import{a as gt,c as _t,l as vt,n as yt,o as bt,r as xt,s as St}from"./atomRegistry-CzI2zp7d.js";import{C as Ct,F as wt,N as Tt,O as Et,P as Dt,T as Ot,j as kt,s as At,w as jt,x as Mt}from"./Stream-Bvl2Z6qI.js";import{B as Nt,Ft as Pt,Gt as Ft,Ht as It,It as Lt,Pt as Rt,Ut as zt,V as Bt,X as Vt,c as Ht,d as Ut,f as Wt,g as Gt,m as Kt,o as qt,p as Jt,rn as Yt,rt as Xt,s as I,u as Zt}from"./src-7C4X1Oy2.js";import{I as Qt,L as $t,O as en,P as tn,R as nn,a as rn,at as an,d as on,g as sn,nt as cn,o as ln,ot as un,p as dn,x as fn,y as pn,z as mn}from"./Schema-8EGdYSms.js";import{t as hn}from"./preload-helper-Czpn1I53.js";import{i as gn,n as _n}from"./cmmdEmbedMode-DhVvltxi.js";var vn=t(m(),1),yn={[Symbol.iterator](){return bn}},bn={next(){return{done:!0,value:void 0}}},xn=()=>yn,Sn=new WeakMap;function Cn(e,t){let n=Sn.get(e);n===void 0&&(n=new WeakMap,Sn.set(e,n));let r=n.get(t);if(r!==void 0)return r;let i={subscribe(n){return e.subscribe(t,n)},snapshot(){return e.get(t)},getServerSnapshot(){return gt(t,e)}};return n.set(t,i),i}function wn(e,t){let n=Cn(e,t);return vn.useSyncExternalStore(n.subscribe,n.snapshot,n.getServerSnapshot)}var Tn=(e,t)=>{let n=vn.useContext(xt);return t?wn(n,vn.useMemo(()=>_t(e,t),[e,t])):wn(n,e)},En=(e,t,n)=>{let r=vn.useContext(xt);vn.useEffect(()=>r.subscribe(e,t,n),[r,e,t,n?.immediate])},Dn=`~effect/FiberSet`,On=e=>je(e,Dn),kn={[Dn]:Dn,[Symbol.iterator](){return this.state._tag===`Closed`?xn():this.state.backing[Symbol.iterator]()},...ce,toJSON(){return{_id:`FiberMap`,state:this.state}}},An=(e,t)=>{let n=Object.create(kn);return n.state={_tag:`Open`,backing:e},n.deferred=t,n},jn=()=>it(re(()=>An(new Set,ct())),e=>ft(()=>{let t=e.state;if(t._tag===`Closed`)return f;e.state={_tag:`Closed`};let n=t.backing;return wt(n).pipe(ye(e.deferred))})),Mn=-1,Nn=Be(s(d,O(Mn))),Pn=u(e=>On(e[0]),(e,t,n)=>{if(e.state._tag===`Closed`){t.interruptUnsafe(Mn);return}e.state.backing.has(t)||(e.state.backing.add(t),t.addObserver(r=>{e.state._tag!==`Closed`&&(e.state.backing.delete(t),oe(r)&&(n?.propagateInterruption===!0?!Nn(r.cause):!mt(r.cause))&&Pe(e.deferred,r))}))}),Fn=function(){let e;return()=>(e===void 0&&(e=Le(S)),e)}(),In=e=>()=>N(Oe(),t=>{let n=Se(t);return(t,r)=>{if(e.state._tag===`Closed`)return Fn();let i=n(t,r);return Pn(e,i),i}}),Ln=e=>He(e.deferred),Rn=`~effect/socket/Socket`,zn=We(`effect/socket/Socket`),Bn=`~effect/socket/Socket/CloseEvent`,Vn=e=>je(e,Bn),Hn=`~effect/socket/Socket/SocketError`,Un=e=>je(e,Hn),Wn=class extends ln(`effect/socket/Socket/SocketReadError`)({_tag:an(`SocketReadError`),cause:rn}){message=`An error occurred during Read`},Gn=class extends ln(`effect/socket/Socket/SocketWriteError`)({_tag:an(`SocketWriteError`),cause:rn}){message=`An error occurred during Write`},Kn=class extends ln(`effect/socket/Socket/SocketOpenError`)({_tag:an(`SocketOpenError`),kind:on([`Unknown`,`Timeout`]),cause:rn}){get message(){return this.kind===`Timeout`?`timeout waiting for "open"`:`An error occurred during Open`}},qn=class extends ln(`effect/socket/Socket/SocketCloseError`)({_tag:an(`SocketCloseError`),code:sn,closeReason:cn(pn)}){static filterClean(e){return function(t){return Yn.is(t)&&t.reason._tag===`SocketCloseError`&&e(t.reason.code)?ke(t.reason):Ze(t)}}get message(){return this.closeReason?`${this.code}: ${this.closeReason}`:`${this.code}`}},Jn=en([Wn,Gn,Kn,qn]),Yn=class extends fn(Hn)(`SocketError`,{_tag:an(`SocketError`),reason:Jn}){constructor(e){`cause`in e.reason?super({...e,cause:e.reason.cause}):super(e)}[Hn]=Hn;static is(e){return Un(e)}message=this.reason.message},Xn=e=>!0,Zn=class extends We()(`~effect/socket/Socket/WebSocket`){},Qn=class extends We()(`@effect/platform/Socket/WebSocketConstructor`){},$n=(e,t)=>Qn.use(n=>er(it((typeof e==`string`?lt(e):e).pipe(N(e=>n(e,t?.protocols))),e=>re(()=>e.close(1e3))),t)),er=(e,t)=>P(r=>{let i,o=kt(!1),s=r.context,c=t?.closeCodeIsError??Xn,l=(r,l)=>Fe(a(function*(a){let s=yield*jn().pipe(Ye(a)),u=yield*Ye(e,a),d=yield*M(In(s)(),Zn,u),p=!1;function m(e){if(e.data instanceof Blob){let t=Ce(he(()=>e.data.arrayBuffer()),e=>{let t=r(new Uint8Array(e));return A(t)?t:f});return d(t)}let t=r(e.data);A(t)&&d(t)}function h(e){u.removeEventListener(`message`,m),u.removeEventListener(`close`,g),Pe(s.deferred,ve(new Yn({reason:p?new Wn({cause:e}):new Kn({kind:`Unknown`,cause:e})})))}function g(e){let t=typeof e.code==`number`?e.code:1001;u.removeEventListener(`message`,m),u.removeEventListener(`error`,h),Pe(s.deferred,ve(new Yn({reason:new qn({code:t,closeReason:e.reason})})))}if(u.addEventListener(`close`,g,{once:!0}),u.addEventListener(`error`,h,{once:!0}),u.addEventListener(`message`,m),u.readyState!==1){let e=ct();u.addEventListener(`open`,()=>{p=!0,Pe(e,f)},{once:!0}),yield*He(e).pipe(k({duration:t?.openTimeout??1e4,orElse:()=>ve(new Yn({reason:new Kn({kind:`Timeout`,cause:Error(`timeout waiting for "open"`)})}))}),n(Ln(s)))}return p=!0,i=u,o.openUnsafe(),l?.onOpen&&(yield*l.onOpen),yield*st(Ln(s),qn.filterClean(e=>!c(e)),()=>f)})).pipe(E(e=>Ve(s,e)),Ne(re(()=>{o.closeUnsafe(),i=void 0}))),u=new TextEncoder,d=(e,t)=>l(t=>typeof t==`string`?e(u.encode(t)):t instanceof Uint8Array?e(t):e(new Uint8Array(t)),t),p=lt(e=>o.whenOpen(re(()=>{let t=i;Vn(e)?t.close(e.code,e.reason):t.send(e)})));return lt(zn.of({[Rn]:Rn,run:d,runRaw:l,writer:p}))}),tr=ee($n,r(zn)),nr=class extends We()(`effect/workers/Transferable/Collector`){},rr=()=>{let e=[],t=t=>{e.push(...t)},n=()=>e,r=()=>{let t=e;return e=[],t};return nr.of({addAllUnsafe:t,addAll:e=>re(()=>t(e)),readUnsafe:n,read:re(n),clearUnsafe:r,clear:re(r)})},ir=`~effect/workers/WorkerError`,ar=class extends ln(`effect/workers/WorkerError/WorkerSpawnError`)({_tag:an(`WorkerSpawnError`),message:pn,cause:cn(rn)}){},or=class extends ln(`effect/workers/WorkerError/WorkerSendError`)({_tag:an(`WorkerSendError`),message:pn,cause:cn(rn)}){},sr=class extends ln(`effect/workers/WorkerError/WorkerReceiveError`)({_tag:an(`WorkerReceiveError`),message:pn,cause:cn(rn)}){},cr=class extends ln(`effect/workers/WorkerError/WorkerUnknownError`)({_tag:an(`WorkerUnknownError`),message:pn,cause:cn(rn)}){},lr=en([ar,or,sr,cr]);ln(ir)({_tag:an(`WorkerError`),reason:lr});var ur=`~effect/rpc/RpcClientError`,dr=class extends ln(`effect/rpc/RpcClientError/RpcClientDefect`)({_tag:an(`RpcClientDefect`),message:pn,cause:rn}){},fr=class extends ln(ur)({_tag:an(`RpcClientError`),reason:en([lr,Jn,Yt,dr])}){[ur]=ur;get message(){return`${this.reason._tag}: ${this.reason.message}`}},pr=e=>typeof e==`bigint`?e:BigInt(e),mr={_tag:`Ping`},hr;try{hr=new TextDecoder}catch{}var L,gr,R=0,_r=[],vr=_r,yr=0,z={},B,br,xr=0,Sr=0,V,Cr,wr=[],H,Tr={useRecords:!1,mapsAsObjects:!0},Er=class{},Dr=new Er;Dr.name=`MessagePack 0xC1`;var Or=!1,kr=2,Ar,jr,Mr;try{Function(``)}catch{kr=1/0}var Nr=class e{constructor(e){e&&(e.useRecords===!1&&e.mapsAsObjects===void 0&&(e.mapsAsObjects=!0),e.sequential&&e.trusted!==!1&&(e.trusted=!0,!e.structures&&e.useRecords!=0&&(e.structures=[],e.maxSharedStructures||=0)),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0),e.int64AsNumber&&(e.int64AsType=`number`)),Object.assign(this,e)}unpack(t,n){if(L)return oi(()=>(si(),this?this.unpack(t,n):e.prototype.unpack.call(Tr,t,n)));!t.buffer&&t.constructor===ArrayBuffer&&(t=typeof Buffer<`u`?Buffer.from(t):new Uint8Array(t)),typeof n==`object`?(gr=n.end||t.length,R=n.start||0):(R=0,gr=n>-1?n:t.length),yr=0,Sr=0,br=null,vr=_r,V=null,L=t;try{H=t.dataView||(t.dataView=new DataView(t.buffer,t.byteOffset,t.byteLength))}catch(e){throw L=null,t instanceof Uint8Array?e:Error(`Source must be a Uint8Array or Buffer but was a `+(t&&typeof t==`object`?t.constructor.name:typeof t))}if(this instanceof e){if(z=this,this.structures)return B=this.structures,Pr(n);(!B||B.length>0)&&(B=[])}else z=Tr,(!B||B.length>0)&&(B=[]);return Pr(n)}unpackMultiple(e,t){let n,r=0;try{Or=!0;let i=e.length,a=this?this.unpack(e,i):li.unpack(e,i);if(t){if(t(a,r,R)===!1)return;for(;R<i;)if(r=R,t(Pr(),r,R)===!1)return}else{for(n=[a];R<i;)r=R,n.push(Pr());return n}}catch(e){throw e.lastPosition=r,e.values=n,e}finally{Or=!1,si()}}_mergeStructures(e,t){jr&&(e=jr.call(this,e)),e||=[],Object.isFrozen(e)&&(e=e.map(e=>e.slice(0)));for(let t=0,n=e.length;t<n;t++){let n=e[t];n&&(n.isShared=!0,t>=32&&(n.highByte=t-32>>5))}e.sharedLength=e.length;for(let n in t||[])if(n>=0){let r=e[n],i=t[n];i&&(r&&((e.restoreStructures||(e.restoreStructures=[]))[n]=r),e[n]=i)}return this.structures=e}decode(e,t){return this.unpack(e,t)}};function Pr(e){try{if(!z.trusted&&!Or){let e=B.sharedLength||0;e<B.length&&(B.length=e)}let t;if(z.randomAccessStructure&&L[R]<64&&L[R]>=32&&Ar?(t=Ar(L,R,gr,z),L=null,!(e&&e.lazy)&&t&&(t=t.toJSON()),R=gr):t=U(),V&&=(R=V.postBundlePosition,null),Or&&(B.restoreStructures=null),R==gr)B&&B.restoreStructures&&Fr(),B=null,L=null,Cr&&=null;else if(R>gr)throw Error(`Unexpected end of MessagePack data`);else if(!Or){let e;try{e=JSON.stringify(t,(e,t)=>typeof t==`bigint`?`${t}n`:t).slice(0,100)}catch(t){e=`(JSON view not available `+t+`)`}throw Error(`Data read, but end of buffer not reached `+e)}return t}catch(e){throw B&&B.restoreStructures&&Fr(),si(),(e instanceof RangeError||e.message.startsWith(`Unexpected end of buffer`)||R>gr)&&(e.incomplete=!0),e}}function Fr(){for(let e in B.restoreStructures)B[e]=B.restoreStructures[e];B.restoreStructures=null}function U(){let e=L[R++];if(e<160)if(e<128){if(e<64)return e;{let t=B[e&63]||z.getStructures&&zr()[e&63];return t?(t.read||=Lr(t,e&63),t.read()):e}}else if(e<144){if(e-=128,z.mapsAsObjects){let t={};for(let n=0;n<e;n++){let e=$r();e===`__proto__`&&(e=`__proto_`),t[e]=U()}return t}{let t=new Map;for(let n=0;n<e;n++)t.set(U(),U());return t}}else{e-=144;let t=Array(e);for(let n=0;n<e;n++)t[n]=U();return z.freezeData?Object.freeze(t):t}if(e<192){let t=e-160;if(Sr>=R)return br.slice(R-xr,(R+=t)-xr);if(Sr==0&&gr<140){let e=t<16?Jr(t):qr(t);if(e!=null)return e}return Br(t)}{let t;switch(e){case 192:return null;case 193:return V?(t=U(),t>0?V[1].slice(V.position1,V.position1+=t):V[0].slice(V.position0,V.position0-=t)):Dr;case 194:return!1;case 195:return!0;case 196:if(t=L[R++],t===void 0)throw Error(`Unexpected end of buffer`);return Xr(t);case 197:return t=H.getUint16(R),R+=2,Xr(t);case 198:return t=H.getUint32(R),R+=4,Xr(t);case 199:return Zr(L[R++]);case 200:return t=H.getUint16(R),R+=2,Zr(t);case 201:return t=H.getUint32(R),R+=4,Zr(t);case 202:if(t=H.getFloat32(R),z.useFloat32>2){let e=ci[(L[R]&127)<<1|L[R+1]>>7];return R+=4,(e*t+(t>0?.5:-.5)>>0)/e}return R+=4,t;case 203:return t=H.getFloat64(R),R+=8,t;case 204:return L[R++];case 205:return t=H.getUint16(R),R+=2,t;case 206:return t=H.getUint32(R),R+=4,t;case 207:return z.int64AsType===`number`?(t=H.getUint32(R)*4294967296,t+=H.getUint32(R+4)):z.int64AsType===`string`?t=H.getBigUint64(R).toString():z.int64AsType===`auto`?(t=H.getBigUint64(R),t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=H.getBigUint64(R),R+=8,t;case 208:return H.getInt8(R++);case 209:return t=H.getInt16(R),R+=2,t;case 210:return t=H.getInt32(R),R+=4,t;case 211:return z.int64AsType===`number`?(t=H.getInt32(R)*4294967296,t+=H.getUint32(R+4)):z.int64AsType===`string`?t=H.getBigInt64(R).toString():z.int64AsType===`auto`?(t=H.getBigInt64(R),t>=BigInt(-2)<<BigInt(52)&&t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=H.getBigInt64(R),R+=8,t;case 212:if(t=L[R++],t==114)return ti(L[R++]&63);{let e=wr[t];if(e)return e.read?(R++,e.read(U())):e.noBuffer?(R++,e()):e(L.subarray(R,++R));throw Error(`Unknown extension `+t)}case 213:return t=L[R],t==114?(R++,ti(L[R++]&63,L[R++])):Zr(2);case 214:return Zr(4);case 215:return Zr(8);case 216:return Zr(16);case 217:return t=L[R++],Sr>=R?br.slice(R-xr,(R+=t)-xr):Vr(t);case 218:return t=H.getUint16(R),R+=2,Sr>=R?br.slice(R-xr,(R+=t)-xr):Hr(t);case 219:return t=H.getUint32(R),R+=4,Sr>=R?br.slice(R-xr,(R+=t)-xr):Ur(t);case 220:return t=H.getUint16(R),R+=2,Gr(t);case 221:return t=H.getUint32(R),R+=4,Gr(t);case 222:return t=H.getUint16(R),R+=2,Kr(t);case 223:return t=H.getUint32(R),R+=4,Kr(t);default:if(e>=224)return e-256;if(e===void 0){let e=Error(`Unexpected end of MessagePack data`);throw e.incomplete=!0,e}throw Error(`Unknown MessagePack token `+e)}}}var Ir=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function Lr(e,t){function n(){if(n.count++>kr){let n=e.read=Function(`r`,`return function(){return `+(z.freezeData?`Object.freeze`:``)+`({`+e.map(e=>e===`__proto__`?`__proto_:r()`:Ir.test(e)?e+`:r()`:`[`+JSON.stringify(e)+`]:r()`).join(`,`)+`})}`)(U);return e.highByte===0&&(e.read=Rr(t,e.read)),n()}let r={};for(let t=0,n=e.length;t<n;t++){let n=e[t];n===`__proto__`&&(n=`__proto_`),r[n]=U()}return z.freezeData?Object.freeze(r):r}return n.count=0,e.highByte===0?Rr(t,n):n}var Rr=(e,t)=>function(){let n=L[R++];if(n===0)return t();let r=e<32?-(e+(n<<5)):e+(n<<5),i=B[r]||zr()[r];if(!i)throw Error(`Record id is not defined for `+r);return i.read||=Lr(i,e),i.read()};function zr(){let e=oi(()=>(L=null,z.getStructures()));return B=z._mergeStructures(e,B)}var Br=Wr,Vr=Wr,Hr=Wr,Ur=Wr;function Wr(e){let t;if(e<16&&(t=Jr(e)))return t;if(e>64&&hr)return hr.decode(L.subarray(R,R+=e));let n=R+e,r=[];for(t=``;R<n;){let e=L[R++];if(!(e&128))r.push(e);else if((e&224)==192){let t=L[R++]&63,n=(e&31)<<6|t;n<128?r.push(65533):r.push(n)}else if((e&240)==224){let t=L[R++]&63,n=L[R++]&63,i=(e&31)<<12|t<<6|n;i<2048||i>=55296&&i<=57343?r.push(65533):r.push(i)}else if((e&248)==240){let t=L[R++]&63,n=L[R++]&63,i=L[R++]&63,a=(e&7)<<18|t<<12|n<<6|i;a<65536||a>1114111?r.push(65533):a>65535?(a-=65536,r.push(a>>>10&1023|55296),a=56320|a&1023,r.push(a)):r.push(a)}else r.push(65533);r.length>=4096&&(t+=W.apply(String,r),r.length=0)}return r.length>0&&(t+=W.apply(String,r)),t}function Gr(e){let t=Array(e);for(let n=0;n<e;n++)t[n]=U();return z.freezeData?Object.freeze(t):t}function Kr(e){if(z.mapsAsObjects){let t={};for(let n=0;n<e;n++){let e=$r();e===`__proto__`&&(e=`__proto_`),t[e]=U()}return t}{let t=new Map;for(let n=0;n<e;n++)t.set(U(),U());return t}}var W=String.fromCharCode;function qr(e){let t=R,n=Array(e);for(let r=0;r<e;r++){let e=L[R++];if((e&128)>0){R=t;return}n[r]=e}return W.apply(String,n)}function Jr(e){if(e<4)if(e<2){if(e===0)return``;{let e=L[R++];if((e&128)>1){--R;return}return W(e)}}else{let t=L[R++],n=L[R++];if((t&128)>0||(n&128)>0){R-=2;return}if(e<3)return W(t,n);let r=L[R++];if((r&128)>0){R-=3;return}return W(t,n,r)}{let t=L[R++],n=L[R++],r=L[R++],i=L[R++];if((t&128)>0||(n&128)>0||(r&128)>0||(i&128)>0){R-=4;return}if(e<6){if(e===4)return W(t,n,r,i);{let e=L[R++];if((e&128)>0){R-=5;return}return W(t,n,r,i,e)}}if(e<8){let a=L[R++],o=L[R++];if((a&128)>0||(o&128)>0){R-=6;return}if(e<7)return W(t,n,r,i,a,o);let s=L[R++];if((s&128)>0){R-=7;return}return W(t,n,r,i,a,o,s)}{let a=L[R++],o=L[R++],s=L[R++],c=L[R++];if((a&128)>0||(o&128)>0||(s&128)>0||(c&128)>0){R-=8;return}if(e<10){if(e===8)return W(t,n,r,i,a,o,s,c);{let e=L[R++];if((e&128)>0){R-=9;return}return W(t,n,r,i,a,o,s,c,e)}}if(e<12){let l=L[R++],u=L[R++];if((l&128)>0||(u&128)>0){R-=10;return}if(e<11)return W(t,n,r,i,a,o,s,c,l,u);let d=L[R++];if((d&128)>0){R-=11;return}return W(t,n,r,i,a,o,s,c,l,u,d)}{let l=L[R++],u=L[R++],d=L[R++],f=L[R++];if((l&128)>0||(u&128)>0||(d&128)>0||(f&128)>0){R-=12;return}if(e<14){if(e===12)return W(t,n,r,i,a,o,s,c,l,u,d,f);{let e=L[R++];if((e&128)>0){R-=13;return}return W(t,n,r,i,a,o,s,c,l,u,d,f,e)}}{let p=L[R++],m=L[R++];if((p&128)>0||(m&128)>0){R-=14;return}if(e<15)return W(t,n,r,i,a,o,s,c,l,u,d,f,p,m);let h=L[R++];if((h&128)>0){R-=15;return}return W(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h)}}}}}function Yr(){let e=L[R++],t;if(e<192)t=e-160;else switch(e){case 217:t=L[R++];break;case 218:t=H.getUint16(R),R+=2;break;case 219:t=H.getUint32(R),R+=4;break;default:throw Error(`Expected string`)}return Wr(t)}function Xr(e){return z.copyBuffers?Uint8Array.prototype.slice.call(L,R,R+=e):L.subarray(R,R+=e)}function Zr(e){let t=L[R++];if(wr[t]){let n;return wr[t](L.subarray(R,n=R+=e),e=>{R=e;try{return U()}finally{R=n}})}throw Error(`Unknown extension type `+t)}var Qr=Array(4096);function $r(){let e=L[R++];if(e>=160&&e<192){if(e-=160,Sr>=R)return br.slice(R-xr,(R+=e)-xr);if(!(Sr==0&&gr<180))return Br(e)}else return R--,ei(U());let t=(e<<5^(e>1?H.getUint16(R):e>0?L[R]:0))&4095,n=Qr[t],r=R,i=R+e-3,a,o=0;if(n&&n.bytes==e){for(;r<i;){if(a=H.getUint32(r),a!=n[o++]){r=1879048192;break}r+=4}for(i+=3;r<i;)if(a=L[r++],a!=n[o++]){r=1879048192;break}if(r===i)return R=r,n.string;i-=3,r=R}for(n=[],Qr[t]=n,n.bytes=e;r<i;)a=H.getUint32(r),n.push(a),r+=4;for(i+=3;r<i;)a=L[r++],n.push(a);let s=e<16?Jr(e):qr(e);return s==null?n.string=Br(e):n.string=s}function ei(e){if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return e.toString();if(e==null)return e+``;if(z.allowArraysInMapKeys&&Array.isArray(e)&&e.flat().every(e=>[`string`,`number`,`boolean`,`bigint`].includes(typeof e)))return e.flat().toString();throw Error(`Invalid property type for record: ${typeof e}`)}var ti=(e,t)=>{let n=U().map(ei),r=e;t!==void 0&&(e=e<32?-((t<<5)+e):(t<<5)+e,n.highByte=t);let i=B[e];return i&&(i.isShared||Or)&&((B.restoreStructures||(B.restoreStructures=[]))[e]=i),B[e]=n,n.read=Lr(n,r),n.read()};wr[0]=()=>{},wr[0].noBuffer=!0,wr[66]=e=>{let t=e.byteLength%8||8,n=BigInt(e[0]&128?e[0]-256:e[0]);for(let r=1;r<t;r++)n<<=BigInt(8),n+=BigInt(e[r]);if(e.byteLength!==t){let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=(e,t)=>{let n=t-e;if(n<=40){let n=r.getBigUint64(e);for(let i=e+8;i<t;i+=8)n<<=64n,n|=r.getBigUint64(i);return n}let a=e+(n>>4<<3),o=i(e,a),s=i(a,t);return o<<BigInt((t-a)*8)|s};n=n<<BigInt((r.byteLength-t)*8)|i(t,r.byteLength)}return n};var ni={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError:typeof AggregateError==`function`?AggregateError:null};wr[101]=()=>{let e=U();if(!ni[e[0]]){let t=Error(e[1],{cause:e[2]});return t.name=e[0],t}return ni[e[0]](e[1],{cause:e[2]})},wr[105]=e=>{if(z.structuredClone===!1)throw Error(`Structured clone extension is disabled`);let t=H.getUint32(R-4);Cr||=new Map;let n=L[R],r;r=n>=144&&n<160||n==220||n==221?[]:n>=128&&n<144||n==222||n==223?new Map:(n>=199&&n<=201||n>=212&&n<=216)&&L[R+1]===115?new Set:{};let i={target:r};Cr.set(t,i);let a=U();if(i.used)Object.assign(r,a);else return i.target=a;if(r instanceof Map)for(let[e,t]of a.entries())r.set(e,t);if(r instanceof Set)for(let e of Array.from(a))r.add(e);return r},wr[112]=e=>{if(z.structuredClone===!1)throw Error(`Structured clone extension is disabled`);let t=H.getUint32(R-4),n=Cr.get(t);return n.used=!0,n.target},wr[115]=()=>new Set(U());var ri=[`Int8`,`Uint8`,`Uint8Clamped`,`Int16`,`Uint16`,`Int32`,`Uint32`,`Float32`,`Float64`,`BigInt64`,`BigUint64`].map(e=>e+`Array`),ii=typeof globalThis==`object`?globalThis:window;wr[116]=e=>{let t=e[0],n=Uint8Array.prototype.slice.call(e,1).buffer,r=ri[t];if(!r){if(t===16)return n;if(t===17)return new DataView(n);throw Error(`Could not find typed array for code `+t)}return new ii[r](n)},wr[120]=()=>{let e=U();return new RegExp(e[0],e[1])};var ai=[];wr[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],n=R;return R+=t-e.length,V=ai,V=[Yr(),Yr()],V.position0=0,V.position1=0,V.postBundlePosition=R,R=n,U()},wr[255]=e=>e.length==4?new Date((e[0]*16777216+(e[1]<<16)+(e[2]<<8)+e[3])*1e3):e.length==8?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+((e[3]&3)*4294967296+e[4]*16777216+(e[5]<<16)+(e[6]<<8)+e[7])*1e3):e.length==12?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+((e[4]&128?-281474976710656:0)+e[6]*1099511627776+e[7]*4294967296+e[8]*16777216+(e[9]<<16)+(e[10]<<8)+e[11])*1e3):new Date(`invalid`);function oi(e){Mr&&Mr();let t=gr,n=R,r=yr,i=xr,a=Sr,o=br,s=vr,c=Cr,l=V,u=new Uint8Array(L.slice(0,gr)),d=B,f=B.slice(0,B.length),p=z,m=Or,h=e();return gr=t,R=n,yr=r,xr=i,Sr=a,br=o,vr=s,Cr=c,V=l,L=u,Or=m,B=d,B.splice(0,B.length,...f),z=p,H=new DataView(L.buffer,L.byteOffset,L.byteLength),h}function si(){L=null,Cr=null,B=null}var ci=Array(147);for(let e=0;e<256;e++)ci[e]=+(`1e`+Math.floor(45.15-e*.30103));var li=new Nr({useRecords:!1});li.unpack,li.unpackMultiple,li.unpack;var ui={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};new Uint8Array(new Float32Array(1).buffer,0,4);var di;try{di=new TextEncoder}catch{}var fi,pi,mi=typeof Buffer<`u`,hi=mi?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,gi=mi?Buffer:Uint8Array,_i=mi?4294967296:2144337920,G,vi,K,q=0,yi,J=null,bi,xi=21760,Si=/[\u0080-\uFFFF]/,Ci=Symbol(`record-id`),wi=class extends Nr{constructor(e){super(e),this.offset=0;let t,n,r,i,a=gi.prototype.utf8Write?function(e,t){return G.utf8Write(e,t,G.byteLength-t)}:di&&di.encodeInto?function(e,t){return di.encodeInto(e,G.subarray(t)).written}:!1,o=this;e||={};let s=e&&e.sequential,c=e.structures||e.saveStructures,l=e.maxSharedStructures;if(l??=c?32:0,l>8160)throw Error(`Maximum maxSharedStructure is 8160`);e.structuredClone&&e.moreTypes==null&&(this.moreTypes=!0);let u=e.maxOwnStructures;u??=c?32:64,!this.structures&&e.useRecords!=0&&(this.structures=[]);let d=l>32||u+l>64,f=l+64,p=l+u+64;if(p>8256)throw Error(`Maximum maxSharedStructure + maxOwnStructure is 8192`);let m=[],h=0,g=0;this.pack=this.encode=function(e,a){if(G||(G=new hi(8192),K=G.dataView||(G.dataView=new DataView(G.buffer,0,8192)),q=0),yi=G.length-10,yi-q<2048?(G=new hi(G.length),K=G.dataView||(G.dataView=new DataView(G.buffer,0,G.length)),yi=G.length-10,q=0):q=q+7&2147483640,t=q,a&2048&&(q+=a&255),i=o.structuredClone?new Map:null,o.bundleStrings&&typeof e!=`string`?(J=[],J.size=1/0):J=null,r=o.structures,r){r.uninitialized&&(r=o._mergeStructures(o.getStructures()));let e=r.sharedLength||0;if(e>l)throw Error(`Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to `+r.sharedLength);if(!r.transitions){r.transitions=Object.create(null);for(let t=0;t<e;t++){let e=r[t];if(!e)continue;let n,i=r.transitions;for(let t=0,r=e.length;t<r;t++){let r=e[t];n=i[r],n||=i[r]=Object.create(null),i=n}i[Ci]=t+64}this.lastNamedStructuresLength=e}s||(r.nextId=e+64)}n&&=!1;let c;try{o.randomAccessStructure&&e&&typeof e==`object`?e.constructor===Object?w(e):e.constructor!==Map&&!Array.isArray(e)&&!pi.some(t=>e instanceof t)?w(e.toJSON?e.toJSON():e):_(e):_(e);let n=J;if(J&&ki(t,_,0),i&&i.idsToInsert){let e=i.idsToInsert.sort((e,t)=>e.offset>t.offset?1:-1),r=e.length,a=-1;for(;n&&r>0;){let i=e[--r].offset+t;i<n.stringsPosition+t&&a===-1&&(a=0),i>n.position+t?a>=0&&(a+=6):(a>=0&&(K.setUint32(n.position+t,K.getUint32(n.position+t)+a),a=-1),n=n.previous,r++)}a>=0&&n&&K.setUint32(n.position+t,K.getUint32(n.position+t)+a),q+=e.length*6,q>yi&&x(q),o.offset=q;let s=Oi(G.subarray(t,q),e);return i=null,s}return o.offset=q,a&512?(G.start=t,G.end=q,G):G.subarray(t,q)}catch(e){throw c=e,e}finally{if(r&&(ee(),n&&o.saveStructures)){let n=r.sharedLength||0,i=G.subarray(t,q),s=Ai(r,o);if(!c)return o.saveStructures(s,s.isCompatible)===!1?o.pack(e,a):(o.lastNamedStructuresLength=n,G.length>1073741824&&(G=null),i)}G.length>1073741824&&(G=null),a&1024&&(q=t)}};let ee=()=>{g<10&&g++;let e=r.sharedLength||0;if(r.length>e&&!s&&(r.length=e),h>1e4)r.transitions=null,g=0,h=0,m.length>0&&(m=[]);else if(m.length>0&&!s){for(let e=0,t=m.length;e<t;e++)m[e][Ci]=0;m=[]}},te=e=>{var t=e.length;t<16?G[q++]=144|t:t<65536?(G[q++]=220,G[q++]=t>>8,G[q++]=t&255):(G[q++]=221,K.setUint32(q,t),q+=4);for(let n=0;n<t;n++)_(e[n])},_=e=>{q>yi&&(G=x(q));var n=typeof e,r;if(n===`string`){let n=e.length;if(J&&n>=4&&n<4096){if((J.size+=n)>xi){let e,n=(J[0]?J[0].length*3+J[1].length:0)+10;q+n>yi&&(G=x(q+n));let r;J.position?(r=J,G[q]=200,q+=3,G[q++]=98,e=q-t,q+=4,ki(t,_,0),K.setUint16(e+t-3,q-t-e)):(G[q++]=214,G[q++]=98,e=q-t,q+=4),J=[``,``],J.previous=r,J.size=0,J.position=e}let r=Si.test(e);J[+!r]+=e,G[q++]=193,_(r?-n:n);return}let i;i=n<32?1:n<256?2:n<65536?3:5;let o=n*3;if(q+o>yi&&(G=x(q+o)),n<64||!a){let t,a,o,s=q+i;for(t=0;t<n;t++)a=e.charCodeAt(t),a<128?G[s++]=a:a<2048?(G[s++]=a>>6|192,G[s++]=a&63|128):(a&64512)==55296&&((o=e.charCodeAt(t+1))&64512)==56320?(a=65536+((a&1023)<<10)+(o&1023),t++,G[s++]=a>>18|240,G[s++]=a>>12&63|128,G[s++]=a>>6&63|128,G[s++]=a&63|128):(G[s++]=a>>12|224,G[s++]=a>>6&63|128,G[s++]=a&63|128);r=s-q-i}else r=a(e,q+i);r<32?G[q++]=160|r:r<256?(i<2&&G.copyWithin(q+2,q+1,q+1+r),G[q++]=217,G[q++]=r):r<65536?(i<3&&G.copyWithin(q+3,q+2,q+2+r),G[q++]=218,G[q++]=r>>8,G[q++]=r&255):(i<5&&G.copyWithin(q+5,q+3,q+3+r),G[q++]=219,K.setUint32(q,r),q+=4),q+=r}else if(n===`number`)if(e>>>0===e)e<32||e<128&&this.useRecords===!1||e<64&&!this.randomAccessStructure?G[q++]=e:e<256?(G[q++]=204,G[q++]=e):e<65536?(G[q++]=205,G[q++]=e>>8,G[q++]=e&255):(G[q++]=206,K.setUint32(q,e),q+=4);else if(e>>0===e)e>=-32?G[q++]=256+e:e>=-128?(G[q++]=208,G[q++]=e+256):e>=-32768?(G[q++]=209,K.setInt16(q,e),q+=2):(G[q++]=210,K.setInt32(q,e),q+=4);else{let t;if((t=this.useFloat32)>0&&e<4294967296&&e>=-2147483648){G[q++]=202,K.setFloat32(q,e);let n;if(t<4||(n=e*ci[(G[q]&127)<<1|G[q+1]>>7])>>0===n){q+=4;return}q--}G[q++]=203,K.setFloat64(q,e),q+=8}else if(n===`object`||n===`function`)if(!e)G[q++]=192;else{if(i){let n=i.get(e);if(n){n.id||=(i.idsToInsert||(i.idsToInsert=[])).push(n),G[q++]=214,G[q++]=112,K.setUint32(q,n.id),q+=4;return}i.set(e,{offset:q-t})}let a=e.constructor;if(a===Object)b(e);else if(a===Array)te(e);else if(a===Map)if(this.mapAsEmptyObject)G[q++]=128;else{r=e.size,r<16?G[q++]=128|r:r<65536?(G[q++]=222,G[q++]=r>>8,G[q++]=r&255):(G[q++]=223,K.setUint32(q,r),q+=4);for(let[t,n]of e)_(t),_(n)}else{for(let t=0,n=fi.length;t<n;t++){let n=pi[t];if(e instanceof n){let n=fi[t];if(n.write){n.type&&(G[q++]=212,G[q++]=n.type,G[q++]=0);let t=n.write.call(this,e);t===e?Array.isArray(e)?te(e):b(e):_(t);return}let r=G,i=K,a=q;G=null;let o;try{o=n.pack.call(this,e,e=>(G=r,r=null,q+=e,q>yi&&x(q),{target:G,targetView:K,position:q-e}),_)}finally{r&&(G=r,K=i,q=a,yi=G.length-10)}o&&(o.length+q>yi&&x(o.length+q),q=Di(o,G,q,n.type));return}}if(Array.isArray(e))te(e);else{if(e.toJSON){let t=e.toJSON();if(t!==e)return _(t)}if(n===`function`)return _(this.writeFunction&&this.writeFunction(e));b(e)}}}else if(n===`boolean`)G[q++]=e?195:194;else if(n===`bigint`){if(e<0x8000000000000000&&e>=-0x8000000000000000)G[q++]=211,K.setBigInt64(q,e);else if(e<0x10000000000000000&&e>0)G[q++]=207,K.setBigUint64(q,e);else if(this.largeBigIntToFloat)G[q++]=203,K.setFloat64(q,Number(e));else if(this.largeBigIntToString)return _(e.toString());else if(this.useBigIntExtension||this.moreTypes){let t=BigInt(e<0?-1:0),n;if(e>>BigInt(65536)===t){let r=BigInt(0x10000000000000000)-BigInt(1),i=[];for(;i.push(e&r),e>>BigInt(63)!==t;)e>>=BigInt(64);n=new Uint8Array(new BigUint64Array(i).buffer),n.reverse()}else{let t=e<0,r=(t?~e:e).toString(16);if(r.length%2?r=`0`+r:parseInt(r.charAt(0),16)>=8&&(r=`00`+r),mi)n=Buffer.from(r,`hex`);else{n=new Uint8Array(r.length/2);for(let e=0;e<n.length;e++)n[e]=parseInt(r.slice(e*2,e*2+2),16)}if(t)for(let e=0;e<n.length;e++)n[e]=~n[e]}n.length+q>yi&&x(n.length+q),q=Di(n,G,q,66);return}else throw RangeError(e+` was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string`);q+=8}else if(n===`undefined`)this.encodeUndefinedAsNil?G[q++]=192:(G[q++]=212,G[q++]=0,G[q++]=0);else throw Error(`Unknown type: `+n)},ne=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?e=>{let t;if(this.skipValues){t=[];for(let n in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(n))&&!this.skipValues.includes(e[n])&&t.push(n)}else t=Object.keys(e);let n=t.length;n<16?G[q++]=128|n:n<65536?(G[q++]=222,G[q++]=n>>8,G[q++]=n&255):(G[q++]=223,K.setUint32(q,n),q+=4);let r;if(this.coercibleKeyAsNumber)for(let i=0;i<n;i++){r=t[i];let n=Number(r);_(isNaN(n)?r:n),_(e[r])}else for(let i=0;i<n;i++)_(r=t[i]),_(e[r])}:e=>{G[q++]=222;let n=q-t;q+=2;let r=0;for(let t in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(t))&&(_(t),_(e[t]),r++);if(r>65535)throw Error(`Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object`);G[n+++t]=r>>8,G[n+t]=r&255},v=this.useRecords===!1?ne:e.progressiveRecords&&!d?e=>{let n,i=r.transitions||(r.transitions=Object.create(null)),a=q++-t,o;for(let s in e)if(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(s)){if(n=i[s],n)i=n;else{let c=Object.keys(e),l=i;i=r.transitions;let u=0;for(let e=0,t=c.length;e<t;e++){let t=c[e];n=i[t],n||(n=i[t]=Object.create(null),u++),i=n}a+t+1==q?(q--,S(i,c,u)):C(i,c,a,u),o=!0,i=l[s]}_(e[s])}if(!o){let n=i[Ci];n?G[a+t]=n:C(i,Object.keys(e),a,0)}}:e=>{let t,n=r.transitions||(r.transitions=Object.create(null)),i=0;for(let r in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(r))&&(t=n[r],t||(t=n[r]=Object.create(null),i++),n=t);let a=n[Ci];a?a>=96&&d?(G[q++]=((a-=96)&31)+96,G[q++]=a>>5):G[q++]=a:S(n,n.__keys__||Object.keys(e),i);for(let t in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(t))&&_(e[t])},y=typeof this.useRecords==`function`&&this.useRecords,b=y?e=>{y(e)?v(e):ne(e)}:v,x=e=>{let n;if(e>16777216){if(e-t>_i)throw Error(`Packed buffer would be larger than maximum buffer size`);n=Math.min(_i,Math.round(Math.max((e-t)*(e>67108864?1.25:2),4194304)/4096)*4096)}else n=(Math.max(e-t<<2,G.length-1)>>12)+1<<12;let r=new hi(n);return K=r.dataView||=new DataView(r.buffer,0,n),e=Math.min(e,G.length),G.copy?G.copy(r,0,t,e):r.set(G.slice(t,e)),q-=t,t=0,yi=r.length-10,G=r},S=(e,t,i)=>{let a=r.nextId;a||=64,a<f&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(a=r.nextOwnId,a<p||(a=f),r.nextOwnId=a+1):(a>=p&&(a=f),r.nextId=a+1);let o=t.highByte=a>=96&&d?a-96>>5:-1;e[Ci]=a,e.__keys__=t,r[a-64]=t,a<f?(t.isShared=!0,r.sharedLength=a-63,n=!0,o>=0?(G[q++]=(a&31)+96,G[q++]=o):G[q++]=a):(o>=0?(G[q++]=213,G[q++]=114,G[q++]=(a&31)+96,G[q++]=o):(G[q++]=212,G[q++]=114,G[q++]=a),i&&(h+=g*i),m.length>=u&&(m.shift()[Ci]=0),m.push(e),_(t))},C=(e,n,r,i)=>{let a=G,o=q,s=yi,c=t;G=vi,q=0,t=0,G||(vi=G=new hi(8192)),yi=G.length-10,S(e,n,i),vi=G;let l=q;if(G=a,q=o,yi=s,t=c,l>1){let e=q+l-1;e>yi&&x(e);let n=r+t;G.copyWithin(n+l,n+1,q),G.set(vi.slice(0,l),n),q=e}else G[r+t]=vi[0]},w=e=>{let i=bi(e,G,t,q,r,x,(e,t,r)=>{if(r)return n=!0;q=t;let i=G;return _(e),ee(),i===G?q:{position:q,targetView:K,target:G}},this);if(i===0)return b(e);q=i}}useBuffer(e){G=e,G.dataView||(G.dataView=new DataView(G.buffer,G.byteOffset,G.byteLength)),K=G.dataView,q=0}set position(e){q=e}get position(){return q}clearSharedData(){this.structures&&=[],this.typedStructs&&=[]}};pi=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,Er],fi=[{pack(e,t,n){let r=e.getTime()/1e3;if((this.useTimestamp32||e.getMilliseconds()===0)&&r>=0&&r<4294967296){let{target:e,targetView:n,position:i}=t(6);e[i++]=214,e[i++]=255,n.setUint32(i,r)}else if(r>0&&r<4294967296){let{target:n,targetView:i,position:a}=t(10);n[a++]=215,n[a++]=255,i.setUint32(a,e.getMilliseconds()*4e6+(r/1e3/4294967296>>0)),i.setUint32(a+4,r)}else if(isNaN(r)){if(this.onInvalidDate)return t(0),n(this.onInvalidDate());let{target:e,targetView:r,position:i}=t(3);e[i++]=212,e[i++]=255,e[i++]=255}else{let{target:n,targetView:i,position:a}=t(15);n[a++]=199,n[a++]=12,n[a++]=255,i.setUint32(a,e.getMilliseconds()*1e6),i.setBigInt64(a+4,BigInt(Math.floor(r)))}}},{pack(e,t,n){if(this.setAsEmptyObject)return t(0),n({});let r=Array.from(e),{target:i,position:a}=t(this.moreTypes?3:0);this.moreTypes&&(i[a++]=212,i[a++]=115,i[a++]=0),n(r)}},{pack(e,t,n){let{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=101,r[i++]=0),n([e.name,e.message,e.cause])}},{pack(e,t,n){let{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=120,r[i++]=0),n([e.source,e.flags])}},{pack(e,t){this.moreTypes?Ti(e,16,t):Ei(mi?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let n=e.constructor;n!==gi&&this.moreTypes?Ti(e,ri.indexOf(n.name),t):Ei(e,t)}},{pack(e,t){this.moreTypes?Ti(e,17,t):Ei(mi?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let{target:n,position:r}=t(1);n[r]=193}}];function Ti(e,t,n,r){let i=e.byteLength;if(i+1<256){var{target:a,position:o}=n(4+i);a[o++]=199,a[o++]=i+1}else if(i+1<65536){var{target:a,position:o}=n(5+i);a[o++]=200,a[o++]=i+1>>8,a[o++]=i+1&255}else{var{target:a,position:o,targetView:s}=n(7+i);a[o++]=201,s.setUint32(o,i+1),o+=4}a[o++]=116,a[o++]=t,e.buffer||(e=new Uint8Array(e)),a.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),o)}function Ei(e,t){let n=e.byteLength;var r,i;if(n<256){var{target:r,position:i}=t(n+2);r[i++]=196,r[i++]=n}else if(n<65536){var{target:r,position:i}=t(n+3);r[i++]=197,r[i++]=n>>8,r[i++]=n&255}else{var{target:r,position:i,targetView:a}=t(n+5);r[i++]=198,a.setUint32(i,n),i+=4}r.set(e,i)}function Di(e,t,n,r){let i=e.length;switch(i){case 1:t[n++]=212;break;case 2:t[n++]=213;break;case 4:t[n++]=214;break;case 8:t[n++]=215;break;case 16:t[n++]=216;break;default:i<256?(t[n++]=199,t[n++]=i):i<65536?(t[n++]=200,t[n++]=i>>8,t[n++]=i&255):(t[n++]=201,t[n++]=i>>24,t[n++]=i>>16&255,t[n++]=i>>8&255,t[n++]=i&255)}return t[n++]=r,t.set(e,n),n+=i,n}function Oi(e,t){let n,r=t.length*6,i=e.length-r;for(;n=t.pop();){let t=n.offset,a=n.id;e.copyWithin(t+r,t,i),r-=6;let o=t+r;e[o++]=214,e[o++]=105,e[o++]=a>>24,e[o++]=a>>16&255,e[o++]=a>>8&255,e[o++]=a&255,i=t}return e}function ki(e,t,n){if(J.length>0){K.setUint32(J.position+e,q+n-J.position-e),J.stringsPosition=q-e;let r=J;J=null,t(r[0]),t(r[1])}}function Ai(e,t){return e.isCompatible=e=>{let n=!e||(t.lastNamedStructuresLength||0)===e.length;return n||t._mergeStructures(e),n},e}var ji=new wi({useRecords:!1});ji.pack,ji.pack;var{NEVER:Mi,ALWAYS:Ni,DECIMAL_ROUND:Pi,DECIMAL_FIT:Fi}=ui,Ii=class extends We()(`effect/rpc/RpcSerialization`){},Li=Ii.of({contentType:`application/json`,includesFraming:!1,makeUnsafe:()=>{let e=new TextDecoder;return{decode:t=>{let n=JSON.parse(typeof t==`string`?t:e.decode(t));return Array.isArray(n)?n:[n]},encode:e=>JSON.stringify(e)}}}),Ri=xe(Ii)(Li),zi=e=>ft(()=>{let t=new Set,n=new Map,r=new Map,a=(e,t)=>Ae(r=>{let i=n.get(e);return i||(i=[],n.set(e,i)),i.push([t,r]),f});return N(e((e,t)=>{let n=r.get(e);return n?n(t):a(e,t)},t),e=>({...e,run(e,a){return i(function*(){t.add(e),r.set(e,a);let i=n.get(e);if(i){n.delete(e);for(let[e,t]of i)yield*_e(ft(()=>a(e)),t)}return yield*v(fe,()=>(t.delete(e),r.delete(e),f))})}}))}),Bi=BigInt(0),Vi=a(function*(e,t){let n=t?.spanPrefix??`RpcClient`,r=t?.supportsAck??!0,i=t?.disableTracing??!1,s=t?.generateRequestId??(()=>Bi++),c=yield*Oe(),u=be(c,qe),d=new Map,p=!1;yield*rt(u,P(e=>(p=!0,m(o(e.id)))));let m=a(function*(e){for(let[t,n]of d)d.delete(t),n._tag===`Queue`?yield*e._tag===`Success`?jt(n.queue):Ot(n.queue,e.cause):n.resume(e)}),h=e=>{let r=Lt(e.successSchema),a=te(e);return(o,s)=>{let c=s?.headers?zt(s.headers):It,l=s?.context??Ie();if(!r){let r=t=>g(e,a,t,e.payloadSchema.make(o),c,l,s?.discard??!1);return i?r(void 0):j(`${n}.${e._tag}`,{attributes:t.spanAttributes},r)}let u=ee(e,a,e.payloadSchema.make(o),c,s?.streamBufferSize??16,l);return s?.asQueue?u:Mt(N(u,At))}},g=(e,n,r,i,a,o,c)=>P(l=>{if(p)return S;let u=s(),f=n(e=>t.onFromClient({message:e,context:o,discard:c}),{_tag:`Request`,id:u,tag:e._tag,payload:i,...r?{traceId:r.traceId,spanId:r.spanId,sampled:r.sampled}:{},headers:Ft(l.getRef(Ki),a)});if(c)return f;let m;return Xe(nt(t=>{let n={_tag:`Effect`,rpc:e,context:o,resume(e){t(e),m&&!m.pollUnsafe()&&l.currentDispatcher.scheduleTask(()=>{m.interruptUnsafe(l.id)},0)}};d.set(u,n),m=f.pipe(r?ht(r,{captureStackTrace:!1}):b,Se(l.context)),m.addObserver(e=>{if(e._tag===`Failure`)return t(e)})}),e=>(d.delete(u),Ue(Dt(m),_(u,Array.from(e),o))))}),ee=a(function*(e,r,a,o,c,l){if(p)return yield*S;let u=i?void 0:yield*y(`${n}.${e._tag}`,{attributes:t.spanAttributes}),m=Tt(),h=s(),g=Ke(m.context,qe);yield*De(g,e=>d.has(h)?(d.delete(h),_(h,oe(e)?Array.from(ue(e.cause)):[],l)):f);let ee=yield*Ct(c);return d.set(h,{_tag:`Queue`,rpc:e,queue:ee,scope:g,context:l}),yield*r(e=>t.onFromClient({message:e,context:l,discard:!1}),{_tag:`Request`,id:h,tag:e._tag,payload:a,...u?{traceId:u.traceId,spanId:u.spanId,sampled:u.sampled}:{},headers:Ft(m.getRef(Ki),o)}).pipe(u?ht(u,{captureStackTrace:!1}):b,Ee(e=>Ot(ee,e)),C,D(g,{startImmediately:!0})),ee}),te=e=>{let t=[];for(let n of e.middlewares.values()){let e=c.mapUnsafe.get(`${n.key}/Client`);e&&t.push(e)}return t.length===0?(e,t)=>e(t):function n(r,i,a=t.length-1){return a===-1?r(i):t[a]({rpc:e,request:i,next(e){return n(r,e,a-1)}})}},_=(e,n,r)=>nt(i=>{let a=Tt();t.onFromClient({message:{_tag:`Interrupt`,requestId:e,interruptors:n},context:r,discard:!1}).pipe(l(1e3),Se(a.context)).addObserver(()=>{i(f)})}),ne=e=>{switch(e._tag){case`Chunk`:{let n=e.requestId,i=d.get(n);return!i||i._tag!==`Queue`?f:Et(i.queue,e.values).pipe(r?Ce(()=>t.onFromClient({message:{_tag:`Ack`,requestId:e.requestId},context:i.context,discard:!1})):b,Ee(e=>Ot(i.queue,e)))}case`Exit`:{let t=e.requestId,n=d.get(t);return n?(d.delete(t),n._tag===`Effect`?(n.resume(e.exit),f):e.exit._tag===`Success`?jt(n.queue):Ot(n.queue,e.exit.cause)):f}case`Defect`:return m(pt(e.defect));case`ClientEnd`:return f}},v;if(t.flatten){let t=new Map;v=function(n,r,i){let a=t.get(n);return a||(a=h(e.requests.get(n)),t.set(n,a)),a(r,i)}}else v={},e.requests.forEach(e=>{v[e._tag]=h(e)});return{client:v,write:ne}}),Hi=0,Ui=a(function*(e,t){let n=Hi++,{run:r,send:i,supportsAck:a,supportsTransferables:o}=yield*qi,s=new Map,{client:c,write:l}=yield*Vi(e,{...t,supportsAck:a,onFromClient({message:t}){switch(t._tag){case`Request`:{let r=e.requests.get(t.tag),a=o?rr():void 0,c=Tt(),l={rpc:r,context:a?et(c.context,nr,a):c.context,schemas:Gi(r)};return s.set(t.id,l),l.schemas.encodePayload(t.payload).pipe(_e(l.context),_,Ce(e=>i(n,{...t,id:String(t.id),payload:e,headers:Object.entries(t.headers)},a&&a.readUnsafe())))}case`Ack`:return s.get(t.requestId)?i(n,{_tag:`Ack`,requestId:String(t.requestId)}):f;case`Interrupt`:return s.get(t.requestId)?(s.delete(t.requestId),i(n,{_tag:`Interrupt`,requestId:String(t.requestId)})):f;case`Eof`:return f}}});return yield*r(n,e=>{switch(e._tag){case`Chunk`:{let t=pr(e.requestId),n=s.get(t);return!n||we(n.schemas.decodeChunk)?f:n.schemas.decodeChunk.value(e.values).pipe(_e(n.context),_,Ce(t=>l({_tag:`Chunk`,clientId:0,requestId:pr(e.requestId),values:t})),p(t=>l({_tag:`Exit`,clientId:0,requestId:pr(e.requestId),exit:dt(t)})))}case`Exit`:{let t=pr(e.requestId),n=s.get(t);return n?(s.delete(t),n.schemas.decodeExit(e.exit).pipe(_e(n.context),_,se({onSuccess:e=>l({_tag:`Exit`,clientId:0,requestId:t,exit:e}),onFailure:e=>l({_tag:`Exit`,clientId:0,requestId:t,exit:dt(e)})}))):f}case`Defect`:return l({_tag:`Defect`,clientId:0,defect:Qi(e.defect)});case`ClientProtocolError`:{let t=Te(e.error);return ie(s.keys(),e=>l({_tag:`Exit`,clientId:0,requestId:e,exit:t}))}default:return f}}).pipe(Ee(g),C,ze),c}),Wi=new WeakMap,Gi=e=>{let t=Wi.get(e);if(t!==void 0)return t;let n=Pt(e.successSchema);return t={decodeChunk:ae(n,e=>Qt(un(dn(e.success)))),encodePayload:mn(un(e.payloadSchema)),decodeExit:Qt(un(Rt(e)))},Wi.set(e,t),t},Ki=at(`effect/rpc/RpcClient/CurrentHeaders`,{defaultValue:()=>It}),qi=class extends We()(`effect/rpc/RpcClient/Protocol`){static make=zi},Ji=e=>qi.make(a(function*(t,r){let i=yield*zn,a=yield*Ii,o=yield*Me(Zi),s=new Map,c=yield*i.writer,l=a.makeUnsafe(),u=yield*Xi(c(l.encode(mr))),d,p=ft(()=>(d=void 0,F(o)?o.value.onConnect:f)),m=e=>ie(r,n=>t(n,e));return yield*ft(()=>(l=a.makeUnsafe(),u.reset(),i.runRaw(e=>{try{let n=l.decode(e);if(n.length===0)return;let r=0;return x({while:()=>r<n.length,body:()=>{let e=n[r++];if(e._tag===`Pong`)return u.onPong(),f;if(`requestId`in e){let n=s.get(e.requestId);if(n!==void 0)return e._tag===`Exit`&&s.delete(e.requestId),t(n,e)}return m(e)},step:w})}catch(e){return m({_tag:`ClientProtocolError`,error:new fr({reason:new dr({message:`Error decoding message`,cause:e})})})}},{onOpen:p}).pipe(n(Ce(u.timeout,()=>ve(new Yn({reason:new Kn({kind:`Timeout`,cause:Error(`ping timeout`)})}))))))).pipe(Ce(()=>ve(new Yn({reason:new qn({code:1e3})}))),F(o)?Ne(o.value.onDisconnect):b,ut(t=>{let n=te(t),r=me(n);return e?.retryTransientErrors&&r&&n.success.reason._tag===`SocketOpenError`?f:(d=new fr({reason:r?n.success.reason:new dr({message:`Unknown socket error`,cause:ge(t)})}),m({_tag:`ClientProtocolError`,error:d}))}),ot(e?.retryPolicy??Yi),$e({module:`RpcClient`,method:`makeProtocolSocket`}),ze),{send(e,t){if(d)return ve(d);t._tag===`Request`&&s.set(t.id,e);let n=l.encode(t);return n===void 0?f:_(c(n))},supportsAck:!0,supportsTransferables:!1}})),Yi=le(500,1.5).pipe(h(ne(5e3))),Xi=a(function*(e){let t=!0,n=0,r=kt();return yield*ft(()=>t?(t=!1,n=0,e):(n+=1,n>=3?r.open:e)).pipe(Je(`5 seconds`),Re,c,C,ze),{timeout:r.await,reset:()=>{t=!0,n=0,r.closeUnsafe()},onPong:()=>{t=!0,n=0}}}),Zi=class extends We()(`effect/rpc/RpcClient/ConnectionHooks`){},Qi=tn(rn),$i=1e3,ea=64e3;Ui(Ht);function ta(e){return!Number.isInteger(e)||e<0||e>=10?null:Math.min(Math.round($i*2**e),ea)}var Y=class extends Error{code;retryable;name=`RelayProtocolFailure`;constructor(e,t,n){super(t),this.code=e,this.retryable=n}};function na(e){return Array.isArray(e)?e.map(na):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,na(t)])):e}function ra(e){let t=JSON.stringify(na(e));if(t===void 0)throw Error(`Relay payload is not JSON serializable.`);return t}var ia={requestId:`@effect/rpc/Ping`,correlationId:`@effect/rpc/Ping`,method:`@effect/rpc/Ping`,requiredScope:null,deliveryClass:`read`,journalPersistence:`none`};function aa(e){return e._tag===`Ping`?ia:null}function oa(e){if(e.policy===null||e.policy.method!==e.method)throw new Y(`method_not_remotable`,`Relay method has no exact dispatch policy: ${e.method}`,!1);if(e.policy.requiredScope!==null&&!e.grantedScopes.includes(e.policy.requiredScope))throw new Y(`scope_denied`,`Relay method ${e.method} requires scope ${e.policy.requiredScope}`,!1);return{requiredScope:e.policy.requiredScope,deliveryClass:e.policy.deliveryClass,journalPersistence:e.policy.journalPersistence}}function sa(e){let t=new Set(e.registeredMethods),n=new Map;for(let r of e.policies){if(n.has(r.method))throw new Y(`method_not_remotable`,`Relay method has duplicate dispatch policies: ${r.method}`,!1);if(!t.has(r.method))throw new Y(`method_not_remotable`,`Relay dispatch policy targets an unregistered method: ${r.method}`,!1);if((r.deliveryClass===`idempotent-command`||r.deliveryClass===`create-command`)==(r.journalPersistence===`none`))throw new Y(`method_not_remotable`,`Relay dispatch policy has incompatible journal persistence: ${r.method}`,!1);n.set(r.method,r)}for(let t of e.registeredMethods)if(!n.has(t))throw new Y(`method_not_remotable`,`Remotely registered method has no dispatch policy: ${t}`,!1);return n}var ca=[{method:I.projectsSearchContents,requiredScope:`workspace.read`,deliveryClass:`read`},{method:I.projectsSearchEntries,requiredScope:`workspace.read`,deliveryClass:`read`},{method:I.projectsListEntries,requiredScope:`workspace.read`,deliveryClass:`read`},{method:I.serverDiscoverSourceControl,requiredScope:`runtime.read`,deliveryClass:`read`},{method:I.serverReportClientActivity,requiredScope:`runtime.read`,deliveryClass:`read`},{method:I.projectsWriteFile,requiredScope:`workspace.write`,deliveryClass:`idempotent-command`},{method:I.projectCheckoutDeletionPreview,requiredScope:`workspace.write`,deliveryClass:`read`},{method:I.projectCheckoutDeletionExecute,requiredScope:`workspace.write`,deliveryClass:`idempotent-command`},{method:I.reviewGetDiffPreview,requiredScope:`diff.read`,deliveryClass:`read`},{method:I.projectsReadFile,requiredScope:`workspace.read`,deliveryClass:`read`},{method:I.cloudListRuntimes,requiredScope:`runtime.read`,deliveryClass:`read`},{method:I.filesystemBrowse,requiredScope:`workspace.read`,deliveryClass:`read`},{method:I.workspaceListDirectory,requiredScope:`workspace.read`,deliveryClass:`read`},{method:I.workspaceReadFile,requiredScope:`workspace.read`,deliveryClass:`bulk-transfer`},{method:I.workspaceBeginWriteFile,requiredScope:`workspace.write`,deliveryClass:`idempotent-command`},{method:I.workspaceWriteFileChunk,requiredScope:`workspace.write`,deliveryClass:`bulk-transfer`},{method:I.workspaceCommitWriteFile,requiredScope:`workspace.write`,deliveryClass:`idempotent-command`},{method:I.workspaceCancelWriteFile,requiredScope:`workspace.write`,deliveryClass:`idempotent-command`},{method:I.shellOpenInEditor,requiredScope:`shell.open`,deliveryClass:`idempotent-command`},{method:I.gitPull,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.gitRefreshStatus,requiredScope:`git.read`,deliveryClass:`read`},{method:I.gitRunStackedAction,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.gitListBranches,requiredScope:`git.read`,deliveryClass:`read`},{method:I.vcsListRefs,requiredScope:`git.read`,deliveryClass:`read`},{method:I.vcsRefreshStatus,requiredScope:`git.read`,deliveryClass:`read`},{method:I.vcsPull,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.vcsCreateWorktree,requiredScope:`git.write`,deliveryClass:`create-command`},{method:I.vcsRemoveWorktree,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.vcsCreateRef,requiredScope:`git.write`,deliveryClass:`create-command`},{method:I.vcsSwitchRef,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.vcsInit,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.gitCreateWorktree,requiredScope:`git.write`,deliveryClass:`create-command`},{method:I.gitRemoveWorktree,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.gitCreateBranch,requiredScope:`git.write`,deliveryClass:`create-command`},{method:I.gitCheckout,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.gitInit,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.gitResolvePullRequest,requiredScope:`git.read`,deliveryClass:`read`},{method:I.gitPreparePullRequestThread,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.terminalOpen,requiredScope:`terminal.write`,deliveryClass:`create-command`},{method:I.terminalAttach,requiredScope:`terminal.write`,deliveryClass:`terminal-output`},{method:I.terminalWrite,requiredScope:`terminal.write`,deliveryClass:`idempotent-command`},{method:I.terminalResize,requiredScope:`terminal.write`,deliveryClass:`idempotent-command`},{method:I.terminalSignal,requiredScope:`terminal.write`,deliveryClass:`idempotent-command`},{method:I.terminalClear,requiredScope:`terminal.write`,deliveryClass:`idempotent-command`},{method:I.terminalRestart,requiredScope:`terminal.write`,deliveryClass:`idempotent-command`},{method:I.terminalClose,requiredScope:`terminal.write`,deliveryClass:`idempotent-command`},{method:I.browserOpenSession,requiredScope:`browser.control`,deliveryClass:`create-command`},{method:I.browserListSessions,requiredScope:`browser.read`,deliveryClass:`read`},{method:I.browserCloseSession,requiredScope:`browser.control`,deliveryClass:`browser-control`},{method:I.browserGetSession,requiredScope:`browser.read`,deliveryClass:`read`},{method:I.browserCommand,requiredScope:`browser.control`,deliveryClass:`browser-control`},{method:I.browserClearBrowsingData,requiredScope:`browser.control`,deliveryClass:`browser-control`},{method:I.browserAttachDisplay,requiredScope:`browser.read`,deliveryClass:`subscription`},{method:I.computerInput,requiredScope:`browser.control`,deliveryClass:`browser-control`},{method:I.browserAddDisplayIceCandidate,requiredScope:`browser.read`,deliveryClass:`browser-control`},{method:I.devTunnelRegister,requiredScope:`browser.control`,deliveryClass:`idempotent-command`},{method:I.devTunnelUnregister,requiredScope:`browser.control`,deliveryClass:`idempotent-command`},{method:I.devTunnelList,requiredScope:`browser.read`,deliveryClass:`read`},{method:I.threadDevRuntimeGet,requiredScope:`runtime.read`,deliveryClass:`read`},{method:I.threadDevRuntimeAllocatePort,requiredScope:`runtime.manage`,deliveryClass:`idempotent-command`},{method:I.threadDevRuntimeRelease,requiredScope:`runtime.manage`,deliveryClass:`idempotent-command`},{method:I.workspaceEnvironmentPreflight,requiredScope:`workspace.read`,deliveryClass:`read`},{method:I.workspaceEnsureScratch,requiredScope:`workspace.write`,deliveryClass:`idempotent-command`},{method:I.serverGetConfig,requiredScope:`runtime.read`,deliveryClass:`read`},{method:I.serverRefreshProviders,requiredScope:`provider.read`,deliveryClass:`read`},{method:I.serverStartProviderAuth,requiredScope:`provider.manage`,deliveryClass:`create-command`},{method:I.serverRepairProviderAuthRuntime,requiredScope:`provider.manage`,deliveryClass:`idempotent-command`},{method:I.serverDisconnectProviderAuth,requiredScope:`provider.manage`,deliveryClass:`idempotent-command`},{method:I.serverGetProviderAuthSession,requiredScope:`provider.read`,deliveryClass:`read`},{method:I.serverCancelProviderAuth,requiredScope:`provider.manage`,deliveryClass:`idempotent-command`},{method:I.serverSubmitProviderAuthCode,requiredScope:`provider.manage`,deliveryClass:`idempotent-command`},{method:I.serverSyncPersonalCodexToCloud,requiredScope:`provider.manage`,deliveryClass:`idempotent-command`},{method:I.serverSyncPersonalClaudeToCloud,requiredScope:`provider.manage`,deliveryClass:`idempotent-command`},{method:I.serverUpsertKeybinding,requiredScope:`settings.write`,deliveryClass:`idempotent-command`},{method:I.serverRemoveKeybinding,requiredScope:`settings.write`,deliveryClass:`idempotent-command`},{method:I.serverGetSettings,requiredScope:`settings.read`,deliveryClass:`read`},{method:I.serverUpdateSettings,requiredScope:`settings.write`,deliveryClass:`idempotent-command`},{method:I.serverUpdateEnvironmentDisplayName,requiredScope:`settings.write`,deliveryClass:`idempotent-command`},{method:I.serverGetTraceDiagnostics,requiredScope:`settings.read`,deliveryClass:`read`},{method:I.serverHeartbeat,requiredScope:`runtime.read`,deliveryClass:`read`},{method:I.usageGetSummary,requiredScope:`runtime.read`,deliveryClass:`read`},{method:I.pullRequestsList,requiredScope:`git.read`,deliveryClass:`read`},{method:I.pullRequestsListStats,requiredScope:`git.read`,deliveryClass:`read`},{method:I.pullRequestsDetail,requiredScope:`git.read`,deliveryClass:`read`},{method:I.pullRequestsActivity,requiredScope:`git.read`,deliveryClass:`read`},{method:I.pullRequestsThreadComments,requiredScope:`git.read`,deliveryClass:`read`},{method:I.pullRequestsDiffFileContents,requiredScope:`git.read`,deliveryClass:`read`},{method:I.pullRequestsRunAction,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.pullRequestsUpdate,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.pullRequestsComment,requiredScope:`git.write`,deliveryClass:`create-command`},{method:I.pullRequestsUpdateComment,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.pullRequestsSubmitReview,requiredScope:`git.write`,deliveryClass:`create-command`},{method:I.pullRequestsReplyToThread,requiredScope:`git.write`,deliveryClass:`create-command`},{method:I.pullRequestsSetThreadResolution,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.pullRequestsSetReaction,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.pullRequestsInvalidate,requiredScope:`git.read`,deliveryClass:`read`},{method:I.pullRequestsReviewerCandidates,requiredScope:`git.read`,deliveryClass:`read`},{method:I.pullRequestsRequestReviewers,requiredScope:`git.write`,deliveryClass:`idempotent-command`},{method:I.subscribeGitStatus,requiredScope:`git.read`,deliveryClass:`subscription`},{method:I.subscribeVcsStatus,requiredScope:`git.read`,deliveryClass:`subscription`},{method:I.subscribeTerminalEvents,requiredScope:`terminal.read`,deliveryClass:`terminal-output`},{method:I.subscribeTerminalMetadata,requiredScope:`terminal.read`,deliveryClass:`read`},{method:I.subscribeBrowserEvents,requiredScope:`browser.read`,deliveryClass:`browser-frame`},{method:I.subscribeServerConfig,requiredScope:`runtime.read`,deliveryClass:`subscription`},{method:I.subscribeServerLifecycle,requiredScope:`runtime.read`,deliveryClass:`subscription`},{method:I.subscribeAuthAccess,requiredScope:`provider.read`,deliveryClass:`subscription`},{method:I.subscribeWorkspaceReadiness,requiredScope:`runtime.read`,deliveryClass:`subscription`},{method:Xt.dispatchCommand,requiredScope:null,deliveryClass:`idempotent-command`},{method:Xt.getTurnDiff,requiredScope:`diff.read`,deliveryClass:`read`},{method:Xt.getFullThreadDiff,requiredScope:`diff.read`,deliveryClass:`read`},{method:Xt.streamTurnDiff,requiredScope:`diff.read`,deliveryClass:`bulk-transfer`},{method:Xt.streamFullThreadDiff,requiredScope:`diff.read`,deliveryClass:`bulk-transfer`},{method:Xt.replayEvents,requiredScope:`thread.read`,deliveryClass:`subscription`},{method:Xt.getArchivedShellSnapshot,requiredScope:`thread.read`,deliveryClass:`read`},{method:Xt.subscribeShell,requiredScope:`thread.read`,deliveryClass:`subscription`},{method:Xt.subscribeThread,requiredScope:`thread.read`,deliveryClass:`subscription`},{method:Xt.getThreadDetailPage,requiredScope:`thread.read`,deliveryClass:`read`},{method:I.assetsCreateUrl,requiredScope:`thread.read`,deliveryClass:`read`},{method:I.attachmentsCreateUploadUrl,requiredScope:`turn.dispatch`,deliveryClass:`create-command`},{method:I.attachmentsDelete,requiredScope:`turn.dispatch`,deliveryClass:`idempotent-command`},{method:Xt.searchThreads,requiredScope:`thread.read`,deliveryClass:`read`},{method:I.providerUploadFeedback,requiredScope:`thread.read`,deliveryClass:`create-command`},{method:I.sourceControlLookupRepository,requiredScope:`git.read`,deliveryClass:`read`},{method:I.sourceControlCloneRepository,requiredScope:`project.write`,deliveryClass:`idempotent-command`}],la=new Set([I.gitPull,I.gitRunStackedAction,I.gitCreateWorktree,I.gitRemoveWorktree,I.gitCreateBranch,I.gitCheckout,I.gitInit,I.gitPreparePullRequestThread,I.threadDevRuntimeAllocatePort,I.threadDevRuntimeRelease,I.serverUpsertKeybinding,I.serverRemoveKeybinding,I.serverUpdateEnvironmentDisplayName,Xt.dispatchCommand]),ua=ca.map(e=>{let t=e.deliveryClass===`idempotent-command`||e.deliveryClass===`create-command`;return{method:e.method,requiredScope:e.requiredScope,deliveryClass:e.deliveryClass,journalPersistence:t?la.has(e.method)?`frame`:`metadata-only`:`none`}}),da=sa({registeredMethods:[...Ht.requests.keys()],policies:ua}),fa={"project.create":{requiredScope:`project.write`,deliveryClass:`create-command`},"project.meta.update":{requiredScope:`project.write`,deliveryClass:`idempotent-command`},"project.script.update":{requiredScope:`project.write`,deliveryClass:`idempotent-command`},"project.delete":{requiredScope:`project.write`,deliveryClass:`idempotent-command`},"thread.create":{requiredScope:`thread.create`,deliveryClass:`create-command`},"thread.delete":{requiredScope:`thread.mutate`,deliveryClass:`idempotent-command`},"thread.archive":{requiredScope:`thread.mutate`,deliveryClass:`idempotent-command`},"thread.settle":{requiredScope:`thread.mutate`,deliveryClass:`idempotent-command`},"thread.unsettle":{requiredScope:`thread.mutate`,deliveryClass:`idempotent-command`},"thread.unarchive":{requiredScope:`thread.mutate`,deliveryClass:`idempotent-command`},"thread.meta.update":{requiredScope:`thread.mutate`,deliveryClass:`idempotent-command`},"thread.runtime-mode.set":{requiredScope:`thread.mutate`,deliveryClass:`idempotent-command`},"thread.interaction-mode.set":{requiredScope:`thread.mutate`,deliveryClass:`idempotent-command`},"thread.turn.start":{requiredScope:`turn.dispatch`,deliveryClass:`create-command`},"thread.turn.interrupt":{requiredScope:`turn.stop`,deliveryClass:`idempotent-command`},"thread.approval.respond":{requiredScope:`approval.respond`,deliveryClass:`idempotent-command`},"thread.user-input.respond":{requiredScope:`approval.respond`,deliveryClass:`idempotent-command`},"thread.checkpoint.revert":{requiredScope:`thread.mutate`,deliveryClass:`idempotent-command`},"thread.session.stop":{requiredScope:`turn.stop`,deliveryClass:`idempotent-command`},"thread.plan-approval.respond":{requiredScope:`approval.respond`,deliveryClass:`idempotent-command`}},pa=new Set([`thread.approval.respond`,`thread.user-input.respond`,`thread.plan-approval.respond`]);function ma(e){if(e.method!==Xt.dispatchCommand||!e.payload||typeof e.payload!=`object`||Array.isArray(e.payload))return null;let t=e.payload;if(typeof t.type!=`string`||!pa.has(t.type))return null;let n=t.type===`thread.plan-approval.respond`?t.promptId:t.requestId;if(typeof t.commandId!=`string`||t.commandId.length===0||typeof n!=`string`||n.length===0)throw new Y(`action_grant_invalid`,`Relay sensitive action metadata is incomplete`,!1);return{commandType:t.type,commandId:t.commandId,targetId:n}}function ha(e){let t=da.get(e.method)??null,n=oa({method:e.method,grantedScopes:e.grantedScopes,policy:t});if(e.method!==Xt.dispatchCommand)return n;if(!e.payload||typeof e.payload!=`object`||!(`type`in e.payload))throw new Y(`method_not_remotable`,`Relay orchestration dispatch payload has no command policy`,!1);let r=e.payload.type;if(typeof r!=`string`||!(r in fa))throw new Y(`method_not_remotable`,`Relay orchestration command has no dispatch policy: ${String(r)}`,!1);let i=fa[r];if(!e.grantedScopes.includes(i.requiredScope))throw new Y(`scope_denied`,`Relay orchestration command ${r} requires scope ${i.requiredScope}`,!1);return{requiredScope:i.requiredScope,deliveryClass:i.deliveryClass,journalPersistence:n.journalPersistence}}var ga=class extends Error{constructor(e){let t;t=e instanceof Error?e.message:typeof e==`string`?e:``,super(t),this.name=this.constructor.name}},_a=class extends ga{},va=class extends ga{},ya=class extends ga{},ba=class extends ga{},xa=class extends ga{},Sa=class extends ga{},Ca=class extends ga{},wa=class extends ga{},Ta=class extends ga{},Ea=class extends ga{},Da=class extends ga{},Oa=ka(globalThis,{});function ka(e,t){return new Proxy(e,{get(n,r,i){return r in t?t[r]:e[r]},set(n,r,i){return r in t&&delete t[r],e[r]=i,!0},deleteProperty(n,r){let i=!1;return r in t&&(delete t[r],i=!0),r in e&&(delete e[r],i=!0),i},ownKeys(n){let r=Reflect.ownKeys(e),i=Reflect.ownKeys(t),a=new Set(i);return[...r.filter(e=>!a.has(e)),...i]},defineProperty(n,r,i){return r in t&&delete t[r],Reflect.defineProperty(e,r,i),!0},getOwnPropertyDescriptor(n,r){return r in t?Reflect.getOwnPropertyDescriptor(t,r):Reflect.getOwnPropertyDescriptor(e,r)},has(n,r){return r in t||r in e}})}async function Aa(){if(Oa!==void 0&&globalThis.crypto!==void 0)return globalThis.crypto.subtle;try{let{webcrypto:e}=await hn(async()=>{let{webcrypto:e}=await import(`./__vite-browser-external-2W3EstLn.js`).then(e=>t(e.default));return{webcrypto:e}},__vite__mapDeps([0,1]));return e.subtle}catch(e){throw new Da(e)}}var ja=class{constructor(){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}async _setup(){this._api===void 0&&(this._api=await Aa())}},Ma={Base:0,Psk:1,Auth:2,AuthPsk:3},Na={NotAssigned:0,DhkemP256HkdfSha256:16,DhkemP384HkdfSha384:17,DhkemP521HkdfSha512:18,DhkemSecp256k1HkdfSha256:19,DhkemX25519HkdfSha256:32,DhkemX448HkdfSha512:33,HybridkemX25519Kyber768:48,MlKem512:64,MlKem768:65,MlKem1024:66,XWing:25722},Pa={HkdfSha256:1,HkdfSha384:2,HkdfSha512:3,Sha3256:4,Sha3384:5,Sha3512:6,Shake128:16,Shake256:17,TurboShake128:18,TurboShake256:19},Fa={Aes128Gcm:1,Aes256Gcm:2,Chacha20Poly1305:3,ExportOnly:65535},Ia=new Uint8Array,La=0n,Ra=1n,za=2n,Ba=new Uint8Array([75,69,77,0,0]),Va=new Uint8Array([72,80,75,69,45,118,49]);function Ha(e){return new Uint8Array(X(e))}function X(e){return e instanceof ArrayBuffer?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice().buffer:new Uint8Array(e).slice().buffer}var Ua=class extends ja{constructor(){super(),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Pa.HkdfSha256}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_suiteId",{enumerable:!0,configurable:!0,writable:!0,value:Ia}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:`HMAC`,hash:`SHA-256`,length:256}})}init(e){this._suiteId=e}buildLabeledIkm(e,t){this._checkInit();let n=new Uint8Array(7+this._suiteId.byteLength+e.byteLength+t.byteLength);return n.set(Va,0),n.set(this._suiteId,7),n.set(e,7+this._suiteId.byteLength),n.set(t,7+this._suiteId.byteLength+e.byteLength),n}buildLabeledInfo(e,t,n){this._checkInit();let r=new Uint8Array(9+this._suiteId.byteLength+e.byteLength+t.byteLength);return r.set(new Uint8Array([0,n]),0),r.set(Va,2),r.set(this._suiteId,9),r.set(e,9+this._suiteId.byteLength),r.set(t,9+this._suiteId.byteLength+e.byteLength),r}async extract(e,t){await this._setup();let n=e.byteLength===0?new ArrayBuffer(this.hashSize):X(e);if(n.byteLength!==this.hashSize)throw new _a(`The salt length must be the same as the hashSize`);let r=X(t),i=await this._api.importKey(`raw`,n,this.algHash,!1,[`sign`]);return await this._api.sign(`HMAC`,i,r)}async expand(e,t,n){await this._setup();let r=X(e),i=await this._api.importKey(`raw`,r,this.algHash,!1,[`sign`]),a=new ArrayBuffer(n),o=new Uint8Array(a),s=Ia,c=Ha(t),l=new Uint8Array(1);if(n>255*this.hashSize)throw Error(`Entropy limit reached`);let u=new Uint8Array(this.hashSize+c.length+1);for(let e=1,t=0;t<o.length;e++)l[0]=e,u.set(s,0),u.set(c,s.length),u.set(l,s.length+c.length),s=new Uint8Array(await this._api.sign(`HMAC`,i,u.slice(0,s.length+c.length+1))),o.length-t>=s.length?(o.set(s,t),t+=s.length):(o.set(s.slice(0,o.length-t),t),t+=o.length-t);return a}async extractAndExpand(e,t,n,r){await this._setup();let i=X(t),a=await this._api.importKey(`raw`,i,`HKDF`,!1,[`deriveBits`]);return await this._api.deriveBits({name:`HKDF`,hash:this.algHash.hash,salt:X(e),info:X(n)},a,r*8)}async labeledExtract(e,t,n){return await this.extract(e,this.buildLabeledIkm(t,n))}async labeledExpand(e,t,n,r){return await this.expand(e,this.buildLabeledInfo(t,n,r),r)}_checkInit(){if(this._suiteId===Ia)throw Error(`Not initialized. Call init()`)}},Wa=class extends Ua{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Pa.HkdfSha256}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:`HMAC`,hash:`SHA-256`,length:256}})}},Ga=e=>typeof e==`object`&&!!e&&typeof e.privateKey==`object`&&typeof e.publicKey==`object`;function Ka(e,t){if(t<=0)throw Error(`i2Osp: too small size`);if(e>=256**t)throw Error(`i2Osp: too large integer`);let n=new Uint8Array(t);for(let r=0;r<t&&e;r++)n[t-(r+1)]=e%256,e=Math.floor(e/256);return n}function qa(e,t){let n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}function Ja(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=atob(t),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}async function Ya(){if(Oa!==void 0&&globalThis.crypto!==void 0)return globalThis.crypto;try{let{webcrypto:e}=await hn(async()=>{let{webcrypto:e}=await import(`./__vite-browser-external-2W3EstLn.js`).then(e=>t(e.default));return{webcrypto:e}},__vite__mapDeps([0,1]));return e}catch{throw Error(`failed to load Crypto`)}}function Xa(e,t){if(e.byteLength!==t.byteLength)throw Error(`xor: different length inputs`);let n=new Uint8Array(e.byteLength);for(let r=0;r<e.byteLength;r++)n[r]=e[r]^t[r];return n}var Za=new Uint8Array([101,97,101,95,112,114,107]),Qa=new Uint8Array([115,104,97,114,101,100,95,115,101,99,114,101,116]);function $a(e,t,n){let r=new Uint8Array(e.length+t.length+n.length);return r.set(e,0),r.set(t,e.length),r.set(n,e.length+t.length),r}var eo=class{constructor(e,t,n){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_prim",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.id=e,this._prim=t,this._kdf=n;let r=new Uint8Array(Ba);r.set(Ka(this.id,2),3),this._kdf.init(r)}async serializePublicKey(e){return await this._prim.serializePublicKey(e)}async deserializePublicKey(e){return await this._prim.deserializePublicKey(X(e))}async serializePrivateKey(e){return await this._prim.serializePrivateKey(e)}async deserializePrivateKey(e){return await this._prim.deserializePrivateKey(X(e))}async importKey(e,t,n=!0){return await this._prim.importKey(e,t,n)}async generateKeyPair(){return await this._prim.generateKeyPair()}async deriveKeyPair(e){let t=X(e);if(t.byteLength>8192)throw new _a(`Too long ikm`);return await this._prim.deriveKeyPair(t)}async encap(e){let t;t=e.ekm===void 0?await this.generateKeyPair():Ga(e.ekm)?e.ekm:await this.deriveKeyPair(e.ekm);let n=await this._prim.serializePublicKey(t.publicKey),r=await this._prim.serializePublicKey(e.recipientPublicKey);try{let i;if(e.senderKey===void 0)i=new Uint8Array(await this._prim.dh(t.privateKey,e.recipientPublicKey));else{let n=Ga(e.senderKey)?e.senderKey.privateKey:e.senderKey;i=qa(new Uint8Array(await this._prim.dh(t.privateKey,e.recipientPublicKey)),new Uint8Array(await this._prim.dh(n,e.recipientPublicKey)))}let a;if(e.senderKey===void 0)a=qa(new Uint8Array(n),new Uint8Array(r));else{let t=Ga(e.senderKey)?e.senderKey.publicKey:await this._prim.derivePublicKey(e.senderKey),i=await this._prim.serializePublicKey(t);a=$a(new Uint8Array(n),new Uint8Array(r),new Uint8Array(i))}return{enc:n,sharedSecret:await this._generateSharedSecret(i,a)}}catch(e){throw new ba(e)}}async decap(e){let t=X(e.enc),n=await this._prim.deserializePublicKey(t),r=Ga(e.recipientKey)?e.recipientKey.privateKey:e.recipientKey,i=Ga(e.recipientKey)?e.recipientKey.publicKey:await this._prim.derivePublicKey(e.recipientKey),a=await this._prim.serializePublicKey(i);try{let i;i=e.senderPublicKey===void 0?new Uint8Array(await this._prim.dh(r,n)):qa(new Uint8Array(await this._prim.dh(r,n)),new Uint8Array(await this._prim.dh(r,e.senderPublicKey)));let o;if(e.senderPublicKey===void 0)o=qa(new Uint8Array(t),new Uint8Array(a));else{let n=await this._prim.serializePublicKey(e.senderPublicKey);o=new Uint8Array(t.byteLength+a.byteLength+n.byteLength),o.set(new Uint8Array(t),0),o.set(new Uint8Array(a),t.byteLength),o.set(new Uint8Array(n),t.byteLength+a.byteLength)}return await this._generateSharedSecret(i,o)}catch(e){throw new xa(e)}}async _generateSharedSecret(e,t){let n=this._kdf.buildLabeledIkm(Za,e),r=this._kdf.buildLabeledInfo(Qa,t,this.secretSize);return await this._kdf.extractAndExpand(Ia,n,r,this.secretSize)}},to=[`deriveBits`],no=new Uint8Array([100,107,112,95,112,114,107]),ro=new Uint8Array([115,107]),io=class{constructor(e,t,n,r=[]){Object.defineProperty(this,"key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extractable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"algorithm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"usages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.key=t,this.type=n,this.algorithm={name:e},this.usages=r,n===`public`&&(this.usages=[])}},ao=class{constructor(e,t,n,r){Object.defineProperty(this,"_algName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_curve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._algName=e,this._nPk=t,this._nSk=t,this._curve=n,this._hkdf=r}serializePublicKey(e){try{return Promise.resolve(e.key.buffer)}catch(e){return Promise.reject(new va(e))}}async deserializePublicKey(e){try{return await this._importRawKey(X(e),!0)}catch(e){throw new ya(e)}}serializePrivateKey(e){try{return Promise.resolve(e.key.buffer)}catch(e){return Promise.reject(new va(e))}}async deserializePrivateKey(e){try{return await this._importRawKey(X(e),!1)}catch(e){throw new ya(e)}}async importKey(e,t,n){try{if(e===`raw`)return await this._importRawKey(t,n);if(t instanceof ArrayBuffer)throw Error(`Invalid jwk key format`);return await this._importJWK(t,n)}catch(e){throw new ya(e)}}async generateKeyPair(){try{let e=await this._curve.utils.randomSecretKey(),t=new io(this._algName,e,`private`,to);return{publicKey:await this.derivePublicKey(t),privateKey:t}}catch(e){throw new Da(e)}}async deriveKeyPair(e){try{let t=X(e),n=await this._hkdf.labeledExtract(Ia.buffer,no,new Uint8Array(t)),r=await this._hkdf.labeledExpand(n,ro,Ia,this._nSk),i=new io(this._algName,new Uint8Array(r),`private`,to);return{privateKey:i,publicKey:await this.derivePublicKey(i)}}catch(e){throw new Ea(e)}}derivePublicKey(e){try{let t=this._curve.getPublicKey(e.key);return Promise.resolve(new io(this._algName,t,`public`))}catch(e){return Promise.reject(new ya(e))}}dh(e,t){try{return Promise.resolve(this._curve.getSharedSecret(e.key,t.key).buffer)}catch(e){return Promise.reject(new va(e))}}_importRawKey(e,t){return new Promise((n,r)=>{t&&e.byteLength!==this._nPk&&r(Error(`Invalid length of the key`)),!t&&e.byteLength!==this._nSk&&r(Error(`Invalid length of the key`)),n(new io(this._algName,new Uint8Array(e),t?`public`:`private`,t?[]:to))})}_importJWK(e,t){return new Promise((n,r)=>{e.kty!==`OKP`&&r(Error(`Invalid kty: ${e.kty}`)),e.crv!==this._algName&&r(Error(`Invalid crv: ${e.crv}`)),t?(e.d!==void 0&&r(Error("Invalid key: `d` should not be set")),typeof e.x!=`string`&&r(Error("Invalid key: `x` not found")),n(new io(this._algName,Ja(e.x),`public`))):(typeof e.d!=`string`&&r(Error("Invalid key: `d` not found")),n(new io(this._algName,Ja(e.d),`private`,to)))})}};function oo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function so(e,t=``){if(!Number.isSafeInteger(e)||e<0){let n=t&&`"${t}" `;throw Error(`${n}expected integer >0, got ${e}`)}}function Z(e,t,n=``){let r=oo(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`;throw Error(o+`expected Uint8Array`+s+`, got `+c)}return e}function co(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function lo(e,t){Z(e,void 0,`digestInto() output`);let n=t.outputLen;if(e.length<n)throw Error(`"digestInto() output" expected to be of length >=`+n)}function uo(e){if(typeof e==`bigint`){if(!Ao(e))throw Error(`positive bigint expected, got `+e)}else so(e);return e}function fo(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function po(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}var mo=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ho(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function go(e,t){return e<<32-t|e>>>t}var _o=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,vo=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`)),yo=[0n,1n,2n,3n,4n,5n,6n,7n,8n,9n,10n,11n,12n,13n,14n,15n];function bo(e){if(Z(e),_o)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=vo[e[n]];return t}var xo={_0:48,_9:57,A:65,F:70,a:97,f:102};function So(e){if(e>=xo._0&&e<=xo._9)return e-xo._0;if(e>=xo.A&&e<=xo.F)return e-(xo.A-10);if(e>=xo.a&&e<=xo.f)return e-(xo.a-10)}function Co(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);if(_o)return Uint8Array.fromHex(e);let t=e.length,n=t/2;if(t%2)throw Error(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=So(e.charCodeAt(i)),a=So(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw Error(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function wo(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);let t=La;for(let n=0;n<e.length;n++){let r=So(e.charCodeAt(n));if(r===void 0)throw Error(`hex string expected, got non-hex character "`+e[n]+`" at index `+n);t=t<<4n|yo[r]}return t}function To(e){so(e,`numberToBigint`);let t=e,n=La,r=1n;for(;t>0;)t%2==1&&(n+=r),t=Math.floor(t/2),r<<=1n;return n}function Eo(e){return wo(bo(ko(Z(e)).reverse()))}function Do(e,t){so(t),e=uo(e);let n=Co(e.toString(16).padStart(t*2,`0`));if(n.length!==t)throw Error(`number too large`);return n}function Oo(e,t){return Do(e,t).reverse()}function ko(e){return Uint8Array.from(e)}function Ao(e){return typeof e==`bigint`&&0n<=e}function jo(e,t,n){return Ao(e)&&Ao(t)&&Ao(n)&&t<=e&&e<n}function Mo(e,t,n,r){if(!jo(t,n,r))throw Error(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function No(e,t={},n={}){if(!e||typeof e!=`object`)throw Error(`expected valid options object`);function r(t,n,r){let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw Error(`param "${t}" is invalid: expected ${n}, got ${a}`)}let i=(e,t)=>Object.entries(e).forEach(([e,n])=>r(e,n,t));i(t,!1),i(n,!0)}async function Po(e=32){let t=await Ya(),n=new Uint8Array(e);return t.getRandomValues(n),n}function Fo(e){return{oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])}}function Io(e){if(typeof e!=`function`||typeof e.create!=`function`)throw Error(`Hash must wrapped by utils.createHasher`);so(e.outputLen),so(e.blockLen)}function Lo(e,t={}){let n=(t,n)=>e(n).update(t).digest(),r=e(void 0),i=Object.assign(n,{outputLen:r.outputLen,blockLen:r.blockLen,create:t=>e(t),...t});return Object.freeze(i)}var Ro=class{constructor(e,t){if(Object.defineProperty(this,"oHash",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"iHash",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"blockLen",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"outputLen",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"finished",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Io(e),Z(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),po(r)}update(e){return co(this),this.iHash.update(e),this}digestInto(e){co(this),Z(e,this.outputLen,`output`),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},zo=(e,t,n)=>new Ro(e,t).update(n).digest();zo.create=(e,t)=>new Ro(e,t);function Bo(e,t,n){return e&t^~e&n}function Vo(e,t,n){return e&t^e&n^t&n}var Ho=class{constructor(e,t,n,r){Object.defineProperty(this,"blockLen",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"outputLen",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"padOffset",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isLE",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"buffer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"view",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"finished",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"length",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"pos",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=ho(this.buffer)}update(e){co(this),Z(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=ho(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){co(this),lo(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,po(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;n.setBigUint64(r-8,To(this.length*8),i),this.process(n,0);let o=ho(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen must be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Uo=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Wo=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Go=new Uint32Array(64),Ko=class extends Ho{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)Go[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=Go[e-15],n=Go[e-2],r=go(t,7)^go(t,18)^t>>>3,i=go(n,17)^go(n,19)^n>>>10;Go[e]=i+Go[e-7]+r+Go[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=go(o,6)^go(o,11)^go(o,25),u=l+t+Bo(o,s,c)+Wo[e]+Go[e]|0,d=(go(n,2)^go(n,13)^go(n,22))+Vo(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){po(Go)}destroy(){this.set(0,0,0,0,0,0,0,0),po(this.buffer)}},qo=class extends Ko{constructor(){super(32),Object.defineProperty(this,"A",{enumerable:!0,configurable:!0,writable:!0,value:Uo[0]|0}),Object.defineProperty(this,"B",{enumerable:!0,configurable:!0,writable:!0,value:Uo[1]|0}),Object.defineProperty(this,"C",{enumerable:!0,configurable:!0,writable:!0,value:Uo[2]|0}),Object.defineProperty(this,"D",{enumerable:!0,configurable:!0,writable:!0,value:Uo[3]|0}),Object.defineProperty(this,"E",{enumerable:!0,configurable:!0,writable:!0,value:Uo[4]|0}),Object.defineProperty(this,"F",{enumerable:!0,configurable:!0,writable:!0,value:Uo[5]|0}),Object.defineProperty(this,"G",{enumerable:!0,configurable:!0,writable:!0,value:Uo[6]|0}),Object.defineProperty(this,"H",{enumerable:!0,configurable:!0,writable:!0,value:Uo[7]|0})}},Jo=Lo(()=>new qo,Fo(1));function Yo(e,t){let n=e%t;return n>=0n?n:t+n}function Xo(e,t,n){let r=e;for(;t-->La;)r*=r,r%=n;return r}function Zo(e,t){return function(n){let r=e(n);return{secretKey:r,publicKey:t(r)}}}function Qo(e){return No(e,{adjustScalarBytes:`function`,powPminus2:`function`}),Object.freeze({...e})}function $o(e){let{P:t,type:n,adjustScalarBytes:r,powPminus2:i,randomBytes:a}=Qo(e),o=n===`x25519`;if(!o&&n!==`x448`)throw Error(`invalid type`);let s=a||Po,c=o?255n:448n,l=o?32:56,u=o?9n:5n,d=o?121665n:39081n,f=o?za**254n:za**447n,p=f+(o?8n*za**251n-Ra:4n*za**445n-Ra)+Ra,m=e=>Yo(e,t),h=g(u);function g(e){return Oo(m(e),l)}function ee(e){let t=ko(Z(e,l,`uCoordinate`));return o&&(t[31]&=127),m(Eo(t))}function te(e){return Eo(r(ko(Z(e,l,`scalar`))))}function _(e,t){let n=x(ee(t),te(e));if(n===0n)throw Error(`invalid private or public key received`);return g(n)}function ne(e){return _(e,h)}let v=ne,y=_;function b(e,t,n){let r=m(e*(t-n));return t=m(t-r),n=m(n+r),{x_2:t,x_3:n}}function x(e,n){Mo(`u`,e,La,t),Mo(`scalar`,n,f,p);let r=n,a=e,o=Ra,s=La,l=e,u=Ra,h=La;for(let e=c-1n;e>=La;e--){let t=r>>e&Ra;h^=t,{x_2:o,x_3:l}=b(h,o,l),{x_2:s,x_3:u}=b(h,s,u),h=t;let n=o+s,i=m(n*n),c=o-s,f=m(c*c),p=i-f,g=l+u,ee=l-u,te=m(ee*n),_=m(g*c),ne=te+_,v=te-_;l=m(ne*ne),u=m(a*m(v*v)),o=m(i*f),s=m(p*(i+m(d*p)))}({x_2:o,x_3:l}=b(h,o,l)),{x_2:s,x_3:u}=b(h,s,u);let g=i(s);return m(o*g)}let S={secretKey:l,publicKey:l,seed:l},C=async e=>(e===void 0&&(e=await s(l)),Z(e,S.seed,`seed`),e),w={randomSecretKey:C};return Object.freeze({keygen:Zo(C,v),getSharedSecret:y,getPublicKey:v,scalarMult:_,scalarMultBase:ne,utils:w,GuBytes:h.slice(),lengths:S})}function es(e){if(typeof e!=`boolean`)throw Error(`boolean expected, not ${e}`)}var ts=(e,t)=>{function n(n,...r){if(Z(n,void 0,`key`),!mo)throw Error(`Non little-endian hardware is not yet supported`);if(e.nonceLength!==void 0){let t=r[0];Z(t,e.varSizeNonce?void 0:e.nonceLength,`nonce`)}let i=e.tagLength;i&&r[1]!==void 0&&Z(r[1],void 0,`AAD`);let a=t(n,...r),o=(e,t)=>{if(t!==void 0){if(e!==2)throw Error(`cipher output not supported`);Z(t,void 0,`output`)}},s=!1;return{encrypt(e,t){if(s)throw Error(`cannot encrypt() twice with same key + nonce`);return s=!0,Z(e),o(a.encrypt.length,t),a.encrypt(e,t)},decrypt(e,t){if(Z(e),i&&e.length<i)throw Error(`"ciphertext" expected length bigger than tagLength=`+i);return o(a.decrypt.length,t),a.decrypt(e,t)}}}return Object.assign(n,e),n};function ns(e,t){if(typeof t!=`object`||!t)throw Error(`options must be defined`);return Object.assign(e,t)}function rs(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}function is(e,t,n=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw Error(`"output" expected Uint8Array of length `+e+`, got: `+t.length);if(n&&!os(t))throw Error(`invalid output, must be aligned`);return t}function as(e,t,n){es(n);let r=new Uint8Array(16),i=ho(r);return i.setBigUint64(0,To(t),n),i.setBigUint64(8,To(e),n),r}function os(e){return e.byteOffset%4==0}var ss=e=>Uint8Array.from(e.split(``).map(e=>e.charCodeAt(0))),cs=ss(`expand 16-byte k`),ls=ss(`expand 32-byte k`),us=fo(cs),ds=fo(ls);function Q(e,t){return e<<t|e>>>32-t}function fs(e){return e.byteOffset%4==0}var ps=64,ms=16,hs=2**32-1,gs=Uint32Array.of();function _s(e,t,n,r,i,a,o,s){let c=i.length,l=new Uint8Array(ps),u=fo(l),d=fs(i)&&fs(a),f=d?fo(i):gs,p=d?fo(a):gs;for(let m=0;m<c;o++){if(e(t,n,r,u,o,s),o>=hs)throw Error(`arx: counter overflow`);let h=Math.min(ps,c-m);if(d&&h===ps){let e=m/4;if(m%4!=0)throw Error(`arx: invalid block position`);for(let t=0,n;t<ms;t++)n=e+t,p[n]=f[n]^u[t];m+=ps;continue}for(let e=0,t;e<h;e++)t=m+e,a[t]=i[t]^l[e];m+=h}}function vs(e,t){let{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:a,rounds:o}=ns({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!=`function`)throw Error(`core must be a function`);return so(i),so(o),es(a),es(n),(t,s,c,l,u=0)=>{Z(t,void 0,`key`),Z(s,void 0,`nonce`),Z(c,void 0,`data`);let d=c.length;if(l===void 0&&(l=new Uint8Array(d)),Z(l,void 0,`output`),so(u),u<0||u>=hs)throw Error(`arx: counter overflow`);if(l.length<d)throw Error(`arx: output (${l.length}) is shorter than data (${d})`);let f=[],p=t.length,m,h;if(p===32)f.push(m=ko(t)),h=ds;else if(p===16&&n)m=new Uint8Array(32),m.set(t),m.set(t,16),h=us,f.push(m);else throw Z(t,32,`arx key`),Error(`invalid key size`);fs(s)||f.push(s=ko(s));let g=fo(m);if(r){if(s.length!==24)throw Error(`arx: extended nonce must be 24 bytes`);r(h,g,fo(s.subarray(0,16)),g),s=s.subarray(16)}let ee=16-i;if(ee!==s.length)throw Error(`arx: nonce must be ${ee} or 16 bytes`);if(ee!==12){let e=new Uint8Array(12);e.set(s,a?0:12-s.length),s=e,f.push(s)}let te=fo(s);return _s(e,h,g,te,c,l,u,o),po(...f),l}}function ys(e,t){return e[t++]&255|(e[t++]&255)<<8}var bs=class{constructor(e){Object.defineProperty(this,"blockLen",{enumerable:!0,configurable:!0,writable:!0,value:16}),Object.defineProperty(this,"outputLen",{enumerable:!0,configurable:!0,writable:!0,value:16}),Object.defineProperty(this,"buffer",{enumerable:!0,configurable:!0,writable:!0,value:new Uint8Array(16)}),Object.defineProperty(this,"r",{enumerable:!0,configurable:!0,writable:!0,value:new Uint16Array(10)}),Object.defineProperty(this,"h",{enumerable:!0,configurable:!0,writable:!0,value:new Uint16Array(10)}),Object.defineProperty(this,"pad",{enumerable:!0,configurable:!0,writable:!0,value:new Uint16Array(8)}),Object.defineProperty(this,"pos",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"finished",{enumerable:!0,configurable:!0,writable:!0,value:!1}),e=ko(Z(e,32,`key`));let t=ys(e,0),n=ys(e,2),r=ys(e,4),i=ys(e,6),a=ys(e,8),o=ys(e,10),s=ys(e,12),c=ys(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|r<<6)&7939,this.r[3]=(r>>>7|i<<9)&8191,this.r[4]=(i>>>4|a<<12)&255,this.r[5]=a>>>1&8190,this.r[6]=(a>>>14|o<<2)&8191,this.r[7]=(o>>>11|s<<5)&8065,this.r[8]=(s>>>8|c<<8)&8191,this.r[9]=c>>>5&127;for(let t=0;t<8;t++)this.pad[t]=ys(e,16+2*t)}process(e,t,n=!1){let r=n?0:2048,{h:i,r:a}=this,o=a[0],s=a[1],c=a[2],l=a[3],u=a[4],d=a[5],f=a[6],p=a[7],m=a[8],h=a[9],g=ys(e,t+0),ee=ys(e,t+2),te=ys(e,t+4),_=ys(e,t+6),ne=ys(e,t+8),v=ys(e,t+10),y=ys(e,t+12),b=ys(e,t+14),x=i[0]+(g&8191),S=i[1]+((g>>>13|ee<<3)&8191),C=i[2]+((ee>>>10|te<<6)&8191),w=i[3]+((te>>>7|_<<9)&8191),T=i[4]+((_>>>4|ne<<12)&8191),E=i[5]+(ne>>>1&8191),D=i[6]+((ne>>>14|v<<2)&8191),O=i[7]+((v>>>11|y<<5)&8191),k=i[8]+((y>>>8|b<<8)&8191),A=i[9]+(b>>>5|r),j=0,M=j+x*o+5*h*S+5*m*C+5*p*w+5*f*T;j=M>>>13,M&=8191,M+=5*d*E+5*u*D+5*l*O+5*c*k+5*s*A,j+=M>>>13,M&=8191;let N=j+x*s+S*o+5*h*C+5*m*w+5*p*T;j=N>>>13,N&=8191,N+=5*f*E+5*d*D+5*u*O+5*l*k+5*c*A,j+=N>>>13,N&=8191;let P=j+x*c+S*s+C*o+5*h*w+5*m*T;j=P>>>13,P&=8191,P+=5*p*E+5*f*D+5*d*O+5*u*k+5*l*A,j+=P>>>13,P&=8191;let F=j+x*l+S*c+C*s+w*o+5*h*T;j=F>>>13,F&=8191,F+=5*m*E+5*p*D+5*f*O+5*d*k+5*u*A,j+=F>>>13,F&=8191;let re=j+x*u+S*l+C*c+w*s+T*o;j=re>>>13,re&=8191,re+=5*h*E+5*m*D+5*p*O+5*f*k+5*d*A,j+=re>>>13,re&=8191;let ie=j+x*d+S*u+C*l+w*c+T*s;j=ie>>>13,ie&=8191,ie+=E*o+5*h*D+5*m*O+5*p*k+5*f*A,j+=ie>>>13,ie&=8191;let ae=j+x*f+S*d+C*u+w*l+T*c;j=ae>>>13,ae&=8191,ae+=E*s+D*o+5*h*O+5*m*k+5*p*A,j+=ae>>>13,ae&=8191;let oe=j+x*p+S*f+C*d+w*u+T*l;j=oe>>>13,oe&=8191,oe+=E*c+D*s+O*o+5*h*k+5*m*A,j+=oe>>>13,oe&=8191;let se=j+x*m+S*p+C*f+w*d+T*u;j=se>>>13,se&=8191,se+=E*l+D*c+O*s+k*o+5*h*A,j+=se>>>13,se&=8191;let ce=j+x*h+S*m+C*p+w*f+T*d;j=ce>>>13,ce&=8191,ce+=E*u+D*l+O*c+k*s+A*o,j+=ce>>>13,ce&=8191,j=(j<<2)+j|0,j=j+M|0,M=j&8191,j>>>=13,N+=j,i[0]=M,i[1]=N,i[2]=P,i[3]=F,i[4]=re,i[5]=ie,i[6]=ae,i[7]=oe,i[8]=se,i[9]=ce}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),r=e[1]>>>13;e[1]&=8191;for(let t=2;t<10;t++)e[t]+=r,r=e[t]>>>13,e[t]&=8191;e[0]+=r*5,r=e[0]>>>13,e[0]&=8191,e[1]+=r,r=e[1]>>>13,e[1]&=8191,e[2]+=r,n[0]=e[0]+5,r=n[0]>>>13,n[0]&=8191;for(let t=1;t<10;t++)n[t]=e[t]+r,r=n[t]>>>13,n[t]&=8191;n[9]-=8192;let i=(r^1)-1;for(let e=0;e<10;e++)n[e]&=i;i=~i;for(let t=0;t<10;t++)e[t]=e[t]&i|n[t];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let a=e[0]+t[0];e[0]=a&65535;for(let n=1;n<8;n++)a=(e[n]+t[n]|0)+(a>>>16)|0,e[n]=a&65535;po(n)}update(e){co(this),Z(e),e=ko(e);let{buffer:t,blockLen:n}=this,r=e.length;for(let i=0;i<r;){let a=Math.min(n-this.pos,r-i);if(a===n){for(;n<=r-i;i+=n)this.process(e,i);continue}t.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){po(this.h,this.r,this.buffer,this.pad)}digestInto(e){co(this),lo(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:r}=this;if(r){for(t[r++]=1;r<16;r++)t[r]=0;this.process(t,0,!0)}this.finalize();let i=0;for(let t=0;t<8;t++)e[i++]=n[t]>>>0,e[i++]=n[t]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function xs(e){let t=(t,n)=>e(n).update(t).digest(),n=e(new Uint8Array(32));return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t}var Ss=xs(e=>new bs(e));function Cs(e,t,n,r,i,a=20){let o=e[0],s=e[1],c=e[2],l=e[3],u=t[0],d=t[1],f=t[2],p=t[3],m=t[4],h=t[5],g=t[6],ee=t[7],te=i,_=n[0],ne=n[1],v=n[2],y=o,b=s,x=c,S=l,C=u,w=d,T=f,E=p,D=m,O=h,k=g,A=ee,j=te,M=_,N=ne,P=v;for(let e=0;e<a;e+=2)y=y+C|0,j=Q(j^y,16),D=D+j|0,C=Q(C^D,12),y=y+C|0,j=Q(j^y,8),D=D+j|0,C=Q(C^D,7),b=b+w|0,M=Q(M^b,16),O=O+M|0,w=Q(w^O,12),b=b+w|0,M=Q(M^b,8),O=O+M|0,w=Q(w^O,7),x=x+T|0,N=Q(N^x,16),k=k+N|0,T=Q(T^k,12),x=x+T|0,N=Q(N^x,8),k=k+N|0,T=Q(T^k,7),S=S+E|0,P=Q(P^S,16),A=A+P|0,E=Q(E^A,12),S=S+E|0,P=Q(P^S,8),A=A+P|0,E=Q(E^A,7),y=y+w|0,P=Q(P^y,16),k=k+P|0,w=Q(w^k,12),y=y+w|0,P=Q(P^y,8),k=k+P|0,w=Q(w^k,7),b=b+T|0,j=Q(j^b,16),A=A+j|0,T=Q(T^A,12),b=b+T|0,j=Q(j^b,8),A=A+j|0,T=Q(T^A,7),x=x+E|0,M=Q(M^x,16),D=D+M|0,E=Q(E^D,12),x=x+E|0,M=Q(M^x,8),D=D+M|0,E=Q(E^D,7),S=S+C|0,N=Q(N^S,16),O=O+N|0,C=Q(C^O,12),S=S+C|0,N=Q(N^S,8),O=O+N|0,C=Q(C^O,7);let F=0;r[F++]=o+y|0,r[F++]=s+b|0,r[F++]=c+x|0,r[F++]=l+S|0,r[F++]=u+C|0,r[F++]=d+w|0,r[F++]=f+T|0,r[F++]=p+E|0,r[F++]=m+D|0,r[F++]=h+O|0,r[F++]=g+k|0,r[F++]=ee+A|0,r[F++]=te+j|0,r[F++]=_+M|0,r[F++]=ne+N|0,r[F++]=v+P|0}var ws=vs(Cs,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Ts=new Uint8Array(16),Es=(e,t)=>{e.update(t);let n=t.length%16;n&&e.update(Ts.subarray(n))},Ds=new Uint8Array(32);function Os(e,t,n,r,i){i!==void 0&&Z(i,void 0,`AAD`);let a=e(t,n,Ds),o=as(r.length,i?i.length:0,!0),s=Ss.create(a);i&&Es(s,i),Es(s,r),s.update(o);let c=s.digest();return po(a,o),c}var ks=ts({blockSize:64,nonceLength:12,tagLength:16},(e=>(t,n,r)=>({encrypt(i,a){let o=i.length;a=is(o+16,a,!1),a.set(i);let s=a.subarray(0,-16);e(t,n,s,s,1);let c=Os(e,t,n,s,r);return a.set(c,o),po(c),a},decrypt(i,a){a=is(i.length-16,a,!1);let o=i.subarray(0,-16),s=i.subarray(-16),c=Os(e,t,n,o,r);if(!rs(s,c))throw Error(`invalid tag`);return a.set(i.subarray(0,-16)),e(t,n,a,a,1),po(c),a}}))(ws)),As=class{constructor(e){Object.defineProperty(this,"_key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._key=new Uint8Array(X(e))}async seal(e,t,n){return await this._seal(X(e),X(t),X(n))}async open(e,t,n){return await this._open(X(e),X(t),X(n))}_seal(e,t,n){return new Promise(r=>{r(ks(this._key,new Uint8Array(e),new Uint8Array(n)).encrypt(new Uint8Array(t)).buffer)})}_open(e,t,n){return new Promise(r=>{r(ks(this._key,new Uint8Array(e),new Uint8Array(n)).decrypt(new Uint8Array(t)).buffer)})}},js=class{constructor(){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Fa.Chacha20Poly1305}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}createEncryptionContext(e){return new As(e)}};function Ms(){return new Promise((e,t)=>{t(new Da(`Not supported`))})}var Ns=new Uint8Array([115,101,99]),Ps=class{constructor(e,t,n){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"exporterSecret",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._api=e,this._kdf=t,this.exporterSecret=n}async seal(e,t){return await Ms()}async open(e,t){return await Ms()}async export(e,t){let n=X(e);if(n.byteLength>8192)throw new _a(`Too long exporter context`);try{return await this._kdf.labeledExpand(this.exporterSecret,Ns,new Uint8Array(n),t)}catch(e){throw new Sa(e)}}},Fs=class extends Ps{},Is=class extends Ps{constructor(e,t,n,r){super(e,t,n),Object.defineProperty(this,"enc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.enc=r}},Ls=class extends Ps{constructor(e,t,n){if(super(e,t,n.exporterSecret),Object.defineProperty(this,"_aead",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nK",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nN",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nT",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n.key===void 0||n.baseNonce===void 0||n.seq===void 0)throw Error(`Required parameters are missing`);this._aead=n.aead,this._nK=this._aead.keySize,this._nN=this._aead.nonceSize,this._nT=this._aead.tagSize;let r=this._aead.createEncryptionContext(n.key);this._ctx={key:r,baseNonce:n.baseNonce,seq:n.seq}}computeNonce(e){let t=Ka(e.seq,e.baseNonce.byteLength);return Xa(e.baseNonce,t).buffer}incrementSeq(e){if(e.seq>2**53-1)throw new Ta(`Message limit reached`);e.seq+=1}},Rs=function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},zs=function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},Bs,Vs=class{constructor(){Bs.set(this,Promise.resolve())}async lock(){let e,t=new Promise(t=>{e=t}),n=Rs(this,Bs,`f`);return zs(this,Bs,t,`f`),await n,e}};Bs=new WeakMap;var Hs=function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},Us=function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},Ws,Gs=class extends Ls{constructor(){super(...arguments),Ws.set(this,void 0)}async open(e,t=Ia.buffer){Us(this,Ws,Hs(this,Ws,`f`)??new Vs,`f`);let n=await Hs(this,Ws,`f`).lock(),r;try{r=await this._ctx.key.open(this.computeNonce(this._ctx),X(e),X(t))}catch(e){throw new wa(e)}finally{n()}return this.incrementSeq(this._ctx),r}};Ws=new WeakMap;var Ks=function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},qs=function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},Js,Ys=class extends Ls{constructor(e,t,n,r){super(e,t,n),Object.defineProperty(this,"enc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Js.set(this,void 0),this.enc=r}async seal(e,t=Ia.buffer){qs(this,Js,Ks(this,Js,`f`)??new Vs,`f`);let n=await Ks(this,Js,`f`).lock(),r;try{r=await this._ctx.key.seal(this.computeNonce(this._ctx),X(e),X(t))}catch(e){throw new Ca(e)}finally{n()}return this.incrementSeq(this._ctx),r}};Js=new WeakMap;var Xs=new Uint8Array([98,97,115,101,95,110,111,110,99,101]),Zs=new Uint8Array([101,120,112]),Qs=new Uint8Array([105,110,102,111,95,104,97,115,104]),$s=new Uint8Array([107,101,121]),ec=new Uint8Array([112,115,107,95,105,100,95,104,97,115,104]),tc=new Uint8Array([115,101,99,114,101,116]),nc=new Uint8Array([72,80,75,69,0,0,0,0,0,0]),rc=class extends ja{constructor(e){if(super(),Object.defineProperty(this,"_kem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_aead",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_suiteId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),typeof e.kem==`number`)throw new _a(`KemId cannot be used`);if(this._kem=e.kem,typeof e.kdf==`number`)throw new _a(`KdfId cannot be used`);if(this._kdf=e.kdf,typeof e.aead==`number`)throw new _a(`AeadId cannot be used`);this._aead=e.aead,this._suiteId=new Uint8Array(nc),this._suiteId.set(Ka(this._kem.id,2),4),this._suiteId.set(Ka(this._kdf.id,2),6),this._suiteId.set(Ka(this._aead.id,2),8),this._kdf.init(this._suiteId)}get kem(){return this._kem}get kdf(){return this._kdf}get aead(){return this._aead}async createSenderContext(e){this._validateInputLength(e),await this._setup();let t=await this._kem.encap(e),n;return n=e.psk===void 0?e.senderKey===void 0?Ma.Base:Ma.Auth:e.senderKey===void 0?Ma.Psk:Ma.AuthPsk,await this._keyScheduleS(n,t.sharedSecret,t.enc,e)}async createRecipientContext(e){this._validateInputLength(e),await this._setup();let t=await this._kem.decap(e),n;return n=e.psk===void 0?e.senderPublicKey===void 0?Ma.Base:Ma.Auth:e.senderPublicKey===void 0?Ma.Psk:Ma.AuthPsk,await this._keyScheduleR(n,t,e)}async seal(e,t,n=Ia.buffer){let r=await this.createSenderContext(e);return{ct:await r.seal(t,n),enc:r.enc}}async open(e,t,n=Ia.buffer){return await(await this.createRecipientContext(e)).open(t,n)}async _keySchedule(e,t,n){let r=n.psk===void 0?Ia:Ha(n.psk.id),i=await this._kdf.labeledExtract(Ia,ec,r),a=n.info===void 0?Ia:Ha(n.info),o=await this._kdf.labeledExtract(Ia,Qs,a),s=new Uint8Array(1+i.byteLength+o.byteLength);s.set(new Uint8Array([e]),0),s.set(new Uint8Array(i),1),s.set(new Uint8Array(o),1+i.byteLength);let c=n.psk===void 0?Ia:Ha(n.psk.key),l=this._kdf.buildLabeledIkm(tc,c),u=this._kdf.buildLabeledInfo(Zs,s,this._kdf.hashSize),d=await this._kdf.extractAndExpand(t,l,u,this._kdf.hashSize);if(this._aead.id===Fa.ExportOnly)return{aead:this._aead,exporterSecret:d};let f=this._kdf.buildLabeledInfo($s,s,this._aead.keySize),p=await this._kdf.extractAndExpand(t,l,f,this._aead.keySize),m=this._kdf.buildLabeledInfo(Xs,s,this._aead.nonceSize),h=await this._kdf.extractAndExpand(t,l,m,this._aead.nonceSize);return{aead:this._aead,exporterSecret:d,key:p,baseNonce:new Uint8Array(h),seq:0}}async _keyScheduleS(e,t,n,r){let i=await this._keySchedule(e,t,r);return i.key===void 0?new Is(this._api,this._kdf,i.exporterSecret,n):new Ys(this._api,this._kdf,i,n)}async _keyScheduleR(e,t,n){let r=await this._keySchedule(e,t,n);return r.key===void 0?new Fs(this._api,this._kdf,r.exporterSecret):new Gs(this._api,this._kdf,r)}_validateInputLength(e){if(e.info!==void 0&&e.info.byteLength>268435456)throw new _a(`Too long info`);if(e.psk!==void 0){if(e.psk.key.byteLength<32)throw new _a(`PSK must have at least 32 bytes`);if(e.psk.key.byteLength>8192)throw new _a(`Too long psk.key`);if(e.psk.id.byteLength>8192)throw new _a(`Too long psk.id`)}}},ic=class extends rc{},ac=1n,oc=2n,sc=3n,cc=5n,lc=57896044618658097711785492504343953926634992332820282019728792003956564819949n;function uc(e){let t=10n,n=80n,r=lc,i=e*e%r*e%r,a=Xo(Xo(i,oc,r)*i%r,ac,r)*e%r,o=Xo(a,cc,r)*a%r,s=Xo(o,t,r)*o%r,c=Xo(s,20n,r)*s%r,l=Xo(c,40n,r)*c%r;return{pow_p_5_8:Xo(Xo(Xo(Xo(l,n,r)*l%r,n,r)*l%r,t,r)*o%r,oc,r)*e%r,b2:i}}function dc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var fc=(()=>{let e=lc;return $o({P:e,type:`x25519`,powPminus2:t=>{let{pow_p_5_8:n,b2:r}=uc(t);return Yo(Xo(n,sc,e)*r,e)},adjustScalarBytes:dc})})(),pc=class extends ao{constructor(e){super(`X25519`,32,fc,e)}derive(e,t){try{return Promise.resolve(this._curve.getSharedSecret(e,t))}catch(e){return Promise.reject(new va(e))}}},mc=`DHKEM_X25519_HKDF_SHA256/HKDF_SHA256/CHACHA20_POLY1305/AUTH`,hc=2**31,gc=65536,_c=16,vc=32,yc=(1n<<255n)-19n,bc=new TextEncoder,xc=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`;function Sc(e){let t=0n;for(let n=0;n<e.length;n+=2)t|=BigInt(Number.parseInt(e.slice(n,n+2),16))<<BigInt(n/2*8);return t}var Cc=new Set([0n,1n,Sc(`e0eb7a7c3b41b8ae1656e3faf19fc46ada098deb9c32b1fd866205165f49b800`),Sc(`5f9c95bca3508c24b1d0b1559c83ef5b04445cc4581c8e86d8224eddd09f1157`),yc-1n]),wc=new Uint8Array,Tc=class extends Wa{async extract(e,t){return X(zo(Jo,e.byteLength===0?new Uint8Array(this.hashSize):Ha(e),Ha(t)))}async expand(e,t,n){if(!Number.isSafeInteger(n)||n<0||n>255*this.hashSize)throw Error(`HKDF output length exceeds the RFC 5869 limit.`);let r=Ha(e),i=Ha(t),a=new Uint8Array(n),o=wc;for(let e=1,t=0;t<a.byteLength;e+=1){let n=kc([o,i,Uint8Array.of(e)]);o=new Uint8Array(zo(Jo,r,n));let s=a.byteLength-t;a.set(o.subarray(0,Math.min(o.byteLength,s)),t),t+=Math.min(o.byteLength,s)}return X(a)}async extractAndExpand(e,t,n,r){return this.expand(await this.extract(e,t),n,r)}},Ec=new ic({kem:new class extends eo{secretSize=32;encSize=32;publicKeySize=32;privateKeySize=32;constructor(e){super(Na.DhkemX25519HkdfSha256,new pc(e),e)}}(new Tc),kdf:new Tc,aead:new js}),$=class extends Error{code;name=`RelayPayloadChannelFailure`;constructor(e,t){super(t),this.code=e}};function Dc(e){return new Uint8Array(e.slice(0))}function Oc(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}function kc(e){let t=e.reduce((e,t)=>e+t.byteLength,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;return n}function Ac(e){if(!Number.isSafeInteger(e)||e<0||e>4294967295)throw new $(`channel_ticket_binding_invalid`,`Invalid uint32 value.`);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!1),t}function jc(e){if(!Number.isSafeInteger(e)||e<0)throw new $(`channel_ticket_binding_invalid`,`Invalid uint64 value.`);let t=new Uint8Array(8);return new DataView(t.buffer).setBigUint64(0,BigInt(e),!1),t}function Mc(e){return kc([Ac(e.byteLength),e])}function Nc(e){return Uint8Array.of(e===`control-to-runtime`?0:1)}function Pc(e){return e===`handshake`?Uint8Array.of(0):e===`application`?Uint8Array.of(1):Uint8Array.of(2)}function Fc(e){let t=``;for(let n=0;n<e.byteLength;n+=3){let r=e[n]??0,i=e[n+1]??0,a=e[n+2]??0,o=r<<16|i<<8|a;t+=xc[o>>>18&63],t+=xc[o>>>12&63],n+1<e.byteLength&&(t+=xc[o>>>6&63]),n+2<e.byteLength&&(t+=xc[o&63])}return t}function Ic(e){if(!/^[A-Za-z0-9_-]*$/.test(e)||e.length%4==1)throw new $(`channel_authentication_failed`,`Encrypted relay frame is not canonical base64url.`);let t=new Uint8Array(Math.floor(e.length*6/8)),n=0,r=0,i=0;for(let a of e){let e=xc.indexOf(a);n=n<<6|e,r+=6,r>=8&&(r-=8,t[i]=n>>>r&255,i+=1)}if(Fc(t)!==e)throw new $(`channel_authentication_failed`,`Encrypted relay frame has a non-canonical base64url encoding.`);return t}function Lc(e){let t=new Uint8Array(e);t[31]=(t[31]??0)&127;let n=0n;for(let e=0;e<t.byteLength;e+=1)n|=BigInt(t[e]??0)<<BigInt(e*8);return Cc.has(n%yc)}var Rc={async sha256(e){if(globalThis.crypto?.subtle===void 0)throw new $(`channel_authentication_failed`,`SHA-256 is unavailable in this runtime.`);return Dc(await globalThis.crypto.subtle.digest(`SHA-256`,Oc(e)))}},zc={randomBytes(e){if(globalThis.crypto?.getRandomValues===void 0)throw new $(`endpoint_key_invalid`,`A cryptographically secure random source is unavailable.`);return globalThis.crypto.getRandomValues(new Uint8Array(e))}};function Bc(e,t){let n=bc.encode(e).byteLength;if(n===0||n>256)throw new $(`channel_ticket_binding_invalid`,`${t} must contain between 1 and 256 UTF-8 bytes.`)}function Vc(e){let t=bc.encode(e).byteLength;if(t===0||t>65536)throw new $(`channel_ticket_binding_invalid`,`Control ticket must contain between 1 and ${gc} UTF-8 bytes.`)}async function Hc(e,t=Rc){Vc(e.exactCompactTicket),Bc(e.channelId,`Channel ID`),Bc(e.runtimeId,`Runtime ID`),jc(e.connectionEpoch);let n=await t.sha256(bc.encode(e.exactCompactTicket));if(n.byteLength!==32)throw new $(`channel_ticket_binding_invalid`,`The control ticket digest must be 32 bytes.`);return{...e,ticketDigest:new Uint8Array(n)}}function Uc(e){return Fc(e.ticketDigest)}async function Wc(e=zc){let t=new Uint8Array(await e.randomBytes(vc));if(t.byteLength!==vc)throw new $(`endpoint_key_invalid`,`The endpoint random source must return ${vc} bytes.`);try{return Fc(t)}finally{t.fill(0)}}function Gc(e){return kc([bc.encode(`forge-relay-v4`),Uint8Array.of(0),e.ticketDigest,Nc(e.direction)])}function Kc(e){return kc([bc.encode(`forge-relay`),Ac(4),e.binding.ticketDigest,bc.encode(e.binding.channelId),Nc(e.binding.direction),Pc(e.frameClass),jc(e.sequence),bc.encode(e.binding.runtimeId),jc(e.binding.connectionEpoch),Ac(e.ciphertextLength)].map(Mc))}async function qc(e=zc){let t=new Uint8Array(await e.randomBytes(vc));if(t.byteLength!==vc)throw new $(`endpoint_key_invalid`,`The endpoint random source must return ${vc} bytes.`);try{return await Ec.kem.deriveKeyPair(t)}catch(e){throw new $(`endpoint_key_invalid`,e instanceof Error?e.message:`Endpoint key generation failed.`)}finally{t.fill(0)}}async function Jc(e){try{return Fc(Dc(await Ec.kem.serializePublicKey(e)))}catch(e){throw new $(`endpoint_key_invalid`,e instanceof Error?e.message:`Endpoint public-key serialization failed.`)}}function Yc(e,t){if(!/^[A-Za-z0-9_-]{43}$/u.test(t))throw new $(`endpoint_key_invalid`,`The endpoint key ID requires a canonical X25519 public key.`);return`${e}:${t}`}async function Xc(e){try{let t=Ic(e);if(t.byteLength!==vc)throw Error(`Invalid endpoint key length.`);if(Lc(t))throw new $(`endpoint_key_invalid`,`Low-order X25519 endpoint public keys are not allowed.`);return await Ec.kem.deserializePublicKey(t)}catch(e){throw e instanceof $?e:new $(`endpoint_key_invalid`,e instanceof Error?e.message:`Endpoint public-key deserialization failed.`)}}var Zc=class{tail=Promise.resolve();run(e){let t=this.tail.then(e,e);return this.tail=t.then(()=>void 0,()=>void 0),t}},Qc=class{startedAt=Date.now();records=0;bytes=0;assertAvailable(e){if(this.records>=hc||this.bytes+e>1073741824||Date.now()-this.startedAt>=18e5)throw new $(`channel_limit_reached`,`The encrypted relay channel must be renewed before another record is sent.`)}commit(e){this.records+=1,this.bytes+=e}};function $c(e,t){if(e.type!==`relay.encrypted-frame`||e.protocolVersion!==4||e.channelId!==t.channelId||e.direction!==t.direction||![`handshake`,`application`,`close`].includes(e.frameClass))throw new $(`channel_ticket_binding_invalid`,`Encrypted relay frame does not match the CMMD-ticket-bound channel.`)}var el=class{binding;context;encapsulatedKey;queue=new Zc;budget=new Qc;sequence=0;constructor(e,t){this.binding=e,this.context=t,this.encapsulatedKey=Fc(Dc(t.enc))}seal(e){return this.queue.run(async()=>{if(e.plaintext.byteLength>16777216)throw new $(`channel_limit_reached`,`Encrypted relay plaintext exceeds the per-record byte limit.`);let t=e.plaintext.byteLength+_c;this.budget.assertAvailable(t);let n=this.sequence,r=Kc({binding:this.binding,frameClass:e.frameClass,sequence:n,ciphertextLength:t}),i;try{i=Dc(await this.context.seal(e.plaintext,r))}catch(e){throw new $(`channel_authentication_failed`,e instanceof Error?e.message:`Relay payload encryption failed.`)}if(i.byteLength!==t)throw new $(`channel_authentication_failed`,`Relay payload encryption returned an invalid ciphertext length.`);return this.sequence+=1,this.budget.commit(i.byteLength),{type:`relay.encrypted-frame`,protocolVersion:4,channelId:this.binding.channelId,direction:this.binding.direction,frameClass:e.frameClass,sequence:n,ciphertext:Fc(i)}})}},tl=class{binding;context;queue=new Zc;budget=new Qc;sequence=0;constructor(e,t){this.binding=e,this.context=t}open(e){return this.queue.run(async()=>{if($c(e,this.binding),!Number.isSafeInteger(e.sequence)||e.sequence!==this.sequence)throw new $(`channel_sequence_invalid`,`Expected encrypted relay sequence ${this.sequence}, received ${String(e.sequence)}.`);let t=Ic(e.ciphertext);this.budget.assertAvailable(t.byteLength);let n=Kc({binding:this.binding,frameClass:e.frameClass,sequence:e.sequence,ciphertextLength:t.byteLength}),r;try{r=Dc(await this.context.open(t,n))}catch(e){throw new $(`channel_authentication_failed`,e instanceof Error?e.message:`Relay payload authentication failed.`)}if(r.byteLength>16777216)throw new $(`channel_limit_reached`,`Decrypted relay plaintext exceeds the per-record byte limit.`);return this.sequence+=1,this.budget.commit(t.byteLength),r})}};async function nl(e){let t=null;try{if(t=new Uint8Array(await(e.randomSource??zc).randomBytes(vc)),t.byteLength!==vc)throw Error(`The endpoint random source must return ${vc} bytes.`);let n=await Ec.createSenderContext({recipientPublicKey:e.recipientPublicKey,senderKey:e.senderKey,info:Gc(e.binding),ekm:t});return new el(e.binding,n)}catch(e){throw new $(`channel_authentication_failed`,e instanceof Error?e.message:`Relay payload sender setup failed.`)}finally{t?.fill(0)}}async function rl(e){try{let t=await Ec.createRecipientContext({recipientKey:e.recipientKey,senderPublicKey:e.senderPublicKey,enc:Ic(e.encapsulatedKey),info:Gc(e.binding)});return new tl(e.binding,t)}catch(e){throw e instanceof $?e:new $(`channel_authentication_failed`,e instanceof Error?e.message:`Relay payload recipient setup failed.`)}}var il=128,al=2097152,ol=864e5,sl=class extends Error{constructor(e){super(e),this.name=`RelayControlJournalError`}};function cl(e){return typeof e==`string`&&e.length>0}function ll(e){return cl(e)&&Number.isFinite(Date.parse(e))}function ul(e){return e===`pending`||e===`retrying`||e===`outcome-unknown`||e===`failed`}function dl(e){return cl(e.transportRequestId)&&cl(e.runtimeId)&&cl(e.actorSessionId)&&cl(e.durableRequestId)&&cl(e.method)}function fl(e){return Number.isSafeInteger(e.sequence)&&Number(e.sequence)>0&&Number.isSafeInteger(e.attemptCount)&&Number(e.attemptCount)>=0}function pl(e){return e.persistence!==`frame`&&e.persistence!==`metadata-only`||e.frame!==null&&!cl(e.frame)?!1:e.persistence!==`metadata-only`||e.frame===null}function ml(e){return!ul(e.status)||e.errorCode!==null&&!cl(e.errorCode)?!1:e.status===`outcome-unknown`||e.status===`failed`?e.frame===null&&cl(e.errorCode):e.errorCode===null}function hl(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return dl(t)&&fl(t)&&pl(t)&&ml(t)&&ll(t.createdAt)&&ll(t.updatedAt)}function gl(e){try{return JSON.parse(e)}catch{throw new sl(`Forge relay control journal is corrupt.`)}}function _l(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=e;return t.version===1&&cl(t.controlSessionId)&&Number.isSafeInteger(t.nextSequence)&&Number(t.nextSequence)>=1&&Array.isArray(t.records)&&t.records.every(hl)}function vl(e){let t=new Set(e.map(xl)),n=new Set(e.map(e=>e.durableRequestId)),r=new Set(e.map(e=>e.sequence));return t.size===e.length&&n.size===e.length&&r.size===e.length}function yl(e){let t=gl(e);if(!_l(t))throw new sl(`Forge relay control journal is corrupt.`);let n=t.records,r=n.reduce((e,t)=>Math.max(e,t.sequence),0);if(!vl(n)||t.nextSequence<=r)throw new sl(`Forge relay control journal is corrupt.`);return{version:1,controlSessionId:t.controlSessionId,nextSequence:t.nextSequence,records:n}}function bl(){return crypto.randomUUID()}function xl(e){return`${e.runtimeId}\0${e.actorSessionId}\0${e.transportRequestId}`}var Sl={pending:1,retrying:2,"outcome-unknown":3,failed:4};function Cl(e,t){let n=e.filter(e=>e.runtimeId===t);if(n.length===0)return{state:`idle`,count:0};let r=n.reduce((e,t)=>Sl[t.status]>Sl[e]?t.status:e,`pending`);return{state:r,count:n.filter(e=>e.status===r).length}}function wl(e){let t=e.randomUUID??bl,n=e.now??(()=>new Date),r=e.maxRecords??il,i=e.maxBytes??al,a=e.maxReplayAgeMs??ol;if(r<1||i<1||a<1)throw new sl(`Forge relay control journal limits must be positive.`);let o=e.storage.read(),s=n(),c=o?yl(o):{version:1,controlSessionId:t(),nextSequence:1,records:[]},l=new Map,u=new Set;function d(){return{controlSessionId:c.controlSessionId,records:[...c.records]}}function f(t){if(t.records.length>r)throw new sl(`Forge relay control journal reached its record limit.`);let n=JSON.stringify(t);if(new TextEncoder().encode(n).byteLength>i)throw new sl(`Forge relay control journal reached its storage limit.`);e.storage.write(n),c=t;let a=d();for(let e of u)e(a)}function p(e,t){return e.status!==`pending`&&e.status!==`retrying`?e:e.persistence===`metadata-only`||e.frame===null?{...e,frame:null,status:`outcome-unknown`,errorCode:`RELAY_COMMAND_OUTCOME_UNKNOWN`,updatedAt:t.toISOString()}:t.getTime()-Date.parse(e.createdAt)>a?{...e,frame:null,status:`outcome-unknown`,errorCode:`RELAY_RECOVERY_EXPIRED`,updatedAt:t.toISOString()}:e}let m=c.records.map(e=>p(e,s)),h=m.some((e,t)=>e!==c.records[t]);(o===null||h)&&f({...c,records:m});function g(e){let t=xl(e);return{key:t,existing:c.records.find(e=>xl(e)===t)??null}}function ee(e,t,n){if([e.method===t.method,e.persistence===t.persistence,n===void 0||n===t.frame,e.frame===null||e.frame===t.frame,t.durableRequestId===void 0||e.durableRequestId===t.durableRequestId].includes(!1))throw new sl(`Relay transport request ${t.transportRequestId} was reused with different content.`);if(e.status===`failed`||e.status===`outcome-unknown`)throw new sl(`Relay transport request ${t.transportRequestId} requires an explicit outcome acknowledgement.`)}function te(e){if(e.durableRequestId!==void 0&&c.records.some(t=>t.durableRequestId===e.durableRequestId))throw new sl(`Relay durable request ${e.durableRequestId} was reused by another transport request.`)}function _(e){let r=n().toISOString();return{runtimeId:e.runtimeId,actorSessionId:e.actorSessionId,transportRequestId:e.transportRequestId,durableRequestId:e.durableRequestId??t(),sequence:c.nextSequence,method:e.method,persistence:e.persistence,frame:e.persistence===`frame`?e.frame:null,status:`pending`,attemptCount:0,errorCode:null,createdAt:r,updatedAt:r}}function ne(e){let{key:t,existing:n}=g(e);if(n!==null)return ee(n,e,l.get(t)),l.set(t,e.frame),n;te(e);let r=_(e);return l.set(t,e.frame),f({...c,nextSequence:c.nextSequence+1,records:[...c.records,r]}),r}function v(e,t,n){let r=c.records.find(r=>r.runtimeId===e&&r.actorSessionId===t&&r.transportRequestId===n);if(!r)throw new sl(`Relay transport request ${n} is not journaled.`);return r}function y(e,t,r,i){v(e,t,r);let a=n().toISOString();l.delete(xl({runtimeId:e,actorSessionId:t,transportRequestId:r})),f({...c,records:c.records.map(n=>n.runtimeId===e&&n.actorSessionId===t&&n.transportRequestId===r?{...n,frame:null,status:`failed`,errorCode:i,updatedAt:a}:n)})}function b(e,t,r){let i=v(e,t,r);if(i.status===`failed`||i.status===`outcome-unknown`)throw new sl(`Relay transport request ${r} has no replayable outcome.`);let a={...i,status:i.attemptCount>0?`retrying`:`pending`,attemptCount:i.attemptCount+1,errorCode:null,updatedAt:n().toISOString()};return f({...c,records:c.records.map(n=>n.runtimeId===e&&n.actorSessionId===t&&n.transportRequestId===r?a:n)}),a}function x(e,t,n){let r=c.records.filter(r=>r.runtimeId!==e||r.actorSessionId!==t||r.transportRequestId!==n);r.length!==c.records.length&&(l.delete(xl({runtimeId:e,actorSessionId:t,transportRequestId:n})),f({...c,records:r}))}function S(e,t,n){let r=v(e,t,n);if(r.status!==`failed`&&r.status!==`outcome-unknown`)throw new sl(`Relay transport request ${n} does not have an acknowledgeable outcome.`);x(e,t,n)}function C(){let e=n(),t=c.records.map(t=>p(t,e));t.some((e,t)=>e!==c.records[t])&&f({...c,records:t})}function w(e,t){let r=n().toISOString(),i=c.records.map(n=>n.runtimeId!==e||n.actorSessionId===t||n.status!==`pending`&&n.status!==`retrying`?n:(l.delete(xl(n)),{...n,frame:null,status:`outcome-unknown`,errorCode:`RELAY_ACTOR_SESSION_CHANGED`,updatedAt:r}));i.some((e,t)=>e!==c.records[t])&&f({...c,records:i})}return{controlSessionId:c.controlSessionId,prepare:ne,records:()=>[...c.records],pending:()=>[...c.records],replayable:(e,t)=>(C(),c.records.filter(n=>n.runtimeId===e&&n.actorSessionId===t&&n.persistence===`frame`&&n.frame!==null&&(n.status===`pending`||n.status===`retrying`))),fenceActor:w,beginAttempt:b,markFailed:y,complete:x,acknowledge:S,subscribe:e=>(u.add(e),e(d()),()=>u.delete(e))}}function Tl(e=null){let t=e;return{read:()=>t,write:e=>{t=e}}}var El=$t(Kt),Dl=nn(Jt),Ol=nn(Wt),kl=[`rpc.read`,`rpc.mutate`,`cursor.resume`,`terminal.stream`,`browser.stream`,`bulk.transfer`,`envelope.validation`,`payload.e2e`];function Al(e,t){if(!Array.isArray(e))return null;for(let n of e)if(Array.isArray(n)&&n.length===2&&n[0]===t&&typeof n[1]==`string`)return n[1];return null}function jl(e,t){let n=JSON.parse(e),r=aa(n);if(r!==null)return{messageType:`request`,...r};let i=Ml(n,t);if(i!==null)return i;let a=Nl(n);if(a!==null)return a;throw Error(`Forge relay protocol v2 requires a recognized Effect RPC frame.`)}function Ml(e,t){if(e._tag!==`Request`||typeof e.id!=`string`||e.id.length===0||typeof e.tag!=`string`||e.tag.length===0)return null;let n=ha({method:e.tag,payload:e.payload,grantedScopes:t});return{messageType:`request`,requestId:e.id,correlationId:Al(e.headers,Zt.requestId)??e.id,method:e.tag,...n}}function Nl(e){return e._tag!==`Ack`&&e._tag!==`Interrupt`||typeof e.requestId!=`string`||e.requestId.length===0?null:{messageType:`acknowledgement`,requestId:e.requestId,correlationId:e.requestId,method:`@effect/rpc/${e._tag}`,requiredScope:null,deliveryClass:`read`,journalPersistence:`none`}}function Pl(e,t){let n=new Event(`error`);return Object.defineProperties(n,{error:{value:Error(t),enumerable:!0},message:{value:`${e}: ${t}`,enumerable:!0}}),n}var Fl=new Set([`network`,`server`,`auth`,`permission`,`client`]),Il=new Set([`network`,`server`]);function Ll(e){return e&&typeof e==`object`?e:{}}function Rl(e){return typeof e.code==`string`&&e.code.length>0?e.code:typeof e.kind==`string`&&Fl.has(e.kind)?`RELAY_ACTION_GRANT_UNAVAILABLE`:`MALFORMED_FRAME`}function zl(e){if(e.retryable===!0||typeof e.kind==`string`&&Il.has(e.kind))return!0;let t=typeof e.status==`number`?e.status:null;return t===429||t!==null&&t>=500}function Bl(e){let t=Ll(e);return{code:Rl(t),message:e instanceof Error?e.message:`Forge relay frame encoding failed.`,retryable:zl(t)}}function Vl(e,t){let n=new Event(e.type),r=e;for(let e of t)r[e]!==void 0&&Object.defineProperty(n,e,{value:r[e],enumerable:!0});return n}function Hl(e){return!Array.isArray(e)||e.length!==2||typeof e[0]!=`string`?!1:Object.values(Zt).includes(e[0])}function Ul(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:null}function Wl(e){if(!Array.isArray(e))return null;for(let t of e){let e=Ul(t);if(e?._tag!==`Fail`)continue;let n=Ul(e.error)?.code;if(typeof n==`string`&&n.length>0)return n}return null}function Gl(e){let t=Ul(e.exit);return t===null?`RELAY_RPC_RESPONSE_INVALID`:t._tag===`Success`?null:t._tag!==`Failure`||!Array.isArray(t.cause)?`RELAY_RPC_RESPONSE_INVALID`:Wl(t.cause)??`RELAY_RPC_FAILED`}function Kl(e){if(typeof e!=`string`)return null;try{let t=El(JSON.parse(e));return t._tag===`Some`?t.value:null}catch{return null}}function ql(e,t){if(e.role===`control`&&e.protocolVersion===t&&e.protocolVersion>=1){if(e.protocolVersion===1)return null;if(e.actor!==void 0&&e.scopes!==void 0)return{runtimeId:e.runtimeId,connectionEpoch:e.connectionEpoch,protocolVersion:e.protocolVersion,actor:e.actor,scopes:e.scopes}}}function Jl(e,t,n){if(typeof e==`string`)try{let r=Ul(JSON.parse(e));if(r?._tag!==`Exit`||typeof r.requestId!=`string`)return;let i=Gl(r);if(i===null){n.complete(t.runtimeId,t.actor.sessionId,r.requestId);return}n.markFailed(t.runtimeId,t.actor.sessionId,r.requestId,i)}catch{}}function Yl(e){let t=Al(e,Zt.sequence);if(t===null)return;let n=Number(t);return Number.isSafeInteger(n)&&n>=0?n:void 0}function Xl(e){return{issuedAt:Al(e,Zt.issuedAt)??new Date().toISOString(),expiresAt:Al(e,Zt.expiresAt)??new Date(Date.now()+12e4).toISOString()}}function Zl(e){if(e!==2&&e!==3&&e!==4)throw new Y(`protocol_version_mismatch`,`Unsupported Forge relay envelope version: ${e}`,!1);return e}async function Ql(e){let t=ma({method:e.identity.method,payload:e.payload});if(t===null)return;let n=$l(e.context);if(e.acquire===void 0)throw new Y(`action_grant_required`,`CMMD action-grant issuance is unavailable for this remote response.`,!1);return e.acquire({...n,method:`orchestration.dispatchCommand`,...t,durableRequestId:e.identity.correlationId,payloadHash:e.payloadHash,requiredScope:`approval.respond`})}function $l(e){if(e.protocolVersion===3)return{protocolVersion:3};if(e.protocolVersion!==4)throw new Y(`protocol_update_required`,`Update Forge on the target runtime before responding remotely.`,!1);return{protocolVersion:4,channelId:eu(e.channelId),channelTicketDigest:eu(e.channelTicketDigest),runtimeEndpointKeyId:eu(e.runtimeEndpointKeyId),controlEndpointKeyId:eu(e.controlEndpointKeyId)}}function eu(e){if(typeof e==`string`&&e.length>0)return e;throw new Y(`channel_ticket_binding_invalid`,`The encrypted Forge relay channel is missing its CMMD ticket binding.`,!1)}function tu(e){return e===void 0?{}:{sequence:e}}function nu(e){return e===void 0?{}:{actionGrant:e}}async function ru(e){let t=jl(e.data,e.context.scopes),n=JSON.parse(e.data),r=Xl(n.headers),i=Yl(n.headers),a=await e.crypto.sha256Base64Url(e.data),o=await Ql({context:e.context,identity:t,payload:n.payload,payloadHash:a,...e.acquireActionGrant===void 0?{}:{acquire:e.acquireActionGrant}}),s=Zl(e.context.protocolVersion),c={messageType:t.messageType,requestId:t.requestId,correlationId:t.correlationId,method:t.method,requiredScope:t.requiredScope,deliveryClass:t.deliveryClass,runtimeId:e.context.runtimeId,connectionEpoch:e.context.connectionEpoch,actor:e.context.actor,...r,payloadHash:a,...tu(i)};return s===2?{protocolVersion:2,...c}:s===3?{protocolVersion:3,...c,...nu(o)}:{protocolVersion:4,...c,...nu(o)}}function iu(e){return typeof e==`string`&&e.length>0}function au(e){return[e.protocolVersion===4,iu(e.runtimeId),Number.isSafeInteger(e.connectionEpoch),Number(e.connectionEpoch)>0,e.hpkeSuite===mc,iu(e.channelId),iu(e.runtimeEndpointKeyId),iu(e.runtimeEndpointPublicKey),iu(e.controlEndpointKeyId),iu(e.controlEndpointPublicKey),iu(e.controlChannelNonce),e.controlEndpointKeyPair!==void 0].every(Boolean)}function ou(e){if(!au(e))throw new Y(`end_to_end_encryption_required`,`Forge relay protocol v4 requires complete endpoint encryption metadata.`,!1);return e}async function su(e){if(await Jc(e.controlEndpointKeyPair.publicKey)!==e.controlEndpointPublicKey)throw new Y(`endpoint_key_invalid`,`The control endpoint private key does not match the CMMD route.`,!1);let t=await Xc(e.runtimeEndpointPublicKey),[n,r]=await Promise.all([Hc({exactCompactTicket:e.token,channelId:e.channelId,direction:`control-to-runtime`,runtimeId:e.runtimeId,connectionEpoch:e.connectionEpoch},e.payloadDigestProvider),Hc({exactCompactTicket:e.token,channelId:e.channelId,direction:`runtime-to-control`,runtimeId:e.runtimeId,connectionEpoch:e.connectionEpoch},e.payloadDigestProvider)]);return{controlToRuntimeBinding:n,runtimeToControlBinding:r,sender:await nl({binding:n,senderKey:e.controlEndpointKeyPair,recipientPublicKey:t,...e.payloadRandomSource?{randomSource:e.payloadRandomSource}:{}}),runtimePublicKey:t,recipient:null,phase:`awaiting-runtime-hello`}}function cu(e,t,n){return[e.direction===`runtime-to-control`,e.frameClass===n,e.channelId===t.channelId].every(Boolean)}function lu(e){return[e.confirmation.phase===e.expectedPhase,e.confirmation.channelId===e.route.channelId,e.confirmation.runtimeId===e.context.runtimeId,e.confirmation.connectionEpoch===e.context.connectionEpoch].every(Boolean)}function uu(e){let{envelope:t}=e.application;return[t.runtimeId===e.context.runtimeId,t.connectionEpoch===e.context.connectionEpoch,t.actor.userId===e.context.actor.userId,t.actor.deviceId===e.context.actor.deviceId,t.actor.sessionId===e.context.actor.sessionId,t.payloadHash===e.payloadHash].every(Boolean)}async function du(e){if(e.channel.recipient!==null){if(e.message.encapsulatedKey!==void 0)throw new Y(`endpoint_key_invalid`,`The runtime attempted to replace its endpoint encapsulation.`,!1);return e.channel.recipient}if(e.message.sequence!==0||!e.message.encapsulatedKey)throw new Y(`channel_confirmation_failed`,`The runtime handshake omitted its endpoint encapsulation.`,!1);let t=await rl({binding:e.channel.runtimeToControlBinding,recipientKey:e.route.controlEndpointKeyPair,senderPublicKey:e.channel.runtimePublicKey,encapsulatedKey:e.message.encapsulatedKey});return e.channel.recipient=t,t}var fu=class extends EventTarget{socket;route;relayCrypto;journal;lifecycle;acquireActionGrant;CONNECTING=WebSocket.CONNECTING;OPEN=WebSocket.OPEN;CLOSING=WebSocket.CLOSING;CLOSED=WebSocket.CLOSED;binaryType=`blob`;onopen=null;onclose=null;onerror=null;onmessage=null;authenticated=!1;context=null;payloadChannel=null;sendChain=Promise.resolve();constructor(e,t,n,r,i={},a){super(),this.socket=e,this.route=t,this.relayCrypto=n,this.journal=r,this.lifecycle=i,this.acquireActionGrant=a,e.addEventListener(`open`,()=>void this.beginAuthentication()),e.addEventListener(`message`,e=>void this.handleMessageSafely(e)),e.addEventListener(`error`,e=>{let t=Vl(e,[`error`,`message`]),n=typeof t.message==`string`?String(t.message):`Forge relay connection failed.`;this.lifecycle.onError?.({code:`RELAY_SOCKET_ERROR`,message:n}),this.emit(`error`,t)}),e.addEventListener(`close`,e=>{this.authenticated=!1,this.context=null,this.payloadChannel=null,this.lifecycle.onDisconnected?.({code:e.code,reason:e.reason}),this.emit(`close`,Vl(e,[`code`,`reason`,`wasClean`]))})}get bufferedAmount(){return this.socket.bufferedAmount}get extensions(){return this.socket.extensions}get protocol(){return this.socket.protocol}get readyState(){return this.authenticated?this.socket.readyState:WebSocket.CONNECTING}get url(){return this.route.relayWebSocketUrl}send(e){if(!this.authenticated||typeof e!=`string`)throw new DOMException(`Forge relay RPC socket is not open for text frames.`,`InvalidStateError`);if(this.route.protocolVersion===1){this.socket.send(JSON.stringify({type:`relay.frame`,payload:e}));return}let t=this.context;if(t===null)throw new DOMException(`Forge relay v2 context is unavailable.`,`InvalidStateError`);let n=jl(e,t.scopes),r=n.messageType===`request`&&n.journalPersistence!==`none`?this.journal.prepare({runtimeId:t.runtimeId,actorSessionId:t.actor.sessionId,transportRequestId:n.requestId,...n.correlationId===n.requestId?{}:{durableRequestId:n.correlationId},method:n.method,frame:e,persistence:n.journalPersistence}):null;this.enqueueFrame(e,r)}enqueueFrame(e,t){this.sendChain=this.sendChain.then(()=>this.transmitFrame(e,t)).catch(e=>{let n=Bl(e);t!==null&&!n.retryable&&this.journal.markFailed(t.runtimeId,t.actorSessionId,t.transportRequestId,n.code),this.lifecycle.onError?.({code:n.code,message:n.message}),this.emit(`error`,Pl(n.code,n.message)),this.socket.readyState<WebSocket.CLOSING&&this.socket.close(4400,`${n.code}: ${n.message}`)})}async transmitFrame(e,t){let n=this.requireReadyContext(),r=await this.outboundFrame(e,t),i=await ru({data:r,context:n,crypto:this.relayCrypto,...this.acquireActionGrant?{acquireActionGrant:this.acquireActionGrant}:{}});if(n.protocolVersion===4){let e=await this.requirePayloadChannel().sender.seal({frameClass:`application`,plaintext:new TextEncoder().encode(JSON.stringify({payload:r,envelope:i}))});this.socket.send(JSON.stringify(e));return}this.socket.send(JSON.stringify({type:`relay.frame`,payload:r,envelope:i}))}requireReadyContext(){if(!this.authenticated||this.socket.readyState!==WebSocket.OPEN)throw new DOMException(`Forge relay RPC socket closed before send.`,`InvalidStateError`);if(this.context===null)throw new DOMException(`Forge relay v2 context is unavailable.`,`InvalidStateError`);return this.context}requirePayloadChannel(){let e=this.payloadChannel;if(e===null||e.phase!==`ready`)throw new Y(`channel_confirmation_failed`,`The Forge relay endpoint channel is not confirmed.`,!1);return e}async outboundFrame(e,t){return t===null?e:this.withDurableHeaders(t,e)}async withDurableHeaders(e,t){let n=this.journal.beginAttempt(e.runtimeId,e.actorSessionId,e.transportRequestId),r=JSON.parse(t),i=await wu({payload:Cu(e.method,r.payload),sequence:n.sequence,requestId:n.durableRequestId,issuedAt:new Date(n.updatedAt),crypto:this.relayCrypto}),a=Array.isArray(r.headers)?r.headers.filter(e=>!Hl(e)):[];return JSON.stringify({...r,headers:[...a,...Object.entries(i)]})}close(e,t){this.socket.close(e,t)}asWebSocket(){return this}emit(e,t){this.dispatchEvent(t);let n=this[`on${e}`];n&&n.call(this.asWebSocket(),t)}async handleMessage(e){if(this.authenticated){if(this.context?.protocolVersion===4){await this.handleEncryptedApplicationMessage(e.data);return}this.context!==null&&Jl(e.data,this.context,this.journal),this.emit(`message`,new MessageEvent(`message`,{data:e.data}));return}await this.handleAuthenticationMessage(e.data)}async handleMessageSafely(e){try{await this.handleMessage(e)}catch(e){let t=Bl(e);this.lifecycle.onError?.({code:t.code,message:t.message}),this.emit(`error`,Pl(t.code,t.message)),this.socket.readyState<WebSocket.CLOSING&&this.socket.close(4400,`${t.code}: ${t.message}`)}}async beginAuthentication(){try{this.route.protocolVersion===4&&(this.payloadChannel=await su(ou(this.route))),this.socket.send(JSON.stringify({type:`relay.auth`,ticket:this.route.token,protocolMinVersion:this.route.protocolVersion,protocolMaxVersion:this.route.protocolVersion,capabilities:kl,...this.payloadChannel?{controlToRuntimeEncapsulatedKey:this.payloadChannel.sender.encapsulatedKey}:{}}))}catch(e){let t=Bl(e);this.lifecycle.onError?.({code:t.code,message:t.message}),this.emit(`error`,Pl(t.code,t.message)),this.socket.close(4400,t.message)}}async handleAuthenticationMessage(e){let t=Kl(e);if(t!==null){if(t.type===`relay.encrypted-frame`&&this.context?.protocolVersion===4){await this.handleEncryptedHandshakeMessage(t);return}if(t.type===`relay.error`){this.lifecycle.onError?.({code:t.code,message:t.message}),this.emit(`error`,Pl(t.code,t.message)),this.socket.close(4403,t.message);return}t.type===`relay.authenticated`&&await this.handleAuthenticatedMessage(t)}}async handleAuthenticatedMessage(e){let t=ql(e,this.route.protocolVersion);if(t===void 0){this.socket.close(4400,`Forge relay authenticated the wrong role.`);return}if(t!==null&&t.protocolVersion===4){let n=ou(this.route),r=this.payloadChannel;if(r===null||![e.runtimeId===n.runtimeId,e.connectionEpoch===n.connectionEpoch].every(Boolean)){this.socket.close(4400,`Forge relay authenticated stale endpoint metadata.`);return}t={...t,channelId:n.channelId,channelTicketDigest:Uc(r.controlToRuntimeBinding),runtimeEndpointKeyId:n.runtimeEndpointKeyId,controlEndpointKeyId:n.controlEndpointKeyId},this.context=t;return}await this.activateAuthenticatedRelay(t)}async handleEncryptedHandshakeMessage(e){if(e.type!==`relay.encrypted-frame`)return;let t=this.payloadChannel,n=this.context,r=ou(this.route);if(t===null||n===null||!cu(e,r,`handshake`))throw new Y(`channel_confirmation_failed`,`The runtime sent an invalid encrypted handshake frame.`,!1);let i=await(await du({channel:t,route:r,message:e})).open(e),a=Dl(JSON.parse(new TextDecoder().decode(i))),o=t.phase===`awaiting-runtime-hello`?`runtime-hello`:`runtime-confirm`;if(!lu({confirmation:a,expectedPhase:o,route:r,context:n}))throw new Y(`channel_confirmation_failed`,`The runtime endpoint confirmation does not match the CMMD route.`,!1);if(o===`runtime-hello`){let e=await t.sender.seal({frameClass:`handshake`,plaintext:new TextEncoder().encode(JSON.stringify({type:`relay.endpoint-confirmation`,protocolVersion:4,phase:`control-confirm`,channelId:r.channelId,runtimeId:n.runtimeId,connectionEpoch:n.connectionEpoch}))});t.phase=`awaiting-runtime-confirm`,this.socket.send(JSON.stringify(e));return}t.phase=`ready`,await this.activateAuthenticatedRelay(n)}async handleEncryptedApplicationMessage(e){let t=Kl(e);if(t?.type!==`relay.encrypted-frame`)throw new Y(`end_to_end_encryption_required`,`The runtime sent plaintext after the encrypted channel was confirmed.`,!1);let n=this.requirePayloadChannel();if(!cu(t,ou(this.route),`application`)||t.encapsulatedKey!==void 0||n.recipient===null)throw new Y(`channel_authentication_failed`,`The runtime sent an invalid encrypted application frame.`,!1);let r=await n.recipient.open(t),i=Ol(JSON.parse(new TextDecoder().decode(r))),a=this.requireReadyContext();if(!uu({application:i,context:a,payloadHash:await this.relayCrypto.sha256Base64Url(i.payload)}))throw new Y(`channel_authentication_failed`,`The decrypted runtime envelope does not match the active route.`,!1);Jl(i.payload,a,this.journal),this.emit(`message`,new MessageEvent(`message`,{data:i.payload}))}async activateAuthenticatedRelay(e){this.context=e,this.authenticated=!0,this.lifecycle.onAuthenticated?.();let t=e===null?[]:this.replayForActor(e);for(let e of t)e.frame!==null&&this.enqueueFrame(e.frame,e);t.length>0&&await this.sendChain,this.emit(`open`,new Event(`open`))}replayForActor(e){return this.journal.fenceActor(e.runtimeId,e.actor.sessionId),this.journal.replayable(e.runtimeId,e.actor.sessionId)}};function pu(e,t,n=gu,r=wl({storage:Tl(),randomUUID:n.randomUUID}),i={},a){return new fu(e,t,n,r,i,a).asWebSocket()}var mu=Ui(qt);async function hu(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest(`SHA-256`,t);return btoa(String.fromCharCode(...new Uint8Array(n))).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replaceAll(`=`,``)}var gu={randomUUID:()=>crypto.randomUUID(),sha256Base64Url:hu},_u=`forge-relay-binding=`,vu=3e4;function yu(e){let t=new URL(String(e)).hash.slice(1);if(!t.startsWith(_u))throw Error(`Forge relay socket URL is missing its route binding.`);let n=decodeURIComponent(t.slice(20));if(n.length===0)throw Error(`Forge relay socket URL has an invalid route binding.`);return n}function bu(e){let t=e.crypto??gu,n=e.bindingTtlMs??vu,r=e.createSocket??((e,t)=>new globalThis.WebSocket(e,t)),i=new Map;return{acquireSocketUrl:async()=>{let r=await e.acquireRoute(),a=t.randomUUID();if(i.has(a))throw Error(`Forge relay route binding identifier was reused.`);let o=new URL(r.relayWebSocketUrl);o.hash=`${_u}${encodeURIComponent(a)}`;let s=setTimeout(()=>i.delete(a),n);return i.set(a,{route:r,expires:s}),o.toString()},constructSocket:(n,a)=>{let o=yu(n),s=i.get(o);if(s===void 0)throw Error(`Forge relay route binding is missing, expired, or already consumed.`);return i.delete(o),clearTimeout(s.expires),e.lifecycle?.onConnecting?.(),pu(r(s.route.relayWebSocketUrl,a),s.route,t,e.journal,e.lifecycle,e.acquireActionGrant)}}}var xu=new Map;function Su(e){let t=xu.get(e);if(t!==void 0)return t;let n=qt.requests.get(e);if(n===void 0)return null;let r=nn(n.payloadSchema);return xu.set(e,r),r}function Cu(e,t){let n=Su(e);if(n===null)return t;try{return n(t)}catch{return t}}async function wu(e){let t=e.issuedAt??new Date,n=e.crypto??gu;return{[Zt.requestId]:e.requestId??n.randomUUID(),[Zt.sequence]:String(e.sequence),[Zt.issuedAt]:t.toISOString(),[Zt.expiresAt]:new Date(t.getTime()+12e4).toISOString(),[Zt.payloadHash]:await n.sha256Base64Url(ra(e.payload))}}function Tu(e,t){return Vt(Ut,({rpc:t,request:n,next:r})=>i(function*(){return ha({method:t._tag,payload:n.payload,grantedScopes:e}),yield*r(n)}))}function Eu(e,t=gu){return mu.pipe(pe(Tu(e,t)))}function Du(e){let t=e.crypto??gu,n=bu({acquireRoute:e.acquireRoute,...e.acquireActionGrant?{acquireActionGrant:e.acquireActionGrant}:{},crypto:t,journal:e.journal,...e.lifecycle?{lifecycle:e.lifecycle}:{}}),i=he(n.acquireSocketUrl).pipe(_),a=xe(Qn,n.constructSocket),o=tr(i).pipe(tt(a)),s=e.delayForRetry??ta,c=de(Qe(e.maxRetries??10),e=>lt(T(s(e)??0)));return r(qi,Ji({retryPolicy:c,retryTransientErrors:!0})).pipe(tt(Ge(o,Ri)))}var Ou=class extends Error{name=`RelayControlRouteSecurityFailure`};async function ku(e){let t=await qc(e),n=await Jc(t.publicKey);return{keyPair:t,publicKey:n,keyId:Yc(`control`,n),channelNonce:await Wc(e)}}function Au(e){return{hpkeSuite:mc,controlEndpointKeyId:e.keyId,controlEndpointPublicKey:e.publicKey,controlChannelNonce:e.channelNonce}}function ju(e){let t=e.route;if(t.protocolVersion!==4||t.hpkeSuite!==`DHKEM_X25519_HKDF_SHA256/HKDF_SHA256/CHACHA20_POLY1305/AUTH`||!t.channelId||!t.runtimeEndpointKeyId||!t.runtimeEndpointPublicKey||t.controlEndpointKeyId!==e.endpoint.keyId||t.controlEndpointPublicKey!==e.endpoint.publicKey||t.controlChannelNonce!==e.endpoint.channelNonce)throw new Ou(`Forge could not establish a verified end-to-end encrypted runtime route.`);return{...t,runtimeId:e.runtimeId,protocolVersion:4,channelId:t.channelId,hpkeSuite:mc,runtimeEndpointKeyId:t.runtimeEndpointKeyId,runtimeEndpointPublicKey:t.runtimeEndpointPublicKey,controlEndpointKeyId:e.endpoint.keyId,controlEndpointPublicKey:e.endpoint.publicKey,controlChannelNonce:e.endpoint.channelNonce,controlEndpointKeyPair:e.endpoint.keyPair,...e.digestProvider?{payloadDigestProvider:e.digestProvider}:{},...e.randomSource?{payloadRandomSource:e.randomSource}:{}}}function Mu(e,t=Nt){return`${e}\0${t}`}function Nu(e){let t=new Map,n=!1;return{register(e){if(n)throw Error(`Terminal control sequencer is disposed.`);let r=Mu(e.threadId,e.terminalId);t.get(r)?.sessionEpoch!==e.sessionEpoch&&t.set(r,{sessionEpoch:e.sessionEpoch,nextControlSequence:1,tail:Promise.resolve(),pendingWriteBytes:0})},enqueue(r){if(n)return Promise.reject(Error(`Terminal control sequencer is disposed.`));let i=r.terminalId??`default`,a=t.get(Mu(r.threadId,i));if(!a)return Promise.reject(Error(`Terminal must be opened before sending controls.`));let o=r.writeBytes??0;if(a.pendingWriteBytes+o>e.maxPendingWriteBytes)return Promise.reject(Error(`Terminal input queue is full while reconnecting.`));a.pendingWriteBytes+=o;let s=a.tail.then(async()=>{let t=a.nextControlSequence;await r.execute({sessionEpoch:a.sessionEpoch,controllerId:e.controllerId,controlSequence:t}),a.nextControlSequence=t+1});return a.tail=s.finally(()=>{a.pendingWriteBytes-=o}).catch(()=>void 0),s},remove(e,n){if(n){t.delete(Mu(e,n));return}let r=`${e}\0`;for(let e of t.keys())e.startsWith(r)&&t.delete(e)},terminalIds(e){let n=`${e}\0`;return[...t.keys()].filter(e=>e.startsWith(n)).map(e=>e.slice(n.length))},dispose(){n=!0,t.clear()}}}nn(Gt);var Pu=[3e3,4e3,8e3,16e3],Fu=3e4;function Iu(e={}){let t=e.retryDelaysMs??Pu;if(t.length===0)throw Error(`retryDelaysMs must not be empty`);let n=e.maxRetries??null,r=e.backoffResetAfterMs??3e4,i=e.now??(()=>Date.now()),a={desired:!1,network:`online`,phase:`available`,attempt:0,generation:0,lastFailure:null,retryAtMs:null,retriesExhausted:!1,credentialsEpoch:0},o=new Set,s=null,c=0,l=e=>{a=e;for(let e of o)e(a);return a},u=()=>l({...a,phase:`connecting`,attempt:c+1,retryAtMs:null,credentialsEpoch:a.credentialsEpoch+1}),d=()=>t[Math.min(Math.max(c-1,0),t.length-1)]??0;return{getState:()=>a,connect:()=>a.desired?a:a.phase===`available`?l({...a,desired:!0,phase:`connecting`}):l({...a,desired:!0}),disconnect:()=>!a.desired&&a.phase===`available`?a:(c=0,s=null,l({...a,desired:!1,phase:`available`,attempt:0,lastFailure:null,retryAtMs:null,retriesExhausted:!1})),retryNow:()=>!a.desired&&a.phase===`available`?a:(c=0,l({...a,retryAtMs:null,retriesExhausted:!1})),setNetwork:e=>a.network===e?a:e===`offline`?(s=null,l({...a,network:e,phase:a.desired?`offline`:`available`,retryAtMs:null})):a.desired&&a.phase===`offline`?l({...a,network:e,phase:`connecting`}):l({...a,network:e}),attemptStarted:()=>u(),attemptConnected:()=>(s=i(),l({...a,phase:`connected`,generation:a.generation+1,lastFailure:null,retryAtMs:null,retriesExhausted:!1})),attemptFailed:e=>{let t=s===null?0:i()-s;s=null,t>=r&&(c=0);let o={...a,lastFailure:e};return e.kind===`blocked`?l({...o,phase:`blocked`,retryAtMs:null}):a.network===`offline`?l({...o,phase:`offline`,retryAtMs:null}):(c+=1,l(n!==null&&c>n?{...o,phase:`backoff`,retryAtMs:null,retriesExhausted:!0}:{...o,phase:`backoff`,retryAtMs:i()+d(),retriesExhausted:!1}))},subscribe:e=>(o.add(e),()=>o.delete(e))}}function Lu(e={}){let t=e.now??(()=>Date.now()),n={status:`ok`,detectedAtMs:null,source:null,reAuthInFlight:!1},r=new Set,i=e=>{n=e;for(let e of r)e(n);return n};return{getState:()=>n,reportAuthFailure:e=>n.status===`expired`?n:i({status:`expired`,detectedAtMs:t(),source:e,reAuthInFlight:n.reAuthInFlight}),clearAuthFailure:()=>i({status:`ok`,detectedAtMs:null,source:null,reAuthInFlight:n.reAuthInFlight}),beginReAuth:()=>!n.reAuthInFlight&&(i({...n,reAuthInFlight:!0}),!0),endReAuth:()=>{n.reAuthInFlight&&i({...n,reAuthInFlight:!1})},subscribe:e=>(r.add(e),()=>r.delete(e))}}function Ru(e){return!e.isWebSurface||e.failureStatus!==`expired`?{kind:`none`}:e.isAuthExemptPath?{kind:`clear-failure`}:{kind:`navigate-login`}}var zu=new Set([`localhost`,`127.0.0.1`,`::1`]);function Bu(e){return e.trim().toLowerCase().replace(/^\[(.*)\]$/,`$1`)}function Vu(e){let t=Bu(e);return zu.has(t)||t.endsWith(`.localhost`)}function Hu(e){try{return Vu(new URL(e).hostname)}catch{return!1}}function Uu(e){let t=e.split(`.`).map(e=>Number(e));if(t.length!==4||t.some(e=>!Number.isInteger(e)||e<0||e>255))return!1;let[n,r]=t;return n===10||n===172&&r>=16&&r<=31||n===192&&r===168}var Wu=`/api/dev/local-web/bootstrap`,Gu=3e3,Ku=null,qu=null,Ju=null;function Yu(){return Ju!==null&&Date.now()-Ju<Gu}function Xu(e){try{return nn(Bt)(e)}catch{return null}}function Zu(){return!1}function Qu(){return typeof window>`u`?null:window.desktopBridge?.getLocalEnvironmentBootstrap()??Ku}async function $u(){if(!Zu()||window.desktopBridge)return Ku=null,Qu();let e;try{e=await fetch(new URL(Wu,window.location.origin),{credentials:`include`})}catch{return Ku=null,Ju=Date.now(),null}if(e.status===204||e.status===404||!e.ok)return Ku=null,Ju=Date.now(),null;let t=Xu(await e.json().catch(()=>null));return Ku=t,Ju=null,t}async function ed(){let e=typeof window>`u`?null:window.desktopBridge?.getLocalEnvironmentBootstrap();return e?(Ku=null,e):Ku||(Yu()?null:qu||(qu=$u().finally(()=>{qu=null}),qu))}function td(){return Qu()}var nd=`forge_backend_mode`,rd=`forge_apex_url`;function id(){return td()}function ad(e){return new URL(e,window.location.origin).toString()}function od(e,t){let n=new URL(e);return`${n.pathname.endsWith(`/`)?n.pathname.slice(0,-1):n.pathname}${t.startsWith(`/`)?t:`/${t}`}`}function sd(e){let t;try{t=new URL(window.location.href)}catch{return e}let n=new URL(e);return(t.protocol===`http:`||t.protocol===`https:`)&&t.port!==``&&n.port!==``&&t.origin!==n.origin&&Vu(t.hostname)&&Vu(n.hostname),e}function cd(){return null}function ld(){let e=ad(window.location.origin),t=new URL(e);if(t.protocol===`http:`)t.protocol=`ws:`;else if(t.protocol===`https:`)t.protocol=`wss:`;else throw Error(`Unsupported HTTP base URL protocol: ${t.protocol}`);return t.pathname=`/ws`,{source:`window-origin`,target:{httpBaseUrl:e,wsBaseUrl:t.toString()}}}function ud(){try{if(localStorage.getItem(nd)!==`apex`)return null;let e=localStorage.getItem(rd)?.trim()??void 0??``;if(!e)return null;let t=ad(e),n=new URL(t);return n.protocol=t.startsWith(`https:`)?`wss:`:`ws:`,{source:`configured`,target:{httpBaseUrl:t,wsBaseUrl:n.toString()}}}catch{return null}}function dd(){let e=id();return!e||e.primaryMode!==`cloud`||!e.bearerToken?null:{source:`paired-bearer`,target:{httpBaseUrl:ad(e.httpBaseUrl),wsBaseUrl:ad(e.wsBaseUrl)},bearerToken:e.bearerToken}}function fd(){let e=id();if(!e||e.primaryMode===`cloud`||!e.httpBaseUrl&&!e.wsBaseUrl)return null;if(!e.httpBaseUrl||!e.wsBaseUrl)throw Error(`Desktop bootstrap must provide both httpBaseUrl and wsBaseUrl for the local environment.`);return{source:`desktop-managed`,target:{httpBaseUrl:ad(e.httpBaseUrl),wsBaseUrl:ad(e.wsBaseUrl)},...e.bearerToken?{bearerToken:e.bearerToken}:{}}}function pd(e,t){let n=md();if(!n)throw Error(`Unable to resolve the primary environment HTTP base URL.`);let r=new URL(sd(n.target.httpBaseUrl));return r.pathname=od(r.toString(),e),t&&(r.search=new URLSearchParams(t).toString()),r.toString()}function md(){return dd()??ud()??fd()??cd()??ld()}function hd(e={}){let t=md(),n=t?.bearerToken;return!t||!n||!gd(t)?e:{...e,credentials:`omit`,headers:{...e.headers,Authorization:`Bearer ${n}`}}}function gd(e){if(e.source!==`desktop-managed`||typeof window>`u`)return!0;try{return new URL(sd(e.target.httpBaseUrl)).origin!==window.location.origin}catch{return!0}}async function _d(e,t){return await e.text()||t}async function vd(){let e=pd(`/api/auth/logout`),t=await fetch(e,hd({credentials:`include`,method:`POST`}));if(!t.ok)throw Error(await _d(t,`Failed to logout authenticated session (${t.status}).`))}var yd=10,bd=yd+1,xd=Object.freeze({attemptCount:0,closeCode:null,closeReason:null,connectedAt:null,disconnectedAt:null,hasConnected:!1,lastError:null,lastErrorAt:null,nextRetryAt:null,online:typeof navigator>`u`||navigator.onLine!==!1,phase:`idle`,reconnectAttemptCount:0,reconnectMaxAttempts:bd,reconnectPhase:`idle`,socketUrl:null}),Sd=St(xd).pipe(bt,vt(`ws-connection-status`)),Cd=Array.from({length:yd},(e,t)=>ta(t)??0);function wd(){return{connection:Iu({retryDelaysMs:Cd,maxRetries:yd,backoffResetAfterMs:Fu}),cloudAuth:Lu()}}var Td=wd(),Ed=Object.freeze({status:`ok`}),Dd=St(Ed).pipe(bt,vt(`cloud-auth-failure`));function Od(e){let t=Td.cloudAuth.reportAuthFailure(e);yt.set(Dd,Ad(t))}function kd(){Td.cloudAuth.clearAuthFailure(),yt.set(Dd,Ed)}function Ad(e){return e.status!==`expired`||e.detectedAtMs===null?Ed:{status:`expired`,detectedAt:new Date(e.detectedAtMs).toISOString(),source:e.source??`http`}}function jd(){return yt.get(Dd)}function Md(){return Td.cloudAuth.beginReAuth()}function Nd(){Td.cloudAuth.endReAuth()}function Pd(){return new Date().toISOString()}function Fd(e){let t=e(Id());return yt.set(Sd,t),t}function Id(){return yt.get(Sd)}function Ld(e){return e.phase===`connected`||e.hasConnected&&e.disconnectedAt===null&&e.phase===`connecting`?`connected`:!e.online&&(e.disconnectedAt!==null||e.phase===`disconnected`)?`offline`:e.hasConnected?`reconnecting`:e.phase===`disconnected`?`error`:`connecting`}var Rd=!1;function zd(e){Td.connection.getState().desired||Td.connection.connect(),Rd=!1;let t=Td.connection.attemptStarted();return Fd(n=>({...n,attemptCount:n.attemptCount+1,nextRetryAt:null,phase:`connecting`,reconnectAttemptCount:t.attempt,reconnectPhase:`attempting`,socketUrl:e}))}function Bd(){return Rd=!1,Td.connection.attemptConnected(),Fd(e=>({...e,closeCode:null,closeReason:null,connectedAt:Pd(),disconnectedAt:null,hasConnected:!0,nextRetryAt:null,phase:`connected`,reconnectAttemptCount:0,reconnectPhase:`idle`}))}function Vd(e){return Rd||(Rd=!0,Td.connection.attemptFailed({kind:`transient`,message:e?.trim()?e:`Unable to connect to the Forge server WebSocket.`})),Fd(t=>Jd(t,{lastError:e?.trim()?e:t.lastError,lastErrorAt:Pd()}))}function Hd(e){return Id().hasConnected&&Ud(e)?Id():(Rd||(Rd=!0,Td.connection.attemptFailed({kind:`transient`,message:e?.reason?.trim()||`WebSocket connection closed.`})),Fd(t=>Jd(t,{closeCode:e?.code??t.closeCode,closeReason:e?.reason?.trim()?e.reason:t.closeReason})))}function Ud(e){return(e?.reason?.trim()??``).length===0&&(e?.code===1e3||e?.code===1001)}function Wd(e){return Td.connection.setNetwork(e?`online`:`offline`),Fd(t=>({...t,online:e}))}function Gd(){return Td.connection.retryNow(),Fd(e=>({...e,nextRetryAt:null,reconnectAttemptCount:0,reconnectPhase:`idle`}))}function Kd(){return Tn(Sd)}function qd(e){return ta(e)}function Jd(e,t){let n=Td.connection.getState(),r=e.disconnectedAt??Pd();return{...e,...t,disconnectedAt:r,nextRetryAt:n.retryAtMs===null?null:new Date(n.retryAtMs).toISOString(),phase:`disconnected`,reconnectPhase:n.retriesExhausted?`exhausted`:`waiting`}}var Yd=class extends Error{constructor(e=`Session has expired. Please re-login.`){super(e),this.name=`ForgeAuthExpiredError`}};function Xd(e){return e instanceof Yd||e instanceof Error&&e.name===`ForgeAuthExpiredError`}var Zd=`forge_auth_expired_reason`,Qd=`session-expired`,$d=`reason`,ef=`cmmd-auth-expired`,tf={"session-expired":`Session has expired. Please re-login.`,"desktop-session-required":`Forge Desktop needs a CMMD sign-in before this device can host or control runtimes.`,"desktop-principal-mismatch":`Forge Desktop and the local Forge session are signed in to different CMMD accounts. Sign in again to reconcile them.`,"desktop-state-unavailable":`Forge Desktop could not verify its native CMMD session. Restart Forge or sign in again.`};function nf(e){if(!(e===null||!(e in tf)))return tf[e]}function rf(e){if(!(typeof window>`u`))try{window.sessionStorage.setItem(Zd,e)}catch{}}function af(){if(typeof window>`u`)return null;try{return new URL(window.location.href).searchParams.getAll($d).includes(ef)?Qd:null}catch{return null}}function of(){if(!(typeof window>`u`))try{let e=new URL(window.location.href),t=e.searchParams.getAll($d);if(!t.includes(ef))return;e.searchParams.delete($d);for(let n of t)n!==ef&&e.searchParams.append($d,n);window.history.replaceState({},typeof document>`u`?``:document.title,e.toString())}catch{}}function sf(){let e=af();return e!==null&&of(),e}function cf(){if(!(typeof window>`u`)){try{window.sessionStorage.removeItem(Zd)}catch{}of()}}function lf(){if(typeof window>`u`)return null;try{let e=window.sessionStorage.getItem(Zd);return of(),e}catch{return of(),null}}function uf(){if(typeof window>`u`)return null;try{let e=window.sessionStorage.getItem(Zd);return e===null?sf():(window.sessionStorage.removeItem(Zd),of(),e)}catch{return sf()}}async function df(){try{let e=pd(`/api/auth/session/renew`);return e.startsWith(`https://`)?(await fetch(e,{credentials:`include`,method:`POST`})).ok:!1}catch{return!1}}async function ff(){if(await df()){kd(),window.location.reload();return}await vd().catch(()=>void 0),kd(),rf(`session-expired`);let e=new URL(pd(`/login`)),t=_n()?gn(e.toString()):e.toString();window.location.assign(t)}var pf=e({handleCmmdAuthExpired:()=>hf}),mf=null;async function hf(e){if((e===void 0||e===401)&&!(typeof window>`u`)){if(mf)return mf;if(Md())return mf=ff().finally(()=>{Nd(),mf=null}),mf}}export{tr as $,hd as A,Ou as B,Vd as C,Od as D,Wd as E,Vu as F,Eu as G,Au as H,Hu as I,qi as J,wl as K,Uu as L,pd as M,td as N,Kd as O,ed as P,Qn as Q,Ru as R,Hd as S,Gd as T,ju as U,ku as V,Du as W,Ji as X,Ui as Y,Ri as Z,jd as _,cf as a,qd as b,ff as c,rf as d,En as et,uf as f,Dd as g,kd as h,Yd as i,md as j,vd as k,df as l,yd as m,hf as n,Xd as o,bd as p,Cl as q,Zd as r,lf as s,pf as t,Tn as tt,nf as u,Id as v,Bd as w,zd as x,Ld as y,Nu as z};
3
+ //# sourceMappingURL=cmmdAuthRedirect-CHlAAdAc.js.map
@@ -0,0 +1,2 @@
1
+ function e(){try{sessionStorage.setItem(`cmmd-forge-embed-mode`,`1`)}catch{}typeof document<`u`&&(document.documentElement.dataset.cmmdEmbed=`1`)}function t(t=typeof window<`u`?window.location.search:``){if(new URLSearchParams(t.startsWith(`?`)?t.slice(1):t).get(`embed`)===`1`)return typeof window<`u`&&e(),!0;if(typeof window>`u`)return!1;try{return sessionStorage.getItem(`cmmd-forge-embed-mode`)===`1`&&(document.documentElement.dataset.cmmdEmbed=`1`,!0)}catch{return!1}}function n(e=typeof window<`u`?window.location.search:``){return t(e)}function r(e){let t=new URL(e,typeof window<`u`?window.location.origin:`http://localhost`);return t.searchParams.set(`embed`,`1`),`${t.pathname}${t.search}${t.hash}`}export{r as i,t as n,e as r,n as t};
2
+ //# sourceMappingURL=cmmdEmbedMode-DhVvltxi.js.map
@@ -0,0 +1,2 @@
1
+ import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{Ha as n}from"./Effect-CyyMOw4X.js";import{S as r,b as i,i as a,n as o,o as s,r as c,y as l}from"./activeOrganizationId-CySrJzMX.js";import{n as ee}from"./cmmdEmbedMode-DhVvltxi.js";var u=t(n(),1),d=`forge:cmmd-work-intake-cache:v1`,f=`forge:cmmd-work-intake-eviction:v1`,p=`forge:cmmd-work-intake-project-eviction:v1:`,m=1,h=1;function g(){if(typeof window>`u`)return null;try{return window.localStorage}catch{return null}}function te(e){return typeof e==`object`&&!!e}function _(e){return e==null||typeof e==`string`}function v(e){if(!e)return null;try{let t=JSON.parse(e);return t.version!==m||typeof t.cachedAt!=`string`||!te(t.intake)||!_(t.evictionGeneration)?null:t}catch{return null}}function ne(e){let t=Array.isArray(e.projectIds)?e.projectIds.filter(e=>typeof e==`string`&&e.length>0):[],n=e.projectId,r=t.length===0&&typeof n==`string`&&n.length>0?[n]:t;return[...new Set(r)]}function y(e){if(!e)return null;try{let t=JSON.parse(e);if(t.version!==h||typeof t.generation!=`string`||t.generation.length===0)return null;let n=ne(t);return n.length===0?null:{version:h,generation:t.generation,projectIds:[...new Set(n)]}}catch{return null}}function b(e){return`${p}${encodeURIComponent(e)}`}function x(e){if(!e)return null;try{let t=JSON.parse(e);return t.version!==h||typeof t.generation!=`string`||t.generation.length===0||typeof t.projectId!=`string`||t.projectId.length===0?null:t}catch{return null}}function re(e,t){if(e===d&&t===null)return{kind:`cache_removed`};if(e===`forge:cmmd-work-intake-eviction:v1`){let e=y(t);return e?{kind:`projects_removed`,projectIds:e.projectIds}:{kind:`malformed`}}if(e?.startsWith(`forge:cmmd-work-intake-project-eviction:v1:`)){let e=x(t);return e?{kind:`projects_removed`,projectIds:[e.projectId]}:{kind:`malformed`}}return{kind:`unrelated`}}function S(e){let t=new Set(y(e.getItem(`forge:cmmd-work-intake-eviction:v1`))?.projectIds??[]);if(typeof e.length==`number`&&typeof e.key==`function`)for(let n=0;n<e.length;n+=1){let r=e.key(n);if(!r?.startsWith(`forge:cmmd-work-intake-project-eviction:v1:`))continue;let i=x(e.getItem(r));i&&t.add(i.projectId)}return[...t].toSorted()}function C(e,t=g()){if(!t)return e;try{let n=new Set(S(t));return n.size===0?e:{...e,projects:e.projects.filter(e=>!n.has(e.id)),tasks:e.tasks.filter(e=>e.projectId===null||!n.has(e.projectId))}}catch{return e}}function w(e=g()){if(!e)return null;try{let t=y(e.getItem(f)),n=S(e);return!t&&n.length===0?null:`${t?.generation??`project-tombstones`}:${n.join(`,`)}`}catch{return null}}function ie(e,t=g()){if(!(!t||e.length===0))try{let n=new Set(e),r=S(t).filter(e=>!n.has(e));for(let e of n)t.removeItem(b(e));r.length===0?t.removeItem(f):t.setItem(f,JSON.stringify({version:h,generation:T(),projectIds:r}))}catch{}}function T(){return typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function ae(e=Date.now(),t=g()){if(!t)return{state:`missing`,record:null};let n=v(t.getItem(d));if(!n||(n.evictionGeneration??null)!==w(t))return{state:`missing`,record:null};let r={...n,intake:C(n.intake,t)},i=Date.parse(r.cachedAt);if(!Number.isFinite(i))return{state:`expired`,record:null};let a=Math.max(0,e-i);return a<=12e4?{state:`fresh`,record:r}:a<=3e5?{state:`stale`,record:r}:{state:`expired`,record:null}}function E(e,t,n=new Date,r=g()){if(!r||w(r)!==t)return!1;let i={version:m,cachedAt:n.toISOString(),intake:C(e,r),evictionGeneration:t};try{return r.setItem(d,JSON.stringify(i)),w(r)===t||(r.removeItem(d),!1)}catch{return!1}}function oe(e,t=g()){if(t)try{let n=S(t),r={version:h,generation:T(),projectId:e};for(let e of n){let n=b(e);t.getItem(n)||t.setItem(n,JSON.stringify({version:h,generation:T(),projectId:e}))}t.setItem(b(e),JSON.stringify(r));let i={version:h,generation:T(),projectIds:S(t)};t.setItem(f,JSON.stringify(i));let a=w(t),o=v(t.getItem(d));if(!o)return;t.setItem(d,JSON.stringify({...o,evictionGeneration:a,intake:C(o.intake,t)})),w(t)!==a&&t.removeItem(d)}catch{try{t.removeItem(d)}catch{}}}var D={connected:!1,isLoading:!1,error:null,source:null,fetchedAt:null,workspace:null,identity:null,campaigns:[],projects:[],tasks:[],workspaces:[],refetchRequestedAt:null,authoritativeRefetchRequested:!1},O=D,k=0,A=new Set;function j(e){O=e;for(let e of A)e()}function M(e){j(e(O))}function N(e){j({connected:e.connected,isLoading:!1,error:null,source:e.source,fetchedAt:e.fetchedAt,workspace:e.workspace,identity:e.identity,campaigns:e.campaigns,projects:e.projects,tasks:e.tasks,workspaces:e.workspaces,refetchRequestedAt:O.refetchRequestedAt,authoritativeRefetchRequested:O.authoritativeRefetchRequested??!1})}function P(e){return A.add(e),()=>A.delete(e)}function F(){return O}function se(){return(0,u.useSyncExternalStore)(P,F,F)}var I={clear(){k+=1,j(D)},beginDataRequest(){return k+=1,k},isDataVersionCurrent(e){return k===e},requestRefetch(e={}){M(t=>({...t,refetchRequestedAt:Math.max(Date.now(),(t.refetchRequestedAt??0)+1),authoritativeRefetchRequested:e.authoritative===!0}))},setBackgroundRefreshError(e){M(t=>({...t,error:e,isLoading:!1}))},setData(e){N(e)},setDataIfCurrent(e,t){return k===t&&(N(e),!0)},setError(e){j({...D,error:e})},setLoading(e){M(t=>({...t,isLoading:e,error:null}))},patchTask(e,t){M(n=>({...n,tasks:n.tasks.map(n=>n.id===e?{...n,...t}:n)}))},patchTasks(e,t){if(e.length===0)return;let n=new Set(e);M(e=>({...e,tasks:e.tasks.map(e=>n.has(e.id)?{...e,...t}:e)}))},replaceTasks(e){M(t=>({...t,tasks:e}))},patchProject(e,t){M(n=>({...n,projects:n.projects.map(n=>n.id===e?{...n,...t}:n)}))},removeProject(e){k+=1,oe(e),M(t=>({...t,projects:t.projects.filter(t=>t.id!==e),tasks:t.tasks.filter(t=>t.projectId!==e)}))},applyExternalProjectRemovals(e){k+=1;let t=new Set(e);M(e=>({...e,projects:e.projects.filter(e=>!t.has(e.id)),tasks:e.tasks.filter(e=>e.projectId===null||!t.has(e.projectId))}))}},L=`forge:command-center:workspace-filter`,R=`forge:command-center:workspace-filter-updated`;function z(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function ce(){return z(l(L))}function B(e){if(typeof window>`u`)return;let t=z(e);t===null?i(L):r(L,t),window.dispatchEvent(new CustomEvent(R,{detail:{workspaceId:t}}))}function V(e){if(typeof window>`u`)return()=>{};let t=t=>{t.key===L&&e(z(t.newValue))},n=t=>{e(z(t.detail?.workspaceId??null))};return window.addEventListener(`storage`,t),window.addEventListener(R,n),()=>{window.removeEventListener(`storage`,t),window.removeEventListener(R,n)}}var H=e({getCurrentForgeWorkspaceId:()=>X,seedCurrentForgeWorkspaceId:()=>Z,switchCurrentForgeWorkspaceId:()=>Q,useCurrentForgeWorkspaceState:()=>$}),U=`forge:current-workspace-id`;function W(){let e=l(U);if(e===null||!/^\d+$/.test(e))return null;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)&&t>0?t:null}var G=W();o(G);var K={workspaceId:G,switchGeneration:0},q=new Set;function J(e){K=e,o(e.workspaceId);for(let e of q)e()}function Y(){return K}function X(){return K.workspaceId}function le(e){return q.add(e),()=>q.delete(e)}function Z(e){if(K.workspaceId===e)return;let t=K.workspaceId!==null;o(e),r(U,String(e)),t&&(s(),c()),a(),J({...K,workspaceId:e})}function Q(e){ee()||K.workspaceId!==e&&(o(e),r(U,String(e)),s(),c(),a(),B(null),J({workspaceId:e,switchGeneration:K.switchGeneration+1}),I.requestRefetch({authoritative:!0}))}function $(){return(0,u.useSyncExternalStore)(le,Y,Y)}export{E as _,$ as a,B as c,P as d,se as f,w as g,ae as h,Q as i,I as l,re as m,X as n,ce as o,ie as p,Z as r,V as s,H as t,F as u};
2
+ //# sourceMappingURL=currentForgeWorkspaceStore-eKCBxKgv.js.map