Release of @iterate-com/ui from 2000e8b7d01972d0bcb917c138e2b325681aef99
ui release builder, 2026-11-27 10:55 UTC · a1c8702642f0ee5ae24efd64ed554dccf0ba1728 · parent 7c5080e
7 files changed
- M dist/chunks/react.mjs
- M dist/components/docs-editor/docs-editor.mjs
- M dist/components/integrations-page.mjs
- M dist/components/repo-ide/repo-ide.mjs
- M dist/live.mjs
- M files.json
- M release.json
M dist/chunks/react.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t}from"./vendor-react";import{_ as n,d as r,f as i,h as a,l as o,r as s,t as c,v as l}from"./vendor-zod";import{a as u,t as d}from"./lib.mjs";var f=/* @__PURE__ */ e(t(),1);const p=i({type:o(`events.iterate.com/itx/created`),payload:i({version:r()})});function m(e){let t=p.safeParse(e);return t.success?t.data.payload.version:void 0}const h=[`events.iterate.com/itx/started-over`,`events.iterate.com/itx/version-ended`],g=i({type:c(h),payload:i({version:r()})});function _(e){let t=g.safeParse(e);return t.success?t.data.payload.version:void 0}const v=i({data:i({retryAfterMs:r()})});async function y(e,t){for(let n=1;;n+=1)try{return await e()}catch(e){if(u(e)!==`UNAVAILABLE`||n>=30)throw e;let r=v.safeParse(e);if(await new Promise(e=>setTimeout(e,r.success?r.data.data.retryAfterMs:1e3)),t())return}}const b={events:[],caughtUp:!1,head:0,older:{loading:!1,exhausted:!1},actors:[],tableVersion:0,version:1},x=1e3;function S(e,t){let n=!1,r,i,a=/* @__PURE__ */ new Set,o=b,s=/* @__PURE__ */ new Set,c=[],l=[],u=!1,d,f=0,p=0,h=0,g=1,v=0,S=!1,w=0,T=/* @__PURE__ */ new Map,E=[],D=!1,O=!1,k=()=>Math.max(0,h-1),A=!1,j=e=>{A||(A=!0,g=e.version??1,h=e.versionStartedAtOffset??0)},M=()=>{O||n||(O=!0,typeof requestAnimationFrame==`function`?requestAnimationFrame(N):setTimeout(N,16))},N=()=>{if(O=!1,n)return;let e=[];for(let t of l){if(s.has(t.offset))continue;s.add(t.offset),e.push(t),t.offset>f&&(f=t.offset),t.type.startsWith(`events.iterate.com/itx/subscription-`)&&(w=Math.max(w,t.offset));let n=t.source?.principal,r=n&&T.get(n.actor);n&&(!r||r.offset<t.offset)&&(T.set(n.actor,{actor:n.actor,email:n.email,grant:t.source?.grant,lastSeenAt:t.createdAt,offset:t.offset}),D=!0)}l=[],e.length>0&&(e.sort((e,t)=>e.offset-t.offset),c=c.length===0||e[0].offset>c.at(-1).offset?c.concat(e):e.at(-1).offset<c[0].offset?e.concat(c):c.concat(e).sort((e,t)=>e.offset-t.offset)),D&&(D=!1,E=[...T.values()].map(({offset:e,...t})=>t).sort((e,t)=>t.lastSeenAt.localeCompare(e.lastSeenAt))),o={events:c,caughtUp:u,error:d,head:f,older:{loading:S||!u&&!d,exhausted:u&&p<=k()},actors:E,tableVersion:w,version:g,subscription:i};for(let e of a)e()},P=(e,t=!1)=>{for(let n of e){if(n.type===`events.iterate.com/itx/created`){let e=m(n);e!==void 0&&(e>g||t)&&z(n.offset,e)}n.offset>=h&&l.push(n)}M()},F=e=>{n||(d=e instanceof Error?e.message:String(e),M())},I=(t,r,i)=>y(()=>e.readEvents(t,r),()=>n||v!==i),L=async()=>{let a=v,o=g,s=await y(()=>e.subscribe({consumes:t.consumes,target:e=>{if(n||v!==a)return;let t=C(e);P(t,t.some(e=>(_(e)??0)>=o))}}),()=>n||v!==a);return s?n||v!==a?(s[Symbol.dispose](),!1):(r=s,Promise.resolve(s.name).then(e=>{!n&&v===a&&e&&(i=e,M())},()=>void 0),!0):!1},R=async(e,t)=>{let r=v,i=0;for(;;){let a=await I(e,Math.min(x,t-e),r);if(!a||n||v!==r)return i;j(a);let o=C(a.events).filter(e=>e.offset<=t);if(P(o),i+=o.length,a.atHead||a.scannedThroughOffset>=t||a.scannedThroughOffset<=e)return i;e=a.scannedThroughOffset}},z=(e,t)=>{v+=1,A=!0,g=t,h=e,p=e-1,u=!1,w=Math.max(w,e),c=c.filter(t=>t.offset>=e),l=l.filter(t=>t.offset>=e);for(let t of s)t<e&&s.delete(t);for(let[t,n]of T)n.offset<e&&(T.delete(t),D=!0);i=void 0;let a=r;r=void 0;try{a?.[Symbol.dispose]()}catch{}M(),(async()=>{if(!await L())return;let t=v;await R(e-1,1/0),!(n||v!==t)&&(u=!0,M())})().catch(F)};return(async()=>{if(!await L())return;let e=v;if(t.history===`tail`){let r=await I(2**53-1,1,e);if(!r||n||v!==e)return;j(r),p=k(),f=Math.max(f,r.scannedThroughOffset);let i=Math.max(k(),r.scannedThroughOffset-x),{since:a}=t;p=typeof a==`number`&&Number.isSafeInteger(a)&&a>i&&a<=r.scannedThroughOffset?a-1:i}await R(p,1/0),!(n||v!==e)&&(u=!0,M())})().catch(F),{get:()=>o,subscribe(e){return a.add(e),()=>a.delete(e)},loadOlder(){if(n||!u||S||p<=k())return;S=!0,M();let e=v;(async()=>{let t=x,r=0;for(;p>k()&&r<x/4;){let i=Math.max(k(),p-t);if(r+=await R(i,p),n||v!==e)return;p=i,t=Math.min(t*2,16*x)}})().catch(F).finally(()=>{S=!1,M()})},dispose(){n=!0,a.clear(),r?.[Symbol.dispose]()}}}function C(e){return JSON.parse(JSON.stringify(e)).filter(e=>e&&typeof e.offset==`number`&&typeof e.type==`string`&&typeof e.createdAt==`string`)}const w=i({key:a(),from:r(),to:r(),patch:s(n([i({op:o(`add`),path:a(),value:l()}),i({op:o(`replace`),path:a(),value:l()}),i({op:o(`remove`),path:a()})])).nullable()});function T(){let e={rev:null,state:void 0},t=/* @__PURE__ */ new Set,n=()=>t.forEach(e=>e());return{get:()=>e.state,rev:()=>e.rev,subscribe:e=>(t.add(e),()=>void t.delete(e)),seed:t=>{e.rev!==null&&t.rev<e.rev||(e={rev:t.rev,state:t.state},n())},clear:()=>{e={rev:null,state:void 0},n()},apply:(t,r)=>{if(!(e.rev!==null&&t.to<=e.rev)){if(t.from!==e.rev||!t.patch){r();return}e={rev:t.to,state:d(e.state,t.patch)},n()}}}}async function E(e,t){let n=T(),r=!1,i=!1,a=!1,o,s=0,c=()=>{if(a)return;if(r){i=!0;return}r=!0;let e=s,o=()=>{r=!1,!a&&i&&(i=!1,c())};t.readSeed().then(r=>{!a&&s===e&&(n.seed(r),t.onResync?.(`healed`)),o()},r=>{!a&&s===e&&(u(r)===`NO_FACET`&&n.clear(),t.onResync?.(r instanceof Error?r:Error(String(r)))),o()})},l=(e,r)=>{if(!(a||s!==e))for(let e of r){let r;try{r=JSON.parse(JSON.stringify(e))}catch{r=void 0}let i=m(r);if(i!==void 0&&i>1){f();return}if(O.safeParse(r).success)continue;let a=D.safeParse(r);if(!a.success){c();continue}if(a.data.payload.key===t.key)try{n.apply(a.data.payload,c)}catch{c()}}},d=async()=>{let n=s,r=await y(()=>e.subscribe({name:t.name,consumes:[`events.iterate.com/itx/live-state-changed`,`events.iterate.com/itx/created`],target:e=>l(n,e)}),()=>a||s!==n);return r?a||s!==n?(k(r),!1):(o=r,!0):!1},f=()=>{s+=1;let e=o;o=void 0,k(e),n.clear(),d().then(e=>e&&c(),e=>!a&&t.onResync?.(e instanceof Error?e:Error(String(e))))};await d();try{let e=t.readSeed(),{signal:r}=t,i=r&&new Promise((e,t)=>{let n=()=>t(r.reason??/* @__PURE__ */ Error(`connectLiveState: aborted while the first seed was pending`));r.aborted?n():r.addEventListener(`abort`,n,{once:!0})});i&&e.catch(()=>void 0);let a=await(i?Promise.race([e,i]):e);s===0&&n.seed(a)}catch(e){throw a=!0,k(o),e}return{store:n,async dispose(){a||(a=!0,k(o))}}}const D=i({payload:w}),O=i({type:c([...h,`events.iterate.com/itx/created`])});function k(e){try{e?.[Symbol.dispose]()}catch{}}function A(e,t){let[n,r]=(0,f.useState)(),[i,a]=(0,f.useState)(`connecting`),[o,s]=(0,f.useState)(),c=(0,f.useRef)(t.readSeed);c.current=t.readSeed,(0,f.useEffect)(()=>{if(r(void 0),a(`connecting`),s(void 0),!e)return;let n=c.current,i=!1,o,l=new AbortController;return E(e,{key:t.key,name:t.name,readSeed:n,signal:l.signal,onResync:e=>{i||(e===`healed`?(a(`live`),s(void 0)):(a(`error`),s(e.message)))}}).then(e=>{if(o=e.dispose,i){e.dispose();return}r(e.store),a(`live`)},e=>{i||(s(e instanceof Error?e.message:String(e)),a(`error`))}),()=>{i=!0,l.abort(),o?.()}},[e,t.key,t.name]);let l=(0,f.useCallback)(e=>n?n.subscribe(e):()=>{},[n]),u=(0,f.useSyncExternalStore)(l,()=>n?.get(),()=>void 0);if(!n&&t.initial)return{value:t.initial.state,rev:t.initial.rev,status:i,error:o};let d=n?.rev()??null;return{value:u,rev:d,status:i===`live`&&d===null?`connecting`:i,error:o}}function j(e,t,n){return A(e,{key:t,readSeed:async()=>P.parse(await e.invoke(N(t))),initial:n})}async function M(e,t){return P.parse(await e.invoke(N(t)))}const N=e=>`itx.facets.get('${e}').liveSnapshot()`,P=i({rev:r(),state:l()});function F(e,t){let[n,r]=(0,f.useState)(()=>({pending:!!e}));return(0,f.useEffect)(()=>{if(!e){r({pending:!1});return}r(e=>e.pending&&!e.stub?e:{pending:!0});let t=!1,n;return e().then(e=>{if(t)return e[Symbol.dispose]();n=e,r({stub:e,pending:!1})},e=>!t&&r({error:e instanceof Error?e.message:String(e),pending:!1})),()=>{t=!0,n?.[Symbol.dispose]()}},t),n}const I={value:void 0,rev:null,status:`connecting`};function L(e,t={}){let[n,r]=(0,f.useState)(),i=JSON.stringify(t.consumes||[`*`]),a=t.history||`tail`,o=(0,f.useRef)(t.since);(0,f.useEffect)(()=>{o.current=t.since}),(0,f.useEffect)(()=>{if(r(void 0),!e)return;let t=S(e,{consumes:JSON.parse(i),history:a,since:o.current});return r({itx:e,connection:t}),()=>t.dispose()},[e,i,a]);let s=e&&n?.itx===e?n.connection:void 0,c=(0,f.useCallback)(e=>s?s.subscribe(e):()=>{},[s]),l=(0,f.useSyncExternalStore)(c,()=>s?.get()??b,()=>b),{events:u,caughtUp:d,head:p,tableVersion:m,version:h}=l,g=(0,f.useCallback)(()=>s?.loadOlder(),[s]),_=(0,f.useMemo)(()=>({loadOlder:g,loading:l.older.loading,exhausted:l.older.exhausted}),[g,l.older]),v=R(p,1e3),[y,x]=(0,f.useState)(),[C,w]=(0,f.useState)();(0,f.useEffect)(()=>{if(!e)return;let t=!1;return Promise.resolve(e.subscriptions.list()).then(n=>{t||(x({itx:e,rows:n}),w(void 0))},n=>!t&&w({itx:e,message:n instanceof Error?n.message:String(n)})),()=>{t=!0}},[e,m,v]);let T=e&&y?.itx===e?y:void 0,[D,O]=(0,f.useState)();(0,f.useEffect)(()=>{if(!e)return;let t=!1;return Promise.resolve(e.rpcStubs.list()).then(n=>!t&&O({itx:e,rpcStubs:n}),()=>void 0),()=>{t=!0}},[e,v]);let k=e&&D?.itx===e?D.rpcStubs:[],A=JSON.stringify(t.liveState||[`core`,...(T?.rows||[]).flatMap(e=>e.hostedFacet?[e.hostedFacet.name]:[])]),[j,M]=(0,f.useState)();(0,f.useEffect)(()=>{if(!e)return;let t=JSON.parse(A);if(t.length===0)return;let n=!1,r=new AbortController,i=[],a=(t,n)=>M(r=>r&&r.itx===e&&r.key===A?{...r,entries:{...r.entries,[t]:{...r.entries[t],...n}}}:r);M({itx:e,key:A,entries:Object.fromEntries(t.map(e=>[e,I]))});for(let o of t)o!==`core`&&E(e,{key:o,readSeed:async()=>await e.invoke(`itx.facets.get('${o}').liveSnapshot()`),signal:r.signal,onResync:e=>{n||(e===`healed`?a(o,{status:`live`,error:void 0}):a(o,{status:`error`,error:e.message}))}}).then(e=>{if(n){e.dispose();return}i.push(e.dispose),i.push(e.store.subscribe(()=>{let t=e.store.rev();a(o,{value:e.store.get(),rev:t,...t===null&&{status:`connecting`,error:void 0}})})),a(o,{value:e.store.get(),rev:e.store.rev(),status:`live`})},e=>{n||a(o,{status:`error`,error:e instanceof Error?e.message:String(e)})});return()=>{n=!0,r.abort();for(let e of i)e()}},[e,A]);let N=JSON.parse(A).includes(`core`),[P,F]=(0,f.useState)(),L=(0,f.useRef)({version:h,inFlight:!1,again:!1});(0,f.useEffect)(()=>{if(!e||!N||!d)return;let t=L.current;if(t.itx!==e&&Object.assign(t,{itx:e,inFlight:!1,again:!1}),t.version=h,t.inFlight){t.again=!0;return}let n=()=>{t.inFlight=!0,t.again=!1;let r=t.version;e.invoke(`itx.facets.get('core').snapshot()`).then(n=>{let i=n;t.itx===e&&F({itx:e,version:r,result:{value:i.state,rev:i.offset,status:`live`}})},n=>t.itx===e&&F({itx:e,version:r,result:{value:void 0,rev:null,status:`error`,error:n instanceof Error?n.message:String(n)}})).finally(()=>{t.itx===e&&(t.inFlight=!1,t.again&&n())})};n()},[e,N,d,v,h]),(0,f.useEffect)(()=>()=>{L.current.itx=void 0},[]);let z=(0,f.useMemo)(()=>{let t=JSON.parse(A),n={...e&&j?.itx===e&&j.key===A&&j.entries};return e&&P?.itx===e&&P.version===h?n.core=P.result:delete n.core,Object.fromEntries(t.map(e=>[e,n[e]||I]))},[e,A,j,P,h]);return{events:u,caughtUp:d,error:l.error,head:p,older:_,processors:{rows:T?.rows||[],loaded:!!T,error:e&&C?.itx===e?C.message:void 0},presence:{actors:l.actors,rpcStubs:k},subscription:l.subscription,version:h,liveState:z}}function R(e,t){let[n,r]=(0,f.useState)(e),i=(0,f.useRef)(0);return(0,f.useEffect)(()=>{if(Object.is(e,n))return;let a=setTimeout(()=>{i.current=Date.now(),r(e)},Math.max(0,i.current+t-Date.now()));return()=>clearTimeout(a)},[e,n,t]),n}export{E as a,L as i,F as n,S as o,j as r,M as t}; +import{r as e}from"./rolldown-runtime.mjs";import{a as t}from"./vendor-react";import{_ as n,d as r,f as i,h as a,l as o,r as s,t as c,v as l}from"./vendor-zod";import{a as u,t as d}from"./lib.mjs";const f=i({type:o(`events.iterate.com/itx/created`),payload:i({version:r()})});function p(e){let t=f.safeParse(e);return t.success?t.data.payload.version:void 0}const m=[`events.iterate.com/itx/started-over`,`events.iterate.com/itx/version-ended`],h=i({type:c(m),payload:i({version:r()})});function g(e){let t=h.safeParse(e);return t.success?t.data.payload.version:void 0}const _=i({data:i({retryAfterMs:r()})});async function v(e,t){for(let n=1;;n+=1)try{return await e()}catch(e){if(u(e)!==`UNAVAILABLE`||n>=30)throw e;let r=_.safeParse(e);if(await new Promise(e=>setTimeout(e,r.success?r.data.data.retryAfterMs:1e3)),t())return}}const y=i({key:a(),from:r(),to:r(),patch:s(n([i({op:o(`add`),path:a(),value:l()}),i({op:o(`replace`),path:a(),value:l()}),i({op:o(`remove`),path:a()})])).nullable()});function b(){let e={rev:null,state:void 0},t=/* @__PURE__ */ new Set,n=()=>t.forEach(e=>e());return{get:()=>e.state,rev:()=>e.rev,subscribe:e=>(t.add(e),()=>void t.delete(e)),seed:t=>{e.rev!==null&&t.rev<e.rev||(e={rev:t.rev,state:t.state},n())},clear:()=>{e={rev:null,state:void 0},n()},apply:(t,r)=>{if(!(e.rev!==null&&t.to<=e.rev)){if(t.from!==e.rev||!t.patch){r();return}e={rev:t.to,state:d(e.state,t.patch)},n()}}}}async function x(e,t){let n=b(),r=!1,i=!1,a=!1,o,s=0,c=()=>{if(a)return;if(r){i=!0;return}r=!0;let e=s,o=()=>{r=!1,!a&&i&&(i=!1,c())};t.readSeed().then(r=>{!a&&s===e&&(n.seed(r),t.onResync?.(`healed`)),o()},r=>{!a&&s===e&&(u(r)===`NO_FACET`&&n.clear(),t.onResync?.(r instanceof Error?r:Error(String(r)))),o()})},l=(e,r)=>{if(!(a||s!==e))for(let e of r){let r;try{r=JSON.parse(JSON.stringify(e))}catch{r=void 0}let i=p(r);if(i!==void 0&&i>1){f();return}if(C.safeParse(r).success)continue;let a=S.safeParse(r);if(!a.success){c();continue}if(a.data.payload.key===t.key)try{n.apply(a.data.payload,c)}catch{c()}}},d=async()=>{let n=s,r=await v(()=>e.subscribe({name:t.name,consumes:[`events.iterate.com/itx/live-state-changed`,`events.iterate.com/itx/created`],target:e=>l(n,e)}),()=>a||s!==n);return r?a||s!==n?(w(r),!1):(o=r,!0):!1},f=()=>{s+=1;let e=o;o=void 0,w(e),n.clear(),d().then(e=>e&&c(),e=>!a&&t.onResync?.(e instanceof Error?e:Error(String(e))))};await d();try{let e=t.readSeed(),{signal:r}=t,i=r&&new Promise((e,t)=>{let n=()=>t(r.reason??/* @__PURE__ */ Error(`connectLiveState: aborted while the first seed was pending`));r.aborted?n():r.addEventListener(`abort`,n,{once:!0})});i&&e.catch(()=>void 0);let a=await(i?Promise.race([e,i]):e);s===0&&n.seed(a)}catch(e){throw a=!0,w(o),e}return{store:n,async dispose(){a||(a=!0,w(o))}}}const S=i({payload:y}),C=i({type:c([...m,`events.iterate.com/itx/created`])});function w(e){try{e?.[Symbol.dispose]()}catch{}}const T={events:[],caughtUp:!1,head:0,older:{loading:!1,exhausted:!1},actors:[],tableVersion:0,version:1},E=1e3;function D(e,t){let n=!1,r,i,a=/* @__PURE__ */ new Set,o=T,s=/* @__PURE__ */ new Set,c=[],l=[],u=!1,d,f=0,m=0,h=0,_=1,y=0,b=!1,x=0,S=/* @__PURE__ */ new Map,C=[],w=!1,D=!1,k=()=>Math.max(0,h-1),A=!1,j=e=>{A||(A=!0,_=e.version??1,h=e.versionStartedAtOffset??0)},M=()=>{D||n||(D=!0,typeof requestAnimationFrame==`function`?requestAnimationFrame(N):setTimeout(N,16))},N=()=>{if(D=!1,n)return;let e=[];for(let t of l){if(s.has(t.offset))continue;s.add(t.offset),e.push(t),t.offset>f&&(f=t.offset),t.type.startsWith(`events.iterate.com/itx/subscription-`)&&(x=Math.max(x,t.offset));let n=t.source?.principal,r=n&&S.get(n.actor);n&&(!r||r.offset<t.offset)&&(S.set(n.actor,{actor:n.actor,email:n.email,grant:t.source?.grant,lastSeenAt:t.createdAt,offset:t.offset}),w=!0)}l=[],e.length>0&&(e.sort((e,t)=>e.offset-t.offset),c=c.length===0||e[0].offset>c.at(-1).offset?c.concat(e):e.at(-1).offset<c[0].offset?e.concat(c):c.concat(e).sort((e,t)=>e.offset-t.offset)),w&&(w=!1,C=[...S.values()].map(({offset:e,...t})=>t).sort((e,t)=>t.lastSeenAt.localeCompare(e.lastSeenAt))),o={events:c,caughtUp:u,error:d,head:f,older:{loading:b||!u&&!d,exhausted:u&&m<=k()},actors:C,tableVersion:x,version:_,subscription:i};for(let e of a)e()},P=(e,t=!1)=>{for(let n of e){if(n.type===`events.iterate.com/itx/created`){let e=p(n);e!==void 0&&(e>_||t)&&z(n.offset,e)}n.offset>=h&&l.push(n)}M()},F=e=>{n||(d=e instanceof Error?e.message:String(e),M())},I=(t,r,i)=>v(()=>e.readEvents(t,r),()=>n||y!==i),L=async()=>{let a=y,o=_,s=await v(()=>e.subscribe({consumes:t.consumes,target:e=>{if(n||y!==a)return;let t=O(e);P(t,t.some(e=>(g(e)??0)>=o))}}),()=>n||y!==a);return s?n||y!==a?(s[Symbol.dispose](),!1):(r=s,Promise.resolve(s.name).then(e=>{!n&&y===a&&e&&(i=e,M())},()=>void 0),!0):!1},R=async(e,t)=>{let r=y,i=0;for(;;){let a=await I(e,Math.min(E,t-e),r);if(!a||n||y!==r)return i;j(a);let o=O(a.events).filter(e=>e.offset<=t);if(P(o),i+=o.length,a.atHead||a.scannedThroughOffset>=t||a.scannedThroughOffset<=e)return i;e=a.scannedThroughOffset}},z=(e,t)=>{y+=1,A=!0,_=t,h=e,m=e-1,u=!1,x=Math.max(x,e),c=c.filter(t=>t.offset>=e),l=l.filter(t=>t.offset>=e);for(let t of s)t<e&&s.delete(t);for(let[t,n]of S)n.offset<e&&(S.delete(t),w=!0);i=void 0;let a=r;r=void 0;try{a?.[Symbol.dispose]()}catch{}M(),(async()=>{if(!await L())return;let t=y;await R(e-1,1/0),!(n||y!==t)&&(u=!0,M())})().catch(F)};return(async()=>{if(!await L())return;let e=y;if(t.history===`tail`){let r=await I(2**53-1,1,e);if(!r||n||y!==e)return;j(r),m=k(),f=Math.max(f,r.scannedThroughOffset);let i=Math.max(k(),r.scannedThroughOffset-E),{since:a}=t;m=typeof a==`number`&&Number.isSafeInteger(a)&&a>i&&a<=r.scannedThroughOffset?a-1:i}await R(m,1/0),!(n||y!==e)&&(u=!0,M())})().catch(F),{get:()=>o,subscribe(e){return a.add(e),()=>a.delete(e)},loadOlder(){if(n||!u||b||m<=k())return;b=!0,M();let e=y;(async()=>{let t=E,r=0;for(;m>k()&&r<E/4;){let i=Math.max(k(),m-t);if(r+=await R(i,m),n||y!==e)return;m=i,t=Math.min(t*2,16*E)}})().catch(F).finally(()=>{b=!1,M()})},dispose(){n=!0,a.clear(),r?.[Symbol.dispose]()}}}function O(e){return JSON.parse(JSON.stringify(e)).filter(e=>e&&typeof e.offset==`number`&&typeof e.type==`string`&&typeof e.createdAt==`string`)}var k=/* @__PURE__ */ e(t(),1);function A(e,t){let[n,r]=(0,k.useState)(),[i,a]=(0,k.useState)(`connecting`),[o,s]=(0,k.useState)(),c=(0,k.useRef)(t.readSeed);c.current=t.readSeed,(0,k.useEffect)(()=>{if(r(void 0),a(`connecting`),s(void 0),!e)return;let n=c.current,i=!1,o,l=new AbortController;return x(e,{key:t.key,name:t.name,readSeed:n,signal:l.signal,onResync:e=>{i||(e===`healed`?(a(`live`),s(void 0)):(a(`error`),s(e.message)))}}).then(e=>{if(o=e.dispose,i){e.dispose();return}r(e.store),a(`live`)},e=>{i||(s(e instanceof Error?e.message:String(e)),a(`error`))}),()=>{i=!0,l.abort(),o?.()}},[e,t.key,t.name]);let l=(0,k.useCallback)(e=>n?n.subscribe(e):()=>{},[n]),u=(0,k.useSyncExternalStore)(l,()=>n?.get(),()=>void 0);if(!n&&t.initial)return{value:t.initial.state,rev:t.initial.rev,status:i,error:o};let d=n?.rev()??null;return{value:u,rev:d,status:i===`live`&&d===null?`connecting`:i,error:o}}function j(e,t,n){return A(e,{key:t,readSeed:async()=>P.parse(await e.invoke(N(t))),initial:n})}async function M(e,t){return P.parse(await e.invoke(N(t)))}const N=e=>`itx.facets.get('${e}').liveSnapshot()`,P=i({rev:r(),state:l()});function F(e,t){let[n,r]=(0,k.useState)(()=>({pending:!!e}));return(0,k.useEffect)(()=>{if(!e){r({pending:!1});return}r(e=>e.pending&&!e.stub?e:{pending:!0});let t=!1,n;return e().then(e=>{if(t)return e[Symbol.dispose]();n=e,r({stub:e,pending:!1})},e=>!t&&r({error:e instanceof Error?e.message:String(e),pending:!1})),()=>{t=!0,n?.[Symbol.dispose]()}},t),n}const I={value:void 0,rev:null,status:`connecting`};function L(e,t={}){let[n,r]=(0,k.useState)(),i=JSON.stringify(t.consumes||[`*`]),a=t.history||`tail`,o=(0,k.useRef)(t.since);(0,k.useEffect)(()=>{o.current=t.since}),(0,k.useEffect)(()=>{if(r(void 0),!e)return;let t=D(e,{consumes:JSON.parse(i),history:a,since:o.current});return r({itx:e,connection:t}),()=>t.dispose()},[e,i,a]);let s=e&&n?.itx===e?n.connection:void 0,c=(0,k.useCallback)(e=>s?s.subscribe(e):()=>{},[s]),l=(0,k.useSyncExternalStore)(c,()=>s?.get()??T,()=>T),{events:u,caughtUp:d,head:f,tableVersion:p,version:m}=l,h=(0,k.useCallback)(()=>s?.loadOlder(),[s]),g=(0,k.useMemo)(()=>({loadOlder:h,loading:l.older.loading,exhausted:l.older.exhausted}),[h,l.older]),_=R(f,1e3),[v,y]=(0,k.useState)(),[b,S]=(0,k.useState)();(0,k.useEffect)(()=>{if(!e)return;let t=!1;return Promise.resolve(e.subscriptions.list()).then(n=>{t||(y({itx:e,rows:n}),S(void 0))},n=>!t&&S({itx:e,message:n instanceof Error?n.message:String(n)})),()=>{t=!0}},[e,p,_]);let C=e&&v?.itx===e?v:void 0,[w,E]=(0,k.useState)();(0,k.useEffect)(()=>{if(!e)return;let t=!1;return Promise.resolve(e.rpcStubs.list()).then(n=>!t&&E({itx:e,rpcStubs:n}),()=>void 0),()=>{t=!0}},[e,_]);let O=e&&w?.itx===e?w.rpcStubs:[],A=JSON.stringify(t.liveState||[`core`,...(C?.rows||[]).flatMap(e=>e.hostedFacet?[e.hostedFacet.name]:[])]),[j,M]=(0,k.useState)();(0,k.useEffect)(()=>{if(!e)return;let t=JSON.parse(A);if(t.length===0)return;let n=!1,r=new AbortController,i=[],a=(t,n)=>M(r=>r&&r.itx===e&&r.key===A?{...r,entries:{...r.entries,[t]:{...r.entries[t],...n}}}:r);M({itx:e,key:A,entries:Object.fromEntries(t.map(e=>[e,I]))});for(let o of t)o!==`core`&&x(e,{key:o,readSeed:async()=>await e.invoke(`itx.facets.get('${o}').liveSnapshot()`),signal:r.signal,onResync:e=>{n||(e===`healed`?a(o,{status:`live`,error:void 0}):a(o,{status:`error`,error:e.message}))}}).then(e=>{if(n){e.dispose();return}i.push(e.dispose),i.push(e.store.subscribe(()=>{let t=e.store.rev();a(o,{value:e.store.get(),rev:t,...t===null&&{status:`connecting`,error:void 0}})})),a(o,{value:e.store.get(),rev:e.store.rev(),status:`live`})},e=>{n||a(o,{status:`error`,error:e instanceof Error?e.message:String(e)})});return()=>{n=!0,r.abort();for(let e of i)e()}},[e,A]);let N=JSON.parse(A).includes(`core`),[P,F]=(0,k.useState)(),L=(0,k.useRef)({version:m,inFlight:!1,again:!1});(0,k.useEffect)(()=>{if(!e||!N||!d)return;let t=L.current;if(t.itx!==e&&Object.assign(t,{itx:e,inFlight:!1,again:!1}),t.version=m,t.inFlight){t.again=!0;return}let n=()=>{t.inFlight=!0,t.again=!1;let r=t.version;e.invoke(`itx.facets.get('core').snapshot()`).then(n=>{let i=n;t.itx===e&&F({itx:e,version:r,result:{value:i.state,rev:i.offset,status:`live`}})},n=>t.itx===e&&F({itx:e,version:r,result:{value:void 0,rev:null,status:`error`,error:n instanceof Error?n.message:String(n)}})).finally(()=>{t.itx===e&&(t.inFlight=!1,t.again&&n())})};n()},[e,N,d,_,m]),(0,k.useEffect)(()=>()=>{L.current.itx=void 0},[]);let z=(0,k.useMemo)(()=>{let t=JSON.parse(A),n={...e&&j?.itx===e&&j.key===A&&j.entries};return e&&P?.itx===e&&P.version===m?n.core=P.result:delete n.core,Object.fromEntries(t.map(e=>[e,n[e]||I]))},[e,A,j,P,m]);return{events:u,caughtUp:d,error:l.error,head:f,older:g,processors:{rows:C?.rows||[],loaded:!!C,error:e&&b?.itx===e?b.message:void 0},presence:{actors:l.actors,rpcStubs:O},subscription:l.subscription,version:m,liveState:z}}function R(e,t){let[n,r]=(0,k.useState)(e),i=(0,k.useRef)(0);return(0,k.useEffect)(()=>{if(Object.is(e,n))return;let a=setTimeout(()=>{i.current=Date.now(),r(e)},Math.max(0,i.current+t-Date.now()));return()=>clearTimeout(a)},[e,n,t]),n}export{D as a,L as i,F as n,x as o,j as r,M as t};
M dist/components/docs-editor/docs-editor.mjs
@@ -1,4 +1,4 @@ -import{r as e}from"../../chunks/rolldown-runtime.mjs";import{a as t,n}from"../../chunks/vendor-react";import{_ as r,d as i,f as a,h as o,i as s,l as c,r as l,v as u}from"../../chunks/vendor-zod";import{a as d,t as f}from"../../chunks/react.mjs";import{t as p}from"../../chunks/usingCtx.mjs";import{M as m,Mt as h,Z as ee,f as te}from"../../chunks/vendor-icons";import{_ as ne,a as re,c as ie,d as ae,f as oe,g as se,h as ce,i as le,l as ue,m as de,n as fe,o as pe,p as me,r as he,s as ge,t as _e,u as ve,v as ye,y as be}from"../../chunks/docs-editor-icons";import{c as xe,i as g,r as Se,t as Ce}from"../../chunks/ui-base";import{Spinner as we}from"../ui/spinner";import{G as _,a as Te,h as Ee,i as De,r as Oe,t as ke}from"../../chunks/ui-shell";import{NativeSelect as Ae,NativeSelectOption as v}from"../ui/native-select";import{plainLeftClick as y}from"../../lib/plain-left-click";import{StreamLink as je}from"../stream-link";import{At as b,Et as Me,Ft as x,I as Ne,Mt as S,O as Pe,Ot as C,Pt as Fe,Q as Ie,S as Le,St as w,T as Re,_t as ze,ct as Be,d as Ve,dt as T,f as He,ft as E,k as Ue,lt as We,mt as Ge,ot as Ke,u as qe,ut as Je,vt as Ye,wt as Xe,xt as Ze,yt as Qe}from"../../chunks/vendor-codemirror";import{a as $e,c as et,d as tt,f as nt,i as rt,l as D,n as it,o as at,r as ot,s as st,t as ct,u as lt}from"../../chunks/vendor-yjs";import{a as ut,c as dt,i as ft,l as pt,n as mt,o as ht,r as gt,s as _t,t as O,u as vt}from"../../chunks/vendor-atomic";import{sourceEditorExtensions as yt}from"../../lib/source-editor";var k=/* @__PURE__ */ e(t(),1);function A(e,t){let{from:n,to:r}=e.state.selection.main,i=t.length,a=e.state.sliceDoc(n-i,n)===t&&e.state.sliceDoc(r,r+i)===t;return e.dispatch(a?{changes:[{from:n-i,to:n},{from:r,to:r+i}]}:{changes:[{from:n,insert:t},{from:r,insert:t}],selection:{anchor:n+i,head:r+i}}),e.focus(),!0}const bt=/^(#{1,6} |> |- \[[ xX]\] |[-*+] |\d+\. )/;function j(e,t){let{from:n,to:r}=e.state.selection.main,i=[];for(let a=e.state.doc.lineAt(n).number;a<=e.state.doc.lineAt(r).number;a++){let n=e.state.doc.line(a),r=n.text.match(bt)?.[0]||``;i.push({from:n.from,to:n.from+r.length,insert:t})}return e.dispatch({changes:i}),e.focus(),!0}function M(e,t){let n=e.state.doc.lineAt(e.state.selection.main.head);return e.dispatch({changes:{from:n.to,insert:`\n\n${t}\n`},selection:{anchor:n.to+2}}),e.focus(),!0}function xt(e,t){let{from:n,to:r}=e.state.selection.main,i=e.state.sliceDoc(n,r)||t;return e.dispatch({changes:{from:n,to:r,insert:`[${i}](${t})`},selection:{anchor:n+1,head:n+1+i.length}}),e.focus(),!0}function N(e){let t=window.prompt(`Link URL`);return!t||xt(e,t)}var P=/* @__PURE__ */ e(n(),1);function F({session:e,state:t}){let n=t.threads.filter(e=>!e.resolved),r=n=>/* @__PURE__ */ (0,P.jsx)(Ct,{session:e,thread:n,active:t.active===n.id,editing:t.editing&&t.editing.thread===n.id?t.editing.comment:null,thinking:!!(n.routedTo&&t.thinking.includes(n.routedTo))},n.id),i=n.filter(e=>!e.attached),a=t.threads.filter(e=>e.resolved);return/* @__PURE__ */ (0,P.jsxs)(`aside`,{"aria-label":`Comments`,className:`flex shrink-0 flex-col gap-3 border-t p-3 wrap-anywhere md:sticky md:top-0 md:max-h-[calc(100svh-4.75rem)] md:w-80 md:self-start md:overflow-y-auto md:border-t-0 md:border-l`,children:[t.draft?/* @__PURE__ */ (0,P.jsxs)(`article`,{"aria-label":`New comment`,ref:St,className:`flex scroll-mb-12 flex-col gap-2 rounded-lg border bg-card p-3 text-sm shadow-xs ring-2 ring-highlight`,children:[/* @__PURE__ */ (0,P.jsx)(I,{quote:t.draft.quote,gone:!1}),/* @__PURE__ */ (0,P.jsx)(L,{label:`Comment`,placeholder:`Add a comment…`,submit:`Comment`,onSubmit:t=>e.postDraft(t),onCancel:()=>e.cancelDraft(),keepPending:!0})]}):null,n.filter(e=>e.attached).map(r),i.length>0?/* @__PURE__ */ (0,P.jsxs)(P.Fragment,{children:[/* @__PURE__ */ (0,P.jsx)(`h3`,{className:`pt-1 text-xs text-muted-foreground`,children:`On text that's gone`}),i.map(r)]}):null,a.length>0?/* @__PURE__ */ (0,P.jsxs)(`details`,{className:`text-sm`,children:[/* @__PURE__ */ (0,P.jsxs)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground`,children:[`Resolved (`,a.length,`)`]}),/* @__PURE__ */ (0,P.jsx)(`div`,{className:`mt-2 flex flex-col gap-3`,children:a.map(r)})]}):null]})}function St(e){let t=()=>e.scrollIntoView({block:`nearest`});t();let n=new IntersectionObserver(([e])=>{e&&e.intersectionRatio<1&&t()},{threshold:1,rootMargin:`0px 0px -48px 0px`});n.observe(e);let r=()=>{n.disconnect(),clearTimeout(i),removeEventListener(`wheel`,r),removeEventListener(`touchmove`,r)},i=setTimeout(r,1500);return addEventListener(`wheel`,r,{passive:!0}),addEventListener(`touchmove`,r,{passive:!0}),r}function Ct({session:e,thread:t,active:n,editing:r,thinking:i}){let a=e.options.user.email;return/* @__PURE__ */ (0,P.jsxs)(`article`,{"aria-label":t.quote?`Comment on “${t.quote.exact}”`:`Comment on the doc`,"aria-current":n||void 0,className:xe(`flex flex-col gap-2 rounded-lg border bg-card p-3 text-sm shadow-xs`,n&&`ring-2 ring-highlight`,t.resolved&&`opacity-80`),children:[/* @__PURE__ */ (0,P.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[/* @__PURE__ */ (0,P.jsx)(`button`,{type:`button`,title:`Show in the doc`,className:`min-w-0 flex-1 cursor-pointer text-left`,onClick:()=>e.focusThread(t.id),children:/* @__PURE__ */ (0,P.jsx)(I,{quote:t.quote,gone:!t.attached})}),t.resolved?/* @__PURE__ */ (0,P.jsx)(g,{size:`icon-xs`,variant:`ghost`,"aria-label":`Reopen`,title:`Resolved by ${z(t.resolved.by)}. Reopen`,onClick:()=>void e.reopen(t.id),children:/* @__PURE__ */ (0,P.jsx)(pe,{})}):/* @__PURE__ */ (0,P.jsx)(g,{size:`icon-xs`,variant:`ghost`,"aria-label":`Resolve`,title:`Resolve`,onClick:()=>void e.resolve(t.id),children:/* @__PURE__ */ (0,P.jsx)(h,{})})]}),/* @__PURE__ */ (0,P.jsx)(`ol`,{className:`flex flex-col gap-2`,children:t.comments.map(i=>/* @__PURE__ */ (0,P.jsx)(wt,{comment:i,mine:i.author===a&&n,editing:r===i.id,onEdit:()=>e.startEditing(t.id,i.id),onSave:n=>e.editComment(t.id,i.id,n),onCancel:()=>e.stopEditing(),onDelete:()=>e.deleteComment(t.id,i.id)},i.id))}),i?/* @__PURE__ */ (0,P.jsxs)(`p`,{role:`status`,className:`flex items-center gap-1.5 font-readme text-xs text-muted-foreground`,children:[/* @__PURE__ */ (0,P.jsx)(ne,{"aria-hidden":!0,className:`size-4 animate-pulse text-success`}),`Thinking…`]}):null,t.resolved?/* @__PURE__ */ (0,P.jsxs)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:[`Resolved by `,z(t.resolved.by)]}):n?/* @__PURE__ */ (0,P.jsx)(L,{label:`Reply`,placeholder:`Reply…`,submit:`Reply`,onSubmit:n=>e.reply(t.id,n)}):null]})}function wt({comment:e,mine:t,editing:n,onEdit:r,onSave:i,onCancel:a,onDelete:o}){let[s,c,l]=(0,k.useActionState)(async()=>R(o()),null);return/* @__PURE__ */ (0,P.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[/* @__PURE__ */ (0,P.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[/* @__PURE__ */ (0,P.jsxs)(`span`,{title:e.author,children:[/* @__PURE__ */ (0,P.jsx)(`span`,{className:`font-medium`,children:z(e.author)}),e.via?/* @__PURE__ */ (0,P.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.via]}):null]}),/* @__PURE__ */ (0,P.jsx)(`time`,{dateTime:e.at,className:`text-xs text-muted-foreground`,suppressHydrationWarning:!0,children:Tt.format(new Date(e.at))})]}),n?/* @__PURE__ */ (0,P.jsx)(L,{label:`Edit comment`,placeholder:``,submit:`Save`,defaultValue:e.body,onSubmit:i,onCancel:a}):/* @__PURE__ */ (0,P.jsxs)(`p`,{className:`whitespace-pre-wrap`,children:[e.body,e.edited?/* @__PURE__ */ (0,P.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:` (edited)`}):null]}),t&&!n?/* @__PURE__ */ (0,P.jsxs)(`div`,{className:`flex gap-1`,children:[/* @__PURE__ */ (0,P.jsx)(g,{size:`icon-xs`,variant:`ghost`,"aria-label":`Edit`,title:`Edit`,onClick:r,children:/* @__PURE__ */ (0,P.jsx)(m,{})}),/* @__PURE__ */ (0,P.jsx)(g,{size:`icon-xs`,variant:`ghost`,"aria-label":`Delete`,title:`Delete`,disabled:l,onClick:()=>(0,k.startTransition)(c),children:/* @__PURE__ */ (0,P.jsx)(te,{})})]}):null,s?.error?/* @__PURE__ */ (0,P.jsx)(`p`,{className:`text-xs text-destructive`,children:s.error}):null]})}function I({quote:e,gone:t}){return e?/* @__PURE__ */ (0,P.jsx)(`span`,{className:xe(`line-clamp-2 border-l-2 border-highlight pl-2 text-xs text-muted-foreground`,t&&`line-through`),children:e.exact}):/* @__PURE__ */ (0,P.jsx)(`span`,{className:`block font-readme text-xs text-muted-foreground`,children:`On the whole doc`})}function L({label:e,placeholder:t,submit:n,defaultValue:r,onSubmit:i,onCancel:a,keepPending:o}){let[s,c]=(0,k.useState)(r||``),[l,u,d]=(0,k.useActionState)(async e=>{let t=s.trim();if(!t)return e;let n=await R(i(t));return n.error||c(``),n},null),f=d||!!(o&&l&&!l.error);return/* @__PURE__ */ (0,P.jsxs)(`form`,{className:`flex flex-col gap-1.5`,action:u,children:[/* @__PURE__ */ (0,P.jsx)(Ce,{name:`body`,"aria-label":e,placeholder:t,value:s,onChange:e=>c(e.target.value),rows:2,autoFocus:!!a,className:`min-h-0`,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit()),e.key===`Escape`&&a&&a()}}),l?.error?/* @__PURE__ */ (0,P.jsx)(`p`,{className:`text-xs text-destructive`,children:l.error}):null,/* @__PURE__ */ (0,P.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[a?/* @__PURE__ */ (0,P.jsx)(g,{type:`button`,size:`xs`,variant:`ghost`,onClick:a,children:`Cancel`}):null,/* @__PURE__ */ (0,P.jsx)(g,{type:`submit`,size:`xs`,disabled:f,children:f?`Posting…`:n})]})]})}const Tt=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`});async function R(e){try{return await e,{error:null}}catch(e){return{error:e instanceof Error?e.message:String(e)}}}function z(e){return e.includes(`@`)?e.split(`@`)[0]:e}const B=`docs/comment-added`,V=`docs/comment-replied`,H=`docs/comment-edited`,U=`docs/comment-deleted`,Et=`docs/comment-resolved`,Dt=`docs/comment-reopened`,Ot=[B,V,H,U,Et,Dt,`docs/comment-reanchored`,`docs/comment-routed`],W=a({exact:o().min(1),prefix:o(),suffix:o()}),kt=o().trim().min(1).max(40).optional();a({thread:o().min(1),quote:W.nullable(),body:o().min(1),via:kt}),a({thread:o(),comment:o().min(1),body:o().min(1),via:kt}),a({thread:o(),comment:o(),body:o().min(1)}),a({thread:o(),comment:o()}),a({thread:o()}),a({thread:o(),quote:W.nullable()}),a({thread:o(),to:o().min(1).nullable()});const At=a({id:o(),author:o(),via:o().nullable().default(null),body:o(),at:o(),edited:s()}),jt=a({id:o(),quote:W.nullable(),detached:s(),resolved:a({by:o(),at:o()}).nullable(),routedTo:o().nullable().default(null),comments:l(At)}),G=`docs/edit-frame`,Mt=`docs/awareness-frame`,Nt=`docs/left`,K=`docs/opened`,Pt=a({update:o(),client:r([i(),c(`processor`)])}),Ft=a({update:o(),client:i()});a({client:i()});function It(e){let t=/^\/repos\/([^/]+)$/.exec(e.repo)?.[1];if(!t)throw Error(`not a repo Docs edits: ${e.repo} (a repo is /repos/<name>)`);return`/docs/${t}/${e.path}`}const Lt=a({commitOid:o().nullable(),dirty:s(),savedBy:l(o()),saveError:o().nullable(),threads:l(jt)});function q(e){let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}function J(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}const Rt=new Set(`png jpg jpeg gif webp avif heic ico bmp tif tiff psd pdf zip gz tgz tar bz2 xz 7z rar jar wasm bin exe dll so dylib woff woff2 ttf otf eot mp3 wav ogg flac m4a mp4 mov webm avi mkv sqlite db`.split(` `));function zt(e){let t=e.split(`/`).at(-1),n=t.includes(`.`)?t.split(`.`).at(-1).toLowerCase():``;return n===`md`||n===`markdown`||n===`mdx`?`markdown`:n===`html`||n===`htm`?`html`:Rt.has(n)?`binary`:`code`}async function Y(e){try{var t=p();let n=t.u(e.mind.repos.get(e.repo)),{commitOid:r,paths:i}=await n.listFiles();if(i.includes(e.path))return;await n.commitFiles({message:`docs: new ${e.path}`,changes:[{path:e.path,content:zt(e.path)===`markdown`?`# ${e.heading}\n`:``}],parent:r,author:e.author})}catch(e){t.e=e}finally{t.d()}}function Bt(e){return e.email?{name:e.email,email:e.email}:void 0}function Vt(e){let t=e.replace(/\.md$/i,``).split(`/`).map(e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``)).filter(Boolean);return t.length>0?`${t.join(`/`)}.md`:``}function Ht(e){return e.split(`/`).at(-1).trim()}const Ut=a({payload:a({path:o()})});var Wt=class{#e={kind:`loading`};#t=/* @__PURE__ */ new Set;mind;repo;#n=null;#r=null;constructor(e,t){this.mind=e,this.repo=t}subscribe=e=>(this.#t.add(e),this.#t.size===1&&this.#a(),()=>{this.#t.delete(e),this.#t.size===0&&(this.#r?.(),this.#r=null)});state=()=>this.#e;reload(){this.#n&&this.#o(this.#n)}#i(e){this.#e=e;for(let e of this.#t)e()}#a(){let e=null,t=!1,n={};this.#r=()=>{t=!0,this.#n=null,e?.[Symbol.dispose]()},(async()=>{let r=await this.mind.subscribe({consumes:[`events.iterate.com/repo/commit-completed`],target:e=>{l(u()).parse(JSON.parse(JSON.stringify(e))).some(e=>Ut.safeParse(e).data?.payload.path===this.repo)&&this.#o(n)}});if(t)return r[Symbol.dispose]();e=r,this.#n=n,await this.#o(n)})().catch(e=>{t||this.#i({kind:`failed`,message:Gt(e)})})}async#o(e){try{try{var t=p();let{paths:n}=await t.u(this.mind.repos.get(this.repo)).listFiles();this.#n===e&&this.#i({kind:`loaded`,paths:n.toSorted()})}catch(e){t.e=e}finally{t.d()}}catch(t){this.#n===e&&this.#i({kind:`failed`,message:Gt(t)})}}};function Gt(e){return e instanceof Error?e.message:String(e)}function Kt({list:e,author:t,docHref:n,onOpen:r}){let i=(0,k.useSyncExternalStore)(e.subscribe,e.state,e.state),[a,o,s]=(0,k.useActionState)(async(n,i)=>{let a=String(i.get(`title`)),o=Vt(a);if(!o)return{error:`A title needs a letter or a digit in it.`};try{await Y({mind:e.mind,repo:e.repo,path:o,heading:Ht(a),author:t})}catch(e){return{error:e instanceof Error?e.message:String(e)}}return e.reload(),r(o),null},null);return/* @__PURE__ */ (0,P.jsxs)(`main`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-6 p-4 md:p-8`,children:[/* @__PURE__ */ (0,P.jsxs)(`form`,{action:o,className:`flex gap-2`,children:[/* @__PURE__ */ (0,P.jsx)(Se,{name:`title`,"aria-label":`New doc title`,placeholder:`New doc title, or folder/title`,autoFocus:!0,required:!0}),/* @__PURE__ */ (0,P.jsx)(g,{type:`submit`,disabled:s,children:s?`Creating…`:`New doc`})]}),a?.error?/* @__PURE__ */ (0,P.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:a.error}):null,i.kind===`loading`?/* @__PURE__ */ (0,P.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`Loading docs…`}):i.kind===`failed`?/* @__PURE__ */ (0,P.jsxs)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:[`Couldn't list the docs: `,i.message]}):i.paths.length>0?/* @__PURE__ */ (0,P.jsx)(`ul`,{"aria-label":`Docs`,className:`flex flex-col divide-y rounded-lg border`,children:i.paths.map(e=>/* @__PURE__ */ (0,P.jsx)(`li`,{children:/* @__PURE__ */ (0,P.jsx)(`a`,{href:n(e),onClick:t=>{y(t)&&(t.preventDefault(),r(e))},className:`block px-4 py-2.5 font-mono text-sm hover:bg-muted`,children:e})},e))}):/* @__PURE__ */ (0,P.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`No docs yet.`})]})}function qt(e){return/* @__PURE__ */ (0,P.jsx)(k.Suspense,{fallback:/* @__PURE__ */ (0,P.jsx)(`p`,{className:`px-2 py-1 font-readme text-xs text-muted-foreground`,children:`Loading files…`}),children:/* @__PURE__ */ (0,P.jsx)(Yt,{...e})})}let Jt;function Yt({list:e,openPath:t,onOpen:n,author:r}){let{PierreDocTree:i}=(0,k.use)(Jt||=import(`./doc-tree`)),a=(0,k.useSyncExternalStore)(e.subscribe,e.state,e.state),[o,s]=(0,k.useState)(null),c=(0,k.useRef)({openPath:t,onOpen:n,author:r});(0,k.useEffect)(()=>{c.current={openPath:t,onOpen:n,author:r}});let l=(0,k.useMemo)(()=>new i({list:e,openPath:()=>c.current.openPath,open:e=>c.current.onOpen(e),create:async t=>{s({path:t,error:null});try{await Y({mind:e.mind,repo:e.repo,path:t,heading:t.split(`/`).at(-1).replace(/\.[^.]+$/,``),author:c.current.author})}catch(e){throw s({path:t,error:e instanceof Error?e.message:String(e)}),e}e.reload(),s(null),c.current.onOpen(t)}}),[e,i]);return(0,k.useEffect)(()=>l.reveal(),[l,t]),/* @__PURE__ */ (0,P.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-1`,children:[a.kind===`loaded`?/* @__PURE__ */ (0,P.jsx)(`div`,{ref:l.mount,"aria-label":`Files`,className:`min-h-0 flex-auto`}):/* @__PURE__ */ (0,P.jsx)(`p`,{className:a.kind===`failed`?`px-2 py-1 text-xs text-destructive`:`px-2 py-1 font-readme text-xs text-muted-foreground`,children:a.kind===`failed`?`Couldn't list the files: ${a.message}`:`Loading files…`}),o&&!o.error?/* @__PURE__ */ (0,P.jsxs)(`p`,{className:`flex items-center gap-1.5 px-2 py-1 font-readme text-xs text-muted-foreground`,children:[/* @__PURE__ */ (0,P.jsx)(we,{}),`Creating `,o.path,`…`]}):null,o?.error?/* @__PURE__ */ (0,P.jsxs)(`p`,{role:`alert`,"data-type":`error`,className:`px-2 py-1 text-xs text-destructive`,children:[`Couldn't make `,o.path,`: `,o.error]}):null]})}function Xt(e,t,n){return{exact:e.slice(t,n),prefix:e.slice(Math.max(0,t-32),t),suffix:e.slice(n,n+32)}}function Zt(e,t){let n=en(e,t.exact);if(n.length>0){let r=n.reduce((n,r)=>Qt(e,t,r)>Qt(e,t,n)?r:n);return{from:r,to:r+t.exact.length,exact:!0}}return $t(e,t)}function Qt(e,t,n){let r=0;for(let i=1;i<=t.prefix.length&&e[n-i]===t.prefix.at(-i);i++)r++;let i=n+t.exact.length;for(let n=0;n<t.suffix.length&&e[i+n]===t.suffix[n];n++)r++;return r}function $t(e,t){let n=t.prefix?en(e,t.prefix).map(e=>e+t.prefix.length):[0],r=t.exact.length*2+16,i=null;for(let a of n){let n=t.suffix?e.indexOf(t.suffix,a):e.length;n<0||n-a>r||n===a||(!i||n-a<i.to-i.from)&&(i={from:a,to:n,exact:!1})}return i}function en(e,t){let n=[];for(let r=e.indexOf(t);r>=0;r=e.indexOf(t,r+1))n.push(r);return n}async function tn(e,t,n){await e.processors.enable(`docs`,{...n.facetSpec(`DocsDurableObject`),consumes:[`events.iterate.com/repo/commit-completed`,K]});let r=It(t);await e.append({type:K,payload:{repo:t.repo,path:t.path},idempotencyKey:`${K}:${r}`});let i=e.cd(r);return await i.processors.enable(`doc`,{...n.facetSpec(`DocDurableObject`),consumes:[G,`docs/commit-noticed`,Nt,...Ot]}),i}const nn=a({type:o(),payload:u()});var rn=class{doc=new st;text=this.doc.getText(`file`);awareness=new ct(this.doc);#e;#t;#n=[];#r=!1;#i=Promise.resolve();#a=null;#o=null;#s=!1;#c=!1;#l=!1;#u=null;constructor(e){this.#e=e.context,this.#t=e.onStatus,this.awareness.setLocalStateField(`user`,{name:e.user.name,color:e.user.color,colorLight:`color-mix(in oklab, ${e.user.color} 20%, transparent)`}),this.doc.on(`update`,(e,t)=>{t!==this&&this.#_(e)}),this.awareness.on(`update`,({added:e},t)=>{if(t!==this)return void this.#y();e.some(e=>e!==this.doc.clientID)&&this.#y()})}open(){return this.#o=this.#d(),this.#o}async#d(){this.#u=await this.#e.subscribe({consumes:[G,Mt],target:e=>{if(!this.#l)for(let t of e)this.#h(t)}}),await this.sync(),this.#y()}sync(){return this.#a?(this.#s=!0,this.#a):(this.#a=this.#f().finally(()=>{this.#a=null}),this.#a)}async#f(){do{this.#s=!1;try{let e=await this.#e.facets.get(`doc`).sync(q(tt(this.doc)),this.doc.clientID);D(this.doc,J(e.update),this);let t=lt(this.doc,J(e.stateVector));this.#c=!1,t.length>2&&this.#_(t),this.#t({kind:`live`})}catch(e){this.#t({kind:`failed`,message:an(e)});return}}while(this.#s||this.#g())}#p;close(){return this.#p||=this.#m()}async#m(){this.#l=!0,rt(this.awareness,[this.doc.clientID],`left`),await this.#o?.catch(()=>{}),await this.#a,this.#u?.[Symbol.dispose](),this.awareness.destroy(),await this.#i,this.#c&&await this.sync(),await this.#e.append({type:Nt,ephemeral:!0,payload:{client:this.doc.clientID}}).catch(()=>{})}unsent(){return this.#r||this.#n.length>0||this.#c}#h(e){let t=nn.safeParse(JSON.parse(JSON.stringify(e)));if(!t.success)return;let n=t.data;if(n.type===`docs/awareness-frame`){let e=Ft.safeParse(n.payload);e.success&&e.data.client!==this.doc.clientID&&it(this.awareness,J(e.data.update),this);return}let r=Pt.safeParse(n.payload);r.success&&r.data.client!==this.doc.clientID&&(D(this.doc,J(r.data.update),this),this.#g()&&this.sync())}#g(){return this.doc.store.pendingStructs!==null||this.doc.store.pendingDs!==null}#_(e){this.#n.push(e),this.#r||(this.#i=this.#v())}async#v(){this.#r=!0;try{for(;this.#n.length>0;){let e=nt(this.#n.splice(0));await this.#e.append({type:G,ephemeral:!0,payload:{update:q(e),client:this.doc.clientID}})}}catch(e){this.#n=[],this.#c=!0,this.#t({kind:`failed`,message:an(e)})}finally{this.#r=!1}}#y(){let e=ot(this.awareness,[this.doc.clientID]);this.#e.append({type:Mt,ephemeral:!0,payload:{update:q(e),client:this.doc.clientID}}).catch(()=>{})}};function an(e){return e instanceof Error?e.message:String(e)}const on=Fe.define(),X=x.define({create:()=>({threads:[],ranges:/* @__PURE__ */ new Map,active:null}),update(e,t){let n=e;if(t.docChanged){let r=ln(e.ranges,t.changes);n={...e,ranges:un(t.state.doc,e.threads,r)}}for(let e of t.effects)if(e.is(on)){let r=t.state.doc,i=/* @__PURE__ */ new Map;for(let t of e.value.threads){let e=n.threads.find(e=>e.id===t.id),r=n.ranges.get(t.id),a=e&&e.quote.exact===t.quote.exact&&e.quote.prefix===t.quote.prefix&&e.quote.suffix===t.quote.suffix;r&&a&&i.set(t.id,r)}n={threads:e.value.threads,ranges:un(r,e.value.threads,i),active:e.value.active}}return t.isUserEvent(`select`)&&(n={...n,active:sn(n.ranges,t.state.selection.main.head)}),n},provide:e=>E.decorations.from(e,({ranges:e,active:t})=>T.set([...e].map(([e,n])=>T.mark({class:e===t?`cm-comment cm-comment-active`:`cm-comment`,attributes:{"data-thread":e}}).range(n.from,n.to)),!0))});function sn(e,t){let n=null;for(let r of e){let[,e]=r;e.from>t||e.to<t||(!n||e.to-e.from<n[1].to-n[1].from)&&(n=r)}return n&&n[0]}const cn=E.baseTheme({".cm-comment":{backgroundColor:`color-mix(in oklab, var(--highlight) 28%, transparent)`,borderBottom:`2px solid color-mix(in oklab, var(--highlight) 80%, transparent)`},".cm-comment-active":{backgroundColor:`color-mix(in oklab, var(--highlight) 60%, transparent)`}});function ln(e,t){let n=/* @__PURE__ */ new Map;for(let[r,i]of e){let e=t.mapPos(i.from,1),a=t.mapPos(i.to,-1);a>e&&n.set(r,{from:e,to:a})}return n}function un(e,t,n){let r=t.filter(e=>!n.has(e.id));if(r.length===0)return n;let i=e.toString();for(let e of r){let t=Zt(i,e.quote);t&&n.set(e.id,{from:t.from,to:t.to})}return n}const dn=/^---\n[\s\S]*?\n---(?=\n|$)/;var fn=class extends Ge{yaml;constructor(e){super(),this.yaml=e}eq(e){return e.yaml===this.yaml}toDOM(){let e=document.createElement(`dl`);e.className=`docs-properties`,e.setAttribute(`aria-label`,`Properties`);for(let t of this.yaml.split(` -`).slice(1,-1)){let n=t.indexOf(`:`);if(n<1)continue;let r=document.createElement(`dt`);r.textContent=t.slice(0,n).trim();let i=document.createElement(`dd`);i.textContent=t.slice(n+1).trim(),e.appendChild(r),e.appendChild(i)}return e}};function pn(e){let t=e.doc.toString().match(dn);if(!t)return T.none;let n=new fn(t[0]);return T.set([T.replace({block:!0,widget:n}).range(0,t[0].length)])}const mn=E.baseTheme({".docs-properties":{display:`grid`,gridTemplateColumns:`fit-content(40%) minmax(0, 1fr)`,gap:`0.125rem 1.25rem`,margin:`0.5rem 0 1rem`,fontSize:`0.8125rem`},".docs-properties dt":{color:`var(--muted-foreground)`}}),hn=x.define({create:pn,update:(e,t)=>t.docChanged?pn(t.state):e,provide:e=>[E.decorations.from(e),E.atomicRanges.of(t=>t.state.field(e)),mn]});function gn(e){return e===`rich`?[hn,mt(),ut(),gt()]:[]}const _n=S.highest(w.of([{key:`Mod-b`,run:e=>A(e,`**`)},{key:`Mod-i`,run:e=>A(e,`_`)},{key:`Mod-e`,run:e=>A(e,"`")},{key:`Mod-Shift-x`,run:e=>A(e,`~~`)},{key:`Mod-k`,run:N}].map(e=>({...e,preventDefault:!0,stopPropagation:!0})))),vn=E.theme({"&":{"--atomic-editor-fg":`var(--foreground)`,"--atomic-editor-fg-muted":`var(--muted-foreground)`,"--atomic-editor-fg-faint":`var(--muted-foreground)`,"--atomic-editor-bg":`var(--background)`,"--atomic-editor-bg-surface":`var(--popover)`,"--atomic-editor-bg-panel":`var(--muted)`,"--atomic-editor-border":`var(--border)`,"--atomic-editor-accent":`var(--primary)`,"--atomic-editor-accent-bright":`var(--foreground)`,"--atomic-editor-accent-soft":`var(--accent)`,"--atomic-editor-link":`var(--primary)`,"--atomic-editor-link-hover":`var(--foreground)`,"--atomic-editor-code-bg":`var(--muted)`,"--atomic-editor-selection-bg":`var(--accent)`,"--atomic-editor-font":`var(--font-sans, system-ui)`,"--atomic-editor-measure":`100%`,"--atomic-editor-hl-comment":`var(--muted-foreground)`,"--atomic-editor-hl-escape":`var(--info)`,"--atomic-editor-hl-function":`var(--chart-5)`,"--atomic-editor-hl-invalid":`var(--destructive)`,"--atomic-editor-hl-keyword":`var(--chart-2)`,"--atomic-editor-hl-number":`var(--info)`,"--atomic-editor-hl-operator":`var(--chart-2)`,"--atomic-editor-hl-property":`var(--info)`,"--atomic-editor-hl-regexp":`var(--chart-1)`,"--atomic-editor-hl-string":`var(--chart-1)`,"--atomic-editor-hl-tag":`var(--success)`,"--atomic-editor-hl-type":`var(--warning)`,"--atomic-editor-hl-variable":`var(--foreground)`,fontSize:`15px`},"&.cm-focused":{outline:`none`},".cm-content":{padding:`8px 0 30vh`},".cm-line":{lineHeight:`1.7`}}),yn=[We({top:!0,scrollToMatch:e=>E.scrollIntoView(e,{y:`center`})}),S.highest(E.theme({".cm-panels":{backgroundColor:`var(--background)`,color:`var(--foreground)`,borderTop:`1px solid var(--border)`},".cm-panel.cm-search":{padding:`6px 36px 6px 16px`,fontSize:`13px`},".cm-panel.cm-search input[type=text], .cm-panel.cm-search button":{height:`26px`,margin:`2px 6px 2px 0`,borderRadius:`0`,border:`1px solid var(--border)`,backgroundColor:`var(--background)`,backgroundImage:`none`,color:`var(--foreground)`,fontSize:`13px`},".cm-panel.cm-search input[type=text]":{width:`16rem`,padding:`0 8px`},".cm-panel.cm-search input[type=text]:focus":{outline:`none`,borderColor:`var(--foreground)`},".cm-panel.cm-search button":{padding:`0 10px`},".cm-panel.cm-search button:hover":{backgroundColor:`var(--accent)`},".cm-panel.cm-search label":{color:`var(--muted-foreground)`,fontSize:`13px`},".cm-panel.cm-search input[type=checkbox]":{accentColor:`var(--foreground)`},".cm-panel.cm-search button[name=close]":{top:`8px`,right:`12px`,border:`none`,padding:`0 6px`,fontSize:`18px`,color:`var(--muted-foreground)`},".cm-searchMatch":{backgroundColor:`color-mix(in oklab, var(--info) 18%, transparent)`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:`color-mix(in oklab, var(--info) 38%, transparent)`,outline:`1px solid var(--info)`}}))];function bn(e){return[Ze(),ze(),Ye(),b.allowMultipleSelections.of(!0),Ie(),Me(),Qe(),Pe(),dt,_t,ht,E.lineWrapping,qe({base:He,codeLanguages:O,extensions:ft}),vt,pt,vn,_n,yn,w.of([...Ue,...Je,...Ve,Re,...Le]),e.preview.of(gn(e.mode))]}function xn(e){return[yt({history:`external`}),yn,e.language]}async function Sn(e){let t=Ne.matchFilename(O,e);return t?await t.load():[]}const Cn=a({paused:a({reason:o()}).nullable(),llmRequests:l(a({})),pendingTriggerOffsets:l(i()),scriptCalls:l(a({answered:s()}))});function wn(e){let t=e.llmRequests.length>0||e.pendingTriggerOffsets.length>0||e.scriptCalls.some(e=>!e.answered);return!e.paused&&t}const Tn=a({user:a({name:o().min(1)})}),Z=[b.readOnly.of(!0),E.editable.of(!1)],En={markdown:`rich`,html:`preview`,code:`code`};var Dn=class{#e;#t=/* @__PURE__ */ new Set;#n=new C;#r=new C;#i=[];#a;#o=null;#s=null;#c=null;#l=null;#u={kind:`opening`};#d=null;#f=!1;#p;#m=null;#h=[];#g=``;#_=/* @__PURE__ */ new Map;options;constructor(e){this.options=e,this.#e={mode:En[e.kind],status:{kind:`opening`},others:[],previewText:e.text,threads:[],active:null,thinking:[],selecting:!1,draft:null,editing:null}}subscribe=e=>(this.#t.add(e),()=>this.#t.delete(e));state=()=>this.#e;#v(e){this.#e={...this.#e,...e};for(let e of this.#t)e()}mountPanels=e=>{e?.appendChild(this.#y())};#y(){return this.#s||=document.createElement(`div`)}mount=e=>{if(!e)return;let t=new E({parent:e,state:b.create({doc:this.options.text,extensions:[this.#w(),Z]})});this.#o=t,this.options.kind!==`markdown`&&this.#T();let n={unmounted:!1,cleanups:[]};this.#d=n;let r=e=>{this.#c?.unsent()&&e.preventDefault()};window.addEventListener(`beforeunload`,r);let i=()=>void this.#c?.close();window.addEventListener(`pagehide`,i);let a=e=>{e.persisted&&this.#x(t,n)};window.addEventListener(`pageshow`,a);let o=e=>{(e.metaKey||e.ctrlKey)&&e.key===`f`&&!e.defaultPrevented&&(e.target instanceof Element&&e.target.closest(`input, textarea, [contenteditable]:not([contenteditable="false"])`)||this.#e.mode!==`preview`&&(e.preventDefault(),Be(t)))};return window.addEventListener(`keydown`,o),this.#S(t,n),()=>{n.unmounted=!0,window.removeEventListener(`beforeunload`,r),window.removeEventListener(`pagehide`,i),window.removeEventListener(`pageshow`,a),window.removeEventListener(`keydown`,o);for(let e of n.cleanups.reverse())e();clearTimeout(this.#a),this.#a=void 0;for(let e of this.#_.values())e();this.#_.clear(),this.#o=null,this.#d=null,this.#c=null,this.#m=null,this.#l=null,t.destroy()}};#b(e,t){e.unmounted?t():e.cleanups.push(t)}#x(e,t){if(!(t.unmounted||this.#f)){e.setState(b.create({doc:e.state.doc.toString(),extensions:[this.#w(),Z]}));for(let e of t.cleanups.splice(0).reverse())e();for(let e of this.#_.values())e();this.#_.clear(),this.#c=null,this.#m=null,this.#l=null,this.#S(e,t)}}async#S(e,t){let n=[],r=e=>{n.push(e),this.#b(t,e)};this.#f=!0,this.#u={kind:`opening`},this.#D();try{let{itx:n,repo:i,path:a,user:o,facetSpec:s}=this.options,c=await tn(n,{repo:i,path:a},{facetSpec:s}),l=Promise.resolve();if(r(()=>{l.finally(()=>c[Symbol.dispose]())}),t.unmounted)return;let u=!0;r(()=>{u=!1});let p=new rn({context:c,user:{name:o.name,color:o.color},onStatus:e=>{u&&(this.#u=e,this.#D())}});if(r(()=>{l=p.close()}),p.awareness.on(`change`,()=>this.#D()),await p.open(),t.unmounted)return;let m=this.#C();if(m.kind===`failed`)throw Error(m.message);let h=await d(c,{key:`doc`,readSeed:async()=>{let{rev:e,state:t}=await f(c,`doc`);return{rev:e,state:Lt.parse(t)}}});if(r(()=>void h.dispose()),t.unmounted)return;r(h.store.subscribe(()=>{let e=h.store.get();e?.commitOid!==this.#p?.commitOid&&p.sync();let t=e?.threads!==this.#p?.threads;this.#p=e,this.#D(),t&&this.#O()})),this.#p=h.store.get(),this.#c=p,this.#m=c,this.#l=new et(p.text),e.setState(b.create({doc:p.text.toString(),extensions:[this.#w(),$e(p.text,p.awareness,{undoManager:this.#l}),w.of(at),this.options.commentOnly?Z:[]]})),this.#v({selecting:!1,previewText:p.text.toString()}),this.#D(),this.#O()}catch(e){for(let e of n.reverse()){let n=t.cleanups.indexOf(e);n<0||(t.cleanups.splice(n,1),e())}this.#u={kind:`failed`,message:e instanceof Error?e.message:String(e)},this.#D()}finally{this.#f=!1}}#C(){return this.#u}#w(){return[this.options.kind===`markdown`?bn({mode:this.#e.mode===`markdown`?`markdown`:`rich`,preview:this.#n}):xn({language:this.#r.of(this.#i)}),Xe({topContainer:this.#y()}),E.contentAttributes.of({"aria-label":this.options.path}),X,cn,w.of([{key:`Mod-Alt-m`,run:()=>this.startComment(),preventDefault:!0}]),E.updateListener.of(e=>{e.startState.field(X)!==e.state.field(X)&&this.#M();let t=!e.state.selection.main.empty;t!==this.#e.selecting&&this.#v({selecting:t})}),this.options.kind===`html`?E.updateListener.of(e=>{e.docChanged&&this.#E()}):[]]}async#T(){this.#i=await Sn(this.options.path),this.#o?.dispatch({effects:this.#r.reconfigure(this.#i)})}#E(){this.#a||=setTimeout(()=>{this.#a=void 0,this.#o&&this.#v({previewText:this.#o.state.doc.toString()})},500)}#D(){let e=this.#p,t=this.#u.kind===`failed`?{kind:this.#c?`disconnected`:`unavailable`,message:this.#u.message}:!this.#c||!e?{kind:`opening`}:e.saveError?{kind:`save-failed`,message:e.saveError}:e.dirty||!e.commitOid?{kind:`editing`}:{kind:`saved`,oid:e.commitOid,by:e.savedBy},n=this.#c,r=n?[...n.awareness.getStates()].filter(([e])=>e!==n.doc.clientID).flatMap(([,e])=>{let t=Tn.safeParse(e);return t.success?[t.data.user.name]:[]}):[];this.#v({status:t,others:r})}#O(){let e=this.#p?this.#p.threads:[],t=this.#e.draft;t&&e.some(e=>e.id===t.thread)&&this.#v({draft:null}),this.#j(this.#e.active),this.#M(),this.#k()}#k(){let e=this.#m;if(!e)return;let t=this.#p?this.#p.threads:[],n=new Set(t.flatMap(e=>!e.resolved&&e.routedTo?[e.routedTo]:[]));for(let[e,t]of this.#_)n.has(e)||(t(),this.#_.delete(e),this.#A(e,!1));for(let t of n){if(this.#_.has(t))continue;let n=e.cd(t),r=new AbortController,i=d(n,{key:`agent`,readSeed:()=>f(n,`agent`),signal:r.signal}).then(e=>{let n=()=>{if(r.signal.aborted)return;let n=Cn.safeParse(e.store.get());this.#A(t,n.success&&wn(n.data))};return n(),{live:e,unsubscribe:e.store.subscribe(n)}});i.catch(()=>void 0),this.#_.set(t,()=>{r.abort(),i.then(({live:e,unsubscribe:t})=>(t(),e.dispose())).catch(()=>void 0).finally(()=>n[Symbol.dispose]())})}}#A(e,t){this.#e.thinking.includes(e)!==t&&this.#v({thinking:t?[...this.#e.thinking,e]:this.#e.thinking.filter(t=>t!==e)})}#j(e){let t=(this.#p?this.#p.threads:[]).filter(e=>!e.resolved),n=this.#e.draft,r=[...t,...n?[{id:n.thread,quote:n.quote}]:[]].flatMap(e=>e.quote?[{id:e.id,quote:e.quote}]:[]);this.#o?.dispatch({effects:on.of({threads:r,active:e})})}#M(){let e=this.#o?.state.field(X,!1),t=e?e.ranges:/* @__PURE__ */ new Map,n=e?e.active:this.#e.active,r=this.#p?this.#p.threads:[],i=e=>{let n=t.get(e.id);return e.quote?n?n.from:1/0:-1},a=[...r].sort((e,t)=>i(e)-i(t)).map(e=>({...e,attached:i(e)!==1/0})),o=a.map(e=>`${e.id}${e.attached?``:`!`}`).join(` `);(o!==this.#g||r!==this.#h||n!==this.#e.active)&&(this.#g=o,this.#h=r,this.#v({threads:a,active:n}))}startComment(){let e=this.#o;if(!e||!this.#m)return!1;let t=e.state.doc.toString(),{from:n,to:r}=e.state.selection.main;for(;n<r&&/\s/.test(t[n]);)n++;for(;r>n&&/\s/.test(t[r-1]);)r--;let i=crypto.randomUUID();return this.#v({draft:{thread:i,quote:r>n?Xt(t,n,r):null},active:i}),this.#j(i),!0}cancelDraft(){this.#v({draft:null,active:null}),this.#j(null)}async postDraft(e){let t=this.#e.draft;t&&await this.#N(B,{thread:t.thread,quote:t.quote,body:e})}reply(e,t){return this.#N(V,{thread:e,comment:crypto.randomUUID(),body:t})}startEditing(e,t){this.#v({editing:{thread:e,comment:t}})}stopEditing(){this.#v({editing:null})}async editComment(e,t,n){await this.#N(H,{thread:e,comment:t,body:n}),this.stopEditing()}deleteComment(e,t){return this.#N(U,{thread:e,comment:t})}resolve(e){return this.#N(Et,{thread:e})}reopen(e){return this.#N(Dt,{thread:e})}focusThread(e){this.#v({active:e}),this.#j(e);let t=this.#o?.state.field(X,!1)?.ranges.get(e);t&&(this.#e.mode===`preview`&&this.setMode(`source`),this.#o?.dispatch({effects:E.scrollIntoView(t.from,{y:`center`})}))}async#N(e,t){if(!this.#m)throw Error(`The doc isn't open yet`);await this.#m.append({type:e,payload:t})}reconnect(){if(this.#c)return void this.#c.sync();this.#o&&this.#d&&!this.#f&&this.#S(this.#o,this.#d)}setMode(e){(e===`rich`||e===`markdown`)&&this.#o?.dispatch({effects:this.#n.reconfigure(gn(e))}),e===`preview`&&this.#o&&Ke(this.#o),this.#v({mode:e}),e!==`preview`&&this.#o?.focus()}run(e){this.#o&&e(this.#o)}undo(){this.#l?.undo()}redo(){this.#l?.redo()}};function On(e){let t=0;for(let n of e)t=t*31+n.charCodeAt(0)|0;let n=[`var(--chart-1)`,`var(--chart-2)`,`var(--chart-3)`,`var(--chart-4)`,`var(--chart-5)`,`var(--info)`,`var(--success)`,`var(--warning)`];return n[Math.abs(t)%n.length]}const kn={markdown:[[`rich`,`Rich`],[`markdown`,`Markdown`]],html:[[`preview`,`Preview`],[`source`,`Source`]],code:[]};function An({session:e,listHref:t,listLabel:n,editHref:r,onNavigate:i,stream:a,unavailable:o}){let s=(0,k.useSyncExternalStore)(e.subscribe,e.state,e.state),{kind:c,commentOnly:l,path:u,repo:d}=e.options,f=jn(s.mode,c),p=/* @__PURE__ */ (0,P.jsx)(Nn,{session:e,selecting:s.selecting,opening:s.status.kind===`opening`});return/* @__PURE__ */ (0,P.jsxs)(`div`,{className:f.container,children:[/* @__PURE__ */ (0,P.jsxs)(`div`,{className:`sticky top-0 z-10 shrink-0 bg-background`,children:[/* @__PURE__ */ (0,P.jsxs)(`div`,{className:`flex min-h-11 flex-wrap items-center gap-x-4 gap-y-1 border-b px-4 py-1.5`,children:[/* @__PURE__ */ (0,P.jsxs)(`p`,{className:`flex min-w-0 gap-2 font-mono text-xs text-muted-foreground`,children:[/* @__PURE__ */ (0,P.jsx)(Mn,{href:t,onNavigate:i,className:`hover:text-foreground`,children:n}),/* @__PURE__ */ (0,P.jsx)(`span`,{"aria-hidden":!0,children:`/`}),/* @__PURE__ */ (0,P.jsx)(`span`,{className:`truncate`,children:u})]}),c===`markdown`&&!l?/* @__PURE__ */ (0,P.jsxs)(P.Fragment,{children:[/* @__PURE__ */ (0,P.jsx)(zn,{session:e}),/* @__PURE__ */ (0,P.jsx)(Rn,{session:e})]}):null,/* @__PURE__ */ (0,P.jsxs)(`div`,{className:`ml-auto flex min-w-0 flex-wrap items-center justify-end gap-3`,children:[s.others.length>0&&/* @__PURE__ */ (0,P.jsxs)(`p`,{"aria-label":`Also here`,className:`min-w-0 text-xs wrap-anywhere text-muted-foreground`,children:[`Also here: `,s.others.join(`, `)]}),l?null:p,/* @__PURE__ */ (0,P.jsx)(Pn,{session:e,mode:s.mode}),a?/* @__PURE__ */ (0,P.jsx)(je,{...a,path:It({repo:d,path:u})}):null]})]}),l?/* @__PURE__ */ (0,P.jsxs)(`div`,{className:`flex min-h-11 flex-wrap items-center justify-between gap-2 border-b px-4 py-1.5`,children:[/* @__PURE__ */ (0,P.jsxs)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:[s.selecting?`Comment on the selected text`:`Select text to comment on it`,` ·`,` `,/* @__PURE__ */ (0,P.jsx)(Mn,{href:r,onNavigate:i,className:`underline hover:text-foreground`,children:`Edit`})]}),p]}):null,/* @__PURE__ */ (0,P.jsx)(`div`,{ref:e.mountPanels})]}),/* @__PURE__ */ (0,P.jsxs)(`div`,{className:f.body,children:[/* @__PURE__ */ (0,P.jsxs)(`div`,{className:f.column,children:[s.status.kind===`unavailable`?/* @__PURE__ */ (0,P.jsxs)(`div`,{role:`alert`,className:`mt-4 flex flex-col gap-1.5 rounded-lg border border-destructive/40 p-3 text-sm`,children:[/* @__PURE__ */ (0,P.jsx)(`p`,{className:`font-medium`,children:`Couldn't open this doc for editing`}),/* @__PURE__ */ (0,P.jsx)(`p`,{className:`font-mono text-xs text-destructive`,children:s.status.message}),o,/* @__PURE__ */ (0,P.jsx)(g,{size:`xs`,variant:`outline`,className:`self-start`,onClick:()=>e.reconnect(),children:`Try again`})]}):null,s.mode===`preview`?/* @__PURE__ */ (0,P.jsx)(Fn,{path:u,html:s.previewText}):null,/* @__PURE__ */ (0,P.jsx)(`div`,{ref:e.mount,className:f.editor})]}),s.threads.length>0||s.draft?/* @__PURE__ */ (0,P.jsx)(F,{session:e,state:s}):null]}),/* @__PURE__ */ (0,P.jsx)(`p`,{role:`status`,className:`sticky bottom-0 shrink-0 border-t bg-background px-4 py-1.5 font-readme text-xs text-muted-foreground`,children:/* @__PURE__ */ (0,P.jsx)(In,{status:s.status,onRetry:()=>e.reconnect()})})]})}function jn(e,t){let n=t===`markdown`;return{container:n?`flex min-w-0 flex-1 flex-col`:`flex min-h-0 min-w-0 flex-1 flex-col`,body:n?`flex flex-1 flex-col md:flex-row`:`flex min-h-0 flex-1 flex-col overflow-auto md:flex-row`,column:e===`preview`?`flex min-h-0 min-w-0 flex-1 flex-col`:n?`mx-auto w-full max-w-3xl min-w-0 flex-1 px-4 md:px-8`:`flex min-h-64 w-full min-w-0 flex-1 flex-col md:min-h-0`,editor:e===`preview`?`hidden`:n?`docs-editor pt-4`:`docs-editor min-h-0 min-w-0 flex-1 overflow-hidden`}}function Mn({href:e,onNavigate:t,className:n,children:r}){return/* @__PURE__ */ (0,P.jsx)(`a`,{href:e,className:n,onClick:n=>{t&&y(n)&&(n.preventDefault(),t(e))},children:r})}function Nn({session:e,selecting:t,opening:n}){let{commentOnly:r}=e.options;return/* @__PURE__ */ (0,P.jsxs)(g,{size:`xs`,variant:r&&t?`default`:`ghost`,title:r?`Comment on the selection`:`Comment on the selection (⌘⌥M)`,disabled:n,onMouseDown:e=>e.preventDefault(),onClick:()=>e.startComment(),children:[/* @__PURE__ */ (0,P.jsx)(ue,{}),`Comment`]})}function Pn({session:e,mode:t}){let n=kn[e.options.kind];return n.length===0?null:/* @__PURE__ */ (0,P.jsx)(`div`,{role:`group`,"aria-label":`Mode`,className:`flex rounded-lg border p-0.5`,children:n.map(([n,r])=>/* @__PURE__ */ (0,P.jsx)(g,{size:`xs`,variant:t===n?`secondary`:`ghost`,"aria-pressed":t===n,onClick:()=>e.setMode(n),children:r},n))})}function Fn({path:e,html:t}){let n=(0,k.useCallback)(e=>{if(!e)return;let n=URL.createObjectURL(new Blob([t],{type:`text/html;charset=utf-8`}));return e.src=n,()=>URL.revokeObjectURL(n)},[t]);return/* @__PURE__ */ (0,P.jsx)(`iframe`,{ref:n,title:`Preview of ${e}`,sandbox:`allow-scripts allow-popups allow-forms`,className:`w-full flex-1 bg-white`},t)}function In({status:e,onRetry:t}){if(e.kind===`opening`)return`Opening…`;if(e.kind===`editing`)return`Editing…`;if(e.kind===`save-failed`)return/* @__PURE__ */ (0,P.jsxs)(`span`,{className:`text-destructive`,children:[`Couldn't save: `,e.message,`. The text is kept, and the next edit saves again.`]});if(e.kind===`unavailable`)return`Not open: the text is the file as it was read.`;if(e.kind===`disconnected`)return/* @__PURE__ */ (0,P.jsxs)(`span`,{className:`text-destructive`,children:[`Lost the connection: `,e.message,`. Your text is still here.`,` `,/* @__PURE__ */ (0,P.jsx)(`button`,{type:`button`,className:`underline`,onClick:t,children:`Try again`})]});let n=`Saved ${e.oid.slice(0,7)}`;return e.by.length>0?`${n} (${e.by.join(`, `)})`:n}const Q=e=>t=>t.run(e),Ln=[[{label:`Undo`,icon:/* @__PURE__ */ (0,P.jsx)(_e,{}),run:e=>e.undo()},{label:`Redo`,icon:/* @__PURE__ */ (0,P.jsx)(ge,{}),run:e=>e.redo()}],[{label:`Bold`,icon:/* @__PURE__ */ (0,P.jsx)(be,{}),run:Q(e=>A(e,`**`))},{label:`Italic`,icon:/* @__PURE__ */ (0,P.jsx)(me,{}),run:Q(e=>A(e,`_`))},{label:`Strikethrough`,icon:/* @__PURE__ */ (0,P.jsx)(le,{}),run:Q(e=>A(e,`~~`))},{label:`Inline code`,icon:/* @__PURE__ */ (0,P.jsx)(ye,{}),run:Q(e=>A(e,"`"))}],[{label:`Bulleted list`,icon:/* @__PURE__ */ (0,P.jsx)(ee,{}),run:Q(e=>j(e,`- `))},{label:`Numbered list`,icon:/* @__PURE__ */ (0,P.jsx)(ve,{}),run:Q(e=>j(e,`1. `))},{label:`Checklist`,icon:/* @__PURE__ */ (0,P.jsx)(ae,{}),run:Q(e=>j(e,`- [ ] `))}],[{label:`Link`,icon:/* @__PURE__ */ (0,P.jsx)(oe,{}),run:Q(N)},{label:`Table`,icon:/* @__PURE__ */ (0,P.jsx)(he,{}),run:Q(e=>M(e,`| Column | Column | +import{r as e}from"../../chunks/rolldown-runtime.mjs";import{a as t,n}from"../../chunks/vendor-react";import{_ as r,d as i,f as a,h as o,i as s,l as c,r as l,v as u}from"../../chunks/vendor-zod";import{o as d,t as f}from"../../chunks/react.mjs";import{M as p,Mt as m,Z as h,f as ee}from"../../chunks/vendor-icons";import{_ as te,a as ne,c as re,d as ie,f as ae,g as oe,h as se,i as ce,l as le,m as ue,n as de,o as fe,p as pe,r as me,s as he,t as ge,u as _e,v as ve,y as ye}from"../../chunks/docs-editor-icons";import{c as be,i as g,r as xe,t as Se}from"../../chunks/ui-base";import{Spinner as Ce}from"../ui/spinner";import{G as _,a as we,h as Te,i as Ee,r as De,t as Oe}from"../../chunks/ui-shell";import{NativeSelect as ke,NativeSelectOption as v}from"../ui/native-select";import{plainLeftClick as y}from"../../lib/plain-left-click";import{t as b}from"../../chunks/usingCtx.mjs";import{StreamLink as Ae}from"../stream-link";import{At as x,Et as je,Ft as S,I as Me,Mt as C,O as Ne,Ot as w,Pt as Pe,Q as Fe,S as Ie,St as T,T as Le,_t as Re,ct as ze,d as Be,dt as E,f as Ve,ft as D,k as He,lt as Ue,mt as We,ot as Ge,u as Ke,ut as qe,vt as Je,wt as Ye,xt as Xe,yt as Ze}from"../../chunks/vendor-codemirror";import{a as Qe,c as $e,d as et,f as tt,i as nt,l as O,n as rt,o as it,r as at,s as ot,t as st,u as ct}from"../../chunks/vendor-yjs";import{a as lt,c as ut,i as dt,l as ft,n as pt,o as mt,r as ht,s as gt,t as k,u as _t}from"../../chunks/vendor-atomic";import{sourceEditorExtensions as vt}from"../../lib/source-editor";var A=/* @__PURE__ */ e(t(),1);function j(e,t){let{from:n,to:r}=e.state.selection.main,i=t.length,a=e.state.sliceDoc(n-i,n)===t&&e.state.sliceDoc(r,r+i)===t;return e.dispatch(a?{changes:[{from:n-i,to:n},{from:r,to:r+i}]}:{changes:[{from:n,insert:t},{from:r,insert:t}],selection:{anchor:n+i,head:r+i}}),e.focus(),!0}const yt=/^(#{1,6} |> |- \[[ xX]\] |[-*+] |\d+\. )/;function M(e,t){let{from:n,to:r}=e.state.selection.main,i=[];for(let a=e.state.doc.lineAt(n).number;a<=e.state.doc.lineAt(r).number;a++){let n=e.state.doc.line(a),r=n.text.match(yt)?.[0]||``;i.push({from:n.from,to:n.from+r.length,insert:t})}return e.dispatch({changes:i}),e.focus(),!0}function N(e,t){let n=e.state.doc.lineAt(e.state.selection.main.head);return e.dispatch({changes:{from:n.to,insert:`\n\n${t}\n`},selection:{anchor:n.to+2}}),e.focus(),!0}function bt(e,t){let{from:n,to:r}=e.state.selection.main,i=e.state.sliceDoc(n,r)||t;return e.dispatch({changes:{from:n,to:r,insert:`[${i}](${t})`},selection:{anchor:n+1,head:n+1+i.length}}),e.focus(),!0}function P(e){let t=window.prompt(`Link URL`);return!t||bt(e,t)}var F=/* @__PURE__ */ e(n(),1);function I({session:e,state:t}){let n=t.threads.filter(e=>!e.resolved),r=n=>/* @__PURE__ */ (0,F.jsx)(St,{session:e,thread:n,active:t.active===n.id,editing:t.editing&&t.editing.thread===n.id?t.editing.comment:null,thinking:!!(n.routedTo&&t.thinking.includes(n.routedTo))},n.id),i=n.filter(e=>!e.attached),a=t.threads.filter(e=>e.resolved);return/* @__PURE__ */ (0,F.jsxs)(`aside`,{"aria-label":`Comments`,className:`flex shrink-0 flex-col gap-3 border-t p-3 wrap-anywhere md:sticky md:top-0 md:max-h-[calc(100svh-4.75rem)] md:w-80 md:self-start md:overflow-y-auto md:border-t-0 md:border-l`,children:[t.draft?/* @__PURE__ */ (0,F.jsxs)(`article`,{"aria-label":`New comment`,ref:xt,className:`flex scroll-mb-12 flex-col gap-2 rounded-lg border bg-card p-3 text-sm shadow-xs ring-2 ring-highlight`,children:[/* @__PURE__ */ (0,F.jsx)(L,{quote:t.draft.quote,gone:!1}),/* @__PURE__ */ (0,F.jsx)(R,{label:`Comment`,placeholder:`Add a comment…`,submit:`Comment`,onSubmit:t=>e.postDraft(t),onCancel:()=>e.cancelDraft(),keepPending:!0})]}):null,n.filter(e=>e.attached).map(r),i.length>0?/* @__PURE__ */ (0,F.jsxs)(F.Fragment,{children:[/* @__PURE__ */ (0,F.jsx)(`h3`,{className:`pt-1 text-xs text-muted-foreground`,children:`On text that's gone`}),i.map(r)]}):null,a.length>0?/* @__PURE__ */ (0,F.jsxs)(`details`,{className:`text-sm`,children:[/* @__PURE__ */ (0,F.jsxs)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground`,children:[`Resolved (`,a.length,`)`]}),/* @__PURE__ */ (0,F.jsx)(`div`,{className:`mt-2 flex flex-col gap-3`,children:a.map(r)})]}):null]})}function xt(e){let t=()=>e.scrollIntoView({block:`nearest`});t();let n=new IntersectionObserver(([e])=>{e&&e.intersectionRatio<1&&t()},{threshold:1,rootMargin:`0px 0px -48px 0px`});n.observe(e);let r=()=>{n.disconnect(),clearTimeout(i),removeEventListener(`wheel`,r),removeEventListener(`touchmove`,r)},i=setTimeout(r,1500);return addEventListener(`wheel`,r,{passive:!0}),addEventListener(`touchmove`,r,{passive:!0}),r}function St({session:e,thread:t,active:n,editing:r,thinking:i}){let a=e.options.user.email;return/* @__PURE__ */ (0,F.jsxs)(`article`,{"aria-label":t.quote?`Comment on “${t.quote.exact}”`:`Comment on the doc`,"aria-current":n||void 0,className:be(`flex flex-col gap-2 rounded-lg border bg-card p-3 text-sm shadow-xs`,n&&`ring-2 ring-highlight`,t.resolved&&`opacity-80`),children:[/* @__PURE__ */ (0,F.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[/* @__PURE__ */ (0,F.jsx)(`button`,{type:`button`,title:`Show in the doc`,className:`min-w-0 flex-1 cursor-pointer text-left`,onClick:()=>e.focusThread(t.id),children:/* @__PURE__ */ (0,F.jsx)(L,{quote:t.quote,gone:!t.attached})}),t.resolved?/* @__PURE__ */ (0,F.jsx)(g,{size:`icon-xs`,variant:`ghost`,"aria-label":`Reopen`,title:`Resolved by ${B(t.resolved.by)}. Reopen`,onClick:()=>void e.reopen(t.id),children:/* @__PURE__ */ (0,F.jsx)(fe,{})}):/* @__PURE__ */ (0,F.jsx)(g,{size:`icon-xs`,variant:`ghost`,"aria-label":`Resolve`,title:`Resolve`,onClick:()=>void e.resolve(t.id),children:/* @__PURE__ */ (0,F.jsx)(m,{})})]}),/* @__PURE__ */ (0,F.jsx)(`ol`,{className:`flex flex-col gap-2`,children:t.comments.map(i=>/* @__PURE__ */ (0,F.jsx)(Ct,{comment:i,mine:i.author===a&&n,editing:r===i.id,onEdit:()=>e.startEditing(t.id,i.id),onSave:n=>e.editComment(t.id,i.id,n),onCancel:()=>e.stopEditing(),onDelete:()=>e.deleteComment(t.id,i.id)},i.id))}),i?/* @__PURE__ */ (0,F.jsxs)(`p`,{role:`status`,className:`flex items-center gap-1.5 font-readme text-xs text-muted-foreground`,children:[/* @__PURE__ */ (0,F.jsx)(te,{"aria-hidden":!0,className:`size-4 animate-pulse text-success`}),`Thinking…`]}):null,t.resolved?/* @__PURE__ */ (0,F.jsxs)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:[`Resolved by `,B(t.resolved.by)]}):n?/* @__PURE__ */ (0,F.jsx)(R,{label:`Reply`,placeholder:`Reply…`,submit:`Reply`,onSubmit:n=>e.reply(t.id,n)}):null]})}function Ct({comment:e,mine:t,editing:n,onEdit:r,onSave:i,onCancel:a,onDelete:o}){let[s,c,l]=(0,A.useActionState)(async()=>z(o()),null);return/* @__PURE__ */ (0,F.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[/* @__PURE__ */ (0,F.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[/* @__PURE__ */ (0,F.jsxs)(`span`,{title:e.author,children:[/* @__PURE__ */ (0,F.jsx)(`span`,{className:`font-medium`,children:B(e.author)}),e.via?/* @__PURE__ */ (0,F.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.via]}):null]}),/* @__PURE__ */ (0,F.jsx)(`time`,{dateTime:e.at,className:`text-xs text-muted-foreground`,suppressHydrationWarning:!0,children:wt.format(new Date(e.at))})]}),n?/* @__PURE__ */ (0,F.jsx)(R,{label:`Edit comment`,placeholder:``,submit:`Save`,defaultValue:e.body,onSubmit:i,onCancel:a}):/* @__PURE__ */ (0,F.jsxs)(`p`,{className:`whitespace-pre-wrap`,children:[e.body,e.edited?/* @__PURE__ */ (0,F.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:` (edited)`}):null]}),t&&!n?/* @__PURE__ */ (0,F.jsxs)(`div`,{className:`flex gap-1`,children:[/* @__PURE__ */ (0,F.jsx)(g,{size:`icon-xs`,variant:`ghost`,"aria-label":`Edit`,title:`Edit`,onClick:r,children:/* @__PURE__ */ (0,F.jsx)(p,{})}),/* @__PURE__ */ (0,F.jsx)(g,{size:`icon-xs`,variant:`ghost`,"aria-label":`Delete`,title:`Delete`,disabled:l,onClick:()=>(0,A.startTransition)(c),children:/* @__PURE__ */ (0,F.jsx)(ee,{})})]}):null,s?.error?/* @__PURE__ */ (0,F.jsx)(`p`,{className:`text-xs text-destructive`,children:s.error}):null]})}function L({quote:e,gone:t}){return e?/* @__PURE__ */ (0,F.jsx)(`span`,{className:be(`line-clamp-2 border-l-2 border-highlight pl-2 text-xs text-muted-foreground`,t&&`line-through`),children:e.exact}):/* @__PURE__ */ (0,F.jsx)(`span`,{className:`block font-readme text-xs text-muted-foreground`,children:`On the whole doc`})}function R({label:e,placeholder:t,submit:n,defaultValue:r,onSubmit:i,onCancel:a,keepPending:o}){let[s,c]=(0,A.useState)(r||``),[l,u,d]=(0,A.useActionState)(async e=>{let t=s.trim();if(!t)return e;let n=await z(i(t));return n.error||c(``),n},null),f=d||!!(o&&l&&!l.error);return/* @__PURE__ */ (0,F.jsxs)(`form`,{className:`flex flex-col gap-1.5`,action:u,children:[/* @__PURE__ */ (0,F.jsx)(Se,{name:`body`,"aria-label":e,placeholder:t,value:s,onChange:e=>c(e.target.value),rows:2,autoFocus:!!a,className:`min-h-0`,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit()),e.key===`Escape`&&a&&a()}}),l?.error?/* @__PURE__ */ (0,F.jsx)(`p`,{className:`text-xs text-destructive`,children:l.error}):null,/* @__PURE__ */ (0,F.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[a?/* @__PURE__ */ (0,F.jsx)(g,{type:`button`,size:`xs`,variant:`ghost`,onClick:a,children:`Cancel`}):null,/* @__PURE__ */ (0,F.jsx)(g,{type:`submit`,size:`xs`,disabled:f,children:f?`Posting…`:n})]})]})}const wt=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`});async function z(e){try{return await e,{error:null}}catch(e){return{error:e instanceof Error?e.message:String(e)}}}function B(e){return e.includes(`@`)?e.split(`@`)[0]:e}const V=`docs/comment-added`,H=`docs/comment-replied`,U=`docs/comment-edited`,Tt=`docs/comment-deleted`,Et=`docs/comment-resolved`,Dt=`docs/comment-reopened`,Ot=[V,H,U,Tt,Et,Dt,`docs/comment-reanchored`,`docs/comment-routed`],W=a({exact:o().min(1),prefix:o(),suffix:o()}),kt=o().trim().min(1).max(40).optional();a({thread:o().min(1),quote:W.nullable(),body:o().min(1),via:kt}),a({thread:o(),comment:o().min(1),body:o().min(1),via:kt}),a({thread:o(),comment:o(),body:o().min(1)}),a({thread:o(),comment:o()}),a({thread:o()}),a({thread:o(),quote:W.nullable()}),a({thread:o(),to:o().min(1).nullable()});const At=a({id:o(),author:o(),via:o().nullable().default(null),body:o(),at:o(),edited:s()}),jt=a({id:o(),quote:W.nullable(),detached:s(),resolved:a({by:o(),at:o()}).nullable(),routedTo:o().nullable().default(null),comments:l(At)}),G=`docs/edit-frame`,Mt=`docs/awareness-frame`,Nt=`docs/left`,K=`docs/opened`,Pt=a({update:o(),client:r([i(),c(`processor`)])}),Ft=a({update:o(),client:i()});a({client:i()});function It(e){let t=/^\/repos\/([^/]+)$/.exec(e.repo)?.[1];if(!t)throw Error(`not a repo Docs edits: ${e.repo} (a repo is /repos/<name>)`);return`/docs/${t}/${e.path}`}const Lt=a({commitOid:o().nullable(),dirty:s(),savedBy:l(o()),saveError:o().nullable(),threads:l(jt)});function q(e){let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}function J(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}const Rt=new Set(`png jpg jpeg gif webp avif heic ico bmp tif tiff psd pdf zip gz tgz tar bz2 xz 7z rar jar wasm bin exe dll so dylib woff woff2 ttf otf eot mp3 wav ogg flac m4a mp4 mov webm avi mkv sqlite db`.split(` `));function zt(e){let t=e.split(`/`).at(-1),n=t.includes(`.`)?t.split(`.`).at(-1).toLowerCase():``;return n===`md`||n===`markdown`||n===`mdx`?`markdown`:n===`html`||n===`htm`?`html`:Rt.has(n)?`binary`:`code`}async function Y(e){try{var t=b();let n=t.u(e.mind.repos.get(e.repo)),{commitOid:r,paths:i}=await n.listFiles();if(i.includes(e.path))return;await n.commitFiles({message:`docs: new ${e.path}`,changes:[{path:e.path,content:zt(e.path)===`markdown`?`# ${e.heading}\n`:``}],parent:r,author:e.author})}catch(e){t.e=e}finally{t.d()}}function Bt(e){return e.email?{name:e.email,email:e.email}:void 0}function Vt(e){let t=e.replace(/\.md$/i,``).split(`/`).map(e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``)).filter(Boolean);return t.length>0?`${t.join(`/`)}.md`:``}function Ht(e){return e.split(`/`).at(-1).trim()}const Ut=a({payload:a({path:o()})});var Wt=class{#e={kind:`loading`};#t=/* @__PURE__ */ new Set;mind;repo;#n=null;#r=null;constructor(e,t){this.mind=e,this.repo=t}subscribe=e=>(this.#t.add(e),this.#t.size===1&&this.#a(),()=>{this.#t.delete(e),this.#t.size===0&&(this.#r?.(),this.#r=null)});state=()=>this.#e;reload(){this.#n&&this.#o(this.#n)}#i(e){this.#e=e;for(let e of this.#t)e()}#a(){let e=null,t=!1,n={};this.#r=()=>{t=!0,this.#n=null,e?.[Symbol.dispose]()},(async()=>{let r=await this.mind.subscribe({consumes:[`events.iterate.com/repo/commit-completed`],target:e=>{l(u()).parse(JSON.parse(JSON.stringify(e))).some(e=>Ut.safeParse(e).data?.payload.path===this.repo)&&this.#o(n)}});if(t)return r[Symbol.dispose]();e=r,this.#n=n,await this.#o(n)})().catch(e=>{t||this.#i({kind:`failed`,message:Gt(e)})})}async#o(e){try{try{var t=b();let{paths:n}=await t.u(this.mind.repos.get(this.repo)).listFiles();this.#n===e&&this.#i({kind:`loaded`,paths:n.toSorted()})}catch(e){t.e=e}finally{t.d()}}catch(t){this.#n===e&&this.#i({kind:`failed`,message:Gt(t)})}}};function Gt(e){return e instanceof Error?e.message:String(e)}function Kt({list:e,author:t,docHref:n,onOpen:r}){let i=(0,A.useSyncExternalStore)(e.subscribe,e.state,e.state),[a,o,s]=(0,A.useActionState)(async(n,i)=>{let a=String(i.get(`title`)),o=Vt(a);if(!o)return{error:`A title needs a letter or a digit in it.`};try{await Y({mind:e.mind,repo:e.repo,path:o,heading:Ht(a),author:t})}catch(e){return{error:e instanceof Error?e.message:String(e)}}return e.reload(),r(o),null},null);return/* @__PURE__ */ (0,F.jsxs)(`main`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-6 p-4 md:p-8`,children:[/* @__PURE__ */ (0,F.jsxs)(`form`,{action:o,className:`flex gap-2`,children:[/* @__PURE__ */ (0,F.jsx)(xe,{name:`title`,"aria-label":`New doc title`,placeholder:`New doc title, or folder/title`,autoFocus:!0,required:!0}),/* @__PURE__ */ (0,F.jsx)(g,{type:`submit`,disabled:s,children:s?`Creating…`:`New doc`})]}),a?.error?/* @__PURE__ */ (0,F.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:a.error}):null,i.kind===`loading`?/* @__PURE__ */ (0,F.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`Loading docs…`}):i.kind===`failed`?/* @__PURE__ */ (0,F.jsxs)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:[`Couldn't list the docs: `,i.message]}):i.paths.length>0?/* @__PURE__ */ (0,F.jsx)(`ul`,{"aria-label":`Docs`,className:`flex flex-col divide-y rounded-lg border`,children:i.paths.map(e=>/* @__PURE__ */ (0,F.jsx)(`li`,{children:/* @__PURE__ */ (0,F.jsx)(`a`,{href:n(e),onClick:t=>{y(t)&&(t.preventDefault(),r(e))},className:`block px-4 py-2.5 font-mono text-sm hover:bg-muted`,children:e})},e))}):/* @__PURE__ */ (0,F.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`No docs yet.`})]})}function qt(e){return/* @__PURE__ */ (0,F.jsx)(A.Suspense,{fallback:/* @__PURE__ */ (0,F.jsx)(`p`,{className:`px-2 py-1 font-readme text-xs text-muted-foreground`,children:`Loading files…`}),children:/* @__PURE__ */ (0,F.jsx)(Yt,{...e})})}let Jt;function Yt({list:e,openPath:t,onOpen:n,author:r}){let{PierreDocTree:i}=(0,A.use)(Jt||=import(`./doc-tree`)),a=(0,A.useSyncExternalStore)(e.subscribe,e.state,e.state),[o,s]=(0,A.useState)(null),c=(0,A.useRef)({openPath:t,onOpen:n,author:r});(0,A.useEffect)(()=>{c.current={openPath:t,onOpen:n,author:r}});let l=(0,A.useMemo)(()=>new i({list:e,openPath:()=>c.current.openPath,open:e=>c.current.onOpen(e),create:async t=>{s({path:t,error:null});try{await Y({mind:e.mind,repo:e.repo,path:t,heading:t.split(`/`).at(-1).replace(/\.[^.]+$/,``),author:c.current.author})}catch(e){throw s({path:t,error:e instanceof Error?e.message:String(e)}),e}e.reload(),s(null),c.current.onOpen(t)}}),[e,i]);return(0,A.useEffect)(()=>l.reveal(),[l,t]),/* @__PURE__ */ (0,F.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-1`,children:[a.kind===`loaded`?/* @__PURE__ */ (0,F.jsx)(`div`,{ref:l.mount,"aria-label":`Files`,className:`min-h-0 flex-auto`}):/* @__PURE__ */ (0,F.jsx)(`p`,{className:a.kind===`failed`?`px-2 py-1 text-xs text-destructive`:`px-2 py-1 font-readme text-xs text-muted-foreground`,children:a.kind===`failed`?`Couldn't list the files: ${a.message}`:`Loading files…`}),o&&!o.error?/* @__PURE__ */ (0,F.jsxs)(`p`,{className:`flex items-center gap-1.5 px-2 py-1 font-readme text-xs text-muted-foreground`,children:[/* @__PURE__ */ (0,F.jsx)(Ce,{}),`Creating `,o.path,`…`]}):null,o?.error?/* @__PURE__ */ (0,F.jsxs)(`p`,{role:`alert`,"data-type":`error`,className:`px-2 py-1 text-xs text-destructive`,children:[`Couldn't make `,o.path,`: `,o.error]}):null]})}function Xt(e,t,n){return{exact:e.slice(t,n),prefix:e.slice(Math.max(0,t-32),t),suffix:e.slice(n,n+32)}}function Zt(e,t){let n=en(e,t.exact);if(n.length>0){let r=n.reduce((n,r)=>Qt(e,t,r)>Qt(e,t,n)?r:n);return{from:r,to:r+t.exact.length,exact:!0}}return $t(e,t)}function Qt(e,t,n){let r=0;for(let i=1;i<=t.prefix.length&&e[n-i]===t.prefix.at(-i);i++)r++;let i=n+t.exact.length;for(let n=0;n<t.suffix.length&&e[i+n]===t.suffix[n];n++)r++;return r}function $t(e,t){let n=t.prefix?en(e,t.prefix).map(e=>e+t.prefix.length):[0],r=t.exact.length*2+16,i=null;for(let a of n){let n=t.suffix?e.indexOf(t.suffix,a):e.length;n<0||n-a>r||n===a||(!i||n-a<i.to-i.from)&&(i={from:a,to:n,exact:!1})}return i}function en(e,t){let n=[];for(let r=e.indexOf(t);r>=0;r=e.indexOf(t,r+1))n.push(r);return n}async function tn(e,t,n){await e.processors.enable(`docs`,{...n.facetSpec(`DocsDurableObject`),consumes:[`events.iterate.com/repo/commit-completed`,K]});let r=It(t);await e.append({type:K,payload:{repo:t.repo,path:t.path},idempotencyKey:`${K}:${r}`});let i=e.cd(r);return await i.processors.enable(`doc`,{...n.facetSpec(`DocDurableObject`),consumes:[G,`docs/commit-noticed`,Nt,...Ot]}),i}const nn=a({type:o(),payload:u()});var rn=class{doc=new ot;text=this.doc.getText(`file`);awareness=new st(this.doc);#e;#t;#n=[];#r=!1;#i=Promise.resolve();#a=null;#o=null;#s=!1;#c=!1;#l=!1;#u=null;constructor(e){this.#e=e.context,this.#t=e.onStatus,this.awareness.setLocalStateField(`user`,{name:e.user.name,color:e.user.color,colorLight:`color-mix(in oklab, ${e.user.color} 20%, transparent)`}),this.doc.on(`update`,(e,t)=>{t!==this&&this.#_(e)}),this.awareness.on(`update`,({added:e},t)=>{if(t!==this)return void this.#y();e.some(e=>e!==this.doc.clientID)&&this.#y()})}open(){return this.#o=this.#d(),this.#o}async#d(){this.#u=await this.#e.subscribe({consumes:[G,Mt],target:e=>{if(!this.#l)for(let t of e)this.#h(t)}}),await this.sync(),this.#y()}sync(){return this.#a?(this.#s=!0,this.#a):(this.#a=this.#f().finally(()=>{this.#a=null}),this.#a)}async#f(){do{this.#s=!1;try{let e=await this.#e.facets.get(`doc`).sync(q(et(this.doc)),this.doc.clientID);O(this.doc,J(e.update),this);let t=ct(this.doc,J(e.stateVector));this.#c=!1,t.length>2&&this.#_(t),this.#t({kind:`live`})}catch(e){this.#t({kind:`failed`,message:an(e)});return}}while(this.#s||this.#g())}#p;close(){return this.#p||=this.#m()}async#m(){this.#l=!0,nt(this.awareness,[this.doc.clientID],`left`),await this.#o?.catch(()=>{}),await this.#a,this.#u?.[Symbol.dispose](),this.awareness.destroy(),await this.#i,this.#c&&await this.sync(),await this.#e.append({type:Nt,ephemeral:!0,payload:{client:this.doc.clientID}}).catch(()=>{})}unsent(){return this.#r||this.#n.length>0||this.#c}#h(e){let t=nn.safeParse(JSON.parse(JSON.stringify(e)));if(!t.success)return;let n=t.data;if(n.type===`docs/awareness-frame`){let e=Ft.safeParse(n.payload);e.success&&e.data.client!==this.doc.clientID&&rt(this.awareness,J(e.data.update),this);return}let r=Pt.safeParse(n.payload);r.success&&r.data.client!==this.doc.clientID&&(O(this.doc,J(r.data.update),this),this.#g()&&this.sync())}#g(){return this.doc.store.pendingStructs!==null||this.doc.store.pendingDs!==null}#_(e){this.#n.push(e),this.#r||(this.#i=this.#v())}async#v(){this.#r=!0;try{for(;this.#n.length>0;){let e=tt(this.#n.splice(0));await this.#e.append({type:G,ephemeral:!0,payload:{update:q(e),client:this.doc.clientID}})}}catch(e){this.#n=[],this.#c=!0,this.#t({kind:`failed`,message:an(e)})}finally{this.#r=!1}}#y(){let e=at(this.awareness,[this.doc.clientID]);this.#e.append({type:Mt,ephemeral:!0,payload:{update:q(e),client:this.doc.clientID}}).catch(()=>{})}};function an(e){return e instanceof Error?e.message:String(e)}const on=Pe.define(),X=S.define({create:()=>({threads:[],ranges:/* @__PURE__ */ new Map,active:null}),update(e,t){let n=e;if(t.docChanged){let r=ln(e.ranges,t.changes);n={...e,ranges:un(t.state.doc,e.threads,r)}}for(let e of t.effects)if(e.is(on)){let r=t.state.doc,i=/* @__PURE__ */ new Map;for(let t of e.value.threads){let e=n.threads.find(e=>e.id===t.id),r=n.ranges.get(t.id),a=e&&e.quote.exact===t.quote.exact&&e.quote.prefix===t.quote.prefix&&e.quote.suffix===t.quote.suffix;r&&a&&i.set(t.id,r)}n={threads:e.value.threads,ranges:un(r,e.value.threads,i),active:e.value.active}}return t.isUserEvent(`select`)&&(n={...n,active:sn(n.ranges,t.state.selection.main.head)}),n},provide:e=>D.decorations.from(e,({ranges:e,active:t})=>E.set([...e].map(([e,n])=>E.mark({class:e===t?`cm-comment cm-comment-active`:`cm-comment`,attributes:{"data-thread":e}}).range(n.from,n.to)),!0))});function sn(e,t){let n=null;for(let r of e){let[,e]=r;e.from>t||e.to<t||(!n||e.to-e.from<n[1].to-n[1].from)&&(n=r)}return n&&n[0]}const cn=D.baseTheme({".cm-comment":{backgroundColor:`color-mix(in oklab, var(--highlight) 28%, transparent)`,borderBottom:`2px solid color-mix(in oklab, var(--highlight) 80%, transparent)`},".cm-comment-active":{backgroundColor:`color-mix(in oklab, var(--highlight) 60%, transparent)`}});function ln(e,t){let n=/* @__PURE__ */ new Map;for(let[r,i]of e){let e=t.mapPos(i.from,1),a=t.mapPos(i.to,-1);a>e&&n.set(r,{from:e,to:a})}return n}function un(e,t,n){let r=t.filter(e=>!n.has(e.id));if(r.length===0)return n;let i=e.toString();for(let e of r){let t=Zt(i,e.quote);t&&n.set(e.id,{from:t.from,to:t.to})}return n}const dn=/^---\n[\s\S]*?\n---(?=\n|$)/;var fn=class extends We{yaml;constructor(e){super(),this.yaml=e}eq(e){return e.yaml===this.yaml}toDOM(){let e=document.createElement(`dl`);e.className=`docs-properties`,e.setAttribute(`aria-label`,`Properties`);for(let t of this.yaml.split(` +`).slice(1,-1)){let n=t.indexOf(`:`);if(n<1)continue;let r=document.createElement(`dt`);r.textContent=t.slice(0,n).trim();let i=document.createElement(`dd`);i.textContent=t.slice(n+1).trim(),e.appendChild(r),e.appendChild(i)}return e}};function pn(e){let t=e.doc.toString().match(dn);if(!t)return E.none;let n=new fn(t[0]);return E.set([E.replace({block:!0,widget:n}).range(0,t[0].length)])}const mn=D.baseTheme({".docs-properties":{display:`grid`,gridTemplateColumns:`fit-content(40%) minmax(0, 1fr)`,gap:`0.125rem 1.25rem`,margin:`0.5rem 0 1rem`,fontSize:`0.8125rem`},".docs-properties dt":{color:`var(--muted-foreground)`}}),hn=S.define({create:pn,update:(e,t)=>t.docChanged?pn(t.state):e,provide:e=>[D.decorations.from(e),D.atomicRanges.of(t=>t.state.field(e)),mn]});function gn(e){return e===`rich`?[hn,pt(),lt(),ht()]:[]}const _n=C.highest(T.of([{key:`Mod-b`,run:e=>j(e,`**`)},{key:`Mod-i`,run:e=>j(e,`_`)},{key:`Mod-e`,run:e=>j(e,"`")},{key:`Mod-Shift-x`,run:e=>j(e,`~~`)},{key:`Mod-k`,run:P}].map(e=>({...e,preventDefault:!0,stopPropagation:!0})))),vn=D.theme({"&":{"--atomic-editor-fg":`var(--foreground)`,"--atomic-editor-fg-muted":`var(--muted-foreground)`,"--atomic-editor-fg-faint":`var(--muted-foreground)`,"--atomic-editor-bg":`var(--background)`,"--atomic-editor-bg-surface":`var(--popover)`,"--atomic-editor-bg-panel":`var(--muted)`,"--atomic-editor-border":`var(--border)`,"--atomic-editor-accent":`var(--primary)`,"--atomic-editor-accent-bright":`var(--foreground)`,"--atomic-editor-accent-soft":`var(--accent)`,"--atomic-editor-link":`var(--primary)`,"--atomic-editor-link-hover":`var(--foreground)`,"--atomic-editor-code-bg":`var(--muted)`,"--atomic-editor-selection-bg":`var(--accent)`,"--atomic-editor-font":`var(--font-sans, system-ui)`,"--atomic-editor-measure":`100%`,"--atomic-editor-hl-comment":`var(--muted-foreground)`,"--atomic-editor-hl-escape":`var(--info)`,"--atomic-editor-hl-function":`var(--chart-5)`,"--atomic-editor-hl-invalid":`var(--destructive)`,"--atomic-editor-hl-keyword":`var(--chart-2)`,"--atomic-editor-hl-number":`var(--info)`,"--atomic-editor-hl-operator":`var(--chart-2)`,"--atomic-editor-hl-property":`var(--info)`,"--atomic-editor-hl-regexp":`var(--chart-1)`,"--atomic-editor-hl-string":`var(--chart-1)`,"--atomic-editor-hl-tag":`var(--success)`,"--atomic-editor-hl-type":`var(--warning)`,"--atomic-editor-hl-variable":`var(--foreground)`,fontSize:`15px`},"&.cm-focused":{outline:`none`},".cm-content":{padding:`8px 0 30vh`},".cm-line":{lineHeight:`1.7`}}),yn=[Ue({top:!0,scrollToMatch:e=>D.scrollIntoView(e,{y:`center`})}),C.highest(D.theme({".cm-panels":{backgroundColor:`var(--background)`,color:`var(--foreground)`,borderTop:`1px solid var(--border)`},".cm-panel.cm-search":{padding:`6px 36px 6px 16px`,fontSize:`13px`},".cm-panel.cm-search input[type=text], .cm-panel.cm-search button":{height:`26px`,margin:`2px 6px 2px 0`,borderRadius:`0`,border:`1px solid var(--border)`,backgroundColor:`var(--background)`,backgroundImage:`none`,color:`var(--foreground)`,fontSize:`13px`},".cm-panel.cm-search input[type=text]":{width:`16rem`,padding:`0 8px`},".cm-panel.cm-search input[type=text]:focus":{outline:`none`,borderColor:`var(--foreground)`},".cm-panel.cm-search button":{padding:`0 10px`},".cm-panel.cm-search button:hover":{backgroundColor:`var(--accent)`},".cm-panel.cm-search label":{color:`var(--muted-foreground)`,fontSize:`13px`},".cm-panel.cm-search input[type=checkbox]":{accentColor:`var(--foreground)`},".cm-panel.cm-search button[name=close]":{top:`8px`,right:`12px`,border:`none`,padding:`0 6px`,fontSize:`18px`,color:`var(--muted-foreground)`},".cm-searchMatch":{backgroundColor:`color-mix(in oklab, var(--info) 18%, transparent)`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:`color-mix(in oklab, var(--info) 38%, transparent)`,outline:`1px solid var(--info)`}}))];function bn(e){return[Xe(),Re(),Je(),x.allowMultipleSelections.of(!0),Fe(),je(),Ze(),Ne(),ut,gt,mt,D.lineWrapping,Ke({base:Ve,codeLanguages:k,extensions:dt}),_t,ft,vn,_n,yn,T.of([...He,...qe,...Be,Le,...Ie]),e.preview.of(gn(e.mode))]}function xn(e){return[vt({history:`external`}),yn,e.language]}async function Sn(e){let t=Me.matchFilename(k,e);return t?await t.load():[]}const Cn=a({paused:a({reason:o()}).nullable(),llmRequests:l(a({})),pendingTriggerOffsets:l(i()),scriptCalls:l(a({answered:s()}))});function wn(e){let t=e.llmRequests.length>0||e.pendingTriggerOffsets.length>0||e.scriptCalls.some(e=>!e.answered);return!e.paused&&t}const Tn=a({user:a({name:o().min(1)})}),Z=[x.readOnly.of(!0),D.editable.of(!1)],En={markdown:`rich`,html:`preview`,code:`code`};var Dn=class{#e;#t=/* @__PURE__ */ new Set;#n=new w;#r=new w;#i=[];#a;#o=null;#s=null;#c=null;#l=null;#u={kind:`opening`};#d=null;#f=!1;#p;#m=null;#h=[];#g=``;#_=/* @__PURE__ */ new Map;options;constructor(e){this.options=e,this.#e={mode:En[e.kind],status:{kind:`opening`},others:[],previewText:e.text,threads:[],active:null,thinking:[],selecting:!1,draft:null,editing:null}}subscribe=e=>(this.#t.add(e),()=>this.#t.delete(e));state=()=>this.#e;#v(e){this.#e={...this.#e,...e};for(let e of this.#t)e()}mountPanels=e=>{e?.appendChild(this.#y())};#y(){return this.#s||=document.createElement(`div`)}mount=e=>{if(!e)return;let t=new D({parent:e,state:x.create({doc:this.options.text,extensions:[this.#w(),Z]})});this.#o=t,this.options.kind!==`markdown`&&this.#T();let n={unmounted:!1,cleanups:[]};this.#d=n;let r=e=>{this.#c?.unsent()&&e.preventDefault()};window.addEventListener(`beforeunload`,r);let i=()=>void this.#c?.close();window.addEventListener(`pagehide`,i);let a=e=>{e.persisted&&this.#x(t,n)};window.addEventListener(`pageshow`,a);let o=e=>{(e.metaKey||e.ctrlKey)&&e.key===`f`&&!e.defaultPrevented&&(e.target instanceof Element&&e.target.closest(`input, textarea, [contenteditable]:not([contenteditable="false"])`)||this.#e.mode!==`preview`&&(e.preventDefault(),ze(t)))};return window.addEventListener(`keydown`,o),this.#S(t,n),()=>{n.unmounted=!0,window.removeEventListener(`beforeunload`,r),window.removeEventListener(`pagehide`,i),window.removeEventListener(`pageshow`,a),window.removeEventListener(`keydown`,o);for(let e of n.cleanups.reverse())e();clearTimeout(this.#a),this.#a=void 0;for(let e of this.#_.values())e();this.#_.clear(),this.#o=null,this.#d=null,this.#c=null,this.#m=null,this.#l=null,t.destroy()}};#b(e,t){e.unmounted?t():e.cleanups.push(t)}#x(e,t){if(!(t.unmounted||this.#f)){e.setState(x.create({doc:e.state.doc.toString(),extensions:[this.#w(),Z]}));for(let e of t.cleanups.splice(0).reverse())e();for(let e of this.#_.values())e();this.#_.clear(),this.#c=null,this.#m=null,this.#l=null,this.#S(e,t)}}async#S(e,t){let n=[],r=e=>{n.push(e),this.#b(t,e)};this.#f=!0,this.#u={kind:`opening`},this.#D();try{let{itx:n,repo:i,path:a,user:o,facetSpec:s}=this.options,c=await tn(n,{repo:i,path:a},{facetSpec:s}),l=Promise.resolve();if(r(()=>{l.finally(()=>c[Symbol.dispose]())}),t.unmounted)return;let u=!0;r(()=>{u=!1});let p=new rn({context:c,user:{name:o.name,color:o.color},onStatus:e=>{u&&(this.#u=e,this.#D())}});if(r(()=>{l=p.close()}),p.awareness.on(`change`,()=>this.#D()),await p.open(),t.unmounted)return;let m=this.#C();if(m.kind===`failed`)throw Error(m.message);let h=await d(c,{key:`doc`,readSeed:async()=>{let{rev:e,state:t}=await f(c,`doc`);return{rev:e,state:Lt.parse(t)}}});if(r(()=>void h.dispose()),t.unmounted)return;r(h.store.subscribe(()=>{let e=h.store.get();e?.commitOid!==this.#p?.commitOid&&p.sync();let t=e?.threads!==this.#p?.threads;this.#p=e,this.#D(),t&&this.#O()})),this.#p=h.store.get(),this.#c=p,this.#m=c,this.#l=new $e(p.text),e.setState(x.create({doc:p.text.toString(),extensions:[this.#w(),Qe(p.text,p.awareness,{undoManager:this.#l}),T.of(it),this.options.commentOnly?Z:[]]})),this.#v({selecting:!1,previewText:p.text.toString()}),this.#D(),this.#O()}catch(e){for(let e of n.reverse()){let n=t.cleanups.indexOf(e);n<0||(t.cleanups.splice(n,1),e())}this.#u={kind:`failed`,message:e instanceof Error?e.message:String(e)},this.#D()}finally{this.#f=!1}}#C(){return this.#u}#w(){return[this.options.kind===`markdown`?bn({mode:this.#e.mode===`markdown`?`markdown`:`rich`,preview:this.#n}):xn({language:this.#r.of(this.#i)}),Ye({topContainer:this.#y()}),D.contentAttributes.of({"aria-label":this.options.path}),X,cn,T.of([{key:`Mod-Alt-m`,run:()=>this.startComment(),preventDefault:!0}]),D.updateListener.of(e=>{e.startState.field(X)!==e.state.field(X)&&this.#M();let t=!e.state.selection.main.empty;t!==this.#e.selecting&&this.#v({selecting:t})}),this.options.kind===`html`?D.updateListener.of(e=>{e.docChanged&&this.#E()}):[]]}async#T(){this.#i=await Sn(this.options.path),this.#o?.dispatch({effects:this.#r.reconfigure(this.#i)})}#E(){this.#a||=setTimeout(()=>{this.#a=void 0,this.#o&&this.#v({previewText:this.#o.state.doc.toString()})},500)}#D(){let e=this.#p,t=this.#u.kind===`failed`?{kind:this.#c?`disconnected`:`unavailable`,message:this.#u.message}:!this.#c||!e?{kind:`opening`}:e.saveError?{kind:`save-failed`,message:e.saveError}:e.dirty||!e.commitOid?{kind:`editing`}:{kind:`saved`,oid:e.commitOid,by:e.savedBy},n=this.#c,r=n?[...n.awareness.getStates()].filter(([e])=>e!==n.doc.clientID).flatMap(([,e])=>{let t=Tn.safeParse(e);return t.success?[t.data.user.name]:[]}):[];this.#v({status:t,others:r})}#O(){let e=this.#p?this.#p.threads:[],t=this.#e.draft;t&&e.some(e=>e.id===t.thread)&&this.#v({draft:null}),this.#j(this.#e.active),this.#M(),this.#k()}#k(){let e=this.#m;if(!e)return;let t=this.#p?this.#p.threads:[],n=new Set(t.flatMap(e=>!e.resolved&&e.routedTo?[e.routedTo]:[]));for(let[e,t]of this.#_)n.has(e)||(t(),this.#_.delete(e),this.#A(e,!1));for(let t of n){if(this.#_.has(t))continue;let n=e.cd(t),r=new AbortController,i=d(n,{key:`agent`,readSeed:()=>f(n,`agent`),signal:r.signal}).then(e=>{let n=()=>{if(r.signal.aborted)return;let n=Cn.safeParse(e.store.get());this.#A(t,n.success&&wn(n.data))};return n(),{live:e,unsubscribe:e.store.subscribe(n)}});i.catch(()=>void 0),this.#_.set(t,()=>{r.abort(),i.then(({live:e,unsubscribe:t})=>(t(),e.dispose())).catch(()=>void 0).finally(()=>n[Symbol.dispose]())})}}#A(e,t){this.#e.thinking.includes(e)!==t&&this.#v({thinking:t?[...this.#e.thinking,e]:this.#e.thinking.filter(t=>t!==e)})}#j(e){let t=(this.#p?this.#p.threads:[]).filter(e=>!e.resolved),n=this.#e.draft,r=[...t,...n?[{id:n.thread,quote:n.quote}]:[]].flatMap(e=>e.quote?[{id:e.id,quote:e.quote}]:[]);this.#o?.dispatch({effects:on.of({threads:r,active:e})})}#M(){let e=this.#o?.state.field(X,!1),t=e?e.ranges:/* @__PURE__ */ new Map,n=e?e.active:this.#e.active,r=this.#p?this.#p.threads:[],i=e=>{let n=t.get(e.id);return e.quote?n?n.from:1/0:-1},a=[...r].sort((e,t)=>i(e)-i(t)).map(e=>({...e,attached:i(e)!==1/0})),o=a.map(e=>`${e.id}${e.attached?``:`!`}`).join(` `);(o!==this.#g||r!==this.#h||n!==this.#e.active)&&(this.#g=o,this.#h=r,this.#v({threads:a,active:n}))}startComment(){let e=this.#o;if(!e||!this.#m)return!1;let t=e.state.doc.toString(),{from:n,to:r}=e.state.selection.main;for(;n<r&&/\s/.test(t[n]);)n++;for(;r>n&&/\s/.test(t[r-1]);)r--;let i=crypto.randomUUID();return this.#v({draft:{thread:i,quote:r>n?Xt(t,n,r):null},active:i}),this.#j(i),!0}cancelDraft(){this.#v({draft:null,active:null}),this.#j(null)}async postDraft(e){let t=this.#e.draft;t&&await this.#N(V,{thread:t.thread,quote:t.quote,body:e})}reply(e,t){return this.#N(H,{thread:e,comment:crypto.randomUUID(),body:t})}startEditing(e,t){this.#v({editing:{thread:e,comment:t}})}stopEditing(){this.#v({editing:null})}async editComment(e,t,n){await this.#N(U,{thread:e,comment:t,body:n}),this.stopEditing()}deleteComment(e,t){return this.#N(Tt,{thread:e,comment:t})}resolve(e){return this.#N(Et,{thread:e})}reopen(e){return this.#N(Dt,{thread:e})}focusThread(e){this.#v({active:e}),this.#j(e);let t=this.#o?.state.field(X,!1)?.ranges.get(e);t&&(this.#e.mode===`preview`&&this.setMode(`source`),this.#o?.dispatch({effects:D.scrollIntoView(t.from,{y:`center`})}))}async#N(e,t){if(!this.#m)throw Error(`The doc isn't open yet`);await this.#m.append({type:e,payload:t})}reconnect(){if(this.#c)return void this.#c.sync();this.#o&&this.#d&&!this.#f&&this.#S(this.#o,this.#d)}setMode(e){(e===`rich`||e===`markdown`)&&this.#o?.dispatch({effects:this.#n.reconfigure(gn(e))}),e===`preview`&&this.#o&&Ge(this.#o),this.#v({mode:e}),e!==`preview`&&this.#o?.focus()}run(e){this.#o&&e(this.#o)}undo(){this.#l?.undo()}redo(){this.#l?.redo()}};function On(e){let t=0;for(let n of e)t=t*31+n.charCodeAt(0)|0;let n=[`var(--chart-1)`,`var(--chart-2)`,`var(--chart-3)`,`var(--chart-4)`,`var(--chart-5)`,`var(--info)`,`var(--success)`,`var(--warning)`];return n[Math.abs(t)%n.length]}const kn={markdown:[[`rich`,`Rich`],[`markdown`,`Markdown`]],html:[[`preview`,`Preview`],[`source`,`Source`]],code:[]};function An({session:e,listHref:t,listLabel:n,editHref:r,onNavigate:i,stream:a,unavailable:o}){let s=(0,A.useSyncExternalStore)(e.subscribe,e.state,e.state),{kind:c,commentOnly:l,path:u,repo:d}=e.options,f=jn(s.mode,c),p=/* @__PURE__ */ (0,F.jsx)(Nn,{session:e,selecting:s.selecting,opening:s.status.kind===`opening`});return/* @__PURE__ */ (0,F.jsxs)(`div`,{className:f.container,children:[/* @__PURE__ */ (0,F.jsxs)(`div`,{className:`sticky top-0 z-10 shrink-0 bg-background`,children:[/* @__PURE__ */ (0,F.jsxs)(`div`,{className:`flex min-h-11 flex-wrap items-center gap-x-4 gap-y-1 border-b px-4 py-1.5`,children:[/* @__PURE__ */ (0,F.jsxs)(`p`,{className:`flex min-w-0 gap-2 font-mono text-xs text-muted-foreground`,children:[/* @__PURE__ */ (0,F.jsx)(Mn,{href:t,onNavigate:i,className:`hover:text-foreground`,children:n}),/* @__PURE__ */ (0,F.jsx)(`span`,{"aria-hidden":!0,children:`/`}),/* @__PURE__ */ (0,F.jsx)(`span`,{className:`truncate`,children:u})]}),c===`markdown`&&!l?/* @__PURE__ */ (0,F.jsxs)(F.Fragment,{children:[/* @__PURE__ */ (0,F.jsx)(zn,{session:e}),/* @__PURE__ */ (0,F.jsx)(Rn,{session:e})]}):null,/* @__PURE__ */ (0,F.jsxs)(`div`,{className:`ml-auto flex min-w-0 flex-wrap items-center justify-end gap-3`,children:[s.others.length>0&&/* @__PURE__ */ (0,F.jsxs)(`p`,{"aria-label":`Also here`,className:`min-w-0 text-xs wrap-anywhere text-muted-foreground`,children:[`Also here: `,s.others.join(`, `)]}),l?null:p,/* @__PURE__ */ (0,F.jsx)(Pn,{session:e,mode:s.mode}),a?/* @__PURE__ */ (0,F.jsx)(Ae,{...a,path:It({repo:d,path:u})}):null]})]}),l?/* @__PURE__ */ (0,F.jsxs)(`div`,{className:`flex min-h-11 flex-wrap items-center justify-between gap-2 border-b px-4 py-1.5`,children:[/* @__PURE__ */ (0,F.jsxs)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:[s.selecting?`Comment on the selected text`:`Select text to comment on it`,` ·`,` `,/* @__PURE__ */ (0,F.jsx)(Mn,{href:r,onNavigate:i,className:`underline hover:text-foreground`,children:`Edit`})]}),p]}):null,/* @__PURE__ */ (0,F.jsx)(`div`,{ref:e.mountPanels})]}),/* @__PURE__ */ (0,F.jsxs)(`div`,{className:f.body,children:[/* @__PURE__ */ (0,F.jsxs)(`div`,{className:f.column,children:[s.status.kind===`unavailable`?/* @__PURE__ */ (0,F.jsxs)(`div`,{role:`alert`,className:`mt-4 flex flex-col gap-1.5 rounded-lg border border-destructive/40 p-3 text-sm`,children:[/* @__PURE__ */ (0,F.jsx)(`p`,{className:`font-medium`,children:`Couldn't open this doc for editing`}),/* @__PURE__ */ (0,F.jsx)(`p`,{className:`font-mono text-xs text-destructive`,children:s.status.message}),o,/* @__PURE__ */ (0,F.jsx)(g,{size:`xs`,variant:`outline`,className:`self-start`,onClick:()=>e.reconnect(),children:`Try again`})]}):null,s.mode===`preview`?/* @__PURE__ */ (0,F.jsx)(Fn,{path:u,html:s.previewText}):null,/* @__PURE__ */ (0,F.jsx)(`div`,{ref:e.mount,className:f.editor})]}),s.threads.length>0||s.draft?/* @__PURE__ */ (0,F.jsx)(I,{session:e,state:s}):null]}),/* @__PURE__ */ (0,F.jsx)(`p`,{role:`status`,className:`sticky bottom-0 shrink-0 border-t bg-background px-4 py-1.5 font-readme text-xs text-muted-foreground`,children:/* @__PURE__ */ (0,F.jsx)(In,{status:s.status,onRetry:()=>e.reconnect()})})]})}function jn(e,t){let n=t===`markdown`;return{container:n?`flex min-w-0 flex-1 flex-col`:`flex min-h-0 min-w-0 flex-1 flex-col`,body:n?`flex flex-1 flex-col md:flex-row`:`flex min-h-0 flex-1 flex-col overflow-auto md:flex-row`,column:e===`preview`?`flex min-h-0 min-w-0 flex-1 flex-col`:n?`mx-auto w-full max-w-3xl min-w-0 flex-1 px-4 md:px-8`:`flex min-h-64 w-full min-w-0 flex-1 flex-col md:min-h-0`,editor:e===`preview`?`hidden`:n?`docs-editor pt-4`:`docs-editor min-h-0 min-w-0 flex-1 overflow-hidden`}}function Mn({href:e,onNavigate:t,className:n,children:r}){return/* @__PURE__ */ (0,F.jsx)(`a`,{href:e,className:n,onClick:n=>{t&&y(n)&&(n.preventDefault(),t(e))},children:r})}function Nn({session:e,selecting:t,opening:n}){let{commentOnly:r}=e.options;return/* @__PURE__ */ (0,F.jsxs)(g,{size:`xs`,variant:r&&t?`default`:`ghost`,title:r?`Comment on the selection`:`Comment on the selection (⌘⌥M)`,disabled:n,onMouseDown:e=>e.preventDefault(),onClick:()=>e.startComment(),children:[/* @__PURE__ */ (0,F.jsx)(le,{}),`Comment`]})}function Pn({session:e,mode:t}){let n=kn[e.options.kind];return n.length===0?null:/* @__PURE__ */ (0,F.jsx)(`div`,{role:`group`,"aria-label":`Mode`,className:`flex rounded-lg border p-0.5`,children:n.map(([n,r])=>/* @__PURE__ */ (0,F.jsx)(g,{size:`xs`,variant:t===n?`secondary`:`ghost`,"aria-pressed":t===n,onClick:()=>e.setMode(n),children:r},n))})}function Fn({path:e,html:t}){let n=(0,A.useCallback)(e=>{if(!e)return;let n=URL.createObjectURL(new Blob([t],{type:`text/html;charset=utf-8`}));return e.src=n,()=>URL.revokeObjectURL(n)},[t]);return/* @__PURE__ */ (0,F.jsx)(`iframe`,{ref:n,title:`Preview of ${e}`,sandbox:`allow-scripts allow-popups allow-forms`,className:`w-full flex-1 bg-white`},t)}function In({status:e,onRetry:t}){if(e.kind===`opening`)return`Opening…`;if(e.kind===`editing`)return`Editing…`;if(e.kind===`save-failed`)return/* @__PURE__ */ (0,F.jsxs)(`span`,{className:`text-destructive`,children:[`Couldn't save: `,e.message,`. The text is kept, and the next edit saves again.`]});if(e.kind===`unavailable`)return`Not open: the text is the file as it was read.`;if(e.kind===`disconnected`)return/* @__PURE__ */ (0,F.jsxs)(`span`,{className:`text-destructive`,children:[`Lost the connection: `,e.message,`. Your text is still here.`,` `,/* @__PURE__ */ (0,F.jsx)(`button`,{type:`button`,className:`underline`,onClick:t,children:`Try again`})]});let n=`Saved ${e.oid.slice(0,7)}`;return e.by.length>0?`${n} (${e.by.join(`, `)})`:n}const Q=e=>t=>t.run(e),Ln=[[{label:`Undo`,icon:/* @__PURE__ */ (0,F.jsx)(ge,{}),run:e=>e.undo()},{label:`Redo`,icon:/* @__PURE__ */ (0,F.jsx)(he,{}),run:e=>e.redo()}],[{label:`Bold`,icon:/* @__PURE__ */ (0,F.jsx)(ye,{}),run:Q(e=>j(e,`**`))},{label:`Italic`,icon:/* @__PURE__ */ (0,F.jsx)(pe,{}),run:Q(e=>j(e,`_`))},{label:`Strikethrough`,icon:/* @__PURE__ */ (0,F.jsx)(ce,{}),run:Q(e=>j(e,`~~`))},{label:`Inline code`,icon:/* @__PURE__ */ (0,F.jsx)(ve,{}),run:Q(e=>j(e,"`"))}],[{label:`Bulleted list`,icon:/* @__PURE__ */ (0,F.jsx)(h,{}),run:Q(e=>M(e,`- `))},{label:`Numbered list`,icon:/* @__PURE__ */ (0,F.jsx)(_e,{}),run:Q(e=>M(e,`1. `))},{label:`Checklist`,icon:/* @__PURE__ */ (0,F.jsx)(ie,{}),run:Q(e=>M(e,`- [ ] `))}],[{label:`Link`,icon:/* @__PURE__ */ (0,F.jsx)(ae,{}),run:Q(P)},{label:`Table`,icon:/* @__PURE__ */ (0,F.jsx)(me,{}),run:Q(e=>N(e,`| Column | Column | | ------ | ------ | -| | |`))},{label:`Divider`,icon:/* @__PURE__ */ (0,P.jsx)(re,{}),run:Q(e=>M(e,`---`))}]],$=[{label:`Paragraph`,icon:/* @__PURE__ */ (0,P.jsx)(ie,{}),run:Q(e=>j(e,``))},{label:`Heading 1`,icon:/* @__PURE__ */ (0,P.jsx)(se,{}),run:Q(e=>j(e,`# `))},{label:`Heading 2`,icon:/* @__PURE__ */ (0,P.jsx)(ce,{}),run:Q(e=>j(e,`## `))},{label:`Heading 3`,icon:/* @__PURE__ */ (0,P.jsx)(de,{}),run:Q(e=>j(e,`### `))},{label:`Quote`,icon:/* @__PURE__ */ (0,P.jsx)(fe,{}),run:Q(e=>j(e,`> `))}];function Rn({session:e}){return/* @__PURE__ */ (0,P.jsxs)(ke,{children:[/* @__PURE__ */ (0,P.jsx)(Ee,{render:/* @__PURE__ */ (0,P.jsx)(g,{size:`icon-sm`,variant:`ghost`,className:`md:hidden`,"aria-label":`Formatting`,title:`Formatting`}),children:/* @__PURE__ */ (0,P.jsx)(be,{})}),/* @__PURE__ */ (0,P.jsx)(Oe,{align:`start`,className:`min-w-56 rounded-lg`,children:/* @__PURE__ */ (0,P.jsx)(De,{"aria-label":`Formatting`,className:`grid grid-cols-6`,children:[...Ln.flat(),...$].map(({label:t,icon:n,run:r})=>/* @__PURE__ */ (0,P.jsx)(Te,{"aria-label":t,title:t,className:`justify-center p-2`,onClick:()=>r(e),children:n},t))})})]})}function zn({session:e}){let t=({label:t,icon:n,run:r})=>/* @__PURE__ */ (0,P.jsx)(g,{size:`icon-sm`,variant:`ghost`,"aria-label":t,title:t,onMouseDown:e=>e.preventDefault(),onClick:()=>r(e),children:n},t),[n,r,i,a]=Ln;return/* @__PURE__ */ (0,P.jsxs)(`div`,{role:`toolbar`,"aria-label":`Formatting`,className:`hidden flex-wrap items-center gap-0.5 md:flex`,children:[n.map(t),/* @__PURE__ */ (0,P.jsx)(_,{orientation:`vertical`,className:`mx-1 h-5`}),r.map(t),/* @__PURE__ */ (0,P.jsx)(_,{orientation:`vertical`,className:`mx-1 h-5`}),i.map(t),/* @__PURE__ */ (0,P.jsx)(_,{orientation:`vertical`,className:`mx-1 h-5`}),/* @__PURE__ */ (0,P.jsxs)(Ae,{size:`sm`,"aria-label":`Block type`,value:``,onChange:t=>$.find(e=>e.label===t.target.value)?.run(e),children:[/* @__PURE__ */ (0,P.jsx)(v,{value:``,disabled:!0,children:`Block type`}),$.map(({label:e})=>/* @__PURE__ */ (0,P.jsx)(v,{value:e,children:e},e))]}),/* @__PURE__ */ (0,P.jsx)(_,{orientation:`vertical`,className:`mx-1 h-5`}),a.map(t)]})}export{F as CommentsPanel,An as DocEditor,Wt as DocList,Kt as DocListPanel,Dn as DocSession,qt as DocTree,Bt as commitAuthorOf,Y as createDoc,On as cursorColor,zt as fileKind,Vt as newDocPath}; +| | |`))},{label:`Divider`,icon:/* @__PURE__ */ (0,F.jsx)(ne,{}),run:Q(e=>N(e,`---`))}]],$=[{label:`Paragraph`,icon:/* @__PURE__ */ (0,F.jsx)(re,{}),run:Q(e=>M(e,``))},{label:`Heading 1`,icon:/* @__PURE__ */ (0,F.jsx)(oe,{}),run:Q(e=>M(e,`# `))},{label:`Heading 2`,icon:/* @__PURE__ */ (0,F.jsx)(se,{}),run:Q(e=>M(e,`## `))},{label:`Heading 3`,icon:/* @__PURE__ */ (0,F.jsx)(ue,{}),run:Q(e=>M(e,`### `))},{label:`Quote`,icon:/* @__PURE__ */ (0,F.jsx)(de,{}),run:Q(e=>M(e,`> `))}];function Rn({session:e}){return/* @__PURE__ */ (0,F.jsxs)(Oe,{children:[/* @__PURE__ */ (0,F.jsx)(Te,{render:/* @__PURE__ */ (0,F.jsx)(g,{size:`icon-sm`,variant:`ghost`,className:`md:hidden`,"aria-label":`Formatting`,title:`Formatting`}),children:/* @__PURE__ */ (0,F.jsx)(ye,{})}),/* @__PURE__ */ (0,F.jsx)(De,{align:`start`,className:`min-w-56 rounded-lg`,children:/* @__PURE__ */ (0,F.jsx)(Ee,{"aria-label":`Formatting`,className:`grid grid-cols-6`,children:[...Ln.flat(),...$].map(({label:t,icon:n,run:r})=>/* @__PURE__ */ (0,F.jsx)(we,{"aria-label":t,title:t,className:`justify-center p-2`,onClick:()=>r(e),children:n},t))})})]})}function zn({session:e}){let t=({label:t,icon:n,run:r})=>/* @__PURE__ */ (0,F.jsx)(g,{size:`icon-sm`,variant:`ghost`,"aria-label":t,title:t,onMouseDown:e=>e.preventDefault(),onClick:()=>r(e),children:n},t),[n,r,i,a]=Ln;return/* @__PURE__ */ (0,F.jsxs)(`div`,{role:`toolbar`,"aria-label":`Formatting`,className:`hidden flex-wrap items-center gap-0.5 md:flex`,children:[n.map(t),/* @__PURE__ */ (0,F.jsx)(_,{orientation:`vertical`,className:`mx-1 h-5`}),r.map(t),/* @__PURE__ */ (0,F.jsx)(_,{orientation:`vertical`,className:`mx-1 h-5`}),i.map(t),/* @__PURE__ */ (0,F.jsx)(_,{orientation:`vertical`,className:`mx-1 h-5`}),/* @__PURE__ */ (0,F.jsxs)(ke,{size:`sm`,"aria-label":`Block type`,value:``,onChange:t=>$.find(e=>e.label===t.target.value)?.run(e),children:[/* @__PURE__ */ (0,F.jsx)(v,{value:``,disabled:!0,children:`Block type`}),$.map(({label:e})=>/* @__PURE__ */ (0,F.jsx)(v,{value:e,children:e},e))]}),/* @__PURE__ */ (0,F.jsx)(_,{orientation:`vertical`,className:`mx-1 h-5`}),a.map(t)]})}export{I as CommentsPanel,An as DocEditor,Wt as DocList,Kt as DocListPanel,Dn as DocSession,qt as DocTree,Bt as commitAuthorOf,Y as createDoc,On as cursorColor,zt as fileKind,Vt as newDocPath};
M dist/components/integrations-page.mjs
@@ -1,14 +1,14 @@ -import{r as e,t}from"../chunks/rolldown-runtime.mjs";import{a as n,n as r}from"../chunks/vendor-react";import{t as i}from"../chunks/dist.mjs";import{_ as a,b as o,c as s,f as c,h as l,m as u,p as d,r as f,t as p,u as m,v as h,y as g}from"../chunks/vendor-zod";import{a as _}from"../chunks/lib.mjs";import{n as ee,r as te}from"../chunks/react.mjs";import{Ht as ne,kt as v}from"../chunks/vendor-icons";import{a as re,c as y,i as b}from"../chunks/ui-base";import{Spinner as x}from"./ui/spinner";import{AlertDialog as S,AlertDialogAction as C,AlertDialogCancel as ie,AlertDialogContent as ae,AlertDialogDescription as oe,AlertDialogFooter as se,AlertDialogHeader as ce,AlertDialogTitle as le,AlertDialogTrigger as ue}from"./ui/alert-dialog";var de=/* @__PURE__ */ t(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):n.JSON5=r()})(e,(function(){function e(e,t){return t={exports:{}},e(t,t.exports),t.exports}var t=e(function(e){var t=e.exports=typeof window<`u`&&window.Math==Math?window:typeof self<`u`&&self.Math==Math?self:Function(`return this`)();typeof __g==`number`&&(__g=t)}),n=e(function(e){var t=e.exports={version:`2.6.5`};typeof __e==`number`&&(__e=t)});n.version;var r=function(e){return typeof e==`object`?e!==null:typeof e==`function`},i=function(e){if(!r(e))throw TypeError(e+` is not an object!`);return e},a=function(e){try{return!!e()}catch{return!0}},o=!a(function(){return Object.defineProperty({},"a",{get:function(){return 7}}).a!=7}),s=t.document,c=r(s)&&r(s.createElement),l=function(e){return c?s.createElement(e):{}},u=!o&&!a(function(){return Object.defineProperty(l(`div`),"a",{get:function(){return 7}}).a!=7}),d=function(e,t){if(!r(e))return e;var n,i;if(t&&typeof(n=e.toString)==`function`&&!r(i=n.call(e))||typeof(n=e.valueOf)==`function`&&!r(i=n.call(e))||!t&&typeof(n=e.toString)==`function`&&!r(i=n.call(e)))return i;throw TypeError(`Can't convert object to primitive value`)},f=Object.defineProperty,p={f:o?Object.defineProperty:function(e,t,n){if(i(e),t=d(t,!0),i(n),u)try{return f(e,t,n)}catch{}if(`get`in n||`set`in n)throw TypeError(`Accessors not supported!`);return`value`in n&&(e[t]=n.value),e}},m=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}},h=o?function(e,t,n){return p.f(e,t,m(1,n))}:function(e,t,n){return e[t]=n,e},g={}.hasOwnProperty,_=function(e,t){return g.call(e,t)},ee=0,te=Math.random(),ne=function(e){return`Symbol(${e===void 0?``:e})_${(++ee+te).toString(36)}`},v=e(function(e){var r=`__core-js_shared__`,i=t[r]||(t[r]={});(e.exports=function(e,t){return i[e]||(i[e]=t===void 0?{}:t)})(`versions`,[]).push({version:n.version,mode:`global`,copyright:`© 2019 Denis Pushkarev (zloirock.ru)`})})(`native-function-to-string`,Function.toString),re=e(function(e){var r=ne(`src`),i=`toString`,a=(``+v).split(i);n.inspectSource=function(e){return v.call(e)},(e.exports=function(e,n,i,o){var s=typeof i==`function`;s&&(_(i,`name`)||h(i,`name`,n)),e[n]!==i&&(s&&(_(i,r)||h(i,r,e[n]?``+e[n]:a.join(String(n)))),e===t?e[n]=i:o?e[n]?e[n]=i:h(e,n,i):(delete e[n],h(e,n,i)))})(Function.prototype,i,function(){return typeof this==`function`&&this[r]||v.call(this)})}),y=function(e){if(typeof e!=`function`)throw TypeError(e+` is not a function!`);return e},b=function(e,t,n){if(y(e),t===void 0)return e;switch(n){case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}},x=`prototype`,S=function(e,r,i){var a=e&S.F,o=e&S.G,s=e&S.S,c=e&S.P,l=e&S.B,u=o?t:s?t[r]||(t[r]={}):(t[r]||{})[x],d=o?n:n[r]||(n[r]={}),f=d[x]||(d[x]={}),p,m,g,_;for(p in o&&(i=r),i)m=!a&&u&&u[p]!==void 0,g=(m?u:i)[p],_=l&&m?b(g,t):c&&typeof g==`function`?b(Function.call,g):g,u&&re(u,p,g,e&S.U),d[p]!=g&&h(d,p,_),c&&f[p]!=g&&(f[p]=g)};t.core=n,S.F=1,S.G=2,S.S=4,S.P=8,S.B=16,S.W=32,S.U=64,S.R=128;var C=S,ie=Math.ceil,ae=Math.floor,oe=function(e){return isNaN(e=+e)?0:(e>0?ae:ie)(e)},se=function(e){if(e==null)throw TypeError(`Can't call method on `+e);return e},ce=function(e){return function(t,n){var r=String(se(t)),i=oe(n),a=r.length,o,s;return i<0||i>=a?e?``:void 0:(o=r.charCodeAt(i),o<55296||o>56319||i+1===a||(s=r.charCodeAt(i+1))<56320||s>57343?e?r.charAt(i):o:e?r.slice(i,i+2):(o-55296<<10)+(s-56320)+65536)}}(!1);C(C.P,`String`,{codePointAt:function(e){return ce(this,e)}}),n.String.codePointAt;var le=Math.max,ue=Math.min,de=function(e,t){return e=oe(e),e<0?le(e+t,0):ue(e,t)},w=String.fromCharCode,T=String.fromCodePoint;C(C.S+C.F*(!!T&&T.length!=1),`String`,{fromCodePoint:function(e){for(var t=arguments,n=[],r=arguments.length,i=0,a;r>i;){if(a=+t[i++],de(a,1114111)!==a)throw RangeError(a+` is not a valid code point`);n.push(a<65536?w(a):w(((a-=65536)>>10)+55296,a%1024+56320))}return n.join(``)}}),n.String.fromCodePoint;var E={Space_Separator:/[\u1680\u2000-\u200A\u202F\u205F\u3000]/,ID_Start:/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,ID_Continue:/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/},D={isSpaceSeparator:function(e){return typeof e==`string`&&E.Space_Separator.test(e)},isIdStartChar:function(e){return typeof e==`string`&&(e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e===`$`||e===`_`||E.ID_Start.test(e))},isIdContinueChar:function(e){return typeof e==`string`&&(e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e>=`0`&&e<=`9`||e===`$`||e===`_`||e===``||e===``||E.ID_Continue.test(e))},isDigit:function(e){return typeof e==`string`&&/[0-9]/.test(e)},isHexDigit:function(e){return typeof e==`string`&&/[0-9A-Fa-f]/.test(e)}},O,k,A,j,M,N,P,F,I,fe=function(e,t){O=String(e),k=`start`,A=[],j=0,M=1,N=0,P=void 0,F=void 0,I=void 0;do P=me(),_e[k]();while(P.type!==`eof`);return typeof t==`function`?pe({"":I},``,t):I};function pe(e,t,n){var r=e[t];if(typeof r==`object`&&r){if(Array.isArray(r))for(var i=0;i<r.length;i++){var a=String(i),o=pe(r,a,n);o===void 0?delete r[a]:Object.defineProperty(r,a,{value:o,writable:!0,enumerable:!0,configurable:!0})}else for(var s in r){var c=pe(r,s,n);c===void 0?delete r[s]:Object.defineProperty(r,s,{value:c,writable:!0,enumerable:!0,configurable:!0})}}return n.call(e,t,r)}var L,R,z,B,V;function me(){for(L=`default`,R=``,z=!1,B=1;;){V=H();var e=W[L]();if(e)return e}}function H(){if(O[j])return String.fromCodePoint(O.codePointAt(j))}function U(){var e=H();return e===` -`?(M++,N=0):e?N+=e.length:N++,e&&(j+=e.length),e}var W={default:function(){switch(V){case` `:case`\v`:case`\f`:case` `:case`\xA0`:case``:case` -`:case`\r`:case`\u2028`:case`\u2029`:U();return;case`/`:U(),L=`comment`;return;case void 0:return U(),G(`eof`)}if(D.isSpaceSeparator(V)){U();return}return W[k]()},comment:function(){switch(V){case`*`:U(),L=`multiLineComment`;return;case`/`:U(),L=`singleLineComment`;return}throw X(U())},multiLineComment:function(){switch(V){case`*`:U(),L=`multiLineCommentAsterisk`;return;case void 0:throw X(U())}U()},multiLineCommentAsterisk:function(){switch(V){case`*`:U();return;case`/`:U(),L=`default`;return;case void 0:throw X(U())}U(),L=`multiLineComment`},singleLineComment:function(){switch(V){case` -`:case`\r`:case`\u2028`:case`\u2029`:U(),L=`default`;return;case void 0:return U(),G(`eof`)}U()},value:function(){switch(V){case`{`:case`[`:return G(`punctuator`,U());case`n`:return U(),K(`ull`),G(`null`,null);case`t`:return U(),K(`rue`),G(`boolean`,!0);case`f`:return U(),K(`alse`),G(`boolean`,!1);case`-`:case`+`:U()===`-`&&(B=-1),L=`sign`;return;case`.`:R=U(),L=`decimalPointLeading`;return;case`0`:R=U(),L=`zero`;return;case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:R=U(),L=`decimalInteger`;return;case`I`:return U(),K(`nfinity`),G(`numeric`,1/0);case`N`:return U(),K(`aN`),G(`numeric`,NaN);case`"`:case`'`:z=U()===`"`,R=``,L=`string`;return}throw X(U())},identifierNameStartEscape:function(){if(V!==`u`)throw X(U());U();var e=q();switch(e){case`$`:case`_`:break;default:if(!D.isIdStartChar(e))throw ve()}R+=e,L=`identifierName`},identifierName:function(){switch(V){case`$`:case`_`:case``:case``:R+=U();return;case`\\`:U(),L=`identifierNameEscape`;return}if(D.isIdContinueChar(V)){R+=U();return}return G(`identifier`,R)},identifierNameEscape:function(){if(V!==`u`)throw X(U());U();var e=q();switch(e){case`$`:case`_`:case``:case``:break;default:if(!D.isIdContinueChar(e))throw ve()}R+=e,L=`identifierName`},sign:function(){switch(V){case`.`:R=U(),L=`decimalPointLeading`;return;case`0`:R=U(),L=`zero`;return;case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:R=U(),L=`decimalInteger`;return;case`I`:return U(),K(`nfinity`),G(`numeric`,B*(1/0));case`N`:return U(),K(`aN`),G(`numeric`,NaN)}throw X(U())},zero:function(){switch(V){case`.`:R+=U(),L=`decimalPoint`;return;case`e`:case`E`:R+=U(),L=`decimalExponent`;return;case`x`:case`X`:R+=U(),L=`hexadecimal`;return}return G(`numeric`,B*0)},decimalInteger:function(){switch(V){case`.`:R+=U(),L=`decimalPoint`;return;case`e`:case`E`:R+=U(),L=`decimalExponent`;return}if(D.isDigit(V)){R+=U();return}return G(`numeric`,B*Number(R))},decimalPointLeading:function(){if(D.isDigit(V)){R+=U(),L=`decimalFraction`;return}throw X(U())},decimalPoint:function(){switch(V){case`e`:case`E`:R+=U(),L=`decimalExponent`;return}if(D.isDigit(V)){R+=U(),L=`decimalFraction`;return}return G(`numeric`,B*Number(R))},decimalFraction:function(){switch(V){case`e`:case`E`:R+=U(),L=`decimalExponent`;return}if(D.isDigit(V)){R+=U();return}return G(`numeric`,B*Number(R))},decimalExponent:function(){switch(V){case`+`:case`-`:R+=U(),L=`decimalExponentSign`;return}if(D.isDigit(V)){R+=U(),L=`decimalExponentInteger`;return}throw X(U())},decimalExponentSign:function(){if(D.isDigit(V)){R+=U(),L=`decimalExponentInteger`;return}throw X(U())},decimalExponentInteger:function(){if(D.isDigit(V)){R+=U();return}return G(`numeric`,B*Number(R))},hexadecimal:function(){if(D.isHexDigit(V)){R+=U(),L=`hexadecimalInteger`;return}throw X(U())},hexadecimalInteger:function(){if(D.isHexDigit(V)){R+=U();return}return G(`numeric`,B*Number(R))},string:function(){switch(V){case`\\`:U(),R+=he();return;case`"`:if(z)return U(),G(`string`,R);R+=U();return;case`'`:if(!z)return U(),G(`string`,R);R+=U();return;case` -`:case`\r`:throw X(U());case`\u2028`:case`\u2029`:Q(V);break;case void 0:throw X(U())}R+=U()},start:function(){switch(V){case`{`:case`[`:return G(`punctuator`,U())}L=`value`},beforePropertyName:function(){switch(V){case`$`:case`_`:R=U(),L=`identifierName`;return;case`\\`:U(),L=`identifierNameStartEscape`;return;case`}`:return G(`punctuator`,U());case`"`:case`'`:z=U()===`"`,L=`string`;return}if(D.isIdStartChar(V)){R+=U(),L=`identifierName`;return}throw X(U())},afterPropertyName:function(){if(V===`:`)return G(`punctuator`,U());throw X(U())},beforePropertyValue:function(){L=`value`},afterPropertyValue:function(){switch(V){case`,`:case`}`:return G(`punctuator`,U())}throw X(U())},beforeArrayValue:function(){if(V===`]`)return G(`punctuator`,U());L=`value`},afterArrayValue:function(){switch(V){case`,`:case`]`:return G(`punctuator`,U())}throw X(U())},end:function(){throw X(U())}};function G(e,t){return{type:e,value:t,line:M,column:N}}function K(e){for(var t=0,n=e;t<n.length;t+=1){var r=n[t];if(H()!==r)throw X(U());U()}}function he(){switch(H()){case`b`:return U(),`\b`;case`f`:return U(),`\f`;case`n`:return U(),` -`;case`r`:return U(),`\r`;case`t`:return U(),` `;case`v`:return U(),`\v`;case`0`:if(U(),D.isDigit(H()))throw X(U());return`\0`;case`x`:return U(),ge();case`u`:return U(),q();case` -`:case`\u2028`:case`\u2029`:return U(),``;case`\r`:return U(),H()===` -`&&U(),``;case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:throw X(U());case void 0:throw X(U())}return U()}function ge(){var e=``,t=H();if(!D.isHexDigit(t)||(e+=U(),t=H(),!D.isHexDigit(t)))throw X(U());return e+=U(),String.fromCodePoint(parseInt(e,16))}function q(){for(var e=``,t=4;t-->0;){var n=H();if(!D.isHexDigit(n))throw X(U());e+=U()}return String.fromCodePoint(parseInt(e,16))}var _e={start:function(){if(P.type===`eof`)throw Z();J()},beforePropertyName:function(){switch(P.type){case`identifier`:case`string`:F=P.value,k=`afterPropertyName`;return;case`punctuator`:Y();return;case`eof`:throw Z()}},afterPropertyName:function(){if(P.type===`eof`)throw Z();k=`beforePropertyValue`},beforePropertyValue:function(){if(P.type===`eof`)throw Z();J()},beforeArrayValue:function(){if(P.type===`eof`)throw Z();if(P.type===`punctuator`&&P.value===`]`){Y();return}J()},afterPropertyValue:function(){if(P.type===`eof`)throw Z();switch(P.value){case`,`:k=`beforePropertyName`;return;case`}`:Y()}},afterArrayValue:function(){if(P.type===`eof`)throw Z();switch(P.value){case`,`:k=`beforeArrayValue`;return;case`]`:Y()}},end:function(){}};function J(){var e;switch(P.type){case`punctuator`:switch(P.value){case`{`:e={};break;case`[`:e=[]}break;case`null`:case`boolean`:case`numeric`:case`string`:e=P.value}if(I===void 0)I=e;else{var t=A[A.length-1];Array.isArray(t)?t.push(e):Object.defineProperty(t,F,{value:e,writable:!0,enumerable:!0,configurable:!0})}if(typeof e==`object`&&e)A.push(e),k=Array.isArray(e)?`beforeArrayValue`:`beforePropertyName`;else{var n=A[A.length-1];k=n==null?`end`:Array.isArray(n)?`afterArrayValue`:`afterPropertyValue`}}function Y(){A.pop();var e=A[A.length-1];k=e==null?`end`:Array.isArray(e)?`afterArrayValue`:`afterPropertyValue`}function X(e){return $(e===void 0?`JSON5: invalid end of input at `+M+`:`+N:`JSON5: invalid character '`+ye(e)+`' at `+M+`:`+N)}function Z(){return $(`JSON5: invalid end of input at `+M+`:`+N)}function ve(){return N-=5,$(`JSON5: invalid identifier character at `+M+`:`+N)}function Q(e){console.warn(`JSON5: '`+ye(e)+`' in strings is not valid ECMAScript; consider escaping`)}function ye(e){var t={"'":`\\'`,'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`,"\v":`\\v`,"\0":`\\0`,"\u2028":`\\u2028`,"\u2029":`\\u2029`};if(t[e])return t[e];if(e<` `){var n=e.charCodeAt(0).toString(16);return`\\x`+(`00`+n).substring(n.length)}return e}function $(e){var t=SyntaxError(e);return t.lineNumber=M,t.columnNumber=N,t}return{parse:fe,stringify:function(e,t,n){var r=[],i=``,a,o,s=``,c;if(typeof t==`object`&&t&&!Array.isArray(t)&&(n=t.space,c=t.quote,t=t.replacer),typeof t==`function`)o=t;else if(Array.isArray(t)){a=[];for(var l=0,u=t;l<u.length;l+=1){var d=u[l],f=void 0;typeof d==`string`?f=d:(typeof d==`number`||d instanceof String||d instanceof Number)&&(f=String(d)),f!==void 0&&a.indexOf(f)<0&&a.push(f)}}return n instanceof Number?n=Number(n):n instanceof String&&(n=String(n)),typeof n==`number`?n>0&&(n=Math.min(10,Math.floor(n)),s=` `.substr(0,n)):typeof n==`string`&&(s=n.substr(0,10)),p(``,{"":e});function p(e,t){var n=t[e];switch(n!=null&&(typeof n.toJSON5==`function`?n=n.toJSON5(e):typeof n.toJSON==`function`&&(n=n.toJSON(e))),o&&(n=o.call(t,e,n)),n instanceof Number?n=Number(n):n instanceof String?n=String(n):n instanceof Boolean&&(n=n.valueOf()),n){case null:return`null`;case!0:return`true`;case!1:return`false`}if(typeof n==`string`)return m(n,!1);if(typeof n==`number`)return String(n);if(typeof n==`object`)return Array.isArray(n)?_(n):h(n)}function m(e){for(var t={"'":.1,'"':.2},n={"'":`\\'`,'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`,"\v":`\\v`,"\0":`\\0`,"\u2028":`\\u2028`,"\u2029":`\\u2029`},r=``,i=0;i<e.length;i++){var a=e[i];switch(a){case`'`:case`"`:t[a]++,r+=a;continue;case`\0`:if(D.isDigit(e[i+1])){r+=`\\x00`;continue}}if(n[a]){r+=n[a];continue}if(a<` `){var o=a.charCodeAt(0).toString(16);r+=`\\x`+(`00`+o).substring(o.length);continue}r+=a}var s=c||Object.keys(t).reduce(function(e,n){return t[e]<t[n]?e:n});return r=r.replace(new RegExp(s,`g`),n[s]),s+r+s}function h(e){if(r.indexOf(e)>=0)throw TypeError(`Converting circular structure to JSON5`);r.push(e);var t=i;i+=s;for(var n=a||Object.keys(e),o=[],c=0,l=n;c<l.length;c+=1){var u=l[c],d=p(u,e);if(d!==void 0){var f=g(u)+`:`;s!==``&&(f+=` `),f+=d,o.push(f)}}var m;if(o.length===0)m=`{}`;else{var h;if(s===``)h=o.join(`,`),m=`{`+h+`}`;else{var _=`, +import{r as e,t}from"../chunks/rolldown-runtime.mjs";import{a as n,n as r}from"../chunks/vendor-react";import{t as i}from"../chunks/dist.mjs";import{_ as a,b as o,c as s,f as c,h as l,m as u,p as d,r as f,t as p,u as m,v as h,y as g}from"../chunks/vendor-zod";import{a as _}from"../chunks/lib.mjs";import{n as ee,r as te}from"../chunks/react.mjs";import{Ht as ne,kt as v}from"../chunks/vendor-icons";import{a as re,c as y,i as b}from"../chunks/ui-base";import{Spinner as x}from"./ui/spinner";import{AlertDialog as S,AlertDialogAction as C,AlertDialogCancel as ie,AlertDialogContent as ae,AlertDialogDescription as oe,AlertDialogFooter as se,AlertDialogHeader as ce,AlertDialogTitle as le,AlertDialogTrigger as ue}from"./ui/alert-dialog";var w=/* @__PURE__ */ e(n(),1);function de(e){if(!e.stateSchema.safeParse({}).success)throw Error(`contract "${e.slug}": stateSchema must parse {} (default every field)`);let t=e.events??{},n=e.processorDeps??[],r=/* @__PURE__ */ new Set;for(let i of n)for(let n of Object.keys(i.events)){if(n in t)throw Error(`contract "${e.slug}": event "${n}" is already owned by a dep`);if(r.has(n))throw Error(`contract "${e.slug}": event "${n}" is declared by two deps`);r.add(n)}let i=e=>t[e]??n.map(t=>t.events[e]).find(Boolean);return{slug:e.slug,version:e.version,description:e.description,consumes:e.consumes,emits:e.emits,stateSchema:e.stateSchema,events:t,processorDeps:n,initialState:()=>e.stateSchema.parse({}),payloadSchemaFor:e=>i(e)?.payloadSchema,eventDefinitionFor:i}}(/* @__PURE__ */ t(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):n.JSON5=r()})(e,(function(){function e(e,t){return t={exports:{}},e(t,t.exports),t.exports}var t=e(function(e){var t=e.exports=typeof window<`u`&&window.Math==Math?window:typeof self<`u`&&self.Math==Math?self:Function(`return this`)();typeof __g==`number`&&(__g=t)}),n=e(function(e){var t=e.exports={version:`2.6.5`};typeof __e==`number`&&(__e=t)});n.version;var r=function(e){return typeof e==`object`?e!==null:typeof e==`function`},i=function(e){if(!r(e))throw TypeError(e+` is not an object!`);return e},a=function(e){try{return!!e()}catch{return!0}},o=!a(function(){return Object.defineProperty({},"a",{get:function(){return 7}}).a!=7}),s=t.document,c=r(s)&&r(s.createElement),l=function(e){return c?s.createElement(e):{}},u=!o&&!a(function(){return Object.defineProperty(l(`div`),"a",{get:function(){return 7}}).a!=7}),d=function(e,t){if(!r(e))return e;var n,i;if(t&&typeof(n=e.toString)==`function`&&!r(i=n.call(e))||typeof(n=e.valueOf)==`function`&&!r(i=n.call(e))||!t&&typeof(n=e.toString)==`function`&&!r(i=n.call(e)))return i;throw TypeError(`Can't convert object to primitive value`)},f=Object.defineProperty,p={f:o?Object.defineProperty:function(e,t,n){if(i(e),t=d(t,!0),i(n),u)try{return f(e,t,n)}catch{}if(`get`in n||`set`in n)throw TypeError(`Accessors not supported!`);return`value`in n&&(e[t]=n.value),e}},m=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}},h=o?function(e,t,n){return p.f(e,t,m(1,n))}:function(e,t,n){return e[t]=n,e},g={}.hasOwnProperty,_=function(e,t){return g.call(e,t)},ee=0,te=Math.random(),ne=function(e){return`Symbol(${e===void 0?``:e})_${(++ee+te).toString(36)}`},v=e(function(e){var r=`__core-js_shared__`,i=t[r]||(t[r]={});(e.exports=function(e,t){return i[e]||(i[e]=t===void 0?{}:t)})(`versions`,[]).push({version:n.version,mode:`global`,copyright:`© 2019 Denis Pushkarev (zloirock.ru)`})})(`native-function-to-string`,Function.toString),re=e(function(e){var r=ne(`src`),i=`toString`,a=(``+v).split(i);n.inspectSource=function(e){return v.call(e)},(e.exports=function(e,n,i,o){var s=typeof i==`function`;s&&(_(i,`name`)||h(i,`name`,n)),e[n]!==i&&(s&&(_(i,r)||h(i,r,e[n]?``+e[n]:a.join(String(n)))),e===t?e[n]=i:o?e[n]?e[n]=i:h(e,n,i):(delete e[n],h(e,n,i)))})(Function.prototype,i,function(){return typeof this==`function`&&this[r]||v.call(this)})}),y=function(e){if(typeof e!=`function`)throw TypeError(e+` is not a function!`);return e},b=function(e,t,n){if(y(e),t===void 0)return e;switch(n){case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}},x=`prototype`,S=function(e,r,i){var a=e&S.F,o=e&S.G,s=e&S.S,c=e&S.P,l=e&S.B,u=o?t:s?t[r]||(t[r]={}):(t[r]||{})[x],d=o?n:n[r]||(n[r]={}),f=d[x]||(d[x]={}),p,m,g,_;for(p in o&&(i=r),i)m=!a&&u&&u[p]!==void 0,g=(m?u:i)[p],_=l&&m?b(g,t):c&&typeof g==`function`?b(Function.call,g):g,u&&re(u,p,g,e&S.U),d[p]!=g&&h(d,p,_),c&&f[p]!=g&&(f[p]=g)};t.core=n,S.F=1,S.G=2,S.S=4,S.P=8,S.B=16,S.W=32,S.U=64,S.R=128;var C=S,ie=Math.ceil,ae=Math.floor,oe=function(e){return isNaN(e=+e)?0:(e>0?ae:ie)(e)},se=function(e){if(e==null)throw TypeError(`Can't call method on `+e);return e},ce=function(e){return function(t,n){var r=String(se(t)),i=oe(n),a=r.length,o,s;return i<0||i>=a?e?``:void 0:(o=r.charCodeAt(i),o<55296||o>56319||i+1===a||(s=r.charCodeAt(i+1))<56320||s>57343?e?r.charAt(i):o:e?r.slice(i,i+2):(o-55296<<10)+(s-56320)+65536)}}(!1);C(C.P,`String`,{codePointAt:function(e){return ce(this,e)}}),n.String.codePointAt;var le=Math.max,ue=Math.min,w=function(e,t){return e=oe(e),e<0?le(e+t,0):ue(e,t)},de=String.fromCharCode,T=String.fromCodePoint;C(C.S+C.F*(!!T&&T.length!=1),`String`,{fromCodePoint:function(e){for(var t=arguments,n=[],r=arguments.length,i=0,a;r>i;){if(a=+t[i++],w(a,1114111)!==a)throw RangeError(a+` is not a valid code point`);n.push(a<65536?de(a):de(((a-=65536)>>10)+55296,a%1024+56320))}return n.join(``)}}),n.String.fromCodePoint;var E={Space_Separator:/[\u1680\u2000-\u200A\u202F\u205F\u3000]/,ID_Start:/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,ID_Continue:/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/},D={isSpaceSeparator:function(e){return typeof e==`string`&&E.Space_Separator.test(e)},isIdStartChar:function(e){return typeof e==`string`&&(e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e===`$`||e===`_`||E.ID_Start.test(e))},isIdContinueChar:function(e){return typeof e==`string`&&(e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e>=`0`&&e<=`9`||e===`$`||e===`_`||e===``||e===``||E.ID_Continue.test(e))},isDigit:function(e){return typeof e==`string`&&/[0-9]/.test(e)},isHexDigit:function(e){return typeof e==`string`&&/[0-9A-Fa-f]/.test(e)}},O,k,A,j,M,N,P,F,I,fe=function(e,t){O=String(e),k=`start`,A=[],j=0,M=1,N=0,P=void 0,F=void 0,I=void 0;do P=pe(),_e[k]();while(P.type!==`eof`);return typeof t==`function`?L({"":I},``,t):I};function L(e,t,n){var r=e[t];if(typeof r==`object`&&r){if(Array.isArray(r))for(var i=0;i<r.length;i++){var a=String(i),o=L(r,a,n);o===void 0?delete r[a]:Object.defineProperty(r,a,{value:o,writable:!0,enumerable:!0,configurable:!0})}else for(var s in r){var c=L(r,s,n);c===void 0?delete r[s]:Object.defineProperty(r,s,{value:c,writable:!0,enumerable:!0,configurable:!0})}}return n.call(e,t,r)}var R,z,B,V,H;function pe(){for(R=`default`,z=``,B=!1,V=1;;){H=U();var e=me[R]();if(e)return e}}function U(){if(O[j])return String.fromCodePoint(O.codePointAt(j))}function W(){var e=U();return e===` +`?(M++,N=0):e?N+=e.length:N++,e&&(j+=e.length),e}var me={default:function(){switch(H){case` `:case`\v`:case`\f`:case` `:case`\xA0`:case``:case` +`:case`\r`:case`\u2028`:case`\u2029`:W();return;case`/`:W(),R=`comment`;return;case void 0:return W(),G(`eof`)}if(D.isSpaceSeparator(H)){W();return}return me[k]()},comment:function(){switch(H){case`*`:W(),R=`multiLineComment`;return;case`/`:W(),R=`singleLineComment`;return}throw X(W())},multiLineComment:function(){switch(H){case`*`:W(),R=`multiLineCommentAsterisk`;return;case void 0:throw X(W())}W()},multiLineCommentAsterisk:function(){switch(H){case`*`:W();return;case`/`:W(),R=`default`;return;case void 0:throw X(W())}W(),R=`multiLineComment`},singleLineComment:function(){switch(H){case` +`:case`\r`:case`\u2028`:case`\u2029`:W(),R=`default`;return;case void 0:return W(),G(`eof`)}W()},value:function(){switch(H){case`{`:case`[`:return G(`punctuator`,W());case`n`:return W(),K(`ull`),G(`null`,null);case`t`:return W(),K(`rue`),G(`boolean`,!0);case`f`:return W(),K(`alse`),G(`boolean`,!1);case`-`:case`+`:W()===`-`&&(V=-1),R=`sign`;return;case`.`:z=W(),R=`decimalPointLeading`;return;case`0`:z=W(),R=`zero`;return;case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:z=W(),R=`decimalInteger`;return;case`I`:return W(),K(`nfinity`),G(`numeric`,1/0);case`N`:return W(),K(`aN`),G(`numeric`,NaN);case`"`:case`'`:B=W()===`"`,z=``,R=`string`;return}throw X(W())},identifierNameStartEscape:function(){if(H!==`u`)throw X(W());W();var e=q();switch(e){case`$`:case`_`:break;default:if(!D.isIdStartChar(e))throw Q()}z+=e,R=`identifierName`},identifierName:function(){switch(H){case`$`:case`_`:case``:case``:z+=W();return;case`\\`:W(),R=`identifierNameEscape`;return}if(D.isIdContinueChar(H)){z+=W();return}return G(`identifier`,z)},identifierNameEscape:function(){if(H!==`u`)throw X(W());W();var e=q();switch(e){case`$`:case`_`:case``:case``:break;default:if(!D.isIdContinueChar(e))throw Q()}z+=e,R=`identifierName`},sign:function(){switch(H){case`.`:z=W(),R=`decimalPointLeading`;return;case`0`:z=W(),R=`zero`;return;case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:z=W(),R=`decimalInteger`;return;case`I`:return W(),K(`nfinity`),G(`numeric`,V*(1/0));case`N`:return W(),K(`aN`),G(`numeric`,NaN)}throw X(W())},zero:function(){switch(H){case`.`:z+=W(),R=`decimalPoint`;return;case`e`:case`E`:z+=W(),R=`decimalExponent`;return;case`x`:case`X`:z+=W(),R=`hexadecimal`;return}return G(`numeric`,V*0)},decimalInteger:function(){switch(H){case`.`:z+=W(),R=`decimalPoint`;return;case`e`:case`E`:z+=W(),R=`decimalExponent`;return}if(D.isDigit(H)){z+=W();return}return G(`numeric`,V*Number(z))},decimalPointLeading:function(){if(D.isDigit(H)){z+=W(),R=`decimalFraction`;return}throw X(W())},decimalPoint:function(){switch(H){case`e`:case`E`:z+=W(),R=`decimalExponent`;return}if(D.isDigit(H)){z+=W(),R=`decimalFraction`;return}return G(`numeric`,V*Number(z))},decimalFraction:function(){switch(H){case`e`:case`E`:z+=W(),R=`decimalExponent`;return}if(D.isDigit(H)){z+=W();return}return G(`numeric`,V*Number(z))},decimalExponent:function(){switch(H){case`+`:case`-`:z+=W(),R=`decimalExponentSign`;return}if(D.isDigit(H)){z+=W(),R=`decimalExponentInteger`;return}throw X(W())},decimalExponentSign:function(){if(D.isDigit(H)){z+=W(),R=`decimalExponentInteger`;return}throw X(W())},decimalExponentInteger:function(){if(D.isDigit(H)){z+=W();return}return G(`numeric`,V*Number(z))},hexadecimal:function(){if(D.isHexDigit(H)){z+=W(),R=`hexadecimalInteger`;return}throw X(W())},hexadecimalInteger:function(){if(D.isHexDigit(H)){z+=W();return}return G(`numeric`,V*Number(z))},string:function(){switch(H){case`\\`:W(),z+=he();return;case`"`:if(B)return W(),G(`string`,z);z+=W();return;case`'`:if(!B)return W(),G(`string`,z);z+=W();return;case` +`:case`\r`:throw X(W());case`\u2028`:case`\u2029`:ve(H);break;case void 0:throw X(W())}z+=W()},start:function(){switch(H){case`{`:case`[`:return G(`punctuator`,W())}R=`value`},beforePropertyName:function(){switch(H){case`$`:case`_`:z=W(),R=`identifierName`;return;case`\\`:W(),R=`identifierNameStartEscape`;return;case`}`:return G(`punctuator`,W());case`"`:case`'`:B=W()===`"`,R=`string`;return}if(D.isIdStartChar(H)){z+=W(),R=`identifierName`;return}throw X(W())},afterPropertyName:function(){if(H===`:`)return G(`punctuator`,W());throw X(W())},beforePropertyValue:function(){R=`value`},afterPropertyValue:function(){switch(H){case`,`:case`}`:return G(`punctuator`,W())}throw X(W())},beforeArrayValue:function(){if(H===`]`)return G(`punctuator`,W());R=`value`},afterArrayValue:function(){switch(H){case`,`:case`]`:return G(`punctuator`,W())}throw X(W())},end:function(){throw X(W())}};function G(e,t){return{type:e,value:t,line:M,column:N}}function K(e){for(var t=0,n=e;t<n.length;t+=1){var r=n[t];if(U()!==r)throw X(W());W()}}function he(){switch(U()){case`b`:return W(),`\b`;case`f`:return W(),`\f`;case`n`:return W(),` +`;case`r`:return W(),`\r`;case`t`:return W(),` `;case`v`:return W(),`\v`;case`0`:if(W(),D.isDigit(U()))throw X(W());return`\0`;case`x`:return W(),ge();case`u`:return W(),q();case` +`:case`\u2028`:case`\u2029`:return W(),``;case`\r`:return W(),U()===` +`&&W(),``;case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:throw X(W());case void 0:throw X(W())}return W()}function ge(){var e=``,t=U();if(!D.isHexDigit(t)||(e+=W(),t=U(),!D.isHexDigit(t)))throw X(W());return e+=W(),String.fromCodePoint(parseInt(e,16))}function q(){for(var e=``,t=4;t-->0;){var n=U();if(!D.isHexDigit(n))throw X(W());e+=W()}return String.fromCodePoint(parseInt(e,16))}var _e={start:function(){if(P.type===`eof`)throw Z();J()},beforePropertyName:function(){switch(P.type){case`identifier`:case`string`:F=P.value,k=`afterPropertyName`;return;case`punctuator`:Y();return;case`eof`:throw Z()}},afterPropertyName:function(){if(P.type===`eof`)throw Z();k=`beforePropertyValue`},beforePropertyValue:function(){if(P.type===`eof`)throw Z();J()},beforeArrayValue:function(){if(P.type===`eof`)throw Z();if(P.type===`punctuator`&&P.value===`]`){Y();return}J()},afterPropertyValue:function(){if(P.type===`eof`)throw Z();switch(P.value){case`,`:k=`beforePropertyName`;return;case`}`:Y()}},afterArrayValue:function(){if(P.type===`eof`)throw Z();switch(P.value){case`,`:k=`beforeArrayValue`;return;case`]`:Y()}},end:function(){}};function J(){var e;switch(P.type){case`punctuator`:switch(P.value){case`{`:e={};break;case`[`:e=[]}break;case`null`:case`boolean`:case`numeric`:case`string`:e=P.value}if(I===void 0)I=e;else{var t=A[A.length-1];Array.isArray(t)?t.push(e):Object.defineProperty(t,F,{value:e,writable:!0,enumerable:!0,configurable:!0})}if(typeof e==`object`&&e)A.push(e),k=Array.isArray(e)?`beforeArrayValue`:`beforePropertyName`;else{var n=A[A.length-1];k=n==null?`end`:Array.isArray(n)?`afterArrayValue`:`afterPropertyValue`}}function Y(){A.pop();var e=A[A.length-1];k=e==null?`end`:Array.isArray(e)?`afterArrayValue`:`afterPropertyValue`}function X(e){return $(e===void 0?`JSON5: invalid end of input at `+M+`:`+N:`JSON5: invalid character '`+ye(e)+`' at `+M+`:`+N)}function Z(){return $(`JSON5: invalid end of input at `+M+`:`+N)}function Q(){return N-=5,$(`JSON5: invalid identifier character at `+M+`:`+N)}function ve(e){console.warn(`JSON5: '`+ye(e)+`' in strings is not valid ECMAScript; consider escaping`)}function ye(e){var t={"'":`\\'`,'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`,"\v":`\\v`,"\0":`\\0`,"\u2028":`\\u2028`,"\u2029":`\\u2029`};if(t[e])return t[e];if(e<` `){var n=e.charCodeAt(0).toString(16);return`\\x`+(`00`+n).substring(n.length)}return e}function $(e){var t=SyntaxError(e);return t.lineNumber=M,t.columnNumber=N,t}return{parse:fe,stringify:function(e,t,n){var r=[],i=``,a,o,s=``,c;if(typeof t==`object`&&t&&!Array.isArray(t)&&(n=t.space,c=t.quote,t=t.replacer),typeof t==`function`)o=t;else if(Array.isArray(t)){a=[];for(var l=0,u=t;l<u.length;l+=1){var d=u[l],f=void 0;typeof d==`string`?f=d:(typeof d==`number`||d instanceof String||d instanceof Number)&&(f=String(d)),f!==void 0&&a.indexOf(f)<0&&a.push(f)}}return n instanceof Number?n=Number(n):n instanceof String&&(n=String(n)),typeof n==`number`?n>0&&(n=Math.min(10,Math.floor(n)),s=` `.substr(0,n)):typeof n==`string`&&(s=n.substr(0,10)),p(``,{"":e});function p(e,t){var n=t[e];switch(n!=null&&(typeof n.toJSON5==`function`?n=n.toJSON5(e):typeof n.toJSON==`function`&&(n=n.toJSON(e))),o&&(n=o.call(t,e,n)),n instanceof Number?n=Number(n):n instanceof String?n=String(n):n instanceof Boolean&&(n=n.valueOf()),n){case null:return`null`;case!0:return`true`;case!1:return`false`}if(typeof n==`string`)return m(n,!1);if(typeof n==`number`)return String(n);if(typeof n==`object`)return Array.isArray(n)?_(n):h(n)}function m(e){for(var t={"'":.1,'"':.2},n={"'":`\\'`,'"':`\\"`,"\\":`\\\\`,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`,"\v":`\\v`,"\0":`\\0`,"\u2028":`\\u2028`,"\u2029":`\\u2029`},r=``,i=0;i<e.length;i++){var a=e[i];switch(a){case`'`:case`"`:t[a]++,r+=a;continue;case`\0`:if(D.isDigit(e[i+1])){r+=`\\x00`;continue}}if(n[a]){r+=n[a];continue}if(a<` `){var o=a.charCodeAt(0).toString(16);r+=`\\x`+(`00`+o).substring(o.length);continue}r+=a}var s=c||Object.keys(t).reduce(function(e,n){return t[e]<t[n]?e:n});return r=r.replace(new RegExp(s,`g`),n[s]),s+r+s}function h(e){if(r.indexOf(e)>=0)throw TypeError(`Converting circular structure to JSON5`);r.push(e);var t=i;i+=s;for(var n=a||Object.keys(e),o=[],c=0,l=n;c<l.length;c+=1){var u=l[c],d=p(u,e);if(d!==void 0){var f=g(u)+`:`;s!==``&&(f+=` `),f+=d,o.push(f)}}var m;if(o.length===0)m=`{}`;else{var h;if(s===``)h=o.join(`,`),m=`{`+h+`}`;else{var _=`, `+i;h=o.join(_),m=`{ `+i+h+`, `+t+`}`}}return r.pop(),i=t,m}function g(e){if(e.length===0)return m(e,!0);var t=String.fromCodePoint(e.codePointAt(0));if(!D.isIdStartChar(t))return m(e,!0);for(var n=t.length;n<e.length;n++)if(!D.isIdContinueChar(String.fromCodePoint(e.codePointAt(n))))return m(e,!0);return e}function _(e){if(r.indexOf(e)>=0)throw TypeError(`Converting circular structure to JSON5`);r.push(e);var t=i;i+=s;for(var n=[],a=0;a<e.length;a++){var o=p(String(a),e);n.push(o===void 0?`null`:o)}var c;if(n.length===0)c=`[]`;else if(s===``)c=`[`+n.join(`,`)+`]`;else{var l=`, `+i,u=n.join(l);c=`[ `+i+u+`, -`+t+`]`}return r.pop(),i=t,c}}}}))})),w=/* @__PURE__ */ e(n(),1);de();const T=String.raw`"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'|/\*[\s\S]*?\*/|//[^\n]*`;RegExp(`${T}|\\.\\.\\.@|@`,`g`),RegExp(`\\{'@':true\\}|'\\.\\.\\.@':true|${T}`,`g`),RegExp(`${T}|[()[\\]{}]`,`g`);const E=/* @__PURE__ */ new Set([`__defineGetter__`,`__defineSetter__`,`__lookupGetter__`,`__lookupSetter__`,`__proto__`,`catch`,`constructor`,`dup`,`finally`,`hasOwnProperty`,`isPrototypeOf`,`map`,`onRpcBroken`,`propertyIsEnumerable`,`prototype`,`then`,`toLocaleString`,`toString`,`valueOf`,`toJSON`,`asymmetricMatch`]);function D(e,t,n){let r=r=>D(e,t,[...n,r]);return new Proxy(function(){},{apply(r,i,a){let o=n[n.length-1],s=[...t,...n.slice(0,-1),[o,...a]];return e.invoke(s)},get(e,t,n){if(typeof t==`symbol`)return Reflect.get(e,t,n);if(!E.has(t))return r(t)},getOwnPropertyDescriptor(e,t){let n=Reflect.getOwnPropertyDescriptor(e,t);if(n)return n;if(!(typeof t==`symbol`||E.has(t)))return{configurable:!0,enumerable:!0,value:r(t),writable:!1}},has(e,t){return typeof t==`symbol`?t in e:!E.has(t)}})}function O(e,t){let n=Object.getPrototypeOf(e.prototype),r=new Proxy(Object.create(n),{get(n,r,i){if(typeof r==`symbol`||r in n)return Reflect.get(n,r,i);if(!E.has(r)&&i instanceof e)return D(i,t,[r])}});Object.setPrototypeOf(e.prototype,r)}O(class extends i{#e;takesTheRest;constructor(e,t={}){super(),this.#e=e,this.takesTheRest=t.takesTheRest??!1}invoke(e){return this.#e(e)}applyRoot(e){return this.#e([[``,...e]])}},[]);function k(e){if(!e.stateSchema.safeParse({}).success)throw Error(`contract "${e.slug}": stateSchema must parse {} (default every field)`);let t=e.events??{},n=e.processorDeps??[],r=/* @__PURE__ */ new Set;for(let i of n)for(let n of Object.keys(i.events)){if(n in t)throw Error(`contract "${e.slug}": event "${n}" is already owned by a dep`);if(r.has(n))throw Error(`contract "${e.slug}": event "${n}" is declared by two deps`);r.add(n)}let i=e=>t[e]??n.map(t=>t.events[e]).find(Boolean);return{slug:e.slug,version:e.version,description:e.description,consumes:e.consumes,emits:e.emits,stateSchema:e.stateSchema,events:t,processorDeps:n,initialState:()=>e.stateSchema.parse({}),payloadSchemaFor:e=>i(e)?.payloadSchema,eventDefinitionFor:i}}const A=l().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/).max(63),j=u({url:g({protocol:/^https?$/}).max(2048)}),M=u({kind:p([`ok`,`attention`,`error`]),text:l().max(200).optional()}),N=l().min(1).max(400),P=u({label:l().min(1).max(40),...j.shape,confirm:N.optional()}),F=`integrationCalls`,I=f(l().max(64)).max(64),fe=/* @__PURE__ */ new Set([...E,F,`invoke`,`applyRoot`,`takesTheRest`,`fetch`,`processEvent`,`processMindEvent`,`deliverEvent`,`email`,`callWithCause`,`mcpCall`,`getItx`,`auth`,`env`,`ctx`,`callerPath`]);function pe(e){let t;try{t=JSON.stringify(e)}catch{return!1}if(t.length>2048)return!1;let n=0,r=0,i=!1;for(let e=0;e<t.length;e+=1){let a=t[e];i?a===`\\`?e+=1:a===`"`&&(i=!1):a===`"`?i=!0:a===`[`||a===`{`?r=Math.max(r,n+=1):(a===`]`||a===`}`)&&--n}return r<=9}const L=u({name:l().regex(/^[a-z][a-zA-Z0-9]{0,63}$/).refine(e=>!fe.has(e),`no function a button may call`),args:f(h()).max(8).refine(pe,`at most 2 KB of arguments, 8 deep`).pipe(f(s())).optional()});function R(e){let t=(e.args||[]).map(e=>JSON.stringify(e)).join(`, `);return`${e.name}(${t})`.replace(/[^\x20-\x7e]/gu,e=>`\\u{${e.codePointAt(0).toString(16)}}`)}const z=u({label:l().min(1).max(40),call:L,confirm:N.optional()}),B=m({link:l().optional().catch(void 0),said:l().transform(e=>e.slice(0,400)).optional().catch(void 0)});function V(e,t){let n=B.safeParse(e).data?.link;if(!n)return null;if(!URL.canParse(n))return{refused:`a link that is no absolute URL`};let r=new URL(n);if(r.protocol!==`https:`)return{refused:`a link that is not https`};if(r.username||r.password||r.port)return{refused:`a link on ${r.host} with a user name, a password or a port`};let i=t.toLowerCase();return i&&r.hostname===i?{follow:r}:{refused:`a link on ${r.hostname}, which is no host of this mind`}}const me=a([P,z]),H=g({protocol:/^https$/}).max(2048),U=u({title:l().min(1).max(80),description:l().max(400).optional(),icon:H.optional(),section:A.optional(),status:M.optional(),actions:f(me).max(4).default([])}),W=u({account:l().min(1).max(200),status:M.optional(),actions:f(me).max(4).default([]),details:d(l().min(1).max(40),l().max(200)).refine(e=>Object.keys(e).length<=10,`at most ten details`).optional()});k({slug:`integration`,version:`1`,description:`The integrations a mind's packages registered, and their connections: what the Dash's Integrations page shows.`,stateSchema:c({integrations:d(l(),U).default({}),connections:d(l(),W).default({})}),events:{"events.iterate.com/integration/configured":{description:`A package registered its card, or registered it again with a change; a null card unregisters it and its connections with it.`,payloadSchema:u({integration:A,card:U.nullable()})},"events.iterate.com/integration/connection-configured":{description:`A package set one connection's row under its card, or set it again with a change; a null row removes it.`,payloadSchema:u({integration:A,connection:l().regex(/^(?!\.\.?$)[a-zA-Z0-9._-]{1,64}$/),row:W.nullable()})}},consumes:[`events.iterate.com/integration/configured`,`events.iterate.com/integration/connection-configured`],emits:[]});function G(e,t,n,r,i){let a=ee(e,t),s=te(a.stub,n,r),c=s.value?i.safeParse(s.value):void 0,l=a.error||s.error||(c?.error?o(c.error):null);return{stub:a.stub,value:s.value,state:c?.data,error:l,failed:!!a.error||s.status===`error`,seeding:s.status===`connecting`&&!!s.value,settled:!!s.value||!!l}}var K=/* @__PURE__ */ e(r(),1);const he=m({integrations:d(l(),h()),connections:d(l(),h())});function ge(e,t){let n,r=async()=>{try{return new Set(I.parse(await e(F,[])))}catch(e){if(_(e)===`NOT_A_METHOD`)return/* @__PURE__ */ new Set;throw n=void 0,e}};return{call:e,controlPlane:t,offered:()=>n||=r()}}function q({openRegistry:e,deps:t,seed:n,callConfig:r,mind:i}){let a=(0,w.useMemo)(()=>r?ge(r,i||``):void 0,[r,i]),o=G(e,t,`integration`,n,he);return/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-8 p-4 md:p-8`,children:[/* @__PURE__ */ (0,K.jsxs)(`header`,{className:`flex flex-col gap-1.5`,children:[/* @__PURE__ */ (0,K.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold tracking-tight`,children:[`Integrations`,o.seeding?/* @__PURE__ */ (0,K.jsx)(x,{}):null]}),/* @__PURE__ */ (0,K.jsx)(`p`,{className:`max-w-prose text-sm text-muted-foreground`,children:`To connect an account or a service, ask your agent: "connect my Gmail", "set up a Telegram bot". What it connects shows here.`})]}),o.error?/* @__PURE__ */ (0,K.jsxs)(`p`,{role:`alert`,"data-type":`error`,className:`text-sm text-destructive`,children:[`Couldn't load this mind's integrations: `,o.error]}):null,o.settled?null:/* @__PURE__ */ (0,K.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading…`}),o.state?/* @__PURE__ */ (0,K.jsx)(_e,{registry:o.state,caller:a}):null]})}function _e({registry:e,caller:t}){let n=Object.entries(e.integrations).flatMap(([e,t])=>{let n=U.safeParse(t).data;return n?[{integration:e,card:n}]:[]}),r=Object.entries(e.connections).flatMap(([e,t])=>{let n=W.safeParse(t).data,r=e.indexOf(`/`);return n?[{integration:e.slice(0,r),connection:e.slice(r+1),row:n}]:[]});if(n.length===0)return/* @__PURE__ */ (0,K.jsx)(J,{});n.sort((e,t)=>e.card.title.localeCompare(t.card.title));let i=n.flatMap(e=>{let t=n.filter(({card:t})=>t.section===e.integration);return t.length?[{section:e.integration,heading:e.card,entry:e,cards:t}]:[]}).sort((e,t)=>e.heading.title.localeCompare(t.heading.title)),a=new Set(i.flatMap(e=>[e.entry,...e.cards])),o=n.filter(e=>!a.has(e)),s=e=>e.map(({integration:e,card:n})=>/* @__PURE__ */ (0,K.jsx)(Y,{integration:e,card:n,rows:r.filter(t=>t.integration===e),caller:t},e)),c=e=>/* @__PURE__ */ (0,K.jsx)(`div`,{className:`divide-y overflow-hidden rounded-lg border bg-card`,children:s(e)});return/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[i.map(({section:e,heading:t,cards:n})=>/* @__PURE__ */ (0,K.jsxs)(`section`,{"aria-labelledby":`integrations-section-${e}`,className:`flex flex-col gap-3`,children:[/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.icon?/* @__PURE__ */ (0,K.jsx)(X,{title:t.title,icon:t.icon,small:!0}):null,/* @__PURE__ */ (0,K.jsx)(`h2`,{id:`integrations-section-${e}`,className:`text-base font-semibold tracking-tight`,children:t.title})]}),t.description&&/* @__PURE__ */ (0,K.jsx)(`p`,{className:`max-w-prose text-sm text-muted-foreground`,children:t.description})]}),c(n)]},e)),o.length?/* @__PURE__ */ (0,K.jsxs)(`section`,{"aria-label":`This mind's own integrations`,className:`flex flex-col gap-3`,children:[i.length?/* @__PURE__ */ (0,K.jsx)(`h2`,{className:`text-base font-semibold tracking-tight`,children:`This mind's own`}):null,c(o)]}):null]})}function J(){return/* @__PURE__ */ (0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Nothing is connected yet.`})}function Y({integration:e,card:t,rows:n,caller:r}){let i=`integration-${e}-heading`,a=n.flatMap(({row:e})=>e.status?[e.status.kind]:[]).toSorted((e,t)=>Q[t]-Q[e])[0],o=a&&Q[a]>Q[t.status?.kind||`ok`]?{kind:a}:t.status;return/* @__PURE__ */ (0,K.jsxs)(`section`,{"aria-labelledby":i,className:`flex min-w-0 flex-col`,children:[/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 px-4 py-3.5 sm:flex-row sm:items-start`,children:[/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`flex min-w-0 flex-1 gap-3`,children:[/* @__PURE__ */ (0,K.jsx)(X,{title:t.title,icon:t.icon}),/* @__PURE__ */ (0,K.jsxs)(`div`,{className:y(`flex min-w-0 flex-1 flex-col gap-0.5`,!t.description&&!o&&`self-center`),children:[/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2.5 gap-y-0.5`,children:[/* @__PURE__ */ (0,K.jsx)(`h3`,{id:i,className:`text-sm font-semibold [overflow-wrap:anywhere]`,children:t.title}),o?/* @__PURE__ */ (0,K.jsx)(be,{status:o}):null]}),t.description&&/* @__PURE__ */ (0,K.jsx)(`p`,{className:`max-w-prose text-xs/5 text-muted-foreground`,children:t.description})]})]}),/* @__PURE__ */ (0,K.jsx)(Se,{actions:t.actions,caller:r,first:n.length===0&&!t.status?`default`:`secondary`,className:`shrink-0 pl-11 sm:pl-0`})]}),n.length===0?null:/* @__PURE__ */ (0,K.jsx)(`ul`,{className:`mr-4 mb-1 ml-15 flex flex-col divide-y border-t`,"aria-label":`${t.title} connections`,children:n.map(({connection:e,row:t})=>/* @__PURE__ */ (0,K.jsx)(Z,{row:t,caller:r},e))})]})}function X({title:e,icon:t,small:n}){let r=n?`size-5 rounded`:`size-8 rounded-md`;return t?/* @__PURE__ */ (0,K.jsx)(`img`,{src:t,alt:``,className:y(`shrink-0 object-contain`,r)}):/* @__PURE__ */ (0,K.jsx)(`span`,{"aria-hidden":`true`,className:y(`flex shrink-0 items-center justify-center border bg-muted text-xs font-semibold text-muted-foreground uppercase`,r),children:e.slice(0,1)})}function Z({row:e,caller:t}){return/* @__PURE__ */ (0,K.jsxs)(`li`,{className:`flex flex-col gap-2 py-2.5 sm:flex-row sm:items-start sm:gap-3`,children:[/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[e.status?/* @__PURE__ */ (0,K.jsx)(ye,{status:e.status,className:`mt-1.5`}):/* @__PURE__ */ (0,K.jsx)(`span`,{className:`size-2 shrink-0`}),/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[/* @__PURE__ */ (0,K.jsx)(`p`,{className:`truncate text-sm font-medium`,title:e.account,children:e.account}),e.status&&(e.status.kind!==`ok`||e.status.text)?/* @__PURE__ */ (0,K.jsx)($,{status:e.status}):null,e.details&&/* @__PURE__ */ (0,K.jsx)(`dl`,{className:`flex flex-wrap gap-x-4 gap-y-0.5 text-xs text-muted-foreground`,children:Object.entries(e.details).map(([e,t])=>/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`min-w-0 [overflow-wrap:anywhere]`,children:[/* @__PURE__ */ (0,K.jsxs)(`dt`,{className:`inline`,children:[e,` `]}),/* @__PURE__ */ (0,K.jsx)(`dd`,{className:`inline text-foreground/80`,children:t})]},e))})]})]}),/* @__PURE__ */ (0,K.jsx)(Se,{actions:e.actions,caller:t,className:`shrink-0 pl-4.5 sm:pl-0`})]})}const ve={ok:`OK`,attention:`Needs attention`,error:`Failed`},Q={ok:0,attention:1,error:2};function ye({status:e,className:t}){return/* @__PURE__ */ (0,K.jsx)(`span`,{role:`img`,"aria-label":ve[e.kind],className:y(`size-2 shrink-0 rounded-full`,{ok:`bg-success`,attention:`bg-warning`,error:`bg-destructive`}[e.kind],t)})}function $({status:e}){return/* @__PURE__ */ (0,K.jsx)(`p`,{"data-type":e.kind===`error`?`error`:void 0,className:y(`text-xs [overflow-wrap:anywhere]`,e.kind===`ok`&&`text-muted-foreground`,e.kind===`attention`&&`text-warning`,e.kind===`error`&&`text-destructive`),children:e.text||ve[e.kind]})}function be({status:e}){return/* @__PURE__ */ (0,K.jsxs)(`div`,{className:`flex max-w-full items-center gap-1.5`,children:[/* @__PURE__ */ (0,K.jsx)(ye,{status:e}),/* @__PURE__ */ (0,K.jsx)($,{status:e})]})}const xe=()=>()=>{};function Se({actions:e,caller:t,first:n=`secondary`,className:r}){let i=(0,w.useSyncExternalStore)(xe,()=>window.location.origin,()=>``),a=/* @__PURE__ */ new Map;for(let t of e){if(`call`in t){let{label:e,call:n,confirm:r}=t;a.set(`${e}\ncall ${n.name} ${JSON.stringify(n.args||[])}`,{label:e,call:n,confirm:r});continue}let e=new URL(t.url).origin!==i;t.confirm&&e||a.set(`${t.label}\n${t.url}`,{label:t.label,href:t.url,beside:e,confirm:t.confirm})}let[o,s]=(0,w.useState)(null);return a.size===0?null:/* @__PURE__ */ (0,K.jsxs)(`div`,{className:y(`flex flex-col items-start gap-1 sm:items-end`,r),children:[/* @__PURE__ */ (0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[...a].map(([e,r],i)=>{let a=i===0&&!r.confirm?n:`secondary`;if(`call`in r)return/* @__PURE__ */ (0,K.jsx)(De,{label:r.label,call:r.call,question:r.confirm,variant:a,caller:t,report:s},e);let{label:o,href:c,beside:l,confirm:u}=r;return u?/* @__PURE__ */ (0,K.jsx)(Ce,{label:o,url:c,question:u,report:s},e):/* @__PURE__ */ (0,K.jsxs)(`a`,{href:c,...l&&{target:`_blank`,rel:`noreferrer`},className:re({variant:a,size:`sm`}),children:[o,l?/* @__PURE__ */ (0,K.jsx)(ne,{"data-icon":`inline-end`}):/* @__PURE__ */ (0,K.jsx)(v,{"data-icon":`inline-end`})]},e)})}),o?/* @__PURE__ */ (0,K.jsx)(Te,{outcome:o}):null]})}function Ce({label:e,url:t,question:n,report:r}){let[i,a]=(0,w.useState)(!1),o=async()=>{a(!0),r(null);try{let n=await fetch(t,{method:`POST`});n.ok||r({error:await n.text()||`${e} failed (${n.status}).`})}catch(e){r({error:Ee(e)})}finally{a(!1)}};return/* @__PURE__ */ (0,K.jsx)(we,{label:e,question:n,busy:i,onYes:()=>void o()})}function we({label:e,question:t,busy:n,onYes:r}){let i=t.indexOf(`? `),a=i>0?t.slice(0,i+1):`${e}?`,o=i>0?t.slice(i+2):t,[s,c]=(0,w.useState)(!1);return/* @__PURE__ */ (0,K.jsxs)(S,{open:s,onOpenChange:c,children:[/* @__PURE__ */ (0,K.jsx)(ue,{render:/* @__PURE__ */ (0,K.jsx)(b,{variant:`secondary`,size:`sm`}),disabled:!!n,"aria-busy":!!n||void 0,children:n?typeof n==`string`?n:`${e}…`:e}),/* @__PURE__ */ (0,K.jsxs)(ae,{children:[/* @__PURE__ */ (0,K.jsxs)(ce,{children:[/* @__PURE__ */ (0,K.jsx)(le,{children:a}),/* @__PURE__ */ (0,K.jsx)(oe,{children:o})]}),/* @__PURE__ */ (0,K.jsxs)(se,{children:[/* @__PURE__ */ (0,K.jsx)(ie,{children:`Cancel`}),/* @__PURE__ */ (0,K.jsx)(C,{onClick:()=>{c(!1),r()},children:e})]})]})]})}function Te({outcome:e}){return`error`in e?/* @__PURE__ */ (0,K.jsx)(`p`,{role:`alert`,"data-type":`error`,className:`max-w-xs text-xs text-destructive sm:text-right`,children:e.error}):/* @__PURE__ */ (0,K.jsx)(`p`,{role:`status`,className:`max-w-xs text-xs text-muted-foreground sm:text-right`,children:e.said})}const Ee=e=>e instanceof Error?e.message:String(e);function De({label:e,call:t,question:n,variant:r,caller:i,report:a}){let[o,s]=(0,w.useState)(!1),[c,l]=(0,w.useState)(!1),u=(0,w.useId)(),d=(0,w.useRef)(!1),f=(0,w.useRef)(!0);if((0,w.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]),(0,w.useEffect)(()=>{let e=e=>{e.persisted&&(d.current=!1,s(!1))};return window.addEventListener(`pageshow`,e),()=>window.removeEventListener(`pageshow`,e)},[]),!i){let t=`This page cannot call the mind's config: its host gave it no way to.`;return/* @__PURE__ */ (0,K.jsx)(`span`,{title:t,className:`inline-flex`,children:/* @__PURE__ */ (0,K.jsx)(b,{variant:r,size:`sm`,disabled:!0,title:t,children:e})})}let p=async()=>{if(d.current)return;d.current=!0,s(`${e}…`),a(null);let n=!1;try{let e=await i.offered();if(!e.has(t.name)){a({error:e.size?`This button calls ${t.name}, which this mind's config does not offer to buttons.`:`This mind's config offers no function to buttons, so this button calls nothing.`});return}let r=await i.call(t.name,t.args||[]),o=B.safeParse(r).data?.said,c=V(r,i.controlPlane);if(c&&`follow`in c){if(!f.current)return;n=!0,s(`Opening ${c.follow.hostname}…`),window.location.assign(c.follow.href);return}c?a({error:`This button's call answered ${c.refused}: the page does not follow it.`}):o&&a({said:o})}catch(e){a({error:`This button's call failed: ${Ee(e)}`.slice(0,400)})}finally{n||(d.current=!1,s(!1))}},m=R(t),h=/* @__PURE__ */ (0,K.jsxs)(K.Fragment,{children:[o||e,o?/* @__PURE__ */ (0,K.jsx)(x,{"data-icon":`inline-end`}):null]}),g=/* @__PURE__ */ (0,K.jsx)(`span`,{id:u,className:`sr-only`,children:m}),_={disabled:!!o,"aria-busy":!!o||void 0,"aria-describedby":u,title:m};return n?/* @__PURE__ */ (0,K.jsxs)(S,{open:c,onOpenChange:l,children:[/* @__PURE__ */ (0,K.jsx)(ue,{render:/* @__PURE__ */ (0,K.jsx)(b,{variant:r,size:`sm`}),..._,children:h}),g,/* @__PURE__ */ (0,K.jsxs)(ae,{children:[/* @__PURE__ */ (0,K.jsxs)(ce,{children:[/* @__PURE__ */ (0,K.jsx)(le,{children:`Call this mind's config?`}),/* @__PURE__ */ (0,K.jsxs)(oe,{render:/* @__PURE__ */ (0,K.jsx)(`div`,{}),className:`flex w-full min-w-0 flex-col gap-3 text-left`,children:[/* @__PURE__ */ (0,K.jsxs)(`figure`,{className:`flex flex-col gap-1 border-l-2 border-border pl-3`,children:[/* @__PURE__ */ (0,K.jsx)(`figcaption`,{className:`text-xs`,children:`The card says:`}),/* @__PURE__ */ (0,K.jsx)(`blockquote`,{className:`text-foreground [overflow-wrap:anywhere]`,children:n})]}),/* @__PURE__ */ (0,K.jsx)(`p`,{children:`This button calls`}),/* @__PURE__ */ (0,K.jsx)(`pre`,{dir:`ltr`,"data-slot":`call-text`,className:`max-h-48 w-full overflow-auto rounded-md bg-muted p-2 text-left font-mono text-xs whitespace-pre-wrap text-foreground [overflow-wrap:anywhere] [unicode-bidi:isolate]`,children:/* @__PURE__ */ (0,K.jsx)(`bdi`,{dir:`ltr`,children:m})}),/* @__PURE__ */ (0,K.jsx)(`p`,{children:`in this mind's config, as you.`})]})]}),/* @__PURE__ */ (0,K.jsxs)(se,{children:[/* @__PURE__ */ (0,K.jsx)(ie,{children:`Cancel`}),/* @__PURE__ */ (0,K.jsx)(C,{onClick:()=>{l(!1),p()},children:e})]})]})]}):/* @__PURE__ */ (0,K.jsxs)(K.Fragment,{children:[/* @__PURE__ */ (0,K.jsx)(b,{variant:r,size:`sm`,..._,onClick:()=>void p(),children:h}),g]})}export{q as IntegrationsPage}; +`+t+`]`}return r.pop(),i=t,c}}}}))})))();const T=String.raw`"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'|/\*[\s\S]*?\*/|//[^\n]*`;RegExp(`${T}|\\.\\.\\.@|@`,`g`),RegExp(`\\{'@':true\\}|'\\.\\.\\.@':true|${T}`,`g`),RegExp(`${T}|[()[\\]{}]`,`g`);const E=/* @__PURE__ */ new Set([`__defineGetter__`,`__defineSetter__`,`__lookupGetter__`,`__lookupSetter__`,`__proto__`,`catch`,`constructor`,`dup`,`finally`,`hasOwnProperty`,`isPrototypeOf`,`map`,`onRpcBroken`,`propertyIsEnumerable`,`prototype`,`then`,`toLocaleString`,`toString`,`valueOf`,`toJSON`,`asymmetricMatch`]);function D(e,t,n){let r=r=>D(e,t,[...n,r]);return new Proxy(function(){},{apply(r,i,a){let o=n[n.length-1],s=[...t,...n.slice(0,-1),[o,...a]];return e.invoke(s)},get(e,t,n){if(typeof t==`symbol`)return Reflect.get(e,t,n);if(!E.has(t))return r(t)},getOwnPropertyDescriptor(e,t){let n=Reflect.getOwnPropertyDescriptor(e,t);if(n)return n;if(!(typeof t==`symbol`||E.has(t)))return{configurable:!0,enumerable:!0,value:r(t),writable:!1}},has(e,t){return typeof t==`symbol`?t in e:!E.has(t)}})}function O(e,t){let n=Object.getPrototypeOf(e.prototype),r=new Proxy(Object.create(n),{get(n,r,i){if(typeof r==`symbol`||r in n)return Reflect.get(n,r,i);if(!E.has(r)&&i instanceof e)return D(i,t,[r])}});Object.setPrototypeOf(e.prototype,r)}O(class extends i{#e;takesTheRest;constructor(e,t={}){super(),this.#e=e,this.takesTheRest=t.takesTheRest??!1}invoke(e){return this.#e(e)}applyRoot(e){return this.#e([[``,...e]])}},[]);const k=l().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/).max(63),A=u({url:g({protocol:/^https?$/}).max(2048)}),j=u({kind:p([`ok`,`attention`,`error`]),text:l().max(200).optional()}),M=l().min(1).max(400),N=u({label:l().min(1).max(40),...A.shape,confirm:M.optional()}),P=`integrationCalls`,F=f(l().max(64)).max(64),I=/* @__PURE__ */ new Set([...E,P,`invoke`,`applyRoot`,`takesTheRest`,`fetch`,`processEvent`,`processMindEvent`,`deliverEvent`,`email`,`callWithCause`,`mcpCall`,`getItx`,`auth`,`env`,`ctx`,`callerPath`]);function fe(e){let t;try{t=JSON.stringify(e)}catch{return!1}if(t.length>2048)return!1;let n=0,r=0,i=!1;for(let e=0;e<t.length;e+=1){let a=t[e];i?a===`\\`?e+=1:a===`"`&&(i=!1):a===`"`?i=!0:a===`[`||a===`{`?r=Math.max(r,n+=1):(a===`]`||a===`}`)&&--n}return r<=9}const L=u({name:l().regex(/^[a-z][a-zA-Z0-9]{0,63}$/).refine(e=>!I.has(e),`no function a button may call`),args:f(h()).max(8).refine(fe,`at most 2 KB of arguments, 8 deep`).pipe(f(s())).optional()});function R(e){let t=(e.args||[]).map(e=>JSON.stringify(e)).join(`, `);return`${e.name}(${t})`.replace(/[^\x20-\x7e]/gu,e=>`\\u{${e.codePointAt(0).toString(16)}}`)}const z=u({label:l().min(1).max(40),call:L,confirm:M.optional()}),B=m({link:l().optional().catch(void 0),said:l().transform(e=>e.slice(0,400)).optional().catch(void 0)});function V(e,t){let n=B.safeParse(e).data?.link;if(!n)return null;if(!URL.canParse(n))return{refused:`a link that is no absolute URL`};let r=new URL(n);if(r.protocol!==`https:`)return{refused:`a link that is not https`};if(r.username||r.password||r.port)return{refused:`a link on ${r.host} with a user name, a password or a port`};let i=t.toLowerCase();return i&&r.hostname===i?{follow:r}:{refused:`a link on ${r.hostname}, which is no host of this mind`}}const H=a([N,z]),pe=g({protocol:/^https$/}).max(2048),U=u({title:l().min(1).max(80),description:l().max(400).optional(),icon:pe.optional(),section:k.optional(),status:j.optional(),actions:f(H).max(4).default([])}),W=u({account:l().min(1).max(200),status:j.optional(),actions:f(H).max(4).default([]),details:d(l().min(1).max(40),l().max(200)).refine(e=>Object.keys(e).length<=10,`at most ten details`).optional()});de({slug:`integration`,version:`1`,description:`The integrations a mind's packages registered, and their connections: what the Dash's Integrations page shows.`,stateSchema:c({integrations:d(l(),U).default({}),connections:d(l(),W).default({})}),events:{"events.iterate.com/integration/configured":{description:`A package registered its card, or registered it again with a change; a null card unregisters it and its connections with it.`,payloadSchema:u({integration:k,card:U.nullable()})},"events.iterate.com/integration/connection-configured":{description:`A package set one connection's row under its card, or set it again with a change; a null row removes it.`,payloadSchema:u({integration:k,connection:l().regex(/^(?!\.\.?$)[a-zA-Z0-9._-]{1,64}$/),row:W.nullable()})}},consumes:[`events.iterate.com/integration/configured`,`events.iterate.com/integration/connection-configured`],emits:[]});function me(e,t,n,r,i){let a=ee(e,t),s=te(a.stub,n,r),c=s.value?i.safeParse(s.value):void 0,l=a.error||s.error||(c?.error?o(c.error):null);return{stub:a.stub,value:s.value,state:c?.data,error:l,failed:!!a.error||s.status===`error`,seeding:s.status===`connecting`&&!!s.value,settled:!!s.value||!!l}}var G=/* @__PURE__ */ e(r(),1);const K=m({integrations:d(l(),h()),connections:d(l(),h())});function he(e,t){let n,r=async()=>{try{return new Set(F.parse(await e(P,[])))}catch(e){if(_(e)===`NOT_A_METHOD`)return/* @__PURE__ */ new Set;throw n=void 0,e}};return{call:e,controlPlane:t,offered:()=>n||=r()}}function ge({openRegistry:e,deps:t,seed:n,callConfig:r,mind:i}){let a=(0,w.useMemo)(()=>r?he(r,i||``):void 0,[r,i]),o=me(e,t,`integration`,n,K);return/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-8 p-4 md:p-8`,children:[/* @__PURE__ */ (0,G.jsxs)(`header`,{className:`flex flex-col gap-1.5`,children:[/* @__PURE__ */ (0,G.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold tracking-tight`,children:[`Integrations`,o.seeding?/* @__PURE__ */ (0,G.jsx)(x,{}):null]}),/* @__PURE__ */ (0,G.jsx)(`p`,{className:`max-w-prose text-sm text-muted-foreground`,children:`To connect an account or a service, ask your agent: "connect my Gmail", "set up a Telegram bot". What it connects shows here.`})]}),o.error?/* @__PURE__ */ (0,G.jsxs)(`p`,{role:`alert`,"data-type":`error`,className:`text-sm text-destructive`,children:[`Couldn't load this mind's integrations: `,o.error]}):null,o.settled?null:/* @__PURE__ */ (0,G.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading…`}),o.state?/* @__PURE__ */ (0,G.jsx)(q,{registry:o.state,caller:a}):null]})}function q({registry:e,caller:t}){let n=Object.entries(e.integrations).flatMap(([e,t])=>{let n=U.safeParse(t).data;return n?[{integration:e,card:n}]:[]}),r=Object.entries(e.connections).flatMap(([e,t])=>{let n=W.safeParse(t).data,r=e.indexOf(`/`);return n?[{integration:e.slice(0,r),connection:e.slice(r+1),row:n}]:[]});if(n.length===0)return/* @__PURE__ */ (0,G.jsx)(_e,{});n.sort((e,t)=>e.card.title.localeCompare(t.card.title));let i=n.flatMap(e=>{let t=n.filter(({card:t})=>t.section===e.integration);return t.length?[{section:e.integration,heading:e.card,entry:e,cards:t}]:[]}).sort((e,t)=>e.heading.title.localeCompare(t.heading.title)),a=new Set(i.flatMap(e=>[e.entry,...e.cards])),o=n.filter(e=>!a.has(e)),s=e=>e.map(({integration:e,card:n})=>/* @__PURE__ */ (0,G.jsx)(J,{integration:e,card:n,rows:r.filter(t=>t.integration===e),caller:t},e)),c=e=>/* @__PURE__ */ (0,G.jsx)(`div`,{className:`divide-y overflow-hidden rounded-lg border bg-card`,children:s(e)});return/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[i.map(({section:e,heading:t,cards:n})=>/* @__PURE__ */ (0,G.jsxs)(`section`,{"aria-labelledby":`integrations-section-${e}`,className:`flex flex-col gap-3`,children:[/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.icon?/* @__PURE__ */ (0,G.jsx)(Y,{title:t.title,icon:t.icon,small:!0}):null,/* @__PURE__ */ (0,G.jsx)(`h2`,{id:`integrations-section-${e}`,className:`text-base font-semibold tracking-tight`,children:t.title})]}),t.description&&/* @__PURE__ */ (0,G.jsx)(`p`,{className:`max-w-prose text-sm text-muted-foreground`,children:t.description})]}),c(n)]},e)),o.length?/* @__PURE__ */ (0,G.jsxs)(`section`,{"aria-label":`This mind's own integrations`,className:`flex flex-col gap-3`,children:[i.length?/* @__PURE__ */ (0,G.jsx)(`h2`,{className:`text-base font-semibold tracking-tight`,children:`This mind's own`}):null,c(o)]}):null]})}function _e(){return/* @__PURE__ */ (0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Nothing is connected yet.`})}function J({integration:e,card:t,rows:n,caller:r}){let i=`integration-${e}-heading`,a=n.flatMap(({row:e})=>e.status?[e.status.kind]:[]).toSorted((e,t)=>Q[t]-Q[e])[0],o=a&&Q[a]>Q[t.status?.kind||`ok`]?{kind:a}:t.status;return/* @__PURE__ */ (0,G.jsxs)(`section`,{"aria-labelledby":i,className:`flex min-w-0 flex-col`,children:[/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 px-4 py-3.5 sm:flex-row sm:items-start`,children:[/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 gap-3`,children:[/* @__PURE__ */ (0,G.jsx)(Y,{title:t.title,icon:t.icon}),/* @__PURE__ */ (0,G.jsxs)(`div`,{className:y(`flex min-w-0 flex-1 flex-col gap-0.5`,!t.description&&!o&&`self-center`),children:[/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2.5 gap-y-0.5`,children:[/* @__PURE__ */ (0,G.jsx)(`h3`,{id:i,className:`text-sm font-semibold [overflow-wrap:anywhere]`,children:t.title}),o?/* @__PURE__ */ (0,G.jsx)($,{status:o}):null]}),t.description&&/* @__PURE__ */ (0,G.jsx)(`p`,{className:`max-w-prose text-xs/5 text-muted-foreground`,children:t.description})]})]}),/* @__PURE__ */ (0,G.jsx)(xe,{actions:t.actions,caller:r,first:n.length===0&&!t.status?`default`:`secondary`,className:`shrink-0 pl-11 sm:pl-0`})]}),n.length===0?null:/* @__PURE__ */ (0,G.jsx)(`ul`,{className:`mr-4 mb-1 ml-15 flex flex-col divide-y border-t`,"aria-label":`${t.title} connections`,children:n.map(({connection:e,row:t})=>/* @__PURE__ */ (0,G.jsx)(X,{row:t,caller:r},e))})]})}function Y({title:e,icon:t,small:n}){let r=n?`size-5 rounded`:`size-8 rounded-md`;return t?/* @__PURE__ */ (0,G.jsx)(`img`,{src:t,alt:``,className:y(`shrink-0 object-contain`,r)}):/* @__PURE__ */ (0,G.jsx)(`span`,{"aria-hidden":`true`,className:y(`flex shrink-0 items-center justify-center border bg-muted text-xs font-semibold text-muted-foreground uppercase`,r),children:e.slice(0,1)})}function X({row:e,caller:t}){return/* @__PURE__ */ (0,G.jsxs)(`li`,{className:`flex flex-col gap-2 py-2.5 sm:flex-row sm:items-start sm:gap-3`,children:[/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[e.status?/* @__PURE__ */ (0,G.jsx)(ve,{status:e.status,className:`mt-1.5`}):/* @__PURE__ */ (0,G.jsx)(`span`,{className:`size-2 shrink-0`}),/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[/* @__PURE__ */ (0,G.jsx)(`p`,{className:`truncate text-sm font-medium`,title:e.account,children:e.account}),e.status&&(e.status.kind!==`ok`||e.status.text)?/* @__PURE__ */ (0,G.jsx)(ye,{status:e.status}):null,e.details&&/* @__PURE__ */ (0,G.jsx)(`dl`,{className:`flex flex-wrap gap-x-4 gap-y-0.5 text-xs text-muted-foreground`,children:Object.entries(e.details).map(([e,t])=>/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`min-w-0 [overflow-wrap:anywhere]`,children:[/* @__PURE__ */ (0,G.jsxs)(`dt`,{className:`inline`,children:[e,` `]}),/* @__PURE__ */ (0,G.jsx)(`dd`,{className:`inline text-foreground/80`,children:t})]},e))})]})]}),/* @__PURE__ */ (0,G.jsx)(xe,{actions:e.actions,caller:t,className:`shrink-0 pl-4.5 sm:pl-0`})]})}const Z={ok:`OK`,attention:`Needs attention`,error:`Failed`},Q={ok:0,attention:1,error:2};function ve({status:e,className:t}){return/* @__PURE__ */ (0,G.jsx)(`span`,{role:`img`,"aria-label":Z[e.kind],className:y(`size-2 shrink-0 rounded-full`,{ok:`bg-success`,attention:`bg-warning`,error:`bg-destructive`}[e.kind],t)})}function ye({status:e}){return/* @__PURE__ */ (0,G.jsx)(`p`,{"data-type":e.kind===`error`?`error`:void 0,className:y(`text-xs [overflow-wrap:anywhere]`,e.kind===`ok`&&`text-muted-foreground`,e.kind===`attention`&&`text-warning`,e.kind===`error`&&`text-destructive`),children:e.text||Z[e.kind]})}function $({status:e}){return/* @__PURE__ */ (0,G.jsxs)(`div`,{className:`flex max-w-full items-center gap-1.5`,children:[/* @__PURE__ */ (0,G.jsx)(ve,{status:e}),/* @__PURE__ */ (0,G.jsx)(ye,{status:e})]})}const be=()=>()=>{};function xe({actions:e,caller:t,first:n=`secondary`,className:r}){let i=(0,w.useSyncExternalStore)(be,()=>window.location.origin,()=>``),a=/* @__PURE__ */ new Map;for(let t of e){if(`call`in t){let{label:e,call:n,confirm:r}=t;a.set(`${e}\ncall ${n.name} ${JSON.stringify(n.args||[])}`,{label:e,call:n,confirm:r});continue}let e=new URL(t.url).origin!==i;t.confirm&&e||a.set(`${t.label}\n${t.url}`,{label:t.label,href:t.url,beside:e,confirm:t.confirm})}let[o,s]=(0,w.useState)(null);return a.size===0?null:/* @__PURE__ */ (0,G.jsxs)(`div`,{className:y(`flex flex-col items-start gap-1 sm:items-end`,r),children:[/* @__PURE__ */ (0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[...a].map(([e,r],i)=>{let a=i===0&&!r.confirm?n:`secondary`;if(`call`in r)return/* @__PURE__ */ (0,G.jsx)(Ee,{label:r.label,call:r.call,question:r.confirm,variant:a,caller:t,report:s},e);let{label:o,href:c,beside:l,confirm:u}=r;return u?/* @__PURE__ */ (0,G.jsx)(Se,{label:o,url:c,question:u,report:s},e):/* @__PURE__ */ (0,G.jsxs)(`a`,{href:c,...l&&{target:`_blank`,rel:`noreferrer`},className:re({variant:a,size:`sm`}),children:[o,l?/* @__PURE__ */ (0,G.jsx)(ne,{"data-icon":`inline-end`}):/* @__PURE__ */ (0,G.jsx)(v,{"data-icon":`inline-end`})]},e)})}),o?/* @__PURE__ */ (0,G.jsx)(we,{outcome:o}):null]})}function Se({label:e,url:t,question:n,report:r}){let[i,a]=(0,w.useState)(!1),o=async()=>{a(!0),r(null);try{let n=await fetch(t,{method:`POST`});n.ok||r({error:await n.text()||`${e} failed (${n.status}).`})}catch(e){r({error:Te(e)})}finally{a(!1)}};return/* @__PURE__ */ (0,G.jsx)(Ce,{label:e,question:n,busy:i,onYes:()=>void o()})}function Ce({label:e,question:t,busy:n,onYes:r}){let i=t.indexOf(`? `),a=i>0?t.slice(0,i+1):`${e}?`,o=i>0?t.slice(i+2):t,[s,c]=(0,w.useState)(!1);return/* @__PURE__ */ (0,G.jsxs)(S,{open:s,onOpenChange:c,children:[/* @__PURE__ */ (0,G.jsx)(ue,{render:/* @__PURE__ */ (0,G.jsx)(b,{variant:`secondary`,size:`sm`}),disabled:!!n,"aria-busy":!!n||void 0,children:n?typeof n==`string`?n:`${e}…`:e}),/* @__PURE__ */ (0,G.jsxs)(ae,{children:[/* @__PURE__ */ (0,G.jsxs)(ce,{children:[/* @__PURE__ */ (0,G.jsx)(le,{children:a}),/* @__PURE__ */ (0,G.jsx)(oe,{children:o})]}),/* @__PURE__ */ (0,G.jsxs)(se,{children:[/* @__PURE__ */ (0,G.jsx)(ie,{children:`Cancel`}),/* @__PURE__ */ (0,G.jsx)(C,{onClick:()=>{c(!1),r()},children:e})]})]})]})}function we({outcome:e}){return`error`in e?/* @__PURE__ */ (0,G.jsx)(`p`,{role:`alert`,"data-type":`error`,className:`max-w-xs text-xs text-destructive sm:text-right`,children:e.error}):/* @__PURE__ */ (0,G.jsx)(`p`,{role:`status`,className:`max-w-xs text-xs text-muted-foreground sm:text-right`,children:e.said})}const Te=e=>e instanceof Error?e.message:String(e);function Ee({label:e,call:t,question:n,variant:r,caller:i,report:a}){let[o,s]=(0,w.useState)(!1),[c,l]=(0,w.useState)(!1),u=(0,w.useId)(),d=(0,w.useRef)(!1),f=(0,w.useRef)(!0);if((0,w.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]),(0,w.useEffect)(()=>{let e=e=>{e.persisted&&(d.current=!1,s(!1))};return window.addEventListener(`pageshow`,e),()=>window.removeEventListener(`pageshow`,e)},[]),!i){let t=`This page cannot call the mind's config: its host gave it no way to.`;return/* @__PURE__ */ (0,G.jsx)(`span`,{title:t,className:`inline-flex`,children:/* @__PURE__ */ (0,G.jsx)(b,{variant:r,size:`sm`,disabled:!0,title:t,children:e})})}let p=async()=>{if(d.current)return;d.current=!0,s(`${e}…`),a(null);let n=!1;try{let e=await i.offered();if(!e.has(t.name)){a({error:e.size?`This button calls ${t.name}, which this mind's config does not offer to buttons.`:`This mind's config offers no function to buttons, so this button calls nothing.`});return}let r=await i.call(t.name,t.args||[]),o=B.safeParse(r).data?.said,c=V(r,i.controlPlane);if(c&&`follow`in c){if(!f.current)return;n=!0,s(`Opening ${c.follow.hostname}…`),window.location.assign(c.follow.href);return}c?a({error:`This button's call answered ${c.refused}: the page does not follow it.`}):o&&a({said:o})}catch(e){a({error:`This button's call failed: ${Te(e)}`.slice(0,400)})}finally{n||(d.current=!1,s(!1))}},m=R(t),h=/* @__PURE__ */ (0,G.jsxs)(G.Fragment,{children:[o||e,o?/* @__PURE__ */ (0,G.jsx)(x,{"data-icon":`inline-end`}):null]}),g=/* @__PURE__ */ (0,G.jsx)(`span`,{id:u,className:`sr-only`,children:m}),_={disabled:!!o,"aria-busy":!!o||void 0,"aria-describedby":u,title:m};return n?/* @__PURE__ */ (0,G.jsxs)(S,{open:c,onOpenChange:l,children:[/* @__PURE__ */ (0,G.jsx)(ue,{render:/* @__PURE__ */ (0,G.jsx)(b,{variant:r,size:`sm`}),..._,children:h}),g,/* @__PURE__ */ (0,G.jsxs)(ae,{children:[/* @__PURE__ */ (0,G.jsxs)(ce,{children:[/* @__PURE__ */ (0,G.jsx)(le,{children:`Call this mind's config?`}),/* @__PURE__ */ (0,G.jsxs)(oe,{render:/* @__PURE__ */ (0,G.jsx)(`div`,{}),className:`flex w-full min-w-0 flex-col gap-3 text-left`,children:[/* @__PURE__ */ (0,G.jsxs)(`figure`,{className:`flex flex-col gap-1 border-l-2 border-border pl-3`,children:[/* @__PURE__ */ (0,G.jsx)(`figcaption`,{className:`text-xs`,children:`The card says:`}),/* @__PURE__ */ (0,G.jsx)(`blockquote`,{className:`text-foreground [overflow-wrap:anywhere]`,children:n})]}),/* @__PURE__ */ (0,G.jsx)(`p`,{children:`This button calls`}),/* @__PURE__ */ (0,G.jsx)(`pre`,{dir:`ltr`,"data-slot":`call-text`,className:`max-h-48 w-full overflow-auto rounded-md bg-muted p-2 text-left font-mono text-xs whitespace-pre-wrap text-foreground [overflow-wrap:anywhere] [unicode-bidi:isolate]`,children:/* @__PURE__ */ (0,G.jsx)(`bdi`,{dir:`ltr`,children:m})}),/* @__PURE__ */ (0,G.jsx)(`p`,{children:`in this mind's config, as you.`})]})]}),/* @__PURE__ */ (0,G.jsxs)(se,{children:[/* @__PURE__ */ (0,G.jsx)(ie,{children:`Cancel`}),/* @__PURE__ */ (0,G.jsx)(C,{onClick:()=>{l(!1),p()},children:e})]})]})]}):/* @__PURE__ */ (0,G.jsxs)(G.Fragment,{children:[/* @__PURE__ */ (0,G.jsx)(b,{variant:r,size:`sm`,..._,onClick:()=>void p(),children:h}),g]})}export{ge as IntegrationsPage};
M dist/components/repo-ide/repo-ide.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/live.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"./chunks/dist.mjs";import{ITX_SESSION as t,itxSessionOf as n}from"./lib/itx-session";import{savedLogTails as r,wipeSavedLogTails as i}from"./lib/saved-log-tail";import{a}from"./chunks/lib.mjs";import{i as o,n as s,o as c,r as l,t as u}from"./chunks/react.mjs";import{useSavedContext as d}from"./lib/saved-context";import{i as f,n as p,r as m,t as h}from"./chunks/use-itx-session.mjs";import{t as g}from"./chunks/usingCtx.mjs";const _=[0,250,500,1e3,2e3,4e3,8e3],v=1e4,y={intervalMs:3e4,deadAfterMs:15e3},b=2e3,x=1008,S=`__itxSocket`;function C(e=document.getElementById(`root`)){let t=window,n=t[S];return delete t[S],w({root:e,early:n instanceof WebSocket?n:void 0})}function w({root:n,url:r=new URL(`/itx`,location.href.replace(/^http/,`ws`)),WebSocket:a=WebSocket,early:o,fetch:s=(e,t)=>fetch(e,t),reload:c=()=>location.reload()}){let l={epoch:0,state:`opening`},u=/* @__PURE__ */ new Set,d=/* @__PURE__ */ new Set,f=e=>{l=e;for(let e of[...u,...d])e()},p={get:()=>l,subscribe(e){return u.add(e),()=>u.delete(e)},watch(e){return d.add(e),()=>d.delete(e)}},m=()=>u.size===0,h=e=>{D(sessionStorage,Date.now())?c():n&&(n.textContent=e)},g,y=!1,S=!1,C=()=>{S=!0,clearTimeout(O),g.dial.socket.close(),i().then(()=>h(`Your sign-in ended. Reload the page to sign in.`))},w=async()=>{let e=await s(new URL(r.href.replace(/^ws/,`http`)),{cache:`no-store`,signal:AbortSignal.timeout(v)}).catch(()=>void 0);await e?.body?.cancel(),e?.status===401&&!S&&C()},O,k=()=>{f({epoch:l.epoch,state:`opening`}),O=setTimeout(()=>f({epoch:l.epoch,state:`reconnecting`}),b)},A=(t,i)=>{let o=T(r,t,a,i),s=e(o.socket),c={stub:s,dial:o};g=c;let u=!1,d,p=()=>{if(!(u||o.socket.readyState!==a.OPEN)){if(u=!0,clearTimeout(d),clearTimeout(O),y&&m())return h(`Disconnected. Reload the page to connect.`);f({epoch:l.epoch,state:`open`})}};Promise.resolve(s.whoami()).then(p,()=>{}),o.socket.addEventListener(`open`,()=>{d=setTimeout(p,5e3),c.heartbeat=E(()=>s.whoami(),()=>o.socket.close()),f({epoch:l.epoch+1,state:l.state})}),o.socket.addEventListener(`close`,e=>{if(c.heartbeat?.stop(),clearTimeout(d),y=!0,S)return;if(e.code===x)return C();if(u)return k(),A(_);let r=t.slice(o.dials());if(r.length)return A(r);w(),clearTimeout(O),m()&&n&&(n.textContent=`Cannot reach the mind. Trying again…`),l.state!==`unreachable`&&f({epoch:l.epoch,state:`unreachable`}),A([15e3])})};O=setTimeout(()=>f({epoch:l.epoch,state:`reconnecting`}),b),A(_,o);let j=()=>{g.heartbeat?.beatNow(),g.dial.hurry()};return addEventListener(`online`,j),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&j()}),new Proxy({},{get:(e,n)=>n===t?p:Reflect.get(g.stub,n)})}function T(e,t,n,r){let i=new EventTarget,a=n.CONNECTING,o,s=0,c,l,u=(e,t=``)=>{if(a===n.CLOSED)return;a=n.CLOSED,clearTimeout(c),c=void 0,clearTimeout(l);let r=o;o=void 0,r?.close(),i.dispatchEvent(new CloseEvent(`close`,{code:e,reason:t}))},d=(t=new n(e))=>{c=void 0,t.binaryType=`arraybuffer`,o=t,l=setTimeout(()=>t.close(),v);let r=()=>{o===t&&a===n.CONNECTING&&(clearTimeout(l),a=n.OPEN,i.dispatchEvent(new Event(`open`)))};t.addEventListener(`open`,r),t.readyState===n.OPEN&&queueMicrotask(r),t.addEventListener(`message`,e=>{o===t&&i.dispatchEvent(new MessageEvent(`message`,{data:e.data}))}),t.addEventListener(`close`,e=>{if(o===t){if(clearTimeout(l),a===n.OPEN||e.code===x)return u(e.code,e.reason);o=void 0,f()}})},f=()=>{let e=t[s++];if(e===void 0)return u(1006);e?c=setTimeout(d,e):d()};return r&&(r.readyState===n.CONNECTING||r.readyState===n.OPEN)?(s=1,d(r)):f(),Object.defineProperty(i,"readyState",{get:()=>a}),{socket:Object.assign(i,{binaryType:`arraybuffer`,send:e=>o?.send(e),close:(e,t)=>u(e??1006,t)}),hurry(){c&&(clearTimeout(c),d())},dials:()=>s}}function E(e,t){let n,r=()=>{clearTimeout(n),n=void 0},i=()=>{n||(n=setTimeout(t,y.deadAfterMs),Promise.resolve(e()).then(r,r))},a=setInterval(i,y.intervalMs);return{beatNow:i,stop(){clearInterval(a),clearTimeout(n)}}}function D(e,t){let n=[];try{let r=JSON.parse(e.getItem(`itx-reloads`)||`[]`);n=(Array.isArray(r)?r:[]).filter(e=>typeof e==`number`&&t-e<6e4),e.setItem(`itx-reloads`,JSON.stringify([...n,t]))}catch{}return n.length<3}function O(e,t){try{var n=g();return n.u(e.authenticate(t)).mind.dup()}catch(e){n.e=e}finally{n.d()}}const k={intervalMs:3e4,deadAfterMs:15e3};function A(e){let t=e.timing||k,n=!1,r,i=()=>{n||r||(r=setTimeout(()=>{o(),e.onDead(`no answer to a heartbeat for ${t.deadAfterMs/1e3} s`)},t.deadAfterMs),j(r),Promise.resolve(e.beat()).catch(()=>{}).then(()=>{clearTimeout(r),r=void 0}))},a=setInterval(i,t.intervalMs);j(a);function o(){n=!0,clearInterval(a),clearTimeout(r)}return{beatNow:i,stop:o}}function j(e){e.unref?.()}const M=[250,500,1e3,2e3,4e3,8e3];function N(e,t={}){let n=t.delaysMs||M,r=t.handshakeTimeoutMs??1e4,i=t.WebSocket||WebSocket,a=t.sleep||(e=>new Promise(t=>setTimeout(t,e))),o=()=>new Promise((t,n)=>{let a=new i(e),o=``,s=setTimeout(()=>{c(),a.close(),n(/* @__PURE__ */ Error(`WebSocket did not open in ${r} ms`))},r);function c(){clearTimeout(s),a.removeEventListener(`open`,u),a.removeEventListener(`close`,d),a.removeEventListener(`error`,l)}function l(e){let t=e.error;t instanceof Error&&(o=` (${t.message})`)}function u(){c(),t(a)}function d(e){c(),n(/* @__PURE__ */ Error(`WebSocket connection failed: closed ${e.code}${e.reason?` "${e.reason}"`:``} before it opened${o}`))}a.addEventListener(`open`,u,{once:!0}),a.addEventListener(`error`,l),a.addEventListener(`close`,d,{once:!0})});return(async()=>{for(let t=1;;t++)try{return await o()}catch(r){let i=n[t-1];if(i===void 0)throw r;console.warn({event:`client.platform-failure-socket-open`,url:String(e),attempt:t,attempts:n.length+1,retryInMs:i,message:r.message}),await a(i)}})()}function P(e){let t=new EventTarget,n,r=WebSocket.CONNECTING,i;return e.then(e=>{if(i){e.close(...i),r=WebSocket.CLOSED,t.dispatchEvent(new CloseEvent(`close`,{code:i[0]??1e3}));return}if(e.readyState!==WebSocket.OPEN){r=WebSocket.CLOSED,t.dispatchEvent(new CloseEvent(`close`,{code:1006}));return}n=e,e.binaryType=`arraybuffer`,e.addEventListener(`message`,e=>t.dispatchEvent(new MessageEvent(`message`,{data:e.data}))),e.addEventListener(`error`,()=>t.dispatchEvent(new Event(`error`))),e.addEventListener(`close`,e=>{r=WebSocket.CLOSED,t.dispatchEvent(new CloseEvent(`close`,{code:e.code,reason:e.reason}))}),r=WebSocket.OPEN,t.dispatchEvent(new Event(`open`))},()=>{r=WebSocket.CLOSED,t.dispatchEvent(new Event(`error`)),t.dispatchEvent(new CloseEvent(`close`,{code:1006}))}),Object.defineProperty(t,"readyState",{get:()=>r}),Object.assign(t,{binaryType:`arraybuffer`,send(e){if(!n)throw Error(`The WebSocket is not open yet.`);n.send(e)},close(e,t){if(n)return n.close(e,t);i=[e,t],r=WebSocket.CLOSING}})}function F(e){return window.location.assign(e),new Promise(()=>{})}const I=`iterate:left-for-sign-in`;function L(e,t){try{return t&&window.sessionStorage.setItem(e,t),window.sessionStorage.getItem(e)}catch{return null}}function R(t){let{mind:n}=t,r=null,i,o=e=>`/.auth/login?${new URLSearchParams({mind:n,next:e})}`,s=()=>{let e=new URL(`/api`,window.location.href);return e.searchParams.set(`mind`,n),e},c=()=>{let e=s();return e.protocol=e.protocol===`https:`?`wss:`:`ws:`,e};function l(t){let s=e(t),c={itx:O(s),socket:t,dispose:p};r=c,Promise.resolve(c.itx.whoami()).catch(e=>{if(a(e)!==`UNAUTHENTICATED`||r!==c)return;let t=Number(L(I));Date.now()-t<6e4||(L(I,String(Date.now())),F(o(window.location.href)))});let l,u=()=>l?.beatNow(),d=()=>document.visibilityState===`visible`&&u(),f=()=>{l?.stop(),window.removeEventListener(`pagehide`,p),window.removeEventListener(`online`,u),document.removeEventListener(`visibilitychange`,d),r===c&&(r=null,i=void 0)};function p(){f(),c.itx[Symbol.dispose](),s[Symbol.dispose]()}return t.addEventListener(`open`,()=>{l=A({beat:()=>c.itx.whoami(),onDead:e=>{console.warn(`The connection to ${n} is dead (${e}). Reconnecting.`),p()}})},{once:!0}),t.addEventListener(`close`,f,{once:!0}),window.addEventListener(`pagehide`,p,{once:!0}),window.addEventListener(`online`,u),document.addEventListener(`visibilitychange`,d),c}let u=new Proxy({},{get(e,t){if(t===Symbol.dispose)return()=>r?.dispose();let n=r||l(new WebSocket(c()));return Reflect.get(n.itx,t)}});async function d(e){let t=r?void 0:N(c()),i=()=>void t?.then(e=>e.close(),()=>{}),a=await fetch(s(),{method:`POST`,body:``,signal:AbortSignal.timeout(1e4)}).catch(e=>{throw i(),e});if(await a.body?.cancel(),a.ok||i(),a.status===401)return F(o(e));if(!a.ok)throw Error(`${n} is unavailable (${a.status}). Please retry.`);return t&&!r?l(P(t)):i(),{itx:u,read:async e=>await e(u)}}return{authenticate(e=`/`){return i||=d(e).catch(e=>{throw i=void 0,e}),i}}}export{c as connectEventLog,R as createIterateClient,u as facetSnapshotOf,n as itxSessionOf,C as memberItx,e as newWebSocketRpcSession,r as savedLogTails,s as useContextStub,l as useFacetLiveState,h as useHeldContext,o as useIterateContext,p as useItxConnection,m as useKept,f as useKeptContext,d as useSavedContext,i as wipeSavedLogTails}; +import{r as e}from"./chunks/dist.mjs";import{ITX_SESSION as t,itxSessionOf as n}from"./lib/itx-session";import{savedLogTails as r,wipeSavedLogTails as i}from"./lib/saved-log-tail";import{a}from"./chunks/lib.mjs";import{a as o,i as s,n as c,r as l,t as u}from"./chunks/react.mjs";import{useSavedContext as d}from"./lib/saved-context";import{i as f,n as p,r as m,t as h}from"./chunks/use-itx-session.mjs";const g=[0,250,500,1e3,2e3,4e3,8e3],_=1e4,v={intervalMs:3e4,deadAfterMs:15e3},y=2e3,b=1008,x=`__itxSocket`;function S(e=document.getElementById(`root`)){let t=window,n=t[x];return delete t[x],C({root:e,early:n instanceof WebSocket?n:void 0})}function C({root:n,url:r=new URL(`/itx`,location.href.replace(/^http/,`ws`)),WebSocket:a=WebSocket,early:o,fetch:s=(e,t)=>fetch(e,t),reload:c=()=>location.reload()}){let l={epoch:0,state:`opening`},u=/* @__PURE__ */ new Set,d=/* @__PURE__ */ new Set,f=e=>{l=e;for(let e of[...u,...d])e()},p={get:()=>l,subscribe(e){return u.add(e),()=>u.delete(e)},watch(e){return d.add(e),()=>d.delete(e)}},m=()=>u.size===0,h=e=>{E(sessionStorage,Date.now())?c():n&&(n.textContent=e)},v,x=!1,S=!1,C=()=>{S=!0,clearTimeout(O),v.dial.socket.close(),i().then(()=>h(`Your sign-in ended. Reload the page to sign in.`))},D=async()=>{let e=await s(new URL(r.href.replace(/^ws/,`http`)),{cache:`no-store`,signal:AbortSignal.timeout(_)}).catch(()=>void 0);await e?.body?.cancel(),e?.status===401&&!S&&C()},O,k=()=>{f({epoch:l.epoch,state:`opening`}),O=setTimeout(()=>f({epoch:l.epoch,state:`reconnecting`}),y)},A=(t,i)=>{let o=w(r,t,a,i),s=e(o.socket),c={stub:s,dial:o};v=c;let u=!1,d,p=()=>{if(!(u||o.socket.readyState!==a.OPEN)){if(u=!0,clearTimeout(d),clearTimeout(O),x&&m())return h(`Disconnected. Reload the page to connect.`);f({epoch:l.epoch,state:`open`})}};Promise.resolve(s.whoami()).then(p,()=>{}),o.socket.addEventListener(`open`,()=>{d=setTimeout(p,5e3),c.heartbeat=T(()=>s.whoami(),()=>o.socket.close()),f({epoch:l.epoch+1,state:l.state})}),o.socket.addEventListener(`close`,e=>{if(c.heartbeat?.stop(),clearTimeout(d),x=!0,S)return;if(e.code===b)return C();if(u)return k(),A(g);let r=t.slice(o.dials());if(r.length)return A(r);D(),clearTimeout(O),m()&&n&&(n.textContent=`Cannot reach the mind. Trying again…`),l.state!==`unreachable`&&f({epoch:l.epoch,state:`unreachable`}),A([15e3])})};O=setTimeout(()=>f({epoch:l.epoch,state:`reconnecting`}),y),A(g,o);let j=()=>{v.heartbeat?.beatNow(),v.dial.hurry()};return addEventListener(`online`,j),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&j()}),new Proxy({},{get:(e,n)=>n===t?p:Reflect.get(v.stub,n)})}function w(e,t,n,r){let i=new EventTarget,a=n.CONNECTING,o,s=0,c,l,u=(e,t=``)=>{if(a===n.CLOSED)return;a=n.CLOSED,clearTimeout(c),c=void 0,clearTimeout(l);let r=o;o=void 0,r?.close(),i.dispatchEvent(new CloseEvent(`close`,{code:e,reason:t}))},d=(t=new n(e))=>{c=void 0,t.binaryType=`arraybuffer`,o=t,l=setTimeout(()=>t.close(),_);let r=()=>{o===t&&a===n.CONNECTING&&(clearTimeout(l),a=n.OPEN,i.dispatchEvent(new Event(`open`)))};t.addEventListener(`open`,r),t.readyState===n.OPEN&&queueMicrotask(r),t.addEventListener(`message`,e=>{o===t&&i.dispatchEvent(new MessageEvent(`message`,{data:e.data}))}),t.addEventListener(`close`,e=>{if(o===t){if(clearTimeout(l),a===n.OPEN||e.code===b)return u(e.code,e.reason);o=void 0,f()}})},f=()=>{let e=t[s++];if(e===void 0)return u(1006);e?c=setTimeout(d,e):d()};return r&&(r.readyState===n.CONNECTING||r.readyState===n.OPEN)?(s=1,d(r)):f(),Object.defineProperty(i,"readyState",{get:()=>a}),{socket:Object.assign(i,{binaryType:`arraybuffer`,send:e=>o?.send(e),close:(e,t)=>u(e??1006,t)}),hurry(){c&&(clearTimeout(c),d())},dials:()=>s}}function T(e,t){let n,r=()=>{clearTimeout(n),n=void 0},i=()=>{n||(n=setTimeout(t,v.deadAfterMs),Promise.resolve(e()).then(r,r))},a=setInterval(i,v.intervalMs);return{beatNow:i,stop(){clearInterval(a),clearTimeout(n)}}}function E(e,t){let n=[];try{let r=JSON.parse(e.getItem(`itx-reloads`)||`[]`);n=(Array.isArray(r)?r:[]).filter(e=>typeof e==`number`&&t-e<6e4),e.setItem(`itx-reloads`,JSON.stringify([...n,t]))}catch{}return n.length<3}function D(){var e=typeof SuppressedError==`function`?SuppressedError:function(e,t){var n=Error();return n.name=`SuppressedError`,n.error=e,n.suppressed=t,n},t={},n=[];function r(e,t){if(t!=null){if(Object(t)!==t)throw TypeError(`using declarations can only be used with objects, functions, null, or undefined.`);if(e)var r=t[Symbol.asyncDispose||Symbol.for(`Symbol.asyncDispose`)];if(r===void 0&&(r=t[Symbol.dispose||Symbol.for(`Symbol.dispose`)],e))var i=r;if(typeof r!=`function`)throw TypeError(`Object is not disposable.`);i&&(r=function(){try{i.call(t)}catch(e){return Promise.reject(e)}}),n.push({v:t,d:r,a:e})}else e&&n.push({d:t,a:e});return t}return{e:t,u:r.bind(null,!1),a:r.bind(null,!0),d:function(){var r,i=this.e,a=0;function o(){for(;r=n.pop();)try{if(!r.a&&a===1)return a=0,n.push(r),Promise.resolve().then(o);if(r.d){var e=r.d.call(r.v);if(r.a)return a|=2,Promise.resolve(e).then(o,s)}else a|=1}catch(e){return s(e)}if(a===1)return i===t?Promise.resolve():Promise.reject(i);if(i!==t)throw i}function s(n){return i=i===t?n:new e(n,i),o()}return o()}}}function O(e,t){try{var n=D();return n.u(e.authenticate(t)).mind.dup()}catch(e){n.e=e}finally{n.d()}}const k={intervalMs:3e4,deadAfterMs:15e3};function A(e){let t=e.timing||k,n=!1,r,i=()=>{n||r||(r=setTimeout(()=>{o(),e.onDead(`no answer to a heartbeat for ${t.deadAfterMs/1e3} s`)},t.deadAfterMs),j(r),Promise.resolve(e.beat()).catch(()=>{}).then(()=>{clearTimeout(r),r=void 0}))},a=setInterval(i,t.intervalMs);j(a);function o(){n=!0,clearInterval(a),clearTimeout(r)}return{beatNow:i,stop:o}}function j(e){e.unref?.()}const M=[250,500,1e3,2e3,4e3,8e3];function N(e,t={}){let n=t.delaysMs||M,r=t.handshakeTimeoutMs??1e4,i=t.WebSocket||WebSocket,a=t.sleep||(e=>new Promise(t=>setTimeout(t,e))),o=()=>new Promise((t,n)=>{let a=new i(e),o=``,s=setTimeout(()=>{c(),a.close(),n(/* @__PURE__ */ Error(`WebSocket did not open in ${r} ms`))},r);function c(){clearTimeout(s),a.removeEventListener(`open`,u),a.removeEventListener(`close`,d),a.removeEventListener(`error`,l)}function l(e){let t=e.error;t instanceof Error&&(o=` (${t.message})`)}function u(){c(),t(a)}function d(e){c(),n(/* @__PURE__ */ Error(`WebSocket connection failed: closed ${e.code}${e.reason?` "${e.reason}"`:``} before it opened${o}`))}a.addEventListener(`open`,u,{once:!0}),a.addEventListener(`error`,l),a.addEventListener(`close`,d,{once:!0})});return(async()=>{for(let t=1;;t++)try{return await o()}catch(r){let i=n[t-1];if(i===void 0)throw r;console.warn({event:`client.platform-failure-socket-open`,url:String(e),attempt:t,attempts:n.length+1,retryInMs:i,message:r.message}),await a(i)}})()}function P(e){let t=new EventTarget,n,r=WebSocket.CONNECTING,i;return e.then(e=>{if(i){e.close(...i),r=WebSocket.CLOSED,t.dispatchEvent(new CloseEvent(`close`,{code:i[0]??1e3}));return}if(e.readyState!==WebSocket.OPEN){r=WebSocket.CLOSED,t.dispatchEvent(new CloseEvent(`close`,{code:1006}));return}n=e,e.binaryType=`arraybuffer`,e.addEventListener(`message`,e=>t.dispatchEvent(new MessageEvent(`message`,{data:e.data}))),e.addEventListener(`error`,()=>t.dispatchEvent(new Event(`error`))),e.addEventListener(`close`,e=>{r=WebSocket.CLOSED,t.dispatchEvent(new CloseEvent(`close`,{code:e.code,reason:e.reason}))}),r=WebSocket.OPEN,t.dispatchEvent(new Event(`open`))},()=>{r=WebSocket.CLOSED,t.dispatchEvent(new Event(`error`)),t.dispatchEvent(new CloseEvent(`close`,{code:1006}))}),Object.defineProperty(t,"readyState",{get:()=>r}),Object.assign(t,{binaryType:`arraybuffer`,send(e){if(!n)throw Error(`The WebSocket is not open yet.`);n.send(e)},close(e,t){if(n)return n.close(e,t);i=[e,t],r=WebSocket.CLOSING}})}function F(e){return window.location.assign(e),new Promise(()=>{})}const I=`iterate:left-for-sign-in`;function L(e,t){try{return t&&window.sessionStorage.setItem(e,t),window.sessionStorage.getItem(e)}catch{return null}}function R(t){let{mind:n}=t,r=null,i,o=e=>`/.auth/login?${new URLSearchParams({mind:n,next:e})}`,s=()=>{let e=new URL(`/api`,window.location.href);return e.searchParams.set(`mind`,n),e},c=()=>{let e=s();return e.protocol=e.protocol===`https:`?`wss:`:`ws:`,e};function l(t){let s=e(t),c={itx:O(s),socket:t,dispose:p};r=c,Promise.resolve(c.itx.whoami()).catch(e=>{if(a(e)!==`UNAUTHENTICATED`||r!==c)return;let t=Number(L(I));Date.now()-t<6e4||(L(I,String(Date.now())),F(o(window.location.href)))});let l,u=()=>l?.beatNow(),d=()=>document.visibilityState===`visible`&&u(),f=()=>{l?.stop(),window.removeEventListener(`pagehide`,p),window.removeEventListener(`online`,u),document.removeEventListener(`visibilitychange`,d),r===c&&(r=null,i=void 0)};function p(){f(),c.itx[Symbol.dispose](),s[Symbol.dispose]()}return t.addEventListener(`open`,()=>{l=A({beat:()=>c.itx.whoami(),onDead:e=>{console.warn(`The connection to ${n} is dead (${e}). Reconnecting.`),p()}})},{once:!0}),t.addEventListener(`close`,f,{once:!0}),window.addEventListener(`pagehide`,p,{once:!0}),window.addEventListener(`online`,u),document.addEventListener(`visibilitychange`,d),c}let u=new Proxy({},{get(e,t){if(t===Symbol.dispose)return()=>r?.dispose();let n=r||l(new WebSocket(c()));return Reflect.get(n.itx,t)}});async function d(e){let t=r?void 0:N(c()),i=()=>void t?.then(e=>e.close(),()=>{}),a=await fetch(s(),{method:`POST`,body:``,signal:AbortSignal.timeout(1e4)}).catch(e=>{throw i(),e});if(await a.body?.cancel(),a.ok||i(),a.status===401)return F(o(e));if(!a.ok)throw Error(`${n} is unavailable (${a.status}). Please retry.`);return t&&!r?l(P(t)):i(),{itx:u,read:async e=>await e(u)}}return{authenticate(e=`/`){return i||=d(e).catch(e=>{throw i=void 0,e}),i}}}export{o as connectEventLog,R as createIterateClient,u as facetSnapshotOf,n as itxSessionOf,S as memberItx,e as newWebSocketRpcSession,r as savedLogTails,c as useContextStub,l as useFacetLiveState,h as useHeldContext,s as useIterateContext,p as useItxConnection,m as useKept,f as useKeptContext,d as useSavedContext,i as wipeSavedLogTails};
M files.json
@@ -43,7 +43,7 @@ "dist/chunks/message.mjs": "sha256-CCuJKCKTUmWWIoAJWvCep0WRwOdrFjprUbhg2lclCT4=", "dist/chunks/presence-line.mjs": "sha256-eTr9L32hODg8+6OmBFyw44Sqi8MeOKWeihypUAa4+c4=", "dist/chunks/principal-label.mjs": "sha256-h24aw3AFL9MqY1nF30QFet44xjXs5+FKERgbcp+skc4=", - "dist/chunks/react.mjs": "sha256-Cw64kORabXCL/X+U9k3ot0IRY1I4tpri6EJUFnHc9kc=", + "dist/chunks/react.mjs": "sha256-BEUK1lJcgRPCj2hNaU40aVO3cLwqbn6mEDIpoUbyihY=", "dist/chunks/read-progress.mjs": "sha256-3RLD5izzrBrDLg6bhq/a2wJATJ8VZJtvbFUlDXecReM=", "dist/chunks/rolldown-runtime.mjs": "sha256-WArYxYBhpN3pm94KVpBeOC8FaFFu4vW4Tb+1IIVwkCE=", "dist/chunks/run.mjs": "sha256-3KBfOiSTkiX9qreu0tH+euZb6l959WxDjEQ4B3nKp2w=", @@ -109,10 +109,10 @@ "dist/components/dash/dash-paths.mjs": "sha256-FYvPJisVzsUQUnag9qsTFJNRFjagybxtlwCJIZPfdqM=", "dist/components/dash/dash.mjs": "sha256-XQxwxGrBwaofzl3jeo0czlfh7d/Diu/gkFqb0hwsw4U=", "dist/components/docs-editor/doc-tree.mjs": "sha256-wY57KTnF9m1TqM7ZxH0rW6N1Pd2Go+BeDz5vkIANcUc=", - "dist/components/docs-editor/docs-editor.mjs": "sha256-m/ORf64MsrjcQrjojyRAbqfPt6Aov3/dkSqS90jclEA=", + "dist/components/docs-editor/docs-editor.mjs": "sha256-hnV9gu9JdE5uAoDPqR8DQkuW12tVgvOpKp74YUu5fCc=", "dist/components/environment-head-content.mjs": "sha256-C7/ht7n3K6Iir2FoK711NDcthqHU7hmj7HkGH/6VR2w=", "dist/components/identifier.mjs": "sha256-dpQb3D5PQ6Y3uy5xM/IHcrckVnXYI+dbVmWtSx8lgUo=", - "dist/components/integrations-page.mjs": "sha256-+3fRUAO3E6bX3W2fq7Y/9QOqgKpTqjyL/TeYbye4Phs=", + "dist/components/integrations-page.mjs": "sha256-Pc/GuCRTVYv/AWrXsb43jhKslmBbhfPYHao/BwV0ei0=", "dist/components/iterate-logo.mjs": "sha256-B11Qke7IiCsUtQ41+sj57Dh0Z7ZnuMFySPqtKJDAaQQ=", "dist/components/last-mind-redirect.mjs": "sha256-Td1V1GbqyNOrYUBot1JDk1F6xAJmMlkyXguAJDwWgcY=", "dist/components/list-row-text.mjs": "sha256-z0+hATb+IjkRezKRa++JmDd8vOXlXSUWOJRuU2h6OVo=", @@ -121,7 +121,7 @@ "dist/components/mind-app-shell.mjs": "sha256-hrYw+EcFbhINJOTZJljM6eaFOckXeJHHIznZnAVPRGQ=", "dist/components/page-tools.mjs": "sha256-fEth7zX58Fh9IqE/MJLycj1jEFf0IfFJN7thTY3DnLo=", "dist/components/reconnecting-mark.mjs": "sha256-Fh3cbCS4KyIzYwq1eqrR5GapvGiP8PBXfN9v0SN7wo4=", - "dist/components/repo-ide/repo-ide.mjs": "sha256-usZKMlHkf2nUMhrFLg2wYTbS973ZGCmBlyTz8RKu6J0=", + "dist/components/repo-ide/repo-ide.mjs": "sha256-lsePreiokQZoFH9hh8aFP3rkgSCzsVCb5K8O9St/Dwc=", "dist/components/route-defaults.mjs": "sha256-rzQtBMUxwnDhhrCeCk6cqB0m56i7WJjAj0dyPqTYGVk=", "dist/components/secrets-page.mjs": "sha256-Sjc3t62h0GyXblDLX38YMxg6bYdq4A8uw7kABMLiCQM=", "dist/components/setup-steps.mjs": "sha256-yoVPX4vhBP6bV6cyrmVJWaPe7kkPUrovO3r9ELfxslo=", @@ -200,7 +200,7 @@ "dist/lib/saved-log-tail.mjs": "sha256-cH0BICZuqawUBfNev4ZQrbdSqcD9kGd9ybLutiB+lwg=", "dist/lib/source-editor.mjs": "sha256-i0rBeeXziLuDv5q3uNTlCwnGIUxaY7xUJOiPyrnl1dU=", "dist/lib/waiting-approvals.mjs": "sha256-VVB3QOpbY/oAAO0BxOq4yul+B6KHL+6TnIFQy/xcrBI=", - "dist/live.mjs": "sha256-Ig7ggDdtfeWhh/B/m6/WbVKij0coAcOC8kavsLjt+XE=", + "dist/live.mjs": "sha256-/tJVz4IrgaJ0LxbBlWInPKWIu8XwJy9bb5GGHg9y4ug=", "dist/page.mjs": "sha256-14Gpwq5VKGQvcgtwIX/CpIT9Pix81z4FKh/h8UCRgCo=", "dist/query.mjs": "sha256-o2FTniaLCsM/AvBCHhL5cvft82Azq+xV9YWijtwi4c4=", "dist/react-dom.mjs": "sha256-7kfOM4XtNIgnCXlSqkdSCc3gNgI43cClnPo+lDAWaMU=",
M release.json
@@ -1,7 +1,6 @@ { "package": "@iterate-com/ui", - "source": "4eb6b938f58a9b76ae039bf98f8a491cd58c1f96", - "workspace": "5e1a4d0d99a3dd630517721a6152be99a70a48ba", + "source": "2000e8b7d01972d0bcb917c138e2b325681aef99", "modules": 188, "rewritten": 525 }