@vercel/board 0.48.1 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/{access-C06pIr0M.mjs → access-BbgmsAFF.mjs} +29 -17
  2. package/dist/access.d.mts +2 -2
  3. package/dist/access.mjs +5 -5
  4. package/dist/{actors-Dkyg-oo0.mjs → actors-CX2D22hL.mjs} +4 -3
  5. package/dist/{auth-B9-wXQ-x.mjs → auth-DJDTfgAL.mjs} +2 -2
  6. package/dist/{auth-li3lKwJG.d.mts → auth-Z9-Khvvw.d.mts} +1 -1
  7. package/dist/{backend-UBP6HimX.d.mts → backend-CcaaS9Xl.d.mts} +31 -8
  8. package/dist/backend-local.d.mts +1 -1
  9. package/dist/backend-local.mjs +1 -1
  10. package/dist/{chat-provider-iN0DFsSE.d.mts → chat-provider-DQ1GHm4o.d.mts} +2 -2
  11. package/dist/{chat-provider-kNWd6MQC.mjs → chat-provider-HJ7y_ipp.mjs} +2 -2
  12. package/dist/cli-commands.d.mts +1 -1
  13. package/dist/cli-commands.mjs +1 -1
  14. package/dist/cli-embedded.d.mts +8 -2
  15. package/dist/cli-embedded.mjs +10 -4
  16. package/dist/cli.mjs +6 -6
  17. package/dist/client-C2T4eaXd.d.mts +544 -0
  18. package/dist/{commands-CJsOA-hf.d.mts → commands-Cm4sODIu.d.mts} +12 -8
  19. package/dist/{commands-Dk6_cHLS.mjs → commands-nN8WpvCe.mjs} +75 -58
  20. package/dist/{conformance-CDP8y2Zm.mjs → conformance-Cr-umDl0.mjs} +102 -20
  21. package/dist/conformance.d.mts +1 -1
  22. package/dist/conformance.mjs +1 -1
  23. package/dist/{engine-BQ0hJw2w.mjs → engine-DJZ8Xy_g.mjs} +10 -7
  24. package/dist/{errors-QhkdzI-o.mjs → errors-DYF4hhIc.mjs} +53 -174
  25. package/dist/{events-B-qyxNsJ.mjs → events-BdOCmnZh.mjs} +3 -3
  26. package/dist/{exports-BzSG0_wL.mjs → exports-CuD-Mxkw.mjs} +389 -118
  27. package/dist/{exports-inhbjAWi.d.mts → exports-lmr6UHHc.d.mts} +4 -4
  28. package/dist/{external-BuVTXT1R.mjs → external-D2jq_DEQ.mjs} +1 -1
  29. package/dist/{index-B0Fnhvk7.d.mts → index-_KxJu15n.d.mts} +2 -2
  30. package/dist/index.d.mts +6 -6
  31. package/dist/index.mjs +4 -4
  32. package/dist/index.node.d.mts +7 -7
  33. package/dist/index.node.mjs +4 -4
  34. package/dist/inspect/app.js +39 -39
  35. package/dist/inspect/engine.js +3 -3
  36. package/dist/inspect-CZeoSm7E.mjs +272 -0
  37. package/dist/inspect-UCcPViyA.mjs +2 -0
  38. package/dist/inspect.d.mts +17 -0
  39. package/dist/inspect.mjs +196 -0
  40. package/dist/{local-BdKxz-Dn.mjs → local-BVSFSSYf.mjs} +165 -61
  41. package/dist/{main-BgiViRZ8.mjs → main-B016auoG.mjs} +227 -49
  42. package/dist/{memory-CMm-Fk_A.mjs → memory-C2lzMV_t.mjs} +2 -2
  43. package/dist/{middleware-CT6vMNUc.mjs → middleware-DUKIITFZ.mjs} +3 -3
  44. package/dist/{page-D-OzDOAX.mjs → page-7KWSGxyC.mjs} +12 -2
  45. package/dist/page-CN77B014.mjs +2 -0
  46. package/dist/profile-header-Cj0Cb1cf.mjs +163 -0
  47. package/dist/{provider-DC3WHUXo.d.mts → provider-Dwb_9mnu.d.mts} +3 -529
  48. package/dist/{routes-CjA6Mp4D.d.mts → routes-B6SEA9yw.d.mts} +130 -4
  49. package/dist/{routes-ABXf3CKq.mjs → routes-BE0y6wCk.mjs} +40 -14
  50. package/dist/{schemas-7VFdomFB.mjs → schemas-CUSTEFIy.mjs} +11 -3
  51. package/dist/{serve-C2Jbr7pR.mjs → serve-B10e7QaY.mjs} +5 -5
  52. package/dist/{server-EOQC5Gtq.mjs → server-ViWNvg5q.mjs} +61 -29
  53. package/dist/{serving-BNdiReQT.mjs → serving-SbqeWqlA.mjs} +1 -1
  54. package/dist/{inspect-n9brh-TT.mjs → shell-DmpmgOPC.mjs} +25 -274
  55. package/dist/{sql-IEbO5vXs.mjs → sql-iABdyCiz.mjs} +18 -5
  56. package/dist/{sqlite-CVG8XKHm.mjs → sqlite-28EMrmk7.mjs} +2 -2
  57. package/dist/{sqlite-db-BJjPQYx4.mjs → sqlite-db-Ckd-ceNe.mjs} +1 -1
  58. package/dist/sync-chat-sdk.d.mts +2 -2
  59. package/dist/sync-chat-sdk.mjs +2 -2
  60. package/dist/sync-github.d.mts +2 -2
  61. package/dist/sync-github.mjs +3 -3
  62. package/dist/sync-linear.d.mts +3 -3
  63. package/dist/sync-linear.mjs +3 -3
  64. package/dist/sync-slack.d.mts +3 -3
  65. package/dist/sync-slack.mjs +11 -7
  66. package/dist/sync.d.mts +2 -2
  67. package/dist/sync.mjs +2 -2
  68. package/dist/{tags-BpFo6q0_.mjs → tags-D0qra0Qy.mjs} +1 -1
  69. package/dist/{task-batch-D4p9N8lN.mjs → task-batch-9lVDG3d-.mjs} +10 -11
  70. package/dist/{tokens-BCp4EWTQ.mjs → tokens-C-iK0Cku.mjs} +2 -2
  71. package/dist/version-C70RLVEK.mjs +5 -0
  72. package/docs/01-board/01-mounting.md +8 -0
  73. package/docs/01-board/03-identity.md +3 -2
  74. package/docs/01-board/04-messages.md +6 -2
  75. package/docs/01-board/05-reading.md +17 -2
  76. package/docs/01-board/09-access.md +40 -6
  77. package/docs/01-board/11-tasks.md +3 -3
  78. package/docs/02-sync/01-overview.md +2 -1
  79. package/docs/03-guides/02-inspector.md +31 -0
  80. package/docs/03-guides/06-sandboxed-agents.md +22 -21
  81. package/docs/04-reference/01-cli.md +91 -33
  82. package/docs/04-reference/02-board.md +20 -7
  83. package/docs/04-reference/03-http.md +9 -6
  84. package/docs/04-reference/05-conformance.md +7 -0
  85. package/package.json +5 -1
  86. package/dist/inspect-BB-XUPuz.mjs +0 -2
  87. package/dist/page-Dr9Aqlej.mjs +0 -2
@@ -1,5 +1,5 @@
1
- import{A as e,C as t,D as n,E as r,F as i,M as a,N as o,O as s,P as c,S as l,T as u,_ as d,a as f,b as p,c as m,d as h,f as g,g as _,h as v,i as y,j as b,k as x,l as S,m as C,n as w,o as T,p as E,r as ee,s as te,t as ne,u as re,v as ie,w as D,x as O,y as k}from"./app.js";o({id:c().min(1),platform:c().min(1),key:c().min(1),...E.shape,raw:i()});const ae=o({root:a(e=>typeof e==`function`).optional(),text:c().optional(),labels:l.optional(),unset:e(O).optional(),noSync:b().optional()}).strict();function A(e){if(e&&typeof e==`object`){for(let t of Object.values(e))A(t);Object.freeze(e)}return e}const oe=o({target:c().min(1),channel:c().min(1),kind:x([`channel`,`thread`])}).strict();var j=class extends Error{code;constructor(e,t){super(t),this.code=e}};const se=e=>e instanceof j&&e.code===`channel_not_found`,ce=o({event:g,raw:i(),dedupe:c().min(1)}),M=/* @__PURE__ */ new WeakMap,le=e=>M.get(e),ue=e=>/^(```|~~~|[-*+] |\d+[.)] |#{1,6} |>|\|)/.test(e),N=/^\[vc\]: #\S*\r?\n/,P=/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g,F=/!\[([^\]]+)\]\(https:\/\/vercel\.com\/static\/status\/[^)]+\)\s*(?:\[[^\]]*\]\((https?:\/\/[^)\s]+)\))?/;function de(e){if(!N.test(e))return null;let t=e.search(/<details><summary>\d+ Skipped Deployments?<\/summary>/),n=[],r=0;for(let i of e.split(/\r?\n/)){let a=r;if(r=e.indexOf(`
1
+ import{A as e,C as t,D as n,E as r,F as i,M as a,N as o,O as s,P as c,S as l,T as u,_ as d,a as f,b as p,c as m,d as h,f as g,g as _,h as v,i as y,j as b,k as x,l as S,m as C,n as w,o as T,p as E,r as ee,s as te,t as ne,u as re,v as ie,w as D,x as O,y as k}from"./app.js";o({id:c().min(1),platform:c().min(1),key:c().min(1),...E.shape,raw:i()});const ae=o({root:a(e=>typeof e==`function`).optional(),text:c().optional(),labels:t.optional(),unset:e(O).optional(),noSync:b().optional()}).strict();function A(e){if(e&&typeof e==`object`){for(let t of Object.values(e))A(t);Object.freeze(e)}return e}const oe=o({target:c().min(1),channel:c().min(1),kind:x([`channel`,`thread`])}).strict();var j=class extends Error{code;constructor(e,t){super(t),this.code=e}};const se=e=>e instanceof j&&e.code===`channel_not_found`,ce=o({event:g,raw:i(),dedupe:c().min(1)}),M=/* @__PURE__ */ new WeakMap,le=e=>M.get(e),ue=e=>/^(```|~~~|[-*+] |\d+[.)] |#{1,6} |>|\|)/.test(e),N=/^\[vc\]: #\S*\r?\n/,P=/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g,F=/!\[([^\]]+)\]\(https:\/\/vercel\.com\/static\/status\/[^)]+\)\s*(?:\[[^\]]*\]\((https?:\/\/[^)\s]+)\))?/;function de(e){if(!N.test(e))return null;let t=e.search(/<details><summary>\d+ Skipped Deployments?<\/summary>/),n=[],r=0;for(let i of e.split(/\r?\n/)){let a=r;if(r=e.indexOf(`
2
2
  `,r)+1||e.length,!i.startsWith(`|`)||/^\|\s*(Project|Name)\s*\|/.test(i)||/^\|\s*:?-/.test(i))continue;let o=i.split(`|`).slice(1,-1).map(e=>e.trim());if(o.length<2)continue;let s=F.exec(o[1]);if(!s)continue;let c=[...o[0].matchAll(P)].at(-1),l=c?.[1]??o[0].replace(/<[^>]*>/g,``).trim();if(!l)continue;let u=o[2]?[...o[2].matchAll(P)].find(e=>/preview/i.test(e[1])):void 0,d=o[3]?.match(/<relative-time[^>]*>([^<]+)<\/relative-time>/)?.[1]?.trim()??(o[3]?.replace(/<[^>]*>/g,``).trim()||null),f=o[3]?.match(/<relative-time[^>]*\sdatetime="([^"]+)"/)?.[1]??null;n.push({project:l,projectUrl:c?.[2]??null,status:s[1].trim(),deploymentUrl:s[2]??null,previewUrl:u?.[2]??null,updated:d,updatedAt:f!==null&&!Number.isNaN(Date.parse(f))?f:null,skipped:t!==-1&&a>t})}return n.length>0?n:null}const I={ready:`✅`,building:`⏳`,queued:`⏳`,initializing:`⏳`,error:`❌`,failed:`❌`,canceled:`⚪`,ignored:`⚪`},L=(e,t)=>t?`[${e}](${t})`:e;function R(e){return e.map(e=>`- ${[`${I[e.status.toLowerCase()]??`▲`} **${L(e.project,e.projectUrl)}**`,`${L(e.status,e.deploymentUrl)}${e.skipped?` (skipped)`:``}`,...e.previewUrl?[L(`Preview`,e.previewUrl)]:[],...e.updated?[e.updated]:[]].join(` · `)}`).join(`
3
- `)}function fe(e,t){return e.by.actor===`github:user:35613825`||e.by.profile===`github:user:35613825`&&!!e.from&&t?.kind===`external`&&t.verified===!0&&t.platform===`github`}function pe(e,t){let n=t?de(e):null;return n?`**▲ Vercel**\n${R(n)}`:e}const z=(e,n=!1)=>{let r=D(e),i=r.trim()===``?n?``:`(no text)`:r;return i.length>1e4?`${i.slice(0,t-1).toWellFormed()}…`:i},B=(e,t,r=e.name??`a file`)=>`📎 ${r}${e.size===void 0?``:` (${n(e.size)})`} didn't come over: ${t}`,V=e=>e instanceof _&&e.code===`no_files`,me=(e,t)=>{let n=e.name??`a file`;if(!e.url||!/^https?:\/\//.test(e.url))return B(e,t);let r=n.replace(/[[\]\\]/g,e=>`\\${e}`),i=e.url.replace(/[ ()]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`);return B(e,t,`[${r}](${i})`)},H=(e,t)=>t.length?`${e.trim()?`${e}\n\n`:``}${t.join(`
3
+ `)}function fe(e,t){return e.by.actor===`github:user:35613825`||e.by.profile===`github:user:35613825`&&!!e.from&&t?.kind===`external`&&t.verified===!0&&t.platform===`github`}function pe(e,t){let n=t?de(e):null;return n?`**▲ Vercel**\n${R(n)}`:e}const z=(e,t=!1)=>{let n=D(e),r=n.trim()===``?t?``:`(no text)`:n;return r.length>1e4?`${r.slice(0,l-1).toWellFormed()}…`:r},B=(e,t,r=e.name??`a file`)=>`📎 ${r}${e.size===void 0?``:` (${n(e.size)})`} didn't come over: ${t}`,V=e=>e instanceof _&&e.code===`no_files`,me=(e,t)=>{let n=e.name??`a file`;if(!e.url||!/^https?:\/\//.test(e.url))return B(e,t);let r=n.replace(/[[\]\\]/g,e=>`\\${e}`),i=e.url.replace(/[ ()]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`);return B(e,t,`[${r}](${i})`)},H=(e,t)=>t.length?`${e.trim()?`${e}\n\n`:``}${t.join(`
4
4
  `)}`:e,he=e=>e.split(`
5
- `).filter(e=>/^📎 .* didn't come over: /u.test(e)),U=e=>JSON.stringify([e.url,e.message,e.snapshot,e.unavailable]),ge=(e,t)=>e.length===t.length&&e.every((e,n)=>U(e)===U(t[n])),_e=new AbortController().signal,ve=e=>{try{return JSON.parse(JSON.stringify(e??null))}catch{return null}},W=e=>typeof e==`string`?D(e):Array.isArray(e)?e.map(W):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,t])=>[D(e),W(t)])):e,G=e=>{let t=e?.data?.error,n=typeof t==`string`?t:e instanceof Error?e.message:String(e);return D(n.slice(0,500))||`unknown error`},ye=e=>e instanceof _&&e.status===404;function K(e,t,n){return n.startsWith(`${e}:`)?n:`${e}:${n.startsWith(`${t}:`)?n.slice(t.length+1):n}`}function be(e,t,n){return e===t?n:re(n,n=>n.kind===`actor`&&n.actor.startsWith(`${t}:`)?`@[${K(e,t,n.actor)}]`:null)}function xe(e,t,n){if(!(`author`in n))return n;let r={...n.author,id:K(e,t,n.author.id)};return n.kind!==`message`&&n.kind!==`edited`||e===t?{...n,author:r}:{...n,author:r,...n.mentioned?{mentioned:n.mentioned.map(n=>({...n,id:K(e,t,n.id)}))}:{},text:be(e,t,n.text)}}function q(e){let t=null,i=()=>{if(!t)throw Error(`sync used before board() bound it`);return t},a={self:`sync`,origin:{via:{kind:`engine`}}};function o(e,t,n=_e,r=a){let o=i().backend;return o[e].call(o,r,t,n)}let c=t=>{let n=e[t];if(!n)throw d(`no sync entry named ${t}`);return n},l=e=>e.slice(0,e.indexOf(`:`)),g=e=>i().syncedHere(e),b=async t=>e[l(t)]!==void 0&&await g(l(t)),x=e=>e.slice(e.indexOf(`:`)+1);async function E(e){try{return await o(`syncThread`,{thread:e})}catch(e){if(ye(e))return null;throw e}}async function D(e){try{let{message:t,replies:n}=await o(`message`,{id:e});return[t,...n]}catch(e){if(ye(e))return[];throw e}}async function O(e){return(await D(e)).find(t=>t.id===e)??null}async function M(e){return e.length===0?{}:(await o(`syncCopies`,{message:[...new Set(e)]})).copies}let N=(e,t)=>o(`syncFind`,e,t),P=null;function F(){if(P)return P;let e=o(`me`,{}).then(e=>e.principal);return P=e,e.catch(()=>{P===e&&(P=null)}),e}async function I(){let[{actors:e},t]=await Promise.all([o(`actors`,{}),F().catch(()=>null)]),n={byId:{},principal:t};for(let t of e)n.byId[t.id]={id:t.id,kind:t.kind,handle:t.handle,name:t.name,avatar:t.avatar,...t.via?{via:{...t.via}}:{},...t.platform?{platform:t.platform}:{},...t.verified?{verified:!0}:{}};return n}let L=/* @__PURE__ */ new Map;function R(e,t){let n=`${e}:${t}`,r=L.get(n);if(r&&(!r.failed||Date.now()-r.at<6e4))return r.id;let i={id:c(e).resolveChannel(t),failed:!1,at:Date.now()};return i.id.catch(r=>{i.failed=!0;let a=se(r);!a&&L.get(n)===i&&L.delete(n),console.warn(`[board] sync ${e}: ${a?`skipping`:`couldn't resolve`} ${t}: ${r.message}`)}),L.set(n,i),i.id}function U(e,t){if(!v(t))return x(t);try{let n=c(e).inboxChannel(e,t);return n===null?null:x(n)}catch{return null}}let q=/* @__PURE__ */ new Map;function Se(e,t){let n=`${e}\u001f${t.toLowerCase()}`,r=q.get(n);if(r&&Date.now()-r.at<3e5)return r.mention;q.size>=1e3&&q.clear();let i=c(e),a=i.findByEmail(t).then(e=>e?i.mention({id:e.id,kind:`external`,handle:e.handle,name:e.name,avatar:e.avatar}):null,()=>null);return q.set(n,{at:Date.now(),mention:a}),a}async function Ce(e){let t=e.indexOf(`:`);if(t<=0)throw d(`sync targets look like <key>:<channel or thread>, got: ${e}`);let n=e.slice(0,t),r=c(n);try{let i=oe.parse(await r.resolveTarget(e.slice(t+1)));if(i.kind===`channel`&&!r.canStartThreads)throw Error(`${r.platform} cannot start threads; use an existing thread`);return{target:`${n}:${i.target}`,kind:i.kind}}catch(t){throw d(`can't sync to ${e}: ${t.message}`)}}async function we(e,t){let{event:n,raw:r,dedupe:i}=ce.parse(W({...t,raw:ve(t.raw)}));for(let t of[n.channel,n.thread,`subthread`in n?n.subthread:null])if(t!==null&&!t.startsWith(`${e}:`))throw d(`provider locations must belong to sync entry ${e}`);let a=le(c(e)),s=a&&await a(x(n.channel),t=>R(e,t)).catch(async e=>{if(await Te(n.thread))return!0;throw e});(!a||s||await Te(n.thread))&&await o(`inboxPush`,{key:e,events:[{id:i,event:n,raw:r}]})}async function Te(e){try{return(await N({thread:e},AbortSignal.timeout(2e3))).thread!==null}catch(e){let t=e?.name;if(t===`TimeoutError`||t===`AbortError`)return!0;throw e}}async function Ee(t,n){let r=e[t];if(!r)throw ie(`no sync entry named ${t}`);if(!await g(t))return new Response(null,{status:200});let i;try{i=await r.receive(t,n,e=>we(t,e))}catch(e){return e instanceof _&&e.status===400?(console.error(`[board] dropped an event the board refuses`,e),new Response(null,{status:200})):(console.error(`[board] intake failed`,e),new Response(`intake failed`,{status:500}))}let a=De([t]).catch(e=>console.error(`[board] couldn't pull ${t}'s inbox:`,G(e)));return ee(a),i}async function De(t=Object.keys(e)){let n=0,r=Date.now()+24e4;for(let e of t)if(await g(e))for(;Date.now()<r;){let{items:t}=await o(`inboxNext`,{key:e,limit:10});if(t.length===0)break;await Promise.all(t.map(t=>Oe(e,t))),n+=t.length}return n}async function Oe(e,t){let n;try{await je(e,{event:t.event,raw:t.raw},{id:t.id,attempt:t.attempt+1})}catch(r){console.error(`[board] sync ${e} couldn't import ${t.id}:`,G(r)),n=G(r)}await o(`inboxAck`,{key:e,id:t.id,lease:t.lease,...n===void 0?{}:{error:n}}).catch(e=>console.error(`[board] couldn't ack an inbox event:`,G(e)))}async function ke(e,t,n,r,i=[]){if(t.length===0)return[];let a=[];for(let o of t){if(a.some(e=>e.url===o.url))continue;let t=(await N({thread:o.thread,message:o.message})).message,s=t===null?null:await O(t);if(s&&!s.deleted&&s.channel===r){a.push({url:o.url,message:s.id,unavailable:null,snapshot:{author:s.author?T(s.author):s.by.actor,text:s.text,createdAt:s.createdAt,files:s.attachments.map(e=>({name:e.name,url:null}))}});continue}if(o.snapshot){a.push({url:o.url,message:null,snapshot:o.snapshot,unavailable:null});continue}let c=i.find(e=>e.url===o.url&&e.snapshot&&e.message===null);if(c){a.push(c);continue}let l=await e.fetchLink(o,n).catch(e=>({snapshot:null,unavailable:G(e)}));a.push({url:o.url,message:null,snapshot:l.snapshot,unavailable:l.snapshot?null:(l.unavailable??`unknown`).slice(0,300)})}return W(a)}async function Ae(e,t,n){let i=[],a=[],c=null;for(let l of t.slice(0,10)){if(c!==null){a.push(me(l,c));continue}if(l.size!==void 0&&l.size>26214400){a.push(B(l,`over ${r/1024/1024} MB`));continue}let t;try{let n=await e.fetchFile(l);if(n===null){a.push(B(l,`${e.platform} can't hand it over`));continue}t=n}catch(t){if(n<3)throw t;console.warn(`[board] couldn't fetch ${l.name??`a file`} from ${e.platform}:`,G(t)),a.push(B(l,`${e.platform} wouldn't hand it over`));continue}if(t.byteLength>26214400){a.push(B(l,`over ${r/1024/1024} MB`));continue}if(t.byteLength===0){a.push(B(l,`it was empty`));continue}let d=l.name??`${l.type}`;try{i.push((await o(`upload`,{data:t,name:d,type:l.mimeType||s(d)})).attachment)}catch(e){if(e instanceof _&&(e.code===`too_large`||e.code===`no_direct_uploads`)){a.push(B(l,`over ${u/1024/1024} MB`));continue}if(!V(e))throw e;c=e.message,a.push(me(l,c))}}for(let e of t.slice(10))a.push(B(e,`a message carries at most 10`));return{attachments:i,notes:a}}async function je(e,t,n){let r=c(e),a={...t,event:xe(e,r.platform,t.event)},{event:o,raw:s}=a,l=(await N({thread:o.thread})).thread??void 0;if(o.kind===`message`){let e=(await N({thread:o.subthread??o.thread,message:o.message})).message;if(e!==null){let t=(await O(e))?.origin;if(!t||t.message!==o.message||(t.subthread??t.thread)!==(o.subthread??o.thread))return}}let u=`author`in o?o.author:{id:`${e}:system`,handle:r.platform,name:r.platform,avatar:null,isBot:!0},f,p=()=>f??=A(r.event({id:n.id,key:e,event:o,raw:s})),m,h,g=!0,_={direction:`in`,key:e,channel:x(o.channel),get event(){return p()},board:i().client({author:u,key:e,...Ne(e,o)},n.id),import(t,r={}){if(!g)throw d(`the sync function has finished`);return m??=Me(e,a,n,l,t,r),m},permalink(){let e=h??r.permalink(p());return h=e,e.catch(()=>{h===e&&(h=void 0)}),e},resolve:t=>R(e,t)};try{await r.sync(_),await m}finally{g=!1}}async function Me(e,t,n,r,i,a){let o=i??(r?(await E(r))?.channel:void 0);if(o===void 0)return{root:null,message:null};try{return await Pe(e,t,n,p.parse(o),ae.parse(a))}catch(e){if(!(e instanceof ne))throw e;let n=(await N({thread:t.event.thread})).thread;return{root:n===null?null:(await E(n))?.root??null,message:null}}}function Ne(e,t){let n=c(e),r=(`subthread`in t?t.subthread:null)??t.thread;return{via:{kind:`sync`,key:e,platform:n.platform,channel:t.channel,thread:r},respond:async e=>{await n.post(x(r),`thread`,{markdown:e})}}}async function Pe(e,t,n,r,i){let{event:a,raw:s}=t,l=Ne(e,a),u=c(e),f=(await N({thread:a.thread})).thread??void 0,p=f?await E(f):null,m=p?.root,g=e=>h(`board-inbound`,n.id,String(e)),_={key:e,channel:l.via.channel,thread:l.via.thread},v=async e=>{if(!e.dropped)return e.message;for(let t of e.dropped)await l.respond(t);throw new ne(e.dropped)},y=async({attachments:t=[],...n})=>({id:await v(await o(`syncImport`,{op:`post`,from:e,source:_,...n,origin:n.origin??null,...t.length?{attachments:t.map(e=>e.id)}:{}})),re:n.re??null}),b=e=>({root:e.re??e.id,message:e.id}),S=(e={})=>{let t={...e,...i.labels};for(let e of i.unset??[])delete t[e];return t},C=e=>{if(!i.root)return e;let t=i.root(A(structuredClone(e)));if(t&&typeof t==`object`&&`then`in t)throw d(`root overrides must be synchronous`);let n=ae.pick({text:!0,labels:!0}).parse(t);return{...e,text:n.text??e.text,labels:{...e.labels,...n.labels}}},w=(t,n,r)=>o(`syncImport`,{op:`labels`,author:t,from:e,origin:{thread:a.thread},set:n,unset:r}),T=async(e,t)=>{if(!i.labels&&!i.unset)return;let n=await O(t),r=Object.fromEntries(Object.entries(i.labels??{}).filter(([e,t])=>n?.labels[e]!==t)),a=(i.unset??[]).filter(e=>n?.labels[e]!==void 0);(Object.keys(r).length||a.length)&&await w(e,r,a)};switch(a.kind){case`message`:{let t=(await N({thread:a.subthread??a.thread,message:a.message})).message;if(t!==null)return{root:m??t,message:t};let{attachments:o,notes:c}=a.files?.length?await Ae(u,a.files,n.attempt):{attachments:[],notes:[]},l=await ke(u,a.links??[],{thread:a.subthread??a.thread,message:a.message},p?.channel??r),d={...l.length?{links:l}:{},...a.mentioned?.length?{mentioned:a.mentioned}:{},author:a.author,text:z(H(i.text??a.text,c),o.length>0),...o.length?{attachments:o}:{},origin:{channel:a.channel,thread:a.thread,subthread:a.subthread,message:a.message,context:a.context},id:await g(0)},f={...d,...i.noSync?{noSync:!0}:{}};if(m!==void 0)return await T(a.author,m),b(await y({...f,re:m}));let h=await u.fetchRoot(x(a.thread));if(h===null){let e=C({text:a.text,labels:{},author:a.author,raw:s});return b(await y({...d,channel:r,text:z(H(i.text??e.text,c),o.length>0),labels:S(e.labels)}))}let _=C({...h,raw:h.raw??null}),v=await y({author:{...h.author,id:K(e,u.platform,h.author.id)},channel:r,text:z(_.text),labels:S(_.labels),origin:{channel:a.channel,thread:a.thread,subthread:null,message:`root:${n.id}`,context:null},id:await g(1)});return b(await y({...f,re:v.id}))}case`edited`:case`deleted`:case`reaction`:{let t=(await N({thread:a.subthread??a.thread,message:a.message})).message;if(t===null)return{root:m??null,message:null};let n=`author`in a?a.author:{id:`${e}:system`,handle:u.platform,name:u.platform,avatar:null,isBot:!0},r={thread:a.subthread??a.thread,message:a.message};if(m!==void 0&&await T(n,m),a.kind===`deleted`)await o(`syncImport`,{op:`delete`,author:n,from:e,origin:r});else if(a.kind===`edited`){let s=await O(t),c=z(H(i.text??a.text,s?he(s.text):[]),(s?.attachments.length??0)>0),l=a.mentioned?.length?{mentioned:a.mentioned}:{};s&&!a.linksOnly&&s.text!==c&&await v(await o(`syncImport`,{op:`edit`,author:n,from:e,origin:r,text:c,source:_,...l}));let d=s?await ke(u,a.links??[],r,s.channel,s.links):[];s&&!ge(d,s.links)&&await o(`syncImport`,{op:`links`,author:n,from:e,origin:r,links:d})}else{if(u.singleReaction){let i=k(a.emoji),s=/* @__PURE__ */ new Set([n.id,`${await F()}+${n.id}`]);for(let[c,l]of Object.entries((await O(t))?.reactions??{}))l.some(e=>s.has(e))&&!(a.added&&c===i)&&await o(`syncImport`,{op:`react`,author:n,from:e,origin:r,emoji:c,remove:!0})}(!u.singleReaction||a.added)&&await o(`syncImport`,{op:`react`,author:n,from:e,origin:r,emoji:a.emoji,remove:!a.added})}return{root:m??null,message:t}}case`lifecycle`:{if(m!==void 0){let t=await O(m),r=t?.origin?.message===`lifecycle:${n.id}`,c=S((r?C({text:J(a),labels:a.labels,author:a.author,raw:s}):null)?.labels??a.labels),l=e=>a.owns?.some(t=>e.startsWith(t))??!1,u=Object.fromEntries(Object.entries(c).filter(([e,n])=>t?.labels[e]!==n)),d=Object.keys(t?.labels??{}).filter(e=>!(e in c)&&(a.unset.includes(e)||i.unset?.includes(e)||l(e)));if(t&&!t.deleted&&(Object.keys(u).length||d.length)&&await w(a.author,u,d),a.retitled&&t&&!t.deleted&&t.from===e&&t.origin?.thread===a.thread){let n=z(i.text??C({text:J(a),labels:t.labels,author:a.author,raw:s}).text);t.text!==n&&await v(await o(`syncImport`,{op:`edit`,author:a.author,from:e,origin:{thread:t.origin.thread,message:t.origin.message},text:n}))}return a.reply?b(await y({author:a.author,re:m,text:z(i.text??a.reply),...i.noSync?{noSync:!0}:{},id:await g(1)})):{root:m,message:r?m:null}}if(!a.createRoot)return{root:null,message:null};let t=C({text:J(a),labels:a.labels,author:a.author,raw:s}),c=await y({author:a.author,channel:r,text:z(a.reply?t.text:i.text??t.text),labels:S(t.labels),origin:{channel:a.channel,thread:a.thread,subthread:null,message:`lifecycle:${n.id}`,context:null},id:await g(0)});return a.reply?b(await y({author:a.author,re:c.id,text:z(i.text??a.reply),...i.noSync?{noSync:!0}:{},id:await g(1)})):b(c)}}}async function Fe(e,t,n){let r=m(n).flatMap(e=>e.kind===`actor`?[e.actor]:[]);if(r.length===0)return n;let i=/* @__PURE__ */ new Map;for(let n of r)!t.byId[n]&&S(n)&&i.set(n,await Se(e,n));return re(n,n=>{if(n.kind===`handle`)return null;if(i.has(n.actor))return i.get(n.actor)??n.actor;let r=Le(n.actor,t);return r?ze(e,r.id,t)??r.name:Ie(e,n.actor,t)})}function Ie(e,t,n){let r=Re(e,t,n);if(r===null)return null;let i=c(e);return i.mentionById(`${i.platform}:${r}`)}function Le(e,t){return t.byId[e]??(t.principal?t.byId[`${t.principal}+${e}`]:void 0)??null}function Re(e,t,n){let{principal:r,profile:i}=y(t),a=i===null?t:f(i)!==null&&r===n.principal?i:null;return a?.startsWith(`${e}:`)?a.slice(e.length+1):null}function ze(e,t,n){let r=n.byId[t],i=r?Re(e,t,n):null;if(i===null)return null;let a=c(e);return a.mention({...r,id:`${a.platform}:${i}`})}async function Be(t,n,r,i,a){let o=i.byId[r.by.actor],s=o?.name??r.by.actor,l=`${o?.via?` ${te(o.via)}`:``}${r.from?` (${o?.platform??e[r.from]?.platform??r.from})`:``}`,u=o?.kind===`deployment`&&!o.via?/(?:@[^@/]+| \([^()]+\))$/.exec(s)?.[0]??``:``,f=`${s}${l}`,p=`${u}${l}`,m=c(t),h=fe(r,o),g=(a??(e=>m.render(e)))(A({message:{...structuredClone(r),text:pe(r.text,h)},author:o?{...o}:null,mentionOf:e=>ze(t,e,i),label:f,target:n}));if(typeof g!=`string`)throw d(`a provider renderer must return markdown`);let _=`**${f}**: `,v=await Fe(t,i,g.startsWith(_)&&ue(g.slice(_.length))?`**${f}**:\n\n${g.slice(_.length)}`:g),y=h?de(r.text):null;return{markdown:v,...o?.verified?{as:{name:f,avatar:Ve(r,o),attribution:p}}:{},...y?{deployments:y}:{}}}function Ve(e,t){let n=e=>!e||/\/avatars\/[a-z0-9-]+$/.test(e),r=t?.avatar??null;if(!n(r))return r;let i=t?.handle.split(`/`)[0]??``,a=e.by.principal.slice(12);return!e.by.principal.startsWith(`vercel:user:`)||!i||/^user-/.test(i)||i.toLowerCase()===a.toLowerCase()?r:`https://vercel.com/api/www/avatar?u=${encodeURIComponent(i)}&s=64&format=png`}let He=e=>e.attachments.map(t=>`\n📎 ${t.name} (${n(t.size)}, on the board: #${e.id})`).join(``),Y=async(e,t,n,r=!1,i)=>{let a=l(e),{markdown:o,...s}=await Be(a,e,t,n,i);return{markdown:t.attachments.length>0&&(r||!c(a).uploadsFiles)?`${o}\n${He(t)}`:o,...s}};async function Ue(e,t,n,r,i){let a=e.replyTo===null?void 0:(await M([e.replyTo]))[e.replyTo]?.[t],o=a!==void 0&&a.thread!==n?a.thread:n,s=c(l(t)),u=await Y(t,e,r,!1,i),f,p;if(!u.markdown.trim()&&e.attachments.length&&s.uploadsFiles)try{let n=await Ke(e,t,o);p=n.message,f=n.files}catch(n){if(!s.refusesFiles(n)&&!V(n))throw n;u=await Y(t,e,r,!0,i),p=(await s.post(x(o),`thread`,u)).message,f=null}else{if(!u.markdown.trim())throw d(`a renderer must return text unless the message has media`);p=(await s.post(x(o),`thread`,u)).message}let m={thread:o,message:p,...f===void 0?{}:{files:f}};return await We(e,t,m),m}async function We(e,t,n){await o(`syncReceipt`,{kind:`message`,message:e.id,target:t,external:{thread:n.thread,message:n.message},...n.files===void 0?{}:{files:n.files}})}async function Ge(e){return Promise.all(e.attachments.map(async e=>{let{data:t}=await o(`attachment`,{id:e.id});return{data:t instanceof Uint8Array?t:new Uint8Array(await new Response(t).arrayBuffer()),filename:e.name,mimeType:e.type}}))}async function Ke(e,t,n){return c(l(t)).uploadFiles(x(n),await Ge(e))}async function X(e,t,n,r,i){let a=c(l(t));if(!a.uploadsFiles||e.attachments.length===0||n.files!==void 0)return;let s;try{s=(await Ke(e,t,n.thread)).files}catch(o){if(!a.refusesFiles(o)&&!V(o))throw Object.assign(/* @__PURE__ */ Error(`files: ${G(o)}`),{cause:o,data:{error:`files: ${G(o)}`}});console.warn(`[board] ${t} won't take #${e.id}'s files (${G(o)}); noting them in its text`),s=null,await Y(t,e,r,!0,i).then(e=>a.edit(x(n.thread),n.message,e)).catch(n=>console.warn(`[board] couldn't note #${e.id}'s files on ${t}:`,G(n)))}await o(`syncReceipt`,{kind:`files`,message:e.id,target:t,files:s})}let Z=(e,t,n,r)=>{e.some(e=>e.error===r)||e.push({id:t,target:n,error:r})};async function Q(e,t){if(t.length!==0){if(e<5||w(e))throw t[0].error;for(let{id:e,target:n,error:r}of t)console.error(`[board] gave up ${n===null?`syncing #${e}`:`delivering #${e} to ${n}`}:`,G(r)),n!==null&&await o(`syncReceipt`,{kind:`failed`,message:e,target:n,error:G(r)})}}async function $(e,t,n,r,i){let a,o=!0,s=()=>d(`the sync function has finished`),l={direction:`out`,key:e,channel:r===null?null:U(e,r),event:A(structuredClone(t)),message:A(structuredClone(n)),target:r,deliver(e={}){if(!o)throw s();return a??=r===null?Promise.resolve():i(e.render),a},start(t){if(!o)throw s();return qe(e,n,t)},resolve:t=>R(e,t)};try{await c(e).sync(l),await a}finally{o=!1}}async function qe(e,t,n){let{target:r,kind:i}=await Ce(`${e}:${n}`),a=t.re===null?t:await O(t.re);!a||a.deleted||a.noSync||r!==(a.origin?a.origin.channel??C(a.origin.thread):null)&&await o(`syncReceipt`,{kind:`thread`,message:a.id,target:r,targetKind:i,cause:`config`})}async function Je(t,n){let r=[];for(let t of Object.keys(e))e[t].canStartThreads&&await g(t)&&r.push(t);if(t.payload.noSync||r.length===0)return;let i=await O(t.message.id);if(!i||i.deleted)return;let a=[];for(let e of r)try{await $(e,t,i,null,async()=>{})}catch(e){Z(a,i.id,null,e)}await Q(n,a)}async function Ye(e,t){let{thread:n,target:r}=e.payload;if(!await b(r)||(e.payload.kind??(v(r)?`thread`:`channel`))===`thread`)return;let i=await E(n);if(!i?.targets.includes(r))return;let[a,...o]=await D(i.root);if(!a||a.id!==i.root||a.deleted)return;let s=[];try{await $(l(r),e,a,r,e=>Xe(i,a,o,r,s,e))}catch(e){Z(s,a.id,r,e)}await Q(t,s)}async function Xe(e,t,n,r,i,a){let o=await I(),s=await M([t.id,...n.map(e=>e.id)]),u=e=>(i.push({id:t.id,target:r,error:e}),e),f=e.external[r];if(f){let e=s[t.id]?.[r];if(e)try{await X(t,r,e,o,a)}catch(e){throw u(e)}}else try{let e=c(l(r)),n=await Y(r,t,o,!1,a),i=!n.markdown.trim()&&t.attachments.length>0&&e.uploadsFiles;if(!n.markdown.trim()&&!i)throw d(`a renderer must return text unless the message has media`);let s,u=await(async()=>{if(!i&&(t.attachments.length===0||!e.startsThreadsWithFiles))return e.post(x(r),`channel`,n);try{let a=await e.post(x(r),`channel`,{...n,files:await Ge(t)});return s=i?a.files??[]:a.files,a}catch(n){if(!e.refusesFiles(n)&&!V(n))throw n;return s=null,e.post(x(r),`channel`,await Y(r,t,o,!0,a))}})();f=`${l(r)}:${u.thread}`;let p={thread:f,message:u.message,...s===void 0?{}:{files:s}};await We(t,r,p),await X(t,r,p,o,a)}catch(e){throw u(e)}let p=[];for(let e of n)if(!(e.deleted||e.noSync||Ze(e,r)))try{await X(e,r,s[e.id]?.[r]??await Ue(e,r,f,o,a),o,a)}catch(t){p.push({id:e.id,target:r,error:t})}if(i.push(...p),p.length)throw p[0].error}let Ze=(e,t)=>e.origin?.thread===t||e.from!==null&&l(t)===e.from;async function Qe(e,t){if(!e.message)return;if(e.message.re===null)return Je(e,t);if(e.payload.noSync)return;let n=await E(e.payload.thread);if(!n||n.targets.length===0)return;let r=await O(e.message.id);if(!r||r.deleted)return;let i=await I(),a=[];for(let t of n.targets){let o=n.external[t];if(await b(t)&&o&&!Ze(r,t))try{await $(l(t),e,r,t,async e=>{let n=(await M([r.id]))[r.id]?.[t]??await Ue(r,t,o,i,e);await X(r,t,n,i,e)})}catch(e){Z(a,r.id,t,e)}}await Q(t,a)}async function $e(e){let t=(await M([e.payload.id]))[e.payload.id]??{};if(Object.keys(t).length===0)return;let n=e.type===`message.edited`?await O(e.payload.id):e.message??await O(e.payload.id);if(!n||e.type===`message.edited`&&n.deleted)return;let r=await I();for(let[i,a]of Object.entries(t))if(!(!await b(i)||e.payload.from!==null&&l(i)===e.payload.from))try{await $(l(i),e,n,i,async t=>{let o=c(l(i)),s=x(a.thread);e.type===`message.edited`?await o.edit(s,a.message,await Y(i,n,r,a.files===null,t)):e.type===`message.deleted`?(await o.delete(s,a.message),a.files?.length&&await o.deleteFiles(a.files)):e.type===`reaction.added`?await o.react(s,a.message,k(e.payload.emoji),!0):await o.react(s,a.message,k(e.payload.emoji),!1)})}catch(t){console.warn(`[board] skipped ${e.type} on ${i}:`,t.message)}}async function et(e){let{id:t}=e.payload,n=(await M([t]))[t]??{},r=e.message;if(!r||Object.keys(n).length===0)return;let i=await O(t);if(!i||i.deleted)return;let a=await I(),o={...i,labels:r.labels},s={...i,labels:e.before?.labels??{}};for(let[t,r]of Object.entries(n))if(await b(t))try{await $(l(t),e,o,t,async e=>{let n=await Y(t,o,a,r.files===null,e);n.markdown!==(await Y(t,s,a,r.files===null,e)).markdown&&await c(l(t)).edit(x(r.thread),r.message,n)})}catch(e){console.warn(`[board] skipped labels.changed on ${t}:`,G(e))}}async function tt(e,{attempt:t}){switch(e.type){case`thread.synced`:return Ye(e,t);case`message.posted`:return Qe(e,t);case`message.edited`:case`message.deleted`:case`reaction.added`:case`reaction.removed`:return $e(e);case`labels.changed`:return et(e)}}async function nt(e,t){let n=e[0]?await E(e[0].thread):null;if(!n)return[];let r=[];for(let e of new Set(Object.values(n.external)))await b(e)&&r.push(e);return(await Promise.all(r.map(async n=>{let r=l(n);try{let i=c(r),a=null;for(let t=e.length-1;t>=0&&a===null;t--){let r=e[t];!r.deleted&&r.origin?.thread===n&&(a=r.origin.message)}return await i.startTyping(x(n),a,t),n}catch(e){return console.warn(`[board] skipped typing on ${n}:`,G(e)),null}}))).filter(e=>e!==null)}async function rt(e,t){try{return`${e}:${await c(e).resolveChannel(t)}`}catch(e){throw d(`can't resolve inbox channel: ${e.message}`)}}let it=e=>e===`unsupported`||e===`invalid_target`?400:e===`channel_not_found`?404:e===`ratelimited`?429:[`no_client`,`list_failed`,`internal_error`,`fatal_error`,`service_unavailable`,`request_timeout`].includes(e)?502:403;async function at(e,t,n,r){let i=c(e);try{let a=await i.read(t,{limit:n,after:r});return{...a,messages:a.messages.map(t=>({...t,text:be(e,i.platform,t.text)}))}}catch(n){throw n instanceof j?new _(it(n.code),n.code,n.message):d(`can't read ${t} from ${e}: ${G(n)}`,`platform_error`)}}async function ot(e,t){let n=c(e);try{return await n.join(t)}catch(n){throw n instanceof j?new _(it(n.code),n.code,n.message):d(`can't join ${t} on ${e}: ${G(n)}`,`platform_error`)}}return{entries:e,bind(e){t=e},caller:a,deliver:tt,receive:je,pull:De,normalizeTarget:Ce,handleWebhook:Ee,inboxChannel:rt,typing:nt,readSource:at,joinSource:ot}}function J(e){let t=e.url?`${e.title}\n${e.url}`:e.title;return e.body?`${t}\n\n${e.body}`:t}export{q as createSyncEngine,K as keyedId};
5
+ `).filter(e=>/^📎 .* didn't come over: /u.test(e)),U=e=>JSON.stringify([e.url,e.message,e.snapshot,e.unavailable]),ge=(e,t)=>e.length===t.length&&e.every((e,n)=>U(e)===U(t[n])),_e=new AbortController().signal,ve=e=>{try{return JSON.parse(JSON.stringify(e??null))}catch{return null}},W=e=>typeof e==`string`?D(e):Array.isArray(e)?e.map(W):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,t])=>[D(e),W(t)])):e,G=e=>{let t=e?.data?.error,n=typeof t==`string`?t:e instanceof Error?e.message:String(e);return D(n.slice(0,500))||`unknown error`},ye=e=>e instanceof _&&e.status===404;function K(e,t,n){return n.startsWith(`${e}:`)?n:`${e}:${n.startsWith(`${t}:`)?n.slice(t.length+1):n}`}function be(e,t,n){return e===t?n:re(n,n=>n.kind===`actor`&&n.actor.startsWith(`${t}:`)?`@[${K(e,t,n.actor)}]`:null)}function xe(e,t,n){if(!(`author`in n))return n;let r={...n.author,id:K(e,t,n.author.id)};return n.kind!==`message`&&n.kind!==`edited`||e===t?{...n,author:r}:{...n,author:r,...n.mentioned?{mentioned:n.mentioned.map(n=>({...n,id:K(e,t,n.id)}))}:{},text:be(e,t,n.text)}}function q(e){let t=null,i=()=>{if(!t)throw Error(`sync used before board() bound it`);return t},a={self:`sync`,origin:{via:{kind:`engine`}}};function o(e,t,n=_e,r=a){let o=i().backend;return o[e].call(o,r,t,n)}let c=t=>{let n=e[t];if(!n)throw d(`no sync entry named ${t}`);return n},l=e=>e.slice(0,e.indexOf(`:`)),g=e=>i().syncedHere(e),b=async t=>e[l(t)]!==void 0&&await g(l(t)),x=e=>e.slice(e.indexOf(`:`)+1);async function E(e){try{return await o(`syncThread`,{thread:e})}catch(e){if(ye(e))return null;throw e}}async function D(e){try{let{message:t,replies:n}=await o(`message`,{id:e});return[t,...n]}catch(e){if(ye(e))return[];throw e}}async function O(e){return(await D(e)).find(t=>t.id===e)??null}async function M(e){return e.length===0?{}:(await o(`syncCopies`,{message:[...new Set(e)]})).copies}let N=(e,t)=>o(`syncFind`,e,t),P=null;function F(){if(P)return P;let e=o(`me`,{}).then(e=>e.principal);return P=e,e.catch(()=>{P===e&&(P=null)}),e}async function I(){let[{actors:e},t]=await Promise.all([o(`actors`,{}),F().catch(()=>null)]),n={byId:{},principal:t};for(let t of e)n.byId[t.id]={id:t.id,kind:t.kind,handle:t.handle,name:t.name,avatar:t.avatar,...t.via?{via:{...t.via}}:{},...t.platform?{platform:t.platform}:{},...t.verified?{verified:!0}:{}};return n}let L=/* @__PURE__ */ new Map;function R(e,t){let n=`${e}:${t}`,r=L.get(n);if(r&&(!r.failed||Date.now()-r.at<6e4))return r.id;let i={id:c(e).resolveChannel(t),failed:!1,at:Date.now()};return i.id.catch(r=>{i.failed=!0;let a=se(r);!a&&L.get(n)===i&&L.delete(n),console.warn(`[board] sync ${e}: ${a?`skipping`:`couldn't resolve`} ${t}: ${r.message}`)}),L.set(n,i),i.id}function U(e,t){if(!v(t))return x(t);try{let n=c(e).inboxChannel(e,t);return n===null?null:x(n)}catch{return null}}let q=/* @__PURE__ */ new Map;function Se(e,t){let n=`${e}\u001f${t.toLowerCase()}`,r=q.get(n);if(r&&Date.now()-r.at<3e5)return r.mention;q.size>=1e3&&q.clear();let i=c(e),a=i.findByEmail(t).then(e=>e?i.mention({id:e.id,kind:`external`,handle:e.handle,name:e.name,avatar:e.avatar}):null,()=>null);return q.set(n,{at:Date.now(),mention:a}),a}async function Ce(e){let t=e.indexOf(`:`);if(t<=0)throw d(`sync targets look like <key>:<channel or thread>, got: ${e}`);let n=e.slice(0,t),r=c(n);try{let i=oe.parse(await r.resolveTarget(e.slice(t+1)));if(i.kind===`channel`&&!r.canStartThreads)throw Error(`${r.platform} cannot start threads; use an existing thread`);return{target:`${n}:${i.target}`,kind:i.kind}}catch(t){throw d(`can't sync to ${e}: ${t.message}`)}}async function we(e,t){let{event:n,raw:r,dedupe:i}=ce.parse(W({...t,raw:ve(t.raw)}));for(let t of[n.channel,n.thread,`subthread`in n?n.subthread:null])if(t!==null&&!t.startsWith(`${e}:`))throw d(`provider locations must belong to sync entry ${e}`);let a=le(c(e)),s=a&&await a(x(n.channel),t=>R(e,t)).catch(async e=>{if(await Te(n.thread))return!0;throw e});(!a||s||await Te(n.thread))&&await o(`inboxPush`,{key:e,events:[{id:i,event:n,raw:r}]})}async function Te(e){try{return(await N({thread:e},AbortSignal.timeout(2e3))).thread!==null}catch(e){let t=e?.name;if(t===`TimeoutError`||t===`AbortError`)return!0;throw e}}async function Ee(t,n){let r=e[t];if(!r)throw ie(`no sync entry named ${t}`);if(!await g(t))return new Response(null,{status:200});let i;try{i=await r.receive(t,n,e=>we(t,e))}catch(e){return e instanceof _&&e.status===400?(console.error(`[board] dropped an event the board refuses`,e),new Response(null,{status:200})):(console.error(`[board] intake failed`,e),new Response(`intake failed`,{status:500}))}let a=De([t]).catch(e=>console.error(`[board] couldn't pull ${t}'s inbox:`,G(e)));return ee(a),i}async function De(t=Object.keys(e)){let n=0,r=Date.now()+24e4;for(let e of t)if(await g(e))for(;Date.now()<r;){let{items:t}=await o(`inboxNext`,{key:e,limit:10});if(t.length===0)break;await Promise.all(t.map(t=>Oe(e,t))),n+=t.length}return n}async function Oe(e,t){let n;try{await je(e,{event:t.event,raw:t.raw},{id:t.id,attempt:t.attempt+1})}catch(r){console.error(`[board] sync ${e} couldn't import ${t.id}:`,G(r)),n=G(r)}await o(`inboxAck`,{key:e,id:t.id,lease:t.lease,...n===void 0?{}:{error:n}}).catch(e=>console.error(`[board] couldn't ack an inbox event:`,G(e)))}async function ke(e,t,n,r,i=[]){if(t.length===0)return[];let a=[];for(let o of t){if(a.some(e=>e.url===o.url))continue;let t=(await N({thread:o.thread,message:o.message})).message,s=t===null?null:await O(t);if(s&&!s.deleted&&s.channel===r){a.push({url:o.url,message:s.id,unavailable:null,snapshot:{author:s.author?T(s.author):s.by.actor,text:s.text,createdAt:s.createdAt,files:s.attachments.map(e=>({name:e.name,url:null}))}});continue}if(o.snapshot){a.push({url:o.url,message:null,snapshot:o.snapshot,unavailable:null});continue}let c=i.find(e=>e.url===o.url&&e.snapshot&&e.message===null);if(c){a.push(c);continue}let l=await e.fetchLink(o,n).catch(e=>({snapshot:null,unavailable:G(e)}));a.push({url:o.url,message:null,snapshot:l.snapshot,unavailable:l.snapshot?null:(l.unavailable??`unknown`).slice(0,300)})}return W(a)}async function Ae(e,t,n){let i=[],a=[],c=null;for(let l of t.slice(0,10)){if(c!==null){a.push(me(l,c));continue}if(l.size!==void 0&&l.size>26214400){a.push(B(l,`over ${r/1024/1024} MB`));continue}let t;try{let n=await e.fetchFile(l);if(n===null){a.push(B(l,`${e.platform} can't hand it over`));continue}t=n}catch(t){if(n<3)throw t;console.warn(`[board] couldn't fetch ${l.name??`a file`} from ${e.platform}:`,G(t)),a.push(B(l,`${e.platform} wouldn't hand it over`));continue}if(t.byteLength>26214400){a.push(B(l,`over ${r/1024/1024} MB`));continue}if(t.byteLength===0){a.push(B(l,`it was empty`));continue}let d=l.name??`${l.type}`;try{i.push((await o(`upload`,{data:t,name:d,type:l.mimeType||s(d)})).attachment)}catch(e){if(e instanceof _&&(e.code===`too_large`||e.code===`no_direct_uploads`)){a.push(B(l,`over ${u/1024/1024} MB`));continue}if(!V(e))throw e;c=e.message,a.push(me(l,c))}}for(let e of t.slice(10))a.push(B(e,`a message carries at most 10`));return{attachments:i,notes:a}}async function je(e,t,n){let r=c(e),a={...t,event:xe(e,r.platform,t.event)},{event:o,raw:s}=a,l=(await N({thread:o.thread})).thread??void 0;if(o.kind===`message`){let e=(await N({thread:o.subthread??o.thread,message:o.message})).message;if(e!==null){let t=(await O(e))?.origin;if(!t||t.message!==o.message||(t.subthread??t.thread)!==(o.subthread??o.thread))return}}let u=`author`in o?o.author:{id:`${e}:system`,handle:r.platform,name:r.platform,avatar:null,isBot:!0},f,p=()=>f??=A(r.event({id:n.id,key:e,event:o,raw:s})),m,h,g=!0,_={direction:`in`,key:e,channel:x(o.channel),get event(){return p()},board:i().client({author:u,key:e,...Ne(e,o)},n.id),import(t,r={}){if(!g)throw d(`the sync function has finished`);return m??=Me(e,a,n,l,t,r),m},permalink(){let e=h??r.permalink(p());return h=e,e.catch(()=>{h===e&&(h=void 0)}),e},resolve:t=>R(e,t)};try{await r.sync(_),await m}finally{g=!1}}async function Me(e,t,n,r,i,a){let o=i??(r?(await E(r))?.channel:void 0);if(o===void 0)return{root:null,message:null};try{return await Pe(e,t,n,p.parse(o),ae.parse(a))}catch(e){if(!(e instanceof ne))throw e;let n=(await N({thread:t.event.thread})).thread;return{root:n===null?null:(await E(n))?.root??null,message:null}}}function Ne(e,t){let n=c(e),r=(`subthread`in t?t.subthread:null)??t.thread;return{via:{kind:`sync`,key:e,platform:n.platform,channel:t.channel,thread:r},respond:async e=>{await n.post(x(r),`thread`,{markdown:e})}}}async function Pe(e,t,n,r,i){let{event:a,raw:s}=t,l=Ne(e,a),u=c(e),f=(await N({thread:a.thread})).thread??void 0,p=f?await E(f):null,m=p?.root,g=e=>h(`board-inbound`,n.id,String(e)),_={key:e,channel:l.via.channel,thread:l.via.thread},v=async e=>{if(!e.dropped)return e.message;for(let t of e.dropped)await l.respond(t);throw new ne(e.dropped)},y=async({attachments:t=[],...n})=>({id:await v(await o(`syncImport`,{op:`post`,from:e,source:_,...n,origin:n.origin??null,...t.length?{attachments:t.map(e=>e.id)}:{}})),re:n.re??null}),b=e=>({root:e.re??e.id,message:e.id}),S=(e={})=>{let t={...e,...i.labels};for(let e of i.unset??[])delete t[e];return t},C=e=>{if(!i.root)return e;let t=i.root(A(structuredClone(e)));if(t&&typeof t==`object`&&`then`in t)throw d(`root overrides must be synchronous`);let n=ae.pick({text:!0,labels:!0}).parse(t);return{...e,text:n.text??e.text,labels:{...e.labels,...n.labels}}},w=(t,n,r)=>o(`syncImport`,{op:`labels`,author:t,from:e,origin:{thread:a.thread},set:n,unset:r}),T=async(e,t)=>{if(!i.labels&&!i.unset)return;let n=await O(t),r=Object.fromEntries(Object.entries(i.labels??{}).filter(([e,t])=>n?.labels[e]!==t)),a=(i.unset??[]).filter(e=>n?.labels[e]!==void 0);(Object.keys(r).length||a.length)&&await w(e,r,a)};switch(a.kind){case`message`:{let t=(await N({thread:a.subthread??a.thread,message:a.message})).message;if(t!==null)return{root:m??t,message:t};let{attachments:o,notes:c}=a.files?.length?await Ae(u,a.files,n.attempt):{attachments:[],notes:[]},l=await ke(u,a.links??[],{thread:a.subthread??a.thread,message:a.message},p?.channel??r),d={...l.length?{links:l}:{},...a.mentioned?.length?{mentioned:a.mentioned}:{},author:a.author,text:z(H(i.text??a.text,c),o.length>0),...o.length?{attachments:o}:{},origin:{channel:a.channel,thread:a.thread,subthread:a.subthread,message:a.message,context:a.context},id:await g(0)},f={...d,...i.noSync?{noSync:!0}:{}};if(m!==void 0)return await T(a.author,m),b(await y({...f,re:m}));let h=await u.fetchRoot(x(a.thread));if(h===null){let e=C({text:a.text,labels:{},author:a.author,raw:s});return b(await y({...d,channel:r,text:z(H(i.text??e.text,c),o.length>0),labels:S(e.labels)}))}let _=C({...h,raw:h.raw??null}),v=await y({author:{...h.author,id:K(e,u.platform,h.author.id)},channel:r,text:z(_.text),labels:S(_.labels),origin:{channel:a.channel,thread:a.thread,subthread:null,message:`root:${n.id}`,context:null},id:await g(1)});return b(await y({...f,re:v.id}))}case`edited`:case`deleted`:case`reaction`:{let t=(await N({thread:a.subthread??a.thread,message:a.message})).message;if(t===null)return{root:m??null,message:null};let n=`author`in a?a.author:{id:`${e}:system`,handle:u.platform,name:u.platform,avatar:null,isBot:!0},r={thread:a.subthread??a.thread,message:a.message};if(m!==void 0&&await T(n,m),a.kind===`deleted`)await o(`syncImport`,{op:`delete`,author:n,from:e,origin:r});else if(a.kind===`edited`){let s=await O(t),c=z(H(i.text??a.text,s?he(s.text):[]),(s?.attachments.length??0)>0),l=a.mentioned?.length?{mentioned:a.mentioned}:{};s&&!a.linksOnly&&s.text!==c&&await v(await o(`syncImport`,{op:`edit`,author:n,from:e,origin:r,text:c,source:_,...l}));let d=s?await ke(u,a.links??[],r,s.channel,s.links):[];s&&!ge(d,s.links)&&await o(`syncImport`,{op:`links`,author:n,from:e,origin:r,links:d})}else{if(u.singleReaction){let i=k(a.emoji),s=/* @__PURE__ */ new Set([n.id,`${await F()}+${n.id}`]);for(let[c,l]of Object.entries((await O(t))?.reactions??{}))l.some(e=>s.has(e))&&!(a.added&&c===i)&&await o(`syncImport`,{op:`react`,author:n,from:e,origin:r,emoji:c,remove:!0})}(!u.singleReaction||a.added)&&await o(`syncImport`,{op:`react`,author:n,from:e,origin:r,emoji:a.emoji,remove:!a.added})}return{root:m??null,message:t}}case`lifecycle`:{if(m!==void 0){let t=await O(m),r=t?.origin?.message===`lifecycle:${n.id}`,c=S((r?C({text:J(a),labels:a.labels,author:a.author,raw:s}):null)?.labels??a.labels),l=e=>a.owns?.some(t=>e.startsWith(t))??!1,u=Object.fromEntries(Object.entries(c).filter(([e,n])=>t?.labels[e]!==n)),d=Object.keys(t?.labels??{}).filter(e=>!(e in c)&&(a.unset.includes(e)||i.unset?.includes(e)||l(e)));if(t&&!t.deleted&&(Object.keys(u).length||d.length)&&await w(a.author,u,d),a.retitled&&t&&!t.deleted&&t.from===e&&t.origin?.thread===a.thread){let n=z(i.text??C({text:J(a),labels:t.labels,author:a.author,raw:s}).text);t.text!==n&&await v(await o(`syncImport`,{op:`edit`,author:a.author,from:e,origin:{thread:t.origin.thread,message:t.origin.message},text:n}))}return a.reply?b(await y({author:a.author,re:m,text:z(i.text??a.reply),...i.noSync?{noSync:!0}:{},id:await g(1)})):{root:m,message:r?m:null}}if(!a.createRoot)return{root:null,message:null};let t=C({text:J(a),labels:a.labels,author:a.author,raw:s}),c=await y({author:a.author,channel:r,text:z(a.reply?t.text:i.text??t.text),labels:S(t.labels),origin:{channel:a.channel,thread:a.thread,subthread:null,message:`lifecycle:${n.id}`,context:null},id:await g(0)});return a.reply?b(await y({author:a.author,re:c.id,text:z(i.text??a.reply),...i.noSync?{noSync:!0}:{},id:await g(1)})):b(c)}}}async function Fe(e,t,n){let r=m(n).flatMap(e=>e.kind===`actor`?[e.actor]:[]);if(r.length===0)return n;let i=/* @__PURE__ */ new Map;for(let n of r)!t.byId[n]&&S(n)&&i.set(n,await Se(e,n));return re(n,n=>{if(n.kind===`handle`)return null;if(i.has(n.actor))return i.get(n.actor)??n.actor;let r=Le(n.actor,t);return r?ze(e,r.id,t)??r.name:Ie(e,n.actor,t)})}function Ie(e,t,n){let r=Re(e,t,n);if(r===null)return null;let i=c(e);return i.mentionById(`${i.platform}:${r}`)}function Le(e,t){return t.byId[e]??(t.principal?t.byId[`${t.principal}+${e}`]:void 0)??null}function Re(e,t,n){let{principal:r,profile:i}=y(t),a=i===null?t:f(i)!==null&&r===n.principal?i:null;return a?.startsWith(`${e}:`)?a.slice(e.length+1):null}function ze(e,t,n){let r=n.byId[t],i=r?Re(e,t,n):null;if(i===null)return null;let a=c(e);return a.mention({...r,id:`${a.platform}:${i}`})}async function Be(t,n,r,i,a){let o=i.byId[r.by.actor],s=o?.name??r.by.actor,l=`${o?.via?` ${te(o.via)}`:``}${r.from?` (${o?.platform??e[r.from]?.platform??r.from})`:``}`,u=o?.kind===`deployment`&&!o.via?/(?:@[^@/]+| \([^()]+\))$/.exec(s)?.[0]??``:``,f=`${s}${l}`,p=`${u}${l}`,m=c(t),h=fe(r,o),g=(a??(e=>m.render(e)))(A({message:{...structuredClone(r),text:pe(r.text,h)},author:o?{...o}:null,mentionOf:e=>ze(t,e,i),label:f,target:n}));if(typeof g!=`string`)throw d(`a provider renderer must return markdown`);let _=`**${f}**: `,v=await Fe(t,i,g.startsWith(_)&&ue(g.slice(_.length))?`**${f}**:\n\n${g.slice(_.length)}`:g),y=h?de(r.text):null;return{markdown:v,...o?.verified?{as:{name:f,avatar:Ve(r,o),attribution:p}}:{},...y?{deployments:y}:{}}}function Ve(e,t){let n=e=>!e||/\/avatars\/[a-z0-9-]+$/.test(e),r=t?.avatar??null;if(!n(r))return r;let i=t?.handle.split(`/`)[0]??``,a=e.by.principal.slice(12);return!e.by.principal.startsWith(`vercel:user:`)||!i||/^user-/.test(i)||i.toLowerCase()===a.toLowerCase()?r:`https://vercel.com/api/www/avatar?u=${encodeURIComponent(i)}&s=64&format=png`}let He=e=>e.attachments.map(t=>`\n📎 ${t.name} (${n(t.size)}, on the board: #${e.id})`).join(``),Y=async(e,t,n,r=!1,i)=>{let a=l(e),{markdown:o,...s}=await Be(a,e,t,n,i);return{markdown:t.attachments.length>0&&(r||!c(a).uploadsFiles)?`${o}\n${He(t)}`:o,...s}};async function Ue(e,t,n,r,i){let a=e.replyTo===null?void 0:(await M([e.replyTo]))[e.replyTo]?.[t],o=a!==void 0&&a.thread!==n?a.thread:n,s=c(l(t)),u=await Y(t,e,r,!1,i),f,p;if(!u.markdown.trim()&&e.attachments.length&&s.uploadsFiles)try{let n=await Ke(e,t,o);p=n.message,f=n.files}catch(n){if(!s.refusesFiles(n)&&!V(n))throw n;u=await Y(t,e,r,!0,i),p=(await s.post(x(o),`thread`,u)).message,f=null}else{if(!u.markdown.trim())throw d(`a renderer must return text unless the message has media`);p=(await s.post(x(o),`thread`,u)).message}let m={thread:o,message:p,...f===void 0?{}:{files:f}};return await We(e,t,m),m}async function We(e,t,n){await o(`syncReceipt`,{kind:`message`,message:e.id,target:t,external:{thread:n.thread,message:n.message},...n.files===void 0?{}:{files:n.files}})}async function Ge(e){return Promise.all(e.attachments.map(async e=>{let{data:t}=await o(`attachment`,{id:e.id});return{data:t instanceof Uint8Array?t:new Uint8Array(await new Response(t).arrayBuffer()),filename:e.name,mimeType:e.type}}))}async function Ke(e,t,n){return c(l(t)).uploadFiles(x(n),await Ge(e))}async function X(e,t,n,r,i){let a=c(l(t));if(!a.uploadsFiles||e.attachments.length===0||n.files!==void 0)return;let s;try{s=(await Ke(e,t,n.thread)).files}catch(o){if(!a.refusesFiles(o)&&!V(o))throw Object.assign(/* @__PURE__ */ Error(`files: ${G(o)}`),{cause:o,data:{error:`files: ${G(o)}`}});console.warn(`[board] ${t} won't take #${e.id}'s files (${G(o)}); noting them in its text`),s=null,await Y(t,e,r,!0,i).then(e=>a.edit(x(n.thread),n.message,e)).catch(n=>console.warn(`[board] couldn't note #${e.id}'s files on ${t}:`,G(n)))}await o(`syncReceipt`,{kind:`files`,message:e.id,target:t,files:s})}let Z=(e,t,n,r)=>{e.some(e=>e.error===r)||e.push({id:t,target:n,error:r})};async function Q(e,t){if(t.length!==0){if(e<5||w(e))throw t[0].error;for(let{id:e,target:n,error:r}of t)console.error(`[board] gave up ${n===null?`syncing #${e}`:`delivering #${e} to ${n}`}:`,G(r)),n!==null&&await o(`syncReceipt`,{kind:`failed`,message:e,target:n,error:G(r)})}}async function $(e,t,n,r,i){let a,o=!0,s=()=>d(`the sync function has finished`),l={direction:`out`,key:e,channel:r===null?null:U(e,r),event:A(structuredClone(t)),message:A(structuredClone(n)),target:r,deliver(e={}){if(!o)throw s();return a??=r===null?Promise.resolve():i(e.render),a},start(t){if(!o)throw s();return qe(e,n,t)},resolve:t=>R(e,t)};try{await c(e).sync(l),await a}finally{o=!1}}async function qe(e,t,n){let{target:r,kind:i}=await Ce(`${e}:${n}`),a=t.re===null?t:await O(t.re);!a||a.deleted||a.noSync||r!==(a.origin?a.origin.channel??C(a.origin.thread):null)&&await o(`syncReceipt`,{kind:`thread`,message:a.id,target:r,targetKind:i,cause:`config`})}async function Je(t,n){let r=[];for(let t of Object.keys(e))e[t].canStartThreads&&await g(t)&&r.push(t);if(t.payload.noSync||r.length===0)return;let i=await O(t.message.id);if(!i||i.deleted)return;let a=[];for(let e of r)try{await $(e,t,i,null,async()=>{})}catch(e){Z(a,i.id,null,e)}await Q(n,a)}async function Ye(e,t){let{thread:n,target:r}=e.payload;if(!await b(r)||(e.payload.kind??(v(r)?`thread`:`channel`))===`thread`)return;let i=await E(n);if(!i?.targets.includes(r))return;let[a,...o]=await D(i.root);if(!a||a.id!==i.root||a.deleted||a.noSync)return;let s=[];try{await $(l(r),e,a,r,e=>Xe(i,a,o,r,s,e))}catch(e){Z(s,a.id,r,e)}await Q(t,s)}async function Xe(e,t,n,r,i,a){let o=await I(),s=await M([t.id,...n.map(e=>e.id)]),u=e=>(i.push({id:t.id,target:r,error:e}),e),f=e.external[r];if(f){let e=s[t.id]?.[r];if(e)try{await X(t,r,e,o,a)}catch(e){throw u(e)}}else try{let e=c(l(r)),n=await Y(r,t,o,!1,a),i=!n.markdown.trim()&&t.attachments.length>0&&e.uploadsFiles;if(!n.markdown.trim()&&!i)throw d(`a renderer must return text unless the message has media`);let s,u=await(async()=>{if(!i&&(t.attachments.length===0||!e.startsThreadsWithFiles))return e.post(x(r),`channel`,n);try{let a=await e.post(x(r),`channel`,{...n,files:await Ge(t)});return s=i?a.files??[]:a.files,a}catch(n){if(!e.refusesFiles(n)&&!V(n))throw n;return s=null,e.post(x(r),`channel`,await Y(r,t,o,!0,a))}})();f=`${l(r)}:${u.thread}`;let p={thread:f,message:u.message,...s===void 0?{}:{files:s}};await We(t,r,p),await X(t,r,p,o,a)}catch(e){throw u(e)}let p=[];for(let e of n)if(!(e.deleted||e.noSync||Ze(e,r)))try{await X(e,r,s[e.id]?.[r]??await Ue(e,r,f,o,a),o,a)}catch(t){p.push({id:e.id,target:r,error:t})}if(i.push(...p),p.length)throw p[0].error}let Ze=(e,t)=>e.origin?.thread===t||e.from!==null&&l(t)===e.from;async function Qe(e,t){if(!e.message)return;if(e.message.re===null)return Je(e,t);if(e.payload.noSync)return;let n=await E(e.payload.thread);if(!n||n.targets.length===0)return;let r=await D(n.root);if(r[0]?.id!==n.root||r[0].noSync)return;let i=r.find(t=>t.id===e.message.id);if(!i||i.deleted)return;let a=await I(),o=[];for(let t of n.targets){let r=n.external[t];if(await b(t)&&r&&!Ze(i,t))try{await $(l(t),e,i,t,async e=>{let n=(await M([i.id]))[i.id]?.[t]??await Ue(i,t,r,a,e);await X(i,t,n,a,e)})}catch(e){Z(o,i.id,t,e)}}await Q(t,o)}async function $e(e){let t=(await M([e.payload.id]))[e.payload.id]??{};if(Object.keys(t).length===0)return;let n=e.type===`message.edited`?await O(e.payload.id):e.message??await O(e.payload.id);if(!n||e.type===`message.edited`&&n.deleted)return;let r=await I();for(let[i,a]of Object.entries(t))if(!(!await b(i)||e.payload.from!==null&&l(i)===e.payload.from))try{await $(l(i),e,n,i,async t=>{let o=c(l(i)),s=x(a.thread);e.type===`message.edited`?await o.edit(s,a.message,await Y(i,n,r,a.files===null,t)):e.type===`message.deleted`?(await o.delete(s,a.message),a.files?.length&&await o.deleteFiles(a.files)):e.type===`reaction.added`?await o.react(s,a.message,k(e.payload.emoji),!0):await o.react(s,a.message,k(e.payload.emoji),!1)})}catch(t){console.warn(`[board] skipped ${e.type} on ${i}:`,t.message)}}async function et(e){let{id:t}=e.payload,n=(await M([t]))[t]??{},r=e.message;if(!r||Object.keys(n).length===0)return;let i=await O(t);if(!i||i.deleted)return;let a=await I(),o={...i,labels:r.labels},s={...i,labels:e.before?.labels??{}};for(let[t,r]of Object.entries(n))if(await b(t))try{await $(l(t),e,o,t,async e=>{let n=await Y(t,o,a,r.files===null,e);n.markdown!==(await Y(t,s,a,r.files===null,e)).markdown&&await c(l(t)).edit(x(r.thread),r.message,n)})}catch(e){console.warn(`[board] skipped labels.changed on ${t}:`,G(e))}}async function tt(e,{attempt:t}){switch(e.type){case`thread.synced`:return Ye(e,t);case`message.posted`:return Qe(e,t);case`message.edited`:case`message.deleted`:case`reaction.added`:case`reaction.removed`:return $e(e);case`labels.changed`:return et(e)}}async function nt(e,t){let n=e[0]?await E(e[0].thread):null;if(!n)return[];let r=[];for(let e of new Set(Object.values(n.external)))await b(e)&&r.push(e);return(await Promise.all(r.map(async n=>{let r=l(n);try{let i=c(r),a=null;for(let t=e.length-1;t>=0&&a===null;t--){let r=e[t];!r.deleted&&r.origin?.thread===n&&(a=r.origin.message)}return await i.startTyping(x(n),a,t),n}catch(e){return console.warn(`[board] skipped typing on ${n}:`,G(e)),null}}))).filter(e=>e!==null)}async function rt(e,t){try{return`${e}:${await c(e).resolveChannel(t)}`}catch(e){throw d(`can't resolve inbox channel: ${e.message}`)}}let it=e=>e===`unsupported`||e===`invalid_target`?400:e===`channel_not_found`?404:e===`ratelimited`?429:[`no_client`,`list_failed`,`internal_error`,`fatal_error`,`service_unavailable`,`request_timeout`].includes(e)?502:403;async function at(e,t,n,r){let i=c(e);try{let a=await i.read(t,{limit:n,after:r});return{...a,messages:a.messages.map(t=>({...t,text:be(e,i.platform,t.text)}))}}catch(n){throw n instanceof j?new _(it(n.code),n.code,n.message):d(`can't read ${t} from ${e}: ${G(n)}`,`platform_error`)}}async function ot(e,t){let n=c(e);try{return await n.join(t)}catch(n){throw n instanceof j?new _(it(n.code),n.code,n.message):d(`can't join ${t} on ${e}: ${G(n)}`,`platform_error`)}}return{entries:e,bind(e){t=e},caller:a,deliver:tt,receive:je,pull:De,normalizeTarget:Ce,handleWebhook:Ee,inboxChannel:rt,typing:nt,readSource:at,joinSource:ot}}function J(e){let t=e.url?`${e.title}\n${e.url}`:e.title;return e.body?`${t}\n\n${e.body}`:t}export{q as createSyncEngine,K as keyedId};
@@ -0,0 +1,272 @@
1
+ import { i as ATTACHMENT_BYTES_MAX, r as parseProfileHeader, t as InvalidProfileHeader } from "./profile-header-Cj0Cb1cf.mjs";
2
+ import "./schemas-CUSTEFIy.mjs";
3
+ import { t as Failed, u as who } from "./main-B016auoG.mjs";
4
+ import { n as relative, r as shell, t as CSP } from "./shell-DmpmgOPC.mjs";
5
+ import { t as page } from "./page-7KWSGxyC.mjs";
6
+ import { randomBytes, timingSafeEqual } from "node:crypto";
7
+ import { createServer } from "node:http";
8
+ /** What a proxy adds to a request it forwards: Tailscale's sets `X-Forwarded-Host`, most others `X-Forwarded-For`. */
9
+ const FORWARDED = [
10
+ "forwarded",
11
+ "x-forwarded-for",
12
+ "x-forwarded-host",
13
+ "x-forwarded-proto",
14
+ "x-real-ip"
15
+ ];
16
+ /** The prebuilt UI where board is installed, read only when an inspector starts without one. */
17
+ const bundle = async () => (await import("./page-CN77B014.mjs")).page();
18
+ /**
19
+ * The UI, and a proxy for the board's API that adds your credentials, for a server
20
+ * on 127.0.0.1 to answer with. Because the proxy acts as you, it answers only its
21
+ * own page: every request must name the server's host (no DNS rebinding) and carry
22
+ * the per-run token that only the page has, and writes must also come from its
23
+ * origin. Your credential for the board never leaves this process. `hosts` adds
24
+ * names a proxy in front of it serves the page on: whoever reaches the page there
25
+ * acts as you, unless `visitor` says who a request is: a client that acts as them,
26
+ * or null for one it can't name, which the proxy then refuses. A request a proxy
27
+ * forwarded must name one of them: the server's own name is this machine's alone,
28
+ * and a caller behind a proxy can send it too.
29
+ */
30
+ async function createInspector(options) {
31
+ const { client } = options;
32
+ const me = await client.me();
33
+ const started = me.profile === null ? null : me.avatar ? {
34
+ name: me.profile,
35
+ avatar: me.avatar
36
+ } : me.profile;
37
+ const board = (await client.discovery().catch(() => null))?.url ?? client.url;
38
+ const app = options.page ?? await bundle();
39
+ const token = randomBytes(24).toString("base64url");
40
+ const allowed = new Set((options.hosts ?? []).map((host) => host.toLowerCase()));
41
+ let hosts = /* @__PURE__ */ new Set();
42
+ let proxied = /* @__PURE__ */ new Set();
43
+ let origins = /* @__PURE__ */ new Set();
44
+ const streams = /* @__PURE__ */ new Set();
45
+ async function proxy(request, response, url) {
46
+ const reading = request.method === "GET" || request.method === "HEAD";
47
+ if (!sameSecret(String(request.headers["x-inspect-token"] ?? ""), token) || !reading && !origins.has(String(request.headers.origin))) return json(response, 403, { error: {
48
+ code: "forbidden",
49
+ message: "the board is reachable only from the inspector's own page"
50
+ } });
51
+ const path = url.pathname.slice(6) || "/";
52
+ if (relative(path)) return json(response, 400, { error: {
53
+ code: "bad_path",
54
+ message: "no relative paths"
55
+ } });
56
+ const visiting = options.visitor?.(request);
57
+ if (visiting === null) return json(response, 401, { error: {
58
+ code: "unauthorized",
59
+ message: "the proxy in front of this page names no one for this request, so there's no one to act as"
60
+ } });
61
+ const acting = visiting ?? client;
62
+ const controller = new AbortController();
63
+ streams.add(controller);
64
+ response.on("close", () => controller.abort());
65
+ try {
66
+ const body = reading ? void 0 : await read(request, path === "/attachments" ? ATTACHMENT_BYTES_MAX : void 0);
67
+ let as = null;
68
+ const named = request.headers["x-board-profile"];
69
+ if (typeof named === "string" && named.trim() !== "") try {
70
+ const { name, avatar } = parseProfileHeader(named);
71
+ as = avatar === null ? name : {
72
+ name,
73
+ avatar
74
+ };
75
+ } catch (error) {
76
+ if (!(error instanceof InvalidProfileHeader)) throw error;
77
+ return json(response, 400, { error: {
78
+ code: "invalid_profile",
79
+ message: error.message
80
+ } });
81
+ }
82
+ const upstream = await acting.request(`${path}${url.search}`, {
83
+ as,
84
+ method: request.method ?? "GET",
85
+ headers: {
86
+ ...request.headers["content-type"] ? { "content-type": String(request.headers["content-type"]) } : {},
87
+ ...request.headers.accept ? { accept: String(request.headers.accept) } : {},
88
+ ...request.headers["x-board-filename"] ? { "x-board-filename": String(request.headers["x-board-filename"]) } : {}
89
+ },
90
+ ...body ? { body } : {},
91
+ signal: controller.signal
92
+ });
93
+ response.writeHead(upstream.status, {
94
+ "content-type": upstream.headers.get("content-type") ?? "application/json",
95
+ "cache-control": "no-store",
96
+ "x-content-type-options": "nosniff"
97
+ });
98
+ if (upstream.body) for await (const chunk of upstream.body) response.write(chunk);
99
+ response.end();
100
+ } catch (error) {
101
+ if (controller.signal.aborted || response.headersSent) return void response.end();
102
+ json(response, 502, { error: {
103
+ code: "unreachable",
104
+ message: `the board didn't answer: ${error.message}`
105
+ } });
106
+ } finally {
107
+ streams.delete(controller);
108
+ }
109
+ }
110
+ function handle(request, response) {
111
+ let url;
112
+ try {
113
+ url = new URL(request.url ?? "/", "http://inspector");
114
+ } catch {
115
+ return send(response, 400, "text/plain; charset=utf-8", "bad request");
116
+ }
117
+ const named = String(request.headers.host).toLowerCase();
118
+ if (!(FORWARDED.some((header) => request.headers[header] !== void 0) ? proxied : hosts).has(named)) return send(response, 421, "text/plain; charset=utf-8", "wrong host");
119
+ if (url.pathname === "/board" || url.pathname.startsWith("/board/")) return void proxy(request, response, url).catch(() => response.headersSent ? response.end() : send(response, 500, "text/plain; charset=utf-8", "error"));
120
+ if (request.method !== "GET") return send(response, 405, "text/plain; charset=utf-8", "method not allowed");
121
+ if (url.pathname === "/app.js") return app ? send(response, 200, "text/javascript; charset=utf-8", app) : send(response, 503, "text/plain; charset=utf-8", "the inspector's UI isn't built: run `pnpm --filter @vercel/board build`");
122
+ send(response, 200, "text/html; charset=utf-8", shell({
123
+ token,
124
+ profile: started,
125
+ base: ""
126
+ }), { "content-security-policy": CSP });
127
+ }
128
+ return {
129
+ board,
130
+ me,
131
+ at(port) {
132
+ const own = [`127.0.0.1:${port}`, `localhost:${port}`];
133
+ hosts = /* @__PURE__ */ new Set([...own, ...allowed]);
134
+ proxied = new Set([...allowed].filter((host) => !own.includes(host)));
135
+ origins = /* @__PURE__ */ new Set([
136
+ `http://127.0.0.1:${port}`,
137
+ `http://localhost:${port}`,
138
+ ...[...allowed].flatMap((host) => [`http://${host}`, `https://${host}`])
139
+ ]);
140
+ return {
141
+ handle,
142
+ close() {
143
+ for (const stream of streams) stream.abort();
144
+ }
145
+ };
146
+ }
147
+ };
148
+ }
149
+ /** The inspector on a server of its own, on 127.0.0.1: `port`, or 4747, or any free one when that's taken. */
150
+ async function startInspector(options) {
151
+ const inspector = await createInspector(options);
152
+ let page = null;
153
+ const server = createServer((request, response) => page ? page.handle(request, response) : void response.writeHead(503).end());
154
+ const port = await listen(server, options.port ?? 4747, options.port === void 0);
155
+ const serving = page = inspector.at(port);
156
+ return {
157
+ url: `http://127.0.0.1:${port}`,
158
+ board: inspector.board,
159
+ me: inspector.me,
160
+ close: () => new Promise((resolve) => {
161
+ serving.close();
162
+ server.close(() => resolve());
163
+ server.closeAllConnections();
164
+ })
165
+ };
166
+ }
167
+ function sameSecret(given, expected) {
168
+ const a = Buffer.from(given);
169
+ const b = Buffer.from(expected);
170
+ return a.length === b.length && timingSafeEqual(a, b);
171
+ }
172
+ function read(request, limit = 1048576) {
173
+ return new Promise((resolve, reject) => {
174
+ let size = 0;
175
+ const chunks = [];
176
+ request.on("data", (chunk) => {
177
+ size += chunk.length;
178
+ if (size > limit) {
179
+ reject(/* @__PURE__ */ new Error("request too large"));
180
+ request.destroy();
181
+ } else chunks.push(chunk);
182
+ });
183
+ request.on("end", () => resolve(new Uint8Array(Buffer.concat(chunks))));
184
+ request.on("error", reject);
185
+ });
186
+ }
187
+ function send(response, status, type, body, headers = {}) {
188
+ response.writeHead(status, {
189
+ "content-type": type,
190
+ "cache-control": "no-store",
191
+ "x-content-type-options": "nosniff",
192
+ "referrer-policy": "no-referrer",
193
+ ...headers
194
+ });
195
+ response.end(body);
196
+ }
197
+ const json = (response, status, body) => send(response, status, "application/json", JSON.stringify(body));
198
+ /** Listens on the port, or any free one when the default port is taken. */
199
+ async function listen(server, port, fallback) {
200
+ try {
201
+ return await listenOn(server, port);
202
+ } catch (error) {
203
+ if (fallback && error.code === "EADDRINUSE") return listenOn(server, 0);
204
+ throw error;
205
+ }
206
+ }
207
+ function listenOn(server, port) {
208
+ return new Promise((resolve, reject) => {
209
+ const onError = (error) => {
210
+ server.off("listening", onListening);
211
+ reject(error);
212
+ };
213
+ const onListening = () => {
214
+ server.off("error", onError);
215
+ resolve(server.address().port);
216
+ };
217
+ server.once("error", onError);
218
+ server.once("listening", onListening);
219
+ server.listen(port, "127.0.0.1");
220
+ });
221
+ }
222
+ //#endregion
223
+ //#region src/cli/inspect.ts
224
+ /** Until Ctrl-C or a SIGTERM, whichever comes first: then neither is listened for. */
225
+ const stopped = () => new Promise((resolve) => {
226
+ const done = () => {
227
+ process.off("SIGINT", done);
228
+ process.off("SIGTERM", done);
229
+ resolve();
230
+ };
231
+ process.once("SIGINT", done);
232
+ process.once("SIGTERM", done);
233
+ });
234
+ /** The page to serve, before anything starts: an install without one says so, and serves nothing. */
235
+ async function pageOf() {
236
+ const found = await page();
237
+ if (found === null) throw new Failed({
238
+ class: "unknown",
239
+ reason: "no_inspector_page",
240
+ message: "The inspector's page isn't installed with this CLI.",
241
+ next: [{ instruction: "Reinstall or update the CLI" }]
242
+ });
243
+ return found;
244
+ }
245
+ /** The hosts `--allow-host`, or `--tailscale`, names: each a host, with its port when that isn't its scheme's default. */
246
+ function allowedHosts({ flags, usage }, flag = "allow-host") {
247
+ const hosts = flags[flag] ?? [];
248
+ const bad = hosts.find((host) => !/^[a-z0-9.-]+(:\d+)?$/i.test(host));
249
+ if (bad !== void 0) throw usage(`--${flag} takes a host, with a port if it isn't the default, like box.tailnet.ts.net: not ${bad}.`);
250
+ return [...new Set(hosts.flatMap((host) => [host, host.replace(/:(443|80)$/, "")]))];
251
+ }
252
+ async function inspect({ flags, out, usage, portFlag, client, openBrowser }) {
253
+ const port = portFlag();
254
+ const hosts = allowedHosts({
255
+ flags,
256
+ usage
257
+ });
258
+ const page = await pageOf();
259
+ const inspector = await startInspector({
260
+ client: client(),
261
+ page,
262
+ hosts,
263
+ ...port !== void 0 ? { port } : {}
264
+ });
265
+ out(`inspecting ${inspector.board} as ${who(inspector.me)} at ${inspector.url} (Ctrl-C to stop)`);
266
+ if (!flags["no-open"]) openBrowser(inspector.url);
267
+ await stopped();
268
+ await inspector.close();
269
+ return 0;
270
+ }
271
+ //#endregion
272
+ export { createInspector as i, inspect as n, stopped as r, allowedHosts as t };
@@ -0,0 +1,2 @@
1
+ import { n as inspect } from "./inspect-CZeoSm7E.mjs";
2
+ export { inspect };
@@ -0,0 +1,17 @@
1
+ import { t as BoardClient } from "./client-C2T4eaXd.mjs";
2
+ //#region src/inspect/handler.d.ts
3
+ /** Answers the inspector's requests under `basePath`: `GET`, `POST`, `PATCH`, `PUT`, and `DELETE` alike. */
4
+ export type InspectorHandler = (request: Request) => Promise<Response>;
5
+ /**
6
+ * The inspector for `board`, served under `basePath` (`/board`: the page at `/board`, its bundle at
7
+ * `/board/app.js`, its proxy at `/board/board/*`). The proxy answers only the page: a request names
8
+ * its token, a browser's says it's from this origin (`Sec-Fetch-Site`), and a write carries this
9
+ * origin. Each request acts as `board`, under the profile the page picks, the way any handle names
10
+ * one (`x-board-profile`). A write that names none is refused: the handle is the deployment, not
11
+ * whoever's visiting, so the page asks who's posting before it loads.
12
+ */
13
+ export declare function inspector(options: {
14
+ board: BoardClient;
15
+ basePath: string;
16
+ }): InspectorHandler;
17
+ //#endregion
@@ -0,0 +1,196 @@
1
+ import { i as ATTACHMENT_BYTES_MAX, r as parseProfileHeader, t as InvalidProfileHeader } from "./profile-header-Cj0Cb1cf.mjs";
2
+ import "./schemas-CUSTEFIy.mjs";
3
+ import { n as relative, r as shell, t as CSP } from "./shell-DmpmgOPC.mjs";
4
+ import { t as page } from "./page-7KWSGxyC.mjs";
5
+ //#region src/inspect/handler.ts
6
+ /**
7
+ * The page's credential for its proxy. A server answers it on many instances, so it's the same for
8
+ * every page: it's no secret, it's a header no other site's page can send without asking first.
9
+ */
10
+ const TOKEN = "page";
11
+ /** A JSON body the inspector reads whole: everything but an upload. */
12
+ const BODY_MAX = 1048576;
13
+ /**
14
+ * The inspector for `board`, served under `basePath` (`/board`: the page at `/board`, its bundle at
15
+ * `/board/app.js`, its proxy at `/board/board/*`). The proxy answers only the page: a request names
16
+ * its token, a browser's says it's from this origin (`Sec-Fetch-Site`), and a write carries this
17
+ * origin. Each request acts as `board`, under the profile the page picks, the way any handle names
18
+ * one (`x-board-profile`). A write that names none is refused: the handle is the deployment, not
19
+ * whoever's visiting, so the page asks who's posting before it loads.
20
+ */
21
+ function inspector(options) {
22
+ const { board } = options;
23
+ const base = options.basePath.replace(/\/+$/, "");
24
+ const app = cached(page);
25
+ const started = cached(async () => profileOf(await board.me()));
26
+ async function proxy(request, path, search) {
27
+ const reading = request.method === "GET" || request.method === "HEAD";
28
+ const site = request.headers.get("sec-fetch-site");
29
+ if (request.headers.get("x-inspect-token") !== TOKEN || site !== null && site !== "same-origin" || !reading && !sameOrigin(request)) return json(403, { error: {
30
+ code: "forbidden",
31
+ message: "the board is reachable only from the inspector's own page"
32
+ } });
33
+ if (relative(path)) return json(400, { error: {
34
+ code: "bad_path",
35
+ message: "no relative paths"
36
+ } });
37
+ let as = null;
38
+ const named = request.headers.get("x-board-profile");
39
+ if (named !== null && named.trim() !== "") try {
40
+ const { name, avatar } = parseProfileHeader(named);
41
+ as = avatar === null ? name : {
42
+ name,
43
+ avatar
44
+ };
45
+ } catch (error) {
46
+ if (!(error instanceof InvalidProfileHeader)) throw error;
47
+ return json(400, { error: {
48
+ code: "invalid_profile",
49
+ message: error.message
50
+ } });
51
+ }
52
+ if (!reading && (as === null || nameOf(as) === nameOf(await started().catch(() => null)))) return json(401, { error: {
53
+ code: "profile_required",
54
+ message: "name a profile to write as, other than the app's own: this page doesn't know who you are"
55
+ } });
56
+ let body;
57
+ if (!reading) {
58
+ const limit = path === "/attachments" ? ATTACHMENT_BYTES_MAX : BODY_MAX;
59
+ const read = await readUpTo(request, limit);
60
+ if (read === null) return json(413, { error: {
61
+ code: "too_large",
62
+ message: `a request to the inspector is at most ${limit} bytes`
63
+ } });
64
+ body = read;
65
+ }
66
+ const forwarded = {};
67
+ for (const header of [
68
+ "content-type",
69
+ "accept",
70
+ "x-board-filename"
71
+ ]) {
72
+ const value = request.headers.get(header);
73
+ if (value !== null) forwarded[header] = value;
74
+ }
75
+ try {
76
+ const upstream = await board.request(`${path}${search}`, {
77
+ as,
78
+ method: request.method,
79
+ headers: forwarded,
80
+ ...body ? { body } : {},
81
+ signal: request.signal
82
+ });
83
+ return new Response(upstream.body, {
84
+ status: upstream.status,
85
+ headers: {
86
+ "content-type": upstream.headers.get("content-type") ?? "application/json",
87
+ "cache-control": "no-store",
88
+ "x-content-type-options": "nosniff"
89
+ }
90
+ });
91
+ } catch (error) {
92
+ return json(502, { error: {
93
+ code: "unreachable",
94
+ message: `the board didn't answer: ${error.message}`
95
+ } });
96
+ }
97
+ }
98
+ return async (request) => {
99
+ const url = new URL(request.url);
100
+ const at = url.pathname === base || url.pathname.startsWith(`${base}/`) ? url.pathname.slice(base.length) || "/" : null;
101
+ if (at === null) return text(404, "not found");
102
+ if (at === "/board" || at.startsWith("/board/")) return proxy(request, at.slice(6) || "/", url.search);
103
+ if (request.method !== "GET" && request.method !== "HEAD") return text(405, "method not allowed");
104
+ if (at === "/app.js") {
105
+ const script = await app();
106
+ if (script === null) return text(503, "the inspector's UI isn't installed with @vercel/board");
107
+ return new Response(script, { headers: {
108
+ ...HEADERS,
109
+ "content-type": "text/javascript; charset=utf-8",
110
+ "cache-control": "private, max-age=31536000, immutable"
111
+ } });
112
+ }
113
+ const profile = await started().catch(() => null);
114
+ return new Response(shell({
115
+ token: TOKEN,
116
+ profile,
117
+ base,
118
+ named: true
119
+ }), { headers: {
120
+ ...HEADERS,
121
+ "content-type": "text/html; charset=utf-8",
122
+ "content-security-policy": CSP
123
+ } });
124
+ };
125
+ }
126
+ /**
127
+ * A request's body, or null once it's more than `limit` bytes: a `Content-Length` over it is refused
128
+ * before reading, and a body without one stops being read, and is canceled, as soon as it passes it.
129
+ */
130
+ async function readUpTo(request, limit) {
131
+ if (Number(request.headers.get("content-length") ?? 0) > limit) return null;
132
+ if (request.body === null) return /* @__PURE__ */ new Uint8Array(0);
133
+ const reader = request.body.getReader();
134
+ const chunks = [];
135
+ let size = 0;
136
+ for (;;) {
137
+ const { done, value } = await reader.read();
138
+ if (done) break;
139
+ size += value.byteLength;
140
+ if (size > limit) {
141
+ await reader.cancel().catch(() => {});
142
+ return null;
143
+ }
144
+ chunks.push(value);
145
+ }
146
+ const body = new Uint8Array(size);
147
+ let at = 0;
148
+ for (const chunk of chunks) {
149
+ body.set(chunk, at);
150
+ at += chunk.byteLength;
151
+ }
152
+ return body;
153
+ }
154
+ /** `load`'s answer, asked for once: a failure is asked again next time. */
155
+ function cached(load) {
156
+ let promise = null;
157
+ return () => promise ??= load().catch((error) => {
158
+ promise = null;
159
+ throw error;
160
+ });
161
+ }
162
+ const HEADERS = {
163
+ "cache-control": "no-store",
164
+ "x-content-type-options": "nosniff",
165
+ "referrer-policy": "no-referrer"
166
+ };
167
+ /** The profile a handle acts as, as the page is told it. */
168
+ const profileOf = (me) => me.profile === null ? null : me.avatar ? {
169
+ name: me.profile,
170
+ avatar: me.avatar
171
+ } : me.profile;
172
+ /** A profile's name as the board keys it: lowercased, so `Factory` is the same actor as `factory`. */
173
+ const nameOf = (profile) => {
174
+ if (profile === null) return null;
175
+ return (typeof profile === "string" ? profile : profile.name).toLowerCase();
176
+ };
177
+ /** A write's `Origin` is this server's, as the request reached it. */
178
+ function sameOrigin(request) {
179
+ const origin = request.headers.get("origin");
180
+ if (origin === null) return false;
181
+ const host = URL.parse(origin)?.host;
182
+ return host !== void 0 && (host === new URL(request.url).host || host === request.headers.get("host"));
183
+ }
184
+ const text = (status, body) => new Response(body, {
185
+ status,
186
+ headers: {
187
+ ...HEADERS,
188
+ "content-type": "text/plain; charset=utf-8"
189
+ }
190
+ });
191
+ const json = (status, body) => Response.json(body, {
192
+ status,
193
+ headers: HEADERS
194
+ });
195
+ //#endregion
196
+ export { inspector };